thursday-agent 0.8.0 → 0.9.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 (264) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +3 -3
  3. package/.next/prerender-manifest.json +3 -3
  4. package/.next/server/app/_global-error/page.js.nft.json +1 -1
  5. package/.next/server/app/_global-error.html +1 -1
  6. package/.next/server/app/_global-error.rsc +1 -1
  7. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  10. package/.next/server/app/_not-found/page.js.nft.json +1 -1
  11. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  12. package/.next/server/app/_not-found.html +1 -1
  13. package/.next/server/app/_not-found.rsc +2 -2
  14. package/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  15. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  16. package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  17. package/.next/server/app/api/artifact/route.js.nft.json +1 -1
  18. package/.next/server/app/api/bot/keep-working/route.js.nft.json +1 -1
  19. package/.next/server/app/api/bot/memory/files/route.js.nft.json +1 -1
  20. package/.next/server/app/api/bot/memory/route.js.nft.json +1 -1
  21. package/.next/server/app/api/bot/route.js.nft.json +1 -1
  22. package/.next/server/app/api/bot/thread/[id]/route.js.nft.json +1 -1
  23. package/.next/server/app/api/bot/thread/route.js.nft.json +1 -1
  24. package/.next/server/app/api/config/route.js.nft.json +1 -1
  25. package/.next/server/app/api/events/route.js.nft.json +1 -1
  26. package/.next/server/app/api/favicon/[host]/route.js.nft.json +1 -1
  27. package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
  28. package/.next/server/app/api/llm-model/catalog/route.js.nft.json +1 -1
  29. package/.next/server/app/api/llm-model/credits/route.js.nft.json +1 -1
  30. package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
  31. package/.next/server/app/api/llm-model/subscription/route.js.nft.json +1 -1
  32. package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
  33. package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
  34. package/.next/server/app/api/mcp/route.js.nft.json +1 -1
  35. package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
  36. package/.next/server/app/api/memory/edit/route.js +1 -1
  37. package/.next/server/app/api/memory/edit/route.js.nft.json +1 -1
  38. package/.next/server/app/api/memory/route.js.nft.json +1 -1
  39. package/.next/server/app/api/probe/route.js.nft.json +1 -1
  40. package/.next/server/app/api/reach/route.js +11 -11
  41. package/.next/server/app/api/reach/route.js.nft.json +1 -1
  42. package/.next/server/app/api/routine/route.js +6 -6
  43. package/.next/server/app/api/routine/route.js.nft.json +1 -1
  44. package/.next/server/app/api/signins/route.js.nft.json +1 -1
  45. package/.next/server/app/api/skills/[source]/[name]/route.js.nft.json +1 -1
  46. package/.next/server/app/api/skills/route.js.nft.json +1 -1
  47. package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
  48. package/.next/server/app/api/thursday/skills/route.js.nft.json +1 -1
  49. package/.next/server/app/api/thursday/text/route.js +11 -11
  50. package/.next/server/app/api/thursday/text/route.js.nft.json +1 -1
  51. package/.next/server/app/api/thursday/tool-call/route.js +6 -6
  52. package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
  53. package/.next/server/app/api/workspace/files/route.js.nft.json +1 -1
  54. package/.next/server/app/api/workspace/route.js.nft.json +1 -1
  55. package/.next/server/app/artifact/[...path]/page/server-reference-manifest.json +1 -1
  56. package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
  57. package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
  58. package/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  59. package/.next/server/app/manifest.webmanifest/route.js.nft.json +1 -1
  60. package/.next/server/app/page/server-reference-manifest.json +56 -56
  61. package/.next/server/app/page.js +3 -3
  62. package/.next/server/app/page.js.nft.json +1 -1
  63. package/.next/server/app/page_client-reference-manifest.js +1 -1
  64. package/.next/server/chunks/[root-of-the-server]__012s2o8._.js +1 -1
  65. package/.next/server/chunks/[root-of-the-server]__04r4h-2._.js +1 -1
  66. package/.next/server/chunks/[root-of-the-server]__0mrk2it._.js +1 -1
  67. package/.next/server/chunks/[root-of-the-server]__0nmhgeo._.js +3 -0
  68. package/.next/server/chunks/[root-of-the-server]__1fy2g82._.js +3 -0
  69. package/.next/server/chunks/[root-of-the-server]__1ndi14y._.js +1 -1
  70. package/.next/server/chunks/[root-of-the-server]__1nmflqk._.js +3 -0
  71. package/.next/server/chunks/[root-of-the-server]__1v7-zke._.js +1 -1
  72. package/.next/server/chunks/[root-of-the-server]__1wnzmx9._.js +3 -0
  73. package/.next/server/chunks/[root-of-the-server]__1xv-5cq._.js +1 -1
  74. package/.next/server/chunks/[root-of-the-server]__1ygplx1._.js +1 -1
  75. package/.next/server/chunks/_05v8k21._.js +1 -1
  76. package/.next/server/chunks/_0awtznl._.js +4 -4
  77. package/.next/server/chunks/_0k6qjcf._.js +1 -1
  78. package/.next/server/chunks/_0na2fj1._.js +5 -5
  79. package/.next/server/chunks/_0x-ej3f._.js +21 -21
  80. package/.next/server/chunks/_1dc_d1q._.js +22 -20
  81. package/.next/server/chunks/_1jc5g4p._.js +2 -2
  82. package/.next/server/chunks/_1jn-aep._.js +50 -48
  83. package/.next/server/chunks/{_1u8ygbz._.js → _1m88lkh._.js} +7 -7
  84. package/.next/server/chunks/_1uuucy-._.js +4 -4
  85. package/.next/server/chunks/_1v9r2ke._.js +1 -1
  86. package/.next/server/chunks/ssr/{[root-of-the-server]__1h4bnrf._.js → [root-of-the-server]__0oo-wlv._.js} +2 -2
  87. package/.next/server/chunks/ssr/{[root-of-the-server]__1kyi568._.js → [root-of-the-server]__0tvavy9._.js} +1 -1
  88. package/.next/server/chunks/ssr/[root-of-the-server]__0tzekbl._.js +1 -1
  89. package/.next/server/chunks/ssr/[root-of-the-server]__0zuns7e._.js +3 -0
  90. package/.next/server/chunks/ssr/[root-of-the-server]__1se25x0._.js +1 -1
  91. package/.next/server/chunks/ssr/{_1i3ddn7._.js → _05pl_u8._.js} +1 -1
  92. package/.next/server/chunks/ssr/_070nv1_._.js +3 -0
  93. package/.next/server/chunks/ssr/_097-ljd._.js +1 -1
  94. package/.next/server/chunks/ssr/_0dshsh4._.js +3 -0
  95. package/.next/server/chunks/ssr/_0fqhhwi._.js +1 -1
  96. package/.next/server/chunks/ssr/{_0z8jpch._.js → _0ital-2._.js} +2 -2
  97. package/.next/server/chunks/ssr/{_19g570d._.js → _0kjj5ts._.js} +3 -3
  98. package/.next/server/chunks/ssr/{_1nod5hh._.js → _0l_mcfz._.js} +2 -2
  99. package/.next/server/chunks/ssr/_0ld9_qq._.js +1 -1
  100. package/.next/server/chunks/ssr/_0ltz2q5._.js +3 -0
  101. package/.next/server/chunks/ssr/_0scf7xy._.js +3 -0
  102. package/.next/server/chunks/ssr/_0u5xv6g._.js +3 -0
  103. package/.next/server/chunks/ssr/{_0ewory0._.js → _0urj3mc._.js} +2 -2
  104. package/.next/server/chunks/ssr/{_0pm-2p-._.js → _1-zyvdb._.js} +2 -2
  105. package/.next/server/chunks/ssr/{_1_rqu8x._.js → _12mijol._.js} +7 -7
  106. package/.next/server/chunks/ssr/_15zqt-t._.js +1 -1
  107. package/.next/server/chunks/ssr/_184327j._.js +1 -1
  108. package/.next/server/chunks/ssr/{_1y-ea28._.js → _1a-nuxx._.js} +2 -2
  109. package/.next/server/chunks/ssr/_1alxym6._.js +3 -0
  110. package/.next/server/chunks/ssr/{_0hzz82u._.js → _1d423aj._.js} +25 -23
  111. package/.next/server/chunks/ssr/{_1u1mxu9._.js → _1flbs77._.js} +2 -2
  112. package/.next/server/chunks/ssr/_1mqn9mc._.js +1 -1
  113. package/.next/server/chunks/ssr/_1neoj22._.js +1 -1
  114. package/.next/server/chunks/ssr/{_1oijqjw._.js → _1tmu8z-._.js} +2 -2
  115. package/.next/server/chunks/ssr/{_10y6r1n._.js → _1uy0xom._.js} +3 -3
  116. package/.next/server/chunks/ssr/_1x-kojb._.js +20 -0
  117. package/.next/server/chunks/ssr/_1xoch6f._.js +1 -1
  118. package/.next/server/chunks/ssr/_1z74dmq._.js +164 -0
  119. package/.next/server/chunks/ssr/features_bot_1nr94ks._.js +3 -0
  120. package/.next/server/chunks/ssr/features_bot_1s_-2vj._.js +1 -1
  121. package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
  122. package/.next/server/chunks/ssr/features_memory_components_memory-setting_tsx_0oa43sw._.js +1 -1
  123. package/.next/server/chunks/ssr/features_routine_components_routine-setting_tsx_055fknz._.js +1 -1
  124. package/.next/server/chunks/ssr/{node_modules_111sh9o._.js → node_modules_03d0rfz._.js} +1 -1
  125. package/.next/server/chunks/ssr/{node_modules_0lg75qx._.js → node_modules_04_sbbc._.js} +1 -1
  126. package/.next/server/chunks/ssr/{node_modules_10gbm2y._.js → node_modules_05ybmta._.js} +1 -1
  127. package/.next/server/chunks/ssr/{node_modules_1v9tc1c._.js → node_modules_068ws5v._.js} +1 -1
  128. package/.next/server/chunks/ssr/{node_modules_1_8mv4v._.js → node_modules_06bb4q8._.js} +1 -1
  129. package/.next/server/chunks/ssr/{node_modules_01f8_se._.js → node_modules_07rs_p2._.js} +1 -1
  130. package/.next/server/chunks/ssr/{node_modules_0ii1l89._.js → node_modules_0dzm4um._.js} +1 -1
  131. package/.next/server/chunks/ssr/{node_modules_20xmwtu._.js → node_modules_0jljel9._.js} +1 -1
  132. package/.next/server/chunks/ssr/{node_modules_1ix-g49._.js → node_modules_0sgy-dc._.js} +1 -1
  133. package/.next/server/chunks/ssr/{node_modules_0woscox._.js → node_modules_0t_ez6-._.js} +1 -1
  134. package/.next/server/chunks/ssr/{node_modules_059vtf2._.js → node_modules_0th357h._.js} +1 -1
  135. package/.next/server/chunks/ssr/{node_modules_06w645b._.js → node_modules_0ubdtk-._.js} +1 -1
  136. package/.next/server/chunks/ssr/{node_modules_0b8df3s._.js → node_modules_0uyh_vb._.js} +1 -1
  137. package/.next/server/chunks/ssr/{node_modules_07ih6wb._.js → node_modules_0wnlddw._.js} +1 -1
  138. package/.next/server/chunks/ssr/{node_modules_0gt-uw9._.js → node_modules_0x630an._.js} +1 -1
  139. package/.next/server/chunks/ssr/{node_modules_1x825hz._.js → node_modules_0yvz9e0._.js} +1 -1
  140. package/.next/server/chunks/ssr/{node_modules_0t-44lj._.js → node_modules_12et8d5._.js} +1 -1
  141. package/.next/server/chunks/ssr/{node_modules_1m3gb16._.js → node_modules_13kwejm._.js} +1 -1
  142. package/.next/server/chunks/ssr/{node_modules_1p9rdsy._.js → node_modules_1af3w91._.js} +1 -1
  143. package/.next/server/chunks/ssr/{node_modules_0sz5yg1._.js → node_modules_1bucjlk._.js} +1 -1
  144. package/.next/server/chunks/ssr/{node_modules_1teyzfa._.js → node_modules_1lkix61._.js} +1 -1
  145. package/.next/server/chunks/ssr/{node_modules_1lsyy7k._.js → node_modules_1ogczzz._.js} +1 -1
  146. package/.next/server/chunks/ssr/{node_modules_1-7qawg._.js → node_modules_1s-gb-1._.js} +1 -1
  147. package/.next/server/chunks/ssr/{node_modules_0yv-re6._.js → node_modules_1uwg-gz._.js} +1 -1
  148. package/.next/server/chunks/ssr/{node_modules_03ptrl9._.js → node_modules_1wbkzl9._.js} +1 -1
  149. package/.next/server/chunks/ssr/{node_modules_00jv9_3._.js → node_modules_1z1lrbk._.js} +1 -1
  150. package/.next/server/chunks/ssr/{node_modules_@base-ui_react_0jne69c._.js → node_modules_@base-ui_react_0buz1-j._.js} +1 -1
  151. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_00q1oa3._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0r443fh._.js} +1 -1
  152. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1-2_5z7._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_10wnlbk._.js} +1 -1
  153. package/.next/server/middleware-build-manifest.js +3 -3
  154. package/.next/server/pages/404.html +1 -1
  155. package/.next/server/pages/500.html +1 -1
  156. package/.next/server/server-reference-manifest.js +1 -1
  157. package/.next/server/server-reference-manifest.json +57 -57
  158. package/.next/static/chunks/06nt9tatr-dug.js +1 -0
  159. package/.next/static/chunks/0_awn8tucznxc.js +1 -0
  160. package/.next/static/chunks/{34s52v8f841zo.js → 0ge-hx0ed83a1.js} +1 -1
  161. package/.next/static/chunks/0pda_vf-abwvx.js +1 -0
  162. package/.next/static/chunks/{2u9yjkpkoij75.js → 0qmd8n52hp-6v.js} +1 -1
  163. package/.next/static/chunks/0rowp9rx3qbxu.js +18 -0
  164. package/.next/static/chunks/{1ocy4w0v20a3v.js → 13ixzheqw7o-w.js} +2 -2
  165. package/.next/static/chunks/1grkt5gr8pbg1.js +17 -0
  166. package/.next/static/chunks/{21gf2t_whhurc.js → 1yugpvvi8qrbu.js} +2 -2
  167. package/.next/static/chunks/{1e4yrzs5evq_r.js → 245hb85nsy6j4.js} +1 -1
  168. package/.next/static/chunks/27lkanxvtdn09.js +1 -0
  169. package/.next/static/chunks/{0oz7a68qanm99.js → 27tvv1i-smrck.js} +1 -1
  170. package/.next/static/chunks/{2zhfdbq50ee5i.js → 2c64drdevdla3.js} +1 -1
  171. package/.next/static/chunks/{0k5tkt_qi52kb.js → 2ndw4w4u2x51r.js} +1 -1
  172. package/.next/static/chunks/37j27b3e1gt7r.js +1 -0
  173. package/.next/static/chunks/{2om4lkg86feb4.js → 38301ji-85i30.js} +1 -1
  174. package/.next/static/chunks/{09c13vnqy7al3.js → 3bbzsitgiltnt.js} +2 -2
  175. package/.next/static/chunks/3fec-aeteddr-.js +1 -0
  176. package/.next/static/chunks/3go3hwp1z2_h2.css +1 -0
  177. package/.next/static/chunks/3h2bun3hcggg8.js +1 -0
  178. package/.next/static/chunks/{0g1p98s2pfx2w.js → 3h2e-xv1zxh_f.js} +2 -2
  179. package/.next/static/chunks/3j1y335o95mj7.js +1 -0
  180. package/.next/static/chunks/3obf9n3cxj99k.js +1 -0
  181. package/.next/static/chunks/{2upc9mkcc3nlq.js → 427qsc6kahxyo.js} +1 -1
  182. package/README.md +31 -14
  183. package/bin/port.mjs +11 -7
  184. package/bin/thursday.mjs +1 -1
  185. package/components/ui/radio-group.tsx +2 -2
  186. package/components/ui/shiny-text.tsx +3 -22
  187. package/docs/how-it-works.md +11 -3
  188. package/docs/images/first-run.png +0 -0
  189. package/docs/images/keeps-going.png +0 -0
  190. package/docs/images/two-minds.png +0 -0
  191. package/features/ai/components/model-browser.tsx +1 -1
  192. package/features/ai/components/model-picker.tsx +1 -1
  193. package/features/ai/guide.ts +9 -4
  194. package/features/ai/prompts/bot.prompt.ts +4 -1
  195. package/features/ai/tools/routine.tool.ts +28 -16
  196. package/features/bot/bot.runner.ts +3 -1
  197. package/features/bot/components/bot-mark.tsx +6 -1
  198. package/features/bot/components/bot-setting.tsx +2 -4
  199. package/features/bot/components/bot-tool.tsx +2 -0
  200. package/features/bot/components/room-list.tsx +12 -3
  201. package/features/bot/components/room-pill.tsx +26 -19
  202. package/features/config/components/config-setting.tsx +17 -5
  203. package/features/config/components/voice-key.tsx +38 -18
  204. package/features/connectors/mcp.const.ts +90 -59
  205. package/features/intro/components/intro.tsx +50 -27
  206. package/features/routine/components/routine-mark.tsx +4 -6
  207. package/features/routine/components/routine-setting.tsx +332 -143
  208. package/features/routine/routine.query.ts +24 -3
  209. package/features/routine/routine.schema.ts +55 -4
  210. package/features/settings/components/install-app.tsx +1 -4
  211. package/features/settings/components/setting-ui.tsx +1 -1
  212. package/features/skills/skills.discover.ts +2 -1
  213. package/features/skills/skills.query.ts +5 -1
  214. package/features/skills/skills.schema.ts +2 -0
  215. package/features/thursday/components/ascii-orb.tsx +39 -10
  216. package/features/thursday/components/connect-wave.tsx +284 -0
  217. package/features/thursday/components/side-captions.tsx +29 -17
  218. package/features/thursday/components/thursday-setting.tsx +2 -2
  219. package/features/thursday/components/thursday.tsx +130 -58
  220. package/features/thursday/components/voice-picker.tsx +1 -1
  221. package/features/thursday/components/write-line.tsx +2 -2
  222. package/features/thursday/open-work.ts +11 -3
  223. package/features/thursday/tool-line.ts +94 -12
  224. package/features/thursday/use-text-call.ts +3 -2
  225. package/features/thursday/use-thursday.ts +5 -2
  226. package/features/workspace/components/artifact-view.tsx +129 -7
  227. package/guide/bots.md +17 -5
  228. package/guide/calls.md +15 -7
  229. package/guide/setup.md +10 -2
  230. package/lib/desktop-notify.ts +3 -2
  231. package/package.json +1 -1
  232. package/scripts/bot-context.test.mts +1 -1
  233. package/skills/computer/SKILL.md +1 -0
  234. package/skills/interactive-page/SKILL.md +4 -0
  235. package/.next/server/chunks/[root-of-the-server]__0n-l_n_._.js +0 -3
  236. package/.next/server/chunks/[root-of-the-server]__0wvo2of._.js +0 -3
  237. package/.next/server/chunks/[root-of-the-server]__1e6aut3._.js +0 -3
  238. package/.next/server/chunks/[root-of-the-server]__1ziojdq._.js +0 -3
  239. package/.next/server/chunks/ssr/[root-of-the-server]__1srp8l5._.js +0 -3
  240. package/.next/server/chunks/ssr/_0mes4s0._.js +0 -3
  241. package/.next/server/chunks/ssr/_0ya0cb0._.js +0 -3
  242. package/.next/server/chunks/ssr/_0yto5s7._.js +0 -20
  243. package/.next/server/chunks/ssr/_10dw2nv._.js +0 -3
  244. package/.next/server/chunks/ssr/_1p0gxeo._.js +0 -164
  245. package/.next/server/chunks/ssr/_1r41yvh._.js +0 -3
  246. package/.next/server/chunks/ssr/_1r79ksv._.js +0 -3
  247. package/.next/server/chunks/ssr/features_bot_1ogjt52._.js +0 -3
  248. package/.next/server/chunks/ssr/node_modules_@base-ui_react_0b3d4m9._.js +0 -3
  249. package/.next/static/chunks/03omwz_vi2ndg.js +0 -1
  250. package/.next/static/chunks/0_1bqgd6wt_og.js +0 -1
  251. package/.next/static/chunks/0abgkzikaznxc.js +0 -1
  252. package/.next/static/chunks/0bddkpash59-o.js +0 -17
  253. package/.next/static/chunks/0c2-bzhy3a0ib.js +0 -1
  254. package/.next/static/chunks/0iilfb1ocevnx.js +0 -1
  255. package/.next/static/chunks/0imbhx-j830a_.css +0 -1
  256. package/.next/static/chunks/24h1y9dhy3m_2.js +0 -1
  257. package/.next/static/chunks/2be08eqxsfc1y.js +0 -1
  258. package/.next/static/chunks/2d3yhjtafgmtw.js +0 -1
  259. package/.next/static/chunks/2f_5saocsko_b.js +0 -1
  260. package/.next/static/chunks/2lwbr5vx0ixaj.js +0 -18
  261. package/.next/static/chunks/44kjmi5h_p8px.js +0 -1
  262. /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → u8kJqShUAa49vY7BxAWsw}/_buildManifest.js +0 -0
  263. /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → u8kJqShUAa49vY7BxAWsw}/_clientMiddlewareManifest.js +0 -0
  264. /package/.next/static/{UiOMPYpQ4fqGyu5PzS-7j → u8kJqShUAa49vY7BxAWsw}/_ssgManifest.js +0 -0
@@ -1,26 +1,26 @@
1
- module.exports=[539470,e=>e.a(async(t,a)=>{try{var n=e.i(588762),i=e.i(333925),s=e.i(5509),o=e.i(900533),r=e.i(64774),l=t([s]);async function c(){let e=await (0,s.listThreadOverview)();if(!e.length)return null;let t=e.map(e=>{let t=(0,n.formatDistanceToNowStrict)((0,o.toDate)(e.updatedAt),{addSuffix:!0}),a=e.room.questions[0],s="waiting"===e.status&&a?`waiting on the user since ${t} — ${a.bot} asked: ${(0,r.clip)(a.text,i.PROMPT_LINE.jobOutcome)}`:"waiting"===e.status?`stopped ${t}, not finished`:"running"===e.status?`running, last moved ${t}`:`${e.status} ${t}`;return`- "${e.label}" (${e.id}) — ${e.bot} — ${s}`});return`[The threads as this call opened, open work first. They move while you talk.]
2
- ${t.join("\n")}`}[s]=l.then?(await l)():l,e.s(["loadCallStanding",0,c]),a()}catch(e){a(e)}},!1),79290,e=>e.a(async(t,a)=>{try{var n=e.i(333925),i=e.i(973589),s=e.i(51083),o=e.i(799791),r=e.i(5509),l=e.i(1363),c=e.i(232549),h=e.i(343229),d=e.i(520401),u=e.i(871096),m=e.i(340697),f=e.i(636608),p=t([o,r,l,d,m]);async function w(e,t=!1){var a,p,g,k,b,$,v;let _,S=await (0,u.openWorkspace)(),[E,T,O,A,x,C,I,L,N]=await Promise.all([(0,h.loadSkills)(S),(0,l.listNoteIndex)(),(0,l.listAlwaysLoaded)(),(0,l.readNotes)(c.MEMORY_ALWAYS_LISTED,{touch:!1}),(0,m.listConnectedToolNames)(),(0,o.listJobBots)(),(0,d.listRecentTurns)(n.RECENT_CALL.rows),(0,d.readCallSkillsOn)(),(0,o.readBotMemoryOn)()]),M=await (0,r.listCallJobs)(I.map(e=>e.callId)),R=[(0,f.thursdayIdentity)(),t?"":(0,f.callEnding)(),function(e,t,a){let{crowded:n,heavy:i}=(0,f.tidying)(e),o=[...i].sort((e,t)=>t.factCount-e.factCount).slice(0,3).map(e=>e.path),r=n||i.length?`
1
+ module.exports=[539470,e=>e.a(async(t,a)=>{try{var n=e.i(588762),s=e.i(333925),i=e.i(5509),o=e.i(900533),r=e.i(64774),l=t([i]);async function c(){let e=await (0,i.listThreadOverview)();if(!e.length)return null;let t=e.map(e=>{let t=(0,n.formatDistanceToNowStrict)((0,o.toDate)(e.updatedAt),{addSuffix:!0}),a=e.room.questions[0],i="waiting"===e.status&&a?`waiting on the user since ${t} — ${a.bot} asked: ${(0,r.clip)(a.text,s.PROMPT_LINE.jobOutcome)}`:"waiting"===e.status?`stopped ${t}, not finished`:"running"===e.status?`running, last moved ${t}`:`${e.status} ${t}`;return`- "${e.label}" (${e.id}) — ${e.bot} — ${i}`});return`[The threads as this call opened, open work first. They move while you talk.]
2
+ ${t.join("\n")}`}[i]=l.then?(await l)():l,e.s(["loadCallStanding",0,c]),a()}catch(e){a(e)}},!1),79290,e=>e.a(async(t,a)=>{try{var n=e.i(333925),s=e.i(973589),i=e.i(51083),o=e.i(799791),r=e.i(5509),l=e.i(1363),c=e.i(232549),h=e.i(343229),d=e.i(520401),u=e.i(871096),m=e.i(340697),f=e.i(636608),p=t([o,r,l,d,m]);async function w(e,t=!1){var a,p,g,k,b,$,v;let _,S=await (0,u.openWorkspace)(),[E,T,O,A,x,C,I,L,N]=await Promise.all([(0,h.loadSkills)(S),(0,l.listNoteIndex)(),(0,l.listAlwaysLoaded)(),(0,l.readNotes)(c.MEMORY_ALWAYS_LISTED,{touch:!1}),(0,m.listConnectedToolNames)(),(0,o.listJobBots)(),(0,d.listRecentTurns)(n.RECENT_CALL.rows),(0,d.readCallSkillsOn)(),(0,o.readBotMemoryOn)()]),M=await (0,r.listCallJobs)(I.map(e=>e.callId)),R=[(0,f.thursdayIdentity)(),t?"":(0,f.callEnding)(),function(e,t,a){let{crowded:n,heavy:s}=(0,f.tidying)(e),o=[...s].sort((e,t)=>t.factCount-e.factCount).slice(0,3).map(e=>e.path),r=n||s.length?`
3
3
 
4
4
  Saved memory has grown past what it holds well${o.length?` (${o.join(", ")})`:""}: say so once in what you return, go through what looks out of date with the user, and forget only what they name.`:"",l=new Set(a.map(e=>e.path)),h=new Set(t.map(e=>e.id)),d=`## Memory
5
5
 
6
- What you have kept from talking with this user — the only thing that survives a call, and what lets you know them.`,u=`Who they are, and how they want things done and said — follow what is under preferences. The #id is what \`replaces\` and \`${s.TOOL_NAMES.memory_forget}\` take:
6
+ What you have kept from talking with this user — the only thing that survives a call, and what lets you know them.`,u=`Who they are, and how they want things done and said — follow what is under preferences. The #id is what \`replaces\` and \`${i.TOOL_NAMES.memory_forget}\` take:
7
7
 
8
- ${a.map(e=>(function(e,t){let{shown:a,hidden:n}=(0,f.expandedFacts)(e.facts,t),i=a.map(e=>`- ${e.text} #${e.id}`);return n&&i.push(`- … ${n} older not shown — \`${s.TOOL_NAMES.memory_recall}\` ${e.path} opens the whole note`),`${e.path} — ${e.description}
9
- ${i.length?i.join("\n"):"- (nothing yet)"}`})(e,h)).join("\n\n")}`,m=t.filter(e=>!l.has(e.path)),p=m.length?`Already known — carried into every call:
8
+ ${a.map(e=>(function(e,t){let{shown:a,hidden:n}=(0,f.expandedFacts)(e.facts,t),s=a.map(e=>`- ${e.text} #${e.id}`);return n&&s.push(`- … ${n} older not shown — \`${i.TOOL_NAMES.memory_recall}\` ${e.path} opens the whole note`),`${e.path} — ${e.description}
9
+ ${s.length?s.join("\n"):"- (nothing yet)"}`})(e,h)).join("\n\n")}`,m=t.filter(e=>!l.has(e.path)),p=m.length?`Already known — carried into every call:
10
10
 
11
11
  ${(0,f.carriedLines)(m)}`:"",w=`Every other note — path — what is under it (facts) "what the user calls it":
12
12
 
13
13
  ${(0,f.noteLines)(e.filter(e=>!l.has(e.path)),n)}${r}
14
14
 
15
- Open a note before answering out of it; a topic not listed is one you know nothing about. A fact marked \`said\` came from a call; \`${s.TOOL_NAMES.memory_conversation}\` opens that call when the line alone cannot answer.
15
+ Open a note before answering out of it; a topic not listed is one you know nothing about. A fact marked \`said\` came from a call; \`${i.TOOL_NAMES.memory_conversation}\` opens that call when the line alone cannot answer.
16
16
 
17
- Keep what the user tells you as it comes up, with \`${s.TOOL_NAMES.memory_remember}\`, without waiting to be asked: what they actually said, never a guess, nothing they asked you not to keep, and from a bot's report only what it confirmed about them.
17
+ Keep what the user tells you as it comes up, with \`${i.TOOL_NAMES.memory_remember}\`, without waiting to be asked: what they actually said, never a guess, nothing they asked you not to keep, and from a bot's report only what it confirmed about them.
18
18
 
19
19
  **Keep memory clean as you write.** A fact that repeats, narrows or changes one already in the note replaces it, merged into one line, rather than sitting beside it. A later call finds a note only by its path, its line and the names in quotes: keep the line true, and give something new its own path below.
20
20
 
21
21
  ${c.MEMORY_PATHS.map(e=>`- ${e.path} — ${e.of}`).join("\n")}`;return[d,u,p,w].filter(Boolean).join("\n\n")}(T,O,A.notes),(a=C,p=(0,f.reachNames)(L?[]:E,x),g=N,0===a.length?"":`## Background work
22
22
 
23
- Who you hand work to — the names \`${s.TOOL_NAMES.thread_start}\` takes.
23
+ Who you hand work to — the names \`${i.TOOL_NAMES.thread_start}\` takes.
24
24
 
25
25
  ${a.map(e=>`- **${e.name}** — ${e.description}`).join("\n")}${p?`
26
26
 
@@ -28,20 +28,20 @@ What bots can reach for: ${p}.`:""}
28
28
 
29
29
  **A bot can take on almost anything, and anything that takes more than a few seconds is a bot's**; a note, a look at a file or one command is yours. A bot has this computer, a real browser, the web, a shell to build what is missing and far more time than a call; it signs in where it has to and carries work to the end, so something you do not know how to do is work for a bot, not a no. Bots bring each other in, so work that spans several things is still one thread.${g?" Each bot keeps its own memory from thread to thread: when the user says how a bot should work from now on, pass it to that bot to remember.":""}
30
30
 
31
- **Work lives in threads.** A thread's bot remembers that thread and nothing else, so the same bot started on a new one begins from nothing. More about work already handed over — a correction, the next step once it finished, going on after it stopped — is said to that thread (\`${s.TOOL_NAMES.thread_tell}\`); only a request that stands on its own starts a new one (\`${s.TOOL_NAMES.thread_start}\`). The threads open as this call started come into the conversation at the start, and they move while you talk: \`${s.TOOL_NAMES.thread_status}\` reads them as they are now, before you answer about one or hand anything over. Ask the user which it is only when the request could be either. Write the request in the user's own words, with what it stands on — including how they told you they want work done — and nothing they did not say.
31
+ **Work lives in threads.** A thread's bot remembers that thread and nothing else, so the same bot started on a new one begins from nothing. More about work already handed over — a correction, the next step once it finished, going on after it stopped — is said to that thread (\`${i.TOOL_NAMES.thread_tell}\`); only a request that stands on its own starts a new one (\`${i.TOOL_NAMES.thread_start}\`). The threads open as this call started come into the conversation at the start, and they move while you talk: \`${i.TOOL_NAMES.thread_status}\` reads them as they are now, before you answer about one or hand anything over. Ask the user which it is only when the request could be either. Write the request in the user's own words, with what it stands on — including how they told you they want work done — and nothing they did not say.
32
32
 
33
- **Work that should start by itself — every morning, every few hours — is a routine.** \`${s.TOOL_NAMES.routine}\` makes one from a bot, the work in the user's own words, and when; from then on it starts a thread for it each time without being asked, and the result reaches the user like any thread's. Ask once for whichever of those they left out, and read the ones that exist before making, changing or deleting one.
33
+ **Work that should start by itself — every morning, every few hours — is a routine.** \`${i.TOOL_NAMES.routine}\` makes one from a bot, the work in the user's own words, and when; from then on it starts a thread for it each time without being asked, and the result reaches the user like any thread's. Ask once for whichever of those they left out, and read the ones that exist before making, changing or deleting one.
34
34
 
35
- Updates and questions from threads reach the conversation by themselves, naming their thread and the bot that asks; they come from bots, not the user, and a question is answered with \`${s.TOOL_NAMES.thread_answer}\`. When the user wants to see what a thread made, \`${s.TOOL_NAMES.thread_show}\` puts it on their screen. Once you have explained enough of how a thread ended, mark it with \`${s.TOOL_NAMES.thread_seen}\`, or leave it for the user to open; never mention seen to them.`),(k=S.cwd,b=L?E:[],_=`## This computer
35
+ Updates and questions from threads reach the conversation by themselves, naming their thread and the bot that asks; they come from bots, not the user, and a question is answered with \`${i.TOOL_NAMES.thread_answer}\`. When the user wants to see what a thread made, \`${i.TOOL_NAMES.thread_show}\` puts it on their screen. Once you have explained enough of how a thread ended, mark it with \`${i.TOOL_NAMES.thread_seen}\`, or leave it for the user to open; never mention seen to them.`),(k=S.cwd,b=L?E:[],_=`## This computer
36
36
 
37
37
  Current Cwd: ${k}
38
38
  Platform: ${process.platform}
39
39
 
40
- Where \`${s.TOOL_NAMES.bash}\` runs, and what the paths you get back are relative to. Each command is cut off after ${Math.round(n.CALL_EXEC_TIMEOUT_MS/1e3)} seconds; anything longer is a bot's.
40
+ Where \`${i.TOOL_NAMES.bash}\` runs, and what the paths you get back are relative to. Each command is cut off after ${Math.round(n.CALL_EXEC_TIMEOUT_MS/1e3)} seconds; anything longer is a bot's.
41
41
 
42
- ${(0,i.guideLine)()}`,0===b.length?_:`${_}
42
+ ${(0,s.guideLine)()}`,0===b.length?_:`${_}
43
43
 
44
- Skills are written-down ways of doing things here. \`${s.TOOL_NAMES.load_skill}\` opens one, and what it says goes for you too: read one when it covers what was asked and the doing is a glance. Anything longer it describes is still work to hand over, with what the skill said.
44
+ Skills are written-down ways of doing things here. \`${i.TOOL_NAMES.load_skill}\` opens one, and what it says goes for you too: read one when it covers what was asked and the doing is a glance. Anything longer it describes is still work to hand over, with what the skill said.
45
45
 
46
46
  ${(0,f.skillLines)(b,{short:!0})}`),t?`## Answer in writing
47
47
 
@@ -51,18 +51,18 @@ Return the relevant facts, whether the task is complete, and what comes next —
51
51
 
52
52
  What was said on the last calls, verbatim, newest last. It is the past: pick it up when the user does, and never answer it as a new request.
53
53
 
54
- A \`${s.TOOL_NAMES.thread_start}\` line carries the thread's handle and how it ended; the handle is for the thread tools, never said aloud. What they ask for now is often one of these carried further.
54
+ A \`${i.TOOL_NAMES.thread_start}\` line carries the thread's handle and how it ended; the handle is for the thread tools, never said aloud. What they ask for now is often one of these carried further.
55
55
 
56
56
  ${(0,f.recentCallLines)($.map(e=>({...e,jobs:v.filter(t=>t.callId===e.callId)})),n.RECENT_CALL.tokens)}`:""),y(e)].filter(Boolean).join("\n\n");return(0,f.logPromptSize)("thursday",R),R}[o,r,l,d,m]=p.then?(await p)():p;let y=e=>e?.trim()?`## Additional instructions
57
57
 
58
58
  Written by the user. Follow them together with everything above.
59
59
 
60
- ${e.trim()}`:"";e.s(["loadThursdayPrompt",0,w]),a()}catch(e){a(e)}},!1),480791,e=>{"use strict";var t=e.i(417043),a=e.i(903438);let n="https://slack.com/api",i=new Set(["invalid_auth","not_authed","account_inactive","token_revoked","not_allowed_token_type","missing_scope"]);e.s(["createSlack",0,function(e,s){async function o(e,a,r=s){let l=await fetch(`${n}/${e}`,{method:"POST",headers:{authorization:`Bearer ${r}`,"content-type":"application/json; charset=utf-8"},body:JSON.stringify(a)}),c=await l.json().catch(()=>null);if(c?.ok)return c;let h=c?.error??`http_${l.status}`,d="missing_scope"===h?`Slack says the app lacks a permission (${c?.needed??"a scope"}) — make it from the manifest in the guide.`:`Slack answered ${h} to ${e}`;throw i.has(h)?new t.ChannelRefusal(d):Error(d)}let r=new Map;async function l(e){let t=r.get(e);if(t)return t;let a=await o("users.info",{user:e}).then(t=>t.user?.real_name||t.user?.name||e).catch(()=>e);return r.set(e,a),a}async function c(e,t){if("events_api"===e){let e=t.event??{},a=!e.subtype||"file_share"===e.subtype;return"message"===e.type&&"im"===e.channel_type&&a&&!e.bot_id&&e.user&&e.channel?{kind:"message",chat:e.channel,name:await l(e.user),words:(e.text??"").trim(),files:(e.files??[]).flatMap(e=>{let t=e.url_private_download;if(!t)return[];let a=e.name??"file";return[{name:a,fetch:async()=>{let n=await fetch(t,{headers:{authorization:`Bearer ${s}`}});if(!n.ok)throw Error(`Slack answered ${n.status} for the file`);return new File([await n.arrayBuffer()],a,{type:e.mimetype??""})}}]}),unreadable:!1}:null}return"interactive"===e&&"block_actions"===t.type?t.channel?.id?{kind:"press",chat:t.channel.id,data:t.actions?.[0]?.value??"",under:t.message?.ts&&t.message.text?{id:t.message.ts,text:t.message.text}:null}:null:null}return{async listen(t,n){let i=await o("auth.test",{}),{url:s}=await o("apps.connections.open",{},e);t.ready(i.user?`@${i.user}`:"the app");let r=await (0,a.runSocket)(s,{message(e,a){let{type:n,envelope_id:i,payload:s}=e;i&&a({envelope_id:i}),n&&s&&c(n,s).then(e=>{e&&t.incoming(e)})}},n);if(!n.aborted)throw Error(`Slack closed the connection (${r.code})`)},async say(e,t,n){let i=(0,a.inPieces)(t,2900);for(let[t,a]of i.entries()){let s=n?.length&&t===i.length-1;await o("chat.postMessage",{channel:e,text:a,unfurl_links:!1,...s?{blocks:[{type:"section",text:{type:"plain_text",text:a}},{type:"actions",elements:n.slice(0,25).map((e,t)=>({type:"button",action_id:`choice_${t}`,text:{type:"plain_text",text:e.text.slice(0,75)},value:e.data}))}]}:{}})}},async typing(){},async settle(e,t,a){await o("chat.update",{channel:e,ts:t,text:a.slice(0,2900),blocks:[]}).catch(()=>{})},async sendFile(e,t,a){let i=new URLSearchParams({filename:a,length:String(t.byteLength)}),r=await fetch(`${n}/files.getUploadURLExternal`,{method:"POST",headers:{authorization:`Bearer ${s}`},body:i}),l=await r.json();if(!l.ok||!l.upload_url||!l.file_id)throw Error(`Slack answered ${l.error??r.status} to the upload`);await fetch(l.upload_url,{method:"POST",body:new Blob([t])}),await o("files.completeUploadExternal",{files:[{id:l.file_id,title:a}],channel_id:e})}}}])},644301,e=>{"use strict";var t=e.i(333925),a=e.i(417043);let n="https://api.telegram.org";e.s(["createTelegram",0,function(e){async function i(t,i,s){let o=i instanceof FormData,r=await fetch(`${n}/bot${e}/${t}`,{method:"POST",signal:s,...o?{body:i}:{headers:{"content-type":"application/json"},body:JSON.stringify(i??{})}}),l=await r.json().catch(()=>null);if(l?.ok)return l.result;let c=l?.description??`Telegram answered ${r.status}`;throw 401===r.status?new a.ChannelRefusal(c):Error(c)}async function s(t,a,s){let{file_path:o}=await i("getFile",{file_id:t});if(!o)throw Error("Telegram did not say where the file is");let r=await fetch(`${n}/file/bot${e}/${o}`);if(!r.ok)throw Error(`Telegram answered ${r.status} for the file`);let l=o.includes(".")?o.slice(o.lastIndexOf(".")):"";return new File([await r.arrayBuffer()],a.includes(".")?a:`${a}${l}`,s?{type:s}:void 0)}return{async listen(e,a){let n=await i("getMe",void 0,a);e.ready(n.username?`@${n.username}`:n.first_name??"the bot");let o=0;for(;!a.aborted;)for(let n of(await i("getUpdates",{offset:o,timeout:t.REACH.pollSeconds,allowed_updates:["message","callback_query"]},AbortSignal.any([a,AbortSignal.timeout((t.REACH.pollSeconds+15)*1e3)])))){o=n.update_id+1;let t=function(e){let t,a=e.callback_query;if(a)return i("answerCallbackQuery",{callback_query_id:a.id}).catch(()=>{}),{kind:"press",chat:String(a.from.id),data:a.data??"",under:a.message?.text?{id:String(a.message.message_id),text:a.message.text}:null};let n=e.message;if(!n?.from||"private"!==n.chat.type)return null;let o=n.photo?.at(-1),r=n.document?{id:n.document.file_id,name:n.document.file_name??"file",type:n.document.mime_type}:o?{id:o.file_id,name:`photo-${n.message_id}`,type:""}:null;return{kind:"message",chat:String(n.chat.id),name:(t=n.from,[t?.first_name,t?.last_name].filter(Boolean).join(" ")||(t?.username?`@${t.username}`:"Someone")),words:(n.text??n.caption??"").trim(),files:r?[{name:r.name,fetch:()=>s(r.id,r.name,r.type)}]:[],unreadable:!!(n.voice||n.audio||n.video)}}(n);t&&e.incoming(t)}},async say(e,t,a){await i("sendMessage",{chat_id:e,text:t,link_preview_options:{is_disabled:!0},...a?.length?{reply_markup:{inline_keyboard:a.map(e=>[{text:e.text,callback_data:e.data}])}}:{}})},async typing(e){await i("sendChatAction",{chat_id:e,action:"typing"}).catch(()=>{})},async settle(e,t,a){await i("editMessageText",{chat_id:e,message_id:Number(t),text:a,link_preview_options:{is_disabled:!0}}).catch(()=>{})},async sendFile(e,t,a,n){let s=new FormData;s.set("chat_id",e),s.set(n?"photo":"document",new Blob([t]),a),await i(n?"sendPhoto":"sendDocument",s)}}}])},312485,e=>e.a(async(t,a)=>{try{var n=e.i(912714),i=e.i(232347),s=e.i(333925),o=e.i(986507),r=e.i(49002),l=e.i(811592),c=e.i(5509),h=e.i(724185),d=e.i(822931),u=e.i(520401),m=e.i(933395),f=e.i(181300),p=e.i(375814),w=e.i(871096),y=e.i(317613),g=e.i(938281),k=e.i(212389),b=e.i(64774),$=e.i(417043),v=e.i(854455),_=e.i(735186),S=e.i(480791),E=e.i(644301),T=t([o,r,l,c,h,u,f]);[o,r,l,c,h,u,f]=T.then?(await T)():T;let W={telegram:e=>(0,E.createTelegram)(e),discord:e=>(0,v.createDiscord)(e),slack:(e,t)=>(0,S.createSlack)(e,t)},D=globalThis,B=D.__reach??={live:new Map,last:null,told:new Set,due:new Map,choices:new Map,listening:null,looking:null},F=()=>i.appEvents.emit({type:"reach"});async function O(e){let t=await (0,h.readConfig)((0,_.reachPersonKey)(e));if(!t)return null;try{let e=JSON.parse(t);return"string"==typeof e.chat&&"string"==typeof e.name?{chat:e.chat,name:e.name}:null}catch{return null}}async function A(e){for(let t of e?[e]:_.REACH_CHANNELS){let a=B.live.get(t);a?.stop.abort(),B.live.delete(t),e&&(await (0,h.removeConfig)((0,_.reachPersonKey)(t)),a?.line&&await (0,u.endCall)(a.line.callId).catch(()=>{}));let n=await Promise.all(_.REACH_KEYS[t].map(h.readConfig));if(!n.every(e=>!!e))continue;let i={name:t,channel:W[t](...n),stop:new AbortController,bot:null,problem:null,asking:null,line:null,turn:Promise.resolve()};B.live.set(t,i),x(i)}B.live.size&&(B.listening??=i.appEvents.subscribe(e=>{"threads"!==e.type||B.looking||(B.looking=setTimeout(()=>{B.looking=null,P().catch(e=>g.logger.error("reach: open work",e))},2e3))})),F()}async function x(e){let{signal:t}=e.stop,a=t=>{e.problem!==t&&(e.problem=t,F())};for(;!t.aborted;){try{await e.channel.listen({ready:t=>{e.bot=t,e.problem=null,F()},incoming:t=>void C(e,t).catch(t=>g.logger.error(`reach ${e.name}: what arrived`,t))},t)}catch(i){if(t.aborted)return;let n=i instanceof Error?i.message:String(i);if(i instanceof $.ChannelRefusal)return g.logger.warn(`reach ${e.name}: ${n}`),a(n);a(n)}await new Promise(e=>setTimeout(e,s.REACH.retryMs))}}async function C(e,t){let{channel:a}=e,n=await O(e.name);if("press"===t.kind){if(n?.chat!==t.chat)return;return q(e,n,t.data,t.under)}if(n?.chat!==t.chat)return n?void await a.say(t.chat,"This Thursday already answers someone else."):(e.asking={chat:t.chat,name:t.name},F(),void await a.say(t.chat,"Almost there. Open Thursday on your computer and press Allow, then write again."));B.last=e.name;let i=t.files.length?await (0,y.keepGivenFiles)(await Promise.all(t.files.map(e=>e.fetch()))):[],s=[t.words,...i].filter(Boolean).join("\n");if(!s){t.unreadable&&await a.say(t.chat,"I can read words, pictures and files here — not voice or video yet. Write it instead.");return}L(e,n,s,s)}async function I(e){let t=e.line;e.line=null,t&&await (0,u.endCall)(t.callId).catch(()=>{})}function L(e,t,a,n,i){let s=e.turn.then(()=>N(e,t,a,n,i));return e.turn=s.then(()=>{},()=>{}),s}async function N(e,t,a,n,i){let{channel:r}=e;r.typing(t.chat).catch(()=>{});let l=setInterval(()=>void r.typing(t.chat).catch(()=>{}),4e3);try{let o=m.ThursdaySettingsSchema.parse({}),l=e.line;(!l||Date.now()-l.lastAt>s.REACH.idleMs||!await (0,u.isCallOpen)(l.callId))&&(await I(e),e.line={...await (0,f.openTextCall)(o),messages:[],lastAt:0});let c=e.line,h=await (0,f.answerInWriting)({callId:c.callId,settings:o,standing:c.standing,messages:[...c.messages,{role:"user",content:a}],said:n});c.messages=h.messages,c.lastAt=Date.now();let d=(0,b.plainText)(h.text)||h.did.join("\n"),p=function(e){let t=[],a=e;for(;a.length>s.REACH.chars;){let e=a.slice(0,s.REACH.chars),n=Math.max(e.lastIndexOf("\n\n"),e.lastIndexOf("\n")),i=n>s.REACH.chars/2?n:s.REACH.chars;t.push(a.slice(0,i).trim()),a=a.slice(i).trim()}return a&&t.push(a),t}(d||"…");for(let[e,a]of p.entries())await r.say(t.chat,a,e===p.length-1?i:void 0);return await M(e,t,h.text),!0}catch(n){let a=(0,k.isPublicError)(n)?n.message:(0,o.modelErrorToString)(n);return g.logger.warn(`reach ${e.name}: ${a}`),await r.say(t.chat,a).catch(()=>{}),!1}finally{clearInterval(l)}}async function M(e,t,a){for(let i of(await (0,w.filesOnDisk)((0,p.pathsIn)(a),null)).slice(-s.REACH.files)){let a=await (0,w.insideWorkspace)(i),o=a?await (0,n.stat)(a).catch(()=>null):null;a&&o&&!(o.size>s.REACH.fileBytes)&&await e.channel.sendFile(t.chat,await (0,n.readFile)(a),i.split("/").pop()??"file","image"===(0,p.viewKindOf)(i)).catch(t=>g.logger.warn(`reach ${e.name}: could not send ${i}`,t))}}async function R(){for(let e of[...B.last?[B.last]:[],..._.REACH_CHANNELS.filter(e=>e!==B.last)]){let t=B.live.get(e),a=t?await O(e):null;if(t&&a)return{live:t,person:a}}return null}async function P(){if(!await R())return;let e=z(await (0,c.listInboxThreads)()),t=new Set(e.map(e=>e.key));for(let[e,a]of B.due)t.has(e)||(clearTimeout(a),B.due.delete(e));for(let t of e)B.told.has(t.key)||B.due.has(t.key)||B.due.set(t.key,setTimeout(()=>void j(t.key),s.REACH.notifyAfterMs))}let z=e=>(0,d.openWork)(e).filter(e=>"progress"!==e.kind);async function j(e){B.due.delete(e);let t=await R();if(!t||B.told.has(e))return;let a=await (0,c.listInboxThreads)(),n=z(a).find(t=>t.key===e);if(!n)return;let i=a.find(t=>t.room.questions.some(t=>`question:${t.id}`===e)),s=i?.room.questions.find(t=>`question:${t.id}`===e),o=(s?.options??[]).map((e,t)=>{let a=`${s?.id.slice(0,40)}:${t}`;return B.choices.set(a,{threadId:i?.id??"",bot:s?.bot??"",question:s?.id??"",answer:e}),{text:e,data:a}});B.told.add(e),await L(t.live,t.person,n.line,null,o)?await (0,l.acceptRoomRelays)(n.relayIds):B.told.delete(e)}async function q(e,t,a,n){let i=B.choices.get(a);if(!i)return void await e.channel.say(t.chat,"That question is no longer open here. Write your answer instead.");for(let[e,t]of B.choices)t.question===i.question&&B.choices.delete(e);try{await (0,r.answerThread)(i.threadId,i.answer,"user",i.bot),n&&await e.channel.settle(t.chat,n.id,`${n.text}
60
+ ${e.trim()}`:"";e.s(["loadThursdayPrompt",0,w]),a()}catch(e){a(e)}},!1),480791,e=>{"use strict";var t=e.i(417043),a=e.i(903438);let n="https://slack.com/api",s=new Set(["invalid_auth","not_authed","account_inactive","token_revoked","not_allowed_token_type","missing_scope"]);e.s(["createSlack",0,function(e,i){async function o(e,a,r=i){let l=await fetch(`${n}/${e}`,{method:"POST",headers:{authorization:`Bearer ${r}`,"content-type":"application/json; charset=utf-8"},body:JSON.stringify(a)}),c=await l.json().catch(()=>null);if(c?.ok)return c;let h=c?.error??`http_${l.status}`,d="missing_scope"===h?`Slack says the app lacks a permission (${c?.needed??"a scope"}) — make it from the manifest in the guide.`:`Slack answered ${h} to ${e}`;throw s.has(h)?new t.ChannelRefusal(d):Error(d)}let r=new Map;async function l(e){let t=r.get(e);if(t)return t;let a=await o("users.info",{user:e}).then(t=>t.user?.real_name||t.user?.name||e).catch(()=>e);return r.set(e,a),a}async function c(e,t){if("events_api"===e){let e=t.event??{},a=!e.subtype||"file_share"===e.subtype;return"message"===e.type&&"im"===e.channel_type&&a&&!e.bot_id&&e.user&&e.channel?{kind:"message",chat:e.channel,name:await l(e.user),words:(e.text??"").trim(),files:(e.files??[]).flatMap(e=>{let t=e.url_private_download;if(!t)return[];let a=e.name??"file";return[{name:a,fetch:async()=>{let n=await fetch(t,{headers:{authorization:`Bearer ${i}`}});if(!n.ok)throw Error(`Slack answered ${n.status} for the file`);return new File([await n.arrayBuffer()],a,{type:e.mimetype??""})}}]}),unreadable:!1}:null}return"interactive"===e&&"block_actions"===t.type?t.channel?.id?{kind:"press",chat:t.channel.id,data:t.actions?.[0]?.value??"",under:t.message?.ts&&t.message.text?{id:t.message.ts,text:t.message.text}:null}:null:null}return{async listen(t,n){let s=await o("auth.test",{}),{url:i}=await o("apps.connections.open",{},e);t.ready(s.user?`@${s.user}`:"the app");let r=await (0,a.runSocket)(i,{message(e,a){let{type:n,envelope_id:s,payload:i}=e;s&&a({envelope_id:s}),n&&i&&c(n,i).then(e=>{e&&t.incoming(e)})}},n);if(!n.aborted)throw Error(`Slack closed the connection (${r.code})`)},async say(e,t,n){let s=(0,a.inPieces)(t,2900);for(let[t,a]of s.entries()){let i=n?.length&&t===s.length-1;await o("chat.postMessage",{channel:e,text:a,unfurl_links:!1,...i?{blocks:[{type:"section",text:{type:"plain_text",text:a}},{type:"actions",elements:n.slice(0,25).map((e,t)=>({type:"button",action_id:`choice_${t}`,text:{type:"plain_text",text:e.text.slice(0,75)},value:e.data}))}]}:{}})}},async typing(){},async settle(e,t,a){await o("chat.update",{channel:e,ts:t,text:a.slice(0,2900),blocks:[]}).catch(()=>{})},async sendFile(e,t,a){let s=new URLSearchParams({filename:a,length:String(t.byteLength)}),r=await fetch(`${n}/files.getUploadURLExternal`,{method:"POST",headers:{authorization:`Bearer ${i}`},body:s}),l=await r.json();if(!l.ok||!l.upload_url||!l.file_id)throw Error(`Slack answered ${l.error??r.status} to the upload`);await fetch(l.upload_url,{method:"POST",body:new Blob([t])}),await o("files.completeUploadExternal",{files:[{id:l.file_id,title:a}],channel_id:e})}}}])},644301,e=>{"use strict";var t=e.i(333925),a=e.i(417043);let n="https://api.telegram.org";e.s(["createTelegram",0,function(e){async function s(t,s,i){let o=s instanceof FormData,r=await fetch(`${n}/bot${e}/${t}`,{method:"POST",signal:i,...o?{body:s}:{headers:{"content-type":"application/json"},body:JSON.stringify(s??{})}}),l=await r.json().catch(()=>null);if(l?.ok)return l.result;let c=l?.description??`Telegram answered ${r.status}`;throw 401===r.status?new a.ChannelRefusal(c):Error(c)}async function i(t,a,i){let{file_path:o}=await s("getFile",{file_id:t});if(!o)throw Error("Telegram did not say where the file is");let r=await fetch(`${n}/file/bot${e}/${o}`);if(!r.ok)throw Error(`Telegram answered ${r.status} for the file`);let l=o.includes(".")?o.slice(o.lastIndexOf(".")):"";return new File([await r.arrayBuffer()],a.includes(".")?a:`${a}${l}`,i?{type:i}:void 0)}return{async listen(e,a){let n=await s("getMe",void 0,a);e.ready(n.username?`@${n.username}`:n.first_name??"the bot");let o=0;for(;!a.aborted;)for(let n of(await s("getUpdates",{offset:o,timeout:t.REACH.pollSeconds,allowed_updates:["message","callback_query"]},AbortSignal.any([a,AbortSignal.timeout((t.REACH.pollSeconds+15)*1e3)])))){o=n.update_id+1;let t=function(e){let t,a=e.callback_query;if(a)return s("answerCallbackQuery",{callback_query_id:a.id}).catch(()=>{}),{kind:"press",chat:String(a.from.id),data:a.data??"",under:a.message?.text?{id:String(a.message.message_id),text:a.message.text}:null};let n=e.message;if(!n?.from||"private"!==n.chat.type)return null;let o=n.photo?.at(-1),r=n.document?{id:n.document.file_id,name:n.document.file_name??"file",type:n.document.mime_type}:o?{id:o.file_id,name:`photo-${n.message_id}`,type:""}:null;return{kind:"message",chat:String(n.chat.id),name:(t=n.from,[t?.first_name,t?.last_name].filter(Boolean).join(" ")||(t?.username?`@${t.username}`:"Someone")),words:(n.text??n.caption??"").trim(),files:r?[{name:r.name,fetch:()=>i(r.id,r.name,r.type)}]:[],unreadable:!!(n.voice||n.audio||n.video)}}(n);t&&e.incoming(t)}},async say(e,t,a){await s("sendMessage",{chat_id:e,text:t,link_preview_options:{is_disabled:!0},...a?.length?{reply_markup:{inline_keyboard:a.map(e=>[{text:e.text,callback_data:e.data}])}}:{}})},async typing(e){await s("sendChatAction",{chat_id:e,action:"typing"}).catch(()=>{})},async settle(e,t,a){await s("editMessageText",{chat_id:e,message_id:Number(t),text:a,link_preview_options:{is_disabled:!0}}).catch(()=>{})},async sendFile(e,t,a,n){let i=new FormData;i.set("chat_id",e),i.set(n?"photo":"document",new Blob([t]),a),await s(n?"sendPhoto":"sendDocument",i)}}}])},312485,e=>e.a(async(t,a)=>{try{var n=e.i(912714),s=e.i(232347),i=e.i(333925),o=e.i(986507),r=e.i(49002),l=e.i(811592),c=e.i(5509),h=e.i(724185),d=e.i(822931),u=e.i(520401),m=e.i(933395),f=e.i(181300),p=e.i(375814),w=e.i(871096),y=e.i(317613),g=e.i(938281),k=e.i(212389),b=e.i(64774),$=e.i(417043),v=e.i(854455),_=e.i(735186),S=e.i(480791),E=e.i(644301),T=t([o,r,l,c,h,u,f]);[o,r,l,c,h,u,f]=T.then?(await T)():T;let W={telegram:e=>(0,E.createTelegram)(e),discord:e=>(0,v.createDiscord)(e),slack:(e,t)=>(0,S.createSlack)(e,t)},D=globalThis,B=D.__reach??={live:new Map,last:null,told:new Set,due:new Map,choices:new Map,listening:null,looking:null},F=()=>s.appEvents.emit({type:"reach"});async function O(e){let t=await (0,h.readConfig)((0,_.reachPersonKey)(e));if(!t)return null;try{let e=JSON.parse(t);return"string"==typeof e.chat&&"string"==typeof e.name?{chat:e.chat,name:e.name}:null}catch{return null}}async function A(e){for(let t of e?[e]:_.REACH_CHANNELS){let a=B.live.get(t);a?.stop.abort(),B.live.delete(t),e&&(await (0,h.removeConfig)((0,_.reachPersonKey)(t)),a?.line&&await (0,u.endCall)(a.line.callId).catch(()=>{}));let n=await Promise.all(_.REACH_KEYS[t].map(h.readConfig));if(!n.every(e=>!!e))continue;let s={name:t,channel:W[t](...n),stop:new AbortController,bot:null,problem:null,asking:null,line:null,turn:Promise.resolve()};B.live.set(t,s),x(s)}B.live.size&&(B.listening??=s.appEvents.subscribe(e=>{"threads"!==e.type||B.looking||(B.looking=setTimeout(()=>{B.looking=null,P().catch(e=>g.logger.error("reach: open work",e))},2e3))})),F()}async function x(e){let{signal:t}=e.stop,a=t=>{e.problem!==t&&(e.problem=t,F())};for(;!t.aborted;){try{await e.channel.listen({ready:t=>{e.bot=t,e.problem=null,F()},incoming:t=>void C(e,t).catch(t=>g.logger.error(`reach ${e.name}: what arrived`,t))},t)}catch(s){if(t.aborted)return;let n=s instanceof Error?s.message:String(s);if(s instanceof $.ChannelRefusal)return g.logger.warn(`reach ${e.name}: ${n}`),a(n);a(n)}await new Promise(e=>setTimeout(e,i.REACH.retryMs))}}async function C(e,t){let{channel:a}=e,n=await O(e.name);if("press"===t.kind){if(n?.chat!==t.chat)return;return q(e,n,t.data,t.under)}if(n?.chat!==t.chat)return n?void await a.say(t.chat,"This Thursday already answers someone else."):(e.asking={chat:t.chat,name:t.name},F(),void await a.say(t.chat,"Almost there. Open Thursday on your computer and press Allow, then write again."));B.last=e.name;let s=t.files.length?await (0,y.keepGivenFiles)(await Promise.all(t.files.map(e=>e.fetch()))):[],i=[t.words,...s].filter(Boolean).join("\n");if(!i){t.unreadable&&await a.say(t.chat,"I can read words, pictures and files here — not voice or video yet. Write it instead.");return}L(e,n,i,i)}async function I(e){let t=e.line;e.line=null,t&&await (0,u.endCall)(t.callId).catch(()=>{})}function L(e,t,a,n,s){let i=e.turn.then(()=>N(e,t,a,n,s));return e.turn=i.then(()=>{},()=>{}),i}async function N(e,t,a,n,s){let{channel:r}=e;r.typing(t.chat).catch(()=>{});let l=setInterval(()=>void r.typing(t.chat).catch(()=>{}),4e3);try{let o=m.ThursdaySettingsSchema.parse({}),l=e.line;(!l||Date.now()-l.lastAt>i.REACH.idleMs||!await (0,u.isCallOpen)(l.callId))&&(await I(e),e.line={...await (0,f.openTextCall)(o),messages:[],lastAt:0});let c=e.line,h=await (0,f.answerInWriting)({callId:c.callId,settings:o,standing:c.standing,messages:[...c.messages,{role:"user",content:a}],said:n});c.messages=h.messages,c.lastAt=Date.now();let d=(0,b.plainText)(h.text)||h.did.join("\n"),p=function(e){let t=[],a=e;for(;a.length>i.REACH.chars;){let e=a.slice(0,i.REACH.chars),n=Math.max(e.lastIndexOf("\n\n"),e.lastIndexOf("\n")),s=n>i.REACH.chars/2?n:i.REACH.chars;t.push(a.slice(0,s).trim()),a=a.slice(s).trim()}return a&&t.push(a),t}(d||"…");for(let[e,a]of p.entries())await r.say(t.chat,a,e===p.length-1?s:void 0);return await M(e,t,h.text),!0}catch(n){let a=(0,k.isPublicError)(n)?n.message:(0,o.modelErrorToString)(n);return g.logger.warn(`reach ${e.name}: ${a}`),await r.say(t.chat,a).catch(()=>{}),!1}finally{clearInterval(l)}}async function M(e,t,a){for(let s of(await (0,w.filesOnDisk)((0,p.pathsIn)(a),null)).slice(-i.REACH.files)){let a=await (0,w.insideWorkspace)(s),o=a?await (0,n.stat)(a).catch(()=>null):null;a&&o&&!(o.size>i.REACH.fileBytes)&&await e.channel.sendFile(t.chat,await (0,n.readFile)(a),s.split("/").pop()??"file","image"===(0,p.viewKindOf)(s)).catch(t=>g.logger.warn(`reach ${e.name}: could not send ${s}`,t))}}async function R(){for(let e of[...B.last?[B.last]:[],..._.REACH_CHANNELS.filter(e=>e!==B.last)]){let t=B.live.get(e),a=t?await O(e):null;if(t&&a)return{live:t,person:a}}return null}async function P(){if(!await R())return;let e=z(await (0,c.listInboxThreads)()),t=new Set(e.map(e=>e.key));for(let[e,a]of B.due)t.has(e)||(clearTimeout(a),B.due.delete(e));for(let t of e)B.told.has(t.key)||B.due.has(t.key)||B.due.set(t.key,setTimeout(()=>void j(t.key),i.REACH.notifyAfterMs))}let z=e=>(0,d.openWork)(e).filter(e=>"progress"!==e.kind);async function j(e){B.due.delete(e);let t=await R();if(!t||B.told.has(e))return;let a=await (0,c.listInboxThreads)(),n=z(a).find(t=>t.key===e);if(!n)return;let s=a.find(t=>t.room.questions.some(t=>`question:${t.id}`===e)),i=s?.room.questions.find(t=>`question:${t.id}`===e),o=(i?.options??[]).map((e,t)=>{let a=`${i?.id.slice(0,40)}:${t}`;return B.choices.set(a,{threadId:s?.id??"",bot:i?.bot??"",question:i?.id??"",answer:e}),{text:e,data:a}});B.told.add(e),await L(t.live,t.person,n.line,null,o)?await (0,l.acceptRoomRelays)(n.relayIds):B.told.delete(e)}async function q(e,t,a,n){let s=B.choices.get(a);if(!s)return void await e.channel.say(t.chat,"That question is no longer open here. Write your answer instead.");for(let[e,t]of B.choices)t.question===s.question&&B.choices.delete(e);try{await (0,r.answerThread)(s.threadId,s.answer,"user",s.bot),n&&await e.channel.settle(t.chat,n.id,`${n.text}
61
61
 
62
- → ${i.answer}`),e.line?.messages.push({role:"user",content:`[The user answered ${i.bot}'s question from their phone: ${i.answer}. It has reached ${i.bot}.]`})}catch(a){await e.channel.say(t.chat,(0,k.isPublicError)(a)?a.message:"That answer did not get through.")}}e.s(["startReach",0,A]),a()}catch(e){a(e)}},!1),822931,e=>{"use strict";var t=e.i(333925),a=e.i(951056),n=e.i(900533);let i={question:0,stopped:1,done:2,progress:3};function s(e){let a=e.trim();if(a.length<=t.CALL_RELAY.chars)return a;let n=a.slice(0,t.CALL_RELAY.chars),i=Math.max(n.lastIndexOf("\n\n"),n.lastIndexOf(". "),n.lastIndexOf(".\n"),n.lastIndexOf("。")),s=(i>t.CALL_RELAY.chars/3?n.slice(0,i+1):n).trim();return`${s}
63
- [The message goes on; the rest is in its thread on screen.]`}e.s(["openWork",0,function(e){let t=[];for(let o of e){let{relays:e,questions:r}=o.room,l=(0,n.toDate)(o.updatedAt).getTime(),c=(e,t)=>`[${e} → Thursday, thread "${o.label}" (${o.id}), ${t}.]`,h=(e,t)=>({kind:"relay",name:o.label,line:t,done:!0,bot:e});for(let a of r){let n=a.options?.length?` Options: ${a.options.join(" / ")}.`:"";t.push({rank:i.question,key:`question:${a.id}`,kind:"question",line:`${c(a.bot,"question")}
64
- ${s(a.text)}${n}`,relayIds:e.filter(e=>e.messageId===a.id).map(e=>e.id),show:h(a.bot,`${a.bot}: question`)})}let d=e.filter(e=>!r.some(t=>t.id===e.messageId)),u="done"===o.status,m="waiting"===o.status&&(0,a.isAppStop)(o.ask)&&!o.ask?.auto;if(u||m){if(o.seen)continue;let e=m?"stopped":"done",a="stopped"===e?`It stopped before finishing. Where it got to: ${s(o.ask?.question??o.outcome??"")}`:`Done. Its answer: ${s(o.outcome??"")}`;t.push({rank:i[e],key:`${e}:${o.id}@${l}`,kind:"ending",line:`${c(o.bot,e)}
65
- ${a}`,relayIds:d.map(e=>e.id),show:h(o.bot,"stopped"===e?`${o.bot} stopped`:`Answer from ${o.bot}`)});continue}for(let e of d)t.push({rank:i.progress,key:`progress:${e.id}`,kind:"progress",line:`${c(e.bot,e.kind)}
66
- ${s(e.text)}`,relayIds:[e.id],show:h(e.bot,`${e.bot}: ${e.kind}`)})}return t.sort((e,t)=>e.rank-t.rank)}])},181300,e=>e.a(async(t,a)=>{try{var n=e.i(734732),i=e.i(853205),s=e.i(333925),o=e.i(247839),r=e.i(113022),l=e.i(986507),c=e.i(864328),h=e.i(539470),d=e.i(79290),u=e.i(51083),m=e.i(656719),f=e.i(724185),p=e.i(426455);e.i(938281);var w=e.i(212389),y=e.i(520401),g=e.i(933395),k=e.i(293822),b=t([r,l,h,d,f,y]);async function $(){let e=await Promise.all(g.TEXT_CALL_PROVIDERS.map(async e=>await (0,f.readConfig)(e.apiKeyName)?e.apiKeyName:null));return(0,g.textCallRunsOn)(t=>e.includes(t))}async function v(e,t){if(t)return t;let a=await $();return a||(0,w.publicError)(O),{provider:a,model:e.backendModel}}async function _(e,t){let a=await v(e,t),[n,i]=await Promise.all([(0,y.insertCall)({provider:a.provider,model:s.TEXT_CALL.model,backendModel:a.model}),(0,h.loadCallStanding)()]);return{callId:n,standing:i}}async function S(e){var t;let a,{callId:i,settings:o,standing:r,messages:l,said:c,signal:h}=e,[d,m]=await Promise.all([E(i,o),(0,y.nextTurnSeq)(i)]);null!==c&&await (0,y.saveTurns)(i,[{id:crypto.randomUUID(),role:"user",text:c,seq:m}]);let f=await (0,n.generateText)({model:d.model,instructions:d.system,messages:[...T(r),...l],allowSystemInMessages:!0,tools:d.tools,providerOptions:d.providerOptions,stopWhen:(0,n.stepCountIs)(s.TEXT_CALL.maxSteps),abortSignal:h,onStepEnd:(t=i,a=null===c?m:m+1,async e=>{for(let n of e.content)if("tool-call"===n.type){let i=e.content.find(e=>"tool-result"===e.type&&e.toolCallId===n.toolCallId);await (0,y.saveTurns)(t,[{id:n.toolCallId,role:"tool",tool:n.toolName,text:n.toolName===u.TOOL_NAMES.web_search?function(e,t){let a=t??{},n=[(e??{}).query,a.action?.query].find(e=>"string"==typeof e&&!!e.trim()),i=Array.isArray(a.sources)?a.sources.flatMap(e=>e&&"object"==typeof e&&"url"in e&&"string"==typeof e.url?[{url:e.url,..."title"in e&&"string"==typeof e.title?{title:e.title}:{}}]:[]):[];return JSON.stringify({query:n??null,sources:i})}(n.input,i?.type==="tool-result"?i.output:null):JSON.stringify(n.input??{}),seq:a++}])}else"text"===n.type&&n.text.trim()?await (0,y.saveTurns)(t,[{id:crypto.randomUUID(),role:"assistant",text:n.text.trim(),seq:a++}]):"reasoning"===n.type&&n.text.trim()&&await (0,y.saveThought)(t,{id:crypto.randomUUID(),text:n.text.trim(),seq:a})})});return{text:f.text.trim(),did:f.steps.flatMap(e=>e.toolCalls.map(e=>(0,k.toolLine)(e.toolName,JSON.stringify(e.input??{}))??e.toolName)),messages:[...l,...f.response.messages]}}[r,l,h,d,f,y]=b.then?(await b)():b,i.z.object({callId:i.z.string().min(1),settings:g.ThursdaySettingsSchema,standing:i.z.string().nullish(),runsOn:c.textModelRefSchema.nullish(),messages:i.z.array(i.z.unknown()).min(1)});let T=e=>e?[{role:"system",content:e}]:[];async function E(e,t,a){let n=await v(t,a),i="openai"===n.provider||"chatgpt"===n.provider,[s,c,h,w,y]=await Promise.all([(0,l.getTextModel)(n),(0,d.loadThursdayPrompt)(t.backendPrompt,!0),(0,r.loadTools)({target:"thursday",callId:e,webSearch:t.webSearch,written:!0}),(0,f.readConfig)(m.EXA_API_KEY),(0,f.readConfig)(o.LIVE_PROVIDER.apiKeyName)]),g=s.searchTools&&Object.values(s.searchTools)[0],k={...h,...t.webSearch&&!w&&g?{[u.TOOL_NAMES.web_search]:g}:{}},b=i?y?await (0,p.acceptedReasoning)({apiKey:y,model:n.model,effort:t.reasoningEffort}):"none"===t.reasoningEffort?{effort:"none"}:{effort:t.reasoningEffort??void 0,summary:"auto"}:null;return{model:s.model,system:c,tools:k,providerOptions:{openai:{...b?.effort?{reasoningEffort:b.effort}:{},...b&&"summary"in b&&b.summary?{reasoningSummary:b.summary}:{}}}}}let O="Writing to Thursday needs a GPT subscription sign-in or an OpenAI key — Settings › API keys.";e.s(["answerInWriting",0,S,"openTextCall",0,_]),a()}catch(e){a(e)}},!1),317613,e=>{"use strict";var t=e.i(912714),a=e.i(750227),n=e.i(333925);e.i(375814);var i=e.i(871096);async function s(e){let s=await (0,i.openWorkspace)(),o=new Set(await (0,t.readdir)((0,a.join)(i.WORKSPACE,n.GIVEN_FILES.dir)).catch(()=>[])),r=[];for(let t of e){let e=t.name.normalize("NFC").replace(/[^\p{L}\p{N}._-]+/gu,"-").replace(/^[-.]+|-+$/g,"")||"file",a=e.lastIndexOf("."),i=a>0?e.slice(0,a):e,l=a>0?e.slice(a):"",c=e;for(let e=2;o.has(c);e++)c=`${i}-${e}${l}`;o.add(c);let h=`${n.GIVEN_FILES.dir}/${c}`;await s.writeFile(h,Buffer.from(await t.arrayBuffer())),r.push(h)}return r}e.s(["keepGivenFiles",0,s])},417043,e=>{"use strict";e.s(["ChannelRefusal",0,class extends Error{}])},903438,e=>{"use strict";e.s(["inPieces",0,function(e,t){let a=[],n=e;for(;n.length>t;){let e=n.slice(0,t),i=Math.max(e.lastIndexOf("\n\n"),e.lastIndexOf("\n")),s=i>t/2?i:t;a.push(n.slice(0,s).trim()),n=n.slice(s).trim()}return n&&a.push(n),a},"runSocket",0,function(e,t,a){return new Promise((n,i)=>{let s=new WebSocket(e),o=e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify(e))},r=()=>s.close(1e3);a.addEventListener("abort",r,{once:!0}),s.addEventListener("message",e=>{try{t.message(JSON.parse(String(e.data)),o)}catch{}}),s.addEventListener("error",()=>{s.readyState!==WebSocket.OPEN&&i(Error(`Could not connect to ${new URL(e).host}`))}),s.addEventListener("close",e=>{a.removeEventListener("abort",r),n({code:e.code,reason:e.reason})})})}])},854455,e=>{"use strict";var t=e.i(417043),a=e.i(903438);let n={4004:"Discord did not take the bot token.",4013:"Discord refused the intents this bot asked for.",4014:"Discord refused an intent this bot is not allowed — check the bot's page."};e.s(["createDiscord",0,function(e){async function i(a,n,i){let s=i instanceof FormData,o=await fetch(`https://discord.com/api/v10${n}`,{method:a,headers:{authorization:`Bot ${e}`,...s||!i?{}:{"content-type":"application/json"}},body:s?i:i?JSON.stringify(i):void 0});if(o.ok)return 204===o.status?null:await o.json();let r=await o.json().catch(()=>null),l=r?.message??`Discord answered ${o.status}`;throw 401===o.status?new t.ChannelRefusal(l):Error(l)}let s=e=>{let t=e.length<=5?1:5,a=[];for(let n=0;n<e.length&&a.length<5;n+=t)a.push({type:1,components:e.slice(n,n+t).map(e=>({type:2,style:2,label:e.text.slice(0,80),custom_id:e.data}))});return a};return{async listen(s,o){let r,l=null;try{let c=await (0,a.runSocket)("wss://gateway.discord.gg/?v=10&encoding=json",{message(t,a){let{op:n,d:o,s:c,t:h}=t;if(null!==c&&(l=c),10===n){let t=o.heartbeat_interval;r=setInterval(()=>a({op:1,d:l}),t),a({op:2,d:{token:e,intents:4096,properties:{os:process.platform,browser:"thursday",device:"thursday"}}})}else if(1===n)a({op:1,d:l});else if(0===n&&"READY"===h)s.ready(o.user.username);else if(0===n&&h){var d,u;let e=(d=h,u=o,"MESSAGE_CREATE"===d?u.guild_id||u.author.bot?null:{kind:"message",chat:u.channel_id,name:u.author.global_name||u.author.username,words:u.content.trim(),files:(u.attachments??[]).map(e=>({name:e.filename,fetch:async()=>{let t=await fetch(e.url);if(!t.ok)throw Error(`Discord answered ${t.status} for the file`);return new File([await t.arrayBuffer()],e.filename,{type:e.content_type??""})}})),unreadable:!1}:"INTERACTION_CREATE"===d?3!==u.type||u.guild_id?null:(i("POST",`/interactions/${u.id}/${u.token}/callback`,{type:6}).catch(()=>{}),{kind:"press",chat:u.channel_id,data:u.data?.custom_id??"",under:u.message?{id:u.message.id,text:u.message.content}:null}):null);e&&s.incoming(e)}}},o),h=n[c.code];if(h)throw new t.ChannelRefusal(h);if(!o.aborted)throw Error(`Discord closed the connection (${c.code})`)}finally{clearInterval(r)}},async say(e,t,n){let o=(0,a.inPieces)(t,1900);for(let[t,a]of o.entries())await i("POST",`/channels/${e}/messages`,{content:a,...n?.length&&t===o.length-1?{components:s(n)}:{}})},async typing(e){await i("POST",`/channels/${e}/typing`).catch(()=>{})},async settle(e,t,a){await i("PATCH",`/channels/${e}/messages/${t}`,{content:a.slice(0,1900),components:[]}).catch(()=>{})},async sendFile(e,t,a){let n=new FormData;n.set("payload_json",JSON.stringify({attachments:[{id:0,filename:a}]})),n.set("files[0]",new Blob([t]),a),await i("POST",`/channels/${e}/messages`,n)}}}])},426455,e=>{"use strict";var t=e.i(853205),a=e.i(333925),n=e.i(938281);e.i(556325),t.z.object({session:t.z.object({id:t.z.string().min(1)}),transport:t.z.object({type:t.z.literal("webrtc"),sdp:t.z.string().min(1)})});let i=new Map;async function s(e){let{apiKey:t,model:s,effort:o}=e,r=`${s} ${o??"auto"}`,l=i.get(r);if(void 0!==l)return l;let c="none"===o?{effort:o}:{...o?{effort:o}:{},summary:"auto"};for(;;){let e=await fetch("https://api.openai.com/v1/responses/input_tokens",{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},signal:AbortSignal.timeout(a.LIVE_CALL.reasoningCheckMs),body:JSON.stringify({model:s,input:".",reasoning:c})}).catch(()=>null);if(!e)return c;let o=Object.keys(c).length?c:null;if(e.ok)return i.set(r,o),o;let l=await e.json().catch(()=>null),h=l?.error?.param?.replace(/^reasoning\./,"");if("effort"!==h&&"summary"!==h||!(h in c))return c;if(n.logger.warn(`${s} takes no reasoning ${h}; calls omit it`),delete c[h],!Object.keys(c).length)return i.set(r,null),null}}e.s(["acceptedReasoning",0,s])}];
62
+ → ${s.answer}`),e.line?.messages.push({role:"user",content:`[The user answered ${s.bot}'s question from their phone: ${s.answer}. It has reached ${s.bot}.]`})}catch(a){await e.channel.say(t.chat,(0,k.isPublicError)(a)?a.message:"That answer did not get through.")}}e.s(["startReach",0,A]),a()}catch(e){a(e)}},!1),822931,e=>{"use strict";var t=e.i(333925),a=e.i(951056),n=e.i(900533);let s={message:"says",question:"asks",report:"reports",interrupted:"was cut off"},i={question:0,stopped:1,done:2,progress:3};function o(e){let a=e.trim();if(a.length<=t.CALL_RELAY.chars)return a;let n=a.slice(0,t.CALL_RELAY.chars),s=Math.max(n.lastIndexOf("\n\n"),n.lastIndexOf(". "),n.lastIndexOf(".\n"),n.lastIndexOf("。")),i=(s>t.CALL_RELAY.chars/3?n.slice(0,s+1):n).trim();return`${i}
63
+ [The message goes on; the rest is in its thread on screen.]`}e.s(["openWork",0,function(e){let t=[];for(let r of e){let{relays:e,questions:l}=r.room,c=(0,n.toDate)(r.updatedAt).getTime(),h=(e,t)=>`[${e} → Thursday, thread "${r.label}" (${r.id}), ${t}.]`,d=(e,t)=>({kind:"relay",name:r.label,line:t,done:!0,bot:e});for(let a of l){let n=a.options?.length?` Options: ${a.options.join(" / ")}.`:"";t.push({rank:i.question,key:`question:${a.id}`,kind:"question",line:`${h(a.bot,"question")}
64
+ ${o(a.text)}${n}`,relayIds:e.filter(e=>e.messageId===a.id).map(e=>e.id),show:d(a.bot,`${a.bot} asks`)})}let u=e.filter(e=>!l.some(t=>t.id===e.messageId)),m="done"===r.status,f="waiting"===r.status&&(0,a.isAppStop)(r.ask)&&!r.ask?.auto;if(m||f){if(r.seen)continue;let e=f?"stopped":"done",a="stopped"===e?`It stopped before finishing. Where it got to: ${o(r.ask?.question??r.outcome??"")}`:`Done. Its answer: ${o(r.outcome??"")}`;t.push({rank:i[e],key:`${e}:${r.id}@${c}`,kind:"ending",line:`${h(r.bot,e)}
65
+ ${a}`,relayIds:u.map(e=>e.id),show:d(r.bot,"stopped"===e?`${r.bot} stopped`:`${r.bot} finished`)});continue}for(let e of u)t.push({rank:i.progress,key:`progress:${e.id}`,kind:"progress",line:`${h(e.bot,e.kind)}
66
+ ${o(e.text)}`,relayIds:[e.id],show:d(e.bot,`${e.bot} ${s[e.kind]}`)})}return t.sort((e,t)=>e.rank-t.rank)}])},181300,e=>e.a(async(t,a)=>{try{var n=e.i(734732),s=e.i(853205),i=e.i(333925),o=e.i(247839),r=e.i(113022),l=e.i(986507),c=e.i(864328),h=e.i(539470),d=e.i(79290),u=e.i(51083),m=e.i(656719),f=e.i(724185),p=e.i(426455);e.i(938281);var w=e.i(212389),y=e.i(520401),g=e.i(933395),k=e.i(293822),b=t([r,l,h,d,f,y]);async function $(){let e=await Promise.all(g.TEXT_CALL_PROVIDERS.map(async e=>await (0,f.readConfig)(e.apiKeyName)?e.apiKeyName:null));return(0,g.textCallRunsOn)(t=>e.includes(t))}async function v(e,t){if(t)return t;let a=await $();return a||(0,w.publicError)(O),{provider:a,model:e.backendModel}}async function _(e,t){let a=await v(e,t),[n,s]=await Promise.all([(0,y.insertCall)({provider:a.provider,model:i.TEXT_CALL.model,backendModel:a.model}),(0,h.loadCallStanding)()]);return{callId:n,standing:s}}async function S(e){var t;let a,{callId:s,settings:o,standing:r,messages:l,said:c,signal:h}=e,[d,m]=await Promise.all([E(s,o),(0,y.nextTurnSeq)(s)]);null!==c&&await (0,y.saveTurns)(s,[{id:crypto.randomUUID(),role:"user",text:c,seq:m}]);let f=await (0,n.generateText)({model:d.model,instructions:d.system,messages:[...T(r),...l],allowSystemInMessages:!0,tools:d.tools,providerOptions:d.providerOptions,stopWhen:(0,n.stepCountIs)(i.TEXT_CALL.maxSteps),abortSignal:h,onStepEnd:(t=s,a=null===c?m:m+1,async e=>{for(let n of e.content)if("tool-call"===n.type){let s=e.content.find(e=>"tool-result"===e.type&&e.toolCallId===n.toolCallId);await (0,y.saveTurns)(t,[{id:n.toolCallId,role:"tool",tool:n.toolName,text:n.toolName===u.TOOL_NAMES.web_search?function(e,t){let a=t??{},n=[(e??{}).query,a.action?.query].find(e=>"string"==typeof e&&!!e.trim()),s=Array.isArray(a.sources)?a.sources.flatMap(e=>e&&"object"==typeof e&&"url"in e&&"string"==typeof e.url?[{url:e.url,..."title"in e&&"string"==typeof e.title?{title:e.title}:{}}]:[]):[];return JSON.stringify({query:n??null,sources:s})}(n.input,s?.type==="tool-result"?s.output:null):JSON.stringify(n.input??{}),seq:a++}])}else"text"===n.type&&n.text.trim()?await (0,y.saveTurns)(t,[{id:crypto.randomUUID(),role:"assistant",text:n.text.trim(),seq:a++}]):"reasoning"===n.type&&n.text.trim()&&await (0,y.saveThought)(t,{id:crypto.randomUUID(),text:n.text.trim(),seq:a})})});return{text:f.text.trim(),did:f.steps.flatMap(e=>e.toolCalls.map(e=>(0,k.toolLine)(e.toolName,JSON.stringify(e.input??{}))??e.toolName)),messages:[...l,...f.response.messages]}}[r,l,h,d,f,y]=b.then?(await b)():b,s.z.object({callId:s.z.string().min(1),settings:g.ThursdaySettingsSchema,standing:s.z.string().nullish(),runsOn:c.textModelRefSchema.nullish(),messages:s.z.array(s.z.unknown()).min(1)});let T=e=>e?[{role:"system",content:e}]:[];async function E(e,t,a){let n=await v(t,a),s="openai"===n.provider||"chatgpt"===n.provider,[i,c,h,w,y]=await Promise.all([(0,l.getTextModel)(n),(0,d.loadThursdayPrompt)(t.backendPrompt,!0),(0,r.loadTools)({target:"thursday",callId:e,webSearch:t.webSearch,written:!0}),(0,f.readConfig)(m.EXA_API_KEY),(0,f.readConfig)(o.LIVE_PROVIDER.apiKeyName)]),g=i.searchTools&&Object.values(i.searchTools)[0],k={...h,...t.webSearch&&!w&&g?{[u.TOOL_NAMES.web_search]:g}:{}},b=s?y?await (0,p.acceptedReasoning)({apiKey:y,model:n.model,effort:t.reasoningEffort}):"none"===t.reasoningEffort?{effort:"none"}:{effort:t.reasoningEffort??void 0,summary:"auto"}:null;return{model:i.model,system:c,tools:k,providerOptions:{openai:{...b?.effort?{reasoningEffort:b.effort}:{},...b&&"summary"in b&&b.summary?{reasoningSummary:b.summary}:{}}}}}let O="Writing to Thursday needs a GPT subscription sign-in or an OpenAI key — Settings › API keys.";e.s(["answerInWriting",0,S,"openTextCall",0,_]),a()}catch(e){a(e)}},!1),317613,e=>{"use strict";var t=e.i(912714),a=e.i(750227),n=e.i(333925);e.i(375814);var s=e.i(871096);async function i(e){let i=await (0,s.openWorkspace)(),o=new Set(await (0,t.readdir)((0,a.join)(s.WORKSPACE,n.GIVEN_FILES.dir)).catch(()=>[])),r=[];for(let t of e){let e=t.name.normalize("NFC").replace(/[^\p{L}\p{N}._-]+/gu,"-").replace(/^[-.]+|-+$/g,"")||"file",a=e.lastIndexOf("."),s=a>0?e.slice(0,a):e,l=a>0?e.slice(a):"",c=e;for(let e=2;o.has(c);e++)c=`${s}-${e}${l}`;o.add(c);let h=`${n.GIVEN_FILES.dir}/${c}`;await i.writeFile(h,Buffer.from(await t.arrayBuffer())),r.push(h)}return r}e.s(["keepGivenFiles",0,i])},417043,e=>{"use strict";e.s(["ChannelRefusal",0,class extends Error{}])},903438,e=>{"use strict";e.s(["inPieces",0,function(e,t){let a=[],n=e;for(;n.length>t;){let e=n.slice(0,t),s=Math.max(e.lastIndexOf("\n\n"),e.lastIndexOf("\n")),i=s>t/2?s:t;a.push(n.slice(0,i).trim()),n=n.slice(i).trim()}return n&&a.push(n),a},"runSocket",0,function(e,t,a){return new Promise((n,s)=>{let i=new WebSocket(e),o=e=>{i.readyState===WebSocket.OPEN&&i.send(JSON.stringify(e))},r=()=>i.close(1e3);a.addEventListener("abort",r,{once:!0}),i.addEventListener("message",e=>{try{t.message(JSON.parse(String(e.data)),o)}catch{}}),i.addEventListener("error",()=>{i.readyState!==WebSocket.OPEN&&s(Error(`Could not connect to ${new URL(e).host}`))}),i.addEventListener("close",e=>{a.removeEventListener("abort",r),n({code:e.code,reason:e.reason})})})}])},854455,e=>{"use strict";var t=e.i(417043),a=e.i(903438);let n={4004:"Discord did not take the bot token.",4013:"Discord refused the intents this bot asked for.",4014:"Discord refused an intent this bot is not allowed — check the bot's page."};e.s(["createDiscord",0,function(e){async function s(a,n,s){let i=s instanceof FormData,o=await fetch(`https://discord.com/api/v10${n}`,{method:a,headers:{authorization:`Bot ${e}`,...i||!s?{}:{"content-type":"application/json"}},body:i?s:s?JSON.stringify(s):void 0});if(o.ok)return 204===o.status?null:await o.json();let r=await o.json().catch(()=>null),l=r?.message??`Discord answered ${o.status}`;throw 401===o.status?new t.ChannelRefusal(l):Error(l)}let i=e=>{let t=e.length<=5?1:5,a=[];for(let n=0;n<e.length&&a.length<5;n+=t)a.push({type:1,components:e.slice(n,n+t).map(e=>({type:2,style:2,label:e.text.slice(0,80),custom_id:e.data}))});return a};return{async listen(i,o){let r,l=null;try{let c=await (0,a.runSocket)("wss://gateway.discord.gg/?v=10&encoding=json",{message(t,a){let{op:n,d:o,s:c,t:h}=t;if(null!==c&&(l=c),10===n){let t=o.heartbeat_interval;r=setInterval(()=>a({op:1,d:l}),t),a({op:2,d:{token:e,intents:4096,properties:{os:process.platform,browser:"thursday",device:"thursday"}}})}else if(1===n)a({op:1,d:l});else if(0===n&&"READY"===h)i.ready(o.user.username);else if(0===n&&h){var d,u;let e=(d=h,u=o,"MESSAGE_CREATE"===d?u.guild_id||u.author.bot?null:{kind:"message",chat:u.channel_id,name:u.author.global_name||u.author.username,words:u.content.trim(),files:(u.attachments??[]).map(e=>({name:e.filename,fetch:async()=>{let t=await fetch(e.url);if(!t.ok)throw Error(`Discord answered ${t.status} for the file`);return new File([await t.arrayBuffer()],e.filename,{type:e.content_type??""})}})),unreadable:!1}:"INTERACTION_CREATE"===d?3!==u.type||u.guild_id?null:(s("POST",`/interactions/${u.id}/${u.token}/callback`,{type:6}).catch(()=>{}),{kind:"press",chat:u.channel_id,data:u.data?.custom_id??"",under:u.message?{id:u.message.id,text:u.message.content}:null}):null);e&&i.incoming(e)}}},o),h=n[c.code];if(h)throw new t.ChannelRefusal(h);if(!o.aborted)throw Error(`Discord closed the connection (${c.code})`)}finally{clearInterval(r)}},async say(e,t,n){let o=(0,a.inPieces)(t,1900);for(let[t,a]of o.entries())await s("POST",`/channels/${e}/messages`,{content:a,...n?.length&&t===o.length-1?{components:i(n)}:{}})},async typing(e){await s("POST",`/channels/${e}/typing`).catch(()=>{})},async settle(e,t,a){await s("PATCH",`/channels/${e}/messages/${t}`,{content:a.slice(0,1900),components:[]}).catch(()=>{})},async sendFile(e,t,a){let n=new FormData;n.set("payload_json",JSON.stringify({attachments:[{id:0,filename:a}]})),n.set("files[0]",new Blob([t]),a),await s("POST",`/channels/${e}/messages`,n)}}}])},426455,e=>{"use strict";var t=e.i(853205),a=e.i(333925),n=e.i(938281);e.i(556325),t.z.object({session:t.z.object({id:t.z.string().min(1)}),transport:t.z.object({type:t.z.literal("webrtc"),sdp:t.z.string().min(1)})});let s=new Map;async function i(e){let{apiKey:t,model:i,effort:o}=e,r=`${i} ${o??"auto"}`,l=s.get(r);if(void 0!==l)return l;let c="none"===o?{effort:o}:{...o?{effort:o}:{},summary:"auto"};for(;;){let e=await fetch("https://api.openai.com/v1/responses/input_tokens",{method:"POST",headers:{Authorization:`Bearer ${t}`,"Content-Type":"application/json"},signal:AbortSignal.timeout(a.LIVE_CALL.reasoningCheckMs),body:JSON.stringify({model:i,input:".",reasoning:c})}).catch(()=>null);if(!e)return c;let o=Object.keys(c).length?c:null;if(e.ok)return s.set(r,o),o;let l=await e.json().catch(()=>null),h=l?.error?.param?.replace(/^reasoning\./,"");if("effort"!==h&&"summary"!==h||!(h in c))return c;if(n.logger.warn(`${i} takes no reasoning ${h}; calls omit it`),delete c[h],!Object.keys(c).length)return s.set(r,null),null}}e.s(["acceptedReasoning",0,i])}];
67
67
 
68
68
  //# sourceMappingURL=_0x-ej3f._.js.map
@@ -1,6 +1,6 @@
1
- module.exports=[851372,e=>e.a(async(t,a)=>{try{var r=e.i(343747),o=e.i(687388),n=e.i(353885),i=e.i(393189),s=e.i(265143),l=e.i(944971),d=e.i(378884),h=e.i(148831),u=e.i(619898),c=e.i(636882),w=e.i(629668),p=e.i(786025),b=e.i(704161),m=e.i(41444),f=e.i(660948),y=e.i(54282),g=t([s,d,h,u,f]);async function T(e,t,a,g){var T,v,$,W,q,x,R,O,M;let A,S,N,E,C,_,D=await (0,p.openWorkspace)(),B=e.trim(),[U,P,j,H,L,Y,F,J,K]=await Promise.all([(0,c.loadSkills)(D,B),(0,u.listNoteIndex)(),(0,f.listConnectedToolNames)(),(0,h.findPinnedTools)(B),(0,s.listJobBots)(),(0,i.listBotMemory)(B),(0,s.readBotMemoryOn)(),(0,p.readMachineTools)(D),(0,d.listBotWork)(B,a?.thread??null)]),z=L.filter(e=>e.name!==B),G=[(T=B,v=a,S=(A=v?.owner??T)===T?"**You** coordinate this thread: its result goes from you to Thursday.":`**${A}** coordinates this thread and brings its result to Thursday.`,N=v?`
1
+ module.exports=[851372,e=>e.a(async(t,a)=>{try{var r=e.i(343747),o=e.i(687388),n=e.i(186304),i=e.i(353885),s=e.i(393189),l=e.i(265143),d=e.i(944971),h=e.i(378884),u=e.i(148831),c=e.i(619898),w=e.i(636882),p=e.i(629668),b=e.i(786025),m=e.i(704161),f=e.i(41444),y=e.i(660948),g=e.i(54282),T=t([l,h,u,c,y]);async function k(e,t,a,n){var T,k,$,W,q,x,R,O,M;let A,S,N,E,C,_,D=await (0,b.openWorkspace)(),B=e.trim(),[U,P,j,H,L,Y,F,J,K]=await Promise.all([(0,w.loadSkills)(D,B),(0,c.listNoteIndex)(),(0,y.listConnectedToolNames)(),(0,u.findPinnedTools)(B),(0,l.listJobBots)(),(0,s.listBotMemory)(B),(0,l.readBotMemoryOn)(),(0,b.readMachineTools)(D),(0,h.listBotWork)(B,a?.thread??null)]),G=L.filter(e=>e.name!==B),z=[(T=B,k=a,S=(A=k?.owner??T)===T?"**You** coordinate this thread: its result goes from you to Thursday.":`**${A}** coordinates this thread and brings its result to Thursday.`,N=k?`
2
2
 
3
- Current conversation: ${v.caller} → ${T}. Your final text goes back to ${v.caller}. Message ID: ${v.messageId??"initial request"}.`:"",`You are ${T}, one of the bots in this thread. ${(0,y.nowLine)()}
3
+ Current conversation: ${k.caller} → ${T}. Your final text goes back to ${k.caller}. Message ID: ${k.messageId??"initial request"}.`:"",`You are ${T}, one of the bots in this thread. ${(0,g.nowLine)()}
4
4
 
5
5
  - **The user** — the one person all of this is for. They talk with Thursday by voice and follow this thread on their screen.
6
6
  - **Thursday** — their personal assistant. She talks with them, hands bots the work that takes time, and tells them what comes back.
@@ -11,34 +11,34 @@ Current conversation: ${v.caller} → ${T}. Your final text goes back to ${v.cal
11
11
 
12
12
  **Never present a guess as a result.** Thursday says what you return out loud, as fact: say which part is unverified and why.`),($=P,`## Thursday's memory of the user
13
13
 
14
- What Thursday keeps from talking with them. When the job needs something about them, open the note with \`${n.TOOL_NAMES.memory_recall}\`; a fact marked \`said\` came from a call, and \`${n.TOOL_NAMES.memory_conversation}\` opens that call. What you learn about them goes in your answer — Thursday decides what to keep.
14
+ What Thursday keeps from talking with them. When the job needs something about them, open the note with \`${i.TOOL_NAMES.memory_recall}\`; a fact marked \`said\` came from a call, and \`${i.TOOL_NAMES.memory_conversation}\` opens that call. What you learn about them goes in your answer — Thursday decides what to keep.
15
15
 
16
16
  path — what is under it (facts) "what the user calls it"
17
17
 
18
- ${(0,y.noteLines)($)}`),function(e,t){let a=new Set(t.map(e=>`${e.server}/${e.name}`)),r=e.filter(e=>!a.has(`${e.server}/${e.name}`));if(0===r.length)return"";let o=a.size?" The ones you already hold are in your tools instead.":"";return`## Connected tools
18
+ ${(0,g.noteLines)($)}`),function(e,t){let a=new Set(t.map(e=>`${e.server}/${e.name}`)),r=e.filter(e=>!a.has(`${e.server}/${e.name}`));if(0===r.length)return"";let o=a.size?" The ones you already hold are in your tools instead.":"";return`## Connected tools
19
19
 
20
- ${(0,y.mcpToolLines)(r)}
20
+ ${(0,g.mcpToolLines)(r)}
21
21
 
22
- Names only: \`${n.TOOL_NAMES.tool_search}\` returns what each one takes, \`${n.TOOL_NAMES.tool_call}\` runs one.${o}`}(j,H),(W=U,0===W.length?"":`## Skills
22
+ Names only: \`${i.TOOL_NAMES.tool_search}\` returns what each one takes, \`${i.TOOL_NAMES.tool_call}\` runs one.${o}`}(j,H),(W=U,0===W.length?"":`## Skills
23
23
 
24
- Written-down ways of doing things. Open one with \`${n.TOOL_NAMES.load_skill}\` before a job it covers, unless its instructions are already in your conversation.
24
+ Written-down ways of doing things. Open one with \`${i.TOOL_NAMES.load_skill}\` before a job it covers, unless its instructions are already in your conversation.
25
25
 
26
- ${(0,y.skillLines)(W)}`),I(D.cwd,J,g),F?(q=(0,i.botMemoryFolder)(B),E=(x=Y).entries.length?x.entries.map(({file:e,line:t,at:a})=>{let n=t?` — ${(0,m.clip)(t,o.PROMPT_LINE.botMemory)}`:"";return`- ${e}${n} \xb7 ${(0,r.format)((0,b.toDate)(a),"yyyy-MM-dd")}`}).join("\n"):"Empty.",C=x.total>x.entries.length?`
26
+ ${(0,g.skillLines)(W)}`),v(D.cwd,J,n),F?(q=(0,s.botMemoryFolder)(B),E=(x=Y).entries.length?x.entries.map(({file:e,line:t,at:a})=>{let n=t?` — ${(0,f.clip)(t,o.PROMPT_LINE.botMemory)}`:"";return`- ${e}${n} \xb7 ${(0,r.format)((0,m.toDate)(a),"yyyy-MM-dd")}`}).join("\n"):"Empty.",C=x.total>x.entries.length?`
27
27
 
28
28
  The newest ${x.entries.length} of ${x.total}; \`ls ${q}\` for the rest.`:"",`## Your memory
29
29
 
30
30
  What you learned on your own earlier jobs, in \`${q}/\`: one topic per file, its first line saying what it holds, read by no other bot, up to ${o.BOT_MEMORY_LIMITS.files} files of ${o.BOT_MEMORY_LIMITS.chars.toLocaleString("en-US")} characters each. It is how you get better at this work. When a job teaches you something a later one would otherwise find out again — how a site signs in, the way through its screens, a command that turned out right — or the user asks you to remember how to work, keep it with the date it was true, and fix or delete what proved wrong. No passwords, keys or codes.
31
31
 
32
- ${E}${C}`):"",function(e,t){if(!t.open.length&&!t.recent.length)return"";let a=t=>{let a=t.said?` — ${(0,m.clip)(t.said,o.BOT_WORK.said)}`:"",r=t.said?(0,w.pathsIn)(t.said).slice(0,o.BOT_WORK.files):[],n=r.length?` \xb7 ${r.map(e=>`\`${e}\``).join(", ")}`:"";return`- ${t.cut?`[${(0,l.workHandle)(t.id)}] `:""}${(0,y.botWorkHead)(t,e)}${a}${n}`},r=(e,t)=>t.length?`${e}
33
- ${t.map(a).join("\n")}`:"",i=[...t.open,...t.recent].some(e=>e.cut)?` A line with an id in brackets was cut short: \`${n.TOOL_NAMES.thread_recall}\` opens that one whole, for when this job builds on it.`:"";return`## Your other threads
32
+ ${E}${C}`):"",function(e,t){if(!t.open.length&&!t.recent.length)return"";let a=t=>{let a=t.said?` — ${(0,f.clip)(t.said,o.BOT_WORK.said)}`:"",r=t.said?(0,p.pathsIn)(t.said).slice(0,o.BOT_WORK.files):[],n=r.length?` \xb7 ${r.map(e=>`\`${e}\``).join(", ")}`:"";return`- ${t.cut?`[${(0,d.workHandle)(t.id)}] `:""}${(0,g.botWorkHead)(t,e)}${a}${n}`},r=(e,t)=>t.length?`${e}
33
+ ${t.map(a).join("\n")}`:"",n=[...t.open,...t.recent].some(e=>e.cut)?` A line with an id in brackets was cut short: \`${i.TOOL_NAMES.thread_recall}\` opens that one whole, for when this job builds on it.`:"";return`## Your other threads
34
34
 
35
- Your threads besides this one. You remember none of them here: each line is where it stands, your own last words there, and the files those words name.${i}
35
+ Your threads besides this one. You remember none of them here: each line is where it stands, your own last words there, and the files those words name.${n}
36
36
 
37
- ${[r("Open",t.open),r("Ended",t.recent)].filter(Boolean).join("\n")}`}(B,K),(R=z,0===R.length?"":`## Bots
37
+ ${[r("Open",t.open),r("Ended",t.recent)].filter(Boolean).join("\n")}`}(B,K),(R=G,0===R.length?"":`## Bots
38
38
 
39
39
  ${R.map(e=>`- **${e.name}** — ${e.description}`).join("\n")}
40
40
 
41
- These lines were written for the user: where one says "you", it means them. When part of the job is another bot's strength, bring it in with \`${n.TOOL_NAMES.send_message}\` rather than rebuilding it yourself.`),(O=B,M=a,_=(M?.owner??O)===O?"Bring what you received together into one result for Thursday: what was done, where it is, what you decided that the request did not say, and what is still open, at the detail the user asked for. Every file you name in it is drawn under your words in the thread and waits in the screen's corner for the user to open, so name each one you want them to see — the page to read first, then the rest.":`Your final text goes back to ${M?.caller??"whoever asked"}: give them everything they need to carry on.`,`## Working together
41
+ These lines were written for the user: where one says "you", it means them. When part of the job is another bot's strength, bring it in with \`${i.TOOL_NAMES.send_message}\` rather than rebuilding it yourself.`),(O=B,M=a,_=(M?.owner??O)===O?"Bring what you received together into one result for Thursday: what was done, where it is, what you decided that the request did not say, and what is still open, at the detail the user asked for. Every file you name in it is drawn under your words in the thread and waits in the screen's corner for the user to open, so name each one you want them to see — the page to read first, then the rest.":`Your final text goes back to ${M?.caller??"whoever asked"}: give them everything they need to carry on.`,`## Working together
42
42
 
43
43
  Nobody sees your work but you, and you see only what others send you, so whatever crosses between you has to stand on its own. A request says what is wanted, what is already known or done, and where the files are; an answer gives exact values, file paths and what is still unverified. Tell whoever is waiting when something they depend on changes. End your turn when you have nothing more to do now: replies arrive as new messages and wake you.
44
44
 
@@ -46,30 +46,32 @@ Ask Thursday with kind \`question\` only for a decision, permission or something
46
46
 
47
47
  ${_}
48
48
 
49
- Write in the user's language, and name the paths of finished work. In Markdown, reference images by absolute route (\`/api/file/${o.PATHS.artifacts}/…\`).`),k(t)].filter(Boolean).join("\n\n");return(0,y.logPromptSize)("bot",G),{text:G}}[s,d,h,u,f]=g.then?(await g)():g;let k=e=>e?.trim()?`## Owner's instructions
49
+ Write in the user's language, and name the paths of finished work. In Markdown, reference images by absolute route (\`/api/file/${o.PATHS.artifacts}/…\`).`),I(t)].filter(Boolean).join("\n\n");return(0,g.logPromptSize)("bot",z),{text:z}}[l,h,u,c,y]=T.then?(await T)():T;let I=e=>e?.trim()?`## Owner's instructions
50
50
 
51
51
  Written by the person this bot works for. Where these and anything above disagree, these win.
52
52
 
53
- ${e.trim()}`:"",I=(e,t,a)=>{var r;let i,s;return`## Environment
53
+ ${e.trim()}`:"",v=(e,t,a)=>{var r;let s,l;return`## Environment
54
54
 
55
55
  Current Cwd: ${e}
56
56
  Platform: ${process.platform}
57
- ${r=t,i=(e,t)=>`${e}: ${t.found.length?t.found.join(", "):"none"}.${t.missing.length?` Not here: ${t.missing.join(", ")}.`:""}`,s=r.managers.found.includes("pnpm")?" Use pnpm, not npm — this workspace is fenced for it (`pnpm-workspace.yaml`, `.npmrc`).":"",[i("Runtimes",r.runtimes),`${i("Package managers",r.managers)}${s}`,null===r.browser?"":`Browser: ${r.browser?"installed":"not installed"}.`].filter(Boolean).join("\n")}
57
+ ${r=t,s=(e,t)=>`${e}: ${t.found.length?t.found.join(", "):"none"}.${t.missing.length?` Not here: ${t.missing.join(", ")}.`:""}`,l=r.managers.found.includes("pnpm")?" Use pnpm, not npm — this workspace is fenced for it (`pnpm-workspace.yaml`, `.npmrc`).":"",[s("Runtimes",r.runtimes),`${s("Package managers",r.managers)}${l}`,null===r.browser?"":`Browser: ${r.browser?"installed":"not installed"}.`].filter(Boolean).join("\n")}
58
58
 
59
59
  Read off this machine as the job opened: what is already here, not the limit of what you can use.
60
60
 
61
- Your workspace, where \`${n.TOOL_NAMES.bash}\` runs. Everything you write goes in one of these folders, kept apart because what is in them lives for different lengths of time:
61
+ Your workspace, where \`${i.TOOL_NAMES.bash}\` runs. Everything you write goes in one of these folders, kept apart because what is in them lives for different lengths of time:
62
62
 
63
63
  - \`${a?.artifacts??o.PATHS.artifacts}/\` — finished work the user opens, one entry per result. Theirs, and it stays.
64
64
  - \`${o.PATHS.projects}/\` — code you build, one folder each; it outlives this job, and its dependencies install inside it, never at the workspace root.
65
65
  - \`${a?.scratch??o.PATHS.scratch}/\` — this job's working material, shared by every bot on it; cleared ${Math.round(o.WORKSPACE_KEEP.forMs/864e5)} days after the job ends.
66
66
  - \`${a?.own??o.PATHS.bots}/\` — yours across every job you run here: what you keep for next time.
67
67
 
68
- Inside the workspace, set up whatever the job needs yourself; installing anything machine-wide waits for the user's yes. Never the directory above the workspace — it is the app's, not the user's; outside the workspace, only where the user pointed you.`};e.s(["buildThreadOpening",0,function(e){if(e.routine){let{when:t,last:a}=e.routine,n=a?` Its last run ended ${(0,r.format)(a.at,"yyyy-MM-dd HH:mm")}: ${(0,m.clip)(a.said,o.PROMPT_LINE.jobOutcome)}`:" This is its first run.";return[{type:"text",text:`You are ${e.bot}. A routine the user set up hands you this thread: it starts by itself, ${t}, and nobody is watching as it does.${n}`},{type:"text",text:`## The routine → ${e.bot}: the job
68
+ Inside the workspace, set up whatever the job needs yourself; installing anything machine-wide waits for the user's yes. Never the directory above the workspace — it is the app's, not the user's; outside the workspace, only where the user pointed you.
69
+
70
+ ${(0,n.botGuideLine)()}`};e.s(["buildThreadOpening",0,function(e){if(e.routine){let{when:t,last:a}=e.routine,n=a?` Its last run ended ${(0,r.format)(a.at,"yyyy-MM-dd HH:mm")}: ${(0,f.clip)(a.said,o.PROMPT_LINE.jobOutcome)}`:" This is its first run.";return[{type:"text",text:`You are ${e.bot}. A routine the user set up hands you this thread: it starts by itself, ${t}, and nobody is watching as it does.${n}`},{type:"text",text:`## The routine → ${e.bot}: the job
69
71
 
70
72
  ${e.request.trim()}`}]}let t="user"===e.from?"The user":"Thursday";return[{type:"text",text:`You are ${e.bot}. ${t} hands you this thread${"user"===e.from?" on screen":" during a call"}.`},{type:"text",text:`## ${t} → ${e.bot}: the job
71
73
 
72
- ${e.request.trim()}`}]},"loadBotPrompt",0,T]),a()}catch(e){a(e)}},!1),585099,e=>e.a(async(t,a)=>{try{var r=e.i(68356),o=e.i(847841),n=e.i(687388),i=e.i(159479),s=e.i(386075),l=e.i(851372),d=e.i(316172),h=e.i(353885),u=e.i(944971),c=e.i(786025),w=e.i(640911),p=e.i(388439),b=e.i(265143),m=e.i(378884),f=t([i,s,l,d,b,m]);[i,s,l,d,b,m]=f.then?(await f)():f;let I=n.BOT_RUN.steps;async function y(e,t){var a,f;let y,k,$,W,q,x,R,O,M,A=t.parent??null,S=await (0,b.findJobBot)(e.bot.trim()),N=S?.name??e.bot.trim(),E=e=>t.emit({...e,bot:N,parent:A});if(!S)return void await E({type:"error",message:`No bot named "${e.bot}". Use a name from the list.`,retry:!1});let C=e.messages,_=await ((a=S).provider&&a.model?(0,s.getTextModel)({provider:a.provider,model:a.model}):(0,s.resolveDefaultModel)().then(s.getTextModel)),D=t.threadId?await (0,m.findThread)(t.threadId):null,[B,{own:U,artifacts:P}]=await Promise.all([t.threadId?(0,c.openJobScratch)(t.threadId,D?.label??"job"):null,(0,c.openBotFolders)(N)]),[j,H]=await Promise.all([(0,l.loadBotPrompt)(N,S.systemPrompt,{thread:t.threadId??null,owner:t.owner,caller:t.caller,messageId:A},{scratch:B,own:U,artifacts:P}),(0,i.loadTools)({target:"bot",bot:N,thread:t.threadId??null,session:t.session??(t.threadId?(0,c.botBrowserSession)(t.threadId,N):null),model:_})]),L=Math.min(await (0,s.compactBudget)(_.ref,S.compactAt),t.contextBudget||1/0),Y=!1,F={...H,[h.TOOL_NAMES.send_message]:(0,o.tool)({description:d.sendMessageSpec.description,inputSchema:d.sendMessageSpec.parameters,execute:async(e,a)=>{let r=await t.send({...e,id:a.toolCallId});return"question"===e.kind&&(Y=!0),r}})},J=new Set,K=(f=n.BOT_RUN.silenceMs,k=new AbortController,$=0,W=!1,q=()=>{clearTimeout(y),y=void 0,W||$>0||(y=setTimeout(()=>{k.abort(new DOMException(`The model sent nothing for ${Math.round(f/6e4)} minutes.`,"TimeoutError"))},f))},{signal:k.signal,touch:q,hold:()=>{$+=1,q()},release:()=>{$=Math.max(0,$-1),q()},end:()=>{W=!0,q()}});for(let[e,a]of Object.entries(F)){let r=a.execute;r&&(a.execute=(a,o)=>{let n=(async()=>{t.signal?.throwIfAborted(),await E({type:"tool",id:o.toolCallId,name:e,input:a}),K.hold();try{t.signal?.throwIfAborted();let n=await r(a,o);if(n&&"object"==typeof n&&Symbol.asyncIterator in n){let e;for await(let t of n)e=t;n=e}return await E({type:"tool-result",id:o.toolCallId,name:e,output:n}),n}catch(t){throw await E({type:"tool-result",id:o.toolCallId,name:e,output:(0,s.modelErrorToString)(t),error:!0}),t}finally{K.release()}})();return J.add(n),n.finally(()=>J.delete(n)).catch(()=>{}),n})}let z=Promise.resolve(),G=()=>{},Q=0,V=new r.ToolLoopAgent({model:_.model,instructions:j.text,tools:F,stopWhen:[(0,r.stepCountIs)(I),()=>Y],prepareStep:async({stepNumber:e,steps:a,messages:r})=>{await z,t.signal?.throwIfAborted();let o={},n=a.at(-1)?.usage.inputTokens??0,i=Math.max(n,r.reduce((e,t)=>e+(0,p.estimateTokens)("string"==typeof t.content?t.content:JSON.stringify(t.content))+4,0));Q=i;let s=r,l=t.compactNow?.()??!1;if((i>L||l)&&r.length>2){K.hold();let e=await T(_.model,F,r,{signal:t.signal,budget:L,instructions:j.text}).finally(K.release);w.logger.debug(`compacted ${r.length} messages at ${i} tokens (budget ${L})`);let a=`${e.text}${await g(D?.id??null,r,B)}`;await E({type:"compact",text:a,usage:e.usage,messages:r.length,tokens:i}),s=[r[0],{role:"user",content:a}]}let d=e>0?await t.notes?.()??[]:[];return(d.length&&(s=[...s,...d.map(e=>({role:"user",content:e}))]),s===r)?o:{...o,messages:s}}}),X=(x=[],R=[],O=!1,{push(e){let t=R.shift();t?t(e):x.push(e)},take(){let e=x.shift();return e?Promise.resolve(e):O?Promise.resolve(null):new Promise(e=>R.push(e))},end(){for(let e of(O=!0,R.splice(0)))e(null)}}),Z=t.signal?AbortSignal.any([t.signal,K.signal]):K.signal;K.touch();let ee=new AbortController,et=AbortSignal.any([Z,ee.signal]);try{M=await V.stream({messages:C,abortSignal:et,onStepEnd:e=>{z=new Promise(e=>{G=e}),X.push({messages:e.response.messages,usage:v(e.usage)})}})}catch(e){throw K.end(),ee.abort(),await Promise.allSettled([...J]),e}let ea="",er="",eo=null,en=e=>{w.logger.error(`${N}: the model run broke`,e);let t=(0,s.modelErrorToString)(e),a=!(0,s.isProviderRefusal)(e);if(!(0,s.isContextOverflow)(e))return{type:"error",message:t,retry:a};let r=Math.floor(Math.min(L,Q||L)*n.BOT_RUN.overflowShrink);return{type:"error",message:t,budget:Math.max(u.COMPACT_AT_MIN,r),retry:a}};Z.addEventListener("abort",()=>{X.end(),G()},{once:!0});try{for await(let e of M.stream)switch(K.touch(),e.type){case"start-step":er="",ea="";break;case"text-delta":ea+=e.text;break;case"text-end":{let e=ea.trim();if(ea="",!e)break;er=[er,e].filter(Boolean).join("\n\n"),await E({type:"text",text:e});break}case"tool-call":await E({type:"tool",id:e.toolCallId,name:e.toolName,input:e.input,providerExecuted:e.providerExecuted,providerOptions:e.providerMetadata});break;case"tool-result":await E({type:"tool-result",id:e.toolCallId,name:e.toolName,output:e.output});break;case"tool-error":await E({type:"tool-result",id:e.toolCallId,name:e.toolName,output:(0,s.modelErrorToString)(e.error),error:!0});break;case"finish-step":{eo=e.finishReason;let t=await X.take();t&&await E({type:"step",...t,budget:L}),G();break}case"abort":if(t.signal?.aborted)return;await E(en(e.reason??"The model stopped sending."));return;case"error":await E(en(e.error));return}}finally{ee.abort(),X.end(),K.end(),G(),await Promise.allSettled([...J])}try{await M.finalStep}catch(e){if(t.signal?.aborted)return;await E(en(e));return}"content-filter"===eo?await E({type:"error",message:"The provider's content filter stopped the response.",retry:!1}):await E({type:"turn-end",text:er,stopped:!Y&&("length"===eo||"error"===eo||"tool-calls"===eo)})}async function g(e,t,a){try{let r=e?await (0,m.listWrittenPaths)(e):(0,m.writtenPathsIn)(t.map(e=>e.content)),o=await (0,c.filesOnDisk)(r,a);if(!o.length)return"";let i=o.slice(-n.BOT_RUN.compactFiles),s=o.length-i.length,l=i.map(e=>`- ${e}`);return s&&l.unshift(`- …and ${s} older ones`),`
74
+ ${e.request.trim()}`}]},"loadBotPrompt",0,k]),a()}catch(e){a(e)}},!1),585099,e=>e.a(async(t,a)=>{try{var r=e.i(68356),o=e.i(847841),n=e.i(687388),i=e.i(159479),s=e.i(386075),l=e.i(851372),d=e.i(316172),h=e.i(353885),u=e.i(944971),c=e.i(786025),w=e.i(640911),p=e.i(388439),b=e.i(265143),m=e.i(378884),f=t([i,s,l,d,b,m]);[i,s,l,d,b,m]=f.then?(await f)():f;let I=n.BOT_RUN.steps;async function y(e,t){var a,f;let y,k,$,W,q,x,R,O,M,A=t.parent??null,S=await (0,b.findJobBot)(e.bot.trim()),N=S?.name??e.bot.trim(),E=e=>t.emit({...e,bot:N,parent:A});if(!S)return void await E({type:"error",message:`No bot named "${e.bot}". Use a name from the list.`,retry:!1});let C=e.messages,_=await ((a=S).provider&&a.model?(0,s.getTextModel)({provider:a.provider,model:a.model}):(0,s.resolveDefaultModel)().then(s.getTextModel)),D=t.threadId?await (0,m.findThread)(t.threadId):null,[B,{own:U,artifacts:P}]=await Promise.all([t.threadId?(0,c.openJobScratch)(t.threadId,D?.label??"job"):null,(0,c.openBotFolders)(N)]),[j,H]=await Promise.all([(0,l.loadBotPrompt)(N,S.systemPrompt,{thread:t.threadId??null,owner:t.owner,caller:t.caller,messageId:A},{scratch:B,own:U,artifacts:P}),(0,i.loadTools)({target:"bot",bot:N,thread:t.threadId??null,session:t.session??(t.threadId?(0,c.botBrowserSession)(t.threadId,N):null),model:_})]),L=Math.min(await (0,s.compactBudget)(_.ref,S.compactAt),t.contextBudget||1/0),Y=!1,F={...H,[h.TOOL_NAMES.send_message]:(0,o.tool)({description:d.sendMessageSpec.description,inputSchema:d.sendMessageSpec.parameters,execute:async(e,a)=>{let r=await t.send({...e,id:a.toolCallId});return"question"===e.kind&&(Y=!0),r}})},J=new Set,K=(f=n.BOT_RUN.silenceMs,k=new AbortController,$=0,W=!1,q=()=>{clearTimeout(y),y=void 0,W||$>0||(y=setTimeout(()=>{k.abort(new DOMException(`The model sent nothing for ${Math.round(f/6e4)} minutes.`,"TimeoutError"))},f))},{signal:k.signal,touch:q,hold:()=>{$+=1,q()},release:()=>{$=Math.max(0,$-1),q()},end:()=>{W=!0,q()}});for(let[e,a]of Object.entries(F)){let r=a.execute;r&&(a.execute=(a,o)=>{let n=(async()=>{t.signal?.throwIfAborted(),await E({type:"tool",id:o.toolCallId,name:e,input:a}),K.hold();try{t.signal?.throwIfAborted();let n=await r(a,o);if(n&&"object"==typeof n&&Symbol.asyncIterator in n){let e;for await(let t of n)e=t;n=e}return await E({type:"tool-result",id:o.toolCallId,name:e,output:n}),n}catch(t){throw await E({type:"tool-result",id:o.toolCallId,name:e,output:(0,s.modelErrorToString)(t),error:!0}),t}finally{K.release()}})();return J.add(n),n.finally(()=>J.delete(n)).catch(()=>{}),n})}let G=Promise.resolve(),z=()=>{},Q=0,V=new r.ToolLoopAgent({model:_.model,instructions:j.text,tools:F,stopWhen:[(0,r.stepCountIs)(I),()=>Y],prepareStep:async({stepNumber:e,steps:a,messages:r})=>{await G,t.signal?.throwIfAborted();let o={},n=a.at(-1)?.usage.inputTokens??0,i=Math.max(n,r.reduce((e,t)=>e+(0,p.estimateTokens)("string"==typeof t.content?t.content:JSON.stringify(t.content))+4,0));Q=i;let s=r,l=t.compactNow?.()??!1;if((i>L||l)&&r.length>2){K.hold();let e=await T(_.model,F,r,{signal:t.signal,budget:L,instructions:j.text}).finally(K.release);w.logger.debug(`compacted ${r.length} messages at ${i} tokens (budget ${L})`);let a=`${e.text}${await g(D?.id??null,r,B)}`;await E({type:"compact",text:a,usage:e.usage,messages:r.length,tokens:i}),s=[r[0],{role:"user",content:a}]}let d=e>0?await t.notes?.()??[]:[];return(d.length&&(s=[...s,...d.map(e=>({role:"user",content:e}))]),s===r)?o:{...o,messages:s}}}),X=(x=[],R=[],O=!1,{push(e){let t=R.shift();t?t(e):x.push(e)},take(){let e=x.shift();return e?Promise.resolve(e):O?Promise.resolve(null):new Promise(e=>R.push(e))},end(){for(let e of(O=!0,R.splice(0)))e(null)}}),Z=t.signal?AbortSignal.any([t.signal,K.signal]):K.signal;K.touch();let ee=new AbortController,et=AbortSignal.any([Z,ee.signal]);try{M=await V.stream({messages:C,abortSignal:et,onStepEnd:e=>{G=new Promise(e=>{z=e}),X.push({messages:e.response.messages,usage:v(e.usage)})}})}catch(e){throw K.end(),ee.abort(),await Promise.allSettled([...J]),e}let ea="",er="",eo=null,en=e=>{w.logger.error(`${N}: the model run broke`,e);let t=(0,s.modelErrorToString)(e),a=!(0,s.isProviderRefusal)(e);if(!(0,s.isContextOverflow)(e))return{type:"error",message:t,retry:a};let r=Math.floor(Math.min(L,Q||L)*n.BOT_RUN.overflowShrink);return{type:"error",message:t,budget:Math.max(u.COMPACT_AT_MIN,r),retry:a}};Z.addEventListener("abort",()=>{X.end(),z()},{once:!0});try{for await(let e of M.stream)switch(K.touch(),e.type){case"start-step":er="",ea="";break;case"text-delta":ea+=e.text;break;case"text-end":{let e=ea.trim();if(ea="",!e)break;er=[er,e].filter(Boolean).join("\n\n"),await E({type:"text",text:e});break}case"tool-call":await E({type:"tool",id:e.toolCallId,name:e.toolName,input:e.input,providerExecuted:e.providerExecuted,providerOptions:e.providerMetadata});break;case"tool-result":await E({type:"tool-result",id:e.toolCallId,name:e.toolName,output:e.output});break;case"tool-error":await E({type:"tool-result",id:e.toolCallId,name:e.toolName,output:(0,s.modelErrorToString)(e.error),error:!0});break;case"finish-step":{eo=e.finishReason;let t=await X.take();t&&await E({type:"step",...t,budget:L}),z();break}case"abort":if(t.signal?.aborted)return;await E(en(e.reason??"The model stopped sending."));return;case"error":await E(en(e.error));return}}finally{ee.abort(),X.end(),K.end(),z(),await Promise.allSettled([...J])}try{await M.finalStep}catch(e){if(t.signal?.aborted)return;await E(en(e));return}"content-filter"===eo?await E({type:"error",message:"The provider's content filter stopped the response.",retry:!1}):await E({type:"turn-end",text:er,stopped:!Y&&("length"===eo||"error"===eo||"tool-calls"===eo)})}async function g(e,t,a){try{let r=e?await (0,m.listWrittenPaths)(e):(0,m.writtenPathsIn)(t.map(e=>e.content)),o=await (0,c.filesOnDisk)(r,a);if(!o.length)return"";let i=o.slice(-n.BOT_RUN.compactFiles),s=o.length-i.length,l=i.map(e=>`- ${e}`);return s&&l.unshift(`- …and ${s} older ones`),`
73
75
 
74
76
  Files this job has on disk now — open one rather than fetching again what is in it:
75
77
  ${l.join("\n")}`}catch(e){return w.logger.warn("files under the summary could not be listed",e),""}}async function T(e,t,a,o){let n;try{return await k(e,t,a,o)}catch(e){if(o.signal?.aborted)throw e;n=e}if((0,s.isContextOverflow)(n)){let i=(0,r.pruneMessages)({messages:a,toolCalls:"before-last-4-messages",emptyMessages:"remove"});try{return await k(e,t,i,o)}catch(e){if(o.signal?.aborted)throw e;n=e}}throw Error(`Could not compact the context (${(0,s.modelErrorToString)(n)}).`,{cause:n})}async function k(e,t,a,o){let i,{text:s,usage:l}=await (0,r.generateText)({model:e,instructions:o.instructions,tools:t,toolChoice:"none",messages:[...a,{role:"user",content:(i=(e=>{let{min:t,max:a,perTokens:r}=n.BOT_RUN.summaryWords;return Math.min(a,Math.max(t,Math.round(e/r)))})(o.budget),`Compact your context. The first message above — who handed you the job, and the job — stays exactly as it is. Everything after it is replaced by what you write now, and you carry on from that first message and this alone; nothing else above can be read again. Write it for a fresh copy of you that has your tools, your instructions and that first message, but has seen none of the rest.
@@ -86,7 +88,7 @@ Cover all of it, and prefer a fact over a description of a fact:
86
88
  Plain text, under ${i} words. No preamble, no headings about the summary itself, no account of how you have been going.`)}],abortSignal:o.signal,timeout:n.BOT_RUN.silenceMs}),d=s.trim();if(!d)throw Object.assign(Error("The summary of the context came back empty, so there is nothing to carry on from."),{isRetryable:!0});return{text:`Everything between the first message and here was compacted. Below is your own summary of it; carry on from the first message and this.
87
89
 
88
90
  ${d}`,usage:v(l)}}let v=e=>({input:e.inputTokens??0,output:e.outputTokens??0});e.s(["resumeTranscript",0,function(e,t=new Map){let a=new Map,r=new Set;for(let t of e)if(("tool"===t.role||"assistant"===t.role)&&Array.isArray(t.content))for(let e of t.content)"tool-result"===e.type&&(a.has(e.toolCallId)||a.set(e.toolCallId,e),"assistant"===t.role&&r.add(e.toolCallId));let o=[],n=new Set;for(let i of e){if("tool"===i.role){let e=i.content.filter(e=>"tool-result"!==e.type);e.length&&o.push({...i,content:e});continue}if("assistant"!==i.role||"string"==typeof i.content){o.push(i);continue}let e=[],s=[];for(let o of i.content){if("tool-call"!==o.type){s.push(o);continue}if(n.has(o.toolCallId))continue;let i=o.input;if("string"==typeof i)try{i=JSON.parse(i)}catch{i=void 0}if(!o.toolCallId||void 0===i){s.push({type:"text",text:"A tool argument stream was interrupted before a complete call was recorded. Inspect the saved work before continuing."});continue}let l=o.toolName===h.TOOL_NAMES.send_message?t.get(o.toolCallId):void 0,d=a.get(o.toolCallId)??(l?{type:"tool-result",toolCallId:o.toolCallId,toolName:o.toolName,output:{type:"json",value:l}}:void 0);if(o.providerExecuted&&(!d||!r.has(o.toolCallId))){s.push({type:"text",text:d?`The provider operation ${o.toolName} returned this data before its native continuation was interrupted: ${JSON.stringify(d.output)}`:`The provider operation ${o.toolName} was interrupted without a recorded result. Its remote execution state is unknown.`});continue}n.add(o.toolCallId),s.push({...o,input:i}),r.has(o.toolCallId)||e.push(d??{type:"tool-result",toolCallId:o.toolCallId,toolName:o.toolName,output:{type:"text",value:"No result: execution was interrupted before a result was recorded. The outcome is unknown. Inspect the current state before repeating the action."}})}s.length&&o.push({...i,content:s}),e.length&&o.push({role:"tool",content:e})}return o},"runBot",0,y]),a()}catch(e){a(e)}},!1),39803,e=>e.a(async(t,a)=>{try{var r=e.i(136340),o=e.i(380690),n=e.i(687388),i=e.i(386075),s=e.i(851372),l=e.i(22676),d=e.i(629668),h=e.i(786025),u=e.i(167004),c=e.i(640911),w=e.i(53748),p=e.i(268486),b=e.i(41444),m=e.i(265143),f=e.i(585099),y=e.i(944971),g=e.i(742712),T=e.i(889034),k=e.i(378884),I=t([i,s,l,m,f,g,k]);[i,s,l,m,f,g,k]=I.then?(await I)():I;let D=globalThis.__roomRuns??=new Map,B=globalThis.__roomThreadLock??=(0,p.createKeyedLock)(),U=globalThis.__roomPausing??={current:Promise.resolve()},P=globalThis.__roomCompactAsked??=new Set,j=(e,t)=>`${e}
89
- ${t}`;async function v(e){let t=await (0,m.findJobBot)(e.bot);(!t||t.disabled)&&(0,w.publicError)("Choose an enabled bot.");let{from:a,routine:r,...o}={...e,bot:t.name},n=(0,s.buildThreadOpening)({bot:o.bot,request:o.request,from:a,routine:r}),i=await (0,k.insertThread)({...o,routineId:r?.id??null,opening:n});return await W(i.id),i.id}async function $(e,t,a="user",r,o){let n=null;return await B(e,async()=>{let i=await (0,k.findThread)(e);if(i||(0,w.publicError)("No such thread."),r){let t=(await (0,g.listRoomWork)(e)).find(e=>e.bot.toLowerCase()===r.trim().toLowerCase());t&&t.bot!==T.ROOM_THURSDAY||(0,w.publicError)("Choose a participant in this thread."),r=t.bot}t.trim()===y.THREAD_CONTINUE&&(0,y.isAppStop)(i.pending)?(await (0,g.resumeRoom)(e),(await (0,g.listRoomWork)(e)).some(e=>"queued"===e.state)||(n=await (0,g.tellRoom)(e,"Continue from the saved conversation.","user"===a?"The user":T.ROOM_THURSDAY,r,void 0,!1))):n=await (0,g.tellRoom)(e,t,"user"===a?"The user":T.ROOM_THURSDAY,r,o)}),await W(e),n}async function W(e){await B(e,async()=>{if(!o.presence.watching&&!await (0,m.readKeepWorkingOn)()){let t=await (0,k.findThread)(e);t?.status!=="running"||[...D.values()].some(t=>t.threadId===e)||await (0,g.pauseRoom)(e,"The app is not open. Work resumes when it returns.",!0);return}for(let t=0;t<2;t++){let t;for(;t=await (0,g.claimRoomWork)(e);)!function(e){let t,a=new AbortController,r=new Promise(e=>{t=e});D.set(e.id,{threadId:e.threadId,stop:a,done:r}),q(e,a.signal).catch(t=>c.logger.error(`thread ${e.threadId}: participant`,t)).finally(()=>{D.delete(e.id),t(),W(e.threadId).catch(t=>c.logger.error(`thread ${e.threadId}: scheduling`,t))})}(t);await (0,g.settleRoom)(e)}})}async function q(e,t){let a=await x(e,t);if(a?.failure?.retry&&!t.aborted&&(await (0,g.noteRoomBreak)(e,a.failure.message),await (0,r.setTimeout)(n.BOT_RUN.retryMs,void 0,{signal:t}).catch(()=>{}),t.aborted||(a=await x(e,t))),!a||t.aborted)return;let i=a.failure?.message,s=a.ending;if(i||!s||s.stopped){let t=i??"The turn was interrupted. Continue from the saved conversation.";B(e.threadId,async()=>{let a=(await (0,g.listRoomWork)(e.threadId)).find(t=>t.id===e.id);if(a?.state!=="running"||a.generation!==e.generation)return;let r=R(e.threadId);await (0,g.pauseRoom)(e.threadId,t),await r}).catch(t=>c.logger.error(`thread ${e.threadId}: pausing`,t));return}await (0,g.finishRoomWork)(e,s.text);let w=await (0,k.findThread)(e.threadId);if(w?.status==="done"){await (0,l.isAnyCallLive)()||(0,u.desktopNotify)(w.label,w.outcome??"");let e=await (0,h.filesOnDisk)((0,d.pathsIn)(w.outcome??""),null),t=e.findIndex(d.opensOnFinish);o.appEvents.emit({type:"finished",threadId:w.id,label:w.label,bot:w.bot,words:(0,b.plainText)(w.outcome??"").slice(0,n.FINISHED_NOTICE.words),paths:t>0?[e[t],...e.filter((e,a)=>a!==t)]:e})}}async function x(e,t){let a=new H(e,t),r=null,o=null;try{let n=await (0,k.findThread)(e.threadId);if(!n)return null;(await (0,g.listParticipantTranscript)(e.threadId,e.bot)).length||await (0,g.appendRoomMessage)(e.threadId,{bot:e.bot,parent:e.id,role:"user",content:`Request: ${n.request}
91
+ ${t}`;async function v(e){let t=await (0,m.findJobBot)(e.bot);(!t||t.disabled)&&(0,w.publicError)("Choose an enabled bot.");let{from:a,routine:r,...o}={...e,bot:t.name},n=(0,s.buildThreadOpening)({bot:o.bot,request:o.request,from:a,routine:r}),i=await (0,k.insertThread)({...o,routineId:r?.id??null,opening:n});return await W(i.id),i.id}async function $(e,t,a="user",r,o){let n=null;return await B(e,async()=>{let i=await (0,k.findThread)(e);if(i||(0,w.publicError)("No such thread."),r){let t=(await (0,g.listRoomWork)(e)).find(e=>e.bot.toLowerCase()===r.trim().toLowerCase());t&&t.bot!==T.ROOM_THURSDAY||(0,w.publicError)("Choose a participant in this thread."),r=t.bot}t.trim()===y.THREAD_CONTINUE&&(0,y.isAppStop)(i.pending)?(await (0,g.resumeRoom)(e),(await (0,g.listRoomWork)(e)).some(e=>"queued"===e.state)||(n=await (0,g.tellRoom)(e,"Continue from the saved conversation.","user"===a?"The user":T.ROOM_THURSDAY,r,void 0,!1))):n=await (0,g.tellRoom)(e,t,"user"===a?"The user":T.ROOM_THURSDAY,r,o)}),await W(e),n}async function W(e){await B(e,async()=>{if(!o.presence.watching&&!await (0,m.readKeepWorkingOn)()){let t=await (0,k.findThread)(e);t?.status!=="running"||[...D.values()].some(t=>t.threadId===e)||await (0,g.pauseRoom)(e,"The app is not open. Work resumes when it returns.",!0);return}for(let t=0;t<2;t++){let t;for(;t=await (0,g.claimRoomWork)(e);)!function(e){let t,a=new AbortController,r=new Promise(e=>{t=e});D.set(e.id,{threadId:e.threadId,stop:a,done:r}),q(e,a.signal).catch(t=>c.logger.error(`thread ${e.threadId}: participant`,t)).finally(()=>{D.delete(e.id),t(),W(e.threadId).catch(t=>c.logger.error(`thread ${e.threadId}: scheduling`,t))})}(t);await (0,g.settleRoom)(e)}})}async function q(e,t){let a=await x(e,t);if(a?.failure?.retry&&!t.aborted&&(await (0,g.noteRoomBreak)(e,a.failure.message),await (0,r.setTimeout)(n.BOT_RUN.retryMs,void 0,{signal:t}).catch(()=>{}),t.aborted||(a=await x(e,t))),!a||t.aborted)return;let i=a.failure?.message,s=a.ending;if(i||!s||s.stopped){let t=i??"The turn was interrupted. Continue from the saved conversation.";B(e.threadId,async()=>{let a=(await (0,g.listRoomWork)(e.threadId)).find(t=>t.id===e.id);if(a?.state!=="running"||a.generation!==e.generation)return;let r=R(e.threadId);await (0,g.pauseRoom)(e.threadId,t),await r}).catch(t=>c.logger.error(`thread ${e.threadId}: pausing`,t));return}await (0,g.finishRoomWork)(e,s.text);let w=await (0,k.findThread)(e.threadId);if(w?.status==="done"){o.presence.watching||await (0,l.isAnyCallLive)()||(0,u.desktopNotify)(w.label,w.outcome??"");let e=await (0,h.filesOnDisk)((0,d.pathsIn)(w.outcome??""),null),t=e.findIndex(d.opensOnFinish);o.appEvents.emit({type:"finished",threadId:w.id,label:w.label,bot:w.bot,words:(0,b.plainText)(w.outcome??"").slice(0,n.FINISHED_NOTICE.words),paths:t>0?[e[t],...e.filter((e,a)=>a!==t)]:e})}}async function x(e,t){let a=new H(e,t),r=null,o=null;try{let n=await (0,k.findThread)(e.threadId);if(!n)return null;(await (0,g.listParticipantTranscript)(e.threadId,e.bot)).length||await (0,g.appendRoomMessage)(e.threadId,{bot:e.bot,parent:e.id,role:"user",content:`Request: ${n.request}
90
92
  Coordinator: ${n.bot}. Continue as ${e.bot} in this thread.`,hidden:!0}),await (0,g.consumeRoomInbox)(e);let i=await (0,g.listParticipantTranscript)(e.threadId,e.bot);await (0,f.runBot)({bot:e.bot,messages:(0,f.resumeTranscript)(i,await (0,g.listRoomReceipts)(e.threadId,e.bot,i))},{signal:t,threadId:e.threadId,parent:e.id,caller:e.caller,owner:n.bot,contextBudget:await (0,g.roomContextBudget)(e.threadId,e.bot),compactNow:()=>P.delete(j(e.threadId,e.bot)),session:(0,h.botBrowserSession)(e.threadId,e.bot),notes:()=>(0,g.consumeRoomInbox)(e),send:async a=>{t.throwIfAborted();let r=a.to.trim();if(r.toLowerCase()===T.ROOM_THURSDAY.toLowerCase())r=T.ROOM_THURSDAY;else{let e=await (0,m.findJobBot)(r);(!e||e.disabled)&&(0,w.publicError)(`No enabled bot named "${r}".`),r=e.name}let o=await (0,g.sendRoomMessage)(e,{...a,to:r});return W(e.threadId).catch(e=>c.logger.error("room message scheduling",e)),o},emit:async i=>{(!t.aborted||"tool-result"===i.type)&&(await a.on(i),"step"===i.type&&await (0,k.addThreadUsage)(e.threadId,i.usage,e.bot===n.bot?{tokens:i.usage.input,budget:i.budget}:null),"compact"===i.type&&await (0,k.addThreadUsage)(e.threadId,i.usage),"turn-end"===i.type&&(r=i),"error"===i.type&&(o={message:i.message,retry:i.retry},i.budget&&await (0,g.lowerRoomContextBudget)(e,i.budget)))}})}catch(a){t.aborted||(c.logger.error(`thread ${e.threadId}: ${e.bot} broke`,a),o={message:(0,i.modelErrorToString)(a),retry:!(0,w.isPublicError)(a)&&!(0,i.isProviderRefusal)(a)})}return{ending:r,failure:o}}class H{work;signal;lane;assistant;tool;parts;calls;results;constructor(e,t){this.work=e,this.signal=t,this.lane=(0,b.PromiseChain)(),this.assistant=null,this.tool=null,this.parts={assistant:[],tool:[]},this.calls=new Set,this.results=new Set}async write(e,t,a=!1){let r={bot:this.work.bot,parent:this.work.id,role:t.role,content:t.content,compact:a,note:a};return null===e?(0,g.appendRoomMessage)(this.work.threadId,r):(await (0,k.upsertMessage)(this.work.threadId,e,r),e)}on(e){return this.lane(async()=>{if(!this.signal.aborted||"tool-result"===e.type)if("text"===e.type)this.parts.assistant.push({type:"text",text:e.text}),this.assistant=await this.write(this.assistant,{role:"assistant",content:this.parts.assistant});else if("tool"===e.type){if(this.calls.has(e.id)){let t=this.parts.assistant.find(t=>"tool-call"===t.type&&t.toolCallId===e.id);t&&"tool-call"===t.type&&e.providerOptions&&(t.providerOptions=e.providerOptions,this.assistant=await this.write(this.assistant,{role:"assistant",content:this.parts.assistant}));return}this.calls.add(e.id),this.parts.assistant.push({type:"tool-call",toolCallId:e.id,toolName:e.name,input:e.input,...e.providerExecuted?{providerExecuted:!0}:{},...e.providerOptions?{providerOptions:e.providerOptions}:{}}),this.assistant=await this.write(this.assistant,{role:"assistant",content:this.parts.assistant})}else if("tool-result"===e.type){if(this.results.has(e.id))return;this.results.add(e.id),this.parts.tool.push({type:"tool-result",toolCallId:e.id,toolName:e.name,output:e.error?{type:"error-text",value:String(e.output)}:"string"==typeof e.output?{type:"text",value:e.output}:{type:"json",value:e.output}}),this.tool=await this.write(this.tool,{role:"tool",content:this.parts.tool})}else if("step"===e.type){let t=[this.assistant,this.tool];for(let[a,r]of e.messages.entries())await this.write(t[a]??null,r);let a=t.slice(e.messages.length).filter(e=>null!==e);a.length&&await (0,k.deleteMessages)(this.work.threadId,a),this.assistant=this.tool=null,this.parts={assistant:[],tool:[]}}else"compact"===e.type&&await this.write(null,{role:"user",content:e.text},!0)})}}async function R(e){let t=[...D.values()].filter(t=>t.threadId===e);for(let e of t)e.stop.abort();await Promise.all(t.map(e=>e.done))}async function O(e){await B(e,async()=>{let t=await (0,k.findThread)(e);t||(0,w.publicError)("No such thread."),t.endedAt&&(0,w.publicError)("That thread has already ended."),await (0,g.cancelRoom)(e),await (0,k.updateThread)(e,{status:"cancelled",outcome:null,pending:null,seen:!0,endedAt:new Date}),await R(e),await (0,h.closeJobShell)(e)})}async function M(e){return B(e,()=>A(e))}async function A(e){let t=await (0,k.findThread)(e);await (0,g.cancelRoom)(e),await R(e),await (0,h.removeJobBrowsers)(e);let a=await (0,k.deleteThread)(e);return a&&t&&await (0,h.removeJobScratch)(e,t.label),a}async function S(){let e=0;for(let t of(await (0,k.listThreadFolders)()))("done"===t.status||"cancelled"===t.status)&&await B(t.id,async()=>{let a=await (0,k.findThread)(t.id);(a?.status==="done"||a?.status==="cancelled")&&await A(t.id)&&(e+=1)});return e}async function N(){let e=Date.now()-n.WORKSPACE_KEEP.forMs,t=t=>("done"===t.status||"cancelled"===t.status)&&(t.endedAt??t.updatedAt).getTime()<e,a=new Set(await (0,h.listScratchFolders)()),r=[];for(let e of(await (0,k.listThreadFolders)())){let o=(0,h.jobScratch)(e.id,e.label);a.delete(o)&&t(e)&&await B(e.id,async()=>{let a=await (0,k.findThread)(e.id);a&&t(a)&&(await (0,h.closeHiddenBrowser)(e.id),await (0,h.removeJobScratch)(e.id,e.label),r.push(o))})}return r.push(...await (0,h.removeUnchangedFolders)([...a])),await (0,h.pruneJobFiles)(),r.length&&c.logger.info(`cleared ${r.length} old job folder(s): ${r.join(", ")}`),r}async function E(){for(let e of(await (0,k.listRunningThreadIds)()))await B(e,async()=>{[...D.values()].some(t=>t.threadId===e)||(await (0,k.findThread)(e))?.status==="running"&&await (0,g.pauseRoom)(e,"The server restarted. Resume from the saved conversation.")})}async function C(e,t=!1){let a=(async()=>{let a=await (0,k.listRunningThreadIds)();await Promise.all(a.map(a=>B(a,async()=>{(await (0,k.findThread)(a))?.status==="running"&&(await R(a),await (0,g.pauseRoom)(a,e,t))})))})();U.current=a,await a}async function _(){if(await U.current,o.presence.watching)for(let e of(await (0,k.listAutoStoppedThreads)()))await B(e,async()=>{let t=await (0,k.findThread)(e);t?.status==="waiting"&&t.pending?.auto&&await (0,g.resumeRoom)(e,!1)}),await W(e)}e.s(["answerThread",0,$,"askCompact",0,function(e,t){P.add(j(e,t))},"cancelThread",0,O,"pauseThreads",0,C,"removeFinishedThreads",0,S,"removeThread",0,M,"resumeStoppedThreads",0,_,"startThread",0,v,"sweepJobFiles",0,N,"sweepThreads",0,E]),a()}catch(e){a(e)}},!1),742712,e=>e.a(async(t,a)=>{try{var r=e.i(666680),o=e.i(875225),n=e.i(260338),i=e.i(518899),s=e.i(380690),l=e.i(687388),d=e.i(528790),h=e.i(613240),u=e.i(353885),c=e.i(53748),w=e.i(944971),p=e.i(889034),b=t([d]);[d]=b.then?(await b)():b;let B=()=>s.appEvents.emit({type:"threads"}),U=e=>"done"===e||"cancelled"===e,P=(e,t,a)=>`message:${(0,r.createHash)("sha256").update(JSON.stringify([e,t,a])).digest("hex")}`;async function m(e,t,a){let[r]=await e.select({id:h.threadWorkTable.id}).from(h.threadWorkTable).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,t),(0,o.eq)(h.threadWorkTable.state,"external"),(0,o.eq)(h.threadWorkTable.caller,a))).limit(1);return!!r}async function f(e,t,a){let r=a.flatMap(e=>"assistant"===e.role&&Array.isArray(e.content)?e.content.flatMap(e=>"tool-call"===e.type&&e.toolName===u.TOOL_NAMES.send_message?[e.toolCallId]:[]):[]),n=r.map(a=>P(e,t,a)),i=new Map;if(!n.length)return i;let[s,l]=await Promise.all([d.database.select({key:h.threadWorkTable.id,to:h.threadWorkTable.bot}).from(h.threadWorkTable).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.inArray)(h.threadWorkTable.id,n))),d.database.select({key:h.threadDeliveryTable.key,to:h.threadWorkTable.bot}).from(h.threadDeliveryTable).innerJoin(h.threadWorkTable,(0,o.eq)(h.threadWorkTable.id,h.threadDeliveryTable.workId)).where((0,o.and)((0,o.eq)(h.threadDeliveryTable.threadId,e),(0,o.inArray)(h.threadDeliveryTable.key,n)))]),c=new Map([...s,...l].map(e=>[e.key,e.to]));for(let[e,t]of r.entries()){let a=c.get(n[e]);a&&i.set(t,{messageId:n[e],to:a})}return i}async function y(e,t,a){let[r]=await e.select({seq:(0,n.max)(h.threadMessageTable.seq)}).from(h.threadMessageTable).where((0,o.eq)(h.threadMessageTable.threadId,t)),i=(r?.seq??-1)+1;return await e.insert(h.threadMessageTable).values({threadId:t,seq:i,...a}),i}let j=(e,t)=>({bot:e.bot,parent:e.id,role:"user",content:`${t} ${p.RESUME_CHECK}`,note:!0});async function g(e,t){await T(e.threadId,j(e,t))}async function T(e,t){let a=await d.database.transaction(a=>y(a,e,t));return B(),a}async function k(e){return d.database.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e)).orderBy(h.threadWorkTable.createdAt,h.threadWorkTable.id)}async function I(e,t){let[a]=await d.database.select({budget:i.sql`min(nullif(${h.threadWorkTable.contextBudget}, 0))`}).from(h.threadWorkTable).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.eq)(h.threadWorkTable.bot,t)));return a?.budget??void 0}async function v(e,t){await d.database.transaction(async a=>{await $(a,e),await a.update(h.threadWorkTable).set({contextBudget:t}).where((0,o.eq)(h.threadWorkTable.id,e.id))}),B()}async function $(e,t){let[a]=await e.select().from(h.threadWorkTable).where((0,o.and)((0,o.eq)(h.threadWorkTable.id,t.id),(0,o.eq)(h.threadWorkTable.generation,t.generation),(0,o.eq)(h.threadWorkTable.state,"running")));return a||(0,c.publicError)("This turn is no longer running."),a}async function W(e,t){await e.insert(h.threadDeliveryTable).values(t).onConflictDoNothing();let[a]=await e.select({bot:h.threadWorkTable.bot}).from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.id,t.workId));a&&await m(e,t.threadId,a.bot)||await e.update(h.threadWorkTable).set({state:"queued"}).where((0,o.and)((0,o.eq)(h.threadWorkTable.id,t.workId),(0,o.inArray)(h.threadWorkTable.state,["waiting","done"])))}async function q(e,t){let a={...p.RoomMessageSchema.parse(t),id:t.id};"question"===a.kind&&a.to!==p.ROOM_THURSDAY&&(0,c.publicError)("Address user questions to Thursday; use a message to contact another bot."),a.options?.length&&"question"!==a.kind&&(0,c.publicError)("Offer answer choices only with a user question.");let r=await d.database.transaction(async t=>{await $(t,e);let r=P(e.threadId,e.bot,a.id),[n]=await t.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.id,r));if(n)return{messageId:r,to:n.bot};let[i]=await t.select({to:h.threadWorkTable.bot}).from(h.threadDeliveryTable).innerJoin(h.threadWorkTable,(0,o.eq)(h.threadWorkTable.id,h.threadDeliveryTable.workId)).where((0,o.eq)(h.threadDeliveryTable.key,r));if(i)return{messageId:r,to:i.to};if(a.to===e.bot&&(0,c.publicError)("Continue your own work directly; choose another recipient."),a.replyTo){let[n]=await t.select().from(h.threadWorkTable).where((0,o.and)((0,o.eq)(h.threadWorkTable.id,a.replyTo),(0,o.eq)(h.threadWorkTable.threadId,e.threadId)));if((!n||n.bot!==e.bot||n.caller!==a.to||U(n.state))&&(0,c.publicError)("Reply to an open message addressed to you from that recipient."),n.parentId)return await W(t,{key:r,threadId:e.threadId,workId:n.parentId,speaker:e.bot,text:a.text}),{messageId:r,to:a.to}}let s=await t.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e.threadId)),d=new Set(s.map(e=>e.bot).filter(e=>e!==p.ROOM_THURSDAY));a.to!==p.ROOM_THURSDAY&&!d.has(a.to)&&d.size>=l.BOT_RUN.participants&&(0,c.publicError)("This thread has reached its participant limit."),s.filter(e=>!U(e.state)).length>=l.BOT_RUN.queuedMessages&&(0,c.publicError)("This thread has reached its pending message limit.");let u=a.to!==p.ROOM_THURSDAY&&await m(t,e.threadId,a.to);return await t.insert(h.threadWorkTable).values({id:r,threadId:e.threadId,bot:a.to,caller:e.bot,parentId:e.id,state:a.to===p.ROOM_THURSDAY?"question"===a.kind?"external":"done":u?"waiting":"queued",result:a.to===p.ROOM_THURSDAY?a.text:null,options:[...new Set(a.options??[])]}),a.to===p.ROOM_THURSDAY?await t.insert(h.threadRelayTable).values({key:r,threadId:e.threadId,bot:e.bot,text:a.text,kind:a.kind,messageId:"question"===a.kind?r:null}):await W(t,{key:r,threadId:e.threadId,workId:r,speaker:e.bot,text:a.text}),await t.update(h.threadTable).set({wrapped:!1,updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e.threadId)),{messageId:r,to:a.to,...u?{note:`${a.to} is waiting for the user's answer and reads this after it.`}:{}}});return B(),r}async function x(e){let t=!1,a=await d.database.transaction(async a=>{let[r]=await a.select().from(h.threadTable).where((0,o.eq)(h.threadTable.id,e));if(!r||"running"!==r.status)return null;let n=await a.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e)).orderBy(i.sql`${h.threadWorkTable}.rowid`),s=new Set(n.filter(e=>"external"===e.state).map(e=>e.caller));for(let e of n)"queued"===e.state&&s.has(e.bot)&&(await a.update(h.threadWorkTable).set({state:"waiting"}).where((0,o.eq)(h.threadWorkTable.id,e.id)),e.state="waiting",t=!0);let d=n.filter(e=>"running"===e.state);if(d.length>=l.BOT_RUN.concurrent)return null;let u=n.find(e=>"queued"===e.state&&!d.some(t=>t.bot===e.bot));if(!u)return null;if(r.turns>=l.BOT_RUN.turns)return await a.update(h.threadWorkTable).set({state:"paused"}).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.eq)(h.threadWorkTable.state,"queued"))),null;let[c]=await a.update(h.threadWorkTable).set({state:"running",generation:u.generation+1}).where((0,o.eq)(h.threadWorkTable.id,u.id)).returning();return await a.update(h.threadTable).set({turns:r.turns+1}).where((0,o.eq)(h.threadTable.id,e)),c});return(a||t)&&B(),a}async function R(e){let t=await d.database.transaction(async t=>{await $(t,e);let a=await t.select().from(h.threadDeliveryTable).where((0,o.and)((0,o.eq)(h.threadDeliveryTable.workId,e.id),(0,o.eq)(h.threadDeliveryTable.consumed,!1))).orderBy(h.threadDeliveryTable.id);for(let r of a){let a=O(r);await y(t,e.threadId,{bot:e.bot,parent:e.id,role:"user",content:a,hidden:!r.visible}),await t.update(h.threadDeliveryTable).set({consumed:!0}).where((0,o.eq)(h.threadDeliveryTable.id,r.id))}return a.map(O)});return t.length&&B(),t}function O(e){return e.visible?(0,w.tagSpeaker)("The user"===e.speaker?"user":"thursday",e.text):`${e.speaker}:
91
93
 
92
94
  ${e.text}`}async function M(e,t){await d.database.transaction(async a=>{await $(a,e);let r=await a.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.parentId,e.id)),n=await a.select({id:h.threadDeliveryTable.id}).from(h.threadDeliveryTable).where((0,o.and)((0,o.eq)(h.threadDeliveryTable.workId,e.id),(0,o.eq)(h.threadDeliveryTable.consumed,!1))).limit(1),i=await m(a,e.threadId,e.bot),s=n.length&&!i?"queued":n.length||r.some(e=>!U(e.state))?"waiting":"done";if(await a.update(h.threadWorkTable).set({state:s,result:t}).where((0,o.eq)(h.threadWorkTable.id,e.id)),"done"!==s)return;if(e.parentId){let[r]=await a.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.id,e.parentId)),[n]=t?[]:await a.select({id:h.threadDeliveryTable.id}).from(h.threadDeliveryTable).where((0,o.and)((0,o.eq)(h.threadDeliveryTable.workId,e.parentId),(0,o.eq)(h.threadDeliveryTable.speaker,e.bot),(0,o.eq)(h.threadDeliveryTable.consumed,!1))).limit(1);r&&"cancelled"!==r.state&&!n&&await W(a,{key:`return:${e.id}:${e.generation}`,threadId:e.threadId,workId:r.id,speaker:e.bot,text:t||"This turn ended without a message."})}let[l]=await a.select().from(h.threadTable).where((0,o.eq)(h.threadTable.id,e.threadId)),d=await a.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e.threadId));l&&e.bot===l.bot&&!e.parentId&&d.every(e=>U(e.state))&&(await a.update(h.threadTable).set({status:t?"done":"waiting",outcome:t||"The room is idle. Send a message to continue.",pending:t?null:{options:[w.THREAD_CONTINUE]},wrapped:!0,endedAt:t?new Date:null,seen:!1,updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e.threadId)),t&&await a.insert(h.threadRelayTable).values({key:`report:${e.threadId}:${l.generation}`,threadId:e.threadId,bot:e.bot,text:t,kind:"report"}).onConflictDoNothing())}),B()}async function A(e){await d.database.transaction(async t=>{let[a]=await t.select().from(h.threadTable).where((0,o.eq)(h.threadTable.id,e));if(!a||"running"!==a.status)return;let r=await t.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e));if(r.some(e=>"queued"===e.state||"running"===e.state))return;let n=r.find(e=>"external"===e.state);if(n)return void await t.update(h.threadTable).set({status:"waiting",outcome:n.result,pending:{options:n.options,messageId:n.id,bot:n.caller},updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e));if(r.some(e=>!U(e.state))||a.wrapped)return void await t.update(h.threadTable).set({status:"waiting",outcome:a.turns>=l.BOT_RUN.turns?"The room reached its automatic turn limit. Continue from the saved conversation.":"Work is paused. Continue from the saved conversation.",pending:{options:[w.THREAD_CONTINUE]},updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e));let i=crypto.randomUUID();await t.insert(h.threadWorkTable).values({id:i,threadId:e,bot:a.bot,caller:p.ROOM_THURSDAY,state:"queued"}),await W(t,{key:i,threadId:e,workId:i,speaker:"Thread activity",text:"The participants have finished their current turns. Bring together the results you received for Thursday, including anything still unresolved."}),await t.update(h.threadTable).set({wrapped:!0}).where((0,o.eq)(h.threadTable.id,e))}),B()}async function S(e,t,a=!1){await d.database.transaction(async r=>{let n=await r.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e));for(let a of n.filter(e=>"running"===e.state||"queued"===e.state))await r.update(h.threadWorkTable).set({state:"paused",generation:a.generation+1}).where((0,o.eq)(h.threadWorkTable.id,a.id)),await y(r,e,j(a,t));await r.update(h.threadTable).set({status:"waiting",outcome:t,pending:{options:[w.THREAD_CONTINUE],...a?{auto:!0}:{}},seen:!1,endedAt:null,updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e)),await r.insert(h.threadRelayTable).values({key:crypto.randomUUID(),threadId:e,bot:n.find(e=>!e.parentId)?.bot??"Bot",text:t,kind:"interrupted",accepted:a})}),B()}async function N(e,t=!0){await d.database.transaction(async a=>{await a.update(h.threadWorkTable).set({state:"queued"}).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.eq)(h.threadWorkTable.state,"paused"))),await a.update(h.threadTable).set({status:"running",...t?{generation:i.sql`${h.threadTable.generation} + 1`,turns:0}:{},pending:null,outcome:null,endedAt:null,updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e)),await a.update(h.threadRelayTable).set({accepted:!0}).where((0,o.and)((0,o.eq)(h.threadRelayTable.threadId,e),(0,o.eq)(h.threadRelayTable.kind,"interrupted")))}),B()}async function E(e,t,a){let r=e.select({workId:h.threadDeliveryTable.workId}).from(h.threadDeliveryTable).where((0,o.and)((0,o.eq)(h.threadDeliveryTable.threadId,t),(0,o.eq)(h.threadDeliveryTable.consumed,!1)));await e.update(h.threadWorkTable).set({state:"queued"}).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,t),(0,o.eq)(h.threadWorkTable.bot,a),(0,o.inArray)(h.threadWorkTable.state,["waiting","done"]),(0,o.inArray)(h.threadWorkTable.id,r)))}async function C(e,t,a,r,n,s=!0){let l=await d.database.transaction(async l=>{let[d]=await l.select().from(h.threadTable).where((0,o.eq)(h.threadTable.id,e));d||(0,c.publicError)("No such thread.");let u=await l.select().from(h.threadWorkTable).where((0,o.eq)(h.threadWorkTable.threadId,e)).orderBy(h.threadWorkTable.createdAt),w=u.filter(e=>"external"===e.state),b=n?w.find(e=>e.id===n)??(0,c.publicError)("That question is no longer waiting for an answer."):s?function(e,t){let a=t?e.filter(e=>e.caller===t):e;if(a.length<=1)return a[0];(0,c.publicError)(`Several questions are waiting for an answer: ${a.map(e=>`${e.caller} (replyTo ${e.id}): “${(e.result??"").slice(0,160)}”`).join("; ")}. Answer one of them by its replyTo.`)}(w,r):void 0,f=b?.caller??r??d.bot,y=b?u.find(e=>e.id===b.parentId):u.find(e=>e.bot===f&&"running"===e.state)??u.find(e=>e.bot===f&&!U(e.state)&&"external"!==e.state);if(b&&(await l.update(h.threadWorkTable).set({state:"done",result:t}).where((0,o.eq)(h.threadWorkTable.id,b.id)),await l.update(h.threadRelayTable).set({accepted:!0}).where((0,o.eq)(h.threadRelayTable.messageId,b.id))),!y){let t=null;if(f!==d.bot){let a=u.findLast(e=>e.bot===d.bot&&!e.parentId&&"cancelled"!==e.state);a?"done"===a.state&&await l.update(h.threadWorkTable).set({state:"waiting"}).where((0,o.eq)(h.threadWorkTable.id,a.id)):a=(await l.insert(h.threadWorkTable).values({id:crypto.randomUUID(),threadId:e,bot:d.bot,caller:p.ROOM_THURSDAY,state:"waiting"}).returning())[0],t=a.id}y=(await l.insert(h.threadWorkTable).values({id:crypto.randomUUID(),threadId:e,bot:f,caller:t?d.bot:p.ROOM_THURSDAY,parentId:t,state:"queued"}).returning())[0]}b&&await W(l,{key:`answer:${b.id}`,threadId:e,workId:y.id,speaker:"Thread activity",text:`The next message answers your question to the user: “${b.result??""}”`});let g=crypto.randomUUID();return await W(l,{key:g,threadId:e,workId:y.id,speaker:a,text:t,visible:!0}),b&&!await m(l,e,f)&&await E(l,e,f),await l.update(h.threadWorkTable).set({state:"queued"}).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.eq)(h.threadWorkTable.state,"paused"))),await l.update(h.threadTable).set({status:"running",generation:i.sql`${h.threadTable.generation} + 1`,turns:0,wrapped:!1,pending:null,outcome:null,endedAt:null,seen:!1,updatedAt:new Date}).where((0,o.eq)(h.threadTable.id,e)),await l.update(h.threadRelayTable).set({accepted:!0}).where((0,o.and)((0,o.eq)(h.threadRelayTable.threadId,e),(0,o.inArray)(h.threadRelayTable.kind,["interrupted","report"]))),{key:g,to:f,answered:b?{bot:b.caller,question:b.result??""}:null}});return B(),l}async function _(e){await d.database.transaction(async t=>{await t.update(h.threadWorkTable).set({state:"cancelled",generation:i.sql`${h.threadWorkTable.generation} + 1`}).where((0,o.and)((0,o.eq)(h.threadWorkTable.threadId,e),(0,o.inArray)(h.threadWorkTable.state,["queued","running","waiting","external","paused"]))),await t.update(h.threadRelayTable).set({accepted:!0}).where((0,o.eq)(h.threadRelayTable.threadId,e))}),B()}async function D(e,t){let[a]=await d.database.select({bot:h.threadTable.bot}).from(h.threadTable).where((0,o.eq)(h.threadTable.id,e)),r=await d.database.select().from(h.threadMessageTable).where((0,o.and)((0,o.eq)(h.threadMessageTable.threadId,e),(0,o.or)((0,o.eq)(h.threadMessageTable.bot,t),a?.bot===t?i.sql`${h.threadMessageTable.bot} is null AND ${h.threadMessageTable.parent} is null`:void 0))).orderBy(h.threadMessageTable.seq),n=r.findLastIndex(e=>e.compact);return(n>0?[r[0],...r.slice(n)]:r).map(e=>({role:e.role,content:e.content}))}e.s(["appendRoomMessage",0,T,"cancelRoom",0,_,"claimRoomWork",0,x,"consumeRoomInbox",0,R,"finishRoomWork",0,M,"listParticipantTranscript",0,D,"listRoomReceipts",0,f,"listRoomWork",0,k,"lowerRoomContextBudget",0,v,"noteRoomBreak",0,g,"pauseRoom",0,S,"resumeRoom",0,N,"roomContextBudget",0,I,"sendRoomMessage",0,q,"settleRoom",0,A,"tellRoom",0,C]),a()}catch(e){a(e)}},!1),167004,e=>{"use strict";var t=e.i(874533),a=e.i(687388);let r=`on run argv
@@ -1,6 +1,6 @@
1
- module.exports=[102473,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__18-2tsq._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(232347)))},130022,e=>{e.v(s=>Promise.all(["server/chunks/config_ts_1g4sz5o._.js"].map(s=>e.l(s))).then(()=>s(333925)))},266965,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1orn-5b._.js","server/chunks/_0khihjk._.js"].map(s=>e.l(s))).then(()=>s(946280)))},171772,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1ndi14y._.js"].map(s=>e.l(s))).then(()=>s(973589)))},242792,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/_10tkr26._.js","server/chunks/[root-of-the-server]__0nr-v8s._.js","server/chunks/_1y8w80a._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_1kg70wc._.js","server/chunks/_1ogqovh._.js"].map(s=>e.l(s))).then(()=>s(799791)))},327784,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0mrk2it._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/_05h2cii._.js","server/chunks/[root-of-the-server]__0n-l_n_._.js","server/chunks/features_0hdaci0._.js","server/chunks/_136j09a._.js","server/chunks/_1kg70wc._.js","server/chunks/_10tkr26._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_1zxp-p6._.js","server/chunks/_1jn-aep._.js"].map(s=>e.l(s))).then(()=>s(49002)))},566024,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0h_x6q6._.js","server/chunks/_05h2cii._.js","server/chunks/_1e48czp._.js","server/chunks/_1y8w80a._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(1363)))},975158,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1e6aut3._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/_10tkr26._.js","server/chunks/_1zxp-p6._.js","server/chunks/[root-of-the-server]__0n-l_n_._.js","server/chunks/_0x-ej3f._.js","server/chunks/_1jn-aep._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_1kg70wc._.js","server/chunks/_05h2cii._.js","server/chunks/_136j09a._.js","server/chunks/features_0hdaci0._.js"].map(s=>e.l(s))).then(()=>s(312485)))},569286,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1ygplx1._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/_05h2cii._.js","server/chunks/[root-of-the-server]__0n-l_n_._.js","server/chunks/features_0hdaci0._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_1kg70wc._.js","server/chunks/_10tkr26._.js","server/chunks/_1jn-aep._.js","server/chunks/_1zxp-p6._.js","server/chunks/_1y8w80a._.js"].map(s=>e.l(s))).then(()=>s(733184)))},741548,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/[root-of-the-server]__0209ah4._.js"].map(s=>e.l(s))).then(()=>s(379651)))},917723,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_0f6ts7z._.js","server/chunks/_1e48czp._.js","server/chunks/_1y8w80a._.js","server/chunks/[root-of-the-server]__12iddfq._.js","server/chunks/features_0hdaci0._.js"].map(s=>e.l(s))).then(()=>s(520401)))},51833,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/[root-of-the-server]__1cjxw0-._.js"].map(s=>e.l(s))).then(()=>s(871096)))},482438,e=>{"use strict";async function s(){let{APP_DIR:s,APP_NAME:r,DATA_DIR:_,DB_FILE_NAME:t,WORKSPACE_KEEP:n}=await e.A(130022),{logger:o}=await e.A(415568),{migrateDatabase:a}=await e.A(266965);await a().catch(e=>{let s=t.replace(/^file:/,"");o.error(`Cannot migrate ${s}`),console.error(` ${e instanceof Error?e.message:e}
1
+ module.exports=[102473,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__18-2tsq._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(232347)))},130022,e=>{e.v(s=>Promise.all(["server/chunks/config_ts_1g4sz5o._.js"].map(s=>e.l(s))).then(()=>s(333925)))},266965,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1orn-5b._.js","server/chunks/_0khihjk._.js"].map(s=>e.l(s))).then(()=>s(946280)))},171772,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1ndi14y._.js"].map(s=>e.l(s))).then(()=>s(973589)))},242792,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/_10tkr26._.js","server/chunks/[root-of-the-server]__0nr-v8s._.js","server/chunks/_1y8w80a._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_1kg70wc._.js","server/chunks/_1ogqovh._.js"].map(s=>e.l(s))).then(()=>s(799791)))},327784,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0mrk2it._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/_05h2cii._.js","server/chunks/[root-of-the-server]__1wnzmx9._.js","server/chunks/_10tkr26._.js","server/chunks/_136j09a._.js","server/chunks/_1kg70wc._.js","server/chunks/features_0hdaci0._.js","server/chunks/_1jn-aep._.js","server/chunks/_1zxp-p6._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(49002)))},566024,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0h_x6q6._.js","server/chunks/_05h2cii._.js","server/chunks/_1e48czp._.js","server/chunks/_1y8w80a._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(1363)))},975158,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0mrk2it._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/features_0hdaci0._.js","server/chunks/_1zxp-p6._.js","server/chunks/[root-of-the-server]__1wnzmx9._.js","server/chunks/_0x-ej3f._.js","server/chunks/_1kg70wc._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_136j09a._.js","server/chunks/_05h2cii._.js","server/chunks/_1jn-aep._.js","server/chunks/_10tkr26._.js"].map(s=>e.l(s))).then(()=>s(312485)))},569286,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__1ygplx1._.js","server/chunks/_1tpr507._.js","server/chunks/features_0rfvely._.js","server/chunks/_05h2cii._.js","server/chunks/[root-of-the-server]__1wnzmx9._.js","server/chunks/_10tkr26._.js","server/chunks/_1jn-aep._.js","server/chunks/_1y8w80a._.js","server/chunks/features_0hdaci0._.js","server/chunks/_1kg70wc._.js","server/chunks/_1zxp-p6._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(733184)))},741548,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/[root-of-the-server]__0209ah4._.js"].map(s=>e.l(s))).then(()=>s(379651)))},917723,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/_0f6ts7z._.js","server/chunks/_1e48czp._.js","server/chunks/_1y8w80a._.js","server/chunks/[root-of-the-server]__12iddfq._.js","server/chunks/features_0hdaci0._.js"].map(s=>e.l(s))).then(()=>s(520401)))},51833,e=>{e.v(s=>Promise.all(["server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y49572._.js","server/chunks/lib_logger_ts_07e65t5._.js","server/chunks/[root-of-the-server]__1cjxw0-._.js"].map(s=>e.l(s))).then(()=>s(871096)))},482438,e=>{"use strict";async function s(){let{APP_DIR:s,APP_NAME:r,DATA_DIR:_,DB_FILE_NAME:t,WORKSPACE_KEEP:o}=await e.A(130022),{logger:n}=await e.A(415568),{migrateDatabase:a}=await e.A(266965);await a().catch(e=>{let s=t.replace(/^file:/,"");n.error(`Cannot migrate ${s}`),console.error(` ${e instanceof Error?e.message:e}
2
2
  Removing it starts over with an empty one. API keys, bots, connectors, calls, threads and memory go with it; the workspace and skills stay.
3
3
  rm "${s}" "${s}-wal" "${s}-shm"
4
- `),process.exit(65)});let{ensureRootNotes:h}=await e.A(566024);await h();let{installGuide:c}=await e.A(171772);await c().catch(e=>o.error("install guide",e));let{sweepJobFiles:v,sweepThreads:l}=await e.A(327784);await l();let i=()=>void v().catch(e=>o.error("sweep job files",e));i(),setInterval(i,n.sweepEveryMs).unref();let{sweepCalls:u}=await e.A(917723);await u();let{presence:k}=await e.A(102473),{pauseThreads:j,resumeStoppedThreads:p}=await e.A(327784),{readKeepWorkingOn:w}=await e.A(242792);k.onGone(()=>{(async()=>{await w()?o.info("browser gone — work goes on"):(o.info("browser gone — stopping what was running"),await j("The browser closed while this was running.",!0)),await u()})().catch(e=>o.error("browser gone",e))}),k.onBack(()=>{p().catch(e=>o.error("resume threads",e))});let{startRoutineClock:m}=await e.A(569286);m();let{adoptKeptSessions:g}=await e.A(741548);await g().catch(e=>o.error("adopt kept sessions",e));let{startReach:f}=await e.A(975158);if(f().catch(e=>o.error("start reach",e)),process.env.NEXT_MANUAL_SIG_HANDLE){let e=!1;for(let[s,r]of[["SIGINT",130],["SIGTERM",143]])process.on(s,()=>{e||(e=!0,o.info(`${s} — parking what was running`),Promise.race([j("The server was shut down while this was running.").catch(e=>o.error("pause threads",e)),new Promise(e=>setTimeout(e,3e3))]).finally(()=>process.exit(r)))})}o.info(`${r} is up — app ${s}, data ${_}`);let{ensureBrowser:d}=await e.A(51833);d().catch(e=>o.debug("browser fetch",e))}e.s(["boot",0,s])},415568,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0sm5xvm._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(938281)))}];
4
+ `),process.exit(65)});let{ensureRootNotes:h}=await e.A(566024);await h();let{installGuide:c}=await e.A(171772);await c().catch(e=>n.error("install guide",e));let{sweepJobFiles:v,sweepThreads:i}=await e.A(327784);await i();let l=()=>void v().catch(e=>n.error("sweep job files",e));l(),setInterval(l,o.sweepEveryMs).unref();let{sweepCalls:u}=await e.A(917723);await u();let{presence:k}=await e.A(102473),{pauseThreads:j,resumeStoppedThreads:m}=await e.A(327784),{readKeepWorkingOn:w}=await e.A(242792);k.onGone(()=>{(async()=>{await w()?n.info("browser gone — work goes on"):(n.info("browser gone — stopping what was running"),await j("The browser closed while this was running.",!0)),await u()})().catch(e=>n.error("browser gone",e))}),k.onBack(()=>{m().catch(e=>n.error("resume threads",e))});let{startRoutineClock:p}=await e.A(569286);p();let{adoptKeptSessions:g}=await e.A(741548);await g().catch(e=>n.error("adopt kept sessions",e));let{startReach:f}=await e.A(975158);if(f().catch(e=>n.error("start reach",e)),process.env.NEXT_MANUAL_SIG_HANDLE){let e=!1;for(let[s,r]of[["SIGINT",130],["SIGTERM",143]])process.on(s,()=>{e||(e=!0,n.info(`${s} — parking what was running`),Promise.race([j("The server was shut down while this was running.").catch(e=>n.error("pause threads",e)),new Promise(e=>setTimeout(e,3e3))]).finally(()=>process.exit(r)))})}n.info(`${r} is up — app ${s}, data ${_}`);let{ensureBrowser:d}=await e.A(51833);d().catch(e=>n.debug("browser fetch",e))}e.s(["boot",0,s])},415568,e=>{e.v(s=>Promise.all(["server/chunks/[root-of-the-server]__0sm5xvm._.js","server/chunks/lib_logger_ts_07e65t5._.js"].map(s=>e.l(s))).then(()=>s(938281)))}];
5
5
 
6
6
  //# sourceMappingURL=_1jc5g4p._.js.map