@amigo-ai/sdk 1.0.0 → 1.1.1

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 (35) hide show
  1. package/README.md +50 -37
  2. package/dist/index.cjs +36 -2
  3. package/dist/index.cjs.map +2 -2
  4. package/dist/index.mjs +36 -2
  5. package/dist/index.mjs.map +2 -2
  6. package/dist/platform.cjs +1788 -0
  7. package/dist/platform.cjs.map +7 -0
  8. package/dist/platform.mjs +1757 -0
  9. package/dist/platform.mjs.map +7 -0
  10. package/dist/types/core/errors.d.ts +11 -1
  11. package/dist/types/core/utils.d.ts +11 -0
  12. package/dist/types/generated/api-types.d.ts +1 -1
  13. package/dist/types/generated/platform-api-types.d.ts +45240 -0
  14. package/dist/types/platform/core/auth.d.ts +6 -0
  15. package/dist/types/platform/core/branded-types.d.ts +59 -0
  16. package/dist/types/platform/core/openapi-client.d.ts +6 -0
  17. package/dist/types/platform/core/websocket.d.ts +8 -0
  18. package/dist/types/platform/index.d.ts +59 -0
  19. package/dist/types/platform/resources/agents.d.ts +107 -0
  20. package/dist/types/platform/resources/api-keys.d.ts +57 -0
  21. package/dist/types/platform/resources/context-graphs.d.ts +114 -0
  22. package/dist/types/platform/resources/conversations.d.ts +154 -0
  23. package/dist/types/platform/resources/data-sources.d.ts +143 -0
  24. package/dist/types/platform/resources/events.d.ts +253 -0
  25. package/dist/types/platform/resources/fhir.d.ts +186 -0
  26. package/dist/types/platform/resources/integrations.d.ts +114 -0
  27. package/dist/types/platform/resources/phone-numbers.d.ts +170 -0
  28. package/dist/types/platform/resources/services.d.ts +133 -0
  29. package/dist/types/platform/resources/sessions.d.ts +61 -0
  30. package/dist/types/platform/resources/skills.d.ts +169 -0
  31. package/dist/types/platform/resources/workspaces.d.ts +187 -0
  32. package/package.json +15 -11
  33. package/assets/readme/amigo-banner.png +0 -0
  34. package/assets/readme/classic-ts-architecture.png +0 -0
  35. package/assets/readme/classic-ts-architecture.svg +0 -102
@@ -0,0 +1,1788 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
31
+
32
+ // src/platform/index.ts
33
+ var index_exports = {};
34
+ __export(index_exports, {
35
+ AmigoError: () => AmigoError,
36
+ AuthenticationError: () => AuthenticationError,
37
+ BadRequestError: () => BadRequestError,
38
+ ConfigurationError: () => ConfigurationError,
39
+ ConflictError: () => ConflictError,
40
+ NetworkError: () => NetworkError,
41
+ NotFoundError: () => NotFoundError,
42
+ ParseError: () => ParseError,
43
+ PermissionError: () => PermissionError,
44
+ PlatformClient: () => PlatformClient,
45
+ RateLimitError: () => RateLimitError,
46
+ ServerError: () => ServerError,
47
+ ServiceUnavailableError: () => ServiceUnavailableError,
48
+ ValidationError: () => ValidationError,
49
+ callSid: () => callSid,
50
+ contextGraphId: () => contextGraphId,
51
+ createPlatformFetch: () => createPlatformFetch,
52
+ dataSourceId: () => dataSourceId,
53
+ entityId: () => entityId,
54
+ integrationId: () => integrationId,
55
+ isAmigoError: () => isAmigoError,
56
+ monitorConceptId: () => monitorConceptId,
57
+ operatorId: () => operatorId,
58
+ phoneNumberId: () => phoneNumberId,
59
+ platformAgentId: () => platformAgentId,
60
+ platformApiKeyId: () => platformApiKeyId,
61
+ platformConversationId: () => platformConversationId,
62
+ platformServiceId: () => platformServiceId,
63
+ reviewItemId: () => reviewItemId,
64
+ skillId: () => skillId,
65
+ taskId: () => taskId,
66
+ unificationRuleId: () => unificationRuleId,
67
+ workspaceId: () => workspaceId
68
+ });
69
+ module.exports = __toCommonJS(index_exports);
70
+
71
+ // src/core/utils.ts
72
+ async function extractData(responsePromise) {
73
+ const result = await responsePromise;
74
+ const data = result.data;
75
+ if (data === void 0 || data === null) {
76
+ throw new ParseError("Expected response data to be present for successful request", "response");
77
+ }
78
+ return data;
79
+ }
80
+ async function* parseSseStream(response) {
81
+ const body = response.body;
82
+ if (!body) return;
83
+ const reader = body.getReader();
84
+ const decoder = new TextDecoder();
85
+ let bufferedText = "";
86
+ let eventId;
87
+ let eventName;
88
+ let retry;
89
+ let dataLines = [];
90
+ const flushEvent = function* () {
91
+ if (dataLines.length === 0) {
92
+ eventName = void 0;
93
+ retry = void 0;
94
+ return;
95
+ }
96
+ const rawData = dataLines.join("\n");
97
+ let data = rawData;
98
+ try {
99
+ data = JSON.parse(rawData);
100
+ } catch {
101
+ }
102
+ const event = { data };
103
+ if (eventId !== void 0) event.id = eventId;
104
+ if (eventName !== void 0) event.event = eventName;
105
+ if (retry !== void 0) event.retry = retry;
106
+ eventName = void 0;
107
+ retry = void 0;
108
+ dataLines = [];
109
+ yield event;
110
+ };
111
+ const processLine = function* (line) {
112
+ if (line === "") {
113
+ yield* flushEvent();
114
+ return;
115
+ }
116
+ if (line.startsWith(":")) return;
117
+ const colonIndex = line.indexOf(":");
118
+ const field = colonIndex === -1 ? line : line.slice(0, colonIndex);
119
+ const value = colonIndex === -1 ? "" : line.slice(colonIndex + 1).replace(/^ /, "");
120
+ switch (field) {
121
+ case "id":
122
+ eventId = value;
123
+ break;
124
+ case "event":
125
+ eventName = value;
126
+ break;
127
+ case "data":
128
+ dataLines.push(value);
129
+ break;
130
+ case "retry": {
131
+ const retryMs = Number.parseInt(value, 10);
132
+ if (!Number.isNaN(retryMs)) retry = retryMs;
133
+ break;
134
+ }
135
+ }
136
+ };
137
+ try {
138
+ while (true) {
139
+ const { done, value } = await reader.read();
140
+ if (done) break;
141
+ bufferedText += decoder.decode(value, { stream: true });
142
+ let newlineIndex;
143
+ while ((newlineIndex = bufferedText.search(/\r?\n/)) !== -1) {
144
+ const line = bufferedText.slice(0, newlineIndex);
145
+ const newlineLength = bufferedText[newlineIndex] === "\r" && bufferedText[newlineIndex + 1] === "\n" ? 2 : 1;
146
+ bufferedText = bufferedText.slice(newlineIndex + newlineLength);
147
+ yield* processLine(line);
148
+ }
149
+ }
150
+ const trailing = bufferedText.trimEnd();
151
+ if (trailing) {
152
+ yield* processLine(trailing);
153
+ }
154
+ yield* flushEvent();
155
+ } finally {
156
+ reader.releaseLock();
157
+ }
158
+ }
159
+ async function parseResponseBody(response) {
160
+ try {
161
+ const text = await response.text();
162
+ if (!text) return void 0;
163
+ try {
164
+ return JSON.parse(text);
165
+ } catch {
166
+ return text;
167
+ }
168
+ } catch {
169
+ return void 0;
170
+ }
171
+ }
172
+ function isNetworkError(error) {
173
+ if (!(error instanceof Error)) return false;
174
+ return error instanceof TypeError || error.message.includes("fetch") || error.message.includes("Failed to fetch") || error.message.includes("Network request failed") || error.message.includes("ECONNREFUSED") || error.message.includes("ETIMEDOUT") || error.message.includes("ENOTFOUND") || error.message.includes("network");
175
+ }
176
+
177
+ // src/core/errors.ts
178
+ var SENSITIVE_FIELDS = /* @__PURE__ */ new Set([
179
+ "id_token",
180
+ "access_token",
181
+ "refresh_token",
182
+ "authorization",
183
+ "api_key",
184
+ "apikey",
185
+ "token",
186
+ "secret",
187
+ "password",
188
+ "x-api-key"
189
+ ]);
190
+ function sanitizeErrorContext(obj) {
191
+ if (obj === null || obj === void 0) return obj;
192
+ if (typeof obj !== "object") return obj;
193
+ if (Array.isArray(obj)) return obj.map(sanitizeErrorContext);
194
+ const result = {};
195
+ for (const [key, value] of Object.entries(obj)) {
196
+ if (SENSITIVE_FIELDS.has(key.toLowerCase())) {
197
+ result[key] = "[REDACTED]";
198
+ } else if (typeof value === "object" && value !== null) {
199
+ result[key] = sanitizeErrorContext(value);
200
+ } else {
201
+ result[key] = value;
202
+ }
203
+ }
204
+ return result;
205
+ }
206
+ var AmigoError = class extends Error {
207
+ constructor(message, options) {
208
+ super(message);
209
+ /** Unique error code for programmatic error handling */
210
+ __publicField(this, "errorCode");
211
+ /** HTTP status code if applicable */
212
+ __publicField(this, "statusCode");
213
+ /** Additional context data */
214
+ __publicField(this, "context");
215
+ this.name = this.constructor.name;
216
+ Object.setPrototypeOf(this, new.target.prototype);
217
+ if (Error.captureStackTrace) {
218
+ Error.captureStackTrace(this, this.constructor);
219
+ }
220
+ this.statusCode = options?.statusCode;
221
+ this.errorCode = options?.errorCode;
222
+ this.context = options?.context;
223
+ }
224
+ /**
225
+ * Returns a JSON-serializable representation of the error.
226
+ * Sensitive fields (tokens, keys) are redacted to prevent leakage.
227
+ */
228
+ toJSON() {
229
+ return {
230
+ name: this.name,
231
+ message: this.message,
232
+ code: this.errorCode,
233
+ statusCode: this.statusCode,
234
+ context: sanitizeErrorContext(this.context),
235
+ stack: this.stack
236
+ };
237
+ }
238
+ };
239
+ function isAmigoErrorOptions(value) {
240
+ if (!value || typeof value !== "object") return false;
241
+ const options = value;
242
+ return "statusCode" in options && (typeof options.statusCode === "number" || options.statusCode === void 0) || "errorCode" in options && (typeof options.errorCode === "string" || options.errorCode === void 0) || "context" in options && (typeof options.context === "object" || options.context === void 0);
243
+ }
244
+ var BadRequestError = class extends AmigoError {
245
+ constructor(message, options) {
246
+ super(message, { ...options, statusCode: options?.statusCode ?? 400 });
247
+ }
248
+ };
249
+ var AuthenticationError = class extends AmigoError {
250
+ constructor(message, options) {
251
+ super(message, { ...options, statusCode: options?.statusCode ?? 401 });
252
+ }
253
+ };
254
+ var PermissionError = class extends AmigoError {
255
+ constructor(message, options) {
256
+ super(message, { ...options, statusCode: options?.statusCode ?? 403 });
257
+ }
258
+ };
259
+ var NotFoundError = class extends AmigoError {
260
+ constructor(message, options) {
261
+ super(message, { ...options, statusCode: options?.statusCode ?? 404 });
262
+ }
263
+ };
264
+ var ConflictError = class extends AmigoError {
265
+ constructor(message, options) {
266
+ super(message, { ...options, statusCode: options?.statusCode ?? 409 });
267
+ }
268
+ };
269
+ var RateLimitError = class extends AmigoError {
270
+ constructor(message, options) {
271
+ super(message, { ...options, statusCode: options?.statusCode ?? 429 });
272
+ }
273
+ };
274
+ var ServerError = class extends AmigoError {
275
+ constructor(message, options) {
276
+ super(message, { ...options, statusCode: options?.statusCode ?? 500 });
277
+ }
278
+ };
279
+ var ServiceUnavailableError = class extends ServerError {
280
+ constructor(message, options) {
281
+ super(message, { ...options, statusCode: options?.statusCode ?? 503 });
282
+ }
283
+ };
284
+ var ConfigurationError = class extends AmigoError {
285
+ constructor(message, field) {
286
+ super(message, { context: { field } });
287
+ this.field = field;
288
+ }
289
+ };
290
+ var ValidationError = class extends BadRequestError {
291
+ constructor(msg, optionsOrFieldErrors, fieldErrors) {
292
+ const isErrorOptions = isAmigoErrorOptions(optionsOrFieldErrors);
293
+ super(
294
+ msg,
295
+ isErrorOptions ? { ...optionsOrFieldErrors, statusCode: optionsOrFieldErrors.statusCode ?? 422 } : { statusCode: 422 }
296
+ );
297
+ this.fieldErrors = fieldErrors;
298
+ this.fieldErrors = isErrorOptions ? fieldErrors : optionsOrFieldErrors;
299
+ }
300
+ };
301
+ var NetworkError = class extends AmigoError {
302
+ constructor(message, originalError, request) {
303
+ super(message, { context: { request } });
304
+ this.originalError = originalError;
305
+ this.request = request;
306
+ }
307
+ };
308
+ var ParseError = class extends AmigoError {
309
+ constructor(message, parseType, originalError) {
310
+ super(message, { context: { parseType } });
311
+ this.parseType = parseType;
312
+ this.originalError = originalError;
313
+ }
314
+ };
315
+ function isAmigoError(error) {
316
+ return error instanceof AmigoError;
317
+ }
318
+ function createApiError(response, body) {
319
+ const map = {
320
+ 400: BadRequestError,
321
+ 401: AuthenticationError,
322
+ 403: PermissionError,
323
+ 404: NotFoundError,
324
+ 409: ConflictError,
325
+ 422: ValidationError,
326
+ 429: RateLimitError,
327
+ 500: ServerError,
328
+ 503: ServiceUnavailableError
329
+ };
330
+ const errorMessageKeys = ["message", "error", "detail"];
331
+ const ErrorClass = map[response.status] ?? AmigoError;
332
+ let message = `HTTP ${response.status} ${response.statusText}`;
333
+ if (body && typeof body === "object") {
334
+ for (const key of errorMessageKeys) {
335
+ if (key in body) {
336
+ message = String(body[key]);
337
+ break;
338
+ }
339
+ }
340
+ }
341
+ const error = new ErrorClass(message, {
342
+ statusCode: response.status,
343
+ errorCode: body && typeof body === "object" && "code" in body ? String(body.code) : void 0,
344
+ context: { response: sanitizeErrorContext(body) }
345
+ });
346
+ return error;
347
+ }
348
+ function createErrorMiddleware() {
349
+ return {
350
+ onResponse: async ({ response }) => {
351
+ if (!response.ok) {
352
+ const body = await parseResponseBody(response);
353
+ throw createApiError(response, body);
354
+ }
355
+ },
356
+ onError: async ({ error, request }) => {
357
+ if (isNetworkError(error)) {
358
+ throw new NetworkError(
359
+ `Network error: ${error instanceof Error ? error.message : String(error)}`,
360
+ error instanceof Error ? error : new Error(String(error)),
361
+ {
362
+ url: request?.url,
363
+ method: request?.method
364
+ }
365
+ );
366
+ }
367
+ throw error;
368
+ }
369
+ };
370
+ }
371
+
372
+ // src/platform/core/openapi-client.ts
373
+ var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
374
+
375
+ // src/platform/core/auth.ts
376
+ function createPlatformAuthMiddleware(apiKey) {
377
+ return {
378
+ onRequest: async ({ request }) => {
379
+ request.headers.set("Authorization", `Bearer ${apiKey}`);
380
+ return request;
381
+ }
382
+ };
383
+ }
384
+
385
+ // src/core/retry.ts
386
+ var DEFAULT_RETRYABLE_STATUS = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
387
+ var DEFAULT_RETRYABLE_METHODS = /* @__PURE__ */ new Set(["GET"]);
388
+ function resolveRetryOptions(options) {
389
+ return {
390
+ maxAttempts: options?.maxAttempts ?? 3,
391
+ backoffBaseMs: options?.backoffBaseMs ?? 250,
392
+ maxDelayMs: options?.maxDelayMs ?? 3e4,
393
+ retryOnStatus: new Set(options?.retryOnStatus ?? DEFAULT_RETRYABLE_STATUS),
394
+ retryOnMethods: new Set(options?.retryOnMethods ?? DEFAULT_RETRYABLE_METHODS)
395
+ };
396
+ }
397
+ function clamp(value, min, max) {
398
+ return Math.max(min, Math.min(max, value));
399
+ }
400
+ function parseRetryAfterMs(headerValue, maxDelayMs) {
401
+ if (!headerValue) return null;
402
+ const seconds = Number(headerValue);
403
+ if (Number.isFinite(seconds)) {
404
+ return clamp(seconds * 1e3, 0, maxDelayMs);
405
+ }
406
+ const date = new Date(headerValue);
407
+ const ms = date.getTime() - Date.now();
408
+ if (Number.isFinite(ms)) {
409
+ return clamp(ms, 0, maxDelayMs);
410
+ }
411
+ return null;
412
+ }
413
+ function computeBackoffWithJitterMs(attemptIndexZeroBased, baseMs, capMs) {
414
+ const windowMs = Math.min(capMs, baseMs * Math.pow(2, attemptIndexZeroBased));
415
+ return Math.random() * windowMs;
416
+ }
417
+ function isAbortError(err) {
418
+ return typeof err === "object" && err !== null && "name" in err && err["name"] === "AbortError";
419
+ }
420
+ function isNetworkError2(err) {
421
+ return err instanceof TypeError && !isAbortError(err);
422
+ }
423
+ async function abortableSleep(ms, signal) {
424
+ if (ms <= 0) {
425
+ signal?.throwIfAborted?.();
426
+ return;
427
+ }
428
+ await new Promise((resolve, reject) => {
429
+ const rejectWith = signal?.reason instanceof Error ? signal.reason : signal?.reason ?? new Error("AbortError");
430
+ if (signal?.aborted) {
431
+ reject(rejectWith);
432
+ return;
433
+ }
434
+ const t = setTimeout(() => {
435
+ off();
436
+ resolve();
437
+ }, ms);
438
+ const onAbort = () => {
439
+ off();
440
+ clearTimeout(t);
441
+ reject(rejectWith);
442
+ };
443
+ const off = () => signal?.removeEventListener("abort", onAbort);
444
+ signal?.addEventListener("abort", onAbort, { once: true });
445
+ });
446
+ }
447
+ function createRetryingFetch(retryOptions, baseFetch) {
448
+ const resolved = resolveRetryOptions(retryOptions);
449
+ const underlying = baseFetch ?? globalThis.fetch;
450
+ const retryingFetch = async (input, init) => {
451
+ const inputMethod = typeof Request !== "undefined" && input instanceof Request ? input.method : void 0;
452
+ const method = (init?.method ?? inputMethod ?? "GET").toUpperCase();
453
+ const signal = init?.signal;
454
+ const isMethodRetryableByDefault = resolved.retryOnMethods.has(method);
455
+ const maxAttempts = Math.max(1, resolved.maxAttempts);
456
+ for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
457
+ let response = null;
458
+ let error = null;
459
+ try {
460
+ response = await underlying(input, init);
461
+ } catch (err) {
462
+ error = err;
463
+ }
464
+ if (!error && response && response.ok) {
465
+ return response;
466
+ }
467
+ let shouldRetry = false;
468
+ let delayMs = null;
469
+ if (isNetworkError2(error)) {
470
+ shouldRetry = isMethodRetryableByDefault;
471
+ if (shouldRetry) {
472
+ delayMs = computeBackoffWithJitterMs(
473
+ attempt - 1,
474
+ resolved.backoffBaseMs,
475
+ resolved.maxDelayMs
476
+ );
477
+ }
478
+ } else if (response) {
479
+ const status = response.status;
480
+ if (method === "POST") {
481
+ if (status === 429) {
482
+ const ra = response.headers.get("Retry-After");
483
+ const parsed = parseRetryAfterMs(ra, resolved.maxDelayMs);
484
+ if (parsed !== null) {
485
+ shouldRetry = true;
486
+ delayMs = parsed;
487
+ }
488
+ }
489
+ } else if (isMethodRetryableByDefault && resolved.retryOnStatus.has(status)) {
490
+ const ra = response.headers.get("Retry-After");
491
+ delayMs = parseRetryAfterMs(ra, resolved.maxDelayMs) ?? computeBackoffWithJitterMs(attempt - 1, resolved.backoffBaseMs, resolved.maxDelayMs);
492
+ shouldRetry = true;
493
+ }
494
+ }
495
+ const attemptsRemain = attempt < maxAttempts;
496
+ if (!shouldRetry || !attemptsRemain) {
497
+ if (error) throw error;
498
+ return response;
499
+ }
500
+ if (signal?.aborted) {
501
+ if (error) throw error;
502
+ return response;
503
+ }
504
+ await abortableSleep(delayMs ?? 0, signal ?? void 0);
505
+ }
506
+ throw new Error("Retry loop exited unexpectedly");
507
+ };
508
+ return retryingFetch;
509
+ }
510
+
511
+ // src/platform/core/openapi-client.ts
512
+ var createClient = typeof import_openapi_fetch.default === "function" ? import_openapi_fetch.default : import_openapi_fetch.default.default;
513
+ function createPlatformFetch(config, mockFetch) {
514
+ const wrappedFetch = createRetryingFetch(
515
+ config.retry,
516
+ mockFetch ?? config.fetch ?? globalThis.fetch
517
+ );
518
+ const client = createClient({
519
+ baseUrl: config.baseUrl,
520
+ fetch: wrappedFetch
521
+ });
522
+ client.use(createErrorMiddleware());
523
+ client.use(createPlatformAuthMiddleware(config.apiKey));
524
+ return client;
525
+ }
526
+
527
+ // src/platform/core/websocket.ts
528
+ function webSocketBaseFromHttpBase(baseUrl) {
529
+ const url = new URL(baseUrl);
530
+ if (url.protocol === "https:") {
531
+ url.protocol = "wss:";
532
+ } else if (url.protocol === "http:") {
533
+ url.protocol = "ws:";
534
+ } else if (url.protocol !== "ws:" && url.protocol !== "wss:") {
535
+ throw new ConfigurationError(`Unsupported Platform API protocol: ${url.protocol}`, "baseUrl");
536
+ }
537
+ return url.toString().replace(/\/$/, "");
538
+ }
539
+ function getWebSocketConstructor(override) {
540
+ if (override) return override;
541
+ if (typeof globalThis.WebSocket === "function") {
542
+ return globalThis.WebSocket;
543
+ }
544
+ throw new ConfigurationError(
545
+ "WebSocket is not available in this runtime; pass WebSocket in the PlatformClient config",
546
+ "WebSocket"
547
+ );
548
+ }
549
+
550
+ // src/platform/resources/agents.ts
551
+ var PlatformAgentResource = class {
552
+ constructor(c, workspaceId2) {
553
+ this.c = c;
554
+ this.workspaceId = workspaceId2;
555
+ }
556
+ /** List agents in the workspace. */
557
+ async list(options) {
558
+ return extractData(
559
+ this.c.GET("/v1/{workspace_id}/agents", {
560
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
561
+ })
562
+ );
563
+ }
564
+ /** Get an agent by ID. */
565
+ async get(options) {
566
+ return extractData(
567
+ this.c.GET("/v1/{workspace_id}/agents/{agent_id}", {
568
+ params: { path: { workspace_id: this.workspaceId, agent_id: options.agentId } }
569
+ })
570
+ );
571
+ }
572
+ /** Create a new agent. */
573
+ async create(options) {
574
+ return extractData(
575
+ this.c.POST("/v1/{workspace_id}/agents", {
576
+ params: { path: { workspace_id: this.workspaceId } },
577
+ body: options.body
578
+ })
579
+ );
580
+ }
581
+ /** Update an agent. */
582
+ async update(options) {
583
+ return extractData(
584
+ this.c.PUT("/v1/{workspace_id}/agents/{agent_id}", {
585
+ params: { path: { workspace_id: this.workspaceId, agent_id: options.agentId } },
586
+ body: options.body
587
+ })
588
+ );
589
+ }
590
+ /** Delete an agent. */
591
+ async delete(options) {
592
+ await this.c.DELETE("/v1/{workspace_id}/agents/{agent_id}", {
593
+ params: { path: { workspace_id: this.workspaceId, agent_id: options.agentId } }
594
+ });
595
+ return void 0;
596
+ }
597
+ /** List agent versions. */
598
+ async listVersions(options) {
599
+ return extractData(
600
+ this.c.GET("/v1/{workspace_id}/agents/{agent_id}/versions", {
601
+ params: {
602
+ path: { workspace_id: this.workspaceId, agent_id: options.agentId },
603
+ query: options.query
604
+ }
605
+ })
606
+ );
607
+ }
608
+ /** Get a specific agent version, or pass `"latest"` for the most recent version. */
609
+ async getVersion(options) {
610
+ return extractData(
611
+ this.c.GET("/v1/{workspace_id}/agents/{agent_id}/versions/{version}", {
612
+ params: {
613
+ path: {
614
+ workspace_id: this.workspaceId,
615
+ agent_id: options.agentId,
616
+ version: options.version
617
+ }
618
+ }
619
+ })
620
+ );
621
+ }
622
+ /** Create a new agent version. */
623
+ async createVersion(options) {
624
+ return extractData(
625
+ this.c.POST("/v1/{workspace_id}/agents/{agent_id}/versions", {
626
+ params: { path: { workspace_id: this.workspaceId, agent_id: options.agentId } },
627
+ body: options.body
628
+ })
629
+ );
630
+ }
631
+ };
632
+
633
+ // src/platform/resources/api-keys.ts
634
+ var PlatformApiKeyResource = class {
635
+ constructor(c, workspaceId2) {
636
+ this.c = c;
637
+ this.workspaceId = workspaceId2;
638
+ }
639
+ /** Get information about the currently authenticated API key. */
640
+ async me() {
641
+ return extractData(this.c.GET("/v1/auth/me"));
642
+ }
643
+ /** List API keys in the workspace. */
644
+ async list(options) {
645
+ return extractData(
646
+ this.c.GET("/v1/{workspace_id}/api-keys", {
647
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
648
+ })
649
+ );
650
+ }
651
+ /** Create a new API key. */
652
+ async create(options) {
653
+ return extractData(
654
+ this.c.POST("/v1/{workspace_id}/api-keys", {
655
+ params: { path: { workspace_id: this.workspaceId } },
656
+ body: options.body
657
+ })
658
+ );
659
+ }
660
+ /** Delete an API key. */
661
+ async delete(options) {
662
+ await this.c.DELETE("/v1/{workspace_id}/api-keys/{key_id}", {
663
+ params: { path: { workspace_id: this.workspaceId, key_id: options.keyId } }
664
+ });
665
+ return void 0;
666
+ }
667
+ /** Rotate an API key and return the replacement secret. */
668
+ async rotate(options) {
669
+ return extractData(
670
+ this.c.POST("/v1/{workspace_id}/api-keys/{key_id}/rotate", {
671
+ params: { path: { workspace_id: this.workspaceId, key_id: options.keyId } },
672
+ body: options.body
673
+ })
674
+ );
675
+ }
676
+ };
677
+
678
+ // src/platform/resources/context-graphs.ts
679
+ var ContextGraphResource = class {
680
+ constructor(c, workspaceId2) {
681
+ this.c = c;
682
+ this.workspaceId = workspaceId2;
683
+ }
684
+ /** List context graphs in the workspace. */
685
+ async list(options) {
686
+ return extractData(
687
+ this.c.GET("/v1/{workspace_id}/context-graphs", {
688
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
689
+ })
690
+ );
691
+ }
692
+ /** Get a context graph by ID. */
693
+ async get(options) {
694
+ return extractData(
695
+ this.c.GET("/v1/{workspace_id}/context-graphs/{context_graph_id}", {
696
+ params: {
697
+ path: {
698
+ workspace_id: this.workspaceId,
699
+ context_graph_id: options.contextGraphId
700
+ }
701
+ }
702
+ })
703
+ );
704
+ }
705
+ /** Create a new context graph. */
706
+ async create(options) {
707
+ return extractData(
708
+ this.c.POST("/v1/{workspace_id}/context-graphs", {
709
+ params: { path: { workspace_id: this.workspaceId } },
710
+ body: options.body
711
+ })
712
+ );
713
+ }
714
+ /** Update a context graph. */
715
+ async update(options) {
716
+ return extractData(
717
+ this.c.PUT("/v1/{workspace_id}/context-graphs/{context_graph_id}", {
718
+ params: {
719
+ path: {
720
+ workspace_id: this.workspaceId,
721
+ context_graph_id: options.contextGraphId
722
+ }
723
+ },
724
+ body: options.body
725
+ })
726
+ );
727
+ }
728
+ /** Delete a context graph. */
729
+ async delete(options) {
730
+ await this.c.DELETE("/v1/{workspace_id}/context-graphs/{context_graph_id}", {
731
+ params: {
732
+ path: {
733
+ workspace_id: this.workspaceId,
734
+ context_graph_id: options.contextGraphId
735
+ }
736
+ }
737
+ });
738
+ return void 0;
739
+ }
740
+ /** List context graph versions. */
741
+ async listVersions(options) {
742
+ return extractData(
743
+ this.c.GET("/v1/{workspace_id}/context-graphs/{context_graph_id}/versions", {
744
+ params: {
745
+ path: {
746
+ workspace_id: this.workspaceId,
747
+ context_graph_id: options.contextGraphId
748
+ },
749
+ query: options.query
750
+ }
751
+ })
752
+ );
753
+ }
754
+ /** Get a specific context graph version. */
755
+ async getVersion(options) {
756
+ return extractData(
757
+ this.c.GET("/v1/{workspace_id}/context-graphs/{context_graph_id}/versions/{version}", {
758
+ params: {
759
+ path: {
760
+ workspace_id: this.workspaceId,
761
+ context_graph_id: options.contextGraphId,
762
+ version: options.version
763
+ }
764
+ }
765
+ })
766
+ );
767
+ }
768
+ /** Create a new context graph version. */
769
+ async createVersion(options) {
770
+ return extractData(
771
+ this.c.POST("/v1/{workspace_id}/context-graphs/{context_graph_id}/versions", {
772
+ params: {
773
+ path: {
774
+ workspace_id: this.workspaceId,
775
+ context_graph_id: options.contextGraphId
776
+ }
777
+ },
778
+ body: options.body
779
+ })
780
+ );
781
+ }
782
+ };
783
+
784
+ // src/platform/resources/conversations.ts
785
+ var PlatformConversationResource = class {
786
+ constructor(c, workspaceId2) {
787
+ this.c = c;
788
+ this.workspaceId = workspaceId2;
789
+ }
790
+ /** List voice and text conversations in the workspace. */
791
+ async list(options) {
792
+ return extractData(
793
+ this.c.GET("/v1/{workspace_id}/conversations", {
794
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
795
+ })
796
+ );
797
+ }
798
+ /** Create a text conversation. */
799
+ async create(options) {
800
+ return extractData(
801
+ this.c.POST("/v1/{workspace_id}/conversations", {
802
+ params: { path: { workspace_id: this.workspaceId } },
803
+ body: options.body
804
+ })
805
+ );
806
+ }
807
+ /** Get a conversation detail by ID. */
808
+ async get(options) {
809
+ return extractData(
810
+ this.c.GET("/v1/{workspace_id}/conversations/{conversation_id}", {
811
+ params: {
812
+ path: {
813
+ workspace_id: this.workspaceId,
814
+ conversation_id: options.conversationId
815
+ }
816
+ }
817
+ })
818
+ );
819
+ }
820
+ /** Close a text conversation. */
821
+ async close(options) {
822
+ await this.c.DELETE("/v1/{workspace_id}/conversations/{conversation_id}", {
823
+ params: {
824
+ path: {
825
+ workspace_id: this.workspaceId,
826
+ conversation_id: options.conversationId
827
+ }
828
+ }
829
+ });
830
+ return void 0;
831
+ }
832
+ /** Send a text turn and receive the full JSON response. */
833
+ async createTurn(options) {
834
+ return extractData(
835
+ this.c.POST("/v1/{workspace_id}/conversations/{conversation_id}/turns", {
836
+ params: {
837
+ path: {
838
+ workspace_id: this.workspaceId,
839
+ conversation_id: options.conversationId
840
+ },
841
+ query: options.query
842
+ },
843
+ body: options.body,
844
+ headers: { Accept: "application/json" }
845
+ })
846
+ );
847
+ }
848
+ /** Send a text turn and receive typed Server-Sent Events. */
849
+ async streamTurn(options) {
850
+ const resp = await this.c.POST("/v1/{workspace_id}/conversations/{conversation_id}/turns", {
851
+ params: {
852
+ path: {
853
+ workspace_id: this.workspaceId,
854
+ conversation_id: options.conversationId
855
+ },
856
+ query: options.query
857
+ },
858
+ body: options.body,
859
+ headers: { Accept: "text/event-stream" },
860
+ parseAs: "stream",
861
+ ...options.signal && { signal: options.signal }
862
+ });
863
+ return parseSseStream(resp.response);
864
+ }
865
+ };
866
+
867
+ // src/platform/resources/data-sources.ts
868
+ var DataSourceResource = class {
869
+ constructor(c, workspaceId2) {
870
+ this.c = c;
871
+ this.workspaceId = workspaceId2;
872
+ }
873
+ /** List data sources in the workspace. */
874
+ async list(options) {
875
+ return extractData(
876
+ this.c.GET("/v1/{workspace_id}/data-sources", {
877
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
878
+ })
879
+ );
880
+ }
881
+ /** Get a data source by ID. */
882
+ async get(options) {
883
+ return extractData(
884
+ this.c.GET("/v1/{workspace_id}/data-sources/{data_source_id}", {
885
+ params: {
886
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId }
887
+ }
888
+ })
889
+ );
890
+ }
891
+ /** Create a new data source. */
892
+ async create(options) {
893
+ return extractData(
894
+ this.c.POST("/v1/{workspace_id}/data-sources", {
895
+ params: { path: { workspace_id: this.workspaceId } },
896
+ body: options.body
897
+ })
898
+ );
899
+ }
900
+ /** Update a data source. */
901
+ async update(options) {
902
+ return extractData(
903
+ this.c.PATCH("/v1/{workspace_id}/data-sources/{data_source_id}", {
904
+ params: {
905
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId }
906
+ },
907
+ body: options.body
908
+ })
909
+ );
910
+ }
911
+ /** Get data source status. */
912
+ async getStatus(options) {
913
+ return extractData(
914
+ this.c.GET("/v1/{workspace_id}/data-sources/{data_source_id}/status", {
915
+ params: {
916
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId }
917
+ }
918
+ })
919
+ );
920
+ }
921
+ /** Get data source sync history. */
922
+ async getSyncHistory(options) {
923
+ return extractData(
924
+ this.c.GET("/v1/{workspace_id}/data-sources/{data_source_id}/sync-history", {
925
+ params: {
926
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId },
927
+ query: options.query
928
+ }
929
+ })
930
+ );
931
+ }
932
+ /** Trigger a data source sync. */
933
+ async triggerSync(options) {
934
+ return extractData(
935
+ this.c.POST("/v1/{workspace_id}/data-sources/{data_source_id}/sync", {
936
+ params: {
937
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId }
938
+ }
939
+ })
940
+ );
941
+ }
942
+ /** Delete a data source. */
943
+ async delete(options) {
944
+ await this.c.DELETE("/v1/{workspace_id}/data-sources/{data_source_id}", {
945
+ params: {
946
+ path: { workspace_id: this.workspaceId, data_source_id: options.dataSourceId }
947
+ }
948
+ });
949
+ return void 0;
950
+ }
951
+ };
952
+
953
+ // src/platform/resources/events.ts
954
+ var PlatformEventResource = class {
955
+ constructor(c, workspaceId2) {
956
+ this.c = c;
957
+ this.workspaceId = workspaceId2;
958
+ }
959
+ /** Open the workspace Server-Sent Events stream. */
960
+ async stream(options) {
961
+ const headers = { Accept: "text/event-stream" };
962
+ if (options?.lastEventId) {
963
+ headers["Last-Event-ID"] = options.lastEventId;
964
+ }
965
+ const resp = await this.c.GET("/v1/{workspace_id}/events/stream", {
966
+ params: { path: { workspace_id: this.workspaceId } },
967
+ headers,
968
+ parseAs: "stream",
969
+ ...options?.signal && { signal: options.signal }
970
+ });
971
+ return parseSseStream(resp.response);
972
+ }
973
+ };
974
+
975
+ // src/platform/resources/fhir.ts
976
+ var FhirResource = class {
977
+ constructor(c, workspaceId2) {
978
+ this.c = c;
979
+ this.workspaceId = workspaceId2;
980
+ }
981
+ /** Get FHIR store status for the workspace. */
982
+ async status() {
983
+ return extractData(
984
+ this.c.GET("/v1/{workspace_id}/fhir/status", {
985
+ params: { path: { workspace_id: this.workspaceId } }
986
+ })
987
+ );
988
+ }
989
+ /** Search FHIR resources by type. */
990
+ async searchResources(options) {
991
+ return extractData(
992
+ this.c.GET("/v1/{workspace_id}/fhir/resources/{resource_type}", {
993
+ params: {
994
+ path: { workspace_id: this.workspaceId, resource_type: options.resourceType },
995
+ query: options.query
996
+ }
997
+ })
998
+ );
999
+ }
1000
+ /** Get a specific FHIR resource by type and ID. */
1001
+ async getResource(options) {
1002
+ return extractData(
1003
+ this.c.GET("/v1/{workspace_id}/fhir/resources/{resource_type}/{resource_id}", {
1004
+ params: {
1005
+ path: {
1006
+ workspace_id: this.workspaceId,
1007
+ resource_type: options.resourceType,
1008
+ resource_id: options.resourceId
1009
+ }
1010
+ }
1011
+ })
1012
+ );
1013
+ }
1014
+ /** Create a FHIR resource. */
1015
+ async createResource(options) {
1016
+ return extractData(
1017
+ this.c.POST("/v1/{workspace_id}/fhir/resources/{resource_type}", {
1018
+ params: {
1019
+ path: { workspace_id: this.workspaceId, resource_type: options.resourceType }
1020
+ },
1021
+ body: options.body
1022
+ })
1023
+ );
1024
+ }
1025
+ /** Update a FHIR resource. */
1026
+ async updateResource(options) {
1027
+ return extractData(
1028
+ this.c.PUT("/v1/{workspace_id}/fhir/resources/{resource_type}/{resource_id}", {
1029
+ params: {
1030
+ path: {
1031
+ workspace_id: this.workspaceId,
1032
+ resource_type: options.resourceType,
1033
+ resource_id: options.resourceId
1034
+ }
1035
+ },
1036
+ body: options.body
1037
+ })
1038
+ );
1039
+ }
1040
+ /** Get sync failures. */
1041
+ async syncFailures(options) {
1042
+ return extractData(
1043
+ this.c.GET("/v1/{workspace_id}/fhir/sync-failures", {
1044
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1045
+ })
1046
+ );
1047
+ }
1048
+ /** Import FHIR data. */
1049
+ async import(options) {
1050
+ return extractData(
1051
+ this.c.POST("/v1/{workspace_id}/fhir/import", {
1052
+ params: { path: { workspace_id: this.workspaceId } },
1053
+ body: options.body
1054
+ })
1055
+ );
1056
+ }
1057
+ /** Search patients. */
1058
+ async searchPatients(options) {
1059
+ return extractData(
1060
+ this.c.GET("/v1/{workspace_id}/fhir/patients", {
1061
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1062
+ })
1063
+ );
1064
+ }
1065
+ /** Get patient timeline. */
1066
+ async getPatientTimeline(options) {
1067
+ return extractData(
1068
+ this.c.GET("/v1/{workspace_id}/fhir/patients/{patient_id}/timeline", {
1069
+ params: {
1070
+ path: { workspace_id: this.workspaceId, patient_id: options.patientId },
1071
+ query: options.query
1072
+ }
1073
+ })
1074
+ );
1075
+ }
1076
+ /** Get patient summary. */
1077
+ async getPatientSummary(options) {
1078
+ return extractData(
1079
+ this.c.GET("/v1/{workspace_id}/fhir/patients/{patient_id}/summary", {
1080
+ params: {
1081
+ path: { workspace_id: this.workspaceId, patient_id: options.patientId }
1082
+ }
1083
+ })
1084
+ );
1085
+ }
1086
+ /** Get FHIR views — patients. */
1087
+ async viewPatients(options) {
1088
+ return extractData(
1089
+ this.c.GET("/v1/{workspace_id}/fhir/views/patients", {
1090
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1091
+ })
1092
+ );
1093
+ }
1094
+ /** Get FHIR views — practitioners. */
1095
+ async viewPractitioners(options) {
1096
+ return extractData(
1097
+ this.c.GET("/v1/{workspace_id}/fhir/views/practitioners", {
1098
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1099
+ })
1100
+ );
1101
+ }
1102
+ /** Get FHIR views — locations. */
1103
+ async viewLocations(options) {
1104
+ return extractData(
1105
+ this.c.GET("/v1/{workspace_id}/fhir/views/locations", {
1106
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1107
+ })
1108
+ );
1109
+ }
1110
+ /** Get FHIR views — appointments. */
1111
+ async viewAppointments(options) {
1112
+ return extractData(
1113
+ this.c.GET("/v1/{workspace_id}/fhir/views/appointments", {
1114
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1115
+ })
1116
+ );
1117
+ }
1118
+ /** Get FHIR views — organizations. */
1119
+ async viewOrganizations(options) {
1120
+ return extractData(
1121
+ this.c.GET("/v1/{workspace_id}/fhir/views/organizations", {
1122
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1123
+ })
1124
+ );
1125
+ }
1126
+ /** Get FHIR views — slots. */
1127
+ async viewSlots(options) {
1128
+ return extractData(
1129
+ this.c.GET("/v1/{workspace_id}/fhir/views/slots", {
1130
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1131
+ })
1132
+ );
1133
+ }
1134
+ };
1135
+
1136
+ // src/platform/resources/integrations.ts
1137
+ var IntegrationResource = class {
1138
+ constructor(c, workspaceId2) {
1139
+ this.c = c;
1140
+ this.workspaceId = workspaceId2;
1141
+ }
1142
+ /** List integrations in the workspace. */
1143
+ async list(options) {
1144
+ return extractData(
1145
+ this.c.GET("/v1/{workspace_id}/integrations", {
1146
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1147
+ })
1148
+ );
1149
+ }
1150
+ /** Get an integration by ID. */
1151
+ async get(options) {
1152
+ return extractData(
1153
+ this.c.GET("/v1/{workspace_id}/integrations/{integration_id}", {
1154
+ params: {
1155
+ path: { workspace_id: this.workspaceId, integration_id: options.integrationId }
1156
+ }
1157
+ })
1158
+ );
1159
+ }
1160
+ /** Create a new integration. */
1161
+ async create(options) {
1162
+ return extractData(
1163
+ this.c.POST("/v1/{workspace_id}/integrations", {
1164
+ params: { path: { workspace_id: this.workspaceId } },
1165
+ body: options.body
1166
+ })
1167
+ );
1168
+ }
1169
+ /** Update an integration. */
1170
+ async update(options) {
1171
+ return extractData(
1172
+ this.c.PUT("/v1/{workspace_id}/integrations/{integration_id}", {
1173
+ params: {
1174
+ path: { workspace_id: this.workspaceId, integration_id: options.integrationId }
1175
+ },
1176
+ body: options.body
1177
+ })
1178
+ );
1179
+ }
1180
+ /** Delete an integration. */
1181
+ async delete(options) {
1182
+ await this.c.DELETE("/v1/{workspace_id}/integrations/{integration_id}", {
1183
+ params: {
1184
+ path: { workspace_id: this.workspaceId, integration_id: options.integrationId }
1185
+ }
1186
+ });
1187
+ return void 0;
1188
+ }
1189
+ /** Test an integration endpoint. */
1190
+ async testEndpoint(options) {
1191
+ return extractData(
1192
+ this.c.POST(
1193
+ "/v1/{workspace_id}/integrations/{integration_id}/endpoints/{endpoint_name}/test",
1194
+ {
1195
+ params: {
1196
+ path: {
1197
+ workspace_id: this.workspaceId,
1198
+ integration_id: options.integrationId,
1199
+ endpoint_name: options.endpointName
1200
+ }
1201
+ },
1202
+ body: options.body
1203
+ }
1204
+ )
1205
+ );
1206
+ }
1207
+ /** Check integration health for the workspace. */
1208
+ async healthCheck() {
1209
+ return extractData(
1210
+ this.c.GET("/v1/{workspace_id}/integrations/health-check", {
1211
+ params: { path: { workspace_id: this.workspaceId } }
1212
+ })
1213
+ );
1214
+ }
1215
+ };
1216
+
1217
+ // src/platform/resources/phone-numbers.ts
1218
+ var PhoneNumberResource = class {
1219
+ constructor(c, workspaceId2) {
1220
+ this.c = c;
1221
+ this.workspaceId = workspaceId2;
1222
+ }
1223
+ /** List phone numbers in the workspace. */
1224
+ async list(options) {
1225
+ return extractData(
1226
+ this.c.GET("/v1/{workspace_id}/phone-numbers", {
1227
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1228
+ })
1229
+ );
1230
+ }
1231
+ /** Get a phone number by ID. */
1232
+ async get(options) {
1233
+ return extractData(
1234
+ this.c.GET("/v1/{workspace_id}/phone-numbers/{phone_number_id}", {
1235
+ params: {
1236
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1237
+ }
1238
+ })
1239
+ );
1240
+ }
1241
+ /** Create a phone number. */
1242
+ async create(options) {
1243
+ return extractData(
1244
+ this.c.POST("/v1/{workspace_id}/phone-numbers", {
1245
+ params: { path: { workspace_id: this.workspaceId } },
1246
+ body: options.body
1247
+ })
1248
+ );
1249
+ }
1250
+ /** Update a phone number. */
1251
+ async update(options) {
1252
+ return extractData(
1253
+ this.c.PUT("/v1/{workspace_id}/phone-numbers/{phone_number_id}", {
1254
+ params: {
1255
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1256
+ },
1257
+ body: options.body
1258
+ })
1259
+ );
1260
+ }
1261
+ /** Delete a phone number. */
1262
+ async delete(options) {
1263
+ await this.c.DELETE("/v1/{workspace_id}/phone-numbers/{phone_number_id}", {
1264
+ params: {
1265
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1266
+ }
1267
+ });
1268
+ return void 0;
1269
+ }
1270
+ /** Set call forwarding for a phone number. */
1271
+ async setForwarding(options) {
1272
+ return extractData(
1273
+ this.c.PUT("/v1/{workspace_id}/phone-numbers/{phone_number_id}/forwarding", {
1274
+ params: {
1275
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1276
+ },
1277
+ body: options.body
1278
+ })
1279
+ );
1280
+ }
1281
+ /** Clear call forwarding for a phone number. */
1282
+ async clearForwarding(options) {
1283
+ await this.c.DELETE("/v1/{workspace_id}/phone-numbers/{phone_number_id}/forwarding", {
1284
+ params: {
1285
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1286
+ }
1287
+ });
1288
+ return void 0;
1289
+ }
1290
+ /** Get the Twilio sub-account for the workspace. */
1291
+ async getTwilioSubAccount() {
1292
+ return extractData(
1293
+ this.c.GET("/v1/{workspace_id}/twilio/sub-account", {
1294
+ params: { path: { workspace_id: this.workspaceId } }
1295
+ })
1296
+ );
1297
+ }
1298
+ /** Provision a Twilio sub-account for the workspace. */
1299
+ async provisionTwilioSubAccount() {
1300
+ return extractData(
1301
+ this.c.POST("/v1/{workspace_id}/twilio/sub-account", {
1302
+ params: { path: { workspace_id: this.workspaceId } }
1303
+ })
1304
+ );
1305
+ }
1306
+ /** Search available phone numbers for purchase. */
1307
+ async searchAvailable(options) {
1308
+ return extractData(
1309
+ this.c.GET("/v1/{workspace_id}/twilio/phone-numbers/available", {
1310
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1311
+ })
1312
+ );
1313
+ }
1314
+ /** Purchase a phone number. */
1315
+ async purchase(options) {
1316
+ return extractData(
1317
+ this.c.POST("/v1/{workspace_id}/twilio/phone-numbers/purchase", {
1318
+ params: { path: { workspace_id: this.workspaceId } },
1319
+ body: options.body
1320
+ })
1321
+ );
1322
+ }
1323
+ /** Release a purchased phone number. */
1324
+ async release(options) {
1325
+ await this.c.DELETE("/v1/{workspace_id}/twilio/phone-numbers/{phone_number_id}/release", {
1326
+ params: {
1327
+ path: { workspace_id: this.workspaceId, phone_number_id: options.phoneNumberId }
1328
+ }
1329
+ });
1330
+ return void 0;
1331
+ }
1332
+ /** Bind a channel-manager phone number to a workspace/service. */
1333
+ async bind(options) {
1334
+ return extractData(
1335
+ this.c.POST("/v1/{workspace_id}/phone-numbers/bind", {
1336
+ params: { path: { workspace_id: this.workspaceId } },
1337
+ body: options.body
1338
+ })
1339
+ );
1340
+ }
1341
+ };
1342
+
1343
+ // src/platform/resources/services.ts
1344
+ var PlatformServiceResource = class {
1345
+ constructor(c, workspaceId2) {
1346
+ this.c = c;
1347
+ this.workspaceId = workspaceId2;
1348
+ }
1349
+ /** List services in the workspace. */
1350
+ async list(options) {
1351
+ return extractData(
1352
+ this.c.GET("/v1/{workspace_id}/services", {
1353
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1354
+ })
1355
+ );
1356
+ }
1357
+ /** Get a service by ID. */
1358
+ async get(options) {
1359
+ return extractData(
1360
+ this.c.GET("/v1/{workspace_id}/services/{service_id}", {
1361
+ params: { path: { workspace_id: this.workspaceId, service_id: options.serviceId } }
1362
+ })
1363
+ );
1364
+ }
1365
+ /** Create a new service. */
1366
+ async create(options) {
1367
+ return extractData(
1368
+ this.c.POST("/v1/{workspace_id}/services", {
1369
+ params: { path: { workspace_id: this.workspaceId } },
1370
+ body: options.body
1371
+ })
1372
+ );
1373
+ }
1374
+ /** Update a service. */
1375
+ async update(options) {
1376
+ return extractData(
1377
+ this.c.PUT("/v1/{workspace_id}/services/{service_id}", {
1378
+ params: { path: { workspace_id: this.workspaceId, service_id: options.serviceId } },
1379
+ body: options.body
1380
+ })
1381
+ );
1382
+ }
1383
+ /** Delete a service. */
1384
+ async delete(options) {
1385
+ await this.c.DELETE("/v1/{workspace_id}/services/{service_id}", {
1386
+ params: { path: { workspace_id: this.workspaceId, service_id: options.serviceId } }
1387
+ });
1388
+ return void 0;
1389
+ }
1390
+ /** Upsert a version set for a service. */
1391
+ async upsertVersionSet(options) {
1392
+ return extractData(
1393
+ this.c.PUT("/v1/{workspace_id}/services/{service_id}/version-sets/{name}", {
1394
+ params: {
1395
+ path: {
1396
+ workspace_id: this.workspaceId,
1397
+ service_id: options.serviceId,
1398
+ name: options.name
1399
+ }
1400
+ },
1401
+ body: options.body
1402
+ })
1403
+ );
1404
+ }
1405
+ /** Resolve all tools available to a service. */
1406
+ async resolveTools(options) {
1407
+ return extractData(
1408
+ this.c.GET("/v1/{workspace_id}/services/{service_id}/tools/resolve", {
1409
+ params: {
1410
+ path: { workspace_id: this.workspaceId, service_id: options.serviceId },
1411
+ query: options.query
1412
+ }
1413
+ })
1414
+ );
1415
+ }
1416
+ /** Run one voice turn through a service. */
1417
+ async voiceTurn(options) {
1418
+ return extractData(
1419
+ this.c.POST("/v1/{workspace_id}/services/{service_id}/voice-turn", {
1420
+ params: { path: { workspace_id: this.workspaceId, service_id: options.serviceId } },
1421
+ body: options.body
1422
+ })
1423
+ );
1424
+ }
1425
+ };
1426
+
1427
+ // src/platform/resources/sessions.ts
1428
+ var PlatformSessionResource = class {
1429
+ constructor(c, workspaceId2, realtime) {
1430
+ this.c = c;
1431
+ this.workspaceId = workspaceId2;
1432
+ this.realtime = realtime;
1433
+ }
1434
+ /** List active voice sessions. */
1435
+ async listActive() {
1436
+ return extractData(
1437
+ this.c.GET("/v1/{workspace_id}/sessions/active", {
1438
+ params: { path: { workspace_id: this.workspaceId } }
1439
+ })
1440
+ );
1441
+ }
1442
+ /** Start an SMS, WhatsApp, or web text session with an entity. */
1443
+ async start(options) {
1444
+ return extractData(
1445
+ this.c.POST("/v1/{workspace_id}/sessions/start", {
1446
+ params: { path: { workspace_id: this.workspaceId } },
1447
+ body: options.body
1448
+ })
1449
+ );
1450
+ }
1451
+ /** Inject an external event or operator guidance into an active voice session. */
1452
+ async inject(options) {
1453
+ return extractData(
1454
+ this.c.POST("/v1/{workspace_id}/sessions/{call_sid}/inject", {
1455
+ params: {
1456
+ path: {
1457
+ workspace_id: this.workspaceId,
1458
+ call_sid: options.callSid
1459
+ }
1460
+ },
1461
+ body: options.body
1462
+ })
1463
+ );
1464
+ }
1465
+ /** Build the public platform text-session WebSocket URL. */
1466
+ buildTextSessionUrl(options) {
1467
+ const url = new URL(
1468
+ `/v1/${encodeURIComponent(this.workspaceId)}/sessions/connect`,
1469
+ `${this.realtime.webSocketBaseUrl}/`
1470
+ );
1471
+ url.searchParams.set("service_id", options.serviceId);
1472
+ url.searchParams.set("entity_id", options.entityId);
1473
+ url.searchParams.set("tool_events", String(options.toolEvents ?? true));
1474
+ if (options.conversationId) {
1475
+ url.searchParams.set("conversation_id", options.conversationId);
1476
+ }
1477
+ return url.toString();
1478
+ }
1479
+ /** Connect to the public bidirectional text-session WebSocket. */
1480
+ connectTextSession(options) {
1481
+ const WebSocketCtor = getWebSocketConstructor(options.WebSocket ?? this.realtime.WebSocket);
1482
+ const token = options.token ?? this.realtime.apiKey;
1483
+ const url = this.buildTextSessionUrl(options);
1484
+ return new WebSocketCtor(url, ["auth", token]);
1485
+ }
1486
+ };
1487
+
1488
+ // src/platform/resources/skills.ts
1489
+ var SkillResource = class {
1490
+ constructor(c, workspaceId2) {
1491
+ this.c = c;
1492
+ this.workspaceId = workspaceId2;
1493
+ }
1494
+ /** List skills in the workspace. */
1495
+ async list(options) {
1496
+ return extractData(
1497
+ this.c.GET("/v1/{workspace_id}/skills", {
1498
+ params: { path: { workspace_id: this.workspaceId }, query: options?.query }
1499
+ })
1500
+ );
1501
+ }
1502
+ /** Get a skill by ID. */
1503
+ async get(options) {
1504
+ return extractData(
1505
+ this.c.GET("/v1/{workspace_id}/skills/{skill_id}", {
1506
+ params: { path: { workspace_id: this.workspaceId, skill_id: options.skillId } }
1507
+ })
1508
+ );
1509
+ }
1510
+ /** Create a new skill. */
1511
+ async create(options) {
1512
+ return extractData(
1513
+ this.c.POST("/v1/{workspace_id}/skills", {
1514
+ params: { path: { workspace_id: this.workspaceId } },
1515
+ body: options.body
1516
+ })
1517
+ );
1518
+ }
1519
+ /** Update a skill. */
1520
+ async update(options) {
1521
+ return extractData(
1522
+ this.c.PUT("/v1/{workspace_id}/skills/{skill_id}", {
1523
+ params: { path: { workspace_id: this.workspaceId, skill_id: options.skillId } },
1524
+ body: options.body
1525
+ })
1526
+ );
1527
+ }
1528
+ /** Delete a skill. */
1529
+ async delete(options) {
1530
+ await this.c.DELETE("/v1/{workspace_id}/skills/{skill_id}", {
1531
+ params: { path: { workspace_id: this.workspaceId, skill_id: options.skillId } }
1532
+ });
1533
+ return void 0;
1534
+ }
1535
+ /** Test a skill in isolation. */
1536
+ async test(options) {
1537
+ return extractData(
1538
+ this.c.POST("/v1/{workspace_id}/skills/{skill_id}/test", {
1539
+ params: { path: { workspace_id: this.workspaceId, skill_id: options.skillId } },
1540
+ body: options.body
1541
+ })
1542
+ );
1543
+ }
1544
+ /** Get HSM/service references for a skill. */
1545
+ async getReferences(options) {
1546
+ return extractData(
1547
+ this.c.GET("/v1/{workspace_id}/skills/{skill_id}/references", {
1548
+ params: { path: { workspace_id: this.workspaceId, skill_id: options.skillId } }
1549
+ })
1550
+ );
1551
+ }
1552
+ };
1553
+
1554
+ // src/platform/resources/workspaces.ts
1555
+ var WorkspaceResource = class {
1556
+ constructor(c, workspaceId2) {
1557
+ this.c = c;
1558
+ this.workspaceId = workspaceId2;
1559
+ }
1560
+ requireWorkspaceId() {
1561
+ if (!this.workspaceId) {
1562
+ throw new Error("workspaceId is required for this operation");
1563
+ }
1564
+ return this.workspaceId;
1565
+ }
1566
+ /** List workspaces accessible to this API key. */
1567
+ async list(options) {
1568
+ return extractData(
1569
+ this.c.GET("/v1/workspaces", {
1570
+ params: { query: options?.query }
1571
+ })
1572
+ );
1573
+ }
1574
+ /** Get a workspace by ID. */
1575
+ async get(options) {
1576
+ return extractData(
1577
+ this.c.GET("/v1/workspaces/{workspace_id}", {
1578
+ params: { path: { workspace_id: options?.workspaceId ?? this.requireWorkspaceId() } }
1579
+ })
1580
+ );
1581
+ }
1582
+ /** Create a new workspace. */
1583
+ async create(options) {
1584
+ return extractData(
1585
+ this.c.POST("/v1/workspaces", {
1586
+ body: options.body
1587
+ })
1588
+ );
1589
+ }
1590
+ /** Create a self-service workspace. */
1591
+ async createSelfService(options) {
1592
+ return extractData(
1593
+ this.c.POST("/v1/workspaces/self-service", {
1594
+ body: options.body
1595
+ })
1596
+ );
1597
+ }
1598
+ /** Update a workspace. */
1599
+ async update(options) {
1600
+ return extractData(
1601
+ this.c.PATCH("/v1/workspaces/{workspace_id}", {
1602
+ params: { path: { workspace_id: options.workspaceId ?? this.requireWorkspaceId() } },
1603
+ body: options.body
1604
+ })
1605
+ );
1606
+ }
1607
+ /** Provision workspace resources (idempotent). */
1608
+ async provision(options) {
1609
+ return extractData(
1610
+ this.c.POST("/v1/workspaces/{workspace_id}/provision", {
1611
+ params: { path: { workspace_id: options?.workspaceId ?? this.requireWorkspaceId() } }
1612
+ })
1613
+ );
1614
+ }
1615
+ /** Archive a workspace. */
1616
+ async archive(options) {
1617
+ return extractData(
1618
+ this.c.POST("/v1/workspaces/{workspace_id}/archive", {
1619
+ params: { path: { workspace_id: options.workspaceId ?? this.requireWorkspaceId() } },
1620
+ body: options.body
1621
+ })
1622
+ );
1623
+ }
1624
+ /** Check whether a workspace can be converted between environments. */
1625
+ async checkEnvironmentConversion(options) {
1626
+ return extractData(
1627
+ this.c.GET("/v1/workspaces/{workspace_id}/environment-check", {
1628
+ params: {
1629
+ path: { workspace_id: options?.workspaceId ?? this.requireWorkspaceId() },
1630
+ query: options?.query
1631
+ }
1632
+ })
1633
+ );
1634
+ }
1635
+ /** Convert a workspace environment. */
1636
+ async convertEnvironment(options) {
1637
+ return extractData(
1638
+ this.c.POST("/v1/workspaces/{workspace_id}/convert-environment", {
1639
+ params: { path: { workspace_id: options.workspaceId ?? this.requireWorkspaceId() } },
1640
+ body: options.body
1641
+ })
1642
+ );
1643
+ }
1644
+ /** Get voice settings for a workspace. */
1645
+ async getVoiceSettings(options) {
1646
+ return extractData(
1647
+ this.c.GET("/v1/{workspace_id}/settings/voice", {
1648
+ params: { path: { workspace_id: options?.workspaceId ?? this.requireWorkspaceId() } }
1649
+ })
1650
+ );
1651
+ }
1652
+ /** Update voice settings for a workspace. */
1653
+ async updateVoiceSettings(options) {
1654
+ return extractData(
1655
+ this.c.PUT("/v1/{workspace_id}/settings/voice", {
1656
+ params: { path: { workspace_id: options.workspaceId ?? this.requireWorkspaceId() } },
1657
+ body: options.body
1658
+ })
1659
+ );
1660
+ }
1661
+ /** Get test caller numbers for a workspace. */
1662
+ async getTestCallerNumbers(options) {
1663
+ return extractData(
1664
+ this.c.GET("/v1/workspaces/{workspace_id}/test-caller-numbers", {
1665
+ params: { path: { workspace_id: options?.workspaceId ?? this.requireWorkspaceId() } }
1666
+ })
1667
+ );
1668
+ }
1669
+ /** Update test caller numbers for a workspace. */
1670
+ async updateTestCallerNumbers(options) {
1671
+ return extractData(
1672
+ this.c.PUT("/v1/workspaces/{workspace_id}/test-caller-numbers", {
1673
+ params: { path: { workspace_id: options.workspaceId ?? this.requireWorkspaceId() } },
1674
+ body: options.body
1675
+ })
1676
+ );
1677
+ }
1678
+ };
1679
+
1680
+ // src/platform/core/branded-types.ts
1681
+ function workspaceId(id) {
1682
+ return id;
1683
+ }
1684
+ function skillId(id) {
1685
+ return id;
1686
+ }
1687
+ function integrationId(id) {
1688
+ return id;
1689
+ }
1690
+ function contextGraphId(id) {
1691
+ return id;
1692
+ }
1693
+ function platformAgentId(id) {
1694
+ return id;
1695
+ }
1696
+ function platformServiceId(id) {
1697
+ return id;
1698
+ }
1699
+ function phoneNumberId(id) {
1700
+ return id;
1701
+ }
1702
+ function platformApiKeyId(id) {
1703
+ return id;
1704
+ }
1705
+ function callSid(id) {
1706
+ return id;
1707
+ }
1708
+ function platformConversationId(id) {
1709
+ return id;
1710
+ }
1711
+ function dataSourceId(id) {
1712
+ return id;
1713
+ }
1714
+ function operatorId(id) {
1715
+ return id;
1716
+ }
1717
+ function reviewItemId(id) {
1718
+ return id;
1719
+ }
1720
+ function monitorConceptId(id) {
1721
+ return id;
1722
+ }
1723
+ function unificationRuleId(id) {
1724
+ return id;
1725
+ }
1726
+ function entityId(id) {
1727
+ return id;
1728
+ }
1729
+ function taskId(id) {
1730
+ return id;
1731
+ }
1732
+
1733
+ // src/platform/index.ts
1734
+ var defaultBaseUrl = "https://api.platform.amigo.ai";
1735
+ var PlatformClient = class {
1736
+ constructor(config) {
1737
+ __publicField(this, "api");
1738
+ __publicField(this, "agents");
1739
+ __publicField(this, "apiKeys");
1740
+ __publicField(this, "contextGraphs");
1741
+ __publicField(this, "conversations");
1742
+ __publicField(this, "dataSources");
1743
+ __publicField(this, "events");
1744
+ __publicField(this, "fhir");
1745
+ __publicField(this, "integrations");
1746
+ __publicField(this, "phoneNumbers");
1747
+ __publicField(this, "services");
1748
+ __publicField(this, "sessions");
1749
+ __publicField(this, "skills");
1750
+ __publicField(this, "workspaces");
1751
+ __publicField(this, "config");
1752
+ this.config = validateConfig(config);
1753
+ this.api = createPlatformFetch(this.config);
1754
+ this.workspaces = new WorkspaceResource(this.api, this.config.workspaceId);
1755
+ this.agents = new PlatformAgentResource(this.api, this.config.workspaceId);
1756
+ this.apiKeys = new PlatformApiKeyResource(this.api, this.config.workspaceId);
1757
+ this.contextGraphs = new ContextGraphResource(this.api, this.config.workspaceId);
1758
+ this.conversations = new PlatformConversationResource(this.api, this.config.workspaceId);
1759
+ this.dataSources = new DataSourceResource(this.api, this.config.workspaceId);
1760
+ this.events = new PlatformEventResource(this.api, this.config.workspaceId);
1761
+ this.fhir = new FhirResource(this.api, this.config.workspaceId);
1762
+ this.integrations = new IntegrationResource(this.api, this.config.workspaceId);
1763
+ this.phoneNumbers = new PhoneNumberResource(this.api, this.config.workspaceId);
1764
+ this.services = new PlatformServiceResource(this.api, this.config.workspaceId);
1765
+ this.sessions = new PlatformSessionResource(this.api, this.config.workspaceId, {
1766
+ apiKey: this.config.apiKey,
1767
+ webSocketBaseUrl: this.config.webSocketBaseUrl,
1768
+ WebSocket: this.config.WebSocket
1769
+ });
1770
+ this.skills = new SkillResource(this.api, this.config.workspaceId);
1771
+ }
1772
+ };
1773
+ function validateConfig(config) {
1774
+ if (!config.apiKey) {
1775
+ throw new ConfigurationError("Platform API key is required", "apiKey");
1776
+ }
1777
+ if (!config.workspaceId) {
1778
+ throw new ConfigurationError("Workspace ID is required", "workspaceId");
1779
+ }
1780
+ const baseUrl = config.baseUrl ?? defaultBaseUrl;
1781
+ const webSocketBaseUrl = config.webSocketBaseUrl ?? webSocketBaseFromHttpBase(baseUrl);
1782
+ return {
1783
+ ...config,
1784
+ baseUrl,
1785
+ webSocketBaseUrl
1786
+ };
1787
+ }
1788
+ //# sourceMappingURL=platform.cjs.map