Skip to content

Commit 3bb00b7

Browse files
authored
let the value of IChatRequestToolSetEntry be tool entries (microsoft#250303)
* toolset telemetry * let the value of `IChatRequestToolSetEntry` be tool entries microsoft#250254
1 parent 024e565 commit 3bb00b7

File tree

7 files changed

+64
-35
lines changed

7 files changed

+64
-35
lines changed

src/vs/workbench/api/common/extHostChatAgents2.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Iterable } from '../../../base/common/iterator.js';
1313
import { Disposable, DisposableMap, DisposableStore, toDisposable } from '../../../base/common/lifecycle.js';
1414
import { revive } from '../../../base/common/marshalling.js';
1515
import { StopWatch } from '../../../base/common/stopwatch.js';
16-
import { assertType, isDefined } from '../../../base/common/types.js';
16+
import { assertType } from '../../../base/common/types.js';
1717
import { URI } from '../../../base/common/uri.js';
1818
import { generateUuid } from '../../../base/common/uuid.js';
1919
import { Location } from '../../../editor/common/languages.js';
@@ -631,13 +631,21 @@ export class ExtHostChatAgents2 extends Disposable implements ExtHostChatAgentsS
631631
{ ...ehResult, metadata: undefined };
632632

633633
// REQUEST turn
634-
const varsWithoutTools = h.request.variables.variables
635-
.filter(v => v.kind !== 'tool')
636-
.map(v => typeConvert.ChatPromptReference.to(v, this.getDiagnosticsWhenEnabled(extension), this._logService))
637-
.filter(isDefined);
638-
const toolReferences = h.request.variables.variables
639-
.filter(v => v.kind === 'tool')
640-
.map(typeConvert.ChatLanguageModelToolReference.to);
634+
const varsWithoutTools: vscode.ChatPromptReference[] = [];
635+
const toolReferences: vscode.ChatLanguageModelToolReference[] = [];
636+
for (const v of h.request.variables.variables) {
637+
if (v.kind === 'tool') {
638+
toolReferences.push(typeConvert.ChatLanguageModelToolReference.to(v));
639+
} else if (v.kind === 'toolset') {
640+
toolReferences.push(...v.value.map(typeConvert.ChatLanguageModelToolReference.to));
641+
} else {
642+
const ref = typeConvert.ChatPromptReference.to(v, this.getDiagnosticsWhenEnabled(extension), this._logService);
643+
if (ref) {
644+
varsWithoutTools.push(ref);
645+
}
646+
}
647+
}
648+
641649
const editedFileEvents = isProposedApiEnabled(extension, 'chatParticipantPrivate') ? h.request.editedFileEvents : undefined;
642650
const turn = new extHostTypes.ChatRequestTurn(h.request.message, h.request.command, varsWithoutTools, h.request.agentId, toolReferences, editedFileEvents);
643651
res.push(turn);

src/vs/workbench/api/common/extHostTypeConverters.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,8 +2922,19 @@ export namespace ChatResponsePart {
29222922

29232923
export namespace ChatAgentRequest {
29242924
export function to(request: IChatAgentRequest, location2: vscode.ChatRequestEditorData | vscode.ChatRequestNotebookData | undefined, model: vscode.LanguageModelChat, diagnostics: readonly [vscode.Uri, readonly vscode.Diagnostic[]][], tools: Map<string, boolean>, extension: IRelaxedExtensionDescription, logService: ILogService): vscode.ChatRequest {
2925-
const toolReferences = request.variables.variables.filter(v => v.kind === 'tool');
2926-
const variableReferences = request.variables.variables.filter(v => v.kind !== 'tool');
2925+
2926+
const toolReferences: typeof request.variables.variables = [];
2927+
const variableReferences: typeof request.variables.variables = [];
2928+
for (const v of request.variables.variables) {
2929+
if (v.kind === 'tool') {
2930+
toolReferences.push(v);
2931+
} else if (v.kind === 'toolset') {
2932+
toolReferences.push(...v.value);
2933+
} else {
2934+
variableReferences.push(v);
2935+
}
2936+
}
2937+
29272938
const requestWithAllProps: vscode.ChatRequest = {
29282939
id: request.requestId,
29292940
prompt: request.message,

src/vs/workbench/contrib/chat/browser/actions/chatContext.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { NotebookEditorInput } from '../../../notebook/common/notebookEditorInpu
2424
import { IChatContextPickService, IChatContextValueItem, IChatContextPickerItem, IChatContextPickerPickItem } from '../chatContextPickService.js';
2525
import { IChatEditingService } from '../../common/chatEditingService.js';
2626
import { IChatRequestToolEntry, IChatRequestToolSetEntry, IChatRequestVariableEntry, IImageVariableEntry, OmittedState } from '../../common/chatModel.js';
27-
import { ToolDataSource, ToolSet } from '../../common/languageModelToolsService.js';
27+
import { IToolData, ToolDataSource, ToolSet } from '../../common/languageModelToolsService.js';
2828
import { IChatWidget } from '../chat.js';
2929
import { imageToHash, isImage } from '../chatPasteProviders.js';
3030
import { convertBufferToScreenshotVariable } from '../contrib/screenshot.js';
@@ -80,30 +80,14 @@ class ToolsContextPickerPick implements IChatContextPickerItem {
8080
toolInfo: ToolDataSource.classify(entry.source),
8181
label: entry.referenceName,
8282
description: entry.description,
83-
asAttachment: (): IChatRequestToolSetEntry => {
84-
return {
85-
kind: 'toolset',
86-
id: entry.id,
87-
icon: entry.icon,
88-
name: entry.referenceName,
89-
value: undefined,
90-
};
91-
}
83+
asAttachment: (): IChatRequestToolSetEntry => this._asToolSetAttachment(entry)
9284
});
9385
} else {
9486
items.push({
9587
toolInfo: ToolDataSource.classify(entry.source),
9688
label: entry.toolReferenceName ?? entry.displayName,
9789
description: entry.userDescription ?? entry.modelDescription,
98-
asAttachment: (): IChatRequestToolEntry => {
99-
return {
100-
kind: 'tool',
101-
id: entry.id,
102-
icon: ThemeIcon.isThemeIcon(entry.icon) ? entry.icon : undefined,
103-
name: entry.displayName,
104-
value: undefined,
105-
};
106-
}
90+
asAttachment: (): IChatRequestToolEntry => this._asToolAttachment(entry)
10791
});
10892
}
10993
}
@@ -135,6 +119,26 @@ class ToolsContextPickerPick implements IChatContextPickerItem {
135119
picks: Promise.resolve(picks)
136120
};
137121
}
122+
123+
private _asToolAttachment(entry: IToolData): IChatRequestToolEntry {
124+
return {
125+
kind: 'tool',
126+
id: entry.id,
127+
icon: ThemeIcon.isThemeIcon(entry.icon) ? entry.icon : undefined,
128+
name: entry.displayName,
129+
value: undefined,
130+
};
131+
}
132+
133+
private _asToolSetAttachment(entry: ToolSet): IChatRequestToolSetEntry {
134+
return {
135+
kind: 'toolset',
136+
id: entry.id,
137+
icon: entry.icon,
138+
name: entry.referenceName,
139+
value: Array.from(entry.getTools()).map(t => this._asToolAttachment(t)),
140+
};
141+
}
138142
}
139143

140144

src/vs/workbench/contrib/chat/common/chatModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface IChatRequestToolEntry extends IBaseChatRequestVariableEntry {
7474

7575
export interface IChatRequestToolSetEntry extends IBaseChatRequestVariableEntry {
7676
readonly kind: 'toolset';
77-
readonly value: undefined;
77+
readonly value: IChatRequestToolEntry[];
7878
}
7979

8080
export interface IChatRequestImplicitVariableEntry extends IBaseChatRequestVariableEntry {

src/vs/workbench/contrib/chat/common/chatParserTypes.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ThemeIcon } from '../../../../base/common/themables.js';
88
import { IOffsetRange, OffsetRange } from '../../../../editor/common/core/ranges/offsetRange.js';
99
import { IRange } from '../../../../editor/common/core/range.js';
1010
import { IChatAgentCommand, IChatAgentData, IChatAgentService, reviveSerializedAgent } from './chatAgents.js';
11-
import { IChatRequestToolSetEntry, IChatRequestVariableEntry, IDiagnosticVariableEntryFilterData } from './chatModel.js';
11+
import { IChatRequestToolEntry, IChatRequestToolSetEntry, IChatRequestVariableEntry, IDiagnosticVariableEntryFilterData } from './chatModel.js';
1212
import { IChatSlashData } from './chatSlashCommands.js';
1313
import { IChatRequestProblemsVariable, IChatRequestVariableValue } from './chatVariables.js';
1414
import { ChatAgentLocation } from './constants.js';
@@ -88,7 +88,7 @@ export class ChatRequestToolPart implements IParsedChatRequestPart {
8888
return this.text;
8989
}
9090

91-
toVariableEntry(): IChatRequestVariableEntry {
91+
toVariableEntry(): IChatRequestToolEntry {
9292
return { kind: 'tool', id: this.toolId, name: this.toolName, range: this.range, value: undefined, icon: ThemeIcon.isThemeIcon(this.icon) ? this.icon : undefined, fullName: this.displayName };
9393
}
9494
}
@@ -99,7 +99,7 @@ export class ChatRequestToolPart implements IParsedChatRequestPart {
9999
export class ChatRequestToolSetPart implements IParsedChatRequestPart {
100100
static readonly Kind = 'toolset';
101101
readonly kind = ChatRequestToolSetPart.Kind;
102-
constructor(readonly range: OffsetRange, readonly editorRange: IRange, readonly id: string, readonly name: string, readonly icon: ThemeIcon) { }
102+
constructor(readonly range: OffsetRange, readonly editorRange: IRange, readonly id: string, readonly name: string, readonly icon: ThemeIcon, readonly tools: IChatRequestToolEntry[]) { }
103103

104104
get text(): string {
105105
return `${chatVariableLeader}${this.name}`;
@@ -110,7 +110,7 @@ export class ChatRequestToolSetPart implements IParsedChatRequestPart {
110110
}
111111

112112
toVariableEntry(): IChatRequestToolSetEntry {
113-
return { kind: 'toolset', id: this.id, name: this.name, range: this.range, icon: this.icon, value: undefined };
113+
return { kind: 'toolset', id: this.id, name: this.name, range: this.range, icon: this.icon, value: this.tools };
114114
}
115115
}
116116

@@ -242,6 +242,7 @@ export function reviveParsedChatRequest(serialized: IParsedChatRequest): IParsed
242242
(part as ChatRequestToolSetPart).id,
243243
(part as ChatRequestToolSetPart).name,
244244
(part as ChatRequestToolSetPart).icon,
245+
(part as ChatRequestToolSetPart).tools ?? [],
245246
);
246247
} else if (part.kind === ChatRequestAgentPart.Kind) {
247248
let agent = (part as ChatRequestAgentPart).agent;

src/vs/workbench/contrib/chat/common/chatRequestParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ export class ChatRequestParser {
165165

166166
const toolset = toolSetsByName.get(name);
167167
if (toolset) {
168-
return new ChatRequestToolSetPart(varRange, varEditorRange, toolset.id, toolset.referenceName, toolset.icon);
168+
const value = Array.from(toolset.getTools()).map(t => new ChatRequestToolPart(varRange, varEditorRange, t.toolReferenceName ?? t.displayName, t.id, t.displayName, t.icon).toVariableEntry());
169+
return new ChatRequestToolSetPart(varRange, varEditorRange, toolset.id, toolset.referenceName, toolset.icon, value);
169170
}
170171

171172
return;

src/vs/workbench/contrib/chat/common/chatServiceImpl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,8 @@ export class ChatService extends Disposable implements IChatService {
961961
// 'range' is range within the prompt text
962962
if (v.kind === 'tool') {
963963
return 'toolInPrompt';
964+
} else if (v.kind === 'toolset') {
965+
return 'toolsetInPrompt';
964966
} else {
965967
return 'fileInPrompt';
966968
}
@@ -974,6 +976,8 @@ export class ChatService extends Disposable implements IChatService {
974976
return 'directory';
975977
} else if (v.kind === 'tool') {
976978
return 'tool';
979+
} else if (v.kind === 'toolset') {
980+
return 'toolset';
977981
} else {
978982
if (URI.isUri(v.value)) {
979983
return 'file';

0 commit comments

Comments
 (0)