@agent-os-sdk/client 0.9.25 → 0.9.26

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 (184) hide show
  1. package/package.json +15 -8
  2. package/src/generated/openapi.ts +82 -0
  3. package/src/generated/swagger.json +163 -0
  4. package/src/modules/templates.ts +35 -0
  5. package/dist/client/AgentOsClient.d.ts +0 -141
  6. package/dist/client/AgentOsClient.d.ts.map +0 -1
  7. package/dist/client/AgentOsClient.js +0 -250
  8. package/dist/client/HttpRequestBuilder.d.ts +0 -50
  9. package/dist/client/HttpRequestBuilder.d.ts.map +0 -1
  10. package/dist/client/HttpRequestBuilder.js +0 -83
  11. package/dist/client/OperationContext.d.ts +0 -19
  12. package/dist/client/OperationContext.d.ts.map +0 -1
  13. package/dist/client/OperationContext.js +0 -13
  14. package/dist/client/OperationContextProvider.d.ts +0 -54
  15. package/dist/client/OperationContextProvider.d.ts.map +0 -1
  16. package/dist/client/OperationContextProvider.js +0 -71
  17. package/dist/client/auth.d.ts +0 -100
  18. package/dist/client/auth.d.ts.map +0 -1
  19. package/dist/client/auth.js +0 -38
  20. package/dist/client/config.d.ts +0 -49
  21. package/dist/client/config.d.ts.map +0 -1
  22. package/dist/client/config.js +0 -62
  23. package/dist/client/helpers.d.ts +0 -63
  24. package/dist/client/helpers.d.ts.map +0 -1
  25. package/dist/client/helpers.js +0 -55
  26. package/dist/client/pagination.d.ts +0 -105
  27. package/dist/client/pagination.d.ts.map +0 -1
  28. package/dist/client/pagination.js +0 -117
  29. package/dist/client/raw.d.ts +0 -277
  30. package/dist/client/raw.d.ts.map +0 -1
  31. package/dist/client/raw.js +0 -337
  32. package/dist/client/retry.d.ts +0 -37
  33. package/dist/client/retry.d.ts.map +0 -1
  34. package/dist/client/retry.js +0 -108
  35. package/dist/client/sanitize.d.ts +0 -19
  36. package/dist/client/sanitize.d.ts.map +0 -1
  37. package/dist/client/sanitize.js +0 -28
  38. package/dist/client/timeout.d.ts +0 -26
  39. package/dist/client/timeout.d.ts.map +0 -1
  40. package/dist/client/timeout.js +0 -51
  41. package/dist/errors/factory.d.ts +0 -22
  42. package/dist/errors/factory.d.ts.map +0 -1
  43. package/dist/errors/factory.js +0 -101
  44. package/dist/errors/index.d.ts +0 -210
  45. package/dist/errors/index.d.ts.map +0 -1
  46. package/dist/errors/index.js +0 -283
  47. package/dist/generated/client.d.ts +0 -20
  48. package/dist/generated/client.d.ts.map +0 -1
  49. package/dist/generated/client.js +0 -15
  50. package/dist/generated/index.d.ts +0 -2
  51. package/dist/generated/index.d.ts.map +0 -1
  52. package/dist/generated/index.js +0 -1
  53. package/dist/generated/openapi.d.ts +0 -12302
  54. package/dist/generated/openapi.d.ts.map +0 -1
  55. package/dist/generated/openapi.js +0 -5
  56. package/dist/index.d.ts +0 -69
  57. package/dist/index.d.ts.map +0 -1
  58. package/dist/index.js +0 -81
  59. package/dist/modules/a2a.d.ts +0 -48
  60. package/dist/modules/a2a.d.ts.map +0 -1
  61. package/dist/modules/a2a.js +0 -37
  62. package/dist/modules/agents.d.ts +0 -346
  63. package/dist/modules/agents.d.ts.map +0 -1
  64. package/dist/modules/agents.js +0 -296
  65. package/dist/modules/apiTokens.d.ts +0 -62
  66. package/dist/modules/apiTokens.d.ts.map +0 -1
  67. package/dist/modules/apiTokens.js +0 -56
  68. package/dist/modules/approvals.d.ts +0 -75
  69. package/dist/modules/approvals.d.ts.map +0 -1
  70. package/dist/modules/approvals.js +0 -91
  71. package/dist/modules/audit.d.ts +0 -78
  72. package/dist/modules/audit.d.ts.map +0 -1
  73. package/dist/modules/audit.js +0 -94
  74. package/dist/modules/auth.d.ts +0 -28
  75. package/dist/modules/auth.d.ts.map +0 -1
  76. package/dist/modules/auth.js +0 -22
  77. package/dist/modules/builder.d.ts +0 -242
  78. package/dist/modules/builder.d.ts.map +0 -1
  79. package/dist/modules/builder.js +0 -248
  80. package/dist/modules/catalog.d.ts +0 -142
  81. package/dist/modules/catalog.d.ts.map +0 -1
  82. package/dist/modules/catalog.js +0 -136
  83. package/dist/modules/chatwoot.d.ts +0 -59
  84. package/dist/modules/chatwoot.d.ts.map +0 -1
  85. package/dist/modules/chatwoot.js +0 -200
  86. package/dist/modules/checkpoints.d.ts +0 -62
  87. package/dist/modules/checkpoints.d.ts.map +0 -1
  88. package/dist/modules/checkpoints.js +0 -48
  89. package/dist/modules/contracts.d.ts +0 -48
  90. package/dist/modules/contracts.d.ts.map +0 -1
  91. package/dist/modules/contracts.js +0 -25
  92. package/dist/modules/credentials.d.ts +0 -105
  93. package/dist/modules/credentials.d.ts.map +0 -1
  94. package/dist/modules/credentials.js +0 -135
  95. package/dist/modules/crons.d.ts +0 -73
  96. package/dist/modules/crons.d.ts.map +0 -1
  97. package/dist/modules/crons.js +0 -67
  98. package/dist/modules/datasets.d.ts +0 -80
  99. package/dist/modules/datasets.d.ts.map +0 -1
  100. package/dist/modules/datasets.js +0 -91
  101. package/dist/modules/evaluation.d.ts +0 -183
  102. package/dist/modules/evaluation.d.ts.map +0 -1
  103. package/dist/modules/evaluation.js +0 -108
  104. package/dist/modules/files.d.ts +0 -89
  105. package/dist/modules/files.d.ts.map +0 -1
  106. package/dist/modules/files.js +0 -133
  107. package/dist/modules/graphs.d.ts +0 -120
  108. package/dist/modules/graphs.d.ts.map +0 -1
  109. package/dist/modules/graphs.js +0 -69
  110. package/dist/modules/improvements.d.ts +0 -52
  111. package/dist/modules/improvements.d.ts.map +0 -1
  112. package/dist/modules/improvements.js +0 -27
  113. package/dist/modules/info.d.ts +0 -76
  114. package/dist/modules/info.d.ts.map +0 -1
  115. package/dist/modules/info.js +0 -93
  116. package/dist/modules/knowledge.d.ts +0 -91
  117. package/dist/modules/knowledge.d.ts.map +0 -1
  118. package/dist/modules/knowledge.js +0 -80
  119. package/dist/modules/me.d.ts +0 -58
  120. package/dist/modules/me.d.ts.map +0 -1
  121. package/dist/modules/me.js +0 -28
  122. package/dist/modules/members.d.ts +0 -124
  123. package/dist/modules/members.d.ts.map +0 -1
  124. package/dist/modules/members.js +0 -142
  125. package/dist/modules/memberships.d.ts +0 -25
  126. package/dist/modules/memberships.d.ts.map +0 -1
  127. package/dist/modules/memberships.js +0 -20
  128. package/dist/modules/metaAgent.d.ts +0 -95
  129. package/dist/modules/metaAgent.d.ts.map +0 -1
  130. package/dist/modules/metaAgent.js +0 -32
  131. package/dist/modules/metrics.d.ts +0 -20
  132. package/dist/modules/metrics.d.ts.map +0 -1
  133. package/dist/modules/metrics.js +0 -27
  134. package/dist/modules/observability.d.ts +0 -19
  135. package/dist/modules/observability.d.ts.map +0 -1
  136. package/dist/modules/observability.js +0 -14
  137. package/dist/modules/playground.d.ts +0 -42
  138. package/dist/modules/playground.d.ts.map +0 -1
  139. package/dist/modules/playground.js +0 -48
  140. package/dist/modules/presets.d.ts +0 -32
  141. package/dist/modules/presets.d.ts.map +0 -1
  142. package/dist/modules/presets.js +0 -199
  143. package/dist/modules/prompts.d.ts +0 -87
  144. package/dist/modules/prompts.d.ts.map +0 -1
  145. package/dist/modules/prompts.js +0 -87
  146. package/dist/modules/roles.d.ts +0 -64
  147. package/dist/modules/roles.d.ts.map +0 -1
  148. package/dist/modules/roles.js +0 -79
  149. package/dist/modules/runs.d.ts +0 -451
  150. package/dist/modules/runs.d.ts.map +0 -1
  151. package/dist/modules/runs.js +0 -536
  152. package/dist/modules/store.d.ts +0 -37
  153. package/dist/modules/store.d.ts.map +0 -1
  154. package/dist/modules/store.js +0 -48
  155. package/dist/modules/templates.d.ts +0 -28
  156. package/dist/modules/templates.d.ts.map +0 -1
  157. package/dist/modules/templates.js +0 -19
  158. package/dist/modules/tenants.d.ts +0 -49
  159. package/dist/modules/tenants.d.ts.map +0 -1
  160. package/dist/modules/tenants.js +0 -56
  161. package/dist/modules/threads.d.ts +0 -205
  162. package/dist/modules/threads.d.ts.map +0 -1
  163. package/dist/modules/threads.js +0 -225
  164. package/dist/modules/tools.d.ts +0 -62
  165. package/dist/modules/tools.d.ts.map +0 -1
  166. package/dist/modules/tools.js +0 -45
  167. package/dist/modules/traces.d.ts +0 -89
  168. package/dist/modules/traces.d.ts.map +0 -1
  169. package/dist/modules/traces.js +0 -65
  170. package/dist/modules/triggers.d.ts +0 -228
  171. package/dist/modules/triggers.d.ts.map +0 -1
  172. package/dist/modules/triggers.js +0 -176
  173. package/dist/modules/usage.d.ts +0 -85
  174. package/dist/modules/usage.d.ts.map +0 -1
  175. package/dist/modules/usage.js +0 -43
  176. package/dist/modules/vectorStores.d.ts +0 -100
  177. package/dist/modules/vectorStores.d.ts.map +0 -1
  178. package/dist/modules/vectorStores.js +0 -159
  179. package/dist/modules/workspaces.d.ts +0 -138
  180. package/dist/modules/workspaces.d.ts.map +0 -1
  181. package/dist/modules/workspaces.js +0 -121
  182. package/dist/sse/client.d.ts +0 -140
  183. package/dist/sse/client.d.ts.map +0 -1
  184. package/dist/sse/client.js +0 -103
@@ -1,108 +0,0 @@
1
- /**
2
- * Agent OS SDK - Retry Logic
3
- *
4
- * Enterprise-grade retry with:
5
- * - Exponential backoff with jitter
6
- * - Respect for Retry-After headers
7
- * - Idempotency-aware mutation retries
8
- * - Proper abort signal handling (no listener leaks)
9
- */
10
- import { AgentOsError, NetworkError, TimeoutError, RateLimitError } from "../errors/index.js";
11
- /**
12
- * Wraps an async function with retry logic.
13
- *
14
- * IMPORTANT: Mutations (POST/PUT/PATCH/DELETE) are only retried if hasIdempotencyKey is true.
15
- * This prevents duplicate side effects.
16
- *
17
- * @param fn - Function to execute (receives an AbortSignal)
18
- * @param config - Retry configuration
19
- * @param context - Request context for retry decisions
20
- * @param parentSignal - Optional parent AbortSignal for cancellation
21
- */
22
- export async function withRetry(fn, config, context, parentSignal) {
23
- let lastError;
24
- for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
25
- // Check parent abort before each attempt
26
- if (parentSignal?.aborted) {
27
- throw new Error("Request aborted");
28
- }
29
- const controller = new AbortController();
30
- // Proper abort propagation without listener leak
31
- const onAbort = () => controller.abort();
32
- parentSignal?.addEventListener("abort", onAbort, { once: true });
33
- try {
34
- return await fn(controller.signal);
35
- }
36
- catch (err) {
37
- lastError = err;
38
- // If parent aborted, don't retry
39
- if (controller.signal.aborted && parentSignal?.aborted) {
40
- throw err;
41
- }
42
- // Check if this error is retryable
43
- if (!shouldRetry(err, config, context)) {
44
- throw err;
45
- }
46
- // Last attempt reached
47
- if (attempt === config.maxRetries) {
48
- throw err;
49
- }
50
- // Rate limit: use Retry-After if available
51
- if (err instanceof RateLimitError && err.retryAfterMs) {
52
- await sleep(err.retryAfterMs);
53
- continue;
54
- }
55
- // Exponential backoff with jitter
56
- const delay = calculateBackoff(attempt, config);
57
- await sleep(delay);
58
- }
59
- finally {
60
- // CRITICAL: Always cleanup listener to prevent memory leak
61
- parentSignal?.removeEventListener("abort", onAbort);
62
- }
63
- }
64
- throw lastError ?? new Error("Retry failed");
65
- }
66
- /**
67
- * Determines if an error should trigger a retry.
68
- */
69
- function shouldRetry(err, config, context) {
70
- // Network and timeout errors are always retryable
71
- if (err instanceof NetworkError || err instanceof TimeoutError) {
72
- return true;
73
- }
74
- // Unknown errors are not retryable
75
- if (!(err instanceof AgentOsError)) {
76
- return false;
77
- }
78
- // Check if status code is in retryable list
79
- if (!config.retryableStatuses.includes(err.status)) {
80
- return false;
81
- }
82
- // CRITICAL: Only retry mutations if they have an idempotency key
83
- // This prevents duplicate side effects from retrying POST/PUT/PATCH/DELETE
84
- const isMutation = !["GET", "HEAD", "OPTIONS"].includes(context.method.toUpperCase());
85
- if (isMutation && !context.hasIdempotencyKey) {
86
- return false;
87
- }
88
- return true;
89
- }
90
- /**
91
- * Calculates backoff delay with exponential increase and jitter.
92
- */
93
- function calculateBackoff(attempt, config) {
94
- // Exponential backoff: baseDelay * 2^attempt
95
- const exponential = config.baseDelayMs * Math.pow(2, attempt);
96
- // Cap at max delay
97
- const capped = Math.min(exponential, config.maxDelayMs);
98
- // Add jitter to prevent thundering herd
99
- const jitter = capped * config.jitterFactor * Math.random();
100
- return Math.floor(capped + jitter);
101
- }
102
- /**
103
- * Sleep utility.
104
- */
105
- function sleep(ms) {
106
- return new Promise(resolve => setTimeout(resolve, ms));
107
- }
108
- export { sleep };
@@ -1,19 +0,0 @@
1
- /**
2
- * Header Sanitization — Security layer for HTTP headers
3
- *
4
- * Removes control characters and enforces size limits.
5
- *
6
- * @see sdk-upgrade.md Section 1.4
7
- */
8
- /**
9
- * Sanitize a single header value.
10
- * - Removes control characters (0x00-0x1F, 0x7F)
11
- * - Truncates to MAX_LEN
12
- */
13
- export declare function sanitizeHeader(v: string): string;
14
- /**
15
- * Sanitize all header values in a record.
16
- * Mutates in place for performance.
17
- */
18
- export declare function sanitizeHeaders(h: Record<string, string>): Record<string, string>;
19
- //# sourceMappingURL=sanitize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/client/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOjF"}
@@ -1,28 +0,0 @@
1
- /**
2
- * Header Sanitization — Security layer for HTTP headers
3
- *
4
- * Removes control characters and enforces size limits.
5
- *
6
- * @see sdk-upgrade.md Section 1.4
7
- */
8
- const MAX_LEN = 1024;
9
- /**
10
- * Sanitize a single header value.
11
- * - Removes control characters (0x00-0x1F, 0x7F)
12
- * - Truncates to MAX_LEN
13
- */
14
- export function sanitizeHeader(v) {
15
- return v.replace(/[\u0000-\u001F\u007F]/g, "").slice(0, MAX_LEN);
16
- }
17
- /**
18
- * Sanitize all header values in a record.
19
- * Mutates in place for performance.
20
- */
21
- export function sanitizeHeaders(h) {
22
- for (const k in h) {
23
- if (Object.prototype.hasOwnProperty.call(h, k) && h[k] !== undefined) {
24
- h[k] = sanitizeHeader(h[k]);
25
- }
26
- }
27
- return h;
28
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Agent OS SDK - Timeout Logic
3
- *
4
- * Wraps async operations with per-attempt timeout.
5
- * Proper abort signal propagation without listener leaks.
6
- */
7
- /**
8
- * Wraps an async function with a timeout.
9
- *
10
- * The timeout is per-attempt, not global. This ensures that slow attempts
11
- * don't consume the entire retry budget.
12
- *
13
- * @param fn - Function to execute (receives an AbortSignal)
14
- * @param timeoutMs - Timeout in milliseconds
15
- * @param parentSignal - Optional parent AbortSignal for cancellation
16
- */
17
- export declare function withTimeout<T>(fn: (signal: AbortSignal) => Promise<T>, timeoutMs: number, parentSignal?: AbortSignal): Promise<T>;
18
- /**
19
- * Creates an AbortController that times out after the specified duration.
20
- * Useful for creating deadline-aware operations.
21
- *
22
- * @param timeoutMs - Timeout in milliseconds
23
- * @returns AbortController that will abort after timeout
24
- */
25
- export declare function createTimeoutController(timeoutMs: number): AbortController;
26
- //# sourceMappingURL=timeout.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/client/timeout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAC/B,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACvC,SAAS,EAAE,MAAM,EACjB,YAAY,CAAC,EAAE,WAAW,GAC3B,OAAO,CAAC,CAAC,CAAC,CAsBZ;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAI1E"}
@@ -1,51 +0,0 @@
1
- /**
2
- * Agent OS SDK - Timeout Logic
3
- *
4
- * Wraps async operations with per-attempt timeout.
5
- * Proper abort signal propagation without listener leaks.
6
- */
7
- import { TimeoutError } from "../errors/index.js";
8
- /**
9
- * Wraps an async function with a timeout.
10
- *
11
- * The timeout is per-attempt, not global. This ensures that slow attempts
12
- * don't consume the entire retry budget.
13
- *
14
- * @param fn - Function to execute (receives an AbortSignal)
15
- * @param timeoutMs - Timeout in milliseconds
16
- * @param parentSignal - Optional parent AbortSignal for cancellation
17
- */
18
- export async function withTimeout(fn, timeoutMs, parentSignal) {
19
- const controller = new AbortController();
20
- // Propagate parent abort
21
- const onAbort = () => controller.abort();
22
- parentSignal?.addEventListener("abort", onAbort, { once: true });
23
- // Set timeout
24
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
25
- try {
26
- return await fn(controller.signal);
27
- }
28
- catch (err) {
29
- // If our timeout triggered the abort (not parent), throw TimeoutError
30
- if (controller.signal.aborted && !parentSignal?.aborted) {
31
- throw new TimeoutError(timeoutMs);
32
- }
33
- throw err;
34
- }
35
- finally {
36
- clearTimeout(timeoutId);
37
- parentSignal?.removeEventListener("abort", onAbort);
38
- }
39
- }
40
- /**
41
- * Creates an AbortController that times out after the specified duration.
42
- * Useful for creating deadline-aware operations.
43
- *
44
- * @param timeoutMs - Timeout in milliseconds
45
- * @returns AbortController that will abort after timeout
46
- */
47
- export function createTimeoutController(timeoutMs) {
48
- const controller = new AbortController();
49
- setTimeout(() => controller.abort(), timeoutMs);
50
- return controller;
51
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * Agent OS SDK - Error Factory
3
- *
4
- * Creates typed errors from HTTP responses.
5
- * Preserves backend error codes and details for debugging.
6
- */
7
- import { AgentOsError } from "./index.js";
8
- /**
9
- * Creates a typed error from an HTTP response.
10
- *
11
- * @param response - The fetch Response object
12
- * @param body - Parsed JSON body (if available)
13
- * @param requestPath - The original request path (for 404 errors)
14
- */
15
- export declare function createErrorFromResponse(response: Response, body?: {
16
- code?: string;
17
- message?: string;
18
- detail?: string;
19
- title?: string;
20
- details?: unknown;
21
- }, requestPath?: string): AgentOsError;
22
- //# sourceMappingURL=factory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/errors/factory.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACH,YAAY,EAUf,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACnC,QAAQ,EAAE,QAAQ,EAClB,IAAI,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EAC9F,WAAW,CAAC,EAAE,MAAM,GACrB,YAAY,CAgEd"}
@@ -1,101 +0,0 @@
1
- /**
2
- * Agent OS SDK - Error Factory
3
- *
4
- * Creates typed errors from HTTP responses.
5
- * Preserves backend error codes and details for debugging.
6
- */
7
- import { AgentOsError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, ValidationError, RateLimitError, ServerError, } from "./index.js";
8
- /**
9
- * Creates a typed error from an HTTP response.
10
- *
11
- * @param response - The fetch Response object
12
- * @param body - Parsed JSON body (if available)
13
- * @param requestPath - The original request path (for 404 errors)
14
- */
15
- export function createErrorFromResponse(response, body, requestPath) {
16
- const status = response.status;
17
- const message = body?.message ||
18
- body?.detail ||
19
- body?.title ||
20
- response.statusText ||
21
- `HTTP ${status}`;
22
- const requestId = response.headers.get("x-request-id") ?? undefined;
23
- const opts = {
24
- requestId,
25
- backendCode: body?.code,
26
- details: body?.details,
27
- };
28
- switch (status) {
29
- case 401:
30
- return new UnauthorizedError(message, opts);
31
- case 403:
32
- return new ForbiddenError(message, opts);
33
- case 404:
34
- return new NotFoundError(message, requestPath, opts);
35
- case 409:
36
- return new ConflictError(message, opts);
37
- case 400:
38
- case 422:
39
- return new ValidationError(message, status, parseFieldErrors(body?.details), opts);
40
- case 429:
41
- const retryAfterHeader = response.headers.get("Retry-After");
42
- let retryAfterMs;
43
- if (retryAfterHeader) {
44
- // Retry-After can be seconds or a date
45
- const seconds = parseInt(retryAfterHeader, 10);
46
- if (!isNaN(seconds)) {
47
- retryAfterMs = seconds * 1000;
48
- }
49
- else {
50
- // Try parsing as date
51
- const date = new Date(retryAfterHeader);
52
- if (!isNaN(date.getTime())) {
53
- retryAfterMs = Math.max(0, date.getTime() - Date.now());
54
- }
55
- }
56
- }
57
- return new RateLimitError(message, retryAfterMs, opts);
58
- default:
59
- if (status >= 500) {
60
- return new ServerError(message, status, opts);
61
- }
62
- // Fallback for unknown 4xx errors
63
- return new ServerError(message, status, opts);
64
- }
65
- }
66
- /**
67
- * Parses field errors from various backend formats.
68
- */
69
- function parseFieldErrors(details) {
70
- if (!details || typeof details !== "object") {
71
- return undefined;
72
- }
73
- // Format 1: Array of { field, message } objects
74
- if (Array.isArray(details)) {
75
- const errors = details.filter((d) => typeof d === "object" &&
76
- d !== null &&
77
- typeof d.field === "string" &&
78
- typeof d.message === "string");
79
- return errors.length > 0 ? errors : undefined;
80
- }
81
- // Format 2: { errors: [...] }
82
- if ("errors" in details && Array.isArray(details.errors)) {
83
- return parseFieldErrors(details.errors);
84
- }
85
- // Format 3: { field: [messages] } (Rails/Django style)
86
- const entries = Object.entries(details);
87
- if (entries.every(([, v]) => Array.isArray(v))) {
88
- const errors = [];
89
- for (const [field, messages] of entries) {
90
- if (Array.isArray(messages)) {
91
- for (const message of messages) {
92
- if (typeof message === "string") {
93
- errors.push({ field, message });
94
- }
95
- }
96
- }
97
- }
98
- return errors.length > 0 ? errors : undefined;
99
- }
100
- return undefined;
101
- }
@@ -1,210 +0,0 @@
1
- /**
2
- * Agent OS SDK - Typed Errors
3
- *
4
- * Enterprise-grade error classification for predictable error handling.
5
- * All errors extend AgentOsError and include semantic information.
6
- */
7
- /**
8
- * Options for constructing typed errors
9
- */
10
- export interface ErrorOptions {
11
- /** Request ID from x-request-id header */
12
- requestId?: string;
13
- /** Original error code from backend (preserves backend semantics) */
14
- backendCode?: string;
15
- /** Raw details object from backend response */
16
- details?: unknown;
17
- }
18
- /**
19
- * Base class for all Agent OS SDK errors.
20
- * Provides consistent structure for error handling and classification.
21
- */
22
- export declare abstract class AgentOsError extends Error {
23
- /** Error code for programmatic handling */
24
- abstract readonly code: string;
25
- /** HTTP status code (0 for network/timeout errors) */
26
- abstract readonly status: number;
27
- /** Request ID from x-request-id header */
28
- readonly requestId?: string;
29
- /** Original error code from backend (preserves backend semantics) */
30
- readonly backendCode?: string;
31
- /** Raw details object from backend response */
32
- readonly details?: unknown;
33
- /** Timestamp when error occurred */
34
- readonly timestamp: string;
35
- constructor(message: string, options?: ErrorOptions);
36
- /**
37
- * Whether this error is retryable with the same request.
38
- * Override in subclasses for specific behavior.
39
- */
40
- isRetryable(): boolean;
41
- /** Convert to JSON for logging/serialization */
42
- toJSON(): Record<string, unknown>;
43
- }
44
- /**
45
- * 401 Unauthorized - Invalid or missing authentication.
46
- *
47
- * @example
48
- * if (error instanceof UnauthorizedError) {
49
- * // Redirect to login
50
- * }
51
- */
52
- export declare class UnauthorizedError extends AgentOsError {
53
- readonly code = "UNAUTHORIZED";
54
- readonly status = 401;
55
- constructor(message?: string, options?: ErrorOptions);
56
- }
57
- /**
58
- * 403 Forbidden - Valid auth but insufficient permissions.
59
- *
60
- * @example
61
- * if (error instanceof ForbiddenError) {
62
- * showToast("You don't have permission to perform this action");
63
- * }
64
- */
65
- export declare class ForbiddenError extends AgentOsError {
66
- readonly code = "FORBIDDEN";
67
- readonly status = 403;
68
- constructor(message?: string, options?: ErrorOptions);
69
- }
70
- /**
71
- * 404 Not Found - Resource does not exist.
72
- *
73
- * @example
74
- * if (error instanceof NotFoundError) {
75
- * console.log(`Not found at: ${error.path}`);
76
- * }
77
- */
78
- export declare class NotFoundError extends AgentOsError {
79
- /** The request path that returned 404 */
80
- readonly path?: string | undefined;
81
- readonly code = "NOT_FOUND";
82
- readonly status = 404;
83
- constructor(message?: string,
84
- /** The request path that returned 404 */
85
- path?: string | undefined, options?: ErrorOptions);
86
- }
87
- /**
88
- * 409 Conflict - Resource already exists or state conflict.
89
- *
90
- * @example
91
- * if (error instanceof ConflictError) {
92
- * // Handle duplicate or version mismatch
93
- * }
94
- */
95
- export declare class ConflictError extends AgentOsError {
96
- readonly code = "CONFLICT";
97
- readonly status = 409;
98
- constructor(message?: string, options?: ErrorOptions);
99
- }
100
- /**
101
- * Field-level validation error detail.
102
- */
103
- export interface FieldError {
104
- field: string;
105
- message: string;
106
- code?: string;
107
- }
108
- /**
109
- * 400/422 Validation Error - Invalid request data.
110
- *
111
- * @example
112
- * if (error instanceof ValidationError) {
113
- * error.fieldErrors?.forEach(fe => {
114
- * showFieldError(fe.field, fe.message);
115
- * });
116
- * }
117
- */
118
- export declare class ValidationError extends AgentOsError {
119
- readonly fieldErrors?: FieldError[] | undefined;
120
- readonly code = "VALIDATION_ERROR";
121
- readonly status: 400 | 422;
122
- constructor(message?: string, status?: 400 | 422, fieldErrors?: FieldError[] | undefined, options?: ErrorOptions);
123
- /** Get error message for a specific field */
124
- getFieldError(field: string): string | undefined;
125
- /** Check if a specific field has an error */
126
- hasFieldError(field: string): boolean;
127
- }
128
- /**
129
- * 429 Too Many Requests - Rate limit exceeded.
130
- *
131
- * @example
132
- * if (error instanceof RateLimitError) {
133
- * if (error.retryAfterMs) {
134
- * await sleep(error.retryAfterMs);
135
- * // Retry request
136
- * }
137
- * }
138
- */
139
- export declare class RateLimitError extends AgentOsError {
140
- /** Time to wait before retrying (milliseconds) */
141
- readonly retryAfterMs?: number | undefined;
142
- readonly code = "RATE_LIMITED";
143
- readonly status = 429;
144
- constructor(message?: string,
145
- /** Time to wait before retrying (milliseconds) */
146
- retryAfterMs?: number | undefined, options?: ErrorOptions);
147
- isRetryable(): boolean;
148
- /** Get retry delay or default */
149
- getRetryDelay(defaultMs?: number): number;
150
- }
151
- /**
152
- * 5xx Server Error - Backend failure.
153
- *
154
- * @example
155
- * if (error instanceof ServerError) {
156
- * if (error.isRetryable()) {
157
- * // Retry with backoff
158
- * }
159
- * }
160
- */
161
- export declare class ServerError extends AgentOsError {
162
- readonly status: number;
163
- readonly code = "SERVER_ERROR";
164
- constructor(message?: string, status?: number, options?: ErrorOptions);
165
- isRetryable(): boolean;
166
- }
167
- /**
168
- * Network Error - Fetch failed (no response received).
169
- *
170
- * @example
171
- * if (error instanceof NetworkError) {
172
- * showToast("Network connection failed. Check your internet.");
173
- * }
174
- */
175
- export declare class NetworkError extends AgentOsError {
176
- readonly cause?: Error | undefined;
177
- readonly code = "NETWORK_ERROR";
178
- readonly status = 0;
179
- constructor(message?: string, cause?: Error | undefined);
180
- isRetryable(): boolean;
181
- }
182
- /**
183
- * Timeout Error - Request exceeded time limit.
184
- *
185
- * @example
186
- * if (error instanceof TimeoutError) {
187
- * console.log(`Request timed out after ${error.timeoutMs}ms`);
188
- * }
189
- */
190
- export declare class TimeoutError extends AgentOsError {
191
- /** Timeout duration in milliseconds */
192
- readonly timeoutMs: number;
193
- readonly code = "TIMEOUT";
194
- readonly status = 0;
195
- constructor(
196
- /** Timeout duration in milliseconds */
197
- timeoutMs: number);
198
- isRetryable(): boolean;
199
- }
200
- /** Check if error is any Agent OS SDK error */
201
- export declare function isAgentOsError(error: unknown): error is AgentOsError;
202
- /** Check if error is retryable */
203
- export declare function isRetryableError(error: unknown): boolean;
204
- /** Check if error is an auth error (401 or 403) */
205
- export declare function isAuthError(error: unknown): error is UnauthorizedError | ForbiddenError;
206
- /** Check if error is a client error (4xx) */
207
- export declare function isClientError(error: unknown): boolean;
208
- /** Check if error is a server error (5xx) */
209
- export declare function isServerError(error: unknown): boolean;
210
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,WA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