@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +10 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +41 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +9 -4
- package/dist/runner/main.js +12 -6
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.js +1 -1
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// The keys a plan-billed harness recipe runs on, saved for that harness alone (HARNESS.md#keys). Each is a sealed row of
|
|
2
|
+
// the one store's sealed_keys (server-keys.ts, AAD sealed_keys|<row>|sealed) named harness:<harness>:<KEY>, so a key saved
|
|
3
|
+
// for one harness is never another's, even under the same name; the store holds ciphertext alone. A value replaced or
|
|
4
|
+
// removed is kept sealed as a retired row (harness-retired:<harness>:<KEY>:<time>), up to RETIRED_KEPT per key, so the
|
|
5
|
+
// cut (the server's secretStores, and a runner's storeSecrets, which reads every sealed_keys row) still holds it, and a
|
|
6
|
+
// timeline written while it was live stays cut after it changes.
|
|
7
|
+
//
|
|
8
|
+
// The server reads and writes them through HarnessKeysOverStore (its Settings → Harness keys routes, owner only). A
|
|
9
|
+
// runner opens a claim's own at its claim (openHarnessKeys), for that run's harness alone, and lays them on its adapter's
|
|
10
|
+
// environment where only the agent's start reads them (runner/cli-run-spec.ts): never on its tools, never another run's.
|
|
11
|
+
import { ApiError, invalid } from "./errors.js";
|
|
12
|
+
import { getSealedKey, putSealedKey, removeSealedKey } from "./server-keys.js";
|
|
13
|
+
import { registerSecretPage, registerSecretWrite, secretMeta, secretName } from "./secret-writes.js";
|
|
14
|
+
import { sealColumn, sealedAt, unsealColumn } from "./store/index.js";
|
|
15
|
+
// Every value saved here is a secret: saving one or removing it takes the owner's session (secret-writes.ts), never the
|
|
16
|
+
// token, and the token's refusal names the console's page.
|
|
17
|
+
registerSecretWrite("saveHarnessKey", () => true);
|
|
18
|
+
registerSecretWrite("deleteHarnessKey", () => true);
|
|
19
|
+
/** The console's page for these keys (Settings → Harness keys). */
|
|
20
|
+
export const HARNESS_KEYS_PAGE = "/#/settings/harness-keys";
|
|
21
|
+
registerSecretPage(["saveHarnessKey", "deleteHarnessKey"], HARNESS_KEYS_PAGE);
|
|
22
|
+
/** The plane of a harness key's name (its row's, and its view's: harness:<harness>:<KEY>). */
|
|
23
|
+
export const HARNESS_KEY_PLANE = "harness";
|
|
24
|
+
const RETIRED_PLANE = "harness-retired";
|
|
25
|
+
/** How many replaced or removed values of one key stay sealed for the cut: the oldest beyond it leaves. */
|
|
26
|
+
export const RETIRED_KEPT = 8;
|
|
27
|
+
/** A value's bounds: under 8 characters or holding whitespace, no cut could hold it whole (server-secrets.ts' floor). */
|
|
28
|
+
const MIN_VALUE = 8;
|
|
29
|
+
const MAX_VALUE_BYTES = 1024;
|
|
30
|
+
const UNFIT = /[\s\u0000-\u001f\u007f-\u009f]/;
|
|
31
|
+
/** The row (and view) name of `key` saved for `harness`. */
|
|
32
|
+
export const harnessKeyRow = (harness, key) => secretName(HARNESS_KEY_PLANE, harness, key);
|
|
33
|
+
const retiredPrefix = (harness, key) => `${secretName(RETIRED_PLANE, harness, key)}:`;
|
|
34
|
+
/** The keys of `names` saved for `harness` that open under `sealKey`, by name. One that does not open (another seal key, or
|
|
35
|
+
* damaged) reads as not saved, never a clear fallback. For a runner's claim, whose run is on that harness. */
|
|
36
|
+
export async function openHarnessKeys(store, sealKey, harness, names) {
|
|
37
|
+
const opened = {};
|
|
38
|
+
for (const name of names) {
|
|
39
|
+
const value = await getSealedKey(store, sealKey, harnessKeyRow(harness, name));
|
|
40
|
+
if (value !== undefined)
|
|
41
|
+
opened[name] = value;
|
|
42
|
+
}
|
|
43
|
+
return opened;
|
|
44
|
+
}
|
|
45
|
+
/** Whether every key of `names` has a row saved for `harness` (its bytes never opened): a trigger's check, and a runner's
|
|
46
|
+
* claim before it opens them. */
|
|
47
|
+
export async function harnessKeysSaved(store, harness, names) {
|
|
48
|
+
if (!names.length)
|
|
49
|
+
return false;
|
|
50
|
+
const rows = new Set((await store.sealedKeys.all()).map((row) => row.name));
|
|
51
|
+
return names.every((name) => rows.has(harnessKeyRow(harness, name)));
|
|
52
|
+
}
|
|
53
|
+
/** Whether a claim laid every key of `names` on `env` (layHarnessKeys: own, never enumerable, not empty), which is when
|
|
54
|
+
* a start takes the keys route (harness-recipe-entry.ts serverRoute). A variable of the same name the environment
|
|
55
|
+
* carries enumerable (one the operator's shell set) is never one: a run takes the keys saved for its harness alone. */
|
|
56
|
+
export function keysLaid(env, names) {
|
|
57
|
+
return names.length > 0 && names.every((name) => {
|
|
58
|
+
const laid = Object.getOwnPropertyDescriptor(env, name);
|
|
59
|
+
return laid !== undefined && laid.enumerable === false && typeof laid.value === "string" && laid.value !== "";
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** For each data directory a server in this process serves, the harnesses whose every key it holds saved
|
|
63
|
+
* (HarnessKeysOverStore keeps its own in step with its snapshot; another server's writes never touch it): what that
|
|
64
|
+
* server's listing, offers and trigger checks read (harness-recipe-entry.ts `why`), so a save shows with no restart. A
|
|
65
|
+
* start never reads it: it runs only on the keys its claim laid (keysLaid). The snapshot is loaded at the server's start,
|
|
66
|
+
* so a second server on the same store sees another's write at its next start; its runs fail closed meanwhile, since
|
|
67
|
+
* each claim opens the rows itself. */
|
|
68
|
+
const savedHere = new Map();
|
|
69
|
+
export const harnessKeysSavedHere = (data, harness) => savedHere.get(data)?.has(harness) === true;
|
|
70
|
+
/** The words a run no person started (a schedule's, a trigger's, a learned workflow's audit shadow or replay:
|
|
71
|
+
* run-launch.ts personStarted) on a plan-billed recipe is refused in at its claim (runner/harness-loops.ts,
|
|
72
|
+
* runner/cli-run-spec.ts): such a run takes keys saved for that harness, never its owner's own sign-in, and not every
|
|
73
|
+
* one is saved, or not every one opened. */
|
|
74
|
+
export const RECIPE_SIGN_IN_PERSON_ONLY = `A run its owner did not start (a scheduled or triggered run, a learned workflow's audit or replay) on a harness recipe billed to its vendor's plan runs on keys saved for that harness, never on its owner's own sign-in, and not every one of its keys is saved: save them in Settings → Harness keys (${HARNESS_KEYS_PAGE}), start this run yourself, or run the agent on a harness billed through this server's model proxy.`;
|
|
75
|
+
/** The words a trigger's message is refused in by a session its claim started with not every key of its plan-billed
|
|
76
|
+
* recipe laid (runner/adapter-loop.ts, the spec's personOnly): that session runs on its owner's own sign-in, or on
|
|
77
|
+
* nothing, whatever was saved since, so a turn no person sent never goes into it. */
|
|
78
|
+
export const RECIPE_TURN_PERSON_ONLY = `This run started on its owner's own sign-in (its harness recipe is billed to its vendor's plan, and its claim opened not every key saved for that harness), so a trigger's message never runs in it, keys saved since or not: message the run yourself, or target a run started once every key was saved in Settings → Harness keys (${HARNESS_KEYS_PAGE}).`;
|
|
79
|
+
/** Lays `keys` on `env` where only a direct read finds them: never enumerable, so no spread, copy or child environment
|
|
80
|
+
* built from `env` carries them (claim-secrets.ts withModelKeys). */
|
|
81
|
+
export function layHarnessKeys(env, keys) {
|
|
82
|
+
for (const [name, value] of Object.entries(keys))
|
|
83
|
+
Object.defineProperty(env, name, { value, enumerable: false, configurable: true, writable: false });
|
|
84
|
+
}
|
|
85
|
+
/** The saved harness keys over the one store, for the server (the one writer of these rows): a snapshot loaded once at
|
|
86
|
+
* start (load()) and kept in step with every write, so a read answers without a round trip. */
|
|
87
|
+
export class HarnessKeysOverStore {
|
|
88
|
+
store;
|
|
89
|
+
sealKey;
|
|
90
|
+
recipes;
|
|
91
|
+
data;
|
|
92
|
+
current = new Map();
|
|
93
|
+
retired = new Map();
|
|
94
|
+
/** The last write in flight (save, remove): each waits for the one before it, so two that overlap never read the same
|
|
95
|
+
* value as the one they replace, and every value a claim may have opened is retired. */
|
|
96
|
+
writing = Promise.resolve();
|
|
97
|
+
/** `work` once every write before it has settled, its failure its own. */
|
|
98
|
+
serial(work) {
|
|
99
|
+
const next = this.writing.then(work);
|
|
100
|
+
this.writing = next.catch(() => undefined);
|
|
101
|
+
return next;
|
|
102
|
+
}
|
|
103
|
+
/** `recipes`: the plan-billed recipes this server is started with (harness-table.ts planRecipesOf), the only harnesses
|
|
104
|
+
* whose keys it saves or shows. `data`: its data directory, which its registry (harnessKeysSavedHere) is kept under. */
|
|
105
|
+
constructor(store, sealKey, recipes, data) {
|
|
106
|
+
this.store = store;
|
|
107
|
+
this.sealKey = sealKey;
|
|
108
|
+
this.recipes = recipes;
|
|
109
|
+
this.data = data;
|
|
110
|
+
}
|
|
111
|
+
/** This server's registry (harnessKeysSavedHere) set from the snapshot: each recipe whose every key is saved. */
|
|
112
|
+
mark() {
|
|
113
|
+
savedHere.set(this.data, new Set(this.recipes.filter((recipe) => this.saved(recipe)).map((recipe) => recipe.id)));
|
|
114
|
+
}
|
|
115
|
+
/** Reads every harness key row once: each current one opened, each retired one opened for the cut. A row that does not
|
|
116
|
+
* open reads as not saved. */
|
|
117
|
+
async load() {
|
|
118
|
+
const current = new Map();
|
|
119
|
+
const retired = new Map();
|
|
120
|
+
for (const row of await this.store.sealedKeys.all()) {
|
|
121
|
+
const isCurrent = row.name.startsWith(`${HARNESS_KEY_PLANE}:`);
|
|
122
|
+
if (!isCurrent && !row.name.startsWith(`${RETIRED_PLANE}:`))
|
|
123
|
+
continue;
|
|
124
|
+
let value;
|
|
125
|
+
try {
|
|
126
|
+
value = unsealColumn(this.sealKey, sealedAt.sealedKey(row.name), row.sealed).toString("utf8");
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (isCurrent)
|
|
132
|
+
current.set(row.name, { value, changedAt: row.updatedAt });
|
|
133
|
+
else {
|
|
134
|
+
const of = row.name.slice(0, row.name.lastIndexOf(":") + 1);
|
|
135
|
+
retired.set(of, [...(retired.get(of) ?? []), { row: row.name, value, at: row.updatedAt }]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const list of retired.values())
|
|
139
|
+
list.sort((a, b) => a.at - b.at);
|
|
140
|
+
this.current = current;
|
|
141
|
+
this.retired = retired;
|
|
142
|
+
this.mark();
|
|
143
|
+
}
|
|
144
|
+
/** Whether every key `recipe` runs on is saved for it. */
|
|
145
|
+
saved(recipe) {
|
|
146
|
+
return recipe.keys.length > 0 && recipe.keys.every((name) => this.current.has(harnessKeyRow(recipe.id, name)));
|
|
147
|
+
}
|
|
148
|
+
/** Every value to cut: each saved key's, and each retired one's still kept. */
|
|
149
|
+
values() {
|
|
150
|
+
return [...[...this.current.values()].map((entry) => entry.value), ...[...this.retired.values()].flat().map((entry) => entry.value)];
|
|
151
|
+
}
|
|
152
|
+
/** GET: `recipe`'s keys, each by name, whether saved and when it changed: never a value. */
|
|
153
|
+
view(recipe) {
|
|
154
|
+
const keys = recipe.keys.map((name) => {
|
|
155
|
+
const row = harnessKeyRow(recipe.id, name);
|
|
156
|
+
const saved = this.current.get(row);
|
|
157
|
+
return secretMeta(row, saved ? { set: true, source: "console", changedAt: new Date(saved.changedAt) } : { set: false });
|
|
158
|
+
});
|
|
159
|
+
return { id: recipe.id, label: recipe.label, keys, ready: this.saved(recipe) };
|
|
160
|
+
}
|
|
161
|
+
/** GET /settings/harness-keys: every plan-billed recipe this server is started with, its keys by name. */
|
|
162
|
+
list() {
|
|
163
|
+
return { harnesses: this.recipes.map((recipe) => this.view(recipe)) };
|
|
164
|
+
}
|
|
165
|
+
/** The plan-billed recipe `id` names on this server, else 404. */
|
|
166
|
+
recipe(id) {
|
|
167
|
+
return planRecipeOr404(this.recipes, id);
|
|
168
|
+
}
|
|
169
|
+
/** PUT: `value` sealed as `key` for `recipe`'s harness alone; a value it replaces kept as a retired row. Durable before it
|
|
170
|
+
* resolves, so a 204 never outruns the store. */
|
|
171
|
+
async save(recipe, key, body) {
|
|
172
|
+
const value = admit(recipe, key, body);
|
|
173
|
+
const row = harnessKeyRow(recipe.id, key);
|
|
174
|
+
await this.serial(async () => {
|
|
175
|
+
const was = this.current.get(row);
|
|
176
|
+
if (was?.value === value)
|
|
177
|
+
return;
|
|
178
|
+
if (was)
|
|
179
|
+
await this.retire(recipe.id, key, was.value);
|
|
180
|
+
await putSealedKey(this.store, this.sealKey, row, value);
|
|
181
|
+
this.current.set(row, { value, changedAt: Date.now() });
|
|
182
|
+
this.mark();
|
|
183
|
+
await this.store.flush();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/** DELETE: `key`'s value for `recipe`'s harness gone from its runs, kept as a retired row for the cut. A row the snapshot
|
|
187
|
+
* does not hold (one that does not open under this server's seal key) is removed too, so no claim counts it saved. */
|
|
188
|
+
async remove(recipe, key) {
|
|
189
|
+
known(recipe, key);
|
|
190
|
+
const row = harnessKeyRow(recipe.id, key);
|
|
191
|
+
await this.serial(async () => {
|
|
192
|
+
const was = this.current.get(row);
|
|
193
|
+
if (was)
|
|
194
|
+
await this.retire(recipe.id, key, was.value);
|
|
195
|
+
await removeSealedKey(this.store, row);
|
|
196
|
+
this.current.delete(row);
|
|
197
|
+
this.mark();
|
|
198
|
+
await this.store.flush();
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/** `value`, which `key` held, sealed as a retired row of its own; the oldest beyond RETIRED_KEPT leaves. */
|
|
202
|
+
async retire(harness, key, value) {
|
|
203
|
+
const of = retiredPrefix(harness, key);
|
|
204
|
+
const list = this.retired.get(of) ?? [];
|
|
205
|
+
const at = Math.max(Date.now(), (list.at(-1)?.at ?? 0) + 1);
|
|
206
|
+
const row = `${of}${at}`;
|
|
207
|
+
await putSealedKey(this.store, this.sealKey, row, value);
|
|
208
|
+
list.push({ row, value, at });
|
|
209
|
+
while (list.length > RETIRED_KEPT)
|
|
210
|
+
await removeSealedKey(this.store, list.shift().row);
|
|
211
|
+
this.retired.set(of, list);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** 422 unless `key` is one `recipe` runs on (recipe.keys): a key no recipe names is never saved for it. */
|
|
215
|
+
function known(recipe, key) {
|
|
216
|
+
if (!recipe.keys.includes(key))
|
|
217
|
+
throw invalid([{ field: "key", reason: "not_an_option", message: `${recipe.label} runs on ${recipe.keys.join(", ")}.` }]);
|
|
218
|
+
}
|
|
219
|
+
/** What a PUT may save: `body.value`, text of 8 to 1024 bytes with no whitespace or control character, for a key the
|
|
220
|
+
* recipe names. No message holds the value. */
|
|
221
|
+
function admit(recipe, key, body) {
|
|
222
|
+
known(recipe, key);
|
|
223
|
+
if (typeof body !== "object" || body === null || Array.isArray(body))
|
|
224
|
+
throw invalid([{ field: "value", reason: "wrong_type", message: "The body is { value }." }]);
|
|
225
|
+
const extra = Object.keys(body).filter((name) => name !== "value");
|
|
226
|
+
if (extra.length)
|
|
227
|
+
throw invalid(extra.map((name) => ({ field: name, reason: "unknown", message: "The body is { value }." })));
|
|
228
|
+
const value = body.value;
|
|
229
|
+
if (typeof value !== "string" || value === "")
|
|
230
|
+
throw invalid([{ field: "value", reason: value === undefined ? "missing" : "wrong_type", message: `${key} is text, not empty` }]);
|
|
231
|
+
if (UNFIT.test(value))
|
|
232
|
+
throw invalid([{ field: "value", reason: "invalid", message: `${key} holds whitespace or a control character` }]);
|
|
233
|
+
if ([...value].length < MIN_VALUE)
|
|
234
|
+
throw invalid([{ field: "value", reason: "too_short", message: `${key} is at least ${MIN_VALUE} characters` }]);
|
|
235
|
+
if (Buffer.byteLength(value) > MAX_VALUE_BYTES)
|
|
236
|
+
throw invalid([{ field: "value", reason: "too_long", message: `${key} is at most ${MAX_VALUE_BYTES} bytes` }]);
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
/** 404 for a harness that is not a plan-billed recipe on this server's table: its keys are saved nowhere. */
|
|
240
|
+
export function planRecipeOr404(recipes, id) {
|
|
241
|
+
const recipe = recipes.find((entry) => entry.id === id);
|
|
242
|
+
if (!recipe)
|
|
243
|
+
throw new ApiError("not_found", `No harness recipe billed to its vendor's plan is named ${id} on this server: its keys are saved for a recipe the server is started with (--harness-recipe).`);
|
|
244
|
+
return recipe;
|
|
245
|
+
}
|
|
246
|
+
/** The bytes a value would be sealed as, for a test that checks a key is sealed at rest. */
|
|
247
|
+
export const sealedHarnessKeyBytes = (key, harness, name, value) => sealColumn(key, sealedAt.sealedKey(harnessKeyRow(harness, name)), value);
|
|
@@ -7,9 +7,9 @@ export declare const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
|
|
|
7
7
|
/** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
|
|
8
8
|
* it would run (harness-recipe.ts checkedOf). */
|
|
9
9
|
export declare const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
|
|
10
|
-
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone
|
|
11
|
-
*
|
|
12
|
-
* own sign-in on their own machine (--harness-sign-in). */
|
|
10
|
+
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone (harness-keys.ts), and not every
|
|
11
|
+
* one is saved: its owner saves them in Settings → Harness keys. Until then it runs under harness-check, or on its
|
|
12
|
+
* owner's own sign-in on their own machine (--harness-sign-in). */
|
|
13
13
|
export declare const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
|
|
14
14
|
/** What a recipe's agent runs on: its keys (each read by its saved name where it runs; none for a proxy-billed agent,
|
|
15
15
|
* on the model proxy), or its owner's own sign-in, whose folder (`home`) the agent is handed by signIn.homeArg. */
|
|
@@ -20,12 +20,16 @@ export type RecipeRoute = {
|
|
|
20
20
|
readonly home: string;
|
|
21
21
|
};
|
|
22
22
|
/** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
|
|
23
|
-
* saved for its harness alone, which come first
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
23
|
+
* saved for its harness alone (harness-keys.ts), which come first: for a start, only those its claim laid on `env`
|
|
24
|
+
* (keysLaid); for the server's listing and offers, `saved` too, every one held saved by the server on this data
|
|
25
|
+
* directory (harnessKeysSavedHere), whose claims lay them. Its owner's own sign-in only where `signIn` (the server's
|
|
26
|
+
* --harness-sign-in: one owner, on their own machine, its runs as its own user, which the start proved) and only for a
|
|
27
|
+
* person's run: a scheduled or triggered one whose claim laid not every key is refused at its claim, before this
|
|
28
|
+
* (runner/cli-run-spec.ts, harness-keys.ts RECIPE_SIGN_IN_PERSON_ONLY). Else HARNESS_KEYS_NOT_SAVED, naming the
|
|
29
|
+
* console's page. harness-check never takes this route: it runs on the recipe's keys from the shell alone. */
|
|
30
|
+
export declare function serverRoute(recipe: Recipe, file: string, data: string, env: NodeJS.ProcessEnv, { signIn, saved }: {
|
|
28
31
|
signIn: boolean;
|
|
32
|
+
saved?: boolean;
|
|
29
33
|
}): RecipeRoute | {
|
|
30
34
|
refused: string;
|
|
31
35
|
message: string;
|
|
@@ -47,7 +51,8 @@ export interface RecipeEntryOptions extends AcpEntryHost {
|
|
|
47
51
|
readonly recipe: Recipe;
|
|
48
52
|
readonly binary: string;
|
|
49
53
|
readonly release: RecipeArchive;
|
|
50
|
-
|
|
54
|
+
/** `probe`: the adapter is built only to check it (harness-table.ts PlanLaunch.probe), not to start its agent. */
|
|
55
|
+
route(env: NodeJS.ProcessEnv, probe?: boolean): RecipeRoute;
|
|
51
56
|
beforeStart(command: string): Promise<void>;
|
|
52
57
|
/** The variables beside the recipe's env at each start: the egress proxy's (harness-egress.ts egressVars). */
|
|
53
58
|
vars(): Readonly<Record<string, string>>;
|
|
@@ -8,6 +8,7 @@ import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
|
|
|
8
8
|
import { ARCHIVE_CODES, archivePlatform, digestOf } from "./harness-archive.js";
|
|
9
9
|
import { egressProxy, egressVars } from "./harness-egress.js";
|
|
10
10
|
import { installDirOf } from "./harness-install.js";
|
|
11
|
+
import { HARNESS_KEYS_PAGE, harnessKeysSavedHere, keysLaid } from "./harness-keys.js";
|
|
11
12
|
import { checkedOf, loadRecipe, pinnedDigest, pinnedTree, recipeBinaryOf, recipeCheckLine, recipeInstallLine, recipeSignInLine, releaseFor, signedIn, signInHomeOf } from "./harness-recipe.js";
|
|
12
13
|
import { acpEntryOf } from "./harness-table.js";
|
|
13
14
|
import { HarnessUnavailable } from "./provider.js";
|
|
@@ -17,25 +18,30 @@ export const HARNESS_NOT_SIGNED_IN = "HARNESS_NOT_SIGNED_IN";
|
|
|
17
18
|
/** A recipe a server names that has no passing harness-check on this data directory for the recipe, binary and files
|
|
18
19
|
* it would run (harness-recipe.ts checkedOf). */
|
|
19
20
|
export const HARNESS_NOT_CHECKED = "HARNESS_NOT_CHECKED";
|
|
20
|
-
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone
|
|
21
|
-
*
|
|
22
|
-
* own sign-in on their own machine (--harness-sign-in). */
|
|
21
|
+
/** A plan-billed recipe a server names, whose runs take keys saved for its harness alone (harness-keys.ts), and not every
|
|
22
|
+
* one is saved: its owner saves them in Settings → Harness keys. Until then it runs under harness-check, or on its
|
|
23
|
+
* owner's own sign-in on their own machine (--harness-sign-in). */
|
|
23
24
|
export const HARNESS_KEYS_NOT_SAVED = "HARNESS_KEYS_NOT_SAVED";
|
|
24
25
|
/** The route a server runs `recipe`'s agent on, or why there is none. Proxy-billed: the model proxy. Plan-billed: keys
|
|
25
|
-
* saved for its harness alone, which come first
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
|
|
26
|
+
* saved for its harness alone (harness-keys.ts), which come first: for a start, only those its claim laid on `env`
|
|
27
|
+
* (keysLaid); for the server's listing and offers, `saved` too, every one held saved by the server on this data
|
|
28
|
+
* directory (harnessKeysSavedHere), whose claims lay them. Its owner's own sign-in only where `signIn` (the server's
|
|
29
|
+
* --harness-sign-in: one owner, on their own machine, its runs as its own user, which the start proved) and only for a
|
|
30
|
+
* person's run: a scheduled or triggered one whose claim laid not every key is refused at its claim, before this
|
|
31
|
+
* (runner/cli-run-spec.ts, harness-keys.ts RECIPE_SIGN_IN_PERSON_ONLY). Else HARNESS_KEYS_NOT_SAVED, naming the
|
|
32
|
+
* console's page. harness-check never takes this route: it runs on the recipe's keys from the shell alone. */
|
|
33
|
+
export function serverRoute(recipe, file, data, env, { signIn, saved = false }) {
|
|
30
34
|
if (recipe.model.billing === "proxy")
|
|
31
35
|
return { on: "keys" };
|
|
36
|
+
if (saved || keysLaid(env, recipe.keys))
|
|
37
|
+
return { on: "keys" };
|
|
32
38
|
if (signIn && recipe.signIn) {
|
|
33
39
|
if (signedIn(data, recipe))
|
|
34
40
|
return { on: "sign-in", home: signInHomeOf(data, recipe.id) };
|
|
35
|
-
return { refused: HARNESS_NOT_SIGNED_IN, message: `${recipe.label} runs on this server on its owner's own sign-in (--harness-sign-in), and
|
|
41
|
+
return { refused: HARNESS_NOT_SIGNED_IN, message: `${recipe.label} runs on this server on its keys saved in Settings → Harness keys (${HARNESS_KEYS_PAGE}), else on its owner's own sign-in (--harness-sign-in), and neither is here: save its keys there, or sign it in with: ${recipeSignInLine(file, data, env)}` };
|
|
36
42
|
}
|
|
37
43
|
const own = recipe.signIn ? "; on your own machine alone, a server started with --harness-sign-in runs it on your own sign-in" : "";
|
|
38
|
-
return { refused: HARNESS_KEYS_NOT_SAVED, message: `${recipe.label} runs on its keys (${recipe.keys.join(", ")}) saved for this harness alone, and
|
|
44
|
+
return { refused: HARNESS_KEYS_NOT_SAVED, message: `${recipe.label} runs on its keys (${recipe.keys.join(", ")}) saved for this harness alone, and not every one is saved: save them in Settings → Harness keys (${HARNESS_KEYS_PAGE}; \`agentrun harness keys\` prints the link)${own}` };
|
|
39
45
|
}
|
|
40
46
|
/** The ACP adapter's recipe for one start of `recipe`'s agent on `route`: the installed `binary`, the platform's own
|
|
41
47
|
* arguments where its release lists them (else the recipe's), and on the sign-in its folder after them. On its keys:
|
|
@@ -97,7 +103,7 @@ export function recipeEntryOf(options) {
|
|
|
97
103
|
}, host)
|
|
98
104
|
: acpEntryOf({
|
|
99
105
|
facts: { ...acp.cursorFacts, id: recipe.id, label: recipe.label },
|
|
100
|
-
recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env), { vars: options.vars(), model: launch.model }),
|
|
106
|
+
recipe: (launch) => acpRecipeFor(recipe, binary, release, options.route(launch.env, launch.probe === true), { vars: options.vars(), model: launch.model }),
|
|
101
107
|
beforeStart: options.beforeStart,
|
|
102
108
|
...checks,
|
|
103
109
|
...(options.hidden ? { hidden: options.hidden } : {}),
|
|
@@ -119,7 +125,12 @@ export function recipeServerEntry(file, data, { signIn = false } = {}) {
|
|
|
119
125
|
throw new Error(`harness recipe ${loaded.file}: ${recipe.label} ${recipe.release.version} has no release for ${platform ?? `${process.platform}-${process.arch}`}`);
|
|
120
126
|
const binary = recipeBinaryOf(data, recipe, release);
|
|
121
127
|
const installed = installDirOf(data, recipe.id);
|
|
122
|
-
|
|
128
|
+
// What the server's listing, offers and checks read (`why`, and the adapter built as a probe): the keys route when its
|
|
129
|
+
// server holds every one saved on this data directory (harnessKeysSavedHere), whose claims lay them. An agent's start
|
|
130
|
+
// reads only what its claim laid (`start`): never what the server lists, which a removal can have outrun, nor the
|
|
131
|
+
// shell's variable of a key's name.
|
|
132
|
+
const route = (env) => serverRoute(recipe, loaded.file, data, env, { signIn, saved: harnessKeysSavedHere(data, recipe.id) });
|
|
133
|
+
const start = (env) => serverRoute(recipe, loaded.file, data, env, { signIn });
|
|
123
134
|
/** Why it cannot run on `env`, in words that end with the command that fixes it; undefined when it can. Nothing is
|
|
124
135
|
* digested here (each start is, beforeStart): the pins and the check's note are compared. */
|
|
125
136
|
const why = (env) => {
|
|
@@ -150,8 +161,8 @@ export function recipeServerEntry(file, data, { signIn = false } = {}) {
|
|
|
150
161
|
throw new HarnessUnavailable(`${recipe.label}'s egress proxy is not running, so its agent does not start`);
|
|
151
162
|
return egressVars(egressUrl);
|
|
152
163
|
},
|
|
153
|
-
route: (env) => {
|
|
154
|
-
const on = route(env);
|
|
164
|
+
route: (env, probe) => {
|
|
165
|
+
const on = probe ? route(env) : start(env);
|
|
155
166
|
if ("refused" in on)
|
|
156
167
|
throw new HarnessUnavailable(`${on.refused}: ${on.message}`);
|
|
157
168
|
return on;
|
package/dist/harness-table.d.ts
CHANGED
|
@@ -170,7 +170,12 @@ export declare const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
|
|
|
170
170
|
/** What a run of a plan-billed ACP agent is given (acpEntryOf's plan branch): its model as its vendor names it (`default`
|
|
171
171
|
* for the vendor's own), a log, the confinement its process starts under and the server's environment. No provider or
|
|
172
172
|
* price: its vendor bills its owner's plan, and no request of it reaches a proxy of ours. */
|
|
173
|
-
export type PlanLaunch = Omit<ModuleLaunch, "provider" | "price" | "skills"
|
|
173
|
+
export type PlanLaunch = Omit<ModuleLaunch, "provider" | "price" | "skills"> & {
|
|
174
|
+
/** Set where the adapter is built only to say whether it would run (the entry's refusal: offers, a save's or a start's
|
|
175
|
+
* check), never to start its agent: a recipe's route reads its server's listing then, and only what a claim laid when
|
|
176
|
+
* its agent starts (harness-recipe-entry.ts). */
|
|
177
|
+
readonly probe?: boolean;
|
|
178
|
+
};
|
|
174
179
|
/** What serve gives acpEntryOf for an ACP agent billed to its owner's plan (its facts' wire `plan`): Cursor's entry and
|
|
175
180
|
* harness-check's plan-billed recipes. Not the kit's: a module's acpEntry is proxy-billed. `missing` may throw a
|
|
176
181
|
* HarnessUnavailable of its own, which keeps the fix (install, pins) it names; `recipe` may throw one too (a key unset). */
|
|
@@ -224,6 +229,16 @@ export declare function harnessTable(env: NodeJS.ProcessEnv): Readonly<Record<st
|
|
|
224
229
|
* that user, never a slot's; and a plan-billed one runs on keys saved for it or, for a person's run alone, its owner's
|
|
225
230
|
* own sign-in (harness-recipe-entry.ts serverRoute). */
|
|
226
231
|
export declare const recipeHarness: (env: NodeJS.ProcessEnv, id: string) => "proxy" | "plan" | undefined;
|
|
232
|
+
/** A harness on `env`'s table whose keys are saved for it alone (harness-keys.ts): a recipe billed to its vendor's plan. */
|
|
233
|
+
export type PlanRecipe = {
|
|
234
|
+
readonly id: string;
|
|
235
|
+
readonly label: string;
|
|
236
|
+
readonly keys: readonly string[];
|
|
237
|
+
};
|
|
238
|
+
/** The names of the keys `id` runs on when it is a plan-billed recipe's harness on `env`'s table, else undefined. */
|
|
239
|
+
export declare const recipeKeysOf: (env: NodeJS.ProcessEnv, id: string) => readonly string[] | undefined;
|
|
240
|
+
/** Every plan-billed recipe's harness on `env`'s table, in its order: what Settings → Harness keys lists. */
|
|
241
|
+
export declare const planRecipesOf: (env: NodeJS.ProcessEnv) => PlanRecipe[];
|
|
227
242
|
/** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
|
|
228
243
|
export declare const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
|
|
229
244
|
/** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
|
package/dist/harness-table.js
CHANGED
|
@@ -226,7 +226,7 @@ function acpPlanEntryOf(options, host = {}) {
|
|
|
226
226
|
if (modelWire(facts.wire))
|
|
227
227
|
throw new Error(`${id} runs on a model wire of ours, so its ACP entry is the proxy-billed one`);
|
|
228
228
|
const prefix = `${id}/`;
|
|
229
|
-
const make = async (env, needs) => {
|
|
229
|
+
const make = async (env, needs, probe = false) => {
|
|
230
230
|
const { fixOf, harnessLog } = await import("./adapters.js");
|
|
231
231
|
// What no key fixes is said first, as for the built-in harnesses' binaries.
|
|
232
232
|
const lacks = await options.missing?.(env);
|
|
@@ -239,7 +239,7 @@ function acpPlanEntryOf(options, host = {}) {
|
|
|
239
239
|
throw new HarnessUnavailable(`${label} runs ${label}'s models, named ${prefix}<model-id>; the run's model is ${needs.model.provider}/${needs.model.modelId}.`);
|
|
240
240
|
const log = host.log ?? harnessLog(id, env);
|
|
241
241
|
try {
|
|
242
|
-
const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env }));
|
|
242
|
+
const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env, ...(probe ? { probe } : {}) }));
|
|
243
243
|
// Its keys (recipe.keys) are read from the run's environment, which holds its own (ownKeys: run-secrets.ts keysFor).
|
|
244
244
|
return acp.acpAdapter({ recipe, ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}), ...(needs.confine ? { confine: needs.confine } : {}), env, log });
|
|
245
245
|
}
|
|
@@ -272,11 +272,12 @@ function acpPlanEntryOf(options, host = {}) {
|
|
|
272
272
|
return { model: { provider: id, modelId } };
|
|
273
273
|
},
|
|
274
274
|
priceModel: (_env, model) => model,
|
|
275
|
-
adapter: make,
|
|
275
|
+
adapter: (env, needs) => make(env, needs),
|
|
276
|
+
// Built only to check it (a probe), never started.
|
|
276
277
|
refusal: async (env, given, { atStart }) => {
|
|
277
278
|
const { startReason } = await import("./adapters.js");
|
|
278
279
|
try {
|
|
279
|
-
const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } });
|
|
280
|
+
const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } }, true);
|
|
280
281
|
const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
|
|
281
282
|
return problems.length ? { reason: problems.join(" ") } : undefined;
|
|
282
283
|
}
|
|
@@ -507,14 +508,14 @@ export function harnessTable(env) {
|
|
|
507
508
|
if (Object.hasOwn(built, entry.id))
|
|
508
509
|
throw new Error(`harness recipe ${file} names ${entry.id}, which a harness module or another recipe already adds`);
|
|
509
510
|
built[entry.id] = entry;
|
|
510
|
-
|
|
511
|
+
const { recipe } = loadRecipe(file);
|
|
512
|
+
madeByRecipe.set(entry, { billing: recipe.model.billing, label: recipe.label, keys: Object.freeze([...recipe.keys]) });
|
|
511
513
|
}
|
|
512
514
|
table = Object.freeze(built);
|
|
513
515
|
loaded.set(key, table);
|
|
514
516
|
}
|
|
515
517
|
return table;
|
|
516
518
|
}
|
|
517
|
-
/** The entries harnessTable made from a recipe (HARNESS_RECIPES_ENV), with the recipe's billing. */
|
|
518
519
|
const madeByRecipe = new WeakMap();
|
|
519
520
|
/** How `id` on `env`'s table is billed when it is a recipe's harness, else undefined. A recipe's install, its check's
|
|
520
521
|
* note and its owner's sign-in are the server user's alone (0700 and 0600 under `<data>/harnesses`), so its runs run as
|
|
@@ -522,8 +523,19 @@ const madeByRecipe = new WeakMap();
|
|
|
522
523
|
* own sign-in (harness-recipe-entry.ts serverRoute). */
|
|
523
524
|
export const recipeHarness = (env, id) => {
|
|
524
525
|
const entry = Object.hasOwn(harnessTable(env), id) ? harnessTable(env)[id] : undefined;
|
|
525
|
-
return entry === undefined ? undefined : madeByRecipe.get(entry);
|
|
526
|
+
return entry === undefined ? undefined : madeByRecipe.get(entry)?.billing;
|
|
527
|
+
};
|
|
528
|
+
/** The names of the keys `id` runs on when it is a plan-billed recipe's harness on `env`'s table, else undefined. */
|
|
529
|
+
export const recipeKeysOf = (env, id) => {
|
|
530
|
+
const entry = Object.hasOwn(harnessTable(env), id) ? harnessTable(env)[id] : undefined;
|
|
531
|
+
const made = entry === undefined ? undefined : madeByRecipe.get(entry);
|
|
532
|
+
return made?.billing === "plan" ? made.keys : undefined;
|
|
526
533
|
};
|
|
534
|
+
/** Every plan-billed recipe's harness on `env`'s table, in its order: what Settings → Harness keys lists. */
|
|
535
|
+
export const planRecipesOf = (env) => Object.values(harnessTable(env)).flatMap((entry) => {
|
|
536
|
+
const made = madeByRecipe.get(entry);
|
|
537
|
+
return made?.billing === "plan" ? [{ id: entry.id, label: made.label, keys: made.keys }] : [];
|
|
538
|
+
});
|
|
527
539
|
/** The owner's setting that names harness modules when no option does: package names or paths, comma-separated. */
|
|
528
540
|
export const HARNESS_MODULES_SETTING = "AGENTRUN_SERVE_HARNESS_MODULES";
|
|
529
541
|
/** The harness modules `given` names (a server's or a runner's `--harness-module`, else HARNESS_MODULES_SETTING): none
|
package/dist/harness.d.ts
CHANGED
|
@@ -51,7 +51,11 @@ export type HarnessCapability = HarnessOffer & {
|
|
|
51
51
|
}[];
|
|
52
52
|
run_memory_mib: number;
|
|
53
53
|
needs?: HarnessNeed[];
|
|
54
|
+
noModelRuns?: true;
|
|
54
55
|
};
|
|
56
|
+
/** `noModelRuns` (never served): a harness this server runs, its default model lacking a key (`needs`), and no model it
|
|
57
|
+
* offers runs here now either, so capabilities serve it `available: false` (server.ts capabilitiesWith). Absent where
|
|
58
|
+
* any model it offers runs, though its default does not: a revision that names that model runs. */
|
|
55
59
|
/** What would give a harness that runs nothing here a model, any one of them: a model key (`key`), or the ChatGPT sign-in
|
|
56
60
|
* (`chatgpt`: codex and pi, on a server that signs in, not signed in or signed in no longer, AGENT_MODEL naming no key's
|
|
57
61
|
* model the harness runs: planWouldRun). */
|
package/dist/harness.js
CHANGED
|
@@ -78,6 +78,9 @@ export function harnessOffers(env) {
|
|
|
78
78
|
// so the picker never offers one a save would refuse. None for a harness that does not run here.
|
|
79
79
|
const entry = harnessOf(env, offer.id);
|
|
80
80
|
const models = [];
|
|
81
|
+
// Whether any model it offers runs here now, not only lacks a key: its default lacking one leaves it available
|
|
82
|
+
// where another runs (noModelRuns).
|
|
83
|
+
let runsOne = false;
|
|
81
84
|
// Its free models (model-form.ts freeCandidates) are offered after the others, by the same checks.
|
|
82
85
|
const free = offer.available ? await freeCandidates(env, offer.id) : [];
|
|
83
86
|
if (offer.available) {
|
|
@@ -90,12 +93,15 @@ export function harnessOffers(env) {
|
|
|
90
93
|
const { FAUX_ENV } = await import("./model.js");
|
|
91
94
|
const { factsOf } = await import("./harness-table.js");
|
|
92
95
|
const facts = factsOf(env, offer.id);
|
|
96
|
+
const { OLLAMA_PROVIDER, ollamaToolsModels } = await import("./ollama-provider.js");
|
|
97
|
+
const toolsModels = ollamaToolsModels(env);
|
|
93
98
|
for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
|
|
94
99
|
if (!MODEL_REF.test(id))
|
|
95
100
|
continue;
|
|
96
101
|
const chosen = await entry.model(env, id, true);
|
|
97
102
|
if (!chosen || !("model" in chosen || chosen.needs === "key"))
|
|
98
103
|
continue;
|
|
104
|
+
let lacksKey = !("model" in chosen);
|
|
99
105
|
if (facts && "model" in chosen && !env[FAUX_ENV]) {
|
|
100
106
|
try {
|
|
101
107
|
providerFor(facts.wire, env, chosen.model, offer.id);
|
|
@@ -103,9 +109,14 @@ export function harnessOffers(env) {
|
|
|
103
109
|
catch (error) {
|
|
104
110
|
if (!(error instanceof HarnessUnavailable && error.keys?.length))
|
|
105
111
|
continue;
|
|
112
|
+
lacksKey = true;
|
|
106
113
|
}
|
|
107
114
|
}
|
|
108
115
|
models.push(id);
|
|
116
|
+
// A model of the Ollama here that takes no tools stays pickable, but gives a run no tools: it is no model a
|
|
117
|
+
// run of this harness has now, as the host's default never is one (model.ts localDefault).
|
|
118
|
+
if (!lacksKey && (!id.startsWith(`${OLLAMA_PROVIDER}/`) || toolsModels.includes(id)))
|
|
119
|
+
runsOne = true;
|
|
109
120
|
}
|
|
110
121
|
}
|
|
111
122
|
// One that runs nothing here for want of a key (unavailable with `keys`, or available with no default model for
|
|
@@ -114,7 +125,7 @@ export function harnessOffers(env) {
|
|
|
114
125
|
const wantsKey = offer.available ? resolved !== undefined && "why" in resolved && resolved.needs === "key" : Boolean(offer.keys?.length);
|
|
115
126
|
const sayWhy = !wantsKey ? {} : offer.available ? { reason: resolved.why } : offer.reason ? { reason: withPlanWords(env, offer.id, offer.reason) } : {};
|
|
116
127
|
const needs = wantsKey ? ["key", ...(planWouldRun(env, offer.id) ? ["chatgpt"] : [])] : [];
|
|
117
|
-
return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}) };
|
|
128
|
+
return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}), ...(offer.available && needs.length && !runsOne ? { noModelRuns: true } : {}) };
|
|
118
129
|
}));
|
|
119
130
|
})();
|
|
120
131
|
offered.set(env, offers);
|
package/dist/host-check.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
|
|
2
2
|
* header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
|
|
3
3
|
export declare function hostName(header: string | undefined): string | undefined;
|
|
4
|
+
/** Whether a Host name (as hostName gives it) is this machine's own: localhost, an IPv4 loopback address or [::1]. Not a name
|
|
5
|
+
* an operator allowed (--allow-host, AGENTRUN_PUBLIC_URL): those pass the server's Host check, and a route that reads this
|
|
6
|
+
* machine's files asks for more. */
|
|
7
|
+
export declare const isLoopbackName: (name: string | undefined) => boolean;
|
|
8
|
+
/** The port a Host header names (1 to 65535), or undefined for none, or for a header that is not `name` or `name:port`. */
|
|
9
|
+
export declare function hostPort(header: string | undefined): number | undefined;
|
|
4
10
|
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
5
11
|
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
6
12
|
* front of it sends. */
|
package/dist/host-check.js
CHANGED
|
@@ -9,6 +9,16 @@ export function hostName(header) {
|
|
|
9
9
|
const match = /^(\[[0-9a-f:.]+\]|[a-z0-9._-]+)(?::(\d{1,5}))?$/.exec(String(header ?? "").trim().toLowerCase());
|
|
10
10
|
return match && (match[2] === undefined || Number(match[2]) <= 65535) ? match[1] : undefined;
|
|
11
11
|
}
|
|
12
|
+
/** Whether a Host name (as hostName gives it) is this machine's own: localhost, an IPv4 loopback address or [::1]. Not a name
|
|
13
|
+
* an operator allowed (--allow-host, AGENTRUN_PUBLIC_URL): those pass the server's Host check, and a route that reads this
|
|
14
|
+
* machine's files asks for more. */
|
|
15
|
+
export const isLoopbackName = (name) => name === "localhost" || name === "[::1]" || (name !== undefined && /^127(\.\d{1,3}){3}$/.test(name));
|
|
16
|
+
/** The port a Host header names (1 to 65535), or undefined for none, or for a header that is not `name` or `name:port`. */
|
|
17
|
+
export function hostPort(header) {
|
|
18
|
+
const match = /^(?:\[[0-9a-f:.]+\]|[a-z0-9._-]+):(\d{1,5})$/.exec(String(header ?? "").trim().toLowerCase());
|
|
19
|
+
const port = match ? Number(match[1]) : 0;
|
|
20
|
+
return port >= 1 && port <= 65535 ? port : undefined;
|
|
21
|
+
}
|
|
12
22
|
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
13
23
|
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
14
24
|
* front of it sends. */
|
package/dist/import-summary.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RunMetrics } from "./timeline/index.js";
|
|
2
|
-
import { type Source } from "
|
|
2
|
+
import { type Source } from "@parcha/agentrun-import";
|
|
3
3
|
/** A session an import found: its source and agent; what it used (undefined: unknown), with its time at work; and its
|
|
4
4
|
* model requests by local hour of the day (undefined: their times are unknown). `untied`: a subagent's session whose
|
|
5
5
|
* file names no parent, so no session of its own either: its tokens and tool calls count in the totals, nothing else. */
|
package/dist/import-summary.js
CHANGED