Skip to content

Commit

Permalink
Move edit_file tool to extension (#241657)
Browse files Browse the repository at this point in the history
Core contributes a tool which is the real implementation of file editing, but the extension gets to control the tool result
  • Loading branch information
roblourens authored Feb 24, 2025
1 parent eb6f14e commit 2e6b279
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const _allApiProposals = {
},
chatParticipantPrivate: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts',
version: 3
version: 4
},
chatProvider: {
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.chatProvider.d.ts',
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/api/common/extHostLanguageModelTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { checkProposedApiEnabled, isProposedApiEnabled } from '../../services/ex
import { ExtHostLanguageModelToolsShape, IMainContext, IToolDataDto, MainContext, MainThreadLanguageModelToolsShape } from './extHost.protocol.js';
import * as typeConvert from './extHostTypeConverters.js';
import { IToolInputProcessor } from '../../contrib/chat/common/tools/tools.js';
import { EditToolData, EditToolId, EditToolInputProcessor } from '../../contrib/chat/common/tools/editFileTool.js';
import { EditToolData, InternalEditToolId, EditToolInputProcessor, ExtensionEditToolId } from '../../contrib/chat/common/tools/editFileTool.js';
import { Dto } from '../../services/extensions/common/proxyIdentifier.js';

export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape {
Expand Down Expand Up @@ -62,7 +62,7 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
throw new Error(`Invalid tool invocation token`);
}

if (toolId === EditToolId && !isProposedApiEnabled(extension, 'chatParticipantPrivate')) {
if ((toolId === InternalEditToolId || toolId === ExtensionEditToolId) && !isProposedApiEnabled(extension, 'chatParticipantPrivate')) {
throw new Error(`Invalid tool: ${toolId}`);
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export class ExtHostLanguageModelTools implements ExtHostLanguageModelToolsShape
return Array.from(this._allTools.values())
.map(tool => typeConvert.LanguageModelToolDescription.to(tool))
.filter(tool => {
if (tool.name === EditToolId) {
if (tool.name === InternalEditToolId || tool.name === ExtensionEditToolId) {
return isProposedApiEnabled(extension, 'chatParticipantPrivate');
}

Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/contrib/chat/common/tools/editFileTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ class Person {
}
`;

export const EditToolId = 'vscode_editFile';
export const ExtensionEditToolId = 'vscode_editFile';
export const InternalEditToolId = 'vscode_editFile_internal';
export const EditToolData: IToolData = {
id: EditToolId,
tags: ['vscode_editing'],
id: InternalEditToolId,
displayName: localize('chat.tools.editFile', "Edit File"),
modelDescription: `Edit a file in the workspace. Use this tool once per file that needs to be modified, even if there are multiple changes for a file. Generate the "explanation" property first. ${codeInstructions}`,
inputSchema: {
Expand Down
2 changes: 1 addition & 1 deletion src/vscode-dts/vscode.proposed.chatParticipantPrivate.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// version: 3
// version: 4

declare module 'vscode' {

Expand Down

0 comments on commit 2e6b279

Please sign in to comment.