@parcha/agentrun-serve 0.1.0-beta.38 → 0.1.0-beta.39
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 +418 -0
- package/README.md +325 -124
- package/dist/adapters.d.ts +4 -1
- package/dist/adapters.js +4 -2
- package/dist/agent-rows.d.ts +0 -2
- package/dist/agents-store.d.ts +5 -5
- package/dist/agents-store.js +14 -14
- package/dist/bash-read-only.js +2 -1
- package/dist/cap-short.d.ts +12 -0
- package/dist/cap-short.js +60 -0
- package/dist/cap.d.ts +3 -10
- package/dist/cap.js +2 -5
- package/dist/catalog.d.ts +0 -5
- package/dist/catalog.js +1 -5
- package/dist/chatgpt-plan.d.ts +163 -0
- package/dist/chatgpt-plan.js +549 -0
- package/dist/cli.js +26 -6
- package/dist/composio-preset.d.ts +8 -0
- package/dist/composio-preset.js +8 -7
- package/dist/composio-triggers.d.ts +113 -0
- package/dist/composio-triggers.js +411 -0
- package/dist/computer-calls.js +2 -2
- package/dist/computer-commands.d.ts +2 -0
- package/dist/computer-commands.js +7 -3
- package/dist/computer-live.d.ts +7 -2
- package/dist/computer-live.js +9 -5
- package/dist/computer-routes.d.ts +2 -2
- package/dist/computer-routes.js +2 -2
- package/dist/computer-setting.d.ts +3 -3
- package/dist/computer-setting.js +5 -5
- package/dist/computer-view.d.ts +15 -0
- package/dist/computer-view.js +16 -2
- package/dist/computer-viewer.js +14 -1
- package/dist/computers.d.ts +5 -2
- package/dist/computers.js +9 -5
- package/dist/console/assets/index-BNhZs-jp.css +1 -0
- package/dist/console/assets/index-BQv5aOGB.js +700 -0
- package/dist/console/index.html +2 -2
- package/dist/console-links.js +3 -3
- package/dist/decision-cap.d.ts +2 -5
- package/dist/decision-cap.js +3 -6
- package/dist/decision-rows.js +11 -11
- package/dist/email/account.d.ts +84 -0
- package/dist/email/account.js +159 -0
- package/dist/email/answer.d.ts +10 -0
- package/dist/email/answer.js +182 -0
- package/dist/email/email-faux.d.ts +95 -0
- package/dist/email/email-faux.js +849 -0
- package/dist/email/labels.d.ts +1 -0
- package/dist/email/labels.js +84 -0
- package/dist/email/mail.d.ts +186 -0
- package/dist/email/mail.js +380 -0
- package/dist/email/names.d.ts +20 -0
- package/dist/email/names.js +40 -0
- package/dist/email/routes.d.ts +9 -0
- package/dist/email/routes.js +50 -0
- package/dist/email/tools.d.ts +20 -0
- package/dist/email/tools.js +517 -0
- package/dist/environment.d.ts +17 -2
- package/dist/environment.js +36 -8
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +12 -0
- package/dist/eval-mailbox.d.ts +103 -0
- package/dist/eval-mailbox.js +236 -0
- package/dist/graph-view.d.ts +9 -2
- package/dist/graph-view.js +6 -2
- package/dist/harness-install.d.ts +28 -2
- package/dist/harness-install.js +147 -59
- package/dist/harness-opencode/adapter.js +2 -26
- package/dist/harness-opencode/facts.js +5 -2
- package/dist/harness-opencode/host/policy.d.ts +2 -0
- package/dist/harness-opencode/host/policy.js +10 -5
- package/dist/harness-opencode/index.d.ts +1 -1
- package/dist/harness-opencode/index.js +1 -1
- package/dist/harness-opencode/versions.d.ts +6 -0
- package/dist/harness-opencode/versions.js +6 -0
- package/dist/harness-table.js +8 -5
- package/dist/harness.d.ts +12 -0
- package/dist/harness.js +15 -3
- package/dist/hosted-search.d.ts +3 -1
- package/dist/hosted-search.js +51 -11
- package/dist/import-sources.d.ts +1 -1
- package/dist/import-sources.js +3 -3
- package/dist/import.d.ts +21 -0
- package/dist/import.js +186 -1
- package/dist/key-check.d.ts +0 -2
- package/dist/key-check.js +3 -4
- package/dist/key-refusal.d.ts +8 -2
- package/dist/key-refusal.js +16 -13
- package/dist/learn/check.d.ts +18 -3
- package/dist/learn/check.js +328 -3
- package/dist/learn/compile.d.ts +9 -2
- package/dist/learn/compile.js +52 -16
- package/dist/learn/grade.d.ts +4 -0
- package/dist/learn/grade.js +4 -1
- package/dist/learn/promote.d.ts +106 -51
- package/dist/learn/promote.js +82 -189
- package/dist/learn/refit.d.ts +21 -12
- package/dist/learn/refit.js +51 -23
- package/dist/learn/replay-calls.js +1 -1
- package/dist/learn/skills.d.ts +2 -7
- package/dist/learn/skills.js +28 -14
- package/dist/learned-nodes.d.ts +15 -7
- package/dist/learned-nodes.js +29 -5
- package/dist/learned-workflow.d.ts +41 -31
- package/dist/learned-workflow.js +122 -63
- package/dist/learning-batch.js +3 -3
- package/dist/learning-cost.d.ts +26 -8
- package/dist/learning-cost.js +17 -7
- package/dist/learning-routes.d.ts +2 -4
- package/dist/learning-routes.js +20 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +4 -1
- package/dist/learning.d.ts +5 -5
- package/dist/link-check.d.ts +27 -0
- package/dist/link-check.js +164 -0
- package/dist/local-models.d.ts +33 -2
- package/dist/local-models.js +43 -5
- package/dist/mcp-pin-first.js +6 -0
- package/dist/mcp-secret-writes.js +3 -0
- package/dist/mcp-servers-store.d.ts +25 -16
- package/dist/mcp-servers-store.js +23 -3
- package/dist/model-form.d.ts +11 -0
- package/dist/model-form.js +17 -1
- package/dist/model.d.ts +26 -6
- package/dist/model.js +126 -18
- package/dist/monid.d.ts +26 -31
- package/dist/monid.js +84 -79
- package/dist/native/binding.d.ts +13 -0
- package/dist/native/binding.js +57 -0
- package/dist/native/cli.d.ts +2 -0
- package/dist/native/cli.js +48 -0
- package/dist/native/connection.d.ts +8 -0
- package/dist/native/connection.js +94 -0
- package/dist/native/context.d.ts +6 -0
- package/dist/native/context.js +22 -0
- package/dist/native/discovery.d.ts +27 -0
- package/dist/native/discovery.js +404 -0
- package/dist/native/environment.d.ts +4 -0
- package/dist/native/environment.js +18 -0
- package/dist/native/history.d.ts +20 -0
- package/dist/native/history.js +147 -0
- package/dist/native/instructions.d.ts +21 -0
- package/dist/native/instructions.js +173 -0
- package/dist/native/remote-worker-bridge.d.ts +3 -0
- package/dist/native/remote-worker-bridge.js +278 -0
- package/dist/native/remote.d.ts +187 -0
- package/dist/native/remote.js +492 -0
- package/dist/native/runtime.d.ts +17 -0
- package/dist/native/runtime.js +316 -0
- package/dist/native/runtimes.d.ts +66 -0
- package/dist/native/runtimes.js +41 -0
- package/dist/native/schema.d.ts +46 -0
- package/dist/native/schema.js +41 -0
- package/dist/native/types.d.ts +87 -0
- package/dist/native/types.js +1 -0
- package/dist/observation/http.d.ts +4 -0
- package/dist/observation/http.js +140 -0
- package/dist/observation/observer.d.ts +301 -0
- package/dist/observation/observer.js +919 -0
- package/dist/observation/schema.d.ts +52 -0
- package/dist/observation/schema.js +154 -0
- package/dist/openapi.d.ts +1 -0
- package/dist/openapi.js +394 -85
- package/dist/paid-calls.d.ts +8 -3
- package/dist/paid-calls.js +6 -2
- package/dist/place-offers.d.ts +4 -8
- package/dist/place-offers.js +4 -9
- package/dist/port-models.d.ts +7 -2
- package/dist/port-models.js +5 -2
- package/dist/print.d.ts +4 -2
- package/dist/print.js +4 -3
- package/dist/propose.d.ts +1 -2
- package/dist/propose.js +10 -1
- package/dist/provider.d.ts +5 -1
- package/dist/provider.js +8 -0
- package/dist/push-handler.d.ts +3 -2
- package/dist/push-handler.js +20 -6
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +13 -2
- package/dist/run-launch.d.ts +10 -1
- package/dist/run-launch.js +11 -4
- package/dist/run-learning-served.d.ts +75 -2
- package/dist/run-manifest.d.ts +3 -0
- package/dist/run-manifest.js +13 -1
- package/dist/run-reads-over-store.d.ts +3 -3
- package/dist/run-reads-over-store.js +13 -10
- package/dist/run-timeline-served.d.ts +3 -2
- package/dist/run-timeline-served.js +8 -9
- package/dist/run-view.d.ts +42 -35
- package/dist/run-view.js +79 -44
- package/dist/runnable.d.ts +13 -5
- package/dist/runnable.js +69 -60
- package/dist/runner/adapter-loop.d.ts +42 -11
- package/dist/runner/adapter-loop.js +651 -247
- package/dist/runner/adapter-run-spec.d.ts +37 -12
- package/dist/runner/adapter-run-spec.js +139 -106
- package/dist/runner/adapters/pi.d.ts +24 -0
- package/dist/runner/adapters/pi.js +59 -9
- package/dist/runner/beside.d.ts +3 -1
- package/dist/runner/beside.js +24 -8
- package/dist/runner/claim-secrets.d.ts +3 -1
- package/dist/runner/claim-secrets.js +28 -4
- package/dist/runner/cli-run-spec.d.ts +30 -0
- package/dist/runner/cli-run-spec.js +94 -50
- package/dist/runner/computer-channel.d.ts +5 -2
- package/dist/runner/computer-channel.js +3 -2
- package/dist/runner/computer-journal.d.ts +6 -0
- package/dist/runner/computer-journal.js +8 -10
- package/dist/runner/conformance/harness.js +6 -3
- package/dist/runner/end-of-run.d.ts +2 -0
- package/dist/runner/end-of-run.js +3 -1
- package/dist/runner/feedback-round.d.ts +40 -13
- package/dist/runner/feedback-round.js +64 -16
- package/dist/runner/harness-loops.js +17 -0
- package/dist/runner/journal-kinds.d.ts +37 -13
- package/dist/runner/journal-kinds.js +9 -5
- package/dist/runner/learning-dispatch.d.ts +3 -2
- package/dist/runner/learning-dispatch.js +6 -6
- package/dist/runner/learning-end.d.ts +4 -0
- package/dist/runner/learning-end.js +64 -36
- package/dist/runner/learning-factory.d.ts +3 -0
- package/dist/runner/learning-factory.js +8 -2
- package/dist/runner/learning-loop.d.ts +2 -0
- package/dist/runner/learning-loop.js +19 -4
- package/dist/runner/loop.d.ts +18 -0
- package/dist/runner/loop.js +34 -0
- package/dist/runner/main.d.ts +6 -1
- package/dist/runner/main.js +26 -4
- package/dist/runner/mcp-run.d.ts +4 -1
- package/dist/runner/mcp-run.js +11 -5
- package/dist/runner/meta-tools.d.ts +10 -3
- package/dist/runner/meta-tools.js +112 -36
- package/dist/runner/metrics.d.ts +80 -21
- package/dist/runner/metrics.js +114 -39
- package/dist/runner/model-route.d.ts +12 -3
- package/dist/runner/model-route.js +139 -18
- package/dist/runner/monid-run.d.ts +8 -6
- package/dist/runner/monid-run.js +117 -43
- package/dist/runner/native-loop.d.ts +11 -0
- package/dist/runner/native-loop.js +438 -0
- package/dist/runner/promotion.d.ts +74 -8
- package/dist/runner/promotion.js +365 -124
- package/dist/runner/redact.js +3 -0
- package/dist/runner/reflect-hook.js +9 -0
- package/dist/runner/runner.d.ts +7 -1
- package/dist/runner/runner.js +8 -4
- package/dist/runner/sdk-loop.d.ts +7 -0
- package/dist/runner/sdk-loop.js +470 -0
- package/dist/runner/spec-holds.d.ts +16 -2
- package/dist/runner/spec-holds.js +42 -14
- package/dist/runner/store-secrets.js +17 -2
- package/dist/runner/workflow-first.d.ts +30 -20
- package/dist/runner/workflow-first.js +22 -32
- package/dist/runner/workflow-loop.d.ts +1 -1
- package/dist/runner/workflow-loop.js +18 -12
- package/dist/runner/workflow-spec.d.ts +4 -1
- package/dist/runner/workflow-spec.js +56 -45
- package/dist/runs-over-store.d.ts +30 -2
- package/dist/runs-over-store.js +46 -14
- package/dist/sdk/runs.d.ts +115 -0
- package/dist/sdk/runs.js +422 -0
- package/dist/sdk/schema.d.ts +175 -0
- package/dist/sdk/schema.js +138 -0
- package/dist/sdk/workflows.d.ts +22 -0
- package/dist/sdk/workflows.js +39 -0
- package/dist/secrets.d.ts +2 -0
- package/dist/secrets.js +19 -1
- package/dist/server.d.ts +48 -32
- package/dist/server.js +554 -130
- package/dist/skill-route.d.ts +3 -0
- package/dist/skill-route.js +16 -0
- package/dist/skills/agentrun-serve/SKILL.md +368 -0
- package/dist/stats.d.ts +10 -10
- package/dist/store/agent-body.d.ts +12 -8
- package/dist/store/agent-body.js +9 -4
- package/dist/store/index.d.ts +1 -1
- package/dist/store/native-command-owner.d.ts +10 -0
- package/dist/store/native-command-owner.js +47 -0
- package/dist/store/postgres/migrations/0012_revision_monid_pin.sql +4 -0
- package/dist/store/postgres/migrations/0013_native_command_owner.sql +6 -0
- package/dist/store/postgres/migrations/0014_run_cost_upper_bound.sql +6 -0
- package/dist/store/postgres/store.js +3 -0
- package/dist/store/schema.d.ts +7 -0
- package/dist/store/schema.js +20 -1
- package/dist/store/sqlite/run-patch.d.ts +8 -1
- package/dist/store/sqlite/run-patch.js +14 -3
- package/dist/store/sqlite/store.js +133 -18
- package/dist/store/store.d.ts +52 -7
- package/dist/store-reads/analytics.d.ts +7 -7
- package/dist/store-reads/analytics.js +23 -5
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/journal.d.ts +5 -0
- package/dist/store-reads/journal.js +85 -41
- package/dist/store-reads/learning.d.ts +85 -5
- package/dist/store-reads/learning.js +45 -17
- package/dist/store-reads/runs.d.ts +5 -0
- package/dist/store-reads/runs.js +3 -2
- package/dist/store-view.js +75 -21
- package/dist/template-eval.d.ts +73 -11
- package/dist/template-eval.js +535 -75
- package/dist/templates.d.ts +70 -20
- package/dist/templates.js +191 -34
- package/dist/text-urls.d.ts +38 -0
- package/dist/text-urls.js +170 -0
- package/dist/timeline/index.d.ts +3 -2
- package/dist/timeline/index.js +3 -2
- package/dist/timeline/labels.d.ts +5 -2
- package/dist/timeline/labels.js +29 -6
- package/dist/timeline/origin.d.ts +1 -1
- package/dist/timeline/origin.js +2 -2
- package/dist/timeline/render-text.js +1 -1
- package/dist/timeline/timeline.d.ts +66 -4
- package/dist/timeline/timeline.js +160 -30
- package/dist/timeline/util.d.ts +5 -0
- package/dist/timeline/util.js +44 -8
- package/dist/timeline/web-calls.d.ts +17 -0
- package/dist/timeline/web-calls.js +106 -0
- package/dist/tool-gate.d.ts +42 -42
- package/dist/tool-gate.js +97 -91
- package/dist/tool-list.d.ts +4 -1
- package/dist/tool-list.js +8 -1
- package/dist/tool-names.d.ts +18 -13
- package/dist/tool-names.js +19 -17
- package/dist/tool-plane.d.ts +17 -13
- package/dist/tool-plane.js +12 -5
- package/dist/tools.d.ts +44 -16
- package/dist/tools.js +28 -28
- package/dist/trigger-adapter.d.ts +85 -5
- package/dist/trigger-adapter.js +6 -0
- package/dist/trigger-adapters.js +3 -1
- package/dist/trigger-composio.d.ts +10 -0
- package/dist/trigger-composio.js +122 -0
- package/dist/trigger-email.d.ts +4 -0
- package/dist/trigger-email.js +228 -0
- package/dist/trigger-signatures.d.ts +6 -10
- package/dist/trigger-signatures.js +16 -16
- package/dist/trigger-targets.d.ts +1 -1
- package/dist/trigger-targets.js +4 -3
- package/dist/trigger-webhook.js +6 -4
- package/dist/triggers.d.ts +94 -9
- package/dist/triggers.js +263 -62
- package/dist/uploads.d.ts +9 -0
- package/dist/uploads.js +27 -0
- package/dist/validate.js +1 -7
- package/dist/web-fake.d.ts +56 -0
- package/dist/web-fake.js +102 -0
- package/dist/web-fetch-direct.d.ts +3 -0
- package/dist/web-fetch-direct.js +4 -1
- package/dist/web-fetch.d.ts +5 -1
- package/dist/web-fetch.js +8 -31
- package/dist/web-search.d.ts +51 -2
- package/dist/web-search.js +116 -18
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -1
- package/dist/workflow/node-runner.js +10 -2
- package/dist/workspace/archil-claim.d.ts +3 -0
- package/dist/workspace/archil-claim.js +9 -2
- package/dist/workspace/computer-deps.d.ts +22 -9
- package/dist/workspace/computer-deps.js +78 -37
- package/dist/workspace/computer-for-claim.d.ts +54 -4
- package/dist/workspace/computer-for-claim.js +179 -39
- package/dist/workspace/computer-janitor.d.ts +10 -3
- package/dist/workspace/computer-janitor.js +96 -29
- package/dist/workspace/computer-kept.d.ts +82 -0
- package/dist/workspace/computer-kept.js +147 -0
- package/dist/workspace/computer-mcp.js +4 -3
- package/dist/workspace/computer-ports.d.ts +23 -3
- package/dist/workspace/computer-ports.js +115 -5
- package/dist/workspace/index.d.ts +1 -2
- package/dist/workspace/index.js +1 -2
- package/dist/workspace/kind-skills/desktop/SKILL.md +25 -18
- package/dist/workspace/kind-skills/phone/SKILL.md +28 -17
- package/dist/workspace/resolve-computer.d.ts +15 -3
- package/dist/workspace/resolve-computer.js +10 -7
- package/dist/workspace/revision-skills.d.ts +6 -2
- package/dist/workspace/revision-skills.js +12 -5
- package/dist/workspace/run-end-computers.d.ts +30 -0
- package/dist/workspace/run-end-computers.js +137 -0
- package/dist/workspace/run-tools.d.ts +28 -29
- package/dist/workspace/run-tools.js +29 -30
- package/dist/wrap-up.d.ts +19 -5
- package/dist/wrap-up.js +31 -4
- package/package.json +13 -9
- package/skills/agentrun-serve/SKILL.md +248 -10
- package/templates/README.md +117 -23
- package/templates/TOOLS.md +168 -0
- package/templates/code-review/agent.md +18 -4
- package/templates/code-review/evals/mentions-defused/case.yaml +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +2 -1
- package/templates/code-review/evals/other-repo/case.yaml +1 -1
- package/templates/code-review/evals/pasted-by-reference/case.yaml +5 -0
- package/templates/code-review/evals/pasted-by-reference/graders/by-reference.md +15 -0
- package/templates/code-review/evals/pasted-by-reference/graders/head-sha.md +6 -0
- package/templates/code-review/evals/pasted-by-reference/prompt.md +31 -0
- package/templates/code-review/skills/review/DEEP.md +2 -2
- package/templates/code-review/skills/review/REVIEWER.md +2 -2
- package/templates/code-review/skills/review/SKILL.md +7 -3
- package/templates/release-notes/evals/draft-not-publish/case.yaml +1 -1
- package/templates/release-notes/evals/issue-write-refused/case.yaml +1 -1
- package/templates/release-notes/evals/late-arrival/case.yaml +1 -1
- package/templates/release-notes/evals/other-repo/case.yaml +1 -1
- package/dist/console/assets/index-CjqQirbo.css +0 -1
- package/dist/console/assets/index-b6-XY5A9.js +0 -576
- package/dist/host-calls.d.ts +0 -20
- package/dist/host-calls.js +0 -12
- package/dist/runner/adapters/pi-computer.d.ts +0 -9
- package/dist/runner/adapters/pi-computer.js +0 -51
- package/dist/workspace/computer-script.d.ts +0 -53
- package/dist/workspace/computer-script.js +0 -172
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Composio: a trigger source set up from here (composio-triggers.ts). A trigger names a saved Composio server, one of its
|
|
2
|
+
// toolkit's events (Composio's trigger slug) and that event's config; making it makes the trigger instance on Composio
|
|
3
|
+
// for the account the server is connected as, and the project's one webhook subscription at this server's address when
|
|
4
|
+
// there is none yet. The server fills in what it made: `instance_id`, Composio's id for the instance, and `hook`, the id
|
|
5
|
+
// of the project's route, /v2/hooks/composio/{hook}, whose secret (the subscription's, Composio's own) is sealed under
|
|
6
|
+
// that scope. Every event of the project comes to that one route, checked once with the secret (trigger-signatures.ts's
|
|
7
|
+
// composio scheme); each trigger whose instance is the delivery's metadata.trigger_id and whose `accept` takes it fires,
|
|
8
|
+
// each its own run. This is the one way Composio's events start runs: a webhook trigger takes no composio signature.
|
|
9
|
+
import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
|
|
10
|
+
import { closedSchema, unknownSourceFields } from "./trigger-adapter.js";
|
|
11
|
+
import { SIGNATURE_SCHEMES } from "./trigger-signatures.js";
|
|
12
|
+
import { MCP_SERVER_NAME } from "./tool-names.js";
|
|
13
|
+
import { isObject } from "./validate.js";
|
|
14
|
+
/** The longest of a sender's words a payload's attrs keep. */
|
|
15
|
+
const ATTR_CHARS = 200;
|
|
16
|
+
const scheme = SIGNATURE_SCHEMES.composio;
|
|
17
|
+
/** A Composio trigger slug: upper case, digits and `_` (GITHUB_ISSUE_ADDED_EVENT). */
|
|
18
|
+
export const COMPOSIO_EVENT = /^[A-Z0-9][A-Z0-9_]{0,127}$/;
|
|
19
|
+
/** The id of a project's route here, made once when its subscription is made or moved here. */
|
|
20
|
+
export const COMPOSIO_HOOK = /^cph_[0-9a-f]{24}$/;
|
|
21
|
+
/** An id Composio gives a trigger instance (ti_...). */
|
|
22
|
+
const INSTANCE = /^[A-Za-z0-9_-]{1,100}$/;
|
|
23
|
+
/** The most bytes an event's config holds, as JSON. */
|
|
24
|
+
const CONFIG_BYTES = 8 * 1024;
|
|
25
|
+
/** The source's field the move of a subscription is asked with: at a create alone, never kept. */
|
|
26
|
+
export const MOVE_FIELD = "move_subscription";
|
|
27
|
+
/** The settings field the project's subscription secret is sealed under, one scope per hook. */
|
|
28
|
+
export const COMPOSIO_SECRET = "secret";
|
|
29
|
+
const jsonOf = (text) => {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(text);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/** The source's fields, checked: each issue through `bad`. A rule of `accept` names the trigger's own event: it reads one
|
|
38
|
+
* event alone. */
|
|
39
|
+
function fieldsOf(value, bad) {
|
|
40
|
+
let failed = false;
|
|
41
|
+
const fail = (...args) => ((failed = true), bad(...args));
|
|
42
|
+
const { server, event, config, instance_id: instance, hook } = value;
|
|
43
|
+
if (typeof server !== "string" || !MCP_SERVER_NAME.test(server))
|
|
44
|
+
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
|
+
if (typeof event !== "string" || !COMPOSIO_EVENT.test(event))
|
|
46
|
+
fail("event", event === undefined ? "missing" : "invalid", "event is one of the server's toolkit's events, as Composio slugs it (GITHUB_ISSUE_ADDED_EVENT): GET /v2/settings/mcp-servers/{name}/composio/events lists them");
|
|
47
|
+
if (!isObject(config) || Buffer.byteLength(JSON.stringify(config), "utf8") > CONFIG_BYTES)
|
|
48
|
+
fail("config", config === undefined ? "missing" : "invalid", `config is the event's config, an object as its schema says (GitHub's {owner, repo}), at most ${CONFIG_BYTES} bytes as JSON`);
|
|
49
|
+
if (instance !== undefined && !(typeof instance === "string" && INSTANCE.test(instance)))
|
|
50
|
+
fail("instance_id", "invalid", "instance_id is Composio's id for the trigger's instance, set by this server");
|
|
51
|
+
if (hook !== undefined && !(typeof hook === "string" && COMPOSIO_HOOK.test(hook)))
|
|
52
|
+
fail("hook", "invalid", "hook is the id of the project's route here, set by this server");
|
|
53
|
+
if (value[MOVE_FIELD] !== undefined && value[MOVE_FIELD] !== true)
|
|
54
|
+
fail(MOVE_FIELD, "invalid", `${MOVE_FIELD} is true, or left out`);
|
|
55
|
+
const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
|
|
56
|
+
if (accept && typeof event === "string")
|
|
57
|
+
accept.forEach((rule, i) => rule.event !== event && fail(`accept[${i}].event`, "invalid", `A composio trigger takes its one event: a rule's event is ${event}.`));
|
|
58
|
+
if (failed)
|
|
59
|
+
return undefined;
|
|
60
|
+
return {
|
|
61
|
+
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 } : {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export const composio = {
|
|
66
|
+
id: "composio",
|
|
67
|
+
label: "Composio trigger",
|
|
68
|
+
delivery: "push",
|
|
69
|
+
owner: false,
|
|
70
|
+
// Each project's subscription secret, Composio's own, sealed under its hook's scope (composio-triggers.ts keeps it).
|
|
71
|
+
settings: { scope: "server", fields: { [COMPOSIO_SECRET]: {} } },
|
|
72
|
+
describe: '{kind: "composio", server, event, config, accept?: [{event, where?}], move_subscription?: true}',
|
|
73
|
+
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
|
+
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`.",
|
|
75
|
+
schemas: [
|
|
76
|
+
closedSchema({
|
|
77
|
+
kind: { const: "composio" },
|
|
78
|
+
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
|
+
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: "The event's config, as its schema in the events list says (GitHub's new-issue event: {owner, repo})." },
|
|
81
|
+
}, {
|
|
82
|
+
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
|
+
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." },
|
|
84
|
+
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
|
+
[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
|
+
}),
|
|
87
|
+
],
|
|
88
|
+
parse(value, _now, bad, issues) {
|
|
89
|
+
issues.push(...unknownSourceFields(value, ["kind", "server", "event", "config", "accept", "instance_id", "hook", MOVE_FIELD]));
|
|
90
|
+
return fieldsOf(value, bad);
|
|
91
|
+
},
|
|
92
|
+
wellFormed: (source) => {
|
|
93
|
+
const read = fieldsOf(source, () => { });
|
|
94
|
+
return read !== undefined && typeof read.instance_id === "string" && typeof read.hook === "string";
|
|
95
|
+
},
|
|
96
|
+
// Each delivery is its own work (an issue each); max_active_runs bounds it.
|
|
97
|
+
concurrent: () => true,
|
|
98
|
+
hookOf: (source) => `composio/${String(source.hook)}`,
|
|
99
|
+
// A delivery fires the triggers of its project's route (`scope`, the hook it came to) whose instance it names, and whose
|
|
100
|
+
// filter takes it.
|
|
101
|
+
takes(source, event) {
|
|
102
|
+
if (event.scope === undefined || source.hook !== event.scope)
|
|
103
|
+
return "other_project";
|
|
104
|
+
if (!event.attrs?.trigger_id || source.instance_id !== event.attrs.trigger_id)
|
|
105
|
+
return "other_instance";
|
|
106
|
+
return source.accept ? acceptRefusal(source.accept, event.event, event.body) : undefined;
|
|
107
|
+
},
|
|
108
|
+
push: {
|
|
109
|
+
maxBodyBytes: 256 << 10,
|
|
110
|
+
key: COMPOSIO_SECRET,
|
|
111
|
+
scoped: true,
|
|
112
|
+
headers: (headers, nowMs) => scheme.precheck(headers, nowMs),
|
|
113
|
+
verify: (key, headers, body, nowMs) => scheme.verify(key, headers, body, nowMs),
|
|
114
|
+
parse(headers, body) {
|
|
115
|
+
const text = body.toString("utf8");
|
|
116
|
+
const doc = jsonOf(text);
|
|
117
|
+
const event = scheme.eventOf(headers, doc);
|
|
118
|
+
const attrs = { scheme: "composio", ...(event !== undefined ? { event: event.slice(0, ATTR_CHARS) } : {}), ...scheme.attrsOf?.(doc) };
|
|
119
|
+
return [{ key: scheme.firingKeyOf(headers, body), text, attrs, ...(event !== undefined ? { event } : {}), body: doc }];
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// The email trigger: a source on a clock that polls (trigger-adapter.ts `poll`). Every every_s seconds, on a grid from the
|
|
2
|
+
// epoch, it reads the server's email account's mailbox (INBOX by default) over IMAP, read-only, and each message that
|
|
3
|
+
// came since its cursor is one firing through the path a pushed event takes (triggers.ts): its accept filter, a run per
|
|
4
|
+
// message, max_active_runs, its key kept for its day. The cursor is the account it was read on (its user, IMAP host and
|
|
5
|
+
// port: nothing secret), the mailbox, its UIDVALIDITY and the last UID read, in the trigger's own settings, kept only once
|
|
6
|
+
// the poll's firings are recorded, so a restart goes on from it. Its start
|
|
7
|
+
// (the engine's start hook) is taken when the trigger is made, when an edit changes its mailbox or account, and when it
|
|
8
|
+
// is turned on again: mail from before then starts no run, and that is said; any other edit keeps the cursor. A start
|
|
9
|
+
// that can't sign in is taken at the first poll that does, and said; a UIDVALIDITY the server changed the same, and so
|
|
10
|
+
// another account saved in its place (PUT /v2/settings/email). A message's key is its Message-ID (else UIDVALIDITY:UID), so
|
|
11
|
+
// one seen twice fires once; its attrs say where it was found (mailbox, UIDVALIDITY, UID), which a run's thread is read
|
|
12
|
+
// from (email/tools.ts). At most POLL_TAKES messages a poll, oldest first. A
|
|
13
|
+
// message this server sent (X-AgentRun-Sent, email/tools.ts email_send) is left, and said. An unreachable server is said
|
|
14
|
+
// on the trigger and tried at the next time; a refused sign-in counts (the engine turns the trigger off at the third).
|
|
15
|
+
import { DEFAULT_ACCOUNT, NO_ACCOUNT } from "./email/account.js";
|
|
16
|
+
import { ACCEPT_SCHEMA, acceptOf, acceptRefusal } from "./trigger-accept.js";
|
|
17
|
+
import { closedSchema, PAYLOAD_KEPT_BYTES, unknownSourceFields } from "./trigger-adapter.js";
|
|
18
|
+
import { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
|
|
19
|
+
/** The most messages one poll takes: the rest wait for the next. */
|
|
20
|
+
export const POLL_TAKES = 20;
|
|
21
|
+
/** The one event an email trigger's accept names. */
|
|
22
|
+
const EVENT = "message";
|
|
23
|
+
/** The trigger's own settings: its cursor and its last check, no secret (public). */
|
|
24
|
+
const CURSOR = "cursor";
|
|
25
|
+
/** Which account a cursor was read on: its user, IMAP host and port, nothing secret (the cursor is a public setting). */
|
|
26
|
+
const accountKey = (account) => `${account.user.trim().toLowerCase()}@${account.imap.host.toLowerCase()}:${account.imap.port}`;
|
|
27
|
+
/** The source's own fields, checked: each issue through `bad`. Undefined when one does not read. */
|
|
28
|
+
function fieldsOf(value, bad) {
|
|
29
|
+
let failed = false;
|
|
30
|
+
const fail = (field, reason, message) => ((failed = true), bad(field, reason, message));
|
|
31
|
+
const account = value.account ?? DEFAULT_ACCOUNT;
|
|
32
|
+
if (account !== DEFAULT_ACCOUNT)
|
|
33
|
+
fail("account", "not_an_option", `account is "${DEFAULT_ACCOUNT}": this server has one email account`);
|
|
34
|
+
const mailbox = value.mailbox ?? "INBOX";
|
|
35
|
+
if (typeof mailbox !== "string" || !mailbox.trim() || mailbox.length > 300 || /[\u0000-\u001f]/.test(mailbox))
|
|
36
|
+
fail("mailbox", "invalid", "mailbox is a mailbox's name: INBOX (the default), or a folder's");
|
|
37
|
+
const every = value.every_s ?? MIN_EVERY_S;
|
|
38
|
+
if (!Number.isSafeInteger(every) || every < MIN_EVERY_S || every > MAX_EVERY_S)
|
|
39
|
+
fail("every_s", "invalid", `every_s is a whole number of seconds, ${MIN_EVERY_S} to ${MAX_EVERY_S}`);
|
|
40
|
+
const accept = value.accept === undefined ? undefined : acceptOf(value.accept, fail);
|
|
41
|
+
accept?.forEach((rule, i) => {
|
|
42
|
+
if (rule.event !== EVENT)
|
|
43
|
+
fail(`accept[${i}].event`, "not_an_option", `An email trigger's one event is "${EVENT}"`);
|
|
44
|
+
if (rule.actions !== undefined)
|
|
45
|
+
fail(`accept[${i}].actions`, "not_allowed", "An email has no action: take it by its fields with where");
|
|
46
|
+
});
|
|
47
|
+
if (failed)
|
|
48
|
+
return undefined;
|
|
49
|
+
return { kind: "email", account: account, mailbox: mailbox.trim(), every_s: every, ...(accept ? { accept } : {}) };
|
|
50
|
+
}
|
|
51
|
+
/** The cursor kept, when it reads. */
|
|
52
|
+
function cursorOf(text) {
|
|
53
|
+
if (!text)
|
|
54
|
+
return undefined;
|
|
55
|
+
try {
|
|
56
|
+
const value = JSON.parse(text);
|
|
57
|
+
return (value.account === undefined || typeof value.account === "string") && typeof value.mailbox === "string" && typeof value.uidvalidity === "string" && Number.isSafeInteger(value.uid) ? value : undefined;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const kept = (cursor) => ({ [CURSOR]: JSON.stringify(cursor) });
|
|
64
|
+
/** Whether `payload`'s JSON is within the engine's bound, measured as the engine does: bytes of UTF-8, escapes counted. */
|
|
65
|
+
const fits = (payload) => Buffer.byteLength(JSON.stringify(payload), "utf8") <= PAYLOAD_KEPT_BYTES;
|
|
66
|
+
/** The first `n` characters (code points) of `text`, ending in `…` when cut. */
|
|
67
|
+
const clipped = (text, n) => (typeof text === "string" && [...text].length > n ? `${[...text].slice(0, n).join("")}…` : text);
|
|
68
|
+
/** A message's payload whole, its JSON within PAYLOAD_KEPT_BYTES, so the engine never cuts it mid-string. When it is over,
|
|
69
|
+
* the text is cut, the longest prefix that fits found by halving (a character's start, escapes counted), said in it and
|
|
70
|
+
* marked `text_truncated: true`; when its other fields alone are over, the subject, the names and the lists are cut too,
|
|
71
|
+
* shorter until it fits. */
|
|
72
|
+
function fittedPayload(whole) {
|
|
73
|
+
if (fits(whole))
|
|
74
|
+
return whole;
|
|
75
|
+
const text = typeof whole.text === "string" ? whole.text : "";
|
|
76
|
+
// No more characters than the bound has bytes can fit: the halving reads at most that many.
|
|
77
|
+
const chars = [...text.slice(0, 2 * PAYLOAD_KEPT_BYTES)].slice(0, PAYLOAD_KEPT_BYTES);
|
|
78
|
+
const said = `\n[cut: the message's text was ${Buffer.byteLength(text, "utf8")} bytes]`;
|
|
79
|
+
let rest = whole;
|
|
80
|
+
const withText = (n) => ({ ...rest, text: `${chars.slice(0, n).join("")}${said}`, text_truncated: true });
|
|
81
|
+
for (let room = 1000; !fits(withText(0)); room = Math.floor(room / 2)) {
|
|
82
|
+
const list = (value) => (Array.isArray(value) ? value.slice(0, Math.max(1, Math.floor(room / 20))).map((one) => (typeof one === "string" ? clipped(one, Math.min(320, room)) : one)) : value);
|
|
83
|
+
const attachments = Array.isArray(whole.attachments) ? whole.attachments.slice(0, Math.max(0, Math.floor(room / 20))).map((a) => ({ ...a, name: clipped(a?.name, Math.min(200, room)) })) : whole.attachments;
|
|
84
|
+
rest = { ...whole, from: clipped(whole.from, Math.min(998, room)), message_id: clipped(whole.message_id, Math.min(998, room)), in_reply_to: clipped(whole.in_reply_to, Math.min(998, room)), subject: clipped(whole.subject, room), from_name: clipped(whole.from_name, Math.min(320, room)), to: list(whole.to), cc: list(whole.cc), attachments };
|
|
85
|
+
if (room === 0)
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
let lo = 0;
|
|
89
|
+
let hi = chars.length;
|
|
90
|
+
while (lo < hi) {
|
|
91
|
+
const mid = Math.ceil((lo + hi) / 2);
|
|
92
|
+
if (fits(withText(mid)))
|
|
93
|
+
lo = mid;
|
|
94
|
+
else
|
|
95
|
+
hi = mid - 1;
|
|
96
|
+
}
|
|
97
|
+
return withText(lo);
|
|
98
|
+
}
|
|
99
|
+
/** A message as the event its trigger fires: its payload (JSON, untrusted, whole within the engine's bound), its attrs
|
|
100
|
+
* (who, what, and where it was found: the run's thread is read from there), keyed by its Message-ID. */
|
|
101
|
+
function eventOf(m, cursor, payloadOf) {
|
|
102
|
+
const payload = fittedPayload(payloadOf(m));
|
|
103
|
+
return {
|
|
104
|
+
key: m.message_id ?? `${cursor.uidvalidity}:${m.uid}`,
|
|
105
|
+
text: JSON.stringify(payload),
|
|
106
|
+
attrs: { from: m.from, subject: m.subject, ...(m.message_id ? { message_id: m.message_id } : {}), mailbox: cursor.mailbox, uidvalidity: cursor.uidvalidity, uid: String(m.uid) },
|
|
107
|
+
event: EVENT,
|
|
108
|
+
body: payload,
|
|
109
|
+
cursor: kept(cursor),
|
|
110
|
+
...(m.sent_here !== undefined ? { left: "Left: this server sent that message (it carries X-AgentRun-Sent), so it starts no run." } : {}),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** `n` messages, in words. */
|
|
114
|
+
const messages = (n) => `${n} message${n === 1 ? "" : "s"}`;
|
|
115
|
+
/** The cursor at the end of `source`'s mailbox on `account` as it is now, and how many messages it holds: where watching
|
|
116
|
+
* starts. */
|
|
117
|
+
async function endOf(session, source, account) {
|
|
118
|
+
const path = await session.resolve(source.mailbox);
|
|
119
|
+
const box = await session.open(path);
|
|
120
|
+
// The newest UID there: UIDNEXT's one before, else the highest a search finds.
|
|
121
|
+
const uid = box.uidNext > 0 ? box.uidNext - 1 : Math.max(0, ...(await session.uids({ all: true })));
|
|
122
|
+
return { cursor: { account: accountKey(account), mailbox: path, uidvalidity: box.uidValidity, uid }, exists: box.exists };
|
|
123
|
+
}
|
|
124
|
+
/** The history line of a start taken for `why`, with `exists` messages left. */
|
|
125
|
+
const watching = (source, exists, why) => why === "enabled"
|
|
126
|
+
? `Watching ${source.mailbox} from now, on again: the ${messages(exists)} already there, any that came while it was off among them, won't start runs.`
|
|
127
|
+
: `Watching ${source.mailbox} from now: the ${messages(exists)} already there won't start runs.`;
|
|
128
|
+
/** The history line of a start that could not read the mailbox. */
|
|
129
|
+
const unchecked = (source, why) => `Couldn't check ${String(source.mailbox ?? "INBOX")} when it was ${why === "created" ? "created" : why === "edited" ? "changed" : "turned on again"}; watching from the first check that signs in.`;
|
|
130
|
+
/** `source`'s start, on `account`: the cursor at its mailbox's end now. */
|
|
131
|
+
async function start(source, account, why) {
|
|
132
|
+
const { MailError, withImap } = await import("./email/mail.js");
|
|
133
|
+
return withImap(account, async (session) => {
|
|
134
|
+
const end = await endOf(session, source, account);
|
|
135
|
+
return { check: { ok: true, message: `Watching ${source.mailbox}.` }, note: watching(source, end.exists, why), cursor: kept(end.cursor) };
|
|
136
|
+
}).catch((error) => {
|
|
137
|
+
const failure = error instanceof MailError ? error : new MailError("failed", String(error?.message ?? error));
|
|
138
|
+
return { check: { ok: false, message: failure.message }, note: unchecked(source, why) };
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/** One poll of `source`'s mailbox from `cursor`, on `account`. The mail libraries load at the first poll, never with the
|
|
142
|
+
* registry (every process that reads the sources). */
|
|
143
|
+
async function poll(source, account, cursor) {
|
|
144
|
+
const { MailError, payloadOf, READ_BYTES, withImap } = await import("./email/mail.js");
|
|
145
|
+
return withImap(account, async (session) => {
|
|
146
|
+
const end = await endOf(session, source, account);
|
|
147
|
+
const path = end.cursor.mailbox;
|
|
148
|
+
// No start yet (one that could not sign in, or a cursor kept before starts were taken): this check takes it.
|
|
149
|
+
if (!cursor || cursor.mailbox !== path)
|
|
150
|
+
return { check: { ok: true, message: `Watching ${source.mailbox}.` }, note: watching(source, end.exists, "created"), cursor: kept(end.cursor) };
|
|
151
|
+
// Another account saved in its place (or a cursor that names none): its UIDs are another mailbox's, so it starts over.
|
|
152
|
+
if (cursor.account !== end.cursor.account) {
|
|
153
|
+
return { check: { ok: true, message: `Watching ${source.mailbox} again: the email account changed.` }, note: `The email account changed: watching ${source.mailbox} from now; the ${messages(end.exists)} there won't start runs.`, cursor: kept(end.cursor) };
|
|
154
|
+
}
|
|
155
|
+
if (cursor.uidvalidity !== end.cursor.uidvalidity) {
|
|
156
|
+
return { check: { ok: true, message: `Watching ${source.mailbox} again: the mail server rebuilt it.` }, note: `${source.mailbox} was rebuilt on the mail server (its UIDVALIDITY changed): watching it from now; the ${messages(end.exists)} there won't start runs.`, cursor: kept(end.cursor) };
|
|
157
|
+
}
|
|
158
|
+
// `n:*` names the highest UID even when it is below n: only those past the cursor count.
|
|
159
|
+
const fresh = (await session.uids({ uid: `${cursor.uid + 1}:*` })).filter((uid) => uid > cursor.uid);
|
|
160
|
+
const taken = fresh.slice(0, POLL_TAKES);
|
|
161
|
+
const read = await session.fetch(path, taken, READ_BYTES);
|
|
162
|
+
const events = read.map((m) => eventOf(m, { ...cursor, uid: m.uid }, payloadOf));
|
|
163
|
+
const last = taken.at(-1) ?? cursor.uid;
|
|
164
|
+
const more = fresh.length - taken.length;
|
|
165
|
+
return { check: { ok: true, message: `Read ${source.mailbox}: ${messages(events.length)} new${more > 0 ? `, ${more} more at the next check` : ""}.` }, events, cursor: kept({ ...cursor, uid: last }) };
|
|
166
|
+
}).catch((error) => {
|
|
167
|
+
const failure = error instanceof MailError ? error : new MailError("failed", String(error?.message ?? error));
|
|
168
|
+
if (failure.kind === "refused")
|
|
169
|
+
return { check: { ok: false, message: failure.message }, refused: { detail: "The mail server refused the sign-in 3 times in a row: check the account in Settings → Email, then turn this trigger on again." } };
|
|
170
|
+
return { check: { ok: false, message: failure.message } };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export const email = {
|
|
174
|
+
id: "email",
|
|
175
|
+
label: "email trigger",
|
|
176
|
+
delivery: "clock",
|
|
177
|
+
owner: false,
|
|
178
|
+
// Each message is its sender's: one run's answer (to alice) is never handed to the next (bob's).
|
|
179
|
+
previousResult: false,
|
|
180
|
+
settings: { scope: "trigger", fields: { [CURSOR]: { public: true }, last_check: { public: true } } },
|
|
181
|
+
describe: `{kind: "email", account?: "${DEFAULT_ACCOUNT}", mailbox?: "INBOX", every_s?: ${MIN_EVERY_S}, accept?: [{event: "${EVENT}", where?}]}`,
|
|
182
|
+
fires: "each new message in the server's email account's mailbox (`email`), read every every_s seconds, that its `accept` takes",
|
|
183
|
+
firedBy: "`email`: a message found in the email account's mailbox, its key from the trigger and the message's Message-ID (else its UIDVALIDITY and UID).",
|
|
184
|
+
schemas: [
|
|
185
|
+
closedSchema({ kind: { const: "email" } }, {
|
|
186
|
+
account: { const: DEFAULT_ACCOUNT, default: DEFAULT_ACCOUNT, description: "The email account it reads (Settings → Email): the server's one, \"default\"." },
|
|
187
|
+
mailbox: { type: "string", minLength: 1, maxLength: 300, default: "INBOX", description: "The mailbox it reads: INBOX, \"Drafts\" or \"Sent\" (the account's own), or a folder's name." },
|
|
188
|
+
every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S, default: MIN_EVERY_S, description: "How often it reads the mailbox, in seconds, on a grid from the epoch." },
|
|
189
|
+
accept: { ...ACCEPT_SCHEMA, description: `The messages that start a run: each rule's event is "${EVENT}", its where reads the payload (/from, /to, /subject, /text, ...). None: every message.` },
|
|
190
|
+
}),
|
|
191
|
+
],
|
|
192
|
+
sent: [
|
|
193
|
+
closedSchema({ kind: { const: "email" }, account: { const: DEFAULT_ACCOUNT }, mailbox: { type: "string" }, every_s: { type: "integer", minimum: MIN_EVERY_S, maximum: MAX_EVERY_S } }, { accept: ACCEPT_SCHEMA }),
|
|
194
|
+
],
|
|
195
|
+
parse(value, _now, bad, issues) {
|
|
196
|
+
issues.push(...unknownSourceFields(value, ["kind", "account", "mailbox", "every_s", "accept"]));
|
|
197
|
+
return fieldsOf(value, bad);
|
|
198
|
+
},
|
|
199
|
+
wellFormed: (source) => fieldsOf(source, () => { }) !== undefined,
|
|
200
|
+
clock(source) {
|
|
201
|
+
const step = source.every_s * 1000;
|
|
202
|
+
return { next: (after) => (Math.floor(after / step) + 1) * step, latest: (first, now) => first + Math.floor((now - first) / step) * step, step };
|
|
203
|
+
},
|
|
204
|
+
problem: (source) => (typeof source.every_s === "number" && (source.every_s < MIN_EVERY_S || source.every_s > MAX_EVERY_S) ? `every_s ${source.every_s} is not ${MIN_EVERY_S} to ${MAX_EVERY_S} seconds` : undefined),
|
|
205
|
+
// Each message is its own work: a run per message, max_active_runs bounding how many at once.
|
|
206
|
+
concurrent: () => true,
|
|
207
|
+
takes: (source, event) => {
|
|
208
|
+
const rules = source.accept;
|
|
209
|
+
return rules ? acceptRefusal(rules, event.event, event.body) : undefined;
|
|
210
|
+
},
|
|
211
|
+
async poll(source, ctx) {
|
|
212
|
+
const account = (await ctx.credentials());
|
|
213
|
+
if (!account)
|
|
214
|
+
return { check: { ok: false, message: NO_ACCOUNT } };
|
|
215
|
+
return poll(source, account, cursorOf(ctx.setting(CURSOR)));
|
|
216
|
+
},
|
|
217
|
+
start: {
|
|
218
|
+
on: ["account", "mailbox"],
|
|
219
|
+
async take(source, ctx) {
|
|
220
|
+
const account = (await ctx.credentials());
|
|
221
|
+
if (!account)
|
|
222
|
+
return { check: { ok: false, message: NO_ACCOUNT }, note: unchecked(source, ctx.why) };
|
|
223
|
+
return start(source, account, ctx.why);
|
|
224
|
+
},
|
|
225
|
+
unchecked,
|
|
226
|
+
},
|
|
227
|
+
title: (attrs) => `${attrs.from ?? ""} — ${attrs.subject ?? ""}`,
|
|
228
|
+
};
|
|
@@ -2,10 +2,8 @@ import { headersRefusal } from "./standard-webhooks.js";
|
|
|
2
2
|
type Headers = Record<string, string | string[] | undefined>;
|
|
3
3
|
export type Scheme = {
|
|
4
4
|
/** The header its signature comes in: a request that carries it, and no other header's, is checked by a scheme that
|
|
5
|
-
* names it
|
|
5
|
+
* names it. */
|
|
6
6
|
signatureHeader: string;
|
|
7
|
-
/** Its secret is the sender's own, given at the trigger's create and rotation, never one this server mints. */
|
|
8
|
-
givenSecret?: true;
|
|
9
7
|
/** How a sender signs under it, for the OpenAPI document. */
|
|
10
8
|
describe: string;
|
|
11
9
|
/** Why the headers alone are refused, before a byte of the body is read. */
|
|
@@ -49,7 +47,6 @@ export declare const SIGNATURE_SCHEMES: {
|
|
|
49
47
|
};
|
|
50
48
|
composio: {
|
|
51
49
|
signatureHeader: string;
|
|
52
|
-
givenSecret: true;
|
|
53
50
|
describe: string;
|
|
54
51
|
precheck: typeof headersRefusal;
|
|
55
52
|
verify: (key: string, headers: Headers, body: Buffer<ArrayBufferLike>, nowMs: number) => string | undefined;
|
|
@@ -62,13 +59,12 @@ export declare const SIGNATURE_SCHEMES: {
|
|
|
62
59
|
};
|
|
63
60
|
};
|
|
64
61
|
export type SchemeName = keyof typeof SIGNATURE_SCHEMES;
|
|
65
|
-
|
|
62
|
+
/** The schemes a webhook trigger's `signature` may name: every one but `composio`, a Composio trigger's. */
|
|
63
|
+
export declare const SCHEME_NAMES: readonly SchemeName[];
|
|
66
64
|
export declare const DEFAULT_SCHEME: SchemeName;
|
|
67
|
-
/** The scheme a request asks for: the one whose signature header it carries.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* read, where the headers' check is the same for both) the first of them stands in. `refusal` when it carries no
|
|
71
|
-
* signature header, or the headers of more than one. */
|
|
65
|
+
/** The webhook scheme a request asks for: the one of SCHEME_NAMES whose signature header it carries. Were two to share a
|
|
66
|
+
* header, the trigger's own (`wanted`, its `signature`) would pick, and with no `wanted` (before the trigger is read) the
|
|
67
|
+
* first of them. `refusal` when it carries no signature header, or the headers of more than one. */
|
|
72
68
|
export declare function schemeOf(headers: Headers, wanted?: string): {
|
|
73
69
|
name: SchemeName;
|
|
74
70
|
scheme: Scheme;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// The signature schemes
|
|
1
|
+
// The signature schemes, in one table: each names the header its signature comes in, checks a
|
|
2
2
|
// request's headers before its body is read, verifies the request under the trigger's secret, and reads the request's
|
|
3
3
|
// firing key (from what its signature covers, so a replay under a new id is the same firing) and its event (what a
|
|
4
|
-
// trigger's accept rules match). A request is checked by
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// trigger's accept rules match). A webhook trigger's `signature` names one of SCHEME_NAMES, and its request is checked by
|
|
5
|
+
// the one of those whose signature header it carries. `composio` is a Composio trigger's alone (trigger-composio.ts
|
|
6
|
+
// checks the project's deliveries with it): a webhook trigger never takes it. A new webhook scheme is one entry here and
|
|
7
|
+
// its name in SCHEME_NAMES: the webhook source's schema and its check read that list.
|
|
7
8
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
8
9
|
import { HOOK_TOLERANCE_S, headersRefusal, HOOK_ID, MIN_KEY_BYTES, verify as verifyStandard, verifyWithKey } from "./standard-webhooks.js";
|
|
9
10
|
import { isObject } from "./validate.js";
|
|
@@ -70,14 +71,14 @@ export const SIGNATURE_SCHEMES = {
|
|
|
70
71
|
};
|
|
71
72
|
},
|
|
72
73
|
},
|
|
73
|
-
// Composio's (docs.composio.dev webhooks, @composio/core's verifyWebhook)
|
|
74
|
-
// ("{id}.{timestamp}.{body}", `v1,<base64 HMAC-SHA256>`), but keyed by the UTF-8
|
|
75
|
-
// Composio minted, not by a base64-decoded `whsec_` key.
|
|
76
|
-
// the event is the body's metadata.trigger_slug, and `where`
|
|
74
|
+
// Composio's (docs.composio.dev webhooks, @composio/core's verifyWebhook), for a Composio trigger's deliveries alone: the
|
|
75
|
+
// Standard Webhooks headers and message ("{id}.{timestamp}.{body}", `v1,<base64 HMAC-SHA256>`), but keyed by the UTF-8
|
|
76
|
+
// bytes of the whole secret string Composio minted for the project's subscription, not by a base64-decoded `whsec_` key.
|
|
77
|
+
// Every event of the project comes to its one route, so the event is the body's metadata.trigger_slug, and `where`
|
|
78
|
+
// reads the trigger's own data under /data.
|
|
77
79
|
composio: {
|
|
78
80
|
signatureHeader: "webhook-signature",
|
|
79
|
-
|
|
80
|
-
describe: `\`composio\` takes a Composio trigger's delivery (the webhook subscription whose URL is the trigger's hook_url): the Standard Webhooks headers and message, \`v1,<base64 HMAC-SHA256 of "{webhook-id}.{webhook-timestamp}.{body}">\`, keyed by the UTF-8 bytes of the whole secret string Composio gave the subscription (make the trigger first, register its hook_url as Composio's webhook subscription, then \`POST /v2/triggers/{id}/secret\` with \`{secret}\`; until then every request is refused, and this server never makes one), with the same ${HOOK_TOLERANCE_S} s window and firing key (\`webhook-id\`). Its event is the body's \`metadata.trigger_slug\` (\`GITHUB_ISSUE_ADDED_EVENT\`), else its top-level \`type\` (the subscription's account events, \`composio.connected_account.expired\`), and \`where\` pointers read the payload under \`/data\`.`,
|
|
81
|
+
describe: `\`composio\` takes a Composio project's delivery to a Composio trigger's route (/hooks/composio/{hook}): the Standard Webhooks headers and message, \`v1,<base64 HMAC-SHA256 of "{webhook-id}.{webhook-timestamp}.{body}">\`, keyed by the UTF-8 bytes of the whole secret string Composio made for the project's subscription (this server makes the subscription and keeps its secret sealed), with the same ${HOOK_TOLERANCE_S} s window and firing key (\`webhook-id\`). Its event is the body's \`metadata.trigger_slug\` (\`GITHUB_ISSUE_ADDED_EVENT\`), else its top-level \`type\` (the subscription's account events, \`composio.connected_account.expired\`), and \`where\` pointers read the payload under \`/data\`.`,
|
|
81
82
|
precheck: headersRefusal,
|
|
82
83
|
verify: (key, headers, body, nowMs) => verifyWithKey(Buffer.from(key, "utf8"), headers, body, nowMs),
|
|
83
84
|
firingKeyOf: (headers) => headers["webhook-id"],
|
|
@@ -98,13 +99,12 @@ export const SIGNATURE_SCHEMES = {
|
|
|
98
99
|
},
|
|
99
100
|
},
|
|
100
101
|
};
|
|
101
|
-
|
|
102
|
+
/** The schemes a webhook trigger's `signature` may name: every one but `composio`, a Composio trigger's. */
|
|
103
|
+
export const SCHEME_NAMES = ["standard", "github"];
|
|
102
104
|
export const DEFAULT_SCHEME = "standard";
|
|
103
|
-
/** The scheme a request asks for: the one whose signature header it carries.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* read, where the headers' check is the same for both) the first of them stands in. `refusal` when it carries no
|
|
107
|
-
* signature header, or the headers of more than one. */
|
|
105
|
+
/** The webhook scheme a request asks for: the one of SCHEME_NAMES whose signature header it carries. Were two to share a
|
|
106
|
+
* header, the trigger's own (`wanted`, its `signature`) would pick, and with no `wanted` (before the trigger is read) the
|
|
107
|
+
* first of them. `refusal` when it carries no signature header, or the headers of more than one. */
|
|
108
108
|
export function schemeOf(headers, wanted) {
|
|
109
109
|
const carried = SCHEME_NAMES.filter((name) => headers[SIGNATURE_SCHEMES[name].signatureHeader] !== undefined);
|
|
110
110
|
const byHeader = new Set(carried.map((name) => SIGNATURE_SCHEMES[name].signatureHeader));
|
|
@@ -40,7 +40,7 @@ export type TriggerTargets = {
|
|
|
40
40
|
targetIssues(target: Target): Promise<InputIssue[]>;
|
|
41
41
|
start(target: Extract<Target, {
|
|
42
42
|
kind: "start_run";
|
|
43
|
-
}>, input: Json, origin: RunTrigger, from: MessageOrigin, title?: string): Promise<{
|
|
43
|
+
}>, input: Json, origin: RunTrigger, from: MessageOrigin, title?: string, previous?: boolean): Promise<{
|
|
44
44
|
run_id: string;
|
|
45
45
|
}>;
|
|
46
46
|
message(target: Extract<Target, {
|
package/dist/trigger-targets.js
CHANGED
|
@@ -61,13 +61,14 @@ export function triggerTargets(store, deps) {
|
|
|
61
61
|
const wrong = revision ? await deps.start.explainRun(await deps.start.inputIssuesOf(revision, target.input), { input: target.input }, revision) : [];
|
|
62
62
|
return [...uncapped, ...wrong.map((issue) => ({ ...issue, field: `target.${issue.field}` }))];
|
|
63
63
|
},
|
|
64
|
-
async start(target, given, trigger, from, title) {
|
|
64
|
+
async start(target, given, trigger, from, title, previous = true) {
|
|
65
65
|
const entry = await deps.needAgent(target.agent_id);
|
|
66
66
|
// An agentic run is handed its trigger's previous result after its message (previousResultOf), so a repeat run
|
|
67
67
|
// (a weekly digest) leaves out what the last one reported. A workflow's input is its own schema's: nothing is added.
|
|
68
|
+
// A source whose firings are different people's (an email's sender: its adapter's previousResult false) hands none.
|
|
68
69
|
const content = given.content;
|
|
69
|
-
const
|
|
70
|
-
const input =
|
|
70
|
+
const handed = previous && entry.revision?.kind === "agentic" && typeof content === "string" ? await previousResultOf(store, deps, trigger) : "";
|
|
71
|
+
const input = handed ? { ...given, content: `${content}${handed}` } : given;
|
|
71
72
|
// The target's cap, else the agent's default as it stands now: a run a trigger starts is never uncapped (capped).
|
|
72
73
|
const run = await startRun(store, deps.start, entry, { input, ...(target.max_cost_usd !== undefined ? { max_cost_usd: target.max_cost_usd } : {}), ...(target.effort ? { effort: target.effort } : {}) },
|
|
73
74
|
// Titled from the trigger (the engine's titleOf: "<Source> <name>"), never from its input, a sender's markup.
|
package/dist/trigger-webhook.js
CHANGED
|
@@ -12,12 +12,15 @@ import { isObject } from "./validate.js";
|
|
|
12
12
|
const ATTR_CHARS = 200;
|
|
13
13
|
/** The scheme a trigger's source takes. */
|
|
14
14
|
const schemeName = (source) => (typeof source.signature === "string" ? source.signature : DEFAULT_SCHEME);
|
|
15
|
-
/** Whether a source's secret is the sender's own (Composio's): given, not minted. */
|
|
16
|
-
const givesSecret = (source) => SIGNATURE_SCHEMES[schemeName(source)]?.givenSecret === true;
|
|
17
15
|
/** The source's own fields, checked: each issue through `bad`. Undefined when one does not read. */
|
|
18
16
|
function fieldsOf(value, bad) {
|
|
19
17
|
let failed = false;
|
|
20
|
-
if (value.signature
|
|
18
|
+
if (value.signature === "composio") {
|
|
19
|
+
// Composio's events start runs through a Composio trigger, whose project subscription this server makes and keeps.
|
|
20
|
+
failed = true;
|
|
21
|
+
bad("signature", "not_an_option", `A webhook trigger takes no composio signature: make a Composio trigger instead, in the console's Triggers → New app trigger (source kind "composio"). signature is one of ${SCHEME_NAMES.join(", ")} (default ${DEFAULT_SCHEME}).`);
|
|
22
|
+
}
|
|
23
|
+
else if (value.signature !== undefined && !SCHEME_NAMES.includes(value.signature)) {
|
|
21
24
|
failed = true;
|
|
22
25
|
bad("signature", "not_an_option", `signature is one of ${SCHEME_NAMES.join(", ")} (default ${DEFAULT_SCHEME})`);
|
|
23
26
|
}
|
|
@@ -40,7 +43,6 @@ export const webhook = {
|
|
|
40
43
|
delivery: "push",
|
|
41
44
|
owner: false,
|
|
42
45
|
settings: { scope: "trigger", fields: { secret: { mint: true, minBytes: MIN_KEY_BYTES } } },
|
|
43
|
-
givesSecret,
|
|
44
46
|
describe: `{kind: "webhook", signature?: ${SCHEME_NAMES.map((name) => `"${name}"`).join(" | ")}, accept?: [{event, actions?, where?}]}`,
|
|
45
47
|
fires: "a signed request to /hooks/{trigger_id} (`webhook`) that its `accept` takes",
|
|
46
48
|
firedBy: "`webhook`: a signed request to /hooks/{trigger_id}, its key from the trigger and what the request's signature covers: its `webhook-id` (`standard`), or the SHA-256 of its body (`github`).",
|