@agent-os-sdk/client 0.9.24 → 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 (185) hide show
  1. package/package.json +15 -8
  2. package/src/generated/openapi.ts +90 -0
  3. package/src/generated/swagger.json +181 -0
  4. package/src/modules/runs.ts +64 -0
  5. package/src/modules/templates.ts +35 -0
  6. package/dist/client/AgentOsClient.d.ts +0 -141
  7. package/dist/client/AgentOsClient.d.ts.map +0 -1
  8. package/dist/client/AgentOsClient.js +0 -250
  9. package/dist/client/HttpRequestBuilder.d.ts +0 -50
  10. package/dist/client/HttpRequestBuilder.d.ts.map +0 -1
  11. package/dist/client/HttpRequestBuilder.js +0 -83
  12. package/dist/client/OperationContext.d.ts +0 -19
  13. package/dist/client/OperationContext.d.ts.map +0 -1
  14. package/dist/client/OperationContext.js +0 -13
  15. package/dist/client/OperationContextProvider.d.ts +0 -54
  16. package/dist/client/OperationContextProvider.d.ts.map +0 -1
  17. package/dist/client/OperationContextProvider.js +0 -71
  18. package/dist/client/auth.d.ts +0 -100
  19. package/dist/client/auth.d.ts.map +0 -1
  20. package/dist/client/auth.js +0 -38
  21. package/dist/client/config.d.ts +0 -49
  22. package/dist/client/config.d.ts.map +0 -1
  23. package/dist/client/config.js +0 -62
  24. package/dist/client/helpers.d.ts +0 -63
  25. package/dist/client/helpers.d.ts.map +0 -1
  26. package/dist/client/helpers.js +0 -55
  27. package/dist/client/pagination.d.ts +0 -105
  28. package/dist/client/pagination.d.ts.map +0 -1
  29. package/dist/client/pagination.js +0 -117
  30. package/dist/client/raw.d.ts +0 -277
  31. package/dist/client/raw.d.ts.map +0 -1
  32. package/dist/client/raw.js +0 -337
  33. package/dist/client/retry.d.ts +0 -37
  34. package/dist/client/retry.d.ts.map +0 -1
  35. package/dist/client/retry.js +0 -108
  36. package/dist/client/sanitize.d.ts +0 -19
  37. package/dist/client/sanitize.d.ts.map +0 -1
  38. package/dist/client/sanitize.js +0 -28
  39. package/dist/client/timeout.d.ts +0 -26
  40. package/dist/client/timeout.d.ts.map +0 -1
  41. package/dist/client/timeout.js +0 -51
  42. package/dist/errors/factory.d.ts +0 -22
  43. package/dist/errors/factory.d.ts.map +0 -1
  44. package/dist/errors/factory.js +0 -101
  45. package/dist/errors/index.d.ts +0 -210
  46. package/dist/errors/index.d.ts.map +0 -1
  47. package/dist/errors/index.js +0 -283
  48. package/dist/generated/client.d.ts +0 -20
  49. package/dist/generated/client.d.ts.map +0 -1
  50. package/dist/generated/client.js +0 -15
  51. package/dist/generated/index.d.ts +0 -2
  52. package/dist/generated/index.d.ts.map +0 -1
  53. package/dist/generated/index.js +0 -1
  54. package/dist/generated/openapi.d.ts +0 -12294
  55. package/dist/generated/openapi.d.ts.map +0 -1
  56. package/dist/generated/openapi.js +0 -5
  57. package/dist/index.d.ts +0 -69
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/index.js +0 -81
  60. package/dist/modules/a2a.d.ts +0 -48
  61. package/dist/modules/a2a.d.ts.map +0 -1
  62. package/dist/modules/a2a.js +0 -37
  63. package/dist/modules/agents.d.ts +0 -346
  64. package/dist/modules/agents.d.ts.map +0 -1
  65. package/dist/modules/agents.js +0 -296
  66. package/dist/modules/apiTokens.d.ts +0 -62
  67. package/dist/modules/apiTokens.d.ts.map +0 -1
  68. package/dist/modules/apiTokens.js +0 -56
  69. package/dist/modules/approvals.d.ts +0 -75
  70. package/dist/modules/approvals.d.ts.map +0 -1
  71. package/dist/modules/approvals.js +0 -91
  72. package/dist/modules/audit.d.ts +0 -78
  73. package/dist/modules/audit.d.ts.map +0 -1
  74. package/dist/modules/audit.js +0 -94
  75. package/dist/modules/auth.d.ts +0 -28
  76. package/dist/modules/auth.d.ts.map +0 -1
  77. package/dist/modules/auth.js +0 -22
  78. package/dist/modules/builder.d.ts +0 -242
  79. package/dist/modules/builder.d.ts.map +0 -1
  80. package/dist/modules/builder.js +0 -248
  81. package/dist/modules/catalog.d.ts +0 -142
  82. package/dist/modules/catalog.d.ts.map +0 -1
  83. package/dist/modules/catalog.js +0 -136
  84. package/dist/modules/chatwoot.d.ts +0 -59
  85. package/dist/modules/chatwoot.d.ts.map +0 -1
  86. package/dist/modules/chatwoot.js +0 -200
  87. package/dist/modules/checkpoints.d.ts +0 -62
  88. package/dist/modules/checkpoints.d.ts.map +0 -1
  89. package/dist/modules/checkpoints.js +0 -48
  90. package/dist/modules/contracts.d.ts +0 -48
  91. package/dist/modules/contracts.d.ts.map +0 -1
  92. package/dist/modules/contracts.js +0 -25
  93. package/dist/modules/credentials.d.ts +0 -105
  94. package/dist/modules/credentials.d.ts.map +0 -1
  95. package/dist/modules/credentials.js +0 -135
  96. package/dist/modules/crons.d.ts +0 -73
  97. package/dist/modules/crons.d.ts.map +0 -1
  98. package/dist/modules/crons.js +0 -67
  99. package/dist/modules/datasets.d.ts +0 -80
  100. package/dist/modules/datasets.d.ts.map +0 -1
  101. package/dist/modules/datasets.js +0 -91
  102. package/dist/modules/evaluation.d.ts +0 -183
  103. package/dist/modules/evaluation.d.ts.map +0 -1
  104. package/dist/modules/evaluation.js +0 -108
  105. package/dist/modules/files.d.ts +0 -89
  106. package/dist/modules/files.d.ts.map +0 -1
  107. package/dist/modules/files.js +0 -133
  108. package/dist/modules/graphs.d.ts +0 -120
  109. package/dist/modules/graphs.d.ts.map +0 -1
  110. package/dist/modules/graphs.js +0 -69
  111. package/dist/modules/improvements.d.ts +0 -52
  112. package/dist/modules/improvements.d.ts.map +0 -1
  113. package/dist/modules/improvements.js +0 -27
  114. package/dist/modules/info.d.ts +0 -76
  115. package/dist/modules/info.d.ts.map +0 -1
  116. package/dist/modules/info.js +0 -93
  117. package/dist/modules/knowledge.d.ts +0 -91
  118. package/dist/modules/knowledge.d.ts.map +0 -1
  119. package/dist/modules/knowledge.js +0 -80
  120. package/dist/modules/me.d.ts +0 -58
  121. package/dist/modules/me.d.ts.map +0 -1
  122. package/dist/modules/me.js +0 -28
  123. package/dist/modules/members.d.ts +0 -124
  124. package/dist/modules/members.d.ts.map +0 -1
  125. package/dist/modules/members.js +0 -142
  126. package/dist/modules/memberships.d.ts +0 -25
  127. package/dist/modules/memberships.d.ts.map +0 -1
  128. package/dist/modules/memberships.js +0 -20
  129. package/dist/modules/metaAgent.d.ts +0 -95
  130. package/dist/modules/metaAgent.d.ts.map +0 -1
  131. package/dist/modules/metaAgent.js +0 -32
  132. package/dist/modules/metrics.d.ts +0 -20
  133. package/dist/modules/metrics.d.ts.map +0 -1
  134. package/dist/modules/metrics.js +0 -27
  135. package/dist/modules/observability.d.ts +0 -19
  136. package/dist/modules/observability.d.ts.map +0 -1
  137. package/dist/modules/observability.js +0 -14
  138. package/dist/modules/playground.d.ts +0 -42
  139. package/dist/modules/playground.d.ts.map +0 -1
  140. package/dist/modules/playground.js +0 -48
  141. package/dist/modules/presets.d.ts +0 -32
  142. package/dist/modules/presets.d.ts.map +0 -1
  143. package/dist/modules/presets.js +0 -199
  144. package/dist/modules/prompts.d.ts +0 -87
  145. package/dist/modules/prompts.d.ts.map +0 -1
  146. package/dist/modules/prompts.js +0 -87
  147. package/dist/modules/roles.d.ts +0 -64
  148. package/dist/modules/roles.d.ts.map +0 -1
  149. package/dist/modules/roles.js +0 -79
  150. package/dist/modules/runs.d.ts +0 -400
  151. package/dist/modules/runs.d.ts.map +0 -1
  152. package/dist/modules/runs.js +0 -526
  153. package/dist/modules/store.d.ts +0 -37
  154. package/dist/modules/store.d.ts.map +0 -1
  155. package/dist/modules/store.js +0 -48
  156. package/dist/modules/templates.d.ts +0 -28
  157. package/dist/modules/templates.d.ts.map +0 -1
  158. package/dist/modules/templates.js +0 -19
  159. package/dist/modules/tenants.d.ts +0 -49
  160. package/dist/modules/tenants.d.ts.map +0 -1
  161. package/dist/modules/tenants.js +0 -56
  162. package/dist/modules/threads.d.ts +0 -205
  163. package/dist/modules/threads.d.ts.map +0 -1
  164. package/dist/modules/threads.js +0 -225
  165. package/dist/modules/tools.d.ts +0 -62
  166. package/dist/modules/tools.d.ts.map +0 -1
  167. package/dist/modules/tools.js +0 -45
  168. package/dist/modules/traces.d.ts +0 -89
  169. package/dist/modules/traces.d.ts.map +0 -1
  170. package/dist/modules/traces.js +0 -65
  171. package/dist/modules/triggers.d.ts +0 -228
  172. package/dist/modules/triggers.d.ts.map +0 -1
  173. package/dist/modules/triggers.js +0 -176
  174. package/dist/modules/usage.d.ts +0 -85
  175. package/dist/modules/usage.d.ts.map +0 -1
  176. package/dist/modules/usage.js +0 -43
  177. package/dist/modules/vectorStores.d.ts +0 -100
  178. package/dist/modules/vectorStores.d.ts.map +0 -1
  179. package/dist/modules/vectorStores.js +0 -159
  180. package/dist/modules/workspaces.d.ts +0 -138
  181. package/dist/modules/workspaces.d.ts.map +0 -1
  182. package/dist/modules/workspaces.js +0 -121
  183. package/dist/sse/client.d.ts +0 -140
  184. package/dist/sse/client.d.ts.map +0 -1
  185. package/dist/sse/client.js +0 -103
@@ -1,526 +0,0 @@
1
- /**
2
- * Runs Module - Core execution API (Fully Typed)
3
- *
4
- * Naming conventions:
5
- * - get* for singular items
6
- * - list* for collections
7
- * - create*, update*, delete* for mutations
8
- */
9
- import { parseSSE } from "../sse/client.js";
10
- export class RunsModule {
11
- client;
12
- constructor(client) {
13
- this.client = client;
14
- }
15
- // ======================== CRUD ========================
16
- /**
17
- * Create a new run.
18
- * @example
19
- * ```ts
20
- * const { data } = await client.runs.create({
21
- * agent_id: "agent-uuid",
22
- * input: { message: "Hello" }
23
- * });
24
- *
25
- * // With idempotency (safe to retry)
26
- * const { data } = await client.runs.create({
27
- * agent_id: "agent-uuid",
28
- * input: { message: "Hello" },
29
- * idempotency_key: "my-unique-key"
30
- * });
31
- * ```
32
- */
33
- async create(body) {
34
- // Send canonical X-Idempotency-Key header + body idempotency_key for backend contract parity.
35
- const headers = {};
36
- if (body.idempotency_key) {
37
- headers["X-Idempotency-Key"] = body.idempotency_key;
38
- }
39
- return this.client.POST("/v1/api/runs", {
40
- body,
41
- headers,
42
- });
43
- }
44
- /**
45
- * Get a run by ID.
46
- */
47
- async get(runId) {
48
- return this.client.GET("/v1/api/runs/{runId}", {
49
- params: { path: { runId } },
50
- });
51
- }
52
- async getInspection(runId) {
53
- return this.client.GET("/v1/api/runs/{runId}/inspection", {
54
- params: { path: { runId } },
55
- });
56
- }
57
- /**
58
- * List runs with optional filters.
59
- */
60
- async list(params) {
61
- return this.client.GET("/v1/api/runs", {
62
- params: { query: params },
63
- });
64
- }
65
- /**
66
- * Iterate through all runs with automatic pagination.
67
- *
68
- * @example
69
- * ```ts
70
- * // Stream all completed runs
71
- * for await (const run of client.runs.iterate({ status: "completed" })) {
72
- * console.log(run.run_id, run.status);
73
- * }
74
- *
75
- * // With limit
76
- * for await (const run of client.runs.iterate({ agent_id: "..." }, { maxItems: 100 })) {
77
- * processRun(run);
78
- * }
79
- * ```
80
- */
81
- async *iterate(filters, options) {
82
- const pageSize = options?.pageSize ?? 100;
83
- const maxItems = options?.maxItems ?? Infinity;
84
- let offset = 0;
85
- let yielded = 0;
86
- let hasMore = true;
87
- while (hasMore && yielded < maxItems) {
88
- if (options?.signal?.aborted)
89
- return;
90
- const response = await this.list({
91
- ...filters,
92
- limit: Math.min(pageSize, maxItems - yielded),
93
- offset,
94
- });
95
- if (response.error)
96
- throw response.error;
97
- const data = response.data;
98
- for (const run of data.items) {
99
- if (yielded >= maxItems)
100
- return;
101
- yield run;
102
- yielded++;
103
- }
104
- offset += data.items.length;
105
- hasMore = offset < data.total && data.items.length > 0;
106
- }
107
- }
108
- // ======================== Execution ========================
109
- /**
110
- * Wait for run completion synchronously.
111
- */
112
- async wait(body) {
113
- return this.client.POST("/v1/api/runs/wait", {
114
- body,
115
- });
116
- }
117
- /**
118
- * Create batch runs.
119
- */
120
- async batch(body) {
121
- return this.client.POST("/v1/api/runs/batch", {
122
- body,
123
- });
124
- }
125
- /**
126
- * Cancel a running run.
127
- */
128
- async cancel(runId, reason) {
129
- return this.client.POST("/v1/api/runs/{runId}/cancel", {
130
- params: { path: { runId } },
131
- body: { reason },
132
- });
133
- }
134
- async getObservabilitySummary(params) {
135
- return this.client.GET("/v1/api/runs/observability/summary", {
136
- params: { query: params },
137
- });
138
- }
139
- async getObservabilityCapabilities(params) {
140
- return this.client.GET("/v1/api/runs/observability/capabilities", {
141
- params: { query: params },
142
- });
143
- }
144
- async getObservabilityBindings(params) {
145
- return this.client.GET("/v1/api/runs/observability/bindings", {
146
- params: { query: params },
147
- });
148
- }
149
- /**
150
- * Resume a run waiting for human input (HITL).
151
- * After the run reaches status 'waiting_for_human', use this to provide
152
- * the human response and continue execution.
153
- *
154
- * @param runId - The run ID to resume
155
- * @param body - The human input to provide
156
- * @returns Updated run (status will change to 'resumed' then 'queued')
157
- *
158
- * @example
159
- * ```ts
160
- * // List runs waiting for human input
161
- * const waiting = await client.runs.list({ status: 'waiting_for_human' })
162
- *
163
- * // Get the prompt
164
- * const run = await client.runs.get(runId)
165
- * console.log(run.human_prompt) // "Deseja continuar com a compra?"
166
- *
167
- * // Respond
168
- * await client.runs.resume(runId, { input: { answer: "sim" } })
169
- * ```
170
- */
171
- async resume(runId, body) {
172
- return this.client.POST("/v1/api/runs/{runId}/resume", {
173
- params: { path: { runId } },
174
- body,
175
- });
176
- }
177
- /**
178
- * Rerun from start (stateless).
179
- */
180
- async rerun(runId) {
181
- return this.client.POST("/v1/api/runs/{runId}/rerun", {
182
- params: { path: { runId } },
183
- });
184
- }
185
- /**
186
- * Replay from checkpoint (stateful).
187
- * Creates a NEW run that starts from the specified checkpoint.
188
- */
189
- async replay(runId, checkpointId, options) {
190
- return this.client.POST("/v1/api/runs/{runId}/checkpoints/{checkpointId}/replay", {
191
- params: { path: { runId, checkpointId } },
192
- body: {
193
- mode: options?.mode,
194
- reason: options?.reason
195
- },
196
- });
197
- }
198
- // ======================== Events ========================
199
- /**
200
- * Get canonical run events from SSOT ledger (polling by seq).
201
- */
202
- async getEvents(runId, params) {
203
- return this.client.GET("/v1/api/runs/{runId}/events", {
204
- params: {
205
- path: { runId },
206
- query: {
207
- attemptId: params.attemptId,
208
- afterSeq: params.afterSeq ?? 0,
209
- limit: params.limit ?? 100,
210
- },
211
- },
212
- });
213
- }
214
- /** Alias: runs.events() -> runs.getEvents() */
215
- events = (runId, params) => this.getEvents(runId, params);
216
- /**
217
- * Wave 2.3: Seq-based event polling for execution trace.
218
- * Use this for incremental polling with reconnection support.
219
- *
220
- * @param runId - Run ID to poll events for
221
- * @param params - Polling options
222
- * @returns Events with seq cursors for pagination
223
- *
224
- * @example
225
- * ```ts
226
- * let afterSeq = 0;
227
- * const attemptId = "attempt-uuid";
228
- * while (run.status === 'running') {
229
- * const { data } = await client.runs.pollEvents(runId, { attemptId, afterSeq });
230
- * for (const event of data.events) {
231
- * console.log(event.type, event.payload);
232
- * }
233
- * afterSeq = data.next_after_seq;
234
- * await sleep(1000);
235
- * }
236
- * ```
237
- */
238
- async pollEvents(runId, params) {
239
- return this.client.GET("/v1/api/runs/{runId}/events", {
240
- params: {
241
- path: { runId },
242
- query: {
243
- attemptId: params.attemptId,
244
- afterSeq: params.afterSeq ?? 0,
245
- limit: params.limit ?? 100
246
- }
247
- },
248
- });
249
- }
250
- // ======================== Checkpoints ========================
251
- /**
252
- * Get checkpoints for a run.
253
- */
254
- async getCheckpoints(runId) {
255
- return this.client.GET("/v1/api/runs/{runId}/checkpoints/index", {
256
- params: { path: { runId } },
257
- });
258
- }
259
- /** Alias: runs.checkpoints() -> runs.getCheckpoints() */
260
- checkpoints = (runId) => this.getCheckpoints(runId);
261
- // ======================== FOLLOW (SSOT SSE) ========================
262
- /**
263
- * Follow a run attempt's canonical event stream with automatic reconnection.
264
- *
265
- * SSOT contract:
266
- * - Stream is keyed by (run_id, attempt_id, seq)
267
- * - Resume is driven by `afterSeq` (monotonic)
268
- * - No implicit attempt inference
269
- *
270
- * @example
271
- * ```ts
272
- * for await (const event of client.runs.follow(runId, attemptId)) {
273
- * if (event.type === "run_event") {
274
- * console.log(event.payload);
275
- * } else if (event.type === "close") {
276
- * console.log("Run completed");
277
- * }
278
- * }
279
- * ```
280
- */
281
- async *follow(runId, attemptId, options) {
282
- if (!attemptId) {
283
- throw new Error("attemptId is required for run event streaming");
284
- }
285
- const signal = options?.signal;
286
- const maxReconnects = options?.maxReconnects ?? 10;
287
- const baseDelayMs = options?.baseDelayMs ?? 1000;
288
- const maxDelayMs = options?.maxDelayMs ?? 30000;
289
- // nextSeq = next seq we expect to receive (or 0 at start)
290
- let nextSeq = options?.startSeq ?? 0;
291
- let reconnectCount = 0;
292
- let receivedTerminal = false;
293
- options?.onConnect?.();
294
- while (!receivedTerminal && reconnectCount <= maxReconnects) {
295
- if (signal?.aborted)
296
- return;
297
- try {
298
- // Build headers - Last-Event-ID is the LAST seq we received (nextSeq - 1)
299
- const headers = {};
300
- if (nextSeq > 0) {
301
- headers["Last-Event-ID"] = String(nextSeq - 1);
302
- }
303
- const response = await this.client.streamGet("/v1/api/runs/{runId}/events/stream", {
304
- params: {
305
- path: { runId },
306
- query: {
307
- attemptId,
308
- afterSeq: nextSeq > 0 ? nextSeq : 0,
309
- },
310
- },
311
- headers,
312
- });
313
- // Check for auth errors - don't reconnect on these
314
- if (response.status === 401 || response.status === 403) {
315
- const errorEvent = {
316
- type: "error",
317
- payload: { code: `HTTP_${response.status}`, message: response.statusText },
318
- seq: -1,
319
- timestamp: new Date().toISOString(),
320
- };
321
- yield errorEvent;
322
- return; // Don't reconnect on auth errors
323
- }
324
- if (!response.ok) {
325
- throw new Error(`SSE connection failed: ${response.status}`);
326
- }
327
- // Reset reconnect count on successful connection
328
- if (reconnectCount > 0) {
329
- options?.onReconnect?.(reconnectCount);
330
- }
331
- reconnectCount = 0;
332
- // Parse SSE stream
333
- for await (const rawEvent of parseSSE(response)) {
334
- if (signal?.aborted)
335
- return;
336
- // Narrow to known event types
337
- const event = narrowFollowEvent(rawEvent);
338
- if (!event)
339
- continue; // Skip unknown event types
340
- // Update seq tracking if event has seq
341
- if (typeof event.seq === "number" && event.seq >= 0) {
342
- nextSeq = event.seq + 1;
343
- }
344
- if (event.type === "error") {
345
- // Error event from server - yield but continue (might reconnect)
346
- yield event;
347
- // If it's a fatal error, break and try reconnect
348
- break;
349
- }
350
- yield event;
351
- if (event.type === "run_event" && isTerminalRunEvent(event)) {
352
- receivedTerminal = true;
353
- yield {
354
- type: "close",
355
- seq: event.seq,
356
- timestamp: event.timestamp,
357
- payload: { terminal: true },
358
- };
359
- return;
360
- }
361
- }
362
- // Stream ended without close event - this is unexpected EOF
363
- // Reconnect unless we already received terminal
364
- if (!receivedTerminal && !signal?.aborted) {
365
- options?.onDisconnect?.("eof");
366
- reconnectCount++;
367
- if (reconnectCount <= maxReconnects) {
368
- await sleep(calculateBackoff(reconnectCount, baseDelayMs, maxDelayMs));
369
- }
370
- }
371
- }
372
- catch (err) {
373
- if (signal?.aborted)
374
- return;
375
- options?.onDisconnect?.("error");
376
- reconnectCount++;
377
- if (reconnectCount <= maxReconnects) {
378
- await sleep(calculateBackoff(reconnectCount, baseDelayMs, maxDelayMs));
379
- }
380
- else {
381
- // Max reconnects exceeded - yield error and stop
382
- yield {
383
- type: "error",
384
- payload: { code: "MAX_RECONNECTS", message: `Max reconnects (${maxReconnects}) exceeded` },
385
- seq: -1,
386
- timestamp: new Date().toISOString(),
387
- };
388
- return;
389
- }
390
- }
391
- }
392
- }
393
- /**
394
- * Create run and follow canonical SSOT stream for the current attempt.
395
- */
396
- async *createAndStream(body, options) {
397
- const { data, error } = await this.create(body);
398
- if (error || !data) {
399
- throw new Error(`Failed to create run: ${JSON.stringify(error)}`);
400
- }
401
- const runId = data.run_id;
402
- const runResponse = await this.get(runId);
403
- if (runResponse.error || !runResponse.data?.current_attempt_id) {
404
- throw new Error("Run created without current_attempt_id; cannot stream SSOT events");
405
- }
406
- yield* this.follow(runId, runResponse.data.current_attempt_id, options);
407
- }
408
- /**
409
- * Wait for a specific event that matches a predicate.
410
- *
411
- * @example
412
- * ```ts
413
- * // Wait for run completion
414
- * const event = await client.runs.waitFor(runId, attemptId, (e) => e.type === "close", {
415
- * timeoutMs: 60000
416
- * });
417
- *
418
- * // Wait for specific node execution
419
- * const nodeEvent = await client.runs.waitFor(runId, attemptId, (e) =>
420
- * e.type === "run_event" && e.payload?.node === "my_node"
421
- * );
422
- * ```
423
- */
424
- async waitFor(runId, attemptId, predicate, options) {
425
- const timeoutMs = options?.timeoutMs ?? 300_000; // 5 min default
426
- const controller = new AbortController();
427
- // Combine parent signal with our timeout
428
- const onAbort = () => controller.abort();
429
- options?.signal?.addEventListener("abort", onAbort, { once: true });
430
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
431
- try {
432
- for await (const event of this.follow(runId, attemptId, {
433
- signal: controller.signal,
434
- startSeq: options?.startSeq,
435
- })) {
436
- if (predicate(event)) {
437
- return event;
438
- }
439
- // If we got close without matching predicate, error
440
- if (event.type === "close") {
441
- throw new Error("Run completed without matching event");
442
- }
443
- }
444
- // Stream ended without match or terminal
445
- throw new Error("Stream ended without matching event");
446
- }
447
- catch (err) {
448
- if (controller.signal.aborted && !options?.signal?.aborted) {
449
- // Our timeout triggered the abort
450
- const { TimeoutError } = await import("../errors/index.js");
451
- throw new TimeoutError(timeoutMs);
452
- }
453
- throw err;
454
- }
455
- finally {
456
- clearTimeout(timeoutId);
457
- options?.signal?.removeEventListener("abort", onAbort);
458
- }
459
- }
460
- }
461
- /** Narrow raw SSE event to FollowEvent */
462
- export function narrowFollowEvent(raw) {
463
- const eventType = raw.event ?? "message";
464
- const validTypes = ["run_event", "heartbeat", "close", "error"];
465
- if (!validTypes.includes(eventType)) {
466
- return null;
467
- }
468
- const data = raw.data;
469
- // Canonical payload from backend SSE is RunEventDto:
470
- // { id, seq, type, timestamp, attempt_id, payload }
471
- if (eventType === "run_event" && data) {
472
- const seq = typeof data.seq === "number" ? data.seq : (raw.id ? parseInt(raw.id, 10) : -1);
473
- const timestamp = typeof data.timestamp === "string" ? data.timestamp : new Date().toISOString();
474
- const innerPayload = (typeof data.payload === "object" && data.payload !== null)
475
- ? data.payload
476
- : null;
477
- const operationId = typeof data.operation_id === "string" ? data.operation_id : undefined;
478
- const parentOperationId = typeof data.parent_operation_id === "string"
479
- ? data.parent_operation_id
480
- : data.parent_operation_id === null
481
- ? null
482
- : undefined;
483
- const rootOperationId = typeof data.root_operation_id === "string" ? data.root_operation_id : undefined;
484
- return {
485
- type: "run_event",
486
- seq,
487
- timestamp,
488
- payload: {
489
- ...(innerPayload ?? {}),
490
- type: typeof data.type === "string" ? data.type : "UNKNOWN",
491
- attempt_id: typeof data.attempt_id === "string" ? data.attempt_id : undefined,
492
- operation_id: operationId,
493
- parent_operation_id: parentOperationId,
494
- root_operation_id: rootOperationId,
495
- },
496
- operation_id: operationId,
497
- parent_operation_id: parentOperationId,
498
- root_operation_id: rootOperationId,
499
- node: typeof innerPayload?.node === "string" ? innerPayload.node : undefined,
500
- };
501
- }
502
- return {
503
- type: eventType,
504
- seq: typeof data?.seq === "number" ? data.seq : (raw.id ? parseInt(raw.id, 10) : -1),
505
- timestamp: typeof data?.timestamp === "string" ? data.timestamp : new Date().toISOString(),
506
- payload: data,
507
- node: typeof data?.node === "string" ? data.node : undefined,
508
- };
509
- }
510
- function isTerminalRunEvent(event) {
511
- const type = typeof event.payload?.type === "string"
512
- ? event.payload.type.toUpperCase()
513
- : "";
514
- return type === "RUN_FINISHED" || type === "RUN_FAILED" || type === "RUN_CANCELLED";
515
- }
516
- /** Calculate exponential backoff with jitter */
517
- function calculateBackoff(attempt, baseMs, maxMs) {
518
- const exponential = baseMs * Math.pow(2, attempt - 1);
519
- const capped = Math.min(exponential, maxMs);
520
- const jitter = capped * 0.2 * Math.random();
521
- return Math.floor(capped + jitter);
522
- }
523
- /** Sleep utility */
524
- function sleep(ms) {
525
- return new Promise(resolve => setTimeout(resolve, ms));
526
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Store Module - Fully Typed
3
- */
4
- import type { RawClient, APIResponse } from "../client/raw.js";
5
- export interface StoreValue {
6
- key: string;
7
- value: string;
8
- ttl_seconds?: number;
9
- created_at: string;
10
- expires_at?: string;
11
- }
12
- export interface StoreKeysResponse {
13
- keys: string[];
14
- total: number;
15
- }
16
- export declare class StoreModule {
17
- private client;
18
- private headers;
19
- constructor(client: RawClient, headers: () => Record<string, string>);
20
- /**
21
- * Get a value by key.
22
- */
23
- get(key: string): Promise<APIResponse<StoreValue>>;
24
- /**
25
- * Set a value.
26
- */
27
- set(key: string, value: string, ttlSeconds?: number): Promise<APIResponse<StoreValue>>;
28
- /**
29
- * Delete a value.
30
- */
31
- delete(key: string): Promise<APIResponse<void>>;
32
- /**
33
- * List all keys.
34
- */
35
- listKeys(prefix?: string): Promise<APIResponse<StoreKeysResponse>>;
36
- }
37
- //# sourceMappingURL=store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/modules/store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,kBAAkB,CAAC;AAI3E,MAAM,WAAW,UAAU;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,WAAW;IACR,OAAO,CAAC,MAAM;IAAa,OAAO,CAAC,OAAO;gBAAlC,MAAM,EAAE,SAAS,EAAU,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAEpF;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAOxD;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAQ5F;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAOrD;;OAEG;IACG,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;CAM3E"}
@@ -1,48 +0,0 @@
1
- /**
2
- * Store Module - Fully Typed
3
- */
4
- export class StoreModule {
5
- client;
6
- headers;
7
- constructor(client, headers) {
8
- this.client = client;
9
- this.headers = headers;
10
- }
11
- /**
12
- * Get a value by key.
13
- */
14
- async get(key) {
15
- return this.client.GET("/v1/api/store/{key}", {
16
- params: { path: { key } },
17
- headers: this.headers(),
18
- });
19
- }
20
- /**
21
- * Set a value.
22
- */
23
- async set(key, value, ttlSeconds) {
24
- return this.client.PUT("/v1/api/store/{key}", {
25
- params: { path: { key } },
26
- body: { value, ttl_seconds: ttlSeconds },
27
- headers: this.headers(),
28
- });
29
- }
30
- /**
31
- * Delete a value.
32
- */
33
- async delete(key) {
34
- return this.client.DELETE("/v1/api/store/{key}", {
35
- params: { path: { key } },
36
- headers: this.headers(),
37
- });
38
- }
39
- /**
40
- * List all keys.
41
- */
42
- async listKeys(prefix) {
43
- return this.client.GET("/v1/api/store", {
44
- params: { query: { prefix } },
45
- headers: this.headers(),
46
- });
47
- }
48
- }
@@ -1,28 +0,0 @@
1
- import type { APIResponse, RawClient } from "../client/raw.js";
2
- export interface AuthoringTemplateSummary {
3
- template_ref: string;
4
- version: string;
5
- display_name: string;
6
- description?: string | null;
7
- template_kind: string;
8
- category: string;
9
- editability_mode: string;
10
- required_capability_refs: string[];
11
- default_policy_refs?: Record<string, unknown> | null;
12
- default_runtime_config_refs?: Record<string, unknown> | null;
13
- }
14
- export interface AuthoringTemplateDetail extends AuthoringTemplateSummary {
15
- base_agent_ir: Record<string, unknown>;
16
- }
17
- export interface AuthoringTemplateListResponse {
18
- items: AuthoringTemplateSummary[];
19
- total: number;
20
- }
21
- export declare class TemplatesModule {
22
- private client;
23
- private headers;
24
- constructor(client: RawClient, headers: () => Record<string, string>);
25
- list(): Promise<APIResponse<AuthoringTemplateListResponse>>;
26
- get(templateRef: string): Promise<APIResponse<AuthoringTemplateDetail>>;
27
- }
28
- //# sourceMappingURL=templates.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/modules/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE/D,MAAM,WAAW,wBAAwB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,wBAAwB,EAAE,MAAM,EAAE,CAAC;IACnC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACrD,2BAA2B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAChE;AAED,MAAM,WAAW,uBAAwB,SAAQ,wBAAwB;IACrE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,6BAA6B;IAC1C,KAAK,EAAE,wBAAwB,EAAE,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,eAAe;IACZ,OAAO,CAAC,MAAM;IAAa,OAAO,CAAC,OAAO;gBAAlC,MAAM,EAAE,SAAS,EAAU,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAE9E,IAAI,IAAI,OAAO,CAAC,WAAW,CAAC,6BAA6B,CAAC,CAAC;IAM3D,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC;CAMhF"}
@@ -1,19 +0,0 @@
1
- export class TemplatesModule {
2
- client;
3
- headers;
4
- constructor(client, headers) {
5
- this.client = client;
6
- this.headers = headers;
7
- }
8
- async list() {
9
- return this.client.GET("/v1/api/templates", {
10
- headers: this.headers(),
11
- });
12
- }
13
- async get(templateRef) {
14
- return this.client.GET("/v1/api/templates/{templateRef}", {
15
- params: { path: { templateRef } },
16
- headers: this.headers(),
17
- });
18
- }
19
- }