@parcha/agentrun-serve 0.1.0-beta.51 → 0.1.0-beta.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +94 -13
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +10 -4
- package/dist/api-only.d.ts +4 -2
- package/dist/api-only.js +5 -3
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/index-DlQepP2J.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +5 -0
- package/dist/learning-words.js +5 -0
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +1 -1
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/openapi.js +45 -12
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +13 -4
- package/dist/run-launch.js +14 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +1 -1
- package/dist/run-view.js +3 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +12 -9
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +13 -13
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +12 -11
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/harness-loops.js +5 -2
- package/dist/runner/journal-kinds.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +47 -22
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.js +6 -4
- package/dist/runner/runner.js +15 -3
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +3 -3
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +5 -2
- package/dist/runs-over-store.js +14 -7
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.js +81 -65
- package/dist/server.js +84 -20
- package/dist/store/agent-body.d.ts +4 -0
- package/dist/store/agent-body.js +4 -1
- package/dist/store/index.d.ts +1 -1
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/schema.d.ts +14 -1
- package/dist/store/schema.js +42 -4
- package/dist/store/sqlite/run-launch.d.ts +22 -0
- package/dist/store/sqlite/run-launch.js +72 -7
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.js +141 -29
- package/dist/store/store-schema.js +2 -2
- package/dist/store/store.d.ts +67 -4
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +3 -0
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tools.js +1 -1
- package/dist/uploads-archil.js +2 -1
- package/dist/uploads.d.ts +0 -3
- package/dist/uploads.js +2 -11
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/dist/console/assets/index-Bt1B51b7.js +0 -733
- package/dist/console/assets/index-sVftE9Ht.css +0 -1
package/dist/server.js
CHANGED
|
@@ -29,7 +29,7 @@ import { existsSync } from "node:fs";
|
|
|
29
29
|
import { rm } from "node:fs/promises";
|
|
30
30
|
import { homedir, hostname } from "node:os";
|
|
31
31
|
import { pinFirst as pinFirstOf } from "./mcp-pin-first.js";
|
|
32
|
-
import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, etagOf, externalKey, getAgent, listAgents, makeRevision, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
|
|
32
|
+
import { agentRevision, agentRevisions, agentView, commitAgent, createAgent, etagOf, externalKey, getAgent, listAgents, makeRevision, ownedElsewhere, refuseExternal, revisionView, setAgentArchived, setCurrentRevision } from "./agents-store.js";
|
|
33
33
|
import { WORKFLOW_ADAPTERS } from "./runner/workflow-adapters.js";
|
|
34
34
|
import { DECISION_ADAPTER, decisionsOf, FAUX_JEV_ENV, FAUX_OPENROUTER_ENV, FAUX_PARALLEL_ENV, fauxFetch } from "./decisions.js";
|
|
35
35
|
import { FAUX_WEB_ENV } from "./web-fetch-direct.js";
|
|
@@ -49,7 +49,7 @@ import { DEFAULT_PORT, healthOf, hostMemory, maxRunsOf, runsThatFit } from "./ho
|
|
|
49
49
|
import { DEFAULT_HOST, elsewhereOf, listenOn, minFreeMibOf, takeOver, urlOf } from "./listen-first.js";
|
|
50
50
|
import { IMPORT_ASKED, MAX_CANDIDATES } from "./import.js";
|
|
51
51
|
import { answerStoreCall } from "./import-proxy.js";
|
|
52
|
-
import { LEARNING_LABEL, learningFolderOf, secretsShown, learningOf, learnsOf, RUN_LEARNING_USE, seedOf } from "./learning.js";
|
|
52
|
+
import { LEARNING_LABEL, learningFolderOf, secretsShown, learningOf, learnsOf, RUN_LEARNING_USE, seedOf, withAgentRepo } from "./learning.js";
|
|
53
53
|
import { askReplay, ReplayRefused, replayView } from "./runner/promotion.js";
|
|
54
54
|
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite, learningLog, pendingCount, readLearnedFile, sendText, statusesOf, textBody, workflowAtDigest, workflowRevisions } from "./learning-routes.js";
|
|
55
55
|
import { answerLlms, MCP_PATH, mcpEndpoint } from "./mcp.js";
|
|
@@ -97,6 +97,7 @@ import { openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned
|
|
|
97
97
|
import { agentDeleting, answerOf, logged, purgedAgent } from "./agents.js";
|
|
98
98
|
import { keepGrade } from "./runner/feedback-round.js";
|
|
99
99
|
import { gradeRow, notAuditableOf } from "./runner/audit.js";
|
|
100
|
+
import { namedDisksOf } from "./learn/learning-of.js";
|
|
100
101
|
import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
|
|
101
102
|
import { auditLoopOf, COMPILE_AFTER_MAX } from "./learning-setting.js";
|
|
102
103
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
@@ -198,7 +199,8 @@ import { computerOfPlace } from "./computer-setting.js";
|
|
|
198
199
|
import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
|
|
199
200
|
import { fauxComputers } from "./faux-computers.js";
|
|
200
201
|
import { writesHeld } from "./workspace.js";
|
|
201
|
-
import { deleteExternalAgent, oneAtATime, purgeAgent, purgeRun, purgingKey } from "./agent-delete.js";
|
|
202
|
+
import { deleteExternalAgent, oneAtATime, purgeAgent, purgedAgain, purgeRun, purgingKey } from "./agent-delete.js";
|
|
203
|
+
import { resetLearning } from "./learning-reset.js";
|
|
202
204
|
import { agentComputerHoldKey } from "./workspace/agent-computer.js";
|
|
203
205
|
import { sdkRunKey } from "./sdk/runs.js";
|
|
204
206
|
import { waitEndedKey } from "./browser-wait-ended.js";
|
|
@@ -494,6 +496,8 @@ export const ROUTES = [
|
|
|
494
496
|
// Answered before routing (mcp.ts), with the token only: listed here for the document.
|
|
495
497
|
{ method: "POST", pattern: /^\/mcp$/, name: "callMcp" },
|
|
496
498
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning$/, name: "getAgentLearning" },
|
|
499
|
+
// The agent's learning reset, the agent and its runs kept (learning-reset.ts).
|
|
500
|
+
{ method: "DELETE", pattern: /^\/agents\/([^/]+)\/learning$/, name: "deleteAgentLearning" },
|
|
497
501
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/cost$/, name: "getLearningCost" },
|
|
498
502
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/promotions$/, name: "listLearningPromotions" },
|
|
499
503
|
{ method: "GET", pattern: /^\/agents\/([^/]+)\/learning\/audits$/, name: "listLearningAudits" },
|
|
@@ -2318,11 +2322,42 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2318
2322
|
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. ${again}`, { retry_after_ms: 5_000 });
|
|
2319
2323
|
}
|
|
2320
2324
|
};
|
|
2325
|
+
/** The Archil disks agent `agentId`'s learning folder may be on: a Mode 2 run's end writes it on the disk its claim
|
|
2326
|
+
* mounted (workspace/learning-workspace.ts, at learningKey), the agent's stored disk (named here only for
|
|
2327
|
+
* `agentDisk`) or one a launch named (kind "launch", a customer's: each run's disk, learn/learning-of.ts namedDisksOf,
|
|
2328
|
+
* read off its row, so a purged run whose launch is gone still names it). A run's kept disk, or a launch's kind
|
|
2329
|
+
* "agent", is the agent's own disk, mounted only while it is still the stored one (workspace/run-disk.ts runDiskOf):
|
|
2330
|
+
* one no longer stored was removed at Archil, its folder with it. */
|
|
2331
|
+
const learningDisksOf = async (agentId, agentDisk) => {
|
|
2332
|
+
const disks = new Set();
|
|
2333
|
+
const stored = agentDisk ? await agentDiskOf(store, agentId) : undefined;
|
|
2334
|
+
if (stored)
|
|
2335
|
+
disks.add(stored.diskId);
|
|
2336
|
+
for (const disk of await namedDisksOf(store, agentId))
|
|
2337
|
+
disks.add(disk);
|
|
2338
|
+
return [...disks];
|
|
2339
|
+
};
|
|
2340
|
+
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete over the agent's
|
|
2341
|
+
* learning folder on this server's disk, as the learning routes open it (learningFolderOf), which deleteLearning ends
|
|
2342
|
+
* in its finally, and over its folder on each Archil disk a launch of its runs named and, for a reset (`agentDisk`),
|
|
2343
|
+
* on its own disk, which the agent's delete removes whole in step 3 (archil-routes.ts removeLearningFolder; Archil
|
|
2344
|
+
* off or refusing is 503 unavailable, nothing here deleted, for the next call). */
|
|
2345
|
+
const learningDelete = options.deleteLearning ?? ((given, agentId, { keepResetLedger = false, agentDisk = false } = {}) => deleteLearning(given, agentId, learningFolderOf(data, agentId), {
|
|
2346
|
+
keepResetLedger,
|
|
2347
|
+
elsewhere: async () => {
|
|
2348
|
+
for (const diskId of await learningDisksOf(agentId, agentDisk)) {
|
|
2349
|
+
try {
|
|
2350
|
+
await archil.removeLearningFolder(agentId, diskId);
|
|
2351
|
+
}
|
|
2352
|
+
catch (error) {
|
|
2353
|
+
if (!(error instanceof ApiError && ["unavailable", "upstream_failed"].includes(error.code)))
|
|
2354
|
+
throw error;
|
|
2355
|
+
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. The agent's learning folder on this server and its learning records are kept: send the DELETE again once it can be reached.`, { retry_after_ms: 5_000 });
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
},
|
|
2359
|
+
}));
|
|
2321
2360
|
/** What DELETE /agents/{id} does outside the store's rows, on this server (agent-delete.ts AgentDeleteHost). */
|
|
2322
|
-
/** Step 2 of DELETE /agents/{id}: the learning module's delete over the agent's learning folder on this server's disk,
|
|
2323
|
-
* as the learning routes open it (learningFolderOf), which deleteLearning ends in its finally. A learning folder on
|
|
2324
|
-
* the agent's Archil disk goes with that disk in step 3. */
|
|
2325
|
-
const learningDelete = options.deleteLearning ?? ((given, agentId) => deleteLearning(given, agentId, learningFolderOf(data, agentId)));
|
|
2326
2361
|
const agentDeleteHost = {
|
|
2327
2362
|
store,
|
|
2328
2363
|
deleteLearning: learningDelete,
|
|
@@ -2374,8 +2409,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2374
2409
|
// DELETE. A run on its agent's own disk: with its agent's delete that disk went whole (removeDisk), its folder with
|
|
2375
2410
|
// it; deleted alone, its folder there is deleted, the disk kept, read from its disk setting, which goes after.
|
|
2376
2411
|
const launched = await store.runs.launch(runId).then((row) => readLaunchBody(row.body)?.archilDisk, (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
|
|
2377
|
-
|
|
2412
|
+
// The agent's learning folder there too: a Mode 2 end wrote the run's diff and correction in it, and nothing reads it.
|
|
2413
|
+
if (launched?.kind === "launch") {
|
|
2378
2414
|
await notYetWith(() => archil.removeRunFolder(agentId, runId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
2415
|
+
await notYetWith(() => archil.removeLearningFolder(agentId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
2416
|
+
}
|
|
2379
2417
|
else if (alone) {
|
|
2380
2418
|
const own = launched?.diskId ?? (await runDiskKept(store, runId));
|
|
2381
2419
|
if (own)
|
|
@@ -2421,6 +2459,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2421
2459
|
pollMs: 200,
|
|
2422
2460
|
...(options.agentDeleteAt ? { at: options.agentDeleteAt } : {}),
|
|
2423
2461
|
};
|
|
2462
|
+
/** What DELETE /agents/{id}/learning does outside the learning module (learning-reset.ts): the agent delete's learning
|
|
2463
|
+
* step, cancel path and wait, and the agent's learning queue, where a run's start reads its seed. */
|
|
2464
|
+
const learningResetHost = {
|
|
2465
|
+
store,
|
|
2466
|
+
deleteLearning: learningDelete,
|
|
2467
|
+
cancel: agentDeleteHost.cancel,
|
|
2468
|
+
inQueue: (agentId, work) => withAgentRepo(data, agentId, work),
|
|
2469
|
+
waitMs: agentDeleteHost.waitMs,
|
|
2470
|
+
pollMs: agentDeleteHost.pollMs,
|
|
2471
|
+
};
|
|
2424
2472
|
// A run's live moment from the store (store-view momentOf), for the one acceptance each act a run takes reads. The run
|
|
2425
2473
|
// routes read from the store + the run view now, not a live Run.
|
|
2426
2474
|
async function needRun(id) {
|
|
@@ -2663,7 +2711,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2663
2711
|
return undefined;
|
|
2664
2712
|
try {
|
|
2665
2713
|
return mcpPinOf(granted, { server: (name) => { const kept = carried.get(name); if (kept)
|
|
2666
|
-
return kept; const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices }; } });
|
|
2714
|
+
return kept; const listing = listings.get(name); return listing && { url: listing.url, tools: listing.tools.map(boundTool), prices: listing.prices, toolkit: listing.toolkit }; } });
|
|
2667
2715
|
}
|
|
2668
2716
|
catch (error) {
|
|
2669
2717
|
throw invalid([{ field: "definition.tools", reason: "not_an_option", message: error.message }]);
|
|
@@ -3029,8 +3077,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3029
3077
|
// (catchup_window_s and max_active_runs the package leaves out back to their defaults, as a fresh apply makes them); a new name is made; one the package
|
|
3030
3078
|
// marked and no longer lists is removed (`removing`). Each trigger the apply makes or keeps is marked as the package's; each write to one the agent had is made only while it
|
|
3031
3079
|
// is still the agent's: one a PATCH moved away meanwhile is neither changed nor removed, and its name is made anew.
|
|
3032
|
-
// Each trigger it made or kept, in the package's order, as it stands after its write: the answer's
|
|
3033
|
-
//
|
|
3080
|
+
// Each trigger it made or kept, in the package's order, as it stands after its write: the answer's triggers (its id,
|
|
3081
|
+
// its name, its kind, and whether it is on).
|
|
3034
3082
|
const answered = [];
|
|
3035
3083
|
const list = (view) => answered.push({ trigger_id: view.id, name: view.name, kind: view.source.kind, enabled: view.enabled });
|
|
3036
3084
|
// The triggers this apply made (never one it changed in place): what a refusal's undo removes.
|
|
@@ -3152,7 +3200,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3152
3200
|
// What the apply did to the agent: made it, wrote a new revision, or wrote none (an update whose package and
|
|
3153
3201
|
// parameters the current revision already holds: commitAgent keeps that revision).
|
|
3154
3202
|
const agentChange = !onto ? "made" : entry.revision?.id === onto.revision?.id ? "unchanged" : "updated";
|
|
3155
|
-
const applied = { template: pkg.id, version: pkg.version, agent_id: entry.agent.id, revision_version: entry.version, agent_change: agentChange, servers: used,
|
|
3203
|
+
const applied = { template: pkg.id, version: pkg.version, agent_id: entry.agent.id, revision_version: entry.version, agent_change: agentChange, servers: used, triggers: answered, ...templateWebhookSecrets([...minted.keys()], new Date().toISOString()), warnings: [...skipped, ...kept, ...modelWarnings, ...computerWarnings, ...unpinned, ...warnings, ...hooks, ...githubTriggers, ...composioSkipped, ...feedsSkipped, ...leftThere, ...appShort, ...twins] };
|
|
3156
3204
|
return { applied, minted, updated: onto !== undefined };
|
|
3157
3205
|
}
|
|
3158
3206
|
/** A run create's issues told from the input this server checks (explain.ts): an agentic run's input schema in force
|
|
@@ -4091,13 +4139,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4091
4139
|
authFailed(`/v2${path}`, "approve_without_session");
|
|
4092
4140
|
throw new ApiError("forbidden", owner ? "Answering a tool call's approval takes the owner's password sign-in in the console, never a token." : "Answering a tool call's approval takes the owner's password sign-in, and this server has no accounts (AGENTRUN_ACCOUNTS=0).");
|
|
4093
4141
|
}
|
|
4094
|
-
// Purging a run or an agent,
|
|
4095
|
-
// token. A console session counts as the owner's only where it does for a secret
|
|
4096
|
-
// loopback-bound server); bound off loopback with accounts off, whoever opened the
|
|
4097
|
-
// credential at all it is 401, as every route is.
|
|
4098
|
-
if ((found.name === "deleteRun" || found.name === "deleteAgent") && byConsoleSession(req) && !writesSecretsAllowed(req, { accounts: owner !== undefined, loopbackBound: isLoopback(host) })) {
|
|
4142
|
+
// Purging a run or an agent, deleting another system's agent, or resetting an agent's learning cannot be undone: the
|
|
4143
|
+
// owner's session or the API token. A console session counts as the owner's only where it does for a secret
|
|
4144
|
+
// (secret-writes.ts: accounts off on a loopback-bound server); bound off loopback with accounts off, whoever opened the
|
|
4145
|
+
// console is no owner. With no credential at all it is 401, as every route is.
|
|
4146
|
+
if ((found.name === "deleteRun" || found.name === "deleteAgent" || found.name === "deleteAgentLearning") && byConsoleSession(req) && !writesSecretsAllowed(req, { accounts: owner !== undefined, loopbackBound: isLoopback(host) })) {
|
|
4099
4147
|
authFailed(`/v2${path}`, "delete_without_owner");
|
|
4100
|
-
throw new ApiError("forbidden", "Deleting a run or an agent takes the owner's session (the password sign-in, or the console on a server bound to loopback) or the API token.");
|
|
4148
|
+
throw new ApiError("forbidden", "Deleting a run or an agent, or resetting an agent's learning, takes the owner's session (the password sign-in, or the console on a server bound to loopback) or the API token.");
|
|
4101
4149
|
}
|
|
4102
4150
|
// Saving, replacing or removing a secret (secret-writes.ts): the one check. Who may is mayWriteSecrets' alone (the
|
|
4103
4151
|
// owner's session); which writes are secret is each plane's registered predicate, read from the body, so a token's
|
|
@@ -4429,8 +4477,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4429
4477
|
await deleteInTurn(id, async () => {
|
|
4430
4478
|
const { agent } = await needAgent(id);
|
|
4431
4479
|
if (agent.purgedAt !== null)
|
|
4432
|
-
return;
|
|
4433
|
-
if (agent
|
|
4480
|
+
return purgedAgain(agentDeleteHost, id);
|
|
4481
|
+
if (ownedElsewhere(agent))
|
|
4434
4482
|
return deleteExternalAgent(agentDeleteHost, id);
|
|
4435
4483
|
if (agent.archivedAt === null)
|
|
4436
4484
|
throw new ApiError("agent_not_archived", `The agent ${id} is not archived: archive it first (POST /v2/agents/${id}/archive), which stops new runs and turns its triggers off, then send the DELETE again. Nothing was purged.`);
|
|
@@ -4556,6 +4604,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4556
4604
|
const row = ID.test(id) ? await store.runs.get(id) : undefined;
|
|
4557
4605
|
if (!row)
|
|
4558
4606
|
throw new ApiError("not_found", `no run ${id}`);
|
|
4607
|
+
// API-only (api-only.ts): a run of an agent another system owns alone, for the backend whose inline runs made it,
|
|
4608
|
+
// as it deletes that agent; a run of an agent made here is the profile's refusal, in its words, as before.
|
|
4609
|
+
if (options.apiOnly) {
|
|
4610
|
+
const agent = await store.agents.get(row.agentId);
|
|
4611
|
+
if (!agent || !ownedElsewhere(agent))
|
|
4612
|
+
throw new ApiError("not_found", apiOnlyRefusal(`/v2${path}`));
|
|
4613
|
+
}
|
|
4559
4614
|
await deleteInTurn(row.agentId, () => purgeRun(agentDeleteHost, id));
|
|
4560
4615
|
res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
4561
4616
|
return void res.end();
|
|
@@ -5303,6 +5358,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5303
5358
|
const written = await agentWrite(id, () => correctionsWrite(data, id, { text, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse }));
|
|
5304
5359
|
return send(res, 200, written, { etag: written.etag });
|
|
5305
5360
|
}
|
|
5361
|
+
case "deleteAgentLearning": {
|
|
5362
|
+
// The agent's learning reset (learning-reset.ts), a write to its learning: in its delete turn (agentWrite), which
|
|
5363
|
+
// reads the agent there (404 unknown) and refuses one being deleted.
|
|
5364
|
+
await agentWrite(id, () => resetLearning(learningResetHost, id));
|
|
5365
|
+
// A run's list row that read a workflow of the agent's says what the folder says now, at the next list.
|
|
5366
|
+
await lister.learningChanged(id);
|
|
5367
|
+
res.writeHead(204, { "cache-control": "no-store", "x-content-type-options": "nosniff" });
|
|
5368
|
+
return void res.end();
|
|
5369
|
+
}
|
|
5306
5370
|
case "listLearnedWorkflowRevisions":
|
|
5307
5371
|
await needAgent(id);
|
|
5308
5372
|
return send(res, 200, await workflowRevisions(data, id, second, url.searchParams, await learningShown(id)));
|
|
@@ -88,6 +88,7 @@ export type AgenticBody = {
|
|
|
88
88
|
learning?: LearningSetting;
|
|
89
89
|
toolSettings?: ToolSettings;
|
|
90
90
|
maxCostUsd?: number;
|
|
91
|
+
maxRequests?: number;
|
|
91
92
|
approvals?: "ask" | "never";
|
|
92
93
|
inputSchema?: Record<string, unknown>;
|
|
93
94
|
outputSchema?: Record<string, unknown>;
|
|
@@ -102,6 +103,7 @@ export type WorkflowBody = {
|
|
|
102
103
|
computer?: RevisionComputer;
|
|
103
104
|
toolSettings?: ToolSettings;
|
|
104
105
|
maxCostUsd?: number;
|
|
106
|
+
maxRequests?: number;
|
|
105
107
|
approvals?: "ask" | "never";
|
|
106
108
|
};
|
|
107
109
|
/** The input a revision's body is built from (the control plane's, in the store's own shape). `toolSettings` is already
|
|
@@ -124,6 +126,7 @@ export type RevisionBodyInput = {
|
|
|
124
126
|
learning?: LearningSetting;
|
|
125
127
|
toolSettings?: ToolSettings;
|
|
126
128
|
maxCostUsd?: number;
|
|
129
|
+
maxRequests?: number;
|
|
127
130
|
approvals?: "ask" | "never";
|
|
128
131
|
inputSchema?: Record<string, unknown>;
|
|
129
132
|
outputSchema?: Record<string, unknown>;
|
|
@@ -138,6 +141,7 @@ export type RevisionBodyInput = {
|
|
|
138
141
|
computer?: unknown;
|
|
139
142
|
toolSettings?: ToolSettings;
|
|
140
143
|
maxCostUsd?: number;
|
|
144
|
+
maxRequests?: number;
|
|
141
145
|
approvals?: "ask" | "never";
|
|
142
146
|
};
|
|
143
147
|
/** The body of a new revision and the text of each skill it names (path to text), everything checked here, before any
|
package/dist/store/agent-body.js
CHANGED
|
@@ -113,7 +113,10 @@ export function bodyOf(input) {
|
|
|
113
113
|
// A default spend cap, for a revision of either kind.
|
|
114
114
|
if (input.maxCostUsd !== undefined && !(typeof input.maxCostUsd === "number" && Number.isFinite(input.maxCostUsd) && input.maxCostUsd > 0))
|
|
115
115
|
invalid("the maxCostUsd is not a number above 0");
|
|
116
|
-
|
|
116
|
+
// The agent's own limit on each run's requests on free models (definition.max_requests), under the server's.
|
|
117
|
+
if (input.maxRequests !== undefined && !(typeof input.maxRequests === "number" && Number.isSafeInteger(input.maxRequests) && input.maxRequests >= 1))
|
|
118
|
+
invalid("the maxRequests is not a whole number above 0");
|
|
119
|
+
const capped = { ...(input.maxCostUsd !== undefined ? { maxCostUsd: input.maxCostUsd } : {}), ...(input.maxRequests !== undefined ? { maxRequests: input.maxRequests } : {}) };
|
|
117
120
|
// Whether the agent runs unattended (its definition.approvals): "never" lets an ask run without a person, for a revision
|
|
118
121
|
// of either kind. "ask" (the default, as an agent read says it) is taken and kept as no value, so the default stays
|
|
119
122
|
// implicit and a definition put back as it reads is the same revision; "never" is kept.
|
package/dist/store/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunnerBelowFloor, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
|
|
2
|
-
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerIntervalRow, ComputerIntervals, 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, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, StoreSchemaState, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, PurgeKept, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
2
|
+
export type { ConstraintRule, AgentRow, Agents, AlsoRow, AttemptCause, ChannelPost, Claim, Command, ComputerIntervalRow, ComputerIntervals, 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, RunAttemptRow, RunAttempts, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, StoreSchemaState, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, PurgeKept, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
3
3
|
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunLaunch, openRunMcpAuth, type RunLaunchSecrets, type ComposioBinding, type RunMcpAuth, type RunMcpEntry, type RunModelKey, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunLaunch, 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";
|
|
@@ -21,6 +21,8 @@ interface SqliteExecutor {
|
|
|
21
21
|
get<R extends object>(sql: string, ...params: SqliteValue[]): Promise<R | undefined>;
|
|
22
22
|
all<R extends object>(sql: string, ...params: SqliteValue[]): Promise<R[]>;
|
|
23
23
|
}
|
|
24
|
+
/** A run's first id to mint: pi's root conversation is 1. */
|
|
25
|
+
export declare const JOURNAL_FIRST_ID = 2;
|
|
24
26
|
type StoredTask = TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
25
27
|
/** A document a commit changed, as the live view reads it: its value at that seq, or `retired` with none. */
|
|
26
28
|
export type JournalDocument = {
|
|
@@ -14,7 +14,8 @@ function readsOf(db) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
/** A run's first id to mint: pi's root conversation is 1. */
|
|
17
|
-
const
|
|
17
|
+
export const JOURNAL_FIRST_ID = 2;
|
|
18
|
+
const FIRST_ID = JOURNAL_FIRST_ID;
|
|
18
19
|
const parseJson = (value) => JSON.parse(String(value));
|
|
19
20
|
const encodeJson = (value) => JSON.stringify(value);
|
|
20
21
|
// Some SQLite bindings replace lone UTF-16 surrogates. JSON encoding keeps indexed identities lossless.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 25: each claim of a run, with the turn it works and its attempt at it, as
|
|
2
|
+
-- store/schema.ts keeps it on SQLite (RUN_ATTEMPTS). Applied once, after 0024, inside the transaction migrate.ts opens.
|
|
3
|
+
-- Never edit this file once applied: a change is a new file. Additive: a runner of version 24 never reads it, and a claim
|
|
4
|
+
-- it makes has no row.
|
|
5
|
+
--
|
|
6
|
+
-- run_attempts: one row per claim (run_id, epoch), written in the claim's own transaction: the turn it works and its
|
|
7
|
+
-- attempt at it, why the attempt before was cut (cause: drain, crash, lease_lapse, retry; null on a turn's first), why
|
|
8
|
+
-- this claim let the run go unfinished (cut, written by its release or its runner's lost lease), its runner, the run's
|
|
9
|
+
-- state it took the run from, the first journal entry id it could write and when it claimed. Data only: the usage read
|
|
10
|
+
-- splits a run's cost by it. Made only where missing, so a store whose record of this file was lost applies it again
|
|
11
|
+
-- unharmed.
|
|
12
|
+
|
|
13
|
+
CREATE TABLE IF NOT EXISTS run_attempts (
|
|
14
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
15
|
+
epoch BIGINT NOT NULL,
|
|
16
|
+
turn BIGINT NOT NULL CHECK (turn >= 1),
|
|
17
|
+
attempt BIGINT NOT NULL CHECK (attempt >= 1),
|
|
18
|
+
cause TEXT COLLATE "C" CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),
|
|
19
|
+
cut TEXT COLLATE "C" CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),
|
|
20
|
+
runner TEXT COLLATE "C" NOT NULL,
|
|
21
|
+
from_state TEXT COLLATE "C" NOT NULL,
|
|
22
|
+
journal_from BIGINT NOT NULL,
|
|
23
|
+
claimed_at BIGINT NOT NULL,
|
|
24
|
+
PRIMARY KEY (run_id, epoch)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
UPDATE store_meta SET schema_version = 25 WHERE singleton = 1;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Version 26: a run's disk (runs.disk, as store/schema.ts keeps it on SQLite): the disk the run's launch named as its own
|
|
2
|
+
-- (a customer's Archil disk, by its id), set once with the queued run; null for the default disk's. Learning reads an
|
|
3
|
+
-- agent's runs on one disk alone. Every run already here takes its disk from its launch body, as a new run's is taken at
|
|
4
|
+
-- its create; a run purged before this (0021) has no launch body left, so it reads as the default disk's, with nothing
|
|
5
|
+
-- of it left to learn from. Applied once, after 0025, inside the transaction migrate.ts opens. Never edit this file once
|
|
6
|
+
-- applied: a change is a new file.
|
|
7
|
+
--
|
|
8
|
+
-- The disk is read from a copy of each body that names one, its escaped NULs and surrogates (\u0000, \ud800-\udfff) read
|
|
9
|
+
-- as escaped spaces: Postgres's json functions refuse a whole document over one, and a run's input may hold one. A
|
|
10
|
+
-- replaced escape stays an escape (an escaped backslash before u0000 keeps its own), so the copy is still JSON, and only
|
|
11
|
+
-- the disk's id and kind are read from it (an Archil disk id holds neither).
|
|
12
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS disk TEXT COLLATE "C";
|
|
13
|
+
UPDATE runs SET disk = launch.disk_id
|
|
14
|
+
FROM (
|
|
15
|
+
SELECT run_id, readable #>> '{archil_disk,disk_id}' AS disk_id, readable #>> '{archil_disk,kind}' AS kind
|
|
16
|
+
FROM (
|
|
17
|
+
SELECT run_id, regexp_replace(body, '\\u(0000|[dD][89a-fA-F][0-9a-fA-F]{2})', '\\u0020', 'g')::json AS readable
|
|
18
|
+
FROM run_launch
|
|
19
|
+
WHERE strpos(body, '"archil_disk"') > 0
|
|
20
|
+
) AS bodies
|
|
21
|
+
) AS launch
|
|
22
|
+
WHERE launch.run_id = runs.id AND launch.kind = 'launch';
|
|
23
|
+
UPDATE store_meta SET schema_version = 26 WHERE singleton = 1;
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SCHEMA_VERSION =
|
|
1
|
+
export declare const SCHEMA_VERSION = 15;
|
|
2
2
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
3
3
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
4
4
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
@@ -19,6 +19,11 @@ export declare const RUNS_COST_UPPER_BOUND = "ALTER TABLE runs ADD COLUMN cost_u
|
|
|
19
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
20
|
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
21
21
|
export declare const RUNS_LABELS: string;
|
|
22
|
+
/** Version 14 → 15 on SQLite (the server's open, sqlite/store.ts), given the runs' columns now: each run's disk
|
|
23
|
+
* (RunRow.disk), written for every run already there from its launch body, as a new run's is at its create, and the
|
|
24
|
+
* version, in one durable write. A run whose launch named no disk of its own reads as the default disk's, and so does a
|
|
25
|
+
* run purged before (its launch body gone): nothing of it is left to learn from. */
|
|
26
|
+
export declare function diskUpgrade(runColumns: ReadonlySet<string>): readonly string[];
|
|
22
27
|
/** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
|
|
23
28
|
* for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
|
|
24
29
|
* RUNS_LABELS is (a trigger made before reads as no package's). */
|
|
@@ -83,6 +88,14 @@ export declare const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at O
|
|
|
83
88
|
export declare const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
|
|
84
89
|
/** How long a hand-back's row is kept: the longest window the capacity read takes. */
|
|
85
90
|
export declare const HAND_BACKS_KEPT_MS: number;
|
|
91
|
+
/** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
|
|
92
|
+
* was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
|
|
93
|
+
* (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
|
|
94
|
+
* (`journal_from`) and when it claimed. Written in the claim's own transaction, its cut in its release's. Data only:
|
|
95
|
+
* the usage read (run-usage.ts) splits a run's cost by it, and nothing decides what a run does on it. In STORE_DDL, and
|
|
96
|
+
* added at a server open to a store an earlier build of this version made, as COMPUTER_INTERVALS is: a claim made before
|
|
97
|
+
* it has no row. */
|
|
98
|
+
export declare const RUN_ATTEMPTS = "CREATE TABLE IF NOT EXISTS run_attempts (\n run_id TEXT NOT NULL,\n epoch INTEGER NOT NULL,\n turn INTEGER NOT NULL CHECK (turn >= 1),\n attempt INTEGER NOT NULL CHECK (attempt >= 1),\n cause TEXT CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),\n cut TEXT CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),\n runner TEXT NOT NULL,\n from_state TEXT NOT NULL,\n journal_from INTEGER NOT NULL,\n claimed_at INTEGER NOT NULL,\n PRIMARY KEY (run_id, epoch)\n ) STRICT";
|
|
86
99
|
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
87
100
|
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
88
101
|
export declare function purgeUpgrade(runColumns: ReadonlySet<string>, agentColumns: ReadonlySet<string>): readonly string[];
|
package/dist/store/schema.js
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
// (IMPORTED_TEMPLATES), as it does the one-answer index. A hosted machine's minted token (minted_tokens, MINTED_TOKENS) is
|
|
21
21
|
// added the same way, and so is each runner's word that it is there and whether it refused to claim (runners, RUNNERS),
|
|
22
22
|
// and each computer a run made, from its create to its proven delete (computer_intervals, COMPUTER_INTERVALS). Each runner's
|
|
23
|
-
// version and slots (runners.version, .slots: RUNNERS_ADDED)
|
|
23
|
+
// version and slots (runners.version, .slots: RUNNERS_ADDED), each hand-back (hand_backs, HAND_BACKS) and each claim of a
|
|
24
|
+
// run with the turn it works and its attempt at it (run_attempts, RUN_ATTEMPTS) are added the same way.
|
|
24
25
|
// Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
|
|
25
26
|
// sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
|
|
26
27
|
// in the clear. Foreign keys are on (the connection's pragma).
|
|
@@ -36,9 +37,10 @@
|
|
|
36
37
|
// .incarnation), the run the machine works for (.run), why the server refused to relay its dial (.refused), and where each
|
|
37
38
|
// such runner takes the dials the server relays to it (runners.host and .port, dial-relay.ts). Version 14 keeps when a run or
|
|
38
39
|
// an agent was purged (runs.purged_at, agents.purged_at; DELETE /runs/{id} and /agents/{id}, agent-delete.ts): its row is
|
|
39
|
-
// then a tombstone, its content gone and its cost kept.
|
|
40
|
-
//
|
|
41
|
-
|
|
40
|
+
// then a tombstone, its content gone and its cost kept. Version 15 keeps the disk a run's launch named as its own
|
|
41
|
+
// (runs.disk; a run on one learns nothing, learn/learning-of.ts). The server upgrades these in place at its open
|
|
42
|
+
// (listingUpgrade from 11, relayUpgrade from 12, purgeUpgrade from 13, then diskUpgrade from 14); a runner waits for it.
|
|
43
|
+
export const SCHEMA_VERSION = 15;
|
|
42
44
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
43
45
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
44
46
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
@@ -64,6 +66,17 @@ export const RUNS_COST_UPPER_BOUND = `ALTER TABLE runs ADD COLUMN ${COST_UPPER_B
|
|
|
64
66
|
/** 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
|
|
65
67
|
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
66
68
|
export const RUNS_LABELS = `ALTER TABLE runs ADD COLUMN ${json("labels", true)}`;
|
|
69
|
+
/** Version 14 → 15 on SQLite (the server's open, sqlite/store.ts), given the runs' columns now: each run's disk
|
|
70
|
+
* (RunRow.disk), written for every run already there from its launch body, as a new run's is at its create, and the
|
|
71
|
+
* version, in one durable write. A run whose launch named no disk of its own reads as the default disk's, and so does a
|
|
72
|
+
* run purged before (its launch body gone): nothing of it is left to learn from. */
|
|
73
|
+
export function diskUpgrade(runColumns) {
|
|
74
|
+
return [
|
|
75
|
+
...(runColumns.has("disk") ? [] : ["ALTER TABLE runs ADD COLUMN disk TEXT"]),
|
|
76
|
+
"UPDATE runs SET disk = (SELECT json_extract(body, '$.archil_disk.disk_id') FROM run_launch WHERE run_launch.run_id = runs.id AND json_extract(body, '$.archil_disk.kind') = 'launch')",
|
|
77
|
+
"UPDATE store_meta SET schema_version = 15 WHERE singleton = 1",
|
|
78
|
+
];
|
|
79
|
+
}
|
|
67
80
|
/** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
|
|
68
81
|
* for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
|
|
69
82
|
* RUNS_LABELS is (a trigger made before reads as no package's). */
|
|
@@ -183,6 +196,26 @@ export const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at ON hand_b
|
|
|
183
196
|
export const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
|
|
184
197
|
/** How long a hand-back's row is kept: the longest window the capacity read takes. */
|
|
185
198
|
export const HAND_BACKS_KEPT_MS = 24 * 60 * 60_000;
|
|
199
|
+
/** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
|
|
200
|
+
* was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
|
|
201
|
+
* (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
|
|
202
|
+
* (`journal_from`) and when it claimed. Written in the claim's own transaction, its cut in its release's. Data only:
|
|
203
|
+
* the usage read (run-usage.ts) splits a run's cost by it, and nothing decides what a run does on it. In STORE_DDL, and
|
|
204
|
+
* added at a server open to a store an earlier build of this version made, as COMPUTER_INTERVALS is: a claim made before
|
|
205
|
+
* it has no row. */
|
|
206
|
+
export const RUN_ATTEMPTS = `CREATE TABLE IF NOT EXISTS run_attempts (
|
|
207
|
+
run_id TEXT NOT NULL,
|
|
208
|
+
epoch INTEGER NOT NULL,
|
|
209
|
+
turn INTEGER NOT NULL CHECK (turn >= 1),
|
|
210
|
+
attempt INTEGER NOT NULL CHECK (attempt >= 1),
|
|
211
|
+
cause TEXT CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),
|
|
212
|
+
cut TEXT CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),
|
|
213
|
+
runner TEXT NOT NULL,
|
|
214
|
+
from_state TEXT NOT NULL,
|
|
215
|
+
journal_from INTEGER NOT NULL,
|
|
216
|
+
claimed_at INTEGER NOT NULL,
|
|
217
|
+
PRIMARY KEY (run_id, epoch)
|
|
218
|
+
) STRICT`;
|
|
186
219
|
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
187
220
|
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
188
221
|
export function purgeUpgrade(runColumns, agentColumns) {
|
|
@@ -380,6 +413,10 @@ export const STORE_DDL = [
|
|
|
380
413
|
-- server and only filtered on (runs.list). Null when it was given none. Added at a server open to a store an earlier
|
|
381
414
|
-- build of this version made (RUNS_LABELS), its runs reading as given none.
|
|
382
415
|
${json("labels", true)},
|
|
416
|
+
-- The disk the run's launch named as its own (RunRow.disk: a customer's Archil disk, by its id), set once with the queued
|
|
417
|
+
-- run from its launch body; null for the default disk's. Learning reads an agent's runs on one disk alone. Version 15
|
|
418
|
+
-- (diskUpgrade): added then and written from each run's launch. A purge keeps it on the run's tombstone.
|
|
419
|
+
disk TEXT,
|
|
383
420
|
started_at INTEGER NOT NULL,
|
|
384
421
|
ended_at INTEGER,
|
|
385
422
|
-- The run's listing (RUN_LISTING_COLUMNS): what a runs list shows of it, kept on its row so a list reads rows alone.
|
|
@@ -634,6 +671,7 @@ export const STORE_DDL = [
|
|
|
634
671
|
HAND_BACKS_RUN,
|
|
635
672
|
COMPUTER_INTERVALS,
|
|
636
673
|
COMPUTER_INTERVALS_RUN,
|
|
674
|
+
RUN_ATTEMPTS,
|
|
637
675
|
// An agent's saved browser sign-ins (design 2.1, the browser sign-in rules): one live row per agent and browser provider, its
|
|
638
676
|
// pointer (the vendor's context or profile id) sealed with the store's one rule (store/seal.ts, AAD
|
|
639
677
|
// sign_ins|<agent>:<provider>|pointer), which the store never opens. The owner sees its name ("default") and saved_at,
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { type LaunchSealed, type RunLaunchInput, type RunLaunchRow, type Runs } from "../store.js";
|
|
2
2
|
import type { Dialect } from "../dialect.js";
|
|
3
3
|
import type { SqliteExecutor } from "./connection.js";
|
|
4
|
+
export { postgresReadableJson, postgresUnicodeRefusal };
|
|
5
|
+
/** JSON text `column` as a read of one id or flag out of it inside a transaction takes it, where a refused statement
|
|
6
|
+
* aborts the transaction and can't be read again: on Postgres its copy with those escapes blanked (postgresReadableJson),
|
|
7
|
+
* on SQLite (whose json functions read them) the column itself. */
|
|
8
|
+
export declare const readableJson: (dialect: Dialect, column: string) => string;
|
|
4
9
|
/** Writes a run's launch row inside `tx` (the same transaction as the queued run it belongs to): the run path and the
|
|
5
10
|
* trigger path both call it, so the row lands with its run or not at all. */
|
|
6
11
|
export declare function writeLaunch(tx: Pick<SqliteExecutor, "run">, runId: string, launch: RunLaunchInput, at: number): Promise<void>;
|
|
12
|
+
/** The disk a launch body names as the run's own (runs.disk, RunRow.disk): its `archil_disk` of kind "launch", by its id
|
|
13
|
+
* (run-launch.ts launchBody writes it so); null for none, or its agent's own disk (the default disk). The one read of the
|
|
14
|
+
* body's disk the store makes, at every create of a run, so no path that queues a run can leave it out. */
|
|
15
|
+
export declare function launchDiskOf(launch: RunLaunchInput | undefined): string | null;
|
|
7
16
|
/** A message's launch secrets written over the run's (runs.command, runs.reopen), inside `tx`: the bytes as given, or a
|
|
8
17
|
* function's answer to the bytes the launch holds now, read in the same transaction. */
|
|
9
18
|
export declare function writeLaunchSealed(tx: Pick<SqliteExecutor, "run" | "get">, runId: string, launchSealed: LaunchSealed): Promise<void>;
|
|
10
19
|
/** The run's launch row, read by the runner at its claim (and the server for views). StoreLaunchMissing when the run has
|
|
11
20
|
* none, never a default. */
|
|
12
21
|
export declare function readLaunch(executor: Pick<SqliteExecutor, "get">, runId: string): Promise<RunLaunchRow>;
|
|
22
|
+
/** Whether `error` (or a cause of it, six deep) is Postgres refusing a JSON document for an escaped NUL or a lone
|
|
23
|
+
* surrogate in it: the text type keeps them, but every json function decodes the whole document's strings. */
|
|
24
|
+
declare function postgresUnicodeRefusal(error: unknown): boolean;
|
|
25
|
+
/** Postgres SQL for JSON text `column` with its escaped NULs and surrogates (\u0000, \ud800-\udfff) read as escaped
|
|
26
|
+
* spaces, for a read of one number or id out of a document whose other strings may hold one (0026_run_disk.sql blanks
|
|
27
|
+
* them for its backfill). A replaced escape stays an escape, so it is still JSON. Only an escape is replaced: u0000 after
|
|
28
|
+
* an escaped backslash (the text \u0000 in an id, written \\u0000) is text and is kept, so an id reads as it is. */
|
|
29
|
+
declare const postgresReadableJson: (column: string) => string;
|
|
13
30
|
/** Project accounting facts before crossing the database boundary. An SDK inbox can contain megabytes of replay;
|
|
14
31
|
* the raw-JSON projection preserves strings, nulls and invalid scalar shapes equally on SQLite and Postgres.
|
|
15
32
|
* Uses an ordinary store connection: a PostgreSQL Unicode refusal is retried outside a failed transaction. */
|
|
@@ -28,3 +45,8 @@ export declare function readLearningStarts(executor: Pick<SqliteExecutor, "all">
|
|
|
28
45
|
runId: string;
|
|
29
46
|
learning: unknown;
|
|
30
47
|
}[]>;
|
|
48
|
+
/** The ids of agent `agentId`'s runs started after `at` whose learning seed was read at or before it (the launch body's
|
|
49
|
+
* `learning.seededAt`), in one read of that one number a run started after `at`: never a run's section or input. */
|
|
50
|
+
export declare function readSeededBefore(executor: Pick<SqliteExecutor, "all"> & {
|
|
51
|
+
readonly dialect: Dialect;
|
|
52
|
+
}, agentId: string, at: number): Promise<string[]>;
|