@amigo-ai/sdk 1.0.0 → 1.1.0

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