@datalayer/agent-runtimes 0.0.7 → 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 (103) hide show
  1. package/README.md +9 -0
  2. package/lib/components/chat/components/AgentDetails.d.ts +14 -1
  3. package/lib/components/chat/components/AgentDetails.js +3 -2
  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 +20 -1
  7. package/lib/components/chat/components/Chat.js +16 -3
  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/base/ChatBase.d.ts +47 -1
  11. package/lib/components/chat/components/base/ChatBase.js +242 -63
  12. package/lib/components/chat/components/display/ToolCallDisplay.d.ts +16 -2
  13. package/lib/components/chat/components/display/ToolCallDisplay.js +148 -6
  14. package/lib/components/chat/components/display/index.d.ts +1 -1
  15. package/lib/components/chat/components/display/index.js +1 -1
  16. package/lib/components/chat/components/elements/ChatInputPrompt.d.ts +12 -1
  17. package/lib/components/chat/components/elements/ChatInputPrompt.js +8 -3
  18. package/lib/components/chat/components/index.d.ts +1 -0
  19. package/lib/components/chat/components/index.js +1 -0
  20. package/lib/components/chat/components/parts/ToolPart.d.ts +1 -1
  21. package/lib/components/chat/components/parts/ToolPart.js +142 -6
  22. package/lib/components/chat/index.d.ts +1 -1
  23. package/lib/components/chat/index.js +1 -1
  24. package/lib/components/chat/protocols/A2AAdapter.d.ts +9 -0
  25. package/lib/components/chat/protocols/A2AAdapter.js +13 -2
  26. package/lib/components/chat/protocols/ACPAdapter.d.ts +9 -0
  27. package/lib/components/chat/protocols/ACPAdapter.js +13 -2
  28. package/lib/components/chat/protocols/AGUIAdapter.d.ts +9 -0
  29. package/lib/components/chat/protocols/AGUIAdapter.js +19 -1
  30. package/lib/components/chat/protocols/VercelAIAdapter.d.ts +7 -0
  31. package/lib/components/chat/protocols/VercelAIAdapter.js +19 -0
  32. package/lib/components/chat/types/execution.d.ts +78 -0
  33. package/lib/components/chat/types/execution.js +64 -0
  34. package/lib/components/chat/types/index.d.ts +1 -0
  35. package/lib/components/chat/types/index.js +1 -0
  36. package/lib/components/chat/types/protocol.d.ts +9 -0
  37. package/lib/components/ui/pagination.d.ts +2 -2
  38. package/lib/components/ui/pagination.js +4 -4
  39. package/lib/components/ui/resizable.d.ts +4 -4
  40. package/lib/components/ui/resizable.js +4 -4
  41. package/lib/examples/A2UiRestaurantExample.js +2 -2
  42. package/lib/examples/AgUiAgenticExample.js +2 -2
  43. package/lib/examples/AgUiBackendToolRenderingExample.js +2 -2
  44. package/lib/examples/AgUiHaikuGenUIExample.js +2 -2
  45. package/lib/examples/AgUiHumanInTheLoopExample.js +2 -2
  46. package/lib/examples/AgUiSharedStateExample.js +2 -2
  47. package/lib/examples/AgUiToolsBasedGenUIExample.js +2 -2
  48. package/lib/examples/AgentRuntimeCustomExample.js +2 -2
  49. package/lib/examples/AgentRuntimeLexical2Example.js +2 -1
  50. package/lib/examples/AgentRuntimeLexicalExample.js +5 -2
  51. package/lib/examples/AgentRuntimeLexicalSidebarExample.js +4 -2
  52. package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
  53. package/lib/examples/AgentRuntimeStandaloneExample.js +2 -2
  54. package/lib/examples/AgentSpaceFormExample.d.ts +70 -2
  55. package/lib/examples/AgentSpaceFormExample.js +177 -43
  56. package/lib/examples/CopilotKitLexicalExample.js +2 -1
  57. package/lib/examples/components/AgentConfiguration.d.ts +17 -2
  58. package/lib/examples/components/AgentConfiguration.js +220 -16
  59. package/lib/examples/components/LexicalEditor.js +2 -1
  60. package/lib/examples/components/MockFileBrowser.js +6 -2
  61. package/lib/examples/components/index.d.ts +0 -1
  62. package/lib/examples/components/index.js +0 -1
  63. package/lib/examples/example-selector.js +0 -1
  64. package/lib/examples/index.d.ts +0 -1
  65. package/lib/examples/index.js +0 -1
  66. package/lib/examples/lexical/editorConfig.d.ts +3 -2
  67. package/lib/examples/lexical/editorConfig.js +7 -1
  68. package/lib/examples/lexical/initial-content.json +2210 -0
  69. package/lib/examples/main.js +15 -1
  70. package/lib/identity/IdentityConnect.d.ts +90 -0
  71. package/lib/identity/IdentityConnect.js +316 -0
  72. package/lib/identity/OAuthCallback.d.ts +58 -0
  73. package/lib/identity/OAuthCallback.js +223 -0
  74. package/lib/identity/dcr.d.ts +257 -0
  75. package/lib/identity/dcr.js +282 -0
  76. package/lib/identity/identityStore.d.ts +72 -0
  77. package/lib/identity/identityStore.js +529 -0
  78. package/lib/identity/index.d.ts +46 -0
  79. package/lib/identity/index.js +17 -0
  80. package/lib/identity/pkce.d.ts +30 -0
  81. package/lib/identity/pkce.js +65 -0
  82. package/lib/identity/types.d.ts +293 -0
  83. package/lib/identity/types.js +73 -0
  84. package/lib/identity/useIdentity.d.ts +108 -0
  85. package/lib/identity/useIdentity.js +323 -0
  86. package/lib/index.d.ts +1 -0
  87. package/lib/index.js +1 -0
  88. package/lib/lib/utils.js +1 -1
  89. package/lib/renderers/a2ui/lib/utils.js +1 -1
  90. package/lib/test-setup.d.ts +1 -1
  91. package/lib/test-setup.js +1 -0
  92. package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.js +32 -1
  93. package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +6 -0
  94. package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +16 -17
  95. package/package.json +20 -7
  96. package/patches/@datalayer+jupyter-lexical+1.0.8.patch +11628 -0
  97. package/patches/@datalayer+jupyter-react+2.0.2.patch +5338 -0
  98. package/lib/examples/AgentSpaceHomeExample.d.ts +0 -8
  99. package/lib/examples/AgentSpaceHomeExample.js +0 -171
  100. package/lib/examples/components/AgentsDataTable.d.ts +0 -13
  101. package/lib/examples/components/AgentsDataTable.js +0 -74
  102. package/lib/examples/components/Rating.d.ts +0 -14
  103. package/lib/examples/components/Rating.js +0 -12
@@ -0,0 +1,282 @@
1
+ /*
2
+ * Copyright (c) 2025-2026 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
5
+ /**
6
+ * Well-known paths for OAuth discovery
7
+ */
8
+ const WELL_KNOWN_PATHS = [
9
+ '/.well-known/oauth-authorization-server',
10
+ '/.well-known/openid-configuration',
11
+ ];
12
+ /**
13
+ * Storage key for DCR clients
14
+ */
15
+ const DCR_STORAGE_KEY = 'agent-runtimes:dcr-clients';
16
+ /**
17
+ * Discover OAuth authorization server metadata
18
+ *
19
+ * @param issuerUrl - The issuer URL (e.g., https://accounts.google.com)
20
+ * @returns Authorization server metadata or null if not found
21
+ */
22
+ export async function discoverAuthorizationServer(issuerUrl) {
23
+ const baseUrl = issuerUrl.replace(/\/$/, '');
24
+ for (const path of WELL_KNOWN_PATHS) {
25
+ try {
26
+ const response = await fetch(`${baseUrl}${path}`, {
27
+ headers: {
28
+ Accept: 'application/json',
29
+ },
30
+ });
31
+ if (response.ok) {
32
+ const metadata = await response.json();
33
+ return metadata;
34
+ }
35
+ }
36
+ catch {
37
+ // Try next path
38
+ continue;
39
+ }
40
+ }
41
+ return null;
42
+ }
43
+ /**
44
+ * Check if an authorization server supports Dynamic Client Registration
45
+ *
46
+ * @param metadata - Authorization server metadata
47
+ * @returns True if DCR is supported
48
+ */
49
+ export function supportsDCR(metadata) {
50
+ return !!metadata.registration_endpoint;
51
+ }
52
+ /**
53
+ * Register a new OAuth client dynamically
54
+ *
55
+ * @param registrationEndpoint - The DCR endpoint URL
56
+ * @param request - Client registration request
57
+ * @param accessToken - Optional access token (for protected registration endpoints)
58
+ * @returns Client registration response
59
+ * @throws Error if registration fails
60
+ */
61
+ export async function registerClient(registrationEndpoint, request, accessToken) {
62
+ const headers = {
63
+ 'Content-Type': 'application/json',
64
+ Accept: 'application/json',
65
+ };
66
+ if (accessToken) {
67
+ headers['Authorization'] = `Bearer ${accessToken}`;
68
+ }
69
+ const response = await fetch(registrationEndpoint, {
70
+ method: 'POST',
71
+ headers,
72
+ body: JSON.stringify(request),
73
+ });
74
+ const data = await response.json();
75
+ if (!response.ok) {
76
+ const error = data;
77
+ throw new Error(`DCR registration failed: ${error.error}${error.error_description ? ` - ${error.error_description}` : ''}`);
78
+ }
79
+ return data;
80
+ }
81
+ /**
82
+ * Update an existing client registration
83
+ *
84
+ * @param registrationClientUri - The client configuration endpoint
85
+ * @param registrationAccessToken - The registration access token
86
+ * @param updates - Fields to update
87
+ * @returns Updated client registration
88
+ */
89
+ export async function updateClientRegistration(registrationClientUri, registrationAccessToken, updates) {
90
+ const response = await fetch(registrationClientUri, {
91
+ method: 'PUT',
92
+ headers: {
93
+ 'Content-Type': 'application/json',
94
+ Accept: 'application/json',
95
+ Authorization: `Bearer ${registrationAccessToken}`,
96
+ },
97
+ body: JSON.stringify(updates),
98
+ });
99
+ const data = await response.json();
100
+ if (!response.ok) {
101
+ const error = data;
102
+ throw new Error(`DCR update failed: ${error.error}${error.error_description ? ` - ${error.error_description}` : ''}`);
103
+ }
104
+ return data;
105
+ }
106
+ /**
107
+ * Delete a client registration
108
+ *
109
+ * @param registrationClientUri - The client configuration endpoint
110
+ * @param registrationAccessToken - The registration access token
111
+ */
112
+ export async function deleteClientRegistration(registrationClientUri, registrationAccessToken) {
113
+ const response = await fetch(registrationClientUri, {
114
+ method: 'DELETE',
115
+ headers: {
116
+ Authorization: `Bearer ${registrationAccessToken}`,
117
+ },
118
+ });
119
+ if (!response.ok && response.status !== 204) {
120
+ throw new Error(`DCR delete failed: ${response.status} ${response.statusText}`);
121
+ }
122
+ }
123
+ /**
124
+ * Get or create a dynamic client for an OAuth provider
125
+ *
126
+ * This is the main entry point for DCR. It:
127
+ * 1. Checks if we already have a registered client for this issuer
128
+ * 2. If not, discovers the authorization server metadata
129
+ * 3. If DCR is supported, registers a new client
130
+ * 4. Stores the client for future use
131
+ *
132
+ * @param issuerUrl - The OAuth provider's issuer URL
133
+ * @param options - Registration options
134
+ * @returns The dynamic client information
135
+ * @throws Error if DCR is not supported or registration fails
136
+ */
137
+ export async function getOrCreateDynamicClient(issuerUrl, options) {
138
+ const normalizedIssuer = issuerUrl.replace(/\/$/, '');
139
+ // Check for existing client
140
+ if (!options.forceNew) {
141
+ const existingClient = loadDynamicClient(normalizedIssuer);
142
+ if (existingClient) {
143
+ // Check if client secret has expired
144
+ if (existingClient.clientSecretExpiresAt &&
145
+ existingClient.clientSecretExpiresAt > 0 &&
146
+ existingClient.clientSecretExpiresAt * 1000 < Date.now()) {
147
+ console.log('[DCR] Client secret expired, re-registering');
148
+ }
149
+ else {
150
+ return existingClient;
151
+ }
152
+ }
153
+ }
154
+ // Discover authorization server
155
+ const metadata = await discoverAuthorizationServer(normalizedIssuer);
156
+ if (!metadata) {
157
+ throw new Error(`Could not discover authorization server at ${normalizedIssuer}`);
158
+ }
159
+ // Check for DCR support
160
+ if (!supportsDCR(metadata)) {
161
+ throw new Error(`Authorization server at ${normalizedIssuer} does not support Dynamic Client Registration`);
162
+ }
163
+ // Build registration request
164
+ const request = {
165
+ redirect_uris: options.redirectUris,
166
+ client_name: options.clientName || 'Agent Runtimes Client',
167
+ grant_types: ['authorization_code', 'refresh_token'],
168
+ response_types: ['code'],
169
+ token_endpoint_auth_method: 'none', // Public client (PKCE)
170
+ };
171
+ if (options.scopes?.length) {
172
+ request.scope = options.scopes.join(' ');
173
+ }
174
+ // Register client
175
+ const registrationResponse = await registerClient(metadata.registration_endpoint, request, options.initialAccessToken);
176
+ // Build dynamic client object
177
+ const dynamicClient = {
178
+ issuer: normalizedIssuer,
179
+ clientId: registrationResponse.client_id,
180
+ clientSecret: registrationResponse.client_secret,
181
+ clientSecretExpiresAt: registrationResponse.client_secret_expires_at,
182
+ registrationAccessToken: registrationResponse.registration_access_token,
183
+ registrationClientUri: registrationResponse.registration_client_uri,
184
+ registeredAt: Date.now(),
185
+ redirectUris: options.redirectUris,
186
+ scopes: options.scopes || [],
187
+ serverMetadata: metadata,
188
+ };
189
+ // Store for future use
190
+ saveDynamicClient(dynamicClient);
191
+ return dynamicClient;
192
+ }
193
+ /**
194
+ * Load a dynamic client from storage
195
+ */
196
+ export function loadDynamicClient(issuer) {
197
+ try {
198
+ const stored = localStorage.getItem(DCR_STORAGE_KEY);
199
+ if (!stored)
200
+ return null;
201
+ const clients = JSON.parse(stored);
202
+ return clients[issuer] || null;
203
+ }
204
+ catch {
205
+ return null;
206
+ }
207
+ }
208
+ /**
209
+ * Save a dynamic client to storage
210
+ */
211
+ export function saveDynamicClient(client) {
212
+ try {
213
+ const stored = localStorage.getItem(DCR_STORAGE_KEY);
214
+ const clients = stored ? JSON.parse(stored) : {};
215
+ clients[client.issuer] = client;
216
+ localStorage.setItem(DCR_STORAGE_KEY, JSON.stringify(clients));
217
+ }
218
+ catch (error) {
219
+ console.error('[DCR] Failed to save client:', error);
220
+ }
221
+ }
222
+ /**
223
+ * Remove a dynamic client from storage
224
+ */
225
+ export function removeDynamicClient(issuer) {
226
+ try {
227
+ const stored = localStorage.getItem(DCR_STORAGE_KEY);
228
+ if (!stored)
229
+ return;
230
+ const clients = JSON.parse(stored);
231
+ delete clients[issuer];
232
+ localStorage.setItem(DCR_STORAGE_KEY, JSON.stringify(clients));
233
+ }
234
+ catch {
235
+ // Ignore storage errors
236
+ }
237
+ }
238
+ /**
239
+ * Get all stored dynamic clients
240
+ */
241
+ export function getAllDynamicClients() {
242
+ try {
243
+ const stored = localStorage.getItem(DCR_STORAGE_KEY);
244
+ if (!stored)
245
+ return [];
246
+ const clients = JSON.parse(stored);
247
+ return Object.values(clients);
248
+ }
249
+ catch {
250
+ return [];
251
+ }
252
+ }
253
+ /**
254
+ * Clear all stored dynamic clients
255
+ */
256
+ export function clearAllDynamicClients() {
257
+ try {
258
+ localStorage.removeItem(DCR_STORAGE_KEY);
259
+ }
260
+ catch {
261
+ // Ignore storage errors
262
+ }
263
+ }
264
+ /**
265
+ * Build OAuth provider config from a dynamic client
266
+ *
267
+ * This converts a DynamicClient into an OAuthProviderConfig that can be
268
+ * used with the rest of the identity system.
269
+ */
270
+ export function dynamicClientToProviderConfig(client, displayName) {
271
+ return {
272
+ provider: client.issuer,
273
+ displayName: displayName || new URL(client.issuer).hostname,
274
+ clientId: client.clientId,
275
+ authorizationUrl: client.serverMetadata.authorization_endpoint,
276
+ tokenUrl: client.serverMetadata.token_endpoint,
277
+ userInfoUrl: client.serverMetadata.userinfo_endpoint,
278
+ revocationUrl: client.serverMetadata.revocation_endpoint,
279
+ defaultScopes: client.scopes,
280
+ redirectUri: client.redirectUris[0],
281
+ };
282
+ }
@@ -0,0 +1,72 @@
1
+ import type { Identity, IdentityStore, AuthorizationRequest } from './types';
2
+ /**
3
+ * Create the identity store
4
+ */
5
+ export declare const useIdentityStore: import("zustand").UseBoundStore<Omit<Omit<Omit<import("zustand").StoreApi<IdentityStore>, "setState"> & {
6
+ setState<A extends string | {
7
+ type: string;
8
+ }>(partial: IdentityStore | Partial<IdentityStore> | ((state: IdentityStore) => IdentityStore | Partial<IdentityStore>), replace?: boolean | undefined, action?: A | undefined): void;
9
+ }, "subscribe"> & {
10
+ subscribe: {
11
+ (listener: (selectedState: IdentityStore, previousSelectedState: IdentityStore) => void): () => void;
12
+ <U>(selector: (state: IdentityStore) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
13
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
14
+ fireImmediately?: boolean;
15
+ } | undefined): () => void;
16
+ };
17
+ }, "persist"> & {
18
+ persist: {
19
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<IdentityStore, any>>) => void;
20
+ clearStorage: () => void;
21
+ rehydrate: () => Promise<void> | void;
22
+ hasHydrated: () => boolean;
23
+ onHydrate: (fn: (state: IdentityStore) => void) => () => void;
24
+ onFinishHydration: (fn: (state: IdentityStore) => void) => () => void;
25
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<IdentityStore, any>>;
26
+ };
27
+ }>;
28
+ /**
29
+ * Get all connected identities
30
+ */
31
+ export declare function useConnectedIdentities(): Identity[];
32
+ /**
33
+ * Get connected provider names
34
+ */
35
+ export declare function useConnectedProviders(): string[];
36
+ /**
37
+ * Get identity for a specific provider
38
+ */
39
+ export declare function useIdentity(provider: string): Identity | undefined;
40
+ /**
41
+ * Check if a provider is connected
42
+ */
43
+ export declare function useIsProviderConnected(provider: string): boolean;
44
+ /**
45
+ * Get pending authorization
46
+ */
47
+ export declare function usePendingAuthorization(): AuthorizationRequest | null;
48
+ /**
49
+ * Get identity loading state
50
+ */
51
+ export declare function useIdentityLoading(): boolean;
52
+ /**
53
+ * Get identity error
54
+ */
55
+ export declare function useIdentityError(): Error | null;
56
+ /**
57
+ * Configure built-in providers with client IDs
58
+ */
59
+ export declare function configureBuiltinProviders(options: {
60
+ github?: {
61
+ clientId: string;
62
+ redirectUri: string;
63
+ };
64
+ google?: {
65
+ clientId: string;
66
+ redirectUri: string;
67
+ };
68
+ kaggle?: {
69
+ clientId: string;
70
+ redirectUri: string;
71
+ };
72
+ }): void;