agora-agents 2.12.0 → 3.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -3
- package/dist/cjs/AgoraPoolClient.d.ts +15 -27
- package/dist/cjs/AgoraPoolClient.js +75 -54
- package/dist/cjs/BaseClient.js +3 -2
- package/dist/cjs/agentkit/Agent.d.ts +14 -1
- package/dist/cjs/agentkit/Agent.js +126 -9
- package/dist/cjs/agentkit/AgentSession.d.ts +11 -2
- package/dist/cjs/agentkit/AgentSession.js +134 -22
- package/dist/cjs/agentkit/index.d.ts +4 -1
- package/dist/cjs/agentkit/index.js +12 -2
- package/dist/cjs/agentkit/session-backend.d.ts +25 -0
- package/dist/cjs/agentkit/session-backend.js +197 -0
- package/dist/cjs/agentkit/types.d.ts +27 -4
- package/dist/cjs/agentkit/v3.d.ts +70 -0
- package/dist/cjs/agentkit/v3.js +700 -0
- package/dist/cjs/agentkit/vendors/avatar.d.ts +24 -12
- package/dist/cjs/agentkit/vendors/avatar.js +48 -3
- package/dist/cjs/agentkit/vendors/base.d.ts +8 -0
- package/dist/cjs/agentkit/vendors/base.js +33 -7
- package/dist/cjs/agentkit/vendors/llm.d.ts +7 -7
- package/dist/cjs/agentkit/vendors/llm.js +26 -22
- package/dist/cjs/agentkit/vendors/tts.d.ts +20 -0
- package/dist/cjs/agentkit/vendors/tts.js +5 -2
- package/dist/cjs/core/publicHeaders.d.ts +2 -0
- package/dist/cjs/core/publicHeaders.js +8 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +14 -1
- package/dist/cjs/v3/campaign-schema.d.ts +1 -0
- package/dist/cjs/v3/campaign-schema.js +18 -0
- package/dist/cjs/v3/campaigns.d.ts +50 -0
- package/dist/cjs/v3/campaigns.js +81 -0
- package/dist/cjs/v3/contract.d.ts +1 -0
- package/dist/cjs/v3/contract.js +9115 -0
- package/dist/cjs/v3/index.d.ts +15 -0
- package/dist/cjs/v3/index.js +56 -0
- package/dist/cjs/v3/resources.d.ts +121 -0
- package/dist/cjs/v3/resources.js +186 -0
- package/dist/cjs/v3/session-lifecycle.d.ts +51 -0
- package/dist/cjs/v3/session-lifecycle.js +127 -0
- package/dist/cjs/v3/session-schema.d.ts +1 -0
- package/dist/cjs/v3/session-schema.js +18 -0
- package/dist/cjs/v3/transport.d.ts +36 -0
- package/dist/cjs/v3/transport.js +161 -0
- package/dist/cjs/v3/types.d.ts +1004 -0
- package/dist/cjs/v3/types.js +2 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/AgoraPoolClient.d.mts +15 -27
- package/dist/esm/AgoraPoolClient.mjs +69 -48
- package/dist/esm/BaseClient.mjs +3 -2
- package/dist/esm/agentkit/Agent.d.mts +14 -1
- package/dist/esm/agentkit/Agent.mjs +126 -9
- package/dist/esm/agentkit/AgentSession.d.mts +11 -2
- package/dist/esm/agentkit/AgentSession.mjs +134 -22
- package/dist/esm/agentkit/index.d.mts +4 -1
- package/dist/esm/agentkit/index.mjs +2 -0
- package/dist/esm/agentkit/session-backend.d.mts +25 -0
- package/dist/esm/agentkit/session-backend.mjs +191 -0
- package/dist/esm/agentkit/types.d.mts +27 -4
- package/dist/esm/agentkit/v3.d.mts +70 -0
- package/dist/esm/agentkit/v3.mjs +687 -0
- package/dist/esm/agentkit/vendors/avatar.d.mts +24 -12
- package/dist/esm/agentkit/vendors/avatar.mjs +45 -6
- package/dist/esm/agentkit/vendors/base.d.mts +8 -0
- package/dist/esm/agentkit/vendors/base.mjs +33 -7
- package/dist/esm/agentkit/vendors/llm.d.mts +7 -7
- package/dist/esm/agentkit/vendors/llm.mjs +26 -22
- package/dist/esm/agentkit/vendors/tts.d.mts +20 -0
- package/dist/esm/agentkit/vendors/tts.mjs +5 -2
- package/dist/esm/core/publicHeaders.d.mts +2 -0
- package/dist/esm/core/publicHeaders.mjs +5 -0
- package/dist/esm/index.d.mts +5 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/v3/campaign-schema.d.mts +1 -0
- package/dist/esm/v3/campaign-schema.mjs +2 -0
- package/dist/esm/v3/campaigns.d.mts +50 -0
- package/dist/esm/v3/campaigns.mjs +77 -0
- package/dist/esm/v3/contract.d.mts +1 -0
- package/dist/esm/v3/contract.mjs +9112 -0
- package/dist/esm/v3/index.d.mts +15 -0
- package/dist/esm/v3/index.mjs +15 -0
- package/dist/esm/v3/resources.d.mts +121 -0
- package/dist/esm/v3/resources.mjs +179 -0
- package/dist/esm/v3/session-lifecycle.d.mts +51 -0
- package/dist/esm/v3/session-lifecycle.mjs +121 -0
- package/dist/esm/v3/session-schema.d.mts +1 -0
- package/dist/esm/v3/session-schema.mjs +2 -0
- package/dist/esm/v3/transport.d.mts +36 -0
- package/dist/esm/v3/transport.mjs +151 -0
- package/dist/esm/v3/types.d.mts +1004 -0
- package/dist/esm/v3/types.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/openapi.yaml +8917 -0
- package/package.json +7 -4
- package/reference.md +3 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CampaignsResource } from "./campaigns.mjs";
|
|
2
|
+
export { CampaignsResource } from "./campaigns.mjs";
|
|
3
|
+
import { AgentsResource, NumbersResource, SecretsResource, SessionsResource } from "./resources.mjs";
|
|
4
|
+
import type { V3Transport } from "./transport.mjs";
|
|
5
|
+
export * from "./resources.mjs";
|
|
6
|
+
export * from "./transport.mjs";
|
|
7
|
+
export * as V3 from "./types.mjs";
|
|
8
|
+
export declare class V3Client {
|
|
9
|
+
readonly campaigns: CampaignsResource;
|
|
10
|
+
readonly agents: AgentsResource;
|
|
11
|
+
readonly secrets: SecretsResource;
|
|
12
|
+
readonly numbers: NumbersResource;
|
|
13
|
+
readonly sessions: SessionsResource;
|
|
14
|
+
constructor(transport: V3Transport);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CampaignsResource } from "./campaigns.mjs";
|
|
2
|
+
export { CampaignsResource } from "./campaigns.mjs";
|
|
3
|
+
import { AgentsResource, NumbersResource, SecretsResource, SessionsResource } from "./resources.mjs";
|
|
4
|
+
export * from "./resources.mjs";
|
|
5
|
+
export * from "./transport.mjs";
|
|
6
|
+
export * as V3 from "./types.mjs";
|
|
7
|
+
export class V3Client {
|
|
8
|
+
constructor(transport) {
|
|
9
|
+
this.campaigns = new CampaignsResource(transport);
|
|
10
|
+
this.agents = new AgentsResource(transport);
|
|
11
|
+
this.secrets = new SecretsResource(transport);
|
|
12
|
+
this.numbers = new NumbersResource(transport);
|
|
13
|
+
this.sessions = new SessionsResource(transport);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { BaseRequestOptions } from "../BaseClient.mjs";
|
|
2
|
+
import type { HttpResponsePromise } from "../core/fetcher/HttpResponsePromise.mjs";
|
|
3
|
+
import { SessionLifecycleResource } from "./session-lifecycle.mjs";
|
|
4
|
+
import { type V3Transport } from "./transport.mjs";
|
|
5
|
+
import type * as T from "./types.mjs";
|
|
6
|
+
export declare class AgentsResource {
|
|
7
|
+
private transport;
|
|
8
|
+
constructor(transport: V3Transport);
|
|
9
|
+
create(request: {
|
|
10
|
+
appid?: string;
|
|
11
|
+
} & T.AgentCreateInput, options?: BaseRequestOptions): HttpResponsePromise<T.AgentResponse>;
|
|
12
|
+
list(request?: {
|
|
13
|
+
appid?: string;
|
|
14
|
+
limit?: number;
|
|
15
|
+
cursor?: string | null;
|
|
16
|
+
order?: "create_ts.desc" | "create_ts.asc";
|
|
17
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.AgentListResponse>;
|
|
18
|
+
listAll(request?: Parameters<AgentsResource["list"]>[0], options?: BaseRequestOptions): AsyncGenerator<T.AgentListItem>;
|
|
19
|
+
get(request: {
|
|
20
|
+
appid?: string;
|
|
21
|
+
id: string;
|
|
22
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.AgentResponse>;
|
|
23
|
+
update(request: {
|
|
24
|
+
appid?: string;
|
|
25
|
+
id: string;
|
|
26
|
+
ifMatch: string;
|
|
27
|
+
} & T.AgentPatch, options?: BaseRequestOptions): HttpResponsePromise<T.AgentResponse>;
|
|
28
|
+
delete(request: {
|
|
29
|
+
appid?: string;
|
|
30
|
+
id: string;
|
|
31
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.AgentDeleteResponse>;
|
|
32
|
+
}
|
|
33
|
+
export declare class SecretsResource {
|
|
34
|
+
private transport;
|
|
35
|
+
constructor(transport: V3Transport);
|
|
36
|
+
create(request: {
|
|
37
|
+
appid?: string;
|
|
38
|
+
} & T.SecretCreate, options?: BaseRequestOptions): HttpResponsePromise<T.SecretSet>;
|
|
39
|
+
list(request?: {
|
|
40
|
+
appid?: string;
|
|
41
|
+
limit?: number;
|
|
42
|
+
cursor?: string | null;
|
|
43
|
+
order?: "create_ts.asc" | "create_ts.desc";
|
|
44
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SecretList>;
|
|
45
|
+
listAll(request?: Parameters<SecretsResource["list"]>[0], options?: BaseRequestOptions): AsyncGenerator<T.SecretSet>;
|
|
46
|
+
get(request: {
|
|
47
|
+
appid?: string;
|
|
48
|
+
name: string;
|
|
49
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SecretSet>;
|
|
50
|
+
replace(request: {
|
|
51
|
+
appid?: string;
|
|
52
|
+
name: string;
|
|
53
|
+
ifMatch: string;
|
|
54
|
+
} & T.SecretReplace, options?: BaseRequestOptions): HttpResponsePromise<T.SecretSet>;
|
|
55
|
+
update(request: {
|
|
56
|
+
appid?: string;
|
|
57
|
+
name: string;
|
|
58
|
+
ifMatch?: string | null;
|
|
59
|
+
} & T.SecretUpdate, options?: BaseRequestOptions): HttpResponsePromise<T.SecretSet>;
|
|
60
|
+
delete(request: {
|
|
61
|
+
appid?: string;
|
|
62
|
+
name: string;
|
|
63
|
+
ifMatch: string;
|
|
64
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SecretDeleted>;
|
|
65
|
+
setKey(request: {
|
|
66
|
+
appid?: string;
|
|
67
|
+
name: string;
|
|
68
|
+
key: string;
|
|
69
|
+
ifMatch?: string | null;
|
|
70
|
+
ifNoneMatch?: "*" | null;
|
|
71
|
+
} & T.SecretKeyWrite, options?: BaseRequestOptions): HttpResponsePromise<T.SecretKey>;
|
|
72
|
+
deleteKey(request: {
|
|
73
|
+
appid?: string;
|
|
74
|
+
name: string;
|
|
75
|
+
key: string;
|
|
76
|
+
ifMatch?: string | null;
|
|
77
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SecretDeleted>;
|
|
78
|
+
}
|
|
79
|
+
export declare class NumbersResource {
|
|
80
|
+
private transport;
|
|
81
|
+
constructor(transport: V3Transport);
|
|
82
|
+
create(request: {
|
|
83
|
+
appid?: string;
|
|
84
|
+
} & T.NumberCreate, options?: BaseRequestOptions): HttpResponsePromise<T.NumberResponse>;
|
|
85
|
+
list(request?: {
|
|
86
|
+
appid?: string;
|
|
87
|
+
limit?: number;
|
|
88
|
+
cursor?: string | null;
|
|
89
|
+
order?: "create_ts.desc" | "create_ts.asc";
|
|
90
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.NumberListResponse>;
|
|
91
|
+
listAll(request?: Parameters<NumbersResource["list"]>[0], options?: BaseRequestOptions): AsyncGenerator<T.NumberResponse>;
|
|
92
|
+
get(request: {
|
|
93
|
+
appid?: string;
|
|
94
|
+
id: string;
|
|
95
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.NumberResponse>;
|
|
96
|
+
update(request: {
|
|
97
|
+
appid?: string;
|
|
98
|
+
id: string;
|
|
99
|
+
ifMatch: string;
|
|
100
|
+
} & T.NumberPatch, options?: BaseRequestOptions): HttpResponsePromise<T.NumberResponse>;
|
|
101
|
+
delete(request: {
|
|
102
|
+
appid?: string;
|
|
103
|
+
id: string;
|
|
104
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.NumberDeleteResponse>;
|
|
105
|
+
}
|
|
106
|
+
export declare class SessionsResource extends SessionLifecycleResource {
|
|
107
|
+
list(request?: {
|
|
108
|
+
appid?: string;
|
|
109
|
+
channel?: string | null;
|
|
110
|
+
status?: string;
|
|
111
|
+
started_after?: number | null;
|
|
112
|
+
started_before?: number | null;
|
|
113
|
+
limit?: number;
|
|
114
|
+
cursor?: string | null;
|
|
115
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SessionList>;
|
|
116
|
+
listAll(request?: Parameters<SessionsResource["list"]>[0], options?: BaseRequestOptions): AsyncGenerator<T.SessionSummary>;
|
|
117
|
+
get(request: {
|
|
118
|
+
appid?: string;
|
|
119
|
+
agentSessionId: string;
|
|
120
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<T.SessionResponse>;
|
|
121
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
2
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
5
|
+
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
6
|
+
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
7
|
+
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
8
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
9
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
10
|
+
function fulfill(value) { resume("next", value); }
|
|
11
|
+
function reject(value) { resume("throw", value); }
|
|
12
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
13
|
+
};
|
|
14
|
+
import { SessionLifecycleResource } from "./session-lifecycle.mjs";
|
|
15
|
+
import { omit, segment, snapshotPagination } from "./transport.mjs";
|
|
16
|
+
export class AgentsResource {
|
|
17
|
+
constructor(transport) {
|
|
18
|
+
this.transport = transport;
|
|
19
|
+
}
|
|
20
|
+
create(request, options) {
|
|
21
|
+
return this.transport.request("POST", `/agents`, request.appid, omit(request, ["appid"]), {}, {}, options);
|
|
22
|
+
}
|
|
23
|
+
list(request = {}, options) {
|
|
24
|
+
return this.transport.request("GET", `/agents`, request.appid, undefined, { limit: request.limit, cursor: request.cursor, order: request.order }, {}, options);
|
|
25
|
+
}
|
|
26
|
+
listAll() {
|
|
27
|
+
return __asyncGenerator(this, arguments, function* listAll_1(request = {}, options) {
|
|
28
|
+
const snapshot = snapshotPagination(request, options);
|
|
29
|
+
request = snapshot.request;
|
|
30
|
+
options = snapshot.options;
|
|
31
|
+
let cursor = request === null || request === void 0 ? void 0 : request.cursor;
|
|
32
|
+
const seen = new Set();
|
|
33
|
+
do {
|
|
34
|
+
const page = yield __await(this.list(Object.assign(Object.assign({}, request), { cursor }), options));
|
|
35
|
+
for (const item of page.data.list)
|
|
36
|
+
yield yield __await(item);
|
|
37
|
+
if (!page.has_more)
|
|
38
|
+
return yield __await(void 0);
|
|
39
|
+
if (!page.next_cursor || seen.has(page.next_cursor))
|
|
40
|
+
throw new Error("Invalid repeated or missing pagination cursor");
|
|
41
|
+
cursor = page.next_cursor;
|
|
42
|
+
seen.add(cursor);
|
|
43
|
+
} while (cursor !== undefined && cursor !== null);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
get(request, options) {
|
|
47
|
+
return this.transport.request("GET", `/agents/${segment(request.id)}`, request.appid, undefined, {}, {}, options);
|
|
48
|
+
}
|
|
49
|
+
update(request, options) {
|
|
50
|
+
return this.transport.request("PATCH", `/agents/${segment(request.id)}`, request.appid, omit(request, ["id", "ifMatch", "appid"]), {}, { "If-Match": request.ifMatch }, options);
|
|
51
|
+
}
|
|
52
|
+
delete(request, options) {
|
|
53
|
+
return this.transport.request("DELETE", `/agents/${segment(request.id)}`, request.appid, undefined, {}, {}, options);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class SecretsResource {
|
|
57
|
+
constructor(transport) {
|
|
58
|
+
this.transport = transport;
|
|
59
|
+
}
|
|
60
|
+
create(request, options) {
|
|
61
|
+
return this.transport.request("POST", `/secrets`, request.appid, omit(request, ["appid"]), {}, {}, options);
|
|
62
|
+
}
|
|
63
|
+
list(request = {}, options) {
|
|
64
|
+
return this.transport.request("GET", `/secrets`, request.appid, undefined, { limit: request.limit, cursor: request.cursor, order: request.order }, {}, options);
|
|
65
|
+
}
|
|
66
|
+
listAll() {
|
|
67
|
+
return __asyncGenerator(this, arguments, function* listAll_2(request = {}, options) {
|
|
68
|
+
const snapshot = snapshotPagination(request, options);
|
|
69
|
+
request = snapshot.request;
|
|
70
|
+
options = snapshot.options;
|
|
71
|
+
let cursor = request === null || request === void 0 ? void 0 : request.cursor;
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
do {
|
|
74
|
+
const page = yield __await(this.list(Object.assign(Object.assign({}, request), { cursor }), options));
|
|
75
|
+
for (const item of page.data.list)
|
|
76
|
+
yield yield __await(item);
|
|
77
|
+
if (!page.has_more)
|
|
78
|
+
return yield __await(void 0);
|
|
79
|
+
if (!page.next_cursor || seen.has(page.next_cursor))
|
|
80
|
+
throw new Error("Invalid repeated or missing pagination cursor");
|
|
81
|
+
cursor = page.next_cursor;
|
|
82
|
+
seen.add(cursor);
|
|
83
|
+
} while (cursor !== undefined && cursor !== null);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
get(request, options) {
|
|
87
|
+
return this.transport.request("GET", `/secrets/${segment(request.name)}`, request.appid, undefined, {}, {}, options);
|
|
88
|
+
}
|
|
89
|
+
replace(request, options) {
|
|
90
|
+
return this.transport.request("PUT", `/secrets/${segment(request.name)}`, request.appid, omit(request, ["name", "ifMatch", "appid"]), {}, { "If-Match": request.ifMatch }, options);
|
|
91
|
+
}
|
|
92
|
+
update(request, options) {
|
|
93
|
+
return this.transport.request("PATCH", `/secrets/${segment(request.name)}`, request.appid, omit(request, ["name", "ifMatch", "appid"]), {}, { "If-Match": request.ifMatch }, options);
|
|
94
|
+
}
|
|
95
|
+
delete(request, options) {
|
|
96
|
+
return this.transport.request("DELETE", `/secrets/${segment(request.name)}`, request.appid, undefined, {}, { "If-Match": request.ifMatch }, options);
|
|
97
|
+
}
|
|
98
|
+
setKey(request, options) {
|
|
99
|
+
return this.transport.request("PUT", `/secrets/${segment(request.name)}/keys/${segment(request.key)}`, request.appid, omit(request, ["name", "key", "ifMatch", "ifNoneMatch", "appid"]), {}, { "If-Match": request.ifMatch, "If-None-Match": request.ifNoneMatch }, options);
|
|
100
|
+
}
|
|
101
|
+
deleteKey(request, options) {
|
|
102
|
+
return this.transport.request("DELETE", `/secrets/${segment(request.name)}/keys/${segment(request.key)}`, request.appid, undefined, {}, { "If-Match": request.ifMatch }, options);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export class NumbersResource {
|
|
106
|
+
constructor(transport) {
|
|
107
|
+
this.transport = transport;
|
|
108
|
+
}
|
|
109
|
+
create(request, options) {
|
|
110
|
+
return this.transport.request("POST", `/numbers`, request.appid, omit(request, ["appid"]), {}, {}, options);
|
|
111
|
+
}
|
|
112
|
+
list(request = {}, options) {
|
|
113
|
+
return this.transport.request("GET", `/numbers`, request.appid, undefined, { limit: request.limit, cursor: request.cursor, order: request.order }, {}, options);
|
|
114
|
+
}
|
|
115
|
+
listAll() {
|
|
116
|
+
return __asyncGenerator(this, arguments, function* listAll_3(request = {}, options) {
|
|
117
|
+
const snapshot = snapshotPagination(request, options);
|
|
118
|
+
request = snapshot.request;
|
|
119
|
+
options = snapshot.options;
|
|
120
|
+
let cursor = request === null || request === void 0 ? void 0 : request.cursor;
|
|
121
|
+
const seen = new Set();
|
|
122
|
+
do {
|
|
123
|
+
const page = yield __await(this.list(Object.assign(Object.assign({}, request), { cursor }), options));
|
|
124
|
+
for (const item of page.data.list)
|
|
125
|
+
yield yield __await(item);
|
|
126
|
+
if (!page.has_more)
|
|
127
|
+
return yield __await(void 0);
|
|
128
|
+
if (!page.next_cursor || seen.has(page.next_cursor))
|
|
129
|
+
throw new Error("Invalid repeated or missing pagination cursor");
|
|
130
|
+
cursor = page.next_cursor;
|
|
131
|
+
seen.add(cursor);
|
|
132
|
+
} while (cursor !== undefined && cursor !== null);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
get(request, options) {
|
|
136
|
+
return this.transport.request("GET", `/numbers/${segment(request.id)}`, request.appid, undefined, {}, {}, options);
|
|
137
|
+
}
|
|
138
|
+
update(request, options) {
|
|
139
|
+
return this.transport.request("PATCH", `/numbers/${segment(request.id)}`, request.appid, omit(request, ["id", "ifMatch", "appid"]), {}, { "If-Match": request.ifMatch }, options);
|
|
140
|
+
}
|
|
141
|
+
delete(request, options) {
|
|
142
|
+
return this.transport.request("DELETE", `/numbers/${segment(request.id)}`, request.appid, undefined, {}, {}, options);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export class SessionsResource extends SessionLifecycleResource {
|
|
146
|
+
list(request = {}, options) {
|
|
147
|
+
return this.transport.request("GET", `/sessions`, request.appid, undefined, {
|
|
148
|
+
channel: request.channel,
|
|
149
|
+
status: request.status,
|
|
150
|
+
started_after: request.started_after,
|
|
151
|
+
started_before: request.started_before,
|
|
152
|
+
limit: request.limit,
|
|
153
|
+
cursor: request.cursor,
|
|
154
|
+
}, {}, options);
|
|
155
|
+
}
|
|
156
|
+
listAll() {
|
|
157
|
+
return __asyncGenerator(this, arguments, function* listAll_4(request = {}, options) {
|
|
158
|
+
const snapshot = snapshotPagination(request, options);
|
|
159
|
+
request = snapshot.request;
|
|
160
|
+
options = snapshot.options;
|
|
161
|
+
let cursor = request === null || request === void 0 ? void 0 : request.cursor;
|
|
162
|
+
const seen = new Set();
|
|
163
|
+
do {
|
|
164
|
+
const page = yield __await(this.list(Object.assign(Object.assign({}, request), { cursor }), options));
|
|
165
|
+
for (const item of page.data.list)
|
|
166
|
+
yield yield __await(item);
|
|
167
|
+
if (!page.has_more)
|
|
168
|
+
return yield __await(void 0);
|
|
169
|
+
if (!page.next_cursor || seen.has(page.next_cursor))
|
|
170
|
+
throw new Error("Invalid repeated or missing pagination cursor");
|
|
171
|
+
cursor = page.next_cursor;
|
|
172
|
+
seen.add(cursor);
|
|
173
|
+
} while (cursor !== undefined && cursor !== null);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
get(request, options) {
|
|
177
|
+
return this.transport.request("GET", `/sessions/${segment(request.agentSessionId)}`, request.appid, undefined, {}, {}, options);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Public contract corrections from engineering's v3-open-questions-reply.md (2026-10-27).
|
|
2
|
+
* Generated schema remains intact; this adapter corrects statuses, timestamps and headers.
|
|
3
|
+
*/
|
|
4
|
+
import type { BaseRequestOptions } from "../BaseClient.mjs";
|
|
5
|
+
import type { HttpResponsePromise } from "../core/fetcher/HttpResponsePromise.mjs";
|
|
6
|
+
import type * as Schema from "./session-schema.mjs";
|
|
7
|
+
import { type V3Transport } from "./transport.mjs";
|
|
8
|
+
export type SessionGeofence = {
|
|
9
|
+
area: "global" | "north_america" | "europe" | "asia" | "india" | "japan";
|
|
10
|
+
exclude_area?: "north_america" | "europe" | "asia" | "india" | "japan";
|
|
11
|
+
};
|
|
12
|
+
export type SessionTransport = (Schema.RtcTransport & {
|
|
13
|
+
geofence?: SessionGeofence;
|
|
14
|
+
}) | Schema.TelephonyTransport;
|
|
15
|
+
export type SessionStartOptions = Omit<Schema.SessionCreate, "agent_id" | "client_reference" | "transport"> & {
|
|
16
|
+
transport: SessionTransport;
|
|
17
|
+
idempotencyKey?: string;
|
|
18
|
+
};
|
|
19
|
+
export type SessionStartRequest = SessionStartOptions & {
|
|
20
|
+
agent_id: string;
|
|
21
|
+
};
|
|
22
|
+
export type EphemeralSessionStartRequest = Omit<Schema.PublicEphemeralSessionCreate, "client_reference" | "transport"> & {
|
|
23
|
+
transport: SessionTransport;
|
|
24
|
+
idempotencyKey?: string;
|
|
25
|
+
};
|
|
26
|
+
export interface SessionStartResponse {
|
|
27
|
+
agent_session_id: string;
|
|
28
|
+
status: "STARTING" | "RUNNING";
|
|
29
|
+
create_ts: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function normalizeSessionStart(value: unknown): SessionStartResponse;
|
|
32
|
+
export declare function validateSessionStart(request: SessionStartRequest | EphemeralSessionStartRequest): void;
|
|
33
|
+
export declare class SessionLifecycleResource {
|
|
34
|
+
protected transport: V3Transport;
|
|
35
|
+
constructor(transport: V3Transport);
|
|
36
|
+
private startRequest;
|
|
37
|
+
start(request: {
|
|
38
|
+
appid?: string;
|
|
39
|
+
} & SessionStartRequest, options?: BaseRequestOptions): HttpResponsePromise<SessionStartResponse>;
|
|
40
|
+
startEphemeral(request: {
|
|
41
|
+
appid?: string;
|
|
42
|
+
} & EphemeralSessionStartRequest, options?: BaseRequestOptions): HttpResponsePromise<SessionStartResponse>;
|
|
43
|
+
update(request: Schema.SessionPatch & {
|
|
44
|
+
appid?: string;
|
|
45
|
+
agentSessionId: string;
|
|
46
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<Schema.SessionUpdateResponse>;
|
|
47
|
+
stop(request: {
|
|
48
|
+
appid?: string;
|
|
49
|
+
agentSessionId: string;
|
|
50
|
+
}, options?: BaseRequestOptions): HttpResponsePromise<Record<string, never>>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { HttpResponsePromise as ResponsePromise } from "../core/fetcher/HttpResponsePromise.mjs";
|
|
2
|
+
import { omit, segment, validateIdempotencyKey } from "./transport.mjs";
|
|
3
|
+
export function normalizeSessionStart(value) {
|
|
4
|
+
var _a;
|
|
5
|
+
const data = value;
|
|
6
|
+
const status = typeof (data === null || data === void 0 ? void 0 : data.status) === "string" ? data.status.toUpperCase() : "";
|
|
7
|
+
const timestamp = (_a = data === null || data === void 0 ? void 0 : data.create_ts) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data.created_at;
|
|
8
|
+
if (!data ||
|
|
9
|
+
typeof data.agent_session_id !== "string" ||
|
|
10
|
+
!data.agent_session_id.trim() ||
|
|
11
|
+
!["STARTING", "RUNNING"].includes(status) ||
|
|
12
|
+
typeof timestamp !== "number" ||
|
|
13
|
+
!Number.isInteger(timestamp) ||
|
|
14
|
+
timestamp < 0)
|
|
15
|
+
throw new Error("Invalid session start response");
|
|
16
|
+
return {
|
|
17
|
+
agent_session_id: data.agent_session_id,
|
|
18
|
+
status: status,
|
|
19
|
+
create_ts: timestamp,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function range(value, min, max, field) {
|
|
23
|
+
if (value !== undefined && (!Number.isInteger(value) || value < min || value > max))
|
|
24
|
+
throw new Error(`${field} must be an integer between ${min} and ${max}`);
|
|
25
|
+
}
|
|
26
|
+
export function validateSessionStart(request) {
|
|
27
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
|
+
if ("client_reference" in request || "clientReference" in request)
|
|
29
|
+
throw new Error("client_reference is being removed; use application-side correlation with the returned session ID");
|
|
30
|
+
if (request.idempotencyKey !== undefined)
|
|
31
|
+
validateIdempotencyKey(request.idempotencyKey);
|
|
32
|
+
const transport = request.transport;
|
|
33
|
+
if (transport.type === "rtc") {
|
|
34
|
+
if (!transport.channel || [...transport.channel].length > 256)
|
|
35
|
+
throw new Error("channel must contain 1–256 characters");
|
|
36
|
+
if (transport.uid !== undefined &&
|
|
37
|
+
(typeof transport.uid !== "string" || !transport.uid.trim() || [...transport.uid].length > 255))
|
|
38
|
+
throw new Error("uid must be nonempty");
|
|
39
|
+
if (!Array.isArray(transport.subscribe_uids) ||
|
|
40
|
+
transport.subscribe_uids.length !== 1 ||
|
|
41
|
+
typeof transport.subscribe_uids[0] !== "string" ||
|
|
42
|
+
!transport.subscribe_uids[0].trim() ||
|
|
43
|
+
[...transport.subscribe_uids[0]].length > 255 ||
|
|
44
|
+
transport.subscribe_uids[0] === "*" ||
|
|
45
|
+
/^0+$/.test(transport.subscribe_uids[0]))
|
|
46
|
+
throw new Error("Exactly one non-wildcard subscriber UID is required");
|
|
47
|
+
const numeric = (uid) => /^[0-9]+$/.test(uid);
|
|
48
|
+
if (transport.uid !== undefined &&
|
|
49
|
+
transport.uid !== "0" &&
|
|
50
|
+
numeric(transport.uid) !== numeric(transport.subscribe_uids[0]))
|
|
51
|
+
throw new Error("Agent and subscriber must use the same UID type");
|
|
52
|
+
if (transport.audio_scenario !== undefined && !["aiserver", "chorus"].includes(transport.audio_scenario))
|
|
53
|
+
throw new Error("Invalid audio_scenario");
|
|
54
|
+
if (transport.geofence !== undefined) {
|
|
55
|
+
const areas = ["global", "north_america", "europe", "asia", "india", "japan"];
|
|
56
|
+
const fence = transport.geofence;
|
|
57
|
+
if (!areas.includes(fence.area) ||
|
|
58
|
+
(fence.exclude_area !== undefined &&
|
|
59
|
+
(fence.area !== "global" || !areas.slice(1).includes(fence.exclude_area))))
|
|
60
|
+
throw new Error("Invalid geofence: exclude_area requires global area");
|
|
61
|
+
}
|
|
62
|
+
if (transport.encryption) {
|
|
63
|
+
if (![
|
|
64
|
+
"aes_128_xts",
|
|
65
|
+
"aes_128_ecb",
|
|
66
|
+
"aes_256_xts",
|
|
67
|
+
"sm4_128_ecb",
|
|
68
|
+
"aes_128_gcm",
|
|
69
|
+
"aes_256_gcm",
|
|
70
|
+
"aes_128_gcm2",
|
|
71
|
+
"aes_256_gcm2",
|
|
72
|
+
].includes(transport.encryption.mode) ||
|
|
73
|
+
!transport.encryption.key)
|
|
74
|
+
throw new Error("Invalid RTC encryption mode/key");
|
|
75
|
+
if (transport.encryption.salt != null && !/^[A-Za-z0-9+/]{43}=$/.test(transport.encryption.salt))
|
|
76
|
+
throw new Error("Invalid RTC encryption salt");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (transport.type === "telephony") {
|
|
80
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(transport.from))
|
|
81
|
+
throw new Error("telephony.from must be a registered number UUID");
|
|
82
|
+
if (!/^\+[1-9][0-9]{1,14}$/.test(transport.to))
|
|
83
|
+
throw new Error("telephony.to must be E.164");
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
throw new Error("Unsupported session transport");
|
|
87
|
+
range((_a = request.lifecycle) === null || _a === void 0 ? void 0 : _a.idle_timeout_ms, 0, 3600000, "idle_timeout_ms");
|
|
88
|
+
range((_b = request.lifecycle) === null || _b === void 0 ? void 0 : _b.max_duration_ms, 1000, 3600000, "max_duration_ms");
|
|
89
|
+
range((_d = (_c = request.lifecycle) === null || _c === void 0 ? void 0 : _c.graceful_stop) === null || _d === void 0 ? void 0 : _d.timeout_ms, 0, 120000, "graceful_stop.timeout_ms");
|
|
90
|
+
if (((_e = request.data_policy) === null || _e === void 0 ? void 0 : _e.retention) !== undefined && !["none", "30_days"].includes(request.data_policy.retention))
|
|
91
|
+
throw new Error("Invalid data_policy.retention");
|
|
92
|
+
for (const [name, value] of Object.entries((_f = request.values) !== null && _f !== void 0 ? _f : {})) {
|
|
93
|
+
if (!/^[a-z][a-z0-9_]{0,63}$/.test(name) ||
|
|
94
|
+
!["string", "number", "boolean"].includes(typeof value) ||
|
|
95
|
+
(typeof value === "number" && !Number.isFinite(value)))
|
|
96
|
+
throw new Error("Invalid session variable value");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export class SessionLifecycleResource {
|
|
100
|
+
constructor(transport) {
|
|
101
|
+
this.transport = transport;
|
|
102
|
+
}
|
|
103
|
+
startRequest(path, request, options) {
|
|
104
|
+
validateSessionStart(request);
|
|
105
|
+
const raw = this.transport.request("POST", path, request.appid, omit(request, ["appid", "idempotencyKey"]), {}, { "Idempotency-Key": request.idempotencyKey }, options);
|
|
106
|
+
return ResponsePromise.fromPromise(raw.withRawResponse().then(({ data, rawResponse }) => ({ data: normalizeSessionStart(data), rawResponse })));
|
|
107
|
+
}
|
|
108
|
+
start(request, options) {
|
|
109
|
+
segment(request.agent_id);
|
|
110
|
+
return this.startRequest("/sessions", request, options);
|
|
111
|
+
}
|
|
112
|
+
startEphemeral(request, options) {
|
|
113
|
+
return this.startRequest("/sessions/ephemeral", request, options);
|
|
114
|
+
}
|
|
115
|
+
update(request, options) {
|
|
116
|
+
return this.transport.request("PATCH", `/sessions/${segment(request.agentSessionId)}`, request.appid, omit(request, ["appid", "agentSessionId"]), {}, {}, options);
|
|
117
|
+
}
|
|
118
|
+
stop(request, options) {
|
|
119
|
+
return this.transport.request("POST", `/sessions/${segment(request.agentSessionId)}/stop`, request.appid, undefined, {}, {}, options);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types.mjs";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BaseClientOptions, BaseRequestOptions } from "../BaseClient.mjs";
|
|
2
|
+
import { HttpResponsePromise } from "../core/fetcher/HttpResponsePromise.mjs";
|
|
3
|
+
import type { RawResponse } from "../core/fetcher/RawResponse.mjs";
|
|
4
|
+
export interface V3Options {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare function validateIdempotencyKey(value: string): void;
|
|
9
|
+
export declare function segment(value: string): string;
|
|
10
|
+
export declare function omit(value: object, keys: string[]): object;
|
|
11
|
+
/** Keep an active cursor scan bound to its original project, filters and headers. */
|
|
12
|
+
export declare function snapshotPagination<T extends object>(request: T | undefined, options?: BaseRequestOptions): {
|
|
13
|
+
request: T;
|
|
14
|
+
options: BaseRequestOptions | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare class V3Error extends Error {
|
|
17
|
+
readonly statusCode: number;
|
|
18
|
+
readonly body: unknown;
|
|
19
|
+
readonly rawResponse: RawResponse;
|
|
20
|
+
constructor(statusCode: number, body: unknown, rawResponse: RawResponse);
|
|
21
|
+
get requestId(): string | null;
|
|
22
|
+
}
|
|
23
|
+
export declare class PreconditionFailedError extends V3Error {
|
|
24
|
+
private readonly reload;
|
|
25
|
+
constructor(body: unknown, raw: RawResponse, reload: () => Promise<unknown>);
|
|
26
|
+
latest(): Promise<unknown>;
|
|
27
|
+
}
|
|
28
|
+
export declare class V3Transport {
|
|
29
|
+
private readonly options;
|
|
30
|
+
private readonly appId;
|
|
31
|
+
private readonly baseUrl;
|
|
32
|
+
private readonly authorization;
|
|
33
|
+
private readonly extraHeaders;
|
|
34
|
+
constructor(options: BaseClientOptions, appId: string, baseUrl: () => string, authorization: () => string, extraHeaders: Record<string, string> | undefined);
|
|
35
|
+
request<T>(method: string, path: string, appid?: string, body?: unknown, query?: Record<string, unknown>, headers?: Record<string, string | null | undefined>, requestOptions?: BaseRequestOptions, stripWriteHeaders?: boolean): HttpResponsePromise<T>;
|
|
36
|
+
}
|