@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42
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 +130 -0
- package/NOTICE +2 -0
- package/README.md +149 -21
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +22 -6
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +23 -26
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +72 -0
- package/dist/eval-mailbox.d.ts +4 -1
- package/dist/eval-mailbox.js +11 -3
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +42 -0
- package/dist/feed/parse.js +291 -0
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +17 -1
- package/dist/learn/check.js +240 -5
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +23 -1
- package/dist/mcp-oauth.js +46 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +151 -21
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +94 -16
- package/dist/runner/adapter-run-spec.d.ts +19 -0
- package/dist/runner/adapter-run-spec.js +57 -36
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +41 -32
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +12 -1
- package/dist/runner/main.js +31 -4
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +6 -2
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +4 -2
- package/dist/runner/model-route.js +8 -8
- package/dist/runner/promotion.d.ts +44 -4
- package/dist/runner/promotion.js +323 -21
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +16 -20
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +21 -7
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +5 -3
- package/dist/server.d.ts +31 -5
- package/dist/server.js +240 -61
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- 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/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +11 -3
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +64 -10
- package/dist/store/store.d.ts +38 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +8 -2
- package/dist/template-eval.d.ts +11 -0
- package/dist/template-eval.js +177 -52
- package/dist/templates.d.ts +13 -1
- package/dist/templates.js +89 -18
- package/dist/timeline/computer.js +2 -1
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-adapter.d.ts +9 -4
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +420 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/validate.js +7 -2
- package/dist/webhooks.js +9 -5
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +35 -4
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +34 -22
- package/package.json +11 -9
- package/templates/README.md +38 -4
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NativeBinding } from "../native/types.js";
|
|
2
|
+
import { type LearningSetting } from "../learning-setting.js";
|
|
2
3
|
/** A revision's body the store refuses: its content is not one the store keeps. The server maps it to an input refusal. */
|
|
3
4
|
export declare class AgentBodyInvalid extends Error {
|
|
4
5
|
constructor(message: string);
|
|
@@ -30,7 +31,7 @@ export type RevisionPlace = {
|
|
|
30
31
|
/** A revision's computer (computer-setting.ts): its kind and the provider that serves it, ids its host knows, and a
|
|
31
32
|
* sandbox's GPUs, a type its provider names and how many; `place` is its v2 view. `image`: one the provider offers for
|
|
32
33
|
* the kind, absent for its default. A desktop's or a phone's surface and exec: how the agent drives it, and whether it
|
|
33
|
-
* may run programs on it. */
|
|
34
|
+
* may run programs on it, and whether each run records a video of its screen. */
|
|
34
35
|
export type RevisionComputer = {
|
|
35
36
|
kind: string;
|
|
36
37
|
provider?: string;
|
|
@@ -42,6 +43,7 @@ export type RevisionComputer = {
|
|
|
42
43
|
persistent?: boolean;
|
|
43
44
|
surface?: "code" | "tools";
|
|
44
45
|
exec?: boolean;
|
|
46
|
+
record?: boolean;
|
|
45
47
|
};
|
|
46
48
|
/** A revision's tool settings as its body keeps them: a map of a tool's key to its settings ({provider?, permission?,
|
|
47
49
|
* pin?}), checked and made canonical by the caller (agents-store.ts, through tool-plane's settingsIssues +
|
|
@@ -73,7 +75,7 @@ export type AgenticBody = {
|
|
|
73
75
|
harness?: string;
|
|
74
76
|
place?: RevisionPlace;
|
|
75
77
|
computer?: RevisionComputer;
|
|
76
|
-
learning?:
|
|
78
|
+
learning?: LearningSetting;
|
|
77
79
|
toolSettings?: ToolSettings;
|
|
78
80
|
maxCostUsd?: number;
|
|
79
81
|
approvals?: "ask" | "never";
|
|
@@ -108,7 +110,7 @@ export type RevisionBodyInput = {
|
|
|
108
110
|
harness?: string;
|
|
109
111
|
place?: unknown;
|
|
110
112
|
computer?: unknown;
|
|
111
|
-
learning?:
|
|
113
|
+
learning?: LearningSetting;
|
|
112
114
|
toolSettings?: ToolSettings;
|
|
113
115
|
maxCostUsd?: number;
|
|
114
116
|
approvals?: "ask" | "never";
|
package/dist/store/agent-body.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// two equal pins are one revision.
|
|
8
8
|
import { createHash } from "node:crypto";
|
|
9
9
|
import { nativeBindingOf } from "../native/binding.js";
|
|
10
|
+
import { learningSettingIssue, learningSettingOf } from "../learning-setting.js";
|
|
10
11
|
/** A revision's body the store refuses: its content is not one the store keeps. The server maps it to an input refusal. */
|
|
11
12
|
export class AgentBodyInvalid extends Error {
|
|
12
13
|
constructor(message) {
|
|
@@ -46,24 +47,24 @@ function placeOf(place) {
|
|
|
46
47
|
/** A GPU type as a body keeps it: the vendor's own name ("T4", "A100-80GB", "RTX-PRO-6000"). */
|
|
47
48
|
const GPU_TYPE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
48
49
|
/** The keys a body's computer keeps. */
|
|
49
|
-
const COMPUTER_KEYS = new Set(["kind", "provider", "image", "gpu", "persistent", "surface", "exec"]);
|
|
50
|
-
/** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?, surface?, exec?}`, nothing
|
|
51
|
-
* and provider ids, image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole
|
|
52
|
-
* 1, persistent and
|
|
50
|
+
const COMPUTER_KEYS = new Set(["kind", "provider", "image", "gpu", "persistent", "surface", "exec", "record"]);
|
|
51
|
+
/** A computer as a body keeps it: `{kind, provider?, image?, gpu?, persistent?, surface?, exec?, record?}`, nothing
|
|
52
|
+
* else: kind and provider ids, image a name with no spaces around it, gpu `{type, count}`, a GPU type name and a whole
|
|
53
|
+
* count from 1, persistent, exec and record booleans, and surface code or tools. */
|
|
53
54
|
function computerOf(computer) {
|
|
54
55
|
const image = isObject(computer) ? computer.image : undefined;
|
|
55
56
|
const named = (value) => typeof value === "string" && value !== "" && value === value.trim();
|
|
56
57
|
const flag = (value) => value === undefined || typeof value === "boolean";
|
|
57
58
|
const surface = isObject(computer) ? computer.surface : undefined;
|
|
58
|
-
if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || !flag(computer.persistent) || !flag(computer.exec) || (surface !== undefined && surface !== "code" && surface !== "tools") || Object.keys(computer).some((key) => !COMPUTER_KEYS.has(key)))
|
|
59
|
-
invalid("the computer is not {kind, provider?, image?, gpu?, persistent?, surface?, exec?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean, surface code or tools, exec a boolean");
|
|
59
|
+
if (!isObject(computer) || !hostId(computer.kind) || (computer.provider !== undefined && !hostId(computer.provider)) || (image !== undefined && !named(image)) || !flag(computer.persistent) || !flag(computer.exec) || !flag(computer.record) || (surface !== undefined && surface !== "code" && surface !== "tools") || Object.keys(computer).some((key) => !COMPUTER_KEYS.has(key)))
|
|
60
|
+
invalid("the computer is not {kind, provider?, image?, gpu?, persistent?, surface?, exec?, record?}, kind and provider each an id (lowercase letters, digits and dashes), image a name, persistent a boolean, surface code or tools, exec a boolean, record a boolean");
|
|
60
61
|
const ok = computer;
|
|
61
62
|
const gpu = ok.gpu;
|
|
62
63
|
if (gpu !== undefined && (!isObject(gpu) || Object.keys(gpu).some((key) => key !== "type" && key !== "count") || typeof gpu.type !== "string" || !GPU_TYPE.test(gpu.type) || !Number.isSafeInteger(gpu.count) || gpu.count < 1)) {
|
|
63
64
|
invalid("the computer's gpu is not {type, count}: a GPU type name (letters, digits, dots, underscores and dashes) and a whole count from 1");
|
|
64
65
|
}
|
|
65
66
|
const kept = gpu;
|
|
66
|
-
return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}), ...(ok.surface !== undefined ? { surface: ok.surface } : {}), ...(ok.exec !== undefined ? { exec: ok.exec } : {}) };
|
|
67
|
+
return { kind: ok.kind, ...(ok.provider !== undefined ? { provider: ok.provider } : {}), ...(ok.image !== undefined ? { image: ok.image } : {}), ...(kept !== undefined ? { gpu: { type: kept.type, count: kept.count } } : {}), ...(ok.persistent !== undefined ? { persistent: ok.persistent } : {}), ...(ok.surface !== undefined ? { surface: ok.surface } : {}), ...(ok.exec !== undefined ? { exec: ok.exec } : {}), ...(ok.record !== undefined ? { record: ok.record } : {}) };
|
|
67
68
|
}
|
|
68
69
|
/** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
|
|
69
70
|
* write. The body keeps each skill path to its text's SHA-256; `skills` is the texts, for the revision's row. */
|
|
@@ -113,8 +114,11 @@ export function bodyOf(input) {
|
|
|
113
114
|
for (const field of ["model", "thinking"])
|
|
114
115
|
if (input[field] !== undefined && (typeof input[field] !== "string" || input[field] === ""))
|
|
115
116
|
invalid(`the ${field} is not a non-empty string`);
|
|
116
|
-
if (input.learning !== undefined
|
|
117
|
-
|
|
117
|
+
if (input.learning !== undefined) {
|
|
118
|
+
const wrong = learningSettingIssue(input.learning);
|
|
119
|
+
if (wrong)
|
|
120
|
+
invalid(wrong);
|
|
121
|
+
}
|
|
118
122
|
if (input.inputSchema !== undefined && !isObject(input.inputSchema))
|
|
119
123
|
invalid("the inputSchema is not a JSON object");
|
|
120
124
|
if (input.outputSchema !== undefined && !isObject(input.outputSchema))
|
|
@@ -138,7 +142,7 @@ export function bodyOf(input) {
|
|
|
138
142
|
...(input.thinking !== undefined ? { thinking: input.thinking } : {}),
|
|
139
143
|
...(input.prompts !== undefined ? { prompts: structuredClone(input.prompts) } : {}),
|
|
140
144
|
...host,
|
|
141
|
-
...(input.learning !== undefined ? { learning: input.learning } : {}),
|
|
145
|
+
...(input.learning !== undefined ? { learning: learningSettingOf(input.learning) } : {}),
|
|
142
146
|
// The JSON Schema each run's input meets (definition.input_schema), checked at every start (validate.ts inputSchemaOf).
|
|
143
147
|
...(input.inputSchema !== undefined ? { inputSchema: structuredClone(input.inputSchema) } : {}),
|
|
144
148
|
// The JSON Schema its final answer's structured part meets (definition.output_schema): a completed run's result.output.
|
package/dist/store/dialect.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ export interface Dialect {
|
|
|
10
10
|
jsonNotFalse(column: string, path: readonly string[]): string;
|
|
11
11
|
/** True when the JSON array in TEXT column `column` holds the string parameter that follows (one `?`). */
|
|
12
12
|
jsonArrayHas(column: string): string;
|
|
13
|
+
/** True when the JSON object of strings in TEXT column `column` holds the key and the value of the two string parameters
|
|
14
|
+
* that follow (two `?`): bound, never spliced, so any key reads safely. False when the column is NULL. */
|
|
15
|
+
jsonObjectHas(column: string): string;
|
|
13
16
|
/** The length of the JSON array in TEXT column `column`. */
|
|
14
17
|
jsonArrayLength(column: string): string;
|
|
15
18
|
/** The JSON object in TEXT column `column` without its top-level `key`. */
|
package/dist/store/dialect.js
CHANGED
|
@@ -15,6 +15,7 @@ export const SQLITE = {
|
|
|
15
15
|
jsonText: (column, path) => `json_extract(${column}, ${jsonPath(path)})`,
|
|
16
16
|
jsonNotFalse: (column, path) => `json_extract(${column}, ${jsonPath(path)}) IS NOT 0`,
|
|
17
17
|
jsonArrayHas: (column) => `EXISTS (SELECT 1 FROM json_each(${column}) WHERE value = ?)`,
|
|
18
|
+
jsonObjectHas: (column) => `EXISTS (SELECT 1 FROM json_each(${column}) AS entry WHERE entry.key = ? AND entry.value = ?)`,
|
|
18
19
|
jsonArrayLength: (column) => `json_array_length(${column})`,
|
|
19
20
|
jsonWithout: (column, key) => `json_remove(${column}, ${jsonPath([key])})`,
|
|
20
21
|
firingOrder: "rowid",
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentArchived, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull } from "./store.js";
|
|
2
|
-
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
2
|
+
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
3
3
|
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunMcpAuth, type RunMcpAuth, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
4
|
export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type ModelTiers, type MonidPinBody, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
|
|
5
5
|
export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
|
|
@@ -12,6 +12,7 @@ export function postgresDialect(schema, { testClock = false } = {}) {
|
|
|
12
12
|
// SQLite's json_extract(...) IS NOT 0: true unless the value is false or the number 0 (absent and null are true).
|
|
13
13
|
jsonNotFalse: (column, keys) => `COALESCE((${column}::json #> ${path(keys)})::text NOT IN ('false', '0'), TRUE)`,
|
|
14
14
|
jsonArrayHas: (column) => `EXISTS (SELECT 1 FROM json_array_elements_text(${column}::json) AS element(value) WHERE element.value = ?)`,
|
|
15
|
+
jsonObjectHas: (column) => `EXISTS (SELECT 1 FROM json_each_text(${column}::json) AS entry(key, value) WHERE entry.key = ? AND entry.value = ?)`,
|
|
15
16
|
jsonArrayLength: (column) => `json_array_length(${column}::json)`,
|
|
16
17
|
// Through jsonb, the one place: a body that loses a key is never read for its key order. Every Postgres JSON function
|
|
17
18
|
// decodes the whole document's strings, so a body holding a string jsonb refuses (an escaped NUL, a lone surrogate)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
-- Version 15: a run's labels (runs.labels, as store/schema.ts keeps them on SQLite): the caller's labels, a JSON object of
|
|
2
|
+
-- strings set once at the run's start; null when it was given none, so a run started before reads as given none. Applied
|
|
3
|
+
-- once, after 0014, inside the transaction migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS labels TEXT COLLATE "C" CHECK (labels IS NULL OR labels::json IS NOT NULL);
|
|
5
|
+
UPDATE store_meta SET schema_version = 15 WHERE singleton = 1;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 16: a hosted machine's minted token (a dial provider's create,
|
|
2
|
+
-- spec/computer/attach.md), as store/schema.ts keeps it on SQLite (MINTED_TOKENS). Applied once, after 0015, inside the
|
|
3
|
+
-- transaction migrate.ts opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- minted_tokens: one row per machine (its name, from its create's request id); the token's SHA-256 alone is kept (hex),
|
|
6
|
+
-- with what the machine must say it is at hello (kind, os, arch), when the token ends (expires_at, the machine's backstop)
|
|
7
|
+
-- and when it was revoked (its delete). The table is made only where it is missing, so a store whose record of this file
|
|
8
|
+
-- was lost applies it again unharmed.
|
|
9
|
+
|
|
10
|
+
CREATE TABLE IF NOT EXISTS minted_tokens (
|
|
11
|
+
machine TEXT COLLATE "C" PRIMARY KEY,
|
|
12
|
+
token_sha256 TEXT COLLATE "C" NOT NULL UNIQUE,
|
|
13
|
+
kind TEXT COLLATE "C" NOT NULL,
|
|
14
|
+
os TEXT COLLATE "C" NOT NULL,
|
|
15
|
+
arch TEXT COLLATE "C" NOT NULL,
|
|
16
|
+
expires_at BIGINT NOT NULL,
|
|
17
|
+
revoked_at BIGINT,
|
|
18
|
+
created_at BIGINT NOT NULL
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
UPDATE store_meta SET schema_version = 16 WHERE singleton = 1;
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -16,12 +16,21 @@ export declare const REVISIONS_MONID_PIN: string;
|
|
|
16
16
|
/** The bound beside a run's cost: in STORE_DDL, and added at a server open to a store an earlier build of this version made,
|
|
17
17
|
* as REVISIONS_MCP_PIN is (a run it ended reads 0: an exact cost or an unknown one, as it was read then). */
|
|
18
18
|
export declare const RUNS_COST_UPPER_BOUND = "ALTER TABLE runs ADD COLUMN cost_upper_bound INTEGER NOT NULL DEFAULT 0 CHECK (cost_upper_bound IN (0, 1))";
|
|
19
|
+
/** A run's labels (JSON, null for none): in STORE_DDL, and added at a server open to a store an earlier build of this version
|
|
20
|
+
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
21
|
+
export declare const RUNS_LABELS: string;
|
|
19
22
|
/** A template package imported from GitHub (POST /v2/templates/import), by its id (`github:<owner>/<repo>[/<path>]`): its
|
|
20
23
|
* source as given (ref and all), the full commit SHA read, the GitHub account that publishes it, and its files as read
|
|
21
24
|
* (`files`, a JSON object of path to base64). A re-import of the id replaces the row. The server checks the files again
|
|
22
25
|
* as it loads them at its start (templates.ts readPackage); nothing in them runs. In STORE_DDL, and added at a server
|
|
23
26
|
* open to a store an earlier build of this version made. */
|
|
24
27
|
export declare const IMPORTED_TEMPLATES: string;
|
|
28
|
+
/** A hosted machine's minted token (a dial provider's create, spec/computer/attach.md): its computerd dials the attach
|
|
29
|
+
* socket and fetches the daemon with it. By the machine (its name, from its create's request id): the token's SHA-256
|
|
30
|
+
* alone (hex), what the machine must say it is at hello (kind, os, arch), and when the token ends (`expires_at`, the
|
|
31
|
+
* machine's backstop) or was revoked (its delete). A row past its end goes at the next mint. In STORE_DDL, and added at
|
|
32
|
+
* a server open to a store an earlier build of this version made. */
|
|
33
|
+
export declare const MINTED_TOKENS = "CREATE TABLE IF NOT EXISTS minted_tokens (\n machine TEXT PRIMARY KEY,\n token_sha256 TEXT NOT NULL UNIQUE,\n kind TEXT NOT NULL,\n os TEXT NOT NULL,\n arch TEXT NOT NULL,\n expires_at INTEGER NOT NULL,\n revoked_at INTEGER,\n created_at INTEGER NOT NULL\n ) STRICT";
|
|
25
34
|
export declare const STORE_DDL: readonly string[];
|
|
26
35
|
/** pi-durable's journal tables (its SqliteStorage schema, version 2, the `sleeping` task status included; MIT, see NOTICE),
|
|
27
36
|
* every one keyed by (run_id, …) with run_id leading its indexes, so one run's scans read only its rows and two runs never
|
package/dist/store/schema.js
CHANGED
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
// build of this version made and drops the table, so a revision saved before has no pin until its first run pins it.
|
|
14
14
|
// Its monid endpoints are pinned beside them (revisions.monid_pin, REVISIONS_MONID_PIN), added at a server open the same way.
|
|
15
15
|
// A run's cost says whether it is the most the run can have cost (runs.cost_upper_bound, RUNS_COST_UPPER_BOUND), added at a
|
|
16
|
-
// server open the same way.
|
|
16
|
+
// server open the same way. A run's labels (runs.labels, RUNS_LABELS) are added at a server open the same way.
|
|
17
17
|
// The template packages imported from GitHub (imported_templates) are a table of their own that nothing
|
|
18
18
|
// else reads, so it needs no version: the server adds it at its open to a store an earlier build of this version made
|
|
19
|
-
// (IMPORTED_TEMPLATES), as it does the one-answer index.
|
|
19
|
+
// (IMPORTED_TEMPLATES), as it does the one-answer index. A hosted machine's minted token (minted_tokens, MINTED_TOKENS) is
|
|
20
|
+
// added the same way.
|
|
20
21
|
// Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
|
|
21
22
|
// sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
|
|
22
23
|
// in the clear. Foreign keys are on (the connection's pragma).
|
|
@@ -50,6 +51,9 @@ const COST_UPPER_BOUND = "cost_upper_bound INTEGER NOT NULL DEFAULT 0 CHECK (cos
|
|
|
50
51
|
/** The bound beside a run's cost: in STORE_DDL, and added at a server open to a store an earlier build of this version made,
|
|
51
52
|
* as REVISIONS_MCP_PIN is (a run it ended reads 0: an exact cost or an unknown one, as it was read then). */
|
|
52
53
|
export const RUNS_COST_UPPER_BOUND = `ALTER TABLE runs ADD COLUMN ${COST_UPPER_BOUND}`;
|
|
54
|
+
/** A run's labels (JSON, null for none): in STORE_DDL, and added at a server open to a store an earlier build of this version
|
|
55
|
+
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
56
|
+
export const RUNS_LABELS = `ALTER TABLE runs ADD COLUMN ${json("labels", true)}`;
|
|
53
57
|
/** A template package imported from GitHub (POST /v2/templates/import), by its id (`github:<owner>/<repo>[/<path>]`): its
|
|
54
58
|
* source as given (ref and all), the full commit SHA read, the GitHub account that publishes it, and its files as read
|
|
55
59
|
* (`files`, a JSON object of path to base64). A re-import of the id replaces the row. The server checks the files again
|
|
@@ -63,6 +67,21 @@ export const IMPORTED_TEMPLATES = `CREATE TABLE IF NOT EXISTS imported_templates
|
|
|
63
67
|
${json("files")},
|
|
64
68
|
imported_at INTEGER NOT NULL
|
|
65
69
|
) STRICT`;
|
|
70
|
+
/** A hosted machine's minted token (a dial provider's create, spec/computer/attach.md): its computerd dials the attach
|
|
71
|
+
* socket and fetches the daemon with it. By the machine (its name, from its create's request id): the token's SHA-256
|
|
72
|
+
* alone (hex), what the machine must say it is at hello (kind, os, arch), and when the token ends (`expires_at`, the
|
|
73
|
+
* machine's backstop) or was revoked (its delete). A row past its end goes at the next mint. In STORE_DDL, and added at
|
|
74
|
+
* a server open to a store an earlier build of this version made. */
|
|
75
|
+
export const MINTED_TOKENS = `CREATE TABLE IF NOT EXISTS minted_tokens (
|
|
76
|
+
machine TEXT PRIMARY KEY,
|
|
77
|
+
token_sha256 TEXT NOT NULL UNIQUE,
|
|
78
|
+
kind TEXT NOT NULL,
|
|
79
|
+
os TEXT NOT NULL,
|
|
80
|
+
arch TEXT NOT NULL,
|
|
81
|
+
expires_at INTEGER NOT NULL,
|
|
82
|
+
revoked_at INTEGER,
|
|
83
|
+
created_at INTEGER NOT NULL
|
|
84
|
+
) STRICT`;
|
|
66
85
|
export const STORE_DDL = [
|
|
67
86
|
`CREATE TABLE IF NOT EXISTS store_meta (
|
|
68
87
|
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
@@ -147,6 +166,10 @@ export const STORE_DDL = [
|
|
|
147
166
|
-- the write-back (sign-ins-store.ts / runs.update's save decision). Null until it first leaves running. Other vendors
|
|
148
167
|
-- free the lease the instant it leaves running (no settle window), so this is read only with one.
|
|
149
168
|
left_running_at INTEGER,
|
|
169
|
+
-- The caller's labels (RunLabels): a JSON object of strings, set once with the queued run (runs.create), opaque to the
|
|
170
|
+
-- server and only filtered on (runs.list). Null when it was given none. Added at a server open to a store an earlier
|
|
171
|
+
-- build of this version made (RUNS_LABELS), its runs reading as given none.
|
|
172
|
+
${json("labels", true)},
|
|
150
173
|
started_at INTEGER NOT NULL,
|
|
151
174
|
ended_at INTEGER
|
|
152
175
|
) STRICT`,
|
|
@@ -385,6 +408,7 @@ export const STORE_DDL = [
|
|
|
385
408
|
PRIMARY KEY (agent_id, key)
|
|
386
409
|
) STRICT`,
|
|
387
410
|
IMPORTED_TEMPLATES,
|
|
411
|
+
MINTED_TOKENS,
|
|
388
412
|
// An agent's saved browser sign-ins (design 2.1, the browser sign-in rules): one live row per agent and browser provider, its
|
|
389
413
|
// pointer (the vendor's context or profile id) sealed with the store's one rule (store/seal.ts, AAD
|
|
390
414
|
// sign_ins|<agent>:<provider>|pointer), which the store never opens. The owner sees its name ("default") and saved_at,
|
|
@@ -23,6 +23,11 @@ const OPEN = new Set();
|
|
|
23
23
|
* the answers of two workers come back in no set order, so a wait that ran out then can be read before that begin's
|
|
24
24
|
* answer adds it to OPEN (lockWait). */
|
|
25
25
|
const BEGINNING = new Set();
|
|
26
|
+
/** How many interactive transactions of this process have ended on each database (`where`), counted once the worker has
|
|
27
|
+
* answered their commit or rollback. A wait whose busy answer is read after a holder of this process let go (its
|
|
28
|
+
* commit's answer read first: two workers' answers come back in no set order) finds it in neither set, yet that holder
|
|
29
|
+
* held the lock through the wait: the count moved since the wait was sent says so (lockWait). */
|
|
30
|
+
const ENDED = new Map();
|
|
26
31
|
/** `opened`'s frames: where a transaction was asked for, without the Error line itself. */
|
|
27
32
|
const framesOf = (opened) => (opened.stack ?? "").split("\n").slice(1).join("\n");
|
|
28
33
|
/** `error` with its stack naming who held the store: `opened` (its own transaction's opener, when it has one), and every
|
|
@@ -216,13 +221,15 @@ export class Connection {
|
|
|
216
221
|
* way, and the holder, once it runs again, commits or meets its deadline. A wait on another process's write, or one
|
|
217
222
|
* this process could run through, ends StoreBusy as ever.
|
|
218
223
|
* Every wait is measured, and the holder looked for when it runs out, never when it is sent: a holder's begin posted
|
|
219
|
-
* in the same turn may take the lock before its answer makes it known.
|
|
220
|
-
*
|
|
224
|
+
* in the same turn may take the lock before its answer makes it known. A holder that ended while the wait was out
|
|
225
|
+
* counts too: its commit's answer may be read before the wait's busy answer. `self`: this request's own begin
|
|
226
|
+
* (BEGINNING), never its own holder. */
|
|
221
227
|
async #lockWait(send, self) {
|
|
222
228
|
let left = this.#busyTimeoutMs;
|
|
223
229
|
for (;;) {
|
|
224
230
|
const clock = runnableDeadline(left, () => { });
|
|
225
231
|
const sent = performance.now();
|
|
232
|
+
const ended = ENDED.get(this.#where) ?? 0;
|
|
226
233
|
try {
|
|
227
234
|
return await send(left < this.#busyTimeoutMs ? left : undefined);
|
|
228
235
|
}
|
|
@@ -230,7 +237,7 @@ export class Connection {
|
|
|
230
237
|
if (!(error instanceof StoreBusy))
|
|
231
238
|
throw error;
|
|
232
239
|
const held = clock.held();
|
|
233
|
-
if (held === 0 || !this.#heldHere(self))
|
|
240
|
+
if (held === 0 || !(this.#heldHere(self) || (ENDED.get(this.#where) ?? 0) !== ended))
|
|
234
241
|
throw error;
|
|
235
242
|
left -= performance.now() - sent - held;
|
|
236
243
|
if (left <= 0)
|
|
@@ -384,6 +391,7 @@ export class Connection {
|
|
|
384
391
|
finally {
|
|
385
392
|
// Kept until the worker has answered the commit or rollback: until then this transaction still holds the lock.
|
|
386
393
|
OPEN.delete(open);
|
|
394
|
+
ENDED.set(open.where, (ENDED.get(open.where) ?? 0) + 1);
|
|
387
395
|
}
|
|
388
396
|
});
|
|
389
397
|
if (until === undefined)
|
|
@@ -43,10 +43,11 @@ export type RunRecord = {
|
|
|
43
43
|
archived_at: number | null;
|
|
44
44
|
imported_from: string | null;
|
|
45
45
|
sign_in_handed: string | null;
|
|
46
|
+
labels: string | null;
|
|
46
47
|
started_at: number;
|
|
47
48
|
ended_at: number | null;
|
|
48
49
|
};
|
|
49
|
-
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, started_at, ended_at";
|
|
50
|
+
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at";
|
|
50
51
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
51
52
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
52
53
|
export declare const EXACT_COST_USD: (alias: string) => string;
|
|
@@ -18,7 +18,7 @@ export const learningLaunchOf = (runId, model, round = 1, capUsd) => ({ harness:
|
|
|
18
18
|
/** The lock a write of a run's sign_in_handed and a sign-in's forget both take (Dialect.lockKey): the forget's check of
|
|
19
19
|
* the running runs' hashes and a launch's write of them are serialized, as SQLite's one writer serializes them. */
|
|
20
20
|
export const SIGN_IN_HANDED_LOCK = "sign_in_handed";
|
|
21
|
-
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, started_at, ended_at";
|
|
21
|
+
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at";
|
|
22
22
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
23
23
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
24
24
|
export const EXACT_COST_USD = (alias) => `CASE WHEN ${alias}.cost_upper_bound = 1 THEN NULL ELSE ${alias}.cost_usd END`;
|
|
@@ -30,7 +30,8 @@ export const runOf = (r) => ({
|
|
|
30
30
|
id: r.id, agentId: r.agent_id, revisionId: r.revision_id, state: r.state, epoch: r.epoch, runner: r.runner, claimedUntil: r.claimed_until,
|
|
31
31
|
wakeAt: r.wake_at, backoffUntil: r.backoff_until, ...costOf(r.cost_usd, r.cost_upper_bound), metrics: r.metrics === null ? null : JSON.parse(r.metrics), summary: r.summary,
|
|
32
32
|
outcome: r.outcome ?? null, archivedAt: r.archived_at, importedFrom: r.imported_from === null ? null : JSON.parse(r.imported_from),
|
|
33
|
-
signInHanded: r.sign_in_handed === null ? null : JSON.parse(r.sign_in_handed),
|
|
33
|
+
signInHanded: r.sign_in_handed === null ? null : JSON.parse(r.sign_in_handed), labels: r.labels === null ? {} : JSON.parse(r.labels),
|
|
34
|
+
startedAt: r.started_at, endedAt: r.ended_at,
|
|
34
35
|
});
|
|
35
36
|
/** Applies `patch` to the claim's run, then writes `also`, through `tx` (an open transaction's handle). Fenced, with nothing
|
|
36
37
|
* of it written once the caller rolls back, when the run's epoch is not the claim's or the claim's lease ran out before
|
|
@@ -11,7 +11,7 @@ import { backfillNativeCommandOwners, nativeCommandOwner, validConnectorId } fro
|
|
|
11
11
|
import { watchCommandsAt, wakeCommands } from "../command-wake.js";
|
|
12
12
|
import { claimFence, storeNow } from "../fence.js";
|
|
13
13
|
import { RunStorage } from "../journal/storage.js";
|
|
14
|
-
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, NATIVE_COMMANDS_INDEX, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, SCHEMA_VERSION } from "../schema.js";
|
|
14
|
+
import { COMMANDS_ONE_ANSWER, DDL, IMPORTED_TEMPLATES, MINTED_TOKENS, NATIVE_COMMANDS_INDEX, REVISIONS_MCP_PIN, REVISIONS_MONID_PIN, RUNS_COST_UPPER_BOUND, RUNS_LABELS, SCHEMA_VERSION } from "../schema.js";
|
|
15
15
|
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, RUN_CHANGES_PAGE, } from "../store.js";
|
|
16
16
|
/** The seq a run-change cursor names (Runs.changedSince): only a cursor this store handed back, a whole number. */
|
|
17
17
|
const seqOf = (cursor) => {
|
|
@@ -107,6 +107,19 @@ const triggerOf = (r) => ({
|
|
|
107
107
|
createdAt: r.created_at, updatedAt: r.updated_at,
|
|
108
108
|
});
|
|
109
109
|
const json = (value) => JSON.stringify(value ?? null);
|
|
110
|
+
/** A UTF-16 surrogate standing alone (in `u` mode a whole pair is one code point, so only a lone half matches). */
|
|
111
|
+
const LONE_SURROGATE = /[\ud800-\udfff]/u;
|
|
112
|
+
/** A run's labels as its column holds them: keys sorted, so the same labels are the same text; null for none. A key or value
|
|
113
|
+
* holding a lone surrogate is refused (TypeError), nothing written: JSON.stringify keeps it as a `\ud800` escape that
|
|
114
|
+
* Postgres' json check takes but json_each_text cannot decode, so every later label search scanning the run would fail. */
|
|
115
|
+
const labelsColumn = (labels) => {
|
|
116
|
+
for (const [key, value] of Object.entries(labels ?? {})) {
|
|
117
|
+
if (LONE_SURROGATE.test(key) || LONE_SURROGATE.test(value))
|
|
118
|
+
throw new TypeError(`a run's label ${JSON.stringify(key)} holds a lone UTF-16 surrogate: a label is whole Unicode characters`);
|
|
119
|
+
}
|
|
120
|
+
const keys = Object.keys(labels ?? {}).sort();
|
|
121
|
+
return keys.length === 0 ? null : JSON.stringify(Object.fromEntries(keys.map((key) => [key, labels[key]])));
|
|
122
|
+
};
|
|
110
123
|
/** A revision's MCP pin as its column keeps it: JSON, or null for none. */
|
|
111
124
|
const pinText = (pin) => (pin === undefined || pin === null ? null : JSON.stringify(pin));
|
|
112
125
|
const removedOf = (r) => r && { url: r.url, sealed: r.sealed === null ? null : Uint8Array.from(r.sealed) };
|
|
@@ -131,6 +144,7 @@ const settingOf = (r) => ({ key: r.key, value: JSON.parse(r.value), updatedAt: r
|
|
|
131
144
|
const sealedKeyOf = (r) => ({ name: r.name, sealed: Uint8Array.from(r.sealed), updatedAt: r.updated_at });
|
|
132
145
|
const ledgerRowOf = (r) => ({ provider: r.provider, sessionId: r.session_id, labels: JSON.parse(r.labels), detail: JSON.parse(r.detail), updatedAt: r.updated_at });
|
|
133
146
|
const pairedOf = (r) => ({ id: r.id, name: r.name, hello: JSON.parse(r.hello), driver: r.driver, labels: JSON.parse(r.labels), pairingId: r.pairing_id, createdAt: r.created_at, seenAt: r.seen_at, revokedAt: r.revoked_at });
|
|
147
|
+
const mintedOf = (r) => ({ machine: r.machine, kind: r.kind, os: r.os, arch: r.arch, expiresAt: r.expires_at, revokedAt: r.revoked_at, createdAt: r.created_at });
|
|
134
148
|
const triggerSettingOf = (r) => ({ adapter: r.adapter, scope: r.scope, field: r.field, sealed: r.sealed, updatedAt: r.updated_at });
|
|
135
149
|
const mcpOauthOf = (r) => ({ state: r.state, server: r.server, sealed: Uint8Array.from(r.sealed), working: r.working === null ? null : JSON.parse(r.working), expiresAt: r.expires_at });
|
|
136
150
|
const SIGN_IN_COLUMNS = "agent_id, provider, name, pointer_sealed, saved_at, save, verified_at";
|
|
@@ -258,12 +272,19 @@ export async function openSqliteStore(options) {
|
|
|
258
272
|
}
|
|
259
273
|
// An earlier build of this version kept no bound beside a run's cost (schema.ts RUNS_COST_UPPER_BOUND): the server adds
|
|
260
274
|
// it, every run it ended reading 0, and a runner, which writes it at each end, waits for that server.
|
|
261
|
-
const
|
|
262
|
-
if (!
|
|
275
|
+
const runColumns = new Set((await connection.all("SELECT name FROM pragma_table_info('runs')")).map((column) => column.name));
|
|
276
|
+
if (!runColumns.has("cost_upper_bound")) {
|
|
263
277
|
if (role === "runner")
|
|
264
278
|
throw new Error("Start the AgentRun server to add the bound beside each run's cost before opening a runner. The runner does not upgrade this store.");
|
|
265
279
|
await connection.write([{ sql: RUNS_COST_UPPER_BOUND }], { full: true });
|
|
266
280
|
}
|
|
281
|
+
// An earlier build of this version kept no labels on a run (schema.ts RUNS_LABELS): the server adds the column, nullable,
|
|
282
|
+
// every run it started reading as given none. A runner reads each run through it, so it waits for that server.
|
|
283
|
+
if (!runColumns.has("labels")) {
|
|
284
|
+
if (role === "runner")
|
|
285
|
+
throw new Error("Start the AgentRun server to add each run's labels before opening a runner. The runner does not upgrade this store.");
|
|
286
|
+
await connection.write([{ sql: RUNS_LABELS }], { full: true });
|
|
287
|
+
}
|
|
267
288
|
// The per-run viewer table was renamed browser_viewers → computer_viewers (schema.ts). Its rows are ephemeral, so none
|
|
268
289
|
// migrate; the server drops a stale browser_viewers an earlier build of this version left, so none lingers beside it.
|
|
269
290
|
// An earlier build of this version made no one-answer index on commands (schema.ts COMMANDS_ONE_ANSWER), or one that
|
|
@@ -285,6 +306,8 @@ export async function openSqliteStore(options) {
|
|
|
285
306
|
{ sql: COMMANDS_ONE_ANSWER },
|
|
286
307
|
// An earlier build of this version kept no imported template packages (schema.ts IMPORTED_TEMPLATES).
|
|
287
308
|
{ sql: IMPORTED_TEMPLATES },
|
|
309
|
+
// Nor any hosted machine's minted token (schema.ts MINTED_TOKENS).
|
|
310
|
+
{ sql: MINTED_TOKENS },
|
|
288
311
|
{ sql: NATIVE_COMMANDS_INDEX },
|
|
289
312
|
], { full: true });
|
|
290
313
|
await backfillNativeCommandOwners(connection);
|
|
@@ -372,6 +395,7 @@ class SqliteStore {
|
|
|
372
395
|
sealedKeys;
|
|
373
396
|
computerLedger;
|
|
374
397
|
pairedComputers;
|
|
398
|
+
mintedTokens;
|
|
375
399
|
importedTemplates;
|
|
376
400
|
triggerSettings;
|
|
377
401
|
channels;
|
|
@@ -773,15 +797,16 @@ class SqliteStore {
|
|
|
773
797
|
})),
|
|
774
798
|
};
|
|
775
799
|
this.runs = {
|
|
776
|
-
create: async ({ id, agentId, revisionId, origin }, launch) => {
|
|
800
|
+
create: async ({ id, agentId, revisionId, origin, labels }, launch) => {
|
|
777
801
|
// sign_in_handed is not written here: the runner writes it at its claim (runs.update under the epoch fence).
|
|
778
|
-
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
802
|
+
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, labels, started_at) VALUES (?, ?, ?, 'queued', 0, ?, ?) RETURNING ${RUN_COLUMNS}`;
|
|
803
|
+
const labelled = labelsColumn(labels);
|
|
779
804
|
if (origin || launch) {
|
|
780
805
|
// The run, its origin and its launch row in one transaction: the key -> run link holds even if the kept response
|
|
781
806
|
// never lands, and a run never exists without the launch it was started with.
|
|
782
807
|
return this.#queued(await db.transaction(async (tx) => {
|
|
783
808
|
const at = now();
|
|
784
|
-
const row = await tx.get(insert, id, agentId, revisionId, at);
|
|
809
|
+
const row = await tx.get(insert, id, agentId, revisionId, labelled, at);
|
|
785
810
|
if (origin)
|
|
786
811
|
await tx.run("INSERT INTO run_origins (key, run_id, fingerprint, created_at) VALUES (?, ?, ?, ?)", origin.key, id, origin.fingerprint ?? null, at);
|
|
787
812
|
if (launch)
|
|
@@ -789,11 +814,11 @@ class SqliteStore {
|
|
|
789
814
|
return runOf(row);
|
|
790
815
|
}));
|
|
791
816
|
}
|
|
792
|
-
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, now()] }]);
|
|
817
|
+
const [result] = await db.write([{ sql: insert, params: [id, agentId, revisionId, labelled, now()] }]);
|
|
793
818
|
return this.#queued(runOf(result.rows[0]));
|
|
794
819
|
},
|
|
795
820
|
createInline: async ({ agent, revision, run, launch }) => {
|
|
796
|
-
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, started_at) VALUES (?, ?, ?, 'queued', 0, ?) RETURNING ${RUN_COLUMNS}`;
|
|
821
|
+
const insert = `INSERT INTO runs (id, agent_id, revision_id, state, epoch, labels, started_at) VALUES (?, ?, ?, 'queued', 0, ?, ?) RETURNING ${RUN_COLUMNS}`;
|
|
797
822
|
const made = await db.transaction(async (tx) => {
|
|
798
823
|
const at = now();
|
|
799
824
|
// Hold the external reference, so two first uses of the same expert serialize (SQLite's one writer already does).
|
|
@@ -816,7 +841,7 @@ class SqliteStore {
|
|
|
816
841
|
await tx.run("UPDATE agents SET current_revision = ?, name = ?, description = ? WHERE id = ?", revisionId, agent.name, agent.description ?? null, mapped.id);
|
|
817
842
|
}
|
|
818
843
|
// The run, its origin and its launch, in the same transaction as the agent and the revision.
|
|
819
|
-
const row = await tx.get(insert, run.id, mapped.id, revisionId, at);
|
|
844
|
+
const row = await tx.get(insert, run.id, mapped.id, revisionId, labelsColumn(run.labels), at);
|
|
820
845
|
if (run.origin)
|
|
821
846
|
await tx.run("INSERT INTO run_origins (key, run_id, fingerprint, created_at) VALUES (?, ?, ?, ?)", run.origin.key, run.id, run.origin.fingerprint ?? null, at);
|
|
822
847
|
await writeLaunch(tx, run.id, launch, at);
|
|
@@ -830,7 +855,7 @@ class SqliteStore {
|
|
|
830
855
|
},
|
|
831
856
|
launch: (runId) => readLaunch(db, runId),
|
|
832
857
|
learningStarts: (agentId) => readLearningStarts(db, agentId, NOT_A_LEARNING_RUN),
|
|
833
|
-
list: async ({ agentId, revisionId, state, archived, limit }) => {
|
|
858
|
+
list: async ({ agentId, revisionId, state, archived, labels, limit }) => {
|
|
834
859
|
// A built-in learning run (a run's grade and merge, queued with its kept learning) is no run of a person's: no list,
|
|
835
860
|
// count, stat or notice names it.
|
|
836
861
|
const where = [NOT_A_LEARNING_RUN];
|
|
@@ -843,6 +868,9 @@ class SqliteStore {
|
|
|
843
868
|
(where.push("state = ?"), params.push(state));
|
|
844
869
|
if (archived !== undefined)
|
|
845
870
|
where.push(`archived_at IS ${archived ? "NOT NULL" : "NULL"}`);
|
|
871
|
+
// Each label, key and value bound as parameters (never spliced into a JSON path), all of them held.
|
|
872
|
+
for (const [key, value] of Object.entries(labels ?? {}))
|
|
873
|
+
(where.push(d.jsonObjectHas("labels")), params.push(key, value));
|
|
846
874
|
const bounded = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0;
|
|
847
875
|
if (bounded)
|
|
848
876
|
params.push(limit);
|
|
@@ -1362,6 +1390,32 @@ class SqliteStore {
|
|
|
1362
1390
|
return (result?.changes ?? 0) === 1;
|
|
1363
1391
|
},
|
|
1364
1392
|
};
|
|
1393
|
+
const MINTED = "SELECT machine, kind, os, arch, expires_at, revoked_at, created_at FROM minted_tokens";
|
|
1394
|
+
this.mintedTokens = {
|
|
1395
|
+
// A mint for a machine that has one replaces it: its older token dials no more.
|
|
1396
|
+
mint: async ({ machine, tokenSha256, kind, os, arch, expiresAt }) => {
|
|
1397
|
+
const at = now();
|
|
1398
|
+
await db.write([
|
|
1399
|
+
{ sql: "DELETE FROM minted_tokens WHERE expires_at <= ?", params: [at] },
|
|
1400
|
+
{
|
|
1401
|
+
sql: "INSERT INTO minted_tokens (machine, token_sha256, kind, os, arch, expires_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT (machine) DO UPDATE SET token_sha256 = excluded.token_sha256, kind = excluded.kind, os = excluded.os, arch = excluded.arch, expires_at = excluded.expires_at, revoked_at = NULL, created_at = excluded.created_at",
|
|
1402
|
+
params: [machine, tokenSha256, kind, os, arch, expiresAt, at],
|
|
1403
|
+
},
|
|
1404
|
+
]);
|
|
1405
|
+
},
|
|
1406
|
+
byToken: async (tokenSha256) => {
|
|
1407
|
+
const row = await db.get(`${MINTED} WHERE token_sha256 = ? AND revoked_at IS NULL AND expires_at > ?`, tokenSha256, now());
|
|
1408
|
+
return row === undefined ? undefined : mintedOf(row);
|
|
1409
|
+
},
|
|
1410
|
+
get: async (machine) => {
|
|
1411
|
+
const row = await db.get(`${MINTED} WHERE machine = ?`, machine);
|
|
1412
|
+
return row === undefined ? undefined : mintedOf(row);
|
|
1413
|
+
},
|
|
1414
|
+
revoke: async (machine) => {
|
|
1415
|
+
const [result] = await db.write([{ sql: "UPDATE minted_tokens SET revoked_at = ? WHERE machine = ? AND revoked_at IS NULL", params: [now(), machine] }]);
|
|
1416
|
+
return (result?.changes ?? 0) === 1;
|
|
1417
|
+
},
|
|
1418
|
+
};
|
|
1365
1419
|
this.importedTemplates = {
|
|
1366
1420
|
list: async () => (await db.all("SELECT id, source, sha, publisher, files, imported_at FROM imported_templates ORDER BY id")).map((row) => ({
|
|
1367
1421
|
id: row.id, source: row.source, sha: row.sha, publisher: row.publisher, files: JSON.parse(row.files), importedAt: row.imported_at,
|
package/dist/store/store.d.ts
CHANGED
|
@@ -129,6 +129,9 @@ export interface RunOrigin {
|
|
|
129
129
|
readonly key: string;
|
|
130
130
|
readonly fingerprint?: string | null;
|
|
131
131
|
}
|
|
132
|
+
/** A run's labels: a small map of the caller's own strings, set once at its start, never read by the server (only
|
|
133
|
+
* filtered on). Bounds: run-labels.ts. */
|
|
134
|
+
export type RunLabels = Readonly<Record<string, string>>;
|
|
132
135
|
export interface RunRow {
|
|
133
136
|
readonly id: string;
|
|
134
137
|
readonly agentId: string;
|
|
@@ -158,6 +161,8 @@ export interface RunRow {
|
|
|
158
161
|
/** The SHA-256 hashes of the browser sign-in pointers handed to the run at its launch (never the pointers), or null when
|
|
159
162
|
* it was handed none. A sign-in whose pointer hashes to one of these cannot be forgotten while the run runs. */
|
|
160
163
|
readonly signInHanded: readonly string[] | null;
|
|
164
|
+
/** The caller's labels, given at its start (RunLabels): opaque to the server, kept as given, {} when none. */
|
|
165
|
+
readonly labels: RunLabels;
|
|
161
166
|
readonly startedAt: number;
|
|
162
167
|
readonly endedAt: number | null;
|
|
163
168
|
}
|
|
@@ -774,6 +779,7 @@ export interface Runs {
|
|
|
774
779
|
agentId: string;
|
|
775
780
|
revisionId: string;
|
|
776
781
|
origin?: RunOrigin;
|
|
782
|
+
labels?: RunLabels;
|
|
777
783
|
}, launch?: RunLaunchInput): Promise<RunRow>;
|
|
778
784
|
/** A run whose agent is given inline and mapped to a source system by `agent.ref` and `revision.version`. In one
|
|
779
785
|
* transaction: the agent (one per `ref`, written on its first run, its name and description brought up to the version
|
|
@@ -801,6 +807,7 @@ export interface Runs {
|
|
|
801
807
|
run: {
|
|
802
808
|
id: string;
|
|
803
809
|
origin?: RunOrigin;
|
|
810
|
+
labels?: RunLabels;
|
|
804
811
|
};
|
|
805
812
|
launch: RunLaunchInput;
|
|
806
813
|
}): Promise<RunRow>;
|
|
@@ -817,12 +824,13 @@ export interface Runs {
|
|
|
817
824
|
learning: unknown;
|
|
818
825
|
}[]>;
|
|
819
826
|
/** Newest first, at most `limit` (no limit: all). `archived` filters on the run's own archive time (true: archived,
|
|
820
|
-
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. */
|
|
827
|
+
* false: not); its agent's archive is read apart. A built-in learning run (one a kept learning names) is never listed. `labels`: only runs holding every one of these labels, key and value. */
|
|
821
828
|
list(filter: {
|
|
822
829
|
agentId?: string;
|
|
823
830
|
revisionId?: string;
|
|
824
831
|
state?: RunState;
|
|
825
832
|
archived?: boolean;
|
|
833
|
+
labels?: RunLabels;
|
|
826
834
|
limit?: number;
|
|
827
835
|
}): Promise<RunRow[]>;
|
|
828
836
|
/** Archives the run (its own archive time), or unarchives it: idempotent. */
|
|
@@ -1239,6 +1247,33 @@ export interface PairedComputers {
|
|
|
1239
1247
|
/** Removes the computer: its token dials no more. False when it was not paired (unknown, or removed already). */
|
|
1240
1248
|
revoke(id: string): Promise<boolean>;
|
|
1241
1249
|
}
|
|
1250
|
+
/** A hosted machine's minted token (store schema `minted_tokens`): what the machine must say it is at hello, and the
|
|
1251
|
+
* token's life. The token is not here: the store keeps its SHA-256 alone. */
|
|
1252
|
+
export interface MintedTokenRow {
|
|
1253
|
+
/** The machine's name (from its create's request id): its id in the attach hub. */
|
|
1254
|
+
readonly machine: string;
|
|
1255
|
+
readonly kind: string;
|
|
1256
|
+
readonly os: string;
|
|
1257
|
+
readonly arch: string;
|
|
1258
|
+
/** When the token ends: the machine's backstop. */
|
|
1259
|
+
readonly expiresAt: number;
|
|
1260
|
+
/** When it was revoked (the machine's delete); null while it is good. */
|
|
1261
|
+
readonly revokedAt: number | null;
|
|
1262
|
+
readonly createdAt: number;
|
|
1263
|
+
}
|
|
1264
|
+
/** The tokens minted for hosted machines that dial this server (a dial provider's create, spec/computer/attach.md). */
|
|
1265
|
+
export interface MintedTokens {
|
|
1266
|
+
/** Keeps the token's SHA-256 for `machine`, replacing one minted for it before. Rows past their end go in the same write. */
|
|
1267
|
+
mint(token: Pick<MintedTokenRow, "machine" | "kind" | "os" | "arch" | "expiresAt"> & {
|
|
1268
|
+
readonly tokenSha256: string;
|
|
1269
|
+
}): Promise<void>;
|
|
1270
|
+
/** The row whose token has this SHA-256, while it is good: neither revoked nor past its end. */
|
|
1271
|
+
byToken(tokenSha256: string): Promise<MintedTokenRow | undefined>;
|
|
1272
|
+
/** The machine's row, good or not; undefined when it has none (never minted, or gone past its end). */
|
|
1273
|
+
get(machine: string): Promise<MintedTokenRow | undefined>;
|
|
1274
|
+
/** Revokes the machine's token. False when it had none good. */
|
|
1275
|
+
revoke(machine: string): Promise<boolean>;
|
|
1276
|
+
}
|
|
1242
1277
|
/** A template package imported from GitHub (store schema `imported_templates`, POST /v2/templates/import): its id
|
|
1243
1278
|
* (`github:<owner>/<repo>[/<path>]`), its source as given, the commit SHA read, its publisher (the GitHub account), and
|
|
1244
1279
|
* its files as they were read, by path, base64. The server checks them again (templates.ts readPackage) as it loads them
|
|
@@ -1475,6 +1510,8 @@ export interface Store {
|
|
|
1475
1510
|
readonly computerLedger: ComputerLedger;
|
|
1476
1511
|
/** The people's own machines paired with this server, and the codes that pair them (spec/computer/attach.md). */
|
|
1477
1512
|
readonly pairedComputers: PairedComputers;
|
|
1513
|
+
/** The tokens minted for hosted machines that dial this server, each kept as its SHA-256. */
|
|
1514
|
+
readonly mintedTokens: MintedTokens;
|
|
1478
1515
|
/** The template packages imported from GitHub, their files kept as read. */
|
|
1479
1516
|
readonly importedTemplates: ImportedTemplates;
|
|
1480
1517
|
/** Each trigger source's sealed settings (design 2.1): a value per adapter, scope and field. */
|