@datalayer/agent-runtimes 1.0.6 → 1.0.7

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 (2) hide show
  1. package/lib/chat/Chat.js +33 -18
  2. package/package.json +1 -1
package/lib/chat/Chat.js CHANGED
@@ -18,7 +18,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
18
  *
19
19
  * @module chat/Chat
20
20
  */
21
- import { useEffect, useMemo, useState } from 'react';
21
+ import { useEffect, useMemo, useState, useRef } from 'react';
22
22
  import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
23
23
  import { Text, Button, Spinner } from '@primer/react';
24
24
  import { AlertIcon, SyncIcon } from '@primer/octicons-react';
@@ -145,6 +145,9 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
145
145
  const [showDetails, setShowDetails] = useState(false);
146
146
  const [messageCount, setMessageCount] = useState(0);
147
147
  const [focusTrigger, setFocusTrigger] = useState(0);
148
+ const renderCountRef = useRef(0);
149
+ renderCountRef.current += 1;
150
+ console.log(`[AgentRuntimes][Chat] render count: ${renderCountRef.current}`);
148
151
  // Get connected identities to pass to backend for skill execution
149
152
  const connectedIdentities = useConnectedIdentities();
150
153
  // Map identities to the format expected by ChatBase
@@ -167,8 +170,9 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
167
170
  return () => clearTimeout(timer);
168
171
  }
169
172
  }, [showDetails]);
170
- // Build protocol config based on transport
171
- const protocolConfig = useMemo(() => {
173
+ // Build protocol config based on transport.
174
+ // Keep this pure: never call React state setters inside this memo.
175
+ const protocolConfigResult = useMemo(() => {
172
176
  try {
173
177
  let endpoint;
174
178
  let authToken = authTokenProp;
@@ -219,33 +223,44 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
219
223
  }
220
224
  }
221
225
  return {
222
- type: getProtocolType(transport),
223
- endpoint,
224
- agentId: resolvedAgentId,
225
- authToken,
226
- options,
227
- // Enable config query for all protocols to fetch models and tools
228
- enableConfigQuery: true,
229
- // For Jupyter-based transports, use Jupyter requestAPI (configEndpoint undefined)
230
- // For FastAPI-based transports, use direct fetch to the configure endpoint
231
- configEndpoint: transport === 'vercel-ai-jupyter'
232
- ? undefined // Use Jupyter requestAPI
233
- : `${baseUrl}/api/v1/configure`,
226
+ config: {
227
+ type: getProtocolType(transport),
228
+ endpoint,
229
+ agentId: resolvedAgentId,
230
+ authToken,
231
+ options,
232
+ // Enable config query for all protocols to fetch models and tools
233
+ enableConfigQuery: true,
234
+ // For Jupyter-based transports, use Jupyter requestAPI (configEndpoint undefined)
235
+ // For FastAPI-based transports, use direct fetch to the configure endpoint
236
+ configEndpoint: transport === 'vercel-ai-jupyter'
237
+ ? undefined // Use Jupyter requestAPI
238
+ : `${baseUrl}/api/v1/configure`,
239
+ },
240
+ error: null,
234
241
  };
235
242
  }
236
243
  catch (err) {
237
244
  console.error('[Chat] Error building protocol config:', err);
238
- setError(err instanceof Error ? err.message : 'Failed to configure');
239
- return undefined;
245
+ return {
246
+ config: undefined,
247
+ error: err instanceof Error ? err.message : 'Failed to configure',
248
+ };
240
249
  }
241
250
  }, [transport, baseUrl, wsUrl, resolvedAgentId, authTokenProp]);
251
+ const protocolConfig = protocolConfigResult.config;
242
252
  // Set initialized once protocol config is built
243
253
  useEffect(() => {
254
+ if (protocolConfigResult.error) {
255
+ setError(protocolConfigResult.error);
256
+ setIsInitializing(false);
257
+ return;
258
+ }
244
259
  if (protocolConfig) {
245
260
  setIsInitializing(false);
246
261
  setError(null);
247
262
  }
248
- }, [protocolConfig]);
263
+ }, [protocolConfig, protocolConfigResult.error]);
249
264
  // Handle reconnect
250
265
  const handleReconnect = () => {
251
266
  setError(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/agent-runtimes",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",