@parcha/agentrun-serve 0.1.0-beta.59 → 0.1.0-beta.61
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 +135 -0
- package/README.md +230 -120
- package/dist/acp-package.d.ts +4 -0
- package/dist/agent-delete.d.ts +6 -9
- package/dist/agent-delete.js +5 -3
- package/dist/agent-package.js +11 -1
- package/dist/api-only.d.ts +21 -3
- package/dist/api-only.js +41 -6
- package/dist/archil-routes.d.ts +4 -1
- package/dist/archil-routes.js +15 -12
- package/dist/archil-settings.d.ts +18 -8
- package/dist/archil-settings.js +35 -17
- package/dist/browser-person.d.ts +1 -1
- package/dist/browser-person.js +1 -1
- package/dist/calendar/tools.js +1 -1
- package/dist/chatgpt-plan.d.ts +4 -2
- package/dist/chatgpt-plan.js +13 -3
- package/dist/claude-login-token.d.ts +5 -0
- package/dist/claude-login-token.js +8 -0
- package/dist/claude-login.d.ts +49 -3
- package/dist/claude-login.js +140 -10
- package/dist/cli-learning/connections.js +1 -1
- package/dist/cli.js +42 -10
- package/dist/console/assets/{backend-BztxEAvb.js → backend-C9ffXUR5.js} +1 -1
- package/dist/console/assets/index-BnZV3lvW.js +639 -0
- package/dist/console/assets/{share-L84tlUDW.js → share-B1o5mJ56.js} +2 -2
- package/dist/console/assets/{styles-CaRKlHke.js → styles-D_znYrHR.js} +31 -31
- package/dist/console/assets/styles-fjQBFfMv.css +1 -0
- package/dist/console/index.html +3 -3
- package/dist/console/share.html +3 -3
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/factory-activity.d.ts +68 -0
- package/dist/factory-activity.js +153 -0
- package/dist/factory-runs.d.ts +11 -0
- package/dist/factory-runs.js +52 -0
- package/dist/filed-tool.d.ts +32 -0
- package/dist/filed-tool.js +122 -0
- package/dist/harness-check.js +2 -1
- package/dist/harness-keys.d.ts +1 -2
- package/dist/harness-keys.js +1 -2
- package/dist/harness-recipe.d.ts +13 -2
- package/dist/harness-recipe.js +30 -7
- package/dist/harness-sign-in.js +2 -1
- package/dist/harness-table.d.ts +9 -3
- package/dist/harness-table.js +11 -5
- package/dist/harness.js +6 -2
- package/dist/import-worker.js +2 -2
- package/dist/import.d.ts +9 -0
- package/dist/import.js +11 -1
- package/dist/key-refusal.d.ts +5 -0
- package/dist/key-refusal.js +30 -18
- package/dist/learn/audit.d.ts +20 -22
- package/dist/learn/audit.js +72 -55
- package/dist/learn/check.js +1 -1
- package/dist/learn/commit.d.ts +35 -43
- package/dist/learn/commit.js +62 -270
- package/dist/learn/compile.d.ts +4 -4
- package/dist/learn/compile.js +6 -7
- package/dist/learn/corrections.js +1 -1
- package/dist/learn/delete.d.ts +5 -12
- package/dist/learn/delete.js +17 -30
- package/dist/learn/forget-run.d.ts +16 -0
- package/dist/learn/forget-run.js +53 -0
- package/dist/learn/index.js +1 -1
- package/dist/learn/learning-of.d.ts +0 -4
- package/dist/learn/learning-of.js +0 -5
- package/dist/learn/{folder.d.ts → legacy/folder.d.ts} +2 -1
- package/dist/learn/{folder.js → legacy/folder.js} +4 -7
- package/dist/learn/legacy/place.d.ts +16 -0
- package/dist/{workspace/learning-workspace.js → learn/legacy/place.js} +12 -42
- package/dist/learn/legacy/scrub.d.ts +28 -0
- package/dist/learn/legacy/scrub.js +258 -0
- package/dist/learn/promote.d.ts +40 -66
- package/dist/learn/promote.js +69 -207
- package/dist/learn/reset-ledger.d.ts +18 -0
- package/dist/learn/reset-ledger.js +14 -0
- package/dist/learn/rows.d.ts +186 -0
- package/dist/learn/rows.js +376 -0
- package/dist/learn/secrets.d.ts +2 -1
- package/dist/learn/secrets.js +2 -2
- package/dist/learn/workflow-draft.d.ts +4 -1
- package/dist/learn/workflow-draft.js +12 -2
- package/dist/learned-nodes.d.ts +36 -0
- package/dist/learned-nodes.js +23 -0
- package/dist/learning-reset.d.ts +1 -1
- package/dist/learning-reset.js +9 -11
- package/dist/learning-routes.d.ts +60 -81
- package/dist/learning-routes.js +187 -360
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +2 -0
- package/dist/learning.d.ts +18 -24
- package/dist/learning.js +35 -66
- package/dist/local-model.d.ts +144 -0
- package/dist/local-model.js +214 -0
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +44 -8
- package/dist/mcp-probe.d.ts +7 -0
- package/dist/mcp-probe.js +7 -0
- package/dist/mcp-resources.d.ts +1 -1
- package/dist/native/discovery.d.ts +6 -0
- package/dist/native/discovery.js +14 -1
- package/dist/native/remote.d.ts +5 -0
- package/dist/native/remote.js +16 -0
- package/dist/native/runtime.js +3 -2
- package/dist/observation/observer.d.ts +6 -6
- package/dist/ollama-provider.d.ts +35 -0
- package/dist/ollama-provider.js +108 -2
- package/dist/openapi.js +147 -35
- package/dist/place-offers.d.ts +3 -0
- package/dist/place-offers.js +3 -0
- package/dist/place.d.ts +35 -12
- package/dist/place.js +67 -29
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +0 -33
- package/dist/purged-workflow.js +3 -71
- package/dist/redact/match.d.ts +36 -8
- package/dist/redact/match.js +179 -44
- package/dist/run-export.js +4 -2
- package/dist/run-launch.d.ts +3 -3
- package/dist/run-learning-served.d.ts +3 -3
- package/dist/run-learning-served.js +1 -1
- package/dist/run-listing.d.ts +1 -1
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +6 -5
- package/dist/run-usage.js +3 -2
- package/dist/runnable.js +25 -8
- package/dist/runner/adapter-loop.d.ts +8 -1
- package/dist/runner/adapter-loop.js +100 -20
- package/dist/runner/adapter-run-spec.d.ts +3 -5
- package/dist/runner/adapter-run-spec.js +35 -61
- package/dist/runner/adapters/pi.d.ts +3 -2
- package/dist/runner/adapters/pi.js +3 -1
- package/dist/runner/audit.d.ts +3 -5
- package/dist/runner/audit.js +28 -51
- package/dist/runner/cli-run-spec.js +19 -22
- package/dist/runner/compare-end.d.ts +1 -3
- package/dist/runner/compare-end.js +6 -2
- package/dist/runner/disk-free.d.ts +15 -4
- package/dist/runner/disk-free.js +25 -7
- package/dist/runner/dispatch.js +2 -2
- package/dist/runner/feedback-round.d.ts +1 -1
- package/dist/runner/feedback-round.js +2 -2
- package/dist/runner/harness-loops.d.ts +9 -0
- package/dist/runner/harness-loops.js +49 -7
- package/dist/runner/held.d.ts +4 -11
- package/dist/runner/held.js +0 -25
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +1 -1
- package/dist/runner/learned-first.d.ts +0 -2
- package/dist/runner/learned-first.js +3 -3
- package/dist/runner/learning-end.d.ts +12 -16
- package/dist/runner/learning-end.js +41 -75
- package/dist/runner/learning-seed.d.ts +13 -16
- package/dist/runner/learning-seed.js +13 -23
- package/dist/runner/live-ticker.js +3 -4
- package/dist/runner/main.js +1 -1
- package/dist/runner/mcp-claim.js +3 -2
- package/dist/runner/mcp-run.d.ts +23 -4
- package/dist/runner/mcp-run.js +31 -2
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -3
- package/dist/runner/monid-run.js +3 -1
- package/dist/runner/native-loop.js +3 -4
- package/dist/runner/promotion.d.ts +19 -28
- package/dist/runner/promotion.js +50 -69
- package/dist/runner/redact.d.ts +3 -0
- package/dist/runner/redact.js +7 -0
- package/dist/runner/reflect-hook.d.ts +2 -2
- package/dist/runner/reflect-hook.js +4 -1
- package/dist/runner/run-child-host.d.ts +1 -9
- package/dist/runner/run-child-host.js +12 -68
- package/dist/runner/runner.d.ts +1 -1
- package/dist/runner/sdk-loop.js +7 -7
- package/dist/runner/workflow-calls.d.ts +4 -1
- package/dist/runner/workflow-calls.js +35 -18
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +3 -1
- package/dist/runner/workflow-spec.d.ts +4 -0
- package/dist/runner/workflow-spec.js +18 -13
- package/dist/runs-over-store.d.ts +2 -2
- package/dist/runs-over-store.js +1 -1
- package/dist/sdk/check.d.ts +1 -4
- package/dist/sdk/check.js +2 -3
- package/dist/sdk/runs.d.ts +20 -7
- package/dist/sdk/runs.js +105 -68
- package/dist/secret-cut.js +7 -4
- package/dist/secret-rules.js +97 -83
- package/dist/secrets.d.ts +4 -0
- package/dist/secrets.js +44 -10
- package/dist/server-fs.d.ts +1 -1
- package/dist/server-fs.js +1 -1
- package/dist/server-keys.d.ts +6 -0
- package/dist/server-keys.js +12 -0
- package/dist/server.d.ts +22 -15
- package/dist/server.js +311 -198
- package/dist/slack.js +2 -1
- package/dist/source-sync/auxiliary.js +2 -2
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrate.js +3 -1
- package/dist/store/postgres/migrations/0032_learning_rows.sql +65 -0
- package/dist/store/schema.d.ts +28 -2
- package/dist/store/schema.js +81 -5
- package/dist/store/sqlite/learning-rows.d.ts +23 -0
- package/dist/store/sqlite/learning-rows.js +559 -0
- package/dist/store/sqlite/store.d.ts +7 -1
- package/dist/store/sqlite/store.js +84 -18
- package/dist/store/store.d.ts +219 -6
- package/dist/store/store.js +13 -0
- package/dist/store-reads/journal.d.ts +33 -3
- package/dist/store-reads/journal.js +99 -4
- package/dist/store-reads/learning.d.ts +23 -26
- package/dist/store-reads/learning.js +42 -30
- package/dist/store-reads/loop.js +1 -1
- package/dist/store-view.d.ts +24 -2
- package/dist/store-view.js +40 -11
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +31 -4
- package/dist/tool-plane.d.ts +27 -3
- package/dist/tool-plane.js +79 -4
- package/dist/tools.d.ts +12 -2
- package/dist/tools.js +42 -7
- package/dist/trigger-launch-hook.d.ts +2 -2
- package/dist/trigger-launch-hook.js +1 -1
- package/dist/triggers.d.ts +7 -4
- package/dist/triggers.js +4 -4
- package/dist/web-holds.d.ts +2 -0
- package/dist/web-holds.js +5 -2
- package/dist/web-run.js +2 -1
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.d.ts +1 -1
- package/dist/workspace/archil.js +1 -1
- package/dist/workspace/computer-deps.js +5 -3
- package/dist/workspace/computer-providers.d.ts +11 -1
- package/dist/workspace/computer-providers.js +29 -2
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/paths.d.ts +0 -4
- package/dist/workspace/paths.js +0 -6
- package/dist/workspace/workspace.d.ts +1 -1
- package/dist/workspace/workspace.js +1 -1
- package/package.json +13 -13
- package/templates/TOOLS.md +46 -0
- package/dist/console/assets/index-LwNL4L9q.js +0 -619
- package/dist/console/assets/styles-DQo8rzY-.css +0 -1
- package/dist/workspace/learning-workspace.d.ts +0 -24
- /package/dist/learn/{learning.sh → legacy/learning.sh} +0 -0
package/dist/server.js
CHANGED
|
@@ -16,7 +16,7 @@ import { ObservationLearning } from "./observation/learning.js";
|
|
|
16
16
|
import { cliLearningOf } from "./store/agent-body.js";
|
|
17
17
|
import { maintainObservations, Observations } from './observation/observer.js';
|
|
18
18
|
import { isObservationRoute, observationHttp } from './observation/http.js';
|
|
19
|
-
import { SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
19
|
+
import { forgetSdkCopies, SDK_MAX_OPEN_MS, SdkRuns, sdkOf, sdkRunSecret } from "./sdk/runs.js";
|
|
20
20
|
import { learningModelOf } from "./learning-model.js";
|
|
21
21
|
import { answerSkill } from './skill-route.js';
|
|
22
22
|
import { RemoteConnectors, verifyRemote, REMOTE_COMPLETION_BODY_BYTES } from './native/remote.js';
|
|
@@ -31,7 +31,7 @@ import { createHash, createHmac, randomBytes, randomUUID } from "node:crypto";
|
|
|
31
31
|
import { chmod, lstat, mkdir, readFile, realpath, rename, stat, writeFile } from "node:fs/promises";
|
|
32
32
|
import { createServer } from "node:http";
|
|
33
33
|
import proxyaddr from "proxy-addr";
|
|
34
|
-
import {
|
|
34
|
+
import { apiOnlyMcpSave, apiOnlyRefusal, apiOnlyTriggerEdit, apiOnlyTriggerSkipped, apiOnlyTurnsOn, servedApiOnly } from "./api-only.js";
|
|
35
35
|
import { API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV } from "./env-switch.js";
|
|
36
36
|
import { composioOutsideNamespaceServers, holdApiOnlyMcpOrigins, offApiOnlyMcpServers } from "./mcp-api-only-origins.js";
|
|
37
37
|
import { declaredKeys, keysOwed, keysOwedRefusal, runKeysOf, runKeysTriggerSkipped, undeclaredKeys, withCarried } from "./run-keys.js";
|
|
@@ -65,15 +65,15 @@ import { HARNESS_MODULES_ENV, HARNESS_MODULES_SETTING, HARNESS_RECIPES_ENV, HARN
|
|
|
65
65
|
import { claudeCliIn, HarnessInstall, installDirOf, NPM_STOP_GRACE_MS, npmInstall } from "./harness-install.js";
|
|
66
66
|
import { DEFAULT_PORT, healthOf, hostMemory, maxRunsOf, runsThatFit } from "./host.js";
|
|
67
67
|
import { DEFAULT_HOST, elsewhereOf, listenOn, minFreeMibOf, takeOver, urlOf } from "./listen-first.js";
|
|
68
|
-
import { IMPORT_ASKED, MAX_CANDIDATES } from "./import.js";
|
|
68
|
+
import { IMPORT_ASKED, IMPORT_HEAP_MB, MAX_CANDIDATES } from "./import.js";
|
|
69
69
|
import { answerStoreCall } from "./import-proxy.js";
|
|
70
|
-
import {
|
|
70
|
+
import { inLearningQueue, LEARNING_LABEL, secretsShown, learningOf, learnsOf, RUN_LEARNING_USE, seedOf } from "./learning.js";
|
|
71
71
|
import { askReplay, ReplayRefused, replayView } from "./runner/promotion.js";
|
|
72
|
-
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite,
|
|
73
|
-
import { purgedRun
|
|
72
|
+
import { agentLearning, changeWorkflow, correctionsView, correctionsWrite, learningLog, pendingCount, readLearnedFile, sendText, statusesOf, textBody, workflowAtDigest, workflowRevisions } from "./learning-routes.js";
|
|
73
|
+
import { purgedRun } from "./purged-workflow.js";
|
|
74
74
|
import { answerLlms, MCP_PATH, mcpEndpoint } from "./mcp.js";
|
|
75
75
|
import { openapiDocument, servedOpenapi, UNSUPPORTED } from "./openapi.js";
|
|
76
|
-
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, placesOf, resolvePlace } from "./place.js";
|
|
76
|
+
import { boxAvailability, boxesLine, defaultPlaceOf, NEW_AGENT_TOOLS, newAgentPlace, noBoxReason, noBoxRefusal, placesOf, resolvePlace } from "./place.js";
|
|
77
77
|
import { boxAllowOf, boxAllowSetIn } from "./box-settings.js";
|
|
78
78
|
import { dockerLimitsOf } from "./workspace/computer-deps.js";
|
|
79
79
|
import { Owner, passwordProblem, SESSION_MS } from "./owner.js";
|
|
@@ -91,7 +91,7 @@ import { screenWaitEnded } from "./browser-wait-ended.js";
|
|
|
91
91
|
import { durationMs, logLine } from "./print.js";
|
|
92
92
|
import { keepPresence, refusedEnd, runnersRefused } from "./runner/presence.js";
|
|
93
93
|
import { approve, archiveRun, cancel, message, pause as pauseRunOverStore, prepareLaunch, raiseCap, resume as resumeRunOverStore, startInline, startRun, stop as stopRunOverStore } from "./runs-over-store.js";
|
|
94
|
-
import { builtOfNow, factsOverStore, listedItem, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
94
|
+
import { builtOfNow, factsOverStore, keptFactory, listedItem, liveOf, lookingBackEnd, momentOverStore, summaryOverStore, timelineOverStore, toolsUsdOverStore, viewOverStore, withheldOverStore } from "./store-view.js";
|
|
95
95
|
import { healEndedCosts } from "./cost-heal.js";
|
|
96
96
|
import { reconcileProjectCheckpoints } from "./source-sync/checkpoints.js";
|
|
97
97
|
import { acknowledgeProjects } from "./source-sync/checkpoint-gate.js";
|
|
@@ -113,25 +113,28 @@ import { ExportFailed, restoreIdsOf, runExport } from "./run-export.js";
|
|
|
113
113
|
import { triggerTargets } from "./trigger-targets.js";
|
|
114
114
|
import { labelFilter, labelsIssues } from "./run-labels.js";
|
|
115
115
|
import { listRuns as listRunsOverStore, readRun as readRunOverStore, runOfOrigin as runOfOriginOverStore } from "./store-reads/runs.js";
|
|
116
|
+
import { observationOf } from "./factory-activity.js";
|
|
117
|
+
import { factoryRunsPage } from "./factory-runs.js";
|
|
116
118
|
import { runEntries } from "./store-reads/journal.js";
|
|
117
119
|
import { metersOverStore, spendOverStore } from "./store-reads/cap.js";
|
|
118
120
|
import { watchRun } from "./live/stream.js";
|
|
119
121
|
import { stats as statsOverStore } from "./store-reads/stats.js";
|
|
120
122
|
import { analytics as analyticsOverStore } from "./store-reads/analytics.js";
|
|
121
123
|
import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
|
|
122
|
-
import { openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
124
|
+
import { LearningRecordRefused, openStore, openRunLaunch, sealRunLaunch, StoreLaunchMissing, StoreOwned, storeTarget } from "./store/index.js";
|
|
123
125
|
import { agentDeleting, answerOf, logged, purgedAgent } from "./agents.js";
|
|
124
126
|
import { keepGrade } from "./runner/feedback-round.js";
|
|
125
127
|
import { gradeRow, notAuditableOf } from "./runner/audit.js";
|
|
126
|
-
import { namedDisksOf } from "./learn/learning-of.js";
|
|
127
128
|
import { auditsOffWords, auditWriterOf, isShadowRun, readAudits, servingLinesOf, shadowRunId } from "./learn/audit.js";
|
|
128
129
|
import { auditLoopOf, COMPILE_AFTER_MAX, holdsReservedKey, RESERVED_SEGMENT } from "./learning-setting.js";
|
|
129
130
|
import { FINAL_STATES, RUN_CHANGES_PAGE } from "./store/store.js";
|
|
130
131
|
import { championOf, forgetRunCopies, GRADE_SOURCES, gradeView, LABEL_MAX, promotionsOf, promotionsShown, servingOf, servingStateOf, shownDeep } from "./learn/promote.js";
|
|
131
132
|
import { workflowNodesOf } from "./learn/workflow-nodes.js";
|
|
132
133
|
import { deleteLearning } from "./learn/delete.js";
|
|
134
|
+
import { forgetLegacyRunLearning, legacyGradesKey, legacyPromotionsKey } from "./learn/legacy/scrub.js";
|
|
133
135
|
import { runModelRef } from "./model.js";
|
|
134
|
-
import {
|
|
136
|
+
import { fullTag, localModelView, localPulls, pullLocalModel, pullThrough, readMachine } from "./local-model.js";
|
|
137
|
+
import { ollamaForget, ollamaHostOf, ollamaHostRefused, ollamaListing, ollamaModels, ollamaReading } from "./ollama-provider.js";
|
|
135
138
|
import { REDACTED } from "./secret-cut.js";
|
|
136
139
|
// The v2 run statuses, as the run view names them (run-view.ts Status), for the list filter's validation. */
|
|
137
140
|
const STATUSES = ["queued", "working", "paused", "input_required", "completed", "failed", "cancelled"];
|
|
@@ -147,7 +150,7 @@ import { hostSecrets, SECRET_NAMES, secret, withSecrets } from "./secrets.js";
|
|
|
147
150
|
import { isSecretWriteOperation, secretPageFor, secretsWritableFields, secretWriteRefusal, secretWriterFacts, writesSecretFor, writesSecretsAllowed } from "./secret-writes.js";
|
|
148
151
|
import { ChatGPTPlan, planOf, PlanSignInRefused, SIGN_OUT_UNCONFIRMED, withPlan } from "./chatgpt-plan.js";
|
|
149
152
|
import { modelGatewayRoute, readSavedGateway, withSavedGateway } from "./model-gateway.js";
|
|
150
|
-
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
153
|
+
import { CLAUDE_LOGIN_ROUTES, LOGIN_REFUSES_API_KEYS, oneOwnerDeps, ClaudeLoginRefused, claudeLoginOf, claudeLoginRouteOff, claudeLoginServed, claudeLoginSwitchedOff, claudeLoginSetting, claudeLoginView, dropRefusedLogin, envAtPlace, LOGIN_HARNESS, loginOf, loginOnRunnerOnly, loopback, signOutClaudeLogin, startLoginHere, turnOffClaudeLogin, turnOnClaudeLogin, withClaudeLogin } from "./claude-login.js";
|
|
151
154
|
import { ClaudeSignIns } from "./claude-sign-in.js";
|
|
152
155
|
import { bootSealKey, parametersDigest, withSealKey } from "./seal-key.js";
|
|
153
156
|
import { ServerLockHeldError, takeServerLock } from "./server-lock.js";
|
|
@@ -262,9 +265,6 @@ const TEMPLATE_UPLOAD_BODY = Math.ceil((IMPORT_LIMITS.packageBytes * 4) / 3) + M
|
|
|
262
265
|
/** The starts that may begin setup's import without ending it (a worker that failed, a process that ended) before the
|
|
263
266
|
* owner's yes is dropped: an import that fails the same way each time is not taken up at every start for good. */
|
|
264
267
|
const IMPORT_STARTS = 3;
|
|
265
|
-
/** The heap of the worker that counts or imports this machine's sessions. A run is read whole, at most MAX_RUN_BYTES of
|
|
266
|
-
* files (import.ts), which this holds several times over. */
|
|
267
|
-
const IMPORT_HEAP_MB = 2048;
|
|
268
268
|
const MAX_MESSAGE = 20_000;
|
|
269
269
|
const MAX_WAIT_MS = 25_000;
|
|
270
270
|
/** A run body's fields that a launch hook's host can't set on a firing's run (RunCreate `trigger_firing`): its trigger's
|
|
@@ -496,11 +496,15 @@ export const ROUTES = [
|
|
|
496
496
|
{ method: "PUT", pattern: /^\/settings\/claude-login$/, name: "turnOnClaudeLogin" },
|
|
497
497
|
{ method: "DELETE", pattern: /^\/settings\/claude-login$/, name: "turnOffClaudeLogin" },
|
|
498
498
|
{ method: "POST", pattern: /^\/settings\/claude-login\/login$/, name: "startClaudeLogin" },
|
|
499
|
+
{ method: "POST", pattern: /^\/settings\/claude-login\/sign-out$/, name: "signOutClaudeLogin" },
|
|
499
500
|
// The model gateway saved in the console (model-gateway.ts): its save, removal and test the owner's session's alone.
|
|
500
501
|
{ method: "GET", pattern: /^\/settings\/model-gateway$/, name: "getModelGateway" },
|
|
501
502
|
{ method: "PUT", pattern: /^\/settings\/model-gateway$/, name: "saveModelGateway" },
|
|
502
503
|
{ method: "DELETE", pattern: /^\/settings\/model-gateway$/, name: "deleteModelGateway" },
|
|
503
504
|
{ method: "POST", pattern: /^\/settings\/model-gateway\/test$/, name: "testModelGateway" },
|
|
505
|
+
// A free local model (local-model.ts): this machine and its recommended model, and one pull of it, the owner's alone.
|
|
506
|
+
{ method: "GET", pattern: /^\/settings\/local-model$/, name: "getLocalModel" },
|
|
507
|
+
{ method: "POST", pattern: /^\/settings\/local-model\/pull$/, name: "pullLocalModel" },
|
|
504
508
|
{ method: "GET", pattern: /^\/settings\/mcp-servers$/, name: "listMcpServers" },
|
|
505
509
|
{ method: "GET", pattern: /^\/settings\/mcp-server-names$/, name: "listMcpServerNames" },
|
|
506
510
|
{ method: "POST", pattern: /^\/settings\/mcp-servers\/preview$/, name: "previewMcpServer" },
|
|
@@ -751,8 +755,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
751
755
|
// their words name the model it lacks. One whose default lacks a key while another model runs is (its `needs` says
|
|
752
756
|
// what the default lacks).
|
|
753
757
|
harnesses: harnesses.map(({ keys: _keys, noModelRuns, ...offer }) => ({ ...offer, available: offer.available && !noModelRuns, max_concurrent_runs: Math.min(maxRuns, runsThatFit(offer.id, memory, env)) })),
|
|
754
|
-
/** The places a revision may name (`definition.place`), this host's default
|
|
755
|
-
|
|
758
|
+
/** The places a revision may name (`definition.place`), this host's default (null where a new agent must name one),
|
|
759
|
+
* and whether this server has each box. */
|
|
760
|
+
places: placesOf(boxes, boxAllowOf(env), !!runnerShell?.size),
|
|
756
761
|
models,
|
|
757
762
|
learning_model,
|
|
758
763
|
/** `pending`: a workflow draft with a call no price covers is kept to wait for its owner's OK, served to no run;
|
|
@@ -813,10 +818,9 @@ function capabilitiesWith(env, maxRuns, harnesses, learning, { needs, priced, le
|
|
|
813
818
|
* (tool-keys-store.ts), never in the clear. */
|
|
814
819
|
tool_keys: { routes: true, at_rest: "sealed" },
|
|
815
820
|
/** GET /settings/harness-keys and PUT/DELETE of one key: a plan-billed recipe's keys, saved for that harness alone
|
|
816
|
-
* (harness-keys.ts); `harnesses` its ids here
|
|
817
|
-
*
|
|
818
|
-
|
|
819
|
-
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id), kept: [] },
|
|
821
|
+
* (harness-keys.ts); `harnesses` its ids here. The page's own GET lists the ids with keys kept whose recipe the
|
|
822
|
+
* server no longer names, so the console offers the page on `routes`, as it does tool keys'. */
|
|
823
|
+
harness_keys: { routes: true, at_rest: "sealed", harnesses: planRecipesOf(env).map((recipe) => recipe.id) },
|
|
820
824
|
/** /settings/mcp-servers: remote MCP servers previewed and saved, each credential sealed under the server's seal key,
|
|
821
825
|
* which always exists (seal-key.ts), so MCP credentials are always kept sealed. Every harness of the table runs a
|
|
822
826
|
* grant (runnable.ts takes one on any), a module's among them. `composio_per_run`: a per-run Composio server takes
|
|
@@ -958,7 +962,8 @@ export async function startServe(options) {
|
|
|
958
962
|
}
|
|
959
963
|
// The Ollama this server asks, and its runner beside it: OLLAMA_HOST, else the default address on one owner's own machine
|
|
960
964
|
// alone (ollamaHostOf). Read once, at the start: a refused one is said once, here, in the base rule's words.
|
|
961
|
-
const
|
|
965
|
+
const notOwn = whyNotOwnMachine(options, data, ownUser);
|
|
966
|
+
const ollamaHost = ollamaHostOf(process.env, notOwn.length === 0);
|
|
962
967
|
const tokenRefused = options.token === undefined ? undefined : tokenProblem(options.token);
|
|
963
968
|
if (tokenRefused)
|
|
964
969
|
throw new Error(tokenRefused);
|
|
@@ -978,8 +983,8 @@ export async function startServe(options) {
|
|
|
978
983
|
dockerLimitsOf(process.env);
|
|
979
984
|
// The Docker host's addresses an operator names (workspace/computer-deps.ts): a bad entry stops the start, in words.
|
|
980
985
|
dockerHostAddressesOf(process.env);
|
|
981
|
-
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one
|
|
982
|
-
//
|
|
986
|
+
// The Archil settings an operator sets (archil-settings.ts ARCHIL_SETTINGS_ENV): one set without the region, or a value
|
|
987
|
+
// the PUT would refuse (no S3 URL for a region serve doesn't know), stops the start, in words naming each variable.
|
|
983
988
|
archilSettingsFromEnv(process.env);
|
|
984
989
|
const boxAllow = boxAllowOf(process.env);
|
|
985
990
|
const maxRuns = maxRunsOf(process.env, options.maxRuns);
|
|
@@ -995,11 +1000,12 @@ export async function startServe(options) {
|
|
|
995
1000
|
// One server per data root: the store's owner lock (StoreOwned), then the data root's own (server-lock.ts), both taken
|
|
996
1001
|
// when startHolding opens the store; a data directory an earlier version wrote is refused there too
|
|
997
1002
|
// (StoreFromEarlierVersion), in words, to start fresh. No oldHomes/oldLayout checks, no migration.
|
|
998
|
-
// What a start that fails stops: the
|
|
999
|
-
// store handle it opened
|
|
1003
|
+
// What a start that fails stops: first the timers it set (each put at the front, so none ticks on a closing store), then
|
|
1004
|
+
// the rest in the order they began: the store handle it opened, its locks, and the webhook deliveries it began, which
|
|
1005
|
+
// would write the next server's outbox.
|
|
1000
1006
|
const stops = [];
|
|
1001
1007
|
try {
|
|
1002
|
-
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost }, stops);
|
|
1008
|
+
return await startHolding(options, data, { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost, notOwn }, stops);
|
|
1003
1009
|
}
|
|
1004
1010
|
catch (error) {
|
|
1005
1011
|
for (const stop of stops)
|
|
@@ -1029,14 +1035,14 @@ async function whileReplaced(take, held, until, waiting) {
|
|
|
1029
1035
|
}
|
|
1030
1036
|
}
|
|
1031
1037
|
async function startHolding(options, data, checked, stops) {
|
|
1032
|
-
const { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost } = checked;
|
|
1038
|
+
const { maxRuns, minFreeBytes, learning, boxAllow, templates, ollamaHost, notOwn } = checked;
|
|
1033
1039
|
/** What an agent's view says of its learning: how many learned items wait for its owner's OK, for an agent that learns
|
|
1034
1040
|
* on this server (learning on, its current revision `learning: true`); none for another, or when the count cannot be
|
|
1035
1041
|
* read (the view never fails for it). */
|
|
1036
1042
|
const learningOfAgent = async (entry) => {
|
|
1037
1043
|
if (learning === "off" || entry.revision?.kind !== "agentic" || !learnsOf(entry.revision.body.learning))
|
|
1038
1044
|
return undefined;
|
|
1039
|
-
const pending = await pendingCount(
|
|
1045
|
+
const pending = await pendingCount(store, entry.agent.id);
|
|
1040
1046
|
return pending === undefined ? undefined : { pending };
|
|
1041
1047
|
};
|
|
1042
1048
|
const log = options.log;
|
|
@@ -1108,7 +1114,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1108
1114
|
const beside = { runner: runnerName(), incarnation: randomUUID() };
|
|
1109
1115
|
// The data root's own lock, once the store is held (so a deploy on Postgres waits at the store's owner lock first): the
|
|
1110
1116
|
// store's lock holds one store, but the data root also holds what the server writes beside it (its token, its seal key,
|
|
1111
|
-
// uploads, harness installs
|
|
1117
|
+
// uploads, harness installs), which two servers on two stores (two Postgres schemas, or SQLite and
|
|
1112
1118
|
// Postgres) would share. The lock is SQLite's EXCLUSIVE lock (server-lock.ts): the kernel drops it when its process
|
|
1113
1119
|
// dies, so a crashed server never leaves it held.
|
|
1114
1120
|
// Its wait runs from when the store was held at the earliest, since a store on Postgres may have been waited for first.
|
|
@@ -1165,10 +1171,24 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1165
1171
|
// not (its runners on other hosts, AGENTRUN_RUNNER_HOSTS), so the tick runs on both. It does nothing while no computer
|
|
1166
1172
|
// is paired; with a runner beside it, nothing past its one read of the routes while no route row is there and no box
|
|
1167
1173
|
// is relayed (computer-attach.ts tick).
|
|
1174
|
+
// The ticks still running, so a failed start and close() wait them out before the store closes.
|
|
1175
|
+
const routeTicks = new Set();
|
|
1168
1176
|
const routeTick = options.apiOnly !== true
|
|
1169
|
-
? setInterval(() =>
|
|
1177
|
+
? setInterval(() => {
|
|
1178
|
+
const ticked = attach.tick()
|
|
1179
|
+
.catch((error) => attachLog("computer_route_tick_failed", { error: error instanceof Error ? error.message : String(error) }))
|
|
1180
|
+
.finally(() => void routeTicks.delete(ticked));
|
|
1181
|
+
routeTicks.add(ticked);
|
|
1182
|
+
}, PAIRED_ROUTE_MS)
|
|
1170
1183
|
: undefined;
|
|
1171
1184
|
routeTick?.unref();
|
|
1185
|
+
// A start that fails after this point clears it as the close does. Each timer's stop goes first (unshift), ahead of
|
|
1186
|
+
// the store's close: a failed start stops its timers and waits out their ticks and sweeps, then closes the store, so
|
|
1187
|
+
// no tick or sweep ever reads a store that is closing.
|
|
1188
|
+
stops.unshift(async () => {
|
|
1189
|
+
clearInterval(routeTick);
|
|
1190
|
+
await Promise.all(routeTicks);
|
|
1191
|
+
});
|
|
1172
1192
|
// This server's own key on every environment it reads its secrets from, so a reader opens what this store holds with the
|
|
1173
1193
|
// key checked against it, never another data directory's that this process booted too (secrets.ts holds one made key).
|
|
1174
1194
|
const own = (env) => withSealKey(env, seal.text);
|
|
@@ -1339,11 +1359,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1339
1359
|
// The start-time switches as this server was started: its options, else the CLI's variables. mcpLoopback is the
|
|
1340
1360
|
// option alone, as everywhere it is read here (localInstall): the CLI sets it from AGENTRUN_MCP_ALLOW_LOOPBACK.
|
|
1341
1361
|
const switched = { mcpLoopback: options.mcpLoopback === true, webhookPrivateTargets: switchedOnBy(process.env, options).webhookPrivateTargets, apiOnlyMcpOrigins };
|
|
1342
|
-
|
|
1343
|
-
const compose = (runnerShell) => {
|
|
1344
|
-
const made = askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1345
|
-
return { ...made, features: { ...made.features, harness_keys: { ...made.features.harness_keys, kept: harnessKeys.unnamed() } } };
|
|
1346
|
-
};
|
|
1362
|
+
const compose = (runnerShell) => askNeeds(capabilitiesWith(env, maxRuns, offers, learning, needs, settings.get(), boxOffers, toolKeys.refused(), runnerShell, isolation, switched));
|
|
1347
1363
|
const recompose = () => void (caps = compose());
|
|
1348
1364
|
// What the offers held now were made from (offersInputs), and the latest probe: one a later probe overtook is dropped.
|
|
1349
1365
|
let offersFrom;
|
|
@@ -1352,7 +1368,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1352
1368
|
// probe that fails never lands; when it is the latest, it clears this as it fails, so no probe is out after it.
|
|
1353
1369
|
let probing;
|
|
1354
1370
|
// The latest probe's turn: it ends as that probe lands or fails, or as a later probe starts and overtakes it, whichever
|
|
1355
|
-
// is first, and never fails. A change that waits for the probe out waits for its turn (
|
|
1371
|
+
// is first, and never fails. A change that waits for the probe out waits for its turn (offersNow), so a dropped
|
|
1356
1372
|
// probe holds no one up and its failure is no one else's.
|
|
1357
1373
|
let turn = Promise.resolve();
|
|
1358
1374
|
let endTurn = () => { };
|
|
@@ -1402,16 +1418,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1402
1418
|
});
|
|
1403
1419
|
/** Whether the offers held now were made from `inputs` (offersInputs). */
|
|
1404
1420
|
const offersMadeFrom = (inputs) => offersFrom !== undefined && sameInputs(inputs, offersFrom);
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
// serverSecrets live, store-view), and a list builds a listing cut of other keys again (builtOfNow). A failed run's error words
|
|
1408
|
-
// name a refused key by the keys and settings, so those listings are built again.
|
|
1409
|
-
await lister.keysChanged();
|
|
1410
|
-
env = readEnv(base);
|
|
1421
|
+
/** What a revision that names no model needs (needsOf), made again from env as it is now: the latest ask's stands. */
|
|
1422
|
+
const needsNow = async () => {
|
|
1411
1423
|
const mine = ++needsAsked;
|
|
1412
1424
|
const next = await needsOf(env);
|
|
1413
1425
|
if (mine === needsAsked)
|
|
1414
1426
|
needs = next;
|
|
1427
|
+
};
|
|
1428
|
+
/** The offers made again from the inputs read now (offersInputs), with no listing built again and env not read again:
|
|
1429
|
+
* the end of a key's change (keysChanged), and all of a refresh of the login, or of a new Ollama listing, whose offers
|
|
1430
|
+
* are not made from the inputs now, since no key changed there. */
|
|
1431
|
+
const offersNow = async () => {
|
|
1415
1432
|
// A probe still out from other inputs (a turn-on's, after its turn-off) would put back offers made from them as it
|
|
1416
1433
|
// lands: a probe of these overtakes it. Only a change starts one, at most one per change, so nothing loops. While the
|
|
1417
1434
|
// probe out has read these inputs, a change starts none: with the offers held made from them too it recomposes at
|
|
@@ -1436,16 +1453,51 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1436
1453
|
return;
|
|
1437
1454
|
}
|
|
1438
1455
|
};
|
|
1456
|
+
const keysChanged = async () => {
|
|
1457
|
+
// A run's learning, view, list and timeline row are cut of the keys saved now by the run view at read time (it reads
|
|
1458
|
+
// serverSecrets live, store-view), and a list builds a listing cut of other keys again (builtOfNow). A failed run's error words
|
|
1459
|
+
// name a refused key by the keys and settings, so those listings are built again.
|
|
1460
|
+
await lister.keysChanged();
|
|
1461
|
+
env = readEnv(base);
|
|
1462
|
+
await needsNow();
|
|
1463
|
+
await offersNow();
|
|
1464
|
+
};
|
|
1439
1465
|
/** The Ollama here, as capabilities read it: its listing asked again behind the answer once stale (ollamaModels), and
|
|
1440
|
-
*
|
|
1466
|
+
* once a listing differs from the one the offers were made from, what a revision that names no model needs (its
|
|
1467
|
+
* default is the listing's: needsOf) and the offers made again from it. No key changed, so no run is relisted. So a
|
|
1441
1468
|
* model pulled, or Ollama started after this server, shows in a later answer with no restart. */
|
|
1442
1469
|
const ollamaNow = async () => {
|
|
1443
1470
|
if (!asksOllama(env))
|
|
1444
1471
|
return;
|
|
1445
1472
|
void ollamaModels(env);
|
|
1446
|
-
if (offersFrom
|
|
1447
|
-
|
|
1473
|
+
if (!offersFrom || offersMadeFrom(offersInputs(env)))
|
|
1474
|
+
return;
|
|
1475
|
+
await needsNow();
|
|
1476
|
+
await offersNow();
|
|
1448
1477
|
};
|
|
1478
|
+
/** How many times a pull's end reads the Ollama listing for its tag before it fails (ollamaPulled). */
|
|
1479
|
+
const PULL_LISTED_TRIES = 6;
|
|
1480
|
+
/** After a pull of `tag` here ends (local-model.ts): the kept listing dropped and read again at once until it lists
|
|
1481
|
+
* `tag` (a listing whose ask of one model failed lists it not), and the reading made again where it differs, so the
|
|
1482
|
+
* model is in the picker and is the default with no wait for OLLAMA_TTL_MS before the pull says done. Never listed
|
|
1483
|
+
* after PULL_LISTED_TRIES reads, the pull fails in words, so the card never runs a template on another model. */
|
|
1484
|
+
const ollamaPulled = async (tag) => {
|
|
1485
|
+
for (let tries = 1;; tries++) {
|
|
1486
|
+
ollamaForget(env);
|
|
1487
|
+
const listed = await ollamaModels(env);
|
|
1488
|
+
if (listed.some((model) => model.name === fullTag(tag)))
|
|
1489
|
+
break;
|
|
1490
|
+
if (tries >= PULL_LISTED_TRIES)
|
|
1491
|
+
throw new Error(`Ollama finished pulling ${tag} but does not list it yet. Press Pull again.`);
|
|
1492
|
+
await new Promise((resolve) => setTimeout(resolve, 250 * tries));
|
|
1493
|
+
}
|
|
1494
|
+
await ollamaNow();
|
|
1495
|
+
};
|
|
1496
|
+
/** This machine, read once (local-model.ts readMachine), or a test's. */
|
|
1497
|
+
let machineRead;
|
|
1498
|
+
const machineOf = () => (machineRead ??= (options.machine ?? readMachine)());
|
|
1499
|
+
const pulls = localPulls({ pull: pullThrough(() => env, options.pullStallMs), finished: ollamaPulled, ...(log ? { log } : {}), signal: stopping.signal });
|
|
1500
|
+
const localModelDeps = () => ({ env, notOwn, machine: machineOf, pulls });
|
|
1449
1501
|
/** After a harness key is saved or removed (harness-keys.ts): the listings built again, cut of it, and the offers probed
|
|
1450
1502
|
* again, as a recipe is offered once every key it runs on is saved here (harnessKeysSavedHere). No environment changes. */
|
|
1451
1503
|
const harnessKeysChanged = async () => {
|
|
@@ -1550,8 +1602,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1550
1602
|
* that fails is answered to it. A probe with no hand-over (a key's save, a harness key's, a new Ollama listing) can
|
|
1551
1603
|
* drop the hand-over's too, and then fail or still be out: the hand-over is still the latest and did not fail, yet the
|
|
1552
1604
|
* offers held were made before it. So the request also goes on only where the offers held are made from the inputs
|
|
1553
|
-
* now (offersMadeFrom); where not, it makes them as a key's save
|
|
1554
|
-
* these inputs, or probes itself, and a probe of its own that fails is answered to it)
|
|
1605
|
+
* now (offersMadeFrom); where not, it makes them again as a key's save ends (offersNow: it waits for the probe out of
|
|
1606
|
+
* these inputs, or probes itself, and a probe of its own that fails is answered to it), with no run relisted, as no
|
|
1607
|
+
* key changed. It looks at most LOGIN_ROUNDS
|
|
1555
1608
|
* times, then is refused (unavailable, retryable), so turns that keep coming never hold it for ever. */
|
|
1556
1609
|
const loginNow = async () => {
|
|
1557
1610
|
if (loginOff !== undefined)
|
|
@@ -1560,7 +1613,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1560
1613
|
const n = await refreshOnce();
|
|
1561
1614
|
const latest = () => handed.n === n && !handed.failed;
|
|
1562
1615
|
if (latest() && !offersMadeFrom(offersInputs(env)))
|
|
1563
|
-
await
|
|
1616
|
+
await offersNow();
|
|
1564
1617
|
if (latest() && offersMadeFrom(offersInputs(env)))
|
|
1565
1618
|
return;
|
|
1566
1619
|
if (round >= LOGIN_ROUNDS)
|
|
@@ -1780,7 +1833,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1780
1833
|
* list reads it, so a tool of bash's family the run would not have shows unavailable (tool-plane.ts shellUnavailable). */
|
|
1781
1834
|
const shellOfRevision = async (revision) => {
|
|
1782
1835
|
const body = revision.body;
|
|
1783
|
-
return shellOf(settingOfDefinition(body)?.computer ?? computerOfPlace(fallbackPlace(revision.kind, revision.kind === "agentic" ? (body.tools ?? []) : [])));
|
|
1836
|
+
return shellOf(settingOfDefinition(body)?.computer ?? computerOfPlace(await fallbackPlace(revision.kind, revision.kind === "agentic" ? (body.tools ?? []) : [])));
|
|
1784
1837
|
};
|
|
1785
1838
|
/** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
|
|
1786
1839
|
* job's (its compile turn is learning's), null while unknown; what learning spent for it
|
|
@@ -1791,27 +1844,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1791
1844
|
const allInViewOf = async (runId, view) => {
|
|
1792
1845
|
const cost = (view.cost ?? {});
|
|
1793
1846
|
const own = typeof cost.usd === "number" && cost.upper_bound !== true ? cost.usd : null;
|
|
1794
|
-
|
|
1795
|
-
// a 500: the revision ledger its `learning_usd` and `all_in_usd` share is read from takes the champion with no record
|
|
1796
|
-
// skipped (as before the purge), so a revision a purged run wrote may be the one it counts as serving, for this read
|
|
1797
|
-
// alone. Figures only: no text is read or shown. Every write that asks the gate still fails closed (decideCheck
|
|
1798
|
-
// throws, so no promote lands; recordPromotion trims nothing). Such a read says so: `cost.degraded`.
|
|
1799
|
-
let degraded = false;
|
|
1800
|
-
const all = await runAllInOverStore(store, runId, own, (agentId, records) => refusedFor(agentId, records).catch((error) => {
|
|
1801
|
-
degraded = true;
|
|
1802
|
-
const line = `learning: run ${runId}: its costs were read without the purge gate's answer: ${error instanceof Error ? error.message : String(error)}`;
|
|
1803
|
-
if (log)
|
|
1804
|
-
log(logLine("learning", { line }));
|
|
1805
|
-
else
|
|
1806
|
-
process.stderr.write(`agentrun-serve: ${line}\n`);
|
|
1807
|
-
return Object.assign(() => false, { unread: true });
|
|
1808
|
-
}));
|
|
1847
|
+
const all = await runAllInOverStore(store, runId, own);
|
|
1809
1848
|
if (!all)
|
|
1810
1849
|
return {};
|
|
1811
1850
|
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1812
1851
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1813
1852
|
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1814
|
-
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd
|
|
1853
|
+
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } };
|
|
1815
1854
|
};
|
|
1816
1855
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1817
1856
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -1928,7 +1967,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1928
1967
|
};
|
|
1929
1968
|
const uploadsTimer = setInterval(sweepUploads, UPLOAD_SWEEP_EVERY_MS);
|
|
1930
1969
|
uploadsTimer.unref();
|
|
1931
|
-
stops.
|
|
1970
|
+
stops.unshift(async () => {
|
|
1932
1971
|
clearInterval(uploadsTimer);
|
|
1933
1972
|
await sweeping;
|
|
1934
1973
|
});
|
|
@@ -2006,6 +2045,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2006
2045
|
};
|
|
2007
2046
|
const refusedTimer = setInterval(() => void sweepRefused(), REFUSED_SWEEP_MS);
|
|
2008
2047
|
refusedTimer.unref();
|
|
2048
|
+
stops.unshift(async () => {
|
|
2049
|
+
refusedStopped = true;
|
|
2050
|
+
clearInterval(refusedTimer);
|
|
2051
|
+
await refusedSweep;
|
|
2052
|
+
});
|
|
2009
2053
|
// The runner beside this server, when its run isolation was refused (cli.ts): its word, kept in this store until the stop.
|
|
2010
2054
|
let refusedBeside;
|
|
2011
2055
|
const sourceWorkspaces = { data, sealKey, env: withSecrets(process.env, "own"), ...(options.archilControl ? { control: options.archilControl } : {}) };
|
|
@@ -2056,6 +2100,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2056
2100
|
};
|
|
2057
2101
|
const localSourceTimer = setInterval(() => void sweepLocalSources(), 30_000);
|
|
2058
2102
|
localSourceTimer.unref();
|
|
2103
|
+
// As close() does: aborted first, so a sync in flight stops instead of being waited out.
|
|
2104
|
+
stops.unshift(async () => {
|
|
2105
|
+
stopping.abort();
|
|
2106
|
+
clearInterval(localSourceTimer);
|
|
2107
|
+
await localSourceSweep;
|
|
2108
|
+
});
|
|
2059
2109
|
const startDeps = {
|
|
2060
2110
|
project: { ...sourceProjects, place: async (given) => {
|
|
2061
2111
|
try {
|
|
@@ -2108,17 +2158,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2108
2158
|
// Whether that is the operator's own setting, not the default: a browser is held to an operator's list alone.
|
|
2109
2159
|
...(boxAllowSetIn(process.env) ? { boxAllowSet: true } : {}),
|
|
2110
2160
|
modelOf,
|
|
2111
|
-
// The run's learning start: the server's learning switch, the agent's seed read now from its learning
|
|
2161
|
+
// The run's learning start: the server's learning switch, the agent's seed read now from its learning rows, and
|
|
2112
2162
|
// the host's secrets as they are shown now to cut the corrections a run is given, a loopback address kept (local): the
|
|
2113
2163
|
// run's own machine. runs-over-store.learningStartFor pins the result (seed, section, workflows) in the launch for the
|
|
2114
2164
|
// runner; a seed that cannot be read starts the run with nothing learned (a fault never refuses it). The runner's spec
|
|
2115
2165
|
// builders read it back as the run's end-of-run step (runner/learning-end.ts learningEndOfRun).
|
|
2116
2166
|
learning,
|
|
2117
2167
|
seedFor: async (agentId) => {
|
|
2118
|
-
//
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning folder could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
2168
|
+
// A store fault surfaces here as a seedOf error, so the run starts with nothing learned, never refused.
|
|
2169
|
+
return seedOf(data, store, agentId).then((seed) => ({ seed }), (error) => {
|
|
2170
|
+
process.stderr.write(`agentrun-serve: the agent ${agentId}'s learning could not be read, so its run starts with nothing learned: ${error.message}\n`);
|
|
2122
2171
|
return { failed: error.message };
|
|
2123
2172
|
});
|
|
2124
2173
|
},
|
|
@@ -2137,22 +2186,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2137
2186
|
return [...serverSecrets(), ...pointers];
|
|
2138
2187
|
};
|
|
2139
2188
|
const learningShown = async (agentId) => secretsShown(await learningValues(agentId));
|
|
2140
|
-
//
|
|
2141
|
-
|
|
2142
|
-
//
|
|
2143
|
-
const
|
|
2144
|
-
// The agent's audit ledger on its learning folder's main (learn/audit.ts), oldest first.
|
|
2145
|
-
const auditsOfAgent = async (agentId) => {
|
|
2146
|
-
const { workspace, end } = learningFolderOf(data, agentId);
|
|
2147
|
-
try {
|
|
2148
|
-
return await readAudits(workspace);
|
|
2149
|
-
}
|
|
2150
|
-
finally {
|
|
2151
|
-
await end().catch(() => undefined);
|
|
2152
|
-
}
|
|
2153
|
-
};
|
|
2154
|
-
// What a run held for its owner's OK reads as it stands on its agent's learning folder's main (statusesOf).
|
|
2155
|
-
const statuses = (agentId) => statusesOf(data, agentId);
|
|
2189
|
+
// The agent's audit ledger (learn/audit.ts), oldest first.
|
|
2190
|
+
const auditsOfAgent = (agentId) => readAudits(store.learning, agentId);
|
|
2191
|
+
// What a run held for its owner's OK reads as it stands in its agent's learning (statusesOf).
|
|
2192
|
+
const statuses = (agentId) => statusesOf(store, agentId);
|
|
2156
2193
|
const viewDepsFor = (origin) => ({ origin, serverSecrets, signIns, sealKey, keyEnv: () => withSavedGateway(own(withSecrets(process.env, "all", storedKeys)), savedGateway), statuses });
|
|
2157
2194
|
// A run read as a whole (its own read, its archive) lists its recordings too, from its recordings folder on this machine
|
|
2158
2195
|
// (run-recordings.ts), where the runner beside it wrote them; every other read of the view opens no file.
|
|
@@ -2639,7 +2676,12 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2639
2676
|
// runner's child holds many).
|
|
2640
2677
|
...(process.execArgv.some((arg) => arg.startsWith("--input-type")) ? { execArgv: workerArgs(process.execArgv) } : {}),
|
|
2641
2678
|
// Its own heap, at most IMPORT_HEAP_MB whatever the machine's memory: an import that needs more ends as a failed
|
|
2642
|
-
// worker (said, and counted: IMPORT_STARTS)
|
|
2679
|
+
// worker (said, and counted: IMPORT_STARTS). A Wrapped read also starts the import package's read threads
|
|
2680
|
+
// (wrappedReading), each with a heap of its own outside this one, capped at its start: a 16 MB young generation
|
|
2681
|
+
// and the import's workerOldMb (64 MB) old one. Their finished reads wait for this thread mostly as transferred
|
|
2682
|
+
// ArrayBuffers (record indexes, request counts), memory outside this cap. So a Wrapped read holds IMPORT_HEAP_MB
|
|
2683
|
+
// for this thread's own heap, plus threads x (workerOldMb + 16) MB, plus readAhead for the replies waiting to be
|
|
2684
|
+
// taken, with up to `threads` replies in flight on top: the pool checks readAhead before it starts a read.
|
|
2643
2685
|
resourceLimits: { maxOldGenerationSizeMb: IMPORT_HEAP_MB },
|
|
2644
2686
|
});
|
|
2645
2687
|
workers.set(worker, { task, exit: once(worker, "exit").catch(() => undefined) });
|
|
@@ -2952,41 +2994,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
2952
2994
|
throw new ApiError("unavailable", `${error.message.replace(/[.\s]*$/, "")}. ${again}`, { retry_after_ms: 5_000 });
|
|
2953
2995
|
}
|
|
2954
2996
|
};
|
|
2955
|
-
/**
|
|
2956
|
-
*
|
|
2957
|
-
|
|
2958
|
-
* 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
|
|
2959
|
-
* "agent", is the agent's own disk, mounted only while it is still the stored one (workspace/run-disk.ts runDiskOf):
|
|
2960
|
-
* one no longer stored was removed at Archil, its folder with it. */
|
|
2961
|
-
const learningDisksOf = async (agentId, agentDisk) => {
|
|
2962
|
-
const disks = new Set();
|
|
2963
|
-
const stored = agentDisk ? await agentDiskOf(store, agentId) : undefined;
|
|
2964
|
-
if (stored)
|
|
2965
|
-
disks.add(stored.diskId);
|
|
2966
|
-
for (const disk of await namedDisksOf(store, agentId))
|
|
2967
|
-
disks.add(disk);
|
|
2968
|
-
return [...disks];
|
|
2969
|
-
};
|
|
2970
|
-
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete over the agent's
|
|
2971
|
-
* learning folder on this server's disk, as the learning routes open it (learningFolderOf), which deleteLearning ends
|
|
2972
|
-
* in its finally, and over its folder on each Archil disk a launch of its runs named and, for a reset (`agentDisk`),
|
|
2973
|
-
* on its own disk, which the agent's delete removes whole in step 3 (archil-routes.ts removeLearningFolder; Archil
|
|
2974
|
-
* off or refusing is 503 unavailable, nothing here deleted, for the next call). */
|
|
2975
|
-
const learningDelete = options.deleteLearning ?? ((given, agentId, { keepResetLedger = false, agentDisk = false } = {}) => deleteLearning(given, agentId, learningFolderOf(data, agentId), {
|
|
2976
|
-
keepResetLedger,
|
|
2977
|
-
elsewhere: async () => {
|
|
2978
|
-
for (const diskId of await learningDisksOf(agentId, agentDisk)) {
|
|
2979
|
-
try {
|
|
2980
|
-
await archil.removeLearningFolder(agentId, diskId);
|
|
2981
|
-
}
|
|
2982
|
-
catch (error) {
|
|
2983
|
-
if (!(error instanceof ApiError && ["unavailable", "upstream_failed"].includes(error.code)))
|
|
2984
|
-
throw error;
|
|
2985
|
-
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 });
|
|
2986
|
-
}
|
|
2987
|
-
}
|
|
2988
|
-
},
|
|
2989
|
-
}));
|
|
2997
|
+
/** Step 2 of DELETE /agents/{id}, and DELETE /agents/{id}/learning: the learning module's delete of the agent's
|
|
2998
|
+
* learning rows (learn/delete.ts). */
|
|
2999
|
+
const learningDelete = options.deleteLearning ?? ((given, agentId, options) => deleteLearning(given, agentId, options));
|
|
2990
3000
|
/** What DELETE /agents/{id} does outside the store's rows, on this server (agent-delete.ts AgentDeleteHost). */
|
|
2991
3001
|
const agentDeleteHost = {
|
|
2992
3002
|
store,
|
|
@@ -3039,7 +3049,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3039
3049
|
// DELETE. A run on its agent's own disk: with its agent's delete that disk went whole (removeDisk), its folder with
|
|
3040
3050
|
// it; deleted alone, its folder there is deleted, the disk kept, read from its disk setting, which goes after.
|
|
3041
3051
|
const launched = await store.runs.launch(runId).then((row) => readLaunchBody(row.body)?.archilDisk, (error) => (error instanceof StoreLaunchMissing ? undefined : Promise.reject(error)));
|
|
3042
|
-
// The agent's learning folder there too
|
|
3052
|
+
// The agent's learning folder there too, kept from before learning moved to the store's rows: a Mode 2 end wrote
|
|
3053
|
+
// the run's diff and correction in it, and nothing reads it (learn/legacy/scrub.ts).
|
|
3043
3054
|
if (launched?.kind === "launch") {
|
|
3044
3055
|
await notYetWith(() => archil.removeRunFolder(agentId, runId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
3045
3056
|
await notYetWith(() => archil.removeLearningFolder(agentId, launched.diskId), ["unavailable", "upstream_failed"], again);
|
|
@@ -3062,8 +3073,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3062
3073
|
await forgetKept("run", runId);
|
|
3063
3074
|
},
|
|
3064
3075
|
forgetAgent: async (agentId) => {
|
|
3065
|
-
// The agent's folder (its runs' folders, its home,
|
|
3076
|
+
// The agent's folder (its runs' folders, its home, the learning folder kept from before the store's rows) and its
|
|
3077
|
+
// scratch folder, and the old learning settings keys (learn/legacy/scrub.ts), as the agent's purge took them before.
|
|
3066
3078
|
await rm(agentFolder(data, agentId), { recursive: true, force: true });
|
|
3079
|
+
for (const key of [legacyGradesKey(agentId), legacyPromotionsKey(agentId)])
|
|
3080
|
+
await store.settings.remove(key);
|
|
3067
3081
|
await rm(join(data, "scratch", agentDirName(agentId)), { recursive: true, force: true });
|
|
3068
3082
|
// Private source metadata is owned by this exact agent. Prefix siblings with dotted IDs are left alone.
|
|
3069
3083
|
for (const key of [`source-sync.agent.${agentId}`, `source-sync.local.${agentId}`])
|
|
@@ -3078,12 +3092,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3078
3092
|
// The replay runs of its input, its audit's shadow run and a learning run it names (the store's), and its audit's shadow
|
|
3079
3093
|
// run by its id (one whose launch is gone too).
|
|
3080
3094
|
madeFrom: async (runId) => [...new Set([...(await store.runs.madeFrom(runId)), shadowRunId(runId)])],
|
|
3081
|
-
// Its copies in the agent's promotion records
|
|
3082
|
-
//
|
|
3083
|
-
//
|
|
3095
|
+
// Its copies in the agent's promotion records. Its learning rows (its saves' words, its notes and workflow files, its
|
|
3096
|
+
// grades and audits) go with the run's rows in the store's purge (Store.learning.purgeRun). Then its text off the
|
|
3097
|
+
// learning kept from before the rows (learn/legacy/scrub.ts: the agent's old learning folder here, the old settings
|
|
3098
|
+
// keys), in the agent's queue: a folder that can't be written now is 503, the run purged or kept as the purge had
|
|
3099
|
+
// got, and the next DELETE does it again.
|
|
3084
3100
|
forgetCopies: async (agentId, runId) => {
|
|
3085
|
-
await forgetRunCopies(store.
|
|
3086
|
-
await
|
|
3101
|
+
await forgetRunCopies(store.learning, agentId, runId);
|
|
3102
|
+
await forgetSdkCopies(store, agentId, runId);
|
|
3103
|
+
await notYetWith(() => forgetLegacyRunLearning(data, agentId, runId, store), ["unavailable"], "The agent's old learning folder keeps the run's text until the DELETE is sent again.");
|
|
3087
3104
|
},
|
|
3088
3105
|
// /usage's meters and a live read's spend, from its journal, as they read now (store-reads/cap.ts), and how its
|
|
3089
3106
|
// learning ended as /stats counts it (its state and reason alone).
|
|
@@ -3110,7 +3127,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3110
3127
|
store,
|
|
3111
3128
|
deleteLearning: learningDelete,
|
|
3112
3129
|
cancel: agentDeleteHost.cancel,
|
|
3113
|
-
inQueue: (agentId, work) =>
|
|
3130
|
+
inQueue: (agentId, work) => inLearningQueue(data, agentId, work),
|
|
3114
3131
|
waitMs: agentDeleteHost.waitMs,
|
|
3115
3132
|
pollMs: agentDeleteHost.pollMs,
|
|
3116
3133
|
};
|
|
@@ -3205,7 +3222,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3205
3222
|
if (!revision.mcpPin && tools.some((tool) => mcpToolOf(tool)))
|
|
3206
3223
|
return null;
|
|
3207
3224
|
try {
|
|
3208
|
-
await runnable(revision, resolvePlace(body.place, fallbackPlace(revision.kind, tools)), { capped: body.maxCostUsd !== undefined, price: readDecisionPrice });
|
|
3225
|
+
await runnable(revision, resolvePlace(body.place, await fallbackPlace(revision.kind, tools)), { capped: body.maxCostUsd !== undefined, price: readDecisionPrice });
|
|
3209
3226
|
return null;
|
|
3210
3227
|
}
|
|
3211
3228
|
catch (error) {
|
|
@@ -3336,8 +3353,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3336
3353
|
const asks = blockers.flatMap((b) => (b.asks ? [b.asks] : []));
|
|
3337
3354
|
throw new ApiError("agent_not_runnable", message, { fields, details: { adapters: [...new Set(blockers.flatMap((b) => (b.adapter ? [b.adapter] : [])))], unbound, missing, code: blockers.some((b) => b.codeNodes || b.shell), ...(tier ? { tier } : {}), ...(Object.keys(decisions).length ? { decisions } : {}), ...(denied.length ? { denied } : {}), ...(asks.length ? { asks } : {}), ...named } });
|
|
3338
3355
|
}
|
|
3339
|
-
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with
|
|
3340
|
-
|
|
3356
|
+
/** Where a revision of `kind` naming `tools` and no place runs here: the place a new agent would be saved with, in the
|
|
3357
|
+
* folder mode of now (Mode 2, where the runner's shell is Archil's exec: the runner, never Docker's box). */
|
|
3358
|
+
const fallbackPlace = async (kind, tools) => defaultPlaceOf(kind, tools, boxOffers, toolOf, (await modeNow()) === 2);
|
|
3341
3359
|
/** What a save of `revision` pins of the MCP tools it grants (an agentic revision's: a workflow's nodes bind none): each
|
|
3342
3360
|
* granted server listed once, now, with its saved credential (McpServersOverStore.pinListing), as `tools` each server's
|
|
3343
3361
|
* listing in the harnesses' shape for the save's checks (blockersOf's `mcp`), and `pin` making the pin from them. A server
|
|
@@ -3410,8 +3428,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3410
3428
|
}
|
|
3411
3429
|
/** A definition being saved: refused (422 by field) when it can never run here; else what this host still lacks, and
|
|
3412
3430
|
* its pins (mcpListingOf, monidPinOf), each carrying from `previous` what its grants did not change. A revision that
|
|
3413
|
-
* names no place is checked where it would run (fallbackPlace).
|
|
3414
|
-
|
|
3431
|
+
* names no place is checked where it would run (fallbackPlace). `toolsUnnamed`: a create whose definition names no tools
|
|
3432
|
+
* (the store has given it its empty list by now), which would get a shell in the default box. */
|
|
3433
|
+
async function saveable(revision, previous, { toolsUnnamed = false } = {}) {
|
|
3415
3434
|
// The store's NewRevision keeps the revision's fields under `body` (AgenticBody|WorkflowBody); build the flat shape the
|
|
3416
3435
|
// host checks (runnable.ts RevisionShape) from it, as shapeOf does for a run's Revision.
|
|
3417
3436
|
const body = revision.body;
|
|
@@ -3426,6 +3445,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3426
3445
|
}
|
|
3427
3446
|
if (cliLearningOf(body) || sdkOf(body))
|
|
3428
3447
|
return { warnings: [], stamp: {} };
|
|
3448
|
+
const noPlace = await noPlaceOf(revision, toolsUnnamed);
|
|
3429
3449
|
await loginNow();
|
|
3430
3450
|
// A workflow's own issues, as POST /workflows/validate lists them (workflowIssues: the DSL's checks, the durable
|
|
3431
3451
|
// runner's refusal), refuse its save before anything is written, each at its path under definition.workflow. Asked
|
|
@@ -3444,7 +3464,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3444
3464
|
void install.ensure().catch((error) => log?.(logLine("harness_install_failed", { harness: install.entry.id, message: error.message })));
|
|
3445
3465
|
}
|
|
3446
3466
|
const named = (revision.kind === "agentic" ? { kind: "agentic", ...body } : workflowShape(body));
|
|
3447
|
-
const shape = named.place ? named : { ...named, place: fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
3467
|
+
const shape = named.place ? named : { ...named, place: await fallbackPlace(named.kind, named.tools ?? []), unnamed: true };
|
|
3448
3468
|
const listing = await mcpListingOf(revision, previous?.mcpPin);
|
|
3449
3469
|
const mcp = listing.tools;
|
|
3450
3470
|
const { monid, warnings: usage = [] } = (await monidPinOf(revision, previous)) ?? {};
|
|
@@ -3464,15 +3484,31 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3464
3484
|
blockers.push(...added.filter((b) => b.unpriced || b.short));
|
|
3465
3485
|
blockers.push(...added.filter((b) => !b.unpriced && !b.short).map((b) => ({ ...b, reason: "not_an_option", fix: "Pick another provider for this tool in definition.tool_settings, or clear the agent's default cap (max_cost_usd: 0).", host: false })));
|
|
3466
3486
|
}
|
|
3467
|
-
|
|
3487
|
+
// A shell tool with no place is refused there already (runnable.ts shellOnRunner); no tools named is refused here.
|
|
3488
|
+
const never = blockers.filter((b) => !b.host).map(issueOf);
|
|
3489
|
+
if (noPlace && !never.some((issue) => issue.field === noPlace.field))
|
|
3490
|
+
never.unshift(noPlace);
|
|
3468
3491
|
if (never.length)
|
|
3469
|
-
throw invalid(never
|
|
3492
|
+
throw invalid(never);
|
|
3470
3493
|
const mcpPin = listing.pin();
|
|
3471
3494
|
// A computer every tool of which is set to deny, here or in the agent's own settings: its runs never start it.
|
|
3472
3495
|
const denied = await deniedComputer(shape, settings.get(), shellOf);
|
|
3473
3496
|
const off = denied ? [{ field: "definition.computer", reason: "not_allowed", message: computerDeniedWords(denied) }] : [];
|
|
3474
3497
|
return { warnings: [...blockers.map(issueOf), ...off, ...usage], stamp: { ...(mcpPin ? { mcpPin } : {}), ...(monid ? { monidPin: monid } : {}) } };
|
|
3475
3498
|
}
|
|
3499
|
+
/** Why a new `revision` cannot be saved for want of a place, the one check a save (saveable) and an apply's plan
|
|
3500
|
+
* (planTemplate) both make, so a plan never says a create the apply refuses: an agentic revision that names no place
|
|
3501
|
+
* and would be given Docker's box (no tools named, `toolsUnnamed`, or a shell tool), where this server has none and the
|
|
3502
|
+
* runner has no shell (Mode 1), is refused, naming a box or the runner, never given another box (place.ts
|
|
3503
|
+
* noBoxRefusal). On Mode 2 it saves for the runner, as it always did. Native, CLI-learning and SDK agents run elsewhere. */
|
|
3504
|
+
async function noPlaceOf(revision, toolsUnnamed) {
|
|
3505
|
+
const body = revision.body;
|
|
3506
|
+
if (revision.kind !== "agentic" || nativeOf(body) || cliLearningOf(body) || sdkOf(body))
|
|
3507
|
+
return undefined;
|
|
3508
|
+
if (body.place !== undefined || body.computer !== undefined)
|
|
3509
|
+
return undefined;
|
|
3510
|
+
return noBoxRefusal(toolsUnnamed ? undefined : body.tools ?? [], boxOffers, toolOf, (await shellOf({ kind: "none" })) === "local");
|
|
3511
|
+
}
|
|
3476
3512
|
/** An agentic `revision`'s monid pin (monid.ts pinMonid) and a warning per endpoint priced by usage; a grant that
|
|
3477
3513
|
* cannot be pinned refuses the save (422). Undefined when it grants none. */
|
|
3478
3514
|
async function monidPinOf(revision, previous) {
|
|
@@ -3503,16 +3539,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3503
3539
|
};
|
|
3504
3540
|
/** POST /agents' body made into its agent, as that route makes one, with what this host still lacks for it. A new agent
|
|
3505
3541
|
* that names no place is given this server's box (place.ts defaultPlaceOf), stamped on its revision, when it names no
|
|
3506
|
-
* tools (it gets bash) or a tool that needs a shell
|
|
3507
|
-
* (browser), keeps the runner. */
|
|
3508
|
-
async function createAgentOf(body, template) {
|
|
3542
|
+
* tools (it gets bash) or a tool that needs a shell, and refused where Docker's box is not here and the runner has no
|
|
3543
|
+
* shell (saveable); one whose tools need none, or that names a tool the box refuses (browser), keeps the runner. */
|
|
3544
|
+
async function createAgentOf(body, template, { toolsUnnamed } = {}) {
|
|
3509
3545
|
let warnings = [];
|
|
3510
3546
|
const definition = checkDefinitionBody(body, { harnesses });
|
|
3511
3547
|
const named = Array.isArray(definition.definition.tools) ? definition.definition.tools : [];
|
|
3512
|
-
const place = fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3548
|
+
const place = await fallbackPlace("agentic", definition.definition.tools === undefined ? NEW_AGENT_TOOLS : named);
|
|
3513
3549
|
const tools = defaultToolsAt(place);
|
|
3514
3550
|
const entry = await agents.create(definition, async (revision) => {
|
|
3515
|
-
|
|
3551
|
+
// A template's apply says whether its package named its tools (applyWith): one that named none, and no computer
|
|
3552
|
+
// list, is the agent that would get Docker's box, whatever its grants compiled to, and is refused where there is none.
|
|
3553
|
+
const saved = await saveable(revision, null, { toolsUnnamed: toolsUnnamed ?? definition.definition.tools === undefined });
|
|
3516
3554
|
warnings = saved.warnings;
|
|
3517
3555
|
return saved.stamp;
|
|
3518
3556
|
}, place.mode === "sandbox" && tools ? { place, tools } : undefined, template);
|
|
@@ -3553,13 +3591,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3553
3591
|
throw new ApiError("agent_archived", `The agent ${id} is archived: unarchive it, then apply the ${pkg.name} template onto it again.`);
|
|
3554
3592
|
return entry;
|
|
3555
3593
|
}
|
|
3556
|
-
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning
|
|
3594
|
+
/** A replay's ports for agent `entry` (runner/promotion.ts askReplay, replayView): its learning as this server
|
|
3557
3595
|
* reads it, cut of the host's secrets as the learning reads cut them, and a replay run's launch made as a run's start
|
|
3558
3596
|
* makes one now (prepareLaunch: the agent's current revision, model, plane and learning start). */
|
|
3559
3597
|
const replayAskOf = (entry) => ({
|
|
3560
3598
|
admitAuxiliary: auxiliaryAdmitter(store, { data, project: startDeps.project }),
|
|
3561
3599
|
store, agentId: entry.agent.id, context: ctx, log: (line) => void log?.(line),
|
|
3562
|
-
|
|
3600
|
+
shown: () => learningShown(entry.agent.id),
|
|
3563
3601
|
launchOf: async (input) => {
|
|
3564
3602
|
const { launch, revision } = await prepareLaunch(startDeps, entry, { input });
|
|
3565
3603
|
return { launch, revisionId: revision.id };
|
|
@@ -3630,6 +3668,14 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3630
3668
|
* skipped for a connection this server lacks), and the computer it picks. Any other refusal is the apply's own. */
|
|
3631
3669
|
async function planTemplate(template, body) {
|
|
3632
3670
|
const p = await prepareApply(template, body, { plan: true });
|
|
3671
|
+
// A fresh apply refused for want of a place (createAgentOf's save) is refused here, in the same words: no plan of a
|
|
3672
|
+
// create the apply would refuse.
|
|
3673
|
+
if (!p.onto) {
|
|
3674
|
+
const { definition, skills } = checkDefinitionBody(p.made.agent, { harnesses });
|
|
3675
|
+
const refused = await noPlaceOf(makeRevision(definition, skills ?? {}, undefined), p.toolsUnnamed);
|
|
3676
|
+
if (refused)
|
|
3677
|
+
throw invalid([refused]);
|
|
3678
|
+
}
|
|
3633
3679
|
// A monid grant is pinned to monid's listing when the agent is saved (saveable: monidPinOf), read with the monid key:
|
|
3634
3680
|
// with none here the apply is refused, so the plan lists the key. A grant the agent's current pin carries reads
|
|
3635
3681
|
// nothing (pinMonid with no key answers before any request).
|
|
@@ -3766,7 +3812,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3766
3812
|
// The model of each tier its subagents run on (packageTiers): the package's where this server runs it.
|
|
3767
3813
|
const tiers = await packageTiers(env, pkg.model, harness ?? DEFAULT_HARNESS, model);
|
|
3768
3814
|
const modelWarnings = [...("warning" in picked && picked.warning ? [picked.warning] : []), ...(tiers.warning ? [tiers.warning] : [])].map((message) => ({ field: "model", reason: "not_an_option", message }));
|
|
3769
|
-
|
|
3815
|
+
// A package that names no tools gets a new agent's where a new agent goes (fallbackPlace): the box's shell tools in
|
|
3816
|
+
// Docker's box; none on the runner, Mode 2's included.
|
|
3817
|
+
const defaultTools = defaultToolsAt(await fallbackPlace("agentic", NEW_AGENT_TOOLS)) ?? [];
|
|
3770
3818
|
// A grant never lifts a deny the owner set on this server: that tool keeps it, and the answer says so.
|
|
3771
3819
|
const server = settings.get();
|
|
3772
3820
|
const denied = grants.filter((tool) => { const set = permissionFrom(tool, server); return set.from === "server" && set.permission === "deny"; });
|
|
@@ -3790,9 +3838,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3790
3838
|
if (!skip)
|
|
3791
3839
|
return [];
|
|
3792
3840
|
const keptOn = had.find((row) => row.enabled && row.name === String(trigger.name).trim());
|
|
3793
|
-
//
|
|
3794
|
-
|
|
3795
|
-
|
|
3841
|
+
// Under the run-keys setting the kept one's firings bring no keys. One that starts a run of this revision is refused
|
|
3842
|
+
// for the keys it owes, but the kept trigger's target is not checked here: a message_run trigger whose run is pinned
|
|
3843
|
+
// to an earlier revision that owes no keys still messages it, and that run may spend. So the warning promises no refusal.
|
|
3844
|
+
const kept = options.apiOnly
|
|
3845
|
+
? `is kept as it was, and still fires: PATCH /v2/triggers/${keptOn?.id} with {"enabled": false} turns it off`
|
|
3846
|
+
: `is kept as it was and still fires until you turn it off (PATCH /v2/triggers/${keptOn?.id} with {"enabled": false}): a firing that would start a run of this revision is refused 409 for the keys it owes, but one aimed at a run of an earlier revision that owes none still reaches that run, which may spend`;
|
|
3847
|
+
return [[i, keptOn ? { ...skip, message: `${skip.message} The agent's trigger ${keptOn.id} of that name ${kept}.` } : skip]];
|
|
3796
3848
|
}));
|
|
3797
3849
|
const unmade = (i) => emptyFeeds.has(i) || hostless.has(i);
|
|
3798
3850
|
const refusedTriggers = madeTriggerIssues(made.triggers, options.triggerClock?.now() ?? Date.now(), pkg.inputSchema).filter((issue) => !unmade(Number(/^triggers\.(\d+)\./.exec(issue.field)?.[1])));
|
|
@@ -3859,12 +3911,15 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3859
3911
|
// triggers are the package's is on each trigger (its mark), not here.
|
|
3860
3912
|
const digest = parametersDigest(sealKey, stable(parameters));
|
|
3861
3913
|
const origin = { id: pkg.id, version: pkg.version, sha: pkg.origin?.sha ?? null, parameters_digest: digest, secrets: declared };
|
|
3862
|
-
|
|
3914
|
+
// A package that names no tools and no computer list makes the agent a create that names no tools makes (createAgentOf),
|
|
3915
|
+
// whatever its grants compiled to: it would get Docker's box, and is refused where there is none (noPlaceOf).
|
|
3916
|
+
const toolsUnnamed = pkg.tools === undefined && !pick;
|
|
3917
|
+
return { pkg, onto, missing, unsaved, saved, mapped, grants, pick, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned: [...keyWarnings, ...skipped, ...kept, ...modelWarnings, ...computerWarnings] };
|
|
3863
3918
|
}
|
|
3864
3919
|
/** applyTemplate's work, in its turn on the agent where it has agent_id: prepareApply's reads and checks, then its
|
|
3865
3920
|
* writes. */
|
|
3866
3921
|
async function applyWith(template, body) {
|
|
3867
|
-
const { pkg, onto, saved, mapped, grants, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3922
|
+
const { pkg, onto, saved, mapped, grants, toolsUnnamed, made, emptyFeeds, hostless, unmade, hadByName, remade, resent, removing, digest, origin, warned } = await prepareApply(template, body, { plan: false });
|
|
3868
3923
|
// A fresh apply of what already made a live agent here (the same package and parameters) still makes one, and says
|
|
3869
3924
|
// which is there: an apply with its agent_id updates that one instead. Read before this apply's agent is made.
|
|
3870
3925
|
const twins = (await twinsOf(onto, pkg.id, digest))
|
|
@@ -3878,7 +3933,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3878
3933
|
throw new ApiError("precondition_failed", `The agent ${onto.agent.id} changed while this apply of the ${pkg.name} template read it (an edit, or another apply, wrote a revision): nothing was changed. Apply it with agent_id again to update the agent as it is now.`);
|
|
3879
3934
|
throw error;
|
|
3880
3935
|
})
|
|
3881
|
-
: await createAgentOf(made.agent, origin);
|
|
3936
|
+
: await createAgentOf(made.agent, origin, { toolsUnnamed });
|
|
3882
3937
|
// An update's triggers are reconciled by name with the ones the agent has: the package's trigger of a name the agent
|
|
3883
3938
|
// has (of the same kind) is changed in place, keeping its id, a feed's seen items, a webhook's secret and whether the
|
|
3884
3939
|
// owner turned it off (an unmarked one is adopted so, and only so: notOurs above), its settings the package's whole
|
|
@@ -4428,6 +4483,40 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4428
4483
|
return { ...(source !== undefined ? { source } : {}), ...windowParams(url), ...(model !== undefined ? { model } : {}) };
|
|
4429
4484
|
}
|
|
4430
4485
|
async function runsPage(url, filter, origin, only = {}) {
|
|
4486
|
+
const vd = viewDepsFor(origin);
|
|
4487
|
+
// The Agent Factory's page, from the rows too: each run's list item and what its listing keeps for the factory
|
|
4488
|
+
// (store-view.ts KeptFactory), built once per change of the run as the list below builds them, so a refresh builds no
|
|
4489
|
+
// view of a run that has not moved, however many runs the board holds and however long they ran. Two reads for the
|
|
4490
|
+
// page (the listings, the runners' ticks), then per run only what is read as it stands now: who observes it
|
|
4491
|
+
// (observationOf) and its computer (runComputerRead, which reads a journal only for a desktop or phone that is up,
|
|
4492
|
+
// or a computer held for its owner). A listing behind, cut of other secrets, or built before listings kept the
|
|
4493
|
+
// factory's part is built first, once: the page shows that build whether or not its write landed (a run that moved
|
|
4494
|
+
// again meanwhile stays behind, for the lister or the next page), so a busy run costs one build a page, never the
|
|
4495
|
+
// several a status filter makes below (listNow), which this page has no need of.
|
|
4496
|
+
if (url.searchParams.has("scope"))
|
|
4497
|
+
return factoryRunsPage(store, url, filter, async (rows) => {
|
|
4498
|
+
const secrets = serverSecrets();
|
|
4499
|
+
const now = vd.now ?? Date.now;
|
|
4500
|
+
const ids = rows.map((row) => row.id);
|
|
4501
|
+
const kept = new Map((await store.runs.listings(ids)).map((read) => [read.id, read]));
|
|
4502
|
+
const ticks = new Map((await store.live.read(ids)).map((tick) => [tick.runId, tick.updatedAt]));
|
|
4503
|
+
const runs = [];
|
|
4504
|
+
for (const row of rows) {
|
|
4505
|
+
const read = kept.get(row.id);
|
|
4506
|
+
// A run purged since the page's rows were read has no listing to show (Runs.listings).
|
|
4507
|
+
if (!read)
|
|
4508
|
+
continue;
|
|
4509
|
+
const held = read.listing !== null && !read.behind && builtOfNow(read.listing, secrets) && keptFactory(read.listing, secrets) ? read.listing : undefined;
|
|
4510
|
+
const listing = held ?? (await lister.build(row.id, read.listMark, vd)).listing;
|
|
4511
|
+
const factory = listing && keptFactory(listing, secrets);
|
|
4512
|
+
if (!listing || !factory)
|
|
4513
|
+
continue;
|
|
4514
|
+
const observation = await observationOf(store, factory.observed, liveOf(row, now()), ticks.get(row.id), now);
|
|
4515
|
+
const summary = { ...listedItem(listing, origin, row.archivedAt ?? read.agentArchivedAt, secrets), factory: { ...factory.activity, observation } };
|
|
4516
|
+
runs.push({ ...summary, ...(await runComputerRead(store, row.id, summary, { context: ctx })) });
|
|
4517
|
+
}
|
|
4518
|
+
return runs;
|
|
4519
|
+
});
|
|
4431
4520
|
const limit = limitOf(url.searchParams.get("limit"));
|
|
4432
4521
|
const offset = cursorOf(url.searchParams.get("cursor"));
|
|
4433
4522
|
const status = url.searchParams.get("status");
|
|
@@ -4439,7 +4528,6 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4439
4528
|
const archived = archivedParam(url);
|
|
4440
4529
|
// `label=<key>:<value>`, once: only the runs holding it (run-labels.ts), filtered in the store.
|
|
4441
4530
|
const labels = labelFilter(url.searchParams.getAll("label"));
|
|
4442
|
-
const vd = viewDepsFor(origin);
|
|
4443
4531
|
// The page from the runs' rows alone (store/schema.ts RUN_LISTING_COLUMNS): filtered (`status` on the listing's status),
|
|
4444
4532
|
// ordered and cut to the page in one query, so a list costs the same at ten runs and at thousands, however long their
|
|
4445
4533
|
// journals. An audit's shadow run is no row of the list (learn/audit.ts): it is read by id, and its cost is its served
|
|
@@ -4456,7 +4544,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4456
4544
|
// A write that lands while a listing is built moves the run's mark, so the listing is not written (Runs.putListing),
|
|
4457
4545
|
// and a run still going is left with no status on its row: the build is made again from the mark that write left, up
|
|
4458
4546
|
// to LIST_TRIES builds, so a filter never leaves off a run because a write met its build. Each is the lister's build
|
|
4459
|
-
// (Lister.build), so a held listing built here has its agent's learning
|
|
4547
|
+
// (Lister.build), so a held listing built here has its agent's learning read by the lister's passes after it.
|
|
4460
4548
|
const listNow = async (runId, read) => {
|
|
4461
4549
|
for (let mark = read, tries = 1;; tries++) {
|
|
4462
4550
|
const { listing, written } = await lister.build(runId, mark, vd);
|
|
@@ -4957,16 +5045,13 @@ async function startHolding(options, data, checked, stops) {
|
|
|
4957
5045
|
// skew check; left out when the store cannot say (a read that failed).
|
|
4958
5046
|
const state = await store.schemaState?.().catch(() => undefined);
|
|
4959
5047
|
const storeSchema = state ? { store_schema: { version: state.version, runner_floor: state.runnerFloor, known: state.known } } : {};
|
|
4960
|
-
//
|
|
4961
|
-
// the
|
|
4962
|
-
|
|
4963
|
-
const keptShown = byOwnerSession(req) || bearer(req.headers.authorization, req);
|
|
4964
|
-
if (!keptShown && req.headers.authorization !== undefined)
|
|
5048
|
+
// This route answers before any bearer check, the same to every caller. A bearer this server does not take still
|
|
5049
|
+
// gets the answer, and the auth_failed line any other route writes for it.
|
|
5050
|
+
if (req.headers.authorization !== undefined && !byOwnerSession(req) && !bearer(req.headers.authorization, req))
|
|
4965
5051
|
authFailed(`/v2${path}`, "wrong_token");
|
|
4966
|
-
const keptCap = { ...answer.features.harness_keys, kept: keptShown ? answer.features.harness_keys.kept : [] };
|
|
4967
5052
|
// tools[].held: the server's keyless holds on each web tool now (web-run.ts withHeld), never cached.
|
|
4968
5053
|
// features.api_keys.routes: false on an API-only server, which serves none of the keys' routes and reads no key.
|
|
4969
|
-
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features,
|
|
5054
|
+
return send(res, 200, { ...answer, tools: withHeld(answer.tools), ...storeSchema, runner_refused: runnerRefused, features: { ...answer.features, computers: await computerCapabilities(computersOf()), triggers: { ...answer.features.triggers, public_url: Boolean(options.publicUrl) }, claude_login: loginServed, api_keys: { ...answer.features.api_keys, routes: !options.apiOnly } } });
|
|
4970
5055
|
}
|
|
4971
5056
|
if (found.name === "getOpenapi")
|
|
4972
5057
|
return send(res, 200, servedOpenapi(openapi, ownerCookieName(req)));
|
|
@@ -5613,9 +5698,9 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5613
5698
|
// the archive, each turned on again by PATCH /triggers/{id} {enabled: true}.
|
|
5614
5699
|
// In the agent's delete turn (agentWrite): an unarchive sent while its purge runs waits for it and is 410, so no
|
|
5615
5700
|
// run of it starts between the purge's live check and its tombstone.
|
|
5616
|
-
// On an API-only server with the launch hook
|
|
5617
|
-
//
|
|
5618
|
-
const turnOn = options.apiOnly && options.launchHook ? (
|
|
5701
|
+
// On an API-only server with the launch hook the unarchive turns its schedule and feed triggers on again (the ones
|
|
5702
|
+
// its apply makes there), so a backend's redeploy needs no PATCH of each.
|
|
5703
|
+
const turnOn = options.apiOnly && options.launchHook ? (trigger) => apiOnlyTurnsOn(trigger.source.kind, trigger.target.kind, true) : undefined;
|
|
5619
5704
|
const triggersOff = await agentWrite(id, () => (found.name === "archiveAgent" ? triggers.agentArchived(id) : triggers.agentUnarchived(id, turnOn)));
|
|
5620
5705
|
// An archived agent's own computer is deleted (an unarchived one gets a new one at its next persistent run).
|
|
5621
5706
|
if (found.name === "archiveAgent")
|
|
@@ -5724,7 +5809,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5724
5809
|
case "deleteRun": {
|
|
5725
5810
|
// In its agent's delete turn (an agent's delete or purge, or another purge of one of its runs, finishes first), the
|
|
5726
5811
|
// run read in that turn, so a DELETE after one that finished is 204 again (purgeRun: a purged run's only work is
|
|
5727
|
-
// its learning
|
|
5812
|
+
// its learning rows' delete, again).
|
|
5728
5813
|
const row = ID.test(id) ? await store.runs.get(id) : undefined;
|
|
5729
5814
|
if (!row)
|
|
5730
5815
|
throw new ApiError("not_found", `no run ${id}`);
|
|
@@ -5804,11 +5889,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
5804
5889
|
const kept = await runWrite(row.agentId, row.id, async () => {
|
|
5805
5890
|
// Kept with what it asks of the run's learning (runner/feedback-round.ts): nothing, or a look-back.
|
|
5806
5891
|
// Its feedback round is a turn with no caller's model key: on the server's key for the run's route, else not opened.
|
|
5807
|
-
|
|
5892
|
+
// A purge of the run from another process, past the check above: the grade's write refuses it in its own
|
|
5893
|
+
// transaction (Store.learning changeRecords), nothing written, and it answers as a purged run's grade does.
|
|
5894
|
+
const graded = gradeView(await keepGrade(store, row.agentId, grade, typeof body.label === "string" ? body.label : undefined, (launch) => !serverKeyMissing(env, { kind: "agentic", model: launch.model, native: Boolean(launch.native) })).catch(async (error) => {
|
|
5895
|
+
const now = error instanceof LearningRecordRefused ? await store.runs.get(row.id) : undefined;
|
|
5896
|
+
throw now && now.purgedAt !== null ? purgedRun(now) : error;
|
|
5897
|
+
}));
|
|
5808
5898
|
// A grade of a run its learned workflow answered alone is an audit row too (runner/audit.ts gradeRow): the hold rule
|
|
5809
5899
|
// reads it with the shadows'. A row not written now is logged, never the grade refused.
|
|
5810
5900
|
const said = (line) => log?.(logLine("audit", { run: row.id, said: line }));
|
|
5811
|
-
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx,
|
|
5901
|
+
await gradeRow({ store, agentId: row.agentId, revisionId: row.revisionId, context: ctx, shown: () => learningShown(row.agentId), log: said }, row, grade.correct, grade.expected).catch((error) => said(`the grade wrote no audit row (${error?.message ?? error})`));
|
|
5812
5902
|
return graded;
|
|
5813
5903
|
});
|
|
5814
5904
|
// Its workflow's name cut as GET /runs/{id}/learning cuts it (learningShown); withheld whole when that cut can't be
|
|
@@ -6268,6 +6358,17 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6268
6358
|
const { revoked } = await plan.signOut();
|
|
6269
6359
|
return send(res, 200, revoked ? { revoked } : { revoked, message: SIGN_OUT_UNCONFIRMED });
|
|
6270
6360
|
}
|
|
6361
|
+
// Its sign-out (claude-login.ts signOutClaudeLogin): AgentRun's own login removed, the mode off; this machine's own
|
|
6362
|
+
// login refused in words.
|
|
6363
|
+
case "signOutClaudeLogin":
|
|
6364
|
+
try {
|
|
6365
|
+
return send(res, 200, await signOutClaudeLogin(loginDeps()), { "cache-control": "no-store" });
|
|
6366
|
+
}
|
|
6367
|
+
catch (error) {
|
|
6368
|
+
if (error instanceof ClaudeLoginRefused)
|
|
6369
|
+
throw new ApiError(error.code, error.message);
|
|
6370
|
+
throw error;
|
|
6371
|
+
}
|
|
6271
6372
|
// Claude Code's login on this machine (claude-login.ts): only its status is read, by asking the CLI.
|
|
6272
6373
|
case "getClaudeLogin":
|
|
6273
6374
|
case "turnOnClaudeLogin":
|
|
@@ -6299,6 +6400,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6299
6400
|
const answer = await modelGatewayRoute({ store, sealKey: seal.key, env: own(withSecrets(base, "own")), changed: gatewayChanged }, found.name, { ...(body !== undefined ? { body } : {}), signal: stopping.signal });
|
|
6300
6401
|
return send(res, 200, answer, { "cache-control": "no-store" });
|
|
6301
6402
|
}
|
|
6403
|
+
// A free local model (local-model.ts): never through `idempotent`, as a pull is one at a time and says so itself.
|
|
6404
|
+
case "getLocalModel":
|
|
6405
|
+
return send(res, 200, await localModelView(localModelDeps()), { "cache-control": "no-store" });
|
|
6406
|
+
case "pullLocalModel":
|
|
6407
|
+
return send(res, 202, await pullLocalModel(localModelDeps(), await bodyOf(req)), { "cache-control": "no-store" });
|
|
6302
6408
|
// Never through `idempotent`: its record keeps the body, and a body may hold a credential.
|
|
6303
6409
|
case "listMcpServers":
|
|
6304
6410
|
return send(res, 200, await mcpServers.list());
|
|
@@ -6500,24 +6606,23 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6500
6606
|
// definition's: an archived agent's too.
|
|
6501
6607
|
case "getAgentLearning": {
|
|
6502
6608
|
const entry = await needAgent(id);
|
|
6503
|
-
// The agent's learning view: its corrections, workflows and log from its learning
|
|
6609
|
+
// The agent's learning view: its corrections, workflows and log from its learning rows; its run-fared counts and
|
|
6504
6610
|
// its impact over the one store (agentLearningOverStore), from each run's launch, journal and learning end.
|
|
6505
6611
|
const { counts, impact } = await agentLearningOverStore(store, id);
|
|
6506
6612
|
// Each workflow's status past its README.md's: where it stands as GET .../learning/promotions says it (servingStateOf
|
|
6507
6613
|
// over the same records and the money rule's decision, costStopOverStore), so the view never says a workflow serves
|
|
6508
6614
|
// that does not run first.
|
|
6509
|
-
const records = await promotionsOf(store.
|
|
6510
|
-
const refused = await refusedFor(id, records);
|
|
6615
|
+
const records = await promotionsOf(store.learning, id);
|
|
6511
6616
|
const costStop = await costStopOverStore(store, id);
|
|
6512
6617
|
const body = entry.revision?.body;
|
|
6513
|
-
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6514
|
-
return send(res, 200, { ...await agentLearning(
|
|
6618
|
+
const modelEnv = !body || sdkOf(body) || nativeOf(body) ? env : envAtPlace(env, resolvePlace(body.place, await fallbackPlace(entry.revision.kind === "workflow" ? "workflow" : "agentic", body.tools ?? [])));
|
|
6619
|
+
return send(res, 200, { ...await agentLearning(store, id, await learningShown(id), counts, impact, (workflow) => servingStateOf(records, workflow, costStop)), learning_model: await learningModelOf(modelEnv, entry.revision) });
|
|
6515
6620
|
}
|
|
6516
6621
|
case "getLearningCost": {
|
|
6517
6622
|
await needAgent(id);
|
|
6518
6623
|
// The agent's cost per run over the one store (agentCostOverStore): each ended run's figures and path, aggregates only.
|
|
6519
6624
|
const { limit, csv } = learningCostQuery(url);
|
|
6520
|
-
const read = await agentCostOverStore(store, id, limit
|
|
6625
|
+
const read = await agentCostOverStore(store, id, limit);
|
|
6521
6626
|
// Each workflow's name as the other learning reads show it: one that holds a secret or a sign-in's value is cut.
|
|
6522
6627
|
const shown = await learningShown(id);
|
|
6523
6628
|
const cost = { ...read, runs: read.runs.map((run) => (run.workflow === null ? run : { ...run, workflow: shown.name(run.workflow) })), workflows: read.workflows.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), bill: { ...read.bill, revisions: read.bill.revisions.map((one) => ({ ...one, workflow: shown.name(one.workflow) })), holds: read.bill.holds.map((one) => ({ ...one, workflow: shown.name(one.workflow), reason: shown.text(one.reason) })) } };
|
|
@@ -6533,28 +6638,25 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6533
6638
|
// its holds (a check's, an audit's). Every text in them cut as the other learning reads cut theirs
|
|
6534
6639
|
// (promotionsShown: a reason as well as each workflow's name). Beside what serves, each one's state, its check's
|
|
6535
6640
|
// numbers and its audit line (learn/audit.ts servingLinesOf), at the agent's numbers.
|
|
6536
|
-
const records = await promotionsOf(store.
|
|
6537
|
-
// Every champion below skips a record the purge gate refuses at its commit, as a run's claim does (championOf).
|
|
6538
|
-
const refused = await refusedFor(id, records);
|
|
6641
|
+
const records = await promotionsOf(store.learning, id);
|
|
6539
6642
|
const shown = await learningShown(id);
|
|
6540
|
-
const shownRead = promotionsShown(records, shown
|
|
6643
|
+
const shownRead = promotionsShown(records, shown);
|
|
6541
6644
|
// A ledger that can't be read now leaves each audit line at no rows, never the read refused.
|
|
6542
6645
|
const loop = auditLoopOf(entry.revision?.body?.learning);
|
|
6543
6646
|
// Each one's state with the money rule's decision a run's launch reads (costStopOverStore): a champion it stopped
|
|
6544
6647
|
// running first reads `stopped`.
|
|
6545
|
-
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id)
|
|
6648
|
+
const lines = servingLinesOf(records, await auditsOfAgent(id).catch(() => []), loop, await costStopOverStore(store, id));
|
|
6546
6649
|
// Why its runs are never audited, when the agent can call a tool that writes (learn/audit.ts auditWriterOf, the
|
|
6547
6650
|
// rule startAudit reads); and how many of the serving revision's runs a trigger started (never audited).
|
|
6548
6651
|
const writer = auditWriterOf(entry.revision ?? undefined);
|
|
6549
6652
|
const auditsOff = writer === undefined ? null : shown.text(auditsOffWords(writer));
|
|
6550
|
-
// The champion's own revision, read by its recorded digest
|
|
6551
|
-
//
|
|
6552
|
-
//
|
|
6653
|
+
// The champion's own revision, read by its recorded digest from the workflow's versions. Its nodes with their tiers
|
|
6654
|
+
// and code checks, and the check it was promoted on; nodes null when no version holds its text (or the rows can't
|
|
6655
|
+
// be read now).
|
|
6553
6656
|
const championRead = async (workflow, digest) => {
|
|
6554
|
-
const champion = championOf(records, workflow
|
|
6657
|
+
const champion = championOf(records, workflow);
|
|
6555
6658
|
const record = champion?.digest === digest ? champion : undefined;
|
|
6556
|
-
const
|
|
6557
|
-
const read = await workflowAtDigest(data, id, workflow, digest, commits, store).catch(() => undefined);
|
|
6659
|
+
const read = await workflowAtDigest(store, id, workflow, digest).catch(() => undefined);
|
|
6558
6660
|
let doc;
|
|
6559
6661
|
try {
|
|
6560
6662
|
doc = read ? JSON.parse(read.text) : undefined;
|
|
@@ -6564,7 +6666,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6564
6666
|
}
|
|
6565
6667
|
return shownDeep({ digest, commit: read?.commit ?? null, nodes: doc === undefined ? null : workflowNodesOf(doc), check: record?.check ?? null }, shown);
|
|
6566
6668
|
};
|
|
6567
|
-
const serving = await Promise.all(servingOf(records
|
|
6669
|
+
const serving = await Promise.all(servingOf(records).map(async (one, i) => ({
|
|
6568
6670
|
...shownRead.serving[i], ...lines[i], audits_off: auditsOff,
|
|
6569
6671
|
not_auditable: one.digest === null ? 0 : await notAuditableOf(store, id, one.workflow, one.digest, loop).catch(() => 0),
|
|
6570
6672
|
champion: one.digest === null ? null : await championRead(one.workflow, one.digest),
|
|
@@ -6573,7 +6675,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6573
6675
|
}
|
|
6574
6676
|
case "listLearningAudits": {
|
|
6575
6677
|
await needAgent(id);
|
|
6576
|
-
// The audit ledger (learn/audit.ts
|
|
6678
|
+
// The audit ledger (the agent's audit records, learn/audit.ts), oldest first: each workflow's name and every other text cut as the
|
|
6577
6679
|
// promotions read cuts its own.
|
|
6578
6680
|
const shown = await learningShown(id);
|
|
6579
6681
|
const rows = await auditsOfAgent(id);
|
|
@@ -6600,11 +6702,11 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6600
6702
|
}
|
|
6601
6703
|
case "listLearningLog":
|
|
6602
6704
|
await needAgent(id);
|
|
6603
|
-
return send(res, 200, await learningLog(
|
|
6705
|
+
return send(res, 200, await learningLog(store, id, url.searchParams, await learningShown(id)));
|
|
6604
6706
|
case "getLearningCorrections": {
|
|
6605
6707
|
await needAgent(id);
|
|
6606
6708
|
// corrections.md whole, as every run of the agent is served it under # Learned, with its ETag in the body and the header.
|
|
6607
|
-
const read = await correctionsView(
|
|
6709
|
+
const read = await correctionsView(store, id, await learningShown(id));
|
|
6608
6710
|
return send(res, 200, read, { etag: read.etag });
|
|
6609
6711
|
}
|
|
6610
6712
|
case "putLearningCorrections": {
|
|
@@ -6613,7 +6715,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6613
6715
|
// What it refuses is what the reads cut: the host's secrets and the agent's sign-in pointers.
|
|
6614
6716
|
const refuse = await learningValues(id);
|
|
6615
6717
|
// A write to the agent's learning: in its delete turn (agentWrite), the body read before, outside it.
|
|
6616
|
-
const written = await agentWrite(id, () => correctionsWrite(
|
|
6718
|
+
const written = await agentWrite(id, () => correctionsWrite(store, id, { text, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse }));
|
|
6617
6719
|
return send(res, 200, written, { etag: written.etag });
|
|
6618
6720
|
}
|
|
6619
6721
|
case "deleteAgentLearning": {
|
|
@@ -6627,10 +6729,10 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6627
6729
|
}
|
|
6628
6730
|
case "listLearnedWorkflowRevisions":
|
|
6629
6731
|
await needAgent(id);
|
|
6630
|
-
return send(res, 200, await workflowRevisions(
|
|
6732
|
+
return send(res, 200, await workflowRevisions(store, id, second, url.searchParams, await learningShown(id)));
|
|
6631
6733
|
case "readLearningFile":
|
|
6632
6734
|
await needAgent(id);
|
|
6633
|
-
return sendText(res, 200, await readLearnedFile(
|
|
6735
|
+
return sendText(res, 200, await readLearnedFile(store, id, second, await learningShown(id)));
|
|
6634
6736
|
case "retireLearningFile":
|
|
6635
6737
|
case "approveLearningFile":
|
|
6636
6738
|
case "restoreLearningFile": {
|
|
@@ -6638,7 +6740,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6638
6740
|
const refuse = await learningValues(id);
|
|
6639
6741
|
const action = found.name === "approveLearningFile" ? "approve" : found.name === "restoreLearningFile" ? "restore" : "retire";
|
|
6640
6742
|
// A change to a workflow is a write to the agent's learning: in its delete turn (agentWrite).
|
|
6641
|
-
const written = await agentWrite(id, () => changeWorkflow(
|
|
6743
|
+
const written = await agentWrite(id, () => changeWorkflow(store, id, second, { action, ifMatch: typeof req.headers["if-match"] === "string" ? req.headers["if-match"] : undefined, refuse, draftTools: () => learnedDraftToolsOf(id) }));
|
|
6642
6744
|
// A run's list row that read a workflow held for the owner's OK says what the folder says now, at the next list.
|
|
6643
6745
|
await lister.learningChanged(id);
|
|
6644
6746
|
return sendText(res, written.status, { ...written, text: secretsShown(refuse).text(written.text) });
|
|
@@ -6674,7 +6776,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6674
6776
|
case "getRunLearning": {
|
|
6675
6777
|
const run = await needRun(id);
|
|
6676
6778
|
// The run's learning view over the store (learning-1's runLearningOverStore): its end, the notes it was given and its seed
|
|
6677
|
-
// from its launch, what it holds for the owner's OK as the store's run view reads it (
|
|
6779
|
+
// from its launch, what it holds for the owner's OK as the store's run view reads it (at its agent's newest save), as main.
|
|
6678
6780
|
// Cut by the run's one cut, and refused for a withheld run (run-learning-served.ts).
|
|
6679
6781
|
return send(res, 200, await servedRunLearning({ serverSecrets, signIns, sealKey, statuses }, store, run.id));
|
|
6680
6782
|
}
|
|
@@ -6825,9 +6927,18 @@ async function startHolding(options, data, checked, stops) {
|
|
|
6825
6927
|
return send(res, 200, triggerRotated(id, (await triggers.rotate(id)).secret, new Date().toISOString()));
|
|
6826
6928
|
case "getTrigger":
|
|
6827
6929
|
return send(res, 200, withSecretOf(await triggers.get(id)));
|
|
6828
|
-
case "updateTrigger":
|
|
6930
|
+
case "updateTrigger": {
|
|
6931
|
+
const body = await bodyOf(req);
|
|
6932
|
+
// On an API-only server, `enabled` alone, and on only where its apply would make the trigger (api-only.ts).
|
|
6933
|
+
if (options.apiOnly) {
|
|
6934
|
+
const trigger = await triggers.get(id);
|
|
6935
|
+
const refused = apiOnlyTriggerEdit(body, trigger.source.kind, options.launchHook !== undefined, trigger.target.kind);
|
|
6936
|
+
if (refused.length)
|
|
6937
|
+
throw invalid(refused);
|
|
6938
|
+
}
|
|
6829
6939
|
// Its secret's metadata as a read answers it, so a page showing the changed trigger keeps saying it is set.
|
|
6830
|
-
return send(res, 200, withSecretOf(await triggers.update(id,
|
|
6940
|
+
return send(res, 200, withSecretOf(await triggers.update(id, body)));
|
|
6941
|
+
}
|
|
6831
6942
|
case "deleteTrigger": {
|
|
6832
6943
|
// Deleted here whatever its sender says; what could not be removed there is answered (Composio's instance).
|
|
6833
6944
|
const said = await triggers.remove(id);
|
|
@@ -7477,6 +7588,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7477
7588
|
// An upgraded socket is no connection closeAllConnections ends, and server.close waits for it.
|
|
7478
7589
|
viewers.close();
|
|
7479
7590
|
clearInterval(routeTick);
|
|
7591
|
+
// A tick already running reads the store: waited out here, before the store closes below.
|
|
7592
|
+
await Promise.all(routeTicks);
|
|
7480
7593
|
await attach.close();
|
|
7481
7594
|
await new Promise((done) => (server.close(done), server.closeAllConnections()));
|
|
7482
7595
|
// No request is left to use a key: its last-use writes end before the store they write to closes.
|
|
@@ -7514,7 +7627,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
7514
7627
|
tokenMade: stored?.made ?? false,
|
|
7515
7628
|
...(setupUrl ? { setupUrl, setupOpen: openSetup } : {}),
|
|
7516
7629
|
...(consoleSessions ? { launchCode: consoleSessions.code } : {}),
|
|
7517
|
-
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env)),
|
|
7630
|
+
boxesLine: boxesLine(boxOffers, enabledBoxes(env), boxAllow, boxesByDefault(env), (await shellOf({ kind: "none" })) === "local"),
|
|
7518
7631
|
attachHub,
|
|
7519
7632
|
beside,
|
|
7520
7633
|
dial: { ...(options.publicUrl ? { url: options.publicUrl.replace(/\/+$/, "") } : {}), tokens: attach.machineTokens, hub: attachHub },
|