@datalayer/agent-runtimes 1.0.4 → 1.0.6
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 +182 -1
- package/lib/AgentNode.d.ts +3 -0
- package/lib/AgentNode.js +676 -0
- package/lib/App.js +1 -1
- package/lib/agent-node/themeStore.d.ts +3 -0
- package/lib/agent-node/themeStore.js +156 -0
- package/lib/agent-node-main.d.ts +1 -0
- package/lib/agent-node-main.js +14 -0
- package/lib/agents/AgentDetails.d.ts +22 -1
- package/lib/agents/AgentDetails.js +34 -47
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +4 -2
- package/lib/chat/Chat.d.ts +5 -106
- package/lib/chat/Chat.js +20 -14
- package/lib/chat/ChatFloating.d.ts +7 -140
- package/lib/chat/ChatFloating.js +3 -3
- package/lib/chat/ChatPopupStandalone.d.ts +8 -47
- package/lib/chat/ChatPopupStandalone.js +3 -3
- package/lib/chat/ChatSidebar.d.ts +4 -69
- package/lib/chat/ChatSidebar.js +83 -51
- package/lib/chat/ChatStandalone.d.ts +4 -54
- package/lib/chat/ChatStandalone.js +3 -3
- package/lib/chat/base/ChatBase.js +1414 -174
- package/lib/chat/display/FloatingBrandButton.js +8 -1
- package/lib/chat/header/ChatHeader.d.ts +3 -1
- package/lib/chat/header/ChatHeader.js +15 -12
- package/lib/chat/header/ChatHeaderBase.d.ts +30 -5
- package/lib/chat/header/ChatHeaderBase.js +41 -16
- package/lib/chat/indicators/McpStatusIndicator.d.ts +7 -4
- package/lib/chat/indicators/McpStatusIndicator.js +7 -32
- package/lib/chat/indicators/SandboxStatusIndicator.d.ts +4 -1
- package/lib/chat/indicators/SandboxStatusIndicator.js +91 -56
- package/lib/chat/indicators/SkillsStatusIndicator.d.ts +7 -0
- package/lib/chat/indicators/SkillsStatusIndicator.js +88 -0
- package/lib/chat/indicators/index.d.ts +1 -0
- package/lib/chat/indicators/index.js +1 -0
- package/lib/chat/messages/ChatMessageList.d.ts +1 -1
- package/lib/chat/messages/ChatMessageList.js +154 -114
- package/lib/chat/messages/ChatMessages.js +6 -2
- package/lib/chat/prompt/InputFooter.d.ts +21 -6
- package/lib/chat/prompt/InputFooter.js +76 -20
- package/lib/chat/prompt/InputPrompt.d.ts +5 -1
- package/lib/chat/prompt/InputPrompt.js +4 -4
- package/lib/chat/prompt/InputPromptFooter.d.ts +3 -1
- package/lib/chat/prompt/InputPromptFooter.js +3 -3
- package/lib/chat/prompt/InputPromptLexical.d.ts +3 -1
- package/lib/chat/prompt/InputPromptLexical.js +12 -5
- package/lib/chat/prompt/InputPromptText.d.ts +3 -1
- package/lib/chat/prompt/InputPromptText.js +2 -2
- package/lib/chat/tools/ToolApprovalBanner.js +1 -1
- package/lib/chat/tools/ToolCallDisplay.d.ts +3 -1
- package/lib/chat/tools/ToolCallDisplay.js +2 -2
- package/lib/chat/usage/TokenUsageBar.js +20 -2
- package/lib/client/AgentRuntimesClientContext.d.ts +53 -0
- package/lib/client/AgentRuntimesClientContext.js +55 -0
- package/lib/client/AgentsMixin.d.ts +0 -18
- package/lib/client/AgentsMixin.js +20 -30
- package/lib/client/IAgentRuntimesClient.d.ts +215 -0
- package/lib/client/IAgentRuntimesClient.js +5 -0
- package/lib/client/SdkAgentRuntimesClient.d.ts +151 -0
- package/lib/client/SdkAgentRuntimesClient.js +134 -0
- package/lib/client/index.d.ts +4 -1
- package/lib/client/index.js +3 -1
- package/lib/components/NotificationEventCard.js +5 -1
- package/lib/config/AgentConfiguration.d.ts +22 -0
- package/lib/config/AgentConfiguration.js +319 -64
- package/lib/context/ContextDistribution.d.ts +3 -1
- package/lib/context/ContextDistribution.js +8 -27
- package/lib/context/ContextInspector.d.ts +3 -1
- package/lib/context/ContextInspector.js +19 -67
- package/lib/context/ContextPanel.d.ts +3 -1
- package/lib/context/ContextPanel.js +104 -64
- package/lib/context/ContextUsage.d.ts +3 -1
- package/lib/context/ContextUsage.js +3 -3
- package/lib/context/CostTracker.d.ts +9 -3
- package/lib/context/CostTracker.js +26 -47
- package/lib/context/CostUsageChart.d.ts +12 -0
- package/lib/context/CostUsageChart.js +378 -0
- package/lib/context/GraphFlowChart.d.ts +16 -0
- package/lib/context/GraphFlowChart.js +182 -0
- package/lib/context/TokenUsageChart.d.ts +8 -1
- package/lib/context/TokenUsageChart.js +349 -211
- package/lib/context/TurnGraphChart.d.ts +39 -0
- package/lib/context/TurnGraphChart.js +538 -0
- package/lib/context/otelWsPool.d.ts +20 -0
- package/lib/context/otelWsPool.js +69 -0
- package/lib/examples/A2UiComponentGalleryExample.d.ts +0 -17
- package/lib/examples/A2UiComponentGalleryExample.js +315 -522
- package/lib/examples/A2UiContactCardExample.d.ts +0 -18
- package/lib/examples/A2UiContactCardExample.js +154 -411
- package/lib/examples/A2UiRestaurantExample.d.ts +0 -30
- package/lib/examples/A2UiRestaurantExample.js +114 -212
- package/lib/examples/A2UiViewerExample.d.ts +0 -18
- package/lib/examples/A2UiViewerExample.js +283 -532
- package/lib/examples/AgUiBackendToolRenderingExample.js +1 -1
- package/lib/examples/AgUiHaikuGenUiExample.d.ts +1 -1
- package/lib/examples/AgUiHaikuGenUiExample.js +1 -1
- package/lib/examples/AgUiSharedStateExample.js +2 -1
- package/lib/examples/AgentCheckpointsExample.js +14 -28
- package/lib/examples/AgentCodemodeExample.d.ts +4 -6
- package/lib/examples/AgentCodemodeExample.js +603 -169
- package/lib/examples/AgentEvalsExample.js +339 -53
- package/lib/examples/AgentGuardrailsExample.js +383 -66
- package/lib/examples/AgentHooksExample.d.ts +3 -0
- package/lib/examples/AgentHooksExample.js +122 -0
- package/lib/examples/AgentInferenceProviderExample.d.ts +3 -0
- package/lib/examples/AgentInferenceProviderExample.js +329 -0
- package/lib/examples/AgentMCPExample.d.ts +3 -0
- package/lib/examples/AgentMCPExample.js +481 -0
- package/lib/examples/AgentMemoryExample.d.ts +1 -2
- package/lib/examples/AgentMemoryExample.js +78 -33
- package/lib/examples/AgentMonitoringExample.js +261 -200
- package/lib/examples/AgentNotificationsExample.d.ts +1 -2
- package/lib/examples/AgentNotificationsExample.js +114 -33
- package/lib/examples/AgentOtelExample.js +32 -42
- package/lib/examples/AgentOutputsExample.d.ts +11 -6
- package/lib/examples/AgentOutputsExample.js +433 -81
- package/lib/examples/AgentParametersExample.d.ts +3 -0
- package/lib/examples/AgentParametersExample.js +248 -0
- package/lib/examples/AgentSandboxExample.d.ts +3 -3
- package/lib/examples/AgentSandboxExample.js +74 -45
- package/lib/examples/AgentSkillsExample.js +95 -103
- package/lib/examples/AgentSubagentsExample.d.ts +14 -0
- package/lib/examples/AgentSubagentsExample.js +228 -0
- package/lib/examples/AgentToolApprovalsExample.js +49 -561
- package/lib/examples/AgentTriggersExample.js +823 -569
- package/lib/examples/{AgentspecExample.d.ts → AgentspecsExample.d.ts} +2 -2
- package/lib/examples/AgentspecsExample.js +1096 -0
- package/lib/examples/ChatCustomExample.js +16 -28
- package/lib/examples/ChatExample.js +13 -29
- package/lib/examples/CopilotKitLexicalExample.js +2 -1
- package/lib/examples/CopilotKitNotebookExample.js +2 -1
- package/lib/examples/HomeExample.d.ts +15 -0
- package/lib/examples/HomeExample.js +77 -0
- package/lib/examples/Lexical2Example.js +4 -2
- package/lib/examples/{LexicalExample.d.ts → LexicalAgentExample.d.ts} +4 -4
- package/lib/examples/{LexicalExample.js → LexicalAgentExample.js} +66 -17
- package/lib/examples/{LexicalSidebarExample.d.ts → LexicalAgentSidebarExample.d.ts} +5 -5
- package/lib/examples/LexicalAgentSidebarExample.js +261 -0
- package/lib/examples/NotebookAgentExample.d.ts +9 -0
- package/lib/examples/NotebookAgentExample.js +192 -0
- package/lib/examples/{NotebookSidebarExample.d.ts → NotebookAgentSidebarExample.d.ts} +2 -2
- package/lib/examples/NotebookAgentSidebarExample.js +221 -0
- package/lib/examples/{DatalayerNotebookExample.d.ts → NotebookCollaborationExample.d.ts} +4 -4
- package/lib/examples/{DatalayerNotebookExample.js → NotebookCollaborationExample.js} +3 -3
- package/lib/examples/NotebookExample.d.ts +4 -7
- package/lib/examples/NotebookExample.js +14 -146
- package/lib/examples/components/AuthRequiredView.d.ts +6 -0
- package/lib/examples/components/AuthRequiredView.js +33 -0
- package/lib/examples/components/ExampleWrapper.d.ts +9 -3
- package/lib/examples/components/ExampleWrapper.js +45 -9
- package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.js +1 -1
- package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.js +1 -1
- package/lib/examples/{ag-ui → components}/haiku/index.d.ts +1 -1
- package/lib/examples/{ag-ui → components}/haiku/index.js +1 -1
- package/lib/examples/components/index.d.ts +3 -0
- package/lib/examples/components/index.js +4 -0
- package/lib/examples/{ag-ui → components}/weather/index.d.ts +1 -1
- package/lib/examples/{ag-ui → components}/weather/index.js +1 -1
- package/lib/examples/example-selector.d.ts +17 -4
- package/lib/examples/example-selector.js +108 -41
- package/lib/examples/index.d.ts +10 -6
- package/lib/examples/index.js +10 -6
- package/lib/examples/lexical/initial-content.json +6 -6
- package/lib/examples/main.js +257 -27
- package/lib/examples/utils/a2ui.d.ts +18 -0
- package/lib/examples/utils/a2ui.js +69 -0
- package/lib/examples/utils/a2uiMarkdownProvider.d.ts +7 -0
- package/lib/examples/utils/a2uiMarkdownProvider.js +9 -0
- package/lib/examples/utils/agentId.d.ts +18 -0
- package/lib/examples/utils/agentId.js +54 -0
- package/lib/examples/utils/agents/earthquake-detector.json +11 -11
- package/lib/examples/utils/agents/sales-forecaster.json +11 -11
- package/lib/examples/utils/agents/social-post-generator.json +11 -11
- package/lib/examples/utils/agents/stock-market.json +11 -11
- package/lib/examples/utils/examplesStore.js +82 -27
- package/lib/examples/utils/useExampleAgentRuntimesUrl.d.ts +5 -0
- package/lib/examples/utils/useExampleAgentRuntimesUrl.js +19 -0
- package/lib/hooks/index.d.ts +8 -8
- package/lib/hooks/index.js +7 -7
- package/lib/hooks/useA2A.d.ts +2 -3
- package/lib/hooks/useAIAgentsWebSocket.d.ts +43 -4
- package/lib/hooks/useAIAgentsWebSocket.js +153 -12
- package/lib/hooks/useAcp.d.ts +1 -2
- package/lib/hooks/useAgUi.d.ts +1 -1
- package/lib/hooks/{useAgents.d.ts → useAgentRuntimes.d.ts} +70 -4
- package/lib/hooks/{useAgents.js → useAgentRuntimes.js} +237 -32
- package/lib/hooks/useAgentsCatalog.js +1 -1
- package/lib/hooks/useAgentsService.d.ts +2 -2
- package/lib/hooks/useAgentsService.js +7 -7
- package/lib/hooks/useCheckpoints.js +1 -1
- package/lib/hooks/useConfig.d.ts +4 -1
- package/lib/hooks/useConfig.js +10 -3
- package/lib/hooks/useContextSnapshot.d.ts +9 -4
- package/lib/hooks/useContextSnapshot.js +9 -37
- package/lib/hooks/useMonitoring.js +3 -0
- package/lib/hooks/useSandbox.d.ts +20 -8
- package/lib/hooks/useSandbox.js +105 -40
- package/lib/hooks/useSkills.d.ts +23 -5
- package/lib/hooks/useSkills.js +94 -39
- package/lib/hooks/useToolApprovals.d.ts +60 -36
- package/lib/hooks/useToolApprovals.js +318 -69
- package/lib/hooks/useVercelAI.d.ts +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -0
- package/lib/inference/index.d.ts +0 -1
- package/lib/middleware/index.d.ts +0 -1
- package/lib/protocols/AGUIAdapter.js +6 -0
- package/lib/protocols/VercelAIAdapter.d.ts +7 -0
- package/lib/protocols/VercelAIAdapter.js +59 -7
- package/lib/specs/agents/agents.d.ts +21 -4
- package/lib/specs/agents/agents.js +2879 -316
- package/lib/specs/agents/index.js +3 -1
- package/lib/specs/benchmarks.d.ts +20 -0
- package/lib/specs/benchmarks.js +205 -0
- package/lib/specs/envvars.js +27 -20
- package/lib/specs/evals.d.ts +10 -9
- package/lib/specs/evals.js +128 -88
- package/lib/specs/events.d.ts +3 -10
- package/lib/specs/events.js +127 -84
- package/lib/specs/frontendTools.js +2 -2
- package/lib/specs/guardrails.d.ts +0 -7
- package/lib/specs/guardrails.js +240 -159
- package/lib/specs/mcpServers.js +35 -6
- package/lib/specs/memory.d.ts +0 -2
- package/lib/specs/memory.js +4 -17
- package/lib/specs/models.d.ts +0 -2
- package/lib/specs/models.js +20 -15
- package/lib/specs/notifications.js +102 -18
- package/lib/specs/outputs.js +15 -9
- package/lib/specs/personas.d.ts +41 -0
- package/lib/specs/personas.js +168 -0
- package/lib/specs/skills.d.ts +1 -1
- package/lib/specs/skills.js +23 -23
- package/lib/specs/teams/index.js +3 -1
- package/lib/specs/teams/teams.js +468 -348
- package/lib/specs/tools.js +4 -4
- package/lib/specs/triggers.js +61 -11
- package/lib/stores/agentRuntimeStore.d.ts +208 -0
- package/lib/stores/agentRuntimeStore.js +650 -0
- package/lib/stores/conversationStore.js +2 -2
- package/lib/stores/index.d.ts +1 -1
- package/lib/stores/index.js +1 -1
- package/lib/tools/adapters/copilotkit/lexicalHooks.d.ts +1 -2
- package/lib/tools/adapters/copilotkit/lexicalHooks.js +1 -3
- package/lib/tools/adapters/copilotkit/notebookHooks.d.ts +1 -2
- package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -3
- package/lib/tools/index.d.ts +0 -2
- package/lib/tools/index.js +0 -1
- package/lib/types/agents-lifecycle.d.ts +18 -0
- package/lib/types/agents.d.ts +6 -0
- package/lib/types/agentspecs.d.ts +54 -1
- package/lib/types/benchmarks.d.ts +43 -0
- package/lib/types/benchmarks.js +5 -0
- package/lib/types/chat.d.ts +325 -8
- package/lib/types/context.d.ts +27 -0
- package/lib/types/cost.d.ts +2 -2
- package/lib/types/evals.d.ts +26 -17
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.js +3 -0
- package/lib/types/mcp.d.ts +8 -0
- package/lib/types/models.d.ts +2 -2
- package/lib/types/personas.d.ts +25 -0
- package/lib/types/personas.js +5 -0
- package/lib/types/skills.d.ts +43 -1
- package/lib/types/stream.d.ts +110 -0
- package/lib/types/stream.js +36 -0
- package/lib/utils/utils.d.ts +9 -5
- package/lib/utils/utils.js +9 -5
- package/package.json +19 -11
- package/scripts/codegen/__pycache__/generate_agents.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_benchmarks.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_evals.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/generate_events.cpython-313.pyc +0 -0
- package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
- package/scripts/codegen/generate_agents.py +187 -45
- package/scripts/codegen/generate_benchmarks.py +441 -0
- package/scripts/codegen/generate_evals.py +94 -16
- package/scripts/codegen/generate_events.py +35 -14
- package/scripts/codegen/generate_personas.py +319 -0
- package/scripts/codegen/generate_skills.py +9 -9
- package/scripts/sync-jupyter.sh +26 -7
- package/lib/api/tool-approvals.d.ts +0 -62
- package/lib/api/tool-approvals.js +0 -145
- package/lib/examples/AgentspecExample.js +0 -705
- package/lib/examples/LexicalSidebarExample.js +0 -163
- package/lib/examples/NotebookSidebarExample.js +0 -119
- package/lib/examples/NotebookSimpleExample.d.ts +0 -6
- package/lib/examples/NotebookSimpleExample.js +0 -22
- package/lib/examples/ag-ui/index.d.ts +0 -10
- package/lib/examples/ag-ui/index.js +0 -16
- package/lib/hooks/useAgentsRegistry.d.ts +0 -10
- package/lib/hooks/useAgentsRegistry.js +0 -20
- package/lib/stores/agentsStore.d.ts +0 -123
- package/lib/stores/agentsStore.js +0 -270
- /package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.d.ts +0 -0
- /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.js +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"id": "social-post-generator",
|
|
3
|
+
"title": "Social Post Generator",
|
|
4
|
+
"description": "A powerful agent template for automated social media post generation.",
|
|
5
|
+
"image": "https://images.unsplash.com/photo-1611926653458-09294b3142bf?w=300&h=150&fit=crop",
|
|
6
|
+
"author": "Eric Charles",
|
|
7
|
+
"editTimestamp": "2 hours ago",
|
|
8
|
+
"status": "paused",
|
|
9
|
+
"transport": "ag-ui",
|
|
10
|
+
"avatarUrl": "https://avatars.githubusercontent.com/primer",
|
|
11
|
+
"stars": 3,
|
|
12
|
+
"notifications": 1
|
|
13
13
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"id": "stocks-watcher",
|
|
3
|
+
"title": "Stocks Watcher",
|
|
4
|
+
"description": "Intelligent stock market analysis and portfolio tracking agent.",
|
|
5
|
+
"image": "https://images.unsplash.com/photo-1611974789855-9c2a0a7236a3?w=300&h=150&fit=crop",
|
|
6
|
+
"author": "Gonzalo Peña-Castellanos",
|
|
7
|
+
"editTimestamp": "3 days ago",
|
|
8
|
+
"status": "paused",
|
|
9
|
+
"transport": "acp",
|
|
10
|
+
"avatarUrl": "https://avatars.githubusercontent.com/desktop",
|
|
11
|
+
"stars": 1,
|
|
12
|
+
"notifications": 0
|
|
13
13
|
}
|
|
@@ -4,34 +4,89 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createStore } from 'zustand/vanilla';
|
|
6
6
|
import { useStore } from 'zustand';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
import { listPersonas } from '../../specs/personas';
|
|
8
|
+
const DEFAULT_PRESENTATION = {
|
|
9
|
+
author: 'Datalayer',
|
|
10
|
+
lastEdited: 'just now',
|
|
11
|
+
screenshot: 'https://images.unsplash.com/photo-1531297484001-80022131f5a1?w=300&h=150&fit=crop',
|
|
12
|
+
status: 'paused',
|
|
13
|
+
protocol: 'vercel-ai',
|
|
14
|
+
avatarUrl: 'https://avatars.githubusercontent.com/datalayer',
|
|
15
|
+
notebookFile: '',
|
|
16
|
+
lexicalFile: '',
|
|
17
|
+
stars: 0,
|
|
18
|
+
notifications: 0,
|
|
19
|
+
};
|
|
20
|
+
const PERSONA_PRESENTATIONS = {
|
|
21
|
+
sentinel: {
|
|
22
|
+
author: 'Eric Charles',
|
|
23
|
+
lastEdited: '53 minutes ago',
|
|
24
|
+
screenshot: 'https://images.unsplash.com/photo-1589519160732-57fc498494f8?w=300&h=150&fit=crop',
|
|
25
|
+
status: 'paused',
|
|
26
|
+
protocol: 'ag-ui',
|
|
27
|
+
avatarUrl: 'https://avatars.githubusercontent.com/atom',
|
|
28
|
+
notebookFile: 'earthquake-detector.ipynb.json',
|
|
29
|
+
lexicalFile: 'earthquake-detector.lexical.json',
|
|
30
|
+
stars: 4,
|
|
31
|
+
},
|
|
32
|
+
trader: {
|
|
33
|
+
author: 'Gonzalo Peña-Castellanos',
|
|
34
|
+
lastEdited: '3 days ago',
|
|
35
|
+
screenshot: 'https://images.unsplash.com/photo-1611974789855-9c2a0a7236a3?w=300&h=150&fit=crop',
|
|
36
|
+
status: 'paused',
|
|
37
|
+
protocol: 'acp',
|
|
38
|
+
avatarUrl: 'https://avatars.githubusercontent.com/desktop',
|
|
39
|
+
notebookFile: 'stock-market.ipynb.json',
|
|
40
|
+
lexicalFile: 'stock-market.lexical.json',
|
|
41
|
+
stars: 1,
|
|
42
|
+
},
|
|
43
|
+
forecaster: {
|
|
44
|
+
author: 'Eric Charles',
|
|
45
|
+
lastEdited: '1 hour ago',
|
|
46
|
+
screenshot: 'https://images.unsplash.com/photo-1460925895917-afdab827c52f?w=300&h=150&fit=crop',
|
|
47
|
+
status: 'running',
|
|
48
|
+
protocol: 'vercel-ai',
|
|
49
|
+
avatarUrl: 'https://avatars.githubusercontent.com/github',
|
|
50
|
+
notebookFile: 'sales-forecaster.ipynb.json',
|
|
51
|
+
lexicalFile: 'sales-forecaster.lexical.json',
|
|
52
|
+
stars: 5,
|
|
53
|
+
notifications: 2,
|
|
54
|
+
},
|
|
55
|
+
marketing: {
|
|
56
|
+
author: 'Eric Charles',
|
|
57
|
+
lastEdited: '2 hours ago',
|
|
58
|
+
screenshot: 'https://images.unsplash.com/photo-1611926653458-09294b3142bf?w=300&h=150&fit=crop',
|
|
59
|
+
status: 'paused',
|
|
60
|
+
protocol: 'ag-ui',
|
|
61
|
+
avatarUrl: 'https://avatars.githubusercontent.com/primer',
|
|
62
|
+
notebookFile: 'social-post-generator.ipynb.json',
|
|
63
|
+
lexicalFile: 'social-post-generator.lexical.json',
|
|
64
|
+
stars: 3,
|
|
65
|
+
notifications: 1,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
// Build the agent list from the generated personas catalogue.
|
|
69
|
+
const initialAgents = listPersonas().map(persona => {
|
|
70
|
+
const presentation = {
|
|
71
|
+
...DEFAULT_PRESENTATION,
|
|
72
|
+
...(PERSONA_PRESENTATIONS[persona.id] ?? {}),
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
id: persona.id,
|
|
76
|
+
name: persona.name,
|
|
77
|
+
description: persona.description,
|
|
78
|
+
author: presentation.author,
|
|
79
|
+
lastEdited: presentation.lastEdited,
|
|
80
|
+
screenshot: presentation.screenshot,
|
|
81
|
+
status: presentation.status,
|
|
82
|
+
protocol: presentation.protocol,
|
|
83
|
+
avatarUrl: presentation.avatarUrl,
|
|
84
|
+
notebookFile: presentation.notebookFile,
|
|
85
|
+
lexicalFile: presentation.lexicalFile,
|
|
86
|
+
stars: presentation.stars,
|
|
87
|
+
notifications: presentation.notifications,
|
|
88
|
+
};
|
|
27
89
|
});
|
|
28
|
-
// Initialize agents from the agents folder
|
|
29
|
-
const initialAgents = [
|
|
30
|
-
transformAgentData(earthquakeDetectorData, 'earthquake-detector', 'earthquake-detector'),
|
|
31
|
-
transformAgentData(stocksWatcherData, 'stock-market', 'stock-market'),
|
|
32
|
-
transformAgentData(salesForecasterData, 'sales-forecaster', 'sales-forecaster'),
|
|
33
|
-
transformAgentData(socialPostGeneratorData, 'social-post-generator', 'social-post-generator'),
|
|
34
|
-
];
|
|
35
90
|
export const agentsStore = createStore(set => ({
|
|
36
91
|
agents: initialAgents,
|
|
37
92
|
getAgentById: (id) => {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the base URL used by examples to call the agent-runtimes service.
|
|
8
|
+
* Priority: explicit override -> dedicated env -> legacy base env -> localhost.
|
|
9
|
+
*/
|
|
10
|
+
export function useExampleAgentRuntimesUrl(override) {
|
|
11
|
+
return useMemo(() => {
|
|
12
|
+
if (override) {
|
|
13
|
+
return override;
|
|
14
|
+
}
|
|
15
|
+
return (import.meta.env.VITE_DATALAYER_AGENT_RUNTIMES_URL ||
|
|
16
|
+
import.meta.env.VITE_BASE_URL ||
|
|
17
|
+
'http://localhost:8765');
|
|
18
|
+
}, [override]);
|
|
19
|
+
}
|
package/lib/hooks/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export { useFrontendTool, useBackendTool, useRegisteredTools, useTool, usePendin
|
|
|
40
40
|
* ChatBase infrastructure hooks.
|
|
41
41
|
*/
|
|
42
42
|
export { useConfig } from './useConfig';
|
|
43
|
-
export { useSkills } from './useSkills';
|
|
43
|
+
export { useSkills, useSkillActions, useAgentRuntimeLoadedSkills as useAgentLoadedSkills, } from './useSkills';
|
|
44
44
|
export { useContextSnapshot } from './useContextSnapshot';
|
|
45
45
|
export { useSandbox } from './useSandbox';
|
|
46
46
|
/**
|
|
@@ -66,19 +66,19 @@ export { useVercelAI } from './useVercelAI';
|
|
|
66
66
|
/**
|
|
67
67
|
* Unified hook for managing agents — both ephemeral and durable.
|
|
68
68
|
*/
|
|
69
|
-
export {
|
|
69
|
+
export { useAgentRuntimes } from './useAgentRuntimes';
|
|
70
70
|
/**
|
|
71
71
|
* Runtime query and mutation hooks.
|
|
72
72
|
*/
|
|
73
|
-
export { useAgentsRuntimes,
|
|
73
|
+
export { useAgentsRuntimes, useAgentRuntimesQuery, useAgentRuntimeByPodName, useCreateAgentRuntime, useDeleteAgentRuntime, useRefreshAgentRuntimes, agentQueryKeys, AGENT_QUERY_OPTIONS, useAgentLifecycleStore, getAgentLifecycleKey, } from './useAgentRuntimes';
|
|
74
74
|
/**
|
|
75
|
-
* Agent
|
|
75
|
+
* Agent-runtime WebSocket stream hook.
|
|
76
76
|
*/
|
|
77
|
-
export {
|
|
77
|
+
export { useAgentRuntimeWebSocket, type UseAgentRuntimeWebSocketOptions, } from './useAgentRuntimes';
|
|
78
78
|
/**
|
|
79
|
-
* Agent registry
|
|
79
|
+
* Agent catalog store, AI Agents REST API, and registry hooks.
|
|
80
80
|
*/
|
|
81
|
-
export {
|
|
81
|
+
export { useAgentCatalogStore, type AgentCatalogStoreState, } from './useAgentsCatalog';
|
|
82
82
|
/**
|
|
83
83
|
* Agents Service REST API (deprecated).
|
|
84
84
|
*/
|
|
@@ -89,5 +89,5 @@ export { useAgentsService, useNotebookAgents } from './useAgentsService';
|
|
|
89
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
90
|
export { useToolApprovals, useToolApprovalsQuery, usePendingApprovalCount, useApproveToolRequest, useRejectToolRequest, } from './useToolApprovals';
|
|
91
91
|
export { useNotifications, useFilteredNotifications, useUnreadNotificationCount, useMarkNotificationRead, useMarkAllNotificationsRead, useAllAgentEvents, useAgentEvents, useAgentEvent, useCreateAgentEvent, useUpdateAgentEvent, useDeleteAgentEvent, useMarkEventRead, useMarkEventUnread, } from './useNotifications';
|
|
92
|
-
export { useAIAgentsWebSocket, type UseAIAgentsWebSocketOptions, } from './useAIAgentsWebSocket';
|
|
92
|
+
export { useAIAgentsWebSocket, type UseAIAgentsWebSocketOptions, type UseAIAgentsWebSocketResult, type AIAgentsWebSocketCloseInfo, type AIAgentsWebSocketConnectionState, } from './useAIAgentsWebSocket';
|
|
93
93
|
export { useOtelTotalTokens, fetchOtelTotalTokens, fetchOtelMetricTotal, fetchOtelMetricRows, toMetricValue, } from './useMonitoring';
|
package/lib/hooks/index.js
CHANGED
|
@@ -47,7 +47,7 @@ export { useFrontendTool, useBackendTool, useRegisteredTools, useTool, usePendin
|
|
|
47
47
|
* ChatBase infrastructure hooks.
|
|
48
48
|
*/
|
|
49
49
|
export { useConfig } from './useConfig';
|
|
50
|
-
export { useSkills } from './useSkills';
|
|
50
|
+
export { useSkills, useSkillActions, useAgentRuntimeLoadedSkills as useAgentLoadedSkills, } from './useSkills';
|
|
51
51
|
export { useContextSnapshot } from './useContextSnapshot';
|
|
52
52
|
export { useSandbox } from './useSandbox';
|
|
53
53
|
// =============================================================================
|
|
@@ -79,19 +79,19 @@ export { useVercelAI } from './useVercelAI';
|
|
|
79
79
|
/**
|
|
80
80
|
* Unified hook for managing agents — both ephemeral and durable.
|
|
81
81
|
*/
|
|
82
|
-
export {
|
|
82
|
+
export { useAgentRuntimes } from './useAgentRuntimes';
|
|
83
83
|
/**
|
|
84
84
|
* Runtime query and mutation hooks.
|
|
85
85
|
*/
|
|
86
|
-
export { useAgentsRuntimes,
|
|
86
|
+
export { useAgentsRuntimes, useAgentRuntimesQuery, useAgentRuntimeByPodName, useCreateAgentRuntime, useDeleteAgentRuntime, useRefreshAgentRuntimes, agentQueryKeys, AGENT_QUERY_OPTIONS, useAgentLifecycleStore, getAgentLifecycleKey, } from './useAgentRuntimes';
|
|
87
87
|
/**
|
|
88
|
-
* Agent
|
|
88
|
+
* Agent-runtime WebSocket stream hook.
|
|
89
89
|
*/
|
|
90
|
-
export {
|
|
90
|
+
export { useAgentRuntimeWebSocket, } from './useAgentRuntimes';
|
|
91
91
|
/**
|
|
92
|
-
* Agent registry
|
|
92
|
+
* Agent catalog store, AI Agents REST API, and registry hooks.
|
|
93
93
|
*/
|
|
94
|
-
export {
|
|
94
|
+
export { useAgentCatalogStore, } from './useAgentsCatalog';
|
|
95
95
|
/**
|
|
96
96
|
* Agents Service REST API (deprecated).
|
|
97
97
|
*/
|
package/lib/hooks/useA2A.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { AgentCard, Task
|
|
2
|
-
export type { AgentCard, Task, TaskState };
|
|
1
|
+
import type { AgentCard, Task } from '@a2a-js/sdk';
|
|
3
2
|
export interface Message {
|
|
4
3
|
role: 'user' | 'assistant' | 'system';
|
|
5
4
|
content: string;
|
|
@@ -9,7 +8,7 @@ export interface Message {
|
|
|
9
8
|
}
|
|
10
9
|
export interface UseA2AOptions {
|
|
11
10
|
/**
|
|
12
|
-
* Base URL for the A2A endpoint (e.g.,
|
|
11
|
+
* Base URL for the A2A endpoint (e.g., `http://localhost:8000`).
|
|
13
12
|
*/
|
|
14
13
|
baseUrl?: string;
|
|
15
14
|
/**
|
|
@@ -1,15 +1,54 @@
|
|
|
1
1
|
/** A message pushed by the server. */
|
|
2
2
|
interface WSMessage {
|
|
3
|
-
channel
|
|
4
|
-
event
|
|
5
|
-
data
|
|
3
|
+
channel?: string;
|
|
4
|
+
event?: string;
|
|
5
|
+
data?: Record<string, unknown>;
|
|
6
|
+
type?: string;
|
|
7
|
+
payload?: unknown;
|
|
8
|
+
raw: unknown;
|
|
6
9
|
}
|
|
10
|
+
export interface AIAgentsWebSocketCloseInfo {
|
|
11
|
+
code: number;
|
|
12
|
+
reason: string;
|
|
13
|
+
wasClean: boolean;
|
|
14
|
+
detail: string;
|
|
15
|
+
}
|
|
16
|
+
export type AIAgentsWebSocketConnectionState = 'connecting' | 'connected' | 'closed';
|
|
7
17
|
/** Options for the WebSocket hook. */
|
|
8
18
|
export interface UseAIAgentsWebSocketOptions {
|
|
19
|
+
/** Enable/disable the socket lifecycle. */
|
|
20
|
+
enabled?: boolean;
|
|
21
|
+
/** Override the service base URL (defaults to aiagentsRunUrl). */
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
/** WebSocket path (or full http/https URL) for the stream endpoint. */
|
|
24
|
+
path?: string;
|
|
25
|
+
/** Query string parameters to append to the WebSocket URL. */
|
|
26
|
+
queryParams?: Record<string, string | number | boolean | null | undefined>;
|
|
27
|
+
/** Auto-reconnect on unexpected disconnects. */
|
|
28
|
+
autoReconnect?: boolean;
|
|
29
|
+
/** Max reconnect attempts before giving up (unbounded by default). */
|
|
30
|
+
maxReconnectAttempts?: number;
|
|
31
|
+
/** Reconnect delay strategy (ms) or static delay in ms. */
|
|
32
|
+
reconnectDelayMs?: number | ((attempt: number) => number);
|
|
9
33
|
/** Additional channels to subscribe to beyond the auto-subscribed user channel. */
|
|
10
34
|
channels?: string[];
|
|
35
|
+
/** Called when the socket opens. */
|
|
36
|
+
onOpen?: () => void;
|
|
11
37
|
/** Called for every incoming message (optional). */
|
|
12
38
|
onMessage?: (msg: WSMessage) => void;
|
|
39
|
+
/** Called when the socket closes. */
|
|
40
|
+
onClose?: (info: AIAgentsWebSocketCloseInfo) => void;
|
|
41
|
+
}
|
|
42
|
+
export interface UseAIAgentsWebSocketResult {
|
|
43
|
+
connectionState: AIAgentsWebSocketConnectionState;
|
|
44
|
+
lastClose: AIAgentsWebSocketCloseInfo | null;
|
|
45
|
+
reconnectAttempt: number;
|
|
46
|
+
/**
|
|
47
|
+
* Send a JSON payload on the underlying WebSocket.
|
|
48
|
+
* Returns `true` when the message was sent, `false` when the socket
|
|
49
|
+
* isn't open (the caller can retry once `connectionState === 'connected'`).
|
|
50
|
+
*/
|
|
51
|
+
send: (payload: unknown) => boolean;
|
|
13
52
|
}
|
|
14
53
|
/**
|
|
15
54
|
* Connect to the AI Agents generic WebSocket.
|
|
@@ -25,5 +64,5 @@ export interface UseAIAgentsWebSocketOptions {
|
|
|
25
64
|
* useAIAgentsWebSocket({ channels: [`agent:${agentId}`] });
|
|
26
65
|
* ```
|
|
27
66
|
*/
|
|
28
|
-
export declare function useAIAgentsWebSocket(options?: UseAIAgentsWebSocketOptions):
|
|
67
|
+
export declare function useAIAgentsWebSocket(options?: UseAIAgentsWebSocketOptions): UseAIAgentsWebSocketResult;
|
|
29
68
|
export {};
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module hooks/useAIAgentsWebSocket
|
|
14
14
|
*/
|
|
15
|
-
import { useEffect, useRef } from 'react';
|
|
15
|
+
import { useEffect, useRef, useState } from 'react';
|
|
16
16
|
import { useQueryClient } from '@tanstack/react-query';
|
|
17
17
|
import { useCoreStore, useIAMStore } from '@datalayer/core/lib/state';
|
|
18
18
|
import { DEFAULT_SERVICE_URLS, API_BASE_PATHS, } from '@datalayer/core/lib/api/constants';
|
|
@@ -27,6 +27,22 @@ function useBaseUrl() {
|
|
|
27
27
|
}
|
|
28
28
|
// ─── Hook ────────────────────────────────────────────────────────────
|
|
29
29
|
const RECONNECT_DELAY_MS = 3_000;
|
|
30
|
+
const WS_DEFAULT_PATH = `${API_BASE_PATHS.AI_AGENTS}/ws`;
|
|
31
|
+
const isDevTraceEnabled = () => {
|
|
32
|
+
try {
|
|
33
|
+
return Boolean(import.meta.env?.DEV);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const logApprovalTrace = (label, details) => {
|
|
40
|
+
if (!isDevTraceEnabled()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.debug(`[approval-trace] ${label}`, details);
|
|
44
|
+
};
|
|
45
|
+
const isObject = (value) => !!value && typeof value === 'object';
|
|
30
46
|
/**
|
|
31
47
|
* Connect to the AI Agents generic WebSocket.
|
|
32
48
|
*
|
|
@@ -44,28 +60,68 @@ const RECONNECT_DELAY_MS = 3_000;
|
|
|
44
60
|
export function useAIAgentsWebSocket(options) {
|
|
45
61
|
const token = useAuthToken();
|
|
46
62
|
const baseUrl = useBaseUrl();
|
|
63
|
+
const configuredBaseUrl = options?.baseUrl ?? baseUrl;
|
|
64
|
+
const enabled = options?.enabled ?? true;
|
|
65
|
+
const wsPath = options?.path ?? WS_DEFAULT_PATH;
|
|
66
|
+
const queryParamsKey = JSON.stringify(options?.queryParams ?? {});
|
|
47
67
|
const queryClient = useQueryClient();
|
|
68
|
+
const [connectionState, setConnectionState] = useState('closed');
|
|
69
|
+
const [lastClose, setLastClose] = useState(null);
|
|
70
|
+
const [reconnectAttempt, setReconnectAttempt] = useState(0);
|
|
48
71
|
const wsRef = useRef(null);
|
|
49
72
|
const reconnectTimer = useRef(null);
|
|
50
73
|
// Keep a ref of channels so we can re-subscribe on reconnect without
|
|
51
74
|
// tearing down the socket when the array reference changes.
|
|
52
75
|
const channelsRef = useRef(options?.channels ?? []);
|
|
53
76
|
channelsRef.current = options?.channels ?? [];
|
|
77
|
+
const autoReconnectRef = useRef(options?.autoReconnect ?? true);
|
|
78
|
+
autoReconnectRef.current = options?.autoReconnect ?? true;
|
|
79
|
+
const maxReconnectAttemptsRef = useRef(options?.maxReconnectAttempts);
|
|
80
|
+
maxReconnectAttemptsRef.current = options?.maxReconnectAttempts;
|
|
81
|
+
const reconnectDelayRef = useRef(options?.reconnectDelayMs);
|
|
82
|
+
reconnectDelayRef.current = options?.reconnectDelayMs;
|
|
83
|
+
const onOpenRef = useRef(options?.onOpen);
|
|
84
|
+
onOpenRef.current = options?.onOpen;
|
|
54
85
|
const onMessageRef = useRef(options?.onMessage);
|
|
55
86
|
onMessageRef.current = options?.onMessage;
|
|
87
|
+
const onCloseRef = useRef(options?.onClose);
|
|
88
|
+
onCloseRef.current = options?.onClose;
|
|
56
89
|
useEffect(() => {
|
|
57
|
-
if (!token)
|
|
90
|
+
if (!enabled || !token) {
|
|
91
|
+
setConnectionState('closed');
|
|
58
92
|
return;
|
|
93
|
+
}
|
|
59
94
|
let disposed = false;
|
|
95
|
+
let reconnectAttempts = 0;
|
|
96
|
+
const toWsUrl = () => {
|
|
97
|
+
const httpUrl = wsPath.startsWith('http://') || wsPath.startsWith('https://')
|
|
98
|
+
? wsPath
|
|
99
|
+
: `${configuredBaseUrl}${wsPath.startsWith('/') ? '' : '/'}${wsPath}`;
|
|
100
|
+
const url = new URL(httpUrl.replace(/^http/, 'ws'));
|
|
101
|
+
url.searchParams.set('token', token);
|
|
102
|
+
const queryParams = JSON.parse(queryParamsKey);
|
|
103
|
+
Object.entries(queryParams).forEach(([key, value]) => {
|
|
104
|
+
if (value === null || value === undefined) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
url.searchParams.set(key, String(value));
|
|
108
|
+
});
|
|
109
|
+
return url.toString();
|
|
110
|
+
};
|
|
60
111
|
function connect() {
|
|
61
112
|
if (disposed)
|
|
62
113
|
return;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const wsUrl = httpUrl.replace(/^http/, 'ws') + `?token=${encodeURIComponent(token)}`;
|
|
114
|
+
const wsUrl = toWsUrl();
|
|
115
|
+
setConnectionState('connecting');
|
|
66
116
|
const ws = new WebSocket(wsUrl);
|
|
67
117
|
wsRef.current = ws;
|
|
68
118
|
ws.onopen = () => {
|
|
119
|
+
reconnectAttempts = 0;
|
|
120
|
+
setReconnectAttempt(0);
|
|
121
|
+
setConnectionState('connected');
|
|
122
|
+
setLastClose(null);
|
|
123
|
+
console.debug('[ws:connect] url=%s', wsUrl);
|
|
124
|
+
onOpenRef.current?.();
|
|
69
125
|
// Subscribe to extra channels.
|
|
70
126
|
const channels = channelsRef.current;
|
|
71
127
|
if (channels.length > 0) {
|
|
@@ -73,36 +129,91 @@ export function useAIAgentsWebSocket(options) {
|
|
|
73
129
|
}
|
|
74
130
|
};
|
|
75
131
|
ws.onmessage = ev => {
|
|
76
|
-
let
|
|
132
|
+
let raw;
|
|
77
133
|
try {
|
|
78
|
-
|
|
134
|
+
raw = JSON.parse(String(ev.data));
|
|
79
135
|
}
|
|
80
136
|
catch {
|
|
81
137
|
return;
|
|
82
138
|
}
|
|
139
|
+
const msg = isObject(raw)
|
|
140
|
+
? {
|
|
141
|
+
channel: typeof raw.channel === 'string' ? raw.channel : undefined,
|
|
142
|
+
event: typeof raw.event === 'string' ? raw.event : undefined,
|
|
143
|
+
data: isObject(raw.data)
|
|
144
|
+
? raw.data
|
|
145
|
+
: undefined,
|
|
146
|
+
type: typeof raw.type === 'string' ? raw.type : undefined,
|
|
147
|
+
payload: raw.payload,
|
|
148
|
+
raw,
|
|
149
|
+
}
|
|
150
|
+
: { raw };
|
|
83
151
|
// Fire optional callback.
|
|
152
|
+
console.debug('[ws:recv] type=%s', msg.type ?? msg.event ?? 'unknown');
|
|
84
153
|
onMessageRef.current?.(msg);
|
|
85
154
|
// Invalidate React Query caches based on the event type.
|
|
86
155
|
const { event } = msg;
|
|
156
|
+
if (typeof event !== 'string') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
87
159
|
if (event.startsWith('event_')) {
|
|
88
160
|
queryClient.invalidateQueries({ queryKey: ['agent-events'] });
|
|
89
161
|
}
|
|
90
162
|
if (event.startsWith('tool_approval_')) {
|
|
163
|
+
const data = msg.data;
|
|
164
|
+
logApprovalTrace('recv_tool_approval_event', {
|
|
165
|
+
event,
|
|
166
|
+
channel: msg.channel,
|
|
167
|
+
approvalId: typeof data?.id === 'string'
|
|
168
|
+
? data.id
|
|
169
|
+
: typeof data?.approval_id === 'string'
|
|
170
|
+
? data.approval_id
|
|
171
|
+
: undefined,
|
|
172
|
+
status: typeof data?.status === 'string' ? data.status : undefined,
|
|
173
|
+
});
|
|
91
174
|
queryClient.invalidateQueries({ queryKey: ['tool-approvals'] });
|
|
92
175
|
}
|
|
93
176
|
if (event.startsWith('notification_')) {
|
|
94
177
|
queryClient.invalidateQueries({ queryKey: ['agent-notifications'] });
|
|
95
178
|
}
|
|
96
179
|
};
|
|
97
|
-
ws.onclose =
|
|
180
|
+
ws.onclose = event => {
|
|
98
181
|
wsRef.current = null;
|
|
99
|
-
|
|
100
|
-
|
|
182
|
+
setConnectionState('closed');
|
|
183
|
+
const closeInfo = {
|
|
184
|
+
code: event.code,
|
|
185
|
+
reason: event.reason,
|
|
186
|
+
wasClean: event.wasClean,
|
|
187
|
+
detail: `code ${event.code}${event.reason ? `: ${event.reason}` : ''}${event.wasClean ? ' (clean)' : ' (unclean)'}`,
|
|
188
|
+
};
|
|
189
|
+
setLastClose(closeInfo);
|
|
190
|
+
console.debug('[ws:disconnect] code=%d reason=%s', event.code, event.reason || '(none)');
|
|
191
|
+
onCloseRef.current?.(closeInfo);
|
|
192
|
+
if (disposed || !autoReconnectRef.current) {
|
|
193
|
+
return;
|
|
101
194
|
}
|
|
195
|
+
reconnectAttempts += 1;
|
|
196
|
+
setReconnectAttempt(reconnectAttempts);
|
|
197
|
+
const maxAttempts = maxReconnectAttemptsRef.current;
|
|
198
|
+
if (typeof maxAttempts === 'number' &&
|
|
199
|
+
Number.isFinite(maxAttempts) &&
|
|
200
|
+
reconnectAttempts > maxAttempts) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const configuredDelay = reconnectDelayRef.current;
|
|
204
|
+
const delay = typeof configuredDelay === 'function'
|
|
205
|
+
? configuredDelay(reconnectAttempts)
|
|
206
|
+
: typeof configuredDelay === 'number'
|
|
207
|
+
? configuredDelay
|
|
208
|
+
: RECONNECT_DELAY_MS;
|
|
209
|
+
reconnectTimer.current = setTimeout(connect, Math.max(0, delay));
|
|
102
210
|
};
|
|
103
211
|
ws.onerror = () => {
|
|
104
212
|
// onclose will fire after onerror; reconnect happens there.
|
|
105
|
-
ws.
|
|
213
|
+
if (ws.readyState === WebSocket.CONNECTING ||
|
|
214
|
+
ws.readyState === WebSocket.OPEN) {
|
|
215
|
+
ws.close();
|
|
216
|
+
}
|
|
106
217
|
};
|
|
107
218
|
}
|
|
108
219
|
connect();
|
|
@@ -110,11 +221,13 @@ export function useAIAgentsWebSocket(options) {
|
|
|
110
221
|
disposed = true;
|
|
111
222
|
if (reconnectTimer.current) {
|
|
112
223
|
clearTimeout(reconnectTimer.current);
|
|
224
|
+
reconnectTimer.current = null;
|
|
113
225
|
}
|
|
114
226
|
wsRef.current?.close();
|
|
115
227
|
wsRef.current = null;
|
|
228
|
+
setConnectionState('closed');
|
|
116
229
|
};
|
|
117
|
-
}, [token,
|
|
230
|
+
}, [token, configuredBaseUrl, wsPath, queryParamsKey, enabled, queryClient]);
|
|
118
231
|
// When the channel list changes, send subscribe/unsubscribe diffs.
|
|
119
232
|
const prevChannelsRef = useRef([]);
|
|
120
233
|
useEffect(() => {
|
|
@@ -133,4 +246,32 @@ export function useAIAgentsWebSocket(options) {
|
|
|
133
246
|
}
|
|
134
247
|
prevChannelsRef.current = [...channelsRef.current];
|
|
135
248
|
}, [options?.channels]);
|
|
249
|
+
return {
|
|
250
|
+
connectionState,
|
|
251
|
+
lastClose,
|
|
252
|
+
reconnectAttempt,
|
|
253
|
+
send: (payload) => {
|
|
254
|
+
const ws = wsRef.current;
|
|
255
|
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
if (isObject(payload) && payload.type === 'tool_approval_decision') {
|
|
260
|
+
logApprovalTrace('send_tool_approval_decision', {
|
|
261
|
+
approvalId: typeof payload.approvalId === 'string'
|
|
262
|
+
? payload.approvalId
|
|
263
|
+
: undefined,
|
|
264
|
+
approved: typeof payload.approved === 'boolean'
|
|
265
|
+
? payload.approved
|
|
266
|
+
: undefined,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
ws.send(typeof payload === 'string' ? payload : JSON.stringify(payload));
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
};
|
|
136
277
|
}
|
package/lib/hooks/useAcp.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type StopReason, type SessionUpdate, type AgentCapabilities, type
|
|
2
|
-
export type { StopReason, AgentCapabilities, ClientCapabilities, ToolCallUpdate, PermissionOption, };
|
|
1
|
+
import { type StopReason, type SessionUpdate, type AgentCapabilities, type PermissionOption, type ToolCallUpdate } from '@agentclientprotocol/sdk';
|
|
3
2
|
export type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
4
3
|
export type SessionUpdateType = SessionUpdate extends {
|
|
5
4
|
sessionUpdate: infer T;
|
package/lib/hooks/useAgUi.d.ts
CHANGED