@amigo-ai/platform-sdk 0.22.0 → 0.24.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.
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ import { AuditResource } from './resources/audit.js';
47
47
  import { WebhookDestinationsResource } from './resources/webhook-destinations.js';
48
48
  import { SafetyResource } from './resources/safety.js';
49
49
  import { ComplianceResource } from './resources/compliance.js';
50
+ import { EventsResource } from './resources/events.js';
50
51
  import { FunctionsResource } from './resources/functions.js';
51
52
  import { resolveScopedPlatformClient, scopePlatformClient } from './resources/base.js';
52
53
  import { withResponse } from './core/utils.js';
@@ -84,6 +85,7 @@ export class AmigoClient {
84
85
  webhookDestinations;
85
86
  safety;
86
87
  compliance;
88
+ events;
87
89
  functions;
88
90
  /** @internal — exposed for path-level type inference in GET/POST/PUT/etc. */
89
91
  api;
@@ -174,6 +176,7 @@ export class AmigoClient {
174
176
  mutable.webhookDestinations = new WebhookDestinationsResource(client, workspaceId);
175
177
  mutable.safety = new SafetyResource(client, workspaceId);
176
178
  mutable.compliance = new ComplianceResource(client, workspaceId);
179
+ mutable.events = new EventsResource(client, workspaceId);
177
180
  mutable.functions = new FunctionsResource(client, workspaceId);
178
181
  }
179
182
  async resolveApiRequest(path, method, init) {
@@ -204,7 +207,7 @@ export { paginate } from './core/utils.js';
204
207
  export { buildLastResponse, extractRequestId } from './core/utils.js';
205
208
  export { parseRateLimitHeaders } from './core/rate-limit.js';
206
209
  export { verifyWebhookSignature, parseWebhookEvent, WebhookVerificationError, } from './core/webhooks.js';
207
- export { sessionConnectAuthProtocols, textStreamAuthProtocols, } from './resources/conversations.js';
210
+ export { sessionConnectAuthProtocols, textStreamAuthProtocols } from './resources/conversations.js';
208
211
  // Device code auth (desktop / CLI login)
209
212
  export { loginWithDeviceCode, TokenManager, FileTokenStorage, MemoryTokenStorage, DeviceCodeExpiredError, DeviceCodeDeniedError, RefreshTokenExpiredError, LoginCancelledError, formatDeviceCodeInstructions, formatDeviceCodeLink, formatWorkspaceList, openBrowser, } from './core/device-code.js';
210
213
  function withWorkspaceId(path, init, workspaceId) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,GAGrB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,mBAAmB,GAKpB,MAAM,2BAA2B,CAAA;AAElC,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,CAAA;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAA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AAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,wBAAwB,EACxB,mBAAmB,EACnB,4BAA4B,EAC5B,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAiB9B,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,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;gBAC/B,YAAY,EAAE,WAAW;aAC1B;SACF;KACF,CAAA;AACH,CAAC"}
package/dist/index.mjs CHANGED
@@ -788,14 +788,6 @@ function resolveScopedPlatformClient(client) {
788
788
 
789
789
  // src/resources/workspaces.ts
790
790
  var WorkspacesResource = class extends WorkspaceScopedResource {
791
- /** Create a new workspace (unauthenticated — no owner membership created) */
792
- async create(body) {
793
- return extractData(
794
- await this.client.POST("/v1/workspaces", {
795
- body
796
- })
797
- );
798
- }
799
791
  /** Create a workspace for the authenticated user and attach owner access */
800
792
  async createSelfService(body) {
801
793
  return extractData(
@@ -1930,7 +1922,10 @@ var ConversationsResource = class extends WorkspaceScopedResource {
1930
1922
  "/v1/{workspace_id}/conversations/{conversation_id}/turns",
1931
1923
  {
1932
1924
  params: {
1933
- path: { workspace_id: this.workspaceId, conversation_id: conversationId }
1925
+ path: { workspace_id: this.workspaceId, conversation_id: conversationId },
1926
+ ...options?.includeToolCalls !== void 0 && {
1927
+ query: { include_tool_calls: options.includeToolCalls }
1928
+ }
1934
1929
  },
1935
1930
  body: request,
1936
1931
  headers: { Accept: "text/event-stream" },
@@ -1943,6 +1938,35 @@ var ConversationsResource = class extends WorkspaceScopedResource {
1943
1938
  }
1944
1939
  return result.data;
1945
1940
  }
1941
+ /**
1942
+ * Send a message and receive the agent's response as a typed
1943
+ * `TurnStreamEvent` async iterable.
1944
+ *
1945
+ * The bytes-and-parser dance from `createTurnStream` is now hidden inside
1946
+ * the SDK — consumers iterate strongly typed events directly. Each yielded
1947
+ * value is a member of the `TurnStreamEvent` discriminated union (`token`,
1948
+ * `thinking`, `tool_call_started`, `tool_call_completed`, `message`,
1949
+ * `done`, `error`), validated as a record with a known `event`
1950
+ * discriminator. Unknown / malformed frames are dropped silently — this
1951
+ * matches the wire-format-drift behavior of the lower-level
1952
+ * `createTurnStream` while keeping the strict `TurnStreamEvent` static
1953
+ * contract intact for consumers.
1954
+ *
1955
+ * @example
1956
+ * ```ts
1957
+ * for await (const event of client.conversations.streamTurn(convId, { message: "Hello" })) {
1958
+ * if (event.event === "token") process.stdout.write(event.text);
1959
+ * else if (event.event === "done") break;
1960
+ * }
1961
+ * ```
1962
+ */
1963
+ async *streamTurn(conversationId, request, options) {
1964
+ const byteStream = await this.createTurnStream(conversationId, request, options);
1965
+ for await (const frame of parseSSEFrames(byteStream)) {
1966
+ const event = parseTurnStreamFrame(frame.event, frame.data);
1967
+ if (event) yield event;
1968
+ }
1969
+ }
1946
1970
  /** Build the real-time text WebSocket URL for browser or custom clients. */
1947
1971
  textStreamUrl(params) {
1948
1972
  const url = buildTextStreamUrl({
@@ -2134,6 +2158,80 @@ function describeInvalidSubprotocolChars(token) {
2134
2158
  }
2135
2159
  return [...chars].map((char) => JSON.stringify(char)).join(", ");
2136
2160
  }
2161
+ async function* parseSSEFrames(stream) {
2162
+ const reader = stream.getReader();
2163
+ const decoder = new TextDecoder();
2164
+ let buffer = "";
2165
+ function* drain(text) {
2166
+ buffer += text;
2167
+ while (true) {
2168
+ const idx = findFrameTerminator(buffer);
2169
+ if (idx === null) break;
2170
+ const block = buffer.slice(0, idx.terminatorStart);
2171
+ buffer = buffer.slice(idx.terminatorEnd);
2172
+ const frame = parseSSEBlock(block);
2173
+ if (frame) yield frame;
2174
+ }
2175
+ }
2176
+ try {
2177
+ while (true) {
2178
+ const { done, value } = await reader.read();
2179
+ if (done) break;
2180
+ yield* drain(decoder.decode(value, { stream: true }));
2181
+ }
2182
+ yield* drain(decoder.decode());
2183
+ if (buffer.trim().length > 0) {
2184
+ const frame = parseSSEBlock(buffer);
2185
+ if (frame) yield frame;
2186
+ buffer = "";
2187
+ }
2188
+ } finally {
2189
+ reader.releaseLock();
2190
+ }
2191
+ }
2192
+ function findFrameTerminator(s) {
2193
+ const lf = s.indexOf("\n\n");
2194
+ const crlf = s.indexOf("\r\n\r\n");
2195
+ if (lf < 0 && crlf < 0) return null;
2196
+ if (lf < 0) return { terminatorStart: crlf, terminatorEnd: crlf + 4 };
2197
+ if (crlf < 0) return { terminatorStart: lf, terminatorEnd: lf + 2 };
2198
+ return lf < crlf ? { terminatorStart: lf, terminatorEnd: lf + 2 } : { terminatorStart: crlf, terminatorEnd: crlf + 4 };
2199
+ }
2200
+ function parseSSEBlock(block) {
2201
+ let event = "";
2202
+ const dataLines = [];
2203
+ for (const line of block.split(/\r?\n/)) {
2204
+ if (line === "" || line.startsWith(":")) continue;
2205
+ const colon = line.indexOf(":");
2206
+ const field = colon < 0 ? line : line.slice(0, colon);
2207
+ let value = colon < 0 ? "" : line.slice(colon + 1);
2208
+ if (value.startsWith(" ")) value = value.slice(1);
2209
+ if (field === "event") event = value;
2210
+ else if (field === "data") dataLines.push(value);
2211
+ }
2212
+ if (!event || dataLines.length === 0) return null;
2213
+ return { event, data: dataLines.join("\n") };
2214
+ }
2215
+ var KNOWN_TURN_STREAM_EVENTS = /* @__PURE__ */ new Set([
2216
+ "token",
2217
+ "thinking",
2218
+ "tool_call_started",
2219
+ "tool_call_completed",
2220
+ "message",
2221
+ "done",
2222
+ "error"
2223
+ ]);
2224
+ function parseTurnStreamFrame(eventName, dataJson) {
2225
+ if (!KNOWN_TURN_STREAM_EVENTS.has(eventName)) return null;
2226
+ let payload;
2227
+ try {
2228
+ payload = JSON.parse(dataJson);
2229
+ } catch {
2230
+ return null;
2231
+ }
2232
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return null;
2233
+ return { ...payload, event: eventName };
2234
+ }
2137
2235
 
2138
2236
  // src/resources/phone-numbers.ts
2139
2237
  var PhoneNumbersResource = class extends WorkspaceScopedResource {
@@ -3152,6 +3250,318 @@ var ComplianceResource = class extends WorkspaceScopedResource {
3152
3250
  }
3153
3251
  };
3154
3252
 
3253
+ // src/resources/events.ts
3254
+ var DEFAULT_INITIAL_DELAY_MS = 3e3;
3255
+ var DEFAULT_MAX_DELAY_MS = 3e4;
3256
+ var DEFAULT_MAX_RECONNECTS = 10;
3257
+ var MAX_FRAME_BYTES = 1048576;
3258
+ var EventsResource = class extends WorkspaceScopedResource {
3259
+ constructor(client, workspaceId2) {
3260
+ super(client, workspaceId2);
3261
+ }
3262
+ /**
3263
+ * Subscribe to the workspace event stream.
3264
+ *
3265
+ * Establishes an SSE connection to ``/v1/{workspace_id}/events/stream``
3266
+ * and invokes ``onEvent`` once per typed {@link WorkspaceSSEEvent}.
3267
+ * Unrecoverable failures (auth errors, exhausted reconnect budget,
3268
+ * caller abort) surface through ``onError``.
3269
+ *
3270
+ * Reconnection is automatic: on a network drop or 5xx, the helper
3271
+ * backs off (initial delay derived from the ``retry:`` directive,
3272
+ * default 3s, doubling with full jitter up to ``maxDelayMs``) and
3273
+ * resumes with the most recently seen ``Last-Event-ID``. The platform
3274
+ * buffers 5 minutes of events for gapless replay.
3275
+ *
3276
+ * @returns a {@link SubscriptionHandle} for cleanup. Aborting the
3277
+ * caller's ``signal`` is equivalent to calling ``unsubscribe()``.
3278
+ */
3279
+ subscribeToWorkspace(options) {
3280
+ const localController = new AbortController();
3281
+ const cleanups = [];
3282
+ if (options.signal) {
3283
+ if (options.signal.aborted) {
3284
+ localController.abort(options.signal.reason);
3285
+ } else {
3286
+ const onAbort = () => localController.abort(options.signal?.reason);
3287
+ options.signal.addEventListener("abort", onAbort, { once: true });
3288
+ cleanups.push(() => options.signal?.removeEventListener("abort", onAbort));
3289
+ }
3290
+ }
3291
+ const done = runSubscription(
3292
+ this.client,
3293
+ this.workspaceId,
3294
+ options,
3295
+ localController.signal
3296
+ ).finally(() => {
3297
+ for (const cleanup of cleanups) cleanup();
3298
+ });
3299
+ return {
3300
+ done,
3301
+ unsubscribe: () => localController.abort()
3302
+ };
3303
+ }
3304
+ };
3305
+ async function runSubscription(client, workspaceId2, options, signal) {
3306
+ let lastEventId = options.lastEventId;
3307
+ let attempt = 0;
3308
+ let delayMs = options.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
3309
+ const maxDelayMs = options.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
3310
+ const maxReconnects = options.maxReconnects ?? DEFAULT_MAX_RECONNECTS;
3311
+ let errorReported = false;
3312
+ const reportError = (error) => {
3313
+ if (errorReported) return;
3314
+ errorReported = true;
3315
+ try {
3316
+ options.onError?.(error);
3317
+ } catch {
3318
+ }
3319
+ };
3320
+ while (!signal.aborted) {
3321
+ if (attempt > 0) {
3322
+ try {
3323
+ options.onReconnect?.(attempt);
3324
+ } catch {
3325
+ }
3326
+ }
3327
+ let outcome;
3328
+ try {
3329
+ outcome = await runOneConnection({
3330
+ client,
3331
+ workspaceId: workspaceId2,
3332
+ lastEventId,
3333
+ signal,
3334
+ onEvent: options.onEvent,
3335
+ onIdAdvance: (id) => {
3336
+ lastEventId = id;
3337
+ },
3338
+ onRetryDirective: (ms) => {
3339
+ delayMs = clampDelay(ms, options.initialDelayMs, maxDelayMs);
3340
+ }
3341
+ });
3342
+ } catch (err) {
3343
+ reportError(err instanceof Error ? err : new Error(String(err)));
3344
+ return;
3345
+ }
3346
+ if (signal.aborted || outcome.kind === "aborted") {
3347
+ return;
3348
+ }
3349
+ if (outcome.kind === "auth-error") {
3350
+ reportError(outcome.error);
3351
+ return;
3352
+ }
3353
+ if (attempt >= maxReconnects) {
3354
+ reportError(
3355
+ new Error(
3356
+ `SSE subscription exhausted reconnect budget (${maxReconnects}): ${outcome.reason}`
3357
+ )
3358
+ );
3359
+ return;
3360
+ }
3361
+ attempt += 1;
3362
+ const sleepMs = jitter(delayMs);
3363
+ delayMs = Math.min(delayMs * 2, maxDelayMs);
3364
+ const slept = await abortableSleep(sleepMs, signal);
3365
+ if (!slept) return;
3366
+ }
3367
+ }
3368
+ async function runOneConnection(args) {
3369
+ const headers = { Accept: "text/event-stream" };
3370
+ if (args.lastEventId !== void 0) {
3371
+ headers["Last-Event-ID"] = args.lastEventId;
3372
+ }
3373
+ let result;
3374
+ try {
3375
+ result = await args.client.GET("/v1/{workspace_id}/events/stream", {
3376
+ params: { path: { workspace_id: args.workspaceId } },
3377
+ headers,
3378
+ parseAs: "stream",
3379
+ signal: args.signal
3380
+ });
3381
+ } catch (err) {
3382
+ if (args.signal.aborted) return { kind: "aborted" };
3383
+ const error = err instanceof Error ? err : new Error(String(err));
3384
+ const status = readStatus(error);
3385
+ if (status === 401 || status === 403) {
3386
+ return { kind: "auth-error", error };
3387
+ }
3388
+ return { kind: "transport-error", reason: error.message };
3389
+ }
3390
+ if (result.error !== void 0) {
3391
+ return { kind: "transport-error", reason: `API error: ${safeStringify(result.error)}` };
3392
+ }
3393
+ const body = result.data;
3394
+ if (!(body instanceof ReadableStream)) {
3395
+ return { kind: "transport-error", reason: "Expected ReadableStream body for SSE" };
3396
+ }
3397
+ try {
3398
+ for await (const frame of parseSSEFrames2(body, args.signal)) {
3399
+ if (args.signal.aborted) return { kind: "aborted" };
3400
+ if (frame.retry !== void 0) {
3401
+ args.onRetryDirective(frame.retry);
3402
+ }
3403
+ if (frame.id !== void 0) {
3404
+ args.onIdAdvance(frame.id);
3405
+ }
3406
+ if (frame.event && frame.data !== void 0) {
3407
+ const event = parseWorkspaceFrame(frame.event, frame.data);
3408
+ if (event) {
3409
+ try {
3410
+ args.onEvent(event);
3411
+ } catch {
3412
+ }
3413
+ }
3414
+ }
3415
+ }
3416
+ } catch (err) {
3417
+ if (args.signal.aborted) return { kind: "aborted" };
3418
+ const reason = err instanceof Error ? err.message : String(err);
3419
+ return { kind: "transport-error", reason };
3420
+ }
3421
+ if (args.signal.aborted) return { kind: "aborted" };
3422
+ return { kind: "transport-error", reason: "Stream closed by server" };
3423
+ }
3424
+ async function* parseSSEFrames2(stream, signal) {
3425
+ const reader = stream.getReader();
3426
+ const decoder = new TextDecoder();
3427
+ let buffer = "";
3428
+ let cancelled = false;
3429
+ const onAbort = () => {
3430
+ if (cancelled) return;
3431
+ cancelled = true;
3432
+ void reader.cancel().catch(() => {
3433
+ });
3434
+ };
3435
+ let removeAbortHandler;
3436
+ if (signal.aborted) {
3437
+ onAbort();
3438
+ } else {
3439
+ signal.addEventListener("abort", onAbort, { once: true });
3440
+ removeAbortHandler = () => signal.removeEventListener("abort", onAbort);
3441
+ }
3442
+ function* drain(text) {
3443
+ buffer += text;
3444
+ if (buffer.length > MAX_FRAME_BYTES) {
3445
+ throw new Error(`SSE frame buffer exceeded ${MAX_FRAME_BYTES} bytes without terminator`);
3446
+ }
3447
+ while (true) {
3448
+ const idx = findFrameTerminator2(buffer);
3449
+ if (idx === null) break;
3450
+ const block = buffer.slice(0, idx.terminatorStart);
3451
+ buffer = buffer.slice(idx.terminatorEnd);
3452
+ const frame = parseSSEBlock2(block);
3453
+ if (frame) yield frame;
3454
+ }
3455
+ }
3456
+ try {
3457
+ while (true) {
3458
+ const { done, value } = await reader.read();
3459
+ if (done) break;
3460
+ yield* drain(decoder.decode(value, { stream: true }));
3461
+ }
3462
+ yield* drain(decoder.decode());
3463
+ if (buffer.trim().length > 0) {
3464
+ const frame = parseSSEBlock2(buffer);
3465
+ if (frame) yield frame;
3466
+ buffer = "";
3467
+ }
3468
+ } finally {
3469
+ removeAbortHandler?.();
3470
+ try {
3471
+ reader.releaseLock();
3472
+ } catch {
3473
+ }
3474
+ }
3475
+ }
3476
+ function findFrameTerminator2(s) {
3477
+ const lf = s.indexOf("\n\n");
3478
+ const crlf = s.indexOf("\r\n\r\n");
3479
+ if (lf < 0 && crlf < 0) return null;
3480
+ if (lf < 0) return { terminatorStart: crlf, terminatorEnd: crlf + 4 };
3481
+ if (crlf < 0) return { terminatorStart: lf, terminatorEnd: lf + 2 };
3482
+ return lf < crlf ? { terminatorStart: lf, terminatorEnd: lf + 2 } : { terminatorStart: crlf, terminatorEnd: crlf + 4 };
3483
+ }
3484
+ function parseSSEBlock2(block) {
3485
+ let event = "";
3486
+ let id;
3487
+ let retry;
3488
+ const dataLines = [];
3489
+ for (const line of block.split(/\r?\n/)) {
3490
+ if (line === "" || line.startsWith(":")) continue;
3491
+ const colon = line.indexOf(":");
3492
+ const field = colon < 0 ? line : line.slice(0, colon);
3493
+ let value = colon < 0 ? "" : line.slice(colon + 1);
3494
+ if (value.startsWith(" ")) value = value.slice(1);
3495
+ if (field === "event") {
3496
+ event = value;
3497
+ } else if (field === "data") {
3498
+ dataLines.push(value);
3499
+ } else if (field === "id") {
3500
+ id = value;
3501
+ } else if (field === "retry") {
3502
+ const parsed = Number.parseInt(value, 10);
3503
+ if (Number.isFinite(parsed) && parsed >= 0) retry = parsed;
3504
+ }
3505
+ }
3506
+ if (!event && dataLines.length === 0 && id === void 0 && retry === void 0) {
3507
+ return null;
3508
+ }
3509
+ return {
3510
+ event,
3511
+ data: dataLines.length > 0 ? dataLines.join("\n") : void 0,
3512
+ id,
3513
+ retry
3514
+ };
3515
+ }
3516
+ function parseWorkspaceFrame(eventName, dataJson) {
3517
+ let payload;
3518
+ try {
3519
+ payload = JSON.parse(dataJson);
3520
+ } catch {
3521
+ return null;
3522
+ }
3523
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return null;
3524
+ return {
3525
+ ...payload,
3526
+ event_type: eventName
3527
+ };
3528
+ }
3529
+ function readStatus(error) {
3530
+ if (typeof error !== "object" || error === null) return void 0;
3531
+ const status = error.statusCode;
3532
+ return typeof status === "number" ? status : void 0;
3533
+ }
3534
+ function safeStringify(value) {
3535
+ try {
3536
+ return JSON.stringify(value);
3537
+ } catch {
3538
+ return String(value);
3539
+ }
3540
+ }
3541
+ function jitter(ms) {
3542
+ return Math.floor(Math.random() * Math.max(1, ms));
3543
+ }
3544
+ function clampDelay(ms, floor, ceiling) {
3545
+ const lo = floor ?? DEFAULT_INITIAL_DELAY_MS;
3546
+ if (!Number.isFinite(ms) || ms <= 0) return lo;
3547
+ return Math.min(Math.max(ms, lo), ceiling);
3548
+ }
3549
+ async function abortableSleep(ms, signal) {
3550
+ if (signal.aborted) return false;
3551
+ return new Promise((resolve) => {
3552
+ const timer = setTimeout(() => {
3553
+ signal.removeEventListener("abort", onAbort);
3554
+ resolve(true);
3555
+ }, ms);
3556
+ const onAbort = () => {
3557
+ clearTimeout(timer);
3558
+ signal.removeEventListener("abort", onAbort);
3559
+ resolve(false);
3560
+ };
3561
+ signal.addEventListener("abort", onAbort, { once: true });
3562
+ });
3563
+ }
3564
+
3155
3565
  // src/resources/functions.ts
3156
3566
  var FunctionsResource = class extends WorkspaceScopedResource {
3157
3567
  async list() {
@@ -3867,6 +4277,7 @@ var AmigoClient = class _AmigoClient {
3867
4277
  webhookDestinations;
3868
4278
  safety;
3869
4279
  compliance;
4280
+ events;
3870
4281
  functions;
3871
4282
  /** @internal — exposed for path-level type inference in GET/POST/PUT/etc. */
3872
4283
  api;
@@ -3962,6 +4373,7 @@ var AmigoClient = class _AmigoClient {
3962
4373
  mutable.webhookDestinations = new WebhookDestinationsResource(client, workspaceId2);
3963
4374
  mutable.safety = new SafetyResource(client, workspaceId2);
3964
4375
  mutable.compliance = new ComplianceResource(client, workspaceId2);
4376
+ mutable.events = new EventsResource(client, workspaceId2);
3965
4377
  mutable.functions = new FunctionsResource(client, workspaceId2);
3966
4378
  }
3967
4379
  async resolveApiRequest(path, method, init) {