@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57
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 +261 -0
- package/README.md +228 -45
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +18 -5
- package/dist/adapters.js +23 -9
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +36 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +28 -3
- package/dist/chatgpt-plan.js +182 -21
- package/dist/claude-login.d.ts +101 -14
- package/dist/claude-login.js +232 -49
- package/dist/claude-sign-in.d.ts +46 -0
- package/dist/claude-sign-in.js +93 -0
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +26 -5
- package/dist/key-refusal.js +313 -37
- package/dist/learn/secrets.d.ts +31 -11
- package/dist/learn/secrets.js +152 -191
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +2 -2
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +245 -42
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +101 -0
- package/dist/redact/match.js +1152 -0
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +3 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +14 -0
- package/dist/runner/adapter-loop.js +56 -11
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +154 -29
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +11 -6
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +85 -36
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +15 -6
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +5 -0
- package/dist/runner/run-child-host.js +71 -30
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +18 -3
- package/dist/runner/runner.js +162 -36
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +57 -13
- package/dist/server.js +371 -113
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +76 -16
- package/dist/store/store.d.ts +53 -3
- package/dist/store/store.js +27 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +4 -4
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +22 -11
- package/dist/template-eval.js +124 -41
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +17 -7
- package/dist/timeline/timeline.js +28 -14
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +69 -6
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +3 -1
- package/dist/workspace/computer-deps.js +12 -4
- package/dist/workspace/computer-for-claim.d.ts +19 -2
- package/dist/workspace/computer-for-claim.js +101 -13
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +55 -4
- package/dist/workspace/computer-kept.js +129 -8
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +65 -0
- package/dist/wrapped.js +77 -0
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +38 -15
- package/dist/console/assets/index-DUYLaqiR.js +0 -746
- package/dist/console/assets/index-DYhU4adm.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
package/dist/run-model-key.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApiError, type InputIssue } from "./errors.js";
|
|
2
|
+
import type { RunLaunch } from "./run-launch.js";
|
|
2
3
|
/** The longest model key a run takes: a header value, never a document. */
|
|
3
4
|
export declare const MAX_MODEL_KEY_CHARS = 4096;
|
|
4
5
|
/** The origin of the model gateway a run's model key goes to (AGENT_MODEL_BASE_URL's, by the one base rule), or undefined
|
|
@@ -22,6 +23,13 @@ export type ModelKeyTarget = {
|
|
|
22
23
|
} | undefined;
|
|
23
24
|
readonly native?: boolean;
|
|
24
25
|
};
|
|
26
|
+
/** A created run's ModelKeyTarget: its revision's kind and its launch's pinned model. A held run its model kept from
|
|
27
|
+
* running (run-launch.ts hold.refused) pins none, so it is keyed by its revision's model as named (heldKeyModel): a
|
|
28
|
+
* gateway server with no key refuses it at its create as it refuses any run there. */
|
|
29
|
+
export declare function keyTargetOf(env: NodeJS.ProcessEnv, launch: Pick<RunLaunch, "model" | "native" | "hold" | "harness">, revision: {
|
|
30
|
+
readonly kind: string;
|
|
31
|
+
readonly body: unknown;
|
|
32
|
+
}): ModelKeyTarget;
|
|
25
33
|
/** The variables a run's model route reads its key from when that route goes to the model gateway (a workflow's model
|
|
26
34
|
* nodes, pi's and codex's models, a CLI harness on Anthropic's wire where ANTHROPIC_BASE_URL is the gateway's origin);
|
|
27
35
|
* undefined for a route that goes elsewhere (a provider's own, the ChatGPT plan, the faux model) or a native run. */
|
package/dist/run-model-key.js
CHANGED
|
@@ -16,8 +16,12 @@
|
|
|
16
16
|
// erased with that end, and revoked by its caller) or tied to no run, with no key to spend, is skipped or refused in words.
|
|
17
17
|
import { ApiError } from "./errors.js";
|
|
18
18
|
import { handedSecretOf } from "./handed-secret.js";
|
|
19
|
-
import {
|
|
19
|
+
import { PLAN_PROVIDER } from "./chatgpt-plan.js";
|
|
20
|
+
import { DEFAULT_HARNESS } from "./harness.js";
|
|
21
|
+
import { harnessOf } from "./harness-table.js";
|
|
22
|
+
import { FAUX_ENV, GATEWAY_KEY_ENV, hostModel, MODEL_PROVIDER, PROVIDER_KEYS } from "./model.js";
|
|
20
23
|
import { gatewayBase } from "./provider.js";
|
|
24
|
+
import { modelWire, WIRES } from "./wires.js";
|
|
21
25
|
/** The longest model key a run takes: a header value, never a document. */
|
|
22
26
|
export const MAX_MODEL_KEY_CHARS = 4096;
|
|
23
27
|
/** The origin of the model gateway a run's model key goes to (AGENT_MODEL_BASE_URL's, by the one base rule), or undefined
|
|
@@ -62,6 +66,32 @@ export function modelKeyOf(value, issues) {
|
|
|
62
66
|
/** 422 model_key_required: a run start, or a message that would start a turn, with no model key to spend: none handed,
|
|
63
67
|
* none the run holds, and none the server holds for its route. */
|
|
64
68
|
export const modelKeyRequired = (message) => new ApiError("model_key_required", `This server holds no model key for this run's model (AGENT_MODEL_API_KEY is not set and none is saved in Settings → Model keys), so each run's caller brings its own: send model_key with ${message ? "a message that starts a turn" : "the run"}, a key for the model gateway at AGENT_MODEL_BASE_URL (such as a LiteLLM virtual key) minted for ${message ? "that turn" : "this run"}.`, { fields: [{ field: "model_key", reason: "missing", message: "model_key is required here: the server holds no model key for this run's model." }] });
|
|
69
|
+
/** A created run's ModelKeyTarget: its revision's kind and its launch's pinned model. A held run its model kept from
|
|
70
|
+
* running (run-launch.ts hold.refused) pins none, so it is keyed by its revision's model as named (heldKeyModel): a
|
|
71
|
+
* gateway server with no key refuses it at its create as it refuses any run there. */
|
|
72
|
+
export function keyTargetOf(env, launch, revision) {
|
|
73
|
+
const named = revision.kind === "agentic" ? revision.body?.model : undefined;
|
|
74
|
+
const model = launch.model ?? (launch.hold?.refused ? heldKeyModel(env, launch.harness ?? DEFAULT_HARNESS, typeof named === "string" ? named : undefined) : undefined);
|
|
75
|
+
return { kind: revision.kind, ...(model ? { model } : {}), native: Boolean(launch.native) };
|
|
76
|
+
}
|
|
77
|
+
/** The model a run on `harness` of `ref` (its revision's; none, the host's default for the harness) is keyed by, read
|
|
78
|
+
* from the name alone (no model resolved, no key read): on the gateway, pi's model and a model on a wire the gateway
|
|
79
|
+
* serves are the gateway's (model.ts chooseModel, wires.ts WIRES), a ChatGPT plan's excepted; else the provider the
|
|
80
|
+
* name gives. None on a harness billed to its own plan, or for a name with no provider.
|
|
81
|
+
* It mirrors the router's gateway rule by name, so it moves with it: model.ts chooseModel (a ChatGPT plan's name goes to
|
|
82
|
+
* the plan, any other on AGENT_MODEL_BASE_URL to MODEL_PROVIDER), provider.ts modelOn (a harness on its own plan, no
|
|
83
|
+
* modelWire, chooses none) and wires.ts WIRES[wire].gateway (which CLI wires the gateway serves). A change to which
|
|
84
|
+
* names or wires go to the gateway there must be made here too, or a held run is checked for the wrong key. */
|
|
85
|
+
function heldKeyModel(env, harness, ref) {
|
|
86
|
+
const wire = harnessOf(env, harness)?.facts?.wire;
|
|
87
|
+
if (wire && !modelWire(wire))
|
|
88
|
+
return undefined;
|
|
89
|
+
const named = ref ?? hostModel(env, "default", harness);
|
|
90
|
+
if (env.AGENT_MODEL_BASE_URL && !named?.startsWith(`${PLAN_PROVIDER}/`) && (!wire || WIRES[wire].gateway))
|
|
91
|
+
return { provider: MODEL_PROVIDER, modelId: named ?? "" };
|
|
92
|
+
const slash = named?.indexOf("/") ?? -1;
|
|
93
|
+
return named && slash > 0 ? { provider: named.slice(0, slash), modelId: named.slice(slash + 1) } : undefined;
|
|
94
|
+
}
|
|
65
95
|
/** The variables a run's model route reads its key from when that route goes to the model gateway (a workflow's model
|
|
66
96
|
* nodes, pi's and codex's models, a CLI harness on Anthropic's wire where ANTHROPIC_BASE_URL is the gateway's origin);
|
|
67
97
|
* undefined for a route that goes elsewhere (a provider's own, the ChatGPT plan, the faux model) or a native run. */
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { type InFlight } from "./in-flight.js";
|
|
1
2
|
import type { Context } from "@earendil-works/chord/context";
|
|
2
3
|
import type { TimelineEvent } from "./timeline/index.js";
|
|
3
4
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
5
|
+
import { type RunCut } from "./run-cut.js";
|
|
4
6
|
import { type Page } from "./rows.js";
|
|
5
7
|
import { type FileView } from "./run-files.js";
|
|
6
8
|
import type { RunStated } from "./store-view.js";
|
|
@@ -35,17 +37,24 @@ export interface RunReadsDeps {
|
|
|
35
37
|
withheld(store: RunReadsStore, runId: string): Promise<boolean>;
|
|
36
38
|
/** The run's one cut (run-cut.ts runCutValues): the values everything served of it is cut of, its graph's parts among
|
|
37
39
|
* them, or `unreadable` when it is withheld. */
|
|
38
|
-
cutValues(store: RunReadsStore, runId: string): Promise<
|
|
39
|
-
values: string[];
|
|
40
|
-
} | "unreadable">;
|
|
40
|
+
cutValues(store: RunReadsStore, runId: string): Promise<RunCut>;
|
|
41
41
|
/** A context for the journal reads (graph, timeline). */
|
|
42
42
|
readonly context: Context;
|
|
43
|
+
/** The server's seal key: a run's census names each file by a MAC under it (run-census.ts fileMac). */
|
|
44
|
+
readonly sealKey: Buffer | undefined;
|
|
43
45
|
}
|
|
44
46
|
/** A run's files, through its Workspace (listRunFiles): every file, path-sorted, cut at the cap. A run with no folder lists
|
|
45
|
-
* none; a run whose output is withheld refuses (403), as its graph does. The same shape the route answered.
|
|
46
|
-
|
|
47
|
+
* none; a run whose output is withheld refuses (403), as its graph does. The same shape the route answered. With `cut`
|
|
48
|
+
* `run`, each file also has its `name`: its path under the run's own cut, as a cut read cuts a file's text (redactSecrets
|
|
49
|
+
* of deps.cutValues' values, read again after the names are cut: underCut), so a run that named a file by a held value
|
|
50
|
+
* (a cache keyed by a key) can be listed to a model by its names alone. Every file is named, whatever its type: a file a
|
|
51
|
+
* cut read doesn't answer (audio, an image) is one a grader is told of by its name. A run whose cut is its census's (its
|
|
52
|
+
* end erased what its caller handed it) names none. */
|
|
53
|
+
export declare function listRunFiles(store: RunReadsStore, runId: string, deps: RunReadsDeps, cut?: string | null): Promise<{
|
|
47
54
|
run_id: string;
|
|
48
|
-
files: FileView
|
|
55
|
+
files: (FileView & {
|
|
56
|
+
name?: string;
|
|
57
|
+
})[];
|
|
49
58
|
complete: true;
|
|
50
59
|
truncated: boolean;
|
|
51
60
|
}>;
|
|
@@ -54,6 +63,9 @@ export declare function listRunFiles(store: RunReadsStore, runId: string, deps:
|
|
|
54
63
|
* one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. With
|
|
55
64
|
* `?cut=run`, the file's text under the run's own cut instead (cutRunFile). */
|
|
56
65
|
export declare function readRunFile(store: RunReadsStore, runId: string, rawPath: string, req: IncomingMessage, res: ServerResponse, url: URL, deps: RunReadsDeps): Promise<void>;
|
|
66
|
+
/** Why a cut read of a file of an ended run is withheld (403) when its census can't say where the secrets the run was
|
|
67
|
+
* handed sat in it (run-census.ts censusCut). */
|
|
68
|
+
export declare const WITHHELD_UNCOUNTED = "This run was handed secrets of its own, and its end erased them; this file was not counted at that end as it is now (written or changed since, past the count's limits, or the run ended with no count), so it is not shown cut. Read it raw.";
|
|
57
69
|
/** A run's browser state (getRunBrowser): `live` with its viewer's link when its runner serves one; else `off` with why
|
|
58
70
|
* when the run has no browser or its browser is unavailable here now (the kept plane re-checked, as a launch would); else
|
|
59
71
|
* `none`. The same words and shapes the route answered. */
|
|
@@ -85,6 +97,9 @@ export interface TimelinePage {
|
|
|
85
97
|
readonly has_more: boolean;
|
|
86
98
|
readonly final: boolean;
|
|
87
99
|
readonly cost: Record<string, unknown> | null;
|
|
100
|
+
/** What the run waits on now (in-flight.ts): each model request sent and not answered, each tool call not returned, from
|
|
101
|
+
* when it was sent; empty once the run is final. */
|
|
102
|
+
readonly in_flight: readonly InFlight[];
|
|
88
103
|
}
|
|
89
104
|
/** What the timeline reader needs beyond the store: a context, the run's timeline rows and its view (status/state/cost). */
|
|
90
105
|
export interface TimelineDeps {
|
|
@@ -95,6 +110,9 @@ export interface TimelineDeps {
|
|
|
95
110
|
runView(store: Store, runId: string): Promise<Record<string, unknown> | undefined>;
|
|
96
111
|
/** How often the store is re-read while a page waits (default 1000 ms, the old poll). */
|
|
97
112
|
readonly pollMs?: number;
|
|
113
|
+
/** The model requests a live run has in flight (in-flight.ts modelsInFlight over its journal); read only while it is
|
|
114
|
+
* not final. None: a page names its tool calls in flight alone. */
|
|
115
|
+
inFlight?(store: Store, runId: string, context: Context): Promise<InFlight[]>;
|
|
98
116
|
}
|
|
99
117
|
/** The run timeline reader over the store (getTimeline): one RowLog per run, its change numbers stable across this server's
|
|
100
118
|
* polls (as the old live run's log was across a process's life), synced from the run's journal on each read. `page` is the
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
// The run READ routes over the one store (design 2.1): the functions the v2 read routes call to answer a run's files, its
|
|
2
|
+
// browser state, its graph and its timeline, over the store instead of a live per-run process. Each answers exactly what the
|
|
3
|
+
// route answers today — the same status codes, words and shapes. A run's files are read through the run's Workspace
|
|
4
|
+
// (workspace/, not a run directory the server owns); its browser state and its timeline read the run's launch, revision and
|
|
5
|
+
// journal. The live halves (a run's open browser viewer, the timeline's live stream) read the runner's live state through
|
|
6
|
+
// the store (live/stream.ts watchRun) and the viewer handover, which the runner publishes.
|
|
7
|
+
import { inFlightOf, toolsInFlight } from "./in-flight.js";
|
|
1
8
|
import { ApiError } from "./errors.js";
|
|
2
9
|
import { GRAPH_CACHE_BYTES, PartCache, servedGraphView } from "./graph-served.js";
|
|
3
10
|
import { runGraph } from "./graph-view.js";
|
|
4
11
|
import { checkedPath, decodedPath } from "./home-path.js";
|
|
5
12
|
import { redactSecrets } from "./learn/secrets.js";
|
|
13
|
+
import { censusCut, censusDigest } from "./run-census.js";
|
|
6
14
|
import { underCut } from "./run-cut.js";
|
|
7
15
|
import { usageWordsOf, WITHHELD_SIGN_IN } from "./run-view.js";
|
|
8
16
|
import { ChangeClock, RowLog } from "./rows.js";
|
|
9
|
-
import { entryAt, listFiles, RUN_FILE_CUT_MAX, sendFile } from "./run-files.js";
|
|
17
|
+
import { cutsAsText, entryAt, listFiles, RUN_FILE_CUT_MAX, sendFile } from "./run-files.js";
|
|
10
18
|
import { typeOf } from "./file-types.js";
|
|
11
19
|
import { readLaunchBody } from "./run-launch.js";
|
|
12
20
|
import { costIsBooked } from "./runner/metrics.js";
|
|
@@ -18,8 +26,15 @@ import { RECORDINGS } from "./workspace/paths.js";
|
|
|
18
26
|
/** The most files a list answers with (server.ts FILE_LIST_CAP). */
|
|
19
27
|
export const FILE_LIST_CAP = 2_000;
|
|
20
28
|
/** A run's files, through its Workspace (listRunFiles): every file, path-sorted, cut at the cap. A run with no folder lists
|
|
21
|
-
* none; a run whose output is withheld refuses (403), as its graph does. The same shape the route answered.
|
|
22
|
-
|
|
29
|
+
* none; a run whose output is withheld refuses (403), as its graph does. The same shape the route answered. With `cut`
|
|
30
|
+
* `run`, each file also has its `name`: its path under the run's own cut, as a cut read cuts a file's text (redactSecrets
|
|
31
|
+
* of deps.cutValues' values, read again after the names are cut: underCut), so a run that named a file by a held value
|
|
32
|
+
* (a cache keyed by a key) can be listed to a model by its names alone. Every file is named, whatever its type: a file a
|
|
33
|
+
* cut read doesn't answer (audio, an image) is one a grader is told of by its name. A run whose cut is its census's (its
|
|
34
|
+
* end erased what its caller handed it) names none. */
|
|
35
|
+
export async function listRunFiles(store, runId, deps, cut = null) {
|
|
36
|
+
if (cut !== null && cut !== "run")
|
|
37
|
+
throw new ApiError("bad_request", `cut must be "run", not ${JSON.stringify(cut)}`);
|
|
23
38
|
// Withheld (its browser sign-in this server can't read) refuses its files too, before any is read: a page it saved signed
|
|
24
39
|
// in is what it saw (store-view's `unshown`), as the graph refuses and the base's filesShown did.
|
|
25
40
|
if (await deps.withheld(store, runId))
|
|
@@ -28,11 +43,18 @@ export async function listRunFiles(store, runId, deps) {
|
|
|
28
43
|
// A folder the run made named recordings is not listed: the route's recordings/ is the run's recordings.
|
|
29
44
|
const { files, deep } = workspace ? await listFiles(workspace, FILE_LIST_CAP, { owned: (name) => name === RECORDINGS }) : { files: [], deep: false };
|
|
30
45
|
files.sort((a, b) => a.path.localeCompare(b.path));
|
|
31
|
-
|
|
46
|
+
const listed = files.slice(0, FILE_LIST_CAP);
|
|
47
|
+
const truncated = deep || files.length > FILE_LIST_CAP;
|
|
48
|
+
if (cut === null)
|
|
49
|
+
return { run_id: runId, files: listed, complete: true, truncated };
|
|
50
|
+
// Once the run's end erased what its caller handed it (censusDigest), its cut no longer holds those values: its census
|
|
51
|
+
// says where they sat in each file's text, never in a name, so no file is named (a grader counts them, as from a server
|
|
52
|
+
// that doesn't know `cut`).
|
|
53
|
+
const named = await underCut(() => deps.cutValues(store, runId), async (held) => (held === "unreadable" ? undefined : held.censusDigest !== undefined ? listed : listed.map((file) => ({ ...file, name: redactSecrets(file.path, held.values, Buffer.byteLength(file.path)) }))));
|
|
54
|
+
if (named === undefined)
|
|
55
|
+
throw new ApiError("forbidden", WITHHELD_SIGN_IN);
|
|
56
|
+
return { run_id: runId, files: named, complete: true, truncated };
|
|
32
57
|
}
|
|
33
|
-
/** A type the cut read takes as text: one the table names text, JSON or NDJSON, or one it doesn't know (its bytes are
|
|
34
|
-
* then read as UTF-8, and a file that isn't is 415). */
|
|
35
|
-
const cutsAsText = (type) => type === undefined || type.startsWith("text/") || type === "application/json" || type === "application/x-ndjson";
|
|
36
58
|
/** One of a run's files, through its Workspace (readRunFile): streamed to `res` as the route streams it, with the route's
|
|
37
59
|
* path check and its 404 words; a withheld run refuses (403) before anything is streamed. A path under recordings/ is
|
|
38
60
|
* one of the run's recordings (its recordings folder, beside its Workspace's), never a file the run made. With
|
|
@@ -52,13 +74,17 @@ export async function readRunFile(store, runId, rawPath, req, res, url, deps) {
|
|
|
52
74
|
return cutRunFile(store, runId, workspace, recording ?? rel, req, res, deps);
|
|
53
75
|
return sendFile(req, res, url, workspace, recording ?? rel, "a tool in the run's box");
|
|
54
76
|
}
|
|
77
|
+
/** Why a cut read of a file of an ended run is withheld (403) when its census can't say where the secrets the run was
|
|
78
|
+
* handed sat in it (run-census.ts censusCut). */
|
|
79
|
+
export const WITHHELD_UNCOUNTED = "This run was handed secrets of its own, and its end erased them; this file was not counted at that end as it is now (written or changed since, past the count's limits, or the run ended with no count), so it is not shown cut. Read it raw.";
|
|
55
80
|
/** File `rel` of the run's `workspace` as UTF-8 text cut of everything the run's own cut holds (deps.cutValues, the set its
|
|
56
|
-
* timeline's calls are cut of: the server's keys, the keys a person saved, its secret stores' values
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
81
|
+
* timeline's calls are cut of: the server's keys, the keys a person saved, its secret stores' values, the sign-in refs
|
|
82
|
+
* the run was handed, and while its launch holds them what its caller handed it: its own model key, tool keys and MCP
|
|
83
|
+
* credentials), through redactSecrets over the whole text, each value and secret shape replaced by "[redacted]" in
|
|
84
|
+
* place, and the text "[redacted]" whole when a value still shows in another form. A long run with no whitespace
|
|
85
|
+
* (compact JSON) is never blanked for its length. Once an end erased what its caller handed it, the run's census says
|
|
86
|
+
* where those sat (run-census.ts censusCut): a file still as counted is cut there too, and any other is withheld (403,
|
|
87
|
+
* WITHHELD_UNCOUNTED). The cut is read again after the text is cut (underCut), so a value saved meanwhile is cut too. An unreadable cut (the run withheld) is 403; a type that isn't text, or bytes that
|
|
62
88
|
* aren't UTF-8 or hold a NUL, 415; a file over RUN_FILE_CUT_MAX, 413. A Range header is not read: the answer is the
|
|
63
89
|
* whole file. */
|
|
64
90
|
async function cutRunFile(store, runId, workspace, rel, req, res, deps) {
|
|
@@ -82,17 +108,33 @@ async function cutRunFile(store, runId, workspace, rel, req, res, deps) {
|
|
|
82
108
|
});
|
|
83
109
|
let text;
|
|
84
110
|
try {
|
|
85
|
-
text
|
|
111
|
+
// A byte order mark is kept as the character it is: the text is the file's bytes, as the census counted them.
|
|
112
|
+
text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
86
113
|
}
|
|
87
114
|
catch {
|
|
88
115
|
throw new ApiError("unsupported_media_type", "a cut read answers UTF-8 text, and this file's bytes are not");
|
|
89
116
|
}
|
|
90
117
|
if (text.includes("\u0000"))
|
|
91
118
|
throw new ApiError("unsupported_media_type", "a cut read answers text, and this file holds a NUL byte");
|
|
92
|
-
const shown = await underCut(() => deps.cutValues(store, runId), async (cut) =>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
119
|
+
const shown = await underCut(() => deps.cutValues(store, runId), async (cut) => {
|
|
120
|
+
if (cut === "unreadable")
|
|
121
|
+
return { withheld: WITHHELD_SIGN_IN };
|
|
122
|
+
if (cut.censusDigest === undefined)
|
|
123
|
+
return { text: redactSecrets(text, cut.values, Buffer.byteLength(text)) };
|
|
124
|
+
// The run's end erased what its caller handed it: where those sat in this file is its census's to say. Read here, the
|
|
125
|
+
// one read that cuts by it; the cut names it by digest, so a census written since withholds this answer and the cut
|
|
126
|
+
// read again after it (underCut) builds it anew.
|
|
127
|
+
const census = await store.runs.launch(runId).then((row) => row.census, () => null);
|
|
128
|
+
if (census === null || censusDigest(census) !== cut.censusDigest)
|
|
129
|
+
return { withheld: WITHHELD_UNCOUNTED };
|
|
130
|
+
const held = censusCut(census, rel, bytes, text, deps.sealKey);
|
|
131
|
+
if (held === "unreadable")
|
|
132
|
+
return { withheld: WITHHELD_UNCOUNTED };
|
|
133
|
+
return { text: held === "whole" ? "[redacted]" : redactSecrets(text, cut.values, Buffer.byteLength(text), held) };
|
|
134
|
+
});
|
|
135
|
+
if ("withheld" in shown)
|
|
136
|
+
throw new ApiError("forbidden", shown.withheld);
|
|
137
|
+
const body = Buffer.from(shown.text);
|
|
96
138
|
res.writeHead(200, {
|
|
97
139
|
"content-type": "text/plain; charset=utf-8",
|
|
98
140
|
"content-length": body.length,
|
|
@@ -208,16 +250,18 @@ export function runTimelines(deps) {
|
|
|
208
250
|
const status = String(view.status);
|
|
209
251
|
const state = String(view.state);
|
|
210
252
|
const log = logOf(calls ? `${runId}\0calls` : runId);
|
|
211
|
-
// The run's rows as they stand now, then its status: a change to either is one more change the page carries.
|
|
212
|
-
log.sync(rows);
|
|
213
|
-
log.setState(`${status}:${state}`);
|
|
214
|
-
const page = log.page(after, limit);
|
|
215
253
|
// Final when the run is terminal and settled (the view says so with poll_after_ms 0, as the old final did).
|
|
216
254
|
const final = view.poll_after_ms === 0;
|
|
255
|
+
// What it waits on now, while it is live: a request sent or answered is a change, as a row is (GRE-4835).
|
|
256
|
+
const waiting = final ? inFlightOf([], []) : inFlightOf(deps.inFlight ? await deps.inFlight(store, runId, deps.context) : [], toolsInFlight(rows));
|
|
257
|
+
// The run's rows as they stand now, then its status and what it waits on: a change to any is one more change the page carries.
|
|
258
|
+
log.sync(rows);
|
|
259
|
+
log.setState(`${status}:${state}${waiting.key ? `:${waiting.key}` : ""}`);
|
|
260
|
+
const page = log.page(after, limit);
|
|
217
261
|
// The run's whole Cost object, as GET /runs/{id} serves it (store-view costOfView): the page and the run read send the
|
|
218
262
|
// same shape, so a reader need not read both to price the run.
|
|
219
263
|
const cost = view.cost ?? null;
|
|
220
|
-
return { run_id: runId, status, state, reset: page.reset, rows: page.rows, drop: page.drop, next_after: page.next_after, unchanged: page.unchanged, has_more: page.has_more, final, cost };
|
|
264
|
+
return { run_id: runId, status, state, reset: page.reset, rows: page.rows, drop: page.drop, next_after: page.next_after, unchanged: page.unchanged, has_more: page.has_more, final, cost, in_flight: waiting.list };
|
|
221
265
|
}
|
|
222
266
|
return {
|
|
223
267
|
async page(store, runId, after, waitMs, limit, calls = false) {
|
package/dist/run-recordings.d.ts
CHANGED
|
@@ -10,7 +10,11 @@ export type RecordingView = {
|
|
|
10
10
|
};
|
|
11
11
|
/** The recordings `folder` holds as a read-only Workspace, or null when it holds none (the run recorded nothing). */
|
|
12
12
|
export declare function recordingsWorkspace(folder: string): Promise<Workspace | null>;
|
|
13
|
-
/** The recordings in `folder`,
|
|
13
|
+
/** The recordings in `folder`, in the order they were recorded: computers by when their first file started, each
|
|
14
|
+
* computer's files in the order it recorded them. A file's start is the one its header says (computer-record.ts writes
|
|
15
|
+
* it), else its birth time, else its last change when this process first read it: never a time that moves while the
|
|
16
|
+
* file is written, so a computer that records on does not move behind one that started after it. Each is its path on
|
|
17
|
+
* the files route, its
|
|
14
18
|
* computer (its ref id, as its file is named: computer-record.ts names a computer's later files <computer>-2.mp4 and
|
|
15
19
|
* on), its length in seconds, its size, and whether it is finished: its trailer is there, or the run ended at `endedAt`
|
|
16
20
|
* and neither that end nor the file's last change is within twice the time the recorder gives ffmpeg to finish it
|
package/dist/run-recordings.js
CHANGED
|
@@ -33,11 +33,18 @@ function* boxes(buf) {
|
|
|
33
33
|
at += length;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/** 1970-01-01 in an MP4 header's seconds since 1904-01-01. */
|
|
37
|
+
const MP4_EPOCH_S = 2_082_844_800;
|
|
36
38
|
/** What box `type` says into `read`: the timescale, the default frame duration, and a fragment's end. */
|
|
37
39
|
function take(read, type, body) {
|
|
38
40
|
if (type === "moov" || type === "trak" || type === "mdia" || type === "mvex" || type === "moof")
|
|
39
41
|
for (const [inner, part] of boxes(body))
|
|
40
42
|
take(read, inner, part);
|
|
43
|
+
else if (type === "mvhd") {
|
|
44
|
+
// Seconds since 1904-01-01 UTC, 64-bit in a version 1 box.
|
|
45
|
+
const seconds = body[0] === 1 ? Number(body.readBigUInt64BE(4)) : body.readUInt32BE(4);
|
|
46
|
+
read.created = seconds > MP4_EPOCH_S ? (seconds - MP4_EPOCH_S) * 1000 : 0;
|
|
47
|
+
}
|
|
41
48
|
else if (type === "mdhd")
|
|
42
49
|
read.timescale = body.readUInt32BE(body[0] === 1 ? 20 : 12);
|
|
43
50
|
else if (type === "trex")
|
|
@@ -62,18 +69,19 @@ function take(read, type, body) {
|
|
|
62
69
|
read.end = Math.max(read.end, start + length);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
/** File `path`'s read, `
|
|
66
|
-
*
|
|
67
|
-
async function readOf(path,
|
|
72
|
+
/** File `path`'s read, as `file` stats it now: the last read when the file is unchanged (it is not opened), on from it
|
|
73
|
+
* when the file only grew, else from its start. */
|
|
74
|
+
async function readOf(path, file) {
|
|
75
|
+
const { size, mtimeMs } = file;
|
|
68
76
|
const kept = reads.get(path);
|
|
69
77
|
if (kept && kept.size === size && kept.mtimeMs === mtimeMs)
|
|
70
78
|
return kept;
|
|
71
|
-
const read = kept && kept.size <= size ? { ...kept } : { at: 0, size: 0, mtimeMs: 0, timescale: 0, dflt: 0, end: 0, finished: false };
|
|
72
|
-
const
|
|
79
|
+
const read = kept && kept.size <= size ? { ...kept } : { at: 0, size: 0, mtimeMs: 0, timescale: 0, dflt: 0, end: 0, finished: false, created: 0, made: file.birthtimeMs || mtimeMs };
|
|
80
|
+
const opened = await open(path, "r");
|
|
73
81
|
try {
|
|
74
82
|
const head = Buffer.alloc(16);
|
|
75
83
|
while (read.at + 8 <= size) {
|
|
76
|
-
await
|
|
84
|
+
await opened.read(head, 0, 16, read.at);
|
|
77
85
|
let length = head.readUInt32BE(0);
|
|
78
86
|
let skip = 8;
|
|
79
87
|
if (length === 1)
|
|
@@ -85,14 +93,14 @@ async function readOf(path, size, mtimeMs) {
|
|
|
85
93
|
read.finished = true;
|
|
86
94
|
if (type === "moov" || type === "moof") {
|
|
87
95
|
const body = Buffer.alloc(length - skip);
|
|
88
|
-
await
|
|
96
|
+
await opened.read(body, 0, body.length, read.at + skip);
|
|
89
97
|
take(read, type, body);
|
|
90
98
|
}
|
|
91
99
|
read.at += length;
|
|
92
100
|
}
|
|
93
101
|
}
|
|
94
102
|
finally {
|
|
95
|
-
await
|
|
103
|
+
await opened.close();
|
|
96
104
|
}
|
|
97
105
|
read.size = size;
|
|
98
106
|
read.mtimeMs = mtimeMs;
|
|
@@ -102,7 +110,11 @@ async function readOf(path, size, mtimeMs) {
|
|
|
102
110
|
reads.delete(reads.keys().next().value);
|
|
103
111
|
return read;
|
|
104
112
|
}
|
|
105
|
-
/** The recordings in `folder`,
|
|
113
|
+
/** The recordings in `folder`, in the order they were recorded: computers by when their first file started, each
|
|
114
|
+
* computer's files in the order it recorded them. A file's start is the one its header says (computer-record.ts writes
|
|
115
|
+
* it), else its birth time, else its last change when this process first read it: never a time that moves while the
|
|
116
|
+
* file is written, so a computer that records on does not move behind one that started after it. Each is its path on
|
|
117
|
+
* the files route, its
|
|
106
118
|
* computer (its ref id, as its file is named: computer-record.ts names a computer's later files <computer>-2.mp4 and
|
|
107
119
|
* on), its length in seconds, its size, and whether it is finished: its trailer is there, or the run ended at `endedAt`
|
|
108
120
|
* and neither that end nor the file's last change is within twice the time the recorder gives ffmpeg to finish it
|
|
@@ -117,17 +129,30 @@ export async function recordingsOf(folder, endedAt) {
|
|
|
117
129
|
const later = /^(.+)-(\d+)$/.exec(base);
|
|
118
130
|
return later && Number(later[2]) >= 2 && files.has(`${later[1]}.mp4`) ? { name, computer: later[1], n: Number(later[2]) } : { name, computer: base, n: 1 };
|
|
119
131
|
});
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
for (const { name, computer } of series) {
|
|
132
|
+
const found = [];
|
|
133
|
+
for (const { name, computer, n } of series) {
|
|
123
134
|
const path = join(folder, name);
|
|
124
135
|
const file = await lstat(path).catch(() => undefined);
|
|
125
136
|
if (!file?.isFile())
|
|
126
137
|
continue;
|
|
127
|
-
const read = await readOf(path, file
|
|
138
|
+
const read = await readOf(path, file).catch(() => undefined);
|
|
128
139
|
const seconds = read?.timescale ? Math.round((read.end / read.timescale) * 10) / 10 : 0;
|
|
129
140
|
const settled = endedAt !== null && Date.now() - Math.max(endedAt, file.mtimeMs) > 2 * RECORDING_LIMITS.settleMs;
|
|
130
|
-
|
|
141
|
+
found.push({ name, computer, n, read, view: { path: `${RECORDINGS}/${name}`, computer, seconds, bytes: file.size, finished: read?.finished === true || settled } });
|
|
131
142
|
}
|
|
143
|
+
// Each computer's start, from its first file: its header's (to the second), then its making (to the ms, for two that
|
|
144
|
+
// started in the same second), then its name. A computer whose first file can't be read goes last.
|
|
145
|
+
const starts = new Map();
|
|
146
|
+
for (const { computer, n, read } of found)
|
|
147
|
+
if (n === 1 && read)
|
|
148
|
+
starts.set(computer, [read.created || read.made, read.made]);
|
|
149
|
+
const last = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
|
|
150
|
+
found.sort((a, b) => {
|
|
151
|
+
if (a.computer === b.computer)
|
|
152
|
+
return a.n - b.n;
|
|
153
|
+
const [x, y] = [starts.get(a.computer) ?? last, starts.get(b.computer) ?? last];
|
|
154
|
+
return x[0] - y[0] || x[1] - y[1] || (a.computer < b.computer ? -1 : 1);
|
|
155
|
+
});
|
|
156
|
+
const listed = found.map((one) => one.view);
|
|
132
157
|
return listed;
|
|
133
158
|
}
|
|
@@ -6,6 +6,8 @@ import { type Store } from "./store/store.js";
|
|
|
6
6
|
export type ServedTimelineDeps = {
|
|
7
7
|
readonly serverSecrets: () => string[];
|
|
8
8
|
readonly signIns?: SignInReader;
|
|
9
|
+
/** The server's seal key (ViewDeps.sealKey). */
|
|
10
|
+
readonly sealKey: Buffer | undefined;
|
|
9
11
|
/** The environment a run's model key is read from, with the keys a person saved (withSecrets, as main's plainKey). */
|
|
10
12
|
readonly keyEnv: () => NodeJS.ProcessEnv;
|
|
11
13
|
/** Each learned item's status on an agent's learning folder's main (learning-routes.ts statusesOf): what a run held for
|
|
@@ -13,6 +15,6 @@ export type ServedTimelineDeps = {
|
|
|
13
15
|
readonly statuses?: (agentId: string) => Promise<ReadonlyMap<string, ItemStatus> | undefined>;
|
|
14
16
|
};
|
|
15
17
|
/** Run `runId`'s Timeline rows as served: cut by its one cut set, its decision rows among them, its error rows in the
|
|
16
|
-
* run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output
|
|
18
|
+
* run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output whole to
|
|
17
19
|
* CALL_RESULT_CHARS too (TimelineOptions.calls), through the same cut, for a reader that grades the run. */
|
|
18
20
|
export declare function servedTimelineRows(deps: ServedTimelineDeps, store: Store, runId: string, context: Context, calls?: boolean): Promise<TimelineEvent[]>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { CALL_RESULT_CHARS, TRIGGER_LABELS } from "./timeline/index.js";
|
|
1
|
+
import { CALL_RESULT_CHARS, scrubUrls, TRIGGER_LABELS } from "./timeline/index.js";
|
|
2
2
|
import { withDecisions } from "./decision-rows.js";
|
|
3
3
|
import { currentLearning, holdsForOk, secretsShown } from "./learning.js";
|
|
4
4
|
import { withLearning } from "./learning-run.js";
|
|
5
5
|
import { runLearningEnd } from "./store-reads/learning.js";
|
|
6
|
-
import { heldNumber, redacted } from "./key-refusal.js";
|
|
6
|
+
import { heldNumber, redacted, redactedCall, withheldWhole } from "./key-refusal.js";
|
|
7
7
|
import { runCutValues, runErrorWordsOf, underCut } from "./run-cut.js";
|
|
8
8
|
import { answersOf, asksOf, shownOf, stopAsked, withApprovalRows, withAsks, withBudgetRows, withOverCap } from "./run-view.js";
|
|
9
9
|
import { launchOf } from "./handed-values.js";
|
|
@@ -14,7 +14,7 @@ import { readRun } from "./store-reads/runs.js";
|
|
|
14
14
|
import { runTimeline, servedSince, wholeAnswerFor, wholeAnswers } from "./store-reads/journal.js";
|
|
15
15
|
import { FINAL_STATES } from "./store/store.js";
|
|
16
16
|
/** Run `runId`'s Timeline rows as served: cut by its one cut set, its decision rows among them, its error rows in the
|
|
17
|
-
* run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output
|
|
17
|
+
* run's error's words; none for a run withheld. `calls`: each call's arguments whole and its output whole to
|
|
18
18
|
* CALL_RESULT_CHARS too (TimelineOptions.calls), through the same cut, for a reader that grades the run. */
|
|
19
19
|
export async function servedTimelineRows(deps, store, runId, context, calls = false) {
|
|
20
20
|
// The run's rows, its decisions, its learning end and the triggers' names, all read in one snapshot of the store (one
|
|
@@ -48,7 +48,7 @@ export async function servedTimelineRows(deps, store, runId, context, calls = fa
|
|
|
48
48
|
// And every call still waiting once a stop is asked and not yet taken, as the run's view reads it (stopAsked).
|
|
49
49
|
const final = run?.state === "stopped" || run?.state === "failed" ? run.state
|
|
50
50
|
: stopAsked(view, run, await snapshot.commands(runId, 0)) ? "stopped" : undefined;
|
|
51
|
-
const options = { redact, settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) =>
|
|
51
|
+
const options = { redact, holds: (text) => withheldWhole(text, values), settled: ended, ended: view ? view.state !== "running" : false, ...(calls ? { calls: { result: CALL_RESULT_CHARS, redact: (text) => redactedCall(text, values, CALL_RESULT_CHARS, scrubUrls), held: (value) => heldNumber(value, values) } } : {}) };
|
|
52
52
|
const timeline = await wholeAnswers(snapshot, runId, context, await runTimeline(snapshot, runId, context, options), options, wholeAnswerFor(values), since);
|
|
53
53
|
// A run whose booked spend passed its cap says so, by how much, after its usage row (run-view.ts withOverCap, as main's
|
|
54
54
|
// served Timeline did): at the cap as it stands (a raise taken counts, capNowOf).
|
package/dist/run-usage.d.ts
CHANGED
|
@@ -166,4 +166,5 @@ export declare function runUsageOverStore(store: Store, runId: string): Promise<
|
|
|
166
166
|
export declare function servedRunUsage(deps: {
|
|
167
167
|
serverSecrets: () => string[];
|
|
168
168
|
signIns?: SignInReader;
|
|
169
|
+
sealKey: Buffer | undefined;
|
|
169
170
|
}, store: Store, runId: string): Promise<RunUsage | undefined>;
|
package/dist/runnable.d.ts
CHANGED
|
@@ -52,7 +52,10 @@ export type RevisionShape = {
|
|
|
52
52
|
* (code nodes this server does not run), `shell` (a shell or executor call), `tier`, `harness`, `box` (the place's,
|
|
53
53
|
* which this server does not have) and `denied` (a tool a workflow's call node calls that is set to deny) name it for a
|
|
54
54
|
* run's 409 details; `notGrantable` a tool no setup makes grantable (a known MCP meta tool, mcp-meta.ts), with why.
|
|
55
|
-
* `short`: a save's cap below what its model needs for one more step and an answer, a warning alone (cap-short.ts).
|
|
55
|
+
* `short`: a save's cap below what its model needs for one more step and an answer, a warning alone (cap-short.ts).
|
|
56
|
+
* `model`: an agentic revision's model is the blocker (no key for it, its harness refusing it or unavailable here for
|
|
57
|
+
* want of a model key alone, no price under a cap): a held run's create defers it to the run's start (server.ts
|
|
58
|
+
* runnable, computer-held.ts). */
|
|
56
59
|
export type Blocker = InputIssue & {
|
|
57
60
|
host: boolean;
|
|
58
61
|
tool?: string;
|
|
@@ -78,6 +81,7 @@ export type Blocker = InputIssue & {
|
|
|
78
81
|
asks?: string;
|
|
79
82
|
unpriced?: true;
|
|
80
83
|
short?: true;
|
|
84
|
+
model?: true;
|
|
81
85
|
};
|
|
82
86
|
/**
|
|
83
87
|
* The model `harness` runs an agentic revision on here: `ref`, its own `provider/model-id`, or with none this host's
|
|
@@ -100,6 +104,11 @@ export declare const NOT_SET_UP = "not_set_up_here";
|
|
|
100
104
|
/** Set to 1 (`--allow-code-nodes`), this server runs workflows' `code` nodes: in the run's process, through the DSL's
|
|
101
105
|
* `new Function` transform, which is no sandbox. Off by default. */
|
|
102
106
|
export declare const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
107
|
+
/** The kind of an agentic `revision`'s computer setting when every tool that computer serves is set to deny under the
|
|
108
|
+
* server's tool `settings` (tool-gate.ts computerDenied), with its shell where `shellOf` puts it: a run of it never
|
|
109
|
+
* starts that computer (computer-for-claim.ts), so blockersOf asks nothing of it, and a save warns (server.ts saveable).
|
|
110
|
+
* Undefined for one with no computer setting, or with no `shellOf` to place its shell. */
|
|
111
|
+
export declare function deniedComputer(revision: RevisionShape, settings: ToolSettingsMap, shellOf?: (setting: RevisionComputer) => Promise<ShellPlace>): Promise<string | undefined>;
|
|
103
112
|
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
104
113
|
* server found at its start (place-offers.ts); none, every box is unavailable. `monid`: its pin. `offers`: the harnesses' offers
|
|
105
114
|
* the server already holds (its reading); none given, they are probed here. `computerReady`: whether an agent's computer
|
package/dist/runnable.js
CHANGED
|
@@ -14,7 +14,7 @@ import { llmTiers, MODEL_NODES, nodeTiers, unpricedModels, workflowNodes } from
|
|
|
14
14
|
import { boxAvailability, newAgentPlace, placeFix, RUN_BOXES } from "./place.js";
|
|
15
15
|
import { allows, BOUND_TOOLS, CALL_TOOLS, grantedTools, missingEnv, NODE_TOOLS, shellTools, toolOf, workflowTools } from "./tools.js";
|
|
16
16
|
import { DENIED, isUnavailable, NO_PARALLEL_KEY, planeFor, whyUnavailable } from "./tool-plane.js";
|
|
17
|
-
import { denyPlace, permissionFrom, permissionKeys, permissionOf } from "./tool-gate.js";
|
|
17
|
+
import { computerDenied, denyPlace, permissionFrom, permissionKeys, permissionOf } from "./tool-gate.js";
|
|
18
18
|
import { approvalsOf } from "./approvals.js";
|
|
19
19
|
import { PARALLEL_KEY_ENV } from "./decisions.js";
|
|
20
20
|
import { keyNeeded } from "./key-words.js";
|
|
@@ -54,6 +54,15 @@ const PRICE_FIX = "Set AGENT_MODEL_PRICE (USD per million input,output,cacheRead
|
|
|
54
54
|
/** Set to 1 (`--allow-code-nodes`), this server runs workflows' `code` nodes: in the run's process, through the DSL's
|
|
55
55
|
* `new Function` transform, which is no sandbox. Off by default. */
|
|
56
56
|
export const CODE_NODES_ENV = "AGENTRUN_SERVE_CODE_NODES";
|
|
57
|
+
/** The kind of an agentic `revision`'s computer setting when every tool that computer serves is set to deny under the
|
|
58
|
+
* server's tool `settings` (tool-gate.ts computerDenied), with its shell where `shellOf` puts it: a run of it never
|
|
59
|
+
* starts that computer (computer-for-claim.ts), so blockersOf asks nothing of it, and a save warns (server.ts saveable).
|
|
60
|
+
* Undefined for one with no computer setting, or with no `shellOf` to place its shell. */
|
|
61
|
+
export async function deniedComputer(revision, settings, shellOf) {
|
|
62
|
+
if (revision.kind !== "agentic" || !revision.computer || !shellOf)
|
|
63
|
+
return undefined;
|
|
64
|
+
return computerDenied({ kind: revision.kind, body: revision }, await shellOf(revision.computer), { settings, problems: [] });
|
|
65
|
+
}
|
|
57
66
|
/** What keeps `revision` from running in `env` under the server's tool `settings` (tool-plane.ts). `boxes`: what this
|
|
58
67
|
* server found at its start (place-offers.ts); none, every box is unavailable. `monid`: its pin. `offers`: the harnesses' offers
|
|
59
68
|
* the server already holds (its reading); none given, they are probed here. `computerReady`: whether an agent's computer
|
|
@@ -79,18 +88,21 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
79
88
|
};
|
|
80
89
|
const harness = revision.harness ?? DEFAULT_HARNESS;
|
|
81
90
|
const offer = (offers ?? (await harnessOffers(env))).find((h) => h.id === harness);
|
|
82
|
-
// One the table hides (HarnessEntry.hidden: Goose before its owner installs it) has no offer: its entry says why.
|
|
91
|
+
// One the table hides (HarnessEntry.hidden: Goose before its owner installs it) has no offer: its entry says why. One
|
|
92
|
+
// that lacks only a model key (its offer's `keys`: harness.ts harnessOffers keeps them on no other) is its model's
|
|
93
|
+
// blocker, which a held create defers.
|
|
83
94
|
if (!offer?.available)
|
|
84
|
-
out.push({ field: "definition.harness", reason: NOT_SET_UP, message: offer?.reason ?? harnessOf(env, harness)?.hidden?.(env) ?? `This server does not run ${harness}.`, host: true, harness });
|
|
95
|
+
out.push({ field: "definition.harness", reason: NOT_SET_UP, message: offer?.reason ?? harnessOf(env, harness)?.hidden?.(env) ?? `This server does not run ${harness}.`, host: true, harness, ...(offer?.keys?.length ? { model: true } : {}) });
|
|
85
96
|
const { place } = revision;
|
|
86
97
|
// A workflow's model and call nodes run on the runner here; in a box they do not run yet. Its fix names the runner: an
|
|
87
98
|
// edit that leaves the place out keeps the agent's (agents-store.ts), so removing the field would change nothing.
|
|
88
99
|
if (revision.kind === "workflow" && place && place.mode !== "runner")
|
|
89
100
|
out.push({ field: "definition.place", reason: "not_an_option", message: `A workflow runs on the runner here: its place is runner (or none), not ${place.mode} on ${place.box ?? "no box"}.`, fix: placeFix({ mode: "runner" }), host: false });
|
|
90
101
|
// An agent with a computer setting is checked by the claim's own answers (resolve-computer.ts computerReadiness: the
|
|
91
|
-
// provider and its kind, the mode's mount, its keys), not as a box; one with only an old place keeps the box check.
|
|
102
|
+
// provider and its kind, the mode's mount, its keys), not as a box; one with only an old place keeps the box check. One
|
|
103
|
+
// every tool of whose computer is set to deny is not: its runs never start it (deniedComputer).
|
|
92
104
|
else if (revision.kind === "agentic" && revision.computer && computerReady) {
|
|
93
|
-
const ready = await computerReady(revision.computer);
|
|
105
|
+
const ready = (await deniedComputer(revision, settings, shellOf)) ? { ok: true } : await computerReady(revision.computer);
|
|
94
106
|
if ("refused" in ready)
|
|
95
107
|
out.push({ field: "definition.computer", reason: NOT_SET_UP, message: ready.refused, host: true, ...(ready.box ? { box: ready.box } : {}) });
|
|
96
108
|
}
|
|
@@ -209,15 +221,15 @@ export async function blockersOf(env, revision, settings = {}, { capped = false,
|
|
|
209
221
|
if (!resolved)
|
|
210
222
|
return out;
|
|
211
223
|
if ("why" in resolved)
|
|
212
|
-
out.push({ field: "definition.model", reason: resolved.host ? NOT_SET_UP : "not_an_option", message: resolved.why, host: resolved.host });
|
|
224
|
+
out.push({ field: "definition.model", reason: resolved.host ? NOT_SET_UP : "not_an_option", message: resolved.why, host: resolved.host, model: true });
|
|
213
225
|
else if ("refused" in resolved)
|
|
214
|
-
out.push({ field: revision.model ? "definition.model" : "definition.harness", reason: NOT_SET_UP, message: resolved.refused, host: true, harness });
|
|
226
|
+
out.push({ field: revision.model ? "definition.model" : "definition.harness", reason: NOT_SET_UP, message: resolved.refused, host: true, harness, model: true });
|
|
215
227
|
// Under a cap, a model serve has no price for (unpricedModels: a gateway id no price names and the catalog does not
|
|
216
228
|
// list) cannot be kept to it: the run is refused now, never started and refused at its first request.
|
|
217
229
|
else if (capped) {
|
|
218
230
|
const unpriced = await unpricedModels(env, revision.model, ["default"], harness);
|
|
219
231
|
for (const id of unpriced)
|
|
220
|
-
out.push({ field: "definition.model", reason: NOT_SET_UP, message: `The model ${id} has no price here, so a run's spend cap cannot be kept on it.`, fix: PRICE_FIX, host: true, unpriced: true });
|
|
232
|
+
out.push({ field: "definition.model", reason: NOT_SET_UP, message: `The model ${id} has no price here, so a run's spend cap cannot be kept on it.`, fix: PRICE_FIX, host: true, unpriced: true, model: true });
|
|
221
233
|
// A save's cap (`capUsd`) below what the model needs for one more step and an answer: a warning, never a refusal
|
|
222
234
|
// (cap-short.ts). Asked of a save alone: a run under such a cap starts, and its wrap-up says the same.
|
|
223
235
|
if (capUsd !== undefined && unpriced.length === 0) {
|