@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,261 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, 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
+ /**
7
+ * Agent Runtime Lexical Example - Next generation chat with Lexical editor.
8
+ *
9
+ * This example demonstrates using the chat component with:
10
+ * - Lexical editor integration
11
+ * - Frontend tool execution
12
+ * - Multiple protocol support (AG-UI, A2A)
13
+ * - Middleware and extensions
14
+ *
15
+ * To run this example, create a .env file with:
16
+ * - VITE_DATALAYER_API_KEY: Get from https://datalayer.app/settings/iam/tokens
17
+ *
18
+ * @module examples/LexicalAgentSidebarExample
19
+ */
20
+ import '@datalayer/jupyter-react/lib/css/PrismCss';
21
+ import { useCallback, useEffect, useMemo, useState } from 'react';
22
+ import { LexicalComposer } from '@lexical/react/LexicalComposer';
23
+ import { RichTextPlugin } from '@lexical/react/LexicalRichTextPlugin';
24
+ import { ContentEditable } from '@lexical/react/LexicalContentEditable';
25
+ import { HistoryPlugin } from '@lexical/react/LexicalHistoryPlugin';
26
+ import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
27
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
28
+ import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
29
+ import { AutoFocusPlugin } from '@lexical/react/LexicalAutoFocusPlugin';
30
+ import { MarkdownShortcutPlugin } from '@lexical/react/LexicalMarkdownShortcutPlugin';
31
+ import { TRANSFORMERS } from '@lexical/markdown';
32
+ import { registerCodeHighlighting } from '@lexical/code';
33
+ import { ListPlugin } from '@lexical/react/LexicalListPlugin';
34
+ import { CheckListPlugin } from '@lexical/react/LexicalCheckListPlugin';
35
+ import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
36
+ import { Box } from '@datalayer/primer-addons';
37
+ import { useJupyter } from '@datalayer/jupyter-react';
38
+ import { ThemedJupyterProvider } from './utils/themedProvider';
39
+ import { ComponentPickerMenuPlugin, JupyterCellPlugin, JupyterInputOutputPlugin, DraggableBlockPlugin, ImagesPlugin, HorizontalRulePlugin, EquationsPlugin, YouTubePlugin, ExcalidrawPlugin, CollapsiblePlugin, AutoLinkPlugin, AutoEmbedPlugin, FloatingTextFormatToolbarPlugin, CodeActionMenuPlugin, ListMaxIndentLevelPlugin, LexicalConfigProvider, LexicalStatePlugin, TableCellResizerPlugin, TablePlugin, } from '@datalayer/jupyter-lexical';
40
+ import { ChatSidebar } from '../chat';
41
+ import { ChatInlinePlugin } from '../lexical/ChatInlinePlugin';
42
+ import { useChatInlineToolbarItems } from '../lexical/useChatInlineToolbarItems';
43
+ import { useLexicalTools } from '../tools/adapters/agent-runtimes/lexicalHooks';
44
+ import { editorConfig } from './lexical/editorConfig';
45
+ import { DEFAULT_MODEL } from '../specs';
46
+ import '@datalayer/jupyter-lexical/style/index.css';
47
+ import './lexical/lexical-theme.css';
48
+ // Fixed lexical document ID
49
+ const LEXICAL_ID = 'chat-lexical-example';
50
+ // Default configuration
51
+ const DEFAULT_BASE_URL = import.meta.env.VITE_BASE_URL || 'http://localhost:8765';
52
+ const DEFAULT_AGENT_ID = import.meta.env.VITE_AGENT_ID || 'lexical-sidebar-agent-runtime-example';
53
+ const VERCEL_AI_ENDPOINT = `${DEFAULT_BASE_URL}/api/v1/vercel-ai/${DEFAULT_AGENT_ID}`;
54
+ function getJupyterSandboxUrl(serviceManager) {
55
+ const envUrl = import.meta.env.VITE_JUPYTER_SANDBOX_URL;
56
+ if (envUrl) {
57
+ return envUrl;
58
+ }
59
+ const baseUrl = serviceManager?.serverSettings?.baseUrl?.replace(/\/$/, '');
60
+ if (!baseUrl) {
61
+ return undefined;
62
+ }
63
+ if (baseUrl.includes('token=')) {
64
+ return baseUrl;
65
+ }
66
+ const token = serviceManager?.serverSettings?.token;
67
+ if (!token) {
68
+ return baseUrl;
69
+ }
70
+ const separator = baseUrl.includes('?') ? '&' : '?';
71
+ return `${baseUrl}${separator}token=${encodeURIComponent(token)}`;
72
+ }
73
+ function useEnsureAgent(agentId, baseUrl, jupyterSandboxUrl) {
74
+ const [isReady, setIsReady] = useState(false);
75
+ const [error, setError] = useState(null);
76
+ useEffect(() => {
77
+ let mounted = true;
78
+ async function ensureAgent() {
79
+ try {
80
+ if (!jupyterSandboxUrl) {
81
+ if (mounted) {
82
+ setError('Could not detect Jupyter server URL from Lexical service manager.');
83
+ setIsReady(false);
84
+ }
85
+ return;
86
+ }
87
+ const response = await fetch(`${baseUrl}/api/v1/agents`, {
88
+ method: 'POST',
89
+ headers: {
90
+ 'Content-Type': 'application/json',
91
+ },
92
+ body: JSON.stringify({
93
+ name: agentId,
94
+ description: 'Demo agent for lexical sidebar example',
95
+ agent_library: 'pydantic-ai',
96
+ transport: 'vercel-ai',
97
+ model: DEFAULT_MODEL,
98
+ system_prompt: 'You are a helpful AI assistant that helps users work with lexical documents. For document operations, always use the lexical frontend tools so actions happen in the live document UI. Use executeCode only for temporary inspection code that should not modify persisted document content.',
99
+ enable_codemode: false,
100
+ sandbox_variant: 'jupyter',
101
+ jupyter_sandbox: jupyterSandboxUrl,
102
+ }),
103
+ });
104
+ if (mounted) {
105
+ if (response.ok) {
106
+ console.warn(`[LexicalAgentSidebarExample] Created agent: ${agentId}`);
107
+ setError(null);
108
+ setIsReady(true);
109
+ }
110
+ else if (response.status === 409 || response.status === 400) {
111
+ console.warn(`[LexicalAgentSidebarExample] Reusing existing agent: ${agentId}`);
112
+ setError(null);
113
+ setIsReady(true);
114
+ }
115
+ else {
116
+ const errorData = await response.json().catch(() => ({}));
117
+ setError(errorData.detail || `Failed to create agent: ${response.status}`);
118
+ setIsReady(false);
119
+ }
120
+ }
121
+ }
122
+ catch (err) {
123
+ if (mounted) {
124
+ console.error('[LexicalAgentSidebarExample] Error creating agent:', err);
125
+ setError(err instanceof Error ? err.message : 'Failed to connect to server');
126
+ setIsReady(false);
127
+ }
128
+ }
129
+ }
130
+ void ensureAgent();
131
+ return () => {
132
+ mounted = false;
133
+ };
134
+ }, [agentId, baseUrl, jupyterSandboxUrl]);
135
+ return { isReady, error };
136
+ }
137
+ /**
138
+ * Lexical plugin for code highlighting
139
+ */
140
+ function CodeHighlightingPlugin() {
141
+ const [editor] = useLexicalComposerContext();
142
+ useEffect(() => {
143
+ return registerCodeHighlighting(editor);
144
+ }, [editor]);
145
+ return null;
146
+ }
147
+ function LexicalEditor({ serviceManager }) {
148
+ const [floatingAnchorElem, setFloatingAnchorElem] = useState(null);
149
+ const [_isLinkEditMode, setIsLinkEditMode] = useState(false);
150
+ // AI actions registered as toolbar items
151
+ const { toolbarItems, isAiOpen, pendingPrompt, clearPendingPrompt, closeAi } = useChatInlineToolbarItems();
152
+ const onRef = (_floatingAnchorElem) => {
153
+ if (_floatingAnchorElem !== null) {
154
+ setFloatingAnchorElem(_floatingAnchorElem);
155
+ }
156
+ };
157
+ // Handle editor changes
158
+ const onChange = useCallback((_editorState) => {
159
+ // Could persist state here
160
+ }, []);
161
+ return (_jsx(LexicalConfigProvider, { lexicalId: LEXICAL_ID, serviceManager: serviceManager, children: _jsxs(LexicalComposer, { initialConfig: editorConfig, children: [_jsx(LexicalStatePlugin, {}), _jsxs(Box, { sx: {
162
+ position: 'relative',
163
+ flex: 1,
164
+ display: 'flex',
165
+ flexDirection: 'column',
166
+ overflow: 'hidden',
167
+ }, children: [_jsx(RichTextPlugin, { contentEditable: _jsx("div", { ref: onRef, style: { flex: 1, display: 'flex', flexDirection: 'column' }, children: _jsx(ContentEditable, { className: "lexical-editor-content", style: {
168
+ flex: 1,
169
+ padding: '24px',
170
+ outline: 'none',
171
+ overflow: 'auto',
172
+ } }) }), placeholder: _jsx("div", { style: {
173
+ position: 'absolute',
174
+ top: '24px',
175
+ left: '24px',
176
+ color: 'var(--fgColor-muted)',
177
+ pointerEvents: 'none',
178
+ }, children: "Start typing or use the chat to create content..." }), ErrorBoundary: LexicalErrorBoundary }), _jsx(HistoryPlugin, {}), _jsx(AutoFocusPlugin, {}), _jsx(OnChangePlugin, { onChange: onChange }), _jsx(MarkdownShortcutPlugin, { transformers: TRANSFORMERS }), _jsx(CodeHighlightingPlugin, {}), _jsx(ListPlugin, {}), _jsx(CheckListPlugin, {}), _jsx(LinkPlugin, {}), _jsx(TablePlugin, {}), _jsx(TableCellResizerPlugin, {}), _jsx(JupyterCellPlugin, {}), _jsx(JupyterInputOutputPlugin, {}), _jsx(ImagesPlugin, {}), _jsx(HorizontalRulePlugin, {}), _jsx(EquationsPlugin, {}), _jsx(YouTubePlugin, {}), _jsx(ExcalidrawPlugin, {}), _jsx(CollapsiblePlugin, {}), _jsx(AutoLinkPlugin, {}), _jsx(AutoEmbedPlugin, {}), _jsx(ListMaxIndentLevelPlugin, { maxDepth: 7 }), floatingAnchorElem && (_jsxs(_Fragment, { children: [_jsx(ComponentPickerMenuPlugin, {}), _jsx(DraggableBlockPlugin, { anchorElem: floatingAnchorElem }), _jsx(FloatingTextFormatToolbarPlugin, { anchorElem: floatingAnchorElem, setIsLinkEditMode: setIsLinkEditMode, extraItems: toolbarItems }), _jsx(CodeActionMenuPlugin, { anchorElem: floatingAnchorElem })] })), _jsx(ChatInlinePlugin, { protocol: {
179
+ type: 'vercel-ai',
180
+ endpoint: VERCEL_AI_ENDPOINT,
181
+ }, isOpen: isAiOpen, onClose: closeAi, pendingPrompt: pendingPrompt, onPendingPromptConsumed: clearPendingPrompt })] })] }) }));
182
+ }
183
+ export function ChatLexicalAgentExampleInner({ serviceManager, }) {
184
+ const jupyterSandboxUrl = useMemo(() => getJupyterSandboxUrl(serviceManager), [serviceManager]);
185
+ const { isReady, error } = useEnsureAgent(DEFAULT_AGENT_ID, DEFAULT_BASE_URL, jupyterSandboxUrl);
186
+ // Get lexical tools for ChatSidebar
187
+ const tools = useLexicalTools(LEXICAL_ID);
188
+ // Build Vercel AI protocol config
189
+ const protocolConfig = useMemo(() => {
190
+ return {
191
+ type: 'vercel-ai',
192
+ endpoint: VERCEL_AI_ENDPOINT,
193
+ agentId: DEFAULT_AGENT_ID,
194
+ enableConfigQuery: true,
195
+ configEndpoint: `${DEFAULT_BASE_URL}/api/v1/configure`,
196
+ };
197
+ }, []);
198
+ return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: {
199
+ height: 'calc(100vh - 70px)',
200
+ width: '100vw',
201
+ display: 'flex',
202
+ overflow: 'hidden',
203
+ }, children: [_jsxs(Box, { sx: {
204
+ flex: 1,
205
+ display: 'flex',
206
+ flexDirection: 'column',
207
+ overflow: 'hidden',
208
+ }, children: [_jsxs(Box, { sx: {
209
+ p: 3,
210
+ borderBottom: '1px solid',
211
+ borderColor: 'border.default',
212
+ bg: 'canvas.subtle',
213
+ }, children: [_jsx("h1", { style: { margin: 0, fontSize: '1.5rem' }, children: "Agent Runtime Lexical Sidebar Example" }), _jsx("p", { style: { margin: '8px 0 0', color: 'var(--fgColor-muted)' }, children: "Next generation chat with Lexical editor integration (NO Provider!)" })] }), _jsx(Box, { sx: {
214
+ flex: 1,
215
+ display: 'flex',
216
+ overflow: 'hidden',
217
+ bg: 'canvas.default',
218
+ }, children: _jsx(LexicalEditor, { serviceManager: serviceManager }) })] }), isReady && (_jsx(ChatSidebar, { title: "AI Assistant", protocol: protocolConfig, position: "right", width: 400, showNewChatButton: true, showClearButton: true, showSettingsButton: true, defaultOpen: true, panelProps: {
219
+ protocol: protocolConfig,
220
+ frontendTools: tools,
221
+ useStore: true,
222
+ suggestions: [
223
+ {
224
+ title: '✍️ Help me write',
225
+ message: 'Can you help me write a document?',
226
+ },
227
+ {
228
+ title: '📝 Summarize text',
229
+ message: 'Can you summarize the content in the editor?',
230
+ },
231
+ {
232
+ title: '🔍 Proofread',
233
+ message: 'Can you proofread and improve my text?',
234
+ },
235
+ {
236
+ title: '💡 Generate ideas',
237
+ message: 'Can you suggest some ideas for content?',
238
+ },
239
+ ],
240
+ } }))] }), error && (_jsxs(Box, { sx: {
241
+ position: 'fixed',
242
+ bottom: 20,
243
+ right: 20,
244
+ padding: 3,
245
+ backgroundColor: 'danger.subtle',
246
+ color: 'danger.fg',
247
+ borderRadius: 2,
248
+ maxWidth: 300,
249
+ }, children: [_jsx("strong", { children: "Error:" }), " ", error] }))] }));
250
+ }
251
+ /**
252
+ * Main example component with Simple wrapper
253
+ */
254
+ export function AgentRuntimeLexicalAgentSidebarExample() {
255
+ return (_jsx(ThemedJupyterProvider, { children: _jsx(SimpleWrapper, {}) }));
256
+ }
257
+ function SimpleWrapper() {
258
+ const { serviceManager } = useJupyter();
259
+ return _jsx(ChatLexicalAgentExampleInner, { serviceManager: serviceManager });
260
+ }
261
+ export default AgentRuntimeLexicalAgentSidebarExample;
@@ -0,0 +1,9 @@
1
+ import { ServiceManager } from '@jupyterlab/services';
2
+ /**
3
+ * Main Agent Runtime notebook example component
4
+ */
5
+ interface AgentRuntimeNotebookExampleProps {
6
+ serviceManager?: ServiceManager.IManager;
7
+ }
8
+ declare function AgentRuntimeNotebookExample({ serviceManager, }: AgentRuntimeNotebookExampleProps): JSX.Element;
9
+ export default AgentRuntimeNotebookExample;
@@ -0,0 +1,192 @@
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
+ /**
7
+ * Agent Runtime Notebook Example with Agent-Runtimes Integration
8
+ *
9
+ * This example demonstrates using the agent-runtimes ChatFloating component
10
+ * with notebook tools for AI-assisted notebook editing.
11
+ *
12
+ * To run this example:
13
+ * 1. Start the agent-runtimes server: `npm run start:server`
14
+ * 2. Start the frontend: `npm run dev`
15
+ *
16
+ * @module examples/NotebookAgentExample
17
+ */
18
+ import React, { useEffect, useMemo, useState } from 'react';
19
+ import { Box } from '@datalayer/primer-addons';
20
+ import { Notebook } from '@datalayer/jupyter-react';
21
+ import { ThemedJupyterProvider } from './utils/themedProvider';
22
+ // Agent-runtimes imports
23
+ import { ChatFloating } from '../chat';
24
+ import { useNotebookTools } from '../tools/adapters/agent-runtimes/notebookHooks';
25
+ // Import Matplotlib notebook
26
+ import MatplotlibNotebook from './utils/notebooks/Matplotlib.ipynb.json';
27
+ import { DEFAULT_MODEL } from '../specs';
28
+ // Fixed notebook ID
29
+ const NOTEBOOK_ID = 'agui-notebook-example';
30
+ // Use the imported Matplotlib notebook
31
+ const NOTEBOOK_CONTENT = MatplotlibNotebook;
32
+ // Base URL for agent-runtimes server
33
+ const BASE_URL = 'http://localhost:8765';
34
+ const AGENT_ID = 'notebook-agent-runtime-example';
35
+ // Vercel AI endpoint
36
+ const VERCEL_AI_ENDPOINT = `${BASE_URL}/api/v1/vercel-ai/${AGENT_ID}`;
37
+ function getJupyterSandboxUrl(serviceManager) {
38
+ const envUrl = import.meta.env.VITE_JUPYTER_SANDBOX_URL;
39
+ if (envUrl) {
40
+ return envUrl;
41
+ }
42
+ const baseUrl = serviceManager?.serverSettings?.baseUrl?.replace(/\/$/, '');
43
+ if (!baseUrl) {
44
+ return undefined;
45
+ }
46
+ if (baseUrl.includes('token=')) {
47
+ return baseUrl;
48
+ }
49
+ const token = serviceManager?.serverSettings?.token;
50
+ if (!token) {
51
+ return baseUrl;
52
+ }
53
+ const separator = baseUrl.includes('?') ? '&' : '?';
54
+ return `${baseUrl}${separator}token=${encodeURIComponent(token)}`;
55
+ }
56
+ /**
57
+ * Hook to ensure the example-agent is aligned with the active notebook runtime.
58
+ * Recreates the agent with jupyter sandbox settings from the Notebook UI.
59
+ */
60
+ function useEnsureAgent(agentId, baseUrl, jupyterSandboxUrl) {
61
+ const [isReady, setIsReady] = useState(false);
62
+ const [error, setError] = useState(null);
63
+ useEffect(() => {
64
+ let mounted = true;
65
+ async function ensureAgent() {
66
+ try {
67
+ if (!jupyterSandboxUrl) {
68
+ if (mounted) {
69
+ setError('Could not detect Jupyter server URL from Notebook service manager.');
70
+ setIsReady(false);
71
+ }
72
+ return;
73
+ }
74
+ const response = await fetch(`${baseUrl}/api/v1/agents`, {
75
+ method: 'POST',
76
+ headers: {
77
+ 'Content-Type': 'application/json',
78
+ },
79
+ body: JSON.stringify({
80
+ name: agentId,
81
+ description: 'Demo agent for notebook example',
82
+ agent_library: 'pydantic-ai',
83
+ transport: 'vercel-ai',
84
+ model: DEFAULT_MODEL,
85
+ system_prompt: 'You are a helpful AI assistant that helps users work with Jupyter notebooks. For notebook operations, always use the notebook frontend tools (runCell, readAllCells, readCell, insertCell, updateCell, deleteCells) so actions happen in the live notebook UI. Use executeCode only for temporary inspection code that should not modify notebook cells.',
86
+ enable_codemode: false,
87
+ sandbox_variant: 'jupyter',
88
+ jupyter_sandbox: jupyterSandboxUrl,
89
+ }),
90
+ });
91
+ if (mounted) {
92
+ if (response.ok) {
93
+ console.warn(`[AgentRuntimeExample] Created agent: ${agentId}`);
94
+ setError(null);
95
+ setIsReady(true);
96
+ }
97
+ else if (response.status === 409 || response.status === 400) {
98
+ // Agent already exists; reuse it and continue.
99
+ console.warn(`[AgentRuntimeExample] Reusing existing agent: ${agentId}`);
100
+ setError(null);
101
+ setIsReady(true);
102
+ }
103
+ else {
104
+ const errorData = await response.json().catch(() => ({}));
105
+ setError(errorData.detail || `Failed to create agent: ${response.status}`);
106
+ }
107
+ }
108
+ }
109
+ catch (err) {
110
+ if (mounted) {
111
+ console.error('[AgentRuntimeExample] Error creating agent:', err);
112
+ setError(err instanceof Error ? err.message : 'Failed to connect to server');
113
+ }
114
+ }
115
+ }
116
+ ensureAgent();
117
+ return () => {
118
+ mounted = false;
119
+ };
120
+ }, [agentId, baseUrl, jupyterSandboxUrl]);
121
+ return { isReady, error };
122
+ }
123
+ const NotebookUI = React.memo(function NotebookUI({ serviceManager, }) {
124
+ return (_jsxs(Box, { sx: {
125
+ flex: 1,
126
+ display: 'flex',
127
+ flexDirection: 'column',
128
+ overflow: 'auto',
129
+ padding: 3,
130
+ }, children: [_jsxs(Box, { sx: {
131
+ marginBottom: 3,
132
+ paddingBottom: 3,
133
+ borderBottom: '1px solid',
134
+ borderColor: 'border.default',
135
+ }, children: [_jsx(Box, { as: "h1", sx: { margin: 0 }, children: "Agent Runtime Notebook Example" }), _jsx("p", { children: "Platform-agnostic tool usage with agent-runtimes integration. Use the AI copilot to manipulate the notebook." })] }), _jsx(Box, { sx: {
136
+ border: '1px solid',
137
+ borderColor: 'border.default',
138
+ borderRadius: 2,
139
+ padding: 3,
140
+ backgroundColor: 'canvas.default',
141
+ }, children: serviceManager ? (_jsx(ThemedJupyterProvider, { children: _jsx(Notebook, { nbformat: NOTEBOOK_CONTENT, id: NOTEBOOK_ID, serviceManager: serviceManager, height: "calc(100vh - 300px)", cellSidebarMargin: 120, startDefaultKernel: true }) })) : (_jsx(Box, { sx: { padding: 3 }, children: _jsx("p", { children: "Loading service manager..." }) })) })] }));
142
+ });
143
+ function NotebookWithChat({ serviceManager, }) {
144
+ const jupyterSandboxUrl = useMemo(() => getJupyterSandboxUrl(serviceManager), [serviceManager]);
145
+ // Ensure the agent exists before rendering chat
146
+ const { isReady, error } = useEnsureAgent(AGENT_ID, BASE_URL, jupyterSandboxUrl);
147
+ const protocolConfig = useMemo(() => ({
148
+ type: 'vercel-ai',
149
+ endpoint: VERCEL_AI_ENDPOINT,
150
+ agentId: AGENT_ID,
151
+ enableConfigQuery: true,
152
+ configEndpoint: `${BASE_URL}/api/v1/configure`,
153
+ }), []);
154
+ // Get notebook tools for ChatFloating
155
+ const frontendTools = useNotebookTools(NOTEBOOK_ID);
156
+ return (_jsxs(Box, { sx: {
157
+ height: '100%',
158
+ width: '100%',
159
+ display: 'flex',
160
+ overflow: 'hidden',
161
+ }, children: [_jsx(NotebookUI, { serviceManager: serviceManager }), error && (_jsxs(Box, { sx: {
162
+ position: 'fixed',
163
+ bottom: 20,
164
+ right: 20,
165
+ padding: 3,
166
+ backgroundColor: 'danger.subtle',
167
+ color: 'danger.fg',
168
+ borderRadius: 2,
169
+ maxWidth: 300,
170
+ }, children: [_jsx("strong", { children: "Error:" }), " ", error] })), isReady && (_jsx(ChatFloating, { protocol: protocolConfig, title: "Notebook AI Agent Runtime", description: "Hi! I can help you edit notebook cells. Try: 'Add a new code cell', 'Run cell 1', or 'Delete the last cell'", defaultOpen: true, defaultViewMode: "panel", position: "bottom-right", frontendTools: frontendTools, useStore: false, showModelSelector: true, showToolsMenu: true, showSkillsMenu: true, suggestions: [
171
+ {
172
+ title: 'Add a cell',
173
+ message: 'Insert a random cell to the notebook',
174
+ },
175
+ {
176
+ title: 'Run the first cell',
177
+ message: 'Run the first cell in the notebook',
178
+ },
179
+ {
180
+ title: 'Show cells',
181
+ message: 'Show the notebook cells content and compute the number of cells',
182
+ },
183
+ {
184
+ title: 'Analyze Titanic',
185
+ message: 'Analyze the Titanic dataset and provide insights about the passengers and survival rates',
186
+ },
187
+ ] }))] }));
188
+ }
189
+ function AgentRuntimeNotebookExample({ serviceManager, }) {
190
+ return _jsx(NotebookWithChat, { serviceManager: serviceManager });
191
+ }
192
+ export default AgentRuntimeNotebookExample;
@@ -9,5 +9,5 @@ export declare function AgentRuntimeNotebookExampleInner({ serviceManager, }: Ch
9
9
  /**
10
10
  * Main example component with Simple wrapper
11
11
  */
12
- export declare function AgentRuntimeNotebookSidebarExample(): import("react/jsx-runtime").JSX.Element;
13
- export default AgentRuntimeNotebookSidebarExample;
12
+ export declare function AgentRuntimeNotebookAgentSidebarExample(): import("react/jsx-runtime").JSX.Element;
13
+ export default AgentRuntimeNotebookAgentSidebarExample;