@agent-os-sdk/client 0.9.26 → 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.
Files changed (209) hide show
  1. package/dist/client/AgentOsClient.d.ts +141 -0
  2. package/dist/client/AgentOsClient.d.ts.map +1 -0
  3. package/{src/client/AgentOsClient.ts → dist/client/AgentOsClient.js} +61 -105
  4. package/dist/client/HttpRequestBuilder.d.ts +50 -0
  5. package/dist/client/HttpRequestBuilder.d.ts.map +1 -0
  6. package/{src/client/HttpRequestBuilder.ts → dist/client/HttpRequestBuilder.js} +9 -41
  7. package/{src/client/OperationContext.ts → dist/client/OperationContext.d.ts} +6 -9
  8. package/dist/client/OperationContext.d.ts.map +1 -0
  9. package/dist/client/OperationContext.js +13 -0
  10. package/dist/client/OperationContextProvider.d.ts +54 -0
  11. package/dist/client/OperationContextProvider.d.ts.map +1 -0
  12. package/{src/client/OperationContextProvider.ts → dist/client/OperationContextProvider.js} +17 -35
  13. package/{src/client/auth.ts → dist/client/auth.d.ts} +29 -65
  14. package/dist/client/auth.d.ts.map +1 -0
  15. package/dist/client/auth.js +38 -0
  16. package/dist/client/config.d.ts +49 -0
  17. package/dist/client/config.d.ts.map +1 -0
  18. package/{src/client/config.ts → dist/client/config.js} +5 -43
  19. package/dist/client/helpers.d.ts +63 -0
  20. package/dist/client/helpers.d.ts.map +1 -0
  21. package/{src/client/helpers.ts → dist/client/helpers.js} +9 -52
  22. package/dist/client/pagination.d.ts +105 -0
  23. package/dist/client/pagination.d.ts.map +1 -0
  24. package/{src/client/pagination.ts → dist/client/pagination.js} +15 -116
  25. package/dist/client/raw.d.ts +277 -0
  26. package/dist/client/raw.d.ts.map +1 -0
  27. package/dist/client/raw.js +337 -0
  28. package/dist/client/retry.d.ts +37 -0
  29. package/dist/client/retry.d.ts.map +1 -0
  30. package/{src/client/retry.ts → dist/client/retry.js} +13 -55
  31. package/dist/client/sanitize.d.ts +19 -0
  32. package/dist/client/sanitize.d.ts.map +1 -0
  33. package/{src/client/sanitize.ts → dist/client/sanitize.js} +4 -7
  34. package/dist/client/timeout.d.ts +26 -0
  35. package/dist/client/timeout.d.ts.map +1 -0
  36. package/{src/client/timeout.ts → dist/client/timeout.js} +10 -18
  37. package/dist/errors/factory.d.ts +22 -0
  38. package/dist/errors/factory.d.ts.map +1 -0
  39. package/{src/errors/factory.ts → dist/errors/factory.js} +18 -57
  40. package/dist/errors/index.d.ts +210 -0
  41. package/dist/errors/index.d.ts.map +1 -0
  42. package/{src/errors/index.ts → dist/errors/index.js} +74 -156
  43. package/{src/generated/client.ts → dist/generated/client.d.ts} +5 -17
  44. package/dist/generated/client.d.ts.map +1 -0
  45. package/dist/generated/client.js +15 -0
  46. package/{src/generated/index.ts → dist/generated/index.d.ts} +1 -1
  47. package/dist/generated/index.d.ts.map +1 -0
  48. package/dist/generated/index.js +1 -0
  49. package/{src/generated/openapi.ts → dist/generated/openapi.d.ts} +1 -1
  50. package/dist/generated/openapi.d.ts.map +1 -0
  51. package/dist/generated/openapi.js +5 -0
  52. package/dist/index.d.ts +69 -0
  53. package/dist/index.d.ts.map +1 -0
  54. package/{src/index.ts → dist/index.js} +13 -63
  55. package/dist/modules/a2a.d.ts +48 -0
  56. package/dist/modules/a2a.d.ts.map +1 -0
  57. package/dist/modules/a2a.js +37 -0
  58. package/dist/modules/agents.d.ts +346 -0
  59. package/dist/modules/agents.d.ts.map +1 -0
  60. package/dist/modules/agents.js +296 -0
  61. package/dist/modules/apiTokens.d.ts +62 -0
  62. package/dist/modules/apiTokens.d.ts.map +1 -0
  63. package/dist/modules/apiTokens.js +56 -0
  64. package/dist/modules/approvals.d.ts +75 -0
  65. package/dist/modules/approvals.d.ts.map +1 -0
  66. package/dist/modules/approvals.js +91 -0
  67. package/dist/modules/audit.d.ts +78 -0
  68. package/dist/modules/audit.d.ts.map +1 -0
  69. package/{src/modules/audit.ts → dist/modules/audit.js} +23 -74
  70. package/{src/modules/auth.ts → dist/modules/auth.d.ts} +6 -11
  71. package/dist/modules/auth.d.ts.map +1 -0
  72. package/dist/modules/auth.js +22 -0
  73. package/dist/modules/builder.d.ts +242 -0
  74. package/dist/modules/builder.d.ts.map +1 -0
  75. package/dist/modules/builder.js +248 -0
  76. package/dist/modules/catalog.d.ts +142 -0
  77. package/dist/modules/catalog.d.ts.map +1 -0
  78. package/dist/modules/catalog.js +136 -0
  79. package/dist/modules/chatwoot.d.ts +59 -0
  80. package/dist/modules/chatwoot.d.ts.map +1 -0
  81. package/dist/modules/chatwoot.js +200 -0
  82. package/dist/modules/checkpoints.d.ts +62 -0
  83. package/dist/modules/checkpoints.d.ts.map +1 -0
  84. package/dist/modules/checkpoints.js +48 -0
  85. package/dist/modules/contracts.d.ts +48 -0
  86. package/dist/modules/contracts.d.ts.map +1 -0
  87. package/dist/modules/contracts.js +25 -0
  88. package/dist/modules/credentials.d.ts +105 -0
  89. package/dist/modules/credentials.d.ts.map +1 -0
  90. package/dist/modules/credentials.js +135 -0
  91. package/dist/modules/crons.d.ts +73 -0
  92. package/dist/modules/crons.d.ts.map +1 -0
  93. package/dist/modules/crons.js +67 -0
  94. package/dist/modules/datasets.d.ts +80 -0
  95. package/dist/modules/datasets.d.ts.map +1 -0
  96. package/dist/modules/datasets.js +91 -0
  97. package/{src/modules/evaluation.ts → dist/modules/evaluation.d.ts} +23 -109
  98. package/dist/modules/evaluation.d.ts.map +1 -0
  99. package/dist/modules/evaluation.js +108 -0
  100. package/dist/modules/files.d.ts +89 -0
  101. package/dist/modules/files.d.ts.map +1 -0
  102. package/dist/modules/files.js +133 -0
  103. package/dist/modules/graphs.d.ts +120 -0
  104. package/dist/modules/graphs.d.ts.map +1 -0
  105. package/dist/modules/graphs.js +69 -0
  106. package/{src/modules/improvements.ts → dist/modules/improvements.d.ts} +8 -27
  107. package/dist/modules/improvements.d.ts.map +1 -0
  108. package/dist/modules/improvements.js +27 -0
  109. package/dist/modules/info.d.ts +76 -0
  110. package/dist/modules/info.d.ts.map +1 -0
  111. package/{src/modules/info.ts → dist/modules/info.js} +16 -66
  112. package/dist/modules/knowledge.d.ts +91 -0
  113. package/dist/modules/knowledge.d.ts.map +1 -0
  114. package/dist/modules/knowledge.js +80 -0
  115. package/{src/modules/me.ts → dist/modules/me.d.ts} +7 -23
  116. package/dist/modules/me.d.ts.map +1 -0
  117. package/dist/modules/me.js +28 -0
  118. package/dist/modules/members.d.ts +124 -0
  119. package/dist/modules/members.d.ts.map +1 -0
  120. package/dist/modules/members.js +142 -0
  121. package/dist/modules/memberships.d.ts +25 -0
  122. package/dist/modules/memberships.d.ts.map +1 -0
  123. package/dist/modules/memberships.js +20 -0
  124. package/{src/modules/metaAgent.ts → dist/modules/metaAgent.d.ts} +8 -44
  125. package/dist/modules/metaAgent.d.ts.map +1 -0
  126. package/dist/modules/metaAgent.js +32 -0
  127. package/dist/modules/metrics.d.ts +20 -0
  128. package/dist/modules/metrics.d.ts.map +1 -0
  129. package/{src/modules/metrics.ts → dist/modules/metrics.js} +7 -14
  130. package/dist/modules/observability.d.ts +19 -0
  131. package/dist/modules/observability.d.ts.map +1 -0
  132. package/dist/modules/observability.js +14 -0
  133. package/dist/modules/playground.d.ts +42 -0
  134. package/dist/modules/playground.d.ts.map +1 -0
  135. package/dist/modules/playground.js +48 -0
  136. package/dist/modules/presets.d.ts +32 -0
  137. package/dist/modules/presets.d.ts.map +1 -0
  138. package/dist/modules/presets.js +199 -0
  139. package/dist/modules/prompts.d.ts +87 -0
  140. package/dist/modules/prompts.d.ts.map +1 -0
  141. package/dist/modules/prompts.js +87 -0
  142. package/dist/modules/roles.d.ts +64 -0
  143. package/dist/modules/roles.d.ts.map +1 -0
  144. package/dist/modules/roles.js +79 -0
  145. package/dist/modules/runs.d.ts +451 -0
  146. package/dist/modules/runs.d.ts.map +1 -0
  147. package/{src/modules/runs.ts → dist/modules/runs.js} +96 -438
  148. package/dist/modules/store.d.ts +37 -0
  149. package/dist/modules/store.d.ts.map +1 -0
  150. package/dist/modules/store.js +48 -0
  151. package/{src/modules/templates.ts → dist/modules/templates.d.ts} +8 -32
  152. package/dist/modules/templates.d.ts.map +1 -0
  153. package/dist/modules/templates.js +26 -0
  154. package/dist/modules/tenants.d.ts +49 -0
  155. package/dist/modules/tenants.d.ts.map +1 -0
  156. package/dist/modules/tenants.js +56 -0
  157. package/dist/modules/threads.d.ts +205 -0
  158. package/dist/modules/threads.d.ts.map +1 -0
  159. package/dist/modules/threads.js +225 -0
  160. package/dist/modules/tools.d.ts +62 -0
  161. package/dist/modules/tools.d.ts.map +1 -0
  162. package/dist/modules/tools.js +45 -0
  163. package/dist/modules/traces.d.ts +89 -0
  164. package/dist/modules/traces.d.ts.map +1 -0
  165. package/dist/modules/traces.js +65 -0
  166. package/{src/modules/triggers.ts → dist/modules/triggers.d.ts} +24 -153
  167. package/dist/modules/triggers.d.ts.map +1 -0
  168. package/dist/modules/triggers.js +176 -0
  169. package/{src/modules/usage.ts → dist/modules/usage.d.ts} +14 -46
  170. package/dist/modules/usage.d.ts.map +1 -0
  171. package/dist/modules/usage.js +43 -0
  172. package/dist/modules/vectorStores.d.ts +100 -0
  173. package/dist/modules/vectorStores.d.ts.map +1 -0
  174. package/dist/modules/vectorStores.js +159 -0
  175. package/dist/modules/workspaces.d.ts +138 -0
  176. package/dist/modules/workspaces.d.ts.map +1 -0
  177. package/dist/modules/workspaces.js +121 -0
  178. package/dist/sse/client.d.ts +140 -0
  179. package/dist/sse/client.d.ts.map +1 -0
  180. package/{src/sse/client.ts → dist/sse/client.js} +24 -100
  181. package/package.json +8 -15
  182. package/src/client/raw.ts +0 -609
  183. package/src/generated/swagger.json +0 -17014
  184. package/src/modules/a2a.ts +0 -64
  185. package/src/modules/agents.ts +0 -604
  186. package/src/modules/apiTokens.ts +0 -101
  187. package/src/modules/approvals.ts +0 -151
  188. package/src/modules/catalog.ts +0 -241
  189. package/src/modules/chatwoot.ts +0 -242
  190. package/src/modules/checkpoints.ts +0 -87
  191. package/src/modules/contracts.ts +0 -80
  192. package/src/modules/credentials.ts +0 -216
  193. package/src/modules/crons.ts +0 -115
  194. package/src/modules/datasets.ts +0 -142
  195. package/src/modules/files.ts +0 -208
  196. package/src/modules/members.ts +0 -199
  197. package/src/modules/memberships.ts +0 -42
  198. package/src/modules/observability.ts +0 -28
  199. package/src/modules/playground.ts +0 -68
  200. package/src/modules/presets.ts +0 -246
  201. package/src/modules/prompts.ts +0 -147
  202. package/src/modules/roles.ts +0 -112
  203. package/src/modules/store.ts +0 -65
  204. package/src/modules/tenants.ts +0 -79
  205. package/src/modules/threads.ts +0 -343
  206. package/src/modules/tools.ts +0 -91
  207. package/src/modules/traces.ts +0 -133
  208. package/src/modules/vectorStores.ts +0 -257
  209. package/src/modules/workspaces.ts +0 -216
package/src/client/raw.ts DELETED
@@ -1,609 +0,0 @@
1
- /**
2
- * Agent OS SDK - Raw HTTP Client
3
- *
4
- * Fully typed HTTP client using openapi-fetch with generated OpenAPI types.
5
- * All types are automatically inferred from the backend Swagger specification.
6
- */
7
-
8
- import createClient, { type Client } from "openapi-fetch";
9
- import type { components, paths } from "../generated/openapi.js";
10
- import { createErrorFromResponse } from "../errors/factory.js";
11
- import { AgentOsError, NetworkError, TimeoutError } from "../errors/index.js";
12
- import { httpRequestBuilder, sanitizeValidCorrelationId } from "./HttpRequestBuilder.js";
13
- import type { OperationContext } from "./OperationContext.js";
14
- import type { OperationContextProvider } from "./OperationContextProvider.js";
15
- import { mergeNetworkConfig, type NetworkConfig } from "./config.js";
16
- import { withRetry } from "./retry.js";
17
- import { withTimeout } from "./timeout.js";
18
-
19
- // Re-export types for external use
20
- export type { components, paths };
21
-
22
- export type ClientOptions = {
23
- baseUrl: string;
24
- headers?: Record<string, string>;
25
- headerProvider?: () => Promise<Record<string, string>>;
26
- /** Optional flow context provider (ALS/manual). */
27
- contextProvider?: OperationContextProvider;
28
- /** Network behavior (timeouts/retries). Defaults to DEFAULT_NETWORK_CONFIG. */
29
- network?: Partial<NetworkConfig>;
30
- /** Hooks for observability (OTEL, Sentry, etc.) */
31
- hooks?: SDKHooks;
32
- };
33
-
34
- /**
35
- * SDK hooks for external observability tools.
36
- * These are called during the request lifecycle for instrumentation.
37
- */
38
- export interface SDKHooks {
39
- /** Called before each request. Return modified request context or void. */
40
- onRequest?: (context: HookRequestContext) => void | Promise<void>;
41
- /** Called after each successful response */
42
- onResponse?: (context: HookResponseContext) => void | Promise<void>;
43
- /** Called on any error (network, timeout, HTTP error) */
44
- onError?: (context: HookErrorContext) => void | Promise<void>;
45
- /** Optional logger bridge used by SDK internal warnings. */
46
- logger?: { warn?: (message: string) => void };
47
- }
48
-
49
- export interface HookRequestContext {
50
- method: string;
51
- url: string;
52
- headers: Record<string, string>;
53
- body?: unknown;
54
- requestId?: string;
55
- }
56
-
57
- export interface HookResponseContext {
58
- method: string;
59
- url: string;
60
- status: number;
61
- durationMs: number;
62
- requestId?: string;
63
- }
64
-
65
- export interface HookErrorContext {
66
- method: string;
67
- url: string;
68
- error: Error;
69
- durationMs: number;
70
- requestId?: string;
71
- }
72
-
73
- /**
74
- * Standard API response wrapper.
75
- * This matches the pattern used by openapi-fetch.
76
- */
77
- export interface APIResponse<T> {
78
- data?: T;
79
- error?: {
80
- code: string;
81
- message: string;
82
- details?: unknown;
83
- };
84
- response: Response;
85
- /** Metadata for observability */
86
- meta?: {
87
- /** Request ID from x-request-id header */
88
- requestId?: string;
89
- };
90
- }
91
-
92
- /**
93
- * Typed API client using openapi-fetch.
94
- * All paths and responses are fully typed from OpenAPI spec.
95
- */
96
- export type TypedClient = Client<paths>;
97
-
98
- /**
99
- * Creates a typed HTTP client with openapi-fetch.
100
- * This provides full type inference for all API endpoints.
101
- */
102
- export function createTypedClient(options: ClientOptions): TypedClient {
103
- return createClient<paths>({
104
- baseUrl: options.baseUrl,
105
- headers: options.headers,
106
- });
107
- }
108
-
109
- /**
110
- * Legacy raw client interface (for backward compatibility).
111
- * Wraps openapi-fetch to provide the old interface while maintaining types.
112
- */
113
- export function createRawClient(options: ClientOptions) {
114
- const { baseUrl, headers: defaultHeaders = {}, headerProvider, contextProvider } = options;
115
- const networkConfig = mergeNetworkConfig(options.network);
116
- const warn = (message: string): void => {
117
- const hookWarn = options.hooks?.logger?.warn;
118
- if (typeof hookWarn === "function") {
119
- hookWarn(message);
120
- return;
121
- }
122
- if (typeof console !== "undefined" && typeof console.warn === "function") {
123
- console.warn(message);
124
- }
125
- };
126
- // Sticky fallback context for clients that don't provide per-operation context.
127
- const fallbackContext: OperationContext = Object.freeze({
128
- correlationId: crypto.randomUUID(),
129
- });
130
- let warnedStickyFallbackContext = false;
131
- let warnedInvalidContextCorrelation = false;
132
- const resolveEffectiveContext = (optsContext?: OperationContext): OperationContext => {
133
- const providerContext = contextProvider?.get();
134
- const usingStickyFallback = !optsContext && !providerContext;
135
- if (usingStickyFallback && !contextProvider && !warnedStickyFallbackContext) {
136
- warnedStickyFallbackContext = true;
137
- warn(
138
- "[AgentOS SDK] Using sticky fallback correlation context per client instance. " +
139
- "For long-lived server clients, configure contextProvider (ALS/manual) to scope correlation per request."
140
- );
141
- }
142
-
143
- const effectiveContext = optsContext ?? providerContext ?? fallbackContext;
144
- const correlationProvidedByCaller =
145
- effectiveContext !== fallbackContext
146
- && typeof effectiveContext?.correlationId === "string";
147
-
148
- if (correlationProvidedByCaller) {
149
- const validCorrelation = sanitizeValidCorrelationId(effectiveContext.correlationId);
150
- if (!validCorrelation) {
151
- if (!warnedInvalidContextCorrelation) {
152
- warnedInvalidContextCorrelation = true;
153
- warn(
154
- "[AgentOS SDK] Invalid correlationId in operation context ignored; generated fallback correlation id. " +
155
- "Provide a valid correlationId (8-128 chars: A-Za-z0-9._:-)."
156
- );
157
- }
158
- // Caller provided invalid flow id: use per-request fallback (not sticky fallback context).
159
- return {
160
- ...effectiveContext,
161
- correlationId: crypto.randomUUID(),
162
- };
163
- }
164
-
165
- if (validCorrelation !== effectiveContext.correlationId) {
166
- return {
167
- ...effectiveContext,
168
- correlationId: validCorrelation,
169
- };
170
- }
171
- }
172
-
173
- return effectiveContext;
174
- };
175
- type ErrorPayload = { code?: string; message?: string; details?: unknown } & Record<string, unknown>;
176
- type HttpAgentOsError = AgentOsError & {
177
- response?: Response;
178
- payload?: ErrorPayload;
179
- };
180
-
181
- async function request<T>(
182
- method: string,
183
- path: string,
184
- opts?: {
185
- params?: { path?: Record<string, string>; query?: Record<string, unknown> };
186
- body?: unknown;
187
- headers?: Record<string, string>;
188
- signal?: AbortSignal;
189
- /** Set to false to disable retry for this request */
190
- retry?: boolean;
191
- /** Override timeout for this request */
192
- timeoutMs?: number;
193
- /** Operation context for flow tracing */
194
- context?: OperationContext;
195
- /** Idempotency key for POST requests */
196
- idempotencyKey?: string;
197
- /** Require correlation ID (throws if missing) */
198
- requireFlow?: boolean;
199
- }
200
- ): Promise<APIResponse<T>> {
201
- // Replace path params
202
- let url = path;
203
- if (opts?.params?.path) {
204
- for (const [key, value] of Object.entries(opts.params.path)) {
205
- url = url.replace(`{${key}}`, encodeURIComponent(value));
206
- // Also handle {id} pattern common in our API
207
- url = url.replace(`{id}`, encodeURIComponent(value));
208
- }
209
- }
210
-
211
- // Build query string
212
- if (opts?.params?.query) {
213
- const query = new URLSearchParams();
214
- for (const [key, value] of Object.entries(opts.params.query)) {
215
- if (value !== undefined && value !== null) {
216
- query.append(key, String(value));
217
- }
218
- }
219
- const queryStr = query.toString();
220
- if (queryStr) {
221
- url += `?${queryStr}`;
222
- }
223
- }
224
-
225
- const fullUrl = `${baseUrl}${url}`;
226
-
227
- // Resolve dynamic headers (e.g. auth)
228
- const dynamicHeaders = headerProvider ? await headerProvider() : {};
229
-
230
- const headers: Record<string, string> = {
231
- ...defaultHeaders,
232
- ...dynamicHeaders,
233
- ...opts?.headers,
234
- };
235
-
236
- if (opts?.body) {
237
- headers["Content-Type"] = "application/json";
238
- }
239
-
240
- const effectiveContext = resolveEffectiveContext(opts?.context);
241
-
242
- // Build standard headers via HttpRequestBuilder (single source of truth)
243
- const builderHeaders = httpRequestBuilder.build({
244
- context: effectiveContext,
245
- idempotencyKey: opts?.idempotencyKey,
246
- requireFlow: opts?.requireFlow,
247
- });
248
-
249
- // Merge builder headers (X-Request-Id, X-Correlation-Id, X-Idempotency-Key, User-Agent)
250
- Object.assign(headers, builderHeaders);
251
-
252
- // Use X-Request-Id from builder as client request ID
253
- const clientRequestId = headers["X-Request-Id"];
254
-
255
- // Call onRequest hook
256
- const startTime = Date.now();
257
- await options.hooks?.onRequest?.({
258
- method,
259
- url: fullUrl,
260
- headers,
261
- body: opts?.body,
262
- requestId: clientRequestId,
263
- });
264
-
265
- // Execute the actual fetch
266
- const doFetch = async (signal?: AbortSignal): Promise<Response> => {
267
- return fetch(fullUrl, {
268
- method,
269
- headers,
270
- body: opts?.body ? JSON.stringify(opts.body) : undefined,
271
- signal,
272
- });
273
- };
274
-
275
- let response: Response;
276
- try {
277
- const hasIdempotencyKey = Boolean(
278
- opts?.idempotencyKey ||
279
- headers["X-Idempotency-Key"] ||
280
- headers["Idempotency-Key"]
281
- );
282
-
283
- const executeAttempt = async (signal?: AbortSignal): Promise<Response> => {
284
- const attemptResponse = await withTimeout(async (timeoutSignal) => {
285
- try {
286
- return await doFetch(timeoutSignal);
287
- } catch (fetchError) {
288
- // Preserve AbortError semantics for caller-provided cancellation.
289
- if (fetchError instanceof Error && fetchError.name === "AbortError") {
290
- throw fetchError;
291
- }
292
-
293
- throw new NetworkError(
294
- fetchError instanceof Error ? fetchError.message : "Network request failed",
295
- fetchError instanceof Error ? fetchError : undefined
296
- );
297
- }
298
- }, opts?.timeoutMs ?? networkConfig.timeoutMs, signal);
299
-
300
- if (!attemptResponse.ok) {
301
- let errorBody: ErrorPayload | undefined;
302
- try {
303
- errorBody = await attemptResponse.json() as ErrorPayload;
304
- } catch {
305
- // Ignore JSON parse errors and fallback to status text.
306
- }
307
-
308
- const typedError = createErrorFromResponse(attemptResponse, errorBody, path) as HttpAgentOsError;
309
- typedError.response = attemptResponse;
310
- typedError.payload = errorBody;
311
- throw typedError;
312
- }
313
-
314
- return attemptResponse;
315
- };
316
-
317
- if (opts?.retry === false) {
318
- response = await executeAttempt(opts?.signal);
319
- } else {
320
- response = await withRetry(
321
- (signal) => executeAttempt(signal),
322
- networkConfig.retry,
323
- { method, hasIdempotencyKey },
324
- opts?.signal
325
- );
326
- }
327
- } catch (requestError) {
328
- const durationMs = Date.now() - startTime;
329
- const error = requestError instanceof Error ? requestError : new Error(String(requestError));
330
- const typedError = requestError instanceof AgentOsError ? requestError as HttpAgentOsError : undefined;
331
- const errorResponse = typedError?.response;
332
- const requestId = errorResponse?.headers.get("x-request-id")
333
- ?? typedError?.requestId
334
- ?? clientRequestId;
335
-
336
- // Call onError hook
337
- await options.hooks?.onError?.({
338
- method,
339
- url: fullUrl,
340
- error,
341
- durationMs,
342
- requestId,
343
- });
344
-
345
- if (typedError && errorResponse) {
346
- return {
347
- error: {
348
- code: typedError.backendCode || typedError.code,
349
- message: typedError.message,
350
- details: typedError.details,
351
- // Include full payload for validation hints and backend-specific fields.
352
- ...typedError.payload,
353
- },
354
- response: errorResponse,
355
- meta: { requestId },
356
- };
357
- }
358
-
359
- if (error instanceof TimeoutError) {
360
- return {
361
- error: {
362
- code: error.code,
363
- message: error.message,
364
- },
365
- response: new Response(null, { status: 408, statusText: "Request Timeout" }),
366
- meta: { requestId },
367
- };
368
- }
369
-
370
- // Network/abort/unexpected errors - return as standardized transport error.
371
- return {
372
- error: {
373
- code: "NETWORK_ERROR",
374
- message: error.message || "Network request failed"
375
- },
376
- response: new Response(null, { status: 503, statusText: "Network Error" }),
377
- meta: { requestId },
378
- };
379
- }
380
-
381
- const durationMs = Date.now() - startTime;
382
-
383
- // Extract requestId for tracing (prefer server requestId if available)
384
- const requestId = response.headers.get("x-request-id") ?? clientRequestId;
385
-
386
- // Call onResponse hook
387
- await options.hooks?.onResponse?.({
388
- method,
389
- url: fullUrl,
390
- status: response.status,
391
- durationMs,
392
- requestId,
393
- });
394
-
395
- // Handle no-content responses
396
- if (response.status === 204) {
397
- return { data: undefined as T, response, meta: { requestId } };
398
- }
399
-
400
- try {
401
- const data = await response.json();
402
- return { data: data as T, response, meta: { requestId } };
403
- } catch {
404
- return { data: undefined as T, response, meta: { requestId } };
405
- }
406
- }
407
-
408
- return {
409
- GET: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
410
- request<T>("GET", path, opts),
411
- POST: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
412
- request<T>("POST", path, opts),
413
- PUT: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
414
- request<T>("PUT", path, opts),
415
- PATCH: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
416
- request<T>("PATCH", path, opts),
417
- DELETE: <T>(path: string, opts?: Parameters<typeof request>[2]) =>
418
- request<T>("DELETE", path, opts),
419
-
420
- /**
421
- * Stream GET request - returns raw Response for SSE consumption.
422
- * Headers are resolved asynchronously (includes Auth + Workspace).
423
- */
424
- streamGet: async (
425
- path: string,
426
- opts?: {
427
- params?: { path?: Record<string, string>; query?: Record<string, unknown> };
428
- headers?: Record<string, string>;
429
- context?: OperationContext;
430
- requireFlow?: boolean;
431
- signal?: AbortSignal;
432
- }
433
- ): Promise<Response> => {
434
- let url = path;
435
- if (opts?.params?.path) {
436
- for (const [key, value] of Object.entries(opts.params.path)) {
437
- url = url.replace(`{${key}}`, encodeURIComponent(value));
438
- }
439
- }
440
- if (opts?.params?.query) {
441
- const query = new URLSearchParams();
442
- for (const [key, value] of Object.entries(opts.params.query)) {
443
- if (value !== undefined && value !== null) {
444
- query.append(key, String(value));
445
- }
446
- }
447
- const queryStr = query.toString();
448
- if (queryStr) url += `?${queryStr}`;
449
- }
450
- const fullUrl = `${baseUrl}${url}`;
451
- const dynamicHeaders = headerProvider ? await headerProvider() : {};
452
- const effectiveContext = resolveEffectiveContext(opts?.context);
453
- const builderHeaders = httpRequestBuilder.build({
454
- context: effectiveContext,
455
- requireFlow: opts?.requireFlow,
456
- });
457
- const headers: Record<string, string> = {
458
- ...defaultHeaders,
459
- ...dynamicHeaders,
460
- ...builderHeaders,
461
- Accept: "text/event-stream",
462
- ...opts?.headers,
463
- };
464
- return fetch(fullUrl, { method: "GET", headers, signal: opts?.signal });
465
- },
466
-
467
- /**
468
- * Stream POST request - returns raw Response for SSE consumption.
469
- * Headers are resolved asynchronously (includes Auth + Workspace).
470
- */
471
- streamPost: async (
472
- path: string,
473
- opts?: {
474
- params?: { path?: Record<string, string> };
475
- body?: unknown;
476
- headers?: Record<string, string>;
477
- signal?: AbortSignal;
478
- context?: OperationContext;
479
- idempotencyKey?: string;
480
- requireFlow?: boolean;
481
- }
482
- ): Promise<Response> => {
483
- let url = path;
484
- if (opts?.params?.path) {
485
- for (const [key, value] of Object.entries(opts.params.path)) {
486
- url = url.replace(`{${key}}`, encodeURIComponent(value));
487
- }
488
- }
489
- const fullUrl = `${baseUrl}${url}`;
490
- const dynamicHeaders = headerProvider ? await headerProvider() : {};
491
- const effectiveContext = resolveEffectiveContext(opts?.context);
492
- const builderHeaders = httpRequestBuilder.build({
493
- context: effectiveContext,
494
- idempotencyKey: opts?.idempotencyKey,
495
- requireFlow: opts?.requireFlow,
496
- });
497
- const headers: Record<string, string> = {
498
- ...defaultHeaders,
499
- ...dynamicHeaders,
500
- ...builderHeaders,
501
- "Content-Type": "application/json",
502
- Accept: "text/event-stream",
503
- ...opts?.headers,
504
- };
505
- return fetch(fullUrl, {
506
- method: "POST",
507
- headers,
508
- body: opts?.body ? JSON.stringify(opts.body) : undefined,
509
- signal: opts?.signal,
510
- });
511
- },
512
-
513
- /** Base URL for constructing full URLs when needed */
514
- baseUrl,
515
- };
516
- }
517
-
518
- export type RawClient = ReturnType<typeof createRawClient>;
519
-
520
- // ============================================================================
521
- // Convenience type exports from OpenAPI schemas
522
- // ============================================================================
523
-
524
- // Agent types
525
- export type Agent = components["schemas"]["AgentExportAgent"];
526
- export type CreateAgentRequest = components["schemas"]["CreateAgentRequest"];
527
- export type UpdateAgentRequest = components["schemas"]["UpdateAgentRequest"];
528
- export type AgentBundle = components["schemas"]["AgentExportBundle"];
529
- export type AgentBundleItem = components["schemas"]["AgentBundleItem"];
530
-
531
- // Run types
532
- export type RunResponse = components["schemas"]["RunResponse"];
533
- export type RunDetailResponse = components["schemas"]["RunDetailResponse"];
534
- export type CreateRunRequest = components["schemas"]["CreateRunRequest"];
535
- export type WaitRunRequest = components["schemas"]["WaitRunRequest"];
536
- export type WaitRunResponse = components["schemas"]["WaitRunResponse"];
537
- export type BatchRunRequest = components["schemas"]["BatchRunRequest"];
538
- export type BatchRunResponse = components["schemas"]["BatchRunResponse"];
539
- export type ReplayRequest = components["schemas"]["ReplayRequest"];
540
- export type RunReplayRequest = components["schemas"]["RunReplayRequest"];
541
- export type RunReplayResponse = components["schemas"]["RunReplayResponse"];
542
- export type CancelRequest = components["schemas"]["CancelRequest"];
543
- export type CancelRunResponse = components["schemas"]["CancelRunResponse"];
544
-
545
- // Thread types
546
- export type ThreadRequest = components["schemas"]["ThreadRequest"];
547
- export type ThreadSearchRequest = components["schemas"]["ThreadSearchRequest"];
548
- export type ThreadCopyRequest = components["schemas"]["ThreadCopyRequest"];
549
- export type ThreadPruneRequest = components["schemas"]["ThreadPruneRequest"];
550
- export type AddMessageRequest = components["schemas"]["AddMessageRequest"];
551
-
552
- // Checkpoint types
553
- export type CheckpointDetail = components["schemas"]["CheckpointDetail"];
554
- export type CheckpointNode = components["schemas"]["CheckpointNode"];
555
- export type CheckpointListResponse = components["schemas"]["CheckpointListResponse"];
556
- export type CheckpointIndexResponse = components["schemas"]["CheckpointIndexResponse"];
557
- export type CreateCheckpointRequest = components["schemas"]["CreateCheckpointRequest"];
558
-
559
- // Credential types
560
- export type CreateCredentialRequest = components["schemas"]["CreateCredentialRequest"];
561
- export type UpdateCredentialRequest = components["schemas"]["UpdateCredentialRequest"];
562
-
563
- // Evaluation types
564
- export type CreateDatasetRequest = components["schemas"]["CreateDatasetRequest"];
565
- export type CreateExperimentRequest = components["schemas"]["CreateExperimentRequest"];
566
- export type ExampleData = components["schemas"]["ExampleData"];
567
- export type AddExamplesRequest = components["schemas"]["AddExamplesRequest"];
568
-
569
- // Vector Store types
570
- export type VectorStoreResponse = components["schemas"]["VectorStoreResponse"];
571
- export type VectorQueryRequest = components["schemas"]["VectorQueryRequest"];
572
- export type VectorQueryResponse = components["schemas"]["VectorQueryResponse"];
573
- export type VectorSearchResult = components["schemas"]["VectorSearchResult"];
574
- export type VectorStoreFileResponse = components["schemas"]["VectorStoreFileResponse"];
575
-
576
- // Cron types
577
- export type CreateCronJobRequest = components["schemas"]["CreateCronJobRequest"];
578
- export type UpdateCronJobRequest = components["schemas"]["UpdateCronJobRequest"];
579
-
580
- // Member types
581
- export type InviteMemberRequest = components["schemas"]["InviteMemberRequest"];
582
- export type UpdateMemberRequest = components["schemas"]["UpdateMemberRequest"];
583
-
584
- // Tenant/Workspace types
585
- export type UpdateTenantRequest = components["schemas"]["UpdateTenantRequest"];
586
- export type UpdateWorkspaceRequest = components["schemas"]["UpdateWorkspaceRequest"];
587
-
588
- // Prompt types
589
- export type CreatePromptRequest = components["schemas"]["CreatePromptRequest"];
590
- export type CreatePromptVersionRequest = components["schemas"]["CreatePromptVersionRequest"];
591
-
592
- // File types
593
- export type CreatePresignedUploadRequest = components["schemas"]["CreatePresignedUploadRequest"];
594
- export type PresignedUploadResponse = components["schemas"]["PresignedUploadResponse"];
595
- export type ConfirmUploadRequest = components["schemas"]["ConfirmUploadRequest"];
596
-
597
- // Trace types
598
- export type SpanData = components["schemas"]["SpanData"];
599
- export type BatchIngestRequest = components["schemas"]["BatchIngestRequest"];
600
- export type AddFeedbackRequest = components["schemas"]["AddFeedbackRequest"];
601
-
602
- // Trigger types
603
- export type UpdateTriggerRequest = components["schemas"]["UpdateTriggerRequest"];
604
-
605
- // Store types
606
- export type StoreValueRequest = components["schemas"]["StoreValueRequest"];
607
-
608
- // Problem details (errors)
609
- export type ProblemDetails = components["schemas"]["ProblemDetails"];