@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.
Files changed (299) hide show
  1. package/README.md +182 -1
  2. package/lib/AgentNode.d.ts +3 -0
  3. package/lib/AgentNode.js +676 -0
  4. package/lib/App.js +1 -1
  5. package/lib/agent-node/themeStore.d.ts +3 -0
  6. package/lib/agent-node/themeStore.js +156 -0
  7. package/lib/agent-node-main.d.ts +1 -0
  8. package/lib/agent-node-main.js +14 -0
  9. package/lib/agents/AgentDetails.d.ts +22 -1
  10. package/lib/agents/AgentDetails.js +34 -47
  11. package/lib/api/index.d.ts +0 -1
  12. package/lib/api/index.js +4 -2
  13. package/lib/chat/Chat.d.ts +5 -106
  14. package/lib/chat/Chat.js +20 -14
  15. package/lib/chat/ChatFloating.d.ts +7 -140
  16. package/lib/chat/ChatFloating.js +3 -3
  17. package/lib/chat/ChatPopupStandalone.d.ts +8 -47
  18. package/lib/chat/ChatPopupStandalone.js +3 -3
  19. package/lib/chat/ChatSidebar.d.ts +4 -69
  20. package/lib/chat/ChatSidebar.js +83 -51
  21. package/lib/chat/ChatStandalone.d.ts +4 -54
  22. package/lib/chat/ChatStandalone.js +3 -3
  23. package/lib/chat/base/ChatBase.js +1414 -174
  24. package/lib/chat/display/FloatingBrandButton.js +8 -1
  25. package/lib/chat/header/ChatHeader.d.ts +3 -1
  26. package/lib/chat/header/ChatHeader.js +15 -12
  27. package/lib/chat/header/ChatHeaderBase.d.ts +30 -5
  28. package/lib/chat/header/ChatHeaderBase.js +41 -16
  29. package/lib/chat/indicators/McpStatusIndicator.d.ts +7 -4
  30. package/lib/chat/indicators/McpStatusIndicator.js +7 -32
  31. package/lib/chat/indicators/SandboxStatusIndicator.d.ts +4 -1
  32. package/lib/chat/indicators/SandboxStatusIndicator.js +91 -56
  33. package/lib/chat/indicators/SkillsStatusIndicator.d.ts +7 -0
  34. package/lib/chat/indicators/SkillsStatusIndicator.js +88 -0
  35. package/lib/chat/indicators/index.d.ts +1 -0
  36. package/lib/chat/indicators/index.js +1 -0
  37. package/lib/chat/messages/ChatMessageList.d.ts +1 -1
  38. package/lib/chat/messages/ChatMessageList.js +154 -114
  39. package/lib/chat/messages/ChatMessages.js +6 -2
  40. package/lib/chat/prompt/InputFooter.d.ts +21 -6
  41. package/lib/chat/prompt/InputFooter.js +76 -20
  42. package/lib/chat/prompt/InputPrompt.d.ts +5 -1
  43. package/lib/chat/prompt/InputPrompt.js +4 -4
  44. package/lib/chat/prompt/InputPromptFooter.d.ts +3 -1
  45. package/lib/chat/prompt/InputPromptFooter.js +3 -3
  46. package/lib/chat/prompt/InputPromptLexical.d.ts +3 -1
  47. package/lib/chat/prompt/InputPromptLexical.js +12 -5
  48. package/lib/chat/prompt/InputPromptText.d.ts +3 -1
  49. package/lib/chat/prompt/InputPromptText.js +2 -2
  50. package/lib/chat/tools/ToolApprovalBanner.js +1 -1
  51. package/lib/chat/tools/ToolCallDisplay.d.ts +3 -1
  52. package/lib/chat/tools/ToolCallDisplay.js +2 -2
  53. package/lib/chat/usage/TokenUsageBar.js +20 -2
  54. package/lib/client/AgentRuntimesClientContext.d.ts +53 -0
  55. package/lib/client/AgentRuntimesClientContext.js +55 -0
  56. package/lib/client/AgentsMixin.d.ts +0 -18
  57. package/lib/client/AgentsMixin.js +20 -30
  58. package/lib/client/IAgentRuntimesClient.d.ts +215 -0
  59. package/lib/client/IAgentRuntimesClient.js +5 -0
  60. package/lib/client/SdkAgentRuntimesClient.d.ts +151 -0
  61. package/lib/client/SdkAgentRuntimesClient.js +134 -0
  62. package/lib/client/index.d.ts +4 -1
  63. package/lib/client/index.js +3 -1
  64. package/lib/components/NotificationEventCard.js +5 -1
  65. package/lib/config/AgentConfiguration.d.ts +22 -0
  66. package/lib/config/AgentConfiguration.js +319 -64
  67. package/lib/context/ContextDistribution.d.ts +3 -1
  68. package/lib/context/ContextDistribution.js +8 -27
  69. package/lib/context/ContextInspector.d.ts +3 -1
  70. package/lib/context/ContextInspector.js +19 -67
  71. package/lib/context/ContextPanel.d.ts +3 -1
  72. package/lib/context/ContextPanel.js +104 -64
  73. package/lib/context/ContextUsage.d.ts +3 -1
  74. package/lib/context/ContextUsage.js +3 -3
  75. package/lib/context/CostTracker.d.ts +9 -3
  76. package/lib/context/CostTracker.js +26 -47
  77. package/lib/context/CostUsageChart.d.ts +12 -0
  78. package/lib/context/CostUsageChart.js +378 -0
  79. package/lib/context/GraphFlowChart.d.ts +16 -0
  80. package/lib/context/GraphFlowChart.js +182 -0
  81. package/lib/context/TokenUsageChart.d.ts +8 -1
  82. package/lib/context/TokenUsageChart.js +349 -211
  83. package/lib/context/TurnGraphChart.d.ts +39 -0
  84. package/lib/context/TurnGraphChart.js +538 -0
  85. package/lib/context/otelWsPool.d.ts +20 -0
  86. package/lib/context/otelWsPool.js +69 -0
  87. package/lib/examples/A2UiComponentGalleryExample.d.ts +0 -17
  88. package/lib/examples/A2UiComponentGalleryExample.js +315 -522
  89. package/lib/examples/A2UiContactCardExample.d.ts +0 -18
  90. package/lib/examples/A2UiContactCardExample.js +154 -411
  91. package/lib/examples/A2UiRestaurantExample.d.ts +0 -30
  92. package/lib/examples/A2UiRestaurantExample.js +114 -212
  93. package/lib/examples/A2UiViewerExample.d.ts +0 -18
  94. package/lib/examples/A2UiViewerExample.js +283 -532
  95. package/lib/examples/AgUiBackendToolRenderingExample.js +1 -1
  96. package/lib/examples/AgUiHaikuGenUiExample.d.ts +1 -1
  97. package/lib/examples/AgUiHaikuGenUiExample.js +1 -1
  98. package/lib/examples/AgUiSharedStateExample.js +2 -1
  99. package/lib/examples/AgentCheckpointsExample.js +14 -28
  100. package/lib/examples/AgentCodemodeExample.d.ts +4 -6
  101. package/lib/examples/AgentCodemodeExample.js +603 -169
  102. package/lib/examples/AgentEvalsExample.js +339 -53
  103. package/lib/examples/AgentGuardrailsExample.js +383 -66
  104. package/lib/examples/AgentHooksExample.d.ts +3 -0
  105. package/lib/examples/AgentHooksExample.js +122 -0
  106. package/lib/examples/AgentInferenceProviderExample.d.ts +3 -0
  107. package/lib/examples/AgentInferenceProviderExample.js +329 -0
  108. package/lib/examples/AgentMCPExample.d.ts +3 -0
  109. package/lib/examples/AgentMCPExample.js +481 -0
  110. package/lib/examples/AgentMemoryExample.d.ts +1 -2
  111. package/lib/examples/AgentMemoryExample.js +78 -33
  112. package/lib/examples/AgentMonitoringExample.js +261 -200
  113. package/lib/examples/AgentNotificationsExample.d.ts +1 -2
  114. package/lib/examples/AgentNotificationsExample.js +114 -33
  115. package/lib/examples/AgentOtelExample.js +32 -42
  116. package/lib/examples/AgentOutputsExample.d.ts +11 -6
  117. package/lib/examples/AgentOutputsExample.js +433 -81
  118. package/lib/examples/AgentParametersExample.d.ts +3 -0
  119. package/lib/examples/AgentParametersExample.js +248 -0
  120. package/lib/examples/AgentSandboxExample.d.ts +3 -3
  121. package/lib/examples/AgentSandboxExample.js +74 -45
  122. package/lib/examples/AgentSkillsExample.js +95 -103
  123. package/lib/examples/AgentSubagentsExample.d.ts +14 -0
  124. package/lib/examples/AgentSubagentsExample.js +228 -0
  125. package/lib/examples/AgentToolApprovalsExample.js +49 -561
  126. package/lib/examples/AgentTriggersExample.js +823 -569
  127. package/lib/examples/{AgentspecExample.d.ts โ†’ AgentspecsExample.d.ts} +2 -2
  128. package/lib/examples/AgentspecsExample.js +1096 -0
  129. package/lib/examples/ChatCustomExample.js +16 -28
  130. package/lib/examples/ChatExample.js +13 -29
  131. package/lib/examples/CopilotKitLexicalExample.js +2 -1
  132. package/lib/examples/CopilotKitNotebookExample.js +2 -1
  133. package/lib/examples/HomeExample.d.ts +15 -0
  134. package/lib/examples/HomeExample.js +77 -0
  135. package/lib/examples/Lexical2Example.js +4 -2
  136. package/lib/examples/{LexicalExample.d.ts โ†’ LexicalAgentExample.d.ts} +4 -4
  137. package/lib/examples/{LexicalExample.js โ†’ LexicalAgentExample.js} +66 -17
  138. package/lib/examples/{LexicalSidebarExample.d.ts โ†’ LexicalAgentSidebarExample.d.ts} +5 -5
  139. package/lib/examples/LexicalAgentSidebarExample.js +261 -0
  140. package/lib/examples/NotebookAgentExample.d.ts +9 -0
  141. package/lib/examples/NotebookAgentExample.js +192 -0
  142. package/lib/examples/{NotebookSidebarExample.d.ts โ†’ NotebookAgentSidebarExample.d.ts} +2 -2
  143. package/lib/examples/NotebookAgentSidebarExample.js +221 -0
  144. package/lib/examples/{DatalayerNotebookExample.d.ts โ†’ NotebookCollaborationExample.d.ts} +4 -4
  145. package/lib/examples/{DatalayerNotebookExample.js โ†’ NotebookCollaborationExample.js} +3 -3
  146. package/lib/examples/NotebookExample.d.ts +4 -7
  147. package/lib/examples/NotebookExample.js +14 -146
  148. package/lib/examples/components/AuthRequiredView.d.ts +6 -0
  149. package/lib/examples/components/AuthRequiredView.js +33 -0
  150. package/lib/examples/components/ExampleWrapper.d.ts +9 -3
  151. package/lib/examples/components/ExampleWrapper.js +45 -9
  152. package/lib/examples/{ag-ui โ†’ components}/haiku/HaikuDisplay.js +1 -1
  153. package/lib/examples/{ag-ui โ†’ components}/haiku/InlineHaikuCard.js +1 -1
  154. package/lib/examples/{ag-ui โ†’ components}/haiku/index.d.ts +1 -1
  155. package/lib/examples/{ag-ui โ†’ components}/haiku/index.js +1 -1
  156. package/lib/examples/components/index.d.ts +3 -0
  157. package/lib/examples/components/index.js +4 -0
  158. package/lib/examples/{ag-ui โ†’ components}/weather/index.d.ts +1 -1
  159. package/lib/examples/{ag-ui โ†’ components}/weather/index.js +1 -1
  160. package/lib/examples/example-selector.d.ts +17 -4
  161. package/lib/examples/example-selector.js +108 -41
  162. package/lib/examples/index.d.ts +10 -6
  163. package/lib/examples/index.js +10 -6
  164. package/lib/examples/lexical/initial-content.json +6 -6
  165. package/lib/examples/main.js +257 -27
  166. package/lib/examples/utils/a2ui.d.ts +18 -0
  167. package/lib/examples/utils/a2ui.js +69 -0
  168. package/lib/examples/utils/a2uiMarkdownProvider.d.ts +7 -0
  169. package/lib/examples/utils/a2uiMarkdownProvider.js +9 -0
  170. package/lib/examples/utils/agentId.d.ts +18 -0
  171. package/lib/examples/utils/agentId.js +54 -0
  172. package/lib/examples/utils/agents/earthquake-detector.json +11 -11
  173. package/lib/examples/utils/agents/sales-forecaster.json +11 -11
  174. package/lib/examples/utils/agents/social-post-generator.json +11 -11
  175. package/lib/examples/utils/agents/stock-market.json +11 -11
  176. package/lib/examples/utils/examplesStore.js +82 -27
  177. package/lib/examples/utils/useExampleAgentRuntimesUrl.d.ts +5 -0
  178. package/lib/examples/utils/useExampleAgentRuntimesUrl.js +19 -0
  179. package/lib/hooks/index.d.ts +8 -8
  180. package/lib/hooks/index.js +7 -7
  181. package/lib/hooks/useA2A.d.ts +2 -3
  182. package/lib/hooks/useAIAgentsWebSocket.d.ts +43 -4
  183. package/lib/hooks/useAIAgentsWebSocket.js +153 -12
  184. package/lib/hooks/useAcp.d.ts +1 -2
  185. package/lib/hooks/useAgUi.d.ts +1 -1
  186. package/lib/hooks/{useAgents.d.ts โ†’ useAgentRuntimes.d.ts} +70 -4
  187. package/lib/hooks/{useAgents.js โ†’ useAgentRuntimes.js} +237 -32
  188. package/lib/hooks/useAgentsCatalog.js +1 -1
  189. package/lib/hooks/useAgentsService.d.ts +2 -2
  190. package/lib/hooks/useAgentsService.js +7 -7
  191. package/lib/hooks/useCheckpoints.js +1 -1
  192. package/lib/hooks/useConfig.d.ts +4 -1
  193. package/lib/hooks/useConfig.js +10 -3
  194. package/lib/hooks/useContextSnapshot.d.ts +9 -4
  195. package/lib/hooks/useContextSnapshot.js +9 -37
  196. package/lib/hooks/useMonitoring.js +3 -0
  197. package/lib/hooks/useSandbox.d.ts +20 -8
  198. package/lib/hooks/useSandbox.js +105 -40
  199. package/lib/hooks/useSkills.d.ts +23 -5
  200. package/lib/hooks/useSkills.js +94 -39
  201. package/lib/hooks/useToolApprovals.d.ts +60 -36
  202. package/lib/hooks/useToolApprovals.js +318 -69
  203. package/lib/hooks/useVercelAI.d.ts +1 -1
  204. package/lib/index.d.ts +2 -1
  205. package/lib/index.js +1 -0
  206. package/lib/inference/index.d.ts +0 -1
  207. package/lib/middleware/index.d.ts +0 -1
  208. package/lib/protocols/AGUIAdapter.js +6 -0
  209. package/lib/protocols/VercelAIAdapter.d.ts +7 -0
  210. package/lib/protocols/VercelAIAdapter.js +59 -7
  211. package/lib/specs/agents/agents.d.ts +21 -4
  212. package/lib/specs/agents/agents.js +2879 -316
  213. package/lib/specs/agents/index.js +3 -1
  214. package/lib/specs/benchmarks.d.ts +20 -0
  215. package/lib/specs/benchmarks.js +205 -0
  216. package/lib/specs/envvars.js +27 -20
  217. package/lib/specs/evals.d.ts +10 -9
  218. package/lib/specs/evals.js +128 -88
  219. package/lib/specs/events.d.ts +3 -10
  220. package/lib/specs/events.js +127 -84
  221. package/lib/specs/frontendTools.js +2 -2
  222. package/lib/specs/guardrails.d.ts +0 -7
  223. package/lib/specs/guardrails.js +240 -159
  224. package/lib/specs/mcpServers.js +35 -6
  225. package/lib/specs/memory.d.ts +0 -2
  226. package/lib/specs/memory.js +4 -17
  227. package/lib/specs/models.d.ts +0 -2
  228. package/lib/specs/models.js +20 -15
  229. package/lib/specs/notifications.js +102 -18
  230. package/lib/specs/outputs.js +15 -9
  231. package/lib/specs/personas.d.ts +41 -0
  232. package/lib/specs/personas.js +168 -0
  233. package/lib/specs/skills.d.ts +1 -1
  234. package/lib/specs/skills.js +23 -23
  235. package/lib/specs/teams/index.js +3 -1
  236. package/lib/specs/teams/teams.js +468 -348
  237. package/lib/specs/tools.js +4 -4
  238. package/lib/specs/triggers.js +61 -11
  239. package/lib/stores/agentRuntimeStore.d.ts +208 -0
  240. package/lib/stores/agentRuntimeStore.js +650 -0
  241. package/lib/stores/conversationStore.js +2 -2
  242. package/lib/stores/index.d.ts +1 -1
  243. package/lib/stores/index.js +1 -1
  244. package/lib/tools/adapters/copilotkit/lexicalHooks.d.ts +1 -2
  245. package/lib/tools/adapters/copilotkit/lexicalHooks.js +1 -3
  246. package/lib/tools/adapters/copilotkit/notebookHooks.d.ts +1 -2
  247. package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -3
  248. package/lib/tools/index.d.ts +0 -2
  249. package/lib/tools/index.js +0 -1
  250. package/lib/types/agents-lifecycle.d.ts +18 -0
  251. package/lib/types/agents.d.ts +6 -0
  252. package/lib/types/agentspecs.d.ts +54 -1
  253. package/lib/types/benchmarks.d.ts +43 -0
  254. package/lib/types/benchmarks.js +5 -0
  255. package/lib/types/chat.d.ts +325 -8
  256. package/lib/types/context.d.ts +27 -0
  257. package/lib/types/cost.d.ts +2 -2
  258. package/lib/types/evals.d.ts +26 -17
  259. package/lib/types/index.d.ts +3 -0
  260. package/lib/types/index.js +3 -0
  261. package/lib/types/mcp.d.ts +8 -0
  262. package/lib/types/models.d.ts +2 -2
  263. package/lib/types/personas.d.ts +25 -0
  264. package/lib/types/personas.js +5 -0
  265. package/lib/types/skills.d.ts +43 -1
  266. package/lib/types/stream.d.ts +110 -0
  267. package/lib/types/stream.js +36 -0
  268. package/lib/utils/utils.d.ts +9 -5
  269. package/lib/utils/utils.js +9 -5
  270. package/package.json +19 -11
  271. package/scripts/codegen/__pycache__/generate_agents.cpython-313.pyc +0 -0
  272. package/scripts/codegen/__pycache__/generate_benchmarks.cpython-313.pyc +0 -0
  273. package/scripts/codegen/__pycache__/generate_evals.cpython-313.pyc +0 -0
  274. package/scripts/codegen/__pycache__/generate_events.cpython-313.pyc +0 -0
  275. package/scripts/codegen/__pycache__/versioning.cpython-313.pyc +0 -0
  276. package/scripts/codegen/generate_agents.py +187 -45
  277. package/scripts/codegen/generate_benchmarks.py +441 -0
  278. package/scripts/codegen/generate_evals.py +94 -16
  279. package/scripts/codegen/generate_events.py +35 -14
  280. package/scripts/codegen/generate_personas.py +319 -0
  281. package/scripts/codegen/generate_skills.py +9 -9
  282. package/scripts/sync-jupyter.sh +26 -7
  283. package/lib/api/tool-approvals.d.ts +0 -62
  284. package/lib/api/tool-approvals.js +0 -145
  285. package/lib/examples/AgentspecExample.js +0 -705
  286. package/lib/examples/LexicalSidebarExample.js +0 -163
  287. package/lib/examples/NotebookSidebarExample.js +0 -119
  288. package/lib/examples/NotebookSimpleExample.d.ts +0 -6
  289. package/lib/examples/NotebookSimpleExample.js +0 -22
  290. package/lib/examples/ag-ui/index.d.ts +0 -10
  291. package/lib/examples/ag-ui/index.js +0 -16
  292. package/lib/hooks/useAgentsRegistry.d.ts +0 -10
  293. package/lib/hooks/useAgentsRegistry.js +0 -20
  294. package/lib/stores/agentsStore.d.ts +0 -123
  295. package/lib/stores/agentsStore.js +0 -270
  296. /package/lib/examples/{ag-ui โ†’ components}/haiku/HaikuDisplay.d.ts +0 -0
  297. /package/lib/examples/{ag-ui โ†’ components}/haiku/InlineHaikuCard.d.ts +0 -0
  298. /package/lib/examples/{ag-ui โ†’ components}/weather/InlineWeatherCard.d.ts +0 -0
  299. /package/lib/examples/{ag-ui โ†’ components}/weather/InlineWeatherCard.js +0 -0
@@ -16,142 +16,57 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
16
  /// <reference types="vite/client" />
17
17
  import { useEffect, useState, useCallback, useRef } from 'react';
18
18
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
19
- import { Text, Button, Spinner, Heading, Label } from '@primer/react';
20
- import { CheckCircleIcon, GraphIcon, SignOutIcon, } from '@primer/octicons-react';
19
+ import { Text, Spinner, Heading, Label } from '@primer/react';
20
+ import { GraphIcon } from '@primer/octicons-react';
21
21
  import { Box } from '@datalayer/primer-addons';
22
- import { ErrorView } from './components';
22
+ import { AuthRequiredView, ErrorView } from './components';
23
23
  import { ThemedProvider } from './utils/themedProvider';
24
+ import { uniqueAgentId } from './utils/agentId';
25
+ import { ContextPanel, } from '../context/ContextPanel';
26
+ import { CostTracker } from '../context/CostTracker';
27
+ import { CostUsageChart } from '../context/CostUsageChart';
28
+ import { TokenUsageChart } from '../context/TokenUsageChart';
29
+ import { GraphFlowChart } from '../context/GraphFlowChart';
30
+ import { TurnGraphChart } from '../context/TurnGraphChart';
31
+ import { useAIAgentsWebSocket } from '../hooks';
32
+ import { parseAgentStreamMessage } from '../types/stream';
33
+ import { useCoreStore } from '@datalayer/core/lib/state';
24
34
  const queryClient = new QueryClient();
25
35
  import { useSimpleAuthStore } from '@datalayer/core/lib/views/otel';
26
- import { SignInSimple } from '@datalayer/core/lib/views/iam';
27
- import { UserBadge } from '@datalayer/core/lib/views/profile';
28
36
  import { Chat } from '../chat';
29
- import { useAgents } from '../hooks/useAgents';
30
- const AGENT_NAME = 'monitoring-demo-agent';
31
- const AGENT_SPEC_ID = 'monitor-sales-kpis';
32
- const clampPercent = (value) => Math.max(0, Math.min(100, value));
33
- const toNumber = (value, fallback) => {
34
- const n = Number(value);
35
- return Number.isFinite(n) ? n : fallback;
36
- };
37
- const randomOffset = (range) => (Math.random() - 0.5) * range;
38
- const createSyntheticSnapshot = (previous) => {
39
- const baseCpu = previous?.cpuPercent ?? 42;
40
- const baseMemory = previous?.memoryPercent ?? 57;
41
- const baseLatency = previous?.latencyMs ?? 320;
42
- const baseErrorRate = previous?.errorRatePercent ?? 1.6;
43
- const baseQueueDepth = previous?.queueDepth ?? 12;
44
- const cpuPercent = clampPercent(baseCpu + randomOffset(10));
45
- const memoryPercent = clampPercent(baseMemory + randomOffset(8));
46
- const latencyMs = Math.max(30, baseLatency + randomOffset(120));
47
- const errorRatePercent = clampPercent(baseErrorRate + randomOffset(0.8));
48
- const queueDepth = Math.max(0, Math.round(baseQueueDepth + randomOffset(8)));
49
- let status = 'healthy';
50
- if (errorRatePercent > 4 || latencyMs > 1200 || cpuPercent > 90) {
51
- status = 'critical';
52
- }
53
- else if (errorRatePercent > 2 || latencyMs > 700 || cpuPercent > 80) {
54
- status = 'degraded';
55
- }
56
- return {
57
- timestamp: new Date().toISOString(),
58
- cpuPercent,
59
- memoryPercent,
60
- latencyMs,
61
- errorRatePercent,
62
- queueDepth,
63
- status,
64
- };
65
- };
66
- const normalizeSnapshot = (raw, previous) => {
67
- if (!raw || typeof raw !== 'object') {
68
- return createSyntheticSnapshot(previous);
69
- }
70
- const data = raw;
71
- const snapshot = createSyntheticSnapshot(previous);
72
- const statusValue = String(data.status ?? snapshot.status).toLowerCase();
73
- const status = statusValue === 'healthy' ||
74
- statusValue === 'degraded' ||
75
- statusValue === 'critical'
76
- ? statusValue
77
- : 'unknown';
78
- return {
79
- timestamp: String(data.timestamp ?? new Date().toISOString()),
80
- cpuPercent: clampPercent(toNumber(data.cpuPercent ?? data.cpu, snapshot.cpuPercent)),
81
- memoryPercent: clampPercent(toNumber(data.memoryPercent ?? data.memory, snapshot.memoryPercent)),
82
- latencyMs: Math.max(0, toNumber(data.latencyMs ?? data.latency, snapshot.latencyMs)),
83
- errorRatePercent: clampPercent(toNumber(data.errorRatePercent ?? data.errorRate, snapshot.errorRatePercent)),
84
- queueDepth: Math.max(0, Math.round(toNumber(data.queueDepth, snapshot.queueDepth))),
85
- status,
86
- };
87
- };
88
- const normalizeAlert = (raw, index) => {
89
- if (!raw || typeof raw !== 'object') {
90
- return null;
91
- }
92
- const data = raw;
93
- const severityValue = String(data.severity ?? 'info').toLowerCase();
94
- const severity = severityValue === 'warning' || severityValue === 'critical'
95
- ? severityValue
96
- : 'info';
97
- return {
98
- id: String(data.id ?? `alert-${Date.now()}-${index}`),
99
- title: String(data.title ?? 'Agent alert detected'),
100
- severity,
101
- timestamp: String(data.timestamp ?? new Date().toISOString()),
102
- };
103
- };
104
- const statusVariant = (status) => {
105
- if (status === 'healthy')
106
- return 'success';
107
- if (status === 'degraded')
108
- return 'attention';
109
- if (status === 'critical')
110
- return 'danger';
111
- return 'secondary';
112
- };
113
- const alertVariant = (severity) => {
114
- if (severity === 'critical')
115
- return 'danger';
116
- if (severity === 'warning')
117
- return 'attention';
118
- return 'secondary';
119
- };
120
- const MetricRow = ({ label, value, percent }) => {
121
- return (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Box, { sx: {
122
- display: 'flex',
123
- justifyContent: 'space-between',
124
- alignItems: 'center',
125
- mb: 1,
126
- }, children: [_jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: label }), _jsx(Text, { sx: { fontSize: 0, fontWeight: 'bold' }, children: value })] }), _jsx(Box, { sx: {
127
- width: '100%',
128
- height: 8,
129
- bg: 'canvas.subtle',
130
- borderRadius: 6,
131
- overflow: 'hidden',
132
- }, children: _jsx(Box, { sx: {
133
- width: `${clampPercent(percent)}%`,
134
- height: '100%',
135
- bg: percent >= 85 ? 'danger.emphasis' : 'accent.emphasis',
136
- transition: 'width 300ms ease-out',
137
- } }) })] }));
138
- };
37
+ const AGENT_NAME = 'monitoring-example-agent';
38
+ const AGENT_SPEC_ID = 'example-monitoring';
39
+ const DEFAULT_LOCAL_BASE_URL = import.meta.env.VITE_BASE_URL || 'http://localhost:8765';
40
+ const OTEL_BASE_URL_ENV = import.meta.env.VITE_OTEL_BASE_URL;
41
+ const DATALAYER_RUN_URL_ENV = import.meta.env.DATALAYER_RUN_URL;
139
42
  const AgentMonitoringInner = ({ onLogout, }) => {
140
43
  const { token } = useSimpleAuthStore();
141
- const { runtime, status: runtimeStatus, isReady, error: hookError, } = useAgents({
142
- agentSpecId: AGENT_SPEC_ID,
143
- autoStart: true,
144
- agentConfig: {
145
- name: AGENT_NAME,
146
- protocol: 'ag-ui',
147
- description: 'Agent with runtime and alert monitoring signals',
148
- },
149
- });
150
- const [snapshots, setSnapshots] = useState([]);
44
+ const agentName = useRef(uniqueAgentId(AGENT_NAME)).current;
45
+ const { configuration } = useCoreStore();
46
+ const [runtimeStatus, setRuntimeStatus] = useState('launching');
47
+ const [isReady, setIsReady] = useState(false);
48
+ const [hookError, setHookError] = useState(null);
49
+ const [agentId, setAgentId] = useState(agentName);
50
+ const [isReconnectedAgent, setIsReconnectedAgent] = useState(false);
151
51
  const [alerts, setAlerts] = useState([]);
152
- const agentBaseUrl = runtime?.agentBaseUrl || '';
153
- const agentId = runtime?.agentId || AGENT_NAME;
154
- const podName = runtime?.podName || '(launchingโ€ฆ)';
52
+ const [liveContext, setLiveContext] = useState(undefined);
53
+ const [liveContextSnapshot, setLiveContextSnapshot] = useState(undefined);
54
+ const [liveCost, setLiveCost] = useState(undefined);
55
+ const [liveMcpStatus, setLiveMcpStatus] = useState(undefined);
56
+ const [monitorLastSnapshotAt, setMonitorLastSnapshotAt] = useState(null);
57
+ const [liveGraphTelemetry, setLiveGraphTelemetry] = useState(undefined);
58
+ const agentBaseUrl = DEFAULT_LOCAL_BASE_URL;
59
+ const otelBaseUrl = configuration?.otelRunUrl ||
60
+ configuration?.runUrl ||
61
+ OTEL_BASE_URL_ENV ||
62
+ DATALAYER_RUN_URL_ENV ||
63
+ 'https://prod1.datalayer.run';
64
+ const podName = agentId;
65
+ // The OTEL service_name resource attribute is 'agent-runtimes' (the
66
+ // application name), NOT the individual agent ID. Use the correct value
67
+ // so the TokenUsageChart WS filter and HTTP query match actual rows.
68
+ const otelServiceName = 'agent-runtimes';
69
+ const chatAuthToken = token === null ? undefined : token;
155
70
  const authFetch = useCallback((url, opts = {}) => fetch(url, {
156
71
  ...opts,
157
72
  headers: {
@@ -161,46 +76,137 @@ const AgentMonitoringInner = ({ onLogout, }) => {
161
76
  },
162
77
  }), [token]);
163
78
  useEffect(() => {
164
- if (!isReady || !agentBaseUrl)
165
- return;
166
- const poll = async () => {
167
- let nextSnapshot = null;
168
- let nextAlerts = null;
79
+ let isCancelled = false;
80
+ const createLocalAgent = async () => {
81
+ setRuntimeStatus('launching');
82
+ setIsReady(false);
83
+ setHookError(null);
84
+ setIsReconnectedAgent(false);
169
85
  try {
170
- const res = await authFetch(`${agentBaseUrl}/api/v1/agents/${agentId}/monitoring`);
171
- if (res.ok) {
172
- const data = await res.json();
173
- const rawSnapshot = data?.snapshot ?? data?.metrics ?? data;
174
- nextAlerts = Array.isArray(data?.alerts)
175
- ? data.alerts
176
- .map((a, i) => normalizeAlert(a, i))
177
- .filter((a) => !!a)
178
- .slice(0, 25)
179
- : [];
180
- setSnapshots(prev => {
181
- nextSnapshot = normalizeSnapshot(rawSnapshot, prev[0]);
182
- return [nextSnapshot, ...prev].slice(0, 40);
183
- });
184
- if (nextAlerts) {
185
- setAlerts(nextAlerts);
86
+ const response = await authFetch(`${agentBaseUrl}/api/v1/agents`, {
87
+ method: 'POST',
88
+ body: JSON.stringify({
89
+ name: agentName,
90
+ description: 'MCP monitoring example โ€“ web crawling via Tavily with live cost/token metrics',
91
+ agent_library: 'pydantic-ai',
92
+ transport: 'vercel-ai',
93
+ agent_spec_id: AGENT_SPEC_ID,
94
+ enable_skills: true,
95
+ tools: [],
96
+ }),
97
+ });
98
+ let resolvedAgentId = agentName;
99
+ let isAlreadyRunning = false;
100
+ if (response.ok) {
101
+ const data = await response.json();
102
+ resolvedAgentId = data?.id || agentName;
103
+ }
104
+ else {
105
+ const contentType = response.headers.get('content-type') || '';
106
+ let detail = '';
107
+ if (contentType.includes('application/json')) {
108
+ const data = await response.json().catch(() => null);
109
+ detail =
110
+ (typeof data?.detail === 'string' && data.detail) ||
111
+ (typeof data?.message === 'string' && data.message) ||
112
+ '';
113
+ }
114
+ else {
115
+ detail = await response.text();
116
+ }
117
+ if (response.status === 409 || /already exists/i.test(detail || '')) {
118
+ isAlreadyRunning = true;
119
+ }
120
+ else {
121
+ throw new Error(detail || `Failed to create local agent: ${response.status}`);
186
122
  }
187
- return;
123
+ }
124
+ if (!isCancelled) {
125
+ setAgentId(resolvedAgentId);
126
+ setIsReconnectedAgent(isAlreadyRunning);
127
+ setIsReady(true);
128
+ setRuntimeStatus('ready');
188
129
  }
189
130
  }
190
- catch {
191
- // Keep UI responsive with synthetic values when endpoint is unavailable.
192
- }
193
- setSnapshots(prev => {
194
- if (prev.length > 0) {
195
- return prev;
131
+ catch (error) {
132
+ if (!isCancelled) {
133
+ setHookError(error instanceof Error ? error.message : 'Agent failed to start');
134
+ setRuntimeStatus('error');
196
135
  }
197
- return [createSyntheticSnapshot()];
198
- });
136
+ }
199
137
  };
200
- poll();
201
- const interval = window.setInterval(poll, 10_000);
202
- return () => window.clearInterval(interval);
203
- }, [isReady, agentBaseUrl, agentId, authFetch]);
138
+ void createLocalAgent();
139
+ return () => {
140
+ isCancelled = true;
141
+ };
142
+ }, [agentBaseUrl, authFetch]);
143
+ const handleMonitoringStreamMessage = useCallback((message) => {
144
+ try {
145
+ const stream = parseAgentStreamMessage(message?.raw ?? message);
146
+ if (!stream || stream.type !== 'agent.snapshot') {
147
+ return;
148
+ }
149
+ const payload = stream.payload;
150
+ if (payload.contextSnapshot) {
151
+ setLiveContext(payload.contextSnapshot);
152
+ setLiveContextSnapshot(payload.contextSnapshot);
153
+ setMonitorLastSnapshotAt(Date.now());
154
+ }
155
+ if (payload.mcpStatus !== undefined) {
156
+ setLiveMcpStatus(payload.mcpStatus ?? undefined);
157
+ }
158
+ if (payload.graphTelemetry) {
159
+ setLiveGraphTelemetry(payload.graphTelemetry);
160
+ }
161
+ const snapshotCost = payload.contextSnapshot?.costUsage ?? payload.costUsage;
162
+ if (!snapshotCost) {
163
+ return;
164
+ }
165
+ setLiveCost({
166
+ agentId,
167
+ lastTurnCostUsd: Number(snapshotCost.lastTurnCostUsd ?? 0),
168
+ cumulativeCostUsd: Number(snapshotCost.cumulativeCostUsd ?? 0),
169
+ perRunBudgetUsd: snapshotCost.perRunBudgetUsd == null
170
+ ? null
171
+ : Number(snapshotCost.perRunBudgetUsd),
172
+ cumulativeBudgetUsd: snapshotCost.cumulativeBudgetUsd == null
173
+ ? null
174
+ : Number(snapshotCost.cumulativeBudgetUsd),
175
+ requestCount: Number(snapshotCost.requestCount ?? 0),
176
+ totalTokensUsed: Number(snapshotCost.totalTokensUsed ?? 0),
177
+ modelBreakdown: Array.isArray(snapshotCost.modelBreakdown)
178
+ ? snapshotCost.modelBreakdown.map(item => ({
179
+ model: String(item.model ?? 'unknown'),
180
+ inputTokens: Number(item.inputTokens ?? 0),
181
+ outputTokens: Number(item.outputTokens ?? 0),
182
+ costUsd: Number(item.costUsd ?? 0),
183
+ requests: Number(item.requests ?? 0),
184
+ }))
185
+ : [],
186
+ runs: Array.isArray(snapshotCost.runs)
187
+ ? snapshotCost.runs.map(item => ({
188
+ pricingResolved: Boolean(item.pricingResolved),
189
+ }))
190
+ : undefined,
191
+ });
192
+ }
193
+ catch {
194
+ // Ignore malformed stream payloads.
195
+ }
196
+ }, [agentId]);
197
+ const monitorSocket = useAIAgentsWebSocket({
198
+ enabled: isReady && Boolean(agentBaseUrl),
199
+ baseUrl: agentBaseUrl,
200
+ path: '/api/v1/tool-approvals/ws',
201
+ queryParams: { agent_id: agentId },
202
+ onMessage: handleMonitoringStreamMessage,
203
+ reconnectDelayMs: attempt => Math.min(1000 * 2 ** Math.max(0, attempt - 1), 10000),
204
+ });
205
+ useEffect(() => {
206
+ // Monitoring alerts endpoint is optional and may return 404 in local mode.
207
+ // Keep the UI quiet and rely on stream snapshots for now.
208
+ setAlerts([]);
209
+ }, [isReady, agentId]);
204
210
  if (!isReady && runtimeStatus !== 'error') {
205
211
  return (_jsxs(Box, { sx: {
206
212
  display: 'flex',
@@ -209,14 +215,11 @@ const AgentMonitoringInner = ({ onLogout, }) => {
209
215
  justifyContent: 'center',
210
216
  height: '100vh',
211
217
  gap: 3,
212
- }, children: [_jsx(Spinner, { size: "large" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: runtimeStatus === 'launching'
213
- ? 'Launching runtime for monitoring agentโ€ฆ'
214
- : 'Creating monitoring demo agentโ€ฆ' })] }));
218
+ }, children: [_jsx(Spinner, { size: "large" }), _jsx(Text, { sx: { color: 'fg.muted' }, children: "Launching local monitoring example agent..." })] }));
215
219
  }
216
220
  if (runtimeStatus === 'error' || hookError) {
217
221
  return _jsx(ErrorView, { error: hookError, onLogout: onLogout });
218
222
  }
219
- const latest = snapshots[0] ?? createSyntheticSnapshot();
220
223
  return (_jsxs(Box, { sx: {
221
224
  height: 'calc(100vh - 60px)',
222
225
  display: 'flex',
@@ -230,46 +233,109 @@ const AgentMonitoringInner = ({ onLogout, }) => {
230
233
  borderBottom: '1px solid',
231
234
  borderColor: 'border.default',
232
235
  flexShrink: 0,
233
- }, children: [_jsx(GraphIcon, { size: 16 }), _jsxs(Heading, { as: "h3", sx: { fontSize: 2, flex: 1 }, children: ["Monitoring \u2014 ", podName] }), _jsx(Label, { variant: statusVariant(latest.status), size: "small", children: latest.status }), token && _jsx(UserBadge, { token: token, variant: "small" }), _jsx(Button, { size: "small", variant: "invisible", onClick: onLogout, leadingVisual: SignOutIcon, sx: { color: 'fg.muted' }, children: "Sign out" })] }), _jsxs(Box, { sx: { flex: 1, minHeight: 0, display: 'flex' }, children: [_jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: _jsx(Chat, { protocol: "ag-ui", baseUrl: agentBaseUrl, agentId: agentId, title: "Monitoring Agent", placeholder: "Ask about performance, latency, and alert trends\u2026", description: `${alerts.length} active alert${alerts.length !== 1 ? 's' : ''}`, showHeader: true, autoFocus: true, height: "100%", runtimeId: podName, historyEndpoint: `${agentBaseUrl}/api/v1/history`, suggestions: [
236
+ }, children: [_jsx(GraphIcon, { size: 16 }), _jsxs(Heading, { as: "h3", sx: { fontSize: 2, flex: 1 }, children: ["Monitoring \u2014 ", podName] }), isReconnectedAgent && (_jsx(Label, { variant: "secondary", size: "small", children: "Reconnected" })), _jsxs(Label, { variant: monitorSocket.connectionState === 'connected'
237
+ ? 'success'
238
+ : 'secondary', children: ["WS: ", monitorSocket.connectionState] })] }), _jsxs(Box, { sx: { flex: 1, minHeight: 0, display: 'flex' }, children: [_jsxs(Box, { sx: {
239
+ width: 320,
240
+ minWidth: 280,
241
+ borderRight: '1px solid',
242
+ borderColor: 'border.default',
243
+ display: 'flex',
244
+ flexDirection: 'column',
245
+ overflow: 'auto',
246
+ '@media (max-width: 1680px)': {
247
+ width: 300,
248
+ minWidth: 260,
249
+ },
250
+ '@media (max-width: 1400px)': {
251
+ display: 'none',
252
+ },
253
+ }, children: [_jsxs(Box, { sx: {
254
+ p: 3,
255
+ borderBottom: '1px solid',
256
+ borderColor: 'border.default',
257
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Token Usage" }), _jsx(TokenUsageChart, { serviceName: otelServiceName, agentId: agentId, apiKey: token ?? undefined, runUrl: otelBaseUrl, liveSystemPromptTokens: liveContextSnapshot?.systemPromptTokens, liveUserMessageTokens: liveContextSnapshot?.userMessageTokens, liveAgentMessageTokens: liveContextSnapshot?.assistantMessageTokens, liveToolsUsageTokens: liveContextSnapshot?.toolTokens, liveTimestampMs: monitorLastSnapshotAt, height: 180 })] }), _jsxs(Box, { sx: {
258
+ p: 3,
259
+ borderBottom: '1px solid',
260
+ borderColor: 'border.default',
261
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Cost" }), _jsx(CostUsageChart, { serviceName: otelServiceName, agentId: agentId, apiKey: token ?? undefined, runUrl: otelBaseUrl, liveCumulativeUsd: liveCost?.cumulativeCostUsd, liveTimestampMs: monitorLastSnapshotAt, height: 180 })] }), _jsxs(Box, { sx: {
262
+ p: 3,
263
+ borderBottom: '1px solid',
264
+ borderColor: 'border.default',
265
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "LLM Cost Monitoring" }), liveCost ? (_jsx(CostTracker, { agentId: agentId, compact: false, liveData: liveCost })) : (_jsxs(Box, { children: [_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "Waiting for first websocket snapshot..." }), monitorSocket.lastClose?.detail && (_jsxs(Text, { sx: {
266
+ color: 'danger.fg',
267
+ fontSize: 0,
268
+ mt: 1,
269
+ display: 'block',
270
+ }, children: ["Last close: ", monitorSocket.lastClose.detail] }))] }))] })] }), _jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: _jsx(Chat, { protocol: "vercel-ai", baseUrl: agentBaseUrl, agentId: agentId, authToken: chatAuthToken, title: "Monitoring Agent", brandIcon: _jsx(GraphIcon, { size: 16 }), placeholder: "Ask for cost, token usage, and turn-level monitoring insights...", description: `${alerts.length} active alert${alerts.length !== 1 ? 's' : ''}`, showHeader: true, showTokenUsage: true, showToolsMenu: true, showSkillsMenu: true, autoFocus: true, height: "100%", runtimeId: agentId, historyEndpoint: `${agentBaseUrl}/api/v1/history`, suggestions: [
271
+ {
272
+ title: 'โ–ถ No-tool turn',
273
+ message: 'Briefly introduce yourself without calling any tool or skill โ€” produces a linear Start โ†’ Model โ†’ Decision โ†’ End graph.',
274
+ },
234
275
  {
235
- title: 'Health summary',
236
- message: 'Summarize current agent health and key bottlenecks',
276
+ title: '๐Ÿ” Single tool call',
277
+ message: 'Use the Tavily web search tool to find the latest news about pydantic-graph. Make a single search call.',
237
278
  },
238
279
  {
239
- title: 'Alert triage',
240
- message: 'List critical alerts first and suggest immediate mitigations',
280
+ title: '๐ŸŒ€ Parallel tool fan-out',
281
+ message: 'Use Tavily to search the web in parallel for these three topics in the same turn: (1) OpenTelemetry traces, (2) agent observability, (3) LLM cost monitoring. Issue all three searches together so the turn graph fans out (Broadcast โ†’ Spread โ†’ Join).',
241
282
  },
242
- ], submitOnSuggestionClick: true }) }), _jsxs(Box, { sx: {
243
- width: 380,
283
+ {
284
+ title: '๐Ÿงฉ Skill call',
285
+ message: 'Use the datalayer-whoami skill to identify my profile, then summarize it.',
286
+ },
287
+ {
288
+ title: '๐Ÿ˜„ Joke skill',
289
+ message: 'Use the jokes skill to tell me a random dad joke, then wrap it in one-sentence commentary.',
290
+ },
291
+ {
292
+ title: '๐Ÿงช Mixed tools + skills',
293
+ message: 'In one turn: (a) use Tavily to search for "OTEL traces best practices", (b) call the datalayer-whoami skill, (c) call the jokes skill. Summarize all three results together. This should produce a Broadcast โ†’ three Spread nodes โ†’ Join in the Turn Execution Graph.',
294
+ },
295
+ {
296
+ title: 'Monitoring summary',
297
+ message: 'Summarize my current token usage, cost status, and recent turn activity.',
298
+ },
299
+ {
300
+ title: 'Turn usage analysis',
301
+ message: 'Analyze the last turn usage and explain which parts drove input and output tokens.',
302
+ },
303
+ ], submitOnSuggestionClick: true, contextSnapshot: liveContextSnapshot, mcpStatusData: liveMcpStatus }) }), _jsxs(Box, { sx: {
304
+ width: 360,
305
+ minWidth: 320,
244
306
  borderLeft: '1px solid',
245
307
  borderColor: 'border.default',
246
308
  display: 'flex',
247
309
  flexDirection: 'column',
248
310
  overflow: 'auto',
311
+ '@media (max-width: 1680px)': {
312
+ width: 340,
313
+ minWidth: 300,
314
+ },
315
+ '@media (max-width: 1100px)': {
316
+ width: 300,
317
+ minWidth: 260,
318
+ },
249
319
  }, children: [_jsxs(Box, { sx: {
250
320
  p: 3,
251
321
  borderBottom: '1px solid',
252
322
  borderColor: 'border.default',
253
- }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Live Metrics" }), _jsx(MetricRow, { label: "CPU", value: `${latest.cpuPercent.toFixed(1)}%`, percent: latest.cpuPercent }), _jsx(MetricRow, { label: "Memory", value: `${latest.memoryPercent.toFixed(1)}%`, percent: latest.memoryPercent }), _jsx(MetricRow, { label: "Latency", value: `${Math.round(latest.latencyMs)} ms`, percent: (latest.latencyMs / 2000) * 100 }), _jsx(MetricRow, { label: "Error Rate", value: `${latest.errorRatePercent.toFixed(2)}%`, percent: latest.errorRatePercent * 20 }), _jsx(MetricRow, { label: "Queue Depth", value: `${latest.queueDepth}`, percent: latest.queueDepth })] }), _jsxs(Box, { sx: { p: 3, flex: 1, overflow: 'auto' }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Recent Alerts" }), alerts.length === 0 ? (_jsxs(Box, { sx: {
254
- p: 2,
255
- border: '1px solid',
256
- borderColor: 'border.default',
257
- borderRadius: 2,
258
- display: 'flex',
259
- alignItems: 'center',
260
- gap: 2,
261
- }, children: [_jsx(CheckCircleIcon, { size: 16 }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: "No active alerts." })] })) : (alerts.map(alert => (_jsxs(Box, { sx: {
262
- p: 2,
263
- mb: 2,
264
- border: '1px solid',
265
- borderColor: 'border.default',
266
- borderRadius: 2,
267
- }, children: [_jsxs(Box, { sx: {
268
- display: 'flex',
269
- justifyContent: 'space-between',
270
- alignItems: 'center',
271
- mb: 1,
272
- }, children: [_jsx(Text, { sx: { fontSize: 1, fontWeight: 'bold' }, children: alert.title }), _jsx(Label, { size: "small", variant: alertVariant(alert.severity), children: alert.severity })] }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: new Date(alert.timestamp).toLocaleString() })] }, alert.id))))] })] })] })] }));
323
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Turn and Session Usage" }), liveContext ? (_jsx(ContextPanel, { agentId: agentId, apiBase: agentBaseUrl, liveData: liveContext, defaultView: "overview", chartHeight: "160px" })) : (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "Waiting for first websocket snapshot..." })), _jsxs(Text, { sx: { mt: 2, color: 'fg.muted', fontSize: 0 }, children: ["Live monitoring uses websocket snapshots only.", monitorLastSnapshotAt
324
+ ? ` Last snapshot ${new Date(monitorLastSnapshotAt).toLocaleTimeString()}.`
325
+ : '', monitorSocket.connectionState !== 'connected' &&
326
+ monitorSocket.reconnectAttempt > 0
327
+ ? ` Reconnect attempt ${monitorSocket.reconnectAttempt}.`
328
+ : ''] })] }), liveGraphTelemetry && (_jsxs(Box, { sx: {
329
+ p: 3,
330
+ borderBottom: '1px solid',
331
+ borderColor: 'border.default',
332
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Graph Execution (live)" }), _jsx(GraphFlowChart, { data: liveGraphTelemetry, height: 240 }), _jsxs(Text, { sx: { mt: 1, color: 'fg.muted', fontSize: 0 }, children: [liveGraphTelemetry.totalNodesExecuted, " node(s) executed across", ' ', liveGraphTelemetry.runCount, " run(s)", liveGraphTelemetry.totalDurationMs
333
+ ? ` โ€” ${(liveGraphTelemetry.totalDurationMs / 1000).toFixed(2)}s total`
334
+ : ''] })] })), _jsxs(Box, { sx: {
335
+ p: 3,
336
+ borderBottom: '1px solid',
337
+ borderColor: 'border.default',
338
+ }, children: [_jsx(Heading, { as: "h4", sx: { fontSize: 1, mb: 2 }, children: "Turn Execution Graph (OTEL traces)" }), _jsx(TurnGraphChart, { serviceName: otelServiceName, agentId: agentId, runUrl: otelBaseUrl, apiKey: token ?? undefined, autoRefreshMs: 10_000, height: 280 })] })] })] })] }));
273
339
  };
274
340
  const syncTokenToIamStore = (token) => {
275
341
  import('@datalayer/core/lib/state').then(({ iamStore }) => {
@@ -277,7 +343,7 @@ const syncTokenToIamStore = (token) => {
277
343
  });
278
344
  };
279
345
  const AgentMonitoringExample = () => {
280
- const { token, setAuth, clearAuth } = useSimpleAuthStore();
346
+ const { token, clearAuth } = useSimpleAuthStore();
281
347
  const hasSynced = useRef(false);
282
348
  useEffect(() => {
283
349
  if (token && !hasSynced.current) {
@@ -285,11 +351,6 @@ const AgentMonitoringExample = () => {
285
351
  syncTokenToIamStore(token);
286
352
  }
287
353
  }, [token]);
288
- const handleSignIn = useCallback((newToken, handle) => {
289
- setAuth(newToken, handle);
290
- hasSynced.current = true;
291
- syncTokenToIamStore(newToken);
292
- }, [setAuth]);
293
354
  const handleLogout = useCallback(() => {
294
355
  clearAuth();
295
356
  hasSynced.current = false;
@@ -298,7 +359,7 @@ const AgentMonitoringExample = () => {
298
359
  });
299
360
  }, [clearAuth]);
300
361
  if (!token) {
301
- return (_jsx(ThemedProvider, { children: _jsx(SignInSimple, { onSignIn: handleSignIn, onApiKeySignIn: apiKey => handleSignIn(apiKey, 'api-key-user'), title: "Agent Monitoring", description: "Sign in to monitor runtime health and alerts.", leadingIcon: _jsx(GraphIcon, { size: 24 }) }) }));
362
+ return (_jsx(ThemedProvider, { children: _jsx(AuthRequiredView, {}) }));
302
363
  }
303
364
  return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(ThemedProvider, { children: _jsx(AgentMonitoringInner, { onLogout: handleLogout }) }) }));
304
365
  };
@@ -4,8 +4,7 @@
4
4
  * Demonstrates notification channels for agents: in-app toasts, email digests,
5
5
  * Slack webhook integrations, and notification preference management.
6
6
  *
7
- * - Creates a cloud agent runtime (environment: 'ai-agents-env') via the Datalayer
8
- * Runtimes API and deploys an agent on its sidecar
7
+ * - Creates a local agent-runtimes agent using the `example-notifications` spec
9
8
  * - Shows a notification center alongside the chat where users can configure
10
9
  * channels and review recent notifications
11
10
  */