@parcha/agentrun-serve 0.1.0-beta.44 → 0.1.0-beta.46
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 +148 -5
- package/README.md +385 -305
- package/dist/acp-package.d.ts +28 -0
- package/dist/acp-package.js +23 -0
- package/dist/adapter-facts.d.ts +8 -1
- package/dist/adapter-facts.js +9 -1
- package/dist/adapters.d.ts +5 -0
- package/dist/adapters.js +36 -3
- package/dist/agent-delete.d.ts +50 -0
- package/dist/agent-delete.js +125 -0
- package/dist/agents-store.d.ts +9 -3
- package/dist/agents-store.js +22 -8
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +8 -4
- package/dist/api-only.d.ts +8 -3
- package/dist/api-only.js +10 -4
- package/dist/archil-routes.d.ts +5 -1
- package/dist/archil-routes.js +57 -2
- package/dist/browser-wait-ended.d.ts +2 -0
- package/dist/browser-wait-ended.js +2 -0
- package/dist/calendar/ics-faux.d.ts +3 -1
- package/dist/calendar/ics-faux.js +12 -2
- package/dist/calendar/tools.js +5 -2
- package/dist/chatgpt-plan.js +3 -1
- package/dist/claude-login.d.ts +135 -0
- package/dist/claude-login.js +244 -0
- package/dist/cli.js +62 -19
- package/dist/composio-preset.js +69 -7
- package/dist/composio-triggers.d.ts +14 -0
- package/dist/composio-triggers.js +79 -15
- package/dist/computer-attach.d.ts +40 -5
- package/dist/computer-attach.js +130 -15
- package/dist/computer-keys.d.ts +3 -0
- package/dist/computer-keys.js +7 -1
- package/dist/computer-live.js +3 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-C2MYaUBa.css +1 -0
- package/dist/console/assets/index-CZZeCReB.js +701 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/dial-relay.d.ts +29 -0
- package/dist/dial-relay.js +94 -0
- package/dist/email/tools.js +10 -5
- package/dist/env-proxy.d.ts +2 -0
- package/dist/env-proxy.js +35 -0
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +7 -4
- package/dist/faux-computers.d.ts +8 -2
- package/dist/faux-computers.js +83 -6
- package/dist/harness-archive.d.ts +67 -0
- package/dist/harness-archive.js +177 -0
- package/dist/harness-goose.d.ts +34 -0
- package/dist/harness-goose.js +87 -0
- package/dist/harness-install.d.ts +21 -0
- package/dist/harness-install.js +24 -11
- package/dist/harness-opencode/adapter.js +1 -1
- package/dist/harness-table.d.ts +9 -1
- package/dist/harness-table.js +20 -3
- package/dist/harness.d.ts +1 -2
- package/dist/harness.js +3 -4
- package/dist/host.js +2 -1
- package/dist/import.d.ts +10 -0
- package/dist/import.js +28 -8
- package/dist/key-check.js +3 -0
- package/dist/learn/audit.d.ts +6 -6
- package/dist/learn/audit.js +3 -7
- package/dist/learn/check.d.ts +23 -89
- package/dist/learn/check.js +57 -335
- package/dist/learn/commit.d.ts +63 -90
- package/dist/learn/commit.js +124 -316
- package/dist/learn/compile.d.ts +53 -50
- package/dist/learn/compile.js +89 -104
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +5 -5
- package/dist/learn/delete.js +8 -10
- package/dist/learn/folder.d.ts +35 -47
- package/dist/learn/folder.js +118 -134
- package/dist/learn/index.d.ts +3 -5
- package/dist/learn/index.js +6 -9
- package/dist/learn/learning.sh +45 -15
- package/dist/learn/promote.d.ts +23 -5
- package/dist/learn/promote.js +40 -2
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +30 -38
- package/dist/learn/{skills.js → workflow-draft.js} +48 -58
- package/dist/learn/workflow-nodes.js +1 -1
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +38 -24
- package/dist/learning-cost.js +41 -24
- package/dist/learning-routes.d.ts +91 -170
- package/dist/learning-routes.js +183 -421
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +21 -10
- package/dist/learning-setting.js +47 -11
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +61 -392
- package/dist/learning.js +101 -651
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +1 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +4 -4
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +4 -0
- package/dist/model.js +26 -9
- package/dist/native/binding.js +1 -1
- package/dist/native/connection.js +1 -1
- package/dist/native/discovery.js +1 -1
- package/dist/native/instructions.d.ts +3 -0
- package/dist/native/instructions.js +5 -3
- package/dist/native/remote-worker-bridge.js +9 -43
- package/dist/native/remote.d.ts +8 -15
- package/dist/native/remote.js +3 -3
- package/dist/native/schema.js +1 -1
- package/dist/native/types.d.ts +2 -2
- package/dist/openapi.js +273 -319
- package/dist/paid-calls.d.ts +8 -0
- package/dist/paid-calls.js +20 -0
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +28 -11
- package/dist/print.d.ts +27 -0
- package/dist/print.js +21 -0
- package/dist/provider.d.ts +7 -0
- package/dist/provider.js +15 -1
- package/dist/reflect-range.js +2 -3
- package/dist/run-launch.d.ts +14 -28
- package/dist/run-launch.js +9 -12
- package/dist/run-learning-served.d.ts +15 -89
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.js +1 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-trace.d.ts +97 -0
- package/dist/run-trace.js +253 -0
- package/dist/run-view.d.ts +15 -0
- package/dist/run-view.js +9 -0
- package/dist/runnable.js +2 -1
- package/dist/runner/adapter-loop.d.ts +8 -6
- package/dist/runner/adapter-loop.js +16 -12
- package/dist/runner/adapter-run-spec.d.ts +16 -4
- package/dist/runner/adapter-run-spec.js +64 -58
- package/dist/runner/adapters/index.js +22 -0
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/audit.js +30 -13
- package/dist/runner/beside.d.ts +6 -2
- package/dist/runner/beside.js +38 -9
- package/dist/runner/claim-secrets.d.ts +18 -2
- package/dist/runner/claim-secrets.js +42 -18
- package/dist/runner/cli-run-spec.js +55 -51
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +35 -13
- package/dist/runner/conformance/subject.d.ts +6 -0
- package/dist/runner/dispatch.d.ts +2 -2
- package/dist/runner/end-of-run.d.ts +6 -14
- package/dist/runner/end-of-run.js +8 -33
- package/dist/runner/feedback-round.d.ts +2 -2
- package/dist/runner/feedback-round.js +7 -7
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +11 -59
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +2 -3
- package/dist/runner/journal-kinds.js +2 -3
- package/dist/runner/learned-first.d.ts +40 -0
- package/dist/runner/learned-first.js +32 -0
- package/dist/runner/learning-end.d.ts +77 -69
- package/dist/runner/learning-end.js +250 -303
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +2 -3
- package/dist/runner/main.d.ts +17 -9
- package/dist/runner/main.js +82 -20
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +10 -5
- package/dist/runner/memory-claim.js +12 -6
- package/dist/runner/model-route.d.ts +7 -4
- package/dist/runner/model-route.js +22 -10
- package/dist/runner/native-loop.d.ts +0 -7
- package/dist/runner/native-loop.js +9 -101
- package/dist/runner/promotion.d.ts +12 -8
- package/dist/runner/promotion.js +37 -28
- package/dist/runner/reflect-hook.d.ts +64 -95
- package/dist/runner/reflect-hook.js +112 -225
- package/dist/runner/run-channel.d.ts +43 -0
- package/dist/runner/run-channel.js +467 -0
- package/dist/runner/run-child-host.d.ts +169 -0
- package/dist/runner/run-child-host.js +1230 -0
- package/dist/runner/run-child.d.ts +1 -0
- package/dist/runner/run-child.js +254 -0
- package/dist/runner/run-errors.d.ts +2 -0
- package/dist/runner/run-errors.js +20 -0
- package/dist/runner/runner.js +1 -5
- package/dist/runner/sdk-ask.d.ts +78 -0
- package/dist/runner/sdk-ask.js +158 -0
- package/dist/runner/sdk-loop.d.ts +2 -4
- package/dist/runner/sdk-loop.js +29 -49
- package/dist/runner/store-secrets.d.ts +5 -3
- package/dist/runner/store-secrets.js +5 -1
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +7 -2
- package/dist/runs-over-store.d.ts +16 -28
- package/dist/runs-over-store.js +31 -38
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/seal-key.d.ts +5 -0
- package/dist/seal-key.js +7 -0
- package/dist/secrets.d.ts +3 -0
- package/dist/secrets.js +16 -3
- package/dist/server.d.ts +55 -33
- package/dist/server.js +689 -322
- package/dist/sign-ins-store.d.ts +8 -0
- package/dist/sign-ins-store.js +36 -1
- package/dist/skills.js +1 -1
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +3 -0
- package/dist/store/postgres/migrations/0017_run_listing.sql +83 -0
- package/dist/store/postgres/migrations/0018_trigger_template.sql +6 -0
- package/dist/store/postgres/migrations/0019_runner_relays.sql +28 -0
- package/dist/store/schema.d.ts +53 -4
- package/dist/store/schema.js +137 -6
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.js +246 -63
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +193 -36
- package/dist/store/store.js +25 -3
- package/dist/store-reads/learning.d.ts +102 -204
- package/dist/store-reads/learning.js +159 -321
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +29 -1
- package/dist/store-view.js +97 -31
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +8 -4
- package/dist/templates.js +44 -6
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +5 -1
- package/dist/timeline/timeline.js +16 -0
- package/dist/tool-gate.d.ts +0 -7
- package/dist/tool-gate.js +1 -15
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +6 -4
- package/dist/tool-keys.js +12 -6
- package/dist/tools.d.ts +2 -2
- package/dist/tools.js +11 -4
- package/dist/triggers.d.ts +65 -6
- package/dist/triggers.js +125 -19
- package/dist/validate.js +1 -1
- package/dist/webhooks.d.ts +7 -2
- package/dist/webhooks.js +12 -5
- package/dist/workspace/agent-computer.d.ts +2 -0
- package/dist/workspace/agent-computer.js +2 -0
- package/dist/workspace/archil-claim.d.ts +7 -0
- package/dist/workspace/archil-claim.js +29 -0
- package/dist/workspace/archil.d.ts +9 -1
- package/dist/workspace/archil.js +165 -3
- package/dist/workspace/attach.d.ts +3 -1
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/attached-computers.d.ts +16 -5
- package/dist/workspace/attached-computers.js +25 -9
- package/dist/workspace/computer-deps.js +1 -1
- package/dist/workspace/computer-for-claim.d.ts +7 -3
- package/dist/workspace/computer-for-claim.js +119 -22
- package/dist/workspace/computer-hold.js +2 -1
- package/dist/workspace/computer-kept.d.ts +11 -1
- package/dist/workspace/computer-kept.js +24 -3
- package/dist/workspace/resolve-computer.d.ts +33 -19
- package/dist/workspace/resolve-computer.js +172 -64
- package/dist/workspace/revision-skills.d.ts +1 -2
- package/dist/workspace/revision-skills.js +3 -4
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +5 -0
- package/dist/workspace/synced-folder.d.ts +85 -0
- package/dist/workspace/synced-folder.js +230 -0
- package/dist/workspace/workspace.d.ts +4 -0
- package/launcher/agentrun-serve +1 -1
- package/package.json +10 -10
- package/templates/README.md +8 -8
- package/templates/inbound-lead/agent.md +5 -4
- package/templates/inbound-lead/evals/learned-correction/case.yaml +3 -3
- package/templates/inbound-lead/evals/learned-correction/fixtures/corrections.md +1 -0
- package/templates/inbound-lead/evals/learned-correction/graders/applies-correction.md +22 -0
- package/templates/inbound-lead/evals/learned-correction/graders/learned-origin.md +1 -1
- package/templates/inbound-lead/evals/learned-correction/prompt.md +1 -1
- package/templates/inbound-lead/lead.schema.json +6 -5
- package/templates/inbound-lead/rules/RUBRIC.md +4 -4
- package/templates/inbound-lead/skills/lead/SKILL.md +4 -4
- package/templates/kyb/agent.md +2 -1
- package/templates/market-monitor/evals/learned-preference/case.yaml +4 -4
- package/templates/market-monitor/evals/learned-preference/fixtures/corrections.md +1 -0
- package/templates/market-monitor/evals/learned-preference/graders/omits-junior-post.md +3 -3
- package/templates/market-monitor/evals/learned-preference/prompt.md +1 -1
- package/templates/release-notes/evals/learned-style/case.yaml +4 -4
- package/templates/release-notes/evals/learned-style/fixtures/corrections.md +1 -0
- package/templates/release-notes/evals/learned-style/graders/same-changes.md +2 -2
- package/templates/release-notes/evals/learned-style/prompt.md +1 -1
- package/dist/console/assets/index-BUktRvS-.css +0 -1
- package/dist/console/assets/index-nB9kTfIN.js +0 -711
- package/dist/learn/grade.d.ts +0 -138
- package/dist/learn/grade.js +0 -682
- package/dist/learn/notes.d.ts +0 -81
- package/dist/learn/notes.js +0 -178
- package/dist/learn/reflect.d.ts +0 -77
- package/dist/learn/reflect.js +0 -228
- package/dist/learn/relevance.d.ts +0 -24
- package/dist/learn/relevance.js +0 -91
- package/dist/learn/seed-check.d.ts +0 -74
- package/dist/learn/seed-check.js +0 -103
- package/dist/learning-batch.d.ts +0 -291
- package/dist/learning-batch.js +0 -600
- package/dist/learning-evals.d.ts +0 -35
- package/dist/learning-evals.js +0 -99
- package/dist/native/context.d.ts +0 -6
- package/dist/native/context.js +0 -22
- package/dist/propose.d.ts +0 -52
- package/dist/propose.js +0 -224
- package/dist/runner/learning-ask.d.ts +0 -47
- package/dist/runner/learning-ask.js +0 -128
- package/dist/runner/learning-dispatch.d.ts +0 -45
- package/dist/runner/learning-dispatch.js +0 -99
- package/dist/runner/learning-factory.d.ts +0 -16
- package/dist/runner/learning-factory.js +0 -50
- package/dist/runner/learning-loop.d.ts +0 -273
- package/dist/runner/learning-loop.js +0 -521
- package/dist/usage.d.ts +0 -11
- package/dist/usage.js +0 -11
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/MEMORY.md +0 -1
- package/templates/inbound-lead/evals/learned-correction/fixtures/learning/no-agencies.md +0 -14
- package/templates/inbound-lead/evals/learned-correction/graders/applies-note.md +0 -21
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/MEMORY.md +0 -1
- package/templates/market-monitor/evals/learned-preference/fixtures/learning/skip-junior-job-posts.md +0 -8
- package/templates/release-notes/evals/learned-style/fixtures/learning/MEMORY.md +0 -1
- package/templates/release-notes/evals/learned-style/fixtures/learning/say-agent-not-bot.md +0 -13
package/dist/learning-cost.d.ts
CHANGED
|
@@ -21,30 +21,36 @@ export type CostLooked = {
|
|
|
21
21
|
* the run's cost here would read other than its usage row (A8). `+ 0` makes a noise-sized negative a plain 0, never -0. */
|
|
22
22
|
export declare const noiseOff: (value: number) => number;
|
|
23
23
|
/** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
|
|
24
|
-
* person asked of it after)
|
|
25
|
-
* grade spent (`gradeUsd`: its learning run's cost once that run ended, stopped or failed, 0 while it runs or when there
|
|
26
|
-
* is none, null when unknown):
|
|
24
|
+
* person asked of it after) and what it kept as it answered (`looked`, none for a run that did not look back):
|
|
27
25
|
* - `cost_usd`: the job's own $: its row's cost less its look-back, never under what it had cost when it answered (a
|
|
28
26
|
* later turn's spend is the job's too); its row's cost for a run that did not look back;
|
|
29
|
-
* - `learning_usd`: what learning cost for it: its look-back
|
|
30
|
-
*
|
|
27
|
+
* - `learning_usd`: what learning cost for it: its look-back (its compile turn) and what was spent beside it
|
|
28
|
+
* (`besideUsd`: its audit's shadow run), 0 for a run that does not learn; null when unknown (a turn stopped mid-ask
|
|
29
|
+
* spent what no one knows, or a shadow still running);
|
|
31
30
|
* - `total_usd`: their sum, the run's all-in $; null when either is. */
|
|
32
|
-
export declare function runCostOf(rowUsd: number | null, looked: CostLooked | null,
|
|
31
|
+
export declare function runCostOf(rowUsd: number | null, looked: CostLooked | null, besideUsd?: number | null): {
|
|
33
32
|
cost_usd: number | null;
|
|
34
33
|
learning_usd: number | null;
|
|
35
34
|
total_usd: number | null;
|
|
36
35
|
};
|
|
37
|
-
/** One run of the series, in the order the agent's runs started: `n` its number among
|
|
36
|
+
/** One run of the series, in the order the agent's runs started: `n` its number among the runs that do a job (JOB_PATHS,
|
|
37
|
+
* 1 the first: the bill's numbering), null for a replay, which checks a revision and does no job. */
|
|
38
38
|
export type CostRun = {
|
|
39
|
-
n: number;
|
|
39
|
+
n: number | null;
|
|
40
40
|
run_id: string;
|
|
41
41
|
started_at: string;
|
|
42
42
|
path: RunPath;
|
|
43
43
|
/** The learned workflow its job called last, by name; null when it called none. */
|
|
44
44
|
workflow: string | null;
|
|
45
|
-
/** The
|
|
46
|
-
*
|
|
47
|
-
|
|
45
|
+
/** The revision of that workflow that ran it (its record's metrics.workflow_digest: the first 16 hex characters of its
|
|
46
|
+
* workflow.json's sha256); null when no learned workflow ran. One value while one revision serves. */
|
|
47
|
+
digest: string | null;
|
|
48
|
+
/** The first run its revision (`workflow` at `digest`) served, over every run of the series (tookOverOf): where that
|
|
49
|
+
* revision took over, its promotion's flag on the chart. The first of them is the summary's takeover (a workflow that
|
|
50
|
+
* ran first always names its revision); false for a replay and a run no revision ran (`digest` null). */
|
|
51
|
+
took_over: boolean;
|
|
52
|
+
/** An audit's shadow run was started for it (runner/audit.ts): its cost is in `learning_usd`. */
|
|
53
|
+
audited: boolean;
|
|
48
54
|
cost_usd: number | null;
|
|
49
55
|
/** Its stored cost is only a bound (the run row's `costAtMostUsd`: a request cut at its cap hold): `cost_usd` and `total_usd` are null, the bound is never shown as a cost. */
|
|
50
56
|
cost_upper_bound: boolean;
|
|
@@ -75,11 +81,17 @@ export type CostReplay = {
|
|
|
75
81
|
/** The paths a learned workflow served a run on: it ran first and answered alone (`workflow`) or handed back
|
|
76
82
|
* (`handed_back`). A `replay` checks a new revision on a graded input and serves no one; an `agent` run is by hand. */
|
|
77
83
|
export declare const SERVED_PATHS: readonly RunPath[];
|
|
84
|
+
/** Each run of the series (every run, oldest first, before a read's limit) with `took_over`: true on the first run a
|
|
85
|
+
* revision (`workflow` at `digest`) served (SERVED_PATHS), never on a replay or a run no revision ran. A promotion is
|
|
86
|
+
* written as a run is claimed, after the runs queued before it started, so where a revision took over is read from the
|
|
87
|
+
* runs it served, never from start times. */
|
|
88
|
+
export declare function tookOverOf(runs: readonly Omit<CostRun, "took_over">[]): CostRun[];
|
|
78
89
|
/** Why the after side has a figure or not: `priced`, it has; `no_served_runs`, no learned workflow has taken over (a
|
|
79
90
|
* replay is no served run); `cost_unknown`, runs were served but none's all-in cost is known exactly. */
|
|
80
91
|
export declare const AFTER_STATES: readonly ["priced", "no_served_runs", "cost_unknown"];
|
|
81
92
|
export type AfterState = (typeof AFTER_STATES)[number];
|
|
82
|
-
/** What the series shows: `takeover`,
|
|
93
|
+
/** What the series shows: `takeover`, the first run a learned workflow served (SERVED_PATHS: it answered alone or handed
|
|
94
|
+
* back; the bill's `promoted`), null before one; `before`, the mean of the job's own $
|
|
83
95
|
* (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known
|
|
84
96
|
* exactly; `after`, the mean all-in $ (learning included) of the runs a learned workflow served from the takeover on
|
|
85
97
|
* (SERVED_PATHS: never a replay, which checks a revision and serves no one, nor a run by hand) whose total is known
|
|
@@ -131,7 +143,7 @@ export type BillPoint = {
|
|
|
131
143
|
/** A revision's learning spend and what its served runs carry of it (amortize): `compile_usd` the compile turns that
|
|
132
144
|
* drafted it (a recompile's turn is its recompiled revision's), `check_usd` its check's replay runs, `spend_usd` the
|
|
133
145
|
* two (each null when a part's cost is unknown), `k` the served runs it is spread over (its check's compile_after),
|
|
134
|
-
* `served`
|
|
146
|
+
* `served` every run it served (its first `k` carry its spend), `attributed_usd` what they carry, `unattributed_usd` the rest, and `state`:
|
|
135
147
|
* `checking` (its check is at work), `serving` (it is the champion) or `stopped` (held or replaced: nothing more will
|
|
136
148
|
* carry it). */
|
|
137
149
|
export type RevisionSpend = {
|
|
@@ -165,8 +177,10 @@ export type BillHold = {
|
|
|
165
177
|
* the first run from `promoted` on after which `actual_usd` never again exceeds `agent_usd`, the booked total past the
|
|
166
178
|
* last point included (null: not yet, or nothing served), and `gap_usd` the booked total less the line at the last point
|
|
167
179
|
* while there is none; `withheld` the runs (a replay among them) whose cost is unknown or only a bound, on neither line;
|
|
168
|
-
* `booked_usd` every priced run's $, spend booked after the last point included
|
|
169
|
-
*
|
|
180
|
+
* `booked_usd` every priced run's $, spend booked after the last point included, and `learning_usd` what of it learning
|
|
181
|
+
* booked: every priced job's learning (its compile turn and its audit's shadow run) and every priced replay. With the
|
|
182
|
+
* v2 split (amortize): `revisions`, `unattributed_usd` (the booked total less every run's all-in: what no run carries)
|
|
183
|
+
* and `holds`. */
|
|
170
184
|
export type Bill = {
|
|
171
185
|
baseline: {
|
|
172
186
|
runs: number;
|
|
@@ -185,18 +199,18 @@ export type Bill = {
|
|
|
185
199
|
gap_usd: number | null;
|
|
186
200
|
withheld: number;
|
|
187
201
|
booked_usd: number;
|
|
202
|
+
learning_usd: number;
|
|
188
203
|
revisions: RevisionShare[];
|
|
189
204
|
unattributed_usd: number | null;
|
|
190
205
|
holds: BillHold[];
|
|
191
206
|
};
|
|
192
|
-
/** The bill over `runs` (the cost series, oldest first, replays among them)
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
|
|
199
|
-
export declare function billOf(runs: readonly CostRun[], promotedAt: string | null): Omit<Bill, "revisions" | "unattributed_usd" | "holds">;
|
|
207
|
+
/** The bill over `runs` (the cost series, oldest first, replays among them): each run that does a job, all in (its own
|
|
208
|
+
* $, its compile turn and its audit shadow), with each replay's $ joining the run that does a job it followed (the first
|
|
209
|
+
* one when none did), cumulative; against the baseline times the runs shown so far. Spend booked with no point to join
|
|
210
|
+
* (a replay after a job of unknown cost) is carried to the next point, and with none after it is still booked: in the
|
|
211
|
+
* gap, and no break-even while it puts the bill over the line. Every sum and difference has its float noise rounded off
|
|
212
|
+
* (noiseOff), so a tie reads as a tie and a decision's sub-micro-dollar cost is booked as the usage row books it. */
|
|
213
|
+
export declare function billOf(runs: readonly CostRun[]): Omit<Bill, "revisions" | "unattributed_usd" | "holds">;
|
|
200
214
|
/** Each revision's spend split over its first `k` served runs (`served`: the runs a learned workflow served, oldest
|
|
201
215
|
* first, with the workflow and digest that served each: a revision is both, as two workflows of the same text share a
|
|
202
216
|
* digest), in whole micro-dollars: each carries spend/k, the first ones a micro-dollar more, and the k-th the
|
|
@@ -215,7 +229,7 @@ export declare function amortize(revisions: readonly RevisionSpend[], served: re
|
|
|
215
229
|
/** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
|
|
216
230
|
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
217
231
|
* it opens as the text it is. */
|
|
218
|
-
export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "
|
|
232
|
+
export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "digest", "audited", "cost_usd", "cost_upper_bound", "learning_usd", "total_usd"];
|
|
219
233
|
export declare function costCsv(runs: readonly CostRun[]): string;
|
|
220
234
|
/** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
|
|
221
235
|
* and `format`, `json` (the default) or `csv`. Anything else is 400. */
|
package/dist/learning-cost.js
CHANGED
|
@@ -22,22 +22,21 @@ const usd = (value) => Math.round(value * 1e6) / 1e6;
|
|
|
22
22
|
* the run's cost here would read other than its usage row (A8). `+ 0` makes a noise-sized negative a plain 0, never -0. */
|
|
23
23
|
export const noiseOff = (value) => Math.round(value * 1e12) / 1e12 + 0;
|
|
24
24
|
/** A run's own cost and what learning added for it, from its row's cost (`rowUsd`: the job, its look-back and any turn a
|
|
25
|
-
* person asked of it after)
|
|
26
|
-
* grade spent (`gradeUsd`: its learning run's cost once that run ended, stopped or failed, 0 while it runs or when there
|
|
27
|
-
* is none, null when unknown):
|
|
25
|
+
* person asked of it after) and what it kept as it answered (`looked`, none for a run that did not look back):
|
|
28
26
|
* - `cost_usd`: the job's own $: its row's cost less its look-back, never under what it had cost when it answered (a
|
|
29
27
|
* later turn's spend is the job's too); its row's cost for a run that did not look back;
|
|
30
|
-
* - `learning_usd`: what learning cost for it: its look-back
|
|
31
|
-
*
|
|
28
|
+
* - `learning_usd`: what learning cost for it: its look-back (its compile turn) and what was spent beside it
|
|
29
|
+
* (`besideUsd`: its audit's shadow run), 0 for a run that does not learn; null when unknown (a turn stopped mid-ask
|
|
30
|
+
* spent what no one knows, or a shadow still running);
|
|
32
31
|
* - `total_usd`: their sum, the run's all-in $; null when either is. */
|
|
33
|
-
export function runCostOf(rowUsd, looked,
|
|
32
|
+
export function runCostOf(rowUsd, looked, besideUsd = 0) {
|
|
34
33
|
const answered = looked?.answered_at !== undefined;
|
|
35
34
|
const asAnswered = answered ? (looked.job_cost_usd ?? null) : rowUsd;
|
|
36
35
|
const back = answered ? (looked.look_back_usd ?? null) : 0;
|
|
37
36
|
// What the row holds past the answer and its look-back is a later turn's spend, unknown once the row's cost is; with the
|
|
38
37
|
// look-back's cost unknown the two can't be told apart, and the job is what it had cost when it answered.
|
|
39
38
|
const job = !answered || asAnswered === null || back === null ? asAnswered : rowUsd === null ? null : Math.max(asAnswered, rowUsd - back);
|
|
40
|
-
const spent = back === null ||
|
|
39
|
+
const spent = back === null || besideUsd === null ? null : back + besideUsd;
|
|
41
40
|
return { cost_usd: job === null ? null : noiseOff(job), learning_usd: spent === null ? null : noiseOff(spent), total_usd: job === null || spent === null ? null : noiseOff(job + spent) };
|
|
42
41
|
}
|
|
43
42
|
/** The fewest runs after the takeover a "times cheaper" figure needs: fewer say too little. */
|
|
@@ -51,11 +50,25 @@ export const COST_RUNS_MAX = 10_000;
|
|
|
51
50
|
/** The paths a learned workflow served a run on: it ran first and answered alone (`workflow`) or handed back
|
|
52
51
|
* (`handed_back`). A `replay` checks a new revision on a graded input and serves no one; an `agent` run is by hand. */
|
|
53
52
|
export const SERVED_PATHS = ["workflow", "handed_back"];
|
|
53
|
+
/** Each run of the series (every run, oldest first, before a read's limit) with `took_over`: true on the first run a
|
|
54
|
+
* revision (`workflow` at `digest`) served (SERVED_PATHS), never on a replay or a run no revision ran. A promotion is
|
|
55
|
+
* written as a run is claimed, after the runs queued before it started, so where a revision took over is read from the
|
|
56
|
+
* runs it served, never from start times. */
|
|
57
|
+
export function tookOverOf(runs) {
|
|
58
|
+
const seen = new Set();
|
|
59
|
+
return runs.map((run) => {
|
|
60
|
+
const revision = run.digest !== null && SERVED_PATHS.includes(run.path) ? JSON.stringify([run.workflow, run.digest]) : null;
|
|
61
|
+
const first = revision !== null && !seen.has(revision);
|
|
62
|
+
if (revision !== null)
|
|
63
|
+
seen.add(revision);
|
|
64
|
+
return { ...run, took_over: first };
|
|
65
|
+
});
|
|
66
|
+
}
|
|
54
67
|
/** Why the after side has a figure or not: `priced`, it has; `no_served_runs`, no learned workflow has taken over (a
|
|
55
68
|
* replay is no served run); `cost_unknown`, runs were served but none's all-in cost is known exactly. */
|
|
56
69
|
export const AFTER_STATES = ["priced", "no_served_runs", "cost_unknown"];
|
|
57
70
|
export function costSummary(runs, replay = null) {
|
|
58
|
-
const first = runs.findIndex((run) => run.path
|
|
71
|
+
const first = runs.findIndex((run) => SERVED_PATHS.includes(run.path));
|
|
59
72
|
const beforeSide = (first < 0 ? runs : runs.slice(0, first)).filter((run) => run.path === "agent").map((run) => ({ value: run.cost_usd, bound: run.cost_upper_bound }));
|
|
60
73
|
// Served runs alone: a replay (a check of a new revision, at workflow cost) and a run by hand are never the after side.
|
|
61
74
|
const served = first < 0 ? [] : runs.slice(first).filter((run) => SERVED_PATHS.includes(run.path));
|
|
@@ -79,17 +92,19 @@ export function costSummary(runs, replay = null) {
|
|
|
79
92
|
/** The paths of the runs that do a job: the bill's run index counts these. A replay checks a revision and an audit's
|
|
80
93
|
* shadow audits a run: their spend is learning, booked where it falls (billOf) and carried by the runs they serve. */
|
|
81
94
|
export const JOB_PATHS = ["agent", "workflow", "handed_back"];
|
|
82
|
-
/** The bill over `runs` (the cost series, oldest first, replays among them)
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
export function billOf(runs, promotedAt) {
|
|
95
|
+
/** The bill over `runs` (the cost series, oldest first, replays among them): each run that does a job, all in (its own
|
|
96
|
+
* $, its compile turn and its audit shadow), with each replay's $ joining the run that does a job it followed (the first
|
|
97
|
+
* one when none did), cumulative; against the baseline times the runs shown so far. Spend booked with no point to join
|
|
98
|
+
* (a replay after a job of unknown cost) is carried to the next point, and with none after it is still booked: in the
|
|
99
|
+
* gap, and no break-even while it puts the bill over the line. Every sum and difference has its float noise rounded off
|
|
100
|
+
* (noiseOff), so a tie reads as a tie and a decision's sub-micro-dollar cost is booked as the usage row books it. */
|
|
101
|
+
export function billOf(runs) {
|
|
90
102
|
const jobs = runs.filter((run) => JOB_PATHS.includes(run.path));
|
|
91
103
|
const priced = (run) => run.total_usd !== null && !run.cost_upper_bound;
|
|
92
|
-
|
|
104
|
+
// The first run a learned workflow served (the summary's takeover): by its place in the series, never by a start time,
|
|
105
|
+
// which two runs queued together can share.
|
|
106
|
+
const first = jobs.findIndex((run) => SERVED_PATHS.includes(run.path));
|
|
107
|
+
const before = (first < 0 ? jobs : jobs.slice(0, first)).filter((run) => run.path === "agent" && run.cost_usd !== null && !run.cost_upper_bound);
|
|
93
108
|
const baseline = before.length ? { runs: before.length, mean_usd: usd(before.reduce((sum, run) => sum + run.cost_usd, 0) / before.length) } : null;
|
|
94
109
|
// Each replay's $ joins the job it followed; one before every job joins the first.
|
|
95
110
|
const extra = new Map();
|
|
@@ -133,8 +148,9 @@ export function billOf(runs, promotedAt) {
|
|
|
133
148
|
});
|
|
134
149
|
// Replays with no job at all to join (every job run archived, say) are booked all the same.
|
|
135
150
|
actual = noiseOff(early.reduce((sum, one) => sum + one, actual));
|
|
136
|
-
|
|
137
|
-
const
|
|
151
|
+
// Of it, learning's: the booked total less the priced jobs' own $ (each priced job's total is its own $ and its learning).
|
|
152
|
+
const learning = noiseOff(jobs.reduce((rest, run) => (priced(run) ? noiseOff(rest - run.cost_usd) : rest), actual));
|
|
153
|
+
const promoted = first < 0 ? null : { n: first + 1, run_id: jobs[first].run_id, at: jobs[first].started_at };
|
|
138
154
|
// The booked total against the line at the last point: spend after it (carried to no point) is in.
|
|
139
155
|
const tail = line === null ? Number.NaN : noiseOff(actual - noiseOff(line * shown));
|
|
140
156
|
let breakEven = null;
|
|
@@ -148,7 +164,7 @@ export function billOf(runs, promotedAt) {
|
|
|
148
164
|
}
|
|
149
165
|
}
|
|
150
166
|
const gap = !breakEven && line !== null && points.length ? tail : null;
|
|
151
|
-
return { baseline, promoted, points, break_even: breakEven, gap_usd: gap, withheld, booked_usd: actual };
|
|
167
|
+
return { baseline, promoted, points, break_even: breakEven, gap_usd: gap, withheld, booked_usd: actual, learning_usd: learning };
|
|
152
168
|
}
|
|
153
169
|
/** Each revision's spend split over its first `k` served runs (`served`: the runs a learned workflow served, oldest
|
|
154
170
|
* first, with the workflow and digest that served each: a revision is both, as two workflows of the same text share a
|
|
@@ -160,12 +176,13 @@ export function amortize(revisions, served) {
|
|
|
160
176
|
const shares = new Map();
|
|
161
177
|
let rest = 0;
|
|
162
178
|
const out = revisions.map((revision) => {
|
|
163
|
-
const
|
|
179
|
+
const all = served.filter((one) => one.workflow === revision.workflow && one.digest === revision.digest);
|
|
180
|
+
const runs = all.slice(0, revision.k);
|
|
164
181
|
if (revision.spend_usd === null) {
|
|
165
182
|
for (const run of runs)
|
|
166
183
|
shares.set(run.run_id, null);
|
|
167
184
|
rest = null;
|
|
168
|
-
return { ...revision, served:
|
|
185
|
+
return { ...revision, served: all.length, attributed_usd: null, unattributed_usd: null };
|
|
169
186
|
}
|
|
170
187
|
// Its whole micro-dollars (read off its pico-dollars, so float noise never drops one), split in integers; the rest
|
|
171
188
|
// under a micro-dollar is the k-th run's.
|
|
@@ -182,14 +199,14 @@ export function amortize(revisions, served) {
|
|
|
182
199
|
const left = noiseOff(revision.spend_usd - carried);
|
|
183
200
|
if (rest !== null)
|
|
184
201
|
rest = noiseOff(rest + left);
|
|
185
|
-
return { ...revision, served:
|
|
202
|
+
return { ...revision, served: all.length, attributed_usd: carried, unattributed_usd: left };
|
|
186
203
|
});
|
|
187
204
|
return { shares, revisions: out, unattributed_usd: rest };
|
|
188
205
|
}
|
|
189
206
|
/** The series as CSV (RFC 4180, a header line, `\r\n` line ends): one row a run, an unknown figure empty. A text cell that
|
|
190
207
|
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
191
208
|
* it opens as the text it is. */
|
|
192
|
-
export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "
|
|
209
|
+
export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "digest", "audited", "cost_usd", "cost_upper_bound", "learning_usd", "total_usd"];
|
|
193
210
|
export function costCsv(runs) {
|
|
194
211
|
const cell = (value) => {
|
|
195
212
|
const raw = value === null || value === undefined ? "" : String(value);
|