@parcha/agentrun-serve 0.1.0-beta.43 → 0.1.0-beta.44
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 +105 -0
- package/README.md +213 -24
- package/dist/cli.js +42 -8
- package/dist/composio-preset.d.ts +4 -3
- package/dist/composio-preset.js +12 -4
- package/dist/composio-triggers.d.ts +20 -2
- package/dist/composio-triggers.js +183 -17
- package/dist/computer-lost.d.ts +11 -0
- package/dist/computer-lost.js +19 -0
- package/dist/computer-record.d.ts +10 -2
- package/dist/computer-record.js +50 -18
- package/dist/computer-setting.d.ts +1 -0
- package/dist/computer-setting.js +2 -2
- package/dist/console/assets/index-BUktRvS-.css +1 -0
- package/dist/console/assets/index-nB9kTfIN.js +711 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +3 -0
- package/dist/harness-table.d.ts +51 -3
- package/dist/harness-table.js +101 -13
- package/dist/harness.d.ts +18 -1
- package/dist/harness.js +21 -9
- package/dist/host.d.ts +12 -10
- package/dist/host.js +18 -16
- package/dist/import-worker.d.ts +3 -0
- package/dist/import-worker.js +7 -5
- package/dist/import.d.ts +22 -1
- package/dist/import.js +141 -28
- package/dist/learn/check.d.ts +3 -0
- package/dist/learn/check.js +1 -1
- package/dist/learn/compile.js +1 -1
- package/dist/learn/delete.d.ts +17 -0
- package/dist/learn/delete.js +44 -0
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +8 -4
- package/dist/learn/skills.d.ts +4 -0
- package/dist/learn/skills.js +17 -1
- package/dist/learn/workflow-nodes.d.ts +22 -1
- package/dist/learn/workflow-nodes.js +28 -9
- package/dist/learning-cost.d.ts +100 -0
- package/dist/learning-cost.js +116 -1
- package/dist/learning-evals.d.ts +2 -0
- package/dist/learning-evals.js +4 -3
- package/dist/learning-routes.d.ts +8 -0
- package/dist/learning-routes.js +17 -0
- package/dist/learning.d.ts +1 -1
- package/dist/listen-first.d.ts +30 -0
- package/dist/listen-first.js +115 -0
- package/dist/llms.txt +2 -1
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/model.d.ts +8 -4
- package/dist/model.js +16 -8
- package/dist/openapi.js +115 -39
- package/dist/owner.d.ts +8 -0
- package/dist/owner.js +11 -0
- package/dist/paid-calls.d.ts +6 -0
- package/dist/paid-calls.js +11 -1
- package/dist/place.d.ts +8 -3
- package/dist/place.js +13 -9
- package/dist/provider.js +15 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-model-key.d.ts +64 -0
- package/dist/run-model-key.js +147 -0
- package/dist/runner/adapter-loop.d.ts +6 -0
- package/dist/runner/adapter-loop.js +9 -2
- package/dist/runner/adapter-run-spec.d.ts +6 -3
- package/dist/runner/adapter-run-spec.js +70 -23
- package/dist/runner/adapters/index.d.ts +4 -2
- package/dist/runner/adapters/index.js +13 -4
- package/dist/runner/audit.d.ts +4 -0
- package/dist/runner/audit.js +15 -4
- package/dist/runner/beside.d.ts +2 -1
- package/dist/runner/beside.js +5 -2
- package/dist/runner/claim-secrets.d.ts +49 -0
- package/dist/runner/claim-secrets.js +110 -1
- package/dist/runner/cli-run-spec.d.ts +2 -1
- package/dist/runner/cli-run-spec.js +32 -13
- package/dist/runner/commands.d.ts +3 -6
- package/dist/runner/feedback-round.d.ts +3 -2
- package/dist/runner/feedback-round.js +7 -3
- package/dist/runner/harness-loops.js +30 -8
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/learning-end.d.ts +3 -0
- package/dist/runner/learning-end.js +4 -0
- package/dist/runner/loop-contract.d.ts +6 -0
- package/dist/runner/loop-contract.js +4 -0
- package/dist/runner/loop.js +6 -2
- package/dist/runner/main.d.ts +1 -0
- package/dist/runner/main.js +24 -7
- package/dist/runner/memory-claim.d.ts +9 -6
- package/dist/runner/memory-claim.js +12 -9
- package/dist/runner/promotion.d.ts +5 -0
- package/dist/runner/promotion.js +46 -7
- package/dist/runner/reflect-hook.d.ts +4 -0
- package/dist/runner/reflect-hook.js +22 -3
- package/dist/runner/runner.js +57 -4
- package/dist/runner/store-secrets.js +9 -5
- package/dist/runner/workflow-spec.js +10 -2
- package/dist/runs-over-store.d.ts +5 -4
- package/dist/runs-over-store.js +13 -3
- package/dist/sdk/workflows.d.ts +1 -1
- package/dist/server.d.ts +64 -50
- package/dist/server.js +457 -120
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/seal.d.ts +20 -2
- package/dist/store/seal.js +24 -8
- package/dist/store/sqlite/run-launch.d.ts +4 -1
- package/dist/store/sqlite/run-launch.js +12 -0
- package/dist/store/sqlite/store.d.ts +3 -2
- package/dist/store/sqlite/store.js +118 -16
- package/dist/store/store.d.ts +38 -3
- package/dist/store-reads/analytics.js +11 -1
- package/dist/store-reads/learning.d.ts +41 -2
- package/dist/store-reads/learning.js +158 -5
- package/dist/store-reads/stats.js +13 -3
- package/dist/store-view.d.ts +5 -1
- package/dist/store-view.js +12 -11
- package/dist/telemetry.d.ts +59 -0
- package/dist/telemetry.js +153 -0
- package/dist/tool-keys-store.d.ts +1 -1
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-plane.d.ts +12 -12
- package/dist/tools.d.ts +11 -11
- package/dist/tools.js +18 -5
- package/dist/trigger-adapter.d.ts +3 -0
- package/dist/trigger-adapters.d.ts +4 -0
- package/dist/trigger-adapters.js +13 -0
- package/dist/trigger-composio.d.ts +58 -1
- package/dist/trigger-composio.js +160 -6
- package/dist/triggers.d.ts +4 -0
- package/dist/triggers.js +22 -3
- package/dist/validate.d.ts +11 -7
- package/dist/validate.js +8 -7
- package/dist/workspace/computer-for-claim.d.ts +15 -5
- package/dist/workspace/computer-for-claim.js +228 -32
- package/dist/workspace/resolve-computer.d.ts +8 -2
- package/dist/workspace/resolve-computer.js +1 -1
- package/package.json +10 -9
- package/dist/console/assets/index-BrcDSBD8.css +0 -1
- package/dist/console/assets/index-Bz6IWncl.js +0 -711
package/dist/tools.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ export declare function toolingOf(revision: Revision): Promise<Tooling>;
|
|
|
323
323
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
324
324
|
export declare const missingEnv: (entry: ToolEntry, env: NodeJS.ProcessEnv) => string[];
|
|
325
325
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
326
|
-
* (names only), and the harnesses that run it (
|
|
326
|
+
* (names only), and the harnesses that run it (one on an adapter runs only the host tools, host-tools.ts). A tool
|
|
327
327
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
328
328
|
* sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
|
|
329
329
|
* is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
|
|
@@ -337,14 +337,14 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
337
337
|
providers?: string[] | undefined;
|
|
338
338
|
provider?: string | undefined;
|
|
339
339
|
default_provider?: string | undefined;
|
|
340
|
-
resolves?: Record<"opencode" | "codex" | "
|
|
341
|
-
why?: Record<"opencode" | "codex" | "
|
|
342
|
-
default_permission: "
|
|
343
|
-
permissions: ("
|
|
340
|
+
resolves?: Record<"opencode" | "codex" | "claude-agent" | "pi", Resolution> | undefined;
|
|
341
|
+
why?: Record<"opencode" | "codex" | "claude-agent" | "pi", string> | undefined;
|
|
342
|
+
default_permission: "ask" | "allow" | "deny";
|
|
343
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
344
344
|
fallback_allow_reads?: true | undefined;
|
|
345
345
|
allow_reads?: true | undefined;
|
|
346
|
-
permission: "
|
|
347
|
-
harnesses:
|
|
346
|
+
permission: "ask" | "allow" | "deny";
|
|
347
|
+
harnesses: string[];
|
|
348
348
|
missing?: string[] | undefined;
|
|
349
349
|
reason?: string | undefined;
|
|
350
350
|
available: boolean;
|
|
@@ -356,11 +356,11 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
356
356
|
name: string;
|
|
357
357
|
summary: string;
|
|
358
358
|
} | {
|
|
359
|
-
default_permission: "
|
|
360
|
-
permissions: ("
|
|
359
|
+
default_permission: "ask" | "allow" | "deny";
|
|
360
|
+
permissions: ("ask" | "allow" | "deny")[];
|
|
361
361
|
fallback_allow_reads?: true | undefined;
|
|
362
362
|
allow_reads?: true | undefined;
|
|
363
|
-
permission: "
|
|
363
|
+
permission: "ask" | "allow" | "deny";
|
|
364
364
|
name: string;
|
|
365
365
|
summary: string;
|
|
366
366
|
blurb: string;
|
|
@@ -368,5 +368,5 @@ export declare const toolsView: (env: NodeJS.ProcessEnv, settings?: ToolSettings
|
|
|
368
368
|
calls: boolean;
|
|
369
369
|
meta: true;
|
|
370
370
|
available: boolean;
|
|
371
|
-
harnesses:
|
|
371
|
+
harnesses: string[];
|
|
372
372
|
})[];
|
package/dist/tools.js
CHANGED
|
@@ -19,7 +19,7 @@ import { registerTurnEnding } from "./timeline/index.js";
|
|
|
19
19
|
import { BACKGROUND_LOG_BYTES, BACKGROUND_MAX, BACKGROUND_PAGE_BYTES } from "./background.js";
|
|
20
20
|
import { isWorkspaceError, localWorkspace } from "./workspace/index.js";
|
|
21
21
|
import { fetchOptions, HTML_READ_CHARS, TEXT_CAP } from "./web-fetch-direct.js";
|
|
22
|
-
import {
|
|
22
|
+
import { harnessIds, onAdapter } from "./harness-table.js";
|
|
23
23
|
import { META_TOOLS } from "./meta-tool-names.js";
|
|
24
24
|
import { localFolderOf } from "./workspace/local.js";
|
|
25
25
|
import { LLM_TOOL } from "./llm.js";
|
|
@@ -28,6 +28,7 @@ import { FAUX_ENV, workflowNodes } from "./model.js";
|
|
|
28
28
|
import { bookedIn, booking } from "./paid-calls.js";
|
|
29
29
|
import { hostToolDefs } from "@parcha/agentrun-kernel/kernel";
|
|
30
30
|
import { browserPrice, browserSpend } from "./browser-cost.js";
|
|
31
|
+
import { sessionRecordings } from "./computer-record.js";
|
|
31
32
|
import { forModel } from "./result.js";
|
|
32
33
|
import { fetchFor, pagesOf, WEB_FETCH_TOOL, webFetchTool } from "./web-fetch.js";
|
|
33
34
|
import { searchFor, WEB_SEARCH_TOOL, webSearchTool } from "./web-search.js";
|
|
@@ -267,7 +268,8 @@ export const runSignInSaved = (store, sealKey, claim, kept) => async (row, chang
|
|
|
267
268
|
* (browser-computer.ts), each driven over its CDP URL by pi-browser's raw-CDP driver: the agent's computer, where it is
|
|
268
269
|
* a browser (the claim's, computer-for-claim.ts), else the one the run's plane names (tool-plane.ts: picked, else
|
|
269
270
|
* Browserbase where the server holds its keys, else Kernel), kept for the run's life; a plane that names none (a run kept
|
|
270
|
-
* from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No recording
|
|
271
|
+
* from before the pick) is Browserbase. Its sessions' custody lives in the run's own store. No vendor's recording:
|
|
272
|
+
* where the agent's computer says computer.record, each session's video is the live view's screencast. The owner
|
|
271
273
|
* watches it live, takes it over and hands it back, and the agent may ask them to (browser-live.ts, browser-person.ts).
|
|
272
274
|
* A session the run still holds is released when the run is let go. Where the plane says unavailable (its vendor's key
|
|
273
275
|
* gone since), each call is refused, saying why. Its session time is the run's spend, held under its cap before it runs
|
|
@@ -423,6 +425,9 @@ const browserTool = {
|
|
|
423
425
|
// (host.liveViewers); never a file in the run's folder, which is the agent's workspace.
|
|
424
426
|
const viewers = live.sessionHandovers(host.liveViewers, at?.host);
|
|
425
427
|
const onSession = (row, change) => viewers.changed(row, change);
|
|
428
|
+
// Where the agent's computer records (its claim's `record`, computer.record): each session's video, by its computer,
|
|
429
|
+
// from its launch (or its reopening after a restart) to its release, through the live view's one screencast of it.
|
|
430
|
+
const recordSession = sessionRecordings(view, computer?.record);
|
|
426
431
|
// Its session time is the run's spend, at its provider's price, and held under the run's cap (browser-cost.ts).
|
|
427
432
|
const providerName = parts.provider?.name ?? vendor;
|
|
428
433
|
const price = browserPrice(providerName, host.env);
|
|
@@ -451,6 +456,7 @@ const browserTool = {
|
|
|
451
456
|
// A session let go ends a wait on the person's answer that kept it open (personWait, below): the run parks.
|
|
452
457
|
if (change === "released")
|
|
453
458
|
hands.sessionEnded(row.session.tag);
|
|
459
|
+
await recordSession(row.session.tag, change === "released" ? null : row.session.resourceId);
|
|
454
460
|
// A session that opens, whatever let the last one go: the Screen tab's ended state goes (browser-wait-ended.ts).
|
|
455
461
|
if (change === "launched" && host.store && host.claim)
|
|
456
462
|
await clearWaitEnded(host.store.settings, host.claim.runId, host.claim.epoch).catch(() => undefined);
|
|
@@ -513,6 +519,8 @@ const browserTool = {
|
|
|
513
519
|
try {
|
|
514
520
|
const opened = await watched?.liveView?.({ id: row.resourceId, tag: row.tag });
|
|
515
521
|
await viewers.reopened(row.tag, opened?.fullscreen);
|
|
522
|
+
if (opened)
|
|
523
|
+
await recordSession(row.tag, row.resourceId);
|
|
516
524
|
}
|
|
517
525
|
catch {
|
|
518
526
|
// A browser that cannot be reached has no view to give: the owner reads none, as for any session without one.
|
|
@@ -706,7 +714,7 @@ export async function toolingOf(revision) {
|
|
|
706
714
|
/** The variables `entry` needs that `env` does not set, by name. */
|
|
707
715
|
export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name]);
|
|
708
716
|
/** Every tool as capabilities show it, the server's one tool catalog: available here, or the variables it is missing
|
|
709
|
-
* (names only), and the harnesses that run it (
|
|
717
|
+
* (names only), and the harnesses that run it (one on an adapter runs only the host tools, host-tools.ts). A tool
|
|
710
718
|
* a user picks a provider for (tool-plane.ts) gives the providers offered, the server's (`provider`, the default where it
|
|
711
719
|
* sets none), the default, and what it resolves to on each harness under the server's `settings`: available where any
|
|
712
720
|
* is not unavailable, and missing PARALLEL_API_KEY where Parallel is picked without it. An unavailable tool says why
|
|
@@ -719,6 +727,11 @@ export const missingEnv = (entry, env) => entry.needs.filter((name) => !env[name
|
|
|
719
727
|
export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell = new Set()) => {
|
|
720
728
|
const views = explainsView(env, settings);
|
|
721
729
|
const picked = withDefaults(settings);
|
|
730
|
+
// The harnesses by the table `env` runs on (a module's among them): a host tool runs on each; any other tool on those
|
|
731
|
+
// that run on the general spec with pi's tools (no adapter facts: pi, and a module's harness without them), as the save
|
|
732
|
+
// check takes them (runnable.ts onAdapter).
|
|
733
|
+
const everyHarness = harnessIds(env);
|
|
734
|
+
const generalSpec = everyHarness.filter((id) => !onAdapter(env, id));
|
|
722
735
|
const table = Object.entries(TOOLS).map(([name, entry]) => {
|
|
723
736
|
const view = PICKABLE.includes(name) ? views[name] : undefined;
|
|
724
737
|
const plane = view?.resolves;
|
|
@@ -732,11 +745,11 @@ export const toolsView = (env, settings = {}, noBox, refused = {}, runnerShell =
|
|
|
732
745
|
// Unavailable says why: a sandbox-only tool no box here can run, why none can (`noBox`); on a tool a user picks a
|
|
733
746
|
// provider for, the resolutions' own words (`web_search is turned off in settings`); else the variables it needs.
|
|
734
747
|
const reason = available ? undefined : refusal ?? boxless ?? (plane ? [...new Set(Object.values(plane).filter(isUnavailable).map(whyUnavailable))].join("; ") : `Needs ${keyNeeded(missing)}`);
|
|
735
|
-
return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...
|
|
748
|
+
return { name, summary: entry.summary, ...(blurbOf(name) ? { blurb: blurbOf(name) } : {}), nodes: entry.nodes, calls: entry.effect !== undefined, ...(entry.callOnly ? { call_only: true } : {}), ...(entry.sandboxOnly ? { sandbox_only: true } : {}), available, ...(reason ? { reason } : {}), ...(missing.length ? { missing } : {}), harnesses: isHostTool(name) ? [...everyHarness] : [...generalSpec], ...serverGate(name, settings), ...(plane ? { providers: [...PROVIDERS[name]], provider: picked[name].provider, default_provider: PROVIDERS[name][0], resolves: plane, why: view.why } : {}) };
|
|
736
749
|
});
|
|
737
750
|
// The host tools over a run's own tools (META_TOOLS): not in the table, never granted or named by a node (`meta`), listed
|
|
738
751
|
// so the owner sees them and their setting (allow or deny; a deny is not offered at all).
|
|
739
|
-
const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...
|
|
752
|
+
const meta = [...META_TOOLS].map((name) => ({ name, summary: META_SUMMARY[name], blurb: blurbOf(name), nodes: false, calls: false, meta: true, available: true, harnesses: [...everyHarness], ...serverGate(name, settings) }));
|
|
740
753
|
return [...table, ...meta];
|
|
741
754
|
};
|
|
742
755
|
const META_SUMMARY = Object.freeze({
|
|
@@ -54,6 +54,9 @@ export type TriggerAdapter = {
|
|
|
54
54
|
parse(value: Json, now: number, bad: (field: string, reason: string, message: string) => void, issues: InputIssue[]): Source | undefined;
|
|
55
55
|
/** Whether a source the store keeps is whole, of its type. */
|
|
56
56
|
wellFormed(source: Json): boolean;
|
|
57
|
+
/** A kept source as every answer sends it, when that is not as kept: a field that holds a credential masked (a composio
|
|
58
|
+
* config's key), by the one rule, whether the source sealed it yet or not. Default: as kept. */
|
|
59
|
+
shown?(source: Source): Source;
|
|
57
60
|
/** The zone its times are read in, for its runs' provenance line. Default UTC. */
|
|
58
61
|
zone?(source: Source): string;
|
|
59
62
|
/** A clock source's times. */
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { TriggerAdapter } from "./trigger-adapter.js";
|
|
2
2
|
export declare const TRIGGER_ADAPTERS: readonly TriggerAdapter[];
|
|
3
|
+
/** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
|
|
4
|
+
* (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
|
|
5
|
+
* that one field of that one shape: any other value is as it is. */
|
|
6
|
+
export declare function shownTrigger(body: unknown, adapters?: readonly TriggerAdapter[]): unknown;
|
package/dist/trigger-adapters.js
CHANGED
|
@@ -5,3 +5,16 @@ import { webhook } from "./trigger-webhook.js";
|
|
|
5
5
|
import { email } from "./trigger-email.js";
|
|
6
6
|
import { feed } from "./trigger-feed.js";
|
|
7
7
|
export const TRIGGER_ADAPTERS = [schedule, webhook, github, composio, email, feed];
|
|
8
|
+
/** A trigger's answer (an object whose top-level `source` is a trigger source) with that source as a read sends it now
|
|
9
|
+
* (its adapter's `shown`): for an answer kept before that rule, an Idempotency-Key's record of a trigger create. Only
|
|
10
|
+
* that one field of that one shape: any other value is as it is. */
|
|
11
|
+
export function shownTrigger(body, adapters = TRIGGER_ADAPTERS) {
|
|
12
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
13
|
+
return body;
|
|
14
|
+
const source = body.source;
|
|
15
|
+
if (source === null || typeof source !== "object" || Array.isArray(source))
|
|
16
|
+
return body;
|
|
17
|
+
const kind = source.kind;
|
|
18
|
+
const adapter = typeof kind === "string" ? adapters.find((a) => a.id === kind) : undefined;
|
|
19
|
+
return adapter?.shown ? { ...body, source: adapter.shown(source) } : body;
|
|
20
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type TriggerAdapter } from "./trigger-adapter.js";
|
|
1
|
+
import { type Source, type TriggerAdapter } from "./trigger-adapter.js";
|
|
2
|
+
import { type Json } from "./validate.js";
|
|
2
3
|
/** A Composio trigger slug: upper case, digits and `_` (GITHUB_ISSUE_ADDED_EVENT). */
|
|
3
4
|
export declare const COMPOSIO_EVENT: RegExp;
|
|
4
5
|
/** The id of a project's route here, made once when its subscription is made or moved here. */
|
|
@@ -7,4 +8,60 @@ export declare const COMPOSIO_HOOK: RegExp;
|
|
|
7
8
|
export declare const MOVE_FIELD = "move_subscription";
|
|
8
9
|
/** The settings field the project's subscription secret is sealed under, one scope per hook. */
|
|
9
10
|
export declare const COMPOSIO_SECRET = "secret";
|
|
11
|
+
/** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
|
|
12
|
+
* CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
|
|
13
|
+
* echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
|
|
14
|
+
export declare const CONFIG_SECRET = "config";
|
|
15
|
+
export declare const CONFIG_UNLISTED = "config_unlisted";
|
|
16
|
+
/** What a trigger keeps, and answers, in place of a sealed config value. */
|
|
17
|
+
export declare const SEALED_MASK = "[sealed]";
|
|
18
|
+
/** The source's field that names its sealed config fields, set by this server. */
|
|
19
|
+
export declare const SEALED_FIELD = "sealed_config";
|
|
20
|
+
/** The settings scope of trigger `id`'s sealed config field `field`. */
|
|
21
|
+
export declare const configScope: (id: string, field: string) => string;
|
|
22
|
+
/** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
|
|
23
|
+
* the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
|
|
24
|
+
* apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
|
|
25
|
+
* word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
|
|
26
|
+
* count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
|
|
27
|
+
* budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
|
|
28
|
+
export declare const secretConfigName: (name: string) => boolean;
|
|
29
|
+
/** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
|
|
30
|
+
* credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
|
|
31
|
+
* before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
|
|
32
|
+
* ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
|
|
33
|
+
* name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
|
|
34
|
+
export declare const credentialUrl: (value: string) => boolean;
|
|
35
|
+
/** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
|
|
36
|
+
* sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
|
|
37
|
+
export declare const sealableValue: (value: unknown) => value is string | number;
|
|
38
|
+
/** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
|
|
39
|
+
* is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
|
|
40
|
+
* those its event's schema marks (sealedSchemaFields). */
|
|
41
|
+
export declare const sealedConfigFields: (config: unknown) => string[];
|
|
42
|
+
/** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
|
|
43
|
+
* or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
|
|
44
|
+
* of those, or says none). What the console's form takes as a password. */
|
|
45
|
+
export declare const sealedSchemaFields: (schema: unknown) => string[];
|
|
46
|
+
/** A credential in a config, where it is: `name`, its top-level field's name or, below the top level, its JSON Pointer
|
|
47
|
+
* (/auth/api_key), as sealed_config names it and its sealed scope is keyed (configScope); `path`, its keys from the
|
|
48
|
+
* config down; `value`. */
|
|
49
|
+
export type ConfigSecret = {
|
|
50
|
+
name: string;
|
|
51
|
+
path: string[];
|
|
52
|
+
value: string | number;
|
|
53
|
+
};
|
|
54
|
+
/** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
|
|
55
|
+
* number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
|
|
56
|
+
* object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
|
|
57
|
+
* at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
|
|
58
|
+
export declare const configSecrets: (config: unknown) => ConfigSecret[];
|
|
59
|
+
/** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
|
|
60
|
+
* in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
|
|
61
|
+
* leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
|
|
62
|
+
export declare const sealedKept: (sent: Json, shown: unknown, sealed: readonly string[]) => Json;
|
|
63
|
+
/** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
|
|
64
|
+
* named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
|
|
65
|
+
* the next start seals it: composio-triggers.ts sealKept). */
|
|
66
|
+
export declare const shownSource: (source: Source) => Source;
|
|
10
67
|
export declare const composio: TriggerAdapter;
|
package/dist/trigger-composio.js
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
// that scope. Every event of the project comes to that one route, checked once with the secret (trigger-signatures.ts's
|
|
7
7
|
// composio scheme); each trigger whose instance is the delivery's metadata.trigger_id and whose `accept` takes it fires,
|
|
8
8
|
// each its own run. This is the one way Composio's events start runs: a webhook trigger takes no composio signature.
|
|
9
|
+
// A config can hold a credential (HubSpot's deal-stage event takes {app_id, developer_api_key}). Composio's trigger
|
|
10
|
+
// schemas mark no field secret (their `config` is a plain JSON schema: type, title, description, required), so a field is
|
|
11
|
+
// sealed by its name (sealedConfigFields), or as an address carrying a credential (credentialUrl): kept in this source's sealed settings, the trigger keeping SEALED_MASK in its
|
|
12
|
+
// place and the field named in `sealed_config`, so no answer, row or log holds it (composio-triggers.ts).
|
|
9
13
|
import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
|
|
10
14
|
import { closedSchema, unknownSourceFields } from "./trigger-adapter.js";
|
|
11
15
|
import { SIGNATURE_SCHEMES } from "./trigger-signatures.js";
|
|
@@ -26,6 +30,151 @@ const CONFIG_BYTES = 8 * 1024;
|
|
|
26
30
|
export const MOVE_FIELD = "move_subscription";
|
|
27
31
|
/** The settings field the project's subscription secret is sealed under, one scope per hook. */
|
|
28
32
|
export const COMPOSIO_SECRET = "secret";
|
|
33
|
+
/** The settings fields a trigger's sealed config value is kept under, one scope per trigger and field (configScope):
|
|
34
|
+
* CONFIG_SECRET for a value the server's list of its secrets can hold (8 bytes or more, no whitespace), so a run that
|
|
35
|
+
* echoes it is cut; CONFIG_UNLISTED, sealed and masked all the same, for one too short or spaced for that list. */
|
|
36
|
+
export const CONFIG_SECRET = "config";
|
|
37
|
+
export const CONFIG_UNLISTED = "config_unlisted";
|
|
38
|
+
/** What a trigger keeps, and answers, in place of a sealed config value. */
|
|
39
|
+
export const SEALED_MASK = "[sealed]";
|
|
40
|
+
/** The source's field that names its sealed config fields, set by this server. */
|
|
41
|
+
export const SEALED_FIELD = "sealed_config";
|
|
42
|
+
/** The settings scope of trigger `id`'s sealed config field `field`. */
|
|
43
|
+
export const configScope = (id, field) => `config:${id}:${encodeURIComponent(field)}`;
|
|
44
|
+
/** The words of a config field's name, lower case: snake, kebab, dotted and camel case split (developerApiKey and
|
|
45
|
+
* developer_api_key both read developer, api, key). */
|
|
46
|
+
const wordsOf = (name) => name.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
47
|
+
/** A word of a name read as its singular: a trailing s dropped (tokens, secrets, keys), from a word of two letters or more. */
|
|
48
|
+
const singular = (word) => (word.length > 1 && word.endsWith("s") ? word.slice(0, -1) : word);
|
|
49
|
+
/** A word that names a credential wherever it stands in a name, read as its singular (credentials, tokens). */
|
|
50
|
+
const SECRET_WORDS = new Set(["secret", "password", "passwd", "passphrase", "passcode", "pwd", "pat", "token", "credential", "apikey", "hapikey", "jwt", "dsn", "sig", "authorization", "bearer", "cookie"]);
|
|
51
|
+
/** A word that, beside a credential's word, makes the name a count or size of it (max_tokens, token_count, tokens_used,
|
|
52
|
+
* tokens_per_minute, password_min_length): no credential. */
|
|
53
|
+
const COUNT_WORDS = new Set(["max", "min", "num", "number", "count", "limit", "total", "used", "usage", "budget", "remaining", "per", "length", "size", "quota"]);
|
|
54
|
+
/** Two words that name a credential together, the one after the other (connection_string); neither does alone. */
|
|
55
|
+
const SECRET_PAIRS = [["connection", "string"]];
|
|
56
|
+
/** Whether config field `name` is named like a credential. Each word is read as its singular (a trailing s dropped), and
|
|
57
|
+
* the name is a credential's when a word is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential,
|
|
58
|
+
* apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie; when it has connection then string; or when its last
|
|
59
|
+
* word is key (api_key, api_keys, developer_api_key, private_key; key_id and keyword are not). A credential's word with a
|
|
60
|
+
* count's word (COUNT_WORDS) just before or after it names a count, not a credential (max_tokens, token_count; a
|
|
61
|
+
* budget_api_key is still a key). Conservative otherwise: a field so named that holds no secret is sealed all the same. */
|
|
62
|
+
export const secretConfigName = (name) => {
|
|
63
|
+
const words = wordsOf(name).map(singular);
|
|
64
|
+
const counted = (i) => COUNT_WORDS.has(words[i - 1] ?? "") || COUNT_WORDS.has(words[i + 1] ?? "");
|
|
65
|
+
return words.some((word, i) => SECRET_WORDS.has(word) && !counted(i)) || (words.at(-1) === "key" && !counted(words.length - 1)) || SECRET_PAIRS.some(([first, then]) => words.some((word, i) => word === first && words[i + 1] === then));
|
|
66
|
+
};
|
|
67
|
+
/** An address in any scheme with an authority (scheme://...): its authority, path, query and fragment, split by hand so a
|
|
68
|
+
* form a URL parser refuses (mongodb://h1:1,h2:2/db) is read too. */
|
|
69
|
+
const ADDRESS = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]*)[^?#]*(\?[^#]*)?(#.*)?$/is;
|
|
70
|
+
/** Whether query or fragment `part` (with its leading ? or #) has a parameter with a value named like a credential. */
|
|
71
|
+
const credentialParam = (part) => part !== undefined && [...new URLSearchParams(part.slice(1))].some(([name, given]) => given !== "" && secretConfigName(name));
|
|
72
|
+
/** An address in any scheme with an '@' after its scheme:// and before any whitespace: a user part, read so whatever a
|
|
73
|
+
* password holds (a raw '/', '?' or '#' that would end the authority early, as in mongodb://u:pa/ss@h) is still one. */
|
|
74
|
+
const USER_PART = /^[a-z][a-z0-9+.-]*:\/\/\S*@/i;
|
|
75
|
+
/** Whether `value` is an address, in any scheme (https, postgres, redis, amqp, mongodb+srv...), that carries a
|
|
76
|
+
* credential: a user part (user:pass@, :pass@, or a token alone as in https://TOKEN@host: any '@' after scheme://
|
|
77
|
+
* before whitespace), or a query or fragment parameter with a value whose name is a credential's (secretConfigName:
|
|
78
|
+
* ?token=, ?api_key=, #access_token=). Such a value is sealed whole, whatever its field's name. Conservative: a user
|
|
79
|
+
* name with no secret (ssh://git@host), or an '@' in a path or query (?email=a@b), is sealed too. */
|
|
80
|
+
export const credentialUrl = (value) => {
|
|
81
|
+
if (USER_PART.test(value))
|
|
82
|
+
return true;
|
|
83
|
+
const parts = ADDRESS.exec(value);
|
|
84
|
+
return parts !== null && (credentialParam(parts[2]) || credentialParam(parts[3]));
|
|
85
|
+
};
|
|
86
|
+
/** Whether `value` is one a credential's field seals: a string, not empty, or a number (its decimal text is what is
|
|
87
|
+
* sealed; the config keeps its type wherever the value goes). A switch, null, an object or an array is not. */
|
|
88
|
+
export const sealableValue = (value) => (typeof value === "string" && value !== "") || (typeof value === "number" && Number.isFinite(value));
|
|
89
|
+
/** The fields of `config` sealed at a save without its schema: each named like a credential (secretConfigName) whose value
|
|
90
|
+
* is sealable (sealableValue), and each whose value is an address carrying a credential (credentialUrl). A create adds
|
|
91
|
+
* those its event's schema marks (sealedSchemaFields). */
|
|
92
|
+
export const sealedConfigFields = (config) => isObject(config) ? Object.entries(config).filter(([name, value]) => (sealableValue(value) && secretConfigName(name)) || (typeof value === "string" && credentialUrl(value))).map(([name]) => name) : [];
|
|
93
|
+
/** The JSON Schema types a credential's value may have. */
|
|
94
|
+
const SEALABLE_TYPES = ["string", "number", "integer"];
|
|
95
|
+
/** The fields of an event's config schema a save seals: each property the schema marks as a credential (format: password,
|
|
96
|
+
* or writeOnly), whatever its name; and each named like a credential that may hold a string or a number (its type is one
|
|
97
|
+
* of those, or says none). What the console's form takes as a password. */
|
|
98
|
+
export const sealedSchemaFields = (schema) => {
|
|
99
|
+
const properties = isObject(schema) && isObject(schema.properties) ? schema.properties : {};
|
|
100
|
+
return Object.entries(properties).filter(([name, property]) => {
|
|
101
|
+
if (isObject(property) && (property.format === "password" || property.writeOnly === true))
|
|
102
|
+
return true;
|
|
103
|
+
const type = isObject(property) ? property.type : undefined;
|
|
104
|
+
return secretConfigName(name) && (type === undefined || SEALABLE_TYPES.includes(String(type)) || (Array.isArray(type) && type.some((one) => SEALABLE_TYPES.includes(String(one)))));
|
|
105
|
+
}).map(([name]) => name);
|
|
106
|
+
};
|
|
107
|
+
const pointerOf = (path) => `/${path.map((key) => key.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
|
|
108
|
+
/** Every credential `config` holds in the clear, at any depth: a sealable value (sealableValue: a string, not empty, or a
|
|
109
|
+
* number), not SEALED_MASK, whose field is named like a credential (secretConfigName), or that is anywhere inside an
|
|
110
|
+
* object or array so named; and every string that is an address carrying a credential (credentialUrl), wherever it is. A create takes one
|
|
111
|
+
* at the top level alone (composio-triggers.ts make); a trigger an earlier server kept may hold one deeper. */
|
|
112
|
+
export const configSecrets = (config) => {
|
|
113
|
+
const found = [];
|
|
114
|
+
const walk = (node, path, named) => {
|
|
115
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
116
|
+
if ((named || (typeof node === "string" && credentialUrl(node))) && sealableValue(node) && node !== SEALED_MASK)
|
|
117
|
+
found.push({ name: path.length === 1 ? path[0] : pointerOf(path), path, value: node });
|
|
118
|
+
}
|
|
119
|
+
else if (Array.isArray(node))
|
|
120
|
+
node.forEach((item, i) => walk(item, [...path, String(i)], named));
|
|
121
|
+
else if (isObject(node))
|
|
122
|
+
for (const [key, item] of Object.entries(node))
|
|
123
|
+
walk(item, [...path, key], named || secretConfigName(key));
|
|
124
|
+
};
|
|
125
|
+
if (isObject(config))
|
|
126
|
+
for (const [key, item] of Object.entries(config))
|
|
127
|
+
walk(item, [key], secretConfigName(key));
|
|
128
|
+
return found;
|
|
129
|
+
};
|
|
130
|
+
/** `config` with each of `secrets` as SEALED_MASK, at its place. */
|
|
131
|
+
const maskedConfig = (config, secrets) => {
|
|
132
|
+
const copy = structuredClone(config);
|
|
133
|
+
for (const { path } of secrets) {
|
|
134
|
+
let node = copy;
|
|
135
|
+
for (const key of path.slice(0, -1))
|
|
136
|
+
node = node[key];
|
|
137
|
+
node[path.at(-1)] = SEALED_MASK;
|
|
138
|
+
}
|
|
139
|
+
return copy;
|
|
140
|
+
};
|
|
141
|
+
/** `sent`, a PATCH's config, with SEALED_MASK put back at each place `shown` (the config as answered) holds a field named
|
|
142
|
+
* in `sealed` (sealed_config: a top-level name, or a JSON Pointer read as configSecrets writes it, pointerOf) and `sent`
|
|
143
|
+
* leaves it out under an object it sends: a sealed value left out is kept. A copy: `sent` is not changed. */
|
|
144
|
+
export const sealedKept = (sent, shown, sealed) => {
|
|
145
|
+
const names = new Set(sealed);
|
|
146
|
+
const places = [];
|
|
147
|
+
const walk = (node, path) => {
|
|
148
|
+
if (path.length && names.has(path.length === 1 ? path[0] : pointerOf(path)))
|
|
149
|
+
places.push(path);
|
|
150
|
+
else if (Array.isArray(node))
|
|
151
|
+
node.forEach((item, i) => walk(item, [...path, String(i)]));
|
|
152
|
+
else if (isObject(node))
|
|
153
|
+
for (const [key, item] of Object.entries(node))
|
|
154
|
+
walk(item, [...path, key]);
|
|
155
|
+
};
|
|
156
|
+
walk(shown, []);
|
|
157
|
+
const copy = structuredClone(sent);
|
|
158
|
+
for (const path of places) {
|
|
159
|
+
let node = copy;
|
|
160
|
+
for (const key of path.slice(0, -1))
|
|
161
|
+
node = isObject(node) ? node[key] : undefined;
|
|
162
|
+
if (isObject(node) && node[path.at(-1)] === undefined)
|
|
163
|
+
node[path.at(-1)] = SEALED_MASK;
|
|
164
|
+
}
|
|
165
|
+
return copy;
|
|
166
|
+
};
|
|
167
|
+
/** `source` as every answer sends it: each credential in its config (configSecrets, at any depth) as SEALED_MASK, and
|
|
168
|
+
* named in sealed_config, whether it is sealed yet or still kept in the clear (a trigger saved before this rule, until
|
|
169
|
+
* the next start seals it: composio-triggers.ts sealKept). */
|
|
170
|
+
export const shownSource = (source) => {
|
|
171
|
+
const config = source.config;
|
|
172
|
+
const clear = configSecrets(config);
|
|
173
|
+
if (!clear.length || !isObject(config))
|
|
174
|
+
return source;
|
|
175
|
+
const sealed = Array.isArray(source[SEALED_FIELD]) ? source[SEALED_FIELD] : [];
|
|
176
|
+
return { ...source, config: maskedConfig(config, clear), [SEALED_FIELD]: [...new Set([...sealed, ...clear.map((secret) => secret.name)])] };
|
|
177
|
+
};
|
|
29
178
|
const jsonOf = (text) => {
|
|
30
179
|
try {
|
|
31
180
|
return JSON.parse(text);
|
|
@@ -39,7 +188,7 @@ const jsonOf = (text) => {
|
|
|
39
188
|
function fieldsOf(value, bad) {
|
|
40
189
|
let failed = false;
|
|
41
190
|
const fail = (...args) => ((failed = true), bad(...args));
|
|
42
|
-
const { server, event, config, instance_id: instance, hook } = value;
|
|
191
|
+
const { server, event, config, instance_id: instance, hook, [SEALED_FIELD]: sealed } = value;
|
|
43
192
|
if (typeof server !== "string" || !MCP_SERVER_NAME.test(server))
|
|
44
193
|
fail("server", server === undefined ? "missing" : "invalid", "server is the name of a saved Composio MCP server (Settings → MCP servers), whose key and account the trigger uses");
|
|
45
194
|
if (typeof event !== "string" || !COMPOSIO_EVENT.test(event))
|
|
@@ -50,6 +199,8 @@ function fieldsOf(value, bad) {
|
|
|
50
199
|
fail("instance_id", "invalid", "instance_id is Composio's id for the trigger's instance, set by this server");
|
|
51
200
|
if (hook !== undefined && !(typeof hook === "string" && COMPOSIO_HOOK.test(hook)))
|
|
52
201
|
fail("hook", "invalid", "hook is the id of the project's route here, set by this server");
|
|
202
|
+
if (sealed !== undefined && !(Array.isArray(sealed) && sealed.length <= 100 && sealed.every((name) => typeof name === "string" && name.length <= 200)))
|
|
203
|
+
fail(SEALED_FIELD, "invalid", `${SEALED_FIELD} names the config's sealed fields, set by this server`);
|
|
53
204
|
if (value[MOVE_FIELD] !== undefined && value[MOVE_FIELD] !== true)
|
|
54
205
|
fail(MOVE_FIELD, "invalid", `${MOVE_FIELD} is true, or left out`);
|
|
55
206
|
const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
|
|
@@ -59,7 +210,7 @@ function fieldsOf(value, bad) {
|
|
|
59
210
|
return undefined;
|
|
60
211
|
return {
|
|
61
212
|
kind: "composio", server: server, event: event, config: config,
|
|
62
|
-
...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
|
|
213
|
+
...(accept ? { accept } : {}), ...(typeof instance === "string" ? { instance_id: instance } : {}), ...(typeof hook === "string" ? { hook } : {}), ...(Array.isArray(sealed) ? { [SEALED_FIELD]: sealed } : {}), ...(value[MOVE_FIELD] === true ? { [MOVE_FIELD]: true } : {}),
|
|
63
214
|
};
|
|
64
215
|
}
|
|
65
216
|
export const composio = {
|
|
@@ -67,8 +218,9 @@ export const composio = {
|
|
|
67
218
|
label: "Composio trigger",
|
|
68
219
|
delivery: "push",
|
|
69
220
|
owner: false,
|
|
70
|
-
// Each project's subscription secret, Composio's own, sealed under its hook's scope
|
|
71
|
-
|
|
221
|
+
// Each project's subscription secret, Composio's own, sealed under its hook's scope, and each trigger's sealed config
|
|
222
|
+
// value under its own (configScope): composio-triggers.ts keeps them.
|
|
223
|
+
settings: { scope: "server", fields: { [COMPOSIO_SECRET]: {}, [CONFIG_SECRET]: {}, [CONFIG_UNLISTED]: { public: true } } },
|
|
72
224
|
describe: '{kind: "composio", server, event, config, accept?: [{event, where?}], move_subscription?: true}',
|
|
73
225
|
fires: "an event of a saved Composio server's toolkit that Composio delivers to /hooks/composio/{hook} for the trigger's instance, that its `accept` takes (`composio`)",
|
|
74
226
|
firedBy: "`composio`: an event Composio delivered for the trigger's instance (the delivery's metadata.trigger_id) that its accept took, its key from the trigger and the delivery's `webhook-id`.",
|
|
@@ -77,18 +229,20 @@ export const composio = {
|
|
|
77
229
|
kind: { const: "composio" },
|
|
78
230
|
server: { type: "string", pattern: MCP_SERVER_NAME.source, description: "A saved Composio MCP server (Settings → MCP servers): its key makes the instance, for the account it is connected as." },
|
|
79
231
|
event: { type: "string", pattern: COMPOSIO_EVENT.source, description: "One of the server's toolkit's events, Composio's trigger slug (GET /settings/mcp-servers/{name}/composio/events)." },
|
|
80
|
-
config: { type: "object", description:
|
|
232
|
+
config: { type: "object", description: `The event's config, as its schema in the events list says (GitHub's new-issue event: {owner, repo}). A field named like a credential (a word of its name, read as its singular, is secret, password, passwd, passphrase, passcode, pwd, pat, token, credential, apikey, hapikey, jwt, dsn, sig, authorization, bearer or cookie, unless a count word (max, min, num, number, count, limit, total, used, usage, budget, remaining, per, length, size, quota) is right beside it: max_tokens and token_count are counts; it has connection then string; or its last word is key: developer_api_key, api_keys), or one the event's schema marks with format: password or writeOnly, holding a string or a number, is sealed at the save, as is any http(s) address with a password in its user part or a query parameter so named with a value: Composio gets it, and every answer has "${SEALED_MASK}" in its place, the field named in ${SEALED_FIELD}. One below the config's top level is refused 422. A PATCH that leaves it out or sends "${SEALED_MASK}" keeps it; another value is a change to the config, refused as any is.` },
|
|
81
233
|
}, {
|
|
82
234
|
accept: { ...ACCEPT_SCHEMA, description: "Optional: which of the event's deliveries fire it. A rule's `event` is the trigger's own, `where` pointers read the delivery, its event's data under `/data` (`/data/title`). None: every delivery for its instance fires." },
|
|
83
235
|
instance_id: { type: "string", readOnly: true, description: "Composio's id for the trigger's instance, set by this server when it makes it: the delivery's metadata.trigger_id. Triggers with the same server, event and config share one." },
|
|
236
|
+
[SEALED_FIELD]: { type: "array", items: { type: "string" }, readOnly: true, description: `The config's sealed fields, set by this server at the save: each answered as "${SEALED_MASK}", its value kept sealed here. Each is a top-level field's name, or, for one an earlier server kept below the top level, its JSON Pointer (/auth/api_key).` },
|
|
84
237
|
hook: { type: "string", pattern: COMPOSIO_HOOK.source, readOnly: true, description: "The id of the project's route here, /hooks/composio/{hook}, set by this server: the address of the project's webhook subscription on Composio." },
|
|
85
238
|
[MOVE_FIELD]: { type: "boolean", enum: [true], writeOnly: true, description: "At a create alone, never kept: the project's webhook subscription is at another address, and the owner moves it here. Without it, such a create is refused 409 composio_subscription_elsewhere, naming the address." },
|
|
86
239
|
}),
|
|
87
240
|
],
|
|
88
241
|
parse(value, _now, bad, issues) {
|
|
89
|
-
issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", MOVE_FIELD]));
|
|
242
|
+
issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", SEALED_FIELD, MOVE_FIELD]));
|
|
90
243
|
return fieldsOf(value, bad);
|
|
91
244
|
},
|
|
245
|
+
shown: shownSource,
|
|
92
246
|
wellFormed: (source) => {
|
|
93
247
|
const read = fieldsOf(source, () => { });
|
|
94
248
|
return read !== undefined && typeof read.instance_id === "string" && typeof read.hook === "string";
|
package/dist/triggers.d.ts
CHANGED
|
@@ -358,6 +358,7 @@ export declare class Triggers {
|
|
|
358
358
|
name: string;
|
|
359
359
|
enabled: boolean;
|
|
360
360
|
source: Source;
|
|
361
|
+
updatedAt: number;
|
|
361
362
|
}[]>;
|
|
362
363
|
/** Every trigger of source `kind` that is on, turned off because the connection it needs is gone (`disabled: {reason:
|
|
363
364
|
* "connection_lost", detail}`), and said; how many. They are kept: on again once it is back. */
|
|
@@ -439,6 +440,9 @@ export declare class Triggers {
|
|
|
439
440
|
} | null | undefined;
|
|
440
441
|
hook_url?: string | undefined;
|
|
441
442
|
}>;
|
|
443
|
+
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
444
|
+
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
445
|
+
private updateOnce;
|
|
442
446
|
/** The trigger deleted, and what its sender keeps of it removed after (said, when it could not be: the delete holds). */
|
|
443
447
|
remove(id: string): Promise<Json | undefined>;
|
|
444
448
|
/** Run now: one firing per Idempotency-Key, driven before the answer. `created` false: the key's firing, as it stands. */
|
package/dist/triggers.js
CHANGED
|
@@ -101,6 +101,8 @@ const REAL_CLOCK = {
|
|
|
101
101
|
},
|
|
102
102
|
};
|
|
103
103
|
const iso = (ms) => new Date(ms).toISOString();
|
|
104
|
+
/** How many times a PATCH carrying a source is checked again when the trigger changed between its read and its write. */
|
|
105
|
+
const SOURCE_EDIT_TRIES = 3;
|
|
104
106
|
export const firingKey = (by, triggerId, what) => `fir_${createHash("sha256").update(`${by}\n${triggerId}\n${what}`).digest("hex").slice(0, 32)}`;
|
|
105
107
|
/** The adapter of `kind`, among `adapters`. */
|
|
106
108
|
const adapterIn = (adapters, kind) => adapters.find((a) => a.id === kind);
|
|
@@ -348,7 +350,7 @@ export class Triggers {
|
|
|
348
350
|
/** Every trigger of source `kind`, on or off, with its name and source: what a source's sender keeps of them is shared
|
|
349
351
|
* between some (composio-triggers.ts: one Composio instance per server, event and config). */
|
|
350
352
|
async ofKind(kind) {
|
|
351
|
-
return (await this.store.triggers.all()).map(asTrigger).filter((t) => t.source.kind === kind).map((t) => ({ id: t.id, name: t.name, enabled: t.enabled, source: t.source }));
|
|
353
|
+
return (await this.store.triggers.all()).map(asTrigger).filter((t) => t.source.kind === kind).map((t) => ({ id: t.id, name: t.name, enabled: t.enabled, source: t.source, updatedAt: t.updatedAt }));
|
|
352
354
|
}
|
|
353
355
|
/** Every trigger of source `kind` that is on, turned off because the connection it needs is gone (`disabled: {reason:
|
|
354
356
|
* "connection_lost", detail}`), and said; how many. They are kept: on again once it is back. */
|
|
@@ -440,6 +442,18 @@ export class Triggers {
|
|
|
440
442
|
* paused range is skipped, never caught up. Only the fields named change, applied to the trigger as it stands once
|
|
441
443
|
* the target's check is done: an edit made meanwhile keeps its own. */
|
|
442
444
|
async update(id, body) {
|
|
445
|
+
// A source is written only on the row it was checked against (its updatedAt): another write meanwhile (the
|
|
446
|
+
// after-start seal's, a poll's next time) checks it again on the row as it is then, so a source read before a seal
|
|
447
|
+
// never writes the clear value back over it.
|
|
448
|
+
for (let tries = 1;; tries++) {
|
|
449
|
+
const done = await this.updateOnce(id, body, tries < SOURCE_EDIT_TRIES);
|
|
450
|
+
if (done)
|
|
451
|
+
return done;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
/** One try of `update`: undefined when its source write was refused because the trigger changed since it was read and
|
|
455
|
+
* `retry` (try again); refused on the last try, precondition_failed. */
|
|
456
|
+
async updateOnce(id, body, retry) {
|
|
443
457
|
const was = await this.need(id);
|
|
444
458
|
const issues = unknownFields(body, WRITABLE);
|
|
445
459
|
let source = body.source === undefined ? undefined : sourceOf(this.adapters, body.source, this.clock.now(), issues);
|
|
@@ -497,9 +511,14 @@ export class Triggers {
|
|
|
497
511
|
...(settings.catchup_window_s !== undefined ? { catchupWindowS: settings.catchup_window_s } : {}),
|
|
498
512
|
...(settings.max_active_runs !== undefined ? { maxActiveRuns: settings.max_active_runs } : {}), ...again, enabled, nextAt: next,
|
|
499
513
|
};
|
|
500
|
-
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : []).catch(async (error) => {
|
|
514
|
+
const row = await this.store.triggers.update(id, patch, enabled ? this.scopesOf(scopeSource) : [], source ? { ifUpdatedAt: trigger.updatedAt, ifSource: trigger.source } : undefined).catch(async (error) => {
|
|
501
515
|
throw (await this.scopeTaken(error, scopeSource, trigger.id)) ?? (await this.archivedRefusal(error)) ?? nameTaken(error, patch.name ?? trigger.name);
|
|
502
516
|
});
|
|
517
|
+
if (!row && source && (await this.store.triggers.get(id))) {
|
|
518
|
+
if (retry)
|
|
519
|
+
return undefined;
|
|
520
|
+
throw new ApiError("precondition_failed", "the trigger kept changing while this edit was checked: read it again, then send the edit again");
|
|
521
|
+
}
|
|
503
522
|
if (!row)
|
|
504
523
|
throw new ApiError("not_found", `no trigger ${id}`);
|
|
505
524
|
// Turned on again, a polled source forgets its cursor and last check, so its first poll watches from now, and is
|
|
@@ -1120,7 +1139,7 @@ export class Triggers {
|
|
|
1120
1139
|
return {
|
|
1121
1140
|
...(hook ? { hook_url: `${this.deps.publicUrl ?? ""}${hook}` } : {}),
|
|
1122
1141
|
...(adapter?.poll ? { last_check: check ? { at: check.at, ok: check.ok, message: check.message } : null } : {}),
|
|
1123
|
-
id: trigger.id, name: trigger.name, enabled: trigger.enabled, source: trigger.source, target: trigger.target, catchup_window_s: trigger.catchupWindowS ?? CATCHUP_WINDOW_S,
|
|
1142
|
+
id: trigger.id, name: trigger.name, enabled: trigger.enabled, source: adapter?.shown ? adapter.shown(trigger.source) : trigger.source, target: trigger.target, catchup_window_s: trigger.catchupWindowS ?? CATCHUP_WINDOW_S,
|
|
1124
1143
|
max_active_runs: trigger.maxActiveRuns ?? null, failures_in_a_row: trigger.failuresInARow, disabled: trigger.disabled ?? null, next_at: trigger.nextAt === null ? null : iso(trigger.nextAt), last_run_id: trigger.lastRunId,
|
|
1125
1144
|
created_at: iso(trigger.createdAt), updated_at: iso(trigger.updatedAt), last_firing: last ? firingView(last) : null,
|
|
1126
1145
|
};
|
package/dist/validate.d.ts
CHANGED
|
@@ -28,10 +28,12 @@ export declare const skillNames: (files: Iterable<string>) => string[];
|
|
|
28
28
|
/**
|
|
29
29
|
* A definition as `POST /agents` and `PUT .../definition` take it: what one revision of an agent keeps. `instructions`
|
|
30
30
|
* makes an agentic revision, `workflow` (an agentrun-dsl workflow) a workflow revision. `creating` asks for a name.
|
|
31
|
+
* `harnesses`: the ids `harness` may name, the server's table's (harness-table.ts harnessIds); the built-in ones by default.
|
|
31
32
|
*/
|
|
32
|
-
export declare function definitionIssues(definition: unknown, { at, creating }?: {
|
|
33
|
-
at?: string
|
|
34
|
-
creating?: boolean
|
|
33
|
+
export declare function definitionIssues(definition: unknown, { at, creating, harnesses }?: {
|
|
34
|
+
at?: string;
|
|
35
|
+
creating?: boolean;
|
|
36
|
+
harnesses?: readonly string[];
|
|
35
37
|
}): InputIssue[];
|
|
36
38
|
/** A definition's skill names against the files its revision holds: each named skill has its SKILL.md, and each
|
|
37
39
|
* SKILL.md is named. */
|
|
@@ -42,16 +44,18 @@ export type DefinitionBody = {
|
|
|
42
44
|
note?: string;
|
|
43
45
|
};
|
|
44
46
|
/** What is wrong with `{definition, skills?, note?}`, as checkDefinitionBody refuses it: every field issue. */
|
|
45
|
-
export declare function definitionBodyIssues(body: Json, { creating }?: {
|
|
46
|
-
creating?: boolean
|
|
47
|
+
export declare function definitionBodyIssues(body: Json, { creating, harnesses }?: {
|
|
48
|
+
creating?: boolean;
|
|
49
|
+
harnesses?: readonly string[];
|
|
47
50
|
}): InputIssue[];
|
|
48
51
|
/**
|
|
49
52
|
* `{definition, skills?, note?}`, as `POST /agents` and `PUT .../definition` take it. `skills` are the revision's skill
|
|
50
53
|
* files (absent on an edit: the current revision's); `note` says what the revision changes. Throws `422 input_invalid`
|
|
51
54
|
* naming every field that is wrong.
|
|
52
55
|
*/
|
|
53
|
-
export declare function checkDefinitionBody(body: Json, { creating }?: {
|
|
54
|
-
creating?: boolean
|
|
56
|
+
export declare function checkDefinitionBody(body: Json, { creating, harnesses }?: {
|
|
57
|
+
creating?: boolean;
|
|
58
|
+
harnesses?: readonly string[];
|
|
55
59
|
}): DefinitionBody;
|
|
56
60
|
/** The default input schema: `{content: string}`. */
|
|
57
61
|
export declare const DEFAULT_INPUT_SCHEMA: {
|