@parcha/agentrun-serve 0.1.0-beta.29 → 0.1.0-beta.31
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/CHANGELOG.md +238 -0
- package/README.md +739 -116
- package/dist/adapters.d.ts +35 -6
- package/dist/adapters.js +152 -26
- package/dist/agents.d.ts +18 -7
- package/dist/agents.js +19 -10
- package/dist/app.js +101 -26
- package/dist/background.d.ts +29 -0
- package/dist/background.js +397 -0
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +99 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +1 -1
- package/dist/box-image.js +9 -7
- package/dist/box-relay-vm.d.ts +84 -0
- package/dist/box-relay-vm.js +410 -0
- package/dist/box-relay.d.ts +8 -5
- package/dist/box-relay.js +14 -9
- package/dist/boxes.d.ts +28 -5
- package/dist/boxes.js +44 -18
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +130 -21
- package/dist/cap.js +339 -67
- package/dist/cli.js +30 -4
- package/dist/coding-tools.d.ts +7 -3
- package/dist/coding-tools.js +16 -10
- package/dist/console/THIRD-PARTY-NOTICES.txt +580 -0
- package/dist/console/assets/index-CnJBf7Lc.js +486 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-rows.d.ts +11 -3
- package/dist/decision-rows.js +18 -11
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -2
- package/dist/files.d.ts +9 -1
- package/dist/files.js +10 -2
- package/dist/grade.d.ts +11 -11
- package/dist/grade.js +43 -55
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +7 -5
- package/dist/graph-view.js +10 -3
- package/dist/harness-app.d.ts +4 -2
- package/dist/harness-app.js +110 -19
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +4 -1
- package/dist/harness.js +5 -2
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/host-tools.d.ts +12 -2
- package/dist/host-tools.js +26 -12
- package/dist/host.js +6 -2
- package/dist/hosted-search.js +5 -1
- package/dist/import.d.ts +2 -2
- package/dist/import.js +4 -3
- package/dist/key-check.d.ts +3 -2
- package/dist/key-check.js +7 -3
- package/dist/key-refusal.js +8 -4
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/check.d.ts +10 -1
- package/dist/learn/check.js +19 -1
- package/dist/learn/grade.d.ts +6 -2
- package/dist/learn/grade.js +28 -14
- package/dist/learn/index.d.ts +3 -3
- package/dist/learn/index.js +3 -3
- package/dist/learn/notes.js +2 -1
- package/dist/learn/reflect.d.ts +2 -2
- package/dist/learn/reflect.js +53 -5
- package/dist/learn/secrets.js +28 -8
- package/dist/learn/skills.d.ts +19 -4
- package/dist/learn/skills.js +95 -6
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +8 -6
- package/dist/learning-run.js +70 -27
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +34 -13
- package/dist/learning.d.ts +52 -3
- package/dist/learning.js +204 -4
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +33 -9
- package/dist/mcp-servers.js +58 -10
- package/dist/mcp.js +5 -5
- package/dist/model.d.ts +13 -11
- package/dist/model.js +11 -10
- package/dist/openapi/agentrun-v2.openapi.json +1 -0
- package/dist/openapi.js +407 -54
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/paid-calls.d.ts +5 -1
- package/dist/paid-calls.js +1 -1
- package/dist/pause.d.ts +2 -0
- package/dist/place.d.ts +29 -5
- package/dist/place.js +51 -11
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/propose.d.ts +2 -0
- package/dist/propose.js +38 -8
- package/dist/request-start.d.ts +12 -4
- package/dist/request-start.js +139 -15
- package/dist/run-box.d.ts +56 -4
- package/dist/run-box.js +183 -23
- package/dist/runnable.d.ts +13 -3
- package/dist/runnable.js +63 -6
- package/dist/runs.d.ts +266 -37
- package/dist/runs.js +884 -90
- package/dist/secrets.d.ts +27 -0
- package/dist/secrets.js +38 -2
- package/dist/server.d.ts +141 -36
- package/dist/server.js +562 -118
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +16 -4
- package/dist/skills.js +35 -7
- package/dist/stats.d.ts +7 -2
- package/dist/stats.js +28 -7
- package/dist/tool-gate.d.ts +281 -0
- package/dist/tool-gate.js +585 -0
- package/dist/tool-keys.d.ts +48 -11
- package/dist/tool-keys.js +46 -8
- package/dist/tool-plane.d.ts +116 -27
- package/dist/tool-plane.js +232 -50
- package/dist/tools.d.ts +69 -14
- package/dist/tools.js +148 -26
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +3 -2
- package/dist/turn-end.js +3 -2
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +11 -2
- package/dist/web-fetch.js +3 -3
- package/dist/webhooks.d.ts +11 -4
- package/dist/webhooks.js +17 -1
- package/launcher/agentrun-serve +1 -1
- package/package.json +16 -14
- package/dist/console/assets/index-BN7oVcO4.js +0 -445
- package/dist/console/assets/index-By-jkqki.css +0 -1
package/dist/grade.js
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
// the prompt is bounded whatever the folder holds (GRADE_CAPS). It runs on the model the server names for grading
|
|
6
6
|
// (learning.ts gradeModelOf: `--grade-model`, else its strong tier), else on the agent's own. Its answer is read by parseVerdict,
|
|
7
7
|
// which fails closed. A
|
|
8
|
-
// call cut off at its bound spent what nobody knows: the grade's cost is then unknown, never $0.
|
|
9
|
-
//
|
|
10
|
-
//
|
|
8
|
+
// call cut off at its bound spent what nobody knows: the grade's cost is then unknown, never $0. No injection screen
|
|
9
|
+
// runs before it: a page classifier cannot see where a note came from, and dropped a preference the user stated (it
|
|
10
|
+
// reads like an instruction); the grader's Planted question decides, with what the user said in view.
|
|
11
11
|
// - The merge is one host commit on main, made with plumbing on a temporary index: the new notes added, each note one of
|
|
12
12
|
// them supersedes marked, the skill's and draft's files added or changed (one the grader held, marked pending), and
|
|
13
13
|
// MEMORY.md rebuilt (buildIndex). Its message is `learning: <run id>: merged`, the verdict's
|
|
@@ -16,20 +16,17 @@
|
|
|
16
16
|
// (learn/check.ts mergeProblems) are asked again of main as it is then, and each note superseded must still be the
|
|
17
17
|
// blob the grade read: one a person changed since is theirs, and nothing merges. The checked-out files are brought in
|
|
18
18
|
// line.
|
|
19
|
-
// The merge runs in the agent's queue; the
|
|
19
|
+
// The merge runs in the agent's queue; the grader never does, so no run's seed waits on a model.
|
|
20
20
|
import { rm } from "node:fs/promises";
|
|
21
21
|
import { join } from "node:path";
|
|
22
22
|
import { buildIndex, gradedItems, held, INDEX_FILE, learnedPlace, mergedNote, mergeProblems, parseNoteFile, supersede, supersededBy } from "./learn/index.js";
|
|
23
23
|
import { claudeModel, claudeProvider, codexModel, codexProvider } from "./adapters.js";
|
|
24
|
-
import { FAUX_JEV_ENV, fauxFetch, jevKey } from "./decisions.js";
|
|
25
24
|
import { homeOf } from "./files.js";
|
|
26
25
|
import { FAUX_HARNESS_ENV } from "./harness.js";
|
|
27
26
|
import { agentFolder, checkOut, git, line, mainOf, NO_TOKENS, readBlobs, withAgentRepo } from "./learning.js";
|
|
28
27
|
import { completer } from "./llm.js";
|
|
29
28
|
import { openRouterOnly, runModels, thinkingOf } from "./model.js";
|
|
30
|
-
/** How long
|
|
31
|
-
* grader may write. */
|
|
32
|
-
const SCREEN_TIMEOUT_MS = 60_000;
|
|
29
|
+
/** How long the grader may take (unless the server names another), and the most it may write. */
|
|
33
30
|
const GRADE_TIMEOUT_MS = 180_000;
|
|
34
31
|
const GRADE_MAX_TOKENS = 16_000;
|
|
35
32
|
const utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
@@ -160,14 +157,15 @@ async function graderModel(env, agent, cost, named) {
|
|
|
160
157
|
const at = (found) => (found && typeof found === "object" ? { ...found, baseUrl: sent.origin } : found);
|
|
161
158
|
chosen = { models: { getModel: (provider, id) => at(catalog.getModel(provider, id)), completeSimple: (...call) => catalog.completeSimple(...call) }, model: { provider: "anthropic", modelId: sent.modelId } };
|
|
162
159
|
}
|
|
163
|
-
else if (agent.harness === "codex" && !env[FAUX_HARNESS_ENV] && openRouterOnly(
|
|
164
|
-
// codex on OpenRouter alone: the grade goes where the run's requests go,
|
|
165
|
-
// runs (codexModel, then the id codexProvider sends), through pi-ai's
|
|
166
|
-
// (openai/<model>) would ask for an OpenAI key, which this route never
|
|
167
|
-
|
|
160
|
+
else if ((agent.harness === "codex" || agent.harness === "opencode") && !env[FAUX_HARNESS_ENV] && openRouterOnly(agent.harness, env)) {
|
|
161
|
+
// codex on OpenRouter alone, and opencode, which takes codex's route: the grade goes where the run's requests go,
|
|
162
|
+
// OpenRouter with its key, on the model the run runs (codexModel, then the id codexProvider sends), through pi-ai's
|
|
163
|
+
// openrouter provider. The revision's own name (openai/<model>) would ask for an OpenAI key, which this route never
|
|
164
|
+
// needs.
|
|
165
|
+
const choice = await codexModel(env, agent.model, agent.harness);
|
|
168
166
|
if ("why" in choice)
|
|
169
167
|
throw new Error(choice.why);
|
|
170
|
-
chosen = await runModels(env, `openrouter/${codexProvider(env, choice.model).modelId}`);
|
|
168
|
+
chosen = await runModels(env, `openrouter/${codexProvider(env, choice.model, agent.harness).modelId}`);
|
|
171
169
|
}
|
|
172
170
|
else
|
|
173
171
|
chosen = await runModels(env, agent.model);
|
|
@@ -190,55 +188,28 @@ async function graderModel(env, agent, cost, named) {
|
|
|
190
188
|
return answer;
|
|
191
189
|
};
|
|
192
190
|
}
|
|
193
|
-
/** The
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!key)
|
|
199
|
-
return undefined;
|
|
200
|
-
const [{ jevProvider }, { judgeFromProvider }, fetch] = await Promise.all([import("@parcha/agentrun-jev"), import("@parcha/agentrun-dsl"), fauxFetch(env, FAUX_JEV_ENV)]);
|
|
201
|
-
const judge = judgeFromProvider(jevProvider({ apiKey: key.key, ...(key.route === "openrouter" ? { provider: "openrouter" } : {}), ...(fetch ? { fetch } : {}) }));
|
|
202
|
-
const add = counter(cost);
|
|
203
|
-
return async (request) => {
|
|
204
|
-
const result = await judge(request).catch((error) => (add(typeof error?.costUsd === "number" ? error.costUsd : null, null), Promise.reject(error)));
|
|
205
|
-
// A decision provider counts `{input_tokens, output_tokens}`, with no cache of its own.
|
|
206
|
-
const used = (result.usage ?? null);
|
|
207
|
-
add(typeof result.cost_usd === "number" ? result.cost_usd : null, typeof used?.input_tokens === "number" && typeof used.output_tokens === "number" ? { ...NO_TOKENS, input: used.input_tokens, output: used.output_tokens } : null);
|
|
208
|
-
return result;
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
/** The screen (only with an independent judge), then the grader, on `gradeModel` when the server names one (gradeModelOf),
|
|
212
|
-
* given `asked`, what the user said in the run: the first note the screen refuses or cannot judge, the grader's verdict,
|
|
213
|
-
* or why the grader gave none; with what it spent. Rejects only when `signal` (the server closing) aborts it: nothing
|
|
214
|
-
* is decided then. */
|
|
191
|
+
/** The grader, on `gradeModel` when the server names one (gradeModelOf), given `asked`, what the user said in the run:
|
|
192
|
+
* its verdict, or why it gave none; with what it spent. An answer the host cannot read is asked once more, with the same
|
|
193
|
+
* prompt and under the same bound, each ask counted once in `cost`; two such answers are a drop that could not be read,
|
|
194
|
+
* with the last answer as it came (`unread`, for the caller to cut of secrets and keep). Rejects only when `signal` (the
|
|
195
|
+
* server closing) aborts it: nothing is decided then. */
|
|
215
196
|
export async function judgeProposal(input) {
|
|
216
197
|
const { runId, agent, main, proposed, env, signal } = input;
|
|
217
198
|
const files = input.files ?? [];
|
|
218
199
|
const cost = { usd: 0, tokens: { ...NO_TOKENS } };
|
|
219
|
-
const judge = await independentJudge(env, cost);
|
|
220
|
-
if (judge) {
|
|
221
|
-
const { createPageClassifier, INJECTION_THRESHOLD } = await import("@parcha/pi-browser");
|
|
222
|
-
const screened = [...proposed, ...files];
|
|
223
|
-
const classify = createPageClassifier({ judge: () => judge, maxPages: screened.length });
|
|
224
|
-
for (const { file, text } of screened) {
|
|
225
|
-
const verdict = await bounded(SCREEN_TIMEOUT_MS, signal, cost, (screen) => classify({ url: file, status: null, contentType: null, text }, screen)).catch(() => undefined);
|
|
226
|
-
signal.throwIfAborted();
|
|
227
|
-
// The injection score alone decides: the classifier's wall question is about pages, not notes.
|
|
228
|
-
const score = verdict?.injection;
|
|
229
|
-
if (typeof score !== "number" || !Number.isFinite(score))
|
|
230
|
-
return { reason: "screen_down", file, cost };
|
|
231
|
-
if (score >= INJECTION_THRESHOLD)
|
|
232
|
-
return { reason: "screen", file, cost };
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
200
|
try {
|
|
236
|
-
const { gradePrompt, parseVerdict } = await import("./learn/index.js");
|
|
201
|
+
const { gradePrompt, parseVerdict, UNREADABLE_REASON } = await import("./learn/index.js");
|
|
237
202
|
const prompt = gradePrompt({ run: runId, instructions: agent.instructions, active: main.active, superseded: main.superseded, proposed, ...(files.length ? { files } : {}), ...(input.asked ? { asked: input.asked } : {}) });
|
|
238
203
|
const grader = await graderModel(env, agent, cost, input.gradeModel);
|
|
239
|
-
const
|
|
204
|
+
const ask = () => bounded(input.gradeTimeoutMs ?? GRADE_TIMEOUT_MS, signal, cost, (grade) => grader({ prompt, maxTokens: GRADE_MAX_TOKENS }, grade));
|
|
240
205
|
// The items with their texts: a note the run marked risky waits whatever the grader says (parseVerdict).
|
|
241
|
-
|
|
206
|
+
const items = gradedItems(proposed, files);
|
|
207
|
+
const first = parseVerdict((await ask()).text, items);
|
|
208
|
+
if (first.reason !== UNREADABLE_REASON || first.items.length)
|
|
209
|
+
return { verdict: first, cost };
|
|
210
|
+
const again = (await ask()).text;
|
|
211
|
+
const verdict = parseVerdict(again, items);
|
|
212
|
+
return verdict.reason === UNREADABLE_REASON && !verdict.items.length ? { verdict, unread: typeof again === "string" ? again : "", cost } : { verdict, cost };
|
|
242
213
|
}
|
|
243
214
|
catch (error) {
|
|
244
215
|
signal.throwIfAborted();
|
|
@@ -248,6 +219,23 @@ export async function judgeProposal(input) {
|
|
|
248
219
|
/** Each skill and draft file as main keeps it: as the run gave it, or, for one the grader held for its owner's OK, with
|
|
249
220
|
* `status: pending` in its SKILL.md or its README.md (learn/skills.ts held). A held workflow.json is as given: its
|
|
250
221
|
* README holds it. */
|
|
222
|
+
/** The graded item a proposal's file is judged as: a draft's README.md with its workflow.json, every other file as
|
|
223
|
+
* itself (a note, a skill's SKILL.md, a draft's workflow.json). */
|
|
224
|
+
const itemOf = (file) => {
|
|
225
|
+
const place = learnedPlace(file);
|
|
226
|
+
return place?.kind === "readme" ? `workflows/${place.name}/workflow.json` : file;
|
|
227
|
+
};
|
|
228
|
+
/** `proposal` with only what `verdict` keeps (a verdict per item): each note, skill and draft (both its files) its item
|
|
229
|
+
* keeps or holds; the ones it drops are left out. A proposal with no verdict (a merge resumed on one kept before the
|
|
230
|
+
* grade read items) is as it is. */
|
|
231
|
+
export function keptProposal(proposal, verdict) {
|
|
232
|
+
if (!verdict?.items.length)
|
|
233
|
+
return proposal;
|
|
234
|
+
const kept = new Set(verdict.items.filter((item) => item.keep).map((item) => item.file));
|
|
235
|
+
const files = (proposal.files ?? []).filter(({ file }) => kept.has(itemOf(file)));
|
|
236
|
+
const { files: _, ...rest } = proposal;
|
|
237
|
+
return { ...rest, notes: proposal.notes.filter(({ file }) => kept.has(file)), ...(files.length ? { files } : {}) };
|
|
238
|
+
}
|
|
251
239
|
export function heldFiles(files, verdict) {
|
|
252
240
|
const waiting = new Set((verdict?.items ?? []).filter((item) => item.pending).map((item) => item.file));
|
|
253
241
|
return files.map(({ file, text }) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The most of a map item's label and of an error (a call's, a decision's) the graph shows. */
|
|
2
|
+
export declare const LABEL_SHOWN = 200;
|
|
3
|
+
export declare const ERROR_SHOWN = 2000;
|
|
4
|
+
export type PartKind = "nodes" | "decision" | "effect";
|
|
5
|
+
/** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: each string and number by
|
|
6
|
+
* redactedOutput, then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text stored cut (a
|
|
7
|
+
* decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from before) has its
|
|
8
|
+
* last 6 times the longest held value plus 16 characters held back, where a value the stored cut split would sit. */
|
|
9
|
+
export declare function servedPart(kind: PartKind, value: unknown, values: readonly string[]): unknown;
|
|
10
|
+
/** What every run's graph keeps in serve's memory, in one cache: each part as served (servedPart), and each workflow
|
|
11
|
+
* run's last whole view, which a busy store's read answers from. */
|
|
12
|
+
export declare const GRAPH_CACHE_BYTES: number;
|
|
13
|
+
/** A least recently used cache bounded by bytes: an entry read or set is the most recent, and past `maxBytes` the least
|
|
14
|
+
* recent go, one at a time, until it fits; never all at once. An entry bigger than the bound is not kept. */
|
|
15
|
+
export declare class PartCache {
|
|
16
|
+
readonly maxBytes: number;
|
|
17
|
+
private readonly entries;
|
|
18
|
+
bytes: number;
|
|
19
|
+
constructor(maxBytes: number);
|
|
20
|
+
get size(): number;
|
|
21
|
+
get(key: string): unknown;
|
|
22
|
+
set(key: string, value: unknown, bytes: number): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// What GET /runs/{id}/graph serves of each part of a run's graph (runs.ts servedGraph): redacted by a run's answer's rule
|
|
2
|
+
// (key-refusal.ts redactedOutput, over the values the server holds and handed the run), and only then cut. graph-view.ts
|
|
3
|
+
// makes the view whole, so a key saved after it was made, or kept for a busy store's read, is still found.
|
|
4
|
+
import { redactedOutput } from "./key-refusal.js";
|
|
5
|
+
/** The most of a map item's label and of an error (a call's, a decision's) the graph shows. */
|
|
6
|
+
export const LABEL_SHOWN = 200;
|
|
7
|
+
export const ERROR_SHOWN = 2000;
|
|
8
|
+
/** Where an error was cut when it was stored, before errors were stored whole: one this long may have been cut there. */
|
|
9
|
+
const ERROR_CUT_BEFORE = 2000;
|
|
10
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
/** `value`, a part of a graph view of `kind`, as the graph serves it with `values` held: each string and number by
|
|
12
|
+
* redactedOutput, then a map item's label cut at LABEL_SHOWN and an error at ERROR_SHOWN. A text stored cut (a
|
|
13
|
+
* decision's state past 64 KB, an error marked cut, or one of exactly ERROR_CUT_BEFORE characters from before) has its
|
|
14
|
+
* last 6 times the longest held value plus 16 characters held back, where a value the stored cut split would sit. */
|
|
15
|
+
export function servedPart(kind, value, values) {
|
|
16
|
+
const shown = redactedOutput(value, values);
|
|
17
|
+
if (!isRecord(shown))
|
|
18
|
+
return shown;
|
|
19
|
+
const hold = 6 * values.reduce((most, held) => Math.max(most, held.length), 0) + 16;
|
|
20
|
+
const heldBack = (text) => `${text.slice(0, Math.max(0, text.length - hold))}…`;
|
|
21
|
+
if (kind === "nodes") {
|
|
22
|
+
return Object.fromEntries(Object.entries(shown).map(([path, node]) => [path, isRecord(node) && Array.isArray(node.items) ? { ...node, items: node.items.map((item) => (isRecord(item) && typeof item.label === "string" ? { ...item, label: item.label.slice(0, LABEL_SHOWN) } : item)) } : node]));
|
|
23
|
+
}
|
|
24
|
+
const raw = isRecord(value) ? value : {};
|
|
25
|
+
const { error_cut: _cut, error_truncated: _truncated, ...rest } = shown;
|
|
26
|
+
const out = { ...rest };
|
|
27
|
+
if (kind === "decision" && out.state_truncated === true && typeof out.state === "string")
|
|
28
|
+
out.state = heldBack(out.state);
|
|
29
|
+
if (typeof out.error === "string") {
|
|
30
|
+
const cut = raw.error_cut === true || raw.error_truncated === true || (typeof raw.error === "string" && raw.error.length === ERROR_CUT_BEFORE);
|
|
31
|
+
out.error = (cut ? heldBack(out.error) : out.error).slice(0, ERROR_SHOWN);
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
/** What every run's graph keeps in serve's memory, in one cache: each part as served (servedPart), and each workflow
|
|
36
|
+
* run's last whole view, which a busy store's read answers from. */
|
|
37
|
+
export const GRAPH_CACHE_BYTES = 32 * 1024 * 1024;
|
|
38
|
+
/** A least recently used cache bounded by bytes: an entry read or set is the most recent, and past `maxBytes` the least
|
|
39
|
+
* recent go, one at a time, until it fits; never all at once. An entry bigger than the bound is not kept. */
|
|
40
|
+
export class PartCache {
|
|
41
|
+
maxBytes;
|
|
42
|
+
entries = new Map();
|
|
43
|
+
bytes = 0;
|
|
44
|
+
constructor(maxBytes) {
|
|
45
|
+
this.maxBytes = maxBytes;
|
|
46
|
+
}
|
|
47
|
+
get size() {
|
|
48
|
+
return this.entries.size;
|
|
49
|
+
}
|
|
50
|
+
get(key) {
|
|
51
|
+
const entry = this.entries.get(key);
|
|
52
|
+
if (!entry)
|
|
53
|
+
return undefined;
|
|
54
|
+
this.entries.delete(key);
|
|
55
|
+
this.entries.set(key, entry);
|
|
56
|
+
return entry.value;
|
|
57
|
+
}
|
|
58
|
+
set(key, value, bytes) {
|
|
59
|
+
const old = this.entries.get(key);
|
|
60
|
+
if (old) {
|
|
61
|
+
this.entries.delete(key);
|
|
62
|
+
this.bytes -= old.bytes;
|
|
63
|
+
}
|
|
64
|
+
if (bytes > this.maxBytes)
|
|
65
|
+
return;
|
|
66
|
+
this.entries.set(key, { value, bytes });
|
|
67
|
+
this.bytes += bytes;
|
|
68
|
+
for (const [oldest, entry] of this.entries) {
|
|
69
|
+
if (this.bytes <= this.maxBytes)
|
|
70
|
+
break;
|
|
71
|
+
this.entries.delete(oldest);
|
|
72
|
+
this.bytes -= entry.bytes;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/dist/graph-view.d.ts
CHANGED
|
@@ -53,6 +53,12 @@ export declare function runGraph(given: GraphInput): Promise<{
|
|
|
53
53
|
graph: import("@parcha/agentrun-dsl/graph").WorkflowGraph;
|
|
54
54
|
nodes: Record<string, NodeView>;
|
|
55
55
|
decisions: {
|
|
56
|
+
images: {
|
|
57
|
+
token: {} | null;
|
|
58
|
+
ref: {} | null;
|
|
59
|
+
url: string | null;
|
|
60
|
+
}[];
|
|
61
|
+
error_cut?: boolean | undefined;
|
|
56
62
|
id: {} | null;
|
|
57
63
|
node: string | null;
|
|
58
64
|
executionPath: {} | null;
|
|
@@ -72,11 +78,6 @@ export declare function runGraph(given: GraphInput): Promise<{
|
|
|
72
78
|
state: {} | null;
|
|
73
79
|
state_truncated: boolean;
|
|
74
80
|
error: string | null;
|
|
75
|
-
images: {
|
|
76
|
-
token: {} | null;
|
|
77
|
-
ref: {} | null;
|
|
78
|
-
url: string | null;
|
|
79
|
-
}[];
|
|
80
81
|
}[];
|
|
81
82
|
effects: {
|
|
82
83
|
node: string | null;
|
|
@@ -87,6 +88,7 @@ export declare function runGraph(given: GraphInput): Promise<{
|
|
|
87
88
|
input: unknown;
|
|
88
89
|
output: unknown;
|
|
89
90
|
error: string | null;
|
|
91
|
+
error_cut?: boolean;
|
|
90
92
|
startedAt: string;
|
|
91
93
|
endedAt: string | null;
|
|
92
94
|
}[];
|
package/dist/graph-view.js
CHANGED
|
@@ -11,15 +11,17 @@ import { llmAnswers, readLiveView, readNodeLog } from "./pause.js";
|
|
|
11
11
|
const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
12
|
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
13
13
|
const at = (state, path) => path.split(".").reduce((value, key) => (isObject(value) ? value[key] : undefined), state);
|
|
14
|
+
/** A map item's label: the item, or its name, whole. The server redacts it, then cuts it (runs.ts servedGraph): a view kept
|
|
15
|
+
* for a busy store's read holds what was written, so a key saved after it is still found whole. */
|
|
14
16
|
const labelOf = (item) => {
|
|
15
17
|
if (typeof item === "string")
|
|
16
|
-
return item
|
|
18
|
+
return item;
|
|
17
19
|
if (typeof item === "number")
|
|
18
20
|
return String(item);
|
|
19
21
|
if (!isObject(item))
|
|
20
22
|
return undefined;
|
|
21
23
|
const named = item.name ?? item.label ?? item.title ?? item.id ?? item.file ?? item.path ?? item.url;
|
|
22
|
-
return typeof named === "string" || typeof named === "number" ? String(named)
|
|
24
|
+
return typeof named === "string" || typeof named === "number" ? String(named) : undefined;
|
|
23
25
|
};
|
|
24
26
|
export async function runGraph(given) {
|
|
25
27
|
const [{ graphNodeOf, nodeStatus, workflowGraph }, { readWorkflowRun }, { durableDecisions, readJournal }] = await Promise.all([
|
|
@@ -169,6 +171,8 @@ export async function runGraph(given) {
|
|
|
169
171
|
questions: r.questions ?? null, answers: r.answers ?? null, evidence: r.evidence ?? [], rule: r.rule ?? null, action: r.action ?? null,
|
|
170
172
|
cost_usd: typeof r.cost_usd === "number" ? r.cost_usd : null, cost_basis: r.cost_basis ?? null, latency_ms: r.latency_ms ?? null,
|
|
171
173
|
state: r.state ?? null, state_truncated: r.state_truncated === true, error: typeof r.error === "string" ? r.error : null,
|
|
174
|
+
// Whole up to 64 KB (the DSL's receipt); `error_cut` marks one it kept cut, for the server to hold its tail back.
|
|
175
|
+
...(r.error_truncated === true ? { error_cut: true } : {}),
|
|
172
176
|
images: images.map((image) => ({ token: image.token ?? null, ref: image.ref ?? null, url: typeof image.ref === "string" ? runFile(image.ref) : null })),
|
|
173
177
|
};
|
|
174
178
|
});
|
|
@@ -188,7 +192,10 @@ export async function runGraph(given) {
|
|
|
188
192
|
if (!start)
|
|
189
193
|
continue;
|
|
190
194
|
const effect = effects[placeOf.get(start)];
|
|
191
|
-
|
|
195
|
+
// An error is stored whole up to 64 KB (app.ts), longer ones cut and marked; one of a log from before, cut at 2000.
|
|
196
|
+
// Whole, as logged (up to 64 KB, app.ts); `error_cut` marks one stored cut, for the server to hold its tail back
|
|
197
|
+
// (graph-served.ts, which also takes one of exactly 2000 characters, from a log made before, as cut).
|
|
198
|
+
Object.assign(effect, { status: line.status, output: line.output ?? null, error: line.error ?? null, ...(line.error_truncated === true ? { error_cut: true } : {}), endedAt: line.at });
|
|
192
199
|
}
|
|
193
200
|
}
|
|
194
201
|
// The run's spend: its decisions', its llm calls' and its model nodes'; one unknown makes it unknown. An llm call's cost
|
package/dist/harness-app.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
|
3
3
|
import { type AgentAdapter, type SessionSpec } from "@parcha/agentrun-kernel";
|
|
4
4
|
import type { DoorHook, DurableRun } from "@parcha/pi-durable-disk";
|
|
5
5
|
import { type ConfineChild } from "./adapters.js";
|
|
6
|
+
import { type RunGate } from "./tool-gate.js";
|
|
6
7
|
import { type CapGuard } from "./cap.js";
|
|
7
8
|
/** The root's marker of a paid request already written as a pi.assistant entry. */
|
|
8
9
|
export declare const BOOKED = "adapter.request";
|
|
@@ -34,5 +35,6 @@ export interface AdapterRun {
|
|
|
34
35
|
* `budgetUsd`: the run's spend cap. `cancelled`: whether the run was cancelled (request-start.ts `cancelledIn`): once it
|
|
35
36
|
* says so, no model request leaves, as on pi. `cwd`: the run's workspace, the directory its file tools confine to, where
|
|
36
37
|
* the harness works too (the adapter's io.cwd), so a path the model builds from its working directory is one the tools
|
|
37
|
-
* take (in a box, coding-tools.ts names it at the box's work dir).
|
|
38
|
-
|
|
38
|
+
* take (in a box, coding-tools.ts names it at the box's work dir). `gate`: the run's tool gate, which each host tool
|
|
39
|
+
* call passes. */
|
|
40
|
+
export declare function adapterRun(make: (confine?: ConfineChild) => Promise<AgentAdapter>, harness: string, spec: Omit<SessionSpec, "tools">, context: Context, budgetUsd?: number, tools?: readonly string[], dir?: string, cap?: CapGuard, cancelled?: () => boolean, cwd?: string, coding?: readonly ToolRegistration[], stopRecord?: StopRecord, gate?: RunGate, extra?: readonly ToolRegistration[]): AdapterRun;
|