|
| 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