@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +261 -0
- package/README.md +228 -45
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +18 -5
- package/dist/adapters.js +23 -9
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +36 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +28 -3
- package/dist/chatgpt-plan.js +182 -21
- package/dist/claude-login.d.ts +101 -14
- package/dist/claude-login.js +232 -49
- package/dist/claude-sign-in.d.ts +46 -0
- package/dist/claude-sign-in.js +93 -0
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +26 -5
- package/dist/key-refusal.js +313 -37
- package/dist/learn/secrets.d.ts +31 -11
- package/dist/learn/secrets.js +152 -191
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +2 -2
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +245 -42
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +101 -0
- package/dist/redact/match.js +1152 -0
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +3 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +14 -0
- package/dist/runner/adapter-loop.js +56 -11
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +154 -29
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +11 -6
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +85 -36
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +15 -6
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +5 -0
- package/dist/runner/run-child-host.js +71 -30
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +18 -3
- package/dist/runner/runner.js +162 -36
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +57 -13
- package/dist/server.js +371 -113
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +76 -16
- package/dist/store/store.d.ts +53 -3
- package/dist/store/store.js +27 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +4 -4
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +22 -11
- package/dist/template-eval.js +124 -41
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +17 -7
- package/dist/timeline/timeline.js +28 -14
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +69 -6
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +3 -1
- package/dist/workspace/computer-deps.js +12 -4
- package/dist/workspace/computer-for-claim.d.ts +19 -2
- package/dist/workspace/computer-for-claim.js +101 -13
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +55 -4
- package/dist/workspace/computer-kept.js +129 -8
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +65 -0
- package/dist/wrapped.js +77 -0
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +38 -15
- package/dist/console/assets/index-DUYLaqiR.js +0 -746
- package/dist/console/assets/index-DYhU4adm.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** How long a sign-in waits for its browser by default: the harness's own limit. */
|
|
2
|
+
export const SIGN_IN_LIMIT_MS = 10 * 60_000;
|
|
3
|
+
const words = (error) => String(error?.message ?? error).slice(0, 200);
|
|
4
|
+
/** The view of a sign-in that ended as `end`. */
|
|
5
|
+
function endedView(started, end, at) {
|
|
6
|
+
const ended = { ...started, ended_at: at };
|
|
7
|
+
switch (end.end) {
|
|
8
|
+
case "exited":
|
|
9
|
+
if (end.code === 0)
|
|
10
|
+
return { ...ended, state: "signed_in" };
|
|
11
|
+
return { ...ended, state: "failed", ...(end.code !== null ? { exit_code: end.code } : {}), ...(end.signal ? { signal: end.signal } : {}) };
|
|
12
|
+
case "timed_out":
|
|
13
|
+
return { ...ended, state: "timed_out" };
|
|
14
|
+
case "failed":
|
|
15
|
+
return { ...ended, state: "not_started", error: end.message };
|
|
16
|
+
case "stopped":
|
|
17
|
+
// Only this server stops one, and it forgets it as it does (a turn's stop), so this view is never kept.
|
|
18
|
+
return { ...ended, state: "failed" };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** The one sign-in this server started, and its start and stop. `limitMs`: how long a sign-in waits for its browser
|
|
22
|
+
* (SIGN_IN_LIMIT_MS by default; a test's is short). `now`: the clock its times are read from. */
|
|
23
|
+
export class ClaudeSignIns {
|
|
24
|
+
limitMs;
|
|
25
|
+
#now;
|
|
26
|
+
#current;
|
|
27
|
+
// Each start or stop counts one: an end that arrives after a later start or stop is not kept.
|
|
28
|
+
#epoch = 0;
|
|
29
|
+
// The turns (serial), one after another, so two presses at once never leave two CLIs waiting on one port, and a change
|
|
30
|
+
// of the login's setting never lands between a sign-in's read of it and its start.
|
|
31
|
+
#queue = Promise.resolve();
|
|
32
|
+
// Set at the server's stop (close): no start after it spawns a CLI.
|
|
33
|
+
#closed = false;
|
|
34
|
+
constructor(options = {}) {
|
|
35
|
+
this.limitMs = options.limitMs ?? SIGN_IN_LIMIT_MS;
|
|
36
|
+
this.#now = options.now ?? Date.now;
|
|
37
|
+
}
|
|
38
|
+
/** The sign-in as it stands, or undefined when none was started here (or it was stopped). */
|
|
39
|
+
view() {
|
|
40
|
+
return this.#current ? { ...this.#current.view } : undefined;
|
|
41
|
+
}
|
|
42
|
+
/** One turn on the queue: `work` runs alone, after every turn asked before it and before every one asked after, and
|
|
43
|
+
* starts or ends the sign-in through its `turn`. Every change of the login's setting and every start of a sign-in is a
|
|
44
|
+
* turn (claude-login.ts: the turn-on, the turn-off, the sign-in's start and the drop at the server's start), each
|
|
45
|
+
* reading the setting inside it, so none lands between another's read and its start or save. A turn lasts while it
|
|
46
|
+
* decides and starts: a sign-in's wait for its browser is no turn's. A turn that throws rejects its own answer alone;
|
|
47
|
+
* the next turn runs as if it had ended. A sign-in starts and ends only through a turn's `start` and `stop`: there is no
|
|
48
|
+
* start or stop beside them, since one called inside a turn would wait for that turn to end, for ever. */
|
|
49
|
+
serial(work) {
|
|
50
|
+
const next = this.#queue.then(() => work({ start: (begin) => this.#start(begin), stop: () => this.#end() }));
|
|
51
|
+
this.#queue = next.catch(() => { });
|
|
52
|
+
return next;
|
|
53
|
+
}
|
|
54
|
+
/** The server's stop: a turn that ends a sign-in that waits and forgets it, resolving once its CLI is gone; a start
|
|
55
|
+
* asked after it (a request still in flight) spawns nothing. A CLI left waiting would keep the browser's callback port
|
|
56
|
+
* from the next server's sign-in. */
|
|
57
|
+
close() {
|
|
58
|
+
this.#closed = true;
|
|
59
|
+
return this.serial((turn) => turn.stop());
|
|
60
|
+
}
|
|
61
|
+
async #start(begin) {
|
|
62
|
+
await this.#end();
|
|
63
|
+
const epoch = ++this.#epoch;
|
|
64
|
+
const started = { started_at: new Date(this.#now()).toISOString(), limit_ms: this.limitMs };
|
|
65
|
+
if (this.#closed) {
|
|
66
|
+
this.#current = { view: { ...started, state: "not_started", ended_at: started.started_at, error: "this server is stopping" } };
|
|
67
|
+
return this.view();
|
|
68
|
+
}
|
|
69
|
+
let handle;
|
|
70
|
+
try {
|
|
71
|
+
handle = begin(this.limitMs);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
this.#current = { view: { ...started, state: "not_started", ended_at: started.started_at, error: words(error) } };
|
|
75
|
+
return this.view();
|
|
76
|
+
}
|
|
77
|
+
this.#current = { view: { ...started, state: "waiting" }, handle };
|
|
78
|
+
void handle.ended.then((end) => {
|
|
79
|
+
if (epoch === this.#epoch)
|
|
80
|
+
this.#current = { view: endedView(started, end, new Date(this.#now()).toISOString()) };
|
|
81
|
+
});
|
|
82
|
+
return this.view();
|
|
83
|
+
}
|
|
84
|
+
async #end() {
|
|
85
|
+
const current = this.#current;
|
|
86
|
+
this.#epoch++;
|
|
87
|
+
this.#current = undefined;
|
|
88
|
+
if (current?.view.state !== "waiting" || !current.handle)
|
|
89
|
+
return;
|
|
90
|
+
current.handle.stop();
|
|
91
|
+
await current.handle.ended;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ import { REPEAT_MS, stopOnce, stopOnSignals } from "./stop-signals.js";
|
|
|
14
14
|
import { resetPassword } from "./owner.js";
|
|
15
15
|
import { banner } from "./print.js";
|
|
16
16
|
import { parseTokens } from "./api-token.js";
|
|
17
|
-
import { API_ONLY_ENV, RUN_KEYS_ENV, switchFrom } from "./env-switch.js";
|
|
17
|
+
import { API_ONLY_ENV, API_ONLY_MCP_ORIGINS_ENV, apiOnlyMcpOriginsFrom, RUN_KEYS_ENV, switchFrom } from "./env-switch.js";
|
|
18
18
|
import { harnessModulesOf, harnessRecipesOf } from "./harness-table.js";
|
|
19
19
|
import { hookOrigin, LAUNCH_HOOK_SECRET_ENV, LAUNCH_HOOK_URL_ENV, launchHookFrom } from "./trigger-launch-hook.js";
|
|
20
20
|
import { surviveClosedPipes } from "./closed-pipes.js";
|
|
@@ -32,6 +32,7 @@ installEnvProxy();
|
|
|
32
32
|
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--faux-browser MODULE] [--faux-github] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--no-runner] [--harness-module MODULE ...] [--harness-recipe FILE ...] [--harness-sign-in]
|
|
33
33
|
agentrun-serve reset-password [--data DIR]
|
|
34
34
|
agentrun-serve validate-template DIR
|
|
35
|
+
agentrun-serve check-upload < BODY.json
|
|
35
36
|
agentrun-serve install-harness goose|cursor [--data DIR]
|
|
36
37
|
agentrun-serve install-harness --recipe FILE [--data DIR]
|
|
37
38
|
agentrun-serve sign-in-harness --recipe FILE [--data DIR]
|
|
@@ -45,6 +46,7 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
45
46
|
agentrun-serve runner --check --heartbeat --data DIR [--name NAME]
|
|
46
47
|
agentrun-serve store-schema [--data DIR]
|
|
47
48
|
agentrun-serve store-schema --build
|
|
49
|
+
agentrun-serve scrub RUN [--data DIR] [--json]
|
|
48
50
|
agentrun-serve native discover|connect --project PATH [--runtime claude-code|codex] [--agent NAME|--profile NAME] [--url URL] [--data DIR] [--no-sync]
|
|
49
51
|
|
|
50
52
|
--data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
|
|
@@ -113,8 +115,14 @@ AGENTRUN_TELEMETRY=0 (or DO_NOT_TRACK=1) turns off the anonymous usage counts (d
|
|
|
113
115
|
version, the platform and how many runs as a range, never prompts, files or keys. Off in CI, under a test runner and under --faux too;
|
|
114
116
|
AGENTRUN_TELEMETRY=debug prints each event on stderr and sends none.
|
|
115
117
|
|
|
118
|
+
AGENTRUN_MARKETPLACE=off stops the console listing marketplace.agentrun.ai's templates beside this server's own (the list
|
|
119
|
+
is read only when a page asks for it, kept 5 minutes); an https address reads that site's list instead. Under --faux it
|
|
120
|
+
is off unless set to an address.
|
|
121
|
+
|
|
116
122
|
AGENTRUN_API_ONLY=1 serves the run API alone, for a server behind its caller's backend (the routes in api-only.ts; every
|
|
117
|
-
other address is a 404, and there are no accounts).
|
|
123
|
+
other address is a 404, and there are no accounts). With it, AGENTRUN_API_ONLY_MCP_ORIGINS (comma-separated origins, such
|
|
124
|
+
as https://mcp.example.com) lets the token save a per_run MCP server at one of those origins (PUT
|
|
125
|
+
/v2/settings/mcp-servers/NAME); unset, that save is a 404. A loopback origin also needs AGENTRUN_MCP_ALLOW_LOOPBACK=1.
|
|
118
126
|
|
|
119
127
|
AGENTRUN_LAUNCH_HOOK_URL with AGENTRUN_LAUNCH_HOOK_SECRET (a whsec_ secret): each trigger firing that would start a run
|
|
120
128
|
is POSTed to that URL, signed as Standard Webhooks, and the host starts the run through the API; this server starts
|
|
@@ -149,6 +157,14 @@ nothing (no lock, no migration). The store is the server's: AGENTRUN_STORE_URL's
|
|
|
149
157
|
once read, 1 when the store could not be read, 2 for bad arguments. --build reads no store and prints only the versions
|
|
150
158
|
this build knows. A running server says the same in GET /v2/capabilities (store_schema).
|
|
151
159
|
|
|
160
|
+
\`agentrun-serve scrub RUN\` counts what a share of run RUN would cut, read from the data directory's store: an imported
|
|
161
|
+
session or a run this server ran, the server stopped or running. It reads the text a share would carry (the run's title,
|
|
162
|
+
result, error and review, its Timeline as served, a workflow's graph, its agent's name), each cut as the server serves it,
|
|
163
|
+
and counts the scrubber's cuts in it by rule and by kind, then says how many cuts a share would make and how many of them
|
|
164
|
+
you could restore. It prints counts only, never a value or any piece of one; --json prints the same as JSON. It writes
|
|
165
|
+
nothing. Exit 0 once counted, 1 when the run is withheld (its held values can't be read here: nothing is counted), 2 for
|
|
166
|
+
bad arguments or a run the store does not hold.
|
|
167
|
+
|
|
152
168
|
\`agentrun-serve eval-template DIR\` runs a template package's eval cases (all, or each --case) as real runs of its agent
|
|
153
169
|
and grades each run with the case's graders (templates/README.md, "Running the evals"). By default on a server of its
|
|
154
170
|
own in this process, over a temp data directory removed at the end, so it never touches your server; --server URL runs
|
|
@@ -229,12 +245,12 @@ if (process.argv[2] === "install-harness") {
|
|
|
229
245
|
const data = resolve(values.data ?? defaultData());
|
|
230
246
|
try {
|
|
231
247
|
const { recipe, file } = loadRecipe(values.recipe);
|
|
232
|
-
const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "
|
|
248
|
+
const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "its files are checked" };
|
|
233
249
|
const { version, installed, binary, pinnedBy } = await installRecipe(recipe, file, data, { onStep: (step) => console.error(`${recipe.label}: ${said[step]}`) });
|
|
234
|
-
const held = { recipe: "the recipe's pin", "first-seen": "the
|
|
250
|
+
const held = { recipe: "the recipe's tree pin", "first-seen": "the tree an earlier install recorded", recorded: "their tree recorded now, as the first one; a later binary or file beside it that differs is refused" }[pinnedBy];
|
|
235
251
|
console.log(installed === "already"
|
|
236
|
-
? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned
|
|
237
|
-
: `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary held to ${held}). Check it with: ${recipeCheckLine(file, data)} --model PROVIDER/MODEL`);
|
|
252
|
+
? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned files are there, so nothing was downloaded; held to ${held}).`
|
|
253
|
+
: `${recipe.label} ${version} is installed in ${dirname(binary)} (now; the binary and every file beside it held to ${held}). Check it with: ${recipeCheckLine(file, data)} --model PROVIDER/MODEL`);
|
|
238
254
|
process.exit(0);
|
|
239
255
|
}
|
|
240
256
|
catch (error) {
|
|
@@ -330,6 +346,39 @@ if (process.argv[2] === "check-harness") {
|
|
|
330
346
|
console.log(`report: ${file}`);
|
|
331
347
|
process.exit(report.ok ? 0 : 1);
|
|
332
348
|
}
|
|
349
|
+
// An upload's body ({files}, as `agentrun deploy` sends POST /v2/templates/import) read from stdin and checked by the
|
|
350
|
+
// import's own check (template-import.ts checkUpload), storing nothing: the package's name and sha as one JSON line and
|
|
351
|
+
// 0, or each reason the import would refuse it, a line each, and 1; 2 when stdin is not JSON. Nothing in it runs. Stdin
|
|
352
|
+
// is decoded once, whole: a character split between two of its chunks reads back as itself.
|
|
353
|
+
if (process.argv[2] === "check-upload") {
|
|
354
|
+
const { checkUpload } = await import("./template-import.js");
|
|
355
|
+
const { ApiError } = await import("./errors.js");
|
|
356
|
+
parseArgs({ args: process.argv.slice(3), options: { data: { type: "string" } } });
|
|
357
|
+
const chunks = [];
|
|
358
|
+
for await (const chunk of process.stdin)
|
|
359
|
+
chunks.push(chunk);
|
|
360
|
+
let body;
|
|
361
|
+
try {
|
|
362
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
console.error("agentrun-serve check-upload reads an upload's body, {files}, as JSON on stdin.");
|
|
366
|
+
process.exit(2);
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
const { pkg } = checkUpload(typeof body === "object" && body !== null ? body.files : undefined);
|
|
370
|
+
console.log(JSON.stringify({ valid: true, name: pkg.name, sha: pkg.origin.sha }));
|
|
371
|
+
process.exit(0);
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
if (!(error instanceof ApiError))
|
|
375
|
+
throw error;
|
|
376
|
+
const reasons = error.extra.fields?.map((field) => field.message) ?? [];
|
|
377
|
+
for (const reason of reasons.length ? reasons : [error.message])
|
|
378
|
+
console.error(reason);
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
333
382
|
// A template package folder checked by the one validator the server runs on the packages it ships (templates.ts): what
|
|
334
383
|
// it holds as one JSON line and 0, or each problem and 1. Nothing in the package runs.
|
|
335
384
|
if (process.argv[2] === "validate-template") {
|
|
@@ -445,6 +494,10 @@ if (process.argv[2] === "store-schema") {
|
|
|
445
494
|
const { storeSchemaMain } = await import("./store/store-schema.js");
|
|
446
495
|
process.exit(await storeSchemaMain(process.argv.slice(3), defaultData(), USAGE));
|
|
447
496
|
}
|
|
497
|
+
if (process.argv[2] === "scrub") {
|
|
498
|
+
const { scrubMain } = await import("./scrub-command.js");
|
|
499
|
+
process.exit(await scrubMain(process.argv.slice(3), commandUsage));
|
|
500
|
+
}
|
|
448
501
|
if (process.argv[2] === "import") {
|
|
449
502
|
const { importCommand } = await import("./import.js");
|
|
450
503
|
process.exit(await importCommand(process.argv.slice(3), USAGE));
|
|
@@ -539,11 +592,14 @@ process.on("SIGINT", signalled);
|
|
|
539
592
|
process.on("SIGTERM", signalled);
|
|
540
593
|
// AGENTRUN_API_ONLY=1: the run routes alone (api-only.ts), and no owner; a value that is neither on nor off stops here.
|
|
541
594
|
// AGENTRUN_RUN_KEYS=1: each run brings the tool keys this server does not hold (run-keys.ts), read the same way.
|
|
595
|
+
// AGENTRUN_API_ONLY_MCP_ORIGINS: the MCP origins its token may save a per_run server at (api-only.ts), read with it alone.
|
|
542
596
|
let apiOnly;
|
|
543
597
|
let runKeys;
|
|
598
|
+
let apiOnlyMcpOrigins;
|
|
544
599
|
try {
|
|
545
600
|
apiOnly = switchFrom(API_ONLY_ENV);
|
|
546
601
|
runKeys = switchFrom(RUN_KEYS_ENV);
|
|
602
|
+
apiOnlyMcpOrigins = apiOnly ? apiOnlyMcpOriginsFrom(process.env[API_ONLY_MCP_ORIGINS_ENV]) : [];
|
|
547
603
|
}
|
|
548
604
|
catch (error) {
|
|
549
605
|
console.error(`${error.message}\n\n${USAGE}`);
|
|
@@ -602,6 +658,7 @@ try {
|
|
|
602
658
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
603
659
|
...(publicUrl ? { publicUrl } : {}),
|
|
604
660
|
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}), ...(launchHook ? { launchHook } : {}), ...(runKeys ? { runKeys } : {}),
|
|
661
|
+
...(apiOnlyMcpOrigins.length ? { apiOnlyMcpOrigins } : {}),
|
|
605
662
|
// The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
|
|
606
663
|
...(trustedProxies.length ? { trustedProxies } : {}),
|
|
607
664
|
// A local install only as its operator says, never inferred: an MCP server on loopback is refused without it.
|
package/dist/composio-made.d.ts
CHANGED
|
@@ -40,6 +40,10 @@ export type Thing = {
|
|
|
40
40
|
};
|
|
41
41
|
/** The store.settings key a server's record lives under. */
|
|
42
42
|
export declare const composioMadeKey: (name: string) => string;
|
|
43
|
+
/** The store.settings key a server's account, as its last refresh read it at Composio, lives under: `{of, user, toolkit,
|
|
44
|
+
* auth_config, state, labels?, checked_at}`, bound to the server row (`of`) and to what it was read for, so a save over
|
|
45
|
+
* the server as another user, toolkit or auth config shows none until the next refresh. No id, no token. */
|
|
46
|
+
export declare const composioAccountKey: (name: string) => string;
|
|
43
47
|
/** The settings value a record is stored as, bound to the server row it was written for. */
|
|
44
48
|
export declare const storedMade: (made: ComposioMade, row: {
|
|
45
49
|
createdAt: number;
|
package/dist/composio-made.js
CHANGED
|
@@ -19,6 +19,10 @@ export const COMPOSIO_KEY_ENV = "COMPOSIO_API_KEY";
|
|
|
19
19
|
export const COMPOSIO_ORIGIN = "https://backend.composio.dev";
|
|
20
20
|
/** The store.settings key a server's record lives under. */
|
|
21
21
|
export const composioMadeKey = (name) => `mcp.composio/${name}`;
|
|
22
|
+
/** The store.settings key a server's account, as its last refresh read it at Composio, lives under: `{of, user, toolkit,
|
|
23
|
+
* auth_config, state, labels?, checked_at}`, bound to the server row (`of`) and to what it was read for, so a save over
|
|
24
|
+
* the server as another user, toolkit or auth config shows none until the next refresh. No id, no token. */
|
|
25
|
+
export const composioAccountKey = (name) => `mcp.composio-account/${name}`;
|
|
22
26
|
/** The settings value a record is stored as, bound to the server row it was written for. */
|
|
23
27
|
export const storedMade = (made, row) => ({ ...made, of: row.createdAt });
|
|
24
28
|
const ID = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
@@ -29,17 +29,57 @@ export type ComposioTool = {
|
|
|
29
29
|
};
|
|
30
30
|
/** A Composio call (asking): its JSON answer, or the refusal in words that name its step. */
|
|
31
31
|
export type Ask = (step: string, method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, missing?: string | InputIssue) => Promise<Json>;
|
|
32
|
+
/** The bytes a run of calls (asking) may still read of Composio's answers, and the most it may read in all. */
|
|
33
|
+
type Budget = {
|
|
34
|
+
left: number;
|
|
35
|
+
readonly of: number;
|
|
36
|
+
};
|
|
32
37
|
/** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
|
|
33
38
|
* value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
|
|
34
39
|
* with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
|
|
35
|
-
* toolkit it has not, or the refusal on another field.
|
|
36
|
-
|
|
40
|
+
* toolkit it has not, or the refusal on another field. `budget`: the bytes its calls may read of Composio's answers, in
|
|
41
|
+
* all; past it, the call is refused in words. */
|
|
42
|
+
export declare function asking(control: ComposioControl, key: string, signal: AbortSignal | undefined, outcome?: string, sealed?: readonly string[], budget?: Budget): Ask;
|
|
37
43
|
/** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
|
|
38
44
|
export declare function composioTools(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
|
|
39
45
|
toolkit: string;
|
|
40
46
|
no_auth: boolean;
|
|
41
47
|
tools: ComposioTool[];
|
|
42
48
|
}>;
|
|
49
|
+
/** A toolkit Composio offers, as the console's toolkit picker shows it: its slug and its name. */
|
|
50
|
+
export type ComposioToolkit = {
|
|
51
|
+
slug: string;
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
/** POST /settings/mcp-servers/composio/toolkits: the toolkits Composio offers, every page (at most MAX_TOOLKIT_PAGES and
|
|
55
|
+
* MAX_TOOLKIT_BYTES in all; a cursor it names a second time ends the list), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its name. Stores nothing. */
|
|
56
|
+
export declare function composioToolkits(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
|
|
57
|
+
toolkits: ComposioToolkit[];
|
|
58
|
+
}>;
|
|
59
|
+
/** Whether a saved Composio server's account is connected, as a refresh last read it at Composio: `connected`, an ACTIVE
|
|
60
|
+
* account under its auth config; `pending`, only one its connect link started and not yet finished; `expired`, only an
|
|
61
|
+
* expired one; `none`, no account (or only failed or inactive ones); `unknown`, Composio didn't answer. */
|
|
62
|
+
export type ComposioAccountState = "connected" | "pending" | "expired" | "none" | "unknown";
|
|
63
|
+
export declare const COMPOSIO_ACCOUNT_STATES: readonly ComposioAccountState[];
|
|
64
|
+
/** `labels`: each connected account's own label, for the owner to tell which account it is: the alias the owner gave it,
|
|
65
|
+
* else the name Composio shows for it (`state.val.displayName`), else the word id Composio gave it. Never its id (which
|
|
66
|
+
* a run's binding names), and nothing else of its state, which holds its tokens. */
|
|
67
|
+
export type ComposioAccount = {
|
|
68
|
+
state: ComposioAccountState;
|
|
69
|
+
labels?: string[];
|
|
70
|
+
};
|
|
71
|
+
/** `value` as a label: one line of text, cut to MAX_LABEL; none when empty or shaped as an account's id. */
|
|
72
|
+
export declare function accountLabel(value: unknown): string | undefined;
|
|
73
|
+
/** The account of a saved Composio server's user for its toolkit, under its auth config (the one its MCP server serves),
|
|
74
|
+
* as Composio lists it now: never one it answers as another user's (an account with no user_id, which Composio's docs
|
|
75
|
+
* say it will stop answering, is taken as the user asked for). `unknown`, unasked, for a user that is no one
|
|
76
|
+
* Composio user (empty, which Composio reads as every user). A per-run server is never asked (checkAccount, made.per_run);
|
|
77
|
+
* one saved before that mode for a user literally named "per_run" is that user's. */
|
|
78
|
+
export declare function composioAccount(ask: Ask, of: {
|
|
79
|
+
user: string;
|
|
80
|
+
toolkit: string;
|
|
81
|
+
auth_config: string;
|
|
82
|
+
}): Promise<ComposioAccount>;
|
|
43
83
|
/** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
|
|
44
84
|
* has none for it yet. */
|
|
45
85
|
export declare function managedConfig(ask: Ask, toolkit: string): Promise<string | undefined>;
|
|
@@ -106,3 +146,4 @@ export declare function composioForget(control: ComposioControl, key: string, id
|
|
|
106
146
|
removed: boolean;
|
|
107
147
|
note: string;
|
|
108
148
|
}>;
|
|
149
|
+
export {};
|
package/dist/composio-preset.js
CHANGED
|
@@ -44,12 +44,34 @@ const MAX_TOOLS = 500;
|
|
|
44
44
|
const MAX_SLUG = 128;
|
|
45
45
|
const WAIT_MS = 20_000;
|
|
46
46
|
const text = (value) => (typeof value === "string" ? value : "");
|
|
47
|
+
const OVER = Symbol("over budget");
|
|
48
|
+
/** `res`'s body as text: with a budget, read only while it lasts, its bytes taken from it (OVER thrown once it runs out). */
|
|
49
|
+
async function answerOf(res, budget) {
|
|
50
|
+
if (!budget)
|
|
51
|
+
return res.text();
|
|
52
|
+
const reader = res.body?.getReader();
|
|
53
|
+
if (!reader)
|
|
54
|
+
return "";
|
|
55
|
+
const parts = [];
|
|
56
|
+
for (;;) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done)
|
|
59
|
+
return Buffer.concat(parts).toString("utf8");
|
|
60
|
+
budget.left -= value.byteLength;
|
|
61
|
+
if (budget.left < 0) {
|
|
62
|
+
await reader.cancel().catch(() => undefined);
|
|
63
|
+
throw OVER;
|
|
64
|
+
}
|
|
65
|
+
parts.push(value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
47
68
|
const issue = (field, reason, message) => ({ field, reason, message });
|
|
48
69
|
/** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
|
|
49
70
|
* value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
|
|
50
71
|
* with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
|
|
51
|
-
* toolkit it has not, or the refusal on another field.
|
|
52
|
-
|
|
72
|
+
* toolkit it has not, or the refusal on another field. `budget`: the bytes its calls may read of Composio's answers, in
|
|
73
|
+
* all; past it, the call is refused in words. */
|
|
74
|
+
export function asking(control, key, signal, outcome = "nothing was saved", sealed = [], budget) {
|
|
53
75
|
const base = (control.baseUrl ?? BASE).replace(/\/+$/, "");
|
|
54
76
|
const send = control.fetch ?? fetch;
|
|
55
77
|
// Composio's words may quote what it was sent, as sent, JSON-escaped or percent-encoded. With a sealed value in play
|
|
@@ -68,9 +90,11 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
|
|
|
68
90
|
headers: { "x-api-key": key, accept: "application/json", ...(body === undefined ? {} : { "content-type": "application/json" }) },
|
|
69
91
|
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
70
92
|
});
|
|
71
|
-
raw = await res
|
|
93
|
+
raw = await answerOf(res, budget);
|
|
72
94
|
}
|
|
73
|
-
catch {
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error === OVER && budget)
|
|
97
|
+
throw new ApiError("upstream_failed", `Composio's answers while ${step} were over ${budget.of / (1024 * 1024)} MiB: ${outcome}.`);
|
|
74
98
|
throw new ApiError("upstream_failed", `Composio did not answer while ${step}: ${outcome}.`);
|
|
75
99
|
}
|
|
76
100
|
let json;
|
|
@@ -170,6 +194,70 @@ const likelySlug = (slug, slugs) => {
|
|
|
170
194
|
const want = slug.toUpperCase();
|
|
171
195
|
return slugs.find((s) => s.toUpperCase() === want);
|
|
172
196
|
};
|
|
197
|
+
/** The most pages of the toolkit list read (PAGE each): Composio offers about a thousand. */
|
|
198
|
+
const MAX_TOOLKIT_PAGES = 20;
|
|
199
|
+
/** The most bytes of its answers the toolkit list reads, every page in all: a thousand toolkits are about one MiB. */
|
|
200
|
+
const MAX_TOOLKIT_BYTES = 8 * 1024 * 1024;
|
|
201
|
+
/** POST /settings/mcp-servers/composio/toolkits: the toolkits Composio offers, every page (at most MAX_TOOLKIT_PAGES and
|
|
202
|
+
* MAX_TOOLKIT_BYTES in all; a cursor it names a second time ends the list), by name: each one's slug, as a save takes it (a slug outside COMPOSIO_TOOLKIT is left out), and its name. Stores nothing. */
|
|
203
|
+
export async function composioToolkits(body, control, signal) {
|
|
204
|
+
if (!isObject(body))
|
|
205
|
+
throw invalid([issue("body", "invalid", "The body is {api_key}.")]);
|
|
206
|
+
const extra = unknownFields(body, ["api_key"]);
|
|
207
|
+
if (extra.length)
|
|
208
|
+
throw invalid(extra);
|
|
209
|
+
const key = typeof body.api_key === "string" ? body.api_key.trim() : "";
|
|
210
|
+
if (!key || key.length > 8192)
|
|
211
|
+
throw invalid([issue("api_key", "missing", "Send your Composio API key.")]);
|
|
212
|
+
const ask = asking(control, key, signal, "no toolkit was listed", [], { left: MAX_TOOLKIT_BYTES, of: MAX_TOOLKIT_BYTES });
|
|
213
|
+
const found = new Map();
|
|
214
|
+
const seen = new Set();
|
|
215
|
+
let cursor;
|
|
216
|
+
for (let page = 0; page < MAX_TOOLKIT_PAGES; page++) {
|
|
217
|
+
const listed = await ask("listing the toolkits", "GET", `/api/v3/toolkits?sort_by=alphabetically&limit=${PAGE}${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ""}`);
|
|
218
|
+
for (const item of Array.isArray(listed.items) ? listed.items : []) {
|
|
219
|
+
const slug = isObject(item) ? text(item.slug).trim().toLowerCase() : "";
|
|
220
|
+
if (TOOLKIT.test(slug) && !found.has(slug))
|
|
221
|
+
found.set(slug, { slug, name: text(item.name).trim() || slug });
|
|
222
|
+
}
|
|
223
|
+
cursor = text(listed.next_cursor) || undefined;
|
|
224
|
+
if (!cursor || seen.has(cursor))
|
|
225
|
+
break;
|
|
226
|
+
seen.add(cursor);
|
|
227
|
+
}
|
|
228
|
+
return { toolkits: [...found.values()].sort((a, b) => a.name.localeCompare(b.name, "en", { sensitivity: "base" }) || a.slug.localeCompare(b.slug)) };
|
|
229
|
+
}
|
|
230
|
+
export const COMPOSIO_ACCOUNT_STATES = ["connected", "pending", "expired", "none", "unknown"];
|
|
231
|
+
/** The longest label kept, and the most labels. */
|
|
232
|
+
const MAX_LABEL = 120;
|
|
233
|
+
const MAX_LABELS = 10;
|
|
234
|
+
/** `value` as a label: one line of text, cut to MAX_LABEL; none when empty or shaped as an account's id. */
|
|
235
|
+
export function accountLabel(value) {
|
|
236
|
+
const line = typeof value === "string" ? value.replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, MAX_LABEL).trim() : "";
|
|
237
|
+
return line && !COMPOSIO_ACCOUNT_ID.test(line) ? line : undefined;
|
|
238
|
+
}
|
|
239
|
+
const labelOf = (account) => accountLabel(account.alias) ?? (isObject(account.state) && isObject(account.state.val) ? accountLabel(account.state.val.displayName) : undefined) ?? accountLabel(account.word_id);
|
|
240
|
+
/** The account of a saved Composio server's user for its toolkit, under its auth config (the one its MCP server serves),
|
|
241
|
+
* as Composio lists it now: never one it answers as another user's (an account with no user_id, which Composio's docs
|
|
242
|
+
* say it will stop answering, is taken as the user asked for). `unknown`, unasked, for a user that is no one
|
|
243
|
+
* Composio user (empty, which Composio reads as every user). A per-run server is never asked (checkAccount, made.per_run);
|
|
244
|
+
* one saved before that mode for a user literally named "per_run" is that user's. */
|
|
245
|
+
export async function composioAccount(ask, of) {
|
|
246
|
+
if (!COMPOSIO_USER_ID.test(of.user))
|
|
247
|
+
return { state: "unknown" };
|
|
248
|
+
const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(of.user)}&toolkit_slugs=${encodeURIComponent(of.toolkit)}&auth_config_ids=${encodeURIComponent(of.auth_config)}`);
|
|
249
|
+
const mine = (Array.isArray(listed.items) ? listed.items : []).filter((a) => isObject(a) && (!a.user_id || a.user_id === of.user) && isObject(a.auth_config) && a.auth_config.id === of.auth_config);
|
|
250
|
+
const active = mine.filter((a) => a.status === "ACTIVE");
|
|
251
|
+
if (active.length) {
|
|
252
|
+
const labels = [...new Set(active.map(labelOf).filter((label) => !!label))].slice(0, MAX_LABELS);
|
|
253
|
+
return { state: "connected", ...(labels.length ? { labels } : {}) };
|
|
254
|
+
}
|
|
255
|
+
if (mine.some((a) => a.status === "INITIATED" || a.status === "INITIALIZING"))
|
|
256
|
+
return { state: "pending" };
|
|
257
|
+
if (mine.some((a) => a.status === "EXPIRED"))
|
|
258
|
+
return { state: "expired" };
|
|
259
|
+
return { state: "none" };
|
|
260
|
+
}
|
|
173
261
|
/** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
|
|
174
262
|
* has none for it yet. */
|
|
175
263
|
export async function managedConfig(ask, toolkit) {
|
|
@@ -18,10 +18,10 @@ export declare function heldField(store: HeldStore, runId: string, options?: Hel
|
|
|
18
18
|
why?: string;
|
|
19
19
|
} | undefined>;
|
|
20
20
|
/** The run read's `computer` field (`{ computer }`, or nothing for a run with none): its revision's computer setting, else
|
|
21
|
-
* the one its place says; taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
|
|
22
|
-
* journal only while that computer is up); with `held` for a run that holds its computer for its owner. The journal is
|
|
21
|
+
* the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
|
|
22
|
+
* journal only while that computer is up) or its browser (browserHeld, one settings read while it is up); with `held` for a run that holds its computer for its owner. The journal is
|
|
23
23
|
* read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
|
|
24
|
-
export declare function runComputerRead(store: HeldStore & Pick<Store, "agents">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
|
|
24
|
+
export declare function runComputerRead(store: HeldStore & Pick<Store, "agents" | "settings">, runId: string, view: Record<string, unknown>, options?: HeldOptions): Promise<{
|
|
25
25
|
computer?: Record<string, unknown>;
|
|
26
26
|
}>;
|
|
27
27
|
/**
|
|
@@ -29,7 +29,8 @@ export declare function runComputerRead(store: HeldStore & Pick<Store, "agents">
|
|
|
29
29
|
* - callRunComputer: the channel's answer (callComputer), the computer's own: `{ ok: true, value }` or `{ ok: false,
|
|
30
30
|
* error }`. 422 for a method the protocol does not have.
|
|
31
31
|
* - startRun, releaseRunComputer: 404 for a run that holds no computer, and for a release of one already let go; 409
|
|
32
|
-
* computer_not_live when the hold is not where the route needs it (not up yet, already started, released).
|
|
32
|
+
* computer_not_live when the hold is not where the route needs it (not up yet, already started, released). A start of a
|
|
33
|
+
* run whose model kept it from running at its create: 409 agent_not_runnable, in its create's words (hold.refused).
|
|
33
34
|
* Either: 503 when the runner took no row in time.
|
|
34
35
|
*/
|
|
35
36
|
export declare function heldRoute(name: string, runId: string, body: unknown, store: HeldStore, options?: HeldOptions): Promise<unknown>;
|
|
@@ -9,14 +9,16 @@
|
|
|
9
9
|
//
|
|
10
10
|
// They are the owner's: the server's token or the owner's session. A run never holds the server's token (runner/main.ts
|
|
11
11
|
// RUNNER_ONLY), so no run's agent reaches its own computer this way: it drives it through its tools.
|
|
12
|
+
import { browserHeld } from "./browser-hold.js";
|
|
12
13
|
import { callComputer, callIssues, sendRow, TAKE_MS } from "./computer-channel.js";
|
|
13
14
|
import { computerHoldOf, entriesOf, runOver } from "./computer-commands.js";
|
|
14
|
-
import { COMPUTER_RELEASE, COMPUTER_START, heldIn, holdIssues } from "./computer-held.js";
|
|
15
|
+
import { COMPUTER_RELEASE, COMPUTER_START, heldIn, heldRefused, holdIssues } from "./computer-held.js";
|
|
15
16
|
import { settingOfDefinition } from "./computer-setting.js";
|
|
16
17
|
import { ApiError, invalid } from "./errors.js";
|
|
17
18
|
import { runComputerField } from "./run-computer.js";
|
|
18
19
|
import { readLaunchBody } from "./run-launch.js";
|
|
19
20
|
import { unknownFields } from "./validate.js";
|
|
21
|
+
import { readKept } from "./workspace/computer-kept.js";
|
|
20
22
|
export { holdIssues };
|
|
21
23
|
/** The routes' names in serve's route table. */
|
|
22
24
|
export const HELD_ROUTES = new Set(["startRun", "callRunComputer", "releaseRunComputer"]);
|
|
@@ -37,9 +39,17 @@ export async function heldField(store, runId, options = {}) {
|
|
|
37
39
|
const state = read.state !== "released" && (await runOver(store, runId)) ? "released" : read.state;
|
|
38
40
|
return { state, minutes: read.minutes, ...(state === "released" ? {} : { until: new Date(read.until).toISOString() }), ...(read.why ? { why: read.why } : {}) };
|
|
39
41
|
}
|
|
42
|
+
/** Whether parked run `runId`'s computer of `kind` was let go: a park's claim releases it but for a desktop, a phone or a
|
|
43
|
+
* sandbox kept for the resume, until its keep's time (workspace/computer-kept.ts). A browser's is said on its own read. */
|
|
44
|
+
async function releasedAtPark(store, runId, kind, now) {
|
|
45
|
+
if (kind === "browser")
|
|
46
|
+
return false;
|
|
47
|
+
const kept = await readKept(store.settings, runId).catch(() => undefined);
|
|
48
|
+
return !kept || kept.kind !== kind || kept.ended === true || kept.ending === true || now >= kept.until;
|
|
49
|
+
}
|
|
40
50
|
/** The run read's `computer` field (`{ computer }`, or nothing for a run with none): its revision's computer setting, else
|
|
41
|
-
* the one its place says; taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
|
|
42
|
-
* journal only while that computer is up); with `held` for a run that holds its computer for its owner. The journal is
|
|
51
|
+
* the one its place says; released once a stop let it go, or while the run is parked with it let go (releasedAtPark); taken_over while the owner holds its desktop or phone (computerHoldOf, read from the run's
|
|
52
|
+
* journal only while that computer is up) or its browser (browserHeld, one settings read while it is up); with `held` for a run that holds its computer for its owner. The journal is
|
|
43
53
|
* read at most once, and not at all for a run that neither can be taken over nor holds. `view` is the run read so far. */
|
|
44
54
|
export async function runComputerRead(store, runId, view, options = {}) {
|
|
45
55
|
const run = await store.runs.get(runId);
|
|
@@ -47,14 +57,19 @@ export async function runComputerRead(store, runId, view, options = {}) {
|
|
|
47
57
|
if (!setting)
|
|
48
58
|
return {};
|
|
49
59
|
const error = view.error;
|
|
50
|
-
|
|
60
|
+
// A stop lets the run's computer go (the run's row is final until a follow-up queues it again); a park keeps a desktop,
|
|
61
|
+
// a phone or a sandbox only for its keep's time.
|
|
62
|
+
const released = run?.state === "stopped" || (run?.state === "parked" && (await releasedAtPark(store, runId, setting.kind, options.now?.() ?? Date.now())));
|
|
63
|
+
const read = { id: runId, status: String(view.status), ...(error && typeof error.code === "string" ? { error: { code: error.code, message: String(error.message ?? "") } } : {}), ...(released ? { released } : {}) };
|
|
51
64
|
// The run's journal, read at most once for the whole field (the hold and `held` both read it), and only when one needs
|
|
52
65
|
// it: a long run's every poll would pay for a read that grows with it.
|
|
53
66
|
let journal;
|
|
54
67
|
const once = { ...options, entries: () => (journal ??= entriesOf(store, runId, options)) };
|
|
55
|
-
// Who drives
|
|
68
|
+
// Who drives, only while the computer is up: a desktop's or a phone's hold from the run's journal; a browser's from the
|
|
69
|
+
// one row its live view's take keeps (browser-hold.ts); a sandbox is never taken over.
|
|
56
70
|
const takeable = setting.kind === "desktop" || setting.kind === "phone";
|
|
57
|
-
const
|
|
71
|
+
const up = runComputerField(setting, read)?.state === "ready";
|
|
72
|
+
const hold = !up ? "agent" : takeable ? await computerHoldOf(store, runId, once) : setting.kind === "browser" && (await browserHeld(store.settings, runId)) ? "person" : "agent";
|
|
58
73
|
const field = runComputerField(setting, read, (_, state) => (hold === "person" ? "taken_over" : state));
|
|
59
74
|
if (!field)
|
|
60
75
|
return {};
|
|
@@ -73,7 +88,8 @@ function fieldsOf(body) {
|
|
|
73
88
|
* - callRunComputer: the channel's answer (callComputer), the computer's own: `{ ok: true, value }` or `{ ok: false,
|
|
74
89
|
* error }`. 422 for a method the protocol does not have.
|
|
75
90
|
* - startRun, releaseRunComputer: 404 for a run that holds no computer, and for a release of one already let go; 409
|
|
76
|
-
* computer_not_live when the hold is not where the route needs it (not up yet, already started, released).
|
|
91
|
+
* computer_not_live when the hold is not where the route needs it (not up yet, already started, released). A start of a
|
|
92
|
+
* run whose model kept it from running at its create: 409 agent_not_runnable, in its create's words (hold.refused).
|
|
77
93
|
* Either: 503 when the runner took no row in time.
|
|
78
94
|
*/
|
|
79
95
|
export async function heldRoute(name, runId, body, store, options = {}) {
|
|
@@ -87,8 +103,13 @@ export async function heldRoute(name, runId, body, store, options = {}) {
|
|
|
87
103
|
const issues = unknownFields(fields, []);
|
|
88
104
|
if (issues.length)
|
|
89
105
|
throw invalid(issues);
|
|
90
|
-
|
|
106
|
+
const hold = await holdOfRun(store, runId);
|
|
107
|
+
if (!hold)
|
|
91
108
|
throw new ApiError("not_found", `run ${runId} holds no computer: a run started with hold: true holds one`);
|
|
109
|
+
// Its model kept it from running at its create: its agent never starts, in the words its create would have said, and
|
|
110
|
+
// nothing is sent, so its computer still takes calls and its release (computer-held.ts).
|
|
111
|
+
if (name === "startRun" && hold.refused)
|
|
112
|
+
throw heldRefused(hold.refused);
|
|
92
113
|
const read = heldIn(await entriesOf(store, runId, options));
|
|
93
114
|
const over = await runOver(store, runId);
|
|
94
115
|
if (name === "releaseRunComputer" && (over || read?.state === "released"))
|
package/dist/computer-held.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { JournalEntry } from "./computer-commands.js";
|
|
2
2
|
import type { ComputerKind } from "./computer-setting.js";
|
|
3
|
-
import type
|
|
3
|
+
import { ApiError, type InputIssue } from "./errors.js";
|
|
4
|
+
import type { HeldRefusal } from "./run-launch.js";
|
|
4
5
|
/** The journal entry kind the runner commits for each change of the hold. */
|
|
5
6
|
export declare const HELD_KIND = "computer.held";
|
|
6
7
|
/** The command row kinds the server writes. */
|
|
@@ -21,6 +22,10 @@ export declare function holdIssues(body: Record<string, unknown>): InputIssue[];
|
|
|
21
22
|
export declare function holdOf(body: Record<string, unknown>, kind: ComputerKind): {
|
|
22
23
|
minutes: number;
|
|
23
24
|
} | InputIssue | undefined;
|
|
25
|
+
/** The refusal of a held run whose model kept it from running when it was created (run-launch.ts hold.refused), for its
|
|
26
|
+
* start and every message: 409 agent_not_runnable, in the words, fields and details its create would have answered.
|
|
27
|
+
* Read from its launch, never checked again: a key saved since runs a new run, never this one. */
|
|
28
|
+
export declare const heldRefused: (refused: HeldRefusal) => ApiError;
|
|
24
29
|
/** Where a held computer is. */
|
|
25
30
|
export type HeldState = "waiting" | "started" | "ended" | "released";
|
|
26
31
|
export declare const HELD_STATES: readonly HeldState[];
|
package/dist/computer-held.js
CHANGED
|
@@ -9,6 +9,15 @@
|
|
|
9
9
|
// the run keeps its computer until the release or the lapse, then ends stopped. A cancel ends the run and lets the
|
|
10
10
|
// computer go at once.
|
|
11
11
|
//
|
|
12
|
+
// A held run's create does not refuse it for its model (no key for it here, its harness refusing it or lacking only a
|
|
13
|
+
// model key here, no price under a cap): a benchmark that only calls the computer and lets it go never needs one. Those words ride its launch (hold.refused),
|
|
14
|
+
// and its start and every message are refused in them (heldRefused), so its agent never runs; its computer still takes
|
|
15
|
+
// calls until the release or the lapse. On pi and on every CLI harness, its model's route chooses no model and reads no
|
|
16
|
+
// key: its provider is a stand-in that refuses every model request in those words, sending none (provider.ts
|
|
17
|
+
// heldRefusedProvider), so a host with no key for it holds the computer all the same. Its claim lays only the keys any
|
|
18
|
+
// claim of the run lays (its tools', a key handed with it), in a run's own process too (run-child-host.ts: no model key,
|
|
19
|
+
// no saved gateway key), routes no subagent tier and takes no learning step. Every other blocker still refuses the create.
|
|
20
|
+
//
|
|
12
21
|
// Like the take-over (computer-commands.ts), it runs over the one store: the server writes command rows, the run's
|
|
13
22
|
// runner applies them to the computer it holds (runner/held-run.ts), and commits what came of each to the run's journal.
|
|
14
23
|
// The server reads the journal, never anything in its own memory.
|
|
@@ -20,6 +29,7 @@
|
|
|
20
29
|
// computer.call (the channel's, computer-channel.ts): each owner call starts the hold's `minutes` again from its `at`.
|
|
21
30
|
// The rows: computer_start `{}`, computer_release `{}`.
|
|
22
31
|
import { CALL_KIND } from "./computer-channel.js";
|
|
32
|
+
import { ApiError } from "./errors.js";
|
|
23
33
|
/** The journal entry kind the runner commits for each change of the hold. */
|
|
24
34
|
export const HELD_KIND = "computer.held";
|
|
25
35
|
/** The command row kinds the server writes. */
|
|
@@ -58,6 +68,10 @@ export function holdOf(body, kind) {
|
|
|
58
68
|
}
|
|
59
69
|
return { minutes: typeof body.hold_minutes === "number" ? body.hold_minutes : HOLD_MINUTES };
|
|
60
70
|
}
|
|
71
|
+
/** The refusal of a held run whose model kept it from running when it was created (run-launch.ts hold.refused), for its
|
|
72
|
+
* start and every message: 409 agent_not_runnable, in the words, fields and details its create would have answered.
|
|
73
|
+
* Read from its launch, never checked again: a key saved since runs a new run, never this one. */
|
|
74
|
+
export const heldRefused = (refused) => new ApiError("agent_not_runnable", refused.message, { fields: [...refused.fields], details: { ...refused.details } });
|
|
61
75
|
export const HELD_STATES = ["waiting", "started", "ended", "released"];
|
|
62
76
|
const dataOf = (entry) => (entry.data && typeof entry.data === "object" ? entry.data : {});
|
|
63
77
|
/** The run's hold, from its journal: undefined until its computer first came up held. */
|