@runtypelabs/sdk 4.20.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +612 -179
- package/dist/index.d.cts +263 -1267
- package/dist/index.d.ts +263 -1267
- package/dist/index.mjs +606 -177
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60,7 +60,6 @@ __export(index_exports, {
|
|
|
60
60
|
ProductDriftError: () => ProductDriftError,
|
|
61
61
|
ProductEnsureConflictError: () => ProductEnsureConflictError,
|
|
62
62
|
ProductsNamespace: () => ProductsNamespace,
|
|
63
|
-
PromptRunner: () => PromptRunner,
|
|
64
63
|
PromptsEndpoint: () => PromptsEndpoint,
|
|
65
64
|
PromptsNamespace: () => PromptsNamespace,
|
|
66
65
|
ProviderKeysEndpoint: () => ProviderKeysEndpoint,
|
|
@@ -89,6 +88,7 @@ __export(index_exports, {
|
|
|
89
88
|
ToolEnsureConflictError: () => ToolEnsureConflictError,
|
|
90
89
|
ToolsEndpoint: () => ToolsEndpoint,
|
|
91
90
|
ToolsNamespace: () => ToolsNamespace,
|
|
91
|
+
UNIFIED_EVENTS_QUERY: () => UNIFIED_EVENTS_QUERY,
|
|
92
92
|
UsersEndpoint: () => UsersEndpoint,
|
|
93
93
|
applyGeneratedRuntimeToolProposalToDispatchRequest: () => applyGeneratedRuntimeToolProposalToDispatchRequest,
|
|
94
94
|
attachRuntimeToolsToDispatchRequest: () => attachRuntimeToolsToDispatchRequest,
|
|
@@ -105,8 +105,10 @@ __export(index_exports, {
|
|
|
105
105
|
computeSkillContentHash: () => computeSkillContentHash,
|
|
106
106
|
computeSurfaceContentHash: () => computeSurfaceContentHash,
|
|
107
107
|
computeToolContentHash: () => computeToolContentHash,
|
|
108
|
+
createAgentEventTranslator: () => createAgentEventTranslator,
|
|
108
109
|
createClient: () => createClient,
|
|
109
110
|
createExternalTool: () => createExternalTool,
|
|
111
|
+
createFlowEventTranslator: () => createFlowEventTranslator,
|
|
110
112
|
defaultWorkflow: () => defaultWorkflow,
|
|
111
113
|
defaultWorkflowConfig: () => defaultWorkflowConfig,
|
|
112
114
|
defineAgent: () => defineAgent,
|
|
@@ -129,6 +131,7 @@ __export(index_exports, {
|
|
|
129
131
|
isDiscoveryToolName: () => isDiscoveryToolName,
|
|
130
132
|
isMarathonArtifactPath: () => isMarathonArtifactPath,
|
|
131
133
|
isPreservationSensitiveTask: () => isPreservationSensitiveTask,
|
|
134
|
+
isUnifiedEventType: () => isUnifiedEventType,
|
|
132
135
|
isWorkflowHookRef: () => isWorkflowHookRef,
|
|
133
136
|
listWorkflowHooks: () => listWorkflowHooks,
|
|
134
137
|
normalizeAgentDefinition: () => normalizeAgentDefinition,
|
|
@@ -151,10 +154,511 @@ __export(index_exports, {
|
|
|
151
154
|
shouldInjectEmptySessionNudge: () => shouldInjectEmptySessionNudge,
|
|
152
155
|
shouldRequestModelEscalation: () => shouldRequestModelEscalation,
|
|
153
156
|
streamEvents: () => streamEvents,
|
|
154
|
-
unregisterWorkflowHook: () => unregisterWorkflowHook
|
|
157
|
+
unregisterWorkflowHook: () => unregisterWorkflowHook,
|
|
158
|
+
withUnifiedEvents: () => withUnifiedEvents
|
|
155
159
|
});
|
|
156
160
|
module.exports = __toCommonJS(index_exports);
|
|
157
161
|
|
|
162
|
+
// src/unified-stream-adapter.ts
|
|
163
|
+
var UNIFIED_EVENTS_QUERY = "events=unified";
|
|
164
|
+
function withUnifiedEvents(path) {
|
|
165
|
+
return path.includes("?") ? `${path}&${UNIFIED_EVENTS_QUERY}` : `${path}?${UNIFIED_EVENTS_QUERY}`;
|
|
166
|
+
}
|
|
167
|
+
var UNIFIED_ONLY_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
168
|
+
"execution_start",
|
|
169
|
+
"execution_complete",
|
|
170
|
+
"execution_error",
|
|
171
|
+
"turn_start",
|
|
172
|
+
"turn_complete",
|
|
173
|
+
"text_start",
|
|
174
|
+
"text_delta",
|
|
175
|
+
"text_complete",
|
|
176
|
+
"reasoning_start",
|
|
177
|
+
"reasoning_delta",
|
|
178
|
+
"reasoning_complete",
|
|
179
|
+
"media_start",
|
|
180
|
+
"media_delta",
|
|
181
|
+
"media_complete",
|
|
182
|
+
"tool_output_delta",
|
|
183
|
+
"await"
|
|
184
|
+
]);
|
|
185
|
+
function isUnifiedEventType(type) {
|
|
186
|
+
return typeof type === "string" && UNIFIED_ONLY_EVENT_TYPES.has(type);
|
|
187
|
+
}
|
|
188
|
+
function str(value) {
|
|
189
|
+
return typeof value === "string" ? value : void 0;
|
|
190
|
+
}
|
|
191
|
+
function num(value) {
|
|
192
|
+
return typeof value === "number" ? value : void 0;
|
|
193
|
+
}
|
|
194
|
+
function compact(event) {
|
|
195
|
+
const out = { type: event.type };
|
|
196
|
+
for (const [k, v] of Object.entries(event)) {
|
|
197
|
+
if (k !== "type" && v !== void 0) out[k] = v;
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
var LEGACY_FLOW_PASSTHROUGH = /* @__PURE__ */ new Set([
|
|
202
|
+
"flow_start",
|
|
203
|
+
"flow_complete",
|
|
204
|
+
"flow_error",
|
|
205
|
+
"flow_await",
|
|
206
|
+
"step_await",
|
|
207
|
+
"step_delta"
|
|
208
|
+
]);
|
|
209
|
+
function createFlowEventTranslator() {
|
|
210
|
+
let currentStepId;
|
|
211
|
+
let currentStepName;
|
|
212
|
+
return (raw) => {
|
|
213
|
+
if (!raw || typeof raw !== "object") return [];
|
|
214
|
+
const data = raw;
|
|
215
|
+
const type = str(data.type);
|
|
216
|
+
if (!type) return [];
|
|
217
|
+
const executionId = str(data.executionId);
|
|
218
|
+
const seq = num(data.seq);
|
|
219
|
+
if (LEGACY_FLOW_PASSTHROUGH.has(type)) return [data];
|
|
220
|
+
switch (type) {
|
|
221
|
+
case "execution_start":
|
|
222
|
+
if (data.kind !== "flow") return [];
|
|
223
|
+
return [
|
|
224
|
+
compact({
|
|
225
|
+
type: "flow_start",
|
|
226
|
+
executionId,
|
|
227
|
+
seq,
|
|
228
|
+
flowId: data.flowId,
|
|
229
|
+
flowName: data.flowName,
|
|
230
|
+
totalSteps: data.totalSteps,
|
|
231
|
+
startedAt: data.startedAt,
|
|
232
|
+
source: data.source
|
|
233
|
+
})
|
|
234
|
+
];
|
|
235
|
+
case "step_start": {
|
|
236
|
+
const id = str(data.id) ?? str(data.stepId);
|
|
237
|
+
const name = str(data.name) ?? str(data.stepName);
|
|
238
|
+
currentStepId = id;
|
|
239
|
+
currentStepName = name;
|
|
240
|
+
return [
|
|
241
|
+
compact({
|
|
242
|
+
type: "step_start",
|
|
243
|
+
executionId,
|
|
244
|
+
seq,
|
|
245
|
+
stepId: id,
|
|
246
|
+
name,
|
|
247
|
+
stepName: name,
|
|
248
|
+
stepType: data.stepType,
|
|
249
|
+
index: data.index,
|
|
250
|
+
totalSteps: data.totalSteps,
|
|
251
|
+
startedAt: data.startedAt,
|
|
252
|
+
outputVariable: data.outputVariable
|
|
253
|
+
})
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
case "text_delta":
|
|
257
|
+
return [
|
|
258
|
+
compact({
|
|
259
|
+
type: "step_delta",
|
|
260
|
+
executionId,
|
|
261
|
+
seq,
|
|
262
|
+
delta: str(data.delta) ?? "",
|
|
263
|
+
text: str(data.delta) ?? "",
|
|
264
|
+
stepId: currentStepId,
|
|
265
|
+
name: currentStepName,
|
|
266
|
+
stepName: currentStepName
|
|
267
|
+
})
|
|
268
|
+
];
|
|
269
|
+
case "step_complete": {
|
|
270
|
+
const id = str(data.id) ?? str(data.stepId);
|
|
271
|
+
const name = str(data.name) ?? str(data.stepName);
|
|
272
|
+
const out = compact({
|
|
273
|
+
type: "step_complete",
|
|
274
|
+
executionId,
|
|
275
|
+
seq,
|
|
276
|
+
stepId: id,
|
|
277
|
+
name,
|
|
278
|
+
stepName: name,
|
|
279
|
+
stepType: data.stepType,
|
|
280
|
+
result: data.result,
|
|
281
|
+
success: data.success,
|
|
282
|
+
executionTime: num(data.durationMs) ?? num(data.executionTime),
|
|
283
|
+
stopReason: data.stopReason,
|
|
284
|
+
completedAt: data.completedAt,
|
|
285
|
+
unresolvedVariables: data.unresolvedVariables,
|
|
286
|
+
error: data.error
|
|
287
|
+
});
|
|
288
|
+
currentStepId = void 0;
|
|
289
|
+
currentStepName = void 0;
|
|
290
|
+
return [out];
|
|
291
|
+
}
|
|
292
|
+
case "execution_complete":
|
|
293
|
+
if (data.kind !== "flow") return [];
|
|
294
|
+
return [
|
|
295
|
+
compact({
|
|
296
|
+
type: "flow_complete",
|
|
297
|
+
executionId,
|
|
298
|
+
seq,
|
|
299
|
+
success: data.success,
|
|
300
|
+
totalSteps: data.totalSteps,
|
|
301
|
+
successfulSteps: data.successfulSteps,
|
|
302
|
+
failedSteps: data.failedSteps,
|
|
303
|
+
executionTime: data.durationMs,
|
|
304
|
+
finalOutput: data.finalOutput,
|
|
305
|
+
completedAt: data.completedAt
|
|
306
|
+
})
|
|
307
|
+
];
|
|
308
|
+
case "execution_error":
|
|
309
|
+
return [
|
|
310
|
+
compact({
|
|
311
|
+
type: "flow_error",
|
|
312
|
+
executionId,
|
|
313
|
+
seq,
|
|
314
|
+
error: data.error,
|
|
315
|
+
code: data.code,
|
|
316
|
+
upgradeUrl: data.upgradeUrl
|
|
317
|
+
})
|
|
318
|
+
];
|
|
319
|
+
case "await":
|
|
320
|
+
return [
|
|
321
|
+
compact({
|
|
322
|
+
type: "flow_await",
|
|
323
|
+
executionId,
|
|
324
|
+
seq,
|
|
325
|
+
toolId: data.toolId ?? data.toolCallId,
|
|
326
|
+
toolName: data.toolName,
|
|
327
|
+
parameters: data.parameters,
|
|
328
|
+
awaitedAt: data.awaitedAt,
|
|
329
|
+
origin: data.origin,
|
|
330
|
+
pageOrigin: data.pageOrigin
|
|
331
|
+
})
|
|
332
|
+
];
|
|
333
|
+
// Channels/markers/tool-family/approval/skip/source/custom/ping the flow
|
|
334
|
+
// consumer never read → no legacy event. (A non-terminal `error` is only
|
|
335
|
+
// produced on agent streams; dropping it here avoids a false flow_error.)
|
|
336
|
+
default:
|
|
337
|
+
return [];
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function createAgentEventTranslator() {
|
|
342
|
+
let agentId;
|
|
343
|
+
let iteration;
|
|
344
|
+
let turnId;
|
|
345
|
+
let reasoningScope;
|
|
346
|
+
let media = null;
|
|
347
|
+
return (raw) => {
|
|
348
|
+
if (!raw || typeof raw !== "object") return [];
|
|
349
|
+
const data = raw;
|
|
350
|
+
const type = str(data.type);
|
|
351
|
+
if (!type) return [];
|
|
352
|
+
const executionId = str(data.executionId);
|
|
353
|
+
const seq = num(data.seq);
|
|
354
|
+
const iter = num(data.iteration) ?? iteration;
|
|
355
|
+
if (type.startsWith("agent_")) return [data];
|
|
356
|
+
switch (type) {
|
|
357
|
+
case "execution_start":
|
|
358
|
+
if (data.kind !== "agent") return [];
|
|
359
|
+
agentId = str(data.agentId);
|
|
360
|
+
return [
|
|
361
|
+
compact({
|
|
362
|
+
type: "agent_start",
|
|
363
|
+
executionId,
|
|
364
|
+
seq,
|
|
365
|
+
agentId: data.agentId,
|
|
366
|
+
agentName: data.agentName,
|
|
367
|
+
maxTurns: data.maxTurns,
|
|
368
|
+
startedAt: data.startedAt,
|
|
369
|
+
config: data.config
|
|
370
|
+
})
|
|
371
|
+
];
|
|
372
|
+
case "turn_start":
|
|
373
|
+
turnId = str(data.id);
|
|
374
|
+
iteration = num(data.iteration) ?? iteration;
|
|
375
|
+
return [
|
|
376
|
+
compact({
|
|
377
|
+
type: "agent_turn_start",
|
|
378
|
+
executionId,
|
|
379
|
+
seq,
|
|
380
|
+
iteration: data.iteration ?? iteration,
|
|
381
|
+
turnId: data.id,
|
|
382
|
+
turnIndex: data.turnIndex,
|
|
383
|
+
role: data.role
|
|
384
|
+
})
|
|
385
|
+
];
|
|
386
|
+
case "text_delta":
|
|
387
|
+
return [
|
|
388
|
+
compact({
|
|
389
|
+
type: "agent_turn_delta",
|
|
390
|
+
executionId,
|
|
391
|
+
seq,
|
|
392
|
+
iteration: iter,
|
|
393
|
+
turnId,
|
|
394
|
+
delta: str(data.delta) ?? "",
|
|
395
|
+
contentType: "text"
|
|
396
|
+
})
|
|
397
|
+
];
|
|
398
|
+
case "reasoning_start":
|
|
399
|
+
reasoningScope = data.scope === "loop" ? "loop" : "turn";
|
|
400
|
+
return [];
|
|
401
|
+
case "reasoning_delta":
|
|
402
|
+
return [
|
|
403
|
+
compact({
|
|
404
|
+
type: "agent_turn_delta",
|
|
405
|
+
executionId,
|
|
406
|
+
seq,
|
|
407
|
+
iteration: iter,
|
|
408
|
+
turnId,
|
|
409
|
+
delta: str(data.delta) ?? "",
|
|
410
|
+
contentType: "thinking"
|
|
411
|
+
})
|
|
412
|
+
];
|
|
413
|
+
case "reasoning_complete": {
|
|
414
|
+
const scope = data.scope === "loop" ? "loop" : reasoningScope;
|
|
415
|
+
reasoningScope = void 0;
|
|
416
|
+
if (scope === "loop") {
|
|
417
|
+
return [
|
|
418
|
+
compact({
|
|
419
|
+
type: "agent_reflection",
|
|
420
|
+
executionId,
|
|
421
|
+
seq,
|
|
422
|
+
iteration: iter,
|
|
423
|
+
reflection: data.text
|
|
424
|
+
})
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
return [];
|
|
428
|
+
}
|
|
429
|
+
case "turn_complete":
|
|
430
|
+
return [
|
|
431
|
+
compact({
|
|
432
|
+
type: "agent_turn_complete",
|
|
433
|
+
executionId,
|
|
434
|
+
seq,
|
|
435
|
+
iteration: data.iteration ?? iter,
|
|
436
|
+
turnId: data.id,
|
|
437
|
+
role: data.role,
|
|
438
|
+
completedAt: data.completedAt,
|
|
439
|
+
content: data.content,
|
|
440
|
+
tokens: data.tokens,
|
|
441
|
+
cost: data.cost,
|
|
442
|
+
stopReason: data.stopReason
|
|
443
|
+
})
|
|
444
|
+
];
|
|
445
|
+
case "tool_start":
|
|
446
|
+
return [
|
|
447
|
+
compact({
|
|
448
|
+
type: "agent_tool_start",
|
|
449
|
+
executionId,
|
|
450
|
+
seq,
|
|
451
|
+
iteration: iter,
|
|
452
|
+
toolCallId: data.toolCallId,
|
|
453
|
+
toolName: data.toolName,
|
|
454
|
+
toolType: data.toolType,
|
|
455
|
+
parameters: data.parameters,
|
|
456
|
+
origin: data.origin,
|
|
457
|
+
pageOrigin: data.pageOrigin
|
|
458
|
+
})
|
|
459
|
+
];
|
|
460
|
+
case "tool_output_delta":
|
|
461
|
+
return [
|
|
462
|
+
compact({
|
|
463
|
+
type: "agent_tool_delta",
|
|
464
|
+
executionId,
|
|
465
|
+
seq,
|
|
466
|
+
iteration: iter,
|
|
467
|
+
toolCallId: data.toolCallId,
|
|
468
|
+
delta: str(data.delta) ?? ""
|
|
469
|
+
})
|
|
470
|
+
];
|
|
471
|
+
case "tool_input_delta":
|
|
472
|
+
return [
|
|
473
|
+
compact({
|
|
474
|
+
type: "agent_tool_input_delta",
|
|
475
|
+
executionId,
|
|
476
|
+
seq,
|
|
477
|
+
iteration: iter,
|
|
478
|
+
toolCallId: data.toolCallId,
|
|
479
|
+
delta: str(data.delta) ?? ""
|
|
480
|
+
})
|
|
481
|
+
];
|
|
482
|
+
case "tool_input_complete":
|
|
483
|
+
return [
|
|
484
|
+
compact({
|
|
485
|
+
type: "agent_tool_input_complete",
|
|
486
|
+
executionId,
|
|
487
|
+
seq,
|
|
488
|
+
iteration: iter,
|
|
489
|
+
toolCallId: data.toolCallId,
|
|
490
|
+
toolName: data.toolName,
|
|
491
|
+
parameters: data.parameters ?? {},
|
|
492
|
+
hiddenParameterNames: data.hiddenParameterNames
|
|
493
|
+
})
|
|
494
|
+
];
|
|
495
|
+
case "tool_complete":
|
|
496
|
+
return [
|
|
497
|
+
compact({
|
|
498
|
+
type: "agent_tool_complete",
|
|
499
|
+
executionId,
|
|
500
|
+
seq,
|
|
501
|
+
iteration: num(data.iteration) ?? iter,
|
|
502
|
+
toolCallId: data.toolCallId,
|
|
503
|
+
toolName: data.toolName,
|
|
504
|
+
success: data.success,
|
|
505
|
+
result: data.result,
|
|
506
|
+
executionTime: data.executionTime
|
|
507
|
+
})
|
|
508
|
+
];
|
|
509
|
+
case "media_start":
|
|
510
|
+
media = {
|
|
511
|
+
mediaType: str(data.mediaType),
|
|
512
|
+
role: str(data.role),
|
|
513
|
+
toolCallId: str(data.toolCallId),
|
|
514
|
+
chunks: []
|
|
515
|
+
};
|
|
516
|
+
return [];
|
|
517
|
+
case "media_delta": {
|
|
518
|
+
const delta = str(data.delta);
|
|
519
|
+
if (media && delta) media.chunks.push(delta);
|
|
520
|
+
return [];
|
|
521
|
+
}
|
|
522
|
+
case "media_complete": {
|
|
523
|
+
const acc = media;
|
|
524
|
+
media = null;
|
|
525
|
+
const mediaType = str(data.mediaType) ?? acc?.mediaType;
|
|
526
|
+
const toolCallId = str(data.toolCallId) ?? acc?.toolCallId;
|
|
527
|
+
const url = str(data.url);
|
|
528
|
+
const inlineData = str(data.data) ?? (acc && acc.chunks.length ? acc.chunks.join("") : void 0);
|
|
529
|
+
let item;
|
|
530
|
+
if (url) {
|
|
531
|
+
const kind = mediaType && mediaType.startsWith("image/") ? "image-url" : "file-url";
|
|
532
|
+
item = compact({ type: kind, url, mediaType });
|
|
533
|
+
} else {
|
|
534
|
+
item = compact({ type: "media", data: inlineData ?? "", mediaType });
|
|
535
|
+
}
|
|
536
|
+
return [
|
|
537
|
+
compact({
|
|
538
|
+
type: "agent_media",
|
|
539
|
+
executionId,
|
|
540
|
+
seq,
|
|
541
|
+
iteration: iter,
|
|
542
|
+
toolCallId,
|
|
543
|
+
media: [item]
|
|
544
|
+
})
|
|
545
|
+
];
|
|
546
|
+
}
|
|
547
|
+
case "approval_start":
|
|
548
|
+
return [
|
|
549
|
+
compact({
|
|
550
|
+
type: "agent_approval_start",
|
|
551
|
+
executionId,
|
|
552
|
+
seq,
|
|
553
|
+
iteration: iter,
|
|
554
|
+
approvalId: data.approvalId,
|
|
555
|
+
toolCallId: data.toolCallId,
|
|
556
|
+
toolName: data.toolName,
|
|
557
|
+
toolType: data.toolType,
|
|
558
|
+
description: data.description,
|
|
559
|
+
reason: data.reason,
|
|
560
|
+
parameters: data.parameters,
|
|
561
|
+
timeout: data.timeout,
|
|
562
|
+
startedAt: data.startedAt
|
|
563
|
+
})
|
|
564
|
+
];
|
|
565
|
+
case "approval_complete":
|
|
566
|
+
return [
|
|
567
|
+
compact({
|
|
568
|
+
type: "agent_approval_complete",
|
|
569
|
+
executionId,
|
|
570
|
+
seq,
|
|
571
|
+
approvalId: data.approvalId,
|
|
572
|
+
decision: data.decision,
|
|
573
|
+
completedAt: data.completedAt,
|
|
574
|
+
resolvedBy: data.resolvedBy
|
|
575
|
+
})
|
|
576
|
+
];
|
|
577
|
+
case "await":
|
|
578
|
+
return [
|
|
579
|
+
compact({
|
|
580
|
+
type: "agent_await",
|
|
581
|
+
executionId,
|
|
582
|
+
seq,
|
|
583
|
+
toolId: data.toolId ?? data.toolCallId,
|
|
584
|
+
toolName: data.toolName,
|
|
585
|
+
parameters: data.parameters,
|
|
586
|
+
awaitedAt: data.awaitedAt,
|
|
587
|
+
origin: data.origin,
|
|
588
|
+
pageOrigin: data.pageOrigin
|
|
589
|
+
})
|
|
590
|
+
];
|
|
591
|
+
case "execution_complete":
|
|
592
|
+
if (data.kind !== "agent") return [];
|
|
593
|
+
return [
|
|
594
|
+
compact({
|
|
595
|
+
type: "agent_complete",
|
|
596
|
+
executionId,
|
|
597
|
+
seq,
|
|
598
|
+
agentId: data.agentId ?? agentId,
|
|
599
|
+
success: data.success,
|
|
600
|
+
iterations: data.iterations,
|
|
601
|
+
stopReason: data.stopReason,
|
|
602
|
+
completedAt: data.completedAt,
|
|
603
|
+
totalCost: data.totalCost,
|
|
604
|
+
totalTokens: data.totalTokens,
|
|
605
|
+
finalOutput: data.finalOutput,
|
|
606
|
+
duration: data.durationMs
|
|
607
|
+
})
|
|
608
|
+
];
|
|
609
|
+
case "execution_error":
|
|
610
|
+
return [
|
|
611
|
+
compact({
|
|
612
|
+
type: "agent_complete",
|
|
613
|
+
executionId,
|
|
614
|
+
seq,
|
|
615
|
+
agentId,
|
|
616
|
+
success: false,
|
|
617
|
+
stopReason: "error",
|
|
618
|
+
error: errorMessage(data.error),
|
|
619
|
+
completedAt: data.completedAt
|
|
620
|
+
})
|
|
621
|
+
];
|
|
622
|
+
case "error":
|
|
623
|
+
return [
|
|
624
|
+
compact({
|
|
625
|
+
type: "agent_error",
|
|
626
|
+
executionId,
|
|
627
|
+
seq,
|
|
628
|
+
iteration: iter,
|
|
629
|
+
error: errorObject(data.error),
|
|
630
|
+
recoverable: true
|
|
631
|
+
})
|
|
632
|
+
];
|
|
633
|
+
case "ping":
|
|
634
|
+
return [compact({ type: "agent_ping", executionId, seq, timestamp: data.timestamp })];
|
|
635
|
+
// turn/text/reasoning open+close markers, step_*, artifact_*, source,
|
|
636
|
+
// custom (fallback beat / routing), and the skill-fold result envelope
|
|
637
|
+
// the SDK never consumed → no legacy event.
|
|
638
|
+
default:
|
|
639
|
+
return [];
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function errorMessage(error) {
|
|
644
|
+
if (typeof error === "string") return error;
|
|
645
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
646
|
+
const message = error.message;
|
|
647
|
+
if (typeof message === "string") return message;
|
|
648
|
+
}
|
|
649
|
+
return error === void 0 ? "Agent execution failed" : JSON.stringify(error);
|
|
650
|
+
}
|
|
651
|
+
function errorObject(error) {
|
|
652
|
+
if (typeof error === "string") return { code: "error", message: error };
|
|
653
|
+
if (error && typeof error === "object") {
|
|
654
|
+
const e = error;
|
|
655
|
+
const obj = { code: e.code ?? "error", message: e.message ?? "" };
|
|
656
|
+
if (e.details !== void 0) obj.details = e.details;
|
|
657
|
+
return obj;
|
|
658
|
+
}
|
|
659
|
+
return { code: "error", message: String(error) };
|
|
660
|
+
}
|
|
661
|
+
|
|
158
662
|
// src/stream-utils.ts
|
|
159
663
|
function parseSSEChunk(chunk, buffer) {
|
|
160
664
|
buffer += chunk;
|
|
@@ -192,7 +696,7 @@ function parseFinalBuffer(buffer) {
|
|
|
192
696
|
}
|
|
193
697
|
return null;
|
|
194
698
|
}
|
|
195
|
-
async function processStream(response, callbacks = {}) {
|
|
699
|
+
async function processStream(response, callbacks = {}, options = {}) {
|
|
196
700
|
if (!response.ok) {
|
|
197
701
|
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
198
702
|
callbacks.onError?.(error);
|
|
@@ -216,6 +720,20 @@ async function processStream(response, callbacks = {}) {
|
|
|
216
720
|
executionTime: 0,
|
|
217
721
|
success: true
|
|
218
722
|
};
|
|
723
|
+
let translate = options.unified === true ? createFlowEventTranslator() : null;
|
|
724
|
+
const autoDetect = options.unified === void 0;
|
|
725
|
+
const dispatch = (parsed) => {
|
|
726
|
+
if (autoDetect && !translate && isUnifiedEventType(parsed?.type)) {
|
|
727
|
+
translate = createFlowEventTranslator();
|
|
728
|
+
}
|
|
729
|
+
if (translate) {
|
|
730
|
+
for (const ev of translate(parsed)) {
|
|
731
|
+
handleEvent(ev, callbacks, results, flowSummary);
|
|
732
|
+
}
|
|
733
|
+
} else {
|
|
734
|
+
handleEvent(parsed, callbacks, results, flowSummary);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
219
737
|
const contentType = response.headers.get("content-type");
|
|
220
738
|
if (contentType?.includes("application/json")) {
|
|
221
739
|
try {
|
|
@@ -272,8 +790,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
272
790
|
buffer = remainingBuffer;
|
|
273
791
|
for (const eventStr of events) {
|
|
274
792
|
try {
|
|
275
|
-
|
|
276
|
-
handleEvent(event, callbacks, results, flowSummary);
|
|
793
|
+
dispatch(JSON.parse(eventStr));
|
|
277
794
|
} catch {
|
|
278
795
|
console.warn("Failed to parse SSE event:", eventStr);
|
|
279
796
|
}
|
|
@@ -282,8 +799,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
282
799
|
const finalEvent = parseFinalBuffer(buffer);
|
|
283
800
|
if (finalEvent) {
|
|
284
801
|
try {
|
|
285
|
-
|
|
286
|
-
handleEvent(event, callbacks, results, flowSummary);
|
|
802
|
+
dispatch(JSON.parse(finalEvent));
|
|
287
803
|
} catch {
|
|
288
804
|
}
|
|
289
805
|
}
|
|
@@ -353,10 +869,17 @@ function handleEvent(event, callbacks, results, summary) {
|
|
|
353
869
|
break;
|
|
354
870
|
}
|
|
355
871
|
}
|
|
356
|
-
async function* streamEvents(response) {
|
|
872
|
+
async function* streamEvents(response, options = {}) {
|
|
357
873
|
if (!response.ok) {
|
|
358
874
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
359
875
|
}
|
|
876
|
+
let translate = options.unified === true ? createFlowEventTranslator() : null;
|
|
877
|
+
const autoDetect = options.unified === void 0;
|
|
878
|
+
const maybeDetect = (parsed) => {
|
|
879
|
+
if (autoDetect && !translate && isUnifiedEventType(parsed?.type)) {
|
|
880
|
+
translate = createFlowEventTranslator();
|
|
881
|
+
}
|
|
882
|
+
};
|
|
360
883
|
const contentType = response.headers.get("content-type");
|
|
361
884
|
if (contentType?.includes("application/json")) {
|
|
362
885
|
try {
|
|
@@ -386,19 +909,35 @@ async function* streamEvents(response) {
|
|
|
386
909
|
const { events, remainingBuffer } = parseSSEChunk(chunk, buffer);
|
|
387
910
|
buffer = remainingBuffer;
|
|
388
911
|
for (const eventStr of events) {
|
|
912
|
+
let parsed;
|
|
389
913
|
try {
|
|
390
|
-
|
|
391
|
-
yield event;
|
|
914
|
+
parsed = JSON.parse(eventStr);
|
|
392
915
|
} catch {
|
|
916
|
+
continue;
|
|
917
|
+
}
|
|
918
|
+
maybeDetect(parsed);
|
|
919
|
+
if (translate) {
|
|
920
|
+
for (const ev of translate(parsed)) yield ev;
|
|
921
|
+
} else {
|
|
922
|
+
yield parsed;
|
|
393
923
|
}
|
|
394
924
|
}
|
|
395
925
|
}
|
|
396
926
|
const finalEvent = parseFinalBuffer(buffer);
|
|
397
927
|
if (finalEvent) {
|
|
928
|
+
let parsed;
|
|
398
929
|
try {
|
|
399
|
-
|
|
400
|
-
yield event;
|
|
930
|
+
parsed = JSON.parse(finalEvent);
|
|
401
931
|
} catch {
|
|
932
|
+
parsed = void 0;
|
|
933
|
+
}
|
|
934
|
+
if (parsed !== void 0) {
|
|
935
|
+
maybeDetect(parsed);
|
|
936
|
+
if (translate) {
|
|
937
|
+
for (const ev of translate(parsed)) yield ev;
|
|
938
|
+
} else {
|
|
939
|
+
yield parsed;
|
|
940
|
+
}
|
|
402
941
|
}
|
|
403
942
|
}
|
|
404
943
|
} finally {
|
|
@@ -408,10 +947,16 @@ async function* streamEvents(response) {
|
|
|
408
947
|
|
|
409
948
|
// src/flow-result.ts
|
|
410
949
|
var FlowResult = class {
|
|
411
|
-
|
|
950
|
+
/**
|
|
951
|
+
* @param options.unified - The response is a unified-vocabulary SSE stream
|
|
952
|
+
* (`/dispatch` since the unified-SSE cutover). Set by dispatch call sites;
|
|
953
|
+
* left unset by the still-legacy eval stream producer.
|
|
954
|
+
*/
|
|
955
|
+
constructor(response, summary, options = {}) {
|
|
412
956
|
this.consumed = false;
|
|
413
957
|
this.cachedSummary = null;
|
|
414
958
|
this.response = response;
|
|
959
|
+
this.streamOptions = options;
|
|
415
960
|
if (summary) {
|
|
416
961
|
this.cachedSummary = summary;
|
|
417
962
|
this.consumed = true;
|
|
@@ -464,7 +1009,7 @@ var FlowResult = class {
|
|
|
464
1009
|
}
|
|
465
1010
|
this.ensureNotConsumed();
|
|
466
1011
|
this.consumed = true;
|
|
467
|
-
this.cachedSummary = await processStream(this.response, callbacks);
|
|
1012
|
+
this.cachedSummary = await processStream(this.response, callbacks, this.streamOptions);
|
|
468
1013
|
return this.cachedSummary;
|
|
469
1014
|
}
|
|
470
1015
|
/**
|
|
@@ -488,6 +1033,7 @@ var FlowResult = class {
|
|
|
488
1033
|
* const analysis = await result.getResult('analyze screenshot') // ✗ undefined
|
|
489
1034
|
* ```
|
|
490
1035
|
*/
|
|
1036
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK step results are intentionally untyped (FlowSummary.results is Map<string, any>); consumers narrow at the use site
|
|
491
1037
|
async getResult(stepName) {
|
|
492
1038
|
const summary = await this.ensureSummary();
|
|
493
1039
|
if (summary.results.has(stepName)) {
|
|
@@ -508,6 +1054,7 @@ var FlowResult = class {
|
|
|
508
1054
|
* }
|
|
509
1055
|
* ```
|
|
510
1056
|
*/
|
|
1057
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- SDK step results are intentionally untyped (FlowSummary.results is Map<string, any>); consumers narrow at the use site
|
|
511
1058
|
async getAllResults() {
|
|
512
1059
|
const summary = await this.ensureSummary();
|
|
513
1060
|
return summary.results;
|
|
@@ -1310,9 +1857,9 @@ var FlowBuilder = class {
|
|
|
1310
1857
|
}
|
|
1311
1858
|
const response = await client.dispatch(config);
|
|
1312
1859
|
if (callbacks) {
|
|
1313
|
-
return processStream(response, callbacks);
|
|
1860
|
+
return processStream(response, callbacks, { unified: true });
|
|
1314
1861
|
}
|
|
1315
|
-
return new FlowResult(response);
|
|
1862
|
+
return new FlowResult(response, void 0, { unified: true });
|
|
1316
1863
|
}
|
|
1317
1864
|
/**
|
|
1318
1865
|
* Set a run condition (when predicate) on the last added step.
|
|
@@ -1444,9 +1991,9 @@ var ClientFlowBuilder = class extends FlowBuilder {
|
|
|
1444
1991
|
}
|
|
1445
1992
|
const response = await dispatchClient.dispatch(config);
|
|
1446
1993
|
if (runCallbacks) {
|
|
1447
|
-
return processStream(response, runCallbacks);
|
|
1994
|
+
return processStream(response, runCallbacks, { unified: true });
|
|
1448
1995
|
}
|
|
1449
|
-
return new FlowResult(response);
|
|
1996
|
+
return new FlowResult(response, void 0, { unified: true });
|
|
1450
1997
|
}
|
|
1451
1998
|
};
|
|
1452
1999
|
function isStreamCallbacks(obj) {
|
|
@@ -2464,7 +3011,7 @@ var RuntypeFlowBuilder = class {
|
|
|
2464
3011
|
config.options = { ...config.options, streamResponse: true };
|
|
2465
3012
|
const client = this.getClient();
|
|
2466
3013
|
const response = await this.dispatchWithPersistedFlow(client, config);
|
|
2467
|
-
const result = new FlowResult(response);
|
|
3014
|
+
const result = new FlowResult(response, void 0, { unified: true });
|
|
2468
3015
|
if (callbacks) {
|
|
2469
3016
|
await result.stream(callbacks);
|
|
2470
3017
|
}
|
|
@@ -2493,7 +3040,7 @@ var RuntypeFlowBuilder = class {
|
|
|
2493
3040
|
config.options = { ...config.options, streamResponse: true };
|
|
2494
3041
|
const client = this.getClient();
|
|
2495
3042
|
const response = await this.dispatchWithPersistedFlow(client, config);
|
|
2496
|
-
const result = new FlowResult(response);
|
|
3043
|
+
const result = new FlowResult(response, void 0, { unified: true });
|
|
2497
3044
|
await result.getSummary();
|
|
2498
3045
|
return result;
|
|
2499
3046
|
}
|
|
@@ -2528,7 +3075,7 @@ var RuntypeFlowBuilder = class {
|
|
|
2528
3075
|
onError: (error) => callbacks?.onError?.(error)
|
|
2529
3076
|
};
|
|
2530
3077
|
try {
|
|
2531
|
-
for await (const event of streamEvents(response)) {
|
|
3078
|
+
for await (const event of streamEvents(response, { unified: true })) {
|
|
2532
3079
|
collectLocalToolAwait(pausedTools, event);
|
|
2533
3080
|
switch (event.type) {
|
|
2534
3081
|
case "flow_start":
|
|
@@ -2636,7 +3183,7 @@ var RuntypeFlowBuilder = class {
|
|
|
2636
3183
|
streamResponse: isStreaming
|
|
2637
3184
|
};
|
|
2638
3185
|
if (isStreaming) {
|
|
2639
|
-
currentResponse = await client.requestStream("/dispatch/resume", {
|
|
3186
|
+
currentResponse = await client.requestStream(withUnifiedEvents("/dispatch/resume"), {
|
|
2640
3187
|
method: "POST",
|
|
2641
3188
|
body: JSON.stringify(resumeData)
|
|
2642
3189
|
});
|
|
@@ -3069,138 +3616,10 @@ var EvalsNamespace = class {
|
|
|
3069
3616
|
};
|
|
3070
3617
|
|
|
3071
3618
|
// src/prompts-namespace.ts
|
|
3072
|
-
var PromptRunner = class {
|
|
3073
|
-
constructor(getClient, promptId, options) {
|
|
3074
|
-
this.getClient = getClient;
|
|
3075
|
-
this.promptId = promptId;
|
|
3076
|
-
this.options = options;
|
|
3077
|
-
}
|
|
3078
|
-
/**
|
|
3079
|
-
* Execute the prompt with streaming response
|
|
3080
|
-
*
|
|
3081
|
-
* Streams the prompt response as it's generated.
|
|
3082
|
-
*
|
|
3083
|
-
* @example
|
|
3084
|
-
* ```typescript
|
|
3085
|
-
* const result = await Runtype.prompts.run('prompt_123', {
|
|
3086
|
-
* recordId: 'rec_456'
|
|
3087
|
-
* }).stream()
|
|
3088
|
-
*
|
|
3089
|
-
* // Process with callbacks
|
|
3090
|
-
* await result.stream({
|
|
3091
|
-
* onStepDelta: (text) => process.stdout.write(text),
|
|
3092
|
-
* onFlowComplete: () => console.log('Done!'),
|
|
3093
|
-
* })
|
|
3094
|
-
* ```
|
|
3095
|
-
*/
|
|
3096
|
-
async stream(callbacks) {
|
|
3097
|
-
const client = this.getClient();
|
|
3098
|
-
const payload = this.buildPayload();
|
|
3099
|
-
payload.stream = true;
|
|
3100
|
-
const response = await client.requestStream(`/prompts/${this.promptId}/run`, {
|
|
3101
|
-
method: "POST",
|
|
3102
|
-
body: JSON.stringify(payload)
|
|
3103
|
-
});
|
|
3104
|
-
const result = new FlowResult(response);
|
|
3105
|
-
if (callbacks) {
|
|
3106
|
-
await result.stream(callbacks);
|
|
3107
|
-
}
|
|
3108
|
-
return result;
|
|
3109
|
-
}
|
|
3110
|
-
/**
|
|
3111
|
-
* Execute the prompt and wait for complete result
|
|
3112
|
-
*
|
|
3113
|
-
* Waits for the entire response before returning.
|
|
3114
|
-
*
|
|
3115
|
-
* @example
|
|
3116
|
-
* ```typescript
|
|
3117
|
-
* const result = await Runtype.prompts.run('prompt_123', {
|
|
3118
|
-
* recordId: 'rec_456'
|
|
3119
|
-
* }).result()
|
|
3120
|
-
*
|
|
3121
|
-
* const output = await result.getResult('prompt')
|
|
3122
|
-
* console.log(output)
|
|
3123
|
-
* ```
|
|
3124
|
-
*/
|
|
3125
|
-
async result() {
|
|
3126
|
-
const client = this.getClient();
|
|
3127
|
-
const payload = this.buildPayload();
|
|
3128
|
-
payload.stream = true;
|
|
3129
|
-
const response = await client.requestStream(`/prompts/${this.promptId}/run`, {
|
|
3130
|
-
method: "POST",
|
|
3131
|
-
body: JSON.stringify(payload)
|
|
3132
|
-
});
|
|
3133
|
-
const result = new FlowResult(response);
|
|
3134
|
-
await result.getSummary();
|
|
3135
|
-
return result;
|
|
3136
|
-
}
|
|
3137
|
-
/**
|
|
3138
|
-
* Build the run payload
|
|
3139
|
-
*/
|
|
3140
|
-
buildPayload() {
|
|
3141
|
-
const payload = {};
|
|
3142
|
-
if (this.options.recordId) {
|
|
3143
|
-
payload.recordId = this.options.recordId;
|
|
3144
|
-
} else if (this.options.record) {
|
|
3145
|
-
payload.record = this.options.record;
|
|
3146
|
-
}
|
|
3147
|
-
if (this.options.modelOverride) {
|
|
3148
|
-
payload.modelOverride = this.options.modelOverride;
|
|
3149
|
-
}
|
|
3150
|
-
if (this.options.temperature !== void 0) {
|
|
3151
|
-
payload.temperature = this.options.temperature;
|
|
3152
|
-
}
|
|
3153
|
-
if (this.options.topP !== void 0) {
|
|
3154
|
-
payload.topP = this.options.topP;
|
|
3155
|
-
}
|
|
3156
|
-
if (this.options.topK !== void 0) {
|
|
3157
|
-
payload.topK = this.options.topK;
|
|
3158
|
-
}
|
|
3159
|
-
if (this.options.frequencyPenalty !== void 0) {
|
|
3160
|
-
payload.frequencyPenalty = this.options.frequencyPenalty;
|
|
3161
|
-
}
|
|
3162
|
-
if (this.options.presencePenalty !== void 0) {
|
|
3163
|
-
payload.presencePenalty = this.options.presencePenalty;
|
|
3164
|
-
}
|
|
3165
|
-
if (this.options.seed !== void 0) {
|
|
3166
|
-
payload.seed = this.options.seed;
|
|
3167
|
-
}
|
|
3168
|
-
if (this.options.maxTokens !== void 0) {
|
|
3169
|
-
payload.maxTokens = this.options.maxTokens;
|
|
3170
|
-
}
|
|
3171
|
-
if (this.options.storeResult !== void 0) {
|
|
3172
|
-
payload.storeResult = this.options.storeResult;
|
|
3173
|
-
}
|
|
3174
|
-
return payload;
|
|
3175
|
-
}
|
|
3176
|
-
};
|
|
3177
3619
|
var PromptsNamespace = class {
|
|
3178
3620
|
constructor(getClient) {
|
|
3179
3621
|
this.getClient = getClient;
|
|
3180
3622
|
}
|
|
3181
|
-
/**
|
|
3182
|
-
* Run a prompt
|
|
3183
|
-
*
|
|
3184
|
-
* Returns a PromptRunner with terminal methods:
|
|
3185
|
-
* - .stream() - Execute and stream results
|
|
3186
|
-
* - .result() - Execute and wait for complete result
|
|
3187
|
-
*
|
|
3188
|
-
* @example
|
|
3189
|
-
* ```typescript
|
|
3190
|
-
* // Stream the response
|
|
3191
|
-
* const result = await Runtype.prompts.run('prompt_123', {
|
|
3192
|
-
* recordId: 'rec_456'
|
|
3193
|
-
* }).stream()
|
|
3194
|
-
*
|
|
3195
|
-
* // Get complete result
|
|
3196
|
-
* const result = await Runtype.prompts.run('prompt_123', {
|
|
3197
|
-
* record: { name: 'Test', metadata: { input: 'Hello' } }
|
|
3198
|
-
* }).result()
|
|
3199
|
-
* ```
|
|
3200
|
-
*/
|
|
3201
|
-
run(promptId, options = {}) {
|
|
3202
|
-
return new PromptRunner(this.getClient, promptId, options);
|
|
3203
|
-
}
|
|
3204
3623
|
/**
|
|
3205
3624
|
* Create a new prompt
|
|
3206
3625
|
*
|
|
@@ -4880,7 +5299,7 @@ var RuntypeClient = class {
|
|
|
4880
5299
|
* Dispatch flow execution (streaming)
|
|
4881
5300
|
*/
|
|
4882
5301
|
async dispatch(config) {
|
|
4883
|
-
return this.requestStream("/dispatch", {
|
|
5302
|
+
return this.requestStream(withUnifiedEvents("/dispatch"), {
|
|
4884
5303
|
method: "POST",
|
|
4885
5304
|
body: JSON.stringify(transformRequest(config))
|
|
4886
5305
|
});
|
|
@@ -5251,7 +5670,7 @@ var Runtype = class {
|
|
|
5251
5670
|
|
|
5252
5671
|
// src/version.ts
|
|
5253
5672
|
var FALLBACK_VERSION = "0.0.0";
|
|
5254
|
-
var SDK_VERSION = "
|
|
5673
|
+
var SDK_VERSION = "5.0.0".length > 0 ? "5.0.0" : FALLBACK_VERSION;
|
|
5255
5674
|
var RUNTYPE_CLIENT_KIND = "sdk";
|
|
5256
5675
|
var SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
|
|
5257
5676
|
|
|
@@ -7374,12 +7793,6 @@ var PromptsEndpoint = class {
|
|
|
7374
7793
|
async delete(id) {
|
|
7375
7794
|
return this.client.delete(`/prompts/${id}`);
|
|
7376
7795
|
}
|
|
7377
|
-
/**
|
|
7378
|
-
* Run a prompt on a specific record
|
|
7379
|
-
*/
|
|
7380
|
-
async runOnRecord(id, recordId) {
|
|
7381
|
-
return this.client.post(`/prompts/${id}/run-on-record`, { recordId });
|
|
7382
|
-
}
|
|
7383
7796
|
/**
|
|
7384
7797
|
* Get flows using this prompt
|
|
7385
7798
|
*/
|
|
@@ -7745,7 +8158,7 @@ var DispatchEndpoint = class {
|
|
|
7745
8158
|
* Dispatch with streaming response
|
|
7746
8159
|
*/
|
|
7747
8160
|
async executeStream(data) {
|
|
7748
|
-
return this.client.requestStream("/dispatch", {
|
|
8161
|
+
return this.client.requestStream(withUnifiedEvents("/dispatch"), {
|
|
7749
8162
|
method: "POST",
|
|
7750
8163
|
body: JSON.stringify(data)
|
|
7751
8164
|
});
|
|
@@ -7761,7 +8174,7 @@ var DispatchEndpoint = class {
|
|
|
7761
8174
|
*/
|
|
7762
8175
|
async resume(data) {
|
|
7763
8176
|
if (data.streamResponse) {
|
|
7764
|
-
return this.client.requestStream("/dispatch/resume", {
|
|
8177
|
+
return this.client.requestStream(withUnifiedEvents("/dispatch/resume"), {
|
|
7765
8178
|
method: "POST",
|
|
7766
8179
|
body: JSON.stringify(data)
|
|
7767
8180
|
});
|
|
@@ -8276,6 +8689,19 @@ async function processAgentStream(body, callbacks) {
|
|
|
8276
8689
|
const reader = body.getReader();
|
|
8277
8690
|
const decoder = new TextDecoder();
|
|
8278
8691
|
let buffer = "";
|
|
8692
|
+
let translate = null;
|
|
8693
|
+
const dispatch = (event) => {
|
|
8694
|
+
if (!translate && isUnifiedEventType(event.data?.type ?? event.eventType)) {
|
|
8695
|
+
translate = createAgentEventTranslator();
|
|
8696
|
+
}
|
|
8697
|
+
if (translate) {
|
|
8698
|
+
for (const legacy of translate(event.data)) {
|
|
8699
|
+
dispatchAgentEvent({ eventType: legacy.type, data: legacy }, callbacks);
|
|
8700
|
+
}
|
|
8701
|
+
} else {
|
|
8702
|
+
dispatchAgentEvent(event, callbacks);
|
|
8703
|
+
}
|
|
8704
|
+
};
|
|
8279
8705
|
try {
|
|
8280
8706
|
while (true) {
|
|
8281
8707
|
const { done, value } = await reader.read();
|
|
@@ -8283,7 +8709,7 @@ async function processAgentStream(body, callbacks) {
|
|
|
8283
8709
|
if (buffer.trim()) {
|
|
8284
8710
|
const { events: events2 } = parseSSEChunkWithEventType(buffer + "\n\n", "");
|
|
8285
8711
|
for (const event of events2) {
|
|
8286
|
-
|
|
8712
|
+
dispatch(event);
|
|
8287
8713
|
}
|
|
8288
8714
|
}
|
|
8289
8715
|
break;
|
|
@@ -8292,7 +8718,7 @@ async function processAgentStream(body, callbacks) {
|
|
|
8292
8718
|
const { events, remainingBuffer } = parseSSEChunkWithEventType(chunk, buffer);
|
|
8293
8719
|
buffer = remainingBuffer;
|
|
8294
8720
|
for (const event of events) {
|
|
8295
|
-
|
|
8721
|
+
dispatch(event);
|
|
8296
8722
|
}
|
|
8297
8723
|
}
|
|
8298
8724
|
} finally {
|
|
@@ -8480,7 +8906,7 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
8480
8906
|
* ```
|
|
8481
8907
|
*/
|
|
8482
8908
|
async executeStream(id, data, init) {
|
|
8483
|
-
return this.client.requestStream(`/agents/${id}/execute
|
|
8909
|
+
return this.client.requestStream(withUnifiedEvents(`/agents/${id}/execute`), {
|
|
8484
8910
|
method: "POST",
|
|
8485
8911
|
body: JSON.stringify({
|
|
8486
8912
|
...data,
|
|
@@ -8832,16 +9258,19 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
8832
9258
|
}
|
|
8833
9259
|
let resumeResponse;
|
|
8834
9260
|
try {
|
|
8835
|
-
resumeResponse = await this.client.requestStream(
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
|
|
9261
|
+
resumeResponse = await this.client.requestStream(
|
|
9262
|
+
withUnifiedEvents(`/agents/${id}/resume`),
|
|
9263
|
+
{
|
|
9264
|
+
method: "POST",
|
|
9265
|
+
body: JSON.stringify({
|
|
9266
|
+
executionId,
|
|
9267
|
+
toolOutputs: { [toolName]: toolResult },
|
|
9268
|
+
streamResponse: true,
|
|
9269
|
+
debugMode: data.debugMode
|
|
9270
|
+
}),
|
|
9271
|
+
...abortSignal ? { signal: abortSignal } : {}
|
|
9272
|
+
}
|
|
9273
|
+
);
|
|
8845
9274
|
} catch (error) {
|
|
8846
9275
|
if (abortSignal?.aborted) return finishAborted(executionId);
|
|
8847
9276
|
throw error;
|
|
@@ -10306,9 +10735,9 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
10306
10735
|
}
|
|
10307
10736
|
/** Returns true if a server-side session error message indicates a transient
|
|
10308
10737
|
* network failure that is safe to retry. */
|
|
10309
|
-
static isRetryableSessionError(
|
|
10310
|
-
if (!
|
|
10311
|
-
const lower =
|
|
10738
|
+
static isRetryableSessionError(errorMessage2) {
|
|
10739
|
+
if (!errorMessage2) return false;
|
|
10740
|
+
const lower = errorMessage2.toLowerCase();
|
|
10312
10741
|
return _AgentsEndpoint.RETRYABLE_SESSION_ERROR_PATTERNS.some(
|
|
10313
10742
|
(pattern) => lower.includes(pattern)
|
|
10314
10743
|
);
|
|
@@ -11760,7 +12189,7 @@ var RuntypeClient2 = class {
|
|
|
11760
12189
|
success: true
|
|
11761
12190
|
};
|
|
11762
12191
|
try {
|
|
11763
|
-
for await (const event of streamEvents(response)) {
|
|
12192
|
+
for await (const event of streamEvents(response, { unified: true })) {
|
|
11764
12193
|
collectLocalToolAwait(pausedTools, event);
|
|
11765
12194
|
switch (event.type) {
|
|
11766
12195
|
case "flow_start":
|
|
@@ -12915,7 +13344,6 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
12915
13344
|
ProductDriftError,
|
|
12916
13345
|
ProductEnsureConflictError,
|
|
12917
13346
|
ProductsNamespace,
|
|
12918
|
-
PromptRunner,
|
|
12919
13347
|
PromptsEndpoint,
|
|
12920
13348
|
PromptsNamespace,
|
|
12921
13349
|
ProviderKeysEndpoint,
|
|
@@ -12944,6 +13372,7 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
12944
13372
|
ToolEnsureConflictError,
|
|
12945
13373
|
ToolsEndpoint,
|
|
12946
13374
|
ToolsNamespace,
|
|
13375
|
+
UNIFIED_EVENTS_QUERY,
|
|
12947
13376
|
UsersEndpoint,
|
|
12948
13377
|
applyGeneratedRuntimeToolProposalToDispatchRequest,
|
|
12949
13378
|
attachRuntimeToolsToDispatchRequest,
|
|
@@ -12960,8 +13389,10 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
12960
13389
|
computeSkillContentHash,
|
|
12961
13390
|
computeSurfaceContentHash,
|
|
12962
13391
|
computeToolContentHash,
|
|
13392
|
+
createAgentEventTranslator,
|
|
12963
13393
|
createClient,
|
|
12964
13394
|
createExternalTool,
|
|
13395
|
+
createFlowEventTranslator,
|
|
12965
13396
|
defaultWorkflow,
|
|
12966
13397
|
defaultWorkflowConfig,
|
|
12967
13398
|
defineAgent,
|
|
@@ -12984,6 +13415,7 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
12984
13415
|
isDiscoveryToolName,
|
|
12985
13416
|
isMarathonArtifactPath,
|
|
12986
13417
|
isPreservationSensitiveTask,
|
|
13418
|
+
isUnifiedEventType,
|
|
12987
13419
|
isWorkflowHookRef,
|
|
12988
13420
|
listWorkflowHooks,
|
|
12989
13421
|
normalizeAgentDefinition,
|
|
@@ -13006,5 +13438,6 @@ var STEP_TYPE_TO_METHOD = {
|
|
|
13006
13438
|
shouldInjectEmptySessionNudge,
|
|
13007
13439
|
shouldRequestModelEscalation,
|
|
13008
13440
|
streamEvents,
|
|
13009
|
-
unregisterWorkflowHook
|
|
13441
|
+
unregisterWorkflowHook,
|
|
13442
|
+
withUnifiedEvents
|
|
13010
13443
|
});
|