@datalayer/agent-runtimes 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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 +25 -16
- 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 +1287 -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 +319 -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 +169 -0
- package/lib/client/AgentsMixin.js +279 -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 +152 -0
- package/lib/components/OutputCard.d.ts +8 -0
- package/lib/components/OutputCard.js +80 -0
- package/lib/components/ToolApprovalCard.d.ts +33 -0
- package/lib/components/ToolApprovalCard.js +60 -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 +506 -0
- package/lib/examples/AgentCodemodeExample.d.ts +14 -0
- package/lib/examples/AgentCodemodeExample.js +262 -0
- package/lib/examples/AgentEvalsExample.d.ts +14 -0
- package/lib/examples/AgentEvalsExample.js +216 -0
- package/lib/examples/AgentGuardrailsExample.d.ts +14 -0
- package/lib/examples/AgentGuardrailsExample.js +218 -0
- package/lib/examples/AgentMemoryExample.d.ts +14 -0
- package/lib/examples/AgentMemoryExample.js +234 -0
- package/lib/examples/AgentMonitoringExample.d.ts +13 -0
- package/lib/examples/AgentMonitoringExample.js +311 -0
- package/lib/examples/AgentNotificationsExample.d.ts +14 -0
- package/lib/examples/AgentNotificationsExample.js +273 -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 +211 -0
- package/lib/examples/AgentSandboxExample.d.ts +17 -0
- package/lib/examples/AgentSandboxExample.js +496 -0
- package/lib/examples/AgentSkillsExample.d.ts +3 -0
- package/lib/examples/AgentSkillsExample.js +290 -0
- package/lib/examples/AgentToolApprovalsExample.d.ts +3 -0
- package/lib/examples/AgentToolApprovalsExample.js +672 -0
- package/lib/examples/AgentTriggersExample.d.ts +14 -0
- package/lib/examples/AgentTriggersExample.js +523 -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} +4 -4
- 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/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 +1 -0
- package/lib/examples/components/index.js +1 -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 +6 -0
- package/lib/examples/main.js +20 -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 +37 -12
- package/lib/hooks/index.js +37 -12
- 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/useAgentsCatalog.d.ts +25 -0
- package/lib/hooks/useAgentsCatalog.js +28 -0
- 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 +2 -3
- package/lib/{components → mcp}/McpServerManager.js +1 -1
- 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 +31 -7
- package/lib/protocols/VercelAIAdapter.js +682 -0
- package/lib/{components/chat/protocols → protocols}/index.d.ts +1 -2
- package/lib/{components/chat/protocols → protocols}/index.js +1 -1
- package/lib/specs/agents/agents.d.ts +54 -0
- package/lib/specs/agents/agents.js +2638 -0
- package/lib/specs/agents/index.js +14 -7
- package/lib/specs/envvars.d.ts +11 -19
- package/lib/specs/envvars.js +42 -21
- package/lib/specs/evals.d.ts +20 -0
- package/lib/specs/evals.js +133 -0
- package/lib/specs/events.d.ts +18 -0
- package/lib/specs/events.js +182 -0
- package/lib/specs/frontendTools.d.ts +14 -0
- package/lib/specs/frontendTools.js +53 -0
- package/lib/specs/guardrails.d.ts +22 -0
- package/lib/specs/guardrails.js +391 -0
- package/lib/specs/index.d.ts +15 -2
- package/lib/specs/index.js +15 -2
- package/lib/specs/mcpServers.d.ts +13 -10
- package/lib/specs/mcpServers.js +95 -25
- package/lib/specs/memory.d.ts +34 -0
- package/lib/specs/memory.js +99 -0
- package/lib/specs/models.d.ts +22 -35
- package/lib/specs/models.js +64 -44
- package/lib/specs/notifications.d.ts +17 -0
- package/lib/specs/notifications.js +187 -0
- package/lib/specs/outputs.d.ts +19 -0
- package/lib/specs/outputs.js +112 -0
- package/lib/specs/skills.d.ts +7 -16
- package/lib/specs/skills.js +89 -12
- package/lib/specs/teams/index.d.ts +17 -0
- package/lib/specs/teams/index.js +37 -0
- package/lib/specs/teams/teams.d.ts +27 -0
- package/lib/specs/teams/teams.js +1120 -0
- package/lib/specs/tools.d.ts +15 -0
- package/lib/specs/tools.js +83 -0
- package/lib/specs/triggers.d.ts +15 -0
- package/lib/specs/triggers.js +117 -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 +2 -2
- package/lib/{components/chat/store → stores}/conversationStore.js +3 -3
- 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} +60 -100
- 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} +59 -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__/generate_agents.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_envvars.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_evals.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_guardrails.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_mcp_servers.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_memory.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_models.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_notifications.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_outputs.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_skills.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_teams.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_tools.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_triggers.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
- package/scripts/codegen/generate_agents.py +464 -58
- package/scripts/codegen/generate_envvars.py +36 -35
- package/scripts/codegen/generate_evals.py +279 -0
- package/scripts/codegen/generate_events.py +312 -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 +326 -0
- package/scripts/codegen/generate_triggers.py +295 -0
- package/scripts/codegen/versioning.py +53 -0
- package/lib/components/chat/components/base/ChatBase.js +0 -2240
- 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/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 -151
- 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 -308
- 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 -282
- package/lib/specs/agents/datalayer-ai/index.d.ts +0 -1
- package/lib/specs/agents/datalayer-ai/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 -189
- /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/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,202 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A2UI extension for chat component.
|
|
7
|
+
* Renders A2UI protocol messages from A2A agents using @a2ui/react v0.8.
|
|
8
|
+
*
|
|
9
|
+
* @module components/extensions/A2UIExtension
|
|
10
|
+
*/
|
|
11
|
+
import React from 'react';
|
|
12
|
+
import { A2UIViewer, initializeDefaultCatalog } from '@a2ui/react';
|
|
13
|
+
initializeDefaultCatalog();
|
|
14
|
+
function valueMapToObject(valueMap) {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const item of valueMap) {
|
|
17
|
+
if (item.valueString !== undefined) {
|
|
18
|
+
result[item.key] = item.valueString;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (item.valueNumber !== undefined) {
|
|
22
|
+
result[item.key] = item.valueNumber;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (item.valueBoolean !== undefined) {
|
|
26
|
+
result[item.key] = item.valueBoolean;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (item.valueMap !== undefined) {
|
|
30
|
+
result[item.key] = valueMapToObject(item.valueMap);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
result[item.key] = null;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function setNestedValue(obj, path, value) {
|
|
38
|
+
let current = obj;
|
|
39
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
40
|
+
const key = path[i];
|
|
41
|
+
const next = current[key];
|
|
42
|
+
if (!next || typeof next !== 'object' || Array.isArray(next)) {
|
|
43
|
+
current[key] = {};
|
|
44
|
+
}
|
|
45
|
+
current = current[key];
|
|
46
|
+
}
|
|
47
|
+
if (path.length > 0) {
|
|
48
|
+
current[path[path.length - 1]] = value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function processA2UIMessage(context, message) {
|
|
52
|
+
if (message.beginRendering) {
|
|
53
|
+
context.surfaces.set(message.beginRendering.surfaceId, {
|
|
54
|
+
surfaceId: message.beginRendering.surfaceId,
|
|
55
|
+
root: message.beginRendering.root,
|
|
56
|
+
mimeType: message.beginRendering.mimeType,
|
|
57
|
+
components: [],
|
|
58
|
+
data: {},
|
|
59
|
+
finished: false,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (message.surfaceUpdate) {
|
|
63
|
+
const surface = context.surfaces.get(message.surfaceUpdate.surfaceId);
|
|
64
|
+
if (surface) {
|
|
65
|
+
surface.components = message.surfaceUpdate.components;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (message.dataModelUpdate) {
|
|
69
|
+
const surface = context.surfaces.get(message.dataModelUpdate.surfaceId);
|
|
70
|
+
const nextData = valueMapToObject(message.dataModelUpdate.contents);
|
|
71
|
+
if (surface) {
|
|
72
|
+
if (message.dataModelUpdate.path &&
|
|
73
|
+
message.dataModelUpdate.path !== '/') {
|
|
74
|
+
const pathParts = message.dataModelUpdate.path
|
|
75
|
+
.split('/')
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
setNestedValue(surface.data, pathParts, nextData);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
surface.data = {
|
|
81
|
+
...surface.data,
|
|
82
|
+
...nextData,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
context.dataModels.set(message.dataModelUpdate.surfaceId, surface.data);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
context.dataModels.set(message.dataModelUpdate.surfaceId, nextData);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (message.finishRendering) {
|
|
92
|
+
const surface = context.surfaces.get(message.finishRendering.surfaceId);
|
|
93
|
+
if (surface) {
|
|
94
|
+
surface.finished = true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function renderSurfaceContent(surface) {
|
|
99
|
+
const { components, mimeType } = surface;
|
|
100
|
+
if (components.length === 0) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
switch (mimeType) {
|
|
104
|
+
case 'text/plain':
|
|
105
|
+
return React.createElement('pre', null, JSON.stringify(components, null, 2));
|
|
106
|
+
case 'application/json':
|
|
107
|
+
return React.createElement('pre', { className: 'json' }, JSON.stringify(components, null, 2));
|
|
108
|
+
default:
|
|
109
|
+
return React.createElement('pre', null, JSON.stringify(components, null, 2));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function renderSurfaces(context) {
|
|
113
|
+
const surfacesToRender = Array.from(context.surfaces.values());
|
|
114
|
+
return React.createElement('div', { className: 'chat-a2ui-container' }, surfacesToRender.map(surface => {
|
|
115
|
+
if (surface.components.length > 0) {
|
|
116
|
+
return React.createElement(A2UIViewer, {
|
|
117
|
+
key: surface.surfaceId,
|
|
118
|
+
root: surface.root,
|
|
119
|
+
components: surface.components,
|
|
120
|
+
data: surface.data,
|
|
121
|
+
onAction: action => {
|
|
122
|
+
console.log('A2UI chat action:', action);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return React.createElement('div', {
|
|
127
|
+
key: surface.surfaceId,
|
|
128
|
+
className: `chat-a2ui-surface chat-a2ui-surface--${surface.mimeType?.replace('/', '-') || 'unknown'}`,
|
|
129
|
+
}, renderSurfaceContent(surface));
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create A2UI activity renderer.
|
|
134
|
+
*/
|
|
135
|
+
export function createA2UIRenderer(_customRenderers) {
|
|
136
|
+
const contexts = new Map();
|
|
137
|
+
const getContext = (sessionId) => {
|
|
138
|
+
if (!contexts.has(sessionId)) {
|
|
139
|
+
contexts.set(sessionId, {
|
|
140
|
+
surfaces: new Map(),
|
|
141
|
+
dataModels: new Map(),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return contexts.get(sessionId);
|
|
145
|
+
};
|
|
146
|
+
return {
|
|
147
|
+
name: 'a2ui-renderer',
|
|
148
|
+
type: 'activity-renderer',
|
|
149
|
+
activityTypes: ['a2ui'],
|
|
150
|
+
render: ({ data }) => {
|
|
151
|
+
const sessionId = 'default';
|
|
152
|
+
const context = getContext(sessionId);
|
|
153
|
+
processA2UIMessage(context, data);
|
|
154
|
+
return renderSurfaces(context);
|
|
155
|
+
},
|
|
156
|
+
priority: 10,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* A2UI Extension implementation class.
|
|
161
|
+
*/
|
|
162
|
+
export class A2UIExtensionImpl {
|
|
163
|
+
name = 'a2ui';
|
|
164
|
+
type = 'activity-renderer';
|
|
165
|
+
activityTypes = ['a2ui'];
|
|
166
|
+
priority = 10;
|
|
167
|
+
contexts = new Map();
|
|
168
|
+
getSurfaces(sessionId) {
|
|
169
|
+
const context = this.contexts.get(sessionId);
|
|
170
|
+
if (!context)
|
|
171
|
+
return new Map();
|
|
172
|
+
const result = new Map();
|
|
173
|
+
for (const [key, surface] of context.surfaces) {
|
|
174
|
+
result.set(key, surface.components);
|
|
175
|
+
}
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
getDataModels(sessionId) {
|
|
179
|
+
return this.contexts.get(sessionId)?.dataModels || new Map();
|
|
180
|
+
}
|
|
181
|
+
processMessage(sessionId, message) {
|
|
182
|
+
if (!this.contexts.has(sessionId)) {
|
|
183
|
+
this.contexts.set(sessionId, {
|
|
184
|
+
surfaces: new Map(),
|
|
185
|
+
dataModels: new Map(),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const context = this.contexts.get(sessionId);
|
|
189
|
+
processA2UIMessage(context, message);
|
|
190
|
+
}
|
|
191
|
+
clearSession(sessionId) {
|
|
192
|
+
this.contexts.delete(sessionId);
|
|
193
|
+
}
|
|
194
|
+
render = ({ activityType: _activityType, data, message: _message, }) => {
|
|
195
|
+
const sessionId = 'default';
|
|
196
|
+
this.processMessage(sessionId, data);
|
|
197
|
+
const ctx = this.contexts.get(sessionId);
|
|
198
|
+
if (!ctx)
|
|
199
|
+
return null;
|
|
200
|
+
return renderSurfaces(ctx);
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Extension registry for chat component.
|
|
3
3
|
* Manages custom renderers and extension points.
|
|
4
4
|
*
|
|
5
|
-
* @module components/
|
|
5
|
+
* @module components/extensions/ExtensionRegistry
|
|
6
6
|
*/
|
|
7
|
-
import type { ChatExtension, MessageRendererExtension, ActivityRendererExtension, ToolUIExtension, ProtocolEventExtension, PanelExtension } from '../types/
|
|
7
|
+
import type { ChatExtension, MessageRendererExtension, ActivityRendererExtension, ToolUIExtension, ProtocolEventExtension, PanelExtension } from '../types/extensions';
|
|
8
8
|
/** Internal extension type for registry organization */
|
|
9
9
|
export type InternalExtensionType = 'message-renderer' | 'activity-renderer' | 'tool-ui' | 'protocol-event' | 'panel';
|
|
10
10
|
/**
|
|
@@ -63,4 +63,3 @@ export declare class ExtensionRegistry {
|
|
|
63
63
|
*/
|
|
64
64
|
clear(): void;
|
|
65
65
|
}
|
|
66
|
-
export { createMessageRenderer, createActivityRenderer, } from '../types/extension';
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* MCP-UI extension for chat component.
|
|
3
3
|
* Renders MCP UI protocol messages and resources.
|
|
4
4
|
*
|
|
5
|
-
* @module components/
|
|
5
|
+
* @module components/extensions/MCPUIExtension
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
|
-
import type { ActivityRendererExtension } from '../types/
|
|
8
|
+
import type { ActivityRendererExtension } from '../types/extensions';
|
|
9
9
|
/**
|
|
10
10
|
* MCP-UI resource types
|
|
11
11
|
*/
|
|
@@ -7,7 +7,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
* MCP-UI extension for chat component.
|
|
8
8
|
* Renders MCP UI protocol messages and resources.
|
|
9
9
|
*
|
|
10
|
-
* @module components/
|
|
10
|
+
* @module components/extensions/MCPUIExtension
|
|
11
11
|
*/
|
|
12
12
|
import React from 'react';
|
|
13
13
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension exports for chat component.
|
|
3
|
+
*
|
|
4
|
+
* @module components/extensions
|
|
5
|
+
*/
|
|
6
|
+
export { ExtensionRegistry } from './ExtensionRegistry';
|
|
7
|
+
export type { InternalExtensionType } from './ExtensionRegistry';
|
|
8
|
+
export { createA2UIRenderer, A2UIExtensionImpl, type A2UIMessage, } from './A2UIExtension';
|
|
9
|
+
export { createMCPUIRenderer, MCPUIExtensionImpl, type MCPUIMessage, type MCPUIResource, } from './MCPUIExtension';
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* Extension exports for chat component.
|
|
7
7
|
*
|
|
8
|
-
* @module components/
|
|
8
|
+
* @module components/extensions
|
|
9
9
|
*/
|
|
10
|
-
export { ExtensionRegistry
|
|
10
|
+
export { ExtensionRegistry } from './ExtensionRegistry';
|
|
11
11
|
export { createA2UIRenderer, A2UIExtensionImpl, } from './A2UIExtension';
|
|
12
12
|
export { createMCPUIRenderer, MCPUIExtensionImpl, } from './MCPUIExtension';
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -9,22 +9,21 @@
|
|
|
9
9
|
*
|
|
10
10
|
* - `useChat` - Main chat hook for messages, streaming, and state
|
|
11
11
|
* - `useFrontendTool`, `useBackendTool` - Tool registration hooks
|
|
12
|
-
* - `useKeyboardShortcuts` - Keyboard shortcut handling
|
|
13
12
|
*
|
|
14
13
|
* ## Transport-Specific Hooks
|
|
15
14
|
* These hooks provide direct protocol access without the chat component system.
|
|
16
15
|
* Use these for custom implementations or when you need fine-grained control.
|
|
17
16
|
*
|
|
18
|
-
* - `
|
|
17
|
+
* - `useAgUi` - AG-UI protocol (Pydantic AI's native protocol)
|
|
19
18
|
* - `useA2A` - A2A protocol (Agent-to-Agent with JSON-RPC)
|
|
20
19
|
* - `useAcp` - ACP protocol (Agent Client Protocol via WebSocket)
|
|
21
|
-
* - `
|
|
20
|
+
* - `useVercelAI` - Vercel AI SDK chat protocol
|
|
22
21
|
*
|
|
23
22
|
* ## Datalayer-Specific Hooks
|
|
24
23
|
* Hooks for Datalayer platform integration.
|
|
25
24
|
*
|
|
26
|
-
* - `
|
|
27
|
-
* - `
|
|
25
|
+
* - `useAgentsService` - Datalayer AI Agents REST API
|
|
26
|
+
* - `useNotebookAgents` - Notebook-specific agent management
|
|
28
27
|
*
|
|
29
28
|
* @module hooks
|
|
30
29
|
*/
|
|
@@ -38,14 +37,17 @@ export { useChat, type UseChatReturn } from './useChat';
|
|
|
38
37
|
*/
|
|
39
38
|
export { useFrontendTool, useBackendTool, useRegisteredTools, useTool, usePendingToolCalls, ActionRegistrar, type UseFrontendToolFn, } from './useTools';
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
40
|
+
* ChatBase infrastructure hooks.
|
|
42
41
|
*/
|
|
43
|
-
export {
|
|
42
|
+
export { useConfig } from './useConfig';
|
|
43
|
+
export { useSkills } from './useSkills';
|
|
44
|
+
export { useContextSnapshot } from './useContextSnapshot';
|
|
45
|
+
export { useSandbox } from './useSandbox';
|
|
44
46
|
/**
|
|
45
47
|
* AG-UI protocol hook - Pydantic AI's native protocol.
|
|
46
48
|
* Use for direct AG-UI communication without the chat component system.
|
|
47
49
|
*/
|
|
48
|
-
export {
|
|
50
|
+
export { useAgUi } from './useAgUi';
|
|
49
51
|
/**
|
|
50
52
|
* A2A protocol hook - Agent-to-Agent with JSON-RPC 2.0.
|
|
51
53
|
* Use for direct A2A communication without the chat component system.
|
|
@@ -60,9 +62,32 @@ export * from './useAcp';
|
|
|
60
62
|
* Vercel AI SDK chat hook - HTTP/SSE streaming.
|
|
61
63
|
* Use for direct Vercel AI communication without the chat component system.
|
|
62
64
|
*/
|
|
63
|
-
export {
|
|
65
|
+
export { useVercelAI } from './useVercelAI';
|
|
64
66
|
/**
|
|
65
|
-
*
|
|
67
|
+
* Unified hook for managing agents — both ephemeral and durable.
|
|
66
68
|
*/
|
|
67
|
-
export
|
|
68
|
-
|
|
69
|
+
export { useAgents } from './useAgents';
|
|
70
|
+
/**
|
|
71
|
+
* Runtime query and mutation hooks.
|
|
72
|
+
*/
|
|
73
|
+
export { useAgentsRuntimes, useAgentRuntimes, useAgentRuntimeByPodName, useCreateAgentRuntime, useDeleteAgentRuntime, useRefreshAgentRuntimes, agentQueryKeys, AGENT_QUERY_OPTIONS, useAgentLifecycleStore, getAgentLifecycleKey, } from './useAgents';
|
|
74
|
+
/**
|
|
75
|
+
* Agent catalog store, AI Agents REST API, and registry hooks.
|
|
76
|
+
*/
|
|
77
|
+
export { useAgentCatalogStore, type AgentCatalogStoreState, } from './useAgentsCatalog';
|
|
78
|
+
/**
|
|
79
|
+
* Agent registry hook.
|
|
80
|
+
*/
|
|
81
|
+
export { useAgentRegistry } from './useAgentsRegistry';
|
|
82
|
+
/**
|
|
83
|
+
* Agents Service REST API (deprecated).
|
|
84
|
+
*/
|
|
85
|
+
export { useAgentsService, useNotebookAgents } from './useAgentsService';
|
|
86
|
+
/**
|
|
87
|
+
* Focused hooks split by responsibility.
|
|
88
|
+
*/
|
|
89
|
+
export { useCheckpoints, useCheckpointsQuery, useRefreshCheckpoints, useDeletePausedAgentRuntime, useResumePausedAgentRuntime, usePauseAgent, useResumeAgent, useCheckpointAgent, useTerminateAgent, useAgentLifecycle, type CheckpointData, type PauseAgentParams, type ResumeAgentParams, type CheckpointAgentParams, type TerminateAgentParams, type AgentLifecycleOptions, type AgentLifecycleReturn, } from './useCheckpoints';
|
|
90
|
+
export { useToolApprovals, useToolApprovalsQuery, usePendingApprovalCount, useApproveToolRequest, useRejectToolRequest, } from './useToolApprovals';
|
|
91
|
+
export { useNotifications, useFilteredNotifications, useUnreadNotificationCount, useMarkNotificationRead, useMarkAllNotificationsRead, useAllAgentEvents, useAgentEvents, useAgentEvent, useCreateAgentEvent, useUpdateAgentEvent, useDeleteAgentEvent, useMarkEventRead, useMarkEventUnread, } from './useNotifications';
|
|
92
|
+
export { useAIAgentsWebSocket, type UseAIAgentsWebSocketOptions, } from './useAIAgentsWebSocket';
|
|
93
|
+
export { useOtelTotalTokens, fetchOtelTotalTokens, fetchOtelMetricTotal, fetchOtelMetricRows, toMetricValue, } from './useMonitoring';
|
package/lib/hooks/index.js
CHANGED
|
@@ -13,22 +13,21 @@
|
|
|
13
13
|
*
|
|
14
14
|
* - `useChat` - Main chat hook for messages, streaming, and state
|
|
15
15
|
* - `useFrontendTool`, `useBackendTool` - Tool registration hooks
|
|
16
|
-
* - `useKeyboardShortcuts` - Keyboard shortcut handling
|
|
17
16
|
*
|
|
18
17
|
* ## Transport-Specific Hooks
|
|
19
18
|
* These hooks provide direct protocol access without the chat component system.
|
|
20
19
|
* Use these for custom implementations or when you need fine-grained control.
|
|
21
20
|
*
|
|
22
|
-
* - `
|
|
21
|
+
* - `useAgUi` - AG-UI protocol (Pydantic AI's native protocol)
|
|
23
22
|
* - `useA2A` - A2A protocol (Agent-to-Agent with JSON-RPC)
|
|
24
23
|
* - `useAcp` - ACP protocol (Agent Client Protocol via WebSocket)
|
|
25
|
-
* - `
|
|
24
|
+
* - `useVercelAI` - Vercel AI SDK chat protocol
|
|
26
25
|
*
|
|
27
26
|
* ## Datalayer-Specific Hooks
|
|
28
27
|
* Hooks for Datalayer platform integration.
|
|
29
28
|
*
|
|
30
|
-
* - `
|
|
31
|
-
* - `
|
|
29
|
+
* - `useAgentsService` - Datalayer AI Agents REST API
|
|
30
|
+
* - `useNotebookAgents` - Notebook-specific agent management
|
|
32
31
|
*
|
|
33
32
|
* @module hooks
|
|
34
33
|
*/
|
|
@@ -45,9 +44,12 @@ export { useChat } from './useChat';
|
|
|
45
44
|
*/
|
|
46
45
|
export { useFrontendTool, useBackendTool, useRegisteredTools, useTool, usePendingToolCalls, ActionRegistrar, } from './useTools';
|
|
47
46
|
/**
|
|
48
|
-
*
|
|
47
|
+
* ChatBase infrastructure hooks.
|
|
49
48
|
*/
|
|
50
|
-
export {
|
|
49
|
+
export { useConfig } from './useConfig';
|
|
50
|
+
export { useSkills } from './useSkills';
|
|
51
|
+
export { useContextSnapshot } from './useContextSnapshot';
|
|
52
|
+
export { useSandbox } from './useSandbox';
|
|
51
53
|
// =============================================================================
|
|
52
54
|
// Transport-Specific Hooks (Direct Protocol Access)
|
|
53
55
|
// =============================================================================
|
|
@@ -55,7 +57,7 @@ export { useKeyboardShortcuts, useChatKeyboardShortcuts, getShortcutDisplay, } f
|
|
|
55
57
|
* AG-UI protocol hook - Pydantic AI's native protocol.
|
|
56
58
|
* Use for direct AG-UI communication without the chat component system.
|
|
57
59
|
*/
|
|
58
|
-
export {
|
|
60
|
+
export { useAgUi } from './useAgUi';
|
|
59
61
|
/**
|
|
60
62
|
* A2A protocol hook - Agent-to-Agent with JSON-RPC 2.0.
|
|
61
63
|
* Use for direct A2A communication without the chat component system.
|
|
@@ -70,12 +72,35 @@ export * from './useAcp';
|
|
|
70
72
|
* Vercel AI SDK chat hook - HTTP/SSE streaming.
|
|
71
73
|
* Use for direct Vercel AI communication without the chat component system.
|
|
72
74
|
*/
|
|
73
|
-
export {
|
|
75
|
+
export { useVercelAI } from './useVercelAI';
|
|
74
76
|
// =============================================================================
|
|
75
77
|
// Datalayer Platform Hooks
|
|
76
78
|
// =============================================================================
|
|
77
79
|
/**
|
|
78
|
-
*
|
|
80
|
+
* Unified hook for managing agents — both ephemeral and durable.
|
|
79
81
|
*/
|
|
80
|
-
export
|
|
81
|
-
|
|
82
|
+
export { useAgents } from './useAgents';
|
|
83
|
+
/**
|
|
84
|
+
* Runtime query and mutation hooks.
|
|
85
|
+
*/
|
|
86
|
+
export { useAgentsRuntimes, useAgentRuntimes, useAgentRuntimeByPodName, useCreateAgentRuntime, useDeleteAgentRuntime, useRefreshAgentRuntimes, agentQueryKeys, AGENT_QUERY_OPTIONS, useAgentLifecycleStore, getAgentLifecycleKey, } from './useAgents';
|
|
87
|
+
/**
|
|
88
|
+
* Agent catalog store, AI Agents REST API, and registry hooks.
|
|
89
|
+
*/
|
|
90
|
+
export { useAgentCatalogStore, } from './useAgentsCatalog';
|
|
91
|
+
/**
|
|
92
|
+
* Agent registry hook.
|
|
93
|
+
*/
|
|
94
|
+
export { useAgentRegistry } from './useAgentsRegistry';
|
|
95
|
+
/**
|
|
96
|
+
* Agents Service REST API (deprecated).
|
|
97
|
+
*/
|
|
98
|
+
export { useAgentsService, useNotebookAgents } from './useAgentsService';
|
|
99
|
+
/**
|
|
100
|
+
* Focused hooks split by responsibility.
|
|
101
|
+
*/
|
|
102
|
+
export { useCheckpoints, useCheckpointsQuery, useRefreshCheckpoints, useDeletePausedAgentRuntime, useResumePausedAgentRuntime, usePauseAgent, useResumeAgent, useCheckpointAgent, useTerminateAgent, useAgentLifecycle, } from './useCheckpoints';
|
|
103
|
+
export { useToolApprovals, useToolApprovalsQuery, usePendingApprovalCount, useApproveToolRequest, useRejectToolRequest, } from './useToolApprovals';
|
|
104
|
+
export { useNotifications, useFilteredNotifications, useUnreadNotificationCount, useMarkNotificationRead, useMarkAllNotificationsRead, useAllAgentEvents, useAgentEvents, useAgentEvent, useCreateAgentEvent, useUpdateAgentEvent, useDeleteAgentEvent, useMarkEventRead, useMarkEventUnread, } from './useNotifications';
|
|
105
|
+
export { useAIAgentsWebSocket, } from './useAIAgentsWebSocket';
|
|
106
|
+
export { useOtelTotalTokens, fetchOtelTotalTokens, fetchOtelMetricTotal, fetchOtelMetricRows, toMetricValue, } from './useMonitoring';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** A message pushed by the server. */
|
|
2
|
+
interface WSMessage {
|
|
3
|
+
channel: string;
|
|
4
|
+
event: string;
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
/** Options for the WebSocket hook. */
|
|
8
|
+
export interface UseAIAgentsWebSocketOptions {
|
|
9
|
+
/** Additional channels to subscribe to beyond the auto-subscribed user channel. */
|
|
10
|
+
channels?: string[];
|
|
11
|
+
/** Called for every incoming message (optional). */
|
|
12
|
+
onMessage?: (msg: WSMessage) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Connect to the AI Agents generic WebSocket.
|
|
16
|
+
*
|
|
17
|
+
* The hook automatically:
|
|
18
|
+
* - subscribes to the user's own channel (done server-side)
|
|
19
|
+
* - subscribes to any extra channels passed via `options.channels`
|
|
20
|
+
* - invalidates the matching React Query keys when events arrive
|
|
21
|
+
* - reconnects on unexpected disconnects
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* useAIAgentsWebSocket({ channels: [`agent:${agentId}`] });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function useAIAgentsWebSocket(options?: UseAIAgentsWebSocketOptions): void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generic WebSocket hook for the AI Agents service.
|
|
7
|
+
*
|
|
8
|
+
* Connects to the single `/ws` endpoint and subscribes to channels.
|
|
9
|
+
* When the server pushes a message on a subscribed channel the
|
|
10
|
+
* corresponding React Query cache is automatically invalidated so
|
|
11
|
+
* the UI refreshes with fresh data from the server.
|
|
12
|
+
*
|
|
13
|
+
* @module hooks/useAIAgentsWebSocket
|
|
14
|
+
*/
|
|
15
|
+
import { useEffect, useRef } from 'react';
|
|
16
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
17
|
+
import { useCoreStore, useIAMStore } from '@datalayer/core/lib/state';
|
|
18
|
+
import { DEFAULT_SERVICE_URLS, API_BASE_PATHS, } from '@datalayer/core/lib/api/constants';
|
|
19
|
+
// ─── Auth / URL helpers ──────────────────────────────────────────────
|
|
20
|
+
function useAuthToken() {
|
|
21
|
+
const token = useIAMStore((s) => s.token);
|
|
22
|
+
return token ?? '';
|
|
23
|
+
}
|
|
24
|
+
function useBaseUrl() {
|
|
25
|
+
const config = useCoreStore((s) => s.configuration);
|
|
26
|
+
return config?.aiagentsRunUrl ?? DEFAULT_SERVICE_URLS.AI_AGENTS;
|
|
27
|
+
}
|
|
28
|
+
// ─── Hook ────────────────────────────────────────────────────────────
|
|
29
|
+
const RECONNECT_DELAY_MS = 3_000;
|
|
30
|
+
/**
|
|
31
|
+
* Connect to the AI Agents generic WebSocket.
|
|
32
|
+
*
|
|
33
|
+
* The hook automatically:
|
|
34
|
+
* - subscribes to the user's own channel (done server-side)
|
|
35
|
+
* - subscribes to any extra channels passed via `options.channels`
|
|
36
|
+
* - invalidates the matching React Query keys when events arrive
|
|
37
|
+
* - reconnects on unexpected disconnects
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* useAIAgentsWebSocket({ channels: [`agent:${agentId}`] });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function useAIAgentsWebSocket(options) {
|
|
45
|
+
const token = useAuthToken();
|
|
46
|
+
const baseUrl = useBaseUrl();
|
|
47
|
+
const queryClient = useQueryClient();
|
|
48
|
+
const wsRef = useRef(null);
|
|
49
|
+
const reconnectTimer = useRef(null);
|
|
50
|
+
// Keep a ref of channels so we can re-subscribe on reconnect without
|
|
51
|
+
// tearing down the socket when the array reference changes.
|
|
52
|
+
const channelsRef = useRef(options?.channels ?? []);
|
|
53
|
+
channelsRef.current = options?.channels ?? [];
|
|
54
|
+
const onMessageRef = useRef(options?.onMessage);
|
|
55
|
+
onMessageRef.current = options?.onMessage;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!token)
|
|
58
|
+
return;
|
|
59
|
+
let disposed = false;
|
|
60
|
+
function connect() {
|
|
61
|
+
if (disposed)
|
|
62
|
+
return;
|
|
63
|
+
// Build the WebSocket URL. Replace http(s) with ws(s).
|
|
64
|
+
const httpUrl = `${baseUrl}${API_BASE_PATHS.AI_AGENTS}/ws`;
|
|
65
|
+
const wsUrl = httpUrl.replace(/^http/, 'ws') + `?token=${encodeURIComponent(token)}`;
|
|
66
|
+
const ws = new WebSocket(wsUrl);
|
|
67
|
+
wsRef.current = ws;
|
|
68
|
+
ws.onopen = () => {
|
|
69
|
+
// Subscribe to extra channels.
|
|
70
|
+
const channels = channelsRef.current;
|
|
71
|
+
if (channels.length > 0) {
|
|
72
|
+
ws.send(JSON.stringify({ subscribe: { channels } }));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
ws.onmessage = ev => {
|
|
76
|
+
let msg;
|
|
77
|
+
try {
|
|
78
|
+
msg = JSON.parse(ev.data);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Fire optional callback.
|
|
84
|
+
onMessageRef.current?.(msg);
|
|
85
|
+
// Invalidate React Query caches based on the event type.
|
|
86
|
+
const { event } = msg;
|
|
87
|
+
if (event.startsWith('event_')) {
|
|
88
|
+
queryClient.invalidateQueries({ queryKey: ['agent-events'] });
|
|
89
|
+
}
|
|
90
|
+
if (event.startsWith('tool_approval_')) {
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['tool-approvals'] });
|
|
92
|
+
}
|
|
93
|
+
if (event.startsWith('notification_')) {
|
|
94
|
+
queryClient.invalidateQueries({ queryKey: ['agent-notifications'] });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
ws.onclose = () => {
|
|
98
|
+
wsRef.current = null;
|
|
99
|
+
if (!disposed) {
|
|
100
|
+
reconnectTimer.current = setTimeout(connect, RECONNECT_DELAY_MS);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
ws.onerror = () => {
|
|
104
|
+
// onclose will fire after onerror; reconnect happens there.
|
|
105
|
+
ws.close();
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
connect();
|
|
109
|
+
return () => {
|
|
110
|
+
disposed = true;
|
|
111
|
+
if (reconnectTimer.current) {
|
|
112
|
+
clearTimeout(reconnectTimer.current);
|
|
113
|
+
}
|
|
114
|
+
wsRef.current?.close();
|
|
115
|
+
wsRef.current = null;
|
|
116
|
+
};
|
|
117
|
+
}, [token, baseUrl, queryClient]);
|
|
118
|
+
// When the channel list changes, send subscribe/unsubscribe diffs.
|
|
119
|
+
const prevChannelsRef = useRef([]);
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const ws = wsRef.current;
|
|
122
|
+
if (!ws || ws.readyState !== WebSocket.OPEN)
|
|
123
|
+
return;
|
|
124
|
+
const prev = new Set(prevChannelsRef.current);
|
|
125
|
+
const next = new Set(channelsRef.current);
|
|
126
|
+
const toSubscribe = channelsRef.current.filter(ch => !prev.has(ch));
|
|
127
|
+
const toUnsubscribe = prevChannelsRef.current.filter(ch => !next.has(ch));
|
|
128
|
+
if (toSubscribe.length > 0) {
|
|
129
|
+
ws.send(JSON.stringify({ subscribe: { channels: toSubscribe } }));
|
|
130
|
+
}
|
|
131
|
+
if (toUnsubscribe.length > 0) {
|
|
132
|
+
ws.send(JSON.stringify({ unsubscribe: { channels: toUnsubscribe } }));
|
|
133
|
+
}
|
|
134
|
+
prevChannelsRef.current = [...channelsRef.current];
|
|
135
|
+
}, [options?.channels]);
|
|
136
|
+
}
|
|
@@ -44,7 +44,7 @@ export interface UseAGUIOptions {
|
|
|
44
44
|
*
|
|
45
45
|
* Example:
|
|
46
46
|
* ```tsx
|
|
47
|
-
* const { messages, sendMessage, isConnected } =
|
|
47
|
+
* const { messages, sendMessage, isConnected } = useAgUi({
|
|
48
48
|
* baseUrl: 'http://localhost:8765',
|
|
49
49
|
* agentId: 'demo-agent',
|
|
50
50
|
* });
|
|
@@ -52,7 +52,7 @@ export interface UseAGUIOptions {
|
|
|
52
52
|
* await sendMessage('Hello!');
|
|
53
53
|
* ```
|
|
54
54
|
*/
|
|
55
|
-
export declare function
|
|
55
|
+
export declare function useAgUi(options?: UseAGUIOptions): {
|
|
56
56
|
messages: Message[];
|
|
57
57
|
isConnected: boolean;
|
|
58
58
|
isSending: boolean;
|
|
@@ -18,7 +18,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
18
18
|
*
|
|
19
19
|
* Example:
|
|
20
20
|
* ```tsx
|
|
21
|
-
* const { messages, sendMessage, isConnected } =
|
|
21
|
+
* const { messages, sendMessage, isConnected } = useAgUi({
|
|
22
22
|
* baseUrl: 'http://localhost:8765',
|
|
23
23
|
* agentId: 'demo-agent',
|
|
24
24
|
* });
|
|
@@ -26,7 +26,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
26
26
|
* await sendMessage('Hello!');
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export function
|
|
29
|
+
export function useAgUi(options = {}) {
|
|
30
30
|
const { baseUrl = 'http://localhost:8765', agentId = 'demo-agent', autoConnect = true, onMessageSent, onMessageReceived, onError, } = options;
|
|
31
31
|
const [messages, setMessages] = useState([]);
|
|
32
32
|
const [isConnected, setIsConnected] = useState(false);
|