@parcha/agentrun-serve 0.1.0-beta.60 → 0.1.0-beta.62
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 +124 -0
- package/README.md +139 -22
- package/dist/acp-package.d.ts +4 -0
- package/dist/api-only.d.ts +23 -1
- package/dist/api-only.js +43 -4
- 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/browser-person.d.ts +1 -1
- package/dist/browser-person.js +1 -1
- package/dist/calendar/tools.js +1 -1
- package/dist/chatgpt-plan.d.ts +26 -8
- package/dist/chatgpt-plan.js +89 -21
- package/dist/claude-login.d.ts +12 -5
- package/dist/claude-login.js +28 -3
- package/dist/cli.js +61 -18
- 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-QnwGVBeU.js → backend-DEgVn5lC.js} +1 -1
- package/dist/console/assets/index-CG5tELph.js +639 -0
- package/dist/console/assets/share-CIeFK2Oe.js +6 -0
- package/dist/console/assets/{styles-CcceGcu2.js → styles-BGZxYkky.js} +2 -2
- 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/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/harness-check.js +2 -1
- package/dist/harness-recipe.d.ts +13 -2
- package/dist/harness-recipe.js +30 -7
- package/dist/harness-sign-in.js +2 -1
- package/dist/harness-table.d.ts +12 -3
- package/dist/harness-table.js +13 -8
- package/dist/import.d.ts +8 -1
- package/dist/import.js +36 -5
- package/dist/key-check.js +22 -8
- package/dist/key-refusal.js +6 -4
- package/dist/learn/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +2 -2
- package/dist/learned-nodes.d.ts +37 -0
- package/dist/learned-nodes.js +24 -0
- package/dist/local-model.d.ts +144 -0
- package/dist/local-model.js +214 -0
- package/dist/mcp-gateway.d.ts +24 -0
- package/dist/mcp-gateway.js +97 -8
- package/dist/mcp-probe.d.ts +7 -0
- package/dist/mcp-probe.js +7 -0
- 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 +42 -0
- package/dist/ollama-provider.js +118 -2
- package/dist/openapi.js +85 -16
- 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 +28 -11
- package/dist/place.js +43 -14
- package/dist/print.d.ts +3 -2
- package/dist/print.js +8 -6
- package/dist/redact/match.d.ts +17 -4
- package/dist/redact/match.js +57 -15
- package/dist/run-export.js +4 -2
- package/dist/run-launch.js +16 -3
- 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-usage.js +3 -2
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +16 -6
- package/dist/runner/adapter-loop.d.ts +8 -1
- package/dist/runner/adapter-loop.js +148 -29
- package/dist/runner/adapter-run-spec.d.ts +9 -6
- package/dist/runner/adapter-run-spec.js +38 -52
- package/dist/runner/adapters/index.d.ts +4 -0
- package/dist/runner/adapters/index.js +2 -1
- package/dist/runner/adapters/pi.d.ts +3 -2
- package/dist/runner/adapters/pi.js +3 -1
- package/dist/runner/audit.d.ts +1 -1
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +18 -7
- package/dist/runner/cli-run-spec.js +24 -17
- package/dist/runner/compare-end.d.ts +1 -1
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.d.ts +14 -0
- package/dist/runner/harness-loops.js +51 -5
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/live-ticker.js +5 -4
- package/dist/runner/loop-contract.d.ts +4 -1
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +24 -4
- package/dist/runner/mcp-run.js +47 -2
- package/dist/runner/meta-tools.js +4 -4
- package/dist/runner/metrics.d.ts +6 -0
- package/dist/runner/metrics.js +12 -4
- package/dist/runner/monid-run.js +3 -1
- package/dist/runner/native-loop.js +3 -3
- package/dist/runner/redact.d.ts +3 -0
- package/dist/runner/redact.js +7 -0
- package/dist/runner/run-child-host.d.ts +10 -6
- package/dist/runner/run-child-host.js +44 -29
- package/dist/runner/run-child.js +1 -0
- package/dist/runner/runner.js +2 -0
- package/dist/runner/sdk-loop.js +5 -3
- package/dist/runner/workflow-calls.d.ts +5 -1
- package/dist/runner/workflow-calls.js +65 -19
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +3 -1
- package/dist/runner/workflow-spec.d.ts +4 -0
- package/dist/runner/workflow-spec.js +18 -13
- package/dist/runs-over-store.d.ts +2 -2
- package/dist/runs-over-store.js +1 -1
- package/dist/secret-cut.js +7 -4
- package/dist/secret-rules.d.ts +0 -1
- package/dist/secret-rules.js +122 -88
- package/dist/server.d.ts +17 -1
- package/dist/server.js +208 -69
- package/dist/share-host.d.ts +111 -0
- package/dist/share-host.js +666 -0
- package/dist/slack.js +2 -1
- package/dist/store/postgres/migrate.js +3 -1
- package/dist/store-reads/analytics.d.ts +15 -0
- package/dist/store-reads/analytics.js +17 -0
- package/dist/store-reads/learning.d.ts +5 -4
- package/dist/store-reads/learning.js +7 -4
- 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-plane.d.ts +24 -1
- package/dist/tool-plane.js +75 -3
- package/dist/tools.d.ts +12 -2
- package/dist/tools.js +42 -7
- package/dist/trigger-composio.js +1 -1
- package/dist/trigger-launch-hook.d.ts +2 -2
- package/dist/trigger-launch-hook.js +1 -1
- package/dist/triggers.d.ts +7 -4
- package/dist/triggers.js +4 -4
- 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/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 +12 -3
- 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/dist/console/assets/index-DZi-muIj.js +0 -629
- package/dist/console/assets/share-pz61zIn9.js +0 -6
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
|
package/dist/errors.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export declare const ERROR_STATUS: {
|
|
|
69
69
|
readonly model_key_required: 422;
|
|
70
70
|
readonly runner_refused: 503;
|
|
71
71
|
readonly api_keys_full: 409;
|
|
72
|
+
readonly local_model_pulling: 409;
|
|
72
73
|
};
|
|
73
74
|
export type ErrorCode = keyof typeof ERROR_STATUS;
|
|
74
75
|
/** A field that is missing or wrong. `example`: a value the field accepts, read from the request body's schema (explain.ts). */
|
package/dist/errors.js
CHANGED
|
@@ -110,6 +110,8 @@ export const ERROR_STATUS = {
|
|
|
110
110
|
runner_refused: 503,
|
|
111
111
|
// POST /settings/api-keys (api-keys.ts) while the server keeps as many API keys as it takes: one is revoked first.
|
|
112
112
|
api_keys_full: 409,
|
|
113
|
+
// POST /settings/local-model/pull while a pull is under way here (local-model.ts): one at a time.
|
|
114
|
+
local_model_pulling: 409,
|
|
113
115
|
};
|
|
114
116
|
const RETRYABLE = new Set(["home_busy", "idempotency_in_progress", "rate_limited", "internal", "unavailable", "github_failed", "runs_in_flight", "learning_busy", "run_learning"]);
|
|
115
117
|
export class ApiError extends Error {
|
package/dist/harness-check.js
CHANGED
|
@@ -24,7 +24,7 @@ import { modelPortFor, SessionFenced } from "@parcha/agentrun-kernel";
|
|
|
24
24
|
import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
|
|
25
25
|
import { archivePlatform } from "./harness-archive.js";
|
|
26
26
|
import { egressProxy, egressVars } from "./harness-egress.js";
|
|
27
|
-
import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, writeChecked } from "./harness-recipe.js";
|
|
27
|
+
import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, recipeSaid, writeChecked } from "./harness-recipe.js";
|
|
28
28
|
import { recipeEntryOf } from "./harness-recipe-entry.js";
|
|
29
29
|
import { providerModels } from "./model.js";
|
|
30
30
|
import { capModelOf } from "./runner/cli-run-spec.js";
|
|
@@ -154,6 +154,7 @@ async function checkRun(options, held) {
|
|
|
154
154
|
held.push(...recipe.keys.map((name) => options.env[name]).filter((value) => typeof value === "string"));
|
|
155
155
|
const head = { recipe: { id: recipe.id, label: recipe.label, file: loaded.file, sha256: loaded.sha256 }, checkedAt };
|
|
156
156
|
const refuse = (code, message) => ({ ok: false, ...head, refused: { code, message: `${code}: ${message}` }, failures: [`${code}: ${message}`] });
|
|
157
|
+
say(recipeSaid(recipe.label, loaded.file, loaded.bundled));
|
|
157
158
|
say(`${recipe.label}: the recipe holds the five rules (${loaded.file})`);
|
|
158
159
|
// What the agent runs on: the recipe's keys, read from this shell, alone (a proxy-billed one's: none, the model proxy's).
|
|
159
160
|
// A check never runs on its owner's own sign-in, which a schedule, a check and a shared server never take
|
package/dist/harness-recipe.d.ts
CHANGED
|
@@ -136,15 +136,26 @@ export declare function recipeProblems(parsed: unknown): {
|
|
|
136
136
|
}[];
|
|
137
137
|
/** The recipe in `text`, or RecipeRefused with every problem. */
|
|
138
138
|
export declare function parseRecipe(text: string): Recipe;
|
|
139
|
-
/** The
|
|
139
|
+
/** The file `given` names, from `cwd`: the recipe the ACP package ships (bundledRecipePath: Google Antigravity's) when
|
|
140
|
+
* `given` is its name, else the file at that path. A name a file in `cwd` also holds is refused, saying both, so the
|
|
141
|
+
* owner's own file is never passed over silently (`./<name>` names the file). A bundled name is never a built-in
|
|
142
|
+
* harness's id: the recipe's own id is that name, and a built-in id is refused as a recipe's (parseRecipe). */
|
|
143
|
+
export declare function resolveRecipe(given: string, cwd?: string): {
|
|
144
|
+
file: string;
|
|
145
|
+
bundled: boolean;
|
|
146
|
+
};
|
|
147
|
+
/** Which recipe resolved, as a command says it before anything else: the one AgentRun ships, or the owner's file. */
|
|
148
|
+
export declare const recipeSaid: (label: string, file: string, bundled: boolean) => string;
|
|
149
|
+
/** The recipe at `path` (a file, or the name of a recipe AgentRun ships: resolveRecipe), read and loaded. */
|
|
140
150
|
export declare function loadRecipe(path: string): {
|
|
141
151
|
recipe: Recipe;
|
|
142
152
|
file: string;
|
|
143
153
|
sha256: string;
|
|
154
|
+
bundled: boolean;
|
|
144
155
|
};
|
|
145
156
|
/** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
|
|
146
157
|
export declare const releaseFor: (recipe: Recipe, platform?: string | undefined) => RecipeArchive | undefined;
|
|
147
|
-
/** The owner's command that installs the recipe at `file` into `data
|
|
158
|
+
/** The owner's command that installs the recipe at `file` into `data` (one AgentRun ships by its name, as goose's is). */
|
|
148
159
|
export declare const recipeInstallLine: (file: string, data: string, env?: NodeJS.ProcessEnv) => string;
|
|
149
160
|
/** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
|
|
150
161
|
export declare const recipeBinaryOf: (data: string, recipe: Recipe, release: RecipeArchive) => string;
|
package/dist/harness-recipe.js
CHANGED
|
@@ -400,9 +400,32 @@ export function parseRecipe(text) {
|
|
|
400
400
|
...(r.signIn ? { signIn: Object.freeze({ args: Object.freeze([...r.signIn.args]), homeArg: r.signIn.homeArg, ...(r.signIn.terms ? { terms: r.signIn.terms } : {}) }) } : {}),
|
|
401
401
|
});
|
|
402
402
|
}
|
|
403
|
-
/** The
|
|
403
|
+
/** The file `given` names, from `cwd`: the recipe the ACP package ships (bundledRecipePath: Google Antigravity's) when
|
|
404
|
+
* `given` is its name, else the file at that path. A name a file in `cwd` also holds is refused, saying both, so the
|
|
405
|
+
* owner's own file is never passed over silently (`./<name>` names the file). A bundled name is never a built-in
|
|
406
|
+
* harness's id: the recipe's own id is that name, and a built-in id is refused as a recipe's (parseRecipe). */
|
|
407
|
+
export function resolveRecipe(given, cwd = process.cwd()) {
|
|
408
|
+
const local = resolve(cwd, given);
|
|
409
|
+
const shipped = acpPackage()?.bundledRecipePath?.(given);
|
|
410
|
+
// The shipped file named by its path is the shipped recipe too.
|
|
411
|
+
if (!shipped)
|
|
412
|
+
return { file: local, bundled: bundledName(local) !== undefined };
|
|
413
|
+
if (existsSync(local))
|
|
414
|
+
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `${given} names both the recipe AgentRun ships (${shipped}) and the file ${local} in this directory: write ./${given} for your file, or name the shipped one from another directory` }]);
|
|
415
|
+
return { file: shipped, bundled: true };
|
|
416
|
+
}
|
|
417
|
+
/** The name of the recipe at `file` when the ACP package ships it, else undefined. */
|
|
418
|
+
const bundledName = (file) => {
|
|
419
|
+
const acp = acpPackage();
|
|
420
|
+
return acp?.BUNDLED_RECIPES?.find((each) => acp.bundledRecipePath?.(each) === resolve(file));
|
|
421
|
+
};
|
|
422
|
+
/** The word a printed command names the recipe at `file` by: its bundled name, else the file. */
|
|
423
|
+
const recipeWord = (file) => bundledName(file) ?? shellWord(file);
|
|
424
|
+
/** Which recipe resolved, as a command says it before anything else: the one AgentRun ships, or the owner's file. */
|
|
425
|
+
export const recipeSaid = (label, file, bundled) => `${label}: ${bundled ? `the recipe AgentRun ships (${file})` : `the recipe file ${file}`}`;
|
|
426
|
+
/** The recipe at `path` (a file, or the name of a recipe AgentRun ships: resolveRecipe), read and loaded. */
|
|
404
427
|
export function loadRecipe(path) {
|
|
405
|
-
const file =
|
|
428
|
+
const { file, bundled } = resolveRecipe(path);
|
|
406
429
|
let text;
|
|
407
430
|
try {
|
|
408
431
|
text = readFileSync(file, "utf8");
|
|
@@ -410,12 +433,12 @@ export function loadRecipe(path) {
|
|
|
410
433
|
catch (error) {
|
|
411
434
|
throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `the recipe file ${file} cannot be read (${error.code ?? error.message})` }]);
|
|
412
435
|
}
|
|
413
|
-
return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex") };
|
|
436
|
+
return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex"), bundled };
|
|
414
437
|
}
|
|
415
438
|
/** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
|
|
416
439
|
export const releaseFor = (recipe, platform = archivePlatform()) => (platform ? recipe.release.archives[platform] : undefined);
|
|
417
|
-
/** The owner's command that installs the recipe at `file` into `data
|
|
418
|
-
export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install
|
|
440
|
+
/** The owner's command that installs the recipe at `file` into `data` (one AgentRun ships by its name, as goose's is). */
|
|
441
|
+
export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install ${bundledName(file) ?? `--recipe ${shellWord(file)}`}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
|
419
442
|
/** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
|
|
420
443
|
export const recipeBinaryOf = (data, recipe, release) => join(installDirOf(data, recipe.id), insideHome(release.cmd));
|
|
421
444
|
/** A first-seen digest record in a file of its own (one line, the sha256), written once and never over another's. */
|
|
@@ -482,7 +505,7 @@ export const signInHomeOf = (data, id) => join(harnessesOf(data), `${id}.sign-in
|
|
|
482
505
|
* `<data>/harnesses/<id>.signed-in`, holding when and on which version. It holds nothing of the sign-in. */
|
|
483
506
|
export const signedInNoteOf = (data, id) => join(harnessesOf(data), `${id}.signed-in`);
|
|
484
507
|
/** The owner's command that signs the recipe at `file` in, on `data`. */
|
|
485
|
-
export const recipeSignInLine = (file, data, env = process.env) => `agentrun harness sign-in --recipe ${
|
|
508
|
+
export const recipeSignInLine = (file, data, env = process.env) => `agentrun harness sign-in --recipe ${recipeWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
|
486
509
|
/** Whether the agent's own sign-in ended well on `data` (signedInNoteOf): nothing in its folder is read to say so.
|
|
487
510
|
* Whether the sign-in still holds is the agent's to say when it runs (an ACP -32000, Authentication required). */
|
|
488
511
|
export const signedIn = (data, recipe) => recipe.signIn !== undefined && existsSync(signedInNoteOf(data, recipe.id));
|
|
@@ -521,4 +544,4 @@ export async function installRecipe(recipe, file, data, options = {}, env = proc
|
|
|
521
544
|
return { version: recipe.release.version, pinnedBy, ...done };
|
|
522
545
|
}
|
|
523
546
|
/** The owner's command that checks the recipe at `file`, installed into `data`. */
|
|
524
|
-
export const recipeCheckLine = (file, data, env = process.env) => `agentrun harness-check --recipe ${
|
|
547
|
+
export const recipeCheckLine = (file, data, env = process.env) => `agentrun harness-check --recipe ${recipeWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
|
package/dist/harness-sign-in.js
CHANGED
|
@@ -11,7 +11,7 @@ import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:f
|
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
import { archivePlatform } from "./harness-archive.js";
|
|
14
|
-
import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, signedInNoteOf, signInHomeOf } from "./harness-recipe.js";
|
|
14
|
+
import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, recipeSaid, signedInNoteOf, signInHomeOf } from "./harness-recipe.js";
|
|
15
15
|
/** A recipe with no signIn: it runs on its keys alone, and has nothing to sign in. */
|
|
16
16
|
export const HARNESS_NO_SIGN_IN = "HARNESS_NO_SIGN_IN";
|
|
17
17
|
/** The agent's own sign-in did not end well: its exit status, a signal, or the time ran out. */
|
|
@@ -35,6 +35,7 @@ export async function signInHarness(options) {
|
|
|
35
35
|
return { ok: false, code: error.code, message: error.message };
|
|
36
36
|
}
|
|
37
37
|
const { recipe, file } = loaded;
|
|
38
|
+
say(recipeSaid(recipe.label, file, loaded.bundled));
|
|
38
39
|
if (!recipe.signIn)
|
|
39
40
|
return refuse(HARNESS_NO_SIGN_IN, `${recipe.label}'s recipe names no signIn: it runs on its keys (${recipe.keys.join(", ") || "none"}), and has nothing to sign in`);
|
|
40
41
|
// The installed binary and every file beside it, the pinned ones, as a check finds them (recipeInstall, installHolds):
|
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[];
|
|
@@ -220,10 +227,12 @@ export declare const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
|
|
|
220
227
|
export declare const HARNESS_RECIPES_ENV = "AGENTRUN_HARNESS_RECIPES";
|
|
221
228
|
/** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
|
|
222
229
|
export declare const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
|
|
223
|
-
/** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING)
|
|
230
|
+
/** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING): each a
|
|
231
|
+
* file, or the name of a recipe AgentRun ships (harness-recipe.ts resolveRecipe). */
|
|
224
232
|
export declare const harnessRecipesOf: (given: readonly string[] | undefined, env: NodeJS.ProcessEnv) => string[];
|
|
225
|
-
/** HARNESS_RECIPES_ENV for the
|
|
226
|
-
* server's start
|
|
233
|
+
/** HARNESS_RECIPES_ENV for the recipes `files` names (each resolved by resolveRecipe: a shipped one's name to its file, a
|
|
234
|
+
* name a file here also holds refused), installed into `data`: none for none. `signIn` only where the server's start
|
|
235
|
+
* proved --harness-sign-in. */
|
|
227
236
|
export declare const harnessRecipesEnv: (files: readonly string[], data: string, { signIn }?: {
|
|
228
237
|
signIn?: boolean;
|
|
229
238
|
}) => NodeJS.ProcessEnv;
|
package/dist/harness-table.js
CHANGED
|
@@ -22,7 +22,7 @@ import { chooseModel, hostModel } from "./model.js";
|
|
|
22
22
|
import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
|
|
23
23
|
import { modelWire, routedId, wireOf, WIRES } from "./wires.js";
|
|
24
24
|
import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
|
|
25
|
-
import { loadRecipe } from "./harness-recipe.js";
|
|
25
|
+
import { loadRecipe, resolveRecipe } from "./harness-recipe.js";
|
|
26
26
|
import { recipeServerEntry } from "./harness-recipe-entry.js";
|
|
27
27
|
/** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
|
|
28
28
|
export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
@@ -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;
|
|
@@ -473,11 +476,13 @@ function recipesOf(env) {
|
|
|
473
476
|
}
|
|
474
477
|
/** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
|
|
475
478
|
export const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
|
|
476
|
-
/** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING)
|
|
479
|
+
/** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING): each a
|
|
480
|
+
* file, or the name of a recipe AgentRun ships (harness-recipe.ts resolveRecipe). */
|
|
477
481
|
export const harnessRecipesOf = (given, env) => given?.length ? [...given] : (env[HARNESS_RECIPES_SETTING] ?? "").split(",").map((name) => name.trim()).filter(Boolean);
|
|
478
|
-
/** HARNESS_RECIPES_ENV for the
|
|
479
|
-
* server's start
|
|
480
|
-
|
|
482
|
+
/** HARNESS_RECIPES_ENV for the recipes `files` names (each resolved by resolveRecipe: a shipped one's name to its file, a
|
|
483
|
+
* name a file here also holds refused), installed into `data`: none for none. `signIn` only where the server's start
|
|
484
|
+
* proved --harness-sign-in. */
|
|
485
|
+
export const harnessRecipesEnv = (files, data, { signIn = false } = {}) => (files.length ? { [HARNESS_RECIPES_ENV]: JSON.stringify({ data: resolve(data), files: files.map((file) => resolveRecipe(file).file), ...(signIn ? { signIn: true } : {}) }) } : {});
|
|
481
486
|
/** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
|
|
482
487
|
* server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
|
|
483
488
|
* harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
|
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) });
|
package/dist/key-refusal.js
CHANGED
|
@@ -249,7 +249,8 @@ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piec
|
|
|
249
249
|
* single-quoted dict through them does) and HTML's character references (named and numeric), so a "+", an encoded
|
|
250
250
|
* byte, an escape and a reference that decode to whitespace count no more than whitespace does, and any other escape
|
|
251
251
|
* counts as what the view keeps of the character it decodes to. A character that renders as nothing (a zero-width
|
|
252
|
-
* space, a soft hyphen
|
|
252
|
+
* space, a soft hyphen, a control character that is no whitespace: a NUL, an escape, a delete; U+FFFF; as it stands or as
|
|
253
|
+
* "\u0001", "\x01", "%01" or "" decodes) or a combining mark counts as nothing too: the views drop it (kept). So does a quote, an apostrophe
|
|
253
254
|
* or JSON's punctuation ("{", "}", "[", "]", ",", ":"), which the join views drop between a text's strings, and, with
|
|
254
255
|
* `fold` (a held value folds: learn/secrets.ts foldsHeld), a separator ("-", "_", ":", "."), which the fold view
|
|
255
256
|
* drops. Padding of any of them never hides the rest of a value split before it. Undefined, so the caller withholds
|
|
@@ -262,7 +263,7 @@ function peek(text, from, count, fold) {
|
|
|
262
263
|
/** The end of the run text[start, to) the pass reads for the head of a value whose rest comes after the run: as few of
|
|
263
264
|
* its last characters as hold `count` characters the matcher sees (at most a piece's worth), counted as peek counts
|
|
264
265
|
* them (with `fold` as peek's), so padding the views read as nothing (whitespace, a zero-width space, a soft hyphen, a
|
|
265
|
-
* quote or JSON's punctuation, a separator a folded value drops, an escape, a character reference or encoded bytes
|
|
266
|
+
* control character, U+FFFF, a quote or JSON's punctuation, a separator a folded value drops, an escape, a character reference or encoded bytes
|
|
266
267
|
* that decode to any of them) between that head and the run's end never pushes the head out of it. Read forward from
|
|
267
268
|
* a start moved back from `to`, twice as far each time, so it reads at most two pieces in all. Undefined, so the
|
|
268
269
|
* caller withholds the text, when that takes more than a piece of text. */
|
|
@@ -339,8 +340,9 @@ const HEX_PAIR = /^[0-9A-Fa-f]{2}$/;
|
|
|
339
340
|
const JOIN_DROPS = new Set(['"', "'", "{", "}", "[", "]", ",", ":"]);
|
|
340
341
|
/** What the fold view drops: the separators of a hex identifier. */
|
|
341
342
|
const FOLD_DROPS = new Set(["-", "_", ":", "."]);
|
|
342
|
-
/** How many characters the views keep of `chars` at the least (peek): squeezed
|
|
343
|
-
*
|
|
343
|
+
/** How many characters the views keep of `chars` at the least (peek): squeezed (a control character that is no
|
|
344
|
+
* whitespace, and U+FFFF, as the views drop them, count 0), less each the join view drops, and, with `fold`, each the
|
|
345
|
+
* fold view drops. */
|
|
344
346
|
function kept(chars, fold) {
|
|
345
347
|
let count = 0;
|
|
346
348
|
for (const char of squeeze(chars))
|
package/dist/learn/secrets.d.ts
CHANGED
|
@@ -64,6 +64,7 @@ export declare function excerptShown(text: string, shown: {
|
|
|
64
64
|
/** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
|
|
65
65
|
* hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
|
|
66
66
|
* shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
|
|
67
|
-
export declare function valueMatcher(values: readonly string[], { fold }?: {
|
|
67
|
+
export declare function valueMatcher(values: readonly string[], { fold, separated }?: {
|
|
68
68
|
fold?: boolean;
|
|
69
|
+
separated?: boolean;
|
|
69
70
|
}): (text: string) => boolean;
|
package/dist/learn/secrets.js
CHANGED
|
@@ -305,7 +305,7 @@ function heldFields(value) {
|
|
|
305
305
|
/** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
|
|
306
306
|
* hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
|
|
307
307
|
* shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
|
|
308
|
-
export function valueMatcher(values, { fold = true } = {}) {
|
|
308
|
+
export function valueMatcher(values, { fold = true, separated = false } = {}) {
|
|
309
309
|
const needles = derivedOf(values);
|
|
310
|
-
return (text) => holds(text, needles, { fold });
|
|
310
|
+
return (text) => holds(text, needles, { fold, separated });
|
|
311
311
|
}
|
package/dist/learned-nodes.d.ts
CHANGED
|
@@ -12,6 +12,43 @@ export declare const LEARNED_NODES = "agentrun.learned_nodes";
|
|
|
12
12
|
* however many nodes failed on the way and were recovered, a map's collected item say), or `failed` (it threw, or was
|
|
13
13
|
* refused before any node ran). */
|
|
14
14
|
export type LearnedEnded = "complete" | "escalated" | "failed";
|
|
15
|
+
/** The record of a learned_workflow call that ended `failed` with no node kept, where the tool kept none: an agent's call
|
|
16
|
+
* a crash cut mid-call, refused when it was issued again (adapter-loop.ts learnedEntry, learnedCallRan). An earlier
|
|
17
|
+
* attempt may have run nodes and spent, so it is no refusal: its $ is what its call id booked. */
|
|
18
|
+
export declare const failedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
|
|
19
|
+
call: string;
|
|
20
|
+
workflow: string;
|
|
21
|
+
digest: string;
|
|
22
|
+
caller: "platform" | "agent";
|
|
23
|
+
nodes: never[];
|
|
24
|
+
ended: LearnedEnded;
|
|
25
|
+
};
|
|
26
|
+
/** The record of a learned_workflow call refused before the tool saw it (`refused`: it ran nothing), which the loop keeps
|
|
27
|
+
* where the tool never ran: the platform's call its gate refused (runner/adapter-loop.ts serveFirst), and an agent's its
|
|
28
|
+
* gate refused with no attempt of it let go since its last refusal (adapter-loop.ts learnedEntry). Either reads
|
|
29
|
+
* `failed` once anything was booked under its call id, or while an attempt of it its gate let go was closed by no
|
|
30
|
+
* refusal (runner/workflow-calls.ts workflowCallsOf). */
|
|
31
|
+
export declare const refusedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
|
|
32
|
+
refused: true;
|
|
33
|
+
call: string;
|
|
34
|
+
workflow: string;
|
|
35
|
+
digest: string;
|
|
36
|
+
caller: "platform" | "agent";
|
|
37
|
+
nodes: never[];
|
|
38
|
+
ended: LearnedEnded;
|
|
39
|
+
};
|
|
40
|
+
/** The mark an agent's learned_workflow call on a CLI gets in the run's journal when its gate lets it go, before it runs:
|
|
41
|
+
* `{ call }`, its call's id (adapter-loop.ts sessionGate). An attempt a crash cuts before its record is kept leaves
|
|
42
|
+
* this, so a later refusal of the call issued again knows an attempt after any earlier refusal may have run. */
|
|
43
|
+
export declare const LEARNED_ALLOWED = "agentrun.learned_allowed";
|
|
44
|
+
/** Whether an attempt of learned_workflow call `call` may have run, from its root's `entries`: the newest of its allow
|
|
45
|
+
* marks (LEARNED_ALLOWED) and its records (LEARNED_NODES) is a mark, or a record not `refused`. Neither: `replayed`, the
|
|
46
|
+
* bridge's word that the call is issued again (a run begun before the marks existed has none), else no attempt was let
|
|
47
|
+
* go, so none ran. */
|
|
48
|
+
export declare function learnedCallRan(entries: readonly {
|
|
49
|
+
readonly kind: string;
|
|
50
|
+
readonly data?: unknown;
|
|
51
|
+
}[], call: string, replayed?: boolean): boolean;
|
|
15
52
|
/** The most nodes a call keeps: a map over a long list runs its body once per item. */
|
|
16
53
|
export declare const LEARNED_NODES_MAX = 64;
|
|
17
54
|
/** One node of a learned workflow's run, as the DSL ended it (its `node.end` event): its label, its kind, how it ended
|