@base44/superagent-native 0.0.2 → 0.0.3

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 (306) hide show
  1. package/lib/commonjs/AgentSettingsPanel.js +123 -47
  2. package/lib/commonjs/AgentSettingsPanel.js.map +1 -1
  3. package/lib/commonjs/AgentSphereIcon.js +14 -118
  4. package/lib/commonjs/AgentSphereIcon.js.map +1 -1
  5. package/lib/commonjs/AttachmentPickerStatusModal.js +3 -2
  6. package/lib/commonjs/AttachmentPickerStatusModal.js.map +1 -1
  7. package/lib/commonjs/ChannelsPanel.js +66 -44
  8. package/lib/commonjs/ChannelsPanel.js.map +1 -1
  9. package/lib/commonjs/ConversationChat.js +11 -2
  10. package/lib/commonjs/ConversationChat.js.map +1 -1
  11. package/lib/commonjs/ConversationComposer.js +8 -7
  12. package/lib/commonjs/ConversationComposer.js.map +1 -1
  13. package/lib/commonjs/ConversationScreen.js +2 -0
  14. package/lib/commonjs/ConversationScreen.js.map +1 -1
  15. package/lib/commonjs/EditorDrawer.js +54 -24
  16. package/lib/commonjs/EditorDrawer.js.map +1 -1
  17. package/lib/commonjs/FilesPanel.js +56 -20
  18. package/lib/commonjs/FilesPanel.js.map +1 -1
  19. package/lib/commonjs/RenameAgentModal.js +2 -1
  20. package/lib/commonjs/RenameAgentModal.js.map +1 -1
  21. package/lib/commonjs/ShareAgentModal.js +11 -10
  22. package/lib/commonjs/ShareAgentModal.js.map +1 -1
  23. package/lib/commonjs/ShareAgentModal.styles.js +2 -2
  24. package/lib/commonjs/ShareAgentModal.styles.js.map +1 -1
  25. package/lib/commonjs/SuperagentHomeScreen.js +27 -9
  26. package/lib/commonjs/SuperagentHomeScreen.js.map +1 -1
  27. package/lib/commonjs/ToolApprovalCard.js +72 -14
  28. package/lib/commonjs/ToolApprovalCard.js.map +1 -1
  29. package/lib/commonjs/ToolCallSummary.js +14 -9
  30. package/lib/commonjs/ToolCallSummary.js.map +1 -1
  31. package/lib/commonjs/agentSphereAssets.js +327 -0
  32. package/lib/commonjs/agentSphereAssets.js.map +1 -0
  33. package/lib/commonjs/agentSphereStyles.js +3 -3
  34. package/lib/commonjs/agentSphereStyles.js.map +1 -1
  35. package/lib/commonjs/apiClient.js +7 -0
  36. package/lib/commonjs/apiClient.js.map +1 -1
  37. package/lib/commonjs/composerStyles.js +2 -2
  38. package/lib/commonjs/composerStyles.js.map +1 -1
  39. package/lib/commonjs/connectorBrandIcons.generated.js +625 -0
  40. package/lib/commonjs/connectorBrandIcons.generated.js.map +1 -0
  41. package/lib/commonjs/connectorBrandIcons.js +3 -55
  42. package/lib/commonjs/connectorBrandIcons.js.map +1 -1
  43. package/lib/commonjs/connectorCatalog.js +19 -1
  44. package/lib/commonjs/connectorCatalog.js.map +1 -1
  45. package/lib/commonjs/conversationParts.js +5 -4
  46. package/lib/commonjs/conversationParts.js.map +1 -1
  47. package/lib/commonjs/conversationRuntime.js +120 -12
  48. package/lib/commonjs/conversationRuntime.js.map +1 -1
  49. package/lib/commonjs/conversationStyles.js +2 -1
  50. package/lib/commonjs/conversationStyles.js.map +1 -1
  51. package/lib/commonjs/editorShellStyles.js +6 -2
  52. package/lib/commonjs/editorShellStyles.js.map +1 -1
  53. package/lib/commonjs/index.js +7 -0
  54. package/lib/commonjs/index.js.map +1 -1
  55. package/lib/commonjs/markdownStyles.js +2 -2
  56. package/lib/commonjs/markdownStyles.js.map +1 -1
  57. package/lib/commonjs/messageActionStyles.js +2 -2
  58. package/lib/commonjs/messageActionStyles.js.map +1 -1
  59. package/lib/commonjs/realtimeClient.js +4 -1
  60. package/lib/commonjs/realtimeClient.js.map +1 -1
  61. package/lib/commonjs/renameAgentModalStyles.js +2 -2
  62. package/lib/commonjs/renameAgentModalStyles.js.map +1 -1
  63. package/lib/commonjs/screenParts.js +24 -41
  64. package/lib/commonjs/screenParts.js.map +1 -1
  65. package/lib/commonjs/styles.js +71 -60
  66. package/lib/commonjs/styles.js.map +1 -1
  67. package/lib/commonjs/superagentApiClient.js +63 -18
  68. package/lib/commonjs/superagentApiClient.js.map +1 -1
  69. package/lib/commonjs/theme.js +249 -0
  70. package/lib/commonjs/theme.js.map +1 -0
  71. package/lib/commonjs/useSuperagentConversation.js +133 -20
  72. package/lib/commonjs/useSuperagentConversation.js.map +1 -1
  73. package/lib/commonjs/useSuperagentRuntime.js +167 -82
  74. package/lib/commonjs/useSuperagentRuntime.js.map +1 -1
  75. package/lib/module/AgentSettingsPanel.js +125 -49
  76. package/lib/module/AgentSettingsPanel.js.map +1 -1
  77. package/lib/module/AgentSphereIcon.js +15 -118
  78. package/lib/module/AgentSphereIcon.js.map +1 -1
  79. package/lib/module/AttachmentPickerStatusModal.js +4 -3
  80. package/lib/module/AttachmentPickerStatusModal.js.map +1 -1
  81. package/lib/module/ChannelsPanel.js +67 -45
  82. package/lib/module/ChannelsPanel.js.map +1 -1
  83. package/lib/module/ConversationChat.js +11 -2
  84. package/lib/module/ConversationChat.js.map +1 -1
  85. package/lib/module/ConversationComposer.js +8 -7
  86. package/lib/module/ConversationComposer.js.map +1 -1
  87. package/lib/module/ConversationScreen.js +2 -0
  88. package/lib/module/ConversationScreen.js.map +1 -1
  89. package/lib/module/EditorDrawer.js +55 -25
  90. package/lib/module/EditorDrawer.js.map +1 -1
  91. package/lib/module/FilesPanel.js +56 -20
  92. package/lib/module/FilesPanel.js.map +1 -1
  93. package/lib/module/RenameAgentModal.js +2 -1
  94. package/lib/module/RenameAgentModal.js.map +1 -1
  95. package/lib/module/ShareAgentModal.js +11 -10
  96. package/lib/module/ShareAgentModal.js.map +1 -1
  97. package/lib/module/ShareAgentModal.styles.js +2 -2
  98. package/lib/module/ShareAgentModal.styles.js.map +1 -1
  99. package/lib/module/SuperagentHomeScreen.js +27 -9
  100. package/lib/module/SuperagentHomeScreen.js.map +1 -1
  101. package/lib/module/ToolApprovalCard.js +72 -14
  102. package/lib/module/ToolApprovalCard.js.map +1 -1
  103. package/lib/module/ToolCallSummary.js +14 -9
  104. package/lib/module/ToolCallSummary.js.map +1 -1
  105. package/lib/module/agentSphereAssets.js +323 -0
  106. package/lib/module/agentSphereAssets.js.map +1 -0
  107. package/lib/module/agentSphereStyles.js +3 -3
  108. package/lib/module/agentSphereStyles.js.map +1 -1
  109. package/lib/module/apiClient.js +7 -0
  110. package/lib/module/apiClient.js.map +1 -1
  111. package/lib/module/composerStyles.js +2 -2
  112. package/lib/module/composerStyles.js.map +1 -1
  113. package/lib/module/connectorBrandIcons.generated.js +621 -0
  114. package/lib/module/connectorBrandIcons.generated.js.map +1 -0
  115. package/lib/module/connectorBrandIcons.js +1 -53
  116. package/lib/module/connectorBrandIcons.js.map +1 -1
  117. package/lib/module/connectorCatalog.js +17 -0
  118. package/lib/module/connectorCatalog.js.map +1 -1
  119. package/lib/module/conversationParts.js +5 -4
  120. package/lib/module/conversationParts.js.map +1 -1
  121. package/lib/module/conversationRuntime.js +118 -12
  122. package/lib/module/conversationRuntime.js.map +1 -1
  123. package/lib/module/conversationStyles.js +3 -2
  124. package/lib/module/conversationStyles.js.map +1 -1
  125. package/lib/module/editorShellStyles.js +6 -2
  126. package/lib/module/editorShellStyles.js.map +1 -1
  127. package/lib/module/index.js +1 -0
  128. package/lib/module/index.js.map +1 -1
  129. package/lib/module/markdownStyles.js +2 -2
  130. package/lib/module/markdownStyles.js.map +1 -1
  131. package/lib/module/messageActionStyles.js +2 -2
  132. package/lib/module/messageActionStyles.js.map +1 -1
  133. package/lib/module/realtimeClient.js +4 -1
  134. package/lib/module/realtimeClient.js.map +1 -1
  135. package/lib/module/renameAgentModalStyles.js +2 -2
  136. package/lib/module/renameAgentModalStyles.js.map +1 -1
  137. package/lib/module/screenParts.js +25 -42
  138. package/lib/module/screenParts.js.map +1 -1
  139. package/lib/module/styles.js +71 -60
  140. package/lib/module/styles.js.map +1 -1
  141. package/lib/module/superagentApiClient.js +63 -18
  142. package/lib/module/superagentApiClient.js.map +1 -1
  143. package/lib/module/theme.js +239 -0
  144. package/lib/module/theme.js.map +1 -0
  145. package/lib/module/useSuperagentConversation.js +135 -22
  146. package/lib/module/useSuperagentConversation.js.map +1 -1
  147. package/lib/module/useSuperagentRuntime.js +167 -82
  148. package/lib/module/useSuperagentRuntime.js.map +1 -1
  149. package/lib/typescript/commonjs/AgentSettingsPanel.d.ts.map +1 -1
  150. package/lib/typescript/commonjs/AgentSphereIcon.d.ts.map +1 -1
  151. package/lib/typescript/commonjs/AttachmentPickerStatusModal.d.ts.map +1 -1
  152. package/lib/typescript/commonjs/ChannelsPanel.d.ts.map +1 -1
  153. package/lib/typescript/commonjs/ConversationChat.d.ts +1 -1
  154. package/lib/typescript/commonjs/ConversationChat.d.ts.map +1 -1
  155. package/lib/typescript/commonjs/ConversationComposer.d.ts.map +1 -1
  156. package/lib/typescript/commonjs/ConversationMessageList.d.ts +1 -1
  157. package/lib/typescript/commonjs/ConversationMessageList.d.ts.map +1 -1
  158. package/lib/typescript/commonjs/ConversationScreen.d.ts +2 -1
  159. package/lib/typescript/commonjs/ConversationScreen.d.ts.map +1 -1
  160. package/lib/typescript/commonjs/EditorDrawer.d.ts +1 -1
  161. package/lib/typescript/commonjs/EditorDrawer.d.ts.map +1 -1
  162. package/lib/typescript/commonjs/FilesPanel.d.ts.map +1 -1
  163. package/lib/typescript/commonjs/RenameAgentModal.d.ts.map +1 -1
  164. package/lib/typescript/commonjs/ShareAgentModal.d.ts.map +1 -1
  165. package/lib/typescript/commonjs/ShareAgentModal.styles.d.ts.map +1 -1
  166. package/lib/typescript/commonjs/SuperagentHomeScreen.d.ts.map +1 -1
  167. package/lib/typescript/commonjs/ToolApprovalCard.d.ts +3 -3
  168. package/lib/typescript/commonjs/ToolApprovalCard.d.ts.map +1 -1
  169. package/lib/typescript/commonjs/ToolCallSummary.d.ts +1 -1
  170. package/lib/typescript/commonjs/ToolCallSummary.d.ts.map +1 -1
  171. package/lib/typescript/commonjs/agentSphereAssets.d.ts +2 -0
  172. package/lib/typescript/commonjs/agentSphereAssets.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/agentSphereStyles.d.ts.map +1 -1
  174. package/lib/typescript/commonjs/apiClient.d.ts.map +1 -1
  175. package/lib/typescript/commonjs/composerStyles.d.ts.map +1 -1
  176. package/lib/typescript/commonjs/connectorBrandIcons.d.ts.map +1 -1
  177. package/lib/typescript/commonjs/connectorBrandIcons.generated.d.ts +2 -0
  178. package/lib/typescript/commonjs/connectorBrandIcons.generated.d.ts.map +1 -0
  179. package/lib/typescript/commonjs/connectorCatalog.d.ts +2 -0
  180. package/lib/typescript/commonjs/connectorCatalog.d.ts.map +1 -1
  181. package/lib/typescript/commonjs/conversationParts.d.ts +1 -1
  182. package/lib/typescript/commonjs/conversationParts.d.ts.map +1 -1
  183. package/lib/typescript/commonjs/conversationRuntime.d.ts +6 -1
  184. package/lib/typescript/commonjs/conversationRuntime.d.ts.map +1 -1
  185. package/lib/typescript/commonjs/conversationStyles.d.ts.map +1 -1
  186. package/lib/typescript/commonjs/editorShellStyles.d.ts +4 -0
  187. package/lib/typescript/commonjs/editorShellStyles.d.ts.map +1 -1
  188. package/lib/typescript/commonjs/index.d.ts +2 -0
  189. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  190. package/lib/typescript/commonjs/markdownStyles.d.ts.map +1 -1
  191. package/lib/typescript/commonjs/messageActionStyles.d.ts.map +1 -1
  192. package/lib/typescript/commonjs/realtimeClient.d.ts.map +1 -1
  193. package/lib/typescript/commonjs/renameAgentModalStyles.d.ts.map +1 -1
  194. package/lib/typescript/commonjs/screenParts.d.ts +1 -1
  195. package/lib/typescript/commonjs/screenParts.d.ts.map +1 -1
  196. package/lib/typescript/commonjs/styles.d.ts +20 -11
  197. package/lib/typescript/commonjs/styles.d.ts.map +1 -1
  198. package/lib/typescript/commonjs/superagentApiClient.d.ts +2 -1
  199. package/lib/typescript/commonjs/superagentApiClient.d.ts.map +1 -1
  200. package/lib/typescript/commonjs/theme.d.ts +36 -0
  201. package/lib/typescript/commonjs/theme.d.ts.map +1 -0
  202. package/lib/typescript/commonjs/types.d.ts +16 -2
  203. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  204. package/lib/typescript/commonjs/useSuperagentConversation.d.ts +3 -2
  205. package/lib/typescript/commonjs/useSuperagentConversation.d.ts.map +1 -1
  206. package/lib/typescript/commonjs/useSuperagentRuntime.d.ts +2 -1
  207. package/lib/typescript/commonjs/useSuperagentRuntime.d.ts.map +1 -1
  208. package/lib/typescript/module/AgentSettingsPanel.d.ts.map +1 -1
  209. package/lib/typescript/module/AgentSphereIcon.d.ts.map +1 -1
  210. package/lib/typescript/module/AttachmentPickerStatusModal.d.ts.map +1 -1
  211. package/lib/typescript/module/ChannelsPanel.d.ts.map +1 -1
  212. package/lib/typescript/module/ConversationChat.d.ts +1 -1
  213. package/lib/typescript/module/ConversationChat.d.ts.map +1 -1
  214. package/lib/typescript/module/ConversationComposer.d.ts.map +1 -1
  215. package/lib/typescript/module/ConversationMessageList.d.ts +1 -1
  216. package/lib/typescript/module/ConversationMessageList.d.ts.map +1 -1
  217. package/lib/typescript/module/ConversationScreen.d.ts +2 -1
  218. package/lib/typescript/module/ConversationScreen.d.ts.map +1 -1
  219. package/lib/typescript/module/EditorDrawer.d.ts +1 -1
  220. package/lib/typescript/module/EditorDrawer.d.ts.map +1 -1
  221. package/lib/typescript/module/FilesPanel.d.ts.map +1 -1
  222. package/lib/typescript/module/RenameAgentModal.d.ts.map +1 -1
  223. package/lib/typescript/module/ShareAgentModal.d.ts.map +1 -1
  224. package/lib/typescript/module/ShareAgentModal.styles.d.ts.map +1 -1
  225. package/lib/typescript/module/SuperagentHomeScreen.d.ts.map +1 -1
  226. package/lib/typescript/module/ToolApprovalCard.d.ts +3 -3
  227. package/lib/typescript/module/ToolApprovalCard.d.ts.map +1 -1
  228. package/lib/typescript/module/ToolCallSummary.d.ts +1 -1
  229. package/lib/typescript/module/ToolCallSummary.d.ts.map +1 -1
  230. package/lib/typescript/module/agentSphereAssets.d.ts +2 -0
  231. package/lib/typescript/module/agentSphereAssets.d.ts.map +1 -0
  232. package/lib/typescript/module/agentSphereStyles.d.ts.map +1 -1
  233. package/lib/typescript/module/apiClient.d.ts.map +1 -1
  234. package/lib/typescript/module/composerStyles.d.ts.map +1 -1
  235. package/lib/typescript/module/connectorBrandIcons.d.ts.map +1 -1
  236. package/lib/typescript/module/connectorBrandIcons.generated.d.ts +2 -0
  237. package/lib/typescript/module/connectorBrandIcons.generated.d.ts.map +1 -0
  238. package/lib/typescript/module/connectorCatalog.d.ts +2 -0
  239. package/lib/typescript/module/connectorCatalog.d.ts.map +1 -1
  240. package/lib/typescript/module/conversationParts.d.ts +1 -1
  241. package/lib/typescript/module/conversationParts.d.ts.map +1 -1
  242. package/lib/typescript/module/conversationRuntime.d.ts +6 -1
  243. package/lib/typescript/module/conversationRuntime.d.ts.map +1 -1
  244. package/lib/typescript/module/conversationStyles.d.ts.map +1 -1
  245. package/lib/typescript/module/editorShellStyles.d.ts +4 -0
  246. package/lib/typescript/module/editorShellStyles.d.ts.map +1 -1
  247. package/lib/typescript/module/index.d.ts +2 -0
  248. package/lib/typescript/module/index.d.ts.map +1 -1
  249. package/lib/typescript/module/markdownStyles.d.ts.map +1 -1
  250. package/lib/typescript/module/messageActionStyles.d.ts.map +1 -1
  251. package/lib/typescript/module/realtimeClient.d.ts.map +1 -1
  252. package/lib/typescript/module/renameAgentModalStyles.d.ts.map +1 -1
  253. package/lib/typescript/module/screenParts.d.ts +1 -1
  254. package/lib/typescript/module/screenParts.d.ts.map +1 -1
  255. package/lib/typescript/module/styles.d.ts +20 -11
  256. package/lib/typescript/module/styles.d.ts.map +1 -1
  257. package/lib/typescript/module/superagentApiClient.d.ts +2 -1
  258. package/lib/typescript/module/superagentApiClient.d.ts.map +1 -1
  259. package/lib/typescript/module/theme.d.ts +36 -0
  260. package/lib/typescript/module/theme.d.ts.map +1 -0
  261. package/lib/typescript/module/types.d.ts +16 -2
  262. package/lib/typescript/module/types.d.ts.map +1 -1
  263. package/lib/typescript/module/useSuperagentConversation.d.ts +3 -2
  264. package/lib/typescript/module/useSuperagentConversation.d.ts.map +1 -1
  265. package/lib/typescript/module/useSuperagentRuntime.d.ts +2 -1
  266. package/lib/typescript/module/useSuperagentRuntime.d.ts.map +1 -1
  267. package/package.json +1 -1
  268. package/src/AgentSettingsPanel.tsx +118 -49
  269. package/src/AgentSphereIcon.tsx +11 -62
  270. package/src/AttachmentPickerStatusModal.tsx +4 -3
  271. package/src/ChannelsPanel.tsx +59 -39
  272. package/src/ConversationChat.tsx +12 -3
  273. package/src/ConversationComposer.tsx +7 -6
  274. package/src/ConversationMessageList.tsx +1 -1
  275. package/src/ConversationScreen.tsx +3 -0
  276. package/src/EditorDrawer.tsx +66 -41
  277. package/src/FilesPanel.tsx +48 -20
  278. package/src/RenameAgentModal.tsx +2 -1
  279. package/src/ShareAgentModal.styles.ts +2 -1
  280. package/src/ShareAgentModal.tsx +9 -8
  281. package/src/SuperagentHomeScreen.tsx +27 -7
  282. package/src/ToolApprovalCard.tsx +82 -14
  283. package/src/ToolCallSummary.tsx +18 -12
  284. package/src/agentSphereAssets.ts +325 -0
  285. package/src/agentSphereStyles.ts +3 -2
  286. package/src/apiClient.ts +7 -0
  287. package/src/composerStyles.ts +2 -1
  288. package/src/connectorBrandIcons.generated.ts +618 -0
  289. package/src/connectorBrandIcons.tsx +1 -53
  290. package/src/connectorCatalog.ts +24 -0
  291. package/src/conversationParts.tsx +6 -5
  292. package/src/conversationRuntime.ts +123 -12
  293. package/src/conversationStyles.ts +2 -1
  294. package/src/editorShellStyles.ts +6 -1
  295. package/src/index.ts +2 -0
  296. package/src/markdownStyles.ts +2 -1
  297. package/src/messageActionStyles.ts +2 -1
  298. package/src/realtimeClient.ts +7 -1
  299. package/src/renameAgentModalStyles.ts +2 -1
  300. package/src/screenParts.tsx +17 -29
  301. package/src/styles.ts +63 -54
  302. package/src/superagentApiClient.ts +68 -18
  303. package/src/theme.ts +254 -0
  304. package/src/types.ts +21 -2
  305. package/src/useSuperagentConversation.ts +141 -24
  306. package/src/useSuperagentRuntime.ts +165 -84
@@ -174,6 +174,11 @@ export function useSuperagentRuntime({
174
174
  const [isLoading, setIsLoading] = useState(true);
175
175
  const [loadError, setLoadError] = useState<string | null>(null);
176
176
  const [runtimeAuthToken, setRuntimeAuthToken] = useState<string | null>(null);
177
+ // Caches the resolved runtime token keyed by the agent it belongs to. The
178
+ // runtimeAuthToken state lags an agent switch (it's cleared in a later effect),
179
+ // so resolveRuntimeToken must not trust it as a cache — this ref can never hand
180
+ // back a different agent's token.
181
+ const runtimeTokenRef = useRef<{ agentId: string; token: string } | null>(null);
177
182
  const [realtimeClient, setRealtimeClient] = useState<SuperagentRealtimeClient | undefined>();
178
183
  const [secrets, setSecrets] = useState<SuperagentSecret[]>([]);
179
184
  const connectorFlowRef = useRef<ConnectorFlow | null>(null);
@@ -299,16 +304,25 @@ export function useSuperagentRuntime({
299
304
  }, [superagentService]);
300
305
 
301
306
  const resolveRuntimeToken = useCallback(async (agentId: string) => {
302
- if (agentId === activeAgentId && runtimeAuthToken) {
303
- return runtimeAuthToken;
307
+ // Use the agent-keyed ref, not the runtimeAuthToken state: the state still
308
+ // holds the previous agent's token during a switch (it's cleared in a later
309
+ // effect), so trusting it could return the wrong agent's token here.
310
+ const cached = runtimeTokenRef.current;
311
+ if (cached && cached.agentId === agentId) {
312
+ return cached.token;
304
313
  }
305
314
 
306
315
  const token = await superagentService.getRuntimeAuthToken(agentId);
307
- if (agentId === activeAgentId) {
316
+ runtimeTokenRef.current = { agentId, token };
317
+ // Compare against the latest active agent (ref), not the closure-captured
318
+ // activeAgentId: the user may have switched agents while the fetch was in
319
+ // flight, and writing a stale agent's token into shared state would point
320
+ // realtime/channel calls at the wrong agent.
321
+ if (agentId === activeAgentIdRef.current) {
308
322
  setRuntimeAuthToken(token);
309
323
  }
310
324
  return token;
311
- }, [activeAgentId, runtimeAuthToken, superagentService]);
325
+ }, [superagentService]);
312
326
 
313
327
  const loadChannels = useCallback(async (agentId: string) => {
314
328
  setIsLoadingChannels(true);
@@ -353,6 +367,7 @@ export function useSuperagentRuntime({
353
367
  setChannelStatus({});
354
368
  setCollaborators([]);
355
369
  setConnectingChannelId(null);
370
+ setConnectingConnectorId(null);
356
371
  setConnectedConnectors([]);
357
372
  setFilePaths([]);
358
373
  setFileLoadError(null);
@@ -406,25 +421,16 @@ export function useSuperagentRuntime({
406
421
  return;
407
422
  }
408
423
 
409
- if (event.status === 'success') {
410
- flow.cancelled = true;
411
- connectorFlowRef.current = null;
412
- setConnectingConnectorId(null);
413
- await loadConnectors(flow.agentId);
414
- return;
415
- }
416
-
417
- if (event.status === 'error') {
418
- flow.cancelled = true;
419
- connectorFlowRef.current = null;
420
- setConnectingConnectorId(null);
424
+ // The callback event carries no connection/connector identifier, so it can't
425
+ // be reliably attributed to this flow a late callback from a superseded
426
+ // connect could otherwise mark the wrong flow. Don't mutate flow state here;
427
+ // waitForConnectorAuthorization polls the authoritative per-connection status
428
+ // (it detects ACTIVE/FAILED on its own). Just refresh the connector list so
429
+ // the UI reflects the latest state.
430
+ if (event.status === 'success' || event.status === 'error') {
421
431
  await loadConnectors(flow.agentId);
422
- showAlert(nativeAdapters, 'Connector failed', 'OAuth authorization did not complete. Please try connecting again.');
423
- return;
424
432
  }
425
-
426
- await loadConnectors(flow.agentId);
427
- }, [loadConnectors, nativeAdapters]);
433
+ }, [loadConnectors]);
428
434
 
429
435
  useEffect(() => {
430
436
  return nativeAdapters.subscribeToExternalAuthCallbacks?.(completePendingConnectorFromCallback);
@@ -562,6 +568,9 @@ export function useSuperagentRuntime({
562
568
  )));
563
569
  } catch (error) {
564
570
  showAlert(nativeAdapters, 'Permissions update failed', getErrorMessage(error));
571
+ // Rethrow so optimistic callers (the permission toggle) can revert; the
572
+ // guard-config caller wraps this in try/catch since the alert already fired.
573
+ throw error;
565
574
  }
566
575
  }, [nativeAdapters, superagentService]);
567
576
 
@@ -634,7 +643,10 @@ export function useSuperagentRuntime({
634
643
  }, [config.baseUrl, config.webUrl, nativeAdapters]);
635
644
 
636
645
  const onCloneAgent = useCallback(({agentId}: SuperagentAgentActionInput) => {
637
- nativeAdapters.openWebUrl?.(buildWebUrl(config.webUrl ?? config.baseUrl, `/remix-app/${encodeURIComponent(agentId)}?clone_history=true`));
646
+ // Use the Superagent clone route — /remix-app is an app route that the web
647
+ // builder redirects back to /superagent/:id for user_agent apps (reopening the
648
+ // original instead of cloning). /clone-superagent/:id is the agent clone flow.
649
+ nativeAdapters.openWebUrl?.(buildWebUrl(config.webUrl ?? config.baseUrl, `/clone-superagent/${encodeURIComponent(agentId)}`));
638
650
  }, [config.baseUrl, config.webUrl, nativeAdapters]);
639
651
 
640
652
  const onDeleteAgent = useCallback(async ({agentId}: SuperagentAgentActionInput) => {
@@ -756,7 +768,10 @@ export function useSuperagentRuntime({
756
768
 
757
769
  const writtenPaths: string[] = [];
758
770
  for (const file of files) {
759
- const safePath = sanitizeSandboxFilePath(file.name) || 'upload';
771
+ const safeName = sanitizeSandboxFilePath(file.name) || 'upload';
772
+ // Stage uploads under a dedicated folder so a picked file named like a
773
+ // generated-app file (package.json, README.md, ...) can't overwrite it.
774
+ const safePath = `incoming_files/${safeName}`;
760
775
  await superagentService.writeSandboxFile(agentId, safePath, file.content);
761
776
  writtenPaths.push(safePath);
762
777
  }
@@ -792,19 +807,31 @@ export function useSuperagentRuntime({
792
807
  setConnectingChannelId('whatsapp');
793
808
  try {
794
809
  const token = await resolveRuntimeToken(agentId);
810
+ // Editor gate: the connect redirect only authenticates the app-user token and
811
+ // does not re-check live editor access, so a downgraded viewer could otherwise
812
+ // open it. /whatsapp/status enforces the two-layer editor check and throws
813
+ // (403) for viewers — require it to pass before opening the setup page.
814
+ await superagentService.getWhatsAppStatus(agentId, token);
795
815
  const connectUrl = superagentService.getWhatsAppConnectUrl(agentId, token);
796
- setChannelStatus((current) => ({
797
- ...current,
798
- whatsapp: {
799
- ...current.whatsapp,
800
- connectUrl,
801
- },
802
- }));
803
- await nativeAdapters.openUrl?.(connectUrl);
816
+ if (activeAgentIdRef.current === agentId) {
817
+ setChannelStatus((current) => ({
818
+ ...current,
819
+ whatsapp: {
820
+ ...current.whatsapp,
821
+ connectUrl,
822
+ },
823
+ }));
824
+ }
825
+ if (!nativeAdapters.openUrl) {
826
+ // Without a URL opener the setup page never launches; surface an error
827
+ // instead of completing silently (mirrors the connector OAuth flow).
828
+ throw new Error('This app cannot open the WhatsApp setup page. Connect WhatsApp from the web app.');
829
+ }
830
+ await nativeAdapters.openUrl(connectUrl);
804
831
  } catch (error) {
805
832
  showAlert(nativeAdapters, 'WhatsApp setup failed', getErrorMessage(error));
806
833
  } finally {
807
- setConnectingChannelId(null);
834
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
808
835
  }
809
836
  }, [nativeAdapters, resolveRuntimeToken, superagentService]);
810
837
 
@@ -813,12 +840,14 @@ export function useSuperagentRuntime({
813
840
  try {
814
841
  const runtimeToken = await resolveRuntimeToken(agentId);
815
842
  const telegram = await superagentService.setupTelegram(agentId, runtimeToken, token);
816
- setChannelStatus((current) => ({
817
- ...current,
818
- telegram,
819
- }));
843
+ if (activeAgentIdRef.current === agentId) {
844
+ setChannelStatus((current) => ({
845
+ ...current,
846
+ telegram,
847
+ }));
848
+ }
820
849
  } finally {
821
- setConnectingChannelId(null);
850
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
822
851
  }
823
852
  }, [resolveRuntimeToken, superagentService]);
824
853
 
@@ -837,14 +866,16 @@ export function useSuperagentRuntime({
837
866
  try {
838
867
  const token = await resolveRuntimeToken(agentId);
839
868
  await superagentService.disconnectTelegram(agentId, token);
840
- setChannelStatus((current) => ({
841
- ...current,
842
- telegram: {connected: false},
843
- }));
869
+ if (activeAgentIdRef.current === agentId) {
870
+ setChannelStatus((current) => ({
871
+ ...current,
872
+ telegram: {connected: false},
873
+ }));
874
+ }
844
875
  } catch (error) {
845
876
  showAlert(nativeAdapters, 'Telegram disconnect failed', getErrorMessage(error));
846
877
  } finally {
847
- setConnectingChannelId(null);
878
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
848
879
  }
849
880
  }, [nativeAdapters, resolveRuntimeToken, superagentService]);
850
881
 
@@ -853,18 +884,20 @@ export function useSuperagentRuntime({
853
884
  try {
854
885
  const token = await resolveRuntimeToken(agentId);
855
886
  const activation = await superagentService.generateLineCode(agentId, token);
856
- setChannelStatus((current) => ({
857
- ...current,
858
- line: {
859
- ...current.line,
860
- activation,
861
- connected: false,
862
- },
863
- }));
887
+ if (activeAgentIdRef.current === agentId) {
888
+ setChannelStatus((current) => ({
889
+ ...current,
890
+ line: {
891
+ ...current.line,
892
+ activation,
893
+ connected: false,
894
+ },
895
+ }));
896
+ }
864
897
  } catch (error) {
865
898
  showAlert(nativeAdapters, 'LINE setup failed', getErrorMessage(error));
866
899
  } finally {
867
- setConnectingChannelId(null);
900
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
868
901
  }
869
902
  }, [nativeAdapters, resolveRuntimeToken, superagentService]);
870
903
 
@@ -873,20 +906,22 @@ export function useSuperagentRuntime({
873
906
  try {
874
907
  const token = await resolveRuntimeToken(agentId);
875
908
  const activation = await superagentService.generateIMessageCode(agentId, token);
876
- setChannelStatus((current) => ({
877
- ...current,
878
- imessage: {
879
- ...current.imessage,
880
- activation,
881
- connected: current.imessage?.connected ?? false,
882
- },
883
- }));
909
+ if (activeAgentIdRef.current === agentId) {
910
+ setChannelStatus((current) => ({
911
+ ...current,
912
+ imessage: {
913
+ ...current.imessage,
914
+ activation,
915
+ connected: current.imessage?.connected ?? false,
916
+ },
917
+ }));
918
+ }
884
919
  return activation;
885
920
  } catch (error) {
886
921
  showAlert(nativeAdapters, 'iMessage setup failed', getErrorMessage(error));
887
922
  throw error;
888
923
  } finally {
889
- setConnectingChannelId(null);
924
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
890
925
  }
891
926
  }, [nativeAdapters, resolveRuntimeToken, superagentService]);
892
927
 
@@ -905,20 +940,25 @@ export function useSuperagentRuntime({
905
940
  try {
906
941
  const token = await resolveRuntimeToken(agentId);
907
942
  const imessage = await superagentService.disconnectIMessage(agentId, token);
908
- setChannelStatus((current) => ({
909
- ...current,
910
- imessage,
911
- }));
943
+ if (activeAgentIdRef.current === agentId) {
944
+ setChannelStatus((current) => ({
945
+ ...current,
946
+ imessage,
947
+ }));
948
+ }
912
949
  } catch (error) {
913
950
  showAlert(nativeAdapters, 'iMessage disconnect failed', getErrorMessage(error));
914
951
  } finally {
915
- setConnectingChannelId(null);
952
+ if (activeAgentIdRef.current === agentId) setConnectingChannelId(null);
916
953
  }
917
954
  }, [nativeAdapters, resolveRuntimeToken, superagentService]);
918
955
 
919
956
  const onOpenIMessage = useCallback(async ({code, phoneNumber}: SuperagentIMessageCodeShareInput) => {
920
957
  try {
921
- await nativeAdapters.openUrl?.(buildIMessageUrl(phoneNumber, code));
958
+ if (!nativeAdapters.openUrl) {
959
+ throw new Error('This app cannot open Messages. Use the web app to share the iMessage code.');
960
+ }
961
+ await nativeAdapters.openUrl(buildIMessageUrl(phoneNumber, code));
922
962
  } catch (error) {
923
963
  showAlert(nativeAdapters, 'iMessage link unavailable', getErrorMessage(error));
924
964
  }
@@ -933,7 +973,11 @@ export function useSuperagentRuntime({
933
973
  }, [nativeAdapters]);
934
974
 
935
975
  const onShareLineCode = useCallback(async ({addFriendUrl, code}: SuperagentLineCodeShareInput) => {
936
- await nativeAdapters.share?.({
976
+ if (!nativeAdapters.share) {
977
+ showAlert(nativeAdapters, 'Sharing unavailable', 'This app cannot share the activation code. Copy it manually instead.');
978
+ return;
979
+ }
980
+ await nativeAdapters.share({
937
981
  message: `LINE activation code: ${code}\n${addFriendUrl}`,
938
982
  title: 'LINE activation code',
939
983
  url: addFriendUrl,
@@ -941,7 +985,11 @@ export function useSuperagentRuntime({
941
985
  }, [nativeAdapters]);
942
986
 
943
987
  const onShareIMessageCode = useCallback(async ({code, phoneNumber}: SuperagentIMessageCodeShareInput) => {
944
- await nativeAdapters.share?.({
988
+ if (!nativeAdapters.share) {
989
+ showAlert(nativeAdapters, 'Sharing unavailable', 'This app cannot share the activation code. Copy it manually instead.');
990
+ return;
991
+ }
992
+ await nativeAdapters.share({
945
993
  message: `Text ${code} to ${phoneNumber} to connect this Superagent on iMessage.`,
946
994
  title: 'iMessage activation code',
947
995
  url: buildIMessageUrl(phoneNumber, code),
@@ -976,26 +1024,38 @@ export function useSuperagentRuntime({
976
1024
  connectorFlowRef.current = null;
977
1025
  setConnectingConnectorId(null);
978
1026
  await loadConnectors(agentId);
979
- return true;
1027
+ // Return the connection_id (string) so the connector tool-approval can
1028
+ // submit it; fall back to `true` when the backend omits it.
1029
+ return connection.connection_id ?? true;
980
1030
  }
981
1031
 
982
1032
  if (!connection.redirect_url || !connection.connection_id) {
983
1033
  throw new Error('The backend did not return an authorization URL for this connector.');
984
1034
  }
985
1035
 
986
- await nativeAdapters.openUrl?.(connection.redirect_url);
987
- await waitForConnectorAuthorization(superagentService, agentId, connectorId, connection.connection_id, flow);
1036
+ if (!nativeAdapters.openUrl) {
1037
+ // Without a URL opener the browser never launches, so polling would just
1038
+ // time out after ~2 minutes. Fail immediately with an actionable error.
1039
+ throw new Error('This app cannot open the authorization page. Connect this integration from the web app.');
1040
+ }
1041
+
1042
+ await nativeAdapters.openUrl(connection.redirect_url);
1043
+ const connected = await waitForConnectorAuthorization(superagentService, agentId, connectorId, connection.connection_id, flow);
988
1044
 
989
- if (!flow.cancelled) {
1045
+ // Only clear shared state if this flow is still the active one — a newer
1046
+ // connect may have superseded it (and owns connectorFlowRef now).
1047
+ if (connectorFlowRef.current === flow) {
990
1048
  connectorFlowRef.current = null;
991
1049
  setConnectingConnectorId(null);
1050
+ }
1051
+ if (connected) {
992
1052
  await loadConnectors(agentId);
993
- return true;
994
1053
  }
995
-
996
- return false;
1054
+ // On success return the connection_id so the connector tool-approval can
1055
+ // submit it for backend verification; `false` on failure.
1056
+ return connected ? connection.connection_id : false;
997
1057
  } catch (error) {
998
- if (!flow.cancelled) {
1058
+ if (connectorFlowRef.current === flow) {
999
1059
  connectorFlowRef.current = null;
1000
1060
  setConnectingConnectorId(null);
1001
1061
  showAlert(nativeAdapters, 'Connector failed', getErrorMessage(error));
@@ -1071,6 +1131,7 @@ export function useSuperagentRuntime({
1071
1131
  // instead of defaulting to the home route.
1072
1132
  initialRoute: currentRoute,
1073
1133
  currentUserAvatarUrl: config.currentUserAvatarUrl,
1134
+ currentUserId: config.currentUserId,
1074
1135
  currentUserName: config.currentUserName,
1075
1136
  fileLoadError,
1076
1137
  fileLoadFailed,
@@ -1143,25 +1204,32 @@ async function waitForConnectorAuthorization(
1143
1204
  connectorId: string,
1144
1205
  connectionId: string,
1145
1206
  flow: ConnectorFlow,
1146
- ) {
1207
+ ): Promise<boolean> {
1208
+ // The connection status (scoped to this flow's connectionId) is the
1209
+ // authoritative source of truth — not a global callback flag, which can't be
1210
+ // attributed to a specific flow. Returns whether the connector ended up ACTIVE.
1211
+ const isActive = async () =>
1212
+ (await superagentService.getConnectorConnectionStatus(agentId, connectorId, connectionId)) === 'ACTIVE';
1213
+
1147
1214
  const maxAttempts = 40;
1148
1215
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
1149
1216
  if (flow.cancelled) {
1150
- return;
1217
+ // Cancelled — but OAuth may have already completed; confirm with the
1218
+ // authoritative status before reporting not-connected.
1219
+ return isActive().catch(() => false);
1151
1220
  }
1152
1221
 
1153
1222
  await delay(3000);
1154
- if (flow.cancelled) {
1155
- return;
1156
- }
1157
1223
 
1158
1224
  const status = await superagentService.getConnectorConnectionStatus(agentId, connectorId, connectionId);
1159
1225
  if (status === 'ACTIVE') {
1160
- return;
1226
+ return true;
1161
1227
  }
1162
1228
  if (status === 'FAILED') {
1163
1229
  throw new Error('OAuth connection failed.');
1164
1230
  }
1231
+ // If the user cancelled during the delay, the next iteration's top-of-loop
1232
+ // check re-confirms via the authoritative status before returning.
1165
1233
  }
1166
1234
 
1167
1235
  throw new Error('Connection timed out after 2 minutes.');
@@ -1178,15 +1246,28 @@ async function openAllowedExternalUrl(
1178
1246
  return;
1179
1247
  }
1180
1248
 
1249
+ if (!nativeAdapters.openUrl) {
1250
+ // No URL opener: surface it instead of passing the host check and then
1251
+ // silently doing nothing.
1252
+ showAlert(nativeAdapters, fallbackMessage, 'This app cannot open external links. Use the web app instead.');
1253
+ return;
1254
+ }
1255
+
1181
1256
  try {
1182
- await nativeAdapters.openUrl?.(url);
1257
+ await nativeAdapters.openUrl(url);
1183
1258
  } catch (error) {
1184
1259
  showAlert(nativeAdapters, fallbackMessage, getErrorMessage(error));
1185
1260
  }
1186
1261
  }
1187
1262
 
1188
1263
  function showAlert(nativeAdapters: SuperagentNativeRuntimeAdapters, title: string, message?: string) {
1189
- nativeAdapters.alert?.(title, message);
1264
+ if (nativeAdapters.alert) {
1265
+ nativeAdapters.alert(title, message);
1266
+ return;
1267
+ }
1268
+ // No host alert adapter — fall back to React Native's Alert (as confirmAction
1269
+ // does) so connector/channel/file/model errors aren't silently swallowed.
1270
+ Alert.alert(title, message);
1190
1271
  }
1191
1272
 
1192
1273
  async function confirmAction(