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