@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
@@ -4,6 +4,7 @@ import type { AgentConnection } from '../types/connection';
4
4
  import type { AgentStatus, AgentRuntimeData } from '../types/agents';
5
5
  import type { CreateAgentRuntimeRequest, AgentLifecycleState, CreateRuntimeApiResponse } from '../types/agents-lifecycle';
6
6
  import { ServiceManager } from '@jupyterlab/services/lib/manager';
7
+ export type RuntimeCreationTarget = 'backend-services' | 'local-agent-runtimes';
7
8
  /**
8
9
  * Options for the useAgents hook.
9
10
  */
@@ -18,6 +19,14 @@ export interface UseAgentOptions {
18
19
  autoStart?: boolean;
19
20
  /** Full agent spec object (persisted with checkpoints) */
20
21
  agentSpec?: Record<string, any>;
22
+ /**
23
+ * Where runtime create/list operations should be sent.
24
+ * - `backend-services`: use backend runtimes service URL
25
+ * - `local-agent-runtimes`: use local agent-runtimes URL
26
+ */
27
+ runtimeCreationTarget?: RuntimeCreationTarget;
28
+ /** Explicit base URL for runtime create/list operations. */
29
+ runtimeCreationBaseUrl?: string;
21
30
  }
22
31
  /**
23
32
  * Return type for the useAgents hook.
@@ -53,6 +62,10 @@ export interface UseAgentReturn {
53
62
  isReady: boolean;
54
63
  /** Error if any */
55
64
  error: string | null;
65
+ /** Effective runtime creation target mode. */
66
+ runtimeCreationTarget: RuntimeCreationTarget;
67
+ /** Effective base URL used for runtime create/list operations. */
68
+ runtimeCreationBaseUrl: string;
56
69
  }
57
70
  /** Default query options for all agent runtime queries. */
58
71
  export declare const AGENT_QUERY_OPTIONS: {
@@ -87,7 +100,7 @@ export declare const agentQueryKeys: {
87
100
  * // Connect mode — attach to an existing runtime
88
101
  * const { isReady, endpoint, connectToRuntime } = useAgents({
89
102
  * autoCreateAgent: true,
90
- * agentConfig: { model: 'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0' },
103
+ * agentConfig: { model: 'bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0' },
91
104
  * });
92
105
  *
93
106
  * // Lifecycle mode — full lifecycle with agentSpecId
@@ -98,14 +111,22 @@ export declare const agentQueryKeys: {
98
111
  * });
99
112
  * ```
100
113
  */
101
- export declare function useAgents(options?: UseAgentOptions): UseAgentReturn;
114
+ export declare function useAgentRuntimes(options?: UseAgentOptions): UseAgentReturn;
102
115
  /**
103
116
  * Hook to fetch user's agent runtimes (running agent instances).
104
117
  *
105
118
  * The backend returns active runtimes from the operator **plus** paused
106
119
  * runtimes synthesised from Solr checkpoint records (with ``status="paused"``).
107
120
  */
108
- export declare function useAgentRuntimes(): import("@tanstack/react-query").UseQueryResult<AgentRuntimeData[], Error>;
121
+ export declare function useAgentRuntimesQuery(scope?: {
122
+ selectedUserUid?: string;
123
+ selectedOrganizationUid?: string;
124
+ selectedTeamUid?: string;
125
+ selectedAgentUid?: string;
126
+ }, queryOptions?: {
127
+ enabled?: boolean;
128
+ refetchInterval?: number | false;
129
+ }): import("@tanstack/react-query").UseQueryResult<AgentRuntimeData[], Error>;
109
130
  /**
110
131
  * Hook to fetch a single agent runtime by pod name.
111
132
  */
@@ -149,4 +170,49 @@ export interface UseAgentsRuntimesReturn {
149
170
  /**
150
171
  * Consolidated runtime list and mutations.
151
172
  */
152
- export declare function useAgentsRuntimes(): UseAgentsRuntimesReturn;
173
+ export declare function useAgentsRuntimes(scope?: {
174
+ selectedUserUid?: string;
175
+ selectedOrganizationUid?: string;
176
+ selectedTeamUid?: string;
177
+ selectedAgentUid?: string;
178
+ }, queryOptions?: {
179
+ enabled?: boolean;
180
+ refetchInterval?: number | false;
181
+ }): UseAgentsRuntimesReturn;
182
+ export interface UseAgentRuntimeWebSocketOptions {
183
+ /** Enable/disable the connection. Defaults to `true`. */
184
+ enabled?: boolean;
185
+ /**
186
+ * Base URL of the agent-runtime server
187
+ * (e.g. `http://localhost:8765`). The WS path is appended automatically.
188
+ */
189
+ baseUrl: string;
190
+ /** Auth token passed as `?token=` query parameter. */
191
+ authToken?: string;
192
+ /** Optional `agent_id` query parameter to scope the stream. */
193
+ agentId?: string;
194
+ /** Auto-reconnect on unexpected disconnects. Defaults to `true`. */
195
+ autoReconnect?: boolean;
196
+ /** Delay between reconnection attempts (ms). Defaults to 3 000. */
197
+ reconnectDelayMs?: number | ((attempt: number) => number);
198
+ /** Maximum reconnect attempts. Unbounded by default. */
199
+ maxReconnectAttempts?: number;
200
+ /** Additional callback fired for every incoming WS message. */
201
+ onMessage?: (msg: {
202
+ type?: string;
203
+ payload?: unknown;
204
+ raw: unknown;
205
+ }) => void;
206
+ }
207
+ /**
208
+ * Connect to the agent-runtime monitoring WebSocket.
209
+ *
210
+ * The hook writes all incoming data into the `useAgentRuntimeStore` Zustand
211
+ * store. Components that need approvals, MCP status, context snapshots, or
212
+ * full-context data simply read from the store.
213
+ *
214
+ * Mount this hook **once** near the top of your component tree (e.g. in
215
+ * the example root or in `ChatBase`). All other components read from the
216
+ * store — no extra WebSocket connections needed.
217
+ */
218
+ export declare function useAgentRuntimeWebSocket(options: UseAgentRuntimeWebSocketOptions): void;
@@ -3,13 +3,13 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * Unified hook for managing agents.
6
+ * Unified hook for managing agent runtimes.
7
7
  *
8
8
  * Combines agent lifecycle management (ephemeral/durable),
9
9
  * runtime catalog (React Query CRUD), lifecycle/catalog stores,
10
- * and the AI Agents REST API.
10
+ * the AI Agents REST API, and the agent-runtime WebSocket stream.
11
11
  *
12
- * @module hooks/useAgents
12
+ * @module hooks/useAgentRuntimes
13
13
  */
14
14
  import { useState, useCallback, useMemo, useEffect, useRef } from 'react';
15
15
  import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
@@ -17,7 +17,8 @@ import { create } from 'zustand';
17
17
  import { persist, createJSONStorage } from 'zustand/middleware';
18
18
  import { useCoreStore, useDatalayer } from '@datalayer/core';
19
19
  import { useIAMStore } from '@datalayer/core/lib/state';
20
- import { useAgentStore, useAgentRuntime, useAgentStatus, useAgentError, useIsLaunching, } from '../stores/agentsStore';
20
+ import { agentRuntimeStore, useAgentRuntimeStore, useAgentRuntimeConnection, useAgentRuntimeStatus, useAgentRuntimeError, useAgentRuntimeIsLaunching, } from '../stores/agentRuntimeStore';
21
+ import { parseAgentStreamMessage, } from '../types/stream';
21
22
  import { DEFAULT_AGENT_CONFIG } from '../types/config';
22
23
  // ═══════════════════════════════════════════════════════════════════════════
23
24
  // Constants
@@ -64,6 +65,14 @@ const RUNTIME_STATUS_MAP = {
64
65
  function toAgentRuntimeData(raw) {
65
66
  const status = typeof raw.status === 'string' ? raw.status.toLowerCase() : '';
66
67
  const normalizedStatus = RUNTIME_STATUS_MAP[status] ?? 'running';
68
+ const rawVolumeUids = Array.isArray(raw.volume_uids)
69
+ ? raw.volume_uids
70
+ : raw.volume_uid
71
+ ? [raw.volume_uid]
72
+ : [];
73
+ const volume_uids = rawVolumeUids
74
+ .map((uid) => String(uid || '').trim())
75
+ .filter(Boolean);
67
76
  return {
68
77
  ...raw,
69
78
  status: normalizedStatus,
@@ -72,6 +81,8 @@ function toAgentRuntimeData(raw) {
72
81
  url: raw.ingress,
73
82
  messageCount: 0,
74
83
  agent_spec_id: raw.agent_spec_id || undefined,
84
+ volume_uids,
85
+ volume_uid: raw.volume_uid || volume_uids[0] || undefined,
75
86
  };
76
87
  }
77
88
  // ═══════════════════════════════════════════════════════════════════════════
@@ -92,7 +103,7 @@ function toAgentRuntimeData(raw) {
92
103
  * // Connect mode — attach to an existing runtime
93
104
  * const { isReady, endpoint, connectToRuntime } = useAgents({
94
105
  * autoCreateAgent: true,
95
- * agentConfig: { model: 'bedrock:us.anthropic.claude-3-5-haiku-20241022-v1:0' },
106
+ * agentConfig: { model: 'bedrock:us.anthropic.claude-sonnet-4-5-20250929-v1:0' },
96
107
  * });
97
108
  *
98
109
  * // Lifecycle mode — full lifecycle with agentSpecId
@@ -103,18 +114,19 @@ function toAgentRuntimeData(raw) {
103
114
  * });
104
115
  * ```
105
116
  */
106
- export function useAgents(options = {}) {
107
- const { agentSpecId, agentConfig, autoCreateAgent = true, autoStart = false, agentSpec, } = options;
117
+ export function useAgentRuntimes(options = {}) {
118
+ const { agentSpecId, agentConfig, autoCreateAgent = true, autoStart = false, agentSpec, runtimeCreationTarget = 'backend-services', runtimeCreationBaseUrl, } = options;
119
+ const { configuration } = useCoreStore();
108
120
  // Base store state
109
- const runtime = useAgentRuntime();
110
- const baseStatus = useAgentStatus();
111
- const storeError = useAgentError();
112
- const isLaunching = useIsLaunching();
121
+ const runtime = useAgentRuntimeConnection();
122
+ const baseStatus = useAgentRuntimeStatus();
123
+ const storeError = useAgentRuntimeError();
124
+ const isLaunching = useAgentRuntimeIsLaunching();
113
125
  // Store actions
114
- const storeLaunchAgent = useAgentStore(state => state.launchAgent);
115
- const storeConnectAgent = useAgentStore(state => state.connectAgent);
116
- const storeCreateAgent = useAgentStore(state => state.createAgent);
117
- const storeDisconnect = useAgentStore(state => state.disconnect);
126
+ const storeLaunchAgent = useAgentRuntimeStore(state => state.launchAgent);
127
+ const storeConnectAgent = useAgentRuntimeStore(state => state.connectAgent);
128
+ const storeCreateAgent = useAgentRuntimeStore(state => state.createAgent);
129
+ const storeDisconnect = useAgentRuntimeStore(state => state.disconnect);
118
130
  // Lifecycle local state
119
131
  const [lifecycleStatus, setLifecycleStatus] = useState('idle');
120
132
  const [lifecycleError, setLifecycleError] = useState(null);
@@ -127,6 +139,23 @@ export function useAgents(options = {}) {
127
139
  agentConfigRef.current = agentConfig;
128
140
  // Whether we're managing a full agent lifecycle (agentSpecId provided)
129
141
  const hasSpec = !!agentSpecId;
142
+ const resolvedRuntimeCreationBaseUrl = useMemo(() => {
143
+ if (runtimeCreationBaseUrl) {
144
+ return runtimeCreationBaseUrl;
145
+ }
146
+ if (runtimeCreationTarget === 'local-agent-runtimes') {
147
+ return (import.meta.env.VITE_DATALAYER_AGENT_RUNTIMES_URL ||
148
+ import.meta.env.VITE_BASE_URL ||
149
+ 'http://localhost:8765');
150
+ }
151
+ return (configuration?.runtimesRunUrl ||
152
+ import.meta.env.VITE_DATALAYER_AGENT_RUNTIMES_URL ||
153
+ 'https://r1.datalayer.run');
154
+ }, [
155
+ configuration?.runtimesRunUrl,
156
+ runtimeCreationBaseUrl,
157
+ runtimeCreationTarget,
158
+ ]);
130
159
  // ─── Auth helpers ─────────────────────────────────────────────────
131
160
  const getAuthHeaders = useCallback(async () => {
132
161
  try {
@@ -134,30 +163,39 @@ export function useAgents(options = {}) {
134
163
  const token = iamStore.getState().token || '';
135
164
  const config = coreStore.getState().configuration;
136
165
  const runUrl = config?.aiagentsRunUrl || '';
137
- const runtimesRunUrl = config?.runtimesRunUrl || '';
166
+ const runtimesRunUrl = resolvedRuntimeCreationBaseUrl;
138
167
  return { token, runUrl, runtimesRunUrl };
139
168
  }
140
169
  catch {
141
170
  return { token: '', runUrl: '', runtimesRunUrl: '' };
142
171
  }
143
- }, []);
172
+ }, [resolvedRuntimeCreationBaseUrl]);
144
173
  // ─── Launch Runtime ─────────────────────────────────────────────────
145
174
  const launchRuntime = useCallback(async (runtimeOptions) => {
146
175
  if (hasSpec) {
147
176
  setLifecycleStatus('launching');
148
177
  setLifecycleError(null);
149
178
  try {
150
- const safeName = `${agentSpecId}`
179
+ const preferredRuntimeName = (typeof agentConfig?.name === 'string' && agentConfig.name) ||
180
+ (typeof agentSpec?.name === 'string' && agentSpec.name) ||
181
+ `${agentSpecId}`;
182
+ const safeName = preferredRuntimeName
151
183
  .replace(/\//g, '-')
152
184
  .replace(/[^a-z0-9-]/g, '-')
153
185
  .replace(/-+/g, '-')
154
186
  .replace(/^-|-$/g, '')
155
187
  .slice(0, 63);
156
- const conn = await storeLaunchAgent(runtimeOptions || {
157
- environmentName: 'ai-agents-env',
158
- creditsLimit: 10,
159
- givenName: safeName,
160
- });
188
+ const conn = await storeLaunchAgent(runtimeOptions
189
+ ? {
190
+ ...runtimeOptions,
191
+ runtimesRunUrl: resolvedRuntimeCreationBaseUrl,
192
+ }
193
+ : {
194
+ environmentName: 'ai-agents-env',
195
+ creditsLimit: 10,
196
+ givenName: safeName,
197
+ runtimesRunUrl: resolvedRuntimeCreationBaseUrl,
198
+ });
161
199
  setLifecycleStatus('ready');
162
200
  return conn;
163
201
  }
@@ -172,9 +210,19 @@ export function useAgents(options = {}) {
172
210
  if (!runtimeOptions) {
173
211
  throw new Error('Runtime options are required in connect mode');
174
212
  }
175
- return storeLaunchAgent(runtimeOptions);
213
+ return storeLaunchAgent({
214
+ ...runtimeOptions,
215
+ runtimesRunUrl: resolvedRuntimeCreationBaseUrl,
216
+ });
176
217
  }
177
- }, [agentSpecId, hasSpec, storeLaunchAgent]);
218
+ }, [
219
+ agentConfig?.name,
220
+ agentSpec?.name,
221
+ agentSpecId,
222
+ hasSpec,
223
+ resolvedRuntimeCreationBaseUrl,
224
+ storeLaunchAgent,
225
+ ]);
178
226
  // ─── Create Agent ───────────────────────────────────────────────────
179
227
  const createAgent = useCallback(async (config) => {
180
228
  if (creatingRef.current) {
@@ -397,6 +445,8 @@ export function useAgents(options = {}) {
397
445
  // Status
398
446
  isReady,
399
447
  error,
448
+ runtimeCreationTarget,
449
+ runtimeCreationBaseUrl: resolvedRuntimeCreationBaseUrl,
400
450
  };
401
451
  }
402
452
  // ═══════════════════════════════════════════════════════════════════════════
@@ -408,16 +458,36 @@ export function useAgents(options = {}) {
408
458
  * The backend returns active runtimes from the operator **plus** paused
409
459
  * runtimes synthesised from Solr checkpoint records (with ``status="paused"``).
410
460
  */
411
- export function useAgentRuntimes() {
461
+ export function useAgentRuntimesQuery(scope, queryOptions) {
412
462
  const { configuration } = useCoreStore();
413
463
  const { requestDatalayer } = useDatalayer({ notifyOnError: false });
414
464
  const { user } = useIAMStore();
415
465
  const queryClient = useQueryClient();
416
466
  return useQuery({
417
- queryKey: agentQueryKeys.agentRuntimes.lists(),
467
+ queryKey: [
468
+ ...agentQueryKeys.agentRuntimes.lists(),
469
+ scope?.selectedUserUid || '',
470
+ scope?.selectedOrganizationUid || '',
471
+ scope?.selectedTeamUid || '',
472
+ scope?.selectedAgentUid || '',
473
+ ],
418
474
  queryFn: async () => {
475
+ const params = new URLSearchParams();
476
+ if (scope?.selectedUserUid) {
477
+ params.set('selected_user_uid', scope.selectedUserUid);
478
+ }
479
+ if (scope?.selectedOrganizationUid) {
480
+ params.set('selected_organization_uid', scope.selectedOrganizationUid);
481
+ }
482
+ if (scope?.selectedTeamUid) {
483
+ params.set('selected_team_uid', scope.selectedTeamUid);
484
+ }
485
+ if (scope?.selectedAgentUid) {
486
+ params.set('selected_agent_uid', scope.selectedAgentUid);
487
+ }
488
+ const query = params.toString();
419
489
  const resp = await requestDatalayer({
420
- url: `${configuration.runtimesRunUrl}/api/runtimes/v1/runtimes`,
490
+ url: `${configuration.runtimesRunUrl}/api/runtimes/v1/runtimes${query ? `?${query}` : ''}`,
421
491
  method: 'GET',
422
492
  });
423
493
  if (resp.success && resp.runtimes) {
@@ -432,8 +502,10 @@ export function useAgentRuntimes() {
432
502
  return [];
433
503
  },
434
504
  ...AGENT_QUERY_OPTIONS,
435
- refetchInterval: 10000,
436
- enabled: !!user,
505
+ refetchInterval: queryOptions?.refetchInterval ?? 10000,
506
+ refetchOnMount: true,
507
+ refetchOnWindowFocus: true,
508
+ enabled: (queryOptions?.enabled ?? true) && !!user,
437
509
  });
438
510
  }
439
511
  /**
@@ -473,6 +545,11 @@ export function useCreateAgentRuntime() {
473
545
  const queryClient = useQueryClient();
474
546
  return useMutation({
475
547
  mutationFn: async (data) => {
548
+ const normalizedVolumeUids = Array.isArray(data.volumeUids)
549
+ ? data.volumeUids.map(uid => String(uid || '').trim()).filter(Boolean)
550
+ : data.volumeUid
551
+ ? [String(data.volumeUid).trim()]
552
+ : [];
476
553
  return requestDatalayer({
477
554
  url: `${configuration.runtimesRunUrl}/api/runtimes/v1/runtimes`,
478
555
  method: 'POST',
@@ -485,6 +562,15 @@ export function useCreateAgentRuntime() {
485
562
  enable_codemode: data.enableCodemode ?? false,
486
563
  agent_spec_id: data.agentSpecId || undefined,
487
564
  agent_spec: data.agentSpec || undefined,
565
+ user_account_handle: data.userAccountHandle || undefined,
566
+ billable_account_uid: data.billableAccountUid || undefined,
567
+ billable_account_type: data.billableAccountType || undefined,
568
+ billable_account_handle: data.billableAccountHandle || undefined,
569
+ billable_source_organization_uid: data.billableSourceOrganizationUid || undefined,
570
+ billable_source_organization_handle: data.billableSourceOrganizationHandle || undefined,
571
+ mount_home_folder: data.mountHomeFolder ?? false,
572
+ volume_uids: normalizedVolumeUids.length > 0 ? normalizedVolumeUids : undefined,
573
+ volume_uid: normalizedVolumeUids[0] || data.volumeUid || undefined,
488
574
  },
489
575
  });
490
576
  },
@@ -514,6 +600,12 @@ export function useDeleteAgentRuntime() {
514
600
  });
515
601
  },
516
602
  onSuccess: (_data, podName) => {
603
+ queryClient.setQueriesData({ queryKey: agentQueryKeys.agentRuntimes.lists() }, (current) => {
604
+ if (!Array.isArray(current)) {
605
+ return current;
606
+ }
607
+ return current.filter(runtime => runtime.pod_name !== podName);
608
+ });
517
609
  queryClient.cancelQueries({
518
610
  queryKey: agentQueryKeys.agentRuntimes.detail(podName),
519
611
  });
@@ -523,6 +615,10 @@ export function useDeleteAgentRuntime() {
523
615
  queryClient.invalidateQueries({
524
616
  queryKey: agentQueryKeys.agentRuntimes.lists(),
525
617
  });
618
+ queryClient.refetchQueries({
619
+ queryKey: agentQueryKeys.agentRuntimes.lists(),
620
+ type: 'active',
621
+ });
526
622
  },
527
623
  });
528
624
  }
@@ -606,8 +702,8 @@ export const useAgentLifecycleStore = create()(persist((set, get) => ({
606
702
  /**
607
703
  * Consolidated runtime list and mutations.
608
704
  */
609
- export function useAgentsRuntimes() {
610
- const runtimesQuery = useAgentRuntimes();
705
+ export function useAgentsRuntimes(scope, queryOptions) {
706
+ const runtimesQuery = useAgentRuntimesQuery(scope, queryOptions);
611
707
  const createRuntimeMutation = useCreateAgentRuntime();
612
708
  const deleteRuntimeMutation = useDeleteAgentRuntime();
613
709
  const refreshRuntimes = useRefreshAgentRuntimes();
@@ -631,3 +727,112 @@ export function useAgentsRuntimes() {
631
727
  deleteRuntimeMutation,
632
728
  ]);
633
729
  }
730
+ const DEFAULT_WS_PATH = '/api/v1/tool-approvals/ws';
731
+ const DEFAULT_RECONNECT_DELAY_MS = 3_000;
732
+ /**
733
+ * Connect to the agent-runtime monitoring WebSocket.
734
+ *
735
+ * The hook writes all incoming data into the `useAgentRuntimeStore` Zustand
736
+ * store. Components that need approvals, MCP status, context snapshots, or
737
+ * full-context data simply read from the store.
738
+ *
739
+ * Mount this hook **once** near the top of your component tree (e.g. in
740
+ * the example root or in `ChatBase`). All other components read from the
741
+ * store — no extra WebSocket connections needed.
742
+ */
743
+ export function useAgentRuntimeWebSocket(options) {
744
+ const { enabled = true, baseUrl, authToken, agentId, autoReconnect = true, reconnectDelayMs = DEFAULT_RECONNECT_DELAY_MS, maxReconnectAttempts, } = options;
745
+ const onMessageRef = useRef(options.onMessage);
746
+ onMessageRef.current = options.onMessage;
747
+ useEffect(() => {
748
+ if (!enabled || !baseUrl) {
749
+ agentRuntimeStore.getState().setWsState('closed');
750
+ return;
751
+ }
752
+ let disposed = false;
753
+ let reconnectAttempts = 0;
754
+ let reconnectTimer = null;
755
+ function buildWsUrl() {
756
+ const httpUrl = `${baseUrl}${DEFAULT_WS_PATH}`;
757
+ const url = new URL(httpUrl.replace(/^http/, 'ws'));
758
+ if (authToken) {
759
+ url.searchParams.set('token', authToken);
760
+ }
761
+ if (agentId) {
762
+ url.searchParams.set('agent_id', agentId);
763
+ }
764
+ return url.toString();
765
+ }
766
+ function connect() {
767
+ if (disposed)
768
+ return;
769
+ const wsUrl = buildWsUrl();
770
+ agentRuntimeStore.getState().setWsState('connecting');
771
+ const ws = new WebSocket(wsUrl);
772
+ agentRuntimeStore.getState().setWs(ws, agentId);
773
+ ws.onopen = () => {
774
+ reconnectAttempts = 0;
775
+ agentRuntimeStore.getState().setWsState('connected');
776
+ };
777
+ ws.onmessage = (ev) => {
778
+ let raw;
779
+ try {
780
+ raw = JSON.parse(String(ev.data));
781
+ }
782
+ catch {
783
+ return;
784
+ }
785
+ const parsed = parseAgentStreamMessage(raw);
786
+ onMessageRef.current?.({
787
+ type: parsed?.type,
788
+ payload: parsed?.payload,
789
+ raw,
790
+ });
791
+ if (!parsed)
792
+ return;
793
+ const state = agentRuntimeStore.getState();
794
+ if (parsed.type === 'agent.snapshot') {
795
+ state.applySnapshot(parsed.payload);
796
+ return;
797
+ }
798
+ };
799
+ ws.onclose = () => {
800
+ agentRuntimeStore.getState().setWs(null, agentId);
801
+ agentRuntimeStore.getState().setWsState('closed');
802
+ if (disposed || !autoReconnect)
803
+ return;
804
+ reconnectAttempts += 1;
805
+ if (typeof maxReconnectAttempts === 'number' &&
806
+ reconnectAttempts > maxReconnectAttempts) {
807
+ return;
808
+ }
809
+ const delay = typeof reconnectDelayMs === 'function'
810
+ ? reconnectDelayMs(reconnectAttempts)
811
+ : reconnectDelayMs;
812
+ reconnectTimer = setTimeout(connect, Math.max(0, delay));
813
+ };
814
+ ws.onerror = () => {
815
+ if (ws.readyState === WebSocket.CONNECTING ||
816
+ ws.readyState === WebSocket.OPEN) {
817
+ ws.close();
818
+ }
819
+ };
820
+ }
821
+ connect();
822
+ return () => {
823
+ disposed = true;
824
+ if (reconnectTimer)
825
+ clearTimeout(reconnectTimer);
826
+ agentRuntimeStore.getState().setWs(null, agentId);
827
+ agentRuntimeStore.getState().resetWs();
828
+ };
829
+ }, [
830
+ enabled,
831
+ baseUrl,
832
+ authToken,
833
+ agentId,
834
+ autoReconnect,
835
+ reconnectDelayMs,
836
+ maxReconnectAttempts,
837
+ ]);
838
+ }
@@ -3,7 +3,7 @@
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
5
  /**
6
- * Agent catalog hooks.
6
+ * Agents catalog hooks.
7
7
  *
8
8
  * Includes the Zustand catalog store and the agent registry hook.
9
9
  *
@@ -4,7 +4,7 @@ export type RequestOptions = {
4
4
  };
5
5
  export type RoomType = 'notebook_persist' | 'notebook_memory' | 'doc_memory';
6
6
  /**
7
- * @deprecated Use useAgents instead
7
+ * @deprecated Use useAgentRuntimes instead
8
8
  */
9
9
  export declare const useAgentsService: (baseUrlOverride?: string) => {
10
10
  createAgent: (documentId: string, documentType: RoomType, ingress?: string, token?: string, kernelId?: string, { signal, baseUrl }?: RequestOptions) => Promise<any>;
@@ -17,6 +17,6 @@ export declare const useAgentsService: (baseUrlOverride?: string) => {
17
17
  * Get the notebook AI agent if any.
18
18
  *
19
19
  * This performs a periodic liveness check and keeps the local store in sync.
20
- * @deprecated Use useAgents instead
20
+ * @deprecated Use useAgentRuntimes instead
21
21
  */
22
22
  export declare function useNotebookAgents(notebookId: string): import("..").AgentRegistryEntry | undefined;
@@ -11,12 +11,12 @@
11
11
  import { useEffect } from 'react';
12
12
  import { useCoreStore, useDatalayer } from '@datalayer/core';
13
13
  import { URLExt } from '@jupyterlab/coreutils';
14
- import { useAgentStore } from '../stores/agentsStore';
14
+ import { useAgentRuntimeStore } from '../stores/agentRuntimeStore';
15
15
  // ═══════════════════════════════════════════════════════════════════════════
16
16
  // Agents Service REST API hook.
17
17
  // ═══════════════════════════════════════════════════════════════════════════
18
18
  /**
19
- * @deprecated Use useAgents instead
19
+ * @deprecated Use useAgentRuntimes instead
20
20
  */
21
21
  export const useAgentsService = (baseUrlOverride = 'api/ai-agents/v1') => {
22
22
  const { configuration } = useCoreStore();
@@ -86,14 +86,14 @@ export const useAgentsService = (baseUrlOverride = 'api/ai-agents/v1') => {
86
86
  * Get the notebook AI agent if any.
87
87
  *
88
88
  * This performs a periodic liveness check and keeps the local store in sync.
89
- * @deprecated Use useAgents instead
89
+ * @deprecated Use useAgentRuntimes instead
90
90
  */
91
91
  export function useNotebookAgents(notebookId) {
92
92
  const { getAgent } = useAgentsService();
93
- const agents = useAgentStore(state => state.agents);
94
- const upsertAgent = useAgentStore(state => state.upsertAgent);
95
- const deleteAgent = useAgentStore(state => state.deleteAgent);
96
- const getAgentById = useAgentStore(state => state.getAgentById);
93
+ const agents = useAgentRuntimeStore(state => state.agents);
94
+ const upsertAgent = useAgentRuntimeStore(state => state.upsertAgent);
95
+ const deleteAgent = useAgentRuntimeStore(state => state.deleteAgent);
96
+ const getAgentById = useAgentRuntimeStore(state => state.getAgentById);
97
97
  useEffect(() => {
98
98
  let abortController;
99
99
  const refreshAIAgent = async () => {
@@ -14,7 +14,7 @@ import { useMemo, useState, useCallback } from 'react';
14
14
  import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
15
15
  import { useIAMStore } from '@datalayer/core/lib/state';
16
16
  import { useCoreStore, useDatalayer } from '@datalayer/core';
17
- import { agentQueryKeys, AGENT_QUERY_OPTIONS } from './useAgents';
17
+ import { agentQueryKeys, AGENT_QUERY_OPTIONS } from './useAgentRuntimes';
18
18
  // ═══════════════════════════════════════════════════════════════════════════
19
19
  // Query hooks
20
20
  // ═══════════════════════════════════════════════════════════════════════════
@@ -3,9 +3,12 @@ import type { RemoteConfig } from '../types/config';
3
3
  * Hook to safely use query when QueryClient is available.
4
4
  * Returns a mock result if no QueryClientProvider is present.
5
5
  */
6
- export declare function useConfig(enabled: boolean, configEndpoint?: string, authToken?: string): import("@tanstack/query-core").QueryObserverRefetchErrorResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverSuccessResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverLoadingErrorResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverPendingResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverPlaceholderResult<RemoteConfig, Error> | {
6
+ export declare function useConfig(enabled: boolean, configEndpoint?: string, authToken?: string, agentId?: string): import("@tanstack/query-core").QueryObserverRefetchErrorResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverSuccessResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverLoadingErrorResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverPendingResult<RemoteConfig, Error> | import("@tanstack/query-core").QueryObserverPlaceholderResult<RemoteConfig, Error> | {
7
7
  data: undefined;
8
8
  isLoading: boolean;
9
9
  isError: boolean;
10
10
  error: null;
11
+ refetch: () => Promise<{
12
+ data: undefined;
13
+ }>;
11
14
  };
@@ -9,7 +9,7 @@ import { requestAPI } from '../api/handler';
9
9
  * Hook to safely use query when QueryClient is available.
10
10
  * Returns a mock result if no QueryClientProvider is present.
11
11
  */
12
- export function useConfig(enabled, configEndpoint, authToken) {
12
+ export function useConfig(enabled, configEndpoint, authToken, agentId) {
13
13
  const queryClient = useContext(QueryClientContext);
14
14
  if (!queryClient) {
15
15
  return {
@@ -17,6 +17,7 @@ export function useConfig(enabled, configEndpoint, authToken) {
17
17
  isLoading: false,
18
18
  isError: false,
19
19
  error: null,
20
+ refetch: () => Promise.resolve({ data: undefined }),
20
21
  };
21
22
  }
22
23
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -30,7 +31,13 @@ export function useConfig(enabled, configEndpoint, authToken) {
30
31
  if (authToken) {
31
32
  headers['Authorization'] = `Bearer ${authToken}`;
32
33
  }
33
- const response = await fetch(configEndpoint, { headers });
34
+ let endpoint = configEndpoint;
35
+ if (agentId) {
36
+ const url = new URL(configEndpoint, window.location.origin);
37
+ url.searchParams.set('agent_id', agentId);
38
+ endpoint = url.toString();
39
+ }
40
+ const response = await fetch(endpoint, { headers });
34
41
  if (!response.ok) {
35
42
  throw new Error(`Config fetch failed: ${response.statusText}`);
36
43
  }
@@ -39,7 +46,7 @@ export function useConfig(enabled, configEndpoint, authToken) {
39
46
  // Otherwise use Jupyter requestAPI.
40
47
  return requestAPI('configure');
41
48
  },
42
- queryKey: ['models', configEndpoint || 'jupyter'],
49
+ queryKey: ['models', configEndpoint || 'jupyter', agentId || 'global'],
43
50
  enabled,
44
51
  retry: 1,
45
52
  });