@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.50
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 +26 -9
- package/README.md +104 -22
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +9 -11
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/{index-CR2ZGei1.css → index-D0mr9wfZ.css} +1 -1
- package/dist/console/assets/index-D7G6o-1E.js +720 -0
- package/dist/console/index.html +2 -2
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness.js +2 -1
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/openapi.js +25 -17
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +2 -2
- package/dist/run-launch.js +2 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +15 -1
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +13 -6
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +14 -6
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/learning-end.js +9 -4
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/run-child-host.d.ts +15 -2
- package/dist/runner/run-child-host.js +24 -8
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/sdk/runs.d.ts +3 -4
- package/dist/sdk/runs.js +10 -7
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +4 -0
- package/dist/server.js +3 -3
- package/dist/store/agent-body.d.ts +2 -3
- package/dist/store/agent-body.js +3 -2
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/schema.d.ts +8 -3
- package/dist/store/schema.js +12 -2
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/store.d.ts +2 -4
- package/dist/store/sqlite/store.js +95 -85
- package/dist/store/store.d.ts +8 -1
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +37 -18
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +1 -1
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +19 -1
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +101 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
2
|
import type { Store } from "../store/store.js";
|
|
3
|
+
/** Who charges for a decision Parallel answered on its own API, on this server's key: Parallel, the same name its web
|
|
4
|
+
* tools' charges carry (paid-calls.ts). */
|
|
5
|
+
export declare const PARALLEL_CHARGER = "parallel";
|
|
6
|
+
/** Whether a decision's receipt says Parallel charged for it as a paid call: answered by the `parallel` provider on
|
|
7
|
+
* Parallel's own API, booked at Parallel's list price (`cost_basis` "estimate", @parcha/agentrun-decisions
|
|
8
|
+
* PARALLEL_LIST_PRICE_USD). One the same provider sent through OpenRouter (Parallel's model there) is booked at the cost
|
|
9
|
+
* OpenRouter reported ("reported", or "unknown"): OpenRouter charged it, a model's cost, and it stays one. */
|
|
10
|
+
export declare const chargedByParallel: (receipt: {
|
|
11
|
+
readonly provider?: unknown;
|
|
12
|
+
readonly cost_basis?: unknown;
|
|
13
|
+
}) => boolean;
|
|
14
|
+
/** A receipt's decision id, the one its booking names (`decision:<id>`). */
|
|
15
|
+
export declare const receiptIdOf: (receipt: Record<string, unknown>) => string;
|
|
16
|
+
/** The ids of the decisions among `receipts` Parallel charged as a paid call (chargedByParallel). */
|
|
17
|
+
export declare function parallelChargedDecisions(receipts: Iterable<Record<string, unknown>>): Set<string>;
|
|
18
|
+
/** Whether a run's journal `entries` book a workflow decision (a request named `decision:<id>`), so its receipts are
|
|
19
|
+
* worth reading. */
|
|
20
|
+
export declare const booksDecisions: (entries: readonly {
|
|
21
|
+
readonly kind: string;
|
|
22
|
+
readonly data?: unknown;
|
|
23
|
+
}[]) => boolean;
|
|
3
24
|
/** A run's decision receipts: the keyed `.count` and family rows in order, read through
|
|
4
25
|
* the one store's journal. */
|
|
5
26
|
export declare function decisionsOverStore(store: Store, runId: string, context: Context): Promise<Array<Record<string, unknown>>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
1
2
|
import { decisionKey } from "../workflow/decisions.js";
|
|
2
3
|
/** A session-scoped document's current value, by kind and (for a family) key: findDocument, then its stored value. */
|
|
3
4
|
async function sessionDocValue(reads, kind, key, context) {
|
|
@@ -7,6 +8,27 @@ async function sessionDocValue(reads, kind, key, context) {
|
|
|
7
8
|
const stored = await reads.document(record.id, "current", context);
|
|
8
9
|
return stored ? stored.value : undefined;
|
|
9
10
|
}
|
|
11
|
+
/** Who charges for a decision Parallel answered on its own API, on this server's key: Parallel, the same name its web
|
|
12
|
+
* tools' charges carry (paid-calls.ts). */
|
|
13
|
+
export const PARALLEL_CHARGER = "parallel";
|
|
14
|
+
/** Whether a decision's receipt says Parallel charged for it as a paid call: answered by the `parallel` provider on
|
|
15
|
+
* Parallel's own API, booked at Parallel's list price (`cost_basis` "estimate", @parcha/agentrun-decisions
|
|
16
|
+
* PARALLEL_LIST_PRICE_USD). One the same provider sent through OpenRouter (Parallel's model there) is booked at the cost
|
|
17
|
+
* OpenRouter reported ("reported", or "unknown"): OpenRouter charged it, a model's cost, and it stays one. */
|
|
18
|
+
export const chargedByParallel = (receipt) => receipt.provider === "parallel" && receipt.cost_basis === "estimate";
|
|
19
|
+
/** A receipt's decision id, the one its booking names (`decision:<id>`). */
|
|
20
|
+
export const receiptIdOf = (receipt) => String(receipt.decision_id ?? receipt.id);
|
|
21
|
+
/** The ids of the decisions among `receipts` Parallel charged as a paid call (chargedByParallel). */
|
|
22
|
+
export function parallelChargedDecisions(receipts) {
|
|
23
|
+
const ids = new Set();
|
|
24
|
+
for (const receipt of receipts)
|
|
25
|
+
if (chargedByParallel(receipt))
|
|
26
|
+
ids.add(receiptIdOf(receipt));
|
|
27
|
+
return ids;
|
|
28
|
+
}
|
|
29
|
+
/** Whether a run's journal `entries` book a workflow decision (a request named `decision:<id>`), so its receipts are
|
|
30
|
+
* worth reading. */
|
|
31
|
+
export const booksDecisions = (entries) => entries.some((e) => e.kind === RUNNER_RECORDS.request && String(e.data?.model ?? "").startsWith("decision:"));
|
|
10
32
|
/** A run's decision receipts: the keyed `.count` and family rows in order, read through
|
|
11
33
|
* the one store's journal. */
|
|
12
34
|
export async function decisionsOverStore(store, runId, context) {
|
|
@@ -66,14 +66,20 @@ export type WholeAnswer = {
|
|
|
66
66
|
};
|
|
67
67
|
/** The WholeAnswer of a run whose served words are cut of `values` (run-cut.ts runCutValues). */
|
|
68
68
|
export declare const wholeAnswerFor: (values: readonly string[]) => WholeAnswer;
|
|
69
|
+
export declare const servedSince: (store: Store) => number;
|
|
70
|
+
/** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers): a purged or deleted
|
|
71
|
+
* run's text kept in no memory of this process (store-view.ts forgetServed). Counted (servedSince), so no read begun
|
|
72
|
+
* before it keeps what it read. The keys it dropped. */
|
|
73
|
+
export declare function forgetServedAnswers(store: Store, runId: string): string[];
|
|
69
74
|
/** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
|
|
70
75
|
* cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
|
|
71
76
|
* shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
|
|
72
77
|
* "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
|
|
73
78
|
* from the journal, settled as the rows were, with no text cap and none
|
|
74
79
|
* of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
|
|
75
|
-
* of it and never cuts. Every other row is as it was.
|
|
76
|
-
|
|
80
|
+
* of it and never cuts. Every other row is as it was. What it read is kept only while no run's text was forgotten since
|
|
81
|
+
* `since` (servedSince, taken before the read began). */
|
|
82
|
+
export declare function wholeAnswers(store: Store, runId: string, context: Context, rows: TimelineEvent[], options: TimelineOptions, whole: WholeAnswer, since: number): Promise<TimelineEvent[]>;
|
|
77
83
|
/** What was said to a run (its hearing), from the one store's entries, as runs.ts noteTurns fed it from the stream: each
|
|
78
84
|
* user entry noted in log order, its origin read by the same matcher. */
|
|
79
85
|
export declare function runHearing(store: Store, runId: string, context: Context): Promise<Hearing>;
|
|
@@ -426,14 +426,31 @@ export const wholeAnswerFor = (values) => ({
|
|
|
426
426
|
* entry's, whose words never change. Kept by store, the newest ANSWERS_KEPT of each. */
|
|
427
427
|
const answersServed = new WeakMap();
|
|
428
428
|
const ANSWERS_KEPT = 32;
|
|
429
|
+
/** How many times the readers of each store were told to forget a run's text (forgetServedAnswers). A read takes it
|
|
430
|
+
* before it reads anything (servedSince) and keeps what it made only while it is the same, so a read begun before a
|
|
431
|
+
* purge, which may still hold the purged run's text, never puts that text back once the purge dropped it. */
|
|
432
|
+
const forgetsOf = new WeakMap();
|
|
433
|
+
export const servedSince = (store) => forgetsOf.get(store.origin) ?? 0;
|
|
434
|
+
/** Run `runId`'s answer rows dropped from what the readers of `store` last served (wholeAnswers): a purged or deleted
|
|
435
|
+
* run's text kept in no memory of this process (store-view.ts forgetServed). Counted (servedSince), so no read begun
|
|
436
|
+
* before it keeps what it read. The keys it dropped. */
|
|
437
|
+
export function forgetServedAnswers(store, runId) {
|
|
438
|
+
forgetsOf.set(store.origin, servedSince(store) + 1);
|
|
439
|
+
const kept = answersServed.get(store.origin);
|
|
440
|
+
const dropped = [...(kept?.keys() ?? [])].filter((key) => key.startsWith(`${runId}\0`));
|
|
441
|
+
for (const key of dropped)
|
|
442
|
+
kept.delete(key);
|
|
443
|
+
return dropped;
|
|
444
|
+
}
|
|
429
445
|
/** `rows` (runTimeline's, rendered with `options`) with each final answer whole, as main served a run's answer: the renderer
|
|
430
446
|
* cuts a row's text at CAPS.text, and its redactor (`options.redact`, key-refusal.ts redacted) reads only the head a row
|
|
431
447
|
* shows and cuts the rest, ending what it cut in "..." (short of the cap when it replaced a held value there), or giving
|
|
432
448
|
* "[redacted]" alone when all it read was redacted. A final answer row at the cap, ending so or reading so is read again
|
|
433
449
|
* from the journal, settled as the rows were, with no text cap and none
|
|
434
450
|
* of the rows' redactor, the same row by its id (its entry's), and given through `whole.serve`, which reads every byte
|
|
435
|
-
* of it and never cuts. Every other row is as it was.
|
|
436
|
-
|
|
451
|
+
* of it and never cuts. Every other row is as it was. What it read is kept only while no run's text was forgotten since
|
|
452
|
+
* `since` (servedSince, taken before the read began). */
|
|
453
|
+
export async function wholeAnswers(store, runId, context, rows, options, whole, since) {
|
|
437
454
|
// The rows' redactor gives exactly "[redacted]" for a text whose head it read was all held or secret-shaped values: the
|
|
438
455
|
// rest of the answer is past what it read, so that row is read again too.
|
|
439
456
|
const cut = (row) => row.kind === "final_answer" && row.text !== null && (row.text.length >= CAPS.text || row.text.endsWith("...") || row.text === "[redacted]");
|
|
@@ -461,12 +478,14 @@ export async function wholeAnswers(store, runId, context, rows, options, whole)
|
|
|
461
478
|
continue;
|
|
462
479
|
}
|
|
463
480
|
served = whole.serve(text);
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
481
|
+
if (servedSince(store) === since) {
|
|
482
|
+
kept.delete(key);
|
|
483
|
+
kept.set(key, served);
|
|
484
|
+
for (const oldest of kept.keys()) {
|
|
485
|
+
if (kept.size <= ANSWERS_KEPT)
|
|
486
|
+
break;
|
|
487
|
+
kept.delete(oldest);
|
|
488
|
+
}
|
|
470
489
|
}
|
|
471
490
|
}
|
|
472
491
|
out.push({ ...row, text: served });
|
package/dist/store-view.d.ts
CHANGED
|
@@ -39,6 +39,10 @@ export declare const settledStatusOf: (state: RunReadState) => Status | undefine
|
|
|
39
39
|
* that withheld the run for a sign-in it could not read back (listingOverStore), and the lister's build that failed
|
|
40
40
|
* (run-listing.ts). */
|
|
41
41
|
export declare const LISTING_RETRY_MS = 30000;
|
|
42
|
+
/** Run `runId`'s text dropped from what the readers of `store` last served: its view's slots (its answer's, its input's)
|
|
43
|
+
* and its whole answer rows (store-reads/journal.ts forgetServedAnswers), so a purged or deleted run's text stays in no
|
|
44
|
+
* memory of this process (agent-delete.ts). What it dropped, by slot and key. */
|
|
45
|
+
export declare function forgetServed(store: Store, runId: string): string[];
|
|
42
46
|
/** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
|
|
43
47
|
* never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
|
|
44
48
|
* followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
|
|
@@ -148,7 +152,7 @@ export declare function healStoredCost(store: Store, runId: string, heal: NonNul
|
|
|
148
152
|
export declare function lookingBackEnd(store: Store, runId: string): Promise<KeptEnd | undefined>;
|
|
149
153
|
/** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
|
|
150
154
|
* paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
|
|
151
|
-
* time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
|
|
155
|
+
* time) and the decisions Parallel charged on its own API (store-reads/decisions.ts chargedByParallel), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
|
|
152
156
|
* learning's as that turn's model requests are (runCostOf). A part of `usd`, never added to it; 0 with none. Null when
|
|
153
157
|
* one's charge is unknown (charged an unknown amount, cut, or still out) or counted at its hold; while the run is at work
|
|
154
158
|
* (not ended, stopped or failed), as its `usd` is the view's snapshot and a paid call booked after it would be read here
|
package/dist/store-view.js
CHANGED
|
@@ -20,13 +20,14 @@ import { learningStartOf, seedFailed } from "./run-launch.js";
|
|
|
20
20
|
import { momentOf, pendingOf, stoppedTurn, approvalOf, asksOf, answersOf, activePauseOf, budgetOf, browserPending, computerPending, redactorOf, servedRunErrorWith, servedReviewWith, statusOf, WITHHELD_SIGN_IN, WITHHELD_TITLE, costWordsOfView, freeOf, stopAsked, usersOf, withAsks, withApprovalRows, } from "./run-view.js";
|
|
21
21
|
import { reflects } from "./reflect-range.js";
|
|
22
22
|
import { freeCeilingMessage, overCapMessage, SPEND_CAP_REACHED } from "@parcha/agentrun-kernel/kernel/cap";
|
|
23
|
-
import {
|
|
23
|
+
import { booksDecisions, decisionsOverStore, parallelChargedDecisions } from "./store-reads/decisions.js";
|
|
24
|
+
import { bookedDecisionsOf, bookedSpend, cliModelWorked, costBasisOf, costWordsOf, endCostOf, planSpend, runCostOf, storedBasisOf } from "./runner/metrics.js";
|
|
24
25
|
import { journalRecords, recordOf } from "./runner/journal-reader.js";
|
|
25
26
|
import { capNowOf, KINDS } from "./runner/journal-kinds.js";
|
|
26
27
|
import { laidOf, pathViewOf, roundsOf, runLearningEnd, usedOnly } from "./store-reads/learning.js";
|
|
27
28
|
import { inReflect, reflectRanges } from "./runner/end-of-run.js";
|
|
28
29
|
import { correctionCount } from "./learn/corrections.js";
|
|
29
|
-
import { isCliRecord, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
|
|
30
|
+
import { forgetServedAnswers, isCliRecord, servedSince, runReflect, runTimeline, wholeAnswerFor, wholeAnswers, withoutFeedbackRounds } from "./store-reads/journal.js";
|
|
30
31
|
import { costOfRun, readRun, runReadState } from "./store-reads/runs.js";
|
|
31
32
|
import { feedbackOf, keptEndOf } from "./runner/feedback-round.js";
|
|
32
33
|
import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
|
|
@@ -56,10 +57,11 @@ const iso = (ms) => new Date(ms).toISOString();
|
|
|
56
57
|
/** What a view last made of a run's text, by store and slot (a run's answer, or its input): the text it read (`input`),
|
|
57
58
|
* the digest of the values it was redacted of (`key`) and what that gave (`out`), so a second view of the same text and
|
|
58
59
|
* values reads nothing again (main's runs.ts servedOnce: a console polls a run's view, and an answer or an input can be
|
|
59
|
-
* large). Newest SERVED_KEPT slots of each store.
|
|
60
|
+
* large). Newest SERVED_KEPT slots of each store. What a read made is kept only while no run's text was forgotten since
|
|
61
|
+
* `since` (servedSince, taken before the read began), so a read a purge overtook never keeps the purged text. */
|
|
60
62
|
const servedByStore = new WeakMap();
|
|
61
63
|
const SERVED_KEPT = 64;
|
|
62
|
-
function keptOnce(store, slot, input, values, make) {
|
|
64
|
+
function keptOnce(store, slot, input, values, since, make) {
|
|
63
65
|
let served = servedByStore.get(store.origin);
|
|
64
66
|
if (!served)
|
|
65
67
|
servedByStore.set(store.origin, (served = new Map()));
|
|
@@ -68,6 +70,8 @@ function keptOnce(store, slot, input, values, make) {
|
|
|
68
70
|
if (last && last.key === key && last.input === input)
|
|
69
71
|
return last.out;
|
|
70
72
|
const out = make();
|
|
73
|
+
if (servedSince(store) !== since)
|
|
74
|
+
return out;
|
|
71
75
|
served.delete(slot);
|
|
72
76
|
served.set(slot, { input, key, out });
|
|
73
77
|
for (const oldest of served.keys()) {
|
|
@@ -77,11 +81,21 @@ function keptOnce(store, slot, input, values, make) {
|
|
|
77
81
|
}
|
|
78
82
|
return out;
|
|
79
83
|
}
|
|
84
|
+
/** Run `runId`'s text dropped from what the readers of `store` last served: its view's slots (its answer's, its input's)
|
|
85
|
+
* and its whole answer rows (store-reads/journal.ts forgetServedAnswers), so a purged or deleted run's text stays in no
|
|
86
|
+
* memory of this process (agent-delete.ts). What it dropped, by slot and key. */
|
|
87
|
+
export function forgetServed(store, runId) {
|
|
88
|
+
const served = servedByStore.get(store.origin);
|
|
89
|
+
const dropped = [`answer ${runId}`, `input ${runId}`].filter((slot) => served?.has(slot));
|
|
90
|
+
for (const slot of dropped)
|
|
91
|
+
served.delete(slot);
|
|
92
|
+
return [...dropped, ...forgetServedAnswers(store, runId)];
|
|
93
|
+
}
|
|
80
94
|
/** A run's answer as served: redactedAnswer's, once per answer and held value set. */
|
|
81
|
-
const servedOnce = (store, runId, input, values) => keptOnce(store, `answer ${runId}`, input, values, () => redactedAnswer(input, values));
|
|
95
|
+
const servedOnce = (store, runId, input, values, since) => keptOnce(store, `answer ${runId}`, input, values, since, () => redactedAnswer(input, values));
|
|
82
96
|
/** Whether a run's input is served (store-view's `input`): only when the cut a run's words get (redactedOutput) leaves it
|
|
83
97
|
* exactly as given, so "Run again" never sends an altered task. Read once per input and held value set. */
|
|
84
|
-
const inputWhole = (store, runId, input, values) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, () => isDeepStrictEqual(redactedOutput(input, values), input));
|
|
98
|
+
const inputWhole = (store, runId, input, values, since) => keptOnce(store, `input ${runId}`, JSON.stringify(input), values, since, () => isDeepStrictEqual(redactedOutput(input, values), input));
|
|
85
99
|
/** A run's whole answer as answerOfRun read it from the rows: its newest final-answer row, never the learning turn's, and
|
|
86
100
|
* never an earlier turn's: a final answer row before the person's last message belongs to the turn that message
|
|
87
101
|
* followed, so a follow-up whose own stop said nothing (no text block: a thinking-only stop) has no answer, null, not
|
|
@@ -153,8 +167,11 @@ export function standsOnPerson(approvals, entries, commands) {
|
|
|
153
167
|
* journal, live tick and commands) is made in one snapshot of the store (Store.snapshot), so the view is of one moment: a
|
|
154
168
|
* runner's commit that lands while it is built is in all of it or in none. What is read through the server's own handles
|
|
155
169
|
* (the run's cut, which reads the agent's sign-ins, and the learning statuses of its folder) is read outside the snapshot,
|
|
156
|
-
* before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection.
|
|
170
|
+
* before and after it: neither is part of the run's moment, and neither may wait on the snapshot's connection. `since`
|
|
171
|
+
* is what the run's text was forgotten as before anything was read (servedSince): what the read made of that text is
|
|
172
|
+
* kept only while it is the same (keptOnce, wholeAnswers), so a read a purge overtook keeps none of it. */
|
|
157
173
|
async function storeRunOf(store, runId, deps) {
|
|
174
|
+
const since = servedSince(store);
|
|
158
175
|
// The run's one cut (run-cut.ts): the pointers it was handed read back and every secret this server never shows, so a
|
|
159
176
|
// run whose words could repeat one is cut of it, rows and all, or withheld when this server cannot read back what it
|
|
160
177
|
// was handed (rowShown's choke point). The snapshot renders under it, so it is read first, and read again after: the cut
|
|
@@ -166,17 +183,17 @@ async function storeRunOf(store, runId, deps) {
|
|
|
166
183
|
};
|
|
167
184
|
if (!(await store.runs.get(runId)))
|
|
168
185
|
return undefined;
|
|
169
|
-
const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut)));
|
|
186
|
+
const run = await underCut(async () => (await cutOf()) ?? "unreadable", (cut) => store.snapshot((snapshot) => storeRunIn(snapshot, runId, deps, cut, since)));
|
|
170
187
|
// An ended run whose end stored its cost unknown while its booking is priced: its store is healed now, after the
|
|
171
188
|
// snapshot (which may not write), so every reader of the stored cost (the list, /stats, /usage, the learning bill)
|
|
172
189
|
// reads the figure this read shows. One conditional write (Runs.healCost); a failure is said and the next read tries again.
|
|
173
190
|
if (run?.heal)
|
|
174
191
|
await healStoredCost(store, runId, run.heal);
|
|
175
192
|
if (!run?.shownEnd || !holdsForOk(run.shownEnd) || !deps.statuses)
|
|
176
|
-
return run && { ...run, learningEnd: run.shownEnd };
|
|
193
|
+
return run && { ...run, learningEnd: run.shownEnd, since };
|
|
177
194
|
// What the learning end held for its owner's OK reads as it stands now on its agent's folder's main (learning.ts
|
|
178
195
|
// currentLearning); its record stays as the merge wrote it.
|
|
179
|
-
return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)) };
|
|
196
|
+
return { ...run, learningEnd: currentLearning(run.shownEnd, await deps.statuses(run.row.agent)), since };
|
|
180
197
|
}
|
|
181
198
|
/** Heals run `runId`'s stored unknown cost to the figure its booking gives (Runs.healCost), at the end it was read at.
|
|
182
199
|
* True when written; false when another write got there first, or when the write failed (said, never thrown: a read
|
|
@@ -212,8 +229,8 @@ export async function lookingBackEnd(store, runId) {
|
|
|
212
229
|
return undefined;
|
|
213
230
|
return lookingBackOf(stored, (await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT)).entries, () => store.commands(runId, 0));
|
|
214
231
|
}
|
|
215
|
-
/** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut. */
|
|
216
|
-
async function storeRunIn(store, runId, deps, cut) {
|
|
232
|
+
/** `storeRunOf`'s reads, over `store` (a snapshot) and the run's cut, begun at `since` (servedSince). */
|
|
233
|
+
async function storeRunIn(store, runId, deps, cut, since) {
|
|
217
234
|
const context = BACKGROUND_CONTEXT;
|
|
218
235
|
const read = await readRun(store, runId, context);
|
|
219
236
|
if (!read)
|
|
@@ -250,7 +267,7 @@ async function storeRunIn(store, runId, deps, cut) {
|
|
|
250
267
|
// A run that ended reads settled, and its usage row says its cost ("Cost: …"), never what it has cost so far. One
|
|
251
268
|
// looking back is still going: its look-back's rows come yet.
|
|
252
269
|
const timelineOptions = { settled: terminal && !lookingBack, ended: terminal && !lookingBack, redact: (text) => redacted(text, values) };
|
|
253
|
-
const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values)));
|
|
270
|
+
const timeline = withAsks(await wholeAnswers(store, runId, context, await runTimeline(store, runId, context, timelineOptions), timelineOptions, wholeAnswerFor(values), since));
|
|
254
271
|
const revisions = await store.agents.revisions(row.agent);
|
|
255
272
|
const version = revisions.findIndex((r) => r.id === row.revision) + 1;
|
|
256
273
|
const ended = await runLearningEnd(store, runId);
|
|
@@ -265,7 +282,7 @@ async function storeRunIn(store, runId, deps, cut) {
|
|
|
265
282
|
// (runReflect). progressAt reads the latest tick, so a working run's last_progress_at advances as today.
|
|
266
283
|
const sdkCompletion = records.entries.findLast(entry => entry.kind === "agentrun.sdk.completion")?.data;
|
|
267
284
|
const sdkSession = records.entries.findLast(entry => entry.kind === "agentrun.sdk.session")?.data;
|
|
268
|
-
const sdk = launch?.sdk ? { runtime: launch.sdk.runtime, model: sdkCompletion?.model ?? launch.sdk.model ?? null, session_id: sdkCompletion?.session_id ?? sdkSession?.session_id ?? null, learning_revision: launch.learning?.seed ?? null, usage: sdkCompletion?.usage ?? null } : undefined;
|
|
285
|
+
const sdk = launch?.sdk ? { runtime: launch.sdk.runtime, ...(launch.sdk.runtime === "external" ? { platform: launch.sdk.platform } : {}), model: sdkCompletion?.model ?? launch.sdk.model ?? null, session_id: sdkCompletion?.session_id ?? sdkSession?.session_id ?? null, learning_revision: launch.learning?.seed ?? null, usage: sdkCompletion?.usage ?? null } : undefined;
|
|
269
286
|
const nativeConfiguration = records.entries.findLast(e => e.kind === "agentrun.native.configuration")?.data;
|
|
270
287
|
const nativeEvents = records.entries.filter(e => e.kind === "agentrun.native.usage").map(e => e.data);
|
|
271
288
|
const reflectRange = (await runReflect(store, runId, context));
|
|
@@ -471,7 +488,7 @@ function costOfView(run) {
|
|
|
471
488
|
}
|
|
472
489
|
/** What run `runId`'s paid tool calls cost, the run read's `cost.tools_usd` (server.ts allInViewOf): the charges its
|
|
473
490
|
* paid-tools session booked (a monid endpoint's, a priced MCP tool's, Parallel's behind the web tools, the browser's
|
|
474
|
-
* time), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
|
|
491
|
+
* time) and the decisions Parallel charged on its own API (store-reads/decisions.ts chargedByParallel), joined and rounded by the one rule its `usd` is (costWordsOf), less those in its end-of-run turn, which are
|
|
475
492
|
* learning's as that turn's model requests are (runCostOf). A part of `usd`, never added to it; 0 with none. Null when
|
|
476
493
|
* one's charge is unknown (charged an unknown amount, cut, or still out) or counted at its hold; while the run is at work
|
|
477
494
|
* (not ended, stopped or failed), as its `usd` is the view's snapshot and a paid call booked after it would be read here
|
|
@@ -487,7 +504,9 @@ export async function toolsUsdOverStore(store, runId) {
|
|
|
487
504
|
return null;
|
|
488
505
|
const records = await journalRecords(store.readJournal(runId), BACKGROUND_CONTEXT);
|
|
489
506
|
const turns = reflectRanges(records.submissions ?? [], records.entries);
|
|
490
|
-
const
|
|
507
|
+
const entries = records.entries.filter((entry) => !inReflect(turns, Number(entry.id)));
|
|
508
|
+
const parallel = booksDecisions(entries) ? parallelChargedDecisions(await decisionsOverStore(store, runId, BACKGROUND_CONTEXT)) : new Set();
|
|
509
|
+
const words = costWordsOf([bookedSpend(entries, "paid"), ...(parallel.size ? [bookedDecisionsOf(entries, parallel)] : [])]);
|
|
491
510
|
return words.upper_bound ? null : words.usd;
|
|
492
511
|
}
|
|
493
512
|
/** How a run's cost was reached (metrics.ts CostBasis): by how its model requests were priced, as its booking says, while
|
|
@@ -572,7 +591,7 @@ async function viewOfRun(store, runId, deps, run, read) {
|
|
|
572
591
|
const shownWords = (text) => withoutLoopback(redacted(text, values));
|
|
573
592
|
// The answer row's text is the answer as served (whole, through redactedAnswer, once per held value set, when the row
|
|
574
593
|
// was cut; else the rows' redactor over what was never cut): served again through redactedAnswer once per that set.
|
|
575
|
-
const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values) : text);
|
|
594
|
+
const servedAnswer = (text) => (text ? servedOnce(store, runId, text, values, run.since) : text);
|
|
576
595
|
const finalAnswer = row.kind === "workflow" || unshown ? null : answerOf(run.rows) ?? row.summary ?? null;
|
|
577
596
|
// A workflow run's output, as its end kept it; an agentic run's, its final answer's structured part when its agent has
|
|
578
597
|
// an output schema and the answer's last fenced json block meets it (storeRunOf's `structured`), else none. Served as
|
|
@@ -636,7 +655,7 @@ async function viewOfRun(store, runId, deps, run, read) {
|
|
|
636
655
|
// The input the run was started with, as its launch keeps it, whole (never the first message the timeline caps): what
|
|
637
656
|
// "Run again" sends again. Null when the cut a run's words get would change it (inputWhole: a held value, a long run
|
|
638
657
|
// with no whitespace), for a withheld run, and for one whose launch holds no input object.
|
|
639
|
-
input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values) ? launch?.input : null,
|
|
658
|
+
input: !unshown && isObject(launch?.input) && inputWhole(store, runId, launch?.input, values, run.since) ? launch?.input : null,
|
|
640
659
|
file_ids: [...(launch?.files ?? [])],
|
|
641
660
|
place: launch?.place ?? { mode: "runner" },
|
|
642
661
|
// The runner holding the run now, when one does (a running run with a live claim): its id, the claim's count (up one each
|
package/dist/template-eval.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type Layout, type MailboxAfter, type MailboxFixture, type MailboxRecord } from "./eval-mailbox.js";
|
|
2
2
|
import { type FeedFixture } from "./eval-feed.js";
|
|
3
|
+
import { type PreviousFixture } from "./eval-previous.js";
|
|
4
|
+
import type { PreviousHandover } from "./trigger-targets.js";
|
|
3
5
|
import type { MonidFake } from "./runner/monid-run.js";
|
|
4
6
|
import { type WebFake } from "./web-fake.js";
|
|
5
7
|
import { type Package } from "./templates.js";
|
|
@@ -56,6 +58,11 @@ export type Grader = ({
|
|
|
56
58
|
messageId: string;
|
|
57
59
|
in?: string;
|
|
58
60
|
notIn: string[];
|
|
61
|
+
} | {
|
|
62
|
+
file: string;
|
|
63
|
+
type: "handed";
|
|
64
|
+
expect: PreviousHandover["kind"];
|
|
65
|
+
dropped?: Record<string, number>;
|
|
59
66
|
}) & {
|
|
60
67
|
/** An email case's layouts this grader grades the runs of; absent, every run. */
|
|
61
68
|
layouts?: Layout[];
|
|
@@ -129,6 +136,9 @@ export type EvalCase = {
|
|
|
129
136
|
/** The case's fake feed (eval-feed.ts): each run gets fake feeds served from it, read in place of the URLs the
|
|
130
137
|
* package's feed trigger names, and is started by that trigger as it would be. */
|
|
131
138
|
feed?: FeedFixture;
|
|
139
|
+
/** The case's previous runs (eval-previous.ts): each run's agent gets them seeded as completed runs of the package's
|
|
140
|
+
* schedule trigger, which then starts the run as it would, handing it the last one's result. */
|
|
141
|
+
previous?: PreviousFixture;
|
|
132
142
|
};
|
|
133
143
|
/** Cases that do not check: every problem, each naming its file. */
|
|
134
144
|
export declare class CaseError extends Error {
|
|
@@ -168,6 +178,8 @@ export type RunRecord = {
|
|
|
168
178
|
now?: string;
|
|
169
179
|
/** Its fake mailbox after it, for a case with `email` (eval-mailbox.ts). */
|
|
170
180
|
mailbox?: MailboxRecord;
|
|
181
|
+
/** What it was handed of its trigger's last result after its message, for a case with `previous` (eval-previous.ts). */
|
|
182
|
+
handed?: PreviousHandover;
|
|
171
183
|
};
|
|
172
184
|
export type Verdict = {
|
|
173
185
|
pass: boolean;
|
|
@@ -299,7 +311,8 @@ export type RunMetrics = {
|
|
|
299
311
|
};
|
|
300
312
|
/** `answer`, `calls`, `mcp_calls`, `created_at`, `ended_at` and `metrics`: what the run left, kept in the report so a caller scores the
|
|
301
313
|
* run itself after the eval's temp server is gone (a hill climb's parser and judge, say). An email case's run carries
|
|
302
|
-
* its fake mailbox's `layout` and what it left there (`mailbox_after`)
|
|
314
|
+
* its fake mailbox's `layout` and what it left there (`mailbox_after`); a previous case's run, what it was handed of its
|
|
315
|
+
* trigger's last result (`handed_previous`). */
|
|
303
316
|
export type RunResult = {
|
|
304
317
|
run: number;
|
|
305
318
|
agent_id: string | null;
|
|
@@ -317,6 +330,7 @@ export type RunResult = {
|
|
|
317
330
|
metrics?: RunMetrics | null;
|
|
318
331
|
layout?: Layout;
|
|
319
332
|
mailbox_after?: MailboxAfter;
|
|
333
|
+
handed_previous?: PreviousHandover;
|
|
320
334
|
};
|
|
321
335
|
export type CaseResult = {
|
|
322
336
|
name: string;
|