Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/importtype*as vscode from'vscode';import{IConfigurationService}from'../../../platform/configuration/common/configurationService';import{IEditSurvivalTrackerService,IEditSurvivalTrackingSession}from'../../../platform/editSurvivalTracking/common/editSurvivalTrackerService';import{NotebookDocumentSnapshot}from'../../../platform/editing/common/notebookDocumentSnapshot';import{TextDocumentSnapshot}from'../../../platform/editing/common/textDocumentSnapshot';import{ modelShouldUseReplaceStringHealing }
applyEdit canExistingFileBeEdited createEditConfirmation formatDiffAsUnified getDisallowedEditUriError logEditToolResult openDocumentAndSnapshot
filePath
oldString
newString
uri
healed
input
generatedEdit
success textEdits vscode notebookEdits updated
success errorMessage
_promptContext
lastOperation inputKey operation
@ promptPathRepresentationService
@ instantiationService
@ workspaceService
@ toolsService
@ notebookService
@ fileSystemService
@ alternativeNotebookContent
@ alternativeNotebookEditGenerator
@ _editSurvivalTrackerService
@ languageDiagnosticsService
@ telemetryService
@ endpointProvider
@ configurationService
@ editToolLearningService
@ logService
@ _otelService
options vscode token vscode
input
options vscode vscode token vscode
input options
cacheKey input
inputKey cacheKey
inputKey cacheKey
operation options input token
options vscode vscode input token vscode
results inputi options i token
results
results
results
i i results i
current resultsi
current
k k i k
other resultsk
other extUriBiasedIgnorePathCasecurrent other
allEdits
current
other
a b ab
hasOverlap allEditse2 i
i
e1 allEditsi
e1e2
hasOverlap
current
success
errorMessage
options vscode vscode input token vscode
uri input
disallowedUriError uri allowedEditUris
disallowedUriError
uri
generatedEdit
success
errorMessage disallowedUriError
input
accessor accessor uri
error
options input
error
input input input
options input
exists canExistingFileBeEdited uri
exists
uri
generatedEdit input
success errorMessage
success textEdits input updated
input
isNotebook uri
openDocumentAndSnapshot uri
didHealRef healed
input input
input
updatedFile edits uri options input didHealRef token
notebookEdits vscode vscode
updated
model options
telemetryOptions
model
requestId
source
notebookEdits updatedFile telemetryOptions token
model
updated updatedFile
updated updatedFile
options input isNotebook didHealRef
uri
input
healed didHealRef
generatedEdit success textEdits edits notebookEdits updated
error
errorMessage
outcome
error
outcome input
input
input
error
errorMessage
error
outcome error
errorMessage error
outcome
errorMessage
outcome options input isNotebook didHealRef
uri input healed didHealRef generatedEdit success errorMessage
options vscode edits token vscode
stream
options editse input e success e healed e
fileResults
existingDiagnosticMap
uri generatedEdit healed edits
existingDiagnosticMap
existingDiagnosticMap
existingDiagnostics existingDiagnosticMap
isNotebook uri
generatedEdit
fileResults operation uri isNotebook existingDiagnostics error generatedEdit
editSurvivalTracker
responseStream
tracker editSurvivalTracker
responseStream part
part
trackerpart
uri
generatedEdit
uriToEdit uri uri
uriToEdit
edit generatedEdit
edit
edit edit
uriToEdit edit
uriToEdit
edit generatedEdit
responseStreamuri edit
responseStreamuri
editSurvivalTrackerres
res requestId requestId requestSource mapper
survivalRateFourGram res
survivalRateNoRevert res
timeDelayMs res
didBranchChange res
res
requestId requestId
requestSource
mapper
textBeforeAiEdits res res
textAfterAiEdits res res
textAfterUserEdits res res
survivalRateFourGram res
survivalRateNoRevert res
timeDelayMs res
didBranchChange res
res
headerRequestId requestId
requestSource
mapper
headBranchName resheadBranchName
headCommitHash resheadCommitHash
remoteUrl resremoteUrl
fileRelativePath resfileRelativePath
survivalRateFourGram res
survivalRateNoRevert res
timeDelayMs res
didBranchChange res
res res res res requestId res
res res
res res
fileResults
operation
uri
isNotebook
existingDiagnostics
healed healed oldString healed newString healed
generatedEdit
uri generatedEdit
isInlineChat location2
result
files fileResults diagnosticsTimeout isInlineChat toolName requestId options model options
options
tokenBudget
t t
token
result fileResultsf f
result
uri oldString newString options vscode vscode
uri
oldString
newString
requestmodel
uri options vscode vscode input didHealRef healed token vscode
model options
filePath
eol
oldString input filePath eol
newString input filePath eol
updatedFile
edits vscode
result uri oldString newString options
updatedFile result
edits result
options
e
e
e
options
model model
e
healed
healed
model
explanation options
filePath filePath
oldString
newString
eol
token
healed healed
e2
options e2
e
didHealRef healed
result
uri
healed
healed
requestmodel
updatedFile result
edits result
e2
options e2
e
edits updatedFile
outcome options vscode vscode input file isNotebookDocument didHeal
model options
isNotebook isNotebookDocument isNotebookDocument
isMulti
requestId options
interactionId options
outcome
model
isNotebook didHeal didHeal didHeal isMulti
headerRequestId options
baseModel model
messageText file
completionTextJson input
postProcessingOutcome outcome
properties properties isNotebook
options vscode vscode healError applicationError
requestId options
interactionId options
model options
healError
applicationError
success healError applicationError
options vscode vscode
model options
model model
options vscode vscode
model options options requestmodel
model
options vscode vscode success
model options
model
model success
input promptContext
promptContext
input
options vscode token vscode vscode
replaceInputs options
allUris replaceInputsinput input
createEditConfirmation
allUris
allowedEditUris
urisNeedingConfirmation replaceInputs urisNeedingConfirmation options token
options
options
replaceInputs
urisNeedingConfirmation
options vscode
token vscode
urisNeedingConfirmationSet urisNeedingConfirmation
allPreparedEdits options token
diffResults
allPreparedEdits preparedEdit
uri preparedEdit
urisNeedingConfirmationSeturi
preparedEdit
oldContent preparedEdit
newContent preparedEdit
formatDiffAsUnified
uri
oldContent
newContent
diffResultsisDefined
/**
* Extract one or more IAbstractReplaceStringInput from the tool's input type T.
* For single-file tools, return an array with one element.
* For multi-file tools, return an array with multiple elements.
*/
protected
abstract
extractReplaceInputs
(
:
T
)
:
IAbstractReplaceStringInput
[
]
;
protected
prepareEdits
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
.
CancellationToken
)
:
Promise
<
IPrepareEdit
[
]
>
{
const
=
this
.
extractReplaceInputs
(
.
input
)
;
const
=
JSON
.
stringify
(
)
;
if
(
this
.
lastOperation
?.
!==
)
{
this
.
lastOperation
=
{
:
,
:
this
.
_prepareEdits
(
,
,
)
}
;
}
return
this
.
lastOperation
.
operation
;
}
private
async
_prepareEdits
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
IAbstractReplaceStringInput
[
]
,
:
.
CancellationToken
)
{
const
=
await
Promise
.
all
(
.
map
(
=>
this
.
_prepareEditsForFile
(
,
,
)
)
)
;
this
.
_errorConflictingEdits
(
)
;
return
;
}
private
_errorConflictingEdits
(
:
IPrepareEdit
[
]
)
{
for
(
let
=
1
;
<
.
length
;
++
)
{
const
=
[
]
;
if
(
!
.
generatedEdit
.
success
)
{
continue
;
}
for
(
let
=
0
;
<
;
++
)
{
const
=
[
]
;
if
(
!
.
generatedEdit
.
success
||
!
.
isEqual
(
.
uri
,
.
uri
)
)
{
continue
;
}
const
=
[
...
.
generatedEdit
.
textEdits
,
...
.
generatedEdit
.
textEdits
,
]
.
sort
(
(
,
)
=>
.
range
.
start
.
compareTo
(
.
range
.
start
)
)
;
const
=
.
some
(
(
,
)
=>
{
if
(
===
0
)
{
return
false
;
}
const
=
[
-
1
]
;
return
!
.
range
.
end
.
isBeforeOrEqual
(
.
range
.
start
)
;
}
)
;
if
(
)
{
.
generatedEdit
=
{
:
false
,
:
`Edit at index ${i} conflicts with another replacement in ${this.promptPathRepresentationService.getFilePath(current.uri)}. You can make another call to try again.`
}
;
break
;
}
}
}
}
private
async
_prepareEditsForFile
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
IAbstractReplaceStringInput
,
:
.
CancellationToken
)
:
Promise
<
IPrepareEdit
>
{
const
=
resolveToolInputPath
(
.
filePath
,
this
.
promptPathRepresentationService
)
;
const
=
getDisallowedEditUriError
(
,
this
.
_promptContext
?.
,
this
.
promptPathRepresentationService
)
;
if
(
)
{
return
{
,
document
:
undefined
,
:
{
:
false
,
:
}
,
,
}
;
}
try
{
await
this
.
instantiationService
.
invokeFunction
(
=>
assertFileNotContentExcluded
(
,
)
)
;
}
catch
(
)
{
this
.
sendReplaceTelemetry
(
'invalidFile'
,
,
,
undefined
,
undefined
,
undefined
)
;
throw
;
}
// Validate parameters
if
(
!
.
filePath
||
.
oldString
===
undefined
||
.
newString
===
undefined
||
!
this
.
_promptContext
)
{
this
.
sendReplaceTelemetry
(
'invalidStrings'
,
,
,
undefined
,
undefined
,
undefined
)
;
throw
new
Error
(
'Invalid input'
)
;
}
// Sometimes the model replaces an empty string in a new file to create it. Allow that pattern.
const
=
await
this
.
instantiationService
.
invokeFunction
(
,
)
;
if
(
!
)
{
return
{
,
document
:
undefined
,
:
.
oldString
?
{
:
false
,
:
`File does not exist: ${input.filePath}. Use the ${ToolName.CreateFile} tool to create it, or correct your filepath.`
}
:
{
:
true
,
:
[
TextEdit
.
insert
(
new
ExtPosition
(
0
,
0
)
,
.
newString
)
]
,
:
undefined
}
,
,
}
;
}
const
=
this
.
notebookService
.
hasSupportedNotebooks
(
)
;
const
document
=
await
this
.
instantiationService
.
invokeFunction
(
,
this
.
_promptContext
,
)
;
const
:
{
?
:
IAbstractReplaceStringInput
}
=
{
}
;
try
{
if
(
.
oldString
===
.
newString
)
{
throw
new
NoChangeError
(
'Input and output are identical'
,
.
filePath
)
;
}
const
{
,
}
=
await
this
.
generateEdit
(
,
document
,
,
,
,
)
;
let
:
(
.
NotebookEdit
|
[
URI
,
.
TextEdit
[
]
]
)
[
]
|
undefined
;
let
:
NotebookDocumentSnapshot
|
TextDocumentSnapshot
;
if
(
document
instanceof
NotebookDocumentSnapshot
)
{
const
=
await
this
.
modelForTelemetry
(
)
;
const
:
NotebookEditGenerationTelemtryOptions
=
{
,
:
this
.
_promptContext
.
requestId
,
:
NotebookEditGenrationSource
.
stringReplace
,
}
;
=
await
Iterable
.
asyncToArray
(
processFullRewriteNotebookEdits
(
document
.
document
,
,
this
.
alternativeNotebookEditGenerator
,
,
)
)
;
sendEditNotebookTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
'stringReplace'
,
document
.
uri
,
this
.
_promptContext
.
requestId
,
||
'unknown'
)
;
=
NotebookDocumentSnapshot
.
fromNewText
(
,
document
)
;
}
else
{
=
TextDocumentSnapshot
.
fromNewText
(
,
document
)
;
}
void
this
.
sendReplaceTelemetry
(
'success'
,
,
,
document
.
getText
(
)
,
,
!
!
.
healed
)
;
return
{
document
,
,
,
:
.
healed
,
:
{
:
true
,
:
,
,
}
}
;
}
catch
(
)
{
// Enhanced error message with more helpful details
let
=
'String replacement failed: '
;
let
:
string
;
if
(
instanceof
NoMatchError
)
{
=
.
oldString
.
match
(
/Lines \d+-\d+ omitted/
)
?
'oldStringHasOmittedLines'
:
.
oldString
.
includes
(
'{…}'
)
?
'oldStringHasSummarizationMarker'
:
.
oldString
.
includes
(
'/*...*/'
)
?
'oldStringHasSummarizationMarkerSemanticSearch'
:
.
kindForTelemetry
;
+=
`${error.message}`
;
}
else
if
(
instanceof
EditError
)
{
=
.
kindForTelemetry
;
+=
.
message
;
}
else
{
=
'other'
;
+=
`${error.message}`
;
}
void
this
.
sendReplaceTelemetry
(
,
,
,
document
.
getText
(
)
,
,
!
!
.
healed
)
;
return
{
document
,
,
,
:
.
healed
,
:
{
:
false
,
}
}
;
}
}
protected
async
applyAllEdits
(
:
.
LanguageModelToolInvocationOptions
<
T
>
,
:
IPrepareEdit
[
]
,
:
.
CancellationToken
)
{
if
(
!
this
.
_promptContext
?.
)
{
throw
new
Error
(
'no prompt context found'
)
;
}
logEditToolResult
(
this
.
logService
,
.
chatRequestId
,
...
.
map
(
=>
(
{
:
.
input
,
:
.
generatedEdit
.
success
,
:
.
healed
}
)
)
)
;
const
:
IEditedFile
[
]
=
[
]
;
const
=
new
ResourceMap<vscode.Diagnostic[]>
(
)
;
for
(
const
{
document
,
,
,
}
of
)
{
if
(
document
&&
!
.
has
(
document
.
uri
)
)
{
.
set
(
document
.
uri
,
this
.
languageDiagnosticsService
.
getDiagnostics
(
document
.
uri
)
)
;
}
const
=
document
?
.
get
(
document
.
uri
)
!
:
[
]
;
const
=
this
.
notebookService
.
hasSupportedNotebooks
(
)
;
if
(
!
.
success
)
{
.
push
(
{
:
ActionType
.
UPDATE
,
,
,
,
:
.
errorMessage
}
)
;
continue
;
}
let
:
IEditSurvivalTrackingSession
|
undefined
;
let
=
this
.
_promptContext
.
stream
;
if
(
document
&&
document
instanceof
TextDocumentSnapshot
)
{
// Only for existing text documents
const
=
=
this
.
_editSurvivalTrackerService
.
initialize
(
document
.
document
)
;
=
ChatResponseStreamImpl
.
spy
(
this
.
_promptContext
.
stream
,
(
)
=>
{
if
(
instanceof
ChatResponseTextEditPart
)
{
.
collectAIEdits
(
.
edits
)
;
}
}
)
;
}
this
.
_promptContext
.
stream
.
markdown
(
'\n```\n'
)
;
this
.
_promptContext
.
stream
.
codeblockUri
(
,
true
)
;
if
(
.
notebookEdits
)
{
const
=
document
?.
??
;
this
.
_promptContext
.
stream
.
notebookEdit
(
,
[
]
)
;
for
(
const
of
.
notebookEdits
)
{
if
(
instanceof
Array
)
{
this
.
_promptContext
.
stream
.
textEdit
(
[
0
]
,
[
1
]
)
;
}
else
{
this
.
_promptContext
.
stream
.
notebookEdit
(
,
)
;
}
}
this
.
_promptContext
.
stream
.
notebookEdit
(
,
true
)
;
}
else
{
for
(
const
of
.
textEdits
)
{
.
textEdit
(
,
)
;
}
.
textEdit
(
,
true
)
;
timeout
(
2000
)
.
then
(
(
)
=>
{
// The tool can't wait for edits to be applied, so just wait before starting the survival tracker.
// TODO@roblourens see if this improves the survival metric, find a better fix.
?.
startReporter
(
=>
{
/* __GDPR__
"codeMapper.trackEditSurvival" : {
"owner": "aeschli",
"comment": "Tracks how much percent of the AI edits survived after 5 minutes of accepting",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"speculationRequestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the speculation request." },
"requestSource": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The source from where the request was made" },
"chatRequestModel": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the base chat request to generate the edit object." },
"mapper": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The code mapper used: One of 'fast', 'fast-lora', 'full' and 'patch'" },
"survivalRateFourGram": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "The rate between 0 and 1 of how much of the AI edit is still present in the document." },
"survivalRateNoRevert": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "The rate between 0 and 1 of how much of the ranges the AI touched ended up being reverted." },
"didBranchChange": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Indicates if the branch changed in the meantime. If the branch changed (value is 1), this event should probably be ignored." },
"timeDelayMs": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "The time delay between the user accepting the edit and measuring the survival rate." }
}
*/
.
telemetryService
.
sendMSFTTelemetryEvent
(
'codeMapper.trackEditSurvival'
,
{
:
this
.
_promptContext
?.
,
:
'agent'
,
:
'stringReplaceTool'
}
,
{
:
.
fourGram
,
:
.
noRevert
,
:
.
timeDelayMs
,
:
.
didBranchChange
?
1
:
0
,
}
)
;
.
telemetryService
.
sendInternalMSFTTelemetryEvent
(
'codeMapper.trackEditSurvival'
,
{
:
this
.
_promptContext
?.
,
:
'agent'
,
:
'stringReplaceTool'
,
:
.
textBeforeAiEdits
?
JSON
.
stringify
(
.
textBeforeAiEdits
)
:
undefined
,
:
.
textAfterAiEdits
?
JSON
.
stringify
(
.
textAfterAiEdits
)
:
undefined
,
:
.
textAfterUserEdits
?
JSON
.
stringify
(
.
textAfterUserEdits
)
:
undefined
,
}
,
{
:
.
fourGram
,
:
.
noRevert
,
:
.
timeDelayMs
,
:
.
didBranchChange
?
1
:
0
,
}
)
;
.
telemetryService
.
sendGHTelemetryEvent
(
'replaceString/trackEditSurvival'
,
{
:
this
.
_promptContext
?.
,
:
'agent'
,
:
'stringReplaceTool'
,
:
.
workspace
?.
,
:
.
workspace
?.
,
:
.
workspace
?.
,
:
.
workspace
?.
,
}
,
{
:
.
fourGram
,
:
.
noRevert
,
:
.
timeDelayMs
,
:
.
didBranchChange
?
1
:
0
,
}
)
;
emitEditSurvivalEvent
(
this
.
_otelService
,
'replace_string'
,
.
fourGram
,
.
noRevert
,
.
timeDelayMs
,
.
didBranchChange
,
this
.
_promptContext
?.
??
''
,
.
workspace
)
;
GenAiMetrics
.
recordEditSurvivalFourGram
(
this
.
_otelService
,
'replace_string'
,
.
fourGram
,
.
timeDelayMs
)
;
GenAiMetrics
.
recordEditSurvivalNoRevert
(
this
.
_otelService
,
'replace_string'
,
.
noRevert
,
.
timeDelayMs
)
;
}
)
;
}
)
;
.
push
(
{
:
ActionType
.
UPDATE
,
,
,
,
:
?
JSON
.
stringify
(
{
:
.
oldString
,
:
.
newString
}
,
null
,
2
)
:
undefined
}
)
;
}
this
.
_promptContext
.
stream
.
markdown
(
'\n```\n'
)
;
if
(
.
updated
)
{
this
.
_promptContext
.
turnEditedDocuments
??=
new
ResourceMap
(
)
;
this
.
_promptContext
.
turnEditedDocuments
.
set
(
,
.
updated
)
;
}
}
const
=
this
.
_promptContext
.
request
?.
instanceof
ChatRequestEditorData
;
const
=
new
ExtendedLanguageModelToolResult
(
[
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
EditFileResult
,
{
:
,
:
?
-
1
:
2000
,
:
this
.
toolName
(
)
,
:
.
chatRequestId
,
:
.
model
}
,
// If we are not called with tokenization options, have _some_ fake tokenizer
// otherwise we end up returning the entire document
.
tokenizationOptions
??
{
:
5000
,
countTokens
:
(
)
=>
Promise
.
resolve
(
.
length
*
3
/
4
)
}
,
,
)
,
)
]
)
;
.
hasError
=
.
some
(
=>
.
error
)
;
return
;
}
protected
doGenerateEdit
(
:
URI
,
:
string
,
:
string
,
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
)
{
return
applyEdit
(
,
,
,
this
.
workspaceService
,
this
.
notebookService
,
this
.
alternativeNotebookContent
,
this
.
_promptContext
?.
?.
)
;
}
private
async
generateEdit
(
:
URI
,
document
:
TextDocumentSnapshot
|
NotebookDocumentSnapshot
,
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
IAbstractReplaceStringInput
,
:
{
?
:
IAbstractReplaceStringInput
}
,
:
.
CancellationToken
)
{
const
=
this
.
modelObjectForTelemetry
(
)
;
const
=
this
.
promptPathRepresentationService
.
getFilePath
(
document
.
uri
)
;
const
=
document
instanceof
TextDocumentSnapshot
&&
document
.
eol
===
EndOfLine
.
CRLF
?
'\r\n'
:
'\n'
;
const
=
removeLeadingFilepathComment
(
.
oldString
,
document
.
languageId
,
)
.
replace
(
/\r?\n/g
,
)
;
const
=
removeLeadingFilepathComment
(
.
newString
,
document
.
languageId
,
)
.
replace
(
/\r?\n/g
,
)
;
// Apply the edit using the improved applyEdit function that uses VS Code APIs
let
:
string
;
let
:
.
TextEdit
[
]
=
[
]
;
try
{
const
=
await
this
.
doGenerateEdit
(
,
,
,
)
;
=
.
updatedFile
;
=
.
edits
;
this
.
recordEditSuccess
(
,
true
)
;
}
catch
(
)
{
if
(
!
(
instanceof
NoMatchError
)
)
{
throw
;
}
this
.
recordEditSuccess
(
,
false
)
;
if
(
&&
!
modelShouldUseReplaceStringHealing
(
)
)
{
throw
;
}
let
:
CorrectedEditResult
;
try
{
=
await
healReplaceStringParams
(
,
document
.
getText
(
)
,
{
:
.
input
.
explanation
,
:
,
,
,
}
,
,
await
this
.
endpointProvider
.
getChatEndpoint
(
'copilot-utility-small'
)
,
)
;
if
(
.
params
.
oldString
===
.
params
.
newString
)
{
throw
new
NoChangeError
(
'change was identical after healing'
,
document
.
uri
.
fsPath
)
;
}
}
catch
(
)
{
this
.
sendHealingTelemetry
(
,
String
(
)
,
undefined
)
;
throw
;
// original error
}
.
healed
=
.
params
;
try
{
const
=
await
applyEdit
(
,
.
params
.
oldString
,
.
params
.
newString
,
this
.
workspaceService
,
this
.
notebookService
,
this
.
alternativeNotebookContent
,
this
.
_promptContext
?.
?.
)
;
=
.
updatedFile
;
=
.
edits
;
}
catch
(
)
{
this
.
sendHealingTelemetry
(
,
undefined
,
String
(
)
)
;
throw
;
// original error
}
}
return
{
,
}
;
}
private
async
sendReplaceTelemetry
(
:
string
,
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
IAbstractReplaceStringInput
,
:
string
|
undefined
,
:
boolean
|
undefined
,
:
boolean
|
undefined
)
{
const
=
await
this
.
modelForTelemetry
(
)
;
const
=
?
1
:
(
===
false
?
0
:
-
1
)
;
const
=
this
.
toolName
(
)
===
ToolName
.
MultiReplaceString
?
1
:
0
;
/* __GDPR__
"replaceStringToolInvoked" : {
"owner": "roblourens",
"comment": "The replace_string tool was invoked",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"interactionId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current interaction." },
"outcome": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the invocation was successful, or a failure reason" },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model that invoked the tool" },
"isNotebook": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook, 1 = yes, 0 = no, other = unknown." },
"didHeal": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook, 1 = yes, 0 = no, other = unknown." },
"isMulti": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a multi-replace operation, 1 = yes, 0 = no." }
}
*/
this
.
telemetryService
.
sendMSFTTelemetryEvent
(
'replaceStringToolInvoked'
,
{
:
.
chatRequestId
,
:
.
chatRequestId
,
,
}
,
{
,
:
===
undefined
?
-
1
:
(
?
1
:
0
)
,
}
)
;
void
multiplexProperties
(
{
:
.
chatRequestId
,
:
,
:
,
:
JSON
.
stringify
(
)
,
:
,
}
)
.
then
(
=>
this
.
telemetryService
.
sendEnhancedGHTelemetryEvent
(
'replaceStringTool'
,
,
{
}
)
)
.
catch
(
(
)
=>
{
/* best-effort telemetry */
}
)
;
}
private
async
sendHealingTelemetry
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
string
|
undefined
,
:
string
|
undefined
)
{
/* __GDPR__
"replaceStringHealingStat" : {
"owner": "roblourens",
"comment": "The replace_string tool was invoked",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"interactionId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current interaction." },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model that invoked the tool" },
"outcome": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Whether the invocation was successful, or a failure reason" },
"healError": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Any error that happened during healing" },
"applicationError": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Any error that happened after application" },
"success": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook, 1 = yes, 0 = no, other = unknown." }
}
*/
this
.
telemetryService
.
sendMSFTTelemetryEvent
(
'replaceStringHealingStat'
,
{
:
.
chatRequestId
,
:
.
chatRequestId
,
:
await
this
.
modelForTelemetry
(
)
,
,
,
}
,
{
:
===
undefined
&&
===
undefined
?
1
:
0
}
)
;
}
protected
async
modelForTelemetry
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
)
{
const
=
this
.
modelObjectForTelemetry
(
)
;
return
&&
(
await
this
.
endpointProvider
.
getChatEndpoint
(
)
)
.
model
;
}
protected
modelObjectForTelemetry
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
)
{
const
=
'model'
in
?
.
model
:
this
.
_promptContext
?.
?.
;
return
;
}
private
async
recordEditSuccess
(
:
.
LanguageModelToolInvocationOptions
<
T
>
|
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
boolean
)
{
const
=
this
.
modelObjectForTelemetry
(
)
;
if
(
)
{
this
.
editToolLearningService
.
didMakeEdit
(
,
this
.
toolName
(
)
as
EditTools
,
)
;
}
}
async
resolveInput
(
:
T
,
:
IBuildPromptContext
)
:
Promise
<
T
>
{
this
.
_promptContext
=
;
// TODO@joyceerhl @roblourens HACK: Avoid types in the input being serialized and not deserialized when they go through invokeTool
return
;
}
async
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
.
CancellationToken
)
:
Promise
<
.
PreparedToolInvocation
>
{
// Extract all replace inputs from the tool input
const
=
this
.
extractReplaceInputs
(
.
input
)
;
const
=
.
map
(
=>
resolveToolInputPath
(
.
filePath
,
this
.
promptPathRepresentationService
)
)
;
return
this
.
instantiationService
.
invokeFunction
(
,
,
this
.
_promptContext
?.
,
(
)
=>
this
.
generateConfirmationDetails
(
,
,
,
)
,
.
forceConfirmationReason
,
undefined
,
.
workingDirectory
,
)
;
}
private
async
generateConfirmationDetails
(
:
IAbstractReplaceStringInput
[
]
,
:
readonly
URI
[
]
,
:
.
LanguageModelToolInvocationPrepareOptions
<
T
>
,
:
.
CancellationToken
)
:
Promise
<
string
>
{
const
=
new
ResourceSet
(
)
;
const
=
await
this
.
prepareEdits
(
,
)
;
// Generate diffs only for files needing confirmation