@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
@@ -0,0 +1,342 @@
1
+ import type { ActionSuggestion } from "@agent-native/agentkit/protocol";
2
+ import type { ActionRunContext } from "@agent-native/core/action";
3
+ import { beforeEach, expect, it, vi } from "vitest";
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ getOrgId: vi.fn(),
7
+ getWorkspaceUrl: vi.fn(),
8
+ getSettings: vi.fn(),
9
+ isLocal: vi.fn(),
10
+ startCreation: vi.fn(),
11
+ listWorkspaceApps: vi.fn(),
12
+ resolveApp: vi.fn(),
13
+ listActions: vi.fn(),
14
+ callAction: vi.fn(),
15
+ }));
16
+
17
+ vi.mock("@agent-native/core/server", () => ({
18
+ getBuilderWorkspaceUrl: mocks.getWorkspaceUrl,
19
+ getRequestOrgId: mocks.getOrgId,
20
+ getRequestUserEmail: () => "owner@example.test",
21
+ readOrgMemberRole: () => "owner",
22
+ }));
23
+ vi.mock("../server/lib/app-creation-store.js", () => ({
24
+ getAppCreationSettings: mocks.getSettings,
25
+ isLocalAppCreationRuntime: mocks.isLocal,
26
+ startWorkspaceAppCreation: mocks.startCreation,
27
+ listWorkspaceApps: mocks.listWorkspaceApps,
28
+ }));
29
+ vi.mock("../server/lib/mcp-gateway.js", () => ({
30
+ resolveGrantedDispatchMcpApp: mocks.resolveApp,
31
+ listGrantedDispatchMcpAppActions: mocks.listActions,
32
+ callGrantedDispatchMcpAppAction: mocks.callAction,
33
+ }));
34
+
35
+ import execute from "./execute-action-suggestion.js";
36
+ import propose from "./propose-action-suggestions.js";
37
+
38
+ const build = {
39
+ id: "equipment-tracker",
40
+ kind: "create-app",
41
+ trigger: "new-domain",
42
+ label: "Build an equipment tracker",
43
+ rationale: "Track who has each item and when it is due.",
44
+ appId: "dispatch",
45
+ execution: {
46
+ type: "create-app",
47
+ domainSpec: "Track checkout and return of shared equipment.",
48
+ },
49
+ } satisfies ActionSuggestion;
50
+
51
+ const filter = {
52
+ id: "human-notifications",
53
+ kind: "filter",
54
+ trigger: "ai-narrowing",
55
+ label: "Save human notifications",
56
+ rationale: "See replies from people in one view.",
57
+ appId: "workspace/mail",
58
+ execution: {
59
+ type: "action",
60
+ action: "create-split",
61
+ params: { senderType: "human" },
62
+ },
63
+ } satisfies ActionSuggestion;
64
+
65
+ const browser = { caller: "frontend" } satisfies ActionRunContext;
66
+
67
+ beforeEach(() => {
68
+ vi.resetAllMocks();
69
+ mocks.getOrgId.mockReturnValue("workspace");
70
+ mocks.getSettings.mockResolvedValue({ builderBranchingEnabled: true });
71
+ mocks.resolveApp.mockResolvedValue({ id: filter.appId });
72
+ mocks.listActions.mockResolvedValue([{ name: filter.execution.action }]);
73
+ mocks.callAction.mockResolvedValue({ content: [] });
74
+ });
75
+
76
+ it("offers a no-app creation suggestion without opening an app or starting creation", async () => {
77
+ expect(await propose.run({ suggestions: [build, build] })).toEqual({
78
+ suggestions: [build],
79
+ });
80
+ expect(mocks.resolveApp).not.toHaveBeenCalled();
81
+ expect(mocks.startCreation).not.toHaveBeenCalled();
82
+
83
+ mocks.startCreation.mockResolvedValue({
84
+ mode: "builder",
85
+ url: "https://builder.example.test/branches/equipment",
86
+ });
87
+ expect(await execute.run({ suggestion: build }, browser)).toEqual({
88
+ suggestionId: build.id,
89
+ status: "accepted",
90
+ outcome: "app-creation-started",
91
+ url: "https://builder.example.test/branches/equipment",
92
+ });
93
+ expect(mocks.startCreation).toHaveBeenCalledWith({
94
+ prompt: build.execution.domainSpec,
95
+ });
96
+ });
97
+
98
+ it("rechecks current action access before returning an accepted receipt", async () => {
99
+ expect(await propose.run({ suggestions: [filter] })).toEqual({
100
+ suggestions: [filter],
101
+ });
102
+ mocks.listActions.mockResolvedValue([]);
103
+ await expect(
104
+ execute.run({ suggestion: filter }, browser),
105
+ ).rejects.toMatchObject({
106
+ errorCode: "action_suggestion_unavailable",
107
+ });
108
+ expect(mocks.callAction).not.toHaveBeenCalled();
109
+
110
+ mocks.listActions.mockResolvedValue([{ name: filter.execution.action }]);
111
+ expect(await execute.run({ suggestion: filter }, browser)).toEqual({
112
+ suggestionId: filter.id,
113
+ status: "accepted",
114
+ outcome: "action-completed",
115
+ });
116
+ expect(mocks.callAction).toHaveBeenCalledExactlyOnceWith(
117
+ filter.appId,
118
+ filter.execution.action,
119
+ filter.execution.params,
120
+ );
121
+ });
122
+
123
+ it("preserves a review requirement from the existing app action path", async () => {
124
+ const approvalReview = {
125
+ url: "https://mail.example.test/#mcpApproval=00000000-0000-4000-8000-000000000000",
126
+ };
127
+ mocks.callAction.mockResolvedValue({
128
+ isError: true,
129
+ approvalReview,
130
+ content: [],
131
+ });
132
+ await expect(
133
+ execute.run({ suggestion: filter }, browser),
134
+ ).rejects.toMatchObject({
135
+ errorCode: "approval_required",
136
+ details: { approvalReview },
137
+ });
138
+ });
139
+
140
+ it("rejects a benign-looking suggestion when its real action is marked destructive", async () => {
141
+ mocks.listActions.mockResolvedValue([
142
+ { name: filter.execution.action, destructive: true },
143
+ ]);
144
+
145
+ expect(await propose.run({ suggestions: [filter] })).toEqual({
146
+ suggestions: [],
147
+ });
148
+ await expect(
149
+ execute.run({ suggestion: filter }, browser),
150
+ ).rejects.toMatchObject({
151
+ errorCode: "action_suggestion_unavailable",
152
+ });
153
+ expect(mocks.callAction).not.toHaveBeenCalled();
154
+ });
155
+
156
+ it("requires an explicit safe selection from actions that also offer deletion", async () => {
157
+ const multiplexed = {
158
+ ...filter,
159
+ execution: { type: "action", action: "manage-splits", params: {} },
160
+ } satisfies ActionSuggestion;
161
+ mocks.listActions.mockResolvedValue([
162
+ {
163
+ name: multiplexed.execution.action,
164
+ inputSchema: {
165
+ properties: { operation: { enum: ["create", "delete"] } },
166
+ },
167
+ },
168
+ ]);
169
+
170
+ for (const params of [{}, { operation: "delete" }]) {
171
+ const suggestion = {
172
+ ...multiplexed,
173
+ execution: { ...multiplexed.execution, params },
174
+ };
175
+ await expect(execute.run({ suggestion }, browser)).rejects.toMatchObject({
176
+ errorCode: "action_suggestion_unavailable",
177
+ });
178
+ }
179
+ expect(mocks.callAction).not.toHaveBeenCalled();
180
+
181
+ const safe = {
182
+ ...multiplexed,
183
+ execution: { ...multiplexed.execution, params: { operation: "create" } },
184
+ };
185
+ expect(await propose.run({ suggestions: [safe] })).toEqual({
186
+ suggestions: [safe],
187
+ });
188
+ await expect(
189
+ execute.run({ suggestion: safe }, browser),
190
+ ).resolves.toMatchObject({
191
+ status: "accepted",
192
+ });
193
+ });
194
+
195
+ it.each(["thread-delete", "deleteThread", "thread.delete"])(
196
+ "rejects the explicit destructive token in %s",
197
+ async (action) => {
198
+ const suggestion = {
199
+ ...filter,
200
+ execution: { ...filter.execution, action },
201
+ };
202
+ mocks.listActions.mockResolvedValue([{ name: action }]);
203
+ await expect(execute.run({ suggestion }, browser)).rejects.toMatchObject({
204
+ errorCode: "action_suggestion_unavailable",
205
+ });
206
+ expect(mocks.callAction).not.toHaveBeenCalled();
207
+ },
208
+ );
209
+
210
+ it("requires a safe nested selection in a mixed schema", async () => {
211
+ const action = "manage-splits";
212
+ mocks.listActions.mockResolvedValue([
213
+ {
214
+ name: action,
215
+ inputSchema: {
216
+ properties: {
217
+ options: {
218
+ properties: { operation: { enum: ["create", "bulk-delete"] } },
219
+ },
220
+ },
221
+ },
222
+ },
223
+ ]);
224
+ for (const params of [{}, { options: { operation: "bulk-delete" } }]) {
225
+ const suggestion = {
226
+ ...filter,
227
+ execution: { type: "action" as const, action, params },
228
+ };
229
+ await expect(execute.run({ suggestion }, browser)).rejects.toMatchObject({
230
+ errorCode: "action_suggestion_unavailable",
231
+ });
232
+ }
233
+ expect(mocks.callAction).not.toHaveBeenCalled();
234
+ const safe = {
235
+ ...filter,
236
+ execution: {
237
+ type: "action" as const,
238
+ action,
239
+ params: { options: { operation: "create" } },
240
+ },
241
+ };
242
+ await expect(
243
+ execute.run({ suggestion: safe }, browser),
244
+ ).resolves.toMatchObject({
245
+ status: "accepted",
246
+ });
247
+ });
248
+
249
+ it("returns an accessible existing app when creation reports its id is registered", async () => {
250
+ mocks.startCreation.mockResolvedValue({
251
+ mode: "app-id-taken",
252
+ appId: "equipment",
253
+ conflict: "registered",
254
+ });
255
+ mocks.listWorkspaceApps.mockResolvedValue([
256
+ {
257
+ id: "equipment",
258
+ url: "https://equipment.example.test/",
259
+ status: "ready",
260
+ },
261
+ ]);
262
+ expect(await execute.run({ suggestion: build }, browser)).toEqual({
263
+ suggestionId: build.id,
264
+ status: "accepted",
265
+ outcome: "action-completed",
266
+ url: "https://equipment.example.test/",
267
+ });
268
+ });
269
+
270
+ it("does not expose a conflicting app outside the visible workspace", async () => {
271
+ mocks.startCreation.mockResolvedValue({
272
+ mode: "app-id-taken",
273
+ appId: "equipment",
274
+ conflict: "registered",
275
+ });
276
+ mocks.listWorkspaceApps.mockResolvedValue([]);
277
+ await expect(
278
+ execute.run({ suggestion: build }, browser),
279
+ ).rejects.toMatchObject({ errorCode: "action_suggestion_unavailable" });
280
+ });
281
+
282
+ it("treats an action whose target already exists as completed", async () => {
283
+ mocks.callAction.mockResolvedValue({
284
+ isError: true,
285
+ content: [
286
+ {
287
+ type: "text",
288
+ text: "Split already exists (errorCode: already_exists)",
289
+ },
290
+ ],
291
+ });
292
+ expect(await execute.run({ suggestion: filter }, browser)).toEqual({
293
+ suggestionId: filter.id,
294
+ status: "accepted",
295
+ outcome: "action-completed",
296
+ });
297
+ });
298
+
299
+ it("still fails an action that errors for another reason", async () => {
300
+ mocks.callAction.mockResolvedValue({
301
+ isError: true,
302
+ content: [{ type: "text", text: "Boom (errorCode: app_failed)" }],
303
+ });
304
+ await expect(
305
+ execute.run({ suggestion: filter }, browser),
306
+ ).rejects.toMatchObject({ errorCode: "app_failed" });
307
+ });
308
+
309
+ it.each([
310
+ ["Split already exists", "app_failed"],
311
+ ["Boom", "duplicate_input"],
312
+ ["Parent folder does not exist", "folder_not_exists"],
313
+ ])("does not report %s (%s) as completed", async (text, code) => {
314
+ mocks.callAction.mockResolvedValue({
315
+ isError: true,
316
+ content: [{ type: "text", text: `${text} (errorCode: ${code})` }],
317
+ });
318
+ await expect(
319
+ execute.run({ suggestion: filter }, browser),
320
+ ).rejects.toMatchObject({ errorCode: code });
321
+ });
322
+
323
+ it("opens the pending Builder branch when the app is already being created", async () => {
324
+ mocks.startCreation.mockResolvedValue({
325
+ mode: "app-id-taken",
326
+ appId: "equipment",
327
+ conflict: "pending",
328
+ });
329
+ mocks.listWorkspaceApps.mockResolvedValue([
330
+ {
331
+ id: "equipment",
332
+ url: "https://builder.example.test/branches/equipment",
333
+ status: "pending",
334
+ },
335
+ ]);
336
+ expect(await execute.run({ suggestion: build }, browser)).toEqual({
337
+ suggestionId: build.id,
338
+ status: "accepted",
339
+ outcome: "app-creation-started",
340
+ url: "https://builder.example.test/branches/equipment",
341
+ });
342
+ });
@@ -1,5 +1,13 @@
1
1
  import { createRequire } from "node:module";
2
2
 
3
+ import {
4
+ invocationEffect,
5
+ isNoWriteError,
6
+ NoWriteError,
7
+ runActionWithExecutionOutcome,
8
+ type ActionExecutionOutcome,
9
+ type ActionRunContext,
10
+ } from "@agent-native/core/action";
3
11
  import { createMCPServerForRequest } from "@agent-native/core/mcp";
4
12
  import { beforeEach, describe, expect, it, vi } from "vitest";
5
13
 
@@ -29,6 +37,25 @@ import readView from "./read_view.js";
29
37
 
30
38
  const ctx = { caller: "mcp" } as never;
31
39
 
40
+ async function failedEffect(args: Record<string, unknown>) {
41
+ const outcome: ActionExecutionOutcome = { refused: false };
42
+ const error = await runActionWithExecutionOutcome(
43
+ callAppAction.run as (
44
+ args: never,
45
+ ctx?: ActionRunContext,
46
+ ) => Promise<never>,
47
+ args as never,
48
+ ctx as ActionRunContext,
49
+ outcome,
50
+ callAppAction,
51
+ ).then(
52
+ () => undefined,
53
+ (thrown: unknown) => thrown,
54
+ );
55
+ expect(error).toBeDefined();
56
+ return invocationEffect(callAppAction, outcome, { failed: { error } }).effect;
57
+ }
58
+
32
59
  describe("app action tools", () => {
33
60
  beforeEach(() => vi.clearAllMocks());
34
61
 
@@ -104,6 +131,32 @@ describe("app action tools", () => {
104
131
  arguments: { app: "slides", action: "list-decks" },
105
132
  });
106
133
  expect(failure.isError).toBe(true);
134
+ mocks.callAction.mockRejectedValue(
135
+ new NoWriteError("Connect the app.", {
136
+ errorCode: "authorization_required",
137
+ details: {
138
+ authorizationUrl:
139
+ "https://dispatch.example.test/_agent-native/mcp/servers/oauth/start?name=app",
140
+ },
141
+ }),
142
+ );
143
+ const authorization = await client.callTool({
144
+ name: "call_app_action",
145
+ arguments: { app: "slides", action: "list-decks" },
146
+ });
147
+ expect(authorization.isError).toBe(true);
148
+ expect(authorization.content).toEqual([
149
+ expect.objectContaining({
150
+ text: expect.stringContaining("authorization_required"),
151
+ }),
152
+ ]);
153
+ expect(authorization.content).toEqual([
154
+ expect.objectContaining({
155
+ text: expect.stringContaining(
156
+ "https://dispatch.example.test/_agent-native/mcp/servers/oauth/start?name=app",
157
+ ),
158
+ }),
159
+ ]);
107
160
  } finally {
108
161
  await client.close();
109
162
  await server.close();
@@ -135,6 +188,56 @@ describe("app action tools", () => {
135
188
  );
136
189
  });
137
190
 
191
+ it("reports an input-check refusal as a call that wrote nothing", async () => {
192
+ mocks.callAction.mockResolvedValue({
193
+ isError: true,
194
+ content: [{ type: "text", text: "Error: Invalid action parameters" }],
195
+ });
196
+ const error = await callAppAction
197
+ .run(
198
+ { app: "mail", action: "send-gmail-message", args: {} } as never,
199
+ ctx,
200
+ )
201
+ .catch((caught: Error) => caught);
202
+ expect(isNoWriteError(error)).toBe(true);
203
+ expect(
204
+ await failedEffect({
205
+ app: "mail",
206
+ action: "send-gmail-message",
207
+ args: {},
208
+ }),
209
+ ).toBe("none");
210
+ expect((error as Error).message).toBe(
211
+ "Error: Invalid action parameters Nothing was changed.",
212
+ );
213
+ expect(error).toMatchObject({
214
+ errorCode: "app_action_invalid_parameters",
215
+ statusCode: 400,
216
+ });
217
+ });
218
+
219
+ it("keeps a handler failure's write outcome unknown", async () => {
220
+ mocks.callAction.mockResolvedValue({
221
+ isError: true,
222
+ content: [{ type: "text", text: "Error: Gmail rejected the message" }],
223
+ });
224
+ const error = await callAppAction
225
+ .run(
226
+ { app: "mail", action: "send-gmail-message", args: {} } as never,
227
+ ctx,
228
+ )
229
+ .catch((caught: Error) => caught);
230
+ expect(isNoWriteError(error)).toBe(false);
231
+ expect(
232
+ await failedEffect({
233
+ app: "mail",
234
+ action: "send-gmail-message",
235
+ args: {},
236
+ }),
237
+ ).toBe("unknown");
238
+ expect((error as Error).message).toMatch(/write outcome may be unknown/);
239
+ });
240
+
138
241
  it("reports an approval wait as approval_required with one errorCode", async () => {
139
242
  mocks.callAction.mockResolvedValue({
140
243
  isError: true,
@@ -7,10 +7,16 @@ import { askGrantedDispatchMcpApp } from "../server/lib/mcp-gateway.js";
7
7
 
8
8
  export default defineAction({
9
9
  description:
10
- "Route a natural-language request to any app granted through this existing Dispatch MCP connection; do not require a separate app MCP connection. Call list_apps first to see which apps are granted.",
10
+ "Send a natural-language request to an app accessible through this Dispatch connection. Accepts a granted `app` id (such as those returned by `list_apps`) and routes the message to that app's agent.",
11
11
  schema: z.object({
12
12
  app: z.string().describe("Granted app id, e.g. mail or calendar."),
13
13
  message: z.string().describe("The request to send to that app's agent."),
14
+ viewportMode: z
15
+ .enum(["foreground", "background"])
16
+ .optional()
17
+ .describe(
18
+ 'Viewport targeting mode; "background" keeps the current foreground pane unchanged.',
19
+ ),
14
20
  async: z
15
21
  .boolean()
16
22
  .optional()
@@ -22,10 +28,11 @@ export default defineAction({
22
28
  .optional()
23
29
  .describe("Maximum inline wait in milliseconds."),
24
30
  }),
25
- run: async ({ app, message, async, maxWaitMs }, ctx) => {
31
+ run: async ({ app, message, viewportMode, async, maxWaitMs }, ctx) => {
26
32
  const result = await askGrantedDispatchMcpApp(app, message, {
27
33
  async,
28
34
  maxWaitMs,
35
+ ...(viewportMode ? { viewportMode } : {}),
29
36
  });
30
37
  track(
31
38
  "a2a_delegated",
@@ -9,8 +9,19 @@ export default defineAction({
9
9
  schema: z.object({
10
10
  app: z.string().describe("Granted app id returned by ask_app."),
11
11
  taskId: z.string().describe("The durable task id returned by ask_app."),
12
+ taskHandle: z
13
+ .string()
14
+ .optional()
15
+ .describe(
16
+ "Opaque sealed task handle returned by ask_app. Preserves the original target route across polls.",
17
+ ),
12
18
  }),
13
19
  readOnly: true,
14
20
  parallelSafe: true,
15
- run: async ({ app, taskId }) => getGrantedDispatchMcpAppTask(app, taskId),
21
+ run: async ({ app, taskId, taskHandle }) =>
22
+ getGrantedDispatchMcpAppTask(
23
+ app,
24
+ taskId,
25
+ taskHandle !== undefined ? { taskHandle } : undefined,
26
+ ),
16
27
  });
@@ -1,15 +1,21 @@
1
- import { defineAction, fail } from "@agent-native/core/action";
1
+ import {
2
+ defineAction,
3
+ fail,
4
+ noteExternalWrite,
5
+ NoWriteError,
6
+ } from "@agent-native/core/action";
2
7
  import { z } from "zod";
3
8
 
4
9
  import {
5
10
  appActionErrorCode,
11
+ appActionRefusedBeforeRun,
6
12
  appActionResultText,
7
13
  } from "../server/lib/app-action-result.js";
8
14
  import { callGrantedDispatchMcpAppAction } from "../server/lib/mcp-gateway.js";
9
15
 
10
16
  export default defineAction({
11
17
  description:
12
- "Run one action of a granted app as the signed-in user and return its result in about a second. Prefer this to ask_app whenever the step is a known action (list the inbox, read a thread, create a draft, list or move an event); ask_app runs the app's whole agent and takes 20 seconds or more. Call list_app_actions first for names and inputs. The app's screen updates from the same data, so call open_app once to show it beside the chat.",
18
+ "Run a single named action on a granted app as the signed-in user (such as listing an inbox, reading a thread, creating a draft, or listing or moving an event). Accepts an `app` id, an `action` name and input `args` (as described by `list_app_actions`), and returns the action result directly without running the app's agent.",
13
19
  schema: z.object({
14
20
  app: z.string().describe("Granted app id, e.g. mail or calendar."),
15
21
  action: z
@@ -19,6 +25,12 @@ export default defineAction({
19
25
  .record(z.string(), z.unknown())
20
26
  .optional()
21
27
  .describe("Action input matching its schema."),
28
+ viewportMode: z
29
+ .enum(["foreground", "background"])
30
+ .optional()
31
+ .describe(
32
+ 'Viewport targeting mode; "background" keeps the current foreground pane unchanged.',
33
+ ),
22
34
  }),
23
35
  mcpOutputSchema: true,
24
36
  outputErrorStrategy: "strict",
@@ -31,12 +43,14 @@ export default defineAction({
31
43
  content: z.array(z.unknown()),
32
44
  }),
33
45
  mcpApp: { structuredContent: true },
34
- run: async ({ app, action, args }) => {
35
- const result = await callGrantedDispatchMcpAppAction(
36
- app,
37
- action,
38
- args ?? {},
39
- );
46
+ run: async ({ app, action, args, viewportMode }) => {
47
+ noteExternalWrite("app-action");
48
+ const actionArgs = args ?? {};
49
+ const result = viewportMode
50
+ ? await callGrantedDispatchMcpAppAction(app, action, actionArgs, {
51
+ viewportMode,
52
+ })
53
+ : await callGrantedDispatchMcpAppAction(app, action, actionArgs);
40
54
  if (result.isError !== true) return result;
41
55
  const text = appActionResultText(result);
42
56
  if (result.approvalReview) {
@@ -50,6 +64,12 @@ export default defineAction({
50
64
  const message = appCode
51
65
  ? text.replace(/(\s*\(errorCode: [a-z0-9_]+\))+\s*$/i, "")
52
66
  : text || "The app action failed.";
67
+ if (appActionRefusedBeforeRun(message)) {
68
+ throw new NoWriteError(`${message} Nothing was changed.`, {
69
+ errorCode: appCode ?? "app_action_invalid_parameters",
70
+ statusCode: 400,
71
+ });
72
+ }
53
73
  // A failed write can still have landed part of its change in the app.
54
74
  fail(
55
75
  `${message} Its write outcome may be unknown; inspect the app before retrying.`,
@@ -5,7 +5,7 @@ import { createGrantedDispatchMcpEmbedSession } from "../server/lib/mcp-gateway.
5
5
 
6
6
  export default defineAction({
7
7
  description:
8
- "MCP Apps helper: create a browser embed session for a Dispatch-granted app URL. Usually called by an MCP App iframe, not directly by the model.",
8
+ "Create a one-time browser embed session for a Dispatch-granted app URL, used by embedded MCP App views.",
9
9
  schema: z.object({
10
10
  app: z
11
11
  .string()
@@ -27,5 +27,11 @@ export default defineAction({
27
27
  readOnly: false,
28
28
  parallelSafe: true,
29
29
  mcpApp: { visibility: ["app"] },
30
- run: async (args) => createGrantedDispatchMcpEmbedSession(args),
30
+ run: async (args, context) =>
31
+ createGrantedDispatchMcpEmbedSession(
32
+ args,
33
+ context?.caller === "http" && args.chrome === "minimal"
34
+ ? { bindBrowserTab: true }
35
+ : undefined,
36
+ ),
31
37
  });
@@ -91,6 +91,11 @@ export default defineAction({
91
91
  toolCallable: false,
92
92
  run: async (args, context) => {
93
93
  await assertWorkspaceEmbedSessionCaller(context?.requestHeaders);
94
- return createWorkspaceSsoEmbedSession(args);
94
+ return createWorkspaceSsoEmbedSession(
95
+ args,
96
+ context?.caller === "http" && args.chrome === "minimal"
97
+ ? { bindBrowserTab: true }
98
+ : undefined,
99
+ );
95
100
  },
96
101
  });