@amigo-ai/platform-sdk 0.4.0 → 0.4.2

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 (57) hide show
  1. package/README.md +147 -55
  2. package/api.md +354 -0
  3. package/dist/core/errors.js +26 -4
  4. package/dist/core/errors.js.map +1 -1
  5. package/dist/core/openapi-client.js +108 -6
  6. package/dist/core/openapi-client.js.map +1 -1
  7. package/dist/core/retry.js +5 -2
  8. package/dist/core/retry.js.map +1 -1
  9. package/dist/core/utils.js +48 -2
  10. package/dist/core/utils.js.map +1 -1
  11. package/dist/core/webhooks.js +8 -2
  12. package/dist/core/webhooks.js.map +1 -1
  13. package/dist/index.cjs +268 -40
  14. package/dist/index.cjs.map +4 -4
  15. package/dist/index.js +50 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/index.mjs +268 -40
  18. package/dist/index.mjs.map +4 -4
  19. package/dist/types/core/errors.d.ts +6 -0
  20. package/dist/types/core/errors.d.ts.map +1 -1
  21. package/dist/types/core/openapi-client.d.ts +24 -1
  22. package/dist/types/core/openapi-client.d.ts.map +1 -1
  23. package/dist/types/core/retry.d.ts +1 -1
  24. package/dist/types/core/retry.d.ts.map +1 -1
  25. package/dist/types/core/utils.d.ts +27 -1
  26. package/dist/types/core/utils.d.ts.map +1 -1
  27. package/dist/types/core/webhooks.d.ts.map +1 -1
  28. package/dist/types/index.d.ts +40 -2
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/resources/actions.d.ts +5 -5
  31. package/dist/types/resources/agents.d.ts +7 -7
  32. package/dist/types/resources/analytics.d.ts +11 -11
  33. package/dist/types/resources/api-keys.d.ts +4 -4
  34. package/dist/types/resources/audit.d.ts +6 -6
  35. package/dist/types/resources/billing.d.ts +6 -6
  36. package/dist/types/resources/calls.d.ts +6 -6
  37. package/dist/types/resources/compliance.d.ts +3 -3
  38. package/dist/types/resources/context-graphs.d.ts +7 -7
  39. package/dist/types/resources/data-sources.d.ts +6 -6
  40. package/dist/types/resources/functions.d.ts +6 -6
  41. package/dist/types/resources/integrations.d.ts +6 -6
  42. package/dist/types/resources/memory.d.ts +3 -3
  43. package/dist/types/resources/operators.d.ts +18 -18
  44. package/dist/types/resources/personas.d.ts +4 -4
  45. package/dist/types/resources/phone-numbers.d.ts +5 -5
  46. package/dist/types/resources/recordings.d.ts +2 -2
  47. package/dist/types/resources/review-queue.d.ts +17 -17
  48. package/dist/types/resources/safety.d.ts +5 -5
  49. package/dist/types/resources/services.d.ts +4 -4
  50. package/dist/types/resources/settings.d.ts +14 -14
  51. package/dist/types/resources/simulations.d.ts +6 -6
  52. package/dist/types/resources/skills.d.ts +5 -5
  53. package/dist/types/resources/triggers.d.ts +8 -8
  54. package/dist/types/resources/webhook-destinations.d.ts +6 -6
  55. package/dist/types/resources/workspaces.d.ts +5 -5
  56. package/dist/types/resources/world.d.ts +18 -18
  57. package/package.json +10 -4
package/dist/index.js CHANGED
@@ -45,8 +45,11 @@ import { WebhookDestinationsResource } from './resources/webhook-destinations.js
45
45
  import { SafetyResource } from './resources/safety.js';
46
46
  import { ComplianceResource } from './resources/compliance.js';
47
47
  import { FunctionsResource } from './resources/functions.js';
48
+ import { withResponse } from './core/utils.js';
48
49
  export const DEFAULT_BASE_URL = 'https://api.platform.amigo.ai';
49
50
  export class AmigoClient {
51
+ workspaceId;
52
+ baseUrl;
50
53
  workspaces;
51
54
  apiKeys;
52
55
  agents;
@@ -75,6 +78,7 @@ export class AmigoClient {
75
78
  safety;
76
79
  compliance;
77
80
  functions;
81
+ api;
78
82
  constructor(config) {
79
83
  if (!config.apiKey || typeof config.apiKey !== 'string') {
80
84
  throw new ConfigurationError('apiKey is required and must be a non-empty string');
@@ -87,9 +91,16 @@ export class AmigoClient {
87
91
  apiKey: config.apiKey,
88
92
  baseUrl,
89
93
  retry: config.retry,
94
+ maxRetries: config.maxRetries,
95
+ timeout: config.timeout,
96
+ headers: config.headers,
97
+ hooks: config.hooks,
90
98
  fetch: config.fetch,
91
99
  });
92
100
  const ws = config.workspaceId;
101
+ this.workspaceId = ws;
102
+ this.baseUrl = baseUrl;
103
+ this.api = client;
93
104
  this.workspaces = new WorkspacesResource(client, ws);
94
105
  this.apiKeys = new ApiKeysResource(client, ws);
95
106
  this.agents = new AgentsResource(client, ws);
@@ -118,10 +129,48 @@ export class AmigoClient {
118
129
  this.compliance = new ComplianceResource(client, ws);
119
130
  this.functions = new FunctionsResource(client, ws);
120
131
  }
132
+ async GET(path, init) {
133
+ return withResponse(await this.api.GET(path, withWorkspaceId(path, init, this.workspaceId)));
134
+ }
135
+ async POST(path, init) {
136
+ return withResponse(await this.api.POST(path, withWorkspaceId(path, init, this.workspaceId)));
137
+ }
138
+ async PUT(path, init) {
139
+ return withResponse(await this.api.PUT(path, withWorkspaceId(path, init, this.workspaceId)));
140
+ }
141
+ async PATCH(path, init) {
142
+ return withResponse(await this.api.PATCH(path, withWorkspaceId(path, init, this.workspaceId)));
143
+ }
144
+ async DELETE(path, init) {
145
+ return withResponse(await this.api.DELETE(path, withWorkspaceId(path, init, this.workspaceId)));
146
+ }
147
+ async HEAD(path, init) {
148
+ return withResponse(await this.api.HEAD(path, withWorkspaceId(path, init, this.workspaceId)));
149
+ }
150
+ async OPTIONS(path, init) {
151
+ return withResponse(await this.api.OPTIONS(path, withWorkspaceId(path, init, this.workspaceId)));
152
+ }
121
153
  }
122
- export { AmigoError, BadRequestError, AuthenticationError, PermissionError, NotFoundError, ConflictError, ValidationError, RateLimitError, ServerError, ServiceUnavailableError, NetworkError, ParseError, ConfigurationError, isAmigoError, isNotFoundError, isRateLimitError, isAuthenticationError, } from './core/errors.js';
154
+ export { AmigoError, BadRequestError, AuthenticationError, PermissionError, NotFoundError, ConflictError, ValidationError, RateLimitError, ServerError, ServiceUnavailableError, NetworkError, RequestTimeoutError, ParseError, ConfigurationError, isAmigoError, isNotFoundError, isRateLimitError, isAuthenticationError, isRequestTimeoutError, } from './core/errors.js';
123
155
  export { workspaceId, apiKeyId, agentId, personaId, skillId, actionId, serviceId, contextGraphId, callId, phoneNumberId, integrationId, entityId, eventId, simulationRunId, simulationSessionId, functionId, dataSourceId, } from './core/branded-types.js';
124
156
  export { paginate } from './core/utils.js';
157
+ export { buildLastResponse, extractRequestId } from './core/utils.js';
125
158
  export { parseRateLimitHeaders } from './core/rate-limit.js';
126
159
  export { verifyWebhookSignature, parseWebhookEvent, WebhookVerificationError, } from './core/webhooks.js';
160
+ function withWorkspaceId(path, init, workspaceId) {
161
+ if (!path.includes('{workspace_id}')) {
162
+ return (init ?? {});
163
+ }
164
+ const current = (init ?? {});
165
+ return {
166
+ ...current,
167
+ params: {
168
+ ...(current.params ?? {}),
169
+ path: {
170
+ workspace_id: workspaceId,
171
+ ...(current.params?.path ?? {}),
172
+ },
173
+ },
174
+ };
175
+ }
127
176
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,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AChB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,kBAAkB,CAAA;AAsBzB,OAAO,EACL,WAAW,EACX,QAAQ,EACR,OAAO,EACP,SAAS,EACT,OAAO,EACP,QAAQ,EACR,SAAS,EACT,cAAc,EACd,MAAM,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,YAAY,GACb,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAWrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAG5D,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,oBAAoB,CAAA;AAgB3B,SAAS,eAAe,CACtB,IAAU,EACV,IAAsB,EACtB,WAAmB;IAEnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAS,CAAA;IAC7B,CAAC;IAED,MAAM,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAI1B,CAAA;IAED,OAAO;QACL,GAAG,OAAO;QACV,MAAM,EAAE;YACN,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;YACzB,IAAI,EAAE;gBACJ,YAAY,EAAE,WAAW;gBACzB,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;aAChC;SACF;KACF,CAAA;AACH,CAAC"}
package/dist/index.mjs CHANGED
@@ -115,6 +115,13 @@ var NetworkError = class extends AmigoError {
115
115
  }
116
116
  }
117
117
  };
118
+ var RequestTimeoutError = class extends NetworkError {
119
+ timeoutMs;
120
+ constructor(message, timeoutMs, cause) {
121
+ super(message, cause);
122
+ this.timeoutMs = timeoutMs;
123
+ }
124
+ };
118
125
  var ParseError = class extends AmigoError {
119
126
  body;
120
127
  constructor(message, body) {
@@ -188,6 +195,9 @@ function isRateLimitError(err) {
188
195
  function isAuthenticationError(err) {
189
196
  return err instanceof AuthenticationError;
190
197
  }
198
+ function isRequestTimeoutError(err) {
199
+ return err instanceof RequestTimeoutError;
200
+ }
191
201
 
192
202
  // src/core/openapi-client.ts
193
203
  import createClientImport from "openapi-fetch";
@@ -210,6 +220,20 @@ function createAuthMiddleware(config) {
210
220
  };
211
221
  }
212
222
 
223
+ // src/core/rate-limit.ts
224
+ function parseRateLimitHeaders(headers) {
225
+ const limit = headers.get("x-ratelimit-limit");
226
+ const remaining = headers.get("x-ratelimit-remaining");
227
+ const reset = headers.get("x-ratelimit-reset");
228
+ const retryAfter = headers.get("retry-after");
229
+ return {
230
+ limit: limit ? parseInt(limit, 10) : null,
231
+ remaining: remaining ? parseInt(remaining, 10) : null,
232
+ reset: reset ? new Date(parseInt(reset, 10) * 1e3) : null,
233
+ retryAfter: retryAfter ? parseInt(retryAfter, 10) : null
234
+ };
235
+ }
236
+
213
237
  // src/core/retry.ts
214
238
  var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
215
239
  var POST_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([429]);
@@ -243,28 +267,106 @@ function parseRetryAfterHeader(header) {
243
267
  }
244
268
  return void 0;
245
269
  }
246
- function resolveRetryOptions(opts) {
270
+ function resolveRetryOptions(opts, maxRetries) {
271
+ const maxAttempts = typeof maxRetries === "number" && Number.isFinite(maxRetries) ? Math.max(1, Math.floor(maxRetries) + 1) : opts?.maxAttempts ?? 3;
247
272
  return {
248
- maxAttempts: opts?.maxAttempts ?? 3,
273
+ maxAttempts,
249
274
  baseDelayMs: opts?.baseDelayMs ?? 250,
250
275
  maxDelayMs: opts?.maxDelayMs ?? 3e4
251
276
  };
252
277
  }
253
278
 
279
+ // src/core/utils.ts
280
+ function extractRequestId(response) {
281
+ return response.headers.get("x-request-id");
282
+ }
283
+ function buildLastResponse(response) {
284
+ return {
285
+ requestId: extractRequestId(response),
286
+ statusCode: response.status,
287
+ headers: response.headers,
288
+ rateLimit: parseRateLimitHeaders(response.headers)
289
+ };
290
+ }
291
+ function extractData(result) {
292
+ if (result.data !== void 0) {
293
+ return attachResponseMetadata(result.data, result.response);
294
+ }
295
+ throw new ParseError(
296
+ "Unexpected empty response from API",
297
+ result.error !== void 0 ? JSON.stringify(result.error) : void 0
298
+ );
299
+ }
300
+ function withResponse(result) {
301
+ const data = extractData(result);
302
+ const lastResponse = buildLastResponse(result.response);
303
+ return {
304
+ data,
305
+ response: result.response,
306
+ requestId: lastResponse.requestId,
307
+ rateLimit: lastResponse.rateLimit
308
+ };
309
+ }
310
+ async function* paginate(fetcher) {
311
+ let token = void 0;
312
+ while (true) {
313
+ const page = await fetcher(token);
314
+ for (const item of page.items) {
315
+ yield item;
316
+ }
317
+ if (!page.has_more || page.continuation_token === null) break;
318
+ token = page.continuation_token;
319
+ }
320
+ }
321
+ function attachResponseMetadata(data, response) {
322
+ if (!response || typeof data !== "object" || data === null) {
323
+ return data;
324
+ }
325
+ const target = data;
326
+ const lastResponse = buildLastResponse(response);
327
+ defineHiddenMetadata(target, "_request_id", lastResponse.requestId);
328
+ defineHiddenMetadata(target, "lastResponse", lastResponse);
329
+ return target;
330
+ }
331
+ function defineHiddenMetadata(target, key, value) {
332
+ try {
333
+ Object.defineProperty(target, key, {
334
+ value,
335
+ enumerable: false,
336
+ configurable: true,
337
+ writable: false
338
+ });
339
+ } catch {
340
+ }
341
+ }
342
+
254
343
  // src/core/openapi-client.ts
255
344
  var createClient = typeof createClientImport === "function" ? createClientImport : createClientImport.default;
256
345
  function createPlatformClient(config) {
257
- const retryOpts = resolveRetryOptions(config.retry);
258
346
  const baseFetch = config.fetch ?? globalThis.fetch;
259
347
  const retryingFetch = async (input, init) => {
260
- const method = (init?.method ?? "GET").toUpperCase();
261
- const signal = init?.signal;
348
+ const baseRequest = input instanceof Request ? input : new Request(input, init);
349
+ 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;
262
357
  const isIdempotent = method === "GET" || method === "HEAD" || method === "OPTIONS";
263
358
  for (let attempt = 0; attempt < retryOpts.maxAttempts; attempt++) {
264
359
  let response;
265
360
  let error;
361
+ let timedOut = false;
266
362
  try {
267
- response = await baseFetch(input, init);
363
+ const prepared = prepareRequestForAttempt(baseRequest, timeoutMs);
364
+ try {
365
+ response = await baseFetch(prepared.request, init);
366
+ } finally {
367
+ timedOut = prepared.timedOut;
368
+ prepared.cleanup();
369
+ }
268
370
  } catch (err) {
269
371
  error = err;
270
372
  }
@@ -272,6 +374,9 @@ function createPlatformClient(config) {
272
374
  const ctx = { method, attempt, response, options: retryOpts };
273
375
  const attemptsRemain = attempt + 1 < retryOpts.maxAttempts;
274
376
  if (error) {
377
+ if (timedOut) {
378
+ throw new RequestTimeoutError(`Request timed out after ${timeoutMs}ms`, timeoutMs, error);
379
+ }
275
380
  if (isIdempotent && attemptsRemain) {
276
381
  await sleep(computeDelay(attempt, new Response(), retryOpts));
277
382
  continue;
@@ -283,7 +388,7 @@ function createPlatformClient(config) {
283
388
  }
284
389
  if (response && attemptsRemain && shouldRetry(ctx)) {
285
390
  const delay = computeDelay(attempt, response, retryOpts);
286
- if (signal?.aborted) return response;
391
+ if (baseRequest.signal.aborted) return response;
287
392
  await sleep(delay);
288
393
  continue;
289
394
  }
@@ -293,7 +398,8 @@ function createPlatformClient(config) {
293
398
  };
294
399
  const client = createClient({
295
400
  baseUrl: config.baseUrl,
296
- fetch: retryingFetch
401
+ fetch: retryingFetch,
402
+ headers: config.headers
297
403
  });
298
404
  const errorMiddleware = {
299
405
  async onResponse({ response }) {
@@ -304,32 +410,95 @@ function createPlatformClient(config) {
304
410
  }
305
411
  };
306
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;
307
433
  client.use(authMiddleware);
308
434
  client.use(errorMiddleware);
435
+ if (hookMiddleware) {
436
+ client.use(hookMiddleware);
437
+ }
309
438
  return client;
310
439
  }
311
440
  function sleep(ms) {
312
441
  return new Promise((resolve) => setTimeout(resolve, ms));
313
442
  }
314
-
315
- // src/core/utils.ts
316
- function extractData(result) {
317
- if (result.data !== void 0) return result.data;
318
- throw new ParseError(
319
- "Unexpected empty response from API",
320
- result.error !== void 0 ? JSON.stringify(result.error) : void 0
321
- );
443
+ function getRequestOption(request, key) {
444
+ const value = request[key];
445
+ return value;
322
446
  }
323
- async function* paginate(fetcher) {
324
- let token = void 0;
325
- while (true) {
326
- const page = await fetcher(token);
327
- for (const item of page.items) {
328
- yield item;
447
+ function prepareRequestForAttempt(request, timeoutMs) {
448
+ const attemptRequest = request.clone();
449
+ const timeout = createTimeoutSignal(attemptRequest.signal, timeoutMs);
450
+ if (!timeout.signal) {
451
+ return {
452
+ request: attemptRequest,
453
+ timedOut: false,
454
+ cleanup: timeout.cleanup
455
+ };
456
+ }
457
+ return {
458
+ request: new Request(attemptRequest, { signal: timeout.signal }),
459
+ get timedOut() {
460
+ return timeout.didTimeout;
461
+ },
462
+ cleanup: timeout.cleanup
463
+ };
464
+ }
465
+ function createTimeoutSignal(upstream, timeoutMs) {
466
+ if (!timeoutMs || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
467
+ return {
468
+ signal: upstream ?? void 0,
469
+ didTimeout: false,
470
+ cleanup: () => {
471
+ }
472
+ };
473
+ }
474
+ const controller = new AbortController();
475
+ let didTimeout = false;
476
+ const cleanups = [];
477
+ const onAbort = () => controller.abort(upstream?.reason);
478
+ if (upstream) {
479
+ if (upstream.aborted) {
480
+ controller.abort(upstream.reason);
481
+ } else {
482
+ upstream.addEventListener("abort", onAbort, { once: true });
483
+ cleanups.push(() => upstream.removeEventListener("abort", onAbort));
329
484
  }
330
- if (!page.has_more || page.continuation_token === null) break;
331
- token = page.continuation_token;
332
485
  }
486
+ const timer = setTimeout(() => {
487
+ didTimeout = true;
488
+ controller.abort();
489
+ }, timeoutMs);
490
+ cleanups.push(() => clearTimeout(timer));
491
+ return {
492
+ signal: controller.signal,
493
+ get didTimeout() {
494
+ return didTimeout;
495
+ },
496
+ cleanup: () => {
497
+ for (const cleanup of cleanups) {
498
+ cleanup();
499
+ }
500
+ }
501
+ };
333
502
  }
334
503
 
335
504
  // src/resources/base.ts
@@ -2108,20 +2277,6 @@ var simulationSessionId = (id) => id;
2108
2277
  var functionId = (id) => id;
2109
2278
  var dataSourceId = (id) => id;
2110
2279
 
2111
- // src/core/rate-limit.ts
2112
- function parseRateLimitHeaders(headers) {
2113
- const limit = headers.get("x-ratelimit-limit");
2114
- const remaining = headers.get("x-ratelimit-remaining");
2115
- const reset = headers.get("x-ratelimit-reset");
2116
- const retryAfter = headers.get("retry-after");
2117
- return {
2118
- limit: limit ? parseInt(limit, 10) : null,
2119
- remaining: remaining ? parseInt(remaining, 10) : null,
2120
- reset: reset ? new Date(parseInt(reset, 10) * 1e3) : null,
2121
- retryAfter: retryAfter ? parseInt(retryAfter, 10) : null
2122
- };
2123
- }
2124
-
2125
2280
  // src/core/webhooks.ts
2126
2281
  var textEncoder = new TextEncoder();
2127
2282
  var MAX_TIMESTAMP_SKEW_MS = 5 * 60 * 1e3;
@@ -2135,7 +2290,11 @@ var WebhookVerificationError = class extends Error {
2135
2290
  async function verifyWebhookSignature(payloadOrOptions, signature, secret) {
2136
2291
  const options = normalizeVerificationOptions(payloadOrOptions, signature, secret);
2137
2292
  const payloadBytes = toUint8Array(options.payload);
2138
- const expectedSignature = await signWebhookPayload(payloadBytes, options.secret, options.timestamp);
2293
+ const expectedSignature = await signWebhookPayload(
2294
+ payloadBytes,
2295
+ options.secret,
2296
+ options.timestamp
2297
+ );
2139
2298
  const actualSignature = normalizeSignature(options.signature);
2140
2299
  if (!actualSignature || !constantTimeEqual(expectedSignature, actualSignature)) {
2141
2300
  return false;
@@ -2216,7 +2375,7 @@ async function signWebhookPayload(payload, secret, timestamp) {
2216
2375
  ["sign"]
2217
2376
  );
2218
2377
  const message = timestamp ? concatUint8Arrays(textEncoder.encode(`v1:${timestamp}:`), payload) : payload;
2219
- const mac = await crypto.subtle.sign("HMAC", key, message);
2378
+ const mac = await crypto.subtle.sign("HMAC", key, toCryptoBuffer(message));
2220
2379
  return new Uint8Array(mac);
2221
2380
  }
2222
2381
  function normalizeSignature(signature) {
@@ -2252,10 +2411,16 @@ function concatUint8Arrays(left, right) {
2252
2411
  combined.set(right, left.length);
2253
2412
  return combined;
2254
2413
  }
2414
+ function toCryptoBuffer(bytes) {
2415
+ const copy = Uint8Array.from(bytes);
2416
+ return copy.buffer;
2417
+ }
2255
2418
 
2256
2419
  // src/index.ts
2257
2420
  var DEFAULT_BASE_URL = "https://api.platform.amigo.ai";
2258
2421
  var AmigoClient = class {
2422
+ workspaceId;
2423
+ baseUrl;
2259
2424
  workspaces;
2260
2425
  apiKeys;
2261
2426
  agents;
@@ -2284,6 +2449,7 @@ var AmigoClient = class {
2284
2449
  safety;
2285
2450
  compliance;
2286
2451
  functions;
2452
+ api;
2287
2453
  constructor(config) {
2288
2454
  if (!config.apiKey || typeof config.apiKey !== "string") {
2289
2455
  throw new ConfigurationError("apiKey is required and must be a non-empty string");
@@ -2296,9 +2462,16 @@ var AmigoClient = class {
2296
2462
  apiKey: config.apiKey,
2297
2463
  baseUrl,
2298
2464
  retry: config.retry,
2465
+ maxRetries: config.maxRetries,
2466
+ timeout: config.timeout,
2467
+ headers: config.headers,
2468
+ hooks: config.hooks,
2299
2469
  fetch: config.fetch
2300
2470
  });
2301
2471
  const ws = config.workspaceId;
2472
+ this.workspaceId = ws;
2473
+ this.baseUrl = baseUrl;
2474
+ this.api = client;
2302
2475
  this.workspaces = new WorkspacesResource(client, ws);
2303
2476
  this.apiKeys = new ApiKeysResource(client, ws);
2304
2477
  this.agents = new AgentsResource(client, ws);
@@ -2327,7 +2500,58 @@ var AmigoClient = class {
2327
2500
  this.compliance = new ComplianceResource(client, ws);
2328
2501
  this.functions = new FunctionsResource(client, ws);
2329
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
+ );
2537
+ }
2330
2538
  };
2539
+ function withWorkspaceId(path, init, workspaceId2) {
2540
+ if (!path.includes("{workspace_id}")) {
2541
+ return init ?? {};
2542
+ }
2543
+ const current = init ?? {};
2544
+ return {
2545
+ ...current,
2546
+ params: {
2547
+ ...current.params ?? {},
2548
+ path: {
2549
+ workspace_id: workspaceId2,
2550
+ ...current.params?.path ?? {}
2551
+ }
2552
+ }
2553
+ };
2554
+ }
2331
2555
  export {
2332
2556
  AmigoClient,
2333
2557
  AmigoError,
@@ -2341,6 +2565,7 @@ export {
2341
2565
  ParseError,
2342
2566
  PermissionError,
2343
2567
  RateLimitError,
2568
+ RequestTimeoutError,
2344
2569
  ServerError,
2345
2570
  ServiceUnavailableError,
2346
2571
  ValidationError,
@@ -2348,17 +2573,20 @@ export {
2348
2573
  actionId,
2349
2574
  agentId,
2350
2575
  apiKeyId,
2576
+ buildLastResponse,
2351
2577
  callId,
2352
2578
  contextGraphId,
2353
2579
  dataSourceId,
2354
2580
  entityId,
2355
2581
  eventId,
2582
+ extractRequestId,
2356
2583
  functionId,
2357
2584
  integrationId,
2358
2585
  isAmigoError,
2359
2586
  isAuthenticationError,
2360
2587
  isNotFoundError,
2361
2588
  isRateLimitError,
2589
+ isRequestTimeoutError,
2362
2590
  paginate,
2363
2591
  parseRateLimitHeaders,
2364
2592
  parseWebhookEvent,