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