@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.
Files changed (267) hide show
  1. package/README.md +34 -0
  2. package/lib/App.js +1 -1
  3. package/lib/agents/AgentDetails.d.ts +22 -1
  4. package/lib/agents/AgentDetails.js +34 -47
  5. package/lib/api/index.d.ts +0 -1
  6. package/lib/api/index.js +4 -2
  7. package/lib/chat/Chat.d.ts +5 -106
  8. package/lib/chat/Chat.js +4 -4
  9. package/lib/chat/ChatFloating.d.ts +7 -140
  10. package/lib/chat/ChatFloating.js +2 -2
  11. package/lib/chat/ChatPopupStandalone.d.ts +8 -47
  12. package/lib/chat/ChatPopupStandalone.js +3 -3
  13. package/lib/chat/ChatSidebar.d.ts +4 -69
  14. package/lib/chat/ChatSidebar.js +2 -2
  15. package/lib/chat/ChatStandalone.d.ts +4 -54
  16. package/lib/chat/ChatStandalone.js +3 -3
  17. package/lib/chat/base/ChatBase.js +1083 -157
  18. package/lib/chat/header/ChatHeaderBase.d.ts +11 -6
  19. package/lib/chat/header/ChatHeaderBase.js +18 -16
  20. package/lib/chat/indicators/McpStatusIndicator.d.ts +7 -4
  21. package/lib/chat/indicators/McpStatusIndicator.js +7 -32
  22. package/lib/chat/indicators/SandboxStatusIndicator.d.ts +4 -1
  23. package/lib/chat/indicators/SandboxStatusIndicator.js +9 -9
  24. package/lib/chat/indicators/SkillsStatusIndicator.d.ts +7 -0
  25. package/lib/chat/indicators/SkillsStatusIndicator.js +88 -0
  26. package/lib/chat/indicators/index.d.ts +1 -0
  27. package/lib/chat/indicators/index.js +1 -0
  28. package/lib/chat/messages/ChatMessageList.d.ts +1 -1
  29. package/lib/chat/messages/ChatMessageList.js +108 -113
  30. package/lib/chat/prompt/InputFooter.d.ts +19 -6
  31. package/lib/chat/prompt/InputFooter.js +71 -18
  32. package/lib/chat/prompt/InputPrompt.d.ts +3 -1
  33. package/lib/chat/prompt/InputPrompt.js +4 -4
  34. package/lib/chat/prompt/InputPromptFooter.js +1 -1
  35. package/lib/chat/prompt/InputPromptLexical.d.ts +3 -1
  36. package/lib/chat/prompt/InputPromptLexical.js +12 -5
  37. package/lib/chat/prompt/InputPromptText.d.ts +3 -1
  38. package/lib/chat/prompt/InputPromptText.js +2 -2
  39. package/lib/chat/tools/ToolApprovalBanner.js +1 -1
  40. package/lib/chat/tools/ToolCallDisplay.d.ts +3 -1
  41. package/lib/chat/tools/ToolCallDisplay.js +2 -2
  42. package/lib/chat/usage/TokenUsageBar.js +20 -2
  43. package/lib/client/AgentRuntimesClientContext.d.ts +53 -0
  44. package/lib/client/AgentRuntimesClientContext.js +55 -0
  45. package/lib/client/AgentsMixin.d.ts +0 -18
  46. package/lib/client/AgentsMixin.js +6 -30
  47. package/lib/client/IAgentRuntimesClient.d.ts +215 -0
  48. package/lib/client/IAgentRuntimesClient.js +5 -0
  49. package/lib/client/SdkAgentRuntimesClient.d.ts +151 -0
  50. package/lib/client/SdkAgentRuntimesClient.js +134 -0
  51. package/lib/client/index.d.ts +4 -1
  52. package/lib/client/index.js +3 -1
  53. package/lib/components/NotificationEventCard.js +5 -1
  54. package/lib/config/AgentConfiguration.js +3 -3
  55. package/lib/context/ContextDistribution.d.ts +3 -1
  56. package/lib/context/ContextDistribution.js +8 -27
  57. package/lib/context/ContextInspector.d.ts +3 -1
  58. package/lib/context/ContextInspector.js +19 -67
  59. package/lib/context/ContextPanel.d.ts +3 -1
  60. package/lib/context/ContextPanel.js +104 -64
  61. package/lib/context/ContextUsage.d.ts +3 -1
  62. package/lib/context/ContextUsage.js +3 -3
  63. package/lib/context/CostTracker.d.ts +9 -3
  64. package/lib/context/CostTracker.js +26 -47
  65. package/lib/context/CostUsageChart.d.ts +12 -0
  66. package/lib/context/CostUsageChart.js +378 -0
  67. package/lib/context/GraphFlowChart.d.ts +16 -0
  68. package/lib/context/GraphFlowChart.js +182 -0
  69. package/lib/context/TokenUsageChart.d.ts +8 -1
  70. package/lib/context/TokenUsageChart.js +349 -211
  71. package/lib/context/TurnGraphChart.d.ts +39 -0
  72. package/lib/context/TurnGraphChart.js +538 -0
  73. package/lib/context/otelWsPool.d.ts +20 -0
  74. package/lib/context/otelWsPool.js +69 -0
  75. package/lib/examples/A2UiComponentGalleryExample.d.ts +0 -17
  76. package/lib/examples/A2UiComponentGalleryExample.js +315 -522
  77. package/lib/examples/A2UiContactCardExample.d.ts +0 -18
  78. package/lib/examples/A2UiContactCardExample.js +154 -411
  79. package/lib/examples/A2UiRestaurantExample.d.ts +0 -30
  80. package/lib/examples/A2UiRestaurantExample.js +114 -212
  81. package/lib/examples/A2UiViewerExample.d.ts +0 -18
  82. package/lib/examples/A2UiViewerExample.js +283 -532
  83. package/lib/examples/AgUiBackendToolRenderingExample.js +1 -1
  84. package/lib/examples/AgUiHaikuGenUiExample.d.ts +1 -1
  85. package/lib/examples/AgUiHaikuGenUiExample.js +1 -1
  86. package/lib/examples/AgentCheckpointsExample.js +13 -27
  87. package/lib/examples/AgentCodemodeExample.d.ts +4 -6
  88. package/lib/examples/AgentCodemodeExample.js +591 -169
  89. package/lib/examples/AgentEvalsExample.js +12 -16
  90. package/lib/examples/AgentGuardrailsExample.js +370 -64
  91. package/lib/examples/AgentHooksExample.d.ts +3 -0
  92. package/lib/examples/AgentHooksExample.js +104 -0
  93. package/lib/examples/AgentMCPExample.d.ts +3 -0
  94. package/lib/examples/AgentMCPExample.js +480 -0
  95. package/lib/examples/AgentMemoryExample.js +13 -17
  96. package/lib/examples/AgentMonitoringExample.js +260 -199
  97. package/lib/examples/AgentNotificationsExample.js +49 -17
  98. package/lib/examples/AgentOtelExample.js +2 -3
  99. package/lib/examples/AgentOutputsExample.d.ts +11 -6
  100. package/lib/examples/AgentOutputsExample.js +382 -81
  101. package/lib/examples/AgentParametersExample.d.ts +3 -0
  102. package/lib/examples/AgentParametersExample.js +246 -0
  103. package/lib/examples/AgentSandboxExample.d.ts +2 -2
  104. package/lib/examples/AgentSandboxExample.js +68 -40
  105. package/lib/examples/AgentSkillsExample.js +91 -99
  106. package/lib/examples/{AgentspecExample.js → AgentSpecsExample.js} +10 -21
  107. package/lib/examples/AgentSubagentsExample.d.ts +14 -0
  108. package/lib/examples/AgentSubagentsExample.js +228 -0
  109. package/lib/examples/AgentToolApprovalsExample.js +29 -557
  110. package/lib/examples/AgentTriggersExample.js +819 -565
  111. package/lib/examples/ChatCustomExample.js +11 -24
  112. package/lib/examples/ChatExample.js +7 -24
  113. package/lib/examples/CopilotKitLexicalExample.js +2 -1
  114. package/lib/examples/CopilotKitNotebookExample.js +2 -1
  115. package/lib/examples/HomeExample.d.ts +15 -0
  116. package/lib/examples/HomeExample.js +77 -0
  117. package/lib/examples/Lexical2Example.js +4 -2
  118. package/lib/examples/{LexicalExample.d.ts → LexicalAgentExample.d.ts} +4 -4
  119. package/lib/examples/{LexicalExample.js → LexicalAgentExample.js} +65 -16
  120. package/lib/examples/{LexicalSidebarExample.d.ts → LexicalAgentSidebarExample.d.ts} +5 -5
  121. package/lib/examples/LexicalAgentSidebarExample.js +261 -0
  122. package/lib/examples/NotebookAgentExample.d.ts +9 -0
  123. package/lib/examples/NotebookAgentExample.js +192 -0
  124. package/lib/examples/{NotebookSidebarExample.d.ts → NotebookAgentSidebarExample.d.ts} +2 -2
  125. package/lib/examples/NotebookAgentSidebarExample.js +221 -0
  126. package/lib/examples/{DatalayerNotebookExample.d.ts → NotebookCollaborationExample.d.ts} +4 -4
  127. package/lib/examples/{DatalayerNotebookExample.js → NotebookCollaborationExample.js} +3 -3
  128. package/lib/examples/NotebookExample.d.ts +4 -7
  129. package/lib/examples/NotebookExample.js +14 -146
  130. package/lib/examples/components/AuthRequiredView.d.ts +6 -0
  131. package/lib/examples/components/AuthRequiredView.js +33 -0
  132. package/lib/examples/components/ExampleWrapper.d.ts +7 -0
  133. package/lib/examples/components/ExampleWrapper.js +25 -6
  134. package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.js +1 -1
  135. package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.js +1 -1
  136. package/lib/examples/{ag-ui → components}/haiku/index.d.ts +1 -1
  137. package/lib/examples/{ag-ui → components}/haiku/index.js +1 -1
  138. package/lib/examples/components/index.d.ts +3 -0
  139. package/lib/examples/components/index.js +4 -0
  140. package/lib/examples/{ag-ui → components}/weather/index.d.ts +1 -1
  141. package/lib/examples/{ag-ui → components}/weather/index.js +1 -1
  142. package/lib/examples/example-selector.d.ts +17 -4
  143. package/lib/examples/example-selector.js +107 -41
  144. package/lib/examples/index.d.ts +9 -6
  145. package/lib/examples/index.js +9 -6
  146. package/lib/examples/main.js +217 -27
  147. package/lib/examples/utils/a2ui.d.ts +18 -0
  148. package/lib/examples/utils/a2ui.js +69 -0
  149. package/lib/examples/utils/a2uiMarkdownProvider.d.ts +7 -0
  150. package/lib/examples/utils/a2uiMarkdownProvider.js +9 -0
  151. package/lib/examples/utils/agentId.d.ts +18 -0
  152. package/lib/examples/utils/agentId.js +54 -0
  153. package/lib/examples/utils/agents/earthquake-detector.json +11 -11
  154. package/lib/examples/utils/agents/sales-forecaster.json +11 -11
  155. package/lib/examples/utils/agents/social-post-generator.json +11 -11
  156. package/lib/examples/utils/agents/stock-market.json +11 -11
  157. package/lib/examples/utils/examplesStore.js +82 -27
  158. package/lib/hooks/index.d.ts +8 -8
  159. package/lib/hooks/index.js +7 -7
  160. package/lib/hooks/useA2A.d.ts +2 -3
  161. package/lib/hooks/useAIAgentsWebSocket.d.ts +43 -4
  162. package/lib/hooks/useAIAgentsWebSocket.js +118 -12
  163. package/lib/hooks/useAcp.d.ts +1 -2
  164. package/lib/hooks/useAgUi.d.ts +1 -1
  165. package/lib/hooks/{useAgents.d.ts → useAgentRuntimes.d.ts} +39 -2
  166. package/lib/hooks/{useAgents.js → useAgentRuntimes.js} +125 -15
  167. package/lib/hooks/useAgentsCatalog.js +1 -1
  168. package/lib/hooks/useAgentsService.d.ts +2 -2
  169. package/lib/hooks/useAgentsService.js +7 -7
  170. package/lib/hooks/useCheckpoints.js +1 -1
  171. package/lib/hooks/useConfig.d.ts +4 -1
  172. package/lib/hooks/useConfig.js +10 -3
  173. package/lib/hooks/useContextSnapshot.d.ts +9 -4
  174. package/lib/hooks/useContextSnapshot.js +9 -37
  175. package/lib/hooks/useMonitoring.js +3 -0
  176. package/lib/hooks/useSandbox.d.ts +20 -8
  177. package/lib/hooks/useSandbox.js +105 -40
  178. package/lib/hooks/useSkills.d.ts +23 -5
  179. package/lib/hooks/useSkills.js +94 -39
  180. package/lib/hooks/useToolApprovals.d.ts +60 -36
  181. package/lib/hooks/useToolApprovals.js +318 -69
  182. package/lib/hooks/useVercelAI.d.ts +1 -1
  183. package/lib/index.d.ts +2 -1
  184. package/lib/index.js +1 -0
  185. package/lib/inference/index.d.ts +0 -1
  186. package/lib/middleware/index.d.ts +0 -1
  187. package/lib/protocols/AGUIAdapter.js +6 -0
  188. package/lib/protocols/VercelAIAdapter.d.ts +7 -0
  189. package/lib/protocols/VercelAIAdapter.js +59 -7
  190. package/lib/specs/agents/agents.d.ts +10 -0
  191. package/lib/specs/agents/agents.js +2139 -262
  192. package/lib/specs/agents/index.js +3 -1
  193. package/lib/specs/envvars.d.ts +1 -0
  194. package/lib/specs/envvars.js +38 -20
  195. package/lib/specs/evals.js +6 -6
  196. package/lib/specs/events.d.ts +3 -10
  197. package/lib/specs/events.js +127 -84
  198. package/lib/specs/frontendTools.js +2 -2
  199. package/lib/specs/guardrails.d.ts +0 -7
  200. package/lib/specs/guardrails.js +240 -159
  201. package/lib/specs/index.d.ts +1 -0
  202. package/lib/specs/index.js +1 -0
  203. package/lib/specs/mcpServers.js +35 -6
  204. package/lib/specs/memory.d.ts +0 -2
  205. package/lib/specs/memory.js +4 -17
  206. package/lib/specs/models.js +25 -5
  207. package/lib/specs/notifications.js +102 -18
  208. package/lib/specs/outputs.js +15 -9
  209. package/lib/specs/personas.d.ts +41 -0
  210. package/lib/specs/personas.js +168 -0
  211. package/lib/specs/skills.d.ts +2 -1
  212. package/lib/specs/skills.js +41 -23
  213. package/lib/specs/teams/index.js +3 -1
  214. package/lib/specs/teams/teams.js +468 -348
  215. package/lib/specs/tools.js +4 -4
  216. package/lib/specs/triggers.js +61 -11
  217. package/lib/stores/agentRuntimeStore.d.ts +204 -0
  218. package/lib/stores/agentRuntimeStore.js +636 -0
  219. package/lib/stores/index.d.ts +1 -1
  220. package/lib/stores/index.js +1 -1
  221. package/lib/tools/adapters/copilotkit/lexicalHooks.d.ts +1 -2
  222. package/lib/tools/adapters/copilotkit/lexicalHooks.js +1 -3
  223. package/lib/tools/adapters/copilotkit/notebookHooks.d.ts +1 -2
  224. package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -3
  225. package/lib/tools/index.d.ts +0 -2
  226. package/lib/tools/index.js +0 -1
  227. package/lib/types/agentspecs.d.ts +50 -1
  228. package/lib/types/chat.d.ts +309 -8
  229. package/lib/types/context.d.ts +27 -0
  230. package/lib/types/cost.d.ts +2 -2
  231. package/lib/types/index.d.ts +2 -0
  232. package/lib/types/index.js +2 -0
  233. package/lib/types/mcp.d.ts +8 -0
  234. package/lib/types/models.d.ts +2 -2
  235. package/lib/types/personas.d.ts +25 -0
  236. package/lib/types/personas.js +5 -0
  237. package/lib/types/skills.d.ts +43 -1
  238. package/lib/types/stream.d.ts +110 -0
  239. package/lib/types/stream.js +36 -0
  240. package/lib/utils/utils.d.ts +9 -5
  241. package/lib/utils/utils.js +9 -5
  242. package/package.json +13 -9
  243. package/scripts/codegen/__pycache__/generate_agents.cpython-313.pyc +0 -0
  244. package/scripts/codegen/__pycache__/generate_events.cpython-313.pyc +0 -0
  245. package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
  246. package/scripts/codegen/generate_agents.py +102 -6
  247. package/scripts/codegen/generate_events.py +35 -13
  248. package/scripts/codegen/generate_personas.py +319 -0
  249. package/scripts/codegen/generate_skills.py +9 -9
  250. package/scripts/sync-jupyter.sh +26 -7
  251. package/lib/api/tool-approvals.d.ts +0 -62
  252. package/lib/api/tool-approvals.js +0 -145
  253. package/lib/examples/LexicalSidebarExample.js +0 -163
  254. package/lib/examples/NotebookSidebarExample.js +0 -119
  255. package/lib/examples/NotebookSimpleExample.d.ts +0 -6
  256. package/lib/examples/NotebookSimpleExample.js +0 -22
  257. package/lib/examples/ag-ui/index.d.ts +0 -10
  258. package/lib/examples/ag-ui/index.js +0 -16
  259. package/lib/hooks/useAgentsRegistry.d.ts +0 -10
  260. package/lib/hooks/useAgentsRegistry.js +0 -20
  261. package/lib/stores/agentsStore.d.ts +0 -123
  262. package/lib/stores/agentsStore.js +0 -270
  263. /package/lib/examples/{AgentspecExample.d.ts → AgentSpecsExample.d.ts} +0 -0
  264. /package/lib/examples/{ag-ui → components}/haiku/HaikuDisplay.d.ts +0 -0
  265. /package/lib/examples/{ag-ui → components}/haiku/InlineHaikuCard.d.ts +0 -0
  266. /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.d.ts +0 -0
  267. /package/lib/examples/{ag-ui → components}/weather/InlineWeatherCard.js +0 -0
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2025-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ import { useEffect, useState } from 'react';
7
+ import { Text, Spinner } from '@primer/react';
8
+ import { Box, setupPrimerPortals } from '@datalayer/primer-addons';
9
+ import { ThemedProvider } from './utils/themedProvider';
10
+ import { uniqueAgentId } from './utils/agentId';
11
+ import { ErrorView } from './components';
12
+ import { Chat } from '../chat';
13
+ setupPrimerPortals();
14
+ const BASE_URL = 'http://localhost:8765';
15
+ const AGENT_SPEC_ID = 'demo-hooks';
16
+ const AGENT_NAME = 'hooks-demo';
17
+ const AgentHooksExample = () => {
18
+ const [agentId, setAgentId] = useState(null);
19
+ const [error, setError] = useState(null);
20
+ const [isCreating, setIsCreating] = useState(true);
21
+ useEffect(() => {
22
+ let cancelled = false;
23
+ const name = uniqueAgentId(AGENT_NAME);
24
+ const createAgent = async () => {
25
+ try {
26
+ const response = await fetch(`${BASE_URL}/api/v1/agents`, {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({
30
+ name,
31
+ agent_spec_id: AGENT_SPEC_ID,
32
+ transport: 'vercel-ai',
33
+ }),
34
+ });
35
+ if (!response.ok) {
36
+ const data = await response
37
+ .json()
38
+ .catch(() => ({ detail: 'Unknown error' }));
39
+ throw new Error(data.detail || `Failed to create agent: ${response.status}`);
40
+ }
41
+ const data = await response.json();
42
+ if (!cancelled) {
43
+ setAgentId(data.id);
44
+ setIsCreating(false);
45
+ }
46
+ }
47
+ catch (err) {
48
+ if (!cancelled) {
49
+ setError(err instanceof Error ? err.message : 'Failed to create agent');
50
+ setIsCreating(false);
51
+ }
52
+ }
53
+ };
54
+ createAgent();
55
+ return () => {
56
+ cancelled = true;
57
+ };
58
+ }, []);
59
+ useEffect(() => {
60
+ return () => {
61
+ if (!agentId) {
62
+ return;
63
+ }
64
+ void fetch(`${BASE_URL}/api/v1/agents/${encodeURIComponent(agentId)}`, {
65
+ method: 'DELETE',
66
+ }).catch(() => {
67
+ // Ignore teardown failures in example mode.
68
+ });
69
+ };
70
+ }, [agentId]);
71
+ if (isCreating) {
72
+ return (_jsx(ThemedProvider, { children: _jsxs(Box, { sx: {
73
+ display: 'flex',
74
+ flexDirection: 'column',
75
+ alignItems: 'center',
76
+ justifyContent: 'center',
77
+ height: '100vh',
78
+ gap: 3,
79
+ bg: 'canvas.default',
80
+ }, children: [_jsx(Spinner, { size: "large" }), _jsxs(Text, { sx: { color: 'fg.muted' }, children: ["Creating agent from ", AGENT_SPEC_ID, "..."] })] }) }));
81
+ }
82
+ if (error || !agentId) {
83
+ return (_jsx(ThemedProvider, { children: _jsx(ErrorView, { error: "Failed to start hooks agent", detail: error || 'No agent ID returned' }) }));
84
+ }
85
+ return (_jsx(Chat, { protocol: "vercel-ai", baseUrl: BASE_URL, agentId: agentId, title: "Hooks Agent", placeholder: "Ask about lifecycle hooks...", description: "Pre-hook installed 'rich', wrote a marker file, and set hook_name / hook_ran_at / hook_env variables in the sandbox", showHeader: true, showModelSelector: true, showToolsMenu: true, showSkillsMenu: true, showTokenUsage: true, showInformation: true, autoFocus: true, height: "100vh", runtimeId: agentId, historyEndpoint: `${BASE_URL}/api/v1/history`, suggestions: [
86
+ {
87
+ title: 'Read the pre-hook marker file',
88
+ message: 'Use execute_code to read /tmp/agent_runtimes_pre_hook_demo.txt and show its contents.',
89
+ },
90
+ {
91
+ title: 'Verify hook variables',
92
+ message: 'Use execute_code to run this verification:\n```python\nassert isinstance(hook_name, str) and hook_name == "demo-hooks:pre", f"❌ hook_name wrong: {hook_name!r}"\nassert isinstance(hook_ran_at, str) and len(hook_ran_at) > 0, f"❌ hook_ran_at wrong: {hook_ran_at!r}"\nassert isinstance(hook_env, dict) and len(hook_env) > 0, f"❌ hook_env wrong: {hook_env!r}"\nprint("✅ hook_name =", hook_name)\nprint("✅ hook_ran_at =", hook_ran_at)\nprint("✅ hook_env =", hook_env)\n```\nThrow an exception with a ❌ message if any variable is missing or has the wrong type, print ✅ lines if all pass.',
93
+ },
94
+ {
95
+ title: "Verify 'rich' was installed",
96
+ message: 'Use execute_code to import rich and print its version — the pre-hook installed it via pip.',
97
+ },
98
+ {
99
+ title: 'Explain the hook lifecycle',
100
+ message: 'What pre-hooks and post-hooks are configured for this agent, and when does each run?',
101
+ },
102
+ ], submitOnSuggestionClick: true }));
103
+ };
104
+ export default AgentHooksExample;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const AgentMCPExample: React.FC;
3
+ export default AgentMCPExample;
@@ -0,0 +1,480 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /*
3
+ * Copyright (c) 2025-2026 Datalayer, Inc.
4
+ * Distributed under the terms of the Modified BSD License.
5
+ */
6
+ /// <reference types="vite/client" />
7
+ import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
8
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
9
+ import { Box } from '@datalayer/primer-addons';
10
+ import { AuthRequiredView, ErrorView } from './components';
11
+ import { Heading, Label, Spinner, Text, Token as PrimerToken, } from '@primer/react';
12
+ import { GlobeIcon, CheckCircleIcon, ServerIcon, XCircleIcon, ToolsIcon, } from '@primer/octicons-react';
13
+ import { useSimpleAuthStore } from '@datalayer/core/lib/views/otel';
14
+ import { ThemedProvider } from './utils/themedProvider';
15
+ import { uniqueAgentId } from './utils/agentId';
16
+ import { Chat } from '../chat';
17
+ import { useAIAgentsWebSocket } from '../hooks';
18
+ import { parseAgentStreamMessage } from '../types/stream';
19
+ import { MCP_STATUS_COLORS, MCP_STATUS_LABELS } from '../types/mcp';
20
+ import { MCP_SERVER_LIBRARY } from '../specs/mcpServers';
21
+ const queryClient = new QueryClient();
22
+ const AGENT_NAME = 'mcp-demo-agent';
23
+ const AGENT_SPEC_ID = 'demo-mcp';
24
+ const DEFAULT_LOCAL_BASE_URL = import.meta.env.VITE_BASE_URL || 'http://localhost:8765';
25
+ /* ── Aggregate MCP status helpers ─────────────────────── */
26
+ function deriveAggregate(servers) {
27
+ if (!servers || servers.length === 0)
28
+ return 'none';
29
+ if (servers.some(s => s.status === 'starting'))
30
+ return 'starting';
31
+ if (servers.some(s => s.status === 'failed'))
32
+ return 'failed';
33
+ if (servers.every(s => s.status === 'started'))
34
+ return 'started';
35
+ return 'not_started';
36
+ }
37
+ /* ── Tool card ────────────────────────────────────────── */
38
+ const McpToolCard = ({ tool }) => {
39
+ const schemaProps = tool.inputSchema
40
+ ?.properties;
41
+ const paramNames = schemaProps ? Object.keys(schemaProps) : [];
42
+ return (_jsxs(Box, { sx: {
43
+ border: '1px solid',
44
+ borderColor: 'border.default',
45
+ borderRadius: 2,
46
+ p: 2,
47
+ mb: 2,
48
+ bg: 'canvas.default',
49
+ }, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 1 }, children: [_jsx(ToolsIcon, { size: 14 }), _jsx(Text, { sx: { fontWeight: 600, fontSize: 1 }, children: tool.name })] }), tool.description && (_jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mb: 1, mt: 0 }, children: tool.description })), _jsxs(Text, { sx: {
50
+ fontSize: 0,
51
+ fontFamily: 'mono',
52
+ color: 'fg.muted',
53
+ display: 'block',
54
+ }, children: ["server: ", tool.serverName] }), paramNames.length > 0 && (_jsx(Box, { sx: { mt: 1, display: 'flex', gap: 1, flexWrap: 'wrap' }, children: paramNames.map(p => (_jsx(PrimerToken, { text: p, size: "small" }, p))) }))] }));
55
+ };
56
+ /* ── Server status card ───────────────────────────────── */
57
+ const McpServerCard = ({ server }) => (_jsxs(Box, { sx: {
58
+ p: 2,
59
+ mb: 2,
60
+ border: '1px solid',
61
+ borderColor: 'border.default',
62
+ borderRadius: 2,
63
+ bg: 'canvas.default',
64
+ }, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 1 }, children: [server.emoji && _jsx(Text, { sx: { fontSize: 2 }, children: server.emoji }), _jsx(Text, { sx: { fontWeight: 600, fontSize: 1 }, children: server.name }), _jsx(Label, { size: "small", variant: server.status === 'started' ? 'success' : 'secondary', children: server.status })] }), server.description && (_jsx(Text, { as: "p", sx: { fontSize: 0, color: 'fg.muted', mt: 0, mb: 1 }, children: server.description })), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [server.toolsCount, " tool", server.toolsCount !== 1 ? 's' : '', " available"] })] }));
65
+ const McpStatusPanel = ({ data }) => {
66
+ const servers = data?.servers ?? [];
67
+ const aggregate = deriveAggregate(servers);
68
+ if (!data) {
69
+ return (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "Waiting for websocket snapshot..." }));
70
+ }
71
+ if (aggregate === 'none') {
72
+ return (_jsxs(Box, { sx: {
73
+ p: 2,
74
+ border: '1px solid',
75
+ borderColor: 'border.default',
76
+ borderRadius: 2,
77
+ display: 'flex',
78
+ alignItems: 'center',
79
+ gap: 2,
80
+ }, children: [_jsx(ServerIcon, { size: 16 }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: "No MCP server is defined for this agent." })] }));
81
+ }
82
+ return (_jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: [_jsxs(Box, { sx: {
83
+ display: 'flex',
84
+ alignItems: 'center',
85
+ gap: 2,
86
+ }, children: [_jsx(Box, { as: "span", sx: {
87
+ display: 'inline-block',
88
+ width: 10,
89
+ height: 10,
90
+ borderRadius: '50%',
91
+ bg: MCP_STATUS_COLORS[aggregate],
92
+ flexShrink: 0,
93
+ } }), _jsx(Text, { sx: { fontSize: 1 }, children: MCP_STATUS_LABELS[aggregate] })] }), servers.map(s => (_jsx(Box, { sx: {
94
+ p: 2,
95
+ border: '1px solid',
96
+ borderColor: 'border.default',
97
+ borderRadius: 2,
98
+ display: 'flex',
99
+ alignItems: 'center',
100
+ gap: 2,
101
+ }, children: _jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [s.status === 'started' ? (_jsx(CheckCircleIcon, { size: 14, fill: "success.fg" })) : s.status === 'failed' ? (_jsx(XCircleIcon, { size: 14, fill: "danger.fg" })) : (_jsx(Box, { as: "span", sx: {
102
+ width: 8,
103
+ height: 8,
104
+ borderRadius: '50%',
105
+ bg: MCP_STATUS_COLORS[s.status] ??
106
+ MCP_STATUS_COLORS.not_started,
107
+ display: 'inline-block',
108
+ } })), _jsx(Text, { sx: { fontSize: 1, fontWeight: 'bold' }, children: s.id })] }), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [s.status, s.status === 'started' && s.tools_count !== undefined
109
+ ? ` · ${s.tools_count} tool${s.tools_count !== 1 ? 's' : ''}`
110
+ : '', s.status === 'failed' && s.error ? ` — ${s.error}` : ''] })] }) }, s.id)))] }));
111
+ };
112
+ /* ── Main inner component ─────────────────────────────── */
113
+ const AgentMCPInner = ({ onLogout }) => {
114
+ const { token } = useSimpleAuthStore();
115
+ const agentName = useRef(uniqueAgentId(AGENT_NAME)).current;
116
+ const [runtimeStatus, setRuntimeStatus] = useState('launching');
117
+ const [isReady, setIsReady] = useState(false);
118
+ const [hookError, setHookError] = useState(null);
119
+ const [agentId, setAgentId] = useState(agentName);
120
+ const [isReconnectedAgent, setIsReconnectedAgent] = useState(false);
121
+ // MCP server IDs from the agent creation spec (e.g. ["tavily"])
122
+ const [selectedServerIds, setSelectedServerIds] = useState([]);
123
+ // Per-agent tool definitions from WS fullContext.tools
124
+ const [agentTools, setAgentTools] = useState([]);
125
+ // WS-provided mcpStatus (global – used as fallback for indicator)
126
+ const [liveMcpStatus, setLiveMcpStatus] = useState(undefined);
127
+ // Pending approvals are now managed internally by ChatBase via the Zustand
128
+ // agent-runtime store — no local state needed.
129
+ const agentBaseUrl = DEFAULT_LOCAL_BASE_URL;
130
+ const chatAuthToken = token === null ? undefined : token;
131
+ const authFetch = useCallback((url, opts = {}) => fetch(url, {
132
+ ...opts,
133
+ headers: {
134
+ 'Content-Type': 'application/json',
135
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
136
+ ...(opts.headers ?? {}),
137
+ },
138
+ }), [token]);
139
+ // ── Create agent ──────────────────────────────────────
140
+ useEffect(() => {
141
+ let isCancelled = false;
142
+ const createAgent = async () => {
143
+ setRuntimeStatus('launching');
144
+ setIsReady(false);
145
+ setHookError(null);
146
+ setIsReconnectedAgent(false);
147
+ try {
148
+ const response = await authFetch(`${agentBaseUrl}/api/v1/agents`, {
149
+ method: 'POST',
150
+ body: JSON.stringify({
151
+ name: agentName,
152
+ description: 'MCP demo agent – web crawling and research via Tavily',
153
+ agent_library: 'pydantic-ai',
154
+ transport: 'vercel-ai',
155
+ agent_spec_id: AGENT_SPEC_ID,
156
+ enable_codemode: false,
157
+ enable_skills: true,
158
+ tools: [],
159
+ }),
160
+ });
161
+ let resolvedAgentId = agentName;
162
+ let isAlreadyRunning = false;
163
+ if (response.ok) {
164
+ const data = await response.json();
165
+ resolvedAgentId = data?.id || agentName;
166
+ }
167
+ else {
168
+ const contentType = response.headers.get('content-type') || '';
169
+ let detail = '';
170
+ if (contentType.includes('application/json')) {
171
+ const data = await response.json().catch(() => null);
172
+ detail =
173
+ (typeof data?.detail === 'string' && data.detail) ||
174
+ (typeof data?.message === 'string' && data.message) ||
175
+ '';
176
+ }
177
+ else {
178
+ detail = await response.text();
179
+ }
180
+ if (response.status === 409 || /already exists/i.test(detail || '')) {
181
+ isAlreadyRunning = true;
182
+ }
183
+ else {
184
+ throw new Error(detail || `Failed to create agent: ${response.status}`);
185
+ }
186
+ }
187
+ if (!isCancelled) {
188
+ setAgentId(resolvedAgentId);
189
+ setIsReconnectedAgent(isAlreadyRunning);
190
+ setIsReady(true);
191
+ setRuntimeStatus('ready');
192
+ }
193
+ }
194
+ catch (error) {
195
+ if (!isCancelled) {
196
+ setHookError(error instanceof Error ? error.message : 'Agent failed to start');
197
+ setRuntimeStatus('error');
198
+ }
199
+ }
200
+ };
201
+ void createAgent();
202
+ return () => {
203
+ isCancelled = true;
204
+ };
205
+ }, [agentBaseUrl, agentName, authFetch]);
206
+ // ── WebSocket: receive MCP status + fullContext tools from agent.snapshot ─
207
+ const handleSnapshotMessage = useCallback((message) => {
208
+ try {
209
+ const stream = parseAgentStreamMessage(message?.raw ?? message);
210
+ if (!stream || stream.type !== 'agent.snapshot')
211
+ return;
212
+ const payload = stream.payload;
213
+ if (payload.mcpStatus !== undefined) {
214
+ setLiveMcpStatus(payload.mcpStatus ?? undefined);
215
+ }
216
+ // Extract per-agent tool definitions from fullContext.tools
217
+ const fc = payload.fullContext;
218
+ if (fc && Array.isArray(fc.tools) && fc.tools.length > 0) {
219
+ setAgentTools(fc.tools);
220
+ }
221
+ }
222
+ catch {
223
+ // Ignore malformed payloads.
224
+ }
225
+ }, []);
226
+ useAIAgentsWebSocket({
227
+ enabled: isReady && Boolean(agentBaseUrl),
228
+ baseUrl: agentBaseUrl,
229
+ path: '/api/v1/tool-approvals/ws',
230
+ queryParams: { agent_id: agentId },
231
+ onMessage: handleSnapshotMessage,
232
+ reconnectDelayMs: attempt => Math.min(1000 * 2 ** Math.max(0, attempt - 1), 10000),
233
+ });
234
+ // ── Fetch creation spec to get selected MCP server IDs ──
235
+ useEffect(() => {
236
+ if (!isReady)
237
+ return;
238
+ const fetchSpec = async () => {
239
+ try {
240
+ const res = await authFetch(`${agentBaseUrl}/api/v1/configure/agents/${agentId}/spec`);
241
+ if (!res.ok)
242
+ return;
243
+ const spec = await res.json();
244
+ const servers = (spec?.selected_mcp_servers ?? []);
245
+ setSelectedServerIds(servers.map(s => s.id));
246
+ }
247
+ catch {
248
+ // Non-fatal: sidebar info is informational
249
+ }
250
+ };
251
+ void fetchSpec();
252
+ }, [isReady, agentId, agentBaseUrl, authFetch]);
253
+ // ── Build McpServerInfo[] from selected servers + catalog + WS tools ──
254
+ const mcpServers = useMemo(() => {
255
+ if (selectedServerIds.length === 0)
256
+ return [];
257
+ return selectedServerIds.map(serverId => {
258
+ const catalogServer = MCP_SERVER_LIBRARY[serverId];
259
+ const serverName = catalogServer?.name ?? serverId;
260
+ // Live status from WS snapshot — the most reliable source of truth.
261
+ const liveServer = liveMcpStatus?.servers?.find(s => s.id === serverId);
262
+ // Match tools by prefix convention: "tavily__tavily_search" → server "tavily"
263
+ // (fallback when live data is not yet available)
264
+ const serverTools = agentTools
265
+ .filter(t => t.name.startsWith(`${serverId}__`))
266
+ .map(t => ({
267
+ name: t.name,
268
+ description: t.description,
269
+ serverId,
270
+ serverName,
271
+ inputSchema: t.parametersSchema,
272
+ }));
273
+ // Prefer live tools from WS snapshot; fall back to agentTools-derived tools.
274
+ const toolsFromLive = (liveServer?.tools ?? []).map(t => ({
275
+ name: t.name,
276
+ description: t.description ?? '',
277
+ serverId,
278
+ serverName,
279
+ inputSchema: undefined,
280
+ }));
281
+ const tools = toolsFromLive.length > 0 ? toolsFromLive : serverTools;
282
+ const status = liveServer?.status ?? (serverTools.length > 0 ? 'started' : 'starting');
283
+ const toolsCount = liveServer?.tools_count ?? tools.length;
284
+ return {
285
+ id: serverId,
286
+ name: serverName,
287
+ description: catalogServer?.description,
288
+ status,
289
+ toolsCount,
290
+ tools,
291
+ emoji: catalogServer?.emoji,
292
+ icon: catalogServer?.icon,
293
+ };
294
+ });
295
+ }, [selectedServerIds, agentTools, liveMcpStatus]);
296
+ // ── Build synthetic McpToolsetsStatusResponse for the Chat MCP indicator ──
297
+ const mcpStatusData = useMemo(() => {
298
+ const derivedEnabledToolsByServer = {};
299
+ const derivedApprovedToolsByServer = {};
300
+ for (const s of mcpServers) {
301
+ if (s.tools.length > 0) {
302
+ derivedEnabledToolsByServer[s.id] = s.tools.map(t => t.name);
303
+ // Keep approval default explicit: enabled but not approved.
304
+ derivedApprovedToolsByServer[s.id] = [];
305
+ }
306
+ }
307
+ // If the WS-provided global mcpStatus has actual servers, prefer it
308
+ if (liveMcpStatus && liveMcpStatus.servers.length > 0) {
309
+ const live = liveMcpStatus;
310
+ const enabledToolsByServer = {
311
+ ...(live.enabled_tools_by_server ?? {}),
312
+ };
313
+ for (const [serverId, tools] of Object.entries(derivedEnabledToolsByServer)) {
314
+ if (!enabledToolsByServer[serverId] ||
315
+ enabledToolsByServer[serverId].length === 0) {
316
+ enabledToolsByServer[serverId] = tools;
317
+ }
318
+ }
319
+ const approvedToolsByServer = {
320
+ ...(live.approved_tools_by_server ?? {}),
321
+ };
322
+ for (const [serverId, tools] of Object.entries(derivedApprovedToolsByServer)) {
323
+ if (!approvedToolsByServer[serverId]) {
324
+ approvedToolsByServer[serverId] = tools;
325
+ }
326
+ }
327
+ return {
328
+ ...live,
329
+ enabled_tools_by_server: enabledToolsByServer,
330
+ approved_tools_by_server: approvedToolsByServer,
331
+ };
332
+ }
333
+ // Otherwise build from our per-agent derived info
334
+ if (mcpServers.length === 0)
335
+ return undefined;
336
+ const servers = mcpServers.map(s => ({
337
+ id: s.id,
338
+ status: s.status,
339
+ tools_count: s.toolsCount,
340
+ tools: s.tools.map(t => ({
341
+ name: t.name,
342
+ description: t.description,
343
+ enabled: true,
344
+ })),
345
+ }));
346
+ const readyServers = servers
347
+ .filter(s => s.status === 'started')
348
+ .map(s => s.id);
349
+ // Build enabled_tools_by_server so the InputFooter ToolsMenu can render
350
+ // tools as enabled immediately on first open.
351
+ const enabledToolsByServer = derivedEnabledToolsByServer;
352
+ const approvedToolsByServer = derivedApprovedToolsByServer;
353
+ return {
354
+ initialized: true,
355
+ ready_count: readyServers.length,
356
+ failed_count: servers.filter(s => s.status === 'failed').length,
357
+ ready_servers: readyServers,
358
+ failed_servers: {},
359
+ servers,
360
+ enabled_tools_by_server: enabledToolsByServer,
361
+ approved_tools_by_server: approvedToolsByServer,
362
+ enabled_tools_count: mcpServers.reduce((sum, s) => sum + s.tools.length, 0),
363
+ };
364
+ }, [liveMcpStatus, mcpServers]);
365
+ const totalTools = mcpServers.reduce((sum, s) => sum + s.toolsCount, 0);
366
+ const aggregate = deriveAggregate(mcpStatusData?.servers ?? []);
367
+ if (!isReady && runtimeStatus !== 'error') {
368
+ return (_jsxs(Box, { sx: {
369
+ display: 'flex',
370
+ flexDirection: 'column',
371
+ alignItems: 'center',
372
+ justifyContent: 'center',
373
+ height: '100vh',
374
+ gap: 3,
375
+ }, children: [_jsx(Spinner, { size: "large" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: "Launching MCP demo agent..." })] }));
376
+ }
377
+ if (runtimeStatus === 'error' || hookError) {
378
+ return _jsx(ErrorView, { error: hookError, onLogout: onLogout });
379
+ }
380
+ return (_jsxs(Box, { sx: {
381
+ height: 'calc(100vh - 60px)',
382
+ display: 'flex',
383
+ flexDirection: 'column',
384
+ }, children: [isReconnectedAgent && (_jsx(Box, { sx: {
385
+ px: 3,
386
+ py: 1,
387
+ borderBottom: '1px solid',
388
+ borderColor: 'border.default',
389
+ }, children: _jsx(Text, { sx: { color: 'fg.muted', fontSize: 0 }, children: "Agent already running - reconnected." }) })), _jsxs(Box, { sx: { flex: 1, minHeight: 0, display: 'flex' }, children: [_jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: _jsx(Chat, { protocol: "vercel-ai", baseUrl: agentBaseUrl, agentId: agentId, authToken: chatAuthToken, title: "MCP Demo Agent", placeholder: "Ask the agent to search the web or explore GitHub...", showHeader: true, showNewChatButton: true, showClearButton: false, showToolsMenu: true, showSkillsMenu: true, showTokenUsage: true, autoFocus: true, height: "100%", runtimeId: agentId, historyEndpoint: `${agentBaseUrl}/api/v1/history`, mcpStatusData: mcpStatusData, showToolApprovalBanner: true, headerActions: _jsx(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2 }, children: _jsxs(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: ["MCP Tools: ", totalTools] }) }), suggestions: [
390
+ {
391
+ title: '🔍 Search the web',
392
+ message: 'Search the web for recent news about AI agents.',
393
+ },
394
+ {
395
+ title: '🐙 GitHub repos',
396
+ message: 'Find trending open-source Python projects on GitHub.',
397
+ },
398
+ {
399
+ title: '📚 Research topic',
400
+ message: 'Research best practices for building RAG applications.',
401
+ },
402
+ {
403
+ title: '⚡ Compare frameworks',
404
+ message: 'Compare popular JavaScript frameworks in 2024.',
405
+ },
406
+ {
407
+ title: '😄 Tell me a joke',
408
+ message: 'Use your jokes skill to tell me a random joke.',
409
+ },
410
+ ], submitOnSuggestionClick: true }) }), _jsxs(Box, { sx: {
411
+ width: 320,
412
+ minWidth: 260,
413
+ borderLeft: '1px solid',
414
+ borderColor: 'border.default',
415
+ display: 'flex',
416
+ flexDirection: 'column',
417
+ minHeight: 0,
418
+ bg: 'canvas.subtle',
419
+ }, children: [_jsxs(Box, { sx: {
420
+ p: 2,
421
+ borderBottom: '1px solid',
422
+ borderColor: 'border.default',
423
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 1 }, children: _jsxs(Box, { sx: { display: 'inline-flex', alignItems: 'center', gap: 1 }, children: [_jsx(ServerIcon, { size: 16 }), "MCP Servers & Tools"] }) }), _jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2 }, children: [_jsx(Box, { as: "span", sx: {
424
+ display: 'inline-block',
425
+ width: 8,
426
+ height: 8,
427
+ borderRadius: '50%',
428
+ bg: MCP_STATUS_COLORS[aggregate],
429
+ flexShrink: 0,
430
+ } }), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [MCP_STATUS_LABELS[aggregate], " \u00B7 ", totalTools, " tool", totalTools !== 1 ? 's' : ''] })] })] }), _jsxs(Box, { sx: { p: 2, overflow: 'auto', flex: 1 }, children: [_jsxs(Box, { sx: { mb: 3 }, children: [_jsx(Heading, { as: "h5", sx: { fontSize: 1, mb: 2 }, children: "MCP Servers" }), _jsx(McpStatusPanel, { data: mcpStatusData })] }), mcpServers.length === 0 ? (_jsxs(Box, { sx: {
431
+ display: 'flex',
432
+ flexDirection: 'column',
433
+ alignItems: 'center',
434
+ gap: 2,
435
+ py: 4,
436
+ }, children: [_jsx(Spinner, { size: "medium" }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: "Waiting for MCP servers to start..." })] })) : (_jsxs(_Fragment, { children: [mcpServers.map(server => (_jsxs(Box, { children: [_jsx(McpServerCard, { server: server }), server.tools.length > 0 && (_jsx(Box, { sx: { pl: 2 }, children: server.tools.map(tool => (_jsx(McpToolCard, { tool: tool }, `${tool.serverId}-${tool.name}`))) }))] }, server.id))), _jsxs(Box, { sx: {
437
+ mt: 3,
438
+ p: 2,
439
+ borderRadius: 2,
440
+ bg: 'canvas.inset',
441
+ border: '1px solid',
442
+ borderColor: 'border.muted',
443
+ }, children: [_jsx(Heading, { as: "h5", sx: { fontSize: 0, mb: 1 }, children: "MCP (Model Context Protocol)" }), _jsxs(Box, { sx: { fontSize: 0, color: 'fg.muted' }, children: [_jsxs(Box, { sx: {
444
+ display: 'flex',
445
+ alignItems: 'center',
446
+ gap: 1,
447
+ mb: 1,
448
+ }, children: [_jsx(GlobeIcon, { size: 12 }), _jsxs(Text, { children: [_jsx("strong", { children: "Servers:" }), " Discover and start MCP servers that expose tools to the agent"] })] }), _jsxs(Box, { sx: {
449
+ display: 'flex',
450
+ alignItems: 'center',
451
+ gap: 1,
452
+ }, children: [_jsx(ToolsIcon, { size: 12 }), _jsxs(Text, { children: [_jsx("strong", { children: "Tools:" }), " Individual capabilities exposed by each server (search, fetch, etc.)"] })] })] })] })] }))] })] })] })] }));
453
+ };
454
+ const syncTokenToIamStore = (token) => {
455
+ import('@datalayer/core/lib/state').then(({ iamStore }) => {
456
+ iamStore.setState({ token });
457
+ });
458
+ };
459
+ const AgentMCPExample = () => {
460
+ const { token, clearAuth } = useSimpleAuthStore();
461
+ const hasSynced = useRef(false);
462
+ useEffect(() => {
463
+ if (token && !hasSynced.current) {
464
+ hasSynced.current = true;
465
+ syncTokenToIamStore(token);
466
+ }
467
+ }, [token]);
468
+ const handleLogout = useCallback(() => {
469
+ clearAuth();
470
+ hasSynced.current = false;
471
+ import('@datalayer/core/lib/state').then(({ iamStore }) => {
472
+ iamStore.setState({ token: undefined });
473
+ });
474
+ }, [clearAuth]);
475
+ if (!token) {
476
+ return (_jsx(ThemedProvider, { children: _jsx(AuthRequiredView, {}) }));
477
+ }
478
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThemedProvider, { children: _jsx(AgentMCPInner, { onLogout: handleLogout }) }) }));
479
+ };
480
+ export default AgentMCPExample;