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