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