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 / prompts / node / panel / chatVariables.tsx 559 строк · изменён 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
import { BasePromptElementProps , PromptElement , PromptElementProps , PromptPiece , PromptReference , PromptSizing , TextChunk , UserMessage } from '@vscode/prompt-tsx' ;
import type { Diagnostic , LanguageModelToolInformation } from 'vscode' ;
import { ChatFetchResponseType , ChatLocation } from '../../../../platform/chat/common/commonTypes' ;
import { ConfigKey ,
chatVariables
includeFilepath
omitReferences
isAgent
useFixCookbook
omitFileContents
props
@ fileSystemService
@ configurationService
@ experimentationService
props
override state sizing
omitFileContents
elements omitFileContents
elements
embeddedInsideUserMessageDefault
elements elements
elements element element
chatVariables
query
props
props
override state sizing
promptFiles
v
v
promptFiles
userMessage
promptFiles userMessage
query chatVariables
match query chatVariables
match
match
query
query
chatVariables
maintainOrder
includeFilepath
omitReferences
omitFileContents
props
@ fileSystemService
props
override state sizing
chatVariables
elements chatVariables
embeddedInsideUserMessageDefault
elements
elements elements
elements element element
element priority
element
chatVariables fileSystemService includeFilepathInCodeBlocks alwaysIncludeSummary omitReferences isAgent useFixCookbook omitFileContents
elements
filePathMode isAgent includeFilepathInCodeBlocks
includeFilepathInCodeBlocks
variable chatVariables
uniqueName variableName value variableValue reference variable
variable variable variable
variable
elements
variableValue variableValue
uri variableValue variableValue variableValue
isDirectory
stat fileSystemService uri
isDirectory stat
isDirectory
elements
file
isAgent variableValue variableValue
elements file
variableValue variableValue
elements
variableValue
elements
omitReferences reference reference variableValue
variableValue
elements
variableValue
elements
elements
diagnostics uri diagnostics
useCookbook
diagnosticSeverityMap
props
@ promptPathRepresentationService
@ workspaceService
@ fixCookbookService
@ alternativeNotebookContent
@ endpoint
props
uri diagnostics
diagnostics d
range d
uri range uri range
cookbook
doc doc doc uri
lang doc doc uri
cookbook lang d
d cookbook
uri range
uri
uri range
notebook cell uri
notebook cell
uri range
range cell range cell
uri range
altDocument notebook
start altDocument cell range
end altDocument cell range
newRange start end
notebook newRange
diagnostic
code diagnostic diagnostic diagnostic diagnostic
code
variableName
folderUri
omitReferences
description
omitContents
props
@ instantiationService
@ promptPathRepresentationService
props
override sizing
accessor
accessor maxLength excludeDotFiles
state
folderPath
state state
name
value
props
@ instantiationService
@ toolsService
@ logService
@ endpointProvider
@ promptEndpoint
@ telemetryService
props
override state sizing _progress token
tools toolCallResults
tools tools
results
toolReference tools
tool toolReference
tool
toolCallResults toolReference
results name toolReference value toolCallResults toolReference
toolArgsEndpoint
internalToolArgs toolReference
toolArgs tool toolArgsEndpoint
name toolReference toolReference toolReference
result tool input toolArgs internalToolArgs toolInvocationToken tools token
tool result
conversationId sessionId
requestId
results name value result
err
errResult err
results name value errResult
embeddedInsideUserMessageDefault
tools results
tools results
tools results priority
results toolResult i tools i toolResult priority
id toolResult priority
tool endpoint
ownTool tool
ownTool provideInput
input ownTool
input
input
tool tool
argFetchProps
promptContext
tools
toolTokens endpoint tool
messages endpoint modelMaxPromptTokens endpoint toolTokens argFetchProps
fnCall
fetchResult endpoint
messages
text _ delta
delta
fnCall delta
tools
endpoint
type
name tool
description tool
parameters tool
tool rule
tool_choice
type
name tool
fnCall
fetchResult
args fnCall
args
e
e
IConfigurationService
}
from
'../../../../platform/configuration/common/configurationService'
;
import
{ IEndpointProvider }
from
'../../../../platform/endpoint/common/endpointProvider'
;
import
{ IFileSystemService }
from
'../../../../platform/filesystem/common/fileSystemService'
;
import
{ FileType }
from
'../../../../platform/filesystem/common/fileTypes'
;
import
{ ILogService }
from
'../../../../platform/log/common/logService'
;
import
{ ICopilotToolCall }
from
'../../../../platform/networking/common/fetch'
;
import
{ IChatEndpoint }
from
'../../../../platform/networking/common/networking'
;
import
{ IAlternativeNotebookContentService }
from
'../../../../platform/notebook/common/alternativeContent'
;
import
{ IPromptPathRepresentationService }
from
'../../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ IExperimentationService }
from
'../../../../platform/telemetry/common/nullExperimentationService'
;
import
{ ITelemetryService }
from
'../../../../platform/telemetry/common/telemetry'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ getLanguage, getLanguageForResource }
from
'../../../../util/common/languages'
;
import
{ createFencedCodeBlock }
from
'../../../../util/common/markdown'
;
import
{ getNotebookAndCellFromUri }
from
'../../../../util/common/notebooks'
;
import
{ isLocation }
from
'../../../../util/common/types'
;
import
{ CancellationToken }
from
'../../../../util/vs/base/common/cancellation'
;
import
{ Schemas }
from
'../../../../util/vs/base/common/network'
;
import
{ isEqual }
from
'../../../../util/vs/base/common/resources'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{ IInstantiationService }
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ DiagnosticSeverity }
from
'../../../../util/vs/workbench/api/common/extHostTypes/diagnostic'
;
import
{ ChatReferenceBinaryData , ChatReferenceDiagnostic , LanguageModelToolResult2 , Range , Uri }
from
'../../../../vscodeTypes'
;
import
{ GenericBasePromptElementProps }
from
'../../../context/node/resolvers/genericPanelIntentInvocation'
;
import
{ ChatVariablesCollection , isCustomizationsIndex, isInstructionFile, isPromptFile, isSessionReference, parseSlashCommand, sessionReferenceAttachmentAttrs }
from
'../../../prompt/common/chatVariablesCollection'
;
import
{ InternalToolReference }
from
'../../../prompt/common/intents'
;
import
{ ToolName }
from
'../../../tools/common/toolNames'
;
import
{ normalizeToolSchema }
from
'../../../tools/common/toolSchemaNormalizer'
;
import
{ IToolsService }
from
'../../../tools/common/toolsService'
;
import
{ EmbeddedInsideUserMessage , embeddedInsideUserMessageDefault }
from
'../base/promptElement'
;
import
{ IPromptEndpoint , PromptRenderer }
from
'../base/promptRenderer'
;
import
{ Tag }
from
'../base/tag'
;
import
{ DiagnosticSuggestedFix }
from
'../inline/diagnosticsContext'
;
import
{ Cookbook , IFixCookbookService }
from
'../inline/fixCookbookService'
;
import
{ SummarizedDocumentLineNumberStyle }
from
'../inline/summarizedDocument/implementation'
;
import
{ FilePathMode , FileVariable }
from
'./fileVariable'
;
import
{ Image }
from
'./image'
;
import
{ NotebookCellOutputVariable }
from
'./notebookVariables'
;
import
{ PanelChatBasePrompt }
from
'./panelChatBasePrompt'
;
import
{ PromptFile }
from
'./promptFile'
;
import
{ sendInvokedToolTelemetry, toolCallErrorToResult, ToolResult , ToolResultMetadata }
from
'./toolCalling'
;
import
{ IFileTreeData , workspaceVisualFileTree }
from
'./workspace/visualFileTree'
;
export
interface
ChatVariablesProps
extends
BasePromptElementProps
,
EmbeddedInsideUserMessage
{
readonly
:
ChatVariablesCollection
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
}
export
class
ChatVariables
extends
PromptElement< ChatVariablesProps, void >
{
constructor
(
:
ChatVariablesProps
,
IFileSystemService
private
readonly
:
IFileSystemService
,
IConfigurationService
private
readonly
:
IConfigurationService
,
IExperimentationService
private
readonly
:
IExperimentationService
,
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
:
Promise
<
PromptPiece
<
any
,
any
>
|
undefined
>
{
const
=
this
.
props
.
omitFileContents
??
(
this
.
props
.
isAgent
&&
this
.
configurationService
.
getExperimentBasedConfig
(
ConfigKey
.
Advanced
.
AgentOmitFileAttachmentContents
,
this
.
experimentationService
)
)
;
const
=
await
renderChatVariables
(
this
.
props
.
chatVariables
,
this
.
fileSystemService
,
this
.
props
.
includeFilepath
,
true
,
this
.
props
.
omitReferences
,
this
.
props
.
isAgent
,
this
.
props
.
useFixCookbook
,
)
;
if
(
.
length
===
0
)
{
return
undefined
;
}
if
(
this
.
props
.
embeddedInsideUserMessage
??
)
{
return
(
< >
{
Boolean
(
.
length
)
&&
< Tag name = ' attachments' priority = { this . props . priority } >
{
...
}
</ Tag >
}
</ >
)
;
}
return
(
< >
{
...
.
map
(
=>
asUserMessage
(
,
this
.
props
.
priority
)
)
}
</ >
)
;
}
}
export
interface
QueryProps
extends
BasePromptElementProps
{
readonly
:
ChatVariablesCollection
;
readonly
:
string
;
}
export
class
UserQuery
extends
PromptElement< QueryProps, void >
{
constructor
(
:
PromptElementProps
<
QueryProps
>
,
)
{
super
(
)
;
}
render
(
:
void
,
:
PromptSizing
)
:
PromptPiece
<
any
,
any
>
|
undefined
{
const
:
PromptElement
[
]
=
[
]
;
for
(
const
of
this
.
props
.
chatVariables
)
{
if
(
isPromptFile
(
.
reference
)
)
{
.
push
(
< PromptFile variable = { v} omitReferences = { false } />
)
;
}
}
const
=
buildSlashCommandUserMessage
(
this
.
props
.
query
,
this
.
props
.
chatVariables
)
;
return
(
< >
{
...
}
{
}
</ >
)
;
}
}
export
function
buildSlashCommandUserMessage
(
:
string
,
:
ChatVariablesCollection
)
:
string
{
const
=
parseSlashCommand
(
,
)
;
if
(
)
{
return
.
args
?
` Follow instructions in # ${ match. promptFile. name} with these arguments: ${ match. args} `
:
` Follow instructions in # ${ match. promptFile. name} `
;
}
return
;
}
export
interface
ChatVariablesAndQueryProps
extends
BasePromptElementProps
,
EmbeddedInsideUserMessage
{
readonly
:
string
;
readonly
:
ChatVariablesCollection
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
readonly
?
:
boolean
;
}
export
class
ChatVariablesAndQuery
extends
PromptElement< ChatVariablesAndQueryProps, void >
{
constructor
(
:
ChatVariablesAndQueryProps
,
IFileSystemService
private
readonly
:
IFileSystemService
,
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
:
Promise
<
PromptPiece
<
any
,
any
>
|
undefined
>
{
const
=
this
.
props
.
maintainOrder
?
this
.
props
.
chatVariables
:
this
.
props
.
chatVariables
.
reverse
(
)
;
const
=
await
renderChatVariables
(
,
this
.
fileSystemService
,
this
.
props
.
includeFilepath
,
true
,
this
.
props
.
omitReferences
,
undefined
,
undefined
,
this
.
props
.
omitFileContents
)
;
if
(
this
.
props
.
embeddedInsideUserMessage
??
)
{
if
(
!
.
length
)
{
return
(
< Tag name = ' prompt' >
< UserQuery chatVariables = { chatVariables} query = { this . props . query } priority = { this . props . priority } />
</ Tag >
)
;
}
return
(
< >
{
Boolean
(
.
length
)
&&
< Tag name = ' attachments' flexGrow = { 1 } priority = { this . props . priority } >
{
}
</ Tag >
}
< Tag name = ' prompt' >
< UserQuery chatVariables = { chatVariables} query = { this . props . query } priority = { this . props . priority } />
</ Tag >
</ >
)
;
}
return
(
< >
{
...
.
map
(
=>
asUserMessage
(
,
this
.
props
.
priority
&&
this
.
props
.
priority
-
1
)
)
}
{
asUserMessage
(
< UserQuery chatVariables = { chatVariables} query = { this . props . query } />
,
this
.
props
.
priority
)
}
</ >
)
;
}
}
function
asUserMessage
(
:
PromptElement
,
:
number
|
undefined
)
:
UserMessage
{
return
(
< UserMessage priority = { priority} >
{
}
</ UserMessage >
)
;
}
export
async
function
renderChatVariables
(
:
ChatVariablesCollection
,
:
IFileSystemService
,
=
true
,
=
true
,
?
:
boolean
,
?
:
boolean
,
?
:
boolean
,
?
:
boolean
)
:
Promise
<
PromptElement
[
]
>
{
const
=
[
]
;
const
=
(
&&
)
?
FilePathMode
.
AsAttribute
:
?
FilePathMode
.
AsComment
:
FilePathMode
.
None
;
for
(
const
of
)
{
const
{
:
,
:
,
}
=
;
if
(
isInstructionFile
(
.
reference
)
||
isCustomizationsIndex
(
.
reference
)
||
isPromptFile
(
.
reference
)
)
{
continue
;
}
if
(
isSessionReference
(
)
)
{
.
push
(
< Tag name = ' attachment' attrs = { sessionReferenceAttachmentAttrs ( variable) } />
)
;
continue
;
}
if
(
URI
.
isUri
(
)
||
isLocation
(
)
)
{
const
=
'uri'
in
?
.
uri
:
;
let
=
false
;
try
{
const
=
await
.
stat
(
)
;
=
.
type
===
FileType
.
Directory
;
}
catch
{
}
if
(
)
{
.
push
(
< FolderVariable variableName = { variableName} folderUri = { uri} omitReferences = { omitReferences} description = { reference. modelDescription } omitContents = { omitFileContents} />
)
;
}
else
{
const
=
< FileVariable
alwaysIncludeSummary = { alwaysIncludeSummary}
filePathMode = { filePathMode}
variableName = { variableName}
variableValue = { variableValue}
omitReferences = { omitReferences}
description = { reference. modelDescription }
lineNumberStyle = { isAgent ? SummarizedDocumentLineNumberStyle . OmittedRanges : undefined }
omitContents = { omitFileContents}
/>
;
if
(
!
||
(
!
URI
.
isUri
(
)
||
.
scheme
!==
Schemas
.
vscodeNotebookCellOutput
)
)
{
.
push
(
)
;
}
if
(
URI
.
isUri
(
)
&&
.
scheme
===
Schemas
.
vscodeNotebookCellOutput
)
{
.
push
(
< NotebookCellOutputVariable outputUri = { variableValue} />
)
;
}
}
}
else
if
(
typeof
===
'string'
)
{
.
push
(
< Tag name = ' attachment' attrs = { variableName ? { id: variableName } : undefined } >
< TextChunk >
{
!
&&
< references value = { [ new PromptReference ( { variableName } ) ] } />
}
{
.
modelDescription
?
.
modelDescription
+
':\n'
:
''
}
{
}
</ TextChunk >
</ Tag >
)
;
}
else
if
(
instanceof
ChatReferenceBinaryData
)
{
.
push
(
< Image variableName = { variableName} variableValue = { await variableValue. data ( ) } reference = { variableValue. reference } omitReferences = { omitReferences} >
</ Image >
)
;
}
else
if
(
typeof
ChatReferenceDiagnostic
!==
'undefined'
&&
instanceof
ChatReferenceDiagnostic
)
{
.
push
(
< DiagnosticVariable diagnostics = { variableValue. diagnostics } useCookbook = { useFixCookbook ?? false } />
)
;
}
}
return
;
}
interface
IDiagnosticVariableProps
extends
BasePromptElementProps
{
:
[
:
Uri
,
:
Diagnostic
[
]
]
[
]
;
?
:
boolean
;
}
const
:
{
[
K
in
DiagnosticSeverity
]
:
string
}
=
{
[
DiagnosticSeverity
.
Error
]
:
'error'
,
[
DiagnosticSeverity
.
Warning
]
:
'warning'
,
[
DiagnosticSeverity
.
Information
]
:
'info'
,
[
DiagnosticSeverity
.
Hint
]
:
'hint'
}
;
class
DiagnosticVariable
extends
PromptElement< IDiagnosticVariableProps>
{
constructor
(
:
PromptElementProps
<
IDiagnosticVariableProps
>
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
IFixCookbookService
private
readonly
:
IFixCookbookService
,
IAlternativeNotebookContentService
private
readonly
:
IAlternativeNotebookContentService
,
IPromptEndpoint
private
readonly
:
IPromptEndpoint
,
)
{
super
(
)
;
}
render
(
)
{
return
< >
{
this
.
props
.
diagnostics
.
flatMap
(
(
[
,
]
)
=>
.
map
(
=>
{
let
=
.
range
;
(
[
,
]
=
this
.
translateNotebookUri
(
,
)
)
;
let
:
Cookbook
|
undefined
;
if
(
this
.
props
.
useCookbook
)
{
const
=
this
.
workspaceService
.
textDocuments
.
find
(
=>
isEqual
(
.
uri
,
)
)
;
const
=
?
getLanguage
(
)
:
getLanguageForResource
(
)
;
=
this
.
fixCookbookService
.
getCookbook
(
.
languageId
,
)
;
}
return
< >
< Tag name = ' error' attrs = { { path: this . promptPathRepresentationService . getFilePath ( uri) , line: range. start . line + 1 , code: getDiagnosticCode ( d) , severity: diagnosticSeverityMap[ d. severity ] } } >
{
.
message
}
</ Tag >
{
&&
< DiagnosticSuggestedFix cookbook = { cookbook} />
}
</ >
;
}
)
)
}
</ >
;
}
private
translateNotebookUri
(
:
Uri
,
:
Range
)
:
[
Uri
,
Range
]
{
if
(
.
scheme
!==
Schemas
.
vscodeNotebookCell
)
{
return
[
,
]
;
}
const
[
,
]
=
getNotebookAndCellFromUri
(
,
this
.
workspaceService
.
notebookDocuments
)
;
if
(
!
||
!
)
{
return
[
,
]
;
}
if
(
.
start
.
line
>
.
document
.
lineCount
||
.
end
.
line
>
.
document
.
lineCount
)
{
return
[
,
]
;
}
const
=
this
.
alternativeNotebookContent
.
create
(
this
.
alternativeNotebookContent
.
getFormat
(
this
.
endpoint
)
)
.
getAlternativeDocument
(
)
;
const
=
.
fromCellPosition
(
,
.
start
)
;
const
=
.
fromCellPosition
(
,
.
end
)
;
const
=
new
Range
(
,
)
;
return
[
.
uri
,
]
;
}
}
function
getDiagnosticCode
(
:
Diagnostic
)
:
string
{
const
=
(
typeof
.
code
===
'object'
&&
!
!
.
code
)
?
.
code
.
value
:
.
code
;
return
String
(
)
;
}
interface
IFolderVariableProps
extends
BasePromptElementProps
{
:
string
;
:
Uri
;
?
:
boolean
;
?
:
string
;
?
:
boolean
;
}
class
FolderVariable
extends
PromptElement< IFolderVariableProps, IFileTreeData | undefined >
{
constructor
(
:
PromptElementProps
<
IFolderVariableProps
>
,
IInstantiationService
private
readonly
:
IInstantiationService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
async
prepare
(
:
PromptSizing
)
:
Promise
<
IFileTreeData
|
undefined
>
{
if
(
this
.
props
.
omitContents
)
{
return
undefined
;
}
try
{
return
this
.
instantiationService
.
invokeFunction
(
=>
workspaceVisualFileTree
(
,
this
.
props
.
folderUri
,
{
:
2000
,
:
false
}
,
CancellationToken
.
None
)
)
;
}
catch
{
return
undefined
;
}
}
render
(
:
IFileTreeData
|
undefined
)
{
const
=
this
.
promptPathRepresentationService
.
getFilePath
(
this
.
props
.
folderUri
)
;
if
(
this
.
props
.
omitContents
)
{
return
(
< Tag name = ' attachment' attrs = { this . props . variableName ? { id: this . props . variableName , folderPath } : undefined } />
)
;
}
return
(
< Tag name = ' attachment' attrs = { this . props . variableName ? { id: this . props . variableName , folderPath } : undefined } >
< TextChunk >
{
!
this
.
props
.
omitReferences
&&
< references value = { [ new PromptReference ( { variableName: this . props . variableName } ) ] } />
}
{
this
.
props
.
description
?
this
.
props
.
description
+
':\n'
:
''
}
The user attached the folder `{folderPath}`
{
?
' which has the following structure: '
+
createFencedCodeBlock
(
''
,
.
tree
)
:
''
}
</ TextChunk >
</ Tag >
)
;
}
}
export
interface
ChatToolCallProps
extends
GenericBasePromptElementProps
,
EmbeddedInsideUserMessage
{
}
interface
IToolCallResult
{
readonly
:
string
|
undefined
;
readonly
:
LanguageModelToolResult2
;
}
export
class
ChatToolReferences
extends
PromptElement< ChatToolCallProps, void >
{
constructor
(
:
ChatToolCallProps
,
IInstantiationService
private
readonly
:
IInstantiationService
,
IToolsService
private
readonly
:
IToolsService
,
ILogService
private
readonly
:
ILogService
,
IEndpointProvider
private
readonly
:
IEndpointProvider
,
IPromptEndpoint
private
readonly
:
IPromptEndpoint
,
ITelemetryService
private
readonly
:
ITelemetryService
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
,
:
unknown
,
?
:
CancellationToken
)
:
Promise
<
PromptPiece
<
any
,
any
>
|
undefined
>
{
const
{
,
}
=
this
.
props
.
promptContext
;
if
(
!
||
!
.
toolReferences
.
length
)
{
return
;
}
const
:
IToolCallResult
[
]
=
[
]
;
for
(
const
of
.
toolReferences
)
{
const
=
this
.
toolsService
.
getTool
(
.
name
)
;
if
(
!
)
{
throw
new
Error
(
` Unknown tool: " ${ toolReference. name} " `
)
;
}
if
(
?.
[
.
id
]
)
{
.
push
(
{
:
.
name
,
:
[
.
id
]
}
)
;
continue
;
}
const
=
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
;
const
=
.
input
??
{
}
;
const
=
await
this
.
fetchToolArgs
(
,
)
;
const
=
.
range
?
this
.
props
.
promptContext
.
query
.
slice
(
.
range
[
0
]
,
.
range
[
1
]
)
:
undefined
;
try
{
const
=
await
this
.
toolsService
.
invokeToolWithEndpoint
(
.
name
,
{
:
{
...
,
...
}
,
:
.
toolInvocationToken
}
,
this
.
promptEndpoint
,
||
CancellationToken
.
None
)
;
sendInvokedToolTelemetry
(
this
.
instantiationService
,
this
.
promptEndpoint
,
this
.
telemetryService
,
.
name
,
,
{
:
this
.
props
.
promptContext
.
conversation
?.
,
:
this
.
props
.
promptContext
.
requestId
,
}
)
;
.
push
(
{
,
:
}
)
;
}
catch
(
)
{
const
=
toolCallErrorToResult
(
)
;
.
push
(
{
,
:
.
result
}
)
;
}
}
if
(
this
.
props
.
embeddedInsideUserMessage
??
)
{
return
this
.
_renderChatToolResults
(
.
toolReferences
,
,
this
.
props
.
priority
)
;
}
return
(
< UserMessage priority = { this . props . priority } >
{
this
.
_renderChatToolResults
(
.
toolReferences
,
)
}
</ UserMessage >
)
;
}
private
_renderChatToolResults
(
:
readonly
InternalToolReference
[
]
,
:
readonly
IToolCallResult
[
]
,
?
:
number
)
{
return
(
< >
These attachments may have useful context for the user's query. The user may refer to these attachments directly using a term that starts with #.
< br />
{
...
.
map
(
(
,
)
=>
this
.
renderChatToolResult
(
[
]
.
id
,
,
)
)
}
</ >
)
;
}
private
renderChatToolResult
(
:
string
,
:
IToolCallResult
,
?
:
number
)
:
PromptElement
{
return
< Tag name = ' attachment' attrs = { toolResult. name ? { tool: toolResult. name } : undefined } priority = { priority} >
< meta value = { new ToolResultMetadata ( id, toolResult. value ) } >
</ meta>
< ToolResult content = { toolResult. value . content } toolCallId = { id} sessionId = { this . props . promptContext . request ?. sessionId} />
</ Tag >
;
}
private
async
fetchToolArgs
(
:
LanguageModelToolInformation
,
:
IChatEndpoint
)
:
Promise
<
any
>
{
const
=
this
.
toolsService
.
getCopilotTool
(
.
name
as
ToolName
)
;
if
(
typeof
?.
===
'function'
)
{
const
=
await
.
provideInput
(
this
.
props
.
promptContext
)
;
if
(
)
{
return
;
}
}
if
(
!
.
inputSchema
||
Object
.
keys
(
.
inputSchema
)
.
length
===
0
)
{
return
{
}
;
}
const
:
GenericBasePromptElementProps
=
{
...
this
.
props
,
:
{
...
this
.
props
.
promptContext
,
:
undefined
}
}
;
const
=
await
.
acquireTokenizer
(
)
.
countToolTokens
(
[
]
)
;
const
{
}
=
await
PromptRenderer
.
create
(
this
.
instantiationService
,
{
...
,
:
.
modelMaxPromptTokens
-
}
,
PanelChatBasePrompt
,
)
.
render
(
)
;
let
:
ICopilotToolCall
|
undefined
;
const
=
await
.
makeChatRequest
(
'fetchToolArgs'
,
,
async
(
,
,
)
=>
{
if
(
.
copilotToolCalls
)
{
=
.
copilotToolCalls
[
0
]
;
}
return
undefined
;
}
,
CancellationToken
.
None
,
ChatLocation
.
Panel
,
undefined
,
{
:
normalizeToolSchema
(
.
family
,
[
{
:
'function'
,
function
:
{
:
.
name
,
:
.
description
,
:
.
inputSchema
}
}
]
,
(
,
)
=>
this
.
logService
.
warn
(
` Tool ${ tool} failed validation: ${ rule} `
)
)
,
:
{
:
'function'
,
function
:
{
:
.
name
,
}
}
,
}
,
false
)
;
if
(
!
)
{
throw
new
Error
(
` Failed to compute args for tool: " ${ tool. name} " `
)
;
}
if
(
.
type
!==
ChatFetchResponseType
.
Success
)
{
throw
new
Error
(
` Fetching tool args failed: ${ fetchResult. type } ${ fetchResult. reason} `
)
;
}
try
{
const
=
JSON
.
parse
(
.
arguments
)
;
return
;
}
catch
(
)
{
throw
new
Error
(
'Invalid tool arguments: '
+
.
message
)
;
}
}
}