@relayflows/sdk 2.0.10 → 2.0.12
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/adapters/base.d.ts +6 -0
- package/dist/adapters/base.d.ts.map +1 -1
- package/dist/adapters/claude.d.ts.map +1 -1
- package/dist/adapters/claude.js +1 -0
- package/dist/adapters/claude.js.map +1 -1
- package/dist/agent-relay-receipt.d.ts +24 -0
- package/dist/agent-relay-receipt.d.ts.map +1 -0
- package/dist/agent-relay-receipt.js +66 -0
- package/dist/agent-relay-receipt.js.map +1 -0
- package/dist/agent-relay-state.d.ts +18 -0
- package/dist/agent-relay-state.d.ts.map +1 -0
- package/dist/agent-relay-state.js +58 -0
- package/dist/agent-relay-state.js.map +1 -0
- package/dist/agent-relay-transport.d.ts +17 -70
- package/dist/agent-relay-transport.d.ts.map +1 -1
- package/dist/agent-relay-transport.js +177 -112
- package/dist/agent-relay-transport.js.map +1 -1
- package/dist/authored-admission.d.ts +5 -0
- package/dist/authored-admission.d.ts.map +1 -0
- package/dist/authored-admission.js +14 -0
- package/dist/authored-admission.js.map +1 -0
- package/dist/authored-budget.d.ts +1 -1
- package/dist/authored-budget.d.ts.map +1 -1
- package/dist/authored-budget.js +3 -3
- package/dist/authored-budget.js.map +1 -1
- package/dist/authored-flow-error.d.ts +1 -1
- package/dist/authored-flow-error.d.ts.map +1 -1
- package/dist/authored-flow-error.js.map +1 -1
- package/dist/authored-flow-executor.d.ts +10 -0
- package/dist/authored-flow-executor.d.ts.map +1 -1
- package/dist/authored-flow-executor.js +10 -7
- package/dist/authored-flow-executor.js.map +1 -1
- package/dist/authored-flow-loader.d.ts +20 -0
- package/dist/authored-flow-loader.d.ts.map +1 -1
- package/dist/authored-flow-loader.js +86 -11
- package/dist/authored-flow-loader.js.map +1 -1
- package/dist/authored-helper-effect.d.ts +1 -1
- package/dist/authored-helper-effect.d.ts.map +1 -1
- package/dist/authored-helper-effect.js +5 -3
- package/dist/authored-helper-effect.js.map +1 -1
- package/dist/authored-mcp.d.ts +1 -1
- package/dist/authored-mcp.d.ts.map +1 -1
- package/dist/authored-mcp.js +7 -4
- package/dist/authored-mcp.js.map +1 -1
- package/dist/authored-node-entry.d.ts +2 -0
- package/dist/authored-node-entry.d.ts.map +1 -0
- package/dist/authored-node-entry.js +111 -0
- package/dist/authored-node-entry.js.map +1 -0
- package/dist/authored-node-runner.d.ts +11 -0
- package/dist/authored-node-runner.d.ts.map +1 -0
- package/dist/authored-node-runner.js +246 -0
- package/dist/authored-node-runner.js.map +1 -0
- package/dist/authored-plugin-effect.d.ts +1 -1
- package/dist/authored-plugin-effect.d.ts.map +1 -1
- package/dist/authored-plugin-effect.js +7 -4
- package/dist/authored-plugin-effect.js.map +1 -1
- package/dist/authored-root.d.ts +38 -0
- package/dist/authored-root.d.ts.map +1 -0
- package/dist/authored-root.js +329 -0
- package/dist/authored-root.js.map +1 -0
- package/dist/authored-runtime-capability.d.ts +6 -0
- package/dist/authored-runtime-capability.d.ts.map +1 -0
- package/dist/authored-runtime-capability.js +40 -0
- package/dist/authored-runtime-capability.js.map +1 -0
- package/dist/authored-source-authority.d.ts +4 -0
- package/dist/authored-source-authority.d.ts.map +1 -0
- package/dist/authored-source-authority.js +61 -0
- package/dist/authored-source-authority.js.map +1 -0
- package/dist/authored-worker-step.d.ts +2 -2
- package/dist/authored-worker-step.d.ts.map +1 -1
- package/dist/authored-worker-step.js +11 -6
- package/dist/authored-worker-step.js.map +1 -1
- package/dist/budget-preflight.d.ts +17 -3
- package/dist/budget-preflight.d.ts.map +1 -1
- package/dist/budget-preflight.js +31 -24
- package/dist/budget-preflight.js.map +1 -1
- package/dist/cli/check.js +3 -1
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/direct-run.d.ts.map +1 -1
- package/dist/cli/direct-run.js +18 -14
- package/dist/cli/direct-run.js.map +1 -1
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +56 -1
- package/dist/cli/run.js.map +1 -1
- package/dist/cli-adapter.d.ts +16 -0
- package/dist/cli-adapter.d.ts.map +1 -1
- package/dist/cli-adapter.js +17 -0
- package/dist/cli-adapter.js.map +1 -1
- package/dist/cli.js +4 -4
- package/dist/cli.js.map +1 -1
- package/dist/cloud-run.d.ts +11 -1
- package/dist/cloud-run.d.ts.map +1 -1
- package/dist/cloud-run.js +65 -19
- package/dist/cloud-run.js.map +1 -1
- package/dist/failure-kinds.d.ts +7 -3
- package/dist/failure-kinds.d.ts.map +1 -1
- package/dist/failure-kinds.js +5 -1
- package/dist/failure-kinds.js.map +1 -1
- package/dist/journal-client.d.ts +1 -1
- package/dist/journal-client.d.ts.map +1 -1
- package/dist/journal-client.js +6 -2
- package/dist/journal-client.js.map +1 -1
- package/dist/llm-worker.d.ts.map +1 -1
- package/dist/llm-worker.js +4 -2
- package/dist/llm-worker.js.map +1 -1
- package/dist/local-agent.d.ts +1 -1
- package/dist/local-agent.d.ts.map +1 -1
- package/dist/local-agent.js +2 -2
- package/dist/local-agent.js.map +1 -1
- package/dist/model-pricing.d.ts +3 -4
- package/dist/model-pricing.d.ts.map +1 -1
- package/dist/model-pricing.js +4 -4
- package/dist/model-pricing.js.map +1 -1
- package/dist/preflight.d.ts +4 -1
- package/dist/preflight.d.ts.map +1 -1
- package/dist/preflight.js +36 -18
- package/dist/preflight.js.map +1 -1
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/spec.d.ts +5 -4
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/worker-cli.d.ts +5 -2
- package/dist/worker-cli.d.ts.map +1 -1
- package/dist/worker-cli.js +43 -46
- package/dist/worker-cli.js.map +1 -1
- package/dist/worker-spend.d.ts +4 -3
- package/dist/worker-spend.d.ts.map +1 -1
- package/dist/worker-spend.js +13 -4
- package/dist/worker-spend.js.map +1 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +12 -4
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/base.ts +7 -0
- package/src/adapters/claude.ts +1 -0
- package/src/agent-relay-receipt.ts +120 -0
- package/src/agent-relay-state.ts +73 -0
- package/src/agent-relay-transport.ts +242 -156
- package/src/authored-admission.ts +17 -0
- package/src/authored-budget.ts +4 -3
- package/src/authored-flow-error.ts +0 -1
- package/src/authored-flow-executor.ts +27 -7
- package/src/authored-flow-loader.ts +96 -13
- package/src/authored-helper-effect.ts +5 -3
- package/src/authored-mcp.ts +6 -4
- package/src/authored-node-entry.ts +90 -0
- package/src/authored-node-runner.ts +219 -0
- package/src/authored-plugin-effect.ts +6 -3
- package/src/authored-root.ts +396 -0
- package/src/authored-runtime-capability.ts +40 -0
- package/src/authored-source-authority.ts +62 -0
- package/src/authored-worker-step.ts +15 -4
- package/src/budget-preflight.ts +41 -25
- package/src/cli/check.ts +3 -1
- package/src/cli/direct-run.ts +24 -16
- package/src/cli/run.ts +58 -1
- package/src/cli-adapter.ts +27 -0
- package/src/cli.ts +5 -5
- package/src/cloud-run.ts +74 -21
- package/src/failure-kinds.ts +5 -1
- package/src/journal-client.ts +6 -2
- package/src/llm-worker.ts +4 -2
- package/src/local-agent.ts +7 -2
- package/src/model-pricing.ts +4 -4
- package/src/preflight.ts +40 -18
- package/src/protocol.ts +2 -0
- package/src/spec.ts +5 -4
- package/src/worker-cli.ts +50 -54
- package/src/worker-spend.ts +15 -4
- package/src/worker.ts +12 -4
|
@@ -1,134 +1,199 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* ends up shelling out to the `agent-relay` CLI, which is fragile.
|
|
8
|
-
*
|
|
9
|
-
* This module speaks to agent-relay via structured HTTP: the same call
|
|
10
|
-
* shape the `mcp__agent-relay__spawn` MCP tool posts. The SDK becomes a
|
|
11
|
-
* first-class agent-relay participant, registered under a derived agent
|
|
12
|
-
* name a caller can DM against.
|
|
13
|
-
*
|
|
14
|
-
* Scope: spawn + close. Streaming inbox and observation are follow-ups.
|
|
15
|
-
*/
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { claimRelayTask } from "./agent-relay-state.js";
|
|
5
|
+
import { canonicalize } from "./canonical.js";
|
|
6
|
+
import { isRecord, nonempty, readTaskReceipt, } from "./agent-relay-receipt.js";
|
|
16
7
|
export class AgentRelayTransportError extends Error {
|
|
17
8
|
cause;
|
|
18
9
|
constructor(message, cause) {
|
|
19
10
|
super(message);
|
|
20
11
|
this.cause = cause;
|
|
21
|
-
this.name =
|
|
12
|
+
this.name = "AgentRelayTransportError";
|
|
22
13
|
}
|
|
23
14
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Read the same env the relay MCP already consumes. Explicit override wins.
|
|
26
|
-
* Missing RELAY_API_KEY refuses immediately — the transport cannot proceed
|
|
27
|
-
* unauthenticated and the direct-spawn fallback is a separate decision.
|
|
28
|
-
*/
|
|
29
15
|
export function readAgentRelayEnv(env = process.env) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
throw new AgentRelayTransportError('agent-relay transport requires RELAY_API_KEY in the environment; falling back to direct transport is the caller\'s responsibility.');
|
|
34
|
-
}
|
|
16
|
+
const agentToken = env.RELAY_AGENT_TOKEN?.trim();
|
|
17
|
+
if (!agentToken)
|
|
18
|
+
throw new AgentRelayTransportError("Relay task transport requires a pre-provisioned RELAY_AGENT_TOKEN.");
|
|
35
19
|
return {
|
|
36
|
-
baseUrl,
|
|
37
|
-
|
|
38
|
-
workspaceId: env['RELAY_DEFAULT_WORKSPACE']?.trim() || undefined,
|
|
39
|
-
agentToken: env['RELAY_AGENT_TOKEN']?.trim() || undefined,
|
|
20
|
+
baseUrl: env.RELAY_BASE_URL?.trim() || "https://cast.agentrelay.com",
|
|
21
|
+
agentToken,
|
|
40
22
|
};
|
|
41
23
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* hitting the network.
|
|
49
|
-
*/
|
|
50
|
-
export async function agentRelaySpawn(request, env = {}) {
|
|
51
|
-
// Only fall back to process.env if the caller didn't supply the required
|
|
52
|
-
// fields directly. Tests pass { apiKey, fetch } inline; they shouldn't need
|
|
53
|
-
// to also set RELAY_API_KEY in the runner env.
|
|
54
|
-
const fromEnv = env.apiKey
|
|
55
|
-
? { baseUrl: env.baseUrl || 'https://cast.agentrelay.com' }
|
|
56
|
-
: readAgentRelayEnv();
|
|
57
|
-
const resolved = { ...fromEnv, ...env };
|
|
58
|
-
const url = new URL('/api/v1/agents/spawn', resolved.baseUrl).toString();
|
|
59
|
-
const doFetch = env.fetch ?? globalThis.fetch;
|
|
60
|
-
if (typeof doFetch !== 'function') {
|
|
61
|
-
throw new AgentRelayTransportError('global fetch is unavailable; provide { fetch } explicitly.');
|
|
62
|
-
}
|
|
63
|
-
const headers = {
|
|
64
|
-
'content-type': 'application/json',
|
|
65
|
-
'authorization': `Bearer ${resolved.apiKey}`,
|
|
66
|
-
};
|
|
67
|
-
if (resolved.workspaceId !== undefined)
|
|
68
|
-
headers['x-relay-workspace'] = resolved.workspaceId;
|
|
69
|
-
if (resolved.agentToken !== undefined)
|
|
70
|
-
headers['x-relay-agent-token'] = resolved.agentToken;
|
|
71
|
-
let response;
|
|
72
|
-
try {
|
|
73
|
-
response = await doFetch(url, {
|
|
74
|
-
method: 'POST',
|
|
75
|
-
headers,
|
|
76
|
-
body: JSON.stringify(request),
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
catch (cause) {
|
|
80
|
-
throw new AgentRelayTransportError(`agent-relay spawn network error at ${url}: ${cause.message ?? String(cause)}`, cause);
|
|
81
|
-
}
|
|
82
|
-
if (response.status < 200 || response.status >= 300) {
|
|
83
|
-
let body;
|
|
84
|
-
try {
|
|
85
|
-
body = (await response.text()).slice(0, 512);
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
body = '<no body>';
|
|
24
|
+
/** Exact Relaycast #436 HTTP contract. Only terminal GET receipts can return. */
|
|
25
|
+
export async function runAgentRelayTask(request, options = {}) {
|
|
26
|
+
const env = options.agentToken
|
|
27
|
+
? {
|
|
28
|
+
baseUrl: options.baseUrl || "https://cast.agentrelay.com",
|
|
29
|
+
agentToken: options.agentToken,
|
|
89
30
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
31
|
+
: { ...readAgentRelayEnv(), ...options };
|
|
32
|
+
const base = new URL(env.baseUrl);
|
|
33
|
+
if (base.username ||
|
|
34
|
+
base.password ||
|
|
35
|
+
base.search ||
|
|
36
|
+
base.hash ||
|
|
37
|
+
base.pathname !== "/" ||
|
|
38
|
+
!["https:", "http:"].includes(base.protocol))
|
|
39
|
+
throw new AgentRelayTransportError("Invalid Relay task base URL");
|
|
40
|
+
const loopback = base.hostname === "[::1]" ||
|
|
41
|
+
(isIP(base.hostname) === 4 && base.hostname.startsWith("127."));
|
|
42
|
+
if (base.protocol !== "https:" && !loopback) {
|
|
43
|
+
throw new AgentRelayTransportError("Relay task credentials require HTTPS outside literal loopback addresses");
|
|
95
44
|
}
|
|
96
|
-
|
|
97
|
-
|
|
45
|
+
const baseUrl = base.origin;
|
|
46
|
+
const timeoutMs = request.timeoutMs ?? 86_400_000;
|
|
47
|
+
if (!Number.isSafeInteger(timeoutMs) ||
|
|
48
|
+
timeoutMs < 1 ||
|
|
49
|
+
timeoutMs > 86_400_000 ||
|
|
50
|
+
![
|
|
51
|
+
request.runId,
|
|
52
|
+
request.stepId,
|
|
53
|
+
request.idempotencyKey,
|
|
54
|
+
request.dataDir,
|
|
55
|
+
request.cli,
|
|
56
|
+
].every(nonempty)) {
|
|
57
|
+
throw new AgentRelayTransportError("Relay task requires durable dispatch identity and a valid deadline");
|
|
98
58
|
}
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
59
|
+
const pollMs = options.pollMs ?? 1000;
|
|
60
|
+
if (!Number.isFinite(pollMs) || pollMs < 1)
|
|
61
|
+
throw new AgentRelayTransportError("Invalid Relay task polling interval");
|
|
62
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
63
|
+
const outer = options.signal ?? new AbortController().signal;
|
|
64
|
+
let deadline = Date.now() + timeoutMs + 30_000;
|
|
65
|
+
let missingDeadline = Date.now() + 30_000;
|
|
66
|
+
async function http(path, body) {
|
|
67
|
+
for (;;) {
|
|
68
|
+
outer.throwIfAborted();
|
|
69
|
+
if (Date.now() >= deadline)
|
|
70
|
+
throw new AgentRelayTransportError("Relay task status unavailable before its reconciliation deadline");
|
|
71
|
+
const bounded = AbortSignal.any([
|
|
72
|
+
outer,
|
|
73
|
+
AbortSignal.timeout(Math.min(15_000, Math.max(1, deadline - Date.now()))),
|
|
74
|
+
]);
|
|
75
|
+
let response;
|
|
76
|
+
let value;
|
|
111
77
|
try {
|
|
112
|
-
await doFetch(
|
|
113
|
-
method:
|
|
114
|
-
|
|
115
|
-
|
|
78
|
+
response = await doFetch(new URL(path, baseUrl), {
|
|
79
|
+
method: body === undefined ? "GET" : "POST",
|
|
80
|
+
redirect: "error",
|
|
81
|
+
signal: bounded,
|
|
82
|
+
headers: {
|
|
83
|
+
authorization: `Bearer ${env.agentToken}`,
|
|
84
|
+
"content-type": "application/json",
|
|
85
|
+
...(body === undefined
|
|
86
|
+
? {}
|
|
87
|
+
: { "Idempotency-Key": request.idempotencyKey }),
|
|
88
|
+
},
|
|
89
|
+
...(body === undefined ? {} : { body: canonicalize(body) }),
|
|
116
90
|
});
|
|
91
|
+
if (response.status === 404 &&
|
|
92
|
+
body === undefined &&
|
|
93
|
+
path.includes("/invocations/")) {
|
|
94
|
+
if (Date.now() >= missingDeadline)
|
|
95
|
+
throw new AgentRelayTransportError("Relay task dispatch remains unconfirmed; no repeat POST is permitted");
|
|
96
|
+
}
|
|
97
|
+
else if (!response.ok &&
|
|
98
|
+
response.status !== 429 &&
|
|
99
|
+
response.status < 500) {
|
|
100
|
+
// Never copy untrusted response bodies, URLs, or tokens into diagnostics.
|
|
101
|
+
throw new AgentRelayTransportError(`Relay task request refused with HTTP ${response.status}`);
|
|
102
|
+
}
|
|
103
|
+
if (response.ok)
|
|
104
|
+
value = await response.json();
|
|
105
|
+
if (body !== undefined && !response.ok)
|
|
106
|
+
return {}; // ambiguous POST: GET only below
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
outer.throwIfAborted();
|
|
110
|
+
if (error instanceof AgentRelayTransportError)
|
|
111
|
+
throw error;
|
|
112
|
+
if (body !== undefined)
|
|
113
|
+
return {}; // response loss or invalid JSON never causes another POST
|
|
114
|
+
if (response?.ok && !bounded.aborted)
|
|
115
|
+
throw new AgentRelayTransportError("Relay task response was not valid JSON");
|
|
117
116
|
}
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
outer.throwIfAborted();
|
|
118
|
+
if (response?.ok && value !== undefined) {
|
|
119
|
+
if (!isRecord(value) || value.ok !== true || !isRecord(value.data))
|
|
120
|
+
throw new AgentRelayTransportError("Relay task response has an invalid data envelope");
|
|
121
|
+
return value.data;
|
|
120
122
|
}
|
|
123
|
+
await delay(pollMs, undefined, { signal: outer });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Resolving the agent is read-only. Pin identity before any invocation so a
|
|
127
|
+
// restarted runner cannot create a second task using another caller's key.
|
|
128
|
+
const agent = await http("/v1/agent");
|
|
129
|
+
if (!nonempty(agent.id))
|
|
130
|
+
throw new AgentRelayTransportError("Relay task caller identity is missing");
|
|
131
|
+
if (!nonempty(agent.workspace_id))
|
|
132
|
+
throw new AgentRelayTransportError("Relay task workspace identity is missing");
|
|
133
|
+
// Pinned action-invoke-v1 identity contract from Relaycast #436.
|
|
134
|
+
const invocationId = "inv_idem_" +
|
|
135
|
+
createHash("sha256")
|
|
136
|
+
.update([
|
|
137
|
+
"action-invoke-v1",
|
|
138
|
+
agent.workspace_id,
|
|
139
|
+
agent.id,
|
|
140
|
+
"task.run",
|
|
141
|
+
request.idempotencyKey,
|
|
142
|
+
].join("\0"))
|
|
143
|
+
.digest("hex");
|
|
144
|
+
const input = {
|
|
145
|
+
cli: request.cli,
|
|
146
|
+
task: request.task,
|
|
147
|
+
...(request.model === undefined ? {} : { model: request.model }),
|
|
148
|
+
...(request.worker_cwd === undefined
|
|
149
|
+
? {}
|
|
150
|
+
: { worker_cwd: request.worker_cwd }),
|
|
151
|
+
...(request.result_schema === undefined
|
|
152
|
+
? {}
|
|
153
|
+
: { result_schema: request.result_schema }),
|
|
154
|
+
task_context: {
|
|
155
|
+
run_id: request.runId,
|
|
156
|
+
step_id: request.stepId,
|
|
157
|
+
dispatch_id: request.idempotencyKey,
|
|
158
|
+
timeout_ms: timeoutMs,
|
|
121
159
|
},
|
|
122
160
|
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
161
|
+
const { claim, created } = await claimRelayTask(request.dataDir, {
|
|
162
|
+
version: 1,
|
|
163
|
+
baseUrl,
|
|
164
|
+
callerId: agent.id,
|
|
165
|
+
workspaceId: agent.workspace_id,
|
|
166
|
+
invocationId,
|
|
167
|
+
runId: request.runId,
|
|
168
|
+
stepId: request.stepId,
|
|
169
|
+
idempotencyKey: request.idempotencyKey,
|
|
170
|
+
input,
|
|
171
|
+
startedAt: Date.now(),
|
|
172
|
+
});
|
|
173
|
+
// A restarted runner may recover a terminal receipt after the task deadline.
|
|
174
|
+
// Give that read one bounded window; never reopen or extend the remote task.
|
|
175
|
+
deadline = Math.max(claim.startedAt + timeoutMs + 30_000, Date.now() + 15_000);
|
|
176
|
+
missingDeadline = claim.startedAt + 30_000;
|
|
177
|
+
if (created) {
|
|
178
|
+
const ack = await http("/v1/actions/task.run/invoke", { input });
|
|
179
|
+
if (Object.keys(ack).length &&
|
|
180
|
+
(ack.invocation_id !== invocationId ||
|
|
181
|
+
ack.action_name !== "task.run" ||
|
|
182
|
+
canonicalize(ack.input) !== canonicalize(input))) {
|
|
183
|
+
throw new AgentRelayTransportError("Relay task acknowledgment has mismatched invocation or input");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
let previous;
|
|
187
|
+
for (;;) {
|
|
188
|
+
const value = await http(`/v1/actions/task.run/invocations/${encodeURIComponent(invocationId)}`);
|
|
189
|
+
if (value.caller_id !== agent.id)
|
|
190
|
+
throw new AgentRelayTransportError("Relay task receipt belongs to another caller");
|
|
191
|
+
const receipt = readTaskReceipt(value, invocationId, input, previous);
|
|
192
|
+
outer.throwIfAborted();
|
|
193
|
+
if (receipt.status === "completed" || receipt.status === "failed")
|
|
194
|
+
return receipt;
|
|
195
|
+
previous = receipt;
|
|
196
|
+
await delay(pollMs, undefined, { signal: outer });
|
|
197
|
+
}
|
|
133
198
|
}
|
|
134
199
|
//# sourceMappingURL=agent-relay-transport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-relay-transport.js","sourceRoot":"","sources":["../src/agent-relay-transport.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agent-relay-transport.js","sourceRoot":"","sources":["../src/agent-relay-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAA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;IACH,CAAC;IACD,IAAI,QAAsC,CAAC;IAC3C,SAAS,CAAC;QACR,MAAM,KAAK,GAAG,MAAM,IAAI,CACtB,oCAAoC,kBAAkB,CAAC,YAAY,CAAC,EAAE,CACvE,CAAC;QACF,IAAI,KAAK,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE;YAC9B,MAAM,IAAI,wBAAwB,CAChC,8CAA8C,CAC/C,CAAC;QACJ,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QACtE,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ;YAC/D,OAAO,OAAO,CAAC;QACjB,QAAQ,GAAG,OAAO,CAAC;QACnB,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Stable retry identity for one operation in one durable authored root. */
|
|
2
|
+
export declare function authoredChildAdmissionKey(rootRunId: string | undefined, stepId: string): string | undefined;
|
|
3
|
+
/** Stable local worker surface for retries of one caller-owned root start. */
|
|
4
|
+
export declare function authoredLocalAgentStream(admissionIdentity: string): string;
|
|
5
|
+
//# sourceMappingURL=authored-admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authored-admission.d.ts","sourceRoot":"","sources":["../src/authored-admission.ts"],"names":[],"mappings":"AAEA,4EAA4E;AAC5E,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,GACb,MAAM,GAAG,SAAS,CAGpB;AAED,8EAA8E;AAC9E,wBAAgB,wBAAwB,CAAC,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAI1E"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/** Stable retry identity for one operation in one durable authored root. */
|
|
3
|
+
export function authoredChildAdmissionKey(rootRunId, stepId) {
|
|
4
|
+
if (rootRunId === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
return `authored-child:${createHash('sha256').update(`${rootRunId}\0${stepId}`).digest('hex')}`;
|
|
7
|
+
}
|
|
8
|
+
/** Stable local worker surface for retries of one caller-owned root start. */
|
|
9
|
+
export function authoredLocalAgentStream(admissionIdentity) {
|
|
10
|
+
return `local-agent-${createHash('sha256')
|
|
11
|
+
.update(`authored-root-worker\0${admissionIdentity}`)
|
|
12
|
+
.digest('hex')}`;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=authored-admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authored-admission.js","sourceRoot":"","sources":["../src/authored-admission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,4EAA4E;AAC5E,MAAM,UAAU,yBAAyB,CACvC,SAA6B,EAC7B,MAAc;IAEd,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC9C,OAAO,kBAAkB,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,KAAK,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAClG,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,wBAAwB,CAAC,iBAAyB;IAChE,OAAO,eAAe,UAAU,CAAC,QAAQ,CAAC;SACvC,MAAM,CAAC,yBAAyB,iBAAiB,EAAE,CAAC;SACpD,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -8,6 +8,6 @@ export declare class AuthoredBudget {
|
|
|
8
8
|
private tail;
|
|
9
9
|
private charges;
|
|
10
10
|
constructor(header: unknown);
|
|
11
|
-
execute<T>(journal: JournalClient, spec: KernelRunSpec, consume: (outcome: RunOutcome) => Promise<T
|
|
11
|
+
execute<T>(journal: JournalClient, spec: KernelRunSpec, consume: (outcome: RunOutcome) => Promise<T>, admissionKey?: string): Promise<T>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=authored-budget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authored-budget.d.ts","sourceRoot":"","sources":["../src/authored-budget.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,WAAW,CAAC;AAEjE,kFAAkF;AAClF,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAuC;IACnD,OAAO,CAAC,OAAO,CAAmF;gBAEtF,MAAM,EAAE,OAAO;IASrB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"authored-budget.d.ts","sourceRoot":"","sources":["../src/authored-budget.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAoB,aAAa,EAAE,MAAM,WAAW,CAAC;AAEjE,kFAAkF;AAClF,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA+B;IACrD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,IAAI,CAAuC;IACnD,OAAO,CAAC,OAAO,CAAmF;gBAEtF,MAAM,EAAE,OAAO;IASrB,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAC1D,OAAO,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CA8CnF"}
|
package/dist/authored-budget.js
CHANGED
|
@@ -16,9 +16,9 @@ export class AuthoredBudget {
|
|
|
16
16
|
throw error;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
async execute(journal, spec, consume) {
|
|
19
|
+
async execute(journal, spec, consume, admissionKey) {
|
|
20
20
|
if (this.limit === undefined)
|
|
21
|
-
return consume(await journal.runStart(spec));
|
|
21
|
+
return consume(await journal.runStart(spec, undefined, admissionKey));
|
|
22
22
|
const previous = this.tail;
|
|
23
23
|
let release;
|
|
24
24
|
this.tail = new Promise(resolve => { release = resolve; });
|
|
@@ -36,7 +36,7 @@ export class AuthoredBudget {
|
|
|
36
36
|
tokens_in: exactNumber(total.input), tokens_out: exactNumber(total.output),
|
|
37
37
|
dollars: `${total.micro / 1000000n}.${String(total.micro % 1000000n).padStart(6, '0')}`,
|
|
38
38
|
wallclock_ms: exactNumber(total.ms), ...(this.limit.window === 'day' && day !== undefined ? { day } : {}),
|
|
39
|
-
} } });
|
|
39
|
+
} } }, undefined, admissionKey);
|
|
40
40
|
try {
|
|
41
41
|
if (outcome.completion_reason === 'budget_exceeded')
|
|
42
42
|
throw new AuthoredFlowExecutionError('step_failed', 'Flow budget exceeded before the next step.', 'budget_exceeded', outcome.run_id);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authored-budget.js","sourceRoot":"","sources":["../src/authored-budget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAKtE,kFAAkF;AAClF,MAAM,OAAO,cAAc;IACR,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AE,GAAG,CAAC,CAAC;4BAChF,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,UAAU,CAAC,EAAC,CAAC,CAAC;oBAC5F,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YAAC,OAAO,EAAE,CAAC;QAAC,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CompletionReason as ProtocolCompletionReason, RunCompletionReason as ProtocolRunCompletionReason } from './protocol.js';
|
|
2
|
-
export type AuthoredFlowExecutionErrorCode = 'helper_provider.mount_required' | 'helper_provider.unsupported' | 'helper_slack.credential_missing' | 'helper_slack.mount_required' | 'budget_syntax_invalid' | '
|
|
2
|
+
export type AuthoredFlowExecutionErrorCode = 'helper_provider.mount_required' | 'helper_provider.unsupported' | 'helper_slack.credential_missing' | 'helper_slack.mount_required' | 'budget_syntax_invalid' | 'agent_cli_unresolved' | 'agent_parked' | 'llm_cli_unresolved' | 'llm_parked' | 'duplicate_completion' | 'journal_protocol_violation' | 'missing_completion' | 'memory_unreachable' | 'operation_after_completion' | 'operation_callback_failed' | 'step_failed' | 'lease_exceeded' | 'unsupported_completion' | 'unsupported_gate' | 'unsupported_header' | 'unsettled_derived_work' | 'unsupported_promise_lifecycle' | 'unsupported_workspace_permission' | 'unawaited_step' | 'unsupported_verb';
|
|
3
3
|
export declare class AuthoredFlowExecutionError extends Error {
|
|
4
4
|
readonly code: AuthoredFlowExecutionErrorCode;
|
|
5
5
|
readonly completionReason?: (ProtocolCompletionReason | ProtocolRunCompletionReason) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authored-flow-error.d.ts","sourceRoot":"","sources":["../src/authored-flow-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,IAAI,wBAAwB,EAC5C,mBAAmB,IAAI,2BAA2B,EACnD,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,8BAA8B,GACtC,gCAAgC,GAChC,6BAA6B,GAC7B,iCAAiC,GACjC,6BAA6B,GAC7B,uBAAuB,GACvB,sBAAsB,GACtB,
|
|
1
|
+
{"version":3,"file":"authored-flow-error.d.ts","sourceRoot":"","sources":["../src/authored-flow-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,IAAI,wBAAwB,EAC5C,mBAAmB,IAAI,2BAA2B,EACnD,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,8BAA8B,GACtC,gCAAgC,GAChC,6BAA6B,GAC7B,iCAAiC,GACjC,6BAA6B,GAC7B,uBAAuB,GACvB,sBAAsB,GACtB,cAAc,GACd,oBAAoB,GACpB,YAAY,GACZ,sBAAsB,GACtB,4BAA4B,GAC5B,oBAAoB,GACpB,oBAAoB,GACpB,4BAA4B,GAC5B,2BAA2B,GAC3B,aAAa,GACb,gBAAgB,GAChB,wBAAwB,GACxB,kBAAkB,GAClB,oBAAoB,GACpB,wBAAwB,GACxB,+BAA+B,GAC/B,kCAAkC,GAClC,gBAAgB,GAChB,kBAAkB,CAAC;AAEvB,qBAAa,0BAA2B,SAAQ,KAAK;IAEjD,QAAQ,CAAC,IAAI,EAAE,8BAA8B;IAE7C,QAAQ,CAAC,gBAAgB,CAAC,GAAE,wBAAwB,GAAG,2BAA2B;IAClF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM;gBAHd,IAAI,EAAE,8BAA8B,EAC7C,OAAO,EAAE,MAAM,EACN,gBAAgB,CAAC,GAAE,wBAAwB,GAAG,2BAA2B,aAAA,EACzE,KAAK,CAAC,EAAE,MAAM,YAAA;CAK1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authored-flow-error.js","sourceRoot":"","sources":["../src/authored-flow-error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authored-flow-error.js","sourceRoot":"","sources":["../src/authored-flow-error.ts"],"names":[],"mappings":"AAgCA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAExC;IAEA;IACA;IAJX,YACW,IAAoC,EAC7C,OAAe,EACN,gBAAyE,EACzE,KAAc;QAEvB,KAAK,CAAC,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QALpB,SAAI,GAAJ,IAAI,CAAgC;QAEpC,qBAAgB,GAAhB,gBAAgB,CAAyD;QACzE,UAAK,GAAL,KAAK,CAAS;QAGvB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -12,7 +12,15 @@ export interface AuthoredFlowJournalStep {
|
|
|
12
12
|
readonly runId: string;
|
|
13
13
|
readonly completionReason: ProtocolCompletionReason;
|
|
14
14
|
}
|
|
15
|
+
export interface AuthoredExecutionRuntime {
|
|
16
|
+
readonly kind: 'node';
|
|
17
|
+
readonly version: string;
|
|
18
|
+
readonly executableSha256: string;
|
|
19
|
+
readonly payloadSha256: string;
|
|
20
|
+
}
|
|
15
21
|
export interface AuthoredFlowExecutionResult {
|
|
22
|
+
readonly executionRuntime?: AuthoredExecutionRuntime;
|
|
23
|
+
readonly rootRunId?: string;
|
|
16
24
|
readonly name: string;
|
|
17
25
|
readonly completionReason: FlowCompletionReason;
|
|
18
26
|
readonly journalSteps: readonly AuthoredFlowJournalStep[];
|
|
@@ -55,6 +63,8 @@ export interface ExecuteAuthoredFlowOptions {
|
|
|
55
63
|
readonly onWait?: RunLifecycleOptions['onWait'];
|
|
56
64
|
readonly onProgress?: (event: ProgressEvent) => void;
|
|
57
65
|
readonly localAgentStream?: string;
|
|
66
|
+
/** Durable kernel root that owns this body's child admission identities. */
|
|
67
|
+
readonly rootRunId?: string;
|
|
58
68
|
}
|
|
59
69
|
export declare function executeAuthoredFlow<Input = undefined>(handle: FlowHandle, journal: JournalClient, input?: Input, options?: ExecuteAuthoredFlowOptions): Promise<AuthoredFlowExecutionResult>;
|
|
60
70
|
//# sourceMappingURL=authored-flow-executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authored-flow-executor.d.ts","sourceRoot":"","sources":["../src/authored-flow-executor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authored-flow-executor.d.ts","sourceRoot":"","sources":["../src/authored-flow-executor.ts"],"names":[],"mappings":"AAeA,OAAO,EAML,KAAK,oBAAoB,EAG1B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAmD,KAAK,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE/G,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAGhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACL,0BAA0B,EAC1B,KAAK,8BAA8B,EACpC,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EACV,gBAAgB,IAAI,wBAAwB,EAE7C,MAAM,eAAe,CAAC;AAoBvB,OAAO,EAAE,0BAA0B,EAAE,KAAK,8BAA8B,EAAE,CAAC;AAE3E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,gBAAgB,EAAE,wBAAwB,CAAC;CACrD;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,gBAAgB,E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.js';
|
|
1
2
|
import { pluginHelpers } from './plugin-loader.js';
|
|
2
3
|
import { runPluginEffect } from './authored-plugin-effect.js';
|
|
3
4
|
import { randomUUID } from 'node:crypto';
|
|
@@ -21,6 +22,7 @@ import { AuthoredFlowOperation, stopAuthoredOperations, verifyAuthoredOperations
|
|
|
21
22
|
import { AuthoredFlowLifecycle } from './authored-flow-lifecycle.js';
|
|
22
23
|
export { AuthoredFlowExecutionError };
|
|
23
24
|
export async function executeAuthoredFlow(handle, journal, input, options = {}) {
|
|
25
|
+
assertAuthoredPromiseHooks();
|
|
24
26
|
const getDefinition = options.getDefinition ?? getAuthoredFlowDefinition;
|
|
25
27
|
const localAgentStream = options.localAgentStream;
|
|
26
28
|
const onProgress = options.onProgress;
|
|
@@ -60,8 +62,8 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
60
62
|
const lifecycle = new AuthoredFlowLifecycle();
|
|
61
63
|
let nextStep = 1;
|
|
62
64
|
let requestedCompletion;
|
|
63
|
-
const lowerDeterministic = authoredDeterministicRunner(definition.name, journal, journalSteps, budget);
|
|
64
|
-
const worker = authoredWorkerRunner(definition, journal, flowPath, journalSteps, waitOptions, localAgentStream, budget, definition.header.budget);
|
|
65
|
+
const lowerDeterministic = authoredDeterministicRunner(definition.name, journal, journalSteps, budget, options.rootRunId);
|
|
66
|
+
const worker = authoredWorkerRunner(definition, journal, flowPath, journalSteps, waitOptions, localAgentStream, budget, definition.header.budget, options.rootRunId);
|
|
65
67
|
function llmOperation(prompt, ...values) {
|
|
66
68
|
assertOperationAllowed('llm', definition.name, requestedCompletion);
|
|
67
69
|
const id = `llm-${nextStep++}`;
|
|
@@ -82,13 +84,13 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
82
84
|
}, onProgress), lifecycle);
|
|
83
85
|
return trackStep(authoredSteps, llmOp);
|
|
84
86
|
}
|
|
85
|
-
const slackRun = randomUUID();
|
|
87
|
+
const slackRun = options.rootRunId ?? randomUUID();
|
|
86
88
|
function slackOperation(call) {
|
|
87
89
|
assertOperationAllowed(`slack.${call.verb}`, definition.name, requestedCompletion);
|
|
88
90
|
const snapshot = snapshotJsonValue(call, 'f.slack call');
|
|
89
91
|
const id = `slack-${slackRun}-${nextStep++}`;
|
|
90
92
|
return trackStep(authoredSteps, new AuthoredFlowOperation(id, `slack.${call.verb}`, () => assertOperationAllowed(`slack.${call.verb}`, definition.name, requestedCompletion), async () => {
|
|
91
|
-
const receipt = await runHelperEffect(journal, definition.name, id, snapshot, options.dataDir ?? dirname(journal.socketPath), journalSteps);
|
|
93
|
+
const receipt = await runHelperEffect(journal, definition.name, id, snapshot, options.dataDir ?? dirname(journal.socketPath), journalSteps, options.rootRunId);
|
|
92
94
|
return (call.verb === 'react' ? undefined : receipt);
|
|
93
95
|
}, lifecycle));
|
|
94
96
|
}
|
|
@@ -98,7 +100,7 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
98
100
|
assertOperationAllowed(verb, definition.name, requestedCompletion);
|
|
99
101
|
const snapshot = snapshotJsonValue(call, `f.${verb} call`);
|
|
100
102
|
const id = `${call.provider}-${slackRun}-${nextStep++}`;
|
|
101
|
-
return trackStep(authoredSteps, new AuthoredFlowOperation(id, verb, () => assertOperationAllowed(verb, definition.name, requestedCompletion), async () => await runHelperEffect(journal, definition.name, id, snapshot, options.dataDir ?? dirname(journal.socketPath), journalSteps), lifecycle));
|
|
103
|
+
return trackStep(authoredSteps, new AuthoredFlowOperation(id, verb, () => assertOperationAllowed(verb, definition.name, requestedCompletion), async () => await runHelperEffect(journal, definition.name, id, snapshot, options.dataDir ?? dirname(journal.socketPath), journalSteps, options.rootRunId), lifecycle));
|
|
102
104
|
}),
|
|
103
105
|
slack: {
|
|
104
106
|
post: (channel, text, opts) => slackOperation({ type: 'effect', provider: 'slack', verb: 'post', params: { channel, text, ...(opts === undefined ? {} : { opts }) } }),
|
|
@@ -109,7 +111,7 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
109
111
|
mcp: buildMcpProxy(checkedMcp.inventory, (server, tool, args, known) => {
|
|
110
112
|
assertOperationAllowed('mcp', definition.name, requestedCompletion);
|
|
111
113
|
const id = `mcp-${nextStep++}`;
|
|
112
|
-
return trackStep(authoredSteps, new AuthoredFlowOperation(id, 'mcp', () => assertOperationAllowed('mcp', definition.name, requestedCompletion), () => runMcpEffect(journal, definition.name, id, server, tool, args, known, checkedMcp.servers[server], journalSteps), lifecycle));
|
|
114
|
+
return trackStep(authoredSteps, new AuthoredFlowOperation(id, 'mcp', () => assertOperationAllowed('mcp', definition.name, requestedCompletion), () => runMcpEffect(journal, definition.name, id, server, tool, args, known, checkedMcp.servers[server], journalSteps, options.rootRunId), lifecycle));
|
|
113
115
|
}),
|
|
114
116
|
memory: authoredMemory(scriptMemoryScope(flowPath, definition.name), () => assertOperationAllowed('memory', definition.name, requestedCompletion), definition.header.memory?.script !== false),
|
|
115
117
|
run(command, runOptions) {
|
|
@@ -156,7 +158,7 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
156
158
|
const label = `${verb.namespace}.${verb.method}`;
|
|
157
159
|
assertOperationAllowed(label, definition.name, requestedCompletion);
|
|
158
160
|
const id = `plugin-${nextStep++}`;
|
|
159
|
-
return trackStep(authoredSteps, new AuthoredFlowOperation(id, label, () => assertOperationAllowed(label, definition.name, requestedCompletion), () => runPluginEffect(journal, definition.name, id, plugin, verb, args, journalSteps, budget), lifecycle));
|
|
161
|
+
return trackStep(authoredSteps, new AuthoredFlowOperation(id, label, () => assertOperationAllowed(label, definition.name, requestedCompletion), () => runPluginEffect(journal, definition.name, id, plugin, verb, args, journalSteps, budget, options.rootRunId), lifecycle));
|
|
160
162
|
}));
|
|
161
163
|
let bodyFailed = false;
|
|
162
164
|
let bodyFailure;
|
|
@@ -213,6 +215,7 @@ export async function executeAuthoredFlow(handle, journal, input, options = {})
|
|
|
213
215
|
await lowerDeterministic(`complete-${nextStep}`, requestedCompletion === 'needs_human'
|
|
214
216
|
? `printf '%s' '{"completionReason":"needs_human"}'` : ':', true);
|
|
215
217
|
return Object.freeze({
|
|
218
|
+
...(options.rootRunId === undefined ? {} : { rootRunId: options.rootRunId }),
|
|
216
219
|
name: definition.name,
|
|
217
220
|
completionReason: requestedCompletion,
|
|
218
221
|
journalSteps: Object.freeze([...journalSteps]),
|