@parcha/agentrun-serve 0.1.0-beta.46 → 0.1.0-beta.47
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 +164 -1
- package/NOTICE +4 -0
- package/README.md +267 -40
- package/dist/acp-package.d.ts +35 -6
- package/dist/acp-package.js +3 -3
- package/dist/adapter-facts.d.ts +5 -2
- package/dist/adapter-facts.js +6 -3
- package/dist/adapters.d.ts +7 -0
- package/dist/adapters.js +39 -0
- package/dist/agents-store.d.ts +5 -3
- package/dist/agents-store.js +13 -8
- package/dist/api-only.d.ts +7 -10
- package/dist/api-only.js +7 -10
- package/dist/archil-routes.js +2 -1
- package/dist/cap.js +12 -2
- package/dist/chatgpt-plan.js +2 -1
- package/dist/cli.js +109 -41
- package/dist/composio-made.d.ts +19 -2
- package/dist/composio-made.js +17 -5
- package/dist/composio-preset.d.ts +42 -7
- package/dist/composio-preset.js +106 -70
- package/dist/composio-triggers.d.ts +9 -4
- package/dist/composio-triggers.js +20 -13
- package/dist/computer-attach.d.ts +11 -10
- package/dist/computer-attach.js +13 -14
- package/dist/computer-commands.d.ts +3 -0
- package/dist/computer-commands.js +3 -2
- package/dist/computer-lost.d.ts +4 -0
- package/dist/computer-lost.js +8 -3
- package/dist/computer-setting.d.ts +2 -0
- package/dist/computer-setting.js +2 -0
- package/dist/computers.d.ts +9 -75
- package/dist/computers.js +20 -66
- package/dist/console/assets/index-BBFzAxLB.js +715 -0
- package/dist/console/assets/index-BRi-Rgq6.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/cost-heal.d.ts +13 -0
- package/dist/cost-heal.js +27 -0
- package/dist/dial-relay.d.ts +6 -2
- package/dist/dial-relay.js +9 -12
- package/dist/email/routes.js +2 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +5 -0
- package/dist/exa-keyless.d.ts +1 -1
- package/dist/exa-keyless.js +1 -1
- package/dist/faux-computers.d.ts +2 -3
- package/dist/faux-computers.js +9 -31
- package/dist/github-connection.js +2 -1
- package/dist/harness-archive.d.ts +19 -2
- package/dist/harness-archive.js +49 -15
- package/dist/harness-check.d.ts +73 -0
- package/dist/harness-check.js +489 -0
- package/dist/harness-cursor.d.ts +45 -0
- package/dist/harness-cursor.js +121 -0
- package/dist/harness-recipe.d.ts +127 -0
- package/dist/harness-recipe.js +357 -0
- package/dist/harness-table.d.ts +12 -0
- package/dist/harness-table.js +62 -2
- package/dist/harness.d.ts +2 -0
- package/dist/harness.js +3 -2
- package/dist/host-check.d.ts +6 -0
- package/dist/host-check.js +14 -0
- package/dist/host.d.ts +10 -3
- package/dist/host.js +17 -3
- package/dist/import-sources.d.ts +2 -0
- package/dist/import-sources.js +2 -0
- package/dist/import-summary.d.ts +15 -5
- package/dist/import-summary.js +24 -8
- package/dist/import.d.ts +24 -4
- package/dist/import.js +108 -26
- package/dist/key-refusal.d.ts +1 -0
- package/dist/key-refusal.js +8 -3
- package/dist/key-words.d.ts +1 -1
- package/dist/key-words.js +4 -4
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +31 -20
- package/dist/learn/compile.js +12 -5
- package/dist/learn/promote.d.ts +69 -2
- package/dist/learn/promote.js +95 -3
- package/dist/learned-nodes.d.ts +4 -3
- package/dist/learned-workflow.js +4 -1
- package/dist/learning-cost.d.ts +6 -16
- package/dist/learning-cost.js +6 -12
- package/dist/learning-words.d.ts +2 -0
- package/dist/learning-words.js +1 -1
- package/dist/listen-first.d.ts +10 -0
- package/dist/listen-first.js +25 -1
- package/dist/llms.txt +1 -1
- package/dist/mcp-gateway.d.ts +2 -1
- package/dist/mcp-gateway.js +31 -15
- package/dist/mcp-probe.d.ts +18 -6
- package/dist/mcp-probe.js +41 -8
- package/dist/mcp-secret-writes.d.ts +8 -0
- package/dist/mcp-secret-writes.js +104 -4
- package/dist/mcp-servers-store.d.ts +11 -5
- package/dist/mcp-servers-store.js +46 -20
- package/dist/model-form.d.ts +2 -1
- package/dist/model-form.js +22 -8
- package/dist/model-gateway.d.ts +113 -0
- package/dist/model-gateway.js +433 -0
- package/dist/model.d.ts +2 -1
- package/dist/model.js +9 -7
- package/dist/monid.js +1 -1
- package/dist/native/binding.d.ts +4 -0
- package/dist/native/binding.js +9 -0
- package/dist/native/cli.d.ts +3 -2
- package/dist/native/cli.js +6 -5
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +322 -39
- package/dist/owner.d.ts +4 -2
- package/dist/owner.js +10 -4
- package/dist/page.d.ts +8 -0
- package/dist/page.js +9 -1
- package/dist/port-models.js +17 -10
- package/dist/provider.d.ts +3 -3
- package/dist/provider.js +12 -3
- package/dist/public-address.d.ts +28 -0
- package/dist/public-address.js +62 -0
- package/dist/run-launch.d.ts +1 -1
- package/dist/run-launch.js +1 -1
- package/dist/run-secrets.d.ts +3 -2
- package/dist/run-secrets.js +6 -4
- package/dist/runner/adapter-loop.d.ts +10 -7
- package/dist/runner/adapter-loop.js +57 -22
- package/dist/runner/adapter-run-spec.d.ts +12 -0
- package/dist/runner/adapter-run-spec.js +40 -6
- package/dist/runner/adapters/index.js +16 -0
- package/dist/runner/adapters/pi.d.ts +5 -2
- package/dist/runner/adapters/pi.js +7 -4
- package/dist/runner/audit.d.ts +7 -0
- package/dist/runner/audit.js +15 -6
- package/dist/runner/claim-secrets.js +5 -1
- package/dist/runner/cli-run-spec.js +15 -7
- package/dist/runner/compare-end.d.ts +43 -0
- package/dist/runner/compare-end.js +95 -0
- package/dist/runner/computer-journal.d.ts +3 -0
- package/dist/runner/computer-journal.js +22 -2
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +94 -54
- package/dist/runner/held.d.ts +5 -4
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +3 -0
- package/dist/runner/loop-contract.d.ts +10 -0
- package/dist/runner/main.d.ts +5 -5
- package/dist/runner/main.js +62 -11
- package/dist/runner/mcp-claim.js +40 -12
- package/dist/runner/metrics.d.ts +26 -0
- package/dist/runner/metrics.js +44 -1
- package/dist/runner/presence.d.ts +41 -0
- package/dist/runner/presence.js +89 -0
- package/dist/runner/promotion.d.ts +9 -4
- package/dist/runner/promotion.js +33 -14
- package/dist/runner/run-child-host.js +40 -10
- package/dist/runner/runner.d.ts +5 -0
- package/dist/runner/runner.js +8 -0
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/store-secrets.js +19 -7
- package/dist/runner/workflow-first.d.ts +5 -2
- package/dist/runner/workflow-first.js +6 -3
- package/dist/runs-over-store.d.ts +6 -2
- package/dist/runs-over-store.js +14 -4
- package/dist/sdk/runs.d.ts +1 -1
- package/dist/sdk/runs.js +6 -1
- package/dist/sdk/schema.js +1 -1
- package/dist/secret-writes.d.ts +16 -3
- package/dist/secret-writes.js +28 -3
- package/dist/server-secrets-store.js +5 -0
- package/dist/server.d.ts +31 -2
- package/dist/server.js +322 -51
- package/dist/sign-ins-secrets.js +4 -1
- package/dist/skills/agentrun-serve/SKILL.md +11 -0
- package/dist/slack-url.d.ts +5 -0
- package/dist/slack-url.js +11 -0
- package/dist/slack.d.ts +107 -0
- package/dist/slack.js +292 -0
- package/dist/start-switches.d.ts +28 -0
- package/dist/start-switches.js +37 -0
- package/dist/stats.d.ts +1 -1
- package/dist/stats.js +2 -1
- package/dist/stop-signals.d.ts +11 -0
- package/dist/stop-signals.js +22 -0
- package/dist/store/agent-body.d.ts +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +1 -1
- package/dist/store/postgres/migrations/0020_runners.sql +18 -0
- package/dist/store/postgres/store.d.ts +1 -1
- package/dist/store/postgres/store.js +4 -2
- package/dist/store/schema.d.ts +13 -5
- package/dist/store/schema.js +20 -11
- package/dist/store/seal.d.ts +16 -4
- package/dist/store/sqlite/store.d.ts +1 -1
- package/dist/store/sqlite/store.js +106 -27
- package/dist/store/store.d.ts +75 -23
- package/dist/store/store.js +11 -0
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +7 -0
- package/dist/store-reads/cap.js +11 -1
- package/dist/store-reads/journal.js +27 -1
- package/dist/store-reads/learning.d.ts +23 -2
- package/dist/store-reads/learning.js +29 -8
- package/dist/store-reads/runs.d.ts +9 -0
- package/dist/store-reads/runs.js +19 -6
- package/dist/store-reads/stats.d.ts +4 -1
- package/dist/store-reads/stats.js +15 -6
- package/dist/store-view.d.ts +123 -14
- package/dist/store-view.js +154 -21
- package/dist/telemetry.d.ts +7 -7
- package/dist/telemetry.js +38 -15
- package/dist/timeline/timeline.js +18 -0
- package/dist/tool-keys-store.js +2 -2
- package/dist/tool-keys.js +2 -1
- package/dist/tool-plane.js +2 -2
- package/dist/trigger-adapter.d.ts +3 -4
- package/dist/trigger-adapter.js +2 -2
- package/dist/trigger-composio.js +3 -3
- package/dist/trigger-email.js +0 -2
- package/dist/trigger-feed.js +0 -2
- package/dist/trigger-schedule.js +3 -0
- package/dist/trigger-secrets-shown.d.ts +6 -3
- package/dist/trigger-secrets-shown.js +22 -13
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +19 -8
- package/dist/triggers.d.ts +2 -2
- package/dist/webhooks.d.ts +82 -8
- package/dist/webhooks.js +128 -45
- package/dist/wires.d.ts +6 -1
- package/dist/wires.js +5 -0
- package/dist/workspace/attach.d.ts +3 -2
- package/dist/workspace/attach.js +2 -1
- package/dist/workspace/attached-computers.d.ts +6 -8
- package/dist/workspace/attached-computers.js +27 -24
- package/dist/workspace/computer-deps.d.ts +2 -3
- package/dist/workspace/computer-deps.js +3 -6
- package/dist/workspace/computer-for-claim.js +72 -96
- package/dist/workspace/computer-kept.d.ts +0 -7
- package/dist/workspace/computer-kept.js +0 -17
- package/dist/workspace/resolve-computer.d.ts +18 -14
- package/dist/workspace/resolve-computer.js +47 -60
- package/dist/workspace/synced-folder.d.ts +20 -15
- package/dist/workspace/synced-folder.js +33 -43
- package/launcher/agentrun-serve +4 -1
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +11 -0
- package/templates/README.md +1 -1
- package/dist/console/assets/index-C2MYaUBa.css +0 -1
- package/dist/console/assets/index-CZZeCReB.js +0 -701
package/dist/composio-made.d.ts
CHANGED
|
@@ -4,11 +4,18 @@ export type Made = {
|
|
|
4
4
|
made: boolean;
|
|
5
5
|
};
|
|
6
6
|
/** What a preset server stands on at Composio: the user its address names, its auth config (none for a toolkit with no
|
|
7
|
-
* sign-in) and the connected accounts
|
|
7
|
+
* sign-in; `named`, from a save, when the owner named it: theirs, never recorded as made) and the connected accounts
|
|
8
|
+
* under it. `per_run`: saved with `user_id: "per_run"` (COMPOSIO_PER_RUN), its address names no user and no account,
|
|
9
|
+
* and each run names its own (mcp_auth, composioPerRun); `user` is then that word and `accounts` empty. Only a save made
|
|
10
|
+
* since the mode exists writes it, so a server saved before for a Composio user literally named "per_run" keeps that
|
|
11
|
+
* user until it is saved again. */
|
|
8
12
|
export type ComposioMade = {
|
|
9
13
|
user: string;
|
|
10
|
-
auth_config: Made
|
|
14
|
+
auth_config: (Made & {
|
|
15
|
+
named?: true;
|
|
16
|
+
}) | null;
|
|
11
17
|
accounts: Made[];
|
|
18
|
+
per_run?: true;
|
|
12
19
|
};
|
|
13
20
|
/** What a delete does at Composio beyond the MCP server: what it removes, in order (the accounts before the auth config
|
|
14
21
|
* they are under), and what it keeps, each with whose it stays (`by`: the saved server that uses it too; none: this
|
|
@@ -34,10 +41,20 @@ export declare const storedMade: (made: ComposioMade, row: {
|
|
|
34
41
|
/** A stored record read for the row created at `createdAt`; undefined when there is none, it was written for another row,
|
|
35
42
|
* or it is not one (then nothing beyond the MCP server is removed). */
|
|
36
43
|
export declare function recordedMade(value: unknown, createdAt: number | undefined): ComposioMade | undefined;
|
|
44
|
+
/** Whether the saved server `row` is a per-run Composio server: auth headers (the install's sealed key) and its own
|
|
45
|
+
* record (`recorded`, read at composioMadeKey) saying per_run. Its runs call it as the Composio user and account each
|
|
46
|
+
* names (mcp_auth.<server> = {composio_user_id, connected_account_id?}); one that names none is refused unsent. */
|
|
47
|
+
export declare const composioPerRun: (row: {
|
|
48
|
+
auth: string;
|
|
49
|
+
createdAt: number;
|
|
50
|
+
}, recorded: unknown) => boolean;
|
|
37
51
|
/** A record a save writes, from what the preset found and made (`found`): a thing it found that a record of the server
|
|
38
52
|
* saved before over this row (`was`) or of another saved server (`others`) says was made here stays made here; and the
|
|
39
53
|
* accounts the server saved before had made, under the same auth config and user, stay its own. */
|
|
40
54
|
export declare function madeToWrite(found: ComposioMade, was: ComposioMade | undefined, others: readonly ComposioMade[]): ComposioMade;
|
|
55
|
+
/** The records of the other saved servers (`others`, by name) that say they made the auth config `id`, each as it is to
|
|
56
|
+
* be written once the owner named that config in a save: made by none of them, so none of their deletes removes it. */
|
|
57
|
+
export declare function releasedOf(id: string, others: readonly (readonly [string, ComposioMade, ...unknown[]])[]): [string, ComposioMade][];
|
|
41
58
|
/** What a removed server's record leaves to do, with the records of the servers still saved (`others`, by name): each
|
|
42
59
|
* thing it made that none of them uses is removed; one another uses is kept and passed to that one (`handover`: its record
|
|
43
60
|
* as it is to be written, owning it); one it didn't make is kept. */
|
package/dist/composio-made.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
// made that no other saved server uses (cleanupOf), and passes what another one uses to that one's record, so the last
|
|
7
7
|
// of them to go removes it. What this server didn't make (an auth config or an account the owner had already, or one no
|
|
8
8
|
// record says it made, as for a server saved before this was recorded) is never removed. A save over the server does the
|
|
9
|
-
// same with what the record it replaces made that the new one no longer stands on (droppedOf).
|
|
9
|
+
// same with what the record it replaces made that the new one no longer stands on (droppedOf). An auth config the owner
|
|
10
|
+
// names in a save (auth_config_id) is the owner's from that save on, whoever made it: the record written says it was not
|
|
11
|
+
// made here, and every other record's claim to have made it is let go (releasedOf), so no delete or save removes it.
|
|
10
12
|
import { isObject } from "./validate.js";
|
|
11
13
|
/** The store.settings key a server's record lives under. */
|
|
12
14
|
export const composioMadeKey = (name) => `mcp.composio/${name}`;
|
|
@@ -23,21 +25,31 @@ export function recordedMade(value, createdAt) {
|
|
|
23
25
|
const accounts = value.accounts.map(thingOf);
|
|
24
26
|
if (config === undefined || accounts.some((account) => !account))
|
|
25
27
|
return undefined;
|
|
26
|
-
return { user: value.user, auth_config: config, accounts: accounts };
|
|
28
|
+
return { user: value.user, auth_config: config, accounts: accounts, ...(value.per_run === true ? { per_run: true } : {}) };
|
|
27
29
|
}
|
|
30
|
+
/** Whether the saved server `row` is a per-run Composio server: auth headers (the install's sealed key) and its own
|
|
31
|
+
* record (`recorded`, read at composioMadeKey) saying per_run. Its runs call it as the Composio user and account each
|
|
32
|
+
* names (mcp_auth.<server> = {composio_user_id, connected_account_id?}); one that names none is refused unsent. */
|
|
33
|
+
export const composioPerRun = (row, recorded) => row.auth === "headers" && recordedMade(recorded, row.createdAt)?.per_run === true;
|
|
28
34
|
/** Whether `other` stands on `mine`'s account: under the same auth config, as the same user (Composio's MCP server picks
|
|
29
35
|
* the account by the two). */
|
|
30
|
-
const sharesAccounts = (mine, other) => mine.auth_config !== null && other.auth_config?.id === mine.auth_config.id && other.user === mine.user;
|
|
36
|
+
const sharesAccounts = (mine, other) => mine.auth_config !== null && other.auth_config?.id === mine.auth_config.id && other.user === mine.user && !mine.per_run && !other.per_run;
|
|
31
37
|
/** A record a save writes, from what the preset found and made (`found`): a thing it found that a record of the server
|
|
32
38
|
* saved before over this row (`was`) or of another saved server (`others`) says was made here stays made here; and the
|
|
33
39
|
* accounts the server saved before had made, under the same auth config and user, stay its own. */
|
|
34
40
|
export function madeToWrite(found, was, others) {
|
|
35
41
|
const all = [...(was ? [was] : []), ...others];
|
|
36
42
|
const madeHere = (id) => all.some((r) => r.auth_config?.id === id ? r.auth_config.made : false) || all.some((r) => r.accounts.some((a) => a.id === id && a.made));
|
|
37
|
-
|
|
43
|
+
// One the owner named is theirs, whatever a record says made it.
|
|
44
|
+
const config = found.auth_config && { id: found.auth_config.id, made: !found.auth_config.named && (found.auth_config.made || madeHere(found.auth_config.id)) };
|
|
38
45
|
const accounts = found.accounts.map((a) => ({ id: a.id, made: a.made || madeHere(a.id) }));
|
|
39
46
|
const kept = was && sharesAccounts(found, was) ? was.accounts.filter((a) => a.made && !accounts.some((b) => b.id === a.id)) : [];
|
|
40
|
-
return { user: found.user, auth_config: config, accounts: [...accounts, ...kept] };
|
|
47
|
+
return { user: found.user, auth_config: config, accounts: [...accounts, ...kept], ...(found.per_run ? { per_run: true } : {}) };
|
|
48
|
+
}
|
|
49
|
+
/** The records of the other saved servers (`others`, by name) that say they made the auth config `id`, each as it is to
|
|
50
|
+
* be written once the owner named that config in a save: made by none of them, so none of their deletes removes it. */
|
|
51
|
+
export function releasedOf(id, others) {
|
|
52
|
+
return others.filter(([, record]) => record.auth_config?.id === id && record.auth_config.made).map(([name, record]) => [name, { ...record, auth_config: { id, made: false } }]);
|
|
41
53
|
}
|
|
42
54
|
/** What a removed server's record leaves to do, with the records of the servers still saved (`others`, by name): each
|
|
43
55
|
* thing it made that none of them uses is removed; one another uses is kept and passed to that one (`handover`: its record
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Cleanup, ComposioMade } from "./composio-made.js";
|
|
2
|
+
import { type InputIssue } from "./errors.js";
|
|
2
3
|
import { type Json } from "./validate.js";
|
|
3
4
|
/** Another Composio than the real one, and its fetch: a test's fake (the same seam as `archilControl`). */
|
|
4
5
|
export type ComposioControl = {
|
|
@@ -7,16 +8,29 @@ export type ComposioControl = {
|
|
|
7
8
|
};
|
|
8
9
|
/** The one Composio user a server's actions run as, unless the owner names another. */
|
|
9
10
|
export declare const COMPOSIO_USER = "agentrun";
|
|
11
|
+
/** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
|
|
12
|
+
export declare const COMPOSIO_TOOLKIT: RegExp;
|
|
13
|
+
/** A Composio user id, as a save's `user_id` and a run's binding (mcp_auth's composio_user_id) take it. */
|
|
14
|
+
export declare const COMPOSIO_USER_ID: RegExp;
|
|
15
|
+
/** The `user_id` a save names for a per-run server, reserved for that and never a Composio user: the server keeps no user
|
|
16
|
+
* and no connected account, and each run names its own (mcp_auth.<server> = {composio_user_id, connected_account_id?}). */
|
|
17
|
+
export declare const COMPOSIO_PER_RUN = "per_run";
|
|
18
|
+
/** A Composio connected account's id, as a run's binding names one: Composio's are `ca_` and a short random id. At least
|
|
19
|
+
* 8 characters in all, so the run's redactors (which hold a value of 8 or more) hold every one. */
|
|
20
|
+
export declare const COMPOSIO_ACCOUNT_ID: RegExp;
|
|
21
|
+
/** A Composio auth config's id, as its dashboard and API show it (`ac_` and a nanoid). */
|
|
22
|
+
export declare const COMPOSIO_AUTH_CONFIG_ID: RegExp;
|
|
10
23
|
export type ComposioTool = {
|
|
11
24
|
slug: string;
|
|
12
25
|
name: string;
|
|
13
26
|
description: string;
|
|
14
27
|
};
|
|
15
28
|
/** A Composio call (asking): its JSON answer, or the refusal in words that name its step. */
|
|
16
|
-
export type Ask = (step: string, method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, missing?: string) => Promise<Json>;
|
|
29
|
+
export type Ask = (step: string, method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body?: unknown, missing?: string | InputIssue) => Promise<Json>;
|
|
17
30
|
/** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
|
|
18
31
|
* value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
|
|
19
|
-
* with sealed values in play passes on none of Composio's words.
|
|
32
|
+
* with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
|
|
33
|
+
* toolkit it has not, or the refusal on another field. */
|
|
20
34
|
export declare function asking(control: ComposioControl, key: string, signal: AbortSignal | undefined, outcome?: string, sealed?: readonly string[]): Ask;
|
|
21
35
|
/** POST /settings/mcp-servers/composio/tools: a toolkit's actions, for the console's picker, and whether it needs no sign-in. */
|
|
22
36
|
export declare function composioTools(body: unknown, control: ComposioControl, signal?: AbortSignal): Promise<{
|
|
@@ -24,13 +38,33 @@ export declare function composioTools(body: unknown, control: ComposioControl, s
|
|
|
24
38
|
no_auth: boolean;
|
|
25
39
|
tools: ComposioTool[];
|
|
26
40
|
}>;
|
|
41
|
+
/** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
|
|
42
|
+
* has none for it yet. */
|
|
43
|
+
export declare function managedConfig(ask: Ask, toolkit: string): Promise<string | undefined>;
|
|
27
44
|
/** The address Composio's generate answers, made one this server's client can use: the helper actions that connect an
|
|
28
|
-
* account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose).
|
|
29
|
-
|
|
45
|
+
* account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose).
|
|
46
|
+
* `perRun`: with no user and no connected account in it either, for each run to name its own (composioRunAddress). */
|
|
47
|
+
export declare function composioAddress(generated: string, perRun?: boolean): string;
|
|
48
|
+
/** The Composio user a per-run server's tools are listed as (its save, refresh, preview and an agent's save): Composio's
|
|
49
|
+
* MCP endpoint refuses an address that names no user, its listing too, and any user lists the server's tools. Outside
|
|
50
|
+
* COMPOSIO_USER_ID (the ~), so no save and no run's binding can name it: never stored, never used for a call. */
|
|
51
|
+
export declare const COMPOSIO_LISTING_USER = "agentrun~tool-listing";
|
|
52
|
+
/** The address a per-run Composio server's tools are listed at: its saved one (no user, no account) as
|
|
53
|
+
* COMPOSIO_LISTING_USER. */
|
|
54
|
+
export declare function composioListingAddress(saved: URL): URL;
|
|
55
|
+
/** What a run's requests to a per-run Composio server add to its saved address: the Composio user and, when the run's
|
|
56
|
+
* binding names one, the connected account its calls run as (Composio's MCP endpoint reads both from the query). */
|
|
57
|
+
export declare const composioRunQuery: (binding: {
|
|
58
|
+
readonly user_id: string;
|
|
59
|
+
readonly connected_account_id?: string;
|
|
60
|
+
}) => Record<string, string>;
|
|
30
61
|
/** PUT /settings/mcp-servers/{name}/composio: Composio makes the managed MCP server, `save` keeps it as a saved MCP server
|
|
31
|
-
* (`{url, auth}`: the key a sealed header
|
|
32
|
-
*
|
|
33
|
-
*
|
|
62
|
+
* (`{url, auth}`: the key a sealed header; `prices`, each granted action at `price_usd` when the body names one), and a
|
|
63
|
+
* toolkit that needs the person's account says where to connect it. The auth config is the body's `auth_config_id` (one
|
|
64
|
+
* the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
|
|
65
|
+
* toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
|
|
66
|
+
* composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
|
|
67
|
+
* it, for its delete to remove what was made. */
|
|
34
68
|
export declare function composioSave<T extends {
|
|
35
69
|
tools?: readonly {
|
|
36
70
|
name: string;
|
|
@@ -41,6 +75,7 @@ export declare function composioSave<T extends {
|
|
|
41
75
|
type: "headers";
|
|
42
76
|
headers: Record<string, string>;
|
|
43
77
|
};
|
|
78
|
+
prices?: Record<string, number>;
|
|
44
79
|
}, made: {
|
|
45
80
|
source: "composio";
|
|
46
81
|
toolkit: string | null;
|
package/dist/composio-preset.js
CHANGED
|
@@ -7,22 +7,41 @@
|
|
|
7
7
|
// is never logged, echoed or put in an error.
|
|
8
8
|
import { randomBytes } from "node:crypto";
|
|
9
9
|
import { ApiError, invalid } from "./errors.js";
|
|
10
|
+
import { priceValid } from "./mcp-probe.js";
|
|
10
11
|
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
11
12
|
import { isObject } from "./validate.js";
|
|
12
13
|
const BASE = "https://backend.composio.dev";
|
|
13
14
|
/** The one Composio user a server's actions run as, unless the owner names another. */
|
|
14
15
|
export const COMPOSIO_USER = "agentrun";
|
|
15
|
-
|
|
16
|
-
const
|
|
16
|
+
/** A Composio toolkit's slug, as a save takes it once trimmed and lower-cased. */
|
|
17
|
+
export const COMPOSIO_TOOLKIT = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
18
|
+
const TOOLKIT = COMPOSIO_TOOLKIT;
|
|
19
|
+
/** A Composio user id, as a save's `user_id` and a run's binding (mcp_auth's composio_user_id) take it. */
|
|
20
|
+
export const COMPOSIO_USER_ID = /^[A-Za-z0-9._@-]{1,128}$/;
|
|
21
|
+
const USER_ID = COMPOSIO_USER_ID;
|
|
22
|
+
/** The `user_id` a save names for a per-run server, reserved for that and never a Composio user: the server keeps no user
|
|
23
|
+
* and no connected account, and each run names its own (mcp_auth.<server> = {composio_user_id, connected_account_id?}). */
|
|
24
|
+
export const COMPOSIO_PER_RUN = "per_run";
|
|
25
|
+
/** A Composio connected account's id, as a run's binding names one: Composio's are `ca_` and a short random id. At least
|
|
26
|
+
* 8 characters in all, so the run's redactors (which hold a value of 8 or more) hold every one. */
|
|
27
|
+
export const COMPOSIO_ACCOUNT_ID = /^ca_[A-Za-z0-9_-]{5,64}$/;
|
|
28
|
+
/** Where Composio's MCP address names the user and the connected account its calls run as. */
|
|
29
|
+
const ADDRESS_USER = "user_id";
|
|
30
|
+
const ADDRESS_ACCOUNT = "connected_account_id";
|
|
31
|
+
/** A Composio auth config's id, as its dashboard and API show it (`ac_` and a nanoid). */
|
|
32
|
+
export const COMPOSIO_AUTH_CONFIG_ID = /^ac_[A-Za-z0-9_-]{1,64}$/;
|
|
17
33
|
const PAGE = 200;
|
|
18
34
|
const MAX_PAGES = 10;
|
|
19
35
|
const MAX_TOOLS = 500;
|
|
36
|
+
/** The longest action slug a save takes: Composio's are far shorter. */
|
|
37
|
+
const MAX_SLUG = 128;
|
|
20
38
|
const WAIT_MS = 20_000;
|
|
21
39
|
const text = (value) => (typeof value === "string" ? value : "");
|
|
22
40
|
const issue = (field, reason, message) => ({ field, reason, message });
|
|
23
41
|
/** A Composio call as `key`: its JSON answer, or an error in words that name `step` and never the key nor a `sealed`
|
|
24
42
|
* value (a trigger's sealed config), and end with `outcome`, what the failure left (a save's: nothing was saved). A call
|
|
25
|
-
* with sealed values in play passes on none of Composio's words.
|
|
43
|
+
* with sealed values in play passes on none of Composio's words. Composio's 404 is `missing` when given: the words of a
|
|
44
|
+
* toolkit it has not, or the refusal on another field. */
|
|
26
45
|
export function asking(control, key, signal, outcome = "nothing was saved", sealed = []) {
|
|
27
46
|
const base = (control.baseUrl ?? BASE).replace(/\/+$/, "");
|
|
28
47
|
const send = control.fetch ?? fetch;
|
|
@@ -64,7 +83,7 @@ export function asking(control, key, signal, outcome = "nothing was saved", seal
|
|
|
64
83
|
if (res.status === 401 || res.status === 403)
|
|
65
84
|
throw invalid([issue("api_key", "refused", `Composio refused the API key while ${step}: check it in Composio's dashboard.`)]);
|
|
66
85
|
if (res.status === 404 && missing)
|
|
67
|
-
throw invalid([issue("toolkit", "not_found", missing)]);
|
|
86
|
+
throw invalid([typeof missing === "string" ? issue("toolkit", "not_found", missing) : missing]);
|
|
68
87
|
if (res.status >= 400 && res.status < 500 && withheld)
|
|
69
88
|
throw invalid([issue("body", "refused", `Composio refused the request while ${step} (HTTP ${res.status}): ${outcome}. Its answer is withheld because the request carried a sealed value.`)]);
|
|
70
89
|
if (res.status >= 400 && res.status < 500)
|
|
@@ -121,70 +140,75 @@ export async function composioTools(body, control, signal) {
|
|
|
121
140
|
const { tools } = await toolkitTools(ask, toolkit);
|
|
122
141
|
return { toolkit, no_auth: needsNoAuth(kit), tools };
|
|
123
142
|
}
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
127
|
-
for (let i = 1; i <= a.length; i++) {
|
|
128
|
-
const row = [i];
|
|
129
|
-
for (let j = 1; j <= b.length; j++)
|
|
130
|
-
row[j] = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
131
|
-
prev = row;
|
|
132
|
-
}
|
|
133
|
-
return prev[b.length];
|
|
134
|
-
}
|
|
135
|
-
/** The listed slug a missing one most likely means, when one is obvious: the same slug in another case, the one listed
|
|
136
|
-
* slug that only adds or drops a trailing _WORD, else the one within a typo's reach (an edit distance of at most
|
|
137
|
-
* max(2, length/10)). */
|
|
138
|
-
function likelySlug(slug, listed) {
|
|
143
|
+
/** The listed slug a missing one means when it is that slug in another case (linear_list_issues for LINEAR_LIST_ISSUES). */
|
|
144
|
+
const likelySlug = (slug, slugs) => {
|
|
139
145
|
const want = slug.toUpperCase();
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
let tie = false;
|
|
149
|
-
for (const s of listed) {
|
|
150
|
-
// An edit distance is at least the length difference: a slug that far off is skipped before the O(n·m) distance, so a
|
|
151
|
-
// huge pasted value against a big toolkit costs one length compare per action.
|
|
152
|
-
if (Math.abs(s.length - want.length) > reach)
|
|
153
|
-
continue;
|
|
154
|
-
const d = distance(want, s.toUpperCase());
|
|
155
|
-
if (d > reach)
|
|
156
|
-
continue;
|
|
157
|
-
if (!best || d < best.d)
|
|
158
|
-
[best, tie] = [{ slug: s, d }, false];
|
|
159
|
-
else if (d === best.d)
|
|
160
|
-
tie = true;
|
|
161
|
-
}
|
|
162
|
-
return best && !tie ? best.slug : undefined;
|
|
146
|
+
return slugs.find((s) => s.toUpperCase() === want);
|
|
147
|
+
};
|
|
148
|
+
/** The toolkit's Composio-managed auth config not disabled, the one a save that names none stands on: none, if Composio
|
|
149
|
+
* has none for it yet. */
|
|
150
|
+
export async function managedConfig(ask, toolkit) {
|
|
151
|
+
const configs = await ask("finding the toolkit's auth config", "GET", `/api/v3/auth_configs?toolkit_slug=${encodeURIComponent(toolkit)}`);
|
|
152
|
+
const managed = (Array.isArray(configs.items) ? configs.items : []).find((c) => isObject(c) && c.is_composio_managed === true && c.status !== "DISABLED" && text(c.id));
|
|
153
|
+
return isObject(managed) ? text(managed.id) : undefined;
|
|
163
154
|
}
|
|
164
155
|
/** The address Composio's generate answers, made one this server's client can use: the helper actions that connect an
|
|
165
|
-
* account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose).
|
|
166
|
-
|
|
156
|
+
* account left off, and the path ended in /mcp (Composio redirects the bare one, which the client refuses on purpose).
|
|
157
|
+
* `perRun`: with no user and no connected account in it either, for each run to name its own (composioRunAddress). */
|
|
158
|
+
export function composioAddress(generated, perRun = false) {
|
|
167
159
|
const url = new URL(generated);
|
|
168
160
|
url.searchParams.delete("include_composio_helper_actions");
|
|
161
|
+
if (perRun)
|
|
162
|
+
for (const name of [ADDRESS_USER, ADDRESS_ACCOUNT])
|
|
163
|
+
url.searchParams.delete(name);
|
|
169
164
|
const path = url.pathname.replace(/\/+$/, "");
|
|
170
165
|
url.pathname = path.endsWith("/mcp") ? path : `${path}/mcp`;
|
|
171
166
|
return url.href;
|
|
172
167
|
}
|
|
168
|
+
/** The Composio user a per-run server's tools are listed as (its save, refresh, preview and an agent's save): Composio's
|
|
169
|
+
* MCP endpoint refuses an address that names no user, its listing too, and any user lists the server's tools. Outside
|
|
170
|
+
* COMPOSIO_USER_ID (the ~), so no save and no run's binding can name it: never stored, never used for a call. */
|
|
171
|
+
export const COMPOSIO_LISTING_USER = "agentrun~tool-listing";
|
|
172
|
+
/** The address a per-run Composio server's tools are listed at: its saved one (no user, no account) as
|
|
173
|
+
* COMPOSIO_LISTING_USER. */
|
|
174
|
+
export function composioListingAddress(saved) {
|
|
175
|
+
const url = new URL(saved.href);
|
|
176
|
+
url.searchParams.set(ADDRESS_USER, COMPOSIO_LISTING_USER);
|
|
177
|
+
return url;
|
|
178
|
+
}
|
|
179
|
+
/** What a run's requests to a per-run Composio server add to its saved address: the Composio user and, when the run's
|
|
180
|
+
* binding names one, the connected account its calls run as (Composio's MCP endpoint reads both from the query). */
|
|
181
|
+
export const composioRunQuery = (binding) => ({ [ADDRESS_USER]: binding.user_id, ...(binding.connected_account_id ? { [ADDRESS_ACCOUNT]: binding.connected_account_id } : {}) });
|
|
173
182
|
/** PUT /settings/mcp-servers/{name}/composio: Composio makes the managed MCP server, `save` keeps it as a saved MCP server
|
|
174
|
-
* (`{url, auth}`: the key a sealed header
|
|
175
|
-
*
|
|
176
|
-
*
|
|
183
|
+
* (`{url, auth}`: the key a sealed header; `prices`, each granted action at `price_usd` when the body names one), and a
|
|
184
|
+
* toolkit that needs the person's account says where to connect it. The auth config is the body's `auth_config_id` (one
|
|
185
|
+
* the owner has, a custom OAuth app's say: read first, and refused unless it is this toolkit's and enabled), else the
|
|
186
|
+
* toolkit's Composio-managed one, found or made. `save` gets what the server stands on there too (`stands`,
|
|
187
|
+
* composio-made.ts): the auth config found or made and the account found or started, each marked whether this save made
|
|
188
|
+
* it, for its delete to remove what was made. */
|
|
177
189
|
export async function composioSave(body, control, save, name, signal, savedUrl) {
|
|
178
190
|
const { key, toolkit, rest } = head(body);
|
|
179
191
|
const tools = Array.isArray(rest.tools) ? rest.tools : [];
|
|
180
192
|
const user = rest.user_id === undefined ? COMPOSIO_USER : typeof rest.user_id === "string" ? rest.user_id : "";
|
|
193
|
+
const price = rest.price_usd;
|
|
194
|
+
const ownConfig = rest.auth_config_id === undefined ? undefined : typeof rest.auth_config_id === "string" ? rest.auth_config_id : "";
|
|
181
195
|
const issues = [];
|
|
182
|
-
if (!tools.length || tools.length > MAX_TOOLS || !tools.every((t) => typeof t === "string" && t))
|
|
183
|
-
issues.push(issue("tools", "invalid", `Send the slugs of the actions to grant: 1 to ${MAX_TOOLS} of them.`));
|
|
196
|
+
if (!tools.length || tools.length > MAX_TOOLS || !tools.every((t) => typeof t === "string" && t && t.length <= MAX_SLUG))
|
|
197
|
+
issues.push(issue("tools", "invalid", `Send the slugs of the actions to grant: 1 to ${MAX_TOOLS} of them, each at most ${MAX_SLUG} characters.`));
|
|
184
198
|
if (!USER_ID.test(user))
|
|
185
|
-
issues.push(issue("user_id", "invalid",
|
|
199
|
+
issues.push(issue("user_id", "invalid", `A user_id is letters, digits and . _ @ - (at most 128), or "${COMPOSIO_PER_RUN}" for a server each run names its own account for.`));
|
|
200
|
+
if (price !== undefined && !priceValid(price))
|
|
201
|
+
issues.push(issue("price_usd", "invalid", "price_usd is what each call of the server's actions costs, in USD: a finite number, 0 or more."));
|
|
202
|
+
if (ownConfig !== undefined && !COMPOSIO_AUTH_CONFIG_ID.test(ownConfig))
|
|
203
|
+
issues.push(issue("auth_config_id", "invalid", "An auth_config_id is the id Composio shows for an auth config: ac_ then letters, digits, _ and - (at most 64 after ac_)."));
|
|
186
204
|
if (issues.length)
|
|
187
205
|
throw invalid(issues);
|
|
206
|
+
// A per-run server: no user, no account, no connect link here; each run names its own (mcp_auth).
|
|
207
|
+
const perRun = user === COMPOSIO_PER_RUN;
|
|
208
|
+
// Every granted action at the one price, saved as the server's prices: each call is held and booked as any priced MCP
|
|
209
|
+
// call (mcp-gateway.ts). None named: the server's prices as they stand, for the actions it still lists (a server saved
|
|
210
|
+
// with none: "not metered").
|
|
211
|
+
const prices = priceValid(price) ? Object.fromEntries([...new Set(tools)].map((slug) => [slug, price])) : undefined;
|
|
188
212
|
const ask = asking(control, key, signal);
|
|
189
213
|
// What this save made at Composio. A failure removes it all again (the MCP server, the account its connect link started,
|
|
190
214
|
// then the auth config), so a failed save leaves nothing it made in the person's account, and never removes what it
|
|
@@ -199,24 +223,33 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
199
223
|
// allowing a slug it doesn't have, which then serves nothing under that name. A list longer than MAX_PAGES refuses
|
|
200
224
|
// nothing on what it didn't read; the check after the save (not_served) still names an action left out.
|
|
201
225
|
const offered = await toolkitTools(ask, toolkit);
|
|
202
|
-
const
|
|
203
|
-
const unknown = offered.complete ? [...new Set(tools)].filter((slug) => !
|
|
226
|
+
const slugs = offered.tools.map((tool) => tool.slug);
|
|
227
|
+
const unknown = offered.complete ? [...new Set(tools)].filter((slug) => !slugs.includes(slug)) : [];
|
|
204
228
|
if (unknown.length) {
|
|
205
|
-
// A slug past 128 characters is named by its first 64 and its length, so the refusal never carries a pasted megabyte back.
|
|
206
229
|
const names = unknown.map((slug) => {
|
|
207
|
-
const likely = likelySlug(slug,
|
|
208
|
-
|
|
209
|
-
return likely ? `${shown} (did you mean ${likely}?)` : shown;
|
|
230
|
+
const likely = likelySlug(slug, slugs);
|
|
231
|
+
return likely ? `${slug} (did you mean ${likely}?)` : slug;
|
|
210
232
|
});
|
|
211
|
-
throw invalid([issue("tools", "not_found", `Composio's ${toolkit} toolkit has no action ${
|
|
233
|
+
throw invalid([issue("tools", "not_found", `Composio's ${toolkit} toolkit has no action ${listed(names, "or")}: pick from its list (POST /settings/mcp-servers/composio/tools). Nothing was saved.`)]);
|
|
212
234
|
}
|
|
213
235
|
const noAuth = needsNoAuth(kit);
|
|
236
|
+
if (noAuth && ownConfig)
|
|
237
|
+
throw invalid([issue("auth_config_id", "not_allowed", `Composio's ${toolkit} toolkit needs no account, so no auth config: send no auth_config_id. Nothing was saved.`)]);
|
|
214
238
|
let authConfig;
|
|
215
239
|
let madeConfig = false;
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
240
|
+
if (ownConfig) {
|
|
241
|
+
// The owner's own auth config (a custom OAuth app's): the server and its connect link are made against it, as it is.
|
|
242
|
+
// Read first, so one Composio doesn't know, of another toolkit, or disabled is refused before anything is made.
|
|
243
|
+
const config = await ask("reading the auth config", "GET", `/api/v3/auth_configs/${encodeURIComponent(ownConfig)}`, undefined, issue("auth_config_id", "not_found", `Composio has no auth config ${ownConfig} in this key's project: use the id its dashboard shows for one of the ${toolkit} toolkit's. Nothing was saved.`));
|
|
244
|
+
const of = isObject(config.toolkit) ? text(config.toolkit.slug).toLowerCase() : "";
|
|
245
|
+
if (of !== toolkit)
|
|
246
|
+
throw invalid([issue("auth_config_id", "wrong_toolkit", `The auth config ${ownConfig} is ${of ? `the ${of} toolkit's` : "no toolkit's Composio names"}, not ${toolkit}'s: use one of ${toolkit}'s. Nothing was saved.`)]);
|
|
247
|
+
if (config.status === "DISABLED")
|
|
248
|
+
throw invalid([issue("auth_config_id", "disabled", `The auth config ${ownConfig} is disabled in Composio: enable it there, or use another. Nothing was saved.`)]);
|
|
249
|
+
authConfig = ownConfig;
|
|
250
|
+
}
|
|
251
|
+
else if (!noAuth) {
|
|
252
|
+
authConfig = await managedConfig(ask, toolkit);
|
|
220
253
|
if (!authConfig) {
|
|
221
254
|
const made = await ask("making the toolkit's auth config", "POST", "/api/v3/auth_configs", { toolkit: { slug: toolkit }, auth_config: { type: "use_composio_managed_auth" } });
|
|
222
255
|
authConfig = isObject(made.auth_config) ? text(made.auth_config.id) : "";
|
|
@@ -233,13 +266,15 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
233
266
|
if (!id)
|
|
234
267
|
throw new ApiError("upstream_failed", "Composio made no MCP server: nothing was saved.");
|
|
235
268
|
madeHere.push({ kind: "mcp", id });
|
|
236
|
-
|
|
269
|
+
// A per-run server's address is generated as the default user's (the one answer shape known, user_ids_url), then
|
|
270
|
+
// saved with no user and no account in it (composioAddress): generating an address makes nothing at Composio.
|
|
271
|
+
const generated = await ask("making the MCP server's address", "POST", "/api/v3.1/mcp/servers/generate", { mcp_server_id: id, user_ids: [perRun ? COMPOSIO_USER : user], managed_auth_by_composio: true });
|
|
237
272
|
const address = Array.isArray(generated.user_ids_url) ? text(generated.user_ids_url[0]) : "";
|
|
238
273
|
if (!address)
|
|
239
274
|
throw new ApiError("upstream_failed", "Composio gave no address for the MCP server: nothing was saved.");
|
|
240
275
|
let connect;
|
|
241
276
|
const accounts = [];
|
|
242
|
-
if (authConfig) {
|
|
277
|
+
if (authConfig && !perRun) {
|
|
243
278
|
// Only an account under this server's auth config serves it: one ACTIVE under another config (a custom one) doesn't.
|
|
244
279
|
const listed = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${encodeURIComponent(user)}&toolkit_slugs=${encodeURIComponent(toolkit)}&auth_config_ids=${encodeURIComponent(authConfig)}`);
|
|
245
280
|
const active = (Array.isArray(listed.items) ? listed.items : []).find((a) => isObject(a) && a.status === "ACTIVE" && isObject(a.auth_config) && a.auth_config.id === authConfig);
|
|
@@ -257,22 +292,23 @@ export async function composioSave(body, control, save, name, signal, savedUrl)
|
|
|
257
292
|
}
|
|
258
293
|
}
|
|
259
294
|
}
|
|
260
|
-
|
|
261
|
-
|
|
295
|
+
// One the owner named is theirs (`named`): never recorded as made here, whoever made it (composio-made.ts).
|
|
296
|
+
const stands = { user, auth_config: authConfig ? { id: authConfig, made: madeConfig, ...(ownConfig ? { named: true } : {}) } : null, accounts, ...(perRun ? { per_run: true } : {}) };
|
|
297
|
+
url = composioAddress(address, perRun);
|
|
262
298
|
// Saved as what it is, a Composio server of this toolkit: a template that needs the toolkit maps to it, whatever its
|
|
263
299
|
// name. A slug no template can name (mcp:<toolkit>/<tool>: no `_`) is saved as a Composio server of no toolkit.
|
|
264
300
|
// Composio leaves out an action it does not serve, and a server that serves none of the picked ones lists no tools at
|
|
265
301
|
// all: its MCP answers the listing "Method not found" (JSON-RPC -32601). Only that answer says "none served", in words
|
|
266
302
|
// naming the picked actions; any other failure (no DNS, a timeout, an HTTP 500) stays the 424 it is.
|
|
267
|
-
const server = await save({ url, auth: { type: "headers", headers: { "x-api-key": key } } }, { source: "composio", toolkit: MCP_SERVER_NAME.test(toolkit) ? toolkit : null }, stands).catch((error) => {
|
|
303
|
+
const server = await save({ url, auth: { type: "headers", headers: { "x-api-key": key } }, ...(prices ? { prices } : {}) }, { source: "composio", toolkit: MCP_SERVER_NAME.test(toolkit) ? toolkit : null }, stands).catch((error) => {
|
|
268
304
|
if (!(error instanceof ApiError) || error.code !== "upstream_failed" || error.extra.details?.rpc_code !== METHOD_NOT_FOUND)
|
|
269
305
|
throw error;
|
|
270
306
|
throw invalid([issue("tools", "not_served", `Composio's ${toolkit} server doesn't serve ${tools.join(", ")}: pick another action.`)]);
|
|
271
307
|
});
|
|
272
308
|
// Composio's server can leave out an action it was allowed (HACKERNEWS_GET_FRONTPAGE, live 11-13): say which, so a grant
|
|
273
309
|
// doesn't vanish without a word. A toolkit with no account yet still lists its actions, so this holds before the connect.
|
|
274
|
-
const
|
|
275
|
-
const missing = tools.filter((slug) => !
|
|
310
|
+
const served = new Set((server.tools ?? []).map((tool) => tool.name));
|
|
311
|
+
const missing = tools.filter((slug) => !served.has(slug));
|
|
276
312
|
return { server, ...(connect ? { connect_url: connect } : {}), ...(missing.length ? { not_served: missing } : {}) };
|
|
277
313
|
}
|
|
278
314
|
catch (error) {
|
|
@@ -323,8 +359,8 @@ export const composioServerId = (address) => {
|
|
|
323
359
|
};
|
|
324
360
|
/** A thing at Composio as the words name it; `removed`: as a removal names it (an account its connect link with it). */
|
|
325
361
|
const named = (thing, removed = false) => thing.kind === "mcp" ? `the MCP server ${thing.id}` : thing.kind === "auth_config" ? `the auth config ${thing.id}` : `the connected account ${thing.id}${removed ? " (its connect link with it)" : ""}`;
|
|
326
|
-
/** "a", "a and b", "a, b and c". */
|
|
327
|
-
const listed = (items) => (items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")}
|
|
362
|
+
/** "a", "a and b", "a, b and c" (or "a, b or c"). */
|
|
363
|
+
const listed = (items, word = "and") => (items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} ${word} ${items.at(-1)}`);
|
|
328
364
|
/** What a delete's answer says it did at Composio, in words: what it removed, what it kept and why (another saved server
|
|
329
365
|
* uses it, or this server didn't make it), and what is left, with where to remove that by hand. `removed`: nothing is
|
|
330
366
|
* left there. */
|
|
@@ -2,11 +2,14 @@ import { type ComposioControl } from "./composio-preset.js";
|
|
|
2
2
|
import type { Source } from "./trigger-adapter.js";
|
|
3
3
|
import type { TriggerUpstream } from "./triggers.js";
|
|
4
4
|
import { type Json } from "./validate.js";
|
|
5
|
-
/** A saved Composio server's key, the Composio user its address names, and its
|
|
5
|
+
/** A saved Composio server's key, the Composio user its address names, its toolkit, and the auth config its save stands
|
|
6
|
+
* on (the managed one found or made, or the one auth_config_id named; none for a server saved before that was recorded,
|
|
7
|
+
* whose link is then under managedConfig's, or of a toolkit with no sign-in). */
|
|
6
8
|
export type ComposioCredential = {
|
|
7
9
|
key: string;
|
|
8
10
|
user: string;
|
|
9
11
|
toolkit: string;
|
|
12
|
+
auth_config?: string;
|
|
10
13
|
};
|
|
11
14
|
/** A trigger of kind composio, as the engine keeps it. */
|
|
12
15
|
type Holder = {
|
|
@@ -27,7 +30,7 @@ export type ComposioTriggerDeps = {
|
|
|
27
30
|
publicUrl?: string;
|
|
28
31
|
/** The composio source's sealed settings: each hook's subscription secret. */
|
|
29
32
|
sealed: Sealed;
|
|
30
|
-
/** Saved server `name`'s key, user and
|
|
33
|
+
/** Saved server `name`'s key, user, toolkit and auth config; refused (thrown) when it is no Composio server: by the source's field at
|
|
31
34
|
* a trigger's create (`field`), as a 404 on its own routes (`route`). */
|
|
32
35
|
credential(name: string, refusal: "field" | "route"): Promise<ComposioCredential>;
|
|
33
36
|
/** Every trigger of kind composio, on or off. */
|
|
@@ -143,8 +146,10 @@ export declare class ComposioTriggers implements TriggerUpstream {
|
|
|
143
146
|
/** The project's subscription for a trigger: made here if there is none (undone with `undo`), reused if it is this
|
|
144
147
|
* server's, moved here only when `move`. Answers its hook. */
|
|
145
148
|
private subscribe;
|
|
146
|
-
/** The id of the one ACTIVE account the server's user has for its toolkit
|
|
147
|
-
*
|
|
149
|
+
/** The id of the one ACTIVE account the server's user has for its toolkit, under the auth config the server's save stands
|
|
150
|
+
* on (as its MCP server serves only those; every config, for a server saved before that was recorded); none: refused,
|
|
151
|
+
* with the link to connect it under that config; several: refused, naming each with when it was connected, so the
|
|
152
|
+
* owner disconnects the ones it shouldn't run as. */
|
|
148
153
|
private accountOf;
|
|
149
154
|
}
|
|
150
155
|
export {};
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
// asked anything.
|
|
26
26
|
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
27
27
|
import { ApiError, invalid } from "./errors.js";
|
|
28
|
-
import { asking } from "./composio-preset.js";
|
|
28
|
+
import { asking, managedConfig } from "./composio-preset.js";
|
|
29
29
|
import { COMPOSIO_HOOK, COMPOSIO_SECRET, CONFIG_SECRET, CONFIG_UNLISTED, configScope, configSecrets, MOVE_FIELD, SEALED_FIELD, SEALED_MASK, sealableValue, sealedConfigFields, sealedKept, sealedSchemaFields, shownSource } from "./trigger-composio.js";
|
|
30
30
|
import { isObject } from "./validate.js";
|
|
31
31
|
/** Where the owner does by hand what this server could not do on Composio. */
|
|
@@ -138,11 +138,14 @@ export class ComposioTriggers {
|
|
|
138
138
|
undo.push(async () => this.leave(ask, instance, await this.leftWith(instance, id)));
|
|
139
139
|
if (!enabled && (await this.leftWith(instance, id)) !== "keep")
|
|
140
140
|
await ask("turning the trigger instance off", "PATCH", `/api/v3/trigger_instances/manage/${enc(instance)}`, { status: "disable" });
|
|
141
|
-
// The saved server is still there, under the key this was made with: one deleted (or saved
|
|
142
|
-
//
|
|
141
|
+
// The saved server is still there, under the key and on the auth config this was made with: one deleted (or saved
|
|
142
|
+
// again with another key, or onto another config, whose accounts the instance's isn't) meanwhile is refused here,
|
|
143
|
+
// and what was made is undone, so no trigger names a server that is gone or an account it doesn't serve.
|
|
143
144
|
const now = await this.deps.credential(server, "field");
|
|
144
145
|
if (now.key !== credential.key)
|
|
145
146
|
throw invalid([{ field: "source.server", reason: "invalid", message: `${server} was saved again with another Composio key while this trigger was being made: nothing was saved, make it again.` }]);
|
|
147
|
+
if (now.auth_config !== credential.auth_config)
|
|
148
|
+
throw invalid([{ field: "source.server", reason: "invalid", message: `${server} was saved again on another auth config while this trigger was being made: nothing was saved, make it again.` }]);
|
|
146
149
|
// Each credential of its config sealed, the trigger keeping the mask in its place: Composio's upsert above was the
|
|
147
150
|
// one place it went.
|
|
148
151
|
undo.push(async () => {
|
|
@@ -626,22 +629,26 @@ export class ComposioTriggers {
|
|
|
626
629
|
this.deps.say({ condition: "composio_subscription_moved", from: sub.webhook_url, hook });
|
|
627
630
|
return hook;
|
|
628
631
|
}
|
|
629
|
-
/** The id of the one ACTIVE account the server's user has for its toolkit
|
|
630
|
-
*
|
|
632
|
+
/** The id of the one ACTIVE account the server's user has for its toolkit, under the auth config the server's save stands
|
|
633
|
+
* on (as its MCP server serves only those; every config, for a server saved before that was recorded); none: refused,
|
|
634
|
+
* with the link to connect it under that config; several: refused, naming each with when it was connected, so the
|
|
635
|
+
* owner disconnects the ones it shouldn't run as. */
|
|
631
636
|
async accountOf(ask, credential, server) {
|
|
632
|
-
const
|
|
633
|
-
const
|
|
637
|
+
const config = credential.auth_config;
|
|
638
|
+
const accounts = await ask("checking the connected account", "GET", `/api/v3/connected_accounts?user_ids=${enc(credential.user)}&toolkit_slugs=${enc(credential.toolkit)}${config ? `&auth_config_ids=${enc(config)}` : ""}&statuses=ACTIVE`);
|
|
639
|
+
const active = (Array.isArray(accounts.items) ? accounts.items : []).filter((a) => isObject(a) && a.status === "ACTIVE" && !!text(a.id) && (!config || (isObject(a.auth_config) && a.auth_config.id === config)));
|
|
634
640
|
if (active.length === 1)
|
|
635
641
|
return text(active[0].id);
|
|
642
|
+
const under = config ? ` under auth config ${config}` : "";
|
|
636
643
|
// Several: never one picked, which would run the trigger as an account the owner didn't choose, unseen.
|
|
637
644
|
if (active.length > 1) {
|
|
638
645
|
const listed = active.map((a) => ({ id: text(a.id), created_at: text(a.created_at) })).sort((a, b) => a.created_at.localeCompare(b.created_at) || a.id.localeCompare(b.id));
|
|
639
|
-
throw new ApiError("composio_account_ambiguous", `${server}'s Composio user ${credential.user} has ${listed.length} connected ${credential.toolkit} accounts: ${listed.map((a) => `${a.id} (connected ${a.created_at || "at an unknown time"})`).join(", ")}. A trigger runs as one account: disconnect the ones it shouldn't run as in Composio, then make the trigger again.`, { details: { server, user_id: credential.user, accounts: listed } });
|
|
646
|
+
throw new ApiError("composio_account_ambiguous", `${server}'s Composio user ${credential.user} has ${listed.length} connected ${credential.toolkit} accounts${under}: ${listed.map((a) => `${a.id} (connected ${a.created_at || "at an unknown time"})`).join(", ")}. A trigger runs as one account: disconnect the ones it shouldn't run as in Composio, then make the trigger again.`, { details: { server, user_id: credential.user, accounts: listed } });
|
|
640
647
|
}
|
|
641
|
-
// The link is under the
|
|
642
|
-
|
|
643
|
-
const
|
|
644
|
-
const link =
|
|
645
|
-
throw new ApiError("composio_not_connected", `${server}'s Composio user ${credential.user} has no connected ${credential.toolkit} account: connect it${link ? ` at ${link}` : " in Composio"}, then make the trigger again.`, { details: { server, user_id: credential.user, ...(link ? { connect_url: link } : {}) } });
|
|
648
|
+
// The link is under the server's auth config; for a server saved before that was recorded, under the one its save
|
|
649
|
+
// found or made (managedConfig, the preset's own finder).
|
|
650
|
+
const linkConfig = config || (await managedConfig(ask, credential.toolkit));
|
|
651
|
+
const link = linkConfig ? text((await ask("making the connect link", "POST", "/api/v3/connected_accounts/link", { auth_config_id: linkConfig, user_id: credential.user })).redirect_url) : "";
|
|
652
|
+
throw new ApiError("composio_not_connected", `${server}'s Composio user ${credential.user} has no connected ${credential.toolkit} account${under}: connect it${link ? ` at ${link}` : " in Composio"}, then make the trigger again.`, { details: { server, user_id: credential.user, ...(link ? { connect_url: link } : {}) } });
|
|
646
653
|
}
|
|
647
654
|
}
|