@datalayer/agent-runtimes 0.0.5 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +150 -22
- package/lib/components/chat/components/AgentDetails.d.ts +15 -2
- package/lib/components/chat/components/AgentDetails.js +9 -93
- package/lib/components/chat/components/AgentIdentity.d.ts +92 -0
- package/lib/components/chat/components/AgentIdentity.js +318 -0
- package/lib/components/chat/components/Chat.d.ts +24 -1
- package/lib/components/chat/components/Chat.js +41 -19
- package/lib/components/chat/components/ChatFloating.d.ts +6 -1
- package/lib/components/chat/components/ChatFloating.js +12 -6
- package/lib/components/chat/components/ContextDistribution.d.ts +47 -0
- package/lib/components/chat/components/ContextDistribution.js +146 -0
- package/lib/components/chat/components/ContextUsage.d.ts +33 -0
- package/lib/components/chat/components/ContextUsage.js +127 -0
- package/lib/components/chat/components/base/ChatBase.d.ts +51 -1
- package/lib/components/chat/components/base/ChatBase.js +278 -74
- package/lib/components/chat/components/display/ToolCallDisplay.d.ts +16 -2
- package/lib/components/chat/components/display/ToolCallDisplay.js +148 -6
- package/lib/components/chat/components/display/index.d.ts +1 -1
- package/lib/components/chat/components/display/index.js +1 -1
- package/lib/components/chat/components/elements/ChatInputPrompt.d.ts +12 -1
- package/lib/components/chat/components/elements/ChatInputPrompt.js +8 -3
- package/lib/components/chat/components/index.d.ts +3 -0
- package/lib/components/chat/components/index.js +3 -0
- package/lib/components/chat/components/parts/ToolPart.d.ts +1 -1
- package/lib/components/chat/components/parts/ToolPart.js +142 -6
- package/lib/components/chat/index.d.ts +1 -1
- package/lib/components/chat/index.js +1 -1
- package/lib/components/chat/protocols/A2AAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/A2AAdapter.js +13 -2
- package/lib/components/chat/protocols/ACPAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/ACPAdapter.js +13 -2
- package/lib/components/chat/protocols/AGUIAdapter.d.ts +9 -0
- package/lib/components/chat/protocols/AGUIAdapter.js +19 -1
- package/lib/components/chat/protocols/VercelAIAdapter.d.ts +7 -0
- package/lib/components/chat/protocols/VercelAIAdapter.js +19 -0
- package/lib/components/chat/types/execution.d.ts +78 -0
- package/lib/components/chat/types/execution.js +64 -0
- package/lib/components/chat/types/index.d.ts +1 -0
- package/lib/components/chat/types/index.js +1 -0
- package/lib/components/chat/types/protocol.d.ts +9 -0
- package/lib/components/ui/pagination.d.ts +2 -2
- package/lib/components/ui/pagination.js +4 -4
- package/lib/components/ui/resizable.d.ts +4 -4
- package/lib/components/ui/resizable.js +4 -4
- package/lib/examples/A2UiRestaurantExample.js +2 -2
- package/lib/examples/AgUiAgenticExample.js +2 -2
- package/lib/examples/AgUiBackendToolRenderingExample.js +2 -2
- package/lib/examples/AgUiHaikuGenUIExample.js +2 -2
- package/lib/examples/AgUiHumanInTheLoopExample.js +2 -2
- package/lib/examples/AgUiSharedStateExample.js +2 -2
- package/lib/examples/AgUiToolsBasedGenUIExample.js +2 -2
- package/lib/examples/AgentRuntimeCustomExample.js +2 -2
- package/lib/examples/AgentRuntimeLexical2Example.js +2 -1
- package/lib/examples/AgentRuntimeLexicalExample.js +5 -2
- package/lib/examples/AgentRuntimeLexicalSidebarExample.js +4 -2
- package/lib/examples/AgentRuntimeNotebookExample.js +1 -1
- package/lib/examples/AgentRuntimeStandaloneExample.js +2 -2
- package/lib/examples/AgentSpaceFormExample.d.ts +70 -2
- package/lib/examples/AgentSpaceFormExample.js +204 -35
- package/lib/examples/CopilotKitLexicalExample.js +2 -1
- package/lib/examples/components/AgentConfiguration.d.ts +37 -0
- package/lib/examples/components/AgentConfiguration.js +239 -8
- package/lib/examples/components/Header.d.ts +0 -2
- package/lib/examples/components/Header.js +2 -16
- package/lib/examples/components/LexicalEditor.js +2 -1
- package/lib/examples/components/MockFileBrowser.js +6 -2
- package/lib/examples/components/index.d.ts +0 -1
- package/lib/examples/components/index.js +0 -1
- package/lib/examples/example-selector.js +0 -1
- package/lib/examples/index.d.ts +0 -1
- package/lib/examples/index.js +0 -1
- package/lib/examples/lexical/editorConfig.d.ts +3 -2
- package/lib/examples/lexical/editorConfig.js +7 -1
- package/lib/examples/lexical/initial-content.json +2210 -0
- package/lib/examples/main.js +15 -1
- package/lib/identity/IdentityConnect.d.ts +90 -0
- package/lib/identity/IdentityConnect.js +316 -0
- package/lib/identity/OAuthCallback.d.ts +58 -0
- package/lib/identity/OAuthCallback.js +223 -0
- package/lib/identity/dcr.d.ts +257 -0
- package/lib/identity/dcr.js +282 -0
- package/lib/identity/identityStore.d.ts +72 -0
- package/lib/identity/identityStore.js +529 -0
- package/lib/identity/index.d.ts +46 -0
- package/lib/identity/index.js +17 -0
- package/lib/identity/pkce.d.ts +30 -0
- package/lib/identity/pkce.js +65 -0
- package/lib/identity/types.d.ts +293 -0
- package/lib/identity/types.js +73 -0
- package/lib/identity/useIdentity.d.ts +108 -0
- package/lib/identity/useIdentity.js +323 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/lib/utils.js +1 -1
- package/lib/renderers/a2ui/lib/utils.js +1 -1
- package/lib/runtime/index.d.ts +35 -0
- package/lib/runtime/index.js +40 -0
- package/lib/runtime/runtimeStore.d.ts +77 -0
- package/lib/runtime/runtimeStore.js +184 -0
- package/lib/runtime/types.d.ts +84 -0
- package/lib/runtime/types.js +15 -0
- package/lib/runtime/useAgentConnection.d.ts +46 -0
- package/lib/runtime/useAgentConnection.js +112 -0
- package/lib/runtime/useAgentRuntime.d.ts +94 -0
- package/lib/runtime/useAgentRuntime.js +125 -0
- package/lib/test-setup.d.ts +1 -1
- package/lib/test-setup.js +1 -0
- package/lib/tools/adapters/agent-runtimes/AgentRuntimesToolAdapter.js +32 -1
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.d.ts +6 -0
- package/lib/tools/adapters/agent-runtimes/lexicalHooks.js +16 -17
- package/package.json +20 -7
- package/patches/@datalayer+jupyter-lexical+1.0.8.patch +11628 -0
- package/patches/@datalayer+jupyter-react+2.0.2.patch +5338 -0
- package/lib/examples/AgentSpaceHomeExample.d.ts +0 -8
- package/lib/examples/AgentSpaceHomeExample.js +0 -171
- package/lib/examples/components/AgentsDataTable.d.ts +0 -13
- package/lib/examples/components/AgentsDataTable.js +0 -74
- package/lib/examples/components/Rating.d.ts +0 -14
- package/lib/examples/components/Rating.js +0 -12
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
* ContextDistribution component - Shows context distribution as a treemap.
|
|
6
|
+
*/
|
|
7
|
+
import { Box, Text, Spinner, Button } from '@primer/react';
|
|
8
|
+
import { ListUnorderedIcon } from '@primer/octicons-react';
|
|
9
|
+
import { useQuery } from '@tanstack/react-query';
|
|
10
|
+
import ReactECharts from 'echarts-for-react';
|
|
11
|
+
import { useState } from 'react';
|
|
12
|
+
function getLocalApiBase() {
|
|
13
|
+
if (typeof window === 'undefined') {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
const host = window.location.hostname;
|
|
17
|
+
return host === 'localhost' || host === '127.0.0.1'
|
|
18
|
+
? 'http://127.0.0.1:8765'
|
|
19
|
+
: '';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Format token count for display
|
|
23
|
+
*/
|
|
24
|
+
function formatTokens(tokens) {
|
|
25
|
+
if (tokens >= 1000000) {
|
|
26
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
27
|
+
}
|
|
28
|
+
if (tokens >= 1000) {
|
|
29
|
+
return `${(tokens / 1000).toFixed(1)}K`;
|
|
30
|
+
}
|
|
31
|
+
return tokens.toString();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ContextDistribution component displays context distribution as a treemap.
|
|
35
|
+
*/
|
|
36
|
+
export function ContextDistribution({ agentId, height = '250px', }) {
|
|
37
|
+
const [showDetails, setShowDetails] = useState(false);
|
|
38
|
+
const { data: snapshotData, isLoading, error, } = useQuery({
|
|
39
|
+
queryKey: ['context-snapshot', agentId],
|
|
40
|
+
queryFn: async () => {
|
|
41
|
+
const apiBase = getLocalApiBase();
|
|
42
|
+
const response = await fetch(`${apiBase}/api/v1/configure/agents/${encodeURIComponent(agentId)}/context-snapshot`);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
throw new Error('Failed to fetch context snapshot');
|
|
45
|
+
}
|
|
46
|
+
return response.json();
|
|
47
|
+
},
|
|
48
|
+
refetchInterval: 10000, // Refresh every 10 seconds
|
|
49
|
+
refetchOnMount: 'always',
|
|
50
|
+
staleTime: 0,
|
|
51
|
+
});
|
|
52
|
+
if (isLoading) {
|
|
53
|
+
return (_jsxs(Box, { sx: {
|
|
54
|
+
p: 3,
|
|
55
|
+
display: 'flex',
|
|
56
|
+
alignItems: 'center',
|
|
57
|
+
justifyContent: 'center',
|
|
58
|
+
height,
|
|
59
|
+
}, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { ml: 2, fontSize: 1, color: 'fg.muted' }, children: "Loading context distribution..." })] }));
|
|
60
|
+
}
|
|
61
|
+
if (error || !snapshotData) {
|
|
62
|
+
return (_jsx(Box, { sx: {
|
|
63
|
+
p: 3,
|
|
64
|
+
bg: 'canvas.subtle',
|
|
65
|
+
borderRadius: 2,
|
|
66
|
+
border: '1px solid',
|
|
67
|
+
borderColor: 'border.default',
|
|
68
|
+
}, children: _jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Failed to load context distribution" }) }));
|
|
69
|
+
}
|
|
70
|
+
const { distribution, totalTokens, contextWindow } = snapshotData;
|
|
71
|
+
const hasData = distribution.children && distribution.children.length > 0;
|
|
72
|
+
// ECharts option for treemap
|
|
73
|
+
const chartOption = {
|
|
74
|
+
tooltip: {
|
|
75
|
+
formatter: (info) => {
|
|
76
|
+
return `${info.name}: ${formatTokens(info.value)} tokens`;
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
series: [
|
|
80
|
+
{
|
|
81
|
+
type: 'treemap',
|
|
82
|
+
data: hasData ? distribution.children : [{ name: 'No data', value: 1 }],
|
|
83
|
+
roam: false,
|
|
84
|
+
breadcrumb: {
|
|
85
|
+
show: false,
|
|
86
|
+
},
|
|
87
|
+
label: {
|
|
88
|
+
show: true,
|
|
89
|
+
formatter: '{b}',
|
|
90
|
+
fontSize: 12,
|
|
91
|
+
},
|
|
92
|
+
itemStyle: {
|
|
93
|
+
borderColor: '#fff',
|
|
94
|
+
borderWidth: 2,
|
|
95
|
+
},
|
|
96
|
+
levels: [
|
|
97
|
+
{
|
|
98
|
+
itemStyle: {
|
|
99
|
+
borderColor: '#777',
|
|
100
|
+
borderWidth: 0,
|
|
101
|
+
gapWidth: 1,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
itemStyle: {
|
|
106
|
+
borderColor: '#555',
|
|
107
|
+
borderWidth: 5,
|
|
108
|
+
gapWidth: 1,
|
|
109
|
+
},
|
|
110
|
+
colorSaturation: [0.35, 0.5],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
colorSaturation: [0.35, 0.5],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
};
|
|
119
|
+
return (_jsxs(Box, { children: [_jsxs(Box, { sx: {
|
|
120
|
+
display: 'flex',
|
|
121
|
+
justifyContent: 'space-between',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
mb: 2,
|
|
124
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 1, fontWeight: 'bold' }, children: ["Current Context (", formatTokens(totalTokens), " /", ' ', formatTokens(contextWindow), " tokens)"] }), _jsx(Button, { size: "small", variant: "invisible", onClick: () => setShowDetails(!showDetails), leadingVisual: ListUnorderedIcon, children: showDetails ? 'Hide Details' : 'Show Details' })] }), hasData ? (_jsx(ReactECharts, { option: chartOption, style: { height }, opts: { renderer: 'svg' } })) : (_jsx(Box, { sx: {
|
|
125
|
+
p: 4,
|
|
126
|
+
bg: 'canvas.subtle',
|
|
127
|
+
borderRadius: 2,
|
|
128
|
+
textAlign: 'center',
|
|
129
|
+
height,
|
|
130
|
+
display: 'flex',
|
|
131
|
+
alignItems: 'center',
|
|
132
|
+
justifyContent: 'center',
|
|
133
|
+
}, children: _jsx(Text, { sx: { color: 'fg.muted', fontSize: 1 }, children: "No context data yet. Start a conversation to see context distribution." }) })), showDetails && hasData && (_jsxs(Box, { sx: {
|
|
134
|
+
mt: 3,
|
|
135
|
+
p: 2,
|
|
136
|
+
border: '1px solid',
|
|
137
|
+
borderColor: 'border.default',
|
|
138
|
+
borderRadius: 2,
|
|
139
|
+
bg: 'canvas.default',
|
|
140
|
+
fontFamily: 'mono',
|
|
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)))] })), (snapshotData.userMessageTokens > 0 ||
|
|
143
|
+
snapshotData.assistantMessageTokens > 0) && (_jsxs(Box, { sx: { mb: 2 }, children: [_jsxs(Text, { sx: { fontWeight: 'bold' }, children: ["Messages:", ' ', formatTokens(snapshotData.userMessageTokens +
|
|
144
|
+
snapshotData.assistantMessageTokens), ' ', "tokens"] }), _jsxs(Box, { sx: { ml: 3, mt: 1 }, children: [_jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 User Messages:", ' ', formatTokens(snapshotData.userMessageTokens), " tokens"] }), _jsxs(Text, { sx: { display: 'block' }, children: ["\u2022 Assistant Responses:", ' ', formatTokens(snapshotData.assistantMessageTokens), " tokens"] })] })] }))] }))] }));
|
|
145
|
+
}
|
|
146
|
+
export default ContextDistribution;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context category child item
|
|
3
|
+
*/
|
|
4
|
+
interface ContextCategoryChild {
|
|
5
|
+
name: string;
|
|
6
|
+
value: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Context category with children
|
|
10
|
+
*/
|
|
11
|
+
interface ContextCategory {
|
|
12
|
+
name: string;
|
|
13
|
+
value: number;
|
|
14
|
+
children: ContextCategoryChild[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context details response from API
|
|
18
|
+
*/
|
|
19
|
+
export interface ContextDetailsResponse {
|
|
20
|
+
name: string;
|
|
21
|
+
totalTokens: number;
|
|
22
|
+
usedTokens: number;
|
|
23
|
+
children: ContextCategory[];
|
|
24
|
+
}
|
|
25
|
+
export interface ContextUsageProps {
|
|
26
|
+
/** Agent ID for fetching context details (required) */
|
|
27
|
+
agentId: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* ContextUsage component displays token usage breakdown by category.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ContextUsage({ agentId }: ContextUsageProps): import("react/jsx-runtime").JSX.Element;
|
|
33
|
+
export default ContextUsage;
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
* ContextUsage component - Shows context usage details with token breakdown.
|
|
6
|
+
*/
|
|
7
|
+
import { CommentDiscussionIcon, DatabaseIcon, FileIcon, ToolsIcon, ClockIcon, } from '@primer/octicons-react';
|
|
8
|
+
import { Box, Heading, Text, ProgressBar, Spinner } from '@primer/react';
|
|
9
|
+
import { useQuery } from '@tanstack/react-query';
|
|
10
|
+
function getLocalApiBase() {
|
|
11
|
+
if (typeof window === 'undefined') {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
const host = window.location.hostname;
|
|
15
|
+
return host === 'localhost' || host === '127.0.0.1'
|
|
16
|
+
? 'http://127.0.0.1:8765'
|
|
17
|
+
: '';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Format token count for display
|
|
21
|
+
*/
|
|
22
|
+
function formatTokens(tokens) {
|
|
23
|
+
if (tokens >= 1000000) {
|
|
24
|
+
return `${(tokens / 1000000).toFixed(1)}M`;
|
|
25
|
+
}
|
|
26
|
+
if (tokens >= 1000) {
|
|
27
|
+
return `${(tokens / 1000).toFixed(1)}K`;
|
|
28
|
+
}
|
|
29
|
+
return tokens.toString();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get icon for context category
|
|
33
|
+
*/
|
|
34
|
+
function getCategoryIcon(name) {
|
|
35
|
+
switch (name.toLowerCase()) {
|
|
36
|
+
case 'files':
|
|
37
|
+
return FileIcon;
|
|
38
|
+
case 'messages':
|
|
39
|
+
return CommentDiscussionIcon;
|
|
40
|
+
case 'tools':
|
|
41
|
+
return ToolsIcon;
|
|
42
|
+
case 'memory':
|
|
43
|
+
return DatabaseIcon;
|
|
44
|
+
case 'system':
|
|
45
|
+
return FileIcon;
|
|
46
|
+
case 'cache':
|
|
47
|
+
return DatabaseIcon;
|
|
48
|
+
default:
|
|
49
|
+
return ClockIcon;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* ContextUsage component displays token usage breakdown by category.
|
|
54
|
+
*/
|
|
55
|
+
export function ContextUsage({ agentId }) {
|
|
56
|
+
const { data: contextData, isLoading, error, } = useQuery({
|
|
57
|
+
queryKey: ['context-details', agentId],
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
const apiBase = getLocalApiBase();
|
|
60
|
+
const response = await fetch(`${apiBase}/api/v1/configure/agents/${encodeURIComponent(agentId)}/context-details`);
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
throw new Error('Failed to fetch context details');
|
|
63
|
+
}
|
|
64
|
+
return response.json();
|
|
65
|
+
},
|
|
66
|
+
refetchInterval: 10000, // Refresh every 10 seconds
|
|
67
|
+
refetchOnMount: 'always', // Always refetch when component mounts
|
|
68
|
+
staleTime: 0, // Data is always considered stale
|
|
69
|
+
});
|
|
70
|
+
if (isLoading) {
|
|
71
|
+
return (_jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
72
|
+
fontSize: 1,
|
|
73
|
+
fontWeight: 'semibold',
|
|
74
|
+
mb: 2,
|
|
75
|
+
color: 'fg.muted',
|
|
76
|
+
}, children: "Cumulative Context Usage" }), _jsxs(Box, { sx: {
|
|
77
|
+
p: 3,
|
|
78
|
+
bg: 'canvas.subtle',
|
|
79
|
+
borderRadius: 2,
|
|
80
|
+
border: '1px solid',
|
|
81
|
+
borderColor: 'border.default',
|
|
82
|
+
display: 'flex',
|
|
83
|
+
alignItems: 'center',
|
|
84
|
+
gap: 2,
|
|
85
|
+
}, children: [_jsx(Spinner, { size: "small" }), _jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Loading context details..." })] })] }));
|
|
86
|
+
}
|
|
87
|
+
if (error || !contextData) {
|
|
88
|
+
return (_jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
89
|
+
fontSize: 1,
|
|
90
|
+
fontWeight: 'semibold',
|
|
91
|
+
mb: 2,
|
|
92
|
+
color: 'fg.muted',
|
|
93
|
+
}, children: "Cumulative Context Usage" }), _jsx(Box, { sx: {
|
|
94
|
+
p: 3,
|
|
95
|
+
bg: 'canvas.subtle',
|
|
96
|
+
borderRadius: 2,
|
|
97
|
+
border: '1px solid',
|
|
98
|
+
borderColor: 'border.default',
|
|
99
|
+
}, children: _jsx(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: "Failed to load context details" }) })] }));
|
|
100
|
+
}
|
|
101
|
+
const contextUsagePercent = (contextData.usedTokens / contextData.totalTokens) * 100;
|
|
102
|
+
return (_jsxs(Box, { children: [_jsx(Heading, { as: "h4", sx: {
|
|
103
|
+
fontSize: 1,
|
|
104
|
+
fontWeight: 'semibold',
|
|
105
|
+
mb: 2,
|
|
106
|
+
color: 'fg.muted',
|
|
107
|
+
}, children: "Cumulative Context Usage" }), _jsxs(Box, { sx: {
|
|
108
|
+
p: 3,
|
|
109
|
+
bg: 'canvas.subtle',
|
|
110
|
+
borderRadius: 2,
|
|
111
|
+
border: '1px solid',
|
|
112
|
+
borderColor: 'border.default',
|
|
113
|
+
}, children: [_jsxs(Box, { sx: { mb: 3 }, children: [_jsxs(Box, { sx: {
|
|
114
|
+
display: 'flex',
|
|
115
|
+
justifyContent: 'space-between',
|
|
116
|
+
mb: 1,
|
|
117
|
+
}, children: [_jsxs(Text, { sx: { fontSize: 1, fontWeight: 'semibold' }, children: [formatTokens(contextData.usedTokens), " /", ' ', formatTokens(contextData.totalTokens), " tokens"] }), _jsxs(Text, { sx: { fontSize: 1, color: 'fg.muted' }, children: [contextUsagePercent.toFixed(0), "%"] })] }), _jsx(ProgressBar, { progress: contextUsagePercent, sx: { height: 8 }, bg: contextUsagePercent > 80 ? 'danger.emphasis' : 'accent.emphasis' })] }), _jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: contextData.children.map(category => {
|
|
118
|
+
const CategoryIcon = getCategoryIcon(category.name);
|
|
119
|
+
const categoryPercent = (category.value / contextData.totalTokens) * 100;
|
|
120
|
+
return (_jsxs(Box, { sx: {
|
|
121
|
+
display: 'flex',
|
|
122
|
+
alignItems: 'center',
|
|
123
|
+
gap: 2,
|
|
124
|
+
}, 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));
|
|
125
|
+
}) })] })] }));
|
|
126
|
+
}
|
|
127
|
+
export default ContextUsage;
|
|
@@ -201,6 +201,16 @@ export interface ChatBaseProps {
|
|
|
201
201
|
showModelSelector?: boolean;
|
|
202
202
|
/** Show tools menu (for protocols that support it) */
|
|
203
203
|
showToolsMenu?: boolean;
|
|
204
|
+
/** Show skills menu (for protocols that support it) */
|
|
205
|
+
showSkillsMenu?: boolean;
|
|
206
|
+
/** Indicate tools are accessed via Codemode meta-tools */
|
|
207
|
+
codemodeEnabled?: boolean;
|
|
208
|
+
/** Initial model ID to select (e.g., 'openai:gpt-4o-mini') */
|
|
209
|
+
initialModel?: string;
|
|
210
|
+
/** Initial MCP server IDs to enable (others will be disabled) */
|
|
211
|
+
initialMcpServers?: string[];
|
|
212
|
+
/** Initial skill IDs to enable */
|
|
213
|
+
initialSkills?: string[];
|
|
204
214
|
/** Custom class name */
|
|
205
215
|
className?: string;
|
|
206
216
|
/** Custom loading state */
|
|
@@ -301,10 +311,50 @@ export interface ChatBaseProps {
|
|
|
301
311
|
* These tools execute in the browser and their results are sent back to the agent.
|
|
302
312
|
*/
|
|
303
313
|
frontendTools?: FrontendToolDefinition[];
|
|
314
|
+
/**
|
|
315
|
+
* Callback when the agent requests authorization for an external service.
|
|
316
|
+
* This is called when a tool needs OAuth access to a service like GitHub.
|
|
317
|
+
*
|
|
318
|
+
* @param provider - The OAuth provider name (e.g., 'github', 'google')
|
|
319
|
+
* @param scopes - The requested OAuth scopes
|
|
320
|
+
* @param context - Additional context about why authorization is needed
|
|
321
|
+
* @returns Promise resolving to the access token, or null if user cancels
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```tsx
|
|
325
|
+
* <ChatBase
|
|
326
|
+
* onAuthorizationRequired={async (provider, scopes, context) => {
|
|
327
|
+
* // Show UI to user to authorize
|
|
328
|
+
* const token = await showAuthDialog(provider, scopes);
|
|
329
|
+
* return token;
|
|
330
|
+
* }}
|
|
331
|
+
* />
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
onAuthorizationRequired?: (provider: string, scopes: string[], context?: {
|
|
335
|
+
toolName?: string;
|
|
336
|
+
reason?: string;
|
|
337
|
+
}) => Promise<string | null>;
|
|
338
|
+
/**
|
|
339
|
+
* Connected identities to pass to agent tools.
|
|
340
|
+
* When provided, access tokens for these identities are automatically
|
|
341
|
+
* included in tool calls that need them.
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```tsx
|
|
345
|
+
* const { identities, getAccessToken } = useIdentity();
|
|
346
|
+
* <ChatBase connectedIdentities={identities} />
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
connectedIdentities?: Array<{
|
|
350
|
+
provider: string;
|
|
351
|
+
userId?: string;
|
|
352
|
+
accessToken?: string;
|
|
353
|
+
}>;
|
|
304
354
|
}
|
|
305
355
|
/**
|
|
306
356
|
* ChatBase component - Universal chat panel supporting store, protocol, and custom modes
|
|
307
357
|
*/
|
|
308
|
-
export declare function ChatBase({ title, showHeader, showLoadingIndicator, showErrors, showInput, showModelSelector, showToolsMenu, className, loadingState, headerActions, useStore: useStoreMode, protocol, 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, }: ChatBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
358
|
+
export declare function ChatBase({ title, showHeader, showLoadingIndicator, showErrors, showInput, showModelSelector, showToolsMenu, showSkillsMenu, codemodeEnabled, initialModel, initialMcpServers, initialSkills, className, loadingState, headerActions, useStore: useStoreMode, protocol, 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, }: ChatBaseProps): import("react/jsx-runtime").JSX.Element;
|
|
309
359
|
export type { PoweredByTagProps };
|
|
310
360
|
export default ChatBase;
|