@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.56
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 +142 -2
- package/README.md +310 -98
- package/dist/adapters.d.ts +11 -0
- package/dist/adapters.js +49 -0
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +6 -13
- package/dist/agents-store.js +6 -5
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-only.d.ts +16 -4
- package/dist/api-only.js +23 -7
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +16 -1
- package/dist/chatgpt-plan.js +116 -12
- package/dist/claude-login.d.ts +34 -5
- package/dist/claude-login.js +31 -7
- package/dist/claude-sign-in.d.ts +35 -0
- package/dist/claude-sign-in.js +90 -0
- package/dist/cli.js +5 -3
- package/dist/composio-made.d.ts +26 -1
- package/dist/composio-made.js +39 -2
- package/dist/composio-preset.d.ts +3 -2
- package/dist/composio-preset.js +46 -14
- package/dist/computer-held-routes.js +2 -3
- package/dist/computer-setting.d.ts +4 -2
- package/dist/computer-setting.js +0 -2
- package/dist/computers-running.d.ts +8 -0
- package/dist/computers-running.js +27 -0
- package/dist/console/assets/backend-Boh7tC4i.js +166 -0
- package/dist/console/assets/index-CQ3cJRzI.js +746 -0
- package/dist/console/assets/index-DKkaS3a0.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/docker-host-addresses.d.ts +23 -3
- package/dist/docker-host-addresses.js +90 -18
- package/dist/exa-keyless.d.ts +2 -3
- package/dist/exa-keyless.js +43 -127
- package/dist/firecrawl-keyless.d.ts +41 -0
- package/dist/firecrawl-keyless.js +152 -0
- package/dist/handed-secret.d.ts +3 -1
- package/dist/handed-secret.js +4 -2
- package/dist/harness-keys.d.ts +98 -0
- package/dist/harness-keys.js +247 -0
- package/dist/harness-recipe-entry.d.ts +14 -9
- package/dist/harness-recipe-entry.js +25 -14
- package/dist/harness-table.d.ts +16 -1
- package/dist/harness-table.js +19 -7
- package/dist/harness.d.ts +4 -0
- package/dist/harness.js +12 -1
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +10 -0
- package/dist/import-summary.d.ts +1 -1
- package/dist/import-summary.js +1 -1
- package/dist/import.d.ts +5 -5
- package/dist/import.js +54 -67
- package/dist/key-refusal.d.ts +21 -5
- package/dist/key-refusal.js +231 -37
- package/dist/keyless-mcp.d.ts +36 -0
- package/dist/keyless-mcp.js +127 -0
- package/dist/learn/audit.d.ts +3 -3
- package/dist/learn/audit.js +3 -3
- package/dist/learn/commit.d.ts +8 -7
- package/dist/learn/commit.js +60 -20
- package/dist/learn/compile.d.ts +4 -3
- package/dist/learn/compile.js +7 -5
- package/dist/learn/folder.d.ts +16 -3
- package/dist/learn/folder.js +46 -13
- package/dist/learn/promote.d.ts +37 -13
- package/dist/learn/promote.js +112 -40
- package/dist/learn/secrets.d.ts +20 -10
- package/dist/learn/secrets.js +44 -176
- package/dist/learning-routes.d.ts +22 -17
- package/dist/learning-routes.js +40 -39
- package/dist/learning.js +2 -2
- package/dist/llms.txt +1 -1
- package/dist/manifest.d.ts +10 -0
- package/dist/manifest.js +30 -0
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +5 -2
- package/dist/mcp-secret-writes.d.ts +16 -7
- package/dist/mcp-secret-writes.js +35 -27
- package/dist/mcp-servers-store.d.ts +30 -6
- package/dist/mcp-servers-store.js +112 -28
- package/dist/mcp-sources.d.ts +10 -2
- package/dist/mcp-sources.js +9 -2
- package/dist/mcp-store.d.ts +13 -7
- package/dist/mcp-store.js +12 -9
- package/dist/model-form.d.ts +3 -2
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +20 -4
- package/dist/model.js +68 -9
- package/dist/native/history.d.ts +1 -1
- package/dist/native/history.js +2 -2
- package/dist/ollama-provider.d.ts +92 -0
- package/dist/ollama-provider.js +495 -0
- package/dist/openapi/agentrun-v2.openapi.json +2 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +197 -55
- package/dist/page.d.ts +11 -3
- package/dist/page.js +22 -7
- package/dist/place-offers.d.ts +25 -1
- package/dist/place-offers.js +62 -8
- package/dist/print.js +1 -1
- package/dist/purged-workflow.d.ts +35 -7
- package/dist/purged-workflow.js +73 -26
- package/dist/redact/match.d.ts +74 -0
- package/dist/redact/match.js +771 -0
- package/dist/run-computer.d.ts +2 -0
- package/dist/run-computer.js +2 -0
- package/dist/run-files.d.ts +4 -0
- package/dist/run-files.js +4 -0
- package/dist/run-keys.d.ts +2 -4
- package/dist/run-keys.js +6 -7
- package/dist/run-launch.d.ts +4 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-reads-over-store.d.ts +3 -2
- package/dist/run-reads-over-store.js +66 -2
- package/dist/run-secrets.js +5 -2
- package/dist/run-timeline-served.d.ts +1 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/runner/adapter-loop.d.ts +9 -3
- package/dist/runner/adapter-loop.js +34 -15
- package/dist/runner/adapter-run-spec.d.ts +3 -0
- package/dist/runner/adapter-run-spec.js +9 -4
- package/dist/runner/audit.js +8 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +13 -5
- package/dist/runner/claim-secrets.d.ts +5 -8
- package/dist/runner/claim-secrets.js +6 -0
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +41 -7
- package/dist/runner/harness-loops.d.ts +22 -9
- package/dist/runner/harness-loops.js +21 -11
- package/dist/runner/held.d.ts +3 -0
- package/dist/runner/learning-end.d.ts +1 -1
- package/dist/runner/learning-end.js +8 -3
- package/dist/runner/loop-contract.d.ts +9 -4
- package/dist/runner/main.js +12 -6
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +26 -2
- package/dist/runner/mcp-run.d.ts +3 -0
- package/dist/runner/mcp-run.js +2 -1
- package/dist/runner/metrics.d.ts +10 -10
- package/dist/runner/metrics.js +19 -38
- package/dist/runner/model-route.d.ts +3 -0
- package/dist/runner/model-route.js +6 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/promotion.d.ts +15 -9
- package/dist/runner/promotion.js +25 -15
- package/dist/runner/run-child-host.d.ts +2 -0
- package/dist/runner/run-child-host.js +19 -9
- package/dist/runner/run-child.js +3 -1
- package/dist/runner/runner.d.ts +4 -0
- package/dist/runner/runner.js +33 -3
- package/dist/runner/sdk-loop.js +2 -0
- package/dist/runner/workflow-loop.d.ts +2 -2
- package/dist/runner/workflow-loop.js +1 -2
- package/dist/runner/workflow-spec.d.ts +1 -1
- package/dist/runner/workflow-spec.js +6 -6
- package/dist/sdk/check.d.ts +4 -1
- package/dist/sdk/check.js +2 -1
- package/dist/sdk/runs.d.ts +2 -2
- package/dist/sdk/runs.js +8 -6
- package/dist/secret-cut.js +2 -1
- package/dist/secret-writes.d.ts +3 -2
- package/dist/secret-writes.js +1 -1
- package/dist/server.d.ts +49 -10
- package/dist/server.js +324 -118
- package/dist/standard-webhooks.d.ts +11 -0
- package/dist/standard-webhooks.js +20 -2
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/schema.js +5 -2
- package/dist/store/sqlite/store.js +133 -47
- package/dist/store/store.d.ts +64 -15
- package/dist/store/store.js +7 -0
- package/dist/store-reads/journal.d.ts +7 -2
- package/dist/store-reads/journal.js +9 -6
- package/dist/store-reads/learning.d.ts +12 -9
- package/dist/store-reads/learning.js +18 -24
- package/dist/store-view.d.ts +0 -5
- package/dist/store-view.js +10 -9
- package/dist/template-eval.d.ts +51 -6
- package/dist/template-eval.js +177 -53
- package/dist/template-import.js +4 -2
- package/dist/templates.d.ts +5 -3
- package/dist/templates.js +19 -40
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +2 -2
- package/dist/timeline/labels.js +2 -2
- package/dist/timeline/timeline.d.ts +14 -9
- package/dist/timeline/timeline.js +15 -7
- package/dist/tool-gate.js +3 -1
- package/dist/tool-plane.d.ts +17 -9
- package/dist/tool-plane.js +38 -17
- package/dist/tools.js +2 -2
- package/dist/trigger-launch-hook.d.ts +16 -8
- package/dist/trigger-launch-hook.js +32 -23
- package/dist/trigger-targets.d.ts +18 -8
- package/dist/trigger-targets.js +42 -19
- package/dist/triggers.d.ts +85 -23
- package/dist/triggers.js +303 -96
- package/dist/validate.js +1 -1
- package/dist/web-fake.js +3 -3
- package/dist/web-fetch-direct.d.ts +4 -0
- package/dist/web-fetch-direct.js +8 -1
- package/dist/web-fetch.d.ts +12 -3
- package/dist/web-fetch.js +47 -14
- package/dist/web-search.d.ts +33 -4
- package/dist/web-search.js +100 -41
- package/dist/webhooks.js +4 -5
- package/dist/workspace/computer-deps.d.ts +2 -1
- package/dist/workspace/computer-deps.js +5 -4
- package/dist/workspace/computer-for-claim.d.ts +8 -2
- package/dist/workspace/computer-for-claim.js +28 -9
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +52 -4
- package/dist/workspace/computer-kept.js +118 -6
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/wrapped.d.ts +57 -0
- package/dist/wrapped.js +51 -0
- package/launcher/agentrun-serve +5 -1
- package/package.json +17 -13
- package/templates/README.md +10 -9
- package/dist/console/assets/index-B_85An2t.js +0 -745
- package/dist/console/assets/index-n1YsbnYh.css +0 -1
- package/dist/import-sources.d.ts +0 -116
- package/dist/import-sources.js +0 -693
|
@@ -40,11 +40,10 @@ export type Counts = {
|
|
|
40
40
|
};
|
|
41
41
|
export { secretsShown, type Shown } from "./learning.js";
|
|
42
42
|
export declare const etagOf: (oid: string) => string;
|
|
43
|
-
/** Which of `runIds` are purged, by the store's purge mark (its row's purge time). */
|
|
44
|
-
export type PurgedOf = (runIds: readonly string[]) => Promise<ReadonlySet<string>>;
|
|
45
43
|
/** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
|
|
46
|
-
* forgetRunText
|
|
47
|
-
|
|
44
|
+
* forgetRunText: a workflow it changed last goes back to the version before it that no purged run of `store` wrote),
|
|
45
|
+
* in the agent's queue, as every write of the folder is. */
|
|
46
|
+
export declare function forgetRunLearning(data: string, agentId: string, runId: string, store: Pick<Store, "runs">): Promise<void>;
|
|
48
47
|
/** A workflow draft as the view lists it: its folder's name, its workflow.json with its `readme`, its description, its
|
|
49
48
|
* status, the run whose merge last changed it, its size in bytes, and the ETag of its README.md (the file that says
|
|
50
49
|
* whether it waits, which an approval names); cut of the host's secrets (a name or a file holding one reads [redacted]).
|
|
@@ -76,8 +75,9 @@ export declare function pendingCount(data: string, agentId: string): Promise<num
|
|
|
76
75
|
/** GET /agents/{id}/learning: main, its corrections.md, its workflow drafts and the first page of its log, and how the
|
|
77
76
|
* agent's runs fared and what learning changed for them (`counts`, `impact`); an agent with no folder (its learning
|
|
78
77
|
* never on) has an empty one. `stateOf`: where each workflow neither pending nor retired stands, by its folder name (the
|
|
79
|
-
* promotions read's own word: learn/promote.ts servingStateOf over the agent's records).
|
|
80
|
-
*
|
|
78
|
+
* promotions read's own word: learn/promote.ts servingStateOf over the agent's records). Through the purge gate
|
|
79
|
+
* (purged-workflow.ts purgeGate, over `store`'s runs): no workflow a purged run wrote, and no purged run's merge in its
|
|
80
|
+
* log. */
|
|
81
81
|
type AgentView = {
|
|
82
82
|
agent: string;
|
|
83
83
|
main: string | null;
|
|
@@ -87,10 +87,10 @@ type AgentView = {
|
|
|
87
87
|
counts: Counts;
|
|
88
88
|
impact: Impact;
|
|
89
89
|
};
|
|
90
|
-
export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState,
|
|
90
|
+
export declare function agentLearning(data: string, agentId: string, shown: Shown, counts: Counts, impact: Impact, stateOf: (workflow: string) => ServingState, store: Pick<Store, "runs">): Promise<AgentView>;
|
|
91
91
|
/** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
|
|
92
|
-
* (
|
|
93
|
-
export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown,
|
|
92
|
+
* (purgeGate). */
|
|
93
|
+
export declare function learningLog(data: string, agentId: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<Page<Change>>;
|
|
94
94
|
/** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
|
|
95
95
|
* id; an empty file's when there is none) and the cap a PUT keeps to, cut of the host's secrets as every read is. */
|
|
96
96
|
export declare function correctionsView(data: string, agentId: string, shown: Shown): Promise<{
|
|
@@ -126,9 +126,9 @@ type WorkflowRevision = {
|
|
|
126
126
|
* commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
|
|
127
127
|
* that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
|
|
128
128
|
* of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
|
|
129
|
-
* LOG_KEEP changes). A purged run's merge is no revision (
|
|
129
|
+
* LOG_KEEP changes). A purged run's merge is no revision (purgeGate). A workflow no commit of the log changed is
|
|
130
130
|
* not_found. */
|
|
131
|
-
export declare function workflowRevisions(data: string, agentId: string, name: string, query: URLSearchParams, shown: Shown,
|
|
131
|
+
export declare function workflowRevisions(data: string, agentId: string, name: string, query: URLSearchParams, shown: Shown, store: Pick<Store, "runs">): Promise<{
|
|
132
132
|
name: string;
|
|
133
133
|
revisions: WorkflowRevision[];
|
|
134
134
|
total: number;
|
|
@@ -137,17 +137,18 @@ export declare function workflowRevisions(data: string, agentId: string, name: s
|
|
|
137
137
|
/** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
|
|
138
138
|
* never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
|
|
139
139
|
* first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
|
|
140
|
-
* main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (
|
|
141
|
-
*
|
|
140
|
+
* main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purgeGate), however
|
|
141
|
+
* old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
|
|
142
142
|
* it is main (snapshotAt). */
|
|
143
143
|
export declare function workflowAtDigest(data: string, agentId: string, name: string, digest: string, commits: readonly string[], store: Pick<Store, "runs">): Promise<{
|
|
144
144
|
text: string;
|
|
145
145
|
commit: string;
|
|
146
146
|
} | undefined>;
|
|
147
147
|
/** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
|
|
148
|
-
* JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404
|
|
149
|
-
*
|
|
150
|
-
*
|
|
148
|
+
* JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404 any
|
|
149
|
+
* missing file is. A file of a workflow still on main whose workflow.json a purged run wrote (its run purged before its
|
|
150
|
+
* purge took the folder's text, until its DELETE is sent again) is 410 purged, as every route of that run is
|
|
151
|
+
* (purgeGate). */
|
|
151
152
|
export declare function readLearnedFile(data: string, agentId: string, raw: string, shown: Shown, store: Pick<Store, "runs">): Promise<{
|
|
152
153
|
text: string;
|
|
153
154
|
etag: string;
|
|
@@ -179,12 +180,16 @@ type DraftTools = () => Promise<{
|
|
|
179
180
|
* held draft (status: pending) to every later run; a retire takes it out of every later run unchecked, so a leaking one
|
|
180
181
|
* can always be revoked; a restore brings it back to the status its retire recorded, checked again as a new draft is
|
|
181
182
|
* (secrets' shapes, the host's values, hidden characters, its README's format, its workflow.json against the agent's
|
|
182
|
-
* tools and gate). A retire of a retired draft commits nothing.
|
|
183
|
+
* tools and gate). A retire of a retired draft commits nothing. An approval or a restore of a workflow whose
|
|
184
|
+
* workflow.json a purged run wrote (still on main until its DELETE is sent again) is 410 purged (purgeGate over
|
|
185
|
+
* `store`'s runs): no person's change gives it to a run; a retire takes it out as any other. `refuse`: the host's
|
|
186
|
+
* secrets. */
|
|
183
187
|
export declare function changeWorkflow(data: string, agentId: string, raw: string, input: {
|
|
184
188
|
action: "approve" | "retire" | "restore";
|
|
185
189
|
ifMatch?: string;
|
|
186
190
|
refuse: readonly string[];
|
|
187
191
|
draftTools?: DraftTools;
|
|
192
|
+
store: Pick<Store, "runs">;
|
|
188
193
|
}): Promise<{
|
|
189
194
|
status: 200;
|
|
190
195
|
file: string;
|
package/dist/learning-routes.js
CHANGED
|
@@ -2,8 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { CORRECTIONS_CAP, draftProblems, frontKeys, isHeld, LEARNED_KEYS, learnedPlace, learnedStatus, printable, released, restorable, restoredLearned, retiredLearned, UNCLEAR_FRONT, unclearFront, unstorable, WORKFLOW_NAME, WORKFLOWS_DIR } from "./learn/index.js";
|
|
3
3
|
import { readmeProblems } from "./learn/workflow-draft.js";
|
|
4
4
|
import { forgetRunText, putCorrections, readCorrections } from "./learn/commit.js";
|
|
5
|
-
import { blobOid, FolderBusy, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotAt, textsAt, writeLearning } from "./learn/folder.js";
|
|
6
|
-
import { purgedRun,
|
|
5
|
+
import { blobOid, FolderBusy, folderOf, FolderRefused, FolderTooLarge, FolderUnreadable, readLearning, PATCH_CAP, readRunDiff, readSnapshot, runDiffKey, snapshotAt, textsAt, writeLearning } from "./learn/folder.js";
|
|
6
|
+
import { purgedRun, purgeGate, purgedRows } from "./purged-workflow.js";
|
|
7
7
|
import { ApiError, invalid } from "./errors.js";
|
|
8
8
|
import { detailShown, filesView, learningFolderOf, reasonShown, withAgentRepo } from "./learning.js";
|
|
9
9
|
import { isObject } from "./validate.js";
|
|
@@ -50,21 +50,14 @@ function routeFailure(error) {
|
|
|
50
50
|
return error.link ? new Error(error.message) : new ApiError("unavailable", error.message);
|
|
51
51
|
return error;
|
|
52
52
|
}
|
|
53
|
-
/** Whether a change of `snapshot`'s log is served: none by a purged run (a run's purge, agent-delete.ts purgeRun), so
|
|
54
|
-
* the folder's history reads serve none of its merges. Asked at each read, so a log the folder rebuilds names them and
|
|
55
|
-
* still serves none. */
|
|
56
|
-
async function servedIn(snapshot, purgedOf) {
|
|
57
|
-
const runs = [...new Set(snapshot.log.flatMap(({ by }) => ("run" in by ? [by.run] : [])))];
|
|
58
|
-
const purged = runs.length ? await purgedOf(runs) : new Set();
|
|
59
|
-
return ({ by }) => !("run" in by && purged.has(by.run));
|
|
60
|
-
}
|
|
61
53
|
/** Run `runId`'s text taken off agent `agentId`'s learning folder's current files at its purge (learn/commit.ts
|
|
62
|
-
* forgetRunText
|
|
63
|
-
|
|
54
|
+
* forgetRunText: a workflow it changed last goes back to the version before it that no purged run of `store` wrote),
|
|
55
|
+
* in the agent's queue, as every write of the folder is. */
|
|
56
|
+
export async function forgetRunLearning(data, agentId, runId, store) {
|
|
64
57
|
await withAgentRepo(data, agentId, async () => {
|
|
65
58
|
const { workspace: ws, end } = learningFolderOf(data, agentId);
|
|
66
59
|
try {
|
|
67
|
-
await forgetRunText(ws, runId);
|
|
60
|
+
await forgetRunText(ws, runId, async (run) => (await purgedRows(store, [run])).has(run));
|
|
68
61
|
}
|
|
69
62
|
catch (error) {
|
|
70
63
|
throw routeFailure(error);
|
|
@@ -182,23 +175,24 @@ export async function pendingCount(data, agentId) {
|
|
|
182
175
|
const status = await statusesOf(data, agentId);
|
|
183
176
|
return status === undefined ? undefined : [...status.values()].filter((value) => value.status === "pending").length;
|
|
184
177
|
}
|
|
185
|
-
export async function agentLearning(data, agentId, shown, counts, impact, stateOf,
|
|
178
|
+
export async function agentLearning(data, agentId, shown, counts, impact, stateOf, store) {
|
|
186
179
|
return reading(data, agentId, async ({ snapshot, body }) => {
|
|
187
|
-
const
|
|
180
|
+
const gate = await purgeGate(snapshot, store, true);
|
|
188
181
|
const corrections = (await readCorrections(snapshot, body)).text;
|
|
189
182
|
// A retired draft whose README.md can't be read is said so (unclearFront), read from its file now, as the snapshot's
|
|
190
183
|
// status was: a few retired items, one read each.
|
|
191
184
|
const unread = async (item) => item.status === "retired" && unclearFront(await body(item.file, item.oid));
|
|
192
|
-
|
|
185
|
+
const items = snapshot.workflows.filter(({ name }) => !gate.workflows.has(name));
|
|
186
|
+
return { agent: agentId, main: snapshot.main, corrections: shown.text(corrections), workflows: await Promise.all(items.map(async (item) => workflowView(item, shown, stateOf, await unread(item)))), log: logPage(snapshot, 0, LOG_PAGE, shown, gate.served), counts, impact };
|
|
193
187
|
}, () => ({ agent: agentId, main: null, corrections: "", workflows: [], log: EMPTY, counts, impact }));
|
|
194
188
|
}
|
|
195
189
|
/** GET /agents/{id}/learning/log?cursor=&limit=: a page of the changes on main, newest first, a purged run's left out
|
|
196
|
-
* (
|
|
197
|
-
export async function learningLog(data, agentId, query, shown,
|
|
190
|
+
* (purgeGate). */
|
|
191
|
+
export async function learningLog(data, agentId, query, shown, store) {
|
|
198
192
|
const { limit, at } = pageRequest(query, LOG_PAGE);
|
|
199
193
|
return reading(data, agentId, async ({ snapshot }) => {
|
|
200
194
|
const page = pageAt(agentId, snapshot, at);
|
|
201
|
-
return logPage(page.snapshot, page.offset, limit, shown, await
|
|
195
|
+
return logPage(page.snapshot, page.offset, limit, shown, (await purgeGate(page.snapshot, store, true)).served);
|
|
202
196
|
}, () => EMPTY);
|
|
203
197
|
}
|
|
204
198
|
/** GET /agents/{id}/learning/corrections: corrections.md on main as text (empty when main holds none), its ETag (its blob
|
|
@@ -244,9 +238,9 @@ const REVISIONS_DEFAULT = 20;
|
|
|
244
238
|
* commits on main's log that changed `workflows/<name>/workflow.json`), oldest first, each with the workflow's text at
|
|
245
239
|
* that commit, so a person can step through how it changed. One read-only exec per revision (textsAt), at most `limit`
|
|
246
240
|
* of them. `total` counts every such commit the log holds, `truncated` says the log itself is cut (it keeps the latest
|
|
247
|
-
* LOG_KEEP changes). A purged run's merge is no revision (
|
|
241
|
+
* LOG_KEEP changes). A purged run's merge is no revision (purgeGate). A workflow no commit of the log changed is
|
|
248
242
|
* not_found. */
|
|
249
|
-
export async function workflowRevisions(data, agentId, name, query, shown,
|
|
243
|
+
export async function workflowRevisions(data, agentId, name, query, shown, store) {
|
|
250
244
|
if (!WORKFLOW_NAME.test(name))
|
|
251
245
|
throw new ApiError("bad_request", "A workflow's folder is named with lowercase letters, digits, dashes and underscores.");
|
|
252
246
|
const given = query.get("limit");
|
|
@@ -257,7 +251,7 @@ export async function workflowRevisions(data, agentId, name, query, shown, purge
|
|
|
257
251
|
if (shown.name(path) !== path)
|
|
258
252
|
throw new ApiError("not_found", "the agent's learning folder has no such workflow");
|
|
259
253
|
const found = await reading(data, agentId, async ({ ws, snapshot }) => {
|
|
260
|
-
const served = await
|
|
254
|
+
const { served } = await purgeGate(snapshot, store, true);
|
|
261
255
|
const touched = snapshot.log.filter((change) => served(change) && change.files.includes(path));
|
|
262
256
|
const latest = touched.slice(0, limit).reverse();
|
|
263
257
|
const revisions = [];
|
|
@@ -277,8 +271,8 @@ export async function workflowRevisions(data, agentId, name, query, shown, purge
|
|
|
277
271
|
/** Learned workflow `name`'s text at `digest` (a champion's, as its promotion records name it), read by that digest and
|
|
278
272
|
* never by paging the workflow's history: at `commits` (the records' learning commits, newest first), then at main, the
|
|
279
273
|
* first commit whose workflow.json is that digest's text, with the commit it was read at. Undefined when none is (no
|
|
280
|
-
* main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (
|
|
281
|
-
*
|
|
274
|
+
* main yet, or no commit read holds it). A commit whose text a purged run wrote is never read (purgeGate), however
|
|
275
|
+
* old. One read-only exec per commit tried (textsAt), and one more for the commit that holds the digest, unless
|
|
282
276
|
* it is main (snapshotAt). */
|
|
283
277
|
export async function workflowAtDigest(data, agentId, name, digest, commits, store) {
|
|
284
278
|
if (!WORKFLOW_NAME.test(name))
|
|
@@ -290,7 +284,7 @@ export async function workflowAtDigest(data, agentId, name, digest, commits, sto
|
|
|
290
284
|
if (raw === undefined || createHash("sha256").update(raw).digest("hex").slice(0, 16) !== digest)
|
|
291
285
|
continue;
|
|
292
286
|
const at = commit === snapshot.main ? snapshot : await snapshotAt(ws, commit).catch(() => undefined);
|
|
293
|
-
if (!at || (await
|
|
287
|
+
if (!at || (await purgeGate(at, store)).workflows.has(name))
|
|
294
288
|
continue;
|
|
295
289
|
return { text: raw, commit };
|
|
296
290
|
}
|
|
@@ -325,9 +319,10 @@ function fileOf(raw, use) {
|
|
|
325
319
|
return file;
|
|
326
320
|
}
|
|
327
321
|
/** GET /agents/{id}/learning/files/{file}: a draft's file on main as text, its ETag, and its type (workflow.json is
|
|
328
|
-
* JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404
|
|
329
|
-
*
|
|
330
|
-
*
|
|
322
|
+
* JSON). A purged run's workflow left main with its purge (learn/commit.ts forgetRunText), so its files are the 404 any
|
|
323
|
+
* missing file is. A file of a workflow still on main whose workflow.json a purged run wrote (its run purged before its
|
|
324
|
+
* purge took the folder's text, until its DELETE is sent again) is 410 purged, as every route of that run is
|
|
325
|
+
* (purgeGate). */
|
|
331
326
|
export async function readLearnedFile(data, agentId, raw, shown, store) {
|
|
332
327
|
const file = fileOf(raw, "read");
|
|
333
328
|
const place = learnedPlace(file);
|
|
@@ -335,7 +330,8 @@ export async function readLearnedFile(data, agentId, raw, shown, store) {
|
|
|
335
330
|
const oid = blobIn(snapshot, file);
|
|
336
331
|
if (oid === undefined)
|
|
337
332
|
return undefined;
|
|
338
|
-
|
|
333
|
+
// Either file of the workflow: the gate refuses its folder whole, as the view and a merge's diff do.
|
|
334
|
+
const purged = (await purgeGate(snapshot, store)).workflows.get(place.name);
|
|
339
335
|
if (purged)
|
|
340
336
|
throw purgedRun(purged);
|
|
341
337
|
return { oid, text: await body(file, oid) };
|
|
@@ -400,7 +396,10 @@ const refused = (problems) => new ApiError("bad_request", `The workflow does not
|
|
|
400
396
|
* held draft (status: pending) to every later run; a retire takes it out of every later run unchecked, so a leaking one
|
|
401
397
|
* can always be revoked; a restore brings it back to the status its retire recorded, checked again as a new draft is
|
|
402
398
|
* (secrets' shapes, the host's values, hidden characters, its README's format, its workflow.json against the agent's
|
|
403
|
-
* tools and gate). A retire of a retired draft commits nothing.
|
|
399
|
+
* tools and gate). A retire of a retired draft commits nothing. An approval or a restore of a workflow whose
|
|
400
|
+
* workflow.json a purged run wrote (still on main until its DELETE is sent again) is 410 purged (purgeGate over
|
|
401
|
+
* `store`'s runs): no person's change gives it to a run; a retire takes it out as any other. `refuse`: the host's
|
|
402
|
+
* secrets. */
|
|
404
403
|
export async function changeWorkflow(data, agentId, raw, input) {
|
|
405
404
|
const file = fileOf(raw, input.action);
|
|
406
405
|
const place = learnedPlace(file);
|
|
@@ -421,6 +420,11 @@ export async function changeWorkflow(data, agentId, raw, input) {
|
|
|
421
420
|
throw new ApiError("not_found", "the agent's learning folder has no such workflow on main");
|
|
422
421
|
if (!match.includes(etagOf(current.oid)))
|
|
423
422
|
throw new ApiError("precondition_failed", "The workflow changed since it was read (a run's merge, or another change): read it again.");
|
|
423
|
+
if (input.action !== "retire") {
|
|
424
|
+
const purged = (await purgeGate(snapshot, input.store)).workflows.get(place.name);
|
|
425
|
+
if (purged)
|
|
426
|
+
throw purgedRun(purged);
|
|
427
|
+
}
|
|
424
428
|
let text;
|
|
425
429
|
if (input.action === "restore") {
|
|
426
430
|
const status = learnedStatus(current.text);
|
|
@@ -537,18 +541,15 @@ export async function runDiffOverStore(data, store, runId, shown) {
|
|
|
537
541
|
}
|
|
538
542
|
return { base: start?.seed ?? null, head: null, files: [] };
|
|
539
543
|
}
|
|
540
|
-
/** `diff` with each file of a learned workflow whose text at its parent a purged run wrote (
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*
|
|
544
|
+
/** `diff` with each file of a learned workflow whose text at its parent a purged run wrote (purgeGate), its whole
|
|
545
|
+
* `workflows/<name>/` folder (README.md too), diffed against nothing, so its patch never shows that text: its text at
|
|
546
|
+
* the merge as an added file, or, deleted there, no file. One more read-only exec when the merge changed such a file
|
|
547
|
+
* (snapshotAt), and one per file served so. */
|
|
544
548
|
async function againstPurged(ws, diff, store) {
|
|
545
|
-
const replaced = (path, status) =>
|
|
546
|
-
const [dir, name, ...rest] = path.split("/");
|
|
547
|
-
return status !== "added" && dir === WORKFLOWS_DIR && rest.length ? name : undefined;
|
|
548
|
-
};
|
|
549
|
+
const replaced = (path, status) => (status === "added" ? undefined : folderOf(path));
|
|
549
550
|
if (!diff.files.some(({ path, status }) => replaced(path, status)))
|
|
550
551
|
return diff;
|
|
551
|
-
const purged = await
|
|
552
|
+
const purged = (await purgeGate(await snapshotAt(ws, diff.parent), store)).workflows;
|
|
552
553
|
const files = [];
|
|
553
554
|
for (const entry of diff.files) {
|
|
554
555
|
const name = replaced(entry.path, entry.status);
|
package/dist/learning.js
CHANGED
|
@@ -18,7 +18,7 @@ import { folderAt, learningInit, learningWorkspace, readLearning } from "./learn
|
|
|
18
18
|
import { agentFolderOf, serialBy } from "./files.js";
|
|
19
19
|
import { withoutLoopbackAddresses } from "./key-refusal.js";
|
|
20
20
|
import { DETAIL_MAX, LIST_DETAIL, said, short, wordsOf } from "./learning-words.js";
|
|
21
|
-
import {
|
|
21
|
+
import { purgeGate } from "./purged-workflow.js";
|
|
22
22
|
export { learnsOf } from "./learning-setting.js";
|
|
23
23
|
/** The server's learning switch (`--learning`, AGENTRUN_SERVE_LEARNING; capabilities.features.learning). `on`, the
|
|
24
24
|
* default: a run learns when its agent's definition says `learning: true`. `off`: no run this server starts does. */
|
|
@@ -215,7 +215,7 @@ export async function seedAt(ws, commit, store) {
|
|
|
215
215
|
const at = await folderAt(ws, commit);
|
|
216
216
|
if (!at)
|
|
217
217
|
throw new Error(`the learning folder's read at ${commit} is gone`);
|
|
218
|
-
const purged = store ? await
|
|
218
|
+
const purged = store ? (await purgeGate(at.snapshot, store)).workflows : new Map();
|
|
219
219
|
const seed = await seedIn(commit, at.snapshot, async (_path, oid) => {
|
|
220
220
|
const bytes = at.blobs.get(oid);
|
|
221
221
|
if (!bytes)
|
package/dist/llms.txt
CHANGED
|
@@ -15,7 +15,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
|
|
|
15
15
|
- [OpenAPI document](/v2/openapi.json): every route and schema, the `agentrun.v2/0` contract with this server's own routes marked `x-agentrun-serve`.
|
|
16
16
|
- [Capabilities](/v2/capabilities): the harnesses, tools, models and efforts this server has, and what it does not offer.
|
|
17
17
|
- `POST /v2/agents` with `{definition: {name, instructions, tools, harness?, model?, thinking?}}` makes an agent (a workflow one holds `workflow` in place of `instructions`). A refusal is `422 input_invalid` naming each field. `PUT /v2/agents/{id}/definition` makes its next revision.
|
|
18
|
-
- An agentic definition's `output_schema` is the JSON Schema its final answer's last fenced
|
|
18
|
+
- An agentic definition's `output_schema` is the JSON Schema its final answer's json block meets (its last fenced one, or the whole answer when it is one JSON object), read into a completed run's `result.output`. A run a schedule trigger starts is handed that trigger's last completed `result.output` after its message, whole up to 32 KiB (as 2-space JSON). Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names.
|
|
19
19
|
- `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
|
|
20
20
|
- `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
|
|
21
21
|
- `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
|
|
2
|
+
* does not read (`problem`, said after "its front matter"); undefined when the file has none. */
|
|
3
|
+
export declare function frontMatter(text: string): {
|
|
4
|
+
data: unknown;
|
|
5
|
+
body: string;
|
|
6
|
+
} | {
|
|
7
|
+
problem: string;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
|
|
10
|
+
export declare function manifestOf(text: string): Record<string, unknown> | undefined;
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// A package file's YAML front matter, read one way wherever it is read: the package reader (templates.ts), its eval
|
|
2
|
+
// cases (template-eval.ts) and `agentrun deploy`, which imports this module (`@parcha/agentrun-serve/manifest`) to find
|
|
3
|
+
// the files a folder's package holds before it sends them. It loads nothing but the YAML parser.
|
|
4
|
+
import { parseDocument } from "yaml";
|
|
5
|
+
/** The front matter: the text between a `---` line at the file's top and the next `---` line. */
|
|
6
|
+
const FRONT = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
|
|
7
|
+
/** A file's front matter, parsed (core schema, unique keys, no merge keys, no aliases), and the body after it; or why it
|
|
8
|
+
* does not read (`problem`, said after "its front matter"); undefined when the file has none. */
|
|
9
|
+
export function frontMatter(text) {
|
|
10
|
+
const match = FRONT.exec(text);
|
|
11
|
+
if (!match)
|
|
12
|
+
return undefined;
|
|
13
|
+
const doc = parseDocument(match[1], { schema: "core", merge: false, uniqueKeys: true, strict: true });
|
|
14
|
+
if (doc.errors.length)
|
|
15
|
+
return { problem: `is not YAML: ${doc.errors[0].message.split("\n")[0]}` };
|
|
16
|
+
try {
|
|
17
|
+
return { data: doc.toJS({ maxAliasCount: 0 }), body: text.slice(match[0].length) };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return { problem: `is refused: ${error.message}` };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** agent.md's manifest, its front matter when that reads as a mapping, else undefined (the package reader says why). */
|
|
24
|
+
export function manifestOf(text) {
|
|
25
|
+
const front = frontMatter(text);
|
|
26
|
+
if (!front || "problem" in front)
|
|
27
|
+
return undefined;
|
|
28
|
+
const { data } = front;
|
|
29
|
+
return typeof data === "object" && data !== null && !Array.isArray(data) ? data : undefined;
|
|
30
|
+
}
|
package/dist/mcp-pin-first.d.ts
CHANGED
|
@@ -29,11 +29,13 @@ export declare function pinFirst(revision: {
|
|
|
29
29
|
* that server's own ports (`own`, Serve.own). `githubApp`:
|
|
30
30
|
* the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
|
|
31
31
|
* repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
|
|
32
|
-
* server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin).
|
|
33
|
-
|
|
32
|
+
* server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
|
|
33
|
+
* test's fake Composio MCP (McpServersOverStore.composioOrigin). */
|
|
34
|
+
export declare function registryListing(store: Parameters<typeof mcpServersOverStore>[0], sealKey: Buffer, { loopback, own, network, githubApp, appOrigin, composioOrigin }?: {
|
|
34
35
|
loopback?: boolean;
|
|
35
36
|
own?: readonly string[];
|
|
36
37
|
network?: OAuthNetwork;
|
|
37
38
|
githubApp?: GithubAppAccess;
|
|
38
39
|
appOrigin?: string;
|
|
40
|
+
composioOrigin?: string;
|
|
39
41
|
}): (server: string, stop?: AbortSignal) => Promise<PinListing>;
|
package/dist/mcp-pin-first.js
CHANGED
|
@@ -68,8 +68,9 @@ export async function pinFirst(revision, deps) {
|
|
|
68
68
|
* that server's own ports (`own`, Serve.own). `githubApp`:
|
|
69
69
|
* the run's GitHub App access (runner/mcp-github.ts), which lists a `github_app` server with a token of the run's
|
|
70
70
|
* repository, metadata read alone, as a save lists it with one (github-connection.ts tokenForListing); without it such a
|
|
71
|
-
* server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin).
|
|
72
|
-
|
|
71
|
+
* server can't be listed. `appOrigin`: a test's fake GitHub MCP (McpServersOverStore.appOrigin). `composioOrigin`: a
|
|
72
|
+
* test's fake Composio MCP (McpServersOverStore.composioOrigin). */
|
|
73
|
+
export function registryListing(store, sealKey, { loopback = false, own = [], network, githubApp, appOrigin, composioOrigin } = {}) {
|
|
73
74
|
let registry;
|
|
74
75
|
// The listing tokens minted and not yet revoked, and how many listings are under way: no one holds a listing token
|
|
75
76
|
// after its listing (the claim's cleanup reaches only githubTokens' tokens), so once no listing is under way, each is
|
|
@@ -82,6 +83,8 @@ export function registryListing(store, sealKey, { loopback = false, own = [], ne
|
|
|
82
83
|
opened.attach("", "", loopback, own);
|
|
83
84
|
if (appOrigin)
|
|
84
85
|
opened.appOrigin = appOrigin;
|
|
86
|
+
if (composioOrigin)
|
|
87
|
+
opened.composioOrigin = composioOrigin;
|
|
85
88
|
if (githubApp)
|
|
86
89
|
opened.appToken = async () => {
|
|
87
90
|
const got = await listingToken(githubApp);
|
|
@@ -2,24 +2,33 @@ import { type SecretRequest } from "./secret-writes.js";
|
|
|
2
2
|
import type { McpCredentialMark } from "./store/index.js";
|
|
3
3
|
/** Whether `operation`'s `body` writes an MCP secret by the body alone (see above). */
|
|
4
4
|
export declare function mcpWritesSecret(operation: string, body: unknown): boolean;
|
|
5
|
-
/** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set
|
|
5
|
+
/** The least of a saved server's row a save's check reads: its auth type, its sealed credential and when that was set,
|
|
6
|
+
* and when the row was made (its source record is bound to it). */
|
|
6
7
|
type SavedRow = {
|
|
7
8
|
auth: string;
|
|
8
9
|
sealed: unknown;
|
|
9
10
|
credentialChangedAt?: number | null;
|
|
11
|
+
createdAt?: number;
|
|
10
12
|
};
|
|
11
13
|
/** A saved server's credential as a writer read it (McpCredentialMark): its auth type, whether one is sealed, and when it
|
|
12
14
|
* was set. A save let through against one mark writes only while the row still has it, in the store's one statement
|
|
13
15
|
* (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
|
|
14
16
|
export declare const credentialMark: (row: SavedRow | undefined) => McpCredentialMark;
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
|
|
17
|
+
/** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
|
|
18
|
+
* generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
|
|
19
|
+
* mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
|
|
20
|
+
* token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
|
|
21
|
+
* write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
|
|
22
|
+
* still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
|
|
23
|
+
* remove), so an owner's save landing after this check is never written over or removed. */
|
|
24
|
+
export declare function tokenWriteOverRefused(_body: unknown, request: SecretRequest): Promise<boolean>;
|
|
21
25
|
/** MCP's operations the one gate reads: the predicates above decide each request. */
|
|
22
26
|
export declare const MCP_SECRET_OPERATIONS: readonly ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
|
|
27
|
+
/** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
|
|
28
|
+
* secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
|
|
29
|
+
* new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
|
|
30
|
+
* the console, so the token's is the one refusal as before. */
|
|
31
|
+
export declare function composioSaveDropsSecret(body: unknown, request: SecretRequest): Promise<boolean>;
|
|
23
32
|
/** The URL a refusal's console link may carry: only one a save would take as it is (http or https, at most 2048
|
|
24
33
|
* characters, no user or password, no query parameter named like a credential: urlOf, the save's own check), with
|
|
25
34
|
* nothing in it shaped like a secret (secretShapes, the learning guard's shapes), no key-shaped path segment or query
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
// MCP's predicates for the one secret-write gate (secret-writes.ts): which MCP operations the server's dispatch takes from
|
|
2
2
|
// the owner's signed-in page alone, refusing every token.
|
|
3
3
|
// - A save that sends a value (a bearer token or a header's value, in any auth type: a value sent is a value, even in a
|
|
4
|
-
// body the save then refuses) writes a secret
|
|
5
|
-
// holds (another auth type, or none), read from the store.
|
|
4
|
+
// body the save then refuses) writes a secret.
|
|
6
5
|
// - A sign-in's start always writes one: its callback seals whatever token set the sign-in it started returns, so who
|
|
7
6
|
// starts it decides whose credential the server's runs use.
|
|
8
|
-
// -
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
7
|
+
// - The private-network OAuth hosts count whole, since they widen where a sign-in sends its code and tokens.
|
|
8
|
+
// - The token saves over and removes only a server the token saved that seals no credential (tokenWriteOverRefused: one
|
|
9
|
+
// rule for every such route, read from the store): the owner's stays the owner's, sealed or not, so the token never
|
|
10
|
+
// drops or changes its credential, moves it, or removes what it made at Composio.
|
|
11
|
+
// A new server with no credential, the token's own server, a preview and a refresh (each keeps nothing new) stay open to a
|
|
12
|
+
// token.
|
|
12
13
|
import { COMPOSIO_TOOLKIT } from "./composio-preset.js";
|
|
13
14
|
import { secretShapes } from "./learn/secrets.js";
|
|
14
15
|
import { urlOf } from "./mcp-probe.js";
|
|
16
|
+
import { mcpSourceKey, savedByToken } from "./mcp-sources.js";
|
|
15
17
|
import { registerNotSecretWrite, registerSecretPage, registerSecretWrite } from "./secret-writes.js";
|
|
16
18
|
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
17
19
|
import { isObject } from "./validate.js";
|
|
@@ -32,40 +34,46 @@ export function mcpWritesSecret(operation, body) {
|
|
|
32
34
|
* was set. A save let through against one mark writes only while the row still has it, in the store's one statement
|
|
33
35
|
* (Mcp.putIfCredential), so it never lands over a credential saved or signed in with after the check. */
|
|
34
36
|
export const credentialMark = (row) => (row ? { auth: row.auth, sealed: row.sealed !== null && row.sealed !== undefined, changedAt: row.credentialChangedAt ?? null } : null);
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
|
|
37
|
+
/** The one rule for the token's write over the saved server its path names, whatever the route: a save over it (the
|
|
38
|
+
* generic save, a Composio save) or its removal. Refused unless the token saved that very row (its source record's mark,
|
|
39
|
+
* mcp-sources.ts savedByToken) and it seals no credential: an owner's server stays the owner's, sealed or not, so the
|
|
40
|
+
* token never drops or changes its credential, moves it, or removes what it made at Composio. A new name has nothing to
|
|
41
|
+
* write over. The write lands only while the row's credential is still the one read here (request.seen) and the row
|
|
42
|
+
* still carries the token's mark, both compared in the store's statement that writes or removes it (McpServers save and
|
|
43
|
+
* remove), so an owner's save landing after this check is never written over or removed. */
|
|
44
|
+
export async function tokenWriteOverRefused(_body, request) {
|
|
38
45
|
const [name] = request.params;
|
|
39
46
|
if (!name)
|
|
40
47
|
return false;
|
|
41
|
-
const
|
|
42
|
-
|
|
48
|
+
const store = request.store;
|
|
49
|
+
const was = await store.mcp.server(name);
|
|
43
50
|
request.seen = credentialMark(was);
|
|
44
|
-
if (!was
|
|
51
|
+
if (!was)
|
|
45
52
|
return false;
|
|
46
|
-
|
|
47
|
-
const type = auth === undefined ? "none" : isObject(auth) ? auth.type : undefined;
|
|
48
|
-
return type !== was.auth;
|
|
49
|
-
}
|
|
50
|
-
/** Whether removing the server its path names drops a credential: it holds a sealed one. A server saved with none (an
|
|
51
|
-
* eval's fake, say) is the token's to remove; the removal lands only while that is still so (request.seen). */
|
|
52
|
-
export async function mcpDeleteDropsSecret(_body, request) {
|
|
53
|
-
const [name] = request.params;
|
|
54
|
-
if (!name)
|
|
55
|
-
return false;
|
|
56
|
-
const was = await request.store.mcp.server(name);
|
|
57
|
-
request.seen = credentialMark(was);
|
|
58
|
-
return !!was && was.sealed !== null && was.sealed !== undefined;
|
|
53
|
+
return (was.sealed !== null && was.sealed !== undefined) || !savedByToken(await store.settings.get(mcpSourceKey(name)), was.createdAt);
|
|
59
54
|
}
|
|
60
55
|
/** MCP's operations the one gate reads: the predicates above decide each request. */
|
|
61
56
|
export const MCP_SECRET_OPERATIONS = ["saveMcpServer", "startMcpOAuth", "putMcpPrivateHosts", "deleteMcpServer"];
|
|
62
|
-
const STORED = { saveMcpServer:
|
|
57
|
+
const STORED = { saveMcpServer: tokenWriteOverRefused, deleteMcpServer: tokenWriteOverRefused };
|
|
63
58
|
for (const operation of MCP_SECRET_OPERATIONS)
|
|
64
59
|
registerSecretWrite(operation, (body) => mcpWritesSecret(operation, body), STORED[operation]);
|
|
65
60
|
// The Composio preset takes the owner's API key and seals it as an MCP header: both routes are the owner's session alone,
|
|
66
61
|
// whatever the body (the listing sends the key too, and only the session may type one).
|
|
67
62
|
registerSecretWrite("listComposioTools", () => true);
|
|
68
|
-
registerSecretWrite("saveComposioServer",
|
|
63
|
+
registerSecretWrite("saveComposioServer", composioSaveSendsKey, composioSaveDropsSecret);
|
|
64
|
+
// A save's body that sends a key's value, or anything but api_key_env alone in its place: a secret written.
|
|
65
|
+
function composioSaveSendsKey(body) {
|
|
66
|
+
return !(isObject(body) && body.api_key === undefined && body.api_key_env !== undefined);
|
|
67
|
+
}
|
|
68
|
+
/** A Composio save that names its key by api_key_env (the server keeps the variable's name, never its value) writes no
|
|
69
|
+
* secret only on an API-only server, which has no owner to save the key from the console: its token's own save, over a
|
|
70
|
+
* new name or a server the token saved, by the one rule (tokenWriteOverRefused). Anywhere else the owner saves keys from
|
|
71
|
+
* the console, so the token's is the one refusal as before. */
|
|
72
|
+
export async function composioSaveDropsSecret(body, request) {
|
|
73
|
+
if (!request.apiOnly || !request.params[0])
|
|
74
|
+
return true;
|
|
75
|
+
return tokenWriteOverRefused(body, request);
|
|
76
|
+
}
|
|
69
77
|
// A Composio server's webhook subscription (composio-triggers.ts): a rotate seals its new secret, a delete drops it.
|
|
70
78
|
registerSecretWrite("rotateComposioSecret", () => true);
|
|
71
79
|
registerSecretWrite("deleteComposioSubscription", () => true);
|