@tangle-network/agent-runtime 0.169.0 → 0.171.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/{activation-CIwer0zU.js → activation-8RxHIo02.js} +2 -2
- package/dist/{activation-CIwer0zU.js.map → activation-8RxHIo02.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/authored-code-DzYtiflw.js +37 -0
- package/dist/authored-code-DzYtiflw.js.map +1 -0
- package/dist/{authoring-CUTgAxxE.js → authoring-U8BvENNa.js} +2 -2
- package/dist/{authoring-CUTgAxxE.js.map → authoring-U8BvENNa.js.map} +1 -1
- package/dist/durable.d.ts +1 -1
- package/dist/durable.js +1 -1
- package/dist/{graph-ZDMygFIo.js → graph-DK_za3yj.js} +2 -2
- package/dist/{graph-ZDMygFIo.js.map → graph-DK_za3yj.js.map} +1 -1
- package/dist/graph.d.ts +36 -93
- package/dist/graph.js +4 -185
- package/dist/graph.js.map +1 -1
- package/dist/{improvement-cycle-BAKN_f4x.js → improvement-cycle-BYCnKZ_G.js} +24 -3
- package/dist/improvement-cycle-BYCnKZ_G.js.map +1 -0
- package/dist/{index-BgptUCKl.d.ts → index-C38CMh7Y.d.ts} +2 -2
- package/dist/{index-BGQtpQuJ.d.ts → index-CTIWK6cQ.d.ts} +59 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -5
- package/dist/intelligence.js +2 -2
- package/dist/kernel.d.ts +2 -2
- package/dist/kernel.js +5 -5
- package/dist/{knowledge-D-7PXKUV.js → knowledge-CbSzAeP-.js} +3 -3
- package/dist/{knowledge-D-7PXKUV.js.map → knowledge-CbSzAeP-.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-DHxQ_VQD.js → loop-runner-bin-CglWRAZs.js} +2 -2
- package/dist/{loop-runner-bin-DHxQ_VQD.js.map → loop-runner-bin-CglWRAZs.js.map} +1 -1
- package/dist/{loop-runner-bin-C2NXQK7J.d.ts → loop-runner-bin-CxXDdDd8.d.ts} +2 -2
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/mcp/bin.js +2 -2
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +3 -3
- package/dist/{openai-tools-UyXVO0kd.js → openai-tools-B_zjkAey.js} +2 -2
- package/dist/{openai-tools-UyXVO0kd.js.map → openai-tools-B_zjkAey.js.map} +1 -1
- package/dist/{runtime-D5l-enW9.js → runtime-DWs-CucB.js} +247 -17
- package/dist/runtime-DWs-CucB.js.map +1 -0
- package/dist/{supervise-rEE46ruH.js → supervise-CG7JDcEG.js} +11 -2
- package/dist/{supervise-rEE46ruH.js.map → supervise-CG7JDcEG.js.map} +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +11 -11
- package/package.json +1 -1
- package/skills/codemode/SKILL.md +49 -0
- package/dist/improvement-cycle-BAKN_f4x.js.map +0 -1
- package/dist/runtime-D5l-enW9.js.map +0 -1
package/dist/graph.js
CHANGED
|
@@ -2,190 +2,9 @@ import { m as ValidationError } from "./errors-CDZ8XsVj.js";
|
|
|
2
2
|
import { d as replaySpawnTree, i as InMemorySpawnJournal, l as materializeTreeView, o as closesCursorSlot, r as InMemoryResultBlobStore, u as pendingWaits, x as contentAddress } from "./spawn-journal-Tgvp5VS5.js";
|
|
3
3
|
import { t as addSpend } from "./util-D6ZEuBMi.js";
|
|
4
4
|
import { N as createBudgetPool, U as createExecutorRegistry, a as uncertainSpawnBudgets, i as sumMeasuredSpendFromEvents, l as runFinalizer, o as bestDelivered, p as createScope, r as maxSeqOf, s as collectDelivered } from "./supervisor-B-mmmiOU.js";
|
|
5
|
-
import { i as workerFromBackend, s as supervisorAgent } from "./supervise-
|
|
6
|
-
import { t as
|
|
7
|
-
|
|
8
|
-
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
9
|
-
/**
|
|
10
|
-
* Refuse the obvious escapes in authored source. A LINT, not a sandbox: it reads text and cannot
|
|
11
|
-
* constrain what running code does. Generalized from `strategy-author.ts`'s contract check, which
|
|
12
|
-
* has guarded agent-authored optimization strategies since 0.60.
|
|
13
|
-
*/
|
|
14
|
-
function assertAuthoredCode(code, options = {}) {
|
|
15
|
-
const context = options.context ?? "authored code";
|
|
16
|
-
const allowed = options.allowedImports ?? [];
|
|
17
|
-
for (const line of code.split("\n")) {
|
|
18
|
-
if (!/^\s*import\s/.test(line)) continue;
|
|
19
|
-
if (!allowed.some((specifier) => line.includes(`'${specifier}'`) || line.includes(`"${specifier}"`))) throw new ValidationError(`${context} rejected: foreign import — ${line.trim().slice(0, 120)}${allowed.length === 0 ? " (no import is allowed here)" : ` (allowed: ${allowed.join(", ")})`}`);
|
|
20
|
-
}
|
|
21
|
-
for (const [pattern, what] of [
|
|
22
|
-
[/\brequire\s*\(/, "require()"],
|
|
23
|
-
[/\bimport\s*\(/, "dynamic import()"],
|
|
24
|
-
[/\beval\s*\(/, "eval()"],
|
|
25
|
-
[/new\s+Function\s*\(/, "new Function()"],
|
|
26
|
-
[/\bprocess\s*[.[]/, "process access"],
|
|
27
|
-
[/\bglobalThis\s*[.[]/, "globalThis access"],
|
|
28
|
-
[/\bfetch\s*\(/, "network access"],
|
|
29
|
-
[/child_process|node:fs|node:net|node:http|worker_threads/, "node builtin access"]
|
|
30
|
-
]) if (pattern.test(code)) throw new ValidationError(`${context} rejected: ${what}`);
|
|
31
|
-
}
|
|
32
|
-
/** The API doc the model is shown — generated from the grant, so the two cannot disagree. */
|
|
33
|
-
function renderCodeApi(config) {
|
|
34
|
-
return [
|
|
35
|
-
"Write ONE async function body. It may call only these operations:",
|
|
36
|
-
"",
|
|
37
|
-
...config.operations.map((operation) => ` ${operation.signature}\n // ${operation.description}`),
|
|
38
|
-
"",
|
|
39
|
-
"Return the result as the body's return value. No imports, no require, no process, no fetch.",
|
|
40
|
-
"Reply with a single fenced code block and nothing else.",
|
|
41
|
-
"",
|
|
42
|
-
`TASK: ${config.task}`
|
|
43
|
-
].join("\n");
|
|
44
|
-
}
|
|
45
|
-
/** Pull the first fenced block out of a model reply; the whole reply if it carries no fence. */
|
|
46
|
-
function extractCodeBlock(reply) {
|
|
47
|
-
const code = (/```(?:[a-zA-Z]*)\n([\s\S]*?)```/u.exec(reply)?.[1] ?? reply).trim();
|
|
48
|
-
if (code.length === 0) throw new ValidationError("codemode: the model returned no code");
|
|
49
|
-
return code;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* A node that asks a model for a program and runs it. Declares the two effects it cannot supply
|
|
53
|
-
* itself — `model` (who writes the code) and `codeRunner` (where it runs) — so the host owns both.
|
|
54
|
-
*/
|
|
55
|
-
function codemodeKind() {
|
|
56
|
-
return {
|
|
57
|
-
id: "codemode",
|
|
58
|
-
version: 1,
|
|
59
|
-
description: "Ask a model for a program over a granted API, then run it as one node.",
|
|
60
|
-
validateConfig: (raw, context) => {
|
|
61
|
-
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new ValidationError(`${context}: codemode config must be an object`);
|
|
62
|
-
const config = raw;
|
|
63
|
-
if (typeof config.task !== "string" || config.task.trim().length === 0) throw new ValidationError(`${context}: codemode config.task must be a non-empty string`);
|
|
64
|
-
if (!Array.isArray(config.operations) || config.operations.length === 0) throw new ValidationError(`${context}: codemode config.operations must grant at least one operation`);
|
|
65
|
-
const seen = /* @__PURE__ */ new Set();
|
|
66
|
-
for (const operation of config.operations) {
|
|
67
|
-
if (!IDENTIFIER.test(operation?.name ?? "")) throw new ValidationError(`${context}: operation name ${JSON.stringify(operation?.name)} is not a JS identifier`);
|
|
68
|
-
if (seen.has(operation.name)) throw new ValidationError(`${context}: duplicate operation ${operation.name}`);
|
|
69
|
-
seen.add(operation.name);
|
|
70
|
-
if (typeof operation.call !== "function") throw new ValidationError(`${context}: operation ${operation.name} has no call`);
|
|
71
|
-
}
|
|
72
|
-
return {
|
|
73
|
-
operations: config.operations,
|
|
74
|
-
task: config.task,
|
|
75
|
-
...config.allowedImports === void 0 ? {} : { allowedImports: config.allowedImports }
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
configSchema: {
|
|
79
|
-
type: "object",
|
|
80
|
-
properties: {
|
|
81
|
-
task: { type: "string" },
|
|
82
|
-
operations: { type: "array" }
|
|
83
|
-
},
|
|
84
|
-
required: ["task", "operations"]
|
|
85
|
-
},
|
|
86
|
-
inputs: [{
|
|
87
|
-
name: "context",
|
|
88
|
-
schema: {}
|
|
89
|
-
}],
|
|
90
|
-
outputs: [],
|
|
91
|
-
effects: ["model", "codeRunner"],
|
|
92
|
-
onCrash: "restart",
|
|
93
|
-
budget: "metered",
|
|
94
|
-
run: ({ config, profile, inputs, effects }) => {
|
|
95
|
-
const author = effects.model;
|
|
96
|
-
const runner = effects.codeRunner;
|
|
97
|
-
let artifact;
|
|
98
|
-
return {
|
|
99
|
-
name: profile.name ?? "codemode",
|
|
100
|
-
act: () => Promise.reject(new ValidationError("codemode: act() is not the execution path")),
|
|
101
|
-
executorSpec: {
|
|
102
|
-
profile,
|
|
103
|
-
harness: null,
|
|
104
|
-
executor: {
|
|
105
|
-
runtime: "inline",
|
|
106
|
-
async execute(task, signal) {
|
|
107
|
-
const spends = [];
|
|
108
|
-
const prompt = [
|
|
109
|
-
renderCodeApi(config),
|
|
110
|
-
inputs.context === void 0 ? "" : `\nCONTEXT: ${JSON.stringify(inputs.context)}`,
|
|
111
|
-
typeof task === "string" && task.length > 0 ? `\n${task}` : ""
|
|
112
|
-
].filter((part) => part.length > 0).join("\n");
|
|
113
|
-
const authored = await author.complete({
|
|
114
|
-
prompt,
|
|
115
|
-
profile,
|
|
116
|
-
signal
|
|
117
|
-
});
|
|
118
|
-
if (authored.spend) spends.push(authored.spend);
|
|
119
|
-
const code = extractCodeBlock(authored.text);
|
|
120
|
-
assertAuthoredCode(code, {
|
|
121
|
-
...config.allowedImports === void 0 ? {} : { allowedImports: config.allowedImports },
|
|
122
|
-
context: `codemode ${JSON.stringify(profile.name ?? "node")}`
|
|
123
|
-
});
|
|
124
|
-
const api = {};
|
|
125
|
-
for (const operation of config.operations) api[operation.name] = async (...args) => {
|
|
126
|
-
const result = await operation.call(...args);
|
|
127
|
-
if (result?.spend) spends.push(result.spend);
|
|
128
|
-
return result?.value;
|
|
129
|
-
};
|
|
130
|
-
const out = await runner.run({
|
|
131
|
-
code,
|
|
132
|
-
api: Object.freeze(api),
|
|
133
|
-
signal
|
|
134
|
-
});
|
|
135
|
-
artifact = {
|
|
136
|
-
outRef: contentAddress({ codemode: out }),
|
|
137
|
-
out,
|
|
138
|
-
spent: totalSpend(spends)
|
|
139
|
-
};
|
|
140
|
-
return artifact;
|
|
141
|
-
},
|
|
142
|
-
teardown: () => Promise.resolve({ destroyed: true }),
|
|
143
|
-
resultArtifact: () => {
|
|
144
|
-
if (!artifact) throw new ValidationError("codemode: resultArtifact() read before execute()");
|
|
145
|
-
return artifact;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/** The node's spend is the model call plus every operation that reported one. An operation that
|
|
154
|
-
* reports nothing is not assumed free — it contributes an UNKNOWN mark, like the kernel's own. */
|
|
155
|
-
function totalSpend(parts) {
|
|
156
|
-
return parts.reduce((total, part) => ({
|
|
157
|
-
iterations: total.iterations + (part.iterations ?? 0),
|
|
158
|
-
tokens: {
|
|
159
|
-
input: total.tokens.input + (part.tokens?.input ?? 0),
|
|
160
|
-
output: total.tokens.output + (part.tokens?.output ?? 0),
|
|
161
|
-
...part.tokens?.tokensKnown === false ? { tokensKnown: false } : {}
|
|
162
|
-
},
|
|
163
|
-
usd: total.usd + (part.usd ?? 0),
|
|
164
|
-
...part.usdKnown === false ? { usdKnown: false } : {},
|
|
165
|
-
ms: total.ms + (part.ms ?? 0)
|
|
166
|
-
}), {
|
|
167
|
-
iterations: 1,
|
|
168
|
-
tokens: {
|
|
169
|
-
input: 0,
|
|
170
|
-
output: 0
|
|
171
|
-
},
|
|
172
|
-
usd: 0,
|
|
173
|
-
ms: 0
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* An in-process `codeRunner`: builds the authored body as a function with the granted API in
|
|
178
|
-
* scope. **A development convenience, not a security boundary** — `assertAuthoredCode` is a lint,
|
|
179
|
-
* and code running in this process can reach whatever the process can. Supply a jailed runner for
|
|
180
|
-
* code you did not write.
|
|
181
|
-
*/
|
|
182
|
-
function inlineCodeRunner() {
|
|
183
|
-
return { async run({ code, api }) {
|
|
184
|
-
const names = Object.keys(api);
|
|
185
|
-
return new Function(...names, `"use strict"; return (async () => { ${code} })()`)(...names.map((name) => api[name]));
|
|
186
|
-
} };
|
|
187
|
-
}
|
|
188
|
-
//#endregion
|
|
5
|
+
import { i as workerFromBackend, s as supervisorAgent } from "./supervise-CG7JDcEG.js";
|
|
6
|
+
import { t as assertAuthoredCode } from "./authored-code-DzYtiflw.js";
|
|
7
|
+
import { t as GraphEdgeCapError } from "./graph-DK_za3yj.js";
|
|
189
8
|
//#region src/runtime/graph/condition.ts
|
|
190
9
|
/**
|
|
191
10
|
* The ONE predicate tree: every guard in a graph — an edge `guard`, a filter projection's
|
|
@@ -2254,6 +2073,6 @@ async function runGraphLoop(engine, compiled, task, options, wakes, onWakeSignal
|
|
|
2254
2073
|
});
|
|
2255
2074
|
}
|
|
2256
2075
|
//#endregion
|
|
2257
|
-
export { CONDITION_OPS, DEFAULT_MAX_NODE_VISITS, ENGINE_WOKEN_SEQ_BASE, JOIN_RULES, MAX_MAX_NODE_VISITS, RUN_GRAPH_ROOT_KIND, admitPayload, agentKind, applyGraphFoldEvent, applyProjection, assembleGraphResult, assertAuthoredCode,
|
|
2076
|
+
export { CONDITION_OPS, DEFAULT_MAX_NODE_VISITS, ENGINE_WOKEN_SEQ_BASE, JOIN_RULES, MAX_MAX_NODE_VISITS, RUN_GRAPH_ROOT_KIND, admitPayload, agentKind, applyGraphFoldEvent, applyProjection, assembleGraphResult, assertAuthoredCode, compileGraph, createEdgeLedger, createGraphEngine, createGraphRun, createRegistry, decideJoin, emptyFoldState, evaluateCondition, foldGraphJournal, formatRegistryHandle, graphFromRunGraph, isEngineFired, isSuspensionRequest, kindHandle, materializeSettles, mintSuspensionToken, narrowEffects, openGraphRun, parseRegistryHandle, runEngineGraph, schemaAccepts, scriptKind, subgraphKind, supervisorKind, suspended, suspensionNodeId, tokenFromSuspensionNodeId, validateCondition, validateNodeKind, validateProjection };
|
|
2258
2077
|
|
|
2259
2078
|
//# sourceMappingURL=graph.js.map
|