@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,5 +1,5 @@
|
|
|
1
1
|
import { _ as WorkspaceError, a as FileReadRequiredError, b as WorkspaceReadOnlyError, c as FilesystemNotReadyError, d as PermissionError, f as SandboxFeatureNotSupportedError, g as UnsupportedGrepPatternError, h as StaleFileError, i as FileNotFoundError, l as IsDirectoryError, m as SearchNotAvailableError, n as DirectoryNotFoundError, o as FilesystemError, p as SandboxNotAvailableError, r as FileExistsError, s as FilesystemNotAvailableError, t as DirectoryNotEmptyError, u as NotDirectoryError, v as WorkspaceNotAvailableError, y as WorkspaceNotReadyError } from "./errors-CzFYpCHw.js";
|
|
2
|
-
import { C as
|
|
2
|
+
import { C as isEnotdirError, E as resolveToBasePath, S as isEnoentError, T as normalizeTextExtension, _ as expandTilde, a as extractSkillFrontmatter, b as getMimeType, d as splitIntoChunks, f as createGlobMatcher, g as resolvePathPattern, l as LocalSkillSource, m as isGlobPattern, n as SKILL_SCOPE_DOCUMENT_PREFIX, p as extractGlobBase, r as WorkspaceSkillsImpl, t as ResolvedSourceWorkspaceSkills, u as SearchEngine, v as fsExists, w as isTextFile, x as isEexistError, y as fsStat } from "./workspace-skills-38OY32_b.js";
|
|
3
3
|
import { t as MastraBase } from "./base-CKLWBhDo.js";
|
|
4
4
|
import { a as RegisteredLogger } from "./logger-BwbmRqfc.js";
|
|
5
5
|
import { u as RequestContext } from "./request-context-COnZHt2-.js";
|
|
@@ -14,10 +14,10 @@ import { constants, existsSync, lstatSync, readFileSync, readlinkSync, realpathS
|
|
|
14
14
|
import os, * as os$1 from "os";
|
|
15
15
|
import * as nodePath from "path";
|
|
16
16
|
import path, { dirname, join, parse, posix } from "path";
|
|
17
|
-
import posixPath from "path/posix";
|
|
18
17
|
import fs$1, * as fs$2 from "fs/promises";
|
|
19
|
-
import { execFileSync } from "child_process";
|
|
20
18
|
import { fileURLToPath, pathToFileURL } from "url";
|
|
19
|
+
import { execFileSync } from "child_process";
|
|
20
|
+
import posixPath from "path/posix";
|
|
21
21
|
import ignore from "ignore";
|
|
22
22
|
// src/workspace/sandbox/utils.ts
|
|
23
23
|
/**
|
|
@@ -112,171 +112,472 @@ function reassembleShellCommand(parts, operators) {
|
|
|
112
112
|
for (let i = 0; i < operators.length; i++) result += ` ${operators[i]} ${parts[i + 1] ?? ""}`;
|
|
113
113
|
return result.trim();
|
|
114
114
|
}
|
|
115
|
-
//
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
FILESYSTEM: {
|
|
132
|
-
READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file`,
|
|
133
|
-
WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file`,
|
|
134
|
-
EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file`,
|
|
135
|
-
LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files`,
|
|
136
|
-
DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
|
|
137
|
-
FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
|
|
138
|
-
MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
|
|
139
|
-
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`,
|
|
140
|
-
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`,
|
|
141
|
-
APPLY_PATCH: `${WORKSPACE_TOOLS_PREFIX}_apply_patch`
|
|
115
|
+
// ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
|
|
116
|
+
const PATTERNS = {
|
|
117
|
+
whitespace: /^\s+$/,
|
|
118
|
+
structuredWhitespace: /\n\s/,
|
|
119
|
+
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]/,
|
|
120
|
+
numeric: /^\d+$/,
|
|
121
|
+
punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_"-]/
|
|
122
|
+
};
|
|
123
|
+
const TOKEN_SPLIT_PATTERN = new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
|
|
124
|
+
const DEFAULT_CHARS_PER_TOKEN = 6;
|
|
125
|
+
const SHORT_TOKEN_THRESHOLD = 3;
|
|
126
|
+
const KANA_CHARS_PER_TOKEN = 1.35;
|
|
127
|
+
const DEFAULT_LANGUAGE_CONFIGS = [
|
|
128
|
+
{
|
|
129
|
+
pattern: /[\u00E4\u00F6\u00FC\u00DF\u1E9E]/i,
|
|
130
|
+
averageCharsPerToken: 2.6
|
|
142
131
|
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
132
|
+
{
|
|
133
|
+
pattern: /[\u00E9\u00E8\u00EA\u00EB\u00E0\u00E2\u00EE\u00EF\u00F4\u00FB\u00F9\u00FC\u00FF\u00E7\u0153\u00E6\u00E1\u00ED\u00F3\u00FA\u00F1]/i,
|
|
134
|
+
averageCharsPerToken: 3
|
|
147
135
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
DOUBLE_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_double_click`,
|
|
152
|
-
RIGHT_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_right_click`,
|
|
153
|
-
MOVE_MOUSE: `${WORKSPACE_TOOLS_PREFIX}_computer_move_mouse`,
|
|
154
|
-
DRAG: `${WORKSPACE_TOOLS_PREFIX}_computer_drag`,
|
|
155
|
-
TYPE: `${WORKSPACE_TOOLS_PREFIX}_computer_type`,
|
|
156
|
-
PRESS_KEY: `${WORKSPACE_TOOLS_PREFIX}_computer_press_key`,
|
|
157
|
-
SCROLL: `${WORKSPACE_TOOLS_PREFIX}_computer_scroll`,
|
|
158
|
-
GET_SCREEN_INFO: `${WORKSPACE_TOOLS_PREFIX}_computer_get_screen_info`,
|
|
159
|
-
WAIT: `${WORKSPACE_TOOLS_PREFIX}_computer_wait`
|
|
136
|
+
{
|
|
137
|
+
pattern: /[\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u011B\u0161\u010D\u0159\u017E\u00FD\u016F\u00FA\u010F\u0165\u0148]/i,
|
|
138
|
+
averageCharsPerToken: 2.5
|
|
160
139
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
140
|
+
{
|
|
141
|
+
pattern: /[\u0430-\u044F\u0451]/i,
|
|
142
|
+
averageCharsPerToken: 4
|
|
164
143
|
},
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
144
|
+
{
|
|
145
|
+
pattern: /[\u03AC-\u03CE]/i,
|
|
146
|
+
averageCharsPerToken: 2.75
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
pattern: /^\p{Extended_Pictographic}[\p{Extended_Pictographic}\p{Emoji_Component}]*$/u,
|
|
150
|
+
averageCharsPerToken: .75
|
|
151
|
+
}
|
|
152
|
+
];
|
|
168
153
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* await callLifecycle(sandbox, 'start'); // calls sandbox._start() ?? sandbox.start()
|
|
176
|
-
* await callLifecycle(filesystem, 'init'); // calls filesystem._init() ?? filesystem.init()
|
|
177
|
-
* ```
|
|
154
|
+
* Walks a text as (segment, estimated token count) pairs. The segments
|
|
155
|
+
* concatenate back to the original text; whitespace segments count zero
|
|
156
|
+
* tokens unless they carry structure (indentation or blank lines).
|
|
178
157
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
function* walkSegments(text, options = {}) {
|
|
159
|
+
if (!text) return;
|
|
160
|
+
const resolvedOptions = resolveOptions(options);
|
|
161
|
+
for (const segment of text.split(TOKEN_SPLIT_PATTERN)) if (segment) yield {
|
|
162
|
+
segment,
|
|
163
|
+
tokenCount: estimateSegmentTokens(segment, resolvedOptions)
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function resolveOptions(options) {
|
|
167
|
+
return {
|
|
168
|
+
defaultCharsPerToken: options.defaultCharsPerToken ?? DEFAULT_CHARS_PER_TOKEN,
|
|
169
|
+
languageConfigs: options.languageConfigs ?? DEFAULT_LANGUAGE_CONFIGS
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function estimateSegmentTokens(segment, { languageConfigs, defaultCharsPerToken }) {
|
|
173
|
+
if (PATTERNS.whitespace.test(segment)) return PATTERNS.structuredWhitespace.test(segment) ? 1 : 0;
|
|
174
|
+
const languageCharsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs);
|
|
175
|
+
if (languageCharsPerToken !== void 0) return Math.ceil(getCharacterCount(segment) / languageCharsPerToken);
|
|
176
|
+
if (PATTERNS.cjk.test(segment)) return estimateCjkTokens(segment);
|
|
177
|
+
if (PATTERNS.numeric.test(segment)) return Math.ceil(segment.length / 3);
|
|
178
|
+
if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
|
|
179
|
+
if (PATTERNS.punctuation.test(segment)) return Math.ceil(segment.length / 2);
|
|
180
|
+
return Math.ceil(segment.length / defaultCharsPerToken);
|
|
181
|
+
}
|
|
182
|
+
function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
|
|
183
|
+
for (const config of languageConfigs) if (segment.search(config.pattern) !== -1) return config.averageCharsPerToken;
|
|
184
|
+
}
|
|
185
|
+
function getCharacterCount(text) {
|
|
186
|
+
return Array.from(text).length;
|
|
187
|
+
}
|
|
188
|
+
function estimateCjkTokens(segment) {
|
|
189
|
+
let kanaCount = 0;
|
|
190
|
+
let otherCount = 0;
|
|
191
|
+
for (const character of segment) {
|
|
192
|
+
const codePoint = character.codePointAt(0);
|
|
193
|
+
if (codePoint >= 12352 && codePoint <= 12543) kanaCount++;
|
|
194
|
+
else otherCount++;
|
|
185
195
|
}
|
|
196
|
+
return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
|
|
186
197
|
}
|
|
187
|
-
// src/workspace/filesystem/composite-filesystem.ts
|
|
188
198
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* Creates a unified filesystem view by combining multiple filesystems at different
|
|
192
|
-
* mount points. Useful for composing local storage, S3, and other backends.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```typescript
|
|
196
|
-
* const cfs = new CompositeFilesystem({
|
|
197
|
-
* mounts: {
|
|
198
|
-
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
199
|
-
* '/s3': new S3Filesystem({ bucket: 'my-bucket', ... }),
|
|
200
|
-
* }
|
|
201
|
-
* });
|
|
202
|
-
*
|
|
203
|
-
* // readdir('/') returns ['local', 's3']
|
|
204
|
-
* // readFile('/local/file.txt') reads from LocalFilesystem
|
|
205
|
-
* // readFile('/s3/data.json') reads from S3Filesystem
|
|
206
|
-
* ```
|
|
199
|
+
* Estimates the number of tokens in a text string using heuristic rules
|
|
207
200
|
*/
|
|
201
|
+
function estimateTokenCount(text, options = {}) {
|
|
202
|
+
if (!text) return 0;
|
|
203
|
+
let tokenCount = 0;
|
|
204
|
+
for (const segmentEstimate of walkSegments(text, options)) tokenCount += segmentEstimate.tokenCount;
|
|
205
|
+
return tokenCount;
|
|
206
|
+
}
|
|
208
207
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* Routes file operations to the appropriate underlying filesystem based on path.
|
|
212
|
-
* Supports cross-mount operations (copy/move between different filesystems).
|
|
213
|
-
*
|
|
214
|
-
* The generic parameter preserves the concrete types of mounted filesystems,
|
|
215
|
-
* enabling typed access via `mounts.get()`.
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* const cfs = new CompositeFilesystem({
|
|
220
|
-
* mounts: {
|
|
221
|
-
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
222
|
-
* '/s3': new S3Filesystem({ bucket: 'my-bucket' }),
|
|
223
|
-
* },
|
|
224
|
-
* });
|
|
225
|
-
*
|
|
226
|
-
* cfs.mounts.get('/local') // LocalFilesystem
|
|
227
|
-
* cfs.mounts.get('/s3') // S3Filesystem
|
|
228
|
-
* ```
|
|
208
|
+
* Extracts a portion of text based on token positions, similar to Array.prototype.slice()
|
|
229
209
|
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
this.id = `cfs-${Date.now().toString(36)}`;
|
|
239
|
-
this._mounts = /* @__PURE__ */ new Map();
|
|
240
|
-
for (const [path, fs] of Object.entries(config.mounts)) {
|
|
241
|
-
const normalized = this.normalizePath(path);
|
|
242
|
-
this._mounts.set(normalized, fs);
|
|
243
|
-
}
|
|
244
|
-
if (this._mounts.size === 0) throw new Error("CompositeFilesystem requires at least one mount");
|
|
245
|
-
this.readOnly = [...this._mounts.values()].every((fs) => fs.readOnly) || void 0;
|
|
246
|
-
const mountPaths = [...this._mounts.keys()];
|
|
247
|
-
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}"`);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Get all mount paths.
|
|
251
|
-
*/
|
|
252
|
-
get mountPaths() {
|
|
253
|
-
return Array.from(this._mounts.keys());
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Get the mounts map.
|
|
257
|
-
* Returns a typed map where `get()` preserves the concrete filesystem type per mount path.
|
|
258
|
-
*/
|
|
259
|
-
get mounts() {
|
|
260
|
-
return this._mounts;
|
|
210
|
+
function sliceByTokens(text, start = 0, end, options = {}) {
|
|
211
|
+
if (!text) return "";
|
|
212
|
+
let segmentEstimates = walkSegments(text, options);
|
|
213
|
+
let totalTokens = 0;
|
|
214
|
+
if (start < 0 || end !== void 0 && end < 0) {
|
|
215
|
+
const bufferedEstimates = Array.from(segmentEstimates);
|
|
216
|
+
for (const { tokenCount } of bufferedEstimates) totalTokens += tokenCount;
|
|
217
|
+
segmentEstimates = bufferedEstimates;
|
|
261
218
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
provider: this.provider,
|
|
273
|
-
status: this.status,
|
|
274
|
-
readOnly: this.readOnly,
|
|
275
|
-
metadata: { mounts }
|
|
276
|
-
};
|
|
219
|
+
const normalizedStart = start < 0 ? Math.max(0, totalTokens + start) : Math.max(0, start);
|
|
220
|
+
const normalizedEnd = end === void 0 ? Infinity : end < 0 ? Math.max(0, totalTokens + end) : end;
|
|
221
|
+
if (normalizedStart >= normalizedEnd) return "";
|
|
222
|
+
const parts = [];
|
|
223
|
+
let currentTokenPos = 0;
|
|
224
|
+
for (const { segment, tokenCount } of segmentEstimates) {
|
|
225
|
+
if (currentTokenPos >= normalizedEnd) break;
|
|
226
|
+
const extracted = extractSegmentPart(segment, currentTokenPos, tokenCount, normalizedStart, normalizedEnd);
|
|
227
|
+
if (extracted) parts.push(extracted);
|
|
228
|
+
currentTokenPos += tokenCount;
|
|
277
229
|
}
|
|
278
|
-
|
|
279
|
-
|
|
230
|
+
return parts.join("");
|
|
231
|
+
}
|
|
232
|
+
function extractSegmentPart(segment, segmentTokenStart, segmentTokenCount, targetStart, targetEnd) {
|
|
233
|
+
if (segmentTokenCount === 0) return segmentTokenStart >= targetStart && segmentTokenStart < targetEnd ? segment : "";
|
|
234
|
+
const segmentTokenEnd = segmentTokenStart + segmentTokenCount;
|
|
235
|
+
if (segmentTokenStart >= targetEnd || segmentTokenEnd <= targetStart) return "";
|
|
236
|
+
const overlapStart = Math.max(0, targetStart - segmentTokenStart);
|
|
237
|
+
const overlapEnd = Math.min(segmentTokenCount, targetEnd - segmentTokenStart);
|
|
238
|
+
if (overlapStart === 0 && overlapEnd === segmentTokenCount) return segment;
|
|
239
|
+
const charStart = Math.floor(overlapStart / segmentTokenCount * segment.length);
|
|
240
|
+
const charEnd = Math.ceil(overlapEnd / segmentTokenCount * segment.length);
|
|
241
|
+
return segment.slice(charStart, charEnd);
|
|
242
|
+
}
|
|
243
|
+
// src/utils/slice-by-tokens.ts
|
|
244
|
+
const UNPAIRED_SURROGATE_RE = /[\uD800-\uDFFF]/gu;
|
|
245
|
+
/**
|
|
246
|
+
* `sliceByTokens` from tokenx cuts on UTF-16 code-unit boundaries, so a cut can
|
|
247
|
+
* land inside a surrogate pair (emoji, CJK ext B+, math alphanumerics) and leave
|
|
248
|
+
* an unpaired surrogate. That is invalid UTF-16: it degrades to U+FFFD on a UTF-8
|
|
249
|
+
* round-trip and strict JSON parsers reject it. Always slice through this helper
|
|
250
|
+
* so every truncation site gets the same repair.
|
|
251
|
+
*/
|
|
252
|
+
function sliceByTokensSafe(text, start, end) {
|
|
253
|
+
return sliceByTokens(text, start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
|
|
254
|
+
}
|
|
255
|
+
/** `text.slice(start, end)` by UTF-16 index, with the same repair for a cut inside a surrogate pair. */
|
|
256
|
+
function sliceSafe(text, start, end) {
|
|
257
|
+
return text.slice(start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
|
|
258
|
+
}
|
|
259
|
+
// src/workspace/line-utils.ts
|
|
260
|
+
/**
|
|
261
|
+
* Extract lines from content by line range.
|
|
262
|
+
*
|
|
263
|
+
* @param content - The document content
|
|
264
|
+
* @param startLine - Starting line number (1-indexed)
|
|
265
|
+
* @param endLine - Ending line number (1-indexed, inclusive)
|
|
266
|
+
* @returns Object with extracted content and metadata
|
|
267
|
+
*/
|
|
268
|
+
function extractLines(content, startLine, endLine) {
|
|
269
|
+
const allLines = content.split("\n");
|
|
270
|
+
const totalLines = allLines.length;
|
|
271
|
+
const start = Math.max(1, startLine ?? 1);
|
|
272
|
+
const end = Math.min(totalLines, endLine ?? totalLines);
|
|
273
|
+
if (start > end) return {
|
|
274
|
+
content: "",
|
|
275
|
+
lines: {
|
|
276
|
+
start: 0,
|
|
277
|
+
end: 0
|
|
278
|
+
},
|
|
279
|
+
totalLines
|
|
280
|
+
};
|
|
281
|
+
return {
|
|
282
|
+
content: allLines.slice(start - 1, end).join("\n"),
|
|
283
|
+
lines: {
|
|
284
|
+
start,
|
|
285
|
+
end
|
|
286
|
+
},
|
|
287
|
+
totalLines
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Extract lines using offset/limit style parameters (like Claude Code).
|
|
292
|
+
*
|
|
293
|
+
* @param content - The document content
|
|
294
|
+
* @param offset - Line number to start from (1-indexed, default: 1)
|
|
295
|
+
* @param limit - Maximum number of lines to read (default: all remaining)
|
|
296
|
+
* @returns Object with extracted content and metadata
|
|
297
|
+
*/
|
|
298
|
+
function extractLinesWithLimit(content, offset, limit) {
|
|
299
|
+
const startLine = offset ?? 1;
|
|
300
|
+
return extractLines(content, startLine, limit ? startLine + limit - 1 : void 0);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Format content with line number prefixes.
|
|
304
|
+
* Output format matches Claude Code: " 1→content here"
|
|
305
|
+
*
|
|
306
|
+
* @param content - The content to format
|
|
307
|
+
* @param startLineNumber - The line number of the first line (1-indexed)
|
|
308
|
+
* @returns Formatted content with line numbers
|
|
309
|
+
*/
|
|
310
|
+
function formatWithLineNumbers(content, startLineNumber = 1) {
|
|
311
|
+
const lines = content.split("\n");
|
|
312
|
+
const maxLineNum = startLineNumber + lines.length - 1;
|
|
313
|
+
const padWidth = Math.max(6, String(maxLineNum).length + 1);
|
|
314
|
+
return lines.map((line, i) => {
|
|
315
|
+
const lineNum = startLineNumber + i;
|
|
316
|
+
return `${String(lineNum).padStart(padWidth)}\u2192${line}`;
|
|
317
|
+
}).join("\n");
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Convert a character index to a line number.
|
|
321
|
+
* Useful for converting RAG chunk character offsets to line numbers.
|
|
322
|
+
*
|
|
323
|
+
* @param content - The full document content
|
|
324
|
+
* @param charIndex - The character index (0-indexed)
|
|
325
|
+
* @returns The line number (1-indexed), or undefined if charIndex is out of bounds
|
|
326
|
+
*/
|
|
327
|
+
function charIndexToLineNumber(content, charIndex) {
|
|
328
|
+
if (charIndex < 0 || charIndex > content.length) return;
|
|
329
|
+
let lineNumber = 1;
|
|
330
|
+
for (let i = 0; i < charIndex && i < content.length; i++) if (content[i] === "\n") lineNumber++;
|
|
331
|
+
return lineNumber;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Convert character range to line range.
|
|
335
|
+
* Useful for converting RAG chunk character offsets to line ranges.
|
|
336
|
+
*
|
|
337
|
+
* @param content - The full document content
|
|
338
|
+
* @param startCharIdx - Start character index (0-indexed)
|
|
339
|
+
* @param endCharIdx - End character index (0-indexed, exclusive)
|
|
340
|
+
* @returns LineRange (1-indexed) or undefined if indices are out of bounds
|
|
341
|
+
*/
|
|
342
|
+
function charRangeToLineRange(content, startCharIdx, endCharIdx) {
|
|
343
|
+
const startLine = charIndexToLineNumber(content, startCharIdx);
|
|
344
|
+
const endLine = charIndexToLineNumber(content, Math.max(0, endCharIdx - 1));
|
|
345
|
+
if (startLine === void 0 || endLine === void 0) return;
|
|
346
|
+
return {
|
|
347
|
+
start: startLine,
|
|
348
|
+
end: endLine
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Count occurrences of a string in content.
|
|
353
|
+
*
|
|
354
|
+
* @param content - The content to search
|
|
355
|
+
* @param searchString - The string to find
|
|
356
|
+
* @returns Number of occurrences
|
|
357
|
+
*/
|
|
358
|
+
function countOccurrences(content, searchString) {
|
|
359
|
+
if (!searchString) return 0;
|
|
360
|
+
let count = 0;
|
|
361
|
+
let position = 0;
|
|
362
|
+
while ((position = content.indexOf(searchString, position)) !== -1) {
|
|
363
|
+
count++;
|
|
364
|
+
position += searchString.length;
|
|
365
|
+
}
|
|
366
|
+
return count;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Replace a string in content, with validation for uniqueness.
|
|
370
|
+
*
|
|
371
|
+
* @param content - The content to modify
|
|
372
|
+
* @param oldString - The string to find and replace
|
|
373
|
+
* @param newString - The replacement string
|
|
374
|
+
* @param replaceAll - If true, replace all occurrences; if false, require unique match
|
|
375
|
+
* @returns Object with result content and metadata
|
|
376
|
+
* @throws Error if oldString is not found or not unique (when replaceAll is false)
|
|
377
|
+
*/
|
|
378
|
+
function replaceString(content, oldString, newString, replaceAll = false) {
|
|
379
|
+
const count = countOccurrences(content, oldString);
|
|
380
|
+
if (count === 0) throw new StringNotFoundError(oldString);
|
|
381
|
+
if (!replaceAll && count > 1) throw new StringNotUniqueError(oldString, count);
|
|
382
|
+
const escapedNewString = newString.replace(/\$/g, "$$$$");
|
|
383
|
+
if (replaceAll) return {
|
|
384
|
+
content: content.split(oldString).join(newString),
|
|
385
|
+
replacements: count
|
|
386
|
+
};
|
|
387
|
+
return {
|
|
388
|
+
content: content.replace(oldString, escapedNewString),
|
|
389
|
+
replacements: 1
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Error thrown when string is not found during replacement.
|
|
394
|
+
*/
|
|
395
|
+
var StringNotFoundError = class extends Error {
|
|
396
|
+
searchString;
|
|
397
|
+
constructor(searchString) {
|
|
398
|
+
super(`The specified text was not found. Make sure you use the exact text from the file.`);
|
|
399
|
+
this.searchString = searchString;
|
|
400
|
+
this.name = "StringNotFoundError";
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Error thrown when string appears multiple times but unique match required.
|
|
405
|
+
*/
|
|
406
|
+
var StringNotUniqueError = class extends Error {
|
|
407
|
+
searchString;
|
|
408
|
+
occurrences;
|
|
409
|
+
constructor(searchString, occurrences) {
|
|
410
|
+
super(`The specified text appears ${occurrences} times. Provide more surrounding context to make the match unique, or use replace_all to replace all occurrences.`);
|
|
411
|
+
this.searchString = searchString;
|
|
412
|
+
this.occurrences = occurrences;
|
|
413
|
+
this.name = "StringNotUniqueError";
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
// src/workspace/constants/index.ts
|
|
417
|
+
const WORKSPACE_TOOLS_PREFIX = "mastra_workspace";
|
|
418
|
+
/**
|
|
419
|
+
* Workspace tool name constants.
|
|
420
|
+
* Use these to reference workspace tools by name.
|
|
421
|
+
*
|
|
422
|
+
* @example
|
|
423
|
+
* ```typescript
|
|
424
|
+
* import { WORKSPACE_TOOLS } from '@mastra/core/workspace';
|
|
425
|
+
*
|
|
426
|
+
* if (toolName === WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND) {
|
|
427
|
+
* // Handle sandbox execution
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
const WORKSPACE_TOOLS = {
|
|
432
|
+
FILESYSTEM: {
|
|
433
|
+
READ_FILE: `${WORKSPACE_TOOLS_PREFIX}_read_file`,
|
|
434
|
+
WRITE_FILE: `${WORKSPACE_TOOLS_PREFIX}_write_file`,
|
|
435
|
+
EDIT_FILE: `${WORKSPACE_TOOLS_PREFIX}_edit_file`,
|
|
436
|
+
LIST_FILES: `${WORKSPACE_TOOLS_PREFIX}_list_files`,
|
|
437
|
+
DELETE: `${WORKSPACE_TOOLS_PREFIX}_delete`,
|
|
438
|
+
FILE_STAT: `${WORKSPACE_TOOLS_PREFIX}_file_stat`,
|
|
439
|
+
MKDIR: `${WORKSPACE_TOOLS_PREFIX}_mkdir`,
|
|
440
|
+
GREP: `${WORKSPACE_TOOLS_PREFIX}_grep`,
|
|
441
|
+
AST_EDIT: `${WORKSPACE_TOOLS_PREFIX}_ast_edit`,
|
|
442
|
+
APPLY_PATCH: `${WORKSPACE_TOOLS_PREFIX}_apply_patch`
|
|
443
|
+
},
|
|
444
|
+
SANDBOX: {
|
|
445
|
+
EXECUTE_COMMAND: `${WORKSPACE_TOOLS_PREFIX}_execute_command`,
|
|
446
|
+
GET_PROCESS_OUTPUT: `${WORKSPACE_TOOLS_PREFIX}_get_process_output`,
|
|
447
|
+
KILL_PROCESS: `${WORKSPACE_TOOLS_PREFIX}_kill_process`
|
|
448
|
+
},
|
|
449
|
+
COMPUTER: {
|
|
450
|
+
SCREENSHOT: `${WORKSPACE_TOOLS_PREFIX}_computer_screenshot`,
|
|
451
|
+
CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_click`,
|
|
452
|
+
DOUBLE_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_double_click`,
|
|
453
|
+
RIGHT_CLICK: `${WORKSPACE_TOOLS_PREFIX}_computer_right_click`,
|
|
454
|
+
MOVE_MOUSE: `${WORKSPACE_TOOLS_PREFIX}_computer_move_mouse`,
|
|
455
|
+
DRAG: `${WORKSPACE_TOOLS_PREFIX}_computer_drag`,
|
|
456
|
+
TYPE: `${WORKSPACE_TOOLS_PREFIX}_computer_type`,
|
|
457
|
+
PRESS_KEY: `${WORKSPACE_TOOLS_PREFIX}_computer_press_key`,
|
|
458
|
+
SCROLL: `${WORKSPACE_TOOLS_PREFIX}_computer_scroll`,
|
|
459
|
+
GET_SCREEN_INFO: `${WORKSPACE_TOOLS_PREFIX}_computer_get_screen_info`,
|
|
460
|
+
WAIT: `${WORKSPACE_TOOLS_PREFIX}_computer_wait`
|
|
461
|
+
},
|
|
462
|
+
SEARCH: {
|
|
463
|
+
SEARCH: `${WORKSPACE_TOOLS_PREFIX}_search`,
|
|
464
|
+
INDEX: `${WORKSPACE_TOOLS_PREFIX}_index`
|
|
465
|
+
},
|
|
466
|
+
LSP: { LSP_INSPECT: `${WORKSPACE_TOOLS_PREFIX}_lsp_inspect` }
|
|
467
|
+
};
|
|
468
|
+
// src/workspace/lifecycle.ts
|
|
469
|
+
/**
|
|
470
|
+
* Call a lifecycle method on a provider, preferring the `_`-prefixed wrapper
|
|
471
|
+
* (which adds status tracking & race-condition safety) when available,
|
|
472
|
+
* falling back to the plain method for interface-only implementations.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```typescript
|
|
476
|
+
* await callLifecycle(sandbox, 'start'); // calls sandbox._start() ?? sandbox.start()
|
|
477
|
+
* await callLifecycle(filesystem, 'init'); // calls filesystem._init() ?? filesystem.init()
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
async function callLifecycle(provider, method) {
|
|
481
|
+
const wrappedFn = provider[`_${method}`];
|
|
482
|
+
if (typeof wrappedFn === "function") await wrappedFn.call(provider);
|
|
483
|
+
else {
|
|
484
|
+
const plainFn = provider[method];
|
|
485
|
+
if (typeof plainFn === "function") await plainFn.call(provider);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
// src/workspace/filesystem/composite-filesystem.ts
|
|
489
|
+
/**
|
|
490
|
+
* CompositeFilesystem - Routes operations to mounted filesystems based on path.
|
|
491
|
+
*
|
|
492
|
+
* Creates a unified filesystem view by combining multiple filesystems at different
|
|
493
|
+
* mount points. Useful for composing local storage, S3, and other backends.
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```typescript
|
|
497
|
+
* const cfs = new CompositeFilesystem({
|
|
498
|
+
* mounts: {
|
|
499
|
+
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
500
|
+
* '/s3': new S3Filesystem({ bucket: 'my-bucket', ... }),
|
|
501
|
+
* }
|
|
502
|
+
* });
|
|
503
|
+
*
|
|
504
|
+
* // readdir('/') returns ['local', 's3']
|
|
505
|
+
* // readFile('/local/file.txt') reads from LocalFilesystem
|
|
506
|
+
* // readFile('/s3/data.json') reads from S3Filesystem
|
|
507
|
+
* ```
|
|
508
|
+
*/
|
|
509
|
+
/**
|
|
510
|
+
* CompositeFilesystem implementation.
|
|
511
|
+
*
|
|
512
|
+
* Routes file operations to the appropriate underlying filesystem based on path.
|
|
513
|
+
* Supports cross-mount operations (copy/move between different filesystems).
|
|
514
|
+
*
|
|
515
|
+
* The generic parameter preserves the concrete types of mounted filesystems,
|
|
516
|
+
* enabling typed access via `mounts.get()`.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* const cfs = new CompositeFilesystem({
|
|
521
|
+
* mounts: {
|
|
522
|
+
* '/local': new LocalFilesystem({ basePath: './data' }),
|
|
523
|
+
* '/s3': new S3Filesystem({ bucket: 'my-bucket' }),
|
|
524
|
+
* },
|
|
525
|
+
* });
|
|
526
|
+
*
|
|
527
|
+
* cfs.mounts.get('/local') // LocalFilesystem
|
|
528
|
+
* cfs.mounts.get('/s3') // S3Filesystem
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
var CompositeFilesystem = class {
|
|
532
|
+
id;
|
|
533
|
+
name = "CompositeFilesystem";
|
|
534
|
+
provider = "composite";
|
|
535
|
+
readOnly;
|
|
536
|
+
status = "ready";
|
|
537
|
+
_mounts;
|
|
538
|
+
constructor(config) {
|
|
539
|
+
this.id = `cfs-${Date.now().toString(36)}`;
|
|
540
|
+
this._mounts = /* @__PURE__ */ new Map();
|
|
541
|
+
for (const [path, fs] of Object.entries(config.mounts)) {
|
|
542
|
+
const normalized = this.normalizePath(path);
|
|
543
|
+
this._mounts.set(normalized, fs);
|
|
544
|
+
}
|
|
545
|
+
if (this._mounts.size === 0) throw new Error("CompositeFilesystem requires at least one mount");
|
|
546
|
+
this.readOnly = [...this._mounts.values()].every((fs) => fs.readOnly) || void 0;
|
|
547
|
+
const mountPaths = [...this._mounts.keys()];
|
|
548
|
+
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}"`);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Get all mount paths.
|
|
552
|
+
*/
|
|
553
|
+
get mountPaths() {
|
|
554
|
+
return Array.from(this._mounts.keys());
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Get the mounts map.
|
|
558
|
+
* Returns a typed map where `get()` preserves the concrete filesystem type per mount path.
|
|
559
|
+
*/
|
|
560
|
+
get mounts() {
|
|
561
|
+
return this._mounts;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Get status and metadata for this composite filesystem.
|
|
565
|
+
* Includes info from each mounted filesystem in `metadata.mounts`.
|
|
566
|
+
*/
|
|
567
|
+
async getInfo() {
|
|
568
|
+
const mounts = {};
|
|
569
|
+
for (const [mountPath, fs] of this._mounts) mounts[mountPath] = await fs.getInfo?.() ?? null;
|
|
570
|
+
return {
|
|
571
|
+
id: this.id,
|
|
572
|
+
name: this.name,
|
|
573
|
+
provider: this.provider,
|
|
574
|
+
status: this.status,
|
|
575
|
+
readOnly: this.readOnly,
|
|
576
|
+
metadata: { mounts }
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Get the underlying filesystem for a given path.
|
|
280
581
|
* Returns undefined if the path doesn't resolve to any mount.
|
|
281
582
|
*/
|
|
282
583
|
getFilesystemForPath(path) {
|
|
@@ -5779,106 +6080,15 @@ const computerPressKeyTool = createTool({
|
|
|
5779
6080
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5780
6081
|
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY);
|
|
5781
6082
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5782
|
-
category: "computer",
|
|
5783
|
-
operation: "pressKey",
|
|
5784
|
-
input: { key },
|
|
5785
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5786
|
-
});
|
|
5787
|
-
try {
|
|
5788
|
-
await computer.press(key);
|
|
5789
|
-
const label = Array.isArray(key) ? key.join("+") : key;
|
|
5790
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY, `Pressed ${label}`);
|
|
5791
|
-
span.end({ success: true });
|
|
5792
|
-
return result;
|
|
5793
|
-
} catch (err) {
|
|
5794
|
-
span.error(err);
|
|
5795
|
-
throw err;
|
|
5796
|
-
}
|
|
5797
|
-
},
|
|
5798
|
-
toModelOutput: mediaToModelOutput
|
|
5799
|
-
});
|
|
5800
|
-
// src/workspace/tools/computer-right-click.ts
|
|
5801
|
-
const computerRightClickTool = createTool({
|
|
5802
|
-
id: WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK,
|
|
5803
|
-
description: "Right-click at pixel coordinates on the sandbox desktop. Use for opening context menus.",
|
|
5804
|
-
inputSchema: z.object({
|
|
5805
|
-
x: z.number().int().min(0).describe("X coordinate in pixels from the left edge of the screen"),
|
|
5806
|
-
y: z.number().int().min(0).describe("Y coordinate in pixels from the top edge of the screen")
|
|
5807
|
-
}),
|
|
5808
|
-
execute: async ({ x, y }, context) => {
|
|
5809
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5810
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK);
|
|
5811
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5812
|
-
category: "computer",
|
|
5813
|
-
operation: "rightClick",
|
|
5814
|
-
input: {
|
|
5815
|
-
x,
|
|
5816
|
-
y
|
|
5817
|
-
},
|
|
5818
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5819
|
-
});
|
|
5820
|
-
try {
|
|
5821
|
-
await computer.rightClick(x, y);
|
|
5822
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK, `Right-clicked at (${x}, ${y})`);
|
|
5823
|
-
span.end({ success: true });
|
|
5824
|
-
return result;
|
|
5825
|
-
} catch (err) {
|
|
5826
|
-
span.error(err);
|
|
5827
|
-
throw err;
|
|
5828
|
-
}
|
|
5829
|
-
},
|
|
5830
|
-
toModelOutput: mediaToModelOutput
|
|
5831
|
-
});
|
|
5832
|
-
// src/workspace/tools/computer-screenshot.ts
|
|
5833
|
-
const computerScreenshotTool = createTool({
|
|
5834
|
-
id: WORKSPACE_TOOLS.COMPUTER.SCREENSHOT,
|
|
5835
|
-
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.",
|
|
5836
|
-
inputSchema: z.object({}),
|
|
5837
|
-
execute: async (_input, context) => {
|
|
5838
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5839
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT);
|
|
5840
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5841
|
-
category: "computer",
|
|
5842
|
-
operation: "screenshot",
|
|
5843
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5844
|
-
});
|
|
5845
|
-
try {
|
|
5846
|
-
const screenshot = await computer.screenshot();
|
|
5847
|
-
const maxMediaBytes = getComputerToolConfig(workspace, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT)?.maxMediaBytes ?? 10485760;
|
|
5848
|
-
const result = screenshotToResult(screenshot, `Screenshot of the desktop (${screenshot.data.byteLength} bytes, ${screenshot.mediaType})`, maxMediaBytes);
|
|
5849
|
-
span.end({ success: true }, { bytesTransferred: screenshot.data.byteLength });
|
|
5850
|
-
return result;
|
|
5851
|
-
} catch (err) {
|
|
5852
|
-
span.error(err);
|
|
5853
|
-
throw err;
|
|
5854
|
-
}
|
|
5855
|
-
},
|
|
5856
|
-
toModelOutput: mediaToModelOutput
|
|
5857
|
-
});
|
|
5858
|
-
// src/workspace/tools/computer-scroll.ts
|
|
5859
|
-
const computerScrollTool = createTool({
|
|
5860
|
-
id: WORKSPACE_TOOLS.COMPUTER.SCROLL,
|
|
5861
|
-
description: "Scroll the sandbox desktop display up or down.",
|
|
5862
|
-
inputSchema: z.object({
|
|
5863
|
-
direction: z.enum(["up", "down"]).describe("Scroll direction"),
|
|
5864
|
-
amount: z.number().int().min(1).optional().describe("Scroll amount in ticks (default: 3)")
|
|
5865
|
-
}),
|
|
5866
|
-
execute: async ({ direction, amount }, context) => {
|
|
5867
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5868
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCROLL);
|
|
5869
|
-
const effectiveAmount = amount ?? 3;
|
|
5870
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5871
|
-
category: "computer",
|
|
5872
|
-
operation: "scroll",
|
|
5873
|
-
input: {
|
|
5874
|
-
direction,
|
|
5875
|
-
amount: effectiveAmount
|
|
5876
|
-
},
|
|
6083
|
+
category: "computer",
|
|
6084
|
+
operation: "pressKey",
|
|
6085
|
+
input: { key },
|
|
5877
6086
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5878
6087
|
});
|
|
5879
6088
|
try {
|
|
5880
|
-
await computer.
|
|
5881
|
-
const
|
|
6089
|
+
await computer.press(key);
|
|
6090
|
+
const label = Array.isArray(key) ? key.join("+") : key;
|
|
6091
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.PRESS_KEY, `Pressed ${label}`);
|
|
5882
6092
|
span.end({ success: true });
|
|
5883
6093
|
return result;
|
|
5884
6094
|
} catch (err) {
|
|
@@ -5888,23 +6098,29 @@ const computerScrollTool = createTool({
|
|
|
5888
6098
|
},
|
|
5889
6099
|
toModelOutput: mediaToModelOutput
|
|
5890
6100
|
});
|
|
5891
|
-
// src/workspace/tools/computer-
|
|
5892
|
-
const
|
|
5893
|
-
id: WORKSPACE_TOOLS.COMPUTER.
|
|
5894
|
-
description: "
|
|
5895
|
-
inputSchema: z.object({
|
|
5896
|
-
|
|
6101
|
+
// src/workspace/tools/computer-right-click.ts
|
|
6102
|
+
const computerRightClickTool = createTool({
|
|
6103
|
+
id: WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK,
|
|
6104
|
+
description: "Right-click at pixel coordinates on the sandbox desktop. Use for opening context menus.",
|
|
6105
|
+
inputSchema: z.object({
|
|
6106
|
+
x: z.number().int().min(0).describe("X coordinate in pixels from the left edge of the screen"),
|
|
6107
|
+
y: z.number().int().min(0).describe("Y coordinate in pixels from the top edge of the screen")
|
|
6108
|
+
}),
|
|
6109
|
+
execute: async ({ x, y }, context) => {
|
|
5897
6110
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5898
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.
|
|
6111
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK);
|
|
5899
6112
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5900
6113
|
category: "computer",
|
|
5901
|
-
operation: "
|
|
5902
|
-
input: {
|
|
6114
|
+
operation: "rightClick",
|
|
6115
|
+
input: {
|
|
6116
|
+
x,
|
|
6117
|
+
y
|
|
6118
|
+
},
|
|
5903
6119
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5904
6120
|
});
|
|
5905
6121
|
try {
|
|
5906
|
-
await computer.
|
|
5907
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.
|
|
6122
|
+
await computer.rightClick(x, y);
|
|
6123
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.RIGHT_CLICK, `Right-clicked at (${x}, ${y})`);
|
|
5908
6124
|
span.end({ success: true });
|
|
5909
6125
|
return result;
|
|
5910
6126
|
} catch (err) {
|
|
@@ -5914,24 +6130,24 @@ const computerTypeTool = createTool({
|
|
|
5914
6130
|
},
|
|
5915
6131
|
toModelOutput: mediaToModelOutput
|
|
5916
6132
|
});
|
|
5917
|
-
// src/workspace/tools/computer-
|
|
5918
|
-
const
|
|
5919
|
-
id: WORKSPACE_TOOLS.COMPUTER.
|
|
5920
|
-
description: "
|
|
5921
|
-
inputSchema: z.object({
|
|
5922
|
-
execute: async (
|
|
6133
|
+
// src/workspace/tools/computer-screenshot.ts
|
|
6134
|
+
const computerScreenshotTool = createTool({
|
|
6135
|
+
id: WORKSPACE_TOOLS.COMPUTER.SCREENSHOT,
|
|
6136
|
+
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.",
|
|
6137
|
+
inputSchema: z.object({}),
|
|
6138
|
+
execute: async (_input, context) => {
|
|
5923
6139
|
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5924
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.
|
|
6140
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT);
|
|
5925
6141
|
const span = startWorkspaceSpan(context, workspace, {
|
|
5926
6142
|
category: "computer",
|
|
5927
|
-
operation: "
|
|
5928
|
-
input: { seconds },
|
|
6143
|
+
operation: "screenshot",
|
|
5929
6144
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5930
6145
|
});
|
|
5931
6146
|
try {
|
|
5932
|
-
|
|
5933
|
-
const
|
|
5934
|
-
|
|
6147
|
+
const screenshot = await computer.screenshot();
|
|
6148
|
+
const maxMediaBytes = getComputerToolConfig(workspace, WORKSPACE_TOOLS.COMPUTER.SCREENSHOT)?.maxMediaBytes ?? 10485760;
|
|
6149
|
+
const result = screenshotToResult(screenshot, `Screenshot of the desktop (${screenshot.data.byteLength} bytes, ${screenshot.mediaType})`, maxMediaBytes);
|
|
6150
|
+
span.end({ success: true }, { bytesTransferred: screenshot.data.byteLength });
|
|
5935
6151
|
return result;
|
|
5936
6152
|
} catch (err) {
|
|
5937
6153
|
span.error(err);
|
|
@@ -5940,199 +6156,127 @@ const computerWaitTool = createTool({
|
|
|
5940
6156
|
},
|
|
5941
6157
|
toModelOutput: mediaToModelOutput
|
|
5942
6158
|
});
|
|
5943
|
-
// src/workspace/tools/
|
|
5944
|
-
const
|
|
5945
|
-
id: WORKSPACE_TOOLS.
|
|
5946
|
-
description: "
|
|
5947
|
-
outputSchema: z.string(),
|
|
6159
|
+
// src/workspace/tools/computer-scroll.ts
|
|
6160
|
+
const computerScrollTool = createTool({
|
|
6161
|
+
id: WORKSPACE_TOOLS.COMPUTER.SCROLL,
|
|
6162
|
+
description: "Scroll the sandbox desktop display up or down.",
|
|
5948
6163
|
inputSchema: z.object({
|
|
5949
|
-
|
|
5950
|
-
|
|
6164
|
+
direction: z.enum(["up", "down"]).describe("Scroll direction"),
|
|
6165
|
+
amount: z.number().int().min(1).optional().describe("Scroll amount in ticks (default: 3)")
|
|
5951
6166
|
}),
|
|
5952
|
-
execute: async ({
|
|
5953
|
-
const { workspace,
|
|
5954
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.
|
|
5955
|
-
const
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
span.
|
|
5972
|
-
|
|
5973
|
-
}
|
|
5974
|
-
|
|
5975
|
-
|
|
5976
|
-
|
|
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
|
-
const startLine = charIndexToLineNumber(content, startCharIdx);
|
|
6064
|
-
const endLine = charIndexToLineNumber(content, Math.max(0, endCharIdx - 1));
|
|
6065
|
-
if (startLine === void 0 || endLine === void 0) return;
|
|
6066
|
-
return {
|
|
6067
|
-
start: startLine,
|
|
6068
|
-
end: endLine
|
|
6069
|
-
};
|
|
6070
|
-
}
|
|
6071
|
-
/**
|
|
6072
|
-
* Count occurrences of a string in content.
|
|
6073
|
-
*
|
|
6074
|
-
* @param content - The content to search
|
|
6075
|
-
* @param searchString - The string to find
|
|
6076
|
-
* @returns Number of occurrences
|
|
6077
|
-
*/
|
|
6078
|
-
function countOccurrences(content, searchString) {
|
|
6079
|
-
if (!searchString) return 0;
|
|
6080
|
-
let count = 0;
|
|
6081
|
-
let position = 0;
|
|
6082
|
-
while ((position = content.indexOf(searchString, position)) !== -1) {
|
|
6083
|
-
count++;
|
|
6084
|
-
position += searchString.length;
|
|
6085
|
-
}
|
|
6086
|
-
return count;
|
|
6087
|
-
}
|
|
6088
|
-
/**
|
|
6089
|
-
* Replace a string in content, with validation for uniqueness.
|
|
6090
|
-
*
|
|
6091
|
-
* @param content - The content to modify
|
|
6092
|
-
* @param oldString - The string to find and replace
|
|
6093
|
-
* @param newString - The replacement string
|
|
6094
|
-
* @param replaceAll - If true, replace all occurrences; if false, require unique match
|
|
6095
|
-
* @returns Object with result content and metadata
|
|
6096
|
-
* @throws Error if oldString is not found or not unique (when replaceAll is false)
|
|
6097
|
-
*/
|
|
6098
|
-
function replaceString(content, oldString, newString, replaceAll = false) {
|
|
6099
|
-
const count = countOccurrences(content, oldString);
|
|
6100
|
-
if (count === 0) throw new StringNotFoundError(oldString);
|
|
6101
|
-
if (!replaceAll && count > 1) throw new StringNotUniqueError(oldString, count);
|
|
6102
|
-
const escapedNewString = newString.replace(/\$/g, "$$$$");
|
|
6103
|
-
if (replaceAll) return {
|
|
6104
|
-
content: content.split(oldString).join(newString),
|
|
6105
|
-
replacements: count
|
|
6106
|
-
};
|
|
6107
|
-
return {
|
|
6108
|
-
content: content.replace(oldString, escapedNewString),
|
|
6109
|
-
replacements: 1
|
|
6110
|
-
};
|
|
6111
|
-
}
|
|
6112
|
-
/**
|
|
6113
|
-
* Error thrown when string is not found during replacement.
|
|
6114
|
-
*/
|
|
6115
|
-
var StringNotFoundError = class extends Error {
|
|
6116
|
-
searchString;
|
|
6117
|
-
constructor(searchString) {
|
|
6118
|
-
super(`The specified text was not found. Make sure you use the exact text from the file.`);
|
|
6119
|
-
this.searchString = searchString;
|
|
6120
|
-
this.name = "StringNotFoundError";
|
|
6121
|
-
}
|
|
6122
|
-
};
|
|
6123
|
-
/**
|
|
6124
|
-
* Error thrown when string appears multiple times but unique match required.
|
|
6125
|
-
*/
|
|
6126
|
-
var StringNotUniqueError = class extends Error {
|
|
6127
|
-
searchString;
|
|
6128
|
-
occurrences;
|
|
6129
|
-
constructor(searchString, occurrences) {
|
|
6130
|
-
super(`The specified text appears ${occurrences} times. Provide more surrounding context to make the match unique, or use replace_all to replace all occurrences.`);
|
|
6131
|
-
this.searchString = searchString;
|
|
6132
|
-
this.occurrences = occurrences;
|
|
6133
|
-
this.name = "StringNotUniqueError";
|
|
6167
|
+
execute: async ({ direction, amount }, context) => {
|
|
6168
|
+
const { workspace, sandbox, computer } = requireComputer(context);
|
|
6169
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.SCROLL);
|
|
6170
|
+
const effectiveAmount = amount ?? 3;
|
|
6171
|
+
const span = startWorkspaceSpan(context, workspace, {
|
|
6172
|
+
category: "computer",
|
|
6173
|
+
operation: "scroll",
|
|
6174
|
+
input: {
|
|
6175
|
+
direction,
|
|
6176
|
+
amount: effectiveAmount
|
|
6177
|
+
},
|
|
6178
|
+
attributes: { sandboxProvider: sandbox.provider }
|
|
6179
|
+
});
|
|
6180
|
+
try {
|
|
6181
|
+
await computer.scroll(direction, effectiveAmount);
|
|
6182
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.SCROLL, `Scrolled ${direction} by ${effectiveAmount}`);
|
|
6183
|
+
span.end({ success: true });
|
|
6184
|
+
return result;
|
|
6185
|
+
} catch (err) {
|
|
6186
|
+
span.error(err);
|
|
6187
|
+
throw err;
|
|
6188
|
+
}
|
|
6189
|
+
},
|
|
6190
|
+
toModelOutput: mediaToModelOutput
|
|
6191
|
+
});
|
|
6192
|
+
// src/workspace/tools/computer-type.ts
|
|
6193
|
+
const computerTypeTool = createTool({
|
|
6194
|
+
id: WORKSPACE_TOOLS.COMPUTER.TYPE,
|
|
6195
|
+
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).",
|
|
6196
|
+
inputSchema: z.object({ text: z.string().describe("The text to type") }),
|
|
6197
|
+
execute: async ({ text }, context) => {
|
|
6198
|
+
const { workspace, sandbox, computer } = requireComputer(context);
|
|
6199
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.TYPE);
|
|
6200
|
+
const span = startWorkspaceSpan(context, workspace, {
|
|
6201
|
+
category: "computer",
|
|
6202
|
+
operation: "type",
|
|
6203
|
+
input: { length: text.length },
|
|
6204
|
+
attributes: { sandboxProvider: sandbox.provider }
|
|
6205
|
+
});
|
|
6206
|
+
try {
|
|
6207
|
+
await computer.type(text);
|
|
6208
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.TYPE, `Typed ${text.length} characters`);
|
|
6209
|
+
span.end({ success: true });
|
|
6210
|
+
return result;
|
|
6211
|
+
} catch (err) {
|
|
6212
|
+
span.error(err);
|
|
6213
|
+
throw err;
|
|
6214
|
+
}
|
|
6215
|
+
},
|
|
6216
|
+
toModelOutput: mediaToModelOutput
|
|
6217
|
+
});
|
|
6218
|
+
// src/workspace/tools/computer-wait.ts
|
|
6219
|
+
const computerWaitTool = createTool({
|
|
6220
|
+
id: WORKSPACE_TOOLS.COMPUTER.WAIT,
|
|
6221
|
+
description: "Wait for the sandbox desktop UI to settle (e.g. an application launching or a page loading) before the next action.",
|
|
6222
|
+
inputSchema: z.object({ seconds: z.number().min(.1).max(30).describe("How long to wait, in seconds (max 30)") }),
|
|
6223
|
+
execute: async ({ seconds }, context) => {
|
|
6224
|
+
const { workspace, sandbox, computer } = requireComputer(context);
|
|
6225
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.WAIT);
|
|
6226
|
+
const span = startWorkspaceSpan(context, workspace, {
|
|
6227
|
+
category: "computer",
|
|
6228
|
+
operation: "wait",
|
|
6229
|
+
input: { seconds },
|
|
6230
|
+
attributes: { sandboxProvider: sandbox.provider }
|
|
6231
|
+
});
|
|
6232
|
+
try {
|
|
6233
|
+
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
6234
|
+
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.WAIT, `Waited ${seconds}s`);
|
|
6235
|
+
span.end({ success: true });
|
|
6236
|
+
return result;
|
|
6237
|
+
} catch (err) {
|
|
6238
|
+
span.error(err);
|
|
6239
|
+
throw err;
|
|
6240
|
+
}
|
|
6241
|
+
},
|
|
6242
|
+
toModelOutput: mediaToModelOutput
|
|
6243
|
+
});
|
|
6244
|
+
// src/workspace/tools/delete-file.ts
|
|
6245
|
+
const deleteFileTool = createTool({
|
|
6246
|
+
id: WORKSPACE_TOOLS.FILESYSTEM.DELETE,
|
|
6247
|
+
description: "Delete a file or directory from the workspace filesystem",
|
|
6248
|
+
outputSchema: z.string(),
|
|
6249
|
+
inputSchema: z.object({
|
|
6250
|
+
path: z.string().describe("The path to the file or directory to delete"),
|
|
6251
|
+
recursive: z.boolean().optional().default(false).describe("If true, delete directories and their contents recursively. Required for non-empty directories.")
|
|
6252
|
+
}),
|
|
6253
|
+
execute: async ({ path, recursive }, context) => {
|
|
6254
|
+
const { workspace, filesystem } = requireFilesystem(context);
|
|
6255
|
+
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.FILESYSTEM.DELETE);
|
|
6256
|
+
const span = startWorkspaceSpan(context, workspace, {
|
|
6257
|
+
category: "filesystem",
|
|
6258
|
+
operation: "delete",
|
|
6259
|
+
input: {
|
|
6260
|
+
path,
|
|
6261
|
+
recursive
|
|
6262
|
+
},
|
|
6263
|
+
attributes: { filesystemProvider: filesystem.provider }
|
|
6264
|
+
});
|
|
6265
|
+
try {
|
|
6266
|
+
if (filesystem.readOnly) throw new WorkspaceReadOnlyError("delete");
|
|
6267
|
+
if ((await filesystem.stat(path)).type === "directory") await filesystem.rmdir(path, {
|
|
6268
|
+
recursive,
|
|
6269
|
+
force: recursive
|
|
6270
|
+
});
|
|
6271
|
+
else await filesystem.deleteFile(path);
|
|
6272
|
+
span.end({ success: true });
|
|
6273
|
+
return `Deleted ${path}`;
|
|
6274
|
+
} catch (err) {
|
|
6275
|
+
span.error(err);
|
|
6276
|
+
throw err;
|
|
6277
|
+
}
|
|
6134
6278
|
}
|
|
6135
|
-
};
|
|
6279
|
+
});
|
|
6136
6280
|
// src/workspace/tools/edit-file.ts
|
|
6137
6281
|
function getEditedLineRanges(content, oldString, newString, replaceAll) {
|
|
6138
6282
|
if (!oldString) return "";
|
|
@@ -6467,150 +6611,6 @@ var BrowserCliHandler = class {
|
|
|
6467
6611
|
* This preserves warmup state across command executions.
|
|
6468
6612
|
*/
|
|
6469
6613
|
const browserCliHandler = new BrowserCliHandler();
|
|
6470
|
-
// ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/tokenx/1.6.0/394289cb1bed8c542941f77748eea1a31bd3419018d0fb2ac7029ece2458cdd1/node_modules/tokenx/dist/index.mjs
|
|
6471
|
-
const PATTERNS = {
|
|
6472
|
-
whitespace: /^\s+$/,
|
|
6473
|
-
structuredWhitespace: /\n\s/,
|
|
6474
|
-
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]/,
|
|
6475
|
-
numeric: /^\d+$/,
|
|
6476
|
-
punctuation: /[.,!?;(){}[\]<>:/\\|@#$%^&*+=`~_"-]/
|
|
6477
|
-
};
|
|
6478
|
-
const TOKEN_SPLIT_PATTERN = new RegExp(`(\\s+|${PATTERNS.punctuation.source}+)`);
|
|
6479
|
-
const DEFAULT_CHARS_PER_TOKEN = 6;
|
|
6480
|
-
const SHORT_TOKEN_THRESHOLD = 3;
|
|
6481
|
-
const KANA_CHARS_PER_TOKEN = 1.35;
|
|
6482
|
-
const DEFAULT_LANGUAGE_CONFIGS = [
|
|
6483
|
-
{
|
|
6484
|
-
pattern: /[\u00E4\u00F6\u00FC\u00DF\u1E9E]/i,
|
|
6485
|
-
averageCharsPerToken: 2.6
|
|
6486
|
-
},
|
|
6487
|
-
{
|
|
6488
|
-
pattern: /[\u00E9\u00E8\u00EA\u00EB\u00E0\u00E2\u00EE\u00EF\u00F4\u00FB\u00F9\u00FC\u00FF\u00E7\u0153\u00E6\u00E1\u00ED\u00F3\u00FA\u00F1]/i,
|
|
6489
|
-
averageCharsPerToken: 3
|
|
6490
|
-
},
|
|
6491
|
-
{
|
|
6492
|
-
pattern: /[\u0105\u0107\u0119\u0142\u0144\u00F3\u015B\u017A\u017C\u011B\u0161\u010D\u0159\u017E\u00FD\u016F\u00FA\u010F\u0165\u0148]/i,
|
|
6493
|
-
averageCharsPerToken: 2.5
|
|
6494
|
-
},
|
|
6495
|
-
{
|
|
6496
|
-
pattern: /[\u0430-\u044F\u0451]/i,
|
|
6497
|
-
averageCharsPerToken: 4
|
|
6498
|
-
},
|
|
6499
|
-
{
|
|
6500
|
-
pattern: /[\u03AC-\u03CE]/i,
|
|
6501
|
-
averageCharsPerToken: 2.75
|
|
6502
|
-
},
|
|
6503
|
-
{
|
|
6504
|
-
pattern: /^\p{Extended_Pictographic}[\p{Extended_Pictographic}\p{Emoji_Component}]*$/u,
|
|
6505
|
-
averageCharsPerToken: .75
|
|
6506
|
-
}
|
|
6507
|
-
];
|
|
6508
|
-
/**
|
|
6509
|
-
* Walks a text as (segment, estimated token count) pairs. The segments
|
|
6510
|
-
* concatenate back to the original text; whitespace segments count zero
|
|
6511
|
-
* tokens unless they carry structure (indentation or blank lines).
|
|
6512
|
-
*/
|
|
6513
|
-
function* walkSegments(text, options = {}) {
|
|
6514
|
-
if (!text) return;
|
|
6515
|
-
const resolvedOptions = resolveOptions(options);
|
|
6516
|
-
for (const segment of text.split(TOKEN_SPLIT_PATTERN)) if (segment) yield {
|
|
6517
|
-
segment,
|
|
6518
|
-
tokenCount: estimateSegmentTokens(segment, resolvedOptions)
|
|
6519
|
-
};
|
|
6520
|
-
}
|
|
6521
|
-
function resolveOptions(options) {
|
|
6522
|
-
return {
|
|
6523
|
-
defaultCharsPerToken: options.defaultCharsPerToken ?? DEFAULT_CHARS_PER_TOKEN,
|
|
6524
|
-
languageConfigs: options.languageConfigs ?? DEFAULT_LANGUAGE_CONFIGS
|
|
6525
|
-
};
|
|
6526
|
-
}
|
|
6527
|
-
function estimateSegmentTokens(segment, { languageConfigs, defaultCharsPerToken }) {
|
|
6528
|
-
if (PATTERNS.whitespace.test(segment)) return PATTERNS.structuredWhitespace.test(segment) ? 1 : 0;
|
|
6529
|
-
const languageCharsPerToken = getLanguageSpecificCharsPerToken(segment, languageConfigs);
|
|
6530
|
-
if (languageCharsPerToken !== void 0) return Math.ceil(getCharacterCount(segment) / languageCharsPerToken);
|
|
6531
|
-
if (PATTERNS.cjk.test(segment)) return estimateCjkTokens(segment);
|
|
6532
|
-
if (PATTERNS.numeric.test(segment)) return Math.ceil(segment.length / 3);
|
|
6533
|
-
if (segment.length <= SHORT_TOKEN_THRESHOLD) return 1;
|
|
6534
|
-
if (PATTERNS.punctuation.test(segment)) return Math.ceil(segment.length / 2);
|
|
6535
|
-
return Math.ceil(segment.length / defaultCharsPerToken);
|
|
6536
|
-
}
|
|
6537
|
-
function getLanguageSpecificCharsPerToken(segment, languageConfigs) {
|
|
6538
|
-
for (const config of languageConfigs) if (segment.search(config.pattern) !== -1) return config.averageCharsPerToken;
|
|
6539
|
-
}
|
|
6540
|
-
function getCharacterCount(text) {
|
|
6541
|
-
return Array.from(text).length;
|
|
6542
|
-
}
|
|
6543
|
-
function estimateCjkTokens(segment) {
|
|
6544
|
-
let kanaCount = 0;
|
|
6545
|
-
let otherCount = 0;
|
|
6546
|
-
for (const character of segment) {
|
|
6547
|
-
const codePoint = character.codePointAt(0);
|
|
6548
|
-
if (codePoint >= 12352 && codePoint <= 12543) kanaCount++;
|
|
6549
|
-
else otherCount++;
|
|
6550
|
-
}
|
|
6551
|
-
return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
|
|
6552
|
-
}
|
|
6553
|
-
/**
|
|
6554
|
-
* Estimates the number of tokens in a text string using heuristic rules
|
|
6555
|
-
*/
|
|
6556
|
-
function estimateTokenCount(text, options = {}) {
|
|
6557
|
-
if (!text) return 0;
|
|
6558
|
-
let tokenCount = 0;
|
|
6559
|
-
for (const segmentEstimate of walkSegments(text, options)) tokenCount += segmentEstimate.tokenCount;
|
|
6560
|
-
return tokenCount;
|
|
6561
|
-
}
|
|
6562
|
-
/**
|
|
6563
|
-
* Extracts a portion of text based on token positions, similar to Array.prototype.slice()
|
|
6564
|
-
*/
|
|
6565
|
-
function sliceByTokens(text, start = 0, end, options = {}) {
|
|
6566
|
-
if (!text) return "";
|
|
6567
|
-
let segmentEstimates = walkSegments(text, options);
|
|
6568
|
-
let totalTokens = 0;
|
|
6569
|
-
if (start < 0 || end !== void 0 && end < 0) {
|
|
6570
|
-
const bufferedEstimates = Array.from(segmentEstimates);
|
|
6571
|
-
for (const { tokenCount } of bufferedEstimates) totalTokens += tokenCount;
|
|
6572
|
-
segmentEstimates = bufferedEstimates;
|
|
6573
|
-
}
|
|
6574
|
-
const normalizedStart = start < 0 ? Math.max(0, totalTokens + start) : Math.max(0, start);
|
|
6575
|
-
const normalizedEnd = end === void 0 ? Infinity : end < 0 ? Math.max(0, totalTokens + end) : end;
|
|
6576
|
-
if (normalizedStart >= normalizedEnd) return "";
|
|
6577
|
-
const parts = [];
|
|
6578
|
-
let currentTokenPos = 0;
|
|
6579
|
-
for (const { segment, tokenCount } of segmentEstimates) {
|
|
6580
|
-
if (currentTokenPos >= normalizedEnd) break;
|
|
6581
|
-
const extracted = extractSegmentPart(segment, currentTokenPos, tokenCount, normalizedStart, normalizedEnd);
|
|
6582
|
-
if (extracted) parts.push(extracted);
|
|
6583
|
-
currentTokenPos += tokenCount;
|
|
6584
|
-
}
|
|
6585
|
-
return parts.join("");
|
|
6586
|
-
}
|
|
6587
|
-
function extractSegmentPart(segment, segmentTokenStart, segmentTokenCount, targetStart, targetEnd) {
|
|
6588
|
-
if (segmentTokenCount === 0) return segmentTokenStart >= targetStart && segmentTokenStart < targetEnd ? segment : "";
|
|
6589
|
-
const segmentTokenEnd = segmentTokenStart + segmentTokenCount;
|
|
6590
|
-
if (segmentTokenStart >= targetEnd || segmentTokenEnd <= targetStart) return "";
|
|
6591
|
-
const overlapStart = Math.max(0, targetStart - segmentTokenStart);
|
|
6592
|
-
const overlapEnd = Math.min(segmentTokenCount, targetEnd - segmentTokenStart);
|
|
6593
|
-
if (overlapStart === 0 && overlapEnd === segmentTokenCount) return segment;
|
|
6594
|
-
const charStart = Math.floor(overlapStart / segmentTokenCount * segment.length);
|
|
6595
|
-
const charEnd = Math.ceil(overlapEnd / segmentTokenCount * segment.length);
|
|
6596
|
-
return segment.slice(charStart, charEnd);
|
|
6597
|
-
}
|
|
6598
|
-
// src/utils/slice-by-tokens.ts
|
|
6599
|
-
const UNPAIRED_SURROGATE_RE = /[\uD800-\uDFFF]/gu;
|
|
6600
|
-
/**
|
|
6601
|
-
* `sliceByTokens` from tokenx cuts on UTF-16 code-unit boundaries, so a cut can
|
|
6602
|
-
* land inside a surrogate pair (emoji, CJK ext B+, math alphanumerics) and leave
|
|
6603
|
-
* an unpaired surrogate. That is invalid UTF-16: it degrades to U+FFFD on a UTF-8
|
|
6604
|
-
* round-trip and strict JSON parsers reject it. Always slice through this helper
|
|
6605
|
-
* so every truncation site gets the same repair.
|
|
6606
|
-
*/
|
|
6607
|
-
function sliceByTokensSafe(text, start, end) {
|
|
6608
|
-
return sliceByTokens(text, start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
|
|
6609
|
-
}
|
|
6610
|
-
/** `text.slice(start, end)` by UTF-16 index, with the same repair for a cut inside a surrogate pair. */
|
|
6611
|
-
function sliceSafe(text, start, end) {
|
|
6612
|
-
return text.slice(start, end).replace(UNPAIRED_SURROGATE_RE, "\uFFFD");
|
|
6613
|
-
}
|
|
6614
6614
|
// src/workspace/tools/output-helpers.ts
|
|
6615
6615
|
/** Default number of lines to return (tail). */
|
|
6616
6616
|
const DEFAULT_TAIL_LINES = 200;
|
|
@@ -11929,4 +11929,4 @@ function describeFactorySandbox(sandbox) {
|
|
|
11929
11929
|
}
|
|
11930
11930
|
};
|
|
11931
11931
|
}
|
|
11932
|
-
export {
|
|
11932
|
+
export { SandboxExecutionError as $, requireFilesystem as A, UnsupportedStdinCloseError as B, DEFAULT_TAIL_LINES as C, editFileTool as D, browserCliHandler as E, getRecommendedIsolation as F, validateSandboxFileMode as G, assertModesUnsupported as H, isIsolationAvailable as I, IsolationUnavailableError as J, MountManager as K, SandboxProcessManager as L, requireWorkspace as M, LocalSandbox as N, deleteFileTool as O, detectIsolation as P, SandboxError as Q, MastraSandbox as R, executeCommandTool as S, BrowserCliHandler as T, supportsComputer as U, MAX_SANDBOX_FILE_MODE as V, supportsNetworking as W, MountNotSupportedError as X, MountError as Y, SandboxAbortError as Z, readFileTool as _, normalizeFactorySandboxSettings as a, LocalFilesystem as at, indexContentTool as b, formatSkillActivation as c, callLifecycle as ct, CompositeVersionedSkillSource as d, sliceByTokensSafe as dt, SandboxNotReadyError as et, VersionedSkillSource as f, estimateTokenCount as ft, searchTool as g, writeFileTool as h, isFactorySandbox as i, normalizeReadTrackerPath as it, requireSandbox as j, applyPatchTool as k, collectSkillForPublish as l, WORKSPACE_TOOLS as lt, resolveToolConfig as m, shellQuote as mt, FactorySandbox as n, SandboxUnsupportedFeatureError as nt, Workspace as o, MastraFilesystem as ot, createWorkspaceTools as p, sliceByTokens as pt, FilesystemNotMountableError as q, describeFactorySandbox as r, evaluateReadRecord as rt, createSkillTools as s, CompositeFilesystem as st, FACTORY_SANDBOX_BRAND as t, SandboxTimeoutError as tt, publishSkillFromSource as u, WORKSPACE_TOOLS_PREFIX as ut, mkdirTool as v, truncateOutput as w, fileStatTool as x, listFilesTool as y, ProcessHandle as z };
|