@parcha/agentrun-serve 0.1.0-beta.61 → 0.1.0-beta.63
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 +113 -0
- package/README.md +128 -20
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/api-only.d.ts +4 -0
- package/dist/api-only.js +5 -1
- package/dist/archil-settings.d.ts +9 -0
- package/dist/archil-settings.js +8 -1
- package/dist/bash-read-only.d.ts +3 -0
- package/dist/bash-read-only.js +6 -3
- package/dist/chatgpt-plan.d.ts +33 -8
- package/dist/chatgpt-plan.js +141 -24
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +19 -8
- package/dist/composio-triggers.d.ts +9 -3
- package/dist/computers.d.ts +3 -0
- package/dist/computers.js +2 -1
- package/dist/console/assets/{backend-C9ffXUR5.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/index-C8Y5Zl8x.js +639 -0
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/assets/{styles-fjQBFfMv.css → styles-D0SufbzK.css} +1 -1
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/cut-pool.d.ts +14 -0
- package/dist/cut-pool.js +98 -0
- package/dist/cut-worker.d.ts +14 -0
- package/dist/cut-worker.js +16 -0
- package/dist/decisions.d.ts +4 -0
- package/dist/decisions.js +9 -1
- package/dist/env-switch.d.ts +3 -0
- package/dist/env-switch.js +3 -0
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/harness-table.d.ts +7 -0
- package/dist/harness-table.js +6 -3
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learned-nodes.d.ts +2 -1
- package/dist/learned-nodes.js +2 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-servers-store.d.ts +7 -10
- package/dist/mcp-servers-store.js +15 -9
- package/dist/native/cli.js +5 -1
- package/dist/ollama-provider.d.ts +10 -3
- package/dist/ollama-provider.js +17 -7
- package/dist/openapi.js +51 -20
- package/dist/otel/tracer.d.ts +6 -3
- package/dist/otel/tracer.js +24 -6
- package/dist/page.d.ts +7 -0
- package/dist/page.js +17 -4
- package/dist/place.d.ts +25 -9
- package/dist/place.js +37 -11
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +26 -6
- package/dist/run-model-key.d.ts +2 -1
- package/dist/run-model-key.js +2 -1
- package/dist/run-reads-over-store.d.ts +7 -0
- package/dist/run-reads-over-store.js +32 -4
- package/dist/run-view.js +9 -3
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +21 -11
- package/dist/runner/adapter-loop.js +95 -28
- package/dist/runner/adapter-run-spec.d.ts +20 -4
- package/dist/runner/adapter-run-spec.js +64 -30
- package/dist/runner/adapters/index.d.ts +6 -0
- package/dist/runner/adapters/index.js +5 -1
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +12 -5
- package/dist/runner/claim-secrets.js +28 -12
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +54 -25
- package/dist/runner/dispatch.js +2 -0
- package/dist/runner/harness-loops.d.ts +5 -0
- package/dist/runner/harness-loops.js +4 -1
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/live-ticker.js +3 -1
- package/dist/runner/loop-contract.d.ts +8 -1
- package/dist/runner/main.js +2 -0
- package/dist/runner/mcp-run.d.ts +5 -0
- package/dist/runner/mcp-run.js +18 -0
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +4 -2
- package/dist/runner/metrics.js +5 -3
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/native-loop.js +2 -2
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +65 -41
- package/dist/runner/run-child.js +2 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +158 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-calls.d.ts +4 -3
- package/dist/runner/workflow-calls.js +41 -12
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -1
- package/dist/secret-rules.js +88 -24
- package/dist/server.d.ts +10 -1
- package/dist/server.js +131 -44
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +669 -0
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/suggestions.js +32 -3
- package/dist/templates.d.ts +3 -1
- package/dist/templates.js +7 -3
- package/dist/tool-gate.d.ts +25 -9
- package/dist/tool-gate.js +58 -19
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tool-plane.d.ts +1 -0
- package/dist/tool-plane.js +6 -2
- package/dist/tools.js +2 -2
- package/dist/trigger-composio.js +1 -1
- package/dist/webhooks.d.ts +3 -0
- package/dist/webhooks.js +5 -0
- package/dist/workspace/archil-claim.d.ts +7 -3
- package/dist/workspace/archil-claim.js +13 -5
- package/dist/workspace/archil-mount-credential.d.ts +6 -0
- package/dist/workspace/archil-mount-credential.js +11 -0
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/computer-deps.d.ts +5 -3
- package/dist/workspace/computer-deps.js +11 -9
- package/dist/workspace/computer-for-claim.d.ts +6 -2
- package/dist/workspace/computer-for-claim.js +43 -12
- package/dist/workspace/computer-janitor.d.ts +7 -4
- package/dist/workspace/computer-janitor.js +7 -4
- package/dist/workspace/computer-kept.d.ts +7 -1
- package/dist/workspace/computer-kept.js +7 -1
- package/dist/workspace/kind-skills/desktop/SKILL.md +17 -4
- package/dist/workspace/mount-revoke-left.d.ts +16 -4
- package/dist/workspace/mount-revoke-left.js +42 -22
- package/dist/workspace/resolve-computer.d.ts +11 -5
- package/dist/workspace/resolve-computer.js +22 -13
- package/dist/workspace/run-end-computers.js +1 -1
- package/dist/workspace/run-tools.d.ts +10 -3
- package/dist/workspace/run-tools.js +5 -4
- package/dist/wrapped.d.ts +29 -2
- package/dist/wrapped.js +20 -3
- package/launcher/agentrun-serve +1 -1
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/index-BnZV3lvW.js +0 -639
- package/dist/console/assets/share-B1o5mJ56.js +0 -6
- /package/dist/console/assets/{styles-D_znYrHR.js → styles-BGZxYkky.js} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type CutJob = {
|
|
2
|
+
readonly id: number;
|
|
3
|
+
readonly text: string;
|
|
4
|
+
readonly values: readonly string[];
|
|
5
|
+
readonly max: number;
|
|
6
|
+
readonly held: readonly (readonly [number, number])[];
|
|
7
|
+
};
|
|
8
|
+
export type CutReply = {
|
|
9
|
+
readonly id: number;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly id: number;
|
|
13
|
+
readonly failed: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The cut of a run file's text (cutFileText, the step a share's export takes too), in a worker thread: a text and a set
|
|
2
|
+
// of values whose cut runs long block this thread, never the server's, and cut-pool.ts terminates it at the read's
|
|
3
|
+
// deadline. One job at a time, each answered by its id: the cut text, or the name of what it threw (never its message,
|
|
4
|
+
// which may quote the text). The job's `max` is the text's byte length, which cutFileText measures itself.
|
|
5
|
+
import { parentPort } from "node:worker_threads";
|
|
6
|
+
import { cutFileText } from "./run-file-cut.js";
|
|
7
|
+
parentPort?.on("message", (job) => {
|
|
8
|
+
let reply;
|
|
9
|
+
try {
|
|
10
|
+
reply = { id: job.id, text: cutFileText(job.text, job.values, job.held) };
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
reply = { id: job.id, failed: error instanceof Error ? error.name : "unknown" };
|
|
14
|
+
}
|
|
15
|
+
parentPort.postMessage(reply);
|
|
16
|
+
});
|
package/dist/decisions.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { DecisionProvider } from "@parcha/agentrun-dsl";
|
|
2
2
|
export declare const JEV_KEY_ENV = "TYPESAFE_API_KEY";
|
|
3
|
+
/** TypeSafe's base in `env`: TYPESAFE_BASE_URL, else TypeSafe's own, held to the rule for a URL a key goes to
|
|
4
|
+
* (httpsBase), which throws in words naming the variable and the URL's origin alone. A run's Jev provider and the key's
|
|
5
|
+
* check (key-check.ts) both send TYPESAFE_API_KEY to it, so the key goes where it was checked. */
|
|
6
|
+
export declare const typesafeBase: (env: NodeJS.ProcessEnv) => string;
|
|
3
7
|
export declare const JEV_OPENROUTER_KEY_ENV = "OPENROUTER_API_KEY";
|
|
4
8
|
export declare const PARALLEL_KEY_ENV = "PARALLEL_API_KEY";
|
|
5
9
|
/** The provider a decision node that names none is answered by. */
|
package/dist/decisions.js
CHANGED
|
@@ -17,12 +17,17 @@
|
|
|
17
17
|
// set it since #2244 removed that engine. Only tests set it; its deletion is its own change.
|
|
18
18
|
import { closeSync, readFileSync } from "node:fs";
|
|
19
19
|
import { pathToFileURL } from "node:url";
|
|
20
|
+
import { httpsBase } from "@parcha/agentrun-computer";
|
|
20
21
|
import { openRouterApp } from "@parcha/agentrun-kernel/host";
|
|
21
22
|
import { JEV_MODEL } from "@parcha/agentrun-web";
|
|
22
23
|
import { WEB_JEV_OFF_ENV, webJevOff } from "./env-switch.js";
|
|
23
24
|
import { FAUX_ENV } from "./model.js";
|
|
24
25
|
import { keyNeeded } from "./key-words.js";
|
|
25
26
|
export const JEV_KEY_ENV = "TYPESAFE_API_KEY";
|
|
27
|
+
/** TypeSafe's base in `env`: TYPESAFE_BASE_URL, else TypeSafe's own, held to the rule for a URL a key goes to
|
|
28
|
+
* (httpsBase), which throws in words naming the variable and the URL's origin alone. A run's Jev provider and the key's
|
|
29
|
+
* check (key-check.ts) both send TYPESAFE_API_KEY to it, so the key goes where it was checked. */
|
|
30
|
+
export const typesafeBase = (env) => httpsBase(env.TYPESAFE_BASE_URL?.trim() || "https://api.typesafe.ai", "TYPESAFE_BASE_URL");
|
|
26
31
|
export const JEV_OPENROUTER_KEY_ENV = "OPENROUTER_API_KEY";
|
|
27
32
|
export const PARALLEL_KEY_ENV = "PARALLEL_API_KEY";
|
|
28
33
|
/** The provider a decision node that names none is answered by. */
|
|
@@ -253,7 +258,10 @@ export async function decisionProvidersIn(env) {
|
|
|
253
258
|
* (the runner's store), so both routes build the same providers. */
|
|
254
259
|
async function decisionProvidersFrom(handed, env) {
|
|
255
260
|
const providers = {};
|
|
256
|
-
|
|
261
|
+
// TypeSafe's SDK reads TYPESAFE_BASE_URL from the process's environment when given no base, and sends the key there:
|
|
262
|
+
// on TypeSafe's route the base is always given, read from `env` by the rule a saved key's check takes it by
|
|
263
|
+
// (typesafeBase), so the key goes where it was checked.
|
|
264
|
+
const jev = handed[JEV_KEY_ENV] !== undefined ? { apiKey: handed[JEV_KEY_ENV], baseURL: typesafeBase(env) } : handed[JEV_OPENROUTER_KEY_ENV] !== undefined ? { provider: "openrouter", apiKey: handed[JEV_OPENROUTER_KEY_ENV] } : undefined;
|
|
257
265
|
if (jev) {
|
|
258
266
|
const [{ jevProvider }, faux] = await Promise.all([import("@parcha/agentrun-jev"), fauxFetch(env, FAUX_JEV_ENV)]);
|
|
259
267
|
providers.jev = jevProvider({ ...jev, ...(faux ? { fetch: faux } : {}) });
|
package/dist/env-switch.d.ts
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
export declare const API_ONLY_ENV = "AGENTRUN_API_ONLY";
|
|
3
3
|
/** The run-keys setting (run-keys.ts). */
|
|
4
4
|
export declare const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
|
|
5
|
+
/** The share host (share-host.ts), as --share-host. */
|
|
6
|
+
export declare const SHARE_HOST_ENV = "AGENTRUN_SHARE_HOST";
|
|
5
7
|
/** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
|
|
6
8
|
export declare const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
|
|
7
9
|
/** What each setting means on, and off where off needs saying: the words a refused value answers. */
|
|
8
10
|
declare const MEANS: {
|
|
9
11
|
readonly AGENTRUN_API_ONLY: readonly ["serve the run API only", "the whole server"];
|
|
10
12
|
readonly AGENTRUN_RUN_KEYS: readonly ["each run brings the tool keys this server does not hold"];
|
|
13
|
+
readonly AGENTRUN_SHARE_HOST: readonly ["serve shares under /r/ alone", "the whole server"];
|
|
11
14
|
readonly AGENTRUN_WEB_JEV_OFF: readonly ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"];
|
|
12
15
|
};
|
|
13
16
|
/** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
|
package/dist/env-switch.js
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
export const API_ONLY_ENV = "AGENTRUN_API_ONLY";
|
|
5
5
|
/** The run-keys setting (run-keys.ts). */
|
|
6
6
|
export const RUN_KEYS_ENV = "AGENTRUN_RUN_KEYS";
|
|
7
|
+
/** The share host (share-host.ts), as --share-host. */
|
|
8
|
+
export const SHARE_HOST_ENV = "AGENTRUN_SHARE_HOST";
|
|
7
9
|
/** Jev off for the web tools (web-run.ts jevWebOf): web_search's results go unranked, whatever key the server holds. */
|
|
8
10
|
export const WEB_JEV_OFF_ENV = "AGENTRUN_WEB_JEV_OFF";
|
|
9
11
|
/** What each setting means on, and off where off needs saying: the words a refused value answers. */
|
|
10
12
|
const MEANS = {
|
|
11
13
|
[API_ONLY_ENV]: ["serve the run API only", "the whole server"],
|
|
12
14
|
[RUN_KEYS_ENV]: ["each run brings the tool keys this server does not hold"],
|
|
15
|
+
[SHARE_HOST_ENV]: ["serve shares under /r/ alone", "the whole server"],
|
|
13
16
|
[WEB_JEV_OFF_ENV]: ["the web tools run without Jev", "Jev ranks web_search's results where the server holds a TypeSafe key"],
|
|
14
17
|
};
|
|
15
18
|
/** Whether `env` turns setting `name` on: `1` or `true` on; unset, empty, `0` or `false` off. Any other value is refused
|
|
@@ -23,7 +23,9 @@ export interface OpenCodeAdapterOptions {
|
|
|
23
23
|
price?: ModelProxyOptions["price"];
|
|
24
24
|
/** The most output tokens one request may ask for. Default 32 000. */
|
|
25
25
|
maxOutputTokens?: number;
|
|
26
|
-
/** The model's context window
|
|
26
|
+
/** The model's context window, in tokens: OpenCode is told it (its model's `limit.context`), and the host's bound on one
|
|
27
|
+
* tool result is its share of it (the kernel's resultMaxChars). A session's own (SessionSpec.contextWindow) wins. With
|
|
28
|
+
* neither, OpenCode is told 272 000 and the host's bound alone holds a result. */
|
|
27
29
|
contextWindow?: number;
|
|
28
30
|
/** Where sessions keep their private directories when the host lends none (`io.dir`): one per session key. */
|
|
29
31
|
sessionsDir?: string;
|
|
@@ -12,7 +12,7 @@ import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { READ_SKILL_FILE, hostedTool, readSkillFileTool, skillProblems, toolSchemaProblems } from "@parcha/agentrun-kernel";
|
|
14
14
|
import { abortedOutcome, openDrive, pendingSubmissions, SessionHalt } from "@parcha/agentrun-kernel/kernel";
|
|
15
|
-
import { bridgeTool, recoveryNote, settleTurn, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
15
|
+
import { bridgeTool, recoveryNote, settleTurn, transcriptOf, windowBudget } from "@parcha/agentrun-kernel/process";
|
|
16
16
|
import { serialWriter, startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
17
17
|
import { openCodeHarness, sentSubmissions } from "./harness.js";
|
|
18
18
|
import { openCodePolicy, TOOL_PREFIX } from "./host/policy.js";
|
|
@@ -131,6 +131,7 @@ export function openCodeAdapter(options) {
|
|
|
131
131
|
}
|
|
132
132
|
const instructions = [...spec.system, ...(skills.length ? [skillsNote(skills)] : [])].join("\n\n");
|
|
133
133
|
const effort = spec.effort ?? spec.thinking;
|
|
134
|
+
const window = spec.contextWindow ?? options.contextWindow;
|
|
134
135
|
let control;
|
|
135
136
|
const harness = openCodeHarness({
|
|
136
137
|
tools: tools.map((tool) => bridgeTool(tool)),
|
|
@@ -146,7 +147,10 @@ export function openCodeAdapter(options) {
|
|
|
146
147
|
hooks: io.models,
|
|
147
148
|
...(options.price ? { price: options.price } : {}),
|
|
148
149
|
...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}),
|
|
149
|
-
|
|
150
|
+
// The window the host knows (the session's, from its catalog; else this adapter's). Only with neither is OpenCode
|
|
151
|
+
// told 272,000, a guess, and then no tool result is held to it: the host's bound alone.
|
|
152
|
+
contextWindow: window ?? 272_000,
|
|
153
|
+
...windowBudget(window, spec.system),
|
|
150
154
|
...(options.eventConnectMs ? { eventConnectMs: options.eventConnectMs } : {}),
|
|
151
155
|
...(options.log ? { log: options.log } : {}),
|
|
152
156
|
...(options.fetch ? { fetch: options.fetch } : {}),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GateAnswer, GateCall } from "@parcha/agentrun-kernel";
|
|
2
2
|
import type { DriveContext, HostTool, SessionState } from "@parcha/agentrun-kernel/kernel";
|
|
3
|
+
import { type ResultBudget } from "@parcha/agentrun-kernel/process";
|
|
3
4
|
import { type ModelProxyHooks, type ModelProxyOptions, type ParentWatch } from "@parcha/agentrun-kernel/host";
|
|
4
5
|
import { type ConfineChild } from "./host/server.js";
|
|
5
6
|
/** The journal stream that holds OpenCode's own events for the session, as `/sync/history` gives them. */
|
|
@@ -51,6 +52,9 @@ export interface OpenCodeHarnessOptions {
|
|
|
51
52
|
price?: ModelProxyOptions["price"];
|
|
52
53
|
maxOutputTokens?: number;
|
|
53
54
|
contextWindow: number;
|
|
55
|
+
/** What the session's model can take of one tool result (its context window): the tool bridge holds every result to
|
|
56
|
+
* it (boundResult's budget). Absent: the host's bound alone (HOST_RESULT_MAX_CHARS). */
|
|
57
|
+
resultBudget?: ResultBudget;
|
|
54
58
|
/** How long one try of the event stream may take to open. Default EVENT_CONNECT_MS. */
|
|
55
59
|
eventConnectMs?: number;
|
|
56
60
|
log?: (message: string, fields?: Record<string, unknown>) => void;
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { createHash, randomBytes } from "node:crypto";
|
|
18
18
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
19
19
|
import { isAbsolute, join, normalize } from "node:path";
|
|
20
|
-
import { journalRecords, NativeJournal, placeSubmissions, recoveryNote, resumeUnstartedCalls, toolBridge, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
20
|
+
import { journalRecords, journalTurn, NativeJournal, placeSubmissions, recoveryNote, resumeUnstartedCalls, toolBridge, transcriptOf } from "@parcha/agentrun-kernel/process";
|
|
21
21
|
import { startModelProxy } from "@parcha/agentrun-kernel/host";
|
|
22
22
|
import { openCodeConfig } from "./config.js";
|
|
23
23
|
import { danglingCalls, settleCall } from "./transcript.js";
|
|
@@ -187,6 +187,8 @@ export function openCodeHarness(options, control) {
|
|
|
187
187
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
188
188
|
const configFile = join(dirs.config, "agentrun-opencode.json");
|
|
189
189
|
const journal = new NativeJournal(ctx);
|
|
190
|
+
// The turn's budget kept on this drive's journal: a resume answers the calls it left on its answer's facts.
|
|
191
|
+
journalTurn(options.resultBudget?.turn, journal);
|
|
190
192
|
const mirrored = (await journal.read(SYNC_STREAM)).map((r) => r.data).filter(isSyncEvent);
|
|
191
193
|
const prompts = (await journal.read(PROMPT_STREAM)).map((r) => r.data);
|
|
192
194
|
let sessionID = mirrored[0]?.aggregate_id;
|
|
@@ -226,6 +228,7 @@ export function openCodeHarness(options, control) {
|
|
|
226
228
|
const bridge = toolBridge(ctx, options.tools, {
|
|
227
229
|
...(gate ? { gate: async (call) => (await barrier(), gate(call)) } : {}),
|
|
228
230
|
beforeNever: () => barrier(),
|
|
231
|
+
...(options.resultBudget ? { budget: options.resultBudget } : {}),
|
|
229
232
|
});
|
|
230
233
|
// A resumed session: each call OpenCode started and never ended goes through the shared decision before OpenCode
|
|
231
234
|
// starts again. A call that never reached its intent runs through the bridge under its own id (the gate, its intent,
|
|
@@ -252,6 +255,8 @@ export function openCodeHarness(options, control) {
|
|
|
252
255
|
const proxy = await startModelProxy({
|
|
253
256
|
policy: openCodePolicy({ model: options.model, tools: options.tools.map((t) => t.name), ...(options.maxOutputTokens ? { maxOutputTokens: options.maxOutputTokens } : {}), onCall: (call) => calls.add(call) }),
|
|
254
257
|
hooks,
|
|
258
|
+
// The turn budget the bridge's calls share: the proxy opens it with each answer's facts.
|
|
259
|
+
...(options.resultBudget?.turn ? { turn: options.resultBudget.turn } : {}),
|
|
255
260
|
model: options.model,
|
|
256
261
|
origin: options.provider.origin,
|
|
257
262
|
credential: async () => (await options.provider.credential()) ?? "",
|
package/dist/harness-table.d.ts
CHANGED
|
@@ -201,6 +201,13 @@ export interface AcpPlanEntryOptions extends ModuleChecks, Pick<HarnessEntry, "o
|
|
|
201
201
|
* built-in Goose starts. A module's acpEntry is the proxy-billed one alone. */
|
|
202
202
|
export declare function acpEntryOf(options: AcpEntryOptions, host?: AcpEntryHost): HarnessEntry;
|
|
203
203
|
export declare function acpEntryOf(options: AcpPlanEntryOptions, host?: AcpEntryHost): HarnessEntry;
|
|
204
|
+
/** What Cursor gives acpEntryOf for its plan-billed entry: billed to its owner's Cursor plan on the owner's Cursor API key
|
|
205
|
+
* (`ownKeys`), its model one Cursor lists for that key (`cursor/<model-id>`, `cursor/default` for Cursor's own). Listed
|
|
206
|
+
* only once its owner has installed it (`agentrun harness install cursor`): `missing` is its release, looked up and
|
|
207
|
+
* verified (harness-cursor.ts cursorMissing), and `beforeStart` checks its launcher and every file beside it again
|
|
208
|
+
* before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says.
|
|
209
|
+
* Exported for its tests, which read its recipe on a host with no Cursor release installed. */
|
|
210
|
+
export declare function cursorOptions(facts: AdapterFacts): AcpPlanEntryOptions;
|
|
204
211
|
/** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
|
|
205
212
|
* server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
|
|
206
213
|
export declare const BUILTIN_OWN_KEYS: readonly string[];
|
package/dist/harness-table.js
CHANGED
|
@@ -334,8 +334,9 @@ async function gooseLaunch(launch) {
|
|
|
334
334
|
* (`ownKeys`), its model one Cursor lists for that key (`cursor/<model-id>`, `cursor/default` for Cursor's own). Listed
|
|
335
335
|
* only once its owner has installed it (`agentrun harness install cursor`): `missing` is its release, looked up and
|
|
336
336
|
* verified (harness-cursor.ts cursorMissing), and `beforeStart` checks its launcher and every file beside it again
|
|
337
|
-
* before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says.
|
|
338
|
-
|
|
337
|
+
* before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says.
|
|
338
|
+
* Exported for its tests, which read its recipe on a host with no Cursor release installed. */
|
|
339
|
+
export function cursorOptions(facts) {
|
|
339
340
|
/** Cursor's launcher, or the HarnessUnavailable that says why it is not here, with the fix (install, pins) it names. */
|
|
340
341
|
const launcher = async (env) => {
|
|
341
342
|
const found = await cursorMissing(env);
|
|
@@ -351,7 +352,9 @@ function cursorOptions(facts) {
|
|
|
351
352
|
card: cursorCardOf,
|
|
352
353
|
missing: async (env) => void (await launcher(env)),
|
|
353
354
|
recipe: async (launch) => {
|
|
354
|
-
|
|
355
|
+
// A held run its model kept from running is laid no key (claim-secrets.ts) and never starts Cursor (acpPlanEntryOf),
|
|
356
|
+
// so it is never refused for the key: its claim holds its computer.
|
|
357
|
+
if (!launch.held && !launch.env[CURSOR_KEY])
|
|
355
358
|
throw new HarnessUnavailable(`${facts.label} runs on your Cursor API key, and ${CURSOR_KEY} is not set where AgentRun starts: set it there (it is handed to Cursor's runs alone), then restart AgentRun.`);
|
|
356
359
|
const acp = acpPackage();
|
|
357
360
|
let limits;
|
package/dist/host-tools.d.ts
CHANGED
|
@@ -18,7 +18,8 @@ export type ToolResults = Map<string, {
|
|
|
18
18
|
* `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
|
|
19
19
|
* document or a task of this run, never another's. A remote executor (workspace/executors.ts
|
|
20
20
|
* piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
|
|
21
|
-
* `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here
|
|
21
|
+
* `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here, but to a tool
|
|
22
|
+
* whose binding runs each call once (RUNS_ONCE), whose `memo` is the call's own. */
|
|
22
23
|
export declare const HOST_API_MEMBERS: readonly ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
|
|
23
24
|
/** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
|
|
24
25
|
export declare const RUN_ONLY_MEMBERS: readonly ["conversationId", "snapshot", "waitForTask"];
|
|
@@ -44,8 +45,22 @@ export interface HostToolCtx {
|
|
|
44
45
|
refused: string;
|
|
45
46
|
} | undefined;
|
|
46
47
|
}
|
|
48
|
+
/** How a tool with no host row (tool-list.ts `replay`) runs as a host tool, given by its own binding: the browser on a
|
|
49
|
+
* harness other than pi (runner/adapter-run-spec.ts browserHostTools). It is never replay-safe, so its call's intent is
|
|
50
|
+
* flushed before it acts (runner/side-effects.ts) and a crash at any point leaves the call's start on the record. Each
|
|
51
|
+
* call runs once, and its api's `memo` is the call's own, empty at its start and gone at its end: no other call, before,
|
|
52
|
+
* after or beside it, reads it. pi's memo is a tool task's, durable across that task's invocations, which lets pi run a
|
|
53
|
+
* cut call again from what it kept; a call that runs once has one invocation. So a run that resumes with such a call in
|
|
54
|
+
* flight (its runner stopped or crashed) has that call ended interrupted by the record's open ("may or may not have
|
|
55
|
+
* taken effect", runner/adapter-loop.ts openCliRecord), never runs it again, and the model goes on from that answer.
|
|
56
|
+
* After a crash the session it drove is the binding's reconcile's to take back on the next claim; a runner's own stop
|
|
57
|
+
* lets it go (the loop's beforeRelease on a shutdown). */
|
|
58
|
+
export declare const RUNS_ONCE: {
|
|
59
|
+
readonly replay: "never";
|
|
60
|
+
readonly memo: "call";
|
|
61
|
+
};
|
|
47
62
|
/** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
|
|
48
63
|
* the paid-call seam, then the tool on the run's environment and harness, its answer the text a
|
|
49
64
|
* model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
|
|
50
|
-
* `name` is not one a host runs (tool-list.ts `replay`). */
|
|
51
|
-
export declare function hostToolOf(name: string, tool: ToolRegistration, ctx: HostToolCtx): HostTool | undefined;
|
|
65
|
+
* `name` is not one a host runs (tool-list.ts `replay`) and its binding gives no `own` way to run it (RUNS_ONCE). */
|
|
66
|
+
export declare function hostToolOf(name: string, tool: ToolRegistration, ctx: HostToolCtx, own?: typeof RUNS_ONCE): HostTool | undefined;
|
package/dist/host-tools.js
CHANGED
|
@@ -19,7 +19,8 @@ export { cutUtf8, MAX_BYTES, MAX_LINES } from "./workspace/executors.js";
|
|
|
19
19
|
* `waitForTask` are the run's own Harness's (run.harness, the claim's journal on the runner), as `commit` is: a
|
|
20
20
|
* document or a task of this run, never another's. A remote executor (workspace/executors.ts
|
|
21
21
|
* piExecutor) has no run Harness and gives none of these three (RUN_ONLY_MEMBERS); the coding tools it runs read none.
|
|
22
|
-
* `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here
|
|
22
|
+
* `memo` and `taskId` are a pi tool task's own, which a host tool runs in none of: they are not given here, but to a tool
|
|
23
|
+
* whose binding runs each call once (RUNS_ONCE), whose `memo` is the call's own. */
|
|
23
24
|
export const HOST_API_MEMBERS = ["env", "callId", "commit", "output", "outputWindow", "retainedOutput", "diagnostic", "agent", "models", "conversationId", "snapshot", "waitForTask"];
|
|
24
25
|
/** The members a host tool's api gives only on a run's Harness: a remote executor's api has none of them. */
|
|
25
26
|
export const RUN_ONLY_MEMBERS = ["conversationId", "snapshot", "waitForTask"];
|
|
@@ -32,12 +33,33 @@ const hostApi = (given) => new Proxy(given, {
|
|
|
32
33
|
});
|
|
33
34
|
/** The tools whose result is pi's own words about a path (`Successfully wrote to <path>`), never a file's text. */
|
|
34
35
|
const SAYS_PATH = new Set(["write", "edit"]);
|
|
36
|
+
/** How a tool with no host row (tool-list.ts `replay`) runs as a host tool, given by its own binding: the browser on a
|
|
37
|
+
* harness other than pi (runner/adapter-run-spec.ts browserHostTools). It is never replay-safe, so its call's intent is
|
|
38
|
+
* flushed before it acts (runner/side-effects.ts) and a crash at any point leaves the call's start on the record. Each
|
|
39
|
+
* call runs once, and its api's `memo` is the call's own, empty at its start and gone at its end: no other call, before,
|
|
40
|
+
* after or beside it, reads it. pi's memo is a tool task's, durable across that task's invocations, which lets pi run a
|
|
41
|
+
* cut call again from what it kept; a call that runs once has one invocation. So a run that resumes with such a call in
|
|
42
|
+
* flight (its runner stopped or crashed) has that call ended interrupted by the record's open ("may or may not have
|
|
43
|
+
* taken effect", runner/adapter-loop.ts openCliRecord), never runs it again, and the model goes on from that answer.
|
|
44
|
+
* After a crash the session it drove is the binding's reconcile's to take back on the next claim; a runner's own stop
|
|
45
|
+
* lets it go (the loop's beforeRelease on a shutdown). */
|
|
46
|
+
export const RUNS_ONCE = { replay: "never", memo: "call" };
|
|
47
|
+
/** One call's memo, as pi's tool task's reads: `memo(name, context)` reads it, `memo(name, candidate, context)` stores the
|
|
48
|
+
* candidate unless one is stored and answers the one stored. */
|
|
49
|
+
function callMemo() {
|
|
50
|
+
const kept = new Map();
|
|
51
|
+
return (async (name, ...rest) => {
|
|
52
|
+
if (rest.length >= 2 && !kept.has(name))
|
|
53
|
+
kept.set(name, rest[0]);
|
|
54
|
+
return kept.get(name);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
35
57
|
/** One pi ToolRegistration `tool` (named `name` by its catalog name) as the kernel's HostTool an adapter session takes:
|
|
36
58
|
* the paid-call seam, then the tool on the run's environment and harness, its answer the text a
|
|
37
59
|
* model reads (the output or the failure, a write's or an error's path named relative to the run's folder). Undefined when
|
|
38
|
-
* `name` is not one a host runs (tool-list.ts `replay`). */
|
|
39
|
-
export function hostToolOf(name, tool, ctx) {
|
|
40
|
-
const replay = replayOf(name);
|
|
60
|
+
* `name` is not one a host runs (tool-list.ts `replay`) and its binding gives no `own` way to run it (RUNS_ONCE). */
|
|
61
|
+
export function hostToolOf(name, tool, ctx, own) {
|
|
62
|
+
const replay = own?.replay ?? replayOf(name);
|
|
41
63
|
if (!replay)
|
|
42
64
|
return undefined;
|
|
43
65
|
return {
|
|
@@ -66,6 +88,7 @@ export function hostToolOf(name, tool, ctx) {
|
|
|
66
88
|
models: createModels(),
|
|
67
89
|
conversationId: ROOT_CONVERSATION_ID,
|
|
68
90
|
snapshot: ctx.snapshot, waitForTask: ctx.waitForTask,
|
|
91
|
+
...(own ? { memo: callMemo() } : {}),
|
|
69
92
|
});
|
|
70
93
|
// A tool that throws (bash on a non-zero exit or a timeout) still answers with its output, as pi's harness does;
|
|
71
94
|
// one that answers a failure as an error result is kept as it is.
|
package/dist/import.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type StorageWrite } from "@earendil-works/pi-durable";
|
|
2
2
|
import { type EntryLike } from "./timeline/index.js";
|
|
3
|
-
import { type Locator, type Session, type Source } from "@parcha/agentrun-import";
|
|
3
|
+
import { cacheTotals, type Locator, type Session, type Source } from "@parcha/agentrun-import";
|
|
4
4
|
import { type Found } from "./import-summary.js";
|
|
5
5
|
import { type Store } from "./store/index.js";
|
|
6
6
|
/** What `runImport`, `planImport` and the CLI reach of the server's open store: the agents it reads and writes, the runs it
|
|
@@ -197,6 +197,13 @@ export declare function transcriptOf(session: Session, cut: (value: unknown) =>
|
|
|
197
197
|
batches: StorageWrite[][];
|
|
198
198
|
entries: EntryLike[];
|
|
199
199
|
};
|
|
200
|
+
/** A run's cache as its metrics keep it (GET /v2/wrapped sums them): the cache read and the whole prompt (input, cache
|
|
201
|
+
* read and write) of its requests and its subagents', its hit rate's parts; its breaks by cause, their extra cost
|
|
202
|
+
* (USD) and how many are unpriced. Numbers alone. */
|
|
203
|
+
export type RunCache = {
|
|
204
|
+
read: number;
|
|
205
|
+
prompt: number;
|
|
206
|
+
} & Omit<ReturnType<typeof cacheTotals>, "sessions">;
|
|
200
207
|
/** What an imported agent is told when its project has no CLAUDE.md or AGENTS.md (or the harness's own file): an agentic
|
|
201
208
|
* revision with no instructions is refused every run (runnable.ts), so an import never writes one. */
|
|
202
209
|
export declare const importedInstructions: (project: string, source: Source) => string;
|
package/dist/import.js
CHANGED
|
@@ -14,7 +14,7 @@ import { BACKGROUND_CONTEXT as ctx } from "@earendil-works/chord/context";
|
|
|
14
14
|
import { AssistantEntry, ROOT_CONVERSATION_ID, ToolResultEntry, UserEntry } from "@earendil-works/pi-durable";
|
|
15
15
|
import { REQUEST_COST, runMetricsOf } from "./timeline/index.js";
|
|
16
16
|
import { defaultData } from "./files.js";
|
|
17
|
-
import { childrenOf, HARNESS_OF, inOrder, locatorKey, locatorOf, locatorParent, locatorSize, mirroredIn, mostEffortOf, ownRequests, priceRequests, READERS, readSession, SOURCE_NAMES, SOURCES, sessionKey, sessionLocators, withSubagentCosts } from "@parcha/agentrun-import";
|
|
17
|
+
import { CACHE_SOURCES, cacheTotals, childrenOf, conversationOf, fileCache, HARNESS_OF, inOrder, locatorKey, locatorOf, locatorParent, locatorSize, mirroredIn, mostEffortOf, ownRequests, priceRequests, READERS, readSession, SOURCE_NAMES, SOURCES, sessionKey, sessionLocators, sessionBreaks, withSubagentCosts } from "@parcha/agentrun-import";
|
|
18
18
|
import { hoursOf, summaryLines } from "./import-summary.js";
|
|
19
19
|
import { stopOnce } from "./stop-signals.js";
|
|
20
20
|
import { catalogPrices, providerModels } from "./model.js";
|
|
@@ -942,7 +942,7 @@ async function holdBack(children, parts, childIds, now) {
|
|
|
942
942
|
* files (Claude Code's), and those naming its thread (Codex's, whichever of its files they ran under). One gone or
|
|
943
943
|
* unreadable is passed over. All of them are held at once, so their sizes are taken from `budget` (what the run's own
|
|
944
944
|
* files left of MAX_RUN_BYTES) before each is read: RunTooLarge once it is spent, as one file over the cap alone spends it. */
|
|
945
|
-
async function readChildren(plan, session, parts, seen, budget) {
|
|
945
|
+
async function readChildren(plan, session, parts, seen, budget, chain = false) {
|
|
946
946
|
const out = [];
|
|
947
947
|
const visited = new Set();
|
|
948
948
|
const under = async (owner) => {
|
|
@@ -958,7 +958,7 @@ async function readChildren(plan, session, parts, seen, budget) {
|
|
|
958
958
|
// No subagent is passed over for its size: the run would be kept without its usage.
|
|
959
959
|
if (!fits(budget, stats.bytes))
|
|
960
960
|
throw new RunTooLarge();
|
|
961
|
-
const child = await readSession(locator, session.source, { seen, lookups: lookupsOf(plan) }).catch(() => undefined);
|
|
961
|
+
const child = await readSession(locator, session.source, { seen, lookups: lookupsOf(plan), ...(chain ? { chain } : {}) }).catch(() => undefined);
|
|
962
962
|
if (!child)
|
|
963
963
|
continue;
|
|
964
964
|
out.push(child);
|
|
@@ -1260,6 +1260,34 @@ export function transcriptOf(session, cut, children = []) {
|
|
|
1260
1260
|
/** What a run's requests cost at the catalog's list prices, each at its own provider's entry for its model: undefined when
|
|
1261
1261
|
* one request's tokens are unknown or its provider does not list its model (the request was served at a price no one
|
|
1262
1262
|
* lists here). A provider's $0 entry is $0. A request of no tokens costs nothing at any price. */
|
|
1263
|
+
/** Whether a source's runs are analyzed for their cache as they are imported: the sources that write a chain
|
|
1264
|
+
* (CACHE_SOURCES), read with it. */
|
|
1265
|
+
const cached = (source) => CACHE_SOURCES.includes(source);
|
|
1266
|
+
/** `parts` (every file of a run read, in order, each with its chain) and its subagents analyzed as cacheHome analyzes a
|
|
1267
|
+
* session: each file alone, then joined into one conversation (sessionBreaks), at the catalog's prices. */
|
|
1268
|
+
async function runCacheOf(parts, subagents, catalog) {
|
|
1269
|
+
const options = { catalog };
|
|
1270
|
+
let read = 0;
|
|
1271
|
+
let prompt = 0;
|
|
1272
|
+
for (const turn of [...parts, ...subagents].flatMap((session) => session.turns)) {
|
|
1273
|
+
if (turn.role !== "assistant" || !turn.usage)
|
|
1274
|
+
continue;
|
|
1275
|
+
read += turn.usage.cacheRead;
|
|
1276
|
+
prompt += turn.usage.input + turn.usage.cacheRead + turn.usage.cacheWrite;
|
|
1277
|
+
}
|
|
1278
|
+
const fileOf = async (session) => ({ file: await fileCache(session, options), requests: session.turns.filter((turn) => turn.role === "assistant").length });
|
|
1279
|
+
const files = [];
|
|
1280
|
+
for (const part of parts)
|
|
1281
|
+
files.push(await fileOf(part));
|
|
1282
|
+
// Each subagent a conversation of its own, in the order read: a thread that goes on in another rollout is one.
|
|
1283
|
+
const conversations = new Map();
|
|
1284
|
+
for (const child of subagents) {
|
|
1285
|
+
const key = conversationOf(locatorOf(child), child);
|
|
1286
|
+
(conversations.get(key) ?? conversations.set(key, []).get(key)).push(await fileOf(child));
|
|
1287
|
+
}
|
|
1288
|
+
const { sessions: _sessions, ...totals } = cacheTotals([{ breaks: await sessionBreaks(files, [...conversations.values()], options) }]);
|
|
1289
|
+
return { read, prompt, ...totals };
|
|
1290
|
+
}
|
|
1263
1291
|
async function estimateOf(entries, catalog) {
|
|
1264
1292
|
// Unknown when one answer priced here has unknown tokens (a failed one's counts are its own, as runMetricsOf reads them).
|
|
1265
1293
|
if (runMetricsOf(entries.filter((entry) => entry.kind === "pi.assistant")).unmetered > 0)
|
|
@@ -1400,7 +1428,7 @@ export async function runImport(store, plan, options) {
|
|
|
1400
1428
|
over = true;
|
|
1401
1429
|
break;
|
|
1402
1430
|
}
|
|
1403
|
-
const part = stats ? await readSession(locatorOf(entry), listed.source, { seen: seen(listed.source), lookups: lookupsOf(plan) }).catch((error) => void report.skipped.push(unread(file, error))) : void report.skipped.push({ what: file, why: "gone since it was listed", kind: "vanished" });
|
|
1431
|
+
const part = stats ? await readSession(locatorOf(entry), listed.source, { seen: seen(listed.source), lookups: lookupsOf(plan), ...(cached(listed.source) ? { chain: true } : {}) }).catch((error) => void report.skipped.push(unread(file, error))) : void report.skipped.push({ what: file, why: "gone since it was listed", kind: "vanished" });
|
|
1404
1432
|
if (!part || !stats)
|
|
1405
1433
|
continue;
|
|
1406
1434
|
searched.push(part);
|
|
@@ -1433,7 +1461,7 @@ export async function runImport(store, plan, options) {
|
|
|
1433
1461
|
// holding a key counts among the keys removed.
|
|
1434
1462
|
const keptAs = text(session.id) === session.id ? session.id : redactedId(session.id);
|
|
1435
1463
|
session.id = keptAs;
|
|
1436
|
-
const subagents = await readChildren(plan, session, searched, seen(listed.source), budget).catch((error) => {
|
|
1464
|
+
const subagents = await readChildren(plan, session, searched, seen(listed.source), budget, cached(listed.source)).catch((error) => {
|
|
1437
1465
|
if (!(error instanceof RunTooLarge))
|
|
1438
1466
|
throw error;
|
|
1439
1467
|
report.skipped.push(tooLarge(listed));
|
|
@@ -1455,6 +1483,9 @@ export async function runImport(store, plan, options) {
|
|
|
1455
1483
|
const estimate = costUsd === undefined ? await estimateOf([...entries, ...subagents.flatMap(entriesOf)], catalog) : undefined;
|
|
1456
1484
|
if (estimate !== undefined)
|
|
1457
1485
|
Object.assign(metrics, { costUsdEst: estimate, costBasis: "catalog" });
|
|
1486
|
+
// Its cache, for GET /v2/wrapped: numbers alone, from every file of it read (copies too, as cacheHome joins them).
|
|
1487
|
+
if (cached(session.source))
|
|
1488
|
+
Object.assign(metrics, { cache: await runCacheOf(searched, subagents, await catalog()) });
|
|
1458
1489
|
const answer = session.turns.findLast((t) => t.role === "assistant" && t.text)?.text;
|
|
1459
1490
|
// Cut, then put on one line and clipped: a key the clip cut short, or a passphrase whose spaces were changed, would
|
|
1460
1491
|
// match no cut.
|
package/dist/key-check.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// costs nothing, given CHECK_MS to answer. A 401 is the provider refusing the key, and the save is refused with nothing
|
|
3
3
|
// kept; a 2xx is the key accepted. A 403 is the provider knowing the key and not answering this call: a key scoped away
|
|
4
4
|
// from it (an OpenAI restricted key without the Models permission) may still do its tools' work, so it is never refused.
|
|
5
|
-
// That, no such call for the provider, no answer in time, the network, a redirect (never followed: Node's fetch carries
|
|
5
|
+
// That, no such call for the provider, a base URL the key may not go to (never sent one), no answer in time, the network, a redirect (never followed: Node's fetch carries
|
|
6
6
|
// a key's own header, x-api-key or x-bb-api-key, to wherever one points), or any other status keeps the key as not
|
|
7
7
|
// checked, saying why: an answer that does not say whether a key works never stops a save.
|
|
8
8
|
// Never a paid request: each call below cites the provider's pages that show it is not billed. No outcome holds the
|
|
9
9
|
// key: the provider's first sentence is quoted only when it holds no KEY_PIECE characters of the key in a row.
|
|
10
|
+
import { httpsBase } from "@parcha/agentrun-computer";
|
|
11
|
+
import { typesafeBase } from "./decisions.js";
|
|
10
12
|
import { MONID_API } from "./monid.js";
|
|
13
|
+
import { ANTHROPIC_ORIGIN, gatewayBase } from "./provider.js";
|
|
11
14
|
import { isObject } from "./validate.js";
|
|
12
15
|
/** How long a provider has to answer a check. */
|
|
13
16
|
export const CHECK_MS = 5_000;
|
|
@@ -15,7 +18,9 @@ export const CHECK_MS = 5_000;
|
|
|
15
18
|
const KEY_PIECE = 6;
|
|
16
19
|
/** The most characters of a provider's words quoted. */
|
|
17
20
|
const QUOTE = 200;
|
|
18
|
-
|
|
21
|
+
/** The base a vendor's calls go to: `set`, the server's variable `name`, else the vendor's own, held to the rule for a URL a
|
|
22
|
+
* key goes to (httpsBase), which throws in words naming the variable and the URL's origin alone. */
|
|
23
|
+
const base = (set, fallback, name) => httpsBase(set?.trim() || fallback, name);
|
|
19
24
|
/** Each provider's check, by key id (tool-keys.ts' TOOL_KEYS, and a model provider's key where the server keeps one),
|
|
20
25
|
* made with the key and the server's environment, at the base this server sends that provider's calls to. */
|
|
21
26
|
export const KEY_CHECKS = {
|
|
@@ -27,17 +32,18 @@ export const KEY_CHECKS = {
|
|
|
27
32
|
parallel: (key) => ({ url: "https://api.parallel.ai/v1/monitors?limit=1", headers: { "x-api-key": key } }),
|
|
28
33
|
// A list of the key's projects: Browserbase bills a session's browser time and proxy bandwidth, and this opens no
|
|
29
34
|
// session (https://docs.browserbase.com/reference/api/list-projects, https://docs.browserbase.com/account/billing/plans).
|
|
30
|
-
browserbase: (key, env) => ({ url: `${base(env.BROWSERBASE_BASE_URL, "https://api.browserbase.com")}/v1/projects`, headers: { "x-bb-api-key": key } }),
|
|
35
|
+
browserbase: (key, env) => ({ url: `${base(env.BROWSERBASE_BASE_URL, "https://api.browserbase.com", "BROWSERBASE_BASE_URL")}/v1/projects`, headers: { "x-bb-api-key": key } }),
|
|
31
36
|
// A list of the key's browser sessions, one at most: Kernel bills a browser's running time, and this starts none
|
|
32
37
|
// (https://www.kernel.sh/docs/api-reference/browsers/list-browser-sessions, https://www.kernel.sh/docs/info/pricing).
|
|
33
|
-
kernel: (key, env) => ({ url: `${base(env.KERNEL_BASE_URL, "https://api.onkernel.com")}/browsers?limit=1`, headers: { authorization: `Bearer ${key}` } }),
|
|
38
|
+
kernel: (key, env) => ({ url: `${base(env.KERNEL_BASE_URL, "https://api.onkernel.com", "KERNEL_BASE_URL")}/browsers?limit=1`, headers: { authorization: `Bearer ${key}` } }),
|
|
34
39
|
// A list of the account's models: TypeSafe prices a System One request's input tokens
|
|
35
40
|
// (https://docs.typesafe.ai/api/list-models, https://docs.typesafe.ai/models).
|
|
36
|
-
typesafe: (key, env) => ({ url: `${
|
|
41
|
+
typesafe: (key, env) => ({ url: `${typesafeBase(env)}/v1/models`, headers: { authorization: `Bearer ${key}` } }),
|
|
37
42
|
// A model provider's key: its list of models, or OpenRouter's record of the key; each prices tokens, and these use none
|
|
38
43
|
// (https://platform.claude.com/docs/en/api/models/list, https://openrouter.ai/docs/api-reference/limits). OpenAI's is
|
|
39
|
-
// in NOT_CHECKED.
|
|
40
|
-
|
|
44
|
+
// in NOT_CHECKED. ANTHROPIC_BASE_URL is the gateway the model path sends Anthropic's key to, under that path's rule
|
|
45
|
+
// (gatewayBase: plain http to this machine alone, one trailing /v1 off), so the check goes where the runs go.
|
|
46
|
+
anthropic: (key, env) => ({ url: `${env.ANTHROPIC_BASE_URL ? gatewayBase("ANTHROPIC_BASE_URL", env.ANTHROPIC_BASE_URL) : ANTHROPIC_ORIGIN}/v1/models?limit=1`, headers: { "x-api-key": key, "anthropic-version": "2023-06-01" } }),
|
|
41
47
|
openrouter: (key) => ({ url: "https://openrouter.ai/api/v1/key", headers: { authorization: `Bearer ${key}` } }),
|
|
42
48
|
// Particle bills inference tokens; its authenticated model listing performs no generation
|
|
43
49
|
// (https://docs.particle.ai/models, https://docs.particle.ai/pricing).
|
|
@@ -82,7 +88,15 @@ export async function checkKey(row, key, env, fetcher, ms = CHECK_MS, stop, name
|
|
|
82
88
|
return notChecked(`${row.label} has no call that costs nothing to check a key with`);
|
|
83
89
|
if (!fetcher)
|
|
84
90
|
return notChecked(`This server runs on faux providers and has no fake ${row.label} to check the key with`);
|
|
85
|
-
|
|
91
|
+
let call;
|
|
92
|
+
try {
|
|
93
|
+
call = check(key, env);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// A base URL the key may not go to, refused by the variable's name in words that give its origin at most: nothing is sent.
|
|
97
|
+
return notChecked(`${row.label} was not checked: ${error.message}`);
|
|
98
|
+
}
|
|
99
|
+
const { url, ...init } = call;
|
|
86
100
|
let res;
|
|
87
101
|
try {
|
|
88
102
|
res = await fetcher(url, { ...init, redirect: "manual", signal: stop ? AbortSignal.any([AbortSignal.timeout(ms), stop]) : AbortSignal.timeout(ms) });
|