@mastra/core 1.86.0-alpha.6 → 1.86.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/@internal_core@0.1.4/dist/memory/index.d.ts +25 -0
- package/dist/agent/agent.d.ts +27 -11
- package/dist/agent/agent.types.d.ts +4 -0
- package/dist/agent/durable/create-durable-agent.d.ts +1 -1
- package/dist/agent/durable/durable-agent.d.ts +30 -500
- package/dist/agent/durable/durable-stream-until-idle.d.ts +2 -1
- package/dist/agent/durable/evented-agent.d.ts +2 -5
- package/dist/agent/durable/execution-engine.d.ts +20 -3
- package/dist/agent/durable/index.cjs +55 -6338
- package/dist/agent/durable/index.d.ts +3 -2
- package/dist/agent/durable/index.js +44 -6327
- package/dist/agent/durable/stream-adapter.d.ts +5 -5
- package/dist/agent/durable/types.d.ts +454 -3
- package/dist/agent/durable/workflows/durable-loop-builder.d.ts +7 -9
- package/dist/agent/helpers.d.ts +1 -1
- package/dist/agent/index.cjs +4 -4
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +4 -4
- package/dist/agent/streams/execution-capability.d.ts +3 -2
- package/dist/agent/streams/execution-policy.d.ts +1 -1
- package/dist/agent/streams/types.d.ts +3 -3
- package/dist/agent/types.d.ts +5 -5
- package/dist/agent-builder/ee/index.cjs +1 -1
- package/dist/agent-builder/ee/index.js +1 -1
- package/dist/agent-controller/index.cjs +2 -2
- package/dist/agent-controller/index.js +2 -2
- package/dist/{agent-controller-c4KbZ8DY.js → agent-controller-Cf3_IuY8.js} +9 -9
- package/dist/{agent-controller-6ORqG6hK.cjs → agent-controller-K5vHtqfO.cjs} +9 -9
- package/dist/{agent-skills-resolver-BIeWsb01.cjs → agent-skills-resolver-BMoCDoaK.cjs} +1 -1
- package/dist/{agent-skills-resolver-k04IRam7.js → agent-skills-resolver-CUEIMDbx.js} +1 -1
- package/dist/background-tasks/index.cjs +1 -1
- package/dist/background-tasks/index.js +1 -1
- package/dist/{background-tasks-CEglmAt7.js → background-tasks-BgpX1P_s.js} +1 -1
- package/dist/{background-tasks-Da0c3R-J.cjs → background-tasks-DqnQMfuf.cjs} +1 -1
- package/dist/browser/index.cjs +2 -2
- package/dist/browser/index.js +2 -2
- package/dist/{builder-DS826dWf.cjs → builder-D8Osghdo.cjs} +3 -3
- package/dist/{builder-0V9N8S15.js → builder-x295GDL6.js} +3 -3
- package/dist/capabilities/302ai.json +191 -191
- package/dist/capabilities/abliteratedllm.json +36 -36
- package/dist/capabilities/abliteration-ai.json +7 -7
- package/dist/capabilities/above.json +20 -20
- package/dist/capabilities/adaption.json +10 -10
- package/dist/capabilities/adzuki.json +31 -31
- package/dist/capabilities/agentrouter.json +10 -10
- package/dist/capabilities/ai-router.json +9 -9
- package/dist/capabilities/aiand.json +19 -19
- package/dist/capabilities/aigrow.json +14 -14
- package/dist/capabilities/aimlapi.json +142 -142
- package/dist/capabilities/aipg.json +2 -2
- package/dist/capabilities/aixy.json +20 -20
- package/dist/capabilities/aki-io.json +15 -15
- package/dist/capabilities/alibaba-cn.json +90 -90
- package/dist/capabilities/alibaba-coding-plan-cn.json +5 -5
- package/dist/capabilities/alibaba-coding-plan.json +5 -5
- package/dist/capabilities/alibaba-token-plan-cn.json +55 -55
- package/dist/capabilities/alibaba-token-plan.json +57 -57
- package/dist/capabilities/alibaba.json +64 -64
- package/dist/capabilities/ambient.json +12 -12
- package/dist/capabilities/amd.json +8 -8
- package/dist/capabilities/anthropic.json +60 -36
- package/dist/capabilities/anyapi.json +14 -14
- package/dist/capabilities/apiko.json +2 -2
- package/dist/capabilities/arcee.json +11 -11
- package/dist/capabilities/augure.json +5 -5
- package/dist/capabilities/auriko.json +19 -19
- package/dist/capabilities/bailing.json +5 -5
- package/dist/capabilities/baseten.json +18 -18
- package/dist/capabilities/bee.json +3 -3
- package/dist/capabilities/berget.json +8 -8
- package/dist/capabilities/bothub.json +13 -13
- package/dist/capabilities/boundless.json +35 -35
- package/dist/capabilities/bumo.json +44 -44
- package/dist/capabilities/byteplus.json +31 -31
- package/dist/capabilities/cerebras.json +4 -4
- package/dist/capabilities/cheapaimodel.json +10 -10
- package/dist/capabilities/cheapest-token.json +31 -31
- package/dist/capabilities/chutes.json +8 -8
- package/dist/capabilities/cline-pass.json +41 -41
- package/dist/capabilities/cloudcode.json +7 -7
- package/dist/capabilities/cloudflare-workers-ai.json +31 -31
- package/dist/capabilities/commandcode.json +147 -147
- package/dist/capabilities/concentrate.json +259 -259
- package/dist/capabilities/cortecs.json +109 -109
- package/dist/capabilities/crossmodel.json +169 -169
- package/dist/capabilities/crusoe.json +10 -10
- package/dist/capabilities/daoxe.json +9 -9
- package/dist/capabilities/databricks.json +59 -59
- package/dist/capabilities/deepinfra.json +85 -85
- package/dist/capabilities/deepseek.json +3 -3
- package/dist/capabilities/digitalocean.json +113 -113
- package/dist/capabilities/dothoosh.json +29 -29
- package/dist/capabilities/doubleword.json +23 -23
- package/dist/capabilities/edenai.json +454 -453
- package/dist/capabilities/empiriolabs.json +170 -170
- package/dist/capabilities/engy.json +22 -22
- package/dist/capabilities/entrim.json +6 -6
- package/dist/capabilities/evroc.json +16 -16
- package/dist/capabilities/ezkielyna.json +9 -9
- package/dist/capabilities/fastrouter.json +80 -80
- package/dist/capabilities/fireworks-ai.json +65 -65
- package/dist/capabilities/freemodel.json +21 -21
- package/dist/capabilities/friendli.json +6 -6
- package/dist/capabilities/frogbot.json +89 -89
- package/dist/capabilities/gisoo.json +19 -19
- package/dist/capabilities/gmicloud.json +16 -16
- package/dist/capabilities/google.json +57 -57
- package/dist/capabilities/graphn.json +12 -12
- package/dist/capabilities/greenpt.json +34 -34
- package/dist/capabilities/groq.json +2 -2
- package/dist/capabilities/helicone.json +83 -83
- package/dist/capabilities/hostinger-router.json +11 -11
- package/dist/capabilities/hpc-ai.json +14 -14
- package/dist/capabilities/huawei-maas.json +14 -14
- package/dist/capabilities/hubris.json +25 -25
- package/dist/capabilities/huggingface.json +48 -48
- package/dist/capabilities/hyper.json +26 -26
- package/dist/capabilities/impossibl.json +132 -132
- package/dist/capabilities/inception.json +2 -2
- package/dist/capabilities/inco.json +5 -5
- package/dist/capabilities/infer.json +12 -12
- package/dist/capabilities/inferall.json +10 -10
- package/dist/capabilities/inference-coop.json +11 -11
- package/dist/capabilities/inferenceapis.json +6 -6
- package/dist/capabilities/inferris.json +4 -4
- package/dist/capabilities/infersia.json +14 -14
- package/dist/capabilities/inferx.json +3 -3
- package/dist/capabilities/infomaniak.json +4 -4
- package/dist/capabilities/io-net.json +2 -2
- package/dist/capabilities/isoquant.json +4 -4
- package/dist/capabilities/iteracompute.json +60 -60
- package/dist/capabilities/jad-ai.json +3 -3
- package/dist/capabilities/jalapeno.json +10 -10
- package/dist/capabilities/jiekou.json +65 -65
- package/dist/capabilities/jzstoken.json +52 -52
- package/dist/capabilities/keln.json +23 -23
- package/dist/capabilities/kenari.json +122 -116
- package/dist/capabilities/kilo.json +627 -627
- package/dist/capabilities/kimi-code-plan-cn.json +7 -7
- package/dist/capabilities/kimi-code-plan-global.json +7 -7
- package/dist/capabilities/kitani.json +2 -2
- package/dist/capabilities/klavo.json +24 -24
- package/dist/capabilities/korouter.json +29 -29
- package/dist/capabilities/kunavo.json +7 -7
- package/dist/capabilities/liquid.json +10 -10
- package/dist/capabilities/lithosai.json +2 -2
- package/dist/capabilities/llmgateway-providers.json +890 -890
- package/dist/capabilities/llmgateway.json +333 -333
- package/dist/capabilities/llmtr.json +30 -30
- package/dist/capabilities/longcat.json +3 -3
- package/dist/capabilities/lowrouter.json +51 -51
- package/dist/capabilities/lyceum.json +14 -14
- package/dist/capabilities/melious.json +15 -15
- package/dist/capabilities/merge-gateway.json +236 -236
- package/dist/capabilities/meta.json +11 -11
- package/dist/capabilities/mistral.json +21 -21
- package/dist/capabilities/mixlayer.json +3 -3
- package/dist/capabilities/modal.json +10 -10
- package/dist/capabilities/model-oracle-ai.json +24 -24
- package/dist/capabilities/modelis.json +20 -20
- package/dist/capabilities/modelscope.json +2 -2
- package/dist/capabilities/modular.json +5 -5
- package/dist/capabilities/moneo.json +16 -16
- package/dist/capabilities/moonshotai-cn.json +7 -7
- package/dist/capabilities/moonshotai.json +7 -7
- package/dist/capabilities/morph.json +16 -16
- package/dist/capabilities/munito-eu.json +4 -4
- package/dist/capabilities/munito.json +6 -6
- package/dist/capabilities/nan.json +29 -29
- package/dist/capabilities/nano-gpt.json +586 -556
- package/dist/capabilities/nearai.json +89 -89
- package/dist/capabilities/nebius.json +29 -29
- package/dist/capabilities/neon.json +126 -126
- package/dist/capabilities/neuralwatt.json +43 -43
- package/dist/capabilities/nokeep.json +2 -2
- package/dist/capabilities/novita-ai.json +140 -140
- package/dist/capabilities/nvidia.json +35 -35
- package/dist/capabilities/oathbreaker.json +2 -2
- package/dist/capabilities/obscurify.json +31 -31
- package/dist/capabilities/oci.json +7 -7
- package/dist/capabilities/ofox.json +354 -354
- package/dist/capabilities/ollama-cloud.json +54 -54
- package/dist/capabilities/openai.json +53 -60
- package/dist/capabilities/opencode-go.json +89 -89
- package/dist/capabilities/openreason.json +5 -5
- package/dist/capabilities/openrouter.json +553 -553
- package/dist/capabilities/opper.json +28 -28
- package/dist/capabilities/orcarouter.json +248 -248
- package/dist/capabilities/outerlabs.json +32 -32
- package/dist/capabilities/ovhcloud.json +4 -4
- package/dist/capabilities/pareto.json +5 -5
- package/dist/capabilities/perplexity-agent.json +55 -55
- package/dist/capabilities/phala.json +33 -33
- package/dist/capabilities/pioneer.json +28 -28
- package/dist/capabilities/poe.json +121 -121
- package/dist/capabilities/poolside.json +3 -3
- package/dist/capabilities/powerspring.json +12 -12
- package/dist/capabilities/primalabs.json +9 -9
- package/dist/capabilities/prime.json +111 -111
- package/dist/capabilities/privatemode-ai.json +13 -13
- package/dist/capabilities/proxystacks.json +7 -7
- package/dist/capabilities/qiniu-ai.json +15 -15
- package/dist/capabilities/refuseless.json +10 -10
- package/dist/capabilities/regolo-ai.json +6 -6
- package/dist/capabilities/requesty.json +171 -188
- package/dist/capabilities/ruapi.json +19 -19
- package/dist/capabilities/runcrate.json +8 -8
- package/dist/capabilities/runinfra.json +13 -13
- package/dist/capabilities/sakana.json +6 -6
- package/dist/capabilities/sambanova.json +6 -6
- package/dist/capabilities/sandbase.json +25 -25
- package/dist/capabilities/sarvam.json +13 -13
- package/dist/capabilities/scaleway.json +20 -20
- package/dist/capabilities/scnet-token-plan.json +8 -8
- package/dist/capabilities/scx-ai.json +30 -30
- package/dist/capabilities/sensenova.json +13 -13
- package/dist/capabilities/siliconflow-cn.json +68 -68
- package/dist/capabilities/siliconflow.json +60 -60
- package/dist/capabilities/snowflake-cortex.json +20 -20
- package/dist/capabilities/sokkan.json +7 -7
- package/dist/capabilities/sparrowcodes.json +23 -23
- package/dist/capabilities/standardcompute.json +103 -103
- package/dist/capabilities/steadyrouter.json +36 -36
- package/dist/capabilities/stepfun-ai-step-plan.json +4 -4
- package/dist/capabilities/stepfun-ai.json +4 -4
- package/dist/capabilities/stepfun-step-plan.json +4 -4
- package/dist/capabilities/stepfun.json +4 -4
- package/dist/capabilities/stepping-stone.json +20 -20
- package/dist/capabilities/subconscious.json +2 -2
- package/dist/capabilities/superbot-gg.json +4 -4
- package/dist/capabilities/synthetic.json +11 -11
- package/dist/capabilities/synthorai.json +23 -23
- package/dist/capabilities/teamorouter.json +21 -21
- package/dist/capabilities/teapot-router.json +12 -12
- package/dist/capabilities/tencent-coding-plan.json +2 -2
- package/dist/capabilities/tencent-token-plan.json +24 -24
- package/dist/capabilities/tencent-tokenhub.json +6 -6
- package/dist/capabilities/tensorx.json +50 -50
- package/dist/capabilities/tenstorrent.json +5 -5
- package/dist/capabilities/the-grid-ai.json +28 -28
- package/dist/capabilities/thinkingmachines.json +60 -60
- package/dist/capabilities/tinfoil.json +14 -14
- package/dist/capabilities/toapis.json +3 -3
- package/dist/capabilities/togetherai.json +51 -51
- package/dist/capabilities/tokengo.json +16 -16
- package/dist/capabilities/tokenify.json +9 -9
- package/dist/capabilities/trustedrouter.json +7 -7
- package/dist/capabilities/trustedtokens.json +15 -15
- package/dist/capabilities/umans-ai-coding-plan.json +14 -14
- package/dist/capabilities/umans-ai.json +12 -12
- package/dist/capabilities/uncensuredai.json +5 -5
- package/dist/capabilities/unrestricted.json +8 -8
- package/dist/capabilities/uplinkswitch.json +19 -19
- package/dist/capabilities/upstage.json +4 -4
- package/dist/capabilities/vancine.json +21 -21
- package/dist/capabilities/vercel.json +551 -551
- package/dist/capabilities/vivgrid.json +85 -85
- package/dist/capabilities/volcengine-coding-plan.json +30 -30
- package/dist/capabilities/volcengine.json +36 -36
- package/dist/capabilities/vultr.json +31 -31
- package/dist/capabilities/wafer.ai.json +16 -16
- package/dist/capabilities/wallaby.json +5 -5
- package/dist/capabilities/wally.json +12 -12
- package/dist/capabilities/wandb.json +15 -15
- package/dist/capabilities/watt.json +23 -23
- package/dist/capabilities/xai.json +6 -6
- package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
- package/dist/capabilities/xiaomi-token-plan-cn.json +3 -3
- package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
- package/dist/capabilities/xiaomi.json +6 -6
- package/dist/capabilities/xpersona.json +13 -13
- package/dist/capabilities/xxapi.json +27 -27
- package/dist/capabilities/zai-coding-plan.json +10 -10
- package/dist/capabilities/zai.json +26 -26
- package/dist/capabilities/zenifra.json +28 -28
- package/dist/capabilities/zenmux.json +197 -197
- package/dist/capabilities/zerogpu.json +14 -14
- package/dist/capabilities/zhipuai-coding-plan.json +7 -7
- package/dist/capabilities/zhipuai.json +24 -24
- package/dist/capabilities/zro.json +7 -7
- package/dist/channels/agent-channels.d.ts +11 -0
- package/dist/channels/chat-tools.d.ts +156 -0
- package/dist/channels/index.cjs +7 -2
- package/dist/channels/index.d.ts +2 -0
- package/dist/channels/index.js +3 -3
- package/dist/{channels-C5DxhFRc.js → channels-Dx4jiXeK.js} +1 -1
- package/dist/{channels-B57qQolh.cjs → channels-q6qnuRNV.cjs} +1 -1
- package/dist/coding-agent/index.cjs +4 -4
- package/dist/coding-agent/index.js +4 -4
- package/dist/{constants-DaBkXs5H.cjs → constants-B9ZDvXZ4.cjs} +41 -0
- package/dist/{constants-BDHIyN28.js → constants-BmdTvEYN.js} +30 -1
- package/dist/datasets/index.cjs +2 -2
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1289 -1284
- package/dist/docs/references/reference-agents-agent.md +1 -1
- package/dist/docs/references/reference-agents-channels.md +34 -1
- package/dist/docs/references/reference-agents-durable-agent.md +26 -2
- package/dist/evals/index.cjs +2 -2
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +2 -2
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.js +1 -1
- package/dist/{filesystem-CUj0vclS.cjs → filesystem-B0AZrbj8.cjs} +1 -1
- package/dist/{filesystem-BBqrAmKK.js → filesystem-B3s0WRud.js} +1 -1
- package/dist/{filesystem-B_HACoLS.js → filesystem-B5X-5G0x.js} +1 -1
- package/dist/{filesystem-pZNvxjuW.cjs → filesystem-BDSpwBke.cjs} +1 -1
- package/dist/{filesystem-5Z777gYZ.js → filesystem-BsdkC311.js} +1 -1
- package/dist/{filesystem-BNHPgtjJ.cjs → filesystem-C-cyJfi1.cjs} +1 -1
- package/dist/{filesystem-U5o28b5w.cjs → filesystem-CEbD_77-.cjs} +1 -1
- package/dist/{filesystem-yHKEz2Pr.cjs → filesystem-CUAgLugE.cjs} +1 -1
- package/dist/{filesystem-Cb8iTPM-.js → filesystem-Cv79mHRk.js} +1 -1
- package/dist/{filesystem-DhiaddZe.cjs → filesystem-DsCQiBl2.cjs} +1 -1
- package/dist/{filesystem-DSYDB3ek.js → filesystem-DzM9pcQ8.js} +1 -1
- package/dist/{filesystem-gpIfFMed.js → filesystem-DzfqVTO_.js} +1 -1
- package/dist/{filesystem-versioned-CxbiSJF-.js → filesystem-versioned-Bijb_p9l.js} +44 -44
- package/dist/harness/index.cjs +2 -2
- package/dist/harness/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/knowledge/index.cjs +1 -1
- package/dist/knowledge/index.js +1 -1
- package/dist/llm/index.cjs +3 -3
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/provider-types.generated.d.ts +7744 -7747
- package/dist/{llm-ByskI6z3.cjs → llm-CsQuqKPc.cjs} +2 -2
- package/dist/{llm-B0VtQDgT.js → llm-DnXK3Pmw.js} +2 -2
- package/dist/loop/base-loop-builder.d.ts +60 -0
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +2 -2
- package/dist/loop/loop-builder.d.ts +10 -32
- package/dist/loop/workflows/agentic-execution/index.d.ts +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +1 -1
- package/dist/{manager-C2RGNH68.js → manager-BsghM-UL.js} +3 -3
- package/dist/{manager-BJKx4lQf.cjs → manager-DwFnIrI6.cjs} +3 -3
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-zUTq9ilk.js → mastra-B8i1UDZs.js} +51 -25
- package/dist/{mastra-FXCeC5rF.cjs → mastra-Cn5NC6Es.cjs} +51 -25
- package/dist/memory/index.cjs +2 -2
- package/dist/memory/index.js +2 -2
- package/dist/{model-BmTFNo62.cjs → model-CNPfry_X.cjs} +1 -1
- package/dist/{model-BTNRPDgQ.js → model-CsOcWMUt.js} +1 -1
- package/dist/{netlify-B_XdjYPY.cjs → netlify-C-83Fxus.cjs} +1 -1
- package/dist/{netlify-BCSVhO5q.js → netlify-C-OpNSGp.js} +1 -1
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/{output-helpers-RlvE2WPA.js → output-helpers-D4II19No.js} +45 -45
- package/dist/processor-provider/index.cjs +1 -1
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +2 -2
- package/dist/processors/index.js +2 -2
- package/dist/processors/processors/pii-detector.d.ts +1 -0
- package/dist/{provider-registry-D8O1G18A.cjs → provider-registry-9O-H9osy.cjs} +22407 -22407
- package/dist/{provider-registry-Ble43Wb4.js → provider-registry-RZ8EgSe8.js} +22407 -22407
- package/dist/provider-registry.json +22277 -22277
- package/dist/{registry-generator-BQ1noftK.cjs → registry-generator-DxCX-FiO.cjs} +1 -1
- package/dist/{registry-generator-D1Zslex6.js → registry-generator-e8sltJls.js} +1 -1
- package/dist/{rehydrate-BiA_HUJH.cjs → rehydrate-B-wrAN7C.cjs} +2 -2
- package/dist/{rehydrate-CgxEur9m.js → rehydrate-D3fPgJwp.js} +2 -2
- package/dist/relevance/index.cjs +2 -2
- package/dist/relevance/index.js +2 -2
- package/dist/{run-registry-aomba2_Z.cjs → run-registry-5_LQBGn_.cjs} +83635 -77661
- package/dist/{run-registry-BUFmc_78.js → run-registry-DC03XLeZ.js} +83435 -76843
- package/dist/{scheduler-BuivoTeD.js → scheduler-B-VZUvv_.js} +1 -1
- package/dist/{scheduler-COSuIH7R.cjs → scheduler-D00X03jQ.cjs} +1 -1
- package/dist/schedules/index.cjs +1 -1
- package/dist/schedules/index.js +1 -1
- package/dist/{schedules-Dmu9qOgc.js → schedules-DZfSx-7P.js} +94 -94
- package/dist/{signal-provider-CicwpNwY.cjs → signal-provider-BFAvh_AJ.cjs} +1 -1
- package/dist/{signal-provider-BOtSN-_0.js → signal-provider-BslnAjWG.js} +1 -1
- package/dist/signals/index.cjs +3 -3
- package/dist/signals/index.js +3 -3
- package/dist/{signals-6EBDPHQX.cjs → signals-B1JSj-Ew.cjs} +2 -2
- package/dist/{signals-BH__LS8Y.js → signals-De9VnwL2.js} +2 -2
- package/dist/skills/index.cjs +2 -2
- package/dist/skills/index.js +2 -2
- package/dist/{source-8qxr6KJv.cjs → source-DDwx-87N.cjs} +1 -1
- package/dist/{source-DRqDgbCv.js → source-Did_2XQc.js} +1 -1
- package/dist/{state-processor-BRk8t1OR.js → state-processor-B9kxpM53.js} +140 -140
- package/dist/{state-processor-Bfs9LkY8.cjs → state-processor-kRNZ38Nf.cjs} +139 -139
- package/dist/storage/constants.cjs +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/agents/index.cjs +1 -1
- package/dist/storage/domains/agents/index.js +1 -1
- package/dist/storage/domains/mcp-clients/index.cjs +1 -1
- package/dist/storage/domains/mcp-clients/index.js +1 -1
- package/dist/storage/domains/mcp-servers/index.cjs +1 -1
- package/dist/storage/domains/mcp-servers/index.js +1 -1
- package/dist/storage/domains/memory/base.d.ts +3 -1
- package/dist/storage/domains/memory/observational-memory-lifecycle.d.ts +1 -1
- package/dist/storage/domains/prompt-blocks/index.cjs +1 -1
- package/dist/storage/domains/prompt-blocks/index.js +1 -1
- package/dist/storage/domains/scorer-definitions/index.cjs +1 -1
- package/dist/storage/domains/scorer-definitions/index.js +1 -1
- package/dist/storage/domains/skills/index.cjs +1 -1
- package/dist/storage/domains/skills/index.js +1 -1
- package/dist/storage/domains/workspaces/index.cjs +1 -1
- package/dist/storage/domains/workspaces/index.js +1 -1
- package/dist/storage/index.cjs +12 -11
- package/dist/storage/index.js +12 -12
- package/dist/storage/types.d.ts +13 -0
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/{stream-DUrp3Fcy.cjs → stream-4aNIw_TQ.cjs} +1 -1
- package/dist/{stream-S_NC5v9e.js → stream-CJUm6EAH.js} +1 -1
- package/dist/test-utils/llm-mock.cjs +1 -1
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +1 -1
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/{tool-loop-agent-DU0BiemT.cjs → tool-loop-agent-Dn0QCB9n.cjs} +3 -3
- package/dist/{tool-loop-agent-BhCzpGfr.js → tool-loop-agent-FEEwHfmg.js} +3 -3
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/{utils-DYIai19q.js → utils-Bd_y1_a-.js} +1 -1
- package/dist/{utils-CeEt4K7t.cjs → utils-DY01hxVd.cjs} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{validate-BRikrNhF.js → validate-CX0yQo_q.js} +1 -1
- package/dist/{validate-BckgxuJ0.cjs → validate-CuB_1Zd3.cjs} +1 -1
- package/dist/vector/index.cjs +1 -1
- package/dist/vector/index.js +1 -1
- package/dist/worker/index.cjs +1 -1
- package/dist/worker/index.js +1 -1
- package/dist/{worker-Du5ybt5o.js → worker-B80xkcKG.js} +3 -3
- package/dist/{worker-D9WwmcJa.cjs → worker-CbaSmip-.cjs} +3 -3
- package/dist/{worker-DcBfwJqD.js → worker-DSEfMPmq.js} +3 -3
- package/dist/{worker-BfhUD77l.cjs → worker-GsGIxPMa.cjs} +3 -3
- package/dist/{workflow-jNWVBYDJ.js → workflow-CZHY_C85.js} +4 -4
- package/dist/{workflow-BWV5m9Mx.cjs → workflow-CnBPXTpv.cjs} +4 -4
- package/dist/workflows/builder/index.cjs +1 -1
- package/dist/workflows/builder/index.js +1 -1
- package/dist/workflows/evented/index.cjs +1 -1
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/workflow.d.ts +1 -1
- package/dist/workflows/index.cjs +6 -6
- package/dist/workflows/index.js +6 -6
- package/dist/workspace/index.cjs +2 -2
- package/dist/workspace/index.js +2 -2
- package/dist/{workspace-BQ2wZj5D.cjs → workspace-D2drutNg.cjs} +607 -607
- package/dist/{workspace-D7JRhn1Z.js → workspace-D7TIleIt.js} +609 -609
- package/dist/{workspace-skills-CGiXfKzA.js → workspace-skills-38OY32_b.js} +531 -531
- package/package.json +8 -8
- package/src/llm/model/provider-types.generated.d.ts +7744 -7747
- package/dist/agent/durable/evented-execution-engine.d.ts +0 -20
- package/dist/{filesystem-versioned-D-OCaYSl.cjs → filesystem-versioned-DZGyPbNC.cjs} +43 -43
- package/dist/{output-helpers-CncZ3y-g.cjs → output-helpers-JL-HeCbT.cjs} +44 -44
- package/dist/{schedules-qIHUKsj4.cjs → schedules-BZS8McF7.cjs} +93 -93
- 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-
|
|
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,168 +117,469 @@ 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
|
-
//
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
FILESYSTEM: {
|
|
137
|
-
READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file`,
|
|
138
|
-
WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file`,
|
|
139
|
-
EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file`,
|
|
140
|
-
LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files`,
|
|
141
|
-
DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
|
|
142
|
-
FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
|
|
143
|
-
MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
|
|
144
|
-
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`,
|
|
145
|
-
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`,
|
|
146
|
-
APPLY_PATCH: `${WORKSPACE_TOOLS_PREFIX}_apply_patch`
|
|
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
|
|
147
136
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
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
|
|
152
140
|
},
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
DOUBLE_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_double_click`,
|
|
157
|
-
RIGHT_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_right_click`,
|
|
158
|
-
MOVE_MOUSE: `${WORKSPACE_TOOLS_PREFIX}_computer_move_mouse`,
|
|
159
|
-
DRAG: `${WORKSPACE_TOOLS_PREFIX}_computer_drag`,
|
|
160
|
-
TYPE: `${WORKSPACE_TOOLS_PREFIX}_computer_type`,
|
|
161
|
-
PRESS_KEY: `${WORKSPACE_TOOLS_PREFIX}_computer_press_key`,
|
|
162
|
-
SCROLL: `${WORKSPACE_TOOLS_PREFIX}_computer_scroll`,
|
|
163
|
-
GET_SCREEN_INFO: `${WORKSPACE_TOOLS_PREFIX}_computer_get_screen_info`,
|
|
164
|
-
WAIT: `${WORKSPACE_TOOLS_PREFIX}_computer_wait`
|
|
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
|
|
165
144
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
145
|
+
{
|
|
146
|
+
pattern: /[\u0430-\u044F\u0451]/i,
|
|
147
|
+
averageCharsPerToken: 4
|
|
169
148
|
},
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
+
];
|
|
173
158
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @example
|
|
179
|
-
* ```typescript
|
|
180
|
-
* await callLifecycle(sandbox, 'start'); // calls sandbox._start() ?? sandbox.start()
|
|
181
|
-
* await callLifecycle(filesystem, 'init'); // calls filesystem._init() ?? filesystem.init()
|
|
182
|
-
* ```
|
|
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).
|
|
183
162
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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++;
|
|
190
200
|
}
|
|
201
|
+
return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
|
|
191
202
|
}
|
|
192
|
-
// src/workspace/filesystem/composite-filesystem.ts
|
|
193
203
|
/**
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* Creates a unified filesystem view by combining multiple filesystems at different
|
|
197
|
-
* mount points. Useful for composing local storage, S3, and other backends.
|
|
198
|
-
*
|
|
199
|
-
* @example
|
|
200
|
-
* ```typescript
|
|
201
|
-
* const cfs = new CompositeFilesystem({
|
|
202
|
-
* mounts: {
|
|
203
|
-
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
204
|
-
* '/s3': new S3Filesystem({ bucket: 'my-bucket', ... }),
|
|
205
|
-
* }
|
|
206
|
-
* });
|
|
207
|
-
*
|
|
208
|
-
* // readdir('/') returns ['local', 's3']
|
|
209
|
-
* // readFile('/local/file.txt') reads from LocalFilesystem
|
|
210
|
-
* // readFile('/s3/data.json') reads from S3Filesystem
|
|
211
|
-
* ```
|
|
204
|
+
* Estimates the number of tokens in a text string using heuristic rules
|
|
212
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
|
+
}
|
|
213
212
|
/**
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* Routes file operations to the appropriate underlying filesystem based on path.
|
|
217
|
-
* Supports cross-mount operations (copy/move between different filesystems).
|
|
218
|
-
*
|
|
219
|
-
* The generic parameter preserves the concrete types of mounted filesystems,
|
|
220
|
-
* enabling typed access via `mounts.get()`.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* ```typescript
|
|
224
|
-
* const cfs = new CompositeFilesystem({
|
|
225
|
-
* mounts: {
|
|
226
|
-
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
227
|
-
* '/s3': new S3Filesystem({ bucket: 'my-bucket' }),
|
|
228
|
-
* },
|
|
229
|
-
* });
|
|
230
|
-
*
|
|
231
|
-
* cfs.mounts.get('/local') // LocalFilesystem
|
|
232
|
-
* cfs.mounts.get('/s3') // S3Filesystem
|
|
233
|
-
* ```
|
|
213
|
+
* Extracts a portion of text based on token positions, similar to Array.prototype.slice()
|
|
234
214
|
*/
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.id = `cfs-${Date.now().toString(36)}`;
|
|
244
|
-
this._mounts = /* @__PURE__ */ new Map();
|
|
245
|
-
for (const [path, fs] of Object.entries(config.mounts)) {
|
|
246
|
-
const normalized = this.normalizePath(path);
|
|
247
|
-
this._mounts.set(normalized, fs);
|
|
248
|
-
}
|
|
249
|
-
if (this._mounts.size === 0) throw new Error("CompositeFilesystem requires at least one mount");
|
|
250
|
-
this.readOnly = [...this._mounts.values()].every((fs) => fs.readOnly) || void 0;
|
|
251
|
-
const mountPaths = [...this._mounts.keys()];
|
|
252
|
-
for (const a of mountPaths) for (const b of mountPaths) if (a !== b && b.startsWith(a + "/")) throw new Error(`Nested mount paths are not supported: "${b}" is nested under "${a}"`);
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Get all mount paths.
|
|
256
|
-
*/
|
|
257
|
-
get mountPaths() {
|
|
258
|
-
return Array.from(this._mounts.keys());
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Get the mounts map.
|
|
262
|
-
* Returns a typed map where `get()` preserves the concrete filesystem type per mount path.
|
|
263
|
-
*/
|
|
264
|
-
get mounts() {
|
|
265
|
-
return this._mounts;
|
|
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;
|
|
266
223
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
+
};
|
|
421
|
+
// src/workspace/constants/index.ts
|
|
422
|
+
const WORKSPACE_TOOLS_PREFIX = "mastra_workspace";
|
|
423
|
+
/**
|
|
424
|
+
* Workspace tool name constants.
|
|
425
|
+
* Use these to reference workspace tools by name.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* import { WORKSPACE_TOOLS } from '@mastra/core/workspace';
|
|
430
|
+
*
|
|
431
|
+
* if (toolName === WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND) {
|
|
432
|
+
* // Handle sandbox execution
|
|
433
|
+
* }
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
const WORKSPACE_TOOLS = {
|
|
437
|
+
FILESYSTEM: {
|
|
438
|
+
READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file`,
|
|
439
|
+
WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file`,
|
|
440
|
+
EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file`,
|
|
441
|
+
LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files`,
|
|
442
|
+
DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
|
|
443
|
+
FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
|
|
444
|
+
MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
|
|
445
|
+
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`,
|
|
446
|
+
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`,
|
|
447
|
+
APPLY_PATCH: `${WORKSPACE_TOOLS_PREFIX}_apply_patch`
|
|
448
|
+
},
|
|
449
|
+
SANDBOX: {
|
|
450
|
+
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`,
|
|
451
|
+
GET_PROCESS_OUTPUT: `${WORKSPACE_TOOLS_PREFIX}_get_process_output`,
|
|
452
|
+
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
453
|
+
},
|
|
454
|
+
COMPUTER: {
|
|
455
|
+
SCREENSHOT: `${WORKSPACE_TOOLS_PREFIX}_computer_screenshot`,
|
|
456
|
+
CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_click`,
|
|
457
|
+
DOUBLE_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_double_click`,
|
|
458
|
+
RIGHT_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_right_click`,
|
|
459
|
+
MOVE_MOUSE: `${WORKSPACE_TOOLS_PREFIX}_computer_move_mouse`,
|
|
460
|
+
DRAG: `${WORKSPACE_TOOLS_PREFIX}_computer_drag`,
|
|
461
|
+
TYPE: `${WORKSPACE_TOOLS_PREFIX}_computer_type`,
|
|
462
|
+
PRESS_KEY: `${WORKSPACE_TOOLS_PREFIX}_computer_press_key`,
|
|
463
|
+
SCROLL: `${WORKSPACE_TOOLS_PREFIX}_computer_scroll`,
|
|
464
|
+
GET_SCREEN_INFO: `${WORKSPACE_TOOLS_PREFIX}_computer_get_screen_info`,
|
|
465
|
+
WAIT: `${WORKSPACE_TOOLS_PREFIX}_computer_wait`
|
|
466
|
+
},
|
|
467
|
+
SEARCH: {
|
|
468
|
+
SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
|
|
469
|
+
INDEX: `${WORKSPACE_TOOLS_PREFIX}_index`
|
|
470
|
+
},
|
|
471
|
+
LSP: { LSP_INSPECT: `${WORKSPACE_TOOLS_PREFIX}_lsp_inspect` }
|
|
472
|
+
};
|
|
473
|
+
// src/workspace/lifecycle.ts
|
|
474
|
+
/**
|
|
475
|
+
* Call a lifecycle method on a provider, preferring the `_`-prefixed wrapper
|
|
476
|
+
* (which adds status tracking & race-condition safety) when available,
|
|
477
|
+
* falling back to the plain method for interface-only implementations.
|
|
478
|
+
*
|
|
479
|
+
* @example
|
|
480
|
+
* ```typescript
|
|
481
|
+
* await callLifecycle(sandbox, 'start'); // calls sandbox._start() ?? sandbox.start()
|
|
482
|
+
* await callLifecycle(filesystem, 'init'); // calls filesystem._init() ?? filesystem.init()
|
|
483
|
+
* ```
|
|
484
|
+
*/
|
|
485
|
+
async function callLifecycle(provider, method) {
|
|
486
|
+
const wrappedFn = provider[`_${method}`];
|
|
487
|
+
if (typeof wrappedFn === "function") await wrappedFn.call(provider);
|
|
488
|
+
else {
|
|
489
|
+
const plainFn = provider[method];
|
|
490
|
+
if (typeof plainFn === "function") await plainFn.call(provider);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
// src/workspace/filesystem/composite-filesystem.ts
|
|
494
|
+
/**
|
|
495
|
+
* CompositeFilesystem - Routes operations to mounted filesystems based on path.
|
|
496
|
+
*
|
|
497
|
+
* Creates a unified filesystem view by combining multiple filesystems at different
|
|
498
|
+
* mount points. Useful for composing local storage, S3, and other backends.
|
|
499
|
+
*
|
|
500
|
+
* @example
|
|
501
|
+
* ```typescript
|
|
502
|
+
* const cfs = new CompositeFilesystem({
|
|
503
|
+
* mounts: {
|
|
504
|
+
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
505
|
+
* '/s3': new S3Filesystem({ bucket: 'my-bucket', ... }),
|
|
506
|
+
* }
|
|
507
|
+
* });
|
|
508
|
+
*
|
|
509
|
+
* // readdir('/') returns ['local', 's3']
|
|
510
|
+
* // readFile('/local/file.txt') reads from LocalFilesystem
|
|
511
|
+
* // readFile('/s3/data.json') reads from S3Filesystem
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
/**
|
|
515
|
+
* CompositeFilesystem implementation.
|
|
516
|
+
*
|
|
517
|
+
* Routes file operations to the appropriate underlying filesystem based on path.
|
|
518
|
+
* Supports cross-mount operations (copy/move between different filesystems).
|
|
519
|
+
*
|
|
520
|
+
* The generic parameter preserves the concrete types of mounted filesystems,
|
|
521
|
+
* enabling typed access via `mounts.get()`.
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```typescript
|
|
525
|
+
* const cfs = new CompositeFilesystem({
|
|
526
|
+
* mounts: {
|
|
527
|
+
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
528
|
+
* '/s3': new S3Filesystem({ bucket: 'my-bucket' }),
|
|
529
|
+
* },
|
|
530
|
+
* });
|
|
531
|
+
*
|
|
532
|
+
* cfs.mounts.get('/local') // LocalFilesystem
|
|
533
|
+
* cfs.mounts.get('/s3') // S3Filesystem
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
var CompositeFilesystem = class {
|
|
537
|
+
id;
|
|
538
|
+
name = "CompositeFilesystem";
|
|
539
|
+
provider = "composite";
|
|
540
|
+
readOnly;
|
|
541
|
+
status = "ready";
|
|
542
|
+
_mounts;
|
|
543
|
+
constructor(config) {
|
|
544
|
+
this.id = `cfs-${Date.now().toString(36)}`;
|
|
545
|
+
this._mounts = /* @__PURE__ */ new Map();
|
|
546
|
+
for (const [path, fs] of Object.entries(config.mounts)) {
|
|
547
|
+
const normalized = this.normalizePath(path);
|
|
548
|
+
this._mounts.set(normalized, fs);
|
|
549
|
+
}
|
|
550
|
+
if (this._mounts.size === 0) throw new Error("CompositeFilesystem requires at least one mount");
|
|
551
|
+
this.readOnly = [...this._mounts.values()].every((fs) => fs.readOnly) || void 0;
|
|
552
|
+
const mountPaths = [...this._mounts.keys()];
|
|
553
|
+
for (const a of mountPaths) for (const b of mountPaths) if (a !== b && b.startsWith(a + "/")) throw new Error(`Nested mount paths are not supported: "${b}" is nested under "${a}"`);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Get all mount paths.
|
|
557
|
+
*/
|
|
558
|
+
get mountPaths() {
|
|
559
|
+
return Array.from(this._mounts.keys());
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Get the mounts map.
|
|
563
|
+
* Returns a typed map where `get()` preserves the concrete filesystem type per mount path.
|
|
564
|
+
*/
|
|
565
|
+
get mounts() {
|
|
566
|
+
return this._mounts;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Get status and metadata for this composite filesystem.
|
|
570
|
+
* Includes info from each mounted filesystem in `metadata.mounts`.
|
|
571
|
+
*/
|
|
572
|
+
async getInfo() {
|
|
573
|
+
const mounts = {};
|
|
574
|
+
for (const [mountPath, fs] of this._mounts) mounts[mountPath] = await fs.getInfo?.() ?? null;
|
|
575
|
+
return {
|
|
576
|
+
id: this.id,
|
|
577
|
+
name: this.name,
|
|
578
|
+
provider: this.provider,
|
|
579
|
+
status: this.status,
|
|
580
|
+
readOnly: this.readOnly,
|
|
581
|
+
metadata: { mounts }
|
|
582
|
+
};
|
|
282
583
|
}
|
|
283
584
|
/**
|
|
284
585
|
* Get the underlying filesystem for a given path.
|
|
@@ -5784,106 +6085,15 @@ const computerPressKeyTool = require_tool.createTool({
|
|
|
5784
6085
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5785
6086
|
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY);
|
|
5786
6087
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5787
|
-
category: "computer",
|
|
5788
|
-
operation: "pressKey",
|
|
5789
|
-
input: { key },
|
|
5790
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5791
|
-
});
|
|
5792
|
-
try {
|
|
5793
|
-
await computer.press(key);
|
|
5794
|
-
const label = Array.isArray(key) ? key.join("+") : key;
|
|
5795
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY, `Pressed ${label}`);
|
|
5796
|
-
span.end({ success: true });
|
|
5797
|
-
return result;
|
|
5798
|
-
} catch (err) {
|
|
5799
|
-
span.error(err);
|
|
5800
|
-
throw err;
|
|
5801
|
-
}
|
|
5802
|
-
},
|
|
5803
|
-
toModelOutput: mediaToModelOutput
|
|
5804
|
-
});
|
|
5805
|
-
// src/workspace/tools/computer-right-click.ts
|
|
5806
|
-
const computerRightClickTool = require_tool.createTool({
|
|
5807
|
-
id: WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK,
|
|
5808
|
-
description: "Right-click at pixel coordinates on the sandbox desktop. Use for opening context menus.",
|
|
5809
|
-
inputSchema: zod_v4.z.object({
|
|
5810
|
-
x: zod_v4.z.number().int().min(0).describe("X coordinate in pixels from the left edge of the screen"),
|
|
5811
|
-
y: zod_v4.z.number().int().min(0).describe("Y coordinate in pixels from the top edge of the screen")
|
|
5812
|
-
}),
|
|
5813
|
-
execute: async ({ x, y }, context) => {
|
|
5814
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5815
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK);
|
|
5816
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5817
|
-
category: "computer",
|
|
5818
|
-
operation: "rightClick",
|
|
5819
|
-
input: {
|
|
5820
|
-
x,
|
|
5821
|
-
y
|
|
5822
|
-
},
|
|
5823
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5824
|
-
});
|
|
5825
|
-
try {
|
|
5826
|
-
await computer.rightClick(x, y);
|
|
5827
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK, `Right-clicked at (${x}, ${y})`);
|
|
5828
|
-
span.end({ success: true });
|
|
5829
|
-
return result;
|
|
5830
|
-
} catch (err) {
|
|
5831
|
-
span.error(err);
|
|
5832
|
-
throw err;
|
|
5833
|
-
}
|
|
5834
|
-
},
|
|
5835
|
-
toModelOutput: mediaToModelOutput
|
|
5836
|
-
});
|
|
5837
|
-
// src/workspace/tools/computer-screenshot.ts
|
|
5838
|
-
const computerScreenshotTool = require_tool.createTool({
|
|
5839
|
-
id: WORKSPACE_TOOLS.COMPUTER.SCREENSHOT,
|
|
5840
|
-
description: "Take a screenshot of the sandbox desktop display. Returns the current screen as an image. Use this to see the desktop state before and after interacting with it.",
|
|
5841
|
-
inputSchema: zod_v4.z.object({}),
|
|
5842
|
-
execute: async (_input, context) => {
|
|
5843
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5844
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT);
|
|
5845
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5846
|
-
category: "computer",
|
|
5847
|
-
operation: "screenshot",
|
|
5848
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5849
|
-
});
|
|
5850
|
-
try {
|
|
5851
|
-
const screenshot = await computer.screenshot();
|
|
5852
|
-
const maxMediaBytes = getComputerToolConfig(workspace, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT)?.maxMediaBytes ?? 10485760;
|
|
5853
|
-
const result = screenshotToResult(screenshot, `Screenshot of the desktop (${screenshot.data.byteLength} bytes, ${screenshot.mediaType})`, maxMediaBytes);
|
|
5854
|
-
span.end({ success: true }, { bytesTransferred: screenshot.data.byteLength });
|
|
5855
|
-
return result;
|
|
5856
|
-
} catch (err) {
|
|
5857
|
-
span.error(err);
|
|
5858
|
-
throw err;
|
|
5859
|
-
}
|
|
5860
|
-
},
|
|
5861
|
-
toModelOutput: mediaToModelOutput
|
|
5862
|
-
});
|
|
5863
|
-
// src/workspace/tools/computer-scroll.ts
|
|
5864
|
-
const computerScrollTool = require_tool.createTool({
|
|
5865
|
-
id: WORKSPACE_TOOLS.COMPUTER.SCROLL,
|
|
5866
|
-
description: "Scroll the sandbox desktop display up or down.",
|
|
5867
|
-
inputSchema: zod_v4.z.object({
|
|
5868
|
-
direction: zod_v4.z.enum(["up", "down"]).describe("Scroll direction"),
|
|
5869
|
-
amount: zod_v4.z.number().int().min(1).optional().describe("Scroll amount in ticks (default: 3)")
|
|
5870
|
-
}),
|
|
5871
|
-
execute: async ({ direction, amount }, context) => {
|
|
5872
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5873
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCROLL);
|
|
5874
|
-
const effectiveAmount = amount ?? 3;
|
|
5875
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5876
|
-
category: "computer",
|
|
5877
|
-
operation: "scroll",
|
|
5878
|
-
input: {
|
|
5879
|
-
direction,
|
|
5880
|
-
amount: effectiveAmount
|
|
5881
|
-
},
|
|
6088
|
+
category: "computer",
|
|
6089
|
+
operation: "pressKey",
|
|
6090
|
+
input: { key },
|
|
5882
6091
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5883
6092
|
});
|
|
5884
6093
|
try {
|
|
5885
|
-
await computer.
|
|
5886
|
-
const
|
|
6094
|
+
await computer.press(key);
|
|
6095
|
+
const label = Array.isArray(key) ? key.join("+") : key;
|
|
6096
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY, `Pressed ${label}`);
|
|
5887
6097
|
span.end({ success: true });
|
|
5888
6098
|
return result;
|
|
5889
6099
|
} catch (err) {
|
|
@@ -5893,23 +6103,29 @@ const computerScrollTool = require_tool.createTool({
|
|
|
5893
6103
|
},
|
|
5894
6104
|
toModelOutput: mediaToModelOutput
|
|
5895
6105
|
});
|
|
5896
|
-
// src/workspace/tools/computer-
|
|
5897
|
-
const
|
|
5898
|
-
id: WORKSPACE_TOOLS.COMPUTER.
|
|
5899
|
-
description: "
|
|
5900
|
-
inputSchema: zod_v4.z.object({
|
|
5901
|
-
|
|
6106
|
+
// src/workspace/tools/computer-right-click.ts
|
|
6107
|
+
const computerRightClickTool = require_tool.createTool({
|
|
6108
|
+
id: WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK,
|
|
6109
|
+
description: "Right-click at pixel coordinates on the sandbox desktop. Use for opening context menus.",
|
|
6110
|
+
inputSchema: zod_v4.z.object({
|
|
6111
|
+
x: zod_v4.z.number().int().min(0).describe("X coordinate in pixels from the left edge of the screen"),
|
|
6112
|
+
y: zod_v4.z.number().int().min(0).describe("Y coordinate in pixels from the top edge of the screen")
|
|
6113
|
+
}),
|
|
6114
|
+
execute: async ({ x, y }, context) => {
|
|
5902
6115
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5903
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.
|
|
6116
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK);
|
|
5904
6117
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5905
6118
|
category: "computer",
|
|
5906
|
-
operation: "
|
|
5907
|
-
input: {
|
|
6119
|
+
operation: "rightClick",
|
|
6120
|
+
input: {
|
|
6121
|
+
x,
|
|
6122
|
+
y
|
|
6123
|
+
},
|
|
5908
6124
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5909
6125
|
});
|
|
5910
6126
|
try {
|
|
5911
|
-
await computer.
|
|
5912
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.
|
|
6127
|
+
await computer.rightClick(x, y);
|
|
6128
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK, `Right-clicked at (${x}, ${y})`);
|
|
5913
6129
|
span.end({ success: true });
|
|
5914
6130
|
return result;
|
|
5915
6131
|
} catch (err) {
|
|
@@ -5919,24 +6135,24 @@ const computerTypeTool = require_tool.createTool({
|
|
|
5919
6135
|
},
|
|
5920
6136
|
toModelOutput: mediaToModelOutput
|
|
5921
6137
|
});
|
|
5922
|
-
// src/workspace/tools/computer-
|
|
5923
|
-
const
|
|
5924
|
-
id: WORKSPACE_TOOLS.COMPUTER.
|
|
5925
|
-
description: "
|
|
5926
|
-
inputSchema: zod_v4.z.object({
|
|
5927
|
-
execute: async (
|
|
6138
|
+
// src/workspace/tools/computer-screenshot.ts
|
|
6139
|
+
const computerScreenshotTool = require_tool.createTool({
|
|
6140
|
+
id: WORKSPACE_TOOLS.COMPUTER.SCREENSHOT,
|
|
6141
|
+
description: "Take a screenshot of the sandbox desktop display. Returns the current screen as an image. Use this to see the desktop state before and after interacting with it.",
|
|
6142
|
+
inputSchema: zod_v4.z.object({}),
|
|
6143
|
+
execute: async (_input, context) => {
|
|
5928
6144
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5929
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.
|
|
6145
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT);
|
|
5930
6146
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5931
6147
|
category: "computer",
|
|
5932
|
-
operation: "
|
|
5933
|
-
input: { seconds },
|
|
6148
|
+
operation: "screenshot",
|
|
5934
6149
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5935
6150
|
});
|
|
5936
6151
|
try {
|
|
5937
|
-
|
|
5938
|
-
const
|
|
5939
|
-
|
|
6152
|
+
const screenshot = await computer.screenshot();
|
|
6153
|
+
const maxMediaBytes = getComputerToolConfig(workspace, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT)?.maxMediaBytes ?? 10485760;
|
|
6154
|
+
const result = screenshotToResult(screenshot, `Screenshot of the desktop (${screenshot.data.byteLength} bytes, ${screenshot.mediaType})`, maxMediaBytes);
|
|
6155
|
+
span.end({ success: true }, { bytesTransferred: screenshot.data.byteLength });
|
|
5940
6156
|
return result;
|
|
5941
6157
|
} catch (err) {
|
|
5942
6158
|
span.error(err);
|
|
@@ -5945,199 +6161,127 @@ const computerWaitTool = require_tool.createTool({
|
|
|
5945
6161
|
},
|
|
5946
6162
|
toModelOutput: mediaToModelOutput
|
|
5947
6163
|
});
|
|
5948
|
-
// src/workspace/tools/
|
|
5949
|
-
const
|
|
5950
|
-
id: WORKSPACE_TOOLS.
|
|
5951
|
-
description: "
|
|
5952
|
-
outputSchema: zod_v4.z.string(),
|
|
6164
|
+
// src/workspace/tools/computer-scroll.ts
|
|
6165
|
+
const computerScrollTool = require_tool.createTool({
|
|
6166
|
+
id: WORKSPACE_TOOLS.COMPUTER.SCROLL,
|
|
6167
|
+
description: "Scroll the sandbox desktop display up or down.",
|
|
5953
6168
|
inputSchema: zod_v4.z.object({
|
|
5954
|
-
|
|
5955
|
-
|
|
6169
|
+
direction: zod_v4.z.enum(["up", "down"]).describe("Scroll direction"),
|
|
6170
|
+
amount: zod_v4.z.number().int().min(1).optional().describe("Scroll amount in ticks (default: 3)")
|
|
5956
6171
|
}),
|
|
5957
|
-
execute: async ({
|
|
5958
|
-
const { workspace,
|
|
5959
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.
|
|
5960
|
-
const
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
span.
|
|
5977
|
-
|
|
5978
|
-
}
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
}
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
}
|
|
6014
|
-
}
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
})
|
|
6043
|
-
}
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
|
|
6052
|
-
|
|
6053
|
-
|
|
6054
|
-
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
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";
|
|
6172
|
+
execute: async ({ direction, amount }, context) => {
|
|
6173
|
+
const { workspace, sandbox, computer } = requireComputer(context);
|
|
6174
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCROLL);
|
|
6175
|
+
const effectiveAmount = amount ?? 3;
|
|
6176
|
+
const span = startWorkspaceSpan(context, workspace, {
|
|
6177
|
+
category: "computer",
|
|
6178
|
+
operation: "scroll",
|
|
6179
|
+
input: {
|
|
6180
|
+
direction,
|
|
6181
|
+
amount: effectiveAmount
|
|
6182
|
+
},
|
|
6183
|
+
attributes: { sandboxProvider: sandbox.provider }
|
|
6184
|
+
});
|
|
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;
|