@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
@@ -1,4 +1,5 @@
1
1
  import { listWorkspaceApps } from "./app-creation-store.js";
2
+ import { hostedCatalogEnabled } from "./dispatch-config.js";
2
3
 
3
4
  export interface CuratedWorkspaceTemplate {
4
5
  id: string;
@@ -167,6 +168,7 @@ export function getCuratedWorkspaceTemplate(
167
168
  export async function listCuratedWorkspaceTemplates(): Promise<
168
169
  CuratedWorkspaceTemplateStatus[]
169
170
  > {
171
+ if (!hostedCatalogEnabled()) return [];
170
172
  const installedIds = new Set(
171
173
  (
172
174
  await listWorkspaceApps({
@@ -0,0 +1,15 @@
1
+ import type { DispatchConfig } from "../../config.js";
2
+
3
+ let activeConfig: DispatchConfig = {};
4
+
5
+ export function getDispatchConfig(): DispatchConfig {
6
+ return activeConfig;
7
+ }
8
+
9
+ export function setDispatchConfig(config: DispatchConfig): void {
10
+ activeConfig = Object.freeze({ ...config });
11
+ }
12
+
13
+ export function hostedCatalogEnabled(): boolean {
14
+ return activeConfig.hostedCatalog !== false;
15
+ }
@@ -0,0 +1,54 @@
1
+ import { expect, it, vi } from "vitest";
2
+
3
+ const mocks = vi.hoisted(() => ({
4
+ read: vi.fn(),
5
+ tab: vi.fn(),
6
+ }));
7
+
8
+ vi.mock("@agent-native/core/application-state", () => ({
9
+ readAppState: mocks.read,
10
+ resolveCurrentRequestStateTab: mocks.tab,
11
+ appStateKeyForBrowserTab: (key: string, tabId: string) => `${key}:${tabId}`,
12
+ }));
13
+
14
+ import { resolveDispatchChildBrowserTab } from "./dispatch-pane-context.js";
15
+
16
+ it("looks up the current Dispatch tab and forwards only a fresh matching installation binding", async () => {
17
+ const mail = { id: "workspace/mail", url: "https://example.test/mail" };
18
+ const row = {
19
+ appId: mail.id,
20
+ origin: "https://example.test",
21
+ childBrowserTabId: "d178e672-918b-4c93-bd78-f627f7f00001",
22
+ observedAt: Date.now(),
23
+ };
24
+ mocks.tab.mockResolvedValue({ tabId: "parent-one", unavailable: false });
25
+ mocks.read.mockResolvedValue(row);
26
+ expect(await resolveDispatchChildBrowserTab(mail)).toBe(
27
+ row.childBrowserTabId,
28
+ );
29
+ expect(mocks.read).toHaveBeenLastCalledWith(
30
+ "dispatch-pane-context:parent-one",
31
+ );
32
+
33
+ mocks.tab.mockResolvedValue({ tabId: "parent-two", unavailable: false });
34
+ mocks.read.mockResolvedValue(null);
35
+ expect(await resolveDispatchChildBrowserTab(mail)).toBeUndefined();
36
+ expect(mocks.read).toHaveBeenLastCalledWith(
37
+ "dispatch-pane-context:parent-two",
38
+ );
39
+
40
+ mocks.read.mockResolvedValue({
41
+ ...row,
42
+ origin: "https://other.example.test",
43
+ });
44
+ expect(await resolveDispatchChildBrowserTab(mail)).toBeUndefined();
45
+ mocks.read.mockResolvedValue({ ...row, observedAt: 0 });
46
+ await expect(resolveDispatchChildBrowserTab(mail)).rejects.toMatchObject({
47
+ errorCode: "dispatch_pane_tab_unavailable",
48
+ });
49
+
50
+ mocks.read.mockClear();
51
+ mocks.tab.mockResolvedValue({ tabId: null, unavailable: false });
52
+ expect(await resolveDispatchChildBrowserTab(mail)).toBeUndefined();
53
+ expect(mocks.read).not.toHaveBeenCalled();
54
+ });
@@ -0,0 +1,54 @@
1
+ import { fail } from "@agent-native/core/action";
2
+ import {
3
+ readAppState,
4
+ appStateKeyForBrowserTab,
5
+ resolveCurrentRequestStateTab,
6
+ } from "@agent-native/core/application-state";
7
+
8
+ import {
9
+ CHAT_FIRST_PANE_BINDING_MAX_AGE_MS,
10
+ CHAT_FIRST_PANE_CONTEXT_STATE_KEY,
11
+ isDispatchChildBrowserTabId,
12
+ } from "../../shared/chat-first-pane.js";
13
+
14
+ /**
15
+ * Resolve only the child claimed by the current Dispatch tab, for the
16
+ * installation that has already passed the current MCP grant check.
17
+ */
18
+ export async function readDispatchPaneContext() {
19
+ const tab = await resolveCurrentRequestStateTab();
20
+ if (!tab.tabId || tab.unavailable) return null;
21
+ return readAppState(
22
+ appStateKeyForBrowserTab(CHAT_FIRST_PANE_CONTEXT_STATE_KEY, tab.tabId),
23
+ );
24
+ }
25
+
26
+ export async function resolveDispatchChildBrowserTab(target: {
27
+ id: string;
28
+ url: string;
29
+ homeUrl?: string;
30
+ }): Promise<string | undefined> {
31
+ const pane = await readDispatchPaneContext();
32
+ if (
33
+ pane?.appId !== target.id ||
34
+ typeof pane.origin !== "string" ||
35
+ !isDispatchChildBrowserTabId(pane.childBrowserTabId)
36
+ ) {
37
+ return undefined;
38
+ }
39
+ const runtimeUrl = target.homeUrl ?? target.url;
40
+ if (!URL.canParse(runtimeUrl) || pane.origin !== new URL(runtimeUrl).origin) {
41
+ return undefined;
42
+ }
43
+ if (
44
+ typeof pane.observedAt !== "number" ||
45
+ !Number.isFinite(pane.observedAt) ||
46
+ Date.now() - pane.observedAt > CHAT_FIRST_PANE_BINDING_MAX_AGE_MS
47
+ ) {
48
+ fail("The visible app tab could not be reached. Reopen it and retry.", {
49
+ errorCode: "dispatch_pane_tab_unavailable",
50
+ statusCode: 409,
51
+ });
52
+ }
53
+ return pane.childBrowserTabId;
54
+ }
@@ -0,0 +1,121 @@
1
+ import { z } from "zod";
2
+
3
+ import type { GoogleBrokerService } from "../../db/google-broker-admission.js";
4
+
5
+ const MAX_PROVIDER_BYTES = 128 * 1024;
6
+ const REQUEST_TIMEOUT_MS = 5_000;
7
+
8
+ const operations = {
9
+ listMail: {
10
+ service: "gmail",
11
+ url: "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=25&fields=messages(id)",
12
+ listKey: "messages",
13
+ },
14
+ listCalendars: {
15
+ service: "calendar",
16
+ url: "https://www.googleapis.com/calendar/v3/users/me/calendarList?maxResults=25&fields=items(id)",
17
+ listKey: "items",
18
+ },
19
+ listDriveFiles: {
20
+ service: "drive",
21
+ url: "https://www.googleapis.com/drive/v3/files?pageSize=25&fields=files(id)",
22
+ listKey: "files",
23
+ },
24
+ } as const satisfies Record<
25
+ string,
26
+ { service: GoogleBrokerService; url: string; listKey: string }
27
+ >;
28
+
29
+ const googleBrokerOperations = z.enum([
30
+ "listMail",
31
+ "listCalendars",
32
+ "listDriveFiles",
33
+ ]);
34
+
35
+ const googleBrokerExecute = z.strictObject({
36
+ jsonrpc: z.literal("2.0"),
37
+ id: z.number().int().nonnegative(),
38
+ method: z.literal("google/execute"),
39
+ params: z.strictObject({
40
+ operation: googleBrokerOperations,
41
+ }),
42
+ });
43
+
44
+ const googleBrokerClaim = z.strictObject({
45
+ jsonrpc: z.literal("2.0"),
46
+ id: z.number().int().nonnegative(),
47
+ method: z.literal("google/claim"),
48
+ params: z.strictObject({ operation: googleBrokerOperations }),
49
+ });
50
+
51
+ export const googleBrokerRequest = z.discriminatedUnion("method", [
52
+ googleBrokerExecute,
53
+ googleBrokerClaim,
54
+ ]);
55
+
56
+ type Operation = z.infer<typeof googleBrokerOperations>;
57
+
58
+ export function googleBrokerService(operation: Operation): GoogleBrokerService {
59
+ return operations[operation].service;
60
+ }
61
+
62
+ export async function readGoogleBrokerResponse(
63
+ response: Response,
64
+ ): Promise<unknown> {
65
+ if (!response.body) throw new Error("Missing Google broker response body");
66
+ const reader = response.body.getReader();
67
+ const chunks: Uint8Array[] = [];
68
+ let length = 0;
69
+ try {
70
+ for (;;) {
71
+ const { done, value } = await reader.read();
72
+ if (done) break;
73
+ length += value.byteLength;
74
+ if (length > MAX_PROVIDER_BYTES)
75
+ throw new Error("Google broker response exceeded its limit");
76
+ chunks.push(value);
77
+ }
78
+ return JSON.parse(Buffer.concat(chunks).toString("utf8"));
79
+ } finally {
80
+ await reader.cancel();
81
+ }
82
+ }
83
+
84
+ export async function executeGoogleBrokerOperation(
85
+ operation: Operation,
86
+ credentials: { accessToken: string; refreshToken?: string },
87
+ fetchProvider: typeof fetch = fetch,
88
+ ): Promise<{ ids: string[] }> {
89
+ const target = operations[operation];
90
+ const response = await fetchProvider(target.url, {
91
+ method: "GET",
92
+ headers: { Authorization: `Bearer ${credentials.accessToken}` },
93
+ redirect: "error",
94
+ signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
95
+ });
96
+ if (!response.ok) {
97
+ await response.body?.cancel();
98
+ throw new Error("Google broker provider request failed");
99
+ }
100
+ const items = z
101
+ .object({
102
+ [target.listKey]: z
103
+ .array(z.object({ id: z.string() }))
104
+ .max(25)
105
+ .optional(),
106
+ })
107
+ .parse(await readGoogleBrokerResponse(response))[target.listKey];
108
+ const secrets = [credentials.accessToken, credentials.refreshToken].filter(
109
+ Boolean,
110
+ );
111
+ const ids = (items ?? []).map(({ id }) => id);
112
+ if (
113
+ ids.some(
114
+ (id) =>
115
+ !/^[A-Za-z0-9_.@#-]{1,254}$/.test(id) ||
116
+ secrets.some((secret) => secret && id.includes(secret)),
117
+ )
118
+ )
119
+ throw new Error("Invalid Google broker provider response");
120
+ return { ids };
121
+ }
@@ -0,0 +1,95 @@
1
+ import { expect, it, vi } from "vitest";
2
+
3
+ import { handleGoogleBrokerRpc } from "./google-broker-rpc.js";
4
+
5
+ it("uses the grant's user and rejects injected targets and leaked credentials", async () => {
6
+ const credentials = {
7
+ accessToken: "fake_access",
8
+ refreshToken: "fake_refresh",
9
+ };
10
+ const request = {
11
+ authorization: "fixture-app-authorization",
12
+ handle: "fixture-grant",
13
+ body: {
14
+ jsonrpc: "2.0",
15
+ id: 1,
16
+ method: "google/execute",
17
+ params: { operation: "listMail" },
18
+ },
19
+ };
20
+ const fetchProvider = vi.fn<typeof fetch>(async () =>
21
+ Response.json({
22
+ messages: [{ id: "message-id" }],
23
+ access_token: credentials.accessToken,
24
+ refresh_token: credentials.refreshToken,
25
+ }),
26
+ );
27
+ const dependencies = {
28
+ authenticateApp: vi.fn(async () => ({
29
+ appId: "mail",
30
+ email: "owner@example.test",
31
+ userId: "owner",
32
+ })),
33
+ admit: vi.fn(
34
+ async () =>
35
+ ({
36
+ status: "admitted",
37
+ userId: "owner",
38
+ accountId: "account",
39
+ }) as const,
40
+ ),
41
+ claim: vi.fn(async () => undefined),
42
+ revealHandle: vi.fn(),
43
+ withActiveGrant: async <T>(
44
+ _handle: string,
45
+ _owner: string,
46
+ run: () => Promise<T>,
47
+ ) => run(),
48
+ labEnabled: vi.fn(async () => true),
49
+ resolveGoogleCredential: vi.fn(async () => credentials),
50
+ fetchProvider,
51
+ };
52
+ const injected = await handleGoogleBrokerRpc(
53
+ {
54
+ ...request,
55
+ body: {
56
+ ...request.body,
57
+ params: {
58
+ ...request.body.params,
59
+ user: "other",
60
+ url: "https://example.test",
61
+ },
62
+ },
63
+ },
64
+ dependencies,
65
+ );
66
+ expect(injected.status).toBe(400);
67
+ expect(fetchProvider).not.toHaveBeenCalled();
68
+
69
+ const result = await handleGoogleBrokerRpc(request, dependencies);
70
+ expect(result.headers.get("cache-control")).toBe("no-store");
71
+ expect(await result.json()).toEqual({
72
+ jsonrpc: "2.0",
73
+ id: 1,
74
+ result: { ids: ["message-id"] },
75
+ });
76
+ expect(dependencies.resolveGoogleCredential).toHaveBeenCalledWith(
77
+ "owner",
78
+ "account",
79
+ "owner@example.test",
80
+ "gmail",
81
+ );
82
+ expect(fetchProvider).toHaveBeenCalledWith(
83
+ "https://gmail.googleapis.com/gmail/v1/users/me/messages?maxResults=25&fields=messages(id)",
84
+ expect.objectContaining({ method: "GET", redirect: "error" }),
85
+ );
86
+
87
+ for (const token of Object.values(credentials)) {
88
+ fetchProvider.mockResolvedValueOnce(
89
+ Response.json({ messages: [{ id: token }] }),
90
+ );
91
+ const leak = await handleGoogleBrokerRpc(request, dependencies);
92
+ expect(leak.status).toBe(502);
93
+ expect(await leak.text()).not.toContain(token);
94
+ }
95
+ });
@@ -0,0 +1,107 @@
1
+ import type { createGoogleBrokerAdmission } from "../../db/google-broker-admission.js";
2
+ import {
3
+ executeGoogleBrokerOperation,
4
+ googleBrokerRequest,
5
+ googleBrokerService,
6
+ } from "./google-broker-provider.js";
7
+
8
+ type Admission = ReturnType<typeof createGoogleBrokerAdmission>;
9
+
10
+ interface Dependencies {
11
+ authenticateApp: (
12
+ authorization: string,
13
+ ) => Promise<{ appId: string; email: string; userId: string } | null>;
14
+ admit: Admission["admit"];
15
+ claim: Admission["claim"];
16
+ revealHandle: (encrypted: string) => string;
17
+ withActiveGrant: Admission["withActiveGrant"];
18
+ labEnabled: (userId: string) => Promise<boolean>;
19
+ resolveGoogleCredential: (
20
+ userId: string,
21
+ accountId: string,
22
+ assertedEmail: string,
23
+ service: Parameters<Admission["admit"]>[0]["service"],
24
+ ) => Promise<{ accessToken: string; refreshToken?: string } | null>;
25
+ fetchProvider?: typeof fetch;
26
+ }
27
+
28
+ function rpcResponse(
29
+ id: number | null,
30
+ status: number,
31
+ body:
32
+ | { result: { ids: string[] } | { handle: string } }
33
+ | { error: { code: number; message: string } },
34
+ ): Response {
35
+ return Response.json(
36
+ { jsonrpc: "2.0", id, ...body },
37
+ { status, headers: { "Cache-Control": "no-store" } },
38
+ );
39
+ }
40
+
41
+ function failure(
42
+ id: number | null,
43
+ status: number,
44
+ code: number,
45
+ message: string,
46
+ ) {
47
+ return rpcResponse(id, status, { error: { code, message } });
48
+ }
49
+
50
+ export async function handleGoogleBrokerRpc(
51
+ request: { authorization: string; handle: string; body: unknown },
52
+ dependencies: Dependencies,
53
+ ): Promise<Response> {
54
+ const parsed = googleBrokerRequest.safeParse(request.body);
55
+ if (!parsed.success) return failure(null, 400, -32600, "Invalid request");
56
+ const {
57
+ id,
58
+ params: { operation },
59
+ } = parsed.data;
60
+ try {
61
+ const app = await dependencies.authenticateApp(request.authorization);
62
+ const denied = () => failure(id, 403, -32003, "Google access denied");
63
+ if (!app || !(await dependencies.labEnabled(app.userId))) return denied();
64
+ const service = googleBrokerService(operation);
65
+ if (parsed.data.method === "google/claim") {
66
+ const stored = await dependencies.claim(app.userId, app.appId, service);
67
+ if (stored === undefined) return denied();
68
+ if (typeof stored !== "string")
69
+ throw new Error("Invalid Google grant ciphertext");
70
+ const handle = dependencies.revealHandle(stored);
71
+ if (!/^[a-f0-9]{64}$/.test(handle))
72
+ throw new Error("Invalid Google grant handle");
73
+ return rpcResponse(id, 200, { result: { handle } });
74
+ }
75
+ const grant = await dependencies.admit({
76
+ handle: request.handle,
77
+ verifiedAppId: app.appId,
78
+ verifiedUserId: app.userId,
79
+ service,
80
+ operation,
81
+ });
82
+ if (grant.status === "rate_limited") {
83
+ return failure(id, 429, -32029, "Google request limit exceeded");
84
+ }
85
+ if (grant.status !== "admitted") return denied();
86
+ const credential = await dependencies.resolveGoogleCredential(
87
+ grant.userId,
88
+ grant.accountId,
89
+ app.email,
90
+ service,
91
+ );
92
+ if (!credential) return denied();
93
+ const result = await dependencies.withActiveGrant(
94
+ request.handle,
95
+ grant.userId,
96
+ () =>
97
+ executeGoogleBrokerOperation(
98
+ operation,
99
+ credential,
100
+ dependencies.fetchProvider,
101
+ ),
102
+ );
103
+ return result ? rpcResponse(id, 200, { result }) : denied();
104
+ } catch {
105
+ return failure(id, 502, -32002, "Google request failed");
106
+ }
107
+ }
@@ -17,6 +17,7 @@ import {
17
17
  } from "@agent-native/core/settings";
18
18
 
19
19
  import { HOSTED_APPS_SETTINGS_INVALID_ERROR_CODE } from "../../shared/hosted-apps-settings.js";
20
+ import { hostedCatalogEnabled } from "./dispatch-config.js";
20
21
 
21
22
  export const HOSTED_APPS_SETTINGS_KEY = "dispatch-hosted-apps-settings";
22
23
 
@@ -64,6 +65,9 @@ function hostedAppsSettingsScope() {
64
65
  export async function readHostedAppsSettings(): Promise<
65
66
  HostedAppsSettings & { invalid: boolean }
66
67
  > {
68
+ if (!hostedCatalogEnabled()) {
69
+ return { showHostedApps: false, invalid: false };
70
+ }
67
71
  const scope = hostedAppsSettingsScope();
68
72
  // No org and no user means there is nowhere the setting could be stored.
69
73
  if (!scope) return { showHostedApps: true, invalid: false };