Skip to content

Commit ea00756

Browse files
committed
Fix broken chat layout after reloading window
Added a new property to the chat agent, but then it's missing from older rehydrated chat models.
1 parent 73f7941 commit ea00756

15 files changed

+43
-23
lines changed

src/vs/workbench/api/browser/mainThreadChatAgents2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
138138
description: dynamicProps.description,
139139
extensionId: extension,
140140
extensionDisplayName: extensionDescription?.displayName ?? extension.value,
141-
extensionPublisher: extensionDescription?.publisherDisplayName ?? extension.value,
141+
extensionPublisherId: extensionDescription?.publisher ?? '', // extensionDescription _should_ be present at this point, since this extension is active and registering agents
142+
extensionPublisherDisplayName: extensionDescription?.publisherDisplayName,
142143
metadata: revive(metadata),
143144
slashCommands: [],
144145
locations: [ChatAgentLocation.Panel] // TODO all dynamic participants are panel only?

src/vs/workbench/contrib/chat/browser/chatAgentHover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ChatAgentHover extends Disposable {
108108

109109
this.name.textContent = `@${agent.name}`;
110110
this.extensionName.textContent = agent.extensionDisplayName;
111-
this.publisherName.textContent = agent.extensionPublisher;
111+
this.publisherName.textContent = agent.extensionPublisherDisplayName ?? agent.extensionPublisherId;
112112

113113
const description = agent.description && !agent.description.endsWith('.') ?
114114
`${agent.description}. ` :

src/vs/workbench/contrib/chat/browser/chatMarkdownDecorationsRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ChatMarkdownDecorationsRenderer {
4242
let text = part.text;
4343
const isDupe = this.chatAgentService.getAgentsByName(part.agent.name).length > 1;
4444
if (isDupe) {
45-
text += ` (${part.agent.extensionPublisher})`;
45+
text += ` (${part.agent.extensionPublisherDisplayName})`;
4646
}
4747

4848
result += `[${text}](${agentRefUrl}?${encodeURIComponent(part.agent.id)})`;

src/vs/workbench/contrib/chat/browser/chatParticipantContributions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ export class ChatExtensionPointHandler implements IWorkbenchContribution {
202202
providerDescriptor.id,
203203
{
204204
extensionId: extension.description.identifier,
205-
extensionPublisher: extension.description.publisherDisplayName ?? extension.description.publisher, // May not be present in OSS
205+
extensionPublisherDisplayName: extension.description.publisherDisplayName ?? extension.description.publisher, // May not be present in OSS
206+
extensionPublisherId: extension.description.publisher,
206207
extensionDisplayName: extension.description.displayName ?? extension.description.name,
207208
id: providerDescriptor.id,
208209
description: providerDescriptor.description,

src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ class InputEditorDecorations extends Disposable {
213213
const textDecorations: IDecorationOptions[] | undefined = [];
214214
if (agentPart) {
215215
const isDupe = !!this.chatAgentService.getAgents().find(other => other.name === agentPart.agent.name && other.id !== agentPart.agent.id);
216-
const publisher = isDupe ? `(${agentPart.agent.extensionPublisher}) ` : '';
216+
const publisher = isDupe ? `(${agentPart.agent.extensionPublisherDisplayName}) ` : '';
217217
const agentHover = `${publisher}${agentPart.agent.description}`;
218218
textDecorations.push({ range: agentPart.editorRange, hoverMessage: new MarkdownString(agentHover) });
219219
if (agentSubcommandPart) {
@@ -361,7 +361,7 @@ class AgentCompletions extends Disposable {
361361
return <CompletionItem>{
362362
// Leading space is important because detail has no space at the start by design
363363
label: isDupe ?
364-
{ label: withAt, description: a.description, detail: ` (${a.extensionPublisher})` } :
364+
{ label: withAt, description: a.description, detail: ` (${a.extensionPublisherDisplayName})` } :
365365
withAt,
366366
insertText: `${withAt} `,
367367
detail: a.description,
@@ -452,7 +452,7 @@ class AgentCompletions extends Disposable {
452452

453453
return {
454454
label: isDupe ?
455-
{ label: agentLabel, description: agent.description, detail: ` (${agent.extensionPublisher})` } :
455+
{ label: agentLabel, description: agent.description, detail: ` (${agent.extensionPublisherDisplayName})` } :
456456
agentLabel,
457457
detail,
458458
filterText: `${chatSubcommandLeader}${agent.name}`,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export interface IChatAgentData {
5959
name: string;
6060
description?: string;
6161
extensionId: ExtensionIdentifier;
62-
extensionPublisher: string;
62+
extensionPublisherId: string;
63+
extensionPublisherDisplayName?: string;
6364
extensionDisplayName: string;
6465
/** The agent invoked when no agent is specified */
6566
isDefault?: boolean;
@@ -325,7 +326,8 @@ export class MergedChatAgent implements IChatAgent {
325326
get name(): string { return this.data.name ?? ''; }
326327
get description(): string { return this.data.description ?? ''; }
327328
get extensionId(): ExtensionIdentifier { return this.data.extensionId; }
328-
get extensionPublisher(): string { return this.data.extensionPublisher; }
329+
get extensionPublisherId(): string { return this.data.extensionPublisherId; }
330+
get extensionPublisherDisplayName() { return this.data.extensionPublisherDisplayName; }
329331
get extensionDisplayName(): string { return this.data.extensionDisplayName; }
330332
get isDefault(): boolean | undefined { return this.data.isDefault; }
331333
get metadata(): IChatAgentMetadata { return this.data.metadata; }
@@ -445,7 +447,7 @@ export class ChatAgentNameService implements IChatAgentNameService {
445447
return true;
446448
}
447449

448-
return allowList.some(id => equalsIgnoreCase(id, id.includes('.') ? chatAgentData.extensionId.value : chatAgentData.extensionPublisher));
450+
return allowList.some(id => equalsIgnoreCase(id, id.includes('.') ? chatAgentData.extensionId.value : chatAgentData.extensionPublisherId));
449451
});
450452
}
451453

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,16 @@ export class ChatModel extends Disposable implements IChatModel {
672672
...(raw as any),
673673
name: (raw as any).id,
674674
};
675+
676+
// Fill in required fields that may be missing from old data
677+
if (!('extensionPublisherId' in agent)) {
678+
agent.extensionPublisherId = agent.extensionPublisher ?? '';
679+
}
680+
681+
if (!('extensionDisplayName' in agent)) {
682+
agent.extensionDisplayName = '';
683+
}
684+
675685
return revive(agent);
676686
}
677687

@@ -847,7 +857,7 @@ export class ChatModel extends Disposable implements IChatModel {
847857
followups: r.response?.followups,
848858
isCanceled: r.response?.isCanceled,
849859
vote: r.response?.vote,
850-
agent: r.response?.agent,
860+
agent: r.response?.agent ? { ...r.response.agent } : undefined,
851861
slashCommand: r.response?.slashCommand,
852862
usedContext: r.response?.usedContext,
853863
contentReferences: r.response?.contentReferences

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatService_can_deserialize.0.snap

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
value: "nullExtensionDescription",
2929
_lower: "nullextensiondescription"
3030
},
31-
extensionPublisher: "",
31+
extensionPublisherDisplayName: "",
3232
extensionDisplayName: "",
3333
locations: [ "panel" ],
3434
metadata: { },
@@ -65,11 +65,12 @@
6565
value: "nullExtensionDescription",
6666
_lower: "nullextensiondescription"
6767
},
68-
extensionPublisher: "",
68+
extensionPublisherDisplayName: "",
6969
extensionDisplayName: "",
7070
locations: [ "panel" ],
7171
metadata: { },
72-
slashCommands: [ ]
72+
slashCommands: [ ],
73+
extensionPublisherId: ""
7374
},
7475
slashCommand: undefined,
7576
usedContext: {

src/vs/workbench/contrib/chat/test/common/__snapshots__/ChatService_can_serialize.1.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
value: "nullExtensionDescription",
2828
_lower: "nullextensiondescription"
2929
},
30-
extensionPublisher: "",
30+
extensionPublisherDisplayName: "",
3131
extensionDisplayName: "",
3232
locations: [ "panel" ],
3333
metadata: {
@@ -68,7 +68,7 @@
6868
value: "nullExtensionDescription",
6969
_lower: "nullextensiondescription"
7070
},
71-
extensionPublisher: "",
71+
extensionPublisherDisplayName: "",
7272
extensionDisplayName: "",
7373
locations: [ "panel" ],
7474
metadata: {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ suite('ChatRequestParser', () => {
115115
});
116116

117117
const getAgentWithSlashCommands = (slashCommands: IChatAgentCommand[]) => {
118-
return { id: 'agent', name: 'agent', extensionId: nullExtensionDescription.identifier, extensionPublisher: '', extensionDisplayName: '', locations: [ChatAgentLocation.Panel], metadata: {}, slashCommands } satisfies IChatAgentData;
118+
return { id: 'agent', name: 'agent', extensionId: nullExtensionDescription.identifier, extensionPublisherDisplayName: '', extensionDisplayName: '', extensionPublisherId: '', locations: [ChatAgentLocation.Panel], metadata: {}, slashCommands } satisfies IChatAgentData;
119119
};
120120

121121
test('agent with subcommand after text', async () => {

0 commit comments

Comments
 (0)