@datalayer/agent-runtimes 0.0.8 → 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 +32 -0
- 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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Distribution child item for treemap
|
|
3
|
+
*/
|
|
4
|
+
interface DistributionChild {
|
|
5
|
+
name: string;
|
|
6
|
+
value: number;
|
|
7
|
+
children?: DistributionChild[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Distribution data for treemap
|
|
11
|
+
*/
|
|
12
|
+
interface Distribution {
|
|
13
|
+
name: string;
|
|
14
|
+
value: number;
|
|
15
|
+
children: DistributionChild[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Request usage snapshot - historic per-request data
|
|
19
|
+
*/
|
|
20
|
+
interface RequestUsageSnapshot {
|
|
21
|
+
requestNum: number;
|
|
22
|
+
inputTokens: number;
|
|
23
|
+
outputTokens: number;
|
|
24
|
+
toolNames: string[];
|
|
25
|
+
timestamp: string | null;
|
|
26
|
+
turnId: string | null;
|
|
27
|
+
durationMs: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Tool snapshot
|
|
31
|
+
*/
|
|
32
|
+
interface ToolSnapshot {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string | null;
|
|
35
|
+
parametersTokens: number;
|
|
36
|
+
totalTokens: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Turn usage
|
|
40
|
+
*/
|
|
41
|
+
interface TurnUsage {
|
|
42
|
+
inputTokens: number;
|
|
43
|
+
outputTokens: number;
|
|
44
|
+
requests: number;
|
|
45
|
+
toolCalls: number;
|
|
46
|
+
toolNames: string[];
|
|
47
|
+
durationSeconds: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Session usage
|
|
51
|
+
*/
|
|
52
|
+
interface SessionUsage {
|
|
53
|
+
inputTokens: number;
|
|
54
|
+
outputTokens: number;
|
|
55
|
+
requests: number;
|
|
56
|
+
toolCalls: number;
|
|
57
|
+
turns: number;
|
|
58
|
+
durationSeconds: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Context snapshot response from API
|
|
62
|
+
*/
|
|
63
|
+
export interface ContextSnapshotResponse {
|
|
64
|
+
agentId: string;
|
|
65
|
+
systemPrompts: string[];
|
|
66
|
+
systemPromptTokens: number;
|
|
67
|
+
tools: ToolSnapshot[];
|
|
68
|
+
toolTokens: number;
|
|
69
|
+
historyToolCallTokens: number;
|
|
70
|
+
historyToolReturnTokens: number;
|
|
71
|
+
currentToolCallTokens: number;
|
|
72
|
+
currentToolReturnTokens: number;
|
|
73
|
+
toolCallTokens: number;
|
|
74
|
+
toolReturnTokens: number;
|
|
75
|
+
historyUserTokens: number;
|
|
76
|
+
historyAssistantTokens: number;
|
|
77
|
+
currentUserTokens: number;
|
|
78
|
+
currentAssistantTokens: number;
|
|
79
|
+
historyTokens: number;
|
|
80
|
+
currentMessageTokens: number;
|
|
81
|
+
userMessageTokens: number;
|
|
82
|
+
assistantMessageTokens: number;
|
|
83
|
+
totalTokens: number;
|
|
84
|
+
modelInputTokens: number | null;
|
|
85
|
+
modelOutputTokens: number | null;
|
|
86
|
+
sumResponseInputTokens: number;
|
|
87
|
+
sumResponseOutputTokens: number;
|
|
88
|
+
perRequestUsage: RequestUsageSnapshot[];
|
|
89
|
+
contextWindow: number;
|
|
90
|
+
turnUsage: TurnUsage | null;
|
|
91
|
+
sessionUsage: SessionUsage | null;
|
|
92
|
+
distribution: Distribution;
|
|
93
|
+
error?: string;
|
|
94
|
+
}
|
|
95
|
+
type ViewMode = 'overview' | 'distribution' | 'history';
|
|
96
|
+
export interface ContextPanelProps {
|
|
97
|
+
/** Agent ID for fetching context details (required) */
|
|
98
|
+
agentId: string;
|
|
99
|
+
/** API base URL for fetching context data */
|
|
100
|
+
apiBase?: string;
|
|
101
|
+
/** Number of messages in conversation (from chat store) */
|
|
102
|
+
messageCount?: number;
|
|
103
|
+
/** Default view mode */
|
|
104
|
+
defaultView?: ViewMode;
|
|
105
|
+
/** Height for charts */
|
|
106
|
+
chartHeight?: string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* ContextPanel component - unified context usage display.
|
|
110
|
+
*/
|
|
111
|
+
export declare function ContextPanel({ agentId, apiBase, messageCount, defaultView, chartHeight, }: ContextPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
112
|
+
export default ContextPanel;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Copyright (c) 2025-2026 Datalayer, Inc.
|
|
3
|
+
// Distributed under the terms of the Modified BSD License.
|
|
4
|
+
/**
|
|
5
|
+
* ContextPanel component - Unified context usage display with:
|
|
6
|
+
* - Cumulative usage with progress bar
|
|
7
|
+
* - Token distribution treemap
|
|
8
|
+
* - Historic usage time-series chart
|
|
9
|
+
*/
|
|
10
|
+
import { CommentDiscussionIcon, DatabaseIcon, FileIcon, ToolsIcon, ClockIcon, GraphIcon, ListUnorderedIcon, } from '@primer/octicons-react';
|
|
11
|
+
import { Heading, Text, ProgressBar, Spinner, Button, SegmentedControl, } from '@primer/react';
|
|
12
|
+
import { Box } from '@datalayer/primer-addons';
|
|
13
|
+
import { useQuery } from '@tanstack/react-query';
|
|
14
|
+
import ReactECharts from 'echarts-for-react';
|
|
15
|
+
import { useState, useMemo } from 'react';
|
|
16
|
+
/**
|
|
17
|
+
* Format token count for display
|
|
18
|
+
*/
|
|
19
|
+
function formatTokens(tokens) {
|
|
20
|
+
if (tokens >= 1000000) {
|
|
21
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
22
|
+
}
|
|
23
|
+
if (tokens >= 1000) {
|
|
24
|
+
return `${(tokens / 1000).toFixed(1)}K`;
|
|
25
|
+
}
|
|
26
|
+
return tokens.toString();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Format duration
|
|
30
|
+
*/
|
|
31
|
+
function formatDuration(seconds) {
|
|
32
|
+
if (seconds < 1) {
|
|
33
|
+
return `${Math.round(seconds * 1000)}ms`;
|
|
34
|
+
}
|
|
35
|
+
if (seconds < 60) {
|
|
36
|
+
return `${seconds.toFixed(1)}s`;
|
|
37
|
+
}
|
|
38
|
+
const minutes = Math.floor(seconds / 60);
|
|
39
|
+
const secs = Math.round(seconds % 60);
|
|
40
|
+
return `${minutes}m ${secs}s`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get icon for context category
|
|
44
|
+
*/
|
|
45
|
+
function getCategoryIcon(name) {
|
|
46
|
+
switch (name.toLowerCase()) {
|
|
47
|
+
case 'messages':
|
|
48
|
+
case 'history':
|
|
49
|
+
return CommentDiscussionIcon;
|
|
50
|
+
case 'tools':
|
|
51
|
+
case 'tool definitions':
|
|
52
|
+
return ToolsIcon;
|
|
53
|
+
case 'system':
|
|
54
|
+
case 'system prompts':
|
|
55
|
+
return FileIcon;
|
|
56
|
+
case 'cache':
|
|
57
|
+
return DatabaseIcon;
|
|
58
|
+
default:
|
|
59
|
+
return ClockIcon;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the API base URL for fetching context data.
|
|
64
|
+
* If apiBase prop is provided, use it.
|
|
65
|
+
* Otherwise, fall back to localhost for local development.
|
|
66
|
+
*/
|
|
67
|
+
function getApiBase(apiBase) {
|
|
68
|
+
if (apiBase) {
|
|
69
|
+
return apiBase;
|
|
70
|
+
}
|
|
71
|
+
if (typeof window === 'undefined') {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
const host = window.location.hostname;
|
|
75
|
+
return host === 'localhost' || host === '127.0.0.1'
|
|
76
|
+
? 'http://127.0.0.1:8765'
|
|
77
|
+
: '';
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* ContextPanel component - unified context usage display.
|
|
81
|
+
*/
|
|
82
|
+
export function ContextPanel({ agentId, apiBase, messageCount = 0, defaultView = 'overview', chartHeight = '200px', }) {
|
|
83
|
+
const [viewMode, setViewMode] = useState(defaultView);
|
|
84
|
+
const [showDetails, setShowDetails] = useState(false);
|
|
85
|
+
const { data: snapshotData, isLoading, error, } = useQuery({
|
|
86
|
+
queryKey: ['context-snapshot', agentId, apiBase],
|
|
87
|
+
queryFn: async () => {
|
|
88
|
+
const base = getApiBase(apiBase);
|
|
89
|
+
const response = await fetch(`${base}/api/v1/configure/agents/${encodeURIComponent(agentId)}/context-snapshot`);
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
throw new Error('Failed to fetch context snapshot');
|
|
92
|
+
}
|
|
93
|
+
return response.json();
|
|
94
|
+
},
|
|
95
|
+
refetchInterval: 5000,
|
|
96
|
+
refetchOnMount: 'always',
|
|
97
|
+
staleTime: 0,
|
|
98
|
+
});
|
|
99
|
+
// Build historic usage chart data from perRequestUsage
|
|
100
|
+
const historyChartOption = useMemo(() => {
|
|
101
|
+
if (!snapshotData?.perRequestUsage ||
|
|
102
|
+
snapshotData.perRequestUsage.length === 0) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const requests = snapshotData.perRequestUsage;
|
|
106
|
+
// Calculate cumulative tokens over time
|
|
107
|
+
let cumulativeInput = 0;
|
|
108
|
+
let cumulativeOutput = 0;
|
|
109
|
+
const xAxisData = [];
|
|
110
|
+
const inputData = [];
|
|
111
|
+
const outputData = [];
|
|
112
|
+
const totalData = [];
|
|
113
|
+
requests.forEach(req => {
|
|
114
|
+
cumulativeInput += req.inputTokens;
|
|
115
|
+
cumulativeOutput += req.outputTokens;
|
|
116
|
+
xAxisData.push(`#${req.requestNum}`);
|
|
117
|
+
inputData.push(cumulativeInput);
|
|
118
|
+
outputData.push(cumulativeOutput);
|
|
119
|
+
totalData.push(cumulativeInput + cumulativeOutput);
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
tooltip: {
|
|
123
|
+
trigger: 'axis',
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
formatter: (params) => {
|
|
126
|
+
const reqNum = params[0]?.axisValue || '';
|
|
127
|
+
let result = `<strong>${reqNum}</strong><br/>`;
|
|
128
|
+
params.forEach(p => {
|
|
129
|
+
result += `${p.marker} ${p.seriesName}: ${formatTokens(p.value)}<br/>`;
|
|
130
|
+
});
|
|
131
|
+
return result;
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
legend: {
|
|
135
|
+
data: ['Input', 'Output', 'Total'],
|
|
136
|
+
bottom: 0,
|
|
137
|
+
textStyle: { fontSize: 10 },
|
|
138
|
+
},
|
|
139
|
+
grid: {
|
|
140
|
+
left: 45,
|
|
141
|
+
right: 15,
|
|
142
|
+
top: 10,
|
|
143
|
+
bottom: 35,
|
|
144
|
+
},
|
|
145
|
+
xAxis: {
|
|
146
|
+
type: 'category',
|
|
147
|
+
data: xAxisData,
|
|
148
|
+
axisLabel: { fontSize: 10 },
|
|
149
|
+
},
|
|
150
|
+
yAxis: {
|
|
151
|
+
type: 'value',
|
|
152
|
+
axisLabel: {
|
|
153
|
+
fontSize: 10,
|
|
154
|
+
formatter: (value) => formatTokens(value),
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
series: [
|
|
158
|
+
{
|
|
159
|
+
name: 'Input',
|
|
160
|
+
type: 'line',
|
|
161
|
+
data: inputData,
|
|
162
|
+
smooth: true,
|
|
163
|
+
lineStyle: { width: 2 },
|
|
164
|
+
areaStyle: { opacity: 0.2 },
|
|
165
|
+
itemStyle: { color: '#3B82F6' },
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'Output',
|
|
169
|
+
type: 'line',
|
|
170
|
+
data: outputData,
|
|
171
|
+
smooth: true,
|
|
172
|
+
lineStyle: { width: 2 },
|
|
173
|
+
areaStyle: { opacity: 0.2 },
|
|
174
|
+
itemStyle: { color: '#10B981' },
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'Total',
|
|
178
|
+
type: 'line',
|
|
179
|
+
data: totalData,
|
|
180
|
+
smooth: true,
|
|
181
|
+
lineStyle: { width: 2, type: 'dashed' },
|
|
182
|
+
itemStyle: { color: '#8B5CF6' },
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
};
|
|
186
|
+
}, [snapshotData?.perRequestUsage]);
|
|
187
|
+
// Build treemap chart option
|
|
188
|
+
const treemapOption = useMemo(() => {
|
|
189
|
+
if (!snapshotData?.distribution)
|
|
190
|
+
return null;
|
|
191
|
+
const { distribution } = snapshotData;
|
|
192
|
+
const hasData = distribution.children && distribution.children.length > 0;
|
|
193
|
+
return {
|
|
194
|
+
tooltip: {
|
|
195
|
+
formatter: (info) => {
|
|
196
|
+
return `${info.name}: ${formatTokens(info.value)} tokens`;
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
series: [
|
|
200
|
+
{
|
|
201
|
+
type: 'treemap',
|
|
202
|
+
data: hasData
|
|
203
|
+
? distribution.children
|
|
204
|
+
: [{ name: 'No data', value: 1 }],
|
|
205
|
+
roam: false,
|
|
206
|
+
breadcrumb: { show: false },
|
|
207
|
+
label: {
|
|
208
|
+
show: true,
|
|
209
|
+
formatter: '{b}',
|
|
210
|
+
fontSize: 11,
|
|
211
|
+
},
|
|
212
|
+
itemStyle: {
|
|
213
|
+
borderColor: '#fff',
|
|
214
|
+
borderWidth: 2,
|
|
215
|
+
},
|
|
216
|
+
levels: [
|
|
217
|
+
{
|
|
218
|
+
itemStyle: {
|
|
219
|
+
borderColor: '#777',
|
|
220
|
+
borderWidth: 0,
|
|
221
|
+
gapWidth: 1,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
itemStyle: {
|
|
226
|
+
borderColor: '#555',
|
|
227
|
+
borderWidth: 5,
|
|
228
|
+
gapWidth: 1,
|
|
229
|
+
},
|
|
230
|
+
colorSaturation: [0.35, 0.5],
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
colorSaturation: [0.35, 0.5],
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
240
|
+
}, [snapshotData?.distribution]);
|
|
241
|
+
if (isLoading) {
|
|
242
|
+
return (_jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
243
|
+
fontSize: 1,
|
|
244
|
+
fontWeight: 'semibold',
|
|
245
|
+
mb: 2,
|
|
246
|
+
color: 'fg.muted',
|
|
247
|
+
}, children: "Context Usage" }), _jsxs(Box, { sx: {
|
|
248
|
+
p: 3,
|
|
249
|
+
bg: 'canvas.subtle',
|
|
250
|
+
borderRadius: 2,
|
|
251
|
+
border: '1px solid',
|
|
252
|
+
borderColor: 'border.default',
|
|
253
|
+
display: 'flex',
|
|
254
|
+
alignItems: 'center',
|
|
255
|
+
gap: 2,
|
|
256
|
+
}, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Loading context details..." })] })] }));
|
|
257
|
+
}
|
|
258
|
+
if (error || !snapshotData) {
|
|
259
|
+
return (_jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
260
|
+
fontSize: 1,
|
|
261
|
+
fontWeight: 'semibold',
|
|
262
|
+
mb: 2,
|
|
263
|
+
color: 'fg.muted',
|
|
264
|
+
}, children: "Context Usage" }), _jsx(Box, { sx: {
|
|
265
|
+
p: 3,
|
|
266
|
+
bg: 'canvas.subtle',
|
|
267
|
+
borderRadius: 2,
|
|
268
|
+
border: '1px solid',
|
|
269
|
+
borderColor: 'border.default',
|
|
270
|
+
}, children: _jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Failed to load context details. Make sure the agent is running." }) })] }));
|
|
271
|
+
}
|
|
272
|
+
const { totalTokens, contextWindow, sessionUsage, turnUsage, distribution } = snapshotData;
|
|
273
|
+
const contextUsagePercent = (totalTokens / contextWindow) * 100;
|
|
274
|
+
const hasDistributionData = distribution?.children && distribution.children.length > 0;
|
|
275
|
+
const hasHistoryData = snapshotData.perRequestUsage && snapshotData.perRequestUsage.length > 0;
|
|
276
|
+
return (_jsxs(Box, { children: [_jsxs(Box, { sx: {
|
|
277
|
+
display: 'flex',
|
|
278
|
+
justifyContent: 'space-between',
|
|
279
|
+
alignItems: 'center',
|
|
280
|
+
mb: 2,
|
|
281
|
+
}, children: [_jsx(Heading, { as: "h4", sx: {
|
|
282
|
+
fontSize: 1,
|
|
283
|
+
fontWeight: 'semibold',
|
|
284
|
+
color: 'fg.muted',
|
|
285
|
+
}, children: "Context Usage" }), messageCount > 0 && (_jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [messageCount, " ", messageCount === 1 ? 'message' : 'messages'] }))] }), _jsxs(Box, { sx: {
|
|
286
|
+
p: 3,
|
|
287
|
+
bg: 'canvas.subtle',
|
|
288
|
+
borderRadius: 2,
|
|
289
|
+
border: '1px solid',
|
|
290
|
+
borderColor: 'border.default',
|
|
291
|
+
}, children: [_jsxs(Box, { sx: { mb: 3 }, children: [_jsxs(Box, { sx: {
|
|
292
|
+
display: 'flex',
|
|
293
|
+
justifyContent: 'space-between',
|
|
294
|
+
mb: 1,
|
|
295
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: [formatTokens(totalTokens), " / ", formatTokens(contextWindow), " tokens"] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: [contextUsagePercent.toFixed(1), "%"] })] }), _jsx(ProgressBar, { progress: Math.min(contextUsagePercent, 100), sx: { height: 8 }, bg: contextUsagePercent > 80 ? 'danger.emphasis' : 'accent.emphasis' })] }), (sessionUsage || turnUsage) && (_jsxs(Box, { sx: {
|
|
296
|
+
display: 'flex',
|
|
297
|
+
gap: 3,
|
|
298
|
+
mb: 3,
|
|
299
|
+
flexWrap: 'wrap',
|
|
300
|
+
}, children: [sessionUsage && (_jsxs(Box, { sx: {
|
|
301
|
+
flex: 1,
|
|
302
|
+
minWidth: 120,
|
|
303
|
+
p: 2,
|
|
304
|
+
bg: 'canvas.default',
|
|
305
|
+
borderRadius: 2,
|
|
306
|
+
border: '1px solid',
|
|
307
|
+
borderColor: 'border.muted',
|
|
308
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted', display: 'block' }, children: ["Session (", sessionUsage.turns, " turns)"] }), _jsx(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: formatTokens(sessionUsage.inputTokens + sessionUsage.outputTokens) }), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [' ', "in ", formatDuration(sessionUsage.durationSeconds)] })] })), turnUsage && (_jsxs(Box, { sx: {
|
|
309
|
+
flex: 1,
|
|
310
|
+
minWidth: 120,
|
|
311
|
+
p: 2,
|
|
312
|
+
bg: 'canvas.default',
|
|
313
|
+
borderRadius: 2,
|
|
314
|
+
border: '1px solid',
|
|
315
|
+
borderColor: 'border.muted',
|
|
316
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted', display: 'block' }, children: ["Last Turn (", turnUsage.requests, " reqs)"] }), _jsx(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: formatTokens(turnUsage.inputTokens + turnUsage.outputTokens) }), _jsxs(Text, { sx: { fontSize: 0, color: 'fg.muted' }, children: [' ', "in ", formatDuration(turnUsage.durationSeconds)] })] }))] })), _jsxs(Box, { sx: {
|
|
317
|
+
display: 'flex',
|
|
318
|
+
justifyContent: 'space-between',
|
|
319
|
+
alignItems: 'center',
|
|
320
|
+
mb: 2,
|
|
321
|
+
}, children: [_jsxs(SegmentedControl, { "aria-label": "View mode", size: "small", onChange: index => {
|
|
322
|
+
const modes = ['overview', 'distribution', 'history'];
|
|
323
|
+
setViewMode(modes[index]);
|
|
324
|
+
}, children: [_jsx(SegmentedControl.Button, { selected: viewMode === 'overview', leadingIcon: ListUnorderedIcon, children: "Overview" }), _jsx(SegmentedControl.Button, { selected: viewMode === 'distribution', leadingIcon: GraphIcon, disabled: !hasDistributionData, children: "Distribution" }), _jsx(SegmentedControl.Button, { selected: viewMode === 'history', leadingIcon: ClockIcon, disabled: !hasHistoryData, children: "History" })] }), viewMode === 'overview' && (_jsx(Button, { size: "small", variant: "invisible", onClick: () => setShowDetails(!showDetails), children: showDetails ? 'Less' : 'More' }))] }), viewMode === 'overview' && (_jsxs(Box, { children: [_jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: [hasDistributionData &&
|
|
325
|
+
distribution.children.map(category => {
|
|
326
|
+
const CategoryIcon = getCategoryIcon(category.name);
|
|
327
|
+
const categoryPercent = (category.value / contextWindow) * 100;
|
|
328
|
+
return (_jsxs(Box, { sx: {
|
|
329
|
+
display: 'flex',
|
|
330
|
+
alignItems: 'center',
|
|
331
|
+
gap: 2,
|
|
332
|
+
}, children: [_jsx(Box, { sx: { color: 'fg.muted', width: 20 }, children: _jsx(CategoryIcon, { size: 16 }) }), _jsx(Text, { sx: { fontSize: 1, flex: 1 }, children: category.name }), _jsx(Text, { sx: { fontSize: 0, color: 'fg.muted', minWidth: 60 }, children: formatTokens(category.value) }), _jsx(Box, { sx: { width: 80 }, children: _jsx(ProgressBar, { progress: categoryPercent, sx: { height: 4 } }) })] }, category.name));
|
|
333
|
+
}), !hasDistributionData && (_jsx(Text, { sx: {
|
|
334
|
+
color: 'fg.muted',
|
|
335
|
+
fontSize: 1,
|
|
336
|
+
textAlign: 'center',
|
|
337
|
+
py: 2,
|
|
338
|
+
}, children: "No context data yet. Start a conversation to see usage." }))] }), showDetails && hasDistributionData && (_jsxs(Box, { sx: {
|
|
339
|
+
mt: 3,
|
|
340
|
+
p: 2,
|
|
341
|
+
bg: 'canvas.default',
|
|
342
|
+
borderRadius: 2,
|
|
343
|
+
border: '1px solid',
|
|
344
|
+
borderColor: 'border.muted',
|
|
345
|
+
fontSize: 0,
|
|
346
|
+
}, children: [snapshotData.systemPromptTokens > 0 && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'semibold' }, children: ["System Prompts:", ' ', formatTokens(snapshotData.systemPromptTokens), " tokens"] }), snapshotData.systemPrompts
|
|
347
|
+
.slice(0, 2)
|
|
348
|
+
.map((prompt, idx) => (_jsxs(Text, { sx: {
|
|
349
|
+
display: 'block',
|
|
350
|
+
ml: 2,
|
|
351
|
+
mt: 1,
|
|
352
|
+
color: 'fg.muted',
|
|
353
|
+
}, children: ["\u2022", ' ', prompt.length > 80
|
|
354
|
+
? prompt.slice(0, 80) + '...'
|
|
355
|
+
: prompt] }, idx)))] })), snapshotData.toolTokens > 0 && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'semibold' }, children: ["Tools: ", formatTokens(snapshotData.toolTokens), " tokens (", snapshotData.tools.length, " tools)"] }), _jsxs(Box, { sx: { ml: 2, mt: 1 }, children: [snapshotData.tools.slice(0, 4).map((tool, idx) => (_jsxs(Text, { sx: { display: 'block', color: 'fg.muted' }, children: ["\u2022 ", tool.name, ": ", formatTokens(tool.totalTokens)] }, idx))), snapshotData.tools.length > 4 && (_jsxs(Text, { sx: { color: 'fg.muted', fontStyle: 'italic' }, children: ["...and ", snapshotData.tools.length - 4, " more"] }))] })] })), (snapshotData.userMessageTokens > 0 ||
|
|
356
|
+
snapshotData.assistantMessageTokens > 0) && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'semibold' }, children: ["Messages:", ' ', formatTokens(snapshotData.userMessageTokens +
|
|
357
|
+
snapshotData.assistantMessageTokens), ' ', "tokens"] }), _jsxs(Box, { sx: { ml: 2, mt: 1 }, children: [_jsxs(Text, { sx: { display: 'block', color: 'fg.muted' }, children: ["\u2022 User: ", formatTokens(snapshotData.userMessageTokens)] }), _jsxs(Text, { sx: { display: 'block', color: 'fg.muted' }, children: ["\u2022 Assistant:", ' ', formatTokens(snapshotData.assistantMessageTokens)] }), snapshotData.toolCallTokens > 0 && (_jsxs(Text, { sx: { display: 'block', color: 'fg.muted' }, children: ["\u2022 Tool calls:", ' ', formatTokens(snapshotData.toolCallTokens)] }))] })] }))] }))] })), viewMode === 'distribution' && treemapOption && (_jsx(ReactECharts, { option: treemapOption, style: { height: chartHeight }, opts: { renderer: 'svg' } })), viewMode === 'history' && historyChartOption && (_jsxs(Box, { children: [_jsx(ReactECharts, { option: historyChartOption, style: { height: chartHeight }, opts: { renderer: 'svg' } }), showDetails && snapshotData.perRequestUsage.length > 0 && (_jsx(Box, { sx: {
|
|
358
|
+
mt: 2,
|
|
359
|
+
maxHeight: '150px',
|
|
360
|
+
overflowY: 'auto',
|
|
361
|
+
fontSize: 0,
|
|
362
|
+
}, children: snapshotData.perRequestUsage
|
|
363
|
+
.slice(-10)
|
|
364
|
+
.reverse()
|
|
365
|
+
.map((req, idx) => (_jsxs(Box, { sx: {
|
|
366
|
+
display: 'flex',
|
|
367
|
+
gap: 2,
|
|
368
|
+
py: 1,
|
|
369
|
+
borderBottom: idx < 9 ? '1px solid' : 'none',
|
|
370
|
+
borderColor: 'border.muted',
|
|
371
|
+
}, children: [_jsxs(Text, { sx: { fontWeight: 'semibold', minWidth: 30 }, children: ["#", req.requestNum] }), _jsxs(Text, { sx: { color: '#3B82F6' }, children: ["\u2193", formatTokens(req.inputTokens)] }), _jsxs(Text, { sx: { color: '#10B981' }, children: ["\u2191", formatTokens(req.outputTokens)] }), req.toolNames.length > 0 && (_jsxs(Text, { sx: { color: 'fg.muted' }, children: ["\uD83D\uDD27 ", req.toolNames.join(', ')] }))] }, req.requestNum))) }))] }))] })] }));
|
|
372
|
+
}
|
|
373
|
+
export default ContextPanel;
|
|
@@ -2,7 +2,10 @@ import React, { type ReactNode } from 'react';
|
|
|
2
2
|
import { type PoweredByTagProps } from '../elements/PoweredByTag';
|
|
3
3
|
import type { ChatMessage } from '../../types/message';
|
|
4
4
|
import type { TransportType } from '../../types/protocol';
|
|
5
|
+
import type { McpServerSelection } from '../../types/inference';
|
|
5
6
|
import type { FrontendToolDefinition } from '../../types/tool';
|
|
7
|
+
import type { BuiltinTool as BuiltinToolType } from '../../../../types';
|
|
8
|
+
import type { MCPServerConfig as MCPServerConfigType } from '../../../AgentConfiguration';
|
|
6
9
|
/**
|
|
7
10
|
* Tool call status for tool rendering
|
|
8
11
|
*/
|
|
@@ -127,12 +130,9 @@ export interface ModelConfig {
|
|
|
127
130
|
isAvailable?: boolean;
|
|
128
131
|
}
|
|
129
132
|
/**
|
|
130
|
-
* Builtin tool configuration
|
|
133
|
+
* Builtin tool configuration (re-exported from types.ts)
|
|
131
134
|
*/
|
|
132
|
-
export
|
|
133
|
-
name: string;
|
|
134
|
-
id: string;
|
|
135
|
-
}
|
|
135
|
+
export type BuiltinTool = BuiltinToolType;
|
|
136
136
|
/**
|
|
137
137
|
* MCP Server Tool configuration
|
|
138
138
|
*/
|
|
@@ -145,17 +145,10 @@ export interface MCPServerTool {
|
|
|
145
145
|
/**
|
|
146
146
|
* MCP Server configuration from backend
|
|
147
147
|
*/
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
enabled: boolean;
|
|
153
|
-
tools: MCPServerTool[];
|
|
154
|
-
command?: string;
|
|
155
|
-
args?: string[];
|
|
156
|
-
isAvailable?: boolean;
|
|
157
|
-
transport?: string;
|
|
158
|
-
}
|
|
148
|
+
/**
|
|
149
|
+
* MCP Server configuration (re-exported from AgentConfiguration)
|
|
150
|
+
*/
|
|
151
|
+
export type MCPServerConfig = MCPServerConfigType;
|
|
159
152
|
/**
|
|
160
153
|
* Remote configuration from server
|
|
161
154
|
*/
|
|
@@ -183,6 +176,20 @@ export interface ProtocolConfig {
|
|
|
183
176
|
/** Additional protocol options */
|
|
184
177
|
options?: Record<string, unknown>;
|
|
185
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Simplified configuration for connecting to an agent runtime server.
|
|
181
|
+
* This is a convenience wrapper over the more detailed ProtocolConfig.
|
|
182
|
+
*/
|
|
183
|
+
export interface AgentRuntimeConfig {
|
|
184
|
+
/** URL of the agent runtime server (e.g., 'http://localhost:8765') */
|
|
185
|
+
url: string;
|
|
186
|
+
/** Optional agent ID to connect to */
|
|
187
|
+
agentId?: string;
|
|
188
|
+
/** Optional authentication token */
|
|
189
|
+
authToken?: string;
|
|
190
|
+
/** Protocol type to use (defaults to 'ag-ui') */
|
|
191
|
+
protocol?: TransportType;
|
|
192
|
+
}
|
|
186
193
|
/**
|
|
187
194
|
* ChatBase props
|
|
188
195
|
*/
|
|
@@ -191,6 +198,13 @@ export interface ChatBaseProps {
|
|
|
191
198
|
title?: string;
|
|
192
199
|
/** Show header */
|
|
193
200
|
showHeader?: boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Show token usage bar (input/output token counts from the backend).
|
|
203
|
+
* Rendered independently of showHeader, so usage is visible even without a title bar.
|
|
204
|
+
* Requires the protocol to have enableConfigQuery=true and an agentId.
|
|
205
|
+
* @default true
|
|
206
|
+
*/
|
|
207
|
+
showTokenUsage?: boolean;
|
|
194
208
|
/** Show loading indicator */
|
|
195
209
|
showLoadingIndicator?: boolean;
|
|
196
210
|
/** Show error messages */
|
|
@@ -207,8 +221,14 @@ export interface ChatBaseProps {
|
|
|
207
221
|
codemodeEnabled?: boolean;
|
|
208
222
|
/** Initial model ID to select (e.g., 'openai:gpt-4o-mini') */
|
|
209
223
|
initialModel?: string;
|
|
210
|
-
/**
|
|
211
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Override the list of available models.
|
|
226
|
+
* When provided, this list replaces the models returned by the config endpoint.
|
|
227
|
+
* Use this to restrict the model selector to a specific subset of models.
|
|
228
|
+
*/
|
|
229
|
+
availableModels?: ModelConfig[];
|
|
230
|
+
/** MCP servers to enable (others will be disabled) */
|
|
231
|
+
mcpServers?: McpServerSelection[];
|
|
212
232
|
/** Initial skill IDs to enable */
|
|
213
233
|
initialSkills?: string[];
|
|
214
234
|
/** Custom class name */
|
|
@@ -228,6 +248,23 @@ export interface ChatBaseProps {
|
|
|
228
248
|
* When provided and useStore is false, enables protocol mode.
|
|
229
249
|
*/
|
|
230
250
|
protocol?: ProtocolConfig;
|
|
251
|
+
/**
|
|
252
|
+
* Simplified agent runtime configuration.
|
|
253
|
+
* A convenience wrapper that creates a ProtocolConfig internally.
|
|
254
|
+
* When provided, will automatically set useStore=false and configure protocol mode.
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```tsx
|
|
258
|
+
* <ChatBase
|
|
259
|
+
* agentRuntimeConfig={{
|
|
260
|
+
* url: 'http://localhost:8765',
|
|
261
|
+
* agentId: 'my-agent',
|
|
262
|
+
* authToken: 'my-token',
|
|
263
|
+
* }}
|
|
264
|
+
* />
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
agentRuntimeConfig?: AgentRuntimeConfig;
|
|
231
268
|
/**
|
|
232
269
|
* Custom message handler (for props-based mode).
|
|
233
270
|
* When provided, uses custom handler instead of store or protocol.
|
|
@@ -351,10 +388,28 @@ export interface ChatBaseProps {
|
|
|
351
388
|
userId?: string;
|
|
352
389
|
accessToken?: string;
|
|
353
390
|
}>;
|
|
391
|
+
/**
|
|
392
|
+
* Runtime ID for conversation persistence.
|
|
393
|
+
* When provided, messages are fetched from the server API on page reload
|
|
394
|
+
* and prevents message mixing between different agent spaces.
|
|
395
|
+
*/
|
|
396
|
+
runtimeId?: string;
|
|
397
|
+
/**
|
|
398
|
+
* Endpoint URL for fetching conversation history.
|
|
399
|
+
* When runtimeId is provided, this endpoint is called to fetch
|
|
400
|
+
* the conversation history on mount.
|
|
401
|
+
* If not provided, defaults to `{protocol.endpoint}/history`.
|
|
402
|
+
*/
|
|
403
|
+
historyEndpoint?: string;
|
|
404
|
+
/**
|
|
405
|
+
* Auth token for the history endpoint.
|
|
406
|
+
* If not provided, uses the protocol's authToken.
|
|
407
|
+
*/
|
|
408
|
+
historyAuthToken?: string;
|
|
354
409
|
}
|
|
355
410
|
/**
|
|
356
411
|
* ChatBase component - Universal chat panel supporting store, protocol, and custom modes
|
|
357
412
|
*/
|
|
358
|
-
export declare function ChatBase({ title, showHeader, showLoadingIndicator, showErrors, showInput, showModelSelector, showToolsMenu, showSkillsMenu, codemodeEnabled, initialModel,
|
|
413
|
+
export declare function ChatBase({ title, showHeader, showTokenUsage, showLoadingIndicator, showErrors, showInput, showModelSelector, showToolsMenu, showSkillsMenu, codemodeEnabled, initialModel, availableModels, mcpServers, initialSkills, className, loadingState, headerActions, useStore: useStoreMode, protocol: protocolProp, agentRuntimeConfig, onSendMessage, enableStreaming, brandIcon, avatarConfig, headerButtons, showPoweredBy, poweredByProps, emptyState, renderToolResult, footerContent, headerContent, children, borderRadius, backgroundColor, border, boxShadow, compact, placeholder, description, onStateUpdate, onNewChat, onClear, onMessagesChange, autoFocus, suggestions, submitOnSuggestionClick, hideMessagesAfterToolUI, focusTrigger, frontendTools, onAuthorizationRequired, connectedIdentities, runtimeId, historyEndpoint, historyAuthToken, }: ChatBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
359
414
|
export type { PoweredByTagProps };
|
|
360
415
|
export default ChatBase;
|