@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39
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 +418 -0
- package/README.md +325 -124
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +9 -2
- package/dist/learn/compile.js +52 -16
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +106 -51
- package/dist/learn/promote.js +82 -189
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +26 -8
- package/dist/learning-cost.js +17 -7
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +33 -2
- package/dist/local-models.js +43 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +394 -85
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +7 -2
- package/dist/port-models.js +5 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/run-launch.d.ts +10 -1
- package/dist/run-launch.js +11 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +42 -35
- package/dist/run-view.js +79 -44
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +42 -11
- package/dist/runner/adapter-loop.js +651 -247
- package/dist/runner/adapter-run-spec.d.ts +37 -12
- package/dist/runner/adapter-run-spec.js +139 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +94 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +37 -13
- package/dist/runner/journal-kinds.js +9 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +12 -3
- package/dist/runner/model-route.js +139 -18
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +74 -8
- package/dist/runner/promotion.js +365 -124
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +554 -130
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.js +3 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +133 -18
- package/dist/store/store.d.ts +52 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +85 -5
- package/dist/store-reads/learning.js +45 -17
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +70 -20
- package/dist/templates.js +191 -34
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +42 -42
- package/dist/tool-gate.js +97 -91
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +44 -16
- package/dist/tools.js +28 -28
- package/dist/trigger-adapter.d.ts +85 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +228 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +94 -9
- package/dist/triggers.js +263 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
package/dist/learning-cost.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export type CostRun = {
|
|
|
40
40
|
* that served it. Null for a run that does not learn. */
|
|
41
41
|
learned_revision: string | null;
|
|
42
42
|
cost_usd: number | null;
|
|
43
|
+
/** 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. */
|
|
44
|
+
cost_upper_bound: boolean;
|
|
43
45
|
learning_usd: number | null;
|
|
44
46
|
total_usd: number | null;
|
|
45
47
|
};
|
|
@@ -51,13 +53,24 @@ export declare const COST_WINDOW = 10;
|
|
|
51
53
|
/** The latest runs the route answers by default, and at most. */
|
|
52
54
|
export declare const COST_RUNS_DEFAULT = 1000;
|
|
53
55
|
export declare const COST_RUNS_MAX = 10000;
|
|
56
|
+
/** The serving promotion's replay (store-reads/learning.ts servingReplayOf): on `n` inputs, the workflow's accuracy and the
|
|
57
|
+
* agent's in percent to a tenth, and whether it `cleared` the bar promotion reads (learn/promote.ts withinBar). */
|
|
58
|
+
export type CostReplay = {
|
|
59
|
+
n: number;
|
|
60
|
+
workflow_pct: number;
|
|
61
|
+
agent_pct: number;
|
|
62
|
+
cleared: boolean;
|
|
63
|
+
};
|
|
54
64
|
/** What the series shows: `takeover`, its first `workflow` run, null before one; `before`, the mean of the job's own $
|
|
55
|
-
* (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known
|
|
56
|
-
* `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known;
|
|
57
|
-
* `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more
|
|
58
|
-
* before side leaves learning out and the after side keeps it in, so
|
|
59
|
-
*
|
|
60
|
-
*
|
|
65
|
+
* (learning left out) over its `agent` runs before the takeover (every one when there is none yet), whose cost is known
|
|
66
|
+
* exactly; `after`, the mean all-in $ (learning included) of every run from the takeover on whose total is known exactly;
|
|
67
|
+
* and `times_cheaper`, before over after to a tenth, once `after` counts CHEAPER_AFTER_RUNS runs or more and every run
|
|
68
|
+
* either side reads is known exactly, else null. The before side leaves learning out and the after side keeps it in, so
|
|
69
|
+
* the figure never flatters learning. `withheld`: after a takeover, how many runs either side reads have an unknown cost
|
|
70
|
+
* and how many one known only as at most (`cost_upper_bound`); while any does there is no ratio, null when none does.
|
|
71
|
+
* `hand_backs`: of the runs a learned workflow ran first on from the takeover on (`workflow` or `handed_back`), how many
|
|
72
|
+
* handed back; null before a takeover. `replay`: the serving promotion's, as given. Every one is over every run, never
|
|
73
|
+
* only the latest a read lists. */
|
|
61
74
|
export type CostSummary = {
|
|
62
75
|
takeover: {
|
|
63
76
|
n: number;
|
|
@@ -76,12 +89,17 @@ export type CostSummary = {
|
|
|
76
89
|
ran: number;
|
|
77
90
|
back: number;
|
|
78
91
|
} | null;
|
|
92
|
+
withheld: {
|
|
93
|
+
unknown: number;
|
|
94
|
+
at_most: number;
|
|
95
|
+
} | null;
|
|
96
|
+
replay: CostReplay | null;
|
|
79
97
|
};
|
|
80
|
-
export declare function costSummary(runs: readonly CostRun[]): CostSummary;
|
|
98
|
+
export declare function costSummary(runs: readonly CostRun[], replay?: CostReplay | null): CostSummary;
|
|
81
99
|
/** 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
|
|
82
100
|
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
83
101
|
* it opens as the text it is. */
|
|
84
|
-
export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
|
|
102
|
+
export declare const COST_CSV_COLUMNS: readonly ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "cost_upper_bound", "learning_usd", "total_usd"];
|
|
85
103
|
export declare function costCsv(runs: readonly CostRun[]): string;
|
|
86
104
|
/** GET /agents/{id}/learning/cost's query: `limit`, an integer from 1 to COST_RUNS_MAX (COST_RUNS_DEFAULT when absent),
|
|
87
105
|
* and `format`, `json` (the default) or `csv`. Anything else is 400. */
|
package/dist/learning-cost.js
CHANGED
|
@@ -41,20 +41,30 @@ export const COST_WINDOW = 10;
|
|
|
41
41
|
/** The latest runs the route answers by default, and at most. */
|
|
42
42
|
export const COST_RUNS_DEFAULT = 1000;
|
|
43
43
|
export const COST_RUNS_MAX = 10_000;
|
|
44
|
-
export function costSummary(runs) {
|
|
44
|
+
export function costSummary(runs, replay = null) {
|
|
45
45
|
const first = runs.findIndex((run) => run.path === "workflow");
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
46
|
+
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 }));
|
|
47
|
+
const afterSide = first < 0 ? [] : runs.slice(first).map((run) => ({ value: run.total_usd, bound: run.cost_upper_bound }));
|
|
48
|
+
const mean = (side) => {
|
|
49
|
+
const values = side.flatMap(({ value, bound }) => (value === null || bound ? [] : [value]));
|
|
50
|
+
return values.length ? { runs: values.length, mean_usd: usd(values.reduce((a, b) => a + b, 0) / values.length) } : null;
|
|
51
|
+
};
|
|
52
|
+
const before = mean(beforeSide);
|
|
53
|
+
const after = first < 0 ? null : mean(afterSide);
|
|
54
|
+
const read = [...beforeSide, ...afterSide];
|
|
55
|
+
// A bound is at most (the row stores its cost null); unknown is a null cost with no bound.
|
|
56
|
+
const unknown = read.filter(({ value, bound }) => value === null && !bound).length;
|
|
57
|
+
const atMost = read.filter(({ bound }) => bound).length;
|
|
58
|
+
const withheld = first >= 0 && unknown + atMost > 0 ? { unknown, at_most: atMost } : null;
|
|
59
|
+
const times = !withheld && before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
|
|
50
60
|
const ranFirst = first < 0 ? [] : runs.slice(first).filter((run) => run.path === "workflow" || run.path === "handed_back");
|
|
51
61
|
const handBacks = first < 0 ? null : { ran: ranFirst.length, back: ranFirst.filter((run) => run.path === "handed_back").length };
|
|
52
|
-
return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times, hand_backs: handBacks };
|
|
62
|
+
return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, times_cheaper: times, hand_backs: handBacks, withheld, replay };
|
|
53
63
|
}
|
|
54
64
|
/** 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
|
|
55
65
|
* a spreadsheet would read as a formula (one starting with =, +, -, @, a tab or a carriage return) starts with a `'`, so
|
|
56
66
|
* it opens as the text it is. */
|
|
57
|
-
export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "learning_usd", "total_usd"];
|
|
67
|
+
export const COST_CSV_COLUMNS = ["n", "run_id", "started_at", "path", "workflow", "learned_revision", "cost_usd", "cost_upper_bound", "learning_usd", "total_usd"];
|
|
58
68
|
export function costCsv(runs) {
|
|
59
69
|
const cell = (value) => {
|
|
60
70
|
const raw = value === null || value === undefined ? "" : String(value);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { DraftAsk } from "./learn/skills.js";
|
|
2
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
2
|
import type { DraftDecisions } from "./learn/skills.js";
|
|
4
3
|
import { type ItemStatus, type Learning, type NoteRuns, type Shown } from "./learning.js";
|
|
@@ -172,7 +171,6 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
172
171
|
tools: string[];
|
|
173
172
|
gated: Record<string, string>;
|
|
174
173
|
deniedBy?: Record<string, "agent" | "server" | "default">;
|
|
175
|
-
ask?: DraftAsk;
|
|
176
174
|
decisions?: DraftDecisions;
|
|
177
175
|
}>;
|
|
178
176
|
}): Promise<{
|
|
@@ -273,8 +271,8 @@ export declare function runLearningBody(input: {
|
|
|
273
271
|
skills?: import("./learning.js").LearnedFile[];
|
|
274
272
|
workflows?: import("./learning.js").LearnedFile[];
|
|
275
273
|
run: string;
|
|
276
|
-
state: "
|
|
277
|
-
reason: "cancelled" | "
|
|
274
|
+
state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
|
|
275
|
+
reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
278
276
|
detail: string | null;
|
|
279
277
|
at: string;
|
|
280
278
|
};
|
package/dist/learning-routes.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
// What a person sees and controls of an agent's learning: this server's own routes under /v2 (learning/1).
|
|
2
|
+
// - Per agent: main's index, its notes and its log of changes, each a page, its skills and workflow drafts, and how its
|
|
3
|
+
// runs' learning fared; one note, a skill's SKILL.md or a draft's file as text with its ETag, its blob id on main.
|
|
4
|
+
// - A person's approval of a note, a skill or a draft that waits for the owner's OK, and their edit, create or retire of
|
|
5
|
+
// one note (a skill or a draft is a run's to change): a precondition on the note's version (If-Match, or If-None-Match: * to
|
|
6
|
+
// create; neither is 428), the structural checks a run's notes pass (learn/check.ts checkNote; a retire, the note's
|
|
7
|
+
// format alone, so a leaking note can always be revoked) and no grader, then one commit on main by the learning
|
|
8
|
+
// script (learn/folder.ts writeLearning: one exec, compare and swap), with MEMORY.md rebuilt and a `Changed-By: user`
|
|
9
|
+
// trailer, the checked-out files brought in line and the snapshot written. MEMORY.md itself is never written here.
|
|
10
|
+
// - Per run: its learning whole, and its diff: what it proposed against its seed, or once merged, its merge commit against
|
|
11
|
+
// its parent, as its merge's script wrote it (`.agentrun/diffs/<run>.json`).
|
|
12
|
+
// Every read is the folder's snapshot (`.agentrun/snapshot.json`), the working-tree bodies it names, each checked against
|
|
13
|
+
// its blob id, and the diff files, through the folder's Workspace file API: no git and no exec (learn/folder.ts
|
|
14
|
+
// readLearning). A body that is not the snapshot's, twice, is a write in flight: 503. A page's cursor names the main it
|
|
15
|
+
// was read at; a later page is read at that main while this server still holds its snapshot, else as the first page of
|
|
16
|
+
// main now. A text that leaves holding one of the host's secrets as they are now (a value made secret after it was
|
|
17
|
+
// written) is cut of it, a file's name holding one reads "[redacted]" whole, and a diff's file holding one is withheld.
|
|
1
18
|
import { noteBytes } from "./learn/check.js";
|
|
2
19
|
import { createHash } from "node:crypto";
|
|
3
20
|
import { approve, buildIndex, CAPS, checkNote, draftProblems, frontKeys, INDEX_FILE, INDEX_LINES, isHeld, LEARNED_KEYS, learnedName, learnedPlace, learnedStatus, NOTE_FILE, NOTE_STATUSES, parseNoteFile, printable, released, retire, retiredLearned, skillProblems, SKILLS_DIR, supersede, UNCLEAR_FRONT, unstorable, WORKFLOWS_DIR, unclearFront, restorable, restore, restoredLearned } from "./learn/index.js";
|
|
@@ -460,9 +477,9 @@ export async function writeNote(data, agentId, raw, input) {
|
|
|
460
477
|
// a restore never brings back a draft no run could run.
|
|
461
478
|
const draft = changes.find(({ path }) => path === `${folder}workflow.json`);
|
|
462
479
|
if (learned.kind !== "skill" && draft && input.draftTools) {
|
|
463
|
-
const { tools, gated, deniedBy,
|
|
480
|
+
const { tools, gated, deniedBy, decisions } = await input.draftTools();
|
|
464
481
|
const dsl = await import("@parcha/agentrun-dsl");
|
|
465
|
-
for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated, deniedBy ?? {},
|
|
482
|
+
for (const { rule, detail } of draftProblems(dsl, draft.bytes.toString("utf8"), tools, gated, deniedBy ?? {}, decisions))
|
|
466
483
|
problems.push(printable({ rule, path: draft.path, detail }, input.refuse));
|
|
467
484
|
}
|
|
468
485
|
if (problems.length)
|
|
@@ -598,7 +615,7 @@ export async function promotable(data, agentId, raw, input) {
|
|
|
598
615
|
if (json && !problems.length) {
|
|
599
616
|
// A learned workflow's decision nodes (LS-07) are checked on this server's decision providers, as a restore checks them.
|
|
600
617
|
const { tools, gated, deniedBy, decisions } = await input.draftTools();
|
|
601
|
-
for (const { rule, detail } of draftProblems(dsl, json.text, tools, gated, deniedBy ?? {},
|
|
618
|
+
for (const { rule, detail } of draftProblems(dsl, json.text, tools, gated, deniedBy ?? {}, decisions))
|
|
602
619
|
problems.push(printable({ rule, path: file, detail }, input.refuse));
|
|
603
620
|
}
|
|
604
621
|
if (problems.length)
|
package/dist/learning-words.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare const STOPPED: {
|
|
|
29
29
|
};
|
|
30
30
|
/** A run's learning, in words, by where it stands. */
|
|
31
31
|
export declare const said: {
|
|
32
|
-
seeded: (notes: number) => string;
|
|
32
|
+
seeded: (notes: number, skills?: number, workflows?: number) => string;
|
|
33
33
|
reflecting: string;
|
|
34
34
|
/** The end-of-run turn's message, as a person reads it in the timeline: never the prompt the model is sent. */
|
|
35
35
|
asked: string;
|
package/dist/learning-words.js
CHANGED
|
@@ -95,7 +95,10 @@ export const STOPPED = {
|
|
|
95
95
|
};
|
|
96
96
|
/** A run's learning, in words, by where it stands. */
|
|
97
97
|
export const said = {
|
|
98
|
-
seeded: (notes
|
|
98
|
+
seeded: (notes, skills = 0, workflows = 0) => {
|
|
99
|
+
const items = [...(notes ? [count(notes, "note")] : []), ...(skills ? [count(skills, "skill")] : []), ...(workflows ? [count(workflows, "workflow")] : [])];
|
|
100
|
+
return items.length ? `Started from ${listed(items)}.` : "Started with nothing learned yet.";
|
|
101
|
+
},
|
|
99
102
|
reflecting: "Looking back on this run…",
|
|
100
103
|
/** The end-of-run turn's message, as a person reads it in the timeline: never the prompt the model is sent. */
|
|
101
104
|
asked: "Looking back on this run.",
|
package/dist/learning.d.ts
CHANGED
|
@@ -185,8 +185,8 @@ export declare const learningView: (learning: Learning, shown: Shown, settled: b
|
|
|
185
185
|
pending?: NoteUsed[];
|
|
186
186
|
skills?: LearnedFile[];
|
|
187
187
|
workflows?: LearnedFile[];
|
|
188
|
-
state: "
|
|
189
|
-
reason: "cancelled" | "
|
|
188
|
+
state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
|
|
189
|
+
reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
190
190
|
detail: string | null;
|
|
191
191
|
at: string;
|
|
192
192
|
};
|
|
@@ -200,10 +200,10 @@ export declare function shortOf<T extends {
|
|
|
200
200
|
detail: string | null;
|
|
201
201
|
at: string;
|
|
202
202
|
}>({ state, reason, detail, at: _, ...notes }: T): {
|
|
203
|
-
state: "
|
|
204
|
-
reason: "cancelled" | "
|
|
203
|
+
state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
|
|
204
|
+
reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
205
205
|
detail: string | null;
|
|
206
|
-
} & Omit<T, "at" | "reason" | "
|
|
206
|
+
} & Omit<T, "at" | "reason" | "detail" | "state">;
|
|
207
207
|
/** The label of the end-of-run turn's timeline rows, and the kind and label of a run's learning row. */
|
|
208
208
|
export declare const LEARNING_LABEL = "learning";
|
|
209
209
|
/** A run's proposal, in its directory (propose.ts): the seed it was checked against, each new note's file and text, its
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A call as a grader's list holds it (template-eval.ts ToolCall): its name, arguments and output's head. */
|
|
2
|
+
export type CheckedCall = {
|
|
3
|
+
tool: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
arguments?: unknown;
|
|
6
|
+
result?: string | null;
|
|
7
|
+
};
|
|
8
|
+
/** A URL's form for matching: scheme, host and path (no trailing slash), and its query values by key, each list sorted. */
|
|
9
|
+
export type CanonicalUrl = {
|
|
10
|
+
base: string;
|
|
11
|
+
query: Map<string, string[]>;
|
|
12
|
+
};
|
|
13
|
+
/** `url` canonical (see the head of this file), or undefined for one that is not an http(s) URL. */
|
|
14
|
+
export declare function canonicalUrl(url: string): CanonicalUrl | undefined;
|
|
15
|
+
/** Whether a cited link matches a url a call answered: the same base and key set, each value equal unless the call's
|
|
16
|
+
* values are all "…". */
|
|
17
|
+
export declare function urlMatches(cited: CanonicalUrl, called: CanonicalUrl): boolean;
|
|
18
|
+
/** Every http(s) URL an answer cites, in order, each once, as the forms it may end at (linksIn, jsonLinks): in its text,
|
|
19
|
+
* and in any string of its JSON (the whole answer, else its last json block), read from the parsed JSON so an escape in
|
|
20
|
+
* it never cuts a URL short. */
|
|
21
|
+
export declare function citedLinks(answer: string): string[][];
|
|
22
|
+
/** The link check's lines for a grader, or undefined when there is nothing to check: the run made no web_search or
|
|
23
|
+
* web_fetch call, and either the answer cites no link or no call returned a URL. One line per distinct link the answer
|
|
24
|
+
* cites, shown as a call's url is (scrubUrl: no query values, fragment or userinfo), saying the first call (numbered as
|
|
25
|
+
* the grader's list numbers them) one of whose urls it matches, or that none does, naming any fetched page whose links
|
|
26
|
+
* were cut, as that page could have held it. */
|
|
27
|
+
export declare function linkCheck(answer: string, calls: readonly CheckedCall[]): string | undefined;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// A template eval's link check (template-eval.ts graderInput): each http(s) link a run's answer cites, matched in code
|
|
2
|
+
// against every url its calls answered (its web calls', and the URLs any other call's result holds whole), so "every link
|
|
3
|
+
// the answer cites appears in the run's calls" is read from one block, never judged as URL equality from a rubric's prose. A link matches a url when their canonical forms do
|
|
4
|
+
// (canonicalUrl): no fragment, no trailing slash on the path, scheme and host lower-cased, no leading "www." on the host,
|
|
5
|
+
// query keys sorted; the two key
|
|
6
|
+
// sets equal, and each value equal, except that a call's value read as "…" (a timeline read elides query values,
|
|
7
|
+
// scrubUrls) matches any value for its key. Structural only: whether a cited item is in scope stays the rubric's call.
|
|
8
|
+
import { lastJsonBlock } from "./answer-json.js";
|
|
9
|
+
import { linksOf, linksWritten, TRAILING, trimmed, wholeUrl } from "./text-urls.js";
|
|
10
|
+
import { scrubUrl } from "./timeline/index.js";
|
|
11
|
+
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
12
|
+
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
|
13
|
+
const ELIDED = "…";
|
|
14
|
+
const isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
const strings = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === "string") : []);
|
|
16
|
+
/** `url` canonical (see the head of this file), or undefined for one that is not an http(s) URL. */
|
|
17
|
+
export function canonicalUrl(url) {
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = new URL(url.trim());
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:")
|
|
26
|
+
return undefined;
|
|
27
|
+
const query = new Map();
|
|
28
|
+
for (const [key, value] of parsed.searchParams)
|
|
29
|
+
query.set(key, [...(query.get(key) ?? []), value]);
|
|
30
|
+
for (const values of query.values())
|
|
31
|
+
values.sort();
|
|
32
|
+
// A host and the same host with "www." in front are one site (cpsc.gov, www.cpsc.gov); "www." is dropped only where a
|
|
33
|
+
// domain is left after it (never www.com's), and no other subdomain is (m., amp.).
|
|
34
|
+
const host = parsed.host.replace(/^www\.(?=[^.]+\.)/, "");
|
|
35
|
+
return { base: `${parsed.protocol}//${host}${parsed.pathname.replace(/\/+$/, "")}`, query };
|
|
36
|
+
}
|
|
37
|
+
/** Whether a cited link matches a url a call answered: the same base and key set, each value equal unless the call's
|
|
38
|
+
* values are all "…". */
|
|
39
|
+
export function urlMatches(cited, called) {
|
|
40
|
+
if (cited.base !== called.base || cited.query.size !== called.query.size)
|
|
41
|
+
return false;
|
|
42
|
+
for (const [key, values] of called.query) {
|
|
43
|
+
const mine = cited.query.get(key);
|
|
44
|
+
if (!mine)
|
|
45
|
+
return false;
|
|
46
|
+
if (values.every((value) => value === ELIDED))
|
|
47
|
+
continue;
|
|
48
|
+
if (mine.length !== values.length || mine.some((value, i) => value !== values[i]))
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
/** The forms a URL found in plain text may end at, longest first: as found, then less one trailing punctuation mark at a
|
|
54
|
+
* time. A URL can end in one (`/wiki/Yahoo!`), so which is the link is read from what matches, never guessed. */
|
|
55
|
+
function formsOf(raw) {
|
|
56
|
+
const forms = [raw];
|
|
57
|
+
for (let url = raw; url && TRAILING.includes(url.at(-1));)
|
|
58
|
+
forms.push((url = url.slice(0, -1)));
|
|
59
|
+
return forms;
|
|
60
|
+
}
|
|
61
|
+
/** Every http(s) URL in `text`, in order, read as a page's links are (linksWritten, text-urls.ts), each as the forms it may
|
|
62
|
+
* end at: a markdown link's target that its ")" closed as that one form; any other as formsOf gives it. A link's text
|
|
63
|
+
* and target read as two. */
|
|
64
|
+
function linksIn(text) {
|
|
65
|
+
return [...linksWritten(text)].flatMap(({ raw, exact }) => (/^https?:\/\//i.test(raw) ? [exact ? [raw] : formsOf(raw)] : []));
|
|
66
|
+
}
|
|
67
|
+
/** A JSON string's links: the string itself when it is one URL whole (wholeUrl: a field holding a link means all of it),
|
|
68
|
+
* else those in its text. */
|
|
69
|
+
const jsonLinks = (text) => {
|
|
70
|
+
const whole = wholeUrl(text);
|
|
71
|
+
return whole === undefined ? linksIn(text) : [[whole]];
|
|
72
|
+
};
|
|
73
|
+
/** Every string in `value`, property names aside. */
|
|
74
|
+
function stringsIn(value) {
|
|
75
|
+
if (typeof value === "string")
|
|
76
|
+
return [value];
|
|
77
|
+
if (Array.isArray(value))
|
|
78
|
+
return value.flatMap(stringsIn);
|
|
79
|
+
return isObj(value) ? Object.values(value).flatMap(stringsIn) : [];
|
|
80
|
+
}
|
|
81
|
+
/** Every http(s) URL an answer cites, in order, each once, as the forms it may end at (linksIn, jsonLinks): in its text,
|
|
82
|
+
* and in any string of its JSON (the whole answer, else its last json block), read from the parsed JSON so an escape in
|
|
83
|
+
* it never cuts a URL short. */
|
|
84
|
+
export function citedLinks(answer) {
|
|
85
|
+
let found;
|
|
86
|
+
try {
|
|
87
|
+
found = stringsIn(JSON.parse(answer)).flatMap(jsonLinks);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
const block = lastJsonBlock(answer);
|
|
91
|
+
let parsed;
|
|
92
|
+
try {
|
|
93
|
+
parsed = block === undefined ? undefined : JSON.parse(block);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
parsed = undefined;
|
|
97
|
+
}
|
|
98
|
+
found = parsed === undefined ? linksIn(answer) : [...linksIn(answer.replace(block, "")), ...stringsIn(parsed).flatMap(jsonLinks)];
|
|
99
|
+
}
|
|
100
|
+
return [...new Map(found.map((forms) => [forms.join("\n"), forms])).values()];
|
|
101
|
+
}
|
|
102
|
+
/** A call's urls for the check, and whether it is a web call: a web_search's results', a web_fetch's asked url, final url
|
|
103
|
+
* and page links, with how many of that page's links its output lost to a cut (`links_cut`). Any other call's are the
|
|
104
|
+
* URLs its result holds as it returned them (linksOf: a JSON string that is a URL whole counts whole). A grader reads
|
|
105
|
+
* only such a result's head (CALL_RESULT_CHARS, cut with "..." as timeline/util.ts cut ends it), so one ending in "..."
|
|
106
|
+
* may have held more past it: a cut of unknown count (1), named on a link that matches nothing, never a verdict. */
|
|
107
|
+
function sourceOf(call) {
|
|
108
|
+
const tool = call.name ?? call.tool;
|
|
109
|
+
const text = call.result ?? "";
|
|
110
|
+
if (tool !== WEB_SEARCH_TOOL && tool !== WEB_FETCH_TOOL)
|
|
111
|
+
return { urls: [...linksOf(text)], cut: text.endsWith("...") ? 1 : 0, web: false };
|
|
112
|
+
const end = text.indexOf("\n");
|
|
113
|
+
let read;
|
|
114
|
+
try {
|
|
115
|
+
read = JSON.parse(end < 0 ? text : text.slice(0, end));
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
read = undefined;
|
|
119
|
+
}
|
|
120
|
+
const out = isObj(read) ? read : {};
|
|
121
|
+
if (tool === WEB_SEARCH_TOOL)
|
|
122
|
+
return { urls: Array.isArray(out.results) ? out.results.flatMap((hit) => (isObj(hit) && typeof hit.url === "string" ? [hit.url] : [])) : [], cut: 0, web: true };
|
|
123
|
+
const asked = isObj(call.arguments) && typeof call.arguments.url === "string" ? [call.arguments.url] : [];
|
|
124
|
+
return { urls: [...asked, ...(typeof out.url === "string" ? [out.url] : []), ...strings(out.links)], cut: typeof out.links_cut === "number" ? out.links_cut : 0, web: true };
|
|
125
|
+
}
|
|
126
|
+
const callsWord = (calls) => (calls.length === 1 ? `call ${calls[0]}` : `calls ${calls.slice(0, -1).join(", ")} and ${calls.at(-1)}`);
|
|
127
|
+
/** The link check's lines for a grader, or undefined when there is nothing to check: the run made no web_search or
|
|
128
|
+
* web_fetch call, and either the answer cites no link or no call returned a URL. One line per distinct link the answer
|
|
129
|
+
* cites, shown as a call's url is (scrubUrl: no query values, fragment or userinfo), saying the first call (numbered as
|
|
130
|
+
* the grader's list numbers them) one of whose urls it matches, or that none does, naming any fetched page whose links
|
|
131
|
+
* were cut, as that page could have held it. */
|
|
132
|
+
export function linkCheck(answer, calls) {
|
|
133
|
+
const sources = calls.map(sourceOf);
|
|
134
|
+
const citations = citedLinks(answer);
|
|
135
|
+
if (!sources.some((source) => source.web) && !(citations.length && sources.some((source) => source.urls.length)))
|
|
136
|
+
return undefined;
|
|
137
|
+
const called = sources.map((source) => source.urls.flatMap((url) => canonicalUrl(url) ?? []));
|
|
138
|
+
const cut = sources.flatMap((source, i) => (source.cut ? [i + 1] : []));
|
|
139
|
+
const seen = new Set();
|
|
140
|
+
const lines = [];
|
|
141
|
+
const matchOf = (cited) => called.findIndex((urls) => urls.some((url) => urlMatches(cited, url)));
|
|
142
|
+
for (const forms of citations) {
|
|
143
|
+
// The longest form that matches a call is the link; with none, a plain-text one less the punctuation around it.
|
|
144
|
+
let [link, at] = [forms.length > 1 ? trimmed(forms[0]) : forms[0], -1];
|
|
145
|
+
for (const form of forms) {
|
|
146
|
+
const canonical = canonicalUrl(form);
|
|
147
|
+
const i = canonical ? matchOf(canonical) : -1;
|
|
148
|
+
if (i < 0)
|
|
149
|
+
continue;
|
|
150
|
+
[link, at] = [form, i];
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
const cited = canonicalUrl(link);
|
|
154
|
+
if (!cited)
|
|
155
|
+
continue;
|
|
156
|
+
const key = JSON.stringify([cited.base, [...cited.query].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))]);
|
|
157
|
+
if (seen.has(key))
|
|
158
|
+
continue;
|
|
159
|
+
seen.add(key);
|
|
160
|
+
lines.push(`${scrubUrl(link)} — ${at >= 0 ? `matches call ${at + 1}` : `no matching call${cut.length ? ` (${callsWord(cut)}'s links were cut)` : ""}`}`);
|
|
161
|
+
}
|
|
162
|
+
const intro = "Each distinct http(s) link the answer cites, checked in code against every url its calls answered (a web_search's results; a web_fetch's url, its final url and its page's links; any other call's URLs as its result holds them): a fragment, a trailing slash, a leading www. on the host and the order of the query are ignored, the query's keys must be the same, and a query value shown as … matches any value for its key. Links are shown with their query values elided.";
|
|
163
|
+
return [intro, ...(lines.length ? lines : ["(the answer cites no http(s) link)"])].join("\n");
|
|
164
|
+
}
|
package/dist/local-models.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Api, Model, MutableModels } from "@earendil-works/pi-ai";
|
|
2
|
+
import { type ModelPrice } from "@parcha/agentrun-kernel/kernel/cap";
|
|
2
3
|
/** Particle-1's price, USD per million tokens: Particle's own list price, from https://docs.particle.ai/models (read
|
|
3
4
|
* 2026-11-07: $0.25 input, $0.03 cached input, $1.00 output; no cache-write price, so $0). */
|
|
4
5
|
export declare const PARTICLE_1_PRICE: {
|
|
@@ -24,6 +25,36 @@ export declare const PRICE_OVERRIDES: readonly {
|
|
|
24
25
|
readonly cost: Model<Api>["cost"];
|
|
25
26
|
readonly toolsAs?: ToolsAs;
|
|
26
27
|
}[];
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
28
|
+
/** Models serve lists that pi-ai's catalog does not: OpenRouter's free variants of models that take tools, each a copy of
|
|
29
|
+
* `like` (a catalog entry on the same provider and wire: its api, base URL, compat and reasoning settings) under its own
|
|
30
|
+
* id, name, input, context window and output ceiling, at $0, taking its tools natively (the `like` entry's `toolsAs` is
|
|
31
|
+
* not copied). Context and output ceiling are OpenRouter's (GET https://openrouter.ai/api/v1/models, read 2026-11-15:
|
|
32
|
+
* context_length and top_provider.max_completion_tokens; pricing "0" prompt and completion). Each one answered a request
|
|
33
|
+
* that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. */
|
|
34
|
+
export declare const ADDED_MODELS: readonly {
|
|
35
|
+
readonly provider: string;
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly like: string;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly input: readonly ("text" | "image")[];
|
|
40
|
+
readonly contextWindow: number;
|
|
41
|
+
readonly maxTokens: number;
|
|
42
|
+
}[];
|
|
43
|
+
/** Whether `provider`/`id` is one of OpenRouter's routers, each of which picks a model per request (the kernel cap's
|
|
44
|
+
* ROUTERS, the one list). OpenRouter lists the price of `auto`, `openrouter/auto*`, `openrouter/fusion`,
|
|
45
|
+
* `openrouter/pareto-code` and `typesafe/jev-router` as -1, the routed model's (read 2026-11-15), which pi-ai's catalog
|
|
46
|
+
* writes as 0; `openrouter/free` routes to a different free model per request. Their zeros say no model's price, so
|
|
47
|
+
* none of them is free: a model serve has no price for, which a cap cannot be kept on and which is never booked at its
|
|
48
|
+
* catalog's $0 (model.ts runModels' `unpriced`). */
|
|
49
|
+
export declare const isRouter: (provider: string, id: string) => boolean;
|
|
50
|
+
/** Whether a catalog entry runs at $0: the kernel's freeModel (kernel/cap/free.ts, the one rule, what a run on it books
|
|
51
|
+
* at $0) on the entry's price, its tiers included. An entry with no cost has no price, so is not free. */
|
|
52
|
+
export declare function isFree(model: {
|
|
53
|
+
id: string;
|
|
54
|
+
api?: string;
|
|
55
|
+
cost?: ModelPrice | null;
|
|
56
|
+
}): boolean;
|
|
57
|
+
/** `models` (pi-ai's built-in catalog, or one built on it) with PRICE_OVERRIDES set on their providers' own entries and
|
|
58
|
+
* ADDED_MODELS listed beside them, in place: a request, a price and a capability read find the catalog's entry at the
|
|
59
|
+
* overridden price, with its toolsAs, and an added model as if the catalog listed it. */
|
|
29
60
|
export declare function withLocalModels<M extends MutableModels>(models: M): M;
|
package/dist/local-models.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { freeModel, ROUTERS } from "@parcha/agentrun-kernel/kernel/cap";
|
|
1
2
|
/** Particle-1's price, USD per million tokens: Particle's own list price, from https://docs.particle.ai/models (read
|
|
2
3
|
* 2026-11-07: $0.25 input, $0.03 cached input, $1.00 output; no cache-write price, so $0). */
|
|
3
4
|
export const PARTICLE_1_PRICE = { input: 0.25, output: 1, cacheRead: 0.03, cacheWrite: 0 };
|
|
@@ -22,17 +23,54 @@ const priced = (list, overrides) => list.map((model) => {
|
|
|
22
23
|
const override = overrides.find((entry) => entry.id === model.id);
|
|
23
24
|
return override ? { ...model, cost: { ...override.cost }, ...(override.toolsAs ? { toolsAs: override.toolsAs } : {}) } : model;
|
|
24
25
|
});
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const ZERO = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
27
|
+
/** Models serve lists that pi-ai's catalog does not: OpenRouter's free variants of models that take tools, each a copy of
|
|
28
|
+
* `like` (a catalog entry on the same provider and wire: its api, base URL, compat and reasoning settings) under its own
|
|
29
|
+
* id, name, input, context window and output ceiling, at $0, taking its tools natively (the `like` entry's `toolsAs` is
|
|
30
|
+
* not copied). Context and output ceiling are OpenRouter's (GET https://openrouter.ai/api/v1/models, read 2026-11-15:
|
|
31
|
+
* context_length and top_provider.max_completion_tokens; pricing "0" prompt and completion). Each one answered a request
|
|
32
|
+
* that defined a tool with a call to that tool, through OpenRouter, on 2026-11-15, billed $0. */
|
|
33
|
+
export const ADDED_MODELS = [
|
|
34
|
+
{ provider: "openrouter", id: "baidu/ernie-5.5-flash-preview:free", like: "inclusionai/ling-3.1-flash", name: "Baidu: ERNIE 5.5 Flash Preview (free)", input: ["text"], contextWindow: 1_024_000, maxTokens: 921_600 },
|
|
35
|
+
{ provider: "openrouter", id: "inclusionai/ling-3.2-flash:free", like: "inclusionai/ling-3.1-flash", name: "inclusionAI: Ling 3.2 Flash (free)", input: ["text"], contextWindow: 1_048_576, maxTokens: 262_144 },
|
|
36
|
+
];
|
|
37
|
+
/** `list` with ADDED_MODELS appended, each built on its `like` entry in `list` (one whose `like` the list lacks is left
|
|
38
|
+
* out) and never twice: once pi-ai lists an id itself, its own entry stands. */
|
|
39
|
+
const added = (list, adds) => [
|
|
40
|
+
...list,
|
|
41
|
+
...adds.flatMap(({ id, like, name, input, contextWindow, maxTokens }) => {
|
|
42
|
+
const base = list.find((model) => model.id === like);
|
|
43
|
+
if (!base || list.some((model) => model.id === id))
|
|
44
|
+
return [];
|
|
45
|
+
const { toolsAs: _base, ...rest } = base;
|
|
46
|
+
return [{ ...rest, id, name, input: [...input], contextWindow, maxTokens, cost: { ...ZERO } }];
|
|
47
|
+
}),
|
|
48
|
+
];
|
|
49
|
+
/** Whether `provider`/`id` is one of OpenRouter's routers, each of which picks a model per request (the kernel cap's
|
|
50
|
+
* ROUTERS, the one list). OpenRouter lists the price of `auto`, `openrouter/auto*`, `openrouter/fusion`,
|
|
51
|
+
* `openrouter/pareto-code` and `typesafe/jev-router` as -1, the routed model's (read 2026-11-15), which pi-ai's catalog
|
|
52
|
+
* writes as 0; `openrouter/free` routes to a different free model per request. Their zeros say no model's price, so
|
|
53
|
+
* none of them is free: a model serve has no price for, which a cap cannot be kept on and which is never booked at its
|
|
54
|
+
* catalog's $0 (model.ts runModels' `unpriced`). */
|
|
55
|
+
export const isRouter = (provider, id) => provider === "openrouter" && ROUTERS.has(id);
|
|
56
|
+
/** Whether a catalog entry runs at $0: the kernel's freeModel (kernel/cap/free.ts, the one rule, what a run on it books
|
|
57
|
+
* at $0) on the entry's price, its tiers included. An entry with no cost has no price, so is not free. */
|
|
58
|
+
export function isFree(model) {
|
|
59
|
+
return freeModel({ id: model.id, api: model.api ?? "", price: model.cost ?? null, outputCeiling: null });
|
|
60
|
+
}
|
|
61
|
+
/** `models` (pi-ai's built-in catalog, or one built on it) with PRICE_OVERRIDES set on their providers' own entries and
|
|
62
|
+
* ADDED_MODELS listed beside them, in place: a request, a price and a capability read find the catalog's entry at the
|
|
63
|
+
* overridden price, with its toolsAs, and an added model as if the catalog listed it. */
|
|
27
64
|
export function withLocalModels(models) {
|
|
28
|
-
for (const providerId of new Set(PRICE_OVERRIDES.map((entry) => entry.provider))) {
|
|
65
|
+
for (const providerId of new Set([...PRICE_OVERRIDES, ...ADDED_MODELS].map((entry) => entry.provider))) {
|
|
29
66
|
const own = models.getProvider(providerId);
|
|
30
67
|
if (!own)
|
|
31
68
|
continue;
|
|
32
69
|
const overrides = PRICE_OVERRIDES.filter((entry) => entry.provider === providerId);
|
|
70
|
+
const adds = ADDED_MODELS.filter((entry) => entry.provider === providerId);
|
|
33
71
|
const listed = Object.assign(Object.create(own), {
|
|
34
|
-
getModels: () => priced(own.getModels(), overrides),
|
|
35
|
-
...(own.getAllModels ? { getAllModels: () => priced(own.getAllModels(), overrides) } : {}),
|
|
72
|
+
getModels: () => added(priced(own.getModels(), overrides), adds),
|
|
73
|
+
...(own.getAllModels ? { getAllModels: () => added(priced(own.getAllModels(), overrides), adds) } : {}),
|
|
36
74
|
});
|
|
37
75
|
models.setProvider(listed);
|
|
38
76
|
}
|
package/dist/mcp-pin-first.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
// store was upgraded): two first runs, or a start and a claim, at once agree on one pin. Nothing moves from a run's old
|
|
7
7
|
// per-run pin (mcp_pins, dropped at the upgrade): the revision's pin is the one every run of it reads.
|
|
8
8
|
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { nativeOf } from "./native/binding.js";
|
|
10
|
+
import { sdkOf } from "./sdk/runs.js";
|
|
9
11
|
import { mcpPinOf } from "./mcp-gateway.js";
|
|
10
12
|
import { boundTool } from "./mcp-probe.js";
|
|
11
13
|
import { mcpServersOverStore } from "./mcp-servers-store.js";
|
|
@@ -18,6 +20,10 @@ import { GITHUB_UNUSABLE } from "./runner/mcp-github.js";
|
|
|
18
20
|
* pin of the other servers alone would stand for good, its missing tool never pinned), and the run is refused in the
|
|
19
21
|
* words it was (server.ts runnable at a start, the claim's own at a claim). */
|
|
20
22
|
export async function pinFirst(revision, deps) {
|
|
23
|
+
// Native source MCP names and SDK callback tools belong to their source, never this server's managed registry.
|
|
24
|
+
// Their runnable guards must refuse managed execution without listing or pinning those names first.
|
|
25
|
+
if (nativeOf(revision.body) || sdkOf(revision.body))
|
|
26
|
+
return undefined;
|
|
21
27
|
if (revision.mcpPin !== undefined && revision.mcpPin !== null)
|
|
22
28
|
return revision.mcpPin;
|
|
23
29
|
if (revision.kind !== "agentic")
|
|
@@ -65,4 +65,7 @@ registerSecretWrite("previewMcpServer", () => false);
|
|
|
65
65
|
// whatever the body (the listing sends the key too, and only the session may type one).
|
|
66
66
|
registerSecretWrite("listComposioTools", () => true);
|
|
67
67
|
registerSecretWrite("saveComposioServer", () => true);
|
|
68
|
+
// A Composio server's webhook subscription (composio-triggers.ts): a rotate seals its new secret, a delete drops it.
|
|
69
|
+
registerSecretWrite("rotateComposioSecret", () => true);
|
|
70
|
+
registerSecretWrite("deleteComposioSubscription", () => true);
|
|
68
71
|
registerNotSecretWrite("refreshMcpServer", "A refresh lists the saved server's tools again with its sealed credential, and writes no credential.");
|