@datalayer/agent-runtimes 1.0.4 → 1.0.5
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 +34 -0
- package/lib/App.js +1 -1
- 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 +4 -4
- package/lib/chat/ChatFloating.d.ts +7 -140
- package/lib/chat/ChatFloating.js +2 -2
- 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 +2 -2
- package/lib/chat/ChatStandalone.d.ts +4 -54
- package/lib/chat/ChatStandalone.js +3 -3
- package/lib/chat/base/ChatBase.js +1083 -157
- package/lib/chat/header/ChatHeaderBase.d.ts +11 -6
- package/lib/chat/header/ChatHeaderBase.js +18 -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 +9 -9
- 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 +108 -113
- package/lib/chat/prompt/InputFooter.d.ts +19 -6
- package/lib/chat/prompt/InputFooter.js +71 -18
- package/lib/chat/prompt/InputPrompt.d.ts +3 -1
- package/lib/chat/prompt/InputPrompt.js +4 -4
- package/lib/chat/prompt/InputPromptFooter.js +1 -1
- 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 +6 -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.js +3 -3
- 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/AgentCheckpointsExample.js +13 -27
- package/lib/examples/AgentCodemodeExample.d.ts +4 -6
- package/lib/examples/AgentCodemodeExample.js +591 -169
- package/lib/examples/AgentEvalsExample.js +12 -16
- package/lib/examples/AgentGuardrailsExample.js +370 -64
- package/lib/examples/AgentHooksExample.d.ts +3 -0
- package/lib/examples/AgentHooksExample.js +104 -0
- package/lib/examples/AgentMCPExample.d.ts +3 -0
- package/lib/examples/AgentMCPExample.js +480 -0
- package/lib/examples/AgentMemoryExample.js +13 -17
- package/lib/examples/AgentMonitoringExample.js +260 -199
- package/lib/examples/AgentNotificationsExample.js +49 -17
- package/lib/examples/AgentOtelExample.js +2 -3
- package/lib/examples/AgentOutputsExample.d.ts +11 -6
- package/lib/examples/AgentOutputsExample.js +382 -81
- package/lib/examples/AgentParametersExample.d.ts +3 -0
- package/lib/examples/AgentParametersExample.js +246 -0
- package/lib/examples/AgentSandboxExample.d.ts +2 -2
- package/lib/examples/AgentSandboxExample.js +68 -40
- package/lib/examples/AgentSkillsExample.js +91 -99
- package/lib/examples/{AgentspecExample.js → AgentSpecsExample.js} +10 -21
- package/lib/examples/AgentSubagentsExample.d.ts +14 -0
- package/lib/examples/AgentSubagentsExample.js +228 -0
- package/lib/examples/AgentToolApprovalsExample.js +29 -557
- package/lib/examples/AgentTriggersExample.js +819 -565
- package/lib/examples/ChatCustomExample.js +11 -24
- package/lib/examples/ChatExample.js +7 -24
- 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} +65 -16
- 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 +7 -0
- package/lib/examples/components/ExampleWrapper.js +25 -6
- 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 +107 -41
- package/lib/examples/index.d.ts +9 -6
- package/lib/examples/index.js +9 -6
- package/lib/examples/main.js +217 -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/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 +118 -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} +39 -2
- package/lib/hooks/{useAgents.js → useAgentRuntimes.js} +125 -15
- 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 +10 -0
- package/lib/specs/agents/agents.js +2139 -262
- package/lib/specs/agents/index.js +3 -1
- package/lib/specs/envvars.d.ts +1 -0
- package/lib/specs/envvars.js +38 -20
- package/lib/specs/evals.js +6 -6
- 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/index.d.ts +1 -0
- package/lib/specs/index.js +1 -0
- 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.js +25 -5
- 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 +2 -1
- package/lib/specs/skills.js +41 -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 +204 -0
- package/lib/stores/agentRuntimeStore.js +636 -0
- 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/agentspecs.d.ts +50 -1
- package/lib/types/chat.d.ts +309 -8
- package/lib/types/context.d.ts +27 -0
- package/lib/types/cost.d.ts +2 -2
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +2 -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 +13 -9
- package/scripts/codegen/__pycache__/generate_agents.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 +102 -6
- package/scripts/codegen/generate_events.py +35 -13
- 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/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/{AgentspecExample.d.ts → AgentSpecsExample.d.ts} +0 -0
- /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,270 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
-
* Distributed under the terms of the Modified BSD License.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Zustand store for agent runtime connection state.
|
|
7
|
-
*
|
|
8
|
-
* Manages two distinct concepts:
|
|
9
|
-
*
|
|
10
|
-
* 1. **Agent Runtime** — a single currently-connected pod (launch, connect,
|
|
11
|
-
* create agent, disconnect). Runtime pods are ephemeral; they have a
|
|
12
|
-
* `podName` and a lifecycle (idle → launching → ready → disconnected).
|
|
13
|
-
*
|
|
14
|
-
* 2. **Agents Registry** — a persisted registry of URL-addressable agents
|
|
15
|
-
* that were previously connected. Each entry has a `baseUrl` + transport
|
|
16
|
-
* pair and can be from any source (agent runtimes OR the stable agents
|
|
17
|
-
* service at `/api/v1/ai-agents/`).
|
|
18
|
-
*
|
|
19
|
-
* @module store/agentsStore
|
|
20
|
-
*/
|
|
21
|
-
import { createStore } from 'zustand/vanilla';
|
|
22
|
-
import { useStore } from 'zustand';
|
|
23
|
-
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
24
|
-
// ─── Helper: build the transport-specific endpoint URL ────────────────────
|
|
25
|
-
function getTransportEndpoint(baseUrl, transport, agentId) {
|
|
26
|
-
switch (transport) {
|
|
27
|
-
case 'vercel-ai':
|
|
28
|
-
return `${baseUrl}/api/v1/vercel-ai/${agentId}`;
|
|
29
|
-
case 'a2a':
|
|
30
|
-
return `${baseUrl}/api/v1/a2a/agents/${agentId}/`;
|
|
31
|
-
case 'acp':
|
|
32
|
-
return `${baseUrl}/api/v1/acp/ws/${agentId}`;
|
|
33
|
-
case 'ag-ui':
|
|
34
|
-
default:
|
|
35
|
-
return `${baseUrl}/api/v1/ag-ui/${agentId}/`;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
// ─── Helper: register agent on the runtime ────────────────────────────────
|
|
39
|
-
async function createAgentOnRuntime(agentBaseUrl, agentId, config = {}) {
|
|
40
|
-
const transport = config.protocol || 'ag-ui';
|
|
41
|
-
const response = await fetch(`${agentBaseUrl}/api/v1/agents`, {
|
|
42
|
-
method: 'POST',
|
|
43
|
-
headers: { 'Content-Type': 'application/json' },
|
|
44
|
-
body: JSON.stringify({
|
|
45
|
-
name: config.name || agentId,
|
|
46
|
-
description: config.description || 'AI assistant',
|
|
47
|
-
agent_library: config.agentLibrary || 'pydantic-ai',
|
|
48
|
-
transport,
|
|
49
|
-
model: config.model || 'bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0',
|
|
50
|
-
system_prompt: config.systemPrompt || 'You are a helpful AI assistant.',
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
if (response.ok || response.status === 400) {
|
|
54
|
-
// 400 means agent already exists, which is fine
|
|
55
|
-
const endpoint = getTransportEndpoint(agentBaseUrl, transport, agentId);
|
|
56
|
-
return { agentId, endpoint, isReady: true };
|
|
57
|
-
}
|
|
58
|
-
const errorData = await response.json().catch(() => ({}));
|
|
59
|
-
throw new Error(errorData.detail || `Failed to create agent: ${response.status}`);
|
|
60
|
-
}
|
|
61
|
-
// ─── Initial runtime state ────────────────────────────────────────────────
|
|
62
|
-
const initialRuntimeState = {
|
|
63
|
-
runtime: null,
|
|
64
|
-
status: 'idle',
|
|
65
|
-
error: null,
|
|
66
|
-
isLaunching: false,
|
|
67
|
-
};
|
|
68
|
-
// ─── Combined Zustand store ───────────────────────────────────────────────
|
|
69
|
-
export const agentStore = createStore()(persist((set, get) => ({
|
|
70
|
-
// ── Agent registry ────────────────────────────────────────────────
|
|
71
|
-
agents: [],
|
|
72
|
-
upsertAgent: agentData => {
|
|
73
|
-
set(state => {
|
|
74
|
-
const existingIndex = state.agents.findIndex(a => a.id === agentData.id);
|
|
75
|
-
const now = Date.now();
|
|
76
|
-
if (existingIndex >= 0) {
|
|
77
|
-
const updatedAgents = [...state.agents];
|
|
78
|
-
updatedAgents[existingIndex] = {
|
|
79
|
-
...updatedAgents[existingIndex],
|
|
80
|
-
...agentData,
|
|
81
|
-
lastUpdated: now,
|
|
82
|
-
};
|
|
83
|
-
return { agents: updatedAgents };
|
|
84
|
-
}
|
|
85
|
-
const newAgent = {
|
|
86
|
-
name: agentData.name || agentData.id,
|
|
87
|
-
description: agentData.description || '',
|
|
88
|
-
status: agentData.status || 'initializing',
|
|
89
|
-
lastUpdated: now,
|
|
90
|
-
...agentData,
|
|
91
|
-
};
|
|
92
|
-
return { agents: [...state.agents, newAgent] };
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
getAgentById: (id) => {
|
|
96
|
-
return get().agents.find(agent => agent.id === id);
|
|
97
|
-
},
|
|
98
|
-
getAgentByUrl: (baseUrl, protocol) => {
|
|
99
|
-
return get().agents.find(agent => agent.baseUrl === baseUrl && agent.protocol === protocol);
|
|
100
|
-
},
|
|
101
|
-
updateAgentStatus: (id, status, error = null) => {
|
|
102
|
-
set(state => {
|
|
103
|
-
const index = state.agents.findIndex(a => a.id === id);
|
|
104
|
-
if (index >= 0) {
|
|
105
|
-
const updatedAgents = [...state.agents];
|
|
106
|
-
updatedAgents[index] = {
|
|
107
|
-
...updatedAgents[index],
|
|
108
|
-
status,
|
|
109
|
-
error,
|
|
110
|
-
lastUpdated: Date.now(),
|
|
111
|
-
};
|
|
112
|
-
return { agents: updatedAgents };
|
|
113
|
-
}
|
|
114
|
-
return {};
|
|
115
|
-
});
|
|
116
|
-
},
|
|
117
|
-
toggleAgentStatus: (id) => {
|
|
118
|
-
set(state => {
|
|
119
|
-
const index = state.agents.findIndex(a => a.id === id);
|
|
120
|
-
if (index >= 0) {
|
|
121
|
-
const updatedAgents = [...state.agents];
|
|
122
|
-
const currentStatus = updatedAgents[index].status;
|
|
123
|
-
updatedAgents[index] = {
|
|
124
|
-
...updatedAgents[index],
|
|
125
|
-
status: currentStatus === 'running' ? 'paused' : 'running',
|
|
126
|
-
lastUpdated: Date.now(),
|
|
127
|
-
};
|
|
128
|
-
return { agents: updatedAgents };
|
|
129
|
-
}
|
|
130
|
-
return {};
|
|
131
|
-
});
|
|
132
|
-
},
|
|
133
|
-
deleteAgent: (id) => {
|
|
134
|
-
set(state => ({
|
|
135
|
-
agents: state.agents.filter(a => a.id !== id),
|
|
136
|
-
}));
|
|
137
|
-
},
|
|
138
|
-
clearAgents: () => {
|
|
139
|
-
set({ agents: [] });
|
|
140
|
-
},
|
|
141
|
-
// ── Agent runtime pod ───────────────────────────────────────────
|
|
142
|
-
...initialRuntimeState,
|
|
143
|
-
connectAgent: connection => {
|
|
144
|
-
const baseUrl = connection.jupyterBaseUrl ||
|
|
145
|
-
connection.serviceManager?.serverSettings.baseUrl;
|
|
146
|
-
if (!baseUrl) {
|
|
147
|
-
throw new Error('connectAgent requires either jupyterBaseUrl or serviceManager');
|
|
148
|
-
}
|
|
149
|
-
const agentBaseUrl = baseUrl.replace('/jupyter/server/', '/agent-runtimes/');
|
|
150
|
-
set({
|
|
151
|
-
runtime: {
|
|
152
|
-
podName: connection.podName,
|
|
153
|
-
environmentName: connection.environmentName,
|
|
154
|
-
jupyterBaseUrl: baseUrl,
|
|
155
|
-
agentBaseUrl,
|
|
156
|
-
serviceManager: connection.serviceManager,
|
|
157
|
-
status: 'ready',
|
|
158
|
-
kernelId: connection.kernelId,
|
|
159
|
-
},
|
|
160
|
-
status: 'ready',
|
|
161
|
-
error: null,
|
|
162
|
-
});
|
|
163
|
-
},
|
|
164
|
-
launchAgent: async (config) => {
|
|
165
|
-
set({ status: 'launching', error: null, isLaunching: true });
|
|
166
|
-
try {
|
|
167
|
-
const { createRuntime } = await import('@datalayer/core/lib/api');
|
|
168
|
-
const runtimePod = await createRuntime({
|
|
169
|
-
environmentName: config.environmentName,
|
|
170
|
-
creditsLimit: config.creditsLimit,
|
|
171
|
-
type: config.type || 'notebook',
|
|
172
|
-
givenName: config.givenName,
|
|
173
|
-
capabilities: config.capabilities,
|
|
174
|
-
snapshot: config.snapshot,
|
|
175
|
-
});
|
|
176
|
-
set({ status: 'connecting' });
|
|
177
|
-
const jupyterBaseUrl = runtimePod.ingress;
|
|
178
|
-
const agentBaseUrl = jupyterBaseUrl.replace('/jupyter/server/', '/agent-runtimes/');
|
|
179
|
-
const connection = {
|
|
180
|
-
podName: runtimePod.pod_name,
|
|
181
|
-
environmentName: runtimePod.environment_name,
|
|
182
|
-
jupyterBaseUrl,
|
|
183
|
-
agentBaseUrl,
|
|
184
|
-
status: 'ready',
|
|
185
|
-
};
|
|
186
|
-
set({ runtime: connection, status: 'ready', isLaunching: false });
|
|
187
|
-
return connection;
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to launch runtime';
|
|
191
|
-
set({ status: 'error', error: errorMessage, isLaunching: false });
|
|
192
|
-
throw err;
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
createAgent: async (config = {}) => {
|
|
196
|
-
const { runtime } = get();
|
|
197
|
-
if (!runtime) {
|
|
198
|
-
throw new Error('No runtime connected. Launch or connect to a runtime first.');
|
|
199
|
-
}
|
|
200
|
-
try {
|
|
201
|
-
const agentId = config.name || runtime.podName;
|
|
202
|
-
const agentConnection = await createAgentOnRuntime(runtime.agentBaseUrl, agentId, config);
|
|
203
|
-
set({
|
|
204
|
-
runtime: {
|
|
205
|
-
...runtime,
|
|
206
|
-
agentId: agentConnection.agentId,
|
|
207
|
-
endpoint: agentConnection.endpoint,
|
|
208
|
-
isReady: agentConnection.isReady,
|
|
209
|
-
},
|
|
210
|
-
});
|
|
211
|
-
return agentConnection;
|
|
212
|
-
}
|
|
213
|
-
catch (err) {
|
|
214
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to create agent';
|
|
215
|
-
set({ error: errorMessage });
|
|
216
|
-
throw err;
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
disconnect: () => {
|
|
220
|
-
set({ runtime: null, status: 'disconnected', error: null });
|
|
221
|
-
},
|
|
222
|
-
clearError: () => set({ error: null }),
|
|
223
|
-
setError: error => set({ error, status: 'error' }),
|
|
224
|
-
reset: () => set(initialRuntimeState),
|
|
225
|
-
}), {
|
|
226
|
-
name: 'agent-runtimes-storage',
|
|
227
|
-
storage: createJSONStorage(() => localStorage),
|
|
228
|
-
// Only persist the agent registry; runtime connection state is ephemeral.
|
|
229
|
-
partialize: state => ({
|
|
230
|
-
agents: state.agents.map(agent => ({
|
|
231
|
-
id: agent.id,
|
|
232
|
-
name: agent.name,
|
|
233
|
-
description: agent.description,
|
|
234
|
-
baseUrl: agent.baseUrl,
|
|
235
|
-
transport: agent.protocol,
|
|
236
|
-
status: agent.status,
|
|
237
|
-
lastUpdated: agent.lastUpdated,
|
|
238
|
-
documentId: agent.documentId,
|
|
239
|
-
runtimeId: agent.runtimeId,
|
|
240
|
-
})),
|
|
241
|
-
}),
|
|
242
|
-
}));
|
|
243
|
-
export function useAgentStore(selector) {
|
|
244
|
-
return useStore(agentStore, selector);
|
|
245
|
-
}
|
|
246
|
-
// Attach getState / subscribe for non-React consumers
|
|
247
|
-
useAgentStore.getState = agentStore.getState;
|
|
248
|
-
useAgentStore.subscribe = agentStore.subscribe;
|
|
249
|
-
// ─── Focused selector hooks ────────────────────────────────────────────────
|
|
250
|
-
/** Currently-connected agent runtime pod connection. */
|
|
251
|
-
export const useAgentRuntime = () => useAgentStore(state => state.runtime);
|
|
252
|
-
/**
|
|
253
|
-
* @deprecated Use useAgentRuntime() — agent fields are merged onto the runtime connection.
|
|
254
|
-
*/
|
|
255
|
-
export const useAgentFromStore = () => useAgentStore(state => state.runtime
|
|
256
|
-
? {
|
|
257
|
-
agentId: state.runtime.agentId,
|
|
258
|
-
endpoint: state.runtime.endpoint,
|
|
259
|
-
isReady: state.runtime.isReady,
|
|
260
|
-
}
|
|
261
|
-
: null);
|
|
262
|
-
export const useAgentStatus = () => useAgentStore(state => state.status);
|
|
263
|
-
export const useAgentError = () => useAgentStore(state => state.error);
|
|
264
|
-
export const useIsLaunching = () => useAgentStore(state => state.isLaunching);
|
|
265
|
-
// ─── Non-React access ──────────────────────────────────────────────────────
|
|
266
|
-
/** Get agent runtime store state outside React. */
|
|
267
|
-
export const getAgentState = () => agentStore.getState();
|
|
268
|
-
/** Subscribe to agent runtime store outside React. */
|
|
269
|
-
export const subscribeToAgent = agentStore.subscribe;
|
|
270
|
-
export default useAgentStore;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|