2024-11-18 09:46:04 -08:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
import * as chatUtils from '@vscode/chat-extension-utils';
|
|
|
|
|
|
|
|
|
|
export function registerChatLibChatParticipant(context: vscode.ExtensionContext) {
|
2025-09-23 21:57:41 -07:00
|
|
|
const handler: vscode.ChatRequestHandler = async (request: vscode.ChatRequest, chatContext: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken) => {
|
|
|
|
|
if (request.command === 'list') {
|
|
|
|
|
stream.markdown(`Available tools: ${vscode.lm.tools.map(tool => tool.name).join(', ')}\n\n`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-18 09:46:04 -08:00
|
|
|
|
2025-09-23 21:57:41 -07:00
|
|
|
const tools = request.command === 'all' ?
|
|
|
|
|
vscode.lm.tools :
|
|
|
|
|
vscode.lm.tools.filter(tool => tool.tags.includes('chat-tools-sample'));
|
2024-11-18 09:46:04 -08:00
|
|
|
|
2025-09-23 21:57:41 -07:00
|
|
|
const libResult = chatUtils.sendChatParticipantRequest(
|
|
|
|
|
request,
|
|
|
|
|
chatContext,
|
|
|
|
|
{
|
|
|
|
|
prompt: 'You are a cat! Answer as a cat.',
|
|
|
|
|
responseStreamOptions: {
|
|
|
|
|
stream,
|
|
|
|
|
references: true,
|
|
|
|
|
responseText: true
|
|
|
|
|
},
|
|
|
|
|
tools
|
|
|
|
|
},
|
|
|
|
|
token);
|
2024-11-18 09:46:04 -08:00
|
|
|
|
2025-09-23 21:57:41 -07:00
|
|
|
return await libResult.result;
|
|
|
|
|
};
|
2024-11-18 09:46:04 -08:00
|
|
|
|
2025-09-23 21:57:41 -07:00
|
|
|
const chatLibParticipant = vscode.chat.createChatParticipant('chat-tools-sample.catTools', handler);
|
|
|
|
|
chatLibParticipant.iconPath = vscode.Uri.joinPath(context.extensionUri, 'cat.jpeg');
|
|
|
|
|
context.subscriptions.push(chatLibParticipant);
|
2024-11-18 09:46:04 -08:00
|
|
|
}
|