@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.cjs CHANGED
@@ -314,9 +314,94 @@ function parseRateLimitHeaders(headers) {
314
314
  };
315
315
  }
316
316
 
317
+ // src/core/request-options.ts
318
+ function stripRequestControls(options) {
319
+ if (!options) {
320
+ return void 0;
321
+ }
322
+ const rest = { ...options };
323
+ delete rest.timeout;
324
+ delete rest.maxRetries;
325
+ delete rest.retry;
326
+ return rest;
327
+ }
328
+ function mergeRequestOptions(base, override) {
329
+ if (!base) {
330
+ return override;
331
+ }
332
+ if (!override) {
333
+ return base;
334
+ }
335
+ const mergeableOverride = override;
336
+ return {
337
+ ...base,
338
+ ...override,
339
+ headers: mergeHeaders(base.headers, mergeableOverride.headers),
340
+ signal: mergeableOverride.signal ?? base.signal,
341
+ timeout: mergeableOverride.timeout ?? base.timeout,
342
+ maxRetries: mergeableOverride.maxRetries ?? base.maxRetries,
343
+ retry: mergeableOverride.retry ?? base.retry
344
+ };
345
+ }
346
+ function mergeScopedRequestOptions(base, override) {
347
+ return mergeRequestOptions(base, override) ?? override;
348
+ }
349
+ function mergeHeaders(base, override) {
350
+ if (!base && !override) {
351
+ return void 0;
352
+ }
353
+ const headers = new Headers();
354
+ let hasEntries = false;
355
+ applyHeaders(headers, base, () => {
356
+ hasEntries = true;
357
+ });
358
+ applyHeaders(headers, override, () => {
359
+ hasEntries = true;
360
+ });
361
+ return hasEntries ? headers : void 0;
362
+ }
363
+ function applyHeaders(target, source, onSet) {
364
+ if (!source) {
365
+ return;
366
+ }
367
+ if (source instanceof Headers) {
368
+ source.forEach((value, key) => {
369
+ target.set(key, value);
370
+ onSet();
371
+ });
372
+ return;
373
+ }
374
+ if (Array.isArray(source)) {
375
+ for (const [key, value] of source) {
376
+ if (!key) {
377
+ continue;
378
+ }
379
+ if (value === null || value === void 0) {
380
+ target.delete(key);
381
+ continue;
382
+ }
383
+ target.set(key, String(value));
384
+ onSet();
385
+ }
386
+ return;
387
+ }
388
+ for (const [key, value] of Object.entries(source)) {
389
+ if (value === null || value === void 0) {
390
+ target.delete(key);
391
+ continue;
392
+ }
393
+ target.set(
394
+ key,
395
+ Array.isArray(value) ? value.map((item) => String(item)).join(", ") : String(value)
396
+ );
397
+ onSet();
398
+ }
399
+ }
400
+
317
401
  // src/core/retry.ts
318
402
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
319
403
  var POST_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429]);
404
+ var jitterCounter = 0;
320
405
  function shouldRetry(ctx) {
321
406
  const { method, attempt, response, options } = ctx;
322
407
  if (attempt >= options.maxAttempts) return false;
@@ -336,7 +421,7 @@ function computeDelay(attempt, response, options) {
336
421
  if (seconds !== void 0) return seconds * 1e3;
337
422
  }
338
423
  const exponential = Math.min(options.maxDelayMs, options.baseDelayMs * Math.pow(2, attempt));
339
- return Math.random() * exponential;
424
+ return jitterFraction() * exponential;
340
425
  }
341
426
  function parseRetryAfterHeader(header) {
342
427
  const seconds = Number(header);
@@ -355,6 +440,31 @@ function resolveRetryOptions(opts, maxRetries) {
355
440
  maxDelayMs: opts?.maxDelayMs ?? 3e4
356
441
  };
357
442
  }
443
+ function jitterFraction() {
444
+ const cryptoApi = getCryptoApi();
445
+ if (cryptoApi) {
446
+ const value = new Uint32Array(1);
447
+ cryptoApi.getRandomValues(value);
448
+ return (value[0] ?? 0) / 4294967296;
449
+ }
450
+ jitterCounter = jitterCounter + 1 >>> 0;
451
+ const mixed = mixUint32((Date.now() ^ Math.imul(jitterCounter, 2654435769)) >>> 0);
452
+ return mixed / 4294967296;
453
+ }
454
+ function getCryptoApi() {
455
+ const cryptoApi = globalThis.crypto;
456
+ if (cryptoApi && typeof cryptoApi.getRandomValues === "function") {
457
+ return cryptoApi;
458
+ }
459
+ return void 0;
460
+ }
461
+ function mixUint32(value) {
462
+ let mixed = (value ^ value >>> 16) >>> 0;
463
+ mixed = Math.imul(mixed, 2146121005) >>> 0;
464
+ mixed = (mixed ^ mixed >>> 15) >>> 0;
465
+ mixed = Math.imul(mixed, 2221713035) >>> 0;
466
+ return (mixed ^ mixed >>> 16) >>> 0;
467
+ }
358
468
 
359
469
  // src/core/utils.ts
360
470
  function extractRequestId(response) {
@@ -422,18 +532,89 @@ function defineHiddenMetadata(target, key, value) {
422
532
 
423
533
  // src/core/openapi-client.ts
424
534
  var createClient = typeof import_openapi_fetch.default === "function" ? import_openapi_fetch.default : import_openapi_fetch.default.default;
535
+ var platformClientContext = /* @__PURE__ */ new WeakMap();
425
536
  function createPlatformClient(config) {
426
- const baseFetch = config.fetch ?? globalThis.fetch;
427
- const retryingFetch = async (input, init) => {
537
+ const transport = toRequestTransport(config.fetch ?? globalThis.fetch);
538
+ const defaults = {
539
+ retry: config.retry,
540
+ maxRetries: config.maxRetries,
541
+ timeout: config.timeout
542
+ };
543
+ const client = createClient({
544
+ baseUrl: config.baseUrl,
545
+ fetch: createRetryingFetch(transport, defaults),
546
+ headers: config.headers
547
+ });
548
+ platformClientContext.set(client, { transport, defaults });
549
+ const errorMiddleware = {
550
+ async onResponse({ response }) {
551
+ if (!response.ok) {
552
+ throw await createApiError(response);
553
+ }
554
+ return response;
555
+ }
556
+ };
557
+ const authMiddleware = createAuthMiddleware({ apiKey: config.apiKey });
558
+ const hookMiddleware = config.hooks ? {
559
+ async onRequest({ request, schemaPath, id }) {
560
+ await config.hooks?.onRequest?.({ request, schemaPath, id });
561
+ return request;
562
+ },
563
+ async onResponse({ request, response, schemaPath, id }) {
564
+ await config.hooks?.onResponse?.({
565
+ id,
566
+ request,
567
+ response,
568
+ schemaPath,
569
+ requestId: extractRequestId(response),
570
+ rateLimit: parseRateLimitHeaders(response.headers)
571
+ });
572
+ return response;
573
+ },
574
+ async onError({ request, error, schemaPath, id }) {
575
+ await config.hooks?.onError?.({ id, request, error, schemaPath });
576
+ }
577
+ } : void 0;
578
+ client.use(authMiddleware);
579
+ client.use(errorMiddleware);
580
+ if (hookMiddleware) {
581
+ client.use(hookMiddleware);
582
+ }
583
+ return client;
584
+ }
585
+ function applyPlatformRequestOptions(client, init) {
586
+ if (!init) {
587
+ return void 0;
588
+ }
589
+ const context = platformClientContext.get(client);
590
+ const stripped = stripRequestControls(init);
591
+ if (!context) {
592
+ return stripped;
593
+ }
594
+ const overrideFetch = stripped?.fetch;
595
+ const hasControlOverride = overrideFetch !== void 0 || init.timeout !== void 0 || init.maxRetries !== void 0 || init.retry !== void 0;
596
+ if (!hasControlOverride) {
597
+ return stripped;
598
+ }
599
+ const transport = toRequestTransport(
600
+ overrideFetch ?? context.transport
601
+ );
602
+ const fetch = createRetryingFetch(transport, {
603
+ timeout: init.timeout ?? context.defaults.timeout,
604
+ maxRetries: init.maxRetries ?? context.defaults.maxRetries,
605
+ retry: init.retry ?? context.defaults.retry
606
+ });
607
+ return {
608
+ ...stripped,
609
+ fetch
610
+ };
611
+ }
612
+ function createRetryingFetch(transport, defaults) {
613
+ return async (input, init) => {
428
614
  const baseRequest = input instanceof Request ? input : new Request(input, init);
429
615
  const method = baseRequest.method.toUpperCase();
430
- const requestRetry = getRequestOption(baseRequest, "retry");
431
- const requestMaxRetries = getRequestOption(baseRequest, "maxRetries");
432
- const retryOpts = resolveRetryOptions(
433
- requestRetry ?? config.retry,
434
- requestMaxRetries ?? config.maxRetries
435
- );
436
- const timeoutMs = getRequestOption(baseRequest, "timeout") ?? config.timeout;
616
+ const retryOpts = resolveRetryOptions(defaults.retry, defaults.maxRetries);
617
+ const timeoutMs = defaults.timeout;
437
618
  const isIdempotent = method === "GET" || method === "HEAD" || method === "OPTIONS";
438
619
  for (let attempt = 0; attempt < retryOpts.maxAttempts; attempt++) {
439
620
  let response;
@@ -442,7 +623,7 @@ function createPlatformClient(config) {
442
623
  try {
443
624
  const prepared = prepareRequestForAttempt(baseRequest, timeoutMs);
444
625
  try {
445
- response = await baseFetch(prepared.request, init);
626
+ response = await transport(prepared.request);
446
627
  } finally {
447
628
  timedOut = prepared.timedOut;
448
629
  prepared.cleanup();
@@ -476,53 +657,12 @@ function createPlatformClient(config) {
476
657
  }
477
658
  throw new NetworkError("Retry loop exhausted");
478
659
  };
479
- const client = createClient({
480
- baseUrl: config.baseUrl,
481
- fetch: retryingFetch,
482
- headers: config.headers
483
- });
484
- const errorMiddleware = {
485
- async onResponse({ response }) {
486
- if (!response.ok) {
487
- throw await createApiError(response);
488
- }
489
- return response;
490
- }
491
- };
492
- const authMiddleware = createAuthMiddleware({ apiKey: config.apiKey });
493
- const hookMiddleware = config.hooks ? {
494
- async onRequest({ request, schemaPath, id }) {
495
- await config.hooks?.onRequest?.({ request, schemaPath, id });
496
- return request;
497
- },
498
- async onResponse({ request, response, schemaPath, id }) {
499
- await config.hooks?.onResponse?.({
500
- id,
501
- request,
502
- response,
503
- schemaPath,
504
- requestId: extractRequestId(response),
505
- rateLimit: parseRateLimitHeaders(response.headers)
506
- });
507
- return response;
508
- },
509
- async onError({ request, error, schemaPath, id }) {
510
- await config.hooks?.onError?.({ id, request, error, schemaPath });
511
- }
512
- } : void 0;
513
- client.use(authMiddleware);
514
- client.use(errorMiddleware);
515
- if (hookMiddleware) {
516
- client.use(hookMiddleware);
517
- }
518
- return client;
519
660
  }
520
661
  function sleep(ms) {
521
662
  return new Promise((resolve) => setTimeout(resolve, ms));
522
663
  }
523
- function getRequestOption(request, key) {
524
- const value = request[key];
525
- return value;
664
+ function toRequestTransport(fetcher) {
665
+ return async (input) => fetcher(input);
526
666
  }
527
667
  function prepareRequestForAttempt(request, timeoutMs) {
528
668
  const attemptRequest = request.clone();
@@ -582,12 +722,98 @@ function createTimeoutSignal(upstream, timeoutMs) {
582
722
  }
583
723
 
584
724
  // src/resources/base.ts
725
+ var scopedClientState = /* @__PURE__ */ new WeakMap();
585
726
  var WorkspaceScopedResource = class {
586
727
  constructor(client, workspaceId2) {
587
728
  this.client = client;
588
729
  this.workspaceId = workspaceId2;
589
730
  }
731
+ withOptions(options) {
732
+ const ResourceCtor = this.constructor;
733
+ return new ResourceCtor(scopePlatformClient(this.client, options), this.workspaceId);
734
+ }
590
735
  };
736
+ function scopePlatformClient(client, options) {
737
+ const { baseClient, options: existingOptions } = resolveScopedPlatformClient(client);
738
+ const mergedOptions = mergeScopedRequestOptions(existingOptions, options);
739
+ const scopedClient = {
740
+ request: (method, path, init) => baseClient.request(
741
+ method,
742
+ path,
743
+ applyPlatformRequestOptions(
744
+ baseClient,
745
+ mergeRequestOptions(mergedOptions, init)
746
+ )
747
+ ),
748
+ GET: (path, init) => baseClient.GET(
749
+ path,
750
+ applyPlatformRequestOptions(
751
+ baseClient,
752
+ mergeRequestOptions(mergedOptions, init)
753
+ )
754
+ ),
755
+ PUT: (path, init) => baseClient.PUT(
756
+ path,
757
+ applyPlatformRequestOptions(
758
+ baseClient,
759
+ mergeRequestOptions(mergedOptions, init)
760
+ )
761
+ ),
762
+ POST: (path, init) => baseClient.POST(
763
+ path,
764
+ applyPlatformRequestOptions(
765
+ baseClient,
766
+ mergeRequestOptions(mergedOptions, init)
767
+ )
768
+ ),
769
+ DELETE: (path, init) => baseClient.DELETE(
770
+ path,
771
+ applyPlatformRequestOptions(
772
+ baseClient,
773
+ mergeRequestOptions(mergedOptions, init)
774
+ )
775
+ ),
776
+ OPTIONS: (path, init) => baseClient.OPTIONS(
777
+ path,
778
+ applyPlatformRequestOptions(
779
+ baseClient,
780
+ mergeRequestOptions(mergedOptions, init)
781
+ )
782
+ ),
783
+ HEAD: (path, init) => baseClient.HEAD(
784
+ path,
785
+ applyPlatformRequestOptions(
786
+ baseClient,
787
+ mergeRequestOptions(mergedOptions, init)
788
+ )
789
+ ),
790
+ PATCH: (path, init) => baseClient.PATCH(
791
+ path,
792
+ applyPlatformRequestOptions(
793
+ baseClient,
794
+ mergeRequestOptions(mergedOptions, init)
795
+ )
796
+ ),
797
+ TRACE: (path, init) => baseClient.TRACE(
798
+ path,
799
+ applyPlatformRequestOptions(
800
+ baseClient,
801
+ mergeRequestOptions(mergedOptions, init)
802
+ )
803
+ ),
804
+ use: (...middleware) => baseClient.use(...middleware),
805
+ eject: (...middleware) => baseClient.eject(...middleware)
806
+ };
807
+ scopedClientState.set(scopedClient, { baseClient, options: mergedOptions });
808
+ return scopedClient;
809
+ }
810
+ function resolveScopedPlatformClient(client) {
811
+ const existing = scopedClientState.get(client);
812
+ return {
813
+ baseClient: existing?.baseClient ?? client,
814
+ options: existing?.options
815
+ };
816
+ }
591
817
 
592
818
  // src/resources/workspaces.ts
593
819
  var WorkspacesResource = class extends WorkspaceScopedResource {
@@ -2360,6 +2586,7 @@ var dataSourceId = (id) => id;
2360
2586
  // src/core/webhooks.ts
2361
2587
  var textEncoder = new TextEncoder();
2362
2588
  var MAX_TIMESTAMP_SKEW_MS = 5 * 60 * 1e3;
2589
+ var webCryptoPromise;
2363
2590
  var WebhookVerificationError = class extends Error {
2364
2591
  constructor(message) {
2365
2592
  super(message);
@@ -2447,6 +2674,7 @@ function toUint8Array(payload) {
2447
2674
  return new Uint8Array(payload);
2448
2675
  }
2449
2676
  async function signWebhookPayload(payload, secret, timestamp) {
2677
+ const crypto = await resolveWebCrypto();
2450
2678
  const key = await crypto.subtle.importKey(
2451
2679
  "raw",
2452
2680
  textEncoder.encode(secret),
@@ -2458,6 +2686,13 @@ async function signWebhookPayload(payload, secret, timestamp) {
2458
2686
  const mac = await crypto.subtle.sign("HMAC", key, toCryptoBuffer(message));
2459
2687
  return new Uint8Array(mac);
2460
2688
  }
2689
+ async function resolveWebCrypto() {
2690
+ if (globalThis.crypto?.subtle) {
2691
+ return globalThis.crypto;
2692
+ }
2693
+ webCryptoPromise ??= import("node:crypto").then(({ webcrypto }) => webcrypto);
2694
+ return await webCryptoPromise;
2695
+ }
2461
2696
  function normalizeSignature(signature) {
2462
2697
  const normalized = signature.startsWith("sha256=") ? signature.slice(7) : signature;
2463
2698
  if (!/^[a-fA-F0-9]+$/.test(normalized) || normalized.length % 2 !== 0) {
@@ -2498,7 +2733,7 @@ function toCryptoBuffer(bytes) {
2498
2733
 
2499
2734
  // src/index.ts
2500
2735
  var DEFAULT_BASE_URL = "https://api.platform.amigo.ai";
2501
- var AmigoClient = class {
2736
+ var AmigoClient = class _AmigoClient {
2502
2737
  workspaceId;
2503
2738
  baseUrl;
2504
2739
  workspaces;
@@ -2548,72 +2783,97 @@ var AmigoClient = class {
2548
2783
  hooks: config.hooks,
2549
2784
  fetch: config.fetch
2550
2785
  });
2551
- const ws = config.workspaceId;
2552
- this.workspaceId = ws;
2553
- this.baseUrl = baseUrl;
2554
- this.api = client;
2555
- this.workspaces = new WorkspacesResource(client, ws);
2556
- this.apiKeys = new ApiKeysResource(client, ws);
2557
- this.agents = new AgentsResource(client, ws);
2558
- this.skills = new SkillsResource(client, ws);
2559
- this.actions = new ActionsResource(client, ws);
2560
- this.operators = new OperatorsResource(client, ws);
2561
- this.triggers = new TriggersResource(client, ws);
2562
- this.services = new ServicesResource(client, ws);
2563
- this.contextGraphs = new ContextGraphsResource(client, ws);
2564
- this.dataSources = new DataSourcesResource(client, ws);
2565
- this.world = new WorldResource(client, ws);
2566
- this.calls = new CallsResource(client, ws);
2567
- this.phoneNumbers = new PhoneNumbersResource(client, ws);
2568
- this.integrations = new IntegrationsResource(client, ws);
2569
- this.analytics = new AnalyticsResource(client, ws);
2570
- this.simulations = new SimulationsResource(client, ws);
2571
- this.settings = new SettingsResource(client, ws);
2572
- this.billing = new BillingResource(client, ws);
2573
- this.memory = new MemoryResource(client, ws);
2574
- this.personas = new PersonasResource(client, ws);
2575
- this.reviewQueue = new ReviewQueueResource(client, ws);
2576
- this.recordings = new RecordingsResource(client, ws);
2577
- this.audit = new AuditResource(client, ws);
2578
- this.webhookDestinations = new WebhookDestinationsResource(client, ws);
2579
- this.safety = new SafetyResource(client, ws);
2580
- this.compliance = new ComplianceResource(client, ws);
2581
- this.functions = new FunctionsResource(client, ws);
2582
- }
2583
- async GET(path, init) {
2584
- return withResponse(
2585
- await this.api.GET(path, withWorkspaceId(path, init, this.workspaceId))
2586
- );
2587
- }
2588
- async POST(path, init) {
2589
- return withResponse(
2590
- await this.api.POST(path, withWorkspaceId(path, init, this.workspaceId))
2591
- );
2592
- }
2593
- async PUT(path, init) {
2594
- return withResponse(
2595
- await this.api.PUT(path, withWorkspaceId(path, init, this.workspaceId))
2596
- );
2597
- }
2598
- async PATCH(path, init) {
2599
- return withResponse(
2600
- await this.api.PATCH(path, withWorkspaceId(path, init, this.workspaceId))
2601
- );
2602
- }
2603
- async DELETE(path, init) {
2604
- return withResponse(
2605
- await this.api.DELETE(path, withWorkspaceId(path, init, this.workspaceId))
2606
- );
2607
- }
2608
- async HEAD(path, init) {
2609
- return withResponse(
2610
- await this.api.HEAD(path, withWorkspaceId(path, init, this.workspaceId))
2611
- );
2612
- }
2613
- async OPTIONS(path, init) {
2614
- return withResponse(
2615
- await this.api.OPTIONS(path, withWorkspaceId(path, init, this.workspaceId))
2616
- );
2786
+ _AmigoClient.hydrate(this, client, config.workspaceId, baseUrl);
2787
+ }
2788
+ withOptions(options) {
2789
+ return _AmigoClient.fromPlatformClient(
2790
+ scopePlatformClient(this.api, options),
2791
+ this.workspaceId,
2792
+ this.baseUrl
2793
+ );
2794
+ }
2795
+ async GET(path, ...[init]) {
2796
+ return withResponse(await this.resolveApiRequest(path, "GET", init));
2797
+ }
2798
+ async POST(path, ...[init]) {
2799
+ return withResponse(await this.resolveApiRequest(path, "POST", init));
2800
+ }
2801
+ async PUT(path, ...[init]) {
2802
+ return withResponse(await this.resolveApiRequest(path, "PUT", init));
2803
+ }
2804
+ async PATCH(path, ...[init]) {
2805
+ return withResponse(await this.resolveApiRequest(path, "PATCH", init));
2806
+ }
2807
+ async DELETE(path, ...[init]) {
2808
+ return withResponse(await this.resolveApiRequest(path, "DELETE", init));
2809
+ }
2810
+ async HEAD(path, ...[init]) {
2811
+ return withResponse(await this.resolveApiRequest(path, "HEAD", init));
2812
+ }
2813
+ async OPTIONS(path, ...[init]) {
2814
+ return withResponse(await this.resolveApiRequest(path, "OPTIONS", init));
2815
+ }
2816
+ static fromPlatformClient(client, workspaceId2, baseUrl) {
2817
+ const instance = Object.create(_AmigoClient.prototype);
2818
+ _AmigoClient.hydrate(instance, client, workspaceId2, baseUrl);
2819
+ return instance;
2820
+ }
2821
+ static hydrate(target, client, workspaceId2, baseUrl) {
2822
+ const mutable = target;
2823
+ mutable.workspaceId = workspaceId2;
2824
+ mutable.baseUrl = baseUrl;
2825
+ target.api = client;
2826
+ mutable.workspaces = new WorkspacesResource(client, workspaceId2);
2827
+ mutable.apiKeys = new ApiKeysResource(client, workspaceId2);
2828
+ mutable.agents = new AgentsResource(client, workspaceId2);
2829
+ mutable.skills = new SkillsResource(client, workspaceId2);
2830
+ mutable.actions = new ActionsResource(client, workspaceId2);
2831
+ mutable.operators = new OperatorsResource(client, workspaceId2);
2832
+ mutable.triggers = new TriggersResource(client, workspaceId2);
2833
+ mutable.services = new ServicesResource(client, workspaceId2);
2834
+ mutable.contextGraphs = new ContextGraphsResource(client, workspaceId2);
2835
+ mutable.dataSources = new DataSourcesResource(client, workspaceId2);
2836
+ mutable.world = new WorldResource(client, workspaceId2);
2837
+ mutable.calls = new CallsResource(client, workspaceId2);
2838
+ mutable.phoneNumbers = new PhoneNumbersResource(client, workspaceId2);
2839
+ mutable.integrations = new IntegrationsResource(client, workspaceId2);
2840
+ mutable.analytics = new AnalyticsResource(client, workspaceId2);
2841
+ mutable.simulations = new SimulationsResource(client, workspaceId2);
2842
+ mutable.settings = new SettingsResource(client, workspaceId2);
2843
+ mutable.billing = new BillingResource(client, workspaceId2);
2844
+ mutable.memory = new MemoryResource(client, workspaceId2);
2845
+ mutable.personas = new PersonasResource(client, workspaceId2);
2846
+ mutable.reviewQueue = new ReviewQueueResource(client, workspaceId2);
2847
+ mutable.recordings = new RecordingsResource(client, workspaceId2);
2848
+ mutable.audit = new AuditResource(client, workspaceId2);
2849
+ mutable.webhookDestinations = new WebhookDestinationsResource(client, workspaceId2);
2850
+ mutable.safety = new SafetyResource(client, workspaceId2);
2851
+ mutable.compliance = new ComplianceResource(client, workspaceId2);
2852
+ mutable.functions = new FunctionsResource(client, workspaceId2);
2853
+ }
2854
+ async resolveApiRequest(path, method, init) {
2855
+ const { baseClient, options } = resolveScopedPlatformClient(this.api);
2856
+ const mergedInit = mergeRequestOptions(options, withWorkspaceId(path, init, this.workspaceId));
2857
+ const requestInit = applyPlatformRequestOptions(
2858
+ baseClient,
2859
+ mergedInit
2860
+ );
2861
+ switch (method) {
2862
+ case "GET":
2863
+ return await baseClient.GET(path, requestInit);
2864
+ case "POST":
2865
+ return await baseClient.POST(path, requestInit);
2866
+ case "PUT":
2867
+ return await baseClient.PUT(path, requestInit);
2868
+ case "PATCH":
2869
+ return await baseClient.PATCH(path, requestInit);
2870
+ case "DELETE":
2871
+ return await baseClient.DELETE(path, requestInit);
2872
+ case "HEAD":
2873
+ return await baseClient.HEAD(path, requestInit);
2874
+ case "OPTIONS":
2875
+ return await baseClient.OPTIONS(path, requestInit);
2876
+ }
2617
2877
  }
2618
2878
  };
2619
2879
  function withWorkspaceId(path, init, workspaceId2) {
@@ -2626,8 +2886,8 @@ function withWorkspaceId(path, init, workspaceId2) {
2626
2886
  params: {
2627
2887
  ...current.params ?? {},
2628
2888
  path: {
2629
- workspace_id: workspaceId2,
2630
- ...current.params?.path ?? {}
2889
+ ...current.params?.path ?? {},
2890
+ workspace_id: workspaceId2
2631
2891
  }
2632
2892
  }
2633
2893
  };