@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (407) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +284 -0
  3. package/dist/acp/agent.d.ts +48 -0
  4. package/dist/acp/agent.js +414 -0
  5. package/dist/acp/errors.d.ts +3 -0
  6. package/dist/acp/errors.js +11 -0
  7. package/dist/acp/event-mapper.d.ts +28 -0
  8. package/dist/acp/event-mapper.js +274 -0
  9. package/dist/acp/index.d.ts +9 -0
  10. package/dist/acp/index.js +21 -0
  11. package/dist/acp/runtime.d.ts +5 -0
  12. package/dist/acp/runtime.js +91 -0
  13. package/dist/acp/server.d.ts +4 -0
  14. package/dist/acp/server.js +35 -0
  15. package/dist/acp/skills.d.ts +6 -0
  16. package/dist/acp/skills.js +30 -0
  17. package/dist/acp.d.ts +2 -0
  18. package/dist/acp.js +1 -0
  19. package/dist/agent-connections/messaging-processor.d.ts +17 -0
  20. package/dist/agent-connections/messaging-processor.js +131 -0
  21. package/dist/agent-connections/ownership.d.ts +24 -0
  22. package/dist/agent-connections/ownership.js +96 -0
  23. package/dist/agent-connections/registry.d.ts +20 -0
  24. package/dist/agent-connections/registry.js +167 -0
  25. package/dist/agent-connections/session-advertisement.d.ts +27 -0
  26. package/dist/agent-connections/session-advertisement.js +86 -0
  27. package/dist/agent-connections/signal-provider.d.ts +141 -0
  28. package/dist/agent-connections/signal-provider.js +35 -0
  29. package/dist/agent-connections/state-processor.d.ts +23 -0
  30. package/dist/agent-connections/state-processor.js +270 -0
  31. package/dist/agent-connections/thread-state.d.ts +41 -0
  32. package/dist/agent-connections/thread-state.js +157 -0
  33. package/dist/agent-connections/tools.d.ts +133 -0
  34. package/dist/agent-connections/tools.js +616 -0
  35. package/dist/agent-connections/types.d.ts +99 -0
  36. package/dist/agent-connections/types.js +4 -0
  37. package/dist/agent-connections/untrusted-text.d.ts +5 -0
  38. package/dist/agent-connections/untrusted-text.js +19 -0
  39. package/dist/agents/background-completion-events.d.ts +16 -0
  40. package/dist/agents/background-completion-events.js +16 -0
  41. package/dist/agents/background-completion.d.ts +22 -0
  42. package/dist/agents/background-completion.js +73 -0
  43. package/dist/agents/context-audit.d.ts +84 -0
  44. package/dist/agents/context-audit.js +115 -0
  45. package/dist/agents/credential-resolver.d.ts +74 -0
  46. package/dist/agents/credential-resolver.js +142 -0
  47. package/dist/agents/custom-provider-source.d.ts +35 -0
  48. package/dist/agents/custom-provider-source.js +22 -0
  49. package/dist/agents/fastembed-subprocess.d.ts +52 -0
  50. package/dist/agents/fastembed-subprocess.js +282 -0
  51. package/dist/agents/instructions.d.ts +42 -0
  52. package/dist/agents/instructions.js +69 -0
  53. package/dist/agents/mastracode-gateway.d.ts +85 -0
  54. package/dist/agents/mastracode-gateway.js +500 -0
  55. package/dist/agents/memory.d.ts +36 -0
  56. package/dist/agents/memory.js +248 -0
  57. package/dist/agents/model.d.ts +158 -0
  58. package/dist/agents/model.js +382 -0
  59. package/dist/agents/modes/build.d.ts +12 -0
  60. package/dist/agents/modes/build.js +33 -0
  61. package/dist/agents/modes/explore.d.ts +10 -0
  62. package/dist/agents/modes/explore.js +25 -0
  63. package/dist/agents/modes/plan.d.ts +8 -0
  64. package/dist/agents/modes/plan.js +43 -0
  65. package/dist/agents/prompts/agent-instructions.d.ts +122 -0
  66. package/dist/agents/prompts/agent-instructions.js +617 -0
  67. package/dist/agents/prompts/build.d.ts +12 -0
  68. package/dist/agents/prompts/build.js +73 -0
  69. package/dist/agents/prompts/fast.d.ts +5 -0
  70. package/dist/agents/prompts/fast.js +23 -0
  71. package/dist/agents/prompts/index.d.ts +61 -0
  72. package/dist/agents/prompts/index.js +141 -0
  73. package/dist/agents/prompts/model.d.ts +5 -0
  74. package/dist/agents/prompts/model.js +20 -0
  75. package/dist/agents/prompts/plan.d.ts +11 -0
  76. package/dist/agents/prompts/plan.js +132 -0
  77. package/dist/agents/prompts/tool-guidance.d.ts +18 -0
  78. package/dist/agents/prompts/tool-guidance.js +158 -0
  79. package/dist/agents/sandbox-filesystem.d.ts +232 -0
  80. package/dist/agents/sandbox-filesystem.js +851 -0
  81. package/dist/agents/subagents/execute.d.ts +3 -0
  82. package/dist/agents/subagents/execute.js +24 -0
  83. package/dist/agents/subagents/explore.d.ts +3 -0
  84. package/dist/agents/subagents/explore.js +15 -0
  85. package/dist/agents/subagents/index.d.ts +6 -0
  86. package/dist/agents/subagents/index.js +15 -0
  87. package/dist/agents/subagents/plan.d.ts +3 -0
  88. package/dist/agents/subagents/plan.js +15 -0
  89. package/dist/agents/thread-caveman-state.d.ts +17 -0
  90. package/dist/agents/thread-caveman-state.js +104 -0
  91. package/dist/agents/tool-availability.d.ts +17 -0
  92. package/dist/agents/tool-availability.js +134 -0
  93. package/dist/agents/tools.d.ts +37 -0
  94. package/dist/agents/tools.js +154 -0
  95. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  96. package/dist/agents/workflow-builder-agent.js +79 -0
  97. package/dist/agents/workspace.d.ts +35 -0
  98. package/dist/agents/workspace.js +207 -0
  99. package/dist/analytics.d.ts +18 -0
  100. package/dist/analytics.js +159 -0
  101. package/dist/auth/account-rotation-processor.d.ts +210 -0
  102. package/dist/auth/account-rotation-processor.js +662 -0
  103. package/dist/auth/account-routing-context.d.ts +17 -0
  104. package/dist/auth/account-routing-context.js +38 -0
  105. package/dist/auth/authorization-input.d.ts +16 -0
  106. package/dist/auth/authorization-input.js +39 -0
  107. package/dist/auth/device-code.d.ts +93 -0
  108. package/dist/auth/device-code.js +126 -0
  109. package/dist/auth/index.d.ts +13 -0
  110. package/dist/auth/index.js +9 -0
  111. package/dist/auth/pkce.d.ts +13 -0
  112. package/dist/auth/pkce.js +29 -0
  113. package/dist/auth/provider-auth-error.d.ts +24 -0
  114. package/dist/auth/provider-auth-error.js +44 -0
  115. package/dist/auth/providers/anthropic.d.ts +40 -0
  116. package/dist/auth/providers/anthropic.js +117 -0
  117. package/dist/auth/providers/github-copilot.d.ts +154 -0
  118. package/dist/auth/providers/github-copilot.js +359 -0
  119. package/dist/auth/providers/kimi-coding.d.ts +38 -0
  120. package/dist/auth/providers/kimi-coding.js +225 -0
  121. package/dist/auth/providers/openai-codex.d.ts +141 -0
  122. package/dist/auth/providers/openai-codex.js +531 -0
  123. package/dist/auth/providers/xai.d.ts +64 -0
  124. package/dist/auth/providers/xai.js +223 -0
  125. package/dist/auth/storage.d.ts +222 -0
  126. package/dist/auth/storage.js +805 -0
  127. package/dist/auth/types.d.ts +164 -0
  128. package/dist/auth/types.js +1 -0
  129. package/dist/clipboard/index.d.ts +26 -0
  130. package/dist/clipboard/index.js +224 -0
  131. package/dist/constants.d.ts +29 -0
  132. package/dist/constants.js +34 -0
  133. package/dist/error-classification.d.ts +10 -0
  134. package/dist/error-classification.js +19 -0
  135. package/dist/evals/context-builder.d.ts +41 -0
  136. package/dist/evals/context-builder.js +156 -0
  137. package/dist/evals/index.d.ts +4 -0
  138. package/dist/evals/index.js +5 -0
  139. package/dist/evals/scorers/classify-command.d.ts +30 -0
  140. package/dist/evals/scorers/classify-command.js +61 -0
  141. package/dist/evals/scorers/efficiency.d.ts +44 -0
  142. package/dist/evals/scorers/efficiency.js +256 -0
  143. package/dist/evals/scorers/extract-tools.d.ts +25 -0
  144. package/dist/evals/scorers/extract-tools.js +57 -0
  145. package/dist/evals/scorers/index.d.ts +3 -0
  146. package/dist/evals/scorers/index.js +3 -0
  147. package/dist/evals/scorers/outcome.d.ts +49 -0
  148. package/dist/evals/scorers/outcome.js +360 -0
  149. package/dist/experimental-agent.d.ts +19 -0
  150. package/dist/experimental-agent.js +45 -0
  151. package/dist/factory/client.d.ts +44 -0
  152. package/dist/factory/client.js +110 -0
  153. package/dist/factory/remote-controller.d.ts +34 -0
  154. package/dist/factory/remote-controller.js +40 -0
  155. package/dist/factory/remote-session.d.ts +210 -0
  156. package/dist/factory/remote-session.js +415 -0
  157. package/dist/goal-manager.d.ts +114 -0
  158. package/dist/goal-manager.js +351 -0
  159. package/dist/goal-signal.d.ts +14 -0
  160. package/dist/goal-signal.js +14 -0
  161. package/dist/headless/cli.d.ts +55 -0
  162. package/dist/headless/cli.js +261 -0
  163. package/dist/headless/flags.d.ts +33 -0
  164. package/dist/headless/flags.js +207 -0
  165. package/dist/headless/format.d.ts +41 -0
  166. package/dist/headless/format.js +94 -0
  167. package/dist/headless/index.d.ts +25 -0
  168. package/dist/headless/index.js +6 -0
  169. package/dist/headless/policy.d.ts +17 -0
  170. package/dist/headless/policy.js +39 -0
  171. package/dist/headless/run-mc.d.ts +7 -0
  172. package/dist/headless/run-mc.js +438 -0
  173. package/dist/headless/types.d.ts +175 -0
  174. package/dist/headless/types.js +16 -0
  175. package/dist/hooks/config.d.ts +11 -0
  176. package/dist/hooks/config.js +77 -0
  177. package/dist/hooks/executor.d.ts +13 -0
  178. package/dist/hooks/executor.js +128 -0
  179. package/dist/hooks/index.d.ts +6 -0
  180. package/dist/hooks/index.js +5 -0
  181. package/dist/hooks/manager.d.ts +75 -0
  182. package/dist/hooks/manager.js +289 -0
  183. package/dist/hooks/types.d.ts +180 -0
  184. package/dist/hooks/types.js +5 -0
  185. package/dist/index.d.ts +537 -0
  186. package/dist/index.js +1399 -0
  187. package/dist/ipc/ipc-reporter.d.ts +14 -0
  188. package/dist/ipc/ipc-reporter.js +18 -0
  189. package/dist/knowledge-inspector.d.ts +139 -0
  190. package/dist/knowledge-inspector.js +533 -0
  191. package/dist/knowledge-scope-id.d.ts +7 -0
  192. package/dist/knowledge-scope-id.js +10 -0
  193. package/dist/knowledge-scope.d.ts +41 -0
  194. package/dist/knowledge-scope.js +85 -0
  195. package/dist/lsp/client.d.ts +56 -0
  196. package/dist/lsp/client.js +248 -0
  197. package/dist/lsp/index.d.ts +4 -0
  198. package/dist/lsp/index.js +4 -0
  199. package/dist/lsp/language.d.ts +9 -0
  200. package/dist/lsp/language.js +41 -0
  201. package/dist/lsp/manager.d.ts +34 -0
  202. package/dist/lsp/manager.js +79 -0
  203. package/dist/lsp/server.d.ts +27 -0
  204. package/dist/lsp/server.js +158 -0
  205. package/dist/lsp/workspace.d.ts +9 -0
  206. package/dist/lsp/workspace.js +52 -0
  207. package/dist/mcp/config.d.ts +77 -0
  208. package/dist/mcp/config.js +313 -0
  209. package/dist/mcp/index.d.ts +6 -0
  210. package/dist/mcp/index.js +3 -0
  211. package/dist/mcp/manager.d.ts +104 -0
  212. package/dist/mcp/manager.js +693 -0
  213. package/dist/mcp/state.d.ts +35 -0
  214. package/dist/mcp/state.js +94 -0
  215. package/dist/mcp/types.d.ts +139 -0
  216. package/dist/mcp/types.js +1 -0
  217. package/dist/onboarding/custom-packs.d.ts +7 -0
  218. package/dist/onboarding/custom-packs.js +17 -0
  219. package/dist/onboarding/custom-providers.d.ts +4 -0
  220. package/dist/onboarding/custom-providers.js +27 -0
  221. package/dist/onboarding/index.d.ts +5 -0
  222. package/dist/onboarding/index.js +3 -0
  223. package/dist/onboarding/om-settings.d.ts +47 -0
  224. package/dist/onboarding/om-settings.js +80 -0
  225. package/dist/onboarding/pack-activation.d.ts +43 -0
  226. package/dist/onboarding/pack-activation.js +105 -0
  227. package/dist/onboarding/packs.d.ts +106 -0
  228. package/dist/onboarding/packs.js +283 -0
  229. package/dist/onboarding/settings.d.ts +563 -0
  230. package/dist/onboarding/settings.js +1110 -0
  231. package/dist/permissions.d.ts +55 -0
  232. package/dist/permissions.js +139 -0
  233. package/dist/platform/index.d.ts +74 -0
  234. package/dist/platform/index.js +199 -0
  235. package/dist/plugin.d.ts +156 -0
  236. package/dist/plugin.js +27 -0
  237. package/dist/plugins/dependencies.d.ts +9 -0
  238. package/dist/plugins/dependencies.js +84 -0
  239. package/dist/plugins/install.d.ts +21 -0
  240. package/dist/plugins/install.js +187 -0
  241. package/dist/plugins/loader.d.ts +25 -0
  242. package/dist/plugins/loader.js +264 -0
  243. package/dist/plugins/manager.d.ts +115 -0
  244. package/dist/plugins/manager.js +507 -0
  245. package/dist/plugins/manifest.d.ts +14 -0
  246. package/dist/plugins/manifest.js +47 -0
  247. package/dist/plugins/package-link.d.ts +3 -0
  248. package/dist/plugins/package-link.js +58 -0
  249. package/dist/plugins/paths.d.ts +10 -0
  250. package/dist/plugins/paths.js +22 -0
  251. package/dist/plugins/registry.d.ts +8 -0
  252. package/dist/plugins/registry.js +109 -0
  253. package/dist/plugins/scaffold.d.ts +10 -0
  254. package/dist/plugins/scaffold.js +115 -0
  255. package/dist/plugins/signal-lane.d.ts +59 -0
  256. package/dist/plugins/signal-lane.js +163 -0
  257. package/dist/plugins/types.d.ts +95 -0
  258. package/dist/plugins/types.js +1 -0
  259. package/dist/process-memory-diagnostics.d.ts +136 -0
  260. package/dist/process-memory-diagnostics.js +497 -0
  261. package/dist/processors/plan-rejection-abort.d.ts +16 -0
  262. package/dist/processors/plan-rejection-abort.js +62 -0
  263. package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
  264. package/dist/providers/amazon-bedrock-gateway.js +142 -0
  265. package/dist/providers/amazon-bedrock.d.ts +28 -0
  266. package/dist/providers/amazon-bedrock.js +99 -0
  267. package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
  268. package/dist/providers/anthropic-prompt-cache.js +8 -0
  269. package/dist/providers/anthropic-thinking.d.ts +5 -0
  270. package/dist/providers/anthropic-thinking.js +22 -0
  271. package/dist/providers/claude-max.d.ts +67 -0
  272. package/dist/providers/claude-max.js +232 -0
  273. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  274. package/dist/providers/github-copilot-gateway.js +58 -0
  275. package/dist/providers/github-copilot.d.ts +60 -0
  276. package/dist/providers/github-copilot.js +320 -0
  277. package/dist/providers/google-thinking.d.ts +31 -0
  278. package/dist/providers/google-thinking.js +64 -0
  279. package/dist/providers/google-vertex-gateway.d.ts +23 -0
  280. package/dist/providers/google-vertex-gateway.js +49 -0
  281. package/dist/providers/google-vertex.d.ts +6 -0
  282. package/dist/providers/google-vertex.js +51 -0
  283. package/dist/providers/kimi-coding.d.ts +14 -0
  284. package/dist/providers/kimi-coding.js +80 -0
  285. package/dist/providers/model-ids.d.ts +53 -0
  286. package/dist/providers/model-ids.js +132 -0
  287. package/dist/providers/openai-codex.d.ts +114 -0
  288. package/dist/providers/openai-codex.js +427 -0
  289. package/dist/providers/provider-thinking.d.ts +23 -0
  290. package/dist/providers/provider-thinking.js +61 -0
  291. package/dist/providers/thinking-request.d.ts +14 -0
  292. package/dist/providers/thinking-request.js +87 -0
  293. package/dist/providers/xai.d.ts +33 -0
  294. package/dist/providers/xai.js +72 -0
  295. package/dist/schedules/index.d.ts +10 -0
  296. package/dist/schedules/index.js +6 -0
  297. package/dist/schedules/interval.d.ts +49 -0
  298. package/dist/schedules/interval.js +212 -0
  299. package/dist/schedules/prompt.d.ts +36 -0
  300. package/dist/schedules/prompt.js +36 -0
  301. package/dist/schedules/run-script.d.ts +8 -0
  302. package/dist/schedules/run-script.js +80 -0
  303. package/dist/schedules/scheduler.d.ts +101 -0
  304. package/dist/schedules/scheduler.js +167 -0
  305. package/dist/schedules/tools.d.ts +57 -0
  306. package/dist/schedules/tools.js +217 -0
  307. package/dist/schema.d.ts +499 -0
  308. package/dist/schema.js +131 -0
  309. package/dist/theme-palette.d.ts +17 -0
  310. package/dist/theme-palette.js +18 -0
  311. package/dist/thinking-catalog.d.ts +4 -0
  312. package/dist/thinking-catalog.js +13 -0
  313. package/dist/thinking.d.ts +37 -0
  314. package/dist/thinking.js +134 -0
  315. package/dist/tool-names.d.ts +77 -0
  316. package/dist/tool-names.js +53 -0
  317. package/dist/tools/index.d.ts +6 -0
  318. package/dist/tools/index.js +3 -0
  319. package/dist/tools/request-sandbox-access.d.ts +6 -0
  320. package/dist/tools/request-sandbox-access.js +80 -0
  321. package/dist/tools/utils.d.ts +20 -0
  322. package/dist/tools/utils.js +31 -0
  323. package/dist/tools/web-search.d.ts +116 -0
  324. package/dist/tools/web-search.js +158 -0
  325. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  326. package/dist/tools/workflows/create-workflow.js +82 -0
  327. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  328. package/dist/tools/workflows/delete-workflow.js +18 -0
  329. package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
  330. package/dist/tools/workflows/ephemeral-memory.js +41 -0
  331. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  332. package/dist/tools/workflows/extract-json-schema.js +19 -0
  333. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  334. package/dist/tools/workflows/get-workflow.js +31 -0
  335. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  336. package/dist/tools/workflows/list-available-agents.js +29 -0
  337. package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
  338. package/dist/tools/workflows/list-available-classifiers.js +53 -0
  339. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  340. package/dist/tools/workflows/list-available-tools.js +37 -0
  341. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  342. package/dist/tools/workflows/list-available-workflows.js +29 -0
  343. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  344. package/dist/tools/workflows/list-workflows.js +30 -0
  345. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  346. package/dist/tools/workflows/run-workflow.js +49 -0
  347. package/dist/tools/workflows/save-workflow.d.ts +1125 -0
  348. package/dist/tools/workflows/save-workflow.js +25 -0
  349. package/dist/tools/workflows/tool-ids.d.ts +16 -0
  350. package/dist/tools/workflows/tool-ids.js +17 -0
  351. package/dist/utils/binaries.d.ts +7 -0
  352. package/dist/utils/binaries.js +97 -0
  353. package/dist/utils/debug-log.d.ts +12 -0
  354. package/dist/utils/debug-log.js +56 -0
  355. package/dist/utils/discarding-scores-storage.d.ts +33 -0
  356. package/dist/utils/discarding-scores-storage.js +51 -0
  357. package/dist/utils/errors.d.ts +36 -0
  358. package/dist/utils/errors.js +215 -0
  359. package/dist/utils/gateway-sync.d.ts +26 -0
  360. package/dist/utils/gateway-sync.js +58 -0
  361. package/dist/utils/local-observability.d.ts +19 -0
  362. package/dist/utils/local-observability.js +54 -0
  363. package/dist/utils/maintenance-lock.d.ts +42 -0
  364. package/dist/utils/maintenance-lock.js +196 -0
  365. package/dist/utils/notification-dispatch.d.ts +74 -0
  366. package/dist/utils/notification-dispatch.js +128 -0
  367. package/dist/utils/open-url.d.ts +10 -0
  368. package/dist/utils/open-url.js +27 -0
  369. package/dist/utils/path-security.d.ts +2 -0
  370. package/dist/utils/path-security.js +7 -0
  371. package/dist/utils/plan-diff.d.ts +25 -0
  372. package/dist/utils/plan-diff.js +59 -0
  373. package/dist/utils/plans.d.ts +61 -0
  374. package/dist/utils/plans.js +120 -0
  375. package/dist/utils/project.d.ts +160 -0
  376. package/dist/utils/project.js +361 -0
  377. package/dist/utils/prune-cli.d.ts +24 -0
  378. package/dist/utils/prune-cli.js +124 -0
  379. package/dist/utils/signals-pubsub.d.ts +103 -0
  380. package/dist/utils/signals-pubsub.js +409 -0
  381. package/dist/utils/slash-command-loader.d.ts +52 -0
  382. package/dist/utils/slash-command-loader.js +139 -0
  383. package/dist/utils/slash-command-processor.d.ts +14 -0
  384. package/dist/utils/slash-command-processor.js +106 -0
  385. package/dist/utils/stdin-pipe.d.ts +33 -0
  386. package/dist/utils/stdin-pipe.js +93 -0
  387. package/dist/utils/storage-factory.d.ts +50 -0
  388. package/dist/utils/storage-factory.js +118 -0
  389. package/dist/utils/storage-maintenance.d.ts +121 -0
  390. package/dist/utils/storage-maintenance.js +352 -0
  391. package/dist/utils/thread-lock.d.ts +26 -0
  392. package/dist/utils/thread-lock.js +109 -0
  393. package/dist/utils/token-estimator.d.ts +3 -0
  394. package/dist/utils/token-estimator.js +19 -0
  395. package/dist/utils/update-check.d.ts +151 -0
  396. package/dist/utils/update-check.js +430 -0
  397. package/dist/utils/wake-session.d.ts +44 -0
  398. package/dist/utils/wake-session.js +83 -0
  399. package/dist/voice/stt-registry.d.ts +67 -0
  400. package/dist/voice/stt-registry.js +144 -0
  401. package/dist/voice/transcribe.d.ts +10 -0
  402. package/dist/voice/transcribe.js +75 -0
  403. package/dist/workflows/register-primitives.d.ts +52 -0
  404. package/dist/workflows/register-primitives.js +40 -0
  405. package/dist/workflows/service.d.ts +64 -0
  406. package/dist/workflows/service.js +50 -0
  407. package/package.json +117 -0
@@ -0,0 +1,40 @@
1
+ import { FACTORY_CONTROLLER_ID, createFactoryClient } from "./client.js";
2
+ // src/factory/remote-controller.ts
3
+ /**
4
+ * The Factory-side counterpart to the local agent controller. Modes, models, and
5
+ * provider auth come from the Factory, never from local settings or auth storage.
6
+ */
7
+ var RemoteController = class {
8
+ id = FACTORY_CONTROLLER_ID;
9
+ #remote;
10
+ #modes = [];
11
+ #models;
12
+ constructor(address, remote) {
13
+ this.#remote = remote ?? createFactoryClient(address).getAgentController("code");
14
+ }
15
+ /** Load the mode list; `listModes()` is synchronous so it must be primed. */
16
+ async connect() {
17
+ this.#modes = await this.#remote.listModes();
18
+ }
19
+ listModes() {
20
+ return this.#modes;
21
+ }
22
+ listAvailableModels() {
23
+ this.#models ??= this.#remote.listModels().then((models) => models);
24
+ this.#models.catch(() => this.#models = void 0);
25
+ return this.#models;
26
+ }
27
+ invalidateAvailableModelsCache() {
28
+ this.#models = void 0;
29
+ }
30
+ /** Auth is the Factory's: report what it reports, or assume ok and let the run surface errors. */
31
+ async getCurrentModelAuthStatus(session) {
32
+ const modelId = session.model.get();
33
+ const model = (await this.listAvailableModels().catch(() => [])).find((m) => m.id === modelId);
34
+ return model ? {
35
+ hasAuth: model.hasApiKey,
36
+ apiKeyEnvVar: model.apiKeyEnvVar
37
+ } : { hasAuth: true };
38
+ }
39
+ };
40
+ export { RemoteController };
@@ -0,0 +1,210 @@
1
+ import type { AgentControllerModeInfo } from '@mastra/client-js';
2
+ import type { AgentControllerDisplayState, AgentControllerEventListener, AgentControllerRequestStateUpdater, AgentControllerThread, PermissionRules, Session } from '@mastra/core/agent-controller';
3
+ import type { FactoryAddress } from './client.js';
4
+ import { createFactoryClient } from './client.js';
5
+ type RemoteHandle = ReturnType<ReturnType<ReturnType<typeof createFactoryClient>['getAgentController']>['session']>;
6
+ type RemoteMode = AgentControllerModeInfo;
7
+ type Files = Array<{
8
+ data: string;
9
+ mediaType: string;
10
+ filename?: string;
11
+ }>;
12
+ /**
13
+ * Stands in for an in-process `Session` while the agent, tools, and storage
14
+ * run inside a Factory. Reads are served from state mirrored off the session's
15
+ * event stream; every action is forwarded to the Factory over HTTP.
16
+ *
17
+ * Only the surface the TUI drives is implemented. Anything else resolves to a
18
+ * no-op so local-only features (thread locks, grants) degrade instead of crash.
19
+ */
20
+ export declare class RemoteSession {
21
+ #private;
22
+ constructor(address: FactoryAddress, sessionId: string, remote?: RemoteHandle);
23
+ /** Create/resume the remote session, hydrate the mirror, and open the event stream. */
24
+ connect(): Promise<void>;
25
+ /** Modes come from the controller; used to resolve the current mode's name and color. */
26
+ setModes(modes: RemoteMode[]): void;
27
+ disconnect(): void;
28
+ subscribe(listener: AgentControllerEventListener): () => void;
29
+ onBeforeAgentEnd(): () => void;
30
+ readonly identity: {
31
+ getResourceId: () => string;
32
+ getDefaultResourceId: () => string;
33
+ getId: () => string;
34
+ getOwnerId: () => string;
35
+ setResourceId: () => void;
36
+ };
37
+ readonly thread: {
38
+ getId: () => string | null;
39
+ isSet: () => boolean;
40
+ requireId: () => string;
41
+ ensureId: () => Promise<string>;
42
+ list: () => Promise<AgentControllerThread[]>;
43
+ getById: ({ threadId }: {
44
+ threadId: string;
45
+ }) => Promise<AgentControllerThread | null>;
46
+ create: ({ title }?: {
47
+ title?: string;
48
+ }) => Promise<AgentControllerThread>;
49
+ switch: ({ threadId }: {
50
+ threadId: string;
51
+ }) => Promise<void>;
52
+ clone: ({ sourceThreadId, title }?: {
53
+ sourceThreadId?: string;
54
+ title?: string;
55
+ }) => Promise<AgentControllerThread>;
56
+ rename: ({ title }: {
57
+ title: string;
58
+ }) => Promise<void>;
59
+ delete: ({ threadId }: {
60
+ threadId: string;
61
+ }) => Promise<void>;
62
+ listMessages: ({ threadId, limit }: {
63
+ threadId: string;
64
+ limit?: number;
65
+ }) => Promise<import("@mastra/client-js").MastraDBMessage[]>;
66
+ listActiveMessages: ({ limit }?: {
67
+ limit?: number;
68
+ }) => Promise<never[] | import("@mastra/client-js").MastraDBMessage[]>;
69
+ firstUserMessage: () => Promise<null>;
70
+ firstUserMessages: () => Promise<Map<any, any>>;
71
+ getSetting: () => Promise<undefined>;
72
+ getSettingOn: () => Promise<undefined>;
73
+ setSetting: () => Promise<void>;
74
+ setSettingOn: () => Promise<void>;
75
+ deleteSetting: () => Promise<void>;
76
+ cleanupSubscription: () => void;
77
+ detachFromCurrent: () => void;
78
+ clear: () => void;
79
+ clearAndReleaseLock: () => Promise<void>;
80
+ cloneToCurrentResource: ({ sourceThreadId }: {
81
+ sourceThreadId: string;
82
+ }) => Promise<AgentControllerThread>;
83
+ loadMetadata: () => Promise<void>;
84
+ };
85
+ readonly mode: {
86
+ get: () => string;
87
+ hasSelection: () => boolean;
88
+ resolve: () => {
89
+ id: string;
90
+ name?: string | undefined;
91
+ };
92
+ set: ({ modeId }: {
93
+ modeId: string;
94
+ }) => void;
95
+ switch: ({ modeId }: {
96
+ modeId: string;
97
+ }) => Promise<void>;
98
+ };
99
+ readonly model: {
100
+ get: () => string;
101
+ hasSelection: () => boolean;
102
+ displayName: () => string;
103
+ set: ({ modelId }: {
104
+ modelId: string;
105
+ }) => void;
106
+ switch: (modelId: string, options?: {
107
+ thinkingLevel?: any;
108
+ }) => Promise<void>;
109
+ syncFromPersisted: () => Promise<void>;
110
+ };
111
+ readonly state: {
112
+ get: () => Record<string, unknown>;
113
+ set: (updates: Record<string, unknown>) => Promise<void>;
114
+ setIf: (updates: Record<string, unknown>, shouldApply: () => boolean) => Promise<boolean>;
115
+ update: <TResult>(updater: AgentControllerRequestStateUpdater<any, TResult>) => Promise<TResult>;
116
+ };
117
+ readonly displayState: {
118
+ get: () => AgentControllerDisplayState;
119
+ clearModifiedFiles: () => void;
120
+ restoreTasks: () => void;
121
+ clearPendingSuspensions: () => void;
122
+ deletePendingSuspension: () => void;
123
+ clearPendingApprovals: () => void;
124
+ resetThread: () => void;
125
+ apply: () => void;
126
+ };
127
+ readonly run: {
128
+ isRunning: () => boolean;
129
+ getRunId: () => null;
130
+ getTraceId: () => null;
131
+ };
132
+ readonly stream: {
133
+ isActive: () => boolean;
134
+ isOpen: () => boolean;
135
+ };
136
+ readonly suspensions: {
137
+ hasPending: () => boolean;
138
+ get: ({ toolCallId }: {
139
+ toolCallId: string;
140
+ }) => {
141
+ toolCallId: string;
142
+ toolName: string;
143
+ args: unknown;
144
+ suspendPayload: unknown;
145
+ resumeSchema?: string;
146
+ resourceId?: string;
147
+ threadId?: string;
148
+ runId?: string;
149
+ } | undefined;
150
+ has: ({ toolCallId }: {
151
+ toolCallId: string;
152
+ }) => boolean;
153
+ delete: () => void;
154
+ };
155
+ readonly permissions: {
156
+ getRules: () => PermissionRules;
157
+ setForCategory: ({ category, policy }: {
158
+ category: any;
159
+ policy: any;
160
+ }) => Promise<void>;
161
+ setForTool: ({ toolName, policy }: {
162
+ toolName: string;
163
+ policy: any;
164
+ }) => Promise<void>;
165
+ };
166
+ getCurrentRunId(): string | null;
167
+ getTags(): Record<string, string>;
168
+ getTokenUsage(): import("@mastra/core/harness").TokenUsage;
169
+ getGrants(): {
170
+ categories: never[];
171
+ tools: never[];
172
+ };
173
+ sendMessage({ content, files }: {
174
+ content: string;
175
+ files?: Files;
176
+ }): Promise<void>;
177
+ queueMessage({ content }: {
178
+ content: string;
179
+ }): Promise<void>;
180
+ sendSignal(input: Parameters<Session['sendSignal']>[0]): {
181
+ id: `${string}-${string}-${string}-${string}-${string}`;
182
+ type: 'user';
183
+ accepted: Promise<{
184
+ accepted: true;
185
+ }>;
186
+ persisted: Promise<void>;
187
+ };
188
+ steer({ content }: {
189
+ content: string;
190
+ }): Promise<void>;
191
+ followUp({ content }: {
192
+ content: string;
193
+ }): Promise<void>;
194
+ respondToToolApproval({ decision, toolCallId, }: {
195
+ decision: 'approve' | 'decline' | 'always_allow_category';
196
+ toolCallId: string;
197
+ }): {
198
+ accepted: true;
199
+ };
200
+ respondToToolSuspension({ resumeData, toolCallId }: {
201
+ resumeData: unknown;
202
+ toolCallId?: string;
203
+ }): Promise<void>;
204
+ claimToolResponse(): boolean;
205
+ releaseToolResponse(): void;
206
+ abort(): void;
207
+ abortRun(): void;
208
+ }
209
+ export {};
210
+ //# sourceMappingURL=remote-session.d.ts.map
@@ -0,0 +1,415 @@
1
+ import { createFactoryClient } from "./client.js";
2
+ import { randomUUID } from "crypto";
3
+ import { defaultDisplayState } from "@mastra/core/agent-controller";
4
+ // src/factory/remote-session.ts
5
+ const MAP_FIELDS = [
6
+ "activeTools",
7
+ "toolInputBuffers",
8
+ "pendingSuspensions",
9
+ "pendingApprovals",
10
+ "activeSubagents",
11
+ "modifiedFiles"
12
+ ];
13
+ /** The wire flattens the display state's Maps to objects; restore them. */
14
+ function hydrateDisplayState(wire) {
15
+ const state = {
16
+ ...defaultDisplayState(),
17
+ ...wire
18
+ };
19
+ for (const field of MAP_FIELDS) {
20
+ const value = wire[field];
21
+ state[field] = value instanceof Map ? value : new Map(Object.entries(value ?? {}));
22
+ }
23
+ return state;
24
+ }
25
+ /** The wire flattens errors to `{ name, message }`; restore them. */
26
+ function hydrateEvent(event) {
27
+ const out = { ...event };
28
+ if (out.displayState && typeof out.displayState === "object") out.displayState = hydrateDisplayState(out.displayState);
29
+ const error = out.error;
30
+ if (error && typeof error === "object" && !(error instanceof Error)) out.error = Object.assign(new Error(error.message ?? "Remote error"), { name: error.name ?? "Error" });
31
+ return out;
32
+ }
33
+ function toThread(thread, resourceId) {
34
+ const date = (value) => value ? new Date(value) : /* @__PURE__ */ new Date();
35
+ return {
36
+ id: thread.id,
37
+ resourceId: thread.resourceId ?? resourceId,
38
+ title: thread.title ?? "",
39
+ createdAt: date(thread.createdAt),
40
+ updatedAt: date(thread.updatedAt)
41
+ };
42
+ }
43
+ /**
44
+ * Stands in for an in-process `Session` while the agent, tools, and storage
45
+ * run inside a Factory. Reads are served from state mirrored off the session's
46
+ * event stream; every action is forwarded to the Factory over HTTP.
47
+ *
48
+ * Only the surface the TUI drives is implemented. Anything else resolves to a
49
+ * no-op so local-only features (thread locks, grants) degrade instead of crash.
50
+ */
51
+ var RemoteSession = class {
52
+ #remote;
53
+ #sessionId;
54
+ /** Whose threads and memory the session works on; the Factory reports it when the session is created. */
55
+ #resourceId;
56
+ #listeners = /* @__PURE__ */ new Set();
57
+ #unsubscribe;
58
+ #threadId = null;
59
+ #modeId = "";
60
+ #modelId = "";
61
+ #running = false;
62
+ #state = {};
63
+ #displayState = defaultDisplayState();
64
+ #modes = [];
65
+ #permissionRules = {
66
+ categories: {},
67
+ tools: {}
68
+ };
69
+ #pendingUserIds = [];
70
+ #userIdMap = /* @__PURE__ */ new Map();
71
+ constructor(address, sessionId, remote) {
72
+ this.#sessionId = sessionId;
73
+ this.#resourceId = sessionId;
74
+ this.#remote = remote ?? createFactoryClient(address).getAgentController("code").session(sessionId);
75
+ }
76
+ /** Create/resume the remote session, hydrate the mirror, and open the event stream. */
77
+ async connect() {
78
+ const created = await this.#remote.create();
79
+ if (created?.resourceId) this.#resourceId = created.resourceId;
80
+ await Promise.all([this.#hydrate(), this.#refreshPermissions()]);
81
+ const subscription = await this.#remote.subscribe({
82
+ reconnect: true,
83
+ onEvent: (event) => this.#receive(hydrateEvent(event)),
84
+ onReconnect: () => void this.#hydrate().catch(() => {})
85
+ });
86
+ this.#unsubscribe = subscription.unsubscribe;
87
+ }
88
+ /** Modes come from the controller; used to resolve the current mode's name and color. */
89
+ setModes(modes) {
90
+ this.#modes = modes;
91
+ }
92
+ disconnect() {
93
+ this.#unsubscribe?.();
94
+ this.#unsubscribe = void 0;
95
+ }
96
+ async #hydrate() {
97
+ const snapshot = await this.#remote.state();
98
+ this.#threadId = snapshot.threadId ?? null;
99
+ this.#modeId = snapshot.modeId;
100
+ this.#modelId = snapshot.modelId;
101
+ this.#running = Boolean(snapshot.running);
102
+ if (snapshot.settings) this.#state = {
103
+ ...this.#state,
104
+ ...snapshot.settings
105
+ };
106
+ this.#displayState = {
107
+ ...this.#displayState,
108
+ ...snapshot.tasks ? { tasks: snapshot.tasks } : {},
109
+ ...snapshot.tokenUsage ? { tokenUsage: snapshot.tokenUsage } : {}
110
+ };
111
+ }
112
+ async #refreshPermissions() {
113
+ const rules = await this.#remote.getPermissions();
114
+ this.#permissionRules = {
115
+ categories: rules.categories ?? {},
116
+ tools: rules.tools ?? {}
117
+ };
118
+ }
119
+ /** Surface a failed remote command in the transcript instead of dropping it. */
120
+ #emitError(message) {
121
+ this.#receive({
122
+ type: "error",
123
+ error: new Error(message)
124
+ });
125
+ }
126
+ /**
127
+ * The TUI renders a user message as soon as it is sent, keyed by the id
128
+ * `sendSignal` returned. The Factory echoes it back under its own id, so map
129
+ * that echo onto the local id to keep it from rendering twice.
130
+ */
131
+ #adoptLocalUserId(e) {
132
+ const message = e.message;
133
+ const isUser = message?.role === "user" || message?.role === "signal" && message.content?.metadata?.signal?.type === "user";
134
+ if (!message?.id || !isUser) return;
135
+ let localId = this.#userIdMap.get(message.id);
136
+ if (!localId && e.type === "message_start") {
137
+ localId = this.#pendingUserIds.shift();
138
+ if (localId) this.#userIdMap.set(message.id, localId);
139
+ }
140
+ if (localId) e.message = {
141
+ ...message,
142
+ id: localId
143
+ };
144
+ }
145
+ #receive(event) {
146
+ const e = event;
147
+ if (e.type === "message_start" || e.type === "message_update" || e.type === "message_end") this.#adoptLocalUserId(e);
148
+ switch (e.type) {
149
+ case "mode_changed":
150
+ this.#modeId = e.modeId;
151
+ break;
152
+ case "model_changed":
153
+ this.#modelId = e.modelId;
154
+ break;
155
+ case "thread_changed":
156
+ this.#threadId = e.threadId;
157
+ break;
158
+ case "thread_created":
159
+ this.#threadId = e.thread.id;
160
+ break;
161
+ case "state_changed":
162
+ this.#state = {
163
+ ...this.#state,
164
+ ...e.state
165
+ };
166
+ break;
167
+ case "display_state_changed":
168
+ this.#displayState = e.displayState;
169
+ break;
170
+ case "agent_start":
171
+ this.#running = true;
172
+ break;
173
+ case "agent_end": this.#running = false;
174
+ }
175
+ for (const listener of this.#listeners) Promise.resolve(listener(event)).catch(() => {});
176
+ }
177
+ subscribe(listener) {
178
+ this.#listeners.add(listener);
179
+ return () => this.#listeners.delete(listener);
180
+ }
181
+ onBeforeAgentEnd() {
182
+ return () => {};
183
+ }
184
+ identity = {
185
+ getResourceId: () => this.#resourceId,
186
+ getDefaultResourceId: () => this.#resourceId,
187
+ getId: () => this.#sessionId,
188
+ getOwnerId: () => this.#sessionId,
189
+ setResourceId: () => {}
190
+ };
191
+ thread = (() => {
192
+ const remote = () => this.#remote;
193
+ const resourceId = () => this.#resourceId;
194
+ return {
195
+ getId: () => this.#threadId,
196
+ isSet: () => this.#threadId !== null,
197
+ requireId: () => {
198
+ if (!this.#threadId) throw new Error("No active thread");
199
+ return this.#threadId;
200
+ },
201
+ ensureId: async () => {
202
+ if (!this.#threadId) await this.thread.create();
203
+ return this.#threadId;
204
+ },
205
+ list: async () => (await remote().listThreads()).map((t) => toThread(t, resourceId())),
206
+ getById: async ({ threadId }) => (await this.thread.list()).find((t) => t.id === threadId) ?? null,
207
+ create: async ({ title } = {}) => {
208
+ const thread = toThread(await remote().createThread(title), resourceId());
209
+ this.#threadId = thread.id;
210
+ return thread;
211
+ },
212
+ switch: async ({ threadId }) => {
213
+ await remote().switchThread(threadId);
214
+ this.#threadId = threadId;
215
+ },
216
+ clone: async ({ sourceThreadId, title } = {}) => {
217
+ const thread = toThread(await remote().cloneThread({
218
+ sourceThreadId,
219
+ title
220
+ }), resourceId());
221
+ this.#threadId = thread.id;
222
+ return thread;
223
+ },
224
+ rename: async ({ title }) => {
225
+ if (this.#threadId) await remote().renameThread(this.#threadId, title);
226
+ },
227
+ delete: async ({ threadId }) => {
228
+ await remote().deleteThread(threadId);
229
+ if (this.#threadId === threadId) this.#threadId = null;
230
+ },
231
+ listMessages: ({ threadId, limit }) => remote().listMessages(threadId, limit),
232
+ listActiveMessages: async ({ limit } = {}) => this.#threadId ? remote().listMessages(this.#threadId, limit) : [],
233
+ firstUserMessage: async () => null,
234
+ firstUserMessages: async () => /* @__PURE__ */ new Map(),
235
+ getSetting: async () => void 0,
236
+ getSettingOn: async () => void 0,
237
+ setSetting: async () => {},
238
+ setSettingOn: async () => {},
239
+ deleteSetting: async () => {},
240
+ cleanupSubscription: () => {},
241
+ detachFromCurrent: () => {},
242
+ clear: () => {
243
+ this.#threadId = null;
244
+ },
245
+ clearAndReleaseLock: async () => {},
246
+ cloneToCurrentResource: async ({ sourceThreadId }) => this.thread.clone({ sourceThreadId }),
247
+ loadMetadata: async () => {}
248
+ };
249
+ })();
250
+ mode = {
251
+ get: () => this.#modeId,
252
+ hasSelection: () => Boolean(this.#modeId),
253
+ resolve: () => this.#modes.find((mode) => mode.id === this.#modeId) ?? {
254
+ id: this.#modeId,
255
+ name: this.#modeId
256
+ },
257
+ set: ({ modeId }) => {
258
+ this.#modeId = modeId;
259
+ },
260
+ switch: async ({ modeId }) => {
261
+ await this.#remote.switchMode(modeId);
262
+ this.#modeId = modeId;
263
+ }
264
+ };
265
+ model = {
266
+ get: () => this.#modelId,
267
+ hasSelection: () => Boolean(this.#modelId),
268
+ displayName: () => this.#modelId,
269
+ set: ({ modelId }) => {
270
+ this.#modelId = modelId;
271
+ },
272
+ switch: async (modelId, options = {}) => {
273
+ await this.#remote.switchModel(modelId, options);
274
+ this.#modelId = modelId;
275
+ },
276
+ syncFromPersisted: async () => {}
277
+ };
278
+ state = {
279
+ get: () => this.#state,
280
+ set: async (updates) => {
281
+ this.#state = {
282
+ ...this.#state,
283
+ ...updates
284
+ };
285
+ await this.#remote.setState(updates);
286
+ },
287
+ setIf: async (updates, shouldApply) => {
288
+ if (!shouldApply()) return false;
289
+ await this.state.set(updates);
290
+ return true;
291
+ },
292
+ update: async (updater) => {
293
+ const { updates, result } = await updater(this.#state);
294
+ if (updates) await this.state.set(updates);
295
+ return result;
296
+ }
297
+ };
298
+ displayState = {
299
+ get: () => this.#displayState,
300
+ clearModifiedFiles: () => {
301
+ this.#displayState = {
302
+ ...this.#displayState,
303
+ modifiedFiles: /* @__PURE__ */ new Map()
304
+ };
305
+ },
306
+ restoreTasks: () => {},
307
+ clearPendingSuspensions: () => {},
308
+ deletePendingSuspension: () => {},
309
+ clearPendingApprovals: () => {},
310
+ resetThread: () => {},
311
+ apply: () => {}
312
+ };
313
+ run = {
314
+ isRunning: () => this.#running,
315
+ getRunId: () => null,
316
+ getTraceId: () => null
317
+ };
318
+ stream = {
319
+ isActive: () => this.#running,
320
+ isOpen: () => this.#running
321
+ };
322
+ suspensions = {
323
+ hasPending: () => this.#displayState.pendingSuspensions.size > 0,
324
+ get: ({ toolCallId }) => this.#displayState.pendingSuspensions.get(toolCallId),
325
+ has: ({ toolCallId }) => this.#displayState.pendingSuspensions.has(toolCallId),
326
+ delete: () => {}
327
+ };
328
+ permissions = {
329
+ getRules: () => this.#permissionRules,
330
+ setForCategory: async ({ category, policy }) => {
331
+ await this.#remote.setPermissionForCategory(category, policy);
332
+ await this.#refreshPermissions();
333
+ },
334
+ setForTool: async ({ toolName, policy }) => {
335
+ await this.#remote.setPermissionForTool(toolName, policy);
336
+ await this.#refreshPermissions();
337
+ }
338
+ };
339
+ getCurrentRunId() {
340
+ return null;
341
+ }
342
+ getTags() {
343
+ return {};
344
+ }
345
+ getTokenUsage() {
346
+ return this.#displayState.tokenUsage;
347
+ }
348
+ getGrants() {
349
+ return {
350
+ categories: [],
351
+ tools: []
352
+ };
353
+ }
354
+ async sendMessage({ content, files }) {
355
+ await this.#remote.sendMessage({
356
+ content,
357
+ files
358
+ });
359
+ }
360
+ async queueMessage({ content }) {
361
+ await this.#remote.followUp(content);
362
+ }
363
+ sendSignal(input) {
364
+ const content = "content" in input ? input.content : void 0;
365
+ const text = typeof content === "string" ? content : Array.isArray(content) ? content.map((part) => typeof part === "string" ? part : part?.text ?? "").join("") : JSON.stringify(content);
366
+ const files = "files" in input ? input.files : void 0;
367
+ const message = files?.length ? {
368
+ content: text,
369
+ files
370
+ } : text;
371
+ const id = randomUUID();
372
+ this.#pendingUserIds.push(id);
373
+ const sent = this.#running ? this.#remote.followUp(message) : this.#remote.sendMessage(message);
374
+ sent.catch(() => {
375
+ this.#pendingUserIds = this.#pendingUserIds.filter((pending) => pending !== id);
376
+ });
377
+ const accepted = sent.then(() => ({ accepted: true }));
378
+ accepted.catch(() => {});
379
+ return {
380
+ id,
381
+ type: "user",
382
+ accepted,
383
+ persisted: sent
384
+ };
385
+ }
386
+ async steer({ content }) {
387
+ await this.#remote.steer(content);
388
+ }
389
+ async followUp({ content }) {
390
+ await this.#remote.followUp(content);
391
+ }
392
+ respondToToolApproval({ decision, toolCallId }) {
393
+ (async () => {
394
+ const ack = await this.#remote.approveTool(toolCallId, decision !== "decline", { alwaysAllowCategory: decision === "always_allow_category" });
395
+ if (ack && "accepted" in ack && ack.accepted === false) this.#emitError(`Tool approval was not applied: ${ack.reason ?? "rejected"}`);
396
+ })().catch((error) => this.#emitError(`Tool approval failed: ${error instanceof Error ? error.message : String(error)}`));
397
+ return { accepted: true };
398
+ }
399
+ async respondToToolSuspension({ resumeData, toolCallId }) {
400
+ const id = toolCallId ?? this.#displayState.pendingSuspensions.keys().next().value;
401
+ if (!id) throw new Error("No pending tool suspension to respond to");
402
+ await this.#remote.respondToToolSuspension(id, resumeData);
403
+ }
404
+ claimToolResponse() {
405
+ return true;
406
+ }
407
+ releaseToolResponse() {}
408
+ abort() {
409
+ this.#remote.abort().catch((error) => this.#emitError(`Abort failed: ${error instanceof Error ? error.message : String(error)}`));
410
+ }
411
+ abortRun() {
412
+ this.abort();
413
+ }
414
+ };
415
+ export { RemoteSession };