@desplega.ai/agent-swarm 2.8.1 → 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-pwjpn0j6.js → actions-ewz7bp4g.js} +20 -19
- package/dist/{amp-adapter-cq9jgj6x.js → amp-adapter-f25tqhnf.js} +3 -3
- package/dist/{app-cnfffgwg.js → app-mkptw0k7.js} +4 -4
- package/dist/{assistant-kpn317y1.js → assistant-c47rfe77.js} +23 -22
- package/dist/{boot-args-schema-pbbnhmc3.js → boot-args-schema-4vb0xsat.js} +1 -1
- package/dist/{boot-reembed-9m0ysxma.js → boot-reembed-1ghy2sab.js} +1 -1
- package/dist/{boot-reembed-majbn53m.js → boot-reembed-htr73hbs.js} +1 -1
- package/dist/{boot-scrub-sweep-app8g8ym.js → boot-scrub-sweep-yrytg42z.js} +4 -4
- package/dist/{boot-seeds-pbtmvcjm.js → boot-seeds-n2b3dx4e.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-jmfqgkqa.js} +2 -2
- package/dist/{claude-adapter-wn1g3qp5.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-pd47nzch.js → claude-managed-setup-hfvry1bd.js} +5 -5
- package/dist/{claude-sdk-session-3a2a6589.js → claude-sdk-session-0hamqzc7.js} +10 -11
- package/dist/{cli-v1dv1r37.js → cli-0bcgyj5b.js} +74 -3
- package/dist/{cli-a3b239vq.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-wk18cm92.js → cli-4ax9mvvg.js} +4 -4
- package/dist/{cli-9wngrawf.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-m4dqmnbp.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-7b8sbmag.js → cli-7c5tgqhf.js} +5 -5
- package/dist/{cli-2gxeg5gr.js → cli-8476gtwf.js} +1 -1
- package/dist/{cli-yncmerje.js → cli-922z7gwm.js} +4 -4
- package/dist/{cli-jrzkw01m.js → cli-93t5s4zq.js} +2 -2
- package/dist/{cli-sn7rtnj4.js → cli-9zmb7ptc.js} +9 -9
- package/dist/{cli-tk7cjj8h.js → cli-am1ptset.js} +3 -3
- package/dist/{cli-cyhbbd1z.js → cli-awwptga4.js} +1 -1
- package/dist/{cli-89cqnasv.js → cli-bhsfbmk8.js} +19 -7
- package/dist/{cli-9vhebtjz.js → cli-bj6qhgte.js} +15 -32
- package/dist/{cli-g70vxtjh.js → cli-c0xjnr8z.js} +2 -2
- package/dist/{cli-vqptjbr7.js → cli-c3ng0mb4.js} +14 -14
- package/dist/{cli-re4raaj0.js → cli-c71n3bxq.js} +11 -6
- package/dist/{cli-7p1kvkck.js → cli-crpf163n.js} +25 -18
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-d3p5vwbk.js → cli-dpsfwh7n.js} +13 -21
- package/dist/{cli-xzm9vcfg.js → cli-dtdht77h.js} +2 -2
- package/dist/{cli-bb431xey.js → cli-e2w34h6z.js} +231 -68
- 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-tqegb8eq.js → cli-gpz1d0t2.js} +4 -4
- package/dist/{cli-7w69ne2f.js → cli-h9yy18gy.js} +239 -67
- package/dist/{cli-m5akxq8q.js → cli-j8cjdzan.js} +1 -1
- package/dist/{cli-m9s2qff2.js → cli-jg5txpm6.js} +187 -93
- package/dist/{cli-k26bkr9t.js → cli-k2rw11py.js} +3 -3
- package/dist/{cli-93k32c37.js → cli-k96cecs7.js} +377 -61
- package/dist/{cli-3vjhs18n.js → cli-kd56bmk4.js} +1 -1
- package/dist/{cli-k0615eh8.js → cli-kmemts3w.js} +13 -13
- package/dist/{cli-pcad4cb1.js → cli-knva3nmx.js} +2 -2
- package/dist/{cli-b085njxz.js → cli-kw44j53p.js} +15 -14
- package/dist/{cli-bsywb58a.js → cli-mdpbjnzq.js} +10 -10
- package/dist/{cli-syybb0p1.js → cli-me0r8gzr.js} +35 -76
- package/dist/{cli-4r05hnqa.js → cli-mwwmka77.js} +15 -15
- package/dist/{cli-1xh9a7hn.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-zcsw143p.js → cli-qmqt520k.js} +2 -2
- package/dist/{cli-2zp0et3v.js → cli-qps8je6j.js} +70 -19
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-k93bq1wq.js → cli-rjvsf9qa.js} +5 -5
- package/dist/{cli-6mma83xa.js → cli-rqfvkx5t.js} +7 -7
- package/dist/{cli-dy32zecz.js → cli-s7zz734a.js} +1 -1
- package/dist/{cli-yn2bbre9.js → cli-s8p8hhty.js} +2 -2
- package/dist/{cli-vbh10fqa.js → cli-sdvcrq5x.js} +5 -5
- package/dist/{cli-b5rs97a6.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-hxpyc9sn.js → cli-t5ys4ebm.js} +3 -3
- package/dist/{cli-qmqk2yc2.js → cli-tas6ckky.js} +2 -2
- package/dist/{cli-p1w18yhx.js → cli-tf79ryyy.js} +1 -1
- package/dist/{cli-kc7v1nfv.js → cli-tnzebztn.js} +1 -1
- package/dist/{cli-gax7fk3t.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-0ntbxyaa.js → cli-z8cvws4c.js} +363 -47
- package/dist/{cli-tacge1w0.js → cli-zdaypkq9.js} +146 -52
- package/dist/{cli-b8e9nb04.js → cli-zeaehgyd.js} +2 -2
- package/dist/{cli-jcpr5smb.js → cli-ztq5z4e1.js} +4 -4
- package/dist/cli.js +21 -21
- package/dist/{codex-adapter-nha71q3n.js → codex-adapter-2brxx5ta.js} +7 -8
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-c930c3ea.js} +2 -2
- package/dist/{codex-login-bcda78ge.js → codex-login-cbrs1h5w.js} +1 -1
- package/dist/{codex-session-runner-ak9x1k1h.js → codex-session-runner-y9anfj0r.js} +8 -9
- package/dist/{commands-f587qpq8.js → commands-wn9q06qr.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-fw608czd.js} +4 -4
- package/dist/{controllers-connect-k5sg9m9h.js → controllers-connect-63j5rdcm.js} +20 -20
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-6mb9jme8.js} +2 -2
- package/dist/{db-nzf8zb5z.js → db-0m6v5tq4.js} +3 -3
- package/dist/{db-amm8w15a.js → db-y4wfrzbm.js} +4 -2
- package/dist/{devin-adapter-xedz98zv.js → devin-adapter-r0yx3gv8.js} +1 -1
- package/dist/{dispatcher-89zrts8f.js → dispatcher-9tq2zzdj.js} +17 -17
- package/dist/{docker-866qpzt9.js → docker-j75atvpt.js} +2 -2
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-t09sv4tq.js} +2 -2
- package/dist/{e2b-s16txnpx.js → e2b-7s9dscap.js} +3 -3
- package/dist/{e2b-jkwfhbcv.js → e2b-a7vzs2vj.js} +3 -3
- package/dist/{easter-egg-3d-533knw22.js → easter-egg-3d-fbwvmwhe.js} +1 -1
- package/dist/{embedding-space-ezwenjmj.js → embedding-space-wh8de1t9.js} +6 -6
- package/dist/{embeddings-np74ht6g.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-z46yx9d7.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-dt9qw9c8.js → heartbeat-2ze5fzpc.js} +20 -20
- package/dist/{hook-8k6fbz9b.js → hook-ca54yd4s.js} +5 -5
- package/dist/{hook-jgcgygex.js → hook-gaehe2w5.js} +8 -8
- package/dist/{http-haw4r8ne.js → http-jfg8t2yk.js} +3839 -122
- package/dist/{index-tvfafeyy.js → index-3gv6sc4z.js} +1 -1
- package/dist/{index-tez78qj3.js → index-3yvzbhxd.js} +100 -23
- package/dist/index-8w2aznds.js +33 -0
- package/dist/{index-5gk12my8.js → index-csgrxedz.js} +1 -1
- package/dist/index-qnjvr362.js +37 -0
- package/dist/index-yzxd3sn9.js +32 -0
- package/dist/{keepalive-xn6s7rmg.js → keepalive-k2a3qe73.js} +4 -4
- package/dist/lead-zhxqbfdv.js +69 -0
- package/dist/{maintenance-vdts800b.js → maintenance-gb5sd5nc.js} +1 -1
- package/dist/{node-4c5jqxr3.js → node-7qsx5kvm.js} +1 -1
- package/dist/{oauth-refresh-sweep-094c8wfk.js → oauth-refresh-sweep-y7rm6bkb.js} +3 -3
- package/dist/{onboard-v99eh56m.js → onboard-jmc5qerv.js} +4 -4
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-7eade9ev.js} +6 -7
- package/dist/{otel-impl-q7yr9yp0.js → otel-impl-8j1xhxqd.js} +2 -2
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-yqmaf32x.js} +14 -13
- package/dist/{pricing-refresh-7dh2yase.js → pricing-refresh-1nj722h6.js} +2 -2
- package/dist/{rbac-roles-mdmc96p4.js → rbac-roles-b1mtr6dr.js} +3 -3
- package/dist/{rbac-roles-npbmdh77.js → rbac-roles-n1f3frk1.js} +2 -2
- package/dist/{render-v2-twhhwmms.js → render-v2-1gfpd8rj.js} +4 -4
- package/dist/{resume-5gsrjd5e.js → resume-w1s1eh5v.js} +7 -7
- package/dist/{runtime-1hv06jsn.js → runtime-84g5egsc.js} +1 -1
- package/dist/{session-access-m191x30x.js → session-access-y6z1txk4.js} +4 -4
- package/dist/{session-source-backfill-nt923ask.js → session-source-backfill-gxxwfh12.js} +3 -3
- package/dist/{setup-wv467afy.js → setup-r91gstyk.js} +1 -1
- package/dist/{virtual-modules-gazyapte.js → virtual-modules-cgnj6kme.js} +3 -3
- package/dist/{work-objects-8zkrpy13.js → work-objects-qcxzg61c.js} +20 -20
- package/dist/worker-7j2907g6.js +69 -0
- package/dist/{worker-follow-up-cecqszem.js → worker-follow-up-y2d2h7km.js} +19 -17
- package/dist/{x-2fyrt5pp.js → x-qhxq2ama.js} +2 -2
- package/openapi.json +2908 -351
- package/package.json +4 -4
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +53 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +40 -9
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- 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 +53 -20
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +677 -0
- package/src/be/savings/model.ts +674 -0
- 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 +91 -4
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- 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/skill-parser.ts +19 -7
- package/src/be/swarm-config-guard.ts +8 -0
- package/src/be/users.ts +29 -2
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +258 -58
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +11 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +15 -1
- package/src/http/requested-by.ts +97 -1
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +849 -0
- package/src/http/scripts.ts +26 -15
- package/src/http/tasks.ts +89 -9
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- 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 +12 -34
- package/src/providers/opencode-adapter.ts +34 -12
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- 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/sdk-allowlist.ts +11 -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 +192 -17
- package/src/scripts-runtime/types/stdlib.d.ts +95 -4
- package/src/scripts-runtime/types/swarm-extension.d.ts +60 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +69 -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/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/base-prompt.test.ts +5 -4
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- 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 +28 -78
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/create-task-vcs-repo.test.ts +136 -0
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- 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/deploy-guard.test.ts +154 -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/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/opencode-adapter.test.ts +53 -6
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/prompt-template-session.test.ts +17 -1
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/runner-requester-profile.test.ts +139 -1
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compound.test.ts +774 -0
- package/src/tests/savings-compute.test.ts +215 -0
- 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 +499 -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 +4 -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/sdk-allowlist.test.ts +40 -0
- package/src/tests/secret-rules.test.ts +124 -1
- package/src/tests/secret-scrubber.test.ts +1 -1
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- 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/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +146 -33
- package/src/utils/constants.ts +2 -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/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- 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-pdy3qsvg.js +0 -15
- package/dist/cli-4bd1rck6.js +0 -4
- package/dist/cli-jywyhqws.js +0 -104
- package/dist/fx-adapter-3q12snn6.js +0 -18
- package/dist/grok-adapter-ahb1w033.js +0 -18
- package/dist/handlers-vbww69re.js +0 -32
- package/dist/index-4xwaf5th.js +0 -32
- package/dist/index-f0hcrs8e.js +0 -33
- package/dist/index-s4ewdma4.js +0 -37
- package/dist/lead-6ygbfhbh.js +0 -70
- package/dist/worker-mz5z7kj0.js +0 -70
- package/src/providers/ctx-mode-env.ts +0 -10
package/src/be/db/tasks/read.ts
CHANGED
|
@@ -6,18 +6,22 @@ import type {
|
|
|
6
6
|
AgentTaskStatus,
|
|
7
7
|
AgentTaskSummary,
|
|
8
8
|
AgentTaskTimelineItem,
|
|
9
|
+
FallbackHop,
|
|
9
10
|
FollowUpConfig,
|
|
10
11
|
ProviderName,
|
|
11
12
|
ReasoningEffort,
|
|
12
13
|
RoutingAffinity,
|
|
13
14
|
RoutingReason,
|
|
14
15
|
RoutingSource,
|
|
16
|
+
TaskSlackParticipants,
|
|
15
17
|
} from "../../../types";
|
|
16
18
|
import {
|
|
19
|
+
FallbackHopSchema,
|
|
17
20
|
FollowUpConfigSchema,
|
|
18
21
|
parseModelTier,
|
|
19
22
|
ReasoningEffortSchema,
|
|
20
23
|
RoutingAffinitySchema,
|
|
24
|
+
TaskSlackParticipantsSchema,
|
|
21
25
|
TERMINAL_TASK_STATUSES,
|
|
22
26
|
} from "../../../types";
|
|
23
27
|
import { normalizeOutputSchema } from "../../../utils/output-schema";
|
|
@@ -68,6 +72,7 @@ export type AgentTaskRow = {
|
|
|
68
72
|
slackThreadTs: string | null;
|
|
69
73
|
slackTriggerMessageTs: string | null;
|
|
70
74
|
slackUserId: string | null;
|
|
75
|
+
slackParticipants?: string | null;
|
|
71
76
|
slackReplySent: number;
|
|
72
77
|
slackProgressMessageTs: string | null;
|
|
73
78
|
slackTreeRootMessageTs: string | null;
|
|
@@ -98,6 +103,7 @@ export type AgentTaskRow = {
|
|
|
98
103
|
modelAlias?: string | null;
|
|
99
104
|
profile?: string | null;
|
|
100
105
|
resolvedProfile?: string | null;
|
|
106
|
+
fallbackHops?: string | null;
|
|
101
107
|
scheduleId: string | null;
|
|
102
108
|
workflowRunId: string | null;
|
|
103
109
|
workflowRunStepId: string | null;
|
|
@@ -256,6 +262,35 @@ const LIST_COLUMNS = {
|
|
|
256
262
|
|
|
257
263
|
type TaskListFields = keyof typeof LIST_COLUMNS;
|
|
258
264
|
|
|
265
|
+
/** The stored hop list; entries that do not parse are dropped, none reads as unset. */
|
|
266
|
+
function parseFallbackHops(value: string | null | undefined): FallbackHop[] | undefined {
|
|
267
|
+
if (!value) return undefined;
|
|
268
|
+
try {
|
|
269
|
+
const parsed: unknown = JSON.parse(value);
|
|
270
|
+
if (!Array.isArray(parsed)) return undefined;
|
|
271
|
+
const hops = parsed.flatMap((entry) => {
|
|
272
|
+
const hop = FallbackHopSchema.safeParse(entry);
|
|
273
|
+
return hop.success ? [hop.data] : [];
|
|
274
|
+
});
|
|
275
|
+
return hops.length > 0 ? hops : undefined;
|
|
276
|
+
} catch {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** The stored participants; a value that does not parse reads as unset. */
|
|
282
|
+
function parseSlackParticipants(
|
|
283
|
+
value: string | null | undefined,
|
|
284
|
+
): TaskSlackParticipants | undefined {
|
|
285
|
+
if (!value) return undefined;
|
|
286
|
+
try {
|
|
287
|
+
const parsed = TaskSlackParticipantsSchema.safeParse(JSON.parse(value));
|
|
288
|
+
return parsed.success ? parsed.data : undefined;
|
|
289
|
+
} catch {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
259
294
|
export function rowToAgentTask(row: AgentTaskRow): AgentTask {
|
|
260
295
|
let followUpConfig: FollowUpConfig | undefined;
|
|
261
296
|
if (row.followUpConfig) {
|
|
@@ -326,6 +361,7 @@ export function rowToAgentTask(row: AgentTaskRow): AgentTask {
|
|
|
326
361
|
slackThreadTs: row.slackThreadTs ?? undefined,
|
|
327
362
|
slackTriggerMessageTs: row.slackTriggerMessageTs ?? undefined,
|
|
328
363
|
slackUserId: row.slackUserId ?? undefined,
|
|
364
|
+
slackParticipants: parseSlackParticipants(row.slackParticipants),
|
|
329
365
|
slackReplySent: !!row.slackReplySent,
|
|
330
366
|
slackProgressMessageTs: row.slackProgressMessageTs ?? undefined,
|
|
331
367
|
slackTreeRootMessageTs: row.slackTreeRootMessageTs ?? undefined,
|
|
@@ -361,6 +397,7 @@ export function rowToAgentTask(row: AgentTaskRow): AgentTask {
|
|
|
361
397
|
: undefined,
|
|
362
398
|
profile: row.profile ?? undefined,
|
|
363
399
|
resolvedProfile: row.resolvedProfile ?? undefined,
|
|
400
|
+
fallbackHops: parseFallbackHops(row.fallbackHops),
|
|
364
401
|
scheduleId: row.scheduleId ?? undefined,
|
|
365
402
|
workflowRunId: row.workflowRunId ?? undefined,
|
|
366
403
|
workflowRunStepId: row.workflowRunStepId ?? undefined,
|
|
@@ -2031,6 +2068,22 @@ export async function getLatestLeadTaskByContextKey(
|
|
|
2031
2068
|
* Unlike getAgentWorkingOnThread (which filters source='slack'), this finds ALL tasks
|
|
2032
2069
|
* including worker tasks that inherited Slack metadata via parentTaskId.
|
|
2033
2070
|
*/
|
|
2071
|
+
/** The oldest task in a Slack thread: who started the swarm's work there. */
|
|
2072
|
+
export async function getFirstTaskInThread(
|
|
2073
|
+
channelId: string,
|
|
2074
|
+
threadTs: string,
|
|
2075
|
+
): Promise<AgentTask | null> {
|
|
2076
|
+
const row = await getDbClient().get<AgentTaskRow>(
|
|
2077
|
+
`SELECT * FROM agent_tasks
|
|
2078
|
+
WHERE slackChannelId = ?
|
|
2079
|
+
AND slackThreadTs = ?
|
|
2080
|
+
ORDER BY createdAt ASC
|
|
2081
|
+
LIMIT 1`,
|
|
2082
|
+
[channelId, threadTs],
|
|
2083
|
+
);
|
|
2084
|
+
return row ? rowToAgentTask(row) : null;
|
|
2085
|
+
}
|
|
2086
|
+
|
|
2034
2087
|
export async function getMostRecentTaskInThread(
|
|
2035
2088
|
channelId: string,
|
|
2036
2089
|
threadTs: string,
|
|
@@ -106,12 +106,23 @@ export async function getRunWorkflow(run: {
|
|
|
106
106
|
return pinned ? mergePinnedDefinition(live, pinned) : live;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Remove only the supplied snapshots that no run references. Collect the
|
|
111
|
+
* hashes before deleting runs, then call this within the same transaction.
|
|
112
|
+
*/
|
|
113
|
+
export async function deleteOrphanedRunDefinitions(hashes: readonly string[]): Promise<void> {
|
|
114
|
+
// Snapshots can be large. Bound each statement's rows and bind parameters,
|
|
115
|
+
// and seek by hash instead of scanning unrelated definitions.
|
|
116
|
+
const batchSize = 100;
|
|
117
|
+
for (let offset = 0; offset < hashes.length; offset += batchSize) {
|
|
118
|
+
const batch = hashes.slice(offset, offset + batchSize);
|
|
119
|
+
await getDbClient().run(
|
|
120
|
+
`DELETE FROM workflow_run_definitions
|
|
121
|
+
WHERE hash IN (${batch.map(() => "?").join(", ")})
|
|
122
|
+
AND NOT EXISTS (
|
|
123
|
+
SELECT 1 FROM workflow_runs r WHERE r.definitionHash = workflow_run_definitions.hash
|
|
124
|
+
)`,
|
|
125
|
+
batch,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
117
128
|
}
|
package/src/be/db-client.ts
CHANGED
|
@@ -40,8 +40,35 @@ export type TransactionOptions = {
|
|
|
40
40
|
* SELECT-only callbacks.
|
|
41
41
|
*/
|
|
42
42
|
readOnly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Wall-clock deadline (epoch ms) for the whole transaction, BEGIN retries and
|
|
45
|
+
* COMMIT retries included. Past it the transaction is rolled back and the call
|
|
46
|
+
* throws `DbTransactionDeadlineError`: BEGIN stops retrying, and COMMIT is never
|
|
47
|
+
* issued (or retried) once the deadline has passed, so a caller that already
|
|
48
|
+
* answered 504 cannot be followed by a late write. A COMMIT that starts before
|
|
49
|
+
* the deadline can still finish up to one `attemptSpinMs` after it. Ignored for
|
|
50
|
+
* a nested call (a SAVEPOINT): the outermost transaction owns the deadline.
|
|
51
|
+
*/
|
|
52
|
+
deadlineAt?: number;
|
|
43
53
|
};
|
|
44
54
|
|
|
55
|
+
/** The transaction's `deadlineAt` passed before it could commit; nothing was written. */
|
|
56
|
+
export class DbTransactionDeadlineError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super("db-client: transaction passed its deadline and was rolled back");
|
|
59
|
+
this.name = "DbTransactionDeadlineError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function assertBeforeDeadline(deadlineAt: number | undefined): void {
|
|
64
|
+
if (deadlineAt !== undefined && Date.now() >= deadlineAt) throw new DbTransactionDeadlineError();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A backoff sleep never runs past the deadline: the next loop turn then fails on time. */
|
|
68
|
+
function sleepMs(ms: number, deadlineAt: number | undefined): number {
|
|
69
|
+
return deadlineAt === undefined ? ms : Math.max(0, Math.min(ms, deadlineAt - Date.now()));
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
export interface DbClient extends DbExecutor {
|
|
46
73
|
/**
|
|
47
74
|
* Run `fn` atomically. The callback receives an executor bound to the
|
|
@@ -393,15 +420,17 @@ class BunSqliteClient implements DbClient {
|
|
|
393
420
|
}
|
|
394
421
|
|
|
395
422
|
const readOnly = opts?.readOnly === true;
|
|
423
|
+
const deadlineAt = opts?.deadlineAt;
|
|
396
424
|
let sleptMs = 0;
|
|
397
425
|
for (let attemptIndex = 0; ; attemptIndex++) {
|
|
426
|
+
assertBeforeDeadline(deadlineAt);
|
|
398
427
|
const backoff = this.busyRetry.backoffMs[attemptIndex];
|
|
399
428
|
const canRetryAfter = backoff !== undefined && sleptMs + backoff <= this.busyRetry.maxWaitMs;
|
|
400
429
|
// The FINAL attempt spins `finalAttemptSpinMs`, never the ambient
|
|
401
430
|
// busy_timeout: a 5s synchronous camp froze every in-flight request.
|
|
402
431
|
// The dense 500ms backoff tail catches a periodic holder's release gap
|
|
403
432
|
// instead (see DEFAULT_BUSY_RETRY).
|
|
404
|
-
const attempt = await this.runTransactionAttempt(fn, readOnly, !canRetryAfter);
|
|
433
|
+
const attempt = await this.runTransactionAttempt(fn, readOnly, !canRetryAfter, deadlineAt);
|
|
405
434
|
if (attempt.ok) return attempt.value;
|
|
406
435
|
if (!canRetryAfter || backoff === undefined) throw attempt.busyBegin;
|
|
407
436
|
sleptMs += backoff;
|
|
@@ -409,7 +438,7 @@ class BunSqliteClient implements DbClient {
|
|
|
409
438
|
// (reads especially) proceeds while this writer waits out the external
|
|
410
439
|
// lock holder. Jitter desynchronizes concurrent retriers from each
|
|
411
440
|
// other and from periodic holders.
|
|
412
|
-
await sleep(jittered(backoff));
|
|
441
|
+
await sleep(sleepMs(jittered(backoff), deadlineAt));
|
|
413
442
|
}
|
|
414
443
|
}
|
|
415
444
|
|
|
@@ -422,6 +451,7 @@ class BunSqliteClient implements DbClient {
|
|
|
422
451
|
fn: (tx: DbExecutor) => Promise<T>,
|
|
423
452
|
readOnly: boolean,
|
|
424
453
|
finalAttempt = false,
|
|
454
|
+
deadlineAt?: number,
|
|
425
455
|
): Promise<{ ok: true; value: T } | { ok: false; busyBegin: unknown }> {
|
|
426
456
|
const release = await this.lock.acquire();
|
|
427
457
|
const ctx: TxContext = { closed: false, afterCommit: [] };
|
|
@@ -449,6 +479,8 @@ class BunSqliteClient implements DbClient {
|
|
|
449
479
|
}
|
|
450
480
|
began = true;
|
|
451
481
|
const result = await txContext.run(ctx, () => fn(tx));
|
|
482
|
+
// Last point a deadline can stop the write: the throw rolls back in the catch below.
|
|
483
|
+
assertBeforeDeadline(deadlineAt);
|
|
452
484
|
if (readOnly) {
|
|
453
485
|
db.run("COMMIT");
|
|
454
486
|
} else {
|
|
@@ -456,7 +488,10 @@ class BunSqliteClient implements DbClient {
|
|
|
456
488
|
// is exact. The open transaction pins the connection, so these
|
|
457
489
|
// retries hold the FIFO lock and their sleeps block queued work;
|
|
458
490
|
// WAL-mode COMMIT BUSY is rare enough for that to be acceptable.
|
|
459
|
-
await this.retryHoldingLock(
|
|
491
|
+
await this.retryHoldingLock(
|
|
492
|
+
() => this.shortSpin(db, () => db.run("COMMIT"), false, false),
|
|
493
|
+
deadlineAt,
|
|
494
|
+
);
|
|
460
495
|
}
|
|
461
496
|
for (const hook of ctx.afterCommit) this.scheduleHook(hook);
|
|
462
497
|
return { ok: true, value: result };
|
|
@@ -635,17 +670,20 @@ class BunSqliteClient implements DbClient {
|
|
|
635
670
|
* COMMIT-only retry: the open transaction pins the shared connection, so
|
|
636
671
|
* the FIFO lock stays held and these sleeps block queued in-process work.
|
|
637
672
|
*/
|
|
638
|
-
private async retryHoldingLock<T>(attempt: () => T): Promise<T> {
|
|
673
|
+
private async retryHoldingLock<T>(attempt: () => T, deadlineAt?: number): Promise<T> {
|
|
639
674
|
let sleptMs = 0;
|
|
640
675
|
for (let attemptIndex = 0; ; attemptIndex++) {
|
|
641
676
|
try {
|
|
642
677
|
return attempt();
|
|
643
678
|
} catch (err) {
|
|
644
679
|
if (!isSqliteBusy(err)) throw err;
|
|
680
|
+
// The transaction is still open and intact after a BUSY COMMIT: the caller rolls it back.
|
|
681
|
+
assertBeforeDeadline(deadlineAt);
|
|
645
682
|
const backoff = this.busyRetry.backoffMs[attemptIndex];
|
|
646
683
|
if (backoff === undefined || sleptMs + backoff > this.busyRetry.maxWaitMs) throw err;
|
|
647
684
|
sleptMs += backoff;
|
|
648
|
-
await sleep(backoff);
|
|
685
|
+
await sleep(sleepMs(backoff, deadlineAt));
|
|
686
|
+
assertBeforeDeadline(deadlineAt);
|
|
649
687
|
}
|
|
650
688
|
}
|
|
651
689
|
}
|
package/src/be/db.ts
CHANGED
|
@@ -158,7 +158,7 @@ import {
|
|
|
158
158
|
} from "../utils/identity-field-budget";
|
|
159
159
|
import { activeModelBlock, type ModelFamily } from "../utils/model-rate-limit-windows";
|
|
160
160
|
import { isEffectiveOutputSchema } from "../utils/output-schema";
|
|
161
|
-
import { getCurrentRequestUserId } from "../utils/request-auth-context";
|
|
161
|
+
import { getCurrentRequestUserId, getCurrentRunProvenance } from "../utils/request-auth-context";
|
|
162
162
|
import { isRuntimePoolsEnabled } from "../utils/runtime-pools-flag";
|
|
163
163
|
import {
|
|
164
164
|
registerSensitiveKeyName,
|
|
@@ -368,6 +368,7 @@ export {
|
|
|
368
368
|
getAllTasks,
|
|
369
369
|
getChildTasks,
|
|
370
370
|
getCompletedSlackTasks,
|
|
371
|
+
getFirstTaskInThread,
|
|
371
372
|
getInProgressSlackTasks,
|
|
372
373
|
getInProgressTasksByContextKey,
|
|
373
374
|
getLatestActiveTaskByContextKey,
|
|
@@ -2585,6 +2586,9 @@ export async function createTaskExtended(
|
|
|
2585
2586
|
if (parent.slackUserId && !options.slackUserId && !explicitForeignChannel) {
|
|
2586
2587
|
options.slackUserId = parent.slackUserId;
|
|
2587
2588
|
}
|
|
2589
|
+
if (parent.slackParticipants && !options.slackParticipants && !explicitForeignChannel) {
|
|
2590
|
+
options.slackParticipants = parent.slackParticipants;
|
|
2591
|
+
}
|
|
2588
2592
|
|
|
2589
2593
|
// AgentMail context
|
|
2590
2594
|
if (parent.agentmailInboxId && !options.agentmailInboxId) {
|
|
@@ -2955,17 +2959,19 @@ export async function createTaskExtended(
|
|
|
2955
2959
|
workflowRunId: options?.workflowRunId,
|
|
2956
2960
|
});
|
|
2957
2961
|
|
|
2962
|
+
const provenance = getCurrentRunProvenance();
|
|
2958
2963
|
const inserted = await getDbClient().get<AgentTaskRow>(
|
|
2959
2964
|
`INSERT INTO agent_tasks (
|
|
2960
2965
|
id, "key", agentId, creatorAgentId, task, status, source, routing_reason, routing_source, routing_note,
|
|
2961
2966
|
taskType, tags, priority, dependsOn, offeredTo, offeredAt,
|
|
2962
|
-
slackChannelId, slackThreadTs, slackTriggerMessageTs, slackUserId,
|
|
2967
|
+
slackChannelId, slackThreadTs, slackTriggerMessageTs, slackUserId, slackParticipants,
|
|
2963
2968
|
vcsProvider, vcsRepo, vcsEventType, vcsNumber, vcsCommentId, vcsAuthor, vcsUrl,
|
|
2964
2969
|
vcsInstallationId, vcsNodeId,
|
|
2965
2970
|
agentmailInboxId, agentmailMessageId, agentmailThreadId,
|
|
2966
|
-
mentionMessageId, mentionChannelId, dir, parentTaskId, dispatchedByTaskId, model, modelTier, effort, profile, scheduleId,
|
|
2967
|
-
workflowRunId, workflowRunStepId, outputSchema, followUpConfig, requestedByUserId, requestedByUserIdInherited, contextKey, routingAffinity, swarmVersion, createdAt, lastUpdatedAt, created_by, updated_by, isHumanFree
|
|
2968
|
-
|
|
2971
|
+
mentionMessageId, mentionChannelId, dir, parentTaskId, dispatchedByTaskId, model, modelTier, effort, profile, fallbackHops, scheduleId,
|
|
2972
|
+
workflowRunId, workflowRunStepId, outputSchema, followUpConfig, requestedByUserId, requestedByUserIdInherited, contextKey, routingAffinity, swarmVersion, createdAt, lastUpdatedAt, created_by, updated_by, isHumanFree,
|
|
2973
|
+
sourceStepId, sourceScriptRunId
|
|
2974
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
2969
2975
|
[
|
|
2970
2976
|
id,
|
|
2971
2977
|
insertKey,
|
|
@@ -2988,6 +2994,7 @@ export async function createTaskExtended(
|
|
|
2988
2994
|
options?.slackThreadTs ?? null,
|
|
2989
2995
|
options?.slackTriggerMessageTs ?? null,
|
|
2990
2996
|
options?.slackUserId ?? null,
|
|
2997
|
+
options?.slackParticipants ? JSON.stringify(options.slackParticipants) : null,
|
|
2991
2998
|
options?.vcsProvider ?? null,
|
|
2992
2999
|
options?.vcsRepo ?? null,
|
|
2993
3000
|
options?.vcsEventType ?? null,
|
|
@@ -3009,6 +3016,7 @@ export async function createTaskExtended(
|
|
|
3009
3016
|
options?.modelTier ?? null,
|
|
3010
3017
|
options?.effort ?? null,
|
|
3011
3018
|
options?.profile?.trim() || null,
|
|
3019
|
+
options?.fallbackHops?.length ? JSON.stringify(options.fallbackHops) : null,
|
|
3012
3020
|
options?.scheduleId ?? null,
|
|
3013
3021
|
options?.workflowRunId ?? null,
|
|
3014
3022
|
options?.workflowRunStepId ?? null,
|
|
@@ -3024,6 +3032,10 @@ export async function createTaskExtended(
|
|
|
3024
3032
|
auditUserId,
|
|
3025
3033
|
auditUserId,
|
|
3026
3034
|
isHumanFree ? 1 : 0,
|
|
3035
|
+
// A task a workflow node owns keeps only its workflowRunId: the engine
|
|
3036
|
+
// can run that node inside the request of the script that triggered it.
|
|
3037
|
+
options?.workflowRunId ? null : (provenance?.sourceStepId ?? null),
|
|
3038
|
+
options?.workflowRunId ? null : (provenance?.sourceScriptRunId ?? null),
|
|
3027
3039
|
],
|
|
3028
3040
|
);
|
|
3029
3041
|
if (!inserted) throw new Error("Failed to create task");
|
|
@@ -7963,8 +7975,13 @@ async function deleteWorkflowRows(id: string, source?: "api" | "mcp"): Promise<b
|
|
|
7963
7975
|
[id],
|
|
7964
7976
|
);
|
|
7965
7977
|
// 3. Delete runs (they reference workflow)
|
|
7978
|
+
const definitionHashes = await client.query<{ definitionHash: string }>(
|
|
7979
|
+
`SELECT DISTINCT definitionHash FROM workflow_runs
|
|
7980
|
+
WHERE workflowId = ? AND definitionHash IS NOT NULL`,
|
|
7981
|
+
[id],
|
|
7982
|
+
);
|
|
7966
7983
|
await client.run("DELETE FROM workflow_runs WHERE workflowId = ?", [id]);
|
|
7967
|
-
await deleteOrphanedRunDefinitions();
|
|
7984
|
+
await deleteOrphanedRunDefinitions(definitionHashes.map((row) => row.definitionHash));
|
|
7968
7985
|
await reclassifyTaskHumanFree(linkedTaskIds);
|
|
7969
7986
|
// 4. Delete every user's favorite of it (no FK to the workflow)
|
|
7970
7987
|
await client.run("DELETE FROM user_favorites WHERE itemType = 'workflow' AND itemId = ?", [id]);
|
|
@@ -8022,7 +8039,7 @@ export async function createWorkflowRun(data: {
|
|
|
8022
8039
|
}): Promise<WorkflowRun> {
|
|
8023
8040
|
const now = new Date().toISOString();
|
|
8024
8041
|
const row = await getDbClient().get<WorkflowRunRow>(
|
|
8025
|
-
`INSERT INTO workflow_runs (id, workflowId, triggerType, startedAt, triggerData, created_by, parentStepId, parentStepAttempt, triggeredByAgentId, definitionHash) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
8042
|
+
`INSERT INTO workflow_runs (id, workflowId, triggerType, startedAt, triggerData, created_by, parentStepId, parentStepAttempt, triggeredByAgentId, definitionHash, sourceStepId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
8026
8043
|
[
|
|
8027
8044
|
data.id,
|
|
8028
8045
|
data.workflowId,
|
|
@@ -8034,6 +8051,14 @@ export async function createWorkflowRun(data: {
|
|
|
8034
8051
|
data.parentStepAttempt ?? 0,
|
|
8035
8052
|
data.triggeredByAgentId ?? null,
|
|
8036
8053
|
data.definitionHash ?? null,
|
|
8054
|
+
// The script step whose run token started this run (trigger-workflow is
|
|
8055
|
+
// a manual or api trigger). A sub-workflow child is linked by
|
|
8056
|
+
// parentStepId instead, and an event or schedule run is never the
|
|
8057
|
+
// script's, even when it starts inside that script's request.
|
|
8058
|
+
data.parentStepId ||
|
|
8059
|
+
(data.triggerType !== "api" && (data.triggerType ?? "manual") !== "manual")
|
|
8060
|
+
? null
|
|
8061
|
+
: (getCurrentRunProvenance()?.sourceStepId ?? null),
|
|
8037
8062
|
],
|
|
8038
8063
|
);
|
|
8039
8064
|
if (!row) throw new Error("Failed to create workflow run");
|
|
@@ -14356,11 +14381,13 @@ export async function recordInlineScriptRun(data: {
|
|
|
14356
14381
|
// redact them here so every caller is covered.
|
|
14357
14382
|
const args = scrubJsonValue(data.args ?? null);
|
|
14358
14383
|
const output = data.output === undefined ? null : scrubJsonValue(data.output);
|
|
14384
|
+
const provenance = getCurrentRunProvenance();
|
|
14359
14385
|
const row = await getDbClient().get<ScriptRunRow>(
|
|
14360
14386
|
`INSERT INTO script_runs
|
|
14361
14387
|
(id, agentId, scriptName, source, args, kind, status, output, error,
|
|
14362
|
-
startedAt, finishedAt, requestedByUserId, created_by, updated_by, apiEndpointId
|
|
14363
|
-
|
|
14388
|
+
startedAt, finishedAt, requestedByUserId, created_by, updated_by, apiEndpointId,
|
|
14389
|
+
sourceStepId, parentScriptRunId)
|
|
14390
|
+
VALUES (?, ?, ?, ?, ?, 'inline', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
14364
14391
|
RETURNING *`,
|
|
14365
14392
|
[
|
|
14366
14393
|
data.id,
|
|
@@ -14377,6 +14404,10 @@ export async function recordInlineScriptRun(data: {
|
|
|
14377
14404
|
data.createdBy ?? null,
|
|
14378
14405
|
data.createdBy ?? null,
|
|
14379
14406
|
data.apiEndpointId ?? null,
|
|
14407
|
+
// A run called through another script run's token (a nested
|
|
14408
|
+
// ctx.swarm.script_run) records that run and its workflow step.
|
|
14409
|
+
provenance?.sourceStepId ?? null,
|
|
14410
|
+
provenance?.sourceScriptRunId ?? null,
|
|
14380
14411
|
],
|
|
14381
14412
|
);
|
|
14382
14413
|
if (!row) throw new Error("Failed to record inline script run");
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Model profiles, PR 3 (runbooks/model-tiers.md § Fallbacks on provider errors).
|
|
2
|
+
|
|
3
|
+
-- JSON array of profile names on the same harness, tried in order when a
|
|
4
|
+
-- provider error ends a task running on this profile. '[]' never hops.
|
|
5
|
+
ALTER TABLE model_profiles ADD COLUMN fallbacks TEXT NOT NULL DEFAULT '[]';
|
|
6
|
+
|
|
7
|
+
-- JSON array of the hops the work took so far ({from, profile, errorClass,
|
|
8
|
+
-- at, skipped?}); every resume of the same work carries it. NULL: no hop.
|
|
9
|
+
ALTER TABLE agent_tasks ADD COLUMN fallbackHops TEXT;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- Daily rollup of the automation savings model (src/be/savings/).
|
|
2
|
+
-- One row per job per UTC day with tier-independent counts and costs; the API
|
|
3
|
+
-- applies the tier curve, the schedule cap, the enabled-only rule and the
|
|
4
|
+
-- error band at read time. Schedule counts stay uncapped here, so the window
|
|
5
|
+
-- cap stays exact when buckets are summed. jobKind 'script' and subKind are
|
|
6
|
+
-- reserved for the script rollup; workflows use subKind ''.
|
|
7
|
+
CREATE TABLE IF NOT EXISTS automation_savings_daily (
|
|
8
|
+
day TEXT NOT NULL,
|
|
9
|
+
jobKind TEXT NOT NULL CHECK (jobKind IN ('workflow', 'script')),
|
|
10
|
+
jobId TEXT NOT NULL,
|
|
11
|
+
jobKey TEXT NOT NULL,
|
|
12
|
+
jobName TEXT NOT NULL,
|
|
13
|
+
subKind TEXT NOT NULL DEFAULT '',
|
|
14
|
+
runs INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
countedRuns INTEGER NOT NULL DEFAULT 0,
|
|
16
|
+
schedRuns INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
schedEffectRuns INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
eventRuns INTEGER NOT NULL DEFAULT 0,
|
|
19
|
+
effectRuns INTEGER NOT NULL DEFAULT 0,
|
|
20
|
+
effectOpsSum REAL NOT NULL DEFAULT 0,
|
|
21
|
+
opsSum REAL NOT NULL DEFAULT 0,
|
|
22
|
+
agentTasks INTEGER NOT NULL DEFAULT 0,
|
|
23
|
+
agentUsd REAL NOT NULL DEFAULT 0,
|
|
24
|
+
agentMs REAL NOT NULL DEFAULT 0,
|
|
25
|
+
followupUsd REAL NOT NULL DEFAULT 0,
|
|
26
|
+
recordedLlmUsd REAL NOT NULL DEFAULT 0,
|
|
27
|
+
estimatedLlmUsd REAL NOT NULL DEFAULT 0,
|
|
28
|
+
computeSecs REAL NOT NULL DEFAULT 0,
|
|
29
|
+
modelVersion INTEGER NOT NULL,
|
|
30
|
+
computedAt TEXT NOT NULL,
|
|
31
|
+
PRIMARY KEY (day, jobKind, jobId, subKind)
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_automation_savings_daily_job
|
|
35
|
+
ON automation_savings_daily(jobKind, jobId, day);
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_automation_savings_daily_key
|
|
37
|
+
ON automation_savings_daily(jobKind, jobKey, day);
|
|
38
|
+
|
|
39
|
+
-- Which days the rollup has computed, per job kind: a day with no runs has no
|
|
40
|
+
-- bucket rows, and this row tells it apart from a day not computed yet.
|
|
41
|
+
CREATE TABLE IF NOT EXISTS automation_savings_days (
|
|
42
|
+
day TEXT NOT NULL,
|
|
43
|
+
jobKind TEXT NOT NULL CHECK (jobKind IN ('workflow', 'script')),
|
|
44
|
+
modelVersion INTEGER NOT NULL,
|
|
45
|
+
computedAt TEXT NOT NULL,
|
|
46
|
+
PRIMARY KEY (day, jobKind)
|
|
47
|
+
);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- Multi-person Slack threads: the people in the thread when the task was
|
|
2
|
+
-- created ({people: [{slackUserId, userId?, trust, starter?, newest?, asked?}],
|
|
3
|
+
-- more}). NULL: not a Slack task, or created before this column existed.
|
|
4
|
+
ALTER TABLE agent_tasks ADD COLUMN slackParticipants TEXT;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
-- Provenance for the savings "with components" view (src/be/savings/).
|
|
2
|
+
--
|
|
3
|
+
-- A script run's per-run api token (session_tokens.scriptRun = 1) now records
|
|
4
|
+
-- where the run came from: the swarm-script workflow step that started it, and
|
|
5
|
+
-- the script_runs row of the run itself. Rows created through that token carry
|
|
6
|
+
-- it, so a workflow's components (child runs, tasks and nested script runs its
|
|
7
|
+
-- script steps made) join exactly instead of by output text.
|
|
8
|
+
--
|
|
9
|
+
-- parentStepId and workflowRunId are not reused: parentStepId carries
|
|
10
|
+
-- sub-workflow attempt semantics, and a workflowRunId on a script-made task
|
|
11
|
+
-- would switch off its lead follow-up.
|
|
12
|
+
ALTER TABLE session_tokens ADD COLUMN sourceStepId TEXT;
|
|
13
|
+
ALTER TABLE session_tokens ADD COLUMN sourceScriptRunId TEXT;
|
|
14
|
+
|
|
15
|
+
ALTER TABLE agent_tasks ADD COLUMN sourceStepId TEXT;
|
|
16
|
+
ALTER TABLE agent_tasks ADD COLUMN sourceScriptRunId TEXT;
|
|
17
|
+
ALTER TABLE workflow_runs ADD COLUMN sourceStepId TEXT;
|
|
18
|
+
ALTER TABLE script_runs ADD COLUMN sourceStepId TEXT;
|
|
19
|
+
ALTER TABLE script_runs ADD COLUMN parentScriptRunId TEXT;
|
|
20
|
+
|
|
21
|
+
-- The rollup reads stamped rows one day at a time, from the child side.
|
|
22
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_sourceStep_created
|
|
23
|
+
ON agent_tasks(createdAt) WHERE sourceStepId IS NOT NULL;
|
|
24
|
+
CREATE INDEX IF NOT EXISTS idx_agent_tasks_sourceScriptRun_created
|
|
25
|
+
ON agent_tasks(createdAt) WHERE sourceScriptRunId IS NOT NULL;
|
|
26
|
+
CREATE INDEX IF NOT EXISTS idx_workflow_runs_sourceStep_started
|
|
27
|
+
ON workflow_runs(startedAt) WHERE sourceStepId IS NOT NULL;
|
|
28
|
+
CREATE INDEX IF NOT EXISTS idx_script_runs_sourceStep_started
|
|
29
|
+
ON script_runs(startedAt) WHERE sourceStepId IS NOT NULL;
|
|
30
|
+
CREATE INDEX IF NOT EXISTS idx_script_runs_parentScriptRunId
|
|
31
|
+
ON script_runs(parentScriptRunId) WHERE parentScriptRunId IS NOT NULL;
|
|
32
|
+
|
|
33
|
+
-- Spend of the agent tasks a workflow's runs caused without owning them:
|
|
34
|
+
-- descendants of its agent-task nodes' tasks, and tasks its script steps
|
|
35
|
+
-- created (with their descendants). Kept on both sides of the saving.
|
|
36
|
+
ALTER TABLE automation_savings_daily ADD COLUMN childTaskUsd REAL NOT NULL DEFAULT 0;
|
|
37
|
+
ALTER TABLE automation_savings_daily ADD COLUMN childTaskMs REAL NOT NULL DEFAULT 0;
|
|
38
|
+
|
|
39
|
+
-- Per UTC day (of the child), how many runs, tasks and script runs each
|
|
40
|
+
-- workflow caused. Read-time only: the "with components" view walks these
|
|
41
|
+
-- links; no list or fleet total adds them, since every child is already
|
|
42
|
+
-- priced on its own row.
|
|
43
|
+
CREATE TABLE IF NOT EXISTS automation_savings_links (
|
|
44
|
+
day TEXT NOT NULL,
|
|
45
|
+
parentJobId TEXT NOT NULL,
|
|
46
|
+
childKind TEXT NOT NULL CHECK (childKind IN ('workflow', 'script', 'task')),
|
|
47
|
+
childJobId TEXT NOT NULL,
|
|
48
|
+
linkKind TEXT NOT NULL CHECK (linkKind IN ('sub-workflow', 'step-workflow', 'step-script', 'step-task', 'descendant-task')),
|
|
49
|
+
n INTEGER NOT NULL DEFAULT 0,
|
|
50
|
+
actualUsd REAL NOT NULL DEFAULT 0,
|
|
51
|
+
keptUsd REAL NOT NULL DEFAULT 0,
|
|
52
|
+
modelVersion INTEGER NOT NULL,
|
|
53
|
+
computedAt TEXT NOT NULL,
|
|
54
|
+
PRIMARY KEY (day, parentJobId, childKind, childJobId, linkKind)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
CREATE INDEX IF NOT EXISTS idx_automation_savings_links_parent
|
|
58
|
+
ON automation_savings_links(parentJobId, day);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
-- The savings read path filters buckets by kind, model version and a day
|
|
2
|
+
-- range (src/be/savings/read.ts). The existing indexes lead with jobId or
|
|
3
|
+
-- jobKey, so every read scanned all buckets of a kind; this one serves the
|
|
4
|
+
-- per-day row count and each day-range slice as a range scan.
|
|
5
|
+
CREATE INDEX IF NOT EXISTS idx_automation_savings_daily_read
|
|
6
|
+
ON automation_savings_daily(jobKind, modelVersion, day, subKind);
|
|
@@ -49,6 +49,11 @@ export interface ProfileCheckOptions {
|
|
|
49
49
|
vcsRepo?: string | null;
|
|
50
50
|
/** Whether the worker's config read includes secret repo rows (`readsRepoSecrets`). */
|
|
51
51
|
includeRepoSecrets?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Judge the profile's fallbacks too (default). Gates that read only `ok`
|
|
54
|
+
* pass false and skip the extra reads.
|
|
55
|
+
*/
|
|
56
|
+
fallbacks?: boolean;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
@@ -70,11 +75,19 @@ export function runtimeReadsRepoSecrets(agent: { id: string; isLead?: boolean })
|
|
|
70
75
|
*/
|
|
71
76
|
export async function vcsRepoId(vcsRepo: string | null | undefined): Promise<string | null> {
|
|
72
77
|
if (!vcsRepo?.trim()) return null;
|
|
73
|
-
const
|
|
78
|
+
const client = getDbClient();
|
|
79
|
+
const named = await client.query<{ id: string; url: string }>(
|
|
74
80
|
"SELECT id, url FROM swarm_repos WHERE name = ? ORDER BY name ASC",
|
|
75
81
|
[vcsRepoName(vcsRepo)],
|
|
76
82
|
);
|
|
77
|
-
|
|
83
|
+
const match = named.find((r) => vcsRepoUrlMatches(r.url, vcsRepo));
|
|
84
|
+
if (match) return match.id;
|
|
85
|
+
// A repo registered under a display name (`frontend` for acme/web) has no name hit:
|
|
86
|
+
// match its URL instead, as fetchRepoConfig falls back to.
|
|
87
|
+
const all = await client.query<{ id: string; url: string }>(
|
|
88
|
+
"SELECT id, url FROM swarm_repos ORDER BY name ASC",
|
|
89
|
+
);
|
|
90
|
+
return all.find((r) => vcsRepoUrlMatches(r.url, vcsRepo))?.id ?? null;
|
|
78
91
|
}
|
|
79
92
|
|
|
80
93
|
/** Pooled credential values the worker would get, by var: exported config rows only. */
|
|
@@ -232,10 +245,37 @@ async function credentialAllowlistRow(
|
|
|
232
245
|
};
|
|
233
246
|
}
|
|
234
247
|
|
|
248
|
+
/** Every check row for one profile on the agent. */
|
|
249
|
+
async function profileRows(
|
|
250
|
+
agent: Agent,
|
|
251
|
+
profile: ModelProfile,
|
|
252
|
+
harness: string | null,
|
|
253
|
+
agentHarness: string | null,
|
|
254
|
+
pools: Map<string, string>,
|
|
255
|
+
): Promise<ProfileCheckRow[]> {
|
|
256
|
+
const checks: ProfileCheckRow[] = [
|
|
257
|
+
harnessRow(profile, harness),
|
|
258
|
+
modelRow(profile, harness),
|
|
259
|
+
harnessCredentialsRow(agent, profile, harness, agentHarness, pools),
|
|
260
|
+
];
|
|
261
|
+
if (hasUnreadableCredentialAllowlist(profile)) {
|
|
262
|
+
// Null credentials here would read as the whole pool; fail closed instead.
|
|
263
|
+
checks.push({
|
|
264
|
+
check: "credential-allowlist",
|
|
265
|
+
state: "fail",
|
|
266
|
+
detail: "the stored credential allowlist is unreadable; set the profile's credentials again",
|
|
267
|
+
});
|
|
268
|
+
} else if (profile.credentials) {
|
|
269
|
+
checks.push(await credentialAllowlistRow(agent.id, profile.credentials, pools));
|
|
270
|
+
}
|
|
271
|
+
return checks;
|
|
272
|
+
}
|
|
273
|
+
|
|
235
274
|
/**
|
|
236
275
|
* Judge whether `agentId` can run `profileName`. Null when the agent or the
|
|
237
|
-
* profile does not exist.
|
|
238
|
-
* primary only.
|
|
276
|
+
* profile does not exist. `profiles` holds the primary, then each of its
|
|
277
|
+
* fallbacks with its own rows; `ok` judges the primary only. A fallback that
|
|
278
|
+
* no longer exists is left out.
|
|
239
279
|
*/
|
|
240
280
|
export async function checkProfileForAgent(
|
|
241
281
|
agentId: string,
|
|
@@ -251,23 +291,16 @@ export async function checkProfileForAgent(
|
|
|
251
291
|
const harness = options.harness === undefined ? agentHarness : options.harness;
|
|
252
292
|
const pools = await configPools(agentId, options);
|
|
253
293
|
|
|
254
|
-
const checks
|
|
255
|
-
harnessRow(profile, harness),
|
|
256
|
-
modelRow(profile, harness),
|
|
257
|
-
harnessCredentialsRow(agent, profile, harness, agentHarness, pools),
|
|
258
|
-
];
|
|
259
|
-
if (hasUnreadableCredentialAllowlist(profile)) {
|
|
260
|
-
// Null credentials here would read as the whole pool; fail closed instead.
|
|
261
|
-
checks.push({
|
|
262
|
-
check: "credential-allowlist",
|
|
263
|
-
state: "fail",
|
|
264
|
-
detail: "the stored credential allowlist is unreadable; set the profile's credentials again",
|
|
265
|
-
});
|
|
266
|
-
} else if (profile.credentials) {
|
|
267
|
-
checks.push(await credentialAllowlistRow(agentId, profile.credentials, pools));
|
|
268
|
-
}
|
|
294
|
+
const checks = await profileRows(agent, profile, harness, agentHarness, pools);
|
|
269
295
|
const ok = !checks.some((row) => row.state === "fail");
|
|
270
|
-
|
|
296
|
+
const profiles: ProfileCheckResult["profiles"] = [{ name: profile.name, ok, checks }];
|
|
297
|
+
for (const name of options.fallbacks === false ? [] : profile.fallbacks) {
|
|
298
|
+
const fallback = await getModelProfileByName(name);
|
|
299
|
+
if (!fallback) continue;
|
|
300
|
+
const rows = await profileRows(agent, fallback, harness, agentHarness, pools);
|
|
301
|
+
profiles.push({ name, ok: !rows.some((row) => row.state === "fail"), checks: rows });
|
|
302
|
+
}
|
|
303
|
+
return { agentId, ok, profiles };
|
|
271
304
|
}
|
|
272
305
|
|
|
273
306
|
/** One line per failing row of the primary profile, for a gate's error message. */
|