@agent-os-sdk/client 0.9.25 → 0.9.27
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/generated/openapi.d.ts +82 -0
- package/dist/generated/openapi.d.ts.map +1 -1
- package/dist/modules/runs.d.ts.map +1 -1
- package/dist/modules/templates.d.ts +23 -0
- package/dist/modules/templates.d.ts.map +1 -1
- package/dist/modules/templates.js +7 -0
- package/package.json +2 -2
- package/src/client/AgentOsClient.ts +0 -294
- package/src/client/HttpRequestBuilder.ts +0 -115
- package/src/client/OperationContext.ts +0 -22
- package/src/client/OperationContextProvider.ts +0 -89
- package/src/client/auth.ts +0 -136
- package/src/client/config.ts +0 -100
- package/src/client/helpers.ts +0 -98
- package/src/client/pagination.ts +0 -218
- package/src/client/raw.ts +0 -609
- package/src/client/retry.ts +0 -150
- package/src/client/sanitize.ts +0 -31
- package/src/client/timeout.ts +0 -59
- package/src/errors/factory.ts +0 -140
- package/src/errors/index.ts +0 -365
- package/src/generated/client.ts +0 -32
- package/src/generated/index.ts +0 -2
- package/src/generated/openapi.ts +0 -12302
- package/src/generated/swagger.json +0 -16851
- package/src/index.ts +0 -131
- package/src/modules/a2a.ts +0 -64
- package/src/modules/agents.ts +0 -604
- package/src/modules/apiTokens.ts +0 -101
- package/src/modules/approvals.ts +0 -151
- package/src/modules/audit.ts +0 -145
- package/src/modules/auth.ts +0 -33
- package/src/modules/catalog.ts +0 -241
- package/src/modules/chatwoot.ts +0 -242
- package/src/modules/checkpoints.ts +0 -87
- package/src/modules/contracts.ts +0 -80
- package/src/modules/credentials.ts +0 -216
- package/src/modules/crons.ts +0 -115
- package/src/modules/datasets.ts +0 -142
- package/src/modules/evaluation.ts +0 -269
- package/src/modules/files.ts +0 -208
- package/src/modules/improvements.ts +0 -71
- package/src/modules/info.ts +0 -143
- package/src/modules/me.ts +0 -74
- package/src/modules/members.ts +0 -199
- package/src/modules/memberships.ts +0 -42
- package/src/modules/metaAgent.ts +0 -131
- package/src/modules/metrics.ts +0 -34
- package/src/modules/observability.ts +0 -28
- package/src/modules/playground.ts +0 -68
- package/src/modules/presets.ts +0 -246
- package/src/modules/prompts.ts +0 -147
- package/src/modules/roles.ts +0 -112
- package/src/modules/runs.ts +0 -878
- package/src/modules/store.ts +0 -65
- package/src/modules/templates.ts +0 -40
- package/src/modules/tenants.ts +0 -79
- package/src/modules/threads.ts +0 -343
- package/src/modules/tools.ts +0 -91
- package/src/modules/traces.ts +0 -133
- package/src/modules/triggers.ts +0 -357
- package/src/modules/usage.ts +0 -117
- package/src/modules/vectorStores.ts +0 -257
- package/src/modules/workspaces.ts +0 -216
- package/src/sse/client.ts +0 -179
package/src/client/retry.ts
DELETED
|
@@ -1,150 +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
|
-
|
|
11
|
-
import { AgentOsError, NetworkError, TimeoutError, RateLimitError } from "../errors/index.js";
|
|
12
|
-
import type { RetryConfig } from "./config.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Context for retry decision-making.
|
|
16
|
-
*/
|
|
17
|
-
export interface RetryContext {
|
|
18
|
-
/** HTTP method (GET, POST, etc.) */
|
|
19
|
-
method: string;
|
|
20
|
-
|
|
21
|
-
/** Whether the request has an idempotency key */
|
|
22
|
-
hasIdempotencyKey: boolean;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Wraps an async function with retry logic.
|
|
27
|
-
*
|
|
28
|
-
* IMPORTANT: Mutations (POST/PUT/PATCH/DELETE) are only retried if hasIdempotencyKey is true.
|
|
29
|
-
* This prevents duplicate side effects.
|
|
30
|
-
*
|
|
31
|
-
* @param fn - Function to execute (receives an AbortSignal)
|
|
32
|
-
* @param config - Retry configuration
|
|
33
|
-
* @param context - Request context for retry decisions
|
|
34
|
-
* @param parentSignal - Optional parent AbortSignal for cancellation
|
|
35
|
-
*/
|
|
36
|
-
export async function withRetry<T>(
|
|
37
|
-
fn: (signal: AbortSignal) => Promise<T>,
|
|
38
|
-
config: RetryConfig,
|
|
39
|
-
context: RetryContext,
|
|
40
|
-
parentSignal?: AbortSignal
|
|
41
|
-
): Promise<T> {
|
|
42
|
-
let lastError: Error | undefined;
|
|
43
|
-
|
|
44
|
-
for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
|
|
45
|
-
// Check parent abort before each attempt
|
|
46
|
-
if (parentSignal?.aborted) {
|
|
47
|
-
throw new Error("Request aborted");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const controller = new AbortController();
|
|
51
|
-
|
|
52
|
-
// Proper abort propagation without listener leak
|
|
53
|
-
const onAbort = () => controller.abort();
|
|
54
|
-
parentSignal?.addEventListener("abort", onAbort, { once: true });
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
return await fn(controller.signal);
|
|
58
|
-
} catch (err) {
|
|
59
|
-
lastError = err as Error;
|
|
60
|
-
|
|
61
|
-
// If parent aborted, don't retry
|
|
62
|
-
if (controller.signal.aborted && parentSignal?.aborted) {
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Check if this error is retryable
|
|
67
|
-
if (!shouldRetry(err, config, context)) {
|
|
68
|
-
throw err;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Last attempt reached
|
|
72
|
-
if (attempt === config.maxRetries) {
|
|
73
|
-
throw err;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Rate limit: use Retry-After if available
|
|
77
|
-
if (err instanceof RateLimitError && err.retryAfterMs) {
|
|
78
|
-
await sleep(err.retryAfterMs);
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Exponential backoff with jitter
|
|
83
|
-
const delay = calculateBackoff(attempt, config);
|
|
84
|
-
await sleep(delay);
|
|
85
|
-
} finally {
|
|
86
|
-
// CRITICAL: Always cleanup listener to prevent memory leak
|
|
87
|
-
parentSignal?.removeEventListener("abort", onAbort);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
throw lastError ?? new Error("Retry failed");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Determines if an error should trigger a retry.
|
|
96
|
-
*/
|
|
97
|
-
function shouldRetry(
|
|
98
|
-
err: unknown,
|
|
99
|
-
config: RetryConfig,
|
|
100
|
-
context: RetryContext
|
|
101
|
-
): boolean {
|
|
102
|
-
// Network and timeout errors are always retryable
|
|
103
|
-
if (err instanceof NetworkError || err instanceof TimeoutError) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Unknown errors are not retryable
|
|
108
|
-
if (!(err instanceof AgentOsError)) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Check if status code is in retryable list
|
|
113
|
-
if (!config.retryableStatuses.includes(err.status)) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// CRITICAL: Only retry mutations if they have an idempotency key
|
|
118
|
-
// This prevents duplicate side effects from retrying POST/PUT/PATCH/DELETE
|
|
119
|
-
const isMutation = !["GET", "HEAD", "OPTIONS"].includes(context.method.toUpperCase());
|
|
120
|
-
if (isMutation && !context.hasIdempotencyKey) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Calculates backoff delay with exponential increase and jitter.
|
|
129
|
-
*/
|
|
130
|
-
function calculateBackoff(attempt: number, config: RetryConfig): number {
|
|
131
|
-
// Exponential backoff: baseDelay * 2^attempt
|
|
132
|
-
const exponential = config.baseDelayMs * Math.pow(2, attempt);
|
|
133
|
-
|
|
134
|
-
// Cap at max delay
|
|
135
|
-
const capped = Math.min(exponential, config.maxDelayMs);
|
|
136
|
-
|
|
137
|
-
// Add jitter to prevent thundering herd
|
|
138
|
-
const jitter = capped * config.jitterFactor * Math.random();
|
|
139
|
-
|
|
140
|
-
return Math.floor(capped + jitter);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Sleep utility.
|
|
145
|
-
*/
|
|
146
|
-
function sleep(ms: number): Promise<void> {
|
|
147
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { sleep };
|
package/src/client/sanitize.ts
DELETED
|
@@ -1,31 +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
|
-
const MAX_LEN = 1024;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Sanitize a single header value.
|
|
13
|
-
* - Removes control characters (0x00-0x1F, 0x7F)
|
|
14
|
-
* - Truncates to MAX_LEN
|
|
15
|
-
*/
|
|
16
|
-
export function sanitizeHeader(v: string): string {
|
|
17
|
-
return v.replace(/[\u0000-\u001F\u007F]/g, "").slice(0, MAX_LEN);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Sanitize all header values in a record.
|
|
22
|
-
* Mutates in place for performance.
|
|
23
|
-
*/
|
|
24
|
-
export function sanitizeHeaders(h: Record<string, string>): Record<string, string> {
|
|
25
|
-
for (const k in h) {
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(h, k) && h[k] !== undefined) {
|
|
27
|
-
h[k] = sanitizeHeader(h[k]);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return h;
|
|
31
|
-
}
|
package/src/client/timeout.ts
DELETED
|
@@ -1,59 +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
|
-
import { TimeoutError } from "../errors/index.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Wraps an async function with a timeout.
|
|
12
|
-
*
|
|
13
|
-
* The timeout is per-attempt, not global. This ensures that slow attempts
|
|
14
|
-
* don't consume the entire retry budget.
|
|
15
|
-
*
|
|
16
|
-
* @param fn - Function to execute (receives an AbortSignal)
|
|
17
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
18
|
-
* @param parentSignal - Optional parent AbortSignal for cancellation
|
|
19
|
-
*/
|
|
20
|
-
export async function withTimeout<T>(
|
|
21
|
-
fn: (signal: AbortSignal) => Promise<T>,
|
|
22
|
-
timeoutMs: number,
|
|
23
|
-
parentSignal?: AbortSignal
|
|
24
|
-
): Promise<T> {
|
|
25
|
-
const controller = new AbortController();
|
|
26
|
-
|
|
27
|
-
// Propagate parent abort
|
|
28
|
-
const onAbort = () => controller.abort();
|
|
29
|
-
parentSignal?.addEventListener("abort", onAbort, { once: true });
|
|
30
|
-
|
|
31
|
-
// Set timeout
|
|
32
|
-
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
return await fn(controller.signal);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
// If our timeout triggered the abort (not parent), throw TimeoutError
|
|
38
|
-
if (controller.signal.aborted && !parentSignal?.aborted) {
|
|
39
|
-
throw new TimeoutError(timeoutMs);
|
|
40
|
-
}
|
|
41
|
-
throw err;
|
|
42
|
-
} finally {
|
|
43
|
-
clearTimeout(timeoutId);
|
|
44
|
-
parentSignal?.removeEventListener("abort", onAbort);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates an AbortController that times out after the specified duration.
|
|
50
|
-
* Useful for creating deadline-aware operations.
|
|
51
|
-
*
|
|
52
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
53
|
-
* @returns AbortController that will abort after timeout
|
|
54
|
-
*/
|
|
55
|
-
export function createTimeoutController(timeoutMs: number): AbortController {
|
|
56
|
-
const controller = new AbortController();
|
|
57
|
-
setTimeout(() => controller.abort(), timeoutMs);
|
|
58
|
-
return controller;
|
|
59
|
-
}
|
package/src/errors/factory.ts
DELETED
|
@@ -1,140 +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
|
-
|
|
8
|
-
import {
|
|
9
|
-
AgentOsError,
|
|
10
|
-
UnauthorizedError,
|
|
11
|
-
ForbiddenError,
|
|
12
|
-
NotFoundError,
|
|
13
|
-
ConflictError,
|
|
14
|
-
ValidationError,
|
|
15
|
-
RateLimitError,
|
|
16
|
-
ServerError,
|
|
17
|
-
type FieldError,
|
|
18
|
-
type ErrorOptions,
|
|
19
|
-
} from "./index.js";
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates a typed error from an HTTP response.
|
|
23
|
-
*
|
|
24
|
-
* @param response - The fetch Response object
|
|
25
|
-
* @param body - Parsed JSON body (if available)
|
|
26
|
-
* @param requestPath - The original request path (for 404 errors)
|
|
27
|
-
*/
|
|
28
|
-
export function createErrorFromResponse(
|
|
29
|
-
response: Response,
|
|
30
|
-
body?: { code?: string; message?: string; detail?: string; title?: string; details?: unknown },
|
|
31
|
-
requestPath?: string
|
|
32
|
-
): AgentOsError {
|
|
33
|
-
const status = response.status;
|
|
34
|
-
const message =
|
|
35
|
-
body?.message ||
|
|
36
|
-
body?.detail ||
|
|
37
|
-
body?.title ||
|
|
38
|
-
response.statusText ||
|
|
39
|
-
`HTTP ${status}`;
|
|
40
|
-
const requestId = response.headers.get("x-request-id") ?? undefined;
|
|
41
|
-
const opts: ErrorOptions = {
|
|
42
|
-
requestId,
|
|
43
|
-
backendCode: body?.code,
|
|
44
|
-
details: body?.details,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
switch (status) {
|
|
48
|
-
case 401:
|
|
49
|
-
return new UnauthorizedError(message, opts);
|
|
50
|
-
|
|
51
|
-
case 403:
|
|
52
|
-
return new ForbiddenError(message, opts);
|
|
53
|
-
|
|
54
|
-
case 404:
|
|
55
|
-
return new NotFoundError(message, requestPath, opts);
|
|
56
|
-
|
|
57
|
-
case 409:
|
|
58
|
-
return new ConflictError(message, opts);
|
|
59
|
-
|
|
60
|
-
case 400:
|
|
61
|
-
case 422:
|
|
62
|
-
return new ValidationError(
|
|
63
|
-
message,
|
|
64
|
-
status as 400 | 422,
|
|
65
|
-
parseFieldErrors(body?.details),
|
|
66
|
-
opts
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
case 429:
|
|
70
|
-
const retryAfterHeader = response.headers.get("Retry-After");
|
|
71
|
-
let retryAfterMs: number | undefined;
|
|
72
|
-
|
|
73
|
-
if (retryAfterHeader) {
|
|
74
|
-
// Retry-After can be seconds or a date
|
|
75
|
-
const seconds = parseInt(retryAfterHeader, 10);
|
|
76
|
-
if (!isNaN(seconds)) {
|
|
77
|
-
retryAfterMs = seconds * 1000;
|
|
78
|
-
} else {
|
|
79
|
-
// Try parsing as date
|
|
80
|
-
const date = new Date(retryAfterHeader);
|
|
81
|
-
if (!isNaN(date.getTime())) {
|
|
82
|
-
retryAfterMs = Math.max(0, date.getTime() - Date.now());
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return new RateLimitError(message, retryAfterMs, opts);
|
|
88
|
-
|
|
89
|
-
default:
|
|
90
|
-
if (status >= 500) {
|
|
91
|
-
return new ServerError(message, status, opts);
|
|
92
|
-
}
|
|
93
|
-
// Fallback for unknown 4xx errors
|
|
94
|
-
return new ServerError(message, status, opts);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Parses field errors from various backend formats.
|
|
100
|
-
*/
|
|
101
|
-
function parseFieldErrors(details: unknown): FieldError[] | undefined {
|
|
102
|
-
if (!details || typeof details !== "object") {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Format 1: Array of { field, message } objects
|
|
107
|
-
if (Array.isArray(details)) {
|
|
108
|
-
const errors = details.filter(
|
|
109
|
-
(d): d is FieldError =>
|
|
110
|
-
typeof d === "object" &&
|
|
111
|
-
d !== null &&
|
|
112
|
-
typeof d.field === "string" &&
|
|
113
|
-
typeof d.message === "string"
|
|
114
|
-
);
|
|
115
|
-
return errors.length > 0 ? errors : undefined;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Format 2: { errors: [...] }
|
|
119
|
-
if ("errors" in details && Array.isArray((details as { errors: unknown }).errors)) {
|
|
120
|
-
return parseFieldErrors((details as { errors: unknown[] }).errors);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Format 3: { field: [messages] } (Rails/Django style)
|
|
124
|
-
const entries = Object.entries(details);
|
|
125
|
-
if (entries.every(([, v]) => Array.isArray(v))) {
|
|
126
|
-
const errors: FieldError[] = [];
|
|
127
|
-
for (const [field, messages] of entries) {
|
|
128
|
-
if (Array.isArray(messages)) {
|
|
129
|
-
for (const message of messages) {
|
|
130
|
-
if (typeof message === "string") {
|
|
131
|
-
errors.push({ field, message });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return errors.length > 0 ? errors : undefined;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return undefined;
|
|
140
|
-
}
|