@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.
- package/lib/commonjs/AgentSettingsPanel.js +123 -47
- package/lib/commonjs/AgentSettingsPanel.js.map +1 -1
- package/lib/commonjs/AgentSphereIcon.js +14 -118
- package/lib/commonjs/AgentSphereIcon.js.map +1 -1
- package/lib/commonjs/AttachmentPickerStatusModal.js +3 -2
- package/lib/commonjs/AttachmentPickerStatusModal.js.map +1 -1
- package/lib/commonjs/ChannelsPanel.js +66 -44
- package/lib/commonjs/ChannelsPanel.js.map +1 -1
- package/lib/commonjs/ConversationChat.js +11 -2
- package/lib/commonjs/ConversationChat.js.map +1 -1
- package/lib/commonjs/ConversationComposer.js +8 -7
- package/lib/commonjs/ConversationComposer.js.map +1 -1
- package/lib/commonjs/ConversationScreen.js +2 -0
- package/lib/commonjs/ConversationScreen.js.map +1 -1
- package/lib/commonjs/EditorDrawer.js +54 -24
- package/lib/commonjs/EditorDrawer.js.map +1 -1
- package/lib/commonjs/FilesPanel.js +56 -20
- package/lib/commonjs/FilesPanel.js.map +1 -1
- package/lib/commonjs/RenameAgentModal.js +2 -1
- package/lib/commonjs/RenameAgentModal.js.map +1 -1
- package/lib/commonjs/ShareAgentModal.js +11 -10
- package/lib/commonjs/ShareAgentModal.js.map +1 -1
- package/lib/commonjs/ShareAgentModal.styles.js +2 -2
- package/lib/commonjs/ShareAgentModal.styles.js.map +1 -1
- package/lib/commonjs/SuperagentHomeScreen.js +27 -9
- package/lib/commonjs/SuperagentHomeScreen.js.map +1 -1
- package/lib/commonjs/ToolApprovalCard.js +72 -14
- package/lib/commonjs/ToolApprovalCard.js.map +1 -1
- package/lib/commonjs/ToolCallSummary.js +14 -9
- package/lib/commonjs/ToolCallSummary.js.map +1 -1
- package/lib/commonjs/agentSphereAssets.js +327 -0
- package/lib/commonjs/agentSphereAssets.js.map +1 -0
- package/lib/commonjs/agentSphereStyles.js +3 -3
- package/lib/commonjs/agentSphereStyles.js.map +1 -1
- package/lib/commonjs/apiClient.js +7 -0
- package/lib/commonjs/apiClient.js.map +1 -1
- package/lib/commonjs/composerStyles.js +2 -2
- package/lib/commonjs/composerStyles.js.map +1 -1
- package/lib/commonjs/connectorBrandIcons.generated.js +625 -0
- package/lib/commonjs/connectorBrandIcons.generated.js.map +1 -0
- package/lib/commonjs/connectorBrandIcons.js +3 -55
- package/lib/commonjs/connectorBrandIcons.js.map +1 -1
- package/lib/commonjs/connectorCatalog.js +19 -1
- package/lib/commonjs/connectorCatalog.js.map +1 -1
- package/lib/commonjs/conversationParts.js +5 -4
- package/lib/commonjs/conversationParts.js.map +1 -1
- package/lib/commonjs/conversationRuntime.js +120 -12
- package/lib/commonjs/conversationRuntime.js.map +1 -1
- package/lib/commonjs/conversationStyles.js +2 -1
- package/lib/commonjs/conversationStyles.js.map +1 -1
- package/lib/commonjs/editorShellStyles.js +6 -2
- package/lib/commonjs/editorShellStyles.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/markdownStyles.js +2 -2
- package/lib/commonjs/markdownStyles.js.map +1 -1
- package/lib/commonjs/messageActionStyles.js +2 -2
- package/lib/commonjs/messageActionStyles.js.map +1 -1
- package/lib/commonjs/realtimeClient.js +4 -1
- package/lib/commonjs/realtimeClient.js.map +1 -1
- package/lib/commonjs/renameAgentModalStyles.js +2 -2
- package/lib/commonjs/renameAgentModalStyles.js.map +1 -1
- package/lib/commonjs/screenParts.js +24 -41
- package/lib/commonjs/screenParts.js.map +1 -1
- package/lib/commonjs/styles.js +71 -60
- package/lib/commonjs/styles.js.map +1 -1
- package/lib/commonjs/superagentApiClient.js +63 -18
- package/lib/commonjs/superagentApiClient.js.map +1 -1
- package/lib/commonjs/theme.js +249 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/useSuperagentConversation.js +133 -20
- package/lib/commonjs/useSuperagentConversation.js.map +1 -1
- package/lib/commonjs/useSuperagentRuntime.js +167 -82
- package/lib/commonjs/useSuperagentRuntime.js.map +1 -1
- package/lib/module/AgentSettingsPanel.js +125 -49
- package/lib/module/AgentSettingsPanel.js.map +1 -1
- package/lib/module/AgentSphereIcon.js +15 -118
- package/lib/module/AgentSphereIcon.js.map +1 -1
- package/lib/module/AttachmentPickerStatusModal.js +4 -3
- package/lib/module/AttachmentPickerStatusModal.js.map +1 -1
- package/lib/module/ChannelsPanel.js +67 -45
- package/lib/module/ChannelsPanel.js.map +1 -1
- package/lib/module/ConversationChat.js +11 -2
- package/lib/module/ConversationChat.js.map +1 -1
- package/lib/module/ConversationComposer.js +8 -7
- package/lib/module/ConversationComposer.js.map +1 -1
- package/lib/module/ConversationScreen.js +2 -0
- package/lib/module/ConversationScreen.js.map +1 -1
- package/lib/module/EditorDrawer.js +55 -25
- package/lib/module/EditorDrawer.js.map +1 -1
- package/lib/module/FilesPanel.js +56 -20
- package/lib/module/FilesPanel.js.map +1 -1
- package/lib/module/RenameAgentModal.js +2 -1
- package/lib/module/RenameAgentModal.js.map +1 -1
- package/lib/module/ShareAgentModal.js +11 -10
- package/lib/module/ShareAgentModal.js.map +1 -1
- package/lib/module/ShareAgentModal.styles.js +2 -2
- package/lib/module/ShareAgentModal.styles.js.map +1 -1
- package/lib/module/SuperagentHomeScreen.js +27 -9
- package/lib/module/SuperagentHomeScreen.js.map +1 -1
- package/lib/module/ToolApprovalCard.js +72 -14
- package/lib/module/ToolApprovalCard.js.map +1 -1
- package/lib/module/ToolCallSummary.js +14 -9
- package/lib/module/ToolCallSummary.js.map +1 -1
- package/lib/module/agentSphereAssets.js +323 -0
- package/lib/module/agentSphereAssets.js.map +1 -0
- package/lib/module/agentSphereStyles.js +3 -3
- package/lib/module/agentSphereStyles.js.map +1 -1
- package/lib/module/apiClient.js +7 -0
- package/lib/module/apiClient.js.map +1 -1
- package/lib/module/composerStyles.js +2 -2
- package/lib/module/composerStyles.js.map +1 -1
- package/lib/module/connectorBrandIcons.generated.js +621 -0
- package/lib/module/connectorBrandIcons.generated.js.map +1 -0
- package/lib/module/connectorBrandIcons.js +1 -53
- package/lib/module/connectorBrandIcons.js.map +1 -1
- package/lib/module/connectorCatalog.js +17 -0
- package/lib/module/connectorCatalog.js.map +1 -1
- package/lib/module/conversationParts.js +5 -4
- package/lib/module/conversationParts.js.map +1 -1
- package/lib/module/conversationRuntime.js +118 -12
- package/lib/module/conversationRuntime.js.map +1 -1
- package/lib/module/conversationStyles.js +3 -2
- package/lib/module/conversationStyles.js.map +1 -1
- package/lib/module/editorShellStyles.js +6 -2
- package/lib/module/editorShellStyles.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/markdownStyles.js +2 -2
- package/lib/module/markdownStyles.js.map +1 -1
- package/lib/module/messageActionStyles.js +2 -2
- package/lib/module/messageActionStyles.js.map +1 -1
- package/lib/module/realtimeClient.js +4 -1
- package/lib/module/realtimeClient.js.map +1 -1
- package/lib/module/renameAgentModalStyles.js +2 -2
- package/lib/module/renameAgentModalStyles.js.map +1 -1
- package/lib/module/screenParts.js +25 -42
- package/lib/module/screenParts.js.map +1 -1
- package/lib/module/styles.js +71 -60
- package/lib/module/styles.js.map +1 -1
- package/lib/module/superagentApiClient.js +63 -18
- package/lib/module/superagentApiClient.js.map +1 -1
- package/lib/module/theme.js +239 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/useSuperagentConversation.js +135 -22
- package/lib/module/useSuperagentConversation.js.map +1 -1
- package/lib/module/useSuperagentRuntime.js +167 -82
- package/lib/module/useSuperagentRuntime.js.map +1 -1
- package/lib/typescript/commonjs/AgentSettingsPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/AgentSphereIcon.d.ts.map +1 -1
- package/lib/typescript/commonjs/AttachmentPickerStatusModal.d.ts.map +1 -1
- package/lib/typescript/commonjs/ChannelsPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/ConversationChat.d.ts +1 -1
- package/lib/typescript/commonjs/ConversationChat.d.ts.map +1 -1
- package/lib/typescript/commonjs/ConversationComposer.d.ts.map +1 -1
- package/lib/typescript/commonjs/ConversationMessageList.d.ts +1 -1
- package/lib/typescript/commonjs/ConversationMessageList.d.ts.map +1 -1
- package/lib/typescript/commonjs/ConversationScreen.d.ts +2 -1
- package/lib/typescript/commonjs/ConversationScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/EditorDrawer.d.ts +1 -1
- package/lib/typescript/commonjs/EditorDrawer.d.ts.map +1 -1
- package/lib/typescript/commonjs/FilesPanel.d.ts.map +1 -1
- package/lib/typescript/commonjs/RenameAgentModal.d.ts.map +1 -1
- package/lib/typescript/commonjs/ShareAgentModal.d.ts.map +1 -1
- package/lib/typescript/commonjs/ShareAgentModal.styles.d.ts.map +1 -1
- package/lib/typescript/commonjs/SuperagentHomeScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ToolApprovalCard.d.ts +3 -3
- package/lib/typescript/commonjs/ToolApprovalCard.d.ts.map +1 -1
- package/lib/typescript/commonjs/ToolCallSummary.d.ts +1 -1
- package/lib/typescript/commonjs/ToolCallSummary.d.ts.map +1 -1
- package/lib/typescript/commonjs/agentSphereAssets.d.ts +2 -0
- package/lib/typescript/commonjs/agentSphereAssets.d.ts.map +1 -0
- package/lib/typescript/commonjs/agentSphereStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/apiClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/composerStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/connectorBrandIcons.d.ts.map +1 -1
- package/lib/typescript/commonjs/connectorBrandIcons.generated.d.ts +2 -0
- package/lib/typescript/commonjs/connectorBrandIcons.generated.d.ts.map +1 -0
- package/lib/typescript/commonjs/connectorCatalog.d.ts +2 -0
- package/lib/typescript/commonjs/connectorCatalog.d.ts.map +1 -1
- package/lib/typescript/commonjs/conversationParts.d.ts +1 -1
- package/lib/typescript/commonjs/conversationParts.d.ts.map +1 -1
- package/lib/typescript/commonjs/conversationRuntime.d.ts +6 -1
- package/lib/typescript/commonjs/conversationRuntime.d.ts.map +1 -1
- package/lib/typescript/commonjs/conversationStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/editorShellStyles.d.ts +4 -0
- package/lib/typescript/commonjs/editorShellStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/markdownStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/messageActionStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/realtimeClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/renameAgentModalStyles.d.ts.map +1 -1
- package/lib/typescript/commonjs/screenParts.d.ts +1 -1
- package/lib/typescript/commonjs/screenParts.d.ts.map +1 -1
- package/lib/typescript/commonjs/styles.d.ts +20 -11
- package/lib/typescript/commonjs/styles.d.ts.map +1 -1
- package/lib/typescript/commonjs/superagentApiClient.d.ts +2 -1
- package/lib/typescript/commonjs/superagentApiClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme.d.ts +36 -0
- package/lib/typescript/commonjs/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +16 -2
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/useSuperagentConversation.d.ts +3 -2
- package/lib/typescript/commonjs/useSuperagentConversation.d.ts.map +1 -1
- package/lib/typescript/commonjs/useSuperagentRuntime.d.ts +2 -1
- package/lib/typescript/commonjs/useSuperagentRuntime.d.ts.map +1 -1
- package/lib/typescript/module/AgentSettingsPanel.d.ts.map +1 -1
- package/lib/typescript/module/AgentSphereIcon.d.ts.map +1 -1
- package/lib/typescript/module/AttachmentPickerStatusModal.d.ts.map +1 -1
- package/lib/typescript/module/ChannelsPanel.d.ts.map +1 -1
- package/lib/typescript/module/ConversationChat.d.ts +1 -1
- package/lib/typescript/module/ConversationChat.d.ts.map +1 -1
- package/lib/typescript/module/ConversationComposer.d.ts.map +1 -1
- package/lib/typescript/module/ConversationMessageList.d.ts +1 -1
- package/lib/typescript/module/ConversationMessageList.d.ts.map +1 -1
- package/lib/typescript/module/ConversationScreen.d.ts +2 -1
- package/lib/typescript/module/ConversationScreen.d.ts.map +1 -1
- package/lib/typescript/module/EditorDrawer.d.ts +1 -1
- package/lib/typescript/module/EditorDrawer.d.ts.map +1 -1
- package/lib/typescript/module/FilesPanel.d.ts.map +1 -1
- package/lib/typescript/module/RenameAgentModal.d.ts.map +1 -1
- package/lib/typescript/module/ShareAgentModal.d.ts.map +1 -1
- package/lib/typescript/module/ShareAgentModal.styles.d.ts.map +1 -1
- package/lib/typescript/module/SuperagentHomeScreen.d.ts.map +1 -1
- package/lib/typescript/module/ToolApprovalCard.d.ts +3 -3
- package/lib/typescript/module/ToolApprovalCard.d.ts.map +1 -1
- package/lib/typescript/module/ToolCallSummary.d.ts +1 -1
- package/lib/typescript/module/ToolCallSummary.d.ts.map +1 -1
- package/lib/typescript/module/agentSphereAssets.d.ts +2 -0
- package/lib/typescript/module/agentSphereAssets.d.ts.map +1 -0
- package/lib/typescript/module/agentSphereStyles.d.ts.map +1 -1
- package/lib/typescript/module/apiClient.d.ts.map +1 -1
- package/lib/typescript/module/composerStyles.d.ts.map +1 -1
- package/lib/typescript/module/connectorBrandIcons.d.ts.map +1 -1
- package/lib/typescript/module/connectorBrandIcons.generated.d.ts +2 -0
- package/lib/typescript/module/connectorBrandIcons.generated.d.ts.map +1 -0
- package/lib/typescript/module/connectorCatalog.d.ts +2 -0
- package/lib/typescript/module/connectorCatalog.d.ts.map +1 -1
- package/lib/typescript/module/conversationParts.d.ts +1 -1
- package/lib/typescript/module/conversationParts.d.ts.map +1 -1
- package/lib/typescript/module/conversationRuntime.d.ts +6 -1
- package/lib/typescript/module/conversationRuntime.d.ts.map +1 -1
- package/lib/typescript/module/conversationStyles.d.ts.map +1 -1
- package/lib/typescript/module/editorShellStyles.d.ts +4 -0
- package/lib/typescript/module/editorShellStyles.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/markdownStyles.d.ts.map +1 -1
- package/lib/typescript/module/messageActionStyles.d.ts.map +1 -1
- package/lib/typescript/module/realtimeClient.d.ts.map +1 -1
- package/lib/typescript/module/renameAgentModalStyles.d.ts.map +1 -1
- package/lib/typescript/module/screenParts.d.ts +1 -1
- package/lib/typescript/module/screenParts.d.ts.map +1 -1
- package/lib/typescript/module/styles.d.ts +20 -11
- package/lib/typescript/module/styles.d.ts.map +1 -1
- package/lib/typescript/module/superagentApiClient.d.ts +2 -1
- package/lib/typescript/module/superagentApiClient.d.ts.map +1 -1
- package/lib/typescript/module/theme.d.ts +36 -0
- package/lib/typescript/module/theme.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +16 -2
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/lib/typescript/module/useSuperagentConversation.d.ts +3 -2
- package/lib/typescript/module/useSuperagentConversation.d.ts.map +1 -1
- package/lib/typescript/module/useSuperagentRuntime.d.ts +2 -1
- package/lib/typescript/module/useSuperagentRuntime.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/AgentSettingsPanel.tsx +118 -49
- package/src/AgentSphereIcon.tsx +11 -62
- package/src/AttachmentPickerStatusModal.tsx +4 -3
- package/src/ChannelsPanel.tsx +59 -39
- package/src/ConversationChat.tsx +12 -3
- package/src/ConversationComposer.tsx +7 -6
- package/src/ConversationMessageList.tsx +1 -1
- package/src/ConversationScreen.tsx +3 -0
- package/src/EditorDrawer.tsx +66 -41
- package/src/FilesPanel.tsx +48 -20
- package/src/RenameAgentModal.tsx +2 -1
- package/src/ShareAgentModal.styles.ts +2 -1
- package/src/ShareAgentModal.tsx +9 -8
- package/src/SuperagentHomeScreen.tsx +27 -7
- package/src/ToolApprovalCard.tsx +82 -14
- package/src/ToolCallSummary.tsx +18 -12
- package/src/agentSphereAssets.ts +325 -0
- package/src/agentSphereStyles.ts +3 -2
- package/src/apiClient.ts +7 -0
- package/src/composerStyles.ts +2 -1
- package/src/connectorBrandIcons.generated.ts +618 -0
- package/src/connectorBrandIcons.tsx +1 -53
- package/src/connectorCatalog.ts +24 -0
- package/src/conversationParts.tsx +6 -5
- package/src/conversationRuntime.ts +123 -12
- package/src/conversationStyles.ts +2 -1
- package/src/editorShellStyles.ts +6 -1
- package/src/index.ts +2 -0
- package/src/markdownStyles.ts +2 -1
- package/src/messageActionStyles.ts +2 -1
- package/src/realtimeClient.ts +7 -1
- package/src/renameAgentModalStyles.ts +2 -1
- package/src/screenParts.tsx +17 -29
- package/src/styles.ts +63 -54
- package/src/superagentApiClient.ts +68 -18
- package/src/theme.ts +254 -0
- package/src/types.ts +21 -2
- package/src/useSuperagentConversation.ts +141 -24
- 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
|
-
|
|
303
|
-
|
|
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
|
-
|
|
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
|
-
}, [
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
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
|
-
|
|
817
|
-
|
|
818
|
-
|
|
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
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
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
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
|
|
909
|
-
|
|
910
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
987
|
-
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
|
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
|
|
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(
|