Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/* __GDPR__
"runNotebookCellInvoked" : {
"owner": "amunger",
"comment": "Tracks the usage and result ",
"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)" },
"model": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model used for the request." },
"result": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Result of the operation: success, failure, or unknown." },
"resultInfo": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "Reason for failure if the result is failure." }
}
*/
.
sendMSFTTelemetryEvent
(
'runNotebookCellInvoked'
,
{
:
this
.
requestId
,
,
:
this
.
model
,
:
this
.
result
,
:
this
.
resultInfo
,
}
,
)
;
}
}
export
class
RunNotebookCellTool
implements
ICopilotTool<IRunNotebookCellToolParams>
{
public
static
=
ToolName
.
RunNotebookCell
;
private
:
IBuildPromptContext
|
undefined
;
constructor
(
IInstantiationService
private
readonly
:
IInstantiationService
,
IPromptPathRepresentationService
private
readonly
:
IPromptPathRepresentationService
,
IWorkspaceService
private
readonly
:
IWorkspaceService
,
INotebookService
private
readonly
:
INotebookService
,
IAlternativeNotebookContentService
protected
readonly
:
IAlternativeNotebookContentService
,
IExtensionsService
private
readonly
:
IExtensionsService
,
IEndpointProvider
private
readonly
:
IEndpointProvider
,
IToolsService
private
readonly
:
IToolsService
,
ITelemetryService
private
readonly
:
ITelemetryService
,
)
{
}
async
invoke
(
:
.
LanguageModelToolInvocationOptions
<
IRunNotebookCellToolParams
>
,
:
.
CancellationToken
)
{
const
{
,
,
}
=
.
input
;
const
=
.
model
&&
(
await
this
.
endpointProvider
.
getChatEndpoint
(
.
model
)
)
.
model
;
const
=
new
RunNotebookTelemetryEvent
(
,
.
chatRequestId
,
)
;
try
{
const
{
,
}
=
this
.
getNotebookAndCell
(
,
)
;
// track that a notebook tool was invoked by the agent, exposes follow execution action to toolbar
this
.
notebookService
.
trackAgentUsage
(
)
;
// If this is a Jupyter notebook with Python code and Jupyter extension isn't installed, recommend installing it
const
JUPYTER_EXTENSION_ID
=
'ms-toolsai.jupyter'
;
if
(
isJupyterNotebookUri
(
.
uri
)
&&
.
getCells
(
)
.
some
(
=>
.
document
.
languageId
.
toLowerCase
(
)
===
'python'
)
&&
!
this
.
extensionsService
.
getExtension
(
JUPYTER_EXTENSION_ID
)
)
{
try
{
const
:
IInstallExtensionToolInput
=
{
:
JUPYTER_EXTENSION_ID
,
:
'Jupyter'
}
;
await
this
.
toolsService
.
invokeTool
(
ToolName
.
InstallExtension
,
{
...
,
}
,
)
;
}
catch
{
//
}
}
await
this
.
notebookService
.
ensureKernelSelected
(
.
uri
)
;
if
(
.
isCancellationRequested
)
{
.
skipped
(
'canceled'
)
;
return
new
LanguageModelToolResult
(
[
]
)
;
}
const
=
.
getCells
(
)
.
findIndex
(
(
)
=>
===
)
;
if
(
.
kind
!==
2
)
{
.
skipped
(
'markdownCell'
)
;
return
new
LanguageModelToolResult
(
[
new
LanguageModelTextPart
(
`Cell ${cellId} is not a code cell so it can't be executed. If this is unexpected, then use the ${ToolName.ReadFile} file tool to get the latest content of the notebook file`
)
]
)
;
}
else
if
(
.
document
.
getText
(
)
.
trim
(
)
===
''
)
{
.
skipped
(
'emptyCell'
)
;
return
new
LanguageModelToolResult
(
[
new
LanguageModelTextPart
(
`Cell ${cellId} is empty, so it won't be executed. If this is unexpected, then use the ${ToolName.ReadFile} file tool to get the latest content of the notebook file`
)
]
)
;
}
let
:
string
|
undefined
=
undefined
;
let
:
.
NotebookCellExecutionSummary
|
undefined
=
undefined
;
const
:
.
Disposable
[
]
=
[
]
;
try
{
const
=
raceCancellationError
(
this
.
waitForCellExecution
(
,
)
,
)
;
const
=
this
.
notebookService
.
getFollowState
(
)
;
await
this
.
notebookService
.
runCells
(
.
uri
,
{
:
,
:
+
1
}
,
)
;
=
await
raceTimeout
(
,
3_000
)
;
if
(
)
{
if
(
.
success
===
false
)
{
.
failed
(
'ExecutionFailed'
)
;
if
(
!
)
{
=
`Cell ${cellId} execution failed. The error should be fixed before running any more cells.`
;
}
}
else
{
.
result
=
'success'
;
}
}
else
{
// some controllers will return before finishing execution,
// But we can't tell the difference between a cell that is still executing and one that just failed to execute
=
`Cell ${cellId} did not finish executing. It may still be running, or it may have failed to execute.`
;
.
failed
(
'ExecutionTimeout'
)
;
}
}
finally
{
dispose
(
)
;
}
const
=
?.
||
[
]
;
const
:
Array
<
LanguageModelPromptTsxPart
|
unknown
>
=
[
]
;
// execution summary
.
push
(
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
RunNotebookCellResultSummary
,
{
,
}
,
.
tokenizationOptions
,
)
)
)
;
const
=
this
.
_promptContext
?.
?
await
this
.
endpointProvider
.
getChatEndpoint
(
this
.
_promptContext
?.
)
:
undefined
;
for
(
let
=
0
;
<
.
length
;
++
)
{
const
=
[
]
;
const
=
?.
?
.
items
.
find
(
(
)
=>
.
mime
===
'image/png'
||
.
mime
===
'image/jpeg'
)
:
undefined
;
if
(
)
{
.
push
(
new
LanguageModelTextPart
(
`<cell-output>\nOutput ${i}:\n`
)
)
;
.
push
(
LanguageModelDataPart
.
image
(
.
data
,
.
mime
===
'image/png'
?
ChatImageMimeType
.
PNG
:
ChatImageMimeType
.
JPEG
)
)
;
.
push
(
new
LanguageModelTextPart
(
`</cell-output>`
)
)
;
}
else
{
.
push
(
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
RunNotebookCellOutput
,
{
,
:
,
:
4
}
,
.
tokenizationOptions
,
)
)
)
;
}
}
const
=
new
ExtendedLanguageModelToolResult
(
as
any
[
]
)
;
const
=
?.
document
.
uri
;
.
toolResultMessage
=
new
MarkdownString
(
`Ran [](${cellUri?.toString()})`
)
;
return
;
}
catch
(
)
{
.
failed
(
.
message
||
'exceptionThrown'
)
;
}
finally
{
await
.
send
(
this
.
telemetryService
)
;
}
}
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
IRunNotebookCellToolParams
>
)
:
.
ProviderResult
<
.
PreparedToolInvocation
>
{
const
{
,
,
}
=
.
input
;
const
{
}
=
this
.
getNotebookAndCell
(
,
)
;
// track that a notebook tool was invoked by the agent, exposes follow execution action to toolbar
this
.
notebookService
.
trackAgentUsage
(
)
;
const
=
this
.
formatRunMessage
(
,
)
;
const
=
{
:
.
t
`Run Notebook Cell`
,
:
,
}
;
return
{
,
:
new
MarkdownString
(
.
t
`Running [](${cell.document.uri.toString()})`
)
,
}
;
}
async
resolveInput
(
:
IRunNotebookCellToolParams
,
:
IBuildPromptContext
)
:
Promise
<
IRunNotebookCellToolParams
>
{
this
.
_promptContext
=
;
return
;
}
private
getNotebookAndCell
(
:
string
,
:
string
)
:
{
:
.
NotebookDocument
;
:
.
NotebookCell
}
{
const
=
this
.
promptPathRepresentationService
.
resolveFilePath
(
)
;
if
(
!
)
{
throw
new
Error
(
`Invalid file path`
)
;
}
const
=
findNotebook
(
,
this
.
workspaceService
.
notebookDocuments
)
;
if
(
!
)
{
throw
new
Error
(
`Notebook ${resolvedUri} not found.`
)
;
}
const
=
getCellIdMap
(
)
.
get
(
)
;
if
(
!
)
{
throw
new
Error
(
`Cell ${cellId} not found in the notebook, use the ${ToolName.ReadFile} file tool to get the latest content of the notebook file`
)
;
}
return
{
,
}
;
}
private
formatRunMessage
(
:
.
NotebookCell
,
?
:
string
)
{
const
=
[
`[](${cell.document.uri.toString()})`
,
''
]
;
.
push
(
'```'
+
.
document
.
languageId
)
;
let
=
true
;
// remove leading and consecutive empty lines
for
(
const
of
.
document
.
getText
(
)
.
split
(
'\n'
)
)
{
if
(
.
length
>
10
)
{
.
push
(
'...'
)
;
break
;
}
if
(
.
trim
(
)
===
''
)
{
if
(
)
{
continue
;
}
=
true
;
}
else
{
=
false
;
}
.
push
(
)
;
}
if
(
)
{
.
unshift
(
''
)
;
.
unshift
(
)
;
}
const
=
.
join
(
'\n'
)
.
trim
(
)
+
'\n```'
;
return
new
MarkdownString
(
)
;
}
private
async
waitForCellExecution
(
:
.
NotebookCell
,
:
.
Disposable
[
]
)
{
return
new
Promise<vscode.NotebookCellExecutionSummary>
(
(
)
=>
{
.
push
(
this
.
workspaceService
.
onDidChangeNotebookDocument
(
(
)
=>
{
for
(
const
of
.
cellChanges
)
{
if
(
.
executionSummary
&&
typeof
.
executionSummary
.
success
===
'boolean'
&&
.
cell
===
)
{
resolve
(
.
executionSummary
)
;
}
}
}
)
)
;
}
)
;
}
}
interface
IRunNotebookCellToolParams
{
:
string
;
:
string
;
?
:
string
;
?
:
boolean
;
}
interface
IRunNotebookCellResultSummaryProps
extends
BasePromptElementProps
{
:
.
NotebookCellExecutionSummary
|
undefined
;
:
string
|
undefined
;
}
class
RunNotebookCellResultSummary
extends
PromptElement<IRunNotebookCellResultSummaryProps>
{
render
(
:
void
,
:
PromptSizing
)
{
const
{
}
=
this
.
props
;
return
(
<>
<Tagname={`execution-summaries`}>
{
&&
this
.
renderSummary
(
'cellId'
,
,
true
)
}
</Tag>
{
this
.
renderAdditionalInfo
(
)
}
</>
)
;
}
private
renderAdditionalInfo
(
)
{
if
(
!
this
.
props
.
infoMessage
)
{
return
<>
</>
;
}
return
(
<Tagname='additional-info'>
{
this
.
renderInfoMessage
(
this
.
props
.
infoMessage
)
}
</Tag>
)
;
}
private
renderSummary
(
:
string
,
:
.
NotebookCellExecutionSummary
,
:
boolean
)
{
let
=
<>
cell
{
}
</>
;
if
(
typeof
?.
===
'boolean'
)
{
=
<>
{
}
{
?.
?
<>
executed successfully
<br/>
</>
:
<>
execution failed
<br/>
</>
}
</>
;
}
else
{
=
<>
{
}
<br/>
</>
;
}
if
(
?.
)
{
=
<>
{
}
Total Duration:
{
.
timing
.
endTime
-
.
timing
.
startTime
}
ms
<br/>
</>
;
}
if
(
&&
?.
)
{
=
<>
{
}
Last Execution Order:
{
.
executionOrder
}
</>
;
}
return
;
}
private
renderInfoMessage
(
:
string
)
{
return
(
<>
{
}
<br/>
</>
)
;
}
}
interface
IRunNotebookCellOutputProps
extends
BasePromptElementProps
{
:
.
NotebookCellOutput
;
:
number
;
:
number
;
}
export
class
RunNotebookCellOutput
extends
PromptElement<IRunNotebookCellOutputProps>
{
render
(
:
void
,
:
PromptSizing
)
{
const
{
,
}
=
this
.
props
;
const
=
.
items
.
find
(
(
)
=>
.
mime
===
'application/vnd.code.notebook.error'
)
;
if
(
)
{
const
=
.
data
.
toString
(
)
;
const
=
.
includes
(
'ModuleNotFoundError'
)
;
return
<Tagname='cell-execution-error'>
Error:
{
parseAndCleanStack
(
)
}
<br/>
{
?
`Either use notebook_install_packages_tool to install the missing package if the tool exists, or add/edit a cell with '%pip install' to install the package.`
:
'Make sure to check the contents of previous cells to see if rerunning those cells would resolve the issue.'