Skip to content

Commit 97f8af3

Browse files
authored
Merge pull request #182576 from microsoft/roblou/smart-ostrich
Chat import/export fixes
2 parents 09023d8 + f2d7e80 commit 97f8af3

10 files changed

+73
-54
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { IChatDetail, IChatService } from 'vs/workbench/contrib/chat/common/chat
2929
import { IChatWidgetHistoryService } from 'vs/workbench/contrib/chat/common/chatWidgetHistoryService';
3030
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3131

32-
export const INTERACTIVE_SESSION_CATEGORY = { value: localize('chat.category', "Chat"), original: 'Chat' };
32+
export const CHAT_CATEGORY = { value: localize('chat.category', "Chat"), original: 'Chat' };
3333

3434
export function registerChatActions() {
3535
registerEditorAction(class ChatAcceptInput extends EditorAction {
@@ -94,7 +94,7 @@ export function registerChatActions() {
9494
value: localize('interactiveSession.clearHistory.label', "Clear Input History"),
9595
original: 'Clear Input History'
9696
},
97-
category: INTERACTIVE_SESSION_CATEGORY,
97+
category: CHAT_CATEGORY,
9898
f1: true,
9999
});
100100
}
@@ -210,7 +210,7 @@ export function registerChatActions() {
210210
value: localize('interactiveSession.clear.label', "Clear"),
211211
original: 'Clear'
212212
},
213-
category: INTERACTIVE_SESSION_CATEGORY,
213+
category: CHAT_CATEGORY,
214214
icon: Codicon.clearAll,
215215
f1: true,
216216
keybinding: {
@@ -245,7 +245,7 @@ export function getOpenChatEditorAction(id: string, label: string, when?: string
245245
id: `workbench.action.openChat.${id}`,
246246
title: { value: localize('interactiveSession.open', "Open Editor ({0})", label), original: `Open Editor (${label})` },
247247
f1: true,
248-
category: INTERACTIVE_SESSION_CATEGORY,
248+
category: CHAT_CATEGORY,
249249
precondition: ContextKeyExpr.deserialize(when)
250250
});
251251
}
@@ -270,7 +270,7 @@ const getClearChatActionDescriptorForViewTitle = (viewId: string, providerId: st
270270
group: 'navigation',
271271
order: 0
272272
},
273-
category: INTERACTIVE_SESSION_CATEGORY,
273+
category: CHAT_CATEGORY,
274274
icon: Codicon.clearAll,
275275
f1: false
276276
});
@@ -300,7 +300,7 @@ const getHistoryChatActionDescriptorForViewTitle = (viewId: string, providerId:
300300
group: 'navigation',
301301
order: 0
302302
},
303-
category: INTERACTIVE_SESSION_CATEGORY,
303+
category: CHAT_CATEGORY,
304304
icon: Codicon.history,
305305
f1: false
306306
});

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService
1919
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
2020
import { TerminalLocation } from 'vs/platform/terminal/common/terminal';
2121
import { IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor';
22-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
22+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
2323
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
2424
import { CONTEXT_IN_INTERACTIVE_SESSION } from 'vs/workbench/contrib/chat/common/chatContextKeys';
2525
import { IChatCopyAction, IChatService, IChatUserActionEvent, InteractiveSessionCopyKind } from 'vs/workbench/contrib/chat/common/chatService';
@@ -52,7 +52,7 @@ export function registerChatCodeBlockActions() {
5252
original: 'Copy'
5353
},
5454
f1: false,
55-
category: INTERACTIVE_SESSION_CATEGORY,
55+
category: CHAT_CATEGORY,
5656
icon: Codicon.copy,
5757
menu: {
5858
id: MenuId.ChatCodeBlock,
@@ -144,7 +144,7 @@ export function registerChatCodeBlockActions() {
144144
original: 'Insert at Cursor'
145145
},
146146
f1: true,
147-
category: INTERACTIVE_SESSION_CATEGORY,
147+
category: CHAT_CATEGORY,
148148
icon: Codicon.insert,
149149
menu: {
150150
id: MenuId.ChatCodeBlock,
@@ -252,7 +252,7 @@ export function registerChatCodeBlockActions() {
252252
original: 'Insert Into New File'
253253
},
254254
f1: true,
255-
category: INTERACTIVE_SESSION_CATEGORY,
255+
category: CHAT_CATEGORY,
256256
icon: Codicon.newFile,
257257
menu: {
258258
id: MenuId.ChatCodeBlock,
@@ -297,7 +297,7 @@ export function registerChatCodeBlockActions() {
297297
original: 'Run in Terminal'
298298
},
299299
f1: true,
300-
category: INTERACTIVE_SESSION_CATEGORY,
300+
category: CHAT_CATEGORY,
301301
icon: Codicon.terminal,
302302
menu: {
303303
id: MenuId.ChatCodeBlock,
@@ -400,7 +400,7 @@ export function registerChatCodeBlockActions() {
400400
when: CONTEXT_IN_INTERACTIVE_SESSION,
401401
},
402402
f1: true,
403-
category: INTERACTIVE_SESSION_CATEGORY,
403+
category: CHAT_CATEGORY,
404404
});
405405
}
406406

@@ -423,7 +423,7 @@ export function registerChatCodeBlockActions() {
423423
when: CONTEXT_IN_INTERACTIVE_SESSION,
424424
},
425425
f1: true,
426-
category: INTERACTIVE_SESSION_CATEGORY,
426+
category: CHAT_CATEGORY,
427427
});
428428
}
429429

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
77
import { localize } from 'vs/nls';
88
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
99
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
10-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
10+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
1111
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
1212
import { IInteractiveRequestViewModel, IInteractiveResponseViewModel, isRequestVM, isResponseVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
1313

@@ -21,7 +21,7 @@ export function registerChatCopyActions() {
2121
original: 'Copy All'
2222
},
2323
f1: false,
24-
category: INTERACTIVE_SESSION_CATEGORY,
24+
category: CHAT_CATEGORY,
2525
menu: {
2626
id: MenuId.ChatContext
2727
}
@@ -54,7 +54,7 @@ export function registerChatCopyActions() {
5454
original: 'Copy'
5555
},
5656
f1: false,
57-
category: INTERACTIVE_SESSION_CATEGORY,
57+
category: CHAT_CATEGORY,
5858
menu: {
5959
id: MenuId.ChatContext
6060
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Codicon } from 'vs/base/common/codicons';
77
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
88
import { localize } from 'vs/nls';
99
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
10-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
10+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
1111
import { IChatWidget } from 'vs/workbench/contrib/chat/browser/chat';
1212
import { CONTEXT_INTERACTIVE_INPUT_HAS_TEXT, CONTEXT_INTERACTIVE_REQUEST_IN_PROGRESS } from 'vs/workbench/contrib/chat/common/chatContextKeys';
1313
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
@@ -30,7 +30,7 @@ export function registerChatExecuteActions() {
3030
original: 'Submit'
3131
},
3232
f1: false,
33-
category: INTERACTIVE_SESSION_CATEGORY,
33+
category: CHAT_CATEGORY,
3434
icon: Codicon.send,
3535
precondition: CONTEXT_INTERACTIVE_INPUT_HAS_TEXT,
3636
menu: {
@@ -60,7 +60,7 @@ export function registerChatExecuteActions() {
6060
original: 'Cancel'
6161
},
6262
f1: false,
63-
category: INTERACTIVE_SESSION_CATEGORY,
63+
category: CHAT_CATEGORY,
6464
icon: Codicon.debugStop,
6565
menu: {
6666
id: MenuId.ChatExecute,

src/vs/workbench/contrib/chat/browser/actions/interactiveSessionImportExport.ts renamed to src/vs/workbench/contrib/chat/browser/actions/chatImportExport.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import { localize } from 'vs/nls';
1010
import { Action2, registerAction2 } from 'vs/platform/actions/common/actions';
1111
import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
1212
import { IFileService } from 'vs/platform/files/common/files';
13-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
13+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
1414
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
1515
import { IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
1616
import { ChatEditorInput } from 'vs/workbench/contrib/chat/browser/chatEditorInput';
17-
import { isSerializableSessionData } from 'vs/workbench/contrib/chat/common/chatModel';
17+
import { isExportableSessionData } from 'vs/workbench/contrib/chat/common/chatModel';
1818
import { IChatService } from 'vs/workbench/contrib/chat/common/chatService';
1919
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2020

2121
const defaultFileName = 'chat.json';
22-
const filters = [{ name: localize('interactiveSession.file.label', "Chat Session"), extensions: ['json'] }];
22+
const filters = [{ name: localize('chat.file.label', "Chat Session"), extensions: ['json'] }];
2323

24-
export function registerInteractiveSessionExportActions() {
25-
registerAction2(class ExportInteractiveSessionAction extends Action2 {
24+
export function registerChatExportActions() {
25+
registerAction2(class ExportChatAction extends Action2 {
2626
constructor() {
2727
super({
28-
id: 'workbench.action.interactiveSession.export',
29-
category: INTERACTIVE_SESSION_CATEGORY,
28+
id: 'workbench.action.chat.export',
29+
category: CHAT_CATEGORY,
3030
title: {
31-
value: localize('interactiveSession.export.label', "Export Session") + '...',
31+
value: localize('chat.export.label', "Export Session") + '...',
3232
original: 'Export Session...'
3333
},
3434
f1: true,
@@ -38,7 +38,7 @@ export function registerInteractiveSessionExportActions() {
3838
const widgetService = accessor.get(IChatWidgetService);
3939
const fileDialogService = accessor.get(IFileDialogService);
4040
const fileService = accessor.get(IFileService);
41-
const interactiveSessionService = accessor.get(IChatService);
41+
const chatService = accessor.get(IChatService);
4242

4343
const widget = widgetService.lastFocusedWidget;
4444
if (!widget || !widget.viewModel) {
@@ -54,26 +54,26 @@ export function registerInteractiveSessionExportActions() {
5454
return;
5555
}
5656

57-
const model = interactiveSessionService.getSession(widget.viewModel.sessionId);
57+
const model = chatService.getSession(widget.viewModel.sessionId);
5858
if (!model) {
5959
return;
6060
}
6161

6262
// Using toJSON on the model
63-
const content = VSBuffer.fromString(JSON.stringify(model, undefined, 2));
63+
const content = VSBuffer.fromString(JSON.stringify(model.toExport(), undefined, 2));
6464
await fileService.writeFile(result, content);
6565
}
6666
});
6767

68-
registerAction2(class ImportInteractiveSessionAction extends Action2 {
68+
registerAction2(class ImportChatAction extends Action2 {
6969
constructor() {
7070
super({
71-
id: 'workbench.action.interactiveSession.import',
71+
id: 'workbench.action.chat.import',
7272
title: {
73-
value: localize('interactiveSession.import.label', "Import Session") + '...',
73+
value: localize('chat.import.label', "Import Session") + '...',
7474
original: 'Export Session...'
7575
},
76-
category: INTERACTIVE_SESSION_CATEGORY,
76+
category: CHAT_CATEGORY,
7777
f1: true,
7878
});
7979
}
@@ -95,7 +95,7 @@ export function registerInteractiveSessionExportActions() {
9595
const content = await fileService.readFile(result[0]);
9696
try {
9797
const data = JSON.parse(content.value.toString());
98-
if (!isSerializableSessionData(data)) {
98+
if (!isExportableSessionData(data)) {
9999
throw new Error('Invalid chat session data');
100100
}
101101

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { ChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatOptions
2222
import { ChatModel } from 'vs/workbench/contrib/chat/common/chatModel';
2323
import { IChatReplyFollowup, IChatService } from 'vs/workbench/contrib/chat/common/chatService';
2424
import { ChatViewModel } from 'vs/workbench/contrib/chat/common/chatViewModel';
25-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
25+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
2626
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
2727
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
2828

@@ -42,7 +42,7 @@ class AskQuickQuestionAction extends Action2 {
4242
id: 'chat.action.askQuickQuestion',
4343
title: { value: localize('askQuickQuestion', "Ask Quick Question"), original: 'Ask Quick Question' },
4444
f1: true,
45-
category: INTERACTIVE_SESSION_CATEGORY,
45+
category: CHAT_CATEGORY,
4646
keybinding: {
4747
weight: KeybindingWeight.WorkbenchContrib,
4848
primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KeyI,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
1010
import { localize } from 'vs/nls';
1111
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions';
1212
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
13-
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
13+
import { CHAT_CATEGORY } from 'vs/workbench/contrib/chat/browser/actions/chatActions';
1414
import { CONTEXT_RESPONSE_VOTE } from 'vs/workbench/contrib/chat/common/chatContextKeys';
1515
import { IChatService, IChatUserActionEvent, InteractiveSessionVoteDirection } from 'vs/workbench/contrib/chat/common/chatService';
1616
import { isResponseVM } from 'vs/workbench/contrib/chat/common/chatViewModel';
@@ -29,7 +29,7 @@ export function registerChatTitleActions() {
2929
original: 'Vote Up'
3030
},
3131
f1: false,
32-
category: INTERACTIVE_SESSION_CATEGORY,
32+
category: CHAT_CATEGORY,
3333
icon: Codicon.thumbsup,
3434
toggled: CONTEXT_RESPONSE_VOTE.isEqualTo('up'),
3535
menu: {
@@ -68,7 +68,7 @@ export function registerChatTitleActions() {
6868
original: 'Vote Down'
6969
},
7070
f1: false,
71-
category: INTERACTIVE_SESSION_CATEGORY,
71+
category: CHAT_CATEGORY,
7272
icon: Codicon.thumbsdown,
7373
toggled: CONTEXT_RESPONSE_VOTE.isEqualTo('down'),
7474
menu: {
@@ -107,7 +107,7 @@ export function registerChatTitleActions() {
107107
original: 'Insert into Notebook'
108108
},
109109
f1: false,
110-
category: INTERACTIVE_SESSION_CATEGORY,
110+
category: CHAT_CATEGORY,
111111
icon: Codicon.insert,
112112
menu: {
113113
id: MenuId.ChatTitle,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { registerChatCopyActions } from 'vs/workbench/contrib/chat/browser/actio
2121
import { registerChatExecuteActions } from 'vs/workbench/contrib/chat/browser/actions/chatExecuteActions';
2222
import { registerChatQuickQuestionActions } from 'vs/workbench/contrib/chat/browser/actions/chatQuickInputActions';
2323
import { registerChatTitleActions } from 'vs/workbench/contrib/chat/browser/actions/chatTitleActions';
24-
import { registerInteractiveSessionExportActions } from 'vs/workbench/contrib/chat/browser/actions/interactiveSessionImportExport';
24+
import { registerChatExportActions } from 'vs/workbench/contrib/chat/browser/actions/chatImportExport';
2525
import { IChatWidgetService } from 'vs/workbench/contrib/chat/browser/chat';
2626
import { ChatContributionService } from 'vs/workbench/contrib/chat/browser/chatContributionServiceImpl';
2727
import { ChatEditor, IChatEditorOptions } from 'vs/workbench/contrib/chat/browser/chatEditor';
@@ -127,7 +127,7 @@ registerChatCodeBlockActions();
127127
registerChatTitleActions();
128128
registerChatExecuteActions();
129129
registerChatQuickQuestionActions();
130-
registerInteractiveSessionExportActions();
130+
registerChatExportActions();
131131

132132
registerSingleton(IChatService, ChatService, InstantiationType.Delayed);
133133
registerSingleton(IChatContributionService, ChatContributionService, InstantiationType.Delayed);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export namespace ChatUri {
155155

156156
interface ISerializedChatEditorInput {
157157
options: IChatEditorOptions;
158+
sessionId: string;
158159
resource: URI;
159160
}
160161

@@ -174,6 +175,7 @@ export class ChatEditorInputSerializer implements IEditorSerializer {
174175

175176
const obj: ISerializedChatEditorInput = {
176177
options: input.options,
178+
sessionId: input.sessionId,
177179
resource: input.resource
178180
};
179181
return JSON.stringify(obj);
@@ -183,7 +185,7 @@ export class ChatEditorInputSerializer implements IEditorSerializer {
183185
try {
184186
const parsed: ISerializedChatEditorInput = JSON.parse(serializedEditor);
185187
const resource = URI.revive(parsed.resource);
186-
return instantiationService.createInstance(ChatEditorInput, resource, parsed.options as IChatEditorOptions);
188+
return instantiationService.createInstance(ChatEditorInput, resource, { ...parsed.options, target: { sessionId: parsed.sessionId } });
187189
} catch (err) {
188190
return undefined;
189191
}

0 commit comments

Comments
 (0)