@parcha/agentrun-serve 0.1.0-beta.47 → 0.1.0-beta.48
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 +48 -1
- package/README.md +84 -14
- package/dist/acp-package.d.ts +24 -6
- package/dist/adapter-facts.d.ts +0 -4
- package/dist/adapter-facts.js +1 -4
- package/dist/adapters.d.ts +3 -12
- package/dist/adapters.js +1 -70
- package/dist/answer-json.d.ts +10 -0
- package/dist/answer-json.js +24 -0
- package/dist/api-only.d.ts +5 -2
- package/dist/api-only.js +10 -2
- package/dist/browser-live.d.ts +9 -4
- package/dist/browser-live.js +18 -5
- package/dist/cap.js +7 -9
- package/dist/cli.js +6 -6
- package/dist/computer-routes.d.ts +8 -5
- package/dist/computer-routes.js +7 -5
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +4 -2
- package/dist/conformance.d.ts +4 -0
- package/dist/conformance.js +6 -0
- package/dist/console/assets/index-CTGegcKt.css +1 -0
- package/dist/console/assets/{index-BBFzAxLB.js → index-D1Se6mgG.js} +165 -165
- package/dist/console/index.html +2 -2
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +99 -70
- package/dist/harness-cursor.d.ts +10 -27
- package/dist/harness-cursor.js +5 -84
- package/dist/harness-goose.d.ts +4 -29
- package/dist/harness-goose.js +6 -86
- package/dist/harness-module.d.ts +4 -0
- package/dist/harness-module.js +1 -0
- package/dist/harness-owned.d.ts +52 -0
- package/dist/harness-owned.js +92 -0
- package/dist/harness-recipe.js +2 -24
- package/dist/harness-table.d.ts +109 -6
- package/dist/harness-table.js +242 -28
- package/dist/harness.js +2 -2
- package/dist/key-refusal.d.ts +2 -1
- package/dist/key-refusal.js +18 -2
- package/dist/learn/promote.d.ts +11 -0
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +23 -0
- package/dist/learning-model.d.ts +18 -0
- package/dist/learning-model.js +77 -0
- package/dist/llms.txt +1 -0
- package/dist/model-form.js +12 -12
- package/dist/model.d.ts +5 -4
- package/dist/model.js +19 -13
- package/dist/openapi.js +35 -5
- package/dist/page.d.ts +1 -0
- package/dist/page.js +1 -1
- package/dist/run-secrets.d.ts +2 -2
- package/dist/run-secrets.js +6 -5
- package/dist/run-trace.js +6 -3
- package/dist/runner/adapter-loop.d.ts +4 -1
- package/dist/runner/adapter-loop.js +1 -2
- package/dist/runner/adapter-run-spec.d.ts +3 -2
- package/dist/runner/adapter-run-spec.js +8 -4
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +6 -42
- package/dist/runner/cli-run-spec.js +10 -6
- package/dist/runner/conformance/host-tools.d.ts +4 -0
- package/dist/runner/conformance/host-tools.js +14 -0
- package/dist/runner/meta-tools.js +4 -2
- package/dist/runner/presence.d.ts +3 -0
- package/dist/runner/presence.js +19 -12
- package/dist/runner/promotion.d.ts +62 -4
- package/dist/runner/promotion.js +146 -15
- package/dist/runner/sdk-loop.js +25 -1
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +2 -1
- package/dist/runs-over-store.js +2 -4
- package/dist/sdk/check.d.ts +31 -0
- package/dist/sdk/check.js +58 -0
- package/dist/sdk/runs.d.ts +10 -2
- package/dist/sdk/runs.js +87 -17
- package/dist/sdk/schema.js +11 -3
- package/dist/server.d.ts +3 -0
- package/dist/server.js +116 -40
- package/dist/store/sqlite/store.js +35 -30
- package/dist/store/store.d.ts +20 -18
- package/dist/store-view.d.ts +5 -3
- package/dist/store-view.js +9 -7
- package/dist/template-eval.js +5 -2
- package/dist/template-github-permissions.d.ts +5 -1
- package/dist/template-github-permissions.js +7 -3
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/timeline.d.ts +8 -0
- package/dist/timeline/timeline.js +18 -6
- package/dist/tool-gate.d.ts +8 -4
- package/dist/tool-gate.js +6 -7
- package/dist/tool-plane.d.ts +4 -0
- package/dist/tool-plane.js +10 -10
- package/dist/trigger-targets.d.ts +11 -2
- package/dist/trigger-targets.js +71 -2
- package/dist/validate.js +5 -1
- package/dist/viewer-credential.d.ts +25 -0
- package/dist/viewer-credential.js +51 -0
- package/dist/workspace/resolve-computer.d.ts +5 -0
- package/dist/workspace/resolve-computer.js +19 -1
- package/package.json +18 -10
- package/templates/code-review/agent.md +2 -3
- package/templates/code-review/evals/mentions-defused/case.yaml +0 -1
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +0 -27
- package/templates/code-review/evals/other-repo/case.yaml +0 -1
- package/templates/code-review/evals/other-repo/fixtures/github-mcp.json +0 -18
- package/templates/code-review/evals/other-repo/graders/no-other-repo.md +1 -1
- package/dist/console/assets/index-BRi-Rgq6.css +0 -1
package/dist/harness-table.js
CHANGED
|
@@ -13,13 +13,14 @@ import { facts as claudeFacts } from "@parcha/agentrun-harness-claude/facts";
|
|
|
13
13
|
import { facts as codexFacts } from "@parcha/agentrun-harness-codex/facts";
|
|
14
14
|
import { facts as openCodeFacts } from "./harness-opencode/facts.js";
|
|
15
15
|
import { CURSOR_FACTS, GOOSE_FACTS } from "./adapter-facts.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { ACP_PACKAGE, acpPackage } from "./acp-package.js";
|
|
17
|
+
import { gooseHidden, gooseMissing } from "./harness-goose.js";
|
|
18
|
+
import { CURSOR_DEFAULT_MODEL, CURSOR_KEY, cursorCardOf, cursorHidden, cursorLimitsOf, cursorMissing } from "./harness-cursor.js";
|
|
18
19
|
import { DEFAULT_HARNESS, HARNESS_ID_PATTERN, PLAN_HARNESSES, RESERVED_HARNESS_IDS } from "./harness.js";
|
|
19
20
|
import { HARNESS_INSTALLS } from "./harness-install.js";
|
|
20
21
|
import { chooseModel } from "./model.js";
|
|
21
22
|
import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
|
|
22
|
-
import { modelWire, WIRES } from "./wires.js";
|
|
23
|
+
import { modelWire, wireOf, WIRES } from "./wires.js";
|
|
23
24
|
import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
|
|
24
25
|
/** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
|
|
25
26
|
export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
|
|
@@ -65,7 +66,7 @@ const onOpenRouter = (id, vendor) => new RegExp(`^openrouter/${vendor}/[^/]+$`).
|
|
|
65
66
|
/** An adapter harness's entry, from its facts and the factory that builds its adapter. */
|
|
66
67
|
function adapterEntry(facts, make, extra = {}) {
|
|
67
68
|
const { wire, id } = facts;
|
|
68
|
-
// A harness billed to its own plan
|
|
69
|
+
// A harness billed to its own plan is acpEntryOf's plan-billed entry (Cursor's): this one is for a model wire of ours.
|
|
69
70
|
if (!modelWire(wire))
|
|
70
71
|
throw new Error(`${id} is billed to its own plan, so its table entry is its own, never adapterEntry's`);
|
|
71
72
|
const { vendor, gateway } = WIRES[wire];
|
|
@@ -117,43 +118,163 @@ function adapterEntry(facts, make, extra = {}) {
|
|
|
117
118
|
};
|
|
118
119
|
return Object.freeze(entry);
|
|
119
120
|
}
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
/** An adapter harness's adapter for one run, from `facts` and its builder: the launch serve chooses for the run's model
|
|
122
|
+
* on this server's keys (providerFor, priceOf). A module's, and the built-in Goose's. An error `missing` or the builder
|
|
123
|
+
* throws is a HarnessUnavailable with the fix its code names in the facts (fixOf: install, pins). */
|
|
124
|
+
function moduleAdapter(facts, build, { missing }, host = {}) {
|
|
125
|
+
return async (env, needs) => {
|
|
126
|
+
const { fixOf, harnessLog, priceOf } = await import("./adapters.js");
|
|
127
|
+
const unavailable = (error) => (error instanceof HarnessUnavailable ? error : new HarnessUnavailable(error.message, fixOf(facts, error)));
|
|
128
|
+
// What no key fixes is said first (a binary): a refusal for it names no key.
|
|
129
|
+
let lacks;
|
|
130
|
+
try {
|
|
131
|
+
lacks = await missing?.(env);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
throw unavailable(error);
|
|
135
|
+
}
|
|
136
|
+
if (lacks)
|
|
137
|
+
throw new HarnessUnavailable(lacks);
|
|
138
|
+
const provider = providerFor(facts.wire, env, needs.model, facts.id);
|
|
139
|
+
// A person's Claude Code login is its CLI's alone (claude-login.ts): no request of this harness goes on it; a key of
|
|
140
|
+
// its wire's vendor's, or OpenRouter's, runs it.
|
|
141
|
+
if (provider.login)
|
|
142
|
+
throw new HarnessUnavailable(`${facts.label} runs on a model key: Claude Code's login on this machine is its CLI's alone.`, undefined, [wireOf(facts.wire).key, "OPENROUTER_API_KEY"]);
|
|
143
|
+
try {
|
|
144
|
+
return await build({
|
|
145
|
+
model: provider.modelId,
|
|
146
|
+
provider: { origin: provider.origin, credential: provider.credential, ...(provider.auth ? { auth: provider.auth } : {}) },
|
|
147
|
+
price: priceOf({ ...needs, model: provider.priceModel }),
|
|
148
|
+
log: host.log ?? harnessLog(facts.id, env),
|
|
149
|
+
...(needs.confine ? { confine: needs.confine } : {}),
|
|
150
|
+
...(needs.skills?.length ? { skills: needs.skills } : {}),
|
|
151
|
+
env,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
throw unavailable(error);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/** `recipe`, once its `keys` name no key this server holds for something else (harness-recipe.ts serverKey, the
|
|
160
|
+
* loader's rule 1) but its own built-in harness's (builtinOwns: Cursor's CURSOR_API_KEY). Its keys are read from the
|
|
161
|
+
* launch's environment, where a server key is readable by name, and a module's or a check's recipe is not the loader's:
|
|
162
|
+
* checked as each launch's recipe is made, before its agent starts, so the harness's offer at start says it. */
|
|
163
|
+
async function ownKeysOnly(facts, recipe) {
|
|
164
|
+
const { RECIPE_CODES, serverKey } = await import("./harness-recipe.js");
|
|
165
|
+
const named = (recipe.keys ?? []).filter((name) => serverKey(name) && !builtinOwns(facts.id, name));
|
|
166
|
+
if (named.length)
|
|
167
|
+
throw new HarnessUnavailable(`${RECIPE_CODES.keys}: ${facts.label}'s recipe names ${named.join(", ")} in keys, a key this server holds for something else; a recipe names only keys saved for its own harness.`);
|
|
168
|
+
return recipe;
|
|
169
|
+
}
|
|
170
|
+
/** The runner of an entry run on serve's table (its facts' adapter, cli-run-spec.ts), never by a runner's adapter of its
|
|
171
|
+
* own: a module's, and Goose's and Cursor's (resolveHarness). Its adapter says so if it is ever asked. The loop keeps the
|
|
172
|
+
* run's record, as for every CLI harness. */
|
|
173
|
+
export const ON_TABLE = Object.freeze({
|
|
174
|
+
record: "loop",
|
|
175
|
+
adapter: async () => {
|
|
176
|
+
throw new Error("this harness runs from its table entry (facts and adapter), not a runner adapter");
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
/** What an ACP harness promises by default: a resume by the agent's session/load, tool calls through its permission asks,
|
|
180
|
+
* its model through the session's proxy (Goose's). */
|
|
181
|
+
const ACP_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "proxy" });
|
|
182
|
+
/** As ACP_PROMISES, with a resume by a new session given the conversation so far: a module's ACP agent's, unless it
|
|
183
|
+
* says "load" (AcpEntryOptions.resume). */
|
|
184
|
+
const ACP_RESTART_PROMISES = Object.freeze({ ...ACP_PROMISES, resume: "restart" });
|
|
185
|
+
/** The code a module's ACP entry is refused by at its first launch when it promises resume "load" and its recipe
|
|
186
|
+
* declares no session/load (AcpEntryOptions.resume). */
|
|
187
|
+
export const HARNESS_RESUME_UNDECLARED = "HARNESS_RESUME_UNDECLARED";
|
|
188
|
+
/** An adapter harness's whole entry over the builder of its adapter for one run (moduleAdapter), run from the table
|
|
189
|
+
* (ON_TABLE): a module's (HarnessModuleKit.adapterEntry, which takes no `hidden`) and the built-in Goose's. */
|
|
190
|
+
const moduleEntryOf = (facts, adapter, { missing, ...extra } = {}, host = {}) => Object.freeze({ ...adapterEntry(facts, moduleAdapter(facts, adapter, missing ? { missing } : {}, host), extra), runner: ON_TABLE });
|
|
191
|
+
/** A proxy-billed ACP agent's whole entry, moduleEntryOf over serve's own ACP adapter: a module's (HarnessModuleKit.acpEntry,
|
|
192
|
+
* `host` none) and a proxy-billed recipe's under harness-check (AcpEntryHost). Its agent's allowlist and keys are read
|
|
193
|
+
* from the launch's environment, never this process's, and its recipe names no server key (ownKeysOnly). */
|
|
194
|
+
function acpProxyEntryOf(options, host = {}) {
|
|
195
|
+
const { facts, resume = "restart" } = options;
|
|
196
|
+
return moduleEntryOf(facts, async (launch) => {
|
|
197
|
+
const acp = acpPackage();
|
|
198
|
+
if (!acp)
|
|
199
|
+
throw new HarnessUnavailable(`${facts.label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
|
|
200
|
+
const recipe = await ownKeysOnly(facts, options.recipe(launch));
|
|
201
|
+
// Promising less than the recipe declares is allowed; promising a session/load the agent is never asked for is not.
|
|
202
|
+
if (resume === "load" && !recipe.declares.load)
|
|
203
|
+
throw new HarnessUnavailable(`${HARNESS_RESUME_UNDECLARED}: ${facts.label} (${facts.id}) promises resume "load", but its recipe's declares.load is false, so its run would restart instead: declare session/load in the recipe, or leave resume at "restart".`);
|
|
204
|
+
return acp.acpAdapter({
|
|
205
|
+
recipe,
|
|
206
|
+
proxy: options.proxy(launch),
|
|
207
|
+
...(options.beforeStart ? { beforeStart: options.beforeStart } : {}),
|
|
208
|
+
...(launch.confine ? { confine: launch.confine } : {}),
|
|
209
|
+
env: launch.env,
|
|
210
|
+
log: launch.log,
|
|
211
|
+
});
|
|
212
|
+
}, { promises: resume === "load" ? ACP_PROMISES : ACP_RESTART_PROMISES, ...(options.missing ? { missing: options.missing } : {}) }, host);
|
|
213
|
+
}
|
|
214
|
+
/** What a plan-billed ACP harness promises: as ACP_PROMISES, billed to its owner's plan. */
|
|
215
|
+
const ACP_PLAN_PROMISES = Object.freeze({ resume: "load", tool_gate: "permission", billing: "plan" });
|
|
216
|
+
/** The model id of a plan-billed agent's own default (`<id>/default`). */
|
|
217
|
+
const PLAN_DEFAULT_MODEL = "default";
|
|
218
|
+
/** A plan-billed ACP agent's whole entry: its models are the ones its vendor lists for its owner, named `<id>/<model-id>`
|
|
219
|
+
* (`<id>/default`: the vendor's own default), checked against that list when its session opens (ACP_MODEL_UNLISTED);
|
|
220
|
+
* no model key, route, proxy, catalog or price of ours is its, and it has no runner adapter of a module's (ON_TABLE). */
|
|
221
|
+
function acpPlanEntryOf(options, host = {}) {
|
|
222
|
+
const { facts } = options;
|
|
223
|
+
const { id, label } = facts;
|
|
224
|
+
if (modelWire(facts.wire))
|
|
225
|
+
throw new Error(`${id} runs on a model wire of ours, so its ACP entry is the proxy-billed one`);
|
|
226
|
+
const prefix = `${id}/`;
|
|
227
|
+
const make = async (env, needs) => {
|
|
228
|
+
const { fixOf, harnessLog } = await import("./adapters.js");
|
|
229
|
+
// What no key fixes is said first, as for the built-in harnesses' binaries.
|
|
230
|
+
const lacks = await options.missing?.(env);
|
|
231
|
+
if (lacks)
|
|
232
|
+
throw new HarnessUnavailable(lacks);
|
|
233
|
+
const acp = acpPackage();
|
|
234
|
+
if (!acp)
|
|
235
|
+
throw new HarnessUnavailable(`${label} needs the ACP adapter (${ACP_PACKAGE}) beside this server`);
|
|
236
|
+
if (needs.model.provider !== id)
|
|
237
|
+
throw new HarnessUnavailable(`${label} runs ${label}'s models, named ${prefix}<model-id>; the run's model is ${needs.model.provider}/${needs.model.modelId}.`);
|
|
238
|
+
const log = host.log ?? harnessLog(id, env);
|
|
239
|
+
try {
|
|
240
|
+
const recipe = await ownKeysOnly(facts, await options.recipe({ model: needs.model.modelId, log, ...(needs.confine ? { confine: needs.confine } : {}), env }));
|
|
241
|
+
// Its keys (recipe.keys) are read from the run's environment, which holds its own (ownKeys: run-secrets.ts keysFor).
|
|
242
|
+
return acp.acpAdapter({ recipe, ...(options.beforeStart ? { beforeStart: options.beforeStart } : {}), ...(needs.confine ? { confine: needs.confine } : {}), env, log });
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
if (error instanceof HarnessUnavailable)
|
|
246
|
+
throw error;
|
|
247
|
+
throw new HarnessUnavailable(error.message, fixOf(facts, error));
|
|
248
|
+
}
|
|
249
|
+
};
|
|
128
250
|
const entry = {
|
|
129
251
|
id,
|
|
130
|
-
label
|
|
252
|
+
label,
|
|
131
253
|
steer: facts.steer,
|
|
132
254
|
runMib: facts.runMib,
|
|
133
255
|
oneAlwaysFits: false,
|
|
134
256
|
facts,
|
|
135
|
-
promises:
|
|
136
|
-
ownKeys: Object.freeze([
|
|
137
|
-
hidden:
|
|
138
|
-
card:
|
|
257
|
+
promises: ACP_PLAN_PROMISES,
|
|
258
|
+
...(options.ownKeys ? { ownKeys: Object.freeze([...options.ownKeys]) } : {}),
|
|
259
|
+
...(options.hidden ? { hidden: options.hidden } : {}),
|
|
260
|
+
...(options.card ? { card: options.card } : {}),
|
|
139
261
|
runs: (_env, model) => model.startsWith(prefix),
|
|
140
262
|
onWire: () => true,
|
|
141
263
|
model: async (_env, ref, available) => {
|
|
142
264
|
if (!available)
|
|
143
265
|
return undefined;
|
|
144
|
-
const named = ref ?? `${prefix}${
|
|
266
|
+
const named = ref ?? `${prefix}${PLAN_DEFAULT_MODEL}`;
|
|
145
267
|
const modelId = named.startsWith(prefix) ? named.slice(prefix.length) : "";
|
|
146
|
-
const { acpPackage } = await import("./acp-package.js");
|
|
147
268
|
if (!modelId || !acpPackage()?.MODEL_ID.test(modelId))
|
|
148
|
-
return { why: `${
|
|
149
|
-
return { model: { provider:
|
|
269
|
+
return { why: `${label} runs a model ${label} lists for your ${label} API key, named ${prefix}<model-id> (${prefix}${PLAN_DEFAULT_MODEL} for ${label}'s own default); ${named} is not one.`, host: false, needs: "model" };
|
|
270
|
+
return { model: { provider: id, modelId } };
|
|
150
271
|
},
|
|
151
272
|
priceModel: (_env, model) => model,
|
|
152
|
-
adapter:
|
|
273
|
+
adapter: make,
|
|
153
274
|
refusal: async (env, given, { atStart }) => {
|
|
154
|
-
const {
|
|
275
|
+
const { startReason } = await import("./adapters.js");
|
|
155
276
|
try {
|
|
156
|
-
const adapter = await
|
|
277
|
+
const adapter = await make(env, given ?? { model: { provider: id, modelId: PLAN_DEFAULT_MODEL }, models: { getModel: () => undefined } });
|
|
157
278
|
const problems = adapter.check({ key: "capabilities", label: "capabilities", system: [], tools: [], context: "fresh" });
|
|
158
279
|
return problems.length ? { reason: problems.join(" ") } : undefined;
|
|
159
280
|
}
|
|
@@ -164,6 +285,77 @@ function cursorEntry(facts) {
|
|
|
164
285
|
};
|
|
165
286
|
return Object.freeze(entry);
|
|
166
287
|
}
|
|
288
|
+
export function acpEntryOf(options, host = {}) {
|
|
289
|
+
return modelWire(options.facts.wire) ? acpProxyEntryOf(options, host) : acpPlanEntryOf(options, host);
|
|
290
|
+
}
|
|
291
|
+
/** The kit a harness module is handed (HarnessModuleKit): never a host's log (AcpEntryHost), so its launches log as
|
|
292
|
+
* their harness. */
|
|
293
|
+
const MODULE_KIT = Object.freeze({
|
|
294
|
+
adapterEntry: (facts, adapter, extra) => moduleEntryOf(facts, adapter, extra),
|
|
295
|
+
acpEntry: (options) => acpProxyEntryOf(options),
|
|
296
|
+
});
|
|
297
|
+
/** Why Goose cannot run here (harness-owned.ts `missing`: not installed, or not the pinned binary) as an error of its
|
|
298
|
+
* code, so moduleAdapter refuses it with the install fix its facts name. */
|
|
299
|
+
const gooseRefused = (missing) => Object.assign(new Error(missing.message), { code: missing.code });
|
|
300
|
+
/** Goose's adapter for one run (moduleAdapter's builder, after its `missing`): its package's gooseAdapter on the binary
|
|
301
|
+
* its owner installed into the data's harnesses directory (`agentrun harness install goose`) and from nowhere else,
|
|
302
|
+
* looked up and verified again (its sha256 is kept per file identity, so only the first look reads it). Its model goes
|
|
303
|
+
* where claude-agent's does, the host's Anthropic Messages provider, through a model proxy of its own. */
|
|
304
|
+
async function gooseLaunch(launch) {
|
|
305
|
+
const found = await gooseMissing(launch.env);
|
|
306
|
+
if ("missing" in found)
|
|
307
|
+
throw gooseRefused(found.missing);
|
|
308
|
+
return acpPackage().gooseAdapter({
|
|
309
|
+
binary: found.binary, sha256: found.sha256, model: launch.model, provider: launch.provider, price: launch.price, log: launch.log,
|
|
310
|
+
...(launch.confine ? { confine: launch.confine } : {}),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/** What Cursor gives acpEntryOf for its plan-billed entry: billed to its owner's Cursor plan on the owner's Cursor API key
|
|
314
|
+
* (`ownKeys`), its model one Cursor lists for that key (`cursor/<model-id>`, `cursor/default` for Cursor's own). Listed
|
|
315
|
+
* only once its owner has installed it (`agentrun harness install cursor`): `missing` is its release, looked up and
|
|
316
|
+
* verified (harness-cursor.ts cursorMissing), and `beforeStart` checks its launcher and every file beside it again
|
|
317
|
+
* before each process starts. Stopped by its owner's turn and tool-call limits (cursorLimitsOf), which its card says. */
|
|
318
|
+
function cursorOptions(facts) {
|
|
319
|
+
/** Cursor's launcher, or the HarnessUnavailable that says why it is not here, with the fix (install, pins) it names. */
|
|
320
|
+
const launcher = async (env) => {
|
|
321
|
+
const found = await cursorMissing(env);
|
|
322
|
+
if (!("missing" in found))
|
|
323
|
+
return found.binary;
|
|
324
|
+
const { fixOf } = await import("./adapters.js");
|
|
325
|
+
throw new HarnessUnavailable(found.missing.message, fixOf(facts, found.missing));
|
|
326
|
+
};
|
|
327
|
+
return {
|
|
328
|
+
facts,
|
|
329
|
+
ownKeys: [CURSOR_KEY],
|
|
330
|
+
hidden: cursorHidden,
|
|
331
|
+
card: cursorCardOf,
|
|
332
|
+
missing: async (env) => void (await launcher(env)),
|
|
333
|
+
recipe: async (launch) => {
|
|
334
|
+
if (!launch.env[CURSOR_KEY])
|
|
335
|
+
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.`);
|
|
336
|
+
const acp = acpPackage();
|
|
337
|
+
let limits;
|
|
338
|
+
try {
|
|
339
|
+
limits = cursorLimitsOf(acp, launch.env);
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
throw new HarnessUnavailable(error.message);
|
|
343
|
+
}
|
|
344
|
+
const model = launch.model === CURSOR_DEFAULT_MODEL ? undefined : launch.model;
|
|
345
|
+
return acp.cursorRecipe({ command: await launcher(launch.env), limits, ...(model ? { model } : {}) });
|
|
346
|
+
},
|
|
347
|
+
beforeStart: async (command) => {
|
|
348
|
+
const acp = acpPackage();
|
|
349
|
+
const release = acp.pinnedRelease(acp.CURSOR_PIN, acp.acpPlatform(), true);
|
|
350
|
+
const root = release && acp.cursorRootOf(command, release.cmd);
|
|
351
|
+
// The launcher is the one cursorMissing found at its pinned path: a release or folder lost since is refused.
|
|
352
|
+
if (!release?.treeSha256 || !root)
|
|
353
|
+
throw new Error(`ACP_BINARY_MISMATCH: the Cursor launcher at ${command} is not at its pinned path inside its folder`);
|
|
354
|
+
// The tree's digest covers every file it runs, the launcher among them (as cursorAdapter's check does).
|
|
355
|
+
await acp.verifyPinnedTree(root, release.treeSha256);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
167
359
|
/** The secrets the built-in harnesses own (each entry's ownKeys), whether or not its package is beside serve here: a
|
|
168
360
|
* server without Cursor's adapter still never hands CURSOR_API_KEY to another harness's run (run-secrets.ts keysFor). */
|
|
169
361
|
export const BUILTIN_OWN_KEYS = Object.freeze([CURSOR_KEY]);
|
|
@@ -189,18 +381,32 @@ const BUILTIN = Object.freeze({
|
|
|
189
381
|
// Goose, over ACP, where its package is beside serve (acp-package.ts): its owner installs its pinned binary
|
|
190
382
|
// (`agentrun harness install goose`, harness-goose.ts), never a run; listed only once it is installed and verified.
|
|
191
383
|
...(GOOSE_FACTS ? {
|
|
192
|
-
[GOOSE_FACTS.id]:
|
|
193
|
-
|
|
384
|
+
[GOOSE_FACTS.id]: moduleEntryOf(GOOSE_FACTS, gooseLaunch, {
|
|
385
|
+
missing: async (env) => {
|
|
386
|
+
const found = await gooseMissing(env);
|
|
387
|
+
if ("missing" in found)
|
|
388
|
+
throw gooseRefused(found.missing);
|
|
389
|
+
return undefined;
|
|
390
|
+
},
|
|
391
|
+
promises: ACP_PROMISES,
|
|
194
392
|
hidden: gooseHidden,
|
|
195
393
|
}),
|
|
196
394
|
} : {}),
|
|
197
395
|
// Cursor, over ACP, where the same package is beside serve: its owner installs its pinned release (`agentrun harness
|
|
198
396
|
// install cursor`, harness-cursor.ts) and sets CURSOR_API_KEY; listed only once it is installed and verified.
|
|
199
|
-
...(CURSOR_FACTS ? { [CURSOR_FACTS.id]:
|
|
397
|
+
...(CURSOR_FACTS ? { [CURSOR_FACTS.id]: acpEntryOf(cursorOptions(CURSOR_FACTS)) } : {}),
|
|
200
398
|
});
|
|
201
399
|
/** The ids of the harnesses this server has built in (Goose and Cursor where their package is beside it, as a recipe
|
|
202
400
|
* needs it too): a recipe or module never takes one (harness-recipe.ts). */
|
|
203
401
|
export const BUILTIN_HARNESS_IDS = Object.freeze(Object.keys(BUILTIN));
|
|
402
|
+
/** Whether built-in harness `id` owns secret `key`: its own built-in entry names it in ownKeys. By the pair, so a key one
|
|
403
|
+
* built-in owns never crosses to another built-in, a module's entry or a test's; and none is owned where its harness's
|
|
404
|
+
* package is not beside serve (run-secrets.ts keysFor). */
|
|
405
|
+
export function builtinOwns(id, key) {
|
|
406
|
+
return Object.hasOwn(BUILTIN, id) && BUILTIN[id].ownKeys?.includes(key) === true;
|
|
407
|
+
}
|
|
408
|
+
/** The code a harness module's entry is refused by when its ownKeys names a key a built-in harness owns (BUILTIN_OWN_KEYS). */
|
|
409
|
+
export const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
|
|
204
410
|
const loaded = new Map();
|
|
205
411
|
const requireHere = createRequire(import.meta.url);
|
|
206
412
|
/** The members a harness module's new entry gives: what the table's readers ask of every entry. */
|
|
@@ -210,7 +416,7 @@ function entriesOf(path, named) {
|
|
|
210
416
|
const module = requireHere(resolve(path));
|
|
211
417
|
if (typeof module.entries !== "function")
|
|
212
418
|
throw new Error(`${named} names ${path}, which exports no entries(builtins)`);
|
|
213
|
-
return module.entries(BUILTIN);
|
|
419
|
+
return module.entries(BUILTIN, MODULE_KIT);
|
|
214
420
|
}
|
|
215
421
|
/** The harness modules `env` names (HARNESS_MODULES_ENV): none when it names none. */
|
|
216
422
|
function modulesOf(env) {
|
|
@@ -256,6 +462,9 @@ export function harnessTable(env) {
|
|
|
256
462
|
const missing = WHOLE.filter((member) => entry[member] === undefined);
|
|
257
463
|
if (missing.length)
|
|
258
464
|
throw new Error(`harness module ${module}: its entry ${id} lacks ${missing.join(", ")}`);
|
|
465
|
+
const owned = (entry.ownKeys ?? []).filter((key) => BUILTIN_OWN_KEYS.includes(key));
|
|
466
|
+
if (owned.length)
|
|
467
|
+
throw Object.assign(new Error(`${HARNESS_KEY_OWNED}: harness module ${module}: its entry ${id} names ${owned.join(", ")} in ownKeys, a key a built-in harness owns and is handed alone: a module's harness takes none of ${BUILTIN_OWN_KEYS.join(", ")}`), { code: HARNESS_KEY_OWNED });
|
|
259
468
|
built[id] = Object.freeze({ ...entry, id });
|
|
260
469
|
}
|
|
261
470
|
}
|
|
@@ -308,6 +517,11 @@ export const ownerHarness = (env, id) => {
|
|
|
308
517
|
const key = id ?? DEFAULT_HARNESS;
|
|
309
518
|
return Object.hasOwn(table, key) ? table[key] : undefined;
|
|
310
519
|
};
|
|
520
|
+
/** The facts of harness `id`'s adapter on the owner's table (ownerTable: the built-in harnesses and those `env`'s modules
|
|
521
|
+
* add, never a test table's, so a stand-in keeps the facts of the harness it stands in for). Every reader of a harness's
|
|
522
|
+
* facts by id asks here: its models (model-form.ts), its key rows (model.ts), its search and tool names (tool-plane.ts,
|
|
523
|
+
* tool-gate.ts). Undefined for pi, for a module's harness that gives none, and for an id the table has none of. */
|
|
524
|
+
export const factsOf = (env, id) => ownerHarness(env, id)?.facts;
|
|
311
525
|
/** The entry of harness `id` (none: the default, pi) on `env`'s table; undefined for an id this server has none of. */
|
|
312
526
|
export const harnessOf = (env, id) => harnessTable(env)[id ?? DEFAULT_HARNESS];
|
|
313
527
|
/** Whether `id` runs on an adapter (every harness but pi): a session of its own, beside the run's process. */
|
package/dist/harness.js
CHANGED
|
@@ -86,9 +86,9 @@ export function harnessOffers(env) {
|
|
|
86
86
|
// lacks only a key is (a save warns of that, never refuses).
|
|
87
87
|
const { MODEL_REF } = await import("./validate.js");
|
|
88
88
|
const { providerFor, HarnessUnavailable } = await import("./provider.js");
|
|
89
|
-
const { adapterFactsOf } = await import("./adapter-facts.js");
|
|
90
89
|
const { FAUX_ENV } = await import("./model.js");
|
|
91
|
-
const
|
|
90
|
+
const { factsOf } = await import("./harness-table.js");
|
|
91
|
+
const facts = factsOf(env, offer.id);
|
|
92
92
|
for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
|
|
93
93
|
if (!MODEL_REF.test(id))
|
|
94
94
|
continue;
|
package/dist/key-refusal.d.ts
CHANGED
|
@@ -27,7 +27,8 @@ export declare const answerPasses: {
|
|
|
27
27
|
/** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
|
|
28
28
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
29
29
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
30
|
-
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none
|
|
30
|
+
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
31
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run of more
|
|
31
32
|
* than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
|
|
32
33
|
* by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
|
|
33
34
|
* output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
|
package/dist/key-refusal.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// count, a file name, a duration, another service's status) is no refused key, and the error is left as it is.
|
|
5
5
|
import { DEFAULT_HARNESS } from "./harness.js";
|
|
6
6
|
import { harnessOf } from "./harness-table.js";
|
|
7
|
-
import { redactSecrets, valueMatcher } from "./learn/secrets.js";
|
|
7
|
+
import { endsInScheme, redactSecrets, valueMatcher } from "./learn/secrets.js";
|
|
8
8
|
import { hostModel, MODEL_KEYS } from "./model.js";
|
|
9
9
|
import { modelWire, openRouterOnly, WIRES } from "./provider.js";
|
|
10
10
|
import { savedGatewayIn } from "./model-gateway.js";
|
|
@@ -82,7 +82,8 @@ export const answerPasses = { count: 0 };
|
|
|
82
82
|
/** `text`, a run's answer as serve serves it (its final answer, or a string in its workflow output), with no held secret
|
|
83
83
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
84
84
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
85
|
-
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none
|
|
85
|
+
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
86
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme). A run of more
|
|
86
87
|
* than ANSWER_PIECE characters with no whitespace is no person's text and is shown as "[redacted]", unread. A value split
|
|
87
88
|
* by whitespace across a cut, or a form only found across pieces, still shows to one valueMatcher pass over the joined
|
|
88
89
|
* output, and then the whole answer is "[redacted]", as redactSecrets does with a text that still holds a value. */
|
|
@@ -104,6 +105,21 @@ export function redactedAnswer(text, secrets) {
|
|
|
104
105
|
continue;
|
|
105
106
|
}
|
|
106
107
|
to = from + space + 1;
|
|
108
|
+
// A cut after a Bearer scheme would leave its token at the head of the next piece, where no shape reads it (the
|
|
109
|
+
// shape is the scheme, then the token). The cut moves back to the whitespace before the scheme; with none in this
|
|
110
|
+
// piece, the scheme and its token are read as one run, to the next whitespace, as a run with no whitespace is.
|
|
111
|
+
if (endsInScheme(text.slice(from, to))) {
|
|
112
|
+
const before = text.slice(from, to).trimEnd().search(/\s[^\s]*$/);
|
|
113
|
+
if (before > 0)
|
|
114
|
+
to = from + before + 1;
|
|
115
|
+
else {
|
|
116
|
+
const next = text.slice(to).search(/\s/);
|
|
117
|
+
to = next < 0 ? text.length : to + next;
|
|
118
|
+
parts.push(to - from > ANSWER_PIECE ? "[redacted]" : redactSecrets(text.slice(from, to), secrets, Buffer.byteLength(text.slice(from, to))));
|
|
119
|
+
from = to;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
107
123
|
}
|
|
108
124
|
const piece = text.slice(from, to);
|
|
109
125
|
parts.push(redactSecrets(piece, secrets, Buffer.byteLength(piece)));
|
package/dist/learn/promote.d.ts
CHANGED
|
@@ -80,6 +80,10 @@ export interface PromotionRecord {
|
|
|
80
80
|
/** The learning commit whose workflows/<workflow>/workflow.json is this digest's text: the seed of the claim that
|
|
81
81
|
* recorded it. What the digest serves from as the champion (championOf) once a newer revision is on the folder's main. */
|
|
82
82
|
readonly commit?: string;
|
|
83
|
+
/** `sdk`: a connected (SDK) agent's check (runner/promotion.ts reserveSdkCheck), on its reservation and the record that
|
|
84
|
+
* decides it. Its one run (`runs`) is the agent's own native turn, not a replay run; a replaying one with no `runs`
|
|
85
|
+
* waits for the next native turn the draft takes. Absent: a server replay's. */
|
|
86
|
+
readonly via?: "sdk";
|
|
83
87
|
}
|
|
84
88
|
/** One audit row a hold was decided on that disagreed: the served run (`served`) and its input, the run whose answer is
|
|
85
89
|
* the agent's (`run`: the shadow run, else the served run for a grade), the agent's answer (`agent`: the shadow's, null
|
|
@@ -142,6 +146,13 @@ export type CheckRecord = CheckBar & {
|
|
|
142
146
|
readonly skipped_tools?: readonly SkippedTool[];
|
|
143
147
|
readonly disagreements?: readonly CheckDisagreement[];
|
|
144
148
|
readonly stopped?: true;
|
|
149
|
+
/** A connected agent's check: how many of its reserved native turns gave no answer to check the draft against (a
|
|
150
|
+
* cancelled or refused turn, a subagent, redacted evidence, no shadow report) and were given back to wait for the
|
|
151
|
+
* next one (runner/promotion.ts SDK_CHECK_RELEASES stops it). Absent: none. */
|
|
152
|
+
readonly released?: number;
|
|
153
|
+
/** A connected agent's check: how many fresh read-only calls its shadow made where the native turn's recording had
|
|
154
|
+
* no result (the client's opt-in shadowReadFallback). Absent: none, every call was answered from the recording. */
|
|
155
|
+
readonly fresh_reads?: number;
|
|
145
156
|
/** How it compared with no agree_on: the fast model that read the answers (its name), when it was asked on any input.
|
|
146
157
|
* With agree_on, the paths compared (CheckBar.agree_on); with neither, the whole answer. */
|
|
147
158
|
readonly grader?: string;
|
package/dist/learn/secrets.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
|
|
2
|
+
* (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
|
|
3
|
+
* redactedAnswer). */
|
|
4
|
+
export declare const endsInScheme: (text: string) => boolean;
|
|
1
5
|
/** The kinds of secret-shaped text in `text`. */
|
|
2
6
|
export declare const secretShapes: (text: string) => string[];
|
|
3
7
|
/** The kinds of text in `text` learning never keeps: every secret shape, and a bank's numbers beside their words. */
|
package/dist/learn/secrets.js
CHANGED
|
@@ -5,6 +5,17 @@ const GITHUB_TOKEN = /gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{20,}/;
|
|
|
5
5
|
const JWT = /eyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/;
|
|
6
6
|
/** A Standard Webhooks signing secret: `whsec_` and base64, this server's or any other's. */
|
|
7
7
|
const WEBHOOK_SECRET = /whsec_[A-Za-z0-9+/]{24,}={0,2}/;
|
|
8
|
+
/** The token after a `Bearer` scheme (RFC 6750's characters), in any case: twenty characters or more with a digit among
|
|
9
|
+
* them, so a word after "bearer" ("bearer authentication/authorization"), a placeholder (`<token>`, `$TOKEN`,
|
|
10
|
+
* `YOUR_API_KEY`) and a challenge's parameter (`Bearer realm="x"`) are none. The token alone is the match: the scheme
|
|
11
|
+
* before it stays, so a reader still sees a header was there. The scheme is at most three blanks before the token, and
|
|
12
|
+
* the digit is looked for only through the token's own characters, so the reading stays linear. */
|
|
13
|
+
const BEARER_TOKEN = /(?<=\bBearer\s{1,3})(?=[A-Za-z._~+/-]*\d)[A-Za-z0-9._~+/-]{20,}={0,2}/i;
|
|
14
|
+
/** The value of a URL parameter named like a credential, after `?` or `&`: sixteen characters or more, to the next
|
|
15
|
+
* separator. The name is the whole parameter's (`token`, never `page_token`), and the value alone is the match, so the
|
|
16
|
+
* name stays. A signed URL's signature is one: whoever holds the URL holds what it grants. No bracket is a value's
|
|
17
|
+
* character (a URL writes one percent-encoded), so a value already cut to "[redacted]" is never read as one. */
|
|
18
|
+
const URL_CREDENTIAL = /(?<=[?&](?:api[_-]?key|access[_-]?token|auth[_-]?token|id[_-]?token|refresh[_-]?token|client[_-]?secret|x-amz-signature|x-amz-security-token|x-goog-signature|token|secret|password|passwd|signature|sig)=)[^\s&#"'`<>\\[\]]{16,}/i;
|
|
8
19
|
/** A bank account number beside its word: "account", "acct", "a/c" or "bank account", maybe "number", "no.", "#", ":"
|
|
9
20
|
* or "is" after it, then six digits or more, single dashes or spaces between them. A count before the word ("4
|
|
10
21
|
* accounts"), a date (YYYY-MM-DD), a year or a card's last four is none: the word must come first, the digits right
|
|
@@ -28,7 +39,16 @@ const SHAPES = [
|
|
|
28
39
|
["JWT", JWT],
|
|
29
40
|
["webhook signing secret", WEBHOOK_SECRET],
|
|
30
41
|
["URL with a password", /:\/\/[^\s/?#@:]+:[^\s/?#@]*@/],
|
|
42
|
+
["bearer token", BEARER_TOKEN],
|
|
43
|
+
["URL parameter named like a credential", URL_CREDENTIAL],
|
|
31
44
|
];
|
|
45
|
+
/** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
|
|
46
|
+
* (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
|
|
47
|
+
* redactedAnswer). */
|
|
48
|
+
export const endsInScheme = (text) => {
|
|
49
|
+
const head = text.trimEnd();
|
|
50
|
+
return head.length < text.length && text.length - head.length <= 3 && /\bBearer$/i.test(head.slice(-7));
|
|
51
|
+
};
|
|
32
52
|
/** The kinds of secret-shaped text in `text`. */
|
|
33
53
|
export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern.test(text)).map(([kind]) => kind);
|
|
34
54
|
/** A bank's numbers beside their words, which learning never keeps: an account, IBAN, routing or sort-code number. Not
|
|
@@ -65,6 +85,8 @@ const toEnd = (m) => m.index + m[0].length;
|
|
|
65
85
|
* and run past it, so it reads on from the next character.
|
|
66
86
|
* - JWT: a match that starts in the first part reads on through the same second and third parts, so it ends where this
|
|
67
87
|
* one does; one that starts in the second part can run past it, into a fourth. It reads on from the second part.
|
|
88
|
+
* - A URL's credential: its value runs to the next separator and may hold "?" and "=", so a parameter of the same
|
|
89
|
+
* name inside it ("?token=a?token=a…") starts a match that runs to the same end.
|
|
68
90
|
* - whsec_: not here. Its run's class has no "_", so a run takes the next secret's "whsec" and stops at its "_": that
|
|
69
91
|
* secret starts inside this match and runs past it, and is found only by reading on from the next character. */
|
|
70
92
|
const RESUME = new Map([
|
|
@@ -72,6 +94,7 @@ const RESUME = new Map([
|
|
|
72
94
|
[SLACK_TOKEN, toEnd],
|
|
73
95
|
[GITHUB_TOKEN, (m) => (m[0].startsWith("github_pat_") ? toEnd(m) : m.index + 1)],
|
|
74
96
|
[JWT, (m) => m.index + m[0].indexOf(".") + 1],
|
|
97
|
+
[URL_CREDENTIAL, toEnd],
|
|
75
98
|
]);
|
|
76
99
|
function places(text, form) {
|
|
77
100
|
const out = [];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ModelNeeds } from "./model.js";
|
|
2
|
+
export type LearningModel = {
|
|
3
|
+
location: "server" | "native";
|
|
4
|
+
ready: boolean;
|
|
5
|
+
model: string | null;
|
|
6
|
+
needs: ModelNeeds | null;
|
|
7
|
+
reason: string | null;
|
|
8
|
+
};
|
|
9
|
+
/** An omitted revision describes the default SDK compile route for a server with no agents yet. Native bindings keep
|
|
10
|
+
* their original sign-in. For managed harnesses the existing model selection checks their own wire/login; SDKs need
|
|
11
|
+
* the separate server compile route, even when the original application's harness already has its own credential.
|
|
12
|
+
* checkCredential is for SDK admission after its durable receipt lookup, never a metadata read. */
|
|
13
|
+
export declare function learningModelOf(env: NodeJS.ProcessEnv, revision?: {
|
|
14
|
+
kind: string;
|
|
15
|
+
body: unknown;
|
|
16
|
+
} | null, options?: {
|
|
17
|
+
checkCredential?: boolean;
|
|
18
|
+
}): Promise<LearningModel>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Learning's model requirement, shared by its settings view and SDK admission. Metadata checks configured routes and
|
|
2
|
+
// sign-in state without reading or renewing a managed token. Only admission checks the actual credential; neither
|
|
3
|
+
// sends a model request or treats a tool/decision key as a generative model credential.
|
|
4
|
+
import { chooseModel, FAUX_ENV, hostModel } from "./model.js";
|
|
5
|
+
import { harnessOf } from "./harness-table.js";
|
|
6
|
+
import { HarnessUnavailable, modelWire, providerFor } from "./provider.js";
|
|
7
|
+
import { nativeOf } from "./native/binding.js";
|
|
8
|
+
import { noServerKeyFor, serverKeyMissing } from "./run-model-key.js";
|
|
9
|
+
import { askRouteOf } from "./runner/sdk-ask.js";
|
|
10
|
+
import { routeOf } from "./runner/model-route.js";
|
|
11
|
+
import { PI_WIRES } from "./runner/adapter-run-spec.js";
|
|
12
|
+
/** An omitted revision describes the default SDK compile route for a server with no agents yet. Native bindings keep
|
|
13
|
+
* their original sign-in. For managed harnesses the existing model selection checks their own wire/login; SDKs need
|
|
14
|
+
* the separate server compile route, even when the original application's harness already has its own credential.
|
|
15
|
+
* checkCredential is for SDK admission after its durable receipt lookup, never a metadata read. */
|
|
16
|
+
export async function learningModelOf(env, revision, options = {}) {
|
|
17
|
+
const body = (revision?.body ?? {});
|
|
18
|
+
const native = nativeOf(body);
|
|
19
|
+
if (native)
|
|
20
|
+
return { location: "native", ready: true, model: native.model ?? null, needs: null,
|
|
21
|
+
reason: "Uses the connected runtime's existing sign-in. Native corrections do not need a server model key; learned workflows are unavailable on this connection." };
|
|
22
|
+
const notReady = (model, needs, reason) => ({ location: "server", ready: false, model, needs, reason });
|
|
23
|
+
if (revision && revision.kind !== "agentic")
|
|
24
|
+
return notReady(null, null, "Workflow definitions do not create new learning.");
|
|
25
|
+
const configured = body.model ?? hostModel(env, "default", body.harness) ?? null;
|
|
26
|
+
try {
|
|
27
|
+
const entry = harnessOf(env, body.harness);
|
|
28
|
+
const choice = entry?.onWire(env) ? await entry.model(env, body.model, true) : await chooseModel(env, body.model, "default", body.harness);
|
|
29
|
+
if (!choice)
|
|
30
|
+
return notReady(configured, "model", "Choose a server model supported by this agent's harness in Settings → API Keys.");
|
|
31
|
+
if ("why" in choice)
|
|
32
|
+
return notReady(configured, choice.needs ?? (choice.host ? "key" : "model"), choice.why.replaceAll("Settings → Model keys", "Settings → API Keys"));
|
|
33
|
+
if (!choice.model)
|
|
34
|
+
return notReady(configured, "model", "Configure a server model in Settings → API Keys before enabling learning.");
|
|
35
|
+
const model = `${choice.model.provider}/${choice.model.modelId}`;
|
|
36
|
+
// A managed plan harness compiles in its own session, never through a server model proxy. Keep its installation,
|
|
37
|
+
// own credential and adapter checks: naming a model alone does not establish that the harness can run here.
|
|
38
|
+
if (revision && !body.sdk && entry?.facts && !modelWire(entry.facts.wire)) {
|
|
39
|
+
const hidden = entry.hidden?.(env);
|
|
40
|
+
if (hidden)
|
|
41
|
+
return notReady(model, "model", hidden);
|
|
42
|
+
const refused = await entry.refusal(env, { model: choice.model, models: { getModel: () => undefined } }, { atStart: false });
|
|
43
|
+
if (refused)
|
|
44
|
+
return notReady(model, entry.ownKeys?.some(key => !env[key]) ? "key" : "model", refused.reason);
|
|
45
|
+
return { location: "server", ready: true, model, needs: null, reason: null };
|
|
46
|
+
}
|
|
47
|
+
const needsServerKey = !env[FAUX_ENV] && (!revision || body.sdk
|
|
48
|
+
? noServerKeyFor(env, "Background learning") !== undefined
|
|
49
|
+
: serverKeyMissing(env, { kind: "agentic", model: choice.model }));
|
|
50
|
+
if (needsServerKey)
|
|
51
|
+
return notReady(model, "key", "Add a server-owned model gateway key in Settings → API Keys. Background learning cannot use a caller's per-run key.");
|
|
52
|
+
// Managed agents compile inside their own harness session, with that harness's model and authentication.
|
|
53
|
+
// SDK agents compile separately through pi's server route. A native application's sign-in is never copied here.
|
|
54
|
+
try {
|
|
55
|
+
if (!revision || body.sdk) {
|
|
56
|
+
const route = await askRouteOf(model, env, one => routeOf(one, env, "default", PI_WIRES));
|
|
57
|
+
if (options.checkCredential)
|
|
58
|
+
await route.provider.credential();
|
|
59
|
+
}
|
|
60
|
+
else if (entry?.onWire(env) && entry.facts) {
|
|
61
|
+
// Wire model selection names a model even with no key. Its provider checks the actual harness login or key.
|
|
62
|
+
const provider = providerFor(entry.facts.wire, env, choice.model, entry.id);
|
|
63
|
+
if (options.checkCredential)
|
|
64
|
+
await provider.credential();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof HarnessUnavailable && !error.keys?.length)
|
|
69
|
+
return notReady(model, "model", `${error.message} Check the learning model and harness in Settings → API Keys.`);
|
|
70
|
+
return notReady(model, "key", "Configure a model credential for this server's selected learning model in Settings → API Keys. Tool and decision-provider keys do not enable workflow compilation.");
|
|
71
|
+
}
|
|
72
|
+
return { location: "server", ready: true, model, needs: null, reason: null };
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return notReady(configured, "model", "The configured learning model could not be resolved. Check its provider, model and credentials in Settings → API Keys.");
|
|
76
|
+
}
|
|
77
|
+
}
|
package/dist/llms.txt
CHANGED
|
@@ -15,6 +15,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
|
|
|
15
15
|
- [OpenAPI document](/v2/openapi.json): every route and schema, the `agentrun.v2/0` contract with this server's own routes marked `x-agentrun-serve`.
|
|
16
16
|
- [Capabilities](/v2/capabilities): the harnesses, tools, models and efforts this server has, and what it does not offer.
|
|
17
17
|
- `POST /v2/agents` with `{definition: {name, instructions, tools, harness?, model?, thinking?}}` makes an agent (a workflow one holds `workflow` in place of `instructions`). A refusal is `422 input_invalid` naming each field. `PUT /v2/agents/{id}/definition` makes its next revision.
|
|
18
|
+
- An agentic definition's `output_schema` is the JSON Schema its final answer's last fenced json block meets, read into a completed run's `result.output`. A run a schedule trigger starts is handed that trigger's last completed `result.output` after its message, whole up to 32 KiB (as 2-space JSON); over it, only the top-level fields the schema names in `x-carried` (an array of unique names of its root `properties`, from the schema of the run that produced it). Keep a carried array oldest first: when the carried fields are over 32 KiB, the largest carried array drops its first (oldest) entries until they fit, said per field; the engine reads no dates. A scalar or object is never cut; still over with nothing left to drop, none is handed, said so.
|
|
18
19
|
- `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
|
|
19
20
|
- `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
|
|
20
21
|
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
|