@agent-native/dispatch 0.43.0-nightly-20261120212328 → 0.43.7

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 (296) hide show
  1. package/CHANGELOG.md +194 -174
  2. package/dist/actions/ask_app.d.ts +3 -0
  3. package/dist/actions/ask_app.js +7 -2
  4. package/dist/actions/ask_app.js.map +1 -1
  5. package/dist/actions/ask_app_status.d.ts +3 -0
  6. package/dist/actions/ask_app_status.js +5 -1
  7. package/dist/actions/ask_app_status.js.map +1 -1
  8. package/dist/actions/call_app_action.d.ts +1 -0
  9. package/dist/actions/call_app_action.js +21 -5
  10. package/dist/actions/call_app_action.js.map +1 -1
  11. package/dist/actions/create_embed_session.d.ts +3 -2
  12. package/dist/actions/create_embed_session.js +4 -2
  13. package/dist/actions/create_embed_session.js.map +1 -1
  14. package/dist/actions/create_workspace_app_embed_session.d.ts +3 -2
  15. package/dist/actions/create_workspace_app_embed_session.js +3 -1
  16. package/dist/actions/create_workspace_app_embed_session.js.map +1 -1
  17. package/dist/actions/delete-destination.d.ts +12 -12
  18. package/dist/actions/execute-action-suggestion.d.ts +44 -0
  19. package/dist/actions/execute-action-suggestion.d.ts.map +1 -0
  20. package/dist/actions/execute-action-suggestion.js +148 -0
  21. package/dist/actions/execute-action-suggestion.js.map +1 -0
  22. package/dist/actions/import-agent.d.ts +13 -13
  23. package/dist/actions/index.d.ts.map +1 -1
  24. package/dist/actions/index.js +5 -1
  25. package/dist/actions/index.js.map +1 -1
  26. package/dist/actions/list-connected-agents.js +3 -2
  27. package/dist/actions/list-connected-agents.js.map +1 -1
  28. package/dist/actions/list-workspace-connections.d.ts +1 -0
  29. package/dist/actions/list-workspace-connections.d.ts.map +1 -1
  30. package/dist/actions/list_app_actions.js +1 -1
  31. package/dist/actions/list_app_actions.js.map +1 -1
  32. package/dist/actions/list_apps.d.ts +2 -0
  33. package/dist/actions/list_apps.js +11 -3
  34. package/dist/actions/list_apps.js.map +1 -1
  35. package/dist/actions/navigate.js +1 -0
  36. package/dist/actions/navigate.js.map +1 -1
  37. package/dist/actions/open_app.d.ts +4 -0
  38. package/dist/actions/open_app.js +14 -6
  39. package/dist/actions/open_app.js.map +1 -1
  40. package/dist/actions/propose-action-suggestions.d.ts +45 -0
  41. package/dist/actions/propose-action-suggestions.d.ts.map +1 -0
  42. package/dist/actions/propose-action-suggestions.js +32 -0
  43. package/dist/actions/propose-action-suggestions.js.map +1 -0
  44. package/dist/actions/provider-api-register.d.ts +12 -12
  45. package/dist/actions/read_view.js +1 -1
  46. package/dist/actions/read_view.js.map +1 -1
  47. package/dist/actions/remember-pointer.js +1 -1
  48. package/dist/actions/remember-pointer.js.map +1 -1
  49. package/dist/actions/resolve-pointer.js +1 -1
  50. package/dist/actions/resolve-pointer.js.map +1 -1
  51. package/dist/actions/route-app-intent.d.ts +6 -0
  52. package/dist/actions/route-app-intent.js +79 -5
  53. package/dist/actions/route-app-intent.js.map +1 -1
  54. package/dist/actions/send-code-agent-remote-command.js +4 -0
  55. package/dist/actions/send-code-agent-remote-command.js.map +1 -1
  56. package/dist/actions/start-workspace-app-creation.js +1 -1
  57. package/dist/actions/start-workspace-app-creation.js.map +1 -1
  58. package/dist/actions/upsert-destination.d.ts +12 -12
  59. package/dist/actions/view-screen.d.ts +12 -1
  60. package/dist/actions/view-screen.js +53 -5
  61. package/dist/actions/view-screen.js.map +1 -1
  62. package/dist/components/chat-action-suggestions.d.ts +8 -0
  63. package/dist/components/chat-action-suggestions.d.ts.map +1 -0
  64. package/dist/components/chat-action-suggestions.js +191 -0
  65. package/dist/components/chat-action-suggestions.js.map +1 -0
  66. package/dist/components/chat-home-apps.d.ts.map +1 -1
  67. package/dist/components/chat-home-apps.js +1 -1
  68. package/dist/components/chat-home-apps.js.map +1 -1
  69. package/dist/components/google-broker-settings-group.d.ts +2 -0
  70. package/dist/components/google-broker-settings-group.d.ts.map +1 -0
  71. package/dist/components/google-broker-settings-group.js +53 -0
  72. package/dist/components/google-broker-settings-group.js.map +1 -0
  73. package/dist/components/layout/Layout.d.ts +4 -1
  74. package/dist/components/layout/Layout.d.ts.map +1 -1
  75. package/dist/components/layout/Layout.js +246 -69
  76. package/dist/components/layout/Layout.js.map +1 -1
  77. package/dist/components/messaging-setup-panel.d.ts.map +1 -1
  78. package/dist/components/messaging-setup-panel.js +47 -15
  79. package/dist/components/messaging-setup-panel.js.map +1 -1
  80. package/dist/components/workspace-app-host.d.ts +27 -4
  81. package/dist/components/workspace-app-host.d.ts.map +1 -1
  82. package/dist/components/workspace-app-host.js +355 -74
  83. package/dist/components/workspace-app-host.js.map +1 -1
  84. package/dist/config.d.ts +5 -0
  85. package/dist/config.d.ts.map +1 -1
  86. package/dist/config.js.map +1 -1
  87. package/dist/db/google-broker-admission.d.ts +36 -0
  88. package/dist/db/google-broker-admission.d.ts.map +1 -0
  89. package/dist/db/google-broker-admission.js +129 -0
  90. package/dist/db/google-broker-admission.js.map +1 -0
  91. package/dist/db/migrations.d.ts +1 -1
  92. package/dist/db/migrations.d.ts.map +1 -1
  93. package/dist/db/migrations.js +42 -0
  94. package/dist/db/migrations.js.map +1 -1
  95. package/dist/lib/action-suggestions.d.ts +20 -0
  96. package/dist/lib/action-suggestions.d.ts.map +1 -0
  97. package/dist/lib/action-suggestions.js +219 -0
  98. package/dist/lib/action-suggestions.js.map +1 -0
  99. package/dist/lib/chat-first-app-route.d.ts +11 -5
  100. package/dist/lib/chat-first-app-route.d.ts.map +1 -1
  101. package/dist/lib/chat-first-app-route.js +9 -5
  102. package/dist/lib/chat-first-app-route.js.map +1 -1
  103. package/dist/lib/chat-first-pane.d.ts +25 -1
  104. package/dist/lib/chat-first-pane.d.ts.map +1 -1
  105. package/dist/lib/chat-first-pane.js +67 -1
  106. package/dist/lib/chat-first-pane.js.map +1 -1
  107. package/dist/lib/data-intent.d.ts +3 -0
  108. package/dist/lib/data-intent.d.ts.map +1 -0
  109. package/dist/lib/data-intent.js +14 -0
  110. package/dist/lib/data-intent.js.map +1 -0
  111. package/dist/lib/dispatch-app-identity.d.ts +10 -0
  112. package/dist/lib/dispatch-app-identity.d.ts.map +1 -0
  113. package/dist/lib/dispatch-app-identity.js +18 -0
  114. package/dist/lib/dispatch-app-identity.js.map +1 -0
  115. package/dist/lib/other-apps.d.ts +15 -0
  116. package/dist/lib/other-apps.d.ts.map +1 -1
  117. package/dist/lib/other-apps.js +31 -0
  118. package/dist/lib/other-apps.js.map +1 -1
  119. package/dist/lib/workspace-app-frame-view.d.ts +15 -0
  120. package/dist/lib/workspace-app-frame-view.d.ts.map +1 -0
  121. package/dist/lib/workspace-app-frame-view.js +72 -0
  122. package/dist/lib/workspace-app-frame-view.js.map +1 -0
  123. package/dist/lib/workspace-apps.d.ts +5 -0
  124. package/dist/lib/workspace-apps.d.ts.map +1 -1
  125. package/dist/lib/workspace-apps.js +85 -23
  126. package/dist/lib/workspace-apps.js.map +1 -1
  127. package/dist/lib/workspace-apps.test.js +6 -0
  128. package/dist/lib/workspace-apps.test.js.map +1 -1
  129. package/dist/routes/pages/_index.d.ts +2 -2
  130. package/dist/routes/pages/chat.d.ts.map +1 -1
  131. package/dist/routes/pages/chat.js +33 -2
  132. package/dist/routes/pages/chat.js.map +1 -1
  133. package/dist/routes/pages/settings-page.d.ts +1 -1
  134. package/dist/routes/pages/settings-page.d.ts.map +1 -1
  135. package/dist/routes/pages/settings-page.js +3 -2
  136. package/dist/routes/pages/settings-page.js.map +1 -1
  137. package/dist/server/index.d.ts +4 -1
  138. package/dist/server/index.d.ts.map +1 -1
  139. package/dist/server/index.js +5 -5
  140. package/dist/server/index.js.map +1 -1
  141. package/dist/server/lib/action-suggestions.d.ts +41 -0
  142. package/dist/server/lib/action-suggestions.d.ts.map +1 -0
  143. package/dist/server/lib/action-suggestions.js +94 -0
  144. package/dist/server/lib/action-suggestions.js.map +1 -0
  145. package/dist/server/lib/app-action-result.d.ts +5 -0
  146. package/dist/server/lib/app-action-result.d.ts.map +1 -1
  147. package/dist/server/lib/app-action-result.js +7 -0
  148. package/dist/server/lib/app-action-result.js.map +1 -1
  149. package/dist/server/lib/app-creation-store.d.ts.map +1 -1
  150. package/dist/server/lib/app-creation-store.js +63 -13
  151. package/dist/server/lib/app-creation-store.js.map +1 -1
  152. package/dist/server/lib/curated-workspace-templates.d.ts.map +1 -1
  153. package/dist/server/lib/curated-workspace-templates.js +3 -0
  154. package/dist/server/lib/curated-workspace-templates.js.map +1 -1
  155. package/dist/server/lib/dispatch-config.d.ts +5 -0
  156. package/dist/server/lib/dispatch-config.d.ts.map +1 -0
  157. package/dist/server/lib/dispatch-config.js +11 -0
  158. package/dist/server/lib/dispatch-config.js.map +1 -0
  159. package/dist/server/lib/dispatch-pane-context.d.ts +11 -0
  160. package/dist/server/lib/dispatch-pane-context.d.ts.map +1 -0
  161. package/dist/server/lib/dispatch-pane-context.js +35 -0
  162. package/dist/server/lib/dispatch-pane-context.js.map +1 -0
  163. package/dist/server/lib/google-broker-provider.d.ts +41 -0
  164. package/dist/server/lib/google-broker-provider.d.ts.map +1 -0
  165. package/dist/server/lib/google-broker-provider.js +96 -0
  166. package/dist/server/lib/google-broker-provider.js.map +1 -0
  167. package/dist/server/lib/google-broker-rpc.d.ts +26 -0
  168. package/dist/server/lib/google-broker-rpc.d.ts.map +1 -0
  169. package/dist/server/lib/google-broker-rpc.js +52 -0
  170. package/dist/server/lib/google-broker-rpc.js.map +1 -0
  171. package/dist/server/lib/hosted-apps-settings.d.ts.map +1 -1
  172. package/dist/server/lib/hosted-apps-settings.js +4 -0
  173. package/dist/server/lib/hosted-apps-settings.js.map +1 -1
  174. package/dist/server/lib/mcp-app-discovery.d.ts +17 -0
  175. package/dist/server/lib/mcp-app-discovery.d.ts.map +1 -0
  176. package/dist/server/lib/mcp-app-discovery.js +231 -0
  177. package/dist/server/lib/mcp-app-discovery.js.map +1 -0
  178. package/dist/server/lib/mcp-gateway.d.ts +64 -21
  179. package/dist/server/lib/mcp-gateway.d.ts.map +1 -1
  180. package/dist/server/lib/mcp-gateway.js +730 -88
  181. package/dist/server/lib/mcp-gateway.js.map +1 -1
  182. package/dist/server/plugins/agent-chat.js +9 -7
  183. package/dist/server/plugins/agent-chat.js.map +1 -1
  184. package/dist/server/plugins/auth.d.ts.map +1 -1
  185. package/dist/server/plugins/auth.js +1 -0
  186. package/dist/server/plugins/auth.js.map +1 -1
  187. package/dist/server/plugins/db.d.ts.map +1 -1
  188. package/dist/server/plugins/db.js +0 -46
  189. package/dist/server/plugins/db.js.map +1 -1
  190. package/dist/server/plugins/integrations.d.ts.map +1 -1
  191. package/dist/server/plugins/integrations.js +4 -1
  192. package/dist/server/plugins/integrations.js.map +1 -1
  193. package/dist/shared/chat-first-pane.d.ts +24 -0
  194. package/dist/shared/chat-first-pane.d.ts.map +1 -1
  195. package/dist/shared/chat-first-pane.js +34 -0
  196. package/dist/shared/chat-first-pane.js.map +1 -1
  197. package/dist/shared/labs.d.ts +1 -0
  198. package/dist/shared/labs.d.ts.map +1 -1
  199. package/dist/shared/labs.js +7 -0
  200. package/dist/shared/labs.js.map +1 -1
  201. package/package.json +7 -6
  202. package/src/actions/action-suggestions.spec.ts +342 -0
  203. package/src/actions/app_actions.spec.ts +103 -0
  204. package/src/actions/ask_app.ts +9 -2
  205. package/src/actions/ask_app_status.ts +12 -1
  206. package/src/actions/call_app_action.ts +28 -8
  207. package/src/actions/create_embed_session.ts +8 -2
  208. package/src/actions/create_workspace_app_embed_session.ts +6 -1
  209. package/src/actions/execute-action-suggestion.ts +177 -0
  210. package/src/actions/index.spec.ts +6 -3
  211. package/src/actions/index.ts +5 -1
  212. package/src/actions/list-connected-agents.spec.ts +26 -1
  213. package/src/actions/list-connected-agents.ts +7 -4
  214. package/src/actions/list_app_actions.ts +1 -1
  215. package/src/actions/list_apps.spec.ts +58 -22
  216. package/src/actions/list_apps.ts +12 -5
  217. package/src/actions/navigate.ts +1 -0
  218. package/src/actions/open_app.spec.ts +17 -1
  219. package/src/actions/open_app.ts +21 -8
  220. package/src/actions/propose-action-suggestions.ts +42 -0
  221. package/src/actions/read_view.ts +1 -1
  222. package/src/actions/remember-pointer.ts +1 -1
  223. package/src/actions/resolve-pointer.ts +1 -1
  224. package/src/actions/route-app-intent.spec.ts +234 -5
  225. package/src/actions/route-app-intent.ts +89 -4
  226. package/src/actions/send-code-agent-remote-command.spec.ts +40 -0
  227. package/src/actions/send-code-agent-remote-command.ts +5 -0
  228. package/src/actions/start-workspace-app-creation.ts +1 -1
  229. package/src/actions/view-screen.bundle.spec.ts +15 -2
  230. package/src/actions/view-screen.spec.ts +81 -3
  231. package/src/actions/view-screen.ts +60 -4
  232. package/src/components/chat-action-suggestions.spec.tsx +362 -0
  233. package/src/components/chat-action-suggestions.tsx +432 -0
  234. package/src/components/chat-home-apps.spec.tsx +19 -0
  235. package/src/components/chat-home-apps.tsx +0 -1
  236. package/src/components/google-broker-settings-group.tsx +186 -0
  237. package/src/components/layout/Layout.spec.tsx +419 -28
  238. package/src/components/layout/Layout.tsx +304 -66
  239. package/src/components/messaging-setup-panel.spec.tsx +278 -4
  240. package/src/components/messaging-setup-panel.tsx +82 -19
  241. package/src/components/workspace-app-card.spec.tsx +79 -10
  242. package/src/components/workspace-app-chat-rail.spec.tsx +81 -3
  243. package/src/components/workspace-app-host.spec.tsx +269 -16
  244. package/src/components/workspace-app-host.tsx +464 -87
  245. package/src/config.ts +5 -0
  246. package/src/db/google-broker-admission.ts +160 -0
  247. package/src/db/migrations.spec.ts +165 -2
  248. package/src/db/migrations.ts +43 -1
  249. package/src/lib/action-suggestions.ts +267 -0
  250. package/src/lib/chat-first-app-route.spec.ts +15 -2
  251. package/src/lib/chat-first-app-route.ts +19 -7
  252. package/src/lib/chat-first-pane.spec.ts +71 -0
  253. package/src/lib/chat-first-pane.ts +101 -4
  254. package/src/lib/data-intent.spec.ts +21 -0
  255. package/src/lib/data-intent.ts +13 -0
  256. package/src/lib/dispatch-app-identity.ts +40 -0
  257. package/src/lib/other-apps.spec.ts +110 -1
  258. package/src/lib/other-apps.ts +41 -0
  259. package/src/lib/workspace-app-frame-view.spec.ts +13 -0
  260. package/src/lib/workspace-app-frame-view.ts +98 -0
  261. package/src/lib/workspace-apps.spec.ts +101 -0
  262. package/src/lib/workspace-apps.test.ts +18 -0
  263. package/src/lib/workspace-apps.ts +102 -24
  264. package/src/routes/pages/chat.spec.tsx +92 -1
  265. package/src/routes/pages/chat.tsx +41 -2
  266. package/src/routes/pages/settings-page.tsx +22 -17
  267. package/src/routes/pages/settings.spec.tsx +4 -0
  268. package/src/server/index.ts +6 -6
  269. package/src/server/lib/action-suggestions.ts +122 -0
  270. package/src/server/lib/app-action-result.ts +8 -0
  271. package/src/server/lib/app-creation-store.spec.ts +251 -0
  272. package/src/server/lib/app-creation-store.ts +72 -12
  273. package/src/server/lib/community-apps.spec.ts +19 -1
  274. package/src/server/lib/curated-workspace-templates.spec.ts +12 -0
  275. package/src/server/lib/curated-workspace-templates.ts +2 -0
  276. package/src/server/lib/dispatch-config.ts +15 -0
  277. package/src/server/lib/dispatch-pane-context.spec.ts +54 -0
  278. package/src/server/lib/dispatch-pane-context.ts +54 -0
  279. package/src/server/lib/google-broker-provider.ts +121 -0
  280. package/src/server/lib/google-broker-rpc.spec.ts +95 -0
  281. package/src/server/lib/google-broker-rpc.ts +107 -0
  282. package/src/server/lib/hosted-apps-settings.ts +4 -0
  283. package/src/server/lib/mcp-app-discovery.ts +318 -0
  284. package/src/server/lib/mcp-gateway.spec.ts +2252 -524
  285. package/src/server/lib/mcp-gateway.ts +1044 -181
  286. package/src/server/plugins/agent-chat.direct-mcp.spec.ts +84 -5
  287. package/src/server/plugins/agent-chat.ts +9 -7
  288. package/src/server/plugins/auth.spec.ts +5 -1
  289. package/src/server/plugins/auth.ts +1 -0
  290. package/src/server/plugins/db.ts +0 -51
  291. package/src/server/plugins/integrations.ts +4 -1
  292. package/src/shared/chat-first-pane.spec.ts +36 -0
  293. package/src/shared/chat-first-pane.ts +55 -0
  294. package/src/shared/labs.ts +8 -0
  295. package/src/server/plugins/agent-chat.spec.ts +0 -206
  296. package/src/server/plugins/integrations.spec.ts +0 -60
@@ -12,6 +12,16 @@ const base = {
12
12
  };
13
13
 
14
14
  describe("planChatFirstAppRoute pointers", () => {
15
+ it("does not open an uncertain route", () => {
16
+ expect(
17
+ planChatFirstAppRoute({
18
+ ...base,
19
+ shownAppId: null,
20
+ answer: { status: "ok", app: "tasks-2", confidence: 0.7 },
21
+ }),
22
+ ).toEqual({ kind: "skip", reason: "low_confidence" });
23
+ });
24
+
15
25
  it("passes a pointer's object to the target", () => {
16
26
  expect(
17
27
  planChatFirstAppRoute({
@@ -20,12 +30,13 @@ describe("planChatFirstAppRoute pointers", () => {
20
30
  answer: {
21
31
  status: "ok",
22
32
  app: "content",
33
+ confidence: 1,
23
34
  pointer: true,
24
35
  url: "https://x/y",
25
36
  },
26
37
  }),
27
38
  ).toEqual({
28
- kind: "open",
39
+ kind: "warm",
29
40
  target: { appId: "content", url: "https://x/y" },
30
41
  });
31
42
  });
@@ -34,7 +45,9 @@ describe("planChatFirstAppRoute pointers", () => {
34
45
  const answer = {
35
46
  status: "ok" as const,
36
47
  app: "content",
48
+ confidence: 1,
37
49
  pointer: true,
50
+ explicit: true as const,
38
51
  url: "https://x/y",
39
52
  };
40
53
  expect(
@@ -44,7 +57,7 @@ describe("planChatFirstAppRoute pointers", () => {
44
57
  planChatFirstAppRoute({
45
58
  ...base,
46
59
  shownAppId: "content",
47
- answer: { status: "ok", app: "content" },
60
+ answer: { status: "ok", app: "content", confidence: 1 },
48
61
  }),
49
62
  ).toEqual({ kind: "skip", reason: "shown" });
50
63
  });
@@ -2,6 +2,11 @@ export type ChatFirstAppRouteAnswer =
2
2
  | {
3
3
  status: "ok";
4
4
  app: string;
5
+ confidence?: number;
6
+ explicit?: true;
7
+ /** Until app screen bindings are discoverable, only the registered home is routable. */
8
+ screen?: "home";
9
+ params?: Record<string, string>;
5
10
  cached?: boolean;
6
11
  latencyMs?: number;
7
12
  model?: string;
@@ -14,6 +19,7 @@ export type ChatFirstAppRouteAnswer =
14
19
 
15
20
  export type ChatFirstAppRouteSkip =
16
21
  | "none"
22
+ | "low_confidence"
17
23
  | "not_configured"
18
24
  | "failed"
19
25
  | "timeout"
@@ -23,13 +29,12 @@ export type ChatFirstAppRouteSkip =
23
29
  | "stale";
24
30
 
25
31
  export type ChatFirstAppRoutePlan<Target = { appId: string }> =
26
- | { kind: "open"; target: Target }
32
+ | { kind: "open" | "warm"; target: Target }
27
33
  | { kind: "skip"; reason: ChatFirstAppRouteSkip };
28
34
 
29
35
  /**
30
- * What an early route answer may do to the pane. It opens only an installed
31
- * app other than Dispatch and the one already shown, and only while nothing has
32
- * changed the pane since the send.
36
+ * Warm a likely installed app while the pane still matches the send. Only
37
+ * an explicit choice can commit a visible pane before the tool handoff.
33
38
  */
34
39
  export function planChatFirstAppRoute<Target extends { appId: string }>(input: {
35
40
  answer: ChatFirstAppRouteAnswer | "timeout";
@@ -44,6 +49,13 @@ export function planChatFirstAppRoute<Target extends { appId: string }>(input: {
44
49
  const { answer } = input;
45
50
  if (answer === "timeout") return { kind: "skip", reason: "timeout" };
46
51
  if (answer.status !== "ok") return { kind: "skip", reason: answer.status };
52
+ if (
53
+ typeof answer.confidence !== "number" ||
54
+ !Number.isFinite(answer.confidence) ||
55
+ answer.confidence < 0.85 ||
56
+ answer.confidence > 1
57
+ )
58
+ return { kind: "skip", reason: "low_confidence" };
47
59
  if (answer.app === "none") return { kind: "skip", reason: "none" };
48
60
  const object = answer.pointer
49
61
  ? { url: answer.url, objectId: answer.objectId }
@@ -60,7 +72,7 @@ export function planChatFirstAppRoute<Target extends { appId: string }>(input: {
60
72
  return { kind: "skip", reason: "shown" };
61
73
  }
62
74
  if (input.stale) return { kind: "skip", reason: "stale" };
63
- return { kind: "open", target };
75
+ return { kind: answer.explicit === true ? "open" : "warm", target };
64
76
  }
65
77
 
66
78
  export type ChatFirstAppRouteRecord = {
@@ -77,11 +89,11 @@ export type ChatFirstAppRouteRecord = {
77
89
  * closed or switched since the send, by the agent or the person, changes it.
78
90
  */
79
91
  export function chatFirstPaneSignature(snapshot: {
80
- tabs: ReadonlyArray<{ id: string }>;
92
+ tabs: ReadonlyArray<{ id: string; path?: string; view?: string }>;
81
93
  activeTabId: string | null;
82
94
  }): string {
83
95
  return JSON.stringify([
84
96
  snapshot.activeTabId,
85
- snapshot.tabs.map((tab) => tab.id),
97
+ snapshot.tabs.map((tab) => [tab.id, tab.path, tab.view]),
86
98
  ]);
87
99
  }
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
 
3
3
  import {
4
+ createTurnViewportLock,
4
5
  delegatedAppFromToolStart,
5
6
  visibleChatFirstSurfaceTabId,
6
7
  } from "./chat-first-pane";
@@ -91,5 +92,75 @@ describe("delegatedAppFromToolStart", () => {
91
92
  input: { agent: "https://example.com/agent" },
92
93
  }),
93
94
  ).toBeNull();
95
+ expect(
96
+ delegatedAppFromToolStart({
97
+ tool: "ask_app",
98
+ input: {
99
+ app: "content-2",
100
+ message: "lookup notes",
101
+ viewportMode: "background",
102
+ },
103
+ }),
104
+ ).toBeNull();
105
+ expect(
106
+ delegatedAppFromToolStart({
107
+ tool: "call_app_action",
108
+ input: {
109
+ app: "content-2",
110
+ action: "search-docs",
111
+ viewportMode: "background",
112
+ },
113
+ }),
114
+ ).toBeNull();
115
+ });
116
+ });
117
+
118
+ describe("createTurnViewportLock", () => {
119
+ it("locks the foreground app for the turn and blocks secondary lookups without focus: true", () => {
120
+ const lock = createTurnViewportLock();
121
+ lock.beginTurn("turn-1");
122
+
123
+ expect(
124
+ lock.evaluate({ appId: "meeting-notes-2", turnKey: "turn-1" }),
125
+ ).toEqual({
126
+ allowed: true,
127
+ lockedAppId: "meeting-notes-2",
128
+ });
129
+
130
+ expect(
131
+ lock.evaluate({ appId: "meeting-notes-2", turnKey: "turn-1" }),
132
+ ).toEqual({
133
+ allowed: true,
134
+ lockedAppId: "meeting-notes-2",
135
+ });
136
+
137
+ expect(lock.evaluate({ appId: "content-2", turnKey: "turn-1" })).toEqual({
138
+ allowed: false,
139
+ lockedAppId: "meeting-notes-2",
140
+ });
141
+
142
+ expect(
143
+ lock.evaluate({
144
+ appId: "content-2",
145
+ focus: true,
146
+ viewportMode: "background",
147
+ turnKey: "turn-1",
148
+ }),
149
+ ).toEqual({
150
+ allowed: false,
151
+ lockedAppId: "meeting-notes-2",
152
+ });
153
+
154
+ expect(
155
+ lock.evaluate({ appId: "content-2", focus: true, turnKey: "turn-1" }),
156
+ ).toEqual({
157
+ allowed: true,
158
+ lockedAppId: "content-2",
159
+ });
160
+
161
+ expect(lock.evaluate({ appId: "decks-2", turnKey: "turn-2" })).toEqual({
162
+ allowed: true,
163
+ lockedAppId: "decks-2",
164
+ });
94
165
  });
95
166
  });
@@ -1,4 +1,30 @@
1
- import type { ChatFirstSurfaceTab } from "@agent-native/core/client/chat-first-state";
1
+ import {
2
+ resolveChatFirstAppTarget,
3
+ type ChatFirstAppRegistration,
4
+ type ChatFirstAppResolution,
5
+ type ChatFirstOpenAppDetail,
6
+ type ChatFirstSurfaceTab,
7
+ } from "@agent-native/core/client/chat-first-state";
8
+
9
+ export function resolveDispatchChatFirstAppTarget(
10
+ detail: ChatFirstOpenAppDetail,
11
+ apps: readonly ChatFirstAppRegistration[],
12
+ options?: { currentOrigin?: string },
13
+ ): ChatFirstAppResolution {
14
+ const requested = detail.app?.trim().toLowerCase();
15
+ if (!requested) return resolveChatFirstAppTarget(detail, apps, options);
16
+
17
+ const enabled = apps.filter((app) => app.enabled !== false);
18
+ const exact = enabled.find((app) => app.id.toLowerCase() === requested);
19
+ if (exact) return resolveChatFirstAppTarget(detail, [exact], options);
20
+
21
+ const named = enabled.filter(
22
+ (app) => app.name?.trim().toLowerCase() === requested,
23
+ );
24
+ return !requested.includes("/") && named.length === 1
25
+ ? resolveChatFirstAppTarget(detail, named, options)
26
+ : { status: "unresolved", reason: "unknown-app" };
27
+ }
2
28
 
3
29
  /**
4
30
  * The tab the side panel shows.
@@ -43,11 +69,82 @@ export function delegatedAppFromToolStart(
43
69
  if (!key) return null;
44
70
  const input = detail.input;
45
71
  if (!input || typeof input !== "object") return null;
46
- const value = (input as Record<string, unknown>)[
47
- key === "agent" ? "agent" : "app"
48
- ];
72
+ const record = input as Record<string, unknown>;
73
+ if (
74
+ typeof record.viewportMode === "string" &&
75
+ record.viewportMode.trim().toLowerCase() === "background"
76
+ ) {
77
+ return null;
78
+ }
79
+ const value = record[key === "agent" ? "agent" : "app"];
49
80
  if (typeof value !== "string") return null;
50
81
  const id = value.trim().toLowerCase();
51
82
  if (!APP_ID_PATTERN.test(id) || id === "dispatch") return null;
52
83
  return id;
53
84
  }
85
+
86
+ export interface TurnViewportLockEvaluation {
87
+ allowed: boolean;
88
+ lockedAppId: string | null;
89
+ }
90
+
91
+ export interface TurnViewportLock {
92
+ beginTurn: (turnKey?: string) => void;
93
+ clear: () => void;
94
+ getLockedAppId: () => string | null;
95
+ evaluate: (request: {
96
+ appId: string;
97
+ focus?: boolean | undefined;
98
+ turnKey?: string | undefined;
99
+ viewportMode?: "foreground" | "background" | undefined;
100
+ }) => TurnViewportLockEvaluation;
101
+ }
102
+
103
+ /**
104
+ * Turn-scoped foreground viewport lock: once a turn commits a foreground app,
105
+ * secondary or background lookups targeting another app cannot overwrite the
106
+ * visible pane unless `focus: true` is explicitly passed.
107
+ */
108
+ export function createTurnViewportLock(): TurnViewportLock {
109
+ let currentTurnKey: string | null = null;
110
+ let lockedAppId: string | null = null;
111
+
112
+ return {
113
+ beginTurn(turnKey?: string) {
114
+ currentTurnKey = turnKey ?? null;
115
+ lockedAppId = null;
116
+ },
117
+ clear() {
118
+ currentTurnKey = null;
119
+ lockedAppId = null;
120
+ },
121
+ getLockedAppId() {
122
+ return lockedAppId;
123
+ },
124
+ evaluate(request) {
125
+ const normalizedAppId = request.appId.trim().toLowerCase();
126
+ if (!normalizedAppId) {
127
+ return { allowed: false, lockedAppId };
128
+ }
129
+ if (request.viewportMode === "background") {
130
+ return { allowed: false, lockedAppId };
131
+ }
132
+ if (request.turnKey !== undefined && request.turnKey !== currentTurnKey) {
133
+ currentTurnKey = request.turnKey;
134
+ lockedAppId = null;
135
+ }
136
+ if (lockedAppId === null) {
137
+ lockedAppId = normalizedAppId;
138
+ return { allowed: true, lockedAppId };
139
+ }
140
+ if (lockedAppId === normalizedAppId) {
141
+ return { allowed: true, lockedAppId };
142
+ }
143
+ if (request.focus === true) {
144
+ lockedAppId = normalizedAppId;
145
+ return { allowed: true, lockedAppId };
146
+ }
147
+ return { allowed: false, lockedAppId };
148
+ },
149
+ };
150
+ }
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { classifyDataIntent } from "./data-intent.js";
4
+
5
+ describe("classifyDataIntent", () => {
6
+ it.each([
7
+ ["show me GitHub messages from actual people", "mail"],
8
+ ["show emails about GitHub issues", "mail"],
9
+ ["open my GitHub inbox", "mail"],
10
+ ["find messages from people", "mail"],
11
+ ["show my GitHub issues", "tasks"],
12
+ ["open GitHub pull requests", "tasks"],
13
+ ["list GitHub PRs assigned to me", "tasks"],
14
+ ["show messages on GitHub pull request 12", "tasks"],
15
+ ["list GitHub issues with the message mentioning timeout", "tasks"],
16
+ ["what is on my calendar", null],
17
+ ["show my pull requests", null],
18
+ ])("classifies %s as %s", (text, app) => {
19
+ expect(classifyDataIntent(text)).toBe(app);
20
+ });
21
+ });
@@ -0,0 +1,13 @@
1
+ const MAIL_STRONG = /\b(?:e-?mails?|inbox)\b/i;
2
+ const MAIL_WEAK = /\bmessages?\b/i;
3
+ const GITHUB = /\bgithub\b/i;
4
+ const GITHUB_RECORD = /\b(?:issues?|pull requests?|prs?)\b/i;
5
+
6
+ export type DataIntentApp = "mail" | "tasks";
7
+
8
+ export function classifyDataIntent(text: string): DataIntentApp | null {
9
+ if (MAIL_STRONG.test(text)) return "mail";
10
+ if (GITHUB.test(text) && GITHUB_RECORD.test(text)) return "tasks";
11
+ if (MAIL_WEAK.test(text)) return "mail";
12
+ return null;
13
+ }
@@ -0,0 +1,40 @@
1
+ type DispatchAppIdentity = {
2
+ id: string;
3
+ name: string;
4
+ aliases?: string[];
5
+ source?:
6
+ | "workspace"
7
+ | "org-directory"
8
+ | "remote-agent"
9
+ | "builtin"
10
+ | undefined;
11
+ granted?: boolean;
12
+ };
13
+
14
+ export function matchDispatchAppCandidates<App extends DispatchAppIdentity>(
15
+ apps: readonly App[],
16
+ requested: string,
17
+ ): App[] {
18
+ const target = requested.trim().toLowerCase();
19
+ if (!target) return [];
20
+ const exact = apps.filter((app) => app.id.toLowerCase() === target);
21
+ if (exact.length || target.includes("/")) return exact;
22
+
23
+ const granted = apps.filter((app) => app.granted !== false);
24
+ const qualified = granted.filter((app) =>
25
+ app.id.toLowerCase().endsWith(`/${target}`),
26
+ );
27
+ const named = granted.filter((app) =>
28
+ [app.name, ...(app.aliases ?? [])].some(
29
+ (name) => name.trim().toLowerCase() === target,
30
+ ),
31
+ );
32
+ const workspace = [...new Set([...qualified, ...named])].filter(
33
+ (app) =>
34
+ app.source === "workspace" ||
35
+ app.source === "org-directory" ||
36
+ (app.source !== "builtin" && qualified.includes(app)),
37
+ );
38
+ if (workspace.length) return workspace;
39
+ return qualified.length ? qualified : named;
40
+ }
@@ -1,6 +1,10 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
 
3
- import { filterBuiltInApps, filterOtherApps } from "./other-apps.js";
3
+ import {
4
+ chatFirstExternalApps,
5
+ filterBuiltInApps,
6
+ filterOtherApps,
7
+ } from "./other-apps.js";
4
8
 
5
9
  describe("filterBuiltInApps", () => {
6
10
  it("keeps configured first-party apps not mounted in the workspace", () => {
@@ -295,3 +299,108 @@ describe("filterOtherApps", () => {
295
299
  ]);
296
300
  });
297
301
  });
302
+
303
+ describe("connected apps in the chat-first pane", () => {
304
+ it("opens an app connected from another workspace at its own origin", async () => {
305
+ const { resolveChatFirstAppTarget } =
306
+ await import("@agent-native/core/client/agent-chat");
307
+ const { mergeChatFirstWorkspaceApps } = await import("./workspace-apps.js");
308
+ const mounted = [{ id: "mail-2", name: "Mail", path: "/mail-2" }];
309
+ const apps = mergeChatFirstWorkspaceApps(
310
+ mounted,
311
+ [],
312
+ chatFirstExternalApps(
313
+ [
314
+ {
315
+ id: "fleet",
316
+ name: "Fleet",
317
+ url: "https://agent-workspace.example.com/fleet",
318
+ source: "custom",
319
+ },
320
+ ],
321
+ mounted,
322
+ ),
323
+ );
324
+ const registrations = apps.map((app) => ({
325
+ id: app.id,
326
+ name: app.name,
327
+ source: app.source,
328
+ path: app.path,
329
+ url: app.url,
330
+ enabled: true,
331
+ }));
332
+
333
+ expect(
334
+ resolveChatFirstAppTarget(
335
+ {
336
+ app: "fleet",
337
+ url: "https://agent-workspace.example.com/fleet/home",
338
+ },
339
+ registrations,
340
+ { currentOrigin: "https://labs.example.com" },
341
+ ),
342
+ ).toEqual({ status: "ready", target: { appId: "fleet", path: "/home" } });
343
+ expect(
344
+ resolveChatFirstAppTarget(
345
+ { url: "https://agent-workspace.example.com/other/home" },
346
+ registrations,
347
+ { currentOrigin: "https://labs.example.com" },
348
+ ),
349
+ ).toEqual({ status: "unresolved", reason: "unknown-app" });
350
+ });
351
+ });
352
+
353
+ describe("chatFirstExternalApps", () => {
354
+ const connected = [
355
+ {
356
+ id: "slides",
357
+ name: "Slides",
358
+ url: "https://slides.example.com/deck",
359
+ homeUrl: "https://slides.example.com/home",
360
+ source: "builtin" as const,
361
+ hiddenFromLaunchers: true,
362
+ },
363
+ {
364
+ id: "fleet",
365
+ name: "Fleet",
366
+ description: "Fleet dashboard",
367
+ url: "https://agent-workspace.example.com/fleet",
368
+ source: "custom" as const,
369
+ },
370
+ {
371
+ id: "mail-2",
372
+ name: "Mail elsewhere",
373
+ url: "https://elsewhere.example.com/mail-2",
374
+ source: "custom" as const,
375
+ },
376
+ ];
377
+
378
+ it("lists hosted apps at their home URL, keeps hidden ones, and tags connected apps", () => {
379
+ expect(chatFirstExternalApps(connected, [{ id: "mail-2" }])).toEqual([
380
+ {
381
+ id: "slides",
382
+ name: "Slides",
383
+ url: "https://slides.example.com/home",
384
+ source: "builtin",
385
+ hiddenFromLaunchers: true,
386
+ },
387
+ {
388
+ id: "fleet",
389
+ name: "Fleet",
390
+ description: "Fleet dashboard",
391
+ url: "https://agent-workspace.example.com/fleet",
392
+ source: "connected",
393
+ },
394
+ ]);
395
+ });
396
+
397
+ it("lists nothing while the mounted app list is loading", () => {
398
+ expect(chatFirstExternalApps(connected, "loading")).toEqual([]);
399
+ });
400
+
401
+ it("keeps every hosted and connected app when the mounted list is unreadable", () => {
402
+ expect(
403
+ chatFirstExternalApps(connected, "unreadable").map((app) => app.id),
404
+ ).toEqual(["slides", "fleet", "mail-2"]);
405
+ });
406
+ });
@@ -101,3 +101,44 @@ export function filterBuiltInApps(
101
101
  }))
102
102
  .sort((a, b) => a.name.localeCompare(b.name));
103
103
  }
104
+
105
+ /**
106
+ * Apps outside this workspace that the chat-first pane can open: first-party
107
+ * hosted apps and apps connected from another workspace. None while the
108
+ * mounted list is loading, so an external row never stands in for a mounted
109
+ * app with the same id. When the mounted list is unreadable they are all
110
+ * kept, since no mounted app can be shown to shadow them.
111
+ */
112
+ export function chatFirstExternalApps(
113
+ connectedApps: ConnectedAppSummary[],
114
+ workspaceApps: WorkspaceAppId[] | "loading" | "unreadable",
115
+ ): {
116
+ id: string;
117
+ name: string;
118
+ description?: string;
119
+ url: string;
120
+ source: "builtin" | "connected";
121
+ hiddenFromLaunchers?: boolean;
122
+ }[] {
123
+ if (workspaceApps === "loading") return [];
124
+ const mounted = workspaceApps === "unreadable" ? [] : workspaceApps;
125
+ const summary = (app: ConnectedAppSummary, url: string) => ({
126
+ id: app.id,
127
+ name: app.name,
128
+ ...(app.description === undefined ? {} : { description: app.description }),
129
+ url,
130
+ });
131
+ return [
132
+ ...filterBuiltInApps(connectedApps, mounted, {
133
+ includeHiddenFromLaunchers: true,
134
+ }).map((app) => ({
135
+ ...summary(app, app.homeUrl?.trim() || app.url),
136
+ source: "builtin" as const,
137
+ ...(app.hiddenFromLaunchers ? { hiddenFromLaunchers: true } : {}),
138
+ })),
139
+ ...filterOtherApps(connectedApps, mounted).map((app) => ({
140
+ ...summary(app, app.url),
141
+ source: "connected" as const,
142
+ })),
143
+ ];
144
+ }
@@ -0,0 +1,13 @@
1
+ import { expect, it } from "vitest";
2
+
3
+ import { workspaceAppFramePath } from "./workspace-app-frame-view.js";
4
+
5
+ it("keeps the app route while excluding the private child tab claim", () => {
6
+ expect(
7
+ workspaceAppFramePath(
8
+ new URL(
9
+ "https://app.example.test/inbox?agentNativeTab=fixture&sort=new#unread",
10
+ ),
11
+ ),
12
+ ).toBe("/inbox?sort=new#unread");
13
+ });
@@ -0,0 +1,98 @@
1
+ import { EMBED_TOKEN_QUERY_PARAM } from "@agent-native/core/shared";
2
+
3
+ import { DISPATCH_CHILD_BROWSER_TAB_PARAM } from "../shared/chat-first-pane";
4
+
5
+ const VIEW_REQUEST_TIMEOUT_MS = 1_000;
6
+
7
+ export interface WorkspaceAppFrameView {
8
+ path: string;
9
+ title?: string;
10
+ selectedText?: string;
11
+ }
12
+
13
+ export function workspaceAppFramePath(url: URL): string {
14
+ const safe = new URL(url);
15
+ if (safe.searchParams.has(EMBED_TOKEN_QUERY_PARAM)) {
16
+ safe.searchParams.delete(EMBED_TOKEN_QUERY_PARAM);
17
+ }
18
+ if (safe.searchParams.has(DISPATCH_CHILD_BROWSER_TAB_PARAM)) {
19
+ safe.searchParams.delete(DISPATCH_CHILD_BROWSER_TAB_PARAM);
20
+ }
21
+ return safe.pathname + safe.search + safe.hash;
22
+ }
23
+
24
+ export function workspaceAppFramePathAtMount(
25
+ url: URL,
26
+ mount: URL,
27
+ ): string | null {
28
+ const base = mount.pathname.replace(/\/+$/, "");
29
+ if (
30
+ url.origin !== mount.origin ||
31
+ (url.pathname !== base && !url.pathname.startsWith(`${base}/`))
32
+ ) {
33
+ return null;
34
+ }
35
+ return workspaceAppFramePath(url);
36
+ }
37
+
38
+ /** A transferred port belongs to this request and only reaches the named origin. */
39
+ export function requestWorkspaceAppFrameView(
40
+ target: Window,
41
+ origin: string,
42
+ request: { operation: "read" } | { operation: "navigate"; path: string },
43
+ signal: AbortSignal,
44
+ ): Promise<WorkspaceAppFrameView | null> {
45
+ if (signal.aborted || typeof MessageChannel === "undefined") {
46
+ return Promise.resolve(null);
47
+ }
48
+ return new Promise((resolve) => {
49
+ const channel = new MessageChannel();
50
+ const finish = (view: WorkspaceAppFrameView | null) => {
51
+ window.clearTimeout(timer);
52
+ signal.removeEventListener("abort", abort);
53
+ channel.port1.close();
54
+ resolve(view);
55
+ };
56
+ const abort = () => finish(null);
57
+ const timer = window.setTimeout(abort, VIEW_REQUEST_TIMEOUT_MS);
58
+ signal.addEventListener("abort", abort, { once: true });
59
+ channel.port1.onmessage = ({ data }: MessageEvent<unknown>) => {
60
+ const view =
61
+ data && typeof data === "object" && "result" in data
62
+ ? data.result
63
+ : null;
64
+ finish(
65
+ view &&
66
+ typeof view === "object" &&
67
+ "path" in view &&
68
+ typeof view.path === "string" &&
69
+ view.path.startsWith("/") &&
70
+ !view.path.startsWith("//")
71
+ ? {
72
+ path: view.path,
73
+ ...("title" in view &&
74
+ typeof view.title === "string" && { title: view.title }),
75
+ ...("selectedText" in view &&
76
+ typeof view.selectedText === "string" && {
77
+ selectedText: view.selectedText,
78
+ }),
79
+ }
80
+ : null,
81
+ );
82
+ };
83
+ try {
84
+ target.postMessage(
85
+ {
86
+ type: "agentNative.viewRequest",
87
+ ...request,
88
+ deadline: Date.now() + VIEW_REQUEST_TIMEOUT_MS,
89
+ },
90
+ origin,
91
+ [channel.port2],
92
+ );
93
+ } catch {
94
+ channel.port2.close();
95
+ finish(null);
96
+ }
97
+ });
98
+ }