@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
@@ -0,0 +1,122 @@
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 { SyncIcon } from '@primer/octicons-react';
9
+ import { Box, setupPrimerPortals } from '@datalayer/primer-addons';
10
+ import { ThemedProvider } from './utils/themedProvider';
11
+ import { uniqueAgentId } from './utils/agentId';
12
+ import { useExampleAgentRuntimesUrl } from './utils/useExampleAgentRuntimesUrl';
13
+ import { ErrorView } from './components';
14
+ import { Chat } from '../chat';
15
+ setupPrimerPortals();
16
+ const AGENT_SPEC_ID = 'example-hooks';
17
+ const AGENT_NAME = 'hooks-example-agent';
18
+ const AgentHooksExample = () => {
19
+ const baseUrl = useExampleAgentRuntimesUrl();
20
+ const [agentId, setAgentId] = useState(null);
21
+ const [error, setError] = useState(null);
22
+ const [isCreating, setIsCreating] = useState(true);
23
+ useEffect(() => {
24
+ let cancelled = false;
25
+ const name = uniqueAgentId(AGENT_NAME);
26
+ const createAgent = async () => {
27
+ try {
28
+ const response = await fetch(`${baseUrl}/api/v1/agents`, {
29
+ method: 'POST',
30
+ headers: { 'Content-Type': 'application/json' },
31
+ body: JSON.stringify({
32
+ name,
33
+ agent_spec_id: AGENT_SPEC_ID,
34
+ transport: 'vercel-ai',
35
+ }),
36
+ });
37
+ if (!response.ok) {
38
+ const data = await response
39
+ .json()
40
+ .catch(() => ({ detail: 'Unknown error' }));
41
+ throw new Error(data.detail || `Failed to create agent: ${response.status}`);
42
+ }
43
+ const data = await response.json();
44
+ if (!cancelled) {
45
+ setAgentId(data.id);
46
+ setIsCreating(false);
47
+ }
48
+ }
49
+ catch (err) {
50
+ if (!cancelled) {
51
+ setError(err instanceof Error ? err.message : 'Failed to create agent');
52
+ setIsCreating(false);
53
+ }
54
+ }
55
+ };
56
+ createAgent();
57
+ return () => {
58
+ cancelled = true;
59
+ };
60
+ }, [baseUrl]);
61
+ useEffect(() => {
62
+ return () => {
63
+ if (!agentId) {
64
+ return;
65
+ }
66
+ void fetch(`${baseUrl}/api/v1/agents/${encodeURIComponent(agentId)}`, {
67
+ method: 'DELETE',
68
+ }).catch(() => {
69
+ // Ignore teardown failures in example mode.
70
+ });
71
+ };
72
+ }, [agentId, baseUrl]);
73
+ if (isCreating) {
74
+ return (_jsx(ThemedProvider, { children: _jsxs(Box, { sx: {
75
+ display: 'flex',
76
+ flexDirection: 'column',
77
+ alignItems: 'center',
78
+ justifyContent: 'center',
79
+ height: '100vh',
80
+ gap: 3,
81
+ bg: 'canvas.default',
82
+ }, children: [_jsx(Spinner, { size: "large" }), _jsxs(Text, { sx: { color: 'fg.muted' }, children: ["Creating agent from ", AGENT_SPEC_ID, "..."] })] }) }));
83
+ }
84
+ if (error || !agentId) {
85
+ return (_jsx(ThemedProvider, { children: _jsx(ErrorView, { error: "Failed to start hooks agent", detail: error || 'No agent ID returned' }) }));
86
+ }
87
+ return (_jsx(Chat, { protocol: "vercel-ai", baseUrl: baseUrl, agentId: agentId, title: "Hooks Agent", brandIcon: _jsx(SyncIcon, { size: 16 }), placeholder: "Ask about lifecycle hooks...", description: "Demonstrates lifecycle hooks and pydantic-style tool hooks: before_tool_execute, after_tool_execute, on_tool_execute_error, deferred_tool_calls", showHeader: true, showModelSelector: true, showToolsMenu: true, showSkillsMenu: true, showTokenUsage: true, showInformation: true, autoFocus: true, height: "100vh", runtimeId: agentId, historyEndpoint: `${baseUrl}/api/v1/history`, suggestions: [
88
+ {
89
+ title: 'Read the pre-hook marker file',
90
+ message: 'Use execute_code to read /tmp/agent_runtimes_pre_hook_demo.txt and show its contents.',
91
+ },
92
+ {
93
+ title: 'Verify hook variables',
94
+ message: 'Use execute_code to run this verification:\n```python\nassert isinstance(hook_name, str) and hook_name == "example-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.',
95
+ },
96
+ {
97
+ title: "Verify 'rich' was installed",
98
+ message: 'Use execute_code to import rich and print its version — the pre-hook installed it via pip.',
99
+ },
100
+ {
101
+ title: 'Explain the hook lifecycle',
102
+ message: 'What pre-hooks and post-hooks are configured for this agent, and when does each run?',
103
+ },
104
+ {
105
+ title: 'Trigger function + python tool hooks',
106
+ message: "Call runtime_sensitive_echo with text 'hello' and reason 'audit', then explain which before_tool_execute hooks ran (function and python).",
107
+ },
108
+ {
109
+ title: 'Trigger deny in python hook',
110
+ message: "Call runtime_sensitive_echo with text 'danger' and reason 'delete notebook', then explain why local Python policy denied it.",
111
+ },
112
+ {
113
+ title: 'Read tool approval audit log',
114
+ message: 'Use execute_code to show the latest entries from /tmp/agent_runtimes_tool_approvals_audit.jsonl and summarize decision and execution status.',
115
+ },
116
+ {
117
+ title: 'Explain deferred hook handling',
118
+ message: 'Explain how deferred_tool_calls works with approval-required tools and when inline resolution is used in this run.',
119
+ },
120
+ ], submitOnSuggestionClick: true }));
121
+ };
122
+ export default AgentHooksExample;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const AgentInferenceProviderExample: React.FC;
3
+ export default AgentInferenceProviderExample;
@@ -0,0 +1,329 @@
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
+ /// <reference types="vite/client" />
7
+ import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
8
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
9
+ import { Button, Box, Heading, SegmentedControl, Spinner, Text, } from '@primer/react';
10
+ import { ThemedProvider } from './utils/themedProvider';
11
+ import { uniqueAgentId } from './utils/agentId';
12
+ import { useSimpleAuthStore } from '@datalayer/core/lib/views/otel';
13
+ import { Chat } from '../chat';
14
+ import { useAIAgentsWebSocket } from '../hooks';
15
+ const AGENT_SPEC_ID = 'example-inference';
16
+ const AGENT_NAME = 'inference-provider-example-agent';
17
+ const DEFAULT_LOCAL_BASE_URL = import.meta.env.VITE_BASE_URL || 'http://localhost:8765';
18
+ const queryClient = new QueryClient();
19
+ const nowIso = () => new Date().toISOString();
20
+ const toErrorMessage = (error) => error instanceof Error ? error.message : String(error);
21
+ const stringifyPayload = (value) => {
22
+ if (typeof value === 'string') {
23
+ return value;
24
+ }
25
+ try {
26
+ return JSON.stringify(value, null, 2);
27
+ }
28
+ catch {
29
+ return String(value);
30
+ }
31
+ };
32
+ const ProviderBadge = ({ provider, }) => (_jsx(Box, { sx: {
33
+ px: 2,
34
+ py: '2px',
35
+ borderRadius: 999,
36
+ border: '1px solid',
37
+ borderColor: 'border.default',
38
+ fontSize: 0,
39
+ color: 'fg.muted',
40
+ bg: 'canvas.inset',
41
+ textTransform: 'uppercase',
42
+ letterSpacing: '0.03em',
43
+ }, children: provider }));
44
+ const AgentInferenceProviderExampleInner = () => {
45
+ const { token } = useSimpleAuthStore();
46
+ const [provider, setProvider] = useState('local');
47
+ const [agentId, setAgentId] = useState(null);
48
+ const [isLaunching, setIsLaunching] = useState(true);
49
+ const [error, setError] = useState(null);
50
+ const [providerEvents, setProviderEvents] = useState([]);
51
+ const [expandedEventIds, setExpandedEventIds] = useState(() => new Set());
52
+ const currentAgentRef = useRef(null);
53
+ const requestEpochRef = useRef(0);
54
+ const baseUrl = DEFAULT_LOCAL_BASE_URL;
55
+ const inferenceUrl = useMemo(() => {
56
+ if (provider === 'local') {
57
+ return 'local inference';
58
+ }
59
+ const env = import.meta.env ?? {};
60
+ return (env.VITE_DATALAYER_AI_INFERENCE_URL ||
61
+ env.VITE_DATALAYER_RUN_URL ||
62
+ 'https://prod1.datalayer.run');
63
+ }, [provider]);
64
+ const authFetch = useCallback((url, init = {}) => {
65
+ return fetch(url, {
66
+ ...init,
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ ...(token ? { Authorization: `Bearer ${token}` } : {}),
70
+ ...(init.headers ?? {}),
71
+ },
72
+ });
73
+ }, [token]);
74
+ const appendProviderEvent = useCallback((type, summary, payload) => {
75
+ setProviderEvents(prev => [
76
+ {
77
+ id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
78
+ type,
79
+ summary,
80
+ payload: stringifyPayload(payload),
81
+ createdAt: nowIso(),
82
+ },
83
+ ...prev,
84
+ ]);
85
+ }, []);
86
+ const deleteAgent = useCallback(async (id) => {
87
+ await authFetch(`${baseUrl}/api/v1/agents/${encodeURIComponent(id)}`, {
88
+ method: 'DELETE',
89
+ }).catch(() => {
90
+ // Best-effort cleanup in example mode.
91
+ });
92
+ }, [authFetch, baseUrl]);
93
+ const launchAgentForProvider = useCallback(async (nextProvider) => {
94
+ requestEpochRef.current += 1;
95
+ const requestEpoch = requestEpochRef.current;
96
+ setIsLaunching(true);
97
+ setError(null);
98
+ const previousAgentId = currentAgentRef.current;
99
+ if (previousAgentId) {
100
+ await deleteAgent(previousAgentId);
101
+ }
102
+ try {
103
+ const configureResponse = await authFetch(`${baseUrl}/api/v1/configure/inference/provider`, {
104
+ method: 'PUT',
105
+ body: JSON.stringify({ provider: nextProvider }),
106
+ });
107
+ appendProviderEvent('configure.provider', `Configured runtime inference provider to ${nextProvider}`, {
108
+ status: configureResponse.status,
109
+ provider: nextProvider,
110
+ });
111
+ const name = uniqueAgentId(`${AGENT_NAME}-${nextProvider}`);
112
+ const createResponse = await authFetch(`${baseUrl}/api/v1/agents`, {
113
+ method: 'POST',
114
+ body: JSON.stringify({
115
+ name,
116
+ transport: 'vercel-ai',
117
+ agent_spec_id: AGENT_SPEC_ID,
118
+ inferenceProvider: nextProvider,
119
+ }),
120
+ });
121
+ if (!createResponse.ok) {
122
+ const detail = await createResponse.text();
123
+ throw new Error(detail || `Failed to create agent (${createResponse.status})`);
124
+ }
125
+ const payload = (await createResponse.json());
126
+ const nextAgentId = payload.id || name;
127
+ if (requestEpoch !== requestEpochRef.current) {
128
+ return;
129
+ }
130
+ currentAgentRef.current = nextAgentId;
131
+ setAgentId(nextAgentId);
132
+ appendProviderEvent('agent.created', 'Launched local agent runtime', {
133
+ agentId: nextAgentId,
134
+ agentSpecId: AGENT_SPEC_ID,
135
+ inferenceProvider: nextProvider,
136
+ baseUrl,
137
+ });
138
+ }
139
+ catch (launchError) {
140
+ if (requestEpoch !== requestEpochRef.current) {
141
+ return;
142
+ }
143
+ setAgentId(null);
144
+ currentAgentRef.current = null;
145
+ setError(toErrorMessage(launchError));
146
+ appendProviderEvent('agent.error', 'Failed to launch agent', {
147
+ provider: nextProvider,
148
+ error: toErrorMessage(launchError),
149
+ });
150
+ }
151
+ finally {
152
+ if (requestEpoch === requestEpochRef.current) {
153
+ setIsLaunching(false);
154
+ }
155
+ }
156
+ }, [appendProviderEvent, authFetch, baseUrl, deleteAgent]);
157
+ useEffect(() => {
158
+ void launchAgentForProvider(provider);
159
+ }, [launchAgentForProvider, provider]);
160
+ useEffect(() => {
161
+ return () => {
162
+ const existing = currentAgentRef.current;
163
+ if (existing) {
164
+ void deleteAgent(existing);
165
+ }
166
+ };
167
+ }, [deleteAgent]);
168
+ const onProviderChange = useCallback((next) => {
169
+ setProvider(next);
170
+ }, []);
171
+ useAIAgentsWebSocket({
172
+ enabled: Boolean(agentId) && !isLaunching,
173
+ baseUrl,
174
+ path: '/api/v1/tool-approvals/ws',
175
+ queryParams: agentId ? { agent_id: agentId } : undefined,
176
+ onMessage: message => {
177
+ const eventType = typeof message.type === 'string'
178
+ ? message.type
179
+ : typeof message.event === 'string'
180
+ ? message.event
181
+ : 'stream.message';
182
+ appendProviderEvent('provider.stream', `Received ${eventType}`, {
183
+ provider,
184
+ agentId,
185
+ message: message.raw ?? message,
186
+ });
187
+ },
188
+ reconnectDelayMs: attempt => Math.min(1000 * 2 ** Math.max(0, attempt - 1), 10000),
189
+ });
190
+ const orderedProviderEvents = useMemo(() => [...providerEvents].sort((a, b) => b.createdAt.localeCompare(a.createdAt)), [providerEvents]);
191
+ const toggleEventExpanded = useCallback((eventId) => {
192
+ setExpandedEventIds(prev => {
193
+ const next = new Set(prev);
194
+ if (next.has(eventId)) {
195
+ next.delete(eventId);
196
+ }
197
+ else {
198
+ next.add(eventId);
199
+ }
200
+ return next;
201
+ });
202
+ }, []);
203
+ return (_jsx(ThemedProvider, { children: _jsxs(Box, { sx: {
204
+ height: '100%',
205
+ minHeight: 0,
206
+ width: '100%',
207
+ display: 'grid',
208
+ gridTemplateColumns: ['1fr', '1fr', 'minmax(680px, 1fr) 420px'],
209
+ gridTemplateRows: 'minmax(0, 1fr)',
210
+ overflow: 'hidden',
211
+ bg: 'canvas.default',
212
+ }, children: [_jsxs(Box, { sx: {
213
+ height: '100%',
214
+ borderRight: ['none', 'none', '1px solid'],
215
+ borderColor: 'border.default',
216
+ p: 3,
217
+ display: 'flex',
218
+ flexDirection: 'column',
219
+ gap: 3,
220
+ minHeight: 0,
221
+ overflow: 'hidden',
222
+ }, children: [_jsxs(Box, { sx: {
223
+ display: 'flex',
224
+ justifyContent: 'space-between',
225
+ alignItems: 'center',
226
+ flexWrap: 'wrap',
227
+ gap: 2,
228
+ }, children: [_jsxs(Box, { children: [_jsx(Heading, { as: "h2", sx: { fontSize: 4, mb: 1 }, children: "Agent Inference Provider Example" }), _jsxs(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: ["Launches a local agent runtime from ", AGENT_SPEC_ID, " and lets you switch between local and datalayer inference."] })] }), _jsx(ProviderBadge, { provider: provider })] }), _jsxs(SegmentedControl, { "aria-label": "Inference provider", fullWidth: true, children: [_jsx(SegmentedControl.Button, { selected: provider === 'local', onClick: () => onProviderChange('local'), children: "local" }), _jsx(SegmentedControl.Button, { selected: provider === 'datalayer', onClick: () => onProviderChange('datalayer'), children: "datalayer" })] }), _jsxs(Box, { sx: {
229
+ display: 'flex',
230
+ gap: 2,
231
+ alignItems: 'center',
232
+ flexWrap: 'wrap',
233
+ }, children: [isLaunching ? _jsx(Spinner, { size: "small" }) : null, _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: ["Runtime URL: ", baseUrl] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: ["Inference URL: ", inferenceUrl] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: ["Agent ID: ", agentId || 'launching...'] })] }), error ? (_jsx(Box, { sx: {
234
+ p: 2,
235
+ borderRadius: 2,
236
+ border: '1px solid',
237
+ borderColor: 'danger.emphasis',
238
+ bg: 'danger.subtle',
239
+ color: 'danger.fg',
240
+ fontSize: 1,
241
+ }, children: error })) : null, _jsx(Box, { sx: {
242
+ flexGrow: 1,
243
+ flexShrink: 1,
244
+ flexBasis: 0,
245
+ minHeight: 0,
246
+ border: '1px solid',
247
+ borderColor: 'border.default',
248
+ borderRadius: 2,
249
+ overflow: 'hidden',
250
+ bg: 'canvas.default',
251
+ }, children: agentId && !isLaunching ? (_jsx(Chat, { protocol: "vercel-ai", baseUrl: baseUrl, agentId: agentId, authToken: token ?? undefined, title: "Agent Inference Provider Example", subtitle: `Spec: ${AGENT_SPEC_ID}`, placeholder: "Ask the inference provider something...", showHeader: true, showNewChatButton: true, showClearButton: false, showModelSelector: true, showToolsMenu: true, showSkillsMenu: true, showTokenUsage: true, autoFocus: true, height: "100%", runtimeId: agentId, historyEndpoint: `${baseUrl}/api/v1/history`, onMessageSent: content => {
252
+ appendProviderEvent('provider.request', `Sent message via ${provider}`, {
253
+ provider,
254
+ agentId,
255
+ content,
256
+ });
257
+ }, onMessageReceived: message => {
258
+ appendProviderEvent('provider.message', 'Received stream message', message);
259
+ }, suggestions: [
260
+ {
261
+ title: 'Compare providers',
262
+ message: 'Give me a short 3-point comparison between local and datalayer inference providers.',
263
+ },
264
+ ], submitOnSuggestionClick: true })) : (_jsxs(Box, { sx: {
265
+ height: '100%',
266
+ display: 'flex',
267
+ alignItems: 'center',
268
+ justifyContent: 'center',
269
+ gap: 2,
270
+ color: 'fg.muted',
271
+ }, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { fontSize: 1 }, children: "Launching provider runtime\u2026" })] })) })] }), _jsxs(Box, { sx: {
272
+ p: 3,
273
+ display: ['none', 'none', 'flex'],
274
+ flexDirection: 'column',
275
+ gap: 2,
276
+ minHeight: 0,
277
+ overflow: 'hidden',
278
+ bg: 'canvas.inset',
279
+ }, children: [_jsx(Heading, { as: "h3", sx: { fontSize: 2 }, children: "Provider Event Stream" }), _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "Low-level request/response events exchanged with the inference provider (newest first)." }), _jsx(Box, { sx: {
280
+ flex: 1,
281
+ minHeight: 0,
282
+ overflowY: 'auto',
283
+ display: 'flex',
284
+ flexDirection: 'column',
285
+ gap: 2,
286
+ }, children: providerEvents.length === 0 ? (_jsx(Box, { sx: {
287
+ border: '1px dashed',
288
+ borderColor: 'border.default',
289
+ borderRadius: 2,
290
+ p: 3,
291
+ }, children: _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "No provider events yet." }) })) : (orderedProviderEvents.map(event => (_jsxs(Box, { sx: {
292
+ border: '1px solid',
293
+ borderColor: 'border.default',
294
+ borderRadius: 2,
295
+ p: 2,
296
+ bg: 'canvas.default',
297
+ }, children: [_jsx(Text, { sx: {
298
+ display: 'block',
299
+ fontSize: 0,
300
+ color: 'fg.muted',
301
+ textTransform: 'uppercase',
302
+ letterSpacing: '0.04em',
303
+ }, children: event.type }), _jsx(Text, { sx: {
304
+ display: 'block',
305
+ fontWeight: 600,
306
+ fontSize: 1,
307
+ mt: 1,
308
+ }, children: event.summary }), _jsx(Text, { sx: {
309
+ display: 'block',
310
+ color: 'fg.muted',
311
+ fontSize: 0,
312
+ mt: 1,
313
+ }, children: new Date(event.createdAt).toLocaleTimeString() }), _jsx(Box, { sx: { mt: 2 }, children: _jsx(Button, { size: "small", variant: "invisible", onClick: () => toggleEventExpanded(event.id), children: expandedEventIds.has(event.id)
314
+ ? 'Hide details'
315
+ : 'Show details' }) }), expandedEventIds.has(event.id) ? (_jsx(Text, { as: "pre", sx: {
316
+ mt: 2,
317
+ mb: 0,
318
+ p: 2,
319
+ borderRadius: 2,
320
+ bg: 'canvas.subtle',
321
+ fontSize: 0,
322
+ whiteSpace: 'pre-wrap',
323
+ fontFamily: 'mono',
324
+ }, children: event.payload })) : null] }, event.id)))) })] })] }) }));
325
+ };
326
+ const AgentInferenceProviderExample = () => {
327
+ return (_jsx(QueryClientProvider, { client: queryClient, children: _jsx(AgentInferenceProviderExampleInner, {}) }));
328
+ };
329
+ export default AgentInferenceProviderExample;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const AgentMCPExample: React.FC;
3
+ export default AgentMCPExample;