-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathai.ts
More file actions
115 lines (107 loc) · 3.15 KB
/
Copy pathai.ts
File metadata and controls
115 lines (107 loc) · 3.15 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
import { registerExtension } from '@codingame/monaco-vscode-api/extensions'
import { ExtensionHostKind } from '@codingame/monaco-vscode-extensions-service-override'
import * as vscode from 'vscode'
export async function registerAiChat() {
const { getApi } = registerExtension(
{
name: 'xydStudioAi',
publisher: 'xyd',
version: '1.0.0',
engines: { vscode: '*' },
contributes: {
chatParticipants: [
{
id: 'xyd.studio.participant',
fullName: 'xyd AI',
name: 'xyd',
isDefault: true,
modes: ['agent'],
locations: ['panel', 'terminal', 'editor'],
},
],
languageModelChatProviders: [
{
vendor: 'copilot',
displayName: 'xyd AI provider',
},
],
},
enabledApiProposals: [
'defaultChatParticipant',
'chatParticipantAdditions',
'chatParticipantPrivate',
'languageModelThinkingPart',
'chatProvider',
],
},
ExtensionHostKind.LocalProcess,
{ system: true }
)
const vscodeApi = await getApi()
// Register language model provider (mock - streams a demo response)
const eventEmitter = new vscodeApi.EventEmitter<void>()
vscodeApi.lm.registerLanguageModelChatProvider('copilot', {
provideLanguageModelChatInformation() {
return [
{
id: 'auto',
capabilities: { toolCalling: false },
family: 'xyd',
maxInputTokens: 100000,
maxOutputTokens: 100000,
name: 'xyd AI',
version: '1.0.0',
isDefault: true,
isUserSelectable: true,
},
]
},
async provideTokenCount() {
return 0
},
async provideLanguageModelChatResponse(
_model: any,
_messages: any,
_options: any,
progress: any
) {
// Demo: stream a response about xyd
const parts = [
"I'm **xyd AI** — ",
'your documentation assistant. ',
'I can help you with:\n\n',
'- Configuring `docs.json`\n',
'- Writing Markdown/MDX content\n',
'- Setting up OpenAPI documentation\n',
'- Choosing and customizing themes\n',
'- Installing and configuring plugins\n\n',
'_This is a demo response. ',
'Connect a real LLM backend to get actual AI assistance._',
]
for (const part of parts) {
progress.report(new vscodeApi.LanguageModelTextPart(part))
await new Promise((r) => setTimeout(r, 100))
}
},
onDidChangeLanguageModelChatInformation: eventEmitter.event,
})
// Register chat participant
vscodeApi.chat.createChatParticipant(
'xyd.studio.participant',
async (
request: any,
_context: any,
response: any
) => {
const modelResponse = await request.model.sendRequest([
vscodeApi.LanguageModelChatMessage.User(request.prompt),
])
for await (const part of modelResponse.stream) {
if (part instanceof vscode.LanguageModelTextPart) {
response.markdown(part.value)
}
}
}
)
console.log('[xyd studio] AI chat registered')
}