@agent-native/core 0.15.12 → 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 +27 -3
  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,745 @@
1
+ export const AGENT_NATIVE_HOST_BRIDGE_VERSION = "0.1.0";
2
+ export const AGENT_NATIVE_HOST_MESSAGE_TYPES = {
3
+ READY: "agentNative.host.ready",
4
+ INIT: "agentNative.host.init",
5
+ GET_CONTEXT: "agentNative.host.getContext",
6
+ CONTEXT: "agentNative.host.context",
7
+ AUTH: "agentNative.host.auth",
8
+ LIST_ACTIONS: "agentNative.host.listActions",
9
+ ACTIONS: "agentNative.host.actions",
10
+ RUN_ACTION: "agentNative.host.runAction",
11
+ ACTION_RESULT: "agentNative.host.actionResult",
12
+ COMMAND: "agentNative.host.command",
13
+ COMMAND_RESULT: "agentNative.host.commandResult",
14
+ ERROR: "agentNative.host.error",
15
+ };
16
+ function isRecord(value) {
17
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
18
+ }
19
+ function normalizeOrigin(value) {
20
+ if (!value)
21
+ return null;
22
+ if (value === "*")
23
+ return "*";
24
+ try {
25
+ return new URL(value).origin;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ function getWindowFromSource(source) {
32
+ if (!source || !("postMessage" in source))
33
+ return null;
34
+ return source;
35
+ }
36
+ function messageError(error) {
37
+ return error instanceof Error ? error : new Error(String(error));
38
+ }
39
+ function serializeForMessage(value, label) {
40
+ if (value === undefined)
41
+ return value;
42
+ try {
43
+ return JSON.parse(JSON.stringify(value));
44
+ }
45
+ catch {
46
+ throw new Error(`${label} must be JSON-serializable`);
47
+ }
48
+ }
49
+ function requestId() {
50
+ return `host-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
51
+ }
52
+ function sessionId() {
53
+ return `session-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
54
+ }
55
+ function createHostSession(session) {
56
+ const now = new Date().toISOString();
57
+ const base = typeof session === "string"
58
+ ? { id: session }
59
+ : session && typeof session === "object"
60
+ ? session
61
+ : {};
62
+ return {
63
+ id: base.id || sessionId(),
64
+ connectedAt: base.connectedAt || now,
65
+ url: base.url ||
66
+ (typeof window !== "undefined" ? window.location.href : undefined),
67
+ ...base,
68
+ };
69
+ }
70
+ function attachSession(context, session) {
71
+ return serializeForMessage({
72
+ ...context,
73
+ session: {
74
+ ...session,
75
+ ...(context.session ?? {}),
76
+ },
77
+ }, "Host context");
78
+ }
79
+ function truncate(value, maxLength) {
80
+ if (!value)
81
+ return undefined;
82
+ const normalized = value.replace(/\s+/g, " ").trim();
83
+ if (normalized.length <= maxLength)
84
+ return normalized;
85
+ return `${normalized.slice(0, Math.max(0, maxLength - 1))}…`;
86
+ }
87
+ function resolveSnapshotRoot(root) {
88
+ if (typeof document === "undefined")
89
+ return null;
90
+ if (typeof root === "function")
91
+ return root() ?? null;
92
+ return root ?? document.body ?? document.documentElement;
93
+ }
94
+ function readElementText(root) {
95
+ if (typeof document === "undefined")
96
+ return root.textContent ?? undefined;
97
+ try {
98
+ const showText = typeof NodeFilter === "undefined" ? 4 : NodeFilter.SHOW_TEXT;
99
+ const walker = document.createTreeWalker(root, showText);
100
+ const parts = [];
101
+ while (walker.nextNode()) {
102
+ const text = walker.currentNode.textContent?.trim();
103
+ if (text)
104
+ parts.push(text);
105
+ }
106
+ return parts.join(" ");
107
+ }
108
+ catch {
109
+ return root.textContent ?? undefined;
110
+ }
111
+ }
112
+ function defaultContext() {
113
+ if (typeof window === "undefined")
114
+ return {};
115
+ return {
116
+ url: window.location.href,
117
+ title: typeof document !== "undefined" ? document.title : undefined,
118
+ route: {
119
+ pathname: window.location.pathname,
120
+ search: window.location.search,
121
+ hash: window.location.hash,
122
+ },
123
+ };
124
+ }
125
+ export function readAgentNativeScreenContext(options = {}) {
126
+ const base = defaultContext();
127
+ if (typeof window === "undefined")
128
+ return base;
129
+ const root = resolveSnapshotRoot(options.root);
130
+ const selectionText = typeof window.getSelection === "function"
131
+ ? window.getSelection()?.toString().trim() || undefined
132
+ : undefined;
133
+ const maxTextLength = options.maxTextLength ?? 6000;
134
+ const maxHtmlLength = options.maxHtmlLength ?? 20000;
135
+ const includeVisibleText = options.includeVisibleText ?? true;
136
+ const includeDomHtml = options.includeDomHtml ?? false;
137
+ const selection = selectionText
138
+ ? { ...(base.selection ?? {}), type: "text", text: selectionText }
139
+ : base.selection;
140
+ return {
141
+ ...base,
142
+ selection,
143
+ screen: {
144
+ url: base.url,
145
+ title: base.title,
146
+ route: base.route,
147
+ selection,
148
+ visibleText: includeVisibleText && root
149
+ ? truncate(readElementText(root), maxTextLength)
150
+ : undefined,
151
+ html: includeDomHtml && root
152
+ ? truncate(root.outerHTML ?? undefined, maxHtmlLength)
153
+ : undefined,
154
+ viewport: {
155
+ width: window.innerWidth,
156
+ height: window.innerHeight,
157
+ scrollX: window.scrollX,
158
+ scrollY: window.scrollY,
159
+ },
160
+ },
161
+ };
162
+ }
163
+ async function resolveHostContext(getContext) {
164
+ const base = defaultContext();
165
+ const custom = getContext ? await getContext() : undefined;
166
+ if (!custom)
167
+ return serializeForMessage(base, "Host context");
168
+ const merged = {
169
+ ...base,
170
+ ...custom,
171
+ route: base.route || custom.route
172
+ ? { ...(base.route ?? {}), ...(custom.route ?? {}) }
173
+ : undefined,
174
+ };
175
+ return serializeForMessage(merged, "Host context");
176
+ }
177
+ async function resolveHostAuth(auth) {
178
+ const value = typeof auth === "function" ? await auth() : auth;
179
+ if (!value)
180
+ return undefined;
181
+ const payload = typeof value === "string" ? { token: value } : value;
182
+ if (!payload || typeof payload !== "object")
183
+ return undefined;
184
+ const headers = payload.headers && typeof payload.headers === "object"
185
+ ? Object.fromEntries(Object.entries(payload.headers).map(([key, val]) => [
186
+ key,
187
+ String(val),
188
+ ]))
189
+ : undefined;
190
+ return serializeForMessage({ ...payload, headers }, "Host auth payload");
191
+ }
192
+ async function resolveClientActions(actions) {
193
+ const value = typeof actions === "function" ? await actions() : actions;
194
+ return Array.isArray(value) ? value : [];
195
+ }
196
+ function toActionManifest(action) {
197
+ if (!action?.name || !action.description)
198
+ return null;
199
+ const { run: _run, ...manifest } = action;
200
+ return serializeForMessage({
201
+ source: "client",
202
+ availability: "browser-session",
203
+ ...manifest,
204
+ schema: manifest.schema ?? manifest.parameters,
205
+ }, "Client action manifest");
206
+ }
207
+ async function resolveActionManifest(actions) {
208
+ const resolved = await resolveClientActions(actions);
209
+ return resolved
210
+ .map(toActionManifest)
211
+ .filter(Boolean);
212
+ }
213
+ async function findClientAction(actions, name) {
214
+ const resolved = await resolveClientActions(actions);
215
+ return resolved.find((action) => action.name === name);
216
+ }
217
+ function dispatchHostEvent(type, payload) {
218
+ if (typeof window === "undefined")
219
+ return { dispatched: true };
220
+ window.dispatchEvent(new CustomEvent(type, {
221
+ detail: payload,
222
+ }));
223
+ return { dispatched: true };
224
+ }
225
+ export const defaultAgentNativeHostCommands = {
226
+ navigate: ({ payload }) => dispatchHostEvent("agentNative:navigate", payload),
227
+ refreshData: ({ payload }) => dispatchHostEvent("agentNative:refresh-data", payload),
228
+ "refresh-data": ({ payload }) => dispatchHostEvent("agentNative:refresh-data", payload),
229
+ remountView: ({ payload }) => dispatchHostEvent("agentNative:remount-view", payload),
230
+ "remount-view": ({ payload }) => dispatchHostEvent("agentNative:remount-view", payload),
231
+ hardReload: () => {
232
+ if (typeof window !== "undefined")
233
+ window.location.reload();
234
+ return { reloading: true };
235
+ },
236
+ "hard-reload": () => {
237
+ if (typeof window !== "undefined")
238
+ window.location.reload();
239
+ return { reloading: true };
240
+ },
241
+ openResource: ({ payload }) => dispatchHostEvent("agentNative:open-resource", payload),
242
+ "open-resource": ({ payload }) => dispatchHostEvent("agentNative:open-resource", payload),
243
+ };
244
+ function isIncomingHostMessage(value) {
245
+ if (!isRecord(value))
246
+ return false;
247
+ return (value.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.READY ||
248
+ value.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.GET_CONTEXT ||
249
+ value.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.LIST_ACTIONS ||
250
+ value.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.RUN_ACTION ||
251
+ value.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND);
252
+ }
253
+ export function createAgentNativeHostBridge(options) {
254
+ let targetWindow = options.targetWindow ?? null;
255
+ let started = false;
256
+ const allowedOrigin = normalizeOrigin(options.agentOrigin);
257
+ const targetOrigin = allowedOrigin && allowedOrigin !== "*" ? allowedOrigin : "*";
258
+ const session = createHostSession(options.session);
259
+ function emit(event) {
260
+ options.onEvent?.(event);
261
+ }
262
+ function trusted(event) {
263
+ if (allowedOrigin &&
264
+ allowedOrigin !== "*" &&
265
+ event.origin !== allowedOrigin) {
266
+ emit({ type: "ignored", reason: "origin", origin: event.origin });
267
+ return false;
268
+ }
269
+ if (targetWindow && event.source !== targetWindow) {
270
+ emit({ type: "ignored", reason: "source", origin: event.origin });
271
+ return false;
272
+ }
273
+ return true;
274
+ }
275
+ function post(message) {
276
+ if (!targetWindow)
277
+ return false;
278
+ targetWindow.postMessage(message, targetOrigin);
279
+ return true;
280
+ }
281
+ async function sendInit(requestId) {
282
+ const message = {
283
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.INIT,
284
+ version: AGENT_NATIVE_HOST_BRIDGE_VERSION,
285
+ requestId,
286
+ };
287
+ try {
288
+ message.session = session;
289
+ message.context = attachSession(await resolveHostContext(options.getContext), session);
290
+ }
291
+ catch (error) {
292
+ message.contextError = messageError(error).message;
293
+ emit({ type: "error", requestId, error: messageError(error) });
294
+ }
295
+ try {
296
+ message.auth = await resolveHostAuth(options.auth);
297
+ }
298
+ catch (error) {
299
+ message.authError = messageError(error).message;
300
+ emit({ type: "error", requestId, error: messageError(error) });
301
+ }
302
+ try {
303
+ message.actions = await resolveActionManifest(options.actions);
304
+ }
305
+ catch (error) {
306
+ message.actionsError = messageError(error).message;
307
+ emit({ type: "error", requestId, error: messageError(error) });
308
+ }
309
+ const sent = post(message);
310
+ if (sent)
311
+ emit({ type: "init", requestId });
312
+ return sent;
313
+ }
314
+ async function sendContext(requestId) {
315
+ try {
316
+ const context = attachSession(await resolveHostContext(options.getContext), session);
317
+ const sent = post({
318
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.CONTEXT,
319
+ ok: true,
320
+ requestId,
321
+ context,
322
+ });
323
+ if (sent)
324
+ emit({ type: "context", requestId });
325
+ return sent;
326
+ }
327
+ catch (error) {
328
+ const err = messageError(error);
329
+ emit({ type: "error", requestId, error: err });
330
+ return post({
331
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.CONTEXT,
332
+ ok: false,
333
+ requestId,
334
+ error: err.message,
335
+ });
336
+ }
337
+ }
338
+ async function sendAuth(requestId) {
339
+ try {
340
+ const auth = await resolveHostAuth(options.auth);
341
+ const sent = post({
342
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.AUTH,
343
+ ok: true,
344
+ requestId,
345
+ auth,
346
+ });
347
+ if (sent)
348
+ emit({ type: "auth", requestId });
349
+ return sent;
350
+ }
351
+ catch (error) {
352
+ const err = messageError(error);
353
+ emit({ type: "error", requestId, error: err });
354
+ return post({
355
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.AUTH,
356
+ ok: false,
357
+ requestId,
358
+ error: err.message,
359
+ });
360
+ }
361
+ }
362
+ async function sendActions(requestId) {
363
+ try {
364
+ const actions = await resolveActionManifest(options.actions);
365
+ const sent = post({
366
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTIONS,
367
+ ok: true,
368
+ requestId,
369
+ actions,
370
+ });
371
+ if (sent)
372
+ emit({ type: "actions", requestId, count: actions.length });
373
+ return sent;
374
+ }
375
+ catch (error) {
376
+ const err = messageError(error);
377
+ emit({ type: "error", requestId, error: err });
378
+ return post({
379
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTIONS,
380
+ ok: false,
381
+ requestId,
382
+ error: err.message,
383
+ });
384
+ }
385
+ }
386
+ async function runHostCommand(command, payload, requestId, event) {
387
+ const handler = options.commands?.[command] ?? defaultAgentNativeHostCommands[command];
388
+ if (!handler) {
389
+ throw new Error(`No host command handler registered for "${command}"`);
390
+ }
391
+ return handler({
392
+ command,
393
+ payload,
394
+ requestId,
395
+ origin: event.origin,
396
+ }, event);
397
+ }
398
+ function needsApproval(action) {
399
+ return (action.destructive === true ||
400
+ action.requiresApproval === true ||
401
+ typeof action.requiresApproval === "object" ||
402
+ Boolean(action.approval));
403
+ }
404
+ function approvalConfig(action) {
405
+ if (action.approval)
406
+ return action.approval;
407
+ return typeof action.requiresApproval === "object"
408
+ ? action.requiresApproval
409
+ : undefined;
410
+ }
411
+ async function assertActionApproved(action, args, context, requestId, event) {
412
+ if (!needsApproval(action))
413
+ return;
414
+ const manifest = toActionManifest(action);
415
+ const response = await runHostCommand("requestApproval", {
416
+ action: manifest,
417
+ args,
418
+ context,
419
+ session,
420
+ approval: approvalConfig(action),
421
+ }, requestId, event);
422
+ const approved = response === true ||
423
+ (isRecord(response) &&
424
+ (response.approved === true || response.ok === true));
425
+ if (!approved)
426
+ throw new Error(`Client action "${action.name}" was not approved`);
427
+ }
428
+ async function handleAction(message, event) {
429
+ if (message.type !== AGENT_NATIVE_HOST_MESSAGE_TYPES.RUN_ACTION)
430
+ return;
431
+ const name = typeof message.name === "string" ? message.name : "";
432
+ const requestId = message.requestId;
433
+ const args = "args" in message ? message.args : message.payload;
434
+ try {
435
+ if (!name)
436
+ throw new Error("Missing client action name");
437
+ const action = await findClientAction(options.actions, name);
438
+ if (!action) {
439
+ throw new Error(`No client action registered for "${name}"`);
440
+ }
441
+ const context = attachSession(await resolveHostContext(options.getContext), session);
442
+ await assertActionApproved(action, args, context, requestId, event);
443
+ emit({ type: "action", name, requestId, origin: event.origin });
444
+ const result = await action.run(args, {
445
+ requestId,
446
+ origin: event.origin,
447
+ context,
448
+ session,
449
+ event,
450
+ refresh: (payload) => runHostCommand("refreshData", payload, requestId, event),
451
+ command: (command, payload) => runHostCommand(command, payload, requestId, event),
452
+ });
453
+ post({
454
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTION_RESULT,
455
+ ok: true,
456
+ requestId,
457
+ result: serializeForMessage(result, "Client action result"),
458
+ });
459
+ }
460
+ catch (error) {
461
+ const err = messageError(error);
462
+ emit({ type: "error", requestId, error: err, origin: event.origin });
463
+ post({
464
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTION_RESULT,
465
+ ok: false,
466
+ requestId,
467
+ error: err.message,
468
+ });
469
+ }
470
+ }
471
+ async function handleCommand(message, event) {
472
+ if (message.type !== AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND)
473
+ return;
474
+ const command = typeof message.command === "string" ? message.command : "";
475
+ const requestId = message.requestId;
476
+ try {
477
+ if (!command)
478
+ throw new Error("Missing host command");
479
+ emit({ type: "command", command, requestId, origin: event.origin });
480
+ const result = await runHostCommand(command, message.payload, requestId, event);
481
+ post({
482
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND_RESULT,
483
+ ok: true,
484
+ requestId,
485
+ result: serializeForMessage(result, "Host command result"),
486
+ });
487
+ }
488
+ catch (error) {
489
+ const err = messageError(error);
490
+ emit({ type: "error", requestId, error: err, origin: event.origin });
491
+ post({
492
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND_RESULT,
493
+ ok: false,
494
+ requestId,
495
+ error: err.message,
496
+ });
497
+ }
498
+ }
499
+ function onMessage(event) {
500
+ const message = event.data;
501
+ if (!isIncomingHostMessage(message))
502
+ return;
503
+ if (!trusted(event))
504
+ return;
505
+ const sourceWindow = getWindowFromSource(event.source);
506
+ if (!targetWindow && sourceWindow)
507
+ targetWindow = sourceWindow;
508
+ if (message.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.READY) {
509
+ emit({
510
+ type: "ready",
511
+ requestId: message.requestId,
512
+ origin: event.origin,
513
+ });
514
+ void sendInit(message.requestId);
515
+ }
516
+ else if (message.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.GET_CONTEXT) {
517
+ void sendContext(message.requestId);
518
+ }
519
+ else if (message.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.LIST_ACTIONS) {
520
+ void sendActions(message.requestId);
521
+ }
522
+ else if (message.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.RUN_ACTION) {
523
+ void handleAction(message, event);
524
+ }
525
+ else if (message.type === AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND) {
526
+ void handleCommand(message, event);
527
+ }
528
+ else {
529
+ emit({ type: "ignored", reason: "message", origin: event.origin });
530
+ }
531
+ }
532
+ const bridge = {
533
+ start() {
534
+ if (started || typeof window === "undefined")
535
+ return bridge;
536
+ window.addEventListener("message", onMessage);
537
+ started = true;
538
+ return bridge;
539
+ },
540
+ stop() {
541
+ if (!started || typeof window === "undefined")
542
+ return;
543
+ window.removeEventListener("message", onMessage);
544
+ started = false;
545
+ },
546
+ setTargetWindow(nextTargetWindow) {
547
+ targetWindow = nextTargetWindow;
548
+ },
549
+ post,
550
+ sendInit,
551
+ sendContext,
552
+ refreshContext: sendContext,
553
+ sendAuth,
554
+ sendActions,
555
+ };
556
+ return bridge;
557
+ }
558
+ function getFrameTargetWindow(targetWindow) {
559
+ if (targetWindow)
560
+ return targetWindow;
561
+ if (typeof window === "undefined")
562
+ return null;
563
+ try {
564
+ return window.parent !== window ? window.parent : window;
565
+ }
566
+ catch {
567
+ return window.parent;
568
+ }
569
+ }
570
+ function isTrustedHostResponse(event, targetWindow, hostOrigin) {
571
+ if (event.source !== targetWindow)
572
+ return false;
573
+ const origin = normalizeOrigin(hostOrigin);
574
+ if (origin && origin !== "*" && event.origin !== origin)
575
+ return false;
576
+ return true;
577
+ }
578
+ function requestFromHost(message, responseType, pick, options = {}) {
579
+ return new Promise((resolve, reject) => {
580
+ const targetWindow = getFrameTargetWindow(options.targetWindow);
581
+ if (!targetWindow || typeof window === "undefined") {
582
+ reject(new Error("No host window is available"));
583
+ return;
584
+ }
585
+ const id = typeof message.requestId === "string" ? message.requestId : requestId();
586
+ const timeoutMs = options.timeoutMs ?? 3000;
587
+ let settled = false;
588
+ const cleanup = () => {
589
+ window.removeEventListener("message", onMessage);
590
+ clearTimeout(timer);
591
+ };
592
+ const finish = (fn) => {
593
+ if (settled)
594
+ return;
595
+ settled = true;
596
+ cleanup();
597
+ fn();
598
+ };
599
+ const timer = setTimeout(() => {
600
+ finish(() => reject(new Error("Timed out waiting for host response")));
601
+ }, timeoutMs);
602
+ function onMessage(event) {
603
+ if (!isTrustedHostResponse(event, targetWindow, options.hostOrigin)) {
604
+ return;
605
+ }
606
+ if (!isRecord(event.data))
607
+ return;
608
+ if (event.data.type !== responseType)
609
+ return;
610
+ if (event.data.requestId !== id)
611
+ return;
612
+ const response = pick(event.data);
613
+ if (response.ok === true) {
614
+ finish(() => resolve(response.value));
615
+ }
616
+ else {
617
+ const error = response.error;
618
+ finish(() => reject(error));
619
+ }
620
+ }
621
+ window.addEventListener("message", onMessage);
622
+ targetWindow.postMessage({ ...message, requestId: id }, options.targetOrigin ?? options.hostOrigin ?? "*");
623
+ });
624
+ }
625
+ export function announceAgentNativeFrameReady(options = {}) {
626
+ const targetWindow = getFrameTargetWindow(options.targetWindow);
627
+ if (!targetWindow)
628
+ return;
629
+ targetWindow.postMessage({
630
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.READY,
631
+ version: AGENT_NATIVE_HOST_BRIDGE_VERSION,
632
+ requestId: requestId(),
633
+ }, options.targetOrigin ?? options.hostOrigin ?? "*");
634
+ }
635
+ export function requestAgentNativeHostContext(options = {}) {
636
+ return requestFromHost({ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.GET_CONTEXT }, AGENT_NATIVE_HOST_MESSAGE_TYPES.CONTEXT, (message) => {
637
+ if (message.ok === false) {
638
+ return {
639
+ ok: false,
640
+ error: new Error(typeof message.error === "string"
641
+ ? message.error
642
+ : "Host context request failed"),
643
+ };
644
+ }
645
+ return {
646
+ ok: true,
647
+ value: (message.context ?? {}),
648
+ };
649
+ }, options);
650
+ }
651
+ export function requestAgentNativeHostActions(options = {}) {
652
+ return requestFromHost({ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.LIST_ACTIONS }, AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTIONS, (message) => {
653
+ if (message.ok === false) {
654
+ return {
655
+ ok: false,
656
+ error: new Error(typeof message.error === "string"
657
+ ? message.error
658
+ : "Host actions request failed"),
659
+ };
660
+ }
661
+ return {
662
+ ok: true,
663
+ value: Array.isArray(message.actions)
664
+ ? message.actions
665
+ : [],
666
+ };
667
+ }, options);
668
+ }
669
+ export function runAgentNativeHostAction(name, args, options = {}) {
670
+ return requestFromHost({
671
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.RUN_ACTION,
672
+ name,
673
+ args,
674
+ }, AGENT_NATIVE_HOST_MESSAGE_TYPES.ACTION_RESULT, (message) => {
675
+ if (message.ok === false) {
676
+ return {
677
+ ok: false,
678
+ error: new Error(typeof message.error === "string"
679
+ ? message.error
680
+ : "Host action failed"),
681
+ };
682
+ }
683
+ return { ok: true, value: message.result };
684
+ }, options);
685
+ }
686
+ export function sendAgentNativeHostCommand(command, payload, options = {}) {
687
+ return requestFromHost({
688
+ type: AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND,
689
+ command,
690
+ payload,
691
+ }, AGENT_NATIVE_HOST_MESSAGE_TYPES.COMMAND_RESULT, (message) => {
692
+ if (message.ok === false) {
693
+ return {
694
+ ok: false,
695
+ error: new Error(typeof message.error === "string"
696
+ ? message.error
697
+ : "Host command failed"),
698
+ };
699
+ }
700
+ return { ok: true, value: message.result };
701
+ }, options);
702
+ }
703
+ export function onAgentNativeHostInit(handler, options = {}) {
704
+ if (typeof window === "undefined")
705
+ return () => { };
706
+ const targetWindow = getFrameTargetWindow(options.targetWindow);
707
+ if (!targetWindow)
708
+ return () => { };
709
+ function onMessage(event) {
710
+ if (!isTrustedHostResponse(event, targetWindow, options.hostOrigin)) {
711
+ return;
712
+ }
713
+ if (!isRecord(event.data))
714
+ return;
715
+ if (event.data.type !== AGENT_NATIVE_HOST_MESSAGE_TYPES.INIT)
716
+ return;
717
+ handler({
718
+ version: typeof event.data.version === "string" ? event.data.version : undefined,
719
+ context: isRecord(event.data.context)
720
+ ? event.data.context
721
+ : undefined,
722
+ auth: isRecord(event.data.auth)
723
+ ? event.data.auth
724
+ : undefined,
725
+ actions: Array.isArray(event.data.actions)
726
+ ? event.data.actions
727
+ : undefined,
728
+ session: isRecord(event.data.session)
729
+ ? event.data.session
730
+ : undefined,
731
+ contextError: typeof event.data.contextError === "string"
732
+ ? event.data.contextError
733
+ : undefined,
734
+ authError: typeof event.data.authError === "string"
735
+ ? event.data.authError
736
+ : undefined,
737
+ actionsError: typeof event.data.actionsError === "string"
738
+ ? event.data.actionsError
739
+ : undefined,
740
+ });
741
+ }
742
+ window.addEventListener("message", onMessage);
743
+ return () => window.removeEventListener("message", onMessage);
744
+ }
745
+ //# sourceMappingURL=host-bridge.js.map