@agent-native/core 0.15.13 → 0.16.0

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 (411) hide show
  1. package/README.md +37 -0
  2. package/dist/agent/app-model-defaults.d.ts +37 -0
  3. package/dist/agent/app-model-defaults.d.ts.map +1 -0
  4. package/dist/agent/app-model-defaults.js +136 -0
  5. package/dist/agent/app-model-defaults.js.map +1 -0
  6. package/dist/agent/engine/registry.d.ts +12 -7
  7. package/dist/agent/engine/registry.d.ts.map +1 -1
  8. package/dist/agent/engine/registry.js +28 -8
  9. package/dist/agent/engine/registry.js.map +1 -1
  10. package/dist/agent/production-agent.d.ts +2 -0
  11. package/dist/agent/production-agent.d.ts.map +1 -1
  12. package/dist/agent/production-agent.js +3 -1
  13. package/dist/agent/production-agent.js.map +1 -1
  14. package/dist/browser-sessions/actions.d.ts +7 -0
  15. package/dist/browser-sessions/actions.d.ts.map +1 -0
  16. package/dist/browser-sessions/actions.js +223 -0
  17. package/dist/browser-sessions/actions.js.map +1 -0
  18. package/dist/browser-sessions/routes.d.ts +7 -0
  19. package/dist/browser-sessions/routes.d.ts.map +1 -0
  20. package/dist/browser-sessions/routes.js +159 -0
  21. package/dist/browser-sessions/routes.js.map +1 -0
  22. package/dist/browser-sessions/store.d.ts +33 -0
  23. package/dist/browser-sessions/store.d.ts.map +1 -0
  24. package/dist/browser-sessions/store.js +506 -0
  25. package/dist/browser-sessions/store.js.map +1 -0
  26. package/dist/browser-sessions/types.d.ts +68 -0
  27. package/dist/browser-sessions/types.d.ts.map +1 -0
  28. package/dist/browser-sessions/types.js +2 -0
  29. package/dist/browser-sessions/types.js.map +1 -0
  30. package/dist/cli/code-agent-commands.d.ts +36 -0
  31. package/dist/cli/code-agent-commands.d.ts.map +1 -0
  32. package/dist/cli/code-agent-commands.js +192 -0
  33. package/dist/cli/code-agent-commands.js.map +1 -0
  34. package/dist/cli/code-agent-connector.d.ts +17 -0
  35. package/dist/cli/code-agent-connector.d.ts.map +1 -0
  36. package/dist/cli/code-agent-connector.js +724 -0
  37. package/dist/cli/code-agent-connector.js.map +1 -0
  38. package/dist/cli/code-agent-executor.d.ts +31 -0
  39. package/dist/cli/code-agent-executor.d.ts.map +1 -0
  40. package/dist/cli/code-agent-executor.js +921 -0
  41. package/dist/cli/code-agent-executor.js.map +1 -0
  42. package/dist/cli/code-agent-runs.d.ts +102 -0
  43. package/dist/cli/code-agent-runs.d.ts.map +1 -0
  44. package/dist/cli/code-agent-runs.js +277 -0
  45. package/dist/cli/code-agent-runs.js.map +1 -0
  46. package/dist/cli/code.d.ts +66 -0
  47. package/dist/cli/code.d.ts.map +1 -0
  48. package/dist/cli/code.js +1306 -0
  49. package/dist/cli/code.js.map +1 -0
  50. package/dist/cli/create.d.ts +2 -1
  51. package/dist/cli/create.d.ts.map +1 -1
  52. package/dist/cli/create.js +11 -1
  53. package/dist/cli/create.js.map +1 -1
  54. package/dist/cli/index.js +26 -1
  55. package/dist/cli/index.js.map +1 -1
  56. package/dist/cli/migrate.d.ts +27 -0
  57. package/dist/cli/migrate.d.ts.map +1 -1
  58. package/dist/cli/migrate.js +1328 -20
  59. package/dist/cli/migrate.js.map +1 -1
  60. package/dist/cli/templates-meta.d.ts.map +1 -1
  61. package/dist/cli/templates-meta.js +26 -2
  62. package/dist/cli/templates-meta.js.map +1 -1
  63. package/dist/cli/workspacify.d.ts +2 -0
  64. package/dist/cli/workspacify.d.ts.map +1 -1
  65. package/dist/cli/workspacify.js +2 -1
  66. package/dist/cli/workspacify.js.map +1 -1
  67. package/dist/client/AgentNative.d.ts +32 -0
  68. package/dist/client/AgentNative.d.ts.map +1 -0
  69. package/dist/client/AgentNative.js +79 -0
  70. package/dist/client/AgentNative.js.map +1 -0
  71. package/dist/client/AgentNativeEmbedded.d.ts +47 -0
  72. package/dist/client/AgentNativeEmbedded.d.ts.map +1 -0
  73. package/dist/client/AgentNativeEmbedded.js +148 -0
  74. package/dist/client/AgentNativeEmbedded.js.map +1 -0
  75. package/dist/client/AgentNativeFrame.d.ts +25 -0
  76. package/dist/client/AgentNativeFrame.d.ts.map +1 -0
  77. package/dist/client/AgentNativeFrame.js +68 -0
  78. package/dist/client/AgentNativeFrame.js.map +1 -0
  79. package/dist/client/AgentPanel.d.ts +19 -2
  80. package/dist/client/AgentPanel.d.ts.map +1 -1
  81. package/dist/client/AgentPanel.js +15 -4
  82. package/dist/client/AgentPanel.js.map +1 -1
  83. package/dist/client/AssistantChat.d.ts +1 -1
  84. package/dist/client/AssistantChat.d.ts.map +1 -1
  85. package/dist/client/AssistantChat.js +79 -48
  86. package/dist/client/AssistantChat.js.map +1 -1
  87. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  88. package/dist/client/MultiTabAssistantChat.js +2 -1
  89. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  90. package/dist/client/NewWorkspaceAppFlow.d.ts.map +1 -1
  91. package/dist/client/NewWorkspaceAppFlow.js +3 -2
  92. package/dist/client/NewWorkspaceAppFlow.js.map +1 -1
  93. package/dist/client/browser-session-bridge.d.ts +44 -0
  94. package/dist/client/browser-session-bridge.d.ts.map +1 -0
  95. package/dist/client/browser-session-bridge.js +339 -0
  96. package/dist/client/browser-session-bridge.js.map +1 -0
  97. package/dist/client/client-action.d.ts +7 -0
  98. package/dist/client/client-action.d.ts.map +1 -0
  99. package/dist/client/client-action.js +4 -0
  100. package/dist/client/client-action.js.map +1 -0
  101. package/dist/client/components/ui/tooltip.d.ts.map +1 -1
  102. package/dist/client/components/ui/tooltip.js +1 -1
  103. package/dist/client/components/ui/tooltip.js.map +1 -1
  104. package/dist/client/composer/AgentComposerFrame.d.ts +17 -0
  105. package/dist/client/composer/AgentComposerFrame.d.ts.map +1 -0
  106. package/dist/client/composer/AgentComposerFrame.js +14 -0
  107. package/dist/client/composer/AgentComposerFrame.js.map +1 -0
  108. package/dist/client/composer/MentionPopover.d.ts.map +1 -1
  109. package/dist/client/composer/MentionPopover.js +2 -2
  110. package/dist/client/composer/MentionPopover.js.map +1 -1
  111. package/dist/client/composer/PromptComposer.d.ts +35 -2
  112. package/dist/client/composer/PromptComposer.d.ts.map +1 -1
  113. package/dist/client/composer/PromptComposer.js +31 -17
  114. package/dist/client/composer/PromptComposer.js.map +1 -1
  115. package/dist/client/composer/TiptapComposer.d.ts +20 -2
  116. package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
  117. package/dist/client/composer/TiptapComposer.js +112 -22
  118. package/dist/client/composer/TiptapComposer.js.map +1 -1
  119. package/dist/client/composer/index.d.ts +3 -2
  120. package/dist/client/composer/index.d.ts.map +1 -1
  121. package/dist/client/composer/index.js +1 -0
  122. package/dist/client/composer/index.js.map +1 -1
  123. package/dist/client/composer/types.d.ts +1 -0
  124. package/dist/client/composer/types.d.ts.map +1 -1
  125. package/dist/client/composer/types.js.map +1 -1
  126. package/dist/client/extensions/AgentNativeExtensionFrame.d.ts +58 -0
  127. package/dist/client/extensions/AgentNativeExtensionFrame.d.ts.map +1 -0
  128. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.d.ts +2 -0
  129. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.d.ts.map +1 -0
  130. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.js +110 -0
  131. package/dist/client/extensions/AgentNativeExtensionFrame.e2e-host.js.map +1 -0
  132. package/dist/client/extensions/AgentNativeExtensionFrame.js +354 -0
  133. package/dist/client/extensions/AgentNativeExtensionFrame.js.map +1 -0
  134. package/dist/client/extensions/AgentNativeExtensionFrame.spec.d.ts +2 -0
  135. package/dist/client/extensions/AgentNativeExtensionFrame.spec.d.ts.map +1 -0
  136. package/dist/client/extensions/AgentNativeExtensionFrame.spec.js +68 -0
  137. package/dist/client/extensions/AgentNativeExtensionFrame.spec.js.map +1 -0
  138. package/dist/client/extensions/agent-native-extension-runtime.d.ts +69 -0
  139. package/dist/client/extensions/agent-native-extension-runtime.d.ts.map +1 -0
  140. package/dist/client/extensions/agent-native-extension-runtime.js +348 -0
  141. package/dist/client/extensions/agent-native-extension-runtime.js.map +1 -0
  142. package/dist/client/extensions/index.d.ts +2 -0
  143. package/dist/client/extensions/index.d.ts.map +1 -1
  144. package/dist/client/extensions/index.js +2 -0
  145. package/dist/client/extensions/index.js.map +1 -1
  146. package/dist/client/extensions/portable-extension.d.ts +86 -0
  147. package/dist/client/extensions/portable-extension.d.ts.map +1 -0
  148. package/dist/client/extensions/portable-extension.js +480 -0
  149. package/dist/client/extensions/portable-extension.js.map +1 -0
  150. package/dist/client/host-bridge.d.ts +266 -0
  151. package/dist/client/host-bridge.d.ts.map +1 -0
  152. package/dist/client/host-bridge.js +745 -0
  153. package/dist/client/host-bridge.js.map +1 -0
  154. package/dist/client/host-tools.d.ts +40 -0
  155. package/dist/client/host-tools.d.ts.map +1 -0
  156. package/dist/client/host-tools.js +94 -0
  157. package/dist/client/host-tools.js.map +1 -0
  158. package/dist/client/index.d.ts +13 -2
  159. package/dist/client/index.d.ts.map +1 -1
  160. package/dist/client/index.js +11 -2
  161. package/dist/client/index.js.map +1 -1
  162. package/dist/client/resources/BuiltinCapabilityDetail.d.ts +10 -0
  163. package/dist/client/resources/BuiltinCapabilityDetail.d.ts.map +1 -0
  164. package/dist/client/resources/BuiltinCapabilityDetail.js +51 -0
  165. package/dist/client/resources/BuiltinCapabilityDetail.js.map +1 -0
  166. package/dist/client/resources/ResourceEditor.d.ts +3 -1
  167. package/dist/client/resources/ResourceEditor.d.ts.map +1 -1
  168. package/dist/client/resources/ResourceEditor.js +40 -17
  169. package/dist/client/resources/ResourceEditor.js.map +1 -1
  170. package/dist/client/resources/ResourceTree.d.ts.map +1 -1
  171. package/dist/client/resources/ResourceTree.js +23 -2
  172. package/dist/client/resources/ResourceTree.js.map +1 -1
  173. package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
  174. package/dist/client/resources/ResourcesPanel.js +77 -17
  175. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  176. package/dist/client/resources/index.d.ts +1 -0
  177. package/dist/client/resources/index.d.ts.map +1 -1
  178. package/dist/client/resources/index.js +1 -0
  179. package/dist/client/resources/index.js.map +1 -1
  180. package/dist/client/resources/use-builtin-capabilities.d.ts +62 -0
  181. package/dist/client/resources/use-builtin-capabilities.d.ts.map +1 -0
  182. package/dist/client/resources/use-builtin-capabilities.js +54 -0
  183. package/dist/client/resources/use-builtin-capabilities.js.map +1 -0
  184. package/dist/client/resources/use-resources.d.ts +30 -2
  185. package/dist/client/resources/use-resources.d.ts.map +1 -1
  186. package/dist/client/resources/use-resources.js +42 -1
  187. package/dist/client/resources/use-resources.js.map +1 -1
  188. package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
  189. package/dist/client/settings/SettingsPanel.js +151 -2
  190. package/dist/client/settings/SettingsPanel.js.map +1 -1
  191. package/dist/client/use-chat-models.d.ts.map +1 -1
  192. package/dist/client/use-chat-models.js +20 -0
  193. package/dist/client/use-chat-models.js.map +1 -1
  194. package/dist/client/use-chat-threads.d.ts.map +1 -1
  195. package/dist/client/use-chat-threads.js +46 -2
  196. package/dist/client/use-chat-threads.js.map +1 -1
  197. package/dist/client/use-chat-threads.spec.js +77 -0
  198. package/dist/client/use-chat-threads.spec.js.map +1 -1
  199. package/dist/code-agents/index.d.ts +4 -0
  200. package/dist/code-agents/index.d.ts.map +1 -0
  201. package/dist/code-agents/index.js +4 -0
  202. package/dist/code-agents/index.js.map +1 -0
  203. package/dist/connections/catalog.d.ts +134 -0
  204. package/dist/connections/catalog.d.ts.map +1 -0
  205. package/dist/connections/catalog.js +180 -0
  206. package/dist/connections/catalog.js.map +1 -0
  207. package/dist/connections/index.d.ts +2 -0
  208. package/dist/connections/index.d.ts.map +1 -0
  209. package/dist/connections/index.js +2 -0
  210. package/dist/connections/index.js.map +1 -0
  211. package/dist/extensions/change-marker.d.ts +10 -0
  212. package/dist/extensions/change-marker.d.ts.map +1 -0
  213. package/dist/extensions/change-marker.js +42 -0
  214. package/dist/extensions/change-marker.js.map +1 -0
  215. package/dist/extensions/routes.d.ts.map +1 -1
  216. package/dist/extensions/routes.js +1 -7
  217. package/dist/extensions/routes.js.map +1 -1
  218. package/dist/extensions/schema.d.ts +1 -0
  219. package/dist/extensions/schema.d.ts.map +1 -1
  220. package/dist/extensions/schema.js +1 -0
  221. package/dist/extensions/schema.js.map +1 -1
  222. package/dist/extensions/slots/routes.js +1 -1
  223. package/dist/extensions/slots/routes.js.map +1 -1
  224. package/dist/extensions/store.d.ts +3 -0
  225. package/dist/extensions/store.d.ts.map +1 -1
  226. package/dist/extensions/store.js +112 -4
  227. package/dist/extensions/store.js.map +1 -1
  228. package/dist/index.d.ts +4 -1
  229. package/dist/index.d.ts.map +1 -1
  230. package/dist/index.js +6 -1
  231. package/dist/index.js.map +1 -1
  232. package/dist/integrations/adapters/telegram.d.ts.map +1 -1
  233. package/dist/integrations/adapters/telegram.js +1 -0
  234. package/dist/integrations/adapters/telegram.js.map +1 -1
  235. package/dist/integrations/index.d.ts +5 -1
  236. package/dist/integrations/index.d.ts.map +1 -1
  237. package/dist/integrations/index.js +4 -1
  238. package/dist/integrations/index.js.map +1 -1
  239. package/dist/integrations/plugin.d.ts +8 -0
  240. package/dist/integrations/plugin.d.ts.map +1 -1
  241. package/dist/integrations/plugin.js +760 -32
  242. package/dist/integrations/plugin.js.map +1 -1
  243. package/dist/integrations/remote-commands-store.d.ts +36 -0
  244. package/dist/integrations/remote-commands-store.d.ts.map +1 -0
  245. package/dist/integrations/remote-commands-store.js +273 -0
  246. package/dist/integrations/remote-commands-store.js.map +1 -0
  247. package/dist/integrations/remote-devices-store.d.ts +43 -0
  248. package/dist/integrations/remote-devices-store.d.ts.map +1 -0
  249. package/dist/integrations/remote-devices-store.js +315 -0
  250. package/dist/integrations/remote-devices-store.js.map +1 -0
  251. package/dist/integrations/remote-push-store.d.ts +37 -0
  252. package/dist/integrations/remote-push-store.d.ts.map +1 -0
  253. package/dist/integrations/remote-push-store.js +299 -0
  254. package/dist/integrations/remote-push-store.js.map +1 -0
  255. package/dist/integrations/remote-retry-job.d.ts +7 -0
  256. package/dist/integrations/remote-retry-job.d.ts.map +1 -0
  257. package/dist/integrations/remote-retry-job.js +45 -0
  258. package/dist/integrations/remote-retry-job.js.map +1 -0
  259. package/dist/integrations/remote-run-events-store.d.ts +18 -0
  260. package/dist/integrations/remote-run-events-store.d.ts.map +1 -0
  261. package/dist/integrations/remote-run-events-store.js +82 -0
  262. package/dist/integrations/remote-run-events-store.js.map +1 -0
  263. package/dist/integrations/remote-types.d.ts +101 -0
  264. package/dist/integrations/remote-types.d.ts.map +1 -0
  265. package/dist/integrations/remote-types.js +2 -0
  266. package/dist/integrations/remote-types.js.map +1 -0
  267. package/dist/integrations/webhook-handler.d.ts +2 -0
  268. package/dist/integrations/webhook-handler.d.ts.map +1 -1
  269. package/dist/integrations/webhook-handler.js +4 -1
  270. package/dist/integrations/webhook-handler.js.map +1 -1
  271. package/dist/jobs/scheduler.d.ts +4 -2
  272. package/dist/jobs/scheduler.d.ts.map +1 -1
  273. package/dist/jobs/scheduler.js +9 -3
  274. package/dist/jobs/scheduler.js.map +1 -1
  275. package/dist/mcp-client/builtin-capabilities.d.ts +20 -0
  276. package/dist/mcp-client/builtin-capabilities.d.ts.map +1 -0
  277. package/dist/mcp-client/builtin-capabilities.js +75 -0
  278. package/dist/mcp-client/builtin-capabilities.js.map +1 -0
  279. package/dist/mcp-client/builtin-store.d.ts +10 -0
  280. package/dist/mcp-client/builtin-store.d.ts.map +1 -0
  281. package/dist/mcp-client/builtin-store.js +55 -0
  282. package/dist/mcp-client/builtin-store.js.map +1 -0
  283. package/dist/mcp-client/index.d.ts +3 -1
  284. package/dist/mcp-client/index.d.ts.map +1 -1
  285. package/dist/mcp-client/index.js +3 -1
  286. package/dist/mcp-client/index.js.map +1 -1
  287. package/dist/mcp-client/routes.d.ts +28 -0
  288. package/dist/mcp-client/routes.d.ts.map +1 -1
  289. package/dist/mcp-client/routes.js +195 -1
  290. package/dist/mcp-client/routes.js.map +1 -1
  291. package/dist/org/context.d.ts.map +1 -1
  292. package/dist/org/context.js +34 -0
  293. package/dist/org/context.js.map +1 -1
  294. package/dist/resources/handlers.d.ts +4 -0
  295. package/dist/resources/handlers.d.ts.map +1 -1
  296. package/dist/resources/handlers.js +46 -7
  297. package/dist/resources/handlers.js.map +1 -1
  298. package/dist/resources/script-helpers.d.ts +8 -1
  299. package/dist/resources/script-helpers.d.ts.map +1 -1
  300. package/dist/resources/script-helpers.js +18 -8
  301. package/dist/resources/script-helpers.js.map +1 -1
  302. package/dist/resources/store.d.ts +19 -0
  303. package/dist/resources/store.d.ts.map +1 -1
  304. package/dist/resources/store.js +86 -3
  305. package/dist/resources/store.js.map +1 -1
  306. package/dist/scripts/agent-engines/list-agent-engines.d.ts +1 -1
  307. package/dist/scripts/agent-engines/list-agent-engines.d.ts.map +1 -1
  308. package/dist/scripts/agent-engines/list-agent-engines.js +18 -7
  309. package/dist/scripts/agent-engines/list-agent-engines.js.map +1 -1
  310. package/dist/scripts/agent-engines/manage-agent-engine.d.ts.map +1 -1
  311. package/dist/scripts/agent-engines/manage-agent-engine.js +100 -7
  312. package/dist/scripts/agent-engines/manage-agent-engine.js.map +1 -1
  313. package/dist/scripts/resources/delete.d.ts.map +1 -1
  314. package/dist/scripts/resources/delete.js +4 -1
  315. package/dist/scripts/resources/delete.js.map +1 -1
  316. package/dist/scripts/resources/effective.d.ts +11 -0
  317. package/dist/scripts/resources/effective.d.ts.map +1 -0
  318. package/dist/scripts/resources/effective.js +54 -0
  319. package/dist/scripts/resources/effective.js.map +1 -0
  320. package/dist/scripts/resources/index.d.ts.map +1 -1
  321. package/dist/scripts/resources/index.js +1 -0
  322. package/dist/scripts/resources/index.js.map +1 -1
  323. package/dist/scripts/resources/list.d.ts +1 -1
  324. package/dist/scripts/resources/list.d.ts.map +1 -1
  325. package/dist/scripts/resources/list.js +17 -5
  326. package/dist/scripts/resources/list.js.map +1 -1
  327. package/dist/scripts/resources/read.d.ts +1 -1
  328. package/dist/scripts/resources/read.d.ts.map +1 -1
  329. package/dist/scripts/resources/read.js +20 -5
  330. package/dist/scripts/resources/read.js.map +1 -1
  331. package/dist/scripts/resources/write.d.ts.map +1 -1
  332. package/dist/scripts/resources/write.js +4 -1
  333. package/dist/scripts/resources/write.js.map +1 -1
  334. package/dist/scripts/runner.d.ts +11 -1
  335. package/dist/scripts/runner.d.ts.map +1 -1
  336. package/dist/scripts/runner.js +75 -27
  337. package/dist/scripts/runner.js.map +1 -1
  338. package/dist/server/action-discovery.d.ts.map +1 -1
  339. package/dist/server/action-discovery.js +5 -0
  340. package/dist/server/action-discovery.js.map +1 -1
  341. package/dist/server/agent-chat-plugin.d.ts +24 -0
  342. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  343. package/dist/server/agent-chat-plugin.js +608 -54
  344. package/dist/server/agent-chat-plugin.js.map +1 -1
  345. package/dist/server/core-routes-plugin.d.ts.map +1 -1
  346. package/dist/server/core-routes-plugin.js +2 -0
  347. package/dist/server/core-routes-plugin.js.map +1 -1
  348. package/dist/server/embedded.d.ts +72 -0
  349. package/dist/server/embedded.d.ts.map +1 -0
  350. package/dist/server/embedded.js +119 -0
  351. package/dist/server/embedded.js.map +1 -0
  352. package/dist/server/index.d.ts +8 -1
  353. package/dist/server/index.d.ts.map +1 -1
  354. package/dist/server/index.js +7 -1
  355. package/dist/server/index.js.map +1 -1
  356. package/dist/server/poll.d.ts.map +1 -1
  357. package/dist/server/poll.js +184 -13
  358. package/dist/server/poll.js.map +1 -1
  359. package/dist/server/resources-plugin.d.ts.map +1 -1
  360. package/dist/server/resources-plugin.js +11 -2
  361. package/dist/server/resources-plugin.js.map +1 -1
  362. package/dist/sharing/actions/extension-change.d.ts +4 -0
  363. package/dist/sharing/actions/extension-change.d.ts.map +1 -0
  364. package/dist/sharing/actions/extension-change.js +13 -0
  365. package/dist/sharing/actions/extension-change.js.map +1 -0
  366. package/dist/sharing/actions/set-resource-visibility.d.ts.map +1 -1
  367. package/dist/sharing/actions/set-resource-visibility.js +3 -0
  368. package/dist/sharing/actions/set-resource-visibility.js.map +1 -1
  369. package/dist/sharing/actions/share-resource.d.ts.map +1 -1
  370. package/dist/sharing/actions/share-resource.js +4 -0
  371. package/dist/sharing/actions/share-resource.js.map +1 -1
  372. package/dist/sharing/actions/unshare-resource.d.ts.map +1 -1
  373. package/dist/sharing/actions/unshare-resource.js +3 -0
  374. package/dist/sharing/actions/unshare-resource.js.map +1 -1
  375. package/dist/templates/default/AGENTS.md +3 -3
  376. package/dist/templates/workspace-core/AGENTS.md +7 -0
  377. package/dist/templates/workspace-root/AGENTS.md +7 -0
  378. package/dist/templates/workspace-root/README.md +25 -0
  379. package/dist/triggers/dispatcher.d.ts +3 -1
  380. package/dist/triggers/dispatcher.d.ts.map +1 -1
  381. package/dist/triggers/dispatcher.js +9 -3
  382. package/dist/triggers/dispatcher.js.map +1 -1
  383. package/dist/workspace-connections/index.d.ts +2 -0
  384. package/dist/workspace-connections/index.d.ts.map +1 -0
  385. package/dist/workspace-connections/index.js +2 -0
  386. package/dist/workspace-connections/index.js.map +1 -0
  387. package/dist/workspace-connections/store.d.ts +229 -0
  388. package/dist/workspace-connections/store.d.ts.map +1 -0
  389. package/dist/workspace-connections/store.js +938 -0
  390. package/dist/workspace-connections/store.js.map +1 -0
  391. package/docs/content/agent-teams.md +6 -0
  392. package/docs/content/cloneable-saas.md +1 -0
  393. package/docs/content/code-agents-ui.md +261 -0
  394. package/docs/content/dispatch.md +40 -3
  395. package/docs/content/embedding-sdk.md +459 -0
  396. package/docs/content/faq.md +1 -0
  397. package/docs/content/getting-started.md +1 -0
  398. package/docs/content/mcp-clients.md +41 -3
  399. package/docs/content/migration-workbench.md +237 -54
  400. package/docs/content/multi-app-workspace.md +41 -0
  401. package/docs/content/multi-tenancy.md +1 -1
  402. package/docs/content/template-brain.md +418 -0
  403. package/docs/content/template-dispatch.md +30 -0
  404. package/docs/content/workspace-connections.md +509 -0
  405. package/docs/content/workspace-management.md +12 -12
  406. package/docs/content/workspace.md +180 -40
  407. package/package.json +7 -2
  408. package/src/templates/default/AGENTS.md +3 -3
  409. package/src/templates/workspace-core/AGENTS.md +7 -0
  410. package/src/templates/workspace-root/AGENTS.md +7 -0
  411. package/src/templates/workspace-root/README.md +25 -0
@@ -0,0 +1,724 @@
1
+ import { spawn } from "node:child_process";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { appendCodeAgentTranscriptEvent, codeAgentRunTranscriptPath, codeAgentStoreRoot, createCodeAgentRunRecord, getCodeAgentRunRecord, listCodeAgentRunRecords, normalizeCodeAgentPermissionMode, queueCodeAgentFollowUp, updateCodeAgentRunRecord, } from "./code-agent-runs.js";
6
+ import { executePendingCodeAgentApproval } from "./code-agent-executor.js";
7
+ const DEVICE_PATH_ENV = "AGENT_NATIVE_REMOTE_DEVICE_PATH";
8
+ const DEFAULT_POLL_INTERVAL_MS = 2_000;
9
+ const MAX_POLL_INTERVAL_MS = 30_000;
10
+ const MAX_TRANSCRIPT_EVENTS_PER_BATCH = 50;
11
+ const activeRunners = new Map();
12
+ export function remoteDeviceConfigPath() {
13
+ return path.resolve(process.env[DEVICE_PATH_ENV] ??
14
+ path.join(os.homedir(), ".agent-native", "remote-device.json"));
15
+ }
16
+ export function loadRemoteCodeAgentDeviceConfig(configPath = remoteDeviceConfigPath()) {
17
+ try {
18
+ const raw = JSON.parse(fs.readFileSync(configPath, "utf-8"));
19
+ if (!isObject(raw))
20
+ return null;
21
+ const token = firstStringValue(raw.token, raw.deviceToken, raw.relayToken, raw.accessToken, raw.bearerToken);
22
+ if (!token)
23
+ return null;
24
+ const pollIntervalMs = Number(raw.pollIntervalMs);
25
+ return {
26
+ token,
27
+ relayUrl: firstStringValue(raw.relayUrl, raw.url, raw.baseUrl),
28
+ deviceId: firstStringValue(raw.deviceId, raw.id),
29
+ deviceName: firstStringValue(raw.deviceName, raw.name),
30
+ pollIntervalMs: Number.isFinite(pollIntervalMs) && pollIntervalMs > 0
31
+ ? Math.min(Math.max(pollIntervalMs, 500), MAX_POLL_INTERVAL_MS)
32
+ : undefined,
33
+ };
34
+ }
35
+ catch {
36
+ return null;
37
+ }
38
+ }
39
+ export async function runCodeAgentConnector(options = {}) {
40
+ const output = options.output ?? process.stdout;
41
+ const configPath = remoteDeviceConfigPath();
42
+ const config = loadRemoteCodeAgentDeviceConfig(configPath);
43
+ if (!config) {
44
+ output.write([
45
+ "Agent-Native Code remote connector is not paired.",
46
+ "",
47
+ `Expected device config: ${configPath}`,
48
+ "Pair this device from Agent Native, or set AGENT_NATIVE_REMOTE_DEVICE_PATH to a JSON file containing a device token.",
49
+ "Then run: agent-native code serve --relay-url <relay-url>",
50
+ "",
51
+ ].join("\n"));
52
+ return 1;
53
+ }
54
+ const relayUrl = normalizeRelayUrl(options.relayUrl ?? config.relayUrl);
55
+ if (!relayUrl) {
56
+ output.write([
57
+ "Agent-Native Code remote connector needs a relay URL.",
58
+ "",
59
+ "Run: agent-native code serve --relay-url https://your-agent-native-app.example",
60
+ `Or add "relayUrl" to ${configPath}.`,
61
+ "",
62
+ ].join("\n"));
63
+ return 1;
64
+ }
65
+ const connector = new RemoteCodeAgentConnector(config, relayUrl, output);
66
+ await connector.run({ signal: options.signal, once: options.once });
67
+ return 0;
68
+ }
69
+ class RemoteCodeAgentConnector {
70
+ config;
71
+ relayUrl;
72
+ output;
73
+ transcriptCursors = new Map();
74
+ remoteRunIds = new Set();
75
+ stopped = false;
76
+ constructor(config, relayUrl, output) {
77
+ this.config = config;
78
+ this.relayUrl = relayUrl;
79
+ this.output = output;
80
+ for (const run of listCodeAgentRunRecords()) {
81
+ if (isRemoteStartedRun(run, relayUrl)) {
82
+ this.remoteRunIds.add(run.id);
83
+ this.transcriptCursors.set(run.id, { offset: 0, seq: 0 });
84
+ }
85
+ }
86
+ }
87
+ async run(options = {}) {
88
+ const onAbort = () => {
89
+ this.stopped = true;
90
+ };
91
+ if (options.signal) {
92
+ if (options.signal.aborted)
93
+ this.stopped = true;
94
+ else
95
+ options.signal.addEventListener("abort", onAbort, { once: true });
96
+ }
97
+ this.output.write(`Agent-Native Code remote connector serving ${this.relayUrl}\n`);
98
+ let backoffMs = this.pollIntervalMs();
99
+ try {
100
+ while (!this.stopped) {
101
+ try {
102
+ await this.pollOnce();
103
+ await this.flushRemoteRunEvents();
104
+ backoffMs = this.pollIntervalMs();
105
+ if (options.once)
106
+ break;
107
+ }
108
+ catch (err) {
109
+ const message = err instanceof Error ? err.message : String(err);
110
+ this.output.write(`Remote connector poll failed: ${message}\n`);
111
+ backoffMs = Math.min(backoffMs * 2, MAX_POLL_INTERVAL_MS);
112
+ }
113
+ await sleep(backoffMs, options.signal);
114
+ }
115
+ }
116
+ finally {
117
+ options.signal?.removeEventListener("abort", onAbort);
118
+ }
119
+ }
120
+ async pollOnce() {
121
+ const response = await this.postJson("/_agent-native/integrations/remote/poll", {
122
+ deviceId: this.config.deviceId,
123
+ deviceName: this.config.deviceName ?? os.hostname(),
124
+ capabilities: [
125
+ "create-run",
126
+ "append-followup",
127
+ "approve",
128
+ "deny",
129
+ "stop",
130
+ "status",
131
+ "run-events",
132
+ ],
133
+ activeRunIds: Array.from(this.remoteRunIds),
134
+ });
135
+ const commands = normalizeCommands(response);
136
+ for (const command of commands) {
137
+ const result = await this.dispatchCommand(command).catch((err) => ({
138
+ ok: false,
139
+ error: err instanceof Error ? err.message : String(err),
140
+ }));
141
+ await this.postCommandResult(command, result);
142
+ }
143
+ }
144
+ async dispatchCommand(command) {
145
+ switch (normalizeKind(command.kind)) {
146
+ case "create-run":
147
+ return this.createRun(command);
148
+ case "append-followup":
149
+ case "append-follow-up":
150
+ case "followup":
151
+ case "follow-up":
152
+ return this.appendFollowUp(command);
153
+ case "approve":
154
+ return this.approve(command);
155
+ case "deny":
156
+ return this.deny(command);
157
+ case "stop":
158
+ return this.stop(command);
159
+ case "status":
160
+ return this.status(command);
161
+ default:
162
+ return {
163
+ ok: false,
164
+ error: `Unsupported remote command kind: ${command.kind}`,
165
+ };
166
+ }
167
+ }
168
+ createRun(command) {
169
+ const prompt = firstTextValue(command.params.prompt, command.params.message, command.params.input);
170
+ if (!prompt) {
171
+ return { ok: false, error: "Missing prompt." };
172
+ }
173
+ const goalId = firstStringValue(command.params.goalId) ?? "task";
174
+ const cwd = resolveCommandCwd(command.params.cwd);
175
+ const permissionMode = normalizeCodeAgentPermissionMode(command.params.permissionMode) ??
176
+ "full-auto";
177
+ const engine = firstStringValue(command.params.engine);
178
+ const model = firstStringValue(command.params.model);
179
+ const effort = firstStringValue(command.params.effort, command.params.reasoningEffort);
180
+ const metadata = isObject(command.params.metadata)
181
+ ? command.params.metadata
182
+ : {};
183
+ const run = createCodeAgentRunRecord({
184
+ goalId,
185
+ title: firstStringValue(command.params.title) ?? titleFromPrompt(prompt),
186
+ subtitle: "Remote coding task",
187
+ status: "queued",
188
+ phase: "queued",
189
+ permissionMode,
190
+ cwd,
191
+ progress: {
192
+ label: "Queued",
193
+ completed: 0,
194
+ total: 1,
195
+ percent: 0,
196
+ },
197
+ details: [
198
+ { label: "Prompt", value: truncateForDisplay(prompt, 160) },
199
+ { label: "Agent", value: "Remote connector" },
200
+ { label: "Mode", value: permissionMode },
201
+ ],
202
+ metadata: {
203
+ ...metadata,
204
+ prompt,
205
+ source: "remote-connector",
206
+ engine,
207
+ model,
208
+ effort,
209
+ remote: {
210
+ commandId: command.id,
211
+ deviceId: this.config.deviceId,
212
+ relayUrl: this.relayUrl,
213
+ },
214
+ },
215
+ });
216
+ appendCodeAgentTranscriptEvent({
217
+ runId: run.id,
218
+ kind: "user",
219
+ message: prompt,
220
+ metadata: { source: "remote-initial-prompt", commandId: command.id },
221
+ });
222
+ appendCodeAgentTranscriptEvent({
223
+ runId: run.id,
224
+ kind: "status",
225
+ message: "Remote Agent-Native Code run queued.",
226
+ metadata: { status: "queued", phase: "queued", commandId: command.id },
227
+ });
228
+ this.remoteRunIds.add(run.id);
229
+ this.transcriptCursors.set(run.id, { offset: 0, seq: 0 });
230
+ this.spawnRunner(run.id, cwd, permissionMode);
231
+ return { ok: true, runId: run.id, run };
232
+ }
233
+ appendFollowUp(command) {
234
+ const runId = firstStringValue(command.params.runId);
235
+ const prompt = firstTextValue(command.params.prompt, command.params.message);
236
+ if (!runId)
237
+ return { ok: false, error: "Missing runId." };
238
+ if (!prompt)
239
+ return { ok: false, error: "Missing prompt." };
240
+ const run = getCodeAgentRunRecord(runId);
241
+ if (!run)
242
+ return { ok: false, error: `Run not found: ${runId}` };
243
+ const permissionMode = normalizeCodeAgentPermissionMode(command.params.permissionMode) ??
244
+ undefined;
245
+ const activeRun = permissionMode
246
+ ? (updateCodeAgentRunRecord(runId, { permissionMode }) ?? run)
247
+ : run;
248
+ const followUpMode = firstStringValue(command.params.followUpMode) === "queued"
249
+ ? "queued"
250
+ : "immediate";
251
+ const runnerActive = activeRunners.has(activeRun.id);
252
+ const shouldQueue = activeRun.status === "needs-approval" || runnerActive;
253
+ const event = appendCodeAgentTranscriptEvent({
254
+ runId: activeRun.id,
255
+ kind: "user",
256
+ message: prompt,
257
+ metadata: {
258
+ source: "remote-follow-up",
259
+ commandId: command.id,
260
+ followUpMode,
261
+ delivery: shouldQueue ? followUpMode : "run-now",
262
+ },
263
+ });
264
+ if (shouldQueue) {
265
+ queueCodeAgentFollowUp({
266
+ runId: activeRun.id,
267
+ prompt,
268
+ mode: followUpMode,
269
+ eventId: event.id,
270
+ permissionMode,
271
+ source: "remote-follow-up",
272
+ createdAt: event.createdAt,
273
+ });
274
+ }
275
+ else {
276
+ this.spawnRunner(activeRun.id, activeRun.cwd, permissionMode);
277
+ }
278
+ this.remoteRunIds.add(activeRun.id);
279
+ return { ok: true, runId: activeRun.id, event, queued: shouldQueue };
280
+ }
281
+ async approve(command) {
282
+ const runId = firstStringValue(command.params.runId);
283
+ if (!runId)
284
+ return { ok: false, error: "Missing runId." };
285
+ const run = getCodeAgentRunRecord(runId);
286
+ if (!run)
287
+ return { ok: false, error: `Run not found: ${runId}` };
288
+ const result = await executePendingCodeAgentApproval(runId);
289
+ this.spawnRunner(runId, run.cwd, run.permissionMode);
290
+ return { ok: true, runId, run: result ?? getCodeAgentRunRecord(runId) };
291
+ }
292
+ deny(command) {
293
+ const runId = firstStringValue(command.params.runId);
294
+ if (!runId)
295
+ return { ok: false, error: "Missing runId." };
296
+ const run = getCodeAgentRunRecord(runId);
297
+ if (!run)
298
+ return { ok: false, error: `Run not found: ${runId}` };
299
+ appendCodeAgentTranscriptEvent({
300
+ runId,
301
+ kind: "status",
302
+ message: "Remote approval denied.",
303
+ metadata: { source: "remote-connector", commandId: command.id },
304
+ });
305
+ const updated = updateCodeAgentRunRecord(runId, {
306
+ status: "paused",
307
+ phase: "approval-denied",
308
+ needsApproval: false,
309
+ metadata: {
310
+ pendingApproval: undefined,
311
+ approvalDeniedAt: new Date().toISOString(),
312
+ },
313
+ });
314
+ return { ok: true, runId, run: updated };
315
+ }
316
+ stop(command) {
317
+ const runId = firstStringValue(command.params.runId);
318
+ if (!runId)
319
+ return { ok: false, error: "Missing runId." };
320
+ const run = getCodeAgentRunRecord(runId);
321
+ if (!run)
322
+ return { ok: false, error: `Run not found: ${runId}` };
323
+ const active = activeRunners.get(runId);
324
+ const pid = active?.child.pid ?? Number(run.metadata?.runnerPid);
325
+ let killed = false;
326
+ let killError;
327
+ if (Number.isFinite(pid) && pid > 0) {
328
+ try {
329
+ process.kill(pid, "SIGTERM");
330
+ killed = true;
331
+ }
332
+ catch (err) {
333
+ killError = err instanceof Error ? err.message : String(err);
334
+ }
335
+ }
336
+ activeRunners.delete(runId);
337
+ appendCodeAgentTranscriptEvent({
338
+ runId,
339
+ kind: "status",
340
+ message: killed
341
+ ? "Remote stop requested for Agent-Native Code runner."
342
+ : "Remote stop requested; no active runner process was found.",
343
+ metadata: {
344
+ source: "remote-connector",
345
+ commandId: command.id,
346
+ pid: Number.isFinite(pid) ? pid : undefined,
347
+ killed,
348
+ killError,
349
+ },
350
+ });
351
+ const updated = updateCodeAgentRunRecord(runId, {
352
+ status: "paused",
353
+ phase: "stopped",
354
+ progress: {
355
+ label: "Stopped",
356
+ completed: 0,
357
+ total: 1,
358
+ percent: 0,
359
+ },
360
+ metadata: {
361
+ runnerState: "stopped",
362
+ stoppedAt: new Date().toISOString(),
363
+ stoppedBy: "remote-connector",
364
+ stopSignalSent: killed,
365
+ stopError: killError,
366
+ },
367
+ });
368
+ return { ok: !killError, runId, run: updated, killed, error: killError };
369
+ }
370
+ status(command) {
371
+ const runId = firstStringValue(command.params.runId);
372
+ if (runId) {
373
+ const run = getCodeAgentRunRecord(runId);
374
+ return run
375
+ ? { ok: true, runId, run, runner: runnerStatus(runId) }
376
+ : { ok: false, runId, error: `Run not found: ${runId}` };
377
+ }
378
+ return {
379
+ ok: true,
380
+ runs: listCodeAgentRunRecords().slice(0, 20),
381
+ activeRunIds: Array.from(activeRunners.keys()),
382
+ };
383
+ }
384
+ spawnRunner(runId, cwd, permissionMode) {
385
+ if (activeRunners.has(runId))
386
+ return;
387
+ const invocation = resolveCodeAgentCliInvocation();
388
+ const child = spawn(invocation.command, [...invocation.args, "code", "run", runId], {
389
+ cwd,
390
+ detached: true,
391
+ stdio: ["ignore", "pipe", "pipe"],
392
+ env: {
393
+ ...process.env,
394
+ AGENT_NATIVE_CODE_AGENTS_HOME: codeAgentStoreRoot(),
395
+ ...(permissionMode
396
+ ? { AGENT_NATIVE_CODE_AGENT_PERMISSION_MODE: permissionMode }
397
+ : {}),
398
+ },
399
+ });
400
+ const runnerCommand = `${invocation.command} ${[
401
+ ...invocation.args,
402
+ "code",
403
+ "run",
404
+ runId,
405
+ ].join(" ")}`;
406
+ const startedAt = new Date().toISOString();
407
+ activeRunners.set(runId, {
408
+ child,
409
+ runId,
410
+ cwd,
411
+ command: runnerCommand,
412
+ startedAt,
413
+ });
414
+ updateCodeAgentRunRecord(runId, {
415
+ status: "running",
416
+ phase: "executing",
417
+ metadata: {
418
+ runnerState: "running",
419
+ runnerPid: child.pid,
420
+ runnerCommand,
421
+ runnerCwd: cwd,
422
+ runnerStartedAt: startedAt,
423
+ },
424
+ });
425
+ child.stdout?.on("data", (chunk) => appendRunnerOutput(runId, chunk));
426
+ child.stderr?.on("data", (chunk) => appendRunnerOutput(runId, chunk, "runner-stderr"));
427
+ child.on("exit", (code, signal) => {
428
+ activeRunners.delete(runId);
429
+ updateCodeAgentRunRecord(runId, {
430
+ metadata: {
431
+ runnerState: "exited",
432
+ runnerExitedAt: new Date().toISOString(),
433
+ runnerExitCode: code,
434
+ runnerExitSignal: signal,
435
+ },
436
+ });
437
+ });
438
+ child.unref();
439
+ }
440
+ async flushRemoteRunEvents() {
441
+ for (const runId of this.remoteRunIds) {
442
+ const cursor = this.transcriptCursors.get(runId) ?? { offset: 0, seq: 0 };
443
+ const batch = readTranscriptBatch(runId, cursor.offset);
444
+ if (batch.events.length === 0) {
445
+ this.transcriptCursors.set(runId, {
446
+ offset: batch.nextOffset,
447
+ seq: cursor.seq,
448
+ });
449
+ continue;
450
+ }
451
+ await this.postJson("/_agent-native/integrations/remote/run-events", {
452
+ deviceId: this.config.deviceId,
453
+ remoteRunId: runId,
454
+ cursor: { offset: batch.nextOffset },
455
+ events: batch.events.map((event, index) => ({
456
+ seq: cursor.seq + index,
457
+ event,
458
+ })),
459
+ });
460
+ this.transcriptCursors.set(runId, {
461
+ offset: batch.nextOffset,
462
+ seq: cursor.seq + batch.events.length,
463
+ });
464
+ }
465
+ }
466
+ async postCommandResult(command, result) {
467
+ await this.postJson("/_agent-native/integrations/remote/result", {
468
+ deviceId: this.config.deviceId,
469
+ commandId: command.id,
470
+ kind: command.kind,
471
+ ok: result.ok !== false,
472
+ status: result.ok === false ? "failed" : "completed",
473
+ result,
474
+ errorMessage: typeof result.error === "string" ? result.error : undefined,
475
+ });
476
+ }
477
+ async postJson(pathname, body) {
478
+ const url = new URL(pathname, this.relayUrl);
479
+ const response = await fetch(url, {
480
+ method: "POST",
481
+ headers: {
482
+ authorization: `Bearer ${this.config.token}`,
483
+ "content-type": "application/json",
484
+ },
485
+ body: JSON.stringify(body),
486
+ });
487
+ if (!response.ok) {
488
+ throw new Error(`${url.pathname} returned ${response.status}`);
489
+ }
490
+ const text = await response.text();
491
+ return text ? JSON.parse(text) : null;
492
+ }
493
+ pollIntervalMs() {
494
+ return this.config.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;
495
+ }
496
+ }
497
+ function normalizeCommands(value) {
498
+ const rawCommands = Array.isArray(value)
499
+ ? value
500
+ : isObject(value) && Array.isArray(value.commands)
501
+ ? value.commands
502
+ : isObject(value) && isObject(value.command)
503
+ ? [value.command]
504
+ : isObject(value) && firstStringValue(value.kind, value.type)
505
+ ? [value]
506
+ : [];
507
+ return rawCommands
508
+ .map((raw) => {
509
+ if (!isObject(raw))
510
+ return null;
511
+ const kind = firstStringValue(raw.kind, raw.type, raw.command, raw.action);
512
+ if (!kind)
513
+ return null;
514
+ const params = isObject(raw.params)
515
+ ? raw.params
516
+ : isObject(raw.payload)
517
+ ? raw.payload
518
+ : isObject(raw.args)
519
+ ? raw.args
520
+ : raw;
521
+ return {
522
+ id: firstStringValue(raw.id, raw.commandId, raw.requestId) ??
523
+ `${normalizeKind(kind)}-${Date.now()}`,
524
+ kind,
525
+ params,
526
+ raw,
527
+ };
528
+ })
529
+ .filter((command) => Boolean(command));
530
+ }
531
+ function normalizeKind(value) {
532
+ return value.trim().toLowerCase().replaceAll("_", "-");
533
+ }
534
+ function readTranscriptBatch(runId, offset) {
535
+ const transcriptPath = codeAgentRunTranscriptPath(runId);
536
+ if (!fs.existsSync(transcriptPath)) {
537
+ return { events: [], nextOffset: 0 };
538
+ }
539
+ const stat = fs.statSync(transcriptPath);
540
+ const safeOffset = Math.max(0, Math.min(offset, stat.size));
541
+ const fd = fs.openSync(transcriptPath, "r");
542
+ try {
543
+ const length = Math.min(stat.size - safeOffset, 256_000);
544
+ if (length <= 0) {
545
+ return {
546
+ events: [],
547
+ nextOffset: safeOffset,
548
+ };
549
+ }
550
+ const buffer = Buffer.alloc(length);
551
+ fs.readSync(fd, buffer, 0, length, safeOffset);
552
+ const text = buffer.toString("utf-8");
553
+ const lines = text.split(/\r?\n/);
554
+ const hasTrailingNewline = /\r?\n$/.test(text);
555
+ const completeLines = hasTrailingNewline ? lines : lines.slice(0, -1);
556
+ const selected = completeLines
557
+ .filter(Boolean)
558
+ .slice(0, MAX_TRANSCRIPT_EVENTS_PER_BATCH);
559
+ const consumedBytes = Buffer.byteLength(selected.map((line) => `${line}\n`).join(""), "utf-8");
560
+ return {
561
+ events: selected
562
+ .map((line) => parseTranscriptEvent(line))
563
+ .filter((event) => Boolean(event)),
564
+ nextOffset: safeOffset + consumedBytes,
565
+ };
566
+ }
567
+ finally {
568
+ fs.closeSync(fd);
569
+ }
570
+ }
571
+ function parseTranscriptEvent(line) {
572
+ try {
573
+ const parsed = JSON.parse(line);
574
+ if (!isObject(parsed))
575
+ return null;
576
+ if (parsed.schemaVersion !== 1 ||
577
+ typeof parsed.id !== "string" ||
578
+ typeof parsed.runId !== "string" ||
579
+ typeof parsed.kind !== "string" ||
580
+ typeof parsed.message !== "string" ||
581
+ typeof parsed.createdAt !== "string") {
582
+ return null;
583
+ }
584
+ if (parsed.kind !== "user" &&
585
+ parsed.kind !== "system" &&
586
+ parsed.kind !== "note" &&
587
+ parsed.kind !== "artifact" &&
588
+ parsed.kind !== "status") {
589
+ return null;
590
+ }
591
+ return {
592
+ schemaVersion: 1,
593
+ id: parsed.id,
594
+ runId: parsed.runId,
595
+ kind: parsed.kind,
596
+ message: parsed.message,
597
+ createdAt: parsed.createdAt,
598
+ metadata: isObject(parsed.metadata) ? parsed.metadata : undefined,
599
+ };
600
+ }
601
+ catch {
602
+ return null;
603
+ }
604
+ }
605
+ function resolveCodeAgentCliInvocation() {
606
+ const currentEntry = process.argv[1];
607
+ if (currentEntry &&
608
+ fs.existsSync(currentEntry) &&
609
+ currentEntry.endsWith(".js")) {
610
+ return { command: process.execPath, args: [path.resolve(currentEntry)] };
611
+ }
612
+ const localDist = path.resolve("packages/core/dist/cli/index.js");
613
+ if (fs.existsSync(localDist)) {
614
+ return { command: process.execPath, args: [localDist] };
615
+ }
616
+ return {
617
+ command: "pnpm",
618
+ args: [
619
+ "--filter",
620
+ "@agent-native/core",
621
+ "exec",
622
+ "node",
623
+ "dist/cli/index.js",
624
+ ],
625
+ };
626
+ }
627
+ function appendRunnerOutput(runId, chunk, source = "runner-stdout") {
628
+ const text = chunk.toString().trim();
629
+ if (!text)
630
+ return;
631
+ appendCodeAgentTranscriptEvent({
632
+ runId,
633
+ kind: "status",
634
+ message: text,
635
+ metadata: { source },
636
+ });
637
+ }
638
+ function runnerStatus(runId) {
639
+ const runner = activeRunners.get(runId);
640
+ return runner
641
+ ? {
642
+ active: true,
643
+ pid: runner.child.pid,
644
+ command: runner.command,
645
+ cwd: runner.cwd,
646
+ startedAt: runner.startedAt,
647
+ }
648
+ : { active: false };
649
+ }
650
+ function isRemoteStartedRun(run, relayUrl) {
651
+ const metadata = run.metadata ?? {};
652
+ const remote = isObject(metadata.remote) ? metadata.remote : {};
653
+ return (metadata.source === "remote-connector" ||
654
+ firstStringValue(remote.relayUrl) === relayUrl);
655
+ }
656
+ function resolveCommandCwd(value) {
657
+ const cwd = firstStringValue(value);
658
+ return cwd ? path.resolve(cwd) : process.cwd();
659
+ }
660
+ function normalizeRelayUrl(value) {
661
+ if (!value)
662
+ return null;
663
+ try {
664
+ const url = new URL(value);
665
+ if (url.protocol !== "http:" && url.protocol !== "https:")
666
+ return null;
667
+ return `${url.origin}${url.pathname.replace(/\/+$/, "") || "/"}`;
668
+ }
669
+ catch {
670
+ return null;
671
+ }
672
+ }
673
+ function firstStringValue(...values) {
674
+ for (const value of values) {
675
+ if (typeof value !== "string")
676
+ continue;
677
+ const trimmed = value.trim();
678
+ if (trimmed)
679
+ return trimmed;
680
+ }
681
+ return undefined;
682
+ }
683
+ function firstTextValue(...values) {
684
+ for (const value of values) {
685
+ if (typeof value === "string" && value.trim())
686
+ return value.trim();
687
+ if (!Array.isArray(value))
688
+ continue;
689
+ const parts = value
690
+ .map((item) => typeof item === "string"
691
+ ? item
692
+ : isObject(item)
693
+ ? (firstStringValue(item.text, item.content, item.message) ?? "")
694
+ : "")
695
+ .map((part) => part.trim())
696
+ .filter(Boolean);
697
+ if (parts.length > 0)
698
+ return parts.join("\n");
699
+ }
700
+ return undefined;
701
+ }
702
+ function titleFromPrompt(prompt) {
703
+ return truncateForDisplay(prompt.replace(/\s+/g, " ").trim(), 80);
704
+ }
705
+ function truncateForDisplay(value, max) {
706
+ return value.length <= max
707
+ ? value
708
+ : `${value.slice(0, Math.max(0, max - 3))}...`;
709
+ }
710
+ function isObject(value) {
711
+ return Boolean(value && typeof value === "object" && !Array.isArray(value));
712
+ }
713
+ function sleep(ms, signal) {
714
+ if (signal?.aborted)
715
+ return Promise.resolve();
716
+ return new Promise((resolve) => {
717
+ const timeout = setTimeout(resolve, ms);
718
+ signal?.addEventListener("abort", () => {
719
+ clearTimeout(timeout);
720
+ resolve();
721
+ }, { once: true });
722
+ });
723
+ }
724
+ //# sourceMappingURL=code-agent-connector.js.map