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 / insertEditTool.tsx 141 строк · изменён 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
import type * as vscode from 'vscode' ;
import { NotebookDocumentSnapshot } from '../../../platform/editing/common/notebookDocumentSnapshot' ;
import { IEndpointProvider } from '../../../platform/endpoint/common/endpointProvider' ;
import { ILanguageDiagnosticsService } from '../../../platform/languages/common/languageDiagnosticsService' ;
import { ILogService } from '../../../platform/log/common/logService' ;
import { IAlternativeNotebookContentService } from '../../../platform/notebook/common/alternativeContent'
explanation
filePath
code
toolName
nonDeferred
promptContext
@ promptPathRepresentationService
@ instantiationService
@ workspaceService
@ toolsService
@ notebookService
@ languageDiagnosticsService
@ alternativeNotebookContentService
@ telemetryService
@ endpointProvider
@ editToolLearningService
@ logService
options vscode token vscode
uri options
uri
disallowedUriError uri allowedEditUris
disallowedUriError
disallowedUriError
accessor accessor uri
existingDiagnostics uri
internalOptions
options
input
options
uri
internalOptions token
options
error
options
error
isNotebook uri
isNotebook
uri request model
uri
uri requestId options request model
files operation uri isNotebook existingDiagnostics toolName requestId options model options
options
tokenBudget
t t
token
options vscode token vscode vscode vscode
uri options
createEditConfirmation
uri uri
allowedEditUris
options
options
options
input promptContext
promptContext
input
options vscode success
options
options success
options input options success
;
import
{ INotebookService }
from
'../../../platform/notebook/common/notebookService'
;
import
{ IPromptPathRepresentationService }
from
'../../../platform/prompts/common/promptPathRepresentationService'
;
import
{ ITelemetryService }
from
'../../../platform/telemetry/common/telemetry'
;
import
{ IWorkspaceService }
from
'../../../platform/workspace/common/workspaceService'
;
import
{ IInstantiationService }
from
'../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ LanguageModelPromptTsxPart , LanguageModelToolResult }
from
'../../../vscodeTypes'
;
import
{ IBuildPromptContext }
from
'../../prompt/common/intents'
;
import
{ renderPromptElementJSON }
from
'../../prompts/node/base/promptRenderer'
;
import
{ IEditToolLearningService }
from
'../common/editToolLearningService'
;
import
{ ToolName }
from
'../common/toolNames'
;
import
{ ICopilotTool , ToolRegistry }
from
'../common/toolsRegistry'
;
import
{ IToolsService }
from
'../common/toolsService'
;
import
{ ActionType }
from
'./applyPatch/parser'
;
import
{ EditFileResult }
from
'./editFileToolResult'
;
import
{ createEditConfirmation, getDisallowedEditUriError, logEditToolResult }
from
'./editFileToolUtils'
;
import
{ sendEditNotebookTelemetry }
from
'./editNotebookTool'
;
import
{ assertFileNotContentExcluded }
from
'./toolUtils'
;
export
interface
IEditFileParams
{
:
string
;
:
string
;
:
string
;
}
export
const
InternalEditToolId
=
'vscode_editFile_internal'
;
export
class
EditFileTool
implements
ICopilotTool< IEditFileParams>
{
public
static
=
ToolName
.
EditFile
;
public
static
readonly
=
true
;
private
?
:
IBuildPromptContext
;
constructor
(
IPromptPathRepresentationService
protected
readonly
:
IPromptPathRepresentationService
,
IInstantiationService
protected
readonly
:
IInstantiationService
,
IWorkspaceService
protected
readonly
:
IWorkspaceService
,
IToolsService
protected
readonly
:
IToolsService
,
INotebookService
protected
readonly
:
INotebookService
,
ILanguageDiagnosticsService
protected
readonly
:
ILanguageDiagnosticsService
,
IAlternativeNotebookContentService
private
readonly
:
IAlternativeNotebookContentService
,
ITelemetryService
private
readonly
:
ITelemetryService
,
IEndpointProvider
private
readonly
:
IEndpointProvider
,
IEditToolLearningService
private
readonly
:
IEditToolLearningService
,
ILogService
private
readonly
:
ILogService
,
)
{
}
async
invoke
(
:
.
LanguageModelToolInvocationOptions
<
IEditFileParams
>
,
:
.
CancellationToken
)
{
const
=
this
.
promptPathRepresentationService
.
resolveFilePath
(
.
input
.
filePath
)
;
if
(
!
)
{
throw
new
Error
(
` Invalid file path `
)
;
}
const
=
getDisallowedEditUriError
(
,
this
.
promptContext
?.
,
this
.
promptPathRepresentationService
)
;
if
(
)
{
throw
new
Error
(
)
;
}
await
this
.
instantiationService
.
invokeFunction
(
=>
assertFileNotContentExcluded
(
,
)
)
;
const
=
this
.
languageDiagnosticsService
.
getDiagnostics
(
)
;
const
=
{
...
,
:
{
...
.
input
,
}
}
;
try
{
await
this
.
toolsService
.
invokeTool
(
InternalEditToolId
,
,
)
;
void
this
.
recordEditSuccess
(
,
true
)
;
}
catch
(
)
{
void
this
.
recordEditSuccess
(
,
false
)
;
throw
;
}
const
=
this
.
notebookService
.
hasSupportedNotebooks
(
)
;
const
document
=
?
await
this
.
workspaceService
.
openNotebookDocumentAndSnapshot
(
,
this
.
alternativeNotebookContentService
.
getFormat
(
this
.
promptContext
?.
?.
)
)
:
await
this
.
workspaceService
.
openTextDocumentAndSnapshot
(
)
;
if
(
document
instanceof
NotebookDocumentSnapshot
)
{
sendEditNotebookTelemetry
(
this
.
telemetryService
,
this
.
endpointProvider
,
'insertEdit'
,
,
this
.
promptContext
?.
,
.
model
??
this
.
promptContext
?.
?.
)
;
}
return
new
LanguageModelToolResult
(
[
new
LanguageModelPromptTsxPart
(
await
renderPromptElementJSON
(
this
.
instantiationService
,
EditFileResult
,
{
:
[
{
:
ActionType
.
UPDATE
,
,
,
}
]
,
:
ToolName
.
EditFile
,
:
.
chatRequestId
,
:
.
model
}
,
.
tokenizationOptions
??
{
:
1000
,
countTokens
:
(
)
=>
Promise
.
resolve
(
.
length
*
3
/
4
)
}
,
,
)
,
)
]
)
;
}
prepareInvocation
(
:
.
LanguageModelToolInvocationPrepareOptions
<
IEditFileParams
>
,
:
.
CancellationToken
)
:
.
ProviderResult
<
.
PreparedToolInvocation
>
{
const
=
this
.
promptPathRepresentationService
.
resolveFilePath
(
.
input
.
filePath
)
;
return
this
.
instantiationService
.
invokeFunction
(
,
?
[
]
:
[
]
,
this
.
promptContext
?.
,
async
(
)
=>
'```\n'
+
.
input
.
code
+
'\n```'
,
.
forceConfirmationReason
,
undefined
,
.
workingDirectory
,
)
;
}
async
resolveInput
(
:
IEditFileParams
,
:
IBuildPromptContext
)
:
Promise
<
IEditFileParams
>
{
this
.
promptContext
=
;
return
;
}
private
recordEditSuccess
(
:
.
LanguageModelToolInvocationOptions
<
IEditFileParams
>
,
:
boolean
)
{
if
(
.
model
)
{
this
.
editToolLearningService
.
didMakeEdit
(
.
model
,
ToolName
.
EditFile
,
)
;
}
logEditToolResult
(
this
.
logService
,
.
chatRequestId
,
{
:
.
input
,
}
)
;
}
}
ToolRegistry
.
registerTool
(
EditFileTool
)
;