@parcha/agentrun-serve 0.1.0-beta.40 → 0.1.0-beta.42
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 +130 -0
- package/NOTICE +2 -0
- package/README.md +149 -21
- package/dist/agent-rows.d.ts +1 -1
- package/dist/agents-store.js +3 -1
- package/dist/api-only.d.ts +3 -1
- package/dist/api-only.js +4 -2
- package/dist/api-token.d.ts +30 -0
- package/dist/api-token.js +89 -0
- package/dist/calendar/address.d.ts +49 -0
- package/dist/calendar/address.js +153 -0
- package/dist/calendar/fetch.d.ts +24 -0
- package/dist/calendar/fetch.js +146 -0
- package/dist/calendar/ics-faux.d.ts +39 -0
- package/dist/calendar/ics-faux.js +236 -0
- package/dist/calendar/labels.d.ts +3 -0
- package/dist/calendar/labels.js +61 -0
- package/dist/calendar/names.d.ts +52 -0
- package/dist/calendar/names.js +54 -0
- package/dist/calendar/parse.d.ts +108 -0
- package/dist/calendar/parse.js +625 -0
- package/dist/calendar/routes.d.ts +17 -0
- package/dist/calendar/routes.js +81 -0
- package/dist/calendar/tools.d.ts +23 -0
- package/dist/calendar/tools.js +124 -0
- package/dist/cli.js +22 -6
- package/dist/composio-made.d.ts +54 -0
- package/dist/composio-made.js +83 -0
- package/dist/composio-preset.d.ts +16 -8
- package/dist/composio-preset.js +106 -43
- package/dist/composio-triggers.d.ts +7 -2
- package/dist/composio-triggers.js +13 -7
- package/dist/computer-attach.d.ts +29 -11
- package/dist/computer-attach.js +141 -47
- package/dist/computer-keys.d.ts +4 -0
- package/dist/computer-keys.js +5 -0
- package/dist/computer-record.d.ts +55 -0
- package/dist/computer-record.js +315 -0
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +15 -2
- package/dist/computers.d.ts +11 -1
- package/dist/computers.js +23 -26
- package/dist/console/assets/{index-B8Zn1Iqn.css → index-C3gNPz58.css} +1 -1
- package/dist/console/assets/index-DYJ_wj27.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.js +9 -2
- package/dist/eval-feed.d.ts +26 -0
- package/dist/eval-feed.js +72 -0
- package/dist/eval-mailbox.d.ts +4 -1
- package/dist/eval-mailbox.js +11 -3
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/feed/feed-faux.d.ts +62 -0
- package/dist/feed/feed-faux.js +123 -0
- package/dist/feed/fetch.d.ts +41 -0
- package/dist/feed/fetch.js +128 -0
- package/dist/feed/parse.d.ts +42 -0
- package/dist/feed/parse.js +291 -0
- package/dist/feed/pointer.d.ts +2 -0
- package/dist/feed/pointer.js +17 -0
- package/dist/file-types.js +1 -0
- package/dist/host-command.d.ts +3 -0
- package/dist/host-command.js +18 -0
- package/dist/host.d.ts +3 -0
- package/dist/host.js +3 -0
- package/dist/learn/check.d.ts +17 -1
- package/dist/learn/check.js +240 -5
- package/dist/learn/compile.d.ts +48 -27
- package/dist/learn/compile.js +134 -101
- package/dist/learn/promote.d.ts +61 -5
- package/dist/learn/promote.js +12 -2
- package/dist/learned-nodes.d.ts +21 -4
- package/dist/learned-nodes.js +21 -8
- package/dist/learned-workflow.d.ts +3 -3
- package/dist/learned-workflow.js +14 -5
- package/dist/learning-setting.d.ts +23 -0
- package/dist/learning-setting.js +51 -0
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +3 -0
- package/dist/learning.d.ts +3 -2
- package/dist/learning.js +5 -3
- package/dist/mcp-oauth.d.ts +23 -1
- package/dist/mcp-oauth.js +46 -5
- package/dist/mcp-pin-first.d.ts +4 -2
- package/dist/mcp-pin-first.js +4 -3
- package/dist/mcp-private-hosts.d.ts +13 -0
- package/dist/mcp-private-hosts.js +16 -0
- package/dist/mcp-servers-store.d.ts +58 -5
- package/dist/mcp-servers-store.js +136 -17
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/observation/http.d.ts +4 -1
- package/dist/observation/http.js +5 -4
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +151 -21
- package/dist/print.d.ts +6 -3
- package/dist/print.js +4 -2
- package/dist/run-files.d.ts +6 -2
- package/dist/run-files.js +29 -7
- package/dist/run-labels.d.ts +23 -0
- package/dist/run-labels.js +79 -0
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-reads-over-store.d.ts +5 -1
- package/dist/run-reads-over-store.js +8 -4
- package/dist/run-recordings.d.ts +20 -0
- package/dist/run-recordings.js +133 -0
- package/dist/run-secrets.js +12 -4
- package/dist/runner/adapter-loop.d.ts +1 -1
- package/dist/runner/adapter-loop.js +94 -16
- package/dist/runner/adapter-run-spec.d.ts +19 -0
- package/dist/runner/adapter-run-spec.js +57 -36
- package/dist/runner/beside.d.ts +6 -3
- package/dist/runner/beside.js +9 -7
- package/dist/runner/cli-run-spec.js +41 -32
- package/dist/runner/conformance/harness.js +69 -14
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/feedback-round.d.ts +9 -25
- package/dist/runner/feedback-round.js +22 -40
- package/dist/runner/learning-end.d.ts +17 -7
- package/dist/runner/learning-end.js +79 -53
- package/dist/runner/main.d.ts +12 -1
- package/dist/runner/main.js +31 -4
- package/dist/runner/mcp-claim.d.ts +3 -0
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +6 -2
- package/dist/runner/mcp-run.js +5 -3
- package/dist/runner/model-route.d.ts +4 -2
- package/dist/runner/model-route.js +8 -8
- package/dist/runner/promotion.d.ts +44 -4
- package/dist/runner/promotion.js +323 -21
- package/dist/runner/reflect-hook.d.ts +5 -0
- package/dist/runner/reflect-hook.js +22 -14
- package/dist/runner/store-secrets.js +3 -1
- package/dist/runner/workflow-first.d.ts +6 -11
- package/dist/runner/workflow-first.js +16 -20
- package/dist/runs-over-store.d.ts +1 -1
- package/dist/runs-over-store.js +5 -2
- package/dist/sdk/runs.d.ts +7 -1
- package/dist/sdk/runs.js +21 -7
- package/dist/secret-cut.js +3 -1
- package/dist/secrets.js +5 -3
- package/dist/server.d.ts +31 -5
- package/dist/server.js +240 -61
- package/dist/store/agent-body.d.ts +5 -3
- package/dist/store/agent-body.js +14 -10
- 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/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrations/0015_run_labels.sql +5 -0
- package/dist/store/postgres/migrations/0016_minted_tokens.sql +21 -0
- package/dist/store/schema.d.ts +9 -0
- package/dist/store/schema.js +26 -2
- package/dist/store/sqlite/connection.js +11 -3
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +3 -2
- package/dist/store/sqlite/store.js +64 -10
- package/dist/store/store.d.ts +38 -1
- package/dist/store-reads/journal.js +2 -1
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +6 -1
- package/dist/store-reads/loop.d.ts +1 -0
- package/dist/store-reads/loop.js +14 -4
- package/dist/store-reads/runs.d.ts +4 -3
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.d.ts +5 -0
- package/dist/store-view.js +8 -2
- package/dist/template-eval.d.ts +11 -0
- package/dist/template-eval.js +177 -52
- package/dist/templates.d.ts +13 -1
- package/dist/templates.js +89 -18
- package/dist/timeline/computer.js +2 -1
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.js +11 -0
- package/dist/trigger-adapter.d.ts +9 -4
- package/dist/trigger-adapters.js +2 -1
- package/dist/trigger-feed.d.ts +12 -0
- package/dist/trigger-feed.js +420 -0
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +23 -5
- package/dist/validate.js +7 -2
- package/dist/webhooks.js +9 -5
- package/dist/workspace/computer-deps.d.ts +5 -1
- package/dist/workspace/computer-deps.js +2 -2
- package/dist/workspace/computer-for-claim.d.ts +7 -0
- package/dist/workspace/computer-for-claim.js +12 -2
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/index.js +2 -0
- package/dist/workspace/paths.d.ts +4 -0
- package/dist/workspace/paths.js +9 -0
- package/dist/workspace/resolve-computer.d.ts +35 -4
- package/dist/workspace/resolve-computer.js +47 -9
- package/launcher/agentrun-serve +34 -22
- package/package.json +11 -9
- package/templates/README.md +38 -4
- package/dist/console/assets/index-Jbxjcmdp.js +0 -705
|
@@ -15,6 +15,7 @@ import { checkPrivateHosts, privateOAuthHosts, savePrivateOAuthHosts } from "./m
|
|
|
15
15
|
import { credentialMark } from "./mcp-secret-writes.js";
|
|
16
16
|
import { secretMeta, secretName } from "./secret-writes.js";
|
|
17
17
|
import { dialAt, issuerOf, LOOPBACK, MAX_PENDING, MCP_SETTINGS_PAGE, mcpServerAt, McpSignIns, reasonOf, SIGN_IN_AGAIN, systemNetwork } from "./mcp-oauth.js";
|
|
18
|
+
import { cleanupOf, composioMadeKey, droppedOf, madeToWrite, recordedMade, storedMade } from "./composio-made.js";
|
|
18
19
|
import { COMPOSIO_USER, composioServerId } from "./composio-preset.js";
|
|
19
20
|
import { mcpSourceKey, recordedForAnother, sourceOf, sourceToWrite, standInGiven, storedSource, toolkitGiven } from "./mcp-sources.js";
|
|
20
21
|
import { SEAL_KEY_ENV, sealKeyOf } from "./tool-keys.js";
|
|
@@ -39,12 +40,15 @@ function changedMeanwhile(name, saved) {
|
|
|
39
40
|
throw new ApiError("precondition_failed", `The MCP server ${name}'s credential changed while this save ran (another save, a sign-in or a removal): read it again, then save again.`);
|
|
40
41
|
return saved;
|
|
41
42
|
}
|
|
42
|
-
function composioHandleOf(removed) {
|
|
43
|
+
function composioHandleOf(removed, cleanup) {
|
|
43
44
|
const id = removed ? composioServerId(removed.url) : undefined;
|
|
44
|
-
const
|
|
45
|
+
const key = composioKeyOf(removed?.opened);
|
|
46
|
+
return { ...(id && key ? { id, key } : { unusable: true }), ...(cleanup ? { cleanup } : {}) };
|
|
47
|
+
}
|
|
48
|
+
/** The Composio key a preset row's opened credential holds (its x-api-key header); none when it does not open. */
|
|
49
|
+
function composioKeyOf(open) {
|
|
45
50
|
const headers = open && "credential" in open && open.credential.type === "headers" ? open.credential.headers : undefined;
|
|
46
|
-
|
|
47
|
-
return id && key ? { id, key } : { unusable: true };
|
|
51
|
+
return headers ? Object.entries(headers).find(([header]) => header.toLowerCase() === "x-api-key")?.[1] : undefined;
|
|
48
52
|
}
|
|
49
53
|
/** The sign-ins in flight over the store (store.mcpOauth): the sign-in's secret parts (the PKCE verifier and the OAuth
|
|
50
54
|
* client, with its secret) sealed together by its state, the rest of its working state plain JSON the callback rebuilds.
|
|
@@ -121,13 +125,20 @@ export class McpServersOverStore {
|
|
|
121
125
|
/** This server's address as a browser reaches it and where it listens (McpServers.attach). `local`: whether its
|
|
122
126
|
* operator said this is a local install (ServeOptions.mcpLoopback, the CLI's AGENTRUN_MCP_ALLOW_LOOPBACK=1), the one kind
|
|
123
127
|
* of server an MCP server's URL may be on loopback for. Never inferred from where it listens: a hosted container
|
|
124
|
-
* listens on loopback behind its proxy too. Omitted, or never attached, it is not one.
|
|
125
|
-
|
|
128
|
+
* listens on loopback behind its proxy too. Omitted, or never attached, it is not one. `beside`: a runner's registry
|
|
129
|
+
* (registryListing), attached at no address of its own, is held to the own addresses of the server beside it. */
|
|
130
|
+
attach(base, listening, local, beside = []) {
|
|
126
131
|
this.signIns.base = base.replace(/\/+$/, "");
|
|
127
132
|
this.signIns.listening = listening.replace(/\/+$/, "");
|
|
133
|
+
this.signIns.beside = [...beside];
|
|
128
134
|
this.loopback = local === true;
|
|
129
135
|
this.signIns.loopback = this.loopback;
|
|
130
136
|
}
|
|
137
|
+
/** This server's own addresses (McpSignIns.own): where it listens, and its public address when that is on loopback. A
|
|
138
|
+
* read on loopback, here or by the runner beside it (Serve.own), never goes to their ports. */
|
|
139
|
+
get own() {
|
|
140
|
+
return this.signIns.own;
|
|
141
|
+
}
|
|
131
142
|
clientDocument() {
|
|
132
143
|
return this.signIns.clientDocument();
|
|
133
144
|
}
|
|
@@ -135,6 +146,12 @@ export class McpServersOverStore {
|
|
|
135
146
|
get callbackOrigin() {
|
|
136
147
|
return new URL(this.signIns.base).origin;
|
|
137
148
|
}
|
|
149
|
+
/** Where a server-side read of a URL may go (a feed's, a calendar's), as an MCP server's requests may: this server's
|
|
150
|
+
* network, its own addresses (never read), the private-network hosts the owner allows (read now, at each call), loopback
|
|
151
|
+
* only on a local install, and stopped with the server. */
|
|
152
|
+
async outboundReach() {
|
|
153
|
+
return { network: this.network, reach: { own: this.signIns.own, allowed: await privateOAuthHosts(this.store), loopback: this.loopback }, signal: this.stopped.signal };
|
|
154
|
+
}
|
|
138
155
|
/** The server's own tool settings, set as the server starts. */
|
|
139
156
|
toolSettings = () => ({});
|
|
140
157
|
async close(boundMs = 2_000) {
|
|
@@ -232,8 +249,15 @@ export class McpServersOverStore {
|
|
|
232
249
|
}
|
|
233
250
|
/** PUT: preview, then keep the server with the tools listed. A body with no credential keeps the sealed one, while the
|
|
234
251
|
* auth type and the URL's origin stay the same. `made`: what made the server, when that is the Composio preset (its
|
|
235
|
-
* source and toolkit, recorded as they are).
|
|
236
|
-
|
|
252
|
+
* source and toolkit, recorded as they are), and `stands`, what it stands on at Composio (composio-made.ts), recorded
|
|
253
|
+
* for its delete. `dropped` is told what a save over a preset server leaves to do there, once the row is written: the
|
|
254
|
+
* MCP server the save before made, when the row names it no longer, and what else that save made that this one no
|
|
255
|
+
* longer stands on (all of it, for an ordinary save that moves the row off Composio, as a delete), which another saved
|
|
256
|
+
* server's record now owns or the caller removes. `guard`, a preset row's: the turn its write and cleanup take, once
|
|
257
|
+
* the listing is done (never across it), and the check of the triggers that use it, made in that turn before a write
|
|
258
|
+
* that leaves what they stand on (an ordinary save moving the row off Composio, a preset save as another user or auth
|
|
259
|
+
* config): refused, nothing written. */
|
|
260
|
+
async save(name, body, stop, checkedAgainst, made, stands, dropped, guard) {
|
|
237
261
|
nameOf(name);
|
|
238
262
|
const was = await this.store.mcp.server(name);
|
|
239
263
|
// Its URL as every read shows it (shownUrl), sent back unchanged: the saved one.
|
|
@@ -242,6 +266,8 @@ export class McpServersOverStore {
|
|
|
242
266
|
// is now, checked before anything is listed; written once the server is, for the row it wrote.
|
|
243
267
|
const sourceIssues = [];
|
|
244
268
|
const wasSource = await this.sourceOf({ name, auth: auth.type, createdAt: was?.createdAt });
|
|
269
|
+
// Whether the row was a Composio preset server (auth headers, source composio), read before this save writes its own.
|
|
270
|
+
const wasPreset = was !== undefined && was.auth === "headers" && (await this.sourceOf(was)).source === "composio";
|
|
245
271
|
// An ordinary save that moves a Composio preset row to another address makes it another service's server: it stops being
|
|
246
272
|
// Composio's, whatever its path looks like, so its delete never sends the key it holds to Composio. It is url's, with the
|
|
247
273
|
// toolkit the same save names, else none.
|
|
@@ -301,14 +327,70 @@ export class McpServersOverStore {
|
|
|
301
327
|
...(priced && Object.keys(priced).length ? { prices: priced } : {}),
|
|
302
328
|
};
|
|
303
329
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
330
|
+
// From here, in the guard's turn (a preset row's): what it stood on read, the triggers checked, the row written, and
|
|
331
|
+
// what it leaves at Composio counted.
|
|
332
|
+
const write = async () => {
|
|
333
|
+
if (guard && wasPreset) {
|
|
334
|
+
const stood = recordedMade(await this.store.settings.get(composioMadeKey(name)), was.createdAt);
|
|
335
|
+
if (moved || (made && stands && (!stood || stood.user !== stands.user || (stood.auth_config?.id ?? null) !== (stands.auth_config?.id ?? null))))
|
|
336
|
+
await guard.inUse();
|
|
337
|
+
}
|
|
338
|
+
const saved = keeping
|
|
339
|
+
// Re-applied only onto a row that still holds a credential of this auth type, at the address this save read: never
|
|
340
|
+
// onto another one's, nor over a row another save moved meanwhile (a Composio save over it, whose cleanup removed the
|
|
341
|
+
// MCP server at the address read; Composio's share an origin). It writes no credential column, so it never drops or
|
|
342
|
+
// replaces one.
|
|
343
|
+
? await this.rewriteKeeping(name, was, fields, "save", (fresh) => fresh.auth === auth.type && fresh.sealed !== null && fresh.url === was.url)
|
|
344
|
+
// A new credential, or none: written only while the row's credential is still `against`, in the store's one statement.
|
|
345
|
+
: changedMeanwhile(name, await saveMcpServerIfCredential(this.store, this.sealKey, { ...fields(was), ...(credential ? { credential } : {}) }, against, { githubMcpOrigin: this.appOrigin }));
|
|
346
|
+
if (source)
|
|
347
|
+
await this.store.settings.put(mcpSourceKey(name), storedSource(source, saved, !made && source === standIn));
|
|
348
|
+
// The Composio MCP server the row named before, when the preset made it (the row was a preset server) and the row names
|
|
349
|
+
// it no longer: a preset save over it made a new one, or an ordinary save moved the row off Composio.
|
|
350
|
+
const madeBefore = wasPreset && (made || moved) ? composioServerId(was.url) : undefined;
|
|
351
|
+
const leftMcp = madeBefore !== undefined && madeBefore !== composioServerId(url.href) ? madeBefore : undefined;
|
|
352
|
+
let left;
|
|
353
|
+
// What it stands on at Composio: what the preset found and made, over what the server saved before over this row had
|
|
354
|
+
// made. A row moved off Composio stands on nothing there: its delete removes nothing at Composio.
|
|
355
|
+
if (made && stands) {
|
|
356
|
+
const others = (await this.composioRecords()).filter(([other]) => other !== name);
|
|
357
|
+
const before = was ? recordedMade(await this.store.settings.get(composioMadeKey(name)), was.createdAt) : undefined;
|
|
358
|
+
const record = madeToWrite(stands, before, others.map(([, other]) => other));
|
|
359
|
+
await this.store.settings.put(composioMadeKey(name), storedMade(record, saved));
|
|
360
|
+
// What the save before made that this one no longer stands on: another saved server's now (its record rewritten to
|
|
361
|
+
// own it), or the caller's to remove at Composio, with the key it was made with.
|
|
362
|
+
if (was && before) {
|
|
363
|
+
const done = droppedOf(before, record, others.map(([other, mine]) => [other, mine]));
|
|
364
|
+
await this.handOver(others, done.handover);
|
|
365
|
+
left = done.cleanup;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else if (moved) {
|
|
369
|
+
// Moved off Composio: what its save made there goes as a delete's does (cleanupOf), the MCP server first, unless the
|
|
370
|
+
// new address names the same Composio MCP server, which still stands on it.
|
|
371
|
+
const before = recordedMade(await this.store.settings.get(composioMadeKey(name)), was.createdAt);
|
|
372
|
+
await this.store.settings.remove(composioMadeKey(name));
|
|
373
|
+
// Only for a caller in the Composio turn (`dropped`, with its `guard`), so no preset save still at Composio is counted out.
|
|
374
|
+
if (before && leftMcp && dropped) {
|
|
375
|
+
const others = (await this.composioRecords()).filter(([other]) => other !== name);
|
|
376
|
+
const done = cleanupOf(before, others.map(([other, record]) => [other, record]));
|
|
377
|
+
await this.handOver(others, done.handover);
|
|
378
|
+
left = done.cleanup;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (was && (leftMcp || left?.remove.length || left?.kept.length)) {
|
|
382
|
+
let key;
|
|
383
|
+
try {
|
|
384
|
+
key = composioKeyOf(openMcpRow(this.sealKey, was));
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
key = undefined;
|
|
388
|
+
}
|
|
389
|
+
dropped?.({ ...(key ? { key } : { unusable: true }), cleanup: left ?? { remove: [], kept: [] }, ...(leftMcp ? { mcp: leftMcp } : {}) });
|
|
390
|
+
}
|
|
391
|
+
return saved;
|
|
392
|
+
};
|
|
393
|
+
const saved = guard ? await guard.turn(write) : await write();
|
|
312
394
|
await this.store.flush();
|
|
313
395
|
return this.view(saved);
|
|
314
396
|
}
|
|
@@ -350,6 +432,9 @@ export class McpServersOverStore {
|
|
|
350
432
|
const fresh = await this.store.mcp.server(name);
|
|
351
433
|
if (!fresh)
|
|
352
434
|
throw notFound(name);
|
|
435
|
+
// A save over a row changed meanwhile is the owner's to redo, read again: never retried as it stands.
|
|
436
|
+
if (!still(fresh) && doing === "save")
|
|
437
|
+
changedMeanwhile(name, undefined);
|
|
353
438
|
if (!still(fresh))
|
|
354
439
|
throw new ApiError("unavailable", `The MCP server ${name} was changed while this ${doing} was made; nothing was saved. Read it again and try again.`);
|
|
355
440
|
if (tries >= REWRITE_TRIES)
|
|
@@ -366,6 +451,8 @@ export class McpServersOverStore {
|
|
|
366
451
|
const row = await this.need(name);
|
|
367
452
|
// Whether it is a Composio preset server: from its record (source composio), read before the row goes.
|
|
368
453
|
const preset = row.auth === "headers" && (await this.sourceOf(row)).source === "composio";
|
|
454
|
+
// What it stands on at Composio, as its save recorded it (none: saved before that was recorded, or not a preset).
|
|
455
|
+
const stands = preset ? recordedMade(await this.store.settings.get(composioMadeKey(name)), row.createdAt) : undefined;
|
|
369
456
|
// The credential revoked is the one the deleting statement saw (RETURNING): a run's refresh landing before it is in it,
|
|
370
457
|
// one landing after finds no row to keep. A sign-in kept as expired has no refresh token left to revoke.
|
|
371
458
|
const removed = checkedAgainst === undefined ? await removeMcpServer(this.store, this.sealKey, name)
|
|
@@ -376,12 +463,44 @@ export class McpServersOverStore {
|
|
|
376
463
|
// never read for another row (mcp-sources.ts), so a server saved again says what it is afresh.
|
|
377
464
|
if (!recordedForAnother(await this.store.settings.get(mcpSourceKey(name)), row.createdAt))
|
|
378
465
|
await this.store.settings.remove(mcpSourceKey(name));
|
|
466
|
+
// What it made at Composio that another saved server uses stays, that one's now (its record rewritten to own it); the
|
|
467
|
+
// rest the delete route removes there.
|
|
468
|
+
let cleanup;
|
|
469
|
+
if (stands) {
|
|
470
|
+
if (!recordedForAnother(await this.store.settings.get(composioMadeKey(name)), row.createdAt))
|
|
471
|
+
await this.store.settings.remove(composioMadeKey(name));
|
|
472
|
+
const others = (await this.composioRecords()).filter(([other]) => other !== name);
|
|
473
|
+
const done = cleanupOf(stands, others.map(([other, record]) => [other, record]));
|
|
474
|
+
await this.handOver(others, done.handover);
|
|
475
|
+
cleanup = done.cleanup;
|
|
476
|
+
}
|
|
379
477
|
await this.store.flush();
|
|
380
478
|
const open = removed?.opened;
|
|
381
479
|
const credential = open && "credential" in open && open.credential.type === "oauth" && !open.credential.expired ? open.credential : undefined;
|
|
382
480
|
if (credential && removed)
|
|
383
481
|
void this.track(this.signIns.revoke(credential.set, removed.url, this.stopped.signal));
|
|
384
|
-
return preset ? { composio: composioHandleOf(removed) } : {};
|
|
482
|
+
return preset ? { composio: composioHandleOf(removed, cleanup) } : {};
|
|
483
|
+
}
|
|
484
|
+
/** Whether `name` is a Composio preset server now (auth headers, source composio): a save of it takes the Composio turn,
|
|
485
|
+
* since one that moves it off Composio removes there what the preset made for it. */
|
|
486
|
+
async composioPreset(name) {
|
|
487
|
+
const row = await this.store.mcp.server(name);
|
|
488
|
+
return row !== undefined && row.auth === "headers" && (await this.sourceOf(row)).source === "composio";
|
|
489
|
+
}
|
|
490
|
+
/** Writes each record a cleanup passes a thing to (composio-made.ts `handover`), for its own row of `others`. */
|
|
491
|
+
async handOver(others, handover) {
|
|
492
|
+
for (const [other, record] of handover) {
|
|
493
|
+
const of = others.find(([n]) => n === other)?.[2];
|
|
494
|
+
if (of !== undefined)
|
|
495
|
+
await this.store.settings.put(composioMadeKey(other), storedMade(record, { createdAt: of }));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/** The saved servers' records of what they stand on at Composio (composio-made.ts), each read for its own row: name,
|
|
499
|
+
* record and the row's created_at. */
|
|
500
|
+
async composioRecords() {
|
|
501
|
+
const rows = await listMcpServers(this.store);
|
|
502
|
+
const read = await Promise.all(rows.map(async (row) => [row.name, recordedMade(await this.store.settings.get(composioMadeKey(row.name)), row.createdAt), row.createdAt]));
|
|
503
|
+
return read.filter((entry) => entry[1] !== undefined).map(([name, record, at]) => [name, record, at]);
|
|
385
504
|
}
|
|
386
505
|
/** POST .../{name}/oauth/start: `{url, scopes?, client_id?, client_secret?, toolkit?}`; answers the URL the owner opens.
|
|
387
506
|
* Its toolkit, as a save's, is written for the server the sign-in saves. */
|
package/dist/mcp.d.ts
CHANGED
|
@@ -41,10 +41,10 @@ export declare const TOOLS: Tool[];
|
|
|
41
41
|
/** GET /llms.txt: what this server is, for a coding agent, without a credential. The text is the repository's
|
|
42
42
|
* `src/llms.txt`, copied beside the server by the build; it holds no data of this server's. */
|
|
43
43
|
export declare function answerLlms(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
44
|
-
/** The endpoint: `route` serves each tool, `authorized` checks an Authorization header against the
|
|
44
|
+
/** The endpoint: `route` serves each tool, `authorized` checks an Authorization header against the server's tokens (and keeps which one opened `req`). */
|
|
45
45
|
export declare function mcpEndpoint({ route, authorized, authFailed, version }: {
|
|
46
46
|
route: Route;
|
|
47
|
-
authorized: (header: string) => boolean;
|
|
47
|
+
authorized: (header: string, req: IncomingMessage) => boolean;
|
|
48
48
|
authFailed: (route: string, reason: string) => void;
|
|
49
49
|
version: string;
|
|
50
50
|
}): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
package/dist/mcp.js
CHANGED
|
@@ -265,7 +265,7 @@ export async function answerLlms(req, res) {
|
|
|
265
265
|
res.writeHead(200, { "content-type": "text/plain; charset=utf-8", "content-length": String(body.length), "cache-control": "no-cache", "x-content-type-options": "nosniff" });
|
|
266
266
|
res.end(req.method === "HEAD" ? undefined : body);
|
|
267
267
|
}
|
|
268
|
-
/** The endpoint: `route` serves each tool, `authorized` checks an Authorization header against the
|
|
268
|
+
/** The endpoint: `route` serves each tool, `authorized` checks an Authorization header against the server's tokens (and keeps which one opened `req`). */
|
|
269
269
|
export function mcpEndpoint({ route, authorized, authFailed, version }) {
|
|
270
270
|
function reply(res, status, body, headers = {}) {
|
|
271
271
|
res.writeHead(status, { ...(body === undefined ? {} : { "content-type": "application/json" }), "cache-control": "no-store", "x-content-type-options": "nosniff", ...headers });
|
|
@@ -349,7 +349,7 @@ export function mcpEndpoint({ route, authorized, authFailed, version }) {
|
|
|
349
349
|
return reply(res, 403, rpcError(null, -32600, "this Origin may not call this server's MCP endpoint"));
|
|
350
350
|
// The token only: the page's session cookie is not taken here (server.ts answers this path before the page).
|
|
351
351
|
const authorization = req.headers.authorization;
|
|
352
|
-
if (authorization === undefined || !authorized(authorization)) {
|
|
352
|
+
if (authorization === undefined || !authorized(authorization, req)) {
|
|
353
353
|
authFailed(MCP_PATH, authorization === undefined ? "no_credential" : "wrong_token");
|
|
354
354
|
return reply(res, 401, rpcError(null, -32001, "the MCP endpoint needs Authorization: Bearer <the token in the data directory>"), { "www-authenticate": "Bearer" });
|
|
355
355
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
2
|
import { Observations } from "./observer.js";
|
|
3
3
|
export declare function isObservationRoute(path: string): boolean;
|
|
4
|
-
export declare function observationHttp(req: IncomingMessage, res: ServerResponse, url: URL, observer: Observations,
|
|
4
|
+
export declare function observationHttp(req: IncomingMessage, res: ServerResponse, url: URL, observer: Observations,
|
|
5
|
+
/** Whether the Authorization header holds one of the server's API tokens (api-token.ts bearerCheck: every entry
|
|
6
|
+
* compared in constant time). */
|
|
7
|
+
authorized: (header: string | undefined) => boolean): Promise<void>;
|
package/dist/observation/http.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** Compatibility routes for the existing source-side CLI. Only bearer auth; browser cookies confer no authority. */
|
|
2
|
-
import { createHash, timingSafeEqual } from "node:crypto";
|
|
3
2
|
import { gunzipSync } from "node:zlib";
|
|
4
3
|
import { MAX_OTLP_PAYLOAD_BYTES, observationCapabilities, ObservationError, } from "./observer.js";
|
|
5
4
|
const PREFIX = "/api/v2/control";
|
|
6
|
-
const digest = (v) => createHash("sha256").update(v).digest();
|
|
7
5
|
const send = (res, status, body, headers = {}) => {
|
|
8
6
|
res.writeHead(status, {
|
|
9
7
|
"content-type": "application/json",
|
|
@@ -52,7 +50,10 @@ async function read(req, maxBytes = 65536) {
|
|
|
52
50
|
export function isObservationRoute(path) {
|
|
53
51
|
return path === PREFIX || path.startsWith(PREFIX + "/");
|
|
54
52
|
}
|
|
55
|
-
export async function observationHttp(req, res, url, observer,
|
|
53
|
+
export async function observationHttp(req, res, url, observer,
|
|
54
|
+
/** Whether the Authorization header holds one of the server's API tokens (api-token.ts bearerCheck: every entry
|
|
55
|
+
* compared in constant time). */
|
|
56
|
+
authorized) {
|
|
56
57
|
try {
|
|
57
58
|
const path = url.pathname.slice(PREFIX.length), method = req.method ?? "GET";
|
|
58
59
|
const credential = String(req.headers.authorization ?? "").replace(/^Bearer /, "");
|
|
@@ -72,7 +73,7 @@ export async function observationHttp(req, res, url, observer, ownerToken) {
|
|
|
72
73
|
: await observer.otlp(id, credential, body, Number(req.headers["x-agentrun-selections-revision"]));
|
|
73
74
|
return send(res, 200, result);
|
|
74
75
|
}
|
|
75
|
-
if (!
|
|
76
|
+
if (!authorized(req.headers.authorization))
|
|
76
77
|
throw new ObservationError(401, "connector_unauthorized");
|
|
77
78
|
const workspace = url.searchParams.get("workspace_id");
|
|
78
79
|
if (workspace !== null && workspace !== "local")
|
package/dist/openapi.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type TriggerAdapter } from "./trigger-adapter.js";
|
|
2
2
|
import "./mcp-secret-writes.js";
|
|
3
3
|
import "./email/routes.js";
|
|
4
|
+
import "./calendar/routes.js";
|
|
4
5
|
import "./computers.js";
|
|
5
6
|
type Json = Record<string, unknown>;
|
|
6
7
|
/** Why each capability this server turns off answers 501, by the route's capability. */
|