-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathcopilot.ts
More file actions
222 lines (198 loc) · 5.06 KB
/
copilot.ts
File metadata and controls
222 lines (198 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import type { OpenAIProvider } from '@ai-sdk/openai'
import type { DeepSeekProvider } from '@ai-sdk/deepseek'
import type { AnthropicProvider } from '@ai-sdk/anthropic'
import type { XaiProvider } from '@ai-sdk/xai'
import { createOpenAI } from '@ai-sdk/openai'
import { createDeepSeek } from '@ai-sdk/deepseek'
import { createAnthropic } from '@ai-sdk/anthropic'
import { createXai } from '@ai-sdk/xai'
import { MCPPromptData } from '@/types/mcp'
import VueI18n from 'vue-i18n'
/**
* Defines the role of a message in the Copilot conversation
*/
export type CopilotRole = 'system' | 'user' | 'assistant'
/**
* Represents a single message in the Copilot conversation
*/
export interface CopilotMessage {
id: string
role: CopilotRole
content: string
reasoning?: string
}
/**
* Defines a preset prompt with translation support
*/
export interface CopilotPresetPrompt {
prompt: string
promptMap: PresetPromptMap
}
/**
* Maps preset prompts to their translated versions
*/
export type PresetPromptMap = Record<
string,
VueI18n.TranslateResult | Record<'system' | 'user', VueI18n.TranslateResult>
>
/**
* Response structure for message retrieval operations
*/
export interface MessagesResponse {
messages: CopilotMessage[]
hasMore: boolean
}
/**
* Error structure for streaming operations
*/
export interface StreamError {
error: unknown
}
/**
* Props for the Copilot input component
*/
export interface CopilotInputProps {
value: string
disabled: boolean
}
/**
* Events emitted by the Copilot input component
*/
export interface CopilotInputEvents {
send: (message?: string) => void
'preset-change': (data: CopilotPresetPrompt) => void
focus: () => void
}
/**
* Props for the Copilot messages component
*/
export interface CopilotMessagesProps {
messages: CopilotMessage[]
isSending: boolean
responseStreamText: string
}
/**
* Events emitted by the Copilot messages component
*/
export interface CopilotMessagesEvents {
'load-more-messages': () => void
scrollToBottom: (behavior: ScrollBehavior) => void
}
/**
* Events emitted by the Copilot header component
*/
export interface CopilotHeaderEvents {
'clear-all-messages': () => void
'toggle-window': () => void
}
/**
* Option structure for preset prompts in dropdown menus
*/
export interface PresetPromptOption {
value: string
label: string | VueI18n.TranslateResult
children?: PresetPromptOption[]
allowedRoutes?: string[]
}
/**
* Type alias for AI model identifiers
*/
export type AIModel = Parameters<OpenAIProvider['chat']>[0]
/**
* Configuration for OpenAI models
*/
export interface OpenAIOptionsModel {
value: 'OpenAI'
children: { value: Parameters<OpenAIProvider['chat']>[0] }[]
providerCreator: typeof createOpenAI
}
/**
* Configuration for DeepSeek models
*/
export interface DeepSeekOptionsModel {
value: 'DeepSeek'
children: { value: Parameters<DeepSeekProvider['chat']>[0] }[]
providerCreator: typeof createDeepSeek
}
/**
* Configuration for Anthropic models
*/
export interface AnthropicOptionsModel {
value: 'Anthropic'
children: { value: Parameters<AnthropicProvider['languageModel']>[0] }[]
providerCreator: typeof createAnthropic
}
/**
* Configuration for xAI models
*/
export interface XaiOptionsModel {
value: 'xAI'
children: { value: Parameters<XaiProvider['chat']>[0] }[]
providerCreator: typeof createXai
}
/**
* Configuration for SiliconFlow models
*/
export interface SiliconFlowOptionsModel {
value: 'SiliconFlow'
children: {
value:
| 'deepseek-ai/DeepSeek-V3'
| 'deepseek-ai/DeepSeek-R1'
| 'Qwen/Qwen2-VL-72B-Instruct'
| 'Qwen/Qwen2.5-72B-Instruct'
| (string & {})
}[]
providerCreator: typeof createOpenAI
}
/**
* Union type of all AI model option configurations
*/
export type AImodelsOptionsModel = (
| OpenAIOptionsModel
| DeepSeekOptionsModel
| AnthropicOptionsModel
| XaiOptionsModel
| SiliconFlowOptionsModel
)[]
/**
* Type definition for prompt options
*/
export interface PromptOptionDefinition {
value: string
labelKey: string
prompt: string | { system: string; user: string }
params?: string[]
}
/**
* Session state interface
*/
export interface SessionState {
systemPrompt: string // Current system prompt for the session
presetPrompt: string // Current preset prompt being used
isNewSession: boolean // Whether this is a new session
lastPresetChangeTime: number // Timestamp of the last preset change
mcpData?: MCPPromptData // MCP data for prompts
}
/**
* Options for AI streaming configuration
*/
export interface AIStreamOptions {
temperature?: number
maxTokens?: number
topP?: number
frequencyPenalty?: number
presencePenalty?: number
disabledReasoningShow?: boolean
}
export interface ChatLoopOptions {
// Core control functions
shouldContinue: (content: string) => boolean
updateCallback: (message: CopilotMessage) => Promise<void>
// Optional configuration
formatAppend?: (current: string, next: string) => string
stopCondition?: (content: string) => boolean
maxTurns?: number
streamOptions?: AIStreamOptions
existingMessage: CopilotMessage
}