diff --git a/chat-sample/package.json b/chat-sample/package.json index 310b2ce5..a5ed3ab7 100644 --- a/chat-sample/package.json +++ b/chat-sample/package.json @@ -37,10 +37,19 @@ "id": "chat-sample_tabCount", "name": "tabCount", "displayName": "Tab Count", - "modelDescription": "The number of active tabs in the editor", - "userDescription": "The number of active tabs in the editor", + "modelDescription": "The number of active tabs in a tab group", "icon": "$(files)", - "canBeInvokedManually": true + "canBeInvokedManually": true, + "parametersSchema": { + "type": "object", + "properties": { + "tabGroup": { + "type": "number", + "description": "The index of the tab group to check. This is optional- if not specified, the active tab group will be checked.", + "default": 0 + } + } + } }, { "id": "chat-sample_catVoice", diff --git a/chat-sample/src/extension.ts b/chat-sample/src/extension.ts index 41c23936..b5eed266 100644 --- a/chat-sample/src/extension.ts +++ b/chat-sample/src/extension.ts @@ -9,9 +9,9 @@ export function activate(context: vscode.ExtensionContext) { function registerChatTool() { vscode.lm.registerTool('chat-sample_catVoice', { - async invoke(parameters, token) { + async invoke(options, token) { return { - [contentType]: await renderElementJSON(CatToolPrompt, {}, parameters.tokenOptions, token), + [contentType]: await renderElementJSON(CatToolPrompt, {}, options.tokenOptions, token), toString() { return 'Reply in the voice of a cat! Use cat analogies when appropriate.'; }, @@ -19,12 +19,24 @@ function registerChatTool() { }, }); + interface ITabCountParameters { + tabGroup?: number; + } + return vscode.lm.registerTool('chat-sample_tabCount', { - async invoke(parameters, token) { + async invoke(options, token) { return { toString() { - const activeTabCount = vscode.window.tabGroups.activeTabGroup.tabs.length; - return `There are ${activeTabCount} tabs open.`; + const params = options.parameters as ITabCountParameters; + if (typeof params.tabGroup === 'number') { + const group = vscode.window.tabGroups.all[Math.max(params.tabGroup - 1, 0)]; + const nth = params.tabGroup === 1 ? '1st' : params.tabGroup === 2 ? '2nd' : params.tabGroup === 3 ? '3rd' : `${params.tabGroup}th`; + return `There are ${group.tabs.length} tabs open in the ${nth} tab group.`; + } else { + const group = vscode.window.tabGroups.activeTabGroup; + return `There are ${group.tabs.length} tabs open.`; + } + }, }; },