@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,122 @@
1
+ import {
2
+ ACTION_SUGGESTION_KINDS,
3
+ ACTION_SUGGESTION_TRIGGERS,
4
+ parseActionSuggestion,
5
+ type ActionSuggestion,
6
+ } from "@agent-native/agentkit/protocol";
7
+ import {
8
+ getBuilderWorkspaceUrl,
9
+ getRequestOrgId,
10
+ getRequestUserEmail,
11
+ readOrgMemberRole,
12
+ } from "@agent-native/core/server";
13
+ import { z } from "zod";
14
+
15
+ import {
16
+ hasUnselectedDestructiveVariant,
17
+ isUnsupportedSuggestedAction,
18
+ NEW_APP_SUGGESTION_APP_ID,
19
+ } from "../../lib/action-suggestions.js";
20
+ import {
21
+ getAppCreationSettings,
22
+ isLocalAppCreationRuntime,
23
+ listWorkspaceApps,
24
+ } from "./app-creation-store.js";
25
+ import {
26
+ listGrantedDispatchMcpAppActions,
27
+ resolveGrantedDispatchMcpApp,
28
+ } from "./mcp-gateway.js";
29
+
30
+ const appId = z.string().trim().min(1).max(256);
31
+
32
+ export const actionSuggestionSchema = z
33
+ .object({
34
+ id: z.string().trim().min(1).max(128),
35
+ kind: z.enum(ACTION_SUGGESTION_KINDS),
36
+ trigger: z.enum(ACTION_SUGGESTION_TRIGGERS),
37
+ label: z.string().trim().min(1).max(96),
38
+ rationale: z.string().trim().min(1).max(280),
39
+ appId,
40
+ execution: z.discriminatedUnion("type", [
41
+ z.object({
42
+ type: z.literal("action"),
43
+ action: z.string().trim().min(1).max(128),
44
+ params: z.record(z.string(), z.unknown()),
45
+ }),
46
+ z.object({
47
+ type: z.literal("customize"),
48
+ targetAppId: appId,
49
+ editSpec: z.string().trim().min(1).max(4_000),
50
+ }),
51
+ z.object({
52
+ type: z.literal("create-app"),
53
+ domainSpec: z.string().trim().min(1).max(4_000),
54
+ }),
55
+ ]),
56
+ })
57
+ .superRefine((value, context) => {
58
+ try {
59
+ parseActionSuggestion(value);
60
+ } catch (error) {
61
+ context.addIssue({
62
+ code: "custom",
63
+ message: error instanceof Error ? error.message : "Invalid suggestion",
64
+ });
65
+ }
66
+ });
67
+
68
+ export async function resolveCustomizationTarget(targetAppId: string) {
69
+ const orgId = getRequestOrgId();
70
+ const userEmail = getRequestUserEmail();
71
+ if (!orgId || !userEmail) return null;
72
+ const role = await readOrgMemberRole(orgId, userEmail);
73
+ if (role !== "owner" && role !== "admin") return null;
74
+
75
+ const app = await resolveGrantedDispatchMcpApp(targetAppId);
76
+ if (app.id !== targetAppId) return null;
77
+ const apps = await listWorkspaceApps();
78
+ const mounted = apps.find(
79
+ (item) =>
80
+ (item.id === app.id || `${orgId}/${item.id}` === app.id) &&
81
+ !item.archived &&
82
+ !item.isDispatch &&
83
+ item.status !== "pending",
84
+ );
85
+ if (!mounted?.url || new URL(mounted.url).origin !== new URL(app.url).origin)
86
+ return null;
87
+ const { builderProjectId } = await getAppCreationSettings();
88
+ return builderProjectId
89
+ ? { appId: mounted.id, builderProjectId, userEmail }
90
+ : null;
91
+ }
92
+
93
+ export async function canOfferActionSuggestion(suggestion: ActionSuggestion) {
94
+ const { appId, execution } = suggestion;
95
+ switch (execution.type) {
96
+ case "action": {
97
+ if (isUnsupportedSuggestedAction(execution)) return false;
98
+ const app = await resolveGrantedDispatchMcpApp(appId);
99
+ if (app.id !== appId) return false;
100
+ const actions = await listGrantedDispatchMcpAppActions(app.id, [
101
+ execution.action,
102
+ ]);
103
+ return actions.some(
104
+ (action) =>
105
+ action.name === execution.action &&
106
+ action.readOnly !== true &&
107
+ action.destructive !== true &&
108
+ !hasUnselectedDestructiveVariant(execution, action.inputSchema),
109
+ );
110
+ }
111
+ case "customize":
112
+ return (await resolveCustomizationTarget(execution.targetAppId)) !== null;
113
+ case "create-app":
114
+ if (appId !== NEW_APP_SUGGESTION_APP_ID || !getRequestOrgId())
115
+ return false;
116
+ return Boolean(
117
+ isLocalAppCreationRuntime() ||
118
+ getBuilderWorkspaceUrl() ||
119
+ (await getAppCreationSettings()).builderBranchingEnabled,
120
+ );
121
+ }
122
+ }
@@ -17,3 +17,11 @@ export function appActionResultText(result: GrantedAppActionResult): string {
17
17
  export function appActionErrorCode(text: string): string | undefined {
18
18
  return /errorCode: ([a-z0-9_]+)/i.exec(text)?.[1];
19
19
  }
20
+
21
+ /**
22
+ * The app turned the call away at its input check, before any handler ran, so
23
+ * nothing was written and the same turn can still use its other actions.
24
+ */
25
+ export function appActionRefusedBeforeRun(text: string): boolean {
26
+ return /^(?:Error:\s*)?Invalid action parameters\b/i.test(text);
27
+ }
@@ -127,6 +127,7 @@ const mocks = vi.hoisted(() => {
127
127
  })),
128
128
  })),
129
129
  })),
130
+ resolveBuilderRequestAuthorization: vi.fn(),
130
131
  resolveBuilderCredentialsDetailed: vi.fn(async () => ({
131
132
  privateKey: null as string | null,
132
133
  publicKey: null as string | null,
@@ -233,6 +234,8 @@ vi.mock("@agent-native/core/server", async (importOriginal) => {
233
234
  return {
234
235
  ...actual,
235
236
  readOrgMemberRole: (...args: any[]) => mocks.readOrgMemberRole(...args),
237
+ resolveBuilderRequestAuthorization: (...args: unknown[]) =>
238
+ mocks.resolveBuilderRequestAuthorization(...args),
236
239
  resolveBuilderCredentialsDetailed: (...args: any[]) =>
237
240
  mocks.resolveBuilderCredentialsDetailed(...args),
238
241
  createBuilderProject: (...args: any[]) =>
@@ -320,6 +323,7 @@ afterEach(() => {
320
323
  }));
321
324
  mocks.resolveAccess.mockReset();
322
325
  mocks.resolveAccess.mockResolvedValue({ role: "viewer", resource: {} });
326
+ mocks.resolveBuilderRequestAuthorization.mockReset();
323
327
  mocks.resolveBuilderCredentialsDetailed.mockResolvedValue({
324
328
  privateKey: null,
325
329
  publicKey: null,
@@ -387,6 +391,25 @@ describe("getAppCreationSettings", () => {
387
391
  });
388
392
 
389
393
  describe("listWorkspaceApps", () => {
394
+ let isolatedCwd: string | null = null;
395
+ let isolatedCwdSpy: ReturnType<typeof vi.spyOn> | null = null;
396
+
397
+ beforeEach(() => {
398
+ isolatedCwd = fs.mkdtempSync(
399
+ path.join(os.tmpdir(), "dispatch-list-workspace-apps-"),
400
+ );
401
+ isolatedCwdSpy = vi.spyOn(process, "cwd").mockReturnValue(isolatedCwd);
402
+ });
403
+
404
+ afterEach(() => {
405
+ isolatedCwdSpy?.mockRestore();
406
+ isolatedCwdSpy = null;
407
+ if (isolatedCwd) {
408
+ fs.rmSync(isolatedCwd, { recursive: true, force: true });
409
+ isolatedCwd = null;
410
+ }
411
+ });
412
+
390
413
  function stubNoPendingContext() {
391
414
  for (const key of [
392
415
  "BRANCH",
@@ -3329,6 +3352,48 @@ describe("startWorkspaceAppCreation", () => {
3329
3352
  });
3330
3353
  });
3331
3354
 
3355
+ it("gives local and hosted builders the same mounted route and readiness gates", async () => {
3356
+ const local = await create();
3357
+ expect(local.mode).toBe("local-agent");
3358
+ if (local.mode !== "local-agent")
3359
+ throw new Error("Expected a local prompt");
3360
+ expect(local.prompt).toContain(
3361
+ "The default workspace mount is /onboarding",
3362
+ );
3363
+ expect(local.prompt).toContain("resolve the actual mount and home");
3364
+ expect(local.prompt).toContain("reuse the existing scoped connection");
3365
+ expect(local.prompt).toContain('navigate("/review")');
3366
+ expect(local.prompt).not.toContain("/apps/onboarding");
3367
+ for (const requirement of [
3368
+ "app-quality-bar/patterns/",
3369
+ "apps/onboarding/DESIGN.md",
3370
+ "apps/onboarding/app.manifest.ts",
3371
+ "screens, entities, viewPolicy, and suggestableCapabilities",
3372
+ "chosen and rejected UX options",
3373
+ "12-row rubric and automatic fails",
3374
+ "blind reviewer",
3375
+ "60-second automated Playwright",
3376
+ "empty, populated, narrow split pane at 520 px or less, and error",
3377
+ "every nav item",
3378
+ "three manifest-driven chat prompts",
3379
+ "visible Loading..., native alert/confirm/prompt, or unexpected full-page reloads",
3380
+ ]) {
3381
+ expect(local.prompt).toContain(requirement);
3382
+ }
3383
+
3384
+ stubHostedRuntime();
3385
+ stubBuilderProjectConfigured();
3386
+ mocks.runBuilderAgent.mockResolvedValueOnce({
3387
+ branchName: "onboarding",
3388
+ url: "https://builder.io/app/projects/project-1/branch/onboarding",
3389
+ status: "processing",
3390
+ });
3391
+ await expect(create()).resolves.toMatchObject({ mode: "builder" });
3392
+ expect(mocks.runBuilderAgent).toHaveBeenCalledWith(
3393
+ expect.objectContaining({ prompt: local.prompt }),
3394
+ );
3395
+ });
3396
+
3332
3397
  it("persists the curated source id for local-agent app creation", async () => {
3333
3398
  const result = await runWithRequestContext(
3334
3399
  { userEmail: "dev@example.test", orgId: "org-123" },
@@ -3554,6 +3619,56 @@ describe("startWorkspaceAppCreation", () => {
3554
3619
  expect(mocks.mutateSetting).toHaveBeenCalled();
3555
3620
  });
3556
3621
 
3622
+ it("hands ordinary app creation data-scope and sample lifecycle guidance to Builder", async () => {
3623
+ stubHostedRuntime();
3624
+ stubBuilderProjectConfigured();
3625
+ mocks.resolveBuilderCredentialsDetailed.mockResolvedValue(
3626
+ credentials({
3627
+ privateKey: "priv",
3628
+ publicKey: "pub",
3629
+ userId: "builder-user-42",
3630
+ }),
3631
+ );
3632
+ mocks.runBuilderAgent.mockResolvedValue({
3633
+ branchName: "tracker1",
3634
+ url: "https://builder.io/app/projects/project-1/tracker1",
3635
+ status: "processing",
3636
+ });
3637
+
3638
+ const result = await runWithRequestContext(
3639
+ { userEmail: "dev@example.test", orgId: "org-123" },
3640
+ () =>
3641
+ startWorkspaceAppCreation({
3642
+ prompt: "Build a personal activity tracker",
3643
+ appId: "tracker",
3644
+ }),
3645
+ );
3646
+
3647
+ expect(result.mode).toBe("builder");
3648
+ expect(mocks.runBuilderAgent).toHaveBeenCalledOnce();
3649
+ const { prompt } = mocks.runBuilderAgent.mock.calls[0][0];
3650
+ expect(prompt).toMatch(
3651
+ /authenticated caller.*access scope.*all domain reads and writes/i,
3652
+ );
3653
+ expect(prompt).toMatch(/scope private user records to their owner/i);
3654
+ expect(prompt).toMatch(
3655
+ /scope organization records to the active organization/i,
3656
+ );
3657
+ expect(prompt).toMatch(/enforce access checks for shared records/i);
3658
+ expect(prompt).toMatch(/do not make all data private/i);
3659
+ expect(prompt).toMatch(/visibly identify.*samples.*UI/i);
3660
+ expect(prompt).toMatch(/mark.*stored records as samples/i);
3661
+ expect(prompt).toMatch(/seed samples per user/i);
3662
+ expect(prompt).toMatch(/scope sample reads and clearing to that user/i);
3663
+ expect(prompt).toMatch(
3664
+ /remember dismissal.*cleared samples do not return/i,
3665
+ );
3666
+ expect(prompt).toMatch(/never silently put samples in real accounts/i);
3667
+ expect(prompt).toMatch(
3668
+ /if any of these safeguards cannot be ensured, use an empty state/i,
3669
+ );
3670
+ });
3671
+
3557
3672
  it("persists the curated source id with a hosted pending reservation", async () => {
3558
3673
  stubHostedRuntime();
3559
3674
  stubBuilderProjectConfigured();
@@ -3702,6 +3817,34 @@ describe("startWorkspaceAppCreation", () => {
3702
3817
  expect(result.message).not.toContain(leakedProjectId);
3703
3818
  });
3704
3819
 
3820
+ it("names the missing Builder membership instead of calling the failure temporary", async () => {
3821
+ stubHostedRuntime();
3822
+ stubBuilderProjectConfigured();
3823
+ mocks.resolveBuilderCredentialsDetailed.mockResolvedValue(credentials());
3824
+ mocks.runBuilderAgent.mockRejectedValue(
3825
+ new ActionContractError(
3826
+ "Builder could not find qa@example.com as a member of this Builder space.",
3827
+ {
3828
+ errorCode: "builder_space_membership_required",
3829
+ statusCode: 400,
3830
+ },
3831
+ ),
3832
+ );
3833
+
3834
+ const result = (await create("onboarding", {
3835
+ userEmail: "dev@example.test",
3836
+ orgId: "org-123",
3837
+ })) as { mode: string; reason: string; message: string };
3838
+
3839
+ expect(result.mode).toBe("builder-unavailable");
3840
+ expect(result.reason).toBe("builder-error");
3841
+ expect(result.message).toContain("member of the connected Builder space");
3842
+ expect(result.message).not.toContain("temporary");
3843
+ expect(
3844
+ mocks.settings.get("dispatch-app-creation-settings:org:org-123"),
3845
+ ).toMatchObject({ pendingApps: [] });
3846
+ });
3847
+
3705
3848
  it("classifies a disconnected Builder as builder-not-connected with a connect action", async () => {
3706
3849
  stubHostedRuntime();
3707
3850
  stubBuilderProjectConfigured();
@@ -3922,6 +4065,114 @@ describe("startWorkspaceAppCreation", () => {
3922
4065
  expect(mocks.runBuilderAgent).not.toHaveBeenCalled();
3923
4066
  });
3924
4067
 
4068
+ function stubBuilderBranchStarted() {
4069
+ mocks.runBuilderAgent.mockResolvedValueOnce({
4070
+ branchName: "onboarding",
4071
+ url: "https://builder.io/app/projects/project-1/branch/onboarding",
4072
+ status: "processing",
4073
+ });
4074
+ }
4075
+
4076
+ it.each([
4077
+ [400, "qa@example.test"],
4078
+ [422, "member@example.test"],
4079
+ ])(
4080
+ "starts the branch after an email lookup rejection (%i)",
4081
+ async (builderStatus, userEmail) => {
4082
+ stubHostedRuntime();
4083
+ stubBuilderProjectConfigured();
4084
+ mocks.state.orgRole = "member";
4085
+ mocks.resolveBuilderRequestAuthorization.mockResolvedValueOnce({
4086
+ source: "legacy",
4087
+ userId: "connected-space-user",
4088
+ });
4089
+ mocks.runBuilderAgent.mockRejectedValueOnce(
4090
+ Object.assign(new Error("User not found for the provided email"), {
4091
+ builderStatus,
4092
+ }),
4093
+ );
4094
+ stubBuilderBranchStarted();
4095
+
4096
+ const result = await create("onboarding", {
4097
+ userEmail,
4098
+ orgId: "org-123",
4099
+ });
4100
+
4101
+ expect(result).toMatchObject({ mode: "builder", appId: "onboarding" });
4102
+ expect(mocks.resolveBuilderRequestAuthorization).toHaveBeenCalledWith({
4103
+ requiredScope: "builder:agents:run",
4104
+ });
4105
+ expect(mocks.runBuilderAgent).toHaveBeenCalledTimes(2);
4106
+ expect(mocks.runBuilderAgent).toHaveBeenNthCalledWith(
4107
+ 1,
4108
+ expect.objectContaining({ projectId: leakedProjectId, userEmail }),
4109
+ );
4110
+ expect(mocks.runBuilderAgent).toHaveBeenNthCalledWith(
4111
+ 2,
4112
+ expect.objectContaining({
4113
+ projectId: leakedProjectId,
4114
+ userId: "connected-space-user",
4115
+ }),
4116
+ );
4117
+ expect(mocks.runBuilderAgent.mock.calls[1]?.[0]).not.toHaveProperty(
4118
+ "userEmail",
4119
+ );
4120
+ expect(
4121
+ mocks.settings.get("dispatch-app-creation-settings:org:org-123"),
4122
+ ).toMatchObject({
4123
+ pendingApps: [
4124
+ expect.objectContaining({ id: "onboarding", createdBy: userEmail }),
4125
+ ],
4126
+ });
4127
+ },
4128
+ );
4129
+
4130
+ it("keeps missing workspace actor actionable and releases the reservation", async () => {
4131
+ stubHostedRuntime();
4132
+ stubBuilderProjectConfigured();
4133
+ mocks.resolveBuilderRequestAuthorization.mockResolvedValueOnce({
4134
+ source: "oauth",
4135
+ });
4136
+ mocks.runBuilderAgent.mockRejectedValueOnce(
4137
+ Object.assign(new Error("User not found for the provided email"), {
4138
+ builderStatus: 400,
4139
+ }),
4140
+ );
4141
+
4142
+ await expect(create()).resolves.toMatchObject({
4143
+ mode: "builder-unavailable",
4144
+ message: expect.stringContaining(
4145
+ "check the connected account and space membership",
4146
+ ),
4147
+ });
4148
+ expect(mocks.runBuilderAgent).toHaveBeenCalledOnce();
4149
+ stubBuilderBranchStarted();
4150
+ await expect(create()).resolves.toMatchObject({ mode: "builder" });
4151
+ });
4152
+
4153
+ it("retains membership guidance when the fallback actor lookup fails", async () => {
4154
+ stubHostedRuntime();
4155
+ stubBuilderProjectConfigured();
4156
+ mocks.resolveBuilderRequestAuthorization.mockRejectedValueOnce(
4157
+ new Error("Unable to look up the workspace actor"),
4158
+ );
4159
+ mocks.runBuilderAgent.mockRejectedValueOnce(
4160
+ Object.assign(new Error("User not found for the provided email"), {
4161
+ builderStatus: 400,
4162
+ }),
4163
+ );
4164
+
4165
+ await expect(create()).resolves.toMatchObject({
4166
+ mode: "builder-unavailable",
4167
+ message: expect.stringContaining(
4168
+ "check the connected account and space membership",
4169
+ ),
4170
+ });
4171
+ expect(mocks.runBuilderAgent).toHaveBeenCalledOnce();
4172
+ stubBuilderBranchStarted();
4173
+ await expect(create()).resolves.toMatchObject({ mode: "builder" });
4174
+ });
4175
+
3925
4176
  it("logs why Builder could not start the branch", async () => {
3926
4177
  stubHostedRuntime();
3927
4178
  stubBuilderProjectConfigured();
@@ -38,6 +38,7 @@ import {
38
38
  resolveAppRuntimeUrl,
39
39
  resolveVercelDeploymentProtectionHeaders,
40
40
  normalizeBuilderAgentAttachments,
41
+ resolveBuilderRequestAuthorization,
41
42
  runBuilderAgent,
42
43
  type BuilderAgentAttachment,
43
44
  } from "@agent-native/core/server";
@@ -110,8 +111,10 @@ const AUTONOMOUS_WORKSPACE_APP_CREATION_CONTRACT = [
110
111
  "- This is a background implementation run launched by the turn-into-app workflow. Treat the source brief and latest user request as authorization to build the app now; do not return a proposal or wait for another turn.",
111
112
  "- Do not ask the user questions during the initial build and do not invoke a clarification, guided-question, or choice flow for a non-blocking decision.",
112
113
  "- If the confirmed source brief describes a spreadsheet source-review or input/output confirmation surface, implement that review UI as part of the first-run app experience and seed it with the bounded candidates and mapping; keep the background build autonomous and do not send a question back from the Builder run.",
113
- "- When the source or a tool presents a recommended option, choose it and continue. When no recommendation is present, choose the most direct, conservative default supported by the source and normal Agent-Native conventions.",
114
+ "- Use the source recommendation as evidence. Compare two or three concrete UX options and record the choice and rejected options in DESIGN.md.",
114
115
  "- Resolve product, visual, copy, layout, route, data-model, dependency, and integration choices yourself. If an input is missing, use an empty state or clearly labeled representative sample so the workflow is demonstrable; never invent private facts or credentials.",
116
+ "- Apply the authenticated caller's access scope to all domain reads and writes: scope private user records to their owner, scope organization records to the active organization, and enforce access checks for shared records. Do not make all data private; the workspace database is shared.",
117
+ "- If using synthetic samples, visibly identify them as samples in the UI and mark their stored records as samples. Seed samples per user, scope sample reads and clearing to that user, and remember dismissal so cleared samples do not return. Never silently put samples in real accounts. If any of these safeguards cannot be ensured, use an empty state instead.",
115
118
  "- Treat the source brief's unknowns and follow-up items as assumptions to record in the app README or a visible Assumptions / Review section, not as questions to send back to the user.",
116
119
  "- If a nonessential integration or provider is unavailable, build the supported boundary and leave a precise setup note; do not stop to ask which equivalent to use.",
117
120
  "- Pause only for a true hard blocker: missing authorization required to create or access the branch, a destructive or irreversible external action, an ambiguous target workspace/project, or the absence of any identifiable repeatable workflow. Otherwise make the best grounded choice and proceed.",
@@ -3354,15 +3357,15 @@ function buildWorkspaceAppPrompt(input: {
3354
3357
  `App description: ${appDescription}`,
3355
3358
  `Template to start from: ${input.template || "chat"}`,
3356
3359
  `User prompt: ${input.prompt.trim()}`,
3357
- "If the user mentions a product or company such as Granola, Loom, Superhuman, Linear, or Notion, treat it as product inspiration unless they explicitly ask to connect to that service. Do not invent or require third-party API keys like GRANOLA_API_KEY just because a product is named.",
3360
+ "Treat named products as workflow inspiration unless the user explicitly asks to connect to them. For requested integrations, inspect the workspace connection catalog and reuse the existing scoped connection and supported actions. If access is missing, show the supported connect or request-access path. Never invent a connector, ask users to paste a secret, or grant access from the build branch.",
3358
3361
  selectedKeys.length
3359
3362
  ? `Dispatch vault keys selected for this app: ${selectedKeys.join(", ")}`
3360
3363
  : "Dispatch vault keys selected for this app: none",
3361
3364
  `Dispatch workspace resources selected for this app:\n${resourceList}`,
3362
- `Dispatch workspace resources with scope=all are global. After the app exists, sync workspace resources to appId "${appId}" so global skills, guardrail instructions, and reference resources reach the new app even when no per-app resources were selected.`,
3365
+ `Dispatch workspace resources with scope=all are global. Use the workspace resource sync for registered appId "${appId}" so global skills and reference resources reach the app even when no per-app resources were selected.`,
3363
3366
  "",
3364
- `Use the workspace app layout: create it under apps/${appId}; Dispatch mounts it at /apps/${appId}. Keep it on the shared workspace database/hosting model, and avoid table-name collisions by namespacing any new domain tables to the app.`,
3365
- `Important routing rule: from outside the app, link to /apps/${appId}; inside apps/${appId}, React Router routes are app-local. Use <Link to="/review"> and navigate("/review"), not "/apps/${appId}/review"; APP_BASE_PATH supplies the mounted prefix, and hardcoding it causes doubled URLs.`,
3367
+ `Use the workspace app layout: create it under apps/${appId}; The default workspace mount is /${appId}. Keep it on the shared workspace database/hosting model, and avoid table-name collisions by namespacing any new domain tables to the app.`,
3368
+ `Important routing rule: resolve the actual mount and home from the workspace registry or preview gateway. Use that resolved URL outside the app. Inside apps/${appId}, React Router routes are app-local. Use <Link to="/review"> and navigate("/review"), not "/${appId}/review"; APP_BASE_PATH supplies the mounted prefix, and hardcoding it causes doubled URLs.`,
3366
3369
  `Home route contract: Dispatch opens the registered app.homePath. If the main screen is app/routes/_index.tsx and there is no app/routes/home.tsx or app/routes/_app.home.tsx, set app.homePath to "/" in server/plugins/config.ts. If the app uses a /home route, keep the default "/home". Never leave the registry pointing at /home when that route does not exist.`,
3367
3370
  "Existing first-party apps are neighbors, not implementation details for this app. If the user prompt mentions Mail, Calendar, Analytics, Dispatch, or other templates, treat them as existing hosted/connected apps that this app can link to or call through A2A/default connected agents. For example, Mail, Calendar, and Analytics already exist at https://mail.agent-native.com, https://calendar.agent-native.com, and https://analytics.agent-native.com.",
3368
3371
  `Do not create wrapper apps or scaffold child apps/routes for Mail, Calendar, Analytics, etc. inside apps/${appId} just so this app can access them. If the request is a cross-app dashboard or overview, build only the new dashboard/overview app and delegate to the existing apps for domain work.`,
@@ -3376,17 +3379,23 @@ function buildWorkspaceAppPrompt(input: {
3376
3379
  "",
3377
3380
  "Agent-Native rules (these are the framework's contract — not optional):",
3378
3381
  `- Persist ALL data in SQL via Drizzle. Add tables to apps/${appId}/server/db/schema.ts and migrations to apps/${appId}/server/plugins/db.ts. NEVER use localStorage, sessionStorage, IndexedDB, or in-memory state for anything the user expects to persist — agent and UI must read the same source of truth.`,
3379
- `- Define every create/read/update/delete as an action in apps/${appId}/actions/ using defineAction. The agent calls these as tools and the frontend calls them via useActionQuery / useActionMutation. If you must raw-fetch framework action endpoints, use agentNativePath("/_agent-native/actions/<name>") so mounted apps call the right URL. Don't add /api/* routes for CRUD.`,
3382
+ `- Define every create/read/update/delete as an action in apps/${appId}/actions/ using defineAction. The agent calls these as tools and the frontend calls them via useActionQuery / useActionMutation. Use the shared action client so the framework resolves the mounted endpoint. Don't add /api/* routes for CRUD.`,
3380
3383
  "- Build the UI from shadcn/ui components in app/components/ui/ (Button, Input, Dialog, Popover, Card, etc.) and Tailwind utilities. Don't author bespoke CSS classes in global.css unless you genuinely need a primitive that shadcn doesn't ship.",
3381
3384
  "- Use Tabler Icons (@tabler/icons-react) for every icon. Never use emojis as icons.",
3382
3385
  `- Expose what the user is looking at via application_state (navigation.view, selection, etc.) so the agent has live context. Mirror the patterns in templates/mail or templates/slides.`,
3383
3386
  "- Optimistic UI for every mutation: update the React Query cache immediately, navigate immediately, run the mutation in the background, roll back on error. Don't await a server round-trip before re-rendering.",
3384
3387
  `- Commit an agent-native.json at apps/${appId}/agent-native.json with { "version": 1, "onboarding": { "firstRun": { "development": "off", "production": "connect-and-integrations" } } }, as the first-party templates do, so local runs open straight into the app. Keep the shared Use Builder.io / Add your own keys onboarding for production; never build a second, custom credential form or hardcode a provider key.`,
3385
3388
  "- Every AI-labeled button must call sendToAgentChat with openSidebar: true — plus submit: true for one-click work, or submit: false when the user should review/edit the proposed prompt first. Keep follow-ups in that same sidebar thread; don't add a second freeform input beside the result. Never use sparkle, wand, magic, robot, or other decorative AI icons on those buttons — a message or neutral action icon, or no icon, instead.",
3386
- "- Choose a named visual direction in DESIGN.md before styling the first screen and build to it. Don't inherit a sibling app's palette unbuilt.",
3387
3389
  '- Left navigation must name real domain destinations, not "Chat" as the only or default entry.',
3388
3390
  "- Anything irreversible — approving, publishing, sending, deleting — must show an explicit confirmation step before it executes. Never default to auto-approve or auto-send just because the workflow could run unattended.",
3389
3391
  "",
3392
+ "Run the five stages in .agents/skills/app-quality-bar/SKILL.md:",
3393
+ "1. Choose 1–2 patterns from app-quality-bar/patterns/ that fit the user's primary task.",
3394
+ `2. Write apps/${appId}/DESIGN.md before styling. It is the required design contract. Record direction, tokens, density, type scale, keyboard map, routes, state behavior, and the chosen and rejected UX options.`,
3395
+ `3. Register apps/${appId}/app.manifest.ts with actual screens, entities, viewPolicy, and suggestableCapabilities. Implement view-screen, truthful navigate, and realtime useDbSync when other actors can change visible work.`,
3396
+ "4. Apply the 12-row rubric and automatic fails linked from .agents/skills/app-quality-bar/visual-review.md to signed-in screenshots. Give a blind reviewer only the screenshots, rubric, and brief. Keep the lower score in each row, fix findings, and recapture. Require mean 4.0 or higher, each row at least 3, and zero automatic fails.",
3397
+ "5. Run the 60-second automated Playwright walkthrough in app-quality-bar: empty, populated, narrow split pane at 520 px or less, and error with retry. Click every nav item, create and edit a fixture, reload and read it back, and exercise three manifest-driven chat prompts. Fail on visible Loading..., native alert/confirm/prompt, or unexpected full-page reloads. Keep readiness pending if verification or blind review is unavailable.",
3398
+ "",
3390
3399
  "Branch readiness requirements before handing off:",
3391
3400
  "- The CLI auto-fills package.json name and displayName from the app id; only edit the description / scripts / dependencies if the app actually needs more than the template provides.",
3392
3401
  `- Save a concise, human-readable app description in apps/${appId}/package.json "description" so Dispatch, A2A discovery, and connected agents can describe what this app does. Use the description above or improve it based on the prompt.`,
@@ -3395,8 +3404,8 @@ function buildWorkspaceAppPrompt(input: {
3395
3404
  "- Update the app manifest/package/deploy metadata needed by the existing workspace deployment model; do not leave the branch relying only on uncommitted local state.",
3396
3405
  "- Verify the app's agent card/A2A metadata is ready so Dispatch can discover and delegate to the app after deployment. Every sibling workspace app should be usable over A2A by default through call-agent.",
3397
3406
  "- Give the app agent context that sibling workspace apps are available over A2A with names and descriptions from the workspace app registry; do not hardcode a stale app list.",
3398
- "- Include a final verification note covering the registry entry, manifest/deploy metadata, relative same-origin routing, and agent-card readiness.",
3399
- `When it is ready, start or update the workspace dev server and navigate the user to /${appId}.`,
3407
+ "- Complete app-quality-bar/preview-acceptance.md. Record the actual registry entry, resolved mount and home, action bindings, and a saved edit read back in a fresh thread from a signed-in workspace member.",
3408
+ `Open the verified registered app when it is ready. Until the workspace gateway serves the app, report the branch or preview status separately from readiness.`,
3400
3409
  ].join("\n"),
3401
3410
  };
3402
3411
  }
@@ -3597,6 +3606,52 @@ export type StartWorkspaceAppCreationResult =
3597
3606
  | AppCreationComingSoonResult
3598
3607
  | AppCreationBuilderResult;
3599
3608
 
3609
+ function isBuilderEmailLookupFailure(
3610
+ error: unknown,
3611
+ ): error is Error & { builderStatus: number } {
3612
+ return (
3613
+ error instanceof Error &&
3614
+ "builderStatus" in error &&
3615
+ [400, 403, 404, 422].some((status) => status === error.builderStatus) &&
3616
+ error.message.trim().replace(/\.$/, "").toLowerCase() ===
3617
+ "user not found for the provided email"
3618
+ );
3619
+ }
3620
+
3621
+ async function startWorkspaceBuilderBranch(
3622
+ args: Parameters<typeof runBuilderAgent>[0],
3623
+ ) {
3624
+ try {
3625
+ return await runBuilderAgent(args);
3626
+ } catch (error) {
3627
+ if (!isBuilderEmailLookupFailure(error)) throw error;
3628
+ if (error.builderStatus === 403 || error.builderStatus === 404) throw error;
3629
+
3630
+ let workspaceAuthorization: Awaited<
3631
+ ReturnType<typeof resolveBuilderRequestAuthorization>
3632
+ >;
3633
+ try {
3634
+ workspaceAuthorization = await resolveBuilderRequestAuthorization({
3635
+ requiredScope: "builder:agents:run",
3636
+ });
3637
+ } catch (authorizationError) {
3638
+ if (builderFailureReason(authorizationError) !== "builder-error") {
3639
+ throw authorizationError;
3640
+ }
3641
+ throw Object.assign(
3642
+ new Error(error.message, { cause: authorizationError }),
3643
+ {
3644
+ builderStatus: error.builderStatus,
3645
+ },
3646
+ );
3647
+ }
3648
+ const userId = workspaceAuthorization?.userId;
3649
+ if (!userId) throw error;
3650
+ const { userEmail: _requesterEmail, ...run } = args;
3651
+ return runBuilderAgent({ ...run, userId });
3652
+ }
3653
+ }
3654
+
3600
3655
  export async function startWorkspaceAppCreation(input: {
3601
3656
  prompt: string;
3602
3657
  appId?: string | null;
@@ -3811,9 +3866,9 @@ export async function startWorkspaceAppCreation(input: {
3811
3866
  };
3812
3867
  try {
3813
3868
  result = normalizeBuilderRunResult(
3814
- await runBuilderAgent({
3869
+ await startWorkspaceBuilderBranch({
3815
3870
  prompt,
3816
- attachments: input.attachments,
3871
+ ...(input.attachments ? { attachments: input.attachments } : {}),
3817
3872
  projectId: builderProjectId,
3818
3873
  userEmail: currentOwnerEmail(),
3819
3874
  }),
@@ -3833,7 +3888,12 @@ export async function startWorkspaceAppCreation(input: {
3833
3888
  err,
3834
3889
  fallbackDetail: "Builder could not start the app branch",
3835
3890
  builderErrorMessage:
3836
- "Builder could not start the app branch. This is usually temporary — try again.",
3891
+ isActionContractError(err) &&
3892
+ err.errorCode === "builder_space_membership_required"
3893
+ ? "Builder could not start the app branch because your email is not a member of the connected Builder space. Ask a space admin to add you, then try again."
3894
+ : isBuilderEmailLookupFailure(err)
3895
+ ? "Builder could not match your email to an account in the connected space. Ask a workspace admin to check the connected account and space membership."
3896
+ : "Builder could not start the app branch. This is usually temporary — try again.",
3837
3897
  });
3838
3898
  }
3839
3899
 
@@ -1,4 +1,5 @@
1
1
  import { execFileSync } from "node:child_process";
2
+ import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
 
@@ -127,7 +128,7 @@ describe("curated community apps", () => {
127
128
  encoding: "utf8",
128
129
  }).trim();
129
130
  const templatePath = "templates/community/qr";
130
- const trackedFiles = execFileSync(
131
+ const gitTrackedFiles = execFileSync(
131
132
  "git",
132
133
  ["ls-files", "-z", "--", templatePath],
133
134
  { cwd: repoRoot, encoding: "utf8" },
@@ -136,6 +137,23 @@ describe("curated community apps", () => {
136
137
  .filter((file) => file.startsWith(templatePath + "/"))
137
138
  .map((file) => file.slice(templatePath.length + 1))
138
139
  .sort();
140
+ const listTemplateFiles = (dir: string, prefix = ""): string[] =>
141
+ fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
142
+ if (
143
+ entry.name === "node_modules" ||
144
+ entry.name === ".git" ||
145
+ entry.name === "dist"
146
+ ) {
147
+ return [];
148
+ }
149
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
150
+ const full = path.join(dir, entry.name);
151
+ return entry.isDirectory() ? listTemplateFiles(full, rel) : [rel];
152
+ });
153
+ const trackedFiles =
154
+ gitTrackedFiles.length > 0
155
+ ? gitTrackedFiles
156
+ : listTemplateFiles(path.join(repoRoot, templatePath)).sort();
139
157
 
140
158
  expect(source.ref).toBe("main");
141
159
  expect(source.templatePath).toBe(templatePath);
@@ -1,9 +1,14 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
2
 
3
3
  const mocks = vi.hoisted(() => ({
4
+ getDispatchConfig: vi.fn<() => Record<string, unknown>>(() => ({})),
4
5
  listWorkspaceApps: vi.fn(),
5
6
  }));
6
7
 
8
+ vi.mock("./dispatch-config.js", () => ({
9
+ hostedCatalogEnabled: () => mocks.getDispatchConfig().hostedCatalog !== false,
10
+ }));
11
+
7
12
  vi.mock("./app-creation-store.js", () => ({
8
13
  listWorkspaceApps: mocks.listWorkspaceApps,
9
14
  }));
@@ -53,4 +58,11 @@ describe("curated workspace templates", () => {
53
58
  includeArchived: true,
54
59
  });
55
60
  });
61
+
62
+ it("lists nothing when the deployment turns the hosted catalog off", async () => {
63
+ mocks.listWorkspaceApps.mockClear();
64
+ mocks.getDispatchConfig.mockReturnValueOnce({ hostedCatalog: false });
65
+ await expect(listCuratedWorkspaceTemplates()).resolves.toEqual([]);
66
+ expect(mocks.listWorkspaceApps).not.toHaveBeenCalled();
67
+ });
56
68
  });