@mastra/core 1.86.0-alpha.6 → 1.86.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/@internal_core@0.1.4/dist/memory/index.d.ts +25 -0
- package/dist/agent/agent.d.ts +87 -12
- package/dist/agent/agent.types.d.ts +34 -2
- package/dist/agent/durable/create-durable-agent.d.ts +1 -1
- package/dist/agent/durable/create-evented-agent.d.ts +6 -0
- package/dist/agent/durable/durable-agent.d.ts +30 -514
- 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 +61 -6351
- package/dist/agent/durable/index.d.ts +3 -2
- package/dist/agent/durable/index.js +50 -6340
- 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 +30 -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-B7POPub5.js} +9 -9
- package/dist/{agent-controller-6ORqG6hK.cjs → agent-controller-DEPayioq.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-Da0c3R-J.cjs → background-tasks-7iftnRK_.cjs} +1 -1
- package/dist/{background-tasks-CEglmAt7.js → background-tasks-Cv1ecD6S.js} +1 -1
- package/dist/browser/index.cjs +2 -2
- package/dist/browser/index.js +2 -2
- package/dist/{builder-DS826dWf.cjs → builder-DuJBbQDH.cjs} +3 -3
- package/dist/{builder-0V9N8S15.js → builder-Gg-xnX_E.js} +3 -3
- package/dist/capabilities/302ai.json +198 -198
- package/dist/capabilities/abliteratedllm.json +38 -38
- package/dist/capabilities/abliteration-ai.json +6 -6
- package/dist/capabilities/above.json +23 -23
- package/dist/capabilities/adaption.json +14 -14
- package/dist/capabilities/adzuki.json +22 -22
- package/dist/capabilities/agentrouter.json +7 -7
- package/dist/capabilities/agnes.json +2 -2
- package/dist/capabilities/ai-router.json +5 -5
- package/dist/capabilities/aiand.json +23 -23
- package/dist/capabilities/aigrow.json +15 -15
- package/dist/capabilities/aimlapi.json +143 -143
- package/dist/capabilities/aipg.json +2 -2
- package/dist/capabilities/aixy.json +16 -16
- package/dist/capabilities/aki-io.json +12 -12
- package/dist/capabilities/alibaba-cn.json +84 -84
- 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 +51 -51
- package/dist/capabilities/alibaba-token-plan.json +52 -52
- package/dist/capabilities/alibaba.json +69 -69
- package/dist/capabilities/ambient.json +12 -12
- package/dist/capabilities/amd.json +10 -10
- package/dist/capabilities/anthropic.json +64 -40
- package/dist/capabilities/anyapi.json +12 -12
- package/dist/capabilities/apiko.json +5 -5
- package/dist/capabilities/arcee.json +7 -7
- package/dist/capabilities/augure.json +8 -8
- package/dist/capabilities/auriko.json +21 -21
- package/dist/capabilities/bailing.json +2 -2
- package/dist/capabilities/baseten.json +26 -26
- package/dist/capabilities/bee.json +4 -4
- package/dist/capabilities/berget.json +4 -4
- package/dist/capabilities/bothub.json +17 -17
- package/dist/capabilities/boundless.json +41 -41
- package/dist/capabilities/bumo.json +43 -43
- package/dist/capabilities/byteplus.json +31 -31
- package/dist/capabilities/cerebras.json +4 -4
- package/dist/capabilities/cheapaimodel.json +6 -6
- package/dist/capabilities/cheapest-token.json +32 -32
- package/dist/capabilities/chutes.json +10 -10
- package/dist/capabilities/cline-pass.json +43 -43
- package/dist/capabilities/cloudcode.json +8 -8
- package/dist/capabilities/cloudferro-sherlock.json +4 -4
- package/dist/capabilities/cloudflare-workers-ai.json +31 -31
- package/dist/capabilities/commandcode.json +151 -151
- package/dist/capabilities/concentrate.json +287 -263
- package/dist/capabilities/cortecs.json +106 -106
- package/dist/capabilities/crossmodel.json +189 -189
- package/dist/capabilities/crusoe.json +3 -3
- package/dist/capabilities/daoxe.json +9 -9
- package/dist/capabilities/databricks.json +62 -62
- package/dist/capabilities/deepinfra.json +97 -88
- package/dist/capabilities/deepseek.json +3 -3
- package/dist/capabilities/digitalocean.json +114 -114
- package/dist/capabilities/dothoosh.json +36 -36
- package/dist/capabilities/doubleword.json +29 -29
- package/dist/capabilities/edenai.json +443 -442
- package/dist/capabilities/empiriolabs.json +172 -172
- package/dist/capabilities/engy.json +20 -20
- package/dist/capabilities/entrim.json +8 -8
- package/dist/capabilities/evroc.json +15 -15
- package/dist/capabilities/ezkielyna.json +7 -7
- package/dist/capabilities/fastrouter.json +82 -82
- package/dist/capabilities/fireworks-ai.json +50 -50
- package/dist/capabilities/freemodel.json +24 -24
- package/dist/capabilities/friendli.json +6 -6
- package/dist/capabilities/frogbot.json +98 -98
- package/dist/capabilities/gisoo.json +20 -20
- package/dist/capabilities/gmicloud.json +14 -14
- package/dist/capabilities/google.json +60 -60
- package/dist/capabilities/graphn.json +12 -12
- package/dist/capabilities/greenpt.json +33 -33
- package/dist/capabilities/groq.json +9 -9
- package/dist/capabilities/helicone.json +81 -81
- package/dist/capabilities/hopper.json +2 -2
- package/dist/capabilities/hostinger-router.json +12 -12
- package/dist/capabilities/hpc-ai.json +10 -10
- package/dist/capabilities/huawei-maas.json +15 -15
- package/dist/capabilities/hubris.json +27 -27
- package/dist/capabilities/huggingface.json +59 -50
- package/dist/capabilities/humain.json +2 -2
- package/dist/capabilities/hyper.json +25 -25
- package/dist/capabilities/impossibl.json +140 -140
- package/dist/capabilities/inception.json +2 -2
- package/dist/capabilities/inceptron.json +8 -8
- package/dist/capabilities/inco.json +4 -4
- package/dist/capabilities/infer.json +14 -14
- package/dist/capabilities/inferall.json +7 -7
- package/dist/capabilities/inference-coop.json +15 -15
- package/dist/capabilities/inferenceapis.json +18 -18
- package/dist/capabilities/inferris.json +4 -4
- package/dist/capabilities/infersia.json +13 -13
- package/dist/capabilities/infomaniak.json +2 -2
- package/dist/capabilities/io-net.json +5 -5
- package/dist/capabilities/isoquant.json +4 -4
- package/dist/capabilities/iteracompute.json +54 -54
- package/dist/capabilities/jalapeno.json +12 -12
- package/dist/capabilities/jiekou.json +63 -63
- package/dist/capabilities/joingonka.json +4 -4
- package/dist/capabilities/jzstoken.json +56 -56
- package/dist/capabilities/keln.json +27 -27
- package/dist/capabilities/kenari.json +117 -111
- package/dist/capabilities/kilo.json +625 -649
- package/dist/capabilities/kimi-code-plan-cn.json +6 -6
- package/dist/capabilities/kimi-code-plan-global.json +6 -6
- package/dist/capabilities/kitani.json +6 -6
- package/dist/capabilities/klavo.json +21 -21
- package/dist/capabilities/korouter.json +33 -33
- package/dist/capabilities/kunavo.json +9 -9
- package/dist/capabilities/liquid.json +8 -8
- package/dist/capabilities/lithosai.json +3 -3
- package/dist/capabilities/llmgateway-providers.json +932 -905
- package/dist/capabilities/llmgateway.json +343 -343
- package/dist/capabilities/llmtr.json +25 -25
- package/dist/capabilities/longcat.json +2 -2
- package/dist/capabilities/lowrouter.json +48 -48
- package/dist/capabilities/lyceum.json +13 -13
- package/dist/capabilities/melious.json +13 -13
- package/dist/capabilities/merge-gateway.json +294 -294
- package/dist/capabilities/meta.json +10 -10
- package/dist/capabilities/minimax-cn-coding-plan.json +6 -6
- package/dist/capabilities/minimax-coding-plan.json +6 -6
- package/dist/capabilities/mistral.json +20 -20
- package/dist/capabilities/mixlayer.json +3 -3
- package/dist/capabilities/modal.json +14 -14
- package/dist/capabilities/model-oracle-ai.json +19 -19
- package/dist/capabilities/modelis.json +19 -19
- package/dist/capabilities/modular.json +5 -5
- package/dist/capabilities/moneo.json +17 -17
- package/dist/capabilities/moonshotai-cn.json +5 -5
- package/dist/capabilities/moonshotai.json +5 -5
- package/dist/capabilities/morph.json +14 -14
- package/dist/capabilities/munito-eu.json +8 -8
- package/dist/capabilities/munito.json +10 -10
- package/dist/capabilities/nan.json +28 -28
- package/dist/capabilities/nano-gpt.json +597 -567
- package/dist/capabilities/nearai.json +89 -89
- package/dist/capabilities/nebius.json +40 -31
- package/dist/capabilities/neon.json +135 -135
- package/dist/capabilities/neuralwatt.json +39 -39
- package/dist/capabilities/nokeep.json +2 -2
- package/dist/capabilities/novita-ai.json +158 -158
- package/dist/capabilities/nvidia.json +35 -35
- package/dist/capabilities/oathbreaker.json +2 -2
- package/dist/capabilities/obscurify.json +26 -26
- package/dist/capabilities/oci.json +6 -6
- package/dist/capabilities/ofox.json +352 -352
- package/dist/capabilities/ollama-cloud.json +52 -52
- package/dist/capabilities/openai.json +49 -56
- package/dist/capabilities/opencode-go.json +82 -81
- package/dist/capabilities/openreason.json +5 -5
- package/dist/capabilities/openrouter.json +557 -567
- package/dist/capabilities/opper.json +28 -22
- package/dist/capabilities/orcarouter.json +230 -230
- package/dist/capabilities/outerlabs.json +33 -33
- package/dist/capabilities/ovhcloud.json +6 -6
- package/dist/capabilities/pareto.json +6 -6
- package/dist/capabilities/perplexity-agent.json +58 -58
- package/dist/capabilities/perplexity.json +2 -2
- package/dist/capabilities/phala.json +22 -22
- package/dist/capabilities/pioneer.json +30 -30
- package/dist/capabilities/poe.json +122 -122
- package/dist/capabilities/poolside.json +3 -3
- package/dist/capabilities/powerspring.json +10 -10
- package/dist/capabilities/primalabs.json +8 -8
- package/dist/capabilities/prime.json +114 -97
- package/dist/capabilities/privatemode-ai.json +11 -11
- package/dist/capabilities/proxystacks.json +7 -7
- package/dist/capabilities/qiniu-ai.json +13 -13
- package/dist/capabilities/refuseless.json +7 -7
- package/dist/capabilities/regolo-ai.json +6 -6
- package/dist/capabilities/requesty.json +172 -189
- package/dist/capabilities/ruapi.json +18 -18
- package/dist/capabilities/runcrate.json +17 -17
- package/dist/capabilities/runinfra.json +16 -16
- package/dist/capabilities/sakana.json +6 -6
- package/dist/capabilities/sambanova.json +4 -4
- package/dist/capabilities/sandbase.json +24 -24
- package/dist/capabilities/sarvam.json +12 -12
- package/dist/capabilities/scaleway.json +19 -19
- package/dist/capabilities/scnet-token-plan.json +10 -10
- package/dist/capabilities/scx-ai.json +23 -23
- package/dist/capabilities/sensenova.json +14 -14
- package/dist/capabilities/siliconflow-cn.json +64 -64
- package/dist/capabilities/siliconflow.json +63 -63
- package/dist/capabilities/snowflake-cortex.json +23 -23
- package/dist/capabilities/sokkan.json +12 -12
- package/dist/capabilities/sparrowcodes.json +23 -23
- package/dist/capabilities/standardcompute.json +83 -83
- package/dist/capabilities/steadyrouter.json +39 -39
- package/dist/capabilities/stepfun-ai-step-plan.json +5 -5
- package/dist/capabilities/stepfun-ai.json +5 -5
- package/dist/capabilities/stepfun-step-plan.json +5 -5
- package/dist/capabilities/stepfun.json +5 -5
- package/dist/capabilities/stepping-stone.json +16 -16
- package/dist/capabilities/superbot-gg.json +4 -4
- package/dist/capabilities/synthetic.json +14 -14
- package/dist/capabilities/synthorai.json +29 -29
- package/dist/capabilities/teamorouter.json +26 -26
- package/dist/capabilities/teapot-router.json +13 -13
- package/dist/capabilities/tencent-coding-plan.json +2 -2
- package/dist/capabilities/tencent-token-plan.json +30 -30
- package/dist/capabilities/tencent-tokenhub.json +8 -8
- package/dist/capabilities/tensorx.json +45 -45
- package/dist/capabilities/tenstorrent.json +8 -8
- package/dist/capabilities/the-grid-ai.json +35 -35
- package/dist/capabilities/thinkingmachines.json +59 -59
- package/dist/capabilities/tinfoil.json +5 -5
- package/dist/capabilities/toapis.json +2 -2
- package/dist/capabilities/togetherai.json +59 -59
- package/dist/capabilities/tokengo.json +24 -24
- package/dist/capabilities/tokenify.json +9 -9
- package/dist/capabilities/trustedrouter.json +5 -5
- package/dist/capabilities/trustedtokens.json +18 -18
- package/dist/capabilities/umans-ai-coding-plan.json +18 -18
- package/dist/capabilities/umans-ai.json +15 -15
- package/dist/capabilities/uncensuredai.json +4 -4
- package/dist/capabilities/unrestricted.json +4 -4
- package/dist/capabilities/uplinkswitch.json +21 -21
- package/dist/capabilities/upstage.json +7 -7
- package/dist/capabilities/vancine.json +20 -20
- package/dist/capabilities/vercel.json +568 -576
- package/dist/capabilities/vivgrid.json +78 -78
- package/dist/capabilities/volcengine-coding-plan.json +30 -30
- package/dist/capabilities/volcengine.json +35 -35
- package/dist/capabilities/vultr.json +27 -27
- package/dist/capabilities/wafer.ai.json +16 -16
- package/dist/capabilities/wallaby.json +5 -5
- package/dist/capabilities/wally.json +11 -11
- package/dist/capabilities/wandb.json +21 -21
- package/dist/capabilities/watt.json +26 -26
- package/dist/capabilities/xai.json +7 -7
- 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 +12 -12
- package/dist/capabilities/xxapi.json +31 -31
- package/dist/capabilities/zai-coding-plan.json +13 -13
- package/dist/capabilities/zai.json +27 -27
- package/dist/capabilities/zenifra.json +27 -27
- package/dist/capabilities/zenmux.json +195 -195
- package/dist/capabilities/zerogpu.json +12 -12
- package/dist/capabilities/zhipuai-coding-plan.json +8 -8
- package/dist/capabilities/zhipuai.json +27 -27
- package/dist/capabilities/zro.json +6 -6
- 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-BRVCOutx.js} +1 -1
- package/dist/{channels-B57qQolh.cjs → channels-MjTA9bFp.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/dataset.d.ts +13 -6
- package/dist/datasets/experiment/durable.d.ts +16 -0
- package/dist/datasets/experiment/index.d.ts +2 -1
- package/dist/datasets/experiment/item.d.ts +26 -4
- package/dist/datasets/experiment/retries.d.ts +18 -0
- package/dist/datasets/experiment/types.d.ts +18 -0
- package/dist/datasets/experiment/workflow-id.d.ts +7 -0
- package/dist/datasets/experiment/workflow.d.ts +74 -0
- package/dist/datasets/index.cjs +3 -2
- package/dist/datasets/index.d.ts +2 -1
- package/dist/datasets/index.js +3 -3
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1309 -1304
- package/dist/docs/references/docs-deployment-workers.md +1 -1
- package/dist/docs/references/docs-evals-experiments.md +29 -1
- package/dist/docs/references/docs-harness-durable-agents.md +9 -5
- package/dist/docs/references/docs-knowledge-agents-and-tools.md +1 -0
- package/dist/docs/references/docs-knowledge-load-your-content.md +1 -1
- package/dist/docs/references/docs-mastra-platform-observability-overview.md +1 -1
- package/dist/docs/references/docs-server-pubsub.md +51 -8
- package/dist/docs/references/docs-signals-running-across-processes.md +2 -0
- package/dist/docs/references/docs-workflows-overview.md +1 -1
- package/dist/docs/references/docs-workflows-scheduled-workflows.md +1 -1
- package/dist/docs/references/integrations-channels-slack.md +4 -2
- package/dist/docs/references/integrations.md +6 -0
- package/dist/docs/references/reference-agents-agent.md +3 -1
- package/dist/docs/references/reference-agents-channels.md +146 -24
- package/dist/docs/references/reference-agents-durable-agent.md +28 -2
- package/dist/docs/references/reference-datasets-runExperimentItem.md +13 -1
- package/dist/docs/references/reference-datasets-startExperimentAsync.md +3 -1
- package/dist/docs/references/reference-editor-mastra-editor.md +3 -1
- package/dist/docs/references/reference-knowledge-knowledge-class.md +2 -2
- package/dist/docs/references/reference-knowledge-knowledge-tools.md +43 -20
- package/dist/docs/references/reference-processors-moderation-processor.md +2 -2
- package/dist/docs/references/reference-pubsub-base.md +5 -1
- package/dist/docs/references/reference-pubsub-event-emitter.md +2 -0
- package/dist/docs/references/reference-pubsub-redis-streams.md +1 -1
- package/dist/docs/references/reference-pubsub-unix-socket-pubsub.md +2 -0
- package/dist/docs/references/reference-streaming-ChunkType.md +1 -1
- package/dist/docs/references/reference-workers-overview.md +1 -1
- package/dist/docs/references/reference-workflows-run-methods-start.md +23 -0
- package/dist/docs/references/reference-workflows-run-methods-timeTravel.md +4 -0
- package/dist/docs/references/reference-workflows-run.md +1 -1
- 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/caching-pubsub.d.ts +1 -0
- package/dist/events/event-emitter/index.d.ts +12 -5
- package/dist/events/index.cjs +15 -1
- package/dist/events/index.js +15 -1
- package/dist/events/pubsub.d.ts +29 -0
- package/dist/events/reach.d.ts +11 -0
- package/dist/events/unix-socket-pubsub.d.ts +14 -0
- 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 +7720 -7720
- package/dist/llm/model/shared.types.d.ts +31 -0
- package/dist/{llm-B0VtQDgT.js → llm-Djd8Qzi0.js} +2 -2
- package/dist/{llm-ByskI6z3.cjs → llm-DmUucguC.cjs} +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-execution/llm-execution-step.d.ts +2 -2
- package/dist/loop/workflows/agentic-loop/index.d.ts +1 -1
- package/dist/{manager-C2RGNH68.js → manager-CO_Xz2zR.js} +461 -95
- package/dist/{manager-BJKx4lQf.cjs → manager-D27PkIPo.cjs} +477 -93
- package/dist/mastra/index.cjs +1 -1
- package/dist/mastra/index.d.ts +13 -0
- package/dist/mastra/index.js +1 -1
- package/dist/{mastra-zUTq9ilk.js → mastra-Ch00nEAJ.js} +66 -25
- package/dist/{mastra-FXCeC5rF.cjs → mastra-qsVWpOTi.cjs} +66 -25
- package/dist/memory/index.cjs +2 -2
- package/dist/memory/index.js +2 -2
- package/dist/{model-BTNRPDgQ.js → model-CW-mfGYA.js} +1 -1
- package/dist/{model-BmTFNo62.cjs → model-Do6DTJoj.cjs} +1 -1
- package/dist/{netlify-B_XdjYPY.cjs → netlify-DU32SDT6.cjs} +1 -1
- package/dist/{netlify-BCSVhO5q.js → netlify-DZSAbdve.js} +1 -1
- package/dist/notifications/index.cjs +1 -1
- package/dist/notifications/index.js +1 -1
- package/dist/{output-helpers-CncZ3y-g.cjs → output-helpers-1Zu4Vt9C.cjs} +112 -69
- package/dist/{output-helpers-RlvE2WPA.js → output-helpers-CedRCE17.js} +113 -70
- 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-Ble43Wb4.js → provider-registry-deA0x-Gd.js} +21349 -21338
- package/dist/{provider-registry-D8O1G18A.cjs → provider-registry-zGezZVsL.cjs} +21349 -21338
- package/dist/provider-registry.json +21695 -21680
- package/dist/{registry-generator-BQ1noftK.cjs → registry-generator-BkQ1AxZn.cjs} +1 -1
- package/dist/{registry-generator-D1Zslex6.js → registry-generator-VvBfOKAD.js} +1 -1
- package/dist/{rehydrate-CgxEur9m.js → rehydrate-BjLV643n.js} +2 -2
- package/dist/{rehydrate-BiA_HUJH.cjs → rehydrate-DDYFpQsV.cjs} +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-5Suldxz3.cjs} +83965 -77543
- package/dist/{run-registry-BUFmc_78.js → run-registry-CGRPldLH.js} +84057 -77017
- 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/knowledge/base.d.ts +5 -0
- package/dist/storage/domains/knowledge/inmemory.d.ts +1 -0
- package/dist/storage/domains/knowledge/pages.d.ts +24 -7
- 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/base/output.d.ts +42 -15
- package/dist/stream/index.cjs +2 -2
- package/dist/stream/index.js +2 -2
- package/dist/stream/types.d.ts +19 -0
- package/dist/{stream-S_NC5v9e.js → stream-Dpwx0whf.js} +1 -1
- package/dist/{stream-DUrp3Fcy.cjs → stream-Dvy_0o14.cjs} +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-BhCzpGfr.js → tool-loop-agent-PbWrEj1k.js} +3 -3
- package/dist/{tool-loop-agent-DU0BiemT.cjs → tool-loop-agent-UxOv3FoK.cjs} +3 -3
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/types.d.ts +27 -1
- package/dist/{utils-CeEt4K7t.cjs → utils-BbMTlyBO.cjs} +1 -1
- package/dist/{utils-DYIai19q.js → utils-BnNi1BYM.js} +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{validate-BRikrNhF.js → validate-HSBcm96b.js} +1 -1
- package/dist/{validate-BckgxuJ0.cjs → validate-Skps-cM3.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-BfhUD77l.cjs → worker-BE-0DyKL.cjs} +3 -3
- package/dist/{worker-DcBfwJqD.js → worker-BKrKHZzU.js} +3 -3
- package/dist/{worker-D9WwmcJa.cjs → worker-BNS5A3qP.cjs} +3 -3
- package/dist/{worker-Du5ybt5o.js → worker-DehaD4qD.js} +3 -3
- package/dist/{workflow-BWV5m9Mx.cjs → workflow-BjUTwaK9.cjs} +4 -4
- package/dist/{workflow-jNWVBYDJ.js → workflow-Bvw6yDjc.js} +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/setup-warning.d.ts +18 -0
- package/dist/workflows/evented/workflow-event-processor/run-status.d.ts +37 -0
- package/dist/workflows/evented/workflow.d.ts +11 -1
- package/dist/workflows/index.cjs +6 -6
- package/dist/workflows/index.js +6 -6
- package/dist/workflows/workflow.d.ts +6 -1
- package/dist/workspace/index.cjs +2 -2
- package/dist/workspace/index.js +2 -2
- package/dist/{workspace-D7JRhn1Z.js → workspace-C05xDH60.js} +564 -411
- package/dist/{workspace-BQ2wZj5D.cjs → workspace-D1OzzlLw.cjs} +564 -411
- package/dist/{workspace-skills-CGiXfKzA.js → workspace-skills-38OY32_b.js} +531 -531
- package/package.json +6 -6
- package/src/llm/model/provider-types.generated.d.ts +7720 -7720
- 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/{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,6 +112,307 @@ 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
|
+
// ../../../../../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
|
|
131
|
+
},
|
|
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
|
|
135
|
+
},
|
|
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
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
pattern: /[\u0430-\u044F\u0451]/i,
|
|
142
|
+
averageCharsPerToken: 4
|
|
143
|
+
},
|
|
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
|
+
];
|
|
153
|
+
/**
|
|
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).
|
|
157
|
+
*/
|
|
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++;
|
|
195
|
+
}
|
|
196
|
+
return otherCount + Math.ceil(kanaCount / KANA_CHARS_PER_TOKEN);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Estimates the number of tokens in a text string using heuristic rules
|
|
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
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Extracts a portion of text based on token positions, similar to Array.prototype.slice()
|
|
209
|
+
*/
|
|
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;
|
|
218
|
+
}
|
|
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;
|
|
229
|
+
}
|
|
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
|
+
};
|
|
115
416
|
// src/workspace/constants/index.ts
|
|
116
417
|
const WORKSPACE_TOOLS_PREFIX = "mastra_workspace";
|
|
117
418
|
/**
|
|
@@ -5876,263 +6177,106 @@ const computerScrollTool = createTool({
|
|
|
5876
6177
|
},
|
|
5877
6178
|
attributes: { sandboxProvider: sandbox.provider }
|
|
5878
6179
|
});
|
|
5879
|
-
try {
|
|
5880
|
-
await computer.scroll(direction, effectiveAmount);
|
|
5881
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.SCROLL, `Scrolled ${direction} by ${effectiveAmount}`);
|
|
5882
|
-
span.end({ success: true });
|
|
5883
|
-
return result;
|
|
5884
|
-
} catch (err) {
|
|
5885
|
-
span.error(err);
|
|
5886
|
-
throw err;
|
|
5887
|
-
}
|
|
5888
|
-
},
|
|
5889
|
-
toModelOutput: mediaToModelOutput
|
|
5890
|
-
});
|
|
5891
|
-
// src/workspace/tools/computer-type.ts
|
|
5892
|
-
const computerTypeTool = createTool({
|
|
5893
|
-
id: WORKSPACE_TOOLS.COMPUTER.TYPE,
|
|
5894
|
-
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).",
|
|
5895
|
-
inputSchema: z.object({ text: z.string().describe("The text to type") }),
|
|
5896
|
-
execute: async ({ text }, context) => {
|
|
5897
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5898
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.TYPE);
|
|
5899
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5900
|
-
category: "computer",
|
|
5901
|
-
operation: "type",
|
|
5902
|
-
input: { length: text.length },
|
|
5903
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5904
|
-
});
|
|
5905
|
-
try {
|
|
5906
|
-
await computer.type(text);
|
|
5907
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.TYPE, `Typed ${text.length} characters`);
|
|
5908
|
-
span.end({ success: true });
|
|
5909
|
-
return result;
|
|
5910
|
-
} catch (err) {
|
|
5911
|
-
span.error(err);
|
|
5912
|
-
throw err;
|
|
5913
|
-
}
|
|
5914
|
-
},
|
|
5915
|
-
toModelOutput: mediaToModelOutput
|
|
5916
|
-
});
|
|
5917
|
-
// src/workspace/tools/computer-wait.ts
|
|
5918
|
-
const computerWaitTool = createTool({
|
|
5919
|
-
id: WORKSPACE_TOOLS.COMPUTER.WAIT,
|
|
5920
|
-
description: "Wait for the sandbox desktop UI to settle (e.g. an application launching or a page loading) before the next action.",
|
|
5921
|
-
inputSchema: z.object({ seconds: z.number().min(.1).max(30).describe("How long to wait, in seconds (max 30)") }),
|
|
5922
|
-
execute: async ({ seconds }, context) => {
|
|
5923
|
-
const { workspace, sandbox, computer } = requireComputer(context);
|
|
5924
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.COMPUTER.WAIT);
|
|
5925
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5926
|
-
category: "computer",
|
|
5927
|
-
operation: "wait",
|
|
5928
|
-
input: { seconds },
|
|
5929
|
-
attributes: { sandboxProvider: sandbox.provider }
|
|
5930
|
-
});
|
|
5931
|
-
try {
|
|
5932
|
-
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
|
|
5933
|
-
const result = await finishComputerAction(workspace, computer, WORKSPACE_TOOLS.COMPUTER.WAIT, `Waited ${seconds}s`);
|
|
5934
|
-
span.end({ success: true });
|
|
5935
|
-
return result;
|
|
5936
|
-
} catch (err) {
|
|
5937
|
-
span.error(err);
|
|
5938
|
-
throw err;
|
|
5939
|
-
}
|
|
5940
|
-
},
|
|
5941
|
-
toModelOutput: mediaToModelOutput
|
|
5942
|
-
});
|
|
5943
|
-
// src/workspace/tools/delete-file.ts
|
|
5944
|
-
const deleteFileTool = createTool({
|
|
5945
|
-
id: WORKSPACE_TOOLS.FILESYSTEM.DELETE,
|
|
5946
|
-
description: "Delete a file or directory from the workspace filesystem",
|
|
5947
|
-
outputSchema: z.string(),
|
|
5948
|
-
inputSchema: z.object({
|
|
5949
|
-
path: z.string().describe("The path to the file or directory to delete"),
|
|
5950
|
-
recursive: z.boolean().optional().default(false).describe("If true, delete directories and their contents recursively. Required for non-empty directories.")
|
|
5951
|
-
}),
|
|
5952
|
-
execute: async ({ path, recursive }, context) => {
|
|
5953
|
-
const { workspace, filesystem } = requireFilesystem(context);
|
|
5954
|
-
await emitWorkspaceMetadata(context, WORKSPACE_TOOLS.FILESYSTEM.DELETE);
|
|
5955
|
-
const span = startWorkspaceSpan(context, workspace, {
|
|
5956
|
-
category: "filesystem",
|
|
5957
|
-
operation: "delete",
|
|
5958
|
-
input: {
|
|
5959
|
-
path,
|
|
5960
|
-
recursive
|
|
5961
|
-
},
|
|
5962
|
-
attributes: { filesystemProvider: filesystem.provider }
|
|
5963
|
-
});
|
|
5964
|
-
try {
|
|
5965
|
-
if (filesystem.readOnly) throw new WorkspaceReadOnlyError("delete");
|
|
5966
|
-
if ((await filesystem.stat(path)).type === "directory") await filesystem.rmdir(path, {
|
|
5967
|
-
recursive,
|
|
5968
|
-
force: recursive
|
|
5969
|
-
});
|
|
5970
|
-
else await filesystem.deleteFile(path);
|
|
5971
|
-
span.end({ success: true });
|
|
5972
|
-
return `Deleted ${path}`;
|
|
5973
|
-
} catch (err) {
|
|
5974
|
-
span.error(err);
|
|
5975
|
-
throw err;
|
|
5976
|
-
}
|
|
5977
|
-
}
|
|
5978
|
-
});
|
|
5979
|
-
// src/workspace/line-utils.ts
|
|
5980
|
-
/**
|
|
5981
|
-
* Extract lines from content by line range.
|
|
5982
|
-
*
|
|
5983
|
-
* @param content - The document content
|
|
5984
|
-
* @param startLine - Starting line number (1-indexed)
|
|
5985
|
-
* @param endLine - Ending line number (1-indexed, inclusive)
|
|
5986
|
-
* @returns Object with extracted content and metadata
|
|
5987
|
-
*/
|
|
5988
|
-
function extractLines(content, startLine, endLine) {
|
|
5989
|
-
const allLines = content.split("\n");
|
|
5990
|
-
const totalLines = allLines.length;
|
|
5991
|
-
const start = Math.max(1, startLine ?? 1);
|
|
5992
|
-
const end = Math.min(totalLines, endLine ?? totalLines);
|
|
5993
|
-
if (start > end) return {
|
|
5994
|
-
content: "",
|
|
5995
|
-
lines: {
|
|
5996
|
-
start: 0,
|
|
5997
|
-
end: 0
|
|
5998
|
-
},
|
|
5999
|
-
totalLines
|
|
6000
|
-
};
|
|
6001
|
-
return {
|
|
6002
|
-
content: allLines.slice(start - 1, end).join("\n"),
|
|
6003
|
-
lines: {
|
|
6004
|
-
start,
|
|
6005
|
-
end
|
|
6006
|
-
},
|
|
6007
|
-
totalLines
|
|
6008
|
-
};
|
|
6009
|
-
}
|
|
6010
|
-
/**
|
|
6011
|
-
* Extract lines using offset/limit style parameters (like Claude Code).
|
|
6012
|
-
*
|
|
6013
|
-
* @param content - The document content
|
|
6014
|
-
* @param offset - Line number to start from (1-indexed, default: 1)
|
|
6015
|
-
* @param limit - Maximum number of lines to read (default: all remaining)
|
|
6016
|
-
* @returns Object with extracted content and metadata
|
|
6017
|
-
*/
|
|
6018
|
-
function extractLinesWithLimit(content, offset, limit) {
|
|
6019
|
-
const startLine = offset ?? 1;
|
|
6020
|
-
return extractLines(content, startLine, limit ? startLine + limit - 1 : void 0);
|
|
6021
|
-
}
|
|
6022
|
-
/**
|
|
6023
|
-
* Format content with line number prefixes.
|
|
6024
|
-
* Output format matches Claude Code: " 1→content here"
|
|
6025
|
-
*
|
|
6026
|
-
* @param content - The content to format
|
|
6027
|
-
* @param startLineNumber - The line number of the first line (1-indexed)
|
|
6028
|
-
* @returns Formatted content with line numbers
|
|
6029
|
-
*/
|
|
6030
|
-
function formatWithLineNumbers(content, startLineNumber = 1) {
|
|
6031
|
-
const lines = content.split("\n");
|
|
6032
|
-
const maxLineNum = startLineNumber + lines.length - 1;
|
|
6033
|
-
const padWidth = Math.max(6, String(maxLineNum).length + 1);
|
|
6034
|
-
return lines.map((line, i) => {
|
|
6035
|
-
const lineNum = startLineNumber + i;
|
|
6036
|
-
return `${String(lineNum).padStart(padWidth)}\u2192${line}`;
|
|
6037
|
-
}).join("\n");
|
|
6038
|
-
}
|
|
6039
|
-
/**
|
|
6040
|
-
* Convert a character index to a line number.
|
|
6041
|
-
* Useful for converting RAG chunk character offsets to line numbers.
|
|
6042
|
-
*
|
|
6043
|
-
* @param content - The full document content
|
|
6044
|
-
* @param charIndex - The character index (0-indexed)
|
|
6045
|
-
* @returns The line number (1-indexed), or undefined if charIndex is out of bounds
|
|
6046
|
-
*/
|
|
6047
|
-
function charIndexToLineNumber(content, charIndex) {
|
|
6048
|
-
if (charIndex < 0 || charIndex > content.length) return;
|
|
6049
|
-
let lineNumber = 1;
|
|
6050
|
-
for (let i = 0; i < charIndex && i < content.length; i++) if (content[i] === "\n") lineNumber++;
|
|
6051
|
-
return lineNumber;
|
|
6052
|
-
}
|
|
6053
|
-
/**
|
|
6054
|
-
* Convert character range to line range.
|
|
6055
|
-
* Useful for converting RAG chunk character offsets to line ranges.
|
|
6056
|
-
*
|
|
6057
|
-
* @param content - The full document content
|
|
6058
|
-
* @param startCharIdx - Start character index (0-indexed)
|
|
6059
|
-
* @param endCharIdx - End character index (0-indexed, exclusive)
|
|
6060
|
-
* @returns LineRange (1-indexed) or undefined if indices are out of bounds
|
|
6061
|
-
*/
|
|
6062
|
-
function charRangeToLineRange(content, startCharIdx, endCharIdx) {
|
|
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";
|
|
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;
|
|
@@ -6685,6 +6685,159 @@ function splitTail(output, tail) {
|
|
|
6685
6685
|
};
|
|
6686
6686
|
}
|
|
6687
6687
|
/**
|
|
6688
|
+
* tokenx is synchronous and allocates per word, so running it over a multi-MB
|
|
6689
|
+
* output blocks the event loop for seconds. Outputs up to this many chars per
|
|
6690
|
+
* token of budget are counted and cut exactly as before; longer ones never reach
|
|
6691
|
+
* tokenx whole (see `countTokensOver` and `sliceEdge`).
|
|
6692
|
+
*/
|
|
6693
|
+
const WINDOW_CHARS_PER_TOKEN = 32;
|
|
6694
|
+
/**
|
|
6695
|
+
* tokenx never gives a non-whitespace segment fewer than one token per this many
|
|
6696
|
+
* UTF-16 chars: 6 by default, and up to 4 code points (8 chars when astral) for
|
|
6697
|
+
* its language rules. So text with more non-whitespace chars than
|
|
6698
|
+
* `limit * MAX_CHARS_PER_TOKEN` is over `limit`.
|
|
6699
|
+
*/
|
|
6700
|
+
const MAX_CHARS_PER_TOKEN = 8;
|
|
6701
|
+
const WHITESPACE_RUN_RE = /\s+/g;
|
|
6702
|
+
const STRUCTURED_WHITESPACE_RE = /\n\s/;
|
|
6703
|
+
const WS = 0;
|
|
6704
|
+
const PUNCT = 1;
|
|
6705
|
+
const DIGIT = 2;
|
|
6706
|
+
const WORD = 3;
|
|
6707
|
+
const CHAR_CLASS = (/* @__PURE__ */ new Uint8Array(128)).fill(WORD);
|
|
6708
|
+
for (const c of " \n\r\v\f") CHAR_CLASS[c.charCodeAt(0)] = WS;
|
|
6709
|
+
for (const c of ".,!?;(){}[]<>:/\\|@#$%^&*+=`~_\"-") CHAR_CLASS[c.charCodeAt(0)] = PUNCT;
|
|
6710
|
+
for (let c = 48; c <= 57; c++) CHAR_CLASS[c] = DIGIT;
|
|
6711
|
+
/** Same set as the regex `\s`, which is what tokenx splits words on. */
|
|
6712
|
+
function isWhitespace(code) {
|
|
6713
|
+
return code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288 || code === 65279;
|
|
6714
|
+
}
|
|
6715
|
+
function runTokens(kind, length, onlyDigits) {
|
|
6716
|
+
if (kind === WS) return 0;
|
|
6717
|
+
if (length <= 3) return 1;
|
|
6718
|
+
if (kind === PUNCT) return Math.ceil(length / 2);
|
|
6719
|
+
return onlyDigits ? Math.ceil(length / 3) : Math.ceil(length / 6);
|
|
6720
|
+
}
|
|
6721
|
+
/**
|
|
6722
|
+
* One pass over char codes with no allocations: an approximate token count
|
|
6723
|
+
* (tokenx's rules for ASCII text, used only for the "of ~N tokens" total) and
|
|
6724
|
+
* the number of non-whitespace chars.
|
|
6725
|
+
*/
|
|
6726
|
+
function scanTokens(text) {
|
|
6727
|
+
let approx = 0;
|
|
6728
|
+
let nonWhitespace = 0;
|
|
6729
|
+
let kind = -1;
|
|
6730
|
+
let length = 0;
|
|
6731
|
+
let onlyDigits = true;
|
|
6732
|
+
for (let i = 0; i < text.length; i++) {
|
|
6733
|
+
const code = text.charCodeAt(i);
|
|
6734
|
+
const cls = code < 128 ? CHAR_CLASS[code] : isWhitespace(code) ? WS : WORD;
|
|
6735
|
+
const runKind = cls === DIGIT ? WORD : cls;
|
|
6736
|
+
if (runKind !== kind) {
|
|
6737
|
+
if (length) approx += runTokens(kind, length, onlyDigits);
|
|
6738
|
+
kind = runKind;
|
|
6739
|
+
length = 0;
|
|
6740
|
+
onlyDigits = true;
|
|
6741
|
+
}
|
|
6742
|
+
length++;
|
|
6743
|
+
if (cls !== WS) nonWhitespace++;
|
|
6744
|
+
if (cls !== DIGIT) onlyDigits = false;
|
|
6745
|
+
}
|
|
6746
|
+
if (length) approx += runTokens(kind, length, onlyDigits);
|
|
6747
|
+
return {
|
|
6748
|
+
approx,
|
|
6749
|
+
nonWhitespace
|
|
6750
|
+
};
|
|
6751
|
+
}
|
|
6752
|
+
/**
|
|
6753
|
+
* Exact token count of `output` when it may fit `limit`, else an approximation.
|
|
6754
|
+
* Returns `undefined` when the output fits, so callers return it as is.
|
|
6755
|
+
*/
|
|
6756
|
+
function countTokensOver(output, limit) {
|
|
6757
|
+
if (output.length <= Math.max(limit, 1) * WINDOW_CHARS_PER_TOKEN) {
|
|
6758
|
+
const exact = estimateTokenCount(output);
|
|
6759
|
+
return exact <= limit ? void 0 : exact;
|
|
6760
|
+
}
|
|
6761
|
+
const { approx, nonWhitespace } = scanTokens(output);
|
|
6762
|
+
if (nonWhitespace > limit * MAX_CHARS_PER_TOKEN) return approx;
|
|
6763
|
+
const exact = estimateTokenCount(output.replace(WHITESPACE_RUN_RE, (run) => STRUCTURED_WHITESPACE_RE.test(run) ? "\n " : " "));
|
|
6764
|
+
return exact <= limit ? void 0 : exact;
|
|
6765
|
+
}
|
|
6766
|
+
/**
|
|
6767
|
+
* `budget` tokens from one end of `output`. Outputs within the overall `limit`'s
|
|
6768
|
+
* size cap are cut exactly as before, by `sliceByTokensSafe(output, 0, budget)`
|
|
6769
|
+
* (`'head'`) or `sliceByTokensSafe(output, -budget)` (`'tail'`). Longer ones hand
|
|
6770
|
+
* tokenx only a window at that end, measured as tokenx sees it: whitespace runs
|
|
6771
|
+
* are collapsed (see `countTokensOver`), so padding can't crowd real text out of
|
|
6772
|
+
* the window. The cut is mapped back to the original text, whitespace and all.
|
|
6773
|
+
*
|
|
6774
|
+
* For those longer outputs the cut is approximate: it fits `budget` by tokenx's
|
|
6775
|
+
* count of the kept text, but can land elsewhere than tokenizing the whole output
|
|
6776
|
+
* would. tokenx counts a segment by its whole length, so a window that ends inside
|
|
6777
|
+
* a long segment counts it differently (at a 2,000-token budget, 65,000 'a' then
|
|
6778
|
+
* 'é' keeps 12,000 chars here and 6,000 when the whole output is tokenized).
|
|
6779
|
+
*/
|
|
6780
|
+
function sliceEdge(output, budget, limit, side) {
|
|
6781
|
+
if (output.length <= Math.max(limit, 1) * WINDOW_CHARS_PER_TOKEN) return side === "head" ? sliceByTokensSafe(output, 0, budget) : sliceByTokensSafe(output, -budget);
|
|
6782
|
+
const target = Math.max(budget, 1) * WINDOW_CHARS_PER_TOKEN;
|
|
6783
|
+
let size = 0;
|
|
6784
|
+
let inWhitespace = false;
|
|
6785
|
+
let edge = side === "head" ? 0 : output.length;
|
|
6786
|
+
while (side === "head" ? edge < output.length : edge > 0) {
|
|
6787
|
+
const code = output.charCodeAt(side === "head" ? edge : edge - 1);
|
|
6788
|
+
const whitespace = code < 128 ? CHAR_CLASS[code] === WS : isWhitespace(code);
|
|
6789
|
+
const cost = whitespace ? inWhitespace ? 0 : 2 : 1;
|
|
6790
|
+
if (size + cost > target) break;
|
|
6791
|
+
size += cost;
|
|
6792
|
+
inWhitespace = whitespace;
|
|
6793
|
+
edge += side === "head" ? 1 : -1;
|
|
6794
|
+
}
|
|
6795
|
+
const window = side === "head" ? output.slice(0, edge) : output.slice(edge);
|
|
6796
|
+
const runs = [];
|
|
6797
|
+
let collapsed = "";
|
|
6798
|
+
let last = 0;
|
|
6799
|
+
for (const match of window.matchAll(WHITESPACE_RUN_RE)) {
|
|
6800
|
+
collapsed += window.slice(last, match.index);
|
|
6801
|
+
const replacement = STRUCTURED_WHITESPACE_RE.test(match[0]) ? "\n " : " ";
|
|
6802
|
+
runs.push({
|
|
6803
|
+
collapsedStart: collapsed.length,
|
|
6804
|
+
collapsedEnd: collapsed.length + replacement.length,
|
|
6805
|
+
start: match.index,
|
|
6806
|
+
end: match.index + match[0].length
|
|
6807
|
+
});
|
|
6808
|
+
collapsed += replacement;
|
|
6809
|
+
last = match.index + match[0].length;
|
|
6810
|
+
}
|
|
6811
|
+
collapsed += window.slice(last);
|
|
6812
|
+
const toWindowIndex = (index) => {
|
|
6813
|
+
let shift = 0;
|
|
6814
|
+
for (const run of runs) {
|
|
6815
|
+
if (index < run.collapsedStart) break;
|
|
6816
|
+
if (index <= run.collapsedEnd) return index === run.collapsedEnd ? run.end : run.start;
|
|
6817
|
+
shift = run.end - run.collapsedEnd;
|
|
6818
|
+
}
|
|
6819
|
+
return index + shift;
|
|
6820
|
+
};
|
|
6821
|
+
if (side === "head") return sliceSafe(window, 0, toWindowIndex(fitBudget(sliceByTokensSafe(collapsed, 0, budget), budget, side).length));
|
|
6822
|
+
const kept = fitBudget(sliceByTokensSafe(collapsed, -budget), budget, side);
|
|
6823
|
+
return sliceSafe(window, toWindowIndex(collapsed.length - kept.length));
|
|
6824
|
+
}
|
|
6825
|
+
/**
|
|
6826
|
+
* tokenx slices a segment by the chars-per-token of its language, picked from the
|
|
6827
|
+
* chars it contains, so a cut that drops the char that picked it (a lone 'ж' in a run
|
|
6828
|
+
* of CJK) can count several times over `budget` on its own. Recount the kept text,
|
|
6829
|
+
* which is no longer than the bounded input it was cut from, and cut it again until
|
|
6830
|
+
* it fits.
|
|
6831
|
+
*/
|
|
6832
|
+
function fitBudget(kept, budget, side) {
|
|
6833
|
+
for (let tokens = estimateTokenCount(kept); kept.length > 0 && tokens > budget; tokens = estimateTokenCount(kept)) {
|
|
6834
|
+
const next = side === "head" ? sliceByTokensSafe(kept, 0, budget) : sliceByTokensSafe(kept, -budget);
|
|
6835
|
+
const length = next.length < kept.length ? next.length : Math.floor(kept.length * budget / tokens);
|
|
6836
|
+
kept = side === "head" ? sliceSafe(kept, 0, length) : sliceSafe(kept, kept.length - length);
|
|
6837
|
+
}
|
|
6838
|
+
return kept;
|
|
6839
|
+
}
|
|
6840
|
+
/**
|
|
6688
6841
|
* Token-based output limit. Truncates output to fit within a token budget.
|
|
6689
6842
|
* Uses tokenx for fast token estimation and truncates at the token level
|
|
6690
6843
|
* (not line boundaries) to maximise use of the budget.
|
|
@@ -6697,9 +6850,9 @@ function splitTail(output, tail) {
|
|
|
6697
6850
|
*/
|
|
6698
6851
|
async function applyTokenLimit(output, limit = DEFAULT_MAX_OUTPUT_TOKENS, from = "start") {
|
|
6699
6852
|
if (!output) return output;
|
|
6700
|
-
const totalTokens =
|
|
6701
|
-
if (totalTokens
|
|
6702
|
-
const kept = from === "start" ?
|
|
6853
|
+
const totalTokens = countTokensOver(output, limit);
|
|
6854
|
+
if (totalTokens === void 0) return output;
|
|
6855
|
+
const kept = from === "start" ? sliceEdge(output, limit, limit, "tail") : sliceEdge(output, limit, limit, "head");
|
|
6703
6856
|
const position = from === "start" ? "last" : "first";
|
|
6704
6857
|
return from === "start" ? `[output truncated: showing ${position} ~${limit} of ~${totalTokens} tokens]\n${kept}` : `${kept}\n[output truncated: showing ${position} ~${limit} of ~${totalTokens} tokens]`;
|
|
6705
6858
|
}
|
|
@@ -6709,12 +6862,12 @@ async function applyTokenLimit(output, limit = DEFAULT_MAX_OUTPUT_TOKENS, from =
|
|
|
6709
6862
|
*/
|
|
6710
6863
|
function sandwich(output, limit, headRatio, firstLine) {
|
|
6711
6864
|
if (!output) return output;
|
|
6712
|
-
const totalTokens =
|
|
6713
|
-
if (totalTokens
|
|
6865
|
+
const totalTokens = countTokensOver(output, limit);
|
|
6866
|
+
if (totalTokens === void 0) return output;
|
|
6714
6867
|
const headBudget = Math.floor(limit * headRatio);
|
|
6715
6868
|
const tailBudget = limit - headBudget;
|
|
6716
|
-
let head = headBudget > 0 ?
|
|
6717
|
-
let tail = tailBudget > 0 ?
|
|
6869
|
+
let head = headBudget > 0 ? sliceEdge(output, headBudget, limit, "head") : "";
|
|
6870
|
+
let tail = tailBudget > 0 ? sliceEdge(output, tailBudget, limit, "tail") : "";
|
|
6718
6871
|
const headEnd = head.length;
|
|
6719
6872
|
let tailStart = output.length - tail.length;
|
|
6720
6873
|
head = head.replace(/\r?\n$/, "");
|
|
@@ -11929,4 +12082,4 @@ function describeFactorySandbox(sandbox) {
|
|
|
11929
12082
|
}
|
|
11930
12083
|
};
|
|
11931
12084
|
}
|
|
11932
|
-
export {
|
|
12085
|
+
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 };
|