@parcha/agentrun-serve 0.1.0-beta.33 → 0.1.0-beta.34
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 +233 -0
- package/README.md +266 -201
- package/dist/adapters.d.ts +0 -4
- package/dist/adapters.js +11 -15
- package/dist/agent-rows.d.ts +98 -0
- package/dist/agent-rows.js +1 -0
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +60 -25
- package/dist/agents.d.ts +9 -125
- package/dist/agents.js +15 -305
- package/dist/answer-json.d.ts +23 -0
- package/dist/answer-json.js +58 -0
- package/dist/api-only.d.ts +1 -1
- package/dist/api-only.js +2 -2
- package/dist/bash-read-only.d.ts +22 -0
- package/dist/bash-read-only.js +701 -0
- package/dist/box-settings.d.ts +3 -23
- package/dist/box-settings.js +7 -51
- package/dist/boxes.d.ts +17 -0
- package/dist/boxes.js +27 -20
- package/dist/browser-commands.d.ts +5 -2
- package/dist/browser-commands.js +4 -4
- package/dist/browser-computer.d.ts +5 -0
- package/dist/browser-computer.js +21 -0
- package/dist/browser-cost.d.ts +9 -6
- package/dist/browser-cost.js +92 -50
- package/dist/browser-live.d.ts +7 -20
- package/dist/browser-live.js +15 -93
- package/dist/browser-person.d.ts +18 -51
- package/dist/browser-person.js +94 -277
- package/dist/cap.d.ts +8 -5
- package/dist/cap.js +12 -5
- package/dist/cli.js +39 -13
- package/dist/closed-pipes.d.ts +2 -0
- package/dist/closed-pipes.js +13 -0
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +2 -0
- package/dist/computer-keys.js +5 -2
- package/dist/computer-setting.d.ts +20 -4
- package/dist/computer-setting.js +25 -5
- package/dist/computers.d.ts +30 -2
- package/dist/computers.js +70 -11
- package/dist/confine.d.ts +120 -0
- package/dist/confine.js +436 -0
- package/dist/console/assets/index-RPHGlXmM.js +540 -0
- package/dist/console/assets/index-opTN5Naq.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/decision-rows.d.ts +1 -1
- package/dist/decision-rows.js +1 -1
- package/dist/docker-daemon.d.ts +31 -0
- package/dist/docker-daemon.js +56 -0
- package/dist/effort-guidance.js +4 -3
- package/dist/environment.d.ts +0 -3
- package/dist/environment.js +3 -5
- package/dist/errors.d.ts +0 -2
- package/dist/errors.js +6 -9
- package/dist/filed-answer.d.ts +32 -0
- package/dist/filed-answer.js +160 -0
- package/dist/files.d.ts +1 -3
- package/dist/files.js +2 -4
- package/dist/github-connection.d.ts +1 -1
- package/dist/graph-view.d.ts +3 -5
- package/dist/graph-view.js +4 -14
- package/dist/handed-values.d.ts +9 -0
- package/dist/handed-values.js +26 -0
- package/dist/harness-install.d.ts +1 -7
- package/dist/harness-install.js +1 -18
- package/dist/harness-opencode/adapter.d.ts +7 -0
- package/dist/harness-opencode/adapter.js +23 -6
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/verify.d.ts +17 -0
- package/dist/harness-opencode/verify.js +30 -10
- package/dist/harness-table.js +6 -1
- package/dist/heard.js +1 -1
- package/dist/held-fd.d.ts +5 -0
- package/dist/held-fd.js +14 -0
- package/dist/host-calls.d.ts +20 -0
- package/dist/host-calls.js +12 -0
- package/dist/host-tools.d.ts +4 -21
- package/dist/host-tools.js +4 -61
- package/dist/host.d.ts +2 -4
- package/dist/host.js +2 -7
- package/dist/import-summary.d.ts +1 -5
- package/dist/import-summary.js +0 -21
- package/dist/import.d.ts +6 -6
- package/dist/import.js +14 -15
- package/dist/key-refusal.d.ts +5 -1
- package/dist/key-refusal.js +19 -4
- package/dist/learn/check.d.ts +6 -2
- package/dist/learn/check.js +83 -29
- package/dist/learn/folder.d.ts +5 -1
- package/dist/learn/folder.js +10 -3
- package/dist/learn/grade.d.ts +14 -0
- package/dist/learn/grade.js +68 -12
- package/dist/learn/index.d.ts +4 -4
- package/dist/learn/index.js +4 -4
- package/dist/learn/reflect.d.ts +31 -2
- package/dist/learn/reflect.js +79 -4
- package/dist/learn/relevance.d.ts +24 -0
- package/dist/learn/relevance.js +91 -0
- package/dist/learn/secrets.d.ts +7 -1
- package/dist/learn/secrets.js +86 -19
- package/dist/learn/skills.d.ts +112 -14
- package/dist/learn/skills.js +556 -52
- package/dist/learned-workflow.d.ts +32 -1
- package/dist/learned-workflow.js +100 -9
- package/dist/learning-routes.d.ts +8 -4
- package/dist/learning-routes.js +23 -9
- package/dist/learning-run.d.ts +9 -26
- package/dist/learning-run.js +22 -32
- package/dist/learning-words.d.ts +12 -5
- package/dist/learning-words.js +18 -9
- package/dist/learning.d.ts +93 -77
- package/dist/learning.js +176 -304
- package/dist/live/stream.js +1 -1
- package/dist/live/translate.js +12 -2
- package/dist/local-models.d.ts +11 -5
- package/dist/local-models.js +13 -8
- package/dist/mcp-gateway.d.ts +11 -49
- package/dist/mcp-gateway.js +44 -135
- package/dist/mcp-oauth.d.ts +10 -14
- package/dist/mcp-oauth.js +14 -32
- package/dist/mcp-probe.d.ts +0 -7
- package/dist/mcp-probe.js +4 -10
- package/dist/mcp-servers-store.d.ts +6 -6
- package/dist/mcp-servers-store.js +12 -14
- package/dist/mcp-store.js +3 -4
- package/dist/mcp.js +4 -3
- package/dist/model.d.ts +6 -7
- package/dist/model.js +43 -27
- package/dist/monid.d.ts +0 -2
- package/dist/monid.js +3 -6
- package/dist/openapi.d.ts +8 -1
- package/dist/openapi.js +121 -47
- package/dist/page.d.ts +1 -3
- package/dist/page.js +6 -18
- package/dist/paid-calls.d.ts +21 -27
- package/dist/paid-calls.js +25 -60
- package/dist/propose.js +83 -39
- package/dist/push-handler.d.ts +1 -1
- package/dist/reflect-range.d.ts +25 -0
- package/dist/reflect-range.js +30 -0
- package/dist/refusal-words.d.ts +5 -1
- package/dist/refusal-words.js +5 -1
- package/dist/rows.d.ts +1 -1
- package/dist/run-cut.d.ts +0 -6
- package/dist/run-cut.js +0 -6
- package/dist/run-db.d.ts +2 -11
- package/dist/run-db.js +2 -37
- package/dist/run-launch.d.ts +19 -2
- package/dist/run-launch.js +13 -5
- package/dist/run-learning-served.d.ts +10 -4
- package/dist/run-learning-served.js +23 -13
- package/dist/run-reads-over-store.d.ts +1 -1
- package/dist/run-reads-over-store.js +15 -6
- package/dist/run-secrets.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +5 -1
- package/dist/run-timeline-served.js +15 -4
- package/dist/run-view.d.ts +7 -8
- package/dist/run-view.js +26 -7
- package/dist/runnable.d.ts +18 -10
- package/dist/runnable.js +21 -10
- package/dist/runner/adapter-loop.d.ts +6 -1
- package/dist/runner/adapter-loop.js +423 -53
- package/dist/runner/adapter-run-spec.d.ts +21 -8
- package/dist/runner/adapter-run-spec.js +90 -32
- package/dist/runner/adapters/index.js +11 -1
- package/dist/runner/adapters/pi.d.ts +12 -2
- package/dist/runner/adapters/pi.js +16 -5
- package/dist/runner/beside.d.ts +30 -3
- package/dist/runner/beside.js +36 -5
- package/dist/runner/claim-secrets.d.ts +10 -1
- package/dist/runner/claim-secrets.js +48 -14
- package/dist/runner/cli-run-spec.d.ts +2 -0
- package/dist/runner/cli-run-spec.js +45 -16
- package/dist/runner/commands.js +1 -1
- package/dist/runner/computer-journal.d.ts +15 -2
- package/dist/runner/computer-journal.js +41 -5
- package/dist/runner/conformance/harness.js +118 -8
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/dispatch.d.ts +8 -1
- package/dist/runner/dispatch.js +81 -7
- package/dist/runner/end-of-run.d.ts +8 -2
- package/dist/runner/end-of-run.js +10 -4
- package/dist/runner/github-app.js +1 -1
- package/dist/runner/harness-loops.d.ts +9 -1
- package/dist/runner/harness-loops.js +15 -2
- package/dist/runner/journal-kinds.d.ts +24 -6
- package/dist/runner/journal-kinds.js +20 -5
- package/dist/runner/journal-reader.d.ts +1 -1
- package/dist/runner/journal-reader.js +2 -2
- package/dist/runner/learning-ask.d.ts +4 -0
- package/dist/runner/learning-ask.js +15 -1
- package/dist/runner/learning-end.d.ts +18 -3
- package/dist/runner/learning-end.js +113 -11
- package/dist/runner/learning-loop.d.ts +5 -0
- package/dist/runner/learning-loop.js +26 -6
- package/dist/runner/main.d.ts +56 -9
- package/dist/runner/main.js +127 -18
- package/dist/runner/mcp-claim.js +1 -2
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +15 -5
- package/dist/runner/memory-claim.d.ts +9 -0
- package/dist/runner/memory-claim.js +25 -0
- package/dist/runner/metrics.d.ts +33 -1
- package/dist/runner/metrics.js +85 -1
- package/dist/runner/model-route.d.ts +13 -0
- package/dist/runner/model-route.js +133 -9
- package/dist/runner/reflect-hook.d.ts +12 -1
- package/dist/runner/reflect-hook.js +33 -3
- package/dist/runner/runner.d.ts +20 -0
- package/dist/runner/runner.js +56 -10
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +3 -3
- package/dist/runner/store-secrets.js +8 -12
- package/dist/runner/text-tools.d.ts +44 -0
- package/dist/runner/text-tools.js +237 -0
- package/dist/runner/workflow-loop.d.ts +6 -0
- package/dist/runner/workflow-loop.js +6 -4
- package/dist/runner/workflow-spec.d.ts +18 -0
- package/dist/runner/workflow-spec.js +63 -17
- package/dist/runs-over-store.d.ts +7 -2
- package/dist/runs-over-store.js +60 -14
- package/dist/seal-key.js +5 -43
- package/dist/sealed-settings-store.d.ts +19 -4
- package/dist/sealed-settings-store.js +9 -9
- package/dist/sealing.d.ts +4 -0
- package/dist/sealing.js +20 -0
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/secret-name.d.ts +9 -0
- package/dist/secret-name.js +15 -0
- package/dist/secret-writes.d.ts +0 -1
- package/dist/secret-writes.js +0 -1
- package/dist/server-fs.d.ts +4 -0
- package/dist/server-fs.js +8 -2
- package/dist/server-lock.d.ts +0 -24
- package/dist/server-lock.js +1 -80
- package/dist/server-secrets-store.d.ts +4 -4
- package/dist/server-secrets-store.js +9 -31
- package/dist/server-secrets.d.ts +4 -9
- package/dist/server-secrets.js +12 -36
- package/dist/server.d.ts +16 -38
- package/dist/server.js +145 -106
- package/dist/sign-ins-store.d.ts +34 -36
- package/dist/sign-ins-store.js +27 -38
- package/dist/sign-ins.d.ts +2 -119
- package/dist/sign-ins.js +5 -311
- package/dist/standard-webhooks.d.ts +1 -1
- package/dist/standard-webhooks.js +1 -1
- package/dist/stats.d.ts +3 -2
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +8 -2
- package/dist/store/agent-body.js +16 -4
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +2 -2
- package/dist/store/open.d.ts +6 -3
- package/dist/store/open.js +2 -2
- package/dist/store/postgres/connection.d.ts +18 -2
- package/dist/store/postgres/connection.js +156 -32
- package/dist/store/postgres/migrate.d.ts +4 -0
- package/dist/store/postgres/migrate.js +9 -2
- package/dist/store/postgres/migrations/0003_commands_one_answer.check.sql +19 -0
- package/dist/store/postgres/migrations/0003_commands_one_answer.sql +13 -0
- package/dist/store/postgres/store.d.ts +9 -2
- package/dist/store/postgres/store.js +9 -0
- package/dist/store/schema.js +1 -1
- package/dist/store/seal.js +2 -2
- package/dist/store/sqlite/connection.js +49 -5
- package/dist/store/sqlite/run-patch.d.ts +3 -0
- package/dist/store/sqlite/run-patch.js +3 -0
- package/dist/store/sqlite/store.js +41 -12
- package/dist/store/store.d.ts +35 -6
- package/dist/store/store.js +12 -2
- package/dist/store-reads/cap.d.ts +1 -1
- package/dist/store-reads/cap.js +22 -4
- package/dist/store-reads/journal.d.ts +9 -6
- package/dist/store-reads/journal.js +93 -17
- package/dist/store-reads/learning.d.ts +26 -8
- package/dist/store-reads/learning.js +12 -4
- package/dist/store-reads/workflow.d.ts +1 -1
- package/dist/store-reads/workflow.js +1 -1
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +53 -18
- package/dist/template-eval.d.ts +60 -4
- package/dist/template-eval.js +120 -54
- package/dist/templates.d.ts +24 -10
- package/dist/templates.js +69 -38
- package/dist/timeline/group.d.ts +33 -0
- package/dist/timeline/group.js +77 -0
- package/dist/timeline/index.d.ts +7 -0
- package/dist/timeline/index.js +7 -0
- package/dist/timeline/labels.d.ts +79 -0
- package/dist/timeline/labels.js +150 -0
- package/dist/timeline/origin.d.ts +56 -0
- package/dist/timeline/origin.js +92 -0
- package/dist/timeline/render-text.d.ts +11 -0
- package/dist/timeline/render-text.js +62 -0
- package/dist/timeline/timeline.d.ts +274 -0
- package/dist/timeline/timeline.js +1308 -0
- package/dist/timeline/util.d.ts +17 -0
- package/dist/timeline/util.js +49 -0
- package/dist/tool-gate.d.ts +41 -216
- package/dist/tool-gate.js +79 -540
- package/dist/tool-keys-store.d.ts +11 -12
- package/dist/tool-keys-store.js +24 -31
- package/dist/tool-keys.d.ts +5 -101
- package/dist/tool-keys.js +8 -267
- package/dist/tool-plane.d.ts +14 -42
- package/dist/tool-plane.js +23 -81
- package/dist/tool-settings-store.d.ts +1 -2
- package/dist/tool-settings-store.js +5 -8
- package/dist/tools.d.ts +30 -18
- package/dist/tools.js +97 -107
- package/dist/trigger-adapter.d.ts +2 -2
- package/dist/trigger-targets.d.ts +13 -1
- package/dist/trigger-targets.js +31 -1
- package/dist/triggers.d.ts +2 -2
- package/dist/triggers.js +3 -3
- package/dist/turn-end.d.ts +1 -1
- package/dist/turn-end.js +1 -1
- package/dist/turns.d.ts +0 -6
- package/dist/turns.js +0 -19
- package/dist/uploads.js +1 -1
- package/dist/usage.d.ts +0 -2
- package/dist/usage.js +0 -2
- package/dist/validate.d.ts +2 -0
- package/dist/validate.js +23 -14
- package/dist/webhooks.d.ts +102 -76
- package/dist/webhooks.js +266 -233
- package/dist/workflow-run.d.ts +114 -0
- package/dist/workflow-run.js +144 -0
- package/dist/workspace/beneath.d.ts +19 -0
- package/dist/workspace/beneath.js +106 -0
- package/dist/workspace/computer-deps.d.ts +24 -6
- package/dist/workspace/computer-deps.js +108 -20
- package/dist/workspace/computer-for-claim.d.ts +12 -11
- package/dist/workspace/computer-for-claim.js +76 -15
- package/dist/workspace/computer-hold.d.ts +6 -1
- package/dist/workspace/computer-hold.js +6 -1
- package/dist/workspace/computer-janitor.d.ts +47 -0
- package/dist/workspace/computer-janitor.js +182 -0
- package/dist/workspace/grep-worker.d.ts +5 -0
- package/dist/workspace/grep-worker.js +9 -6
- package/dist/workspace/index.d.ts +3 -2
- package/dist/workspace/index.js +3 -3
- package/dist/workspace/local.d.ts +11 -2
- package/dist/workspace/local.js +161 -43
- package/dist/workspace/resolve-computer.d.ts +50 -10
- package/dist/workspace/resolve-computer.js +46 -11
- package/dist/workspace/run-tools.d.ts +13 -31
- package/dist/workspace/run-tools.js +10 -27
- package/dist/workspace-paths.d.ts +0 -17
- package/dist/workspace-paths.js +1 -41
- package/dist/workspace.d.ts +0 -14
- package/dist/workspace.js +3 -96
- package/package.json +13 -13
- package/templates/README.md +9 -3
- package/templates/market-monitor/agent.md +2 -2
- package/templates/market-monitor/skills/monitor/SKILL.md +6 -4
- package/dist/bound-files.d.ts +0 -4
- package/dist/bound-files.js +0 -164
- package/dist/coding-tools.d.ts +0 -47
- package/dist/coding-tools.js +0 -189
- package/dist/computer-adb.d.ts +0 -12
- package/dist/computer-adb.js +0 -14
- package/dist/console/assets/index-Dn0ngwG9.js +0 -535
- package/dist/console/assets/index-DvW6Aled.css +0 -1
- package/dist/grade.d.ts +0 -63
- package/dist/grade.js +0 -150
- package/dist/mcp-servers.d.ts +0 -269
- package/dist/mcp-servers.js +0 -456
- package/dist/packs.d.ts +0 -71
- package/dist/packs.js +0 -180
- package/dist/sealed-settings.d.ts +0 -60
- package/dist/sealed-settings.js +0 -171
- package/dist/sessions.d.ts +0 -6
- package/dist/sessions.js +0 -109
- package/dist/workspace/computer-serves.d.ts +0 -12
- package/dist/workspace/computer-serves.js +0 -15
package/dist/live/stream.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// stored commit (live/translate.ts), in commit order, each batch naming its commit's seq so a reader that comes back
|
|
4
4
|
// resumes from it; and beside them, never inside a commit's batch, what the runner holds before pi stores it (the run's
|
|
5
5
|
// run_live row: a running tool, a partial answer), in the same vocabulary.
|
|
6
|
-
import { RUN_RESUMED } from "
|
|
6
|
+
import { RUN_RESUMED } from "../timeline/index.js";
|
|
7
7
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
8
8
|
import { FINAL_STATES } from "../store/store.js";
|
|
9
9
|
import { emptyState, snapshotOf, translate } from "./translate.js";
|
package/dist/live/translate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AgentDoc, UsageDoc } from "@earendil-works/pi-durable";
|
|
2
|
-
import { HOST_PHASE, RUN_RESUMED } from "
|
|
2
|
+
import { HOST_PHASE, RUN_RESUMED } from "../timeline/index.js";
|
|
3
3
|
import { REFLECT_LABEL, reflectFrom } from "../runner/end-of-run.js";
|
|
4
4
|
import { KINDS } from "../runner/journal-kinds.js";
|
|
5
5
|
import { PI_STOP } from "../runner/pi-stop.js";
|
|
@@ -107,7 +107,7 @@ export function translate(state, commit) {
|
|
|
107
107
|
const tasks = commit.tasks.filter(mine);
|
|
108
108
|
const submissions = commit.submissions.filter(mine);
|
|
109
109
|
// The end-of-run turn's input placed in this commit: its messages from there on are the turn's.
|
|
110
|
-
state.reflectFrom ??= reflectFrom(submissions);
|
|
110
|
+
state.reflectFrom ??= reflectFrom(submissions, entries);
|
|
111
111
|
const tag = (entry) => (state.reflectFrom !== undefined && Number(entry.id) >= state.reflectFrom ? { agent_label: REFLECT_LABEL } : {});
|
|
112
112
|
for (const entry of entries) {
|
|
113
113
|
const message = modelOf(entry);
|
|
@@ -177,6 +177,16 @@ export function translate(state, commit) {
|
|
|
177
177
|
events.push({ type: "message_start", message, ...tag(entry) }, { type: "message_end", entry: synthetic, ...tag(entry) });
|
|
178
178
|
continue;
|
|
179
179
|
}
|
|
180
|
+
if (entry.kind === KINDS.endOfRunTurn && dataOf(entry).role === "person") {
|
|
181
|
+
// A CLI run's end-of-run turn asked (adapter-loop.ts answering): its prompt, in a commit of its own, is the turn's
|
|
182
|
+
// message, as a pi run's placed input is, so a stream already open shows the turn at once.
|
|
183
|
+
const text = dataOf(entry).text;
|
|
184
|
+
const message = { role: "user", content: typeof text === "string" ? text : "" };
|
|
185
|
+
const synthetic = { ...entry, model: [message] };
|
|
186
|
+
state.entries.push(synthetic);
|
|
187
|
+
events.push({ type: "message_start", message, ...tag(entry) }, { type: "message_end", entry: synthetic, ...tag(entry) });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
180
190
|
if (entry.kind === KINDS.end) {
|
|
181
191
|
// A person's stop (the only stop a loop ends a run on: a lost claim or a shutdown writes no end): one phase row,
|
|
182
192
|
// worded the same on every harness, from the loop's own end entry.
|
package/dist/local-models.d.ts
CHANGED
|
@@ -7,17 +7,23 @@ export declare const PARTICLE_1_PRICE: {
|
|
|
7
7
|
readonly cacheRead: 0.03;
|
|
8
8
|
readonly cacheWrite: 0;
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
10
|
+
/** How a model takes its tools: "native", the request's own tools parameter (every model pi-ai lists), or "text", the
|
|
11
|
+
* tools described in its system prompt and its calls read back from its reply (runner/text-tools.ts, on the runner's
|
|
12
|
+
* translated route, runner/model-route.ts). A wire format of the model's provider, not a choice of a task's. */
|
|
13
|
+
export type ToolsAs = "native" | "text";
|
|
14
|
+
/** What serve sets over pi-ai's own catalog entries, by provider and id: a price (`cost`), and how the model takes its
|
|
15
|
+
* tools (`toolsAs`, absent: native). pi-ai 1.5.0 lists particle-ai/particle-1 at
|
|
11
16
|
* OpenRouter's current promotional price ($0.05 input, $0.003 cache read, $0.50 output). A run's cap holds each request
|
|
12
17
|
* at its worst case, priced from the catalog, before it is sent, and a hold must never price below what can be billed:
|
|
13
|
-
* the promotion can end before the catalog follows. So the hold takes Particle's list price
|
|
14
|
-
*
|
|
15
|
-
*
|
|
18
|
+
* the promotion can end before the catalog follows. So the hold takes Particle's list price, and so does the booking:
|
|
19
|
+
* a request that answers is booked at pi-ai's calculateCost on this same catalog entry, its list price, not at what
|
|
20
|
+
* OpenRouter bills during the promotion. */
|
|
16
21
|
export declare const PRICE_OVERRIDES: readonly {
|
|
17
22
|
readonly provider: string;
|
|
18
23
|
readonly id: string;
|
|
19
24
|
readonly cost: Model<Api>["cost"];
|
|
25
|
+
readonly toolsAs?: ToolsAs;
|
|
20
26
|
}[];
|
|
21
27
|
/** `models` (pi-ai's built-in catalog, or one built on it) with PRICE_OVERRIDES set on their providers' own entries, in
|
|
22
|
-
* place: a request, a price and a capability read find the catalog's entry at the overridden price. */
|
|
28
|
+
* place: a request, a price and a capability read find the catalog's entry at the overridden price, with its toolsAs. */
|
|
23
29
|
export declare function withLocalModels<M extends MutableModels>(models: M): M;
|
package/dist/local-models.js
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
/** Particle-1's price, USD per million tokens: Particle's own list price, from https://docs.particle.ai/models (read
|
|
2
2
|
* 2026-11-07: $0.25 input, $0.03 cached input, $1.00 output; no cache-write price, so $0). */
|
|
3
3
|
export const PARTICLE_1_PRICE = { input: 0.25, output: 1, cacheRead: 0.03, cacheWrite: 0 };
|
|
4
|
-
/**
|
|
4
|
+
/** What serve sets over pi-ai's own catalog entries, by provider and id: a price (`cost`), and how the model takes its
|
|
5
|
+
* tools (`toolsAs`, absent: native). pi-ai 1.5.0 lists particle-ai/particle-1 at
|
|
5
6
|
* OpenRouter's current promotional price ($0.05 input, $0.003 cache read, $0.50 output). A run's cap holds each request
|
|
6
7
|
* at its worst case, priced from the catalog, before it is sent, and a hold must never price below what can be billed:
|
|
7
|
-
* the promotion can end before the catalog follows. So the hold takes Particle's list price
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* the promotion can end before the catalog follows. So the hold takes Particle's list price, and so does the booking:
|
|
9
|
+
* a request that answers is booked at pi-ai's calculateCost on this same catalog entry, its list price, not at what
|
|
10
|
+
* OpenRouter bills during the promotion. */
|
|
10
11
|
export const PRICE_OVERRIDES = [
|
|
11
|
-
|
|
12
|
+
// Particle-1 takes its tools as text: Particle AI, its one provider on OpenRouter, caches no prefix of a request that
|
|
13
|
+
// carries a tools parameter (measured 2026-11-11: such a request renders to a prompt whose token count varies by send,
|
|
14
|
+
// and 0-30% of it is cached); with its tools as text, 76-92% of a review's input is read from the cache.
|
|
15
|
+
{ provider: "openrouter", id: "particle-ai/particle-1", cost: { ...PARTICLE_1_PRICE }, toolsAs: "text" },
|
|
12
16
|
];
|
|
13
17
|
/** `list` with each overridden model's price in place of the catalog's, whole: a field of the catalog's cost the override
|
|
14
18
|
* does not name (its price `tiers`, which pi-ai's calculateCost prices a request at once its input passes one) never
|
|
15
|
-
* survives, so a later catalog's promotional tier cannot price a hold below the list price.
|
|
19
|
+
* survives, so a later catalog's promotional tier cannot price a hold below the list price. An override's `toolsAs`
|
|
20
|
+
* rides on the entry beside it. */
|
|
16
21
|
const priced = (list, overrides) => list.map((model) => {
|
|
17
22
|
const override = overrides.find((entry) => entry.id === model.id);
|
|
18
|
-
return override ? { ...model, cost: { ...override.cost } } : model;
|
|
23
|
+
return override ? { ...model, cost: { ...override.cost }, ...(override.toolsAs ? { toolsAs: override.toolsAs } : {}) } : model;
|
|
19
24
|
});
|
|
20
25
|
/** `models` (pi-ai's built-in catalog, or one built on it) with PRICE_OVERRIDES set on their providers' own entries, in
|
|
21
|
-
* place: a request, a price and a capability read find the catalog's entry at the overridden price. */
|
|
26
|
+
* place: a request, a price and a capability read find the catalog's entry at the overridden price, with its toolsAs. */
|
|
22
27
|
export function withLocalModels(models) {
|
|
23
28
|
for (const providerId of new Set(PRICE_OVERRIDES.map((entry) => entry.provider))) {
|
|
24
29
|
const own = models.getProvider(providerId);
|
package/dist/mcp-gateway.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { type ToolRegistration } from "@earendil-works/pi-durable";
|
|
2
1
|
import type { McpCallResult, McpTool, SessionMcp } from "@parcha/agentrun-kernel";
|
|
3
|
-
import { type Gate, type Park } from "./tool-gate.js";
|
|
4
2
|
import { type Workspace } from "./workspace/index.js";
|
|
5
|
-
/** The run's pinned MCP tools, in its directory: written once, at its first launch. */
|
|
6
|
-
export declare const MCP_PIN = "mcp-tools.json";
|
|
7
3
|
/** A catalog name of an MCP tool: `mcp:<server>/<tool>`. A server name has no `_`, so `mcp__<server>__<tool>` splits one way. */
|
|
8
4
|
export declare const MCP_NAME: RegExp;
|
|
9
|
-
/** The longest answer the model reads whole; the rest is filed in the run's work/
|
|
5
|
+
/** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
|
|
6
|
+
* (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
|
|
10
7
|
export declare const MCP_CLIP = 60000;
|
|
11
8
|
/** The most of one upstream answer read. */
|
|
12
9
|
export declare const MAX_RESPONSE: number;
|
|
@@ -19,35 +16,20 @@ export type McpPin = Record<string, {
|
|
|
19
16
|
tools: McpTool[];
|
|
20
17
|
prices?: Record<string, number>;
|
|
21
18
|
}>;
|
|
22
|
-
/**
|
|
19
|
+
/** Each granted server's URL now, and its credential's headers when that URL is the pinned one (the claim step's). */
|
|
23
20
|
export type McpCredentials = Record<string, {
|
|
24
21
|
url: string;
|
|
25
22
|
headers?: Record<string, string>; /** Why its saved credential did not open: its calls are refused unsent. */
|
|
26
23
|
unopened?: string; /** When its credential ends (ms): a token minted for the run's launch (a github_app server's), whose calls past it are refused unsent, in words. */
|
|
27
24
|
expires_at?: number;
|
|
28
25
|
}>;
|
|
29
|
-
/** The servers saved on this server
|
|
26
|
+
/** The servers saved on this server, as a claim's pin reads them. */
|
|
30
27
|
export interface McpServerSource {
|
|
31
28
|
server(name: string): {
|
|
32
29
|
url: string;
|
|
33
30
|
tools: readonly McpTool[];
|
|
34
31
|
prices?: Readonly<Record<string, number>>;
|
|
35
32
|
} | undefined;
|
|
36
|
-
/** The server's credential, opened now: its headers, or why it does not open, each under its own tag; undefined when
|
|
37
|
-
* it has none. With `runId`, for that run's launch: a github_app server's static headers with the token minted for
|
|
38
|
-
* the run (mint), or why it has none. */
|
|
39
|
-
headers(name: string, runId?: string): {
|
|
40
|
-
headers: Record<string, string>;
|
|
41
|
-
expires_at?: number;
|
|
42
|
-
} | {
|
|
43
|
-
unopened: string;
|
|
44
|
-
} | undefined;
|
|
45
|
-
/** Before a launch: an OAuth access token near its expiry refreshed (mcp-servers.ts headersForRun). Never throws. */
|
|
46
|
-
refresh?(name: string): Promise<void>;
|
|
47
|
-
/** Before a launch: a github_app server's installation token minted for run `runId`, narrowed to the one repository
|
|
48
|
-
* its first message (`input`) is about (github-connection.ts githubTargetOf); kept in memory for headers. Never
|
|
49
|
-
* throws: a token there is none of is a credential that does not open, said in words to the run's calls. */
|
|
50
|
-
mint?(name: string, runId: string, input: unknown): Promise<void>;
|
|
51
33
|
}
|
|
52
34
|
/** `mcp:<server>/<tool>` read, or undefined for a name that is not one. */
|
|
53
35
|
export declare const mcpNameOf: (name: string) => {
|
|
@@ -85,42 +67,22 @@ export interface McpGatewayOptions {
|
|
|
85
67
|
callMs?: number;
|
|
86
68
|
connectMs?: number;
|
|
87
69
|
};
|
|
88
|
-
/** The run's
|
|
89
|
-
|
|
90
|
-
* adapter loop's gate asks before each call's intent, and the call reaches here allowed. A test may omit it too, and
|
|
91
|
-
* then every call is let go. Its `executor` and `spill`, where it has them, run an approved call and pass a result
|
|
92
|
-
* through. */
|
|
93
|
-
gate?: Pick<Gate, "enter"> & Partial<Pick<Gate, "executor" | "spill">>;
|
|
94
|
-
/** The run's commit to its store, once it is open: a parked call's request, a priced call's mark and charge, and an
|
|
95
|
-
* unpriced call's "not metered" are written on its root. None: a priced call is refused unsent, as a paid call with
|
|
96
|
-
* nowhere to book it is (paid-calls.ts). */
|
|
97
|
-
commit?: () => Park["commit"] | undefined;
|
|
98
|
-
/** Read `credentials` at every call and every request rather than copy it when the gateway is built: a change made
|
|
99
|
-
* after (a token refreshed behind the claim, a server removed) reaches it, even through a client already connected.
|
|
100
|
-
* Only the runner's MCP claim step (runner/mcp-claim.ts), which keeps that object current, passes it. Without it, the
|
|
101
|
-
* credentials are copied at construction and a client sends the headers it connected with. */
|
|
102
|
-
liveCredentials?: true;
|
|
70
|
+
/** The run's commit to its store: an unpriced call's "not metered" is written on its root. */
|
|
71
|
+
commit?: () => McpCommit | undefined;
|
|
103
72
|
}
|
|
73
|
+
/** A run's journal commit. */
|
|
74
|
+
export type McpCommit = <T>(change: (tx: unknown) => Promise<T>) => Promise<T>;
|
|
104
75
|
/** What a call with no call id answers where a gate must know it by one: nothing was sent. */
|
|
105
76
|
export declare const noCallId: (name: string) => string;
|
|
106
|
-
/**
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
* commit, and how it ends a parked call's turn); none, the run's root commit. */
|
|
77
|
+
/** The gateway: a session's servers, and their calls. `credentials` is read at every call and every request, never
|
|
78
|
+
* copied: a change the claim step makes after (a token refreshed behind the claim, a server removed) reaches it, even
|
|
79
|
+
* through a client already connected. */
|
|
110
80
|
export type McpGateway = Omit<SessionMcp, "call"> & {
|
|
111
81
|
call(server: string, tool: string, args: Record<string, unknown>, context: {
|
|
112
82
|
signal: AbortSignal;
|
|
113
83
|
callId?: string;
|
|
114
|
-
park?: Park;
|
|
115
84
|
}): Promise<McpCallResult>;
|
|
116
85
|
/** The credential values the calls in flight hold for their scrub, every call's together (none when idle). */
|
|
117
86
|
heldValues(): string[];
|
|
118
87
|
};
|
|
119
88
|
export declare function mcpGateway(options: McpGatewayOptions): McpGateway;
|
|
120
|
-
/** Whether the gateway's answer is a call the gate parked for a person's approval: the harness ends the turn on it, and
|
|
121
|
-
* a harness's session records the call as one that did not run (McpCallResult's `parked`). The door that serves a
|
|
122
|
-
* harness's own MCP client sends the answer's content and error only. */
|
|
123
|
-
export declare const isParked: (result: McpCallResult) => boolean;
|
|
124
|
-
/** pi's tools for the gateway's servers: each granted tool under its wire name (`mcp__<server>__<tool>`), with the pinned
|
|
125
|
-
* description and schema, never run again after a crash. */
|
|
126
|
-
export declare function mcpRegistrations(gateway: McpGateway): ToolRegistration[];
|
package/dist/mcp-gateway.js
CHANGED
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
// A run's remote MCP servers
|
|
2
|
-
//
|
|
3
|
-
// MCP client
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// - Its credentials come over the run's secrets pipe (secrets.ts mcpCredentials), only for the servers it grants, with
|
|
9
|
-
// each server's URL now: one whose URL is not the pinned one is never sent anything, and the credential the pipe
|
|
10
|
-
// holds for a moved server is none.
|
|
1
|
+
// A run's remote MCP servers: the one place every harness's MCP call goes through. A claimed run's spec builds one per
|
|
2
|
+
// claim from its MCP claim step (runner/mcp-run.ts mcpForClaim); pi calls it through the runner's host tools, and a
|
|
3
|
+
// harness with its own MCP client through the session proxy's /mcp/<server> (@parcha/agentrun-kernel/host mcpRoute).
|
|
4
|
+
// - What a run may call is pinned (mcpPinOf): each granted tool as the server listed it when its owner saved it, and
|
|
5
|
+
// the server's URL then. A later refresh of the server never changes a running agent's tools.
|
|
6
|
+
// - Its credentials come from the claim step, only for the servers it grants, with each server's URL now, read at every
|
|
7
|
+
// call and every request: one whose URL is not the pinned one is never sent anything.
|
|
11
8
|
// - One upstream client per server (the official SDK), connected at its first call; no redirect is followed, so a
|
|
12
9
|
// credential goes nowhere but the pinned URL, and an answer past MAX_RESPONSE is cut off.
|
|
13
10
|
// - A call is never sent twice: each harness records its intent before it reaches here (pi-durable's tool intent,
|
|
14
11
|
// Claude's PreToolUse), and one a crash cut off is answered interrupted there. An aborted call aborts upstream.
|
|
15
12
|
// - Every failure is a result the model reads, naming the server and never a header.
|
|
16
|
-
// -
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
// - A tool its owner priced (the server's `prices`) is held at that price under the run's cap and booked as the run's
|
|
22
|
-
// tool cost, as any paid call (cap.ts paidCall): refused unsent when the cap cannot take it. A tool with no price runs,
|
|
23
|
-
// marked "not metered" on the run's root (TOOL_UNMETERED), outside the run's cost.
|
|
13
|
+
// - The runner's adapter loop gates every call before its intent (tool-gate.ts RunGate.decide), as
|
|
14
|
+
// `mcp:<server>/<tool>`: a call that reaches here was allowed.
|
|
15
|
+
// - A tool its owner priced (the server's `prices`) is held at that price on the run's one ledger and booked as the
|
|
16
|
+
// run's tool cost (paid-calls.ts paidStep): refused unsent when the cap cannot take it, or when no ledger books it. A
|
|
17
|
+
// tool with no price runs, marked "not metered" on the run's root (TOOL_UNMETERED), outside the run's cost.
|
|
24
18
|
import { randomUUID } from "node:crypto";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import { wireName } from "./catalog.js";
|
|
19
|
+
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
20
|
+
import { TOOL_UNMETERED } from "./timeline/index.js";
|
|
21
|
+
import { filedAnswer } from "./filed-answer.js";
|
|
22
|
+
import { paidLedger, paidStep } from "./paid-calls.js";
|
|
30
23
|
import { metaToolOf } from "./mcp-meta.js";
|
|
31
24
|
import { SIGN_IN_AGAIN } from "./mcp-oauth.js";
|
|
32
|
-
import {
|
|
33
|
-
import { forModel } from "./result.js";
|
|
25
|
+
import { mcpToolName } from "./tool-gate.js";
|
|
34
26
|
import { workspaceAt, workspaceErrorWords } from "./workspace/index.js";
|
|
35
|
-
/** The run's pinned MCP tools, in its directory: written once, at its first launch. */
|
|
36
|
-
export const MCP_PIN = "mcp-tools.json";
|
|
37
27
|
/** A catalog name of an MCP tool: `mcp:<server>/<tool>`. A server name has no `_`, so `mcp__<server>__<tool>` splits one way. */
|
|
38
28
|
export const MCP_NAME = /^mcp:([a-z][a-z0-9-]{0,31})\/([A-Za-z0-9_-]{1,64})$/;
|
|
39
|
-
/** The longest answer the model reads whole; the rest is filed in the run's work/
|
|
29
|
+
/** The longest answer the model reads whole; past it, the rest is filed in the run's work/ as lines read pages through
|
|
30
|
+
* (filed-answer.ts). Within the host's result bound (HOST_RESULT_MAX_CHARS), so every harness passes it whole. */
|
|
40
31
|
export const MCP_CLIP = 60_000;
|
|
41
32
|
/** The most of one upstream answer read. */
|
|
42
33
|
export const MAX_RESPONSE = 4 * 1024 * 1024;
|
|
@@ -186,17 +177,10 @@ const until = (work, signal) => new Promise((resolve, reject) => {
|
|
|
186
177
|
});
|
|
187
178
|
/** What a call with no call id answers where a gate must know it by one: nothing was sent. */
|
|
188
179
|
export const noCallId = (name) => `The ${name} call was not sent: it came with no call id, so it cannot wait for a person's approval.`;
|
|
189
|
-
/** What a call that needs a person's approval answers from a harness that cannot wait for one: nothing was sent. */
|
|
190
|
-
export const cannotWait = (name) => `The ${name} call needs a person's approval, which this harness can't wait for yet; nothing was sent.`;
|
|
191
|
-
/** The gateways that hold their run's gate: each of their calls enters it, in `call`. */
|
|
192
|
-
const gating = new WeakSet();
|
|
193
180
|
export function mcpGateway(options) {
|
|
194
181
|
const clients = new Map();
|
|
195
182
|
const pins = new Map(Object.entries(options.pin));
|
|
196
|
-
const
|
|
197
|
-
const credentials = live
|
|
198
|
-
? { get: (server) => (Object.hasOwn(options.credentials, server) ? options.credentials[server] : undefined) }
|
|
199
|
-
: new Map(Object.entries(options.credentials));
|
|
183
|
+
const credentials = { get: (server) => (Object.hasOwn(options.credentials, server) ? options.credentials[server] : undefined) };
|
|
200
184
|
/** Each server's last HTTP status, which tells a refused credential from another failure. */
|
|
201
185
|
const statuses = new Map();
|
|
202
186
|
const send = options.fetch ?? fetch;
|
|
@@ -263,7 +247,7 @@ export function mcpGateway(options) {
|
|
|
263
247
|
const { Client, StreamableHTTPClientTransport } = await import("@modelcontextprotocol/client");
|
|
264
248
|
// The 2026-07-28 revision first, a 2025-era server through its initialize, as a preview connects.
|
|
265
249
|
const client = new Client({ name: "agentrun", version: "1.0.0" }, { capabilities: {}, versionNegotiation: { mode: "auto" } });
|
|
266
|
-
await client.connect(new StreamableHTTPClientTransport(new URL(url), { fetch: guarded(server,
|
|
250
|
+
await client.connect(new StreamableHTTPClientTransport(new URL(url), { fetch: guarded(server, () => credentials.get(server)?.headers ?? {}, status) }), { timeout: options.bounds?.connectMs ?? CONNECT_MS });
|
|
267
251
|
return client;
|
|
268
252
|
})();
|
|
269
253
|
clients.set(server, upstream);
|
|
@@ -272,28 +256,41 @@ export function mcpGateway(options) {
|
|
|
272
256
|
}
|
|
273
257
|
return upstream;
|
|
274
258
|
};
|
|
275
|
-
/** The model's text of `result`: its text blocks
|
|
276
|
-
*
|
|
277
|
-
* (never through a link),
|
|
259
|
+
/** The model's text of `result`: its text blocks and its embedded text resources (GitHub's get_file_contents answers a
|
|
260
|
+
* file as one) joined, its structured content when it has neither. Past MCP_CLIP, its start and the rest filed in the
|
|
261
|
+
* run's evidence/mcp/<server>/ as readable lines, through its Workspace (never through a link), the text saying where
|
|
262
|
+
* and the read offset that goes on (filed-answer.ts), so read pages through it with no shell. With blocks that are
|
|
263
|
+
* neither (an image, a blob), the whole result is filed there as JSON, and the text says where. `clean` scrubs every
|
|
264
|
+
* credential the call's server took or sent. */
|
|
278
265
|
const textOf = async (server, tool, result, clean) => {
|
|
279
266
|
const blocks = Array.isArray(result.content) ? result.content : [];
|
|
280
|
-
const texts = blocks.
|
|
267
|
+
const texts = blocks.flatMap((block) => {
|
|
268
|
+
if (block?.type === "text" && typeof block.text === "string")
|
|
269
|
+
return [block.text];
|
|
270
|
+
const resource = block?.type === "resource" ? block.resource : undefined;
|
|
271
|
+
if (typeof resource?.text !== "string")
|
|
272
|
+
return [];
|
|
273
|
+
const about = [typeof resource.uri === "string" ? resource.uri : "", typeof resource.mimeType === "string" ? `(${resource.mimeType})` : ""].filter(Boolean).join(" ");
|
|
274
|
+
return [`[resource${about ? ` ${about}` : ""}]\n${resource.text}`];
|
|
275
|
+
});
|
|
281
276
|
let text = clean(texts.join("\n\n"));
|
|
282
277
|
if (!text && result.structuredContent !== undefined)
|
|
283
278
|
text = clean(JSON.stringify(result.structuredContent));
|
|
284
279
|
const other = blocks.length - texts.length;
|
|
285
280
|
if (text.length <= MCP_CLIP && other === 0)
|
|
286
281
|
return text;
|
|
287
|
-
const name = `${tool}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}
|
|
282
|
+
const name = `${tool}-${new Date().toISOString().replace(/[:.]/g, "-")}-${randomUUID().slice(0, 8)}`;
|
|
283
|
+
if (other === 0)
|
|
284
|
+
return filedAnswer(() => workspaceAt(options.work()), `evidence/mcp/${server}`, name, text, MCP_CLIP);
|
|
288
285
|
const head = text.length > MCP_CLIP ? `${text.slice(0, MCP_CLIP)}\n[cut at ${MCP_CLIP} of ${text.length} characters; ` : `${text}\n[${other} block${other > 1 ? "s" : ""} that ${other > 1 ? "are" : "is"} not text; `;
|
|
289
286
|
try {
|
|
290
|
-
await workspaceAt(options.work()).write(`evidence/mcp/${server}/${name}`, clean(JSON.stringify(result)));
|
|
287
|
+
await workspaceAt(options.work()).write(`evidence/mcp/${server}/${name}.json`, clean(JSON.stringify(result)));
|
|
291
288
|
}
|
|
292
289
|
catch (error) {
|
|
293
290
|
// The Workspace's code and the port's line for it, never the error's message, which names paths.
|
|
294
291
|
return `${head}the whole answer could not be saved (${workspaceErrorWords(error) ?? error?.code ?? "write failed"})]`;
|
|
295
292
|
}
|
|
296
|
-
return `${head}the whole answer is in the run's files at evidence/mcp/${server}/${name}]`;
|
|
293
|
+
return `${head}the whole answer is in the run's files at evidence/mcp/${server}/${name}.json]`;
|
|
297
294
|
};
|
|
298
295
|
/** The call itself, to a server whose address is the pinned one. A gate's decision or a paid call's hold goes around
|
|
299
296
|
* it, in `call` below: the one place every harness's call passes before anything is sent. */
|
|
@@ -391,105 +388,17 @@ export function mcpGateway(options) {
|
|
|
391
388
|
const stepped = await paidStep(onLedger, callId ?? name, { name, holdUsd: price, basis: `the price its owner set for ${name}`, by: label.charged_by }, () => call(), () => (went ? price : 0));
|
|
392
389
|
return "refused" in stepped ? said(stepped.refused, true) : stepped.result;
|
|
393
390
|
}
|
|
394
|
-
|
|
395
|
-
return said(`${name} was not sent: this call has no run to book its price under.`, true);
|
|
396
|
-
const paid = await paidCall(name, async () => {
|
|
397
|
-
// Held at its price meanwhile; marked right before it leaves, and settled at its price once it left, whatever it
|
|
398
|
-
// answers: its owner says each call costs that. One that never left (a failed connect, a stop) books nothing.
|
|
399
|
-
const result = await call(async () => {
|
|
400
|
-
try {
|
|
401
|
-
await writeHold((kind, data) => record(commit, kind, data), { ...label, heldUsd: price });
|
|
402
|
-
return undefined;
|
|
403
|
-
}
|
|
404
|
-
catch (error) {
|
|
405
|
-
return holdRefusal(name, error);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
if (went)
|
|
409
|
-
await record(commit, TOOL_COST, { ...label, usd: price }).catch(() => undefined);
|
|
410
|
-
return result;
|
|
411
|
-
}, () => (went ? price : 0), { usd: price, basis: `the price its owner set for ${name}` });
|
|
412
|
-
return "refused" in paid ? said(paid.refused, true) : paid.result;
|
|
391
|
+
return said(`${name} was not sent: this call has no run to book its price under.`, true);
|
|
413
392
|
};
|
|
414
|
-
// An approved call, run by the gate once a person allows it: through the same path, once. It has the same deadline as
|
|
415
|
-
// any call: forward() gives callTool CALL_MS and a server's first connection CONNECT_MS, so a server that never answers
|
|
416
|
-
// ends the call as an error the model reads, the upstream request aborted, and the run goes on; the gate's own stop or
|
|
417
|
-
// cancel reaches it through `signal`.
|
|
418
|
-
options.gate?.executor?.("mcp:", async (name, args, callId, signal) => {
|
|
419
|
-
const parsed = /^mcp:([^/]+)\/(.+)$/.exec(name);
|
|
420
|
-
const result = parsed ? await sent(parsed[1], parsed[2], (args ?? {}), callId, signal) : said(`${name} is not an MCP tool.`, true);
|
|
421
|
-
return { text: result.content.map((block) => block.text).join("\n\n"), isError: result.isError === true };
|
|
422
|
-
});
|
|
423
393
|
const gateway = {
|
|
424
394
|
servers: [...pins].map(([name, pinned]) => ({ name, tools: pinned.tools })),
|
|
425
395
|
heldValues: () => [...new Set([...inFlight.values()].flatMap((calls) => [...calls].flatMap((values) => [...values])))],
|
|
426
|
-
async call(server, tool, args, { signal, callId
|
|
396
|
+
async call(server, tool, args, { signal, callId }) {
|
|
427
397
|
const why = unsendable(server, tool);
|
|
428
398
|
if (why)
|
|
429
399
|
return said(why, true);
|
|
430
|
-
|
|
431
|
-
// A parked call is answered and resumed by its id, the harness's own: a call with none is never parked.
|
|
432
|
-
if (gate && !callId)
|
|
433
|
-
return said(noCallId(mcpToolName(server, tool)), true);
|
|
434
|
-
const id = callId ?? `mcp_${randomUUID()}`;
|
|
435
|
-
if (gate) {
|
|
436
|
-
const name = mcpToolName(server, tool);
|
|
437
|
-
// A call parks only where its harness can end the turn on it (a park with `parked`). Anywhere else the gate's
|
|
438
|
-
// commit of the request is refused, so an ask leaves no approval waiting, and the call is answered so.
|
|
439
|
-
const park = given?.parked ? given : { commit: () => Promise.reject(new CannotPark()) };
|
|
440
|
-
const cannot = said(cannotWait(name), true);
|
|
441
|
-
let entered;
|
|
442
|
-
try {
|
|
443
|
-
// The approval card shows the call's declared price, or that it is not metered.
|
|
444
|
-
const price = pins.get(server).prices;
|
|
445
|
-
entered = await gate.enter(name, args, id, park, { price: price && Object.hasOwn(price, tool) ? price[tool] : "not metered" });
|
|
446
|
-
}
|
|
447
|
-
catch (error) {
|
|
448
|
-
if (error instanceof CannotPark)
|
|
449
|
-
return cannot;
|
|
450
|
-
return said(`The ${name} call was not sent: the tool gate failed (${String(error?.message ?? error).slice(0, 200)}).`, true);
|
|
451
|
-
}
|
|
452
|
-
if (entered?.parked)
|
|
453
|
-
return park === given ? { ...said(entered.text), parked: true } : cannot;
|
|
454
|
-
if (entered)
|
|
455
|
-
return said(entered.text, entered.isError);
|
|
456
|
-
const result = await sent(server, tool, args, id, signal);
|
|
457
|
-
const text = result.content.map((block) => block.text).join("\n\n");
|
|
458
|
-
return said(gate.spill ? gate.spill(id, text) : text, result.isError === true);
|
|
459
|
-
}
|
|
460
|
-
return sent(server, tool, args, id, signal);
|
|
400
|
+
return sent(server, tool, args, callId ?? `mcp_${randomUUID()}`, signal);
|
|
461
401
|
},
|
|
462
402
|
};
|
|
463
|
-
if (options.gate)
|
|
464
|
-
gating.add(gateway);
|
|
465
403
|
return gateway;
|
|
466
404
|
}
|
|
467
|
-
/** A park refused: the call came from a harness that cannot end its turn on a parked call. */
|
|
468
|
-
class CannotPark extends Error {
|
|
469
|
-
}
|
|
470
|
-
/** Whether the gateway's answer is a call the gate parked for a person's approval: the harness ends the turn on it, and
|
|
471
|
-
* a harness's session records the call as one that did not run (McpCallResult's `parked`). The door that serves a
|
|
472
|
-
* harness's own MCP client sends the answer's content and error only. */
|
|
473
|
-
export const isParked = (result) => result.parked === true;
|
|
474
|
-
/** pi's tools for the gateway's servers: each granted tool under its wire name (`mcp__<server>__<tool>`), with the pinned
|
|
475
|
-
* description and schema, never run again after a crash. */
|
|
476
|
-
export function mcpRegistrations(gateway) {
|
|
477
|
-
// Marked when the gateway holds the run's gate: its calls enter the gate in the gateway, so the gate's own wrapper
|
|
478
|
-
// (tool-gate.ts extension) leaves them be. Unmarked, the wrapper gates them as any tool.
|
|
479
|
-
const marked = gating.has(gateway) ? { [GATED_BY_GATEWAY]: true } : {};
|
|
480
|
-
return gateway.servers.flatMap((server) => server.tools.map((tool) => Object.assign(defineTool({
|
|
481
|
-
name: wireName(`mcp:${server.name}/${tool.name}`),
|
|
482
|
-
description: tool.description || tool.title || `${tool.name}, a tool of the MCP server ${server.name}.`,
|
|
483
|
-
replay: "unsafe",
|
|
484
|
-
parameters: tool.inputSchema,
|
|
485
|
-
execute: async (args, api, context) => {
|
|
486
|
-
// The gate's park is this call's own journal commit, as for every pi tool.
|
|
487
|
-
// pi ends the turn on a parked answer itself (below), so its park needs nothing told.
|
|
488
|
-
const park = { commit: (change) => api.commit(change, context), parked: () => undefined };
|
|
489
|
-
const result = await gateway.call(server.name, tool.name, (args ?? {}), { signal: context?.abortSignal ?? new AbortController().signal, ...(api?.callId ? { callId: api.callId, park } : {}) });
|
|
490
|
-
const text = result.content.map((block) => block.text).join("\n\n");
|
|
491
|
-
// A parked call ends the turn, as ask_person's does; the gate resumes the session once a person answers.
|
|
492
|
-
return isParked(result) ? forModel(text, { control: { terminate: true } }) : forModel(text, { isError: result.isError === true });
|
|
493
|
-
},
|
|
494
|
-
}), marked)));
|
|
495
|
-
}
|
package/dist/mcp-oauth.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const MCP_SETTINGS_PAGE = "/#/settings/mcp";
|
|
|
9
9
|
export declare const SIGN_IN_AGAIN = "sign in again in Settings \u2192 MCP servers";
|
|
10
10
|
/** The most sign-ins that may be in flight at once: the in-memory map evicts to it, and the store-backed one refuses past it. */
|
|
11
11
|
export declare const MAX_PENDING = 64;
|
|
12
|
-
/** How long a token refresh's request may take: a run's start waits for it, two tries at most (mcp-
|
|
12
|
+
/** How long a token refresh's request may take: a run's start waits for it, two tries at most (runner/mcp-claim.ts), so an
|
|
13
13
|
* authorization server that never answers holds a start's answer no more than about eight seconds, well under a
|
|
14
14
|
* client's timeout, and its call is then refused unsent, saying to try again. */
|
|
15
15
|
export declare const REFRESH_REQUEST_MS = 4000;
|
|
@@ -98,18 +98,16 @@ export declare const signInCookie: (port: number | undefined, state: string, htt
|
|
|
98
98
|
export declare const startedHere: (cookies: string | undefined, port: number | undefined, state: string | null) => boolean;
|
|
99
99
|
export declare class McpSignIns {
|
|
100
100
|
private readonly network;
|
|
101
|
-
private readonly pendingStore
|
|
101
|
+
private readonly pendingStore;
|
|
102
102
|
private readonly allowed;
|
|
103
|
-
/** `pendingStore`: where sign-ins in flight are kept
|
|
104
|
-
*
|
|
105
|
-
|
|
106
|
-
constructor(network?: OAuthNetwork, pendingStore?: PendingStore | undefined, allowed?: () => Promise<readonly string[]>);
|
|
107
|
-
private readonly pending;
|
|
103
|
+
/** `pendingStore`: where sign-ins in flight are kept (over store.mcpOauth). `allowed`: the private-network hosts the
|
|
104
|
+
* owner allows (privateOAuthHosts), read at a sign-in's start and again at its callback. */
|
|
105
|
+
constructor(network: OAuthNetwork, pendingStore: PendingStore, allowed: () => Promise<readonly string[]>);
|
|
108
106
|
/** This server's address as a browser reaches it (AGENTRUN_PUBLIC_URL, else where it listens), no trailing slash:
|
|
109
|
-
* set by
|
|
107
|
+
* set by McpServersOverStore.attach as the server starts listening. */
|
|
110
108
|
base: string;
|
|
111
109
|
/** Where this server listens (`http://<host>:<port>`), whatever `base` is: its port is never an endpoint a loopback
|
|
112
|
-
* authorization server may name. Set by
|
|
110
|
+
* authorization server may name. Set by McpServersOverStore.attach. */
|
|
113
111
|
listening: string;
|
|
114
112
|
/** This server's own local addresses, whose ports a loopback authorization server may never name: where it listens,
|
|
115
113
|
* and its public address too when that is on loopback (a local https proxy on another port, in front of the
|
|
@@ -147,11 +145,9 @@ export declare class McpSignIns {
|
|
|
147
145
|
kind?: ClientKind;
|
|
148
146
|
keptFor?: string;
|
|
149
147
|
}): Promise<string>;
|
|
150
|
-
/** The callback's sign-in, by its state: once, and only within ten minutes of its start. `was`
|
|
151
|
-
* when it started (null for none), so a sign-in the owner since replaced or forgot is not
|
|
152
|
-
|
|
153
|
-
/** take() over the pending store (the store server), async: the callback's sign-in, by its state, once and only within
|
|
154
|
-
* ten minutes of its start. The same refusal as take() when it is used, expired or unknown. */
|
|
148
|
+
/** The callback's sign-in, by its state, from the pending store: once, and only within ten minutes of its start. `was`
|
|
149
|
+
* is the server's save when it started (null for none), so a sign-in the owner since replaced or forgot is not
|
|
150
|
+
* written back. */
|
|
155
151
|
takePending(state: string | null): Promise<Pending>;
|
|
156
152
|
/** The code exchanged (with the verifier and the client the start kept) for the token set to seal. */
|
|
157
153
|
finish(entry: Pending, code: string, iss: string | undefined, stop?: AbortSignal): Promise<TokenSet>;
|