@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,432 @@
1
+ import type {
2
+ ActionSuggestion,
3
+ ActionSuggestionReceipt,
4
+ } from "@agent-native/agentkit/protocol";
5
+ import { sendToAgentChat } from "@agent-native/core/client/agent-chat";
6
+ import {
7
+ actionErrorCode,
8
+ useActionMutation,
9
+ } from "@agent-native/core/client/hooks";
10
+ import { useT } from "@agent-native/core/client/i18n";
11
+ import { useAgentThread } from "@agent-native/toolkit/app/agentkit/react";
12
+ import { IconInfoCircle, IconX } from "@tabler/icons-react";
13
+ import { useMemo, useRef, useState } from "react";
14
+
15
+ import {
16
+ ACTION_SUGGESTION_EXECUTION,
17
+ selectTurnActionSuggestions,
18
+ suggestedActionOperations,
19
+ requiresSuggestionReview,
20
+ } from "../lib/action-suggestions.js";
21
+ import { Button } from "./ui/button.js";
22
+ import {
23
+ Dialog,
24
+ DialogContent,
25
+ DialogDescription,
26
+ DialogFooter,
27
+ DialogHeader,
28
+ DialogTitle,
29
+ } from "./ui/dialog.js";
30
+
31
+ function approvalLink(error: unknown): string | undefined {
32
+ if (
33
+ !error ||
34
+ typeof error !== "object" ||
35
+ !("details" in error) ||
36
+ !error.details ||
37
+ typeof error.details !== "object" ||
38
+ !("approvalReview" in error.details)
39
+ )
40
+ return undefined;
41
+ const review = error.details.approvalReview;
42
+ if (
43
+ !review ||
44
+ typeof review !== "object" ||
45
+ !("url" in review) ||
46
+ typeof review.url !== "string"
47
+ )
48
+ return undefined;
49
+ if (!URL.canParse(review.url)) return undefined;
50
+ const url = new URL(review.url);
51
+ const isLocal =
52
+ url.protocol === "http:" &&
53
+ ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
54
+ if (url.protocol !== "https:" && !isLocal) return undefined;
55
+ if (url.username || url.password) return undefined;
56
+ if (!new URLSearchParams(url.hash.slice(1)).has("mcpApproval"))
57
+ return undefined;
58
+ return url.href;
59
+ }
60
+
61
+ function SuggestionOperation({ suggestion }: { suggestion: ActionSuggestion }) {
62
+ const t = useT();
63
+ const { execution } = suggestion;
64
+ if (execution.type === "create-app") {
65
+ return t("dispatch.pages.suggestionCreateAppOperation", {
66
+ defaultValue: "Create app in this workspace",
67
+ });
68
+ }
69
+ if (execution.type === "customize") {
70
+ return (
71
+ <>
72
+ {t("dispatch.pages.suggestionCustomizeOperation", {
73
+ defaultValue: "Customize",
74
+ })}
75
+ {" · "}
76
+ <bdi>{execution.targetAppId}</bdi>
77
+ </>
78
+ );
79
+ }
80
+
81
+ const operations = suggestedActionOperations(execution);
82
+ return (
83
+ <>
84
+ <bdi>{suggestion.appId}</bdi>
85
+ {" · "}
86
+ <bdi>{execution.action}</bdi>
87
+ {operations.length > 0 ? (
88
+ <>
89
+ {" · "}
90
+ <bdi>{operations.join(", ")}</bdi>
91
+ </>
92
+ ) : null}
93
+ </>
94
+ );
95
+ }
96
+
97
+ function argumentLabel(key: string): string {
98
+ const label = key
99
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
100
+ .replace(/[_-]+/g, " ");
101
+ return label.charAt(0).toUpperCase() + label.slice(1);
102
+ }
103
+
104
+ function ReviewValue({ value }: { value: unknown }) {
105
+ const t = useT();
106
+ if (value === null)
107
+ return (
108
+ <>{t("dispatch.pages.suggestionNullValue", { defaultValue: "None" })}</>
109
+ );
110
+ if (value === undefined) return null;
111
+ if (Array.isArray(value))
112
+ return (
113
+ <ul className="list-inside list-disc">
114
+ {value.map((item, index) => (
115
+ <li key={index}>
116
+ <ReviewValue value={item} />
117
+ </li>
118
+ ))}
119
+ </ul>
120
+ );
121
+ if (typeof value === "object")
122
+ return (
123
+ <dl className="space-y-2">
124
+ {Object.entries(value).map(([key, item]) => (
125
+ <div key={key}>
126
+ <dt className="font-medium">{argumentLabel(key)}</dt>
127
+ <dd>
128
+ <ReviewValue value={item} />
129
+ </dd>
130
+ </div>
131
+ ))}
132
+ </dl>
133
+ );
134
+ if (typeof value === "boolean")
135
+ return (
136
+ <>
137
+ {t(
138
+ value
139
+ ? "dispatch.pages.suggestionYesValue"
140
+ : "dispatch.pages.suggestionNoValue",
141
+ {
142
+ defaultValue: value ? "Yes" : "No",
143
+ },
144
+ )}
145
+ </>
146
+ );
147
+ return <span dir="auto">{String(value)}</span>;
148
+ }
149
+
150
+ export function ChatActionSuggestions({ threadId }: { threadId: string }) {
151
+ const thread = useAgentThread(threadId);
152
+ const turn = useMemo(() => selectTurnActionSuggestions(thread), [thread]);
153
+ return turn ? (
154
+ <ActionSuggestionChips
155
+ key={`${threadId}:${turn.runId}`}
156
+ suggestions={turn.suggestions}
157
+ />
158
+ ) : null;
159
+ }
160
+
161
+ export function ActionSuggestionChips({
162
+ suggestions,
163
+ }: {
164
+ suggestions: ActionSuggestion[];
165
+ }) {
166
+ const t = useT();
167
+ const execution = useActionMutation<
168
+ ActionSuggestionReceipt,
169
+ { suggestion: ActionSuggestion }
170
+ >(ACTION_SUGGESTION_EXECUTION, { uiOnly: true, retry: false });
171
+ const executing = useRef(false);
172
+ const [handled, setHandled] = useState<Set<string>>(new Set());
173
+ const [pendingId, setPendingId] = useState<string>();
174
+ const [review, setReview] = useState<ActionSuggestion>();
175
+ const [receipt, setReceipt] = useState<ActionSuggestionReceipt>();
176
+ const [failure, setFailure] = useState<{
177
+ approval: boolean;
178
+ url: string | undefined;
179
+ }>();
180
+
181
+ function hide(suggestionId: string) {
182
+ setHandled((current) => new Set(current).add(suggestionId));
183
+ }
184
+
185
+ async function execute(suggestion: ActionSuggestion) {
186
+ if (executing.current || handled.has(suggestion.id)) return;
187
+ executing.current = true;
188
+ setPendingId(suggestion.id);
189
+ setReceipt(undefined);
190
+ setFailure(undefined);
191
+ try {
192
+ const result = await execution.mutateAsync({ suggestion });
193
+ if (result.suggestionId !== suggestion.id)
194
+ throw new Error("Mismatched suggestion receipt");
195
+ if (
196
+ result.status === "handoff" &&
197
+ result.outcome === "local-app-creation"
198
+ ) {
199
+ sendToAgentChat({
200
+ message: result.prompt,
201
+ submit: true,
202
+ type: "code",
203
+ newTab: true,
204
+ reuseEmptyTab: true,
205
+ });
206
+ }
207
+ hide(suggestion.id);
208
+ setReceipt(result);
209
+ } catch (error) {
210
+ hide(suggestion.id);
211
+ const approval = actionErrorCode(error) === "approval_required";
212
+ setFailure({ approval, url: approval ? approvalLink(error) : undefined });
213
+ } finally {
214
+ executing.current = false;
215
+ setPendingId(undefined);
216
+ }
217
+ }
218
+
219
+ const visible = suggestions.filter(
220
+ (suggestion) => !handled.has(suggestion.id),
221
+ );
222
+ if (!visible.length && !receipt && !failure) return null;
223
+ const candidateUrl = receipt && "url" in receipt ? receipt.url : undefined;
224
+ const parsedUrl =
225
+ candidateUrl && URL.canParse(candidateUrl)
226
+ ? new URL(candidateUrl)
227
+ : undefined;
228
+ const receiptUrl =
229
+ parsedUrl &&
230
+ !parsedUrl.username &&
231
+ !parsedUrl.password &&
232
+ (parsedUrl.protocol === "https:" ||
233
+ (parsedUrl.protocol === "http:" &&
234
+ ["localhost", "127.0.0.1", "[::1]"].includes(parsedUrl.hostname)))
235
+ ? parsedUrl.href
236
+ : undefined;
237
+
238
+ return (
239
+ <div className="flex flex-wrap items-center gap-2 py-2">
240
+ {visible.map((suggestion) => (
241
+ <div
242
+ key={suggestion.id}
243
+ className="inline-flex max-w-full items-center rounded-full border border-border"
244
+ >
245
+ <Button
246
+ type="button"
247
+ variant="ghost"
248
+ size="sm"
249
+ className="h-auto min-w-0 flex-col items-start gap-0 rounded-l-full rounded-r-none py-1.5 text-left whitespace-normal"
250
+ title={suggestion.rationale}
251
+ disabled={pendingId !== undefined}
252
+ aria-busy={pendingId === suggestion.id}
253
+ onClick={() => {
254
+ if (requiresSuggestionReview(suggestion)) setReview(suggestion);
255
+ else void execute(suggestion);
256
+ }}
257
+ >
258
+ <span dir="auto">{suggestion.label}</span>
259
+ <span className="text-xs text-muted-foreground [overflow-wrap:anywhere]">
260
+ <SuggestionOperation suggestion={suggestion} />
261
+ </span>
262
+ </Button>
263
+ {!requiresSuggestionReview(suggestion) ? (
264
+ <Button
265
+ type="button"
266
+ variant="ghost"
267
+ size="sm"
268
+ className="rounded-none px-2 text-muted-foreground"
269
+ aria-label={t("dispatch.pages.reviewActionSuggestionLabel", {
270
+ defaultValue: "Review {{label}}",
271
+ label: suggestion.label,
272
+ })}
273
+ disabled={pendingId !== undefined}
274
+ onClick={() => setReview(suggestion)}
275
+ >
276
+ <IconInfoCircle size={14} aria-hidden="true" />
277
+ </Button>
278
+ ) : null}
279
+ <Button
280
+ type="button"
281
+ variant="ghost"
282
+ size="sm"
283
+ className="rounded-l-none rounded-r-full px-2 text-muted-foreground"
284
+ aria-label={t("dispatch.pages.dismissActionSuggestion", {
285
+ defaultValue: "Dismiss {{label}}",
286
+ label: suggestion.label,
287
+ })}
288
+ disabled={pendingId === suggestion.id}
289
+ onClick={() => hide(suggestion.id)}
290
+ >
291
+ <IconX size={14} aria-hidden="true" />
292
+ </Button>
293
+ </div>
294
+ ))}
295
+ <Dialog
296
+ open={review !== undefined}
297
+ onOpenChange={(open) => {
298
+ if (!open) setReview(undefined);
299
+ }}
300
+ >
301
+ {review ? (
302
+ <DialogContent>
303
+ <DialogHeader>
304
+ <DialogTitle>
305
+ {t("dispatch.pages.reviewActionSuggestionTitle", {
306
+ defaultValue: "Review suggested action",
307
+ })}
308
+ </DialogTitle>
309
+ <DialogDescription>
310
+ <SuggestionOperation suggestion={review} />
311
+ </DialogDescription>
312
+ </DialogHeader>
313
+ <div className="max-h-[50vh] overflow-auto rounded-md border border-border p-3 text-sm whitespace-pre-wrap [overflow-wrap:anywhere]">
314
+ {review.execution.type === "action" ? (
315
+ <dl className="space-y-2">
316
+ <div>
317
+ <dt className="font-medium">
318
+ {t("dispatch.pages.suggestionActionLabel", {
319
+ defaultValue: "Action",
320
+ })}
321
+ </dt>
322
+ <dd dir="auto">{argumentLabel(review.execution.action)}</dd>
323
+ </div>
324
+ <div>
325
+ <dt className="font-medium">
326
+ {t("dispatch.pages.suggestionAppLabel", {
327
+ defaultValue: "App",
328
+ })}
329
+ </dt>
330
+ <dd dir="auto">{review.appId}</dd>
331
+ </div>
332
+ {Object.entries(review.execution.params).map(
333
+ ([key, item]) => (
334
+ <div key={key}>
335
+ <dt className="font-medium">{argumentLabel(key)}</dt>
336
+ <dd>
337
+ <ReviewValue value={item} />
338
+ </dd>
339
+ </div>
340
+ ),
341
+ )}
342
+ </dl>
343
+ ) : (
344
+ <span dir="auto">
345
+ {review.execution.type === "customize"
346
+ ? review.execution.editSpec
347
+ : review.execution.domainSpec}
348
+ </span>
349
+ )}
350
+ </div>
351
+ <DialogFooter>
352
+ <Button
353
+ type="button"
354
+ variant="outline"
355
+ onClick={() => setReview(undefined)}
356
+ >
357
+ {t("dispatch.pages.cancelActionSuggestion", {
358
+ defaultValue: "Cancel",
359
+ })}
360
+ </Button>
361
+ <Button
362
+ type="button"
363
+ disabled={pendingId !== undefined}
364
+ onClick={() => {
365
+ setReview(undefined);
366
+ void execute(review);
367
+ }}
368
+ >
369
+ {t("dispatch.pages.runActionSuggestion", {
370
+ defaultValue: "Run action",
371
+ })}
372
+ </Button>
373
+ </DialogFooter>
374
+ </DialogContent>
375
+ ) : null}
376
+ </Dialog>
377
+ {receipt ? (
378
+ <span role="status" className="text-sm text-muted-foreground">
379
+ {receiptUrl ? (
380
+ <a
381
+ className="underline"
382
+ href={receiptUrl}
383
+ target="_blank"
384
+ rel="noreferrer"
385
+ >
386
+ {receipt.outcome === "action-completed"
387
+ ? t("dispatch.pages.openExistingApp", {
388
+ defaultValue: "Open app",
389
+ })
390
+ : t("dispatch.pages.openInBuilder", {
391
+ defaultValue: "Open in Builder",
392
+ })}
393
+ </a>
394
+ ) : receipt.status === "accepted" ? (
395
+ t("dispatch.pages.actionSuggestionAccepted", {
396
+ defaultValue: "Suggestion accepted.",
397
+ })
398
+ ) : (
399
+ t("dispatch.pages.actionSuggestionContinueInCode", {
400
+ defaultValue: "Continue in Code.",
401
+ })
402
+ )}
403
+ </span>
404
+ ) : null}
405
+ {failure ? (
406
+ <span role="alert" className="text-sm text-destructive">
407
+ {failure.url ? (
408
+ <a
409
+ className="underline"
410
+ href={failure.url}
411
+ target="_blank"
412
+ rel="noreferrer"
413
+ >
414
+ {t("dispatch.pages.reviewActionSuggestionApproval", {
415
+ defaultValue: "Review approval",
416
+ })}
417
+ </a>
418
+ ) : failure.approval ? (
419
+ t("dispatch.pages.actionSuggestionApprovalRequired", {
420
+ defaultValue: "Approval is required for this action.",
421
+ })
422
+ ) : (
423
+ t("dispatch.pages.actionSuggestionUnconfirmed", {
424
+ defaultValue:
425
+ "Could not confirm the suggested action. Check the app before trying again.",
426
+ })
427
+ )}
428
+ </span>
429
+ ) : null}
430
+ </div>
431
+ );
432
+ }
@@ -269,6 +269,25 @@ describe("DispatchChatHomeApps", () => {
269
269
  expect(launcherState.value.openApp).not.toHaveBeenCalled();
270
270
  });
271
271
 
272
+ it("opens hosted apps in place with no external-link arrow on the Open button", async () => {
273
+ launcherState.value.workspaceApps = [
274
+ { id: "mail", name: "Mail", source: "builtin", url: "https://m.test" },
275
+ ] as typeof launcherState.value.workspaceApps;
276
+ appLayoutState.value = { pinnedIds: [], orderedIds: [] };
277
+
278
+ await act(async () => renderChatHome(root));
279
+
280
+ const open = container.querySelector<HTMLButtonElement>(
281
+ "button[aria-label='Open Mail']",
282
+ );
283
+ expect(open).not.toBeNull();
284
+ expect(open?.querySelector("svg")).toBeNull();
285
+ await act(async () => open?.click());
286
+ expect(launcherState.value.openApp).toHaveBeenCalledWith(
287
+ expect.objectContaining({ id: "mail" }),
288
+ );
289
+ });
290
+
272
291
  it("says the workspace has no apps under Apps when only hosted apps exist", async () => {
273
292
  launcherState.value.workspaceApps = [
274
293
  { id: "mail", name: "Mail", source: "builtin", url: "https://m.test" },
@@ -155,7 +155,6 @@ export function DispatchChatHomeApps() {
155
155
  href={href}
156
156
  onOpen={() => launcher.openApp(app)}
157
157
  showNewTabOption={Boolean(href)}
158
- external={app.source === "builtin"}
159
158
  labels={appOpenActionLabels(t, app.name)}
160
159
  />
161
160
  </article>
@@ -0,0 +1,186 @@
1
+ import { useT } from "@agent-native/core/client/i18n";
2
+ import { useLab } from "@agent-native/core/client/labs/use-lab";
3
+ import {
4
+ useActionMutation,
5
+ useActionQuery,
6
+ } from "@agent-native/core/client/use-action";
7
+ import { SettingsGroup, SettingsRow } from "@agent-native/toolkit/app/settings";
8
+ import { useState } from "react";
9
+ import { toast } from "sonner";
10
+
11
+ import { GOOGLE_BROKER_LAB } from "../shared/labs.js";
12
+ import { Button } from "./ui/button.js";
13
+ import {
14
+ Select,
15
+ SelectContent,
16
+ SelectItem,
17
+ SelectTrigger,
18
+ SelectValue,
19
+ } from "./ui/select.js";
20
+
21
+ const destinations = [
22
+ { appId: "mail", label: "Mail", provider: "gmail" },
23
+ { appId: "calendar", label: "Calendar", provider: "google_calendar" },
24
+ { appId: "brain", label: "Brain", provider: "google_drive" },
25
+ ] as const;
26
+
27
+ type Account = {
28
+ accountId: string;
29
+ displayName: string | null;
30
+ services: { providerId: string; state: string; label: string }[];
31
+ };
32
+
33
+ function GoogleBrokerGrantControl({
34
+ accounts,
35
+ appId,
36
+ onIssued,
37
+ }: {
38
+ accounts: Account[];
39
+ appId: string;
40
+ onIssued: () => void;
41
+ }) {
42
+ const t = useT();
43
+ const [accountId, setAccountId] = useState("");
44
+ const issue = useActionMutation<
45
+ { issued: boolean },
46
+ { appId: string; accountId: string }
47
+ >("issue-google-app-grant", {
48
+ onSuccess: onIssued,
49
+ onError: (error) => toast.error(error.message),
50
+ });
51
+ const chooseAccount = t(
52
+ "agentChat.settingsShell.appGroup.googleBrokerAccount",
53
+ );
54
+ return (
55
+ <div className="flex flex-wrap items-center gap-2">
56
+ <Select value={accountId} onValueChange={setAccountId}>
57
+ <SelectTrigger aria-label={chooseAccount}>
58
+ <SelectValue placeholder={chooseAccount} />
59
+ </SelectTrigger>
60
+ <SelectContent>
61
+ {accounts.map((account) => (
62
+ <SelectItem key={account.accountId} value={account.accountId}>
63
+ {account.displayName
64
+ ? `${account.displayName} · ${account.accountId}`
65
+ : account.accountId}
66
+ </SelectItem>
67
+ ))}
68
+ </SelectContent>
69
+ </Select>
70
+ <Button
71
+ variant="outline"
72
+ disabled={
73
+ issue.isPending ||
74
+ !accounts.some((account) => account.accountId === accountId)
75
+ }
76
+ onClick={() => issue.mutate({ appId, accountId })}
77
+ >
78
+ {t("agentChat.settingsShell.appGroup.googleBrokerAllow")}
79
+ </Button>
80
+ </div>
81
+ );
82
+ }
83
+
84
+ type Grant = {
85
+ id: string;
86
+ google_account_id: string;
87
+ app_id: string;
88
+ service: string;
89
+ };
90
+
91
+ export function GoogleBrokerSettingsGroup() {
92
+ const t = useT();
93
+ const enabled = useLab(GOOGLE_BROKER_LAB);
94
+ const query = useActionQuery<{ grants: Grant[]; apps: string[] }>(
95
+ "list-google-app-grants",
96
+ {},
97
+ { enabled },
98
+ );
99
+ const accounts = useActionQuery<{ accounts: Account[] }>(
100
+ "list-google-accounts",
101
+ {},
102
+ { enabled },
103
+ );
104
+ const revoke = useActionMutation<{ revoked: boolean }, { id: string }>(
105
+ "revoke-google-app-grant",
106
+ {
107
+ onSuccess: () => void query.refetch(),
108
+ onError: (error) => toast.error(error.message),
109
+ },
110
+ );
111
+ const available = destinations.flatMap(({ appId, label, provider }) => {
112
+ if (
113
+ !query.data?.apps.includes(appId) ||
114
+ query.data.grants.some((grant) => grant.app_id === appId)
115
+ )
116
+ return [];
117
+ const eligible =
118
+ accounts.data?.accounts.filter((account) =>
119
+ account.services.some(
120
+ (entry) =>
121
+ entry.providerId === provider && entry.state === "connected",
122
+ ),
123
+ ) ?? [];
124
+ const service = eligible[0]?.services.find(
125
+ (entry) => entry.providerId === provider,
126
+ );
127
+ return service
128
+ ? [{ appId, label: `${label} · ${service.label}`, accounts: eligible }]
129
+ : [];
130
+ });
131
+ const failed = query.isError || accounts.isError;
132
+ if (!enabled || (!failed && !query.data?.grants.length && !available.length))
133
+ return null;
134
+
135
+ return (
136
+ <SettingsGroup
137
+ id="google-broker"
138
+ title={t("agentChat.settingsShell.appGroup.googleBroker")}
139
+ >
140
+ {failed && (
141
+ <SettingsRow
142
+ label={t("agentChat.googleServices.loadFailed")}
143
+ control={
144
+ <Button
145
+ onClick={() =>
146
+ void Promise.all([query.refetch(), accounts.refetch()])
147
+ }
148
+ variant="outline"
149
+ >
150
+ {t("agentChat.googleServices.retry")}
151
+ </Button>
152
+ }
153
+ />
154
+ )}
155
+ {available.map((item) => (
156
+ <SettingsRow
157
+ key={item.appId}
158
+ label={item.label}
159
+ control={
160
+ <GoogleBrokerGrantControl
161
+ appId={item.appId}
162
+ accounts={item.accounts}
163
+ onIssued={() => void query.refetch()}
164
+ />
165
+ }
166
+ />
167
+ ))}
168
+ {query.data?.grants.map((grant) => (
169
+ <SettingsRow
170
+ key={grant.id}
171
+ label={`${grant.app_id} · ${grant.service}`}
172
+ description={grant.google_account_id}
173
+ control={
174
+ <Button
175
+ variant="outline"
176
+ disabled={revoke.isPending}
177
+ onClick={() => revoke.mutate({ id: grant.id })}
178
+ >
179
+ {t("agentChat.settingsShell.appGroup.googleBrokerRevoke")}
180
+ </Button>
181
+ }
182
+ />
183
+ ))}
184
+ </SettingsGroup>
185
+ );
186
+ }