@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
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automation savings model: what the work a workflow did would have cost if
|
|
3
|
+
* agent tasks had done it instead.
|
|
4
|
+
*
|
|
5
|
+
* Port of the `automation-savings-estimate` script, version 7, calibrated on
|
|
6
|
+
* 2026-11-05 against opus 5.5 session costs. Change a constant here only
|
|
7
|
+
* together with a new calibration.
|
|
8
|
+
*
|
|
9
|
+
* Per substituted run: agent-only cost = R * curve(tau) * err + F, with
|
|
10
|
+
* tau = T0 + K * ops (capped at TAU_MAX turns), where ops counts the awaited
|
|
11
|
+
* I/O calls of the deterministic steps. Agent-task nodes inside a workflow are
|
|
12
|
+
* kept at their actual cost on both sides; only the deterministic glue is
|
|
13
|
+
* substituted.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
|
|
18
|
+
export const SAVINGS_TIERS = ["smol", "regular", "smart", "ultra"] as const;
|
|
19
|
+
export type SavingsTier = (typeof SAVINGS_TIERS)[number];
|
|
20
|
+
export type SavingsBand = { p10: number; p50: number; p90: number };
|
|
21
|
+
type Quantile = keyof SavingsBand;
|
|
22
|
+
|
|
23
|
+
export const CALIBRATION_MODEL = "claude-opus-5-5";
|
|
24
|
+
export const CALIBRATED_AT = "2026-11-05";
|
|
25
|
+
/**
|
|
26
|
+
* Version of the constants and of the facts the daily rollup stores. Bump it
|
|
27
|
+
* with any change here or in the rollup's SQL: buckets computed under an older
|
|
28
|
+
* version are recomputed on the next tick.
|
|
29
|
+
*/
|
|
30
|
+
export const MODEL_VERSION = 2;
|
|
31
|
+
|
|
32
|
+
/** Agent turns per deterministic op. */
|
|
33
|
+
export const K = 0.2753;
|
|
34
|
+
/** Bootstrap turns of a fresh agent session. */
|
|
35
|
+
export const T0 = 2;
|
|
36
|
+
/** tau cap: the fleet's p95 session length in turns. */
|
|
37
|
+
export const TAU_MAX = 61;
|
|
38
|
+
/** An agent would not poll faster than hourly: schedule runs count at most 24 a day. */
|
|
39
|
+
export const CAP_PER_DAY = 24;
|
|
40
|
+
/** Lead follow-up review per standalone agent task, USD. */
|
|
41
|
+
export const F_FOLLOWUP = 0.107;
|
|
42
|
+
/** USD per million SystemOne input tokens when a run records no cost. */
|
|
43
|
+
export const JEV_PER_M = 0.042;
|
|
44
|
+
/** Failure and retry multiplier, from scheduled agent tasks. */
|
|
45
|
+
export const R: SavingsBand = { p10: 1.011, p50: 1.02, p90: 1.03 };
|
|
46
|
+
/** Leave-one-out backtest spread for a single job. */
|
|
47
|
+
export const ERR_JOB: SavingsBand = { p10: 0.542, p50: 1.0, p90: 1.508 };
|
|
48
|
+
/** Monte Carlo spread for a fleet sum. */
|
|
49
|
+
export const ERR_FLEET: SavingsBand = { p10: 0.746, p50: 1.0, p90: 1.325 };
|
|
50
|
+
/** Ops of a swarm-script node whose script is not in the catalog. */
|
|
51
|
+
export const DEFAULT_OPS = 9;
|
|
52
|
+
/** Ops of a script run with inline source (no catalog entry), from v7. */
|
|
53
|
+
export const INLINE_OPS = 3.9;
|
|
54
|
+
/** Job id of the script runs that carry no script name (inline source). */
|
|
55
|
+
export const INLINE_SCRIPT_NAME = "(inline source)";
|
|
56
|
+
/** Upper bound on the ops counted for one script. */
|
|
57
|
+
export const MAX_SCRIPT_OPS = 100;
|
|
58
|
+
/**
|
|
59
|
+
* Enabled-only rule (an event router): an event-triggered workflow that ran
|
|
60
|
+
* more than this many times a day on average, and where fewer than
|
|
61
|
+
* ROUTER_MAX_EFFECT_SHARE of its runs had an effect, is a filter over an event
|
|
62
|
+
* stream. Only its effect runs count, each as one agent decision.
|
|
63
|
+
* The v7 script names the router; a product needs a rule. The plan's 24 a day
|
|
64
|
+
* also caught an event workflow that does real work on every run (41 runs a
|
|
65
|
+
* day, no linked effects), so the threshold is 10 events an hour.
|
|
66
|
+
*/
|
|
67
|
+
export const ROUTER_MIN_RUNS_PER_DAY = 240;
|
|
68
|
+
export const ROUTER_MAX_EFFECT_SHARE = 0.1;
|
|
69
|
+
/** Share of runs with `triggerType='event'` for a workflow to count as event-triggered. */
|
|
70
|
+
export const ROUTER_MIN_EVENT_SHARE = 0.9;
|
|
71
|
+
|
|
72
|
+
// Session cost (USD) and agent-active hours by session length in turns
|
|
73
|
+
// (index 0 = 1 turn), per tier, from 30 days of session_costs repriced at each
|
|
74
|
+
// tier's model.
|
|
75
|
+
export type CurveSet = Record<SavingsTier, { usd: readonly number[]; hrs: readonly number[] }>;
|
|
76
|
+
export const CURVE: CurveSet = {
|
|
77
|
+
smol: {
|
|
78
|
+
usd: [
|
|
79
|
+
0.0056, 0.0068, 0.0075, 0.0086, 0.0092, 0.0105, 0.012, 0.0146, 0.0163, 0.0171, 0.0184, 0.02,
|
|
80
|
+
0.0212, 0.0222, 0.0225, 0.0242, 0.0254, 0.0268, 0.028, 0.0291, 0.0306, 0.0319, 0.0333, 0.0353,
|
|
81
|
+
0.0359, 0.0374, 0.0389, 0.0413, 0.043, 0.0434, 0.045, 0.047, 0.0489, 0.0505, 0.051, 0.0535,
|
|
82
|
+
0.0554, 0.057, 0.0586, 0.0595, 0.0612, 0.0633, 0.065, 0.0679, 0.0683, 0.0702, 0.0717, 0.0742,
|
|
83
|
+
0.0757, 0.0764, 0.078, 0.0805, 0.0824, 0.0842, 0.085, 0.0881, 0.0901, 0.093, 0.0949, 0.0963,
|
|
84
|
+
0.0979,
|
|
85
|
+
],
|
|
86
|
+
hrs: [
|
|
87
|
+
0.00409, 0.00521, 0.00674, 0.00831, 0.00993, 0.0126, 0.01586, 0.01997, 0.02272, 0.02392,
|
|
88
|
+
0.02615, 0.03049, 0.034, 0.03708, 0.03835, 0.04398, 0.04779, 0.05207, 0.05544, 0.05811,
|
|
89
|
+
0.06247, 0.06595, 0.07002, 0.07589, 0.0778, 0.08234, 0.08704, 0.09357, 0.09884, 0.10091,
|
|
90
|
+
0.10694, 0.11393, 0.12002, 0.12476, 0.12736, 0.13666, 0.14271, 0.14854, 0.15322, 0.15738,
|
|
91
|
+
0.16341, 0.17023, 0.17766, 0.18815, 0.18983, 0.19846, 0.1996, 0.20217, 0.20833, 0.21012,
|
|
92
|
+
0.21538, 0.2224, 0.23067, 0.23488, 0.23825, 0.24844, 0.25554, 0.26838, 0.27469, 0.27725,
|
|
93
|
+
0.28259,
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
regular: {
|
|
97
|
+
usd: [
|
|
98
|
+
0.0878, 0.1074, 0.1211, 0.1383, 0.1497, 0.1699, 0.196, 0.2372, 0.2628, 0.2762, 0.2952, 0.3209,
|
|
99
|
+
0.3399, 0.3544, 0.3593, 0.3859, 0.4041, 0.425, 0.4435, 0.4586, 0.4817, 0.5001, 0.5215, 0.5501,
|
|
100
|
+
0.5582, 0.5795, 0.6027, 0.6364, 0.6621, 0.6678, 0.6917, 0.7189, 0.7459, 0.7683, 0.7758,
|
|
101
|
+
0.8096, 0.8361, 0.8588, 0.8806, 0.893, 0.9152, 0.9422, 0.9654, 1.0056, 1.0108, 1.0351, 1.0545,
|
|
102
|
+
1.0885, 1.108, 1.1184, 1.1389, 1.1716, 1.1969, 1.2205, 1.2309, 1.2733, 1.3003, 1.3399, 1.3639,
|
|
103
|
+
1.3838, 1.4053,
|
|
104
|
+
],
|
|
105
|
+
hrs: [
|
|
106
|
+
0.00341, 0.00435, 0.00562, 0.00693, 0.00828, 0.0105, 0.01322, 0.01665, 0.01894, 0.01994,
|
|
107
|
+
0.0218, 0.02541, 0.02834, 0.0309, 0.03197, 0.03665, 0.03983, 0.0434, 0.04621, 0.04844,
|
|
108
|
+
0.05207, 0.05497, 0.05836, 0.06326, 0.06485, 0.06863, 0.07255, 0.07799, 0.08239, 0.08411,
|
|
109
|
+
0.08914, 0.09496, 0.10004, 0.10399, 0.10616, 0.11391, 0.11896, 0.12382, 0.12771, 0.13118,
|
|
110
|
+
0.13621, 0.14189, 0.14808, 0.15683, 0.15823, 0.16542, 0.16638, 0.16852, 0.17365, 0.17514,
|
|
111
|
+
0.17952, 0.18537, 0.19227, 0.19578, 0.19858, 0.20708, 0.213, 0.22371, 0.22896, 0.23109,
|
|
112
|
+
0.23555,
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
smart: {
|
|
116
|
+
usd: [
|
|
117
|
+
0.1746, 0.2138, 0.2413, 0.2756, 0.2983, 0.3385, 0.3907, 0.4729, 0.5243, 0.551, 0.589, 0.6402,
|
|
118
|
+
0.6783, 0.7075, 0.7173, 0.7705, 0.8068, 0.8487, 0.8857, 0.9158, 0.9621, 0.9989, 1.0416,
|
|
119
|
+
1.0987, 1.1149, 1.1576, 1.2041, 1.2714, 1.3225, 1.3339, 1.3815, 1.4359, 1.49, 1.5347, 1.5496,
|
|
120
|
+
1.617, 1.67, 1.7153, 1.7596, 1.7844, 1.8288, 1.8828, 1.9291, 2.0095, 2.0198, 2.0683, 2.1069,
|
|
121
|
+
2.1748, 2.2137, 2.2345, 2.2752, 2.3413, 2.3918, 2.4388, 2.4595, 2.5444, 2.5985, 2.678, 2.7259,
|
|
122
|
+
2.7657, 2.8086,
|
|
123
|
+
],
|
|
124
|
+
hrs: [
|
|
125
|
+
0.00265, 0.00338, 0.00437, 0.00539, 0.00644, 0.00817, 0.01029, 0.01296, 0.01474, 0.01552,
|
|
126
|
+
0.01696, 0.01978, 0.02205, 0.02405, 0.02488, 0.02852, 0.031, 0.03377, 0.03596, 0.03769,
|
|
127
|
+
0.04052, 0.04278, 0.04541, 0.04923, 0.05046, 0.05341, 0.05645, 0.06069, 0.06411, 0.06545,
|
|
128
|
+
0.06937, 0.0739, 0.07785, 0.08092, 0.08261, 0.08865, 0.09257, 0.09635, 0.09939, 0.10209,
|
|
129
|
+
0.106, 0.11041, 0.11524, 0.12204, 0.12313, 0.12873, 0.12947, 0.13114, 0.13513, 0.13629,
|
|
130
|
+
0.1397, 0.14425, 0.14962, 0.15235, 0.15453, 0.16114, 0.16575, 0.17408, 0.17817, 0.17983,
|
|
131
|
+
0.1833,
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
ultra: {
|
|
135
|
+
usd: [
|
|
136
|
+
0.4215, 0.5126, 0.5737, 0.6515, 0.702, 0.7922, 0.9108, 1.0969, 1.2137, 1.2729, 1.3559, 1.4659,
|
|
137
|
+
1.5471, 1.6075, 1.6273, 1.7385, 1.8143, 1.9006, 1.9774, 2.0389, 2.1345, 2.211, 2.2993, 2.4146,
|
|
138
|
+
2.4463, 2.5326, 2.6278, 2.7635, 2.8673, 2.8901, 2.9876, 3.0983, 3.2073, 3.2964, 3.3254,
|
|
139
|
+
3.4593, 3.5632, 3.6518, 3.7384, 3.784, 3.8661, 3.9685, 4.0556, 4.2104, 4.229, 4.3174, 4.3912,
|
|
140
|
+
4.5199, 4.5949, 4.6375, 4.7124, 4.8381, 4.931, 5.017, 5.0554, 5.2133, 5.3132, 5.4655, 5.5501,
|
|
141
|
+
5.6254, 5.7067,
|
|
142
|
+
],
|
|
143
|
+
hrs: [
|
|
144
|
+
0.00265, 0.00338, 0.00437, 0.00539, 0.00644, 0.00817, 0.01029, 0.01296, 0.01474, 0.01552,
|
|
145
|
+
0.01696, 0.01978, 0.02205, 0.02405, 0.02488, 0.02852, 0.031, 0.03377, 0.03596, 0.03769,
|
|
146
|
+
0.04052, 0.04278, 0.04541, 0.04923, 0.05046, 0.05341, 0.05645, 0.06069, 0.06411, 0.06545,
|
|
147
|
+
0.06937, 0.0739, 0.07785, 0.08092, 0.08261, 0.08865, 0.09257, 0.09635, 0.09939, 0.10209,
|
|
148
|
+
0.106, 0.11041, 0.11524, 0.12204, 0.12313, 0.12873, 0.12947, 0.13114, 0.13513, 0.13629,
|
|
149
|
+
0.1397, 0.14425, 0.14962, 0.15235, 0.15453, 0.16114, 0.16575, 0.17408, 0.17817, 0.17983,
|
|
150
|
+
0.1833,
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** Where the curve in use came from: the constants above, or this deployment's own sessions. */
|
|
156
|
+
export type CalibrationSource = "shipped" | "deployment";
|
|
157
|
+
export type Calibration = {
|
|
158
|
+
source: CalibrationSource;
|
|
159
|
+
/** YYYY-MM-DD the curve was derived. */
|
|
160
|
+
calibratedAt: string;
|
|
161
|
+
model: string;
|
|
162
|
+
curve: CurveSet;
|
|
163
|
+
/** The sessions the curve was derived from; absent on a row stored before this was recorded. */
|
|
164
|
+
window?: { start: string; end: string; sessions: number };
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const SHIPPED_CALIBRATION: Calibration = {
|
|
168
|
+
source: "shipped",
|
|
169
|
+
calibratedAt: CALIBRATED_AT,
|
|
170
|
+
model: CALIBRATION_MODEL,
|
|
171
|
+
curve: CURVE,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** Global `swarm_config` key holding the JSON written by `POST /api/savings/calibration`. */
|
|
175
|
+
export const SAVINGS_CALIBRATION_KEY = "SAVINGS_CURVE_CALIBRATION";
|
|
176
|
+
|
|
177
|
+
const CurveArraySchema = z.array(z.number().positive()).length(TAU_MAX);
|
|
178
|
+
const TierCurveSchema = z.object({ usd: CurveArraySchema, hrs: CurveArraySchema });
|
|
179
|
+
export const StoredCalibrationSchema = z.object({
|
|
180
|
+
calibratedAt: z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
181
|
+
model: z.string().min(1),
|
|
182
|
+
window: z
|
|
183
|
+
.object({ start: z.string(), end: z.string(), sessions: z.number().int().nonnegative() })
|
|
184
|
+
.optional(),
|
|
185
|
+
curve: z.object({
|
|
186
|
+
smol: TierCurveSchema,
|
|
187
|
+
regular: TierCurveSchema,
|
|
188
|
+
smart: TierCurveSchema,
|
|
189
|
+
ultra: TierCurveSchema,
|
|
190
|
+
}),
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
/** The stored deployment curve, or null when the value is missing or malformed (callers fall back to the shipped one). */
|
|
194
|
+
export function parseCalibration(raw: string | null | undefined): Calibration | null {
|
|
195
|
+
if (!raw) return null;
|
|
196
|
+
try {
|
|
197
|
+
const parsed = StoredCalibrationSchema.safeParse(JSON.parse(raw));
|
|
198
|
+
if (!parsed.success) return null;
|
|
199
|
+
const { calibratedAt, model, curve, window } = parsed.data;
|
|
200
|
+
return { source: "deployment", calibratedAt, model, curve, ...(window ? { window } : {}) };
|
|
201
|
+
} catch {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Linear interpolation on the tier curve; tau is clamped to [1, TAU_MAX]. */
|
|
207
|
+
export function curve(
|
|
208
|
+
tau: number,
|
|
209
|
+
tier: SavingsTier,
|
|
210
|
+
key: "usd" | "hrs",
|
|
211
|
+
set: CurveSet = CURVE,
|
|
212
|
+
): number {
|
|
213
|
+
const t = Math.max(1, Math.min(TAU_MAX, tau));
|
|
214
|
+
const a = set[tier][key];
|
|
215
|
+
const lo = Math.floor(t);
|
|
216
|
+
const hi = Math.ceil(t);
|
|
217
|
+
const vLo = a[lo - 1] as number;
|
|
218
|
+
const vHi = a[hi - 1] as number;
|
|
219
|
+
return vLo + (vHi - vLo) * (t - lo);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** Retired copies (`<name>-retired-YYYY-MM-DD`) are versions of one job. */
|
|
223
|
+
export function jobKey(name: string): string {
|
|
224
|
+
return name.replace(/-retired-\d{4}-\d{2}-\d{2}$/, "");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Count of `await` in a script's source, as the ops a swarm-script node performs. */
|
|
228
|
+
export function scriptOpsFromAwaitCount(awaits: number): number {
|
|
229
|
+
return Math.min(MAX_SCRIPT_OPS, Number(awaits) || 0);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
type DefinitionNode = { id: string; type: string; config?: Record<string, unknown> };
|
|
233
|
+
|
|
234
|
+
/** Deterministic ops per node id. Agent-task, wait and control nodes count 0. */
|
|
235
|
+
export function nodeOpsOf(
|
|
236
|
+
definition: { nodes?: DefinitionNode[] } | null | undefined,
|
|
237
|
+
opsByScript: ReadonlyMap<string, number>,
|
|
238
|
+
): Map<string, number> {
|
|
239
|
+
const ops = new Map<string, number>();
|
|
240
|
+
for (const node of definition?.nodes ?? []) {
|
|
241
|
+
let o = 0;
|
|
242
|
+
if (node.type === "swarm-script") {
|
|
243
|
+
const name = node.config?.scriptName;
|
|
244
|
+
o = (typeof name === "string" ? opsByScript.get(name) : undefined) ?? DEFAULT_OPS;
|
|
245
|
+
} else if (node.type === "script") {
|
|
246
|
+
o = Math.max(1, (JSON.stringify(node.config ?? {}).match(/\bawait\b/g) ?? []).length);
|
|
247
|
+
} else if (
|
|
248
|
+
["system-one-decision", "system-one-extraction", "raw-llm", "notify", "code-match"].includes(
|
|
249
|
+
node.type,
|
|
250
|
+
)
|
|
251
|
+
) {
|
|
252
|
+
o = 1;
|
|
253
|
+
}
|
|
254
|
+
ops.set(node.id, o);
|
|
255
|
+
}
|
|
256
|
+
return ops;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Tier-independent facts about one workflow over a window. */
|
|
260
|
+
export type WorkflowFacts = {
|
|
261
|
+
/** Every run that started in the window. */
|
|
262
|
+
runs: number;
|
|
263
|
+
/** Runs that were not skipped or cancelled. */
|
|
264
|
+
countedRuns: number;
|
|
265
|
+
/** Counted runs started by a schedule. */
|
|
266
|
+
schedRuns: number;
|
|
267
|
+
/** Of `schedRuns`, the runs that created an agent task or started a child workflow. */
|
|
268
|
+
schedEffectRuns: number;
|
|
269
|
+
/** Runs started by an event trigger. */
|
|
270
|
+
eventRuns: number;
|
|
271
|
+
/** Runs of any trigger and status that created an agent task or started a child workflow. */
|
|
272
|
+
effectRuns: number;
|
|
273
|
+
/** Deterministic ops summed over the steps of the effect runs. */
|
|
274
|
+
effectOpsSum: number;
|
|
275
|
+
/** Deterministic ops summed over every step of every run. */
|
|
276
|
+
opsSum: number;
|
|
277
|
+
agentTasks: number;
|
|
278
|
+
/** Session cost of the agent tasks the runs created. */
|
|
279
|
+
agentUsd: number;
|
|
280
|
+
agentMs: number;
|
|
281
|
+
/** Lead follow-up review cost of those agent tasks. */
|
|
282
|
+
followupUsd: number;
|
|
283
|
+
/**
|
|
284
|
+
* Session cost of tasks the runs caused without owning them: descendants of
|
|
285
|
+
* the agent-task nodes' tasks, and tasks the script steps created with their
|
|
286
|
+
* descendants. Kept on both sides of the saving, like `agentUsd`.
|
|
287
|
+
*/
|
|
288
|
+
childTaskUsd: number;
|
|
289
|
+
childTaskMs: number;
|
|
290
|
+
/** LLM cost a run reported itself (report node). */
|
|
291
|
+
recordedLlmUsd: number;
|
|
292
|
+
/** LLM cost estimated from SystemOne tokens and raw-llm output size. */
|
|
293
|
+
estimatedLlmUsd: number;
|
|
294
|
+
/** Wall time of the deterministic steps. */
|
|
295
|
+
computeSecs: number;
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
export type PricedWorkflow = {
|
|
299
|
+
/** True when the enabled-only rule priced only the effect runs. */
|
|
300
|
+
enabledOnlyRule: boolean;
|
|
301
|
+
runs: number;
|
|
302
|
+
substitutedRuns: number;
|
|
303
|
+
/** Schedule runs above the hourly cap that still count because they had an effect. */
|
|
304
|
+
effectRuns: number;
|
|
305
|
+
enabledOnlyRuns: number;
|
|
306
|
+
capApplied: boolean;
|
|
307
|
+
opsPerRun: number;
|
|
308
|
+
/** Measured spend of every run in the window: agent tasks, their reviews, recorded LLM cost. */
|
|
309
|
+
measuredUsd: number;
|
|
310
|
+
/**
|
|
311
|
+
* LLM spend estimated from tokens and output size, not measured. Zero when the
|
|
312
|
+
* runs recorded their LLM cost, which then counts in `measuredUsd` instead.
|
|
313
|
+
*/
|
|
314
|
+
estimatedLlmUsd: number;
|
|
315
|
+
/**
|
|
316
|
+
* Scaled estimate, not a measurement:
|
|
317
|
+
* `(measuredUsd + estimatedLlmUsd) * substitutedRuns / runs`.
|
|
318
|
+
* The estimator's actual side; it assumes spend is spread evenly over runs.
|
|
319
|
+
*/
|
|
320
|
+
actualUsd: number;
|
|
321
|
+
agentOnlyUsd: SavingsBand;
|
|
322
|
+
savingUsd: SavingsBand;
|
|
323
|
+
/** Scaled estimate like `actualUsd`: measured hours times the substituted share. */
|
|
324
|
+
actualHours: number;
|
|
325
|
+
agentOnlyHours: SavingsBand;
|
|
326
|
+
hoursSaved: SavingsBand;
|
|
327
|
+
/** What one substituted run would cost an agent at p50 (R * curve + review). */
|
|
328
|
+
agentOnlyUsdPerRun: number;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/** Agent spend the runs caused: kept on both sides of the saving. */
|
|
332
|
+
const keptSpendOf = (f: WorkflowFacts): number => f.agentUsd + f.followupUsd + f.childTaskUsd;
|
|
333
|
+
const keptHoursOf = (f: WorkflowFacts): number => (f.agentMs + f.childTaskMs) / 3.6e6;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Split spend into measured and estimated. The window picks the LLM source
|
|
337
|
+
* (`useRecorded`): when any run recorded its LLM cost, no day adds an estimate.
|
|
338
|
+
*/
|
|
339
|
+
function spendOf(
|
|
340
|
+
facts: WorkflowFacts,
|
|
341
|
+
useRecorded: boolean,
|
|
342
|
+
): { measuredUsd: number; estimatedLlmUsd: number } {
|
|
343
|
+
return {
|
|
344
|
+
measuredUsd: keptSpendOf(facts) + (useRecorded ? facts.recordedLlmUsd : 0),
|
|
345
|
+
estimatedLlmUsd: useRecorded ? 0 : facts.estimatedLlmUsd,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const bandOf = (fn: (q: Quantile) => number): SavingsBand => ({
|
|
350
|
+
p10: fn("p10"),
|
|
351
|
+
p50: fn("p50"),
|
|
352
|
+
p90: fn("p90"),
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
/** Schedule runs one version of a job substitutes, and how many of them fit under the cap. */
|
|
356
|
+
export type ScheduleAllocation = { vSched: number; vCap: number };
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Share the hourly cap across the versions of one job (`jobKey`), in order.
|
|
360
|
+
* A run with a downstream effect always counts, so the job total is
|
|
361
|
+
* max(min(all schedule runs, cap), all effect runs). Same arithmetic as v7.
|
|
362
|
+
*/
|
|
363
|
+
export function allocateSchedule(
|
|
364
|
+
versions: readonly Pick<WorkflowFacts, "schedRuns" | "schedEffectRuns">[],
|
|
365
|
+
days: number,
|
|
366
|
+
): ScheduleAllocation[] {
|
|
367
|
+
const cap = CAP_PER_DAY * days;
|
|
368
|
+
let used = 0;
|
|
369
|
+
let eff = 0;
|
|
370
|
+
return versions.map((v) => {
|
|
371
|
+
const vCap = Math.min(v.schedRuns, Math.max(0, cap - used));
|
|
372
|
+
const vSched = Math.max(Math.min(used + v.schedRuns, cap), eff + v.schedEffectRuns) - used;
|
|
373
|
+
used += vSched;
|
|
374
|
+
eff += v.schedEffectRuns;
|
|
375
|
+
return { vSched, vCap };
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** The enabled-only rule (see ROUTER_MIN_RUNS_PER_DAY). */
|
|
380
|
+
export function isEnabledOnlyRouter(facts: WorkflowFacts, days: number): boolean {
|
|
381
|
+
return (
|
|
382
|
+
facts.runs > ROUTER_MIN_RUNS_PER_DAY * days &&
|
|
383
|
+
facts.effectRuns < ROUTER_MAX_EFFECT_SHARE * facts.runs &&
|
|
384
|
+
facts.eventRuns >= ROUTER_MIN_EVENT_SHARE * facts.runs
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** A router run with an effect is one agent decision at the run's own ops; the job it starts is priced on its own row. */
|
|
389
|
+
function priceRouter(
|
|
390
|
+
facts: WorkflowFacts,
|
|
391
|
+
opts: { tier: SavingsTier; band: "job" | "fleet"; curve?: CurveSet },
|
|
392
|
+
): PricedWorkflow {
|
|
393
|
+
const v = facts.effectRuns;
|
|
394
|
+
const opsPerRun = v > 0 ? facts.effectOpsSum / v : 0;
|
|
395
|
+
const tau = Math.min(TAU_MAX, T0 + K * opsPerRun);
|
|
396
|
+
const unitUsd = v > 0 ? curve(tau, opts.tier, "usd", opts.curve) : 0;
|
|
397
|
+
const unitHrs = v > 0 ? curve(tau, opts.tier, "hrs", opts.curve) : 0;
|
|
398
|
+
const review = unitUsd > 0 ? F_FOLLOWUP : 0;
|
|
399
|
+
const err = opts.band === "job" ? ERR_JOB : ERR_FLEET;
|
|
400
|
+
const agentOnlyUsd = bandOf((q) => v * (R[q] * unitUsd * err[q] + review));
|
|
401
|
+
const agentOnlyHours = bandOf((q) => v * R[q] * unitHrs * err[q]);
|
|
402
|
+
return {
|
|
403
|
+
enabledOnlyRule: true,
|
|
404
|
+
runs: facts.runs,
|
|
405
|
+
substitutedRuns: v,
|
|
406
|
+
effectRuns: v,
|
|
407
|
+
enabledOnlyRuns: facts.runs - v,
|
|
408
|
+
capApplied: false,
|
|
409
|
+
opsPerRun,
|
|
410
|
+
// Measured spend is reported; the rule subtracts nothing (v7: the jobs
|
|
411
|
+
// the router starts are priced, with their spend, on their own rows).
|
|
412
|
+
...spendOf(facts, facts.recordedLlmUsd > 0),
|
|
413
|
+
actualUsd: 0,
|
|
414
|
+
agentOnlyUsd,
|
|
415
|
+
savingUsd: agentOnlyUsd,
|
|
416
|
+
actualHours: 0,
|
|
417
|
+
agentOnlyHours,
|
|
418
|
+
hoursSaved: agentOnlyHours,
|
|
419
|
+
agentOnlyUsdPerRun: R.p50 * unitUsd + review,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Price one workflow's facts at a tier. `band` picks the error spread: `job`
|
|
425
|
+
* for a single job, `fleet` for a sum over many jobs. `allocation` carries the
|
|
426
|
+
* cap shared with the job's other versions (`allocateSchedule`); without it the
|
|
427
|
+
* workflow is the job's only version. `curve` overrides the shipped
|
|
428
|
+
* session-cost curve with a deployment calibration.
|
|
429
|
+
*/
|
|
430
|
+
export function priceWorkflow(
|
|
431
|
+
facts: WorkflowFacts,
|
|
432
|
+
opts: { tier: SavingsTier; days: number; band: "job" | "fleet"; curve?: CurveSet },
|
|
433
|
+
allocation?: ScheduleAllocation,
|
|
434
|
+
): PricedWorkflow {
|
|
435
|
+
if (isEnabledOnlyRouter(facts, opts.days)) return priceRouter(facts, opts);
|
|
436
|
+
const runs = facts.runs;
|
|
437
|
+
// Schedule runs: at most the hourly cap, but a run with a downstream effect always counts.
|
|
438
|
+
const { vSched, vCap } =
|
|
439
|
+
allocation ?? (allocateSchedule([facts], opts.days)[0] as ScheduleAllocation);
|
|
440
|
+
const substituted = vSched + (facts.countedRuns - facts.schedRuns);
|
|
441
|
+
const opsPerRun = runs > 0 ? facts.opsSum / runs : 0;
|
|
442
|
+
const tau = Math.min(TAU_MAX, T0 + K * opsPerRun);
|
|
443
|
+
// A pure agent dispatcher (no deterministic ops) substitutes nothing.
|
|
444
|
+
const orchestrates = !(opsPerRun < 1 && facts.agentTasks > 0);
|
|
445
|
+
const unitUsd = orchestrates ? curve(tau, opts.tier, "usd", opts.curve) : 0;
|
|
446
|
+
const unitHrs = orchestrates ? curve(tau, opts.tier, "hrs", opts.curve) : 0;
|
|
447
|
+
const review = unitUsd > 0 ? F_FOLLOWUP : 0;
|
|
448
|
+
const share = runs > 0 ? substituted / runs : 0;
|
|
449
|
+
const { measuredUsd, estimatedLlmUsd } = spendOf(facts, facts.recordedLlmUsd > 0);
|
|
450
|
+
const keptUsd = keptSpendOf(facts) * share;
|
|
451
|
+
const keptHours = keptHoursOf(facts) * share;
|
|
452
|
+
const actualUsd = (measuredUsd + estimatedLlmUsd) * share;
|
|
453
|
+
const actualHours = (keptHoursOf(facts) + facts.computeSecs / 3600) * share;
|
|
454
|
+
const err = opts.band === "job" ? ERR_JOB : ERR_FLEET;
|
|
455
|
+
const agentOnlyUsd = bandOf((q) => keptUsd + substituted * (R[q] * unitUsd * err[q] + review));
|
|
456
|
+
const agentOnlyHours = bandOf((q) => keptHours + substituted * R[q] * unitHrs * err[q]);
|
|
457
|
+
return {
|
|
458
|
+
enabledOnlyRule: false,
|
|
459
|
+
runs,
|
|
460
|
+
substitutedRuns: substituted,
|
|
461
|
+
effectRuns: vSched - vCap,
|
|
462
|
+
enabledOnlyRuns: runs - substituted,
|
|
463
|
+
capApplied: vCap < facts.schedRuns,
|
|
464
|
+
opsPerRun,
|
|
465
|
+
measuredUsd,
|
|
466
|
+
estimatedLlmUsd,
|
|
467
|
+
actualUsd,
|
|
468
|
+
agentOnlyUsd,
|
|
469
|
+
savingUsd: bandOf((q) => agentOnlyUsd[q] - actualUsd),
|
|
470
|
+
actualHours,
|
|
471
|
+
agentOnlyHours,
|
|
472
|
+
hoursSaved: bandOf((q) => agentOnlyHours[q] - actualHours),
|
|
473
|
+
agentOnlyUsdPerRun: R.p50 * unitUsd + review,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Split a window's p50 saving, scaled actual cost, measured spend and
|
|
479
|
+
* estimated LLM spend across the UTC days its runs started on, so the days
|
|
480
|
+
* sum to `priceWorkflow` over the window. The unit
|
|
481
|
+
* cost (tau), the substituted share and the LLM source are the window's.
|
|
482
|
+
* When the hourly cap or the effect rule makes the window's counted schedule
|
|
483
|
+
* runs differ from the raw ones, they are spread pro rata over the days'
|
|
484
|
+
* schedule runs. A workflow priced by the enabled-only rule splits by its
|
|
485
|
+
* days' effect runs.
|
|
486
|
+
*/
|
|
487
|
+
export function splitByDay(
|
|
488
|
+
facts: WorkflowFacts,
|
|
489
|
+
byDay: readonly (WorkflowFacts & { day: string })[],
|
|
490
|
+
opts: { tier: SavingsTier; days: number; curve?: CurveSet },
|
|
491
|
+
/** The window's pricing when it is already known (a cap shared with other versions). */
|
|
492
|
+
pricedWindow?: PricedWorkflow,
|
|
493
|
+
): {
|
|
494
|
+
day: string;
|
|
495
|
+
savingUsd: number;
|
|
496
|
+
actualUsd: number;
|
|
497
|
+
measuredUsd: number;
|
|
498
|
+
estimatedLlmUsd: number;
|
|
499
|
+
}[] {
|
|
500
|
+
const priced = pricedWindow ?? priceWorkflow(facts, { ...opts, band: "job" });
|
|
501
|
+
const useRecorded = facts.recordedLlmUsd > 0;
|
|
502
|
+
// Enabled-only rule: each effect run is one decision at the window's unit cost.
|
|
503
|
+
if (priced.enabledOnlyRule) {
|
|
504
|
+
return byDay.map((d) => ({
|
|
505
|
+
day: d.day,
|
|
506
|
+
savingUsd: d.effectRuns * priced.agentOnlyUsdPerRun,
|
|
507
|
+
actualUsd: 0,
|
|
508
|
+
...spendOf(d, useRecorded),
|
|
509
|
+
}));
|
|
510
|
+
}
|
|
511
|
+
const runs = facts.runs;
|
|
512
|
+
const share = runs > 0 ? priced.substitutedRuns / runs : 0;
|
|
513
|
+
const nonSched = facts.countedRuns - facts.schedRuns;
|
|
514
|
+
const vSched = priced.substitutedRuns - nonSched;
|
|
515
|
+
// p50 agent-only cost of one substituted run (ERR_JOB.p50 is 1). The sum test pins this.
|
|
516
|
+
const unitUsd = priced.agentOnlyUsdPerRun;
|
|
517
|
+
return byDay.map((d) => {
|
|
518
|
+
const substituted =
|
|
519
|
+
(facts.schedRuns > 0 ? (vSched * d.schedRuns) / facts.schedRuns : 0) +
|
|
520
|
+
(d.countedRuns - d.schedRuns);
|
|
521
|
+
const { measuredUsd, estimatedLlmUsd } = spendOf(d, useRecorded);
|
|
522
|
+
const keptUsd = keptSpendOf(d) * share;
|
|
523
|
+
const actualUsd = (measuredUsd + estimatedLlmUsd) * share;
|
|
524
|
+
return {
|
|
525
|
+
day: d.day,
|
|
526
|
+
savingUsd: keptUsd + substituted * unitUsd - actualUsd,
|
|
527
|
+
actualUsd,
|
|
528
|
+
measuredUsd,
|
|
529
|
+
estimatedLlmUsd,
|
|
530
|
+
};
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Tier-independent facts about one script (by name) over a window. */
|
|
535
|
+
export type ScriptFacts = {
|
|
536
|
+
/** Every run that started in the window. */
|
|
537
|
+
runs: number;
|
|
538
|
+
/** Runs started through an API endpoint: enabled-only unless they had an effect. */
|
|
539
|
+
apiRuns: number;
|
|
540
|
+
/** Non-API runs whose output names an agent task created while they ran. */
|
|
541
|
+
effectRuns: number;
|
|
542
|
+
/** API runs with such an effect. */
|
|
543
|
+
apiEffectRuns: number;
|
|
544
|
+
/** Ops summed over every run (ops per run times runs). */
|
|
545
|
+
opsSum: number;
|
|
546
|
+
/** Wall time of the runs. */
|
|
547
|
+
computeSecs: number;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
export type ScriptKind = "script-scheduled" | "script-agent-invoked";
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Price one script's facts at a tier, as v7 `scriptJobs` does. A scheduled
|
|
554
|
+
* script (a schedule targets it) is a standalone agent task with a lead
|
|
555
|
+
* review; any other script is priced as the extra turns it would add to the
|
|
556
|
+
* calling agent's session (no bootstrap, no review). Non-API runs count at
|
|
557
|
+
* most 24 a day, unless they had a downstream effect. An API run counts only
|
|
558
|
+
* when it had an effect, then as a standalone decision with a review.
|
|
559
|
+
* Scripts record no LLM spend and keep no agent active, so their actual
|
|
560
|
+
* cost and agent-hours are 0.
|
|
561
|
+
*/
|
|
562
|
+
export function priceScript(
|
|
563
|
+
facts: ScriptFacts,
|
|
564
|
+
opts: {
|
|
565
|
+
tier: SavingsTier;
|
|
566
|
+
days: number;
|
|
567
|
+
band: "job" | "fleet";
|
|
568
|
+
kind: ScriptKind;
|
|
569
|
+
curve?: CurveSet;
|
|
570
|
+
},
|
|
571
|
+
): PricedWorkflow {
|
|
572
|
+
const runs = facts.runs;
|
|
573
|
+
const nonApi = runs - facts.apiRuns;
|
|
574
|
+
const vCap = Math.min(nonApi, CAP_PER_DAY * opts.days);
|
|
575
|
+
const v = Math.max(vCap, Math.min(nonApi, facts.effectRuns));
|
|
576
|
+
const apiV = facts.apiEffectRuns;
|
|
577
|
+
const opsPerRun = runs > 0 ? facts.opsSum / runs : 0;
|
|
578
|
+
const tau = Math.min(TAU_MAX, T0 + K * opsPerRun);
|
|
579
|
+
const fullUsd = curve(tau, opts.tier, "usd", opts.curve);
|
|
580
|
+
const fullHrs = curve(tau, opts.tier, "hrs", opts.curve);
|
|
581
|
+
const scheduled = opts.kind === "script-scheduled";
|
|
582
|
+
const unitUsd = scheduled
|
|
583
|
+
? fullUsd
|
|
584
|
+
: Math.max(0, fullUsd - curve(T0, opts.tier, "usd", opts.curve));
|
|
585
|
+
const unitHrs = scheduled
|
|
586
|
+
? fullHrs
|
|
587
|
+
: Math.max(0, fullHrs - curve(T0, opts.tier, "hrs", opts.curve));
|
|
588
|
+
const review = scheduled ? F_FOLLOWUP : 0;
|
|
589
|
+
const err = opts.band === "job" ? ERR_JOB : ERR_FLEET;
|
|
590
|
+
const agentOnlyUsd = bandOf(
|
|
591
|
+
(q) => v * (R[q] * unitUsd * err[q] + review) + apiV * (R[q] * fullUsd * err[q] + F_FOLLOWUP),
|
|
592
|
+
);
|
|
593
|
+
const agentOnlyHours = bandOf(
|
|
594
|
+
(q) => v * R[q] * unitHrs * err[q] + apiV * R[q] * fullHrs * err[q],
|
|
595
|
+
);
|
|
596
|
+
// A script run keeps no agent active: scheduled and API runs have no agent,
|
|
597
|
+
// and an agent-invoked run's wait is already inside the turns `unitHrs`
|
|
598
|
+
// removes. v7 subtracted the runs' wall time, which made short runs negative.
|
|
599
|
+
const actualHours = 0;
|
|
600
|
+
return {
|
|
601
|
+
enabledOnlyRule: false,
|
|
602
|
+
runs,
|
|
603
|
+
substitutedRuns: v + apiV,
|
|
604
|
+
effectRuns: v - vCap + apiV,
|
|
605
|
+
enabledOnlyRuns: runs - v - apiV,
|
|
606
|
+
capApplied: vCap < nonApi,
|
|
607
|
+
opsPerRun,
|
|
608
|
+
measuredUsd: 0,
|
|
609
|
+
estimatedLlmUsd: 0,
|
|
610
|
+
actualUsd: 0,
|
|
611
|
+
agentOnlyUsd,
|
|
612
|
+
savingUsd: agentOnlyUsd,
|
|
613
|
+
actualHours,
|
|
614
|
+
agentOnlyHours,
|
|
615
|
+
hoursSaved: bandOf((q) => agentOnlyHours[q] - actualHours),
|
|
616
|
+
agentOnlyUsdPerRun: R.p50 * unitUsd + review,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Split a script's window p50 saving across the UTC days its runs started
|
|
622
|
+
* on, so the days sum to `priceScript` over the window. Counted non-API runs
|
|
623
|
+
* are spread pro rata over the days' non-API runs; API effect runs count on
|
|
624
|
+
* their own day.
|
|
625
|
+
*/
|
|
626
|
+
export function splitScriptByDay(
|
|
627
|
+
facts: ScriptFacts,
|
|
628
|
+
byDay: readonly (ScriptFacts & { day: string })[],
|
|
629
|
+
priced: PricedWorkflow,
|
|
630
|
+
): {
|
|
631
|
+
day: string;
|
|
632
|
+
savingUsd: number;
|
|
633
|
+
actualUsd: number;
|
|
634
|
+
measuredUsd: number;
|
|
635
|
+
estimatedLlmUsd: number;
|
|
636
|
+
}[] {
|
|
637
|
+
const nonApi = facts.runs - facts.apiRuns;
|
|
638
|
+
const v = priced.substitutedRuns - facts.apiEffectRuns;
|
|
639
|
+
const apiUnit =
|
|
640
|
+
facts.apiEffectRuns > 0
|
|
641
|
+
? (priced.agentOnlyUsd.p50 - v * priced.agentOnlyUsdPerRun) / facts.apiEffectRuns
|
|
642
|
+
: 0;
|
|
643
|
+
return byDay.map((d) => ({
|
|
644
|
+
day: d.day,
|
|
645
|
+
savingUsd:
|
|
646
|
+
(nonApi > 0 ? (v * (d.runs - d.apiRuns)) / nonApi : 0) * priced.agentOnlyUsdPerRun +
|
|
647
|
+
d.apiEffectRuns * apiUnit,
|
|
648
|
+
actualUsd: 0,
|
|
649
|
+
measuredUsd: 0,
|
|
650
|
+
estimatedLlmUsd: 0,
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const TIER_MODEL: Record<SavingsTier, string> = {
|
|
655
|
+
smol: "haiku-5-5",
|
|
656
|
+
regular: "sonnet-5-5",
|
|
657
|
+
smart: "opus-5-5",
|
|
658
|
+
ultra: "fable-5-1",
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
/** The model's assumptions in words, from the v7 estimator, with this port's constants. */
|
|
662
|
+
export function savingsAssumptions(tier: SavingsTier): string[] {
|
|
663
|
+
return [
|
|
664
|
+
`Tier ${tier} prices sessions at ${TIER_MODEL[tier]} on the fleet's measured session token profile (${CALIBRATION_MODEL}, calibrated ${CALIBRATED_AT}).`,
|
|
665
|
+
`Agent turns per deterministic op K=${K}, bootstrap T0=${T0} turns, session length capped at ${TAU_MAX} turns (fleet p95).`,
|
|
666
|
+
`Schedule-triggered runs count at most ${CAP_PER_DAY} a day per job (an agent would not poll faster than hourly) unless they caused a downstream effect; event and manual runs count 1:1; skipped and cancelled runs are excluded.`,
|
|
667
|
+
`Event routers (over ${ROUTER_MIN_RUNS_PER_DAY} event runs a day, under ${ROUTER_MAX_EFFECT_SHARE * 100}% with an effect) and API-invoked script runs are enabled-only: an effect run counts as one agent decision, never as the job it starts, which is priced on its own row.`,
|
|
668
|
+
"Effect links: a workflow run created an agent task (agent_tasks.workflowRunId) or started a child workflow run (workflow_runs.parentStepId); a script run wrote the id of an agent task created during the run into its output.",
|
|
669
|
+
`Failure and retry multiplier R=${R.p50} (p10 ${R.p10}, p90 ${R.p90}) from scheduled agent tasks; lead follow-up review $${F_FOLLOWUP} per standalone agent task.`,
|
|
670
|
+
"Scripts no schedule targets are priced as the extra turns they add to the calling agent's session (no bootstrap, no review).",
|
|
671
|
+
"Agent-task nodes inside workflows count at their actual cost on both sides; only the deterministic glue is substituted.",
|
|
672
|
+
"Scripts record no LLM spend, so their actual cost counts as $0; LLM calls made inside scripts are not counted.",
|
|
673
|
+
];
|
|
674
|
+
}
|