Skip to content

Commit 1155663

Browse files
authored
Add ToolResultAudience and ChatResponsePullRequestPart (microsoft#257806)
* Add ToolResultAudience and ChatResponsePullRequestPart Part of microsoft#255383 * Clean up
1 parent 34786eb commit 1155663

17 files changed

+311
-33
lines changed

src/vs/base/common/marshallingIds.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ export const enum MarshalledId {
2828
LanguageModelPromptTsxPart,
2929
LanguageModelDataPart,
3030
ChatSessionContext,
31+
ChatResponsePullRequestPart,
3132
}

src/vs/platform/extensions/common/extensionsApiProposals.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ const _allApiProposals = {
251251
languageModelSystem: {
252252
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageModelSystem.d.ts',
253253
},
254+
languageModelToolResultAudience: {
255+
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageModelToolResultAudience.d.ts',
256+
},
254257
languageStatusText: {
255258
proposal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.languageStatusText.d.ts',
256259
},

src/vs/workbench/api/common/extHost.api.impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
18551855
ChatResponseConfirmationPart: extHostTypes.ChatResponseConfirmationPart,
18561856
ChatResponseMovePart: extHostTypes.ChatResponseMovePart,
18571857
ChatResponseExtensionsPart: extHostTypes.ChatResponseExtensionsPart,
1858+
ChatResponsePullRequestPart: extHostTypes.ChatResponsePullRequestPart,
18581859
ChatPrepareToolInvocationPart: extHostTypes.ChatPrepareToolInvocationPart,
18591860
ChatResponseReferencePartStatusKind: extHostTypes.ChatResponseReferencePartStatusKind,
18601861
ChatRequestTurn: extHostTypes.ChatRequestTurn,
@@ -1873,11 +1874,14 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
18731874
LanguageModelToolResultPart: extHostTypes.LanguageModelToolResultPart,
18741875
LanguageModelToolResultPart2: extHostTypes.LanguageModelToolResultPart2,
18751876
LanguageModelTextPart: extHostTypes.LanguageModelTextPart,
1877+
LanguageModelTextPart2: extHostTypes.LanguageModelTextPart,
1878+
ToolResultAudience: extHostTypes.ToolResultAudience,
18761879
LanguageModelToolCallPart: extHostTypes.LanguageModelToolCallPart,
18771880
LanguageModelError: extHostTypes.LanguageModelError,
18781881
LanguageModelToolResult: extHostTypes.LanguageModelToolResult,
18791882
LanguageModelToolResult2: extHostTypes.LanguageModelToolResult2,
18801883
LanguageModelDataPart: extHostTypes.LanguageModelDataPart,
1884+
LanguageModelDataPart2: extHostTypes.LanguageModelDataPart,
18811885
LanguageModelToolExtensionSource: extHostTypes.LanguageModelToolExtensionSource,
18821886
LanguageModelToolMCPSource: extHostTypes.LanguageModelToolMCPSource,
18831887
ExtendedLanguageModelToolResult: extHostTypes.ExtendedLanguageModelToolResult,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export class ChatAgentResponseStream {
291291
part instanceof extHostTypes.ChatResponseCodeCitationPart ||
292292
part instanceof extHostTypes.ChatResponseMovePart ||
293293
part instanceof extHostTypes.ChatResponseExtensionsPart ||
294+
part instanceof extHostTypes.ChatResponsePullRequestPart ||
294295
part instanceof extHostTypes.ChatResponseProgressPart2
295296
) {
296297
checkProposedApiEnabled(that._extension, 'chatParticipantAdditions');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class LanguageModelResponse {
9999

100100
let out: vscode.LanguageModelTextPart | vscode.LanguageModelToolCallPart;
101101
if (fragment.part.type === 'text') {
102-
out = new extHostTypes.LanguageModelTextPart(fragment.part.value);
102+
out = new extHostTypes.LanguageModelTextPart(fragment.part.value, fragment.part.audience);
103103
} else if (fragment.part.type === 'data') {
104104
out = new extHostTypes.LanguageModelTextPart('');
105105
} else {
@@ -296,9 +296,9 @@ export class ExtHostLanguageModels implements ExtHostLanguageModelsShape {
296296
if (fragment.part instanceof extHostTypes.LanguageModelToolCallPart) {
297297
part = { type: 'tool_use', name: fragment.part.name, parameters: fragment.part.input, toolCallId: fragment.part.callId };
298298
} else if (fragment.part instanceof extHostTypes.LanguageModelTextPart) {
299-
part = { type: 'text', value: fragment.part.value };
299+
part = { type: 'text', value: fragment.part.value, audience: fragment.part.audience };
300300
} else if (fragment.part instanceof extHostTypes.LanguageModelDataPart) {
301-
part = { type: 'data', value: { mimeType: fragment.part.mimeType as ChatImageMimeType, data: VSBuffer.wrap(fragment.part.data) } };
301+
part = { type: 'data', value: { mimeType: fragment.part.mimeType as ChatImageMimeType, data: VSBuffer.wrap(fragment.part.data) }, audience: fragment.part.audience };
302302
}
303303

304304
if (!part) {

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

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import { IViewBadge } from '../../common/views.js';
4141
import { IChatAgentRequest, IChatAgentResult } from '../../contrib/chat/common/chatAgents.js';
4242
import { IChatRequestDraft } from '../../contrib/chat/common/chatEditingService.js';
4343
import { IChatRequestVariableEntry, isImageVariableEntry } from '../../contrib/chat/common/chatVariableEntries.js';
44-
import { IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatMoveMessage, IChatPrepareToolInvocationPart, IChatProgressMessage, IChatResponseCodeblockUriPart, IChatTaskDto, IChatTaskResult, IChatTextEdit, IChatTreeData, IChatUserActionEvent, IChatWarningMessage } from '../../contrib/chat/common/chatService.js';
44+
import { IChatAgentMarkdownContentWithVulnerability, IChatCodeCitation, IChatCommandButton, IChatConfirmation, IChatContentInlineReference, IChatContentReference, IChatExtensionsContent, IChatFollowup, IChatMarkdownContent, IChatMoveMessage, IChatPrepareToolInvocationPart, IChatProgressMessage, IChatPullRequestContent, IChatResponseCodeblockUriPart, IChatTaskDto, IChatTaskResult, IChatTextEdit, IChatTreeData, IChatUserActionEvent, IChatWarningMessage } from '../../contrib/chat/common/chatService.js';
4545
import { IToolResult, IToolResultInputOutputDetails, IToolResultOutputDetails, ToolDataSource } from '../../contrib/chat/common/languageModelToolsService.js';
4646
import * as chatProvider from '../../contrib/chat/common/languageModels.js';
4747
import { IChatMessageDataPart, IChatResponseDataPart, IChatResponsePromptTsxPart, IChatResponseTextPart } from '../../contrib/chat/common/languageModels.js';
@@ -2316,11 +2316,11 @@ export namespace LanguageModelChatMessage {
23162316
export function to(message: chatProvider.IChatMessage): vscode.LanguageModelChatMessage {
23172317
const content = message.content.map(c => {
23182318
if (c.type === 'text') {
2319-
return new LanguageModelTextPart(c.value);
2319+
return new LanguageModelTextPart(c.value, c.audience);
23202320
} else if (c.type === 'tool_result') {
23212321
const content: (LanguageModelTextPart | LanguageModelPromptTsxPart)[] = c.value.map(part => {
23222322
if (part.type === 'text') {
2323-
return new types.LanguageModelTextPart(part.value);
2323+
return new types.LanguageModelTextPart(part.value, part.audience);
23242324
} else {
23252325
return new types.LanguageModelPromptTsxPart(part.value);
23262326
}
@@ -2360,7 +2360,8 @@ export namespace LanguageModelChatMessage {
23602360
if (part instanceof types.LanguageModelTextPart) {
23612361
return {
23622362
type: 'text',
2363-
value: part.value
2363+
value: part.value,
2364+
audience: part.audience,
23642365
} satisfies IChatResponseTextPart;
23652366
} else if (part instanceof types.LanguageModelPromptTsxPart) {
23662367
return {
@@ -2411,11 +2412,11 @@ export namespace LanguageModelChatMessage2 {
24112412
export function to(message: chatProvider.IChatMessage): vscode.LanguageModelChatMessage2 {
24122413
const content = message.content.map(c => {
24132414
if (c.type === 'text') {
2414-
return new LanguageModelTextPart(c.value);
2415+
return new LanguageModelTextPart(c.value, c.audience);
24152416
} else if (c.type === 'tool_result') {
24162417
const content: (LanguageModelTextPart | LanguageModelPromptTsxPart | LanguageModelDataPart)[] = c.value.map(part => {
24172418
if (part.type === 'text') {
2418-
return new types.LanguageModelTextPart(part.value);
2419+
return new types.LanguageModelTextPart(part.value, part.audience);
24192420
} else if (part.type === 'data') {
24202421
return new types.LanguageModelDataPart(part.value.data.buffer, part.value.mimeType);
24212422
} else {
@@ -2455,7 +2456,8 @@ export namespace LanguageModelChatMessage2 {
24552456
if (part instanceof types.LanguageModelTextPart) {
24562457
return {
24572458
type: 'text',
2458-
value: part.value
2459+
value: part.value,
2460+
audience: part.audience,
24592461
} satisfies IChatResponseTextPart;
24602462
} else if (part instanceof types.LanguageModelPromptTsxPart) {
24612463
return {
@@ -2468,7 +2470,8 @@ export namespace LanguageModelChatMessage2 {
24682470
value: {
24692471
mimeType: part.mimeType as chatProvider.ChatImageMimeType,
24702472
data: VSBuffer.wrap(part.data)
2471-
}
2473+
},
2474+
audience: part.audience
24722475
} satisfies IChatResponseDataPart;
24732476
} else {
24742477
// Strip unknown parts
@@ -2493,6 +2496,7 @@ export namespace LanguageModelChatMessage2 {
24932496
type: 'data',
24942497
mimeType: c.mimeType,
24952498
data: VSBuffer.wrap(c.data),
2499+
audience: c.audience
24962500
} satisfies IChatMessageDataPart;
24972501
}
24982502
} else if (c instanceof types.LanguageModelToolCallPart) {
@@ -2692,6 +2696,19 @@ export namespace ChatResponseExtensionsPart {
26922696
}
26932697
}
26942698

2699+
export namespace ChatResponsePullRequestPart {
2700+
export function from(part: vscode.ChatResponsePullRequestPart): Dto<IChatPullRequestContent> {
2701+
return {
2702+
kind: 'pullRequest',
2703+
author: part.author,
2704+
title: part.title,
2705+
description: part.description,
2706+
uri: part.uri,
2707+
linkTag: part.linkTag
2708+
};
2709+
}
2710+
}
2711+
26952712
export namespace ChatResponseMovePart {
26962713
export function from(part: vscode.ChatResponseMovePart): Dto<IChatMoveMessage> {
26972714
return {
@@ -2982,6 +2999,8 @@ export namespace ChatResponsePart {
29822999
return ChatResponseExtensionsPart.from(part);
29833000
} else if (part instanceof types.ChatPrepareToolInvocationPart) {
29843001
return ChatPrepareToolInvocationPart.from(part);
3002+
} else if (part instanceof types.ChatResponsePullRequestPart) {
3003+
return ChatResponsePullRequestPart.from(part);
29853004
} else if (part instanceof types.ChatToolInvocationPart) {
29863005
return ChatToolInvocationPart.from(part);
29873006
}
@@ -3215,7 +3234,7 @@ export namespace ChatAgentResult {
32153234
if (value.$mid === MarshalledId.LanguageModelToolResult) {
32163235
return new types.LanguageModelToolResult(cloneAndChange(value.content, reviveMetadata));
32173236
} else if (value.$mid === MarshalledId.LanguageModelTextPart) {
3218-
return new types.LanguageModelTextPart(value.value);
3237+
return new types.LanguageModelTextPart(value.value, value.audience);
32193238
} else if (value.$mid === MarshalledId.LanguageModelPromptTsxPart) {
32203239
return new types.LanguageModelPromptTsxPart(value.value);
32213240
}
@@ -3399,7 +3418,7 @@ export namespace LanguageModelToolResult {
33993418
export function to(result: IToolResult): vscode.LanguageModelToolResult {
34003419
return new types.LanguageModelToolResult(result.content.map(item => {
34013420
if (item.kind === 'text') {
3402-
return new types.LanguageModelTextPart(item.value);
3421+
return new types.LanguageModelTextPart(item.value, item.audience);
34033422
} else {
34043423
return new types.LanguageModelPromptTsxPart(item.value);
34053424
}
@@ -3411,12 +3430,20 @@ export namespace LanguageModelToolResult {
34113430
checkProposedApiEnabled(extension, 'chatParticipantPrivate');
34123431
}
34133432

3433+
const checkAudienceApi = (item: LanguageModelTextPart) => {
3434+
if (item.audience) {
3435+
checkProposedApiEnabled(extension, 'languageModelToolResultAudience');
3436+
}
3437+
};
3438+
34143439
return {
34153440
content: result.content.map(item => {
34163441
if (item instanceof types.LanguageModelTextPart) {
3442+
checkAudienceApi(item);
34173443
return {
34183444
kind: 'text',
3419-
value: item.value
3445+
value: item.value,
3446+
audience: item.audience
34203447
};
34213448
} else if (item instanceof types.LanguageModelPromptTsxPart) {
34223449
return {
@@ -3437,13 +3464,9 @@ export namespace LanguageModelToolResult2 {
34373464
export function to(result: IToolResult): vscode.LanguageModelToolResult2 {
34383465
return new types.LanguageModelToolResult2(result.content.map(item => {
34393466
if (item.kind === 'text') {
3440-
return new types.LanguageModelTextPart(item.value);
3467+
return new types.LanguageModelTextPart(item.value, item.audience);
34413468
} else if (item.kind === 'data') {
3442-
const mimeType = Object.values(types.ChatImageMimeType).includes(item.value.mimeType as types.ChatImageMimeType) ? item.value.mimeType as types.ChatImageMimeType : undefined;
3443-
if (!mimeType) {
3444-
throw new Error('Invalid MIME type');
3445-
}
3446-
return new types.LanguageModelDataPart(item.value.data.buffer, mimeType);
3469+
return new types.LanguageModelDataPart(item.value.data.buffer, item.value.mimeType, item.audience);
34473470
} else {
34483471
return new types.LanguageModelPromptTsxPart(item.value);
34493472
}
@@ -3455,6 +3478,12 @@ export namespace LanguageModelToolResult2 {
34553478
checkProposedApiEnabled(extension, 'chatParticipantPrivate');
34563479
}
34573480

3481+
const checkAudienceApi = (item: LanguageModelTextPart | LanguageModelDataPart) => {
3482+
if (item.audience) {
3483+
checkProposedApiEnabled(extension, 'languageModelToolResultAudience');
3484+
}
3485+
};
3486+
34583487
let hasBuffers = false;
34593488
let detailsDto: Dto<Array<URI | types.Location> | IToolResultInputOutputDetails | IToolResultOutputDetails | undefined> = undefined;
34603489
if (Array.isArray(result.toolResultDetails)) {
@@ -3477,23 +3506,27 @@ export namespace LanguageModelToolResult2 {
34773506
const dto: Dto<IToolResult> = {
34783507
content: result.content.map(item => {
34793508
if (item instanceof types.LanguageModelTextPart) {
3509+
checkAudienceApi(item);
34803510
return {
34813511
kind: 'text',
3482-
value: item.value
3512+
value: item.value,
3513+
audience: item.audience
34833514
};
34843515
} else if (item instanceof types.LanguageModelPromptTsxPart) {
34853516
return {
34863517
kind: 'promptTsx',
34873518
value: item.value,
34883519
};
34893520
} else if (item instanceof types.LanguageModelDataPart) {
3521+
checkAudienceApi(item);
34903522
hasBuffers = true;
34913523
return {
34923524
kind: 'data',
34933525
value: {
34943526
mimeType: item.mimeType,
34953527
data: VSBuffer.wrap(item.data)
3496-
}
3528+
},
3529+
audience: item.audience
34973530
};
34983531
} else {
34993532
throw new Error('Unknown LanguageModelToolResult part type');

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,6 +4703,27 @@ export class ChatResponseExtensionsPart {
47034703
}
47044704
}
47054705

4706+
export class ChatResponsePullRequestPart {
4707+
constructor(
4708+
public readonly uri: vscode.Uri,
4709+
public readonly title: string,
4710+
public readonly description: string,
4711+
public readonly author: string,
4712+
public readonly linkTag: string
4713+
) {
4714+
}
4715+
4716+
toJSON() {
4717+
return {
4718+
$mid: MarshalledId.ChatResponsePullRequestPart,
4719+
uri: this.uri,
4720+
title: this.title,
4721+
description: this.description,
4722+
author: this.author
4723+
};
4724+
}
4725+
}
4726+
47064727
export class ChatResponseTextEditPart implements vscode.ChatResponseTextEditPart {
47074728
uri: vscode.Uri;
47084729
edits: vscode.TextEdit[];
@@ -4994,28 +5015,38 @@ export class LanguageModelToolCallPart implements vscode.LanguageModelToolCallPa
49945015
}
49955016
}
49965017

4997-
export class LanguageModelTextPart implements vscode.LanguageModelTextPart {
5018+
export enum ToolResultAudience {
5019+
Assistant = 0,
5020+
User = 1,
5021+
}
5022+
5023+
export class LanguageModelTextPart implements vscode.LanguageModelTextPart2 {
49985024
value: string;
5025+
audience: vscode.ToolResultAudience[] | undefined;
49995026

5000-
constructor(value: string) {
5027+
constructor(value: string, audience?: vscode.ToolResultAudience[]) {
50015028
this.value = value;
5029+
audience = audience;
50025030
}
50035031

50045032
toJSON() {
50055033
return {
50065034
$mid: MarshalledId.LanguageModelTextPart,
50075035
value: this.value,
5036+
audience: this.audience,
50085037
};
50095038
}
50105039
}
50115040

5012-
export class LanguageModelDataPart implements vscode.LanguageModelDataPart {
5041+
export class LanguageModelDataPart implements vscode.LanguageModelDataPart2 {
50135042
mimeType: string;
50145043
data: Uint8Array<ArrayBufferLike>;
5044+
audience: vscode.ToolResultAudience[] | undefined;
50155045

5016-
constructor(data: Uint8Array<ArrayBufferLike>, mimeType: string) {
5046+
constructor(data: Uint8Array<ArrayBufferLike>, mimeType: string, audience?: vscode.ToolResultAudience[]) {
50175047
this.mimeType = mimeType;
50185048
this.data = data;
5049+
this.audience = audience;
50195050
}
50205051

50215052
static image(data: Uint8Array<ArrayBufferLike>, mimeType: ChatImageMimeType): vscode.LanguageModelDataPart {
@@ -5036,6 +5067,7 @@ export class LanguageModelDataPart implements vscode.LanguageModelDataPart {
50365067
$mid: MarshalledId.LanguageModelDataPart,
50375068
mimeType: this.mimeType,
50385069
data: this.data,
5070+
audience: this.audience
50395071
};
50405072
}
50415073
}

0 commit comments

Comments
 (0)