@oona/vlo 0.0.0-stage → 0.1.1
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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +83 -2
- package/dist/agent.d.ts +151 -0
- package/dist/agent.js +445 -0
- package/dist/cli.d.ts +8 -0
- package/dist/cli.js +1540 -0
- package/dist/define-DwM_Qhbw.js +74 -0
- package/dist/domain-Bs8TeDCv.js +338 -0
- package/dist/domain-CJN6n_JD.d.ts +860 -0
- package/dist/host.d.ts +844 -0
- package/dist/host.js +314 -0
- package/dist/index-CIIcdblQ.d.ts +824 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/roles-D25bG980.js +3869 -0
- package/dist/src-DVCYkPA7.js +734 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +511 -0
- package/dist/types-BLQQMmkc.d.ts +746 -0
- package/dist/vlo_kernel-CtzHHfHA.js +276 -0
- package/package.json +95 -4
- package/wasm/vlo_kernel.d.ts +82 -0
- package/wasm/vlo_kernel.js +382 -0
- package/wasm/vlo_kernel_bg.wasm +0 -0
- package/wasm/vlo_kernel_bg.wasm.d.ts +15 -0
package/dist/agent.js
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { d as activity, f as signal } from "./domain-Bs8TeDCv.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { d as WorkflowFailure, g as signalTimeoutStepId, m as cmd } from "./src-DVCYkPA7.js";
|
|
4
|
+
// src/agent/decision.ts
|
|
5
|
+
/**
|
|
6
|
+
* `decision` — the decider is an ordinary activity whose output is a typed, journaled
|
|
7
|
+
* action. The tool registry fixes its output schema, so an LLM worker is
|
|
8
|
+
* constrained to names the loop can actually dispatch.
|
|
9
|
+
*/
|
|
10
|
+
/** Reserved tool name: the decider is finished and `final` (or the last candidate) is the answer. */
|
|
11
|
+
const DONE = "done";
|
|
12
|
+
const JSON_VALUE = z.lazy(() => z.union([
|
|
13
|
+
z.null(),
|
|
14
|
+
z.boolean(),
|
|
15
|
+
z.number(),
|
|
16
|
+
z.string(),
|
|
17
|
+
z.array(JSON_VALUE),
|
|
18
|
+
z.record(z.string(), JSON_VALUE)
|
|
19
|
+
]));
|
|
20
|
+
function decision(name, options) {
|
|
21
|
+
const tools = Object.keys(options.tools);
|
|
22
|
+
if (tools.length === 0) throw new TypeError("decision: no tools given");
|
|
23
|
+
if (tools.includes("done")) throw new TypeError(`decision: "${DONE}" is a reserved tool name`);
|
|
24
|
+
return activity(name, {
|
|
25
|
+
input: options.input,
|
|
26
|
+
output: z.object({
|
|
27
|
+
tool: z.enum([...tools, DONE]),
|
|
28
|
+
args: z.unknown().optional(),
|
|
29
|
+
rationale: z.string().optional(),
|
|
30
|
+
final: JSON_VALUE.optional()
|
|
31
|
+
}),
|
|
32
|
+
...options.retry !== void 0 ? { retry: options.retry } : {},
|
|
33
|
+
...options.queue !== void 0 ? { queue: options.queue } : {},
|
|
34
|
+
...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
// src/agent/approval.ts
|
|
38
|
+
/**
|
|
39
|
+
* Tool approval: a person says yes or no before a gated tool runs.
|
|
40
|
+
*
|
|
41
|
+
* The wait is an ordinary signal wait, so a run holds no compute while somebody decides.
|
|
42
|
+
* Each gated call waits on its own signal name, `<name>:<iteration>`, which is what makes an
|
|
43
|
+
* approval single-use: a duplicate, a late reply or a signed link for one call can never
|
|
44
|
+
* approve the next one.
|
|
45
|
+
*/
|
|
46
|
+
/** Prefix of the signal a gated tool call waits on; the iteration is appended. */
|
|
47
|
+
const DEFAULT_APPROVAL_SIGNAL = "agent.tool_approval";
|
|
48
|
+
const APPROVAL_SCHEMA = z.object({
|
|
49
|
+
approved: z.boolean().optional(),
|
|
50
|
+
reason: z.string().optional(),
|
|
51
|
+
by: z.string().optional()
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* The signal the gated call of `iteration` waits on. Pass it to `client.signal` or
|
|
55
|
+
* `client.signalLink`; the iteration is the suffix of the wait's step id, `approve#<i>`.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* await client.signal(runId, approvalSignal(2), { approved: false, reason: "wrong audience" });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
function approvalSignal(iteration, name = DEFAULT_APPROVAL_SIGNAL) {
|
|
63
|
+
return signal(`${name}:${iteration}`, APPROVAL_SCHEMA);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads a reply. No payload approves (a signed link's form sends none); a payload that is
|
|
67
|
+
* not a {@link ToolApproval} rejects, because an approval nobody can read is not one.
|
|
68
|
+
*/
|
|
69
|
+
function readApproval(payload) {
|
|
70
|
+
const parsed = APPROVAL_SCHEMA.safeParse(payload ?? {});
|
|
71
|
+
if (!parsed.success) return {
|
|
72
|
+
approved: false,
|
|
73
|
+
reason: "the approval reply was not valid"
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
...parsed.data,
|
|
77
|
+
approved: parsed.data.approved !== false
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// src/agent/budget.ts
|
|
81
|
+
/**
|
|
82
|
+
* The budget: ceilings on what one run may spend, and the signal that raises them.
|
|
83
|
+
*
|
|
84
|
+
* Exhaustion parks the run rather than failing it, so the work already paid
|
|
85
|
+
* for survives while a human decides whether to keep going.
|
|
86
|
+
*/
|
|
87
|
+
const DEFAULT_TOPUP_SIGNAL = "agent.budget_topup";
|
|
88
|
+
const TOPUP_SCHEMA = z.object({
|
|
89
|
+
tokens: z.number().nonnegative().optional(),
|
|
90
|
+
costMicroUsd: z.number().nonnegative().optional(),
|
|
91
|
+
steps: z.number().int().nonnegative().optional()
|
|
92
|
+
});
|
|
93
|
+
/** The signal a parked agent waits on. Pass the result to `agentLoop({ topup })`. */
|
|
94
|
+
function budgetTopup(name = DEFAULT_TOPUP_SIGNAL) {
|
|
95
|
+
return signal(name, TOPUP_SCHEMA);
|
|
96
|
+
}
|
|
97
|
+
/** True once any configured ceiling is reached. Absent ceilings never bind. */
|
|
98
|
+
function isExhausted(budget, spent, iteration) {
|
|
99
|
+
if (budget.tokens !== void 0 && spent.tokens >= budget.tokens) return true;
|
|
100
|
+
if (budget.costMicroUsd !== void 0 && spent.cost_micro_usd >= budget.costMicroUsd) return true;
|
|
101
|
+
if (budget.steps !== void 0 && iteration >= budget.steps) return true;
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Raises the ceilings a top-up names. A ceiling that was never set stays unbounded —
|
|
106
|
+
* granting 100 tokens to an unlimited budget must not turn it into a limit of 100.
|
|
107
|
+
*/
|
|
108
|
+
function grant(budget, topup) {
|
|
109
|
+
return {
|
|
110
|
+
...budget.tokens !== void 0 ? { tokens: budget.tokens + (topup.tokens ?? 0) } : {},
|
|
111
|
+
...budget.costMicroUsd !== void 0 ? { costMicroUsd: budget.costMicroUsd + (topup.costMicroUsd ?? 0) } : {},
|
|
112
|
+
...budget.steps !== void 0 ? { steps: budget.steps + (topup.steps ?? 0) } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// src/agent/state.ts
|
|
116
|
+
const NO_USAGE = {
|
|
117
|
+
cpu_ms: 0,
|
|
118
|
+
tokens: 0,
|
|
119
|
+
cost_micro_usd: 0
|
|
120
|
+
};
|
|
121
|
+
/** The run total the kernel banked, including the event that carries it. */
|
|
122
|
+
function spentOf(event) {
|
|
123
|
+
return event.usage_total;
|
|
124
|
+
}
|
|
125
|
+
/** These shapes are JSON by construction; TypeScript cannot see it through optional keys. */
|
|
126
|
+
function asJson(value) {
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
// src/agent/loop.ts
|
|
130
|
+
/**
|
|
131
|
+
* `agentLoop` — decide → tool → evaluate, as a pure reducer.
|
|
132
|
+
*
|
|
133
|
+
* Nothing loops at runtime: every arrow below is one journaled event folded into state, so
|
|
134
|
+
* the run survives a crash mid-thought and replays deterministically. The budget is a
|
|
135
|
+
* reducer decision over the usage the kernel banks on each event — exhaustion parks the run
|
|
136
|
+
* on a top-up signal instead of failing it. A gated tool waits the same way, on a person's
|
|
137
|
+
* yes or no, before it is dispatched.
|
|
138
|
+
*/
|
|
139
|
+
const DEFAULT_MAX_ITERATIONS = 50;
|
|
140
|
+
const DEFAULT_MEMORY_LIMIT = 20;
|
|
141
|
+
/** One step id per phase per iteration, so a replay asks the kernel for the same step. */
|
|
142
|
+
const STEP_ID = {
|
|
143
|
+
decide: (i) => `decide#${i}`,
|
|
144
|
+
tool: (i) => `tool#${i}`,
|
|
145
|
+
evaluate: (i) => `evaluate#${i}`,
|
|
146
|
+
topup: (i) => `topup#${i}`,
|
|
147
|
+
approve: (i) => `approve#${i}`
|
|
148
|
+
};
|
|
149
|
+
function agentLoop(options) {
|
|
150
|
+
const cfg = compile(options);
|
|
151
|
+
return {
|
|
152
|
+
init: (goal) => ({
|
|
153
|
+
phase: "decide",
|
|
154
|
+
goal,
|
|
155
|
+
iteration: 0,
|
|
156
|
+
memory: [],
|
|
157
|
+
budget: cfg.budget,
|
|
158
|
+
spent: NO_USAGE
|
|
159
|
+
}),
|
|
160
|
+
on: {
|
|
161
|
+
started: (state) => decide(cfg, state),
|
|
162
|
+
task_done: (state, event) => onTaskDone(cfg, state, event),
|
|
163
|
+
signal: (state, event) => onSignal(cfg, state, event),
|
|
164
|
+
timer: (state, event) => onTimer(cfg, state, event)
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function compile(options) {
|
|
169
|
+
const tools = new Map(Object.entries(options.tools).map(([name, target]) => [name, erase(target)]));
|
|
170
|
+
if (tools.size === 0) throw new TypeError("agentLoop: no tools given");
|
|
171
|
+
const maxIterations = options.maxIterations ?? 50;
|
|
172
|
+
const memoryLimit = options.memoryLimit ?? 20;
|
|
173
|
+
if (maxIterations < 1) throw new TypeError("agentLoop: maxIterations must be >= 1");
|
|
174
|
+
if (memoryLimit < 1) throw new TypeError("agentLoop: memoryLimit must be >= 1");
|
|
175
|
+
const gated = options.approval?.tools ?? [];
|
|
176
|
+
for (const name of gated) if (!tools.has(name)) throw new TypeError(`agentLoop: approval names an unknown tool "${name}"`);
|
|
177
|
+
return {
|
|
178
|
+
decide: erase(options.decide),
|
|
179
|
+
tools,
|
|
180
|
+
evaluate: options.evaluate === void 0 ? void 0 : erase(options.evaluate),
|
|
181
|
+
threshold: options.threshold,
|
|
182
|
+
budget: options.budget,
|
|
183
|
+
topup: options.topup ?? budgetTopup(),
|
|
184
|
+
approval: options.approval === void 0 ? void 0 : {
|
|
185
|
+
tools: new Set(gated),
|
|
186
|
+
name: options.approval.name ?? "agent.tool_approval",
|
|
187
|
+
timeoutMs: options.approval.timeoutMs,
|
|
188
|
+
onTimeout: options.approval.onTimeout ?? "reject"
|
|
189
|
+
},
|
|
190
|
+
maxIterations,
|
|
191
|
+
memoryLimit
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const erase = (target) => target;
|
|
195
|
+
function decide(cfg, state) {
|
|
196
|
+
const at = {
|
|
197
|
+
...clearPending(state),
|
|
198
|
+
phase: "decide"
|
|
199
|
+
};
|
|
200
|
+
const input = asJson({
|
|
201
|
+
goal: at.goal,
|
|
202
|
+
memory: at.memory,
|
|
203
|
+
candidate: at.candidate ?? null,
|
|
204
|
+
score: at.score ?? null
|
|
205
|
+
});
|
|
206
|
+
return [at, [cmd.task(cfg.decide, input, { id: STEP_ID.decide(at.iteration) })]];
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* A result the loop is not waiting for — a duplicate delivery, or one from an iteration
|
|
210
|
+
* already left behind — is folded and ignored, exactly as the `sequence` helper does.
|
|
211
|
+
*/
|
|
212
|
+
function onTaskDone(cfg, state, event) {
|
|
213
|
+
if (state.phase === "parked" || state.phase === "approval" || state.phase === "done") return [state, []];
|
|
214
|
+
if (event.step_id !== STEP_ID[state.phase](state.iteration)) return [state, []];
|
|
215
|
+
const at = {
|
|
216
|
+
...state,
|
|
217
|
+
spent: spentOf(event)
|
|
218
|
+
};
|
|
219
|
+
if (event.status !== "succeeded") return observeFailure(cfg, at, event);
|
|
220
|
+
if (state.phase === "decide") return onDecided(cfg, at, event);
|
|
221
|
+
if (state.phase === "tool") return onToolDone(cfg, at, event);
|
|
222
|
+
return onEvaluated(cfg, at, event);
|
|
223
|
+
}
|
|
224
|
+
/** Agents route around failures: a task that exhausted its retries becomes an observation. */
|
|
225
|
+
function observeFailure(cfg, state, event) {
|
|
226
|
+
return advance(cfg, remember(cfg, state, {
|
|
227
|
+
tool: state.pending?.tool ?? event.activity,
|
|
228
|
+
error: event.error ?? event.status
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
function onDecided(cfg, state, event) {
|
|
232
|
+
const decision = readDecision(event.output ?? null);
|
|
233
|
+
if (decision.tool === "done") return complete(state, decision.final ?? state.candidate ?? null, false);
|
|
234
|
+
const target = cfg.tools.get(decision.tool);
|
|
235
|
+
if (target === void 0) {
|
|
236
|
+
const error = `unknown tool "${decision.tool}"`;
|
|
237
|
+
return advance(cfg, remember(cfg, state, {
|
|
238
|
+
tool: decision.tool,
|
|
239
|
+
error
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
const parsed = target.input.safeParse(decision.args ?? null);
|
|
243
|
+
if (!parsed.success) {
|
|
244
|
+
const error = `invalid args: ${parsed.error.issues.map((issue) => issue.message).join("; ")}`;
|
|
245
|
+
return advance(cfg, remember(cfg, state, {
|
|
246
|
+
tool: decision.tool,
|
|
247
|
+
args: asJson(decision.args ?? null),
|
|
248
|
+
error
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
const pending = {
|
|
252
|
+
tool: decision.tool,
|
|
253
|
+
args: parsed.data
|
|
254
|
+
};
|
|
255
|
+
if (cfg.approval?.tools.has(decision.tool)) return askApproval(cfg.approval, {
|
|
256
|
+
...state,
|
|
257
|
+
pending
|
|
258
|
+
}, decision.rationale);
|
|
259
|
+
return dispatch(target, {
|
|
260
|
+
...state,
|
|
261
|
+
pending
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
/** Runs the tool the decider picked; `state.pending` already names it. */
|
|
265
|
+
function dispatch(target, state) {
|
|
266
|
+
const at = {
|
|
267
|
+
...state,
|
|
268
|
+
phase: "tool"
|
|
269
|
+
};
|
|
270
|
+
return [at, [cmd.task(target, at.pending?.args ?? null, { id: STEP_ID.tool(at.iteration) })]];
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* A gated tool: park on this call's own signal and tell whoever is listening what is being
|
|
274
|
+
* asked. The run holds no compute while somebody decides.
|
|
275
|
+
*/
|
|
276
|
+
function askApproval(approval, state, rationale) {
|
|
277
|
+
const at = {
|
|
278
|
+
...state,
|
|
279
|
+
phase: "approval"
|
|
280
|
+
};
|
|
281
|
+
const context = asJson({
|
|
282
|
+
tool: at.pending?.tool,
|
|
283
|
+
args: at.pending?.args ?? null,
|
|
284
|
+
iteration: at.iteration,
|
|
285
|
+
...rationale !== void 0 ? { rationale } : {}
|
|
286
|
+
});
|
|
287
|
+
return [at, cmd.awaitHuman(approvalSignal(at.iteration, approval.name), {
|
|
288
|
+
id: STEP_ID.approve(at.iteration),
|
|
289
|
+
context,
|
|
290
|
+
...approval.timeoutMs !== void 0 ? { timeoutMs: approval.timeoutMs } : {}
|
|
291
|
+
})];
|
|
292
|
+
}
|
|
293
|
+
/** A person answered: run the tool, or tell the decider it was turned down. */
|
|
294
|
+
function onApproval(cfg, state, event) {
|
|
295
|
+
const at = {
|
|
296
|
+
...state,
|
|
297
|
+
spent: spentOf(event)
|
|
298
|
+
};
|
|
299
|
+
const pending = at.pending;
|
|
300
|
+
const target = pending === void 0 ? void 0 : cfg.tools.get(pending.tool);
|
|
301
|
+
if (pending === void 0 || target === void 0) return advance(cfg, at);
|
|
302
|
+
const reply = readApproval(event.payload);
|
|
303
|
+
if (reply.approved) return dispatch(target, at);
|
|
304
|
+
const who = reply.by !== void 0 ? ` by ${reply.by}` : "";
|
|
305
|
+
const why = reply.reason !== void 0 ? `: ${reply.reason}` : "";
|
|
306
|
+
return advance(cfg, remember(cfg, at, {
|
|
307
|
+
...pending,
|
|
308
|
+
error: `rejected${who}${why}`
|
|
309
|
+
}));
|
|
310
|
+
}
|
|
311
|
+
/** Nobody answered in time. */
|
|
312
|
+
function onTimer(cfg, state, event) {
|
|
313
|
+
const waiting = signalTimeoutStepId(STEP_ID.approve(state.iteration));
|
|
314
|
+
if (state.phase !== "approval" || event.step_id !== waiting) return [state, []];
|
|
315
|
+
const tool = state.pending?.tool ?? "tool";
|
|
316
|
+
if (cfg.approval?.onTimeout === "fail") throw new WorkflowFailure(`agent: approval timed out for "${tool}"`, { step_id: STEP_ID.approve(state.iteration) });
|
|
317
|
+
const at = {
|
|
318
|
+
...state,
|
|
319
|
+
spent: spentOf(event)
|
|
320
|
+
};
|
|
321
|
+
return advance(cfg, remember(cfg, at, {
|
|
322
|
+
tool,
|
|
323
|
+
...at.pending !== void 0 ? { args: at.pending.args } : {},
|
|
324
|
+
error: "approval timed out"
|
|
325
|
+
}));
|
|
326
|
+
}
|
|
327
|
+
function onToolDone(cfg, state, event) {
|
|
328
|
+
const output = event.output ?? null;
|
|
329
|
+
const pending = state.pending;
|
|
330
|
+
const at = {
|
|
331
|
+
...remember(cfg, state, {
|
|
332
|
+
tool: pending?.tool ?? event.activity,
|
|
333
|
+
...pending !== void 0 ? { args: pending.args } : {},
|
|
334
|
+
output
|
|
335
|
+
}),
|
|
336
|
+
candidate: output
|
|
337
|
+
};
|
|
338
|
+
if (cfg.evaluate === void 0) return advance(cfg, at);
|
|
339
|
+
const input = asJson({
|
|
340
|
+
goal: at.goal,
|
|
341
|
+
candidate: output
|
|
342
|
+
});
|
|
343
|
+
return [{
|
|
344
|
+
...at,
|
|
345
|
+
phase: "evaluate"
|
|
346
|
+
}, [cmd.task(cfg.evaluate, input, { id: STEP_ID.evaluate(state.iteration) })]];
|
|
347
|
+
}
|
|
348
|
+
function onEvaluated(cfg, state, event) {
|
|
349
|
+
const score = readScore(event.output ?? null);
|
|
350
|
+
const at = {
|
|
351
|
+
...state,
|
|
352
|
+
score,
|
|
353
|
+
memory: scoreLast(state.memory, score)
|
|
354
|
+
};
|
|
355
|
+
if (cfg.threshold !== void 0 && score >= cfg.threshold) return complete(at, at.candidate ?? null, false);
|
|
356
|
+
return advance(cfg, at);
|
|
357
|
+
}
|
|
358
|
+
function onSignal(cfg, state, event) {
|
|
359
|
+
if (state.phase === "approval" && event.step_id === STEP_ID.approve(state.iteration)) return onApproval(cfg, state, event);
|
|
360
|
+
if (state.phase !== "parked" || event.name !== cfg.topup.name) return [state, []];
|
|
361
|
+
const granted = cfg.topup.schema.safeParse(event.payload);
|
|
362
|
+
return decide(cfg, {
|
|
363
|
+
...state,
|
|
364
|
+
spent: spentOf(event),
|
|
365
|
+
budget: grant(state.budget, granted.success ? granted.data : {})
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
/** One cycle is over: charge it against the ceilings, then decide again — or park. */
|
|
369
|
+
function advance(cfg, state) {
|
|
370
|
+
const at = {
|
|
371
|
+
...state,
|
|
372
|
+
iteration: state.iteration + 1
|
|
373
|
+
};
|
|
374
|
+
if (at.iteration >= cfg.maxIterations) return complete(at, at.candidate ?? null, true);
|
|
375
|
+
if (isExhausted(at.budget, at.spent, at.iteration)) return park(cfg, at);
|
|
376
|
+
return decide(cfg, at);
|
|
377
|
+
}
|
|
378
|
+
function park(cfg, state) {
|
|
379
|
+
const at = {
|
|
380
|
+
...clearPending(state),
|
|
381
|
+
phase: "parked"
|
|
382
|
+
};
|
|
383
|
+
const parked = asJson({ parked: {
|
|
384
|
+
iteration: at.iteration,
|
|
385
|
+
budget: at.budget,
|
|
386
|
+
spent: at.spent,
|
|
387
|
+
candidate: at.candidate ?? null,
|
|
388
|
+
score: at.score ?? null
|
|
389
|
+
} });
|
|
390
|
+
return [at, [cmd.emit("agent", parked), cmd.awaitSignal(cfg.topup, { id: STEP_ID.topup(at.iteration) })]];
|
|
391
|
+
}
|
|
392
|
+
function complete(state, candidate, exhausted) {
|
|
393
|
+
const result = {
|
|
394
|
+
candidate,
|
|
395
|
+
...state.score !== void 0 ? { score: state.score } : {},
|
|
396
|
+
iterations: exhausted ? state.iteration : state.iteration + 1,
|
|
397
|
+
spent: state.spent,
|
|
398
|
+
...exhausted ? { exhausted: true } : {}
|
|
399
|
+
};
|
|
400
|
+
return [{
|
|
401
|
+
...state,
|
|
402
|
+
phase: "done",
|
|
403
|
+
candidate
|
|
404
|
+
}, [cmd.complete(asJson(result))]];
|
|
405
|
+
}
|
|
406
|
+
function remember(cfg, state, observation) {
|
|
407
|
+
return {
|
|
408
|
+
...state,
|
|
409
|
+
memory: [...state.memory, observation].slice(-cfg.memoryLimit)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function scoreLast(memory, score) {
|
|
413
|
+
const last = memory[memory.length - 1];
|
|
414
|
+
if (last === void 0) return [];
|
|
415
|
+
return [...memory.slice(0, -1), {
|
|
416
|
+
...last,
|
|
417
|
+
score
|
|
418
|
+
}];
|
|
419
|
+
}
|
|
420
|
+
/** A new decision supersedes whatever the previous one dispatched. */
|
|
421
|
+
function clearPending(state) {
|
|
422
|
+
const next = { ...state };
|
|
423
|
+
delete next.pending;
|
|
424
|
+
return next;
|
|
425
|
+
}
|
|
426
|
+
function readDecision(output) {
|
|
427
|
+
if (output === null || typeof output !== "object" || Array.isArray(output)) throw new WorkflowFailure("agent: decide returned no decision object", output);
|
|
428
|
+
const tool = output["tool"];
|
|
429
|
+
if (typeof tool !== "string") throw new WorkflowFailure("agent: decide returned no `tool`", output);
|
|
430
|
+
return {
|
|
431
|
+
tool,
|
|
432
|
+
args: output["args"],
|
|
433
|
+
rationale: typeof output["rationale"] === "string" ? output["rationale"] : void 0,
|
|
434
|
+
final: output["final"]
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function readScore(output) {
|
|
438
|
+
if (typeof output === "number") return output;
|
|
439
|
+
if (output !== null && typeof output === "object" && !Array.isArray(output)) {
|
|
440
|
+
const score = output["score"];
|
|
441
|
+
if (typeof score === "number") return score;
|
|
442
|
+
}
|
|
443
|
+
throw new WorkflowFailure("agent: evaluate returned no numeric `score`", output);
|
|
444
|
+
}
|
|
445
|
+
export { DEFAULT_APPROVAL_SIGNAL, DEFAULT_MAX_ITERATIONS, DEFAULT_MEMORY_LIMIT, DEFAULT_TOPUP_SIGNAL, DONE, agentLoop, approvalSignal, budgetTopup, decision };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `vlo` command: one verb per file under `cli/`.
|
|
3
|
+
*
|
|
4
|
+
* `dev` and `serve` are the same host with different defaults — that is deliberate, and it
|
|
5
|
+
* is why `doctor` and `deploy` read the same profile: whatever runs on a laptop, what a
|
|
6
|
+
* check reports and what a template deploys all come from one place in `vlo.config.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function main(argv?: readonly string[], cwd?: string): Promise<void>;
|