diff --git a/src/apis/analytics.ts b/src/apis/analytics.ts new file mode 100644 index 0000000..755db01 --- /dev/null +++ b/src/apis/analytics.ts @@ -0,0 +1,559 @@ +import { ApiResource } from '../apiResource'; +import { APIResponseType, ApiClientInterface } from '../_types/generalTypes'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export interface AnalyticsBaseParams { + time_of_generation_min: string; + time_of_generation_max: string; + total_units_min?: number; + total_units_max?: number; + cost_min?: number; + cost_max?: number; + prompt_token_min?: number; + prompt_token_max?: number; + completion_token_min?: number; + completion_token_max?: number; + status_code?: string; + page_size?: number; + weighted_feedback_min?: number; + weighted_feedback_max?: number; + order_by?: string; + order_by_type?: string; + virtual_keys?: string; + configs?: string; + workspace_slug?: string; + api_key_ids?: string; + ai_org_model?: string; + metadata?: string; + cache_status?: string; +} + +export type AnalyticsGraphsGetParams = AnalyticsBaseParams; + +export interface AnalyticsGroupsGetParams extends AnalyticsBaseParams { + page_size?: number; + current_page?: number; +} + +export type AnalyticsGroupByValue = + | 'ai_service' + | 'model' + | 'status_code' + | 'api_key' + | 'config' + | 'workspace' + | 'provider' + | 'prompt'; + +export type AnalyticsColumnValue = + | 'requests' + | 'cost' + | 'total_tokens' + | 'avg_tokens' + | 'avg_input_tokens' + | 'avg_output_tokens' + | 'avg_latency' + | 'p95_latency' + | 'p99_latency' + | 'success_rate' + | 'error_count' + | 'cache_hit_rate' + | 'last_seen' + | 'first_seen'; + +export interface AnalyticsGroupedDataParams extends AnalyticsGroupsGetParams { + columns?: string; + include_total?: boolean; +} + +export type AnalyticsSummaryGetParams = AnalyticsBaseParams; + +export class Analytics extends ApiResource { + graphs: AnalyticsGraphs; + groups: AnalyticsGroups; + summary: AnalyticsSummary; + + constructor(client: any) { + super(client); + this.graphs = new AnalyticsGraphs(client); + this.groups = new AnalyticsGroups(client); + this.summary = new AnalyticsSummary(client); + } +} + +export class AnalyticsGraphs extends ApiResource { + requests( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/requests${queryParams}`, + { ...opts } + ); + return response; + } + + cost( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/cost${queryParams}`, { + ...opts, + }); + return response; + } + + latency( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/latency${queryParams}`, { + ...opts, + }); + return response; + } + + tokens( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/tokens${queryParams}`, { + ...opts, + }); + return response; + } + + users( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/users${queryParams}`, { + ...opts, + }); + return response; + } + + usersRequests( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/users-requests${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/graphs/errors${queryParams}`, { + ...opts, + }); + return response; + } + + errors_rate( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-rate${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors_stack( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-stack${queryParams}`, + { + ...opts, + } + ); + return response; + } + + errors_status_code( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/errors-status-code${queryParams}`, + { + ...opts, + } + ); + return response; + } + + requests_rescued( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/requests-rescued${queryParams}`, + { + ...opts, + } + ); + return response; + } + + cache_hit_rate( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/cache-hit-rate${queryParams}`, + { + ...opts, + } + ); + return response; + } + + cache_latency( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/cache-latency${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedbacks( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/graphs/feedbacks${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedbacks_score( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/score${queryParams}`, + { + ...opts, + } + ); + + return response; + } + + feedbacks_weighted( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/weighted${queryParams}`, + { + ...opts, + } + ); + return response; + } + + feedback_ai_models( + _query: AnalyticsGraphsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + + const response = this.getMethod( + `/analytics/graphs/feedbacks/ai-models${queryParams}`, + { + ...opts, + } + ); + return response; + } +} + +export class AnalyticsGroups extends ApiResource { + users( + _query: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/groups/users${queryParams}`, { + ...opts, + }); + return response; + } + + aiModels( + _query: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/ai-models${queryParams}`, + { + ...opts, + } + ); + return response; + } + + workspaces( + _query: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/workspaces${queryParams}`, + { + ...opts, + } + ); + return response; + } + + metadata( + metadataKey: string, + _query: AnalyticsGroupsGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/metadata/${metadataKey}${queryParams}`, + { + ...opts, + } + ); + return response; + } + + groupedData( + groupBy: AnalyticsGroupByValue, + _query: AnalyticsGroupedDataParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/analytics/groups/${groupBy}${queryParams}`, + { + ...opts, + } + ); + return response; + } +} + +export class AnalyticsSummary extends ApiResource { + cache( + _query: AnalyticsSummaryGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const queryParams = toQueryParams(_query); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/analytics/summary/cache${queryParams}`, { + ...opts, + }); + return response; + } +} diff --git a/src/apis/index.ts b/src/apis/index.ts index 3bbb992..00b9e27 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -38,3 +38,6 @@ export { Conversations } from './conversations'; export { Videos } from './videos'; export { ChatKit } from './chatkit'; export { Guardrails } from './guardrails'; +export { Analytics } from './analytics'; +export { MCPIntegrations } from './mcpIntegrations'; +export { MCPServers } from './mcpServers'; diff --git a/src/apis/mcpIntegrations.ts b/src/apis/mcpIntegrations.ts new file mode 100644 index 0000000..fe1efb8 --- /dev/null +++ b/src/apis/mcpIntegrations.ts @@ -0,0 +1,406 @@ +import { ApiClientInterface, APIResponseType } from '../_types/generalTypes'; +import { ApiResource } from '../apiResource'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export type MCPIntegrationAuthType = + | 'oauth_auto' + | 'oauth_client_credentials' + | 'headers' + | 'none'; + +export type MCPIntegrationTransport = 'http' | 'sse'; + +export interface MCPIntegrationsCreateParams { + name: string; + url: string; + auth_type: MCPIntegrationAuthType; + transport: MCPIntegrationTransport; + workspace_id?: string; + organisation_id?: string; + slug?: string; + description?: string | null; + configurations?: Record; +} + +export interface MCPIntegrationsCreateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPIntegrationsListParams { + organisation_id?: string; + workspace_id?: string; + type?: 'workspace' | 'organisation' | 'all'; + page_size?: number; + current_page?: number; + search?: string; +} + +export interface MCPIntegrationData extends APIResponseType { + id?: string; + slug?: string; + name?: string; + description?: string | null; + url?: string; + auth_type?: MCPIntegrationAuthType; + transport?: MCPIntegrationTransport; + configurations?: Record; + workspace_id?: string | null; + organisation_id?: string; + owner_id?: string; + created_at?: string; + updated_at?: string; +} + +export interface MCPIntegrationsListResponse extends APIResponseType { + data?: MCPIntegrationData[]; + total?: number; +} + +export interface MCPIntegrationsRetrieveParams { + id: string; +} + +export interface MCPIntegrationsUpdateParams { + id: string; + name?: string; + description?: string | null; + url?: string; + auth_type?: MCPIntegrationAuthType; + transport?: MCPIntegrationTransport; + configurations?: Record; +} + +export interface MCPIntegrationsUpdateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPIntegrationsDeleteParams { + id: string; +} + +export interface MCPIntegrationsSyncParams { + id: string; + server_info?: { + name?: string; + version?: string; + title?: string; + description?: string; + website_url?: string; + icons?: any[]; + protocol_version?: string; + capabilities?: Record; + instructions?: string; + }; + capabilities?: Array<{ + name?: string; + type?: 'tool' | 'prompt' | 'resource' | 'resource_template'; + title?: string; + description?: string; + icons?: any[]; + _meta?: Record; + input_schema?: Record; + inputSchema?: Record; + output_schema?: Record; + outputSchema?: Record; + execution?: Record; + annotations?: Record; + arguments?: any[]; + uri?: string; + mime_type?: string; + mimeType?: string; + size?: number; + uri_template?: string; + uriTemplate?: string; + }>; +} + +export interface MCPIntegrationsTestParams { + id: string; +} + +export interface MCPIntegrationsWorkspacesListParams { + id: string; +} + +export interface MCPIntegrationsWorkspacesUpdateParams { + id: string; + workspaces: Array<{ + id: string; + enabled: boolean; + }>; + global_workspace_access?: { + enabled: boolean; + } | null; + override_existing_workspace_access?: boolean; +} + +export interface MCPIntegrationsCapabilitiesListParams { + id: string; +} + +export interface MCPIntegrationsCapabilitiesUpdateParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled: boolean; + }>; +} + +export interface MCPIntegrationsMetadataGetParams { + id: string; +} + +export class MCPIntegrations extends ApiResource { + workspaces: MCPIntegrationsWorkspaces; + capabilities: MCPIntegrationsCapabilities; + metadata: MCPIntegrationsMetadata; + + constructor(client: any) { + super(client); + this.workspaces = new MCPIntegrationsWorkspaces(client); + this.capabilities = new MCPIntegrationsCapabilities(client); + this.metadata = new MCPIntegrationsMetadata(client); + } + + create( + body: MCPIntegrationsCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + '/mcp-integrations', + { + body, + ...opts, + } + ); + return response; + } + + list( + _body?: MCPIntegrationsListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(body); + const response = this.getMethod( + `/mcp-integrations${query}`, + { ...opts } + ); + return response; + } + + retrieve( + body: MCPIntegrationsRetrieveParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}`, + { body: restBody, ...opts } + ); + return response; + } + + delete( + body: MCPIntegrationsDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod( + `/mcp-integrations/${id}`, + { ...opts } + ); + return response; + } + + sync( + body: MCPIntegrationsSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-integrations/${id}/sync`, + { body: restBody, ...opts } + ); + return response; + } + + test( + body: MCPIntegrationsTestParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-integrations/${id}/test`, + { body: {}, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsWorkspaces extends ApiResource { + list( + body: MCPIntegrationsWorkspacesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/workspaces`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsWorkspacesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}/workspaces`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsCapabilities extends ApiResource { + list( + body: MCPIntegrationsCapabilitiesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/capabilities`, + { ...opts } + ); + return response; + } + + update( + body: MCPIntegrationsCapabilitiesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-integrations/${id}/capabilities`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPIntegrationsMetadata extends ApiResource { + get( + body: MCPIntegrationsMetadataGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-integrations/${id}/metadata`, + { ...opts } + ); + return response; + } +} diff --git a/src/apis/mcpServers.ts b/src/apis/mcpServers.ts new file mode 100644 index 0000000..91c704d --- /dev/null +++ b/src/apis/mcpServers.ts @@ -0,0 +1,580 @@ +import { ApiClientInterface, APIResponseType } from '../_types/generalTypes'; +import { ApiResource } from '../apiResource'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export interface MCPServersCreateParams { + name: string; + mcp_integration_id: string; + workspace_id?: string; + description?: string | null; + slug?: string; +} + +export interface MCPServersCreateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPServersListParams { + workspace_id?: string; + current_page?: number; + page_size?: number; + id?: string; + search?: string; +} + +export interface MCPServerMetadata { + title?: string | null; + description?: string | null; + icons?: any[] | null; + server_name?: string | null; + server_version?: string | null; + protocol_version?: string | null; + sync_status?: string; + last_synced_at?: string | null; +} + +export interface MCPServerData extends APIResponseType { + id?: string; + slug?: string; + name?: string; + description?: string | null; + workspace_id?: string; + organisation_id?: string; + mcp_integration_id?: string; + owner_id?: string; + url?: string; + metadata?: MCPServerMetadata; + created_at?: string; + updated_at?: string; +} + +export interface MCPServersListResponse extends APIResponseType { + data?: MCPServerData[]; + total?: number; +} + +export interface MCPServersRetrieveParams { + id: string; +} + +export interface MCPServersUpdateParams { + id: string; + name?: string; + description?: string | null; +} + +export interface MCPServersUpdateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface MCPServersDeleteParams { + id: string; +} + +export interface MCPServersTestParams { + id: string; +} + +export interface MCPServersTokensGetParams { + id: string; +} + +export interface MCPServersTokensSetParams { + id: string; + access_token: string; + refresh_token?: string; +} + +export interface MCPServersTokensDeleteParams { + id: string; +} + +export interface MCPServersClientInfoParams { + id: string; +} + +export interface MCPServerCapability { + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled?: boolean; + description?: string | null; + schema?: Record | null; +} + +export interface MCPServersCapabilitiesListParams { + id: string; +} + +export interface MCPServersCapabilitiesUpdateParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + enabled: boolean; + }>; +} + +export interface MCPServersCapabilitiesSyncParams { + id: string; + capabilities: Array<{ + name: string; + type: 'tool' | 'prompt' | 'resource'; + description?: string | null; + schema?: Record | null; + }>; +} + +export interface MCPServersUserAccessCheckParams { + id: string; +} + +export interface MCPServersUserAccessListParams { + id: string; +} + +export interface MCPServersUserAccessUpdateParams { + id: string; + user_access?: Array<{ + id?: string; + user_id?: string; + enabled: boolean; + }>; + default_user_access?: 'allow' | 'deny'; +} + +export interface MCPServersMetadataGetParams { + id: string; +} + +export interface MCPServersMetadataSyncParams { + id: string; + server_name?: string | null; + server_version?: string | null; + protocol_version?: string | null; + title?: string | null; + description?: string | null; + website_url?: string | null; + icons?: any[] | null; + capability_flags?: Record | null; + instructions?: string | null; +} + +export interface MCPServersConnectionsListParams { + id: string; + user_id?: string; + workspace_id?: string; + current_page?: number; + page_size?: number; +} + +export interface MCPServersConnectionsDeleteParams { + id: string; + user_id?: string; + workspace_id?: string; +} + +export class MCPServers extends ApiResource { + capabilities: MCPServersCapabilities; + userAccess: MCPServersUserAccess; + metadata: MCPServersMetadata; + connections: MCPServersConnections; + + constructor(client: any) { + super(client); + this.capabilities = new MCPServersCapabilities(client); + this.userAccess = new MCPServersUserAccess(client); + this.metadata = new MCPServersMetadata(client); + this.connections = new MCPServersConnections(client); + } + + create( + body: MCPServersCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post('/mcp-servers', { + body, + ...opts, + }); + return response; + } + + list( + _query?: MCPServersListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(_query); + const response = this.getMethod( + `/mcp-servers${query}`, + { ...opts } + ); + return response; + } + + retrieve( + body: MCPServersRetrieveParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/mcp-servers/${id}`, { + ...opts, + }); + return response; + } + + update( + body: MCPServersUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`/mcp-servers/${id}`, { + body: restBody, + ...opts, + }); + return response; + } + + delete( + body: MCPServersDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod(`/mcp-servers/${id}`, { + ...opts, + }); + return response; + } + + test( + body: MCPServersTestParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post(`/mcp-servers/${id}/test`, { + body: {}, + ...opts, + }); + return response; + } + + getTokens( + body: MCPServersTokensGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/tokens`, + { ...opts } + ); + return response; + } + + setTokens( + body: MCPServersTokensSetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`/mcp-servers/${id}/tokens`, { + body: restBody, + ...opts, + }); + return response; + } + + deleteTokens( + body: MCPServersTokensDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod( + `/mcp-servers/${id}/tokens`, + { ...opts } + ); + return response; + } + + getClientInfo( + body: MCPServersClientInfoParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/client-info`, + { ...opts } + ); + return response; + } +} + +export class MCPServersCapabilities extends ApiResource { + list( + body: MCPServersCapabilitiesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/capabilities`, + { ...opts } + ); + return response; + } + + update( + body: MCPServersCapabilitiesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-servers/${id}/capabilities`, + { body: restBody, ...opts } + ); + return response; + } + + sync( + body: MCPServersCapabilitiesSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-servers/${id}/capabilities/sync`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersUserAccess extends ApiResource { + check( + body: MCPServersUserAccessCheckParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/user-access/check`, + { ...opts } + ); + return response; + } + + list( + body: MCPServersUserAccessListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/user-access`, + { ...opts } + ); + return response; + } + + update( + body: MCPServersUserAccessUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `/mcp-servers/${id}/user-access`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersMetadata extends ApiResource { + get( + body: MCPServersMetadataGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `/mcp-servers/${id}/metadata`, + { ...opts } + ); + return response; + } + + sync( + body: MCPServersMetadataSyncParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/mcp-servers/${id}/metadata/sync`, + { body: restBody, ...opts } + ); + return response; + } +} + +export class MCPServersConnections extends ApiResource { + list( + body: MCPServersConnectionsListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...queryParams } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.getMethod( + `/mcp-servers/${id}/connections${query}`, + { ...opts } + ); + return response; + } + + delete( + body: MCPServersConnectionsDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { id, ...queryParams } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.deleteMethod( + `/mcp-servers/${id}/connections${query}`, + { ...opts } + ); + return response; + } +} diff --git a/src/client.ts b/src/client.ts index 1566c3e..e1fa778 100644 --- a/src/client.ts +++ b/src/client.ts @@ -223,6 +223,9 @@ export class Portkey extends ApiClient { realtime: new API.Realtime(this), chatkit: new API.ChatKit(this), }; + analytics = new API.Analytics(this); + mcpServers = new API.MCPServers(this); + mcpIntegrations = new API.MCPIntegrations(this); post = ( url: string, diff --git a/src/utils.ts b/src/utils.ts index f5347a5..6269021 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -19,6 +19,7 @@ import { ApiKeysListParams } from './apis/apiKeys'; import { CongfigsListParams } from './apis/configs'; import { LogsExportListParams } from './apis/logsExport'; import { getBrowserInfo } from './core'; +import { AnalyticsBaseParams } from './apis/analytics'; type PlatformProperties = { 'x-portkey-runtime'?: string; @@ -219,17 +220,18 @@ export function toQueryParams( | ApiKeysListParams | CongfigsListParams | LogsExportListParams + | AnalyticsBaseParams | any ): string { if (!params) { return ''; } - const queryParams = Object.entries(params) - .filter(([, value]) => value !== undefined && value !== null) - .map(([key, value]) => `${key}=${value}`) - .join('&'); - - return queryParams ? `?${queryParams}` : ''; + const search = new URLSearchParams(); + for (const [key, value] of Object.entries(params)) { + if (value !== undefined && value !== null) + search.append(key, String(value)); + } + return search.toString() ? `?${search.toString()}` : ''; } export function setBaseURL(baseURL: any, apiKey: any) {