@datalayer/agent-runtimes 0.0.5 → 0.0.8

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 (119) hide show
  1. package/README.md +150 -22
  2. package/lib/components/chat/components/AgentDetails.d.ts +15 -2
  3. package/lib/components/chat/components/AgentDetails.js +9 -93
  4. package/lib/components/chat/components/AgentIdentity.d.ts +92 -0
  5. package/lib/components/chat/components/AgentIdentity.js +318 -0
  6. package/lib/components/chat/components/Chat.d.ts +24 -1
  7. package/lib/components/chat/components/Chat.js +41 -19
  8. package/lib/components/chat/components/ChatFloating.d.ts +6 -1
  9. package/lib/components/chat/components/ChatFloating.js +12 -6
  10. package/lib/components/chat/components/ContextDistribution.d.ts +47 -0
  11. package/lib/components/chat/components/ContextDistribution.js +146 -0
  12. package/lib/components/chat/components/ContextUsage.d.ts +33 -0
  13. package/lib/components/chat/components/ContextUsage.js +127 -0
  14. package/lib/components/chat/components/base/ChatBase.d.ts +51 -1
  15. package/lib/components/chat/components/base/ChatBase.js +278 -74
  16. package/lib/components/chat/components/display/ToolCallDisplay.d.ts +16 -2
  17. package/lib/components/chat/components/display/ToolCallDisplay.js +148 -6
  18. package/lib/components/chat/components/display/index.d.ts +1 -1
  19. package/lib/components/chat/components/display/index.js +1 -1
  20. package/lib/components/chat/components/elements/ChatInputPrompt.d.ts +12 -1
  21. package/lib/components/chat/components/elements/ChatInputPrompt.js +8 -3
  22. package/lib/components/chat/components/index.d.ts +3 -0
  23. package/lib/components/chat/components/index.js +3 -0
  24. package/lib/components/chat/components/parts/ToolPart.d.ts +1 -1
  25. package/lib/components/chat/components/parts/ToolPart.js +142 -6
  26. package/lib/components/chat/index.d.ts +1 -1
  27. package/lib/components/chat/index.js +1 -1
  28. package/lib/components/chat/protocols/A2AAdapter.d.ts +9 -0
  29. package/lib/components/chat/protocols/A2AAdapter.js +13 -2
  30. package/lib/components/chat/protocols/ACPAdapter.d.ts +9 -0
  31. package/lib/components/chat/protocols/ACPAdapter.js +13 -2
  32. package/lib/components/chat/protocols/AGUIAdapter.d.ts +9 -0
  33. package/lib/components/chat/protocols/AGUIAdapter.js +19 -1
  34. package/lib/components/chat/protocols/VercelAIAdapter.d.ts +7 -0
  35. package/lib/components/chat/protocols/VercelAIAdapter.js +19 -0
  36. package/lib/components/chat/types/execution.d.ts +78 -0
  37. package/lib/components/chat/types/execution.js +64 -0
  38. package/lib/components/chat/types/index.d.ts +1 -0
  39. package/lib/components/chat/types/index.js +1 -0
  40. package/lib/components/chat/types/protocol.d.ts +9 -0
  41. package/lib/components/ui/pagination.d.ts +2 -2
  42. package/lib/components/ui/pagination.js +4 -4
  43. package/lib/components/ui/resizable.d.ts +4 -4
  44. package/lib/components/ui/resizable.js +4 -4
  45. package/lib/examples/A2UiRestaurantExample.js +2 -2
  46. package/lib/examples/AgUiAgenticExample.js +2 -2
  47. package/lib/examples/AgUiBackendToolRenderingExample.js +2 -2
  48. package/lib/examples/AgUiHaikuGenUIExample.js +2 -2
  49. package/lib/examples/AgUiHumanInTheLoopExample.js +2 -2
  50. package/lib/examples/AgUiSharedStateExample.js +2 -2
  51. package/lib/examples/AgUiToolsBasedGenUIExample.js +2 -2
  52. package/lib/examples/AgentRuntimeCustomExample.js +2 -2
  53. package/lib/examples/AgentRuntimeLexical2Example.js +2 -1
  54. package/lib/examples/AgentRuntimeLexicalExample.js +5 -2
  55. package/lib/examples/AgentRuntimeLexicalSidebarExample.js +4 -2
  56. package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
  57. package/lib/examples/AgentRuntimeStandaloneExample.js +2 -2
  58. package/lib/examples/AgentSpaceFormExample.d.ts +70 -2
  59. package/lib/examples/AgentSpaceFormExample.js +204 -35
  60. package/lib/examples/CopilotKitLexicalExample.js +2 -1
  61. package/lib/examples/components/AgentConfiguration.d.ts +37 -0
  62. package/lib/examples/components/AgentConfiguration.js +239 -8
  63. package/lib/examples/components/Header.d.ts +0 -2
  64. package/lib/examples/components/Header.js +2 -16
  65. package/lib/examples/components/LexicalEditor.js +2 -1
  66. package/lib/examples/components/MockFileBrowser.js +6 -2
  67. package/lib/examples/components/index.d.ts +0 -1
  68. package/lib/examples/components/index.js +0 -1
  69. package/lib/examples/example-selector.js +0 -1
  70. package/lib/examples/index.d.ts +0 -1
  71. package/lib/examples/index.js +0 -1
  72. package/lib/examples/lexical/editorConfig.d.ts +3 -2
  73. package/lib/examples/lexical/editorConfig.js +7 -1
  74. package/lib/examples/lexical/initial-content.json +2210 -0
  75. package/lib/examples/main.js +15 -1
  76. package/lib/identity/IdentityConnect.d.ts +90 -0
  77. package/lib/identity/IdentityConnect.js +316 -0
  78. package/lib/identity/OAuthCallback.d.ts +58 -0
  79. package/lib/identity/OAuthCallback.js +223 -0
  80. package/lib/identity/dcr.d.ts +257 -0
  81. package/lib/identity/dcr.js +282 -0
  82. package/lib/identity/identityStore.d.ts +72 -0
  83. package/lib/identity/identityStore.js +529 -0
  84. package/lib/identity/index.d.ts +46 -0
  85. package/lib/identity/index.js +17 -0
  86. package/lib/identity/pkce.d.ts +30 -0
  87. package/lib/identity/pkce.js +65 -0
  88. package/lib/identity/types.d.ts +293 -0
  89. package/lib/identity/types.js +73 -0
  90. package/lib/identity/useIdentity.d.ts +108 -0
  91. package/lib/identity/useIdentity.js +323 -0
  92. package/lib/index.d.ts +2 -0
  93. package/lib/index.js +2 -0
  94. package/lib/lib/utils.js +1 -1
  95. package/lib/renderers/a2ui/lib/utils.js +1 -1
  96. package/lib/runtime/index.d.ts +35 -0
  97. package/lib/runtime/index.js +40 -0
  98. package/lib/runtime/runtimeStore.d.ts +77 -0
  99. package/lib/runtime/runtimeStore.js +184 -0
  100. package/lib/runtime/types.d.ts +84 -0
  101. package/lib/runtime/types.js +15 -0
  102. package/lib/runtime/useAgentConnection.d.ts +46 -0
  103. package/lib/runtime/useAgentConnection.js +112 -0
  104. package/lib/runtime/useAgentRuntime.d.ts +94 -0
  105. package/lib/runtime/useAgentRuntime.js +125 -0
  106. package/lib/test-setup.d.ts +1 -1
  107. package/lib/test-setup.js +1 -0
  108. package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.js +32 -1
  109. package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +6 -0
  110. package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +16 -17
  111. package/package.json +20 -7
  112. package/patches/@datalayer+jupyter-lexical+1.0.8.patch +11628 -0
  113. package/patches/@datalayer+jupyter-react+2.0.2.patch +5338 -0
  114. package/lib/examples/AgentSpaceHomeExample.d.ts +0 -8
  115. package/lib/examples/AgentSpaceHomeExample.js +0 -171
  116. package/lib/examples/components/AgentsDataTable.d.ts +0 -13
  117. package/lib/examples/components/AgentsDataTable.js +0 -74
  118. package/lib/examples/components/Rating.d.ts +0 -14
  119. package/lib/examples/components/Rating.js +0 -12
@@ -0,0 +1,323 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * React hook for identity management.
7
+ *
8
+ * Provides a simple interface for OAuth 2.1 identity management.
9
+ *
10
+ * @module identity/useIdentity
11
+ */
12
+ import { useCallback, useEffect, useMemo } from 'react';
13
+ import { useIdentityStore, useConnectedIdentities, useConnectedProviders, usePendingAuthorization, useIdentityLoading, useIdentityError, configureBuiltinProviders, } from './identityStore';
14
+ /**
15
+ * Hook for managing OAuth identities
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const {
20
+ * identities,
21
+ * connect,
22
+ * disconnect,
23
+ * isConnected,
24
+ * } = useIdentity({
25
+ * providers: {
26
+ * github: { clientId: 'your-client-id' },
27
+ * },
28
+ * });
29
+ *
30
+ * // Connect to GitHub
31
+ * await connect('github', ['repo', 'read:user']);
32
+ *
33
+ * // Check connection
34
+ * if (isConnected('github')) {
35
+ * const token = await getAccessToken('github');
36
+ * }
37
+ * ```
38
+ */
39
+ export function useIdentity(options = {}) {
40
+ const { providers, baseUrl = typeof window !== 'undefined' ? window.location.origin : '', callbackPath = typeof window !== 'undefined'
41
+ ? window.location.pathname
42
+ : '/oauth/callback', autoHandleCallback = true, } = options;
43
+ // Store state
44
+ const identities = useConnectedIdentities();
45
+ const connectedProviders = useConnectedProviders();
46
+ const pendingAuthorization = usePendingAuthorization();
47
+ const isLoading = useIdentityLoading();
48
+ const error = useIdentityError();
49
+ // Store actions
50
+ const startAuthorization = useIdentityStore(s => s.startAuthorization);
51
+ const completeAuthorizationAction = useIdentityStore(s => s.completeAuthorization);
52
+ const cancelAuthorizationAction = useIdentityStore(s => s.cancelAuthorization);
53
+ const disconnectAction = useIdentityStore(s => s.disconnect);
54
+ const getIdentityAction = useIdentityStore(s => s.getIdentity);
55
+ const isConnectedAction = useIdentityStore(s => s.isConnected);
56
+ const getTokenAction = useIdentityStore(s => s.getToken);
57
+ const configureProviderAction = useIdentityStore(s => s.configureProvider);
58
+ // Configure providers on mount
59
+ useEffect(() => {
60
+ if (!providers)
61
+ return;
62
+ const redirectUri = `${baseUrl}${callbackPath}`;
63
+ if (providers.github) {
64
+ configureBuiltinProviders({
65
+ github: {
66
+ clientId: providers.github.clientId,
67
+ redirectUri: providers.github.redirectUri || redirectUri,
68
+ },
69
+ });
70
+ }
71
+ if (providers.google) {
72
+ configureBuiltinProviders({
73
+ google: {
74
+ clientId: providers.google.clientId,
75
+ redirectUri: providers.google.redirectUri || redirectUri,
76
+ },
77
+ });
78
+ }
79
+ if (providers.kaggle) {
80
+ configureBuiltinProviders({
81
+ kaggle: {
82
+ clientId: providers.kaggle.clientId,
83
+ redirectUri: providers.kaggle.redirectUri || redirectUri,
84
+ },
85
+ });
86
+ }
87
+ // Configure custom providers
88
+ if (providers.custom) {
89
+ providers.custom.forEach(config => {
90
+ configureProviderAction(config);
91
+ });
92
+ }
93
+ }, [providers, baseUrl, callbackPath, configureProviderAction]);
94
+ // Auto-handle OAuth callback from URL
95
+ useEffect(() => {
96
+ if (!autoHandleCallback || typeof window === 'undefined')
97
+ return;
98
+ const params = new URLSearchParams(window.location.search);
99
+ const code = params.get('code');
100
+ const state = params.get('state');
101
+ const error = params.get('error');
102
+ const errorDescription = params.get('error_description');
103
+ if ((code && state) || error) {
104
+ completeAuthorizationAction({
105
+ code: code || '',
106
+ state: state || '',
107
+ error: error || undefined,
108
+ errorDescription: errorDescription || undefined,
109
+ })
110
+ .then(() => {
111
+ // Clean up URL
112
+ const cleanUrl = window.location.pathname;
113
+ window.history.replaceState({}, '', cleanUrl);
114
+ })
115
+ .catch(err => {
116
+ console.error('OAuth callback error:', err);
117
+ // Clean up URL even on error
118
+ const cleanUrl = window.location.pathname;
119
+ window.history.replaceState({}, '', cleanUrl);
120
+ });
121
+ }
122
+ }, [autoHandleCallback, completeAuthorizationAction]);
123
+ // Connect via redirect
124
+ const connect = useCallback(async (provider, scopes) => {
125
+ const authUrl = await startAuthorization(provider, scopes);
126
+ // Redirect to authorization URL
127
+ window.location.href = authUrl;
128
+ }, [startAuthorization]);
129
+ // Connect via popup
130
+ const connectWithPopup = useCallback(async (provider, scopes) => {
131
+ // Start authorization first (async), then create promise for popup flow
132
+ const authUrl = await startAuthorization(provider, scopes, {
133
+ onComplete: () => { },
134
+ onError: () => { },
135
+ });
136
+ return new Promise((resolve, reject) => {
137
+ // Update callbacks for the pending authorization
138
+ const store = useIdentityStore.getState();
139
+ if (store.pendingAuthorization) {
140
+ store.pendingAuthorization.onComplete = resolve;
141
+ store.pendingAuthorization.onError = reject;
142
+ }
143
+ // Open popup
144
+ const width = 600;
145
+ const height = 700;
146
+ const left = window.screenX + (window.outerWidth - width) / 2;
147
+ const top = window.screenY + (window.outerHeight - height) / 2;
148
+ const popup = window.open(authUrl, 'oauth_popup', `width=${width},height=${height},left=${left},top=${top},toolbar=no,menubar=no`);
149
+ if (!popup) {
150
+ reject(new Error('Failed to open popup window'));
151
+ return;
152
+ }
153
+ // Listen for callback via postMessage from OAuthCallback component
154
+ const handleMessage = (event) => {
155
+ if (event.origin !== window.location.origin)
156
+ return;
157
+ // Handle success message from OAuthCallback
158
+ if (event.data?.type === 'oauth-callback-success') {
159
+ window.removeEventListener('message', handleMessage);
160
+ clearInterval(pollTimer);
161
+ popup.close();
162
+ const providerName = event.data.provider;
163
+ const identityFromPopup = event.data.identity;
164
+ console.debug('[Identity] Received oauth-callback-success for provider:', providerName);
165
+ console.debug('[Identity] Identity from popup:', identityFromPopup);
166
+ if (identityFromPopup) {
167
+ // Use the identity directly from the popup message
168
+ // Create a new Map to ensure React detects the change
169
+ const currentIdentities = useIdentityStore.getState().identities;
170
+ const newIdentities = new Map(currentIdentities);
171
+ newIdentities.set(providerName, identityFromPopup);
172
+ // Update the store
173
+ useIdentityStore.setState({
174
+ identities: newIdentities,
175
+ pendingAuthorization: null,
176
+ });
177
+ console.debug('[Identity] Store updated with identity from popup, identities count:', newIdentities.size);
178
+ resolve(identityFromPopup);
179
+ return;
180
+ }
181
+ // Fallback: read from localStorage if identity not in message
182
+ setTimeout(() => {
183
+ const STORAGE_KEY = 'agent-runtimes-identity';
184
+ const stored = localStorage.getItem(STORAGE_KEY);
185
+ console.debug('[Identity] Fallback: reading from localStorage');
186
+ if (stored) {
187
+ try {
188
+ const data = JSON.parse(stored);
189
+ const identitiesArray = data.state?.identities || [];
190
+ const identitiesMap = new Map(identitiesArray);
191
+ const identity = identitiesMap.get(providerName);
192
+ if (identity) {
193
+ const currentIdentities = useIdentityStore.getState().identities;
194
+ const newIdentities = new Map(currentIdentities);
195
+ newIdentities.set(providerName, identity);
196
+ useIdentityStore.setState({
197
+ identities: newIdentities,
198
+ pendingAuthorization: null,
199
+ });
200
+ resolve(identity);
201
+ return;
202
+ }
203
+ }
204
+ catch (e) {
205
+ console.error('[Identity] Failed to parse identity from localStorage:', e);
206
+ }
207
+ }
208
+ // Final fallback
209
+ useIdentityStore.setState({ pendingAuthorization: null });
210
+ reject(new Error('Identity not found after OAuth success'));
211
+ }, 100);
212
+ }
213
+ // Handle error message from OAuthCallback
214
+ else if (event.data?.type === 'oauth-callback-error') {
215
+ window.removeEventListener('message', handleMessage);
216
+ clearInterval(pollTimer);
217
+ popup.close();
218
+ useIdentityStore.setState({ pendingAuthorization: null });
219
+ reject(new Error(event.data.error || 'OAuth authentication failed'));
220
+ }
221
+ // Legacy: handle 'oauth_callback' message type
222
+ else if (event.data?.type === 'oauth_callback') {
223
+ window.removeEventListener('message', handleMessage);
224
+ clearInterval(pollTimer);
225
+ popup.close();
226
+ completeAuthorizationAction(event.data.payload)
227
+ .then(resolve)
228
+ .catch(reject);
229
+ }
230
+ };
231
+ window.addEventListener('message', handleMessage);
232
+ // Also poll for popup close (user cancelled)
233
+ const pollTimer = setInterval(() => {
234
+ if (popup.closed) {
235
+ clearInterval(pollTimer);
236
+ window.removeEventListener('message', handleMessage);
237
+ // Don't reject if we already got a message
238
+ if (useIdentityStore.getState().pendingAuthorization) {
239
+ cancelAuthorizationAction();
240
+ reject(new Error('Popup closed by user'));
241
+ }
242
+ }
243
+ }, 500);
244
+ });
245
+ }, [
246
+ startAuthorization,
247
+ completeAuthorizationAction,
248
+ cancelAuthorizationAction,
249
+ ]);
250
+ // Connect with token (for token-based providers like Kaggle)
251
+ const connectWithTokenAction = useIdentityStore(s => s.connectWithToken);
252
+ const connectWithToken = useCallback(async (provider, token, options) => {
253
+ return connectWithTokenAction(provider, token, options);
254
+ }, [connectWithTokenAction]);
255
+ // Disconnect
256
+ const disconnect = useCallback(async (provider) => {
257
+ await disconnectAction(provider);
258
+ }, [disconnectAction]);
259
+ // Complete authorization
260
+ const completeAuthorization = useCallback(async (callback) => {
261
+ return completeAuthorizationAction(callback);
262
+ }, [completeAuthorizationAction]);
263
+ // Cancel authorization
264
+ const cancelAuthorization = useCallback(() => {
265
+ cancelAuthorizationAction();
266
+ }, [cancelAuthorizationAction]);
267
+ // Check if connected
268
+ const isConnected = useCallback((provider) => {
269
+ return isConnectedAction(provider);
270
+ }, [isConnectedAction]);
271
+ // Get identity
272
+ const getIdentity = useCallback((provider) => {
273
+ return getIdentityAction(provider);
274
+ }, [getIdentityAction]);
275
+ // Get access token
276
+ const getAccessToken = useCallback(async (provider) => {
277
+ const token = await getTokenAction(provider);
278
+ return token?.accessToken ?? null;
279
+ }, [getTokenAction]);
280
+ // Configure provider
281
+ const configureProvider = useCallback((config) => {
282
+ configureProviderAction(config);
283
+ }, [configureProviderAction]);
284
+ // Derived state
285
+ const isAuthorizing = pendingAuthorization !== null;
286
+ return useMemo(() => ({
287
+ // State
288
+ identities,
289
+ connectedProviders,
290
+ isAuthorizing,
291
+ isLoading,
292
+ error,
293
+ pendingAuthorization,
294
+ // Actions
295
+ connect,
296
+ connectWithPopup,
297
+ connectWithToken,
298
+ disconnect,
299
+ completeAuthorization,
300
+ cancelAuthorization,
301
+ isConnected,
302
+ getIdentity,
303
+ getAccessToken,
304
+ configureProvider,
305
+ }), [
306
+ identities,
307
+ connectedProviders,
308
+ isAuthorizing,
309
+ isLoading,
310
+ error,
311
+ pendingAuthorization,
312
+ connect,
313
+ connectWithPopup,
314
+ connectWithToken,
315
+ disconnect,
316
+ completeAuthorization,
317
+ cancelAuthorization,
318
+ isConnected,
319
+ getIdentity,
320
+ getAccessToken,
321
+ configureProvider,
322
+ ]);
323
+ }
package/lib/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './components';
2
2
  export * from './state';
3
+ export * from './runtime';
4
+ export * from './identity';
package/lib/index.js CHANGED
@@ -4,3 +4,5 @@
4
4
  */
5
5
  export * from './components';
6
6
  export * from './state';
7
+ export * from './runtime';
8
+ export * from './identity';
package/lib/lib/utils.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2025-2026 Datalayer, Inc.
3
3
  * Distributed under the terms of the Modified BSD License.
4
4
  */
5
- import { clsx } from "clsx";
5
+ import clsx from "clsx";
6
6
  import { twMerge } from "tailwind-merge";
7
7
  export function cn(...inputs) {
8
8
  return twMerge(clsx(inputs));
@@ -17,7 +17,7 @@
17
17
  See the License for the specific language governing permissions and
18
18
  limitations under the License.
19
19
  */
20
- import { clsx } from "clsx";
20
+ import clsx from "clsx";
21
21
  import { twMerge } from "tailwind-merge";
22
22
  /**
23
23
  * Utility function to merge Tailwind CSS classes.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Runtime management module for agent-runtimes.
3
+ *
4
+ * Provides a Zustand store and hooks for launching and managing cloud runtimes
5
+ * with integrated AI agent support.
6
+ *
7
+ * @module runtime
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { useRuntimeStore, useRuntime, useAgent } from '@datalayer/agent-runtimes/lib/runtime';
12
+ *
13
+ * // Launch a new runtime
14
+ * const { launchRuntime, createAgent } = useRuntimeStore();
15
+ * const runtime = await launchRuntime({ environmentName: 'python-simple', creditsLimit: 100 });
16
+ * const agent = await createAgent({ model: 'anthropic:claude-sonnet-4-5' });
17
+ *
18
+ * // Use in ChatFloating
19
+ * <ChatFloating endpoint={agent.endpoint} />
20
+ *
21
+ * // Or connect to an existing runtime
22
+ * const { connectToRuntime } = useRuntimeStore();
23
+ * connectToRuntime({
24
+ * podName: 'my-pod',
25
+ * environmentName: 'python-simple',
26
+ * serviceManager: myServiceManager,
27
+ * });
28
+ * ```
29
+ */
30
+ export { useRuntimeStore, useRuntime, useAgent, useRuntimeStatus, useRuntimeError, useIsLaunching, getRuntimeState, subscribeToRuntime, } from './runtimeStore';
31
+ export { useAgentConnection } from './useAgentConnection';
32
+ export { useAgentRuntime } from './useAgentRuntime';
33
+ export type { IRuntimeLocation, IRuntimeType, IRuntimeCapabilities, IRuntimePod, IRuntimeOptions, IRuntimeDesc, } from './types';
34
+ export type { RuntimeConnection, AgentRuntimeStatus as RuntimeStatus, AgentConfig, AgentConnection, AgentRuntimeState, } from './types';
35
+ export { DEFAULT_AGENT_CONFIG } from './types';
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Runtime management module for agent-runtimes.
7
+ *
8
+ * Provides a Zustand store and hooks for launching and managing cloud runtimes
9
+ * with integrated AI agent support.
10
+ *
11
+ * @module runtime
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { useRuntimeStore, useRuntime, useAgent } from '@datalayer/agent-runtimes/lib/runtime';
16
+ *
17
+ * // Launch a new runtime
18
+ * const { launchRuntime, createAgent } = useRuntimeStore();
19
+ * const runtime = await launchRuntime({ environmentName: 'python-simple', creditsLimit: 100 });
20
+ * const agent = await createAgent({ model: 'anthropic:claude-sonnet-4-5' });
21
+ *
22
+ * // Use in ChatFloating
23
+ * <ChatFloating endpoint={agent.endpoint} />
24
+ *
25
+ * // Or connect to an existing runtime
26
+ * const { connectToRuntime } = useRuntimeStore();
27
+ * connectToRuntime({
28
+ * podName: 'my-pod',
29
+ * environmentName: 'python-simple',
30
+ * serviceManager: myServiceManager,
31
+ * });
32
+ * ```
33
+ */
34
+ // Zustand store
35
+ export { useRuntimeStore, useRuntime, useAgent, useRuntimeStatus, useRuntimeError, useIsLaunching, getRuntimeState, subscribeToRuntime, } from './runtimeStore';
36
+ // Hooks
37
+ export { useAgentConnection } from './useAgentConnection';
38
+ export { useAgentRuntime } from './useAgentRuntime';
39
+ // Constants
40
+ export { DEFAULT_AGENT_CONFIG } from './types';
@@ -0,0 +1,77 @@
1
+ import type { ServiceManager } from '@jupyterlab/services';
2
+ import type { IRuntimeOptions, RuntimeConnection, AgentRuntimeStatus, AgentConfig, AgentConnection } from './types';
3
+ /**
4
+ * Runtime store state interface.
5
+ */
6
+ interface RuntimeStoreState {
7
+ /** Current runtime connection */
8
+ runtime: RuntimeConnection | null;
9
+ /** Current agent connection */
10
+ agent: AgentConnection | null;
11
+ /** Current status */
12
+ status: AgentRuntimeStatus;
13
+ /** Error message if any */
14
+ error: string | null;
15
+ /** Whether a launch is in progress */
16
+ isLaunching: boolean;
17
+ }
18
+ /**
19
+ * Runtime store actions interface.
20
+ */
21
+ interface RuntimeStoreActions {
22
+ /** Launch a new runtime */
23
+ launchRuntime: (options: IRuntimeOptions) => Promise<RuntimeConnection>;
24
+ /** Connect to an existing runtime */
25
+ connectToRuntime: (connection: {
26
+ podName: string;
27
+ environmentName: string;
28
+ serviceManager: ServiceManager.IManager;
29
+ kernelId?: string;
30
+ }) => void;
31
+ /** Create an agent on the current runtime */
32
+ createAgent: (config?: AgentConfig) => Promise<AgentConnection>;
33
+ /** Disconnect from the current runtime */
34
+ disconnect: () => void;
35
+ /** Clear any errors */
36
+ clearError: () => void;
37
+ /** Set error */
38
+ setError: (error: string) => void;
39
+ /** Reset store to initial state */
40
+ reset: () => void;
41
+ }
42
+ type RuntimeStore = RuntimeStoreState & RuntimeStoreActions;
43
+ /**
44
+ * Zustand store for runtime management.
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * import { useRuntimeStore } from '@datalayer/agent-runtimes/lib/runtime';
49
+ *
50
+ * // In a component
51
+ * const { runtime, launchRuntime, status } = useRuntimeStore();
52
+ *
53
+ * // Launch a runtime
54
+ * await launchRuntime({ environmentName: 'python-simple', creditsLimit: 100 });
55
+ *
56
+ * // Access runtime info
57
+ * console.log(runtime?.agentBaseUrl);
58
+ * ```
59
+ */
60
+ export declare const useRuntimeStore: import("zustand").UseBoundStore<import("zustand").StoreApi<RuntimeStore>>;
61
+ /**
62
+ * Selector hooks for common use cases.
63
+ */
64
+ export declare const useRuntime: () => RuntimeConnection | null;
65
+ export declare const useAgent: () => AgentConnection | null;
66
+ export declare const useRuntimeStatus: () => AgentRuntimeStatus;
67
+ export declare const useRuntimeError: () => string | null;
68
+ export declare const useIsLaunching: () => boolean;
69
+ /**
70
+ * Get runtime store state without React (for use outside components).
71
+ */
72
+ export declare const getRuntimeState: () => RuntimeStore;
73
+ /**
74
+ * Subscribe to runtime store changes (for use outside React).
75
+ */
76
+ export declare const subscribeToRuntime: (listener: (state: RuntimeStore, prevState: RuntimeStore) => void) => () => void;
77
+ export {};