@amigo-ai/platform-sdk 0.4.2 → 0.4.4

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 (66) hide show
  1. package/README.md +72 -15
  2. package/api.md +14 -21
  3. package/assets/readme/amigo-banner.png +0 -0
  4. package/assets/readme/platform-architecture.svg +117 -0
  5. package/dist/core/openapi-client.js +89 -55
  6. package/dist/core/openapi-client.js.map +1 -1
  7. package/dist/core/request-options.js +80 -0
  8. package/dist/core/request-options.js.map +1 -0
  9. package/dist/core/retry.js +29 -1
  10. package/dist/core/retry.js.map +1 -1
  11. package/dist/core/webhooks.js +9 -0
  12. package/dist/core/webhooks.js.map +1 -1
  13. package/dist/index.cjs +383 -123
  14. package/dist/index.cjs.map +3 -3
  15. package/dist/index.js +81 -47
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +383 -123
  18. package/dist/index.mjs.map +3 -3
  19. package/dist/resources/base.js +33 -0
  20. package/dist/resources/base.js.map +1 -1
  21. package/dist/types/core/openapi-client.d.ts +2 -0
  22. package/dist/types/core/openapi-client.d.ts.map +1 -1
  23. package/dist/types/core/request-options.d.ts +66 -0
  24. package/dist/types/core/request-options.d.ts.map +1 -0
  25. package/dist/types/core/retry.d.ts.map +1 -1
  26. package/dist/types/core/webhooks.d.ts.map +1 -1
  27. package/dist/types/generated/api.d.ts +1132 -244
  28. package/dist/types/generated/api.d.ts.map +1 -1
  29. package/dist/types/index.d.ts +14 -23
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/resources/actions.d.ts.map +1 -1
  32. package/dist/types/resources/agents.d.ts +4 -4
  33. package/dist/types/resources/agents.d.ts.map +1 -1
  34. package/dist/types/resources/analytics.d.ts +1 -3
  35. package/dist/types/resources/analytics.d.ts.map +1 -1
  36. package/dist/types/resources/api-keys.d.ts.map +1 -1
  37. package/dist/types/resources/audit.d.ts.map +1 -1
  38. package/dist/types/resources/base.d.ts +8 -3
  39. package/dist/types/resources/base.d.ts.map +1 -1
  40. package/dist/types/resources/billing.d.ts.map +1 -1
  41. package/dist/types/resources/calls.d.ts +1 -1
  42. package/dist/types/resources/calls.d.ts.map +1 -1
  43. package/dist/types/resources/context-graphs.d.ts.map +1 -1
  44. package/dist/types/resources/data-sources.d.ts.map +1 -1
  45. package/dist/types/resources/functions.d.ts.map +1 -1
  46. package/dist/types/resources/integrations.d.ts.map +1 -1
  47. package/dist/types/resources/memory.d.ts.map +1 -1
  48. package/dist/types/resources/operators.d.ts +18 -18
  49. package/dist/types/resources/operators.d.ts.map +1 -1
  50. package/dist/types/resources/personas.d.ts.map +1 -1
  51. package/dist/types/resources/phone-numbers.d.ts +8 -8
  52. package/dist/types/resources/phone-numbers.d.ts.map +1 -1
  53. package/dist/types/resources/review-queue.d.ts +6 -6
  54. package/dist/types/resources/review-queue.d.ts.map +1 -1
  55. package/dist/types/resources/safety.d.ts.map +1 -1
  56. package/dist/types/resources/services.d.ts.map +1 -1
  57. package/dist/types/resources/settings.d.ts.map +1 -1
  58. package/dist/types/resources/simulations.d.ts.map +1 -1
  59. package/dist/types/resources/skills.d.ts.map +1 -1
  60. package/dist/types/resources/triggers.d.ts +35 -35
  61. package/dist/types/resources/triggers.d.ts.map +1 -1
  62. package/dist/types/resources/webhook-destinations.d.ts +6 -6
  63. package/dist/types/resources/webhook-destinations.d.ts.map +1 -1
  64. package/dist/types/resources/workspaces.d.ts.map +1 -1
  65. package/dist/types/resources/world.d.ts.map +1 -1
  66. package/package.json +9 -3
package/dist/index.mjs CHANGED
@@ -234,9 +234,94 @@ function parseRateLimitHeaders(headers) {
234
234
  };
235
235
  }
236
236
 
237
+ // src/core/request-options.ts
238
+ function stripRequestControls(options) {
239
+ if (!options) {
240
+ return void 0;
241
+ }
242
+ const rest = { ...options };
243
+ delete rest.timeout;
244
+ delete rest.maxRetries;
245
+ delete rest.retry;
246
+ return rest;
247
+ }
248
+ function mergeRequestOptions(base, override) {
249
+ if (!base) {
250
+ return override;
251
+ }
252
+ if (!override) {
253
+ return base;
254
+ }
255
+ const mergeableOverride = override;
256
+ return {
257
+ ...base,
258
+ ...override,
259
+ headers: mergeHeaders(base.headers, mergeableOverride.headers),
260
+ signal: mergeableOverride.signal ?? base.signal,
261
+ timeout: mergeableOverride.timeout ?? base.timeout,
262
+ maxRetries: mergeableOverride.maxRetries ?? base.maxRetries,
263
+ retry: mergeableOverride.retry ?? base.retry
264
+ };
265
+ }
266
+ function mergeScopedRequestOptions(base, override) {
267
+ return mergeRequestOptions(base, override) ?? override;
268
+ }
269
+ function mergeHeaders(base, override) {
270
+ if (!base && !override) {
271
+ return void 0;
272
+ }
273
+ const headers = new Headers();
274
+ let hasEntries = false;
275
+ applyHeaders(headers, base, () => {
276
+ hasEntries = true;
277
+ });
278
+ applyHeaders(headers, override, () => {
279
+ hasEntries = true;
280
+ });
281
+ return hasEntries ? headers : void 0;
282
+ }
283
+ function applyHeaders(target, source, onSet) {
284
+ if (!source) {
285
+ return;
286
+ }
287
+ if (source instanceof Headers) {
288
+ source.forEach((value, key) => {
289
+ target.set(key, value);
290
+ onSet();
291
+ });
292
+ return;
293
+ }
294
+ if (Array.isArray(source)) {
295
+ for (const [key, value] of source) {
296
+ if (!key) {
297
+ continue;
298
+ }
299
+ if (value === null || value === void 0) {
300
+ target.delete(key);
301
+ continue;
302
+ }
303
+ target.set(key, String(value));
304
+ onSet();
305
+ }
306
+ return;
307
+ }
308
+ for (const [key, value] of Object.entries(source)) {
309
+ if (value === null || value === void 0) {
310
+ target.delete(key);
311
+ continue;
312
+ }
313
+ target.set(
314
+ key,
315
+ Array.isArray(value) ? value.map((item) => String(item)).join(", ") : String(value)
316
+ );
317
+ onSet();
318
+ }
319
+ }
320
+
237
321
  // src/core/retry.ts
238
322
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
239
323
  var POST_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429]);
324
+ var jitterCounter = 0;
240
325
  function shouldRetry(ctx) {
241
326
  const { method, attempt, response, options } = ctx;
242
327
  if (attempt >= options.maxAttempts) return false;
@@ -256,7 +341,7 @@ function computeDelay(attempt, response, options) {
256
341
  if (seconds !== void 0) return seconds * 1e3;
257
342
  }
258
343
  const exponential = Math.min(options.maxDelayMs, options.baseDelayMs * Math.pow(2, attempt));
259
- return Math.random() * exponential;
344
+ return jitterFraction() * exponential;
260
345
  }
261
346
  function parseRetryAfterHeader(header) {
262
347
  const seconds = Number(header);
@@ -275,6 +360,31 @@ function resolveRetryOptions(opts, maxRetries) {
275
360
  maxDelayMs: opts?.maxDelayMs ?? 3e4
276
361
  };
277
362
  }
363
+ function jitterFraction() {
364
+ const cryptoApi = getCryptoApi();
365
+ if (cryptoApi) {
366
+ const value = new Uint32Array(1);
367
+ cryptoApi.getRandomValues(value);
368
+ return (value[0] ?? 0) / 4294967296;
369
+ }
370
+ jitterCounter = jitterCounter + 1 >>> 0;
371
+ const mixed = mixUint32((Date.now() ^ Math.imul(jitterCounter, 2654435769)) >>> 0);
372
+ return mixed / 4294967296;
373
+ }
374
+ function getCryptoApi() {
375
+ const cryptoApi = globalThis.crypto;
376
+ if (cryptoApi && typeof cryptoApi.getRandomValues === "function") {
377
+ return cryptoApi;
378
+ }
379
+ return void 0;
380
+ }
381
+ function mixUint32(value) {
382
+ let mixed = (value ^ value >>> 16) >>> 0;
383
+ mixed = Math.imul(mixed, 2146121005) >>> 0;
384
+ mixed = (mixed ^ mixed >>> 15) >>> 0;
385
+ mixed = Math.imul(mixed, 2221713035) >>> 0;
386
+ return (mixed ^ mixed >>> 16) >>> 0;
387
+ }
278
388
 
279
389
  // src/core/utils.ts
280
390
  function extractRequestId(response) {
@@ -342,18 +452,89 @@ function defineHiddenMetadata(target, key, value) {
342
452
 
343
453
  // src/core/openapi-client.ts
344
454
  var createClient = typeof createClientImport === "function" ? createClientImport : createClientImport.default;
455
+ var platformClientContext = /* @__PURE__ */ new WeakMap();
345
456
  function createPlatformClient(config) {
346
- const baseFetch = config.fetch ?? globalThis.fetch;
347
- const retryingFetch = async (input, init) => {
457
+ const transport = toRequestTransport(config.fetch ?? globalThis.fetch);
458
+ const defaults = {
459
+ retry: config.retry,
460
+ maxRetries: config.maxRetries,
461
+ timeout: config.timeout
462
+ };
463
+ const client = createClient({
464
+ baseUrl: config.baseUrl,
465
+ fetch: createRetryingFetch(transport, defaults),
466
+ headers: config.headers
467
+ });
468
+ platformClientContext.set(client, { transport, defaults });
469
+ const errorMiddleware = {
470
+ async onResponse({ response }) {
471
+ if (!response.ok) {
472
+ throw await createApiError(response);
473
+ }
474
+ return response;
475
+ }
476
+ };
477
+ const authMiddleware = createAuthMiddleware({ apiKey: config.apiKey });
478
+ const hookMiddleware = config.hooks ? {
479
+ async onRequest({ request, schemaPath, id }) {
480
+ await config.hooks?.onRequest?.({ request, schemaPath, id });
481
+ return request;
482
+ },
483
+ async onResponse({ request, response, schemaPath, id }) {
484
+ await config.hooks?.onResponse?.({
485
+ id,
486
+ request,
487
+ response,
488
+ schemaPath,
489
+ requestId: extractRequestId(response),
490
+ rateLimit: parseRateLimitHeaders(response.headers)
491
+ });
492
+ return response;
493
+ },
494
+ async onError({ request, error, schemaPath, id }) {
495
+ await config.hooks?.onError?.({ id, request, error, schemaPath });
496
+ }
497
+ } : void 0;
498
+ client.use(authMiddleware);
499
+ client.use(errorMiddleware);
500
+ if (hookMiddleware) {
501
+ client.use(hookMiddleware);
502
+ }
503
+ return client;
504
+ }
505
+ function applyPlatformRequestOptions(client, init) {
506
+ if (!init) {
507
+ return void 0;
508
+ }
509
+ const context = platformClientContext.get(client);
510
+ const stripped = stripRequestControls(init);
511
+ if (!context) {
512
+ return stripped;
513
+ }
514
+ const overrideFetch = stripped?.fetch;
515
+ const hasControlOverride = overrideFetch !== void 0 || init.timeout !== void 0 || init.maxRetries !== void 0 || init.retry !== void 0;
516
+ if (!hasControlOverride) {
517
+ return stripped;
518
+ }
519
+ const transport = toRequestTransport(
520
+ overrideFetch ?? context.transport
521
+ );
522
+ const fetch = createRetryingFetch(transport, {
523
+ timeout: init.timeout ?? context.defaults.timeout,
524
+ maxRetries: init.maxRetries ?? context.defaults.maxRetries,
525
+ retry: init.retry ?? context.defaults.retry
526
+ });
527
+ return {
528
+ ...stripped,
529
+ fetch
530
+ };
531
+ }
532
+ function createRetryingFetch(transport, defaults) {
533
+ return async (input, init) => {
348
534
  const baseRequest = input instanceof Request ? input : new Request(input, init);
349
535
  const method = baseRequest.method.toUpperCase();
350
- const requestRetry = getRequestOption(baseRequest, "retry");
351
- const requestMaxRetries = getRequestOption(baseRequest, "maxRetries");
352
- const retryOpts = resolveRetryOptions(
353
- requestRetry ?? config.retry,
354
- requestMaxRetries ?? config.maxRetries
355
- );
356
- const timeoutMs = getRequestOption(baseRequest, "timeout") ?? config.timeout;
536
+ const retryOpts = resolveRetryOptions(defaults.retry, defaults.maxRetries);
537
+ const timeoutMs = defaults.timeout;
357
538
  const isIdempotent = method === "GET" || method === "HEAD" || method === "OPTIONS";
358
539
  for (let attempt = 0; attempt < retryOpts.maxAttempts; attempt++) {
359
540
  let response;
@@ -362,7 +543,7 @@ function createPlatformClient(config) {
362
543
  try {
363
544
  const prepared = prepareRequestForAttempt(baseRequest, timeoutMs);
364
545
  try {
365
- response = await baseFetch(prepared.request, init);
546
+ response = await transport(prepared.request);
366
547
  } finally {
367
548
  timedOut = prepared.timedOut;
368
549
  prepared.cleanup();
@@ -396,53 +577,12 @@ function createPlatformClient(config) {
396
577
  }
397
578
  throw new NetworkError("Retry loop exhausted");
398
579
  };
399
- const client = createClient({
400
- baseUrl: config.baseUrl,
401
- fetch: retryingFetch,
402
- headers: config.headers
403
- });
404
- const errorMiddleware = {
405
- async onResponse({ response }) {
406
- if (!response.ok) {
407
- throw await createApiError(response);
408
- }
409
- return response;
410
- }
411
- };
412
- const authMiddleware = createAuthMiddleware({ apiKey: config.apiKey });
413
- const hookMiddleware = config.hooks ? {
414
- async onRequest({ request, schemaPath, id }) {
415
- await config.hooks?.onRequest?.({ request, schemaPath, id });
416
- return request;
417
- },
418
- async onResponse({ request, response, schemaPath, id }) {
419
- await config.hooks?.onResponse?.({
420
- id,
421
- request,
422
- response,
423
- schemaPath,
424
- requestId: extractRequestId(response),
425
- rateLimit: parseRateLimitHeaders(response.headers)
426
- });
427
- return response;
428
- },
429
- async onError({ request, error, schemaPath, id }) {
430
- await config.hooks?.onError?.({ id, request, error, schemaPath });
431
- }
432
- } : void 0;
433
- client.use(authMiddleware);
434
- client.use(errorMiddleware);
435
- if (hookMiddleware) {
436
- client.use(hookMiddleware);
437
- }
438
- return client;
439
580
  }
440
581
  function sleep(ms) {
441
582
  return new Promise((resolve) => setTimeout(resolve, ms));
442
583
  }
443
- function getRequestOption(request, key) {
444
- const value = request[key];
445
- return value;
584
+ function toRequestTransport(fetcher) {
585
+ return async (input) => fetcher(input);
446
586
  }
447
587
  function prepareRequestForAttempt(request, timeoutMs) {
448
588
  const attemptRequest = request.clone();
@@ -502,12 +642,98 @@ function createTimeoutSignal(upstream, timeoutMs) {
502
642
  }
503
643
 
504
644
  // src/resources/base.ts
645
+ var scopedClientState = /* @__PURE__ */ new WeakMap();
505
646
  var WorkspaceScopedResource = class {
506
647
  constructor(client, workspaceId2) {
507
648
  this.client = client;
508
649
  this.workspaceId = workspaceId2;
509
650
  }
651
+ withOptions(options) {
652
+ const ResourceCtor = this.constructor;
653
+ return new ResourceCtor(scopePlatformClient(this.client, options), this.workspaceId);
654
+ }
510
655
  };
656
+ function scopePlatformClient(client, options) {
657
+ const { baseClient, options: existingOptions } = resolveScopedPlatformClient(client);
658
+ const mergedOptions = mergeScopedRequestOptions(existingOptions, options);
659
+ const scopedClient = {
660
+ request: (method, path, init) => baseClient.request(
661
+ method,
662
+ path,
663
+ applyPlatformRequestOptions(
664
+ baseClient,
665
+ mergeRequestOptions(mergedOptions, init)
666
+ )
667
+ ),
668
+ GET: (path, init) => baseClient.GET(
669
+ path,
670
+ applyPlatformRequestOptions(
671
+ baseClient,
672
+ mergeRequestOptions(mergedOptions, init)
673
+ )
674
+ ),
675
+ PUT: (path, init) => baseClient.PUT(
676
+ path,
677
+ applyPlatformRequestOptions(
678
+ baseClient,
679
+ mergeRequestOptions(mergedOptions, init)
680
+ )
681
+ ),
682
+ POST: (path, init) => baseClient.POST(
683
+ path,
684
+ applyPlatformRequestOptions(
685
+ baseClient,
686
+ mergeRequestOptions(mergedOptions, init)
687
+ )
688
+ ),
689
+ DELETE: (path, init) => baseClient.DELETE(
690
+ path,
691
+ applyPlatformRequestOptions(
692
+ baseClient,
693
+ mergeRequestOptions(mergedOptions, init)
694
+ )
695
+ ),
696
+ OPTIONS: (path, init) => baseClient.OPTIONS(
697
+ path,
698
+ applyPlatformRequestOptions(
699
+ baseClient,
700
+ mergeRequestOptions(mergedOptions, init)
701
+ )
702
+ ),
703
+ HEAD: (path, init) => baseClient.HEAD(
704
+ path,
705
+ applyPlatformRequestOptions(
706
+ baseClient,
707
+ mergeRequestOptions(mergedOptions, init)
708
+ )
709
+ ),
710
+ PATCH: (path, init) => baseClient.PATCH(
711
+ path,
712
+ applyPlatformRequestOptions(
713
+ baseClient,
714
+ mergeRequestOptions(mergedOptions, init)
715
+ )
716
+ ),
717
+ TRACE: (path, init) => baseClient.TRACE(
718
+ path,
719
+ applyPlatformRequestOptions(
720
+ baseClient,
721
+ mergeRequestOptions(mergedOptions, init)
722
+ )
723
+ ),
724
+ use: (...middleware) => baseClient.use(...middleware),
725
+ eject: (...middleware) => baseClient.eject(...middleware)
726
+ };
727
+ scopedClientState.set(scopedClient, { baseClient, options: mergedOptions });
728
+ return scopedClient;
729
+ }
730
+ function resolveScopedPlatformClient(client) {
731
+ const existing = scopedClientState.get(client);
732
+ return {
733
+ baseClient: existing?.baseClient ?? client,
734
+ options: existing?.options
735
+ };
736
+ }
511
737
 
512
738
  // src/resources/workspaces.ts
513
739
  var WorkspacesResource = class extends WorkspaceScopedResource {
@@ -2280,6 +2506,7 @@ var dataSourceId = (id) => id;
2280
2506
  // src/core/webhooks.ts
2281
2507
  var textEncoder = new TextEncoder();
2282
2508
  var MAX_TIMESTAMP_SKEW_MS = 5 * 60 * 1e3;
2509
+ var webCryptoPromise;
2283
2510
  var WebhookVerificationError = class extends Error {
2284
2511
  constructor(message) {
2285
2512
  super(message);
@@ -2367,6 +2594,7 @@ function toUint8Array(payload) {
2367
2594
  return new Uint8Array(payload);
2368
2595
  }
2369
2596
  async function signWebhookPayload(payload, secret, timestamp) {
2597
+ const crypto = await resolveWebCrypto();
2370
2598
  const key = await crypto.subtle.importKey(
2371
2599
  "raw",
2372
2600
  textEncoder.encode(secret),
@@ -2378,6 +2606,13 @@ async function signWebhookPayload(payload, secret, timestamp) {
2378
2606
  const mac = await crypto.subtle.sign("HMAC", key, toCryptoBuffer(message));
2379
2607
  return new Uint8Array(mac);
2380
2608
  }
2609
+ async function resolveWebCrypto() {
2610
+ if (globalThis.crypto?.subtle) {
2611
+ return globalThis.crypto;
2612
+ }
2613
+ webCryptoPromise ??= import("node:crypto").then(({ webcrypto }) => webcrypto);
2614
+ return await webCryptoPromise;
2615
+ }
2381
2616
  function normalizeSignature(signature) {
2382
2617
  const normalized = signature.startsWith("sha256=") ? signature.slice(7) : signature;
2383
2618
  if (!/^[a-fA-F0-9]+$/.test(normalized) || normalized.length % 2 !== 0) {
@@ -2418,7 +2653,7 @@ function toCryptoBuffer(bytes) {
2418
2653
 
2419
2654
  // src/index.ts
2420
2655
  var DEFAULT_BASE_URL = "https://api.platform.amigo.ai";
2421
- var AmigoClient = class {
2656
+ var AmigoClient = class _AmigoClient {
2422
2657
  workspaceId;
2423
2658
  baseUrl;
2424
2659
  workspaces;
@@ -2468,72 +2703,97 @@ var AmigoClient = class {
2468
2703
  hooks: config.hooks,
2469
2704
  fetch: config.fetch
2470
2705
  });
2471
- const ws = config.workspaceId;
2472
- this.workspaceId = ws;
2473
- this.baseUrl = baseUrl;
2474
- this.api = client;
2475
- this.workspaces = new WorkspacesResource(client, ws);
2476
- this.apiKeys = new ApiKeysResource(client, ws);
2477
- this.agents = new AgentsResource(client, ws);
2478
- this.skills = new SkillsResource(client, ws);
2479
- this.actions = new ActionsResource(client, ws);
2480
- this.operators = new OperatorsResource(client, ws);
2481
- this.triggers = new TriggersResource(client, ws);
2482
- this.services = new ServicesResource(client, ws);
2483
- this.contextGraphs = new ContextGraphsResource(client, ws);
2484
- this.dataSources = new DataSourcesResource(client, ws);
2485
- this.world = new WorldResource(client, ws);
2486
- this.calls = new CallsResource(client, ws);
2487
- this.phoneNumbers = new PhoneNumbersResource(client, ws);
2488
- this.integrations = new IntegrationsResource(client, ws);
2489
- this.analytics = new AnalyticsResource(client, ws);
2490
- this.simulations = new SimulationsResource(client, ws);
2491
- this.settings = new SettingsResource(client, ws);
2492
- this.billing = new BillingResource(client, ws);
2493
- this.memory = new MemoryResource(client, ws);
2494
- this.personas = new PersonasResource(client, ws);
2495
- this.reviewQueue = new ReviewQueueResource(client, ws);
2496
- this.recordings = new RecordingsResource(client, ws);
2497
- this.audit = new AuditResource(client, ws);
2498
- this.webhookDestinations = new WebhookDestinationsResource(client, ws);
2499
- this.safety = new SafetyResource(client, ws);
2500
- this.compliance = new ComplianceResource(client, ws);
2501
- this.functions = new FunctionsResource(client, ws);
2502
- }
2503
- async GET(path, init) {
2504
- return withResponse(
2505
- await this.api.GET(path, withWorkspaceId(path, init, this.workspaceId))
2506
- );
2507
- }
2508
- async POST(path, init) {
2509
- return withResponse(
2510
- await this.api.POST(path, withWorkspaceId(path, init, this.workspaceId))
2511
- );
2512
- }
2513
- async PUT(path, init) {
2514
- return withResponse(
2515
- await this.api.PUT(path, withWorkspaceId(path, init, this.workspaceId))
2516
- );
2517
- }
2518
- async PATCH(path, init) {
2519
- return withResponse(
2520
- await this.api.PATCH(path, withWorkspaceId(path, init, this.workspaceId))
2521
- );
2522
- }
2523
- async DELETE(path, init) {
2524
- return withResponse(
2525
- await this.api.DELETE(path, withWorkspaceId(path, init, this.workspaceId))
2526
- );
2527
- }
2528
- async HEAD(path, init) {
2529
- return withResponse(
2530
- await this.api.HEAD(path, withWorkspaceId(path, init, this.workspaceId))
2531
- );
2532
- }
2533
- async OPTIONS(path, init) {
2534
- return withResponse(
2535
- await this.api.OPTIONS(path, withWorkspaceId(path, init, this.workspaceId))
2536
- );
2706
+ _AmigoClient.hydrate(this, client, config.workspaceId, baseUrl);
2707
+ }
2708
+ withOptions(options) {
2709
+ return _AmigoClient.fromPlatformClient(
2710
+ scopePlatformClient(this.api, options),
2711
+ this.workspaceId,
2712
+ this.baseUrl
2713
+ );
2714
+ }
2715
+ async GET(path, ...[init]) {
2716
+ return withResponse(await this.resolveApiRequest(path, "GET", init));
2717
+ }
2718
+ async POST(path, ...[init]) {
2719
+ return withResponse(await this.resolveApiRequest(path, "POST", init));
2720
+ }
2721
+ async PUT(path, ...[init]) {
2722
+ return withResponse(await this.resolveApiRequest(path, "PUT", init));
2723
+ }
2724
+ async PATCH(path, ...[init]) {
2725
+ return withResponse(await this.resolveApiRequest(path, "PATCH", init));
2726
+ }
2727
+ async DELETE(path, ...[init]) {
2728
+ return withResponse(await this.resolveApiRequest(path, "DELETE", init));
2729
+ }
2730
+ async HEAD(path, ...[init]) {
2731
+ return withResponse(await this.resolveApiRequest(path, "HEAD", init));
2732
+ }
2733
+ async OPTIONS(path, ...[init]) {
2734
+ return withResponse(await this.resolveApiRequest(path, "OPTIONS", init));
2735
+ }
2736
+ static fromPlatformClient(client, workspaceId2, baseUrl) {
2737
+ const instance = Object.create(_AmigoClient.prototype);
2738
+ _AmigoClient.hydrate(instance, client, workspaceId2, baseUrl);
2739
+ return instance;
2740
+ }
2741
+ static hydrate(target, client, workspaceId2, baseUrl) {
2742
+ const mutable = target;
2743
+ mutable.workspaceId = workspaceId2;
2744
+ mutable.baseUrl = baseUrl;
2745
+ target.api = client;
2746
+ mutable.workspaces = new WorkspacesResource(client, workspaceId2);
2747
+ mutable.apiKeys = new ApiKeysResource(client, workspaceId2);
2748
+ mutable.agents = new AgentsResource(client, workspaceId2);
2749
+ mutable.skills = new SkillsResource(client, workspaceId2);
2750
+ mutable.actions = new ActionsResource(client, workspaceId2);
2751
+ mutable.operators = new OperatorsResource(client, workspaceId2);
2752
+ mutable.triggers = new TriggersResource(client, workspaceId2);
2753
+ mutable.services = new ServicesResource(client, workspaceId2);
2754
+ mutable.contextGraphs = new ContextGraphsResource(client, workspaceId2);
2755
+ mutable.dataSources = new DataSourcesResource(client, workspaceId2);
2756
+ mutable.world = new WorldResource(client, workspaceId2);
2757
+ mutable.calls = new CallsResource(client, workspaceId2);
2758
+ mutable.phoneNumbers = new PhoneNumbersResource(client, workspaceId2);
2759
+ mutable.integrations = new IntegrationsResource(client, workspaceId2);
2760
+ mutable.analytics = new AnalyticsResource(client, workspaceId2);
2761
+ mutable.simulations = new SimulationsResource(client, workspaceId2);
2762
+ mutable.settings = new SettingsResource(client, workspaceId2);
2763
+ mutable.billing = new BillingResource(client, workspaceId2);
2764
+ mutable.memory = new MemoryResource(client, workspaceId2);
2765
+ mutable.personas = new PersonasResource(client, workspaceId2);
2766
+ mutable.reviewQueue = new ReviewQueueResource(client, workspaceId2);
2767
+ mutable.recordings = new RecordingsResource(client, workspaceId2);
2768
+ mutable.audit = new AuditResource(client, workspaceId2);
2769
+ mutable.webhookDestinations = new WebhookDestinationsResource(client, workspaceId2);
2770
+ mutable.safety = new SafetyResource(client, workspaceId2);
2771
+ mutable.compliance = new ComplianceResource(client, workspaceId2);
2772
+ mutable.functions = new FunctionsResource(client, workspaceId2);
2773
+ }
2774
+ async resolveApiRequest(path, method, init) {
2775
+ const { baseClient, options } = resolveScopedPlatformClient(this.api);
2776
+ const mergedInit = mergeRequestOptions(options, withWorkspaceId(path, init, this.workspaceId));
2777
+ const requestInit = applyPlatformRequestOptions(
2778
+ baseClient,
2779
+ mergedInit
2780
+ );
2781
+ switch (method) {
2782
+ case "GET":
2783
+ return await baseClient.GET(path, requestInit);
2784
+ case "POST":
2785
+ return await baseClient.POST(path, requestInit);
2786
+ case "PUT":
2787
+ return await baseClient.PUT(path, requestInit);
2788
+ case "PATCH":
2789
+ return await baseClient.PATCH(path, requestInit);
2790
+ case "DELETE":
2791
+ return await baseClient.DELETE(path, requestInit);
2792
+ case "HEAD":
2793
+ return await baseClient.HEAD(path, requestInit);
2794
+ case "OPTIONS":
2795
+ return await baseClient.OPTIONS(path, requestInit);
2796
+ }
2537
2797
  }
2538
2798
  };
2539
2799
  function withWorkspaceId(path, init, workspaceId2) {
@@ -2546,8 +2806,8 @@ function withWorkspaceId(path, init, workspaceId2) {
2546
2806
  params: {
2547
2807
  ...current.params ?? {},
2548
2808
  path: {
2549
- workspace_id: workspaceId2,
2550
- ...current.params?.path ?? {}
2809
+ ...current.params?.path ?? {},
2810
+ workspace_id: workspaceId2
2551
2811
  }
2552
2812
  }
2553
2813
  };