@desplega.ai/agent-swarm 2.13.0 → 2.13.2
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/README.md +1 -1
- package/dist/acp-adapter-x1qqgzwx.js +17 -0
- package/dist/{acp-targets-86f0sh6g.js → acp-targets-mz8c5dnt.js} +10 -10
- package/dist/{actions-zv8vcxvr.js → actions-5ft3qp5a.js} +27 -27
- package/dist/{agent-fs-provision-jqshb33y.js → agent-fs-provision-6fgz7wvz.js} +4 -4
- package/dist/{amp-adapter-gt503ywc.js → amp-adapter-nthn8ezm.js} +3 -3
- package/dist/{app-6t4k5rh1.js → app-535m78qw.js} +10 -10
- package/dist/{approval-notifications-fcfw063h.js → approval-notifications-dewbk403.js} +11 -11
- package/dist/{assistant-9dzybh12.js → assistant-39zyabv2.js} +28 -28
- package/dist/{boot-args-schema-xzfp2feg.js → boot-args-schema-bqv5bf77.js} +1 -1
- package/dist/{boot-reembed-3jz0p2jk.js → boot-reembed-157c0gcz.js} +1 -1
- package/dist/{boot-reembed-r88wngfg.js → boot-reembed-fas7z3zn.js} +1 -1
- package/dist/{boot-scrub-sweep-scrqhw48.js → boot-scrub-sweep-tmec0be2.js} +2 -2
- package/dist/{boot-seeds-vb2dcrrb.js → boot-seeds-32zm50x2.js} +4 -4
- package/dist/{boxd-68n75y1s.js → boxd-hr8rsxzq.js} +1 -1
- package/dist/{claude-adapter-h3mp9hgs.js → claude-adapter-gwq7x2nj.js} +9 -9
- package/dist/{claude-managed-adapter-kpbyj2vb.js → claude-managed-adapter-rkvw6fvq.js} +4 -4
- package/dist/{claude-managed-setup-0efr3wkg.js → claude-managed-setup-0vgz4d1j.js} +6 -6
- package/dist/{claude-sdk-session-03dw669q.js → claude-sdk-session-5wbwxy8c.js} +20967 -19390
- package/dist/{cli-z64t9pe6.js → cli-0f7n3td3.js} +1 -1
- package/dist/{cli-j53hpbsm.js → cli-0xwb7zpt.js} +2 -2
- package/dist/{cli-wxwv3t11.js → cli-1f48qdnb.js} +55 -13
- package/dist/{cli-gfcv679k.js → cli-1gevjrc1.js} +1 -1
- package/dist/{cli-0jkenasr.js → cli-2v4xxnx2.js} +1 -1
- package/dist/{cli-hc6e4tac.js → cli-2wde56gv.js} +6 -6
- package/dist/{cli-mh7pdxe0.js → cli-31vt7baf.js} +17 -17
- package/dist/{cli-ercwc8xn.js → cli-3mf04tkh.js} +1 -1
- package/dist/{cli-s6zk31gr.js → cli-43dsqhcp.js} +4 -4
- package/dist/{cli-1dbv9mj9.js → cli-4djg31jh.js} +1 -1
- package/dist/{cli-tn91wc6e.js → cli-50whymxq.js} +1 -1
- package/dist/{cli-js10kdk7.js → cli-5basv0e7.js} +19 -5
- package/dist/{cli-b2jh3dyb.js → cli-5k1hvycs.js} +4 -4
- package/dist/{cli-dkejt425.js → cli-62fjschk.js} +7 -7
- package/dist/{cli-zqmmy073.js → cli-69eq6gdk.js} +18 -18
- package/dist/{cli-qm3ntjqs.js → cli-6rmryz03.js} +13 -13
- package/dist/{cli-mz34pxbk.js → cli-7m6bbtab.js} +11 -11
- package/dist/{cli-wv20kbr3.js → cli-8a4qg44m.js} +5 -5
- package/dist/{cli-2m6yaq6b.js → cli-8fj8yfmk.js} +1 -1
- package/dist/{cli-9m9kyw77.js → cli-8qvte9hn.js} +2 -2
- package/dist/{cli-x05p2d05.js → cli-9tevdxyf.js} +1 -1
- package/dist/{cli-qec9bynj.js → cli-a6rzw649.js} +3 -3
- package/dist/{cli-ex1y88j3.js → cli-at67kvnp.js} +1 -1
- package/dist/{cli-yn4kt85g.js → cli-b0kqw55g.js} +1 -1
- package/dist/{cli-n3qe7tyr.js → cli-b0m3bg0f.js} +134 -3
- package/dist/{cli-xfjn2kyq.js → cli-bp2rt28p.js} +9 -9
- package/dist/{cli-2jk4s7z1.js → cli-c9bwawf9.js} +3 -3
- package/dist/{cli-wndegmns.js → cli-cmgdptmx.js} +3 -3
- package/dist/{cli-3p288654.js → cli-cpkxh68d.js} +2 -2
- package/dist/{cli-117g15t4.js → cli-cs26ed89.js} +8 -8
- package/dist/{cli-prf7kz78.js → cli-d0jb2qnt.js} +603 -78
- package/dist/{cli-8hp56wat.js → cli-d2epqm0y.js} +1 -1
- package/dist/{cli-wrhbym01.js → cli-d528acsw.js} +6 -6
- package/dist/{cli-tstj6e8e.js → cli-dnvmwsvc.js} +310 -88
- package/dist/{cli-9fsagra4.js → cli-e87fg3en.js} +1 -1
- package/dist/{cli-jj3c5nyb.js → cli-erh1rgh4.js} +116 -56
- package/dist/{cli-f1952kjy.js → cli-ewb028rs.js} +4 -4
- package/dist/{cli-ct8sz3np.js → cli-f1sdh8ca.js} +6 -6
- package/dist/{cli-0b655smz.js → cli-fcwrd7bh.js} +5 -5
- package/dist/{cli-eb279wn3.js → cli-fgm2mad9.js} +2 -2
- package/dist/{cli-bpje8n65.js → cli-fp65jdp2.js} +31 -6
- package/dist/{cli-dnh64e8e.js → cli-g0b3ma7r.js} +7 -7
- package/dist/{cli-avxh26pd.js → cli-gc7jkf4a.js} +4 -4
- package/dist/{cli-2skf1mdf.js → cli-gedf48yw.js} +4 -4
- package/dist/{cli-ajjvqhf3.js → cli-getrvmtx.js} +27 -6
- package/dist/{cli-c8v2yvej.js → cli-gq6qhmrr.js} +2 -2
- package/dist/{cli-mbwmqb5w.js → cli-h0ewec3d.js} +1 -1
- package/dist/{cli-tdk7jtka.js → cli-hv3820ez.js} +1 -1
- package/dist/{cli-avqkr20b.js → cli-j2ybkdk2.js} +2 -2
- package/dist/{cli-pqfecppn.js → cli-je587f74.js} +1 -1
- package/dist/{cli-hgsxnjyg.js → cli-jkkcm72j.js} +13 -13
- package/dist/{cli-g6j6ac3h.js → cli-ka13xx6b.js} +2 -2
- package/dist/{cli-t35hx078.js → cli-m1wddksc.js} +2 -2
- package/dist/{cli-50w82h6m.js → cli-mwxez0pz.js} +1 -0
- package/dist/{cli-nc6a8b5b.js → cli-n14r8h4n.js} +2 -2
- package/dist/{cli-y4a4458j.js → cli-n46d87mj.js} +3 -3
- package/dist/{cli-0dg7ytxm.js → cli-nkfv398a.js} +1096 -75
- package/dist/{cli-fhvk2nvp.js → cli-nvqq3232.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-hbq0kwxz.js → cli-r4fphq38.js} +4 -4
- package/dist/{cli-47hz21se.js → cli-r8ddn0hf.js} +4 -5
- package/dist/{cli-hpb9x72z.js → cli-rvhaahfv.js} +9 -9
- package/dist/{cli-qhhb30e8.js → cli-s08zsqva.js} +9 -9
- package/dist/{cli-sdh61g52.js → cli-s6fhqbz1.js} +2 -2
- package/dist/{cli-y518qkjg.js → cli-sjk85d7v.js} +13 -12
- package/dist/{cli-ytc7fpza.js → cli-t25rq8mg.js} +4 -4
- package/dist/{cli-sq913bh1.js → cli-t9nxq30h.js} +8 -8
- package/dist/{cli-49f5jyhh.js → cli-tbdw3f92.js} +3 -3
- package/dist/{cli-1v82d2w6.js → cli-tceqvv6h.js} +4 -4
- package/dist/{cli-fz9pcjsw.js → cli-tgmate57.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-7dbhnsj9.js → cli-wdtqkqnq.js} +4 -4
- package/dist/{cli-kde4ky90.js → cli-x5yb8zc8.js} +2 -2
- package/dist/{cli-w14j2z4k.js → cli-x7aqhxj5.js} +2 -2
- package/dist/{cli-kspxjftk.js → cli-xerdrnqs.js} +15 -6
- package/dist/{cli-48nvk6sb.js → cli-xhkek467.js} +2 -2
- package/dist/{cli-dka73bak.js → cli-xysy1g8x.js} +152 -12
- package/dist/{cli-7wy8gbwb.js → cli-ya1cj689.js} +1 -1
- package/dist/{cli-n85m2wkq.js → cli-zkbz8m2q.js} +3 -2
- package/dist/{cli-0pazkmd4.js → cli-zm6bkx3e.js} +4 -4
- package/dist/{cli-6h88mn9q.js → cli-zqy28rwx.js} +4 -4
- package/dist/cli.js +30 -29
- package/dist/{codex-adapter-f3yp0kaj.js → codex-adapter-x25xfbnh.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-kn5xnrvp.js} +9 -9
- package/dist/{commands-5bzf2tfw.js → commands-8n59gxmy.js} +3 -3
- package/dist/{controller-5xt7kvfm.js → controller-wn3vd217.js} +3 -3
- package/dist/{controllers-connect-0gg13mzp.js → controllers-connect-09gvkrhc.js} +28 -28
- package/dist/core-2b8bv6ny.js +42 -0
- package/dist/{cursor-adapter-p0c5zv6r.js → cursor-adapter-w1681kp1.js} +2 -2
- package/dist/{db-2s68ycq7.js → db-e71keqxk.js} +3 -3
- package/dist/{db-q7q639k5.js → db-spg81qtr.js} +2 -2
- package/dist/{devin-adapter-t8d86q9x.js → devin-adapter-fs90ab4v.js} +1 -1
- package/dist/{dispatcher-j2y1q7ae.js → dispatcher-fr4vawwb.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-ac9tv9a6.js} +1 -1
- package/dist/{embedding-space-3n6mhhmy.js → embedding-space-an77f45k.js} +6 -6
- package/dist/{embeddings-jfmj6yme.js → embeddings-jkrehejr.js} +1 -1
- package/dist/{event-bus-v4ywhc2p.js → event-bus-08t2b4y2.js} +1 -1
- package/dist/{execute-tjrej979.js → execute-3mys4nta.js} +1 -1
- package/dist/{external-channel-jy8w2gg3.js → external-channel-s6zxpts9.js} +2 -2
- package/dist/fx-adapter-4yet1c4f.js +20 -0
- package/dist/grok-adapter-8ge6tw7m.js +20 -0
- package/dist/handlers-0r9evrdj.js +41 -0
- package/dist/heartbeat-jjpb44e5.js +50 -0
- package/dist/{hook-fv1jwrv7.js → hook-68gbs87k.js} +6 -6
- package/dist/{hook-bpnncsec.js → hook-y6n23zzj.js} +8 -8
- package/dist/{http-bpa26czn.js → http-8c6y008s.js} +404 -146
- package/dist/{index-w216g9y9.js → index-0vthtbc2.js} +38 -22
- package/dist/index-1v23363p.js +39 -0
- package/dist/index-30qw6vyw.js +44 -0
- package/dist/index-6bm3w6cn.js +40 -0
- package/dist/{index-s8re7mvq.js → index-6h3r0vpe.js} +1 -1
- package/dist/{index-620y7jzq.js → index-7dgxveck.js} +3 -3
- package/dist/{index-4k7m5dgj.js → index-maddg9ys.js} +143 -103
- package/dist/{index-0h6qd4p1.js → index-mbpxhc4w.js} +3 -4
- package/dist/index-rz8ve510.js +569 -0
- package/dist/{index-mpj0z9e0.js → index-we3nd2t0.js} +1 -1
- package/dist/{index-pe3d8jfy.js → index-whysn1wf.js} +1 -1
- package/dist/{index-52tgbhrw.js → index-xcw7hjt5.js} +28 -28
- package/dist/{index-8p0j4h4j.js → index-ym9fgxad.js} +94 -89
- package/dist/{k8s-fy8hbhkg.js → k8s-8326q0rq.js} +2 -2
- package/dist/{keepalive-d6z12s04.js → keepalive-7e9r5dvp.js} +5 -4
- package/dist/lead-3jpc7kcr.js +79 -0
- package/dist/{maintenance-7kac6g2g.js → maintenance-d3erjvcg.js} +1 -1
- package/dist/{oauth-refresh-sweep-t1xjetbh.js → oauth-refresh-sweep-0qh70988.js} +4 -3
- package/dist/{object-webhooks-6rdagg0r.js → object-webhooks-ac7v2q5p.js} +7 -7
- package/dist/{onboard-32y1cfxy.js → onboard-5yphtken.js} +4 -4
- package/dist/{opencode-adapter-enp3v31n.js → opencode-adapter-0xvyba4m.js} +8 -8
- package/dist/{otel-impl-k0tm5ptj.js → otel-impl-svqp691q.js} +2 -2
- package/dist/{pending-24zebgvs.js → pending-bn4xe5br.js} +26 -26
- package/dist/{pi-mono-adapter-yj72xxxe.js → pi-mono-adapter-763s8a3w.js} +20 -18
- package/dist/{pricing-refresh-cf25x38j.js → pricing-refresh-kfc215mf.js} +2 -2
- package/dist/{rbac-roles-0wydd22m.js → rbac-roles-3bznvkpt.js} +3 -3
- package/dist/{rbac-roles-at6crb3r.js → rbac-roles-6r4h2ghj.js} +2 -2
- package/dist/{render-v2-nvcw0jd7.js → render-v2-f3qedbpy.js} +10 -10
- package/dist/{resume-y4w0k5v3.js → resume-vcag4ann.js} +13 -13
- package/dist/{runtime-vpe43hx0.js → runtime-x0s55z2t.js} +1 -1
- package/dist/{session-access-gkyvnfye.js → session-access-nwzve8q2.js} +5 -5
- package/dist/{session-source-backfill-3w2st4m2.js → session-source-backfill-jpqfzmgz.js} +2 -2
- package/dist/{setup-axxvqtys.js → setup-d2smwaem.js} +1 -1
- package/dist/thread-buffer-8fc703jc.js +42 -0
- package/dist/{tree-visibility-y4fqvab5.js → tree-visibility-dwzc8en0.js} +2 -2
- package/dist/{user-merge-jobs-kcmwvrc6.js → user-merge-jobs-4ce7kma2.js} +3 -3
- package/dist/{virtual-modules-7d92dct1.js → virtual-modules-78a6yw71.js} +3 -3
- package/dist/{work-objects-f708e069.js → work-objects-m0w1e7q8.js} +28 -28
- package/dist/worker-3p2vq107.js +79 -0
- package/dist/{worker-follow-up-0by8wztc.js → worker-follow-up-e3t6f895.js} +25 -25
- package/dist/{x-3dtaf2r9.js → x-asbrnafg.js} +2 -2
- package/openapi.json +1795 -1623
- package/package.json +13 -12
- 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/migrations/341_user_token_expiry.sql +4 -0
- package/src/be/schedules/validate.ts +26 -0
- package/src/be/scripts/run-credential.ts +55 -1
- package/src/be/scripts/typecheck.ts +4 -4
- package/src/be/scripts/user-code-mode.ts +160 -0
- package/src/be/swarm-config-guard.ts +4 -0
- package/src/be/users.ts +48 -7
- 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-connection-proxy.ts +18 -6
- package/src/http/script-connections.ts +12 -4
- package/src/http/script-runs.ts +12 -3
- package/src/http/scripts.ts +2 -11
- package/src/http/tasks.ts +6 -10
- package/src/http/users.ts +1 -0
- package/src/integrations/chat-sdk/adapters.ts +29 -0
- package/src/integrations/chat-sdk/limits.ts +3 -0
- package/src/integrations/chat-sdk/rocketchat/README.md +8 -0
- package/src/integrations/chat-sdk/rocketchat/index.ts +790 -0
- package/src/integrations/chat-sdk/rocketchat/markdown.ts +210 -0
- package/src/integrations/chat-sdk/rocketchat/types.ts +249 -0
- package/src/integrations/chat-sdk/runtime.ts +11 -5
- package/src/integrations/chat-sdk/schema.ts +37 -3
- package/src/integrations/chat-sdk/status.ts +9 -0
- 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 +3 -0
- package/src/rbac/permissions.ts +9 -0
- package/src/scripts-runtime/executors/native.ts +225 -67
- package/src/scripts-runtime/mcp-client.ts +2 -1
- package/src/scripts-runtime/swarm-sdk.ts +2 -1
- package/src/scripts-runtime/types/stdlib.d.ts +4 -4
- package/src/scripts-runtime/types/swarm-extension.d.ts +7 -7
- package/src/scripts-runtime/types/swarm-sdk.d.ts +4 -4
- package/src/server-user.ts +98 -0
- 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/chat-sdk-rocketchat-vendored.test.ts +67 -0
- package/src/tests/chat-sdk-status-route.test.ts +13 -1
- package/src/tests/codex-app-server.test.ts +4 -6
- 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/mcp-user-route.test.ts +10 -1
- 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-mcp.test.ts +14 -10
- package/src/tests/script-connections-sql.test.ts +6 -2
- package/src/tests/script-connections.test.ts +4 -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/tools/script-common.ts +37 -22
- package/src/tools/script-query-types.ts +1 -1
- package/src/tools/script-run.ts +1 -1
- package/src/tools/script-search.ts +12 -10
- package/src/tools/utils.ts +7 -1
- 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/chat-sdk/content.md +2 -2
- package/templates/skills/pages/content.md +11 -0
- package/templates/skills/swarm-docs/content.md +4 -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
- /package/dist/{cli-m4ejz4nj.js → cli-cah298e5.js} +0 -0
|
@@ -577,10 +577,10 @@ export interface SwarmSdk {
|
|
|
577
577
|
|
|
578
578
|
// --- write: chat sdk ---
|
|
579
579
|
chat_reply(args: { text?: string; card?: unknown }): Promise<unknown>;
|
|
580
|
-
chat_post(args: { adapter: "telegram" | "slack" | "discord" | "teams"; threadId?: string; channelId?: string; text?: string; card?: unknown }): Promise<unknown>;
|
|
581
|
-
chat_openDm(args: { adapter: "telegram" | "slack" | "discord" | "teams"; userId: string }): Promise<unknown>;
|
|
582
|
-
chat_registerChannel(args: { adapter: "telegram" | "slack" | "discord" | "teams"; channelId: string; agentId?: string; workflowId?: string; name?: string }): Promise<unknown>;
|
|
583
|
-
chat_unregisterChannel(args: { adapter: "telegram" | "slack" | "discord" | "teams"; channelId: string }): Promise<unknown>;
|
|
580
|
+
chat_post(args: { adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat"; threadId?: string; channelId?: string; text?: string; card?: unknown }): Promise<unknown>;
|
|
581
|
+
chat_openDm(args: { adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat"; userId: string }): Promise<unknown>;
|
|
582
|
+
chat_registerChannel(args: { adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat"; channelId: string; agentId?: string; workflowId?: string; name?: string }): Promise<unknown>;
|
|
583
|
+
chat_unregisterChannel(args: { adapter: "telegram" | "slack" | "discord" | "teams" | "rocketchat"; channelId: string }): Promise<unknown>;
|
|
584
584
|
|
|
585
585
|
// --- write: messaging (internal) ---
|
|
586
586
|
message_post(args: { channel?: string; content: string; to?: string }): Promise<unknown>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { isExecutorAllowedByDeployment } from "../../scripts-runtime/executors/registry";
|
|
2
|
+
import type { ScriptRecord } from "../../types";
|
|
3
|
+
import { scrubObject, scrubSecrets } from "../../utils/secret-scrubber";
|
|
4
|
+
import { recordInlineScriptRun } from "../db";
|
|
5
|
+
import { getScript } from "./db";
|
|
6
|
+
import { type ScriptSearchResult, searchScripts } from "./embeddings";
|
|
7
|
+
import { runScriptAsUserWithRunCredential } from "./run-credential";
|
|
8
|
+
import { refuseSourceWithSecrets } from "./source-secrets";
|
|
9
|
+
import { scriptStdlibTypesWithGeneratedApis } from "./typecheck";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Code mode on the user MCP: search, type and run scripts as a person, with no
|
|
13
|
+
* agent and no task. A user has no agent scope, so only global scripts are
|
|
14
|
+
* visible. Results mirror the `/api/scripts/*` bodies so the tools render them
|
|
15
|
+
* the same way the agent-side tools do.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** `script_runs.agentId` for a user MCP run, which has no agent (like "schedule"). */
|
|
19
|
+
export const USER_SCRIPT_RUN_AGENT_ID = "user-mcp";
|
|
20
|
+
|
|
21
|
+
export type UserCodeModeResponse = { status: number; body: unknown };
|
|
22
|
+
|
|
23
|
+
/** The `/api/scripts/search` result rows, shared with that route. */
|
|
24
|
+
export function toScriptSearchResults(matches: ScriptSearchResult[]) {
|
|
25
|
+
return matches.map(({ script, score }) => ({
|
|
26
|
+
name: script.name,
|
|
27
|
+
signature: JSON.parse(script.signatureJson),
|
|
28
|
+
argsJsonSchema: script.argsJsonSchema
|
|
29
|
+
? (JSON.parse(script.argsJsonSchema) as Record<string, unknown>)
|
|
30
|
+
: null,
|
|
31
|
+
description: script.description,
|
|
32
|
+
score,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function searchScriptsForUser(args: {
|
|
37
|
+
query: string;
|
|
38
|
+
limit?: number;
|
|
39
|
+
}): Promise<UserCodeModeResponse> {
|
|
40
|
+
const matches = await searchScripts({ query: args.query, scope: "global", limit: args.limit });
|
|
41
|
+
return { status: 200, body: { results: toScriptSearchResults(matches) } };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// A user run gets no agent connections or apps, so its types carry none.
|
|
45
|
+
const EMPTY_API_TYPES = "export interface ScriptApiRegistry {}\n";
|
|
46
|
+
const EMPTY_MCP_TYPES = "export interface ScriptMcpRegistry {}\n";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* `stdlibTypes` is the whole authoring surface: the `stdlib` module plus the
|
|
50
|
+
* full `swarm-sdk` module, so it alone is enough to write a script.
|
|
51
|
+
*/
|
|
52
|
+
export async function scriptTypesForUser(name?: string): Promise<UserCodeModeResponse> {
|
|
53
|
+
let script: ScriptRecord | null = null;
|
|
54
|
+
if (name) {
|
|
55
|
+
script = await getScript({ name, scope: "global" });
|
|
56
|
+
if (!script) return { status: 404, body: { error: "Script not found" } };
|
|
57
|
+
}
|
|
58
|
+
const stdlibTypes = await scriptStdlibTypesWithGeneratedApis(
|
|
59
|
+
EMPTY_API_TYPES,
|
|
60
|
+
EMPTY_MCP_TYPES,
|
|
61
|
+
"",
|
|
62
|
+
);
|
|
63
|
+
if (!script) return { status: 200, body: { stdlibTypes } };
|
|
64
|
+
return {
|
|
65
|
+
status: 200,
|
|
66
|
+
body: {
|
|
67
|
+
signature: JSON.parse(script.signatureJson),
|
|
68
|
+
argsJsonSchema: script.argsJsonSchema
|
|
69
|
+
? (JSON.parse(script.argsJsonSchema) as Record<string, unknown>)
|
|
70
|
+
: null,
|
|
71
|
+
stdlibTypes,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function runScriptForUser(args: {
|
|
77
|
+
userId: string;
|
|
78
|
+
name?: string;
|
|
79
|
+
source?: string;
|
|
80
|
+
args?: unknown;
|
|
81
|
+
}): Promise<UserCodeModeResponse> {
|
|
82
|
+
if (!args.name === !args.source) {
|
|
83
|
+
return { status: 400, body: { error: "Pass exactly one of name or source" } };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let source = args.source as string;
|
|
87
|
+
let fsMode: ScriptRecord["fsMode"] = "none";
|
|
88
|
+
let executor: ScriptRecord["executor"] = null;
|
|
89
|
+
if (args.name) {
|
|
90
|
+
const script = await getScript({ name: args.name, scope: "global" });
|
|
91
|
+
if (!script) return { status: 404, body: { error: "Script not found" } };
|
|
92
|
+
({ source, fsMode, executor } = script);
|
|
93
|
+
} else {
|
|
94
|
+
// The run row records the source: refuse an embedded secret before it runs or persists.
|
|
95
|
+
const refusal = refuseSourceWithSecrets(source);
|
|
96
|
+
if (refusal) return { status: 400, body: refusal };
|
|
97
|
+
}
|
|
98
|
+
if (fsMode === "workspace-rw") {
|
|
99
|
+
return { status: 501, body: { error: "workspace-rw scripts are not supported in v1" } };
|
|
100
|
+
}
|
|
101
|
+
if (executor && !isExecutorAllowedByDeployment(executor)) {
|
|
102
|
+
return {
|
|
103
|
+
status: 400,
|
|
104
|
+
body: {
|
|
105
|
+
error: 'Executor "native" is not permitted when deployment SCRIPT_EXECUTOR="quickjs"',
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const startedAt = new Date().toISOString();
|
|
111
|
+
const output = await runScriptAsUserWithRunCredential(
|
|
112
|
+
{ source, args: args.args, fsMode, executor },
|
|
113
|
+
args.userId,
|
|
114
|
+
);
|
|
115
|
+
const ok = output.exitCode === 0 && !output.error && !output.runtimeError;
|
|
116
|
+
try {
|
|
117
|
+
await recordInlineScriptRun({
|
|
118
|
+
id: crypto.randomUUID(),
|
|
119
|
+
agentId: USER_SCRIPT_RUN_AGENT_ID,
|
|
120
|
+
requestedByUserId: args.userId,
|
|
121
|
+
createdBy: args.userId,
|
|
122
|
+
source,
|
|
123
|
+
args: scrubObject(args.args ?? null),
|
|
124
|
+
scriptName: args.name ?? "(inline source)",
|
|
125
|
+
status: ok ? "completed" : "failed",
|
|
126
|
+
output: scrubObject(output.result),
|
|
127
|
+
error: ok
|
|
128
|
+
? undefined
|
|
129
|
+
: scrubSecrets(
|
|
130
|
+
[
|
|
131
|
+
output.error,
|
|
132
|
+
output.stderr || undefined,
|
|
133
|
+
output.runtimeError
|
|
134
|
+
? `${output.runtimeError.name}: ${output.runtimeError.message}`
|
|
135
|
+
: undefined,
|
|
136
|
+
]
|
|
137
|
+
.filter(Boolean)
|
|
138
|
+
.join(" — ") || `Script exited with code ${output.exitCode}`,
|
|
139
|
+
),
|
|
140
|
+
startedAt,
|
|
141
|
+
finishedAt: new Date().toISOString(),
|
|
142
|
+
});
|
|
143
|
+
} catch {
|
|
144
|
+
// The run already executed; the row is observability only.
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
status: 200,
|
|
149
|
+
body: scrubObject({
|
|
150
|
+
result: output.result,
|
|
151
|
+
truncated: output.truncated,
|
|
152
|
+
durationMs: output.durationMs,
|
|
153
|
+
stdout: output.stdout,
|
|
154
|
+
stderr: output.stderr,
|
|
155
|
+
exitCode: output.exitCode,
|
|
156
|
+
error: output.error,
|
|
157
|
+
runtimeError: output.runtimeError,
|
|
158
|
+
}),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -724,6 +724,10 @@ const VALIDATED_KEYS: Record<string, ConfigValidator> = {
|
|
|
724
724
|
APPS_JSON_COLUMN_MAX_BYTES_BOUNDS.min,
|
|
725
725
|
APPS_JSON_COLUMN_MAX_BYTES_BOUNDS.max,
|
|
726
726
|
),
|
|
727
|
+
// Worker worktree reaper (src/commands/worktree-reaper.ts clamps to the same ranges).
|
|
728
|
+
...enumValidator("WORKTREE_REAPER_MODE", ["off", "dry-run", "on"]),
|
|
729
|
+
...boundedIntegerValidators(["WORKTREE_TTL_HOURS"], 1, 2160),
|
|
730
|
+
...boundedIntegerValidators(["WORKTREE_SWEEP_INTERVAL_MINUTES"], 5, 1440),
|
|
727
731
|
...boundedIntegerValidators(
|
|
728
732
|
["CODEX_OAUTH_KEEP_WARM_MAX_AGE_HOURS"],
|
|
729
733
|
CODEX_OAUTH_KEEP_WARM_MAX_AGE_HOURS_BOUNDS.min,
|
package/src/be/users.ts
CHANGED
|
@@ -304,7 +304,7 @@ export async function listUserTokens(userId: string): Promise<UserTokenSummary[]
|
|
|
304
304
|
return getDbClient().query<UserTokenRow>(
|
|
305
305
|
`SELECT id, userId, label, tokenPreview, createdAt, lastUsedAt, revokedAt
|
|
306
306
|
FROM user_tokens
|
|
307
|
-
WHERE userId = ?
|
|
307
|
+
WHERE userId = ? AND expiresAt IS NULL
|
|
308
308
|
ORDER BY createdAt DESC`,
|
|
309
309
|
[userId],
|
|
310
310
|
);
|
|
@@ -511,6 +511,43 @@ export async function mintToken(
|
|
|
511
511
|
return { tokenId, plaintext };
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
/**
|
|
515
|
+
* Mint the short-lived `aswt_` token a user MCP script run presents on its
|
|
516
|
+
* `ctx.swarm` calls, so the script can do only what the requesting user's own
|
|
517
|
+
* token can. It expires at `now + ttlMs` (the backstop for a run that dies
|
|
518
|
+
* without revoking) and stays off the People page token list. No identity
|
|
519
|
+
* event: one per run would flood the audit log, like `mintScriptRunToken`.
|
|
520
|
+
*/
|
|
521
|
+
export async function mintUserScriptRunToken(
|
|
522
|
+
userId: string,
|
|
523
|
+
ttlMs: number,
|
|
524
|
+
): Promise<{ tokenId: string; plaintext: string }> {
|
|
525
|
+
const plaintext = `${TOKEN_PREFIX}${randomChars(TOKEN_ALPHABET, 24)}`;
|
|
526
|
+
const tokenId = randomUUID().replace(/-/g, "");
|
|
527
|
+
const now = new Date();
|
|
528
|
+
await getDbClient().run(
|
|
529
|
+
`INSERT INTO user_tokens (id, userId, label, tokenHash, tokenPreview, createdAt, expiresAt)
|
|
530
|
+
VALUES (?, ?, 'script-run', ?, ?, ?, ?)`,
|
|
531
|
+
[
|
|
532
|
+
tokenId,
|
|
533
|
+
userId,
|
|
534
|
+
sha256Hex(plaintext),
|
|
535
|
+
plaintext.slice(-4),
|
|
536
|
+
now.toISOString(),
|
|
537
|
+
new Date(now.getTime() + ttlMs).toISOString(),
|
|
538
|
+
],
|
|
539
|
+
);
|
|
540
|
+
return { tokenId, plaintext };
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Revoke a token minted by `mintUserScriptRunToken`. No-op if already revoked. */
|
|
544
|
+
export async function revokeUserScriptRunToken(tokenId: string): Promise<void> {
|
|
545
|
+
await getDbClient().run(
|
|
546
|
+
"UPDATE user_tokens SET revokedAt = ? WHERE id = ? AND expiresAt IS NOT NULL AND revokedAt IS NULL",
|
|
547
|
+
[new Date().toISOString(), tokenId],
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
514
551
|
/**
|
|
515
552
|
* Revoke a previously-minted token. Sets `revokedAt = now` and emits
|
|
516
553
|
* `token_revoked`. Subsequent `resolveUserByToken(plaintext)` returns null.
|
|
@@ -586,11 +623,14 @@ export async function resolveUserToken(
|
|
|
586
623
|
const hash = sha256Hex(plaintext);
|
|
587
624
|
const client = getDbClient();
|
|
588
625
|
|
|
589
|
-
const row = await client.get<{
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
626
|
+
const row = await client.get<{
|
|
627
|
+
id: string;
|
|
628
|
+
userId: string;
|
|
629
|
+
revokedAt: string | null;
|
|
630
|
+
expiresAt: string | null;
|
|
631
|
+
}>("SELECT id, userId, revokedAt, expiresAt FROM user_tokens WHERE tokenHash = ?", [hash]);
|
|
593
632
|
if (!row || row.revokedAt !== null) return null;
|
|
633
|
+
if (row.expiresAt !== null && Date.parse(row.expiresAt) <= Date.now()) return null;
|
|
594
634
|
|
|
595
635
|
// Best-effort lastUsedAt update — never let a failure here leak to the
|
|
596
636
|
// caller and block a successful token resolution.
|
|
@@ -613,8 +653,9 @@ export async function resolveUserToken(
|
|
|
613
653
|
*/
|
|
614
654
|
export async function isLiveUserToken(tokenId: string, userId: string): Promise<boolean> {
|
|
615
655
|
const row = await getDbClient().get<{ found: number }>(
|
|
616
|
-
|
|
617
|
-
|
|
656
|
+
`SELECT 1 AS found FROM user_tokens
|
|
657
|
+
WHERE id = ? AND userId = ? AND revokedAt IS NULL AND (expiresAt IS NULL OR expiresAt > ?)`,
|
|
658
|
+
[tokenId, userId, new Date().toISOString()],
|
|
618
659
|
);
|
|
619
660
|
return row != null;
|
|
620
661
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RateLimitWindowTelemetry } from "../utils/error-tracker";
|
|
1
|
+
import type { RateLimitWindowTelemetry, SpendCap } from "../utils/error-tracker";
|
|
2
2
|
import { modelFamilyOf } from "../utils/model-rate-limit-windows";
|
|
3
3
|
import type {
|
|
4
4
|
ProviderAccountTelemetry,
|
|
@@ -15,6 +15,7 @@ async function reportKeyRateLimit(
|
|
|
15
15
|
keySuffix: string,
|
|
16
16
|
keyIndex: number,
|
|
17
17
|
rateLimitedUntil: string,
|
|
18
|
+
spendCap?: SpendCap,
|
|
18
19
|
): Promise<void> {
|
|
19
20
|
try {
|
|
20
21
|
const response = await fetch(`${apiUrl}/api/keys/report-rate-limit`, {
|
|
@@ -28,6 +29,7 @@ async function reportKeyRateLimit(
|
|
|
28
29
|
keySuffix,
|
|
29
30
|
keyIndex,
|
|
30
31
|
rateLimitedUntil,
|
|
32
|
+
...(spendCap ? { spendCap } : {}),
|
|
31
33
|
}),
|
|
32
34
|
// Awaited on a key-wide outcome: a hung API must not hold the task open.
|
|
33
35
|
signal: AbortSignal.timeout(10_000),
|
|
@@ -39,7 +41,7 @@ async function reportKeyRateLimit(
|
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
43
|
console.log(
|
|
42
|
-
`[credentials] Reported key ...${keySuffix} as rate-limited until ${rateLimitedUntil}`,
|
|
44
|
+
`[credentials] Reported key ...${keySuffix} as ${spendCap ? "spend-capped" : "rate-limited"} until ${rateLimitedUntil}`,
|
|
43
45
|
);
|
|
44
46
|
} catch (err) {
|
|
45
47
|
console.warn(
|
|
@@ -181,6 +183,7 @@ export async function reportCredentialOutcomeThenFinish(
|
|
|
181
183
|
credentialInfo.keySuffix,
|
|
182
184
|
credentialInfo.keyIndex,
|
|
183
185
|
keyRateLimitedUntil,
|
|
186
|
+
outcome.kind === "key" ? outcome.spendCap : undefined,
|
|
184
187
|
).catch(() => {});
|
|
185
188
|
// `finish` may resume the task on another key of the pool: the bench
|
|
186
189
|
// lands first, so the resume's claim cannot draw this key again.
|
|
@@ -839,6 +839,25 @@ export async function reportAcpStatus(
|
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
841
|
|
|
842
|
+
/**
|
|
843
|
+
* The model the task itself selected (a pin, a tier or a task profile), for
|
|
844
|
+
* `buildLatestModelReport({ taskModel })`. Claim resolution also returns the
|
|
845
|
+
* agent's own default profile (`profile:agent-default`); that model comes from the
|
|
846
|
+
* agent's settings, not the task, so it must not report as task-selected.
|
|
847
|
+
*/
|
|
848
|
+
export function taskSelectedModelForReport(opts: {
|
|
849
|
+
/** Server claim-time resolution (`task.resolvedModel`). */
|
|
850
|
+
resolvedModel?: string;
|
|
851
|
+
modelSource?: string;
|
|
852
|
+
/** Local resolution from the task's own pin/tier. */
|
|
853
|
+
localModel?: string;
|
|
854
|
+
}): string | undefined {
|
|
855
|
+
if (opts.resolvedModel) {
|
|
856
|
+
return opts.modelSource === "profile:agent-default" ? undefined : opts.resolvedModel;
|
|
857
|
+
}
|
|
858
|
+
return opts.localModel || undefined;
|
|
859
|
+
}
|
|
860
|
+
|
|
842
861
|
export function buildLatestModelReport(opts: {
|
|
843
862
|
model: string;
|
|
844
863
|
taskModel?: string;
|
|
@@ -61,7 +61,10 @@ export function classifyProviderError(
|
|
|
61
61
|
return { errorClass: "model_window" };
|
|
62
62
|
case "key":
|
|
63
63
|
return {
|
|
64
|
-
errorClass:
|
|
64
|
+
errorClass:
|
|
65
|
+
rateLimitOutcome.spendCap || isCodexCreditsExhaustedMessage(text)
|
|
66
|
+
? "credits"
|
|
67
|
+
: "rate_limit",
|
|
65
68
|
};
|
|
66
69
|
case "none":
|
|
67
70
|
break;
|
|
@@ -3,8 +3,10 @@ import {
|
|
|
3
3
|
isCodexCreditsExhaustedMessage,
|
|
4
4
|
isRateLimitMessage,
|
|
5
5
|
MAX_RATE_LIMIT_RESET_MS,
|
|
6
|
+
MAX_SPEND_CAP_HOLD_MS,
|
|
6
7
|
parseRateLimitResetTime,
|
|
7
8
|
type RateLimitWindowTelemetry,
|
|
9
|
+
type SpendCap,
|
|
8
10
|
} from "../utils/error-tracker";
|
|
9
11
|
import {
|
|
10
12
|
type ModelFamily,
|
|
@@ -19,7 +21,7 @@ import type {
|
|
|
19
21
|
|
|
20
22
|
export type RateLimitOutcome =
|
|
21
23
|
| { kind: "none" }
|
|
22
|
-
| { kind: "key"; rateLimitedUntil: string }
|
|
24
|
+
| { kind: "key"; rateLimitedUntil: string; spendCap?: SpendCap }
|
|
23
25
|
/**
|
|
24
26
|
* The key's seat cannot run the model (`credits_required`). Not a rate
|
|
25
27
|
* limit: the seat rejection never marks the key by itself.
|
|
@@ -62,12 +64,40 @@ interface ClassifiableResult {
|
|
|
62
64
|
creditsRequired?: { observedAt: string; overageDisabledReason?: string };
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
function clampMs(candidateMs: number, nowMs: number): number {
|
|
67
|
+
function clampMs(candidateMs: number, nowMs: number, maxResetMs = MAX_RATE_LIMIT_RESET_MS): number {
|
|
66
68
|
const minMs = nowMs + 60_000;
|
|
67
|
-
const maxMs = nowMs +
|
|
69
|
+
const maxMs = nowMs + maxResetMs;
|
|
68
70
|
return Math.min(Math.max(candidateMs, minMs), maxMs);
|
|
69
71
|
}
|
|
70
72
|
|
|
73
|
+
/** OpenRouter's key spend limit (403 `openrouter_key_limit`) and its out-of-credits 402. */
|
|
74
|
+
const SPEND_CAP_TEXT =
|
|
75
|
+
/key limit exceeded|"limit_source"\s*:\s*"openrouter_key_limit"|insufficient credits|requires more credits/i;
|
|
76
|
+
|
|
77
|
+
function numberOf(text: string, pattern: RegExp): number | null {
|
|
78
|
+
const value = Number(text.match(pattern)?.[1]);
|
|
79
|
+
return Number.isFinite(value) ? value : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The spend cap a failure text reports, or null when it is not a spend cap.
|
|
84
|
+
* Reads the JSON metadata first (`limit_usd`, `spend_usd`, `resets_at`), then
|
|
85
|
+
* the message ("$1.07 of $1.00 used; resets <ISO>").
|
|
86
|
+
*/
|
|
87
|
+
export function parseSpendCapMessage(text: string): SpendCap | null {
|
|
88
|
+
if (!SPEND_CAP_TEXT.test(text)) return null;
|
|
89
|
+
const resetText =
|
|
90
|
+
text.match(/"resets_at"\s*:\s*"([^"]+)"/)?.[1] ??
|
|
91
|
+
text.match(/resets (\d{4}-\d{2}-\d{2}T[\d:.]+Z)/)?.[1];
|
|
92
|
+
const resetMs = resetText ? Date.parse(resetText) : Number.NaN;
|
|
93
|
+
return {
|
|
94
|
+
limitUsd: numberOf(text, /"limit_usd"\s*:\s*([\d.]+)/) ?? numberOf(text, /of \$([\d.]+) used/),
|
|
95
|
+
spendUsd:
|
|
96
|
+
numberOf(text, /"spend_usd"\s*:\s*([\d.]+)/) ?? numberOf(text, /\$([\d.]+) of \$[\d.]+ used/),
|
|
97
|
+
resetsAt: Number.isFinite(resetMs) ? new Date(resetMs).toISOString() : null,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
71
101
|
/**
|
|
72
102
|
* Classifies a finished provider session's rate-limit signal into one of
|
|
73
103
|
* four outcomes: no rate limit, a key-wide rate limit (legacy path), a
|
|
@@ -134,6 +164,21 @@ export function classifyRateLimitOutcome(
|
|
|
134
164
|
}
|
|
135
165
|
}
|
|
136
166
|
|
|
167
|
+
// Before the rate-limit text check: OpenRouter's cap body says "usage limit",
|
|
168
|
+
// which would read as a short rate limit and re-hand the key every 5 minutes.
|
|
169
|
+
const spendCap = failureReason != null ? parseSpendCapMessage(failureReason) : null;
|
|
170
|
+
if (spendCap) {
|
|
171
|
+
// shortcut: a cap with no reset holds for MAX_SPEND_CAP_HOLD_MS, not forever; editing the key re-creates its status row.
|
|
172
|
+
const untilMs = spendCap.resetsAt
|
|
173
|
+
? Date.parse(spendCap.resetsAt)
|
|
174
|
+
: nowMs + MAX_SPEND_CAP_HOLD_MS;
|
|
175
|
+
return {
|
|
176
|
+
kind: "key",
|
|
177
|
+
rateLimitedUntil: new Date(clampMs(untilMs, nowMs, MAX_SPEND_CAP_HOLD_MS)).toISOString(),
|
|
178
|
+
spendCap,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
137
182
|
if (
|
|
138
183
|
result.rateLimitResetAt != null ||
|
|
139
184
|
(failureReason != null && isRateLimitMessage(failureReason))
|