@desplega.ai/agent-swarm 2.8.2 → 2.8.3
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-xq6s2z6t.js +14 -0
- package/dist/{actions-kxek041g.js → actions-ewz7bp4g.js} +20 -19
- package/dist/{amp-adapter-ce7jjke4.js → amp-adapter-f25tqhnf.js} +3 -3
- package/dist/{app-v6zz8yh0.js → app-mkptw0k7.js} +4 -4
- package/dist/{assistant-m0sw9xx2.js → assistant-c47rfe77.js} +23 -22
- package/dist/{boot-args-schema-66bk37wv.js → boot-args-schema-4vb0xsat.js} +1 -1
- package/dist/{boot-reembed-edjpwsc1.js → boot-reembed-1ghy2sab.js} +1 -1
- package/dist/{boot-reembed-y27n09tz.js → boot-reembed-htr73hbs.js} +1 -1
- package/dist/{boot-scrub-sweep-1xc35965.js → boot-scrub-sweep-yrytg42z.js} +4 -4
- package/dist/{boot-seeds-7hjj91qj.js → boot-seeds-n2b3dx4e.js} +4 -4
- package/dist/{boxd-ent8ch04.js → boxd-jmfqgkqa.js} +1 -1
- package/dist/{claude-adapter-stw7jdcf.js → claude-adapter-r33pqnzx.js} +8 -9
- package/dist/{claude-managed-adapter-jh6c523j.js → claude-managed-adapter-hddmxjyj.js} +4 -4
- package/dist/{claude-managed-setup-y6z2perp.js → claude-managed-setup-hfvry1bd.js} +5 -5
- package/dist/{claude-sdk-session-vvya8wqk.js → claude-sdk-session-0hamqzc7.js} +10 -11
- package/dist/{cli-v1dv1r37.js → cli-0bcgyj5b.js} +74 -3
- package/dist/{cli-t2tma8gb.js → cli-0vksaxvr.js} +2 -2
- package/dist/{cli-mrt48bx7.js → cli-15204js0.js} +1 -1
- package/dist/{cli-8aes17e4.js → cli-1m96dc36.js} +3 -3
- package/dist/{cli-2r0jcc3k.js → cli-2d0cghfn.js} +1 -1
- package/dist/{cli-0cq8y6m7.js → cli-4ax9mvvg.js} +4 -4
- package/dist/{cli-tekytdq9.js → cli-4dpkjc2e.js} +6 -6
- package/dist/{cli-x1wa213s.js → cli-4e1hfbpq.js} +5 -5
- package/dist/{cli-7349va39.js → cli-500c09j9.js} +921 -431
- package/dist/{cli-9mb2q6pb.js → cli-54qr8mcd.js} +2 -2
- package/dist/{cli-m88rpzkh.js → cli-5a7szzfh.js} +2 -2
- package/dist/{cli-bst1vp7e.js → cli-5y2fvw4z.js} +13 -5
- package/dist/{cli-vj75tyaw.js → cli-6yygkr0w.js} +7 -7
- package/dist/{cli-kjtwrhea.js → cli-7c5tgqhf.js} +5 -5
- package/dist/{cli-2gxeg5gr.js → cli-8476gtwf.js} +1 -1
- package/dist/{cli-zh9rsbqf.js → cli-922z7gwm.js} +3 -3
- package/dist/{cli-jrzkw01m.js → cli-93t5s4zq.js} +2 -2
- package/dist/{cli-gyt3zydq.js → cli-9zmb7ptc.js} +9 -9
- package/dist/{cli-dzpc6en0.js → cli-am1ptset.js} +2 -2
- package/dist/{cli-w401b9tq.js → cli-awwptga4.js} +1 -1
- package/dist/{cli-26ctbcdp.js → cli-bhsfbmk8.js} +3 -3
- package/dist/{cli-mxn1qvbn.js → cli-bj6qhgte.js} +14 -32
- package/dist/{cli-g70vxtjh.js → cli-c0xjnr8z.js} +2 -2
- package/dist/{cli-jdknh18m.js → cli-c3ng0mb4.js} +13 -13
- package/dist/{cli-f4e8r23x.js → cli-c71n3bxq.js} +11 -6
- package/dist/{cli-6rc5frdm.js → cli-crpf163n.js} +25 -18
- package/dist/{cli-1qkz151v.js → cli-dpsfwh7n.js} +13 -21
- package/dist/{cli-xzm9vcfg.js → cli-dtdht77h.js} +2 -2
- package/dist/{cli-a0z912j7.js → cli-e2w34h6z.js} +137 -62
- package/dist/{cli-eddnyg3t.js → cli-emekyyhr.js} +1 -1
- package/dist/{cli-d84byzn8.js → cli-f1kwb5fc.js} +109 -33
- package/dist/{cli-0jzra9ad.js → cli-gn9y6fn7.js} +2 -2
- package/dist/{cli-vdektqgf.js → cli-gpz1d0t2.js} +4 -4
- package/dist/{cli-rcecc3yq.js → cli-h9yy18gy.js} +84 -36
- package/dist/{cli-m5akxq8q.js → cli-j8cjdzan.js} +1 -1
- package/dist/{cli-m9s2qff2.js → cli-jg5txpm6.js} +187 -93
- package/dist/{cli-b98a65ed.js → cli-k2rw11py.js} +3 -3
- package/dist/{cli-3e875j5p.js → cli-k96cecs7.js} +276 -47
- package/dist/{cli-3vjhs18n.js → cli-kd56bmk4.js} +1 -1
- package/dist/{cli-3sy2xags.js → cli-kmemts3w.js} +12 -12
- package/dist/{cli-f6bahpn5.js → cli-knva3nmx.js} +2 -2
- package/dist/{cli-959kp5h2.js → cli-kw44j53p.js} +13 -13
- package/dist/{cli-bsywb58a.js → cli-mdpbjnzq.js} +10 -10
- package/dist/{cli-2kvhc7x8.js → cli-me0r8gzr.js} +35 -76
- package/dist/{cli-4vzgeta4.js → cli-mwwmka77.js} +14 -14
- package/dist/{cli-q24n86d2.js → cli-n5t077me.js} +2 -2
- package/dist/{cli-rvhdmjvt.js → cli-nx2n3z6p.js} +1 -1
- package/dist/{cli-28fq781p.js → cli-pe4d96rb.js} +1 -1
- package/dist/{cli-3rkdne1h.js → cli-pxwtcgcp.js} +2 -2
- package/dist/{cli-n6vtrcht.js → cli-qmqt520k.js} +2 -2
- package/dist/{cli-pchypa1s.js → cli-qps8je6j.js} +17 -2
- package/dist/{cli-97ae65rz.js → cli-rjvsf9qa.js} +5 -5
- package/dist/{cli-e1p3n5gq.js → cli-rqfvkx5t.js} +6 -6
- package/dist/{cli-3vmb0n58.js → cli-s7zz734a.js} +1 -1
- package/dist/{cli-rmzsadkf.js → cli-s8p8hhty.js} +2 -2
- package/dist/{cli-j24zbska.js → cli-sdvcrq5x.js} +5 -5
- package/dist/{cli-5y340nzn.js → cli-sg27rk2t.js} +5 -5
- package/dist/{cli-d6521kb5.js → cli-skmhsnqh.js} +1 -1
- package/dist/{cli-5mrq3ake.js → cli-t4dv07kr.js} +1 -1
- package/dist/{cli-z1w943va.js → cli-t5ys4ebm.js} +3 -3
- package/dist/{cli-f4r3g076.js → cli-tas6ckky.js} +2 -2
- package/dist/{cli-1pz0330a.js → cli-tf79ryyy.js} +1 -1
- package/dist/{cli-kc7v1nfv.js → cli-tnzebztn.js} +1 -1
- package/dist/{cli-pfs8adn4.js → cli-vx421edw.js} +3 -3
- package/dist/{cli-kchjb7qy.js → cli-x3ex5bqf.js} +1 -1
- package/dist/cli-yss07azk.js +142 -0
- package/dist/{cli-fwy8kfd6.js → cli-z8cvws4c.js} +98 -16
- package/dist/{cli-g5mtmf6t.js → cli-zdaypkq9.js} +146 -52
- package/dist/{cli-fpjmegdb.js → cli-zeaehgyd.js} +2 -2
- package/dist/{cli-837vfs2x.js → cli-ztq5z4e1.js} +4 -4
- package/dist/cli.js +20 -20
- package/dist/{codex-adapter-zerf5qsp.js → codex-adapter-2brxx5ta.js} +7 -8
- package/dist/{codex-hook-30gyhzxe.js → codex-hook-c930c3ea.js} +1 -1
- package/dist/{codex-login-bcda78ge.js → codex-login-cbrs1h5w.js} +1 -1
- package/dist/{codex-session-runner-89s304py.js → codex-session-runner-y9anfj0r.js} +8 -9
- package/dist/{commands-jeh1b51j.js → commands-wn9q06qr.js} +3 -3
- package/dist/{controller-mctfbrse.js → controller-fw608czd.js} +4 -4
- package/dist/{controllers-connect-nxa1ddwn.js → controllers-connect-63j5rdcm.js} +20 -20
- package/dist/{cursor-adapter-qj8vehv6.js → cursor-adapter-6mb9jme8.js} +2 -2
- package/dist/{db-2dvay0es.js → db-0m6v5tq4.js} +3 -3
- package/dist/{db-b36qn6k3.js → db-y4wfrzbm.js} +4 -2
- package/dist/{devin-adapter-xedz98zv.js → devin-adapter-r0yx3gv8.js} +1 -1
- package/dist/{dispatcher-gndbta01.js → dispatcher-9tq2zzdj.js} +17 -17
- package/dist/{docker-866qpzt9.js → docker-j75atvpt.js} +2 -2
- package/dist/{dsh-adapter-f75sz821.js → dsh-adapter-t09sv4tq.js} +2 -2
- package/dist/{e2b-jbm7mj93.js → e2b-7s9dscap.js} +2 -2
- package/dist/{e2b-3gpc2n3w.js → e2b-a7vzs2vj.js} +2 -2
- package/dist/{easter-egg-3d-533knw22.js → easter-egg-3d-fbwvmwhe.js} +1 -1
- package/dist/{embedding-space-4p05vb2x.js → embedding-space-wh8de1t9.js} +6 -6
- package/dist/{embeddings-m6768mgh.js → embeddings-3hpbdtjr.js} +1 -1
- package/dist/{event-bus-e66gh7cc.js → event-bus-tr6h3gv8.js} +1 -1
- package/dist/{execute-b3mrb1mv.js → execute-4bdf8sdy.js} +1 -1
- package/dist/{external-channel-gjv3jne3.js → external-channel-ts2fwqh0.js} +2 -2
- package/dist/fx-adapter-1rnxnf56.js +17 -0
- package/dist/grok-adapter-efhmf1r8.js +17 -0
- package/dist/handlers-anrr3py9.js +32 -0
- package/dist/{heartbeat-a1tv60gt.js → heartbeat-2ze5fzpc.js} +20 -20
- package/dist/{hook-8h5dzcgq.js → hook-ca54yd4s.js} +5 -5
- package/dist/{hook-cyaps9ba.js → hook-gaehe2w5.js} +7 -7
- package/dist/{http-t15mhbd9.js → http-jfg8t2yk.js} +3861 -1798
- package/dist/{index-tvfafeyy.js → index-3gv6sc4z.js} +1 -1
- package/dist/{index-qav6455f.js → index-3yvzbhxd.js} +97 -22
- package/dist/index-8w2aznds.js +33 -0
- package/dist/{index-w1zqf680.js → index-csgrxedz.js} +1 -1
- package/dist/index-qnjvr362.js +37 -0
- package/dist/index-yzxd3sn9.js +32 -0
- package/dist/{keepalive-91s7hzrb.js → keepalive-k2a3qe73.js} +4 -4
- package/dist/lead-zhxqbfdv.js +69 -0
- package/dist/{maintenance-7pjmy5xy.js → maintenance-gb5sd5nc.js} +1 -1
- package/dist/{node-4c5jqxr3.js → node-7qsx5kvm.js} +1 -1
- package/dist/{oauth-refresh-sweep-rzqfm94j.js → oauth-refresh-sweep-y7rm6bkb.js} +3 -3
- package/dist/{onboard-74st7pag.js → onboard-jmc5qerv.js} +3 -3
- package/dist/{opencode-adapter-arn7gm8q.js → opencode-adapter-7eade9ev.js} +6 -7
- package/dist/{otel-impl-rnzey8cb.js → otel-impl-8j1xhxqd.js} +2 -2
- package/dist/{pi-mono-adapter-6mkwq64n.js → pi-mono-adapter-yqmaf32x.js} +13 -13
- package/dist/{pricing-refresh-ha21jhk7.js → pricing-refresh-1nj722h6.js} +2 -2
- package/dist/{rbac-roles-wqhma4dr.js → rbac-roles-b1mtr6dr.js} +3 -3
- package/dist/{rbac-roles-59dxachk.js → rbac-roles-n1f3frk1.js} +2 -2
- package/dist/{render-v2-14kpzx12.js → render-v2-1gfpd8rj.js} +4 -4
- package/dist/{resume-gsa5fb5f.js → resume-w1s1eh5v.js} +7 -7
- package/dist/{runtime-1hv06jsn.js → runtime-84g5egsc.js} +1 -1
- package/dist/{session-access-skm7bnp6.js → session-access-y6z1txk4.js} +4 -4
- package/dist/{session-source-backfill-pbqzbncv.js → session-source-backfill-gxxwfh12.js} +3 -3
- package/dist/{setup-5yermsem.js → setup-r91gstyk.js} +1 -1
- package/dist/{virtual-modules-gazyapte.js → virtual-modules-cgnj6kme.js} +3 -3
- package/dist/{work-objects-xj0ck0w4.js → work-objects-qcxzg61c.js} +20 -20
- package/dist/worker-7j2907g6.js +69 -0
- package/dist/{worker-follow-up-911xc0b8.js → worker-follow-up-y2d2h7km.js} +17 -17
- package/dist/{x-2fyrt5pp.js → x-qhxq2ama.js} +2 -2
- package/openapi.json +1214 -108
- package/package.json +3 -3
- package/src/be/db/tasks/read.ts +33 -0
- package/src/be/db.ts +32 -7
- package/src/be/migrations/289_automation_savings_daily.sql +47 -0
- package/src/be/migrations/291_task_slack_participants.sql +4 -0
- package/src/be/migrations/293_savings_component_links.sql +58 -0
- package/src/be/migrations/296_automation_savings_daily_read_index.sql +6 -0
- package/src/be/model-profile-check.ts +10 -2
- package/src/be/savings/compute.ts +511 -16
- package/src/be/savings/model.ts +282 -14
- package/src/be/savings/read.ts +1500 -0
- package/src/be/savings/rollup.ts +571 -0
- package/src/be/scripts/run-credential.ts +15 -3
- package/src/be/scripts/typecheck.ts +86 -4
- package/src/be/seed-scripts/catalog/dreaming-learnings.ts +10 -2
- package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +70 -4
- package/src/be/swarm-config-guard.ts +8 -0
- package/src/be/users.ts +29 -2
- package/src/commands/runner.ts +159 -41
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/index.ts +8 -1
- package/src/http/poll.ts +14 -1
- package/src/http/requested-by.ts +97 -1
- package/src/http/savings.ts +676 -190
- package/src/http/scripts.ts +26 -15
- package/src/http/tasks.ts +43 -5
- package/src/prompts/session-templates.ts +80 -3
- package/src/providers/acp-targets.ts +1 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/claude-adapter.ts +0 -20
- package/src/providers/claude-flag-settings.ts +12 -10
- package/src/providers/codex-adapter.ts +9 -34
- package/src/providers/opencode-adapter.ts +34 -12
- package/src/scheduler/scheduler.ts +20 -14
- package/src/scripts-runtime/ctx.ts +1 -1
- package/src/scripts-runtime/executors/quickjs-bundle.ts +1 -0
- package/src/scripts-runtime/executors/quickjs-prelude.ts +162 -2
- package/src/scripts-runtime/executors/quickjs-runner.ts +4 -1
- package/src/scripts-runtime/stdlib/fetch.ts +113 -15
- package/src/scripts-runtime/stdlib/index.ts +3 -1
- package/src/scripts-runtime/stdlib/retry.ts +174 -0
- package/src/scripts-runtime/swarm-sdk.ts +186 -17
- package/src/scripts-runtime/types/stdlib.d.ts +86 -4
- package/src/scripts-runtime/types/swarm-extension.d.ts +26 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +60 -2
- package/src/slack/actions.ts +1 -0
- package/src/slack/assistant.ts +2 -0
- package/src/slack/enrich.ts +144 -50
- package/src/slack/handlers.ts +37 -95
- package/src/slack/templates.ts +9 -0
- package/src/slack/thread-buffer.ts +45 -71
- package/src/slack/thread-participants.ts +187 -0
- package/src/tests/base-prompt.test.ts +5 -4
- package/src/tests/claude-adapter-binary.test.ts +7 -1
- package/src/tests/claude-adapter.test.ts +10 -64
- package/src/tests/claude-flag-settings.test.ts +15 -11
- package/src/tests/claude-hook-credentials.test.ts +0 -1
- package/src/tests/claude-sdk-lifecycle.test.ts +5 -1
- package/src/tests/codex-adapter.test.ts +17 -78
- package/src/tests/create-task-vcs-repo.test.ts +136 -0
- package/src/tests/db-task-read-contract.test.ts +2 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dreaming-learnings.test.ts +104 -0
- package/src/tests/extensions-pre-task.test.ts +4 -2
- package/src/tests/fetch-resolved-env.test.ts +47 -1
- package/src/tests/opencode-adapter.test.ts +53 -6
- package/src/tests/prompt-template-session.test.ts +17 -1
- package/src/tests/runner-requester-profile.test.ts +139 -1
- package/src/tests/savings-compound.test.ts +774 -0
- package/src/tests/savings-compute.test.ts +7 -198
- package/src/tests/savings-fleet-latency.test.ts +143 -0
- package/src/tests/savings-fleet-read.test.ts +195 -0
- package/src/tests/savings-fleet-scale.test.ts +222 -0
- package/src/tests/savings-model.test.ts +212 -0
- package/src/tests/savings-read.test.ts +367 -0
- package/src/tests/savings-rollup.test.ts +766 -0
- package/src/tests/savings-scripts.test.ts +611 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-executor-conformance.test.ts +444 -0
- package/src/tests/scripts-http.test.ts +55 -0
- package/src/tests/scripts-runtime-fetch.test.ts +2 -2
- package/src/tests/secret-rules.test.ts +124 -1
- package/src/tests/secret-scrubber.test.ts +1 -1
- package/src/tests/slack-dm-implicit-mention.test.ts +20 -1
- package/src/tests/slack-identity-resolution.test.ts +23 -0
- package/src/tests/slack-inbound-files.test.ts +2 -1
- package/src/tests/slack-thread-participants.test.ts +429 -0
- package/src/tests/tool-annotations.test.ts +30 -0
- package/src/types.ts +31 -0
- package/src/utils/mcp-server-fetcher.test.ts +89 -0
- package/src/utils/mcp-server-fetcher.ts +13 -5
- package/src/utils/request-auth-context.ts +24 -0
- package/src/utils/secret-rules.generated.ts +1 -1
- package/src/utils/secret-scrubber.ts +154 -29
- package/src/workflows/executors/swarm-script.ts +23 -19
- package/templates/skills/swarm-scripts/SKILL.md +5 -4
- package/templates/skills/swarm-scripts/content.md +5 -4
- package/templates/skills/work-on-task/SKILL.md +1 -1
- package/templates/skills/work-on-task/content.md +1 -1
- package/templates/workflows/dreaming/content.md +1 -1
- package/dist/acp-adapter-fqzkxyra.js +0 -15
- package/dist/cli-4bd1rck6.js +0 -4
- package/dist/cli-xf3qw745.js +0 -104
- package/dist/fx-adapter-rpsgb1tw.js +0 -18
- package/dist/grok-adapter-n2m3zjg1.js +0 -18
- package/dist/handlers-nv8edn19.js +0 -32
- package/dist/index-ksmyd6kc.js +0 -37
- package/dist/index-rjnrje98.js +0 -32
- package/dist/index-tv3413wy.js +0 -33
- package/dist/lead-3hmddvrm.js +0 -70
- package/dist/worker-qgg0m2gw.js +0 -70
- package/src/providers/ctx-mode-env.ts +0 -10
|
@@ -2,6 +2,7 @@ import { scrubObject } from "../utils/secret-scrubber";
|
|
|
2
2
|
import { Redacted } from "./redacted";
|
|
3
3
|
import { readScriptSdkJsonResponse } from "./response-limit";
|
|
4
4
|
import { isSdkToolAllowed, mcpToolNameForSdkMethod } from "./sdk-allowlist";
|
|
5
|
+
import { backoffMs, retryAfterMs } from "./stdlib/retry";
|
|
5
6
|
import type { SwarmConfig } from "./swarm-config";
|
|
6
7
|
|
|
7
8
|
type BridgeRequest = {
|
|
@@ -474,11 +475,158 @@ function bridgeRequestFor(name: string, args: unknown): BridgeRequest | null {
|
|
|
474
475
|
}
|
|
475
476
|
}
|
|
476
477
|
|
|
478
|
+
// ── transient-failure retries ──
|
|
479
|
+
// Every ctx.swarm call retries a 429 (the rate limiter refused it before any
|
|
480
|
+
// work ran). A 502/503/504 or a network error retries only when a repeat is
|
|
481
|
+
// safe: a read, or a write whose route dedupes by its `Idempotency-Key`
|
|
482
|
+
// header (workflow_trigger with `idempotencyKey`). Any other write may have
|
|
483
|
+
// landed, and a second call would repeat it. script_run's `idempotencyKey`
|
|
484
|
+
// does not count: it overwrites a KV entry and does not dedupe the run.
|
|
485
|
+
const BRIDGE_MAX_RETRIES = 3;
|
|
486
|
+
const BRIDGE_MIN_DELAY_MS = 250;
|
|
487
|
+
const BRIDGE_MAX_DELAY_MS = 2_000;
|
|
488
|
+
/** Total retry time per call, so retries cannot eat the script's wall clock. */
|
|
489
|
+
const BRIDGE_RETRY_BUDGET_MS = 5_000;
|
|
490
|
+
const READ_RETRY_STATUSES = new Set([502, 503, 504]);
|
|
491
|
+
|
|
492
|
+
// MCP tool names that only read. Prefix/suffix rules cover get-* / list-* /
|
|
493
|
+
// *-get / *-list / *-search; the set lists the rest. A tool missing here is
|
|
494
|
+
// treated as a write, which is the safe default. tool-annotations.test.ts
|
|
495
|
+
// fails when a tool annotated `readOnlyHint: true` is missing here.
|
|
496
|
+
// read-messages may mark messages read; repeating that is harmless.
|
|
497
|
+
const READ_TOOL_PATTERN = /^(get|list)-|-(get|list|search)$/;
|
|
498
|
+
const READ_TOOLS = new Set([
|
|
499
|
+
"db-query",
|
|
500
|
+
"kv-get",
|
|
501
|
+
"kv-list",
|
|
502
|
+
"my-agent-info",
|
|
503
|
+
"script-query-types",
|
|
504
|
+
"skill-get-file",
|
|
505
|
+
"slack-read",
|
|
506
|
+
"slack-list-channels",
|
|
507
|
+
"chat-read-thread",
|
|
508
|
+
"app-rows-list",
|
|
509
|
+
"app-row-get",
|
|
510
|
+
"app-history",
|
|
511
|
+
"app-diff",
|
|
512
|
+
"context-history",
|
|
513
|
+
"context-diff",
|
|
514
|
+
"extension-catalog",
|
|
515
|
+
"tracker-status",
|
|
516
|
+
"tracker-sync-status",
|
|
517
|
+
"app-query",
|
|
518
|
+
"resolve-user",
|
|
519
|
+
"room-decode",
|
|
520
|
+
"read-messages",
|
|
521
|
+
"check-model-profile",
|
|
522
|
+
"preview-prompt-template",
|
|
523
|
+
]);
|
|
524
|
+
// GET routes that change state: polling claims work.
|
|
525
|
+
const NON_READ_GET_METHODS = new Set(["task_poll"]);
|
|
526
|
+
|
|
527
|
+
export function isReadOnlyBridgeCall(name: string, method: string): boolean {
|
|
528
|
+
if (method === "GET") return !NON_READ_GET_METHODS.has(name);
|
|
529
|
+
const tool = mcpToolNameForSdkMethod(name);
|
|
530
|
+
return READ_TOOL_PATTERN.test(tool) || READ_TOOLS.has(tool);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function hasIdempotencyKey(headers: Record<string, string> | undefined): boolean {
|
|
534
|
+
return Object.keys(headers ?? {}).some((key) => key.toLowerCase() === "idempotency-key");
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/** A keyed write may repeat, but it stays a write: only a read gets the retry deadline. */
|
|
538
|
+
function bridgeSafety(readOnly: boolean, keyed: boolean) {
|
|
539
|
+
return { repeatSafe: readOnly || keyed, readOnly };
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** Waits `ms`, or less when `signal` aborts first. */
|
|
543
|
+
function sleep(ms: number, signal: AbortSignal | undefined): Promise<void> {
|
|
544
|
+
return new Promise((resolve) => {
|
|
545
|
+
const done = () => {
|
|
546
|
+
clearTimeout(timer);
|
|
547
|
+
signal?.removeEventListener("abort", done);
|
|
548
|
+
resolve();
|
|
549
|
+
};
|
|
550
|
+
const timer = setTimeout(done, ms);
|
|
551
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* What a retry that ran out of budget hands back: the failure the caller would
|
|
557
|
+
* have seen with no retry, the earlier status with a note in place of its
|
|
558
|
+
* already-cancelled body.
|
|
559
|
+
*/
|
|
560
|
+
function budgetSpentResponse(previous: Response): Response {
|
|
561
|
+
return Response.json(
|
|
562
|
+
{
|
|
563
|
+
error: `HTTP ${previous.status}; the retry did not answer within the ${BRIDGE_RETRY_BUDGET_MS}ms retry budget`,
|
|
564
|
+
},
|
|
565
|
+
{ status: previous.status, statusText: previous.statusText },
|
|
566
|
+
);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* `signal` is the run's own signal (quickjs aborts it when the run ends): an
|
|
571
|
+
* aborted run gets the current outcome at once, never another wait or attempt.
|
|
572
|
+
*
|
|
573
|
+
* `repeatSafe`: a 502/503/504 or a network error may be retried (a read, or a
|
|
574
|
+
* keyed write). `readOnly`: the call only reads.
|
|
575
|
+
*
|
|
576
|
+
* The first attempt runs unbounded, as it did before retries existed. A retry
|
|
577
|
+
* of a read is cut off when the retry budget is spent, and the caller gets
|
|
578
|
+
* the earlier failure. A write's retry, keyed or not, is never cut off: it may
|
|
579
|
+
* be the write's first real run (after a 429) or start the work a keyed route
|
|
580
|
+
* dedupes, and cutting it off reports a failure for work that went ahead.
|
|
581
|
+
*/
|
|
582
|
+
async function bridgeFetch(
|
|
583
|
+
url: string,
|
|
584
|
+
init: RequestInit,
|
|
585
|
+
{ repeatSafe, readOnly }: { repeatSafe: boolean; readOnly: boolean },
|
|
586
|
+
signal: AbortSignal | undefined,
|
|
587
|
+
): Promise<Response> {
|
|
588
|
+
const started = Date.now();
|
|
589
|
+
const remaining = () => BRIDGE_RETRY_BUDGET_MS - (Date.now() - started);
|
|
590
|
+
const fits = (delay: number) => delay <= remaining();
|
|
591
|
+
let previous: { response: Response } | { error: unknown } | undefined;
|
|
592
|
+
for (let attempt = 1; ; attempt++) {
|
|
593
|
+
const budget = previous && readOnly ? AbortSignal.timeout(Math.max(1, remaining())) : undefined;
|
|
594
|
+
let res: Response;
|
|
595
|
+
try {
|
|
596
|
+
res = await fetch(url, budget ? { ...init, signal: budget } : init);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
if (budget?.aborted && !signal?.aborted && previous) {
|
|
599
|
+
if ("error" in previous) throw previous.error;
|
|
600
|
+
return budgetSpentResponse(previous.response);
|
|
601
|
+
}
|
|
602
|
+
const delay = backoffMs(attempt, BRIDGE_MIN_DELAY_MS, BRIDGE_MAX_DELAY_MS);
|
|
603
|
+
// An abort means the run is ending: settle now, never wait and retry.
|
|
604
|
+
const aborted = signal?.aborted || (error instanceof Error && error.name === "AbortError");
|
|
605
|
+
if (aborted || !repeatSafe || attempt > BRIDGE_MAX_RETRIES || !fits(delay)) throw error;
|
|
606
|
+
previous = { error };
|
|
607
|
+
await sleep(delay, signal);
|
|
608
|
+
if (signal?.aborted) throw error;
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
const retryable = res.status === 429 || (repeatSafe && READ_RETRY_STATUSES.has(res.status));
|
|
612
|
+
if (!retryable || attempt > BRIDGE_MAX_RETRIES || signal?.aborted) return res;
|
|
613
|
+
const delay =
|
|
614
|
+
(res.status === 429 ? retryAfterMs(res.headers.get("retry-after")) : undefined) ??
|
|
615
|
+
backoffMs(attempt, BRIDGE_MIN_DELAY_MS, BRIDGE_MAX_DELAY_MS);
|
|
616
|
+
// A Retry-After past the budget: hand the 429 back rather than wait.
|
|
617
|
+
if (!fits(delay)) return res;
|
|
618
|
+
await res.body?.cancel().catch(() => {});
|
|
619
|
+
previous = { response: res };
|
|
620
|
+
await sleep(delay, signal);
|
|
621
|
+
if (signal?.aborted) return res;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
|
|
477
625
|
async function callBridgeApi(
|
|
478
626
|
name: string,
|
|
479
627
|
args: unknown,
|
|
480
628
|
config: SwarmConfig,
|
|
481
|
-
options: { throwOnError?: boolean; preserveData?: boolean } = {},
|
|
629
|
+
options: { throwOnError?: boolean; preserveData?: boolean; signal?: AbortSignal } = {},
|
|
482
630
|
): Promise<unknown> {
|
|
483
631
|
const baseUrl = Redacted.value(config.mcpBaseUrl).replace(/\/$/, "");
|
|
484
632
|
const request = bridgeRequestFor(name, args);
|
|
@@ -486,11 +634,16 @@ async function callBridgeApi(
|
|
|
486
634
|
// Tools without a specific REST route go through the generic MCP bridge
|
|
487
635
|
if (!request) {
|
|
488
636
|
const mcpToolName = mcpToolNameForSdkMethod(name);
|
|
489
|
-
const res = await
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
637
|
+
const res = await bridgeFetch(
|
|
638
|
+
`${baseUrl}/api/mcp-bridge`,
|
|
639
|
+
{
|
|
640
|
+
method: "POST",
|
|
641
|
+
headers: headers(config),
|
|
642
|
+
body: JSON.stringify({ tool: mcpToolName, args: args ?? {} }),
|
|
643
|
+
},
|
|
644
|
+
bridgeSafety(isReadOnlyBridgeCall(name, "POST"), false),
|
|
645
|
+
options.signal,
|
|
646
|
+
);
|
|
494
647
|
const data = await readScriptSdkJsonResponse(res, `ctx.swarm.${name}`);
|
|
495
648
|
if (!res.ok && options.throwOnError) {
|
|
496
649
|
const message =
|
|
@@ -519,11 +672,16 @@ async function callBridgeApi(
|
|
|
519
672
|
});
|
|
520
673
|
}
|
|
521
674
|
|
|
522
|
-
const res = await
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
675
|
+
const res = await bridgeFetch(
|
|
676
|
+
`${baseUrl}${request.path}`,
|
|
677
|
+
{
|
|
678
|
+
method: request.method,
|
|
679
|
+
headers: { ...headers(config), ...request.headers },
|
|
680
|
+
body: request.body === undefined ? undefined : JSON.stringify(request.body),
|
|
681
|
+
},
|
|
682
|
+
bridgeSafety(isReadOnlyBridgeCall(name, request.method), hasIdempotencyKey(request.headers)),
|
|
683
|
+
options.signal,
|
|
684
|
+
);
|
|
527
685
|
const data = await readScriptSdkJsonResponse(res, `ctx.swarm.${name}`);
|
|
528
686
|
if (!res.ok && options.throwOnError) {
|
|
529
687
|
const message =
|
|
@@ -536,7 +694,12 @@ async function callBridgeApi(
|
|
|
536
694
|
return options.preserveData ? result : scrubObject(result);
|
|
537
695
|
}
|
|
538
696
|
|
|
539
|
-
async function callTool(
|
|
697
|
+
async function callTool(
|
|
698
|
+
name: string,
|
|
699
|
+
args: unknown,
|
|
700
|
+
config: SwarmConfig,
|
|
701
|
+
signal: AbortSignal | undefined,
|
|
702
|
+
): Promise<unknown> {
|
|
540
703
|
if (!isSdkToolAllowed(name)) {
|
|
541
704
|
throw new Error(
|
|
542
705
|
`Tool '${name}' is not exposed to scripts (lifecycle/cred tool); use the MCP surface directly if you're an agent`,
|
|
@@ -544,11 +707,11 @@ async function callTool(name: string, args: unknown, config: SwarmConfig): Promi
|
|
|
544
707
|
}
|
|
545
708
|
|
|
546
709
|
if (name === "script_search" || name === "script_run") {
|
|
547
|
-
return callBridgeApi(name, args, config, { throwOnError: true });
|
|
710
|
+
return callBridgeApi(name, args, config, { throwOnError: true, signal });
|
|
548
711
|
}
|
|
549
712
|
|
|
550
713
|
if (name === "kv_getOrNull") {
|
|
551
|
-
const result = (await callBridgeApi(name, args, config)) as {
|
|
714
|
+
const result = (await callBridgeApi(name, args, config, { signal })) as {
|
|
552
715
|
success: boolean;
|
|
553
716
|
status: number;
|
|
554
717
|
data: unknown;
|
|
@@ -564,7 +727,7 @@ async function callTool(name: string, args: unknown, config: SwarmConfig): Promi
|
|
|
564
727
|
return result.data;
|
|
565
728
|
}
|
|
566
729
|
|
|
567
|
-
return callBridgeApi(name, args, config);
|
|
730
|
+
return callBridgeApi(name, args, config, { signal });
|
|
568
731
|
}
|
|
569
732
|
|
|
570
733
|
type RoomMethods = Record<
|
|
@@ -573,11 +736,17 @@ type RoomMethods = Record<
|
|
|
573
736
|
>;
|
|
574
737
|
type RuntimeSwarmSdk = Record<string, (args?: unknown) => Promise<unknown>> & { room: RoomMethods };
|
|
575
738
|
|
|
576
|
-
|
|
739
|
+
/** `signal`: the run's abort signal; it stops bridge retries when the run ends. */
|
|
740
|
+
export function createSwarmSdk(
|
|
741
|
+
config: SwarmConfig,
|
|
742
|
+
options: { signal?: AbortSignal } = {},
|
|
743
|
+
): RuntimeSwarmSdk {
|
|
744
|
+
const { signal } = options;
|
|
577
745
|
const roomCall = (method: keyof RoomMethods) => async (args?: unknown) => {
|
|
578
746
|
const result = (await callBridgeApi(`room_${method}`, args, config, {
|
|
579
747
|
throwOnError: true,
|
|
580
748
|
preserveData: true,
|
|
749
|
+
signal,
|
|
581
750
|
})) as { data: { room?: unknown } };
|
|
582
751
|
return method === "decode" ? result.data : result.data.room;
|
|
583
752
|
};
|
|
@@ -592,7 +761,7 @@ export function createSwarmSdk(config: SwarmConfig): RuntimeSwarmSdk {
|
|
|
592
761
|
get(target, prop) {
|
|
593
762
|
if (typeof prop !== "string") return undefined;
|
|
594
763
|
if (prop in target) return target[prop];
|
|
595
|
-
return (args?: unknown) => callTool(prop, args, config);
|
|
764
|
+
return (args?: unknown) => callTool(prop, args, config, signal);
|
|
596
765
|
},
|
|
597
766
|
}) as RuntimeSwarmSdk;
|
|
598
767
|
}
|
|
@@ -9,11 +9,35 @@ declare module "stdlib" {
|
|
|
9
9
|
meta<T>(self: Redacted<T>): { type: "system" | "user"; isSecret: boolean };
|
|
10
10
|
isSecret<T>(self: Redacted<T>): boolean;
|
|
11
11
|
};
|
|
12
|
-
export function fetch(input: string | URL | Request, init?:
|
|
13
|
-
export function fetchJson(input: string | URL | Request, init?:
|
|
12
|
+
export function fetch(input: string | URL | Request, init?: FetchOptions): Promise<Response>;
|
|
13
|
+
export function fetchJson(input: string | URL | Request, init?: FetchOptions): Promise<unknown>;
|
|
14
14
|
export function grep(pattern: string, files?: string | string[]): Promise<string>;
|
|
15
15
|
export function glob(pattern: string): Promise<string[]>;
|
|
16
16
|
export function table(rows: Array<Record<string, unknown>>): string;
|
|
17
|
+
export interface RetryOptions {
|
|
18
|
+
retries?: number;
|
|
19
|
+
minDelayMs?: number;
|
|
20
|
+
maxDelayMs?: number;
|
|
21
|
+
budgetMs?: number;
|
|
22
|
+
retryOn?: (errorOrResult: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
export interface FetchRetryOptions extends RetryOptions {
|
|
26
|
+
idempotencyKey?: boolean | string;
|
|
27
|
+
}
|
|
28
|
+
export type FetchOptions = RequestInit & {
|
|
29
|
+
retry?: boolean | FetchRetryOptions;
|
|
30
|
+
/** @deprecated Use retry: { retries }. Total attempts. */
|
|
31
|
+
retries?: number;
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
};
|
|
34
|
+
export const retry: {
|
|
35
|
+
<T>(fn: (attempt: number) => T | Promise<T>, options?: RetryOptions): Promise<Awaited<T>>;
|
|
36
|
+
wrap<A extends unknown[], T>(
|
|
37
|
+
fn: (...args: A) => T | Promise<T>,
|
|
38
|
+
options?: RetryOptions,
|
|
39
|
+
): (...args: A) => Promise<Awaited<T>>;
|
|
40
|
+
};
|
|
17
41
|
}
|
|
18
42
|
|
|
19
43
|
declare module "swarm-sdk" {
|
|
@@ -750,12 +774,70 @@ declare module "swarm-sdk" {
|
|
|
750
774
|
}): Promise<unknown>;
|
|
751
775
|
}
|
|
752
776
|
|
|
777
|
+
export interface RetryOptions {
|
|
778
|
+
/** Retries after the first call. Default 3, so at most 4 calls. */
|
|
779
|
+
retries?: number;
|
|
780
|
+
/** First backoff delay in ms. Doubles on each retry, with jitter. Default 200. */
|
|
781
|
+
minDelayMs?: number;
|
|
782
|
+
/** Cap on a single wait, including a Retry-After wait. Default 5000. */
|
|
783
|
+
maxDelayMs?: number;
|
|
784
|
+
/** Total time across all calls and waits, in ms. Default 30000. */
|
|
785
|
+
budgetMs?: number;
|
|
786
|
+
/**
|
|
787
|
+
* Decides whether to retry: gets the thrown error or the returned value and
|
|
788
|
+
* the 1-based attempt. Default: retry any throw, plus a failed fetch Response,
|
|
789
|
+
* ctx.api raw result or ctx.swarm envelope with status 429, 502, 503 or 504.
|
|
790
|
+
*/
|
|
791
|
+
retryOn?: (errorOrResult: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
792
|
+
/** Stops the retries: once it aborts, the wait ends and retry rejects with its reason. */
|
|
793
|
+
signal?: AbortSignal;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
export interface FetchRetryOptions extends RetryOptions {
|
|
797
|
+
/**
|
|
798
|
+
* Sends an Idempotency-Key header, the same value on every attempt: true
|
|
799
|
+
* generates a UUID per call, a string is used as is. A POST or PATCH with
|
|
800
|
+
* the header also retries 502/503/504 and network errors. It only prevents
|
|
801
|
+
* a duplicate when the server dedupes by the key.
|
|
802
|
+
*/
|
|
803
|
+
idempotencyKey?: boolean | string;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* ctx.stdlib.fetch options. Default retries: 429 on every method (Retry-After
|
|
808
|
+
* honoured); 502/503/504 and network errors on GET, HEAD, OPTIONS, PUT, DELETE,
|
|
809
|
+
* or any request with an Idempotency-Key. A stream body gets one attempt.
|
|
810
|
+
*/
|
|
811
|
+
export type FetchOptions = RequestInit & {
|
|
812
|
+
/** false: one attempt. true or omitted: the defaults above. An object tunes them. */
|
|
813
|
+
retry?: boolean | FetchRetryOptions;
|
|
814
|
+
/** @deprecated Use retry: { retries }. Total attempts, so retries: 1 is one attempt. */
|
|
815
|
+
retries?: number;
|
|
816
|
+
/** Per-attempt timeout in ms. Default 30000. */
|
|
817
|
+
timeoutMs?: number;
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
export interface Retry {
|
|
821
|
+
/**
|
|
822
|
+
* Calls fn(attempt) (sync or async) until it succeeds or a retry is not
|
|
823
|
+
* warranted. Out of attempts or budget: rethrows the last error or returns
|
|
824
|
+
* the last result. Honours Retry-After on a 429, capped by maxDelayMs.
|
|
825
|
+
*/
|
|
826
|
+
<T>(fn: (attempt: number) => T | Promise<T>, options?: RetryOptions): Promise<Awaited<T>>;
|
|
827
|
+
/** Returns a reusable function with fn's arguments that retries each call. */
|
|
828
|
+
wrap<A extends unknown[], T>(
|
|
829
|
+
fn: (...args: A) => T | Promise<T>,
|
|
830
|
+
options?: RetryOptions,
|
|
831
|
+
): (...args: A) => Promise<Awaited<T>>;
|
|
832
|
+
}
|
|
833
|
+
|
|
753
834
|
export interface ScriptStdlib {
|
|
754
|
-
fetch(input: string | URL | Request, init?:
|
|
755
|
-
fetchJson(input: string | URL | Request, init?:
|
|
835
|
+
fetch(input: string | URL | Request, init?: FetchOptions): Promise<Response>;
|
|
836
|
+
fetchJson(input: string | URL | Request, init?: FetchOptions): Promise<unknown>;
|
|
756
837
|
grep(pattern: string, files?: string | string[]): Promise<string>;
|
|
757
838
|
glob(pattern: string): Promise<string[]>;
|
|
758
839
|
table(rows: Array<Record<string, unknown>>): string;
|
|
840
|
+
retry: Retry;
|
|
759
841
|
Redacted: RedactedStatic;
|
|
760
842
|
}
|
|
761
843
|
|
|
@@ -41,6 +41,19 @@ declare module "swarm-extension" {
|
|
|
41
41
|
slackThreadTs?: string | undefined;
|
|
42
42
|
slackTriggerMessageTs?: string | undefined;
|
|
43
43
|
slackUserId?: string | undefined;
|
|
44
|
+
slackParticipants?:
|
|
45
|
+
| {
|
|
46
|
+
people: {
|
|
47
|
+
slackUserId: string;
|
|
48
|
+
trust: "external" | "unknown" | "internal";
|
|
49
|
+
userId?: string | undefined;
|
|
50
|
+
starter?: boolean | undefined;
|
|
51
|
+
newest?: boolean | undefined;
|
|
52
|
+
asked?: boolean | undefined;
|
|
53
|
+
}[];
|
|
54
|
+
more: number;
|
|
55
|
+
}
|
|
56
|
+
| undefined;
|
|
44
57
|
overrideSlackContext?: boolean | undefined;
|
|
45
58
|
vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;
|
|
46
59
|
vcsRepo?: string | undefined;
|
|
@@ -192,6 +205,19 @@ declare module "swarm-extension" {
|
|
|
192
205
|
slackThreadTs?: string | undefined;
|
|
193
206
|
slackTriggerMessageTs?: string | undefined;
|
|
194
207
|
slackUserId?: string | undefined;
|
|
208
|
+
slackParticipants?:
|
|
209
|
+
| {
|
|
210
|
+
people: {
|
|
211
|
+
slackUserId: string;
|
|
212
|
+
trust: "external" | "unknown" | "internal";
|
|
213
|
+
userId?: string | undefined;
|
|
214
|
+
starter?: boolean | undefined;
|
|
215
|
+
newest?: boolean | undefined;
|
|
216
|
+
asked?: boolean | undefined;
|
|
217
|
+
}[];
|
|
218
|
+
more: number;
|
|
219
|
+
}
|
|
220
|
+
| undefined;
|
|
195
221
|
slackProgressMessageTs?: string | undefined;
|
|
196
222
|
slackTreeRootMessageTs?: string | undefined;
|
|
197
223
|
vcsProvider?: "github" | "gitlab" | "azure-devops" | "bitbucket" | undefined;
|
|
@@ -732,12 +732,70 @@ declare module "swarm-sdk" {
|
|
|
732
732
|
}): Promise<unknown>;
|
|
733
733
|
}
|
|
734
734
|
|
|
735
|
+
export interface RetryOptions {
|
|
736
|
+
/** Retries after the first call. Default 3, so at most 4 calls. */
|
|
737
|
+
retries?: number;
|
|
738
|
+
/** First backoff delay in ms. Doubles on each retry, with jitter. Default 200. */
|
|
739
|
+
minDelayMs?: number;
|
|
740
|
+
/** Cap on a single wait, including a Retry-After wait. Default 5000. */
|
|
741
|
+
maxDelayMs?: number;
|
|
742
|
+
/** Total time across all calls and waits, in ms. Default 30000. */
|
|
743
|
+
budgetMs?: number;
|
|
744
|
+
/**
|
|
745
|
+
* Decides whether to retry: gets the thrown error or the returned value and
|
|
746
|
+
* the 1-based attempt. Default: retry any throw, plus a failed fetch Response,
|
|
747
|
+
* ctx.api raw result or ctx.swarm envelope with status 429, 502, 503 or 504.
|
|
748
|
+
*/
|
|
749
|
+
retryOn?: (errorOrResult: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
750
|
+
/** Stops the retries: once it aborts, the wait ends and retry rejects with its reason. */
|
|
751
|
+
signal?: AbortSignal;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
export interface FetchRetryOptions extends RetryOptions {
|
|
755
|
+
/**
|
|
756
|
+
* Sends an Idempotency-Key header, the same value on every attempt: true
|
|
757
|
+
* generates a UUID per call, a string is used as is. A POST or PATCH with
|
|
758
|
+
* the header also retries 502/503/504 and network errors. It only prevents
|
|
759
|
+
* a duplicate when the server dedupes by the key.
|
|
760
|
+
*/
|
|
761
|
+
idempotencyKey?: boolean | string;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* ctx.stdlib.fetch options. Default retries: 429 on every method (Retry-After
|
|
766
|
+
* honoured); 502/503/504 and network errors on GET, HEAD, OPTIONS, PUT, DELETE,
|
|
767
|
+
* or any request with an Idempotency-Key. A stream body gets one attempt.
|
|
768
|
+
*/
|
|
769
|
+
export type FetchOptions = RequestInit & {
|
|
770
|
+
/** false: one attempt. true or omitted: the defaults above. An object tunes them. */
|
|
771
|
+
retry?: boolean | FetchRetryOptions;
|
|
772
|
+
/** @deprecated Use retry: { retries }. Total attempts, so retries: 1 is one attempt. */
|
|
773
|
+
retries?: number;
|
|
774
|
+
/** Per-attempt timeout in ms. Default 30000. */
|
|
775
|
+
timeoutMs?: number;
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
export interface Retry {
|
|
779
|
+
/**
|
|
780
|
+
* Calls fn(attempt) (sync or async) until it succeeds or a retry is not
|
|
781
|
+
* warranted. Out of attempts or budget: rethrows the last error or returns
|
|
782
|
+
* the last result. Honours Retry-After on a 429, capped by maxDelayMs.
|
|
783
|
+
*/
|
|
784
|
+
<T>(fn: (attempt: number) => T | Promise<T>, options?: RetryOptions): Promise<Awaited<T>>;
|
|
785
|
+
/** Returns a reusable function with fn's arguments that retries each call. */
|
|
786
|
+
wrap<A extends unknown[], T>(
|
|
787
|
+
fn: (...args: A) => T | Promise<T>,
|
|
788
|
+
options?: RetryOptions,
|
|
789
|
+
): (...args: A) => Promise<Awaited<T>>;
|
|
790
|
+
}
|
|
791
|
+
|
|
735
792
|
export interface ScriptStdlib {
|
|
736
|
-
fetch(input: string | URL | Request, init?:
|
|
737
|
-
fetchJson(input: string | URL | Request, init?:
|
|
793
|
+
fetch(input: string | URL | Request, init?: FetchOptions): Promise<Response>;
|
|
794
|
+
fetchJson(input: string | URL | Request, init?: FetchOptions): Promise<unknown>;
|
|
738
795
|
grep(pattern: string, files?: string | string[]): Promise<string>;
|
|
739
796
|
glob(pattern: string): Promise<string[]>;
|
|
740
797
|
table(rows: Array<Record<string, unknown>>): string;
|
|
798
|
+
retry: Retry;
|
|
741
799
|
Redacted: RedactedStatic;
|
|
742
800
|
}
|
|
743
801
|
|
package/src/slack/actions.ts
CHANGED
|
@@ -112,6 +112,7 @@ export function registerActionHandlers(app: App): void {
|
|
|
112
112
|
const requestedByUserId = await resolveSlackUserId(client, body.user.id, {
|
|
113
113
|
sampleEventType: "view_submission",
|
|
114
114
|
sampleContext: view.callback_id || "follow_up_submit",
|
|
115
|
+
userTeam: body.user.team_id,
|
|
115
116
|
});
|
|
116
117
|
noteSlackInboundSideEffect("task_created");
|
|
117
118
|
const followUpTask = await createTaskWithSiblingAwareness(
|
package/src/slack/assistant.ts
CHANGED
|
@@ -230,6 +230,7 @@ export function createAssistant(
|
|
|
230
230
|
? await resolveSlackUserId(client, userId, {
|
|
231
231
|
sampleEventType: "assistant_message",
|
|
232
232
|
sampleContext: rawText,
|
|
233
|
+
userTeam: msg.user_team as string | undefined,
|
|
233
234
|
})
|
|
234
235
|
: undefined;
|
|
235
236
|
|
|
@@ -247,6 +248,7 @@ export function createAssistant(
|
|
|
247
248
|
message.ts,
|
|
248
249
|
files,
|
|
249
250
|
cachedBotUserId ?? undefined,
|
|
251
|
+
msg.user_team as string | undefined,
|
|
250
252
|
);
|
|
251
253
|
const count = getBufferMessageCount(`${channelId}:${threadTs}`);
|
|
252
254
|
const event = count === 1 ? "accepted" : "buffered";
|