@datalayer/agent-runtimes 1.0.2 → 1.0.4
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/README.md +14 -132
- package/lib/Agent.js +2 -2
- package/lib/AgentLexical.d.ts +1 -12
- package/lib/AgentLexical.js +3 -14
- package/lib/AgentNotebook.js +3 -3
- package/lib/App.js +2 -2
- package/lib/{components/chat/components → agents}/AgentDetails.d.ts +13 -2
- package/lib/{components/chat/components → agents}/AgentDetails.js +6 -12
- package/lib/api/agents.d.ts +47 -0
- package/lib/api/agents.js +106 -0
- package/lib/api/context.d.ts +17 -0
- package/lib/api/context.js +45 -0
- package/lib/api/evals.d.ts +27 -0
- package/lib/api/evals.js +63 -0
- package/lib/api/events.d.ts +17 -0
- package/lib/api/events.js +93 -0
- package/lib/{components/chat → api}/handler.js +1 -1
- package/lib/api/index.d.ts +15 -0
- package/lib/api/index.js +20 -0
- package/lib/api/notifications.d.ts +39 -0
- package/lib/api/notifications.js +103 -0
- package/lib/api/output.d.ts +28 -0
- package/lib/api/output.js +64 -0
- package/lib/api/tool-approvals.d.ts +62 -0
- package/lib/api/tool-approvals.js +145 -0
- package/lib/{components/chat/components → chat}/Chat.d.ts +26 -15
- package/lib/{components/chat/components → chat}/Chat.js +16 -16
- package/lib/{components/chat/components → chat}/ChatFloating.d.ts +17 -9
- package/lib/{components/chat/components → chat}/ChatFloating.js +17 -9
- package/lib/{components/chat/components → chat}/ChatInline.d.ts +2 -2
- package/lib/{components/chat/components → chat}/ChatInline.js +8 -6
- package/lib/{components/chat/components → chat}/ChatPopupStandalone.d.ts +3 -4
- package/lib/{components/chat/components → chat}/ChatPopupStandalone.js +6 -6
- package/lib/{components/chat/components → chat}/ChatSidebar.d.ts +14 -5
- package/lib/{components/chat/components → chat}/ChatSidebar.js +48 -26
- package/lib/{components/chat/components → chat}/ChatStandalone.d.ts +3 -4
- package/lib/{components/chat/components → chat}/ChatStandalone.js +5 -5
- package/lib/chat/base/ChatBase.d.ts +6 -0
- package/lib/chat/base/ChatBase.js +1338 -0
- package/lib/chat/display/EmptyState.d.ts +27 -0
- package/lib/chat/display/EmptyState.js +41 -0
- package/lib/{components/chat/components/elements → chat/display}/FloatingBrandButton.d.ts +1 -1
- package/lib/{components/chat/components/elements → chat/display}/FloatingBrandButton.js +1 -1
- package/lib/{components/chat/components/elements → chat/display}/PoweredByTag.d.ts +1 -1
- package/lib/{components/chat/components/elements → chat/header}/ChatHeader.d.ts +1 -4
- package/lib/{components/chat/components/elements → chat/header}/ChatHeader.js +1 -1
- package/lib/chat/header/ChatHeaderBase.d.ts +38 -0
- package/lib/chat/header/ChatHeaderBase.js +83 -0
- package/lib/chat/index.d.ts +66 -0
- package/lib/chat/index.js +74 -0
- package/lib/chat/indicators/McpStatusIndicator.d.ts +9 -0
- package/lib/chat/indicators/McpStatusIndicator.js +128 -0
- package/lib/chat/indicators/SandboxStatusIndicator.d.ts +10 -0
- package/lib/chat/indicators/SandboxStatusIndicator.js +175 -0
- package/lib/chat/indicators/index.d.ts +17 -0
- package/lib/chat/indicators/index.js +19 -0
- package/lib/chat/messages/ChatMessageList.d.ts +49 -0
- package/lib/chat/messages/ChatMessageList.js +332 -0
- package/lib/{components/chat/components/elements → chat/messages}/ChatMessages.d.ts +2 -2
- package/lib/{components/chat/components/elements → chat/messages}/ChatMessages.js +6 -4
- package/lib/{components/chat/components → chat}/parts/DynamicToolPart.d.ts +1 -1
- package/lib/{components/chat/components/elements → chat/parts}/MessagePart.d.ts +1 -1
- package/lib/{components/chat/components/elements → chat/parts}/MessagePart.js +4 -4
- package/lib/{components/chat/components → chat}/parts/ReasoningPart.js +1 -1
- package/lib/{components/chat/components → chat}/parts/TextPart.d.ts +1 -1
- package/lib/{components/chat/components → chat}/parts/ToolPart.js +1 -1
- package/lib/{components/chat/components → chat}/parts/index.d.ts +2 -1
- package/lib/{components/chat/components → chat}/parts/index.js +2 -1
- package/lib/chat/prompt/InputFooter.d.ts +43 -0
- package/lib/chat/prompt/InputFooter.js +135 -0
- package/lib/chat/prompt/InputPrompt.d.ts +60 -0
- package/lib/chat/prompt/InputPrompt.js +83 -0
- package/lib/chat/prompt/InputPromptFooter.d.ts +25 -0
- package/lib/chat/prompt/InputPromptFooter.js +15 -0
- package/lib/chat/prompt/InputPromptHeader.d.ts +15 -0
- package/lib/chat/prompt/InputPromptHeader.js +15 -0
- package/lib/chat/prompt/InputPromptLexical.d.ts +16 -0
- package/lib/chat/prompt/InputPromptLexical.js +122 -0
- package/lib/chat/prompt/InputPromptText.d.ts +24 -0
- package/lib/chat/prompt/InputPromptText.js +66 -0
- package/lib/chat/prompt/index.d.ts +11 -0
- package/lib/chat/prompt/index.js +15 -0
- package/lib/{components/chat/components → chat}/styles/streamdownStyles.d.ts +1 -1
- package/lib/chat/tools/ToolApprovalBanner.d.ts +31 -0
- package/lib/chat/tools/ToolApprovalBanner.js +62 -0
- package/lib/{components/chat/components/elements → chat/tools}/ToolApprovalDialog.js +1 -1
- package/lib/{components/chat/components/display → chat/tools}/ToolCallDisplay.d.ts +13 -4
- package/lib/{components/chat/components/display → chat/tools}/ToolCallDisplay.js +18 -8
- package/lib/chat/tools/index.d.ts +8 -0
- package/lib/{components/chat/components/display → chat/tools}/index.js +3 -1
- package/lib/chat/usage/TokenUsageBar.d.ts +8 -0
- package/lib/chat/usage/TokenUsageBar.js +213 -0
- package/lib/client/AgentsMixin.d.ts +216 -0
- package/lib/client/AgentsMixin.js +388 -0
- package/lib/client/index.d.ts +6 -0
- package/lib/client/index.js +10 -0
- package/lib/components/NotificationEventCard.d.ts +8 -0
- package/lib/components/NotificationEventCard.js +177 -0
- package/lib/components/OutputCard.d.ts +8 -0
- package/lib/components/OutputCard.js +94 -0
- package/lib/components/ToolApprovalCard.d.ts +33 -0
- package/lib/components/ToolApprovalCard.js +78 -0
- package/lib/components/index.d.ts +3 -7
- package/lib/components/index.js +3 -4
- package/lib/{components → config}/AgentConfiguration.d.ts +43 -21
- package/lib/{components → config}/AgentConfiguration.js +48 -28
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +1 -0
- package/lib/{components/chat/components → context}/ContextInspector.js +38 -8
- package/lib/{components/chat/components → context}/ContextPanel.js +27 -6
- package/lib/context/CostTracker.d.ts +37 -0
- package/lib/context/CostTracker.js +124 -0
- package/lib/context/TokenUsageChart.d.ts +10 -0
- package/lib/context/TokenUsageChart.js +288 -0
- package/lib/examples/A2UiComponentGalleryExample.d.ts +20 -0
- package/lib/examples/A2UiComponentGalleryExample.js +568 -0
- package/lib/examples/A2UiContactCardExample.d.ts +21 -0
- package/lib/examples/A2UiContactCardExample.js +432 -0
- package/lib/examples/A2UiRestaurantExample.d.ts +11 -3
- package/lib/examples/A2UiRestaurantExample.js +63 -98
- package/lib/examples/A2UiViewerExample.d.ts +21 -0
- package/lib/examples/A2UiViewerExample.js +563 -0
- package/lib/examples/AgUiAgenticExample.js +3 -3
- package/lib/examples/AgUiBackendToolRenderingExample.js +3 -3
- package/lib/examples/{AgUiHaikuGenUIExample.d.ts → AgUiHaikuGenUiExample.d.ts} +4 -4
- package/lib/examples/{AgUiHaikuGenUIExample.js → AgUiHaikuGenUiExample.js} +7 -7
- package/lib/examples/AgUiHumanInTheLoopExample.js +3 -3
- package/lib/examples/AgUiSharedStateExample.js +3 -3
- package/lib/examples/{AgUiToolsBasedGenUIExample.d.ts → AgUiToolsBasedGenUiExample.d.ts} +4 -4
- package/lib/examples/{AgUiToolsBasedGenUIExample.js → AgUiToolsBasedGenUiExample.js} +7 -7
- package/lib/examples/AgentCheckpointsExample.d.ts +19 -0
- package/lib/examples/AgentCheckpointsExample.js +500 -0
- package/lib/examples/AgentCodemodeExample.d.ts +14 -0
- package/lib/examples/AgentCodemodeExample.js +256 -0
- package/lib/examples/AgentEvalsExample.d.ts +14 -0
- package/lib/examples/AgentEvalsExample.js +210 -0
- package/lib/examples/AgentGuardrailsExample.d.ts +14 -0
- package/lib/examples/AgentGuardrailsExample.js +212 -0
- package/lib/examples/AgentMemoryExample.d.ts +14 -0
- package/lib/examples/AgentMemoryExample.js +228 -0
- package/lib/examples/AgentMonitoringExample.d.ts +13 -0
- package/lib/examples/AgentMonitoringExample.js +305 -0
- package/lib/examples/AgentNotificationsExample.d.ts +14 -0
- package/lib/examples/AgentNotificationsExample.js +267 -0
- package/lib/examples/AgentOtelExample.d.ts +25 -0
- package/lib/examples/AgentOtelExample.js +281 -0
- package/lib/examples/AgentOutputsExample.d.ts +14 -0
- package/lib/examples/AgentOutputsExample.js +205 -0
- package/lib/examples/AgentSandboxExample.d.ts +17 -0
- package/lib/examples/AgentSandboxExample.js +490 -0
- package/lib/examples/AgentSkillsExample.d.ts +3 -0
- package/lib/examples/AgentSkillsExample.js +284 -0
- package/lib/examples/AgentToolApprovalsExample.d.ts +3 -0
- package/lib/examples/AgentToolApprovalsExample.js +737 -0
- package/lib/examples/AgentTriggersExample.d.ts +14 -0
- package/lib/examples/AgentTriggersExample.js +1090 -0
- package/lib/examples/{AgentRuntimeFormExample.d.ts → AgentspecExample.d.ts} +3 -4
- package/lib/examples/{AgentRuntimeFormExample.js → AgentspecExample.js} +92 -34
- package/lib/examples/{JupyterCellExample.js → CellSimpleExample.js} +1 -1
- package/lib/examples/{AgentRuntimeCustomExample.js → ChatCustomExample.js} +3 -3
- package/lib/examples/{AgentRuntimeChatExample.js → ChatExample.js} +6 -14
- package/lib/examples/{AgentRuntimeStandaloneExample.js → ChatStandaloneExample.js} +2 -2
- package/lib/examples/CopilotKitLexicalExample.d.ts +3 -14
- package/lib/examples/CopilotKitLexicalExample.js +4 -15
- package/lib/examples/CopilotKitNotebookExample.js +4 -6
- package/lib/examples/DatalayerNotebookExample.js +2 -2
- package/lib/examples/{AgentRuntimeLexical2Example.d.ts → Lexical2Example.d.ts} +2 -13
- package/lib/examples/{AgentRuntimeLexical2Example.js → Lexical2Example.js} +8 -17
- package/lib/examples/{AgentRuntimeLexicalExample.d.ts → LexicalExample.d.ts} +1 -12
- package/lib/examples/{AgentRuntimeLexicalExample.js → LexicalExample.js} +28 -27
- package/lib/examples/{AgentRuntimeLexicalSidebarExample.d.ts → LexicalSidebarExample.d.ts} +2 -13
- package/lib/examples/{AgentRuntimeLexicalSidebarExample.js → LexicalSidebarExample.js} +6 -18
- package/lib/examples/{AgentRuntimeNotebookExample.js → NotebookExample.js} +14 -10
- package/lib/examples/{AgentRuntimeNotebookSidebarExample.js → NotebookSidebarExample.js} +5 -8
- package/lib/examples/{JupyterNotebookExample.js → NotebookSimpleExample.js} +2 -2
- package/lib/examples/ag-ui/weather/InlineWeatherCard.js +1 -1
- package/lib/examples/components/ErrorView.d.ts +14 -0
- package/lib/examples/components/ErrorView.js +20 -0
- package/lib/examples/components/ExampleWrapper.d.ts +12 -0
- package/lib/examples/components/ExampleWrapper.js +16 -0
- package/lib/examples/components/Header.d.ts +2 -2
- package/lib/examples/components/HeaderControls.js +1 -1
- package/lib/examples/components/LexicalEditor.d.ts +1 -12
- package/lib/examples/components/LexicalEditor.js +1 -12
- package/lib/examples/components/MainContent.d.ts +4 -11
- package/lib/examples/components/MainContent.js +6 -60
- package/lib/examples/components/index.d.ts +3 -0
- package/lib/examples/components/index.js +2 -0
- package/lib/examples/example-selector.d.ts +1 -1
- package/lib/examples/example-selector.js +35 -22
- package/lib/examples/index.d.ts +26 -13
- package/lib/examples/index.js +26 -12
- package/lib/examples/main.d.ts +7 -0
- package/lib/examples/main.js +21 -43
- package/lib/examples/utils/examplesStore.d.ts +4 -0
- package/lib/examples/{stores → utils}/examplesStore.js +1 -1
- package/lib/examples/utils/notebooks/Empty.ipynb.json +33 -0
- package/lib/examples/utils/notebooks/NotebookExample2.ipynb.json +48 -0
- package/lib/examples/utils/themeStore.d.ts +8 -0
- package/lib/examples/utils/themeStore.js +14 -0
- package/lib/extensions/A2UIExtension.d.ts +65 -0
- package/lib/extensions/A2UIExtension.js +202 -0
- package/lib/{components/chat/extensions → extensions}/ExtensionRegistry.d.ts +2 -3
- package/lib/{components/chat/extensions → extensions}/ExtensionRegistry.js +0 -2
- package/lib/{components/chat/extensions → extensions}/MCPUIExtension.d.ts +2 -2
- package/lib/{components/chat/extensions → extensions}/MCPUIExtension.js +1 -1
- package/lib/extensions/index.d.ts +9 -0
- package/lib/{components/chat/extensions → extensions}/index.js +2 -2
- package/lib/hooks/index.d.ts +33 -16
- package/lib/hooks/index.js +33 -16
- package/lib/hooks/useAIAgentsWebSocket.d.ts +29 -0
- package/lib/hooks/useAIAgentsWebSocket.js +136 -0
- package/lib/hooks/{useAGUI.d.ts → useAgUi.d.ts} +2 -2
- package/lib/hooks/{useAGUI.js → useAgUi.js} +2 -2
- package/lib/hooks/useAgents.d.ts +150 -11
- package/lib/hooks/useAgents.js +623 -61
- package/lib/hooks/{useAgentStore.d.ts → useAgentsCatalog.d.ts} +3 -8
- package/lib/hooks/{useAgentStore.js → useAgentsCatalog.js} +9 -3
- package/lib/hooks/useAgentsRegistry.d.ts +10 -0
- package/lib/hooks/useAgentsRegistry.js +20 -0
- package/lib/hooks/useAgentsService.d.ts +22 -0
- package/lib/hooks/useAgentsService.js +146 -0
- package/lib/hooks/useChat.d.ts +2 -2
- package/lib/hooks/useChat.js +14 -8
- package/lib/hooks/useCheckpoints.d.ts +176 -0
- package/lib/hooks/useCheckpoints.js +466 -0
- package/lib/hooks/useConfig.d.ts +11 -0
- package/lib/hooks/useConfig.js +46 -0
- package/lib/hooks/useContextSnapshot.d.ts +11 -0
- package/lib/hooks/useContextSnapshot.js +44 -0
- package/lib/hooks/useMonitoring.d.ts +24 -0
- package/lib/hooks/useMonitoring.js +111 -0
- package/lib/hooks/useNotifications.d.ts +67 -0
- package/lib/hooks/useNotifications.js +208 -0
- package/lib/hooks/useSandbox.d.ts +12 -0
- package/lib/hooks/useSandbox.js +49 -0
- package/lib/hooks/useSkills.d.ts +13 -0
- package/lib/hooks/useSkills.js +46 -0
- package/lib/hooks/useToolApprovals.d.ts +45 -0
- package/lib/hooks/useToolApprovals.js +126 -0
- package/lib/hooks/useTools.d.ts +4 -4
- package/lib/hooks/useTools.js +2 -2
- package/lib/hooks/{useVercelChat.d.ts → useVercelAI.d.ts} +3 -3
- package/lib/hooks/{useVercelChat.js → useVercelAI.js} +2 -2
- package/lib/{components/chat/components → identity}/AgentIdentity.d.ts +1 -1
- package/lib/{components/chat/components → identity}/AgentIdentity.js +4 -3
- package/lib/identity/index.d.ts +1 -0
- package/lib/identity/index.js +2 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +3 -2
- package/lib/{components/chat/inference → inference}/BaseInferenceProvider.d.ts +3 -3
- package/lib/{components/chat/inference → inference}/DatalayerInferenceProvider.d.ts +3 -3
- package/lib/{components/chat/inference → inference}/DatalayerInferenceProvider.js +1 -1
- package/lib/{components/chat/inference → inference}/SelfHostedInferenceProvider.d.ts +2 -2
- package/lib/{components/chat/inference → inference}/SelfHostedInferenceProvider.js +1 -1
- package/lib/{components/chat/inference → inference}/index.d.ts +1 -1
- package/lib/{components/chat/inference → inference}/index.js +1 -1
- package/lib/lexical/ChatInlinePlugin.d.ts +1 -1
- package/lib/lexical/ChatInlinePlugin.js +1 -1
- package/lib/{components → mcp}/McpServerManager.d.ts +1 -2
- package/lib/mcp/index.d.ts +1 -0
- package/lib/{specs/agents/codeai → mcp}/index.js +1 -1
- package/lib/{components/chat/middleware → middleware}/MiddlewarePipeline.d.ts +3 -3
- package/lib/{components/chat/middleware → middleware}/index.d.ts +1 -1
- package/lib/{components/chat/middleware → middleware}/index.js +1 -1
- package/lib/{components/chat/protocols → protocols}/A2AAdapter.d.ts +6 -6
- package/lib/{components/chat/protocols → protocols}/A2AAdapter.js +3 -3
- package/lib/{components/chat/protocols → protocols}/ACPAdapter.d.ts +6 -6
- package/lib/{components/chat/protocols → protocols}/ACPAdapter.js +4 -4
- package/lib/{components/chat/protocols → protocols}/AGUIAdapter.d.ts +14 -6
- package/lib/{components/chat/protocols → protocols}/AGUIAdapter.js +72 -10
- package/lib/{components/chat/protocols → protocols}/BaseProtocolAdapter.d.ts +6 -6
- package/lib/{components/chat/protocols → protocols}/BaseProtocolAdapter.js +1 -1
- package/lib/{components/chat/protocols → protocols}/VercelAIAdapter.d.ts +33 -7
- package/lib/protocols/VercelAIAdapter.js +748 -0
- package/lib/{components/chat/protocols → protocols}/index.d.ts +1 -2
- package/lib/{components/chat/protocols → protocols}/index.js +1 -1
- package/lib/shims/json5.d.ts +4 -0
- package/lib/shims/json5.js +8 -0
- package/lib/specs/agents/agents.d.ts +54 -0
- package/lib/specs/agents/agents.js +1489 -0
- package/lib/specs/agents/index.js +15 -12
- package/lib/specs/envvars.d.ts +11 -19
- package/lib/specs/envvars.js +52 -38
- package/lib/specs/evals.d.ts +20 -0
- package/lib/specs/evals.js +133 -0
- package/lib/specs/events.d.ts +26 -0
- package/lib/specs/events.js +140 -0
- package/lib/specs/frontendTools.d.ts +14 -0
- package/lib/specs/frontendTools.js +53 -0
- package/lib/specs/guardrails.d.ts +29 -0
- package/lib/specs/guardrails.js +310 -0
- package/lib/specs/index.d.ts +15 -2
- package/lib/specs/index.js +15 -2
- package/lib/specs/mcpServers.d.ts +13 -11
- package/lib/specs/mcpServers.js +75 -50
- package/lib/specs/memory.d.ts +36 -0
- package/lib/specs/memory.js +112 -0
- package/lib/specs/models.d.ts +21 -34
- package/lib/specs/models.js +66 -66
- package/lib/specs/notifications.d.ts +17 -0
- package/lib/specs/notifications.js +103 -0
- package/lib/specs/outputs.d.ts +19 -0
- package/lib/specs/outputs.js +106 -0
- package/lib/specs/skills.d.ts +7 -16
- package/lib/specs/skills.js +95 -18
- package/lib/specs/teams/index.d.ts +17 -0
- package/lib/specs/teams/index.js +35 -0
- package/lib/specs/teams/teams.d.ts +27 -0
- package/lib/specs/teams/teams.js +1000 -0
- package/lib/specs/tools.d.ts +15 -0
- package/lib/specs/tools.js +86 -0
- package/lib/specs/triggers.d.ts +15 -0
- package/lib/specs/triggers.js +67 -0
- package/lib/stores/agentsStore.d.ts +123 -0
- package/lib/stores/agentsStore.js +270 -0
- package/lib/{components/chat/store → stores}/chatStore.d.ts +3 -2
- package/lib/{components/chat/store → stores}/chatStore.js +2 -2
- package/lib/{components/chat/store → stores}/conversationStore.d.ts +1 -1
- package/lib/{components/chat/store → stores}/conversationStore.js +1 -1
- package/lib/{components/chat/store → stores}/index.d.ts +3 -2
- package/lib/{components/chat/store → stores}/index.js +3 -2
- package/lib/{components/chat/tools → tools}/ToolExecutor.d.ts +2 -2
- package/lib/{components/chat/tools → tools}/ToolExecutor.js +1 -1
- package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.d.ts +1 -1
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +14 -10
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +31 -21
- package/lib/tools/adapters/agent-runtimes/notebookHooks.d.ts +1 -1
- package/lib/tools/index.d.ts +3 -0
- package/lib/tools/index.js +3 -7
- package/lib/types/a2a.d.ts +39 -0
- package/lib/types/acp.d.ts +21 -0
- package/lib/types/ag-ui.d.ts +25 -0
- package/lib/types/agents-lifecycle.d.ts +36 -0
- package/lib/types/agents.d.ts +80 -0
- package/lib/types/agents.js +22 -0
- package/lib/types/agentspecs.d.ts +90 -0
- package/lib/{components/chat/components/base/ChatBase.d.ts → types/chat.d.ts} +59 -99
- package/lib/types/checkpoints.d.ts +32 -0
- package/lib/types/checkpoints.js +5 -0
- package/lib/types/config.d.ts +67 -0
- package/lib/{runtime/types.js → types/config.js} +2 -2
- package/lib/types/connection.d.ts +31 -0
- package/lib/types/connection.js +5 -0
- package/lib/types/context.d.ts +67 -0
- package/lib/types/context.js +5 -0
- package/lib/types/cost.d.ts +42 -0
- package/lib/types/cost.js +5 -0
- package/lib/types/envvars.d.ts +21 -0
- package/lib/types/envvars.js +5 -0
- package/lib/types/evals.d.ts +66 -0
- package/lib/types/evals.js +5 -0
- package/lib/types/events.d.ts +49 -0
- package/lib/types/events.js +5 -0
- package/lib/types/eventspecs.d.ts +39 -0
- package/lib/types/eventspecs.js +5 -0
- package/lib/types/examples.d.ts +31 -0
- package/lib/types/examples.js +5 -0
- package/lib/{components/chat/types → types}/execution.d.ts +10 -1
- package/lib/{components/chat/types/extension.d.ts → types/extensions.d.ts} +3 -3
- package/lib/types/guardrails.d.ts +106 -0
- package/lib/types/guardrails.js +5 -0
- package/lib/types/index.d.ts +36 -2
- package/lib/types/index.js +35 -2
- package/lib/{components/chat/types → types}/inference.d.ts +3 -3
- package/lib/types/inference.js +5 -0
- package/lib/types/mcp.d.ts +117 -0
- package/lib/types/mcp.js +27 -0
- package/lib/types/memory.d.ts +23 -0
- package/lib/types/memory.js +5 -0
- package/lib/{components/chat/types/message.d.ts → types/messages.d.ts} +20 -1
- package/lib/{components/chat/types → types}/middleware.d.ts +3 -3
- package/lib/types/models.d.ts +63 -0
- package/lib/types/models.js +5 -0
- package/lib/types/notifications.d.ts +85 -0
- package/lib/types/notifications.js +5 -0
- package/lib/types/outputs.d.ts +51 -0
- package/lib/types/outputs.js +5 -0
- package/lib/{components/chat/types → types}/protocol.d.ts +37 -99
- package/lib/types/protocol.js +5 -0
- package/lib/types/sandbox.d.ts +27 -0
- package/lib/types/sandbox.js +24 -0
- package/lib/types/skills.d.ts +74 -0
- package/lib/types/skills.js +5 -0
- package/lib/types/teams.d.ts +133 -0
- package/lib/types/teams.js +5 -0
- package/lib/types/tool-approvals.d.ts +39 -0
- package/lib/types/tool-approvals.js +5 -0
- package/lib/{components/chat/types/tool.d.ts → types/tools.d.ts} +61 -4
- package/lib/types/triggers.d.ts +48 -0
- package/lib/types/triggers.js +5 -0
- package/lib/types/usage.d.ts +36 -0
- package/lib/types/usage.js +5 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +5 -0
- package/lib/utils/utils.d.ts +60 -0
- package/lib/utils/utils.js +205 -0
- package/package.json +13 -14
- package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
- package/scripts/codegen/generate_agents.py +377 -61
- package/scripts/codegen/generate_envvars.py +36 -35
- package/scripts/codegen/generate_evals.py +279 -0
- package/scripts/codegen/generate_events.py +320 -0
- package/scripts/codegen/generate_frontend_tools.py +266 -0
- package/scripts/codegen/generate_guardrails.py +475 -0
- package/scripts/codegen/generate_mcp_servers.py +36 -9
- package/scripts/codegen/generate_memory.py +468 -0
- package/scripts/codegen/generate_models.py +22 -46
- package/scripts/codegen/generate_notifications.py +309 -0
- package/scripts/codegen/generate_outputs.py +267 -0
- package/scripts/codegen/generate_skills.py +108 -51
- package/scripts/codegen/generate_teams.py +922 -0
- package/scripts/codegen/generate_tools.py +346 -0
- package/scripts/codegen/generate_triggers.py +295 -0
- package/scripts/codegen/versioning.py +53 -0
- package/style/primer-primitives.css +1 -6
- package/lib/components/chat/components/base/ChatBase.js +0 -2242
- package/lib/components/chat/components/base/InputPrompt.d.ts +0 -42
- package/lib/components/chat/components/base/InputPrompt.js +0 -131
- package/lib/components/chat/components/display/index.d.ts +0 -6
- package/lib/components/chat/components/index.d.ts +0 -26
- package/lib/components/chat/components/index.js +0 -39
- package/lib/components/chat/extensions/A2UIExtension.d.ts +0 -87
- package/lib/components/chat/extensions/A2UIExtension.js +0 -312
- package/lib/components/chat/extensions/index.d.ts +0 -10
- package/lib/components/chat/index.d.ts +0 -61
- package/lib/components/chat/index.js +0 -76
- package/lib/components/chat/protocols/VercelAIAdapter.js +0 -315
- package/lib/components/chat/tools/index.d.ts +0 -8
- package/lib/components/chat/tools/index.js +0 -11
- package/lib/components/chat/types/index.d.ts +0 -12
- package/lib/components/chat/types/index.js +0 -17
- package/lib/components/sparklines/Sparklines.d.ts +0 -16
- package/lib/components/sparklines/Sparklines.js +0 -65
- package/lib/components/sparklines/SparklinesLine.d.ts +0 -8
- package/lib/components/sparklines/SparklinesLine.js +0 -37
- package/lib/components/sparklines/dataProcessing.d.ts +0 -25
- package/lib/components/sparklines/dataProcessing.js +0 -35
- package/lib/components/sparklines/index.d.ts +0 -4
- package/lib/components/sparklines/index.js +0 -7
- package/lib/components/sparklines/types.d.ts +0 -36
- package/lib/examples/stores/examplesStore.d.ts +0 -5
- package/lib/examples/stores/notebooks/Empty.ipynb.json +0 -33
- package/lib/examples/stores/notebooks/NotebookExample2.ipynb.json +0 -48
- package/lib/examples/stores/themeStore.d.ts +0 -33
- package/lib/examples/stores/themeStore.js +0 -38
- package/lib/hooks/useAgentRuntimes.d.ts +0 -350
- package/lib/hooks/useAgentRuntimes.js +0 -78
- package/lib/hooks/useKeyboardShortcuts.d.ts +0 -47
- package/lib/hooks/useKeyboardShortcuts.js +0 -153
- package/lib/hooks/useMobile.d.ts +0 -1
- package/lib/hooks/useMobile.js +0 -19
- package/lib/hooks/useNotebookAIAgent.d.ts +0 -8
- package/lib/hooks/useNotebookAIAgent.js +0 -73
- package/lib/renderers/a2ui/components/A2UIRenderer.d.ts +0 -7
- package/lib/renderers/a2ui/components/A2UIRenderer.js +0 -102
- package/lib/renderers/a2ui/components/SurfaceRenderer.d.ts +0 -7
- package/lib/renderers/a2ui/components/SurfaceRenderer.js +0 -101
- package/lib/renderers/a2ui/components/content/AudioPlayer.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/AudioPlayer.js +0 -38
- package/lib/renderers/a2ui/components/content/Divider.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/Divider.js +0 -35
- package/lib/renderers/a2ui/components/content/Icon.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/Icon.js +0 -110
- package/lib/renderers/a2ui/components/content/Image.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/Image.js +0 -61
- package/lib/renderers/a2ui/components/content/Text.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/Text.js +0 -64
- package/lib/renderers/a2ui/components/content/Video.d.ts +0 -9
- package/lib/renderers/a2ui/components/content/Video.js +0 -37
- package/lib/renderers/a2ui/components/content/index.d.ts +0 -6
- package/lib/renderers/a2ui/components/content/index.js +0 -25
- package/lib/renderers/a2ui/components/index.d.ts +0 -5
- package/lib/renderers/a2ui/components/index.js +0 -24
- package/lib/renderers/a2ui/components/interactive/Button.d.ts +0 -11
- package/lib/renderers/a2ui/components/interactive/Button.js +0 -71
- package/lib/renderers/a2ui/components/interactive/CheckBox.d.ts +0 -9
- package/lib/renderers/a2ui/components/interactive/CheckBox.js +0 -48
- package/lib/renderers/a2ui/components/interactive/DateTimeInput.d.ts +0 -9
- package/lib/renderers/a2ui/components/interactive/DateTimeInput.js +0 -62
- package/lib/renderers/a2ui/components/interactive/MultipleChoice.d.ts +0 -9
- package/lib/renderers/a2ui/components/interactive/MultipleChoice.js +0 -73
- package/lib/renderers/a2ui/components/interactive/Slider.d.ts +0 -9
- package/lib/renderers/a2ui/components/interactive/Slider.js +0 -53
- package/lib/renderers/a2ui/components/interactive/TextField.d.ts +0 -9
- package/lib/renderers/a2ui/components/interactive/TextField.js +0 -72
- package/lib/renderers/a2ui/components/interactive/index.d.ts +0 -6
- package/lib/renderers/a2ui/components/interactive/index.js +0 -25
- package/lib/renderers/a2ui/components/layout/Card.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/Card.js +0 -30
- package/lib/renderers/a2ui/components/layout/Column.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/Column.js +0 -65
- package/lib/renderers/a2ui/components/layout/List.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/List.js +0 -55
- package/lib/renderers/a2ui/components/layout/Modal.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/Modal.js +0 -58
- package/lib/renderers/a2ui/components/layout/Row.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/Row.js +0 -65
- package/lib/renderers/a2ui/components/layout/Tabs.d.ts +0 -11
- package/lib/renderers/a2ui/components/layout/Tabs.js +0 -48
- package/lib/renderers/a2ui/components/layout/index.d.ts +0 -6
- package/lib/renderers/a2ui/components/layout/index.js +0 -25
- package/lib/renderers/a2ui/context/A2UIContext.d.ts +0 -17
- package/lib/renderers/a2ui/context/A2UIContext.js +0 -54
- package/lib/renderers/a2ui/context/ThemeContext.d.ts +0 -20
- package/lib/renderers/a2ui/context/ThemeContext.js +0 -333
- package/lib/renderers/a2ui/hooks/useA2UI.d.ts +0 -36
- package/lib/renderers/a2ui/hooks/useA2UI.js +0 -62
- package/lib/renderers/a2ui/hooks/useDataBinding.d.ts +0 -8
- package/lib/renderers/a2ui/hooks/useDataBinding.js +0 -83
- package/lib/renderers/a2ui/index.d.ts +0 -9
- package/lib/renderers/a2ui/index.js +0 -28
- package/lib/renderers/a2ui/lib/utils.d.ts +0 -11
- package/lib/renderers/a2ui/lib/utils.js +0 -38
- package/lib/renderers/a2ui/types/index.d.ts +0 -17
- package/lib/runtime/index.d.ts +0 -38
- package/lib/runtime/index.js +0 -40
- package/lib/runtime/runtimeStore.d.ts +0 -76
- package/lib/runtime/runtimeStore.js +0 -184
- package/lib/runtime/types.d.ts +0 -84
- package/lib/runtime/useAgentConnection.d.ts +0 -45
- package/lib/runtime/useAgentConnection.js +0 -112
- package/lib/runtime/useAgentRuntime.d.ts +0 -93
- package/lib/runtime/useAgentRuntime.js +0 -125
- package/lib/specs/agents/codeai/agents.d.ts +0 -28
- package/lib/specs/agents/codeai/agents.js +0 -179
- package/lib/specs/agents/codeai/index.d.ts +0 -1
- package/lib/specs/agents/codemode-paper/agents.d.ts +0 -31
- package/lib/specs/agents/codemode-paper/agents.js +0 -378
- package/lib/specs/agents/codemode-paper/index.d.ts +0 -1
- package/lib/specs/agents/codemode-paper/index.js +0 -5
- package/lib/specs/agents/datalayer-ai/agents.d.ts +0 -31
- package/lib/specs/agents/datalayer-ai/agents.js +0 -352
- package/lib/specs/agents/datalayer-ai/index.d.ts +0 -1
- package/lib/specs/agents/datalayer-ai/index.js +0 -5
- package/lib/specs/agents/mocks/agents.d.ts +0 -43
- package/lib/specs/agents/mocks/agents.js +0 -2293
- package/lib/specs/agents/mocks/index.d.ts +0 -1
- package/lib/specs/agents/mocks/index.js +0 -5
- package/lib/state/index.d.ts +0 -1
- package/lib/state/index.js +0 -5
- package/lib/state/substates/AIAgentState.d.ts +0 -80
- package/lib/state/substates/AIAgentState.js +0 -108
- package/lib/state/substates/index.d.ts +0 -1
- package/lib/state/substates/index.js +0 -5
- package/lib/types/AIAgent.d.ts +0 -17
- package/lib/types/Types.d.ts +0 -217
- /package/lib/{components/chat → api}/handler.d.ts +0 -0
- /package/lib/{renderers/index.d.ts → api/utils.d.ts} +0 -0
- /package/lib/{renderers/index.js → api/utils.js} +0 -0
- /package/lib/{components/chat/components/elements → chat/display}/PoweredByTag.js +0 -0
- /package/lib/{components/chat/components → chat}/parts/DynamicToolPart.js +0 -0
- /package/lib/{components/chat/components → chat}/parts/ReasoningPart.d.ts +0 -0
- /package/lib/{components/chat/components → chat}/parts/TextPart.js +0 -0
- /package/lib/{components/chat/components → chat}/parts/ToolPart.d.ts +0 -0
- /package/lib/{components/chat/components → chat}/styles/streamdownStyles.js +0 -0
- /package/lib/{components/chat/components/elements → chat/tools}/ToolApprovalDialog.d.ts +0 -0
- /package/lib/{components/chat/components → context}/ContextDistribution.d.ts +0 -0
- /package/lib/{components/chat/components → context}/ContextDistribution.js +0 -0
- /package/lib/{components/chat/components → context}/ContextInspector.d.ts +0 -0
- /package/lib/{components/chat/components → context}/ContextPanel.d.ts +0 -0
- /package/lib/{components/chat/components → context}/ContextUsage.d.ts +0 -0
- /package/lib/{components/chat/components → context}/ContextUsage.js +0 -0
- /package/lib/examples/{JupyterCellExample.d.ts → CellSimpleExample.d.ts} +0 -0
- /package/lib/examples/{AgentRuntimeCustomExample.d.ts → ChatCustomExample.d.ts} +0 -0
- /package/lib/examples/{AgentRuntimeChatExample.d.ts → ChatExample.d.ts} +0 -0
- /package/lib/examples/{AgentRuntimeStandaloneExample.d.ts → ChatStandaloneExample.d.ts} +0 -0
- /package/lib/examples/{AgentRuntimeNotebookExample.d.ts → NotebookExample.d.ts} +0 -0
- /package/lib/examples/{AgentRuntimeNotebookSidebarExample.d.ts → NotebookSidebarExample.d.ts} +0 -0
- /package/lib/examples/{JupyterNotebookExample.d.ts → NotebookSimpleExample.d.ts} +0 -0
- /package/lib/examples/{stores → utils}/agents/earthquake-detector.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/agents/earthquake-detector.json +0 -0
- /package/lib/examples/{stores → utils}/agents/earthquake-detector.lexical.json +0 -0
- /package/lib/examples/{stores → utils}/agents/sales-forecaster.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/agents/sales-forecaster.json +0 -0
- /package/lib/examples/{stores → utils}/agents/sales-forecaster.lexical.json +0 -0
- /package/lib/examples/{stores → utils}/agents/social-post-generator.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/agents/social-post-generator.json +0 -0
- /package/lib/examples/{stores → utils}/agents/social-post-generator.lexical.json +0 -0
- /package/lib/examples/{stores → utils}/agents/stock-market.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/agents/stock-market.json +0 -0
- /package/lib/examples/{stores → utils}/agents/stock-market.lexical.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/IPyWidgetsExample.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/IPyWidgetsExampleWithState.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/Lite.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/Matplotlib.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/NotebookExample1.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/NotebookOutputs.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/NotebookToCExample.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/notebooks/OutputIPyWidgetsExample.d.ts +0 -0
- /package/lib/examples/{stores → utils}/notebooks/OutputIPyWidgetsExample.js +0 -0
- /package/lib/examples/{stores → utils}/notebooks/PyGWalker.ipynb.json +0 -0
- /package/lib/examples/{stores → utils}/themedProvider.d.ts +0 -0
- /package/lib/examples/{stores → utils}/themedProvider.js +0 -0
- /package/lib/{components/chat/inference → inference}/BaseInferenceProvider.js +0 -0
- /package/lib/{components → mcp}/McpServerManager.js +0 -0
- /package/lib/{components/chat/middleware → middleware}/MiddlewarePipeline.js +0 -0
- /package/lib/{components/chat/types/inference.js → types/a2a.js} +0 -0
- /package/lib/{components/chat/types/protocol.js → types/acp.js} +0 -0
- /package/lib/{components/sparklines/types.js → types/ag-ui.js} +0 -0
- /package/lib/{renderers/a2ui/types/index.js → types/agents-lifecycle.js} +0 -0
- /package/lib/types/{AIAgent.js → agentspecs.js} +0 -0
- /package/lib/types/{Types.js → chat.js} +0 -0
- /package/lib/{components/chat/types → types}/execution.js +0 -0
- /package/lib/{components/chat/types/extension.js → types/extensions.js} +0 -0
- /package/lib/{components/chat/types/message.js → types/messages.js} +0 -0
- /package/lib/{components/chat/types → types}/middleware.js +0 -0
- /package/lib/{components/chat/types/tool.js → types/tools.js} +0 -0
|
@@ -0,0 +1,1090 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
4
|
+
* Distributed under the terms of the Modified BSD License.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* AgentTriggersExample
|
|
8
|
+
*
|
|
9
|
+
* Demonstrates multiple trigger types for agents: cron schedules,
|
|
10
|
+
* webhook URLs, event-based listeners, and manual invocations.
|
|
11
|
+
*
|
|
12
|
+
* - Creates a cloud agent runtime (environment: 'ai-agents-env') via the Datalayer
|
|
13
|
+
* Runtimes API and deploys an agent via its sidecar
|
|
14
|
+
* - Shows a tabbed control panel to configure each trigger type
|
|
15
|
+
* - Lists recent trigger history and next scheduled run
|
|
16
|
+
*/
|
|
17
|
+
/// <reference types="vite/client" />
|
|
18
|
+
import { useEffect, useState, useCallback, useRef } from 'react';
|
|
19
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
20
|
+
import { Text, Button, Spinner, Heading, Label, TextInput, Flash, Timeline, Truncate, Tooltip, } from '@primer/react';
|
|
21
|
+
import { ClockIcon, SyncIcon, CheckCircleIcon, XCircleIcon, PlayIcon, SignOutIcon, GlobeIcon, ZapIcon, EyeIcon, EyeClosedIcon, TrashIcon, CopyIcon, } from '@primer/octicons-react';
|
|
22
|
+
import { Box } from '@datalayer/primer-addons';
|
|
23
|
+
import { ErrorView } from './components';
|
|
24
|
+
import { ThemedProvider } from './utils/themedProvider';
|
|
25
|
+
import { useSimpleAuthStore } from '@datalayer/core/lib/views/otel';
|
|
26
|
+
import { SignInSimple } from '@datalayer/core/lib/views/iam';
|
|
27
|
+
import { UserBadge } from '@datalayer/core/lib/views/profile';
|
|
28
|
+
import { Chat } from '../chat';
|
|
29
|
+
import { ToolApprovalBanner, ToolApprovalDialog, } from '../chat/tools';
|
|
30
|
+
import { useAgentEvents, useDeleteAgentEvent, useMarkEventRead, useMarkEventUnread, useAIAgentsWebSocket, } from '../hooks';
|
|
31
|
+
import { VercelAIAdapter } from '../protocols';
|
|
32
|
+
import { createUserMessage } from '../types/messages';
|
|
33
|
+
const queryClient = new QueryClient();
|
|
34
|
+
// ─── Constants ─────────────────────────────────────────────────────────────
|
|
35
|
+
const AGENT_NAME = 'trigger-demo-agent';
|
|
36
|
+
const AGENT_SPEC_ID = 'demo-one-trigger';
|
|
37
|
+
const APPROVAL_AGENT_NAME = 'trigger-approval-demo-agent';
|
|
38
|
+
const APPROVAL_AGENT_SPEC_ID = 'demo-one-trigger-approval';
|
|
39
|
+
const ONCE_TRIGGER_PROMPT = "List the user's top 3 public and top 3 private GitHub repositories, ranked by recent activity, and provide a brief summary of each.";
|
|
40
|
+
const ONCE_TRIGGER_APPROVAL_PROMPT = "Call runtime_sensitive_echo exactly once with message='Tool approval demo executed' and reason='audit'. Do not call any other tool.";
|
|
41
|
+
const DEFAULT_LOCAL_BASE_URL = import.meta.env.VITE_BASE_URL || 'http://localhost:8765';
|
|
42
|
+
const DEFAULT_CRON = '0 8 * * *'; // daily at 08:00 UTC
|
|
43
|
+
// ─── Inner component (rendered after auth) ─────────────────────────────────
|
|
44
|
+
const AgentTriggerInner = ({ onLogout, }) => {
|
|
45
|
+
const { token } = useSimpleAuthStore();
|
|
46
|
+
const [runtimeStatus, setRuntimeStatus] = useState('launching');
|
|
47
|
+
const [isReady, setIsReady] = useState(false);
|
|
48
|
+
const [hookError, setHookError] = useState(null);
|
|
49
|
+
const [agentId, setAgentId] = useState(AGENT_NAME);
|
|
50
|
+
const agentBaseUrl = DEFAULT_LOCAL_BASE_URL;
|
|
51
|
+
const chatAuthToken = token === null ? undefined : token;
|
|
52
|
+
// Cron state
|
|
53
|
+
const [cronExpr, setCronExpr] = useState(DEFAULT_CRON);
|
|
54
|
+
const [editCron, setEditCron] = useState(DEFAULT_CRON);
|
|
55
|
+
const [nextRun, setNextRun] = useState(null);
|
|
56
|
+
const [triggerHistory, setTriggerHistory] = useState([]);
|
|
57
|
+
const [isUpdating, setIsUpdating] = useState(false);
|
|
58
|
+
const [isTriggeringNow, setIsTriggeringNow] = useState(false);
|
|
59
|
+
const [triggerFlash, setTriggerFlash] = useState(null);
|
|
60
|
+
// Tab state
|
|
61
|
+
const [activeTab, setActiveTab] = useState('once');
|
|
62
|
+
// Once trigger state
|
|
63
|
+
const [isLaunchingOnce, setIsLaunchingOnce] = useState(false);
|
|
64
|
+
const [onceFlash, setOnceFlash] = useState(null);
|
|
65
|
+
const [lastOnceStartedAt, setLastOnceStartedAt] = useState(null);
|
|
66
|
+
const [hasTriggeredOnce, setHasTriggeredOnce] = useState(false);
|
|
67
|
+
const [streamedOnceOutput, setStreamedOnceOutput] = useState(null);
|
|
68
|
+
const [streamedOnceEndedAt, setStreamedOnceEndedAt] = useState(null);
|
|
69
|
+
// Webhook state
|
|
70
|
+
const [webhookUrl, setWebhookUrl] = useState(null);
|
|
71
|
+
const [webhookSecret, setWebhookSecret] = useState(null);
|
|
72
|
+
const [webhookEnabled, setWebhookEnabled] = useState(false);
|
|
73
|
+
// Sidebar messages state
|
|
74
|
+
const [sidebarMessages, setSidebarMessages] = useState([]);
|
|
75
|
+
const [sidebarMessagesError, setSidebarMessagesError] = useState(null);
|
|
76
|
+
// Event state
|
|
77
|
+
const [eventTopic, setEventTopic] = useState('');
|
|
78
|
+
const [eventFilter, setEventFilter] = useState('');
|
|
79
|
+
const [eventSubscribed, setEventSubscribed] = useState(false);
|
|
80
|
+
// Approval agent state
|
|
81
|
+
const [approvalAgentId, setApprovalAgentId] = useState(APPROVAL_AGENT_NAME);
|
|
82
|
+
const [approvalAgentReady, setApprovalAgentReady] = useState(false);
|
|
83
|
+
const [isLaunchingApproval, setIsLaunchingApproval] = useState(false);
|
|
84
|
+
const [approvalFlash, setApprovalFlash] = useState(null);
|
|
85
|
+
const [hasTriggeredApproval, setHasTriggeredApproval] = useState(false);
|
|
86
|
+
const [approvals, setApprovals] = useState([]);
|
|
87
|
+
const [approvalLoading, setApprovalLoading] = useState(null);
|
|
88
|
+
const [approvalError, setApprovalError] = useState(null);
|
|
89
|
+
const [activeApproval, setActiveApproval] = useState(null);
|
|
90
|
+
// Approval sidebar messages
|
|
91
|
+
const [approvalSidebarMessages, setApprovalSidebarMessages] = useState([]);
|
|
92
|
+
const approvalStreamRef = useRef(null);
|
|
93
|
+
// Events hooks
|
|
94
|
+
const eventsQuery = useAgentEvents(agentId);
|
|
95
|
+
const deleteEventMutation = useDeleteAgentEvent(agentId);
|
|
96
|
+
const markReadMutation = useMarkEventRead(agentId);
|
|
97
|
+
const markUnreadMutation = useMarkEventUnread(agentId);
|
|
98
|
+
const agentEvents = eventsQuery.data?.events ?? [];
|
|
99
|
+
// WebSocket for real-time event updates
|
|
100
|
+
useAIAgentsWebSocket({
|
|
101
|
+
channels: agentId ? [`agent:${agentId}`] : [],
|
|
102
|
+
});
|
|
103
|
+
// Authenticated fetch helper (for sidecar endpoints)
|
|
104
|
+
const authFetch = useCallback((url, opts = {}) => fetch(url, {
|
|
105
|
+
...opts,
|
|
106
|
+
headers: {
|
|
107
|
+
'Content-Type': 'application/json',
|
|
108
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
109
|
+
...(opts.headers ?? {}),
|
|
110
|
+
},
|
|
111
|
+
}), [token]);
|
|
112
|
+
// ── Create agent on local server ─────────────────────────────────────────
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
let isCancelled = false;
|
|
115
|
+
const createAgent = async () => {
|
|
116
|
+
setRuntimeStatus('launching');
|
|
117
|
+
setIsReady(false);
|
|
118
|
+
setHookError(null);
|
|
119
|
+
try {
|
|
120
|
+
const response = await authFetch(`${agentBaseUrl}/api/v1/agents`, {
|
|
121
|
+
method: 'POST',
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
name: AGENT_NAME,
|
|
124
|
+
description: 'Agent with cron, webhook, event, and manual triggers',
|
|
125
|
+
agent_library: 'pydantic-ai',
|
|
126
|
+
transport: 'vercel-ai',
|
|
127
|
+
agent_spec_id: AGENT_SPEC_ID,
|
|
128
|
+
tools: [],
|
|
129
|
+
}),
|
|
130
|
+
});
|
|
131
|
+
let resolvedAgentId = AGENT_NAME;
|
|
132
|
+
if (response.ok) {
|
|
133
|
+
const data = await response.json();
|
|
134
|
+
resolvedAgentId = data?.id || AGENT_NAME;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
const contentType = response.headers.get('content-type') || '';
|
|
138
|
+
let detail = '';
|
|
139
|
+
if (contentType.includes('application/json')) {
|
|
140
|
+
const data = await response.json().catch(() => null);
|
|
141
|
+
detail =
|
|
142
|
+
(typeof data?.detail === 'string' && data.detail) ||
|
|
143
|
+
(typeof data?.message === 'string' && data.message) ||
|
|
144
|
+
'';
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
detail = await response.text();
|
|
148
|
+
}
|
|
149
|
+
if (response.status === 409 || /already exists/i.test(detail || '')) {
|
|
150
|
+
// Agent already running — reuse it
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
throw new Error(detail || `Failed to create agent: ${response.status}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!isCancelled) {
|
|
157
|
+
setAgentId(resolvedAgentId);
|
|
158
|
+
setIsReady(true);
|
|
159
|
+
setRuntimeStatus('ready');
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (!isCancelled) {
|
|
164
|
+
setHookError(error instanceof Error ? error.message : 'Agent failed to start');
|
|
165
|
+
setRuntimeStatus('error');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
void createAgent();
|
|
170
|
+
return () => {
|
|
171
|
+
isCancelled = true;
|
|
172
|
+
};
|
|
173
|
+
}, [agentBaseUrl, authFetch]);
|
|
174
|
+
// ── Poll trigger metadata ─────────────────────────────────────────────
|
|
175
|
+
// TODO: enable once the ai-agents service exposes /trigger and
|
|
176
|
+
// /trigger/history endpoints on the platform API.
|
|
177
|
+
// Currently these endpoints don't exist on either the local
|
|
178
|
+
// agent-runtimes server or the ai-agents service.
|
|
179
|
+
const upsertSidebarMessage = useCallback((setMessages, message) => {
|
|
180
|
+
setMessages(prev => {
|
|
181
|
+
const idx = prev.findIndex(m => m.id === message.id);
|
|
182
|
+
if (idx >= 0) {
|
|
183
|
+
const next = [...prev];
|
|
184
|
+
next[idx] = { ...next[idx], ...message };
|
|
185
|
+
return next;
|
|
186
|
+
}
|
|
187
|
+
return [...prev, message];
|
|
188
|
+
});
|
|
189
|
+
}, []);
|
|
190
|
+
const streamRunMessages = useCallback(async (targetAgentId, prompt, setMessages, setError, options) => {
|
|
191
|
+
const endpoint = `${agentBaseUrl}/api/v1/vercel-ai/${encodeURIComponent(targetAgentId)}`;
|
|
192
|
+
if (options?.keepAliveForApproval && approvalStreamRef.current) {
|
|
193
|
+
approvalStreamRef.current.unsubscribe();
|
|
194
|
+
approvalStreamRef.current.adapter.disconnect();
|
|
195
|
+
approvalStreamRef.current = null;
|
|
196
|
+
}
|
|
197
|
+
const adapter = new VercelAIAdapter({
|
|
198
|
+
protocol: 'vercel-ai',
|
|
199
|
+
baseUrl: endpoint,
|
|
200
|
+
agentId: targetAgentId,
|
|
201
|
+
headers: token ? { Authorization: `Bearer ${token}` } : undefined,
|
|
202
|
+
});
|
|
203
|
+
let latestAssistantText = null;
|
|
204
|
+
let pendingApproval = false;
|
|
205
|
+
const unsubscribe = adapter.subscribe(event => {
|
|
206
|
+
if (event.type === 'message' && event.message) {
|
|
207
|
+
const msg = event.message;
|
|
208
|
+
const content = typeof msg.content === 'string'
|
|
209
|
+
? msg.content
|
|
210
|
+
: JSON.stringify(msg.content);
|
|
211
|
+
if (msg.role === 'assistant') {
|
|
212
|
+
latestAssistantText = content;
|
|
213
|
+
}
|
|
214
|
+
upsertSidebarMessage(setMessages, {
|
|
215
|
+
id: msg.id,
|
|
216
|
+
role: msg.role,
|
|
217
|
+
content,
|
|
218
|
+
createdAt: msg.createdAt?.toISOString(),
|
|
219
|
+
});
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (event.type === 'tool-call' && event.toolCall) {
|
|
223
|
+
upsertSidebarMessage(setMessages, {
|
|
224
|
+
id: `tool-call-${event.toolCall.toolCallId}`,
|
|
225
|
+
role: 'tool',
|
|
226
|
+
content: `${event.toolCall.toolName}(${JSON.stringify(event.toolCall.args)})`,
|
|
227
|
+
createdAt: event.timestamp.toISOString(),
|
|
228
|
+
});
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
if (event.type === 'tool-result' && event.toolResult) {
|
|
232
|
+
const resultObj = event.toolResult.result &&
|
|
233
|
+
typeof event.toolResult.result === 'object'
|
|
234
|
+
? event.toolResult.result
|
|
235
|
+
: undefined;
|
|
236
|
+
if (resultObj?.pending_approval === true) {
|
|
237
|
+
pendingApproval = true;
|
|
238
|
+
}
|
|
239
|
+
upsertSidebarMessage(setMessages, {
|
|
240
|
+
id: `tool-result-${event.toolResult.toolCallId}`,
|
|
241
|
+
role: 'tool',
|
|
242
|
+
content: JSON.stringify(event.toolResult.result),
|
|
243
|
+
createdAt: event.timestamp.toISOString(),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
try {
|
|
248
|
+
setError(null);
|
|
249
|
+
await adapter.connect();
|
|
250
|
+
await adapter.sendMessage(createUserMessage(prompt));
|
|
251
|
+
return { finalAssistantText: latestAssistantText, pendingApproval };
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
setError(error instanceof Error ? error.message : 'Streaming request failed');
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
if (options?.keepAliveForApproval && pendingApproval) {
|
|
259
|
+
approvalStreamRef.current = { adapter, unsubscribe };
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
unsubscribe();
|
|
263
|
+
adapter.disconnect();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}, [agentBaseUrl, token, upsertSidebarMessage]);
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
return () => {
|
|
269
|
+
if (approvalStreamRef.current) {
|
|
270
|
+
approvalStreamRef.current.unsubscribe();
|
|
271
|
+
approvalStreamRef.current.adapter.disconnect();
|
|
272
|
+
approvalStreamRef.current = null;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
}, []);
|
|
276
|
+
// ── Create approval agent on local server ────────────────────────────────
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (!isReady)
|
|
279
|
+
return;
|
|
280
|
+
let isCancelled = false;
|
|
281
|
+
const createApprovalAgent = async () => {
|
|
282
|
+
try {
|
|
283
|
+
const response = await authFetch(`${agentBaseUrl}/api/v1/agents`, {
|
|
284
|
+
method: 'POST',
|
|
285
|
+
body: JSON.stringify({
|
|
286
|
+
name: APPROVAL_AGENT_NAME,
|
|
287
|
+
description: 'Agent with once trigger and tool approval',
|
|
288
|
+
agent_library: 'pydantic-ai',
|
|
289
|
+
transport: 'vercel-ai',
|
|
290
|
+
agent_spec_id: APPROVAL_AGENT_SPEC_ID,
|
|
291
|
+
tools: ['runtime-sensitive-echo'],
|
|
292
|
+
}),
|
|
293
|
+
});
|
|
294
|
+
let resolvedId = APPROVAL_AGENT_NAME;
|
|
295
|
+
if (response.ok) {
|
|
296
|
+
const data = await response.json();
|
|
297
|
+
resolvedId = data?.id || APPROVAL_AGENT_NAME;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
const contentType = response.headers.get('content-type') || '';
|
|
301
|
+
let detail = '';
|
|
302
|
+
if (contentType.includes('application/json')) {
|
|
303
|
+
const data = await response.json().catch(() => null);
|
|
304
|
+
detail = data?.detail || data?.message || '';
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
detail = await response.text();
|
|
308
|
+
}
|
|
309
|
+
if (response.status === 409 || /already exists/i.test(detail || '')) {
|
|
310
|
+
// Already running — reuse
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
console.warn('Failed to create approval agent:', detail);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!isCancelled) {
|
|
318
|
+
setApprovalAgentId(resolvedId);
|
|
319
|
+
setApprovalAgentReady(true);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch (error) {
|
|
323
|
+
console.warn('Approval agent creation failed:', error);
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
void createApprovalAgent();
|
|
327
|
+
return () => { isCancelled = true; };
|
|
328
|
+
}, [isReady, agentBaseUrl, authFetch]);
|
|
329
|
+
// ── Poll tool approvals ─────────────────────────────────────────────────
|
|
330
|
+
const pollApprovals = useCallback(async () => {
|
|
331
|
+
if (!approvalAgentReady)
|
|
332
|
+
return;
|
|
333
|
+
try {
|
|
334
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/tool-approvals`);
|
|
335
|
+
if (!res.ok)
|
|
336
|
+
return;
|
|
337
|
+
const data = await res.json();
|
|
338
|
+
const all = Array.isArray(data) ? data : (data.approvals ?? data.requests ?? []);
|
|
339
|
+
const pending = all.filter((a) => a.status === 'pending' && (!a.agent_id || a.agent_id === approvalAgentId));
|
|
340
|
+
setApprovals(pending);
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
// Non-fatal
|
|
344
|
+
}
|
|
345
|
+
}, [approvalAgentReady, agentBaseUrl, approvalAgentId, authFetch]);
|
|
346
|
+
useEffect(() => {
|
|
347
|
+
if (!hasTriggeredApproval)
|
|
348
|
+
return;
|
|
349
|
+
void pollApprovals();
|
|
350
|
+
const interval = setInterval(pollApprovals, 2000);
|
|
351
|
+
return () => clearInterval(interval);
|
|
352
|
+
}, [hasTriggeredApproval, pollApprovals]);
|
|
353
|
+
// Approval sidebar messages are populated from live Vercel stream events.
|
|
354
|
+
// ── Approve / Reject handlers ───────────────────────────────────────────
|
|
355
|
+
const handleApprove = useCallback(async (requestId) => {
|
|
356
|
+
setApprovalLoading(requestId);
|
|
357
|
+
setApprovalError(null);
|
|
358
|
+
try {
|
|
359
|
+
const approval = approvals.find(a => a.id === requestId);
|
|
360
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/tool-approvals/${requestId}/approve`, { method: 'POST', body: JSON.stringify({}) });
|
|
361
|
+
if (!res.ok) {
|
|
362
|
+
throw new Error(`Approve failed (${res.status})`);
|
|
363
|
+
}
|
|
364
|
+
if (approval?.tool_call_id && approvalStreamRef.current) {
|
|
365
|
+
await approvalStreamRef.current.adapter.sendToolResult(approval.tool_call_id, {
|
|
366
|
+
toolCallId: approval.tool_call_id,
|
|
367
|
+
success: true,
|
|
368
|
+
result: {
|
|
369
|
+
approved: true,
|
|
370
|
+
approvalId: requestId,
|
|
371
|
+
message: 'Approved from trigger panel',
|
|
372
|
+
},
|
|
373
|
+
});
|
|
374
|
+
approvalStreamRef.current.unsubscribe();
|
|
375
|
+
approvalStreamRef.current.adapter.disconnect();
|
|
376
|
+
approvalStreamRef.current = null;
|
|
377
|
+
}
|
|
378
|
+
setApprovals(prev => prev.filter(a => a.id !== requestId));
|
|
379
|
+
void pollApprovals();
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
setApprovalError(error instanceof Error ? error.message : 'Failed to approve');
|
|
383
|
+
}
|
|
384
|
+
finally {
|
|
385
|
+
setApprovalLoading(null);
|
|
386
|
+
}
|
|
387
|
+
}, [agentBaseUrl, authFetch, pollApprovals, approvals]);
|
|
388
|
+
const handleReject = useCallback(async (requestId, note) => {
|
|
389
|
+
setApprovalLoading(requestId);
|
|
390
|
+
setApprovalError(null);
|
|
391
|
+
try {
|
|
392
|
+
const approval = approvals.find(a => a.id === requestId);
|
|
393
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/tool-approvals/${requestId}/reject`, { method: 'POST', body: JSON.stringify(note ? { note } : {}) });
|
|
394
|
+
if (!res.ok) {
|
|
395
|
+
throw new Error(`Reject failed (${res.status})`);
|
|
396
|
+
}
|
|
397
|
+
if (approval?.tool_call_id && approvalStreamRef.current) {
|
|
398
|
+
await approvalStreamRef.current.adapter.sendToolResult(approval.tool_call_id, {
|
|
399
|
+
toolCallId: approval.tool_call_id,
|
|
400
|
+
success: true,
|
|
401
|
+
result: {
|
|
402
|
+
approved: false,
|
|
403
|
+
approvalId: requestId,
|
|
404
|
+
message: note || 'Rejected from trigger panel',
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
approvalStreamRef.current.unsubscribe();
|
|
408
|
+
approvalStreamRef.current.adapter.disconnect();
|
|
409
|
+
approvalStreamRef.current = null;
|
|
410
|
+
}
|
|
411
|
+
setApprovals(prev => prev.filter(a => a.id !== requestId));
|
|
412
|
+
void pollApprovals();
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
setApprovalError(error instanceof Error ? error.message : 'Failed to reject');
|
|
416
|
+
}
|
|
417
|
+
finally {
|
|
418
|
+
setApprovalLoading(null);
|
|
419
|
+
}
|
|
420
|
+
}, [agentBaseUrl, authFetch, pollApprovals, approvals]);
|
|
421
|
+
// ── Launch once trigger with approval ────────────────────────────────────
|
|
422
|
+
const handleLaunchOnceApproval = useCallback(async () => {
|
|
423
|
+
if (!agentBaseUrl || !approvalAgentReady)
|
|
424
|
+
return;
|
|
425
|
+
setIsLaunchingApproval(true);
|
|
426
|
+
setApprovalFlash(null);
|
|
427
|
+
setApprovalSidebarMessages([]);
|
|
428
|
+
setSidebarMessagesError(null);
|
|
429
|
+
setHasTriggeredApproval(true);
|
|
430
|
+
const runId = `once-approval-${Date.now()}`;
|
|
431
|
+
const startTime = new Date().toISOString();
|
|
432
|
+
setTriggerHistory(prev => [
|
|
433
|
+
{
|
|
434
|
+
id: runId,
|
|
435
|
+
timestamp: startTime,
|
|
436
|
+
status: 'running',
|
|
437
|
+
source: 'once',
|
|
438
|
+
},
|
|
439
|
+
...prev,
|
|
440
|
+
]);
|
|
441
|
+
try {
|
|
442
|
+
setApprovalFlash('Once trigger with approval launched — waiting for tool approval.');
|
|
443
|
+
const streamResult = await streamRunMessages(approvalAgentId, ONCE_TRIGGER_APPROVAL_PROMPT, setApprovalSidebarMessages, setSidebarMessagesError, { keepAliveForApproval: true });
|
|
444
|
+
if (!streamResult.pendingApproval && approvalStreamRef.current) {
|
|
445
|
+
approvalStreamRef.current.unsubscribe();
|
|
446
|
+
approvalStreamRef.current.adapter.disconnect();
|
|
447
|
+
approvalStreamRef.current = null;
|
|
448
|
+
}
|
|
449
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId
|
|
450
|
+
? {
|
|
451
|
+
...r,
|
|
452
|
+
status: 'success',
|
|
453
|
+
duration_ms: Date.now() - new Date(startTime).getTime(),
|
|
454
|
+
}
|
|
455
|
+
: r));
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
setApprovalFlash('Network error');
|
|
459
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId ? { ...r, status: 'failure' } : r));
|
|
460
|
+
}
|
|
461
|
+
finally {
|
|
462
|
+
setIsLaunchingApproval(false);
|
|
463
|
+
}
|
|
464
|
+
}, [
|
|
465
|
+
agentBaseUrl,
|
|
466
|
+
approvalAgentReady,
|
|
467
|
+
approvalAgentId,
|
|
468
|
+
streamRunMessages,
|
|
469
|
+
]);
|
|
470
|
+
// ── Pending approvals for banner/dialog ──────────────────────────────────
|
|
471
|
+
const pendingApprovals = approvals.map(req => ({
|
|
472
|
+
id: req.id,
|
|
473
|
+
toolName: req.tool_name,
|
|
474
|
+
toolDescription: req.note,
|
|
475
|
+
args: req.tool_args ?? {},
|
|
476
|
+
agentId: approvalAgentId,
|
|
477
|
+
requestedAt: req.created_at ?? new Date().toISOString(),
|
|
478
|
+
}));
|
|
479
|
+
// ── Update cron ──────────────────────────────────────────────────────────
|
|
480
|
+
const handleUpdateCron = useCallback(async () => {
|
|
481
|
+
if (!agentBaseUrl || !editCron.trim())
|
|
482
|
+
return;
|
|
483
|
+
setIsUpdating(true);
|
|
484
|
+
try {
|
|
485
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/trigger`, {
|
|
486
|
+
method: 'PUT',
|
|
487
|
+
body: JSON.stringify({ cron: editCron.trim() }),
|
|
488
|
+
});
|
|
489
|
+
if (res.ok) {
|
|
490
|
+
const d = await res.json();
|
|
491
|
+
setCronExpr(d.cron ?? editCron.trim());
|
|
492
|
+
if (d.next_run)
|
|
493
|
+
setNextRun(d.next_run);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch {
|
|
497
|
+
/* ok */
|
|
498
|
+
}
|
|
499
|
+
finally {
|
|
500
|
+
setIsUpdating(false);
|
|
501
|
+
}
|
|
502
|
+
}, [agentBaseUrl, agentId, editCron, authFetch]);
|
|
503
|
+
// ── Manual trigger ───────────────────────────────────────────────────────
|
|
504
|
+
const handleTriggerNow = useCallback(async () => {
|
|
505
|
+
if (!agentBaseUrl)
|
|
506
|
+
return;
|
|
507
|
+
setIsTriggeringNow(true);
|
|
508
|
+
setTriggerFlash(null);
|
|
509
|
+
const runId = `manual-${Date.now()}`;
|
|
510
|
+
const startTime = new Date().toISOString();
|
|
511
|
+
setTriggerHistory(prev => [
|
|
512
|
+
{
|
|
513
|
+
id: runId,
|
|
514
|
+
timestamp: startTime,
|
|
515
|
+
status: 'running',
|
|
516
|
+
source: 'manual',
|
|
517
|
+
},
|
|
518
|
+
...prev,
|
|
519
|
+
]);
|
|
520
|
+
try {
|
|
521
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/trigger/run`, { method: 'POST', body: JSON.stringify({ source: 'manual' }) });
|
|
522
|
+
if (res.ok) {
|
|
523
|
+
setTriggerFlash('Trigger fired successfully');
|
|
524
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId
|
|
525
|
+
? {
|
|
526
|
+
...r,
|
|
527
|
+
status: 'success',
|
|
528
|
+
duration_ms: Date.now() - new Date(startTime).getTime(),
|
|
529
|
+
}
|
|
530
|
+
: r));
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
setTriggerFlash(`Trigger failed (${res.status})`);
|
|
534
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId ? { ...r, status: 'failure' } : r));
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
setTriggerFlash('Network error');
|
|
539
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId ? { ...r, status: 'failure' } : r));
|
|
540
|
+
}
|
|
541
|
+
finally {
|
|
542
|
+
setIsTriggeringNow(false);
|
|
543
|
+
}
|
|
544
|
+
}, [agentBaseUrl, agentId, authFetch]);
|
|
545
|
+
// ── Webhook management ─────────────────────────────────────────────────
|
|
546
|
+
const handleGenerateWebhook = useCallback(async () => {
|
|
547
|
+
if (!agentBaseUrl)
|
|
548
|
+
return;
|
|
549
|
+
setIsUpdating(true);
|
|
550
|
+
try {
|
|
551
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/trigger/webhook`, { method: 'POST' });
|
|
552
|
+
if (res.ok) {
|
|
553
|
+
const d = await res.json();
|
|
554
|
+
setWebhookUrl(d.url ?? null);
|
|
555
|
+
setWebhookSecret(d.secret ?? null);
|
|
556
|
+
setWebhookEnabled(true);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
catch {
|
|
560
|
+
/* ok */
|
|
561
|
+
}
|
|
562
|
+
finally {
|
|
563
|
+
setIsUpdating(false);
|
|
564
|
+
}
|
|
565
|
+
}, [agentBaseUrl, agentId, authFetch]);
|
|
566
|
+
const handleToggleWebhook = useCallback(async () => {
|
|
567
|
+
if (!agentBaseUrl)
|
|
568
|
+
return;
|
|
569
|
+
try {
|
|
570
|
+
await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/trigger/webhook`, {
|
|
571
|
+
method: 'PATCH',
|
|
572
|
+
body: JSON.stringify({ enabled: !webhookEnabled }),
|
|
573
|
+
});
|
|
574
|
+
setWebhookEnabled(prev => !prev);
|
|
575
|
+
}
|
|
576
|
+
catch {
|
|
577
|
+
/* ok */
|
|
578
|
+
}
|
|
579
|
+
}, [agentBaseUrl, agentId, webhookEnabled, authFetch]);
|
|
580
|
+
// ── Event subscription ─────────────────────────────────────────────────
|
|
581
|
+
const handleSubscribeEvent = useCallback(async () => {
|
|
582
|
+
if (!agentBaseUrl || !eventTopic.trim())
|
|
583
|
+
return;
|
|
584
|
+
setIsUpdating(true);
|
|
585
|
+
try {
|
|
586
|
+
const res = await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/trigger/event`, {
|
|
587
|
+
method: 'POST',
|
|
588
|
+
body: JSON.stringify({
|
|
589
|
+
topic: eventTopic.trim(),
|
|
590
|
+
filter: eventFilter.trim() || undefined,
|
|
591
|
+
}),
|
|
592
|
+
});
|
|
593
|
+
if (res.ok) {
|
|
594
|
+
setEventSubscribed(true);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
catch {
|
|
598
|
+
/* ok */
|
|
599
|
+
}
|
|
600
|
+
finally {
|
|
601
|
+
setIsUpdating(false);
|
|
602
|
+
}
|
|
603
|
+
}, [agentBaseUrl, agentId, eventTopic, eventFilter, authFetch]);
|
|
604
|
+
// ── Launch once trigger ──────────────────────────────────────────────────
|
|
605
|
+
const handleLaunchOnce = useCallback(async () => {
|
|
606
|
+
if (!agentBaseUrl)
|
|
607
|
+
return;
|
|
608
|
+
setIsLaunchingOnce(true);
|
|
609
|
+
setOnceFlash(null);
|
|
610
|
+
setStreamedOnceOutput(null);
|
|
611
|
+
setStreamedOnceEndedAt(null);
|
|
612
|
+
setSidebarMessages([]);
|
|
613
|
+
setSidebarMessagesError(null);
|
|
614
|
+
const runId = `once-${Date.now()}`;
|
|
615
|
+
const startTime = new Date().toISOString();
|
|
616
|
+
setLastOnceStartedAt(startTime);
|
|
617
|
+
setHasTriggeredOnce(true);
|
|
618
|
+
setTriggerHistory(prev => [
|
|
619
|
+
{
|
|
620
|
+
id: runId,
|
|
621
|
+
timestamp: startTime,
|
|
622
|
+
status: 'running',
|
|
623
|
+
source: 'once',
|
|
624
|
+
},
|
|
625
|
+
...prev,
|
|
626
|
+
]);
|
|
627
|
+
try {
|
|
628
|
+
setOnceFlash('Once trigger launched — streaming live output.');
|
|
629
|
+
const streamResult = await streamRunMessages(agentId, ONCE_TRIGGER_PROMPT, setSidebarMessages, setSidebarMessagesError);
|
|
630
|
+
setStreamedOnceOutput(streamResult.finalAssistantText);
|
|
631
|
+
setStreamedOnceEndedAt(new Date().toISOString());
|
|
632
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId
|
|
633
|
+
? {
|
|
634
|
+
...r,
|
|
635
|
+
status: 'success',
|
|
636
|
+
duration_ms: Date.now() - new Date(startTime).getTime(),
|
|
637
|
+
}
|
|
638
|
+
: r));
|
|
639
|
+
}
|
|
640
|
+
catch {
|
|
641
|
+
setOnceFlash('Network error');
|
|
642
|
+
setTriggerHistory(prev => prev.map(r => r.id === runId ? { ...r, status: 'failure' } : r));
|
|
643
|
+
}
|
|
644
|
+
finally {
|
|
645
|
+
setIsLaunchingOnce(false);
|
|
646
|
+
}
|
|
647
|
+
}, [agentBaseUrl, agentId, streamRunMessages]);
|
|
648
|
+
// ── Loading / Error ──────────────────────────────────────────────────────
|
|
649
|
+
if (!isReady && runtimeStatus !== 'error') {
|
|
650
|
+
return (_jsxs(Box, { sx: {
|
|
651
|
+
display: 'flex',
|
|
652
|
+
flexDirection: 'column',
|
|
653
|
+
alignItems: 'center',
|
|
654
|
+
justifyContent: 'center',
|
|
655
|
+
height: '100vh',
|
|
656
|
+
gap: 3,
|
|
657
|
+
}, children: [_jsx(Spinner, { size: "large" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: runtimeStatus === 'launching'
|
|
658
|
+
? 'Launching runtime for trigger agent…'
|
|
659
|
+
: 'Creating trigger demo agent…' })] }));
|
|
660
|
+
}
|
|
661
|
+
if (runtimeStatus === 'error' || hookError) {
|
|
662
|
+
return _jsx(ErrorView, { error: hookError, onLogout: onLogout });
|
|
663
|
+
}
|
|
664
|
+
const triggerRunCurl = `curl -N -X POST '${agentBaseUrl}/api/v1/vercel-ai/${agentId}' -H 'Content-Type: application/json' -H 'Accept: text/event-stream'${token ? " -H 'Authorization: Bearer <TOKEN>'" : ''} --data '{"messages":[{"role":"user","parts":[{"type":"text","text":"${ONCE_TRIGGER_PROMPT.replace(/"/g, '\\"')}"}]}],"trigger":"submit-message","sdkVersion":6}'`;
|
|
665
|
+
return (_jsxs(Box, { sx: {
|
|
666
|
+
height: 'calc(100vh - 60px)',
|
|
667
|
+
display: 'flex',
|
|
668
|
+
flexDirection: 'column',
|
|
669
|
+
}, children: [_jsxs(Box, { sx: {
|
|
670
|
+
display: 'flex',
|
|
671
|
+
alignItems: 'center',
|
|
672
|
+
gap: 2,
|
|
673
|
+
px: 3,
|
|
674
|
+
py: 2,
|
|
675
|
+
borderBottom: '1px solid',
|
|
676
|
+
borderColor: 'border.default',
|
|
677
|
+
flexShrink: 0,
|
|
678
|
+
}, children: [_jsx(ClockIcon, { size: 16 }), _jsxs(Heading, { as: "h3", sx: { fontSize: 2, flex: 1 }, children: ["Triggers \u2014 ", agentId] }), token && _jsx(UserBadge, { token: token, variant: "small" }), _jsx(Button, { size: "small", variant: "invisible", onClick: onLogout, leadingVisual: SignOutIcon, sx: { color: 'fg.muted' }, children: "Sign out" })] }), _jsx(ToolApprovalBanner, { pendingApprovals: pendingApprovals, onReview: approval => {
|
|
679
|
+
const req = approvals.find(a => a.id === approval.id) || null;
|
|
680
|
+
setActiveApproval(req);
|
|
681
|
+
}, onApproveAll: async () => {
|
|
682
|
+
for (const a of approvals) {
|
|
683
|
+
await handleApprove(a.id);
|
|
684
|
+
}
|
|
685
|
+
} }), _jsx(ToolApprovalDialog, { isOpen: !!activeApproval, toolName: activeApproval?.tool_name ?? '', toolDescription: activeApproval?.note, args: activeApproval?.tool_args ?? {}, onApprove: async () => {
|
|
686
|
+
if (activeApproval) {
|
|
687
|
+
await handleApprove(activeApproval.id);
|
|
688
|
+
setActiveApproval(null);
|
|
689
|
+
}
|
|
690
|
+
}, onDeny: async () => {
|
|
691
|
+
if (activeApproval) {
|
|
692
|
+
await handleReject(activeApproval.id, 'Rejected from dialog');
|
|
693
|
+
setActiveApproval(null);
|
|
694
|
+
}
|
|
695
|
+
}, onClose: () => setActiveApproval(null) }), approvalError && (_jsx(Box, { sx: { px: 3, py: 1 }, children: _jsx(Text, { sx: { color: 'danger.fg', fontSize: 0 }, children: approvalError }) })), _jsxs(Box, { sx: { flex: 1, minHeight: 0, display: 'flex' }, children: [_jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: _jsx(Chat, { protocol: "vercel-ai", baseUrl: agentBaseUrl, agentId: agentId, authToken: chatAuthToken, title: "Trigger Agent", description: `View-only trigger output. Cron: ${cronExpr} | Webhook: ${webhookEnabled ? 'on' : 'off'} | Event: ${eventSubscribed ? eventTopic : 'none'}`, showHeader: true, autoFocus: false, height: "100%", runtimeId: agentId, showInput: false, showModelSelector: false, showToolsMenu: false, showSkillsMenu: false }) }), _jsxs(Box, { sx: {
|
|
696
|
+
width: 380,
|
|
697
|
+
borderLeft: '1px solid',
|
|
698
|
+
borderColor: 'border.default',
|
|
699
|
+
display: 'flex',
|
|
700
|
+
flexDirection: 'column',
|
|
701
|
+
overflow: 'auto',
|
|
702
|
+
}, children: [_jsx(Box, { sx: {
|
|
703
|
+
display: 'flex',
|
|
704
|
+
borderBottom: '1px solid',
|
|
705
|
+
borderColor: 'border.default',
|
|
706
|
+
flexShrink: 0,
|
|
707
|
+
}, children: [
|
|
708
|
+
{ key: 'once', icon: ZapIcon, label: 'Once' },
|
|
709
|
+
{ key: 'cron', icon: ClockIcon, label: 'Cron' },
|
|
710
|
+
{
|
|
711
|
+
key: 'webhook',
|
|
712
|
+
icon: GlobeIcon,
|
|
713
|
+
label: 'Webhook',
|
|
714
|
+
},
|
|
715
|
+
{ key: 'event', icon: ZapIcon, label: 'Event' },
|
|
716
|
+
{
|
|
717
|
+
key: 'manual',
|
|
718
|
+
icon: PlayIcon,
|
|
719
|
+
label: 'Manual',
|
|
720
|
+
},
|
|
721
|
+
].map(t => (_jsx(Button, { size: "small", variant: "invisible", leadingVisual: t.icon, onClick: () => setActiveTab(t.key), sx: {
|
|
722
|
+
flex: 1,
|
|
723
|
+
borderRadius: 0,
|
|
724
|
+
borderBottom: activeTab === t.key ? '2px solid' : '2px solid transparent',
|
|
725
|
+
borderColor: activeTab === t.key ? 'accent.fg' : 'transparent',
|
|
726
|
+
fontWeight: activeTab === t.key ? 'bold' : 'normal',
|
|
727
|
+
}, children: t.label }, t.key))) }), activeTab === 'once' && (_jsxs(Box, { sx: {
|
|
728
|
+
p: 3,
|
|
729
|
+
borderBottom: '1px solid',
|
|
730
|
+
borderColor: 'border.default',
|
|
731
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2 }, children: [_jsx(ZapIcon, { size: 16 }), _jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Once Trigger" })] }), _jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 3 }, children: "Launch a single streaming run for the once-trigger prompt and watch tool calls, tool results, and assistant text update in real time." }), _jsxs(Box, { sx: {
|
|
732
|
+
bg: 'canvas.subtle',
|
|
733
|
+
border: '1px solid',
|
|
734
|
+
borderColor: 'border.default',
|
|
735
|
+
borderRadius: 2,
|
|
736
|
+
p: 2,
|
|
737
|
+
mb: 2,
|
|
738
|
+
display: 'grid',
|
|
739
|
+
gap: 1,
|
|
740
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 0 }, children: [_jsx("strong", { children: "Agent ID:" }), " ", agentId] }), _jsxs(Text, { sx: { fontSize: 0 }, children: [_jsx("strong", { children: "Base URL:" }), " ", agentBaseUrl] }), lastOnceStartedAt && (_jsxs(Text, { sx: { fontSize: 0 }, children: [_jsx("strong", { children: "Last once launch:" }), ' ', new Date(lastOnceStartedAt).toLocaleString()] }))] }), _jsx(Button, { size: "small", variant: "primary", leadingVisual: ZapIcon, onClick: handleLaunchOnce, disabled: isLaunchingOnce, sx: { width: '100%' }, children: isLaunchingOnce ? 'Launching…' : 'Launch Once' }), _jsx(Button, { size: "small", variant: "danger", leadingVisual: ZapIcon, onClick: handleLaunchOnceApproval, disabled: isLaunchingApproval || !approvalAgentReady, sx: { width: '100%', mt: 2 }, children: isLaunchingApproval ? 'Launching…' : 'Launch Once with Approval' }), onceFlash && (_jsx(Flash, { variant: onceFlash.includes('launched') ? 'success' : 'danger', sx: { mt: 2, fontSize: 0 }, children: onceFlash })), approvalFlash && (_jsx(Flash, { variant: approvalFlash.includes('launched') ? 'success' : 'danger', sx: { mt: 2, fontSize: 0 }, children: approvalFlash })), hasTriggeredOnce && (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: "Generated Output" }), (() => {
|
|
741
|
+
const outputEvent = lastOnceStartedAt
|
|
742
|
+
? [...agentEvents]
|
|
743
|
+
.filter(e => e.kind === 'agent-output' &&
|
|
744
|
+
new Date(e.created_at).getTime() >=
|
|
745
|
+
new Date(lastOnceStartedAt).getTime() - 5000)
|
|
746
|
+
.sort((a, b) => new Date(b.created_at).getTime() -
|
|
747
|
+
new Date(a.created_at).getTime())[0]
|
|
748
|
+
: undefined;
|
|
749
|
+
const hasStreamFallback = !outputEvent && !isLaunchingOnce && streamedOnceOutput !== null;
|
|
750
|
+
if (!outputEvent && !hasStreamFallback) {
|
|
751
|
+
return (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 2 }, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "Waiting for agent output\u2026" })] }));
|
|
752
|
+
}
|
|
753
|
+
const p = outputEvent?.payload;
|
|
754
|
+
const outputText = outputEvent
|
|
755
|
+
? (p?.outputs ? String(p.outputs) : '')
|
|
756
|
+
: (streamedOnceOutput ?? '');
|
|
757
|
+
const exitStatus = outputEvent ? p?.exit_status : 'completed';
|
|
758
|
+
const durationMs = outputEvent
|
|
759
|
+
? p?.duration_ms
|
|
760
|
+
: (lastOnceStartedAt && streamedOnceEndedAt
|
|
761
|
+
? new Date(streamedOnceEndedAt).getTime() -
|
|
762
|
+
new Date(lastOnceStartedAt).getTime()
|
|
763
|
+
: undefined);
|
|
764
|
+
const endedAt = outputEvent ? p?.ended_at : streamedOnceEndedAt;
|
|
765
|
+
return (_jsxs(Box, { sx: {
|
|
766
|
+
mb: 2,
|
|
767
|
+
border: '1px solid',
|
|
768
|
+
borderColor: exitStatus === 'error'
|
|
769
|
+
? 'danger.muted'
|
|
770
|
+
: 'success.muted',
|
|
771
|
+
borderRadius: 2,
|
|
772
|
+
overflow: 'hidden',
|
|
773
|
+
}, children: [_jsxs(Box, { sx: {
|
|
774
|
+
display: 'flex',
|
|
775
|
+
alignItems: 'center',
|
|
776
|
+
gap: 1,
|
|
777
|
+
px: 2,
|
|
778
|
+
py: 1,
|
|
779
|
+
bg: exitStatus === 'error'
|
|
780
|
+
? 'danger.subtle'
|
|
781
|
+
: 'success.subtle',
|
|
782
|
+
borderBottom: '1px solid',
|
|
783
|
+
borderColor: exitStatus === 'error'
|
|
784
|
+
? 'danger.muted'
|
|
785
|
+
: 'success.muted',
|
|
786
|
+
}, children: [_jsx(Label, { variant: exitStatus === 'error' ? 'danger' : 'success', size: "small", children: exitStatus ?? 'completed' }), durationMs != null && (_jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [(Number(durationMs) / 1000).toFixed(1), "s"] })), endedAt && (_jsx(Text, { sx: {
|
|
787
|
+
fontSize: 0,
|
|
788
|
+
color: 'fg.muted',
|
|
789
|
+
ml: 'auto',
|
|
790
|
+
whiteSpace: 'nowrap',
|
|
791
|
+
}, children: new Date(endedAt).toLocaleString() })), _jsx(Button, { size: "small", variant: "invisible", sx: { p: 1 }, onClick: () => navigator.clipboard.writeText(outputText), children: _jsx(CopyIcon, { size: 12 }) })] }), _jsx(Box, { sx: {
|
|
792
|
+
p: 2,
|
|
793
|
+
bg: 'canvas.default',
|
|
794
|
+
maxHeight: 300,
|
|
795
|
+
overflow: 'auto',
|
|
796
|
+
}, children: _jsx(Text, { sx: {
|
|
797
|
+
fontSize: 0,
|
|
798
|
+
color: 'fg.default',
|
|
799
|
+
display: 'block',
|
|
800
|
+
whiteSpace: 'pre-wrap',
|
|
801
|
+
wordBreak: 'break-word',
|
|
802
|
+
fontFamily: 'mono',
|
|
803
|
+
}, children: outputText || '(empty output)' }) })] }));
|
|
804
|
+
})()] })), hasTriggeredOnce && (_jsxs(_Fragment, { children: [_jsxs(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: ["Streaming Messages", isLaunchingOnce && (_jsx(Spinner, { size: "small", sx: {
|
|
805
|
+
ml: 2,
|
|
806
|
+
verticalAlign: 'middle',
|
|
807
|
+
width: 14,
|
|
808
|
+
height: 14,
|
|
809
|
+
minWidth: 14,
|
|
810
|
+
minHeight: 14,
|
|
811
|
+
} }))] }), sidebarMessagesError ? (_jsx(Flash, { variant: "danger", sx: { fontSize: 0, mb: 2 }, children: sidebarMessagesError })) : sidebarMessages.filter(msg => msg.role !== 'user').length === 0 ? (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 2 }, children: [_jsx(Spinner, { size: "small", sx: { width: 16, height: 16, minWidth: 16, minHeight: 16 } }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "Waiting for streaming messages\u2026" })] })) : (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2, mb: 2 }, children: sidebarMessages
|
|
812
|
+
.slice()
|
|
813
|
+
.filter(msg => msg.role !== 'user')
|
|
814
|
+
.sort((a, b) => {
|
|
815
|
+
const ta = a.createdAt ? new Date(a.createdAt).getTime() : 0;
|
|
816
|
+
const tb = b.createdAt ? new Date(b.createdAt).getTime() : 0;
|
|
817
|
+
return tb - ta;
|
|
818
|
+
})
|
|
819
|
+
.slice(0, 10)
|
|
820
|
+
.map(msg => {
|
|
821
|
+
const content = typeof msg.content === 'string'
|
|
822
|
+
? msg.content
|
|
823
|
+
: JSON.stringify(msg.content);
|
|
824
|
+
return (_jsxs(Box, { sx: {
|
|
825
|
+
p: 2,
|
|
826
|
+
bg: 'canvas.subtle',
|
|
827
|
+
borderRadius: 2,
|
|
828
|
+
border: '1px solid',
|
|
829
|
+
borderColor: 'border.default',
|
|
830
|
+
}, children: [_jsxs(Box, { sx: {
|
|
831
|
+
display: 'flex',
|
|
832
|
+
alignItems: 'center',
|
|
833
|
+
gap: 1,
|
|
834
|
+
mb: 1,
|
|
835
|
+
}, children: [_jsx(Label, { size: "small", variant: msg.role === 'assistant'
|
|
836
|
+
? 'accent'
|
|
837
|
+
: msg.role === 'tool'
|
|
838
|
+
? 'success'
|
|
839
|
+
: 'secondary', children: msg.role }), msg.createdAt && (_jsx(Text, { sx: {
|
|
840
|
+
fontSize: 0,
|
|
841
|
+
color: 'fg.muted',
|
|
842
|
+
marginLeft: 'auto',
|
|
843
|
+
whiteSpace: 'nowrap',
|
|
844
|
+
}, children: new Date(msg.createdAt).toLocaleTimeString() }))] }), _jsx(Text, { sx: {
|
|
845
|
+
fontSize: 0,
|
|
846
|
+
color: 'fg.default',
|
|
847
|
+
display: 'block',
|
|
848
|
+
whiteSpace: 'pre-wrap',
|
|
849
|
+
wordBreak: 'break-word',
|
|
850
|
+
}, children: content.length > 320
|
|
851
|
+
? `${content.slice(0, 320)}…`
|
|
852
|
+
: content })] }, `once-msg-${msg.id}`));
|
|
853
|
+
}) }))] })), hasTriggeredApproval && approvals.length > 0 && (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: "Pending Tool Approvals" }), _jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2, mb: 2 }, children: approvals.map(a => (_jsxs(Box, { sx: {
|
|
854
|
+
p: 2,
|
|
855
|
+
border: '1px solid',
|
|
856
|
+
borderColor: 'attention.muted',
|
|
857
|
+
borderRadius: 2,
|
|
858
|
+
bg: 'attention.subtle',
|
|
859
|
+
}, children: [_jsxs(Text, { sx: { fontWeight: 600, fontSize: 1, display: 'block', mb: 1 }, children: ["\uD83D\uDEE1\uFE0F ", a.tool_name] }), a.tool_args && (_jsx(Text, { sx: { fontSize: 0, color: 'fg.muted', display: 'block', mb: 2, fontFamily: 'mono' }, children: JSON.stringify(a.tool_args) })), _jsxs(Box, { sx: { display: 'flex', gap: 1 }, children: [_jsx(Button, { size: "small", variant: "primary", onClick: () => void handleApprove(a.id), disabled: approvalLoading === a.id, children: approvalLoading === a.id ? 'Approving…' : 'Approve' }), _jsx(Button, { size: "small", variant: "danger", onClick: () => void handleReject(a.id, 'Rejected from trigger panel'), disabled: approvalLoading === a.id, children: "Reject" })] })] }, a.id))) })] })), hasTriggeredApproval && (_jsxs(_Fragment, { children: [_jsxs(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: ["Approval Agent Messages", isLaunchingApproval && (_jsx(Spinner, { size: "small", sx: {
|
|
860
|
+
ml: 2,
|
|
861
|
+
verticalAlign: 'middle',
|
|
862
|
+
width: 14,
|
|
863
|
+
height: 14,
|
|
864
|
+
minWidth: 14,
|
|
865
|
+
minHeight: 14,
|
|
866
|
+
} }))] }), hasTriggeredApproval && (_jsxs(_Fragment, { children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: "Generated Output" }), (() => {
|
|
867
|
+
const latestAssistantOutput = approvalSidebarMessages
|
|
868
|
+
.filter(msg => msg.role === 'assistant')
|
|
869
|
+
.sort((a, b) => {
|
|
870
|
+
const ta = a.createdAt ? new Date(a.createdAt).getTime() : 0;
|
|
871
|
+
const tb = b.createdAt ? new Date(b.createdAt).getTime() : 0;
|
|
872
|
+
return tb - ta;
|
|
873
|
+
})[0];
|
|
874
|
+
if (!latestAssistantOutput) {
|
|
875
|
+
return (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 2 }, children: [_jsx(Spinner, { size: "small", sx: { width: 16, height: 16, minWidth: 16, minHeight: 16 } }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "Waiting for agent output\u2026" })] }));
|
|
876
|
+
}
|
|
877
|
+
const outputText = typeof latestAssistantOutput.content === 'string'
|
|
878
|
+
? latestAssistantOutput.content
|
|
879
|
+
: JSON.stringify(latestAssistantOutput.content);
|
|
880
|
+
return (_jsxs(Box, { sx: {
|
|
881
|
+
mb: 2,
|
|
882
|
+
border: '1px solid',
|
|
883
|
+
borderColor: 'success.muted',
|
|
884
|
+
borderRadius: 2,
|
|
885
|
+
overflow: 'hidden',
|
|
886
|
+
}, children: [_jsxs(Box, { sx: {
|
|
887
|
+
display: 'flex',
|
|
888
|
+
alignItems: 'center',
|
|
889
|
+
gap: 1,
|
|
890
|
+
px: 2,
|
|
891
|
+
py: 1,
|
|
892
|
+
bg: 'success.subtle',
|
|
893
|
+
borderBottom: '1px solid',
|
|
894
|
+
borderColor: 'success.muted',
|
|
895
|
+
}, children: [_jsx(Label, { variant: "success", size: "small", children: "completed" }), latestAssistantOutput.createdAt && (_jsx(Text, { sx: {
|
|
896
|
+
fontSize: 0,
|
|
897
|
+
color: 'fg.muted',
|
|
898
|
+
ml: 'auto',
|
|
899
|
+
whiteSpace: 'nowrap',
|
|
900
|
+
}, children: new Date(latestAssistantOutput.createdAt).toLocaleString() })), _jsx(Button, { size: "small", variant: "invisible", sx: { p: 1 }, onClick: () => navigator.clipboard.writeText(outputText), children: _jsx(CopyIcon, { size: 12 }) })] }), _jsx(Box, { sx: {
|
|
901
|
+
p: 2,
|
|
902
|
+
bg: 'canvas.default',
|
|
903
|
+
maxHeight: 300,
|
|
904
|
+
overflow: 'auto',
|
|
905
|
+
}, children: _jsx(Text, { sx: {
|
|
906
|
+
fontSize: 0,
|
|
907
|
+
color: 'fg.default',
|
|
908
|
+
display: 'block',
|
|
909
|
+
whiteSpace: 'pre-wrap',
|
|
910
|
+
wordBreak: 'break-word',
|
|
911
|
+
fontFamily: 'mono',
|
|
912
|
+
}, children: outputText || '(empty output)' }) })] }));
|
|
913
|
+
})()] })), approvalSidebarMessages.filter(msg => msg.role !== 'user').length === 0 ? (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 2 }, children: [_jsx(Spinner, { size: "small", sx: { width: 16, height: 16, minWidth: 16, minHeight: 16 } }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "Waiting for approval agent messages\u2026" })] })) : (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2, mb: 2 }, children: approvalSidebarMessages
|
|
914
|
+
.slice()
|
|
915
|
+
.filter(msg => msg.role !== 'user')
|
|
916
|
+
.sort((a, b) => {
|
|
917
|
+
const ta = a.createdAt ? new Date(a.createdAt).getTime() : 0;
|
|
918
|
+
const tb = b.createdAt ? new Date(b.createdAt).getTime() : 0;
|
|
919
|
+
return tb - ta;
|
|
920
|
+
})
|
|
921
|
+
.slice(0, 10)
|
|
922
|
+
.map(msg => {
|
|
923
|
+
const content = typeof msg.content === 'string'
|
|
924
|
+
? msg.content
|
|
925
|
+
: JSON.stringify(msg.content);
|
|
926
|
+
return (_jsxs(Box, { sx: {
|
|
927
|
+
p: 2,
|
|
928
|
+
bg: 'canvas.subtle',
|
|
929
|
+
borderRadius: 2,
|
|
930
|
+
border: '1px solid',
|
|
931
|
+
borderColor: 'border.default',
|
|
932
|
+
}, children: [_jsxs(Box, { sx: {
|
|
933
|
+
display: 'flex',
|
|
934
|
+
alignItems: 'center',
|
|
935
|
+
gap: 1,
|
|
936
|
+
mb: 1,
|
|
937
|
+
}, children: [_jsx(Label, { size: "small", variant: msg.role === 'assistant'
|
|
938
|
+
? 'accent'
|
|
939
|
+
: msg.role === 'tool'
|
|
940
|
+
? 'success'
|
|
941
|
+
: 'secondary', children: msg.role }), msg.createdAt && (_jsx(Text, { sx: {
|
|
942
|
+
fontSize: 0,
|
|
943
|
+
color: 'fg.muted',
|
|
944
|
+
marginLeft: 'auto',
|
|
945
|
+
whiteSpace: 'nowrap',
|
|
946
|
+
}, children: new Date(msg.createdAt).toLocaleTimeString() }))] }), _jsx(Text, { sx: {
|
|
947
|
+
fontSize: 0,
|
|
948
|
+
color: 'fg.default',
|
|
949
|
+
display: 'block',
|
|
950
|
+
whiteSpace: 'pre-wrap',
|
|
951
|
+
wordBreak: 'break-word',
|
|
952
|
+
}, children: content.length > 320
|
|
953
|
+
? `${content.slice(0, 320)}…`
|
|
954
|
+
: content })] }, `approval-msg-${msg.id}`));
|
|
955
|
+
}) }))] })), _jsxs(Box, { sx: { mt: 2, display: 'grid', gap: 2 }, children: [_jsxs(Box, { children: [_jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: "Stream once (local curl)" }), _jsx(Box, { sx: {
|
|
956
|
+
mt: 1,
|
|
957
|
+
bg: 'canvas.subtle',
|
|
958
|
+
borderRadius: 2,
|
|
959
|
+
p: 2,
|
|
960
|
+
fontFamily: 'mono',
|
|
961
|
+
fontSize: 0,
|
|
962
|
+
wordBreak: 'break-all',
|
|
963
|
+
}, children: triggerRunCurl })] }), _jsx(Button, { size: "small", leadingVisual: CopyIcon, onClick: () => navigator.clipboard.writeText(triggerRunCurl), children: "Copy streaming command" })] })] })), activeTab === 'cron' && (_jsxs(Box, { sx: {
|
|
964
|
+
p: 3,
|
|
965
|
+
borderBottom: '1px solid',
|
|
966
|
+
borderColor: 'border.default',
|
|
967
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2 }, children: [_jsx(ClockIcon, { size: 16 }), _jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Cron Schedule" })] }), _jsxs(Label, { variant: "primary", sx: { mb: 2, display: 'inline-block' }, children: ["Current: ", cronExpr] }), nextRun && (_jsxs(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 2 }, children: ["Next run: ", new Date(nextRun).toLocaleString()] })), _jsxs(Box, { sx: { display: 'flex', gap: 2, mb: 2 }, children: [_jsx(TextInput, { value: editCron, onChange: e => setEditCron(e.target.value), placeholder: "* * * * *", sx: { flex: 1 }, size: "small" }), _jsx(Button, { size: "small", variant: "primary", leadingVisual: SyncIcon, onClick: handleUpdateCron, disabled: isUpdating, children: isUpdating ? 'Saving…' : 'Update' })] }), _jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted' }, children: "Standard cron syntax: minute hour day month weekday" })] })), activeTab === 'webhook' && (_jsxs(Box, { sx: {
|
|
968
|
+
p: 3,
|
|
969
|
+
borderBottom: '1px solid',
|
|
970
|
+
borderColor: 'border.default',
|
|
971
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2 }, children: [_jsx(GlobeIcon, { size: 16 }), _jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Webhook Trigger" })] }), _jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 3 }, children: "Generate a unique URL that triggers this agent on incoming HTTP POST requests. Useful for CI/CD pipelines, external services, or custom integrations." }), webhookUrl ? (_jsxs(_Fragment, { children: [_jsx(Label, { variant: webhookEnabled ? 'success' : 'secondary', sx: { mb: 2, display: 'inline-block' }, children: webhookEnabled ? 'Active' : 'Disabled' }), _jsx(Box, { sx: {
|
|
972
|
+
bg: 'canvas.subtle',
|
|
973
|
+
p: 2,
|
|
974
|
+
borderRadius: 2,
|
|
975
|
+
mb: 2,
|
|
976
|
+
fontFamily: 'mono',
|
|
977
|
+
fontSize: 0,
|
|
978
|
+
wordBreak: 'break-all',
|
|
979
|
+
}, children: webhookUrl }), webhookSecret && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsx(Text, { sx: { fontSize: 0, fontWeight: 'bold' }, children: "Secret:" }), _jsx(Box, { sx: {
|
|
980
|
+
bg: 'canvas.subtle',
|
|
981
|
+
p: 2,
|
|
982
|
+
borderRadius: 2,
|
|
983
|
+
mt: 1,
|
|
984
|
+
fontFamily: 'mono',
|
|
985
|
+
fontSize: 0,
|
|
986
|
+
}, children: webhookSecret })] })), _jsxs(Box, { sx: { display: 'flex', gap: 2 }, children: [_jsx(Button, { size: "small", leadingVisual: CopyIcon, onClick: () => navigator.clipboard.writeText(webhookUrl), children: "Copy URL" }), _jsx(Button, { size: "small", variant: webhookEnabled ? 'danger' : 'primary', onClick: handleToggleWebhook, children: webhookEnabled ? 'Disable' : 'Enable' })] })] })) : (_jsx(Button, { size: "small", variant: "primary", leadingVisual: GlobeIcon, onClick: handleGenerateWebhook, disabled: isUpdating, sx: { width: '100%' }, children: isUpdating ? 'Generating…' : 'Generate Webhook URL' }))] })), activeTab === 'event' && (_jsxs(Box, { sx: {
|
|
987
|
+
p: 3,
|
|
988
|
+
borderBottom: '1px solid',
|
|
989
|
+
borderColor: 'border.default',
|
|
990
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2 }, children: [_jsx(ZapIcon, { size: 16 }), _jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Event Trigger" })] }), _jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 3 }, children: "Subscribe to a Kafka topic or internal event stream. The agent triggers on matching messages." }), eventSubscribed ? (_jsxs(_Fragment, { children: [_jsxs(Label, { variant: "success", sx: { mb: 2, display: 'inline-block' }, children: ["Subscribed to: ", eventTopic] }), eventFilter && (_jsxs(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 2 }, children: ["Filter: ", eventFilter] })), _jsx(Button, { size: "small", variant: "danger", onClick: () => setEventSubscribed(false), sx: { width: '100%' }, children: "Unsubscribe" })] })) : (_jsxs(_Fragment, { children: [_jsx(TextInput, { value: eventTopic, onChange: e => setEventTopic(e.target.value), placeholder: "e.g. kpi.daily-report", sx: { width: '100%', mb: 2 }, size: "small" }), _jsx(TextInput, { value: eventFilter, onChange: e => setEventFilter(e.target.value), placeholder: "Optional JSONPath filter", sx: { width: '100%', mb: 2 }, size: "small" }), _jsx(Button, { size: "small", variant: "primary", leadingVisual: ZapIcon, onClick: handleSubscribeEvent, disabled: isUpdating || !eventTopic.trim(), sx: { width: '100%' }, children: isUpdating ? 'Subscribing…' : 'Subscribe' })] }))] })), activeTab === 'manual' && (_jsxs(Box, { sx: {
|
|
991
|
+
p: 3,
|
|
992
|
+
borderBottom: '1px solid',
|
|
993
|
+
borderColor: 'border.default',
|
|
994
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 2 }, children: [_jsx(PlayIcon, { size: 16 }), _jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Manual Trigger" })] }), _jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 3 }, children: "Fire the agent immediately. This is equivalent to the cron job executing but bypasses the schedule." }), _jsx(Button, { size: "small", leadingVisual: PlayIcon, onClick: handleTriggerNow, disabled: isTriggeringNow, sx: { width: '100%' }, children: isTriggeringNow ? 'Triggering…' : 'Trigger Now' }), triggerFlash && (_jsx(Flash, { variant: triggerFlash.includes('success') ? 'success' : 'danger', sx: { mt: 2, fontSize: 0 }, children: triggerFlash }))] })), _jsxs(Box, { sx: { p: 3, flex: 1, overflow: 'auto' }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Trigger History" }), triggerHistory.length === 0 ? (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "No trigger runs recorded yet." })) : (_jsx(Timeline, { children: triggerHistory.slice(0, 20).map(rec => (_jsxs(Timeline.Item, { children: [_jsx(Timeline.Badge, { children: rec.status === 'success' ? (_jsx(CheckCircleIcon, {})) : rec.status === 'failure' ? (_jsx(XCircleIcon, {})) : (_jsx(Spinner, { size: "small" })) }), _jsx(Timeline.Body, { children: _jsxs(Text, { sx: { fontSize: 0 }, children: [new Date(rec.timestamp).toLocaleString(), ' — ', _jsx(Label, { variant: rec.status === 'success'
|
|
995
|
+
? 'success'
|
|
996
|
+
: rec.status === 'failure'
|
|
997
|
+
? 'danger'
|
|
998
|
+
: 'accent', size: "small", children: rec.status }), rec.duration_ms != null && (_jsxs(Text, { sx: { ml: 1, color: 'fg.muted' }, children: ["(", (rec.duration_ms / 1000).toFixed(1), "s)"] }))] }) })] }, rec.id))) })), _jsx(Heading, { as: "h4", sx: { fontSize: 1, mt: 3, mb: 2 }, children: "Agent Events" }), agentEvents.length === 0 ? (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "No agent events yet." })) : (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: [...agentEvents]
|
|
999
|
+
.sort((a, b) => new Date(b.created_at).getTime() -
|
|
1000
|
+
new Date(a.created_at).getTime())
|
|
1001
|
+
.map((evt) => (_jsxs(Box, { sx: {
|
|
1002
|
+
p: 2,
|
|
1003
|
+
bg: evt.read ? 'canvas.subtle' : 'accent.subtle',
|
|
1004
|
+
borderRadius: 2,
|
|
1005
|
+
border: '1px solid',
|
|
1006
|
+
borderColor: evt.read
|
|
1007
|
+
? 'border.default'
|
|
1008
|
+
: 'accent.muted',
|
|
1009
|
+
}, children: [_jsxs(Box, { sx: {
|
|
1010
|
+
display: 'flex',
|
|
1011
|
+
alignItems: 'center',
|
|
1012
|
+
gap: 1,
|
|
1013
|
+
mb: 1,
|
|
1014
|
+
}, children: [_jsx(Label, { variant: evt.kind === 'agent-started'
|
|
1015
|
+
? 'accent'
|
|
1016
|
+
: evt.kind === 'agent-output'
|
|
1017
|
+
? 'success'
|
|
1018
|
+
: evt.kind?.includes('alert')
|
|
1019
|
+
? 'danger'
|
|
1020
|
+
: 'attention', size: "small", children: evt.kind }), _jsx(Text, { sx: { flex: 1, fontSize: 0, fontWeight: 'bold' }, children: evt.title }), _jsx(Text, { sx: {
|
|
1021
|
+
fontSize: 0,
|
|
1022
|
+
color: 'fg.muted',
|
|
1023
|
+
whiteSpace: 'nowrap',
|
|
1024
|
+
}, children: new Date(evt.created_at).toLocaleString() }), _jsx(Button, { size: "small", variant: "invisible", onClick: () => {
|
|
1025
|
+
const payload = {
|
|
1026
|
+
eventId: String(evt.id),
|
|
1027
|
+
eventAgentId: String(evt.agent_id || agentId || ''),
|
|
1028
|
+
};
|
|
1029
|
+
if (evt.read) {
|
|
1030
|
+
markUnreadMutation.mutate(payload);
|
|
1031
|
+
}
|
|
1032
|
+
else {
|
|
1033
|
+
markReadMutation.mutate(payload);
|
|
1034
|
+
}
|
|
1035
|
+
}, sx: { p: 1 }, children: evt.read ? (_jsx(EyeClosedIcon, { size: 12 })) : (_jsx(EyeIcon, { size: 12 })) }), _jsx(Button, { size: "small", variant: "invisible", onClick: () => deleteEventMutation.mutate(evt.id), sx: { p: 1, color: 'danger.fg' }, children: _jsx(TrashIcon, { size: 12 }) })] }), evt.payload &&
|
|
1036
|
+
(() => {
|
|
1037
|
+
const p = evt.payload;
|
|
1038
|
+
return (_jsxs(Box, { sx: { fontSize: 0, color: 'fg.muted' }, children: [evt.kind === 'agent-output' && p.outputs && (_jsx(Tooltip, { text: String(p.outputs), direction: "n", children: _jsx("button", { type: "button", "aria-label": String(p.outputs), style: {
|
|
1039
|
+
all: 'unset',
|
|
1040
|
+
display: 'block',
|
|
1041
|
+
width: '100%',
|
|
1042
|
+
cursor: 'default',
|
|
1043
|
+
}, children: _jsxs(Box, { sx: {
|
|
1044
|
+
mb: 1,
|
|
1045
|
+
display: 'flex',
|
|
1046
|
+
alignItems: 'baseline',
|
|
1047
|
+
gap: 1,
|
|
1048
|
+
minWidth: 0,
|
|
1049
|
+
}, children: [_jsx(Text, { as: "span", sx: {
|
|
1050
|
+
fontWeight: 'bold',
|
|
1051
|
+
color: 'fg.default',
|
|
1052
|
+
whiteSpace: 'nowrap',
|
|
1053
|
+
}, children: "Output:" }), _jsx(Truncate, { title: String(p.outputs), maxWidth: "100%", sx: { minWidth: 0, flex: 1 }, children: String(p.outputs) })] }) }) })), evt.kind === 'agent-output' &&
|
|
1054
|
+
p.duration_ms != null && (_jsxs(Text, { as: "p", children: ["Duration:", ' ', (Number(p.duration_ms) / 1000).toFixed(1), "s"] })), evt.kind?.includes('guardrail') && p.message && (_jsx(Text, { as: "p", children: String(p.message) }))] }));
|
|
1055
|
+
})()] }, evt.id))) }))] })] })] })] }));
|
|
1056
|
+
};
|
|
1057
|
+
// ─── Sync token to core IAM store ──────────────────────────────────────────
|
|
1058
|
+
const syncTokenToIamStore = (token) => {
|
|
1059
|
+
import('@datalayer/core/lib/state').then(({ iamStore }) => {
|
|
1060
|
+
iamStore.setState({ token });
|
|
1061
|
+
});
|
|
1062
|
+
};
|
|
1063
|
+
// ─── Main component with auth gate ─────────────────────────────────────────
|
|
1064
|
+
const AgentTriggersExample = () => {
|
|
1065
|
+
const { token, setAuth, clearAuth } = useSimpleAuthStore();
|
|
1066
|
+
const hasSynced = useRef(false);
|
|
1067
|
+
useEffect(() => {
|
|
1068
|
+
if (token && !hasSynced.current) {
|
|
1069
|
+
hasSynced.current = true;
|
|
1070
|
+
syncTokenToIamStore(token);
|
|
1071
|
+
}
|
|
1072
|
+
}, [token]);
|
|
1073
|
+
const handleSignIn = useCallback((newToken, handle) => {
|
|
1074
|
+
setAuth(newToken, handle);
|
|
1075
|
+
hasSynced.current = true;
|
|
1076
|
+
syncTokenToIamStore(newToken);
|
|
1077
|
+
}, [setAuth]);
|
|
1078
|
+
const handleLogout = useCallback(() => {
|
|
1079
|
+
clearAuth();
|
|
1080
|
+
hasSynced.current = false;
|
|
1081
|
+
import('@datalayer/core/lib/state').then(({ iamStore }) => {
|
|
1082
|
+
iamStore.setState({ token: undefined });
|
|
1083
|
+
});
|
|
1084
|
+
}, [clearAuth]);
|
|
1085
|
+
if (!token) {
|
|
1086
|
+
return (_jsx(ThemedProvider, { children: _jsx(SignInSimple, { onSignIn: handleSignIn, onApiKeySignIn: apiKey => handleSignIn(apiKey, 'api-key-user'), title: "Agent Triggers", description: "Sign in to configure cron, webhook, event, and manual triggers.", leadingIcon: _jsx(ClockIcon, { size: 24 }) }) }));
|
|
1087
|
+
}
|
|
1088
|
+
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThemedProvider, { children: _jsx(AgentTriggerInner, { onLogout: handleLogout }) }) }));
|
|
1089
|
+
};
|
|
1090
|
+
export default AgentTriggersExample;
|