@desplega.ai/agent-swarm 2.9.0 → 2.10.0

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.
Files changed (453) hide show
  1. package/dist/acp-adapter-bht22g3k.js +16 -0
  2. package/dist/{acp-targets-swxq55dr.js → acp-targets-arrwv4f0.js} +7 -7
  3. package/dist/{actions-pb678g3e.js → actions-y0d2n1c2.js} +102 -21
  4. package/dist/{agent-fs-provision-dmhnc38q.js → agent-fs-provision-tpj7sktd.js} +4 -4
  5. package/dist/{amp-adapter-3pa66q27.js → amp-adapter-vmmnmw8d.js} +2 -2
  6. package/dist/{anthropic-messages-x2cp5fvf.js → anthropic-messages-zdca3gv1.js} +22 -22
  7. package/dist/{app-17d12ev4.js → app-wb7w45dq.js} +6 -3
  8. package/dist/{approval-notifications-h7vd9pmg.js → approval-notifications-7mqr6vbd.js} +8 -5
  9. package/dist/{assistant-t7k39ree.js → assistant-gf60454p.js} +23 -21
  10. package/dist/{boot-args-schema-0gqmkfbe.js → boot-args-schema-qxmd59sr.js} +1 -1
  11. package/dist/{boot-reembed-f064w382.js → boot-reembed-5tmeskj2.js} +1 -1
  12. package/dist/{boot-reembed-n6anc01d.js → boot-reembed-wb44vc3s.js} +1 -1
  13. package/dist/boot-scrub-sweep-25bxhnw4.js +9 -0
  14. package/dist/{boot-seeds-f99fjs5q.js → boot-seeds-nj9za0vk.js} +4 -4
  15. package/dist/{claude-adapter-gvznwxgc.js → claude-adapter-d3krpdyb.js} +7 -7
  16. package/dist/{claude-managed-adapter-pbrbvc64.js → claude-managed-adapter-t8nfgcgz.js} +2 -2
  17. package/dist/{claude-managed-setup-kdxttvc3.js → claude-managed-setup-7y4pwd81.js} +3 -3
  18. package/dist/{claude-sdk-session-0t2teq6n.js → claude-sdk-session-d138zy0e.js} +7 -7
  19. package/dist/{cli-6dp0jkfj.js → cli-01k6wpr9.js} +4 -4
  20. package/dist/{cli-c07v0qfa.js → cli-124ntmf0.js} +83 -74
  21. package/dist/{cli-1tvdx9t5.js → cli-2rnd5j3t.js} +1 -1
  22. package/dist/{cli-4ghh072d.js → cli-2spnz7ye.js} +36 -36
  23. package/dist/{cli-dd37e0cm.js → cli-2v2zdm0a.js} +1 -1
  24. package/dist/{cli-aa8s22gn.js → cli-3aaeb78m.js} +195 -186
  25. package/dist/{cli-8x8y70av.js → cli-3caf7pmg.js} +2 -2
  26. package/dist/{cli-jd3kxppb.js → cli-3et6fmfe.js} +1 -1
  27. package/dist/{cli-kaa4bd7x.js → cli-3f8zbtqa.js} +9 -8
  28. package/dist/{cli-57pvhnyt.js → cli-43evxwj4.js} +1 -1
  29. package/dist/cli-43ms35q9.js +270 -0
  30. package/dist/cli-47hz21se.js +25584 -0
  31. package/dist/{cli-n515ex5z.js → cli-4ymxrwg5.js} +16 -16
  32. package/dist/{cli-2tnbc3gw.js → cli-539h29es.js} +2379 -66
  33. package/dist/{cli-rts1qvb4.js → cli-5qhfv9rw.js} +2 -2
  34. package/dist/{cli-faf46gdq.js → cli-6037prsx.js} +10 -10
  35. package/dist/{cli-bk9v1xrv.js → cli-6cwr32fe.js} +25 -25
  36. package/dist/{cli-812paz57.js → cli-6ehs4mta.js} +18 -2
  37. package/dist/{cli-95930z69.js → cli-6ym4jhzp.js} +2 -2
  38. package/dist/{cli-zg3z63x3.js → cli-7mv4h3sn.js} +1 -1
  39. package/dist/{cli-9a2rtd77.js → cli-7r162fxe.js} +24 -15
  40. package/dist/{cli-eg437b5p.js → cli-7sf9sb0w.js} +2 -1
  41. package/dist/{cli-vw5x18yj.js → cli-8st34zhr.js} +20 -10
  42. package/dist/{cli-fgphc007.js → cli-91pkxres.js} +1 -1
  43. package/dist/{cli-2kg31ted.js → cli-9fjr27ez.js} +11 -11
  44. package/dist/{cli-wr1h0k28.js → cli-9w8712tq.js} +617 -278
  45. package/dist/cli-aw83sr40.js +98 -0
  46. package/dist/{cli-ssvdrk4y.js → cli-b6px1k1q.js} +1 -1
  47. package/dist/{cli-w7dxb2fj.js → cli-cc93xzes.js} +6 -6
  48. package/dist/{cli-js8zrfyg.js → cli-fcfbct2j.js} +5 -5
  49. package/dist/{cli-3zxdz9r7.js → cli-fq2rr3jb.js} +6 -6
  50. package/dist/{boot-scrub-sweep-ejd5dnrz.js → cli-had1p04a.js} +8 -9
  51. package/dist/{cli-7cgf614g.js → cli-j6te8keb.js} +5 -5
  52. package/dist/{cli-25nstr34.js → cli-jrbq4djp.js} +1 -1
  53. package/dist/{cli-pz1c00aa.js → cli-k3q2va86.js} +2 -2
  54. package/dist/{cli-nhq5js1b.js → cli-k5yewqgd.js} +3 -3
  55. package/dist/cli-kbtzfrxj.js +404 -0
  56. package/dist/{cli-dx439zpg.js → cli-kpgcm7xy.js} +13 -1
  57. package/dist/{cli-mc1fx4xd.js → cli-m9cvf7vs.js} +10 -10
  58. package/dist/{cli-kmvcm34h.js → cli-md50mj0r.js} +2 -2
  59. package/dist/{cli-q8cfh1t9.js → cli-mk7c5ac4.js} +1 -1
  60. package/dist/cli-mys27d03.js +321 -0
  61. package/dist/{cli-spzkdgtg.js → cli-n3qe7tyr.js} +172 -168
  62. package/dist/{cli-7akn6ze9.js → cli-nh7x3133.js} +7 -28
  63. package/dist/{cli-fnh4b12r.js → cli-nstkanmx.js} +6 -6
  64. package/dist/{cli-g3zzby8t.js → cli-nv4xsvmk.js} +5 -5
  65. package/dist/{cli-sn4pc4qx.js → cli-p0c3vtch.js} +2 -2
  66. package/dist/{cli-5ntc4we6.js → cli-p0n7b5rz.js} +859 -2058
  67. package/dist/{cli-pn1v1pb0.js → cli-psffsanb.js} +3 -2
  68. package/dist/{cli-svc803vq.js → cli-q5srsxq2.js} +15 -15
  69. package/dist/{cli-nmcpzbty.js → cli-qrta34nb.js} +4 -4
  70. package/dist/{cli-k09cxm6m.js → cli-qx4f057j.js} +2 -2
  71. package/dist/{cli-eepnpee7.js → cli-s1khw52h.js} +12 -12
  72. package/dist/{cli-h474mvp5.js → cli-s1zqk1aj.js} +21 -11
  73. package/dist/{cli-8axx8vnw.js → cli-sb4426be.js} +10 -10
  74. package/dist/{cli-kqh27v2y.js → cli-th1dkc2v.js} +1 -1
  75. package/dist/{cli-cw7mc1je.js → cli-tr27kwyg.js} +3 -3
  76. package/dist/{cli-5kcmxwxv.js → cli-tvgqesec.js} +7 -5
  77. package/dist/{cli-a9hfzg2r.js → cli-ty3gha1p.js} +6 -6
  78. package/dist/{cli-fjggej24.js → cli-v46zsvqk.js} +1 -1
  79. package/dist/{cli-5gygrr67.js → cli-v8z0yga9.js} +4 -4
  80. package/dist/{cli-k7pt28ad.js → cli-vfqvrd82.js} +5 -5
  81. package/dist/{cli-vvgaz8t6.js → cli-vq2eg24x.js} +2 -2
  82. package/dist/{cli-pwsax0vp.js → cli-vsw91x06.js} +23 -22
  83. package/dist/{cli-7fx9jyfs.js → cli-w1q68d8x.js} +67 -11
  84. package/dist/{cli-c5cspahx.js → cli-wafmk3fn.js} +45 -20
  85. package/dist/{cli-ymct0ycy.js → cli-wwp1bd3n.js} +5495 -5095
  86. package/dist/{cli-me4maa4j.js → cli-y4ccxtz5.js} +45 -9
  87. package/dist/{cli-m1fbz2wj.js → cli-y8p78ekx.js} +178 -19
  88. package/dist/{cli-nr46j5pw.js → cli-z0m452jr.js} +1 -1
  89. package/dist/{cli-gddgcnav.js → cli-zeh2mhkg.js} +1 -1
  90. package/dist/{cli-e9973bf0.js → cli-zk7v5s89.js} +2 -2
  91. package/dist/cli.js +24 -23
  92. package/dist/{cloudflare-workers-ai-system-one-9y1zx3pt.js → cloudflare-workers-ai-system-one-4aysy6rh.js} +2 -2
  93. package/dist/{codex-adapter-44yq2fkn.js → codex-adapter-exfdbj73.js} +6 -6
  94. package/dist/{codex-hook-h1zb7cfk.js → codex-hook-59atdwd8.js} +1 -1
  95. package/dist/{codex-login-cdyrr5y1.js → codex-login-a239g1ah.js} +1 -1
  96. package/dist/{codex-session-runner-zbh26gbw.js → codex-session-runner-xhznc4g3.js} +6 -6
  97. package/dist/{commands-54f02v5b.js → commands-d8g349v4.js} +3 -3
  98. package/dist/{controller-9gpwcdek.js → controller-mwgdmb8y.js} +6 -3
  99. package/dist/{controllers-connect-61re6k1n.js → controllers-connect-5v7qx04j.js} +22 -20
  100. package/dist/core-sxy4epp2.js +38 -0
  101. package/dist/{cursor-adapter-7e4g81vd.js → cursor-adapter-p2q5h35d.js} +1 -1
  102. package/dist/{db-wnh0qjy1.js → db-qpganbeb.js} +3 -3
  103. package/dist/{db-dg2gc7fd.js → db-wcw0b2j8.js} +8 -2
  104. package/dist/{dispatcher-jrm24r43.js → dispatcher-8d8s49yz.js} +20 -18
  105. package/dist/{docker-9aq30pp2.js → docker-09tkkg0n.js} +42 -3
  106. package/dist/{dsh-adapter-1yqk267c.js → dsh-adapter-me0twn13.js} +1 -1
  107. package/dist/{easter-egg-3d-r4h9cs9m.js → easter-egg-3d-wv7w5ty6.js} +1 -1
  108. package/dist/{embedding-space-bafjr5f7.js → embedding-space-e48xchqa.js} +6 -6
  109. package/dist/{embeddings-7xmgqe0e.js → embeddings-tgq2afbq.js} +1 -1
  110. package/dist/{execute-d6jg5ns0.js → execute-8rhwrk7f.js} +1 -1
  111. package/dist/{external-channel-frq1xvq2.js → external-channel-8bt3j2pm.js} +2 -2
  112. package/dist/fx-adapter-adtdb3jb.js +19 -0
  113. package/dist/{google-generative-ai-hh7strj3.js → google-generative-ai-bh0djqjp.js} +5 -5
  114. package/dist/{google-vertex-fy5bw2pm.js → google-vertex-prjbw8dj.js} +9 -9
  115. package/dist/grok-adapter-accnn9km.js +19 -0
  116. package/dist/handlers-1x77561e.js +35 -0
  117. package/dist/{heartbeat-6bpa611t.js → heartbeat-x0056ra5.js} +23 -21
  118. package/dist/{hook-hvm5nf46.js → hook-a7vmn2st.js} +5 -5
  119. package/dist/{hook-w12k146y.js → hook-mrd2ayxv.js} +6 -6
  120. package/dist/{http-43tthdvs.js → http-ym9c5svp.js} +1335 -363
  121. package/dist/{index-fn054vsf.js → index-01ns1pkw.js} +1 -1
  122. package/dist/{index-1f0vypbg.js → index-0h6qd4p1.js} +34 -24
  123. package/dist/index-48qzcqzj.js +35 -0
  124. package/dist/{index-4b1q8kan.js → index-4k7m5dgj.js} +629 -354
  125. package/dist/index-620y7jzq.js +15 -0
  126. package/dist/{index-cret47a5.js → index-8p0j4h4j.js} +506 -43
  127. package/dist/{index-m5gx1xd6.js → index-9myfj74s.js} +40 -40
  128. package/dist/{index-bs7gw5fd.js → index-b5wgnm78.js} +44 -44
  129. package/dist/{index-ftywhyr0.js → index-ny60jcat.js} +394 -66
  130. package/dist/{index-tx9mc2ap.js → index-p46tvwtx.js} +24 -22
  131. package/dist/{index-585gyczt.js → index-pe3d8jfy.js} +3 -3
  132. package/dist/index-rkvaambe.js +36 -0
  133. package/dist/{index-mhq4sh5w.js → index-x6azjwm8.js} +1 -1
  134. package/dist/index-xj1mq27m.js +40 -0
  135. package/dist/k8s-m56sw868.js +217 -0
  136. package/dist/{keepalive-rk0j0jvh.js → keepalive-7yxg8z4c.js} +3 -3
  137. package/dist/lead-enzn86bz.js +74 -0
  138. package/dist/{maintenance-g6z6kaxw.js → maintenance-6tefxmk1.js} +1 -1
  139. package/dist/{node-jftbyawr.js → node-2wfcey7d.js} +1 -1
  140. package/dist/{oauth-refresh-sweep-2k3g2q4w.js → oauth-refresh-sweep-70cavc3a.js} +2 -2
  141. package/dist/{onboard-6fdbvh3v.js → onboard-fja65z08.js} +5 -5
  142. package/dist/{openai-decisions-q3hh60wr.js → openai-decisions-ytp6w6xh.js} +1 -1
  143. package/dist/{opencode-adapter-fdbsvts7.js → opencode-adapter-hakkm7yh.js} +6 -6
  144. package/dist/{otel-impl-rvwtc09q.js → otel-impl-7zhnt6gj.js} +1 -1
  145. package/dist/{pending-sqkrb836.js → pending-h01yzpx4.js} +21 -19
  146. package/dist/{pi-mono-adapter-asqayqcg.js → pi-mono-adapter-f52hz743.js} +40 -13
  147. package/dist/{pricing-refresh-f5tkgmw2.js → pricing-refresh-fzxvk2zf.js} +2 -2
  148. package/dist/{rbac-roles-06s555fa.js → rbac-roles-9v6vhgbs.js} +3 -3
  149. package/dist/{rbac-roles-szxsg8t1.js → rbac-roles-hfgh8sba.js} +2 -2
  150. package/dist/{render-v2-103p266q.js → render-v2-1rgspxzf.js} +6 -3
  151. package/dist/{resume-v7kjewt9.js → resume-tqy61x24.js} +10 -7
  152. package/dist/{runtime-f1gmk0b7.js → runtime-exkxyx5f.js} +1 -1
  153. package/dist/{session-access-6shev8ts.js → session-access-3act7vt4.js} +4 -4
  154. package/dist/{session-source-backfill-bd7spzjd.js → session-source-backfill-82qe7fqq.js} +3 -3
  155. package/dist/{setup-kmxmztdb.js → setup-ry1vfdef.js} +1 -1
  156. package/dist/thread-buffer-3x93yexa.js +38 -0
  157. package/dist/{typesafe-system-one-f2en2knd.js → typesafe-system-one-vcfj2ak8.js} +2 -2
  158. package/dist/user-merge-jobs-bx6bf7db.js +22 -0
  159. package/dist/{virtual-modules-57eje5wy.js → virtual-modules-s0rjzcqq.js} +3 -3
  160. package/dist/{work-objects-zr47ygmf.js → work-objects-z2e5tv03.js} +29 -23
  161. package/dist/{worker-follow-up-grrr3fda.js → worker-follow-up-y3xeg89w.js} +20 -18
  162. package/dist/worker-zfcv2wbf.js +74 -0
  163. package/openapi.json +2763 -147
  164. package/package.json +9 -8
  165. package/src/apps/catalog.generated.json +43 -3
  166. package/src/apps/page-validator.ts +27 -0
  167. package/src/be/boot-seeds.ts +7 -1
  168. package/src/be/db/model-groups.ts +238 -0
  169. package/src/be/db/model-profiles.ts +28 -7
  170. package/src/be/db/session-costs.ts +225 -0
  171. package/src/be/db/session-log-reasoning.ts +36 -0
  172. package/src/be/db/tasks/read.ts +8 -3
  173. package/src/be/db/tasks/write.ts +34 -1
  174. package/src/be/db/user-references.ts +75 -0
  175. package/src/be/db/users/references.ts +185 -0
  176. package/src/be/db-client.ts +70 -19
  177. package/src/be/db.ts +232 -361
  178. package/src/be/key-window-usage.ts +386 -0
  179. package/src/be/memory/demotion-evidence.ts +34 -0
  180. package/src/be/memory/reranker.ts +34 -12
  181. package/src/be/memory/review-recall-filter.ts +83 -0
  182. package/src/be/memory/search-candidates.ts +19 -6
  183. package/src/be/memory/types.ts +11 -0
  184. package/src/be/migrations/303_task_ui_specs.sql +28 -0
  185. package/src/be/migrations/306_provider_account_telemetry.sql +1 -0
  186. package/src/be/migrations/307_session_cost_credential_attribution.sql +23 -0
  187. package/src/be/migrations/310_session_logs_reasoning.sql +12 -0
  188. package/src/be/migrations/312_task_ui_action_runs_repeatable.sql +6 -0
  189. package/src/be/migrations/314_model_groups.sql +85 -0
  190. package/src/be/migrations/318_superseded_workflow_cut_backfill.sql +22 -0
  191. package/src/be/migrations/319_user_fk_indexes.sql +153 -0
  192. package/src/be/migrations/320_session_costs_kind.sql +4 -0
  193. package/src/be/migrations/321_user_merge_jobs.sql +52 -0
  194. package/src/be/pricing-normalize.ts +2 -0
  195. package/src/be/rbac-roles.ts +6 -4
  196. package/src/be/runtime-pools/db.ts +23 -5
  197. package/src/be/runtime-pools/supervisor.ts +15 -1
  198. package/src/be/scripts/db.ts +11 -0
  199. package/src/be/scripts/typecheck.ts +2 -0
  200. package/src/be/seed-model-groups.ts +86 -0
  201. package/src/be/seed-model-profiles.ts +20 -13
  202. package/src/be/seed-scripts/catalog/boot-triage.inline.ts +1 -0
  203. package/src/be/seed-scripts/catalog/boot-triage.ts +1 -0
  204. package/src/be/seed-scripts/catalog/dreaming-gather.ts +165 -1
  205. package/src/be/seed-scripts/catalog/wait-for-task.ts +5 -1
  206. package/src/be/seed-skills/index.ts +3 -0
  207. package/src/be/swarm-config-guard.ts +58 -1
  208. package/src/be/task-ui-spec.ts +259 -0
  209. package/src/be/user-merge-jobs.ts +564 -0
  210. package/src/be/users.ts +41 -23
  211. package/src/commands/controller.ts +3 -0
  212. package/src/commands/credential-outcome-report.ts +13 -3
  213. package/src/commands/onboard/agent-fs-version.ts +1 -1
  214. package/src/commands/onboard/compose-generator.ts +1 -1
  215. package/src/commands/onboard/env-generator.ts +1 -1
  216. package/src/commands/provider-credentials.ts +1 -1
  217. package/src/commands/rate-limit-outcome.ts +6 -0
  218. package/src/commands/runner.ts +34 -53
  219. package/src/extensions/catalog.generated.json +3 -3
  220. package/src/extensions/contract-types.generated.ts +1 -1
  221. package/src/extensions/contract.ts +15 -0
  222. package/src/extensions/dispatcher.ts +14 -4
  223. package/src/github/handlers.ts +57 -0
  224. package/src/github/types.ts +4 -0
  225. package/src/http/all-routes.ts +2 -0
  226. package/src/http/api-keys.ts +258 -30
  227. package/src/http/approval-requests.ts +5 -1
  228. package/src/http/auth.ts +3 -1
  229. package/src/http/config.ts +34 -1
  230. package/src/http/index.ts +13 -0
  231. package/src/http/memory.ts +19 -6
  232. package/src/http/model-groups.ts +277 -0
  233. package/src/http/model-profiles.ts +30 -13
  234. package/src/http/session-data.ts +74 -23
  235. package/src/http/sessions.ts +6 -2
  236. package/src/http/tasks.ts +140 -5
  237. package/src/http/tool-hooks.ts +140 -0
  238. package/src/http/users.ts +142 -19
  239. package/src/http/workflows.ts +19 -1
  240. package/src/integrations/chat-sdk/inbound.ts +8 -2
  241. package/src/integrations/chat-sdk/limits.ts +8 -3
  242. package/src/integrations/chat-sdk/relay.ts +87 -0
  243. package/src/jira/outbound.ts +5 -3
  244. package/src/linear/outbound.ts +5 -1
  245. package/src/prompts/base-prompt.ts +8 -0
  246. package/src/prompts/session-templates.ts +19 -2
  247. package/src/providers/acp-targets.ts +2 -2
  248. package/src/providers/amp-adapter.ts +1 -1
  249. package/src/providers/claude-adapter.ts +27 -4
  250. package/src/providers/claude-flag-settings.ts +39 -1
  251. package/src/providers/codex-adapter.ts +85 -3
  252. package/src/providers/codex-app-server.ts +9 -5
  253. package/src/providers/codex-oauth/auth-json.ts +1 -0
  254. package/src/providers/pi-mono-adapter.ts +35 -2
  255. package/src/providers/pricing-sources.md +41 -0
  256. package/src/providers/types.ts +11 -0
  257. package/src/rbac/legacy-policy.ts +1 -0
  258. package/src/rbac/permissions.ts +5 -0
  259. package/src/runtime-providers/docker.ts +65 -1
  260. package/src/runtime-providers/index.ts +7 -5
  261. package/src/runtime-providers/k8s.ts +250 -0
  262. package/src/scheduler/deferred-task-waits.ts +18 -5
  263. package/src/scripts-runtime/types/stdlib.d.ts +2 -0
  264. package/src/scripts-runtime/types/swarm-extension.d.ts +24 -9
  265. package/src/scripts-runtime/types/swarm-sdk.d.ts +2 -0
  266. package/src/slack/actions.ts +79 -0
  267. package/src/slack/app.ts +22 -15
  268. package/src/slack/blocks.ts +23 -2
  269. package/src/slack/inbound-files.ts +2 -0
  270. package/src/slack/render-v2.ts +154 -23
  271. package/src/slack/responses.ts +3 -2
  272. package/src/slack/work-objects.ts +4 -1
  273. package/src/tasks/errors.ts +5 -0
  274. package/src/tests/acp-adapter.test.ts +30 -6
  275. package/src/tests/api-key-tracking.test.ts +0 -72
  276. package/src/tests/api-keys-status-model-limits.test.ts +93 -1
  277. package/src/tests/api-keys-validation.test.ts +42 -0
  278. package/src/tests/approval-card-resolution.test.ts +7 -1
  279. package/src/tests/approval-requests-notifications.test.ts +11 -1
  280. package/src/tests/apps-catalog-page-frame.test.ts +49 -0
  281. package/src/tests/apps-session-thread.test.ts +79 -0
  282. package/src/tests/base-prompt.test.ts +111 -5
  283. package/src/tests/chat-sdk-relay.test.ts +170 -2
  284. package/src/tests/check-pr-body.test.ts +43 -0
  285. package/src/tests/claude-adapter-binary.test.ts +67 -6
  286. package/src/tests/claude-flag-settings.test.ts +29 -0
  287. package/src/tests/claude-sdk-lifecycle.test.ts +5 -0
  288. package/src/tests/codex-adapter.test.ts +340 -2
  289. package/src/tests/codex-app-server.test.ts +16 -0
  290. package/src/tests/codex-oauth.test.ts +3 -1
  291. package/src/tests/codex-rate-limits.test.ts +384 -0
  292. package/src/tests/credential-check.test.ts +14 -6
  293. package/src/tests/credential-outcome-report.test.ts +20 -0
  294. package/src/tests/db-client.test.ts +146 -0
  295. package/src/tests/db-task-read-contract.test.ts +3 -0
  296. package/src/tests/db-task-write-contract.test.ts +4 -0
  297. package/src/tests/deferred-task-wake.test.ts +63 -1
  298. package/src/tests/deploy-guard.test.ts +7 -7
  299. package/src/tests/deploy-select.test.ts +83 -0
  300. package/src/tests/docker-isolation-config-guard.test.ts +29 -0
  301. package/src/tests/docs-index-footprint.test.js +11 -3
  302. package/src/tests/dreaming-gather-corrections.test.ts +467 -0
  303. package/src/tests/e2e-visuals-comment.test.ts +82 -0
  304. package/src/tests/e2e-visuals-verify-pr.test.ts +138 -0
  305. package/src/tests/event-loop-lag.test.ts +9 -7
  306. package/src/tests/extensions-example-sql-admin-only.test.ts +7 -4
  307. package/src/tests/fixtures/extensions/native-tool-recorder/hooks.ts +26 -0
  308. package/src/tests/fixtures/extensions/native-tool-recorder/manifest.json +10 -0
  309. package/src/tests/fixtures/onboard/content.compose.yml.txt +1 -1
  310. package/src/tests/fixtures/onboard/content.env.txt +1 -1
  311. package/src/tests/fixtures/onboard/dev.compose.yml.txt +1 -1
  312. package/src/tests/fixtures/onboard/dev.env.txt +1 -1
  313. package/src/tests/fixtures/onboard/full-all.compose.yml.txt +1 -1
  314. package/src/tests/fixtures/onboard/full-all.env.txt +1 -1
  315. package/src/tests/fixtures/onboard/full.compose.yml.txt +1 -1
  316. package/src/tests/fixtures/onboard/full.env.txt +1 -1
  317. package/src/tests/fixtures/onboard/research.compose.yml.txt +1 -1
  318. package/src/tests/fixtures/onboard/research.env.txt +1 -1
  319. package/src/tests/fixtures/onboard/solo.compose.yml.txt +1 -1
  320. package/src/tests/fixtures/onboard/solo.env.txt +1 -1
  321. package/src/tests/fixtures/ui-spec-slack/deploys.json +121 -0
  322. package/src/tests/fixtures/ui-spec-slack/incident.json +183 -0
  323. package/src/tests/fixtures/ui-spec-slack/three-charts-stale.json +196 -0
  324. package/src/tests/fixtures/ui-spec-slack/video-rejected-by-slack.json +183 -0
  325. package/src/tests/fixtures/ui-spec-slack/video.json +446 -0
  326. package/src/tests/github-event-filter.test.ts +8 -0
  327. package/src/tests/github-handlers-inline-comments.test.ts +2 -0
  328. package/src/tests/github-handlers-reactions.test.ts +4 -0
  329. package/src/tests/github-handlers.test.ts +3 -0
  330. package/src/tests/github-sender-trust.test.ts +223 -0
  331. package/src/tests/gitleaks-download-retry.test.ts +85 -0
  332. package/src/tests/http-users.test.ts +142 -41
  333. package/src/tests/human-thread-routing.test.ts +187 -0
  334. package/src/tests/jira-outbound-sync.test.ts +33 -1
  335. package/src/tests/k8s-pool-smoke.test.ts +190 -0
  336. package/src/tests/key-window-usage.test.ts +846 -0
  337. package/src/tests/linear-outbound-sync.test.ts +30 -1
  338. package/src/tests/memory-rater-store.test.ts +35 -1
  339. package/src/tests/memory-reranker.test.ts +39 -4
  340. package/src/tests/memory-review-recall-filter.test.ts +205 -0
  341. package/src/tests/migration-318-superseded-workflow-cut-backfill.test.ts +74 -0
  342. package/src/tests/model-groups-api.test.ts +415 -0
  343. package/src/tests/model-profiles-api.test.ts +1 -0
  344. package/src/tests/operator-granted-credentials.test.ts +7 -2
  345. package/src/tests/operator-granted-role-wire.test.ts +2 -1
  346. package/src/tests/pi-mono-adapter.test.ts +79 -0
  347. package/src/tests/preload-env.test.ts +2 -0
  348. package/src/tests/preload.ts +3 -1
  349. package/src/tests/prompt-template-session.test.ts +4 -3
  350. package/src/tests/provider-quota-persistence.test.ts +362 -0
  351. package/src/tests/rate-limit-event.test.ts +22 -0
  352. package/src/tests/rbac-engine.test.ts +1 -0
  353. package/src/tests/reasoning-events.test.ts +164 -0
  354. package/src/tests/routing-affinity-inventory.test.ts +22 -0
  355. package/src/tests/runtime-k8s-pools.test.ts +142 -0
  356. package/src/tests/runtime-pools-db.test.ts +42 -2
  357. package/src/tests/runtime-pools-http.test.ts +47 -2
  358. package/src/tests/runtime-provider-registration.test.ts +5 -14
  359. package/src/tests/runtime-providers-docker.test.ts +91 -0
  360. package/src/tests/runtime-providers-k8s.test.ts +303 -0
  361. package/src/tests/script-connections.test.ts +18 -1
  362. package/src/tests/secret-canary-sweep.test.ts +41 -5
  363. package/src/tests/seed-scripts.test.ts +23 -0
  364. package/src/tests/session-cost-attribution.test.ts +748 -0
  365. package/src/tests/session-costs.test.ts +14 -15
  366. package/src/tests/session-logs.test.ts +83 -0
  367. package/src/tests/sessions-detail-batch.test.ts +7 -0
  368. package/src/tests/short-id.test.ts +23 -0
  369. package/src/tests/slack-blocks.test.ts +69 -0
  370. package/src/tests/slack-render-v2.test.ts +411 -0
  371. package/src/tests/slack-start-reload-race.test.ts +67 -0
  372. package/src/tests/spec-base-url.test.ts +13 -1
  373. package/src/tests/subscription-plans.test.ts +20 -1
  374. package/src/tests/system-one-decide-session-cost.test.ts +196 -0
  375. package/src/tests/task-ui-action-route.test.ts +249 -0
  376. package/src/tests/task-ui-actions.test.ts +195 -0
  377. package/src/tests/task-ui-script-actions.test.ts +517 -0
  378. package/src/tests/task-ui-spec-fallback.test.ts +65 -0
  379. package/src/tests/task-ui-spec.test.ts +368 -0
  380. package/src/tests/tool-hooks-http.test.ts +187 -0
  381. package/src/tests/ui-spec-script-actions-config.test.ts +196 -0
  382. package/src/tests/user-delete-perf.test.ts +321 -0
  383. package/src/tests/user-merge-jobs.test.ts +680 -0
  384. package/src/tests/vcs-provider.test.ts +25 -5
  385. package/src/tests/vendored-openapi.test.ts +13 -1
  386. package/src/tests/workflow-agent-task-retry.test.ts +96 -1
  387. package/src/tests/workflow-foreach-supersede-retry.test.ts +10 -0
  388. package/src/tests/workflow-http-v2.test.ts +27 -0
  389. package/src/tests/workflow-replay.test.ts +10 -1
  390. package/src/tests/workflow-triggers-v2.test.ts +128 -0
  391. package/src/tests/workflow-wait-event.test.ts +109 -1
  392. package/src/tools/defer-task.ts +1 -1
  393. package/src/tools/memory-search.ts +14 -3
  394. package/src/tools/store-progress.ts +69 -3
  395. package/src/tools/swarm-config/delete-config.ts +12 -1
  396. package/src/tools/swarm-config/set-config.ts +8 -0
  397. package/src/tools/system-one-decide.ts +113 -3
  398. package/src/tools/utils.ts +4 -1
  399. package/src/tools/workflows/create-workflow.ts +2 -0
  400. package/src/tools/workflows/update-workflow.ts +3 -1
  401. package/src/types.ts +93 -4
  402. package/src/ui-spec/actions.ts +112 -0
  403. package/src/ui-spec/fallback.ts +19 -0
  404. package/src/ui-spec/schema.ts +38 -0
  405. package/src/ui-spec/script-actions.ts +340 -0
  406. package/src/ui-spec/script-allowlist.ts +48 -0
  407. package/src/ui-spec/slack.ts +17 -0
  408. package/src/ui-spec/validate.ts +169 -0
  409. package/src/utils/codex-rate-limits.ts +159 -0
  410. package/src/utils/credentials.ts +2 -0
  411. package/src/utils/error-tracker.ts +19 -0
  412. package/src/utils/provider-account-telemetry.ts +331 -0
  413. package/src/utils/reasoning-events.ts +107 -0
  414. package/src/utils/short-id.ts +20 -14
  415. package/src/utils/subscription-plans.ts +11 -59
  416. package/src/utils/task-ui-spec.ts +79 -0
  417. package/src/vcs/index.ts +12 -2
  418. package/src/workflows/executors/system-one-decision.ts +2 -2
  419. package/src/workflows/resume.ts +3 -2
  420. package/src/workflows/task-step-routing.ts +38 -13
  421. package/src/workflows/triggers.ts +35 -3
  422. package/templates/extensions/manifest.schema.json +13 -0
  423. package/templates/extensions/sql-admin-only/README.md +2 -1
  424. package/templates/extensions/sql-admin-only/hooks.ts +7 -3
  425. package/templates/extensions/sql-admin-only/manifest.json +1 -1
  426. package/templates/skills/apps/SKILL.md +32 -5
  427. package/templates/skills/apps/content.md +32 -5
  428. package/templates/skills/swarm-docs/content.md +2 -0
  429. package/templates/skills/ui-spec/config.json +14 -0
  430. package/templates/skills/ui-spec/content.md +133 -0
  431. package/templates/workflows/dreaming/content.md +1 -1
  432. package/dist/acp-adapter-jqn86aam.js +0 -16
  433. package/dist/cli-7831nhaw.js +0 -93
  434. package/dist/cli-srtkr1h2.js +0 -12078
  435. package/dist/fx-adapter-0zrkfbkd.js +0 -19
  436. package/dist/grok-adapter-3db1c538.js +0 -19
  437. package/dist/handlers-k22n8mnn.js +0 -33
  438. package/dist/index-8xcyd3mc.js +0 -33
  439. package/dist/index-9sy2bh6n.js +0 -38
  440. package/dist/index-b24j7t2m.js +0 -12797
  441. package/dist/index-wjd56k1v.js +0 -34
  442. package/dist/lead-atxf3q6e.js +0 -72
  443. package/dist/thread-buffer-4yz236d0.js +0 -36
  444. package/dist/worker-p4hbtcy3.js +0 -72
  445. package/dist/{azure-openai-responses-590s1eea.js → azure-openai-responses-b3y7fz36.js} +8 -8
  446. package/dist/{cli-j49yqpvh.js → cli-7evph51z.js} +3 -3
  447. package/dist/{cli-g0vv9dg4.js → cli-8y43jx2r.js} +8 -8
  448. package/dist/{cli-m0cy2vyf.js → cli-k6nejceb.js} +4 -4
  449. package/dist/{mistral-conversations-0c30em7t.js → mistral-conversations-tm2vd4gc.js} +8 -8
  450. package/dist/{openai-codex-responses-bkcd8pjj.js → openai-codex-responses-sxjv60xx.js} +4 -4
  451. package/dist/{openai-completions-f3n69rep.js → openai-completions-0c7qnhsx.js} +20 -20
  452. package/dist/{openai-responses-gbh0wfqe.js → openai-responses-a7h29chp.js} +15 -15
  453. package/dist/{pi-messages-zebyt7gb.js → pi-messages-2j0fpqwq.js} +5 -5
@@ -12076,7 +12076,7 @@ var init_unified = __esm(() => {
12076
12076
  init_lib22();
12077
12077
  });
12078
12078
 
12079
- // node_modules/chat/dist/chunk-LKOB5H73.js
12079
+ // node_modules/chat/dist/chunk-5S562BSE.js
12080
12080
  function isTextNode2(node) {
12081
12081
  return node.type === "text";
12082
12082
  }
@@ -12181,6 +12181,100 @@ function getNodeValue(node) {
12181
12181
  }
12182
12182
  return "";
12183
12183
  }
12184
+ function countChars(value, chars) {
12185
+ let count = 0;
12186
+ for (const char of value) {
12187
+ if (chars.includes(char)) {
12188
+ count++;
12189
+ }
12190
+ }
12191
+ return count;
12192
+ }
12193
+ function isBlank(char) {
12194
+ return char === undefined || char === " " || char === "\t";
12195
+ }
12196
+ function leadingColumns(line) {
12197
+ let columns = 0;
12198
+ for (const char of line) {
12199
+ if (char === " ") {
12200
+ columns++;
12201
+ } else if (char === "\t") {
12202
+ columns += 4 - columns % 4;
12203
+ } else {
12204
+ break;
12205
+ }
12206
+ }
12207
+ return columns;
12208
+ }
12209
+ function countContainerMarkers(line) {
12210
+ let count = 0;
12211
+ let i = 0;
12212
+ while (i < line.length) {
12213
+ while (line[i] === " " || line[i] === "\t") {
12214
+ i++;
12215
+ }
12216
+ const char = line[i];
12217
+ if (char === ">") {
12218
+ i++;
12219
+ } else if ((char === "-" || char === "+" || char === "*") && isBlank(line[i + 1])) {
12220
+ i += 2;
12221
+ } else if (char === "[" && line[i + 1] === "^") {
12222
+ const labelEnd = line.indexOf("]", i + 2);
12223
+ if (labelEnd === -1 || line[labelEnd + 1] !== ":") {
12224
+ return count;
12225
+ }
12226
+ i = labelEnd + 2;
12227
+ } else {
12228
+ let digits = 0;
12229
+ while (digits < 10 && line[i + digits] >= "0" && line[i + digits] <= "9") {
12230
+ digits++;
12231
+ }
12232
+ const delimiter = line[i + digits];
12233
+ if (digits === 0 || digits > 9 || !(delimiter === "." || delimiter === ")") || !isBlank(line[i + digits + 1])) {
12234
+ return count;
12235
+ }
12236
+ i += digits + 2;
12237
+ }
12238
+ count++;
12239
+ }
12240
+ return count;
12241
+ }
12242
+ function fenceOpener(line) {
12243
+ const marker = FENCE_OPEN_PATTERN.exec(line)?.[1];
12244
+ if (marker?.startsWith("`") && line.slice(marker.length).includes("`")) {
12245
+ return;
12246
+ }
12247
+ return marker;
12248
+ }
12249
+ function exceedsWwwAutolinksPerWord(line, max) {
12250
+ for (const word of line.split(WHITESPACE_PATTERN)) {
12251
+ if ((word.match(WWW_AUTOLINK_PATTERN)?.length ?? 0) > max) {
12252
+ return true;
12253
+ }
12254
+ }
12255
+ return false;
12256
+ }
12257
+ function closesFence(line, opener) {
12258
+ const marker = FENCE_CLOSE_PATTERN.exec(line)?.[1];
12259
+ return marker !== undefined && marker[0] === opener[0] && marker.length >= opener.length;
12260
+ }
12261
+ function exceedsDepth(ast, max) {
12262
+ const stack = [[ast, 0]];
12263
+ let entry = stack.pop();
12264
+ while (entry) {
12265
+ const [node, depth] = entry;
12266
+ if (depth > max) {
12267
+ return true;
12268
+ }
12269
+ if ("children" in node) {
12270
+ for (const child of node.children) {
12271
+ stack.push([child, depth + 1]);
12272
+ }
12273
+ }
12274
+ entry = stack.pop();
12275
+ }
12276
+ return false;
12277
+ }
12184
12278
  function parseMarkdown2(markdown) {
12185
12279
  const processor = unified().use(remarkParse).use(remarkGfm);
12186
12280
  return processor.parse(markdown);
@@ -12268,6 +12362,18 @@ function paragraph2(children) {
12268
12362
  function root2(children) {
12269
12363
  return { type: "root", children };
12270
12364
  }
12365
+ function TextInput(options) {
12366
+ return {
12367
+ type: "text_input",
12368
+ id: options.id,
12369
+ label: options.label,
12370
+ placeholder: options.placeholder,
12371
+ initialValue: options.initialValue,
12372
+ multiline: options.multiline,
12373
+ optional: options.optional,
12374
+ maxLength: options.maxLength
12375
+ };
12376
+ }
12271
12377
  function isCardElement(value) {
12272
12378
  return typeof value === "object" && value !== null && "type" in value && value.type === "card";
12273
12379
  }
@@ -12320,7 +12426,8 @@ function Button(options) {
12320
12426
  disabled: options.disabled,
12321
12427
  actionType: options.actionType,
12322
12428
  callbackUrl: options.callbackUrl,
12323
- tooltip: options.tooltip
12429
+ tooltip: options.tooltip,
12430
+ visibleTo: options.visibleTo
12324
12431
  };
12325
12432
  }
12326
12433
  function LinkButton(options) {
@@ -12330,7 +12437,8 @@ function LinkButton(options) {
12330
12437
  url: options.url,
12331
12438
  label: options.label,
12332
12439
  style: options.style,
12333
- tooltip: options.tooltip
12440
+ tooltip: options.tooltip,
12441
+ visibleTo: options.visibleTo
12334
12442
  };
12335
12443
  }
12336
12444
  function Field(options) {
@@ -12406,6 +12514,8 @@ function cardChildToFallbackText(child) {
12406
12514
  return tableElementToAscii2(child.headers, child.rows);
12407
12515
  case "chart":
12408
12516
  return chartElementToFallbackText2(child);
12517
+ case "text_input":
12518
+ return child.label;
12409
12519
  case "section":
12410
12520
  return child.children.map((c) => cardChildToFallbackText(c)).filter(Boolean).join(`
12411
12521
  `);
@@ -12413,33 +12523,56 @@ function cardChildToFallbackText(child) {
12413
12523
  return null;
12414
12524
  }
12415
12525
  }
12416
- var BaseFormatConverter2 = class {
12526
+ var LINE_BREAK_REGEX, DEFAULT_MAX_INCOMING_PARSE_LENGTH = 16384, DEFAULT_MAX_INCOMING_EMPHASIS_MARKERS = 2048, DEFAULT_MAX_INCOMING_CLOSING_BRACKETS = 128, DEFAULT_MAX_INCOMING_ANGLE_BRACKETS = 512, DEFAULT_MAX_INCOMING_WWW_AUTOLINKS = 8, DEFAULT_MAX_INCOMING_CONTAINER_MARKERS = 32, LINE_ENDING_PATTERN, FENCE_SKIP_DISABLED_PATTERN, FENCE_OPEN_PATTERN, FENCE_CLOSE_PATTERN, WWW_AUTOLINK_PATTERN, WHITESPACE_PATTERN, DEFAULT_MAX_INCOMING_AST_DEPTH = 128, BaseFormatConverter2 = class {
12527
+ indentListContinuationLines = false;
12417
12528
  renderList(node, depth, nodeConverter, unorderedBullet = "-") {
12418
- const indent = " ".repeat(depth);
12529
+ return this.renderListLines(node, " ".repeat(depth), nodeConverter, unorderedBullet).join(`
12530
+ `);
12531
+ }
12532
+ renderListLines(node, indent, nodeConverter, unorderedBullet) {
12419
12533
  const start = node.start ?? 1;
12420
12534
  const lines = [];
12421
12535
  for (const [i, item] of getNodeChildren2(node).entries()) {
12422
12536
  const prefix = node.ordered ? `${start + i}.` : unorderedBullet;
12423
- let isFirstContent = true;
12537
+ const marker = `${indent}${prefix} `;
12538
+ const contentIndent = " ".repeat(marker.length);
12539
+ let previous;
12424
12540
  for (const child of getNodeChildren2(item)) {
12425
12541
  if (isListNode2(child)) {
12426
- lines.push(this.renderList(child, depth + 1, nodeConverter, unorderedBullet));
12542
+ const nested = this.renderListLines(child, contentIndent, nodeConverter, unorderedBullet);
12543
+ if (nested.length === 0) {
12544
+ continue;
12545
+ }
12546
+ if (previous) {
12547
+ const canInterrupt = previous.type !== "html" && (!child.ordered || (child.start ?? 1) === 1);
12548
+ if (!canInterrupt) {
12549
+ lines.push("");
12550
+ }
12551
+ lines.push(...nested);
12552
+ } else {
12553
+ lines.push(`${marker}${nested[0].slice(contentIndent.length)}`);
12554
+ lines.push(...nested.slice(1));
12555
+ }
12556
+ previous = child;
12427
12557
  continue;
12428
12558
  }
12429
12559
  const text2 = nodeConverter(child);
12430
12560
  if (!text2.trim()) {
12431
12561
  continue;
12432
12562
  }
12433
- if (isFirstContent) {
12434
- lines.push(`${indent}${prefix} ${text2}`);
12435
- isFirstContent = false;
12563
+ const [firstLine, ...rest] = text2.split(LINE_BREAK_REGEX);
12564
+ if (previous) {
12565
+ lines.push("", `${contentIndent}${firstLine}`);
12436
12566
  } else {
12437
- lines.push(`${indent} ${text2}`);
12567
+ lines.push(`${marker}${firstLine}`);
12568
+ }
12569
+ for (const line of rest) {
12570
+ lines.push(this.indentListContinuationLines && line ? `${contentIndent}${line}` : line);
12438
12571
  }
12572
+ previous = child;
12439
12573
  }
12440
12574
  }
12441
- return lines.join(`
12442
- `);
12575
+ return lines;
12443
12576
  }
12444
12577
  defaultNodeToText(node, nodeConverter) {
12445
12578
  const children = getNodeChildren2(node);
@@ -12460,6 +12593,73 @@ var BaseFormatConverter2 = class {
12460
12593
  extractPlainText(platformText) {
12461
12594
  return toPlainText2(this.toAst(platformText));
12462
12595
  }
12596
+ maxIncomingParseLength = DEFAULT_MAX_INCOMING_PARSE_LENGTH;
12597
+ maxIncomingEmphasisMarkers = DEFAULT_MAX_INCOMING_EMPHASIS_MARKERS;
12598
+ maxIncomingClosingBrackets = DEFAULT_MAX_INCOMING_CLOSING_BRACKETS;
12599
+ maxIncomingAngleBrackets = DEFAULT_MAX_INCOMING_ANGLE_BRACKETS;
12600
+ maxIncomingWwwAutolinks = DEFAULT_MAX_INCOMING_WWW_AUTOLINKS;
12601
+ maxIncomingContainerMarkers = DEFAULT_MAX_INCOMING_CONTAINER_MARKERS;
12602
+ maxIncomingAstDepth = DEFAULT_MAX_INCOMING_AST_DEPTH;
12603
+ parseIncoming(platformText) {
12604
+ if (this.exceedsIncomingBudget(platformText)) {
12605
+ return this.unparsedIncoming(platformText);
12606
+ }
12607
+ let formatted;
12608
+ try {
12609
+ formatted = this.toAst(platformText);
12610
+ } catch (error) {
12611
+ if (error instanceof RangeError) {
12612
+ return this.unparsedIncoming(platformText);
12613
+ }
12614
+ throw error;
12615
+ }
12616
+ if (exceedsDepth(formatted, this.maxIncomingAstDepth)) {
12617
+ return this.unparsedIncoming(platformText);
12618
+ }
12619
+ return { text: toPlainText2(formatted), formatted };
12620
+ }
12621
+ exceedsIncomingBudget(platformText) {
12622
+ if (platformText.length > this.maxIncomingParseLength) {
12623
+ return true;
12624
+ }
12625
+ const skipFences = !FENCE_SKIP_DISABLED_PATTERN.test(platformText);
12626
+ let emphasisMarkers = 0;
12627
+ let closingBrackets = 0;
12628
+ let angleBrackets = 0;
12629
+ let fence;
12630
+ for (const line of platformText.split(LINE_ENDING_PATTERN)) {
12631
+ if (fence) {
12632
+ if (closesFence(line, fence)) {
12633
+ fence = undefined;
12634
+ }
12635
+ continue;
12636
+ }
12637
+ if (skipFences) {
12638
+ fence = fenceOpener(line);
12639
+ if (fence) {
12640
+ continue;
12641
+ }
12642
+ }
12643
+ const nesting = line.trim() ? countContainerMarkers(line) + Math.floor(leadingColumns(line) / 2) : 0;
12644
+ emphasisMarkers += countChars(line, "*_~");
12645
+ closingBrackets += countChars(line, "]");
12646
+ angleBrackets += countChars(line, "<");
12647
+ if (nesting > this.maxIncomingContainerMarkers || emphasisMarkers > this.maxIncomingEmphasisMarkers || closingBrackets > this.maxIncomingClosingBrackets || angleBrackets > this.maxIncomingAngleBrackets || exceedsWwwAutolinksPerWord(line, this.maxIncomingWwwAutolinks)) {
12648
+ return true;
12649
+ }
12650
+ }
12651
+ return false;
12652
+ }
12653
+ incomingFallbackText(platformText) {
12654
+ return platformText;
12655
+ }
12656
+ unparsedIncoming(platformText) {
12657
+ const fallback = this.incomingFallbackText(platformText);
12658
+ return {
12659
+ text: fallback,
12660
+ formatted: root2([paragraph2([text5(fallback)])])
12661
+ };
12662
+ }
12463
12663
  fromMarkdown(markdown) {
12464
12664
  return this.fromAst(parseMarkdown2(markdown));
12465
12665
  }
@@ -12520,6 +12720,8 @@ var BaseFormatConverter2 = class {
12520
12720
  return tableElementToAscii2(child.headers, child.rows);
12521
12721
  case "chart":
12522
12722
  return chartElementToFallbackText2(child);
12723
+ case "text_input":
12724
+ return child.label;
12523
12725
  case "section":
12524
12726
  return child.children.map((c) => this.cardChildToFallbackText(c)).filter(Boolean).join(`
12525
12727
  `);
@@ -12528,15 +12730,22 @@ var BaseFormatConverter2 = class {
12528
12730
  }
12529
12731
  }
12530
12732
  };
12531
- var init_chunk_LKOB5H73 = __esm(() => {
12733
+ var init_chunk_5S562BSE = __esm(() => {
12532
12734
  init_mdast_util_to_string();
12533
12735
  init_remark_gfm();
12534
12736
  init_remark_parse();
12535
12737
  init_remark_stringify();
12536
12738
  init_unified();
12739
+ LINE_BREAK_REGEX = /\r\n|\r|\n/;
12740
+ LINE_ENDING_PATTERN = /\r\n|\r|\n/;
12741
+ FENCE_SKIP_DISABLED_PATTERN = /^ {0,3}<|^ {1,3}(?:`{3,}|~{3,})/m;
12742
+ FENCE_OPEN_PATTERN = /^(`{3,}|~{3,})/;
12743
+ FENCE_CLOSE_PATTERN = /^ {0,3}(`{3,}|~{3,})[ \t]*$/;
12744
+ WWW_AUTOLINK_PATTERN = /www\./gi;
12745
+ WHITESPACE_PATTERN = /\s+/;
12537
12746
  });
12538
12747
 
12539
- // node_modules/chat/dist/chunk-5B5TSGU4.js
12748
+ // node_modules/chat/dist/chunk-D5LKW5SX.js
12540
12749
  function isModalElement(value) {
12541
12750
  return typeof value === "object" && value !== null && "type" in value && value.type === "modal";
12542
12751
  }
@@ -12560,18 +12769,6 @@ function Modal(options) {
12560
12769
  children: options.children ?? []
12561
12770
  };
12562
12771
  }
12563
- function TextInput(options) {
12564
- return {
12565
- type: "text_input",
12566
- id: options.id,
12567
- label: options.label,
12568
- placeholder: options.placeholder,
12569
- initialValue: options.initialValue,
12570
- multiline: options.multiline,
12571
- optional: options.optional,
12572
- maxLength: options.maxLength
12573
- };
12574
- }
12575
12772
  function DateInput(options) {
12576
12773
  return {
12577
12774
  type: "date_input",
@@ -12739,7 +12936,8 @@ function resolveJSXElement(element) {
12739
12936
  actionType: props.actionType,
12740
12937
  callbackUrl: props.callbackUrl,
12741
12938
  disabled: props.disabled,
12742
- tooltip: props.tooltip
12939
+ tooltip: props.tooltip,
12940
+ visibleTo: props.visibleTo
12743
12941
  });
12744
12942
  }
12745
12943
  if (type === LinkButton) {
@@ -12752,7 +12950,8 @@ function resolveJSXElement(element) {
12752
12950
  url: props.url,
12753
12951
  label,
12754
12952
  style: props.style,
12755
- tooltip: props.tooltip
12953
+ tooltip: props.tooltip,
12954
+ visibleTo: props.visibleTo
12756
12955
  });
12757
12956
  }
12758
12957
  if (type === CardLink) {
@@ -12943,8 +13142,8 @@ function isJSX(value) {
12943
13142
  return false;
12944
13143
  }
12945
13144
  var VALID_MODAL_CHILD_TYPES, JSX_ELEMENT;
12946
- var init_chunk_5B5TSGU4 = __esm(() => {
12947
- init_chunk_LKOB5H73();
13145
+ var init_chunk_D5LKW5SX = __esm(() => {
13146
+ init_chunk_5S562BSE();
12948
13147
  VALID_MODAL_CHILD_TYPES = [
12949
13148
  "text_input",
12950
13149
  "date_input",
@@ -12958,6 +13157,136 @@ var init_chunk_5B5TSGU4 = __esm(() => {
12958
13157
  JSX_ELEMENT = /* @__PURE__ */ Symbol.for("chat.jsx.element");
12959
13158
  });
12960
13159
 
13160
+ // node_modules/chat/dist/chunk-Y5QSQ2Z3.js
13161
+ function encodeCallbackValue(token) {
13162
+ return `${CALLBACK_TOKEN_PREFIX}${token}`;
13163
+ }
13164
+ function decodeCallbackValue(value) {
13165
+ if (!value?.startsWith(CALLBACK_TOKEN_PREFIX)) {
13166
+ return { callbackToken: undefined };
13167
+ }
13168
+ return { callbackToken: value.slice(CALLBACK_TOKEN_PREFIX.length) };
13169
+ }
13170
+ function generateToken() {
13171
+ return crypto.randomUUID().replace(/-/g, "").slice(0, 16);
13172
+ }
13173
+ async function processActionsElement(actions, stateAdapter, scope) {
13174
+ return {
13175
+ type: "actions",
13176
+ children: await Promise.all(actions.children.map(async (el) => {
13177
+ if (el.type !== "button" || !el.callbackUrl) {
13178
+ return el;
13179
+ }
13180
+ const token = generateToken();
13181
+ const stored = {
13182
+ actionId: el.id,
13183
+ url: el.callbackUrl,
13184
+ originalValue: el.value,
13185
+ scope
13186
+ };
13187
+ await stateAdapter.set(`${CALLBACK_CACHE_KEY_PREFIX}${token}`, stored, CALLBACK_TTL_MS);
13188
+ const { callbackUrl: _callbackUrl, ...rest } = el;
13189
+ const processed = {
13190
+ ...rest,
13191
+ value: encodeCallbackValue(token)
13192
+ };
13193
+ return processed;
13194
+ }))
13195
+ };
13196
+ }
13197
+ function hasCallbackButtons(children) {
13198
+ for (const child of children) {
13199
+ if (child.type === "actions") {
13200
+ for (const el of child.children) {
13201
+ if (el.type === "button" && el.callbackUrl) {
13202
+ return true;
13203
+ }
13204
+ }
13205
+ }
13206
+ if (child.type === "section" && "children" in child && hasCallbackButtons(child.children)) {
13207
+ return true;
13208
+ }
13209
+ }
13210
+ return false;
13211
+ }
13212
+ async function processChildren2(children, stateAdapter, scope) {
13213
+ const result = [];
13214
+ for (const child of children) {
13215
+ if (child.type === "actions") {
13216
+ result.push(await processActionsElement(child, stateAdapter, scope));
13217
+ } else if (child.type === "section" && "children" in child) {
13218
+ result.push({
13219
+ ...child,
13220
+ children: await processChildren2(child.children, stateAdapter, scope)
13221
+ });
13222
+ } else {
13223
+ result.push(child);
13224
+ }
13225
+ }
13226
+ return result;
13227
+ }
13228
+ async function processCardCallbackUrls(card, stateAdapter, scope) {
13229
+ if (!hasCallbackButtons(card.children)) {
13230
+ return card;
13231
+ }
13232
+ return {
13233
+ ...card,
13234
+ children: await processChildren2(card.children, stateAdapter, scope)
13235
+ };
13236
+ }
13237
+ async function resolveCallbackUrl(token, stateAdapter, context) {
13238
+ const key = `${CALLBACK_CACHE_KEY_PREFIX}${token}`;
13239
+ const lock = await stateAdapter.acquireLock(key, CALLBACK_LOCK_TTL_MS);
13240
+ if (!lock) {
13241
+ return null;
13242
+ }
13243
+ try {
13244
+ const stored = await stateAdapter.get(key);
13245
+ if (!stored || typeof stored !== "object" || typeof stored.actionId !== "string" || typeof stored.url !== "string" || stored.originalValue !== undefined && typeof stored.originalValue !== "string" || !stored.scope || typeof stored.scope.id !== "string" || stored.scope.type !== "channel" && stored.scope.type !== "thread") {
13246
+ return null;
13247
+ }
13248
+ const scopeId = stored.scope.type === "channel" ? context?.channelId : context?.threadId;
13249
+ if (stored.actionId !== context?.actionId || stored.scope.id !== scopeId) {
13250
+ return null;
13251
+ }
13252
+ await stateAdapter.delete(key);
13253
+ return stored;
13254
+ } finally {
13255
+ await stateAdapter.releaseLock(lock);
13256
+ }
13257
+ }
13258
+ async function createCallbackReceipt(stateAdapter, receipt) {
13259
+ const nonce = crypto.randomUUID();
13260
+ await stateAdapter.set(`${CALLBACK_RECEIPT_KEY_PREFIX}${nonce}`, receipt, CALLBACK_RECEIPT_TTL_MS);
13261
+ return nonce;
13262
+ }
13263
+ async function restoreCallbackToken(stateAdapter, token, stored) {
13264
+ await stateAdapter.set(`${CALLBACK_CACHE_KEY_PREFIX}${token}`, stored, CALLBACK_TTL_MS);
13265
+ }
13266
+ async function postToCallbackUrl(callbackUrl, payload) {
13267
+ try {
13268
+ const response = await fetch(callbackUrl, {
13269
+ method: "POST",
13270
+ headers: { "Content-Type": "application/json" },
13271
+ body: JSON.stringify(payload)
13272
+ });
13273
+ if (!response.ok) {
13274
+ return {
13275
+ error: new Error(`Callback URL returned ${response.status}: ${await response.text().catch(() => "")}`),
13276
+ status: response.status
13277
+ };
13278
+ }
13279
+ return { status: response.status };
13280
+ } catch (error) {
13281
+ return { error };
13282
+ }
13283
+ }
13284
+ var CALLBACK_TOKEN_PREFIX = "__cb:", CALLBACK_CACHE_KEY_PREFIX = "chat:callback:", CALLBACK_TTL_MS, CALLBACK_LOCK_TTL_MS = 1e4, CALLBACK_RECEIPT_KEY_PREFIX = "chat:callback-receipt:", CALLBACK_RECEIPT_TTL_MS;
13285
+ var init_chunk_Y5QSQ2Z3 = __esm(() => {
13286
+ CALLBACK_TTL_MS = 7 * 24 * 60 * 60 * 1000;
13287
+ CALLBACK_RECEIPT_TTL_MS = 24 * 60 * 60 * 1000;
13288
+ });
13289
+
12961
13290
  // node_modules/@workflow/serde/dist/index.js
12962
13291
  var WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE;
12963
13292
  var init_dist2 = __esm(() => {
@@ -13486,7 +13815,7 @@ var init_dist3 = __esm(() => {
13486
13815
  $e = vn;
13487
13816
  });
13488
13817
 
13489
- // node_modules/chat/dist/chunk-ZGXC7ZLP.js
13818
+ // node_modules/chat/dist/chunk-MOZRUO2D.js
13490
13819
  async function* fromFullStream(stream) {
13491
13820
  let needsSeparator = false;
13492
13821
  let hasEmittedText = false;
@@ -13543,121 +13872,6 @@ async function postPostableObject(obj, adapter, threadId, postFn, logger) {
13543
13872
  obj.onPosted(context(raw));
13544
13873
  }
13545
13874
  }
13546
- function encodeCallbackValue(token) {
13547
- return `${CALLBACK_TOKEN_PREFIX}${token}`;
13548
- }
13549
- function decodeCallbackValue(value) {
13550
- if (!value?.startsWith(CALLBACK_TOKEN_PREFIX)) {
13551
- return { callbackToken: undefined };
13552
- }
13553
- return { callbackToken: value.slice(CALLBACK_TOKEN_PREFIX.length) };
13554
- }
13555
- function generateToken() {
13556
- return crypto.randomUUID().replace(/-/g, "").slice(0, 16);
13557
- }
13558
- async function processActionsElement(actions, stateAdapter, scope) {
13559
- return {
13560
- type: "actions",
13561
- children: await Promise.all(actions.children.map(async (el) => {
13562
- if (el.type !== "button" || !el.callbackUrl) {
13563
- return el;
13564
- }
13565
- const token = generateToken();
13566
- const stored = {
13567
- actionId: el.id,
13568
- url: el.callbackUrl,
13569
- originalValue: el.value,
13570
- scope
13571
- };
13572
- await stateAdapter.set(`${CALLBACK_CACHE_KEY_PREFIX}${token}`, stored, CALLBACK_TTL_MS);
13573
- const { callbackUrl: _callbackUrl, ...rest } = el;
13574
- const processed = {
13575
- ...rest,
13576
- value: encodeCallbackValue(token)
13577
- };
13578
- return processed;
13579
- }))
13580
- };
13581
- }
13582
- function hasCallbackButtons(children) {
13583
- for (const child of children) {
13584
- if (child.type === "actions") {
13585
- for (const el of child.children) {
13586
- if (el.type === "button" && el.callbackUrl) {
13587
- return true;
13588
- }
13589
- }
13590
- }
13591
- if (child.type === "section" && "children" in child && hasCallbackButtons(child.children)) {
13592
- return true;
13593
- }
13594
- }
13595
- return false;
13596
- }
13597
- async function processChildren2(children, stateAdapter, scope) {
13598
- const result = [];
13599
- for (const child of children) {
13600
- if (child.type === "actions") {
13601
- result.push(await processActionsElement(child, stateAdapter, scope));
13602
- } else if (child.type === "section" && "children" in child) {
13603
- result.push({
13604
- ...child,
13605
- children: await processChildren2(child.children, stateAdapter, scope)
13606
- });
13607
- } else {
13608
- result.push(child);
13609
- }
13610
- }
13611
- return result;
13612
- }
13613
- async function processCardCallbackUrls(card, stateAdapter, scope) {
13614
- if (!hasCallbackButtons(card.children)) {
13615
- return card;
13616
- }
13617
- return {
13618
- ...card,
13619
- children: await processChildren2(card.children, stateAdapter, scope)
13620
- };
13621
- }
13622
- async function resolveCallbackUrl(token, stateAdapter, context) {
13623
- const key = `${CALLBACK_CACHE_KEY_PREFIX}${token}`;
13624
- const lock = await stateAdapter.acquireLock(key, CALLBACK_LOCK_TTL_MS);
13625
- if (!lock) {
13626
- return null;
13627
- }
13628
- try {
13629
- const stored = await stateAdapter.get(key);
13630
- if (!stored || typeof stored !== "object" || typeof stored.actionId !== "string" || typeof stored.url !== "string" || stored.originalValue !== undefined && typeof stored.originalValue !== "string" || !stored.scope || typeof stored.scope.id !== "string" || stored.scope.type !== "channel" && stored.scope.type !== "thread") {
13631
- return null;
13632
- }
13633
- const scopeId = stored.scope.type === "channel" ? context?.channelId : context?.threadId;
13634
- if (stored.actionId !== context?.actionId || stored.scope.id !== scopeId) {
13635
- return null;
13636
- }
13637
- await stateAdapter.delete(key);
13638
- return stored;
13639
- } finally {
13640
- await stateAdapter.releaseLock(lock);
13641
- }
13642
- }
13643
- async function postToCallbackUrl(callbackUrl, payload) {
13644
- try {
13645
- const response = await fetch(callbackUrl, {
13646
- method: "POST",
13647
- headers: { "Content-Type": "application/json" },
13648
- body: JSON.stringify(payload)
13649
- });
13650
- if (!response.ok) {
13651
- return {
13652
- error: new Error(`Callback URL returned ${response.status}: ${await response.text().catch(() => "")}`),
13653
- status: response.status
13654
- };
13655
- }
13656
- return { status: response.status };
13657
- } catch (error) {
13658
- return { error };
13659
- }
13660
- }
13661
13875
  function setChatSingleton(chat) {
13662
13876
  _singleton = chat;
13663
13877
  }
@@ -13861,6 +14075,23 @@ function isLazyConfig2(config) {
13861
14075
  function isAsyncIterable2(value) {
13862
14076
  return value !== null && typeof value === "object" && Symbol.asyncIterator in value;
13863
14077
  }
14078
+ function withAiGenerated(postable, options) {
14079
+ return options?.aiGenerated ? { ...postable, aiGenerated: true } : postable;
14080
+ }
14081
+ function getNeverAbortedSignal() {
14082
+ if (!neverAbortedSignal) {
14083
+ neverAbortedSignal = typeof AbortController === "function" ? new AbortController().signal : {
14084
+ aborted: false,
14085
+ reason: undefined,
14086
+ onabort: null,
14087
+ throwIfAborted() {},
14088
+ addEventListener() {},
14089
+ removeEventListener() {},
14090
+ dispatchEvent: () => false
14091
+ };
14092
+ }
14093
+ return neverAbortedSignal;
14094
+ }
13864
14095
  async function* takeUntilAborted(source, signal) {
13865
14096
  const iterator = source[Symbol.asyncIterator]();
13866
14097
  let onAbort;
@@ -13994,7 +14225,7 @@ var STREAM_CHUNK_TYPES, adapterMap, Message3, POSTABLE_OBJECT, ChatError, LockEr
13994
14225
  console.error(`[${this.prefix}] ${message}`, ...args);
13995
14226
  }
13996
14227
  }
13997
- }, THREAD_STATE_TTL_MS, CALLBACK_TOKEN_PREFIX = "__cb:", CALLBACK_CACHE_KEY_PREFIX = "chat:callback:", CALLBACK_TTL_MS, CALLBACK_LOCK_TTL_MS = 1e4, _singleton = null, ChatBinding = class {
14228
+ }, THREAD_STATE_TTL_MS, _singleton = null, ChatBinding = class {
13998
14229
  explicit;
13999
14230
  owner;
14000
14231
  checked;
@@ -14124,10 +14355,11 @@ var STREAM_CHUNK_TYPES, adapterMap, Message3, POSTABLE_OBJECT, ChatError, LockEr
14124
14355
  }
14125
14356
  return wrapTablesForAppend(text2, closeFences);
14126
14357
  }
14127
- }, INLINE_MARKER_CHARS, TABLE_ROW_RE, TABLE_SEPARATOR_RE, THREAD_STATE_KEY_PREFIX = "thread-state:", NEVER_ABORTED_SIGNAL, ThreadImpl;
14128
- var init_chunk_ZGXC7ZLP = __esm(() => {
14129
- init_chunk_5B5TSGU4();
14130
- init_chunk_LKOB5H73();
14358
+ }, INLINE_MARKER_CHARS, TABLE_ROW_RE, TABLE_SEPARATOR_RE, THREAD_STATE_KEY_PREFIX = "thread-state:", neverAbortedSignal, ThreadImpl;
14359
+ var init_chunk_MOZRUO2D = __esm(() => {
14360
+ init_chunk_D5LKW5SX();
14361
+ init_chunk_Y5QSQ2Z3();
14362
+ init_chunk_5S562BSE();
14131
14363
  init_dist2();
14132
14364
  init_dist2();
14133
14365
  init_dist3();
@@ -14272,7 +14504,6 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
14272
14504
  }
14273
14505
  };
14274
14506
  THREAD_STATE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
14275
- CALLBACK_TTL_MS = 7 * 24 * 60 * 60 * 1000;
14276
14507
  ChannelImpl = class _ChannelImpl {
14277
14508
  id;
14278
14509
  isDM;
@@ -14604,7 +14835,6 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
14604
14835
  INLINE_MARKER_CHARS = /* @__PURE__ */ new Set(["*", "~", "`", "["]);
14605
14836
  TABLE_ROW_RE = /^\|.*\|$/;
14606
14837
  TABLE_SEPARATOR_RE = /^\|[\s:]*-{1,}[\s:]*(\|[\s:]*-{1,}[\s:]*)*\|$/;
14607
- NEVER_ABORTED_SIGNAL = new AbortController().signal;
14608
14838
  ThreadImpl = class _ThreadImpl {
14609
14839
  id;
14610
14840
  channelId;
@@ -14629,7 +14859,7 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
14629
14859
  this.channelId = config.channelId;
14630
14860
  this.isDM = config.isDM ?? false;
14631
14861
  this.channelVisibility = config.channelVisibility ?? "unknown";
14632
- this.signal = config.signal ?? NEVER_ABORTED_SIGNAL;
14862
+ this.signal = config.signal ?? getNeverAbortedSignal();
14633
14863
  this._isSubscribedContext = config.isSubscribedContext ?? false;
14634
14864
  this._currentMessage = config.currentMessage;
14635
14865
  this._logger = config.logger;
@@ -14671,6 +14901,9 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
14671
14901
  }
14672
14902
  return state;
14673
14903
  }
14904
+ getStateAdapter() {
14905
+ return this._stateAdapter;
14906
+ }
14674
14907
  get recentMessages() {
14675
14908
  return this._recentMessages;
14676
14909
  }
@@ -14801,6 +15034,7 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
14801
15034
  if (message.kind === "stream") {
14802
15035
  const data = message.getPostData();
14803
15036
  const streamOptions = {
15037
+ ...data.options.aiGenerated ? { aiGenerated: true } : {},
14804
15038
  ...data.options.updateIntervalMs !== undefined ? { updateIntervalMs: data.options.updateIntervalMs } : {},
14805
15039
  ...data.options.groupTasks ? { taskDisplayMode: data.options.groupTasks } : {},
14806
15040
  ...data.options.endWith ? { stopBlocks: data.options.endWith } : {},
@@ -15002,7 +15236,7 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15002
15236
  }
15003
15237
  if (raw) {
15004
15238
  this._typingStarted = false;
15005
- const sent = this.createSentMessage(raw.id, { markdown: accumulated }, raw.threadId);
15239
+ const sent = this.createSentMessage(raw.id, withAiGenerated({ markdown: accumulated }, options), raw.threadId);
15006
15240
  if (this._threadHistory) {
15007
15241
  await this._threadHistory.append(this.id, new Message3(sent));
15008
15242
  }
@@ -15053,13 +15287,18 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15053
15287
  return;
15054
15288
  }
15055
15289
  async startTyping(status) {
15056
- const initiatorUserId = this._currentMessage?.author.userId;
15057
- if (initiatorUserId) {
15058
- await this.adapter.startTyping(this.id, status, { initiatorUserId });
15059
- this._typingStarted = true;
15060
- return;
15290
+ const options = {};
15291
+ if (this._currentMessage?.author.userId) {
15292
+ options.initiatorUserId = this._currentMessage.author.userId;
15293
+ }
15294
+ if (this._currentMessage?.id) {
15295
+ options.messageId = this._currentMessage.id;
15296
+ }
15297
+ if (options.initiatorUserId || options.messageId) {
15298
+ await this.adapter.startTyping(this.id, status, options);
15299
+ } else {
15300
+ await this.adapter.startTyping(this.id, status);
15061
15301
  }
15062
- await this.adapter.startTyping(this.id, status);
15063
15302
  this._typingStarted = true;
15064
15303
  }
15065
15304
  async finishTyping(status = "active") {
@@ -15115,9 +15354,7 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15115
15354
  const content = renderer.render();
15116
15355
  if (content.trim() && content !== lastEditContent) {
15117
15356
  try {
15118
- await this.adapter.editMessage(threadIdForEdits, msg.id, {
15119
- markdown: content
15120
- });
15357
+ await this.adapter.editMessage(threadIdForEdits, msg.id, withAiGenerated({ markdown: content }, options));
15121
15358
  lastEditContent = content;
15122
15359
  } catch (error) {
15123
15360
  this._logger?.warn("fallbackStream edit failed", error);
@@ -15136,9 +15373,7 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15136
15373
  if (!msg) {
15137
15374
  const content = renderer.render();
15138
15375
  if (content.trim()) {
15139
- msg = await this.adapter.postMessage(this.id, {
15140
- markdown: content
15141
- });
15376
+ msg = await this.adapter.postMessage(this.id, withAiGenerated({ markdown: content }, options));
15142
15377
  threadIdForEdits = msg.threadId || this.id;
15143
15378
  lastEditContent = content;
15144
15379
  scheduleNextEdit();
@@ -15158,18 +15393,14 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15158
15393
  const accumulated = renderer.getText();
15159
15394
  const finalContent = renderer.finish();
15160
15395
  if (!msg) {
15161
- msg = await this.adapter.postMessage(this.id, {
15162
- markdown: accumulated.trim() ? accumulated : " "
15163
- });
15396
+ msg = await this.adapter.postMessage(this.id, withAiGenerated({ markdown: accumulated.trim() ? accumulated : " " }, options));
15164
15397
  threadIdForEdits = msg.threadId || this.id;
15165
15398
  lastEditContent = accumulated;
15166
15399
  }
15167
15400
  if (finalContent.trim() && finalContent !== lastEditContent) {
15168
- await this.adapter.editMessage(threadIdForEdits, msg.id, {
15169
- markdown: accumulated
15170
- });
15401
+ await this.adapter.editMessage(threadIdForEdits, msg.id, withAiGenerated({ markdown: accumulated }, options));
15171
15402
  }
15172
- const sent = this.createSentMessage(msg.id, { markdown: accumulated }, threadIdForEdits);
15403
+ const sent = this.createSentMessage(msg.id, withAiGenerated({ markdown: accumulated }, options), threadIdForEdits);
15173
15404
  if (this._threadHistory) {
15174
15405
  await this._threadHistory.append(this.id, new Message3(sent));
15175
15406
  }
@@ -15324,19 +15555,19 @@ var init_chunk_ZGXC7ZLP = __esm(() => {
15324
15555
  };
15325
15556
  });
15326
15557
 
15327
- // node_modules/chat/dist/chunk-NHNHX3US.js
15558
+ // node_modules/chat/dist/chunk-SJYUIZC4.js
15328
15559
  import { AsyncLocalStorage } from "async_hooks";
15329
15560
  function runInConversation(threadId, fn) {
15330
- return threadId === undefined ? fn() : conversationStorage.run(threadId, fn);
15561
+ return conversationStorage.run(threadId ?? null, fn);
15331
15562
  }
15332
15563
  var conversationStorage;
15333
- var init_chunk_NHNHX3US = __esm(() => {
15564
+ var init_chunk_SJYUIZC4 = __esm(() => {
15334
15565
  conversationStorage = new AsyncLocalStorage;
15335
15566
  });
15336
15567
 
15337
- // node_modules/chat/dist/chunk-YUZG5S7P.js
15338
- var init_chunk_YUZG5S7P = __esm(() => {
15339
- init_chunk_NHNHX3US();
15568
+ // node_modules/chat/dist/chunk-ZNX7PRK5.js
15569
+ var init_chunk_ZNX7PRK5 = __esm(() => {
15570
+ init_chunk_SJYUIZC4();
15340
15571
  });
15341
15572
 
15342
15573
  // node_modules/chat/dist/chunk-BPCHXMC3.js
@@ -15396,6 +15627,16 @@ function sleepUntilAbort(ms, signal) {
15396
15627
  signal.addEventListener("abort", done, { once: true });
15397
15628
  });
15398
15629
  }
15630
+ function callbackOrigin(url) {
15631
+ try {
15632
+ return new URL(url).origin;
15633
+ } catch {
15634
+ return "[invalid URL]";
15635
+ }
15636
+ }
15637
+ function modalStaysOpen(response) {
15638
+ return response?.action === "errors" || response?.action === "update" || response?.action === "push";
15639
+ }
15399
15640
  function getEmoji2(name) {
15400
15641
  let emojiValue = emojiRegistry.get(name);
15401
15642
  if (!emojiValue) {
@@ -15423,6 +15664,8 @@ function convertEmojiPlaceholders2(text2, platform, resolver = defaultEmojiResol
15423
15664
  return resolver.toGChat(emojiName);
15424
15665
  case "github":
15425
15666
  return resolver.toGChat(emojiName);
15667
+ case "gitlab":
15668
+ return resolver.toGChat(emojiName);
15426
15669
  case "linear":
15427
15670
  return resolver.toGChat(emojiName);
15428
15671
  case "notion":
@@ -16015,10 +16258,26 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16015
16258
  this.directMessageHandlers.push(handler);
16016
16259
  this.logger.debug("Registered direct message handler");
16017
16260
  }
16018
- onNewMessage(pattern, handler) {
16019
- this.messagePatterns.push({ pattern, handler });
16261
+ onNewMessage(patternOrHandler, handler) {
16262
+ if (typeof patternOrHandler === "function") {
16263
+ if (handler !== undefined) {
16264
+ throw new ChatError("onNewMessage received a handler as its first argument and an extra second argument. Pass the pattern first: onNewMessage(pattern, handler), or only a handler: onNewMessage(handler).", "INVALID_PATTERN");
16265
+ }
16266
+ this.messagePatterns.push({ handler: patternOrHandler });
16267
+ this.logger.debug("Registered message pattern handler", {
16268
+ pattern: "unfiltered"
16269
+ });
16270
+ return;
16271
+ }
16272
+ if (!(patternOrHandler instanceof RegExp)) {
16273
+ throw new ChatError(`onNewMessage expects a RegExp or a handler function as its first argument, received ${typeof patternOrHandler}`, "INVALID_PATTERN");
16274
+ }
16275
+ if (typeof handler !== "function") {
16276
+ throw new ChatError(`onNewMessage(pattern, handler) requires a handler function, received ${typeof handler}`, "INVALID_HANDLER");
16277
+ }
16278
+ this.messagePatterns.push({ pattern: patternOrHandler, handler });
16020
16279
  this.logger.debug("Registered message pattern handler", {
16021
- pattern: pattern.toString()
16280
+ pattern: patternOrHandler.toString()
16022
16281
  });
16023
16282
  }
16024
16283
  onMessageUpdated(handler) {
@@ -16233,19 +16492,21 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16233
16492
  ...this.optionsLoadHandlers.filter(({ actionIds }) => actionIds.length > 0 && actionIds.includes(event.actionId)),
16234
16493
  ...this.optionsLoadHandlers.filter(({ actionIds }) => actionIds.length === 0)
16235
16494
  ];
16236
- for (const { handler } of matchingHandlers) {
16237
- try {
16238
- const options = await handler(event);
16239
- if (options) {
16240
- return options;
16495
+ return await runInConversation(undefined, async () => {
16496
+ for (const { handler } of matchingHandlers) {
16497
+ try {
16498
+ const options = await handler(event);
16499
+ if (options) {
16500
+ return options;
16501
+ }
16502
+ } catch (err) {
16503
+ this.logger.error("Options load handler error", {
16504
+ error: err,
16505
+ actionId: event.actionId
16506
+ });
16241
16507
  }
16242
- } catch (err) {
16243
- this.logger.error("Options load handler error", {
16244
- error: err,
16245
- actionId: event.actionId
16246
- });
16247
16508
  }
16248
- }
16509
+ });
16249
16510
  }
16250
16511
  async processModalSubmit(event, contextId, options) {
16251
16512
  const { callbackUrl, relatedThread, relatedMessage, relatedChannel } = await this.retrieveModalContext(event.adapter.name, contextId);
@@ -16274,8 +16535,15 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16274
16535
  }
16275
16536
  return;
16276
16537
  };
16277
- const result = await runInConversation(conversationId, runHandlers);
16278
- if (callbackUrl && result?.action !== "errors") {
16538
+ let result;
16539
+ try {
16540
+ result = await runInConversation(conversationId, runHandlers);
16541
+ } finally {
16542
+ if (!modalStaysOpen(result)) {
16543
+ await this.deleteModalContext(event.adapter.name, contextId);
16544
+ }
16545
+ }
16546
+ if (callbackUrl && result?.action !== "errors" && await this.claimModalCallback(event.adapter.name, contextId)) {
16279
16547
  const task = postToCallbackUrl(callbackUrl, {
16280
16548
  type: "modal_submit",
16281
16549
  callbackId: event.callbackId,
@@ -16284,13 +16552,13 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16284
16552
  }).then(({ error }) => {
16285
16553
  if (error) {
16286
16554
  this.logger.error("Modal callbackUrl POST failed", {
16287
- callbackUrl,
16555
+ callbackOrigin: callbackOrigin(callbackUrl),
16288
16556
  error
16289
16557
  });
16290
16558
  }
16291
16559
  }).catch((error) => {
16292
16560
  this.logger.error("Modal callbackUrl POST failed", {
16293
- callbackUrl,
16561
+ callbackOrigin: callbackOrigin(callbackUrl),
16294
16562
  error
16295
16563
  });
16296
16564
  });
@@ -16317,7 +16585,11 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16317
16585
  }
16318
16586
  }
16319
16587
  };
16320
- await runInConversation(conversationId, runHandlers);
16588
+ try {
16589
+ await runInConversation(conversationId, runHandlers);
16590
+ } finally {
16591
+ await this.deleteModalContext(event.adapter.name, contextId);
16592
+ }
16321
16593
  })().catch((err) => {
16322
16594
  this.logger.error("Modal close handler error", {
16323
16595
  error: err,
@@ -16384,15 +16656,17 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16384
16656
  options?.waitUntil?.(task);
16385
16657
  }
16386
16658
  async abortTurn(threadId) {
16387
- const localControllers = this.activeTurnControllers.get(threadId);
16659
+ const adapter = this.resolveAdapterForThread(threadId);
16660
+ const key = this.concurrencyKey(adapter, threadId, this.resolveConcurrencyScope(adapter));
16661
+ const localControllers = this.activeTurnControllers.get(key);
16388
16662
  if (localControllers) {
16389
16663
  for (const controller of localControllers.values()) {
16390
16664
  controller.abort();
16391
16665
  }
16392
16666
  }
16393
- const activeTurnId = await this._stateAdapter.get(this.activeTurnKey(threadId));
16667
+ const activeTurnId = await this._stateAdapter.get(this.activeTurnKey(key));
16394
16668
  if (activeTurnId) {
16395
- await this._stateAdapter.set(this.abortTurnKey(threadId), activeTurnId, ACTIVE_TURN_TTL_MS);
16669
+ await this._stateAdapter.set(this.abortTurnKey(key), activeTurnId, ACTIVE_TURN_TTL_MS);
16396
16670
  }
16397
16671
  }
16398
16672
  processAssistantContextChanged(event, options) {
@@ -16566,26 +16840,40 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16566
16840
  });
16567
16841
  }
16568
16842
  }
16843
+ async deleteModalContext(adapterName, contextId) {
16844
+ if (!contextId) {
16845
+ return;
16846
+ }
16847
+ try {
16848
+ await this._stateAdapter.delete(`modal-context:${adapterName}:${contextId}`);
16849
+ } catch (err) {
16850
+ this.logger.error("Failed to delete modal context", {
16851
+ contextId,
16852
+ error: err
16853
+ });
16854
+ }
16855
+ }
16856
+ async claimModalCallback(adapterName, contextId) {
16857
+ if (!contextId) {
16858
+ return false;
16859
+ }
16860
+ return await this._stateAdapter.setIfNotExists(`modal-callback:${adapterName}:${contextId}`, true, MODAL_CONTEXT_TTL_MS);
16861
+ }
16569
16862
  async retrieveModalContext(adapterName, contextId) {
16863
+ const empty = {
16864
+ callbackUrl: undefined,
16865
+ relatedThread: undefined,
16866
+ relatedMessage: undefined,
16867
+ relatedChannel: undefined
16868
+ };
16570
16869
  if (!contextId) {
16571
- return {
16572
- callbackUrl: undefined,
16573
- relatedThread: undefined,
16574
- relatedMessage: undefined,
16575
- relatedChannel: undefined
16576
- };
16870
+ return empty;
16577
16871
  }
16578
16872
  const key = `modal-context:${adapterName}:${contextId}`;
16579
16873
  const stored = await this._stateAdapter.get(key);
16580
16874
  if (!stored) {
16581
- return {
16582
- callbackUrl: undefined,
16583
- relatedThread: undefined,
16584
- relatedMessage: undefined,
16585
- relatedChannel: undefined
16586
- };
16875
+ return empty;
16587
16876
  }
16588
- await this._stateAdapter.delete(key);
16589
16877
  const adapter = this.adapters.get(adapterName);
16590
16878
  let relatedThread;
16591
16879
  if (stored.thread) {
@@ -16634,20 +16922,49 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16634
16922
  }
16635
16923
  const actionEvent = resolved ? { ...event, value: resolved.originalValue } : event;
16636
16924
  let callbackUrlPromise;
16637
- if (resolved) {
16925
+ if (resolved && callbackToken) {
16638
16926
  const callbackUrl = resolved.url;
16639
16927
  callbackUrlPromise = (async () => {
16928
+ const user = { id: event.user.userId, name: event.user.userName };
16929
+ let receipt;
16930
+ try {
16931
+ receipt = await createCallbackReceipt(this._stateAdapter, {
16932
+ url: callbackUrl,
16933
+ actionId: resolved.actionId,
16934
+ user,
16935
+ threadId: event.threadId,
16936
+ messageId: event.messageId
16937
+ });
16938
+ } catch (error2) {
16939
+ this.logger.error("Button callbackUrl receipt write failed", {
16940
+ callbackOrigin: callbackOrigin(callbackUrl),
16941
+ actionId: event.actionId,
16942
+ error: error2
16943
+ });
16944
+ try {
16945
+ await restoreCallbackToken(this._stateAdapter, callbackToken, resolved);
16946
+ } catch (restoreError) {
16947
+ this.logger.error("Button callback token restore failed", {
16948
+ callbackOrigin: callbackOrigin(callbackUrl),
16949
+ actionId: event.actionId,
16950
+ error: restoreError
16951
+ });
16952
+ }
16953
+ return;
16954
+ }
16640
16955
  const { error } = await postToCallbackUrl(callbackUrl, {
16641
16956
  type: "action",
16642
16957
  actionId: resolved.actionId,
16643
16958
  value: resolved.originalValue,
16644
- user: { id: event.user.userId, name: event.user.userName },
16959
+ values: event.values,
16960
+ user,
16645
16961
  threadId: event.threadId,
16646
- messageId: event.messageId
16962
+ messageId: event.messageId,
16963
+ receipt
16647
16964
  });
16648
16965
  if (error) {
16649
16966
  this.logger.error("Button callbackUrl POST failed", {
16650
- callbackUrl,
16967
+ callbackOrigin: callbackOrigin(callbackUrl),
16651
16968
  actionId: event.actionId,
16652
16969
  error
16653
16970
  });
@@ -16854,6 +17171,10 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16854
17171
  });
16855
17172
  }
16856
17173
  thread(threadId) {
17174
+ const adapter = this.resolveAdapterForThread(threadId);
17175
+ return this.createThread(adapter, threadId, undefined, false);
17176
+ }
17177
+ resolveAdapterForThread(threadId) {
16857
17178
  const adapterName = threadId.split(":")[0];
16858
17179
  if (!adapterName) {
16859
17180
  throw new ChatError(`Invalid thread ID: ${threadId}`, "INVALID_THREAD_ID");
@@ -16862,7 +17183,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16862
17183
  if (!adapter) {
16863
17184
  throw new ChatError(`Adapter "${adapterName}" not found for thread ID "${threadId}"`, "ADAPTER_NOT_FOUND");
16864
17185
  }
16865
- return this.createThread(adapter, threadId, undefined, false);
17186
+ return adapter;
16866
17187
  }
16867
17188
  inferAdapterFromUserId(userId) {
16868
17189
  if (userId.startsWith("users/")) {
@@ -16912,7 +17233,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16912
17233
  }
16913
17234
  throw new ChatError(`Cannot infer adapter from userId "${userId}". Expected: Slack ("U..."), Teams ("29:..."), Google Chat ("users/..."), Linear (UUID), or Discord/Telegram/GitHub (numeric).`, "UNKNOWN_USER_ID_FORMAT");
16914
17235
  }
16915
- async getLockKey(adapter, threadId) {
17236
+ async getLockKey(adapter, threadId, concurrencyScope) {
16916
17237
  const channelId = adapter.channelIdFromThreadId(threadId);
16917
17238
  let scope;
16918
17239
  if (typeof this._lockScope === "function") {
@@ -16926,7 +17247,13 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16926
17247
  } else {
16927
17248
  scope = this._lockScope ?? adapter.lockScope ?? "thread";
16928
17249
  }
16929
- return scope === "channel" ? channelId : threadId;
17250
+ return this.concurrencyKey(adapter, scope === "channel" ? channelId : threadId, concurrencyScope);
17251
+ }
17252
+ resolveConcurrencyScope(adapter) {
17253
+ return adapter.getConcurrencyScope?.();
17254
+ }
17255
+ concurrencyKey(adapter, key, scope) {
17256
+ return scope === undefined ? key : `concurrency:${JSON.stringify([adapter.name, scope, key])}`;
16930
17257
  }
16931
17258
  handleIncomingMessage(adapter, threadId, message) {
16932
17259
  return runInConversation(threadId, () => this.routeIncomingMessage(adapter, threadId, message));
@@ -16948,11 +17275,12 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16948
17275
  });
16949
17276
  return;
16950
17277
  }
17278
+ const scope = this.resolveConcurrencyScope(adapter);
16951
17279
  if (!deduplicate) {
16952
- await this.dispatchIncomingMessage(adapter, threadId, message);
17280
+ await this.dispatchIncomingMessage(adapter, threadId, message, scope);
16953
17281
  return;
16954
17282
  }
16955
- const dedupeKey = `dedupe:${adapter.name}:${message.id}`;
17283
+ const dedupeKey = this.concurrencyKey(adapter, `dedupe:${adapter.name}:${message.id}`, scope);
16956
17284
  const isFirstProcess = await this._stateAdapter.setIfNotExists(dedupeKey, true, this._dedupeTtlMs);
16957
17285
  if (!isFirstProcess) {
16958
17286
  this.logger.debug("Skipping duplicate message", {
@@ -16961,9 +17289,9 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16961
17289
  });
16962
17290
  return;
16963
17291
  }
16964
- await this.dispatchIncomingMessage(adapter, threadId, message);
17292
+ await this.dispatchIncomingMessage(adapter, threadId, message, scope);
16965
17293
  }
16966
- async dispatchIncomingMessage(adapter, threadId, message) {
17294
+ async dispatchIncomingMessage(adapter, threadId, message, scope) {
16967
17295
  if (adapter.persistThreadHistory || adapter.persistMessageHistory) {
16968
17296
  const channelId = adapter.channelIdFromThreadId(threadId);
16969
17297
  const appends = [this._threadHistory.append(threadId, message)];
@@ -16972,17 +17300,17 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
16972
17300
  }
16973
17301
  await Promise.all(appends);
16974
17302
  }
16975
- const lockKey = await this.getLockKey(adapter, threadId);
17303
+ const lockKey = await this.getLockKey(adapter, threadId, scope);
16976
17304
  const strategy = this._concurrencyStrategy;
16977
17305
  if (strategy === "concurrent") {
16978
- await this.handleConcurrent(adapter, threadId, message);
17306
+ await this.handleConcurrent(adapter, threadId, message, scope);
16979
17307
  return;
16980
17308
  }
16981
17309
  if (strategy === "queue" || strategy === "debounce" || strategy === "burst") {
16982
- await this.handleQueueOrDebounce(adapter, threadId, lockKey, message, strategy);
17310
+ await this.handleQueueOrDebounce(adapter, threadId, lockKey, message, strategy, scope);
16983
17311
  return;
16984
17312
  }
16985
- await this.handleDrop(adapter, threadId, lockKey, message);
17313
+ await this.handleDrop(adapter, threadId, lockKey, message, scope);
16986
17314
  }
16987
17315
  async handleMessageUpdated(adapter, threadId, message, previousMessage) {
16988
17316
  setMessageAdapter(message, adapter);
@@ -17032,7 +17360,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17032
17360
  }
17033
17361
  });
17034
17362
  }
17035
- async handleDrop(adapter, threadId, lockKey, message) {
17363
+ async handleDrop(adapter, threadId, lockKey, message, scope) {
17036
17364
  let lock = await this._stateAdapter.acquireLock(lockKey, DEFAULT_LOCK_TTL_MS);
17037
17365
  if (!lock) {
17038
17366
  const resolution = typeof this._onLockConflict === "function" ? await this._onLockConflict(threadId, message) : this._onLockConflict ?? "drop";
@@ -17057,9 +17385,9 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17057
17385
  lockKey,
17058
17386
  token: lock.token
17059
17387
  });
17060
- await this.withHeldLock(lock, threadId, lockKey, () => this.dispatchToHandlers(adapter, threadId, message));
17388
+ await this.withHeldLock(lock, threadId, lockKey, () => this.dispatchToHandlers(adapter, threadId, message, scope));
17061
17389
  }
17062
- async handleQueueOrDebounce(adapter, threadId, lockKey, message, strategy) {
17390
+ async handleQueueOrDebounce(adapter, threadId, lockKey, message, strategy, scope) {
17063
17391
  const { maxQueueSize, queueEntryTtlMs, onQueueFull, debounceMs } = this._concurrencyConfig;
17064
17392
  const lock = await this._stateAdapter.acquireLock(lockKey, DEFAULT_LOCK_TTL_MS);
17065
17393
  if (!lock) {
@@ -17105,7 +17433,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17105
17433
  messageId: message.id,
17106
17434
  debounceMs
17107
17435
  });
17108
- await this.debounceLoop(heartbeat, adapter, lockKey);
17436
+ await this.debounceLoop(heartbeat, adapter, lockKey, scope);
17109
17437
  } else if (strategy === "burst") {
17110
17438
  await this._stateAdapter.enqueue(lockKey, {
17111
17439
  message,
@@ -17119,15 +17447,15 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17119
17447
  debounceMs
17120
17448
  });
17121
17449
  await sleep(debounceMs);
17122
- await this.drainQueue(heartbeat, adapter, lockKey);
17450
+ await this.drainQueue(heartbeat, adapter, lockKey, scope);
17123
17451
  } else {
17124
- await this.dispatchToHandlers(adapter, threadId, message);
17125
- await this.drainQueue(heartbeat, adapter, lockKey);
17452
+ await this.dispatchToHandlers(adapter, threadId, message, scope);
17453
+ await this.drainQueue(heartbeat, adapter, lockKey, scope);
17126
17454
  }
17127
17455
  });
17128
17456
  }
17129
17457
  async withHeldLock(lock, threadId, lockKey, fn) {
17130
- const heartbeat = this.startLockHeartbeat(lock);
17458
+ const heartbeat = this.startLockHeartbeat(lock, threadId);
17131
17459
  try {
17132
17460
  await fn(heartbeat);
17133
17461
  } finally {
@@ -17136,7 +17464,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17136
17464
  this.logger.debug("Lock released", { threadId, lockKey });
17137
17465
  }
17138
17466
  }
17139
- startLockHeartbeat(lock) {
17467
+ startLockHeartbeat(lock, threadId) {
17140
17468
  const { maxLockLifetimeMs } = this._concurrencyConfig;
17141
17469
  const startedAt = Date.now();
17142
17470
  let stopped = false;
@@ -17150,7 +17478,8 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17150
17478
  if (Date.now() - startedAt >= maxLockLifetimeMs) {
17151
17479
  clearInterval(heartbeat);
17152
17480
  this.logger.warn("Lock heartbeat reached maxLockLifetimeMs — the lock will lapse at its TTL", {
17153
- threadId: lock.threadId,
17481
+ threadId,
17482
+ lockKey: lock.threadId,
17154
17483
  token: lock.token,
17155
17484
  maxLockLifetimeMs
17156
17485
  });
@@ -17165,7 +17494,8 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17165
17494
  clearInterval(heartbeat);
17166
17495
  if (!stopped) {
17167
17496
  this.logger.warn("Lock heartbeat stopped after ownership was lost", {
17168
- threadId: lock.threadId,
17497
+ threadId,
17498
+ lockKey: lock.threadId,
17169
17499
  token: lock.token
17170
17500
  });
17171
17501
  }
@@ -17178,13 +17508,15 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17178
17508
  clearInterval(heartbeat);
17179
17509
  this.logger.warn("Lock lapsed while the heartbeat could not reach the state backend", {
17180
17510
  error,
17181
- threadId: lock.threadId,
17511
+ threadId,
17512
+ lockKey: lock.threadId,
17182
17513
  token: lock.token
17183
17514
  });
17184
17515
  } else {
17185
17516
  this.logger.warn("Lock heartbeat failed", {
17186
17517
  error,
17187
- threadId: lock.threadId,
17518
+ threadId,
17519
+ lockKey: lock.threadId,
17188
17520
  token: lock.token
17189
17521
  });
17190
17522
  }
@@ -17202,7 +17534,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17202
17534
  }
17203
17535
  };
17204
17536
  }
17205
- async debounceLoop(heartbeat, adapter, lockKey) {
17537
+ async debounceLoop(heartbeat, adapter, lockKey, scope) {
17206
17538
  const { debounceMs } = this._concurrencyConfig;
17207
17539
  const skipped = [];
17208
17540
  while (true) {
@@ -17253,14 +17585,14 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17253
17585
  lockKey,
17254
17586
  messageId: latest.message.id
17255
17587
  });
17256
- await runInConversation(messageThreadId, () => this.dispatchToHandlers(adapter, messageThreadId, latest.message, {
17588
+ await runInConversation(messageThreadId, () => this.dispatchToHandlers(adapter, messageThreadId, latest.message, scope, {
17257
17589
  skipped: messageSkipped,
17258
17590
  totalSinceLastHandler: messageSkipped.length + 1
17259
17591
  }));
17260
17592
  skipped.length = 0;
17261
17593
  }
17262
17594
  }
17263
- async drainQueue(heartbeat, adapter, lockKey) {
17595
+ async drainQueue(heartbeat, adapter, lockKey, scope) {
17264
17596
  while (true) {
17265
17597
  if (heartbeat.isOwnershipLost()) {
17266
17598
  this.logger.warn("Stopping queue drain after lock ownership was lost", {
@@ -17305,20 +17637,21 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17305
17637
  skipped,
17306
17638
  totalSinceLastHandler: skipped.length + 1
17307
17639
  };
17308
- await runInConversation(messageThreadId, () => this.dispatchToHandlers(adapter, messageThreadId, latest.message, context));
17640
+ await runInConversation(messageThreadId, () => this.dispatchToHandlers(adapter, messageThreadId, latest.message, scope, context));
17309
17641
  }
17310
17642
  }
17311
- async handleConcurrent(adapter, threadId, message) {
17643
+ async handleConcurrent(adapter, threadId, message, scope) {
17312
17644
  const { maxConcurrent } = this._concurrencyConfig;
17313
17645
  if (!Number.isFinite(maxConcurrent)) {
17314
- await this.dispatchToHandlers(adapter, threadId, message);
17646
+ await this.dispatchToHandlers(adapter, threadId, message, scope);
17315
17647
  return;
17316
17648
  }
17317
- await this.acquireConcurrentSlot(threadId, maxConcurrent);
17649
+ const key = this.concurrencyKey(adapter, threadId, scope);
17650
+ await this.acquireConcurrentSlot(key, maxConcurrent);
17318
17651
  try {
17319
- await this.dispatchToHandlers(adapter, threadId, message);
17652
+ await this.dispatchToHandlers(adapter, threadId, message, scope);
17320
17653
  } finally {
17321
- this.releaseConcurrentSlot(threadId);
17654
+ this.releaseConcurrentSlot(key);
17322
17655
  }
17323
17656
  }
17324
17657
  acquireConcurrentSlot(threadId, maxConcurrent) {
@@ -17350,18 +17683,19 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17350
17683
  this._concurrentSlots.delete(threadId);
17351
17684
  }
17352
17685
  }
17353
- async dispatchToHandlers(adapter, threadId, message, context) {
17686
+ async dispatchToHandlers(adapter, threadId, message, scope, context) {
17354
17687
  const turnId = randomUUID();
17355
17688
  const controller = new AbortController;
17356
- let controllers = this.activeTurnControllers.get(threadId);
17689
+ const key = this.concurrencyKey(adapter, threadId, scope);
17690
+ let controllers = this.activeTurnControllers.get(key);
17357
17691
  if (!controllers) {
17358
17692
  controllers = /* @__PURE__ */ new Map;
17359
- this.activeTurnControllers.set(threadId, controllers);
17693
+ this.activeTurnControllers.set(key, controllers);
17360
17694
  }
17361
17695
  controllers.set(turnId, controller);
17362
17696
  if (adapter.supportsTurnCancellation) {
17363
17697
  try {
17364
- await this._stateAdapter.set(this.activeTurnKey(threadId), turnId, ACTIVE_TURN_TTL_MS);
17698
+ await this._stateAdapter.set(this.activeTurnKey(key), turnId, ACTIVE_TURN_TTL_MS);
17365
17699
  } catch (error) {
17366
17700
  this.logger.warn("Could not publish active turn for cancellation", {
17367
17701
  error,
@@ -17370,7 +17704,7 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17370
17704
  }
17371
17705
  }
17372
17706
  const monitorStop = new AbortController;
17373
- const monitor = adapter.supportsTurnCancellation ? this.monitorTurnAbort(threadId, turnId, controller, monitorStop.signal) : Promise.resolve();
17707
+ const monitor = adapter.supportsTurnCancellation ? this.monitorTurnAbort(threadId, key, turnId, controller, monitorStop.signal) : Promise.resolve();
17374
17708
  try {
17375
17709
  await this.dispatchToHandlersWithSignal(adapter, threadId, message, controller.signal, context);
17376
17710
  } finally {
@@ -17378,10 +17712,10 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17378
17712
  await monitor;
17379
17713
  controllers.delete(turnId);
17380
17714
  if (controllers.size === 0) {
17381
- this.activeTurnControllers.delete(threadId);
17715
+ this.activeTurnControllers.delete(key);
17382
17716
  }
17383
17717
  if (adapter.supportsTurnCancellation) {
17384
- await this.clearTurnMarkers(threadId, turnId);
17718
+ await this.clearTurnMarkers(threadId, key, turnId);
17385
17719
  }
17386
17720
  }
17387
17721
  }
@@ -17391,10 +17725,10 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17391
17725
  abortTurnKey(threadId) {
17392
17726
  return `abort-turn:${threadId}`;
17393
17727
  }
17394
- async monitorTurnAbort(threadId, turnId, controller, stopSignal) {
17728
+ async monitorTurnAbort(threadId, turnKey, turnId, controller, stopSignal) {
17395
17729
  while (!(stopSignal.aborted || controller.signal.aborted)) {
17396
17730
  try {
17397
- const abortedTurnId = await this._stateAdapter.get(this.abortTurnKey(threadId));
17731
+ const abortedTurnId = await this._stateAdapter.get(this.abortTurnKey(turnKey));
17398
17732
  if (abortedTurnId === turnId) {
17399
17733
  controller.abort();
17400
17734
  return;
@@ -17411,15 +17745,15 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17411
17745
  }
17412
17746
  }
17413
17747
  }
17414
- async clearTurnMarkers(threadId, turnId) {
17748
+ async clearTurnMarkers(threadId, turnKey, turnId) {
17415
17749
  try {
17416
- const activeTurnId = await this._stateAdapter.get(this.activeTurnKey(threadId));
17750
+ const activeTurnId = await this._stateAdapter.get(this.activeTurnKey(turnKey));
17417
17751
  if (activeTurnId === turnId) {
17418
- await this._stateAdapter.delete(this.activeTurnKey(threadId));
17752
+ await this._stateAdapter.delete(this.activeTurnKey(turnKey));
17419
17753
  }
17420
- const abortedTurnId = await this._stateAdapter.get(this.abortTurnKey(threadId));
17754
+ const abortedTurnId = await this._stateAdapter.get(this.abortTurnKey(turnKey));
17421
17755
  if (abortedTurnId === turnId) {
17422
- await this._stateAdapter.delete(this.abortTurnKey(threadId));
17756
+ await this._stateAdapter.delete(this.abortTurnKey(turnKey));
17423
17757
  }
17424
17758
  } catch (error) {
17425
17759
  this.logger.warn("Could not clear turn cancellation state", {
@@ -17471,20 +17805,24 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17471
17805
  }
17472
17806
  this.logger.debug("Checking message patterns", {
17473
17807
  patternCount: this.messagePatterns.length,
17474
- patterns: this.messagePatterns.map((p) => p.pattern.toString()),
17808
+ patterns: this.messagePatterns.map((p) => p.pattern?.toString() ?? "unfiltered"),
17475
17809
  messageText: message.text
17476
17810
  });
17477
17811
  let matchedPattern = false;
17478
17812
  for (const { pattern, handler } of this.messagePatterns) {
17479
- const matches = pattern.test(message.text);
17813
+ if (pattern?.global || pattern?.sticky) {
17814
+ pattern.lastIndex = 0;
17815
+ }
17816
+ const matches = !pattern || pattern.test(message.text);
17817
+ const patternLabel = pattern?.toString() ?? "unfiltered";
17480
17818
  this.logger.debug("Pattern test", {
17481
- pattern: pattern.toString(),
17819
+ pattern: patternLabel,
17482
17820
  text: message.text,
17483
17821
  matches
17484
17822
  });
17485
17823
  if (matches) {
17486
17824
  this.logger.debug("Message matched pattern - calling handler", {
17487
- pattern: pattern.toString()
17825
+ pattern: patternLabel
17488
17826
  });
17489
17827
  matchedPattern = true;
17490
17828
  await handler(thread, message, context);
@@ -17697,12 +18035,13 @@ var DEFAULT_MAX_THREADS = 5, THREAD_FETCH_CONCURRENCY = 4, ChannelHistoryApiImpl
17697
18035
  this.buildReverseMaps();
17698
18036
  }
17699
18037
  }, defaultEmojiResolver2, EMOJI_PLACEHOLDER_REGEX, emoji, cardChildToFallbackText2, isCardElement2, isJSX2, toModalElement2;
17700
- var init_dist4 = __esm(() => {
17701
- init_chunk_ZGXC7ZLP();
17702
- init_chunk_5B5TSGU4();
17703
- init_chunk_YUZG5S7P();
17704
- init_chunk_LKOB5H73();
17705
- init_chunk_NHNHX3US();
18038
+ var init_dist8 = __esm(() => {
18039
+ init_chunk_MOZRUO2D();
18040
+ init_chunk_D5LKW5SX();
18041
+ init_chunk_ZNX7PRK5();
18042
+ init_chunk_Y5QSQ2Z3();
18043
+ init_chunk_5S562BSE();
18044
+ init_chunk_SJYUIZC4();
17706
18045
  init_chunk_BPCHXMC3();
17707
18046
  DURATION_RE = /^(\d+)([smhd])$/;
17708
18047
  MS_PER_UNIT = {
@@ -17836,4 +18175,4 @@ var init_dist4 = __esm(() => {
17836
18175
  toModalElement2 = toModalElement;
17837
18176
  });
17838
18177
 
17839
- export { isTextNode2, isParagraphNode2, isStrongNode2, isEmphasisNode2, isDeleteNode2, isInlineCodeNode2, isCodeNode2, isLinkNode2, isBlockquoteNode2, isListNode2, isTableNode2, tableToAscii2, tableElementToAscii2, chartElementToFallbackText2, getNodeChildren2, parseMarkdown2, stringifyMarkdown2, toPlainText2, markdownToPlainText2, walkAst2, BaseFormatConverter2, Message3, NotImplementedError3, ConsoleLogger2, StreamingMarkdownRenderer2, Chat2, getEmoji2, defaultEmojiResolver2, convertEmojiPlaceholders2, cardChildToFallbackText2, isCardElement2, isJSX2, toModalElement2, init_dist4 };
18178
+ export { isTextNode2, isParagraphNode2, isStrongNode2, isEmphasisNode2, isDeleteNode2, isInlineCodeNode2, isCodeNode2, isLinkNode2, isBlockquoteNode2, isListNode2, isTableNode2, tableToAscii2, tableElementToAscii2, chartElementToFallbackText2, getNodeChildren2, parseMarkdown2, stringifyMarkdown2, toPlainText2, markdownToPlainText2, walkAst2, BaseFormatConverter2, Message3, NotImplementedError3, ConsoleLogger2, StreamingMarkdownRenderer2, Chat2, getEmoji2, defaultEmojiResolver2, convertEmojiPlaceholders2, cardChildToFallbackText2, isCardElement2, isJSX2, toModalElement2, init_dist8 };