@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
@@ -5,11 +5,15 @@ import { describe, expect, it } from "vitest";
5
5
  import {
6
6
  isDefaultWorkspaceAppHiddenId,
7
7
  isDispatchWorkspaceAppId,
8
+ isEmbeddedInExternalHost,
9
+ isInIframe,
8
10
  isPathMountedWorkspaceApp,
9
11
  isWorkspaceAppHostPageUrl,
10
12
  isWorkspaceAppVisibleInDefaultLaunchers,
11
13
  isWorkspaceSsoApp,
12
14
  mergeChatFirstWorkspaceApps,
15
+ navigateToWorkspaceApp,
16
+ shouldOpenWorkspaceAppInTopWindow,
13
17
  workspaceAppSourceFromConnected,
14
18
  workspaceAppIdFromRoute,
15
19
  workspaceAppInitialPathFromSplat,
@@ -512,4 +516,101 @@ describe("workspace app routes", () => {
512
516
  expect(workspaceAppSourceFromConnected("custom")).toBe("connected");
513
517
  expect(workspaceAppSourceFromConnected("workspace")).toBe("workspace");
514
518
  });
519
+
520
+ it("strips this Dispatch's own /apps/<id> host page url when resolving standalone app hrefs", () => {
521
+ const origin = window.location.origin;
522
+ const hostApp = {
523
+ id: "coach",
524
+ name: "Coach",
525
+ path: "/coach",
526
+ homePath: "/",
527
+ url: `${origin}/dispatch/apps/coach`,
528
+ };
529
+ expect(workspaceAppHref(hostApp)).toBe("/coach");
530
+ expect(workspaceAppDirectHref(hostApp, "/")).toBe("/coach");
531
+ expect(workspaceAppDirectHref(hostApp, "/sessions")).toBe(
532
+ "/coach/sessions",
533
+ );
534
+
535
+ const onboardingApp = {
536
+ id: "onboarding",
537
+ name: "Onboarding",
538
+ path: "/onboarding",
539
+ homePath: "/accounts",
540
+ url: `${origin}/apps/onboarding`,
541
+ };
542
+ expect(workspaceAppHref(onboardingApp)).toBe("/onboarding/accounts");
543
+ });
544
+
545
+ it("auto-detects iframes and embedded desktop/chat hosts", () => {
546
+ const originalTop = window.top;
547
+ const originalUserAgent = navigator.userAgent;
548
+
549
+ try {
550
+ expect(isInIframe()).toBe(false);
551
+ expect(isEmbeddedInExternalHost()).toBe(false);
552
+ expect(shouldOpenWorkspaceAppInTopWindow()).toBe(false);
553
+
554
+ Object.defineProperty(window, "top", {
555
+ configurable: true,
556
+ value: {},
557
+ });
558
+ expect(isInIframe()).toBe(true);
559
+ expect(isEmbeddedInExternalHost()).toBe(true);
560
+ expect(shouldOpenWorkspaceAppInTopWindow()).toBe(true);
561
+
562
+ Object.defineProperty(window, "top", {
563
+ configurable: true,
564
+ get() {
565
+ throw new Error("Blocked cross-origin top access");
566
+ },
567
+ });
568
+ expect(isInIframe()).toBe(true);
569
+ expect(isEmbeddedInExternalHost()).toBe(true);
570
+
571
+ Object.defineProperty(window, "top", {
572
+ configurable: true,
573
+ value: originalTop,
574
+ });
575
+ Object.defineProperty(navigator, "userAgent", {
576
+ configurable: true,
577
+ value:
578
+ "Mozilla/5.0 T3Code/1.2.0 Electron/34.0.0 Chrome/132.0.0.0 Safari/537.36",
579
+ });
580
+ expect(isInIframe()).toBe(false);
581
+ expect(isEmbeddedInExternalHost()).toBe(true);
582
+ expect(shouldOpenWorkspaceAppInTopWindow()).toBe(true);
583
+ } finally {
584
+ Object.defineProperty(window, "top", {
585
+ configurable: true,
586
+ value: originalTop,
587
+ });
588
+ Object.defineProperty(navigator, "userAgent", {
589
+ configurable: true,
590
+ value: originalUserAgent,
591
+ });
592
+ }
593
+ });
594
+
595
+ it("navigates the current frame rather than hijacking window.top inside a generic external iframe", () => {
596
+ const originalTop = window.top;
597
+ const originalHref = window.location.href;
598
+ const topWindow = { location: { href: "https://claude.ai/chat" } };
599
+ Object.defineProperty(window, "top", {
600
+ configurable: true,
601
+ value: topWindow,
602
+ });
603
+
604
+ try {
605
+ expect(navigateToWorkspaceApp("/coach")).toBe(true);
606
+ expect(topWindow.location.href).toBe("https://claude.ai/chat");
607
+ expect(window.location.pathname).toBe("/coach");
608
+ } finally {
609
+ Object.defineProperty(window, "top", {
610
+ configurable: true,
611
+ value: originalTop,
612
+ });
613
+ window.history.replaceState({}, "", originalHref);
614
+ }
615
+ });
515
616
  });
@@ -76,6 +76,24 @@ describe("workspaceAppDirectHref", () => {
76
76
  "/atlas",
77
77
  ),
78
78
  ).toBe("https://workspace.example.test/atlas");
79
+ expect(
80
+ workspaceAppDirectHref(
81
+ { path: "/decks-2", url: "https://workspace.example.test/decks-2" },
82
+ "/decks-2/docs/abc",
83
+ ),
84
+ ).toBe("https://workspace.example.test/decks-2/docs/abc");
85
+ expect(
86
+ workspaceAppDirectHref(
87
+ {
88
+ path: "/decks-2",
89
+ url: "https://workspace.example.test/decks-2/decks-2",
90
+ },
91
+ "/decks-2/decks-2/docs/abc",
92
+ ),
93
+ ).toBe("https://workspace.example.test/decks-2/docs/abc");
94
+ expect(
95
+ workspaceAppDirectHref({ path: "/decks-2" }, "/decks-2/decks-2?slide=1"),
96
+ ).toBe("/decks-2?slide=1");
79
97
  });
80
98
 
81
99
  it("resolves a mounted relative app path", () => {
@@ -63,11 +63,22 @@ export function workspaceAppSourceFromConnected(
63
63
  }
64
64
 
65
65
  interface WorkspaceAppHrefSource {
66
+ id?: string;
66
67
  path?: string | null;
67
68
  url?: string | null;
68
69
  workspaceSso?: boolean;
69
70
  }
70
71
 
72
+ function stripHostPageUrl<T extends WorkspaceAppHrefSource>(app: T): T {
73
+ if (!app.id || !app.url?.trim() || !app.path?.trim()) return app;
74
+ const origin =
75
+ typeof window === "undefined" ? undefined : window.location.origin;
76
+ if (!isWorkspaceAppHostPageUrl({ id: app.id, url: app.url }, origin)) {
77
+ return app;
78
+ }
79
+ return { ...app, url: null };
80
+ }
81
+
71
82
  export function isDispatchWorkspaceAppId(appId: string): boolean {
72
83
  return appId.trim().toLowerCase() === "dispatch";
73
84
  }
@@ -369,20 +380,24 @@ export function workspaceAppHref(app: WorkspaceAppSummary): string | null {
369
380
  })
370
381
  : null;
371
382
  }
372
- const base = app.path || app.url || null;
373
- if (!base || app.isDispatch) return base;
374
- return workspaceAppDirectHref(app, workspaceAppTargetPath(app));
383
+ const normalized = stripHostPageUrl(app);
384
+ const base = normalized.path || normalized.url || null;
385
+ if (!base || normalized.isDispatch) return base;
386
+ return workspaceAppDirectHref(normalized, workspaceAppTargetPath(normalized));
375
387
  }
376
388
 
377
389
  export function workspaceAppTargetPath(app: {
390
+ id?: string;
391
+ path?: string | null;
378
392
  homePath?: string | null;
379
393
  url?: string | null;
380
394
  }): string {
381
- if (typeof app.homePath === "string") {
382
- return normalizeWorkspaceAppHomePath(app.homePath);
395
+ const normalized = stripHostPageUrl(app);
396
+ if (typeof normalized.homePath === "string") {
397
+ return normalizeWorkspaceAppHomePath(normalized.homePath);
383
398
  }
384
399
 
385
- const rawUrl = app.url?.trim();
400
+ const rawUrl = normalized.url?.trim();
386
401
  if (rawUrl) {
387
402
  try {
388
403
  const url = new URL(rawUrl);
@@ -419,10 +434,35 @@ export function workspaceAppEmbedTarget(
419
434
  return path.startsWith("/") ? { path } : path ? { url: path } : {};
420
435
  }
421
436
 
437
+ function collapseRepeatedLeadingMountSegment(
438
+ pathname: string,
439
+ mountSegment?: string | null,
440
+ ): string {
441
+ const segments = pathname.split("/").filter(Boolean);
442
+ const firstSegment = segments[0];
443
+ const secondSegment = segments[1];
444
+ if (!firstSegment || !secondSegment) return pathname;
445
+ const first = firstSegment.toLowerCase();
446
+ const second = secondSegment.toLowerCase();
447
+ if (first !== second) return pathname;
448
+ if (mountSegment && first !== mountSegment.toLowerCase()) return pathname;
449
+ let start = 0;
450
+ while (start + 1 < segments.length) {
451
+ const current = segments[start];
452
+ const next = segments[start + 1];
453
+ if (!current || !next || current.toLowerCase() !== next.toLowerCase()) {
454
+ break;
455
+ }
456
+ start += 1;
457
+ }
458
+ return `/${segments.slice(start).join("/")}`;
459
+ }
460
+
422
461
  export function workspaceAppDirectHref(
423
462
  app: WorkspaceAppHrefSource,
424
463
  targetPath: string,
425
464
  ): string | null {
465
+ const normalized = stripHostPageUrl(app);
426
466
  const target = targetPath.trim();
427
467
  if (!target || !target.startsWith("/") || target.startsWith("//")) {
428
468
  return null;
@@ -438,7 +478,7 @@ export function workspaceAppDirectHref(
438
478
  const targetPathname = targetUrl.pathname || "/";
439
479
 
440
480
  let absoluteBase: URL | null = null;
441
- const rawUrl = app.url?.trim();
481
+ const rawUrl = normalized.url?.trim();
442
482
  if (rawUrl) {
443
483
  try {
444
484
  const parsedBase = new URL(rawUrl);
@@ -451,26 +491,44 @@ export function workspaceAppDirectHref(
451
491
  }
452
492
  }
453
493
 
454
- const mountedPath = app.path?.trim();
455
- const basePath = absoluteBase
456
- ? absoluteBase.pathname
457
- : mountedPath
458
- ? `/${mountedPath.replace(/^[/\\]+/, "").split(/[?#]/, 1)[0]}`
459
- : null;
494
+ const mountedPath = normalized.path?.trim();
495
+ const normalizedMountedPath = mountedPath
496
+ ? `/${mountedPath.replace(/^[/\\]+/, "").split(/[?#]/, 1)[0]}`.replace(
497
+ /\/+$/,
498
+ "",
499
+ ) || "/"
500
+ : null;
501
+ const basePath = absoluteBase ? absoluteBase.pathname : normalizedMountedPath;
460
502
  if (!basePath) return null;
461
503
 
462
- const normalizedBasePath = basePath.replace(/\/+$/, "") || "/";
504
+ const mountSegment =
505
+ normalizedMountedPath && normalizedMountedPath !== "/"
506
+ ? normalizedMountedPath.split("/").filter(Boolean)[0]
507
+ : basePath.split("/").filter(Boolean)[0];
508
+ const normalizedBasePath =
509
+ collapseRepeatedLeadingMountSegment(
510
+ basePath.replace(/\/+$/, "") || "/",
511
+ mountSegment,
512
+ ) || "/";
513
+ const cleanedTargetPathname = collapseRepeatedLeadingMountSegment(
514
+ targetPathname,
515
+ mountSegment,
516
+ );
517
+ const lowerBasePath = normalizedBasePath.toLowerCase();
518
+ const lowerTargetPath = cleanedTargetPathname.toLowerCase();
463
519
  const targetIsMountedPath =
464
520
  normalizedBasePath !== "/" &&
465
- (targetPathname === normalizedBasePath ||
466
- targetPathname.startsWith(`${normalizedBasePath}/`));
521
+ (lowerTargetPath === lowerBasePath ||
522
+ lowerTargetPath.startsWith(`${lowerBasePath}/`));
467
523
  const resolvedPath = targetIsMountedPath
468
- ? targetPathname
524
+ ? cleanedTargetPathname === "/"
525
+ ? normalizedBasePath
526
+ : `${normalizedBasePath}${cleanedTargetPathname.slice(normalizedBasePath.length)}`
469
527
  : normalizedBasePath === "/"
470
- ? targetPathname
471
- : targetPathname === "/"
528
+ ? cleanedTargetPathname
529
+ : cleanedTargetPathname === "/"
472
530
  ? normalizedBasePath
473
- : `${normalizedBasePath}/${targetPathname.replace(/^\/+/, "")}`;
531
+ : `${normalizedBasePath}/${cleanedTargetPathname.replace(/^\/+/, "")}`;
474
532
 
475
533
  if (absoluteBase) {
476
534
  absoluteBase.pathname = resolvedPath;
@@ -486,9 +544,27 @@ export function isPendingBuilderHref(app: WorkspaceAppSummary): boolean {
486
544
  return app.status === "pending" && !!app.builderUrl;
487
545
  }
488
546
 
489
- export function shouldOpenWorkspaceAppInTopWindow(): boolean {
547
+ export function isInIframe(): boolean {
548
+ if (typeof window === "undefined") return false;
549
+ try {
550
+ return window.self !== window.top;
551
+ } catch {
552
+ // coercion-ok: cross-origin access error on window.top proves this window is framed.
553
+ return true;
554
+ }
555
+ }
556
+
557
+ export function isEmbeddedInExternalHost(): boolean {
490
558
  if (typeof window === "undefined") return false;
491
- return isInBuilderFrame() || getClientSurface() !== "web";
559
+ if (isInBuilderFrame() || getClientSurface() !== "web" || isInIframe()) {
560
+ return true;
561
+ }
562
+ const search = window.location.search;
563
+ return new URLSearchParams(search).get("electron") === "1";
564
+ }
565
+
566
+ export function shouldOpenWorkspaceAppInTopWindow(): boolean {
567
+ return isEmbeddedInExternalHost();
492
568
  }
493
569
 
494
570
  export function navigateToWorkspaceApp(href: string): boolean {
@@ -499,8 +575,10 @@ export function navigateToWorkspaceApp(href: string): boolean {
499
575
  if (targetUrl.protocol !== "http:" && targetUrl.protocol !== "https:") {
500
576
  return false;
501
577
  }
502
- const targetWindow =
503
- shouldOpenWorkspaceAppInTopWindow() && window.top ? window.top : window;
578
+ const useTopWindow =
579
+ (isInBuilderFrame() || getClientSurface() !== "web") &&
580
+ Boolean(window.top);
581
+ const targetWindow = useTopWindow && window.top ? window.top : window;
504
582
  targetWindow.location.href = targetUrl.href;
505
583
  return true;
506
584
  } catch {
@@ -1,7 +1,13 @@
1
1
  // @vitest-environment happy-dom
2
2
  import React, { act, type ReactNode } from "react";
3
3
  import { createRoot, type Root } from "react-dom/client";
4
- import { MemoryRouter } from "react-router";
4
+ import {
5
+ MemoryRouter,
6
+ Route,
7
+ Routes,
8
+ useLocation,
9
+ useNavigate,
10
+ } from "react-router";
5
11
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6
12
 
7
13
  import { TooltipProvider } from "../../components/ui/tooltip";
@@ -379,4 +385,89 @@ describe("Dispatch ChatRoute", () => {
379
385
  );
380
386
  expect(container.textContent).not.toContain("Request ID");
381
387
  });
388
+
389
+ it("ignores stale threadUrlSync navigations after leaving /chat for /apps", async () => {
390
+ let observedPath = "";
391
+ let moveToApps: (() => void) | undefined;
392
+
393
+ function LocationProbe() {
394
+ const location = useLocation();
395
+ const navigate = useNavigate();
396
+ observedPath = location.pathname;
397
+ moveToApps = () => {
398
+ void navigate("/apps");
399
+ };
400
+ return null;
401
+ }
402
+
403
+ await act(async () => {
404
+ root.render(
405
+ <TooltipProvider>
406
+ <MemoryRouter initialEntries={["/chat"]}>
407
+ <LocationProbe />
408
+ <Routes>
409
+ <Route path="/chat/*" element={<ChatRoute />} />
410
+ <Route path="/apps" element={<div data-testid="apps-page" />} />
411
+ </Routes>
412
+ </MemoryRouter>
413
+ </TooltipProvider>,
414
+ );
415
+ });
416
+
417
+ const staleNavigate = (
418
+ clientState.surfaceProps?.threadUrlSync as {
419
+ navigate: (path: string, options?: { replace?: boolean }) => void;
420
+ }
421
+ ).navigate;
422
+ expect(observedPath).toBe("/chat");
423
+
424
+ await act(async () => {
425
+ moveToApps?.();
426
+ });
427
+ expect(observedPath).toBe("/apps");
428
+
429
+ await act(async () => {
430
+ staleNavigate("/chat/thread-late");
431
+ });
432
+ expect(observedPath).toBe("/apps");
433
+ });
434
+
435
+ it("ignores threadUrlSync navigations when window.location already left /chat", async () => {
436
+ let observedPath = "";
437
+ function LocationProbe() {
438
+ observedPath = useLocation().pathname;
439
+ return null;
440
+ }
441
+
442
+ window.history.replaceState(null, "", "/chat");
443
+ try {
444
+ await act(async () => {
445
+ root.render(
446
+ <TooltipProvider>
447
+ <MemoryRouter initialEntries={["/chat"]}>
448
+ <LocationProbe />
449
+ <Routes>
450
+ <Route path="/chat/*" element={<ChatRoute />} />
451
+ <Route path="/apps" element={<div />} />
452
+ </Routes>
453
+ </MemoryRouter>
454
+ </TooltipProvider>,
455
+ );
456
+ });
457
+
458
+ const syncNavigate = (
459
+ clientState.surfaceProps?.threadUrlSync as {
460
+ navigate: (path: string, options?: { replace?: boolean }) => void;
461
+ }
462
+ ).navigate;
463
+
464
+ window.history.replaceState(null, "", "/apps");
465
+ await act(async () => {
466
+ syncNavigate("/chat/thread-late");
467
+ });
468
+ expect(observedPath).toBe("/chat");
469
+ } finally {
470
+ window.history.replaceState(null, "", "/");
471
+ }
472
+ });
382
473
  });
@@ -15,6 +15,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
15
15
  import { useLocation, useNavigate } from "react-router";
16
16
 
17
17
  import { ActionQueryError } from "../../components/action-query-error";
18
+ import { ChatActionSuggestions } from "../../components/chat-action-suggestions";
18
19
  import { DispatchChatHomeApps } from "../../components/chat-home-apps";
19
20
  import { useDispatchExtensions } from "../../components/layout/Layout";
20
21
  import { Skeleton } from "../../components/ui/skeleton";
@@ -45,6 +46,10 @@ function stripBasePath(pathname: string): string {
45
46
  return pathname;
46
47
  }
47
48
 
49
+ function isChatPath(pathname: string): boolean {
50
+ return pathname === "/chat" || pathname.startsWith("/chat/");
51
+ }
52
+
48
53
  function threadIdFromPath(pathname: string): string | null {
49
54
  const match = stripBasePath(pathname).match(/^\/chat\/([^/]+)/);
50
55
  if (!match) return null;
@@ -139,9 +144,38 @@ export default function ChatRoute() {
139
144
  readChatFirstMode() ||
140
145
  new URLSearchParams(location.search).get("chatFirst") === "1";
141
146
 
147
+ const isMountedRef = useRef(true);
148
+ const locationPathnameRef = useRef(location.pathname);
149
+ const tracksWindowChatPathRef = useRef(false);
150
+ useEffect(() => {
151
+ locationPathnameRef.current = location.pathname;
152
+ if (
153
+ typeof window !== "undefined" &&
154
+ isChatPath(stripBasePath(window.location.pathname))
155
+ ) {
156
+ tracksWindowChatPathRef.current = true;
157
+ }
158
+ }, [location.pathname]);
159
+ useEffect(() => {
160
+ isMountedRef.current = true;
161
+ return () => {
162
+ isMountedRef.current = false;
163
+ };
164
+ }, []);
165
+
142
166
  const navigateThreadUrl = useCallback(
143
- (path: string, options?: { replace?: boolean }) =>
144
- navigate(dispatchNavTarget(path), options),
167
+ (path: string, options?: { replace?: boolean }) => {
168
+ if (!isMountedRef.current) return;
169
+ if (!isChatPath(stripBasePath(locationPathnameRef.current))) return;
170
+ if (
171
+ tracksWindowChatPathRef.current &&
172
+ typeof window !== "undefined" &&
173
+ !isChatPath(stripBasePath(window.location.pathname))
174
+ ) {
175
+ return;
176
+ }
177
+ void navigate(dispatchNavTarget(path), options);
178
+ },
145
179
  [navigate],
146
180
  );
147
181
  const threadUrlSync = useMemo<DispatchThreadUrlSync>(
@@ -341,6 +375,11 @@ export default function ChatRoute() {
341
375
  </div>
342
376
  ) : null
343
377
  }
378
+ threadFooterSlot={({ threadId }) =>
379
+ threadId ? (
380
+ <ChatActionSuggestions key={threadId} threadId={threadId} />
381
+ ) : null
382
+ }
344
383
  afterComposerSlot={
345
384
  !agent && !prompt?.message && !threadUrlSync.routeThreadId ? (
346
385
  <DispatchChatHomeApps />
@@ -30,6 +30,7 @@ import { IconShield } from "@tabler/icons-react";
30
30
  import { useMemo, useState } from "react";
31
31
  import { Link } from "react-router";
32
32
 
33
+ import { GoogleBrokerSettingsGroup } from "../../components/google-broker-settings-group.js";
33
34
  import { HostedAppsSettingsGroup } from "../../components/hosted-apps-settings-group";
34
35
  import { Button } from "../../components/ui/button";
35
36
  import { Switch } from "../../components/ui/switch";
@@ -246,26 +247,30 @@ export function DispatchSettingsPage({ changelog }: DispatchSettingsPageProps) {
246
247
  {chatFirstStorageAlert}
247
248
  </SettingsRow>
248
249
  </SettingsGroup>
250
+ <GoogleBrokerSettingsGroup />
249
251
  </div>
250
252
  }
251
253
  generalGroups={
252
- <SettingsGroup id="workspace" title={t("settings.workspaceTitle")}>
253
- <SettingsRow
254
- id="chat-first"
255
- label={t("settings.chatFirstTitle")}
256
- description={t("settings.chatFirstDescription")}
257
- control={chatFirstSwitch}
258
- >
259
- {chatFirstStorageAlert}
260
- </SettingsRow>
261
- <SettingsRow
262
- id="workspace-resources"
263
- label={t("settings.resourcesTitle")}
264
- description={t("settings.workspaceDescription")}
265
- control={resourceSettingsButton}
266
- />
267
- {connectAppsRow}
268
- </SettingsGroup>
254
+ <>
255
+ <SettingsGroup id="workspace" title={t("settings.workspaceTitle")}>
256
+ <SettingsRow
257
+ id="chat-first"
258
+ label={t("settings.chatFirstTitle")}
259
+ description={t("settings.chatFirstDescription")}
260
+ control={chatFirstSwitch}
261
+ >
262
+ {chatFirstStorageAlert}
263
+ </SettingsRow>
264
+ <SettingsRow
265
+ id="workspace-resources"
266
+ label={t("settings.resourcesTitle")}
267
+ description={t("settings.workspaceDescription")}
268
+ control={resourceSettingsButton}
269
+ />
270
+ {connectAppsRow}
271
+ </SettingsGroup>
272
+ <GoogleBrokerSettingsGroup />
273
+ </>
269
274
  }
270
275
  whatsNew={
271
276
  <div className="mx-auto w-full max-w-2xl">
@@ -72,6 +72,10 @@ vi.mock("../../components/hosted-apps-settings-group", () => ({
72
72
  HostedAppsSettingsGroup: () => <section data-hosted-apps-group />,
73
73
  }));
74
74
 
75
+ vi.mock("../../components/google-broker-settings-group.js", () => ({
76
+ GoogleBrokerSettingsGroup: () => <section data-google-broker-group />,
77
+ }));
78
+
75
79
  vi.mock("@agent-native/toolkit/app/settings", () => ({
76
80
  AccountSettingsCard: () => null,
77
81
  CORE_SETTINGS_PAGES: [
@@ -7,6 +7,7 @@ import {
7
7
  import { dispatchActions } from "../actions/index.js";
8
8
  import type { DispatchConfig } from "../config.js";
9
9
  import { dispatchAccessDescriptor } from "../shared/app-roles.js";
10
+ import { getDispatchConfig, setDispatchConfig } from "./lib/dispatch-config.js";
10
11
  export {
11
12
  listOrganizationVisibleWorkspaceApps,
12
13
  listWorkspaceApps,
@@ -26,14 +27,10 @@ defineAppRoles(dispatchAccessDescriptor, { allowOrgAdmins: true });
26
27
 
27
28
  registerPackageActions(dispatchActions);
28
29
 
29
- let activeConfig: DispatchConfig = {};
30
-
31
- export function getDispatchConfig(): DispatchConfig {
32
- return activeConfig;
33
- }
30
+ export { getDispatchConfig };
34
31
 
35
32
  export function setupDispatch(config: DispatchConfig = {}): NitroPluginDef {
36
- activeConfig = Object.freeze({ ...config });
33
+ setDispatchConfig(config);
37
34
  return (nitroApp) => {
38
35
  void nitroApp;
39
36
  };
@@ -49,3 +46,6 @@ export {
49
46
  export { default as dispatchCoreRoutesPlugin } from "./plugins/core-routes.js";
50
47
 
51
48
  export type { DispatchConfig } from "../config.js";
49
+
50
+ export { createGoogleBrokerAdmission } from "../db/google-broker-admission.js";
51
+ export { handleGoogleBrokerRpc } from "./lib/google-broker-rpc.js";