Skip to content

Commit 9a2a7e2

Browse files
committed
fix: types
1 parent 2e03cdd commit 9a2a7e2

File tree

3 files changed

+170
-11
lines changed

3 files changed

+170
-11
lines changed

src/components/ComponentsProvider/chatPlaceholderTypes.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type React from 'react';
22

3+
import type {ChatConfig, ChatContext} from '../../types/chat';
4+
35
// Placeholder types for chat components
46
// These will be properly typed when implemented in external packages
57

@@ -8,17 +10,9 @@ export interface AIAssistantButtonProps {
810
}
911

1012
export interface ChatPanelProps {
11-
config?: {
12-
backendUrl?: string;
13-
showQuota?: boolean;
14-
enableContext?: boolean;
15-
customActions?: any[];
16-
maxMessages?: number;
17-
welcomeMessage?: string;
18-
suggestions?: string[];
19-
};
20-
context?: any;
21-
formatContext?: (context: any) => string;
13+
config?: ChatConfig;
14+
context?: ChatContext;
15+
formatContext?: (context: ChatContext) => string;
2216
}
2317

2418
// Placeholder components that do nothing

src/lib.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,20 @@ export type {AsideNavigationProps} from './containers/AsideNavigation/AsideNavig
3535
export type {GetMonitoringLink, GetMonitoringClusterLink} from './utils/monitoring';
3636

3737
export {configureUIFactory} from './uiFactory/uiFactory';
38+
39+
// Export chat types
40+
export type {
41+
ChatMessage,
42+
ChatState,
43+
ChatDelta,
44+
ChatRequest,
45+
ChatConfig,
46+
ChatContext,
47+
ChatCustomAction,
48+
QuotaInfo,
49+
ToolCall,
50+
UsageBreakdown,
51+
} from './types/chat';
52+
53+
// Re-export chat component types from ComponentsProvider
54+
export type {AIAssistantButtonProps, ChatPanelProps} from './components/ComponentsProvider';

src/types/chat.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Chat types exported from ydb-embedded-ui
2+
// These types are used by chat components implemented in external packages
3+
4+
import type React from 'react';
5+
6+
export interface ChatMessage {
7+
id: string;
8+
role: 'user' | 'assistant' | 'system' | 'tool';
9+
content: string;
10+
timestamp: number;
11+
toolCalls?: ToolCall[];
12+
toolCallId?: string;
13+
metadata?: {
14+
model?: string;
15+
usage?: {
16+
promptTokens: number;
17+
completionTokens: number;
18+
totalTokens: number;
19+
};
20+
};
21+
usageBreakdown?: UsageBreakdown;
22+
}
23+
24+
export interface ToolCall {
25+
id: string;
26+
type: 'function';
27+
function: {
28+
name: string;
29+
arguments: string;
30+
};
31+
status?: 'pending' | 'executing' | 'completed' | 'error';
32+
startTime?: number;
33+
endTime?: number;
34+
}
35+
36+
export interface UsageBreakdown {
37+
mainChatTokens: number;
38+
summaryTokens: number;
39+
totalTokens: number;
40+
estimatedCost: number;
41+
breakdown: {
42+
mainChat: {
43+
inputTokens: number;
44+
outputTokens: number;
45+
cost: number;
46+
};
47+
summary: {
48+
inputTokens: number;
49+
outputTokens: number;
50+
cost: number;
51+
};
52+
};
53+
}
54+
55+
export interface ChatDelta {
56+
type: 'content' | 'done' | 'error' | 'tool_result' | 'tool_calls' | 'tool_status' | 'usage';
57+
content?: string;
58+
error?: string;
59+
tool_calls?: ToolCall[];
60+
tool_call_id?: string;
61+
tool_status?: 'executing' | 'completed' | 'error';
62+
usage?: UsageBreakdown;
63+
}
64+
65+
export interface ChatState {
66+
messages: ChatMessage[];
67+
isStreaming: boolean;
68+
error: string | null;
69+
sessionId: string | null;
70+
isOpen: boolean;
71+
needsNewAssistantMessage?: boolean;
72+
currentStreamingMessageId?: string;
73+
}
74+
75+
export interface ChatRequest {
76+
messages: Array<{
77+
role: string;
78+
content: string;
79+
tool_calls?: ToolCall[];
80+
tool_call_id?: string;
81+
}>;
82+
context?: string;
83+
stream: boolean;
84+
model: string;
85+
}
86+
87+
export interface QuotaInfo {
88+
daily: {
89+
used: number;
90+
limit: number;
91+
percentage: number;
92+
remaining: number;
93+
};
94+
monthly: {
95+
used: number;
96+
limit: number;
97+
percentage: number;
98+
remaining: number;
99+
};
100+
pool: string;
101+
login: string;
102+
}
103+
104+
export interface ChatContext {
105+
// Current page context
106+
currentPage:
107+
| 'cluster'
108+
| 'tenant'
109+
| 'node'
110+
| 'pDisk'
111+
| 'vDisk'
112+
| 'tablet'
113+
| 'storageGroup'
114+
| 'unknown';
115+
116+
// Key identifiers
117+
clusterName?: string;
118+
tenantName?: string;
119+
nodeId?: string;
120+
tabletId?: string;
121+
pDiskId?: string;
122+
vDiskId?: string;
123+
storageGroupId?: string;
124+
125+
// Current view/tab
126+
activeTab?: string;
127+
128+
// URL for reference
129+
currentPath: string;
130+
}
131+
132+
export interface ChatCustomAction {
133+
id: string;
134+
label: string;
135+
icon?: React.ComponentType<{size?: number}>;
136+
handler: (message: ChatMessage) => void;
137+
}
138+
139+
export interface ChatConfig {
140+
backendUrl?: string;
141+
quotaUrl?: string;
142+
showQuota?: boolean;
143+
enableContext?: boolean;
144+
customActions?: ChatCustomAction[];
145+
maxMessages?: number;
146+
welcomeMessage?: string;
147+
suggestions?: string[];
148+
}

0 commit comments

Comments
 (0)