diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index e216fe2..2655290 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -24,15 +24,15 @@ export interface ApiClientInterface { azureResourceName?: string | null | undefined; azureDeploymentId?: string | null | undefined; azureApiVersion?: string | null | undefined; - azureEndpointName?: string | null | undefined; + azureEndpointName?: string | null | undefined; huggingfaceBaseUrl?: string | null | undefined; forwardHeaders?: Array | null | undefined; cacheNamespace?: string | null | undefined; requestTimeout?: number | null | undefined; strictOpenAiCompliance?: boolean | null | undefined; anthropicBeta?: string | null | undefined; - anthropicVersion?: string | null | undefined; - mistralFimCompletion?: string | null | undefined; + anthropicVersion?: string | null | undefined; + mistralFimCompletion?: string | null | undefined; } export interface APIResponseType { diff --git a/src/_types/portkeyConstructs.ts b/src/_types/portkeyConstructs.ts index 7831aa2..6ced280 100644 --- a/src/_types/portkeyConstructs.ts +++ b/src/_types/portkeyConstructs.ts @@ -4,9 +4,9 @@ export interface RetrySettings { } export interface FunctionInterface { - name: string; - description: string; - parameters: string; + name: string; + description: string; + parameters: string; } export interface ModelParams { diff --git a/src/apiResource.ts b/src/apiResource.ts index a8ca244..9ae2993 100644 --- a/src/apiResource.ts +++ b/src/apiResource.ts @@ -4,14 +4,14 @@ export class ApiResource { protected client: Portkey; protected post: Portkey['_post']; protected put: Portkey['_put']; - protected getMethod: Portkey["_get"] - protected deleteMethod: Portkey["_delete"] + protected getMethod: Portkey['_get']; + protected deleteMethod: Portkey['_delete']; - constructor(client: Portkey) { - this.client = client - this.post = client._post.bind(client) - this.put = client._put.bind(client) - this.getMethod = client._get.bind(client) - this.deleteMethod = client._delete.bind(client) // delete is a reserved word - } + constructor(client: Portkey) { + this.client = client; + this.post = client._post.bind(client); + this.put = client._put.bind(client); + this.getMethod = client._get.bind(client); + this.deleteMethod = client._delete.bind(client); // delete is a reserved word + } } diff --git a/src/apis/admin.ts b/src/apis/admin.ts index 0f912a6..1b05aa7 100644 --- a/src/apis/admin.ts +++ b/src/apis/admin.ts @@ -1,494 +1,588 @@ -import { ApiResource } from "../apiResource"; -import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; -import { APIPromise, RequestOptions } from "../baseClient"; -import { createHeaders } from "./createHeaders"; -import { toQueryParams } from "../utils"; +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 UsersGetParams{ - userId?: string; +export interface UsersGetParams { + userId?: string; } export interface UsersGetResponse extends APIResponseType { - object?: string, - id?: string, - first_name?: string, - last_name?: string, - role?: string, - email?: string, - created_at?: Date, - last_updated_at?: Date - workspace_ids?: string[] + object?: string; + id?: string; + first_name?: string; + last_name?: string; + role?: string; + email?: string; + created_at?: Date; + last_updated_at?: Date; + workspace_ids?: string[]; } -export interface UsersListParams{ - pageSize?: number|string; - currentPage?: number; - email?: string; - role?: "admin" | "member" | "owner" | any; +export interface UsersListParams { + pageSize?: number | string; + currentPage?: number; + email?: string; + role?: 'admin' | 'member' | 'owner' | any; } export interface UsersListResponse extends APIResponseType { - total?: number, - object?: string, - data?: UsersGetResponse[] + total?: number; + object?: string; + data?: UsersGetResponse[]; } -export interface UsersUpdateParams{ - userId?: string, - role?: "admin" | "member" | any, +export interface UsersUpdateParams { + userId?: string; + role?: 'admin' | 'member' | any; } -export interface UsersDeleteParams{ - userId?: string; +export interface UsersDeleteParams { + userId?: string; } -export interface UserInviteParams{ - email?: string, - role?: string, - workspaces?: Record[] - workspace_api_key_details?: Record +export interface UserInviteParams { + email?: string; + role?: string; + workspaces?: Record[]; + workspace_api_key_details?: Record; } export interface UserInviteResponse extends APIResponseType { - id?: string, - invite_link?: string, + id?: string; + invite_link?: string; } -export interface UserInviteGetParams{ - inviteId?: string, +export interface UserInviteGetParams { + inviteId?: string; } export interface UserInviteGetResponse extends APIResponseType { - object?: string, - id?: string, - email?: string, - role?: "admin"| "member" | any, - created_at?: Date, - expires_at?: Date, - accepted_at?: Date|null, - status?: string - invited_by?: string + object?: string; + id?: string; + email?: string; + role?: 'admin' | 'member' | any; + created_at?: Date; + expires_at?: Date; + accepted_at?: Date | null; + status?: string; + invited_by?: string; } -export interface UserInviteListParams{ - email?: string, - role?: "admin" | "member" | any, - status?: "pending" | "accepted" | "expired"| "cancelled"| any, - pageSize?: number, - currentPage?: number +export interface UserInviteListParams { + email?: string; + role?: 'admin' | 'member' | any; + status?: 'pending' | 'accepted' | 'expired' | 'cancelled' | any; + pageSize?: number; + currentPage?: number; } export interface UserInviteListResponse extends APIResponseType { - object?: string, - total?: number, - data?: UserInviteGetResponse[] + object?: string; + total?: number; + data?: UserInviteGetResponse[]; } export interface UserInviteDeleteParams { - inviteId?: string, + inviteId?: string; } -export interface WorkspacesAddParams{ - name?: string, - description?: string, - defaults?: Record, - users?: string[], +export interface WorkspacesAddParams { + name?: string; + description?: string; + defaults?: Record; + users?: string[]; } export interface WorkspacesAddResponse extends APIResponseType { - id?: string, - slug?: string, - name?: string, - description?: string, - created_at?: Date, - last_updated_at?: Date, - defaults?: Record, - users?: Record[], - object?: string, + id?: string; + slug?: string; + name?: string; + description?: string; + created_at?: Date; + last_updated_at?: Date; + defaults?: Record; + users?: Record[]; + object?: string; } export interface WorkspacesGetParams { - workspaceId?: string; + workspaceId?: string; } export interface WorkspacesGetResponse extends APIResponseType { - id?: string, - slug?: string, - name?: string, - description?: string, - created_at?: Date, - last_updated_at?: Date, - defaults?: Record | null, - users?: Record[], + id?: string; + slug?: string; + name?: string; + description?: string; + created_at?: Date; + last_updated_at?: Date; + defaults?: Record | null; + users?: Record[]; } export interface WorkspacesListParams { - page_size?: number; - current_page?: number; + page_size?: number; + current_page?: number; } export interface WorkspacesListResponse extends APIResponseType { - total?: number, - object?: string, - data?: WorkspacesGetResponse[] + total?: number; + object?: string; + data?: WorkspacesGetResponse[]; } -export interface WorkspacesUpdateParams{ - workspaceId?: string, - name?: string, - description?: string, - defaults?: Record, +export interface WorkspacesUpdateParams { + workspaceId?: string; + name?: string; + description?: string; + defaults?: Record; } export interface WorkspacesUpdateResponse extends APIResponseType { - id?: string, - slug?: string, - name?: string, - description?: string, - created_at?: Date, - is_default?:number, - last_updated_at?: Date, - defaults?: Record, - object?: string, + id?: string; + slug?: string; + name?: string; + description?: string; + created_at?: Date; + is_default?: number; + last_updated_at?: Date; + defaults?: Record; + object?: string; } -export interface WorkspacesDeleteParams{ - workspaceId?: string; - name?: string; +export interface WorkspacesDeleteParams { + workspaceId?: string; + name?: string; } -export interface WorkspaceMemberAddParams{ - workspaceId?: string, - users?: { id: string, role: "member" | "admin" }[], +export interface WorkspaceMemberAddParams { + workspaceId?: string; + users?: { id: string; role: 'member' | 'admin' }[]; } -export interface WorkspaceMemberGetParams{ - workspaceId?: string, - userId?: string, +export interface WorkspaceMemberGetParams { + workspaceId?: string; + userId?: string; } export interface WorkspaceMemberGetResponse extends APIResponseType { - first_name?: string, - last_name?: string, - org_role?: string, - role?: string, - created_at?: Date, - last_updated_at?: Date, - status?: string - workspace_id?: string, - scopes?: string[], - settings?: Record| null, - object?: string, + first_name?: string; + last_name?: string; + org_role?: string; + role?: string; + created_at?: Date; + last_updated_at?: Date; + status?: string; + workspace_id?: string; + scopes?: string[]; + settings?: Record | null; + object?: string; } export interface WorkspaceMemberListParams { - workspaceId?: string, - page_size?: number, - current_page?: number, - email?: string, - role?: "admin" | "manager" | "member" | any, + workspaceId?: string; + page_size?: number; + current_page?: number; + email?: string; + role?: 'admin' | 'manager' | 'member' | any; } export interface WorkspaceMemberListResponse extends APIResponseType { - total?: number, - object?: string, - data?: WorkspaceMemberGetResponse[] + total?: number; + object?: string; + data?: WorkspaceMemberGetResponse[]; } -export interface WorkspaceMemberDeleteParams{ - workspaceId?: string, - userId?: string, +export interface WorkspaceMemberDeleteParams { + workspaceId?: string; + userId?: string; } -export interface WorkspaceMemberUpdateParams{ - workspaceId?: string, - userId?: string, - role?: "admin" | "member" | any, +export interface WorkspaceMemberUpdateParams { + workspaceId?: string; + userId?: string; + role?: 'admin' | 'member' | any; } // Function to convert UsersGetParams to query parameters - export class Admin extends ApiResource { - users: Users - workspaces: Workspaces - constructor(client: any) { - super(client); - this.users = new Users(client); - this.workspaces= new Workspaces(client); - } + users: Users; + workspaces: Workspaces; + constructor(client: any) { + super(client); + this.users = new Users(client); + this.workspaces = new Workspaces(client); + } } - export class Users extends ApiResource { - - invites: Invites= new Invites(this.client); - - retrieve( - _body: UsersGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const userId = body.userId; - - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/admin/users/${userId}`, {...opts }); - return response; + invites: Invites = new Invites(this.client); + + retrieve( + _body: UsersGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const userId = body.userId; + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - list( - _body: UsersListParams, - 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(`/admin/users${query}`, { ...opts }); - return response; + const response = this.getMethod( + `/admin/users/${userId}`, + { ...opts } + ); + return response; + } + + list( + _body: UsersListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - update( - _body: UsersUpdateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const userId = body.userId; - delete body.userId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.put(`/admin/users/${userId}`, { body, ...opts }); - return response; + const query = toQueryParams(body); + const response = this.getMethod(`/admin/users${query}`, { + ...opts, + }); + return response; + } + + update( + _body: UsersUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const userId = body.userId; + delete body.userId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - delete( - _body: UsersDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const userId = body.userId; - if (params){ - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/admin/users/${userId}`, { body, ...opts }); - return response; + const response = this.put(`/admin/users/${userId}`, { body, ...opts }); + return response; + } + + delete( + _body: UsersDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const userId = body.userId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - + const response = this.deleteMethod(`/admin/users/${userId}`, { + body, + ...opts, + }); + return response; + } } - export class Invites extends ApiResource { - - - create( - _body: UserInviteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post('/admin/users/invites', { body, ...opts }); - return response; + create( + _body: UserInviteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - retrieve( - _body: UserInviteGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body=_body; - const inviteId = body.inviteId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/admin/users/invites/${inviteId}`, { ...opts }); - return response; + const response = this.post('/admin/users/invites', { + body, + ...opts, + }); + return response; + } + + retrieve( + _body: UserInviteGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const inviteId = body.inviteId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - list( - _body?: UserInviteListParams, - 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(`/admin/users/invites${query}`, { ...opts }); - return response; + const response = this.getMethod( + `/admin/users/invites/${inviteId}`, + { ...opts } + ); + return response; + } + + list( + _body?: UserInviteListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - delete( - _body: UserInviteDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const inviteId = body.inviteId; - if (params){ - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/admin/users/invites/${inviteId}`, { body, ...opts }); - return response; + const query = body ? toQueryParams(body) : ''; + const response = this.getMethod( + `/admin/users/invites${query}`, + { ...opts } + ); + return response; + } + + delete( + _body: UserInviteDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const inviteId = body.inviteId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - + const response = this.deleteMethod( + `/admin/users/invites/${inviteId}`, + { body, ...opts } + ); + return response; + } } export class Workspaces extends ApiResource { - users: Member = new Member(this.client); - - create( - _body: WorkspacesAddParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post('/admin/workspaces', { body, ...opts }); - return response; + users: Member = new Member(this.client); + + create( + _body: WorkspacesAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - retrieve( - _body: WorkspacesGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/admin/workspaces/${workspaceId}`, { ...opts }); - return response; + const response = this.post('/admin/workspaces', { + body, + ...opts, + }); + return response; + } + retrieve( + _body: WorkspacesGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - list( - _body: WorkspacesListParams, - 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(`/admin/workspaces${query}`, { ...opts }); - return response; + const response = this.getMethod( + `/admin/workspaces/${workspaceId}`, + { ...opts } + ); + return response; + } + + list( + _body: WorkspacesListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - update( - _body: WorkspacesUpdateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - delete body.workspaceId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.put(`/admin/workspaces/${workspaceId}`, { body, ...opts }); - return response; + const query = toQueryParams(body); + const response = this.getMethod( + `/admin/workspaces${query}`, + { ...opts } + ); + return response; + } + + update( + _body: WorkspacesUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + delete body.workspaceId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - delete( - _body: WorkspacesDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - if (params){ - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/admin/workspaces/${workspaceId}`, { body, ...opts }); - return response; + const response = this.put( + `/admin/workspaces/${workspaceId}`, + { body, ...opts } + ); + return response; + } + + delete( + _body: WorkspacesDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - + const response = this.deleteMethod( + `/admin/workspaces/${workspaceId}`, + { body, ...opts } + ); + return response; + } } export class Member extends ApiResource { - - create( - _body: WorkspaceMemberAddParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post(`/admin/workspaces/${workspaceId}/users`, { body, ...opts }); - return response; + create( + _body: WorkspaceMemberAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - retrieve( - _body: WorkspaceMemberGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - const userId = body.userId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/admin/workspaces/${workspaceId}/users/${userId}`, { ...opts }); - return response; + const response = this.post(`/admin/workspaces/${workspaceId}/users`, { + body, + ...opts, + }); + return response; + } + + retrieve( + _body: WorkspaceMemberGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + const userId = body.userId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - list( - _body: WorkspaceMemberListParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const query = toQueryParams(body); - const response = this.getMethod(`/admin/workspaces/${workspaceId}/users${query}`, { ...opts }); - return response; + const response = this.getMethod( + `/admin/workspaces/${workspaceId}/users/${userId}`, + { ...opts } + ); + return response; + } + + list( + _body: WorkspaceMemberListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - - delete( - _body: WorkspaceMemberDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - const userId = body.userId; - if (params){ - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/admin/workspaces/${workspaceId}/users/${userId}`, { body, ...opts }); - return response; + const query = toQueryParams(body); + const response = this.getMethod( + `/admin/workspaces/${workspaceId}/users${query}`, + { ...opts } + ); + return response; + } + + delete( + _body: WorkspaceMemberDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + const userId = body.userId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - update( - _body: WorkspaceMemberUpdateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const workspaceId = body.workspaceId; - const userId = body.userId; - delete body.workspaceId; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.put(`/admin/workspaces/${workspaceId}/users/${userId}`, { body, ...opts }); - return response; + const response = this.deleteMethod( + `/admin/workspaces/${workspaceId}/users/${userId}`, + { body, ...opts } + ); + return response; + } + update( + _body: WorkspaceMemberUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const workspaceId = body.workspaceId; + const userId = body.userId; + delete body.workspaceId; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } -} \ No newline at end of file + const response = this.put( + `/admin/workspaces/${workspaceId}/users/${userId}`, + { body, ...opts } + ); + return response; + } +} diff --git a/src/apis/apiKeys.ts b/src/apis/apiKeys.ts index 84ba40d..f30196e 100644 --- a/src/apis/apiKeys.ts +++ b/src/apis/apiKeys.ts @@ -1,138 +1,163 @@ -import { ApiResource } from "../apiResource"; -import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; -import { APIPromise, RequestOptions } from "../baseClient"; -import { createHeaders } from "./createHeaders"; -import { toQueryParams } from "../utils"; +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 ApiKeysAddParams { - type?: string; - "sub-type"?: string; - name?: string; - description?: string; - workspace_id?:string; - user_id?:string; - rate_limits?: Record[]; - usage_limits?: Record; - scopes: string[]; - defaults?: Record; + type?: string; + 'sub-type'?: string; + name?: string; + description?: string; + workspace_id?: string; + user_id?: string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes: string[]; + defaults?: Record; } export interface ApiKeysAddResponse extends APIResponseType { - id?: string; - key?: string; - object?: string; + id?: string; + key?: string; + object?: string; } export interface ApiKeysGetParams { - id?: string; + id?: string; } export interface ApiKeysGetResponse extends APIResponseType { - id?: string; - key?: string; - name?: string; - description?: string; - type?: string; - organisation_id?: string; - workspace_id?: string; - user_id?: string; - status?: string; - created_at?: Date; - last_updated_at?: Date; - creation_mode?: string; - rate_limits?: Record[]; - usage_limits?: Record; - reset_usage?:number; - scopes?: string[]; - defaults?: Record; - object?: string; + id?: string; + key?: string; + name?: string; + description?: string; + type?: string; + organisation_id?: string; + workspace_id?: string; + user_id?: string; + status?: string; + created_at?: Date; + last_updated_at?: Date; + creation_mode?: string; + rate_limits?: Record[]; + usage_limits?: Record; + reset_usage?: number; + scopes?: string[]; + defaults?: Record; + object?: string; } export interface ApiKeysUpdateParams { - id?: string; - name?: string; - description?: string; - rate_limits?: Record[]; - usage_limits?: Record; - scopes?: string[]; - defaults?: Record; + id?: string; + name?: string; + description?: string; + rate_limits?: Record[]; + usage_limits?: Record; + scopes?: string[]; + defaults?: Record; } export interface ApiKeysListParams { - page_size?: number; - current_page?: number; - workspace_id?: string; + page_size?: number; + current_page?: number; + workspace_id?: string; } export interface ApiKeysListResponse extends APIResponseType { - total?: number; - object?: string; - data?: Record[]; + total?: number; + object?: string; + data?: Record[]; } export interface ApiKeysDeleteParams { - id?: string; + id?: string; } export class ApiKeys extends ApiResource { - create( - _body: ApiKeysAddParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const type = body.type; - const subType = body["sub-type"]; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post(`/api-keys/${type}/${subType}`, { body, ...opts }); - return response; - } + create( + _body: ApiKeysAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const type = body.type; + const subType = body['sub-type']; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.post( + `/api-keys/${type}/${subType}`, + { body, ...opts } + ); + return response; + } - retrieve( - _body: ApiKeysGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const id = body.id; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/api-keys/${id}`, { ...opts }); - return response; - } + retrieve( + _body: ApiKeysGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const id = body.id; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.getMethod(`/api-keys/${id}`, { + ...opts, + }); + return response; + } - update( - _body: ApiKeysUpdateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - const id = body.id; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.put(`/api-keys/${id}`, { body, ...opts }); - return response; - } - list( - _body: ApiKeysListParams, - 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(`/api-keys${query}`, {...opts }); - return response; + update( + _body: ApiKeysUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const id = body.id; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; + } + const response = this.put(`/api-keys/${id}`, { body, ...opts }); + return response; + } + list( + _body: ApiKeysListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - delete( - _body: ApiKeysDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ):APIPromise{ - const body = _body; - const id=body.id; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/api-keys/${id}`, { body, ...opts }); - return response; + const query = toQueryParams(body); + const response = this.getMethod(`/api-keys${query}`, { + ...opts, + }); + return response; + } + delete( + _body: ApiKeysDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const id = body.id; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } + const response = this.deleteMethod(`/api-keys/${id}`, { + body, + ...opts, + }); + return response; + } } diff --git a/src/apis/assistants.ts b/src/apis/assistants.ts index e5f45b6..efe08cd 100644 --- a/src/apis/assistants.ts +++ b/src/apis/assistants.ts @@ -5,17 +5,17 @@ import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; export interface AssistantCreateParams { - model: string; - description?: string | null; - instructions?: string | null; - metadata?: unknown | null; - name?: string | null; - tools?: Array; - response_format?: any | null; - temperature?: number | null; - tool_resources?: any | null; - top_p?: number | null; - [key: string]: any; + model: string; + description?: string | null; + instructions?: string | null; + metadata?: unknown | null; + name?: string | null; + tools?: Array; + response_format?: any | null; + temperature?: number | null; + tool_resources?: any | null; + top_p?: number | null; + [key: string]: any; } export interface FileCreateParams { @@ -28,9 +28,9 @@ export interface FileListParams extends CursorPageParams { } export interface CursorPageParams { - after?: string; - limit?: number; - [key: string]: any; + after?: string; + limit?: number; + [key: string]: any; } export interface AssistantListParams extends CursorPageParams { @@ -39,14 +39,14 @@ export interface AssistantListParams extends CursorPageParams { } export interface AssistantUpdateParams { - description?: string | null; - file_ids?: Array; - instructions?: string | null; - metadata?: unknown | null; - model?: string; - name?: string | null; - tools?: Array; - [key: string]: any; + description?: string | null; + file_ids?: Array; + instructions?: string | null; + metadata?: unknown | null; + model?: string; + name?: string | null; + tools?: Array; + [key: string]: any; } export class Assistants extends ApiResource { diff --git a/src/apis/betaChat.ts b/src/apis/betaChat.ts index b612a08..ac58edf 100644 --- a/src/apis/betaChat.ts +++ b/src/apis/betaChat.ts @@ -11,9 +11,8 @@ import { import { ChatCompletionStreamingFunctionRunnerParams, ChatCompletionStreamingToolRunnerParams, -} from "openai/lib/ChatCompletionStreamingRunner"; -import { ChatCompletionParseParams } from "openai/resources/beta/chat/completions"; - +} from 'openai/lib/ChatCompletionStreamingRunner'; +import { ChatCompletionParseParams } from 'openai/resources/beta/chat/completions'; export class BetaChat extends ApiResource { completions: Completions; diff --git a/src/apis/configs.ts b/src/apis/configs.ts index e0fdf6d..fc56615 100644 --- a/src/apis/configs.ts +++ b/src/apis/configs.ts @@ -1,132 +1,158 @@ -import { ApiResource } from "../apiResource"; -import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; -import { APIPromise, RequestOptions } from "../baseClient"; -import { createHeaders } from "./createHeaders"; -import { toQueryParams } from "../utils"; +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 ConfigsAddParams { - name?: string; - config?: Record; - isDefault?: number; - workspace_id?:string; + name?: string; + config?: Record; + isDefault?: number; + workspace_id?: string; } export interface ConfigsAddResponse extends APIResponseType { - id?: string; - version_id?: string; - slug?: string; - object?: string; + id?: string; + version_id?: string; + slug?: string; + object?: string; } export interface ConfigsGetParams { - slug?: string; + slug?: string; } export interface ConfigsGetResponse extends APIResponseType { - id?: string; - name?: string; - workspace_id?: string; - slug?: string; - organization_id?: string; - is_default?: number; - status?: string; - owner_id?: string; - created_at?: string; - updated_by?: string; - last_updated_at?: string; - config?: Record; - format?: string; - type?: string; - version_id?: string; - object?: string; + id?: string; + name?: string; + workspace_id?: string; + slug?: string; + organization_id?: string; + is_default?: number; + status?: string; + owner_id?: string; + created_at?: string; + updated_by?: string; + last_updated_at?: string; + config?: Record; + format?: string; + type?: string; + version_id?: string; + object?: string; } export interface CongfigsListParams { - workspace_id?: string; + workspace_id?: string; } export interface ConfigsListResponse extends APIResponseType { - object?: boolean; - total?: number; - data?: Record[]; + object?: boolean; + total?: number; + data?: Record[]; } export interface ConfigsUpdateParams { - slug?: string; - name?: string; - config?: Record; - status?: string; + slug?: string; + name?: string; + config?: Record; + status?: string; } export interface ConfigsUpdateResponse extends APIResponseType { - version_id?: string; - object?: string; + version_id?: string; + object?: string; } export interface ConfigsDeleteParams { - id?: string; + id?: string; } export class Configs extends ApiResource { - constructor(client: any) { - super(client); + constructor(client: any) { + super(client); + } + create( + _body: ConfigsAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - create( - _body: ConfigsAddParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const body = _body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post('/configs', { body, ...opts }); - return response; - } + const response = this.post('/configs', { + body, + ...opts, + }); + return response; + } - retrieve( - _body: ConfigsGetParams, - 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(`/configs/${slug}`, { ...opts }); - return response; - } + retrieve( + _body: ConfigsGetParams, + 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(`/configs/${slug}`, { + ...opts, + }); + return response; + } - update( - _body: ConfigsUpdateParams, - 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.put(`/configs/${slug}`, { body, ...opts }); - return response; - } - list( - _body?:CongfigsListParams, - params?: ApiClientInterface, - opts?: RequestOptions - ):APIPromise{ - const body = _body; - const query = toQueryParams(body); - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/configs${query}`, {...opts}); - return response; + update( + _body: ConfigsUpdateParams, + 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.put(`/configs/${slug}`, { + body, + ...opts, + }); + return response; + } + list( + _body?: CongfigsListParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const query = toQueryParams(body); + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } - delete( - _body:ConfigsDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ):APIPromise{ - const body = _body; - const configId = body.id; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/configs/${configId}`, {...opts}); - return response; + const response = this.getMethod(`/configs${query}`, { + ...opts, + }); + return response; + } + delete( + _body: ConfigsDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const body = _body; + const configId = body.id; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } + const response = this.deleteMethod(`/configs/${configId}`, { + ...opts, + }); + return response; + } } - diff --git a/src/apis/embeddings.ts b/src/apis/embeddings.ts index 68403a6..de7c1b1 100644 --- a/src/apis/embeddings.ts +++ b/src/apis/embeddings.ts @@ -7,10 +7,10 @@ import { overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; export interface EmbeddingsBody extends ModelParams { - input: string | number | (string | number)[] | (string | number)[][]; - model?: string; - dimensions?: number; - encoding_format?: string; + input: string | number | (string | number)[] | (string | number)[][]; + model?: string; + dimensions?: number; + encoding_format?: string; } export type EmbeddingsResponse = Record & APIResponseType; diff --git a/src/apis/files.ts b/src/apis/files.ts index 3cd1255..c410885 100644 --- a/src/apis/files.ts +++ b/src/apis/files.ts @@ -131,9 +131,9 @@ export class MainFiles extends ApiResource { } export interface FileCreateParams { - file: any; - purpose?: string; - [key: string]: any; + file: any; + purpose?: string; + [key: string]: any; } export interface FileObject { @@ -148,6 +148,6 @@ export interface FileObject { } export interface FileListParams { - purpose?: string; - [key: string]: any; - } \ No newline at end of file + purpose?: string; + [key: string]: any; +} diff --git a/src/apis/images.ts b/src/apis/images.ts index 2f08b5d..8282cc9 100644 --- a/src/apis/images.ts +++ b/src/apis/images.ts @@ -17,25 +17,25 @@ export interface ImagesBody { } export interface ImageEditParams { - image: any; - prompt: string; - mask?: any; - model?: string | null; - n?: number | null; - response_format?: string | null; - size?: string | null; - user?: string; - [key: string]: any; + image: any; + prompt: string; + mask?: any; + model?: string | null; + n?: number | null; + response_format?: string | null; + size?: string | null; + user?: string; + [key: string]: any; } export interface ImageCreateVariationParams { - image: any; - model?: string | null; - n?: number | null; - response_format?: string | null; - size?: string | null; - user?: string; - [key: string]: any; + image: any; + model?: string | null; + n?: number | null; + response_format?: string | null; + size?: string | null; + user?: string; + [key: string]: any; } export interface ImagesResponse { diff --git a/src/apis/index.ts b/src/apis/index.ts index 6deac4b..92b00e0 100644 --- a/src/apis/index.ts +++ b/src/apis/index.ts @@ -1,23 +1,23 @@ -export { Chat } from "./chatCompletions"; -export { Completions } from "./completions"; -export { createHeaders } from "./createHeaders"; -export { Feedback } from "./feedback"; -export { Generations, Prompt } from "./generations"; -export { postMethod } from "./postMethod"; -export { Embeddings } from "./embeddings"; -export { Images } from "./images"; -export { Assistants } from "./assistants"; -export { Threads } from "./threads"; -export { MainFiles } from "./files"; -export { Models } from "./models"; -export { Admin } from "./admin"; -export { Configs } from "./configs"; -export { Batches } from "./batches"; -export { VirtualKeys } from "./virtualKeys"; -export { FineTuning } from "./fineTuning" -export { Moderations } from "./moderations" -export { Audio } from "./audio" -export { VectorStores } from "./vectorStores" -export { BetaChat } from "./betaChat" -export { Uploads } from "./uploads" -export { ApiKeys } from "./apiKeys" +export { Chat } from './chatCompletions'; +export { Completions } from './completions'; +export { createHeaders } from './createHeaders'; +export { Feedback } from './feedback'; +export { Generations, Prompt } from './generations'; +export { postMethod } from './postMethod'; +export { Embeddings } from './embeddings'; +export { Images } from './images'; +export { Assistants } from './assistants'; +export { Threads } from './threads'; +export { MainFiles } from './files'; +export { Models } from './models'; +export { Admin } from './admin'; +export { Configs } from './configs'; +export { Batches } from './batches'; +export { VirtualKeys } from './virtualKeys'; +export { FineTuning } from './fineTuning'; +export { Moderations } from './moderations'; +export { Audio } from './audio'; +export { VectorStores } from './vectorStores'; +export { BetaChat } from './betaChat'; +export { Uploads } from './uploads'; +export { ApiKeys } from './apiKeys'; diff --git a/src/apis/moderations.ts b/src/apis/moderations.ts index 00e2b37..c908745 100644 --- a/src/apis/moderations.ts +++ b/src/apis/moderations.ts @@ -5,25 +5,25 @@ import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; import { createHeaders } from './createHeaders'; export interface ModerationCreateParams { - input: string | Array; - model?: any ; - [key: string]: any; + input: string | Array; + model?: any; + [key: string]: any; } -export class Moderations extends ApiResource{ - async create( - _body: ModerationCreateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): Promise { - const body: ModerationCreateParams = _body; - if (params) { - const config = overrideConfig(this.client.config, params.config); - this.client.customHeaders = { - ...this.client.customHeaders, - ...createHeaders({ ...params, config }), - }; - } +export class Moderations extends ApiResource { + async create( + _body: ModerationCreateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): Promise { + const body: ModerationCreateParams = _body; + if (params) { + const config = overrideConfig(this.client.config, params.config); + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params, config }), + }; + } const OAIclient = initOpenAIClient(this.client); diff --git a/src/apis/threads.ts b/src/apis/threads.ts index 7094e7d..bedc7c5 100644 --- a/src/apis/threads.ts +++ b/src/apis/threads.ts @@ -633,9 +633,9 @@ export class Steps extends ApiResource { } export interface ThreadCreateParams { - messages?: Array; - metadata?: unknown | null; - [key: string]: any; + messages?: Array; + metadata?: unknown | null; + [key: string]: any; } export interface Message { @@ -646,16 +646,16 @@ export interface Message { } export interface ThreadUpdateParams { - metadata?: unknown | null; - [key: string]: any; + metadata?: unknown | null; + [key: string]: any; } export interface MessageCreateParams { - content: string; - role: string; - file_ids?: Array; - metadata?: unknown | null; - [key: string]: any; + content: string; + role: string; + file_ids?: Array; + metadata?: unknown | null; + [key: string]: any; } export interface MessageListParams extends CursorPageParams { @@ -674,8 +674,8 @@ export interface FileListParams extends CursorPageParams { } export interface MessageUpdateParams { - metadata?: unknown | null; - [key: string]: any; + metadata?: unknown | null; + [key: string]: any; } export interface RunCreateParams { @@ -723,13 +723,13 @@ export interface StepListParams extends CursorPageParams { } export interface RunUpdateParams { - metadata?: unknown | null; - [key: string]: any; + metadata?: unknown | null; + [key: string]: any; } export interface RunSubmitToolOutputsParams { - tool_outputs: Array; - [key: string]: any; + tool_outputs: Array; + [key: string]: any; } export interface ToolOutput { diff --git a/src/apis/uploads.ts b/src/apis/uploads.ts index 44468f4..4fd901b 100644 --- a/src/apis/uploads.ts +++ b/src/apis/uploads.ts @@ -1,9 +1,9 @@ -import { ApiClientInterface } from "../_types/generalTypes"; -import { ApiResource } from "../apiResource"; -import { RequestOptions } from "../baseClient"; -import { finalResponse, initOpenAIClient, overrideConfig } from "../utils"; -import { createHeaders } from "./createHeaders"; -import { Uploadable } from "openai/uploads"; +import { ApiClientInterface } from '../_types/generalTypes'; +import { ApiResource } from '../apiResource'; +import { RequestOptions } from '../baseClient'; +import { finalResponse, initOpenAIClient, overrideConfig } from '../utils'; +import { createHeaders } from './createHeaders'; +import { Uploadable } from 'openai/uploads'; export interface UploadCompleteParams { part_ids: Array; diff --git a/src/apis/vectorStores.ts b/src/apis/vectorStores.ts index f6be176..05d0485 100644 --- a/src/apis/vectorStores.ts +++ b/src/apis/vectorStores.ts @@ -534,21 +534,21 @@ export interface CursorPageParams { } export interface FileCreateParams { - file_id: string; - [key: string]: any; + file_id: string; + [key: string]: any; } export interface FileListParams extends CursorPageParams { - before?: string; - filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled'; - order?: 'asc' | 'desc'; - [key: string]: any; - } + before?: string; + filter?: 'in_progress' | 'completed' | 'failed' | 'cancelled'; + order?: 'asc' | 'desc'; + [key: string]: any; +} - export interface FileBatchCreateParams { - file_ids: Array; - [key: string]: any; - } +export interface FileBatchCreateParams { + file_ids: Array; + [key: string]: any; +} export interface FileBatchListFilesParams extends CursorPageParams { before?: string; diff --git a/src/apis/virtualKeys.ts b/src/apis/virtualKeys.ts index 9af0437..4ad3dd3 100644 --- a/src/apis/virtualKeys.ts +++ b/src/apis/virtualKeys.ts @@ -1,135 +1,163 @@ -import { ApiResource } from "../apiResource"; -import { APIResponseType, ApiClientInterface } from "../_types/generalTypes"; -import { APIPromise, RequestOptions } from "../baseClient"; -import { createHeaders } from "./createHeaders"; -import { toQueryParams } from "../utils"; +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 VirtualKeysAddParams { - name?: string; - provider?: string; - key?: string; - note?: string | null; - apiVersion?: string | null; - resourceName?: string | null; - deploymentName?: string | null; - workspace_id?: string; - usage_limits?: Record; - [key: string]: any; + name?: string; + provider?: string; + key?: string; + note?: string | null; + apiVersion?: string | null; + resourceName?: string | null; + deploymentName?: string | null; + workspace_id?: string; + usage_limits?: Record; + [key: string]: any; } export interface VirtualKeysAddResponse extends APIResponseType { - id?: string; - slug?:string; - object?: string; + id?: string; + slug?: string; + object?: string; } export interface VirtualKeysGetParams { - slug?: string; + slug?: string; } export interface VirtualKeysGetResponse extends APIResponseType { - id?: string, - ai_provider_name?: string, - model_config?: Record, - masked_api_key?: string, - slug?: string, - name?: string, - usage_limits?: Record, - status?: string, - note?: null|string, - created_at?: Date, - rate_limits?: Record[], - object?: string, + id?: string; + ai_provider_name?: string; + model_config?: Record; + masked_api_key?: string; + slug?: string; + name?: string; + usage_limits?: Record; + status?: string; + note?: null | string; + created_at?: Date; + rate_limits?: Record[]; + object?: string; } export interface VirtualKeysListParams { - workspace_id?: string; + workspace_id?: string; } export interface VirtualKeysListResponse extends APIResponseType { - object?:string, - total?:number, - data?: VirtualKeysGetResponse[]; + object?: string; + total?: number; + data?: VirtualKeysGetResponse[]; } export interface VirtualKeysUpdateParams { - slug?: string; - name?: string; - key?: string; - note?: string | null; - usage_limits?: Record; - rate_limits?: Record[]; - [key: string]: any; + slug?: string; + name?: string; + key?: string; + note?: string | null; + usage_limits?: Record; + rate_limits?: Record[]; + [key: string]: any; } export interface VirtualKeysUpdateResponse extends APIResponseType { - id?:string; - slug?:string; - object?: string; + id?: string; + slug?: string; + object?: string; } export interface VirtualKeysDeleteParams { - slug?: string; + slug?: string; } - export class VirtualKeys extends ApiResource { - create( - body: VirtualKeysAddParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.post('/virtual-keys', { body, ...opts }); - return response; + create( + body: VirtualKeysAddParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } + const response = this.post('/virtual-keys', { + body, + ...opts, + }); + return response; + } - list( - _body?: VirtualKeysListParams, - 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(`/virtual-keys${query}`, { ...opts }); - return response; + list( + _body?: VirtualKeysListParams, + 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( + `/virtual-keys${query}`, + { ...opts } + ); + return response; + } - retrieve( - body: VirtualKeysGetParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const { slug } = body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.getMethod(`/virtual-keys/${slug}`, { ...opts }); - return response; + retrieve( + body: VirtualKeysGetParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } + const response = this.getMethod( + `/virtual-keys/${slug}`, + { ...opts } + ); + return response; + } - update( - body: VirtualKeysUpdateParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const { slug, ...restBody } = body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.put(`/virtual-keys/${slug}`, { body: restBody, ...opts }); - return response; + update( + body: VirtualKeysUpdateParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug, ...restBody } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } + const response = this.put( + `/virtual-keys/${slug}`, + { body: restBody, ...opts } + ); + return response; + } - delete( - body: VirtualKeysDeleteParams, - params?: ApiClientInterface, - opts?: RequestOptions - ): APIPromise { - const { slug } = body; - if (params) { - this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params }) } - } - const response = this.deleteMethod(`/virtual-keys/${slug}`, { ...opts }); - return response; + delete( + body: VirtualKeysDeleteParams, + params?: ApiClientInterface, + opts?: RequestOptions + ): APIPromise { + const { slug } = body; + if (params) { + this.client.customHeaders = { + ...this.client.customHeaders, + ...createHeaders({ ...params }), + }; } -} \ No newline at end of file + const response = this.deleteMethod(`/virtual-keys/${slug}`, { + ...opts, + }); + return response; + } +} diff --git a/src/baseClient.ts b/src/baseClient.ts index 9b3b384..2ad0aa7 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -161,15 +161,16 @@ export abstract class ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, + azureEndpointName, huggingfaceBaseUrl, forwardHeaders, cacheNamespace, requestTimeout, strictOpenAiCompliance, - anthropicBeta, - anthropicVersion, - mistralFimCompletion }: ApiClientInterface) { + anthropicBeta, + anthropicVersion, + mistralFimCompletion, + }: ApiClientInterface) { this.apiKey = apiKey ?? ''; this.baseURL = baseURL ?? ''; this.customHeaders = createHeaders({ @@ -196,10 +197,13 @@ export abstract class ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, huggingfaceBaseUrl, + azureEndpointName, + huggingfaceBaseUrl, forwardHeaders, requestTimeout, - strictOpenAiCompliance, anthropicVersion, mistralFimCompletion, + strictOpenAiCompliance, + anthropicVersion, + mistralFimCompletion, anthropicBeta, }); this.portkeyHeaders = this.defaultHeaders(); @@ -229,13 +233,19 @@ export abstract class ApiClient { return this.methodRequest('put', path, opts); } - _get(path:string, opts?: RequestOptions): APIPromise { - return this.methodRequest("get", path, opts); - } + _get( + path: string, + opts?: RequestOptions + ): APIPromise { + return this.methodRequest('get', path, opts); + } - _delete(path: string, opts?: RequestOptions): APIPromise { - return this.methodRequest("delete", path, opts); - } + _delete( + path: string, + opts?: RequestOptions + ): APIPromise { + return this.methodRequest('delete', path, opts); + } protected generateError( status: number | undefined, @@ -274,30 +284,31 @@ export abstract class ApiClient { return { response, options: opts, responseHeaders: response.headers }; } - buildRequest(opts: FinalRequestOptions): { req: RequestInit, url: string } { - const url = new URL(this.baseURL + opts.path!) - const { method, body } = opts; - const reqHeaders: Record = { - ...this.defaultHeaders(), ...this.customHeaders, - }; - const httpAgent: Agent | undefined = defaultHttpAgent - let req: RequestInit; - if (method === "get"){ - req = { - method, - headers: reqHeaders, - ...(httpAgent && { agent: httpAgent }) - } - } else { - req = { - method, - body: JSON.stringify(parseBody(body)), - headers: reqHeaders, - ...(httpAgent && { agent: httpAgent }) - } - } - return { req: req, url: url.toString() } + buildRequest(opts: FinalRequestOptions): { req: RequestInit; url: string } { + const url = new URL(this.baseURL + opts.path!); + const { method, body } = opts; + const reqHeaders: Record = { + ...this.defaultHeaders(), + ...this.customHeaders, + }; + const httpAgent: Agent | undefined = defaultHttpAgent; + let req: RequestInit; + if (method === 'get') { + req = { + method, + headers: reqHeaders, + ...(httpAgent && { agent: httpAgent }), + }; + } else { + req = { + method, + body: JSON.stringify(parseBody(body)), + headers: reqHeaders, + ...(httpAgent && { agent: httpAgent }), + }; } + return { req: req, url: url.toString() }; + } methodRequest( method: HTTPMethod, diff --git a/src/client.ts b/src/client.ts index 9bc3f5f..445607a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -30,15 +30,15 @@ export class Portkey extends ApiClient { azureResourceName?: string | null | undefined; azureDeploymentId?: string | null | undefined; azureApiVersion?: string | null | undefined; - azureEndpointName?: string | null | undefined; + azureEndpointName?: string | null | undefined; huggingfaceBaseUrl?: string | null | undefined; forwardHeaders?: Array | null | undefined; requestTimeout?: number | null | undefined; cacheNamespace?: string | null | undefined; strictOpenAiCompliance?: boolean | null | undefined; anthropicBeta?: string | null | undefined; - anthropicVersion?: string | null | undefined; - mistralFimCompletion?: string | null | undefined; + anthropicVersion?: string | null | undefined; + mistralFimCompletion?: string | null | undefined; constructor({ apiKey = readEnv('PORTKEY_API_KEY') ?? null, baseURL = readEnv('PORTKEY_BASE_URL') ?? null, @@ -63,15 +63,15 @@ export class Portkey extends ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, + azureEndpointName, huggingfaceBaseUrl, forwardHeaders, cacheNamespace, requestTimeout, strictOpenAiCompliance, anthropicBeta, - anthropicVersion, - mistralFimCompletion + anthropicVersion, + mistralFimCompletion, }: ApiClientInterface) { super({ apiKey, @@ -98,14 +98,14 @@ export class Portkey extends ApiClient { azureResourceName, azureDeploymentId, azureApiVersion, - azureEndpointName, + azureEndpointName, huggingfaceBaseUrl, forwardHeaders, requestTimeout, strictOpenAiCompliance, anthropicBeta, - anthropicVersion, - mistralFimCompletion + anthropicVersion, + mistralFimCompletion, }); this.apiKey = apiKey; @@ -134,40 +134,40 @@ export class Portkey extends ApiClient { this.azureResourceName = azureResourceName; this.azureDeploymentId = azureDeploymentId; this.azureApiVersion = azureApiVersion; - this.azureEndpointName = azureEndpointName; + this.azureEndpointName = azureEndpointName; this.huggingfaceBaseUrl = huggingfaceBaseUrl; this.forwardHeaders = forwardHeaders; this.requestTimeout = requestTimeout; this.strictOpenAiCompliance = strictOpenAiCompliance; this.anthropicBeta = anthropicBeta; - this.anthropicVersion = anthropicVersion; - this.mistralFimCompletion = mistralFimCompletion; + this.anthropicVersion = anthropicVersion; + this.mistralFimCompletion = mistralFimCompletion; } - completions: API.Completions = new API.Completions(this); - chat = new API.Chat(this); - embeddings = new API.Embeddings(this); - files = new API.MainFiles(this); - images = new API.Images(this); - models = new API.Models(this); - generations = new API.Generations(this); - prompts = new API.Prompt(this); - feedback = new API.Feedback(this); - batches = new API.Batches(this); - fineTuning = new API.FineTuning(this); - moderations = new API.Moderations(this); - audio = new API.Audio(this); - uploads = new API.Uploads(this); - admin = new API.Admin(this); - virtualKeys = new API.VirtualKeys(this); - apiKeys = new API.ApiKeys(this); - configs = new API.Configs(this); - beta = { - assistants: new API.Assistants(this), - threads: new API.Threads(this), - vectorStores: new API.VectorStores(this), - chat: new API.BetaChat(this), - }; + completions: API.Completions = new API.Completions(this); + chat = new API.Chat(this); + embeddings = new API.Embeddings(this); + files = new API.MainFiles(this); + images = new API.Images(this); + models = new API.Models(this); + generations = new API.Generations(this); + prompts = new API.Prompt(this); + feedback = new API.Feedback(this); + batches = new API.Batches(this); + fineTuning = new API.FineTuning(this); + moderations = new API.Moderations(this); + audio = new API.Audio(this); + uploads = new API.Uploads(this); + admin = new API.Admin(this); + virtualKeys = new API.VirtualKeys(this); + apiKeys = new API.ApiKeys(this); + configs = new API.Configs(this); + beta = { + assistants: new API.Assistants(this), + threads: new API.Threads(this), + vectorStores: new API.VectorStores(this), + chat: new API.BetaChat(this), + }; post = ( url: string, diff --git a/src/utils.ts b/src/utils.ts index 2224257..5c38ca4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,10 +2,15 @@ import { OPEN_AI_API_KEY, PORTKEY_HEADER_PREFIX } from './constants'; import { createResponseHeaders } from './streaming'; import OpenAI from 'openai'; import type { Portkey } from './index'; -import { UserInviteListParams, UsersListParams, WorkspaceMemberListParams, WorkspacesListParams } from "./apis/admin"; -import { VirtualKeysListParams } from "./apis/virtualKeys"; -import { ApiKeysListParams } from "./apis/apiKeys"; -import { CongfigsListParams } from "./apis/configs"; +import { + UserInviteListParams, + UsersListParams, + WorkspaceMemberListParams, + WorkspacesListParams, +} from './apis/admin'; +import { VirtualKeysListParams } from './apis/virtualKeys'; +import { ApiKeysListParams } from './apis/apiKeys'; +import { CongfigsListParams } from './apis/configs'; type PlatformProperties = { 'x-portkey-runtime'?: string; @@ -142,14 +147,23 @@ export function initOpenAIClient(client: Portkey) { maxRetries: 0, }); } -export function toQueryParams(params?: (UsersListParams | UserInviteListParams | WorkspacesListParams | WorkspaceMemberListParams |VirtualKeysListParams | ApiKeysListParams | CongfigsListParams)): string { - if (!params) { - return ''; - } - const queryParams = Object.entries(params) - .filter(([, value]) => value !== undefined && value !== null) - .map(([key, value]) => `${key}=${value}`) - .join('&'); - - return queryParams ? `?${queryParams}` : ''; +export function toQueryParams( + params?: + | UsersListParams + | UserInviteListParams + | WorkspacesListParams + | WorkspaceMemberListParams + | VirtualKeysListParams + | ApiKeysListParams + | CongfigsListParams +): string { + if (!params) { + return ''; + } + const queryParams = Object.entries(params) + .filter(([, value]) => value !== undefined && value !== null) + .map(([key, value]) => `${key}=${value}`) + .join('&'); + + return queryParams ? `?${queryParams}` : ''; } diff --git a/src/version.ts b/src/version.ts index 24d5ef7..071d772 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const VERSION = "1.5.0"; \ No newline at end of file +export const VERSION = '1.5.0';