Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"agentkeepalive": "^4.6.0",
"dotenv": "^16.5.0",
"openai": "5.20.2",
"openai": "6.3.0",
"ws": "^8.18.2"
}
}
163 changes: 163 additions & 0 deletions src/apis/chatkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import { ApiResource } from '../apiResource';
import { createHeaders } from './createHeaders';
import { finalResponse, initOpenAIClient, overrideConfig } from '../utils';
import { ApiClientInterface } from '../_types/generalTypes';
import { APIPromise, RequestOptions } from '../baseClient';
import {
ChatKitUploadFileParams,
ChatKitUploadFileResponse,
} from 'openai/resources/beta/chatkit/chatkit';
import { SessionCreateParams } from 'openai/resources/beta/chatkit/sessions';
import {
ChatKitThread,
ChatSession,
ThreadDeleteResponse,
ThreadListItemsParams,
ThreadListParams,
} from 'openai/resources/beta/chatkit/threads';

export class ChatKit extends ApiResource {
sessions: ChatKitSessions;
threads: ChatKitThreads;
constructor(client: any) {
super(client);
this.sessions = new ChatKitSessions(client);
this.threads = new ChatKitThreads(client);
}

uploadFile(
body: ChatKitUploadFileParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ChatKitUploadFileResponse> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.uploadFile(body, opts);
return result as any;
}
}

export class ChatKitSessions extends ApiResource {
create(
body: SessionCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ChatSession> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.sessions
.create(body, opts)
.withResponse();
return finalResponse(result);
}

cancel(
sessionID: string,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<void> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.sessions
.cancel(sessionID, opts)
.withResponse();
return finalResponse(result);
}
}

export class ChatKitThreads extends ApiResource {
retrieve(
threadID: string,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ChatKitThread> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.threads
.retrieve(threadID, opts)
.withResponse();
return finalResponse(result);
}

list(
query: ThreadListParams | null | undefined = {},
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.threads.list(query, opts);
return result as any;
}
delete(
threadID: string,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<ThreadDeleteResponse> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.threads
.delete(threadID, opts)
.withResponse();
return finalResponse(result);
}

listItems(
threadID: string,
query: ThreadListItemsParams | null | undefined = {},
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.beta.chatkit.threads.listItems(
threadID,
query,
opts
);
return result as any;
}
}
2 changes: 2 additions & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export { Providers } from './providers';
export { Webhooks } from './webhooks';
export { MainRealtime } from './mainRealtime';
export { Conversations } from './conversations';
export { Videos } from './videos';
export { ChatKit } from './chatkit';
87 changes: 86 additions & 1 deletion src/apis/mainRealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@ import { ClientSecretCreateParams } from 'openai/resources/realtime/client-secre
import { ApiResource } from '../apiResource';
import { ApiClientInterface } from '../_types/generalTypes';
import { finalResponse, initOpenAIClient, overrideConfig } from '../utils';
import { RequestOptions } from '../baseClient';
import { APIPromise, RequestOptions } from '../baseClient';
import { createHeaders } from './createHeaders';
import {
CallAcceptParams,
CallReferParams,
CallRejectParams,
} from 'openai/resources/realtime/calls';

export class MainRealtime extends ApiResource {
clientSecrets: ClientSecrets;
calls: Calls;

constructor(client: any) {
super(client);
this.clientSecrets = new ClientSecrets(client);
this.calls = new Calls(client);
}
}

Expand Down Expand Up @@ -38,3 +46,80 @@ export class ClientSecrets extends ApiResource {
return finalResponse(result);
}
}

export class Calls extends ApiResource {
constructor(client: any) {
super(client);
}

accept(
callID: string,
body: CallAcceptParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<void> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.realtime.calls.accept(callID, body, opts);
return result as any;
}

hangup(
callID: string,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<void> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.realtime.calls.hangup(callID, opts);
return result as any;
}

refer(
callID: string,
body: CallReferParams,
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<void> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.realtime.calls.refer(callID, body, opts);
return result as any;
}

reject(
callID: string,
body: CallRejectParams | null | undefined = {},
params?: ApiClientInterface,
opts?: RequestOptions
): APIPromise<void> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}
const OAIclient = initOpenAIClient(this.client);
const result = OAIclient.realtime.calls.reject(callID, body, opts);
return result as any;
}
}
Loading