@parcha/agentrun-serve 0.1.0-beta.56 → 0.1.0-beta.58
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 +281 -0
- package/README.md +246 -66
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +15 -3
- package/dist/adapters.js +17 -6
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +15 -5
- package/dist/api-only.js +32 -8
- package/dist/box-paths.d.ts +4 -3
- package/dist/box-paths.js +7 -4
- 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/chatgpt-plan.d.ts +18 -8
- package/dist/chatgpt-plan.js +91 -34
- package/dist/claude-login-token.d.ts +117 -0
- package/dist/claude-login-token.js +737 -0
- package/dist/claude-login.d.ts +120 -22
- package/dist/claude-login.js +347 -63
- package/dist/claude-sign-in.d.ts +17 -6
- package/dist/claude-sign-in.js +42 -39
- package/dist/cli.js +33 -10
- 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-attach.d.ts +35 -17
- package/dist/computer-attach.js +301 -49
- 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/computers.d.ts +10 -10
- package/dist/computers.js +5 -5
- package/dist/console/assets/{backend-Boh7tC4i.js → backend-CSAWUqtZ.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-DPh29cyz.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/dial-relay.d.ts +25 -4
- package/dist/dial-relay.js +129 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +8 -0
- package/dist/env-switch.js +31 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +56 -20
- package/dist/fal-price.js +400 -90
- 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/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 +9 -4
- package/dist/key-refusal.js +107 -25
- package/dist/learn/ledger.d.ts +170 -0
- package/dist/learn/ledger.js +218 -0
- package/dist/learn/promote.d.ts +3 -3
- package/dist/learn/promote.js +1 -1
- package/dist/learn/secrets.d.ts +13 -3
- package/dist/learn/secrets.js +118 -17
- package/dist/learning-cost.d.ts +28 -23
- package/dist/learning-cost.js +19 -23
- package/dist/link-check.js +1 -1
- package/dist/live-reach.d.ts +2 -0
- package/dist/live-reach.js +2 -0
- package/dist/llms.txt +1 -1
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +35 -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/micro.d.ts +2 -0
- package/dist/micro.js +2 -0
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +10 -6
- package/dist/model.js +16 -11
- package/dist/monid.d.ts +14 -1
- package/dist/monid.js +103 -26
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.js +210 -37
- 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 +4 -0
- package/dist/place-offers.js +7 -4
- package/dist/provider.d.ts +11 -2
- package/dist/provider.js +59 -8
- package/dist/redact/match.d.ts +30 -3
- package/dist/redact/match.js +422 -41
- 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 +4 -2
- 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 +2 -0
- package/dist/run-timeline-served.js +2 -2
- package/dist/run-usage.d.ts +1 -0
- package/dist/run-view.d.ts +1 -2
- package/dist/run-view.js +2 -1
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +11 -0
- package/dist/runner/adapter-loop.js +58 -26
- package/dist/runner/adapter-run-spec.d.ts +55 -11
- package/dist/runner/adapter-run-spec.js +183 -52
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.d.ts +9 -2
- package/dist/runner/beside.js +27 -9
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +27 -10
- package/dist/runner/claim-secrets.js +49 -22
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +97 -38
- 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 +24 -6
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/main.d.ts +11 -6
- package/dist/runner/main.js +19 -9
- package/dist/runner/mcp-claim.js +31 -3
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +11 -1
- package/dist/runner/presence.js +7 -0
- package/dist/runner/reflect-hook.js +1 -1
- package/dist/runner/run-child-host.d.ts +22 -8
- package/dist/runner/run-child-host.js +128 -41
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +17 -3
- package/dist/runner/runner.js +130 -34
- package/dist/runner/save-slots.js +2 -1
- 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.d.ts +11 -0
- package/dist/runner/subagent.js +16 -38
- package/dist/runner/workflow-first.d.ts +35 -15
- package/dist/runner/workflow-first.js +38 -25
- package/dist/runner/workflow-spec.js +4 -3
- 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 +65 -13
- package/dist/server.js +470 -157
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/slots.d.ts +9 -0
- package/dist/slots.js +45 -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/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/postgres/migrations/0028_learning_ledger.sql +44 -0
- package/dist/store/schema.d.ts +23 -0
- package/dist/store/schema.js +58 -2
- 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 +12 -2
- package/dist/store/sqlite/run-patch.js +42 -5
- package/dist/store/sqlite/store.js +105 -12
- package/dist/store/store.d.ts +57 -2
- package/dist/store/store.js +20 -0
- package/dist/store-reads/learning.d.ts +84 -124
- package/dist/store-reads/learning.js +210 -274
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +3 -3
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +39 -9
- package/dist/template-eval.js +191 -60
- package/dist/template-import.js +6 -2
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +14 -8
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +22 -7
- package/dist/timeline/web-calls.js +106 -35
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +66 -5
- 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/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 +10 -13
- package/dist/web-save.js +13 -55
- 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/attached-computers.d.ts +32 -9
- package/dist/workspace/attached-computers.js +77 -13
- package/dist/workspace/computer-deps.d.ts +8 -2
- package/dist/workspace/computer-deps.js +10 -3
- package/dist/workspace/computer-for-claim.d.ts +12 -1
- package/dist/workspace/computer-for-claim.js +83 -11
- package/dist/workspace/computer-kept.d.ts +3 -0
- package/dist/workspace/computer-kept.js +11 -2
- 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/paired-route.d.ts +91 -0
- package/dist/workspace/paired-route.js +153 -0
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +20 -6
- package/dist/wrapped.js +66 -25
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +32 -10
- package/dist/console/assets/index-CQ3cJRzI.js +0 -746
- package/dist/console/assets/index-DKkaS3a0.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
package/dist/claude-sign-in.js
CHANGED
|
@@ -14,7 +14,7 @@ function endedView(started, end, at) {
|
|
|
14
14
|
case "failed":
|
|
15
15
|
return { ...ended, state: "not_started", error: end.message };
|
|
16
16
|
case "stopped":
|
|
17
|
-
// Only this server stops one, and it forgets it as it does (stop), so this view is never kept.
|
|
17
|
+
// Only this server stops one, and it forgets it as it does (a turn's stop), so this view is never kept.
|
|
18
18
|
return { ...ended, state: "failed" };
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -24,9 +24,10 @@ export class ClaudeSignIns {
|
|
|
24
24
|
limitMs;
|
|
25
25
|
#now;
|
|
26
26
|
#current;
|
|
27
|
-
// Each start or stop
|
|
28
|
-
#
|
|
29
|
-
//
|
|
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.
|
|
30
31
|
#queue = Promise.resolve();
|
|
31
32
|
// Set at the server's stop (close): no start after it spawns a CLI.
|
|
32
33
|
#closed = false;
|
|
@@ -38,49 +39,51 @@ export class ClaudeSignIns {
|
|
|
38
39
|
view() {
|
|
39
40
|
return this.#current ? { ...this.#current.view } : undefined;
|
|
40
41
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
let handle;
|
|
52
|
-
try {
|
|
53
|
-
handle = begin(this.limitMs);
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
this.#current = { view: { ...started, state: "not_started", ended_at: started.started_at, error: words(error) } };
|
|
57
|
-
return this.view();
|
|
58
|
-
}
|
|
59
|
-
this.#current = { view: { ...started, state: "waiting" }, handle };
|
|
60
|
-
void handle.ended.then((end) => {
|
|
61
|
-
if (turn === this.#turn)
|
|
62
|
-
this.#current = { view: endedView(started, end, new Date(this.#now()).toISOString()) };
|
|
63
|
-
});
|
|
64
|
-
return this.view();
|
|
65
|
-
});
|
|
66
|
-
this.#queue = next.catch(() => { });
|
|
67
|
-
return next;
|
|
68
|
-
}
|
|
69
|
-
/** End a sign-in that waits, and forget the one there is (a turn-off). */
|
|
70
|
-
stop() {
|
|
71
|
-
const next = this.#queue.then(() => this.#end());
|
|
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() }));
|
|
72
51
|
this.#queue = next.catch(() => { });
|
|
73
52
|
return next;
|
|
74
53
|
}
|
|
75
|
-
/** The server's stop:
|
|
76
|
-
* in flight) spawns nothing. A CLI left waiting would keep the browser's callback port
|
|
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. */
|
|
77
57
|
close() {
|
|
78
58
|
this.#closed = true;
|
|
79
|
-
return this.stop();
|
|
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();
|
|
80
83
|
}
|
|
81
84
|
async #end() {
|
|
82
85
|
const current = this.#current;
|
|
83
|
-
this.#
|
|
86
|
+
this.#epoch++;
|
|
84
87
|
this.#current = undefined;
|
|
85
88
|
if (current?.view.state !== "waiting" || !current.handle)
|
|
86
89
|
return;
|
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";
|
|
@@ -45,6 +45,7 @@ const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--
|
|
|
45
45
|
agentrun-serve runner --check --heartbeat --data DIR [--name NAME]
|
|
46
46
|
agentrun-serve store-schema [--data DIR]
|
|
47
47
|
agentrun-serve store-schema --build
|
|
48
|
+
agentrun-serve scrub RUN [--data DIR] [--json]
|
|
48
49
|
agentrun-serve native discover|connect --project PATH [--runtime claude-code|codex] [--agent NAME|--profile NAME] [--url URL] [--data DIR] [--no-sync]
|
|
49
50
|
|
|
50
51
|
--data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
|
|
@@ -113,8 +114,13 @@ AGENTRUN_TELEMETRY=0 (or DO_NOT_TRACK=1) turns off the anonymous usage counts (d
|
|
|
113
114
|
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
115
|
AGENTRUN_TELEMETRY=debug prints each event on stderr and sends none.
|
|
115
116
|
|
|
117
|
+
AGENTRUN_MARKETPLACE=off stops the console listing marketplace.agentrun.ai's templates beside this server's own (the list
|
|
118
|
+
is read only when a page asks for it, kept 5 minutes); an https address reads that site's list instead. Under --faux it
|
|
119
|
+
is off unless set to an address.
|
|
120
|
+
|
|
116
121
|
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).
|
|
122
|
+
other address is a 404, and there are no accounts). AGENTRUN_API_ONLY_MCP_ORIGINS: the MCP origins the token may save a
|
|
123
|
+
per_run MCP server at (README, API only).
|
|
118
124
|
|
|
119
125
|
AGENTRUN_LAUNCH_HOOK_URL with AGENTRUN_LAUNCH_HOOK_SECRET (a whsec_ secret): each trigger firing that would start a run
|
|
120
126
|
is POSTed to that URL, signed as Standard Webhooks, and the host starts the run through the API; this server starts
|
|
@@ -149,6 +155,14 @@ nothing (no lock, no migration). The store is the server's: AGENTRUN_STORE_URL's
|
|
|
149
155
|
once read, 1 when the store could not be read, 2 for bad arguments. --build reads no store and prints only the versions
|
|
150
156
|
this build knows. A running server says the same in GET /v2/capabilities (store_schema).
|
|
151
157
|
|
|
158
|
+
\`agentrun-serve scrub RUN\` counts what a share of run RUN would cut, read from the data directory's store: an imported
|
|
159
|
+
session or a run this server ran, the server stopped or running. It reads the text a share would carry (the run's title,
|
|
160
|
+
result, error and review, its Timeline as served, a workflow's graph, its agent's name), each cut as the server serves it,
|
|
161
|
+
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
|
|
162
|
+
you could restore. It prints counts only, never a value or any piece of one; --json prints the same as JSON. It writes
|
|
163
|
+
nothing. Exit 0 once counted, 1 when the run is withheld (its held values can't be read here: nothing is counted), 2 for
|
|
164
|
+
bad arguments or a run the store does not hold.
|
|
165
|
+
|
|
152
166
|
\`agentrun-serve eval-template DIR\` runs a template package's eval cases (all, or each --case) as real runs of its agent
|
|
153
167
|
and grades each run with the case's graders (templates/README.md, "Running the evals"). By default on a server of its
|
|
154
168
|
own in this process, over a temp data directory removed at the end, so it never touches your server; --server URL runs
|
|
@@ -229,12 +243,12 @@ if (process.argv[2] === "install-harness") {
|
|
|
229
243
|
const data = resolve(values.data ?? defaultData());
|
|
230
244
|
try {
|
|
231
245
|
const { recipe, file } = loadRecipe(values.recipe);
|
|
232
|
-
const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "
|
|
246
|
+
const said = { downloaded: "the archive is downloaded and its sha256 matches the recipe", unpacked: "unpacked", verified: "its files are checked" };
|
|
233
247
|
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
|
|
248
|
+
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
249
|
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`);
|
|
250
|
+
? `${recipe.label} ${version} is installed in ${dirname(binary)} (already: the pinned files are there, so nothing was downloaded; held to ${held}).`
|
|
251
|
+
: `${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
252
|
process.exit(0);
|
|
239
253
|
}
|
|
240
254
|
catch (error) {
|
|
@@ -445,6 +459,10 @@ if (process.argv[2] === "store-schema") {
|
|
|
445
459
|
const { storeSchemaMain } = await import("./store/store-schema.js");
|
|
446
460
|
process.exit(await storeSchemaMain(process.argv.slice(3), defaultData(), USAGE));
|
|
447
461
|
}
|
|
462
|
+
if (process.argv[2] === "scrub") {
|
|
463
|
+
const { scrubMain } = await import("./scrub-command.js");
|
|
464
|
+
process.exit(await scrubMain(process.argv.slice(3), commandUsage));
|
|
465
|
+
}
|
|
448
466
|
if (process.argv[2] === "import") {
|
|
449
467
|
const { importCommand } = await import("./import.js");
|
|
450
468
|
process.exit(await importCommand(process.argv.slice(3), USAGE));
|
|
@@ -539,11 +557,14 @@ process.on("SIGINT", signalled);
|
|
|
539
557
|
process.on("SIGTERM", signalled);
|
|
540
558
|
// 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
559
|
// AGENTRUN_RUN_KEYS=1: each run brings the tool keys this server does not hold (run-keys.ts), read the same way.
|
|
560
|
+
// 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
561
|
let apiOnly;
|
|
543
562
|
let runKeys;
|
|
563
|
+
let apiOnlyMcpOrigins;
|
|
544
564
|
try {
|
|
545
565
|
apiOnly = switchFrom(API_ONLY_ENV);
|
|
546
566
|
runKeys = switchFrom(RUN_KEYS_ENV);
|
|
567
|
+
apiOnlyMcpOrigins = apiOnly ? apiOnlyMcpOriginsFrom(process.env[API_ONLY_MCP_ORIGINS_ENV]) : [];
|
|
547
568
|
}
|
|
548
569
|
catch (error) {
|
|
549
570
|
console.error(`${error.message}\n\n${USAGE}`);
|
|
@@ -602,6 +623,7 @@ try {
|
|
|
602
623
|
// The public address is the server's with accounts on or off: the Host names it serves, the webhook URLs it gives.
|
|
603
624
|
...(publicUrl ? { publicUrl } : {}),
|
|
604
625
|
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true } : {}), ...(apiOnly ? { apiOnly } : {}), ...(launchHook ? { launchHook } : {}), ...(runKeys ? { runKeys } : {}),
|
|
626
|
+
...(apiOnlyMcpOrigins.length ? { apiOnlyMcpOrigins } : {}),
|
|
605
627
|
// The proxies whose X-Forwarded-For the sign-in limit reads (comma-separated); none unless set.
|
|
606
628
|
...(trustedProxies.length ? { trustedProxies } : {}),
|
|
607
629
|
// A local install only as its operator says, never inferred: an MCP server on loopback is refused without it.
|
|
@@ -636,11 +658,12 @@ if (!values["no-runner"] && askedAt === undefined) {
|
|
|
636
658
|
// its shell is taken out first, as the server's own environment drops it (runner/main.ts besideRunEnv).
|
|
637
659
|
const { besideRunEnv } = await import("./runner/main.js");
|
|
638
660
|
// With the computer janitor: what a crashed runner of this server left is ended (never under --faux). With the
|
|
639
|
-
// server's AttachHub: a paired computer's socket is in
|
|
640
|
-
//
|
|
641
|
-
//
|
|
661
|
+
// server's AttachHub and the name and incarnation the server gave it (Serve.beside): a paired computer's socket is in
|
|
662
|
+
// this process, and this runner's run holds it under a route that names it, so a runner apart (its own process,
|
|
663
|
+
// relaying through this server) takes it for no other run meanwhile. Its runs reach an MCP server on loopback only
|
|
664
|
+
// when this server is a local install (Serve.localInstall).
|
|
642
665
|
// Each run a process of its own, as a user of its own where the image's helper can switch (run-child-host.ts).
|
|
643
|
-
runnerProc = await runnerBeside(data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, ownProcesses: true, hub: serve.attachHub, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, onRunEnded: telemetry.runEnded });
|
|
666
|
+
runnerProc = await runnerBeside(data, { loops, loopsTold, drainMs, env: besideRunEnv(process.env, fauxEnvOf(serveOptions)), janitor: true, ownProcesses: true, hub: serve.attachHub, beside: serve.beside, dial: serve.dial, mcpLoopback: serve.localInstall, mcpOwn: serve.own, ollamaHost: serve.ollamaHost, onRunEnded: telemetry.runEnded });
|
|
644
667
|
}
|
|
645
668
|
catch (error) {
|
|
646
669
|
// A run isolation the runner cannot give (run-child-host.ts runIsolationOf) is said, and the server serves on with no
|
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) {
|
|
@@ -3,7 +3,10 @@ import type { Duplex } from "node:stream";
|
|
|
3
3
|
import { type AttachHub, type AttachSocket, type HelloResult, type MachineTokens } from "@parcha/agentrun-computer";
|
|
4
4
|
import { WebSocket } from "ws";
|
|
5
5
|
import { type LiveReach } from "./live-reach.js";
|
|
6
|
-
import type { MintedTokens, PairedComputerRow, PairedComputers,
|
|
6
|
+
import type { MintedTokens, PairedComputerRow, PairedComputers, Runners } from "./store/index.js";
|
|
7
|
+
import { type Route, type RouteSettings } from "./workspace/paired-route.js";
|
|
8
|
+
export { liveRelays, type RelayRow } from "./runner/presence.js";
|
|
9
|
+
export { RELAY_CONNECT_MS } from "./live-reach.js";
|
|
7
10
|
/** The characters of a pairing code: no 0, O, 1 or I, so a person reads it off a screen without a doubt. */
|
|
8
11
|
export declare const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
|
9
12
|
/** A computer's token starts with this, so a secret scanner knows one. */
|
|
@@ -64,8 +67,8 @@ export type PairedView = {
|
|
|
64
67
|
serves: string[];
|
|
65
68
|
/** When it serves no kind, why, naming what its driver lacks (servesNoKind); null when it serves one. */
|
|
66
69
|
unserved: string | null;
|
|
67
|
-
/** On a server whose runner runs in a process of its own, why no run here can use it
|
|
68
|
-
* instead (RUNNER_APART_WORDS); null where its runs can. */
|
|
70
|
+
/** On a server whose runner runs in a process of its own and relays no computer's socket, why no run here can use it
|
|
71
|
+
* and what to do instead (RUNNER_APART_WORDS); null where its runs can. */
|
|
69
72
|
runs_refused: string | null;
|
|
70
73
|
os: string;
|
|
71
74
|
os_version: string | null;
|
|
@@ -84,16 +87,25 @@ export type PairedView = {
|
|
|
84
87
|
off: string;
|
|
85
88
|
}>;
|
|
86
89
|
driver: string;
|
|
90
|
+
/** Its socket is up: in this server's hub, or relayed to the runner that holds its run. */
|
|
87
91
|
online: boolean;
|
|
88
92
|
held_by_run: string | null;
|
|
89
93
|
held_until: string | null;
|
|
94
|
+
/** The runner whose hub holds it for the run (its route, workspace/paired-route.ts); null while this server's hub does. */
|
|
95
|
+
held_on: string | null;
|
|
96
|
+
/** Why a run's route of it was refused or dropped, in words (its runner gone or restarted, it did not reach the runner
|
|
97
|
+
* in time), until it next attaches here; null when there is nothing to say. */
|
|
98
|
+
hold_note: string | null;
|
|
90
99
|
/** The pairing (createPairing's id) whose code paired it. */
|
|
91
100
|
pairing: string;
|
|
92
101
|
created_at: string;
|
|
93
102
|
/** Its last hello: the live socket's while it is attached (never null while online), else the last one kept. */
|
|
94
103
|
seen_at: string | null;
|
|
95
104
|
};
|
|
96
|
-
|
|
105
|
+
/** `row` as GET /v2/computers lists it. `runsRefused`: why no run here can use it (RUNNER_APART_WORDS), or null. `route`:
|
|
106
|
+
* its route (workspace/paired-route.ts), which names the run that holds it and the runner whose hub does while a run's
|
|
107
|
+
* claim routed it there; `relayed`: its socket is relayed to that runner now (createAttachRoutes relayedPaired). */
|
|
108
|
+
export declare function pairedView(row: PairedComputerRow, hub: Pick<AttachHub, "online" | "since" | "hello" | "claimed" | "deadline">, serves: readonly string[], runsRefused?: string | null, route?: Route, relayed?: boolean): PairedView;
|
|
97
109
|
/** How the socket's liveness is timed: ATTACH_HEARTBEAT_MS and ATTACH_IDLE_MS, unless a test gives its own. */
|
|
98
110
|
export type AttachTiming = {
|
|
99
111
|
readonly heartbeatMs: number;
|
|
@@ -106,9 +118,12 @@ export type AttachTiming = {
|
|
|
106
118
|
* once ws gives up on it. */
|
|
107
119
|
export declare function attachSocketOf(ws: WebSocket, timing?: AttachTiming, closing?: (code: number, reason: string) => void): AttachSocket;
|
|
108
120
|
export interface AttachRoutesOptions {
|
|
121
|
+
/** `settings`: where the paired computers' routes are (workspace/paired-route.ts); absent, no paired computer is
|
|
122
|
+
* routed (every one is this hub's on the server, and none is taken on a runner's listener). */
|
|
109
123
|
readonly store: {
|
|
110
124
|
readonly pairedComputers: PairedComputers;
|
|
111
125
|
readonly mintedTokens: MintedTokens;
|
|
126
|
+
readonly settings?: RouteSettings;
|
|
112
127
|
};
|
|
113
128
|
readonly hub: AttachHub;
|
|
114
129
|
/** Told each event worth a line: a computer paired, attached, refused at its hello, removed; a machine's token minted
|
|
@@ -117,9 +132,13 @@ export interface AttachRoutesOptions {
|
|
|
117
132
|
/** An API-only server's (api-only.ts): the socket takes a hosted machine's minted token alone, and a paired computer's
|
|
118
133
|
* (the console's) is 401 as one it does not know. */
|
|
119
134
|
readonly machinesOnly?: boolean;
|
|
120
|
-
/** No runner in this server's process (ServeOptions.runnerApart):
|
|
121
|
-
* can use a paired computer, and
|
|
135
|
+
/** No runner in this server's process (ServeOptions.runnerApart): while no runner relays (`relayed`), a pairing code
|
|
136
|
+
* and the pair answer say no run here can use a paired computer, and what to do so one can (RUNNER_APART_WORDS).
|
|
137
|
+
* Not runnerApart, the route tick stops at its read while no route row is there and no box is relayed. */
|
|
122
138
|
readonly runnerApart?: boolean;
|
|
139
|
+
/** Whether a runner in a process of its own relays now (server.ts relayed), read at each pairing code and pair answer;
|
|
140
|
+
* absent: none does. */
|
|
141
|
+
readonly relayed?: () => Promise<boolean>;
|
|
123
142
|
/** The socket's liveness timing: the protocol's unless a test gives its own. */
|
|
124
143
|
readonly timing?: AttachTiming;
|
|
125
144
|
readonly now?: () => number;
|
|
@@ -138,20 +157,16 @@ export interface AttachRoutesOptions {
|
|
|
138
157
|
readonly runners: Pick<Runners, "live">;
|
|
139
158
|
readonly reach: LiveReach;
|
|
140
159
|
};
|
|
160
|
+
/** On the server: the runner beside it in its process (Serve.beside, runner/beside.ts), whose run's route keeps a
|
|
161
|
+
* paired box in this hub. A route that names it and its incarnation is this hub's: the upgrade takes the box here,
|
|
162
|
+
* and the tick moves it here (from a runner apart that still has it) and never away. */
|
|
163
|
+
readonly beside?: {
|
|
164
|
+
readonly runner: string;
|
|
165
|
+
readonly incarnation: string;
|
|
166
|
+
};
|
|
141
167
|
}
|
|
142
168
|
/** A request's Bearer token, or undefined. */
|
|
143
169
|
export declare const bearerOf: (authorization: string | undefined) => string | undefined;
|
|
144
|
-
/** A runner's row that says where its relay answers. */
|
|
145
|
-
export type RelayRow = RunnerRow & {
|
|
146
|
-
readonly host: string;
|
|
147
|
-
readonly port: number;
|
|
148
|
-
};
|
|
149
|
-
/** The runners whose relay takes dials now: their rows seen within PRESENCE_STALE_MS on the store's clock (Runners.live,
|
|
150
|
-
* the database's on Postgres), never one process's, that say where their relay answers. The server relays a dial only
|
|
151
|
-
* to one of these, and says a dial provider is served while one answers at a host it dials (server.ts relayed). */
|
|
152
|
-
export declare function liveRelays(runners: Pick<Runners, "live">): Promise<RelayRow[]>;
|
|
153
|
-
/** How long the server waits for a runner's attach listener to take a relayed dial. */
|
|
154
|
-
export declare const RELAY_CONNECT_MS = 10000;
|
|
155
170
|
/** Two WebSockets joined frame by frame, each an attach socket with `timing` (attachSocketOf: its idle close, its binary
|
|
156
171
|
* refusal, the server's maxPayload), each closing the other with its code and reason: once it ended, or as soon as it
|
|
157
172
|
* starts a close of its own, so an idle peer's close reaches the other side at once. */
|
|
@@ -175,5 +190,8 @@ export declare function createAttachRoutes(options: AttachRoutesOptions): {
|
|
|
175
190
|
close: () => Promise<void>;
|
|
176
191
|
machineTokens: MachineTokens;
|
|
177
192
|
daemon: (authorization: string | undefined, arch: string | null) => Promise<string>;
|
|
193
|
+
tick: () => Promise<void>;
|
|
194
|
+
relayedTo: (id: string) => string | undefined;
|
|
195
|
+
runsRefused: () => Promise<string | null>;
|
|
178
196
|
};
|
|
179
197
|
export type AttachRoutes = ReturnType<typeof createAttachRoutes>;
|