thursday-agent 0.4.0 → 0.5.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 (199) 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.html +1 -1
  12. package/.next/server/app/_not-found.rsc +1 -1
  13. package/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  14. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  15. package/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  16. package/.next/server/app/api/artifact/route.js +4 -4
  17. package/.next/server/app/api/artifact/route.js.nft.json +1 -1
  18. package/.next/server/app/api/bot/memory/files/route.js +3 -3
  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/task/[id]/route.js +8 -8
  23. package/.next/server/app/api/bot/task/[id]/route.js.nft.json +1 -1
  24. package/.next/server/app/api/bot/task/route.js +6 -6
  25. package/.next/server/app/api/bot/task/route.js.nft.json +1 -1
  26. package/.next/server/app/api/config/route.js.nft.json +1 -1
  27. package/.next/server/app/api/events/route.js.nft.json +1 -1
  28. package/.next/server/app/api/file/[...path]/route.js +4 -4
  29. package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
  30. package/.next/server/app/api/llm-model/catalog/route.js +2 -2
  31. package/.next/server/app/api/llm-model/catalog/route.js.nft.json +1 -1
  32. package/.next/server/app/api/llm-model/credits/route.js +2 -2
  33. package/.next/server/app/api/llm-model/credits/route.js.nft.json +1 -1
  34. package/.next/server/app/api/llm-model/route.js +2 -2
  35. package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
  36. package/.next/server/app/api/llm-model/subscription/route.js +2 -2
  37. package/.next/server/app/api/llm-model/subscription/route.js.nft.json +1 -1
  38. package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
  39. package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
  40. package/.next/server/app/api/mcp/route.js.nft.json +1 -1
  41. package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
  42. package/.next/server/app/api/memory/edit/route.js +11 -11
  43. package/.next/server/app/api/memory/edit/route.js.nft.json +1 -1
  44. package/.next/server/app/api/memory/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 +6 -6
  48. package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
  49. package/.next/server/app/api/thursday/skills/route.js +6 -6
  50. package/.next/server/app/api/thursday/skills/route.js.nft.json +1 -1
  51. package/.next/server/app/api/thursday/tool-call/route.js +8 -8
  52. package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
  53. package/.next/server/app/api/workspace/route.js +3 -2
  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 +2 -2
  57. package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
  58. package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
  59. package/.next/server/app/favicon.ico/route.js.nft.json +1 -1
  60. package/.next/server/app/page/server-reference-manifest.json +40 -40
  61. package/.next/server/app/page.js +1 -1
  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]__026u77e._.js +5 -0
  65. package/.next/server/chunks/{[root-of-the-server]__02xjoto._.js → [root-of-the-server]__050zri4._.js} +1 -1
  66. package/.next/server/chunks/[root-of-the-server]__0bg9710._.js +3 -0
  67. package/.next/server/chunks/[root-of-the-server]__0in-d5s._.js +3 -0
  68. package/.next/server/chunks/[root-of-the-server]__0pa9k-f._.js +8 -0
  69. package/.next/server/chunks/[root-of-the-server]__0qi_m0e._.js +8 -0
  70. package/.next/server/chunks/[root-of-the-server]__0tq0m_k._.js +3 -0
  71. package/.next/server/chunks/[root-of-the-server]__0xep6j_._.js +3 -0
  72. package/.next/server/chunks/[root-of-the-server]__144l7qt._.js +8 -0
  73. package/.next/server/chunks/[root-of-the-server]__1anc1p9._.js +1 -1
  74. package/.next/server/chunks/[root-of-the-server]__1jg8t86._.js +8 -0
  75. package/.next/server/chunks/{[root-of-the-server]__12cabg9._.js → [root-of-the-server]__1lldzy9._.js} +1 -1
  76. package/.next/server/chunks/{[root-of-the-server]__01dkp4a._.js → [root-of-the-server]__1peqvsi._.js} +1 -1
  77. package/.next/server/chunks/[root-of-the-server]__1w8gm5h._.js +10 -0
  78. package/.next/server/chunks/[root-of-the-server]__1xt39nn._.js +8 -0
  79. package/.next/server/chunks/[root-of-the-server]__1zb8mfo._.js +8 -0
  80. package/.next/server/chunks/_0-fjql4._.js +11 -6
  81. package/.next/server/chunks/_00xh_q0._.js +1 -1
  82. package/.next/server/chunks/{_1_9mjx-._.js → _091bi8d._.js} +1 -1
  83. package/.next/server/chunks/_0fzqt2y._.js +29 -21
  84. package/.next/server/chunks/{_0u4aiy2._.js → _0lr92vd._.js} +1 -1
  85. package/.next/server/chunks/_0mecv0f._.js +11 -6
  86. package/.next/server/chunks/{_0sbynis._.js → _0si7xzn._.js} +1 -1
  87. package/.next/server/chunks/_1230wbx._.js +5 -5
  88. package/.next/server/chunks/{_0obojvv._.js → _18d7-5p._.js} +1 -1
  89. package/.next/server/chunks/_1c78vw5._.js +33 -25
  90. package/.next/server/chunks/_1d0j961._.js +2 -2
  91. package/.next/server/chunks/_1krd9rf._.js +1 -1
  92. package/.next/server/chunks/{_03a0897._.js → _1zkfbaa._.js} +1 -1
  93. package/.next/server/chunks/features_1qf3cei._.js +6 -1
  94. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0r28-sm._.js → node_modules_consola_dist_chunks_prompt_mjs_17k8irj._.js} +1 -1
  95. package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_1xoq2rl._.js → node_modules_consola_dist_chunks_prompt_mjs_1jidylq._.js} +1 -1
  96. package/.next/server/chunks/ssr/[root-of-the-server]__0-nob52._.js +4 -0
  97. package/.next/server/chunks/ssr/{[root-of-the-server]__202p40z._.js → [root-of-the-server]__0s4wb56._.js} +1 -1
  98. package/.next/server/chunks/ssr/{[root-of-the-server]__0xsog8n._.js → [root-of-the-server]__0sd3izg._.js} +2 -2
  99. package/.next/server/chunks/ssr/{[root-of-the-server]__1gtlw6v._.js → [root-of-the-server]__1-13tcn._.js} +2 -2
  100. package/.next/server/chunks/ssr/[root-of-the-server]__10-dz5o._.js +1 -1
  101. package/.next/server/chunks/ssr/{[root-of-the-server]__0s9l2sv._.js → [root-of-the-server]__1zidpfl._.js} +1 -1
  102. package/.next/server/chunks/ssr/_001_ms1._.js +6 -1
  103. package/.next/server/chunks/ssr/{_0gb4gmf._.js → _04z2c7b._.js} +2 -2
  104. package/.next/server/chunks/ssr/{_1nnsk7z._.js → _06tssji._.js} +2 -2
  105. package/.next/server/chunks/ssr/_0fk4c7d._.js +3 -0
  106. package/.next/server/chunks/ssr/_0i_6q1w._.js +1 -1
  107. package/.next/server/chunks/ssr/{_1h0rw11._.js → _0m2lsd1._.js} +2 -2
  108. package/.next/server/chunks/ssr/_0mggveb._.js +3 -0
  109. package/.next/server/chunks/ssr/{_1jhd09t._.js → _0nbpc_8._.js} +2 -2
  110. package/.next/server/chunks/ssr/{_1fojd41._.js → _0rzucul._.js} +3 -3
  111. package/.next/server/chunks/ssr/_0s99bgb._.js +1 -1
  112. package/.next/server/chunks/ssr/_1-teee5._.js +4 -4
  113. package/.next/server/chunks/ssr/{_0fz4mf_._.js → _11j92tu._.js} +2 -2
  114. package/.next/server/chunks/ssr/{_1b2mjwr._.js → _1ebxla1._.js} +2 -2
  115. package/.next/server/chunks/ssr/{_1gd8q8l._.js → _1jdgjv9._.js} +2 -2
  116. package/.next/server/chunks/ssr/_1lz_cq2._.js +19 -11
  117. package/.next/server/chunks/ssr/{_0ilna52._.js → _1nj4niv._.js} +2 -2
  118. package/.next/server/chunks/ssr/_1ovmc9s._.js +3 -0
  119. package/.next/server/chunks/ssr/features_config_components_config-setting_tsx_0xfwqdg._.js +1 -1
  120. package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
  121. package/.next/server/chunks/ssr/{node_modules_0pvd7q-._.js → node_modules_0-dr_o7._.js} +1 -1
  122. package/.next/server/chunks/ssr/{node_modules_1_pc9kq._.js → node_modules_04sksn9._.js} +1 -1
  123. package/.next/server/chunks/ssr/{node_modules_1vh5ntv._.js → node_modules_05-n6dz._.js} +1 -1
  124. package/.next/server/chunks/ssr/{node_modules_0b__sgl._.js → node_modules_056qgf-._.js} +1 -1
  125. package/.next/server/chunks/ssr/{node_modules_0g7fzk3._.js → node_modules_07dsgkx._.js} +1 -1
  126. package/.next/server/chunks/ssr/{node_modules_04jf_m8._.js → node_modules_0bvopy2._.js} +1 -1
  127. package/.next/server/chunks/ssr/{node_modules_0arus10._.js → node_modules_0fkeku3._.js} +1 -1
  128. package/.next/server/chunks/ssr/{node_modules_14om4ar._.js → node_modules_0ifp389._.js} +1 -1
  129. package/.next/server/chunks/ssr/{node_modules_0cxaxk9._.js → node_modules_0iur59s._.js} +1 -1
  130. package/.next/server/chunks/ssr/{node_modules_1aaxuef._.js → node_modules_0m383r2._.js} +1 -1
  131. package/.next/server/chunks/ssr/{node_modules_1qpjvy5._.js → node_modules_0u9da1h._.js} +1 -1
  132. package/.next/server/chunks/ssr/{node_modules_1cx_ql6._.js → node_modules_0zeg3x_._.js} +1 -1
  133. package/.next/server/chunks/ssr/{node_modules_0_-_a--._.js → node_modules_1-y7nni._.js} +1 -1
  134. package/.next/server/chunks/ssr/{node_modules_08dhkiq._.js → node_modules_16mkxuo._.js} +1 -1
  135. package/.next/server/chunks/ssr/{node_modules_198nmll._.js → node_modules_1a0kmjl._.js} +1 -1
  136. package/.next/server/chunks/ssr/{node_modules_1efrqxi._.js → node_modules_1chvq5f._.js} +1 -1
  137. package/.next/server/chunks/ssr/{node_modules_0yugy6m._.js → node_modules_1j8j4pt._.js} +1 -1
  138. package/.next/server/chunks/ssr/{node_modules_09q35v_._.js → node_modules_1k6n600._.js} +1 -1
  139. package/.next/server/chunks/ssr/{node_modules_1cz2hle._.js → node_modules_1k7z2j6._.js} +1 -1
  140. package/.next/server/chunks/ssr/{node_modules_1gdh31p._.js → node_modules_1k8j8n0._.js} +1 -1
  141. package/.next/server/chunks/ssr/{node_modules_1eg7m6c._.js → node_modules_1lz0oxc._.js} +1 -1
  142. package/.next/server/chunks/ssr/{node_modules_0940ns5._.js → node_modules_1t77e4n._.js} +1 -1
  143. package/.next/server/chunks/ssr/{node_modules_00etblx._.js → node_modules_1uyk91w._.js} +1 -1
  144. package/.next/server/chunks/ssr/{node_modules_0had7xd._.js → node_modules_1x0ztf4._.js} +1 -1
  145. package/.next/server/chunks/ssr/{node_modules_14q6g4n._.js → node_modules_1y79i83._.js} +1 -1
  146. package/.next/server/chunks/ssr/{node_modules_1hpopmo._.js → node_modules_20c28js._.js} +1 -1
  147. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1b748ic._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0bkwd0u._.js} +1 -1
  148. package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1z4hm5e._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0p9a9su._.js} +1 -1
  149. package/.next/server/chunks/ssr/{node_modules_@vercel_oidc_dist_06mk8id._.js → node_modules_@vercel_oidc_dist_1o553h-._.js} +1 -1
  150. package/.next/server/middleware-build-manifest.js +3 -3
  151. package/.next/server/pages/404.html +1 -1
  152. package/.next/server/pages/500.html +1 -1
  153. package/.next/server/server-reference-manifest.js +1 -1
  154. package/.next/server/server-reference-manifest.json +41 -41
  155. package/.next/static/chunks/{39j0fvpybzabl.js → 0n3jle9kbqfr2.js} +2 -2
  156. package/.next/static/chunks/{0fl3gwe4-l6tz.js → 11r2yp_yh9_qn.js} +1 -1
  157. package/.next/static/chunks/{1jd09sxcjddu1.js → 126fj4pga_72k.js} +1 -1
  158. package/.next/static/chunks/{0gnqdjn2lvdad.js → 159udiexf6dom.js} +1 -1
  159. package/.next/static/chunks/{08qe4as2q428z.js → 18gi7o2ibrgh8.js} +1 -1
  160. package/.next/static/chunks/{2u7xt6mxg44lf.js → 1q9z1tohil7xn.js} +1 -1
  161. package/.next/static/chunks/{3zmcsnuo25zvq.js → 1sjgfets224re.js} +1 -1
  162. package/.next/static/chunks/{0wcprt5ot5she.js → 1wszsr83t01gh.js} +1 -1
  163. package/.next/static/chunks/{0w52rrrmuj9r9.js → 2szintyibu0s5.js} +1 -1
  164. package/.next/static/chunks/{0hwap1-p0m5sa.js → 3-b6b7entqazs.js} +1 -1
  165. package/.next/static/chunks/{17p6tk6k88dq6.js → 3dmbhsv2u_8kj.js} +1 -1
  166. package/.next/static/chunks/{214ya3n5gxeih.js → 3i0a5px-oufgc.js} +1 -1
  167. package/.next/static/chunks/{1w73ece_6bheu.js → 3wexk9qo8zuj3.js} +3 -3
  168. package/.next/static/chunks/3xre8bu_pk1p_.js +1 -0
  169. package/.next/static/chunks/{3woj-xd7ki5_i.js → 3zv6t3i77xhr_.js} +1 -1
  170. package/.next/static/chunks/{3akmqm77muj4-.js → 408ueu4hfvcg7.js} +1 -1
  171. package/.next/static/chunks/{15m575979un5f.js → 435atsnhs7ksu.js} +6 -6
  172. package/bin/thursday.mjs +0 -0
  173. package/features/ai/prompts/bot.prompt.ts +1 -1
  174. package/features/ai/tools/bot.tool.ts +3 -3
  175. package/features/ai/tools/skills.tool.ts +25 -8
  176. package/features/bot/bot.run.ts +184 -73
  177. package/features/bot/bot.runner.ts +48 -23
  178. package/features/bot/task.query.ts +107 -4
  179. package/features/bot/task.store.ts +3 -5
  180. package/features/workspace/workspace.ts +27 -20
  181. package/package.json +1 -1
  182. package/skills/browser/SKILL.md +6 -5
  183. package/.next/server/chunks/[root-of-the-server]__04q--0f._.js +0 -8
  184. package/.next/server/chunks/[root-of-the-server]__0bl-e63._.js +0 -3
  185. package/.next/server/chunks/[root-of-the-server]__0jq4ohy._.js +0 -8
  186. package/.next/server/chunks/[root-of-the-server]__0ls6_8y._.js +0 -8
  187. package/.next/server/chunks/[root-of-the-server]__1339jnv._.js +0 -8
  188. package/.next/server/chunks/[root-of-the-server]__18_teo8._.js +0 -8
  189. package/.next/server/chunks/[root-of-the-server]__1ccon1w._.js +0 -10
  190. package/.next/server/chunks/[root-of-the-server]__1wa1k7r._.js +0 -8
  191. package/.next/server/chunks/_1zjrdag._.js +0 -3
  192. package/.next/server/chunks/ssr/[root-of-the-server]__1ox7hbk._.js +0 -4
  193. package/.next/server/chunks/ssr/_0n3toaw._.js +0 -3
  194. package/.next/server/chunks/ssr/_1-_etts._.js +0 -3
  195. package/.next/server/chunks/ssr/_1f-dg-6._.js +0 -3
  196. package/.next/static/chunks/00rd4-v8r7axp.js +0 -1
  197. /package/.next/static/{kaTO0UHqF1bMnWgCDik2f → G6-gNoyGDEcgAsq-L4PE1}/_buildManifest.js +0 -0
  198. /package/.next/static/{kaTO0UHqF1bMnWgCDik2f → G6-gNoyGDEcgAsq-L4PE1}/_clientMiddlewareManifest.js +0 -0
  199. /package/.next/static/{kaTO0UHqF1bMnWgCDik2f → G6-gNoyGDEcgAsq-L4PE1}/_ssgManifest.js +0 -0
@@ -1,11 +1,11 @@
1
- module.exports=[851372,e=>e.a(async(t,o)=>{try{var a=e.i(343747),n=e.i(687388),s=e.i(353885),r=e.i(393189),i=e.i(265143),l=e.i(148831),u=e.i(619898),h=e.i(636882),d=e.i(786025),c=e.i(704161),p=e.i(640911),w=e.i(41444),y=e.i(660948),m=e.i(54282),f=t([i,l,u,y]);async function g(e,t,o,f){var g,b,A,E,_,j,I,C;let B,P,L=await (0,d.openWorkspace)(),W=e.trim(),q=o?.askedBy??null,[R,U,Y,H,F,D,J,G]=await Promise.all([(0,h.loadSkills)(L),(0,u.listNoteIndex)(),(0,y.listConnectedToolNames)(),(0,l.findPinnedTools)(W),(0,i.listJobBots)(),(0,r.listBotMemory)(W),(0,i.readBotMemoryOn)(),(0,d.readMachineTools)(L)]),K=o&&!o.canBorrow?[]:F.filter(e=>e.name!==W&&!o?.above.includes(e.name)),z=[q?(g=W,b=q,[`You are ${g}, one of the bots that work for the user. ${(0,m.nowLine)()}
1
+ module.exports=[851372,e=>e.a(async(t,o)=>{try{var a=e.i(343747),n=e.i(687388),s=e.i(353885),r=e.i(393189),i=e.i(265143),l=e.i(148831),u=e.i(619898),h=e.i(636882),d=e.i(786025),c=e.i(704161),p=e.i(640911),w=e.i(41444),y=e.i(660948),m=e.i(54282),f=t([i,l,u,y]);async function g(e,t,o,f){var g,b,M,E,I,_,j,B;let C,P,L=await (0,d.openWorkspace)(),W=e.trim(),q=o?.askedBy??null,[U,R,Y,F,D,H,J,K]=await Promise.all([(0,h.loadSkills)(L),(0,u.listNoteIndex)(),(0,y.listConnectedToolNames)(),(0,l.findPinnedTools)(W),(0,i.listJobBots)(),(0,r.listBotMemory)(W),(0,i.readBotMemoryOn)(),(0,d.readMachineTools)(L)]),G=o&&!o.canBorrow?[]:D.filter(e=>e.name!==W&&!o?.above.includes(e.name)),z=[q?(g=W,b=q,[`You are ${g}, one of the bots that work for the user. ${(0,m.nowLine)()}
2
2
 
3
3
  ${k}
4
4
  - **${b}** — a bot on this job, who handed you one part of it. They cannot see your thread.
5
- - **You** — you do that part. What you hand back goes into ${b}'s work as it is, never to Thursday or the user.`,T,$].join("\n\n")):(A=W,[`You are ${A}, one of the bots that work for the user. ${(0,m.nowLine)()}
5
+ - **You** — you do that part. What you hand back goes into ${b}'s work as it is, never to Thursday or the user.`,T,$].join("\n\n")):(M=W,[`You are ${M}, one of the bots that work for the user. ${(0,m.nowLine)()}
6
6
 
7
7
  ${k}
8
- - **You** — you do the work. Your answer goes to Thursday, not to the user, and she tells them what they need from it.`,T,$].join("\n\n")),(E=U,`## Thursday's memory of the user
8
+ - **You** — you do the work. Your answer goes to Thursday, not to the user, and she tells them what they need from it.`,T,$].join("\n\n")),(E=R,`## Thursday's memory of the user
9
9
 
10
10
  What Thursday keeps from talking with them. Open a note from the listing with \`${s.TOOL_NAMES.memory_recall}\` when the job needs something about them; what you find out about them goes in your answer, and she keeps what matters.
11
11
 
@@ -15,24 +15,24 @@ ${(0,m.noteLines)(E)}`),function(e,t){let o=new Set(t.map(e=>`${e.server}/${e.na
15
15
 
16
16
  ${(0,m.mcpToolLines)(a)}
17
17
 
18
- Names only: \`${s.TOOL_NAMES.tool_search}\` returns what each one takes, \`${s.TOOL_NAMES.tool_call}\` runs one.${n}`}(Y,H),(_=R,0===_.length?"":`## Skills
18
+ Names only: \`${s.TOOL_NAMES.tool_search}\` returns what each one takes, \`${s.TOOL_NAMES.tool_call}\` runs one.${n}`}(Y,F),(I=U,0===I.length?"":`## Skills
19
19
 
20
- Written-down methods. When the job is one of these, read it with \`${s.TOOL_NAMES.load_skill}\` before starting.
20
+ Written-down methods. Use the instructions already in your conversation. When the job needs a skill whose full instructions are absent, read it with \`${s.TOOL_NAMES.load_skill}\` before starting.
21
21
 
22
- ${(0,m.skillLines)(_)}`),N(L.cwd,G,f),J?(j=(0,r.botMemoryFolder)(W),B=(I=D).entries.length?I.entries.map(({file:e,line:t,at:o})=>{let s=t?` — ${(0,w.clip)(t,n.PROMPT_LINE.botMemory)}`:"";return`- ${e}${s} \xb7 ${(0,a.format)((0,c.toDate)(o),"yyyy-MM-dd")}`}).join("\n"):"Empty.",P=I.total>I.entries.length?`
22
+ ${(0,m.skillLines)(I)}`),N(L.cwd,K,f),J?(_=(0,r.botMemoryFolder)(W),C=(j=H).entries.length?j.entries.map(({file:e,line:t,at:o})=>{let s=t?` — ${(0,w.clip)(t,n.PROMPT_LINE.botMemory)}`:"";return`- ${e}${s} \xb7 ${(0,a.format)((0,c.toDate)(o),"yyyy-MM-dd")}`}).join("\n"):"Empty.",P=j.total>j.entries.length?`
23
23
 
24
- The newest ${I.entries.length} of ${I.total}; \`ls ${j}\` for the rest.`:"",`## Your memory
24
+ The newest ${j.entries.length} of ${j.total}; \`ls ${_}\` for the rest.`:"",`## Your memory
25
25
 
26
- What you kept from your own earlier jobs, in \`${j}/\` under the Cwd above: one topic per file, its first line saying what it holds, read by no other bot. Keep what a later job would otherwise have to find out again — how a site signs in, the way through its screens, a command that turned out right — with the date you found it true, and fix or delete a file that proved wrong. No passwords, keys or codes.
26
+ What you kept from your own earlier jobs, in \`${_}/\` under the Cwd above: one topic per file, its first line saying what it holds, read by no other bot. Keep what a later job would otherwise have to find out again — how a site signs in, the way through its screens, a command that turned out right — with the date you found it true, and fix or delete a file that proved wrong. No passwords, keys or codes.
27
27
 
28
- ${B}${P}`):"",(C=K,0===C.length?"":`## Bots
28
+ ${C}${P}`):"",(B=G,0===B.length?"":`## Bots
29
29
 
30
- ${C.map(e=>`- **${e.name}** — ${e.description}`).join("\n")}
30
+ ${B.map(e=>`- **${e.name}** — ${e.description}`).join("\n")}
31
31
 
32
32
  These lines were written for the user, who reads them on their own screen: where one says "you" it means them, not you.
33
33
 
34
- A part of your job another bot is for goes to \`${s.TOOL_NAMES.ask_bot}\`, because their tools and their practice are the reason they exist. What you build is made of what they bring back, so send for it before you build. A part you could finish in a couple of commands is yours; one that would take a run of its own is theirs. What you were handed stays yours and you answer for it. They get the job, the call it came from and what you write them — not this thread.`),q?S(q):O,q?M(q):x,v(t)].filter(Boolean).join("\n\n");return(0,m.logPromptSize)("bot",z),p.logger.debug(`bot prompt
35
- ${z}`),{text:z,peers:K.map(e=>e.name),opening:null}}[i,l,u,y]=f.then?(await f)():f;let k=`- **The user** — the one person all of this is for. They talk with Thursday by voice, and they follow this job on their screen.
34
+ A part of your job another bot is for goes to \`${s.TOOL_NAMES.ask_bot}\`, because their tools and their practice are the reason they exist. What you build is made of what they bring back, so send for it before you build. A part you could finish in a couple of commands is yours; one that would take a run of its own is theirs. What you were handed stays yours and you answer for it. They get the job, the call it came from and what you write them — not this thread.`),q?S(q):O,q?A(q):x,v(t)].filter(Boolean).join("\n\n");return(0,m.logPromptSize)("bot",z),p.logger.debug(`bot prompt
35
+ ${z}`),{text:z,peers:G.map(e=>e.name),opening:null}}[i,l,u,y]=f.then?(await f)():f;let k=`- **The user** — the one person all of this is for. They talk with Thursday by voice, and they follow this job on their screen.
36
36
  - **Thursday** — their own personal assistant, one to one. She holds the conversation with them, hands bots the work that takes time, and tells them what comes back.`,T=`**You are on a real computer — the user's own.** You have a shell and a filesystem, and the job is done, not described: where there is no tool for something, write one — in \`node\` unless they asked for another language, the runtime this app itself runs on. Reach for \`${s.TOOL_NAMES.bash}\` before concluding that something cannot be done, but after the roster, not instead of it: a script you write to do another bot's job is the long way round.
37
37
 
38
38
  **What is missing gets installed**, onto the machine once they say yes. What is already there is nobody's question — Environment says what this machine has.
@@ -68,7 +68,7 @@ What you cannot get for yourself goes to \`${s.TOOL_NAMES.ask_back}\`: ${e} hand
68
68
 
69
69
  Every job ends with \`${s.TOOL_NAMES.answer}\`. **Answer what was asked, at the size it was asked**: a question ends in its answer — one number is one line — and a thing to make comes back made, an action done, photos in a page, a comparison in a table. Once you have what they asked for the job is done; the next thing you would go and check is theirs to ask for.
70
70
 
71
- You are answering Thursday, not the user: she picks what to say out of this. Write it plainly, in the user's language — the thread is on their screen as you write it. Anything past a few lines is a file under \`${n.PATHS.artifacts}/\`, and the answer names its path — it becomes a link on their screen. In a \`.md\`, images only by absolute route (\`/api/file/${n.PATHS.artifacts}/…\`).`,M=e=>`## Answering
71
+ You are answering Thursday, not the user: she picks what to say out of this. Write it plainly, in the user's language — the thread is on their screen as you write it. Anything past a few lines is a file under \`${n.PATHS.artifacts}/\`, and the answer names its path — it becomes a link on their screen. In a \`.md\`, images only by absolute route (\`/api/file/${n.PATHS.artifacts}/…\`).`,A=e=>`## Answering
72
72
 
73
73
  Every part ends with \`${s.TOOL_NAMES.answer}\`; what you hand back goes into ${e}'s own answer. Hand back what the brief asked for, in the shape it asked for, with everything you learned that bears on it — exact values, the paths of files you wrote, what did not work. They cannot see your thread, so long is right here.`;function b(e,t){let o=e.length-1,a=e.map((a,n)=>{if(0===n)return n===o?`- **${a} (you)** — ${"user"===t?"the user handed you this job on their screen, not during a call":"Thursday handed you this job during a call"}.`:`- **${a}** — holds this job and answers for it.`;let s=e[n-1];return n===o?`- **${a} (you)** — ${s} handed you one part of it: the last section below. You answer to ${s}; nobody else hears from you.`:`- **${a}** — ${s} handed them one part of it.`});return`## Who is on this job
74
74
 
@@ -82,14 +82,22 @@ ${e.request.trim()}`,s=t.length?`## The call the job came from — its last ${t.
82
82
 
83
83
  A detail missing from the job may be here — a name, a number, which of two. Where the two disagree the job wins, unless they asked out loud for something to be done and the job only asks about it: then the doing is the job.
84
84
 
85
- ${t.map(e=>`${"user"===e.role?"user":"thursday"}: ${(0,w.clip)(e.text,n.PROMPT_LINE.callTurn)}`).join("\n")}`:"";return[{type:"text",text:b([e.bot],e.from)},{type:"text",text:[a,s].filter(Boolean).join("\n\n")}]},"chainOf",0,function(e){return e?.role!=="user"?"":"string"==typeof e.content?e.content:e.content.flatMap(e=>"text"===e.type?[e.text]:[]).at(-1)??""},"loadBotPrompt",0,g]),o()}catch(e){o(e)}},!1),585099,e=>e.a(async(t,o)=>{try{var a=e.i(68356),n=e.i(847841),s=e.i(687388),r=e.i(159479),i=e.i(386075),l=e.i(851372),u=e.i(316172),h=e.i(353885),d=e.i(944971),c=e.i(786025),p=e.i(640911),w=e.i(53748),y=e.i(388439),m=e.i(265143),f=e.i(780274),g=t([r,i,l,m,f]);[r,i,l,m,f]=g.then?(await g)():g;let O=s.BOT_RUN.steps;async function b(e,t){var o,w,g;let b,$,M,A,E,_,j,I,C=t.depth??0,B=t.parent??null,P=e.bot.trim(),L=e=>t.emit({...e,bot:P,parent:B}),W=await (0,m.findJobBot)(P);if(!W)return void await L({type:"error",message:`No bot named "${e.bot}". Use a name from the list.`,failure:"fatal"});if(W.disabled&&"request"in e)return void await L({type:"error",message:`${W.name} is switched off. Use a name from the list.`,failure:"fatal"});let q=await ((o=W).provider&&o.model?(0,i.getTextModel)({provider:o.provider,model:o.model}):(0,i.resolveDefaultModel)().then(i.getTextModel)),R=t.taskId?await (0,f.findTask)(t.taskId):null,[U,Y]=await Promise.all([t.taskId?(0,c.openJobScratch)(t.taskId,R?.label??"job"):null,(0,c.openBotFolder)(P)]),[H,F]=await Promise.all([(0,l.loadBotPrompt)(P,W.systemPrompt,"askedBy"in e?{askedBy:e.askedBy,above:e.above,canBorrow:C<s.BOT_RUN.depth}:null,{scratch:U,own:Y}),(0,r.loadTools)({target:"bot",bot:P,session:t.session??t.taskId,model:q})]),D=Math.min(await (0,i.compactBudget)(q.ref,W.compactAt),("askedBy"in e?0:R?.contextBudget)||1/0),J="messages"in e?e.messages:[{role:"user",content:(0,l.buildHandoff)({chain:e.chain,bots:[...e.above,P],did:e.context??null,part:e.request})}],G={left:s.BOT_RUN.askBack},K="askedBy"in e?function(e,t,o){let a={...e};delete a[h.TOOL_NAMES.ask_thursday];let{answer:s}=o;return s?{...a,[h.TOOL_NAMES.ask_back]:(0,n.tool)({description:u.askBackSpec.description,inputSchema:u.askBackSpec.parameters,execute:async({question:e})=>(t.left-=1,s(e))})}:a}(F,G,t):F,z=C<s.BOT_RUN.depth?function(e,t){if(0===t.peers.length)return e;let o={...e,[h.TOOL_NAMES.ask_bot]:(0,n.tool)({description:u.askBotSpec.description,inputSchema:u.askBotSpec.parameters,execute:async({bot:e,request:a,context:n},s)=>{if(e===t.name||t.above.includes(e))return`${e} is already on this job, above you and waiting on your part. Pick another bot, or do it yourself.`;let r=t.options.taskId?`${t.options.session??t.options.taskId}-${s.toolCallId.slice(0,8)}`:null,i=[],l=async n=>{let r=await N({model:t.model,instructions:t.instructions,tools:o,messages:s.messages,asked:{bot:e,request:a},question:n,signal:t.options.signal});return await t.emit({type:"answered",question:n,...r}),i.push({question:n,answer:r.text}),r.text};try{var u;let o=await v({bot:e,request:a,context:n,askedBy:t.name,chain:t.chain,above:[...t.above,t.name]},{...t.options,signal:s.abortSignal??t.options.signal,depth:t.depth+1,parent:s.toolCallId,session:r,answer:l});return i.length?`${o}
85
+ ${t.map(e=>`${"user"===e.role?"user":"thursday"}: ${(0,w.clip)(e.text,n.PROMPT_LINE.callTurn)}`).join("\n")}`:"";return[{type:"text",text:b([e.bot],e.from)},{type:"text",text:[a,s].filter(Boolean).join("\n\n")}]},"chainOf",0,function(e){return e?.role!=="user"?"":"string"==typeof e.content?e.content:e.content.flatMap(e=>"text"===e.type?[e.text]:[]).at(-1)??""},"loadBotPrompt",0,g]),o()}catch(e){o(e)}},!1),585099,e=>e.a(async(t,o)=>{try{var a=e.i(68356),n=e.i(847841),s=e.i(687388),r=e.i(159479),i=e.i(386075),l=e.i(851372),u=e.i(316172),h=e.i(353885),d=e.i(944971),c=e.i(786025),p=e.i(640911),w=e.i(53748),y=e.i(268486),m=e.i(388439),f=e.i(41444),g=e.i(265143),b=e.i(780274),k=t([r,i,l,g,b]);[r,i,l,g,b]=k.then?(await k)():k;let E=s.BOT_RUN.steps;async function T(e,t){var o,y,k;let T,N,j,B,C,P,L,W,q,U=t.depth??0,R=t.parent??null,Y=await (0,g.findJobBot)(e.bot.trim()),F=Y?.name??e.bot.trim(),D=e=>t.emit({...e,bot:F,parent:R});if(!Y)return void await D({type:"error",message:`No bot named "${e.bot}". Use a name from the list.`,failure:"fatal"});let H="askedBy"in e&&t.taskId?await (0,b.listBotThread)(t.taskId,F):[];if(Y.disabled&&"request"in e&&!H.length)return void await D({type:"error",message:`${Y.name} is switched off. Use a name from the list.`,failure:"fatal"});if(t={...t,desks:t.desks??S()},"messages"in e)q=e.messages;else{let o=H.length?`## ${e.askedBy} → ${F}: the next request
86
86
 
87
- ${u=e,i.map(({question:e,answer:t})=>`(On the way ${u} asked you: "${e}" — you answered: "${t}")`).join("\n")}`:o}finally{r&&(0,c.closeHiddenBrowser)(r)}}})};return o}(K,{name:P,model:q.model,instructions:H.text,peers:H.peers,depth:C,chain:(0,l.chainOf)(J[0]),above:"askedBy"in e?e.above:[],options:t,emit:L}):K,Q={compact:null,interjections:[]},V=(w=s.BOT_RUN.silenceMs,$=new AbortController,M=0,A=!1,E=()=>{clearTimeout(b),b=void 0,A||M>0||(b=setTimeout(()=>{$.abort(new DOMException(`The model sent nothing for ${Math.round(w/6e4)} minutes.`,"TimeoutError"))},w))},{signal:$.signal,touch:E,hold:()=>{M+=1,E()},release:()=>{M=Math.max(0,M-1),E()},end:()=>{A=!0,E()}}),X=0,Z=new a.ToolLoopAgent({model:q.model,instructions:H.text,tools:z,stopWhen:[(0,a.stepCountIs)(O),S,(0,a.hasToolCall)(h.TOOL_NAMES.ask_thursday)],prepareStep:async({stepNumber:e,steps:o,messages:a})=>{let n=e<O-1?{}:{activeTools:[h.TOOL_NAMES.answer],toolChoice:{type:"tool",toolName:h.TOOL_NAMES.answer}};!n.activeTools&&G.left<=0&&(n={...n,activeTools:Object.keys(z).filter(e=>e!==h.TOOL_NAMES.ask_back)});let s=o.at(-1)?.usage.inputTokens??0,r=Math.max(s,a.reduce((e,t)=>e+(0,y.estimateTokens)("string"==typeof t.content?t.content:JSON.stringify(t.content))+4,0));X=r;let i=a;if(r>D&&a.length>2){V.hold();let e=await T(q.model,z,a,{signal:t.signal,budget:D,instructions:H.text}).finally(V.release);p.logger.debug(`compacted ${a.length} messages at ${r} tokens (budget ${D})`);let o=`${e.text}${await k(R?.id??null,a,U)}`;Q.compact={type:"compact",text:o,usage:e.usage,messages:a.length,tokens:r},i=[a[0],{role:"user",content:o}]}let l=e>0?t.notes?.()??[]:[];return(l.length&&(Q.interjections.push(...l),i=[...i,...l.map(e=>({role:"user",content:e}))]),i===a)?n:{...n,messages:i}}}),ee=(_=[],j=[],I=!1,{push(e){let t=j.shift();t?t(e):_.push(e)},take(){let e=_.shift();return e?Promise.resolve(e):I?Promise.resolve(null):new Promise(e=>j.push(e))},end(){for(let e of(I=!0,j.splice(0)))e(null)}}),et=t.signal?AbortSignal.any([t.signal,V.signal]):V.signal;V.touch();let eo=await Z.stream({messages:J,abortSignal:et,onStepEnd:e=>ee.push({messages:e.response.messages,usage:x(e.usage)})}),ea="",en=null,es=null,er=null,ei=-1,el=null,eu=new Set,eh=e=>{let t=(0,i.modelFailureOf)(e),o=(0,i.modelErrorToString)(e);if("overflow"!==t)return{type:"error",message:o,failure:t};let a=Math.floor(Math.min(D,X||D)*s.BOT_RUN.overflowShrink);return{type:"error",message:o,failure:t,budget:Math.max(d.COMPACT_AT_MIN,a)}};et.addEventListener("abort",()=>ee.end(),{once:!0});try{for await(let e of eo.fullStream)switch(V.touch(),e.type){case"start-step":for(let e of(ei+=1,Q.compact&&(await L(Q.compact),Q.compact=null),Q.interjections.splice(0)))await L({type:"interjection",text:e});break;case"text-delta":ea+=e.text;break;case"text-end":{let e=ea.trim();if(ea="",!e)break;en=e,await L({type:"text",text:e});break}case"tool-call":if(e.toolName===h.TOOL_NAMES.ask_thursday){let t=e.input;es={id:e.toolCallId,question:String(t.question??""),options:(0,f.optionsOf)(t.options)}}else if(e.toolName===h.TOOL_NAMES.answer){let t=e.input;er={text:String(t.result??"").trim(),stopped:ei>=O-1}}e.providerExecuted||e.toolName===h.TOOL_NAMES.ask_thursday||(eu.add(e.toolCallId),V.hold()),await L({type:"tool",id:e.toolCallId,name:e.toolName,input:e.input});break;case"tool-result":eu.delete(e.toolCallId)&&V.release(),e.toolName===h.TOOL_NAMES.answer&&er&&!(0,u.answerAccepted)(e.output)&&(er={text:`${er.text}
87
+ ${e.request.trim()}${e.context?.trim()?`
88
88
 
89
- ${g=e.output,"string"==typeof g?g:g&&"object"==typeof g&&"value"in g?"string"==typeof g.value?g.value:JSON.stringify(g.value??""):JSON.stringify(g??"")}`,stopped:!0}),await L({type:"tool-result",id:e.toolCallId,name:e.toolName,output:e.output});break;case"tool-error":eu.delete(e.toolCallId)&&V.release(),await L({type:"tool-result",id:e.toolCallId,name:e.toolName,output:(0,i.modelErrorToString)(e.error),error:!0});break;case"finish-step":{el=e.finishReason;let t=await ee.take();t&&await L({type:"step",...t,budget:D});break}case"abort":if(t.signal?.aborted)return;await L({type:"error",message:e.reason??"The model stopped sending.",failure:"transient"});return;case"error":await L(eh(e.error));return}}finally{ee.end(),V.end()}try{await eo.response}catch(e){if(t.signal?.aborted)return;await L(eh(e));return}es?await L({type:"waiting",...es}):er?await L({type:"answer",...er}):"content-filter"===el?await L({type:"error",message:"The provider's content filter stopped the response.",failure:"fatal"}):await L({type:"answer",text:en??"Stopped without handing anything back.",stopped:null===en||"length"===el||ei>=O-1})}let S=({steps:e})=>e.at(-1)?.toolResults.some(e=>e.toolName===h.TOOL_NAMES.answer&&(0,u.answerAccepted)(e.output))??!1;async function k(e,t,o){try{let a=e?await (0,f.listWrittenPaths)(e):(0,f.writtenPathsIn)(t.map(e=>e.content)),n=await (0,c.filesOnDisk)(a,o);if(!n.length)return"";let r=n.slice(-s.BOT_RUN.compactFiles),i=n.length-r.length,l=r.map(e=>`- ${e}`);return i&&l.unshift(`- …and ${i} older ones`),`
89
+ ## What ${e.askedBy} passes on
90
+
91
+ ${e.context.trim()}`:""}`:(0,l.buildHandoff)({chain:e.chain,bots:[...e.above,F],did:e.context??null,part:e.request});q=[...M(H,t.taskId?await (0,b.listBorrowedTails)(t.taskId):void 0),{role:"user",content:o}],t.signal?.throwIfAborted(),await D({type:"request",content:o})}let J=await ((o=Y).provider&&o.model?(0,i.getTextModel)({provider:o.provider,model:o.model}):(0,i.resolveDefaultModel)().then(i.getTextModel)),K=t.taskId?await (0,b.findTask)(t.taskId):null,[G,z]=await Promise.all([t.taskId?(0,c.openJobScratch)(t.taskId,K?.label??"job"):null,(0,c.openBotFolder)(F)]),[Q,V]=await Promise.all([(0,l.loadBotPrompt)(F,Y.systemPrompt,"askedBy"in e?{askedBy:e.askedBy,above:e.above,canBorrow:U<s.BOT_RUN.depth}:null,{scratch:G,own:z}),(0,r.loadTools)({target:"bot",bot:F,session:t.session??t.taskId,model:J})]),X=Math.min(await (0,i.compactBudget)(J.ref,Y.compactAt),("askedBy"in e?0:K?.contextBudget)||1/0),Z={left:s.BOT_RUN.askBack},ee="askedBy"in e?function(e,t,o){let a={...e};delete a[h.TOOL_NAMES.ask_thursday];let{answer:s}=o;return s?{...a,[h.TOOL_NAMES.ask_back]:(0,n.tool)({description:u.askBackSpec.description,inputSchema:u.askBackSpec.parameters,execute:async({question:e})=>(t.left-=1,s(e))})}:a}(V,Z,t):V,et=U<s.BOT_RUN.depth?function(e,t){if(0===t.peers.length)return e;let o=new WeakMap,a={...e,[h.TOOL_NAMES.ask_bot]:(0,n.tool)({description:u.askBotSpec.description,inputSchema:u.askBotSpec.parameters,execute:async({bot:e,request:n,context:s},r)=>{let l=await (0,g.findJobBot)(e);if(!l)return`No bot named "${e}". Use a name from the list.`;if((e=l.name)===t.name||t.above.includes(e))return`${e} is already above you and waiting on this part. Use ask_back for a question, or pick another bot.`;let u=r.abortSignal??t.options.signal;return t.options.desks.run(t.name,e,u,async()=>{let l=t.options.taskId?(0,c.botBrowserSession)(t.options.taskId,e):null,h=[],d=o.get(r.messages);d||(d={messages:[...r.messages],answer:(0,f.PromiseChain)()},o.set(r.messages,d));let p=d;try{let o=await O({bot:e,request:n,context:s,askedBy:t.name,chain:t.chain,above:[...t.above,t.name]},{...t.options,signal:u,depth:t.depth+1,parent:r.toolCallId,session:l,notes:void 0,answer:o=>p.answer(async()=>{u?.throwIfAborted();let s=await A({model:t.model,instructions:t.instructions,tools:a,messages:p.messages,asked:{bot:e,request:n},question:o,signal:u});return p.messages.push({role:"user",content:`${e} asks about the part you handed over:
92
+
93
+ ${o}`},{role:"assistant",content:s.text}),await t.emit({type:"answered",question:o,...s}),h.push({question:o,answer:s.text}),s.text})});return h.length?`${o}
94
+
95
+ ${x(e,h)}`:o}catch(t){u?.throwIfAborted(),(0,w.publicError)([(0,i.modelErrorToString)(t),x(e,h)].filter(Boolean).join("\n\n"))}})}})};return a}(ee,{name:F,model:J.model,instructions:Q.text,peers:Q.peers,depth:U,chain:(0,l.chainOf)(q[0]),above:"askedBy"in e?e.above:[],options:t,emit:D}):ee,eo={compact:null,interjections:[]},ea=(y=s.BOT_RUN.silenceMs,N=new AbortController,j=0,B=!1,C=()=>{clearTimeout(T),T=void 0,B||j>0||(T=setTimeout(()=>{N.abort(new DOMException(`The model sent nothing for ${Math.round(y/6e4)} minutes.`,"TimeoutError"))},y))},{signal:N.signal,touch:C,hold:()=>{j+=1,C()},release:()=>{j=Math.max(0,j-1),C()},end:()=>{B=!0,C()}}),en=0,es=new a.ToolLoopAgent({model:J.model,instructions:Q.text,tools:et,stopWhen:[(0,a.stepCountIs)(E),I,(0,a.hasToolCall)(h.TOOL_NAMES.ask_thursday)],prepareStep:async({stepNumber:e,steps:o,messages:a})=>{let n=e<E-1?{}:{activeTools:[h.TOOL_NAMES.answer],toolChoice:{type:"tool",toolName:h.TOOL_NAMES.answer}};!n.activeTools&&Z.left<=0&&(n={...n,activeTools:Object.keys(et).filter(e=>e!==h.TOOL_NAMES.ask_back)});let s=o.at(-1)?.usage.inputTokens??0,r=Math.max(s,a.reduce((e,t)=>e+(0,m.estimateTokens)("string"==typeof t.content?t.content:JSON.stringify(t.content))+4,0));en=r;let i=a;if(r>X&&a.length>2){ea.hold();let e=await v(J.model,et,a,{signal:t.signal,budget:X,instructions:Q.text}).finally(ea.release);p.logger.debug(`compacted ${a.length} messages at ${r} tokens (budget ${X})`);let o=`${e.text}${await $(K?.id??null,a,G)}`;eo.compact={type:"compact",text:o,usage:e.usage,messages:a.length,tokens:r},i=[a[0],{role:"user",content:o}]}let l=e>0?t.notes?.()??[]:[];return(l.length&&(eo.interjections.push(...l),i=[...i,...l.map(e=>({role:"user",content:e}))]),i===a)?n:{...n,messages:i}}}),er=(P=[],L=[],W=!1,{push(e){let t=L.shift();t?t(e):P.push(e)},take(){let e=P.shift();return e?Promise.resolve(e):W?Promise.resolve(null):new Promise(e=>L.push(e))},end(){for(let e of(W=!0,L.splice(0)))e(null)}}),ei=t.signal?AbortSignal.any([t.signal,ea.signal]):ea.signal;ea.touch();let el=await es.stream({messages:q,abortSignal:ei,onStepEnd:e=>er.push({messages:e.response.messages,usage:_(e.usage)})}),eu="",eh=null,ed=null,ec=null,ep=-1,ew=null,ey=new Set,em=e=>{let t=(0,i.modelFailureOf)(e),o=(0,i.modelErrorToString)(e);if("overflow"!==t)return{type:"error",message:o,failure:t};let a=Math.floor(Math.min(X,en||X)*s.BOT_RUN.overflowShrink);return{type:"error",message:o,failure:t,budget:Math.max(d.COMPACT_AT_MIN,a)}};ei.addEventListener("abort",()=>er.end(),{once:!0});try{for await(let e of el.fullStream)switch(ea.touch(),e.type){case"start-step":for(let e of(ep+=1,eo.compact&&(await D(eo.compact),eo.compact=null),eo.interjections.splice(0)))await D({type:"interjection",text:e});break;case"text-delta":eu+=e.text;break;case"text-end":{let e=eu.trim();if(eu="",!e)break;eh=e,await D({type:"text",text:e});break}case"tool-call":if(e.toolName===h.TOOL_NAMES.ask_thursday){let t=e.input;ed={id:e.toolCallId,question:String(t.question??""),options:(0,b.optionsOf)(t.options)}}else if(e.toolName===h.TOOL_NAMES.answer){let t=e.input;ec={text:String(t.result??"").trim(),stopped:ep>=E-1}}e.providerExecuted||e.toolName===h.TOOL_NAMES.ask_thursday||(ey.add(e.toolCallId),ea.hold()),await D({type:"tool",id:e.toolCallId,name:e.toolName,input:e.input});break;case"tool-result":ey.delete(e.toolCallId)&&ea.release(),e.toolName===h.TOOL_NAMES.answer&&ec&&!(0,u.answerAccepted)(e.output)&&(ec={text:`${ec.text}
96
+
97
+ ${k=e.output,"string"==typeof k?k:k&&"object"==typeof k&&"value"in k?"string"==typeof k.value?k.value:JSON.stringify(k.value??""):JSON.stringify(k??"")}`,stopped:!0}),await D({type:"tool-result",id:e.toolCallId,name:e.toolName,output:e.output});break;case"tool-error":ey.delete(e.toolCallId)&&ea.release(),await D({type:"tool-result",id:e.toolCallId,name:e.toolName,output:(0,i.modelErrorToString)(e.error),error:!0});break;case"finish-step":{ew=e.finishReason;let t=await er.take();t&&await D({type:"step",...t,budget:X});break}case"abort":if(t.signal?.aborted)return;await D({type:"error",message:e.reason??"The model stopped sending.",failure:"transient"});return;case"error":await D(em(e.error));return}}finally{er.end(),ea.end()}try{await el.response}catch(e){if(t.signal?.aborted)return;await D(em(e));return}ed?await D({type:"waiting",...ed}):ec?await D({type:"answer",...ec}):"content-filter"===ew?await D({type:"error",message:"The provider's content filter stopped the response.",failure:"fatal"}):await D({type:"answer",text:eh??"Stopped without handing anything back.",stopped:null===eh||"length"===ew||ep>=E-1})}let I=({steps:e})=>e.at(-1)?.toolResults.some(e=>e.toolName===h.TOOL_NAMES.answer&&(0,u.answerAccepted)(e.output))??!1;async function $(e,t,o){try{let a=e?await (0,b.listWrittenPaths)(e):(0,b.writtenPathsIn)(t.map(e=>e.content)),n=await (0,c.filesOnDisk)(a,o);if(!n.length)return"";let r=n.slice(-s.BOT_RUN.compactFiles),i=n.length-r.length,l=r.map(e=>`- ${e}`);return i&&l.unshift(`- …and ${i} older ones`),`
90
98
 
91
99
  Files this job has on disk now — open one rather than fetching again what is in it:
92
- ${l.join("\n")}`}catch(e){return p.logger.warn("files under the summary could not be listed",e),""}}async function T(e,t,o,n){let s;try{return await $(e,t,o,n)}catch(e){if(n.signal?.aborted)throw e;s=e}if("overflow"===(0,i.modelFailureOf)(s)){let r=(0,a.pruneMessages)({messages:o,toolCalls:"before-last-4-messages",emptyMessages:"remove"});try{return await $(e,t,r,n)}catch(e){if(n.signal?.aborted)throw e;s=e}}throw Error(`Could not compact the context (${(0,i.modelErrorToString)(s)}).`,{cause:s})}async function $(e,t,o,n){let r,{text:i,usage:l}=await (0,a.generateText)({model:e,system:n.instructions,tools:t,toolChoice:"none",messages:[...o,{role:"user",content:(r=(e=>{let{min:t,max:o,perTokens:a}=s.BOT_RUN.summaryWords;return Math.min(o,Math.max(t,Math.round(e/a)))})(n.budget),`Compact your context. The first message above — the job, the call it came from, and anything handed over with it — 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.
100
+ ${l.join("\n")}`}catch(e){return p.logger.warn("files under the summary could not be listed",e),""}}async function v(e,t,o,n){let s;try{return await N(e,t,o,n)}catch(e){if(n.signal?.aborted)throw e;s=e}if("overflow"===(0,i.modelFailureOf)(s)){let r=(0,a.pruneMessages)({messages:o,toolCalls:"before-last-4-messages",emptyMessages:"remove"});try{return await N(e,t,r,n)}catch(e){if(n.signal?.aborted)throw e;s=e}}throw Error(`Could not compact the context (${(0,i.modelErrorToString)(s)}).`,{cause:s})}async function N(e,t,o,n){let r,{text:i,usage:l}=await (0,a.generateText)({model:e,system:n.instructions,tools:t,toolChoice:"none",messages:[...o,{role:"user",content:(r=(e=>{let{min:t,max:o,perTokens:a}=s.BOT_RUN.summaryWords;return Math.min(o,Math.max(t,Math.round(e/a)))})(n.budget),`Compact your context. The first message above — the job, the call it came from, and anything handed over with it — 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.
93
101
 
94
102
  Cover all of it, and prefer a fact over a description of a fact:
95
103
 
@@ -102,9 +110,9 @@ Cover all of it, and prefer a fact over a description of a fact:
102
110
 
103
111
  Plain text, under ${r} words. No preamble, no headings about the summary itself, no account of how you have been going.`)}],abortSignal:n.signal,timeout:s.BOT_RUN.silenceMs}),u=i.trim();if(!u)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.
104
112
 
105
- ${u}`,usage:x(l)}}let x=e=>({input:e.inputTokens??0,output:e.outputTokens??0});async function v(e,t){let o="",a=null;return await b(e,{...t,emit:async e=>{"answer"===e.type&&(o=e.stopped?`${e.text}
113
+ ${u}`,usage:_(l)}}let _=e=>({input:e.inputTokens??0,output:e.outputTokens??0});async function O(e,t){let o="",a=null;return await T(e,{...t,emit:async e=>{e.parent===(t.parent??null)&&"answer"===e.type&&(o=e.stopped?`${e.text}
106
114
 
107
- (As far as they got — they stopped before finishing.)`:e.text),"error"===e.type&&(a=e.message),await t.emit(e)}}),a&&(0,w.publicError)(a),o}async function N(e){try{let t,o,{text:n,usage:r}=await (0,a.generateText)({model:e.model,system:e.instructions,tools:e.tools,toolChoice:"none",messages:[...e.messages,{role:"user",content:(t=e.asked,o=e.question,`You handed one part of your job to ${t.bot}:
115
+ (As far as they got — they stopped before finishing.)`:e.text),e.parent===(t.parent??null)&&"error"===e.type&&(a=e.message),await t.emit(e)}}),t.signal?.throwIfAborted(),a&&(0,w.publicError)(a),o}function S(){let e=(0,y.createKeyedLock)(),t=new Map,o=new Set,a=(e,o,n=new Set)=>e===o||!n.has(e)&&(n.add(e),[...t.get(e)?.keys()??[]].some(e=>a(e,o,n)));return{async run(n,s,r,i){r?.throwIfAborted(),a(s,n)&&(0,w.publicError)(`${s} is waiting on your work. Finish this part before asking them, or choose another bot.`);let l=t.get(n)??new Map;t.set(n,l),l.set(s,(l.get(s)??0)+1);let u=e(s,async()=>(r?.throwIfAborted(),i()));o.add(u);try{return await u}finally{o.delete(u);let e=(l.get(s)??1)-1;e?l.set(s,e):l.delete(s),l.size||t.delete(n)}},async settle(){for(;o.size;)await Promise.allSettled([...o])}}}function x(e,t){return t.map(({question:t,answer:o})=>`(On the way ${e} asked you: "${t}" — you answered: "${o}")`).join("\n")}async function A(e){try{let t,o,{text:n,usage:r}=await (0,a.generateText)({model:e.model,system:e.instructions,tools:e.tools,toolChoice:"none",messages:[...e.messages,{role:"user",content:(t=e.asked,o=e.question,`You handed one part of your job to ${t.bot}:
108
116
 
109
117
  > ${t.request.trim()}
110
118
 
@@ -112,11 +120,11 @@ Before going on, they ask you:
112
120
 
113
121
  > ${o.trim()}
114
122
 
115
- Answer from what you already have — the request as it reached you, the call it came out of, what you found before asking them. A few lines, plain text, and nothing else: no tools run here. If it is not in what you have, say so rather than guess, and say which way to go without it.`)}],abortSignal:e.signal,timeout:s.BOT_RUN.silenceMs});return{text:n.trim()||"They had nothing to add. Go on with your best reading, and say what you assumed in what you hand back.",usage:x(r)}}catch(t){if(e.signal?.aborted)throw t;return p.logger.warn(`ask_back: ${(0,i.modelErrorToString)(t)}`),{text:`No answer came back (${(0,i.modelErrorToString)(t)}). Go on with your best reading, and say what you assumed in what you hand back.`,usage:d.NO_TOKENS}}}e.s(["resumeThread",0,function(e,t=new Map){let o=new Set;for(let t of e)if(("tool"===t.role||"assistant"===t.role)&&"string"!=typeof t.content)for(let e of t.content)"tool-result"===e.type&&o.add(e.toolCallId);let a=[],n=[];for(let s of e){if(n.length&&"tool"===s.role){a.push({...s,content:[...n,...s.content]}),n=[];continue}n.length&&(a.push({role:"tool",content:n}),n=[]),a.push(s),"assistant"===s.role&&"string"!=typeof s.content&&(n=s.content.flatMap(e=>"tool-call"!==e.type||o.has(e.toolCallId)?[]:[{type:"tool-result",toolCallId:e.toolCallId,toolName:e.toolName,output:{type:"text",value:function(e,t){let o=e.toolName===h.TOOL_NAMES.ask_bot?t.get(e.toolCallId):void 0;return o?`No result: the run was stopped before ${o.bot} answered, and they are not working on it any more. What they had written by then:
123
+ Answer from what you already have — the request as it reached you, the call it came out of, what you found before asking them. A few lines, plain text, and nothing else: no tools run here. If it is not in what you have, say so rather than guess, and say which way to go without it.`)}],abortSignal:e.signal,timeout:s.BOT_RUN.silenceMs});return{text:n.trim()||"They had nothing to add. Go on with your best reading, and say what you assumed in what you hand back.",usage:_(r)}}catch(t){if(e.signal?.aborted)throw t;return p.logger.warn(`ask_back: ${(0,i.modelErrorToString)(t)}`),{text:`No answer came back (${(0,i.modelErrorToString)(t)}). Go on with your best reading, and say what you assumed in what you hand back.`,usage:d.NO_TOKENS}}}function M(e,t=new Map){let o=new Set;for(let t of e)if(("tool"===t.role||"assistant"===t.role)&&"string"!=typeof t.content)for(let e of t.content)"tool-result"===e.type&&o.add(e.toolCallId);let a=[],n=[];for(let s of e){if(n.length&&"tool"===s.role){a.push({...s,content:[...n,...s.content]}),n=[];continue}n.length&&(a.push({role:"tool",content:n}),n=[]),a.push(s),"assistant"===s.role&&"string"!=typeof s.content&&(n=s.content.flatMap(e=>"tool-call"!==e.type||o.has(e.toolCallId)?[]:[{type:"tool-result",toolCallId:e.toolCallId,toolName:e.toolName,output:{type:"text",value:function(e,t){let o=e.toolName===h.TOOL_NAMES.ask_bot?t.get(e.toolCallId):void 0;return o?`No result: the run was stopped before ${o.bot} answered, and they are not working on it any more. What they had written by then:
116
124
 
117
125
  ${o.tail}
118
126
 
119
- Check what they did before relying on it, then finish the part yourself or hand them what is left.`:"No result: the run was stopped before this call returned. Check what it did before relying on it."}(e,t)}}]))}return n.length&&a.push({role:"tool",content:n}),a},"runBot",0,b]),o()}catch(e){o(e)}},!1),39803,e=>e.a(async(t,o)=>{try{var a=e.i(380690),n=e.i(687388),s=e.i(386075),r=e.i(851372),i=e.i(353885),l=e.i(22676),u=e.i(629668),h=e.i(786025),d=e.i(167004),c=e.i(640911),p=e.i(53748),w=e.i(268486),y=e.i(585099),m=e.i(944971),f=e.i(780274),g=t([s,r,l,y,f]);[s,r,l,y,f]=g.then?(await g)():g;let _=globalThis.__botRuns??=new Map,j=globalThis.__botTaskLock??=(0,w.createKeyedLock)(),I=globalThis.__botResumes??=new Map;async function b(e){let{from:t,...o}=e,a=o.callId?await (0,l.listCallTurns)(o.callId,r.OPENING_TURNS):[],n=(0,r.buildTaskOpening)({bot:o.bot,request:o.request,conversation:a,from:t}),s=await (0,f.insertTask)({...o,opening:n});return x(s.id,{bot:o.bot,messages:[{role:"user",content:n}]}),s.id}async function k(e,t,o){let a=o?(0,m.tagSpeaker)(o,t):t;return j(e,async()=>{let t=await (0,f.findTask)(e);t||(0,p.publicError)("No such job.");let o=_.get(e);if(o&&"running"===t.status&&o.note(a))return void c.logger.debug(`task ${e}: interjection queued`);o&&(o.stop.abort(),await o.done),$(e);let n=await (0,f.listThread)(e),{reply:s,as:r}=function(e,t,o){var a;let n,s,r="waiting"===e.status?e.pending:null,l=r?.toolCallId?(a=r.toolCallId,n=new Set(o.flatMap(e=>"tool"===e.role?e.content.flatMap(e=>"tool-result"===e.type?[e.toolCallId]:[]):[])),s=o.findLast(e=>"assistant"===e.role&&"string"!=typeof e.content&&e.content.some(e=>"tool-call"===e.type&&e.toolCallId===a)),(s?.role==="assistant"&&"string"!=typeof s.content?s.content.flatMap(e=>"tool-call"===e.type&&e.toolName===i.TOOL_NAMES.ask_thursday?[e.toolCallId]:[]):[a]).filter(e=>!n.has(e))):[];return l.length?{as:"answer",reply:{role:"tool",content:l.map(e=>({type:"tool-result",toolCallId:e,toolName:i.TOOL_NAMES.ask_thursday,output:{type:"text",value:t}}))}}:{as:"running"===e.status?"interruption":"waiting"===e.status?"answer":"follow-up",reply:{role:"user",content:t}}}(t,a,n);c.logger.debug(`task ${e}: ${r}`),await (0,f.upsertMessage)(e,await (0,f.lastSeq)(e)+1,{bot:null,parent:null,...s}),await (0,f.updateTask)(e,{status:"running",outcome:null,pending:null,seen:!1,endedAt:null}),x(e,{bot:t.bot,messages:(0,y.resumeThread)([...n,s],await (0,f.listBorrowedTails)(e))})})}async function T(e){return j(e,async()=>{let t=await (0,f.findTask)(e);t||(0,p.publicError)("No such job."),t.endedAt&&(0,p.publicError)("That job has already ended."),$(e),_.get(e)?.stop.abort(),await (0,f.updateTask)(e,{status:"failed",outcome:"Cancelled.",pending:null,seen:!0,endedAt:new Date}),(0,h.closeJobShell)(e)})}function $(e){clearTimeout(I.get(e)),I.delete(e)}async function v(e){a.presence.watching&&await j(e,async()=>{let t=await (0,f.findTask)(e);if(!t||"waiting"!==t.status||!t.pending?.auto||_.has(e))return;c.logger.debug(`task ${e}: picking back up`);let o=await (0,f.listThread)(e);await (0,f.updateTask)(e,{status:"running",outcome:null,pending:null,seen:!1,endedAt:null}),x(e,{bot:t.bot,messages:(0,y.resumeThread)(o,await (0,f.listBorrowedTails)(e))})})}async function N(e,t){let o=await (0,f.countStopsSinceSpoken)(e),a=o<n.BOT_RUN.autoResumes,s=n.BOT_RUN.retryAfterMs,r=a&&t.retry?s[Math.min(o,s.length-1)]:0;await O(e,(0,f.stopNote)(t.why)).catch(t=>c.logger.warn(`task ${e}: stop not written`,t)),await S(e,{status:"waiting",outcome:a?`${t.why} ${r?`It tries again in ${C(r)}.`:"It picks back up by itself."}`:`${t.why} It has stopped ${o+1} times in a row, so it waits for you. Everything it had done is still here.`,pending:{toolCallId:null,options:[m.TASK_CONTINUE],...a?{auto:!0,retryAt:Date.now()+r}:{}},...t.budget?{contextBudget:t.budget}:{},seen:!1,endedAt:null}),a&&($(e),I.set(e,setTimeout(()=>{I.delete(e),v(e).catch(t=>c.logger.error(`task ${e}: resume`,t))},Math.max(0,r))))}globalThis.__botPausing??={current:Promise.resolve()};let C=e=>e<6e4?`${Math.round(e/1e3)} seconds`:`${Math.round(e/6e4)} minutes`;async function O(e,t){await (0,f.upsertMessage)(e,await (0,f.lastSeq)(e)+1,{bot:null,parent:null,role:"user",content:t,note:!0})}async function S(e,t){for(let o of[1e3,3e3,null])try{await (0,f.updateTask)(e,t);return}catch(t){if(null===o)throw t;c.logger.warn(`task ${e}: ending not written, trying again`,t),await new Promise(e=>setTimeout(e,o))}}function x(e,t){let o=new AbortController,a=()=>{},n=new Promise(e=>{a=e}),s=[];_.set(e,{stop:o,done:n,note:t=>!!_.has(e)&&(s.push(t),!0)}),M(e,t,o.signal,s).catch(t=>{c.logger.error(`task ${e}`,t)}).finally(a)}class B{taskId;seq;steps;closed;constructor(e,t){this.taskId=e,this.steps=new Map,this.closed=!1,this.seq=t}close(){this.closed=!0}async note(e){await (0,f.upsertMessage)(this.taskId,++this.seq,{bot:null,parent:null,role:"user",content:e,note:!0})}step(e){let t=`${e.bot} ${e.parent??""}`,o=this.steps.get(t);return o||(o={assistant:null,tool:null,parts:{assistant:[],tool:[]}},this.steps.set(t,o)),o}write(e,t,o,a={}){let n={bot:t.bot,parent:t.parent,role:o.role,content:o.content,compact:a.compact??!1,note:a.note??!1};return(0,f.upsertMessage)(this.taskId,e,n)}async on(e){if(this.closed)return;let t=this.step(e);switch(e.type){case"text":return t.assistant??=++this.seq,t.parts.assistant.push({type:"text",text:e.text}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool":return t.assistant??=++this.seq,t.parts.assistant.push({type:"tool-call",toolCallId:e.id,toolName:e.name,input:e.input}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool-result":return t.assistant??=++this.seq,t.tool??=++this.seq,t.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.write(t.tool,e,{role:"tool",content:t.parts.tool});case"step":{let o=[t.assistant,t.tool];this.steps.delete(`${e.bot} ${e.parent??""}`);let a=new Set;for(let[t,n]of e.messages.entries()){let s=o[t]??++this.seq;a.add(s),await this.write(s,e,n)}let n=o.filter(e=>null!==e&&!a.has(e));n.length&&await (0,f.deleteMessages)(this.taskId,n);return}case"compact":return this.write(++this.seq,e,{role:"user",content:e.text},{compact:!0,note:!0});case"interjection":return this.write(++this.seq,e,{role:"user",content:e.text});default:return}}}async function M(e,t,o,r){let i=new B(e,await (0,f.lastSeq)(e)),l=null,d=null;try{await (0,y.runBot)(t,{signal:o,taskId:e,notes:()=>r.splice(0),emit:async t=>{await i.on(t),"step"===t.type&&await (0,f.addTaskUsage)(e,t.usage,t.parent?null:{tokens:t.usage.input,budget:t.budget}),("compact"===t.type||"answered"===t.type)&&await (0,f.addTaskUsage)(e,t.usage),t.parent||("waiting"===t.type?l={status:"waiting",outcome:t.question,pending:{toolCallId:t.id,options:t.options}}:"answer"===t.type?l=t.stopped?{status:"waiting",outcome:t.text,pending:{toolCallId:null,options:[m.TASK_CONTINUE]}}:{status:"done",outcome:t.text,pending:null}:"error"===t.type&&(d={message:t.message,failure:t.failure,budget:t.budget},l={status:"failed",outcome:A(t.message),pending:null}))}})}catch(e){d={message:(0,s.modelErrorToString)(e),failure:(0,s.modelFailureOf)(e)},l={status:"failed",outcome:A(d.message),pending:null}}finally{i.close(),_.delete(e)}if(o.aborted)return;let p=l??{status:"failed",outcome:"Stopped without handing anything back.",pending:null},w=d&&"fatal"!==d.failure?d:null;try{w?await N(e,{why:"overflow"===w.failure?`The model refused the context as too long (${w.message}); it is compacted before going on.`:`The model call failed (${w.message}).`,retry:"transient"===w.failure,budget:w.budget}):("failed"===p.status&&await i.note(`The run stopped here: ${d?.message??p.outcome}`).catch(t=>c.logger.warn(`task ${e}: break not written`,t)),await S(e,{...p,seen:!1,endedAt:"waiting"===p.status?null:new Date}))}catch(t){c.logger.error(`task ${e}: could not record how it ended`,t);return}w||"waiting"===p.status?(0,h.pruneJobFiles)():(0,h.closeHiddenBrowser)(e);let g=await (0,f.findTask)(e);if(g){if(r.length){let t=r.splice(0).join("\n\n");c.logger.debug(`task ${e}: interjection after the run ended — resuming`),k(e,t).catch(t=>{c.logger.error(`task ${e}: late interjection`,t)});return}if(!w&&(await E(g.label,p),"done"===p.status)){var b;let t,o=(b=p.outcome,(t=(0,u.pathsIn)(b)).find(e=>e.startsWith(`${n.PATHS.artifacts}/`))??t[0]??null);o&&a.appEvents.emit({type:"artifact",taskId:e,label:g.label,path:o})}}}function A(e){return`The run broke: ${e}
127
+ Check what they did before relying on it, then finish the part yourself or hand them what is left.`:"No result: the run was stopped before this call returned. Check what it did before relying on it."}(e,t)}}]))}return n.length&&a.push({role:"tool",content:n}),a}e.s(["createBotDesks",0,S,"resumeThread",0,M,"runBot",0,T]),o()}catch(e){o(e)}},!1),39803,e=>e.a(async(t,o)=>{try{var a=e.i(380690),n=e.i(687388),s=e.i(386075),r=e.i(851372),i=e.i(353885),l=e.i(22676),u=e.i(629668),h=e.i(786025),d=e.i(167004),c=e.i(640911),p=e.i(53748),w=e.i(268486),y=e.i(585099),m=e.i(944971),f=e.i(780274),g=t([s,r,l,y,f]);[s,r,l,y,f]=g.then?(await g)():g;let I=globalThis.__botRuns??=new Map,_=globalThis.__botTaskLock??=(0,w.createKeyedLock)(),j=globalThis.__botResumes??=new Map;async function b(e){let{from:t,...o}=e,a=o.callId?await (0,l.listCallTurns)(o.callId,r.OPENING_TURNS):[],n=(0,r.buildTaskOpening)({bot:o.bot,request:o.request,conversation:a,from:t}),s=await (0,f.insertTask)({...o,opening:n});return x(s.id,{bot:o.bot,messages:[{role:"user",content:n}]}),s.id}async function k(e,t,o){let a=o?(0,m.tagSpeaker)(o,t):t;return _(e,async()=>{let t=await (0,f.findTask)(e);t||(0,p.publicError)("No such job.");let o=I.get(e);if(o&&"running"===t.status&&o.note(a))return void c.logger.debug(`task ${e}: interjection queued`);o&&(o.stop.abort(),await o.done),$(e);let n=await (0,f.listThread)(e),{reply:s,as:r}=function(e,t,o){var a;let n,s,r="waiting"===e.status?e.pending:null,l=r?.toolCallId?(a=r.toolCallId,n=new Set(o.flatMap(e=>"tool"===e.role?e.content.flatMap(e=>"tool-result"===e.type?[e.toolCallId]:[]):[])),s=o.findLast(e=>"assistant"===e.role&&"string"!=typeof e.content&&e.content.some(e=>"tool-call"===e.type&&e.toolCallId===a)),(s?.role==="assistant"&&"string"!=typeof s.content?s.content.flatMap(e=>"tool-call"===e.type&&e.toolName===i.TOOL_NAMES.ask_thursday?[e.toolCallId]:[]):[a]).filter(e=>!n.has(e))):[];return l.length?{as:"answer",reply:{role:"tool",content:l.map(e=>({type:"tool-result",toolCallId:e,toolName:i.TOOL_NAMES.ask_thursday,output:{type:"text",value:t}}))}}:{as:"running"===e.status?"interruption":"waiting"===e.status?"answer":"follow-up",reply:{role:"user",content:t}}}(t,a,n);c.logger.debug(`task ${e}: ${r}`),await (0,f.upsertMessage)(e,await (0,f.lastSeq)(e)+1,{bot:null,parent:null,...s}),await (0,f.updateTask)(e,{status:"running",outcome:null,pending:null,seen:!1,endedAt:null}),x(e,{bot:t.bot,messages:(0,y.resumeThread)([...n,s],await (0,f.listBorrowedTails)(e))})})}async function T(e){return _(e,async()=>{let t=await (0,f.findTask)(e);t||(0,p.publicError)("No such job."),t.endedAt&&(0,p.publicError)("That job has already ended."),$(e);let o=I.get(e);o?.stop.abort(),await (0,f.updateTask)(e,{status:"failed",outcome:"Cancelled.",pending:null,seen:!0,endedAt:new Date}),await o?.done,await (0,h.closeJobShell)(e)})}function $(e){clearTimeout(j.get(e)),j.delete(e)}async function v(e){a.presence.watching&&await _(e,async()=>{let t=await (0,f.findTask)(e);if(!t||"waiting"!==t.status||!t.pending?.auto||I.has(e))return;c.logger.debug(`task ${e}: picking back up`);let o=await (0,f.listThread)(e);await (0,f.updateTask)(e,{status:"running",outcome:null,pending:null,seen:!1,endedAt:null}),x(e,{bot:t.bot,messages:(0,y.resumeThread)(o,await (0,f.listBorrowedTails)(e))})})}async function N(e,t){let o=await (0,f.countStopsSinceSpoken)(e),a=o<n.BOT_RUN.autoResumes,s=n.BOT_RUN.retryAfterMs,r=a&&t.retry?s[Math.min(o,s.length-1)]:0;await O(e,(0,f.stopNote)(t.why)).catch(t=>c.logger.warn(`task ${e}: stop not written`,t)),await S(e,{status:"waiting",outcome:a?`${t.why} ${r?`It tries again in ${B(r)}.`:"It picks back up by itself."}`:`${t.why} It has stopped ${o+1} times in a row, so it waits for you. Everything it had done is still here.`,pending:{toolCallId:null,options:[m.TASK_CONTINUE],...a?{auto:!0,retryAt:Date.now()+r}:{}},...t.budget?{contextBudget:t.budget}:{},seen:!1,endedAt:null}),a&&($(e),j.set(e,setTimeout(()=>{j.delete(e),v(e).catch(t=>c.logger.error(`task ${e}: resume`,t))},Math.max(0,r))))}globalThis.__botPausing??={current:Promise.resolve()};let B=e=>e<6e4?`${Math.round(e/1e3)} seconds`:`${Math.round(e/6e4)} minutes`;async function O(e,t){await (0,f.upsertMessage)(e,await (0,f.lastSeq)(e)+1,{bot:null,parent:null,role:"user",content:t,note:!0})}async function S(e,t){for(let o of[1e3,3e3,null])try{await (0,f.updateTask)(e,t);return}catch(t){if(null===o)throw t;c.logger.warn(`task ${e}: ending not written, trying again`,t),await new Promise(e=>setTimeout(e,o))}}function x(e,t){let o=new AbortController,a=()=>{},n=new Promise(e=>{a=e}),s=[];I.set(e,{stop:o,done:n,note:t=>!!I.has(e)&&(s.push(t),!0)}),A(e,t,o.signal,s).catch(t=>{c.logger.error(`task ${e}`,t)}).finally(a)}class C{taskId;seq;steps;closed;constructor(e,t){this.taskId=e,this.steps=new Map,this.closed=!1,this.seq=t}close(){this.closed=!0}async note(e){await (0,f.upsertMessage)(this.taskId,++this.seq,{bot:null,parent:null,role:"user",content:e,note:!0})}step(e){let t=`${e.bot} ${e.parent??""}`,o=this.steps.get(t);return o||(o={assistant:null,tool:null,parts:{assistant:[],tool:[]}},this.steps.set(t,o)),o}write(e,t,o,a={}){let n={bot:t.bot,parent:t.parent,role:o.role,content:o.content,compact:a.compact??!1,note:a.note??!1};return(0,f.upsertMessage)(this.taskId,e,n)}async on(e){if(this.closed)return;let t=this.step(e);switch(e.type){case"request":return this.write(++this.seq,e,{role:"user",content:e.content});case"text":return t.assistant??=++this.seq,t.parts.assistant.push({type:"text",text:e.text}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool":return t.assistant??=++this.seq,t.parts.assistant.push({type:"tool-call",toolCallId:e.id,toolName:e.name,input:e.input}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool-result":return t.assistant??=++this.seq,t.tool??=++this.seq,t.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.write(t.tool,e,{role:"tool",content:t.parts.tool});case"step":{let o=[t.assistant,t.tool];this.steps.delete(`${e.bot} ${e.parent??""}`);let a=new Set;for(let[t,n]of e.messages.entries()){let s=o[t]??++this.seq;a.add(s),await this.write(s,e,n)}let n=o.filter(e=>null!==e&&!a.has(e));n.length&&await (0,f.deleteMessages)(this.taskId,n);return}case"compact":return this.write(++this.seq,e,{role:"user",content:e.text},{compact:!0,note:!0});case"interjection":return this.write(++this.seq,e,{role:"user",content:e.text});default:return}}}async function A(e,t,o,r){let i=new C(e,await (0,f.lastSeq)(e)),l=(0,y.createBotDesks)(),d=null,p=null;try{await (0,y.runBot)(t,{signal:o,taskId:e,desks:l,notes:()=>r.splice(0),emit:async t=>{await i.on(t),"step"===t.type&&await (0,f.addTaskUsage)(e,t.usage,t.parent?null:{tokens:t.usage.input,budget:t.budget}),("compact"===t.type||"answered"===t.type)&&await (0,f.addTaskUsage)(e,t.usage),t.parent||("waiting"===t.type?d={status:"waiting",outcome:t.question,pending:{toolCallId:t.id,options:t.options}}:"answer"===t.type?d=t.stopped?{status:"waiting",outcome:t.text,pending:{toolCallId:null,options:[m.TASK_CONTINUE]}}:{status:"done",outcome:t.text,pending:null}:"error"===t.type&&(p={message:t.message,failure:t.failure,budget:t.budget},d={status:"failed",outcome:M(t.message),pending:null}))}})}catch(e){p={message:(0,s.modelErrorToString)(e),failure:(0,s.modelFailureOf)(e)},d={status:"failed",outcome:M(p.message),pending:null}}finally{await l.settle(),i.close(),I.delete(e)}if(o.aborted)return;let w=d??{status:"failed",outcome:"Stopped without handing anything back.",pending:null},g=p&&"fatal"!==p.failure?p:null;try{g?await N(e,{why:"overflow"===g.failure?`The model refused the context as too long (${g.message}); it is compacted before going on.`:`The model call failed (${g.message}).`,retry:"transient"===g.failure,budget:g.budget}):("failed"===w.status&&await i.note(`The run stopped here: ${p?.message??w.outcome}`).catch(t=>c.logger.warn(`task ${e}: break not written`,t)),await S(e,{...w,seen:!1,endedAt:"waiting"===w.status?null:new Date}))}catch(t){c.logger.error(`task ${e}: could not record how it ended`,t);return}(0,h.pruneJobFiles)();let b=await (0,f.findTask)(e);if(b){if(r.length){let t=r.splice(0).join("\n\n");c.logger.debug(`task ${e}: interjection after the run ended — resuming`),k(e,t).catch(t=>{c.logger.error(`task ${e}: late interjection`,t)});return}if(!g&&(await E(b.label,w),"done"===w.status)){var T;let t,o=(T=w.outcome,(t=(0,u.pathsIn)(T)).find(e=>e.startsWith(`${n.PATHS.artifacts}/`))??t[0]??null);o&&a.appEvents.emit({type:"artifact",taskId:e,label:b.label,path:o})}}}function M(e){return`The run broke: ${e}
120
128
 
121
129
  Everything it had done is still here — answer to pick it back up.`}async function E(e,t){if(0!==a.appEventStream.watchers&&await (0,l.isAnyCallLive)())return;let o="waiting"===t.status?`${e} — needs you`:e;(0,d.desktopNotify)(o,t.outcome)}e.s(["answerTask",0,k,"cancelTask",0,T,"startTask",0,b]),o()}catch(e){o(e)}},!1),167004,e=>{"use strict";var t=e.i(874533),o=e.i(687388);let a=`on run argv
122
130
  display notification (item 2 of argv) with title (item 1 of argv)
@@ -1,3 +1,3 @@
1
1
  module.exports=[548368,e=>e.a(async(t,a)=>{try{var r=e.i(687388),n=e.i(22676),i=e.i(91264),o=t([n]);[n]=o.then?(await o)():o;let s=(0,i.serverRoute)(e=>{let t=new URL(e.url).searchParams.get("before"),a=t?new Date(t):null;return(0,n.listCallHistory)({before:a&&!Number.isNaN(a.getTime())?a:null,limit:r.CALL_HISTORY_PAGE})});e.s(["GET",0,s]),a()}catch(e){a(e)}},!1),252838,e=>{"use strict";var t=e.i(747909),a=e.i(174017),r=e.i(996250),n=e.i(759756),i=e.i(561916),o=e.i(174677),s=e.i(869741),l=e.i(316795),u=e.i(487718),d=e.i(995169),c=e.i(47587),p=e.i(666012),h=e.i(570101),R=e.i(626937),v=e.i(10372),m=e.i(193695);e.i(52474);var g=e.i(600220);let f=new t.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/thursday/call/route",pathname:"/api/thursday/call",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/app/api/thursday/call/route.ts",nextConfigOutput:"standalone",userland:()=>e.r(548368),...{}}),{workAsyncStorage:E,workUnitAsyncStorage:w,serverHooks:C}=f;async function x(e,t,r){r.requestMeta&&(0,n.setRequestMeta)(e,r.requestMeta),f.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let E="/api/thursday/call/route";E=E.replace(/\/index$/,"")||"/";let w=await f.prepare(e,t,{srcPage:E,multiZoneDraftMode:!1});if(!w)return t.statusCode=400,t.end("Bad Request"),null==r.waitUntil||r.waitUntil.call(r,Promise.resolve()),null;let{buildId:C,deploymentId:x,params:_,nextConfig:y,parsedUrl:A,isDraftMode:T,prerenderManifest:P,routerServerContext:b,isOnDemandRevalidate:N,revalidateOnlyGenerated:S,resolvedPathname:O,clientReferenceManifest:H,serverActionsManifest:q}=w,I=(0,s.normalizeAppPath)(E),k=!!(P.dynamicRoutes[I]||P.routes[O]),M=async()=>((null==b?void 0:b.render404)?await b.render404(e,t,A,!1):t.end("This page could not be found"),null);if(k&&!T){let e=!!P.routes[O],t=P.dynamicRoutes[I];if(t&&!1===t.fallback&&!e){if(y.adapterPath)return await M();throw new m.NoFallbackError}}let U=null;!k||f.isDev||T||(U="/index"===(U=O)?"/":U);let D=!0===f.isDev||!k,j=k&&!D;q&&H&&(0,o.setManifestsSingleton)({page:E,clientReferenceManifest:H,serverActionsManifest:q});let L=e.method||"GET",F=(0,i.getTracer)(),K=F.getActiveScopeSpan(),G=!!(null==b?void 0:b.isWrappedByNextServer),$=!!(0,n.getRequestMeta)(e,"minimalMode"),B=(0,n.getRequestMeta)(e,"incrementalCache")||await f.getIncrementalCache(e,y,P,$);null==B||B.resetRequestCache(),globalThis.__incrementalCache=B;let V={params:_,previewProps:P.preview,renderOpts:{experimental:{authInterrupts:!!y.experimental.authInterrupts,useCacheTimeout:y.experimental.useCacheTimeout},cacheComponents:!!y.cacheComponents,validationLevel:y.experimental.instantInsights.validationLevel,supportsDynamicResponse:D,incrementalCache:B,hmrRefreshHash:(0,n.getRequestMeta)(e,"hmrRefreshHash"),cacheLifeProfiles:y.cacheLife,staticPageGenerationTimeout:y.staticPageGenerationTimeout,waitUntil:r.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,a,r,n)=>f.onRequestError(e,t,r,n,b)},sharedContext:{buildId:C,deploymentId:x}},X=new l.NodeNextRequest(e),W=new l.NodeNextResponse(t),z=u.NextRequestAdapter.fromNodeNextRequest(X,(0,u.signalFromNodeResponse)(t)),Y=async({previousCacheEntry:a})=>{try{if(!$&&N&&S&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let n=await f.handle(z,V);e.fetchMetrics=V.renderOpts.fetchMetrics;let i=V.renderOpts.pendingWaitUntil;i&&r.waitUntil&&(r.waitUntil(i),i=void 0);let o=V.renderOpts.collectedTags;if(!k)return await (0,p.sendResponse)(X,W,n,i),null;{let e=await n.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(n.headers);o&&(t[v.NEXT_CACHE_TAGS_HEADER]=o),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let a=void 0!==V.renderOpts.collectedRevalidate&&!(V.renderOpts.collectedRevalidate>=v.INFINITE_CACHE)&&V.renderOpts.collectedRevalidate,r=void 0===V.renderOpts.collectedExpire||V.renderOpts.collectedExpire>=v.INFINITE_CACHE?!1!==a&&a>0?y.expireTime:void 0:V.renderOpts.collectedExpire;return{value:{kind:g.CachedRouteKind.APP_ROUTE,status:n.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:a,expire:r}}}}catch(t){throw(null==a?void 0:a.isStale)&&await f.onRequestError(e,t,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:j,isOnDemandRevalidate:N})},!1,b),t}},Z=async(n,o)=>{try{var s,l;let n=await f.handleResponse({req:e,nextConfig:y,cacheKey:U,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:P,isRoutePPREnabled:!1,isOnDemandRevalidate:N,revalidateOnlyGenerated:S,responseGenerator:Y,waitUntil:r.waitUntil,isMinimalMode:$});if(!k)return;if((null==n||null==(s=n.value)?void 0:s.kind)!==g.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==n||null==(l=n.value)?void 0:l.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});$||t.setHeader("x-nextjs-cache",N?"REVALIDATED":n.isMiss?"MISS":n.isStale?"STALE":"HIT"),T&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let i=(0,h.fromNodeOutgoingHttpHeaders)(n.value.headers);$&&k||i.delete(v.NEXT_CACHE_TAGS_HEADER),!n.cacheControl||t.getHeader("Cache-Control")||i.get("Cache-Control")||i.set("Cache-Control",(0,R.getCacheControlHeader)(n.cacheControl)),await (0,p.sendResponse)(X,W,new Response(n.value.body,{headers:i,status:n.value.status||200}));return}catch(t){if(t instanceof m.NoFallbackError||await f.onRequestError(e,t,{routerKind:"App Router",routePath:I,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:j,isOnDemandRevalidate:N})},!1,b),k)throw t;await (0,p.sendResponse)(X,W,new Response(null,{status:500}));return}finally{(()=>{if(!n)return;let e=t.statusCode;n.setAttributes({"http.status_code":e,"next.rsc":!1}),e&&e>=500&&(n.setStatus({code:i.SpanStatusCode.ERROR}),n.setAttribute("error.type",e.toString()));let a=F.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==d.BaseServerSpan.handleRequest)return console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let r=a.get("next.route")||I,s=`${L} ${r}`;n.setAttributes({"next.route":r,"http.route":r,"next.span_name":s}),n.updateName(s),o&&o!==n&&(o.setAttribute("http.route",r),o.updateName(s))})()}};if(G&&K)await Z(K,void 0);else{let t=F.getActiveScopeSpan();await F.withPropagatedContext(e.headers,()=>F.trace(d.BaseServerSpan.handleRequest,{spanName:`${L} ${E}`,kind:i.SpanKind.SERVER,attributes:{"http.method":L,"http.target":e.url}},e=>Z(e,t)),void 0,!G)}}e.s(["handler",0,x,"patchFetch",0,function(){return(0,r.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:w})},"routeModule",0,f,"serverHooks",0,C,"workAsyncStorage",0,E,"workUnitAsyncStorage",0,w])},329280,e=>{e.v(t=>Promise.all(["server/chunks/[externals]_node_readline_1u65a-m._.js","server/chunks/node_modules_consola_dist_chunks_prompt_mjs_02axwqv._.js"].map(t=>e.l(t))).then(()=>t(781937)))}];
2
2
 
3
- //# sourceMappingURL=_0u4aiy2._.js.map
3
+ //# sourceMappingURL=_0lr92vd._.js.map