@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.
Files changed (407) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +284 -0
  3. package/dist/acp/agent.d.ts +48 -0
  4. package/dist/acp/agent.js +414 -0
  5. package/dist/acp/errors.d.ts +3 -0
  6. package/dist/acp/errors.js +11 -0
  7. package/dist/acp/event-mapper.d.ts +28 -0
  8. package/dist/acp/event-mapper.js +274 -0
  9. package/dist/acp/index.d.ts +9 -0
  10. package/dist/acp/index.js +21 -0
  11. package/dist/acp/runtime.d.ts +5 -0
  12. package/dist/acp/runtime.js +91 -0
  13. package/dist/acp/server.d.ts +4 -0
  14. package/dist/acp/server.js +35 -0
  15. package/dist/acp/skills.d.ts +6 -0
  16. package/dist/acp/skills.js +30 -0
  17. package/dist/acp.d.ts +2 -0
  18. package/dist/acp.js +1 -0
  19. package/dist/agent-connections/messaging-processor.d.ts +17 -0
  20. package/dist/agent-connections/messaging-processor.js +131 -0
  21. package/dist/agent-connections/ownership.d.ts +24 -0
  22. package/dist/agent-connections/ownership.js +96 -0
  23. package/dist/agent-connections/registry.d.ts +20 -0
  24. package/dist/agent-connections/registry.js +167 -0
  25. package/dist/agent-connections/session-advertisement.d.ts +27 -0
  26. package/dist/agent-connections/session-advertisement.js +86 -0
  27. package/dist/agent-connections/signal-provider.d.ts +141 -0
  28. package/dist/agent-connections/signal-provider.js +35 -0
  29. package/dist/agent-connections/state-processor.d.ts +23 -0
  30. package/dist/agent-connections/state-processor.js +270 -0
  31. package/dist/agent-connections/thread-state.d.ts +41 -0
  32. package/dist/agent-connections/thread-state.js +157 -0
  33. package/dist/agent-connections/tools.d.ts +133 -0
  34. package/dist/agent-connections/tools.js +616 -0
  35. package/dist/agent-connections/types.d.ts +99 -0
  36. package/dist/agent-connections/types.js +4 -0
  37. package/dist/agent-connections/untrusted-text.d.ts +5 -0
  38. package/dist/agent-connections/untrusted-text.js +19 -0
  39. package/dist/agents/background-completion-events.d.ts +16 -0
  40. package/dist/agents/background-completion-events.js +16 -0
  41. package/dist/agents/background-completion.d.ts +22 -0
  42. package/dist/agents/background-completion.js +73 -0
  43. package/dist/agents/context-audit.d.ts +84 -0
  44. package/dist/agents/context-audit.js +115 -0
  45. package/dist/agents/credential-resolver.d.ts +74 -0
  46. package/dist/agents/credential-resolver.js +142 -0
  47. package/dist/agents/custom-provider-source.d.ts +35 -0
  48. package/dist/agents/custom-provider-source.js +22 -0
  49. package/dist/agents/fastembed-subprocess.d.ts +52 -0
  50. package/dist/agents/fastembed-subprocess.js +282 -0
  51. package/dist/agents/instructions.d.ts +42 -0
  52. package/dist/agents/instructions.js +69 -0
  53. package/dist/agents/mastracode-gateway.d.ts +85 -0
  54. package/dist/agents/mastracode-gateway.js +500 -0
  55. package/dist/agents/memory.d.ts +36 -0
  56. package/dist/agents/memory.js +248 -0
  57. package/dist/agents/model.d.ts +158 -0
  58. package/dist/agents/model.js +382 -0
  59. package/dist/agents/modes/build.d.ts +12 -0
  60. package/dist/agents/modes/build.js +33 -0
  61. package/dist/agents/modes/explore.d.ts +10 -0
  62. package/dist/agents/modes/explore.js +25 -0
  63. package/dist/agents/modes/plan.d.ts +8 -0
  64. package/dist/agents/modes/plan.js +43 -0
  65. package/dist/agents/prompts/agent-instructions.d.ts +122 -0
  66. package/dist/agents/prompts/agent-instructions.js +617 -0
  67. package/dist/agents/prompts/build.d.ts +12 -0
  68. package/dist/agents/prompts/build.js +73 -0
  69. package/dist/agents/prompts/fast.d.ts +5 -0
  70. package/dist/agents/prompts/fast.js +23 -0
  71. package/dist/agents/prompts/index.d.ts +61 -0
  72. package/dist/agents/prompts/index.js +141 -0
  73. package/dist/agents/prompts/model.d.ts +5 -0
  74. package/dist/agents/prompts/model.js +20 -0
  75. package/dist/agents/prompts/plan.d.ts +11 -0
  76. package/dist/agents/prompts/plan.js +132 -0
  77. package/dist/agents/prompts/tool-guidance.d.ts +18 -0
  78. package/dist/agents/prompts/tool-guidance.js +158 -0
  79. package/dist/agents/sandbox-filesystem.d.ts +232 -0
  80. package/dist/agents/sandbox-filesystem.js +851 -0
  81. package/dist/agents/subagents/execute.d.ts +3 -0
  82. package/dist/agents/subagents/execute.js +24 -0
  83. package/dist/agents/subagents/explore.d.ts +3 -0
  84. package/dist/agents/subagents/explore.js +15 -0
  85. package/dist/agents/subagents/index.d.ts +6 -0
  86. package/dist/agents/subagents/index.js +15 -0
  87. package/dist/agents/subagents/plan.d.ts +3 -0
  88. package/dist/agents/subagents/plan.js +15 -0
  89. package/dist/agents/thread-caveman-state.d.ts +17 -0
  90. package/dist/agents/thread-caveman-state.js +104 -0
  91. package/dist/agents/tool-availability.d.ts +17 -0
  92. package/dist/agents/tool-availability.js +134 -0
  93. package/dist/agents/tools.d.ts +37 -0
  94. package/dist/agents/tools.js +154 -0
  95. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  96. package/dist/agents/workflow-builder-agent.js +79 -0
  97. package/dist/agents/workspace.d.ts +35 -0
  98. package/dist/agents/workspace.js +207 -0
  99. package/dist/analytics.d.ts +18 -0
  100. package/dist/analytics.js +159 -0
  101. package/dist/auth/account-rotation-processor.d.ts +210 -0
  102. package/dist/auth/account-rotation-processor.js +662 -0
  103. package/dist/auth/account-routing-context.d.ts +17 -0
  104. package/dist/auth/account-routing-context.js +38 -0
  105. package/dist/auth/authorization-input.d.ts +16 -0
  106. package/dist/auth/authorization-input.js +39 -0
  107. package/dist/auth/device-code.d.ts +93 -0
  108. package/dist/auth/device-code.js +126 -0
  109. package/dist/auth/index.d.ts +13 -0
  110. package/dist/auth/index.js +9 -0
  111. package/dist/auth/pkce.d.ts +13 -0
  112. package/dist/auth/pkce.js +29 -0
  113. package/dist/auth/provider-auth-error.d.ts +24 -0
  114. package/dist/auth/provider-auth-error.js +44 -0
  115. package/dist/auth/providers/anthropic.d.ts +40 -0
  116. package/dist/auth/providers/anthropic.js +117 -0
  117. package/dist/auth/providers/github-copilot.d.ts +154 -0
  118. package/dist/auth/providers/github-copilot.js +359 -0
  119. package/dist/auth/providers/kimi-coding.d.ts +38 -0
  120. package/dist/auth/providers/kimi-coding.js +225 -0
  121. package/dist/auth/providers/openai-codex.d.ts +141 -0
  122. package/dist/auth/providers/openai-codex.js +531 -0
  123. package/dist/auth/providers/xai.d.ts +64 -0
  124. package/dist/auth/providers/xai.js +223 -0
  125. package/dist/auth/storage.d.ts +222 -0
  126. package/dist/auth/storage.js +805 -0
  127. package/dist/auth/types.d.ts +164 -0
  128. package/dist/auth/types.js +1 -0
  129. package/dist/clipboard/index.d.ts +26 -0
  130. package/dist/clipboard/index.js +224 -0
  131. package/dist/constants.d.ts +29 -0
  132. package/dist/constants.js +34 -0
  133. package/dist/error-classification.d.ts +10 -0
  134. package/dist/error-classification.js +19 -0
  135. package/dist/evals/context-builder.d.ts +41 -0
  136. package/dist/evals/context-builder.js +156 -0
  137. package/dist/evals/index.d.ts +4 -0
  138. package/dist/evals/index.js +5 -0
  139. package/dist/evals/scorers/classify-command.d.ts +30 -0
  140. package/dist/evals/scorers/classify-command.js +61 -0
  141. package/dist/evals/scorers/efficiency.d.ts +44 -0
  142. package/dist/evals/scorers/efficiency.js +256 -0
  143. package/dist/evals/scorers/extract-tools.d.ts +25 -0
  144. package/dist/evals/scorers/extract-tools.js +57 -0
  145. package/dist/evals/scorers/index.d.ts +3 -0
  146. package/dist/evals/scorers/index.js +3 -0
  147. package/dist/evals/scorers/outcome.d.ts +49 -0
  148. package/dist/evals/scorers/outcome.js +360 -0
  149. package/dist/experimental-agent.d.ts +19 -0
  150. package/dist/experimental-agent.js +45 -0
  151. package/dist/factory/client.d.ts +44 -0
  152. package/dist/factory/client.js +110 -0
  153. package/dist/factory/remote-controller.d.ts +34 -0
  154. package/dist/factory/remote-controller.js +40 -0
  155. package/dist/factory/remote-session.d.ts +210 -0
  156. package/dist/factory/remote-session.js +415 -0
  157. package/dist/goal-manager.d.ts +114 -0
  158. package/dist/goal-manager.js +351 -0
  159. package/dist/goal-signal.d.ts +14 -0
  160. package/dist/goal-signal.js +14 -0
  161. package/dist/headless/cli.d.ts +55 -0
  162. package/dist/headless/cli.js +261 -0
  163. package/dist/headless/flags.d.ts +33 -0
  164. package/dist/headless/flags.js +207 -0
  165. package/dist/headless/format.d.ts +41 -0
  166. package/dist/headless/format.js +94 -0
  167. package/dist/headless/index.d.ts +25 -0
  168. package/dist/headless/index.js +6 -0
  169. package/dist/headless/policy.d.ts +17 -0
  170. package/dist/headless/policy.js +39 -0
  171. package/dist/headless/run-mc.d.ts +7 -0
  172. package/dist/headless/run-mc.js +438 -0
  173. package/dist/headless/types.d.ts +175 -0
  174. package/dist/headless/types.js +16 -0
  175. package/dist/hooks/config.d.ts +11 -0
  176. package/dist/hooks/config.js +77 -0
  177. package/dist/hooks/executor.d.ts +13 -0
  178. package/dist/hooks/executor.js +128 -0
  179. package/dist/hooks/index.d.ts +6 -0
  180. package/dist/hooks/index.js +5 -0
  181. package/dist/hooks/manager.d.ts +75 -0
  182. package/dist/hooks/manager.js +289 -0
  183. package/dist/hooks/types.d.ts +180 -0
  184. package/dist/hooks/types.js +5 -0
  185. package/dist/index.d.ts +537 -0
  186. package/dist/index.js +1399 -0
  187. package/dist/ipc/ipc-reporter.d.ts +14 -0
  188. package/dist/ipc/ipc-reporter.js +18 -0
  189. package/dist/knowledge-inspector.d.ts +139 -0
  190. package/dist/knowledge-inspector.js +533 -0
  191. package/dist/knowledge-scope-id.d.ts +7 -0
  192. package/dist/knowledge-scope-id.js +10 -0
  193. package/dist/knowledge-scope.d.ts +41 -0
  194. package/dist/knowledge-scope.js +85 -0
  195. package/dist/lsp/client.d.ts +56 -0
  196. package/dist/lsp/client.js +248 -0
  197. package/dist/lsp/index.d.ts +4 -0
  198. package/dist/lsp/index.js +4 -0
  199. package/dist/lsp/language.d.ts +9 -0
  200. package/dist/lsp/language.js +41 -0
  201. package/dist/lsp/manager.d.ts +34 -0
  202. package/dist/lsp/manager.js +79 -0
  203. package/dist/lsp/server.d.ts +27 -0
  204. package/dist/lsp/server.js +158 -0
  205. package/dist/lsp/workspace.d.ts +9 -0
  206. package/dist/lsp/workspace.js +52 -0
  207. package/dist/mcp/config.d.ts +77 -0
  208. package/dist/mcp/config.js +313 -0
  209. package/dist/mcp/index.d.ts +6 -0
  210. package/dist/mcp/index.js +3 -0
  211. package/dist/mcp/manager.d.ts +104 -0
  212. package/dist/mcp/manager.js +693 -0
  213. package/dist/mcp/state.d.ts +35 -0
  214. package/dist/mcp/state.js +94 -0
  215. package/dist/mcp/types.d.ts +139 -0
  216. package/dist/mcp/types.js +1 -0
  217. package/dist/onboarding/custom-packs.d.ts +7 -0
  218. package/dist/onboarding/custom-packs.js +17 -0
  219. package/dist/onboarding/custom-providers.d.ts +4 -0
  220. package/dist/onboarding/custom-providers.js +27 -0
  221. package/dist/onboarding/index.d.ts +5 -0
  222. package/dist/onboarding/index.js +3 -0
  223. package/dist/onboarding/om-settings.d.ts +47 -0
  224. package/dist/onboarding/om-settings.js +80 -0
  225. package/dist/onboarding/pack-activation.d.ts +43 -0
  226. package/dist/onboarding/pack-activation.js +105 -0
  227. package/dist/onboarding/packs.d.ts +106 -0
  228. package/dist/onboarding/packs.js +283 -0
  229. package/dist/onboarding/settings.d.ts +563 -0
  230. package/dist/onboarding/settings.js +1110 -0
  231. package/dist/permissions.d.ts +55 -0
  232. package/dist/permissions.js +139 -0
  233. package/dist/platform/index.d.ts +74 -0
  234. package/dist/platform/index.js +199 -0
  235. package/dist/plugin.d.ts +156 -0
  236. package/dist/plugin.js +27 -0
  237. package/dist/plugins/dependencies.d.ts +9 -0
  238. package/dist/plugins/dependencies.js +84 -0
  239. package/dist/plugins/install.d.ts +21 -0
  240. package/dist/plugins/install.js +187 -0
  241. package/dist/plugins/loader.d.ts +25 -0
  242. package/dist/plugins/loader.js +264 -0
  243. package/dist/plugins/manager.d.ts +115 -0
  244. package/dist/plugins/manager.js +507 -0
  245. package/dist/plugins/manifest.d.ts +14 -0
  246. package/dist/plugins/manifest.js +47 -0
  247. package/dist/plugins/package-link.d.ts +3 -0
  248. package/dist/plugins/package-link.js +58 -0
  249. package/dist/plugins/paths.d.ts +10 -0
  250. package/dist/plugins/paths.js +22 -0
  251. package/dist/plugins/registry.d.ts +8 -0
  252. package/dist/plugins/registry.js +109 -0
  253. package/dist/plugins/scaffold.d.ts +10 -0
  254. package/dist/plugins/scaffold.js +115 -0
  255. package/dist/plugins/signal-lane.d.ts +59 -0
  256. package/dist/plugins/signal-lane.js +163 -0
  257. package/dist/plugins/types.d.ts +95 -0
  258. package/dist/plugins/types.js +1 -0
  259. package/dist/process-memory-diagnostics.d.ts +136 -0
  260. package/dist/process-memory-diagnostics.js +497 -0
  261. package/dist/processors/plan-rejection-abort.d.ts +16 -0
  262. package/dist/processors/plan-rejection-abort.js +62 -0
  263. package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
  264. package/dist/providers/amazon-bedrock-gateway.js +142 -0
  265. package/dist/providers/amazon-bedrock.d.ts +28 -0
  266. package/dist/providers/amazon-bedrock.js +99 -0
  267. package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
  268. package/dist/providers/anthropic-prompt-cache.js +8 -0
  269. package/dist/providers/anthropic-thinking.d.ts +5 -0
  270. package/dist/providers/anthropic-thinking.js +22 -0
  271. package/dist/providers/claude-max.d.ts +67 -0
  272. package/dist/providers/claude-max.js +232 -0
  273. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  274. package/dist/providers/github-copilot-gateway.js +58 -0
  275. package/dist/providers/github-copilot.d.ts +60 -0
  276. package/dist/providers/github-copilot.js +320 -0
  277. package/dist/providers/google-thinking.d.ts +31 -0
  278. package/dist/providers/google-thinking.js +64 -0
  279. package/dist/providers/google-vertex-gateway.d.ts +23 -0
  280. package/dist/providers/google-vertex-gateway.js +49 -0
  281. package/dist/providers/google-vertex.d.ts +6 -0
  282. package/dist/providers/google-vertex.js +51 -0
  283. package/dist/providers/kimi-coding.d.ts +14 -0
  284. package/dist/providers/kimi-coding.js +80 -0
  285. package/dist/providers/model-ids.d.ts +53 -0
  286. package/dist/providers/model-ids.js +132 -0
  287. package/dist/providers/openai-codex.d.ts +114 -0
  288. package/dist/providers/openai-codex.js +427 -0
  289. package/dist/providers/provider-thinking.d.ts +23 -0
  290. package/dist/providers/provider-thinking.js +61 -0
  291. package/dist/providers/thinking-request.d.ts +14 -0
  292. package/dist/providers/thinking-request.js +87 -0
  293. package/dist/providers/xai.d.ts +33 -0
  294. package/dist/providers/xai.js +72 -0
  295. package/dist/schedules/index.d.ts +10 -0
  296. package/dist/schedules/index.js +6 -0
  297. package/dist/schedules/interval.d.ts +49 -0
  298. package/dist/schedules/interval.js +212 -0
  299. package/dist/schedules/prompt.d.ts +36 -0
  300. package/dist/schedules/prompt.js +36 -0
  301. package/dist/schedules/run-script.d.ts +8 -0
  302. package/dist/schedules/run-script.js +80 -0
  303. package/dist/schedules/scheduler.d.ts +101 -0
  304. package/dist/schedules/scheduler.js +167 -0
  305. package/dist/schedules/tools.d.ts +57 -0
  306. package/dist/schedules/tools.js +217 -0
  307. package/dist/schema.d.ts +499 -0
  308. package/dist/schema.js +131 -0
  309. package/dist/theme-palette.d.ts +17 -0
  310. package/dist/theme-palette.js +18 -0
  311. package/dist/thinking-catalog.d.ts +4 -0
  312. package/dist/thinking-catalog.js +13 -0
  313. package/dist/thinking.d.ts +37 -0
  314. package/dist/thinking.js +134 -0
  315. package/dist/tool-names.d.ts +77 -0
  316. package/dist/tool-names.js +53 -0
  317. package/dist/tools/index.d.ts +6 -0
  318. package/dist/tools/index.js +3 -0
  319. package/dist/tools/request-sandbox-access.d.ts +6 -0
  320. package/dist/tools/request-sandbox-access.js +80 -0
  321. package/dist/tools/utils.d.ts +20 -0
  322. package/dist/tools/utils.js +31 -0
  323. package/dist/tools/web-search.d.ts +116 -0
  324. package/dist/tools/web-search.js +158 -0
  325. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  326. package/dist/tools/workflows/create-workflow.js +82 -0
  327. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  328. package/dist/tools/workflows/delete-workflow.js +18 -0
  329. package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
  330. package/dist/tools/workflows/ephemeral-memory.js +41 -0
  331. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  332. package/dist/tools/workflows/extract-json-schema.js +19 -0
  333. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  334. package/dist/tools/workflows/get-workflow.js +31 -0
  335. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  336. package/dist/tools/workflows/list-available-agents.js +29 -0
  337. package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
  338. package/dist/tools/workflows/list-available-classifiers.js +53 -0
  339. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  340. package/dist/tools/workflows/list-available-tools.js +37 -0
  341. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  342. package/dist/tools/workflows/list-available-workflows.js +29 -0
  343. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  344. package/dist/tools/workflows/list-workflows.js +30 -0
  345. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  346. package/dist/tools/workflows/run-workflow.js +49 -0
  347. package/dist/tools/workflows/save-workflow.d.ts +1125 -0
  348. package/dist/tools/workflows/save-workflow.js +25 -0
  349. package/dist/tools/workflows/tool-ids.d.ts +16 -0
  350. package/dist/tools/workflows/tool-ids.js +17 -0
  351. package/dist/utils/binaries.d.ts +7 -0
  352. package/dist/utils/binaries.js +97 -0
  353. package/dist/utils/debug-log.d.ts +12 -0
  354. package/dist/utils/debug-log.js +56 -0
  355. package/dist/utils/discarding-scores-storage.d.ts +33 -0
  356. package/dist/utils/discarding-scores-storage.js +51 -0
  357. package/dist/utils/errors.d.ts +36 -0
  358. package/dist/utils/errors.js +215 -0
  359. package/dist/utils/gateway-sync.d.ts +26 -0
  360. package/dist/utils/gateway-sync.js +58 -0
  361. package/dist/utils/local-observability.d.ts +19 -0
  362. package/dist/utils/local-observability.js +54 -0
  363. package/dist/utils/maintenance-lock.d.ts +42 -0
  364. package/dist/utils/maintenance-lock.js +196 -0
  365. package/dist/utils/notification-dispatch.d.ts +74 -0
  366. package/dist/utils/notification-dispatch.js +128 -0
  367. package/dist/utils/open-url.d.ts +10 -0
  368. package/dist/utils/open-url.js +27 -0
  369. package/dist/utils/path-security.d.ts +2 -0
  370. package/dist/utils/path-security.js +7 -0
  371. package/dist/utils/plan-diff.d.ts +25 -0
  372. package/dist/utils/plan-diff.js +59 -0
  373. package/dist/utils/plans.d.ts +61 -0
  374. package/dist/utils/plans.js +120 -0
  375. package/dist/utils/project.d.ts +160 -0
  376. package/dist/utils/project.js +361 -0
  377. package/dist/utils/prune-cli.d.ts +24 -0
  378. package/dist/utils/prune-cli.js +124 -0
  379. package/dist/utils/signals-pubsub.d.ts +103 -0
  380. package/dist/utils/signals-pubsub.js +409 -0
  381. package/dist/utils/slash-command-loader.d.ts +52 -0
  382. package/dist/utils/slash-command-loader.js +139 -0
  383. package/dist/utils/slash-command-processor.d.ts +14 -0
  384. package/dist/utils/slash-command-processor.js +106 -0
  385. package/dist/utils/stdin-pipe.d.ts +33 -0
  386. package/dist/utils/stdin-pipe.js +93 -0
  387. package/dist/utils/storage-factory.d.ts +50 -0
  388. package/dist/utils/storage-factory.js +118 -0
  389. package/dist/utils/storage-maintenance.d.ts +121 -0
  390. package/dist/utils/storage-maintenance.js +352 -0
  391. package/dist/utils/thread-lock.d.ts +26 -0
  392. package/dist/utils/thread-lock.js +109 -0
  393. package/dist/utils/token-estimator.d.ts +3 -0
  394. package/dist/utils/token-estimator.js +19 -0
  395. package/dist/utils/update-check.d.ts +151 -0
  396. package/dist/utils/update-check.js +430 -0
  397. package/dist/utils/wake-session.d.ts +44 -0
  398. package/dist/utils/wake-session.js +83 -0
  399. package/dist/voice/stt-registry.d.ts +67 -0
  400. package/dist/voice/stt-registry.js +144 -0
  401. package/dist/voice/transcribe.d.ts +10 -0
  402. package/dist/voice/transcribe.js +75 -0
  403. package/dist/workflows/register-primitives.d.ts +52 -0
  404. package/dist/workflows/register-primitives.js +40 -0
  405. package/dist/workflows/service.d.ts +64 -0
  406. package/dist/workflows/service.js +50 -0
  407. 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,4 @@
1
+ export { LSPClient } from './client.js';
2
+ export { getServersForFile } from './server.js';
3
+ export { lspManager } from './manager.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,4 @@
1
+ import { LSPClient } from "./client.js";
2
+ import { getServersForFile } from "./server.js";
3
+ import { lspManager } from "./manager.js";
4
+ export { LSPClient, getServersForFile, lspManager };
@@ -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