@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
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/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy of `encodeKnowledgeScopeId` from `@mastra/core/knowledge` (core 1.84+), kept here so code-sdk
|
|
3
|
+
* still loads when npm resolves an older core. Escapes `%`, `/`, `#` and `:` so an id stays one scope
|
|
4
|
+
* segment. knowledge-scope-id.test.ts pins it to core's output.
|
|
5
|
+
*/
|
|
6
|
+
export declare function encodeKnowledgeScopeId(id: string): string;
|
|
7
|
+
//# sourceMappingURL=knowledge-scope-id.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/knowledge-scope-id.ts
|
|
2
|
+
/**
|
|
3
|
+
* Copy of `encodeKnowledgeScopeId` from `@mastra/core/knowledge` (core 1.84+), kept here so code-sdk
|
|
4
|
+
* still loads when npm resolves an older core. Escapes `%`, `/`, `#` and `:` so an id stays one scope
|
|
5
|
+
* segment. knowledge-scope-id.test.ts pins it to core's output.
|
|
6
|
+
*/
|
|
7
|
+
function encodeKnowledgeScopeId(id) {
|
|
8
|
+
return id.replaceAll("%", "%25").replaceAll("/", "%2F").replaceAll("#", "%23").replaceAll(":", "%3A");
|
|
9
|
+
}
|
|
10
|
+
export { encodeKnowledgeScopeId };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { MastraCodeState } from './schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* The org tag the built-in (`knowledge: true`) Knowledge writes under when the host gives no scopes. A
|
|
4
|
+
* fixed literal on purpose: deriving it from a hostname, machine id or path would fragment local
|
|
5
|
+
* Knowledge per machine or checkout, so several machines sharing one store could never share it.
|
|
6
|
+
*/
|
|
7
|
+
export declare const LOCAL_KNOWLEDGE_ORG_ID = "local";
|
|
8
|
+
export type KnowledgeSessionScopes = {
|
|
9
|
+
resolved: true;
|
|
10
|
+
scopes: string[];
|
|
11
|
+
} | {
|
|
12
|
+
resolved: false;
|
|
13
|
+
reason: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The scope tags a session's runs act with, beside each run's own identity tags: the host's `scopes`
|
|
17
|
+
* plus the session's own.
|
|
18
|
+
* Every Knowledge reader and writer in a session (the code agent, the /knowledge inspector) uses
|
|
19
|
+
* this, so what the agent writes is what the inspector reads.
|
|
20
|
+
*
|
|
21
|
+
* - Factory sessions require `org:<factoryOrgId>` and `project:<factoryProjectId>`, with each id
|
|
22
|
+
* encoded into one canonical segment, so projects stay isolated. A host `project:` tag with another
|
|
23
|
+
* value is refused. A Factory session with no org resolves to nothing (fail closed): a
|
|
24
|
+
* session owner is a user id, never an org.
|
|
25
|
+
* - A Factory session refuses a host `resource:` or `thread:` tag: those are each run's own identity,
|
|
26
|
+
* and a host one would let every run read that user's or thread's pages.
|
|
27
|
+
* - When the host's scopes name an `org:`, a Factory session acts with the host's scopes alone, without
|
|
28
|
+
* its own `org:` and `project:` tags, for a Knowledge instance that declares only that org; every org
|
|
29
|
+
* and project on the host shares it. A host `project:` tag is refused then, so the host can't stand
|
|
30
|
+
* in for a project.
|
|
31
|
+
* - Local sessions act with the host's scopes as given; they are canonical addresses already.
|
|
32
|
+
*/
|
|
33
|
+
export declare function resolveKnowledgeSessionScopes(state: Pick<MastraCodeState, 'factoryOrgId' | 'factoryProjectId' | 'factoryOrgUnresolved'> | undefined, hostScopes?: readonly string[]): KnowledgeSessionScopes;
|
|
34
|
+
/**
|
|
35
|
+
* The host's `resource:`/`thread:` tags.
|
|
36
|
+
* @deprecated Unused: an unresolved Factory session now adds no host tags to a run's scopes.
|
|
37
|
+
*/
|
|
38
|
+
export declare function knowledgeUnresolvedScopes(hostScopes: readonly string[]): string[];
|
|
39
|
+
/** The non-identity tags of a session's scopes, as plain strings. */
|
|
40
|
+
export declare function knowledgeSessionTags(scopes: readonly string[]): string[];
|
|
41
|
+
//# sourceMappingURL=knowledge-scope.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { encodeKnowledgeScopeId } from "./knowledge-scope-id.js";
|
|
2
|
+
// src/knowledge-scope.ts
|
|
3
|
+
/**
|
|
4
|
+
* The org tag the built-in (`knowledge: true`) Knowledge writes under when the host gives no scopes. A
|
|
5
|
+
* fixed literal on purpose: deriving it from a hostname, machine id or path would fragment local
|
|
6
|
+
* Knowledge per machine or checkout, so several machines sharing one store could never share it.
|
|
7
|
+
*/
|
|
8
|
+
const LOCAL_KNOWLEDGE_ORG_ID = "local";
|
|
9
|
+
function isIdentityTag(tag) {
|
|
10
|
+
return tag.startsWith("resource:") || tag.startsWith("thread:");
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The scope tags a session's runs act with, beside each run's own identity tags: the host's `scopes`
|
|
14
|
+
* plus the session's own.
|
|
15
|
+
* Every Knowledge reader and writer in a session (the code agent, the /knowledge inspector) uses
|
|
16
|
+
* this, so what the agent writes is what the inspector reads.
|
|
17
|
+
*
|
|
18
|
+
* - Factory sessions require `org:<factoryOrgId>` and `project:<factoryProjectId>`, with each id
|
|
19
|
+
* encoded into one canonical segment, so projects stay isolated. A host `project:` tag with another
|
|
20
|
+
* value is refused. A Factory session with no org resolves to nothing (fail closed): a
|
|
21
|
+
* session owner is a user id, never an org.
|
|
22
|
+
* - A Factory session refuses a host `resource:` or `thread:` tag: those are each run's own identity,
|
|
23
|
+
* and a host one would let every run read that user's or thread's pages.
|
|
24
|
+
* - When the host's scopes name an `org:`, a Factory session acts with the host's scopes alone, without
|
|
25
|
+
* its own `org:` and `project:` tags, for a Knowledge instance that declares only that org; every org
|
|
26
|
+
* and project on the host shares it. A host `project:` tag is refused then, so the host can't stand
|
|
27
|
+
* in for a project.
|
|
28
|
+
* - Local sessions act with the host's scopes as given; they are canonical addresses already.
|
|
29
|
+
*/
|
|
30
|
+
function resolveKnowledgeSessionScopes(state, hostScopes = []) {
|
|
31
|
+
const projectId = typeof state?.factoryProjectId === "string" ? state.factoryProjectId.trim() : "";
|
|
32
|
+
const orgId = typeof state?.factoryOrgId === "string" ? state.factoryOrgId.trim() : "";
|
|
33
|
+
if (projectId.length > 0 || orgId.length > 0 || state?.factoryOrgUnresolved === true) {
|
|
34
|
+
if (!orgId) return {
|
|
35
|
+
resolved: false,
|
|
36
|
+
reason: "This Factory session has no resolved organization."
|
|
37
|
+
};
|
|
38
|
+
const identity = hostScopes.find(isIdentityTag);
|
|
39
|
+
if (identity) return {
|
|
40
|
+
resolved: false,
|
|
41
|
+
reason: `Scope ${identity} is a run's identity and can't be a host scope.`
|
|
42
|
+
};
|
|
43
|
+
const hostOrg = hostScopes.find((tag) => tag.startsWith("org:"));
|
|
44
|
+
if (hostOrg) {
|
|
45
|
+
const refused = hostScopes.find((tag) => tag.startsWith("project:"));
|
|
46
|
+
if (refused) return {
|
|
47
|
+
resolved: false,
|
|
48
|
+
reason: `Scope ${refused} can't be held with the host's ${hostOrg}.`
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
resolved: true,
|
|
52
|
+
scopes: [...hostScopes]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const required = [`org:${encodeKnowledgeScopeId(orgId)}`, ...projectId ? [`project:${encodeKnowledgeScopeId(projectId)}`] : []];
|
|
56
|
+
for (const tag of hostScopes) {
|
|
57
|
+
const conflict = required.find((requiredTag) => requiredTag.startsWith("project:") && requiredTag !== tag);
|
|
58
|
+
if (tag.startsWith("project:") && conflict) return {
|
|
59
|
+
resolved: false,
|
|
60
|
+
reason: `Scope ${tag} conflicts with this Factory session's ${conflict}.`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const held = new Set(hostScopes);
|
|
64
|
+
return {
|
|
65
|
+
resolved: true,
|
|
66
|
+
scopes: [...hostScopes, ...required.filter((tag) => !held.has(tag))]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
resolved: true,
|
|
71
|
+
scopes: [...hostScopes]
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The host's `resource:`/`thread:` tags.
|
|
76
|
+
* @deprecated Unused: an unresolved Factory session now adds no host tags to a run's scopes.
|
|
77
|
+
*/
|
|
78
|
+
function knowledgeUnresolvedScopes(hostScopes) {
|
|
79
|
+
return hostScopes.filter(isIdentityTag);
|
|
80
|
+
}
|
|
81
|
+
/** The non-identity tags of a session's scopes, as plain strings. */
|
|
82
|
+
function knowledgeSessionTags(scopes) {
|
|
83
|
+
return scopes.filter((tag) => !isIdentityTag(tag));
|
|
84
|
+
}
|
|
85
|
+
export { LOCAL_KNOWLEDGE_ORG_ID, knowledgeSessionTags, knowledgeUnresolvedScopes, resolveKnowledgeSessionScopes };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Diagnostic } from 'vscode-languageserver-protocol';
|
|
2
|
+
import type { LSPServerInfo } from './server.js';
|
|
3
|
+
/**
|
|
4
|
+
* LSP Client wrapper for JSON-RPC communication
|
|
5
|
+
*/
|
|
6
|
+
export declare class LSPClient {
|
|
7
|
+
private connection;
|
|
8
|
+
private process;
|
|
9
|
+
private serverInfo;
|
|
10
|
+
private workspaceRoot;
|
|
11
|
+
private diagnostics;
|
|
12
|
+
private initializationOptions;
|
|
13
|
+
constructor(serverInfo: LSPServerInfo, workspaceRoot: string);
|
|
14
|
+
/**
|
|
15
|
+
* Initialize the LSP connection
|
|
16
|
+
*/
|
|
17
|
+
initialize(): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Notify the server that a document has been opened
|
|
20
|
+
*/
|
|
21
|
+
notifyOpen(filePath: string, content: string, languageId: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Notify the server that a document has changed
|
|
24
|
+
*/
|
|
25
|
+
notifyChange(filePath: string, content: string, version: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Wait for diagnostics to be available for a specific file
|
|
28
|
+
* @param waitForChange If true, waits for diagnostics to change from their initial state
|
|
29
|
+
*/
|
|
30
|
+
waitForDiagnostics(filePath: string, timeoutMs?: number, waitForChange?: boolean): Promise<Diagnostic[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Get hover information for a position
|
|
33
|
+
*/
|
|
34
|
+
getHover(filePath: string, line: number, character: number): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Get diagnostics for a specific file
|
|
37
|
+
*/
|
|
38
|
+
getDiagnostics(filePath: string): Diagnostic[];
|
|
39
|
+
/**
|
|
40
|
+
* Get all diagnostics from all files
|
|
41
|
+
*/
|
|
42
|
+
getAllDiagnostics(): Diagnostic[];
|
|
43
|
+
/**
|
|
44
|
+
* Notify server that a file was closed
|
|
45
|
+
*/
|
|
46
|
+
notifyClose(filePath: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Restart the LSP client
|
|
49
|
+
*/
|
|
50
|
+
restart(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Shutdown the connection
|
|
53
|
+
*/
|
|
54
|
+
shutdown(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { StreamMessageReader, StreamMessageWriter, createMessageConnection } from "vscode-jsonrpc/node.js";
|
|
2
|
+
import { Position, TextDocumentIdentifier } from "vscode-languageserver-protocol";
|
|
3
|
+
// src/lsp/client.ts
|
|
4
|
+
/**
|
|
5
|
+
* LSP Client wrapper for JSON-RPC communication
|
|
6
|
+
*/
|
|
7
|
+
var LSPClient = class {
|
|
8
|
+
connection = null;
|
|
9
|
+
process = null;
|
|
10
|
+
serverInfo;
|
|
11
|
+
workspaceRoot;
|
|
12
|
+
diagnostics = /* @__PURE__ */ new Map();
|
|
13
|
+
initializationOptions = null;
|
|
14
|
+
constructor(serverInfo, workspaceRoot) {
|
|
15
|
+
this.serverInfo = serverInfo;
|
|
16
|
+
this.workspaceRoot = workspaceRoot;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Initialize the LSP connection
|
|
20
|
+
*/
|
|
21
|
+
async initialize() {
|
|
22
|
+
const spawnResult = await this.serverInfo.spawn(this.workspaceRoot);
|
|
23
|
+
if (!spawnResult) throw new Error("Failed to spawn LSP server");
|
|
24
|
+
let initializationOptions = void 0;
|
|
25
|
+
if ("process" in spawnResult) {
|
|
26
|
+
this.process = spawnResult.process;
|
|
27
|
+
initializationOptions = spawnResult.initialization;
|
|
28
|
+
} else this.process = spawnResult;
|
|
29
|
+
if (!this.process.stdin || !this.process.stdout) throw new Error("Failed to create LSP process with proper stdio");
|
|
30
|
+
const reader = new StreamMessageReader(this.process.stdout);
|
|
31
|
+
const writer = new StreamMessageWriter(this.process.stdin);
|
|
32
|
+
this.connection = createMessageConnection(reader, writer);
|
|
33
|
+
this.connection.onError((error) => {
|
|
34
|
+
if ((error?.[0])?.code !== "ERR_STREAM_DESTROYED") {}
|
|
35
|
+
});
|
|
36
|
+
this.connection.onNotification("textDocument/publishDiagnostics", (params) => {
|
|
37
|
+
if (params.diagnostics && params.diagnostics.length > 0) {}
|
|
38
|
+
this.diagnostics.set(params.uri, params.diagnostics);
|
|
39
|
+
});
|
|
40
|
+
this.connection.onNotification((_method, _params) => {});
|
|
41
|
+
this.connection.listen();
|
|
42
|
+
if (this.process.stderr) this.process.stderr.on("data", (_data) => {});
|
|
43
|
+
this.process.on("error", (_error) => {});
|
|
44
|
+
this.process.on("exit", (_code, _signal) => {});
|
|
45
|
+
const initParams = {
|
|
46
|
+
processId: process.pid,
|
|
47
|
+
rootUri: `file://${this.workspaceRoot}`,
|
|
48
|
+
workspaceFolders: [{
|
|
49
|
+
name: "workspace",
|
|
50
|
+
uri: `file://${this.workspaceRoot}`
|
|
51
|
+
}],
|
|
52
|
+
capabilities: {
|
|
53
|
+
window: { workDoneProgress: true },
|
|
54
|
+
workspace: { configuration: true },
|
|
55
|
+
textDocument: {
|
|
56
|
+
publishDiagnostics: {
|
|
57
|
+
relatedInformation: true,
|
|
58
|
+
tagSupport: { valueSet: [1, 2] },
|
|
59
|
+
versionSupport: false
|
|
60
|
+
},
|
|
61
|
+
synchronization: {
|
|
62
|
+
didOpen: true,
|
|
63
|
+
didChange: true,
|
|
64
|
+
dynamicRegistration: false,
|
|
65
|
+
willSave: false,
|
|
66
|
+
willSaveWaitUntil: false,
|
|
67
|
+
didSave: false
|
|
68
|
+
},
|
|
69
|
+
completion: {
|
|
70
|
+
dynamicRegistration: false,
|
|
71
|
+
completionItem: {
|
|
72
|
+
snippetSupport: false,
|
|
73
|
+
commitCharactersSupport: false,
|
|
74
|
+
documentationFormat: ["markdown", "plaintext"],
|
|
75
|
+
deprecatedSupport: false,
|
|
76
|
+
preselectSupport: false
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
definition: {
|
|
80
|
+
dynamicRegistration: false,
|
|
81
|
+
linkSupport: true
|
|
82
|
+
},
|
|
83
|
+
typeDefinition: {
|
|
84
|
+
dynamicRegistration: false,
|
|
85
|
+
linkSupport: true
|
|
86
|
+
},
|
|
87
|
+
implementation: {
|
|
88
|
+
dynamicRegistration: false,
|
|
89
|
+
linkSupport: true
|
|
90
|
+
},
|
|
91
|
+
references: { dynamicRegistration: false },
|
|
92
|
+
documentHighlight: { dynamicRegistration: false },
|
|
93
|
+
documentSymbol: {
|
|
94
|
+
dynamicRegistration: false,
|
|
95
|
+
hierarchicalDocumentSymbolSupport: true
|
|
96
|
+
},
|
|
97
|
+
codeAction: {
|
|
98
|
+
dynamicRegistration: false,
|
|
99
|
+
codeActionLiteralSupport: { codeActionKind: { valueSet: [
|
|
100
|
+
"quickfix",
|
|
101
|
+
"refactor",
|
|
102
|
+
"refactor.extract",
|
|
103
|
+
"refactor.inline",
|
|
104
|
+
"refactor.rewrite",
|
|
105
|
+
"source",
|
|
106
|
+
"source.organizeImports"
|
|
107
|
+
] } }
|
|
108
|
+
},
|
|
109
|
+
hover: {
|
|
110
|
+
dynamicRegistration: false,
|
|
111
|
+
contentFormat: ["markdown", "plaintext"]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
if (initializationOptions) {
|
|
117
|
+
initParams.initializationOptions = initializationOptions;
|
|
118
|
+
this.initializationOptions = initializationOptions;
|
|
119
|
+
}
|
|
120
|
+
this.connection.onRequest("workspace/configuration", (params) => {
|
|
121
|
+
return params.items?.map(() => ({})) || [];
|
|
122
|
+
});
|
|
123
|
+
this.connection.onRequest("window/workDoneProgress/create", (_params) => {
|
|
124
|
+
return null;
|
|
125
|
+
});
|
|
126
|
+
await Promise.race([this.connection.sendRequest("initialize", initParams), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("LSP initialize request timed out")), 1e4))]);
|
|
127
|
+
this.connection.sendNotification("initialized", {});
|
|
128
|
+
if (this.initializationOptions) this.connection.sendNotification("workspace/didChangeConfiguration", { settings: this.initializationOptions });
|
|
129
|
+
else this.connection.sendNotification("workspace/didChangeConfiguration", { settings: {} });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Notify the server that a document has been opened
|
|
133
|
+
*/
|
|
134
|
+
notifyOpen(filePath, content, languageId) {
|
|
135
|
+
if (!this.connection) return;
|
|
136
|
+
const uri = `file://${filePath}`;
|
|
137
|
+
this.diagnostics.delete(uri);
|
|
138
|
+
this.connection.sendNotification("textDocument/didOpen", { textDocument: {
|
|
139
|
+
uri,
|
|
140
|
+
languageId,
|
|
141
|
+
version: 0,
|
|
142
|
+
text: content
|
|
143
|
+
} });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Notify the server that a document has changed
|
|
147
|
+
*/
|
|
148
|
+
notifyChange(filePath, content, version) {
|
|
149
|
+
if (!this.connection) return;
|
|
150
|
+
this.connection.sendNotification("textDocument/didChange", {
|
|
151
|
+
textDocument: {
|
|
152
|
+
uri: `file://${filePath}`,
|
|
153
|
+
version
|
|
154
|
+
},
|
|
155
|
+
contentChanges: [{ text: content }]
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Wait for diagnostics to be available for a specific file
|
|
160
|
+
* @param waitForChange If true, waits for diagnostics to change from their initial state
|
|
161
|
+
*/
|
|
162
|
+
async waitForDiagnostics(filePath, timeoutMs = 5e3, waitForChange = false) {
|
|
163
|
+
if (!this.connection) return [];
|
|
164
|
+
const uri = `file://${filePath}`;
|
|
165
|
+
const startTime = Date.now();
|
|
166
|
+
const initialDiagnostics = this.diagnostics.get(uri);
|
|
167
|
+
const initialCount = initialDiagnostics?.length || 0;
|
|
168
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
169
|
+
const currentDiagnostics = this.diagnostics.get(uri);
|
|
170
|
+
const currentCount = currentDiagnostics?.length || 0;
|
|
171
|
+
if (waitForChange) {
|
|
172
|
+
if (currentDiagnostics !== void 0 && currentCount !== initialCount) return currentDiagnostics;
|
|
173
|
+
} else if (currentDiagnostics !== void 0) return currentDiagnostics;
|
|
174
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
175
|
+
}
|
|
176
|
+
return waitForChange ? initialDiagnostics || [] : [];
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get hover information for a position
|
|
180
|
+
*/
|
|
181
|
+
async getHover(filePath, line, character) {
|
|
182
|
+
if (!this.connection) return null;
|
|
183
|
+
try {
|
|
184
|
+
return await this.connection.sendRequest("textDocument/hover", {
|
|
185
|
+
textDocument: TextDocumentIdentifier.create(`file://${filePath}`),
|
|
186
|
+
position: Position.create(line, character)
|
|
187
|
+
});
|
|
188
|
+
} catch {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Get diagnostics for a specific file
|
|
194
|
+
*/
|
|
195
|
+
getDiagnostics(filePath) {
|
|
196
|
+
const uri = `file://${filePath}`;
|
|
197
|
+
return this.diagnostics.get(uri) || [];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get all diagnostics from all files
|
|
201
|
+
*/
|
|
202
|
+
getAllDiagnostics() {
|
|
203
|
+
const allDiagnostics = [];
|
|
204
|
+
for (const diagnostics of this.diagnostics.values()) allDiagnostics.push(...diagnostics);
|
|
205
|
+
return allDiagnostics;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Notify server that a file was closed
|
|
209
|
+
*/
|
|
210
|
+
notifyClose(filePath) {
|
|
211
|
+
if (!this.connection) return;
|
|
212
|
+
const uri = `file://${filePath}`;
|
|
213
|
+
this.diagnostics.delete(uri);
|
|
214
|
+
this.connection.sendNotification("textDocument/didClose", { textDocument: TextDocumentIdentifier.create(uri) });
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Restart the LSP client
|
|
218
|
+
*/
|
|
219
|
+
async restart() {
|
|
220
|
+
await this.shutdown();
|
|
221
|
+
await this.initialize();
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Shutdown the connection
|
|
225
|
+
*/
|
|
226
|
+
async shutdown() {
|
|
227
|
+
if (this.connection) {
|
|
228
|
+
try {
|
|
229
|
+
if (this.process && !this.process.killed) {
|
|
230
|
+
await Promise.race([this.connection.sendRequest("shutdown"), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("Shutdown request timed out")), 1e3))]);
|
|
231
|
+
this.connection.sendNotification("exit");
|
|
232
|
+
}
|
|
233
|
+
} catch {}
|
|
234
|
+
try {
|
|
235
|
+
this.connection.dispose();
|
|
236
|
+
} catch {}
|
|
237
|
+
this.connection = null;
|
|
238
|
+
}
|
|
239
|
+
if (this.process) {
|
|
240
|
+
try {
|
|
241
|
+
if (!this.process.killed) this.process.kill();
|
|
242
|
+
} catch {}
|
|
243
|
+
this.process = null;
|
|
244
|
+
}
|
|
245
|
+
this.diagnostics = /* @__PURE__ */ new Map();
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
export { LSPClient };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps file extensions to LSP language identifiers
|
|
3
|
+
*/
|
|
4
|
+
export declare const LANGUAGE_EXTENSIONS: Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Get LSP language ID for a file path
|
|
7
|
+
*/
|
|
8
|
+
export declare function getLanguageId(filePath: string): string | undefined;
|
|
9
|
+
//# sourceMappingURL=language.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/lsp/language.ts
|
|
2
|
+
/**
|
|
3
|
+
* Maps file extensions to LSP language identifiers
|
|
4
|
+
*/
|
|
5
|
+
const LANGUAGE_EXTENSIONS = {
|
|
6
|
+
".ts": "typescript",
|
|
7
|
+
".tsx": "typescriptreact",
|
|
8
|
+
".js": "javascript",
|
|
9
|
+
".jsx": "javascriptreact",
|
|
10
|
+
".mjs": "javascript",
|
|
11
|
+
".cjs": "javascript",
|
|
12
|
+
".py": "python",
|
|
13
|
+
".pyi": "python",
|
|
14
|
+
".go": "go",
|
|
15
|
+
".rs": "rust",
|
|
16
|
+
".c": "c",
|
|
17
|
+
".cpp": "cpp",
|
|
18
|
+
".cc": "cpp",
|
|
19
|
+
".cxx": "cpp",
|
|
20
|
+
".h": "c",
|
|
21
|
+
".hpp": "cpp",
|
|
22
|
+
".java": "java",
|
|
23
|
+
".json": "json",
|
|
24
|
+
".jsonc": "jsonc",
|
|
25
|
+
".yaml": "yaml",
|
|
26
|
+
".yml": "yaml",
|
|
27
|
+
".md": "markdown",
|
|
28
|
+
".html": "html",
|
|
29
|
+
".css": "css",
|
|
30
|
+
".scss": "scss",
|
|
31
|
+
".sass": "sass",
|
|
32
|
+
".less": "less"
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Get LSP language ID for a file path
|
|
36
|
+
*/
|
|
37
|
+
function getLanguageId(filePath) {
|
|
38
|
+
const ext = filePath.substring(filePath.lastIndexOf("."));
|
|
39
|
+
return LANGUAGE_EXTENSIONS[ext];
|
|
40
|
+
}
|
|
41
|
+
export { LANGUAGE_EXTENSIONS, getLanguageId };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { LSPClient } from './client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Singleton LSP client manager that keeps clients alive and reuses them
|
|
4
|
+
* across tool calls for better performance and accuracy
|
|
5
|
+
*/
|
|
6
|
+
declare class LSPManager {
|
|
7
|
+
private clients;
|
|
8
|
+
private initializationPromises;
|
|
9
|
+
/**
|
|
10
|
+
* Get or create an LSP client for a file
|
|
11
|
+
* Returns null if no LSP server is available for the file
|
|
12
|
+
*/
|
|
13
|
+
getClient(filePath: string, workspaceRoot: string): Promise<LSPClient | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Shutdown a specific client
|
|
16
|
+
*/
|
|
17
|
+
shutdownClient(workspaceRoot: string, serverName?: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Shutdown all clients
|
|
20
|
+
*/
|
|
21
|
+
shutdownAll(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the number of active clients
|
|
24
|
+
*/
|
|
25
|
+
getActiveClientCount(): number;
|
|
26
|
+
/**
|
|
27
|
+
* Close a document in all active clients
|
|
28
|
+
* This is useful for tests that reuse the same file path
|
|
29
|
+
*/
|
|
30
|
+
closeDocument(filePath: string): void;
|
|
31
|
+
}
|
|
32
|
+
export declare const lspManager: LSPManager;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { LSPClient } from "./client.js";
|
|
2
|
+
import { getServersForFile } from "./server.js";
|
|
3
|
+
// src/lsp/manager.ts
|
|
4
|
+
/**
|
|
5
|
+
* Singleton LSP client manager that keeps clients alive and reuses them
|
|
6
|
+
* across tool calls for better performance and accuracy
|
|
7
|
+
*/
|
|
8
|
+
var LSPManager = class {
|
|
9
|
+
clients = /* @__PURE__ */ new Map();
|
|
10
|
+
initializationPromises = /* @__PURE__ */ new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Get or create an LSP client for a file
|
|
13
|
+
* Returns null if no LSP server is available for the file
|
|
14
|
+
*/
|
|
15
|
+
async getClient(filePath, workspaceRoot) {
|
|
16
|
+
const servers = getServersForFile(filePath, workspaceRoot);
|
|
17
|
+
if (servers.length === 0) return null;
|
|
18
|
+
const serverInfo = servers.find((s) => s.languageIds.includes("typescript") || s.languageIds.includes("javascript") || s.languageIds.includes("python") || s.languageIds.includes("go")) || servers[0];
|
|
19
|
+
if (!serverInfo) return null;
|
|
20
|
+
const key = `${serverInfo.name}:${workspaceRoot}`;
|
|
21
|
+
if (this.clients.has(key)) return this.clients.get(key);
|
|
22
|
+
if (this.initializationPromises.has(key)) {
|
|
23
|
+
await this.initializationPromises.get(key);
|
|
24
|
+
return this.clients.get(key) || null;
|
|
25
|
+
}
|
|
26
|
+
const initPromise = (async () => {
|
|
27
|
+
const client = new LSPClient(serverInfo, workspaceRoot);
|
|
28
|
+
await client.initialize();
|
|
29
|
+
this.clients.set(key, client);
|
|
30
|
+
})();
|
|
31
|
+
this.initializationPromises.set(key, initPromise);
|
|
32
|
+
try {
|
|
33
|
+
await Promise.race([initPromise, new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error("LSP client initialization timed out")), 15e3))]);
|
|
34
|
+
return this.clients.get(key) || null;
|
|
35
|
+
} catch {
|
|
36
|
+
this.clients.delete(key);
|
|
37
|
+
return null;
|
|
38
|
+
} finally {
|
|
39
|
+
this.initializationPromises.delete(key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Shutdown a specific client
|
|
44
|
+
*/
|
|
45
|
+
async shutdownClient(workspaceRoot, serverName) {
|
|
46
|
+
const keysToRemove = [];
|
|
47
|
+
for (const [key, client] of this.clients.entries()) if (key.includes(workspaceRoot) && (!serverName || key.startsWith(serverName))) {
|
|
48
|
+
await client.shutdown();
|
|
49
|
+
keysToRemove.push(key);
|
|
50
|
+
}
|
|
51
|
+
for (const key of keysToRemove) this.clients.delete(key);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Shutdown all clients
|
|
55
|
+
*/
|
|
56
|
+
async shutdownAll() {
|
|
57
|
+
const shutdownPromises = Array.from(this.clients.values()).map((client) => client.shutdown());
|
|
58
|
+
await Promise.all(shutdownPromises);
|
|
59
|
+
this.clients.clear();
|
|
60
|
+
this.initializationPromises.clear();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the number of active clients
|
|
64
|
+
*/
|
|
65
|
+
getActiveClientCount() {
|
|
66
|
+
return this.clients.size;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Close a document in all active clients
|
|
70
|
+
* This is useful for tests that reuse the same file path
|
|
71
|
+
*/
|
|
72
|
+
closeDocument(filePath) {
|
|
73
|
+
for (const client of this.clients.values()) try {
|
|
74
|
+
client.notifyClose(filePath);
|
|
75
|
+
} catch {}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const lspManager = new LSPManager();
|
|
79
|
+
export { lspManager };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
2
|
+
/**
|
|
3
|
+
* LSP Server definition and spawning logic
|
|
4
|
+
*/
|
|
5
|
+
export interface LSPServerInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
languageIds: string[];
|
|
9
|
+
root: (cwd: string) => string | null;
|
|
10
|
+
spawn: (root: string) => ChildProcess | Promise<{
|
|
11
|
+
process: ChildProcess;
|
|
12
|
+
initialization?: any;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Find the nearest project root directory
|
|
17
|
+
*/
|
|
18
|
+
export declare function findNearestRoot(cwd: string, markers: string[]): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Built-in LSP server definitions
|
|
21
|
+
*/
|
|
22
|
+
export declare const BUILTIN_SERVERS: Record<string, LSPServerInfo>;
|
|
23
|
+
/**
|
|
24
|
+
* Get all servers that can handle a file
|
|
25
|
+
*/
|
|
26
|
+
export declare function getServersForFile(filePath: string, cwd: string): LSPServerInfo[];
|
|
27
|
+
//# sourceMappingURL=server.d.ts.map
|