@mastra/core 1.86.0-alpha.6 → 1.86.0-alpha.8

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 (509) hide show
  1. package/dist/_types/@internal_core@0.1.4/dist/memory/index.d.ts +25 -0
  2. package/dist/agent/agent.d.ts +87 -12
  3. package/dist/agent/agent.types.d.ts +34 -2
  4. package/dist/agent/durable/create-durable-agent.d.ts +1 -1
  5. package/dist/agent/durable/create-evented-agent.d.ts +6 -0
  6. package/dist/agent/durable/durable-agent.d.ts +30 -514
  7. package/dist/agent/durable/durable-stream-until-idle.d.ts +2 -1
  8. package/dist/agent/durable/evented-agent.d.ts +2 -5
  9. package/dist/agent/durable/execution-engine.d.ts +20 -3
  10. package/dist/agent/durable/index.cjs +61 -6351
  11. package/dist/agent/durable/index.d.ts +3 -2
  12. package/dist/agent/durable/index.js +50 -6340
  13. package/dist/agent/durable/stream-adapter.d.ts +5 -5
  14. package/dist/agent/durable/types.d.ts +454 -3
  15. package/dist/agent/durable/workflows/durable-loop-builder.d.ts +7 -9
  16. package/dist/agent/helpers.d.ts +1 -1
  17. package/dist/agent/index.cjs +4 -4
  18. package/dist/agent/index.d.ts +1 -1
  19. package/dist/agent/index.js +4 -4
  20. package/dist/agent/streams/execution-capability.d.ts +3 -2
  21. package/dist/agent/streams/execution-policy.d.ts +1 -1
  22. package/dist/agent/streams/types.d.ts +3 -3
  23. package/dist/agent/types.d.ts +30 -5
  24. package/dist/agent-builder/ee/index.cjs +1 -1
  25. package/dist/agent-builder/ee/index.js +1 -1
  26. package/dist/agent-controller/index.cjs +2 -2
  27. package/dist/agent-controller/index.js +2 -2
  28. package/dist/{agent-controller-c4KbZ8DY.js → agent-controller-B7POPub5.js} +9 -9
  29. package/dist/{agent-controller-6ORqG6hK.cjs → agent-controller-DEPayioq.cjs} +9 -9
  30. package/dist/{agent-skills-resolver-BIeWsb01.cjs → agent-skills-resolver-BMoCDoaK.cjs} +1 -1
  31. package/dist/{agent-skills-resolver-k04IRam7.js → agent-skills-resolver-CUEIMDbx.js} +1 -1
  32. package/dist/background-tasks/index.cjs +1 -1
  33. package/dist/background-tasks/index.js +1 -1
  34. package/dist/{background-tasks-Da0c3R-J.cjs → background-tasks-7iftnRK_.cjs} +1 -1
  35. package/dist/{background-tasks-CEglmAt7.js → background-tasks-Cv1ecD6S.js} +1 -1
  36. package/dist/browser/index.cjs +2 -2
  37. package/dist/browser/index.js +2 -2
  38. package/dist/{builder-DS826dWf.cjs → builder-DuJBbQDH.cjs} +3 -3
  39. package/dist/{builder-0V9N8S15.js → builder-Gg-xnX_E.js} +3 -3
  40. package/dist/capabilities/302ai.json +198 -198
  41. package/dist/capabilities/abliteratedllm.json +38 -38
  42. package/dist/capabilities/abliteration-ai.json +6 -6
  43. package/dist/capabilities/above.json +23 -23
  44. package/dist/capabilities/adaption.json +14 -14
  45. package/dist/capabilities/adzuki.json +22 -22
  46. package/dist/capabilities/agentrouter.json +7 -7
  47. package/dist/capabilities/agnes.json +2 -2
  48. package/dist/capabilities/ai-router.json +5 -5
  49. package/dist/capabilities/aiand.json +23 -23
  50. package/dist/capabilities/aigrow.json +15 -15
  51. package/dist/capabilities/aimlapi.json +143 -143
  52. package/dist/capabilities/aipg.json +2 -2
  53. package/dist/capabilities/aixy.json +16 -16
  54. package/dist/capabilities/aki-io.json +12 -12
  55. package/dist/capabilities/alibaba-cn.json +84 -84
  56. package/dist/capabilities/alibaba-coding-plan-cn.json +5 -5
  57. package/dist/capabilities/alibaba-coding-plan.json +5 -5
  58. package/dist/capabilities/alibaba-token-plan-cn.json +51 -51
  59. package/dist/capabilities/alibaba-token-plan.json +52 -52
  60. package/dist/capabilities/alibaba.json +69 -69
  61. package/dist/capabilities/ambient.json +12 -12
  62. package/dist/capabilities/amd.json +10 -10
  63. package/dist/capabilities/anthropic.json +64 -40
  64. package/dist/capabilities/anyapi.json +12 -12
  65. package/dist/capabilities/apiko.json +5 -5
  66. package/dist/capabilities/arcee.json +7 -7
  67. package/dist/capabilities/augure.json +8 -8
  68. package/dist/capabilities/auriko.json +21 -21
  69. package/dist/capabilities/bailing.json +2 -2
  70. package/dist/capabilities/baseten.json +26 -26
  71. package/dist/capabilities/bee.json +4 -4
  72. package/dist/capabilities/berget.json +4 -4
  73. package/dist/capabilities/bothub.json +17 -17
  74. package/dist/capabilities/boundless.json +41 -41
  75. package/dist/capabilities/bumo.json +43 -43
  76. package/dist/capabilities/byteplus.json +31 -31
  77. package/dist/capabilities/cerebras.json +4 -4
  78. package/dist/capabilities/cheapaimodel.json +6 -6
  79. package/dist/capabilities/cheapest-token.json +32 -32
  80. package/dist/capabilities/chutes.json +10 -10
  81. package/dist/capabilities/cline-pass.json +43 -43
  82. package/dist/capabilities/cloudcode.json +8 -8
  83. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  84. package/dist/capabilities/cloudflare-workers-ai.json +31 -31
  85. package/dist/capabilities/commandcode.json +151 -151
  86. package/dist/capabilities/concentrate.json +287 -263
  87. package/dist/capabilities/cortecs.json +106 -106
  88. package/dist/capabilities/crossmodel.json +189 -189
  89. package/dist/capabilities/crusoe.json +3 -3
  90. package/dist/capabilities/daoxe.json +9 -9
  91. package/dist/capabilities/databricks.json +62 -62
  92. package/dist/capabilities/deepinfra.json +97 -88
  93. package/dist/capabilities/deepseek.json +3 -3
  94. package/dist/capabilities/digitalocean.json +114 -114
  95. package/dist/capabilities/dothoosh.json +36 -36
  96. package/dist/capabilities/doubleword.json +29 -29
  97. package/dist/capabilities/edenai.json +443 -442
  98. package/dist/capabilities/empiriolabs.json +172 -172
  99. package/dist/capabilities/engy.json +20 -20
  100. package/dist/capabilities/entrim.json +8 -8
  101. package/dist/capabilities/evroc.json +15 -15
  102. package/dist/capabilities/ezkielyna.json +7 -7
  103. package/dist/capabilities/fastrouter.json +82 -82
  104. package/dist/capabilities/fireworks-ai.json +50 -50
  105. package/dist/capabilities/freemodel.json +24 -24
  106. package/dist/capabilities/friendli.json +6 -6
  107. package/dist/capabilities/frogbot.json +98 -98
  108. package/dist/capabilities/gisoo.json +20 -20
  109. package/dist/capabilities/gmicloud.json +14 -14
  110. package/dist/capabilities/google.json +60 -60
  111. package/dist/capabilities/graphn.json +12 -12
  112. package/dist/capabilities/greenpt.json +33 -33
  113. package/dist/capabilities/groq.json +9 -9
  114. package/dist/capabilities/helicone.json +81 -81
  115. package/dist/capabilities/hopper.json +2 -2
  116. package/dist/capabilities/hostinger-router.json +12 -12
  117. package/dist/capabilities/hpc-ai.json +10 -10
  118. package/dist/capabilities/huawei-maas.json +15 -15
  119. package/dist/capabilities/hubris.json +27 -27
  120. package/dist/capabilities/huggingface.json +59 -50
  121. package/dist/capabilities/humain.json +2 -2
  122. package/dist/capabilities/hyper.json +25 -25
  123. package/dist/capabilities/impossibl.json +140 -140
  124. package/dist/capabilities/inception.json +2 -2
  125. package/dist/capabilities/inceptron.json +8 -8
  126. package/dist/capabilities/inco.json +4 -4
  127. package/dist/capabilities/infer.json +14 -14
  128. package/dist/capabilities/inferall.json +7 -7
  129. package/dist/capabilities/inference-coop.json +15 -15
  130. package/dist/capabilities/inferenceapis.json +18 -18
  131. package/dist/capabilities/inferris.json +4 -4
  132. package/dist/capabilities/infersia.json +13 -13
  133. package/dist/capabilities/infomaniak.json +2 -2
  134. package/dist/capabilities/io-net.json +5 -5
  135. package/dist/capabilities/isoquant.json +4 -4
  136. package/dist/capabilities/iteracompute.json +54 -54
  137. package/dist/capabilities/jalapeno.json +12 -12
  138. package/dist/capabilities/jiekou.json +63 -63
  139. package/dist/capabilities/joingonka.json +4 -4
  140. package/dist/capabilities/jzstoken.json +56 -56
  141. package/dist/capabilities/keln.json +27 -27
  142. package/dist/capabilities/kenari.json +117 -111
  143. package/dist/capabilities/kilo.json +625 -649
  144. package/dist/capabilities/kimi-code-plan-cn.json +6 -6
  145. package/dist/capabilities/kimi-code-plan-global.json +6 -6
  146. package/dist/capabilities/kitani.json +6 -6
  147. package/dist/capabilities/klavo.json +21 -21
  148. package/dist/capabilities/korouter.json +33 -33
  149. package/dist/capabilities/kunavo.json +9 -9
  150. package/dist/capabilities/liquid.json +8 -8
  151. package/dist/capabilities/lithosai.json +3 -3
  152. package/dist/capabilities/llmgateway-providers.json +932 -905
  153. package/dist/capabilities/llmgateway.json +343 -343
  154. package/dist/capabilities/llmtr.json +25 -25
  155. package/dist/capabilities/longcat.json +2 -2
  156. package/dist/capabilities/lowrouter.json +48 -48
  157. package/dist/capabilities/lyceum.json +13 -13
  158. package/dist/capabilities/melious.json +13 -13
  159. package/dist/capabilities/merge-gateway.json +294 -294
  160. package/dist/capabilities/meta.json +10 -10
  161. package/dist/capabilities/minimax-cn-coding-plan.json +6 -6
  162. package/dist/capabilities/minimax-coding-plan.json +6 -6
  163. package/dist/capabilities/mistral.json +20 -20
  164. package/dist/capabilities/mixlayer.json +3 -3
  165. package/dist/capabilities/modal.json +14 -14
  166. package/dist/capabilities/model-oracle-ai.json +19 -19
  167. package/dist/capabilities/modelis.json +19 -19
  168. package/dist/capabilities/modular.json +5 -5
  169. package/dist/capabilities/moneo.json +17 -17
  170. package/dist/capabilities/moonshotai-cn.json +5 -5
  171. package/dist/capabilities/moonshotai.json +5 -5
  172. package/dist/capabilities/morph.json +14 -14
  173. package/dist/capabilities/munito-eu.json +8 -8
  174. package/dist/capabilities/munito.json +10 -10
  175. package/dist/capabilities/nan.json +28 -28
  176. package/dist/capabilities/nano-gpt.json +597 -567
  177. package/dist/capabilities/nearai.json +89 -89
  178. package/dist/capabilities/nebius.json +40 -31
  179. package/dist/capabilities/neon.json +135 -135
  180. package/dist/capabilities/neuralwatt.json +39 -39
  181. package/dist/capabilities/nokeep.json +2 -2
  182. package/dist/capabilities/novita-ai.json +158 -158
  183. package/dist/capabilities/nvidia.json +35 -35
  184. package/dist/capabilities/oathbreaker.json +2 -2
  185. package/dist/capabilities/obscurify.json +26 -26
  186. package/dist/capabilities/oci.json +6 -6
  187. package/dist/capabilities/ofox.json +352 -352
  188. package/dist/capabilities/ollama-cloud.json +52 -52
  189. package/dist/capabilities/openai.json +49 -56
  190. package/dist/capabilities/opencode-go.json +82 -81
  191. package/dist/capabilities/openreason.json +5 -5
  192. package/dist/capabilities/openrouter.json +557 -567
  193. package/dist/capabilities/opper.json +28 -22
  194. package/dist/capabilities/orcarouter.json +230 -230
  195. package/dist/capabilities/outerlabs.json +33 -33
  196. package/dist/capabilities/ovhcloud.json +6 -6
  197. package/dist/capabilities/pareto.json +6 -6
  198. package/dist/capabilities/perplexity-agent.json +58 -58
  199. package/dist/capabilities/perplexity.json +2 -2
  200. package/dist/capabilities/phala.json +22 -22
  201. package/dist/capabilities/pioneer.json +30 -30
  202. package/dist/capabilities/poe.json +122 -122
  203. package/dist/capabilities/poolside.json +3 -3
  204. package/dist/capabilities/powerspring.json +10 -10
  205. package/dist/capabilities/primalabs.json +8 -8
  206. package/dist/capabilities/prime.json +114 -97
  207. package/dist/capabilities/privatemode-ai.json +11 -11
  208. package/dist/capabilities/proxystacks.json +7 -7
  209. package/dist/capabilities/qiniu-ai.json +13 -13
  210. package/dist/capabilities/refuseless.json +7 -7
  211. package/dist/capabilities/regolo-ai.json +6 -6
  212. package/dist/capabilities/requesty.json +172 -189
  213. package/dist/capabilities/ruapi.json +18 -18
  214. package/dist/capabilities/runcrate.json +17 -17
  215. package/dist/capabilities/runinfra.json +16 -16
  216. package/dist/capabilities/sakana.json +6 -6
  217. package/dist/capabilities/sambanova.json +4 -4
  218. package/dist/capabilities/sandbase.json +24 -24
  219. package/dist/capabilities/sarvam.json +12 -12
  220. package/dist/capabilities/scaleway.json +19 -19
  221. package/dist/capabilities/scnet-token-plan.json +10 -10
  222. package/dist/capabilities/scx-ai.json +23 -23
  223. package/dist/capabilities/sensenova.json +14 -14
  224. package/dist/capabilities/siliconflow-cn.json +64 -64
  225. package/dist/capabilities/siliconflow.json +63 -63
  226. package/dist/capabilities/snowflake-cortex.json +23 -23
  227. package/dist/capabilities/sokkan.json +12 -12
  228. package/dist/capabilities/sparrowcodes.json +23 -23
  229. package/dist/capabilities/standardcompute.json +83 -83
  230. package/dist/capabilities/steadyrouter.json +39 -39
  231. package/dist/capabilities/stepfun-ai-step-plan.json +5 -5
  232. package/dist/capabilities/stepfun-ai.json +5 -5
  233. package/dist/capabilities/stepfun-step-plan.json +5 -5
  234. package/dist/capabilities/stepfun.json +5 -5
  235. package/dist/capabilities/stepping-stone.json +16 -16
  236. package/dist/capabilities/superbot-gg.json +4 -4
  237. package/dist/capabilities/synthetic.json +14 -14
  238. package/dist/capabilities/synthorai.json +29 -29
  239. package/dist/capabilities/teamorouter.json +26 -26
  240. package/dist/capabilities/teapot-router.json +13 -13
  241. package/dist/capabilities/tencent-coding-plan.json +2 -2
  242. package/dist/capabilities/tencent-token-plan.json +30 -30
  243. package/dist/capabilities/tencent-tokenhub.json +8 -8
  244. package/dist/capabilities/tensorx.json +45 -45
  245. package/dist/capabilities/tenstorrent.json +8 -8
  246. package/dist/capabilities/the-grid-ai.json +35 -35
  247. package/dist/capabilities/thinkingmachines.json +59 -59
  248. package/dist/capabilities/tinfoil.json +5 -5
  249. package/dist/capabilities/toapis.json +2 -2
  250. package/dist/capabilities/togetherai.json +59 -59
  251. package/dist/capabilities/tokengo.json +24 -24
  252. package/dist/capabilities/tokenify.json +9 -9
  253. package/dist/capabilities/trustedrouter.json +5 -5
  254. package/dist/capabilities/trustedtokens.json +18 -18
  255. package/dist/capabilities/umans-ai-coding-plan.json +18 -18
  256. package/dist/capabilities/umans-ai.json +15 -15
  257. package/dist/capabilities/uncensuredai.json +4 -4
  258. package/dist/capabilities/unrestricted.json +4 -4
  259. package/dist/capabilities/uplinkswitch.json +21 -21
  260. package/dist/capabilities/upstage.json +7 -7
  261. package/dist/capabilities/vancine.json +20 -20
  262. package/dist/capabilities/vercel.json +568 -576
  263. package/dist/capabilities/vivgrid.json +78 -78
  264. package/dist/capabilities/volcengine-coding-plan.json +30 -30
  265. package/dist/capabilities/volcengine.json +35 -35
  266. package/dist/capabilities/vultr.json +27 -27
  267. package/dist/capabilities/wafer.ai.json +16 -16
  268. package/dist/capabilities/wallaby.json +5 -5
  269. package/dist/capabilities/wally.json +11 -11
  270. package/dist/capabilities/wandb.json +21 -21
  271. package/dist/capabilities/watt.json +26 -26
  272. package/dist/capabilities/xai.json +7 -7
  273. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  274. package/dist/capabilities/xiaomi-token-plan-cn.json +3 -3
  275. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  276. package/dist/capabilities/xiaomi.json +6 -6
  277. package/dist/capabilities/xpersona.json +12 -12
  278. package/dist/capabilities/xxapi.json +31 -31
  279. package/dist/capabilities/zai-coding-plan.json +13 -13
  280. package/dist/capabilities/zai.json +27 -27
  281. package/dist/capabilities/zenifra.json +27 -27
  282. package/dist/capabilities/zenmux.json +195 -195
  283. package/dist/capabilities/zerogpu.json +12 -12
  284. package/dist/capabilities/zhipuai-coding-plan.json +8 -8
  285. package/dist/capabilities/zhipuai.json +27 -27
  286. package/dist/capabilities/zro.json +6 -6
  287. package/dist/channels/agent-channels.d.ts +11 -0
  288. package/dist/channels/chat-tools.d.ts +156 -0
  289. package/dist/channels/index.cjs +7 -2
  290. package/dist/channels/index.d.ts +2 -0
  291. package/dist/channels/index.js +3 -3
  292. package/dist/{channels-C5DxhFRc.js → channels-BRVCOutx.js} +1 -1
  293. package/dist/{channels-B57qQolh.cjs → channels-MjTA9bFp.cjs} +1 -1
  294. package/dist/coding-agent/index.cjs +4 -4
  295. package/dist/coding-agent/index.js +4 -4
  296. package/dist/{constants-DaBkXs5H.cjs → constants-B9ZDvXZ4.cjs} +41 -0
  297. package/dist/{constants-BDHIyN28.js → constants-BmdTvEYN.js} +30 -1
  298. package/dist/datasets/dataset.d.ts +13 -6
  299. package/dist/datasets/experiment/durable.d.ts +16 -0
  300. package/dist/datasets/experiment/index.d.ts +2 -1
  301. package/dist/datasets/experiment/item.d.ts +26 -4
  302. package/dist/datasets/experiment/retries.d.ts +18 -0
  303. package/dist/datasets/experiment/types.d.ts +18 -0
  304. package/dist/datasets/experiment/workflow-id.d.ts +7 -0
  305. package/dist/datasets/experiment/workflow.d.ts +74 -0
  306. package/dist/datasets/index.cjs +3 -2
  307. package/dist/datasets/index.d.ts +2 -1
  308. package/dist/datasets/index.js +3 -3
  309. package/dist/docs/SKILL.md +2 -2
  310. package/dist/docs/assets/SOURCE_MAP.json +1309 -1304
  311. package/dist/docs/references/docs-deployment-workers.md +1 -1
  312. package/dist/docs/references/docs-evals-experiments.md +29 -1
  313. package/dist/docs/references/docs-harness-durable-agents.md +9 -5
  314. package/dist/docs/references/docs-knowledge-agents-and-tools.md +1 -0
  315. package/dist/docs/references/docs-knowledge-load-your-content.md +1 -1
  316. package/dist/docs/references/docs-mastra-platform-observability-overview.md +1 -1
  317. package/dist/docs/references/docs-server-pubsub.md +51 -8
  318. package/dist/docs/references/docs-signals-running-across-processes.md +2 -0
  319. package/dist/docs/references/docs-workflows-overview.md +1 -1
  320. package/dist/docs/references/docs-workflows-scheduled-workflows.md +1 -1
  321. package/dist/docs/references/integrations-channels-slack.md +4 -2
  322. package/dist/docs/references/integrations.md +6 -0
  323. package/dist/docs/references/reference-agents-agent.md +3 -1
  324. package/dist/docs/references/reference-agents-channels.md +146 -24
  325. package/dist/docs/references/reference-agents-durable-agent.md +28 -2
  326. package/dist/docs/references/reference-datasets-runExperimentItem.md +13 -1
  327. package/dist/docs/references/reference-datasets-startExperimentAsync.md +3 -1
  328. package/dist/docs/references/reference-editor-mastra-editor.md +3 -1
  329. package/dist/docs/references/reference-knowledge-knowledge-class.md +2 -2
  330. package/dist/docs/references/reference-knowledge-knowledge-tools.md +43 -20
  331. package/dist/docs/references/reference-processors-moderation-processor.md +2 -2
  332. package/dist/docs/references/reference-pubsub-base.md +5 -1
  333. package/dist/docs/references/reference-pubsub-event-emitter.md +2 -0
  334. package/dist/docs/references/reference-pubsub-redis-streams.md +1 -1
  335. package/dist/docs/references/reference-pubsub-unix-socket-pubsub.md +2 -0
  336. package/dist/docs/references/reference-streaming-ChunkType.md +1 -1
  337. package/dist/docs/references/reference-workers-overview.md +1 -1
  338. package/dist/docs/references/reference-workflows-run-methods-start.md +23 -0
  339. package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +4 -0
  340. package/dist/docs/references/reference-workflows-run.md +1 -1
  341. package/dist/evals/index.cjs +2 -2
  342. package/dist/evals/index.js +2 -2
  343. package/dist/evals/scoreTraces/index.cjs +2 -2
  344. package/dist/evals/scoreTraces/index.js +2 -2
  345. package/dist/events/caching-pubsub.d.ts +1 -0
  346. package/dist/events/event-emitter/index.d.ts +12 -5
  347. package/dist/events/index.cjs +15 -1
  348. package/dist/events/index.js +15 -1
  349. package/dist/events/pubsub.d.ts +29 -0
  350. package/dist/events/reach.d.ts +11 -0
  351. package/dist/events/unix-socket-pubsub.d.ts +14 -0
  352. package/dist/{filesystem-CUj0vclS.cjs → filesystem-B0AZrbj8.cjs} +1 -1
  353. package/dist/{filesystem-BBqrAmKK.js → filesystem-B3s0WRud.js} +1 -1
  354. package/dist/{filesystem-B_HACoLS.js → filesystem-B5X-5G0x.js} +1 -1
  355. package/dist/{filesystem-pZNvxjuW.cjs → filesystem-BDSpwBke.cjs} +1 -1
  356. package/dist/{filesystem-5Z777gYZ.js → filesystem-BsdkC311.js} +1 -1
  357. package/dist/{filesystem-BNHPgtjJ.cjs → filesystem-C-cyJfi1.cjs} +1 -1
  358. package/dist/{filesystem-U5o28b5w.cjs → filesystem-CEbD_77-.cjs} +1 -1
  359. package/dist/{filesystem-yHKEz2Pr.cjs → filesystem-CUAgLugE.cjs} +1 -1
  360. package/dist/{filesystem-Cb8iTPM-.js → filesystem-Cv79mHRk.js} +1 -1
  361. package/dist/{filesystem-DhiaddZe.cjs → filesystem-DsCQiBl2.cjs} +1 -1
  362. package/dist/{filesystem-DSYDB3ek.js → filesystem-DzM9pcQ8.js} +1 -1
  363. package/dist/{filesystem-gpIfFMed.js → filesystem-DzfqVTO_.js} +1 -1
  364. package/dist/{filesystem-versioned-CxbiSJF-.js → filesystem-versioned-Bijb_p9l.js} +44 -44
  365. package/dist/harness/index.cjs +2 -2
  366. package/dist/harness/index.js +2 -2
  367. package/dist/index.cjs +1 -1
  368. package/dist/index.js +1 -1
  369. package/dist/knowledge/index.cjs +1 -1
  370. package/dist/knowledge/index.js +1 -1
  371. package/dist/llm/index.cjs +3 -3
  372. package/dist/llm/index.js +3 -3
  373. package/dist/llm/model/provider-types.generated.d.ts +7720 -7720
  374. package/dist/llm/model/shared.types.d.ts +31 -0
  375. package/dist/{llm-B0VtQDgT.js → llm-Djd8Qzi0.js} +2 -2
  376. package/dist/{llm-ByskI6z3.cjs → llm-DmUucguC.cjs} +2 -2
  377. package/dist/loop/base-loop-builder.d.ts +60 -0
  378. package/dist/loop/index.cjs +2 -2
  379. package/dist/loop/index.js +2 -2
  380. package/dist/loop/loop-builder.d.ts +10 -32
  381. package/dist/loop/workflows/agentic-execution/index.d.ts +1 -1
  382. package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +2 -2
  383. package/dist/loop/workflows/agentic-loop/index.d.ts +1 -1
  384. package/dist/{manager-C2RGNH68.js → manager-CO_Xz2zR.js} +461 -95
  385. package/dist/{manager-BJKx4lQf.cjs → manager-D27PkIPo.cjs} +477 -93
  386. package/dist/mastra/index.cjs +1 -1
  387. package/dist/mastra/index.d.ts +13 -0
  388. package/dist/mastra/index.js +1 -1
  389. package/dist/{mastra-zUTq9ilk.js → mastra-Ch00nEAJ.js} +66 -25
  390. package/dist/{mastra-FXCeC5rF.cjs → mastra-qsVWpOTi.cjs} +66 -25
  391. package/dist/memory/index.cjs +2 -2
  392. package/dist/memory/index.js +2 -2
  393. package/dist/{model-BTNRPDgQ.js → model-CW-mfGYA.js} +1 -1
  394. package/dist/{model-BmTFNo62.cjs → model-Do6DTJoj.cjs} +1 -1
  395. package/dist/{netlify-B_XdjYPY.cjs → netlify-DU32SDT6.cjs} +1 -1
  396. package/dist/{netlify-BCSVhO5q.js → netlify-DZSAbdve.js} +1 -1
  397. package/dist/notifications/index.cjs +1 -1
  398. package/dist/notifications/index.js +1 -1
  399. package/dist/{output-helpers-CncZ3y-g.cjs → output-helpers-1Zu4Vt9C.cjs} +112 -69
  400. package/dist/{output-helpers-RlvE2WPA.js → output-helpers-CedRCE17.js} +113 -70
  401. package/dist/processor-provider/index.cjs +1 -1
  402. package/dist/processor-provider/index.js +1 -1
  403. package/dist/processors/index.cjs +2 -2
  404. package/dist/processors/index.js +2 -2
  405. package/dist/processors/processors/pii-detector.d.ts +1 -0
  406. package/dist/{provider-registry-Ble43Wb4.js → provider-registry-deA0x-Gd.js} +21349 -21338
  407. package/dist/{provider-registry-D8O1G18A.cjs → provider-registry-zGezZVsL.cjs} +21349 -21338
  408. package/dist/provider-registry.json +21695 -21680
  409. package/dist/{registry-generator-BQ1noftK.cjs → registry-generator-BkQ1AxZn.cjs} +1 -1
  410. package/dist/{registry-generator-D1Zslex6.js → registry-generator-VvBfOKAD.js} +1 -1
  411. package/dist/{rehydrate-CgxEur9m.js → rehydrate-BjLV643n.js} +2 -2
  412. package/dist/{rehydrate-BiA_HUJH.cjs → rehydrate-DDYFpQsV.cjs} +2 -2
  413. package/dist/relevance/index.cjs +2 -2
  414. package/dist/relevance/index.js +2 -2
  415. package/dist/{run-registry-aomba2_Z.cjs → run-registry-5Suldxz3.cjs} +83965 -77543
  416. package/dist/{run-registry-BUFmc_78.js → run-registry-CGRPldLH.js} +84057 -77017
  417. package/dist/{scheduler-BuivoTeD.js → scheduler-B-VZUvv_.js} +1 -1
  418. package/dist/{scheduler-COSuIH7R.cjs → scheduler-D00X03jQ.cjs} +1 -1
  419. package/dist/schedules/index.cjs +1 -1
  420. package/dist/schedules/index.js +1 -1
  421. package/dist/{schedules-Dmu9qOgc.js → schedules-DZfSx-7P.js} +94 -94
  422. package/dist/{signal-provider-CicwpNwY.cjs → signal-provider-BFAvh_AJ.cjs} +1 -1
  423. package/dist/{signal-provider-BOtSN-_0.js → signal-provider-BslnAjWG.js} +1 -1
  424. package/dist/signals/index.cjs +3 -3
  425. package/dist/signals/index.js +3 -3
  426. package/dist/{signals-6EBDPHQX.cjs → signals-B1JSj-Ew.cjs} +2 -2
  427. package/dist/{signals-BH__LS8Y.js → signals-De9VnwL2.js} +2 -2
  428. package/dist/skills/index.cjs +2 -2
  429. package/dist/skills/index.js +2 -2
  430. package/dist/{source-8qxr6KJv.cjs → source-DDwx-87N.cjs} +1 -1
  431. package/dist/{source-DRqDgbCv.js → source-Did_2XQc.js} +1 -1
  432. package/dist/{state-processor-BRk8t1OR.js → state-processor-B9kxpM53.js} +140 -140
  433. package/dist/{state-processor-Bfs9LkY8.cjs → state-processor-kRNZ38Nf.cjs} +139 -139
  434. package/dist/storage/constants.cjs +1 -1
  435. package/dist/storage/constants.js +1 -1
  436. package/dist/storage/domains/agents/index.cjs +1 -1
  437. package/dist/storage/domains/agents/index.js +1 -1
  438. package/dist/storage/domains/knowledge/base.d.ts +5 -0
  439. package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
  440. package/dist/storage/domains/knowledge/pages.d.ts +24 -7
  441. package/dist/storage/domains/mcp-clients/index.cjs +1 -1
  442. package/dist/storage/domains/mcp-clients/index.js +1 -1
  443. package/dist/storage/domains/mcp-servers/index.cjs +1 -1
  444. package/dist/storage/domains/mcp-servers/index.js +1 -1
  445. package/dist/storage/domains/memory/base.d.ts +3 -1
  446. package/dist/storage/domains/memory/observational-memory-lifecycle.d.ts +1 -1
  447. package/dist/storage/domains/prompt-blocks/index.cjs +1 -1
  448. package/dist/storage/domains/prompt-blocks/index.js +1 -1
  449. package/dist/storage/domains/scorer-definitions/index.cjs +1 -1
  450. package/dist/storage/domains/scorer-definitions/index.js +1 -1
  451. package/dist/storage/domains/skills/index.cjs +1 -1
  452. package/dist/storage/domains/skills/index.js +1 -1
  453. package/dist/storage/domains/workspaces/index.cjs +1 -1
  454. package/dist/storage/domains/workspaces/index.js +1 -1
  455. package/dist/storage/index.cjs +12 -11
  456. package/dist/storage/index.js +12 -12
  457. package/dist/storage/types.d.ts +13 -0
  458. package/dist/stream/base/output.d.ts +42 -15
  459. package/dist/stream/index.cjs +2 -2
  460. package/dist/stream/index.js +2 -2
  461. package/dist/stream/types.d.ts +19 -0
  462. package/dist/{stream-S_NC5v9e.js → stream-Dpwx0whf.js} +1 -1
  463. package/dist/{stream-DUrp3Fcy.cjs → stream-Dvy_0o14.cjs} +1 -1
  464. package/dist/test-utils/llm-mock.cjs +1 -1
  465. package/dist/test-utils/llm-mock.js +1 -1
  466. package/dist/tool-loop-agent/index.cjs +1 -1
  467. package/dist/tool-loop-agent/index.js +1 -1
  468. package/dist/{tool-loop-agent-BhCzpGfr.js → tool-loop-agent-PbWrEj1k.js} +3 -3
  469. package/dist/{tool-loop-agent-DU0BiemT.cjs → tool-loop-agent-UxOv3FoK.cjs} +3 -3
  470. package/dist/tools/index.cjs +1 -1
  471. package/dist/tools/index.js +1 -1
  472. package/dist/tools/types.d.ts +27 -1
  473. package/dist/{utils-CeEt4K7t.cjs → utils-BbMTlyBO.cjs} +1 -1
  474. package/dist/{utils-DYIai19q.js → utils-BnNi1BYM.js} +1 -1
  475. package/dist/utils.cjs +1 -1
  476. package/dist/utils.js +1 -1
  477. package/dist/{validate-BRikrNhF.js → validate-HSBcm96b.js} +1 -1
  478. package/dist/{validate-BckgxuJ0.cjs → validate-Skps-cM3.cjs} +1 -1
  479. package/dist/vector/index.cjs +1 -1
  480. package/dist/vector/index.js +1 -1
  481. package/dist/worker/index.cjs +1 -1
  482. package/dist/worker/index.js +1 -1
  483. package/dist/{worker-BfhUD77l.cjs → worker-BE-0DyKL.cjs} +3 -3
  484. package/dist/{worker-DcBfwJqD.js → worker-BKrKHZzU.js} +3 -3
  485. package/dist/{worker-D9WwmcJa.cjs → worker-BNS5A3qP.cjs} +3 -3
  486. package/dist/{worker-Du5ybt5o.js → worker-DehaD4qD.js} +3 -3
  487. package/dist/{workflow-BWV5m9Mx.cjs → workflow-BjUTwaK9.cjs} +4 -4
  488. package/dist/{workflow-jNWVBYDJ.js → workflow-Bvw6yDjc.js} +4 -4
  489. package/dist/workflows/builder/index.cjs +1 -1
  490. package/dist/workflows/builder/index.js +1 -1
  491. package/dist/workflows/evented/index.cjs +1 -1
  492. package/dist/workflows/evented/index.js +1 -1
  493. package/dist/workflows/evented/setup-warning.d.ts +18 -0
  494. package/dist/workflows/evented/workflow-event-processor/run-status.d.ts +37 -0
  495. package/dist/workflows/evented/workflow.d.ts +11 -1
  496. package/dist/workflows/index.cjs +6 -6
  497. package/dist/workflows/index.js +6 -6
  498. package/dist/workflows/workflow.d.ts +6 -1
  499. package/dist/workspace/index.cjs +2 -2
  500. package/dist/workspace/index.js +2 -2
  501. package/dist/{workspace-D7JRhn1Z.js → workspace-C05xDH60.js} +564 -411
  502. package/dist/{workspace-BQ2wZj5D.cjs → workspace-D1OzzlLw.cjs} +564 -411
  503. package/dist/{workspace-skills-CGiXfKzA.js → workspace-skills-38OY32_b.js} +531 -531
  504. package/package.json +6 -6
  505. package/src/llm/model/provider-types.generated.d.ts +7720 -7720
  506. package/dist/agent/durable/evented-execution-engine.d.ts +0 -20
  507. package/dist/{filesystem-versioned-D-OCaYSl.cjs → filesystem-versioned-DZGyPbNC.cjs} +43 -43
  508. package/dist/{schedules-qIHUKsj4.cjs → schedules-BZS8McF7.cjs} +93 -93
  509. package/dist/{workspace-skills-CUSjYHdi.cjs → workspace-skills-BcquhPDn.cjs} +530 -530
@@ -1,7 +1,7 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-BrhgMLW6.cjs");
2
2
  const require_request_context = require("./request-context-D9RXYCy8.cjs");
3
3
  const require_errors = require("./errors-D5kMB1FQ.cjs");
4
- const require_workspace_skills = require("./workspace-skills-CUSjYHdi.cjs");
4
+ const require_workspace_skills = require("./workspace-skills-BcquhPDn.cjs");
5
5
  const require_base = require("./base-BIzR1D3_.cjs");
6
6
  const require_logger = require("./logger-CvzZYuJd.cjs");
7
7
  const require_tool = require("./tool-CYlT2UA-.cjs");
@@ -15,12 +15,12 @@ let os = require("os");
15
15
  os = require_rolldown_runtime.__toESM(os, 1);
16
16
  let path = require("path");
17
17
  path = require_rolldown_runtime.__toESM(path, 1);
18
- let path_posix = require("path/posix");
19
- path_posix = require_rolldown_runtime.__toESM(path_posix, 1);
20
18
  let fs_promises = require("fs/promises");
21
19
  fs_promises = require_rolldown_runtime.__toESM(fs_promises, 1);
22
- let child_process = require("child_process");
23
20
  let url = require("url");
21
+ let child_process = require("child_process");
22
+ let path_posix = require("path/posix");
23
+ path_posix = require_rolldown_runtime.__toESM(path_posix, 1);
24
24
  let ignore = require("ignore");
25
25
  ignore = require_rolldown_runtime.__toESM(ignore, 1);
26
26
  let _mastra_schema_compat_schema = require("@mastra/schema-compat/schema");
@@ -117,6 +117,307 @@ function reassembleShellCommand(parts, operators) {
117
117
  for (let i = 0; i < operators.length; i++) result += ` ${operators[i]} ${parts[i + 1] ?? ""}`;
118
118
  return result.trim();
119
119
  }
120
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
121
+ const PATTERNS = {
122
+ whitespace: /^\s+$/,
123
+ structuredWhitespace: /\n\s/,
124
+ cjk: /[\u4E00-\u9FFF\u3400-\u4DBF\u3000-\u30FF\uFF00-\uFFEF\u2E80-\u2EFF\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uD7B0-\uD7FF]/,
125
+ numeric: /^\d+$/,
126
+ punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_"-]/
127
+ };
128
+ const TOKEN_SPLIT_PATTERN = new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
129
+ const DEFAULT_CHARS_PER_TOKEN = 6;
130
+ const SHORT_TOKEN_THRESHOLD = 3;
131
+ const KANA_CHARS_PER_TOKEN = 1.35;
132
+ const DEFAULT_LANGUAGE_CONFIGS = [
133
+ {
134
+ pattern: /[\u00E4\u00F6\u00FC\u00DF\u1E9E]/i,
135
+ averageCharsPerToken: 2.6
136
+ },
137
+ {
138
+ pattern: /[\u00E9\u00E8\u00EA\u00EB\u00E0\u00E2\u00EE\u00EF\u00F4\u00FB\u00F9\u00FC\u00FF\u00E7\u0153\u00E6\u00E1\u00ED\u00F3\u00FA\u00F1]/i,
139
+ averageCharsPerToken: 3
140
+ },
141
+ {
142
+ pattern: /[\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u011B\u0161\u010D\u0159\u017E\u00FD\u016F\u00FA\u010F\u0165\u0148]/i,
143
+ averageCharsPerToken: 2.5
144
+ },
145
+ {
146
+ pattern: /[\u0430-\u044F\u0451]/i,
147
+ averageCharsPerToken: 4
148
+ },
149
+ {
150
+ pattern: /[\u03AC-\u03CE]/i,
151
+ averageCharsPerToken: 2.75
152
+ },
153
+ {
154
+ pattern: /^\p{Extended_Pictographic}[\p{Extended_Pictographic}\p{Emoji_Component}]*$/u,
155
+ averageCharsPerToken: .75
156
+ }
157
+ ];
158
+ /**
159
+ * Walks a text as (segment, estimated token count) pairs. The segments
160
+ * concatenate back to the original text; whitespace segments count zero
161
+ * tokens unless they carry structure (indentation or blank lines).
162
+ */
163
+ function* walkSegments(text, options = {}) {
164
+ if (!text) return;
165
+ const resolvedOptions = resolveOptions(options);
166
+ for (const segment of text.split(TOKEN_SPLIT_PATTERN)) if (segment) yield {
167
+ segment,
168
+ tokenCount: estimateSegmentTokens(segment, resolvedOptions)
169
+ };
170
+ }
171
+ function resolveOptions(options) {
172
+ return {
173
+ defaultCharsPerToken: options.defaultCharsPerToken ?? DEFAULT_CHARS_PER_TOKEN,
174
+ languageConfigs: options.languageConfigs ?? DEFAULT_LANGUAGE_CONFIGS
175
+ };
176
+ }
177
+ function estimateSegmentTokens(segment, { languageConfigs, defaultCharsPerToken }) {
178
+ if (PATTERNS.whitespace.test(segment)) return PATTERNS.structuredWhitespace.test(segment) ? 1 : 0;
179
+ const languageCharsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs);
180
+ if (languageCharsPerToken !== void 0) return Math.ceil(getCharacterCount(segment) / languageCharsPerToken);
181
+ if (PATTERNS.cjk.test(segment)) return estimateCjkTokens(segment);
182
+ if (PATTERNS.numeric.test(segment)) return Math.ceil(segment.length / 3);
183
+ if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
184
+ if (PATTERNS.punctuation.test(segment)) return Math.ceil(segment.length / 2);
185
+ return Math.ceil(segment.length / defaultCharsPerToken);
186
+ }
187
+ function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
188
+ for (const config of languageConfigs) if (segment.search(config.pattern) !== -1) return config.averageCharsPerToken;
189
+ }
190
+ function getCharacterCount(text) {
191
+ return Array.from(text).length;
192
+ }
193
+ function estimateCjkTokens(segment) {
194
+ let kanaCount = 0;
195
+ let otherCount = 0;
196
+ for (const character of segment) {
197
+ const codePoint = character.codePointAt(0);
198
+ if (codePoint >= 12352 && codePoint <= 12543) kanaCount++;
199
+ else otherCount++;
200
+ }
201
+ return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
202
+ }
203
+ /**
204
+ * Estimates the number of tokens in a text string using heuristic rules
205
+ */
206
+ function estimateTokenCount(text, options = {}) {
207
+ if (!text) return 0;
208
+ let tokenCount = 0;
209
+ for (const segmentEstimate of walkSegments(text, options)) tokenCount += segmentEstimate.tokenCount;
210
+ return tokenCount;
211
+ }
212
+ /**
213
+ * Extracts a portion of text based on token positions, similar to Array.prototype.slice()
214
+ */
215
+ function sliceByTokens(text, start = 0, end, options = {}) {
216
+ if (!text) return "";
217
+ let segmentEstimates = walkSegments(text, options);
218
+ let totalTokens = 0;
219
+ if (start < 0 || end !== void 0 && end < 0) {
220
+ const bufferedEstimates = Array.from(segmentEstimates);
221
+ for (const { tokenCount } of bufferedEstimates) totalTokens += tokenCount;
222
+ segmentEstimates = bufferedEstimates;
223
+ }
224
+ const normalizedStart = start < 0 ? Math.max(0, totalTokens + start) : Math.max(0, start);
225
+ const normalizedEnd = end === void 0 ? Infinity : end < 0 ? Math.max(0, totalTokens + end) : end;
226
+ if (normalizedStart >= normalizedEnd) return "";
227
+ const parts = [];
228
+ let currentTokenPos = 0;
229
+ for (const { segment, tokenCount } of segmentEstimates) {
230
+ if (currentTokenPos >= normalizedEnd) break;
231
+ const extracted = extractSegmentPart(segment, currentTokenPos, tokenCount, normalizedStart, normalizedEnd);
232
+ if (extracted) parts.push(extracted);
233
+ currentTokenPos += tokenCount;
234
+ }
235
+ return parts.join("");
236
+ }
237
+ function extractSegmentPart(segment, segmentTokenStart, segmentTokenCount, targetStart, targetEnd) {
238
+ if (segmentTokenCount === 0) return segmentTokenStart >= targetStart && segmentTokenStart < targetEnd ? segment : "";
239
+ const segmentTokenEnd = segmentTokenStart + segmentTokenCount;
240
+ if (segmentTokenStart >= targetEnd || segmentTokenEnd <= targetStart) return "";
241
+ const overlapStart = Math.max(0, targetStart - segmentTokenStart);
242
+ const overlapEnd = Math.min(segmentTokenCount, targetEnd - segmentTokenStart);
243
+ if (overlapStart === 0 && overlapEnd === segmentTokenCount) return segment;
244
+ const charStart = Math.floor(overlapStart / segmentTokenCount * segment.length);
245
+ const charEnd = Math.ceil(overlapEnd / segmentTokenCount * segment.length);
246
+ return segment.slice(charStart, charEnd);
247
+ }
248
+ // src/utils/slice-by-tokens.ts
249
+ const UNPAIRED_SURROGATE_RE = /[\uD800-\uDFFF]/gu;
250
+ /**
251
+ * `sliceByTokens` from tokenx cuts on UTF-16 code-unit boundaries, so a cut can
252
+ * land inside a surrogate pair (emoji, CJK ext B+, math alphanumerics) and leave
253
+ * an unpaired surrogate. That is invalid UTF-16: it degrades to U+FFFD on a UTF-8
254
+ * round-trip and strict JSON parsers reject it. Always slice through this helper
255
+ * so every truncation site gets the same repair.
256
+ */
257
+ function sliceByTokensSafe(text, start, end) {
258
+ return sliceByTokens(text, start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
259
+ }
260
+ /** `text.slice(start, end)` by UTF-16 index, with the same repair for a cut inside a surrogate pair. */
261
+ function sliceSafe(text, start, end) {
262
+ return text.slice(start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
263
+ }
264
+ // src/workspace/line-utils.ts
265
+ /**
266
+ * Extract lines from content by line range.
267
+ *
268
+ * @param content - The document content
269
+ * @param startLine - Starting line number (1-indexed)
270
+ * @param endLine - Ending line number (1-indexed, inclusive)
271
+ * @returns Object with extracted content and metadata
272
+ */
273
+ function extractLines(content, startLine, endLine) {
274
+ const allLines = content.split("\n");
275
+ const totalLines = allLines.length;
276
+ const start = Math.max(1, startLine ?? 1);
277
+ const end = Math.min(totalLines, endLine ?? totalLines);
278
+ if (start > end) return {
279
+ content: "",
280
+ lines: {
281
+ start: 0,
282
+ end: 0
283
+ },
284
+ totalLines
285
+ };
286
+ return {
287
+ content: allLines.slice(start - 1, end).join("\n"),
288
+ lines: {
289
+ start,
290
+ end
291
+ },
292
+ totalLines
293
+ };
294
+ }
295
+ /**
296
+ * Extract lines using offset/limit style parameters (like Claude Code).
297
+ *
298
+ * @param content - The document content
299
+ * @param offset - Line number to start from (1-indexed, default: 1)
300
+ * @param limit - Maximum number of lines to read (default: all remaining)
301
+ * @returns Object with extracted content and metadata
302
+ */
303
+ function extractLinesWithLimit(content, offset, limit) {
304
+ const startLine = offset ?? 1;
305
+ return extractLines(content, startLine, limit ? startLine + limit - 1 : void 0);
306
+ }
307
+ /**
308
+ * Format content with line number prefixes.
309
+ * Output format matches Claude Code: " 1→content here"
310
+ *
311
+ * @param content - The content to format
312
+ * @param startLineNumber - The line number of the first line (1-indexed)
313
+ * @returns Formatted content with line numbers
314
+ */
315
+ function formatWithLineNumbers(content, startLineNumber = 1) {
316
+ const lines = content.split("\n");
317
+ const maxLineNum = startLineNumber + lines.length - 1;
318
+ const padWidth = Math.max(6, String(maxLineNum).length + 1);
319
+ return lines.map((line, i) => {
320
+ const lineNum = startLineNumber + i;
321
+ return `${String(lineNum).padStart(padWidth)}\u2192${line}`;
322
+ }).join("\n");
323
+ }
324
+ /**
325
+ * Convert a character index to a line number.
326
+ * Useful for converting RAG chunk character offsets to line numbers.
327
+ *
328
+ * @param content - The full document content
329
+ * @param charIndex - The character index (0-indexed)
330
+ * @returns The line number (1-indexed), or undefined if charIndex is out of bounds
331
+ */
332
+ function charIndexToLineNumber(content, charIndex) {
333
+ if (charIndex < 0 || charIndex > content.length) return;
334
+ let lineNumber = 1;
335
+ for (let i = 0; i < charIndex && i < content.length; i++) if (content[i] === "\n") lineNumber++;
336
+ return lineNumber;
337
+ }
338
+ /**
339
+ * Convert character range to line range.
340
+ * Useful for converting RAG chunk character offsets to line ranges.
341
+ *
342
+ * @param content - The full document content
343
+ * @param startCharIdx - Start character index (0-indexed)
344
+ * @param endCharIdx - End character index (0-indexed, exclusive)
345
+ * @returns LineRange (1-indexed) or undefined if indices are out of bounds
346
+ */
347
+ function charRangeToLineRange(content, startCharIdx, endCharIdx) {
348
+ const startLine = charIndexToLineNumber(content, startCharIdx);
349
+ const endLine = charIndexToLineNumber(content, Math.max(0, endCharIdx - 1));
350
+ if (startLine === void 0 || endLine === void 0) return;
351
+ return {
352
+ start: startLine,
353
+ end: endLine
354
+ };
355
+ }
356
+ /**
357
+ * Count occurrences of a string in content.
358
+ *
359
+ * @param content - The content to search
360
+ * @param searchString - The string to find
361
+ * @returns Number of occurrences
362
+ */
363
+ function countOccurrences(content, searchString) {
364
+ if (!searchString) return 0;
365
+ let count = 0;
366
+ let position = 0;
367
+ while ((position = content.indexOf(searchString, position)) !== -1) {
368
+ count++;
369
+ position += searchString.length;
370
+ }
371
+ return count;
372
+ }
373
+ /**
374
+ * Replace a string in content, with validation for uniqueness.
375
+ *
376
+ * @param content - The content to modify
377
+ * @param oldString - The string to find and replace
378
+ * @param newString - The replacement string
379
+ * @param replaceAll - If true, replace all occurrences; if false, require unique match
380
+ * @returns Object with result content and metadata
381
+ * @throws Error if oldString is not found or not unique (when replaceAll is false)
382
+ */
383
+ function replaceString(content, oldString, newString, replaceAll = false) {
384
+ const count = countOccurrences(content, oldString);
385
+ if (count === 0) throw new StringNotFoundError(oldString);
386
+ if (!replaceAll && count > 1) throw new StringNotUniqueError(oldString, count);
387
+ const escapedNewString = newString.replace(/\$/g, "$$$$");
388
+ if (replaceAll) return {
389
+ content: content.split(oldString).join(newString),
390
+ replacements: count
391
+ };
392
+ return {
393
+ content: content.replace(oldString, escapedNewString),
394
+ replacements: 1
395
+ };
396
+ }
397
+ /**
398
+ * Error thrown when string is not found during replacement.
399
+ */
400
+ var StringNotFoundError = class extends Error {
401
+ searchString;
402
+ constructor(searchString) {
403
+ super(`The specified text was not found. Make sure you use the exact text from the file.`);
404
+ this.searchString = searchString;
405
+ this.name = "StringNotFoundError";
406
+ }
407
+ };
408
+ /**
409
+ * Error thrown when string appears multiple times but unique match required.
410
+ */
411
+ var StringNotUniqueError = class extends Error {
412
+ searchString;
413
+ occurrences;
414
+ constructor(searchString, occurrences) {
415
+ super(`The specified text appears ${occurrences} times. Provide more surrounding context to make the match unique, or use replace_all to replace all occurrences.`);
416
+ this.searchString = searchString;
417
+ this.occurrences = occurrences;
418
+ this.name = "StringNotUniqueError";
419
+ }
420
+ };
120
421
  // src/workspace/constants/index.ts
121
422
  const WORKSPACE_TOOLS_PREFIX = "mastra_workspace";
122
423
  /**
@@ -5881,263 +6182,106 @@ const computerScrollTool = require_tool.createTool({
5881
6182
  },
5882
6183
  attributes: { sandboxProvider: sandbox.provider }
5883
6184
  });
5884
- try {
5885
- await computer.scroll(direction, effectiveAmount);
5886
- const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.SCROLL, `Scrolled ${direction} by ${effectiveAmount}`);
5887
- span.end({ success: true });
5888
- return result;
5889
- } catch (err) {
5890
- span.error(err);
5891
- throw err;
5892
- }
5893
- },
5894
- toModelOutput: mediaToModelOutput
5895
- });
5896
- // src/workspace/tools/computer-type.ts
5897
- const computerTypeTool = require_tool.createTool({
5898
- id: WORKSPACE_TOOLS.COMPUTER.TYPE,
5899
- description: "Type text into the focused element on the sandbox desktop using the keyboard. Click an input field first to focus it. Use the press-key tool for special keys (Enter, Tab, shortcuts).",
5900
- inputSchema: zod_v4.z.object({ text: zod_v4.z.string().describe("The text to type") }),
5901
- execute: async ({ text }, context) => {
5902
- const { workspace, sandbox, computer } = requireComputer(context);
5903
- await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.TYPE);
5904
- const span = startWorkspaceSpan(context, workspace, {
5905
- category: "computer",
5906
- operation: "type",
5907
- input: { length: text.length },
5908
- attributes: { sandboxProvider: sandbox.provider }
5909
- });
5910
- try {
5911
- await computer.type(text);
5912
- const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.TYPE, `Typed ${text.length} characters`);
5913
- span.end({ success: true });
5914
- return result;
5915
- } catch (err) {
5916
- span.error(err);
5917
- throw err;
5918
- }
5919
- },
5920
- toModelOutput: mediaToModelOutput
5921
- });
5922
- // src/workspace/tools/computer-wait.ts
5923
- const computerWaitTool = require_tool.createTool({
5924
- id: WORKSPACE_TOOLS.COMPUTER.WAIT,
5925
- description: "Wait for the sandbox desktop UI to settle (e.g. an application launching or a page loading) before the next action.",
5926
- inputSchema: zod_v4.z.object({ seconds: zod_v4.z.number().min(.1).max(30).describe("How long to wait, in seconds (max 30)") }),
5927
- execute: async ({ seconds }, context) => {
5928
- const { workspace, sandbox, computer } = requireComputer(context);
5929
- await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.WAIT);
5930
- const span = startWorkspaceSpan(context, workspace, {
5931
- category: "computer",
5932
- operation: "wait",
5933
- input: { seconds },
5934
- attributes: { sandboxProvider: sandbox.provider }
5935
- });
5936
- try {
5937
- await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
5938
- const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.WAIT, `Waited ${seconds}s`);
5939
- span.end({ success: true });
5940
- return result;
5941
- } catch (err) {
5942
- span.error(err);
5943
- throw err;
5944
- }
5945
- },
5946
- toModelOutput: mediaToModelOutput
5947
- });
5948
- // src/workspace/tools/delete-file.ts
5949
- const deleteFileTool = require_tool.createTool({
5950
- id: WORKSPACE_TOOLS.FILESYSTEM.DELETE,
5951
- description: "Delete a file or directory from the workspace filesystem",
5952
- outputSchema: zod_v4.z.string(),
5953
- inputSchema: zod_v4.z.object({
5954
- path: zod_v4.z.string().describe("The path to the file or directory to delete"),
5955
- recursive: zod_v4.z.boolean().optional().default(false).describe("If true, delete directories and their contents recursively. Required for non-empty directories.")
5956
- }),
5957
- execute: async ({ path, recursive }, context) => {
5958
- const { workspace, filesystem } = requireFilesystem(context);
5959
- await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.FILESYSTEM.DELETE);
5960
- const span = startWorkspaceSpan(context, workspace, {
5961
- category: "filesystem",
5962
- operation: "delete",
5963
- input: {
5964
- path,
5965
- recursive
5966
- },
5967
- attributes: { filesystemProvider: filesystem.provider }
5968
- });
5969
- try {
5970
- if (filesystem.readOnly) throw new require_errors.WorkspaceReadOnlyError("delete");
5971
- if ((await filesystem.stat(path)).type === "directory") await filesystem.rmdir(path, {
5972
- recursive,
5973
- force: recursive
5974
- });
5975
- else await filesystem.deleteFile(path);
5976
- span.end({ success: true });
5977
- return `Deleted ${path}`;
5978
- } catch (err) {
5979
- span.error(err);
5980
- throw err;
5981
- }
5982
- }
5983
- });
5984
- // src/workspace/line-utils.ts
5985
- /**
5986
- * Extract lines from content by line range.
5987
- *
5988
- * @param content - The document content
5989
- * @param startLine - Starting line number (1-indexed)
5990
- * @param endLine - Ending line number (1-indexed, inclusive)
5991
- * @returns Object with extracted content and metadata
5992
- */
5993
- function extractLines(content, startLine, endLine) {
5994
- const allLines = content.split("\n");
5995
- const totalLines = allLines.length;
5996
- const start = Math.max(1, startLine ?? 1);
5997
- const end = Math.min(totalLines, endLine ?? totalLines);
5998
- if (start > end) return {
5999
- content: "",
6000
- lines: {
6001
- start: 0,
6002
- end: 0
6003
- },
6004
- totalLines
6005
- };
6006
- return {
6007
- content: allLines.slice(start - 1, end).join("\n"),
6008
- lines: {
6009
- start,
6010
- end
6011
- },
6012
- totalLines
6013
- };
6014
- }
6015
- /**
6016
- * Extract lines using offset/limit style parameters (like Claude Code).
6017
- *
6018
- * @param content - The document content
6019
- * @param offset - Line number to start from (1-indexed, default: 1)
6020
- * @param limit - Maximum number of lines to read (default: all remaining)
6021
- * @returns Object with extracted content and metadata
6022
- */
6023
- function extractLinesWithLimit(content, offset, limit) {
6024
- const startLine = offset ?? 1;
6025
- return extractLines(content, startLine, limit ? startLine + limit - 1 : void 0);
6026
- }
6027
- /**
6028
- * Format content with line number prefixes.
6029
- * Output format matches Claude Code: " 1→content here"
6030
- *
6031
- * @param content - The content to format
6032
- * @param startLineNumber - The line number of the first line (1-indexed)
6033
- * @returns Formatted content with line numbers
6034
- */
6035
- function formatWithLineNumbers(content, startLineNumber = 1) {
6036
- const lines = content.split("\n");
6037
- const maxLineNum = startLineNumber + lines.length - 1;
6038
- const padWidth = Math.max(6, String(maxLineNum).length + 1);
6039
- return lines.map((line, i) => {
6040
- const lineNum = startLineNumber + i;
6041
- return `${String(lineNum).padStart(padWidth)}\u2192${line}`;
6042
- }).join("\n");
6043
- }
6044
- /**
6045
- * Convert a character index to a line number.
6046
- * Useful for converting RAG chunk character offsets to line numbers.
6047
- *
6048
- * @param content - The full document content
6049
- * @param charIndex - The character index (0-indexed)
6050
- * @returns The line number (1-indexed), or undefined if charIndex is out of bounds
6051
- */
6052
- function charIndexToLineNumber(content, charIndex) {
6053
- if (charIndex < 0 || charIndex > content.length) return;
6054
- let lineNumber = 1;
6055
- for (let i = 0; i < charIndex && i < content.length; i++) if (content[i] === "\n") lineNumber++;
6056
- return lineNumber;
6057
- }
6058
- /**
6059
- * Convert character range to line range.
6060
- * Useful for converting RAG chunk character offsets to line ranges.
6061
- *
6062
- * @param content - The full document content
6063
- * @param startCharIdx - Start character index (0-indexed)
6064
- * @param endCharIdx - End character index (0-indexed, exclusive)
6065
- * @returns LineRange (1-indexed) or undefined if indices are out of bounds
6066
- */
6067
- function charRangeToLineRange(content, startCharIdx, endCharIdx) {
6068
- const startLine = charIndexToLineNumber(content, startCharIdx);
6069
- const endLine = charIndexToLineNumber(content, Math.max(0, endCharIdx - 1));
6070
- if (startLine === void 0 || endLine === void 0) return;
6071
- return {
6072
- start: startLine,
6073
- end: endLine
6074
- };
6075
- }
6076
- /**
6077
- * Count occurrences of a string in content.
6078
- *
6079
- * @param content - The content to search
6080
- * @param searchString - The string to find
6081
- * @returns Number of occurrences
6082
- */
6083
- function countOccurrences(content, searchString) {
6084
- if (!searchString) return 0;
6085
- let count = 0;
6086
- let position = 0;
6087
- while ((position = content.indexOf(searchString, position)) !== -1) {
6088
- count++;
6089
- position += searchString.length;
6090
- }
6091
- return count;
6092
- }
6093
- /**
6094
- * Replace a string in content, with validation for uniqueness.
6095
- *
6096
- * @param content - The content to modify
6097
- * @param oldString - The string to find and replace
6098
- * @param newString - The replacement string
6099
- * @param replaceAll - If true, replace all occurrences; if false, require unique match
6100
- * @returns Object with result content and metadata
6101
- * @throws Error if oldString is not found or not unique (when replaceAll is false)
6102
- */
6103
- function replaceString(content, oldString, newString, replaceAll = false) {
6104
- const count = countOccurrences(content, oldString);
6105
- if (count === 0) throw new StringNotFoundError(oldString);
6106
- if (!replaceAll && count > 1) throw new StringNotUniqueError(oldString, count);
6107
- const escapedNewString = newString.replace(/\$/g, "$$$$");
6108
- if (replaceAll) return {
6109
- content: content.split(oldString).join(newString),
6110
- replacements: count
6111
- };
6112
- return {
6113
- content: content.replace(oldString, escapedNewString),
6114
- replacements: 1
6115
- };
6116
- }
6117
- /**
6118
- * Error thrown when string is not found during replacement.
6119
- */
6120
- var StringNotFoundError = class extends Error {
6121
- searchString;
6122
- constructor(searchString) {
6123
- super(`The specified text was not found. Make sure you use the exact text from the file.`);
6124
- this.searchString = searchString;
6125
- this.name = "StringNotFoundError";
6126
- }
6127
- };
6128
- /**
6129
- * Error thrown when string appears multiple times but unique match required.
6130
- */
6131
- var StringNotUniqueError = class extends Error {
6132
- searchString;
6133
- occurrences;
6134
- constructor(searchString, occurrences) {
6135
- super(`The specified text appears ${occurrences} times. Provide more surrounding context to make the match unique, or use replace_all to replace all occurrences.`);
6136
- this.searchString = searchString;
6137
- this.occurrences = occurrences;
6138
- this.name = "StringNotUniqueError";
6185
+ try {
6186
+ await computer.scroll(direction, effectiveAmount);
6187
+ const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.SCROLL, `Scrolled ${direction} by ${effectiveAmount}`);
6188
+ span.end({ success: true });
6189
+ return result;
6190
+ } catch (err) {
6191
+ span.error(err);
6192
+ throw err;
6193
+ }
6194
+ },
6195
+ toModelOutput: mediaToModelOutput
6196
+ });
6197
+ // src/workspace/tools/computer-type.ts
6198
+ const computerTypeTool = require_tool.createTool({
6199
+ id: WORKSPACE_TOOLS.COMPUTER.TYPE,
6200
+ description: "Type text into the focused element on the sandbox desktop using the keyboard. Click an input field first to focus it. Use the press-key tool for special keys (Enter, Tab, shortcuts).",
6201
+ inputSchema: zod_v4.z.object({ text: zod_v4.z.string().describe("The text to type") }),
6202
+ execute: async ({ text }, context) => {
6203
+ const { workspace, sandbox, computer } = requireComputer(context);
6204
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.TYPE);
6205
+ const span = startWorkspaceSpan(context, workspace, {
6206
+ category: "computer",
6207
+ operation: "type",
6208
+ input: { length: text.length },
6209
+ attributes: { sandboxProvider: sandbox.provider }
6210
+ });
6211
+ try {
6212
+ await computer.type(text);
6213
+ const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.TYPE, `Typed ${text.length} characters`);
6214
+ span.end({ success: true });
6215
+ return result;
6216
+ } catch (err) {
6217
+ span.error(err);
6218
+ throw err;
6219
+ }
6220
+ },
6221
+ toModelOutput: mediaToModelOutput
6222
+ });
6223
+ // src/workspace/tools/computer-wait.ts
6224
+ const computerWaitTool = require_tool.createTool({
6225
+ id: WORKSPACE_TOOLS.COMPUTER.WAIT,
6226
+ description: "Wait for the sandbox desktop UI to settle (e.g. an application launching or a page loading) before the next action.",
6227
+ inputSchema: zod_v4.z.object({ seconds: zod_v4.z.number().min(.1).max(30).describe("How long to wait, in seconds (max 30)") }),
6228
+ execute: async ({ seconds }, context) => {
6229
+ const { workspace, sandbox, computer } = requireComputer(context);
6230
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.WAIT);
6231
+ const span = startWorkspaceSpan(context, workspace, {
6232
+ category: "computer",
6233
+ operation: "wait",
6234
+ input: { seconds },
6235
+ attributes: { sandboxProvider: sandbox.provider }
6236
+ });
6237
+ try {
6238
+ await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
6239
+ const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.WAIT, `Waited ${seconds}s`);
6240
+ span.end({ success: true });
6241
+ return result;
6242
+ } catch (err) {
6243
+ span.error(err);
6244
+ throw err;
6245
+ }
6246
+ },
6247
+ toModelOutput: mediaToModelOutput
6248
+ });
6249
+ // src/workspace/tools/delete-file.ts
6250
+ const deleteFileTool = require_tool.createTool({
6251
+ id: WORKSPACE_TOOLS.FILESYSTEM.DELETE,
6252
+ description: "Delete a file or directory from the workspace filesystem",
6253
+ outputSchema: zod_v4.z.string(),
6254
+ inputSchema: zod_v4.z.object({
6255
+ path: zod_v4.z.string().describe("The path to the file or directory to delete"),
6256
+ recursive: zod_v4.z.boolean().optional().default(false).describe("If true, delete directories and their contents recursively. Required for non-empty directories.")
6257
+ }),
6258
+ execute: async ({ path, recursive }, context) => {
6259
+ const { workspace, filesystem } = requireFilesystem(context);
6260
+ await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.FILESYSTEM.DELETE);
6261
+ const span = startWorkspaceSpan(context, workspace, {
6262
+ category: "filesystem",
6263
+ operation: "delete",
6264
+ input: {
6265
+ path,
6266
+ recursive
6267
+ },
6268
+ attributes: { filesystemProvider: filesystem.provider }
6269
+ });
6270
+ try {
6271
+ if (filesystem.readOnly) throw new require_errors.WorkspaceReadOnlyError("delete");
6272
+ if ((await filesystem.stat(path)).type === "directory") await filesystem.rmdir(path, {
6273
+ recursive,
6274
+ force: recursive
6275
+ });
6276
+ else await filesystem.deleteFile(path);
6277
+ span.end({ success: true });
6278
+ return `Deleted ${path}`;
6279
+ } catch (err) {
6280
+ span.error(err);
6281
+ throw err;
6282
+ }
6139
6283
  }
6140
- };
6284
+ });
6141
6285
  // src/workspace/tools/edit-file.ts
6142
6286
  function getEditedLineRanges(content, oldString, newString, replaceAll) {
6143
6287
  if (!oldString) return "";
@@ -6472,150 +6616,6 @@ var BrowserCliHandler = class {
6472
6616
  * This preserves warmup state across command executions.
6473
6617
  */
6474
6618
  const browserCliHandler = new BrowserCliHandler();
6475
- // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
6476
- const PATTERNS = {
6477
- whitespace: /^\s+$/,
6478
- structuredWhitespace: /\n\s/,
6479
- cjk: /[\u4E00-\u9FFF\u3400-\u4DBF\u3000-\u30FF\uFF00-\uFFEF\u2E80-\u2EFF\u31C0-\u31EF\u3200-\u32FF\u3300-\u33FF\uAC00-\uD7AF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uD7B0-\uD7FF]/,
6480
- numeric: /^\d+$/,
6481
- punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_"-]/
6482
- };
6483
- const TOKEN_SPLIT_PATTERN = new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
6484
- const DEFAULT_CHARS_PER_TOKEN = 6;
6485
- const SHORT_TOKEN_THRESHOLD = 3;
6486
- const KANA_CHARS_PER_TOKEN = 1.35;
6487
- const DEFAULT_LANGUAGE_CONFIGS = [
6488
- {
6489
- pattern: /[\u00E4\u00F6\u00FC\u00DF\u1E9E]/i,
6490
- averageCharsPerToken: 2.6
6491
- },
6492
- {
6493
- pattern: /[\u00E9\u00E8\u00EA\u00EB\u00E0\u00E2\u00EE\u00EF\u00F4\u00FB\u00F9\u00FC\u00FF\u00E7\u0153\u00E6\u00E1\u00ED\u00F3\u00FA\u00F1]/i,
6494
- averageCharsPerToken: 3
6495
- },
6496
- {
6497
- pattern: /[\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u011B\u0161\u010D\u0159\u017E\u00FD\u016F\u00FA\u010F\u0165\u0148]/i,
6498
- averageCharsPerToken: 2.5
6499
- },
6500
- {
6501
- pattern: /[\u0430-\u044F\u0451]/i,
6502
- averageCharsPerToken: 4
6503
- },
6504
- {
6505
- pattern: /[\u03AC-\u03CE]/i,
6506
- averageCharsPerToken: 2.75
6507
- },
6508
- {
6509
- pattern: /^\p{Extended_Pictographic}[\p{Extended_Pictographic}\p{Emoji_Component}]*$/u,
6510
- averageCharsPerToken: .75
6511
- }
6512
- ];
6513
- /**
6514
- * Walks a text as (segment, estimated token count) pairs. The segments
6515
- * concatenate back to the original text; whitespace segments count zero
6516
- * tokens unless they carry structure (indentation or blank lines).
6517
- */
6518
- function* walkSegments(text, options = {}) {
6519
- if (!text) return;
6520
- const resolvedOptions = resolveOptions(options);
6521
- for (const segment of text.split(TOKEN_SPLIT_PATTERN)) if (segment) yield {
6522
- segment,
6523
- tokenCount: estimateSegmentTokens(segment, resolvedOptions)
6524
- };
6525
- }
6526
- function resolveOptions(options) {
6527
- return {
6528
- defaultCharsPerToken: options.defaultCharsPerToken ?? DEFAULT_CHARS_PER_TOKEN,
6529
- languageConfigs: options.languageConfigs ?? DEFAULT_LANGUAGE_CONFIGS
6530
- };
6531
- }
6532
- function estimateSegmentTokens(segment, { languageConfigs, defaultCharsPerToken }) {
6533
- if (PATTERNS.whitespace.test(segment)) return PATTERNS.structuredWhitespace.test(segment) ? 1 : 0;
6534
- const languageCharsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs);
6535
- if (languageCharsPerToken !== void 0) return Math.ceil(getCharacterCount(segment) / languageCharsPerToken);
6536
- if (PATTERNS.cjk.test(segment)) return estimateCjkTokens(segment);
6537
- if (PATTERNS.numeric.test(segment)) return Math.ceil(segment.length / 3);
6538
- if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
6539
- if (PATTERNS.punctuation.test(segment)) return Math.ceil(segment.length / 2);
6540
- return Math.ceil(segment.length / defaultCharsPerToken);
6541
- }
6542
- function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
6543
- for (const config of languageConfigs) if (segment.search(config.pattern) !== -1) return config.averageCharsPerToken;
6544
- }
6545
- function getCharacterCount(text) {
6546
- return Array.from(text).length;
6547
- }
6548
- function estimateCjkTokens(segment) {
6549
- let kanaCount = 0;
6550
- let otherCount = 0;
6551
- for (const character of segment) {
6552
- const codePoint = character.codePointAt(0);
6553
- if (codePoint >= 12352 && codePoint <= 12543) kanaCount++;
6554
- else otherCount++;
6555
- }
6556
- return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
6557
- }
6558
- /**
6559
- * Estimates the number of tokens in a text string using heuristic rules
6560
- */
6561
- function estimateTokenCount(text, options = {}) {
6562
- if (!text) return 0;
6563
- let tokenCount = 0;
6564
- for (const segmentEstimate of walkSegments(text, options)) tokenCount += segmentEstimate.tokenCount;
6565
- return tokenCount;
6566
- }
6567
- /**
6568
- * Extracts a portion of text based on token positions, similar to Array.prototype.slice()
6569
- */
6570
- function sliceByTokens(text, start = 0, end, options = {}) {
6571
- if (!text) return "";
6572
- let segmentEstimates = walkSegments(text, options);
6573
- let totalTokens = 0;
6574
- if (start < 0 || end !== void 0 && end < 0) {
6575
- const bufferedEstimates = Array.from(segmentEstimates);
6576
- for (const { tokenCount } of bufferedEstimates) totalTokens += tokenCount;
6577
- segmentEstimates = bufferedEstimates;
6578
- }
6579
- const normalizedStart = start < 0 ? Math.max(0, totalTokens + start) : Math.max(0, start);
6580
- const normalizedEnd = end === void 0 ? Infinity : end < 0 ? Math.max(0, totalTokens + end) : end;
6581
- if (normalizedStart >= normalizedEnd) return "";
6582
- const parts = [];
6583
- let currentTokenPos = 0;
6584
- for (const { segment, tokenCount } of segmentEstimates) {
6585
- if (currentTokenPos >= normalizedEnd) break;
6586
- const extracted = extractSegmentPart(segment, currentTokenPos, tokenCount, normalizedStart, normalizedEnd);
6587
- if (extracted) parts.push(extracted);
6588
- currentTokenPos += tokenCount;
6589
- }
6590
- return parts.join("");
6591
- }
6592
- function extractSegmentPart(segment, segmentTokenStart, segmentTokenCount, targetStart, targetEnd) {
6593
- if (segmentTokenCount === 0) return segmentTokenStart >= targetStart && segmentTokenStart < targetEnd ? segment : "";
6594
- const segmentTokenEnd = segmentTokenStart + segmentTokenCount;
6595
- if (segmentTokenStart >= targetEnd || segmentTokenEnd <= targetStart) return "";
6596
- const overlapStart = Math.max(0, targetStart - segmentTokenStart);
6597
- const overlapEnd = Math.min(segmentTokenCount, targetEnd - segmentTokenStart);
6598
- if (overlapStart === 0 && overlapEnd === segmentTokenCount) return segment;
6599
- const charStart = Math.floor(overlapStart / segmentTokenCount * segment.length);
6600
- const charEnd = Math.ceil(overlapEnd / segmentTokenCount * segment.length);
6601
- return segment.slice(charStart, charEnd);
6602
- }
6603
- // src/utils/slice-by-tokens.ts
6604
- const UNPAIRED_SURROGATE_RE = /[\uD800-\uDFFF]/gu;
6605
- /**
6606
- * `sliceByTokens` from tokenx cuts on UTF-16 code-unit boundaries, so a cut can
6607
- * land inside a surrogate pair (emoji, CJK ext B+, math alphanumerics) and leave
6608
- * an unpaired surrogate. That is invalid UTF-16: it degrades to U+FFFD on a UTF-8
6609
- * round-trip and strict JSON parsers reject it. Always slice through this helper
6610
- * so every truncation site gets the same repair.
6611
- */
6612
- function sliceByTokensSafe(text, start, end) {
6613
- return sliceByTokens(text, start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
6614
- }
6615
- /** `text.slice(start, end)` by UTF-16 index, with the same repair for a cut inside a surrogate pair. */
6616
- function sliceSafe(text, start, end) {
6617
- return text.slice(start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
6618
- }
6619
6619
  // src/workspace/tools/output-helpers.ts
6620
6620
  /** Default number of lines to return (tail). */
6621
6621
  const DEFAULT_TAIL_LINES = 200;
@@ -6690,6 +6690,159 @@ function splitTail(output, tail) {
6690
6690
  };
6691
6691
  }
6692
6692
  /**
6693
+ * tokenx is synchronous and allocates per word, so running it over a multi-MB
6694
+ * output blocks the event loop for seconds. Outputs up to this many chars per
6695
+ * token of budget are counted and cut exactly as before; longer ones never reach
6696
+ * tokenx whole (see `countTokensOver` and `sliceEdge`).
6697
+ */
6698
+ const WINDOW_CHARS_PER_TOKEN = 32;
6699
+ /**
6700
+ * tokenx never gives a non-whitespace segment fewer than one token per this many
6701
+ * UTF-16 chars: 6 by default, and up to 4 code points (8 chars when astral) for
6702
+ * its language rules. So text with more non-whitespace chars than
6703
+ * `limit * MAX_CHARS_PER_TOKEN` is over `limit`.
6704
+ */
6705
+ const MAX_CHARS_PER_TOKEN = 8;
6706
+ const WHITESPACE_RUN_RE = /\s+/g;
6707
+ const STRUCTURED_WHITESPACE_RE = /\n\s/;
6708
+ const WS = 0;
6709
+ const PUNCT = 1;
6710
+ const DIGIT = 2;
6711
+ const WORD = 3;
6712
+ const CHAR_CLASS = (/* @__PURE__ */ new Uint8Array(128)).fill(WORD);
6713
+ for (const c of " \n\r\v\f") CHAR_CLASS[c.charCodeAt(0)] = WS;
6714
+ for (const c of ".,!?;(){}[]<>:/\\|@#$%^&*+=`~_\"-") CHAR_CLASS[c.charCodeAt(0)] = PUNCT;
6715
+ for (let c = 48; c <= 57; c++) CHAR_CLASS[c] = DIGIT;
6716
+ /** Same set as the regex `\s`, which is what tokenx splits words on. */
6717
+ function isWhitespace(code) {
6718
+ return code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279;
6719
+ }
6720
+ function runTokens(kind, length, onlyDigits) {
6721
+ if (kind === WS) return 0;
6722
+ if (length <= 3) return 1;
6723
+ if (kind === PUNCT) return Math.ceil(length / 2);
6724
+ return onlyDigits ? Math.ceil(length / 3) : Math.ceil(length / 6);
6725
+ }
6726
+ /**
6727
+ * One pass over char codes with no allocations: an approximate token count
6728
+ * (tokenx's rules for ASCII text, used only for the "of ~N tokens" total) and
6729
+ * the number of non-whitespace chars.
6730
+ */
6731
+ function scanTokens(text) {
6732
+ let approx = 0;
6733
+ let nonWhitespace = 0;
6734
+ let kind = -1;
6735
+ let length = 0;
6736
+ let onlyDigits = true;
6737
+ for (let i = 0; i < text.length; i++) {
6738
+ const code = text.charCodeAt(i);
6739
+ const cls = code < 128 ? CHAR_CLASS[code] : isWhitespace(code) ? WS : WORD;
6740
+ const runKind = cls === DIGIT ? WORD : cls;
6741
+ if (runKind !== kind) {
6742
+ if (length) approx += runTokens(kind, length, onlyDigits);
6743
+ kind = runKind;
6744
+ length = 0;
6745
+ onlyDigits = true;
6746
+ }
6747
+ length++;
6748
+ if (cls !== WS) nonWhitespace++;
6749
+ if (cls !== DIGIT) onlyDigits = false;
6750
+ }
6751
+ if (length) approx += runTokens(kind, length, onlyDigits);
6752
+ return {
6753
+ approx,
6754
+ nonWhitespace
6755
+ };
6756
+ }
6757
+ /**
6758
+ * Exact token count of `output` when it may fit `limit`, else an approximation.
6759
+ * Returns `undefined` when the output fits, so callers return it as is.
6760
+ */
6761
+ function countTokensOver(output, limit) {
6762
+ if (output.length <= Math.max(limit, 1) * WINDOW_CHARS_PER_TOKEN) {
6763
+ const exact = estimateTokenCount(output);
6764
+ return exact <= limit ? void 0 : exact;
6765
+ }
6766
+ const { approx, nonWhitespace } = scanTokens(output);
6767
+ if (nonWhitespace > limit * MAX_CHARS_PER_TOKEN) return approx;
6768
+ const exact = estimateTokenCount(output.replace(WHITESPACE_RUN_RE, (run) => STRUCTURED_WHITESPACE_RE.test(run) ? "\n " : " "));
6769
+ return exact <= limit ? void 0 : exact;
6770
+ }
6771
+ /**
6772
+ * `budget` tokens from one end of `output`. Outputs within the overall `limit`'s
6773
+ * size cap are cut exactly as before, by `sliceByTokensSafe(output, 0, budget)`
6774
+ * (`'head'`) or `sliceByTokensSafe(output, -budget)` (`'tail'`). Longer ones hand
6775
+ * tokenx only a window at that end, measured as tokenx sees it: whitespace runs
6776
+ * are collapsed (see `countTokensOver`), so padding can't crowd real text out of
6777
+ * the window. The cut is mapped back to the original text, whitespace and all.
6778
+ *
6779
+ * For those longer outputs the cut is approximate: it fits `budget` by tokenx's
6780
+ * count of the kept text, but can land elsewhere than tokenizing the whole output
6781
+ * would. tokenx counts a segment by its whole length, so a window that ends inside
6782
+ * a long segment counts it differently (at a 2,000-token budget, 65,000 'a' then
6783
+ * 'é' keeps 12,000 chars here and 6,000 when the whole output is tokenized).
6784
+ */
6785
+ function sliceEdge(output, budget, limit, side) {
6786
+ if (output.length <= Math.max(limit, 1) * WINDOW_CHARS_PER_TOKEN) return side === "head" ? sliceByTokensSafe(output, 0, budget) : sliceByTokensSafe(output, -budget);
6787
+ const target = Math.max(budget, 1) * WINDOW_CHARS_PER_TOKEN;
6788
+ let size = 0;
6789
+ let inWhitespace = false;
6790
+ let edge = side === "head" ? 0 : output.length;
6791
+ while (side === "head" ? edge < output.length : edge > 0) {
6792
+ const code = output.charCodeAt(side === "head" ? edge : edge - 1);
6793
+ const whitespace = code < 128 ? CHAR_CLASS[code] === WS : isWhitespace(code);
6794
+ const cost = whitespace ? inWhitespace ? 0 : 2 : 1;
6795
+ if (size + cost > target) break;
6796
+ size += cost;
6797
+ inWhitespace = whitespace;
6798
+ edge += side === "head" ? 1 : -1;
6799
+ }
6800
+ const window = side === "head" ? output.slice(0, edge) : output.slice(edge);
6801
+ const runs = [];
6802
+ let collapsed = "";
6803
+ let last = 0;
6804
+ for (const match of window.matchAll(WHITESPACE_RUN_RE)) {
6805
+ collapsed += window.slice(last, match.index);
6806
+ const replacement = STRUCTURED_WHITESPACE_RE.test(match[0]) ? "\n " : " ";
6807
+ runs.push({
6808
+ collapsedStart: collapsed.length,
6809
+ collapsedEnd: collapsed.length + replacement.length,
6810
+ start: match.index,
6811
+ end: match.index + match[0].length
6812
+ });
6813
+ collapsed += replacement;
6814
+ last = match.index + match[0].length;
6815
+ }
6816
+ collapsed += window.slice(last);
6817
+ const toWindowIndex = (index) => {
6818
+ let shift = 0;
6819
+ for (const run of runs) {
6820
+ if (index < run.collapsedStart) break;
6821
+ if (index <= run.collapsedEnd) return index === run.collapsedEnd ? run.end : run.start;
6822
+ shift = run.end - run.collapsedEnd;
6823
+ }
6824
+ return index + shift;
6825
+ };
6826
+ if (side === "head") return sliceSafe(window, 0, toWindowIndex(fitBudget(sliceByTokensSafe(collapsed, 0, budget), budget, side).length));
6827
+ const kept = fitBudget(sliceByTokensSafe(collapsed, -budget), budget, side);
6828
+ return sliceSafe(window, toWindowIndex(collapsed.length - kept.length));
6829
+ }
6830
+ /**
6831
+ * tokenx slices a segment by the chars-per-token of its language, picked from the
6832
+ * chars it contains, so a cut that drops the char that picked it (a lone 'ж' in a run
6833
+ * of CJK) can count several times over `budget` on its own. Recount the kept text,
6834
+ * which is no longer than the bounded input it was cut from, and cut it again until
6835
+ * it fits.
6836
+ */
6837
+ function fitBudget(kept, budget, side) {
6838
+ for (let tokens = estimateTokenCount(kept); kept.length > 0 && tokens > budget; tokens = estimateTokenCount(kept)) {
6839
+ const next = side === "head" ? sliceByTokensSafe(kept, 0, budget) : sliceByTokensSafe(kept, -budget);
6840
+ const length = next.length < kept.length ? next.length : Math.floor(kept.length * budget / tokens);
6841
+ kept = side === "head" ? sliceSafe(kept, 0, length) : sliceSafe(kept, kept.length - length);
6842
+ }
6843
+ return kept;
6844
+ }
6845
+ /**
6693
6846
  * Token-based output limit. Truncates output to fit within a token budget.
6694
6847
  * Uses tokenx for fast token estimation and truncates at the token level
6695
6848
  * (not line boundaries) to maximise use of the budget.
@@ -6702,9 +6855,9 @@ function splitTail(output, tail) {
6702
6855
  */
6703
6856
  async function applyTokenLimit(output, limit = DEFAULT_MAX_OUTPUT_TOKENS, from = "start") {
6704
6857
  if (!output) return output;
6705
- const totalTokens = estimateTokenCount(output);
6706
- if (totalTokens <= limit) return output;
6707
- const kept = from === "start" ? sliceByTokensSafe(output, -limit) : sliceByTokensSafe(output, 0, limit);
6858
+ const totalTokens = countTokensOver(output, limit);
6859
+ if (totalTokens === void 0) return output;
6860
+ const kept = from === "start" ? sliceEdge(output, limit, limit, "tail") : sliceEdge(output, limit, limit, "head");
6708
6861
  const position = from === "start" ? "last" : "first";
6709
6862
  return from === "start" ? `[output truncated: showing ${position} ~${limit} of ~${totalTokens} tokens]\n${kept}` : `${kept}\n[output truncated: showing ${position} ~${limit} of ~${totalTokens} tokens]`;
6710
6863
  }
@@ -6714,12 +6867,12 @@ async function applyTokenLimit(output, limit = DEFAULT_MAX_OUTPUT_TOKENS, from =
6714
6867
  */
6715
6868
  function sandwich(output, limit, headRatio, firstLine) {
6716
6869
  if (!output) return output;
6717
- const totalTokens = estimateTokenCount(output);
6718
- if (totalTokens <= limit) return output;
6870
+ const totalTokens = countTokensOver(output, limit);
6871
+ if (totalTokens === void 0) return output;
6719
6872
  const headBudget = Math.floor(limit * headRatio);
6720
6873
  const tailBudget = limit - headBudget;
6721
- let head = headBudget > 0 ? sliceByTokensSafe(output, 0, headBudget) : "";
6722
- let tail = tailBudget > 0 ? sliceByTokensSafe(output, -tailBudget) : "";
6874
+ let head = headBudget > 0 ? sliceEdge(output, headBudget, limit, "head") : "";
6875
+ let tail = tailBudget > 0 ? sliceEdge(output, tailBudget, limit, "tail") : "";
6723
6876
  const headEnd = head.length;
6724
6877
  let tailStart = output.length - tail.length;
6725
6878
  head = head.replace(/\r?\n$/, "");