diff --git a/src/apis/index.ts b/src/apis/index.ts index 9daf9c1..e47dd23 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -31,3 +31,5 @@ export { Labels } from './labels'; export { Collections } from './collections'; export { Evals } from './evals'; export { Containers } from './containers'; +export { Integrations } from './integrations'; +export { Providers } from './providers'; diff --git a/src/apis/integrations.ts b/src/apis/integrations.ts new file mode 100644 index 0000000..c2c311d --- /dev/null +++ b/src/apis/integrations.ts @@ -0,0 +1,287 @@ +import { INTEGRATIONS_API } from '../constants'; +import { ApiResource } from '../apiResource'; +import { APIPromise, RequestOptions } from '../baseClient'; +import { ApiClientInterface } from '../_types/generalTypes'; +import { createHeaders } from './createHeaders'; +import { toQueryParams } from '../utils'; + +export interface IntegrationAddParams { + name?: string; + description?: string; + key?: string; + ai_provider_id?: string; + workspace_id?: string; + slug?: string; + configurations?: Record; +} + +export interface IntegrationListParams { + workspace_id?: string; + current_page?: number; + page_size?: number; + type?: 'workspace' | 'organisation' | 'all'; +} + +export interface IntegrationGetParams { + slug?: string; +} + +export interface IntegrationDeleteParams { + slug?: string; +} + +export interface IntegrationUpdateParams { + slug?: string; + name?: string; + description?: string; + key?: string; + configurations?: Record; +} + +export interface WorkspaceAccessUpdateParams { + slug?: string; + global_workspace_access?: Record; + override_existing_workspaces_access?: boolean; + workspaces?: Record[]; +} + +export interface WorkspaceAccessListParams { + slug: string; +} + +export interface ModelUpdateParams { + slug: string; + allow_all_models?: boolean; + models?: Record[]; +} + +export interface ModelListParams { + slug: string; +} + +export interface ModelDeleteParams { + slug: string; + slugs?: string; +} + +export class Integrations extends ApiResource { + workspaces: Workspaces; + models: Models; + + constructor(client: any) { + super(client); + this.workspaces = new Workspaces(client); + this.models = new Models(client); + } + + create( + _body: IntegrationAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post(`${INTEGRATIONS_API}`, { + body, + ...opts, + }); + return response; + } + + list( + _body?: IntegrationListParams, + 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(`${INTEGRATIONS_API}${query}`, { + ...opts, + }); + return response; + } + + retrieve( + _body: IntegrationGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`${INTEGRATIONS_API}/${slug}`, { + ...opts, + }); + return response; + } + + update( + _body: IntegrationUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = _body; + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`${INTEGRATIONS_API}/${slug}`, { + body: restBody, + ...opts, + }); + return response; + } + + delete( + _body: IntegrationDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.deleteMethod(`${INTEGRATIONS_API}/${slug}`, { + ...opts, + }); + return response; + } +} + +export class Workspaces extends ApiResource { + constructor(client: any) { + super(client); + } + + update( + _body: WorkspaceAccessUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`${INTEGRATIONS_API}/${slug}/workspaces`, { + body: restBody, + ...opts, + }); + return response; + } + + list( + _body: WorkspaceAccessListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod( + `${INTEGRATIONS_API}/${slug}/workspaces`, + { + ...opts, + } + ); + return response; + } +} + +export class Models extends ApiResource { + constructor(client: any) { + super(client); + } + + update( + _body: ModelUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`${INTEGRATIONS_API}/${slug}/models`, { + body: restBody, + ...opts, + }); + return response; + } + + list( + _body: ModelListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`${INTEGRATIONS_API}/${slug}/models`, { + ...opts, + }); + return response; + } + + delete( + _body: ModelDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const slug = body.slug; + const slugs = body.slugs; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = slugs ? `?slugs=${slugs}` : ''; + const response = this.deleteMethod( + `${INTEGRATIONS_API}/${slug}/models${query}`, + { + ...opts, + } + ); + return response; + } +} diff --git a/src/apis/providers.ts b/src/apis/providers.ts new file mode 100644 index 0000000..86abb61 --- /dev/null +++ b/src/apis/providers.ts @@ -0,0 +1,183 @@ +import { PROVIDERS_API } from '../constants'; +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 ProvidersListParams { + current_page?: number; + page_size?: number; + workspace_id?: string; +} + +export interface ProvidersListResponse extends APIResponseType { + object?: string; + total?: number; + data?: ProvidersResponse[]; +} + +export interface ProvidersCreateParams { + name: string; + integration_id: string; + workspace_id?: string; + slug?: string; + note?: string; + usage_limits?: Record; + rate_limits?: Record; + expires_at?: string; +} + +export interface ProvidersCreateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface ProvidersGetParams { + slug: string; + workspace_id?: string; +} + +export interface ProvidersResponse extends APIResponseType { + id?: string; + slug?: string; + name?: string; + note?: string; + integration_id?: string; + workspace_id?: string; + usage_limits?: Record; + rate_limits?: any[]; + expires_at?: string; + created_at?: Date; + last_updated_at?: Date; +} + +export interface ProvidersUpdateParams { + slug: string; + workspace_id?: string; + name?: string; + note?: string; + usage_limits?: Record; + rate_limits?: Record; + expires_at?: string; + reset_usage?: boolean; +} + +export interface ProvidersUpdateResponse extends APIResponseType { + id?: string; + slug?: string; +} + +export interface ProvidersDeleteParams { + slug: string; + workspace_id?: string; +} + +export class Providers extends ApiResource { + list( + _body?: ProvidersListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = body ? toQueryParams(body) : ''; + const response = this.getMethod( + `${PROVIDERS_API}${query}`, + { + ...opts, + } + ); + return response; + } + + create( + _body: ProvidersCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post(PROVIDERS_API, { + body, + ...opts, + }); + return response; + } + + retrieve( + _body: ProvidersGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...queryParams } = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.getMethod( + `${PROVIDERS_API}/${slug}${query}`, + { + ...opts, + } + ); + return response; + } + + update( + _body: ProvidersUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put( + `${PROVIDERS_API}/${slug}`, + { + body: restBody, + ...opts, + } + ); + return response; + } + + delete( + _body: ProvidersDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...queryParams } = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const query = toQueryParams(queryParams); + const response = this.deleteMethod( + `${PROVIDERS_API}/${slug}${query}`, + { + ...opts, + } + ); + return response; + } +} diff --git a/src/client.ts b/src/client.ts index 6f6e463..6acb311 100644 --- a/src/client.ts +++ b/src/client.ts @@ -210,6 +210,9 @@ export class Portkey extends ApiClient { apiKeys = new API.ApiKeys(this); configs = new API.Configs(this); logs = new API.Logs(this); + integrations = new API.Integrations(this); + providers = new API.Providers(this); + beta = { assistants: new API.Assistants(this), threads: new API.Threads(this), diff --git a/src/constants.ts b/src/constants.ts index 85505e1..12cc9fa 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -50,4 +50,6 @@ export const PROMPTS_API = '/prompts'; export const PROMPT_PARTIALS_API = '/prompts/partials'; export const LABELS_API = '/labels'; export const COLLECTIONS_API = '/collections'; +export const INTEGRATIONS_API = '/integrations'; +export const PROVIDERS_API = '/providers'; export const AUDIO_FILE_DURATION_HEADER = 'audio-file-duration';