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 / tools / node / notebookSummaryTool.tsx 188 строк · изменён 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
import * as l10n from '@vscode/l10n' ;
import { PromptElement , PromptElementProps , PromptSizing } from '@vscode/prompt-tsx' ;
import type * as vscode from 'vscode' ;
import { IAlternativeNotebookContentService } from '../../../platform/notebook/common/alternativeContent' ;
import { getCellId } from '../../../platform/notebook/common/helpers' ;
import { INotebookSummaryTracker } from '../../../platform/notebook/common/notebookSummaryTracker'
filePath
toolName
promptContext
@ promptPathRepresentationService
@ instantiationService
@ workspaceService
@ alternativeNotebookContent
@ notebookStructureTracker
@ notebookService
@ logger
options vscode token vscode
uri options
uri
notebook uri
notebook
uri notebook
uri
notebook notebook uri
ex
ex
token
notebook
notebook
format request model
altDoc format notebook
notebook altDoc includeCellLines
options
tokenBudget
t t
token
input promptContext
promptContext
input
options vscode token vscode vscode vscode
invocationMessage l10n
notebook vscode
altDoc
includeCellLines
props
@ alternativeNotebookContent
@ promptPathRepresentationService
@ logger
props
override state sizing
ex
ex
ex
hasAnyCellBeenExecuted cell cell executionOrder cell timing
altDoc
includeCellLines altDoc
hasAnyCellBeenExecuted cell i
cellNumber i
language cell
cellType cell
executionOrder cell executionOrder
cellId cell
executionSummary
altCellStartLine includeCellLines altDoc cell
altCellEndLine includeCellLines altDoc cell cell
cellLines
executionOrder cell timing
executionSummary
state cell success cell
executionSummary
cell
executionSummary
indent
mimeTypes
cell output output item mimeTypes item
outputs cell cell indent mimeTypes
cellNumber cellId indent cellType language includeCellLines indent cellLines indent executionSummary outputs
;
import
{ IPromptPathRepresentationService }
from
'../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ IWorkspaceService }
from
'../../../platform/workspace/common/workspaceService'
;
import
{ findNotebook }
from
'../../../util/common/notebooks'
;
import
{ IInstantiationService }
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ LanguageModelPromptTsxPart , LanguageModelToolResult , MarkdownString , NotebookCellKind , Position }
from
'../../../vscodeTypes'
;
import
{ IBuildPromptContext }
from
'../../prompt/common/intents'
;
import
{ renderPromptElementJSON }
from
'../../prompts/node/base/promptRenderer'
;
import
{ NotebookVariables }
from
'../../prompts/node/panel/notebookVariables'
;
import
{ ToolName }
from
'../common/toolNames'
;
import
{ ICopilotTool , ToolRegistry }
from
'../common/toolsRegistry'
;
import
{ AlternativeNotebookDocument }
from
'../../../platform/notebook/common/alternativeNotebookDocument'
;
import
{ INotebookService }
from
'../../../platform/notebook/common/notebookService'
;
import
{ ILogService }
from
'../../../platform/log/common/logService'
;
export
interface
INotebookSummaryToolParams
{
:
string
;
}
export
class
NotebookSummaryTool
implements
ICopilotTool< INotebookSummaryToolParams>
{
public
static
=
ToolName
.
GetNotebookSummary
;
private
?
:
IBuildPromptContext
;
constructor
(
IPromptPathRepresentationService
protected
readonly
:
IPromptPathRepresentationService
,
IInstantiationService
protected
readonly
:
IInstantiationService
,
IWorkspaceService
protected
readonly
:
IWorkspaceService
,
IAlternativeNotebookContentService
protected
readonly
:
IAlternativeNotebookContentService
,
INotebookSummaryTracker
protected
readonly
:
INotebookSummaryTracker
,
INotebookService
private
readonly
:
INotebookService
,
ILogService
private
readonly
:
ILogService
,
)
{
}
async
invoke
(
:
.
LanguageModelToolInvocationOptions
<
INotebookSummaryToolParams
>
,
:
.
CancellationToken
)
{
this
.
logger
.
trace
(
` Invoking Notebook Summary Tool for file ${ options. input. filePath} `
)
;
let
=
this
.
promptPathRepresentationService
.
resolveFilePath
(
.
input
.
filePath
)
;
if
(
!
)
{
throw
new
Error
(
` Invalid file path `
)
;
}
let
=
findNotebook
(
,
this
.
workspaceService
.
notebookDocuments
)
;
if
(
)
{
=
.
uri
;
}
else
if
(
!
this
.
notebookService
.
hasSupportedNotebooks
(
)
)
{
throw
new
Error
(
` Use this tool only with Notebook files, the file ${ uri. toString ( ) } is not a notebook. `
)
;
}
try
{
=
||
await
this
.
workspaceService
.
openNotebookDocument
(
)
;
}
catch
(
)
{
this
.
logger
.
error
(
` Failed to open notebook: ${ uri. toString ( ) } `
,
)
;
throw
new
Error
(
` Failed to open the notebook ${ uri. toString ( ) } , ${ ex. message || '' } . Verify the file exists. `
)
;
}
if
(
.
isCancellationRequested
)
{
return
;
}
this
.
notebookStructureTracker
.
trackNotebook
(
)
;
this
.
notebookStructureTracker
.
clearState
(
)
;
const
=
this
.
alternativeNotebookContent
.
getFormat
(
this
.
promptContext
?.
?.
)
;
const
=
this
.
alternativeNotebookContent
.
create
(
)
.
getAlternativeDocument
(
)
;
return
new
LanguageModelToolResult
(
[
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
NotebookSummary
,
{
,
,
:
true
}
,
.
tokenizationOptions
??
{
:
1000
,
countTokens
:
(
)
=>
Promise
.
resolve
(
.
length
*
3
/
4
)
}
,
,
)
,
)
]
)
;
}
async
resolveInput
(
:
INotebookSummaryToolParams
,
:
IBuildPromptContext
)
:
Promise
<
INotebookSummaryToolParams
>
{
this
.
promptContext
=
;
return
;
}
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
INotebookSummaryToolParams
>
,
:
.
CancellationToken
)
:
.
ProviderResult
<
.
PreparedToolInvocation
>
{
return
{
:
new
MarkdownString
(
.
t
` Retrieving Notebook summary. `
)
}
;
}
}
ToolRegistry
.
registerTool
(
NotebookSummaryTool
)
;
type
NotebookStatePromptProps
=
PromptElementProps
<
{
:
.
NotebookDocument
;
:
AlternativeNotebookDocument
|
undefined
;
:
boolean
;
}
>
;
export
class
NotebookSummary
extends
PromptElement< NotebookStatePromptProps>
{
constructor
(
:
NotebookStatePromptProps
,
IAlternativeNotebookContentService
protected
readonly
:
IAlternativeNotebookContentService
,
IPromptPathRepresentationService
protected
readonly
:
IPromptPathRepresentationService
,
ILogService
private
readonly
:
ILogService
,
)
{
super
(
)
;
}
async
render
(
:
void
,
:
PromptSizing
)
{
try
{
return
(
< >
{
this
.
getSummary
(
)
}
< br />
< NotebookVariables notebook = { this . props . notebook } />
</ >
)
;
}
catch
(
)
{
this
.
logger
.
error
(
` Error rendering NotebookSummary prompt element for notebook ${ this . props. notebook. uri. toString ( ) } `
,
)
;
throw
;
}
}
private
getSummary
(
)
{
this
.
logger
.
trace
(
` Generating notebook summary for ${ this . props. notebook. uri. toString ( ) } `
)
;
const
=
this
.
props
.
notebook
.
getCells
(
)
.
some
(
=>
.
executionSummary
?.
!==
undefined
&&
.
executionSummary
?.
)
;
const
=
this
.
props
.
altDoc
;
const
=
this
.
props
.
includeCellLines
&&
!
!
;
return
(
< >
Below is a summary of the notebook
{
this
.
promptPathRepresentationService
.
getFilePath
(
this
.
props
.
notebook
.
uri
)
}
:
< br />
{
?
'The execution count can be used to determine the order in which the cells were executed'
:
'None of the cells have been executed'
}
.
< br />
{
this
.
props
.
notebook
.
cellCount
===
0
?
'This notebook does not have any cells.'
:
''
}
< br />
{
this
.
props
.
notebook
.
getCells
(
)
.
map
(
(
,
)
=>
{
const
=
+
1
;
const
=
.
kind
===
NotebookCellKind
.
Code
?
` , Language = ${ cell. document. languageId} `
:
''
;
const
=
.
kind
===
NotebookCellKind
.
Code
?
'Code'
:
'Markdown'
;
const
=
.
executionSummary
?.
;
const
=
getCellId
(
)
;
let
=
''
;
const
=
?
.
fromCellPosition
(
,
new
Position
(
0
,
0
)
)
.
line
+
1
:
-
1
;
const
=
?
.
fromCellPosition
(
,
new
Position
(
.
document
.
lineCount
-
1
,
0
)
)
.
line
+
1
:
-
1
;
const
=
` From ${ altCellStartLine} to ${ altCellEndLine} `
;
if
(
===
undefined
||
!
.
executionSummary
?.
)
{
=
` Execution = Cell not executed. `
;
}
else
{
const
=
typeof
.
executionSummary
?.
===
'undefined'
?
'and'
:
(
.
executionSummary
.
success
?
'successfully and'
:
'with errors and'
)
;
=
` Execution = Cell executed ${ state} execution Count = ${ executionOrder} `
;
}
if
(
.
kind
===
NotebookCellKind
.
Markup
)
{
=
'This is a markdown cell, and cannot be executed.'
;
}
const
=
' '
;
const
=
new
Set< string >
(
)
;
.
outputs
.
forEach
(
=>
.
items
.
forEach
(
=>
.
add
(
.
mime
)
)
)
;
const
=
(
.
kind
!==
NotebookCellKind
.
Markup
&&
.
outputs
.
length
>
0
)
?
< >
{
}
Cell has outputs with mime types =
{
Array
.
from
(
)
.
join
(
', '
)
}
< br />
</ >
:
< >
</ >
;
return
(
< >
{
}
. Cell Id =
{
}
< br />
{
}
Cell Type =
{
}
{
}
< br />
{
&&
< >
{
}
Cell Lines =
{
}
< br />
</ >
}
{
}
{
}
< br />
{
}
</ >
)
;
}
)
}
</ >
)
;
}
}