Skip to content

Commit 6a6ce14

Browse files
authored
Fix tool call params order (microsoft#226502)
And convert tool_use part correctly
1 parent df612ac commit 6a6ce14

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,8 +2316,10 @@ export namespace LanguageModelChatMessage {
23162316
const content2 = message.content.map(c => {
23172317
if (c.type === 'text') {
23182318
return c.value;
2319-
} else {
2319+
} else if (c.type === 'tool_result') {
23202320
return new types.LanguageModelToolResultPart(c.toolCallId, c.value, c.isError);
2321+
} else {
2322+
return new types.LanguageModelToolCallPart(c.name, c.toolCallId, c.parameters);
23212323
}
23222324
});
23232325
const content = content2.find(c => typeof c === 'string') ?? '';
@@ -2333,17 +2335,28 @@ export namespace LanguageModelChatMessage {
23332335
const name = message.name;
23342336

23352337
const content = message.content2.map((c): chatProvider.IChatMessagePart => {
2336-
if (message.content2 instanceof types.LanguageModelToolResultPart) {
2338+
if (c instanceof types.LanguageModelToolResultPart) {
23372339
return {
23382340
type: 'tool_result',
2339-
toolCallId: message.content2.toolCallId,
2340-
value: message.content2.content,
2341-
isError: message.content2.isError
2341+
toolCallId: c.toolCallId,
2342+
value: c.content,
2343+
isError: c.isError
2344+
};
2345+
} else if (c instanceof types.LanguageModelToolCallPart) {
2346+
return {
2347+
type: 'tool_use',
2348+
toolCallId: c.toolCallId,
2349+
name: c.name,
2350+
parameters: c.parameters
23422351
};
23432352
} else {
2353+
if (typeof c !== 'string') {
2354+
throw new Error('Unexpected chat message content type');
2355+
}
2356+
23442357
return {
23452358
type: 'text',
2346-
value: message.content
2359+
value: c
23472360
};
23482361
}
23492362
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface IChatMessageToolResultPart {
3434
isError?: boolean;
3535
}
3636

37-
export type IChatMessagePart = IChatMessageTextPart | IChatMessageToolResultPart;
37+
export type IChatMessagePart = IChatMessageTextPart | IChatMessageToolResultPart | IChatResponseToolUsePart;
3838

3939
export interface IChatMessage {
4040
readonly name?: string | undefined;

src/vscode-dts/vscode.proposed.lmTools.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare module 'vscode' {
3535
toolCallId: string;
3636
parameters: any;
3737

38-
constructor(name: string, parameters: any, toolCallId: string);
38+
constructor(name: string, toolCallId: string, parameters: any);
3939
}
4040

4141
// LM -> USER: text chunk

0 commit comments

Comments
 (0)