@mastra/code-sdk 0.0.0-aggregate-trace-20261015182851

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 (749) 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.d.ts.map +1 -0
  5. package/dist/acp/agent.js +416 -0
  6. package/dist/acp/agent.js.map +1 -0
  7. package/dist/acp/errors.d.ts +3 -0
  8. package/dist/acp/errors.d.ts.map +1 -0
  9. package/dist/acp/errors.js +14 -0
  10. package/dist/acp/errors.js.map +1 -0
  11. package/dist/acp/event-mapper.d.ts +28 -0
  12. package/dist/acp/event-mapper.d.ts.map +1 -0
  13. package/dist/acp/event-mapper.js +279 -0
  14. package/dist/acp/event-mapper.js.map +1 -0
  15. package/dist/acp/index.d.ts +9 -0
  16. package/dist/acp/index.d.ts.map +1 -0
  17. package/dist/acp/index.js +24 -0
  18. package/dist/acp/index.js.map +1 -0
  19. package/dist/acp/runtime.d.ts +5 -0
  20. package/dist/acp/runtime.d.ts.map +1 -0
  21. package/dist/acp/runtime.js +91 -0
  22. package/dist/acp/runtime.js.map +1 -0
  23. package/dist/acp/server.d.ts +4 -0
  24. package/dist/acp/server.d.ts.map +1 -0
  25. package/dist/acp/server.js +38 -0
  26. package/dist/acp/server.js.map +1 -0
  27. package/dist/acp/skills.d.ts +6 -0
  28. package/dist/acp/skills.d.ts.map +1 -0
  29. package/dist/acp/skills.js +33 -0
  30. package/dist/acp/skills.js.map +1 -0
  31. package/dist/acp.d.ts +2 -0
  32. package/dist/acp.d.ts.map +1 -0
  33. package/dist/acp.js +2 -0
  34. package/dist/agent-connections/messaging-processor.d.ts +17 -0
  35. package/dist/agent-connections/messaging-processor.d.ts.map +1 -0
  36. package/dist/agent-connections/messaging-processor.js +134 -0
  37. package/dist/agent-connections/messaging-processor.js.map +1 -0
  38. package/dist/agent-connections/ownership.d.ts +24 -0
  39. package/dist/agent-connections/ownership.d.ts.map +1 -0
  40. package/dist/agent-connections/ownership.js +99 -0
  41. package/dist/agent-connections/ownership.js.map +1 -0
  42. package/dist/agent-connections/registry.d.ts +20 -0
  43. package/dist/agent-connections/registry.d.ts.map +1 -0
  44. package/dist/agent-connections/registry.js +170 -0
  45. package/dist/agent-connections/registry.js.map +1 -0
  46. package/dist/agent-connections/session-advertisement.d.ts +27 -0
  47. package/dist/agent-connections/session-advertisement.d.ts.map +1 -0
  48. package/dist/agent-connections/session-advertisement.js +89 -0
  49. package/dist/agent-connections/session-advertisement.js.map +1 -0
  50. package/dist/agent-connections/signal-provider.d.ts +141 -0
  51. package/dist/agent-connections/signal-provider.d.ts.map +1 -0
  52. package/dist/agent-connections/signal-provider.js +38 -0
  53. package/dist/agent-connections/signal-provider.js.map +1 -0
  54. package/dist/agent-connections/state-processor.d.ts +23 -0
  55. package/dist/agent-connections/state-processor.d.ts.map +1 -0
  56. package/dist/agent-connections/state-processor.js +273 -0
  57. package/dist/agent-connections/state-processor.js.map +1 -0
  58. package/dist/agent-connections/thread-state.d.ts +41 -0
  59. package/dist/agent-connections/thread-state.d.ts.map +1 -0
  60. package/dist/agent-connections/thread-state.js +160 -0
  61. package/dist/agent-connections/thread-state.js.map +1 -0
  62. package/dist/agent-connections/tools.d.ts +133 -0
  63. package/dist/agent-connections/tools.d.ts.map +1 -0
  64. package/dist/agent-connections/tools.js +552 -0
  65. package/dist/agent-connections/tools.js.map +1 -0
  66. package/dist/agent-connections/types.d.ts +99 -0
  67. package/dist/agent-connections/types.d.ts.map +1 -0
  68. package/dist/agent-connections/types.js +7 -0
  69. package/dist/agent-connections/types.js.map +1 -0
  70. package/dist/agent-connections/untrusted-text.d.ts +5 -0
  71. package/dist/agent-connections/untrusted-text.d.ts.map +1 -0
  72. package/dist/agent-connections/untrusted-text.js +22 -0
  73. package/dist/agent-connections/untrusted-text.js.map +1 -0
  74. package/dist/agents/background-completion-events.d.ts +16 -0
  75. package/dist/agents/background-completion-events.d.ts.map +1 -0
  76. package/dist/agents/background-completion-events.js +19 -0
  77. package/dist/agents/background-completion-events.js.map +1 -0
  78. package/dist/agents/background-completion.d.ts +9 -0
  79. package/dist/agents/background-completion.d.ts.map +1 -0
  80. package/dist/agents/background-completion.js +59 -0
  81. package/dist/agents/background-completion.js.map +1 -0
  82. package/dist/agents/context-audit.d.ts +84 -0
  83. package/dist/agents/context-audit.d.ts.map +1 -0
  84. package/dist/agents/context-audit.js +118 -0
  85. package/dist/agents/context-audit.js.map +1 -0
  86. package/dist/agents/credential-resolver.d.ts +67 -0
  87. package/dist/agents/credential-resolver.d.ts.map +1 -0
  88. package/dist/agents/credential-resolver.js +136 -0
  89. package/dist/agents/credential-resolver.js.map +1 -0
  90. package/dist/agents/custom-provider-source.d.ts +35 -0
  91. package/dist/agents/custom-provider-source.d.ts.map +1 -0
  92. package/dist/agents/custom-provider-source.js +25 -0
  93. package/dist/agents/custom-provider-source.js.map +1 -0
  94. package/dist/agents/instructions.d.ts +40 -0
  95. package/dist/agents/instructions.d.ts.map +1 -0
  96. package/dist/agents/instructions.js +63 -0
  97. package/dist/agents/instructions.js.map +1 -0
  98. package/dist/agents/mastracode-gateway.d.ts +76 -0
  99. package/dist/agents/mastracode-gateway.d.ts.map +1 -0
  100. package/dist/agents/mastracode-gateway.js +434 -0
  101. package/dist/agents/mastracode-gateway.js.map +1 -0
  102. package/dist/agents/memory.d.ts +39 -0
  103. package/dist/agents/memory.d.ts.map +1 -0
  104. package/dist/agents/memory.js +266 -0
  105. package/dist/agents/memory.js.map +1 -0
  106. package/dist/agents/model.d.ts +123 -0
  107. package/dist/agents/model.d.ts.map +1 -0
  108. package/dist/agents/model.js +295 -0
  109. package/dist/agents/model.js.map +1 -0
  110. package/dist/agents/modes/build.d.ts +12 -0
  111. package/dist/agents/modes/build.d.ts.map +1 -0
  112. package/dist/agents/modes/build.js +36 -0
  113. package/dist/agents/modes/build.js.map +1 -0
  114. package/dist/agents/modes/explore.d.ts +10 -0
  115. package/dist/agents/modes/explore.d.ts.map +1 -0
  116. package/dist/agents/modes/explore.js +28 -0
  117. package/dist/agents/modes/explore.js.map +1 -0
  118. package/dist/agents/modes/plan.d.ts +8 -0
  119. package/dist/agents/modes/plan.d.ts.map +1 -0
  120. package/dist/agents/modes/plan.js +46 -0
  121. package/dist/agents/modes/plan.js.map +1 -0
  122. package/dist/agents/prompts/agent-instructions.d.ts +99 -0
  123. package/dist/agents/prompts/agent-instructions.d.ts.map +1 -0
  124. package/dist/agents/prompts/agent-instructions.js +275 -0
  125. package/dist/agents/prompts/agent-instructions.js.map +1 -0
  126. package/dist/agents/prompts/build.d.ts +12 -0
  127. package/dist/agents/prompts/build.d.ts.map +1 -0
  128. package/dist/agents/prompts/build.js +76 -0
  129. package/dist/agents/prompts/build.js.map +1 -0
  130. package/dist/agents/prompts/fast.d.ts +5 -0
  131. package/dist/agents/prompts/fast.d.ts.map +1 -0
  132. package/dist/agents/prompts/fast.js +26 -0
  133. package/dist/agents/prompts/fast.js.map +1 -0
  134. package/dist/agents/prompts/index.d.ts +54 -0
  135. package/dist/agents/prompts/index.d.ts.map +1 -0
  136. package/dist/agents/prompts/index.js +127 -0
  137. package/dist/agents/prompts/index.js.map +1 -0
  138. package/dist/agents/prompts/model.d.ts +5 -0
  139. package/dist/agents/prompts/model.d.ts.map +1 -0
  140. package/dist/agents/prompts/model.js +23 -0
  141. package/dist/agents/prompts/model.js.map +1 -0
  142. package/dist/agents/prompts/plan.d.ts +8 -0
  143. package/dist/agents/prompts/plan.d.ts.map +1 -0
  144. package/dist/agents/prompts/plan.js +129 -0
  145. package/dist/agents/prompts/plan.js.map +1 -0
  146. package/dist/agents/prompts/tool-guidance.d.ts +18 -0
  147. package/dist/agents/prompts/tool-guidance.d.ts.map +1 -0
  148. package/dist/agents/prompts/tool-guidance.js +181 -0
  149. package/dist/agents/prompts/tool-guidance.js.map +1 -0
  150. package/dist/agents/sandbox-filesystem.d.ts +151 -0
  151. package/dist/agents/sandbox-filesystem.d.ts.map +1 -0
  152. package/dist/agents/sandbox-filesystem.js +581 -0
  153. package/dist/agents/sandbox-filesystem.js.map +1 -0
  154. package/dist/agents/subagents/execute.d.ts +3 -0
  155. package/dist/agents/subagents/execute.d.ts.map +1 -0
  156. package/dist/agents/subagents/execute.js +27 -0
  157. package/dist/agents/subagents/execute.js.map +1 -0
  158. package/dist/agents/subagents/explore.d.ts +3 -0
  159. package/dist/agents/subagents/explore.d.ts.map +1 -0
  160. package/dist/agents/subagents/explore.js +18 -0
  161. package/dist/agents/subagents/explore.js.map +1 -0
  162. package/dist/agents/subagents/plan.d.ts +3 -0
  163. package/dist/agents/subagents/plan.d.ts.map +1 -0
  164. package/dist/agents/subagents/plan.js +18 -0
  165. package/dist/agents/subagents/plan.js.map +1 -0
  166. package/dist/agents/thread-caveman-state.d.ts +17 -0
  167. package/dist/agents/thread-caveman-state.d.ts.map +1 -0
  168. package/dist/agents/thread-caveman-state.js +107 -0
  169. package/dist/agents/thread-caveman-state.js.map +1 -0
  170. package/dist/agents/tool-availability.d.ts +12 -0
  171. package/dist/agents/tool-availability.d.ts.map +1 -0
  172. package/dist/agents/tool-availability.js +129 -0
  173. package/dist/agents/tool-availability.js.map +1 -0
  174. package/dist/agents/tools.d.ts +37 -0
  175. package/dist/agents/tools.d.ts.map +1 -0
  176. package/dist/agents/tools.js +131 -0
  177. package/dist/agents/tools.js.map +1 -0
  178. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  179. package/dist/agents/workflow-builder-agent.d.ts.map +1 -0
  180. package/dist/agents/workflow-builder-agent.js +82 -0
  181. package/dist/agents/workflow-builder-agent.js.map +1 -0
  182. package/dist/agents/workspace.d.ts +33 -0
  183. package/dist/agents/workspace.d.ts.map +1 -0
  184. package/dist/agents/workspace.js +208 -0
  185. package/dist/agents/workspace.js.map +1 -0
  186. package/dist/analytics.d.ts +18 -0
  187. package/dist/analytics.d.ts.map +1 -0
  188. package/dist/analytics.js +162 -0
  189. package/dist/analytics.js.map +1 -0
  190. package/dist/auth/account-rotation-processor.d.ts +182 -0
  191. package/dist/auth/account-rotation-processor.d.ts.map +1 -0
  192. package/dist/auth/account-rotation-processor.js +609 -0
  193. package/dist/auth/account-rotation-processor.js.map +1 -0
  194. package/dist/auth/account-routing-context.d.ts +13 -0
  195. package/dist/auth/account-routing-context.d.ts.map +1 -0
  196. package/dist/auth/account-routing-context.js +41 -0
  197. package/dist/auth/account-routing-context.js.map +1 -0
  198. package/dist/auth/authorization-input.d.ts +16 -0
  199. package/dist/auth/authorization-input.d.ts.map +1 -0
  200. package/dist/auth/authorization-input.js +42 -0
  201. package/dist/auth/authorization-input.js.map +1 -0
  202. package/dist/auth/device-code.d.ts +93 -0
  203. package/dist/auth/device-code.d.ts.map +1 -0
  204. package/dist/auth/device-code.js +129 -0
  205. package/dist/auth/device-code.js.map +1 -0
  206. package/dist/auth/index.d.ts +13 -0
  207. package/dist/auth/index.d.ts.map +1 -0
  208. package/dist/auth/index.js +9 -0
  209. package/dist/auth/pkce.d.ts +13 -0
  210. package/dist/auth/pkce.d.ts.map +1 -0
  211. package/dist/auth/pkce.js +32 -0
  212. package/dist/auth/pkce.js.map +1 -0
  213. package/dist/auth/provider-auth-error.d.ts +12 -0
  214. package/dist/auth/provider-auth-error.d.ts.map +1 -0
  215. package/dist/auth/provider-auth-error.js +16 -0
  216. package/dist/auth/provider-auth-error.js.map +1 -0
  217. package/dist/auth/providers/anthropic.d.ts +40 -0
  218. package/dist/auth/providers/anthropic.d.ts.map +1 -0
  219. package/dist/auth/providers/anthropic.js +120 -0
  220. package/dist/auth/providers/anthropic.js.map +1 -0
  221. package/dist/auth/providers/github-copilot.d.ts +154 -0
  222. package/dist/auth/providers/github-copilot.d.ts.map +1 -0
  223. package/dist/auth/providers/github-copilot.js +362 -0
  224. package/dist/auth/providers/github-copilot.js.map +1 -0
  225. package/dist/auth/providers/kimi-coding.d.ts +38 -0
  226. package/dist/auth/providers/kimi-coding.d.ts.map +1 -0
  227. package/dist/auth/providers/kimi-coding.js +228 -0
  228. package/dist/auth/providers/kimi-coding.js.map +1 -0
  229. package/dist/auth/providers/openai-codex.d.ts +141 -0
  230. package/dist/auth/providers/openai-codex.d.ts.map +1 -0
  231. package/dist/auth/providers/openai-codex.js +533 -0
  232. package/dist/auth/providers/openai-codex.js.map +1 -0
  233. package/dist/auth/providers/xai.d.ts +64 -0
  234. package/dist/auth/providers/xai.d.ts.map +1 -0
  235. package/dist/auth/providers/xai.js +226 -0
  236. package/dist/auth/providers/xai.js.map +1 -0
  237. package/dist/auth/storage.d.ts +214 -0
  238. package/dist/auth/storage.d.ts.map +1 -0
  239. package/dist/auth/storage.js +774 -0
  240. package/dist/auth/storage.js.map +1 -0
  241. package/dist/auth/types.d.ts +164 -0
  242. package/dist/auth/types.d.ts.map +1 -0
  243. package/dist/auth/types.js +1 -0
  244. package/dist/clipboard/index.d.ts +26 -0
  245. package/dist/clipboard/index.d.ts.map +1 -0
  246. package/dist/clipboard/index.js +226 -0
  247. package/dist/clipboard/index.js.map +1 -0
  248. package/dist/constants.d.ts +12 -0
  249. package/dist/constants.d.ts.map +1 -0
  250. package/dist/constants.js +20 -0
  251. package/dist/constants.js.map +1 -0
  252. package/dist/error-classification.d.ts +10 -0
  253. package/dist/error-classification.d.ts.map +1 -0
  254. package/dist/error-classification.js +22 -0
  255. package/dist/error-classification.js.map +1 -0
  256. package/dist/evals/context-builder.d.ts +41 -0
  257. package/dist/evals/context-builder.d.ts.map +1 -0
  258. package/dist/evals/context-builder.js +161 -0
  259. package/dist/evals/context-builder.js.map +1 -0
  260. package/dist/evals/index.d.ts +4 -0
  261. package/dist/evals/index.d.ts.map +1 -0
  262. package/dist/evals/index.js +5 -0
  263. package/dist/evals/scorers/classify-command.d.ts +31 -0
  264. package/dist/evals/scorers/classify-command.d.ts.map +1 -0
  265. package/dist/evals/scorers/classify-command.js +73 -0
  266. package/dist/evals/scorers/classify-command.js.map +1 -0
  267. package/dist/evals/scorers/efficiency.d.ts +44 -0
  268. package/dist/evals/scorers/efficiency.d.ts.map +1 -0
  269. package/dist/evals/scorers/efficiency.js +259 -0
  270. package/dist/evals/scorers/efficiency.js.map +1 -0
  271. package/dist/evals/scorers/extract-tools.d.ts +25 -0
  272. package/dist/evals/scorers/extract-tools.d.ts.map +1 -0
  273. package/dist/evals/scorers/extract-tools.js +60 -0
  274. package/dist/evals/scorers/extract-tools.js.map +1 -0
  275. package/dist/evals/scorers/index.d.ts +3 -0
  276. package/dist/evals/scorers/index.d.ts.map +1 -0
  277. package/dist/evals/scorers/index.js +3 -0
  278. package/dist/evals/scorers/outcome.d.ts +49 -0
  279. package/dist/evals/scorers/outcome.d.ts.map +1 -0
  280. package/dist/evals/scorers/outcome.js +347 -0
  281. package/dist/evals/scorers/outcome.js.map +1 -0
  282. package/dist/experimental-agent.d.ts +11 -0
  283. package/dist/experimental-agent.d.ts.map +1 -0
  284. package/dist/experimental-agent.js +36 -0
  285. package/dist/experimental-agent.js.map +1 -0
  286. package/dist/goal-manager.d.ts +114 -0
  287. package/dist/goal-manager.d.ts.map +1 -0
  288. package/dist/goal-manager.js +354 -0
  289. package/dist/goal-manager.js.map +1 -0
  290. package/dist/goal-signal.d.ts +14 -0
  291. package/dist/goal-signal.d.ts.map +1 -0
  292. package/dist/goal-signal.js +17 -0
  293. package/dist/goal-signal.js.map +1 -0
  294. package/dist/headless/cli.d.ts +48 -0
  295. package/dist/headless/cli.d.ts.map +1 -0
  296. package/dist/headless/cli.js +239 -0
  297. package/dist/headless/cli.js.map +1 -0
  298. package/dist/headless/flags.d.ts +33 -0
  299. package/dist/headless/flags.d.ts.map +1 -0
  300. package/dist/headless/flags.js +203 -0
  301. package/dist/headless/flags.js.map +1 -0
  302. package/dist/headless/format.d.ts +39 -0
  303. package/dist/headless/format.d.ts.map +1 -0
  304. package/dist/headless/format.js +85 -0
  305. package/dist/headless/format.js.map +1 -0
  306. package/dist/headless/index.d.ts +25 -0
  307. package/dist/headless/index.d.ts.map +1 -0
  308. package/dist/headless/index.js +6 -0
  309. package/dist/headless/policy.d.ts +17 -0
  310. package/dist/headless/policy.d.ts.map +1 -0
  311. package/dist/headless/policy.js +42 -0
  312. package/dist/headless/policy.js.map +1 -0
  313. package/dist/headless/run-mc.d.ts +7 -0
  314. package/dist/headless/run-mc.d.ts.map +1 -0
  315. package/dist/headless/run-mc.js +408 -0
  316. package/dist/headless/run-mc.js.map +1 -0
  317. package/dist/headless/types.d.ts +174 -0
  318. package/dist/headless/types.d.ts.map +1 -0
  319. package/dist/headless/types.js +19 -0
  320. package/dist/headless/types.js.map +1 -0
  321. package/dist/hooks/config.d.ts +11 -0
  322. package/dist/hooks/config.d.ts.map +1 -0
  323. package/dist/hooks/config.js +80 -0
  324. package/dist/hooks/config.js.map +1 -0
  325. package/dist/hooks/executor.d.ts +13 -0
  326. package/dist/hooks/executor.d.ts.map +1 -0
  327. package/dist/hooks/executor.js +129 -0
  328. package/dist/hooks/executor.js.map +1 -0
  329. package/dist/hooks/index.d.ts +6 -0
  330. package/dist/hooks/index.d.ts.map +1 -0
  331. package/dist/hooks/index.js +5 -0
  332. package/dist/hooks/manager.d.ts +54 -0
  333. package/dist/hooks/manager.d.ts.map +1 -0
  334. package/dist/hooks/manager.js +241 -0
  335. package/dist/hooks/manager.js.map +1 -0
  336. package/dist/hooks/types.d.ts +172 -0
  337. package/dist/hooks/types.d.ts.map +1 -0
  338. package/dist/hooks/types.js +8 -0
  339. package/dist/hooks/types.js.map +1 -0
  340. package/dist/index.d.ts +463 -0
  341. package/dist/index.d.ts.map +1 -0
  342. package/dist/index.js +1305 -0
  343. package/dist/index.js.map +1 -0
  344. package/dist/ipc/ipc-reporter.d.ts +14 -0
  345. package/dist/ipc/ipc-reporter.d.ts.map +1 -0
  346. package/dist/ipc/ipc-reporter.js +21 -0
  347. package/dist/ipc/ipc-reporter.js.map +1 -0
  348. package/dist/knowledge-inspector.d.ts +123 -0
  349. package/dist/knowledge-inspector.d.ts.map +1 -0
  350. package/dist/knowledge-inspector.js +516 -0
  351. package/dist/knowledge-inspector.js.map +1 -0
  352. package/dist/knowledge-scope.d.ts +35 -0
  353. package/dist/knowledge-scope.d.ts.map +1 -0
  354. package/dist/knowledge-scope.js +47 -0
  355. package/dist/knowledge-scope.js.map +1 -0
  356. package/dist/lsp/client.d.ts +56 -0
  357. package/dist/lsp/client.d.ts.map +1 -0
  358. package/dist/lsp/client.js +251 -0
  359. package/dist/lsp/client.js.map +1 -0
  360. package/dist/lsp/index.d.ts +4 -0
  361. package/dist/lsp/index.d.ts.map +1 -0
  362. package/dist/lsp/index.js +4 -0
  363. package/dist/lsp/language.d.ts +9 -0
  364. package/dist/lsp/language.d.ts.map +1 -0
  365. package/dist/lsp/language.js +44 -0
  366. package/dist/lsp/language.js.map +1 -0
  367. package/dist/lsp/manager.d.ts +34 -0
  368. package/dist/lsp/manager.d.ts.map +1 -0
  369. package/dist/lsp/manager.js +82 -0
  370. package/dist/lsp/manager.js.map +1 -0
  371. package/dist/lsp/server.d.ts +27 -0
  372. package/dist/lsp/server.d.ts.map +1 -0
  373. package/dist/lsp/server.js +159 -0
  374. package/dist/lsp/server.js.map +1 -0
  375. package/dist/lsp/workspace.d.ts +9 -0
  376. package/dist/lsp/workspace.d.ts.map +1 -0
  377. package/dist/lsp/workspace.js +55 -0
  378. package/dist/lsp/workspace.js.map +1 -0
  379. package/dist/mcp/config.d.ts +77 -0
  380. package/dist/mcp/config.d.ts.map +1 -0
  381. package/dist/mcp/config.js +316 -0
  382. package/dist/mcp/config.js.map +1 -0
  383. package/dist/mcp/index.d.ts +6 -0
  384. package/dist/mcp/index.d.ts.map +1 -0
  385. package/dist/mcp/index.js +3 -0
  386. package/dist/mcp/manager.d.ts +102 -0
  387. package/dist/mcp/manager.d.ts.map +1 -0
  388. package/dist/mcp/manager.js +650 -0
  389. package/dist/mcp/manager.js.map +1 -0
  390. package/dist/mcp/state.d.ts +35 -0
  391. package/dist/mcp/state.d.ts.map +1 -0
  392. package/dist/mcp/state.js +97 -0
  393. package/dist/mcp/state.js.map +1 -0
  394. package/dist/mcp/types.d.ts +139 -0
  395. package/dist/mcp/types.d.ts.map +1 -0
  396. package/dist/mcp/types.js +1 -0
  397. package/dist/onboarding/custom-packs.d.ts +7 -0
  398. package/dist/onboarding/custom-packs.d.ts.map +1 -0
  399. package/dist/onboarding/custom-packs.js +20 -0
  400. package/dist/onboarding/custom-packs.js.map +1 -0
  401. package/dist/onboarding/custom-providers.d.ts +4 -0
  402. package/dist/onboarding/custom-providers.d.ts.map +1 -0
  403. package/dist/onboarding/custom-providers.js +30 -0
  404. package/dist/onboarding/custom-providers.js.map +1 -0
  405. package/dist/onboarding/index.d.ts +5 -0
  406. package/dist/onboarding/index.d.ts.map +1 -0
  407. package/dist/onboarding/index.js +3 -0
  408. package/dist/onboarding/om-settings.d.ts +47 -0
  409. package/dist/onboarding/om-settings.d.ts.map +1 -0
  410. package/dist/onboarding/om-settings.js +83 -0
  411. package/dist/onboarding/om-settings.js.map +1 -0
  412. package/dist/onboarding/pack-activation.d.ts +52 -0
  413. package/dist/onboarding/pack-activation.d.ts.map +1 -0
  414. package/dist/onboarding/pack-activation.js +108 -0
  415. package/dist/onboarding/pack-activation.js.map +1 -0
  416. package/dist/onboarding/packs.d.ts +102 -0
  417. package/dist/onboarding/packs.d.ts.map +1 -0
  418. package/dist/onboarding/packs.js +278 -0
  419. package/dist/onboarding/packs.js.map +1 -0
  420. package/dist/onboarding/settings.d.ts +538 -0
  421. package/dist/onboarding/settings.d.ts.map +1 -0
  422. package/dist/onboarding/settings.js +1060 -0
  423. package/dist/onboarding/settings.js.map +1 -0
  424. package/dist/permissions.d.ts +55 -0
  425. package/dist/permissions.d.ts.map +1 -0
  426. package/dist/permissions.js +142 -0
  427. package/dist/permissions.js.map +1 -0
  428. package/dist/plugin.d.ts +156 -0
  429. package/dist/plugin.d.ts.map +1 -0
  430. package/dist/plugin.js +30 -0
  431. package/dist/plugin.js.map +1 -0
  432. package/dist/plugins/dependencies.d.ts +9 -0
  433. package/dist/plugins/dependencies.d.ts.map +1 -0
  434. package/dist/plugins/dependencies.js +87 -0
  435. package/dist/plugins/dependencies.js.map +1 -0
  436. package/dist/plugins/install.d.ts +21 -0
  437. package/dist/plugins/install.d.ts.map +1 -0
  438. package/dist/plugins/install.js +190 -0
  439. package/dist/plugins/install.js.map +1 -0
  440. package/dist/plugins/loader.d.ts +19 -0
  441. package/dist/plugins/loader.d.ts.map +1 -0
  442. package/dist/plugins/loader.js +260 -0
  443. package/dist/plugins/loader.js.map +1 -0
  444. package/dist/plugins/manager.d.ts +98 -0
  445. package/dist/plugins/manager.d.ts.map +1 -0
  446. package/dist/plugins/manager.js +456 -0
  447. package/dist/plugins/manager.js.map +1 -0
  448. package/dist/plugins/manifest.d.ts +14 -0
  449. package/dist/plugins/manifest.d.ts.map +1 -0
  450. package/dist/plugins/manifest.js +50 -0
  451. package/dist/plugins/manifest.js.map +1 -0
  452. package/dist/plugins/package-link.d.ts +3 -0
  453. package/dist/plugins/package-link.d.ts.map +1 -0
  454. package/dist/plugins/package-link.js +61 -0
  455. package/dist/plugins/package-link.js.map +1 -0
  456. package/dist/plugins/paths.d.ts +10 -0
  457. package/dist/plugins/paths.d.ts.map +1 -0
  458. package/dist/plugins/paths.js +25 -0
  459. package/dist/plugins/paths.js.map +1 -0
  460. package/dist/plugins/registry.d.ts +8 -0
  461. package/dist/plugins/registry.d.ts.map +1 -0
  462. package/dist/plugins/registry.js +112 -0
  463. package/dist/plugins/registry.js.map +1 -0
  464. package/dist/plugins/scaffold.d.ts +10 -0
  465. package/dist/plugins/scaffold.d.ts.map +1 -0
  466. package/dist/plugins/scaffold.js +116 -0
  467. package/dist/plugins/scaffold.js.map +1 -0
  468. package/dist/plugins/signal-lane.d.ts +58 -0
  469. package/dist/plugins/signal-lane.d.ts.map +1 -0
  470. package/dist/plugins/signal-lane.js +166 -0
  471. package/dist/plugins/signal-lane.js.map +1 -0
  472. package/dist/plugins/types.d.ts +81 -0
  473. package/dist/plugins/types.d.ts.map +1 -0
  474. package/dist/plugins/types.js +1 -0
  475. package/dist/process-memory-diagnostics.d.ts +135 -0
  476. package/dist/process-memory-diagnostics.d.ts.map +1 -0
  477. package/dist/process-memory-diagnostics.js +499 -0
  478. package/dist/process-memory-diagnostics.js.map +1 -0
  479. package/dist/processors/plan-rejection-abort.d.ts +12 -0
  480. package/dist/processors/plan-rejection-abort.d.ts.map +1 -0
  481. package/dist/processors/plan-rejection-abort.js +54 -0
  482. package/dist/processors/plan-rejection-abort.js.map +1 -0
  483. package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
  484. package/dist/providers/amazon-bedrock-gateway.d.ts.map +1 -0
  485. package/dist/providers/amazon-bedrock-gateway.js +144 -0
  486. package/dist/providers/amazon-bedrock-gateway.js.map +1 -0
  487. package/dist/providers/amazon-bedrock.d.ts +28 -0
  488. package/dist/providers/amazon-bedrock.d.ts.map +1 -0
  489. package/dist/providers/amazon-bedrock.js +102 -0
  490. package/dist/providers/amazon-bedrock.js.map +1 -0
  491. package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
  492. package/dist/providers/anthropic-prompt-cache.d.ts.map +1 -0
  493. package/dist/providers/anthropic-prompt-cache.js +11 -0
  494. package/dist/providers/anthropic-prompt-cache.js.map +1 -0
  495. package/dist/providers/anthropic-thinking.d.ts +5 -0
  496. package/dist/providers/anthropic-thinking.d.ts.map +1 -0
  497. package/dist/providers/anthropic-thinking.js +25 -0
  498. package/dist/providers/anthropic-thinking.js.map +1 -0
  499. package/dist/providers/claude-max.d.ts +67 -0
  500. package/dist/providers/claude-max.d.ts.map +1 -0
  501. package/dist/providers/claude-max.js +226 -0
  502. package/dist/providers/claude-max.js.map +1 -0
  503. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  504. package/dist/providers/github-copilot-gateway.d.ts.map +1 -0
  505. package/dist/providers/github-copilot-gateway.js +61 -0
  506. package/dist/providers/github-copilot-gateway.js.map +1 -0
  507. package/dist/providers/github-copilot.d.ts +60 -0
  508. package/dist/providers/github-copilot.d.ts.map +1 -0
  509. package/dist/providers/github-copilot.js +318 -0
  510. package/dist/providers/github-copilot.js.map +1 -0
  511. package/dist/providers/google-thinking.d.ts +31 -0
  512. package/dist/providers/google-thinking.d.ts.map +1 -0
  513. package/dist/providers/google-thinking.js +67 -0
  514. package/dist/providers/google-thinking.js.map +1 -0
  515. package/dist/providers/kimi-coding.d.ts +14 -0
  516. package/dist/providers/kimi-coding.d.ts.map +1 -0
  517. package/dist/providers/kimi-coding.js +78 -0
  518. package/dist/providers/kimi-coding.js.map +1 -0
  519. package/dist/providers/model-ids.d.ts +30 -0
  520. package/dist/providers/model-ids.d.ts.map +1 -0
  521. package/dist/providers/model-ids.js +79 -0
  522. package/dist/providers/model-ids.js.map +1 -0
  523. package/dist/providers/openai-codex.d.ts +84 -0
  524. package/dist/providers/openai-codex.d.ts.map +1 -0
  525. package/dist/providers/openai-codex.js +347 -0
  526. package/dist/providers/openai-codex.js.map +1 -0
  527. package/dist/providers/provider-thinking.d.ts +23 -0
  528. package/dist/providers/provider-thinking.d.ts.map +1 -0
  529. package/dist/providers/provider-thinking.js +64 -0
  530. package/dist/providers/provider-thinking.js.map +1 -0
  531. package/dist/providers/thinking-request.d.ts +14 -0
  532. package/dist/providers/thinking-request.d.ts.map +1 -0
  533. package/dist/providers/thinking-request.js +90 -0
  534. package/dist/providers/thinking-request.js.map +1 -0
  535. package/dist/providers/xai.d.ts +33 -0
  536. package/dist/providers/xai.d.ts.map +1 -0
  537. package/dist/providers/xai.js +71 -0
  538. package/dist/providers/xai.js.map +1 -0
  539. package/dist/schedules/index.d.ts +10 -0
  540. package/dist/schedules/index.d.ts.map +1 -0
  541. package/dist/schedules/index.js +6 -0
  542. package/dist/schedules/interval.d.ts +49 -0
  543. package/dist/schedules/interval.d.ts.map +1 -0
  544. package/dist/schedules/interval.js +215 -0
  545. package/dist/schedules/interval.js.map +1 -0
  546. package/dist/schedules/prompt.d.ts +36 -0
  547. package/dist/schedules/prompt.d.ts.map +1 -0
  548. package/dist/schedules/prompt.js +39 -0
  549. package/dist/schedules/prompt.js.map +1 -0
  550. package/dist/schedules/run-script.d.ts +8 -0
  551. package/dist/schedules/run-script.d.ts.map +1 -0
  552. package/dist/schedules/run-script.js +83 -0
  553. package/dist/schedules/run-script.js.map +1 -0
  554. package/dist/schedules/scheduler.d.ts +101 -0
  555. package/dist/schedules/scheduler.d.ts.map +1 -0
  556. package/dist/schedules/scheduler.js +169 -0
  557. package/dist/schedules/scheduler.js.map +1 -0
  558. package/dist/schedules/tools.d.ts +57 -0
  559. package/dist/schedules/tools.d.ts.map +1 -0
  560. package/dist/schedules/tools.js +220 -0
  561. package/dist/schedules/tools.js.map +1 -0
  562. package/dist/schema.d.ts +499 -0
  563. package/dist/schema.d.ts.map +1 -0
  564. package/dist/schema.js +134 -0
  565. package/dist/schema.js.map +1 -0
  566. package/dist/theme-palette.d.ts +17 -0
  567. package/dist/theme-palette.d.ts.map +1 -0
  568. package/dist/theme-palette.js +21 -0
  569. package/dist/theme-palette.js.map +1 -0
  570. package/dist/thinking-catalog.d.ts +4 -0
  571. package/dist/thinking-catalog.d.ts.map +1 -0
  572. package/dist/thinking-catalog.js +13 -0
  573. package/dist/thinking-catalog.js.map +1 -0
  574. package/dist/thinking.d.ts +37 -0
  575. package/dist/thinking.d.ts.map +1 -0
  576. package/dist/thinking.js +137 -0
  577. package/dist/thinking.js.map +1 -0
  578. package/dist/tool-names.d.ts +77 -0
  579. package/dist/tool-names.d.ts.map +1 -0
  580. package/dist/tool-names.js +56 -0
  581. package/dist/tool-names.js.map +1 -0
  582. package/dist/tools/index.d.ts +6 -0
  583. package/dist/tools/index.d.ts.map +1 -0
  584. package/dist/tools/index.js +3 -0
  585. package/dist/tools/request-sandbox-access.d.ts +6 -0
  586. package/dist/tools/request-sandbox-access.d.ts.map +1 -0
  587. package/dist/tools/request-sandbox-access.js +80 -0
  588. package/dist/tools/request-sandbox-access.js.map +1 -0
  589. package/dist/tools/utils.d.ts +20 -0
  590. package/dist/tools/utils.d.ts.map +1 -0
  591. package/dist/tools/utils.js +32 -0
  592. package/dist/tools/utils.js.map +1 -0
  593. package/dist/tools/web-search.d.ts +114 -0
  594. package/dist/tools/web-search.d.ts.map +1 -0
  595. package/dist/tools/web-search.js +155 -0
  596. package/dist/tools/web-search.js.map +1 -0
  597. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  598. package/dist/tools/workflows/create-workflow.d.ts.map +1 -0
  599. package/dist/tools/workflows/create-workflow.js +81 -0
  600. package/dist/tools/workflows/create-workflow.js.map +1 -0
  601. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  602. package/dist/tools/workflows/delete-workflow.d.ts.map +1 -0
  603. package/dist/tools/workflows/delete-workflow.js +21 -0
  604. package/dist/tools/workflows/delete-workflow.js.map +1 -0
  605. package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
  606. package/dist/tools/workflows/ephemeral-memory.d.ts.map +1 -0
  607. package/dist/tools/workflows/ephemeral-memory.js +44 -0
  608. package/dist/tools/workflows/ephemeral-memory.js.map +1 -0
  609. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  610. package/dist/tools/workflows/extract-json-schema.d.ts.map +1 -0
  611. package/dist/tools/workflows/extract-json-schema.js +22 -0
  612. package/dist/tools/workflows/extract-json-schema.js.map +1 -0
  613. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  614. package/dist/tools/workflows/get-workflow.d.ts.map +1 -0
  615. package/dist/tools/workflows/get-workflow.js +34 -0
  616. package/dist/tools/workflows/get-workflow.js.map +1 -0
  617. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  618. package/dist/tools/workflows/list-available-agents.d.ts.map +1 -0
  619. package/dist/tools/workflows/list-available-agents.js +32 -0
  620. package/dist/tools/workflows/list-available-agents.js.map +1 -0
  621. package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
  622. package/dist/tools/workflows/list-available-classifiers.d.ts.map +1 -0
  623. package/dist/tools/workflows/list-available-classifiers.js +56 -0
  624. package/dist/tools/workflows/list-available-classifiers.js.map +1 -0
  625. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  626. package/dist/tools/workflows/list-available-tools.d.ts.map +1 -0
  627. package/dist/tools/workflows/list-available-tools.js +40 -0
  628. package/dist/tools/workflows/list-available-tools.js.map +1 -0
  629. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  630. package/dist/tools/workflows/list-available-workflows.d.ts.map +1 -0
  631. package/dist/tools/workflows/list-available-workflows.js +32 -0
  632. package/dist/tools/workflows/list-available-workflows.js.map +1 -0
  633. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  634. package/dist/tools/workflows/list-workflows.d.ts.map +1 -0
  635. package/dist/tools/workflows/list-workflows.js +33 -0
  636. package/dist/tools/workflows/list-workflows.js.map +1 -0
  637. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  638. package/dist/tools/workflows/run-workflow.d.ts.map +1 -0
  639. package/dist/tools/workflows/run-workflow.js +52 -0
  640. package/dist/tools/workflows/run-workflow.js.map +1 -0
  641. package/dist/tools/workflows/save-workflow.d.ts +1125 -0
  642. package/dist/tools/workflows/save-workflow.d.ts.map +1 -0
  643. package/dist/tools/workflows/save-workflow.js +28 -0
  644. package/dist/tools/workflows/save-workflow.js.map +1 -0
  645. package/dist/tools/workflows/tool-ids.d.ts +16 -0
  646. package/dist/tools/workflows/tool-ids.d.ts.map +1 -0
  647. package/dist/tools/workflows/tool-ids.js +20 -0
  648. package/dist/tools/workflows/tool-ids.js.map +1 -0
  649. package/dist/utils/binaries.d.ts +7 -0
  650. package/dist/utils/binaries.d.ts.map +1 -0
  651. package/dist/utils/binaries.js +78 -0
  652. package/dist/utils/binaries.js.map +1 -0
  653. package/dist/utils/debug-log.d.ts +12 -0
  654. package/dist/utils/debug-log.d.ts.map +1 -0
  655. package/dist/utils/debug-log.js +59 -0
  656. package/dist/utils/debug-log.js.map +1 -0
  657. package/dist/utils/discarding-scores-storage.d.ts +33 -0
  658. package/dist/utils/discarding-scores-storage.d.ts.map +1 -0
  659. package/dist/utils/discarding-scores-storage.js +54 -0
  660. package/dist/utils/discarding-scores-storage.js.map +1 -0
  661. package/dist/utils/errors.d.ts +36 -0
  662. package/dist/utils/errors.d.ts.map +1 -0
  663. package/dist/utils/errors.js +196 -0
  664. package/dist/utils/errors.js.map +1 -0
  665. package/dist/utils/gateway-sync.d.ts +26 -0
  666. package/dist/utils/gateway-sync.d.ts.map +1 -0
  667. package/dist/utils/gateway-sync.js +61 -0
  668. package/dist/utils/gateway-sync.js.map +1 -0
  669. package/dist/utils/maintenance-lock.d.ts +42 -0
  670. package/dist/utils/maintenance-lock.d.ts.map +1 -0
  671. package/dist/utils/maintenance-lock.js +199 -0
  672. package/dist/utils/maintenance-lock.js.map +1 -0
  673. package/dist/utils/notification-dispatch.d.ts +59 -0
  674. package/dist/utils/notification-dispatch.d.ts.map +1 -0
  675. package/dist/utils/notification-dispatch.js +109 -0
  676. package/dist/utils/notification-dispatch.js.map +1 -0
  677. package/dist/utils/open-url.d.ts +10 -0
  678. package/dist/utils/open-url.d.ts.map +1 -0
  679. package/dist/utils/open-url.js +30 -0
  680. package/dist/utils/open-url.js.map +1 -0
  681. package/dist/utils/path-security.d.ts +2 -0
  682. package/dist/utils/path-security.d.ts.map +1 -0
  683. package/dist/utils/path-security.js +10 -0
  684. package/dist/utils/path-security.js.map +1 -0
  685. package/dist/utils/plan-diff.d.ts +25 -0
  686. package/dist/utils/plan-diff.d.ts.map +1 -0
  687. package/dist/utils/plan-diff.js +62 -0
  688. package/dist/utils/plan-diff.js.map +1 -0
  689. package/dist/utils/plans.d.ts +59 -0
  690. package/dist/utils/plans.d.ts.map +1 -0
  691. package/dist/utils/plans.js +117 -0
  692. package/dist/utils/plans.js.map +1 -0
  693. package/dist/utils/project.d.ts +160 -0
  694. package/dist/utils/project.d.ts.map +1 -0
  695. package/dist/utils/project.js +364 -0
  696. package/dist/utils/project.js.map +1 -0
  697. package/dist/utils/prune-cli.d.ts +24 -0
  698. package/dist/utils/prune-cli.d.ts.map +1 -0
  699. package/dist/utils/prune-cli.js +125 -0
  700. package/dist/utils/prune-cli.js.map +1 -0
  701. package/dist/utils/signals-pubsub.d.ts +101 -0
  702. package/dist/utils/signals-pubsub.d.ts.map +1 -0
  703. package/dist/utils/signals-pubsub.js +410 -0
  704. package/dist/utils/signals-pubsub.js.map +1 -0
  705. package/dist/utils/slash-command-loader.d.ts +52 -0
  706. package/dist/utils/slash-command-loader.d.ts.map +1 -0
  707. package/dist/utils/slash-command-loader.js +142 -0
  708. package/dist/utils/slash-command-loader.js.map +1 -0
  709. package/dist/utils/slash-command-processor.d.ts +14 -0
  710. package/dist/utils/slash-command-processor.d.ts.map +1 -0
  711. package/dist/utils/slash-command-processor.js +109 -0
  712. package/dist/utils/slash-command-processor.js.map +1 -0
  713. package/dist/utils/stdin-pipe.d.ts +33 -0
  714. package/dist/utils/stdin-pipe.d.ts.map +1 -0
  715. package/dist/utils/stdin-pipe.js +96 -0
  716. package/dist/utils/stdin-pipe.js.map +1 -0
  717. package/dist/utils/storage-factory.d.ts +50 -0
  718. package/dist/utils/storage-factory.d.ts.map +1 -0
  719. package/dist/utils/storage-factory.js +121 -0
  720. package/dist/utils/storage-factory.js.map +1 -0
  721. package/dist/utils/storage-maintenance.d.ts +121 -0
  722. package/dist/utils/storage-maintenance.d.ts.map +1 -0
  723. package/dist/utils/storage-maintenance.js +355 -0
  724. package/dist/utils/storage-maintenance.js.map +1 -0
  725. package/dist/utils/thread-lock.d.ts +26 -0
  726. package/dist/utils/thread-lock.d.ts.map +1 -0
  727. package/dist/utils/thread-lock.js +112 -0
  728. package/dist/utils/thread-lock.js.map +1 -0
  729. package/dist/utils/token-estimator.d.ts +3 -0
  730. package/dist/utils/token-estimator.d.ts.map +1 -0
  731. package/dist/utils/token-estimator.js +21 -0
  732. package/dist/utils/token-estimator.js.map +1 -0
  733. package/dist/utils/update-check.d.ts +151 -0
  734. package/dist/utils/update-check.d.ts.map +1 -0
  735. package/dist/utils/update-check.js +432 -0
  736. package/dist/utils/update-check.js.map +1 -0
  737. package/dist/voice/stt-registry.d.ts +64 -0
  738. package/dist/voice/stt-registry.d.ts.map +1 -0
  739. package/dist/voice/stt-registry.js +144 -0
  740. package/dist/voice/stt-registry.js.map +1 -0
  741. package/dist/workflows/register-primitives.d.ts +52 -0
  742. package/dist/workflows/register-primitives.d.ts.map +1 -0
  743. package/dist/workflows/register-primitives.js +40 -0
  744. package/dist/workflows/register-primitives.js.map +1 -0
  745. package/dist/workflows/service.d.ts +64 -0
  746. package/dist/workflows/service.d.ts.map +1 -0
  747. package/dist/workflows/service.js +53 -0
  748. package/dist/workflows/service.js.map +1 -0
  749. package/package.json +107 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["/**\n * Error handling utilities for the Mastra Code TUI.\n * Parses API errors and provides user-friendly messages.\n */\n\nimport { PROVIDER_AUTH_REQUIRED_ERROR } from '../auth/provider-auth-error.js';\n\nexport interface ParsedError {\n /** User-friendly error message */\n message: string;\n /** Extra diagnostic detail to surface to the user */\n detail?: string;\n /** Request URL involved in the failure, when available */\n requestUrl?: string;\n /** Error type for categorization */\n type: ErrorType;\n /** Whether this error is retryable */\n retryable: boolean;\n /** Suggested retry delay in ms (if retryable) */\n retryDelay?: number;\n /** Original error for debugging */\n originalError: Error;\n}\n\nexport type ErrorType =\n | 'rate_limit'\n | 'auth'\n | 'network'\n | 'timeout'\n | 'invalid_request'\n | 'server_error'\n | 'model_not_found'\n | 'context_length'\n | 'content_filter'\n | 'unknown';\n\n/**\n * Parse an error and return a user-friendly representation.\n */\nfunction summarizeErrorDetail(error: unknown): string | undefined {\n if (error instanceof Error) {\n if (error.cause instanceof Error && error.cause.message) {\n return error.cause.message;\n }\n\n if (typeof error.cause === 'string' && error.cause.trim().length > 0) {\n return error.cause;\n }\n\n if (error.message.trim().length > 0) {\n return error.message;\n }\n }\n\n if (typeof error === 'string' && error.trim().length > 0) {\n return error;\n }\n\n if (error && typeof error === 'object') {\n const errorObj = error as Record<string, unknown>;\n const candidates = [errorObj['message'], errorObj['cause'], errorObj['code'], errorObj['statusText']];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n }\n\n return undefined;\n}\n\nfunction extractRequestUrl(error: unknown): string | undefined {\n if (!error || typeof error !== 'object') {\n return undefined;\n }\n\n const candidates: unknown[] = [];\n const errorObj = error as Record<string, unknown>;\n candidates.push(errorObj['requestUrl'], errorObj['url']);\n\n if (errorObj['cause'] && typeof errorObj['cause'] === 'object') {\n const causeObj = errorObj['cause'] as Record<string, unknown>;\n candidates.push(causeObj['requestUrl'], causeObj['url']);\n }\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n }\n\n return undefined;\n}\n\n/** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */\nfunction isSerializedError(value: unknown): value is { name: string; message: string } {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'name' in value &&\n typeof value.name === 'string' &&\n 'message' in value &&\n typeof value.message === 'string'\n );\n}\n\nfunction toError(error: unknown): Error {\n if (error instanceof Error) return error;\n if (!isSerializedError(error)) return new Error(String(error));\n const rebuilt = new Error(error.message);\n rebuilt.name = error.name;\n return rebuilt;\n}\n\nexport function parseError(error: unknown): ParsedError {\n const err = toError(error);\n const message = err.message.toLowerCase();\n const errorObj = error as Record<string, unknown>;\n const detail = summarizeErrorDetail(error);\n const requestUrl = extractRequestUrl(error);\n\n // Matched by name, not instance: the error may have crossed a serialization boundary.\n if (err.name === PROVIDER_AUTH_REQUIRED_ERROR) {\n return { message: err.message, detail, requestUrl, type: 'auth', retryable: false, originalError: err };\n }\n\n // Check for rate limiting\n if (\n message.includes('rate limit') ||\n message.includes('rate_limit') ||\n message.includes('429') ||\n errorObj.statusCode === 429 ||\n errorObj.status === 429\n ) {\n const retryAfter = extractRetryAfter(errorObj);\n return {\n message: 'Rate limited. Please wait a moment before trying again.',\n type: 'rate_limit',\n retryable: true,\n retryDelay: retryAfter || 5000,\n originalError: err,\n };\n }\n\n // Check for authentication errors\n if (\n message.includes('unauthorized') ||\n message.includes('authentication') ||\n message.includes('invalid api key') ||\n message.includes('invalid_api_key') ||\n message.includes('api key') ||\n errorObj.statusCode === 401 ||\n errorObj.status === 401\n ) {\n return {\n message: 'Authentication failed. Check the credential configured for this provider.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for forbidden/permission errors\n if (errorObj.statusCode === 403 || errorObj.status === 403) {\n return {\n message: 'Access denied. You may not have permission to use this model.',\n detail,\n requestUrl,\n type: 'auth',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for network errors\n if (\n message.includes('network') ||\n message.includes('econnrefused') ||\n message.includes('enotfound') ||\n message.includes('fetch failed') ||\n message.includes('connection')\n ) {\n return {\n message: 'Network error while contacting the provider or gateway.',\n detail,\n requestUrl,\n type: 'network',\n retryable: true,\n retryDelay: 2000,\n originalError: err,\n };\n }\n\n // Check for timeout errors\n if (message.includes('timeout') || message.includes('timed out') || message.includes('etimedout')) {\n return {\n message: 'Request timed out. The server may be overloaded.',\n type: 'timeout',\n retryable: true,\n retryDelay: 3000,\n originalError: err,\n };\n }\n\n // Check for model not found\n if (\n message.includes('model not found') ||\n message.includes('model_not_found') ||\n message.includes('does not exist') ||\n message.includes('invalid model')\n ) {\n return {\n message: 'Model not found. Please select a different model with /models.',\n type: 'model_not_found',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for context length errors\n if (\n message.includes('context length') ||\n message.includes('context_length') ||\n message.includes('too many tokens') ||\n message.includes('maximum context') ||\n message.includes('token limit')\n ) {\n return {\n message: 'Message too long. Try starting a new thread with /new.',\n type: 'context_length',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for content filter errors\n if (\n message.includes('content filter') ||\n message.includes('content_filter') ||\n message.includes('content policy') ||\n message.includes('safety') ||\n message.includes('prohibited')\n ) {\n return {\n message: \"Content was filtered by the model's safety system.\",\n type: 'content_filter',\n retryable: false,\n originalError: err,\n };\n }\n\n // Check for server errors\n if (\n message.includes('internal server') ||\n message.includes('server error') ||\n errorObj.statusCode === 500 ||\n errorObj.status === 500 ||\n errorObj.statusCode === 502 ||\n errorObj.status === 502 ||\n errorObj.statusCode === 503 ||\n errorObj.status === 503\n ) {\n return {\n message: 'Server error. The API may be experiencing issues.',\n type: 'server_error',\n retryable: true,\n retryDelay: 5000,\n originalError: err,\n };\n }\n\n // Check for invalid request errors\n if (\n message.includes('invalid request') ||\n message.includes('bad request') ||\n errorObj.statusCode === 400 ||\n errorObj.status === 400\n ) {\n return {\n message: `Invalid request: ${extractErrorDetail(err)}`,\n type: 'invalid_request',\n retryable: false,\n originalError: err,\n };\n }\n\n // Unknown error - try to extract useful info\n return {\n message: extractErrorDetail(err),\n type: 'unknown',\n retryable: false,\n originalError: err,\n };\n}\n\n/**\n * Extract retry-after header value from error.\n */\nfunction extractRetryAfter(error: Record<string, unknown>): number | undefined {\n const headers = error.headers as Record<string, unknown> | undefined;\n const retryAfter = error.retryAfter || headers?.['retry-after'];\n if (typeof retryAfter === 'number') {\n return retryAfter * 1000; // Convert seconds to ms\n }\n if (typeof retryAfter === 'string') {\n const seconds = parseInt(retryAfter, 10);\n if (!isNaN(seconds)) {\n return seconds * 1000;\n }\n }\n return undefined;\n}\n\n/**\n * Extract a useful error detail from an error object.\n */\nfunction extractErrorDetail(error: Error): string {\n const errorObj = error as unknown as Record<string, unknown>;\n\n // Try to get a specific error message from common API error formats\n if (errorObj.error && typeof errorObj.error === 'object') {\n const apiError = errorObj.error as Record<string, unknown>;\n if (apiError.message) return String(apiError.message);\n }\n\n if (errorObj.message) return String(errorObj.message);\n if (errorObj.detail) return String(errorObj.detail);\n if (errorObj.reason) return String(errorObj.reason);\n\n // Clean up the error message\n let message = error.message;\n\n // Remove common prefixes\n message = message.replace(/^(error|exception|failed):\\s*/i, '');\n\n // Truncate very long messages\n if (message.length > 200) {\n message = message.substring(0, 200) + '...';\n }\n\n return message || 'An unknown error occurred';\n}\n\n/**\n * Sleep for a given number of milliseconds.\n */\nexport function sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Retry a function with exponential backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n options: {\n maxRetries?: number;\n initialDelay?: number;\n maxDelay?: number;\n onRetry?: (error: ParsedError, attempt: number) => void;\n } = {},\n): Promise<T> {\n const { maxRetries = 3, initialDelay = 1000, maxDelay = 30000, onRetry } = options;\n\n let lastError: ParsedError | undefined;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (error) {\n lastError = parseError(error);\n\n // Don't retry non-retryable errors\n if (!lastError.retryable || attempt === maxRetries) {\n throw lastError.originalError;\n }\n\n // Calculate delay with exponential backoff\n const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);\n\n if (onRetry) {\n onRetry(lastError, attempt + 1);\n }\n\n await sleep(delay);\n }\n }\n\n // Should never reach here, but TypeScript needs this\n throw lastError?.originalError || new Error('Retry failed');\n}\n"],"mappings":";;;;;;;;;AAuCA,SAAS,qBAAqB,OAAoC;CAChE,IAAI,iBAAiB,OAAO;EAC1B,IAAI,MAAM,iBAAiB,SAAS,MAAM,MAAM,SAC9C,OAAO,MAAM,MAAM;EAGrB,IAAI,OAAO,MAAM,UAAU,YAAY,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,GACjE,OAAO,MAAM;EAGf,IAAI,MAAM,QAAQ,KAAK,CAAC,CAAC,SAAS,GAChC,OAAO,MAAM;CAEjB;CAEA,IAAI,OAAO,UAAU,YAAY,MAAM,KAAK,CAAC,CAAC,SAAS,GACrD,OAAO;CAGT,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,WAAW;EACjB,MAAM,aAAa;GAAC,SAAS;GAAY,SAAS;GAA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,OAAO;CACpD,IAAI,SAAS,QAAQ,OAAO,OAAO,SAAS,MAAM;CAClD,IAAI,SAAS,QAAQ,OAAO,OAAO,SAAS,MAAM;CAGlD,IAAI,UAAU,MAAM;CAGpB,UAAU,QAAQ,QAAQ,kCAAkC,EAAE;CAG9D,IAAI,QAAQ,SAAS,KACnB,UAAU,QAAQ,UAAU,GAAG,GAAG,IAAI;CAGxC,OAAO,WAAW;AACpB;;;;AAKA,SAAgB,MAAM,IAA2B;CAC/C,OAAO,IAAI,SAAQ,YAAW,WAAW,SAAS,EAAE,CAAC;AACvD;;;;AAKA,eAAsB,UACpB,IACA,UAKI,CAAC,GACO;CACZ,MAAM,EAAE,aAAa,GAAG,eAAe,KAAM,WAAW,KAAO,YAAY;CAE3E,IAAI;CAEJ,KAAK,IAAI,UAAU,GAAG,WAAW,YAAY,WAC3C,IAAI;EACF,OAAO,MAAM,GAAG;CAClB,SAAS,OAAO;EACd,YAAY,WAAW,KAAK;EAG5B,IAAI,CAAC,UAAU,aAAa,YAAY,YACtC,MAAM,UAAU;EAIlB,MAAM,QAAQ,KAAK,IAAI,UAAU,cAAc,eAAe,KAAK,IAAI,GAAG,OAAO,GAAG,QAAQ;EAE5F,IAAI,SACF,QAAQ,WAAW,UAAU,CAAC;EAGhC,MAAM,MAAM,KAAK;CACnB;CAIF,MAAM,WAAW,iCAAiB,IAAI,MAAM,cAAc;AAC5D"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Gateway sync utility for keeping the model registry up to date.
3
+ *
4
+ * This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
5
+ * mastracode and `mastra dev` share a single implementation for fetching
6
+ * providers, generating types, and writing to the global cache. Keep this
7
+ * file small — provider/registry logic belongs in `@mastra/core`.
8
+ */
9
+ /**
10
+ * Sync gateways and update the global cache via `@mastra/core`'s registry.
11
+ *
12
+ * Skips the sync if the global cache was refreshed within the last
13
+ * `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
14
+ * the same process coalesce while a sync is in flight.
15
+ */
16
+ export declare function syncGateways(force?: boolean): Promise<void>;
17
+ /**
18
+ * Start periodic gateway sync.
19
+ * @param intervalMs Sync interval in milliseconds (default: 5 minutes)
20
+ */
21
+ export declare function startGatewaySync(intervalMs?: number): void;
22
+ /**
23
+ * Stop periodic gateway sync.
24
+ */
25
+ export declare function stopGatewaySync(): void;
26
+ //# sourceMappingURL=gateway-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway-sync.d.ts","sourceRoot":"","sources":["../../src/utils/gateway-sync.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAC,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB/D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,SAA2B,GAAG,IAAI,CAe5E;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAKtC"}
@@ -0,0 +1,61 @@
1
+ import { GatewayRegistry } from "@mastra/core/llm";
2
+ //#region src/utils/gateway-sync.ts
3
+ /**
4
+ * Gateway sync utility for keeping the model registry up to date.
5
+ *
6
+ * This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
7
+ * mastracode and `mastra dev` share a single implementation for fetching
8
+ * providers, generating types, and writing to the global cache. Keep this
9
+ * file small — provider/registry logic belongs in `@mastra/core`.
10
+ */
11
+ const DEFAULT_SYNC_INTERVAL_MS = 300 * 1e3;
12
+ let syncInterval = null;
13
+ let isSyncing = false;
14
+ function getRegistry() {
15
+ return GatewayRegistry.getInstance({ useDynamicLoading: true });
16
+ }
17
+ /**
18
+ * Sync gateways and update the global cache via `@mastra/core`'s registry.
19
+ *
20
+ * Skips the sync if the global cache was refreshed within the last
21
+ * `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
22
+ * the same process coalesce while a sync is in flight.
23
+ */
24
+ async function syncGateways(force = false) {
25
+ if (isSyncing && !force) return;
26
+ if (!force) {
27
+ const lastSync = getRegistry().getLastRefreshTime();
28
+ if (lastSync && Date.now() - lastSync.getTime() < DEFAULT_SYNC_INTERVAL_MS) return;
29
+ }
30
+ isSyncing = true;
31
+ try {
32
+ await getRegistry().syncGateways(true);
33
+ } catch {} finally {
34
+ isSyncing = false;
35
+ }
36
+ }
37
+ /**
38
+ * Start periodic gateway sync.
39
+ * @param intervalMs Sync interval in milliseconds (default: 5 minutes)
40
+ */
41
+ function startGatewaySync(intervalMs = DEFAULT_SYNC_INTERVAL_MS) {
42
+ if (syncInterval) return;
43
+ syncGateways().catch(() => {});
44
+ syncInterval = setInterval(() => {
45
+ syncGateways().catch(() => {});
46
+ }, intervalMs);
47
+ syncInterval.unref();
48
+ }
49
+ /**
50
+ * Stop periodic gateway sync.
51
+ */
52
+ function stopGatewaySync() {
53
+ if (syncInterval) {
54
+ clearInterval(syncInterval);
55
+ syncInterval = null;
56
+ }
57
+ }
58
+ //#endregion
59
+ export { startGatewaySync, stopGatewaySync, syncGateways };
60
+
61
+ //# sourceMappingURL=gateway-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway-sync.js","names":[],"sources":["../../src/utils/gateway-sync.ts"],"sourcesContent":["/**\n * Gateway sync utility for keeping the model registry up to date.\n *\n * This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so\n * mastracode and `mastra dev` share a single implementation for fetching\n * providers, generating types, and writing to the global cache. Keep this\n * file small — provider/registry logic belongs in `@mastra/core`.\n */\n\nimport { GatewayRegistry } from '@mastra/core/llm';\n\nconst DEFAULT_SYNC_INTERVAL_MS = 5 * 60 * 1000;\n\nlet syncInterval: NodeJS.Timeout | null = null;\nlet isSyncing = false;\n\nfunction getRegistry(): GatewayRegistry {\n return GatewayRegistry.getInstance({ useDynamicLoading: true });\n}\n\n/**\n * Sync gateways and update the global cache via `@mastra/core`'s registry.\n *\n * Skips the sync if the global cache was refreshed within the last\n * `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in\n * the same process coalesce while a sync is in flight.\n */\nexport async function syncGateways(force = false): Promise<void> {\n if (isSyncing && !force) {\n return;\n }\n\n if (!force) {\n const lastSync = getRegistry().getLastRefreshTime();\n if (lastSync && Date.now() - lastSync.getTime() < DEFAULT_SYNC_INTERVAL_MS) {\n return;\n }\n }\n\n isSyncing = true;\n try {\n await getRegistry().syncGateways(true);\n } catch {\n // Silently ignore — the bundled registry already contains all model\n // data so a failed network fetch is non-critical.\n } finally {\n isSyncing = false;\n }\n}\n\n/**\n * Start periodic gateway sync.\n * @param intervalMs Sync interval in milliseconds (default: 5 minutes)\n */\nexport function startGatewaySync(intervalMs = DEFAULT_SYNC_INTERVAL_MS): void {\n if (syncInterval) {\n return;\n }\n\n // Do an initial sync (will skip if recently synced)\n syncGateways().catch(() => {});\n\n // Set up periodic sync\n syncInterval = setInterval(() => {\n syncGateways().catch(() => {});\n }, intervalMs);\n\n // Don't prevent process exit\n syncInterval.unref();\n}\n\n/**\n * Stop periodic gateway sync.\n */\nexport function stopGatewaySync(): void {\n if (syncInterval) {\n clearInterval(syncInterval);\n syncInterval = null;\n }\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,2BAA2B,MAAS;AAE1C,IAAI,eAAsC;AAC1C,IAAI,YAAY;AAEhB,SAAS,cAA+B;CACtC,OAAO,gBAAgB,YAAY,EAAE,mBAAmB,KAAK,CAAC;AAChE;;;;;;;;AASA,eAAsB,aAAa,QAAQ,OAAsB;CAC/D,IAAI,aAAa,CAAC,OAChB;CAGF,IAAI,CAAC,OAAO;EACV,MAAM,WAAW,YAAY,CAAC,CAAC,mBAAmB;EAClD,IAAI,YAAY,KAAK,IAAI,IAAI,SAAS,QAAQ,IAAI,0BAChD;CAEJ;CAEA,YAAY;CACZ,IAAI;EACF,MAAM,YAAY,CAAC,CAAC,aAAa,IAAI;CACvC,QAAQ,CAGR,UAAU;EACR,YAAY;CACd;AACF;;;;;AAMA,SAAgB,iBAAiB,aAAa,0BAAgC;CAC5E,IAAI,cACF;CAIF,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC;CAG7B,eAAe,kBAAkB;EAC/B,aAAa,CAAC,CAAC,YAAY,CAAC,CAAC;CAC/B,GAAG,UAAU;CAGb,aAAa,MAAM;AACrB;;;;AAKA,SAAgB,kBAAwB;CACtC,IAAI,cAAc;EAChB,cAAc,YAAY;EAC1B,eAAe;CACjB;AACF"}
@@ -0,0 +1,42 @@
1
+ export declare class MaintenanceLockError extends Error {
2
+ readonly ownerPids: number[];
3
+ constructor(message: string, ownerPids: number[]);
4
+ }
5
+ export declare function getMaintenanceLockPath(): string;
6
+ /** Owner of a lock whose pid file is still being written (PID not known yet). */
7
+ export declare const UNKNOWN_OWNER = -1;
8
+ /**
9
+ * Creating a pid file (open, then write) is not atomic, so an empty or
10
+ * unparseable file may belong to a process that is mid-write. Only treat it as
11
+ * stale once it is older than this.
12
+ */
13
+ export declare const MALFORMED_PID_FILE_GRACE_MS = 5000;
14
+ /**
15
+ * PID holding the maintenance lock, `UNKNOWN_OWNER` while its pid file is still
16
+ * being written, or null. Stale locks are removed.
17
+ */
18
+ export declare function getMaintenanceLockOwner(): number | null;
19
+ /** PIDs of other live registered sessions. Stale registrations are removed. */
20
+ export declare function getLiveSessionPids(): number[];
21
+ /** Test-only: drop every registration held by this process and forget lock ownership. */
22
+ export declare function resetSessionRegistrationsForTesting(): void;
23
+ /** Register one running session in this process. Pair with exactly one unregisterSession(). */
24
+ export declare function registerSession(): void;
25
+ /** Release one registration made by registerSession(). */
26
+ export declare function unregisterSession(): void;
27
+ /**
28
+ * Register this session, then wait for any running maintenance to finish.
29
+ * Waits indefinitely by default: a vacuum on a multi-GB database can take
30
+ * minutes. With `timeoutMs`, throws after that long naming the holder.
31
+ */
32
+ export declare function registerSessionAndWaitForMaintenance({ timeoutMs, pollMs, onWait, }?: {
33
+ timeoutMs?: number;
34
+ pollMs?: number;
35
+ onWait?: (ownerPid: number) => void;
36
+ }): Promise<void>;
37
+ /**
38
+ * Acquire the maintenance lock, then refuse if any mastracode session is live.
39
+ * Returns a release function.
40
+ */
41
+ export declare function acquireMaintenanceLock(): () => void;
42
+ //# sourceMappingURL=maintenance-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintenance-lock.d.ts","sourceRoot":"","sources":["../../src/utils/maintenance-lock.ts"],"names":[],"mappings":"AAiBA,qBAAa,oBAAqB,SAAQ,KAAK;aAG3B,SAAS,EAAE,MAAM,EAAE;gBADnC,OAAO,EAAE,MAAM,EACC,SAAS,EAAE,MAAM,EAAE;CAKtC;AAcD,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED,iFAAiF;AACjF,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,OAAQ,CAAC;AAuCjD;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,IAAI,CAgBvD;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAmB7C;AAOD,yFAAyF;AACzF,wBAAgB,mCAAmC,IAAI,IAAI,CAG1D;AAYD,+FAA+F;AAC/F,wBAAgB,eAAe,IAAI,IAAI,CAStC;AAED,0DAA0D;AAC1D,wBAAgB,iBAAiB,IAAI,IAAI,CAIxC;AAED;;;;GAIG;AACH,wBAAsB,oCAAoC,CAAC,EACzD,SAAoB,EACpB,MAAY,EACZ,MAAM,GACP,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBnG;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,IAAI,CA0CnD"}
@@ -0,0 +1,199 @@
1
+ import { getAppDataDir } from "./project.js";
2
+ import path from "path";
3
+ import fs from "fs";
4
+ //#region src/utils/maintenance-lock.ts
5
+ /**
6
+ * Mutual exclusion between storage maintenance (`mastracode prune`) and running
7
+ * mastracode sessions, using the same pid-file / stale-PID pattern as
8
+ * thread-lock.ts.
9
+ *
10
+ * - Every process that opens storage registers a session pid file.
11
+ * - `prune` holds `maintenance.lock` for its whole run.
12
+ *
13
+ * The checks are ordered so the race is closed both ways: `prune` acquires the
14
+ * lock and THEN looks for live sessions; a starter registers and THEN looks for
15
+ * the lock. Whichever acts second always sees the other.
16
+ */
17
+ var MaintenanceLockError = class extends Error {
18
+ ownerPids;
19
+ constructor(message, ownerPids) {
20
+ super(message);
21
+ this.ownerPids = ownerPids;
22
+ this.name = "MaintenanceLockError";
23
+ }
24
+ };
25
+ function getLocksDir() {
26
+ const dir = path.join(getAppDataDir(), "locks");
27
+ fs.mkdirSync(dir, { recursive: true });
28
+ return dir;
29
+ }
30
+ function getSessionsDir() {
31
+ const dir = path.join(getLocksDir(), "sessions");
32
+ fs.mkdirSync(dir, { recursive: true });
33
+ return dir;
34
+ }
35
+ function getMaintenanceLockPath() {
36
+ return path.join(getLocksDir(), "maintenance.lock");
37
+ }
38
+ /** Owner of a lock whose pid file is still being written (PID not known yet). */
39
+ const UNKNOWN_OWNER = -1;
40
+ /**
41
+ * Creating a pid file (open, then write) is not atomic, so an empty or
42
+ * unparseable file may belong to a process that is mid-write. Only treat it as
43
+ * stale once it is older than this.
44
+ */
45
+ const MALFORMED_PID_FILE_GRACE_MS = 5e3;
46
+ function isProcessAlive(pid) {
47
+ try {
48
+ process.kill(pid, 0);
49
+ return true;
50
+ } catch (error) {
51
+ return error.code !== "ESRCH";
52
+ }
53
+ }
54
+ /** Whether a pid file with no readable PID is old enough to reap. Missing files count as reapable. */
55
+ function isMalformedPidFileStale(file) {
56
+ try {
57
+ return Date.now() - fs.statSync(file).mtimeMs > MALFORMED_PID_FILE_GRACE_MS;
58
+ } catch {
59
+ return true;
60
+ }
61
+ }
62
+ function describeOwners(pids) {
63
+ const known = pids.filter((pid) => pid !== -1);
64
+ return known.length > 0 ? ` (PID ${known.join(", ")})` : "";
65
+ }
66
+ function readPid(file) {
67
+ try {
68
+ const pid = parseInt(fs.readFileSync(file, "utf-8").trim(), 10);
69
+ return isNaN(pid) ? null : pid;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+ let lockHeld = false;
75
+ /**
76
+ * PID holding the maintenance lock, `UNKNOWN_OWNER` while its pid file is still
77
+ * being written, or null. Stale locks are removed.
78
+ */
79
+ function getMaintenanceLockOwner() {
80
+ const lockPath = getMaintenanceLockPath();
81
+ if (!fs.existsSync(lockPath)) return null;
82
+ const pid = readPid(lockPath);
83
+ if (pid === process.pid) {
84
+ if (lockHeld) return pid;
85
+ } else if (pid !== null && isProcessAlive(pid)) return pid;
86
+ if (pid === null && !isMalformedPidFileStale(lockPath)) return -1;
87
+ try {
88
+ fs.unlinkSync(lockPath);
89
+ } catch {}
90
+ return null;
91
+ }
92
+ /** PIDs of other live registered sessions. Stale registrations are removed. */
93
+ function getLiveSessionPids() {
94
+ const dir = getSessionsDir();
95
+ const live = [];
96
+ for (const file of fs.readdirSync(dir)) {
97
+ if (!file.endsWith(".pid")) continue;
98
+ const filePath = path.join(dir, file);
99
+ const pid = readPid(filePath);
100
+ if (pid === process.pid) continue;
101
+ if (pid !== null && isProcessAlive(pid)) live.push(pid);
102
+ else if (pid === null && !isMalformedPidFileStale(filePath)) live.push(-1);
103
+ else try {
104
+ fs.unlinkSync(filePath);
105
+ } catch {}
106
+ }
107
+ return live;
108
+ }
109
+ let sessionRefs = 0;
110
+ let exitHookInstalled = false;
111
+ /** Test-only: drop every registration held by this process and forget lock ownership. */
112
+ function resetSessionRegistrationsForTesting() {
113
+ while (sessionRefs > 0) unregisterSession();
114
+ lockHeld = false;
115
+ }
116
+ function getSessionPidPath() {
117
+ return path.join(getSessionsDir(), `${process.pid}.pid`);
118
+ }
119
+ function removeSessionPidFile() {
120
+ try {
121
+ fs.unlinkSync(getSessionPidPath());
122
+ } catch {}
123
+ }
124
+ /** Register one running session in this process. Pair with exactly one unregisterSession(). */
125
+ function registerSession() {
126
+ if (sessionRefs === 0) fs.writeFileSync(getSessionPidPath(), String(process.pid), { mode: 420 });
127
+ sessionRefs++;
128
+ if (!exitHookInstalled) {
129
+ exitHookInstalled = true;
130
+ process.once("exit", removeSessionPidFile);
131
+ }
132
+ }
133
+ /** Release one registration made by registerSession(). */
134
+ function unregisterSession() {
135
+ if (sessionRefs === 0) return;
136
+ sessionRefs--;
137
+ if (sessionRefs === 0) removeSessionPidFile();
138
+ }
139
+ /**
140
+ * Register this session, then wait for any running maintenance to finish.
141
+ * Waits indefinitely by default: a vacuum on a multi-GB database can take
142
+ * minutes. With `timeoutMs`, throws after that long naming the holder.
143
+ */
144
+ async function registerSessionAndWaitForMaintenance({ timeoutMs = Infinity, pollMs = 250, onWait } = {}) {
145
+ registerSession();
146
+ const deadline = Date.now() + timeoutMs;
147
+ let notified = false;
148
+ for (;;) {
149
+ const owner = getMaintenanceLockOwner();
150
+ if (owner === null) return;
151
+ if (!notified) {
152
+ notified = true;
153
+ onWait?.(owner);
154
+ }
155
+ if (Date.now() >= deadline) {
156
+ unregisterSession();
157
+ throw new MaintenanceLockError(`Storage maintenance (mastracode prune${describeOwners([owner])}) is still running after ${Math.round(timeoutMs / 1e3)}s. Wait for it to finish, or stop it, then start mastracode again.`, [owner]);
158
+ }
159
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
160
+ }
161
+ }
162
+ /**
163
+ * Acquire the maintenance lock, then refuse if any mastracode session is live.
164
+ * Returns a release function.
165
+ */
166
+ function acquireMaintenanceLock() {
167
+ const lockPath = getMaintenanceLockPath();
168
+ for (let attempt = 0;; attempt++) try {
169
+ fs.writeFileSync(lockPath, String(process.pid), {
170
+ flag: "wx",
171
+ mode: 420
172
+ });
173
+ lockHeld = true;
174
+ break;
175
+ } catch (error) {
176
+ if (error.code !== "EEXIST") throw error;
177
+ const owner = getMaintenanceLockOwner();
178
+ if (owner !== null || attempt > 0) throw new MaintenanceLockError(`Another mastracode prune is already running${owner === null ? "" : describeOwners([owner])}.`, owner === null ? [] : [owner]);
179
+ }
180
+ let released = false;
181
+ const release = () => {
182
+ if (released) return;
183
+ released = true;
184
+ lockHeld = false;
185
+ if (readPid(lockPath) === process.pid) try {
186
+ fs.unlinkSync(lockPath);
187
+ } catch {}
188
+ };
189
+ const sessions = getLiveSessionPids();
190
+ if (sessions.length > 0) {
191
+ release();
192
+ throw new MaintenanceLockError(`mastracode is running${describeOwners(sessions)}. Exit every mastracode session before running prune.`, sessions);
193
+ }
194
+ return release;
195
+ }
196
+ //#endregion
197
+ export { MALFORMED_PID_FILE_GRACE_MS, MaintenanceLockError, UNKNOWN_OWNER, acquireMaintenanceLock, getLiveSessionPids, getMaintenanceLockOwner, getMaintenanceLockPath, registerSession, registerSessionAndWaitForMaintenance, resetSessionRegistrationsForTesting, unregisterSession };
198
+
199
+ //# sourceMappingURL=maintenance-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maintenance-lock.js","names":[],"sources":["../../src/utils/maintenance-lock.ts"],"sourcesContent":["/**\n * Mutual exclusion between storage maintenance (`mastracode prune`) and running\n * mastracode sessions, using the same pid-file / stale-PID pattern as\n * thread-lock.ts.\n *\n * - Every process that opens storage registers a session pid file.\n * - `prune` holds `maintenance.lock` for its whole run.\n *\n * The checks are ordered so the race is closed both ways: `prune` acquires the\n * lock and THEN looks for live sessions; a starter registers and THEN looks for\n * the lock. Whichever acts second always sees the other.\n */\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { getAppDataDir } from './project.js';\n\nexport class MaintenanceLockError extends Error {\n constructor(\n message: string,\n public readonly ownerPids: number[],\n ) {\n super(message);\n this.name = 'MaintenanceLockError';\n }\n}\n\nfunction getLocksDir(): string {\n const dir = path.join(getAppDataDir(), 'locks');\n fs.mkdirSync(dir, { recursive: true });\n return dir;\n}\n\nfunction getSessionsDir(): string {\n const dir = path.join(getLocksDir(), 'sessions');\n fs.mkdirSync(dir, { recursive: true });\n return dir;\n}\n\nexport function getMaintenanceLockPath(): string {\n return path.join(getLocksDir(), 'maintenance.lock');\n}\n\n/** Owner of a lock whose pid file is still being written (PID not known yet). */\nexport const UNKNOWN_OWNER = -1;\n\n/**\n * Creating a pid file (open, then write) is not atomic, so an empty or\n * unparseable file may belong to a process that is mid-write. Only treat it as\n * stale once it is older than this.\n */\nexport const MALFORMED_PID_FILE_GRACE_MS = 5_000;\n\nfunction isProcessAlive(pid: number): boolean {\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n // Only ESRCH proves the process is gone; EPERM etc. mean it exists.\n return (error as NodeJS.ErrnoException).code !== 'ESRCH';\n }\n}\n\n/** Whether a pid file with no readable PID is old enough to reap. Missing files count as reapable. */\nfunction isMalformedPidFileStale(file: string): boolean {\n try {\n return Date.now() - fs.statSync(file).mtimeMs > MALFORMED_PID_FILE_GRACE_MS;\n } catch {\n return true;\n }\n}\n\nfunction describeOwners(pids: number[]): string {\n const known = pids.filter(pid => pid !== UNKNOWN_OWNER);\n return known.length > 0 ? ` (PID ${known.join(', ')})` : '';\n}\n\nfunction readPid(file: string): number | null {\n try {\n const pid = parseInt(fs.readFileSync(file, 'utf-8').trim(), 10);\n return isNaN(pid) ? null : pid;\n } catch {\n return null;\n }\n}\n\n// True while this process holds maintenance.lock, so an own-PID lock can be told\n// apart from a stale leftover whose PID we reused.\nlet lockHeld = false;\n\n/**\n * PID holding the maintenance lock, `UNKNOWN_OWNER` while its pid file is still\n * being written, or null. Stale locks are removed.\n */\nexport function getMaintenanceLockOwner(): number | null {\n const lockPath = getMaintenanceLockPath();\n if (!fs.existsSync(lockPath)) return null;\n const pid = readPid(lockPath);\n if (pid === process.pid) {\n // We hold it (e.g. a concurrent prune in this process): a live owner.\n if (lockHeld) return pid;\n // Otherwise it is a leftover from a dead process whose PID we reused.\n } else if (pid !== null && isProcessAlive(pid)) {\n return pid;\n }\n if (pid === null && !isMalformedPidFileStale(lockPath)) return UNKNOWN_OWNER;\n try {\n fs.unlinkSync(lockPath);\n } catch {}\n return null;\n}\n\n/** PIDs of other live registered sessions. Stale registrations are removed. */\nexport function getLiveSessionPids(): number[] {\n const dir = getSessionsDir();\n const live: number[] = [];\n for (const file of fs.readdirSync(dir)) {\n if (!file.endsWith('.pid')) continue;\n const filePath = path.join(dir, file);\n const pid = readPid(filePath);\n if (pid === process.pid) continue;\n if (pid !== null && isProcessAlive(pid)) {\n live.push(pid);\n } else if (pid === null && !isMalformedPidFileStale(filePath)) {\n live.push(UNKNOWN_OWNER);\n } else {\n try {\n fs.unlinkSync(filePath);\n } catch {}\n }\n }\n return live;\n}\n\n// Refcounted: one process may start several sessions (e.g. repeated\n// createMastraCode() calls). The pid file exists while the count is > 0.\nlet sessionRefs = 0;\nlet exitHookInstalled = false;\n\n/** Test-only: drop every registration held by this process and forget lock ownership. */\nexport function resetSessionRegistrationsForTesting(): void {\n while (sessionRefs > 0) unregisterSession();\n lockHeld = false;\n}\n\nfunction getSessionPidPath(): string {\n return path.join(getSessionsDir(), `${process.pid}.pid`);\n}\n\nfunction removeSessionPidFile(): void {\n try {\n fs.unlinkSync(getSessionPidPath());\n } catch {}\n}\n\n/** Register one running session in this process. Pair with exactly one unregisterSession(). */\nexport function registerSession(): void {\n if (sessionRefs === 0) {\n fs.writeFileSync(getSessionPidPath(), String(process.pid), { mode: 0o644 });\n }\n sessionRefs++;\n if (!exitHookInstalled) {\n exitHookInstalled = true;\n process.once('exit', removeSessionPidFile);\n }\n}\n\n/** Release one registration made by registerSession(). */\nexport function unregisterSession(): void {\n if (sessionRefs === 0) return;\n sessionRefs--;\n if (sessionRefs === 0) removeSessionPidFile();\n}\n\n/**\n * Register this session, then wait for any running maintenance to finish.\n * Waits indefinitely by default: a vacuum on a multi-GB database can take\n * minutes. With `timeoutMs`, throws after that long naming the holder.\n */\nexport async function registerSessionAndWaitForMaintenance({\n timeoutMs = Infinity,\n pollMs = 250,\n onWait,\n}: { timeoutMs?: number; pollMs?: number; onWait?: (ownerPid: number) => void } = {}): Promise<void> {\n registerSession();\n const deadline = Date.now() + timeoutMs;\n let notified = false;\n for (;;) {\n const owner = getMaintenanceLockOwner();\n if (owner === null) return;\n if (!notified) {\n notified = true;\n onWait?.(owner);\n }\n if (Date.now() >= deadline) {\n unregisterSession();\n throw new MaintenanceLockError(\n `Storage maintenance (mastracode prune${describeOwners([owner])}) is still running after ${Math.round(timeoutMs / 1000)}s. ` +\n `Wait for it to finish, or stop it, then start mastracode again.`,\n [owner],\n );\n }\n await new Promise(resolve => setTimeout(resolve, pollMs));\n }\n}\n\n/**\n * Acquire the maintenance lock, then refuse if any mastracode session is live.\n * Returns a release function.\n */\nexport function acquireMaintenanceLock(): () => void {\n const lockPath = getMaintenanceLockPath();\n for (let attempt = 0; ; attempt++) {\n try {\n // 'wx' makes creation atomic, so two prunes cannot both win.\n fs.writeFileSync(lockPath, String(process.pid), { flag: 'wx', mode: 0o644 });\n lockHeld = true;\n break;\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n // getMaintenanceLockOwner() removes a stale lock, so the retry can win.\n const owner = getMaintenanceLockOwner();\n if (owner !== null || attempt > 0) {\n throw new MaintenanceLockError(\n `Another mastracode prune is already running${owner === null ? '' : describeOwners([owner])}.`,\n owner === null ? [] : [owner],\n );\n }\n }\n }\n\n let released = false;\n const release = () => {\n if (released) return;\n released = true;\n lockHeld = false;\n if (readPid(lockPath) === process.pid) {\n try {\n fs.unlinkSync(lockPath);\n } catch {}\n }\n };\n\n const sessions = getLiveSessionPids();\n if (sessions.length > 0) {\n release();\n throw new MaintenanceLockError(\n `mastracode is running${describeOwners(sessions)}. Exit every mastracode session before running prune.`,\n sessions,\n );\n }\n return release;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,IAAa,uBAAb,cAA0C,MAAM;CAG5B;CAFlB,YACE,SACA,WACA;EACA,MAAM,OAAO;EAFG,KAAA,YAAA;EAGhB,KAAK,O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AS,GAAG;EACvB,QAAQ;EACR,MAAM,IAAI,qBACR,wBAAwB,eAAe,QAAQ,EAAE,wDACjD,QACF;CACF;CACA,OAAO;AACT"}
@@ -0,0 +1,59 @@
1
+ import type { LeaseProvider } from '@mastra/core/events';
2
+ import type { Mastra } from '@mastra/core/mastra';
3
+ /**
4
+ * Whether this call runs inside this process's own dispatch pass for
5
+ * `resourceId`, as opposed to the dispatch schedule every process sharing the
6
+ * database takes turns running.
7
+ */
8
+ export declare function isDispatchingNotificationsFor(resourceId: string): boolean;
9
+ /**
10
+ * Whether a delivery-time policy should leave a due notification pending
11
+ * (`hold`). Deliveries happen from this process's own dispatch pass for the
12
+ * record's resource. Anything else holds: a thread no session here owns
13
+ * belongs to another process sharing the database, and once this process's
14
+ * dispatcher runs, its own resources are delivered by whichever process holds
15
+ * their dispatch lease, never by the shared dispatch schedule.
16
+ */
17
+ export declare function shouldHoldNotificationDelivery({ resourceId, ownedHere, dispatcher, }: {
18
+ resourceId: string;
19
+ /** Whether a session in this process owns the resource. */
20
+ ownedHere: boolean;
21
+ dispatcher: {
22
+ readonly running: boolean;
23
+ };
24
+ }): boolean;
25
+ export type ResourceNotificationDispatcherOptions = {
26
+ getMastra: () => Mastra | undefined;
27
+ /** The resources this process runs sessions for. */
28
+ getResourceIds: () => Iterable<string>;
29
+ /**
30
+ * Cross-process leases. When set, a resource's notifications are dispatched
31
+ * only by the process holding its dispatch lease, so two processes serving
32
+ * the same resource (worktrees of one repo) never both deliver them.
33
+ */
34
+ leases?: LeaseProvider;
35
+ /** Unique to this process. */
36
+ owner: string;
37
+ intervalMs?: number;
38
+ leaseTtlMs?: number;
39
+ onError?: (error: unknown) => void;
40
+ };
41
+ /**
42
+ * Delivers the due notifications of the resources this process serves, on a
43
+ * timer of its own.
44
+ *
45
+ * Every Mastra Code process shares one database, so one notification store and
46
+ * one dispatch schedule, and the scheduler gives each fire to whichever process
47
+ * claims it first, usually the same one for as long as it runs. That process
48
+ * cannot run another project's thread, so its delivery policy holds those
49
+ * records. Each process therefore dispatches its own resources here.
50
+ */
51
+ export declare function createResourceNotificationDispatcher(options: ResourceNotificationDispatcherOptions): {
52
+ readonly running: boolean;
53
+ start(): void;
54
+ stop(): Promise<void>;
55
+ /** Runs one dispatch pass now. Only dispatches while started. */
56
+ tick: () => Promise<void>;
57
+ };
58
+ export type ResourceNotificationDispatcher = ReturnType<typeof createResourceNotificationDispatcher>;
59
+ //# sourceMappingURL=notification-dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-dispatch.d.ts","sourceRoot":"","sources":["../../src/utils/notification-dispatch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAWlD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,UAAU,EACV,SAAS,EACT,UAAU,GACX,EAAE;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAC3C,GAAG,OAAO,CAGV;AAED,MAAM,MAAM,qCAAqC,GAAG;IAClD,SAAS,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACpC,oDAAoD;IACpD,cAAc,EAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC;;;;OAIG;IACH,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACpC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,qCAAqC;sBA2DhF,OAAO;aAGb,IAAI;YAMC,OAAO,CAAC,IAAI,CAAC;IAM3B,iEAAiE;gBA1BlD,OAAO,CAAC,IAAI,CAAC;EA6B/B;AAED,MAAM,MAAM,8BAA8B,GAAG,UAAU,CAAC,OAAO,oCAAoC,CAAC,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { notificationDispatchLeaseKey } from "./signals-pubsub.js";
2
+ import { dispatchDueNotifications } from "@mastra/core/notifications";
3
+ import { AsyncLocalStorage } from "async_hooks";
4
+ //#region src/utils/notification-dispatch.ts
5
+ const DEFAULT_INTERVAL_MS = 1e4;
6
+ const DEFAULT_LEASE_TTL_MS = 6e4;
7
+ /** The resource whose notifications the current async context is dispatching. */
8
+ const dispatchingFor = new AsyncLocalStorage();
9
+ /**
10
+ * Whether this call runs inside this process's own dispatch pass for
11
+ * `resourceId`, as opposed to the dispatch schedule every process sharing the
12
+ * database takes turns running.
13
+ */
14
+ function isDispatchingNotificationsFor(resourceId) {
15
+ return dispatchingFor.getStore() === resourceId;
16
+ }
17
+ /**
18
+ * Whether a delivery-time policy should leave a due notification pending
19
+ * (`hold`). Deliveries happen from this process's own dispatch pass for the
20
+ * record's resource. Anything else holds: a thread no session here owns
21
+ * belongs to another process sharing the database, and once this process's
22
+ * dispatcher runs, its own resources are delivered by whichever process holds
23
+ * their dispatch lease, never by the shared dispatch schedule.
24
+ */
25
+ function shouldHoldNotificationDelivery({ resourceId, ownedHere, dispatcher }) {
26
+ if (isDispatchingNotificationsFor(resourceId)) return false;
27
+ return !ownedHere || dispatcher.running;
28
+ }
29
+ /**
30
+ * Delivers the due notifications of the resources this process serves, on a
31
+ * timer of its own.
32
+ *
33
+ * Every Mastra Code process shares one database, so one notification store and
34
+ * one dispatch schedule, and the scheduler gives each fire to whichever process
35
+ * claims it first, usually the same one for as long as it runs. That process
36
+ * cannot run another project's thread, so its delivery policy holds those
37
+ * records. Each process therefore dispatches its own resources here.
38
+ */
39
+ function createResourceNotificationDispatcher(options) {
40
+ const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
41
+ const leaseTtlMs = options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS;
42
+ const held = /* @__PURE__ */ new Set();
43
+ let timer;
44
+ let ticking;
45
+ const release = async (resourceId) => {
46
+ held.delete(resourceId);
47
+ await options.leases?.releaseLease(notificationDispatchLeaseKey(resourceId), options.owner).catch(options.onError);
48
+ };
49
+ const claim = async (resourceId) => {
50
+ if (!options.leases) return true;
51
+ try {
52
+ const { acquired } = await options.leases.acquireLease(notificationDispatchLeaseKey(resourceId), options.owner, leaseTtlMs);
53
+ if (acquired) held.add(resourceId);
54
+ else held.delete(resourceId);
55
+ return acquired;
56
+ } catch (error) {
57
+ options.onError?.(error);
58
+ return false;
59
+ }
60
+ };
61
+ const runTick = async () => {
62
+ const mastra = options.getMastra();
63
+ const storage = await mastra?.getStorage()?.getStore("notifications");
64
+ if (!mastra || !storage) return;
65
+ const resourceIds = new Set(options.getResourceIds());
66
+ for (const resourceId of [...held]) if (!resourceIds.has(resourceId)) await release(resourceId);
67
+ for (const resourceId of resourceIds) {
68
+ if (!timer || !await claim(resourceId)) continue;
69
+ try {
70
+ await dispatchingFor.run(resourceId, () => dispatchDueNotifications({
71
+ mastra,
72
+ storage,
73
+ resourceId
74
+ }));
75
+ } catch (error) {
76
+ options.onError?.(error);
77
+ }
78
+ }
79
+ };
80
+ const tick = () => {
81
+ ticking ??= runTick().catch((error) => options.onError?.(error)).finally(() => {
82
+ ticking = void 0;
83
+ });
84
+ return ticking;
85
+ };
86
+ return {
87
+ get running() {
88
+ return timer !== void 0;
89
+ },
90
+ start() {
91
+ if (timer) return;
92
+ timer = setInterval(() => void tick(), intervalMs);
93
+ timer.unref?.();
94
+ tick();
95
+ },
96
+ async stop() {
97
+ if (timer) clearInterval(timer);
98
+ timer = void 0;
99
+ await ticking;
100
+ await Promise.all([...held].map(release));
101
+ },
102
+ /** Runs one dispatch pass now. Only dispatches while started. */
103
+ tick
104
+ };
105
+ }
106
+ //#endregion
107
+ export { createResourceNotificationDispatcher, isDispatchingNotificationsFor, shouldHoldNotificationDelivery };
108
+
109
+ //# sourceMappingURL=notification-dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification-dispatch.js","names":[],"sources":["../../src/utils/notification-dispatch.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\n\nimport type { LeaseProvider } from '@mastra/core/events';\nimport type { Mastra } from '@mastra/core/mastra';\nimport { dispatchDueNotifications } from '@mastra/core/notifications';\n\nimport { notificationDispatchLeaseKey } from './signals-pubsub.js';\n\nconst DEFAULT_INTERVAL_MS = 10_000;\nconst DEFAULT_LEASE_TTL_MS = 60_000;\n\n/** The resource whose notifications the current async context is dispatching. */\nconst dispatchingFor = new AsyncLocalStorage<string>();\n\n/**\n * Whether this call runs inside this process's own dispatch pass for\n * `resourceId`, as opposed to the dispatch schedule every process sharing the\n * database takes turns running.\n */\nexport function isDispatchingNotificationsFor(resourceId: string): boolean {\n return dispatchingFor.getStore() === resourceId;\n}\n\n/**\n * Whether a delivery-time policy should leave a due notification pending\n * (`hold`). Deliveries happen from this process's own dispatch pass for the\n * record's resource. Anything else holds: a thread no session here owns\n * belongs to another process sharing the database, and once this process's\n * dispatcher runs, its own resources are delivered by whichever process holds\n * their dispatch lease, never by the shared dispatch schedule.\n */\nexport function shouldHoldNotificationDelivery({\n resourceId,\n ownedHere,\n dispatcher,\n}: {\n resourceId: string;\n /** Whether a session in this process owns the resource. */\n ownedHere: boolean;\n dispatcher: { readonly running: boolean };\n}): boolean {\n if (isDispatchingNotificationsFor(resourceId)) return false;\n return !ownedHere || dispatcher.running;\n}\n\nexport type ResourceNotificationDispatcherOptions = {\n getMastra: () => Mastra | undefined;\n /** The resources this process runs sessions for. */\n getResourceIds: () => Iterable<string>;\n /**\n * Cross-process leases. When set, a resource's notifications are dispatched\n * only by the process holding its dispatch lease, so two processes serving\n * the same resource (worktrees of one repo) never both deliver them.\n */\n leases?: LeaseProvider;\n /** Unique to this process. */\n owner: string;\n intervalMs?: number;\n leaseTtlMs?: number;\n onError?: (error: unknown) => void;\n};\n\n/**\n * Delivers the due notifications of the resources this process serves, on a\n * timer of its own.\n *\n * Every Mastra Code process shares one database, so one notification store and\n * one dispatch schedule, and the scheduler gives each fire to whichever process\n * claims it first, usually the same one for as long as it runs. That process\n * cannot run another project's thread, so its delivery policy holds those\n * records. Each process therefore dispatches its own resources here.\n */\nexport function createResourceNotificationDispatcher(options: ResourceNotificationDispatcherOptions) {\n const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;\n const leaseTtlMs = options.leaseTtlMs ?? DEFAULT_LEASE_TTL_MS;\n const held = new Set<string>();\n let timer: ReturnType<typeof setInterval> | undefined;\n let ticking: Promise<void> | undefined;\n\n const release = async (resourceId: string) => {\n held.delete(resourceId);\n await options.leases?.releaseLease(notificationDispatchLeaseKey(resourceId), options.owner).catch(options.onError);\n };\n\n const claim = async (resourceId: string): Promise<boolean> => {\n if (!options.leases) return true;\n try {\n // Acquiring a lease this process already holds renews it.\n const { acquired } = await options.leases.acquireLease(\n notificationDispatchLeaseKey(resourceId),\n options.owner,\n leaseTtlMs,\n );\n if (acquired) held.add(resourceId);\n else held.delete(resourceId);\n return acquired;\n } catch (error) {\n options.onError?.(error);\n return false;\n }\n };\n\n const runTick = async () => {\n const mastra = options.getMastra();\n const storage = await mastra?.getStorage()?.getStore('notifications');\n if (!mastra || !storage) return;\n const resourceIds = new Set(options.getResourceIds());\n for (const resourceId of [...held]) {\n if (!resourceIds.has(resourceId)) await release(resourceId);\n }\n for (const resourceId of resourceIds) {\n if (!timer || !(await claim(resourceId))) continue;\n try {\n await dispatchingFor.run(resourceId, () => dispatchDueNotifications({ mastra, storage, resourceId }));\n } catch (error) {\n options.onError?.(error);\n }\n }\n };\n\n const tick = (): Promise<void> => {\n // Ticks run from a timer, so a failure must be reported, never left as an unhandled rejection.\n ticking ??= runTick()\n .catch(error => options.onError?.(error))\n .finally(() => {\n ticking = undefined;\n });\n return ticking;\n };\n\n return {\n get running(): boolean {\n return timer !== undefined;\n },\n start(): void {\n if (timer) return;\n timer = setInterval(() => void tick(), intervalMs);\n timer.unref?.();\n void tick();\n },\n async stop(): Promise<void> {\n if (timer) clearInterval(timer);\n timer = undefined;\n await ticking;\n await Promise.all([...held].map(release));\n },\n /** Runs one dispatch pass now. Only dispatches while started. */\n tick,\n };\n}\n\nexport type ResourceNotificationDispatcher = ReturnType<typeof createResourceNotificationDispatcher>;\n"],"mappings":";;;;AAQA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;;AAG7B,MAAM,iBAAiB,IAAI,kBAA0B;;;;;;AAOrD,SAAgB,8BAA8B,YAA6B;CACzE,OAAO,eAAe,SAAS,MAAM;AACvC;;;;;;;;;AAUA,SAAgB,+BAA+B,EAC7C,YACA,WACA,cAMU;CACV,IAAI,8BAA8B,UAAU,GAAG,OAAO;CACtD,OAAO,CAAC,aAAa,WAAW;AAClC;;;;;;;;;;;AA6BA,SAAgB,qCAAqC,SAAgD;CACnG,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,aAAa,QAAQ,cAAc;CACzC,MAAM,uBAAO,IAAI,IAAY;CAC7B,IAAI;CACJ,IAAI;CAEJ,MAAM,UAAU,OAAO,eAAuB;EAC5C,KAAK,OAAO,UAAU;EACtB,MAAM,QAAQ,QAAQ,aAAa,6BAA6B,UAAU,GAAG,QAAQ,KAAK,CAAC,CAAC,MAAM,QAAQ,OAAO;CACnH;CAEA,MAAM,QAAQ,OAAO,eAAyC;EAC5D,IAAI,CAAC,QAAQ,QAAQ,OAAO;EAC5B,IAAI;GAEF,MAAM,EAAE,aAAa,MAAM,QAAQ,OAAO,aACxC,6BAA6B,UAAU,GACvC,QAAQ,OACR,UACF;GACA,IAAI,UAAU,KAAK,IAAI,UAAU;QAC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without going through a shell.
6
+ * Only well-formed http(s) URLs are opened; anything else is ignored
7
+ * (the URL is still displayed for the user to open manually).
8
+ */
9
+ export declare function openUrlInBrowser(url: string): void;
10
+ //# sourceMappingURL=open-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-url.d.ts","sourceRoot":"","sources":["../../src/utils/open-url.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAsBlD"}
@@ -0,0 +1,30 @@
1
+ import { spawn } from "child_process";
2
+ //#region src/utils/open-url.ts
3
+ /**
4
+ * Best-effort browser opening for OAuth and other login flows.
5
+ */
6
+ /**
7
+ * Open a URL in the default browser without going through a shell.
8
+ * Only well-formed http(s) URLs are opened; anything else is ignored
9
+ * (the URL is still displayed for the user to open manually).
10
+ */
11
+ function openUrlInBrowser(url) {
12
+ let parsed;
13
+ try {
14
+ parsed = new URL(url);
15
+ } catch {
16
+ return;
17
+ }
18
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return;
19
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
20
+ const child = spawn(cmd, args, {
21
+ stdio: "ignore",
22
+ detached: true
23
+ });
24
+ child.on("error", () => {});
25
+ child.unref();
26
+ }
27
+ //#endregion
28
+ export { openUrlInBrowser };
29
+
30
+ //# sourceMappingURL=open-url.js.map