Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
// Sometimes we get the notebook cell Uri in the resource.
// Resolve this to notebook.
=
findNotebook
(
,
this
.
workspaceService
.
notebookDocuments
)
?.
||
;
// Validate parameters
const
=
this
.
promptContext
?.
;
if
(
!
)
{
sendEditNotebookToolOutcomeTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
,
'invalid_input_no_stream'
)
;
throw
new
ErrorWithTelemetrySafeReason
(
`Invalid input, no stream`
,
'invalid_input_no_stream'
)
;
}
let
:
.
NotebookDocument
;
try
{
=
await
this
.
workspaceService
.
openNotebookDocument
(
)
;
}
catch
(
)
{
if
(
await
this
.
fileSystemService
.
stat
(
)
.
catch
(
(
)
=>
false
)
)
{
throw
;
}
else
{
// Possible the notebook does not exist and model is trying to create a new notebook.
// Edit tool doesn't support creating a new notebook.
const
=
this
.
promptContext
?.
?.
?.
some
(
=>
.
name
===
ToolName
.
EditFile
)
;
const
=
?
ToolName
.
EditFile
:
ToolName
.
CreateFile
;
const
=
.
message
||
.
toString
(
)
;
throw
new
Error
(
`${message}\nIf trying to create a Notebook, then first use the ${toolToCreateFile} tool to create an empty notebook.`
)
;
}
}
const
=
.
uri
;
const
=
this
.
alternativeNotebookContent
.
create
(
this
.
alternativeNotebookContent
.
getFormat
(
this
.
promptContext
?.
?.
)
)
;
if
(
.
isCancellationRequested
)
{
sendEditNotebookToolOutcomeTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
,
'cancelled'
)
;
return
;
}
const
:
ChangedCell
[
]
=
.
getCells
(
)
.
map
(
(
,
)
=>
(
{
,
,
:
'existing'
}
)
)
;
const
:
ChangedCell
[
]
=
[
]
;
const
:
[
.
Uri
,
TextEdit
]
[
]
=
[
]
;
// We must wait for all of the cell edits to get applied.
// This way we can return the final state of the notebook.
// We do the same in edit file too as well. Not doing this could result in inconsistencies as model will have an invalid state of the notebook document.
const
=
new
EventEmitter<void>
(
)
;
const
=
new
DisposableStore
(
)
;
.
add
(
toDisposable
(
(
)
=>
{
.
fire
(
)
;
.
dispose
(
)
;
}
)
)
;
const
=
this
.
waitForCellOperationComplete
(
,
.
event
,
,
,
)
;
const
=
this
.
waitForCellTextEditsToComplete
(
.
event
,
,
,
)
;
const
=
createSingleCallFunction
(
(
)
=>
.
notebookEdit
(
,
true
)
)
;
.
add
(
toDisposable
(
(
)
=>
sendEndEdit
(
)
)
)
;
let
:
string
|
undefined
=
undefined
;
let
:
string
|
undefined
=
undefined
;
let
:
'insert'
|
'edit'
|
'delete'
|
undefined
=
undefined
;
try
{
// First validate all of the args begore applying any changes.
const
{
,
,
,
}
=
this
.
fixInput
(
.
input
,
,
)
;
=
;
this
.
validateInput
(
{
,
,
}
,
)
;
.
notebookEdit
(
,
[
]
)
;
const
=
getCellIdMap
(
)
;
if
(
===
'insert'
)
{
let
=
-
1
;
// Index in notebook where we are to insert this new cell.
let
=
-
1
;
// Index in cells array.
let
=
-
1
;
// Original intended Notebook Cell Index.
if
(
===
'top'
)
{
=
0
;
// Possible we have already inserted a cell at the top.
// We need to find the last cell that was inserted at the top.
const
=
findLast
(
,
=>
.
type
===
'insert'
&&
.
originalIndex
===
0
)
;
if
(
)
{
=
.
indexOf
(
)
+
1
;
=
.
index
+
1
;
}
else
{
=
0
;
=
0
;
}
}
else
if
(
===
'bottom'
)
{
// Possible we have already inserted a cell at the bottom.
// We need to find the last cell that was inserted at the bottom.
=
.
length
;
=
.
filter
(
=>
.
type
!==
'delete'
)
.
length
;
}
else
{
const
=
?
.
get
(
)
:
undefined
;
if
(
!
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
'invalid_cell_id_insert_after'
,
)
;
}
const
=
.
find
(
=>
.
cell
===
)
!
;
=
.
indexOf
(
)
+
1
;
=
=
.
index
+
1
;
// Possible we have already inserted a cell at the top.
// We need to find the last cell that was inserted at the top.
const
=
findLast
(
,
=>
.
type
===
'insert'
&&
.
originalIndex
===
)
;
if
(
)
{
=
.
indexOf
(
)
+
1
;
=
.
index
+
1
;
}
}
const
=
===
'markdown'
?
NotebookCellKind
.
Markup
:
NotebookCellKind
.
Code
;
const
=
new
NotebookCellData
(
,
||
''
,
)
;
.
push
(
{
:
'insert'
,
:
,
,
}
)
;
// Shift other indexes by 1.
.
filter
(
(
{
}
)
=>
!==
'delete'
)
.
filter
(
(
{
}
)
=>
>=
)
.
forEach
(
=>
.
index
=
.
index
+
1
)
;
.
splice
(
,
0
,
{
,
:
,
:
'insert'
,
}
)
;
.
notebookEdit
(
,
NotebookEdit
.
insertCells
(
,
[
]
)
)
;
}
else
{
const
=
?
.
get
(
)
:
undefined
;
if
(
!
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
'invalid_cell_id_empty'
,
)
;
}
const
=
.
find
(
=>
.
cell
===
)
!
.
index
;
if
(
===
-
1
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
'invalid_cell_id_edit_or_delete'
)
;
}
if
(
===
'delete'
)
{
const
=
new
NotebookRange
(
,
+
1
)
;
// Shift other indexes by 1.
const
=
.
find
(
(
{
,
}
)
=>
===
&&
===
'existing'
)
!
;
.
push
(
{
:
'delete'
,
:
.
cell
as
.
NotebookCell
,
:
}
)
;
.
type
=
'delete'
;
.
filter
(
(
{
}
)
=>
!==
'delete'
)
.
filter
(
(
{
}
)
=>
>
)
.
forEach
(
=>
.
index
=
.
index
-
1
)
;
.
notebookEdit
(
,
NotebookEdit
.
deleteCells
(
)
)
;
}
else
{
if
(
===
undefined
)
{
throw
new
ErrorWithTelemetrySafeReason
(
'Invalid input: newCode is required for edit operation'
,
'invalid_input_new_code_required'
)
;
}
const
=
.
cellAt
(
)
;
.
push
(
{
:
'existing'
,
:
,
:
}
)
;
sendEditNotebookCellTelemetry
(
this
.
telemetryService
,
false
,
.
document
.
uri
,
,
this
.
endpointProvider
)
;
const
=
new
TextEdit
(
new
Range
(
new
Position
(
0
,
0
)
,
.
document
.
lineAt
(
.
document
.
lineCount
-
1
)
.
range
.
end
)
,
)
;
.
textEdit
(
.
document
.
uri
,
)
;
.
push
(
[
.
document
.
uri
,
]
)
;
}
}
sendEndEdit
(
)
;
const
=
summarizeOriginalEdits
(
,
,
,
)
;
this
.
logger
.
trace
(
`[Notebook] ${summaryOfExpectedEdits}`
)
;
if
(
.
isCancellationRequested
)
{
return
;
}
.
fire
(
)
;
// Possible this logic for waiting for edits is wrong.
// Wait for a max of 10s, if not done, then log an error and return.
// Worse case scenario, we report incorrect content in the response.
const
=
new
StatefulPromise
(
new
Promise<void>
(
(
)
=>
{
const
=
setTimeout
(
(
)
=>
{
if
(
.
length
)
{
const
=
summarizeEdits
(
)
;
this
.
logger
.
error
(
`[Notebook] Timed out waiting for cell operations to complete.`
`[Notebook] Timed out waiting for cell text edit operations to complete.`
,
`${summaryOfExpectedEdits}. Pending Text Edits ${summaryOfPendingEdits}`
)
;
}
resolve
(
)
;
}
,
10_000
)
;
.
add
(
toDisposable
(
(
)
=>
clearTimeout
(
)
)
)
;
}
)
)
;
await
raceCancellation
(
Promise
.
race
(
[
.
promise
,
Promise
.
all
(
[
,
]
)
]
)
,
)
;
if
(
.
isCancellationRequested
)
{
return
;
}
// If we timedout waiting for edit operations to complete, we don't want to return the result.
if
(
.
isResolved
)
{
return
new
LanguageModelToolResult
(
[
new
LanguageModelTextPart
(
`Notebook edited successfully. Use the ${ToolName.ReadFile} file tool to get the latest content of the notebook file`
)
]
)
;
}
return
new
LanguageModelToolResult
(
[
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
EditFileResult
,
{
document
:
,
:
,
:
this
.
promptContext
?.
?.
}
,
// If we are not called with tokenization options, have _some_ fake tokenizer
// otherwise we end up returning the entire document
.
tokenizationOptions
??
{
:
1000
,
countTokens
:
(
)
=>
Promise
.
resolve
(
.
length
*
3
/
4
)
}
,
,
)
,
)
]
)
;
}
catch
(
)
{
if
(
isCancellationError
(
)
)
{
=
'cancellation'
;
}
else
{
=
&&
instanceof
ErrorWithTelemetrySafeReason
?
.
reason
:
'unknown'
;
=
&&
instanceof
ErrorWithTelemetrySafeReason
?
.
data
:
''
;
}
throw
;
}
finally
{
.
dispose
(
)
;
if
(
!
)
{
sendEditNotebookCellOperationsTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
,
)
;
}
sendEditNotebookToolOutcomeTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
,
??
'success'
,
)
;
sendEditNotebookTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
'notebookEdit'
,
,
this
.
promptContext
?.
,
.
model
??
this
.
promptContext
?.
?.
)
;
}
}
async
resolveInput
(
:
IEditNotebookToolParams
,
:
IBuildPromptContext
)
:
Promise
<
IEditNotebookToolParams
>
{
this
.
promptContext
=
;
return
;
}
async
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
IEditNotebookToolParams
>
,
:
.
CancellationToken
)
:
Promise
<
.
PreparedToolInvocation
>
{
const
=
resolveToolInputPath
(
.
input
.
filePath
,
this
.
promptPathRepresentationService
)
;
const
=
await
this
.
instantiationService
.
invokeFunction
(
,
[
]
,
this
.
promptContext
?.
,
async
(
)
=>
{
const
=
'\n\n'
+
createFencedCodeBlock
(
.
input
.
language
||
'python'
,
asArray
(
.
input
.
newCode
||
''
)
.
join
(
'\n'
)
)
;
switch
(
.
input
.
editType
)
{
case
'insert'
:
return
.
t
(
'Insert a new cell in {0}:'
,
formatUriForFileWidget
(
)
)
+
;
case
'edit'
:
return
.
t
(
'Replace cell in {0}:'
,
formatUriForFileWidget
(
)
)
+
;
case
'delete'
:
return
.
t
(
'Delete cell from {0}.'
,
formatUriForFileWidget
(
)
)
;
default
:
return
.
t
(
'Edit {0}'
,
formatUriForFileWidget
(
)
)
;
}
}
,
.
forceConfirmationReason
,
undefined
,
.
workingDirectory
,
)
;
return
{
...
,
:
new
MarkdownString
(
.
t
(
'Edit {0}'
,
formatUriForFileWidget
(
)
)
)
}
;
}
private
validateInput
(
{
,
,
}
:
{
:
'edit'
|
'insert'
|
'delete'
;
:
string
;
:
string
|
undefined
}
,
:
.
NotebookDocument
)
{
// Possible we'll get cellId as a number such as -1 when inserting a cell at the top.
const
=
;
const
=
getCellIdMap
(
)
;
const
=
(
&&
!==
'top'
&&
!==
'bottom'
)
?
.
get
(
)
:
undefined
;
if
(
&&
!==
'top'
&&
!==
'bottom'
&&
!
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
`invalidCellId${editType}`
,
)
;
}
switch
(
)
{
case
'insert'
:
if
(
===
undefined
)
{
throw
new
ErrorWithTelemetrySafeReason
(
'None of the edits were applied as newCode is required for insert operation'
,
'missingNewCode'
)
;
}
if
(
.
length
&&
isJupyterNotebook
(
)
)
{
if
(
.
startsWith
(
'{'
)
&&
.
includes
(
'"cell_type'
)
&&
.
includes
(
'"source'
)
&&
.
endsWith
(
'}'
)
)
{
// Possible the entire notebook JSON was provided as newCode.
// This is not supported.
throw
new
ErrorWithTelemetrySafeReason
(
'When inserting cell(s) do NOT provide the entire notebook JSON as newCode. Provide the code (as plain text) for the cell instead.'
,
'gotEntireNotebookJson'
)
;
}
}
break
;
case
'delete'
:
if
(
!
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
'missingCellId'
,
)
;
}
break
;
case
'edit'
:
if
(
!
)
{
throw
new
ErrorWithTelemetrySafeReason
(
getInvalidCellErrorMessage
(
)
,
'missingCellId'
,
)
;
}
if
(
===
undefined
)
{
throw
new
ErrorWithTelemetrySafeReason
(
'None of the edits were applied as newCode is required for edit operation'
,
'missingNewCode'
)
;
}
if
(
.
includes
(
EXISTING_CODE_MARKER
)
)
{
throw
new
ErrorWithTelemetrySafeReason
(
`When editing a cell do NOT use the marker ${EXISTING_CODE_MARKER} to identify existing code. Provide the full code instead.`
,
'gotExistingCodeMarker'
)
;
}
break
;
}
}
private
fixInput
(
:
IEditNotebookToolParams
,
:
.
NotebookDocument
,
:
BaseAlternativeNotebookContentProvider
)
{
const
=
.
language
||
getDefaultLanguage
(
)
||
'python'
;
// Default to Python if no language
let
=
(
.
cellId
||
''
)
.
toString
(
)
.
trim
(
)
;
if
(
.
toLowerCase
(
)
===
'top'
)
{
=
'top'
;
}
if
(
.
toLowerCase
(
)
===
'bottom'
)
{
=
'bottom'
;
}
// If the insertion has no cell id, then treat it as bottom.
if
(
.
editType
===
'insert'
&&
!
)
{
=
'bottom'
;
}
if
(
&&
!==
'top'
&&
!==
'bottom'
)
{
=
normalizeCellId
(
)
;
}
let
=
.
newCode
;
if
(
&&
Array
.
isArray
(
)
)
{
const
=
getCellEOL
(
,
,
)
;
=
Array
.
isArray
(
)
?
.
join
(
)
:
;
}
if
(
.
editType
===
'insert'
)
{
=
?
.
stripCellMarkers
(
)
:
''
;
}
return
{
,
,
:
.
editType
,
}
;
}
async
waitForCellOperationComplete
(
:
.
NotebookDocument
,
:
.
Event
<
void
>
,
:
ChangedCell
[
]
,
:
DisposableStore
,
:
.
CancellationToken
)
:
Promise
<
void
>
{
const
=
.
add
(
new
DisposableStore
(
)
)
;
return
new
Promise<void>
(
(
)
=>
{
let
=
false
;
.
add
(
.
onCancellationRequested
(
(
)
=>
resolve
(
)
)
)
;
.
add
(
done
(
(
)
=>
{
=
true
;
if
(
.
length
===
0
)
{
resolve
(
)
;
}
}
)
)
;
.
add
(
this
.
workspaceService
.
onDidChangeNotebookDocument
(
(
)
=>
{
if
(
.
notebook
!==
)
{
return
;
}
.
filter
(
=>
{
if
(
.
type
===
'existing'
)
{
if
(
.
notebook
===
&&
.
cellChanges
.
some
(
=>
.
cell
===
.
cell
)
)
{
return
true
;
}
return
false
;
}
for
(
const
of
.
contentChanges
)
{
if
(
.
removedCells
.
length
&&
.
type
===
'delete'
&&
.
removedCells
.
some
(
=>
===
.
cell
)
)
{
return
true
;
}
if
(
.
addedCells
.
length
&&
.
type
===
'insert'
&&
.
addedCells
.
some
(
=>
.
index
===
.
index
)
)
{
return
true
;
}
}
return
false
;
}
)
.
forEach
(
=>
{
const
=
.
findIndex
(
=>
===
)
;
if
(
!==
-
1
)
{
.
splice
(
,
1
)
;
}
}
)
;
if
(
&&
.
length
===
0
)
{
resolve
(
)
;
}
}
)
)
;
}
)
.
finally
(
(
)
=>
.
dispose
(
)
)
;
}
async
waitForCellTextEditsToComplete
(
:
.
Event
<
void
>
,
:
[
.
Uri
,
TextEdit
]
[
]
,
:
DisposableStore
,
:
.
CancellationToken
)
:
Promise
<
any
>
{
const
=
.
add
(
new
DisposableStore
(
)
)
;
return
new
Promise<void>
(
(
)
=>
{
let
=
false
;
.
add
(
.
onCancellationRequested
(
(
)
=>
resolve
(
)
)
)
;
.
add
(
done
(
(
)
=>
{
=
true
;
if
(
.
length
===
0
)
{
resolve
(
)
;
}
}
)
)
;
.
add
(
this
.
workspaceService
.
onDidChangeTextDocument
(
(
)
=>
{
.
filter
(
(
[
,
]
)
=>
{
for
(
const
of
.
contentChanges
)
{
if
(
!
isEqual
(
.
document
.
uri
,
)
)
{
continue
;
}
if
(
isEqual
(
.
document
.
uri
,
)
&&
(
.
range
.
contains
(
.
range
)
||
.
range
.
contains
(
.
range
)
||
.
range
.
isEqual
(
.
range
)
)
)
{
return
true
;
}
}
return
false
;
}
)
.
forEach
(
=>
{
const
=
.
findIndex
(
=>
[
0
]
===
[
0
]
&&
[
1
]
===
[
1
]
)
;
if
(
!==
-
1
)
{
.
splice
(
,
1
)
;
}
}
)
;
if
(
&&
.
length
===
0
)
{
resolve
(
)
;
}
}
)
)
;
}
)
.
finally
(
(
)
=>
.
dispose
(
)
)
;
}
}
function
getInvalidCellErrorMessage
(
:
string
)
{
if
(
)
{
return
`None of the edits were applied as provided cell id: '${cellId}' is invalid. Notebook may have been modified, try reading the Notebook file again or use the ${ToolName.GetNotebookSummary} to get a list of the notebook cells, types and Cell Ids`
;
}
return
`None of the edits were applied as the cell id was not provided or was empty`
;
}
function
getCellEOL
(
:
string
|
undefined
,
:
string
,
:
.
NotebookDocument
)
{
const
=
getCellIdMap
(
)
;
if
(
&&
!==
'top'
&&
!==
'bottom'
)
{
const
=
.
get
(
)
;
if
(
)
{
return
.
document
.
eol
===
EndOfLine
.
LF
?
'\n'
:
'\r\n'
;
}
}
const
=
===
'markdown'
?
NotebookCellKind
.
Markup
:
NotebookCellKind
.
Code
;
const
=
.
getCells
(
)
.
find
(
=>
.
kind
===
)
;
if
(
)
{
return
.
document
.
eol
===
EndOfLine
.
LF
?
'\n'
:
'\r\n'
;
}
return
EOL
;
}
function
summarizeOriginalEdits
(
:
.
NotebookDocument
,
:
'insert'
|
'edit'
|
'delete'
,
:
string
,
:
ChangedCell
[
]
)
:
string
{
const
:
string
[
]
=
[
]
;
.
push
(
`Notebook ${notebook.uri.toString()}. `
)
;
.
push
(
`Original number of cells: ${notebook.cellCount}. `
`${index}. Cell ${getCellId(cell)}, ${range} to Edit`
)
;
}
else
{
.
push
(
`[WARNING] ${index}. Cell Uri NOT found, ${range} to Edit (${edit[0].toString()})`
)
;
}
}
return
.
join
(
'\n'
)
;
}
export
interface
IEditFileResultProps
extends
BasePromptElementProps
{
document
:
.
NotebookDocument
;
:
ChangedCell
[
]
;
:
.
LanguageModelChat
|
undefined
;
}
export
class
EditFileResult
extends
PromptElement<IEditFileResultProps>
{
constructor
(
:
PromptElementProps
<
IEditFileResultProps
>
,
IAlternativeNotebookContentService
protected
readonly
:
IAlternativeNotebookContentService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
)
{
super
(
)
;
}
/**
* When cells are inserted, the model doesn't have the details of the ids of the new cells.
* All it has is the cell ids of the cells after which the cells were inserted.
* Its been observed that the model uses the ids of the cells that were used as args in editTool as identifiers of the new cells.
* To try and avoid this hallucination, we need to show the cells that were inserted along with their ids.
*/
async
render
(
:
void
,
:
PromptSizing
)
{
const
document
=
this
.
props
.
document
;
const
:
.
NotebookCell
[
]
=
[
]
;
if
(
this
.
props
.
changes
.
every
(
=>
.
type
!==
'insert'
)
)
{
return
<>
The notebook file was successfully edited.
</>
;
}
let
:
.
NotebookCell
|
undefined
;
const
=
new
Set
(
this
.
props
.
changes
.
filter
(
=>
.
type
===
'existing'
)
.
map
(
=>
.
cell
)
)
;
document
.
getCells
(
)
.
forEach
(
(
)
=>
{
if
(
.
has
(
)
)
{
=
;
return
;
}
// This is a new cell, we need to include it in the summary.
/* __GDPR__
"editNotebook.toolUsed" : {
"owner": "donjayamanne",
"comment": "Tracks the tool used to edit Notebook documents",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"resourceHash": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The hash of the resource of the current request turn. (Notebook Uri)" },
"editTool": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Tool used to edit the notebook, one of 'notebookEdit' | 'applyPatch' | 'stringReplace' | 'newNotebookIntent' | 'editCodeIntent' | 'insertEdit' | 'createFile'" },
"isNotebook": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook (this measure is used to identify notebook related telemetry)." },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the request." }
}
*/
.
sendMSFTTelemetryEvent
(
'editNotebook.toolUsed'
,
{
,
:
,
,
}
,
{
:
1
}
)
;
}
async
function
sendEditNotebookToolOutcomeTelemetry
(
:
ITelemetryService
,
:
IEndpointProvider
|
undefined
,
:
.
LanguageModelToolInvocationOptions
<
IEditNotebookToolParams
>
,
:
string
,
?
:
string
)
{
const
=
(
.
model
&&
&&
(
await
.
getChatEndpoint
(
.
model
)
)
.
model
)
;
/* __GDPR__
"editNotebook.toolOutcome" : {
"owner": "donjayamanne",
"comment": "Tracks the tool used to edit Notebook documents",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"isNotebook": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook (this measure is used to identify notebook related telemetry)." },
"outcome": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Outcome of the edit operation" },
"failureData": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Additional data about the failure, if any" },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the request." }
}
*/
.
sendMSFTTelemetryEvent
(
'editNotebook.toolOutcome'
,
{
:
.
chatRequestId
,
,
,
}
,
{
:
1
}
)
;
}
async
function
sendEditNotebookCellOperationsTelemetry
(
:
ITelemetryService
,
:
IEndpointProvider
|
undefined
,
:
.
LanguageModelToolInvocationOptions
<
IEditNotebookToolParams
>
,
:
'insert'
|
'edit'
|
'delete'
|
undefined
)
{
const
=
(
.
model
&&
&&
(
await
.
getChatEndpoint
(
.
model
)
)
.
model
)
;
/* __GDPR__
"editNotebook.cellEditOps" : {
"owner": "donjayamanne",
"comment": "Tracks the tool used to edit Notebook documents",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"isNotebook": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook (this measure is used to identify notebook related telemetry)." },
"insert": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of cell inserts" },
"delete": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of cell deletes" },
"edit": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Number of cell edits" },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the request." }
}
*/
.
sendMSFTTelemetryEvent
(
'editNotebook.cellEditOps'
,
{
:
.
chatRequestId
,
}
,
{
:
1
,
:
===
'insert'
?
1
:
0
,
:
===
'edit'
?
1
:
0
,
delete
:
===
'delete'
?
1
:
0
}
)
;
}
async
function
sendEditNotebookCellTelemetry
(
:
ITelemetryService
,
:
boolean
,
:
.
Uri
,
:
.
LanguageModelToolInvocationOptions
<
IEditNotebookToolParams
>
,
:
IEndpointProvider
)
{
const
=
await
createSha256Hash
(
.
fsPath
)
;
const
=
.
model
&&
(
await
.
getChatEndpoint
(
.
model
)
)
.
model
;
/* __GDPR__
"editNotebook.editCellWithCodeMarker" : {
"owner": "donjayamanne",
"comment": "Tracks the presence of code markers in code when editing Notebook cells",
"requestId": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The id of the current request turn." },
"resourceHash": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The hash of the resource of the current request turn. (Notebook Uri)" },
"hasCodeMarker": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "comment": "Whether there any code markers are present", "isMeasurement": true },
"isNotebook": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "Whether the document is a notebook (this measure is used to identify notebook related telemetry)." },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the request." }
}
*/
.
sendMSFTTelemetryEvent
(
'editNotebook.editCellWithCodeMarker'
,
{
:
.
chatRequestId
,
,
}
,
{
:
?
1
:
0
,
:
1
}
)
;
}
// This is what we get, when using indexes, Model generates multiple tool call,
// Unfortunately this causes issues.
// Basically we can get multiple tool calls one after the other.
// However the tool has no idea whether the cell indexes relate to a previous state or latest state of notebook.
// E.g. if we have 10 cells (a,b,c,d,e,f,g,h,i,j,k), and we apply the edits based on the following individual tool calls.
// We want to delete indexes 2,3,4,6, hence expect cells c,d,e,g to be deleted.
// However after each tool call, the notebook gets updated hence indexes shift.
// As a result we end up deleting cells c,e,g,j.
// Given indexes are not stable, we need to use cell ids.
// This way if a cell is deleted and the id is incorrect, we can throw an error and model will request the latest state of the notebook.
// Where as using indexes we could end up deleting/updating the wrong cells.