ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / prompt / node / intentDetector.tsx 652 строк · изменён 14 нояб., 04:52
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
import { BasePromptElementProps , PromptElement , PromptElementProps , PromptMetadata , Raw , SystemMessage , UserMessage } from '@vscode/prompt-tsx' ;
import type { CancellationToken , ChatContext , ChatParticipantDetectionProvider , ChatParticipantDetectionResult , ChatParticipantMetadata , ChatRequest , Uri , ChatLocation as VscodeChatLocation } from 'vscode' ;
import { getChatParticipantIdFromName
getAgentForIntent
@ logService
@ endpointProvider
@ telemetryService
@ configurationService
@ intentService
@ instantiationService
@ tabsAndEditorsService
@ experimentationService
chatRequest context options participants token
options options
selectedEndpoint chatRequest
selectedEndpoint
chatVariables chatRequest
turns accessor accessor context
detectedIntentId
shouldIncludeGitHub chatRequest
builtinParticipants options p p shouldIncludeGitHub p p
thirdPartyParticipants options p p p p
detectedIntent
options
chatRequest turns
chatRequest
token
chatVariables
builtinParticipants
turns
detectedIntent detectedIntent
detectedIntent
chatRequest ref ref
chatRequest
detectedIntentId detectedIntent
detectedIntent
detectedIntent
detectedIntentId detectedIntent
agent detectedIntent options
agent
overrideCommand agent agent agent agent
participant agent
command overrideCommand
thirdPartyParticipants options
detectedIntent
options
chatRequest
token
chatRequest
builtinParticipants
thirdPartyParticipants
turns
detectedIntent detectedIntent
detectedIntentId detectedIntent
detectedIntent
detectedIntentId
doc
docSnapshot doc doc
chatRequest
detectedIntentId
chatVariables
options
turns
docSnapshot
documentContext history messageText
preferredIntent
documentContext history length
documentContext documentContext documentContext
preferredIntent
documentContext documentContext documentContext
preferredIntent
messageText
preferredIntent
preferredIntent
documentContext
messageText
token
baseUserTelemetry
chatVariables
builtinParticipants
thirdPartyParticipants
history
builtinParticipants thirdPartyParticipants
endpoint
preferredIntent documentContext history messageText
promptRenderer
endpoint
preferredIntent
userQuestion messageText
documentContext
history
chatVariables
builtinParticipants builtinParticipants
thirdPartyParticipants thirdPartyParticipants
messages metadata promptRenderer token
fetchResult endpoint
messages
token
stop
max_tokens
intent fetchResult baseUserTelemetry messageText preferredIntent thirdPartyParticipants thirdPartyParticipants builtinParticipants documentContext
chosenIntent intent intent intent id intent participant
preferredIntent
chosenIntent
documentContext language
fileMetadata metadata
messageText
preferredIntent
fileMetadata filePath
fileMetadata fileExcerpt
chosenIntent
documentContext language
messages
intent
userQuery
assignedIntent
chatVariables
history
endpoint
messages currentSelection endpoint
messages conversationHistory endpoint history priority messages
history historyMessages fileExcerpt attachedContext fileExcerptExceedsBudget currentSelection content conversationHistory chatVariables
chatLocation
userQuery
history historyMessages
assignedIntent assignedIntent assignedIntent
assignedThirdPartyChatParticipant assignedIntent assignedIntent
assignedThirdPartyChatCommand assignedIntent assignedIntent
fileExcerpt fileExcerpt fileExcerptExceedsBudget
attachedContext attachedContext
e
message e e e
fetchResult
baseUserTelemetry
messageText
preferredIntent
participants
documentContext
fetchResult
baseUserTelemetry
baseUserTelemetry fetchResult
cleanedIntentResponses fetchResult intentResponse
intentResponse
cleanedIntentResponses cleanedIntentResponses i i
cleanedIntentResponses preferredIntent
cleanedIntentResponses preferredIntent
cleanedIntentResponses participants p p
participant
categoryNamesToParticipants participants acc participant
participant alias
acc alias participant participant command participant
acc
intent cleanedIntentResponses
r r categoryNamesToParticipants r
s s participant command s
chosenIntent intent intent intent id intent participant
chosenIntent
documentContext
documentContext
documentContext documentContext
editIntent
editIntent
intent editIntent
baseUserTelemetry
promptTelemetryData baseUserTelemetry
messageText
promptContext cleanedIntentResponses
intent chosenIntent
promptTelemetryData promptTelemetryData
intent
baseUserTelemetry
fetchResult type reason requestId
telemetryErrorData baseUserTelemetry
resultType fetchResult
reason fetchResult
telemetryErrorData telemetryErrorData
preferredIntent
detectedIntent
languageId
isRerunWithoutIntentDetection
chatLocation
preferredIntent preferredIntent
detectedIntent detectedIntent
languageId languageId
isRerunWithoutIntentDetection isRerunWithoutIntentDetection
fileExcerpt historyMessages attachedContext
telemetryBudget
names
attachedContext
attachment attachedContext
nameLength attachment
telemetryBudget nameLength
telemetryBudget nameLength
names attachment
fileExcerptExceedsBudget
fileExcerpt
fileExcerptSize fileExcerpt
fileExcerptSize telemetryBudget
fileExcerptExceedsBudget
fileExcerpt
telemetryBudget fileExcerptSize
fileExcerpt
history
i historyMessages i i
message historyMessages i
text
textLength text
telemetryBudget textLength
history text
telemetryBudget textLength
fileExcerpt fileExcerptExceedsBudget history history attachedContext names
request
preferredIntent
currentFilePath
fileExerpt
detectedIntent
languageId
isRerunWithoutIntentDetection
historyMessages
fileExcerpt history fileExerpt historyMessages
chatLocation
request
preferredIntent preferredIntent
filePath currentFilePath
fileExerpt fileExcerpt
detectedIntent detectedIntent
languageId languageId
isRerunWithoutIntentDetection isRerunWithoutIntentDetection
history history
fileExcerpt
filePath
history
preferredIntent
userQuestion
documentContext
chatVariables
builtinParticipants
thirdPartyParticipants
props
@ _ignoreService
@ _configurationService
@ _intentService
props
builtinParticipants
preferredIntent
userQuestion
documentContext
currentFileUri
currentFileContext
fileExcerptCodeBlock
documentContext documentContext
selection documentContext
currentFileUri
range
selection
selection selection
currentFileContext range
fileExcerptCodeBlock currentFileContext
_e
fileMetadata currentFileContext currentFileUri path
documentContext documentContext
builtinParticipants builtinParticipants participant participant
participant
seen
a participant p p
a value
seen value
seen value
currentFileUri fileExcerptCodeBlock
fileExcerptCodeBlock preferredIntent userQuestion builtinParticipants alias
alias alias
builtinParticipants alias
alias alias
userQuestion
includeDynamicParticipants
participants
override
p
p alias
alias alias alias alias alias example
override
history chatVariables userQuestion
CHAT_PARTICIPANT_ID_PREFIX
,
}
from
'../../../platform/chat/common/chatAgents'
;
import
{ ChatFetchResponseType , ChatLocation , ChatResponse }
from
'../../../platform/chat/common/commonTypes'
;
import
{ getTextPart, roleToString }
from
'../../../platform/chat/common/globalStringUtils'
;
import
{ ConfigKey , IConfigurationService }
from
'../../../platform/configuration/common/configurationService'
;
import
{ TextDocumentSnapshot }
from
'../../../platform/editing/common/textDocumentSnapshot'
;
import
{ IEndpointProvider }
from
'../../../platform/endpoint/common/endpointProvider'
;
import
{ IIgnoreService }
from
'../../../platform/ignore/common/ignoreService'
;
import
{ ILogService }
from
'../../../platform/log/common/logService'
;
import
{ ITabsAndEditorsService }
from
'../../../platform/tabs/common/tabsAndEditorsService'
;
import
{ IExperimentationService }
from
'../../../platform/telemetry/common/nullExperimentationService'
;
import
{ ITelemetryService }
from
'../../../platform/telemetry/common/telemetry'
;
import
{ isNotebookCellOrNotebookChatInput }
from
'../../../util/common/notebooks'
;
import
{ isFalsyOrEmpty }
from
'../../../util/vs/base/common/arrays'
;
import
{ IInstantiationService }
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ Position , Range }
from
'../../../vscodeTypes'
;
import
{
,
GITHUB_PLATFORM_AGENT
,
Intent
}
from
'../../common/constants'
;
import
{ IIntentService }
from
'../../intents/node/intentService'
;
import
{ UnknownIntent }
from
'../../intents/node/unknownIntent'
;
import
{ InstructionMessage }
from
'../../prompts/node/base/instructionMessage'
;
import
{ PromptRenderer , renderPromptElement }
from
'../../prompts/node/base/promptRenderer'
;
import
{ ChatVariablesAndQuery }
from
'../../prompts/node/panel/chatVariables'
;
import
{ ConversationHistory , HistoryWithInstructions }
from
'../../prompts/node/panel/conversationHistory'
;
import
{ CurrentSelection }
from
'../../prompts/node/panel/currentSelection'
;
import
{ CodeBlock }
from
'../../prompts/node/panel/safeElements'
;
import
{ getToolName }
from
'../../tools/common/toolNames'
;
import
{ CodebaseTool }
from
'../../tools/node/codebaseTool'
;
import
{ ChatVariablesCollection }
from
'../common/chatVariablesCollection'
;
import
{ Turn }
from
'../common/conversation'
;
import
{ addHistoryToConversation }
from
'./chatParticipantRequestHandler'
;
import
{ IDocumentContext }
from
'./documentContext'
;
import
{ IIntent }
from
'./intents'
;
import
{ ConversationalBaseTelemetryData }
from
'./telemetry'
;
export
class
IntentDetector
implements
ChatParticipantDetectionProvider
{
constructor
(
ILogService
private
readonly
:
ILogService
,
IEndpointProvider
private
readonly
:
IEndpointProvider
,
ITelemetryService
private
readonly
:
ITelemetryService
,
IConfigurationService
private
readonly
:
IConfigurationService
,
IIntentService
private
readonly
:
IIntentService
,
IInstantiationService
private
readonly
:
IInstantiationService
,
ITabsAndEditorsService
private
readonly
:
ITabsAndEditorsService
,
IExperimentationService
private
readonly
:
IExperimentationService
,
)
{
}
async
provideParticipantDetection
(
:
ChatRequest
,
:
ChatContext
,
:
{
?
:
ChatParticipantMetadata
[
]
;
location
:
VscodeChatLocation
}
,
:
CancellationToken
)
:
Promise
<
ChatParticipantDetectionResult
|
null
|
undefined
>
{
if
(
(
.
location
!==
ChatLocation
.
Panel
&&
.
location
!==
ChatLocation
.
Editor
)
||
this
.
configurationService
.
getNonExtensionConfig
(
'chat.detectParticipant.enabled'
)
===
false
)
{
return
;
}
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
)
;
if
(
.
family
.
startsWith
(
'o1'
)
)
{
return
;
}
const
=
new
ChatVariablesCollection
(
.
references
)
;
const
{
}
=
this
.
instantiationService
.
invokeFunction
(
=>
addHistoryToConversation
(
,
.
history
)
)
;
let
:
string
|
ChatParticipantDetectionResult
|
undefined
;
const
=
(
.
toolReferences
.
length
===
0
)
;
const
=
.
participants
?.
filter
(
=>
(
(
.
participant
===
GITHUB_PLATFORM_AGENT
&&
)
||
.
participant
.
startsWith
(
CHAT_PARTICIPANT_ID_PREFIX
)
)
&&
.
disambiguation
.
length
)
??
[
]
;
const
=
.
participants
?.
filter
(
=>
.
participant
!==
GITHUB_PLATFORM_AGENT
&&
!
.
participant
.
startsWith
(
CHAT_PARTICIPANT_ID_PREFIX
)
&&
.
disambiguation
.
length
)
??
[
]
;
try
{
const
=
await
this
.
detectIntent
(
.
location
,
IDocumentContext
.
inferDocumentContext
(
,
this
.
tabsAndEditorsService
.
activeTextEditor
,
)
,
.
prompt
,
,
undefined
,
,
,
undefined
,
,
)
;
if
(
&&
'participant'
in
)
{
if
(
.
participant
===
getChatParticipantIdFromName
(
'workspace'
)
)
{
if
(
.
toolReferences
.
find
(
(
)
=>
getToolName
(
.
name
)
===
CodebaseTool
.
toolName
)
)
{
return
undefined
;
}
if
(
this
.
configurationService
.
getExperimentBasedConfig
<
boolean
>
(
ConfigKey
.
TeamInternal
.
AskAgent
,
this
.
experimentationService
)
&&
.
model
.
capabilities
.
supportsToolCalling
)
{
return
undefined
;
}
}
=
;
return
;
}
else
if
(
)
{
=
.
id
;
const
=
getAgentForIntent
(
.
id
as
Intent
,
.
location
)
;
if
(
)
{
const
=
.
agent
===
Intent
.
Editor
&&
(
.
command
===
Intent
.
Edit
||
.
command
===
Intent
.
Generate
)
?
undefined
:
.
command
;
return
{
:
getChatParticipantIdFromName
(
.
agent
)
,
:
,
}
;
}
}
else
if
(
.
length
&&
.
location
===
ChatLocation
.
Panel
)
{
const
=
await
this
.
detectIntent
(
.
location
,
undefined
,
.
prompt
,
,
undefined
,
new
ChatVariablesCollection
(
.
references
)
,
,
,
,
)
;
if
(
&&
'participant'
in
)
{
=
;
return
;
}
}
}
finally
{
if
(
)
{
const
=
this
.
tabsAndEditorsService
.
activeTextEditor
?.
document
;
const
=
?
TextDocumentSnapshot
.
create
(
)
:
undefined
;
this
.
collectIntentDetectionContextInternal
(
.
prompt
,
,
,
.
location
,
.
slice
(
0
,
-
1
)
,
)
;
}
}
}
private
async
getPreferredIntent
(
location
:
ChatLocation
,
:
IDocumentContext
|
undefined
,
?
:
readonly
Turn
[
]
,
?
:
string
)
{
let
:
Intent
|
undefined
;
if
(
location
===
ChatLocation
.
Editor
&&
&&
!
?.
)
{
if
(
.
selection
.
isEmpty
&&
.
document
.
lineAt
(
.
selection
.
start
.
line
)
.
text
.
trim
(
)
===
''
)
{
=
Intent
.
Generate
;
}
else
if
(
!
.
selection
.
isEmpty
&&
.
selection
.
start
.
line
!==
.
selection
.
end
.
line
)
{
=
Intent
.
Edit
;
}
}
if
(
?.
trimStart
(
)
.
startsWith
(
'/fixTestFailure'
)
)
{
=
Intent
.
Fix
;
}
return
;
}
async
detectIntent
(
location
:
ChatLocation
,
:
IDocumentContext
|
undefined
,
:
string
,
:
CancellationToken
,
:
ConversationalBaseTelemetryData
|
undefined
,
:
ChatVariablesCollection
,
:
ChatParticipantMetadata
[
]
,
?
:
ChatParticipantMetadata
[
]
,
?
:
readonly
Turn
[
]
,
)
:
Promise
<
IIntent
|
ChatParticipantDetectionResult
|
undefined
>
{
this
.
logService
.
trace
(
'Building intent detector'
)
;
if
(
.
length
===
0
&&
(
isFalsyOrEmpty
(
)
)
)
{
this
.
logService
.
trace
(
'No participants available for intent detection'
)
;
return
undefined
;
}
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
;
const
=
await
this
.
getPreferredIntent
(
location
,
,
,
)
;
const
=
PromptRenderer
.
create
(
this
.
instantiationService
,
,
(
location
===
ChatLocation
.
Editor
?
IntentDetectionPrompt
:
GPT4OIntentDetectionPrompt
)
,
{
,
location
,
:
,
,
,
,
:
,
:
,
}
)
;
const
{
,
}
=
await
.
render
(
undefined
,
)
;
this
.
logService
.
trace
(
'Built intent detector'
)
;
const
=
await
.
makeChatRequest
(
'intentDetection'
,
,
undefined
,
,
location
,
undefined
,
{
:
[
';'
]
,
:
20
}
)
;
const
=
this
.
validateResult
(
,
,
,
location
,
,
?
:
,
)
;
const
=
&&
'id'
in
?
?.
:
?.
;
this
.
sendTelemetry
(
,
,
?.
.
languageId
,
undefined
,
location
)
;
const
=
.
get
(
DocumentExcerptInfo
)
;
this
.
sendInternalTelemetry
(
,
,
?.
,
?.
,
,
?.
.
languageId
,
undefined
,
.
slice
(
0
,
-
1
)
,
location
)
;
return
;
}
async
collectIntentDetectionContextInternal
(
:
string
,
:
string
|
ChatParticipantDetectionResult
,
:
ChatVariablesCollection
,
location
:
ChatLocation
,
:
Turn
[
]
=
[
]
,
document
?
:
TextDocumentSnapshot
)
{
try
{
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
;
const
{
:
}
=
await
renderPromptElement
(
this
.
instantiationService
,
,
CurrentSelection
,
{
document
}
)
;
const
{
:
}
=
await
renderPromptElement
(
this
.
instantiationService
,
,
ConversationHistory
,
{
,
:
1000
}
,
undefined
,
undefined
)
.
catch
(
(
)
=>
(
{
:
[
]
}
)
)
;
const
{
:
,
,
,
}
=
this
.
prepareInternalTelemetryContext
(
getTextPart
(
?.
[
0
]
?.
)
,
,
)
;
this
.
telemetryService
.
sendInternalMSFTTelemetryEvent
(
'participantDetectionContext'
,
{
:
ChatLocation
.
toString
(
location
)
,
,
:
.
join
(
''
)
,
:
typeof
===
'string'
?
:
undefined
,
:
typeof
!==
'string'
?
.
participant
:
undefined
,
:
typeof
!==
'string'
?
.
command
:
undefined
,
:
??
(
?
'<truncated>'
:
'<none>'
)
,
:
.
join
(
';'
)
}
,
{
}
)
;
}
catch
(
)
{
const
=
instanceof
Error
?
.
message
:
String
(
)
;
this
.
logService
.
warn
(
` [IntentDetector] Skipping participant detection context telemetry: ${ message} `
)
;
}
}
private
validateResult
(
:
ChatResponse
,
:
ConversationalBaseTelemetryData
|
undefined
,
:
string
,
location
:
ChatLocation
,
?
:
Intent
,
?
:
ChatParticipantMetadata
[
]
,
?
:
IDocumentContext
|
undefined
,
)
:
IIntent
|
ChatParticipantDetectionResult
|
undefined
{
if
(
.
type
!==
ChatFetchResponseType
.
Success
)
{
if
(
)
{
this
.
sendPromptIntentErrorTelemetry
(
,
)
;
}
return
undefined
;
}
let
=
[
.
value
]
.
map
(
=>
.
trimStart
(
)
.
split
(
'\n'
)
[
0
]
.
replaceAll
(
'```'
,
''
)
.
replace
(
/ function id:| response: / i
,
''
)
.
trim
(
)
)
;
=
.
filter
(
=>
!==
UnknownIntent
.
ID
)
;
if
(
!
.
length
&&
)
{
=
[
]
;
}
if
(
(
[
0
]
===
'github_questions'
)
&&
?.
find
(
=>
.
participant
===
GITHUB_PLATFORM_AGENT
)
)
{
return
{
:
GITHUB_PLATFORM_AGENT
}
;
}
const
=
?.
reduce < { [ categoryName: string ] : { participant: string ; command? : string } } >
(
(
,
)
=>
{
.
disambiguation
.
forEach
(
(
)
=>
{
[
.
category
]
=
{
:
.
participant
,
:
.
command
}
;
}
)
;
return
;
}
,
{
}
)
;
let
=
.
map
(
=>
this
.
intentService
.
getIntent
(
,
location
)
??
?.
[
]
)
.
filter
(
(
)
:
is
(
IIntent
|
{
:
string
;
?
:
string
}
)
=>
!==
undefined
)
?.
[
0
]
;
const
=
&&
'id'
in
?
?.
:
?.
;
this
.
logService
.
debug
(
` picked intent " ${ chosenIntent} " from ${ JSON . stringify ( fetchResult. value, null , '\t' ) } `
)
;
if
(
location
===
ChatLocation
.
Editor
&&
===
Intent
.
Edit
&&
&&
.
selection
.
isEmpty
&&
.
document
.
lineAt
(
.
selection
.
start
.
line
)
.
text
.
trim
(
)
===
''
)
{
const
=
this
.
intentService
.
getIntent
(
Intent
.
Generate
,
ChatLocation
.
Editor
)
;
if
(
)
{
=
;
}
}
if
(
)
{
const
=
.
extendedBy
(
{
,
:
.
join
(
)
,
:
||
'unknown'
,
}
)
;
this
.
telemetryService
.
sendEnhancedGHTelemetryEvent
(
'conversation.promptIntent'
,
.
raw
.
properties
,
.
raw
.
measurements
)
;
}
return
;
}
private
sendPromptIntentErrorTelemetry
(
:
ConversationalBaseTelemetryData
,
:
{
:
string
;
:
string
;
:
string
}
)
{
const
=
.
extendedBy
(
{
:
.
type
,
:
.
reason
,
}
)
;
this
.
telemetryService
.
sendEnhancedGHTelemetryErrorEvent
(
'conversation.promptIntentError'
,
.
raw
.
properties
,
.
raw
.
measurements
)
;
}
private
sendTelemetry
(
:
Intent
|
undefined
,
:
string
|
undefined
,
:
string
|
undefined
,
:
boolean
|
undefined
,
location
:
ChatLocation
)
{
this
.
telemetryService
.
sendMSFTTelemetryEvent
(
'intentDetection'
,
{
:
ChatLocation
.
toString
(
location
)
,
:
??
'<none>'
,
:
??
'<none>'
,
:
??
'<none>'
,
:
String
(
)
??
'<none>'
,
}
)
;
}
private
prepareInternalTelemetryContext
(
:
string
|
undefined
,
:
Raw
.
ChatMessage
[
]
,
?
:
ChatVariablesCollection
)
{
let
=
5000
;
const
:
string
[
]
=
[
]
;
if
(
)
{
for
(
const
of
)
{
const
=
Buffer
.
byteLength
(
.
uniqueName
,
'utf8'
)
;
if
(
-
<
0
)
{
break
;
}
-=
;
.
push
(
.
uniqueName
)
;
}
}
let
=
false
;
if
(
)
{
const
=
Buffer
.
byteLength
(
,
'utf8'
)
;
if
(
>
)
{
=
true
;
=
undefined
;
}
else
{
-=
;
}
}
else
{
=
undefined
;
}
const
:
string
[
]
=
[
]
;
for
(
let
=
.
length
-
1
;
>=
0
;
-=
1
)
{
const
=
[
]
;
const
=
` ${ roleToString ( message. role) . toUpperCase ( ) } : ${ message. content} \n\n `
;
const
=
Buffer
.
byteLength
(
,
'utf8'
)
;
if
(
-
<
0
)
{
break
;
}
.
push
(
)
;
-=
;
}
return
{
,
,
:
.
reverse
(
)
,
:
}
;
}
private
sendInternalTelemetry
(
:
string
,
:
Intent
|
undefined
,
:
string
|
undefined
,
:
string
|
undefined
,
:
string
|
undefined
,
:
string
|
undefined
,
:
boolean
|
undefined
,
:
Raw
.
ChatMessage
[
]
,
location
:
ChatLocation
)
{
const
{
,
}
=
this
.
prepareInternalTelemetryContext
(
,
)
;
this
.
telemetryService
.
sendInternalMSFTTelemetryEvent
(
'intentDetection'
,
{
:
ChatLocation
.
toString
(
location
)
,
,
:
??
'<none>'
,
:
??
'<none>'
,
:
??
'<none>'
,
:
??
'<none>'
,
:
??
'<none>'
,
:
String
(
)
??
'<none>'
,
:
.
join
(
''
)
}
,
{
}
)
;
}
}
class
DocumentExcerptInfo
extends
PromptMetadata
{
constructor
(
readonly
:
string
|
undefined
,
readonly
:
string
|
undefined
,
)
{
super
(
)
;
}
}
type
IntentDetectionPromptProps
=
PromptElementProps
<
{
?
:
readonly
Turn
[
]
;
:
Intent
|
undefined
;
location
:
ChatLocation
;
:
string
;
:
IDocumentContext
|
undefined
;
:
ChatVariablesCollection
;
:
ChatParticipantMetadata
[
]
;
?
:
ChatParticipantMetadata
[
]
;
}
>
;
class
IntentDetectionPrompt
extends
PromptElement< IntentDetectionPromptProps>
{
constructor
(
:
IntentDetectionPromptProps
,
IIgnoreService
protected
readonly
:
IIgnoreService
,
IConfigurationService
protected
readonly
:
IConfigurationService
,
IIntentService
protected
readonly
:
IIntentService
,
)
{
super
(
)
;
}
async
render
(
)
{
let
{
,
,
,
,
}
=
this
.
props
;
let
:
Uri
|
undefined
;
let
:
string
|
undefined
;
let
:
CodeBlock
|
undefined
;
try
{
if
(
!==
undefined
&&
!
(
await
this
.
_ignoreService
.
isCopilotIgnored
(
.
document
.
uri
)
)
)
{
const
{
document
,
}
=
;
=
document
.
uri
;
const
=
new
Range
(
new
Position
(
Math
.
max
(
.
start
.
line
-
5
,
0
)
,
0
)
,
new
Position
(
Math
.
min
(
.
end
.
line
+
5
,
document
.
lineCount
)
,
document
.
lineAt
(
.
end
.
line
)
.
text
.
length
)
,
)
;
=
document
.
getText
(
)
;
=
.
trim
(
)
.
length
>
0
?
< CodeBlock uri = { currentFileUri} languageId = { document . languageId } code = { currentFileContext} shouldTrim = { false } />
:
undefined
;
}
}
catch
(
)
{
}
const
=
new
DocumentExcerptInfo
(
,
?.
)
;
if
(
!==
undefined
&&
isNotebookCellOrNotebookChatInput
(
.
document
.
uri
)
)
{
=
.
filter
(
(
)
=>
.
command
!==
'tests'
)
;
}
function
commands
(
:
ChatParticipantMetadata
[
]
)
{
const
=
new
Set< string >
(
)
;
const
=
.
flatMap
(
(
)
=>
.
disambiguation
)
;
return
.
filter
(
=>
{
if
(
.
has
(
.
category
)
)
{
return
false
;
}
.
add
(
.
category
)
;
return
true
;
}
)
;
}
return
(
< >
< meta value = { fileMetadata} />
< SystemMessage >
When asked for your name, you must respond with "GitHub Copilot".
< br />
Follow the user's requirements carefully & to the letter.
< br />
</ SystemMessage >
< UserMessage >
A software developer is using an AI chatbot in a code editor
{
&&
` in file ${ currentFileUri. path} `
}
.
< br />
{
===
undefined
?
< br />
:
< >
Current active file contains following excerpt:
< br />
{
}
< br />
</ >
}
The developer added the following request to the chat and your goal is to select a function to perform the request.
< br />
{
&&
` The developer probably wants Function Id ' ${ preferredIntent} ', pick different only if you're certain. `
}
< br />
Request:
{
}
< br />
< br />
Available functions:
< br />
{
commands
(
)
.
map
(
(
)
=>
< >
Function Id:
{
.
category
}
< br />
Function Description:
{
.
description
}
< br />
< br />
</ >
)
}
< br />
Here are some examples to make the instructions clearer:
< br />
{
commands
(
)
.
map
(
(
)
=>
< >
Request:
{
.
examples
[
0
]
}
< br />
Response:
{
.
category
}
< br />
< br />
</ >
)
}
Request:
{
}
< br />
Response:
</ UserMessage >
</ >
)
;
}
}
interface
BuiltinParticipantDescriptionsProps
extends
BasePromptElementProps
{
:
boolean
;
:
ChatParticipantMetadata
[
]
;
}
class
ParticipantDescriptions
extends
PromptElement< BuiltinParticipantDescriptionsProps>
{
render
(
)
{
return
(
< >
{
this
.
props
.
participants
.
flatMap
(
(
)
=>
{
return
.
disambiguation
.
map
(
(
)
=>
{
return
(
< >
|
{
.
category
??
(
as
any
)
.
categoryName
}
|
{
.
description
}
|
{
.
examples
.
length
?
.
examples
.
map
(
=>
` " ${ example} " `
)
.
join
(
', '
)
:
'--'
}
|
< br />
</ >
)
;
}
)
;
}
)
}
{
this
.
props
.
includeDynamicParticipants
&&
< >
| github_questions | The user is asking about an issue, pull request, branch, commit hash, diff, discussion, repository, or published release on GitHub.com. This category does not include performing local Git operations using the CLI. | "What has been changed in the pull request 1361 in browserify/browserify repo?" |
< br />
</ >
}
{
this
.
props
.
includeDynamicParticipants
&&
< >
| web_questions | The user is asking a question that requires current knowledge from a web search engine. Such questions often reference time periods that exceed your knowledge cutoff. | "What is the latest LTS version of Node.js?" |
< br />
</ >
}
| unknown | The user's question does not fit exactly one of the categories above, is about a product other than Visual Studio Code or GitHub, or is a general question about code, code errors, or software engineering. | "How do I center a div in CSS?" |
< br />
</ >
)
;
}
}
export
class
GPT4OIntentDetectionPrompt
extends
IntentDetectionPrompt
{
render
(
)
{
const
{
,
,
}
=
this
.
props
;
return
(
< >
< HistoryWithInstructions history = { history || [ ] } passPriority historyPriority = { 800 } >
< InstructionMessage >
You are a helpful AI programming assistant to a user who is a software engineer, acting on behalf of the Visual Studio Code editor. Your task is to choose one category from the Markdown table of categories below that matches the user's question. Carefully review the user's question, any previous messages, and any provided context such as code snippets. Respond with just the category name. Your chosen category will help Visual Studio Code provide the user with a higher-quality response, and choosing incorrectly will degrade the user's experience of using Visual Studio Code, so you must choose wisely. If you cannot choose just one category, or if none of the categories seem like they would provide the user with a better result, you must always respond with "unknown".
< br />
< br />
| Category name | Category description | Example of matching question |
< br />
| -- | -- | -- |
< br />
< ParticipantDescriptions participants = { this . props . thirdPartyParticipants ? this . props . thirdPartyParticipants : this . props . builtinParticipants } includeDynamicParticipants = { ! this . props . thirdPartyParticipants } />
</ InstructionMessage >
</ HistoryWithInstructions >
{
< ChatVariablesAndQuery query = { userQuestion} chatVariables = { chatVariables} priority = { 900 } embeddedInsideUserMessage = { false } />
}
</ >
)
;
}
}