Repository navigation
Expand file tree
/
Copy pathsessions.ts
More file actions
96 lines (86 loc) · 2.89 KB
/
Copy pathsessions.ts
File metadata and controls
96 lines (86 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import * as ThreadsAPI from './threads';
import { APIPromise } from '../../../core/api-promise';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
function resolveResourceRequestOptions(
options: RequestOptions | undefined,
buildOptions: (options: RequestOptions | undefined) => RequestOptions | Promise<RequestOptions>,
): Promise<RequestOptions> {
return Promise.resolve(options).then(buildOptions);
}
export class Sessions extends APIResource {
/**
* Create a ChatKit session.
*
* @example
* ```ts
* const chatSession =
* await client.beta.chatkit.sessions.create({
* user: 'x',
* workflow: { id: 'id' },
* });
* ```
*/
create(body: SessionCreateParams, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {
return this._client.post(
'/chatkit/sessions',
resolveResourceRequestOptions(options, (options) => ({
body,
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
__security: { bearerAuth: true },
})),
);
}
/**
* Cancel an active ChatKit session and return its most recent metadata.
*
* Cancelling prevents new requests from using the issued client secret.
*
* @example
* ```ts
* const chatSession =
* await client.beta.chatkit.sessions.cancel('cksess_123');
* ```
*/
cancel(sessionID: string, options?: RequestOptions): APIPromise<ThreadsAPI.ChatSession> {
return this._client.post(
path`/chatkit/sessions/${sessionID}/cancel`,
resolveResourceRequestOptions(options, (options) => ({
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'chatkit_beta=v1' }, options?.headers]),
__security: { bearerAuth: true },
})),
);
}
}
export interface SessionCreateParams {
/**
* A free-form string that identifies your end user; ensures this Session can
* access other objects that have the same `user` scope.
*/
user: string;
/**
* Workflow that powers the session.
*/
workflow: ThreadsAPI.ChatSessionWorkflowParam;
/**
* Optional overrides for ChatKit runtime configuration features
*/
chatkit_configuration?: ThreadsAPI.ChatSessionChatKitConfigurationParam;
/**
* Optional override for session expiration timing in seconds from creation.
* Defaults to 10 minutes.
*/
expires_after?: ThreadsAPI.ChatSessionExpiresAfterParam;
/**
* Optional override for per-minute request limits. When omitted, defaults to 10.
*/
rate_limits?: ThreadsAPI.ChatSessionRateLimitsParam;
}
export declare namespace Sessions {
export { type SessionCreateParams as SessionCreateParams };
}