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,151 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { fetcher } from "../core/fetcher/Fetcher.mjs";
|
|
11
|
+
import { HttpResponsePromise } from "../core/fetcher/HttpResponsePromise.mjs";
|
|
12
|
+
import { isInternalHeader } from "../core/publicHeaders.mjs";
|
|
13
|
+
export function validateIdempotencyKey(value) {
|
|
14
|
+
if (typeof value !== "string" || !value.trim())
|
|
15
|
+
throw new Error("Idempotency-Key must not be empty");
|
|
16
|
+
if (!/^[\x21-\x7E]{1,256}$/.test(value))
|
|
17
|
+
throw new Error("Idempotency-Key must contain 1–256 printable ASCII characters without spaces");
|
|
18
|
+
}
|
|
19
|
+
export function segment(value) {
|
|
20
|
+
if (typeof value !== "string" || !value.trim())
|
|
21
|
+
throw new Error("v3 path identifiers must not be empty");
|
|
22
|
+
if (value === "." || value === "..")
|
|
23
|
+
throw new Error("v3 path identifiers must not be dot segments");
|
|
24
|
+
return encodeURIComponent(value);
|
|
25
|
+
}
|
|
26
|
+
export function omit(value, keys) {
|
|
27
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key)));
|
|
28
|
+
}
|
|
29
|
+
/** Keep an active cursor scan bound to its original project, filters and headers. */
|
|
30
|
+
export function snapshotPagination(request, options) {
|
|
31
|
+
var _a;
|
|
32
|
+
return {
|
|
33
|
+
request: Object.assign({}, request),
|
|
34
|
+
options: options === undefined
|
|
35
|
+
? undefined
|
|
36
|
+
: Object.assign(Object.assign({}, options), { headers: Object.assign({}, options.headers), queryParams: JSON.parse(JSON.stringify((_a = options.queryParams) !== null && _a !== void 0 ? _a : {})) }),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export class V3Error extends Error {
|
|
40
|
+
constructor(statusCode, body, rawResponse) {
|
|
41
|
+
super(`v3 request failed (${statusCode})`);
|
|
42
|
+
this.statusCode = statusCode;
|
|
43
|
+
this.body = body;
|
|
44
|
+
this.rawResponse = rawResponse;
|
|
45
|
+
this.name = "V3Error";
|
|
46
|
+
}
|
|
47
|
+
get requestId() {
|
|
48
|
+
return this.rawResponse.headers.get("Agora-Request-Id");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class PreconditionFailedError extends V3Error {
|
|
52
|
+
constructor(body, raw, reload) {
|
|
53
|
+
super(412, body, raw);
|
|
54
|
+
this.reload = reload;
|
|
55
|
+
this.name = "PreconditionFailedError";
|
|
56
|
+
}
|
|
57
|
+
latest() {
|
|
58
|
+
return this.reload();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class V3Transport {
|
|
62
|
+
constructor(options, appId, baseUrl, authorization, extraHeaders) {
|
|
63
|
+
this.options = options;
|
|
64
|
+
this.appId = appId;
|
|
65
|
+
this.baseUrl = baseUrl;
|
|
66
|
+
this.authorization = authorization;
|
|
67
|
+
this.extraHeaders = extraHeaders;
|
|
68
|
+
}
|
|
69
|
+
request(method, path, appid = this.appId, body, query = {}, headers = {}, requestOptions = {}, stripWriteHeaders = false) {
|
|
70
|
+
// Snapshot JSON payload and option maps before any async auth/header suppliers run.
|
|
71
|
+
const capturedHeaders = [this.options.headers, this.extraHeaders, headers].map((value) => (Object.assign({}, value)));
|
|
72
|
+
const capturedOptions = Object.assign(Object.assign({}, requestOptions), { headers: Object.assign({}, requestOptions.headers) });
|
|
73
|
+
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
75
|
+
for (const key of Object.keys(capturedOptions)) {
|
|
76
|
+
if (["customerid", "customersecret", "clientid", "clientsecret", "username", "password"].includes(key.replace(/_/g, "").toLowerCase()))
|
|
77
|
+
throw new Error(`${key} is not supported; use token authorization`);
|
|
78
|
+
}
|
|
79
|
+
if (body && typeof body === "object" && "idempotencyKey" in body)
|
|
80
|
+
throw new Error("idempotencyKey is not supported by this operation");
|
|
81
|
+
const bodySnapshot = body === undefined ? undefined : JSON.parse(JSON.stringify(body));
|
|
82
|
+
// Reject removed preview pipelines even for JavaScript/untyped callers.
|
|
83
|
+
for (const pipeline of [
|
|
84
|
+
bodySnapshot === null || bodySnapshot === void 0 ? void 0 : bodySnapshot.pipeline,
|
|
85
|
+
(_a = bodySnapshot === null || bodySnapshot === void 0 ? void 0 : bodySnapshot.agent) === null || _a === void 0 ? void 0 : _a.pipeline,
|
|
86
|
+
(_c = (_b = bodySnapshot === null || bodySnapshot === void 0 ? void 0 : bodySnapshot.agent) === null || _b === void 0 ? void 0 : _b.overrides) === null || _c === void 0 ? void 0 : _c.pipeline,
|
|
87
|
+
]) {
|
|
88
|
+
if (pipeline && typeof pipeline === "object" && (pipeline.mode === "realtime" || "mllm" in pipeline))
|
|
89
|
+
throw new Error("MLLM is not supported by the preview API");
|
|
90
|
+
}
|
|
91
|
+
const querySnapshot = JSON.parse(JSON.stringify(Object.assign(Object.assign({}, query), capturedOptions.queryParams)));
|
|
92
|
+
requestOptions = capturedOptions;
|
|
93
|
+
const resolved = {};
|
|
94
|
+
for (const source of [
|
|
95
|
+
capturedHeaders[0],
|
|
96
|
+
{ Authorization: this.authorization() },
|
|
97
|
+
capturedHeaders[1],
|
|
98
|
+
capturedHeaders[2],
|
|
99
|
+
requestOptions.headers,
|
|
100
|
+
requestOptions.authorization !== undefined
|
|
101
|
+
? { Authorization: requestOptions.authorization }
|
|
102
|
+
: undefined,
|
|
103
|
+
]) {
|
|
104
|
+
for (const [name, supplier] of Object.entries(source !== null && source !== void 0 ? source : {})) {
|
|
105
|
+
const key = name.toLowerCase();
|
|
106
|
+
if (stripWriteHeaders && ["if-match", "if-none-match", "idempotency-key"].includes(key))
|
|
107
|
+
continue;
|
|
108
|
+
const value = yield (typeof supplier === "function" ? supplier() : supplier);
|
|
109
|
+
if (value == null)
|
|
110
|
+
continue;
|
|
111
|
+
if (isInternalHeader(key))
|
|
112
|
+
throw new Error(`${name} is an internal header and is not supported`);
|
|
113
|
+
if (key === "authorization" && !/^agora token=\S+$/i.test(value))
|
|
114
|
+
throw new Error("Only Agora token authorization is supported");
|
|
115
|
+
if (key === "idempotency-key")
|
|
116
|
+
validateIdempotencyKey(value);
|
|
117
|
+
if (key === "idempotency-key" &&
|
|
118
|
+
!(method === "POST" &&
|
|
119
|
+
(["/sessions", "/sessions/ephemeral", "/campaigns"].includes(path) ||
|
|
120
|
+
/^\/campaigns\/[^/]+:(pause|resume|cancel)$/.test(path))))
|
|
121
|
+
throw new Error("Idempotency-Key is only supported for session starts and campaign creation/actions");
|
|
122
|
+
resolved[key] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const response = yield fetcher({
|
|
126
|
+
url: `${this.baseUrl().replace(/\/+$/, "")}/conversational-ai/v1/projects/${segment(appid)}${path}`,
|
|
127
|
+
method,
|
|
128
|
+
contentType: "application/json",
|
|
129
|
+
requestType: "json",
|
|
130
|
+
responseType: "json",
|
|
131
|
+
body: bodySnapshot,
|
|
132
|
+
queryParameters: querySnapshot,
|
|
133
|
+
headers: resolved,
|
|
134
|
+
timeoutMs: ((_e = (_d = requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : this.options.timeoutInSeconds) !== null && _e !== void 0 ? _e : 60) * 1000,
|
|
135
|
+
// Writes never retry automatically, including requests with explicit idempotency keys.
|
|
136
|
+
maxRetries: method === "GET" ? ((_g = (_f = requestOptions.maxRetries) !== null && _f !== void 0 ? _f : this.options.maxRetries) !== null && _g !== void 0 ? _g : 2) : 0,
|
|
137
|
+
abortSignal: requestOptions.abortSignal,
|
|
138
|
+
fetchFn: this.options.fetch,
|
|
139
|
+
});
|
|
140
|
+
if (response.ok)
|
|
141
|
+
return { data: response.body, rawResponse: response.rawResponse };
|
|
142
|
+
const error = response.error;
|
|
143
|
+
const status = "statusCode" in error ? error.statusCode : response.rawResponse.status;
|
|
144
|
+
const detail = "body" in error ? error.body : error;
|
|
145
|
+
if (status === 412)
|
|
146
|
+
throw new PreconditionFailedError(detail, response.rawResponse, () => this.request("GET", path.includes("/keys/") ? path.split("/keys/")[0] : path, appid, undefined, {}, {}, requestOptions, true));
|
|
147
|
+
throw new V3Error(status, detail, response.rawResponse);
|
|
148
|
+
});
|
|
149
|
+
return HttpResponsePromise.fromPromise(run());
|
|
150
|
+
}
|
|
151
|
+
}
|