@datalayer/agent-runtimes 0.0.9 → 0.0.10
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/README.md +2 -1
- package/lib/{examples/components → components}/AgentConfiguration.d.ts +27 -12
- package/lib/{examples/components → components}/AgentConfiguration.js +170 -22
- package/lib/{examples/components → components}/FooterMetrics.d.ts +1 -2
- package/lib/{examples/components → components}/Header.d.ts +1 -6
- package/lib/{examples/components → components}/Header.js +5 -39
- package/lib/{examples/components → components}/HeaderControls.d.ts +1 -2
- package/lib/{examples/components → components}/HeaderControls.js +1 -1
- package/lib/{examples/components → components}/LexicalEditor.d.ts +2 -3
- package/lib/{examples/components → components}/LexicalEditor.js +2 -2
- package/lib/components/MainContent.d.ts +34 -0
- package/lib/{examples/components → components}/MainContent.js +18 -9
- package/lib/components/McpServerManager.d.ts +30 -0
- package/lib/components/McpServerManager.js +331 -0
- package/lib/{examples/components → components}/MockFileBrowser.d.ts +1 -2
- package/lib/{examples/components → components}/SessionTabs.d.ts +2 -3
- package/lib/{examples/components → components}/TimeTravel.d.ts +1 -2
- package/lib/components/chat/components/AgentDetails.d.ts +3 -1
- package/lib/components/chat/components/AgentDetails.js +323 -31
- package/lib/components/chat/components/Chat.d.ts +37 -3
- package/lib/components/chat/components/Chat.js +29 -10
- package/lib/components/chat/components/ChatFloating.d.ts +27 -2
- package/lib/components/chat/components/ChatFloating.js +17 -10
- package/lib/components/chat/components/ChatPopupStandalone.js +1 -1
- package/lib/components/chat/components/ChatSidebar.d.ts +1 -1
- package/lib/components/chat/components/ChatStandalone.d.ts +1 -1
- package/lib/components/chat/components/ChatStandalone.js +1 -1
- package/lib/components/chat/components/ContextDistribution.d.ts +70 -6
- package/lib/components/chat/components/ContextDistribution.js +11 -4
- package/lib/components/chat/components/ContextInspector.d.ts +81 -0
- package/lib/components/chat/components/ContextInspector.js +261 -0
- package/lib/components/chat/components/ContextPanel.d.ts +112 -0
- package/lib/components/chat/components/ContextPanel.js +373 -0
- package/lib/components/chat/components/base/ChatBase.d.ts +74 -19
- package/lib/components/chat/components/base/ChatBase.js +296 -37
- package/lib/components/chat/components/index.d.ts +3 -1
- package/lib/components/chat/components/index.js +2 -0
- package/lib/components/chat/extensions/ExtensionRegistry.d.ts +1 -1
- package/lib/components/chat/extensions/index.d.ts +1 -0
- package/lib/components/chat/index.d.ts +3 -3
- package/lib/components/chat/protocols/AGUIAdapter.js +24 -4
- package/lib/components/chat/protocols/VercelAIAdapter.js +35 -1
- package/lib/components/chat/store/chatStore.d.ts +2 -3
- package/lib/components/chat/store/conversationStore.d.ts +83 -0
- package/lib/components/chat/store/conversationStore.js +174 -0
- package/lib/components/chat/store/index.d.ts +2 -1
- package/lib/components/chat/store/index.js +1 -0
- package/lib/components/chat/types/inference.d.ts +17 -0
- package/lib/components/chat/types/protocol.d.ts +10 -0
- package/lib/components/index.d.ts +23 -0
- package/lib/components/index.js +11 -0
- package/lib/config/agents.d.ts +33 -0
- package/lib/config/agents.js +424 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +8 -0
- package/lib/config/mcpServers.d.ts +18 -0
- package/lib/config/mcpServers.js +129 -0
- package/lib/config/skills.d.ts +25 -0
- package/lib/config/skills.js +54 -0
- package/lib/{lib → config}/utils.d.ts +1 -1
- package/lib/{lib → config}/utils.js +2 -2
- package/lib/examples/AgentRuntimeLexical2Example.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexical2Example.js +3 -2
- package/lib/examples/AgentRuntimeLexicalExample.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexicalExample.js +5 -3
- package/lib/examples/AgentRuntimeLexicalSidebarExample.d.ts +1 -0
- package/lib/examples/AgentRuntimeLexicalSidebarExample.js +3 -3
- package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
- package/lib/examples/AgentSpaceFormExample.d.ts +2 -2
- package/lib/examples/AgentSpaceFormExample.js +167 -29
- package/lib/examples/CopilotKitLexicalExample.d.ts +1 -0
- package/lib/examples/CopilotKitLexicalExample.js +3 -2
- package/lib/examples/index.d.ts +1 -0
- package/lib/examples/stores/notebooks/NotebookExample2.ipynb.json +43 -43
- package/lib/hooks/useAGUI.d.ts +1 -1
- package/lib/hooks/useAGUI.js +1 -1
- package/lib/identity/types.d.ts +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +1 -0
- package/lib/runtime/index.d.ts +3 -0
- package/lib/runtime/runtimeStore.d.ts +3 -4
- package/lib/runtime/useAgentConnection.d.ts +2 -3
- package/lib/runtime/useAgentRuntime.d.ts +2 -3
- package/lib/stories/Cell.stories.js +1 -1
- package/lib/tools/adapters/agent-runtimes/notebookHooks.js +1 -0
- package/lib/tools/adapters/copilotkit/notebookHooks.js +1 -0
- package/lib/types.d.ts +150 -0
- package/package.json +4 -5
- package/scripts/apply-patches.sh +1 -1
- package/scripts/codegen/generate_agents.py +452 -0
- package/scripts/codegen/generate_mcp_servers.py +424 -0
- package/scripts/codegen/generate_skills.py +321 -0
- package/scripts/download-ai-elements.py +35 -20
- package/scripts/sync-jupyter.sh +6 -0
- package/lib/components/ui/accordion.d.ts +0 -7
- package/lib/components/ui/accordion.js +0 -22
- package/lib/components/ui/alert-dialog.d.ts +0 -14
- package/lib/components/ui/alert-dialog.js +0 -43
- package/lib/components/ui/alert.d.ts +0 -9
- package/lib/components/ui/alert.js +0 -24
- package/lib/components/ui/aspect-ratio.d.ts +0 -3
- package/lib/components/ui/aspect-ratio.js +0 -11
- package/lib/components/ui/avatar.d.ts +0 -6
- package/lib/components/ui/avatar.js +0 -18
- package/lib/components/ui/badge.d.ts +0 -9
- package/lib/components/ui/badge.js +0 -22
- package/lib/components/ui/breadcrumb.d.ts +0 -11
- package/lib/components/ui/breadcrumb.js +0 -27
- package/lib/components/ui/button-group.d.ts +0 -11
- package/lib/components/ui/button-group.js +0 -31
- package/lib/components/ui/button.d.ts +0 -13
- package/lib/components/ui/button.js +0 -39
- package/lib/components/ui/calendar.d.ts +0 -8
- package/lib/components/ui/calendar.js +0 -80
- package/lib/components/ui/card.d.ts +0 -9
- package/lib/components/ui/card.js +0 -24
- package/lib/components/ui/carousel.d.ts +0 -19
- package/lib/components/ui/carousel.js +0 -95
- package/lib/components/ui/chart.d.ts +0 -53
- package/lib/components/ui/chart.js +0 -136
- package/lib/components/ui/checkbox.d.ts +0 -4
- package/lib/components/ui/checkbox.js +0 -13
- package/lib/components/ui/collapsible.d.ts +0 -5
- package/lib/components/ui/collapsible.js +0 -17
- package/lib/components/ui/command.d.ts +0 -18
- package/lib/components/ui/command.js +0 -38
- package/lib/components/ui/context-menu.d.ts +0 -25
- package/lib/components/ui/context-menu.js +0 -55
- package/lib/components/ui/dialog.d.ts +0 -15
- package/lib/components/ui/dialog.js +0 -40
- package/lib/components/ui/drawer.d.ts +0 -13
- package/lib/components/ui/drawer.js +0 -39
- package/lib/components/ui/dropdown-menu.d.ts +0 -25
- package/lib/components/ui/dropdown-menu.js +0 -55
- package/lib/components/ui/empty.d.ts +0 -11
- package/lib/components/ui/empty.js +0 -37
- package/lib/components/ui/field.d.ts +0 -24
- package/lib/components/ui/field.js +0 -80
- package/lib/components/ui/form.d.ts +0 -24
- package/lib/components/ui/form.js +0 -63
- package/lib/components/ui/hover-card.d.ts +0 -6
- package/lib/components/ui/hover-card.js +0 -18
- package/lib/components/ui/input-group.d.ts +0 -19
- package/lib/components/ui/input-group.js +0 -69
- package/lib/components/ui/input-otp.d.ts +0 -11
- package/lib/components/ui/input-otp.js +0 -25
- package/lib/components/ui/input.d.ts +0 -3
- package/lib/components/ui/input.js +0 -6
- package/lib/components/ui/item.d.ts +0 -23
- package/lib/components/ui/item.js +0 -66
- package/lib/components/ui/kbd.d.ts +0 -3
- package/lib/components/ui/kbd.js +0 -13
- package/lib/components/ui/label.d.ts +0 -4
- package/lib/components/ui/label.js +0 -12
- package/lib/components/ui/menubar.d.ts +0 -26
- package/lib/components/ui/menubar.js +0 -58
- package/lib/components/ui/navigation-menu.d.ts +0 -14
- package/lib/components/ui/navigation-menu.js +0 -31
- package/lib/components/ui/pagination.d.ts +0 -13
- package/lib/components/ui/pagination.js +0 -29
- package/lib/components/ui/popover.d.ts +0 -7
- package/lib/components/ui/popover.js +0 -21
- package/lib/components/ui/progress.d.ts +0 -4
- package/lib/components/ui/progress.js +0 -12
- package/lib/components/ui/radio-group.d.ts +0 -5
- package/lib/components/ui/radio-group.js +0 -16
- package/lib/components/ui/resizable.d.ts +0 -8
- package/lib/components/ui/resizable.js +0 -19
- package/lib/components/ui/scroll-area.d.ts +0 -5
- package/lib/components/ui/scroll-area.js +0 -17
- package/lib/components/ui/select.d.ts +0 -15
- package/lib/components/ui/select.js +0 -42
- package/lib/components/ui/separator.d.ts +0 -4
- package/lib/components/ui/separator.js +0 -12
- package/lib/components/ui/sheet.d.ts +0 -13
- package/lib/components/ui/sheet.js +0 -44
- package/lib/components/ui/sidebar.d.ts +0 -69
- package/lib/components/ui/sidebar.js +0 -216
- package/lib/components/ui/skeleton.d.ts +0 -2
- package/lib/components/ui/skeleton.js +0 -10
- package/lib/components/ui/slider.d.ts +0 -4
- package/lib/components/ui/slider.js +0 -18
- package/lib/components/ui/sonner.d.ts +0 -3
- package/lib/components/ui/sonner.js +0 -25
- package/lib/components/ui/spinner.d.ts +0 -2
- package/lib/components/ui/spinner.js +0 -11
- package/lib/components/ui/switch.d.ts +0 -4
- package/lib/components/ui/switch.js +0 -12
- package/lib/components/ui/table.d.ts +0 -10
- package/lib/components/ui/table.js +0 -32
- package/lib/components/ui/tabs.d.ts +0 -7
- package/lib/components/ui/tabs.js +0 -21
- package/lib/components/ui/textarea.d.ts +0 -3
- package/lib/components/ui/textarea.js +0 -6
- package/lib/components/ui/toast.d.ts +0 -15
- package/lib/components/ui/toast.js +0 -38
- package/lib/components/ui/toaster.d.ts +0 -1
- package/lib/components/ui/toaster.js +0 -14
- package/lib/components/ui/toggle-group.d.ts +0 -9
- package/lib/components/ui/toggle-group.js +0 -26
- package/lib/components/ui/toggle.d.ts +0 -9
- package/lib/components/ui/toggle.js +0 -30
- package/lib/components/ui/tooltip.d.ts +0 -7
- package/lib/components/ui/tooltip.js +0 -21
- package/lib/components/vercel-ai-elements/artifact.d.ts +0 -23
- package/lib/components/vercel-ai-elements/artifact.js +0 -24
- package/lib/components/vercel-ai-elements/code-block.d.ts +0 -17
- package/lib/components/vercel-ai-elements/code-block.js +0 -94
- package/lib/components/vercel-ai-elements/conversation.d.ts +0 -15
- package/lib/components/vercel-ai-elements/conversation.js +0 -21
- package/lib/components/vercel-ai-elements/loader.d.ts +0 -5
- package/lib/components/vercel-ai-elements/loader.js +0 -8
- package/lib/components/vercel-ai-elements/message.d.ts +0 -46
- package/lib/components/vercel-ai-elements/message.js +0 -109
- package/lib/components/vercel-ai-elements/model-selector.d.ts +0 -35
- package/lib/components/vercel-ai-elements/model-selector.js +0 -22
- package/lib/components/vercel-ai-elements/prompt-input.d.ts +0 -195
- package/lib/components/vercel-ai-elements/prompt-input.js +0 -589
- package/lib/components/vercel-ai-elements/reasoning.d.ts +0 -26
- package/lib/components/vercel-ai-elements/reasoning.js +0 -80
- package/lib/components/vercel-ai-elements/shimmer.d.ts +0 -9
- package/lib/components/vercel-ai-elements/shimmer.js +0 -22
- package/lib/components/vercel-ai-elements/sources.d.ts +0 -12
- package/lib/components/vercel-ai-elements/sources.js +0 -13
- package/lib/components/vercel-ai-elements/suggestion.d.ts +0 -10
- package/lib/components/vercel-ai-elements/suggestion.js +0 -16
- package/lib/components/vercel-ai-elements/tool.d.ts +0 -23
- package/lib/components/vercel-ai-elements/tool.js +0 -52
- package/lib/examples/components/MainContent.d.ts +0 -19
- package/lib/examples/components/index.d.ts +0 -10
- package/lib/examples/components/index.js +0 -13
- package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.d.ts +0 -12
- package/lib/examples/vercel-ai-elements/VercelAiElementsShowcase.js +0 -69
- package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ArtifactShowcase.js +0 -85
- package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/CodeBlockShowcase.js +0 -62
- package/lib/examples/vercel-ai-elements/components/ConversationShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ConversationShowcase.js +0 -51
- package/lib/examples/vercel-ai-elements/components/LoaderShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/LoaderShowcase.js +0 -9
- package/lib/examples/vercel-ai-elements/components/MessageShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/MessageShowcase.js +0 -56
- package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ModelSelectorShowcase.js +0 -50
- package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/PromptInputShowcase.js +0 -16
- package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ReasoningShowcase.js +0 -72
- package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ShimmerShowcase.js +0 -9
- package/lib/examples/vercel-ai-elements/components/SourcesShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/SourcesShowcase.js +0 -43
- package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/SuggestionShowcase.js +0 -31
- package/lib/examples/vercel-ai-elements/components/ToolShowcase.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/components/ToolShowcase.js +0 -54
- package/lib/examples/vercel-ai-elements/index.d.ts +0 -13
- package/lib/examples/vercel-ai-elements/index.js +0 -17
- package/lib/examples/vercel-ai-elements/main.d.ts +0 -1
- package/lib/examples/vercel-ai-elements/main.js +0 -9
- package/lib/examples/vercel-ai-elements/showcase.css +0 -128
- package/lib/hooks/useToast.d.ts +0 -44
- package/lib/hooks/useToast.js +0 -128
- package/patches/@datalayer+jupyter-lexical+1.0.8.patch +0 -11628
- package/patches/@datalayer+jupyter-react+2.0.2.patch +0 -5338
- package/style/showcase-vercel-ai.css +0 -137
- /package/lib/{examples/components → components}/FooterMetrics.js +0 -0
- /package/lib/{examples/components → components}/MockFileBrowser.js +0 -0
- /package/lib/{examples/components → components}/SessionTabs.js +0 -0
- /package/lib/{examples/components → components}/TimeTravel.js +0 -0
- /package/lib/{models → types}/AIAgent.d.ts +0 -0
- /package/lib/{models → types}/AIAgent.js +0 -0
- /package/lib/{models → types}/index.d.ts +0 -0
- /package/lib/{models → types}/index.js +0 -0
|
@@ -43,7 +43,7 @@ function useIsMobile(breakpoint = 640) {
|
|
|
43
43
|
* ChatFloating component
|
|
44
44
|
* A floating chat window built on ChatBase
|
|
45
45
|
*/
|
|
46
|
-
export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useStoreMode = true, title = 'Chat', description = 'Start a conversation with the AI agent.', position = 'bottom-right', defaultOpen = false, width = 400, height = 550, showHeader = true, showButton = true, showNewChatButton = true, showClearButton = true, showSettingsButton = false, enableKeyboardShortcuts = true, toggleShortcut = '/', showPoweredBy = true, poweredByProps, clickOutsideToClose = true, escapeToClose = true, className, onSettingsClick, onNewChat, onOpen, onClose, onStateUpdate, children, brandIcon, buttonIcon, buttonTooltip = 'Chat with AI', brandColor = '#7c3aed', offset = 20, animationDuration = 200, renderToolResult, tools: _tools, initialState: _initialState, suggestions, submitOnSuggestionClick = true, hideMessagesAfterToolUI = false, defaultViewMode = 'floating', showPanelBackdrop = false, showModelSelector = false, showToolsMenu = false, showSkillsMenu = false, panelProps, }) {
|
|
46
|
+
export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useStoreMode = true, title = 'Chat', description = 'Start a conversation with the AI agent.', position = 'bottom-right', defaultOpen = false, width = 400, height = 550, showHeader = true, showButton = true, showNewChatButton = true, showClearButton = true, showSettingsButton = false, enableKeyboardShortcuts = true, toggleShortcut = '/', showPoweredBy = true, poweredByProps, clickOutsideToClose = true, escapeToClose = true, className, onSettingsClick, onNewChat, onOpen, onClose, onStateUpdate, children, brandIcon, buttonIcon, buttonTooltip = 'Chat with AI', brandColor = '#7c3aed', offset = 20, animationDuration = 200, renderToolResult, tools: _tools, initialState: _initialState, suggestions, submitOnSuggestionClick = true, hideMessagesAfterToolUI = false, defaultViewMode = 'floating', showPanelBackdrop = false, availableModels, showModelSelector = false, showToolsMenu = false, showSkillsMenu = false, showTokenUsage = true, runtimeId, historyEndpoint, historyAuthToken, panelProps, }) {
|
|
47
47
|
// Store-based state
|
|
48
48
|
const storeIsOpen = useChatOpen();
|
|
49
49
|
const storeMessages = useChatMessages();
|
|
@@ -68,15 +68,23 @@ export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useSt
|
|
|
68
68
|
return protocolProp;
|
|
69
69
|
if (!endpoint)
|
|
70
70
|
return undefined;
|
|
71
|
-
// Extract base URL from endpoint
|
|
72
|
-
|
|
71
|
+
// Extract base URL from endpoint - everything before /api/v1/
|
|
72
|
+
// e.g., https://prod1.datalayer.run/agent-runtimes/pool1/rt123/api/v1/ag-ui/default/
|
|
73
|
+
// -> https://prod1.datalayer.run/agent-runtimes/pool1/rt123
|
|
74
|
+
const baseUrl = endpoint.match(/^(.*?)\/api\/v1\//)?.[1] ||
|
|
75
|
+
endpoint.match(/^(https?:\/\/[^/]+)/)?.[1] ||
|
|
76
|
+
'';
|
|
77
|
+
// Extract agentId from endpoint path (e.g., .../ag-ui/default/ -> default)
|
|
78
|
+
const agentIdMatch = endpoint.match(/\/ag-ui\/([^/]+)/);
|
|
79
|
+
const extractedAgentId = agentIdMatch ? agentIdMatch[1] : undefined;
|
|
73
80
|
return {
|
|
74
81
|
type: 'ag-ui',
|
|
75
82
|
endpoint,
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
agentId: extractedAgentId,
|
|
84
|
+
// Enable config query for model/tools/skills selector or token usage
|
|
85
|
+
enableConfigQuery: showModelSelector || showToolsMenu || showSkillsMenu || showTokenUsage,
|
|
78
86
|
// Config endpoint is at /api/v1/configure (global, not per-agent)
|
|
79
|
-
configEndpoint: showModelSelector || showToolsMenu || showSkillsMenu
|
|
87
|
+
configEndpoint: showModelSelector || showToolsMenu || showSkillsMenu || showTokenUsage
|
|
80
88
|
? `${baseUrl}/api/v1/configure`
|
|
81
89
|
: undefined,
|
|
82
90
|
};
|
|
@@ -86,6 +94,7 @@ export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useSt
|
|
|
86
94
|
showModelSelector,
|
|
87
95
|
showToolsMenu,
|
|
88
96
|
showSkillsMenu,
|
|
97
|
+
showTokenUsage,
|
|
89
98
|
]);
|
|
90
99
|
// Clear messages when endpoint/protocol changes (e.g., switching examples)
|
|
91
100
|
useEffect(() => {
|
|
@@ -364,9 +373,7 @@ export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useSt
|
|
|
364
373
|
border: '1px solid',
|
|
365
374
|
borderColor: 'border.default',
|
|
366
375
|
borderRadius: viewMode === 'panel' || isMobile ? 0 : '12px',
|
|
367
|
-
boxShadow: viewMode === 'panel'
|
|
368
|
-
? '-4px 0 20px rgba(0, 0, 0, 0.15)'
|
|
369
|
-
: '0 8px 30px rgba(0, 0, 0, 0.12)',
|
|
376
|
+
boxShadow: viewMode === 'panel' ? 'shadow.large' : 'shadow.extra-large',
|
|
370
377
|
overflow: 'hidden',
|
|
371
378
|
transform: viewMode === 'panel'
|
|
372
379
|
? isOpen
|
|
@@ -393,6 +400,6 @@ export function ChatFloating({ endpoint, protocol: protocolProp, useStore: useSt
|
|
|
393
400
|
...poweredByProps,
|
|
394
401
|
}, renderToolResult: renderToolResult, description: description, onStateUpdate: onStateUpdate, onNewChat: onNewChat, suggestions: suggestions, submitOnSuggestionClick: submitOnSuggestionClick, hideMessagesAfterToolUI: hideMessagesAfterToolUI, avatarConfig: {
|
|
395
402
|
showAvatars: true,
|
|
396
|
-
}, placeholder: "Type a message...", backgroundColor: "canvas.subtle", frontendTools: _tools, showModelSelector: showModelSelector, showToolsMenu: showToolsMenu, showSkillsMenu: showSkillsMenu, ...panelProps, children: children }) })] }));
|
|
403
|
+
}, placeholder: "Type a message...", backgroundColor: "canvas.subtle", frontendTools: _tools, showModelSelector: showModelSelector, availableModels: availableModels, showToolsMenu: showToolsMenu, showSkillsMenu: showSkillsMenu, showTokenUsage: showTokenUsage, runtimeId: runtimeId, historyEndpoint: historyEndpoint, historyAuthToken: historyAuthToken, ...panelProps, children: children }) })] }));
|
|
397
404
|
}
|
|
398
405
|
export default ChatFloating;
|
|
@@ -382,7 +382,7 @@ export function ChatPopupStandalone({ onSendMessage, title = 'Chat', description
|
|
|
382
382
|
border: '1px solid',
|
|
383
383
|
borderColor: 'border.default',
|
|
384
384
|
borderRadius: isMobile ? 0 : '12px',
|
|
385
|
-
boxShadow: '
|
|
385
|
+
boxShadow: 'shadow.extra-large',
|
|
386
386
|
overflow: 'hidden',
|
|
387
387
|
transform: getAnimationTransform(isOpen),
|
|
388
388
|
opacity: isOpen ? 1 : 0,
|
|
@@ -59,7 +59,7 @@ export interface ChatSidebarProps {
|
|
|
59
59
|
/**
|
|
60
60
|
* Handler for sending messages.
|
|
61
61
|
* When provided, this is used instead of protocol mode.
|
|
62
|
-
* Signature: (message, messages, options?) => Promise<string | void
|
|
62
|
+
* Signature: `(message, messages, options?) => Promise<string | void>`
|
|
63
63
|
*/
|
|
64
64
|
onSendMessage?: MessageHandler;
|
|
65
65
|
/** Enable streaming mode (default: true) */
|
|
@@ -19,7 +19,7 @@ export interface ChatStandaloneProps {
|
|
|
19
19
|
/**
|
|
20
20
|
* Handler for sending messages - REQUIRED.
|
|
21
21
|
* This function will be called when the user sends a message.
|
|
22
|
-
* Signature: (message, messages, options?) => Promise<string | void
|
|
22
|
+
* Signature: `(message, messages, options?) => Promise<string | void>`
|
|
23
23
|
* - message: The user's message text
|
|
24
24
|
* - messages: All messages in the conversation (including the new user message)
|
|
25
25
|
* - options: Streaming callbacks (onChunk, onComplete, onError, signal)
|
|
@@ -292,7 +292,7 @@ export function ChatStandalone({ onSendMessage, title = 'Chat', description = 'S
|
|
|
292
292
|
border: '1px solid',
|
|
293
293
|
borderColor: 'border.default',
|
|
294
294
|
borderRadius: isMobile ? 0 : '12px',
|
|
295
|
-
boxShadow: '
|
|
295
|
+
boxShadow: 'shadow.extra-large',
|
|
296
296
|
overflow: 'hidden',
|
|
297
297
|
transform: getAnimationTransform(isOpen),
|
|
298
298
|
opacity: isOpen ? 1 : 0,
|
|
@@ -14,6 +14,54 @@ interface Distribution {
|
|
|
14
14
|
value: number;
|
|
15
15
|
children: DistributionChild[];
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Tool snapshot
|
|
19
|
+
*/
|
|
20
|
+
interface ToolSnapshot {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string | null;
|
|
23
|
+
parametersTokens: number;
|
|
24
|
+
totalTokens: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Message snapshot
|
|
28
|
+
*/
|
|
29
|
+
interface MessageSnapshot {
|
|
30
|
+
role: string;
|
|
31
|
+
content: string;
|
|
32
|
+
estimatedTokens: number;
|
|
33
|
+
timestamp: string | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Request usage snapshot
|
|
37
|
+
*/
|
|
38
|
+
interface RequestUsageSnapshot {
|
|
39
|
+
requestNum: number;
|
|
40
|
+
inputTokens: number;
|
|
41
|
+
outputTokens: number;
|
|
42
|
+
toolNames: string[];
|
|
43
|
+
timestamp: string | null;
|
|
44
|
+
turnId: string | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Turn usage
|
|
48
|
+
*/
|
|
49
|
+
interface TurnUsage {
|
|
50
|
+
inputTokens: number;
|
|
51
|
+
outputTokens: number;
|
|
52
|
+
requests: number;
|
|
53
|
+
toolCalls: number;
|
|
54
|
+
toolNames: string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Session usage
|
|
58
|
+
*/
|
|
59
|
+
interface SessionUsage {
|
|
60
|
+
inputTokens: number;
|
|
61
|
+
outputTokens: number;
|
|
62
|
+
requests: number;
|
|
63
|
+
toolCalls: number;
|
|
64
|
+
}
|
|
17
65
|
/**
|
|
18
66
|
* Context snapshot response from API
|
|
19
67
|
*/
|
|
@@ -21,16 +69,32 @@ export interface ContextSnapshotResponse {
|
|
|
21
69
|
agentId: string;
|
|
22
70
|
systemPrompts: string[];
|
|
23
71
|
systemPromptTokens: number;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
72
|
+
tools: ToolSnapshot[];
|
|
73
|
+
toolTokens: number;
|
|
74
|
+
historyToolCallTokens: number;
|
|
75
|
+
historyToolReturnTokens: number;
|
|
76
|
+
currentToolCallTokens: number;
|
|
77
|
+
currentToolReturnTokens: number;
|
|
78
|
+
toolCallTokens: number;
|
|
79
|
+
toolReturnTokens: number;
|
|
80
|
+
messages: MessageSnapshot[];
|
|
81
|
+
historyUserTokens: number;
|
|
82
|
+
historyAssistantTokens: number;
|
|
83
|
+
currentUserTokens: number;
|
|
84
|
+
currentAssistantTokens: number;
|
|
85
|
+
historyTokens: number;
|
|
86
|
+
currentMessageTokens: number;
|
|
30
87
|
userMessageTokens: number;
|
|
31
88
|
assistantMessageTokens: number;
|
|
32
89
|
totalTokens: number;
|
|
90
|
+
modelInputTokens: number | null;
|
|
91
|
+
modelOutputTokens: number | null;
|
|
92
|
+
sumResponseInputTokens: number;
|
|
93
|
+
sumResponseOutputTokens: number;
|
|
94
|
+
perRequestUsage: RequestUsageSnapshot[];
|
|
33
95
|
contextWindow: number;
|
|
96
|
+
turnUsage: TurnUsage | null;
|
|
97
|
+
sessionUsage: SessionUsage | null;
|
|
34
98
|
distribution: Distribution;
|
|
35
99
|
error?: string;
|
|
36
100
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
3
|
// Distributed under the terms of the Modified BSD License.
|
|
4
4
|
/**
|
|
@@ -139,8 +139,15 @@ export function ContextDistribution({ agentId, height = '250px', }) {
|
|
|
139
139
|
bg: 'canvas.default',
|
|
140
140
|
fontFamily: 'mono',
|
|
141
141
|
fontSize: 0,
|
|
142
|
-
}, children: [_jsx(Text, { sx: { fontWeight: 'bold', display: 'block', mb: 2 }, children: "Context Breakdown:" }), snapshotData.systemPromptTokens > 0 && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["System Prompts: ", formatTokens(snapshotData.systemPromptTokens), ' ', "tokens"] }), snapshotData.systemPrompts.map((prompt, idx) => (_jsxs(Text, { sx: { display: 'block', ml: 3, mt: 1, color: 'fg.muted' }, children: ["\u2022", ' ', prompt.length > 100 ? prompt.slice(0, 100) + '...' : prompt] }, idx)))] })),
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
}, children: [_jsx(Text, { sx: { fontWeight: 'bold', display: 'block', mb: 2 }, children: "Context Breakdown:" }), snapshotData.systemPromptTokens > 0 && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["System Prompts: ", formatTokens(snapshotData.systemPromptTokens), ' ', "tokens"] }), snapshotData.systemPrompts.map((prompt, idx) => (_jsxs(Text, { sx: { display: 'block', ml: 3, mt: 1, color: 'fg.muted' }, children: ["\u2022", ' ', prompt.length > 100 ? prompt.slice(0, 100) + '...' : prompt] }, idx)))] })), snapshotData.toolTokens > 0 && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["Tool Definitions: ", formatTokens(snapshotData.toolTokens), " tokens (", snapshotData.tools.length, " tools)"] }), _jsxs(Box, { sx: { ml: 3, mt: 1 }, children: [snapshotData.tools.slice(0, 5).map((tool, idx) => (_jsxs(Text, { sx: { display: 'block', color: 'fg.muted' }, children: ["\u2022 ", tool.name, ": ", formatTokens(tool.totalTokens), " tokens"] }, idx))), snapshotData.tools.length > 5 && (_jsxs(Text, { sx: {
|
|
143
|
+
display: 'block',
|
|
144
|
+
color: 'fg.muted',
|
|
145
|
+
fontStyle: 'italic',
|
|
146
|
+
}, children: ["...and ", snapshotData.tools.length - 5, " more tools"] }))] })] })), (snapshotData.historyUserTokens > 0 ||
|
|
147
|
+
snapshotData.historyAssistantTokens > 0 ||
|
|
148
|
+
snapshotData.historyToolCallTokens > 0) && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["History:", ' ', formatTokens(snapshotData.historyUserTokens +
|
|
149
|
+
snapshotData.historyAssistantTokens +
|
|
150
|
+
snapshotData.historyToolCallTokens +
|
|
151
|
+
snapshotData.historyToolReturnTokens), ' ', "tokens"] }), _jsxs(Box, { sx: { ml: 3, mt: 1 }, children: [_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 User Messages:", ' ', formatTokens(snapshotData.historyUserTokens), " tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Assistant Responses:", ' ', formatTokens(snapshotData.historyAssistantTokens), " tokens"] }), snapshotData.historyToolCallTokens > 0 && (_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Tool Calls:", ' ', formatTokens(snapshotData.historyToolCallTokens), " tokens"] })), snapshotData.historyToolReturnTokens > 0 && (_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Tool Returns:", ' ', formatTokens(snapshotData.historyToolReturnTokens), " tokens"] }))] })] })), snapshotData.currentUserTokens > 0 && (_jsx(Box, { sx: { mb: 2 }, children: _jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["Current User: ", formatTokens(snapshotData.currentUserTokens), ' ', "tokens"] }) })), snapshotData.turnUsage && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsx(Text, { sx: { fontWeight: 'bold' }, children: "Turn Usage (model-reported):" }), _jsxs(Box, { sx: { ml: 3, mt: 1 }, children: [_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Input: ", formatTokens(snapshotData.turnUsage.inputTokens), ' ', "tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Output: ", formatTokens(snapshotData.turnUsage.outputTokens), ' ', "tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Requests: ", snapshotData.turnUsage.requests] }), snapshotData.turnUsage.toolCalls > 0 && (_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Tool Calls: ", snapshotData.turnUsage.toolCalls, snapshotData.turnUsage.toolNames.length > 0 && (_jsxs(_Fragment, { children: [" (", snapshotData.turnUsage.toolNames.join(', '), ")"] }))] }))] })] })), snapshotData.sessionUsage && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsx(Text, { sx: { fontWeight: 'bold' }, children: "Session Totals:" }), _jsxs(Box, { sx: { ml: 3, mt: 1 }, children: [_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Total Input:", ' ', formatTokens(snapshotData.sessionUsage.inputTokens), " tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Total Output:", ' ', formatTokens(snapshotData.sessionUsage.outputTokens), " tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Total Requests: ", snapshotData.sessionUsage.requests] }), snapshotData.sessionUsage.toolCalls > 0 && (_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Total Tool Calls: ", snapshotData.sessionUsage.toolCalls] }))] })] }))] }))] }));
|
|
145
152
|
}
|
|
146
153
|
export default ContextDistribution;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool detail from API
|
|
3
|
+
*/
|
|
4
|
+
interface ToolDetail {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string | null;
|
|
7
|
+
parametersSchema: Record<string, unknown>;
|
|
8
|
+
parametersTokens: number;
|
|
9
|
+
totalTokens: number;
|
|
10
|
+
sourceType: string;
|
|
11
|
+
isAsync: boolean;
|
|
12
|
+
requiresApproval: boolean;
|
|
13
|
+
sourceCode: string | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Message detail from API
|
|
17
|
+
*/
|
|
18
|
+
interface MessageDetail {
|
|
19
|
+
role: string;
|
|
20
|
+
content: string;
|
|
21
|
+
estimatedTokens: number;
|
|
22
|
+
timestamp: string | null;
|
|
23
|
+
inContext: boolean;
|
|
24
|
+
toolName: string | null;
|
|
25
|
+
toolCallId: string | null;
|
|
26
|
+
isToolCall: boolean;
|
|
27
|
+
isToolResult: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* System prompt from API
|
|
31
|
+
*/
|
|
32
|
+
interface SystemPrompt {
|
|
33
|
+
content: string;
|
|
34
|
+
tokens: number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Token summary from API
|
|
38
|
+
*/
|
|
39
|
+
interface TokenSummary {
|
|
40
|
+
systemPrompts: number;
|
|
41
|
+
tools: number;
|
|
42
|
+
memory: number;
|
|
43
|
+
history: number;
|
|
44
|
+
current: number;
|
|
45
|
+
total: number;
|
|
46
|
+
contextWindow: number;
|
|
47
|
+
usagePercent: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Full context response from API
|
|
51
|
+
*/
|
|
52
|
+
export interface FullContextResponse {
|
|
53
|
+
agentId: string;
|
|
54
|
+
modelConfiguration: {
|
|
55
|
+
modelName: string | null;
|
|
56
|
+
contextWindow: number;
|
|
57
|
+
settings: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
systemPrompts: SystemPrompt[];
|
|
60
|
+
systemPromptTokens: number;
|
|
61
|
+
tools: ToolDetail[];
|
|
62
|
+
toolTokens: number;
|
|
63
|
+
messages: MessageDetail[];
|
|
64
|
+
memoryBlocks: Record<string, unknown>[];
|
|
65
|
+
memoryTokens: number;
|
|
66
|
+
toolEnvironment: Record<string, string>;
|
|
67
|
+
toolRules: Record<string, unknown>[];
|
|
68
|
+
tokenSummary: TokenSummary;
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface ContextInspectorProps {
|
|
72
|
+
/** Agent ID for fetching full context */
|
|
73
|
+
agentId: string;
|
|
74
|
+
/** API base URL for fetching context data */
|
|
75
|
+
apiBase?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* ContextInspector component displays full detailed context snapshot.
|
|
79
|
+
*/
|
|
80
|
+
export declare function ContextInspector({ agentId, apiBase }: ContextInspectorProps): import("react/jsx-runtime").JSX.Element;
|
|
81
|
+
export default ContextInspector;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
// Distributed under the terms of the Modified BSD License.
|
|
4
|
+
/**
|
|
5
|
+
* ContextInspector component - Shows detailed context snapshot with full tool schemas,
|
|
6
|
+
* message history with in_context flags, and model configuration.
|
|
7
|
+
*/
|
|
8
|
+
import { Text, Spinner, Button, Label, ProgressBar } from '@primer/react';
|
|
9
|
+
import { Box } from '@datalayer/primer-addons';
|
|
10
|
+
import { AiModelIcon, TerminalIcon, CommentDiscussionIcon, DatabaseIcon, KeyIcon, CodeIcon, CheckCircleIcon, XCircleIcon, ChevronDownIcon, ChevronRightIcon, InfoIcon, } from '@primer/octicons-react';
|
|
11
|
+
import { useQuery } from '@tanstack/react-query';
|
|
12
|
+
import React, { useState, useMemo } from 'react';
|
|
13
|
+
/**
|
|
14
|
+
* Get the API base URL for fetching context data.
|
|
15
|
+
* If apiBase prop is provided, use it.
|
|
16
|
+
* Otherwise, fall back to localhost for local development.
|
|
17
|
+
*/
|
|
18
|
+
function getApiBase(apiBase) {
|
|
19
|
+
if (apiBase) {
|
|
20
|
+
return apiBase;
|
|
21
|
+
}
|
|
22
|
+
if (typeof window === 'undefined') {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
const host = window.location.hostname;
|
|
26
|
+
return host === 'localhost' || host === '127.0.0.1'
|
|
27
|
+
? 'http://127.0.0.1:8765'
|
|
28
|
+
: '';
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Format token count for display
|
|
32
|
+
*/
|
|
33
|
+
function formatTokens(tokens) {
|
|
34
|
+
if (tokens >= 1000000) {
|
|
35
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
36
|
+
}
|
|
37
|
+
if (tokens >= 1000) {
|
|
38
|
+
return `${(tokens / 1000).toFixed(1)}K`;
|
|
39
|
+
}
|
|
40
|
+
return tokens.toString();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Collapsible section component
|
|
44
|
+
*/
|
|
45
|
+
function CollapsibleSection({ title, icon, count, tokens, defaultExpanded = false, children, }) {
|
|
46
|
+
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
47
|
+
return (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Box, { as: "button", onClick: () => setExpanded(!expanded), sx: {
|
|
48
|
+
display: 'flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap: 2,
|
|
51
|
+
width: '100%',
|
|
52
|
+
p: 2,
|
|
53
|
+
bg: 'canvas.subtle',
|
|
54
|
+
border: '1px solid',
|
|
55
|
+
borderColor: 'border.default',
|
|
56
|
+
borderRadius: 2,
|
|
57
|
+
cursor: 'pointer',
|
|
58
|
+
'&:hover': {
|
|
59
|
+
bg: 'canvas.inset',
|
|
60
|
+
},
|
|
61
|
+
}, children: [expanded ? (_jsx(ChevronDownIcon, { size: 16 })) : (_jsx(ChevronRightIcon, { size: 16 })), React.createElement(icon, { size: 16 }), _jsx(Text, { sx: { fontWeight: 'semibold', flex: 1, textAlign: 'left' }, children: title }), count !== undefined && (_jsx(Label, { variant: "secondary", size: "small", children: count })), tokens !== undefined && tokens > 0 && (_jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [formatTokens(tokens), " tokens"] }))] }), expanded && (_jsx(Box, { sx: {
|
|
62
|
+
border: '1px solid',
|
|
63
|
+
borderColor: 'border.default',
|
|
64
|
+
borderTop: 'none',
|
|
65
|
+
borderRadius: '0 0 6px 6px',
|
|
66
|
+
p: 2,
|
|
67
|
+
}, children: children }))] }));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Tool detail view component
|
|
71
|
+
*/
|
|
72
|
+
function ToolDetailView({ tool }) {
|
|
73
|
+
const [showSchema, setShowSchema] = useState(false);
|
|
74
|
+
const [showSource, setShowSource] = useState(false);
|
|
75
|
+
return (_jsxs(Box, { sx: {
|
|
76
|
+
p: 2,
|
|
77
|
+
mb: 2,
|
|
78
|
+
bg: 'canvas.default',
|
|
79
|
+
border: '1px solid',
|
|
80
|
+
borderColor: 'border.muted',
|
|
81
|
+
borderRadius: 2,
|
|
82
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 1 }, children: [_jsx(Text, { sx: { fontWeight: 'bold', fontFamily: 'mono', fontSize: 1 }, children: tool.name }), _jsx(Label, { size: "small", variant: "secondary", children: tool.sourceType }), tool.isAsync && (_jsx(Label, { size: "small", variant: "accent", children: "async" })), tool.requiresApproval && (_jsx(Label, { size: "small", variant: "attention", children: "requires approval" })), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted', ml: 'auto' }, children: [formatTokens(tool.totalTokens), " tokens"] })] }), tool.description && (_jsx(Text, { sx: { fontSize: 1, color: 'fg.muted', display: 'block', mb: 2 }, children: tool.description })), _jsxs(Box, { sx: { display: 'flex', gap: 2 }, children: [_jsxs(Button, { size: "small", variant: "invisible", onClick: () => setShowSchema(!showSchema), children: [showSchema ? 'Hide' : 'Show', " Schema"] }), tool.sourceCode && (_jsxs(Button, { size: "small", variant: "invisible", onClick: () => setShowSource(!showSource), children: [showSource ? 'Hide' : 'Show', " Source"] }))] }), showSchema && (_jsx(Box, { as: "pre", sx: {
|
|
83
|
+
mt: 2,
|
|
84
|
+
p: 2,
|
|
85
|
+
bg: 'canvas.inset',
|
|
86
|
+
borderRadius: 2,
|
|
87
|
+
fontSize: 0,
|
|
88
|
+
overflow: 'auto',
|
|
89
|
+
maxHeight: 200,
|
|
90
|
+
}, children: JSON.stringify(tool.parametersSchema, null, 2) })), showSource && tool.sourceCode && (_jsx(Box, { as: "pre", sx: {
|
|
91
|
+
mt: 2,
|
|
92
|
+
p: 2,
|
|
93
|
+
bg: 'canvas.inset',
|
|
94
|
+
borderRadius: 2,
|
|
95
|
+
fontSize: 0,
|
|
96
|
+
overflow: 'auto',
|
|
97
|
+
maxHeight: 300,
|
|
98
|
+
}, children: tool.sourceCode }))] }));
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Message detail view component
|
|
102
|
+
*/
|
|
103
|
+
function MessageDetailView({ message }) {
|
|
104
|
+
const roleColors = {
|
|
105
|
+
user: 'accent.fg',
|
|
106
|
+
assistant: 'success.fg',
|
|
107
|
+
system: 'attention.fg',
|
|
108
|
+
tool: 'done.fg',
|
|
109
|
+
};
|
|
110
|
+
const roleIcons = {
|
|
111
|
+
user: CommentDiscussionIcon,
|
|
112
|
+
assistant: AiModelIcon,
|
|
113
|
+
system: InfoIcon,
|
|
114
|
+
tool: TerminalIcon,
|
|
115
|
+
};
|
|
116
|
+
const RoleIcon = roleIcons[message.role] || CommentDiscussionIcon;
|
|
117
|
+
return (_jsxs(Box, { sx: {
|
|
118
|
+
p: 2,
|
|
119
|
+
mb: 1,
|
|
120
|
+
bg: message.inContext ? 'canvas.default' : 'canvas.inset',
|
|
121
|
+
border: '1px solid',
|
|
122
|
+
borderColor: message.inContext ? 'border.default' : 'border.muted',
|
|
123
|
+
borderRadius: 2,
|
|
124
|
+
opacity: message.inContext ? 1 : 0.7,
|
|
125
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 2, mb: 1 }, children: [_jsx(RoleIcon, { size: 14 }), _jsx(Text, { sx: {
|
|
126
|
+
fontWeight: 'semibold',
|
|
127
|
+
fontSize: 0,
|
|
128
|
+
color: roleColors[message.role] || 'fg.default',
|
|
129
|
+
textTransform: 'capitalize',
|
|
130
|
+
}, children: message.role }), message.toolName && (_jsx(Label, { size: "small", variant: "secondary", children: message.toolName })), message.isToolCall && (_jsx(Label, { size: "small", variant: "accent", children: "call" })), message.isToolResult && (_jsx(Label, { size: "small", variant: "success", children: "result" })), message.inContext ? (_jsx(CheckCircleIcon, { size: 12, fill: "var(--fgColor-success)" })) : (_jsx(XCircleIcon, { size: 12, fill: "var(--fgColor-muted)" })), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted', ml: 'auto' }, children: [formatTokens(message.estimatedTokens), " tokens"] })] }), _jsx(Text, { sx: {
|
|
131
|
+
fontSize: 0,
|
|
132
|
+
fontFamily: 'mono',
|
|
133
|
+
display: 'block',
|
|
134
|
+
whiteSpace: 'pre-wrap',
|
|
135
|
+
wordBreak: 'break-word',
|
|
136
|
+
maxHeight: 100,
|
|
137
|
+
overflow: 'auto',
|
|
138
|
+
}, children: message.content.length > 500
|
|
139
|
+
? message.content.slice(0, 500) + '...'
|
|
140
|
+
: message.content })] }));
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* ContextInspector component displays full detailed context snapshot.
|
|
144
|
+
*/
|
|
145
|
+
export function ContextInspector({ agentId, apiBase }) {
|
|
146
|
+
const { data: contextData, isLoading, error, } = useQuery({
|
|
147
|
+
queryKey: ['full-context', agentId, apiBase],
|
|
148
|
+
queryFn: async () => {
|
|
149
|
+
const base = getApiBase(apiBase);
|
|
150
|
+
const response = await fetch(`${base}/api/v1/configure/agents/${encodeURIComponent(agentId)}/full-context`);
|
|
151
|
+
if (!response.ok) {
|
|
152
|
+
throw new Error('Failed to fetch full context');
|
|
153
|
+
}
|
|
154
|
+
return response.json();
|
|
155
|
+
},
|
|
156
|
+
refetchInterval: 30000, // Refresh every 30 seconds (less frequent than snapshot)
|
|
157
|
+
refetchOnMount: 'always',
|
|
158
|
+
staleTime: 0,
|
|
159
|
+
});
|
|
160
|
+
// Separate messages by in_context status
|
|
161
|
+
const { inContextMessages, outOfContextMessages } = useMemo(() => {
|
|
162
|
+
if (!contextData?.messages) {
|
|
163
|
+
return { inContextMessages: [], outOfContextMessages: [] };
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
inContextMessages: contextData.messages.filter(m => m.inContext),
|
|
167
|
+
outOfContextMessages: contextData.messages.filter(m => !m.inContext),
|
|
168
|
+
};
|
|
169
|
+
}, [contextData?.messages]);
|
|
170
|
+
if (isLoading) {
|
|
171
|
+
return (_jsxs(Box, { sx: {
|
|
172
|
+
p: 3,
|
|
173
|
+
display: 'flex',
|
|
174
|
+
alignItems: 'center',
|
|
175
|
+
justifyContent: 'center',
|
|
176
|
+
}, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { ml: 2, color: 'fg.muted' }, children: "Loading full context snapshot..." })] }));
|
|
177
|
+
}
|
|
178
|
+
if (error || !contextData) {
|
|
179
|
+
return (_jsx(Box, { sx: {
|
|
180
|
+
p: 3,
|
|
181
|
+
bg: 'danger.subtle',
|
|
182
|
+
borderRadius: 2,
|
|
183
|
+
border: '1px solid',
|
|
184
|
+
borderColor: 'danger.muted',
|
|
185
|
+
}, children: _jsx(Text, { sx: { color: 'danger.fg' }, children: "Failed to load context snapshot" }) }));
|
|
186
|
+
}
|
|
187
|
+
if (contextData.error) {
|
|
188
|
+
return (_jsx(Box, { sx: {
|
|
189
|
+
p: 3,
|
|
190
|
+
bg: 'attention.subtle',
|
|
191
|
+
borderRadius: 2,
|
|
192
|
+
border: '1px solid',
|
|
193
|
+
borderColor: 'attention.muted',
|
|
194
|
+
}, children: _jsx(Text, { sx: { color: 'attention.fg' }, children: contextData.error }) }));
|
|
195
|
+
}
|
|
196
|
+
const { tokenSummary, modelConfiguration } = contextData;
|
|
197
|
+
return (_jsxs(Box, { children: [_jsxs(Box, { sx: { mb: 3 }, children: [_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', mb: 1 }, children: [_jsxs(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: ["Context Usage: ", formatTokens(tokenSummary.total), " /", ' ', formatTokens(tokenSummary.contextWindow)] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: [tokenSummary.usagePercent.toFixed(1), "%"] })] }), _jsx(ProgressBar, { progress: tokenSummary.usagePercent, sx: { height: 8 }, bg: tokenSummary.usagePercent > 80
|
|
198
|
+
? 'danger.emphasis'
|
|
199
|
+
: 'accent.emphasis' }), _jsxs(Box, { sx: {
|
|
200
|
+
display: 'flex',
|
|
201
|
+
gap: 3,
|
|
202
|
+
mt: 2,
|
|
203
|
+
flexWrap: 'wrap',
|
|
204
|
+
fontSize: 0,
|
|
205
|
+
color: 'fg.muted',
|
|
206
|
+
}, children: [_jsxs(Text, { children: ["System: ", formatTokens(tokenSummary.systemPrompts)] }), _jsxs(Text, { children: ["Tools: ", formatTokens(tokenSummary.tools)] }), tokenSummary.memory > 0 && (_jsxs(Text, { children: ["Memory: ", formatTokens(tokenSummary.memory)] })), _jsxs(Text, { children: ["History: ", formatTokens(tokenSummary.history)] }), _jsxs(Text, { children: ["Current: ", formatTokens(tokenSummary.current)] })] })] }), _jsx(CollapsibleSection, { title: "Model Configuration", icon: AiModelIcon, defaultExpanded: true, children: _jsxs(Box, { sx: { display: 'grid', gridTemplateColumns: '1fr 2fr', gap: 2 }, children: [_jsx(Text, { sx: { fontWeight: 'semibold', fontSize: 1 }, children: "Model:" }), _jsx(Text, { sx: { fontSize: 1, fontFamily: 'mono' }, children: modelConfiguration.modelName || 'Not specified' }), _jsx(Text, { sx: { fontWeight: 'semibold', fontSize: 1 }, children: "Context Window:" }), _jsxs(Text, { sx: { fontSize: 1 }, children: [formatTokens(modelConfiguration.contextWindow), " tokens"] }), Object.keys(modelConfiguration.settings).length > 0 && (_jsxs(_Fragment, { children: [_jsx(Text, { sx: { fontWeight: 'semibold', fontSize: 1 }, children: "Settings:" }), _jsx(Box, { as: "pre", sx: {
|
|
207
|
+
fontSize: 0,
|
|
208
|
+
p: 2,
|
|
209
|
+
bg: 'canvas.inset',
|
|
210
|
+
borderRadius: 2,
|
|
211
|
+
overflow: 'auto',
|
|
212
|
+
}, children: JSON.stringify(modelConfiguration.settings, null, 2) })] }))] }) }), _jsx(CollapsibleSection, { title: "System Prompts", icon: InfoIcon, count: contextData.systemPrompts.length, tokens: contextData.systemPromptTokens, children: contextData.systemPrompts.length === 0 ? (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "No system prompts configured" })) : (contextData.systemPrompts.map((prompt, idx) => (_jsxs(Box, { sx: {
|
|
213
|
+
p: 2,
|
|
214
|
+
mb: 2,
|
|
215
|
+
bg: 'canvas.inset',
|
|
216
|
+
borderRadius: 2,
|
|
217
|
+
border: '1px solid',
|
|
218
|
+
borderColor: 'border.muted',
|
|
219
|
+
}, children: [_jsxs(Box, { sx: {
|
|
220
|
+
display: 'flex',
|
|
221
|
+
justifyContent: 'space-between',
|
|
222
|
+
mb: 1,
|
|
223
|
+
}, children: [_jsxs(Text, { sx: { fontWeight: 'semibold', fontSize: 0 }, children: ["Prompt ", idx + 1] }), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [formatTokens(prompt.tokens), " tokens"] })] }), _jsx(Text, { as: "pre", sx: {
|
|
224
|
+
fontSize: 0,
|
|
225
|
+
whiteSpace: 'pre-wrap',
|
|
226
|
+
wordBreak: 'break-word',
|
|
227
|
+
maxHeight: 200,
|
|
228
|
+
overflow: 'auto',
|
|
229
|
+
}, children: prompt.content })] }, idx)))) }), _jsx(CollapsibleSection, { title: "Tools", icon: TerminalIcon, count: contextData.tools.length, tokens: contextData.toolTokens, children: contextData.tools.length === 0 ? (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "No tools configured" })) : (contextData.tools.map((tool, idx) => (_jsx(ToolDetailView, { tool: tool }, idx)))) }), _jsx(CollapsibleSection, { title: "Message History", icon: CommentDiscussionIcon, count: contextData.messages.length, children: contextData.messages.length === 0 ? (_jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "No messages yet" })) : (_jsxs(_Fragment, { children: [outOfContextMessages.length > 0 && (_jsxs(Box, { sx: { mb: 3 }, children: [_jsxs(Text, { sx: {
|
|
230
|
+
fontWeight: 'semibold',
|
|
231
|
+
fontSize: 1,
|
|
232
|
+
color: 'fg.muted',
|
|
233
|
+
mb: 2,
|
|
234
|
+
display: 'block',
|
|
235
|
+
}, children: ["Out of Context (", outOfContextMessages.length, ")"] }), outOfContextMessages.map((msg, idx) => (_jsx(MessageDetailView, { message: msg }, `out-${idx}`)))] })), inContextMessages.length > 0 && (_jsxs(Box, { children: [_jsxs(Text, { sx: {
|
|
236
|
+
fontWeight: 'semibold',
|
|
237
|
+
fontSize: 1,
|
|
238
|
+
color: 'success.fg',
|
|
239
|
+
mb: 2,
|
|
240
|
+
display: 'block',
|
|
241
|
+
}, children: ["In Context (", inContextMessages.length, ")"] }), inContextMessages.map((msg, idx) => (_jsx(MessageDetailView, { message: msg }, `in-${idx}`)))] }))] })) }), contextData.memoryBlocks.length > 0 && (_jsx(CollapsibleSection, { title: "Memory Blocks", icon: DatabaseIcon, count: contextData.memoryBlocks.length, tokens: contextData.memoryTokens, children: contextData.memoryBlocks.map((block, idx) => (_jsx(Box, { as: "pre", sx: {
|
|
242
|
+
p: 2,
|
|
243
|
+
mb: 2,
|
|
244
|
+
bg: 'canvas.inset',
|
|
245
|
+
borderRadius: 2,
|
|
246
|
+
fontSize: 0,
|
|
247
|
+
overflow: 'auto',
|
|
248
|
+
}, children: JSON.stringify(block, null, 2) }, idx))) })), Object.keys(contextData.toolEnvironment).length > 0 && (_jsx(CollapsibleSection, { title: "Tool Environment", icon: KeyIcon, count: Object.keys(contextData.toolEnvironment).length, children: _jsx(Box, { sx: { display: 'grid', gridTemplateColumns: '1fr 2fr', gap: 2 }, children: Object.entries(contextData.toolEnvironment).map(([key, value]) => (_jsxs(React.Fragment, { children: [_jsx(Text, { sx: {
|
|
249
|
+
fontFamily: 'mono',
|
|
250
|
+
fontSize: 1,
|
|
251
|
+
fontWeight: 'semibold',
|
|
252
|
+
}, children: key }), _jsx(Text, { sx: { fontFamily: 'mono', fontSize: 1, color: 'fg.muted' }, children: value })] }, key))) }) })), contextData.toolRules.length > 0 && (_jsx(CollapsibleSection, { title: "Tool Rules", icon: CodeIcon, count: contextData.toolRules.length, children: contextData.toolRules.map((rule, idx) => (_jsx(Box, { as: "pre", sx: {
|
|
253
|
+
p: 2,
|
|
254
|
+
mb: 2,
|
|
255
|
+
bg: 'canvas.inset',
|
|
256
|
+
borderRadius: 2,
|
|
257
|
+
fontSize: 0,
|
|
258
|
+
overflow: 'auto',
|
|
259
|
+
}, children: JSON.stringify(rule, null, 2) }, idx))) }))] }));
|
|
260
|
+
}
|
|
261
|
+
export default ContextInspector;
|