@parcha/agentrun-serve 0.1.0-beta.36 → 0.1.0-beta.37
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 +170 -0
- package/README.md +158 -52
- package/dist/attach-conformance-cli.d.ts +1 -0
- package/dist/attach-conformance-cli.js +18 -0
- package/dist/attach-conformance.d.ts +25 -0
- package/dist/attach-conformance.js +343 -0
- package/dist/browser-cost.d.ts +1 -1
- package/dist/browser-live.d.ts +20 -8
- package/dist/browser-live.js +50 -27
- package/dist/cap.d.ts +0 -17
- package/dist/cap.js +0 -91
- package/dist/catalog.d.ts +1 -12
- package/dist/catalog.js +3 -33
- package/dist/cli.js +13 -4
- package/dist/composio-preset.d.ts +36 -0
- package/dist/composio-preset.js +179 -0
- package/dist/computer-attach.d.ts +125 -0
- package/dist/computer-attach.js +330 -0
- package/dist/computer-calls.d.ts +48 -0
- package/dist/computer-calls.js +126 -0
- package/dist/computer-channel.d.ts +57 -0
- package/dist/computer-channel.js +115 -0
- package/dist/computer-commands.d.ts +1 -1
- package/dist/computer-held-routes.d.ts +35 -0
- package/dist/computer-held-routes.js +106 -0
- package/dist/computer-held.d.ts +48 -0
- package/dist/computer-held.js +87 -0
- package/dist/computer-keys.d.ts +21 -1
- package/dist/computer-keys.js +53 -11
- package/dist/computer-live.d.ts +160 -0
- package/dist/computer-live.js +643 -0
- package/dist/computer-view.d.ts +13 -0
- package/dist/computer-view.js +50 -3
- package/dist/computer-viewer.d.ts +6 -0
- package/dist/computer-viewer.js +297 -0
- package/dist/computers.d.ts +33 -7
- package/dist/computers.js +50 -8
- package/dist/console/assets/index-Cn6JX1uH.js +563 -0
- package/dist/console/assets/index-DRN62V5v.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/faux-computers.d.ts +9 -20
- package/dist/faux-computers.js +53 -25
- package/dist/github-connection.d.ts +10 -2
- package/dist/github-connection.js +65 -2
- package/dist/github-faux.js +1 -1
- package/dist/graph-view.d.ts +1 -1
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +35 -1
- package/dist/host-tools.d.ts +1 -1
- package/dist/hosted-search.d.ts +5 -4
- package/dist/hosted-search.js +2 -7
- package/dist/import-sources.d.ts +10 -0
- package/dist/import-sources.js +44 -2
- package/dist/import.d.ts +3 -3
- package/dist/import.js +37 -6
- package/dist/learn/check.d.ts +4 -1
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +4 -2
- package/dist/learn/commit.js +5 -5
- package/dist/learn/folder.d.ts +6 -0
- package/dist/learn/folder.js +4 -1
- package/dist/learn/general.d.ts +66 -0
- package/dist/learn/general.js +73 -0
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +22 -1
- package/dist/learn/reflect.d.ts +10 -1
- package/dist/learn/reflect.js +14 -4
- package/dist/learn/skills.d.ts +33 -5
- package/dist/learn/skills.js +53 -7
- package/dist/learned-workflow.d.ts +24 -0
- package/dist/learned-workflow.js +66 -3
- package/dist/learning-batch.d.ts +283 -0
- package/dist/learning-batch.js +574 -0
- package/dist/learning-evals.d.ts +33 -0
- package/dist/learning-evals.js +98 -0
- package/dist/learning-routes.d.ts +25 -2
- package/dist/learning-routes.js +39 -6
- package/dist/learning-words.d.ts +6 -0
- package/dist/learning-words.js +6 -0
- package/dist/learning.d.ts +28 -15
- package/dist/learning.js +84 -44
- package/dist/live/stream.js +6 -3
- package/dist/live/translate.d.ts +4 -3
- package/dist/live/translate.js +8 -4
- package/dist/live-reach.d.ts +37 -0
- package/dist/live-reach.js +62 -0
- package/dist/mcp-gateway.d.ts +9 -0
- package/dist/mcp-gateway.js +60 -11
- package/dist/mcp-oauth.d.ts +57 -7
- package/dist/mcp-oauth.js +133 -18
- package/dist/mcp-private-hosts.d.ts +4 -4
- package/dist/mcp-private-hosts.js +20 -12
- package/dist/mcp-probe.d.ts +19 -2
- package/dist/mcp-probe.js +44 -9
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +38 -15
- package/dist/mcp-servers-store.js +112 -20
- package/dist/mcp-store.d.ts +10 -4
- package/dist/mcp-store.js +17 -6
- package/dist/model-form.d.ts +26 -0
- package/dist/model-form.js +80 -0
- package/dist/model.js +23 -10
- package/dist/openapi.js +386 -21
- package/dist/page.d.ts +18 -0
- package/dist/page.js +48 -20
- package/dist/paid-calls.d.ts +1 -1
- package/dist/place-offers.d.ts +2 -3
- package/dist/place-offers.js +3 -7
- package/dist/place.js +1 -2
- package/dist/print.d.ts +15 -1
- package/dist/print.js +14 -3
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +13 -5
- package/dist/provider.js +3 -2
- package/dist/reflect-range.d.ts +8 -1
- package/dist/reflect-range.js +1 -1
- package/dist/run-launch.d.ts +14 -2
- package/dist/run-launch.js +9 -4
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-repo.d.ts +20 -0
- package/dist/run-repo.js +63 -0
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-view.d.ts +3 -3
- package/dist/run-view.js +14 -7
- package/dist/runner/adapter-loop.d.ts +23 -7
- package/dist/runner/adapter-loop.js +648 -62
- package/dist/runner/adapter-run-spec.d.ts +11 -3
- package/dist/runner/adapter-run-spec.js +77 -22
- package/dist/runner/adapters/pi-computer.d.ts +7 -0
- package/dist/runner/adapters/pi-computer.js +43 -0
- package/dist/runner/adapters/pi.d.ts +9 -4
- package/dist/runner/adapters/pi.js +76 -14
- package/dist/runner/beside.d.ts +7 -3
- package/dist/runner/beside.js +21 -11
- package/dist/runner/claim-secrets.d.ts +4 -0
- package/dist/runner/claim-secrets.js +6 -1
- package/dist/runner/cli-run-spec.d.ts +20 -3
- package/dist/runner/cli-run-spec.js +113 -43
- package/dist/runner/commands.d.ts +3 -1
- package/dist/runner/commands.js +28 -3
- package/dist/runner/computer-channel.d.ts +34 -0
- package/dist/runner/computer-channel.js +61 -0
- package/dist/runner/conformance/harness.js +80 -14
- package/dist/runner/conformance/subject.d.ts +1 -1
- package/dist/runner/dispatch.js +3 -0
- package/dist/runner/end-of-run.d.ts +22 -12
- package/dist/runner/end-of-run.js +38 -16
- package/dist/runner/github-app.d.ts +2 -1
- package/dist/runner/github-app.js +4 -2
- package/dist/runner/harness-loops.js +15 -1
- package/dist/runner/held-run.d.ts +65 -0
- package/dist/runner/held-run.js +158 -0
- package/dist/runner/journal-kinds.d.ts +20 -1
- package/dist/runner/journal-kinds.js +14 -0
- package/dist/runner/journal-reader.d.ts +5 -4
- package/dist/runner/journal-reader.js +12 -10
- package/dist/runner/learning-ask.d.ts +7 -1
- package/dist/runner/learning-ask.js +21 -6
- package/dist/runner/learning-dispatch.d.ts +22 -0
- package/dist/runner/learning-dispatch.js +77 -10
- package/dist/runner/learning-end.d.ts +22 -1
- package/dist/runner/learning-end.js +92 -12
- package/dist/runner/learning-factory.d.ts +1 -1
- package/dist/runner/learning-factory.js +11 -5
- package/dist/runner/learning-loop.d.ts +67 -7
- package/dist/runner/learning-loop.js +173 -21
- package/dist/runner/learning-seed.d.ts +7 -0
- package/dist/runner/learning-seed.js +13 -0
- package/dist/runner/live-ticker.js +1 -0
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +2 -1
- package/dist/runner/main.d.ts +13 -1
- package/dist/runner/main.js +27 -5
- package/dist/runner/mcp-claim.d.ts +10 -7
- package/dist/runner/mcp-claim.js +113 -24
- package/dist/runner/mcp-github.js +1 -1
- package/dist/runner/mcp-run.d.ts +5 -5
- package/dist/runner/mcp-run.js +15 -3
- package/dist/runner/metrics.d.ts +11 -2
- package/dist/runner/metrics.js +12 -2
- package/dist/runner/pr-checkout.d.ts +1 -0
- package/dist/runner/pr-checkout.js +1 -1
- package/dist/runner/reflect-hook.d.ts +18 -0
- package/dist/runner/reflect-hook.js +20 -8
- package/dist/runner/runner.d.ts +26 -0
- package/dist/runner/runner.js +184 -15
- package/dist/runner/scratch-sweep.d.ts +13 -0
- package/dist/runner/scratch-sweep.js +62 -0
- package/dist/runner/sessions.d.ts +1 -1
- package/dist/runner/store-port.d.ts +4 -2
- package/dist/runner/store-secrets.js +4 -3
- package/dist/runner/subagent.js +3 -1
- package/dist/runner/workflow-host.d.ts +6 -1
- package/dist/runner/workflow-host.js +1 -1
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-spec.d.ts +14 -2
- package/dist/runner/workflow-spec.js +56 -20
- package/dist/runs-over-store.d.ts +6 -1
- package/dist/runs-over-store.js +38 -9
- package/dist/seal-key.js +3 -3
- package/dist/sealed-settings-store.d.ts +5 -2
- package/dist/sealed-settings-store.js +10 -4
- package/dist/secret-writes.d.ts +5 -4
- package/dist/secret-writes.js +5 -4
- package/dist/server-secrets-store.d.ts +4 -3
- package/dist/server-secrets-store.js +15 -9
- package/dist/server-secrets.js +3 -2
- package/dist/server.d.ts +43 -14
- package/dist/server.js +472 -126
- package/dist/settings-wake.d.ts +21 -0
- package/dist/settings-wake.js +59 -0
- package/dist/standard-webhooks.d.ts +4 -1
- package/dist/standard-webhooks.js +8 -4
- package/dist/store/command-wake.d.ts +12 -0
- package/dist/store/command-wake.js +37 -0
- package/dist/store/dialect.d.ts +6 -0
- package/dist/store/dialect.js +5 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +3 -2
- package/dist/store/journal/storage.js +13 -5
- package/dist/store/postgres/dialect.js +4 -0
- package/dist/store/postgres/migrations/0005_learning_rounds.sql +14 -0
- package/dist/store/postgres/migrations/0006_run_changes_channel_attempts.sql +57 -0
- package/dist/store/postgres/migrations/0007_viewer_host.sql +11 -0
- package/dist/store/postgres/migrations/0008_paired_computers.sql +30 -0
- package/dist/store/postgres/migrations/0009_commands_answer.sql +10 -0
- package/dist/store/schema.d.ts +1 -1
- package/dist/store/schema.js +77 -8
- package/dist/store/sqlite/run-patch.d.ts +7 -5
- package/dist/store/sqlite/run-patch.js +28 -13
- package/dist/store/sqlite/store.js +272 -54
- package/dist/store/store.d.ts +268 -9
- package/dist/store/store.js +12 -1
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +8 -1
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +1 -1
- package/dist/store-reads/import-summary.d.ts +1 -1
- package/dist/store-reads/journal.d.ts +5 -4
- package/dist/store-reads/journal.js +73 -15
- package/dist/store-reads/learning.d.ts +20 -4
- package/dist/store-reads/learning.js +74 -18
- package/dist/store-reads/runs.d.ts +1 -1
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +26 -11
- package/dist/template-eval.js +6 -4
- package/dist/template-github-permissions.d.ts +22 -8
- package/dist/template-github-permissions.js +35 -15
- package/dist/timeline/timeline.d.ts +27 -0
- package/dist/timeline/timeline.js +10 -9
- package/dist/timeline/util.d.ts +4 -0
- package/dist/timeline/util.js +14 -0
- package/dist/tool-budget.d.ts +19 -7
- package/dist/tool-budget.js +14 -8
- package/dist/tool-gate.d.ts +16 -9
- package/dist/tool-gate.js +53 -42
- package/dist/tool-plane.d.ts +16 -12
- package/dist/tool-plane.js +9 -4
- package/dist/tools.d.ts +13 -4
- package/dist/tools.js +13 -4
- package/dist/trigger-adapter.d.ts +4 -0
- package/dist/trigger-secrets-shown.d.ts +2 -2
- package/dist/trigger-secrets-shown.js +1 -1
- package/dist/trigger-signatures.d.ts +25 -6
- package/dist/trigger-signatures.js +41 -7
- package/dist/trigger-targets.d.ts +2 -0
- package/dist/trigger-targets.js +1 -0
- package/dist/trigger-webhook.js +5 -2
- package/dist/triggers.d.ts +7 -3
- package/dist/triggers.js +35 -5
- package/dist/turns.js +16 -1
- package/dist/validate.js +11 -1
- package/dist/web-fetch.d.ts +1 -1
- package/dist/web-search.d.ts +10 -5
- package/dist/web-search.js +7 -6
- package/dist/webhooks.d.ts +145 -102
- package/dist/webhooks.js +559 -322
- package/dist/workflow/decisions.d.ts +1 -1
- package/dist/workflow/node-runner.d.ts +2 -1
- package/dist/workflow/node.d.ts +2 -1
- package/dist/workflow/node.js +3 -1
- package/dist/workflow/pi-versions.d.ts +23 -0
- package/dist/workflow/pi-versions.js +57 -0
- package/dist/workflow/record-tool.d.ts +2 -1
- package/dist/workflow/store.d.ts +1 -1
- package/dist/workflow/task.js +3 -2
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/attached-computers.d.ts +41 -0
- package/dist/workspace/attached-computers.js +114 -0
- package/dist/workspace/computer-deps.d.ts +16 -9
- package/dist/workspace/computer-deps.js +19 -7
- package/dist/workspace/computer-for-claim.d.ts +17 -8
- package/dist/workspace/computer-for-claim.js +62 -21
- package/dist/workspace/computer-hold.d.ts +11 -27
- package/dist/workspace/computer-hold.js +36 -56
- package/dist/workspace/computer-ledger.d.ts +3 -1
- package/dist/workspace/computer-ledger.js +4 -0
- package/dist/workspace/computer-mcp.d.ts +25 -0
- package/dist/workspace/computer-mcp.js +41 -0
- package/dist/workspace/computer-ports.d.ts +4 -13
- package/dist/workspace/computer-ports.js +4 -107
- package/dist/workspace/computer-script.d.ts +37 -0
- package/dist/workspace/computer-script.js +138 -0
- package/dist/workspace/executors.d.ts +1 -1
- package/dist/workspace/index.d.ts +4 -2
- package/dist/workspace/index.js +3 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +119 -84
- package/dist/workspace/kind-skills/phone/SKILL.md +100 -85
- package/dist/workspace/resolve-computer.d.ts +3 -0
- package/dist/workspace/resolve-computer.js +8 -2
- package/dist/workspace/run-tools.d.ts +32 -15
- package/dist/workspace/run-tools.js +23 -30
- package/package.json +19 -16
- package/templates/market-monitor/agent.md +1 -1
- package/dist/console/assets/index-BI4Byidu.js +0 -550
- package/dist/console/assets/index-C19gUF2n.css +0 -1
- package/dist/run-db.d.ts +0 -53
- package/dist/run-db.js +0 -116
- package/dist/workflow/readers.d.ts +0 -36
- package/dist/workflow/readers.js +0 -145
- package/dist/workflow/wal.d.ts +0 -11
- package/dist/workflow/wal.js +0 -106
package/dist/learn/reflect.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { CAPS } from "./check.js";
|
|
8
8
|
import { INDEX_FILE, INDEX_LINES } from "./notes.js";
|
|
9
|
-
import { LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
|
|
9
|
+
import { draftDecisionProviders, LEARNED_MCP_TOOL, SKILL_NAME } from "./skills.js";
|
|
10
10
|
/** Control and invisible characters: none may reach the prompt through a value the host puts in it. */
|
|
11
11
|
const UNSEEN = /[\p{Cc}\p{Cf}]/u;
|
|
12
12
|
/** The info word that opens a note's block in the answer: ```note <file>. */
|
|
@@ -22,6 +22,9 @@ export const DRAFT_AFTER_RUNS = 3;
|
|
|
22
22
|
* LEARNED_MCP_TOOL). */
|
|
23
23
|
const TOOL_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
24
24
|
const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
|
|
25
|
+
/** What a later round's end-of-run prompt says first (reflectPrompt's `later`): the run looked back before, at an end a
|
|
26
|
+
* follow-up opened it again from, so only what came since is new. */
|
|
27
|
+
export const LATER_LOOK = "You looked back on this run before. Since then the conversation went on: keep only what the messages since then teach (a reviewer's word on your answer included), and never repeat a note you kept then.";
|
|
25
28
|
/** The end-of-run turn's message. `dir` is the run's copy of the folder relative to the run's workspace (`.learning`),
|
|
26
29
|
* where the agent can read its notes: the prompt never names a path of the host's, which a box would not see. `active`
|
|
27
30
|
* is how many notes are active in it, so how many lines the index has left. `tools`, the tools a workflow draft's
|
|
@@ -32,9 +35,13 @@ const printable = (tool) => TOOL_NAME.test(tool) || LEARNED_MCP_TOOL.test(tool);
|
|
|
32
35
|
* summary), said under the ask, one line each (at most DESCRIBED_MAX characters, unseen characters and line breaks made
|
|
33
36
|
* spaces); one for a tool not in `tools` is left out. Nothing is described unless a draft is asked for. `workflows`, false
|
|
34
37
|
* for a run of a revision that says `learning: "notes"`: the prompt asks for notes and a skill alone, says to keep no
|
|
35
|
-
* workflow draft, and asks for none (`draftFor` and `described` are not said).
|
|
38
|
+
* workflow draft, and asks for none (`draftFor` and `described` are not said). `decisions`, the run's decision providers
|
|
39
|
+
* (skills.ts DraftDecisions, the one the draft check reads): with a provider it has (draftDecisionProviders), a draft may
|
|
40
|
+
* use judge, pick and sift nodes; without, the prompt bans them as it always did. `later`, a later round's (a follow-up
|
|
41
|
+
* opened the run again after it looked back): the prompt says so (LATER_LOOK) after its first line. */
|
|
36
42
|
export function reflectPrompt(options) {
|
|
37
|
-
const { dir, active, tools = [], draftFor = [], described = [], workflows = true } = options;
|
|
43
|
+
const { dir, active, tools = [], draftFor = [], described = [], workflows = true, decisions, later = false } = options;
|
|
44
|
+
const judges = draftDecisionProviders(decisions).length > 0;
|
|
38
45
|
if (typeof dir !== "string" || dir === "" || dir.startsWith("/") || UNSEEN.test(dir))
|
|
39
46
|
throw new Error("the directory must be a path relative to the run's workspace, with no control or unseen characters");
|
|
40
47
|
if (!Number.isSafeInteger(active) || active < 0)
|
|
@@ -47,6 +54,7 @@ export function reflectPrompt(options) {
|
|
|
47
54
|
return [
|
|
48
55
|
"The task is done. Before the run ends, say what this run taught you that will help in later runs, if anything.",
|
|
49
56
|
"",
|
|
57
|
+
...(later ? [LATER_LOOK, ""] : []),
|
|
50
58
|
"Look back over the whole conversation: what the user asked, anything they asked you to remember (even if you said you",
|
|
51
59
|
"saved it), what you tried, and what worked. Only what you answer now is kept: files you wrote during the task are not.",
|
|
52
60
|
"Use no tool in this turn.",
|
|
@@ -124,7 +132,9 @@ export function reflectPrompt(options) {
|
|
|
124
132
|
"",
|
|
125
133
|
...(workflows ? [
|
|
126
134
|
"A workflow draft does the job as one workflow DSL document: front matter with one line that says what it does and",
|
|
127
|
-
"when to use it, then the JSON.
|
|
135
|
+
"when to use it, then the JSON. " + (judges
|
|
136
|
+
? "It uses model and tool-call nodes, and may use judge (answers a question about a value), pick (chooses one of several options) and sift (keeps the items that pass a test) nodes, which run on this run's decision provider under its cap and tool policy; no code node, no shell or"
|
|
137
|
+
: "It uses model and tool-call nodes only: no judge, pick or sift node, no code node, no shell or"),
|
|
128
138
|
`executor call. Its model nodes name no tool. ${tools.length ? `Its call nodes may run only these tools: ${tools.join(", ")}.` : "It has no call node on a tool."} At most ${CAPS.file} bytes of JSON.`,
|
|
129
139
|
"To change a draft you were given, give it again whole under its name.",
|
|
130
140
|
"Its schemas are declared once under `schemas`, and `input` and `output` name one each by `schemaId`, never a schema",
|
package/dist/learn/skills.d.ts
CHANGED
|
@@ -193,9 +193,36 @@ export declare const MODEL_NODE_TOOLS = "a learned workflow's model node runs wi
|
|
|
193
193
|
/** What a learned draft whose output names no path is refused with. */
|
|
194
194
|
export declare const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
|
|
195
195
|
/** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
|
|
196
|
-
* runNode and
|
|
197
|
-
*
|
|
198
|
-
export declare const LEARNED_NODES = "a learned workflow runs model and tool-call nodes";
|
|
196
|
+
* runNode, runEffect, and runJudge only when the run has decision providers): a judge, pick or sift node, a route by
|
|
197
|
+
* question, a verify or an ask on a run with none. Refused at learn time and before a call runs any node, never after. */
|
|
198
|
+
export declare const LEARNED_NODES = "a learned workflow runs model and tool-call nodes, and decision nodes on a run with decision providers";
|
|
199
|
+
/** A learned draft's decisions as its check reads them (LS-07): the decision providers the run has (by id, the DSL's
|
|
200
|
+
* DecisionProvider each, decisions.ts decisionProvidersIn over its keys) and the one a node that names none is asked
|
|
201
|
+
* of; `gated`, the provider ids the run's gate does not allow (by its setting, the provider's bare id as its settings
|
|
202
|
+
* key: tool-plane.ts DECISION_PROVIDER_KEYS), of which deny alone refuses, and `deniedBy`, where each deny was set. With none, a decision node
|
|
203
|
+
* is refused (LEARNED_NODES). */
|
|
204
|
+
export type DraftDecisions = {
|
|
205
|
+
readonly providers: Readonly<Record<string, unknown>>;
|
|
206
|
+
readonly default: string;
|
|
207
|
+
readonly gated?: Readonly<Record<string, string>>;
|
|
208
|
+
readonly deniedBy?: Readonly<Record<string, SettingFrom>>;
|
|
209
|
+
};
|
|
210
|
+
/** The providers a draft's decision node may name on this run, by id, as the check reads them (unrunnableNodes: the run's
|
|
211
|
+
* providers; gatedDecisions: deny alone refuses one). None when the run has no `decisions`, so a decision node is
|
|
212
|
+
* refused (LEARNED_NODES): the one place the rule is read, for the check and for what the reflect prompt allows. */
|
|
213
|
+
export declare const draftDecisionProviders: (decisions: DraftDecisions | undefined) => string[];
|
|
214
|
+
/** Each decision a draft asks, by the node that asks it (the DSL's inspection lists each node and its pointer, a composed
|
|
215
|
+
* workflow's inner ones too): its kind, its pointer and its provider's id, the one it names or else `fallback`, the
|
|
216
|
+
* run's default. A judge, pick or sift node; a route by question (not by value); a loop's or an escalate's ask
|
|
217
|
+
* predicate; a model node's verify (asked of the default). */
|
|
218
|
+
export declare function decisionsAsked(dsl: Pick<DraftReader, "inspectWorkflow">, doc: unknown, fallback: string): {
|
|
219
|
+
kind: string;
|
|
220
|
+
path: string;
|
|
221
|
+
provider: string;
|
|
222
|
+
}[];
|
|
223
|
+
/** What a decision node asking `provider` is refused with when the run's gate denies it, worded as a call node's tool is
|
|
224
|
+
* (gatedNodes), with the node's place. */
|
|
225
|
+
export declare const deniedDecisionWords: (provider: string, from: SettingFrom | undefined, kind: string, path: string) => string;
|
|
199
226
|
/** Where a deny was set (tool-gate.ts SettingFrom), and its words (tool-gate.ts denyPlace), kept here so the learn
|
|
200
227
|
* module needs no import of the gate. */
|
|
201
228
|
type SettingFrom = "agent" | "server" | "default";
|
|
@@ -236,7 +263,8 @@ export declare const LEARNED_MAX_TURNS = 8;
|
|
|
236
263
|
* `validateWorkflow` judges it, with `executeCode: false` so no code it holds is run (a code node is syntax-checked),
|
|
237
264
|
* and with `tools`, so a node that names a tool outside them is its error: a harness's own tool (Bash, exec_command,
|
|
238
265
|
* apply_patch) is never on the list. A model node that names any tool is refused (MODEL_NODE_TOOLS), and a node the
|
|
239
|
-
* learned runner cannot run (LEARNED_NODES: a judge's
|
|
266
|
+
* learned runner cannot run (LEARNED_NODES: a judge's on a run with no `decisions`; with them, one whose provider the run
|
|
267
|
+
* lacks or its gate holds to ask or deny). With no list it
|
|
240
268
|
* fails closed: a draft the DSL refuses only once given an empty list names a tool. */
|
|
241
269
|
/** The MCP tools set to ask a learned call would ask its approver about (`asked`, learnedDraftTools), and whether a card
|
|
242
270
|
* names them all (`fits`: learned-workflow.ts learnedAskFits, the gate's own rule, handed in so it is never copied). */
|
|
@@ -244,5 +272,5 @@ export type DraftAsk = {
|
|
|
244
272
|
readonly asked: readonly string[];
|
|
245
273
|
readonly fits: (asks: readonly string[]) => boolean;
|
|
246
274
|
};
|
|
247
|
-
export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, ask?: DraftAsk): DraftProblem[];
|
|
275
|
+
export declare function draftProblems(dsl: DraftReader, text: string, tools?: readonly string[], gated?: Readonly<Record<string, string>>, deniedBy?: Readonly<Record<string, SettingFrom>>, ask?: DraftAsk, decisions?: DraftDecisions): DraftProblem[];
|
|
248
276
|
export {};
|
package/dist/learn/skills.js
CHANGED
|
@@ -685,9 +685,52 @@ const toolingNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node)
|
|
|
685
685
|
/** What a learned draft whose output names no path is refused with. */
|
|
686
686
|
export const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
|
|
687
687
|
/** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
|
|
688
|
-
* runNode and
|
|
689
|
-
*
|
|
690
|
-
export const LEARNED_NODES = "a learned workflow runs model and tool-call nodes";
|
|
688
|
+
* runNode, runEffect, and runJudge only when the run has decision providers): a judge, pick or sift node, a route by
|
|
689
|
+
* question, a verify or an ask on a run with none. Refused at learn time and before a call runs any node, never after. */
|
|
690
|
+
export const LEARNED_NODES = "a learned workflow runs model and tool-call nodes, and decision nodes on a run with decision providers";
|
|
691
|
+
/** The providers a draft's decision node may name on this run, by id, as the check reads them (unrunnableNodes: the run's
|
|
692
|
+
* providers; gatedDecisions: deny alone refuses one). None when the run has no `decisions`, so a decision node is
|
|
693
|
+
* refused (LEARNED_NODES): the one place the rule is read, for the check and for what the reflect prompt allows. */
|
|
694
|
+
export const draftDecisionProviders = (decisions) => decisions ? Object.keys(decisions.providers).filter((id) => !Object.hasOwn(decisions.gated ?? {}, id) || decisions.gated[id] !== "deny") : [];
|
|
695
|
+
/** Each decision a draft asks, by the node that asks it (the DSL's inspection lists each node and its pointer, a composed
|
|
696
|
+
* workflow's inner ones too): its kind, its pointer and its provider's id, the one it names or else `fallback`, the
|
|
697
|
+
* run's default. A judge, pick or sift node; a route by question (not by value); a loop's or an escalate's ask
|
|
698
|
+
* predicate; a model node's verify (asked of the default). */
|
|
699
|
+
export function decisionsAsked(dsl, doc, fallback) {
|
|
700
|
+
return dsl.inspectWorkflow(doc).nodes.flatMap((node) => {
|
|
701
|
+
const fields = at(doc, node.path) ?? {};
|
|
702
|
+
const named = (choice) => {
|
|
703
|
+
const provider = choice?.provider;
|
|
704
|
+
return typeof provider === "string" ? provider : fallback;
|
|
705
|
+
};
|
|
706
|
+
const asked = (choice) => [{ kind: node.kind, path: node.path, provider: named(choice) }];
|
|
707
|
+
if (node.kind === "judge" || node.kind === "pick" || node.kind === "sift")
|
|
708
|
+
return asked(fields);
|
|
709
|
+
if (node.kind === "route" && typeof fields.valuePath !== "string")
|
|
710
|
+
return asked(fields);
|
|
711
|
+
if (node.kind === "loop" && fields.until?.predicate === "ask")
|
|
712
|
+
return asked(fields.until);
|
|
713
|
+
if (node.kind === "escalate" && fields.when?.predicate === "ask")
|
|
714
|
+
return asked(fields.when);
|
|
715
|
+
if (fields.verify && typeof fields.verify === "object")
|
|
716
|
+
return [{ kind: node.kind, path: node.path, provider: fallback }];
|
|
717
|
+
return [];
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
/** What a decision node asking `provider` is refused with when the run's gate denies it, worded as a call node's tool is
|
|
721
|
+
* (gatedNodes), with the node's place. */
|
|
722
|
+
export const deniedDecisionWords = (provider, from, kind, path) => `This workflow's decision node asks ${provider}, which is set to deny ${denyPlace(from)}. (the ${kind} node at ${path})`;
|
|
723
|
+
/** A draft's decision nodes whose provider the run's gate denies (`decisions.gated`): deny alone refuses, as the runner
|
|
724
|
+
* hands a claim a provider's keys while its gate's policy is not deny (a provider is a settings key that is allow or
|
|
725
|
+
* deny; a gate that reads no setting of it answers ask, which refuses nothing here). */
|
|
726
|
+
const gatedDecisions = (dsl, doc, decisions) => {
|
|
727
|
+
if (!decisions?.gated)
|
|
728
|
+
return [];
|
|
729
|
+
return decisionsAsked(dsl, doc, decisions.default).flatMap(({ kind, path, provider }) => {
|
|
730
|
+
const setting = Object.hasOwn(decisions.gated, provider) ? decisions.gated[provider] : undefined;
|
|
731
|
+
return setting === "deny" ? [{ rule: "workflow", detail: deniedDecisionWords(provider, decisions.deniedBy?.[provider], kind, path) }] : [];
|
|
732
|
+
});
|
|
733
|
+
};
|
|
691
734
|
const denyPlace = (from = "server") => (from === "agent" ? "for this agent" : from === "default" ? "by default" : "on this server");
|
|
692
735
|
/** A draft's call nodes that call a tool in `gated` (by name, what the gate holds it to: ask or deny), a composed
|
|
693
736
|
* workflow node's inner ones too (the DSL's inspection lists them, by their pointer under it): the run would park on it
|
|
@@ -813,9 +856,12 @@ const longNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node) =>
|
|
|
813
856
|
});
|
|
814
857
|
/** The node the learned runner cannot run, as the DSL's own check says it (assertWorkflowCapabilities, which runWorkflow
|
|
815
858
|
* makes before any node runs) with the runner's deps: none when it can run every one. */
|
|
816
|
-
const unrunnableNodes = (dsl, doc) => {
|
|
859
|
+
const unrunnableNodes = (dsl, doc, decisions) => {
|
|
817
860
|
const workflow = dsl.desugarWorkflow(doc);
|
|
818
|
-
|
|
861
|
+
// With the run's decision providers, a decision node is runnable when its provider is one of them and answers what it
|
|
862
|
+
// asks (the DSL's checkDecisionProviders): the same registry the call's judge is built on.
|
|
863
|
+
const judging = decisions ? { runJudge: async () => ({}), decisionProviders: { providers: decisions.providers, default: decisions.default } } : {};
|
|
864
|
+
const runner = { runNode: async () => ({}), runEffect: async () => ({}), ...judging };
|
|
819
865
|
try {
|
|
820
866
|
dsl.assertWorkflowCapabilities(workflow.root, runner, workflow);
|
|
821
867
|
return [];
|
|
@@ -828,7 +874,7 @@ const issuesOf = (dsl, doc, tools) => {
|
|
|
828
874
|
const valid = dsl.validateWorkflow(doc, { executeCode: false, ...(tools ? { tools } : {}) });
|
|
829
875
|
return valid.ok ? [] : valid.issues;
|
|
830
876
|
};
|
|
831
|
-
export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask) {
|
|
877
|
+
export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask, decisions) {
|
|
832
878
|
let doc;
|
|
833
879
|
try {
|
|
834
880
|
doc = JSON.parse(text);
|
|
@@ -844,7 +890,7 @@ export function draftProblems(dsl, text, tools, gated = {}, deniedBy = {}, ask)
|
|
|
844
890
|
return issues.slice(0, 5).map((issue) => ({ rule: "workflow", detail: `the workflow DSL refuses it: ${issue.code} at ${issue.path || "/"}: ${issue.message.slice(0, 200)}` }));
|
|
845
891
|
let out;
|
|
846
892
|
try {
|
|
847
|
-
out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
|
|
893
|
+
out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc, decisions), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated, deniedBy), ...gatedDecisions(dsl, doc, decisions), ...[...synthesisProblems(doc, dsl), ...loopProblems(doc)].map((detail) => ({ rule: "workflow", detail }))];
|
|
848
894
|
// A learned workflow answers the value at its output's path: one that names none would answer its whole state, which
|
|
849
895
|
// fails its output schema when the call ends, after every node spent.
|
|
850
896
|
const path = doc?.output?.path;
|
|
@@ -6,6 +6,11 @@ import { type Ledger } from "./paid-calls.js";
|
|
|
6
6
|
import type { Plane } from "./tool-plane.js";
|
|
7
7
|
import { type SettingFrom } from "./tool-gate.js";
|
|
8
8
|
import type { Complete } from "./llm.js";
|
|
9
|
+
import type { SearchOn } from "./web-search.js";
|
|
10
|
+
import type { Workspace } from "./workspace/workspace.js";
|
|
11
|
+
import type { DecisionProvider } from "@parcha/agentrun-dsl";
|
|
12
|
+
import type { Refusal } from "@parcha/agentrun-kernel";
|
|
13
|
+
import type { RunDecisions } from "@parcha/agentrun-kernel/kernel/cap";
|
|
9
14
|
/** What a learned_workflow call's approval card says of its MCP calls' arguments: the workflow decides them as it runs. */
|
|
10
15
|
export declare const LEARNED_MCP_ARGUMENTS = "decided by the workflow while it runs, from its input and its earlier steps";
|
|
11
16
|
/** What a learned_workflow call's card shows of the MCP tools set to ask that the workflow can call: that their arguments
|
|
@@ -61,6 +66,9 @@ export type LearnedWorkflowRun = {
|
|
|
61
66
|
modelName?(tier: string | undefined): string | undefined;
|
|
62
67
|
/** The `llm` tool's completion, for a call node that names it. */
|
|
63
68
|
complete?: Complete;
|
|
69
|
+
/** The run's models a call node's native web_search goes through (EffectRun.search): on the runner, the session's
|
|
70
|
+
* port. */
|
|
71
|
+
search?: SearchOn;
|
|
64
72
|
/** The run's gate's permission of a tool now (tool-gate.ts RunGate policy): a call node's tool set to ask or deny is
|
|
65
73
|
* refused before any node runs, and asked again as each call node runs, a composed workflow's inner ones too, so one
|
|
66
74
|
* set to either since the call began is refused there, never run. Required: a learned workflow never runs a tool
|
|
@@ -73,6 +81,22 @@ export type LearnedWorkflowRun = {
|
|
|
73
81
|
* each call node runs, before `policy` is asked: a tool set to deny since the call began is then refused. None: the
|
|
74
82
|
* gate reads its settings live (main's process). */
|
|
75
83
|
refresh?: () => Promise<void>;
|
|
84
|
+
/** The run's own Workspace (on the runner: its local folder in Mode 1, its folder on the run's disk in Mode 2), which
|
|
85
|
+
* a decision node's images are read through. Absent: the local folder at `work`. */
|
|
86
|
+
workspace?: Workspace;
|
|
87
|
+
/** The run's decisions (LS-07): its decision providers (decisions.ts decisionProvidersIn over the run's keys) and the
|
|
88
|
+
* one a node that names none is asked of; `book`, the run's decisions on its one cap (the adapter loop's
|
|
89
|
+
* ledger.decisions: DECISION_SESSION); `pause`, the run's pause on a refusal of that cap (ledger.pause), so its next
|
|
90
|
+
* request is refused in the cap's words and the run parks there. None: a decision node is refused before any node
|
|
91
|
+
* runs. */
|
|
92
|
+
decisions?: {
|
|
93
|
+
readonly providers: {
|
|
94
|
+
readonly providers: Readonly<Record<string, DecisionProvider>>;
|
|
95
|
+
readonly default: string;
|
|
96
|
+
};
|
|
97
|
+
readonly book: RunDecisions;
|
|
98
|
+
readonly pause?: (refusal: Refusal) => Promise<void>;
|
|
99
|
+
};
|
|
76
100
|
/** The run's MCP tools by catalog name (`mcp:<server>/<tool>`): those the claim's pin holds, which its revision grants.
|
|
77
101
|
* A call node may name one of these; it runs through the run's own MCP, as the loop wrapped it (host-calls.ts). */
|
|
78
102
|
mcpTools?: readonly string[];
|
package/dist/learned-workflow.js
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
// its paid requests booked under the tool's call (paid-calls.ts), each node's under a call of its own; web_search
|
|
13
13
|
// where it resolves native on the provider's hosted search through the run's models (hosted-search.ts), on a harness
|
|
14
14
|
// whose own search it is too (harness-app.ts gives that harness no host tool of the name).
|
|
15
|
+
// - a decision node (judge, pick, sift, a route by question, an ask predicate, a verify: LS-07), on a run handed its
|
|
16
|
+
// decisions (`run.decisions`: its decision providers on its own keys, and the adapter loop's ledger.decisions on
|
|
17
|
+
// the run's one cap), asked of the provider it names, else the run's default, held to the run's gate under that
|
|
18
|
+
// provider's bare id (tool-plane.ts DECISION_PROVIDER_KEYS: allow or deny), refused only on deny; each admitted on the run's cap before it is sent, priced as a
|
|
19
|
+
// workflow agent's decision is (runner/workflow-spec.ts decisionJudge), settled at what it charged, and one the cap
|
|
20
|
+
// has no room for never sent, the run paused on the cap's refusal (ledger.pause). A run handed none runs no
|
|
21
|
+
// decision node: the check refuses it before any node runs.
|
|
15
22
|
// Each model request is a request on the run's one route, so what the workflow spends is the run's cost, under its cap:
|
|
16
23
|
// on pi the run's models, as a side request (request-start.ts, cap.ts: marked, and costed on the run's timeline as
|
|
17
24
|
// `learned_workflow`); on another harness the session's model proxy, under a side key (port-models.ts): the harness's
|
|
@@ -23,6 +30,8 @@ import { registerLabel, registerOutcome } from "./timeline/index.js";
|
|
|
23
30
|
import { sideRequests } from "./cap.js";
|
|
24
31
|
import { LEARNED_NODES, LEARNED_NODES_MAX } from "./learned-nodes.js";
|
|
25
32
|
import { draftProblems, LEARNED_MAX_TURNS } from "./learn/index.js";
|
|
33
|
+
import { decisionsAsked, deniedDecisionWords } from "./learn/skills.js";
|
|
34
|
+
import { DEFAULT_DECISION_PROVIDER } from "./decisions.js";
|
|
26
35
|
import { workflowLine } from "./learning.js";
|
|
27
36
|
import { ledgerOf } from "./paid-calls.js";
|
|
28
37
|
import { PORT_PROVIDER } from "./port-models.js";
|
|
@@ -259,10 +268,11 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
|
|
|
259
268
|
deniedBy[name] = run.denyFrom(name);
|
|
260
269
|
}
|
|
261
270
|
}
|
|
262
|
-
const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy);
|
|
271
|
+
const problems = draftProblems(dsl, flow.workflow, tools, gated, deniedBy, undefined, decisionsOf(run, dsl, flow.workflow));
|
|
263
272
|
if (problems.length)
|
|
264
273
|
return refuse(problems.map(({ detail }) => detail).join("; "));
|
|
265
274
|
const doc = JSON.parse(flow.workflow);
|
|
275
|
+
const runJudge = run.decisions ? await learnedJudge(run, run.decisions) : undefined;
|
|
266
276
|
// The host runner loads @earendil-works/pi-coding-agent and pi-agent-core, serve's own dependencies (package.json).
|
|
267
277
|
const { createPiHostRunner } = await import("./workflow/host-session.js");
|
|
268
278
|
const runners = new Map();
|
|
@@ -337,7 +347,7 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
|
|
|
337
347
|
throw new Error(`This ${tool} call needs a person's approval, which a workflow's call node cannot wait for; it was not run.`);
|
|
338
348
|
// Its paid requests booked under the tool's call, as a call of its own: the node, its execution path, its item in a map.
|
|
339
349
|
const booked = ledger ? { ledger: { call: callId, record: ledger.record } } : {};
|
|
340
|
-
return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...booked });
|
|
350
|
+
return effect(given, { signal: own, env: run.env, work: run.work, ...(run.complete ? { complete: run.complete } : {}), ...(run.search ? { search: run.search } : {}), ...booked });
|
|
341
351
|
};
|
|
342
352
|
// Each node as it ends, by the DSL's own event: what the call's timeline row shows of it.
|
|
343
353
|
const onEvent = (event) => {
|
|
@@ -348,7 +358,8 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
|
|
|
348
358
|
nodes.push({ label: String(event.label), kind: String(detail.kind ?? ""), status: String(detail.status ?? ""), duration_ms: typeof detail.duration_ms === "number" ? detail.duration_ms : 0, ...ran });
|
|
349
359
|
};
|
|
350
360
|
try {
|
|
351
|
-
const
|
|
361
|
+
const judging = runJudge && run.decisions ? { runJudge, decisionProviders: run.decisions.providers } : {};
|
|
362
|
+
const result = await dsl.runWorkflow(doc, input, { runNode: runNode, runEffect: runEffect, onEvent, ...judging, ...(signal ? { signal } : {}) });
|
|
352
363
|
if (result.status !== "complete")
|
|
353
364
|
return refuse(`it ended ${result.status}`);
|
|
354
365
|
return { text: learnedText(learnedOutput(result.output)), isError: false, nodes };
|
|
@@ -359,3 +370,55 @@ export async function runLearned(run, flow, input, signal, ledger, nodes = []) {
|
|
|
359
370
|
return { text: `The learned workflow ${flow.name} failed: ${String(error?.message ?? error).slice(0, 1000)}`, isError: true, nodes };
|
|
360
371
|
}
|
|
361
372
|
}
|
|
373
|
+
/** The draft check's decisions for `run` (learn/skills.ts DraftDecisions): its providers, and the gate's setting of each
|
|
374
|
+
* provider `text` asks (its bare id as the settings key) where it is not allow, with where a deny was set. A run handed
|
|
375
|
+
* no decisions (its claim was handed no key: none named, or each denied) has no provider, so a decision node is refused
|
|
376
|
+
* in the gate's words when its provider is denied, else as one the host does not have; never asked. */
|
|
377
|
+
function decisionsOf(run, dsl, text) {
|
|
378
|
+
const providers = run.decisions?.providers ?? { providers: {}, default: DEFAULT_DECISION_PROVIDER };
|
|
379
|
+
const gated = {};
|
|
380
|
+
// A deny comes from a layer or the default, never from approvals (learnedDraftTools' rule).
|
|
381
|
+
const deniedBy = {};
|
|
382
|
+
let doc;
|
|
383
|
+
try {
|
|
384
|
+
doc = JSON.parse(text);
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return { providers: providers.providers, default: providers.default };
|
|
388
|
+
}
|
|
389
|
+
for (const { provider } of decisionsAsked(dsl, doc, providers.default)) {
|
|
390
|
+
const setting = run.policy(provider);
|
|
391
|
+
if (setting === "allow")
|
|
392
|
+
continue;
|
|
393
|
+
gated[provider] = setting;
|
|
394
|
+
if (setting === "deny")
|
|
395
|
+
deniedBy[provider] = run.denyFrom(provider);
|
|
396
|
+
}
|
|
397
|
+
return { providers: providers.providers, default: providers.default, gated, deniedBy };
|
|
398
|
+
}
|
|
399
|
+
/** A learned workflow's judge (the DSL's runJudge) for `run`: its providers' judge (judgeFromProviders), each decision
|
|
400
|
+
* first held to the run's gate as it is asked (a provider set to deny since the call began is refused, never sent, as
|
|
401
|
+
* a call node's tool is at its effect; deny alone refuses, the rule the runner hands a claim its keys by), then admitted on the run's one cap and settled at what it charged
|
|
402
|
+
* (decisionJudge, as a workflow agent's decision is). A refusal of the cap pauses the run (`decisions.pause`): the
|
|
403
|
+
* decision node fails with the cap's words, and nothing is sent. */
|
|
404
|
+
async function learnedJudge(run, decisions) {
|
|
405
|
+
const [{ judgeFromProviders }, { decisionJudge }, { imageLoader }] = await Promise.all([import("@parcha/agentrun-dsl"), import("./runner/workflow-spec.js"), import("./pdf-pages.js")]);
|
|
406
|
+
// A decision node's images (a page drawn by pdf_pages, a screenshot, an upload) are read through the run's own Workspace
|
|
407
|
+
// (Mode 2: its folder on the run's disk, never the runner's local path), as a workflow agent's are (pdf-pages.ts
|
|
408
|
+
// imageLoader).
|
|
409
|
+
const inner = judgeFromProviders({ providers: decisions.providers.providers, default: decisions.providers.default, loadImage: imageLoader(run.workspace ?? run.work) });
|
|
410
|
+
const capped = decisionJudge(inner, {
|
|
411
|
+
getCap: () => decisions.book,
|
|
412
|
+
providers: decisions.providers,
|
|
413
|
+
park: (refusal) => {
|
|
414
|
+
void decisions.pause?.({ refuse: refusal.message, forGood: refusal.forGood, code: "spend_cap_reached", ...(refusal.figures ? { figures: refusal.figures } : {}) });
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
return (async (params) => {
|
|
418
|
+
const provider = params.provider ?? decisions.providers.default;
|
|
419
|
+
await run.refresh?.();
|
|
420
|
+
if (run.policy(provider) === "deny")
|
|
421
|
+
throw new Error(deniedDecisionWords(provider, run.denyFrom(provider), "decision", params.label));
|
|
422
|
+
return capped(params);
|
|
423
|
+
});
|
|
424
|
+
}
|