@datalayer/agent-runtimes 1.0.7 → 1.0.9
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.
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, useRef } from 'react';
|
|
21
|
+
import { useEffect, useMemo, useState, useRef, useCallback } 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,9 +145,7 @@ 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
|
|
149
|
-
renderCountRef.current += 1;
|
|
150
|
-
console.log(`[AgentRuntimes][Chat] render count: ${renderCountRef.current}`);
|
|
148
|
+
const lastMessageCountRef = useRef(null);
|
|
151
149
|
// Get connected identities to pass to backend for skill execution
|
|
152
150
|
const connectedIdentities = useConnectedIdentities();
|
|
153
151
|
// Map identities to the format expected by ChatBase
|
|
@@ -272,6 +270,26 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
|
|
|
272
270
|
const handleNewChat = () => {
|
|
273
271
|
onDisconnect?.();
|
|
274
272
|
};
|
|
273
|
+
const handleInformationClick = useCallback(() => {
|
|
274
|
+
setShowDetails(true);
|
|
275
|
+
}, []);
|
|
276
|
+
const handleBackFromDetails = useCallback(() => {
|
|
277
|
+
setShowDetails(false);
|
|
278
|
+
}, []);
|
|
279
|
+
const handleMessagesChange = useCallback((messages) => {
|
|
280
|
+
const nextCount = messages.length;
|
|
281
|
+
if (lastMessageCountRef.current === nextCount) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
lastMessageCountRef.current = nextCount;
|
|
285
|
+
setMessageCount(nextCount);
|
|
286
|
+
}, []);
|
|
287
|
+
const headerButtons = useMemo(() => ({
|
|
288
|
+
showNewChat: showNewChatButton,
|
|
289
|
+
showClear: showClearButton,
|
|
290
|
+
onNewChat: handleNewChat,
|
|
291
|
+
}), [showNewChatButton, showClearButton]);
|
|
292
|
+
const avatarConfig = useMemo(() => ({ showAvatars: true }), []);
|
|
275
293
|
// Render error state
|
|
276
294
|
if (error) {
|
|
277
295
|
return (_jsx(QueryClientProvider, { client: queryClient, children: _jsxs(Box, { className: className, sx: {
|
|
@@ -306,7 +324,7 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
|
|
|
306
324
|
display: showDetails ? 'flex' : 'none',
|
|
307
325
|
flexDirection: 'column',
|
|
308
326
|
height: '100%',
|
|
309
|
-
}, children: _jsx(AgentDetails, { name: title || 'AI Agent', icon: brandIcon, protocol: transport, url: protocolConfig?.endpoint || baseUrl, messageCount: messageCount, agentId: agentId, apiBase: baseUrl, identityProviders: identityProviders, onIdentityConnect: onIdentityConnect, onIdentityDisconnect: onIdentityDisconnect, onBack:
|
|
327
|
+
}, children: _jsx(AgentDetails, { name: title || 'AI Agent', icon: brandIcon, protocol: transport, url: protocolConfig?.endpoint || baseUrl, messageCount: messageCount, agentId: agentId, apiBase: baseUrl, identityProviders: identityProviders, onIdentityConnect: onIdentityConnect, onIdentityDisconnect: onIdentityDisconnect, onBack: handleBackFromDetails, mcpStatusData: mcpStatusData, codemodeStatusData: codemodeStatusData }) }), _jsxs(Box, { sx: {
|
|
310
328
|
display: showDetails ? 'none' : 'flex',
|
|
311
329
|
flexDirection: 'column',
|
|
312
330
|
height: '100%',
|
|
@@ -331,12 +349,6 @@ export function Chat({ protocol: transport, extensions: _extensions, baseUrl = '
|
|
|
331
349
|
? 'attention.fg'
|
|
332
350
|
: 'danger.fg',
|
|
333
351
|
flex: 1,
|
|
334
|
-
}, children: errorBanner.message })] })), _jsx(ChatBase, { title: title, subtitle: subtitle, brandIcon: brandIcon, showHeader: showHeader, protocol: protocolConfig, placeholder: placeholder, description: description, suggestions: suggestions, submitOnSuggestionClick: submitOnSuggestionClick, autoFocus: autoFocus, runtimeId: runtimeId, historyEndpoint: historyEndpoint, pendingPrompt: pendingPrompt, showInformation: showInformation, onInformationClick:
|
|
335
|
-
showNewChat: showNewChatButton,
|
|
336
|
-
showClear: showClearButton,
|
|
337
|
-
onNewChat: handleNewChat,
|
|
338
|
-
}, avatarConfig: {
|
|
339
|
-
showAvatars: true,
|
|
340
|
-
}, backgroundColor: "canvas.default", focusTrigger: focusTrigger, chatViewMode: chatViewMode, onChatViewModeChange: onChatViewModeChange, frontendTools: frontendTools, onToolCallStart: onToolCallStart, onToolCallComplete: onToolCallComplete, renderToolResult: renderToolResult, hideMessagesAfterToolUI: hideMessagesAfterToolUI, contextSnapshot: contextSnapshot, mcpStatusData: mcpStatusData, sandboxStatusData: sandboxStatusData, showToolApprovalBanner: showToolApprovalBanner, pendingApprovals: pendingApprovals, onApproveApproval: onApproveApproval, onRejectApproval: onRejectApproval })] })] }) }));
|
|
352
|
+
}, children: errorBanner.message })] })), _jsx(ChatBase, { title: title, subtitle: subtitle, brandIcon: brandIcon, showHeader: showHeader, protocol: protocolConfig, placeholder: placeholder, description: description, suggestions: suggestions, submitOnSuggestionClick: submitOnSuggestionClick, autoFocus: autoFocus, runtimeId: runtimeId, historyEndpoint: historyEndpoint, pendingPrompt: pendingPrompt, showInformation: showInformation, onInformationClick: handleInformationClick, headerContent: headerContent, headerActions: headerActions, showModelSelector: showModelSelector, showToolsMenu: showToolsMenu, showInput: showInput, disableInputPrompt: disableInputPrompt, showSkillsMenu: showSkillsMenu, showTokenUsage: showTokenUsage, codemodeEnabled: codemodeEnabled, onToggleCodemode: onToggleCodemode, initialModel: initialModel, availableModels: availableModels, mcpServers: mcpServers, initialSkills: initialSkills, connectedIdentities: identitiesForChat, onNewChat: handleNewChat, onMessagesChange: handleMessagesChange, headerButtons: headerButtons, avatarConfig: avatarConfig, backgroundColor: "canvas.default", focusTrigger: focusTrigger, chatViewMode: chatViewMode, onChatViewModeChange: onChatViewModeChange, frontendTools: frontendTools, onToolCallStart: onToolCallStart, onToolCallComplete: onToolCallComplete, renderToolResult: renderToolResult, hideMessagesAfterToolUI: hideMessagesAfterToolUI, contextSnapshot: contextSnapshot, mcpStatusData: mcpStatusData, sandboxStatusData: sandboxStatusData, showToolApprovalBanner: showToolApprovalBanner, pendingApprovals: pendingApprovals, onApproveApproval: onApproveApproval, onRejectApproval: onRejectApproval })] })] }) }));
|
|
341
353
|
}
|
|
342
354
|
export default Chat;
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { create } from 'zustand';
|
|
13
13
|
import { devtools, subscribeWithSelector, persist } from 'zustand/middleware';
|
|
14
|
+
import { useShallow } from 'zustand/react/shallow';
|
|
14
15
|
import { GITHUB_PROVIDER, GOOGLE_PROVIDER, KAGGLE_PROVIDER } from './types';
|
|
15
16
|
import { generatePKCEPair, generateState } from './pkce';
|
|
16
17
|
/**
|
|
@@ -459,15 +460,15 @@ export const useIdentityStore = create()(devtools(subscribeWithSelector(persist(
|
|
|
459
460
|
* Get all connected identities
|
|
460
461
|
*/
|
|
461
462
|
export function useConnectedIdentities() {
|
|
462
|
-
return useIdentityStore(state => Array.from(state.identities.values()).filter(i => i.isConnected));
|
|
463
|
+
return useIdentityStore(useShallow(state => Array.from(state.identities.values()).filter(i => i.isConnected)));
|
|
463
464
|
}
|
|
464
465
|
/**
|
|
465
466
|
* Get connected provider names
|
|
466
467
|
*/
|
|
467
468
|
export function useConnectedProviders() {
|
|
468
|
-
return useIdentityStore(state => Array.from(state.identities.entries())
|
|
469
|
+
return useIdentityStore(useShallow(state => Array.from(state.identities.entries())
|
|
469
470
|
.filter(([_, identity]) => identity.isConnected)
|
|
470
|
-
.map(([provider]) => provider));
|
|
471
|
+
.map(([provider]) => provider)));
|
|
471
472
|
}
|
|
472
473
|
/**
|
|
473
474
|
* Get identity for a specific provider
|
|
@@ -24,7 +24,6 @@ function isRecentDuplicate(toolName, params) {
|
|
|
24
24
|
if (lastExecution) {
|
|
25
25
|
const timeSinceExecution = Date.now() - lastExecution;
|
|
26
26
|
if (timeSinceExecution < CACHE_TTL_MS) {
|
|
27
|
-
console.log(`[agent-runtimes] 🚫 DUPLICATE DETECTED - Skipping execution (${timeSinceExecution}ms since last call)`);
|
|
28
27
|
return true;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -53,7 +52,6 @@ function processParameters(params) {
|
|
|
53
52
|
(value.startsWith('{') || value.startsWith('['))) {
|
|
54
53
|
try {
|
|
55
54
|
processed[key] = JSON.parse(value);
|
|
56
|
-
console.log(`[agent-runtimes] 📝 Parsed JSON string for parameter '${key}'`);
|
|
57
55
|
}
|
|
58
56
|
catch {
|
|
59
57
|
// If parsing fails, keep the original string
|
|
@@ -82,13 +80,8 @@ export function createAgentRuntimesTool(definition, operation, context) {
|
|
|
82
80
|
description: definition.description,
|
|
83
81
|
parameters: definition.parameters,
|
|
84
82
|
handler: async (params) => {
|
|
85
|
-
console.log(`[agent-runtimes] ========== HANDLER CALLED ==========`);
|
|
86
|
-
console.log(`[agent-runtimes] Tool: ${definition.name}`);
|
|
87
|
-
console.log(`[agent-runtimes] Operation: ${definition.operation}`);
|
|
88
|
-
console.log(`[agent-runtimes] Params:`, params);
|
|
89
83
|
// Check for duplicate execution
|
|
90
84
|
if (isRecentDuplicate(definition.name, params)) {
|
|
91
|
-
console.log(`[agent-runtimes] 🚫 DUPLICATE DETECTED - Returning early`);
|
|
92
85
|
return {
|
|
93
86
|
success: false,
|
|
94
87
|
message: 'Operation already executed recently (duplicate detected)',
|
|
@@ -97,13 +90,11 @@ export function createAgentRuntimesTool(definition, operation, context) {
|
|
|
97
90
|
try {
|
|
98
91
|
// Process parameters to handle JSON strings
|
|
99
92
|
const processedParams = processParameters(params);
|
|
100
|
-
console.log(`[agent-runtimes] Processed params:`, processedParams);
|
|
101
93
|
// Use OperationRunner to execute operation with TOON format
|
|
102
94
|
const result = await runner.execute(operation, processedParams, {
|
|
103
95
|
...context,
|
|
104
96
|
format: 'toon', // Return human/LLM-readable string
|
|
105
97
|
});
|
|
106
|
-
console.log(`[agent-runtimes] Operation result:`, result);
|
|
107
98
|
return result;
|
|
108
99
|
}
|
|
109
100
|
catch (error) {
|
|
@@ -136,6 +127,5 @@ export function createAllAgentRuntimesTools(definitions, operations, context) {
|
|
|
136
127
|
const tool = createAgentRuntimesTool(definition, operation, context);
|
|
137
128
|
tools.push(tool);
|
|
138
129
|
}
|
|
139
|
-
console.log(`[agent-runtimes Tools] Created ${tools.length} frontend tools`);
|
|
140
130
|
return tools;
|
|
141
131
|
}
|