@parcha/agentrun-serve 0.1.0-beta.30 → 0.1.0-beta.31
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 +50 -0
- package/README.md +182 -26
- package/dist/agents.d.ts +8 -3
- package/dist/agents.js +4 -1
- package/dist/app.js +23 -8
- package/dist/background.d.ts +2 -1
- package/dist/background.js +41 -20
- package/dist/box-egress-vm.d.ts +125 -0
- package/dist/box-egress-vm.js +350 -0
- package/dist/box-egress.d.ts +3 -2
- package/dist/box-relay-vm.d.ts +4 -0
- package/dist/box-relay-vm.js +76 -55
- package/dist/boxes.d.ts +7 -2
- package/dist/boxes.js +30 -11
- package/dist/cap.d.ts +2 -1
- package/dist/cap.js +2 -1
- package/dist/cli.js +30 -4
- package/dist/console/assets/{index-34jfpIbQ.js → index-CnJBf7Lc.js} +90 -85
- package/dist/console/index.html +1 -1
- package/dist/decisions.d.ts +3 -3
- package/dist/decisions.js +4 -3
- package/dist/files.d.ts +3 -0
- package/dist/files.js +3 -0
- package/dist/grade.d.ts +5 -2
- package/dist/grade.js +13 -5
- package/dist/harness-app.js +10 -1
- package/dist/host-check.d.ts +12 -0
- package/dist/host-check.js +34 -0
- package/dist/key-words.d.ts +37 -0
- package/dist/key-words.js +40 -0
- package/dist/learn/grade.d.ts +3 -0
- package/dist/learn/grade.js +3 -1
- package/dist/learn/index.d.ts +1 -1
- package/dist/learn/index.js +1 -1
- package/dist/learn/reflect.js +2 -0
- package/dist/learn/skills.d.ts +2 -0
- package/dist/learn/skills.js +16 -0
- package/dist/learning-routes.d.ts +30 -1
- package/dist/learning-routes.js +173 -19
- package/dist/learning-run.d.ts +1 -1
- package/dist/learning-run.js +25 -4
- package/dist/learning-words.d.ts +7 -3
- package/dist/learning-words.js +26 -8
- package/dist/learning.d.ts +9 -1
- package/dist/learning.js +57 -2
- package/dist/mcp-gateway.d.ts +96 -0
- package/dist/mcp-gateway.js +408 -0
- package/dist/mcp-meta.d.ts +17 -0
- package/dist/mcp-meta.js +38 -0
- package/dist/mcp-servers.d.ts +26 -5
- package/dist/mcp-servers.js +53 -10
- package/dist/openapi.js +52 -9
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -0
- package/dist/place.d.ts +3 -2
- package/dist/place.js +11 -3
- package/dist/print.d.ts +7 -0
- package/dist/print.js +13 -0
- package/dist/run-box.js +15 -5
- package/dist/runnable.d.ts +8 -1
- package/dist/runnable.js +51 -2
- package/dist/runs.d.ts +15 -8
- package/dist/runs.js +66 -13
- package/dist/secrets.d.ts +15 -0
- package/dist/secrets.js +20 -2
- package/dist/server.d.ts +10 -1
- package/dist/server.js +111 -29
- package/dist/tool-gate.d.ts +18 -3
- package/dist/tool-gate.js +44 -13
- package/dist/tool-keys.d.ts +2 -1
- package/dist/tool-keys.js +4 -8
- package/dist/tool-plane.d.ts +5 -1
- package/dist/tool-plane.js +30 -6
- package/dist/tools.js +8 -5
- package/dist/web-fetch.js +3 -3
- package/package.json +12 -16
package/dist/console/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<meta name="color-scheme" content="light dark" />
|
|
7
7
|
<title>AgentRun</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' fill='%23ff8000'/%3E%3Cpath d='M12 9l11 7-11 7z' fill='%23000'/%3E%3C/svg%3E" />
|
|
9
|
-
<script type="module" crossorigin src="./assets/index-
|
|
9
|
+
<script type="module" crossorigin src="./assets/index-CnJBf7Lc.js"></script>
|
|
10
10
|
<link rel="stylesheet" crossorigin href="./assets/index-DUHbWcIP.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
package/dist/decisions.d.ts
CHANGED
|
@@ -54,14 +54,14 @@ export type DecisionNeeds = {
|
|
|
54
54
|
* descriptor at all. */
|
|
55
55
|
export declare function decisionKeysFor(env: NodeJS.ProcessEnv, needs: DecisionNeeds): Record<string, string>;
|
|
56
56
|
/** Why Jev does not run here, naming the variable to set. */
|
|
57
|
-
export declare const jevMissing
|
|
57
|
+
export declare const jevMissing: string;
|
|
58
58
|
/** Why Parallel does not run here, naming the variable to set. */
|
|
59
|
-
export declare const parallelMissing
|
|
59
|
+
export declare const parallelMissing: string;
|
|
60
60
|
/** Why the OpenRouter route is worth a note, naming the variable Jev runs on: its key is also the model gateway's, which
|
|
61
61
|
* a run's process holds. */
|
|
62
62
|
export declare const jevGatewayNote: (env: NodeJS.ProcessEnv) => string;
|
|
63
63
|
/** Why OpenRouter's decision models do not run here, naming the variable to set. */
|
|
64
|
-
export declare const openrouterMissing
|
|
64
|
+
export declare const openrouterMissing: string;
|
|
65
65
|
/** What to know of OpenRouter's decision models here: the key they run on, which a run's process holds as the model
|
|
66
66
|
* gateway's, and that images go only to a model the catalog lists with image input, untested live. */
|
|
67
67
|
export declare const openrouterNote: (env: NodeJS.ProcessEnv) => string;
|
package/dist/decisions.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import { closeSync, readFileSync } from "node:fs";
|
|
17
17
|
import { pathToFileURL } from "node:url";
|
|
18
18
|
import { FAUX_ENV } from "./model.js";
|
|
19
|
+
import { keyNeeded } from "./key-words.js";
|
|
19
20
|
export const JEV_KEY_ENV = "TYPESAFE_API_KEY";
|
|
20
21
|
export const JEV_OPENROUTER_KEY_ENV = "OPENROUTER_API_KEY";
|
|
21
22
|
export const PARALLEL_KEY_ENV = "PARALLEL_API_KEY";
|
|
@@ -90,14 +91,14 @@ export function decisionKeysFor(env, needs) {
|
|
|
90
91
|
return Object.fromEntries(Object.entries(decisionKeysOf(env)).filter(([name]) => names.has(name)));
|
|
91
92
|
}
|
|
92
93
|
/** Why Jev does not run here, naming the variable to set. */
|
|
93
|
-
export const jevMissing = `
|
|
94
|
+
export const jevMissing = `A workflow's judge, pick, sift, route and ask nodes need ${keyNeeded([JEV_KEY_ENV])}. Jev also runs through OpenRouter, on ${keyNeeded([JEV_OPENROUTER_KEY_ENV])}, or on ${JEV_GATEWAY_KEY_ENV} with AGENT_MODEL_BASE_URL on openrouter.ai, set where the server starts.`;
|
|
94
95
|
/** Why Parallel does not run here, naming the variable to set. */
|
|
95
|
-
export const parallelMissing = `
|
|
96
|
+
export const parallelMissing = `A decision node naming the provider "parallel" needs ${keyNeeded([PARALLEL_KEY_ENV])}.`;
|
|
96
97
|
/** Why the OpenRouter route is worth a note, naming the variable Jev runs on: its key is also the model gateway's, which
|
|
97
98
|
* a run's process holds. */
|
|
98
99
|
export const jevGatewayNote = (env) => `Jev runs on ${openRouterKeyEnv(env)}, the model gateway key on this server, which a run's processes hold in their environment for its model nodes. Set ${JEV_KEY_ENV} to keep the decision key out of them.`;
|
|
99
100
|
/** Why OpenRouter's decision models do not run here, naming the variable to set. */
|
|
100
|
-
export const openrouterMissing = `
|
|
101
|
+
export const openrouterMissing = `A decision node naming the provider "openrouter" needs ${keyNeeded([JEV_OPENROUTER_KEY_ENV])}, or ${JEV_GATEWAY_KEY_ENV} with AGENT_MODEL_BASE_URL on openrouter.ai, set where the server starts.`;
|
|
101
102
|
/** What to know of OpenRouter's decision models here: the key they run on, which a run's process holds as the model
|
|
102
103
|
* gateway's, and that images go only to a model the catalog lists with image input, untested live. */
|
|
103
104
|
export const openrouterNote = (env) => `Any OpenRouter Decisions model, named by the node's model (required), on ${openRouterKeyEnv(env)}, the model gateway key on this server, which a run's processes hold in their environment. Images are experimental: sent only to a model OpenRouter's catalog lists with image input.`;
|
package/dist/files.d.ts
CHANGED
|
@@ -13,6 +13,9 @@ export declare const RUN_LAUNCHING = "launching";
|
|
|
13
13
|
export declare const FOLLOW_UP_OPEN_ENV = "AGENTRUN_FOLLOW_UP_OPEN";
|
|
14
14
|
/** The server's API token (`ar_local_...`), in the data directory, made at its first start when it is given none. */
|
|
15
15
|
export declare const TOKEN_FILE = ".token";
|
|
16
|
+
/** Where a running server is, for the launcher's CLI (`npx @parcha/agentrun agents list`), in the data directory: its
|
|
17
|
+
* base URL, its pid and its token's file, never the token. Written once it listens, mode 0600; removed on a clean exit. */
|
|
18
|
+
export declare const SERVER_FILE = ".server.json";
|
|
16
19
|
/** The server-wide door token, in the data directory: the door of a run an older server started takes it. */
|
|
17
20
|
export declare const DOOR_TOKEN_FILE = ".door-token";
|
|
18
21
|
/** A run's own door token, in its directory, made at its first launch and handed to its process alone (its
|
package/dist/files.js
CHANGED
|
@@ -17,6 +17,9 @@ export const RUN_LAUNCHING = "launching";
|
|
|
17
17
|
export const FOLLOW_UP_OPEN_ENV = "AGENTRUN_FOLLOW_UP_OPEN";
|
|
18
18
|
/** The server's API token (`ar_local_...`), in the data directory, made at its first start when it is given none. */
|
|
19
19
|
export const TOKEN_FILE = ".token";
|
|
20
|
+
/** Where a running server is, for the launcher's CLI (`npx @parcha/agentrun agents list`), in the data directory: its
|
|
21
|
+
* base URL, its pid and its token's file, never the token. Written once it listens, mode 0600; removed on a clean exit. */
|
|
22
|
+
export const SERVER_FILE = ".server.json";
|
|
20
23
|
/** The server-wide door token, in the data directory: the door of a run an older server started takes it. */
|
|
21
24
|
export const DOOR_TOKEN_FILE = ".door-token";
|
|
22
25
|
/** A run's own door token, in its directory, made at its first launch and handed to its process alone (its
|
package/dist/grade.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type Judged = {
|
|
|
19
19
|
cost: GradeCost;
|
|
20
20
|
} & ({
|
|
21
21
|
verdict: Verdict;
|
|
22
|
+
unread?: string;
|
|
22
23
|
} | {
|
|
23
24
|
reason: "grade_failed";
|
|
24
25
|
error: Error;
|
|
@@ -55,8 +56,10 @@ export declare function graderAuth(provider: RunProvider): {
|
|
|
55
56
|
fileExists: () => Promise<boolean>;
|
|
56
57
|
};
|
|
57
58
|
/** The grader, on `gradeModel` when the server names one (gradeModelOf), given `asked`, what the user said in the run:
|
|
58
|
-
* its verdict, or why it gave none; with what it spent.
|
|
59
|
-
*
|
|
59
|
+
* its verdict, or why it gave none; with what it spent. An answer the host cannot read is asked once more, with the same
|
|
60
|
+
* prompt and under the same bound, each ask counted once in `cost`; two such answers are a drop that could not be read,
|
|
61
|
+
* with the last answer as it came (`unread`, for the caller to cut of secrets and keep). Rejects only when `signal` (the
|
|
62
|
+
* server closing) aborts it: nothing is decided then. */
|
|
60
63
|
export declare function judgeProposal(input: {
|
|
61
64
|
runId: string;
|
|
62
65
|
agent: Agent;
|
package/dist/grade.js
CHANGED
|
@@ -189,19 +189,27 @@ async function graderModel(env, agent, cost, named) {
|
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
191
|
/** The grader, on `gradeModel` when the server names one (gradeModelOf), given `asked`, what the user said in the run:
|
|
192
|
-
* its verdict, or why it gave none; with what it spent.
|
|
193
|
-
*
|
|
192
|
+
* its verdict, or why it gave none; with what it spent. An answer the host cannot read is asked once more, with the same
|
|
193
|
+
* prompt and under the same bound, each ask counted once in `cost`; two such answers are a drop that could not be read,
|
|
194
|
+
* with the last answer as it came (`unread`, for the caller to cut of secrets and keep). Rejects only when `signal` (the
|
|
195
|
+
* server closing) aborts it: nothing is decided then. */
|
|
194
196
|
export async function judgeProposal(input) {
|
|
195
197
|
const { runId, agent, main, proposed, env, signal } = input;
|
|
196
198
|
const files = input.files ?? [];
|
|
197
199
|
const cost = { usd: 0, tokens: { ...NO_TOKENS } };
|
|
198
200
|
try {
|
|
199
|
-
const { gradePrompt, parseVerdict } = await import("./learn/index.js");
|
|
201
|
+
const { gradePrompt, parseVerdict, UNREADABLE_REASON } = await import("./learn/index.js");
|
|
200
202
|
const prompt = gradePrompt({ run: runId, instructions: agent.instructions, active: main.active, superseded: main.superseded, proposed, ...(files.length ? { files } : {}), ...(input.asked ? { asked: input.asked } : {}) });
|
|
201
203
|
const grader = await graderModel(env, agent, cost, input.gradeModel);
|
|
202
|
-
const
|
|
204
|
+
const ask = () => bounded(input.gradeTimeoutMs ?? GRADE_TIMEOUT_MS, signal, cost, (grade) => grader({ prompt, maxTokens: GRADE_MAX_TOKENS }, grade));
|
|
203
205
|
// The items with their texts: a note the run marked risky waits whatever the grader says (parseVerdict).
|
|
204
|
-
|
|
206
|
+
const items = gradedItems(proposed, files);
|
|
207
|
+
const first = parseVerdict((await ask()).text, items);
|
|
208
|
+
if (first.reason !== UNREADABLE_REASON || first.items.length)
|
|
209
|
+
return { verdict: first, cost };
|
|
210
|
+
const again = (await ask()).text;
|
|
211
|
+
const verdict = parseVerdict(again, items);
|
|
212
|
+
return verdict.reason === UNREADABLE_REASON && !verdict.items.length ? { verdict, unread: typeof again === "string" ? again : "", cost } : { verdict, cost };
|
|
205
213
|
}
|
|
206
214
|
catch (error) {
|
|
207
215
|
signal.throwIfAborted();
|
package/dist/harness-app.js
CHANGED
|
@@ -661,7 +661,16 @@ export function adapterRun(make, harness, spec, context, budgetUsd, tools = [],
|
|
|
661
661
|
// The park every gated call of the run's takes, built once: the host tools' here, and the MCP gateway's, which takes
|
|
662
662
|
// the same object beside them (`{ gate, park }`). A call parked by its id or by its tool and arguments ends its turn.
|
|
663
663
|
const park = { commit: (change) => commit(change), parked: (callId) => void (parked = { callId }), parkedBy: (match) => void (parked = match), turn: () => taking };
|
|
664
|
-
|
|
664
|
+
// An MCP call from the harness's own client takes the same park, and its result is kept by its call id too, for the
|
|
665
|
+
// root's record of it, as a host tool's is.
|
|
666
|
+
const gateway = spec.mcp;
|
|
667
|
+
const mcp = gateway && { ...gateway, call: async (...[server, tool, args, call]) => {
|
|
668
|
+
const result = await gateway.call(server, tool, args, { ...call, ...(gate ? { park } : {}) });
|
|
669
|
+
if (call.callId)
|
|
670
|
+
results.set(call.callId, { text: result.content.map((block) => block.text).join("\n\n"), isError: result.isError === true });
|
|
671
|
+
return result;
|
|
672
|
+
} };
|
|
673
|
+
session = await adapter.open({ ...spec, ...(mcp ? { mcp } : {}), tools: hostTools(durable, tools, context, results, coding, gate ? { gate, park } : undefined, extra) }, { writer, models: booking.models, signal: stop.signal, onEvent, ...(dir ? { dir } : {}), ...(cwd ? { cwd } : {}) });
|
|
665
674
|
// A turn the person stopped is still open in the session (an interrupt writes no end there), and it is not resumed.
|
|
666
675
|
// The run's stop record names the person's newest message when they stopped: with no message on the root newer than
|
|
667
676
|
// it, the open turn is the stopped one. The session settles it, ended interrupted, and the next message is a turn of
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
|
|
2
|
+
* header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
|
|
3
|
+
export declare function hostName(header: string | undefined): string | undefined;
|
|
4
|
+
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
5
|
+
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
6
|
+
* front of it sends. */
|
|
7
|
+
export declare function loopbackNames(host: string, allowHosts?: readonly string[], publicUrl?: string): Set<string>;
|
|
8
|
+
/** What a refused request is told: the names that work and how to add one. It never repeats the Host it was sent. */
|
|
9
|
+
export declare const HOST_FIX = "this server answers at localhost or 127.0.0.1, on any port (a tunnel such as ssh -L 7340:localhost:7340 works); to serve it at a name of its own, start it with AGENTRUN_PUBLIC_URL=https://<name> or --allow-host <name>";
|
|
10
|
+
/** The page a browser gets for a refused Host: fixed text, under the console's CSP (page.ts). Its addresses carry no
|
|
11
|
+
* scheme: a published package names no loopback URL (scripts/verify-packages.mjs). */
|
|
12
|
+
export declare const HOST_REFUSED_PAGE = "<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\"><title>AgentRun: open it at localhost</title></head>\n<body>\n<h1>Open AgentRun at localhost</h1>\n<p>This AgentRun server answers only at a name on its own machine, so it refused the address this page was opened at.</p>\n<p>Open it at <code>localhost:<port></code> or <code>127.0.0.1:<port></code>, with the port you reached it on. From another computer, a tunnel works at any local port: <code>ssh -L 7340:localhost:7340 <server></code>, then open <code>localhost:7340</code> in the browser.</p>\n<p>To serve it at a name of its own (behind HTTPS, for example), start it with <code>AGENTRUN_PUBLIC_URL=https://<name></code>, or add the name with <code>--allow-host <name></code>.</p>\n</body></html>\n";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The Host check of a server on loopback (server.ts), the guard against DNS rebinding: a page on a name of its own, its
|
|
2
|
+
// address rebound to 127.0.0.1, calling this server from the person's browser. The name is what tells that page apart, so
|
|
3
|
+
// the check is on the name alone. The port is not part of it: through a tunnel (`ssh -L 8080:localhost:7340`), a proxy in
|
|
4
|
+
// front, or a server that took the next free port, a browser sends the port it opened, which is not the server's, and a
|
|
5
|
+
// page that rebound its name gains nothing from any port.
|
|
6
|
+
/** The name a Host header gives, lowercased and without its port (an IPv6 address keeps its brackets). Undefined for a
|
|
7
|
+
* header that is not `name` or `name:port`: no user part, no path, no empty or non-numeric port. */
|
|
8
|
+
export function hostName(header) {
|
|
9
|
+
const match = /^(\[[0-9a-f:.]+\]|[a-z0-9._-]+)(?::(\d{1,5}))?$/.exec(String(header ?? "").trim().toLowerCase());
|
|
10
|
+
return match && (match[2] === undefined || Number(match[2]) <= 65535) ? match[1] : undefined;
|
|
11
|
+
}
|
|
12
|
+
/** The names a server listening on loopback `host` answers to: this machine's (localhost, 127.0.0.1, [::1], and `host`
|
|
13
|
+
* itself), each --allow-host name, and the name of the address people open (AGENTRUN_PUBLIC_URL), which a proxy in
|
|
14
|
+
* front of it sends. */
|
|
15
|
+
export function loopbackNames(host, allowHosts = [], publicUrl) {
|
|
16
|
+
const own = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
17
|
+
const names = ["localhost", "127.0.0.1", "[::1]", own, ...allowHosts];
|
|
18
|
+
if (publicUrl !== undefined && URL.canParse(publicUrl))
|
|
19
|
+
names.push(new URL(publicUrl).hostname);
|
|
20
|
+
return new Set(names.map(hostName).filter((name) => name !== undefined));
|
|
21
|
+
}
|
|
22
|
+
/** What a refused request is told: the names that work and how to add one. It never repeats the Host it was sent. */
|
|
23
|
+
export const HOST_FIX = "this server answers at localhost or 127.0.0.1, on any port (a tunnel such as ssh -L 7340:localhost:7340 works); to serve it at a name of its own, start it with AGENTRUN_PUBLIC_URL=https://<name> or --allow-host <name>";
|
|
24
|
+
/** The page a browser gets for a refused Host: fixed text, under the console's CSP (page.ts). Its addresses carry no
|
|
25
|
+
* scheme: a published package names no loopback URL (scripts/verify-packages.mjs). */
|
|
26
|
+
export const HOST_REFUSED_PAGE = `<!doctype html>
|
|
27
|
+
<html lang="en"><head><meta charset="utf-8"><title>AgentRun: open it at localhost</title></head>
|
|
28
|
+
<body>
|
|
29
|
+
<h1>Open AgentRun at localhost</h1>
|
|
30
|
+
<p>This AgentRun server answers only at a name on its own machine, so it refused the address this page was opened at.</p>
|
|
31
|
+
<p>Open it at <code>localhost:<port></code> or <code>127.0.0.1:<port></code>, with the port you reached it on. From another computer, a tunnel works at any local port: <code>ssh -L 7340:localhost:7340 <server></code>, then open <code>localhost:7340</code> in the browser.</p>
|
|
32
|
+
<p>To serve it at a name of its own (behind HTTPS, for example), start it with <code>AGENTRUN_PUBLIC_URL=https://<name></code>, or add the name with <code>--allow-host <name></code>.</p>
|
|
33
|
+
</body></html>
|
|
34
|
+
`;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Each tool key a person may save, fixed here: its fields (BROWSERBASE_PROJECT_ID is no secret, and is kept the same
|
|
2
|
+
* way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision provider. */
|
|
3
|
+
export declare const TOOL_KEY_ROWS: readonly [{
|
|
4
|
+
readonly id: "parallel";
|
|
5
|
+
readonly kind: "tool";
|
|
6
|
+
readonly label: "Parallel";
|
|
7
|
+
readonly fields: readonly ["PARALLEL_API_KEY"];
|
|
8
|
+
readonly unlocks: readonly ["web_fetch", "web_search", "decisions.parallel"];
|
|
9
|
+
}, {
|
|
10
|
+
readonly id: "monid";
|
|
11
|
+
readonly kind: "tool";
|
|
12
|
+
readonly label: "Monid";
|
|
13
|
+
readonly fields: readonly ["MONID_API_KEY"];
|
|
14
|
+
readonly unlocks: readonly ["monid.discover", "monid.inspect", "monid.run"];
|
|
15
|
+
}, {
|
|
16
|
+
readonly id: "browserbase";
|
|
17
|
+
readonly kind: "tool";
|
|
18
|
+
readonly label: "Browserbase";
|
|
19
|
+
readonly fields: readonly ["BROWSERBASE_API_KEY", "BROWSERBASE_PROJECT_ID"];
|
|
20
|
+
readonly unlocks: readonly ["browser"];
|
|
21
|
+
}, {
|
|
22
|
+
readonly id: "kernel";
|
|
23
|
+
readonly kind: "tool";
|
|
24
|
+
readonly label: "Kernel";
|
|
25
|
+
readonly fields: readonly ["KERNEL_API_KEY"];
|
|
26
|
+
readonly unlocks: readonly ["browser"];
|
|
27
|
+
}, {
|
|
28
|
+
readonly id: "typesafe";
|
|
29
|
+
readonly kind: "tool";
|
|
30
|
+
readonly label: "TypeSafe (Jev)";
|
|
31
|
+
readonly fields: readonly ["TYPESAFE_API_KEY"];
|
|
32
|
+
readonly unlocks: readonly ["decisions.jev"];
|
|
33
|
+
}];
|
|
34
|
+
/** What `vars` (the variables a tool needs that this server does not hold) are, as a person fixes them: each savable
|
|
35
|
+
* key's "a <Label> key: save one in Settings → Tool keys (or set <VARS> where the server starts)", then any variable no
|
|
36
|
+
* key saves, to set where the server starts. */
|
|
37
|
+
export declare function keyNeeded(vars: readonly string[]): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The keys a person may save on Settings → Tool keys (tool-keys.ts' TOOL_KEYS reads the tool rows from here), and the
|
|
2
|
+
// words for one a tool needs that this server does not hold: where the person saves it is named first, then the
|
|
3
|
+
// variable to set where the server starts, since a key saved and then removed in Settings was never in the environment.
|
|
4
|
+
import { MODEL_KEYS } from "./model.js";
|
|
5
|
+
/** Each tool key a person may save, fixed here: its fields (BROWSERBASE_PROJECT_ID is no secret, and is kept the same
|
|
6
|
+
* way), and what it may unlock: tools by name, and `decisions.<id>`, a workflow's decision provider. */
|
|
7
|
+
export const TOOL_KEY_ROWS = [
|
|
8
|
+
{ id: "parallel", kind: "tool", label: "Parallel", fields: ["PARALLEL_API_KEY"], unlocks: ["web_fetch", "web_search", "decisions.parallel"] },
|
|
9
|
+
{ id: "monid", kind: "tool", label: "Monid", fields: ["MONID_API_KEY"], unlocks: ["monid.discover", "monid.inspect", "monid.run"] },
|
|
10
|
+
{ id: "browserbase", kind: "tool", label: "Browserbase", fields: ["BROWSERBASE_API_KEY", "BROWSERBASE_PROJECT_ID"], unlocks: ["browser"] },
|
|
11
|
+
// The browser's other vendor (tool-plane.ts BROWSER_KEYS): a run's browser is the one its plane picks.
|
|
12
|
+
{ id: "kernel", kind: "tool", label: "Kernel", fields: ["KERNEL_API_KEY"], unlocks: ["browser"] },
|
|
13
|
+
// Jev's decision provider (decisions.ts' `jev`), on TypeSafe's key: a workflow's judges, as Parallel's key unlocks its.
|
|
14
|
+
{ id: "typesafe", kind: "tool", label: "TypeSafe (Jev)", fields: ["TYPESAFE_API_KEY"], unlocks: ["decisions.jev"] },
|
|
15
|
+
];
|
|
16
|
+
/** Every key Settings → Tool keys saves, tool keys and model keys alike (a saved model key reaches every run): its label
|
|
17
|
+
* and fields. */
|
|
18
|
+
const SAVABLE = [
|
|
19
|
+
...TOOL_KEY_ROWS.map((row) => ({ label: row.label, fields: row.fields })),
|
|
20
|
+
...MODEL_KEYS.map((row) => ({ label: row.label, fields: [row.field] })),
|
|
21
|
+
];
|
|
22
|
+
const article = (label) => (/^[AEIOU]/i.test(label) ? "an" : "a");
|
|
23
|
+
/** What `vars` (the variables a tool needs that this server does not hold) are, as a person fixes them: each savable
|
|
24
|
+
* key's "a <Label> key: save one in Settings → Tool keys (or set <VARS> where the server starts)", then any variable no
|
|
25
|
+
* key saves, to set where the server starts. */
|
|
26
|
+
export function keyNeeded(vars) {
|
|
27
|
+
const left = [...vars];
|
|
28
|
+
const parts = [];
|
|
29
|
+
for (const row of SAVABLE) {
|
|
30
|
+
const hit = row.fields.filter((field) => left.includes(field));
|
|
31
|
+
if (!hit.length)
|
|
32
|
+
continue;
|
|
33
|
+
for (const field of hit)
|
|
34
|
+
left.splice(left.indexOf(field), 1);
|
|
35
|
+
parts.push(`${article(row.label)} ${row.label} key: save one in Settings → Tool keys (or set ${hit.join(" and ")} where the server starts)`);
|
|
36
|
+
}
|
|
37
|
+
for (const name of left)
|
|
38
|
+
parts.push(`${name}, set where the server starts`);
|
|
39
|
+
return parts.join("; and ");
|
|
40
|
+
}
|
package/dist/learn/grade.d.ts
CHANGED
|
@@ -60,6 +60,9 @@ export type Verdict = {
|
|
|
60
60
|
readonly reason: string;
|
|
61
61
|
readonly items: readonly VerdictItem[];
|
|
62
62
|
};
|
|
63
|
+
/** The verdict when the grader's answer cannot be read: never a merge. */
|
|
64
|
+
/** Why a verdict is no merge when the grader's answer could not be read at all: the host asks once more on it. */
|
|
65
|
+
export declare const UNREADABLE_REASON = "the grader's verdict could not be read";
|
|
63
66
|
/** The files the grader gives one item for, in order: the new notes', then each skill and draft's (gradedFiles). */
|
|
64
67
|
export declare const gradedFiles: (proposed: readonly NoteText[], files?: readonly NoteText[]) => string[];
|
|
65
68
|
/** The items the grader judges, with their texts, in gradedFiles' order: what parseVerdict reads, a note's text for the
|
package/dist/learn/grade.js
CHANGED
|
@@ -51,7 +51,9 @@ export const GRADE_RUBRIC = [
|
|
|
51
51
|
* new notes of at most CAPS.note bytes each, fenced, come to less. */
|
|
52
52
|
export const GRADE_CAPS = Object.freeze({ prompt: 200_000, instructions: 16_000, indexLine: 300, asked: 4, askedMessage: 1_000 });
|
|
53
53
|
/** The verdict when the grader's answer cannot be read: never a merge. */
|
|
54
|
-
|
|
54
|
+
/** Why a verdict is no merge when the grader's answer could not be read at all: the host asks once more on it. */
|
|
55
|
+
export const UNREADABLE_REASON = "the grader's verdict could not be read";
|
|
56
|
+
const UNREADABLE = Object.freeze({ merge: false, reason: UNREADABLE_REASON, items: Object.freeze([]) });
|
|
55
57
|
/** The longest reason, and the longest `why` or `question`, a verdict carries, in UTF-16 units. */
|
|
56
58
|
const REASON_MAX = 500;
|
|
57
59
|
/** A run id: 1 to 128 letters, digits, dots, dashes or underscores, starting with a letter or digit. */
|
package/dist/learn/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { CAPS, checkNote, checkProposal, mergeProblems, printable, supersededBy, unstorable, type Base, type Change, type CheckInput, type Problem, type ProposalCheck, type ProposedNote, type Rule } from "./check.js";
|
|
2
|
-
export { GRADE_CAPS, GRADE_RUBRIC, gradedFiles, gradedItems, gradePrompt, parseVerdict, type GradeInput, type IndexEntry, type NoteText, type Verdict, type VerdictItem } from "./grade.js";
|
|
2
|
+
export { GRADE_CAPS, GRADE_RUBRIC, gradedFiles, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON, type GradeInput, type IndexEntry, type NoteText, type Verdict, type VerdictItem } from "./grade.js";
|
|
3
3
|
export { hiddenCharacter } from "./invisible.js";
|
|
4
4
|
export { ANSWER_MAX, NOTE_BLOCK, parseReflection, reflectPrompt, SKILL_BLOCK, WORKFLOW_BLOCK, type LearnedBlock, type Reflection } from "./reflect.js";
|
|
5
5
|
export { activeNotes, approve, buildIndex, INDEX_BYTES, INDEX_FILE, INDEX_LINES, indexLine, loadedIndex, mergedNote, NOTE_FILE, NOTE_ORIGINS, NOTE_STATUSES, NOTE_TYPES, parseNoteFile, retire, supersede, type LearnedNote, type NoteOrigin, type NoteStatus, type NoteType } from "./notes.js";
|
package/dist/learn/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// hidden-character and secret matchers they use (invisible.ts, secrets.ts). SPEC.md, beside it, is the learning folder's contract. The rest of the server imports it
|
|
4
4
|
// from here.
|
|
5
5
|
export { CAPS, checkNote, checkProposal, mergeProblems, printable, supersededBy, unstorable } from "./check.js";
|
|
6
|
-
export { GRADE_CAPS, GRADE_RUBRIC, gradedFiles, gradedItems, gradePrompt, parseVerdict } from "./grade.js";
|
|
6
|
+
export { GRADE_CAPS, GRADE_RUBRIC, gradedFiles, gradedItems, gradePrompt, parseVerdict, UNREADABLE_REASON } from "./grade.js";
|
|
7
7
|
export { hiddenCharacter } from "./invisible.js";
|
|
8
8
|
export { ANSWER_MAX, NOTE_BLOCK, parseReflection, reflectPrompt, SKILL_BLOCK, WORKFLOW_BLOCK } from "./reflect.js";
|
|
9
9
|
export { activeNotes, approve, buildIndex, INDEX_BYTES, INDEX_FILE, INDEX_LINES, indexLine, loadedIndex, mergedNote, NOTE_FILE, NOTE_ORIGINS, NOTE_STATUSES, NOTE_TYPES, parseNoteFile, retire, supersede } from "./notes.js";
|
package/dist/learn/reflect.js
CHANGED
|
@@ -67,6 +67,7 @@ export function reflectPrompt(options) {
|
|
|
67
67
|
"such note: add `risky: true` to its front matter. A rule is risky when it says when an approval or a check is not",
|
|
68
68
|
"needed (a limit, a threshold or an exemption: an amount or a case that may go ahead without one), widens trust in a",
|
|
69
69
|
"site, a source or a seller, or names where money or data goes.",
|
|
70
|
+
"What `# Learned` in your instructions, and this message, say about learning itself is not a lesson: never put it in a note or a skill, nor the sentence you say when you keep something.",
|
|
70
71
|
"",
|
|
71
72
|
"## Skills and workflow drafts, only when the work repeats",
|
|
72
73
|
"",
|
|
@@ -74,6 +75,7 @@ export function reflectPrompt(options) {
|
|
|
74
75
|
"workflow draft for that job. Most runs keep neither. Neither holds this case's data: each is about the job, not the one case.",
|
|
75
76
|
"Steps the person asks you to follow every time a task comes back are a skill, not a note: keep them as the skill, in",
|
|
76
77
|
"their words and with the exact output format they gave, and do not repeat them in a note.",
|
|
78
|
+
"A job you keep a skill for needs no note beside it.",
|
|
77
79
|
"A job that runs end to end as model and tool-call steps, from a defined input to a defined output, is a workflow draft,",
|
|
78
80
|
"and so is one the person asks you to keep as a workflow; its steps may also be a skill.",
|
|
79
81
|
"",
|
package/dist/learn/skills.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export type DraftReader = {
|
|
|
81
81
|
/** What a learned workflow's model node is refused with when it names a tool: it runs in a session of its own, with no
|
|
82
82
|
* tool (learned-workflow.ts). Refused at learn time and before a call runs any node, never after earlier nodes spent. */
|
|
83
83
|
export declare const MODEL_NODE_TOOLS = "a learned workflow's model node runs without tools";
|
|
84
|
+
/** What a learned draft whose output names no path is refused with. */
|
|
85
|
+
export declare const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
|
|
84
86
|
/** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
|
|
85
87
|
* runNode and runEffect alone): a judge, pick or sift node, a route by question, a verify or an ask needs a decision
|
|
86
88
|
* provider (runJudge) a run is not given. Refused at learn time and before a call runs any node, never after. */
|
package/dist/learn/skills.js
CHANGED
|
@@ -185,6 +185,8 @@ const toolingNodes = (dsl, doc) => dsl.inspectWorkflow(doc).nodes.flatMap((node)
|
|
|
185
185
|
const tools = at(doc, node.path)?.tools;
|
|
186
186
|
return Array.isArray(tools) && tools.length ? [{ rule: "workflow", detail: `the model node at ${node.path} names a tool (${tools.map(String).join(", ").slice(0, 200)}): ${MODEL_NODE_TOOLS}` }] : [];
|
|
187
187
|
});
|
|
188
|
+
/** What a learned draft whose output names no path is refused with. */
|
|
189
|
+
export const LEARNED_OUTPUT_PATH = "its output names no path: a learned workflow's output is the value at output.path";
|
|
188
190
|
/** What a learned workflow is refused with when a node needs more than its runner gives the DSL (learned-workflow.ts:
|
|
189
191
|
* runNode and runEffect alone): a judge, pick or sift node, a route by question, a verify or an ask needs a decision
|
|
190
192
|
* provider (runJudge) a run is not given. Refused at learn time and before a call runs any node, never after. */
|
|
@@ -260,6 +262,20 @@ export function draftProblems(dsl, text, tools, gated = {}) {
|
|
|
260
262
|
let out;
|
|
261
263
|
try {
|
|
262
264
|
out = [...toolingNodes(dsl, doc), ...executableNodes(dsl, doc), ...unrunnableNodes(dsl, doc), ...longNodes(dsl, doc), ...gatedNodes(dsl, doc, gated)];
|
|
265
|
+
// A learned workflow answers the value at its output's path: one that names none would answer its whole state, which
|
|
266
|
+
// fails its output schema when the call ends, after every node spent.
|
|
267
|
+
const path = doc?.output?.path;
|
|
268
|
+
if (typeof path !== "string" || !path)
|
|
269
|
+
out.push({ rule: "workflow", detail: LEARNED_OUTPUT_PATH });
|
|
270
|
+
// A composed workflow node's child too: its output is the value at its own output.path, or it fails the same way.
|
|
271
|
+
for (const node of dsl.inspectWorkflow(doc).nodes) {
|
|
272
|
+
if (node.kind !== "workflow")
|
|
273
|
+
continue;
|
|
274
|
+
const child = at(doc, node.path)?.workflow;
|
|
275
|
+
const childPath = child?.output?.path;
|
|
276
|
+
if (typeof childPath !== "string" || !childPath)
|
|
277
|
+
out.push({ rule: "workflow", detail: `the workflow node at ${node.path}: ${LEARNED_OUTPUT_PATH}` });
|
|
278
|
+
}
|
|
263
279
|
}
|
|
264
280
|
catch (error) {
|
|
265
281
|
// The inspection reads the whole document, as validation need not: what it cannot read is refused, never passed.
|
|
@@ -18,6 +18,20 @@ type NoteView = {
|
|
|
18
18
|
superseded_by: string | null;
|
|
19
19
|
text: string;
|
|
20
20
|
etag: string;
|
|
21
|
+
retired?: Retired;
|
|
22
|
+
last_change?: LastChange;
|
|
23
|
+
};
|
|
24
|
+
/** When a retired note, skill or draft was retired, and by whom: a person (its retire's commit), else a run. */
|
|
25
|
+
type Retired = {
|
|
26
|
+
at: string;
|
|
27
|
+
by: "person" | "run";
|
|
28
|
+
};
|
|
29
|
+
/** The newest change to a note, skill or draft (its file: the note, a SKILL.md, a draft's README.md): what it was, by
|
|
30
|
+
* whom and when. A person's is named by its commit (`learning: <kind> by a person: <file>`); a run's merge is `learned`. */
|
|
31
|
+
type LastChange = {
|
|
32
|
+
kind: "approved" | "edited" | "created" | "retired" | "restored" | "learned";
|
|
33
|
+
by: "person" | "run";
|
|
34
|
+
at: string;
|
|
21
35
|
};
|
|
22
36
|
type Change = {
|
|
23
37
|
by: {
|
|
@@ -51,7 +65,18 @@ type LearnedView = {
|
|
|
51
65
|
run: string | null;
|
|
52
66
|
bytes: number;
|
|
53
67
|
etag: string;
|
|
68
|
+
retired?: Retired;
|
|
69
|
+
last_change?: LastChange;
|
|
70
|
+
};
|
|
71
|
+
/** For tests: how many times a pending count was read from a folder (once per commit of its main). */
|
|
72
|
+
export declare const pendingTestHooks: {
|
|
73
|
+
reads: number;
|
|
54
74
|
};
|
|
75
|
+
/** How many of agent `agentId`'s learned items wait for its owner's OK on its folder's main: notes, skills and workflow
|
|
76
|
+
* drafts held with `status: pending`, as the learning view reads them (notesAt, learnedAt). Read once per commit of
|
|
77
|
+
* main (a list of agents asks for every agent): the commit is resolved each time, the folder only when it moved. A
|
|
78
|
+
* folder never made has none waiting; one that cannot be read is undefined (the caller shows no count). */
|
|
79
|
+
export declare function pendingCount(data: string, agentId: string): Promise<number | undefined>;
|
|
55
80
|
/** GET /agents/{id}/learning: main, its index, the first page of its notes and of its log, and how the agent's runs
|
|
56
81
|
* fared and what learning changed for them (`counts`, `impact`: learning-run.ts, from the runs' rows and the learning
|
|
57
82
|
* ledger); an agent with no folder (its learning never on) has an empty one. */
|
|
@@ -69,7 +94,10 @@ export declare function agentLearning(data: string, agentId: string, shown: Show
|
|
|
69
94
|
agent: string;
|
|
70
95
|
main: string;
|
|
71
96
|
index: string;
|
|
72
|
-
notes: Page<NoteView
|
|
97
|
+
notes: Page<NoteView & {
|
|
98
|
+
last_change?: LastChange;
|
|
99
|
+
retired?: Retired;
|
|
100
|
+
}>;
|
|
73
101
|
skills: LearnedView[];
|
|
74
102
|
workflows: LearnedView[];
|
|
75
103
|
log: Page<Change>;
|
|
@@ -114,6 +142,7 @@ export declare function writeNote(data: string, agentId: string, raw: string, in
|
|
|
114
142
|
body?: Buffer;
|
|
115
143
|
refuse: readonly string[];
|
|
116
144
|
approve?: boolean;
|
|
145
|
+
restore?: boolean;
|
|
117
146
|
}): Promise<{
|
|
118
147
|
status: 200 | 201;
|
|
119
148
|
file: string;
|