@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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 +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
// (RFC 1918, 100.64.0.0/10, fc00::/7), still only over https; loopback, link-local (cloud metadata among it, and the
|
|
7
7
|
// metadata services inside those ranges), unspecified, multicast, broadcast, reserved and this machine's own addresses
|
|
8
8
|
// stay refused whatever the list says.
|
|
9
|
+
//
|
|
10
|
+
// Above the owner, the operator (AGENTRUN_PRIVATE_HOSTS, read from each process's own environment at each use, so a
|
|
11
|
+
// server and each of its runners hold to their own): unset, the owner's list holds as above (a machine one owner uses);
|
|
12
|
+
// `none`, no owner's list is read and none can be saved, so nothing of an MCP server or a calendar reaches a private
|
|
13
|
+
// network (a runner many customers share, whose private network is the platform's own); or a comma list of ranges
|
|
14
|
+
// (`10.20.0.0/16,fd12:3456::/32`) a listed host's every address must also fall in. A value that is neither is read as
|
|
15
|
+
// `none` (fail closed), and the capabilities' switches show it.
|
|
9
16
|
import net from "node:net";
|
|
10
17
|
import os from "node:os";
|
|
11
18
|
import { invalid } from "./errors.js";
|
|
@@ -26,6 +33,37 @@ for (const [base, bits] of [["10.0.0.0", 8], ["172.16.0.0", 12], ["192.168.0.0",
|
|
|
26
33
|
ALLOWABLE.addSubnet(base, bits, "ipv4");
|
|
27
34
|
ALLOWABLE.addSubnet("fc00::", 7, "ipv6");
|
|
28
35
|
const familyOf = (address) => (net.isIPv6(address) ? "ipv6" : "ipv4");
|
|
36
|
+
/** The operator's bound on the owner's private hosts, read from the environment of the process that dials. */
|
|
37
|
+
export const PRIVATE_HOSTS_ENV = "AGENTRUN_PRIVATE_HOSTS";
|
|
38
|
+
/** The operator's bound as `env` sets it (PRIVATE_HOSTS_ENV). */
|
|
39
|
+
export function privateHostsBound(env = process.env) {
|
|
40
|
+
const raw = env[PRIVATE_HOSTS_ENV]?.trim();
|
|
41
|
+
if (!raw)
|
|
42
|
+
return { mode: "owner" };
|
|
43
|
+
if (raw === "none")
|
|
44
|
+
return { mode: "none" };
|
|
45
|
+
const list = new net.BlockList();
|
|
46
|
+
const ranges = [];
|
|
47
|
+
for (const entry of raw.split(",").map((one) => one.trim()).filter(Boolean)) {
|
|
48
|
+
const match = /^([^/]+)\/(\d{1,3})$/.exec(entry);
|
|
49
|
+
const family = match ? net.isIP(match[1]) : 0;
|
|
50
|
+
const bits = match ? Number(match[2]) : NaN;
|
|
51
|
+
if (!match || family === 0 || bits > (family === 4 ? 32 : 128))
|
|
52
|
+
return { mode: "none", invalid: `${PRIVATE_HOSTS_ENV}: ${entry} is not an address range such as 10.20.0.0/16 (or none); read as none` };
|
|
53
|
+
list.addSubnet(match[1], bits, family === 4 ? "ipv4" : "ipv6");
|
|
54
|
+
ranges.push(entry);
|
|
55
|
+
}
|
|
56
|
+
if (!ranges.length)
|
|
57
|
+
return { mode: "none", invalid: `${PRIVATE_HOSTS_ENV}=${raw} names no range; read as none` };
|
|
58
|
+
return { mode: "ranges", ranges, list };
|
|
59
|
+
}
|
|
60
|
+
/** The bound as the capabilities' switches show it: unset (null), `none`, or the ranges; a value read as none says so. */
|
|
61
|
+
export const privateHostsSwitchValue = (env = process.env) => {
|
|
62
|
+
const bound = privateHostsBound(env);
|
|
63
|
+
return bound.mode === "owner" ? null : bound.mode === "none" ? (bound.invalid ? `none (${bound.invalid})` : "none") : bound.ranges.join(",");
|
|
64
|
+
};
|
|
65
|
+
/** Why an owner's list cannot be saved under the operator's bound, or undefined when it can. */
|
|
66
|
+
export const ownerListRefused = (env = process.env) => privateHostsBound(env).mode === "none" ? `This server's operator allows no private-network host (${PRIVATE_HOSTS_ENV}=none): an MCP server or a calendar is reached on a public address alone.` : undefined;
|
|
29
67
|
/** The cloud metadata services inside ALLOWABLE (AWS's over IPv6 in fc00::/7, Alibaba Cloud's in 100.64/10): never
|
|
30
68
|
* allowable whatever the list says. The rest (169.254.169.254 among them) are link-local, outside it already. The same
|
|
31
69
|
* addresses the computer's egress table refuses (packages/computer/src/docker/egress-table.ts). */
|
|
@@ -41,9 +79,14 @@ export function localAddresses() {
|
|
|
41
79
|
}
|
|
42
80
|
/** Whether a private address `address`, which a listed host resolves to, may be dialled: only in ALLOWABLE, and never one
|
|
43
81
|
* of `own` (this machine's addresses, and this server's own; an IPv4-mapped form is the same address). */
|
|
44
|
-
export function privateAllowed(address, own) {
|
|
82
|
+
export function privateAllowed(address, own, env = process.env) {
|
|
45
83
|
if (!inAllowableRange(address))
|
|
46
84
|
return false;
|
|
85
|
+
const bound = privateHostsBound(env);
|
|
86
|
+
if (bound.mode === "none")
|
|
87
|
+
return false;
|
|
88
|
+
if (bound.mode === "ranges" && !bound.list.check(address, familyOf(address)))
|
|
89
|
+
return false;
|
|
47
90
|
const mine = new net.BlockList();
|
|
48
91
|
for (const one of own)
|
|
49
92
|
if (net.isIP(one))
|
|
@@ -59,7 +102,10 @@ function hostsOf(value) {
|
|
|
59
102
|
/** The private-network hosts the owner allows an authorization server, or an MCP server itself (mcp-oauth.ts
|
|
60
103
|
* mcpServerAt), on: read from the store at each use, so a host removed is refused from the next request on. The one read
|
|
61
104
|
* of the setting, for the server's sign-in, preview, save and refresh and the runner's token refresh and calls alike. */
|
|
62
|
-
export async function privateOAuthHosts(store) {
|
|
105
|
+
export async function privateOAuthHosts(store, env = process.env) {
|
|
106
|
+
// The operator's `none`: the owner's list is not read, so no host of it is allowed anywhere this process dials.
|
|
107
|
+
if (privateHostsBound(env).mode === "none")
|
|
108
|
+
return [];
|
|
63
109
|
return hostsOf(await store.settings.get(MCP_PRIVATE_HOSTS_KEY));
|
|
64
110
|
}
|
|
65
111
|
/** The store.settings key a server keeps its own addresses under at each start (Serve.own: where it listens, and its
|
|
@@ -134,13 +180,17 @@ function entryOf(value, field) {
|
|
|
134
180
|
}
|
|
135
181
|
/** A PUT body `{ hosts }` checked: the list as kept (each entry hostKey'd, the first of any repeat kept), or 422 with
|
|
136
182
|
* every entry that is not a host name or an IP address on a private network, in words. */
|
|
137
|
-
export function checkPrivateHosts(body) {
|
|
183
|
+
export function checkPrivateHosts(body, env = process.env) {
|
|
138
184
|
const issues = unknownFields(body, ["hosts"]);
|
|
139
185
|
const { hosts } = body;
|
|
140
186
|
if (!Array.isArray(hosts)) {
|
|
141
187
|
issues.push({ field: "hosts", reason: hosts === undefined ? "missing" : "wrong_type", message: "hosts is a list of host names or IP addresses (an empty list allows none)." });
|
|
142
188
|
throw invalid(issues);
|
|
143
189
|
}
|
|
190
|
+
// Under the operator's `none` only the empty list is saved: an owner's host would never be allowed.
|
|
191
|
+
const refused = hosts.length ? ownerListRefused(env) : undefined;
|
|
192
|
+
if (refused)
|
|
193
|
+
throw invalid([{ field: "hosts", reason: "not_an_option", message: refused }]);
|
|
144
194
|
if (hosts.length > MAX_PRIVATE_HOSTS)
|
|
145
195
|
issues.push({ field: "hosts", reason: "too_long", message: `hosts holds at most ${MAX_PRIVATE_HOSTS} hosts; it holds ${hosts.length}.` });
|
|
146
196
|
const kept = [];
|
|
@@ -227,6 +227,7 @@ export declare class McpServersOverStore {
|
|
|
227
227
|
reason?: string;
|
|
228
228
|
})[];
|
|
229
229
|
prices: McpPrices;
|
|
230
|
+
toolkit: string | null;
|
|
230
231
|
} | undefined>;
|
|
231
232
|
/** `listing`, and when it is refused as a server that signs in with OAuth (auth_required, `auth: oauth`), whether that
|
|
232
233
|
* sign-in can start with no Client ID entered (`details.oauth.registration`, McpSignIns.registration), so the console
|
|
@@ -218,10 +218,11 @@ export class McpServersOverStore {
|
|
|
218
218
|
const row = await this.store.mcp.server(name);
|
|
219
219
|
if (!row)
|
|
220
220
|
return undefined;
|
|
221
|
+
const { toolkit } = await this.sourceOf(row);
|
|
221
222
|
const url = new URL(row.url);
|
|
222
223
|
const pinned = (tools) => {
|
|
223
224
|
const listed = marked(row.url, { tools });
|
|
224
|
-
return { url: row.url, tools: listed.tools, prices: pricesListed((row.prices ?? undefined), listed.tools) };
|
|
225
|
+
return { url: row.url, tools: listed.tools, prices: pricesListed((row.prices ?? undefined), listed.tools), toolkit };
|
|
225
226
|
};
|
|
226
227
|
const send = await this.reached(row.auth, url, stop);
|
|
227
228
|
try {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// A media file's length in seconds, read from its bytes alone: an ISO file's movie header (mp4, m4a, mov), a WAV's data
|
|
2
|
+
// chunk over its byte rate, an MP3's frame count (Xing, Info or VBRI) or, with none, its frames walked one by one. Pure: no decoder, nothing read past the bytes given. Undefined for anything else, or a file cut short of the
|
|
3
|
+
// header its length is in.
|
|
4
|
+
const tag = (b, at, text) => at >= 0 && b.length >= at + text.length && [...text].every((c, i) => b[at + i] === c.charCodeAt(0));
|
|
5
|
+
const u32 = (b, at) => (b[at] * 0x1000000) + (b[at + 1] << 16) + (b[at + 2] << 8) + b[at + 3];
|
|
6
|
+
const u32le = (b, at) => b[at] + (b[at + 1] << 8) + (b[at + 2] << 16) + b[at + 3] * 0x1000000;
|
|
7
|
+
const length = (seconds) => (Number.isFinite(seconds) && seconds > 0 ? seconds : undefined);
|
|
8
|
+
/** The boxes of an ISO file between `from` and `to`: each one's type and where its body starts and ends. A box that runs
|
|
9
|
+
* past `to`, or is smaller than its own header, ends the walk. */
|
|
10
|
+
function* boxes(b, from, to) {
|
|
11
|
+
for (let at = from; at + 8 <= to;) {
|
|
12
|
+
let size = u32(b, at);
|
|
13
|
+
let head = 8;
|
|
14
|
+
if (size === 1) {
|
|
15
|
+
if (at + 16 > to)
|
|
16
|
+
return;
|
|
17
|
+
size = u32(b, at + 8) * 0x100000000 + u32(b, at + 12);
|
|
18
|
+
head = 16;
|
|
19
|
+
}
|
|
20
|
+
else if (size === 0)
|
|
21
|
+
size = to - at;
|
|
22
|
+
if (size < head || at + size > to)
|
|
23
|
+
return;
|
|
24
|
+
yield { type: String.fromCharCode(b[at + 4], b[at + 5], b[at + 6], b[at + 7]), start: at + head, end: at + size };
|
|
25
|
+
at += size;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** An ISO file's length: its moov's mvhd, duration over timescale (64-bit in version 1). */
|
|
29
|
+
function isoSeconds(b) {
|
|
30
|
+
for (const top of boxes(b, 0, b.length)) {
|
|
31
|
+
if (top.type !== "moov")
|
|
32
|
+
continue;
|
|
33
|
+
for (const { type, start, end } of boxes(b, top.start, top.end)) {
|
|
34
|
+
if (type !== "mvhd")
|
|
35
|
+
continue;
|
|
36
|
+
const wide = b[start] === 1;
|
|
37
|
+
if (end - start < (wide ? 32 : 20))
|
|
38
|
+
return undefined;
|
|
39
|
+
const scale = u32(b, start + (wide ? 20 : 12));
|
|
40
|
+
const ticks = wide ? u32(b, start + 24) * 0x100000000 + u32(b, start + 28) : u32(b, start + 16);
|
|
41
|
+
return scale > 0 ? length(ticks / scale) : undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
/** A WAV's length: its data chunk's bytes (those in the file, when it states more) over its fmt chunk's byte rate. */
|
|
47
|
+
function wavSeconds(b) {
|
|
48
|
+
let rate;
|
|
49
|
+
for (let at = 12; at + 8 <= b.length;) {
|
|
50
|
+
const size = u32le(b, at + 4);
|
|
51
|
+
if (tag(b, at, "fmt ")) {
|
|
52
|
+
if (at + 20 > b.length)
|
|
53
|
+
return undefined;
|
|
54
|
+
rate = u32le(b, at + 16);
|
|
55
|
+
}
|
|
56
|
+
else if (tag(b, at, "data"))
|
|
57
|
+
return rate ? length(Math.min(size, b.length - at - 8) / rate) : undefined;
|
|
58
|
+
at += 8 + size + (size % 2);
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
// MPEG audio, by version bits (3: MPEG-1, 2: MPEG-2, 0: MPEG-2.5) and layer bits (3: I, 2: II, 1: III).
|
|
63
|
+
const RATES = { 3: [44_100, 48_000, 32_000], 2: [22_050, 24_000, 16_000], 0: [11_025, 12_000, 8_000] };
|
|
64
|
+
const KBPS_V1 = {
|
|
65
|
+
3: [0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448],
|
|
66
|
+
2: [0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384],
|
|
67
|
+
1: [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320],
|
|
68
|
+
};
|
|
69
|
+
const KBPS_V2 = {
|
|
70
|
+
3: [0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256],
|
|
71
|
+
2: [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160],
|
|
72
|
+
1: [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160],
|
|
73
|
+
};
|
|
74
|
+
/** The MPEG audio frame header at `at`, or undefined when those four bytes are none. */
|
|
75
|
+
function frameAt(b, at) {
|
|
76
|
+
if (at + 4 > b.length || b[at] !== 0xff || (b[at + 1] & 0xe0) !== 0xe0)
|
|
77
|
+
return undefined;
|
|
78
|
+
const version = (b[at + 1] >> 3) & 3;
|
|
79
|
+
const layer = (b[at + 1] >> 1) & 3;
|
|
80
|
+
const rate = RATES[version]?.[(b[at + 2] >> 2) & 3];
|
|
81
|
+
const kbps = (version === 3 ? KBPS_V1 : KBPS_V2)[layer]?.[b[at + 2] >> 4];
|
|
82
|
+
if (!rate || !kbps)
|
|
83
|
+
return undefined;
|
|
84
|
+
const padding = (b[at + 2] >> 1) & 1;
|
|
85
|
+
const mono = b[at + 3] >> 6 === 3;
|
|
86
|
+
const samples = layer === 3 ? 384 : layer === 2 || version === 3 ? 1152 : 576;
|
|
87
|
+
const bytes = layer === 3 ? (Math.floor((12 * kbps * 1000) / rate) + padding) * 4 : Math.floor(((samples / 8) * kbps * 1000) / rate) + padding;
|
|
88
|
+
return { rate, samples, bytes, side: version === 3 ? (mono ? 17 : 32) : mono ? 9 : 17 };
|
|
89
|
+
}
|
|
90
|
+
/** The furthest past a tag an MP3's first frame is looked for. */
|
|
91
|
+
const SYNC_SCAN = 64 * 1024;
|
|
92
|
+
/** Every frame's samples over its rate, from the frame at `at` to `end`. A last frame cut short ends it; bytes that stop
|
|
93
|
+
* being frames before that give no length, since a bitrate guessed for them could read the file short. */
|
|
94
|
+
function walkedSeconds(b, at, end) {
|
|
95
|
+
let seconds = 0;
|
|
96
|
+
while (at < end) {
|
|
97
|
+
const frame = frameAt(b, at);
|
|
98
|
+
if (!frame)
|
|
99
|
+
return undefined;
|
|
100
|
+
if (at + frame.bytes > end)
|
|
101
|
+
break;
|
|
102
|
+
seconds += frame.samples / frame.rate;
|
|
103
|
+
at += frame.bytes;
|
|
104
|
+
}
|
|
105
|
+
return length(seconds);
|
|
106
|
+
}
|
|
107
|
+
/** An MP3's length: its first frame's Xing, Info or VBRI frame count times a frame's samples over its rate; with none,
|
|
108
|
+
* its frames walked one by one (a variable bitrate needs no header), the first taken only when another follows it. */
|
|
109
|
+
function mp3Seconds(b) {
|
|
110
|
+
let start = 0;
|
|
111
|
+
// An ID3v2 tag: its size is four 7-bit bytes, with a 10-byte footer when flagged.
|
|
112
|
+
if (tag(b, 0, "ID3") && b.length >= 10)
|
|
113
|
+
start = 10 + ((b[6] & 0x7f) << 21) + ((b[7] & 0x7f) << 14) + ((b[8] & 0x7f) << 7) + (b[9] & 0x7f) + (b[5] & 0x10 ? 10 : 0);
|
|
114
|
+
const end = b.length - (tag(b, b.length - 128, "TAG") ? 128 : 0);
|
|
115
|
+
for (let at = start; at < Math.min(end, start + SYNC_SCAN); at++) {
|
|
116
|
+
const frame = frameAt(b, at);
|
|
117
|
+
if (!frame)
|
|
118
|
+
continue;
|
|
119
|
+
const xing = at + 4 + frame.side;
|
|
120
|
+
if ((tag(b, xing, "Xing") || tag(b, xing, "Info")) && xing + 12 <= b.length && b[xing + 7] & 1)
|
|
121
|
+
return length((u32(b, xing + 8) * frame.samples) / frame.rate);
|
|
122
|
+
if (tag(b, at + 36, "VBRI") && at + 54 <= b.length)
|
|
123
|
+
return length((u32(b, at + 50) * frame.samples) / frame.rate);
|
|
124
|
+
if (at + frame.bytes === end || frameAt(b, at + frame.bytes))
|
|
125
|
+
return walkedSeconds(b, at, end);
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
/** The length of the media file `bytes`, in seconds; undefined when it can't be read from them. */
|
|
130
|
+
export function mediaSeconds(bytes) {
|
|
131
|
+
if (tag(bytes, 4, "ftyp") || tag(bytes, 4, "moov") || tag(bytes, 4, "mdat") || tag(bytes, 4, "free") || tag(bytes, 4, "wide"))
|
|
132
|
+
return isoSeconds(bytes);
|
|
133
|
+
if (tag(bytes, 0, "RIFF") && tag(bytes, 8, "WAVE"))
|
|
134
|
+
return wavSeconds(bytes);
|
|
135
|
+
return mp3Seconds(bytes);
|
|
136
|
+
}
|
package/dist/model-gateway.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ export declare const GATEWAY_KEY_ROW = "model_gateway.api_key";
|
|
|
13
13
|
* `bare`, the part after the provider (AGENT_MODEL_GATEWAY_IDS=bare). The tiers' own models go as saved either way. */
|
|
14
14
|
export declare const GATEWAY_IDS: readonly ["as_named", "bare"];
|
|
15
15
|
export type GatewayIds = (typeof GATEWAY_IDS)[number];
|
|
16
|
+
/** Whether a gateway is sent a model id whole or bare: read by the process that sends (a runner, for its runs). */
|
|
17
|
+
export declare const GATEWAY_IDS_ENV = "AGENT_MODEL_GATEWAY_IDS";
|
|
16
18
|
/** How long the test waits for the gateway, and how many ids it lists. */
|
|
17
19
|
export declare const TEST_TIMEOUT_MS = 10000;
|
|
18
20
|
/** The most of the gateway's answer to the test that is read: a list of MAX_LISTED models is far smaller. */
|
package/dist/model-gateway.js
CHANGED
|
@@ -53,7 +53,9 @@ export const GATEWAY_KEY_ROW = "model_gateway.api_key";
|
|
|
53
53
|
export const GATEWAY_IDS = ["as_named", "bare"];
|
|
54
54
|
/** The variable each tier's model fills, as the environment names it (model.ts TIER_ENV). */
|
|
55
55
|
const TIER_VARS = { default: "AGENT_MODEL", fast: "AGENT_MODEL_FAST", strong: "AGENT_MODEL_STRONG" };
|
|
56
|
-
|
|
56
|
+
/** Whether a gateway is sent a model id whole or bare: read by the process that sends (a runner, for its runs). */
|
|
57
|
+
export const GATEWAY_IDS_ENV = "AGENT_MODEL_GATEWAY_IDS";
|
|
58
|
+
const IDS_VAR = GATEWAY_IDS_ENV;
|
|
57
59
|
const BASE_VAR = "AGENT_MODEL_BASE_URL";
|
|
58
60
|
/** The longest key and model id taken: a header value, a name. */
|
|
59
61
|
const MAX_KEY_CHARS = 4096;
|
|
@@ -12,6 +12,7 @@ export declare const NATIVE_RUNTIME_FACTS: Readonly<{
|
|
|
12
12
|
readonly label: "Claude Code CLI";
|
|
13
13
|
readonly minimumVersion: "2.1.322";
|
|
14
14
|
readonly namedSelector: "agent";
|
|
15
|
+
readonly captureRuntime: "claude-code-cli";
|
|
15
16
|
readonly protocol: "claude-json";
|
|
16
17
|
readonly authStatus: readonly string[];
|
|
17
18
|
readonly authStatusJson: true;
|
|
@@ -35,6 +36,7 @@ export declare const NATIVE_RUNTIME_FACTS: Readonly<{
|
|
|
35
36
|
readonly label: "Codex CLI";
|
|
36
37
|
readonly minimumVersion: "0.167.2";
|
|
37
38
|
readonly namedSelector: "profile";
|
|
39
|
+
readonly captureRuntime: "codex-cli";
|
|
38
40
|
readonly protocol: "codex-json";
|
|
39
41
|
readonly authStatus: readonly string[];
|
|
40
42
|
readonly authStatusJson: false;
|
package/dist/native/runtimes.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const NATIVE_RUNTIME_FACTS = Object.freeze({
|
|
2
2
|
"claude-code": Object.freeze({
|
|
3
3
|
binary: "claude", label: "Claude Code CLI", minimumVersion: "2.1.322", namedSelector: "agent",
|
|
4
|
+
captureRuntime: "claude-code-cli",
|
|
4
5
|
protocol: "claude-json", authStatus: Object.freeze(["auth", "status", "--json"]),
|
|
5
6
|
authStatusJson: true, loginCommand: "claude auth login",
|
|
6
7
|
observation: Object.freeze({
|
|
@@ -15,6 +16,7 @@ export const NATIVE_RUNTIME_FACTS = Object.freeze({
|
|
|
15
16
|
}),
|
|
16
17
|
codex: Object.freeze({
|
|
17
18
|
binary: "codex", label: "Codex CLI", minimumVersion: "0.167.2", namedSelector: "profile",
|
|
19
|
+
captureRuntime: "codex-cli",
|
|
18
20
|
protocol: "codex-json", authStatus: Object.freeze(["login", "status"]),
|
|
19
21
|
authStatusJson: false, loginCommand: "codex login",
|
|
20
22
|
observation: Object.freeze({
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CliLearningConnections } from "../cli-learning/connections.js";
|
|
2
|
+
import { type CliLearningObservationScope, type CliLearningReadiness } from "../cli-learning/observation-proof.js";
|
|
3
|
+
import type { Store } from "../store/store.js";
|
|
4
|
+
export type LearningReport = {
|
|
5
|
+
readiness: CliLearningReadiness;
|
|
6
|
+
connection_id?: string;
|
|
7
|
+
native_session_hash?: string;
|
|
8
|
+
proof?: string;
|
|
9
|
+
};
|
|
10
|
+
/** Persist only verified identifiers and the generation that authorized them, never credentials or proofs. */
|
|
11
|
+
export type LearningAssociation = {
|
|
12
|
+
readiness: CliLearningReadiness;
|
|
13
|
+
connection_id?: string;
|
|
14
|
+
native_session_hash?: string;
|
|
15
|
+
generation?: string;
|
|
16
|
+
};
|
|
17
|
+
export type ObservedLearning = {
|
|
18
|
+
state: "on" | "off" | "setup_required" | "unknown" | "unsupported";
|
|
19
|
+
reason: "ready" | "source_setup_required" | "source_unknown" | "delegated_session" | "connection_unavailable" | "server_disabled" | "agent_disabled" | "awaiting_activation";
|
|
20
|
+
agent_id?: string;
|
|
21
|
+
connection_id?: string;
|
|
22
|
+
mode?: "off" | "notes" | "corrections" | "workflows";
|
|
23
|
+
};
|
|
24
|
+
export declare class ObservationLearning {
|
|
25
|
+
private readonly store;
|
|
26
|
+
private readonly connections;
|
|
27
|
+
private readonly enabled;
|
|
28
|
+
constructor(store: Store, connections: CliLearningConnections, enabled?: boolean);
|
|
29
|
+
verify(report: LearningReport, scope: Omit<CliLearningObservationScope, "connection_id" | "readiness" | "native_session_hash">): Promise<LearningAssociation>;
|
|
30
|
+
view(association: LearningAssociation | undefined, runtime: "codex" | "claude-code"): Promise<ObservedLearning>;
|
|
31
|
+
}
|
|
32
|
+
export declare function unboundLearning(readiness?: CliLearningReadiness): ObservedLearning;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { getAgent } from "../agents-store.js";
|
|
3
|
+
import { cliLearningObservationProof } from "../cli-learning/observation-proof.js";
|
|
4
|
+
import { learnsOf } from "../learning-setting.js";
|
|
5
|
+
import { cliLearningOf, learningSettingForBody } from "../store/agent-body.js";
|
|
6
|
+
export class ObservationLearning {
|
|
7
|
+
store;
|
|
8
|
+
connections;
|
|
9
|
+
enabled;
|
|
10
|
+
constructor(store, connections, enabled = true) {
|
|
11
|
+
this.store = store;
|
|
12
|
+
this.connections = connections;
|
|
13
|
+
this.enabled = enabled;
|
|
14
|
+
}
|
|
15
|
+
async verify(report, scope) {
|
|
16
|
+
if (!report.connection_id)
|
|
17
|
+
return { readiness: report.readiness };
|
|
18
|
+
const row = await this.connections.get(report.connection_id).catch(() => undefined);
|
|
19
|
+
if (!row?.active || row.runtime !== scope.runtime || !report.proof || !report.native_session_hash)
|
|
20
|
+
return { readiness: "unknown" };
|
|
21
|
+
const expected = cliLearningObservationProof(this.connections.token(row), { ...scope, connection_id: row.connection_id, readiness: report.readiness, native_session_hash: report.native_session_hash });
|
|
22
|
+
if (!timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(report.proof, "hex")))
|
|
23
|
+
return { readiness: "unknown" };
|
|
24
|
+
return { readiness: report.readiness, connection_id: row.connection_id, generation: row.generation, native_session_hash: report.native_session_hash };
|
|
25
|
+
}
|
|
26
|
+
async view(association, runtime) {
|
|
27
|
+
const readiness = association?.readiness ?? "unknown";
|
|
28
|
+
if (!association?.connection_id)
|
|
29
|
+
return unboundLearning(readiness);
|
|
30
|
+
const row = await this.connections.get(association.connection_id).catch(() => undefined);
|
|
31
|
+
if (!row?.active || row.generation !== association.generation || row.runtime !== runtime)
|
|
32
|
+
return { state: "unknown", reason: "connection_unavailable" };
|
|
33
|
+
const entry = await getAgent(this.store, row.agent_id);
|
|
34
|
+
const binding = cliLearningOf(entry?.revision?.body);
|
|
35
|
+
if (!entry || entry.agent.archivedAt != null || !binding || binding.connection_id !== row.connection_id || binding.runtime !== runtime || binding.project !== row.project)
|
|
36
|
+
return { state: "unknown", reason: "connection_unavailable" };
|
|
37
|
+
// Source hooks deliver owner corrections; they do not expose a workflow execution bridge.
|
|
38
|
+
const mode = learnsOf(learningSettingForBody(entry.revision.body)) ? "corrections" : "off";
|
|
39
|
+
const linked = { agent_id: row.agent_id, connection_id: row.connection_id, mode };
|
|
40
|
+
if (!this.enabled)
|
|
41
|
+
return { state: "off", reason: "server_disabled", ...linked };
|
|
42
|
+
if (mode === "off")
|
|
43
|
+
return { state: "off", reason: "agent_disabled", ...linked };
|
|
44
|
+
if (readiness !== "ready")
|
|
45
|
+
return { ...unboundLearning(readiness), ...linked };
|
|
46
|
+
let activated = Boolean(association.native_session_hash && row.hook_sessions?.[association.native_session_hash]);
|
|
47
|
+
// Older connections already have a last-window receipt. It proves activation only for that exact
|
|
48
|
+
// native session and current credential generation; another session in the project proves nothing.
|
|
49
|
+
if (!activated && row.last_run_id) {
|
|
50
|
+
const launch = await this.store.runs.launch(row.last_run_id).catch(() => undefined);
|
|
51
|
+
const window = launch?.body?.cli_learning;
|
|
52
|
+
activated = Boolean(window && window.connection_id === row.connection_id && window.connection_generation === row.generation
|
|
53
|
+
&& createHash("sha256").update(window.session_id).digest("hex") === association.native_session_hash);
|
|
54
|
+
}
|
|
55
|
+
if (!activated)
|
|
56
|
+
return { state: "unknown", reason: "awaiting_activation", ...linked };
|
|
57
|
+
return { state: "on", reason: "ready", ...linked };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export function unboundLearning(readiness = "unknown") {
|
|
61
|
+
if (readiness === "setup_required")
|
|
62
|
+
return { state: "setup_required", reason: "source_setup_required" };
|
|
63
|
+
if (readiness === "unsupported")
|
|
64
|
+
return { state: "unsupported", reason: "delegated_session" };
|
|
65
|
+
return { state: "unknown", reason: "source_unknown" };
|
|
66
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Store } from "../store/store.js";
|
|
2
2
|
import { type NativeObservationHarness } from "../native/runtimes.js";
|
|
3
|
+
import { ObservationLearning } from "./learning.js";
|
|
3
4
|
export declare const MAX_OTLP_PAYLOAD_BYTES = 1048576;
|
|
4
5
|
type Harness = NativeObservationHarness;
|
|
5
6
|
type Selection = {
|
|
@@ -17,6 +18,10 @@ export declare class ObservationError extends Error {
|
|
|
17
18
|
}
|
|
18
19
|
export declare const observationCapabilities: () => {
|
|
19
20
|
version: number;
|
|
21
|
+
session_labels: boolean;
|
|
22
|
+
cli_learning: {
|
|
23
|
+
session_association: boolean;
|
|
24
|
+
};
|
|
20
25
|
ingestion_modes: string[];
|
|
21
26
|
supported_harnesses: ("codex" | "claude")[];
|
|
22
27
|
logs_formats: string[];
|
|
@@ -25,6 +30,7 @@ export declare const observationCapabilities: () => {
|
|
|
25
30
|
max_log_records: number;
|
|
26
31
|
max_payload_bytes: number;
|
|
27
32
|
token_usage: {
|
|
33
|
+
polling: boolean;
|
|
28
34
|
supported_harnesses: ("codex" | "claude")[];
|
|
29
35
|
model_attribute: string;
|
|
30
36
|
count_attributes: string[];
|
|
@@ -40,7 +46,8 @@ export declare const observationCapabilities: () => {
|
|
|
40
46
|
export declare class Observations {
|
|
41
47
|
readonly store: Store;
|
|
42
48
|
readonly now: () => number;
|
|
43
|
-
|
|
49
|
+
private readonly learning?;
|
|
50
|
+
constructor(store: Store, now?: () => number, learning?: ObservationLearning | undefined);
|
|
44
51
|
private stamp;
|
|
45
52
|
private rows;
|
|
46
53
|
private row;
|