@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
@@ -2,6 +2,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
 
3
3
  const mocks = vi.hoisted(() => ({
4
4
  navigation: {} as Record<string, unknown>,
5
+ pane: null as Record<string, unknown> | null,
6
+ tab: { tabId: "parent-one", unavailable: false } as {
7
+ tabId: string | null;
8
+ unavailable: boolean;
9
+ },
5
10
  appState: {} as Record<string, unknown>,
6
11
  listAgentRunFailures: vi.fn(),
7
12
  listThreadDebugSources: vi.fn(),
@@ -14,6 +19,8 @@ vi.mock("@agent-native/core", () => ({
14
19
  }));
15
20
 
16
21
  vi.mock("@agent-native/core/application-state", () => ({
22
+ appStateKeyForBrowserTab: (key: string, tabId: string) => `${key}:${tabId}`,
23
+ resolveCurrentRequestStateTab: async () => mocks.tab,
17
24
  readAppState: vi.fn(async (key: string) =>
18
25
  key === "navigation" ? mocks.navigation : (mocks.appState[key] ?? null),
19
26
  ),
@@ -23,6 +30,10 @@ vi.mock("../server/lib/app-creation-store.js", () => ({
23
30
  listWorkspaceApps: vi.fn(),
24
31
  }));
25
32
 
33
+ vi.mock("../server/lib/dispatch-pane-context.js", () => ({
34
+ readDispatchPaneContext: async () => mocks.pane,
35
+ }));
36
+
26
37
  vi.mock("../server/lib/dispatch-store.js", () => ({
27
38
  listOverview: vi.fn(async () => ({
28
39
  counts: {},
@@ -58,6 +69,72 @@ vi.mock("../server/lib/workspace-resources-store.js", () => ({
58
69
 
59
70
  import viewScreen from "./view-screen.js";
60
71
 
72
+ describe("view-screen MCP exposure", () => {
73
+ it("returns current pane identity and paths over MCP without operational data", async () => {
74
+ mocks.navigation = { view: "overview", path: "/account-wide" };
75
+ mocks.appState = {
76
+ "navigation:parent-one": {
77
+ view: "chat",
78
+ path: "/chat/current?filter=private",
79
+ owner: "hidden",
80
+ },
81
+ "navigation:parent-two": { view: "apps", path: "/apps?filter=private" },
82
+ };
83
+ mocks.pane = {
84
+ appId: "workspace/mail",
85
+ path: "/mail/threads/2?filter=private",
86
+ };
87
+ expect(viewScreen.mcpTool).toBe(true);
88
+ expect(viewScreen.readOnly).toBe(true);
89
+ expect(await viewScreen.run({}, { caller: "mcp" } as never)).toEqual({
90
+ navigation: { view: "chat", path: "/chat/current" },
91
+ embeddedApp: {
92
+ status: "open",
93
+ id: "workspace/mail",
94
+ path: "/mail/threads/2",
95
+ source: "chat-first-pane",
96
+ },
97
+ });
98
+ mocks.tab = { tabId: "parent-two", unavailable: false };
99
+ expect(await viewScreen.run({}, { caller: "mcp" } as never)).toEqual({
100
+ navigation: { view: "apps", path: "/apps" },
101
+ });
102
+ for (const tab of [
103
+ { tabId: "parent-without-route", unavailable: false },
104
+ { tabId: null, unavailable: true },
105
+ { tabId: null, unavailable: false },
106
+ ]) {
107
+ mocks.tab = tab;
108
+ expect(await viewScreen.run({}, { caller: "mcp" } as never)).toEqual({});
109
+ }
110
+ mocks.tab = { tabId: "parent-one", unavailable: false };
111
+ mocks.appState = {};
112
+ mocks.pane = null;
113
+ });
114
+ });
115
+
116
+ describe("view-screen app pane", () => {
117
+ it("does not borrow the account-wide pane when the current tab has none", async () => {
118
+ mocks.navigation = { view: "chat" };
119
+ mocks.tab = { tabId: "parent-one", unavailable: false };
120
+ mocks.pane = null;
121
+ mocks.appState = {
122
+ "chat-first-pane": { appId: "workspace/other", path: "/other" },
123
+ };
124
+ try {
125
+ const empty = JSON.parse((await viewScreen.run({})) as string);
126
+ expect(empty).not.toHaveProperty("embeddedApp");
127
+
128
+ mocks.pane = { appId: "workspace/current", path: "/current" };
129
+ const current = JSON.parse((await viewScreen.run({})) as string);
130
+ expect(current.embeddedApp).toMatchObject({ id: "workspace/current" });
131
+ } finally {
132
+ mocks.appState = {};
133
+ mocks.pane = null;
134
+ }
135
+ });
136
+ });
137
+
61
138
  describe("view-screen Thread Debug summary", () => {
62
139
  beforeEach(() => {
63
140
  mocks.navigation = { view: "thread-debug" };
@@ -130,6 +207,7 @@ describe("view-screen embedded workspace app", () => {
130
207
  beforeEach(() => {
131
208
  mocks.navigation = { view: "chat" };
132
209
  mocks.appState = {};
210
+ mocks.pane = null;
133
211
  mocks.listWorkspaceResourceOptions.mockReset();
134
212
  mocks.listWorkspaceResourceOptions.mockResolvedValue([]);
135
213
  });
@@ -153,7 +231,7 @@ describe("view-screen embedded workspace app", () => {
153
231
  });
154
232
 
155
233
  it("names the chat-first pane app while the route stays on /chat", async () => {
156
- mocks.appState["chat-first-pane"] = {
234
+ mocks.pane = {
157
235
  appId: "mail",
158
236
  path: "/inbox",
159
237
  placement: "side",
@@ -170,7 +248,7 @@ describe("view-screen embedded workspace app", () => {
170
248
  });
171
249
 
172
250
  it("keeps a pane's named screen when it carries no path", async () => {
173
- mocks.appState["chat-first-pane"] = { appId: "mail", view: "inbox" };
251
+ mocks.pane = { appId: "mail", view: "inbox" };
174
252
 
175
253
  const result = JSON.parse(await viewScreen.run({}));
176
254
 
@@ -203,7 +281,7 @@ describe("view-screen embedded workspace app", () => {
203
281
  });
204
282
 
205
283
  it("reports a pane that names no app as unknown, not as no app open", async () => {
206
- mocks.appState["chat-first-pane"] = { placement: "side" };
284
+ mocks.pane = { placement: "side" };
207
285
 
208
286
  const result = JSON.parse(await viewScreen.run({}));
209
287
 
@@ -1,9 +1,14 @@
1
1
  import { defineAction } from "@agent-native/core/action";
2
- import { readAppState } from "@agent-native/core/application-state";
2
+ import {
3
+ appStateKeyForBrowserTab,
4
+ readAppState,
5
+ resolveCurrentRequestStateTab,
6
+ } from "@agent-native/core/application-state";
3
7
  import type { ActionEntry } from "@agent-native/core/server";
4
8
  import { z } from "zod";
5
9
 
6
10
  import { listWorkspaceApps } from "../server/lib/app-creation-store.js";
11
+ import { readDispatchPaneContext } from "../server/lib/dispatch-pane-context.js";
7
12
  import { listOverview } from "../server/lib/dispatch-store.js";
8
13
  import {
9
14
  getAgentThreadDebug,
@@ -84,6 +89,7 @@ type EmbeddedApp =
84
89
 
85
90
  async function resolveEmbeddedApp(
86
91
  navigation: Record<string, any> | null,
92
+ readPane = () => readAppState(CHAT_FIRST_PANE_STATE_KEY),
87
93
  ): Promise<EmbeddedApp | null> {
88
94
  if (navigation?.view === "workspace-app") {
89
95
  const id =
@@ -109,7 +115,7 @@ async function resolveEmbeddedApp(
109
115
  }
110
116
 
111
117
  if (navigation?.view !== "chat") return null;
112
- const pane = await readAppState(CHAT_FIRST_PANE_STATE_KEY);
118
+ const pane = await readPane();
113
119
  if (pane === null) return null;
114
120
  const appId = typeof pane.appId === "string" ? pane.appId.trim() : "";
115
121
  if (!appId) {
@@ -129,12 +135,56 @@ async function resolveEmbeddedApp(
129
135
  };
130
136
  }
131
137
 
138
+ function publicPanePath(value: unknown): string | undefined {
139
+ if (
140
+ typeof value !== "string" ||
141
+ !value.startsWith("/") ||
142
+ value.startsWith("//")
143
+ ) {
144
+ return undefined;
145
+ }
146
+ const path = value.split(/[?#]/, 1)[0];
147
+ return path && path.length <= 2_000 ? path : undefined;
148
+ }
149
+
150
+ async function readMcpView() {
151
+ const tab = await resolveCurrentRequestStateTab();
152
+ if (!tab.tabId || tab.unavailable) return {};
153
+ const navigation = await readAppState(
154
+ appStateKeyForBrowserTab("navigation", tab.tabId),
155
+ );
156
+ const pane = await resolveEmbeddedApp(navigation, readDispatchPaneContext);
157
+ return {
158
+ ...(typeof navigation?.view === "string"
159
+ ? {
160
+ navigation: {
161
+ view: navigation.view,
162
+ path: publicPanePath(navigation.path),
163
+ },
164
+ }
165
+ : {}),
166
+ ...(pane?.status === "open"
167
+ ? {
168
+ embeddedApp: {
169
+ status: pane.status,
170
+ id: pane.id,
171
+ path: publicPanePath(pane.path),
172
+ source: pane.source,
173
+ },
174
+ }
175
+ : {}),
176
+ };
177
+ }
178
+
132
179
  export default defineAction({
133
180
  description:
134
181
  "See what the user is currently looking at in the dispatch UI, including navigation state, any embedded workspace app, and a compact operational summary.",
135
182
  schema: z.object({}),
183
+ readOnly: true,
136
184
  http: false,
137
- run: async () => {
185
+ mcpTool: true,
186
+ run: async (_input, context) => {
187
+ if (context?.caller === "mcp") return readMcpView();
138
188
  const [navigation, overview, vaultOverview] = await Promise.all([
139
189
  readAppState("navigation"),
140
190
  listOverview(),
@@ -147,7 +197,13 @@ export default defineAction({
147
197
  };
148
198
  if (navigation) screen.navigation = navigation;
149
199
 
150
- const embeddedApp = await resolveEmbeddedApp(navigation);
200
+ const embeddedApp = await resolveEmbeddedApp(navigation, async () => {
201
+ const tab = await resolveCurrentRequestStateTab();
202
+ if (tab.unavailable) return null;
203
+ return tab.tabId
204
+ ? readDispatchPaneContext()
205
+ : readAppState(CHAT_FIRST_PANE_STATE_KEY);
206
+ });
151
207
  if (embeddedApp) screen.embeddedApp = embeddedApp;
152
208
 
153
209
  if (navigation?.view === "chat" || navigation?.view === "browser-chat") {
@@ -0,0 +1,362 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { createAgentThreadState } from "@agent-native/agentkit/client";
4
+ import type { ActionSuggestion } from "@agent-native/agentkit/protocol";
5
+ import React, { act } from "react";
6
+ import { createRoot, type Root } from "react-dom/client";
7
+ import { afterEach, beforeEach, expect, it, vi } from "vitest";
8
+
9
+ const mocks = vi.hoisted(() => ({
10
+ useThread: vi.fn(),
11
+ useMutation: vi.fn(),
12
+ mutate: vi.fn(),
13
+ sendMessage: vi.fn(),
14
+ }));
15
+
16
+ vi.mock("@agent-native/toolkit/app/agentkit/react", () => ({
17
+ useAgentThread: mocks.useThread,
18
+ }));
19
+ vi.mock("@agent-native/core/client/hooks", () => ({
20
+ useActionMutation: mocks.useMutation,
21
+ actionErrorCode: (error?: { errorCode?: string }) => error?.errorCode,
22
+ }));
23
+ vi.mock("@agent-native/core/client/agent-chat", () => ({
24
+ sendToAgentChat: mocks.sendMessage,
25
+ }));
26
+ vi.mock("@agent-native/core/client/i18n", () => ({
27
+ useT:
28
+ () => (_key: string, options: { defaultValue: string; label?: string }) =>
29
+ options.defaultValue.replace("{{label}}", options.label ?? ""),
30
+ }));
31
+
32
+ import { ChatActionSuggestions } from "./chat-action-suggestions.js";
33
+
34
+ const filter = {
35
+ id: "human-notifications",
36
+ kind: "filter",
37
+ trigger: "ai-narrowing",
38
+ label: "Save human notifications",
39
+ rationale: "See replies from people in one view.",
40
+ appId: "workspace/mail",
41
+ execution: {
42
+ type: "action",
43
+ action: "create-split",
44
+ params: { senderType: "human" },
45
+ },
46
+ } satisfies ActionSuggestion;
47
+
48
+ const automation = {
49
+ ...filter,
50
+ id: "triage-reminder",
51
+ kind: "automation",
52
+ trigger: "repeated-query",
53
+ label: "Remind me to triage notifications",
54
+ execution: {
55
+ type: "action",
56
+ action: "create-reminder",
57
+ params: { cadence: "daily", assignee: null, enabled: false },
58
+ },
59
+ } satisfies ActionSuggestion;
60
+
61
+ const build = {
62
+ id: "equipment-tracker",
63
+ kind: "create-app",
64
+ trigger: "new-domain",
65
+ label: "Build equipment tracker",
66
+ rationale: "Track shared equipment.",
67
+ appId: "dispatch",
68
+ execution: {
69
+ type: "create-app",
70
+ domainSpec: "Track equipment and due dates.",
71
+ },
72
+ } satisfies ActionSuggestion;
73
+
74
+ function doneThread() {
75
+ const thread = createAgentThreadState("thread");
76
+ thread.runs.run = { id: "run", status: "completed", lastSequence: 8 };
77
+ return thread;
78
+ }
79
+
80
+ let container: HTMLDivElement;
81
+ let root: Root;
82
+
83
+ beforeEach(() => {
84
+ vi.resetAllMocks();
85
+ (
86
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
87
+ ).IS_REACT_ACT_ENVIRONMENT = true;
88
+ mocks.useMutation.mockReturnValue({ mutateAsync: mocks.mutate });
89
+ container = document.createElement("div");
90
+ document.body.appendChild(container);
91
+ root = createRoot(container);
92
+ });
93
+
94
+ afterEach(async () => {
95
+ await act(async () => root.unmount());
96
+ container.remove();
97
+ });
98
+
99
+ async function render() {
100
+ await act(async () =>
101
+ root.render(<ChatActionSuggestions threadId="thread" />),
102
+ );
103
+ }
104
+
105
+ function chip(label: string) {
106
+ return [...container.querySelectorAll("button")].find(
107
+ (button) => button.firstElementChild?.textContent === label,
108
+ );
109
+ }
110
+
111
+ it("shows at most two suggestions from real tool result shapes and executes the selected action directly", async () => {
112
+ const thread = doneThread();
113
+ thread.tools.foreign = {
114
+ id: "foreign",
115
+ name: "call_app_action",
116
+ runId: "run",
117
+ status: "completed",
118
+ input: { app: "another-workspace/mail" },
119
+ output: {
120
+ structuredContent: {
121
+ suggestions: [
122
+ { ...filter, id: "foreign", label: "Foreign suggestion" },
123
+ ],
124
+ },
125
+ },
126
+ };
127
+ thread.tools.destructive = {
128
+ id: "destructive",
129
+ name: "call_app_action",
130
+ runId: "run",
131
+ status: "completed",
132
+ input: { app: filter.appId },
133
+ output: {
134
+ structuredContent: {
135
+ suggestions: [
136
+ {
137
+ ...filter,
138
+ id: "delete-split",
139
+ label: "Organize this inbox",
140
+ execution: { type: "action", action: "delete-split", params: {} },
141
+ },
142
+ ],
143
+ },
144
+ },
145
+ };
146
+ thread.tools.app = {
147
+ id: "app",
148
+ name: "call_app_action",
149
+ runId: "run",
150
+ status: "completed",
151
+ input: { app: filter.appId },
152
+ output: JSON.stringify({
153
+ structuredContent: { suggestions: [filter, automation] },
154
+ content: [],
155
+ }),
156
+ };
157
+ thread.tools.turn = {
158
+ id: "turn",
159
+ name: "propose-action-suggestions",
160
+ runId: "run",
161
+ status: "completed",
162
+ output: JSON.stringify({ suggestions: [filter, build] }),
163
+ };
164
+ mocks.useThread.mockReturnValue(thread);
165
+ mocks.mutate.mockResolvedValue({
166
+ suggestionId: filter.id,
167
+ status: "accepted",
168
+ outcome: "action-completed",
169
+ });
170
+
171
+ await render();
172
+ expect(chip("Foreign suggestion")).toBeUndefined();
173
+ expect(chip("Organize this inbox")).toBeUndefined();
174
+ expect(chip(filter.label)?.textContent).toContain(
175
+ "workspace/mail · create-split",
176
+ );
177
+ expect(chip(build.label)).toBeUndefined();
178
+ await act(async () =>
179
+ container
180
+ .querySelector<HTMLButtonElement>(
181
+ `[aria-label="Dismiss ${automation.label}"]`,
182
+ )
183
+ ?.click(),
184
+ );
185
+ expect(chip(automation.label)).toBeUndefined();
186
+ expect(mocks.mutate).not.toHaveBeenCalled();
187
+ await act(async () => chip(filter.label)?.click());
188
+ expect(mocks.useMutation).toHaveBeenCalledWith("execute-action-suggestion", {
189
+ uiOnly: true,
190
+ retry: false,
191
+ });
192
+ expect(mocks.mutate).toHaveBeenCalledExactlyOnceWith({ suggestion: filter });
193
+ expect(mocks.sendMessage).not.toHaveBeenCalled();
194
+ expect(container.querySelector('[role="status"]')?.textContent).toBe(
195
+ "Suggestion accepted.",
196
+ );
197
+ });
198
+
199
+ it("shows a turn-level suggestion after completion without an app tool result", async () => {
200
+ const thread = doneThread();
201
+ thread.runs.run.status = "running";
202
+ thread.tools.turn = {
203
+ id: "turn",
204
+ name: "propose-action-suggestions",
205
+ runId: "run",
206
+ status: "completed",
207
+ output: JSON.stringify({ suggestions: [build] }),
208
+ };
209
+ mocks.useThread.mockReturnValue(thread);
210
+ await render();
211
+ expect(chip(build.label)).toBeUndefined();
212
+
213
+ mocks.useThread.mockReturnValue({
214
+ ...thread,
215
+ runs: { run: { ...thread.runs.run, status: "completed" } },
216
+ });
217
+ await render();
218
+ expect(chip(build.label)).toBeDefined();
219
+ });
220
+
221
+ it("surfaces an actionable approval review instead of a success receipt", async () => {
222
+ const thread = doneThread();
223
+ thread.tools.turn = {
224
+ id: "turn",
225
+ name: "propose-action-suggestions",
226
+ runId: "run",
227
+ status: "completed",
228
+ output: { suggestions: [filter] },
229
+ };
230
+ mocks.useThread.mockReturnValue(thread);
231
+ const url =
232
+ "https://mail.example.test/#mcpApproval=00000000-0000-4000-8000-000000000000";
233
+ mocks.mutate.mockRejectedValue(
234
+ Object.assign(new Error("Pending approval"), {
235
+ errorCode: "approval_required",
236
+ details: { approvalReview: { url } },
237
+ }),
238
+ );
239
+
240
+ await render();
241
+ await act(async () => chip(filter.label)?.click());
242
+ expect(container.querySelector("[role=alert] a")?.getAttribute("href")).toBe(
243
+ url,
244
+ );
245
+ expect(container.querySelector("[role=status]")).toBeNull();
246
+ });
247
+
248
+ it.each([
249
+ [automation, "daily", "Cadence"],
250
+ [build, build.execution.domainSpec, "Create app in this workspace"],
251
+ [
252
+ {
253
+ ...build,
254
+ kind: "customize-app",
255
+ appId: "workspace/mail",
256
+ execution: {
257
+ type: "customize",
258
+ targetAppId: "workspace/mail",
259
+ editSpec: "Set the default inbox column.",
260
+ },
261
+ } satisfies ActionSuggestion,
262
+ "Set the default inbox column.",
263
+ "Customize",
264
+ ],
265
+ ])(
266
+ "shows the concrete payload and waits for confirmation for $id",
267
+ async (suggestion, payload, label) => {
268
+ const thread = doneThread();
269
+ thread.tools.turn = {
270
+ id: "turn",
271
+ name: "propose-action-suggestions",
272
+ runId: "run",
273
+ status: "completed",
274
+ output: { suggestions: [suggestion] },
275
+ };
276
+ mocks.useThread.mockReturnValue(thread);
277
+ mocks.mutate.mockResolvedValue({
278
+ suggestionId: suggestion.id,
279
+ status: "accepted",
280
+ outcome: "action-completed",
281
+ });
282
+ await render();
283
+ await act(async () => chip(suggestion.label)?.click());
284
+ expect(mocks.mutate).not.toHaveBeenCalled();
285
+ const dialog = document.querySelector('[role="dialog"]');
286
+ expect(dialog?.textContent).toContain(payload);
287
+ expect(dialog?.querySelector("pre")).toBeNull();
288
+ expect(dialog?.textContent).toContain(label);
289
+ expect(dialog?.textContent).not.toContain("{\n");
290
+ const run = [...(dialog?.querySelectorAll("button") ?? [])].find(
291
+ (button) => button.textContent === "Run action",
292
+ );
293
+ await act(async () => run?.click());
294
+ expect(mocks.mutate).toHaveBeenCalledExactlyOnceWith({ suggestion });
295
+ },
296
+ );
297
+
298
+ it("offers the existing app after confirmation", async () => {
299
+ const thread = doneThread();
300
+ thread.tools.turn = {
301
+ id: "turn",
302
+ name: "propose-action-suggestions",
303
+ runId: "run",
304
+ status: "completed",
305
+ output: { suggestions: [build] },
306
+ };
307
+ mocks.useThread.mockReturnValue(thread);
308
+ mocks.mutate.mockResolvedValue({
309
+ suggestionId: build.id,
310
+ status: "accepted",
311
+ outcome: "action-completed",
312
+ url: "https://equipment.example.test/",
313
+ });
314
+ await render();
315
+ await act(async () => chip(build.label)?.click());
316
+ const run = [...document.querySelectorAll('[role="dialog"] button')].find(
317
+ (button) => button.textContent === "Run action",
318
+ );
319
+ await act(async () =>
320
+ run?.dispatchEvent(new MouseEvent("click", { bubbles: true })),
321
+ );
322
+ expect(mocks.mutate).toHaveBeenCalledExactlyOnceWith({ suggestion: build });
323
+ expect(
324
+ container.querySelector('[role="status"] a')?.getAttribute("href"),
325
+ ).toBe("https://equipment.example.test/");
326
+ });
327
+
328
+ it("shows explicit null and boolean values in the review", async () => {
329
+ const thread = doneThread();
330
+ thread.tools.turn = {
331
+ id: "turn",
332
+ name: "propose-action-suggestions",
333
+ runId: "run",
334
+ status: "completed",
335
+ output: { suggestions: [automation] },
336
+ };
337
+ mocks.useThread.mockReturnValue(thread);
338
+ await render();
339
+ await act(async () => chip(automation.label)?.click());
340
+ const dialog = document.querySelector('[role="dialog"]');
341
+ expect(dialog?.textContent).toContain("AssigneeNone");
342
+ expect(dialog?.textContent).toContain("EnabledNo");
343
+ });
344
+
345
+ it("summarizes the action and its arguments as labeled text", async () => {
346
+ const thread = doneThread();
347
+ thread.tools.turn = {
348
+ id: "turn",
349
+ name: "propose-action-suggestions",
350
+ runId: "run",
351
+ status: "completed",
352
+ output: { suggestions: [automation] },
353
+ };
354
+ mocks.useThread.mockReturnValue(thread);
355
+ await render();
356
+ await act(async () => chip(automation.label)?.click());
357
+ const text = document.querySelector('[role="dialog"]')?.textContent ?? "";
358
+ expect(text).toContain("ActionCreate reminder");
359
+ expect(text).toContain("Appworkspace/mail");
360
+ expect(text).toContain("Cadencedaily");
361
+ expect(text).not.toMatch(/[{}"]/);
362
+ });