@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
|
@@ -4,186 +4,495 @@ import * as path$1 from "path";
|
|
|
4
4
|
import * as fs$1 from "fs/promises";
|
|
5
5
|
import picomatch from "picomatch";
|
|
6
6
|
import { parse as parse$1, stringify } from "yaml";
|
|
7
|
-
// src/workspace/filesystem/fs-utils.ts
|
|
8
|
-
/**
|
|
9
|
-
* Shared filesystem utilities for LocalFilesystem and LocalSkillSource.
|
|
10
|
-
*
|
|
11
|
-
* These utilities provide consistent implementations for common fs operations.
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Expand a leading `~` or `~/` to the user's home directory.
|
|
15
|
-
* Shell commands handle this automatically, but Node.js path APIs do not.
|
|
16
|
-
*/
|
|
17
|
-
function expandTilde(p) {
|
|
18
|
-
if (p === "~") return os$1.homedir();
|
|
19
|
-
if (p.startsWith("~/") || p.startsWith("~\\")) return path$1.join(os$1.homedir(), p.slice(2));
|
|
20
|
-
return p;
|
|
21
|
-
}
|
|
22
7
|
/**
|
|
23
|
-
*
|
|
8
|
+
* Default tokenization options
|
|
24
9
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
10
|
+
const DEFAULT_TOKENIZE_OPTIONS = {
|
|
11
|
+
lowercase: true,
|
|
12
|
+
removePunctuation: true,
|
|
13
|
+
minLength: 2,
|
|
14
|
+
stopwords: /* @__PURE__ */ new Set([
|
|
15
|
+
"a",
|
|
16
|
+
"an",
|
|
17
|
+
"and",
|
|
18
|
+
"are",
|
|
19
|
+
"as",
|
|
20
|
+
"at",
|
|
21
|
+
"be",
|
|
22
|
+
"by",
|
|
23
|
+
"for",
|
|
24
|
+
"from",
|
|
25
|
+
"has",
|
|
26
|
+
"he",
|
|
27
|
+
"in",
|
|
28
|
+
"is",
|
|
29
|
+
"it",
|
|
30
|
+
"its",
|
|
31
|
+
"of",
|
|
32
|
+
"on",
|
|
33
|
+
"or",
|
|
34
|
+
"that",
|
|
35
|
+
"the",
|
|
36
|
+
"to",
|
|
37
|
+
"was",
|
|
38
|
+
"were",
|
|
39
|
+
"will",
|
|
40
|
+
"with"
|
|
41
|
+
]),
|
|
42
|
+
splitPattern: /\s+/
|
|
43
|
+
};
|
|
28
44
|
/**
|
|
29
|
-
*
|
|
30
|
-
* e.g. treating a file as a directory). Like ENOENT, this means the requested
|
|
31
|
-
* target cannot be resolved.
|
|
45
|
+
* Tokenize text into an array of terms
|
|
32
46
|
*/
|
|
33
|
-
function
|
|
34
|
-
|
|
47
|
+
function tokenize(text, options = {}) {
|
|
48
|
+
if (options.tokenizer) return options.tokenizer(text);
|
|
49
|
+
const opts = {
|
|
50
|
+
...DEFAULT_TOKENIZE_OPTIONS,
|
|
51
|
+
...options
|
|
52
|
+
};
|
|
53
|
+
let processed = text;
|
|
54
|
+
if (opts.lowercase) processed = processed.toLowerCase();
|
|
55
|
+
if (opts.removePunctuation) processed = processed.replace(/[^\p{L}\p{N}_\s]/gu, " ");
|
|
56
|
+
return processed.split(opts.splitPattern).filter((token) => {
|
|
57
|
+
if (token.length < opts.minLength) return false;
|
|
58
|
+
if (opts.stopwords?.has(token)) return false;
|
|
59
|
+
return true;
|
|
60
|
+
});
|
|
35
61
|
}
|
|
36
62
|
/**
|
|
37
|
-
*
|
|
63
|
+
* Find the line range where query terms appear in content.
|
|
64
|
+
* Returns the range spanning from the first to the last line containing any query term.
|
|
65
|
+
*
|
|
66
|
+
* @param content - The document content
|
|
67
|
+
* @param queryTerms - Tokenized query terms to find
|
|
68
|
+
* @param options - Tokenization options (should match indexing options)
|
|
69
|
+
* @returns LineRange if terms found, undefined otherwise
|
|
38
70
|
*/
|
|
39
|
-
function
|
|
40
|
-
|
|
71
|
+
function findLineRange(content, queryTerms, options = {}) {
|
|
72
|
+
if (queryTerms.length === 0) return void 0;
|
|
73
|
+
const lines = content.split("\n");
|
|
74
|
+
const opts = {
|
|
75
|
+
lowercase: true,
|
|
76
|
+
removePunctuation: true,
|
|
77
|
+
minLength: 2,
|
|
78
|
+
...options
|
|
79
|
+
};
|
|
80
|
+
const lowercase = !opts.tokenizer && opts.lowercase;
|
|
81
|
+
const normalizedTerms = new Set(queryTerms.map((t) => lowercase ? t.toLowerCase() : t));
|
|
82
|
+
let firstMatchLine;
|
|
83
|
+
let lastMatchLine;
|
|
84
|
+
for (let i = 0; i < lines.length; i++) {
|
|
85
|
+
const lineTokens = tokenize(lines[i], options);
|
|
86
|
+
for (const token of lineTokens) if (normalizedTerms.has(token)) {
|
|
87
|
+
const lineNum = i + 1;
|
|
88
|
+
if (firstMatchLine === void 0) firstMatchLine = lineNum;
|
|
89
|
+
lastMatchLine = lineNum;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (firstMatchLine !== void 0 && lastMatchLine !== void 0) return {
|
|
94
|
+
start: firstMatchLine,
|
|
95
|
+
end: lastMatchLine
|
|
96
|
+
};
|
|
41
97
|
}
|
|
42
|
-
const MIME_TYPES = {
|
|
43
|
-
txt: "text/plain",
|
|
44
|
-
html: "text/html",
|
|
45
|
-
htm: "text/html",
|
|
46
|
-
css: "text/css",
|
|
47
|
-
csv: "text/csv",
|
|
48
|
-
md: "text/markdown",
|
|
49
|
-
js: "application/javascript",
|
|
50
|
-
mjs: "application/javascript",
|
|
51
|
-
ts: "application/typescript",
|
|
52
|
-
tsx: "application/typescript",
|
|
53
|
-
jsx: "application/javascript",
|
|
54
|
-
json: "application/json",
|
|
55
|
-
xml: "application/xml",
|
|
56
|
-
yaml: "text/yaml",
|
|
57
|
-
yml: "text/yaml",
|
|
58
|
-
py: "text/x-python",
|
|
59
|
-
rb: "text/x-ruby",
|
|
60
|
-
go: "text/x-go",
|
|
61
|
-
rs: "text/x-rust",
|
|
62
|
-
java: "text/x-java",
|
|
63
|
-
c: "text/x-c",
|
|
64
|
-
cpp: "text/x-c++",
|
|
65
|
-
h: "text/x-c",
|
|
66
|
-
hpp: "text/x-c++",
|
|
67
|
-
sh: "text/x-sh",
|
|
68
|
-
bash: "text/x-sh",
|
|
69
|
-
zsh: "text/x-sh",
|
|
70
|
-
toml: "text/toml",
|
|
71
|
-
ini: "text/plain",
|
|
72
|
-
env: "text/plain",
|
|
73
|
-
sql: "text/x-sql",
|
|
74
|
-
graphql: "application/graphql",
|
|
75
|
-
gql: "application/graphql",
|
|
76
|
-
vue: "text/x-vue",
|
|
77
|
-
svelte: "text/x-svelte",
|
|
78
|
-
scss: "text/x-scss",
|
|
79
|
-
sass: "text/x-sass",
|
|
80
|
-
less: "text/x-less",
|
|
81
|
-
php: "application/x-php",
|
|
82
|
-
swift: "text/x-swift",
|
|
83
|
-
kt: "text/x-kotlin",
|
|
84
|
-
kts: "text/x-kotlin",
|
|
85
|
-
dart: "application/dart",
|
|
86
|
-
lua: "text/x-lua",
|
|
87
|
-
r: "text/x-r",
|
|
88
|
-
tf: "text/x-terraform",
|
|
89
|
-
tfvars: "text/x-terraform",
|
|
90
|
-
mdx: "text/markdown",
|
|
91
|
-
sas: "text/plain",
|
|
92
|
-
log: "text/plain",
|
|
93
|
-
jsonl: "application/jsonl",
|
|
94
|
-
png: "image/png",
|
|
95
|
-
jpg: "image/jpeg",
|
|
96
|
-
jpeg: "image/jpeg",
|
|
97
|
-
gif: "image/gif",
|
|
98
|
-
svg: "image/svg+xml",
|
|
99
|
-
webp: "image/webp",
|
|
100
|
-
ico: "image/x-icon",
|
|
101
|
-
bmp: "image/bmp",
|
|
102
|
-
tiff: "image/tiff",
|
|
103
|
-
tif: "image/tiff",
|
|
104
|
-
heic: "image/heic",
|
|
105
|
-
heif: "image/heif",
|
|
106
|
-
avif: "image/avif",
|
|
107
|
-
pdf: "application/pdf",
|
|
108
|
-
mp3: "audio/mpeg",
|
|
109
|
-
wav: "audio/wav",
|
|
110
|
-
ogg: "audio/ogg",
|
|
111
|
-
flac: "audio/flac",
|
|
112
|
-
m4a: "audio/mp4",
|
|
113
|
-
aac: "audio/aac",
|
|
114
|
-
mp4: "video/mp4",
|
|
115
|
-
webm: "video/webm",
|
|
116
|
-
mov: "video/quicktime",
|
|
117
|
-
avi: "video/x-msvideo",
|
|
118
|
-
mkv: "video/x-matroska",
|
|
119
|
-
zip: "application/zip",
|
|
120
|
-
tar: "application/x-tar",
|
|
121
|
-
gz: "application/gzip",
|
|
122
|
-
tgz: "application/gzip",
|
|
123
|
-
bz2: "application/x-bzip2",
|
|
124
|
-
"7z": "application/x-7z-compressed",
|
|
125
|
-
rar: "application/vnd.rar",
|
|
126
|
-
exe: "application/vnd.microsoft.portable-executable",
|
|
127
|
-
dll: "application/vnd.microsoft.portable-executable",
|
|
128
|
-
so: "application/x-sharedlib",
|
|
129
|
-
dylib: "application/x-sharedlib",
|
|
130
|
-
bin: "application/x-binary",
|
|
131
|
-
dat: "application/x-binary",
|
|
132
|
-
dmg: "application/x-apple-diskimage",
|
|
133
|
-
iso: "application/x-iso9660-image",
|
|
134
|
-
deb: "application/vnd.debian.binary-package",
|
|
135
|
-
rpm: "application/x-rpm",
|
|
136
|
-
doc: "application/msword",
|
|
137
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
138
|
-
xls: "application/vnd.ms-excel",
|
|
139
|
-
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
140
|
-
ppt: "application/vnd.ms-powerpoint",
|
|
141
|
-
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
142
|
-
ttf: "font/ttf",
|
|
143
|
-
otf: "font/otf",
|
|
144
|
-
woff: "font/woff",
|
|
145
|
-
woff2: "font/woff2",
|
|
146
|
-
wasm: "application/wasm",
|
|
147
|
-
class: "application/java-vm",
|
|
148
|
-
pyc: "application/x-python-code"
|
|
149
|
-
};
|
|
150
98
|
/**
|
|
151
|
-
*
|
|
99
|
+
* Compute term frequencies for a list of tokens
|
|
152
100
|
*/
|
|
153
|
-
function
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
return
|
|
101
|
+
function computeTermFrequencies(tokens) {
|
|
102
|
+
const frequencies = /* @__PURE__ */ new Map();
|
|
103
|
+
for (const token of tokens) frequencies.set(token, (frequencies.get(token) || 0) + 1);
|
|
104
|
+
return frequencies;
|
|
157
105
|
}
|
|
158
106
|
/**
|
|
159
|
-
*
|
|
107
|
+
* BM25 Index for keyword-based document retrieval
|
|
160
108
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
109
|
+
var BM25Index = class BM25Index {
|
|
110
|
+
/** BM25 k1 parameter */
|
|
111
|
+
k1;
|
|
112
|
+
/** BM25 b parameter */
|
|
113
|
+
b;
|
|
114
|
+
/** Documents in the index */
|
|
115
|
+
#documents = /* @__PURE__ */ new Map();
|
|
116
|
+
/** Inverted index: term -> document IDs containing the term */
|
|
117
|
+
#invertedIndex = /* @__PURE__ */ new Map();
|
|
118
|
+
/** Document frequency: term -> number of documents containing the term */
|
|
119
|
+
#documentFrequency = /* @__PURE__ */ new Map();
|
|
120
|
+
/** Average document length */
|
|
121
|
+
#avgDocLength = 0;
|
|
122
|
+
/** Total number of documents */
|
|
123
|
+
#docCount = 0;
|
|
124
|
+
/** Tokenization options */
|
|
125
|
+
#tokenizeOptions;
|
|
126
|
+
constructor(config = {}, tokenizeOptions = {}) {
|
|
127
|
+
this.k1 = config.k1 ?? 1.5;
|
|
128
|
+
this.b = config.b ?? .75;
|
|
129
|
+
this.#tokenizeOptions = tokenizeOptions;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Add a document to the index
|
|
133
|
+
*/
|
|
134
|
+
add(id, content, metadata) {
|
|
135
|
+
if (this.#documents.has(id)) this.remove(id);
|
|
136
|
+
const tokens = tokenize(content, this.#tokenizeOptions);
|
|
137
|
+
const termFrequencies = computeTermFrequencies(tokens);
|
|
138
|
+
const doc = {
|
|
139
|
+
id,
|
|
140
|
+
content,
|
|
141
|
+
tokens,
|
|
142
|
+
termFrequencies,
|
|
143
|
+
length: tokens.length,
|
|
144
|
+
metadata
|
|
145
|
+
};
|
|
146
|
+
this.#documents.set(id, doc);
|
|
147
|
+
this.#docCount++;
|
|
148
|
+
for (const term of termFrequencies.keys()) {
|
|
149
|
+
if (!this.#invertedIndex.has(term)) this.#invertedIndex.set(term, /* @__PURE__ */ new Set());
|
|
150
|
+
this.#invertedIndex.get(term).add(id);
|
|
151
|
+
this.#documentFrequency.set(term, (this.#documentFrequency.get(term) || 0) + 1);
|
|
152
|
+
}
|
|
153
|
+
this.#updateAvgDocLength();
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Remove a document from the index
|
|
157
|
+
*/
|
|
158
|
+
remove(id) {
|
|
159
|
+
const doc = this.#documents.get(id);
|
|
160
|
+
if (!doc) return false;
|
|
161
|
+
for (const term of doc.termFrequencies.keys()) {
|
|
162
|
+
const docIds = this.#invertedIndex.get(term);
|
|
163
|
+
if (docIds) {
|
|
164
|
+
docIds.delete(id);
|
|
165
|
+
if (docIds.size === 0) {
|
|
166
|
+
this.#invertedIndex.delete(term);
|
|
167
|
+
this.#documentFrequency.delete(term);
|
|
168
|
+
} else this.#documentFrequency.set(term, (this.#documentFrequency.get(term) || 1) - 1);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.#documents.delete(id);
|
|
172
|
+
this.#docCount--;
|
|
173
|
+
this.#updateAvgDocLength();
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Clear all documents from the index
|
|
178
|
+
*/
|
|
179
|
+
clear() {
|
|
180
|
+
this.#documents.clear();
|
|
181
|
+
this.#invertedIndex.clear();
|
|
182
|
+
this.#documentFrequency.clear();
|
|
183
|
+
this.#docCount = 0;
|
|
184
|
+
this.#avgDocLength = 0;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Search for documents matching the query
|
|
188
|
+
*/
|
|
189
|
+
search(query, topK = 10, minScore = 0) {
|
|
190
|
+
const queryTokens = tokenize(query, this.#tokenizeOptions);
|
|
191
|
+
if (queryTokens.length === 0 || this.#docCount === 0) return [];
|
|
192
|
+
const scores = /* @__PURE__ */ new Map();
|
|
193
|
+
for (const queryTerm of queryTokens) {
|
|
194
|
+
const docIds = this.#invertedIndex.get(queryTerm);
|
|
195
|
+
if (!docIds) continue;
|
|
196
|
+
const df = this.#documentFrequency.get(queryTerm) || 0;
|
|
197
|
+
const idf = this.#computeIDF(df);
|
|
198
|
+
for (const docId of docIds) {
|
|
199
|
+
const doc = this.#documents.get(docId);
|
|
200
|
+
const tf = doc.termFrequencies.get(queryTerm) || 0;
|
|
201
|
+
const termScore = this.#computeTermScore(tf, doc.length, idf);
|
|
202
|
+
scores.set(docId, (scores.get(docId) || 0) + termScore);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const results = [];
|
|
206
|
+
for (const [docId, score] of scores.entries()) if (score >= minScore) {
|
|
207
|
+
const doc = this.#documents.get(docId);
|
|
208
|
+
results.push({
|
|
209
|
+
id: docId,
|
|
210
|
+
content: doc.content,
|
|
211
|
+
score,
|
|
212
|
+
metadata: doc.metadata
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
results.sort((a, b) => b.score - a.score);
|
|
216
|
+
return results.slice(0, topK);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get a document by ID
|
|
220
|
+
*/
|
|
221
|
+
get(id) {
|
|
222
|
+
return this.#documents.get(id);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Check if a document exists in the index
|
|
226
|
+
*/
|
|
227
|
+
has(id) {
|
|
228
|
+
return this.#documents.has(id);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get the number of documents in the index
|
|
232
|
+
*/
|
|
233
|
+
get size() {
|
|
234
|
+
return this.#docCount;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get all document IDs
|
|
238
|
+
*/
|
|
239
|
+
get documentIds() {
|
|
240
|
+
return Array.from(this.#documents.keys());
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Serialize the index to a JSON-compatible object
|
|
244
|
+
*/
|
|
245
|
+
serialize() {
|
|
246
|
+
const documents = [];
|
|
247
|
+
for (const [id, doc] of this.#documents.entries()) documents.push({
|
|
248
|
+
id,
|
|
249
|
+
content: doc.content,
|
|
250
|
+
tokens: doc.tokens,
|
|
251
|
+
termFrequencies: Object.fromEntries(doc.termFrequencies),
|
|
252
|
+
length: doc.length,
|
|
253
|
+
metadata: doc.metadata
|
|
254
|
+
});
|
|
255
|
+
return {
|
|
256
|
+
k1: this.k1,
|
|
257
|
+
b: this.b,
|
|
258
|
+
documents,
|
|
259
|
+
avgDocLength: this.#avgDocLength
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Deserialize an index from a JSON object
|
|
264
|
+
*/
|
|
265
|
+
static deserialize(data, tokenizeOptions = {}) {
|
|
266
|
+
const index = new BM25Index({
|
|
267
|
+
k1: data.k1,
|
|
268
|
+
b: data.b
|
|
269
|
+
}, tokenizeOptions);
|
|
270
|
+
for (const doc of data.documents) {
|
|
271
|
+
const termFrequencies = new Map(Object.entries(doc.termFrequencies));
|
|
272
|
+
const document = {
|
|
273
|
+
id: doc.id,
|
|
274
|
+
content: doc.content,
|
|
275
|
+
tokens: doc.tokens,
|
|
276
|
+
termFrequencies,
|
|
277
|
+
length: doc.length,
|
|
278
|
+
metadata: doc.metadata
|
|
279
|
+
};
|
|
280
|
+
index.#documents.set(doc.id, document);
|
|
281
|
+
index.#docCount++;
|
|
282
|
+
for (const term of termFrequencies.keys()) {
|
|
283
|
+
if (!index.#invertedIndex.has(term)) index.#invertedIndex.set(term, /* @__PURE__ */ new Set());
|
|
284
|
+
index.#invertedIndex.get(term).add(doc.id);
|
|
285
|
+
index.#documentFrequency.set(term, (index.#documentFrequency.get(term) || 0) + 1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
index.#avgDocLength = data.avgDocLength;
|
|
289
|
+
return index;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Update average document length after add/remove operations
|
|
293
|
+
*/
|
|
294
|
+
#updateAvgDocLength() {
|
|
295
|
+
if (this.#docCount === 0) {
|
|
296
|
+
this.#avgDocLength = 0;
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
let totalLength = 0;
|
|
300
|
+
for (const doc of this.#documents.values()) totalLength += doc.length;
|
|
301
|
+
this.#avgDocLength = totalLength / this.#docCount;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Compute IDF (Inverse Document Frequency) for a term
|
|
305
|
+
*/
|
|
306
|
+
#computeIDF(df) {
|
|
307
|
+
return Math.log((this.#docCount - df + .5) / (df + .5) + 1);
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Compute the BM25 score component for a single term
|
|
311
|
+
*/
|
|
312
|
+
#computeTermScore(tf, docLength, idf) {
|
|
313
|
+
return idf * (tf * (this.k1 + 1) / (tf + this.k1 * (1 - this.b + this.b * (docLength / this.#avgDocLength))));
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
// src/workspace/filesystem/fs-utils.ts
|
|
317
|
+
/**
|
|
318
|
+
* Shared filesystem utilities for LocalFilesystem and LocalSkillSource.
|
|
319
|
+
*
|
|
320
|
+
* These utilities provide consistent implementations for common fs operations.
|
|
321
|
+
*/
|
|
322
|
+
/**
|
|
323
|
+
* Expand a leading `~` or `~/` to the user's home directory.
|
|
324
|
+
* Shell commands handle this automatically, but Node.js path APIs do not.
|
|
325
|
+
*/
|
|
326
|
+
function expandTilde(p) {
|
|
327
|
+
if (p === "~") return os$1.homedir();
|
|
328
|
+
if (p.startsWith("~/") || p.startsWith("~\\")) return path$1.join(os$1.homedir(), p.slice(2));
|
|
329
|
+
return p;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Check if an error is an ENOENT (file not found) error.
|
|
333
|
+
*/
|
|
334
|
+
function isEnoentError(error) {
|
|
335
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Check if an error is an ENOTDIR error (a path component is not a directory,
|
|
339
|
+
* e.g. treating a file as a directory). Like ENOENT, this means the requested
|
|
340
|
+
* target cannot be resolved.
|
|
341
|
+
*/
|
|
342
|
+
function isEnotdirError(error) {
|
|
343
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === "ENOTDIR";
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Check if an error is an EEXIST (file exists) error.
|
|
347
|
+
*/
|
|
348
|
+
function isEexistError(error) {
|
|
349
|
+
return error !== null && typeof error === "object" && "code" in error && error.code === "EEXIST";
|
|
350
|
+
}
|
|
351
|
+
const MIME_TYPES = {
|
|
352
|
+
txt: "text/plain",
|
|
353
|
+
html: "text/html",
|
|
354
|
+
htm: "text/html",
|
|
355
|
+
css: "text/css",
|
|
356
|
+
csv: "text/csv",
|
|
357
|
+
md: "text/markdown",
|
|
358
|
+
js: "application/javascript",
|
|
359
|
+
mjs: "application/javascript",
|
|
360
|
+
ts: "application/typescript",
|
|
361
|
+
tsx: "application/typescript",
|
|
362
|
+
jsx: "application/javascript",
|
|
363
|
+
json: "application/json",
|
|
364
|
+
xml: "application/xml",
|
|
365
|
+
yaml: "text/yaml",
|
|
366
|
+
yml: "text/yaml",
|
|
367
|
+
py: "text/x-python",
|
|
368
|
+
rb: "text/x-ruby",
|
|
369
|
+
go: "text/x-go",
|
|
370
|
+
rs: "text/x-rust",
|
|
371
|
+
java: "text/x-java",
|
|
372
|
+
c: "text/x-c",
|
|
373
|
+
cpp: "text/x-c++",
|
|
374
|
+
h: "text/x-c",
|
|
375
|
+
hpp: "text/x-c++",
|
|
376
|
+
sh: "text/x-sh",
|
|
377
|
+
bash: "text/x-sh",
|
|
378
|
+
zsh: "text/x-sh",
|
|
379
|
+
toml: "text/toml",
|
|
380
|
+
ini: "text/plain",
|
|
381
|
+
env: "text/plain",
|
|
382
|
+
sql: "text/x-sql",
|
|
383
|
+
graphql: "application/graphql",
|
|
384
|
+
gql: "application/graphql",
|
|
385
|
+
vue: "text/x-vue",
|
|
386
|
+
svelte: "text/x-svelte",
|
|
387
|
+
scss: "text/x-scss",
|
|
388
|
+
sass: "text/x-sass",
|
|
389
|
+
less: "text/x-less",
|
|
390
|
+
php: "application/x-php",
|
|
391
|
+
swift: "text/x-swift",
|
|
392
|
+
kt: "text/x-kotlin",
|
|
393
|
+
kts: "text/x-kotlin",
|
|
394
|
+
dart: "application/dart",
|
|
395
|
+
lua: "text/x-lua",
|
|
396
|
+
r: "text/x-r",
|
|
397
|
+
tf: "text/x-terraform",
|
|
398
|
+
tfvars: "text/x-terraform",
|
|
399
|
+
mdx: "text/markdown",
|
|
400
|
+
sas: "text/plain",
|
|
401
|
+
log: "text/plain",
|
|
402
|
+
jsonl: "application/jsonl",
|
|
403
|
+
png: "image/png",
|
|
404
|
+
jpg: "image/jpeg",
|
|
405
|
+
jpeg: "image/jpeg",
|
|
406
|
+
gif: "image/gif",
|
|
407
|
+
svg: "image/svg+xml",
|
|
408
|
+
webp: "image/webp",
|
|
409
|
+
ico: "image/x-icon",
|
|
410
|
+
bmp: "image/bmp",
|
|
411
|
+
tiff: "image/tiff",
|
|
412
|
+
tif: "image/tiff",
|
|
413
|
+
heic: "image/heic",
|
|
414
|
+
heif: "image/heif",
|
|
415
|
+
avif: "image/avif",
|
|
416
|
+
pdf: "application/pdf",
|
|
417
|
+
mp3: "audio/mpeg",
|
|
418
|
+
wav: "audio/wav",
|
|
419
|
+
ogg: "audio/ogg",
|
|
420
|
+
flac: "audio/flac",
|
|
421
|
+
m4a: "audio/mp4",
|
|
422
|
+
aac: "audio/aac",
|
|
423
|
+
mp4: "video/mp4",
|
|
424
|
+
webm: "video/webm",
|
|
425
|
+
mov: "video/quicktime",
|
|
426
|
+
avi: "video/x-msvideo",
|
|
427
|
+
mkv: "video/x-matroska",
|
|
428
|
+
zip: "application/zip",
|
|
429
|
+
tar: "application/x-tar",
|
|
430
|
+
gz: "application/gzip",
|
|
431
|
+
tgz: "application/gzip",
|
|
432
|
+
bz2: "application/x-bzip2",
|
|
433
|
+
"7z": "application/x-7z-compressed",
|
|
434
|
+
rar: "application/vnd.rar",
|
|
435
|
+
exe: "application/vnd.microsoft.portable-executable",
|
|
436
|
+
dll: "application/vnd.microsoft.portable-executable",
|
|
437
|
+
so: "application/x-sharedlib",
|
|
438
|
+
dylib: "application/x-sharedlib",
|
|
439
|
+
bin: "application/x-binary",
|
|
440
|
+
dat: "application/x-binary",
|
|
441
|
+
dmg: "application/x-apple-diskimage",
|
|
442
|
+
iso: "application/x-iso9660-image",
|
|
443
|
+
deb: "application/vnd.debian.binary-package",
|
|
444
|
+
rpm: "application/x-rpm",
|
|
445
|
+
doc: "application/msword",
|
|
446
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
447
|
+
xls: "application/vnd.ms-excel",
|
|
448
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
449
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
450
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
451
|
+
ttf: "font/ttf",
|
|
452
|
+
otf: "font/otf",
|
|
453
|
+
woff: "font/woff",
|
|
454
|
+
woff2: "font/woff2",
|
|
455
|
+
wasm: "application/wasm",
|
|
456
|
+
class: "application/java-vm",
|
|
457
|
+
pyc: "application/x-python-code"
|
|
458
|
+
};
|
|
459
|
+
/**
|
|
460
|
+
* Get MIME type for a filename based on extension.
|
|
461
|
+
*/
|
|
462
|
+
function getMimeType(filename) {
|
|
463
|
+
const ext = path$1.extname(filename).slice(1).toLowerCase();
|
|
464
|
+
const mimeType = Object.hasOwn(MIME_TYPES, ext) ? MIME_TYPES[ext] : void 0;
|
|
465
|
+
return typeof mimeType === "string" ? mimeType : "application/octet-stream";
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Extensions that should be treated as text files.
|
|
469
|
+
*/
|
|
470
|
+
const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
471
|
+
".md",
|
|
472
|
+
".txt",
|
|
473
|
+
".json",
|
|
474
|
+
".yaml",
|
|
475
|
+
".yml",
|
|
476
|
+
".js",
|
|
477
|
+
".mjs",
|
|
478
|
+
".ts",
|
|
479
|
+
".tsx",
|
|
480
|
+
".jsx",
|
|
481
|
+
".py",
|
|
482
|
+
".rb",
|
|
483
|
+
".go",
|
|
484
|
+
".rs",
|
|
485
|
+
".java",
|
|
486
|
+
".c",
|
|
487
|
+
".cpp",
|
|
488
|
+
".h",
|
|
489
|
+
".hpp",
|
|
490
|
+
".sh",
|
|
491
|
+
".bash",
|
|
492
|
+
".zsh",
|
|
493
|
+
".html",
|
|
494
|
+
".htm",
|
|
495
|
+
".css",
|
|
187
496
|
".xml",
|
|
188
497
|
".toml",
|
|
189
498
|
".ini",
|
|
@@ -387,378 +696,69 @@ function createGlobMatcher(patterns, options) {
|
|
|
387
696
|
*
|
|
388
697
|
* @example
|
|
389
698
|
* matchGlob('src/index.ts', '**\/*.ts') // true
|
|
390
|
-
*/
|
|
391
|
-
function matchGlob(path, pattern, options) {
|
|
392
|
-
return createGlobMatcher(pattern, options)(path);
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Walk a directory tree recursively, returning all entries (files and directories).
|
|
396
|
-
* Skips symlinked directories to prevent infinite loops.
|
|
397
|
-
*/
|
|
398
|
-
async function walkAll(readdir, dir, depth, maxDepth) {
|
|
399
|
-
if (depth >= maxDepth) return [];
|
|
400
|
-
try {
|
|
401
|
-
const entries = await readdir(dir);
|
|
402
|
-
const results = [];
|
|
403
|
-
for (const entry of entries) {
|
|
404
|
-
if (entry.type === "directory" && entry.isSymlink) continue;
|
|
405
|
-
const fullPath = dir === "." || dir === "" ? entry.name : `${dir}/${entry.name}`;
|
|
406
|
-
results.push({
|
|
407
|
-
path: fullPath,
|
|
408
|
-
type: entry.type
|
|
409
|
-
});
|
|
410
|
-
if (entry.type === "directory") results.push(...await walkAll(readdir, fullPath, depth + 1, maxDepth));
|
|
411
|
-
}
|
|
412
|
-
return results;
|
|
413
|
-
} catch {
|
|
414
|
-
return [];
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Resolve a path pattern to matching filesystem entries.
|
|
419
|
-
*
|
|
420
|
-
* Handles both plain paths and glob patterns consistently:
|
|
421
|
-
* - Plain paths: determines file vs directory via readdir probe, returns single entry
|
|
422
|
-
* - Glob patterns: walks from the glob base, matches both files and directories
|
|
423
|
-
*
|
|
424
|
-
* @example
|
|
425
|
-
* // Plain paths
|
|
426
|
-
* resolvePathPattern('/docs', readdir) // [{ path: '/docs', type: 'directory' }]
|
|
427
|
-
* resolvePathPattern('/docs/readme.md', readdir) // [{ path: '/docs/readme.md', type: 'file' }]
|
|
428
|
-
*
|
|
429
|
-
* // Glob patterns — matches files and directories
|
|
430
|
-
* resolvePathPattern('/docs/**\/*.md', readdir) // all .md files under /docs
|
|
431
|
-
* resolvePathPattern('**\/skills', readdir) // all directories (and files) named 'skills'
|
|
432
|
-
* resolvePathPattern('/skills/**', readdir) // everything under /skills
|
|
433
|
-
*/
|
|
434
|
-
async function resolvePathPattern(pattern, readdir, options) {
|
|
435
|
-
const maxDepth = options?.maxDepth ?? 10;
|
|
436
|
-
const normalized = pattern.length > 1 && pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
437
|
-
if (!isGlobPattern(normalized)) try {
|
|
438
|
-
await readdir(normalized);
|
|
439
|
-
return [{
|
|
440
|
-
path: normalized,
|
|
441
|
-
type: "directory"
|
|
442
|
-
}];
|
|
443
|
-
} catch {
|
|
444
|
-
return [{
|
|
445
|
-
path: normalized,
|
|
446
|
-
type: "file"
|
|
447
|
-
}];
|
|
448
|
-
}
|
|
449
|
-
const walkRoot = extractGlobBase(normalized);
|
|
450
|
-
const matcher = createGlobMatcher(normalized, { dot: options?.dot ?? false });
|
|
451
|
-
return (await walkAll(readdir, walkRoot, 0, maxDepth)).filter((entry) => matcher(entry.path));
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Default tokenization options
|
|
455
|
-
*/
|
|
456
|
-
const DEFAULT_TOKENIZE_OPTIONS = {
|
|
457
|
-
lowercase: true,
|
|
458
|
-
removePunctuation: true,
|
|
459
|
-
minLength: 2,
|
|
460
|
-
stopwords: /* @__PURE__ */ new Set([
|
|
461
|
-
"a",
|
|
462
|
-
"an",
|
|
463
|
-
"and",
|
|
464
|
-
"are",
|
|
465
|
-
"as",
|
|
466
|
-
"at",
|
|
467
|
-
"be",
|
|
468
|
-
"by",
|
|
469
|
-
"for",
|
|
470
|
-
"from",
|
|
471
|
-
"has",
|
|
472
|
-
"he",
|
|
473
|
-
"in",
|
|
474
|
-
"is",
|
|
475
|
-
"it",
|
|
476
|
-
"its",
|
|
477
|
-
"of",
|
|
478
|
-
"on",
|
|
479
|
-
"or",
|
|
480
|
-
"that",
|
|
481
|
-
"the",
|
|
482
|
-
"to",
|
|
483
|
-
"was",
|
|
484
|
-
"were",
|
|
485
|
-
"will",
|
|
486
|
-
"with"
|
|
487
|
-
]),
|
|
488
|
-
splitPattern: /\s+/
|
|
489
|
-
};
|
|
490
|
-
/**
|
|
491
|
-
* Tokenize text into an array of terms
|
|
492
|
-
*/
|
|
493
|
-
function tokenize(text, options = {}) {
|
|
494
|
-
if (options.tokenizer) return options.tokenizer(text);
|
|
495
|
-
const opts = {
|
|
496
|
-
...DEFAULT_TOKENIZE_OPTIONS,
|
|
497
|
-
...options
|
|
498
|
-
};
|
|
499
|
-
let processed = text;
|
|
500
|
-
if (opts.lowercase) processed = processed.toLowerCase();
|
|
501
|
-
if (opts.removePunctuation) processed = processed.replace(/[^\p{L}\p{N}_\s]/gu, " ");
|
|
502
|
-
return processed.split(opts.splitPattern).filter((token) => {
|
|
503
|
-
if (token.length < opts.minLength) return false;
|
|
504
|
-
if (opts.stopwords?.has(token)) return false;
|
|
505
|
-
return true;
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
/**
|
|
509
|
-
* Find the line range where query terms appear in content.
|
|
510
|
-
* Returns the range spanning from the first to the last line containing any query term.
|
|
511
|
-
*
|
|
512
|
-
* @param content - The document content
|
|
513
|
-
* @param queryTerms - Tokenized query terms to find
|
|
514
|
-
* @param options - Tokenization options (should match indexing options)
|
|
515
|
-
* @returns LineRange if terms found, undefined otherwise
|
|
516
|
-
*/
|
|
517
|
-
function findLineRange(content, queryTerms, options = {}) {
|
|
518
|
-
if (queryTerms.length === 0) return void 0;
|
|
519
|
-
const lines = content.split("\n");
|
|
520
|
-
const opts = {
|
|
521
|
-
lowercase: true,
|
|
522
|
-
removePunctuation: true,
|
|
523
|
-
minLength: 2,
|
|
524
|
-
...options
|
|
525
|
-
};
|
|
526
|
-
const lowercase = !opts.tokenizer && opts.lowercase;
|
|
527
|
-
const normalizedTerms = new Set(queryTerms.map((t) => lowercase ? t.toLowerCase() : t));
|
|
528
|
-
let firstMatchLine;
|
|
529
|
-
let lastMatchLine;
|
|
530
|
-
for (let i = 0; i < lines.length; i++) {
|
|
531
|
-
const lineTokens = tokenize(lines[i], options);
|
|
532
|
-
for (const token of lineTokens) if (normalizedTerms.has(token)) {
|
|
533
|
-
const lineNum = i + 1;
|
|
534
|
-
if (firstMatchLine === void 0) firstMatchLine = lineNum;
|
|
535
|
-
lastMatchLine = lineNum;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (firstMatchLine !== void 0 && lastMatchLine !== void 0) return {
|
|
540
|
-
start: firstMatchLine,
|
|
541
|
-
end: lastMatchLine
|
|
542
|
-
};
|
|
543
|
-
}
|
|
544
|
-
/**
|
|
545
|
-
* Compute term frequencies for a list of tokens
|
|
546
|
-
*/
|
|
547
|
-
function computeTermFrequencies(tokens) {
|
|
548
|
-
const frequencies = /* @__PURE__ */ new Map();
|
|
549
|
-
for (const token of tokens) frequencies.set(token, (frequencies.get(token) || 0) + 1);
|
|
550
|
-
return frequencies;
|
|
699
|
+
*/
|
|
700
|
+
function matchGlob(path, pattern, options) {
|
|
701
|
+
return createGlobMatcher(pattern, options)(path);
|
|
551
702
|
}
|
|
552
703
|
/**
|
|
553
|
-
*
|
|
704
|
+
* Walk a directory tree recursively, returning all entries (files and directories).
|
|
705
|
+
* Skips symlinked directories to prevent infinite loops.
|
|
554
706
|
*/
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
b;
|
|
560
|
-
/** Documents in the index */
|
|
561
|
-
#documents = /* @__PURE__ */ new Map();
|
|
562
|
-
/** Inverted index: term -> document IDs containing the term */
|
|
563
|
-
#invertedIndex = /* @__PURE__ */ new Map();
|
|
564
|
-
/** Document frequency: term -> number of documents containing the term */
|
|
565
|
-
#documentFrequency = /* @__PURE__ */ new Map();
|
|
566
|
-
/** Average document length */
|
|
567
|
-
#avgDocLength = 0;
|
|
568
|
-
/** Total number of documents */
|
|
569
|
-
#docCount = 0;
|
|
570
|
-
/** Tokenization options */
|
|
571
|
-
#tokenizeOptions;
|
|
572
|
-
constructor(config = {}, tokenizeOptions = {}) {
|
|
573
|
-
this.k1 = config.k1 ?? 1.5;
|
|
574
|
-
this.b = config.b ?? .75;
|
|
575
|
-
this.#tokenizeOptions = tokenizeOptions;
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* Add a document to the index
|
|
579
|
-
*/
|
|
580
|
-
add(id, content, metadata) {
|
|
581
|
-
if (this.#documents.has(id)) this.remove(id);
|
|
582
|
-
const tokens = tokenize(content, this.#tokenizeOptions);
|
|
583
|
-
const termFrequencies = computeTermFrequencies(tokens);
|
|
584
|
-
const doc = {
|
|
585
|
-
id,
|
|
586
|
-
content,
|
|
587
|
-
tokens,
|
|
588
|
-
termFrequencies,
|
|
589
|
-
length: tokens.length,
|
|
590
|
-
metadata
|
|
591
|
-
};
|
|
592
|
-
this.#documents.set(id, doc);
|
|
593
|
-
this.#docCount++;
|
|
594
|
-
for (const term of termFrequencies.keys()) {
|
|
595
|
-
if (!this.#invertedIndex.has(term)) this.#invertedIndex.set(term, /* @__PURE__ */ new Set());
|
|
596
|
-
this.#invertedIndex.get(term).add(id);
|
|
597
|
-
this.#documentFrequency.set(term, (this.#documentFrequency.get(term) || 0) + 1);
|
|
598
|
-
}
|
|
599
|
-
this.#updateAvgDocLength();
|
|
600
|
-
}
|
|
601
|
-
/**
|
|
602
|
-
* Remove a document from the index
|
|
603
|
-
*/
|
|
604
|
-
remove(id) {
|
|
605
|
-
const doc = this.#documents.get(id);
|
|
606
|
-
if (!doc) return false;
|
|
607
|
-
for (const term of doc.termFrequencies.keys()) {
|
|
608
|
-
const docIds = this.#invertedIndex.get(term);
|
|
609
|
-
if (docIds) {
|
|
610
|
-
docIds.delete(id);
|
|
611
|
-
if (docIds.size === 0) {
|
|
612
|
-
this.#invertedIndex.delete(term);
|
|
613
|
-
this.#documentFrequency.delete(term);
|
|
614
|
-
} else this.#documentFrequency.set(term, (this.#documentFrequency.get(term) || 1) - 1);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
this.#documents.delete(id);
|
|
618
|
-
this.#docCount--;
|
|
619
|
-
this.#updateAvgDocLength();
|
|
620
|
-
return true;
|
|
621
|
-
}
|
|
622
|
-
/**
|
|
623
|
-
* Clear all documents from the index
|
|
624
|
-
*/
|
|
625
|
-
clear() {
|
|
626
|
-
this.#documents.clear();
|
|
627
|
-
this.#invertedIndex.clear();
|
|
628
|
-
this.#documentFrequency.clear();
|
|
629
|
-
this.#docCount = 0;
|
|
630
|
-
this.#avgDocLength = 0;
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* Search for documents matching the query
|
|
634
|
-
*/
|
|
635
|
-
search(query, topK = 10, minScore = 0) {
|
|
636
|
-
const queryTokens = tokenize(query, this.#tokenizeOptions);
|
|
637
|
-
if (queryTokens.length === 0 || this.#docCount === 0) return [];
|
|
638
|
-
const scores = /* @__PURE__ */ new Map();
|
|
639
|
-
for (const queryTerm of queryTokens) {
|
|
640
|
-
const docIds = this.#invertedIndex.get(queryTerm);
|
|
641
|
-
if (!docIds) continue;
|
|
642
|
-
const df = this.#documentFrequency.get(queryTerm) || 0;
|
|
643
|
-
const idf = this.#computeIDF(df);
|
|
644
|
-
for (const docId of docIds) {
|
|
645
|
-
const doc = this.#documents.get(docId);
|
|
646
|
-
const tf = doc.termFrequencies.get(queryTerm) || 0;
|
|
647
|
-
const termScore = this.#computeTermScore(tf, doc.length, idf);
|
|
648
|
-
scores.set(docId, (scores.get(docId) || 0) + termScore);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
707
|
+
async function walkAll(readdir, dir, depth, maxDepth) {
|
|
708
|
+
if (depth >= maxDepth) return [];
|
|
709
|
+
try {
|
|
710
|
+
const entries = await readdir(dir);
|
|
651
711
|
const results = [];
|
|
652
|
-
for (const
|
|
653
|
-
|
|
712
|
+
for (const entry of entries) {
|
|
713
|
+
if (entry.type === "directory" && entry.isSymlink) continue;
|
|
714
|
+
const fullPath = dir === "." || dir === "" ? entry.name : `${dir}/${entry.name}`;
|
|
654
715
|
results.push({
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
score,
|
|
658
|
-
metadata: doc.metadata
|
|
716
|
+
path: fullPath,
|
|
717
|
+
type: entry.type
|
|
659
718
|
});
|
|
719
|
+
if (entry.type === "directory") results.push(...await walkAll(readdir, fullPath, depth + 1, maxDepth));
|
|
660
720
|
}
|
|
661
|
-
results
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
/**
|
|
665
|
-
* Get a document by ID
|
|
666
|
-
*/
|
|
667
|
-
get(id) {
|
|
668
|
-
return this.#documents.get(id);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Check if a document exists in the index
|
|
672
|
-
*/
|
|
673
|
-
has(id) {
|
|
674
|
-
return this.#documents.has(id);
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* Get the number of documents in the index
|
|
678
|
-
*/
|
|
679
|
-
get size() {
|
|
680
|
-
return this.#docCount;
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Get all document IDs
|
|
684
|
-
*/
|
|
685
|
-
get documentIds() {
|
|
686
|
-
return Array.from(this.#documents.keys());
|
|
687
|
-
}
|
|
688
|
-
/**
|
|
689
|
-
* Serialize the index to a JSON-compatible object
|
|
690
|
-
*/
|
|
691
|
-
serialize() {
|
|
692
|
-
const documents = [];
|
|
693
|
-
for (const [id, doc] of this.#documents.entries()) documents.push({
|
|
694
|
-
id,
|
|
695
|
-
content: doc.content,
|
|
696
|
-
tokens: doc.tokens,
|
|
697
|
-
termFrequencies: Object.fromEntries(doc.termFrequencies),
|
|
698
|
-
length: doc.length,
|
|
699
|
-
metadata: doc.metadata
|
|
700
|
-
});
|
|
701
|
-
return {
|
|
702
|
-
k1: this.k1,
|
|
703
|
-
b: this.b,
|
|
704
|
-
documents,
|
|
705
|
-
avgDocLength: this.#avgDocLength
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* Deserialize an index from a JSON object
|
|
710
|
-
*/
|
|
711
|
-
static deserialize(data, tokenizeOptions = {}) {
|
|
712
|
-
const index = new BM25Index({
|
|
713
|
-
k1: data.k1,
|
|
714
|
-
b: data.b
|
|
715
|
-
}, tokenizeOptions);
|
|
716
|
-
for (const doc of data.documents) {
|
|
717
|
-
const termFrequencies = new Map(Object.entries(doc.termFrequencies));
|
|
718
|
-
const document = {
|
|
719
|
-
id: doc.id,
|
|
720
|
-
content: doc.content,
|
|
721
|
-
tokens: doc.tokens,
|
|
722
|
-
termFrequencies,
|
|
723
|
-
length: doc.length,
|
|
724
|
-
metadata: doc.metadata
|
|
725
|
-
};
|
|
726
|
-
index.#documents.set(doc.id, document);
|
|
727
|
-
index.#docCount++;
|
|
728
|
-
for (const term of termFrequencies.keys()) {
|
|
729
|
-
if (!index.#invertedIndex.has(term)) index.#invertedIndex.set(term, /* @__PURE__ */ new Set());
|
|
730
|
-
index.#invertedIndex.get(term).add(doc.id);
|
|
731
|
-
index.#documentFrequency.set(term, (index.#documentFrequency.get(term) || 0) + 1);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
index.#avgDocLength = data.avgDocLength;
|
|
735
|
-
return index;
|
|
736
|
-
}
|
|
737
|
-
/**
|
|
738
|
-
* Update average document length after add/remove operations
|
|
739
|
-
*/
|
|
740
|
-
#updateAvgDocLength() {
|
|
741
|
-
if (this.#docCount === 0) {
|
|
742
|
-
this.#avgDocLength = 0;
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
let totalLength = 0;
|
|
746
|
-
for (const doc of this.#documents.values()) totalLength += doc.length;
|
|
747
|
-
this.#avgDocLength = totalLength / this.#docCount;
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Compute IDF (Inverse Document Frequency) for a term
|
|
751
|
-
*/
|
|
752
|
-
#computeIDF(df) {
|
|
753
|
-
return Math.log((this.#docCount - df + .5) / (df + .5) + 1);
|
|
721
|
+
return results;
|
|
722
|
+
} catch {
|
|
723
|
+
return [];
|
|
754
724
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Resolve a path pattern to matching filesystem entries.
|
|
728
|
+
*
|
|
729
|
+
* Handles both plain paths and glob patterns consistently:
|
|
730
|
+
* - Plain paths: determines file vs directory via readdir probe, returns single entry
|
|
731
|
+
* - Glob patterns: walks from the glob base, matches both files and directories
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* // Plain paths
|
|
735
|
+
* resolvePathPattern('/docs', readdir) // [{ path: '/docs', type: 'directory' }]
|
|
736
|
+
* resolvePathPattern('/docs/readme.md', readdir) // [{ path: '/docs/readme.md', type: 'file' }]
|
|
737
|
+
*
|
|
738
|
+
* // Glob patterns — matches files and directories
|
|
739
|
+
* resolvePathPattern('/docs/**\/*.md', readdir) // all .md files under /docs
|
|
740
|
+
* resolvePathPattern('**\/skills', readdir) // all directories (and files) named 'skills'
|
|
741
|
+
* resolvePathPattern('/skills/**', readdir) // everything under /skills
|
|
742
|
+
*/
|
|
743
|
+
async function resolvePathPattern(pattern, readdir, options) {
|
|
744
|
+
const maxDepth = options?.maxDepth ?? 10;
|
|
745
|
+
const normalized = pattern.length > 1 && pattern.endsWith("/") ? pattern.slice(0, -1) : pattern;
|
|
746
|
+
if (!isGlobPattern(normalized)) try {
|
|
747
|
+
await readdir(normalized);
|
|
748
|
+
return [{
|
|
749
|
+
path: normalized,
|
|
750
|
+
type: "directory"
|
|
751
|
+
}];
|
|
752
|
+
} catch {
|
|
753
|
+
return [{
|
|
754
|
+
path: normalized,
|
|
755
|
+
type: "file"
|
|
756
|
+
}];
|
|
760
757
|
}
|
|
761
|
-
|
|
758
|
+
const walkRoot = extractGlobBase(normalized);
|
|
759
|
+
const matcher = createGlobMatcher(normalized, { dot: options?.dot ?? false });
|
|
760
|
+
return (await walkAll(readdir, walkRoot, 0, maxDepth)).filter((entry) => matcher(entry.path));
|
|
761
|
+
}
|
|
762
762
|
// src/workspace/search/search-engine.ts
|
|
763
763
|
/**
|
|
764
764
|
* Type guard: returns true when the embedder is the batch-capable variant.
|
|
@@ -3007,4 +3007,4 @@ function stripLeadingAndTrailingSlashes(s) {
|
|
|
3007
3007
|
while (end > start && s.charCodeAt(end - 1) === 47) end--;
|
|
3008
3008
|
return start === 0 && end === s.length ? s : s.slice(start, end);
|
|
3009
3009
|
}
|
|
3010
|
-
export {
|
|
3010
|
+
export { isEnotdirError as C, BM25Index as D, resolveToBasePath as E, tokenize as O, isEnoentError as S, normalizeTextExtension as T, expandTilde as _, extractSkillFrontmatter as a, getMimeType as b, stringifyFrontmatter as c, splitIntoChunks as d, createGlobMatcher as f, resolvePathPattern as g, matchGlob as h, SKILL_LIMITS as i, LocalSkillSource as l, isGlobPattern as m, SKILL_SCOPE_DOCUMENT_PREFIX as n, validateSkillContent as o, extractGlobBase as p, WorkspaceSkillsImpl as r, validateSkillMetadata as s, ResolvedSourceWorkspaceSkills as t, SearchEngine as u, fsExists as v, isTextFile as w, isEexistError as x, fsStat as y };
|