@desplega.ai/agent-swarm 2.13.0 → 2.13.1
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/dist/acp-adapter-xtj40wd8.js +17 -0
- package/dist/{acp-targets-86f0sh6g.js → acp-targets-n7vm5atw.js} +10 -10
- package/dist/{actions-zv8vcxvr.js → actions-hq6wp9xv.js} +27 -27
- package/dist/{agent-fs-provision-jqshb33y.js → agent-fs-provision-y0qc1rdd.js} +4 -4
- package/dist/{amp-adapter-gt503ywc.js → amp-adapter-1qqs6h91.js} +3 -3
- package/dist/{app-6t4k5rh1.js → app-7m4z44rv.js} +10 -10
- package/dist/{approval-notifications-fcfw063h.js → approval-notifications-8sr41gjx.js} +11 -11
- package/dist/{assistant-9dzybh12.js → assistant-hkczwfv6.js} +28 -28
- package/dist/{boot-args-schema-xzfp2feg.js → boot-args-schema-8025snev.js} +1 -1
- package/dist/{boot-reembed-r88wngfg.js → boot-reembed-15m87nr1.js} +1 -1
- package/dist/{boot-reembed-3jz0p2jk.js → boot-reembed-4bbpxjh1.js} +1 -1
- package/dist/{boot-scrub-sweep-scrqhw48.js → boot-scrub-sweep-eajr97e9.js} +2 -2
- package/dist/{boot-seeds-vb2dcrrb.js → boot-seeds-9cwy39jx.js} +4 -4
- package/dist/{boxd-68n75y1s.js → boxd-hr8rsxzq.js} +1 -1
- package/dist/{claude-adapter-h3mp9hgs.js → claude-adapter-g61wa4rt.js} +9 -9
- package/dist/{claude-managed-adapter-kpbyj2vb.js → claude-managed-adapter-znkk0prm.js} +3 -3
- package/dist/{claude-managed-setup-0efr3wkg.js → claude-managed-setup-f1wndkr2.js} +2 -2
- package/dist/{claude-sdk-session-03dw669q.js → claude-sdk-session-687xzf21.js} +20763 -19381
- package/dist/{cli-gfcv679k.js → cli-04103ryh.js} +1 -1
- package/dist/{cli-hbq0kwxz.js → cli-0a336ze7.js} +4 -4
- package/dist/{cli-1v82d2w6.js → cli-0fx95c06.js} +4 -4
- package/dist/{cli-wxwv3t11.js → cli-0m77n7ej.js} +3 -3
- package/dist/{cli-j53hpbsm.js → cli-0xwb7zpt.js} +2 -2
- package/dist/{cli-0dg7ytxm.js → cli-13t0smbk.js} +917 -23
- package/dist/{cli-0pazkmd4.js → cli-1b5axkt1.js} +4 -4
- package/dist/{cli-6h88mn9q.js → cli-1carhg8g.js} +4 -4
- package/dist/{cli-hgsxnjyg.js → cli-1dr5at77.js} +10 -10
- package/dist/{cli-0jkenasr.js → cli-2v4xxnx2.js} +1 -1
- package/dist/{cli-dnh64e8e.js → cli-32xndx6b.js} +6 -6
- package/dist/{cli-hpb9x72z.js → cli-3m8vqehw.js} +9 -9
- package/dist/{cli-ercwc8xn.js → cli-3mf04tkh.js} +1 -1
- package/dist/{cli-7dbhnsj9.js → cli-3zyme1wt.js} +4 -4
- package/dist/{cli-s6zk31gr.js → cli-43dsqhcp.js} +4 -4
- package/dist/{cli-t35hx078.js → cli-4h90xaet.js} +2 -2
- package/dist/{cli-117g15t4.js → cli-4mj5g29m.js} +8 -8
- package/dist/{cli-47hz21se.js → cli-4tbvndmm.js} +4 -5
- package/dist/{cli-tn91wc6e.js → cli-50whymxq.js} +1 -1
- package/dist/{cli-js10kdk7.js → cli-5basv0e7.js} +19 -5
- package/dist/{cli-xfjn2kyq.js → cli-5v6b2am8.js} +5 -5
- package/dist/{cli-49f5jyhh.js → cli-6r1dwegd.js} +3 -3
- package/dist/{cli-kspxjftk.js → cli-7ewre3dm.js} +15 -6
- package/dist/{cli-n3qe7tyr.js → cli-84xtgbn6.js} +35 -2
- package/dist/{cli-w14j2z4k.js → cli-8cmjkbvj.js} +2 -2
- package/dist/{cli-2m6yaq6b.js → cli-8fj8yfmk.js} +1 -1
- package/dist/{cli-9m9kyw77.js → cli-8rbkw18r.js} +2 -2
- package/dist/{cli-x05p2d05.js → cli-9tevdxyf.js} +1 -1
- package/dist/{cli-f1952kjy.js → cli-9xx36trj.js} +4 -4
- package/dist/{cli-hc6e4tac.js → cli-a8ts6x1n.js} +6 -6
- package/dist/{cli-mh7pdxe0.js → cli-aebswqmz.js} +12 -12
- package/dist/{cli-ex1y88j3.js → cli-at67kvnp.js} +1 -1
- package/dist/{cli-b2jh3dyb.js → cli-bjmq14k9.js} +4 -4
- package/dist/{cli-mz34pxbk.js → cli-byxsctca.js} +11 -11
- package/dist/{cli-dka73bak.js → cli-c0tyzt73.js} +152 -12
- package/dist/{cli-wv20kbr3.js → cli-c8kqmzzf.js} +5 -5
- package/dist/{cli-qhhb30e8.js → cli-cd9acnvd.js} +9 -9
- package/dist/{cli-wndegmns.js → cli-cmgdptmx.js} +3 -3
- package/dist/{cli-1dbv9mj9.js → cli-cn6fpa1p.js} +1 -1
- package/dist/{cli-wrhbym01.js → cli-cp0m07wb.js} +6 -6
- package/dist/{cli-3p288654.js → cli-cpkxh68d.js} +2 -2
- package/dist/{cli-g6j6ac3h.js → cli-cqxwjb93.js} +2 -2
- package/dist/{cli-8hp56wat.js → cli-d2epqm0y.js} +1 -1
- package/dist/{cli-qm3ntjqs.js → cli-dd57p1gd.js} +13 -13
- package/dist/{cli-tstj6e8e.js → cli-fn8aj7gb.js} +250 -55
- package/dist/{cli-bpje8n65.js → cli-fp65jdp2.js} +31 -6
- package/dist/{cli-2skf1mdf.js → cli-gedf48yw.js} +4 -4
- package/dist/{cli-c8v2yvej.js → cli-gq6qhmrr.js} +2 -2
- package/dist/{cli-sq913bh1.js → cli-grcc2h2g.js} +8 -8
- package/dist/{cli-qec9bynj.js → cli-h03j6je3.js} +3 -3
- package/dist/{cli-mbwmqb5w.js → cli-h0ewec3d.js} +1 -1
- package/dist/{cli-jj3c5nyb.js → cli-h9bejmkf.js} +76 -39
- package/dist/{cli-ct8sz3np.js → cli-hs3mqswp.js} +6 -6
- package/dist/{cli-tdk7jtka.js → cli-hv3820ez.js} +1 -1
- package/dist/{cli-pqfecppn.js → cli-je587f74.js} +1 -1
- package/dist/{cli-y4a4458j.js → cli-jhtvt7gn.js} +3 -3
- package/dist/{cli-dkejt425.js → cli-mmw2sjaf.js} +7 -7
- package/dist/{cli-50w82h6m.js → cli-mwxez0pz.js} +1 -0
- package/dist/{cli-avxh26pd.js → cli-nk8swfpx.js} +4 -4
- package/dist/{cli-fhvk2nvp.js → cli-p7g7wd9n.js} +9 -9
- package/dist/{cli-bhgrhedp.js → cli-q8aq48v1.js} +1 -1
- package/dist/{cli-6a40p4kv.js → cli-qn79645p.js} +1 -1
- package/dist/{cli-nc6a8b5b.js → cli-qx1dwrr5.js} +2 -2
- package/dist/{cli-sdh61g52.js → cli-s6fhqbz1.js} +2 -2
- package/dist/{cli-eb279wn3.js → cli-sfajkbd7.js} +2 -2
- package/dist/{cli-z64t9pe6.js → cli-snypfjgj.js} +1 -1
- package/dist/{cli-ytc7fpza.js → cli-t25rq8mg.js} +4 -4
- package/dist/{cli-zqmmy073.js → cli-t90k0phh.js} +18 -18
- package/dist/{cli-fz9pcjsw.js → cli-tzzas8rb.js} +4 -4
- package/dist/{cli-rtmqzat7.js → cli-vdfngx2g.js} +2 -2
- package/dist/{cli-9w8712tq.js → cli-vr4eyq6p.js} +43 -14
- package/dist/{cli-z4f346g5.js → cli-vx9acp12.js} +1 -1
- package/dist/{cli-y518qkjg.js → cli-w24f3j49.js} +10 -10
- package/dist/{cli-yn4kt85g.js → cli-w41bvvms.js} +1 -1
- package/dist/{cli-9fsagra4.js → cli-w6c6dj91.js} +1 -1
- package/dist/{cli-kde4ky90.js → cli-x5yb8zc8.js} +2 -2
- package/dist/{cli-48nvk6sb.js → cli-xhkek467.js} +2 -2
- package/dist/{cli-avqkr20b.js → cli-y6qqbpwc.js} +2 -2
- package/dist/{cli-7wy8gbwb.js → cli-ya1cj689.js} +1 -1
- package/dist/{cli-prf7kz78.js → cli-yeh3g1q6.js} +603 -78
- package/dist/{cli-ajjvqhf3.js → cli-z6m6xzxt.js} +2 -2
- package/dist/{cli-2jk4s7z1.js → cli-zaate0rd.js} +3 -3
- package/dist/{cli-n85m2wkq.js → cli-zkbz8m2q.js} +3 -2
- package/dist/{cli-0b655smz.js → cli-zvpkrgsc.js} +5 -5
- package/dist/cli.js +27 -27
- package/dist/{codex-adapter-f3yp0kaj.js → codex-adapter-ysfg6ty3.js} +8 -8
- package/dist/{codex-hook-262cekfp.js → codex-hook-c0nvm30r.js} +2 -2
- package/dist/{codex-login-1ven7yje.js → codex-login-ven5cz5j.js} +1 -1
- package/dist/{codex-session-runner-ns4mv70p.js → codex-session-runner-823scr6g.js} +9 -9
- package/dist/{commands-5bzf2tfw.js → commands-5rbm07fz.js} +3 -3
- package/dist/{controller-5xt7kvfm.js → controller-wn3vd217.js} +3 -3
- package/dist/{controllers-connect-0gg13mzp.js → controllers-connect-34jzhfft.js} +28 -28
- package/dist/core-kdehq26g.js +42 -0
- package/dist/{cursor-adapter-p0c5zv6r.js → cursor-adapter-w1681kp1.js} +2 -2
- package/dist/{db-2s68ycq7.js → db-6bkgbfwk.js} +3 -3
- package/dist/{db-q7q639k5.js → db-hcj16x7z.js} +2 -2
- package/dist/{devin-adapter-t8d86q9x.js → devin-adapter-fs90ab4v.js} +1 -1
- package/dist/{dispatcher-j2y1q7ae.js → dispatcher-jgjqrfzv.js} +25 -25
- package/dist/{docker-1b41eysj.js → docker-1h33jvh9.js} +2 -2
- package/dist/{dsh-adapter-pgnkf4st.js → dsh-adapter-g9yqv09y.js} +2 -2
- package/dist/{e2b-xm60c8ad.js → e2b-jnk0yeva.js} +2 -2
- package/dist/{e2b-ew8c5j5v.js → e2b-y7e5kmzf.js} +2 -2
- package/dist/{easter-egg-3d-0kea97jf.js → easter-egg-3d-w17nsny6.js} +1 -1
- package/dist/{embedding-space-3n6mhhmy.js → embedding-space-v06fwy7b.js} +6 -6
- package/dist/{embeddings-jfmj6yme.js → embeddings-g50dxea4.js} +1 -1
- package/dist/{event-bus-v4ywhc2p.js → event-bus-08t2b4y2.js} +1 -1
- package/dist/{execute-tjrej979.js → execute-1n36haw1.js} +1 -1
- package/dist/{external-channel-jy8w2gg3.js → external-channel-43tv8pg6.js} +2 -2
- package/dist/fx-adapter-bvh05t4a.js +20 -0
- package/dist/grok-adapter-my5j8mdf.js +20 -0
- package/dist/handlers-wyymeeqh.js +41 -0
- package/dist/heartbeat-sf3nk937.js +50 -0
- package/dist/{hook-bpnncsec.js → hook-dqph1e05.js} +8 -8
- package/dist/{hook-fv1jwrv7.js → hook-m1m9dm6w.js} +6 -6
- package/dist/{http-bpa26czn.js → http-w0th1cz9.js} +160 -102
- package/dist/index-22khdtby.js +44 -0
- package/dist/{index-mpj0z9e0.js → index-c0e8en64.js} +1 -1
- package/dist/{index-620y7jzq.js → index-e8pz8qdg.js} +3 -3
- package/dist/{index-8p0j4h4j.js → index-ez823q84.js} +94 -89
- package/dist/{index-w216g9y9.js → index-ffba0z8q.js} +35 -21
- package/dist/{index-s8re7mvq.js → index-gkpfgpg7.js} +1 -1
- package/dist/{index-4k7m5dgj.js → index-k8ajc0g0.js} +143 -103
- package/dist/index-np0582ac.js +40 -0
- package/dist/{index-52tgbhrw.js → index-pb03vans.js} +28 -28
- package/dist/index-vgkrj1jt.js +39 -0
- package/dist/{index-pe3d8jfy.js → index-whysn1wf.js} +1 -1
- package/dist/{index-0h6qd4p1.js → index-y4vd4mhn.js} +3 -4
- package/dist/{k8s-fy8hbhkg.js → k8s-8326q0rq.js} +2 -2
- package/dist/{keepalive-d6z12s04.js → keepalive-2v06q2e8.js} +5 -4
- package/dist/lead-55z813ng.js +79 -0
- package/dist/{maintenance-7kac6g2g.js → maintenance-vx7vjhhy.js} +1 -1
- package/dist/{oauth-refresh-sweep-t1xjetbh.js → oauth-refresh-sweep-g06k4bza.js} +4 -3
- package/dist/{object-webhooks-6rdagg0r.js → object-webhooks-3dzdq4fm.js} +7 -7
- package/dist/{onboard-32y1cfxy.js → onboard-232pazny.js} +4 -4
- package/dist/{opencode-adapter-enp3v31n.js → opencode-adapter-t0paqbh8.js} +8 -8
- package/dist/{otel-impl-k0tm5ptj.js → otel-impl-kmpkyp4y.js} +2 -2
- package/dist/{pending-24zebgvs.js → pending-x0z3vx1x.js} +26 -26
- package/dist/{pi-mono-adapter-yj72xxxe.js → pi-mono-adapter-7pmypn6d.js} +17 -15
- package/dist/{pricing-refresh-cf25x38j.js → pricing-refresh-ytjmtyd7.js} +2 -2
- package/dist/{rbac-roles-0wydd22m.js → rbac-roles-fgm5mxr2.js} +3 -3
- package/dist/{rbac-roles-at6crb3r.js → rbac-roles-xyaxekh3.js} +2 -2
- package/dist/{render-v2-nvcw0jd7.js → render-v2-ws972g4r.js} +10 -10
- package/dist/{resume-y4w0k5v3.js → resume-m6mjzhkp.js} +13 -13
- package/dist/{runtime-vpe43hx0.js → runtime-zzpc0c8a.js} +1 -1
- package/dist/{session-access-gkyvnfye.js → session-access-vp35xs91.js} +5 -5
- package/dist/{session-source-backfill-3w2st4m2.js → session-source-backfill-p73e8zbe.js} +2 -2
- package/dist/{setup-axxvqtys.js → setup-r4kd7rxg.js} +1 -1
- package/dist/thread-buffer-cm2nzq6t.js +42 -0
- package/dist/{tree-visibility-y4fqvab5.js → tree-visibility-07h2tbs2.js} +2 -2
- package/dist/{user-merge-jobs-kcmwvrc6.js → user-merge-jobs-96vg9rpe.js} +3 -3
- package/dist/{virtual-modules-7d92dct1.js → virtual-modules-vgn3f2x4.js} +3 -3
- package/dist/{work-objects-f708e069.js → work-objects-74hbcx3e.js} +28 -28
- package/dist/worker-5pn2vzx6.js +79 -0
- package/dist/{worker-follow-up-0by8wztc.js → worker-follow-up-ezavwn5d.js} +25 -25
- package/dist/{x-3dtaf2r9.js → x-asbrnafg.js} +2 -2
- package/openapi.json +1793 -1622
- package/package.json +10 -10
- package/src/apps/catalog.generated.json +726 -0
- package/src/apps/definition.ts +24 -7
- package/src/apps/page-validator.ts +225 -3
- package/src/be/db.ts +38 -10
- package/src/be/mcp-proxy.ts +5 -4
- package/src/be/migrations/340_api_key_spend_cap.sql +5 -0
- package/src/be/schedules/validate.ts +26 -0
- package/src/be/swarm-config-guard.ts +4 -0
- package/src/commands/credential-outcome-report.ts +5 -2
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-credentials.ts +19 -0
- package/src/commands/provider-error-class.ts +4 -1
- package/src/commands/rate-limit-outcome.ts +48 -3
- package/src/commands/runner.ts +113 -55
- package/src/commands/worktree-reaper.ts +600 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/agents.ts +4 -0
- package/src/http/api-keys.ts +27 -3
- package/src/http/pages-public.ts +40 -4
- package/src/http/pool-keys.ts +21 -2
- package/src/http/schedules.ts +28 -3
- package/src/http/script-connections.ts +12 -4
- package/src/http/script-runs.ts +12 -3
- package/src/http/tasks.ts +6 -10
- package/src/mcp-client/http-client.ts +3 -1
- package/src/oauth/identity-capture.ts +6 -1
- package/src/oauth/mcp-wrapper.ts +10 -3
- package/src/oauth/wrapper.ts +15 -3
- package/src/prompts/session-templates.ts +1 -0
- package/src/providers/acp-targets.ts +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/dsh-adapter.ts +1 -1
- package/src/providers/pi-mono-adapter.ts +4 -2
- package/src/providers/runtime-dependencies.ts +1 -1
- package/src/rbac/legacy-policy.ts +2 -0
- package/src/rbac/permissions.ts +5 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +7 -7
- package/src/slack/enrich.ts +14 -11
- package/src/tests/agents-list-model-display.test.ts +23 -0
- package/src/tests/apps-spike2.test.ts +35 -0
- package/src/tests/base-prompt.test.ts +1 -0
- package/src/tests/deploy-guard.test.ts +24 -0
- package/src/tests/dsh-adapter.test.ts +1 -1
- package/src/tests/ensure-token.test.ts +2 -2
- package/src/tests/entrypoint-repo-autoclone-args.test.ts +202 -0
- package/src/tests/fake-dns.ts +47 -0
- package/src/tests/fixtures/base-prompt-baseline.json +12 -12
- package/src/tests/latest-model-report.test.ts +138 -0
- package/src/tests/mcp-oauth-dcr-reuse.test.ts +5 -2
- package/src/tests/mcp-oauth-ensure-token.test.ts +3 -2
- package/src/tests/mcp-oauth-manual-client.test.ts +6 -1
- package/src/tests/mcp-oauth-wrapper.test.ts +20 -4
- package/src/tests/mcp-outbound-fetch-guard.test.ts +169 -0
- package/src/tests/mcp-server-ssrf.test.ts +2 -0
- package/src/tests/memory-search-stall.test.ts +5 -0
- package/src/tests/oauth-connection-fetch-guard.test.ts +162 -0
- package/src/tests/oauth-token-endpoint-fetch-guard.test.ts +121 -0
- package/src/tests/oauth-wrapper.test.ts +1 -2
- package/src/tests/pages-head-v2.test.ts +2 -1
- package/src/tests/script-connections-http.test.ts +8 -3
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/slack-thread-participants.test.ts +14 -3
- package/src/tests/spend-cap-credentials.test.ts +34 -0
- package/src/tests/spend-cap-outcome.test.ts +67 -0
- package/src/tests/subscription-first.test.ts +119 -0
- package/src/tests/worktree-reaper.test.ts +424 -0
- package/src/tools/get-task-details.ts +247 -5
- package/src/tools/schedules/patch-schedule.ts +26 -1
- package/src/tools/schedules/update-schedule.ts +28 -2
- package/src/utils/credentials.ts +36 -1
- package/src/utils/egress-guard.ts +40 -10
- package/src/utils/error-tracker.ts +17 -0
- package/templates/skills/apps/SKILL.md +191 -2
- package/templates/skills/apps/content.md +191 -2
- package/templates/skills/boards-and-sheets/content.md +11 -0
- package/templates/skills/pages/content.md +11 -0
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +1 -0
- package/templates/skills/swarm-scripts/content.md +1 -0
- package/templates/workflows/ralph-loop/content.md +6 -6
- package/dist/acp-adapter-cn53011z.js +0 -17
- package/dist/cli-pr0eze3x.js +0 -149
- package/dist/core-0fqtbrxa.js +0 -42
- package/dist/fx-adapter-k6w3jvz9.js +0 -20
- package/dist/grok-adapter-4q5tssw0.js +0 -20
- package/dist/handlers-qxgfvvsf.js +0 -41
- package/dist/heartbeat-6tr2w2da.js +0 -50
- package/dist/index-0mcxjdsa.js +0 -44
- package/dist/index-dz4q23ag.js +0 -40
- package/dist/index-s175jckx.js +0 -39
- package/dist/lead-p3hx7h35.js +0 -79
- package/dist/thread-buffer-rwa7d4dx.js +0 -42
- package/dist/worker-8rg9gz74.js +0 -79
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Generated by scripts/bundle-extension-types.ts. Do not edit.
|
|
2
2
|
// biome-ignore-all lint/suspicious/noTemplateCurlyInString: Type declarations contain literal template placeholders.
|
|
3
3
|
export const EXTENSION_TYPE_DEFINITIONS =
|
|
4
|
-
'// biome-ignore-all lint/suspicious/noConfusingVoidType: Extension handlers may explicitly return no result.\ndeclare module "swarm-extension" {\n export type CreateTaskOptions = {\n key?: string | undefined;\n agentId?: string | null | undefined;\n creatorAgentId?: string | undefined;\n source?:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb"\n | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n taskType?: string | undefined;\n tags?: string[] | undefined;\n priority?: number | undefined;\n dependsOn?: string[] | undefined;\n offeredTo?: string | undefined;\n status?: "draft" | "backlog" | "unassigned" | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n overrideSlackContext?: boolean | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | undefined;\n workflowRunStepId?: string | undefined;\n sourceTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n inheritParentOutputSchema?: boolean | undefined;\n inheritParentRequester?: boolean | undefined;\n inheritParentRoutingAffinity?: boolean | undefined;\n inheritParentFollowUpConfig?: boolean | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n requestedByUserId?: string | undefined;\n contextKey?: string | undefined;\n bypassTrackerContextDedup?: boolean | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n };\n\n export type AgentTask = {\n id: string;\n key: string;\n agentId: string | null;\n task: string;\n status:\n | "skipped"\n | "draft"\n | "backlog"\n | "unassigned"\n | "offered"\n | "reviewing"\n | "pending"\n | "in_progress"\n | "paused"\n | "completed"\n | "failed"\n | "cancelled"\n | "superseded";\n source:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb";\n tags: string[];\n priority: number;\n dependsOn: string[];\n createdAt: string;\n lastUpdatedAt: string;\n slackReplySent: boolean;\n wasPaused: boolean;\n creatorAgentId?: string | undefined;\n title?: string | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n poolWakeAt?: string | undefined;\n taskType?: string | undefined;\n offeredTo?: string | undefined;\n offeredAt?: string | undefined;\n acceptedAt?: string | undefined;\n rejectionReason?: string | undefined;\n finishedAt?: string | undefined;\n notifiedAt?: string | undefined;\n failureReason?: string | undefined;\n output?: string | undefined;\n progress?: string | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n slackProgressMessageTs?: string | undefined;\n slackTreeRootMessageTs?: string | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n claudeSessionId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n resolvedModel?: string | undefined;\n modelSource?: string | undefined;\n modelAlias?: string | undefined;\n resolvedEffort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n resolvedProfile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | null | undefined;\n workflowRunStepId?: string | null | undefined;\n contextKey?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n deferredAt?: string | undefined;\n compactionCount?: number | undefined;\n peakContextPercent?: number | undefined;\n peakContextTokens?: number | undefined;\n contextWindowSize?: number | undefined;\n credentialKeySuffix?: string | undefined;\n credentialKeyType?: string | undefined;\n requestedByUserId?: string | undefined;\n swarmVersion?: string | undefined;\n provider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n providerMeta?: Record<string, unknown> | undefined;\n harnessVariant?: string | undefined;\n harnessVariantMeta?: Record<string, unknown> | undefined;\n totalCostUsd?: number | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "pi"\n | "claude"\n | "claude-managed"\n | "codex"\n | "grok"\n | "fx"\n | "opencode"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n routingAffinityInvalid?: boolean | undefined;\n };\n\n export type ActiveSession = {\n id: string;\n agentId: string;\n taskId: string | null;\n triggerType: string;\n inboxMessageId: string | null;\n taskDescription: string | null;\n runnerSessionId: string | null;\n providerSessionId: string | null;\n startedAt: string;\n lastHeartbeatAt: string;\n runtimeInstanceId?: string | null | undefined;\n };\n\n export type SteerMode = "steer" | "queue";\n\n export type SteeringSource = "chat" | "script" | "slack" | "mcp" | "api" | "ui" | "app-page";\n\n export type RequestInfo = {\n sessionId: string | undefined;\n agentId: string | undefined;\n runtimeInstanceId: string | undefined;\n sourceTaskId: string | undefined;\n auditSourceTaskId: string | undefined;\n contextKey: string | undefined;\n callOrigin: "mcp" | "native" | "extension" | "script-sdk";\n harness?: string | undefined;\n };\n\n import type { SwarmSdk } from "swarm-sdk";\n import type { z } from "zod";\n export type Runtime = "api" | "worker";\n export interface ExtensionScriptAsset {\n name: string;\n file: string;\n description: string;\n intent?: string;\n }\n export interface ExtensionScheduleAsset {\n name: string;\n description?: string;\n script: string;\n cronExpression?: string;\n intervalMs?: number;\n timezone?: string;\n args?: Record<string, unknown>;\n }\n export interface ExtensionWorkflowAsset {\n file: string;\n }\n export interface ExtensionSkillAsset {\n dir: string;\n }\n export interface ExtensionManifest {\n $schema?: string;\n name: string;\n description: string;\n version: string;\n runtime: Runtime;\n assets: {\n hooks: string;\n scripts?: readonly ExtensionScriptAsset[];\n schedules?: readonly ExtensionScheduleAsset[];\n workflows?: readonly ExtensionWorkflowAsset[];\n skills?: readonly ExtensionSkillAsset[];\n };\n homepage?: string;\n author?: string;\n /** Tool-call sources this extension\'s tool handlers receive. Default `["mcp"]`. */\n toolSources?: readonly ToolSource[];\n }\n /** `mcp`: swarm MCP tools. `native`: harness built-ins reported by a worker shim. */\n export type ToolSource = "mcp" | "native";\n export interface HooksModule {\n default: SwarmExtension;\n config?: z.ZodTypeAny;\n }\n export interface ExtensionState {\n get<T = unknown>(key: string): Promise<T | null>;\n set<T>(key: string, value: T): Promise<void>;\n incr(key: string, by?: number): Promise<number>;\n del(key: string): Promise<void>;\n }\n export interface ExtensionLogger {\n debug(message: string, data?: unknown): void;\n info(message: string, data?: unknown): void;\n warn(message: string, data?: unknown): void;\n error(message: string, data?: unknown): void;\n }\n type ConfigFor<M extends ExtensionManifest> = M extends {\n config: infer C extends z.ZodTypeAny;\n }\n ? z.infer<C>\n : Record<string, unknown>;\n export interface ApiCtx<Config = Record<string, unknown>> {\n swarm: SwarmSdk;\n state: ExtensionState;\n config: Config;\n log: ExtensionLogger;\n signal: AbortSignal;\n event: {\n name: keyof SwarmEventMap;\n at: string;\n extension: {\n id: string;\n version: number;\n };\n };\n }\n export interface WorkerCtx<Config = Record<string, unknown>>\n extends Omit<ApiCtx<Config>, "swarm"> {\n swarm: SwarmSdk;\n worker: {\n agentId: string;\n taskId: string;\n harness: string;\n };\n }\n export type CtxFor<M extends ExtensionManifest> = M["runtime"] extends "api"\n ? ApiCtx<ConfigFor<M>>\n : WorkerCtx<ConfigFor<M>>;\n export type PreResult<Modify> =\n | void\n | {\n action: "continue";\n }\n | {\n action: "modify";\n data: Modify;\n }\n | {\n action: "block";\n reason: string;\n };\n export type TaskCreateOrigin =\n | "rest"\n | "app"\n | "mcp"\n | "slack"\n | "schedule"\n | "workflow"\n | "webhook"\n | "followUp"\n | `extension:${string}`;\n export interface TaskCreateEvent {\n options: CreateTaskOptions;\n description: string;\n origin: TaskCreateOrigin;\n requestInfo?: RequestInfo;\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n trigger: "mention" | "thread-buffer";\n messages: {\n ts: string;\n userId: string;\n text: string;\n }[];\n };\n }\n /** A pre.task.create hook blocked a task before it was created. */\n export interface TaskBlockedEvent {\n /** The extension that blocked, or whose model/agent rewrite was rejected. */\n extension: {\n id: string;\n name: string;\n };\n /** The scrubbed block reason. */\n reason: string;\n origin: TaskCreateOrigin;\n source?: AgentTask["source"];\n requester: {\n userId?: string;\n agentId?: string;\n slackUserId?: string;\n };\n context?: {\n contextKey?: string;\n scheduleId?: string;\n workflowRunId?: string;\n workflowRunStepId?: string;\n parentTaskId?: string;\n vcsRepo?: string;\n vcsNumber?: number;\n slackChannelId?: string;\n slackThreadTs?: string;\n };\n /** The original task description, scrubbed and cut to 500 characters. */\n description: string;\n }\n export type TaskCreateModify = Partial<\n Pick<\n CreateTaskOptions,\n | "agentId"\n | "creatorAgentId"\n | "source"\n | "taskType"\n | "tags"\n | "priority"\n | "dependsOn"\n | "offeredTo"\n | "vcsProvider"\n | "vcsRepo"\n | "vcsEventType"\n | "vcsNumber"\n | "vcsCommentId"\n | "vcsAuthor"\n | "vcsUrl"\n | "vcsInstallationId"\n | "vcsNodeId"\n | "agentmailInboxId"\n | "agentmailMessageId"\n | "agentmailThreadId"\n | "mentionMessageId"\n | "mentionChannelId"\n | "dir"\n | "model"\n | "modelTier"\n | "effort"\n | "outputSchema"\n | "followUpConfig"\n | "bypassTrackerContextDedup"\n >\n > & {\n description?: string;\n };\n export interface TaskFollowUpEvent {\n completedTask: AgentTask;\n status: "completed" | "failed";\n output?: string;\n failureReason?: string;\n workerAgentId: string;\n leadAgentId: string;\n summary: string;\n }\n export interface TaskSteerEvent {\n task: AgentTask;\n message: string;\n mode: SteerMode;\n source: SteeringSource;\n sender: {\n kind: "user" | "agent" | "system";\n userId?: string;\n agentId?: string;\n };\n messageTimestamps?: string[];\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n channelId: string;\n threadTs: string;\n userId?: string;\n };\n }\n export interface TaskSteerModify {\n message: string;\n }\n export type TaskFollowUpModify = Partial<\n Pick<CreateTaskOptions, "agentId" | "priority" | "followUpConfig">\n > & {\n description?: string;\n };\n export interface SlackRouteEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n botMentioned: boolean;\n threadContext?: {\n channelId: string;\n threadTs: string;\n };\n }\n export interface SlackRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n };\n }\n /** A Chat SDK message after its thread buffer flushed, before routing. */\n export interface ChatRouteEvent {\n /** Adapter name, such as `telegram` or `slack`. */\n adapter: string;\n channelId: string;\n /** The Chat SDK thread id, prefixed with the adapter name. */\n threadId: string;\n /** The first buffered sender. */\n userId: string;\n userName?: string;\n /** The buffered messages, joined. */\n text: string;\n /** True for an @mention and for a reply to one of the bot\'s messages. */\n botMentioned: boolean;\n isDirectMessage: boolean;\n /** Platform chat type, such as Telegram `private`, `group`, `supergroup` or `channel`. */\n chatType?: string;\n /** Set for a Telegram supergroup with topics. */\n isForum?: boolean;\n /** A buffered message replies to one of the bot\'s own messages. */\n replyToBot: boolean;\n /** Set when earlier swarm tasks exist in this thread. */\n threadContext?: {\n adapter: string;\n threadId: string;\n };\n }\n export interface ChatRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n }\n | {\n kind: "workflow";\n workflowId: string;\n };\n }\n export type HeartbeatClassification = "no-session" | "stale-session" | "fresh-stalled";\n export type HeartbeatAction = "supersede-resume" | "fail" | "record";\n export interface HeartbeatRemediateEvent {\n task: AgentTask;\n session?: ActiveSession;\n classification: HeartbeatClassification;\n proposedAction: HeartbeatAction;\n reason: string;\n taskAgeMs: number;\n sessionHeartbeatAgeMs?: number;\n }\n export interface HeartbeatRemediateModify {\n proposedAction: HeartbeatAction;\n }\n export interface ToolCallEvent {\n tool: string;\n /** Secret-scrubbed on native calls: a secret reads as `[REDACTED:<name>]`. */\n args: unknown;\n requestInfo: RequestInfo;\n /** Native calls only: the harness\'s own tool name, such as `Bash`. */\n nativeTool?: string;\n /** Native calls only: the harness\'s own argument shape, secret-scrubbed. */\n rawArgs?: unknown;\n /** Native calls only: the harness\'s call id, and its parent for a nested call. */\n toolCallId?: string;\n parentToolCallId?: string;\n }\n export interface ToolCallModify {\n args: unknown;\n }\n export interface TaskEvent {\n task: AgentTask;\n }\n export interface TaskCompletedEvent extends TaskEvent {\n output: string;\n }\n export interface TaskFailedEvent extends TaskEvent {\n failureReason: string;\n }\n export interface TaskSupersededEvent extends TaskEvent {\n supersededBy: string;\n }\n export interface TaskProgressEvent extends TaskEvent {\n progress: string;\n }\n export interface SlackMessageEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n taskId?: string;\n }\n /** A Chat SDK message the swarm received or sent. */\n export interface ChatMessageEvent {\n adapter: string;\n channelId: string;\n threadId: string;\n /** The sender, for an inbound message. */\n userId?: string;\n text: string;\n direction: "inbound" | "outbound";\n taskId?: string;\n messageId?: string;\n }\n /**\n * A person answered an approval request. Fires for workflow and standalone\n * requests. Timeouts and cancellations do not emit it today.\n */\n export interface ApprovalResolvedEvent {\n requestId: string;\n status: "approved" | "rejected" | "timeout" | "cancelled";\n responses: Record<string, unknown> | null;\n /** Set when a workflow human-in-the-loop step asked. Absent for a standalone request. */\n workflowRunId?: string;\n workflowRunStepId?: string;\n /** The task whose agent asked, for a standalone request. */\n sourceTaskId?: string;\n }\n /** A task was refused because a daily spend budget is used up. */\n export interface TaskBudgetRefusedEvent extends TaskEvent {\n /** The agent the task was refused for. */\n agentId: string;\n /** Which budget refused it. The matching spend and budget fields are set. */\n cause: "agent" | "global" | "user";\n agentSpendUsd?: number;\n agentBudgetUsd?: number;\n globalSpendUsd?: number;\n globalBudgetUsd?: number;\n userSpendUsd?: number;\n userBudgetUsd?: number;\n /** ISO 8601 time the daily budget resets. */\n resetAt: string;\n }\n /** An inbound AgentMail message. */\n export interface EmailReceivedEvent {\n inboxId: string;\n /** The From header as sent. */\n from: string;\n subject: string;\n /** The text body, or the HTML when there is no text, cut to 500 characters with `...` appended. */\n body: string;\n threadId: string;\n messageId: string;\n }\n /** An inbound Kapso (WhatsApp) message. */\n export interface KapsoMessageEvent {\n phoneNumberId: string;\n conversationId?: string;\n messageId: string;\n from?: string;\n /** Kapso message type, such as `text` or `image`. */\n type?: string;\n /** The text, or a placeholder naming the type for a non-text message. */\n text: string;\n }\n export type VcsProvider = "github" | "gitlab" | "azure-devops" | "bitbucket";\n /**\n * The provider object the event is about, as the provider names it. GitLab\n * calls a pull request a merge request, and a comment a `note`.\n */\n export type VcsEventKind =\n | "pull_request"\n | "merge_request"\n | "issue"\n | "issue_comment"\n | "note"\n | "pull_request_review"\n | "pipeline";\n /**\n * A webhook event from a connected code host. `action` is the provider\'s own\n * value: `opened`, `closed`, `synchronize`, `merge`, `created`, `commented`, or,\n * for a pipeline, its status such as `success` or `failed`. Fields a kind does\n * not carry are absent.\n */\n export interface VcsEvent {\n provider: VcsProvider;\n kind: VcsEventKind;\n action: string;\n /** `owner/name` on GitHub and GitLab, `workspace/repo_slug` on Bitbucket, the repository URL on Azure DevOps. */\n repo: string;\n /** The PR, merge request, or issue number. Absent for a pipeline outside a merge request. */\n number?: number;\n title?: string;\n body?: string | null;\n /** Login of the user behind the event. Set for pull requests, merge requests, and Azure DevOps comments. */\n author?: string;\n url?: string;\n merged?: boolean;\n changedFiles?: number;\n /** The review verdict, on a pull request review. */\n reviewState?: string;\n }\n export interface ToolCallCompletedEvent extends ToolCallEvent {\n result: unknown;\n durationMs: number;\n /** Native calls only: the harness reported the call as failed. */\n isError?: boolean;\n }\n export interface SwarmEventMap {\n "pre.task.create": {\n event: TaskCreateEvent;\n modify: TaskCreateModify;\n result: PreResult<TaskCreateModify>;\n };\n "pre.task.followUp": {\n event: TaskFollowUpEvent;\n modify: TaskFollowUpModify;\n result: PreResult<TaskFollowUpModify>;\n };\n "pre.task.steer": {\n event: TaskSteerEvent;\n modify: TaskSteerModify;\n result: PreResult<TaskSteerModify>;\n };\n "pre.slack.route": {\n event: SlackRouteEvent;\n modify: SlackRouteModify;\n result: PreResult<SlackRouteModify>;\n };\n "pre.chat.route": {\n event: ChatRouteEvent;\n modify: ChatRouteModify;\n result: PreResult<ChatRouteModify>;\n };\n "pre.heartbeat.remediate": {\n event: HeartbeatRemediateEvent;\n modify: HeartbeatRemediateModify;\n result: PreResult<HeartbeatRemediateModify>;\n };\n "pre.tool.call": {\n event: ToolCallEvent;\n modify: ToolCallModify;\n result: PreResult<ToolCallModify>;\n };\n "post.task.created": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.blocked": {\n event: TaskBlockedEvent;\n modify: never;\n result: void;\n };\n "post.task.completed": {\n event: TaskCompletedEvent;\n modify: never;\n result: void;\n };\n "post.task.failed": {\n event: TaskFailedEvent;\n modify: never;\n result: void;\n };\n "post.task.cancelled": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.superseded": {\n event: TaskSupersededEvent;\n modify: never;\n result: void;\n };\n "post.task.progress": {\n event: TaskProgressEvent;\n modify: never;\n result: void;\n };\n "post.slack.message": {\n event: SlackMessageEvent;\n modify: never;\n result: void;\n };\n "post.chat.message": {\n event: ChatMessageEvent;\n modify: never;\n result: void;\n };\n "post.approval.resolved": {\n event: ApprovalResolvedEvent;\n modify: never;\n result: void;\n };\n "post.task.budgetRefused": {\n event: TaskBudgetRefusedEvent;\n modify: never;\n result: void;\n };\n "post.email.received": {\n event: EmailReceivedEvent;\n modify: never;\n result: void;\n };\n "post.kapso.message": {\n event: KapsoMessageEvent;\n modify: never;\n result: void;\n };\n "post.vcs.event": {\n event: VcsEvent;\n modify: never;\n result: void;\n };\n "post.tool.call": {\n event: ToolCallCompletedEvent;\n modify: never;\n result: void;\n };\n }\n export interface ExtensionApi<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > {\n on<E extends keyof SwarmEventMap>(\n event: E,\n handler: (\n event: SwarmEventMap[E]["event"],\n ctx: CtxFor<M>,\n ) => Promise<SwarmEventMap[E]["result"]> | SwarmEventMap[E]["result"],\n opts?: {\n priority?: number;\n },\n ): void;\n }\n export type SwarmExtension<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > = (api: ExtensionApi<M>) => void;\n export { block, modify } from "./contract-runtime";\n}\n';
|
|
4
|
+
'// biome-ignore-all lint/suspicious/noConfusingVoidType: Extension handlers may explicitly return no result.\ndeclare module "swarm-extension" {\n export type CreateTaskOptions = {\n key?: string | undefined;\n agentId?: string | null | undefined;\n creatorAgentId?: string | undefined;\n source?:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb"\n | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n taskType?: string | undefined;\n tags?: string[] | undefined;\n priority?: number | undefined;\n dependsOn?: string[] | undefined;\n offeredTo?: string | undefined;\n status?: "draft" | "backlog" | "unassigned" | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n overrideSlackContext?: boolean | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | undefined;\n workflowRunStepId?: string | undefined;\n sourceTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n inheritParentOutputSchema?: boolean | undefined;\n inheritParentRequester?: boolean | undefined;\n inheritParentRoutingAffinity?: boolean | undefined;\n inheritParentFollowUpConfig?: boolean | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n requestedByUserId?: string | undefined;\n contextKey?: string | undefined;\n bypassTrackerContextDedup?: boolean | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "codex"\n | "pi"\n | "opencode"\n | "claude"\n | "claude-managed"\n | "grok"\n | "fx"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n };\n\n export type AgentTask = {\n id: string;\n key: string;\n agentId: string | null;\n task: string;\n status:\n | "skipped"\n | "draft"\n | "backlog"\n | "unassigned"\n | "offered"\n | "reviewing"\n | "pending"\n | "in_progress"\n | "paused"\n | "completed"\n | "failed"\n | "cancelled"\n | "superseded";\n source:\n | "chat"\n | "workflow"\n | "schedule"\n | "slack"\n | "agentmail"\n | "mcp"\n | "api"\n | "ui"\n | "github"\n | "gitlab"\n | "azure-devops"\n | "bitbucket"\n | "system"\n | "linear"\n | "jira"\n | "comb";\n tags: string[];\n priority: number;\n dependsOn: string[];\n createdAt: string;\n lastUpdatedAt: string;\n slackReplySent: boolean;\n wasPaused: boolean;\n creatorAgentId?: string | undefined;\n title?: string | undefined;\n routingReason?:\n | "skill"\n | "continuity"\n | "overflow"\n | "human_pinned"\n | "reroute_fault"\n | undefined;\n routingSource?: "declared" | "engine_default" | undefined;\n routingNote?: string | undefined;\n poolWakeAt?: string | undefined;\n taskType?: string | undefined;\n offeredTo?: string | undefined;\n offeredAt?: string | undefined;\n acceptedAt?: string | undefined;\n rejectionReason?: string | undefined;\n finishedAt?: string | undefined;\n notifiedAt?: string | undefined;\n failureReason?: string | undefined;\n output?: string | undefined;\n progress?: string | undefined;\n slackChannelId?: string | undefined;\n slackThreadTs?: string | undefined;\n slackTriggerMessageTs?: string | undefined;\n slackUserId?: string | undefined;\n slackParticipants?:\n | {\n people: {\n slackUserId: string;\n trust: "external" | "unknown" | "internal";\n userId?: string | undefined;\n starter?: boolean | undefined;\n newest?: boolean | undefined;\n asked?: boolean | undefined;\n }[];\n more: number;\n }\n | undefined;\n slackProgressMessageTs?: string | undefined;\n slackTreeRootMessageTs?: string | undefined;\n vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;\n vcsRepo?: string | undefined;\n vcsEventType?: string | undefined;\n vcsNumber?: number | undefined;\n vcsCommentId?: number | undefined;\n vcsAuthor?: string | undefined;\n vcsUrl?: string | undefined;\n vcsInstallationId?: number | undefined;\n vcsNodeId?: string | undefined;\n agentmailInboxId?: string | undefined;\n agentmailMessageId?: string | undefined;\n agentmailThreadId?: string | undefined;\n mentionMessageId?: string | undefined;\n mentionChannelId?: string | undefined;\n dir?: string | undefined;\n parentTaskId?: string | undefined;\n dispatchedByTaskId?: string | undefined;\n claudeSessionId?: string | undefined;\n model?: string | undefined;\n modelTier?: "smol" | "regular" | "smart" | "ultra" | undefined;\n effort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n resolvedModel?: string | undefined;\n modelSource?: string | undefined;\n modelAlias?: string | undefined;\n resolvedEffort?: "low" | "medium" | "high" | "max" | "off" | "xhigh" | undefined;\n profile?: string | undefined;\n resolvedProfile?: string | undefined;\n fallbackHops?:\n | {\n from: string;\n profile: string;\n errorClass:\n | "rate_limit"\n | "model_window"\n | "seat"\n | "credits"\n | "overloaded"\n | "server_error"\n | "auth"\n | "pool_empty";\n at: string;\n skipped?: { profile: string; reason: string }[] | undefined;\n }[]\n | undefined;\n scheduleId?: string | undefined;\n workflowRunId?: string | null | undefined;\n workflowRunStepId?: string | null | undefined;\n contextKey?: string | undefined;\n outputSchema?: Record<string, unknown> | undefined;\n followUpConfig?:\n | {\n disabled?: boolean | undefined;\n onCompleted?: string | undefined;\n onFailed?: string | undefined;\n }\n | undefined;\n deferredAt?: string | undefined;\n compactionCount?: number | undefined;\n peakContextPercent?: number | undefined;\n peakContextTokens?: number | undefined;\n contextWindowSize?: number | undefined;\n credentialKeySuffix?: string | undefined;\n credentialKeyType?: string | undefined;\n requestedByUserId?: string | undefined;\n swarmVersion?: string | undefined;\n provider?:\n | "codex"\n | "pi"\n | "opencode"\n | "claude"\n | "claude-managed"\n | "grok"\n | "fx"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n providerMeta?: Record<string, unknown> | undefined;\n harnessVariant?: string | undefined;\n harnessVariantMeta?: Record<string, unknown> | undefined;\n totalCostUsd?: number | undefined;\n routingAffinity?:\n | {\n capabilities: string[];\n sourceAgentId?: string | undefined;\n role?: string | undefined;\n harnessProvider?:\n | "codex"\n | "pi"\n | "opencode"\n | "claude"\n | "claude-managed"\n | "grok"\n | "fx"\n | "dsh"\n | "cursor"\n | "amp"\n | "devin"\n | "acp"\n | undefined;\n leadOnly?: boolean | undefined;\n }\n | undefined;\n routingAffinityInvalid?: boolean | undefined;\n };\n\n export type ActiveSession = {\n id: string;\n agentId: string;\n taskId: string | null;\n triggerType: string;\n inboxMessageId: string | null;\n taskDescription: string | null;\n runnerSessionId: string | null;\n providerSessionId: string | null;\n startedAt: string;\n lastHeartbeatAt: string;\n runtimeInstanceId?: string | null | undefined;\n };\n\n export type SteerMode = "steer" | "queue";\n\n export type SteeringSource = "chat" | "script" | "slack" | "mcp" | "api" | "ui" | "app-page";\n\n export type RequestInfo = {\n sessionId: string | undefined;\n agentId: string | undefined;\n runtimeInstanceId: string | undefined;\n sourceTaskId: string | undefined;\n auditSourceTaskId: string | undefined;\n contextKey: string | undefined;\n callOrigin: "native" | "mcp" | "extension" | "script-sdk";\n harness?: string | undefined;\n };\n\n import type { SwarmSdk } from "swarm-sdk";\n import type { z } from "zod";\n export type Runtime = "api" | "worker";\n export interface ExtensionScriptAsset {\n name: string;\n file: string;\n description: string;\n intent?: string;\n }\n export interface ExtensionScheduleAsset {\n name: string;\n description?: string;\n script: string;\n cronExpression?: string;\n intervalMs?: number;\n timezone?: string;\n args?: Record<string, unknown>;\n }\n export interface ExtensionWorkflowAsset {\n file: string;\n }\n export interface ExtensionSkillAsset {\n dir: string;\n }\n export interface ExtensionManifest {\n $schema?: string;\n name: string;\n description: string;\n version: string;\n runtime: Runtime;\n assets: {\n hooks: string;\n scripts?: readonly ExtensionScriptAsset[];\n schedules?: readonly ExtensionScheduleAsset[];\n workflows?: readonly ExtensionWorkflowAsset[];\n skills?: readonly ExtensionSkillAsset[];\n };\n homepage?: string;\n author?: string;\n /** Tool-call sources this extension\'s tool handlers receive. Default `["mcp"]`. */\n toolSources?: readonly ToolSource[];\n }\n /** `mcp`: swarm MCP tools. `native`: harness built-ins reported by a worker shim. */\n export type ToolSource = "mcp" | "native";\n export interface HooksModule {\n default: SwarmExtension;\n config?: z.ZodTypeAny;\n }\n export interface ExtensionState {\n get<T = unknown>(key: string): Promise<T | null>;\n set<T>(key: string, value: T): Promise<void>;\n incr(key: string, by?: number): Promise<number>;\n del(key: string): Promise<void>;\n }\n export interface ExtensionLogger {\n debug(message: string, data?: unknown): void;\n info(message: string, data?: unknown): void;\n warn(message: string, data?: unknown): void;\n error(message: string, data?: unknown): void;\n }\n type ConfigFor<M extends ExtensionManifest> = M extends {\n config: infer C extends z.ZodTypeAny;\n }\n ? z.infer<C>\n : Record<string, unknown>;\n export interface ApiCtx<Config = Record<string, unknown>> {\n swarm: SwarmSdk;\n state: ExtensionState;\n config: Config;\n log: ExtensionLogger;\n signal: AbortSignal;\n event: {\n name: keyof SwarmEventMap;\n at: string;\n extension: {\n id: string;\n version: number;\n };\n };\n }\n export interface WorkerCtx<Config = Record<string, unknown>>\n extends Omit<ApiCtx<Config>, "swarm"> {\n swarm: SwarmSdk;\n worker: {\n agentId: string;\n taskId: string;\n harness: string;\n };\n }\n export type CtxFor<M extends ExtensionManifest> = M["runtime"] extends "api"\n ? ApiCtx<ConfigFor<M>>\n : WorkerCtx<ConfigFor<M>>;\n export type PreResult<Modify> =\n | void\n | {\n action: "continue";\n }\n | {\n action: "modify";\n data: Modify;\n }\n | {\n action: "block";\n reason: string;\n };\n export type TaskCreateOrigin =\n | "rest"\n | "app"\n | "mcp"\n | "slack"\n | "schedule"\n | "workflow"\n | "webhook"\n | "followUp"\n | `extension:${string}`;\n export interface TaskCreateEvent {\n options: CreateTaskOptions;\n description: string;\n origin: TaskCreateOrigin;\n requestInfo?: RequestInfo;\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n trigger: "mention" | "thread-buffer";\n messages: {\n ts: string;\n userId: string;\n text: string;\n }[];\n };\n }\n /** A pre.task.create hook blocked a task before it was created. */\n export interface TaskBlockedEvent {\n /** The extension that blocked, or whose model/agent rewrite was rejected. */\n extension: {\n id: string;\n name: string;\n };\n /** The scrubbed block reason. */\n reason: string;\n origin: TaskCreateOrigin;\n source?: AgentTask["source"];\n requester: {\n userId?: string;\n agentId?: string;\n slackUserId?: string;\n };\n context?: {\n contextKey?: string;\n scheduleId?: string;\n workflowRunId?: string;\n workflowRunStepId?: string;\n parentTaskId?: string;\n vcsRepo?: string;\n vcsNumber?: number;\n slackChannelId?: string;\n slackThreadTs?: string;\n };\n /** The original task description, scrubbed and cut to 500 characters. */\n description: string;\n }\n export type TaskCreateModify = Partial<\n Pick<\n CreateTaskOptions,\n | "agentId"\n | "creatorAgentId"\n | "source"\n | "taskType"\n | "tags"\n | "priority"\n | "dependsOn"\n | "offeredTo"\n | "vcsProvider"\n | "vcsRepo"\n | "vcsEventType"\n | "vcsNumber"\n | "vcsCommentId"\n | "vcsAuthor"\n | "vcsUrl"\n | "vcsInstallationId"\n | "vcsNodeId"\n | "agentmailInboxId"\n | "agentmailMessageId"\n | "agentmailThreadId"\n | "mentionMessageId"\n | "mentionChannelId"\n | "dir"\n | "model"\n | "modelTier"\n | "effort"\n | "outputSchema"\n | "followUpConfig"\n | "bypassTrackerContextDedup"\n >\n > & {\n description?: string;\n };\n export interface TaskFollowUpEvent {\n completedTask: AgentTask;\n status: "completed" | "failed";\n output?: string;\n failureReason?: string;\n workerAgentId: string;\n leadAgentId: string;\n summary: string;\n }\n export interface TaskSteerEvent {\n task: AgentTask;\n message: string;\n mode: SteerMode;\n source: SteeringSource;\n sender: {\n kind: "user" | "agent" | "system";\n userId?: string;\n agentId?: string;\n };\n messageTimestamps?: string[];\n /** Slack ingress metadata; not persisted or writable through modify. */\n slack?: {\n channelId: string;\n threadTs: string;\n userId?: string;\n };\n }\n export interface TaskSteerModify {\n message: string;\n }\n export type TaskFollowUpModify = Partial<\n Pick<CreateTaskOptions, "agentId" | "priority" | "followUpConfig">\n > & {\n description?: string;\n };\n export interface SlackRouteEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n botMentioned: boolean;\n threadContext?: {\n channelId: string;\n threadTs: string;\n };\n }\n export interface SlackRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n };\n }\n /** A Chat SDK message after its thread buffer flushed, before routing. */\n export interface ChatRouteEvent {\n /** Adapter name, such as `telegram` or `slack`. */\n adapter: string;\n channelId: string;\n /** The Chat SDK thread id, prefixed with the adapter name. */\n threadId: string;\n /** The first buffered sender. */\n userId: string;\n userName?: string;\n /** The buffered messages, joined. */\n text: string;\n /** True for an @mention and for a reply to one of the bot\'s messages. */\n botMentioned: boolean;\n isDirectMessage: boolean;\n /** Platform chat type, such as Telegram `private`, `group`, `supergroup` or `channel`. */\n chatType?: string;\n /** Set for a Telegram supergroup with topics. */\n isForum?: boolean;\n /** A buffered message replies to one of the bot\'s own messages. */\n replyToBot: boolean;\n /** Set when earlier swarm tasks exist in this thread. */\n threadContext?: {\n adapter: string;\n threadId: string;\n };\n }\n export interface ChatRouteModify {\n target:\n | {\n kind: "agent";\n agentId: string;\n }\n | {\n kind: "lead";\n }\n | {\n kind: "broadcast";\n }\n | {\n kind: "workflow";\n workflowId: string;\n };\n }\n export type HeartbeatClassification = "no-session" | "stale-session" | "fresh-stalled";\n export type HeartbeatAction = "supersede-resume" | "fail" | "record";\n export interface HeartbeatRemediateEvent {\n task: AgentTask;\n session?: ActiveSession;\n classification: HeartbeatClassification;\n proposedAction: HeartbeatAction;\n reason: string;\n taskAgeMs: number;\n sessionHeartbeatAgeMs?: number;\n }\n export interface HeartbeatRemediateModify {\n proposedAction: HeartbeatAction;\n }\n export interface ToolCallEvent {\n tool: string;\n /** Secret-scrubbed on native calls: a secret reads as `[REDACTED:<name>]`. */\n args: unknown;\n requestInfo: RequestInfo;\n /** Native calls only: the harness\'s own tool name, such as `Bash`. */\n nativeTool?: string;\n /** Native calls only: the harness\'s own argument shape, secret-scrubbed. */\n rawArgs?: unknown;\n /** Native calls only: the harness\'s call id, and its parent for a nested call. */\n toolCallId?: string;\n parentToolCallId?: string;\n }\n export interface ToolCallModify {\n args: unknown;\n }\n export interface TaskEvent {\n task: AgentTask;\n }\n export interface TaskCompletedEvent extends TaskEvent {\n output: string;\n }\n export interface TaskFailedEvent extends TaskEvent {\n failureReason: string;\n }\n export interface TaskSupersededEvent extends TaskEvent {\n supersededBy: string;\n }\n export interface TaskProgressEvent extends TaskEvent {\n progress: string;\n }\n export interface SlackMessageEvent {\n channelId: string;\n userId: string;\n text: string;\n threadTs?: string;\n taskId?: string;\n }\n /** A Chat SDK message the swarm received or sent. */\n export interface ChatMessageEvent {\n adapter: string;\n channelId: string;\n threadId: string;\n /** The sender, for an inbound message. */\n userId?: string;\n text: string;\n direction: "inbound" | "outbound";\n taskId?: string;\n messageId?: string;\n }\n /**\n * A person answered an approval request. Fires for workflow and standalone\n * requests. Timeouts and cancellations do not emit it today.\n */\n export interface ApprovalResolvedEvent {\n requestId: string;\n status: "approved" | "rejected" | "timeout" | "cancelled";\n responses: Record<string, unknown> | null;\n /** Set when a workflow human-in-the-loop step asked. Absent for a standalone request. */\n workflowRunId?: string;\n workflowRunStepId?: string;\n /** The task whose agent asked, for a standalone request. */\n sourceTaskId?: string;\n }\n /** A task was refused because a daily spend budget is used up. */\n export interface TaskBudgetRefusedEvent extends TaskEvent {\n /** The agent the task was refused for. */\n agentId: string;\n /** Which budget refused it. The matching spend and budget fields are set. */\n cause: "agent" | "global" | "user";\n agentSpendUsd?: number;\n agentBudgetUsd?: number;\n globalSpendUsd?: number;\n globalBudgetUsd?: number;\n userSpendUsd?: number;\n userBudgetUsd?: number;\n /** ISO 8601 time the daily budget resets. */\n resetAt: string;\n }\n /** An inbound AgentMail message. */\n export interface EmailReceivedEvent {\n inboxId: string;\n /** The From header as sent. */\n from: string;\n subject: string;\n /** The text body, or the HTML when there is no text, cut to 500 characters with `...` appended. */\n body: string;\n threadId: string;\n messageId: string;\n }\n /** An inbound Kapso (WhatsApp) message. */\n export interface KapsoMessageEvent {\n phoneNumberId: string;\n conversationId?: string;\n messageId: string;\n from?: string;\n /** Kapso message type, such as `text` or `image`. */\n type?: string;\n /** The text, or a placeholder naming the type for a non-text message. */\n text: string;\n }\n export type VcsProvider = "github" | "gitlab" | "azure-devops" | "bitbucket";\n /**\n * The provider object the event is about, as the provider names it. GitLab\n * calls a pull request a merge request, and a comment a `note`.\n */\n export type VcsEventKind =\n | "pull_request"\n | "merge_request"\n | "issue"\n | "issue_comment"\n | "note"\n | "pull_request_review"\n | "pipeline";\n /**\n * A webhook event from a connected code host. `action` is the provider\'s own\n * value: `opened`, `closed`, `synchronize`, `merge`, `created`, `commented`, or,\n * for a pipeline, its status such as `success` or `failed`. Fields a kind does\n * not carry are absent.\n */\n export interface VcsEvent {\n provider: VcsProvider;\n kind: VcsEventKind;\n action: string;\n /** `owner/name` on GitHub and GitLab, `workspace/repo_slug` on Bitbucket, the repository URL on Azure DevOps. */\n repo: string;\n /** The PR, merge request, or issue number. Absent for a pipeline outside a merge request. */\n number?: number;\n title?: string;\n body?: string | null;\n /** Login of the user behind the event. Set for pull requests, merge requests, and Azure DevOps comments. */\n author?: string;\n url?: string;\n merged?: boolean;\n changedFiles?: number;\n /** The review verdict, on a pull request review. */\n reviewState?: string;\n }\n export interface ToolCallCompletedEvent extends ToolCallEvent {\n result: unknown;\n durationMs: number;\n /** Native calls only: the harness reported the call as failed. */\n isError?: boolean;\n }\n export interface SwarmEventMap {\n "pre.task.create": {\n event: TaskCreateEvent;\n modify: TaskCreateModify;\n result: PreResult<TaskCreateModify>;\n };\n "pre.task.followUp": {\n event: TaskFollowUpEvent;\n modify: TaskFollowUpModify;\n result: PreResult<TaskFollowUpModify>;\n };\n "pre.task.steer": {\n event: TaskSteerEvent;\n modify: TaskSteerModify;\n result: PreResult<TaskSteerModify>;\n };\n "pre.slack.route": {\n event: SlackRouteEvent;\n modify: SlackRouteModify;\n result: PreResult<SlackRouteModify>;\n };\n "pre.chat.route": {\n event: ChatRouteEvent;\n modify: ChatRouteModify;\n result: PreResult<ChatRouteModify>;\n };\n "pre.heartbeat.remediate": {\n event: HeartbeatRemediateEvent;\n modify: HeartbeatRemediateModify;\n result: PreResult<HeartbeatRemediateModify>;\n };\n "pre.tool.call": {\n event: ToolCallEvent;\n modify: ToolCallModify;\n result: PreResult<ToolCallModify>;\n };\n "post.task.created": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.blocked": {\n event: TaskBlockedEvent;\n modify: never;\n result: void;\n };\n "post.task.completed": {\n event: TaskCompletedEvent;\n modify: never;\n result: void;\n };\n "post.task.failed": {\n event: TaskFailedEvent;\n modify: never;\n result: void;\n };\n "post.task.cancelled": {\n event: TaskEvent;\n modify: never;\n result: void;\n };\n "post.task.superseded": {\n event: TaskSupersededEvent;\n modify: never;\n result: void;\n };\n "post.task.progress": {\n event: TaskProgressEvent;\n modify: never;\n result: void;\n };\n "post.slack.message": {\n event: SlackMessageEvent;\n modify: never;\n result: void;\n };\n "post.chat.message": {\n event: ChatMessageEvent;\n modify: never;\n result: void;\n };\n "post.approval.resolved": {\n event: ApprovalResolvedEvent;\n modify: never;\n result: void;\n };\n "post.task.budgetRefused": {\n event: TaskBudgetRefusedEvent;\n modify: never;\n result: void;\n };\n "post.email.received": {\n event: EmailReceivedEvent;\n modify: never;\n result: void;\n };\n "post.kapso.message": {\n event: KapsoMessageEvent;\n modify: never;\n result: void;\n };\n "post.vcs.event": {\n event: VcsEvent;\n modify: never;\n result: void;\n };\n "post.tool.call": {\n event: ToolCallCompletedEvent;\n modify: never;\n result: void;\n };\n }\n export interface ExtensionApi<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > {\n on<E extends keyof SwarmEventMap>(\n event: E,\n handler: (\n event: SwarmEventMap[E]["event"],\n ctx: CtxFor<M>,\n ) => Promise<SwarmEventMap[E]["result"]> | SwarmEventMap[E]["result"],\n opts?: {\n priority?: number;\n },\n ): void;\n }\n export type SwarmExtension<\n M extends ExtensionManifest = ExtensionManifest & {\n runtime: "api";\n },\n > = (api: ExtensionApi<M>) => void;\n export { block, modify } from "./contract-runtime";\n}\n';
|
package/src/http/agents.ts
CHANGED
|
@@ -1384,6 +1384,10 @@ export async function handleAgentsRest(
|
|
|
1384
1384
|
if (model !== undefined || profile === null) {
|
|
1385
1385
|
await deleteSwarmConfigByKey("agent", parsed.params.id, MODEL_PROFILE_CONFIG_KEY);
|
|
1386
1386
|
} else if (profile !== undefined) {
|
|
1387
|
+
// The profile beats MODEL_OVERRIDE at claim: drop the override so the two
|
|
1388
|
+
// keys cannot name different models. Before the upsert, since deleting an
|
|
1389
|
+
// override clears the profile.
|
|
1390
|
+
await deleteSwarmConfigByKey("agent", parsed.params.id, "MODEL_OVERRIDE");
|
|
1387
1391
|
await upsertSwarmConfig({
|
|
1388
1392
|
scope: "agent",
|
|
1389
1393
|
scopeId: parsed.params.id,
|
package/src/http/api-keys.ts
CHANGED
|
@@ -20,7 +20,11 @@ import {
|
|
|
20
20
|
KeyWindowUsageLimitError,
|
|
21
21
|
keyWindowUsageSchema,
|
|
22
22
|
} from "../be/key-window-usage";
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
MAX_RATE_LIMIT_RESET_MS,
|
|
25
|
+
MAX_SPEND_CAP_HOLD_MS,
|
|
26
|
+
type RateLimitWindowTelemetry,
|
|
27
|
+
} from "../utils/error-tracker";
|
|
24
28
|
import {
|
|
25
29
|
activeModelBlocks,
|
|
26
30
|
isModelScopedWindow,
|
|
@@ -85,6 +89,13 @@ const reportUsage = route({
|
|
|
85
89
|
auth: { apiKey: true },
|
|
86
90
|
});
|
|
87
91
|
|
|
92
|
+
/** A provider spend limit behind a key's rate limit (`SpendCap`). */
|
|
93
|
+
export const SpendCapSchema = z.object({
|
|
94
|
+
limitUsd: z.number().nullable(),
|
|
95
|
+
spendUsd: z.number().nullable(),
|
|
96
|
+
resetsAt: z.string().datetime().nullable(),
|
|
97
|
+
});
|
|
98
|
+
|
|
88
99
|
const reportRateLimit = route({
|
|
89
100
|
method: "post",
|
|
90
101
|
path: "/api/keys/report-rate-limit",
|
|
@@ -98,6 +109,8 @@ const reportRateLimit = route({
|
|
|
98
109
|
rateLimitedUntil: z.string().datetime(),
|
|
99
110
|
scope: z.string().optional(),
|
|
100
111
|
scopeId: z.string().optional(),
|
|
112
|
+
/** The provider spend limit behind the rejection (OpenRouter key limit, out of credits). */
|
|
113
|
+
spendCap: SpendCapSchema.optional(),
|
|
101
114
|
}),
|
|
102
115
|
responses: {
|
|
103
116
|
200: { description: "Key marked as rate-limited", schema: successMessageSchema },
|
|
@@ -402,6 +415,8 @@ const getAvailable = route({
|
|
|
402
415
|
earliestModelResetAt: z.string().nullable().optional(),
|
|
403
416
|
/** Indices excluded because the key's subscription plan cannot run the model. Present only when model was passed. */
|
|
404
417
|
seatBlockedIndices: z.array(z.number().int()).optional(),
|
|
418
|
+
/** Rate-limited indices whose limit is a provider spend cap. */
|
|
419
|
+
spendCappedIndices: z.array(z.number().int()),
|
|
405
420
|
/**
|
|
406
421
|
* Server-side order of the newest auth failure on these keys. Pass it back as
|
|
407
422
|
* `authFence` on `clear-rate-limit`: failures recorded after it survive the clear.
|
|
@@ -425,6 +440,8 @@ const ApiKeyStatusSchema = z.object({
|
|
|
425
440
|
scopeId: z.string().nullable(),
|
|
426
441
|
status: z.string(),
|
|
427
442
|
rateLimitedUntil: z.string().nullable(),
|
|
443
|
+
/** The spend cap behind the current rate limit, or null for an ordinary one. */
|
|
444
|
+
spendCap: SpendCapSchema.nullable(),
|
|
428
445
|
lastUsedAt: z.string().nullable(),
|
|
429
446
|
lastRateLimitAt: z.string().nullable(),
|
|
430
447
|
totalUsageCount: z.number().int(),
|
|
@@ -744,7 +761,12 @@ export async function handleApiKeys(
|
|
|
744
761
|
const parsed = await reportRateLimit.parse(req, res, pathSegments, queryParams);
|
|
745
762
|
if (!parsed) return true;
|
|
746
763
|
|
|
747
|
-
const { keyType, keySuffix, keyIndex,
|
|
764
|
+
const { keyType, keySuffix, keyIndex, scope, scopeId, spendCap } = parsed.body;
|
|
765
|
+
// A spend cap fails admission for the whole pool, so the reporter never sets an unbounded hold.
|
|
766
|
+
const holdUntilMs = Date.now() + (spendCap ? MAX_SPEND_CAP_HOLD_MS : MAX_RATE_LIMIT_RESET_MS);
|
|
767
|
+
const rateLimitedUntil = new Date(
|
|
768
|
+
Math.min(Date.parse(parsed.body.rateLimitedUntil), holdUntilMs),
|
|
769
|
+
).toISOString();
|
|
748
770
|
try {
|
|
749
771
|
await markKeyRateLimited(
|
|
750
772
|
keyType,
|
|
@@ -753,10 +775,11 @@ export async function handleApiKeys(
|
|
|
753
775
|
rateLimitedUntil,
|
|
754
776
|
scope,
|
|
755
777
|
scopeId ?? null,
|
|
778
|
+
spendCap ?? null,
|
|
756
779
|
);
|
|
757
780
|
reportRateLimit.respond(res, 200, {
|
|
758
781
|
success: true,
|
|
759
|
-
message: `Key ...${keySuffix} marked as rate-limited until ${rateLimitedUntil}`,
|
|
782
|
+
message: `Key ...${keySuffix} marked as ${spendCap ? "spend-capped" : "rate-limited"} until ${rateLimitedUntil}`,
|
|
760
783
|
});
|
|
761
784
|
} catch (err) {
|
|
762
785
|
jsonError(res, err instanceof Error ? err.message : "Failed to mark rate limit", 500);
|
|
@@ -886,6 +909,7 @@ export async function handleApiKeys(
|
|
|
886
909
|
success: true,
|
|
887
910
|
availableIndices: result.availableIndices,
|
|
888
911
|
rejectedIndices: result.rejectedIndices,
|
|
912
|
+
spendCappedIndices: result.spendCappedIndices,
|
|
889
913
|
totalKeys,
|
|
890
914
|
authFailureFence: result.authFailureFence,
|
|
891
915
|
...(model !== undefined
|
package/src/http/pages-public.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
extractAndVerifyCookie,
|
|
45
45
|
isLocalDevPageRequest,
|
|
46
46
|
LEGACY_PAGE_SESSION_COOKIE,
|
|
47
|
+
type PageSessionPayload,
|
|
47
48
|
pageSessionSetCookies,
|
|
48
49
|
verifyPageSession,
|
|
49
50
|
} from "../utils/page-session";
|
|
@@ -331,6 +332,36 @@ export function getPageFrameAncestors(): string[] {
|
|
|
331
332
|
return origins;
|
|
332
333
|
}
|
|
333
334
|
|
|
335
|
+
/**
|
|
336
|
+
* The configured app URLs as CSP origins, each with a leading space. An entry
|
|
337
|
+
* that does not parse as an http(s) URL is dropped, so a stray value cannot add
|
|
338
|
+
* a source or a directive to the policy.
|
|
339
|
+
*/
|
|
340
|
+
function embedOrigins(appUrls: string[]): string {
|
|
341
|
+
const origins = new Set<string>();
|
|
342
|
+
for (const value of appUrls) {
|
|
343
|
+
try {
|
|
344
|
+
const url = new URL(value);
|
|
345
|
+
if (url.protocol === "https:" || url.protocol === "http:") origins.add(url.origin);
|
|
346
|
+
} catch {
|
|
347
|
+
// not a URL: skip it
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return Array.from(origins, (origin) => ` ${origin}`).join("");
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Who is viewing, for `<meta name="swarm-viewer">`: `user` for a signed-in
|
|
355
|
+
* viewer, `operator` for a launch with the shared swarm key, else `guest`. The
|
|
356
|
+
* `<swarm-object>` embed reads it so a guest gets a sign-in placeholder and
|
|
357
|
+
* sends no object request. It is a UI hint only: `/@swarm/api` still decides.
|
|
358
|
+
*/
|
|
359
|
+
function pageViewer(payload: PageSessionPayload | null): "user" | "operator" | "guest" {
|
|
360
|
+
if (payload?.uid) return "user";
|
|
361
|
+
if (payload?.op) return "operator";
|
|
362
|
+
return "guest";
|
|
363
|
+
}
|
|
364
|
+
|
|
334
365
|
/**
|
|
335
366
|
* Build the `Content-Security-Policy` for the served HTML. Allows inline
|
|
336
367
|
* scripts (required for `BROWSER_SDK_JS`) but locks down everything else to
|
|
@@ -351,6 +382,10 @@ function buildCsp(page: Page): string {
|
|
|
351
382
|
const devFallbacks = getLocalDevAppOrigins();
|
|
352
383
|
const embedders = page.authMode === "public" ? getPageFrameAncestors() : [];
|
|
353
384
|
const ancestors = Array.from(new Set([...configured, ...devFallbacks, ...embedders]));
|
|
385
|
+
// The dashboard origins also serve the `<swarm-object>` embed bundle
|
|
386
|
+
// (`/embed/v1/*`: module scripts, its shadow-root stylesheet and fonts).
|
|
387
|
+
// connect-src stays 'self': the embed talks to `/@swarm/api` only.
|
|
388
|
+
const appOrigins = embedOrigins(configured);
|
|
354
389
|
// Allow Tailwind Play CDN (`cdn.tailwindcss.com`, design version 1; the
|
|
355
390
|
// pinned v4 build of design version 2 comes from jsdelivr) for scripts, Google
|
|
356
391
|
// Fonts (`fonts.googleapis.com` stylesheets + `fonts.gstatic.com` font
|
|
@@ -362,9 +397,9 @@ function buildCsp(page: Page): string {
|
|
|
362
397
|
// a multi-hundred-KB bundle.
|
|
363
398
|
return [
|
|
364
399
|
"default-src 'self'",
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
400
|
+
`script-src 'self' 'unsafe-inline' 'unsafe-eval' https://cdn.tailwindcss.com https://cdn.jsdelivr.net https://unpkg.com${appOrigins}`,
|
|
401
|
+
`style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.tailwindcss.com https://cdn.jsdelivr.net https://unpkg.com${appOrigins}`,
|
|
402
|
+
`font-src 'self' https://fonts.gstatic.com data:${appOrigins}`,
|
|
368
403
|
"img-src 'self' data: https:",
|
|
369
404
|
"media-src 'self' data: https: blob:",
|
|
370
405
|
"connect-src 'self'",
|
|
@@ -667,7 +702,8 @@ export async function handlePagesPublic(
|
|
|
667
702
|
const feedback = isPageFeedbackRequested(queryParams);
|
|
668
703
|
const html =
|
|
669
704
|
injectBrowserSdk(page.body, {
|
|
670
|
-
head
|
|
705
|
+
// The viewer meta goes after the head defaults, which start with <base target>.
|
|
706
|
+
head: `${pageHead(page, queryParams, wantsPrint)}<meta name="swarm-viewer" content="${pageViewer(cookiePayload)}">`,
|
|
671
707
|
headFirst: feedback ? feedbackKeyGuardScript() : "",
|
|
672
708
|
standardsMode: page.designVersion !== 1,
|
|
673
709
|
}) +
|
package/src/http/pool-keys.ts
CHANGED
|
@@ -15,12 +15,19 @@ import type { SwarmConfig } from "../types";
|
|
|
15
15
|
import { CREDENTIAL_POOL_VARS, splitCredentialPool } from "../utils/credentials";
|
|
16
16
|
import { checkProviderPoolKey } from "../utils/provider-key-probes";
|
|
17
17
|
import { registerEnvSecrets, scrubSecrets } from "../utils/secret-scrubber";
|
|
18
|
+
import { SpendCapSchema } from "./api-keys";
|
|
18
19
|
import { ensureConfigAdmin, requestSecretReadScope, runConfigWriteSideEffects } from "./config";
|
|
19
20
|
import { getDeploymentEnvValue } from "./core";
|
|
20
21
|
import { route } from "./route-def";
|
|
21
22
|
import { jsonError } from "./utils";
|
|
22
23
|
|
|
23
|
-
export const PoolKeyStatusSchema = z.enum([
|
|
24
|
+
export const PoolKeyStatusSchema = z.enum([
|
|
25
|
+
"ok",
|
|
26
|
+
"rejected",
|
|
27
|
+
"rate_limited",
|
|
28
|
+
"spend_capped",
|
|
29
|
+
"unchecked",
|
|
30
|
+
]);
|
|
24
31
|
export type PoolKeyStatus = z.infer<typeof PoolKeyStatusSchema>;
|
|
25
32
|
export const PoolKeySchema = z.object({
|
|
26
33
|
index: z.number().int().min(0),
|
|
@@ -29,6 +36,8 @@ export const PoolKeySchema = z.object({
|
|
|
29
36
|
error: z.string().nullable(),
|
|
30
37
|
checkedAt: z.string().nullable(),
|
|
31
38
|
rateLimitedUntil: z.string().nullable(),
|
|
39
|
+
/** Set with `spend_capped`: the provider spend limit the key hit. */
|
|
40
|
+
spendCap: SpendCapSchema.nullable(),
|
|
32
41
|
});
|
|
33
42
|
export type PoolKey = z.infer<typeof PoolKeySchema>;
|
|
34
43
|
export const PoolKeysResponseSchema = z.object({
|
|
@@ -146,13 +155,23 @@ async function poolResponse(key: string): Promise<PoolKeysResponse> {
|
|
|
146
155
|
row?.status === "rate_limited" &&
|
|
147
156
|
!!row.rateLimitedUntil &&
|
|
148
157
|
Date.parse(row.rateLimitedUntil) > Date.now();
|
|
158
|
+
const spendCap = limited ? (row?.spendCap ?? null) : null;
|
|
149
159
|
return {
|
|
150
160
|
index,
|
|
151
161
|
suffix,
|
|
152
|
-
status: rejected
|
|
162
|
+
status: rejected
|
|
163
|
+
? "rejected"
|
|
164
|
+
: spendCap
|
|
165
|
+
? "spend_capped"
|
|
166
|
+
: limited
|
|
167
|
+
? "rate_limited"
|
|
168
|
+
: row
|
|
169
|
+
? "ok"
|
|
170
|
+
: "unchecked",
|
|
153
171
|
error: rejected ? scrubSecrets(row?.lastValidationError) || null : null,
|
|
154
172
|
checkedAt: rejected ? row!.lastValidationFailedAt : (row?.updatedAt ?? null),
|
|
155
173
|
rateLimitedUntil: row?.rateLimitedUntil ?? null,
|
|
174
|
+
spendCap,
|
|
156
175
|
};
|
|
157
176
|
}),
|
|
158
177
|
};
|
package/src/http/schedules.ts
CHANGED
|
@@ -22,7 +22,11 @@ import {
|
|
|
22
22
|
taskProfileError,
|
|
23
23
|
} from "../be/db/model-profiles";
|
|
24
24
|
import { explicitModelErrorForAgent } from "../be/model-validation";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
changesScheduleTarget,
|
|
27
|
+
mergeScheduleTiming,
|
|
28
|
+
validateRecurringTiming,
|
|
29
|
+
} from "../be/schedules/validate";
|
|
26
30
|
import { getScript } from "../be/scripts/db";
|
|
27
31
|
import { can } from "../rbac";
|
|
28
32
|
import { calculateNextRun, dispatchScheduleTarget } from "../scheduler/scheduler";
|
|
@@ -230,7 +234,7 @@ const updateSchedule = route({
|
|
|
230
234
|
responses: {
|
|
231
235
|
200: { description: "Schedule updated", schema: ScheduledTaskSchema.nullable() },
|
|
232
236
|
400: { description: "Validation error" },
|
|
233
|
-
403: { description: "Deferral owned by another agent" },
|
|
237
|
+
403: { description: "Deferral or target owned by another agent" },
|
|
234
238
|
404: { description: "Schedule not found" },
|
|
235
239
|
409: { description: "Duplicate name" },
|
|
236
240
|
},
|
|
@@ -249,7 +253,7 @@ const patchSchedule = route({
|
|
|
249
253
|
responses: {
|
|
250
254
|
200: { description: "Schedule patched", schema: ScheduledTaskSchema.nullable() },
|
|
251
255
|
400: { description: "Validation error" },
|
|
252
|
-
403: { description: "Deferral owned by another agent" },
|
|
256
|
+
403: { description: "Deferral or target owned by another agent" },
|
|
253
257
|
404: { description: "Schedule not found" },
|
|
254
258
|
409: { description: "Duplicate name" },
|
|
255
259
|
},
|
|
@@ -616,6 +620,27 @@ export async function handleSchedules(
|
|
|
616
620
|
return true;
|
|
617
621
|
}
|
|
618
622
|
}
|
|
623
|
+
// A schedule fires as its creator. An agent may change what it runs only
|
|
624
|
+
// as its creator or a lead, as in the patch-schedule and update-schedule tools.
|
|
625
|
+
if (changesScheduleTarget(existing, parsed.body)) {
|
|
626
|
+
const principal = await agentFirstPrincipal(req, myAgentId);
|
|
627
|
+
if (
|
|
628
|
+
principal.kind === "agent" &&
|
|
629
|
+
!can({
|
|
630
|
+
principal,
|
|
631
|
+
verb: "schedule.target.update.any",
|
|
632
|
+
resource: { kind: "owned", ownerAgentId: existing.createdByAgentId },
|
|
633
|
+
source: "http",
|
|
634
|
+
}).allow
|
|
635
|
+
) {
|
|
636
|
+
jsonError(
|
|
637
|
+
res,
|
|
638
|
+
`Schedule "${existing.name}" runs as the agent that created it. Only that agent or a lead can change its targetType, taskTemplate, workflowId, scriptName, scriptArgs or params.`,
|
|
639
|
+
403,
|
|
640
|
+
);
|
|
641
|
+
return true;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
619
644
|
// A move to another agent re-judges the stored model against the new harness.
|
|
620
645
|
const agentChanged =
|
|
621
646
|
parsed.body.targetAgentId !== undefined &&
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
type IntegrationType,
|
|
67
67
|
} from "@/telemetry";
|
|
68
68
|
import type { OAuthApp } from "@/tracker/types";
|
|
69
|
+
import { createSsrfGuardedFetch, EgressDeniedError } from "@/utils/egress-guard";
|
|
69
70
|
import { resolveScopedResourceId, scopedResourceScopeIdSchema } from "@/utils/scoped-resource";
|
|
70
71
|
import { registerVolatileSecret, scrubSecrets } from "@/utils/secret-scrubber";
|
|
71
72
|
import { ensureHttpPermission } from "./config";
|
|
@@ -1456,7 +1457,10 @@ async function listOAuthApps() {
|
|
|
1456
1457
|
* request was attempted (a revocationUrl is configured), false otherwise.
|
|
1457
1458
|
* Network/HTTP failures are logged (scrubbed) and never fail the caller.
|
|
1458
1459
|
*/
|
|
1459
|
-
async function attemptRemoteRevocation(
|
|
1460
|
+
export async function attemptRemoteRevocation(
|
|
1461
|
+
app: OAuthApp,
|
|
1462
|
+
accessToken: string,
|
|
1463
|
+
): Promise<boolean> {
|
|
1460
1464
|
const revocationUrl = app.revocationUrl ?? undefined;
|
|
1461
1465
|
if (!revocationUrl) return false;
|
|
1462
1466
|
|
|
@@ -1492,7 +1496,8 @@ async function attemptRemoteRevocation(app: OAuthApp, accessToken: string): Prom
|
|
|
1492
1496
|
const controller = new AbortController();
|
|
1493
1497
|
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
1494
1498
|
try {
|
|
1495
|
-
|
|
1499
|
+
// Guarded: a public name that resolves to a private address is refused too.
|
|
1500
|
+
await createSsrfGuardedFetch(publicEndpointSsrfOptions())(revocationUrl, {
|
|
1496
1501
|
method: "POST",
|
|
1497
1502
|
headers,
|
|
1498
1503
|
body: body.toString(),
|
|
@@ -1527,9 +1532,11 @@ function oauthDiscoveryUrls(inputUrl: string): string[] {
|
|
|
1527
1532
|
|
|
1528
1533
|
async function fetchJsonMetadata(url: string, signal: AbortSignal): Promise<unknown> {
|
|
1529
1534
|
let current = assertUrlSafe(url, publicEndpointSsrfOptions());
|
|
1535
|
+
// Checks each hop's resolved address; the loop below still owns redirects.
|
|
1536
|
+
const guardedFetch = createSsrfGuardedFetch(publicEndpointSsrfOptions());
|
|
1530
1537
|
let response: Response | null = null;
|
|
1531
1538
|
for (let hop = 0; hop <= 5; hop += 1) {
|
|
1532
|
-
response = await
|
|
1539
|
+
response = await guardedFetch(current, {
|
|
1533
1540
|
headers: { accept: "application/json" },
|
|
1534
1541
|
signal,
|
|
1535
1542
|
redirect: "manual",
|
|
@@ -1573,7 +1580,7 @@ function extractOAuthDiscovery(metadata: unknown) {
|
|
|
1573
1580
|
};
|
|
1574
1581
|
}
|
|
1575
1582
|
|
|
1576
|
-
async function discoverOAuthApp(url: string) {
|
|
1583
|
+
export async function discoverOAuthApp(url: string) {
|
|
1577
1584
|
const controller = new AbortController();
|
|
1578
1585
|
const timeout = setTimeout(() => controller.abort(), DISCOVERY_TIMEOUT_MS);
|
|
1579
1586
|
const failures: string[] = [];
|
|
@@ -1604,6 +1611,7 @@ async function discoverOAuthApp(url: string) {
|
|
|
1604
1611
|
function isUrlSafetyError(error: unknown): boolean {
|
|
1605
1612
|
if (!(error instanceof Error)) return false;
|
|
1606
1613
|
return (
|
|
1614
|
+
error instanceof EgressDeniedError ||
|
|
1607
1615
|
error.message.startsWith("Refusing ") ||
|
|
1608
1616
|
error.message.startsWith("Invalid URL:") ||
|
|
1609
1617
|
error.message.startsWith("Missing hostname:")
|
package/src/http/script-runs.ts
CHANGED
|
@@ -57,6 +57,7 @@ import {
|
|
|
57
57
|
RawLlmOutputSchema,
|
|
58
58
|
} from "../workflows/executors/raw-llm";
|
|
59
59
|
import { bodyTask, route } from "./route-def";
|
|
60
|
+
import { resolveTaskRequester } from "./task-requester";
|
|
60
61
|
import { json, jsonError } from "./utils";
|
|
61
62
|
|
|
62
63
|
const DEFAULT_SCRIPT_RUN_CONCURRENCY_CAP = 10;
|
|
@@ -482,6 +483,10 @@ export async function handleScriptRuns(
|
|
|
482
483
|
// read cap-1 active runs and all insert, exceeding the cap.
|
|
483
484
|
const cap = scriptRunConcurrencyCap();
|
|
484
485
|
const sourceTaskId = await resolveRunSourceTaskId(req, agent.id);
|
|
486
|
+
// Same rules as POST /api/tasks: a non-lead agent cannot name another user.
|
|
487
|
+
const requestedByUserId = parsed.body.requestedByUserId
|
|
488
|
+
? await resolveTaskRequester(req, agent.id, parsed.body.requestedByUserId)
|
|
489
|
+
: undefined;
|
|
485
490
|
const creation = await getDbClient().transaction(async () => {
|
|
486
491
|
if ((await countActiveScriptRuns()) >= cap) return null;
|
|
487
492
|
return await createScriptRun({
|
|
@@ -491,9 +496,9 @@ export async function handleScriptRuns(
|
|
|
491
496
|
args: parsed.body.args ?? null,
|
|
492
497
|
scriptName: parsed.body.scriptName,
|
|
493
498
|
idempotencyKey: parsed.body.idempotencyKey,
|
|
494
|
-
requestedByUserId
|
|
499
|
+
requestedByUserId,
|
|
495
500
|
sourceTaskId,
|
|
496
|
-
createdBy:
|
|
501
|
+
createdBy: requestedByUserId,
|
|
497
502
|
});
|
|
498
503
|
});
|
|
499
504
|
if (!creation) {
|
|
@@ -737,6 +742,10 @@ export async function handleScriptRuns(
|
|
|
737
742
|
return true;
|
|
738
743
|
}
|
|
739
744
|
const followUpThread = await followUpThreadForSourceTask(run.sourceTaskId);
|
|
745
|
+
// A step may name its own requester only when its agent may assign one; else the run's.
|
|
746
|
+
const stepRequester = parsed.body.requestedByUserId
|
|
747
|
+
? await resolveTaskRequester(req, agentId, parsed.body.requestedByUserId, null)
|
|
748
|
+
: undefined;
|
|
740
749
|
// The replay lookup, the guard decision and the insert share one write
|
|
741
750
|
// transaction. It serializes this step against the run's other steps,
|
|
742
751
|
// other runs and send-task dispatches into the same thread.
|
|
@@ -810,7 +819,7 @@ export async function handleScriptRuns(
|
|
|
810
819
|
vcsRepo: parsed.body.vcsRepo,
|
|
811
820
|
model: parsed.body.model,
|
|
812
821
|
parentTaskId: parsed.body.parentTaskId,
|
|
813
|
-
requestedByUserId:
|
|
822
|
+
requestedByUserId: stepRequester ?? run.requestedByUserId,
|
|
814
823
|
outputSchema: parsed.body.outputSchema,
|
|
815
824
|
contextKey,
|
|
816
825
|
});
|
package/src/http/tasks.ts
CHANGED
|
@@ -59,7 +59,6 @@ import {
|
|
|
59
59
|
} from "../be/steering";
|
|
60
60
|
import { getTaskCitations, TaskCitationSchema } from "../be/task-citations";
|
|
61
61
|
import { getTaskUiSpec, TaskUiSpecSchema } from "../be/task-ui-spec";
|
|
62
|
-
import { findUserById } from "../be/users";
|
|
63
62
|
import { can, isRbacEnabled, type RbacPrincipal, type RbacResource } from "../rbac";
|
|
64
63
|
import { mirrorSessionPrompt } from "../slack/session-mirror";
|
|
65
64
|
import { chatThreadOfContextKey } from "../tasks/context-key";
|
|
@@ -1543,15 +1542,12 @@ export async function handleTasks(
|
|
|
1543
1542
|
return true;
|
|
1544
1543
|
}
|
|
1545
1544
|
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
) {
|
|
1553
|
-
requestedByUserId = (await findUserById(parsed.body.requestedByUserId))?.id;
|
|
1554
|
-
}
|
|
1545
|
+
// Same rules as POST /api/tasks: a non-lead agent cannot name another user.
|
|
1546
|
+
const requestedByUserId = await resolveTaskRequester(
|
|
1547
|
+
req,
|
|
1548
|
+
myAgentId,
|
|
1549
|
+
parsed.body.requestedByUserId,
|
|
1550
|
+
);
|
|
1555
1551
|
|
|
1556
1552
|
try {
|
|
1557
1553
|
const auth = getRequestAuth(req);
|
|
@@ -44,6 +44,8 @@ type McpHttpClientOptions = {
|
|
|
44
44
|
omitEmptyAuthHeaders?: boolean;
|
|
45
45
|
/** Revalidate the resolved request URL immediately before every fetch. */
|
|
46
46
|
validateUrl?: (url: string) => void;
|
|
47
|
+
/** Fetch used for every request. Defaults to the global fetch. */
|
|
48
|
+
fetch?: typeof fetch;
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
export class McpHttpClient {
|
|
@@ -91,7 +93,7 @@ export class McpHttpClient {
|
|
|
91
93
|
const url = this.useRawUrl ? this.baseUrl : `${this.baseUrl}/mcp`;
|
|
92
94
|
try {
|
|
93
95
|
this.options.validateUrl?.(url);
|
|
94
|
-
const res = await fetch(url, {
|
|
96
|
+
const res = await (this.options.fetch ?? fetch)(url, {
|
|
95
97
|
method: "POST",
|
|
96
98
|
headers,
|
|
97
99
|
body: JSON.stringify(body),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { createSsrfGuardedFetch } from "@/utils/egress-guard";
|
|
1
2
|
import { scrubSecrets } from "@/utils/secret-scrubber";
|
|
2
3
|
import { assertOAuthEgressUrlSafe } from "./app-validation";
|
|
4
|
+
import { publicEndpointSsrfOptions } from "./mcp-wrapper";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Best-effort account identity captured after a successful token exchange.
|
|
@@ -66,7 +68,10 @@ export async function captureIdentity(input: {
|
|
|
66
68
|
const controller = new AbortController();
|
|
67
69
|
const timer = setTimeout(() => controller.abort(), IDENTITY_FETCH_TIMEOUT_MS);
|
|
68
70
|
try {
|
|
69
|
-
|
|
71
|
+
// The guarded fetch also checks the resolved address, so a public name
|
|
72
|
+
// that resolves to a private one never receives the bearer.
|
|
73
|
+
const guardedFetch = createSsrfGuardedFetch(publicEndpointSsrfOptions());
|
|
74
|
+
const response = await guardedFetch(input.userinfoUrl, {
|
|
70
75
|
headers: {
|
|
71
76
|
authorization: `Bearer ${input.accessToken}`,
|
|
72
77
|
accept: "application/json",
|