diff --git a/chat-sample/package.json b/chat-sample/package.json index 691458ed..fb3a97d5 100644 --- a/chat-sample/package.json +++ b/chat-sample/package.json @@ -52,7 +52,8 @@ }, "supportedContentTypes": [ "text/plain" - ] + ], + "requiresConfirmation": true }, { "id": "chat-sample_catVoice", diff --git a/chat-sample/src/extension.ts b/chat-sample/src/extension.ts index 91510bcd..b18e68de 100644 --- a/chat-sample/src/extension.ts +++ b/chat-sample/src/extension.ts @@ -21,6 +21,7 @@ function registerChatTool(context: vscode.ExtensionContext) { return result; }, + provideToolInvocationMessage: async () => 'Speaking in the voice of a cat', })); interface ITabCountParameters { @@ -29,6 +30,7 @@ function registerChatTool(context: vscode.ExtensionContext) { context.subscriptions.push(vscode.lm.registerTool('chat-sample_tabCount', { async invoke(options, token) { + await new Promise(resolve => setTimeout(resolve, 5000)); const params = options.parameters as ITabCountParameters; if (typeof params.tabGroup === 'number') { const group = vscode.window.tabGroups.all[Math.max(params.tabGroup - 1, 0)]; @@ -39,6 +41,14 @@ function registerChatTool(context: vscode.ExtensionContext) { return { 'text/plain': `There are ${group.tabs.length} tabs open.` }; } }, + provideToolInvocationMessage: async () => 'Counting the number of tabs', + provideToolConfirmationMessages: async (options) => { + const params = options.parameters as ITabCountParameters; + return { + title: 'Count the number of open tabs', + message: new vscode.MarkdownString(`${options.participantName} will count the number of **open tabs**` + (params.tabGroup !== undefined ? ` in tab group ${params.tabGroup}` : '')) + }; + } })); } @@ -56,7 +66,7 @@ function registerChatParticipant(context: vscode.ExtensionContext) { }); const model = models[0]; - stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.id).join(', ')}\n\n`); + // stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.id).join(', ')}\n\n`); const allTools = vscode.lm.tools.map((tool): vscode.LanguageModelChatTool => { return { @@ -106,7 +116,6 @@ function registerChatParticipant(context: vscode.ExtensionContext) { throw new Error(`Got invalid tool use parameters: "${part.parameters}". (${(err as Error).message})`); } - stream.progress(`Calling tool: ${tool.id} with ${part.parameters}`); // TODO support prompt-tsx here const requestedContentType = 'text/plain'; toolCalls.push({ diff --git a/chat-sample/vscode.proposed.lmTools.d.ts b/chat-sample/vscode.proposed.lmTools.d.ts index 43749d8a..89175362 100644 --- a/chat-sample/vscode.proposed.lmTools.d.ts +++ b/chat-sample/vscode.proposed.lmTools.d.ts @@ -166,9 +166,28 @@ declare module 'vscode' { supportedContentTypes: string[]; } + export interface LanguageModelToolProvideConfirmationMessageOptions { + participantName: string; + parameters: any; + } + + export interface LanguageModelToolConfirmationMessages { + title: string; + message: string | MarkdownString; + } + export interface LanguageModelTool { - // TODO@API should it be LanguageModelToolResult | string? invoke(options: LanguageModelToolInvocationOptions, token: CancellationToken): ProviderResult; + + /** + * This can be implemented to customize the message shown to the user when a tool requires confirmation. + */ + provideToolConfirmationMessages?(options: LanguageModelToolProvideConfirmationMessageOptions, token: CancellationToken): Thenable; + + /** + * This message will be shown with the progress notification when the tool is invoked in a chat session. + */ + provideToolInvocationMessage?(parameters: any, token: CancellationToken): Thenable; } export interface ChatLanguageModelToolReference {