@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.45
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 +231 -0
- package/README.md +580 -320
- 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 +92 -22
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +81 -11
- package/dist/composio-triggers.d.ts +34 -2
- package/dist/composio-triggers.js +261 -31
- 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/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/computers.d.ts +21 -10
- package/dist/computers.js +39 -28
- package/dist/console/assets/index-3O2Yl6hZ.js +701 -0
- package/dist/console/assets/index-DaFsZuzQ.css +1 -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 +4 -1
- package/dist/errors.js +10 -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 +59 -3
- package/dist/harness-table.js +119 -14
- package/dist/harness.d.ts +17 -1
- package/dist/harness.js +22 -11
- package/dist/host.d.ts +12 -10
- package/dist/host.js +19 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- 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 +26 -89
- package/dist/learn/check.js +58 -336
- 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 +88 -103
- package/dist/learn/corrections.d.ts +13 -0
- package/dist/learn/corrections.js +23 -0
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +42 -0
- 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 +20 -2
- package/dist/learn/promote.js +17 -4
- package/dist/learn/{skills.d.ts → workflow-draft.d.ts} +34 -38
- package/dist/learn/{skills.js → workflow-draft.js} +65 -59
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +29 -10
- package/dist/learned-workflow.js +2 -2
- package/dist/learning-cost.d.ts +127 -13
- package/dist/learning-cost.js +142 -10
- package/dist/learning-routes.d.ts +99 -170
- package/dist/learning-routes.js +199 -420
- package/dist/learning-run.d.ts +19 -40
- package/dist/learning-run.js +23 -93
- package/dist/learning-setting.d.ts +4 -4
- package/dist/learning-setting.js +6 -6
- package/dist/learning-words.d.ts +28 -74
- package/dist/learning-words.js +64 -162
- package/dist/learning.d.ts +62 -393
- package/dist/learning.js +101 -651
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/live-reach.d.ts +25 -2
- package/dist/live-reach.js +46 -4
- package/dist/llms.txt +2 -1
- package/dist/local-models.d.ts +3 -11
- package/dist/local-models.js +5 -6
- package/dist/mcp-servers-store.d.ts +16 -16
- package/dist/model-form.js +6 -5
- package/dist/model.d.ts +12 -4
- package/dist/model.js +41 -16
- 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 +375 -347
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +14 -0
- package/dist/paid-calls.js +31 -1
- package/dist/particle-provider.d.ts +11 -0
- package/dist/particle-provider.js +135 -0
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- 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 +30 -2
- 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 +16 -90
- package/dist/run-listing.d.ts +34 -0
- package/dist/run-listing.js +128 -0
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- 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 +14 -6
- package/dist/runner/adapter-loop.js +25 -14
- package/dist/runner/adapter-run-spec.d.ts +22 -7
- package/dist/runner/adapter-run-spec.js +130 -77
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +35 -4
- package/dist/runner/adapters/pi.d.ts +4 -12
- package/dist/runner/adapters/pi.js +2 -2
- package/dist/runner/audit.d.ts +5 -1
- package/dist/runner/audit.js +31 -12
- package/dist/runner/beside.d.ts +7 -2
- package/dist/runner/beside.js +41 -9
- package/dist/runner/claim-secrets.d.ts +66 -1
- package/dist/runner/claim-secrets.js +136 -3
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +82 -59
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/conformance/harness.d.ts +6 -0
- package/dist/runner/conformance/harness.js +16 -5
- 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 +5 -4
- package/dist/runner/feedback-round.js +14 -10
- package/dist/runner/github-app.js +3 -1
- package/dist/runner/harness-loops.d.ts +0 -8
- package/dist/runner/harness-loops.js +30 -56
- package/dist/runner/held.d.ts +170 -0
- package/dist/runner/held.js +57 -0
- package/dist/runner/journal-kinds.d.ts +7 -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 -66
- package/dist/runner/learning-end.js +250 -299
- package/dist/runner/learning-seed.d.ts +15 -33
- package/dist/runner/learning-seed.js +24 -45
- package/dist/runner/loop-contract.d.ts +8 -3
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +18 -9
- package/dist/runner/main.js +82 -22
- package/dist/runner/mcp-run.d.ts +11 -0
- package/dist/runner/mcp-run.js +67 -0
- package/dist/runner/memory-claim.d.ts +14 -6
- package/dist/runner/memory-claim.js +18 -9
- 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 +13 -6
- package/dist/runner/promotion.js +63 -17
- package/dist/runner/reflect-hook.d.ts +64 -91
- package/dist/runner/reflect-hook.js +112 -206
- 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 +1222 -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 +58 -9
- 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 +14 -6
- package/dist/runner/workflow-first.d.ts +5 -0
- package/dist/runner/workflow-first.js +4 -0
- package/dist/runner/workflow-spec.js +17 -4
- package/dist/runs-over-store.d.ts +21 -32
- package/dist/runs-over-store.js +44 -41
- package/dist/sdk/runs.d.ts +6 -11
- package/dist/sdk/runs.js +20 -41
- package/dist/sdk/schema.js +3 -4
- package/dist/sdk/workflows.d.ts +1 -1
- 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 +119 -83
- package/dist/server.js +1121 -419
- 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 +3 -3
- package/dist/store/index.js +2 -2
- 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/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/connection.d.ts +2 -0
- package/dist/store/sqlite/connection.js +3 -1
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/run-patch.d.ts +0 -17
- package/dist/store/sqlite/run-patch.js +4 -33
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +360 -75
- package/dist/store/sqlite/worker.js +25 -0
- package/dist/store/store.d.ts +231 -39
- package/dist/store/store.js +25 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +131 -194
- package/dist/store-reads/learning.js +292 -301
- package/dist/store-reads/loop.d.ts +0 -1
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +34 -2
- package/dist/store-view.js +108 -41
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/template-eval.d.ts +3 -6
- package/dist/template-eval.js +22 -36
- package/dist/templates.d.ts +2 -1
- package/dist/templates.js +6 -3
- 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/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +13 -13
- package/dist/tools.js +29 -9
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +64 -5
- package/dist/triggers.js +141 -17
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +9 -8
- package/dist/webhooks.d.ts +4 -1
- package/dist/webhooks.js +11 -4
- 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 +22 -8
- package/dist/workspace/computer-for-claim.js +339 -46
- 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 +41 -21
- 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 -9
- package/templates/README.md +7 -7
- package/templates/inbound-lead/agent.md +3 -3
- 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/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-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.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 -33
- package/dist/learning-evals.js +0 -98
- 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/reflect-range.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LEARNING_LABEL } from "./learning.js";
|
|
2
2
|
import { said } from "./learning-words.js";
|
|
3
|
-
import { askedForDryRun } from "./learn/reflect.js";
|
|
4
3
|
import { askedForCompile } from "./learn/compile.js";
|
|
5
4
|
/** The run asked its end-of-run turn and has not ended since. */
|
|
6
5
|
export const reflecting = (run) => run.meta.reflect !== undefined && run.meta.reflect.until === undefined;
|
|
@@ -25,7 +24,7 @@ export function labelled(reflect, rows) {
|
|
|
25
24
|
return rows.map((row) => (!reflects(reflect, row.id) ? row : {
|
|
26
25
|
...row, agent_label: LEARNING_LABEL,
|
|
27
26
|
...(row.kind === "final_answer" ? { kind: "text_block" } : {}),
|
|
28
|
-
// The turn
|
|
29
|
-
...(row.kind === "user_message" ? ((words) => ({ summary: words, text: words }))(
|
|
27
|
+
// The compile turn's ask, or its ask again once the checks sent a draft back; any other message of the turn, its own.
|
|
28
|
+
...(row.kind === "user_message" ? ((words) => ({ summary: words, text: words }))(askedForCompile(row.text) === "again" ? said.askedCompileAgain : askedForCompile(row.text) ? said.askedCompile : said.asked) : {}),
|
|
30
29
|
}));
|
|
31
30
|
}
|
package/dist/run-launch.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ import { type Json } from "./validate.js";
|
|
|
7
7
|
import type { Place } from "./workspace/place.js";
|
|
8
8
|
/** What a run is launched with: everything its runner needs to build the run's spec at its claim, nothing derived later.
|
|
9
9
|
* The server writes it once at start; the runner reads it at each claim (its claim rebuilds the run from the store, this
|
|
10
|
-
* body included). `harness` picks the loop's adapter (
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* body included). `harness` picks the loop's adapter (absent, the revision's harness is used); `input` is the start
|
|
11
|
+
* request's body for a person's or a trigger's run, or an object a built-in run names. `model`, `plane`, `approvers`,
|
|
12
|
+
* `documents` and `boxAllow` are the per-run choices
|
|
13
13
|
* the old path recomputed; here they are pinned at start, and optional (a built-in run may name none). */
|
|
14
14
|
export interface RunLaunch {
|
|
15
15
|
readonly sdk?: {
|
|
@@ -27,7 +27,7 @@ export interface RunLaunch {
|
|
|
27
27
|
* repository (run-repo.ts); a github trigger's run has none here, its event names it. */
|
|
28
28
|
readonly repo?: string;
|
|
29
29
|
readonly place: Place;
|
|
30
|
-
/** The loop's adapter, when not the revision's
|
|
30
|
+
/** The loop's adapter, when not the revision's (an SDK run names "sdk"). */
|
|
31
31
|
readonly harness?: string;
|
|
32
32
|
/** The run's model, pinned at start. */
|
|
33
33
|
readonly model?: {
|
|
@@ -51,33 +51,19 @@ export interface RunLaunch {
|
|
|
51
51
|
* runner copies them into the run's work/inputs/ at its claim, as the old start copied them before the process ran. */
|
|
52
52
|
readonly files?: readonly string[];
|
|
53
53
|
/** The run's learning start, when its agent learns and the server's learning is on, decided once here so the runner reads
|
|
54
|
-
* no learning folder or git: `
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* workflows the seed offers its learned_workflow tool (chooseWorkflows), absent when none; `notesOnly`, a run of a
|
|
62
|
-
* revision that says `learning: "notes"`: given its notes and skills but never a learned workflow, and asked for no
|
|
63
|
-
* workflow draft at its end; `gradeModel`, the model the
|
|
64
|
-
* server names to grade what the run proposes (learning.ts gradeModelOf: --grade-model, else AGENTRUN_SERVE_GRADE_MODEL,
|
|
65
|
-
* else AGENT_MODEL_STRONG), absent when it names none and the agent's own grades it; and `seedFailed`, why it starts with
|
|
66
|
-
* nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts RUN_LEARNING_USE):
|
|
67
|
-
* it starts from all of the above and keeps nothing, never asked its end-of-run turn. Absent when the run does not learn. */
|
|
54
|
+
* no learning folder or git: `seed`, the learning commit's sha (or null when the seed could not be read); `section`,
|
|
55
|
+
* the exact # Learned text to lay into the prompt (its owner's corrections, learning.ts learnedSection); `workflows`,
|
|
56
|
+
* the names of the learned workflows the seed offers the run (chooseWorkflows), absent when none; `noWorkflows`, a run
|
|
57
|
+
* never answered by a learned workflow and asked for no workflow draft at its end (a native run, an SDK run with no
|
|
58
|
+
* workflow binding); `model`, the model an SDK run's compile turn is asked on (its agent's own); `seedFailed`, why it
|
|
59
|
+
* starts with nothing learned when it does (SeedFailed); `use`, a run started with `learning: "use"` (learning.ts
|
|
60
|
+
* RUN_LEARNING_USE): it starts from all of the above and keeps nothing. Absent when the run does not learn. */
|
|
68
61
|
readonly learning?: {
|
|
69
|
-
readonly given: readonly {
|
|
70
|
-
readonly file: string;
|
|
71
|
-
readonly name: string;
|
|
72
|
-
}[];
|
|
73
62
|
readonly seed: string | null;
|
|
74
63
|
readonly section: string;
|
|
75
|
-
readonly seedNotes?: number;
|
|
76
|
-
readonly notesLeftOut?: readonly string[];
|
|
77
|
-
readonly skills?: readonly string[];
|
|
78
64
|
readonly workflows?: readonly string[];
|
|
79
|
-
readonly
|
|
80
|
-
readonly
|
|
65
|
+
readonly noWorkflows?: true;
|
|
66
|
+
readonly model?: string;
|
|
81
67
|
readonly seedFailed?: SeedFailed;
|
|
82
68
|
readonly use?: true;
|
|
83
69
|
};
|
|
@@ -129,7 +115,7 @@ export declare function launchBody(launch: RunLaunch): Json;
|
|
|
129
115
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
130
116
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
131
117
|
export declare function readLaunchBody(stored: unknown): RunLaunch | undefined;
|
|
132
|
-
/** The run's learning start (its
|
|
118
|
+
/** The run's learning start (its seed sha, its # Learned section and its learned workflows), read from one place by learning's
|
|
133
119
|
* routes and the runner; undefined when the run does not learn. */
|
|
134
120
|
export declare const learningStartOf: (launch: RunLaunch) => RunLaunch["learning"];
|
|
135
121
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
package/dist/run-launch.js
CHANGED
|
@@ -67,7 +67,7 @@ export function launchBody(launch) {
|
|
|
67
67
|
...(launch.boxAllow !== undefined ? { box_allow: launch.boxAllow } : {}),
|
|
68
68
|
...(launch.boxAllowSet ? { box_allow_set: true } : {}),
|
|
69
69
|
...(launch.files?.length ? { files: launch.files } : {}),
|
|
70
|
-
...(launch.learning ? { learning: {
|
|
70
|
+
...(launch.learning ? { learning: { seed: launch.learning.seed, section: launch.learning.section, ...(launch.learning.workflows?.length ? { workflows: [...launch.learning.workflows] } : {}), ...(launch.learning.noWorkflows ? { noWorkflows: true } : {}), ...(launch.learning.model ? { model: launch.learning.model } : {}), ...(launch.learning.seedFailed ? { seedFailed: launch.learning.seedFailed } : {}), ...(launch.learning.use ? { use: true } : {}) } } : {}),
|
|
71
71
|
...(launch.workflowFirst === false ? { workflow_first: false } : {}),
|
|
72
72
|
...(launch.replay ? { replay: { of: launch.replay.of, workflow: launch.replay.workflow, digest: launch.replay.digest } } : {}),
|
|
73
73
|
...(launch.audit ? { audit: { of: launch.audit.of, workflow: launch.audit.workflow, digest: launch.audit.digest } } : {}),
|
|
@@ -78,19 +78,16 @@ export function launchBody(launch) {
|
|
|
78
78
|
...(launch.hold ? { hold: { minutes: launch.hold.minutes } } : {}),
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
-
/** The learning start a launch body names, as read back: its
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* when the body names none (a run that does not learn). */
|
|
81
|
+
/** The learning start a launch body names, as read back: its seed sha, its # Learned section text, the learned workflows
|
|
82
|
+
* it was offered, its compile model, why its seed failed and whether it only uses them (`use`), or undefined when the
|
|
83
|
+
* body names none (a run that does not learn). */
|
|
85
84
|
function readLearning(value) {
|
|
86
85
|
if (!isObject(value))
|
|
87
86
|
return undefined;
|
|
88
|
-
const given = Array.isArray(value.given) ? value.given.flatMap((note) => (isObject(note) && typeof note.file === "string" && typeof note.name === "string" ? [{ file: note.file, name: note.name }] : [])) : [];
|
|
89
87
|
const seed = typeof value.seed === "string" ? value.seed : null;
|
|
90
88
|
const section = typeof value.section === "string" ? value.section : "";
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
return { given, seed, section, ...(typeof value.seedNotes === "number" ? { seedNotes: value.seedNotes } : {}), ...(notesLeftOut.length ? { notesLeftOut } : {}), ...(skills.length ? { skills } : {}), ...(workflows.length ? { workflows } : {}), ...(value.notesOnly === true ? { notesOnly: true } : {}), ...(typeof value.gradeModel === "string" && value.gradeModel !== "" ? { gradeModel: value.gradeModel } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
|
|
89
|
+
const workflows = Array.isArray(value.workflows) ? value.workflows.filter((name) => typeof name === "string") : [];
|
|
90
|
+
return { seed, section, ...(workflows.length ? { workflows } : {}), ...(value.noWorkflows === true ? { noWorkflows: true } : {}), ...(typeof value.model === "string" && value.model !== "" ? { model: value.model } : {}), ...(typeof value.seedFailed === "string" && SEED_FAILURES.includes(value.seedFailed) ? { seedFailed: value.seedFailed } : {}), ...(value.use === true ? { use: true } : {}) };
|
|
94
91
|
}
|
|
95
92
|
/** A launch body read back into a `RunLaunch`, with the input-origin fail-safe applied through the body's own trigger, or
|
|
96
93
|
* undefined when the body is not one (not an object, or it names no place: a damaged or hand-edited body). */
|
|
@@ -122,7 +119,7 @@ export function readLaunchBody(stored) {
|
|
|
122
119
|
...(boxAllow !== undefined ? { boxAllow } : {}),
|
|
123
120
|
...(stored.box_allow_set === true ? { boxAllowSet: true } : {}),
|
|
124
121
|
...(Array.isArray(stored.files) && stored.files.every((id) => typeof id === "string") ? { files: stored.files } : {}),
|
|
125
|
-
...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? {
|
|
122
|
+
...(stored.learning !== undefined ? { learning: readLearning(stored.learning) ?? { seed: null, section: "" } } : {}),
|
|
126
123
|
...(stored.workflow_first === false ? { workflowFirst: false } : {}),
|
|
127
124
|
...(readReplay(stored.replay) ? { replay: readReplay(stored.replay) } : {}),
|
|
128
125
|
...(readReplay(stored.audit) ? { audit: readReplay(stored.audit) } : {}),
|
|
@@ -133,11 +130,11 @@ export function readLaunchBody(stored) {
|
|
|
133
130
|
...(isObject(stored.hold) && typeof stored.hold.minutes === "number" ? { hold: { minutes: stored.hold.minutes } } : {}),
|
|
134
131
|
};
|
|
135
132
|
}
|
|
136
|
-
/** The run's learning start (its
|
|
133
|
+
/** The run's learning start (its seed sha, its # Learned section and its learned workflows), read from one place by learning's
|
|
137
134
|
* routes and the runner; undefined when the run does not learn. */
|
|
138
135
|
export const learningStartOf = (launch) => launch.learning;
|
|
139
136
|
/** The same start read from a launch body's `learning` member alone (Store.runs.learningStarts), as readLaunchBody reads it. */
|
|
140
|
-
export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? {
|
|
137
|
+
export const learningStartOfStored = (stored) => (stored === undefined ? undefined : readLearning(stored) ?? { seed: null, section: "" });
|
|
141
138
|
const SEED_FAILURES = ["unreadable", "not_copied"];
|
|
142
139
|
/** A learning start with no seed (no commit of main, runs-over-store.ts learningStartFor): the run learns nothing, is
|
|
143
140
|
* never asked what to keep, and so is never told it learns. Why is its `seedFailed`, when its start records one. */
|
|
@@ -7,24 +7,15 @@ export declare function servedRunLearning(deps: {
|
|
|
7
7
|
signIns?: SignInReader;
|
|
8
8
|
statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
|
|
9
9
|
}, store: Store, runId: string): Promise<{
|
|
10
|
+
run: string;
|
|
11
|
+
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
12
|
+
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
13
|
+
detail: string | null;
|
|
14
|
+
at: string;
|
|
15
|
+
workflows: import("./learning.js").LearnedFile[];
|
|
16
|
+
corrections: number;
|
|
10
17
|
seed: string | null;
|
|
11
18
|
merged: string | null;
|
|
12
|
-
pending: {
|
|
13
|
-
file: string;
|
|
14
|
-
name: string;
|
|
15
|
-
}[];
|
|
16
|
-
verdict: {
|
|
17
|
-
merge: boolean;
|
|
18
|
-
reason: string;
|
|
19
|
-
items: {
|
|
20
|
-
why: string;
|
|
21
|
-
question?: string | undefined;
|
|
22
|
-
origin?: "run" | "you" | undefined;
|
|
23
|
-
pending?: boolean | undefined;
|
|
24
|
-
file: string;
|
|
25
|
-
keep: boolean;
|
|
26
|
-
}[];
|
|
27
|
-
} | null;
|
|
28
19
|
problems: {
|
|
29
20
|
detail: string;
|
|
30
21
|
path?: string | undefined;
|
|
@@ -32,7 +23,6 @@ export declare function servedRunLearning(deps: {
|
|
|
32
23
|
}[];
|
|
33
24
|
compiled: {
|
|
34
25
|
workflow: string;
|
|
35
|
-
from_notes: string[];
|
|
36
26
|
attempts: {
|
|
37
27
|
ok: boolean;
|
|
38
28
|
errors: string[];
|
|
@@ -41,63 +31,34 @@ export declare function servedRunLearning(deps: {
|
|
|
41
31
|
promoted: boolean | null;
|
|
42
32
|
} | null;
|
|
43
33
|
draft_errors: string[];
|
|
44
|
-
cost_usd: {
|
|
45
|
-
grade: number | null;
|
|
46
|
-
};
|
|
47
|
-
tokens: {
|
|
48
|
-
grade: import("./learning.js").Tokens | null;
|
|
49
|
-
};
|
|
50
34
|
used: {
|
|
51
|
-
skills: {
|
|
52
|
-
name: string;
|
|
53
|
-
read: boolean;
|
|
54
|
-
}[];
|
|
55
35
|
workflows: {
|
|
56
36
|
name: string;
|
|
57
37
|
calls: number;
|
|
58
38
|
failed: number;
|
|
59
39
|
}[];
|
|
60
40
|
};
|
|
61
|
-
given?: import("./learning.js").NoteUsed[];
|
|
62
|
-
read?: import("./learning.js").NoteUsed[];
|
|
63
|
-
learned?: import("./learning.js").NoteLearned[];
|
|
64
|
-
skills?: import("./learning.js").LearnedFile[];
|
|
65
|
-
workflows?: import("./learning.js").LearnedFile[];
|
|
66
|
-
run: string;
|
|
67
|
-
state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
|
|
68
|
-
reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
69
|
-
detail: string | null;
|
|
70
|
-
at: string;
|
|
71
41
|
} | {
|
|
72
42
|
graded: {
|
|
73
43
|
workflow: string | null;
|
|
74
44
|
feedback_status: "running" | "ended" | "not_run" | null;
|
|
75
45
|
source: "feedback" | "eval";
|
|
76
46
|
graded_at: string;
|
|
77
|
-
path: "agent" | "workflow" | "
|
|
47
|
+
path: "agent" | "workflow" | "replay" | "handed_back" | "audit";
|
|
78
48
|
workflow_digest: string | null;
|
|
79
|
-
feedback: "
|
|
49
|
+
feedback: "correction" | null;
|
|
80
50
|
run_id: string;
|
|
81
51
|
correct: boolean;
|
|
82
52
|
};
|
|
53
|
+
run: string;
|
|
54
|
+
state: "dropped" | "merged" | "seeded" | "reflecting";
|
|
55
|
+
reason: "cancelled" | "use" | "empty" | "crashed" | "reflect_failed" | "no_budget" | "checker" | "unknown_cost" | "seed_failed" | null;
|
|
56
|
+
detail: string | null;
|
|
57
|
+
at: string;
|
|
58
|
+
workflows: import("./learning.js").LearnedFile[];
|
|
59
|
+
corrections: number;
|
|
83
60
|
seed: string | null;
|
|
84
61
|
merged: string | null;
|
|
85
|
-
pending: {
|
|
86
|
-
file: string;
|
|
87
|
-
name: string;
|
|
88
|
-
}[];
|
|
89
|
-
verdict: {
|
|
90
|
-
merge: boolean;
|
|
91
|
-
reason: string;
|
|
92
|
-
items: {
|
|
93
|
-
why: string;
|
|
94
|
-
question?: string | undefined;
|
|
95
|
-
origin?: "run" | "you" | undefined;
|
|
96
|
-
pending?: boolean | undefined;
|
|
97
|
-
file: string;
|
|
98
|
-
keep: boolean;
|
|
99
|
-
}[];
|
|
100
|
-
} | null;
|
|
101
62
|
problems: {
|
|
102
63
|
detail: string;
|
|
103
64
|
path?: string | undefined;
|
|
@@ -105,7 +66,6 @@ export declare function servedRunLearning(deps: {
|
|
|
105
66
|
}[];
|
|
106
67
|
compiled: {
|
|
107
68
|
workflow: string;
|
|
108
|
-
from_notes: string[];
|
|
109
69
|
attempts: {
|
|
110
70
|
ok: boolean;
|
|
111
71
|
errors: string[];
|
|
@@ -114,33 +74,13 @@ export declare function servedRunLearning(deps: {
|
|
|
114
74
|
promoted: boolean | null;
|
|
115
75
|
} | null;
|
|
116
76
|
draft_errors: string[];
|
|
117
|
-
cost_usd: {
|
|
118
|
-
grade: number | null;
|
|
119
|
-
};
|
|
120
|
-
tokens: {
|
|
121
|
-
grade: import("./learning.js").Tokens | null;
|
|
122
|
-
};
|
|
123
77
|
used: {
|
|
124
|
-
skills: {
|
|
125
|
-
name: string;
|
|
126
|
-
read: boolean;
|
|
127
|
-
}[];
|
|
128
78
|
workflows: {
|
|
129
79
|
name: string;
|
|
130
80
|
calls: number;
|
|
131
81
|
failed: number;
|
|
132
82
|
}[];
|
|
133
83
|
};
|
|
134
|
-
given?: import("./learning.js").NoteUsed[];
|
|
135
|
-
read?: import("./learning.js").NoteUsed[];
|
|
136
|
-
learned?: import("./learning.js").NoteLearned[];
|
|
137
|
-
skills?: import("./learning.js").LearnedFile[];
|
|
138
|
-
workflows?: import("./learning.js").LearnedFile[];
|
|
139
|
-
run: string;
|
|
140
|
-
state: "dropped" | "proposed" | "merged" | "seeded" | "reflecting";
|
|
141
|
-
reason: "cancelled" | "use" | "empty" | "unparsed" | "seed_failed" | "no_budget" | "unknown_cost" | "crashed" | "reflect_timeout" | "reflect_failed" | "propose_failed" | "checker" | "grader" | "grade_failed" | null;
|
|
142
|
-
detail: string | null;
|
|
143
|
-
at: string;
|
|
144
84
|
} | null>;
|
|
145
85
|
/** Run `runId`'s learning diff as GET /runs/{id}/learning/diff serves it (learning-routes.ts runDiffOverStore), cut as its
|
|
146
86
|
* learning is, or ApiError forbidden for a withheld run. */
|
|
@@ -161,20 +101,6 @@ export declare function servedRunDiff(deps: {
|
|
|
161
101
|
patch: string;
|
|
162
102
|
withheld?: undefined;
|
|
163
103
|
})[];
|
|
164
|
-
} | {
|
|
165
|
-
base: string;
|
|
166
|
-
head: null;
|
|
167
|
-
files: ({
|
|
168
|
-
path: string;
|
|
169
|
-
status: string;
|
|
170
|
-
withheld: string;
|
|
171
|
-
patch?: undefined;
|
|
172
|
-
} | {
|
|
173
|
-
path: string;
|
|
174
|
-
status: string;
|
|
175
|
-
patch: string;
|
|
176
|
-
withheld?: undefined;
|
|
177
|
-
})[];
|
|
178
104
|
} | {
|
|
179
105
|
base: string | null;
|
|
180
106
|
head: null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RunListing, Store } from "./store/store.js";
|
|
2
|
+
import { type ViewDeps } from "./store-view.js";
|
|
3
|
+
/** How often an idle lister looks again (ms). */
|
|
4
|
+
export declare const LISTER_IDLE_MS = 400;
|
|
5
|
+
export interface Lister {
|
|
6
|
+
/** Starts its own passes: the first at once, then one each idle time (none with an idle time of Infinity). */
|
|
7
|
+
start(): void;
|
|
8
|
+
/** Builds run `runId`'s listing over `deps` and writes it at `mark`, the mark read before the build (Runs.putListing:
|
|
9
|
+
* not written when a write moved it since). A listing that read a workflow held for its owner's OK puts its agent's
|
|
10
|
+
* folder among those each pass reads, with the statuses this build read: an approval that lands after that read is
|
|
11
|
+
* then seen by the next pass, whoever built the listing (a pass, or a list). Undefined for an unknown run. */
|
|
12
|
+
build(runId: string, mark: number, deps: ViewDeps): Promise<{
|
|
13
|
+
listing: RunListing | undefined;
|
|
14
|
+
written: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
/** Resolves once a pass finds nothing it may build now: every run's listing is current, but for a held run built within
|
|
17
|
+
* its rebuild time. For tests and benchmarks; the server never waits on it. */
|
|
18
|
+
settled(): Promise<void>;
|
|
19
|
+
/** The server's keys or settings changed: every failed run's listing (its error words) is marked behind before this
|
|
20
|
+
* resolves, so the next list builds it again. */
|
|
21
|
+
keysChanged(): Promise<void>;
|
|
22
|
+
/** A person changed agent `agentId`'s learning folder (a workflow approved, retired or restored): each of its runs
|
|
23
|
+
* whose listing read a workflow held for the owner's OK is marked behind before this resolves, so the next list says what
|
|
24
|
+
* the folder says now. A change made outside the server is read by the next pass. */
|
|
25
|
+
learningChanged(agentId: string): Promise<void>;
|
|
26
|
+
/** Stops after the pass under way. */
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
/** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
|
|
30
|
+
export declare function createLister(store: Store, depsOf: () => ViewDeps, options?: {
|
|
31
|
+
readonly log?: (line: string, error: Error) => void;
|
|
32
|
+
readonly now?: () => number;
|
|
33
|
+
readonly idleMs?: number;
|
|
34
|
+
}): Lister;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { LISTING_HELD, LISTING_KEYED } from "./store/schema.js";
|
|
2
|
+
import { LISTING_RETRY_MS, listingOverStore } from "./store-view.js";
|
|
3
|
+
/** Most rows one read of a pass reads. */
|
|
4
|
+
const PASS_ROWS = 32;
|
|
5
|
+
/** How often an idle lister looks again (ms). */
|
|
6
|
+
export const LISTER_IDLE_MS = 400;
|
|
7
|
+
/** The least time between two builds of one run a runner holds (ms). */
|
|
8
|
+
const HELD_REBUILD_MS = 1_000;
|
|
9
|
+
/** The lister over `store`, its passes not started (Lister.start): a list may build through it before they are. */
|
|
10
|
+
export function createLister(store, depsOf, options = {}) {
|
|
11
|
+
const now = options.now ?? Date.now;
|
|
12
|
+
/** Infinity: no pass of its own, only those settled() asks for. */
|
|
13
|
+
const idleMs = options.idleMs ?? LISTER_IDLE_MS;
|
|
14
|
+
let closing = false;
|
|
15
|
+
let timer;
|
|
16
|
+
let pass = Promise.resolve(0);
|
|
17
|
+
/** A held run's last build: when, and how long it took. */
|
|
18
|
+
const built = new Map();
|
|
19
|
+
/** The agents with a run whose learning holds items for the owner's OK, with their folder's statuses as last read (for an
|
|
20
|
+
* agent first met in a build, as that build read them). */
|
|
21
|
+
const folders = new Map();
|
|
22
|
+
/** When each run whose view failed to build last failed. */
|
|
23
|
+
const failed = new Map();
|
|
24
|
+
/** The first pass marks behind every listing that read outside its run: the keys or folders may have moved while no
|
|
25
|
+
* server ran. */
|
|
26
|
+
let relistKeys = true;
|
|
27
|
+
const say = (what, error) => options.log?.(what, error instanceof Error ? error : new Error(String(error)));
|
|
28
|
+
/** Lister.build: the one build of a listing, a pass's or a list's. */
|
|
29
|
+
async function build(id, mark, deps) {
|
|
30
|
+
// The folder statuses this build read, by agent: the baseline a later pass compares against, never a read made after
|
|
31
|
+
// it, which a person's approval landing before this listing's write would already hold.
|
|
32
|
+
const read = new Map();
|
|
33
|
+
const statuses = deps.statuses;
|
|
34
|
+
const buildDeps = statuses ? { ...deps, statuses: async (agentId) => { const seen = await statuses(agentId); if (!read.has(agentId))
|
|
35
|
+
read.set(agentId, seen); return seen; } } : deps;
|
|
36
|
+
const listing = await listingOverStore(store, id, buildDeps);
|
|
37
|
+
const written = listing ? await store.runs.putListing(id, mark, listing) : false;
|
|
38
|
+
const agentId = listing ? String(listing.item.agent_id) : "";
|
|
39
|
+
if (listing && listing.flags & LISTING_HELD && !folders.has(agentId))
|
|
40
|
+
folders.set(agentId, read.get(agentId));
|
|
41
|
+
return { listing, written };
|
|
42
|
+
}
|
|
43
|
+
/** One pass: what moved outside the runs' writes, then each behind row this pass may build. The rows it built. */
|
|
44
|
+
async function once() {
|
|
45
|
+
const deps = depsOf();
|
|
46
|
+
if (relistKeys) {
|
|
47
|
+
relistKeys = false;
|
|
48
|
+
await store.runs.relist({ flags: LISTING_HELD | LISTING_KEYED });
|
|
49
|
+
}
|
|
50
|
+
for (const [agentId, seen] of folders) {
|
|
51
|
+
const statuses = await deps.statuses?.(agentId);
|
|
52
|
+
if (statuses === seen)
|
|
53
|
+
continue;
|
|
54
|
+
folders.set(agentId, statuses);
|
|
55
|
+
await store.runs.relist({ flags: LISTING_HELD, agentId });
|
|
56
|
+
}
|
|
57
|
+
// PASS_ROWS rows at a time, until a read builds one or none is left. A row passed over (a held run built within its
|
|
58
|
+
// rebuild time, a run whose view failed to build and waits for its retry, one written meanwhile) stays behind, so
|
|
59
|
+
// the next read starts after every row passed over so far: such rows never hold up the rows after them.
|
|
60
|
+
let count = 0;
|
|
61
|
+
let passed = 0;
|
|
62
|
+
for (;;) {
|
|
63
|
+
const rows = await store.runs.behind({ limit: PASS_ROWS, offset: passed });
|
|
64
|
+
for (const { id, mark, held } of rows) {
|
|
65
|
+
if (closing)
|
|
66
|
+
break;
|
|
67
|
+
const last = built.get(id);
|
|
68
|
+
if ((held && last && now() - last.at < Math.max(HELD_REBUILD_MS, 4 * last.ms)) || (failed.get(id) ?? -Infinity) > now() - LISTING_RETRY_MS) {
|
|
69
|
+
passed++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const start = now();
|
|
73
|
+
let listing;
|
|
74
|
+
let written;
|
|
75
|
+
try {
|
|
76
|
+
({ listing, written } = await build(id, mark, deps));
|
|
77
|
+
failed.delete(id);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
failed.set(id, now());
|
|
81
|
+
say("run_listing_unbuilt", error);
|
|
82
|
+
passed++;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!written)
|
|
86
|
+
passed++;
|
|
87
|
+
if (!listing)
|
|
88
|
+
continue;
|
|
89
|
+
count++;
|
|
90
|
+
if (held)
|
|
91
|
+
built.set(id, { at: now(), ms: now() - start });
|
|
92
|
+
else
|
|
93
|
+
built.delete(id);
|
|
94
|
+
}
|
|
95
|
+
if (closing || count > 0 || rows.length < PASS_ROWS)
|
|
96
|
+
return count;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** A pass after the one under way: one at a time, whoever asks. */
|
|
100
|
+
const turn = () => (pass = pass.then(() => (closing ? 0 : once())).catch((error) => (say("run_listing_unbuilt", error), 0)));
|
|
101
|
+
function next(delay) {
|
|
102
|
+
if (closing || !Number.isFinite(idleMs))
|
|
103
|
+
return;
|
|
104
|
+
timer = setTimeout(() => void turn().then((count) => next(count > 0 ? 0 : idleMs)), delay);
|
|
105
|
+
timer.unref();
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
start() {
|
|
109
|
+
next(0);
|
|
110
|
+
},
|
|
111
|
+
build,
|
|
112
|
+
async settled() {
|
|
113
|
+
while ((await turn()) > 0)
|
|
114
|
+
;
|
|
115
|
+
},
|
|
116
|
+
async keysChanged() {
|
|
117
|
+
await store.runs.relist({ flags: LISTING_KEYED });
|
|
118
|
+
},
|
|
119
|
+
async learningChanged(agentId) {
|
|
120
|
+
await store.runs.relist({ flags: LISTING_HELD, agentId });
|
|
121
|
+
},
|
|
122
|
+
async stop() {
|
|
123
|
+
closing = true;
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
await pass;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
|
+
/** The longest model key a run takes: a header value, never a document. */
|
|
3
|
+
export declare const MAX_MODEL_KEY_CHARS = 4096;
|
|
4
|
+
/** The origin of the model gateway a run's model key goes to (AGENT_MODEL_BASE_URL's, by the one base rule), or undefined
|
|
5
|
+
* when the server names none or one a key may not go to. */
|
|
6
|
+
export declare function runModelOrigin(env: NodeJS.ProcessEnv): string | undefined;
|
|
7
|
+
/** The variables a run's model key fills in a model route's env, for a gateway at `origin`: the gateway's key, and
|
|
8
|
+
* ANTHROPIC_API_KEY where ANTHROPIC_BASE_URL is that same gateway. */
|
|
9
|
+
export declare function runKeyNames(env: NodeJS.ProcessEnv, origin: string): string[];
|
|
10
|
+
/** A model key `body` hands, checked: text of 1 to MAX_MODEL_KEY_CHARS characters with no whitespace or control character
|
|
11
|
+
* (it goes in a header). Issues are pushed at `model_key`. */
|
|
12
|
+
export declare function modelKeyOf(value: unknown, issues: InputIssue[]): string | undefined;
|
|
13
|
+
/** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
|
|
14
|
+
* none the run holds, and none the server holds for its route. */
|
|
15
|
+
export declare const modelKeyRequired: (message: boolean) => ApiError;
|
|
16
|
+
/** What of a run says where its model requests go: its kind and its launch's pinned model. */
|
|
17
|
+
export type ModelKeyTarget = {
|
|
18
|
+
readonly kind: "agentic" | "workflow" | string;
|
|
19
|
+
readonly model?: {
|
|
20
|
+
readonly provider: string;
|
|
21
|
+
readonly modelId: string;
|
|
22
|
+
} | undefined;
|
|
23
|
+
readonly native?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/** The variables a run's model route reads its key from when that route goes to the model gateway (a workflow's model
|
|
26
|
+
* nodes, pi's and codex's models, a CLI harness on Anthropic's wire where ANTHROPIC_BASE_URL is the gateway's origin);
|
|
27
|
+
* undefined for a route that goes elsewhere (a provider's own, the ChatGPT plan, the faux model) or a native run. */
|
|
28
|
+
export declare function gatewayKeyNames(env: NodeJS.ProcessEnv, run: ModelKeyTarget): string[] | undefined;
|
|
29
|
+
/** Whether a run of `run` with no key of its own has none to spend: its route goes to the gateway, and `env` (the
|
|
30
|
+
* server's, with the keys saved in Settings) holds no key it reads. */
|
|
31
|
+
export declare function serverKeyMissing(env: NodeJS.ProcessEnv, run: ModelKeyTarget): boolean;
|
|
32
|
+
/** Words for model spend tied to no run's key (`what`, a noun phrase) on a server that holds no gateway key (`env`, its
|
|
33
|
+
* keys saved in Settings among them): skipped or refused, never sent with no key. Undefined where the server holds one. */
|
|
34
|
+
export declare function noServerKeyFor(env: NodeJS.ProcessEnv, what: string): string | undefined;
|
|
35
|
+
/** The words of noServerKeyFor for `what`. */
|
|
36
|
+
export declare const noServerKeyWords: (what: string) => string;
|
|
37
|
+
/** Words for spend after the turn of a run that held its own model key (`what`): skipped, since that key is erased with
|
|
38
|
+
* the turn's end and revoked by its caller, and the server's key never pays for a run that brought its own. */
|
|
39
|
+
export declare const runKeyEndedFor: (what: string) => string;
|
|
40
|
+
/** Why a run's model key would never be used, so it is refused rather than kept unused; undefined where it applies: a
|
|
41
|
+
* workflow run (its model nodes go to the gateway), or an agentic run whose model goes to the gateway (pi's and codex's,
|
|
42
|
+
* MODEL_PROVIDER) or to Anthropic's endpoint on the gateway's origin (a CLI harness on Anthropic's wire). */
|
|
43
|
+
export declare function modelKeyMisfit(env: NodeJS.ProcessEnv, run: ModelKeyTarget): string | undefined;
|
|
44
|
+
/** A run's model key as a claim holds it: the gateway origin it was handed for, and the key now (a message's replaces it
|
|
45
|
+
* at the next command; none before the run's first key, and none once its launch no longer holds one). */
|
|
46
|
+
export interface HeldModelKey {
|
|
47
|
+
readonly origin: string;
|
|
48
|
+
key(): string | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `env` for a run's model routes when the run holds its own key: every property of `env` but each model key (the runner's
|
|
52
|
+
* own and any saved one never go), with the run's key read at each request (`held.key()`) in each variable it fills
|
|
53
|
+
* (runKeyNames). Those are getters, never enumerable: a spread of the result, a spawn given it or a tool's env made from
|
|
54
|
+
* it carries none of them. No ChatGPT sign-in either (a symbol, not copied): every model call tied to the run carries
|
|
55
|
+
* the run's key.
|
|
56
|
+
*/
|
|
57
|
+
export declare function withRunModelKey(env: NodeJS.ProcessEnv, held: HeldModelKey): NodeJS.ProcessEnv;
|
|
58
|
+
/**
|
|
59
|
+
* `env` (a claim's model env on the server's keys, withModelKeys) for a run that holds no key of its own yet: each
|
|
60
|
+
* variable a run's key fills (runKeyNames) reads the run's key once a message hands one, and the server's value until
|
|
61
|
+
* then, at each request; every other variable as it is. So a run that started on the server's key spends a message's
|
|
62
|
+
* key from the request after that message on. Getters, never enumerable, as withRunModelKey's.
|
|
63
|
+
*/
|
|
64
|
+
export declare function withRunModelKeyLater(env: NodeJS.ProcessEnv, held: HeldModelKey): NodeJS.ProcessEnv;
|