Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/browser/actions/chatDeveloperActions.ts
5245 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Codicon } from '../../../../../base/common/codicons.js';
7
import { isUriComponents, URI } from '../../../../../base/common/uri.js';
8
import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions.js';
9
import { localize2 } from '../../../../../nls.js';
10
import { Categories } from '../../../../../platform/action/common/actionCommonCategories.js';
11
import { Action2, registerAction2 } from '../../../../../platform/actions/common/actions.js';
12
import { IEditorService } from '../../../../services/editor/common/editorService.js';
13
import { ChatContextKeys } from '../../common/actions/chatContextKeys.js';
14
import { IChatService } from '../../common/chatService/chatService.js';
15
import { IChatWidgetService } from '../chat.js';
16
17
function uriReplacer(_key: string, value: unknown): unknown {
18
if (URI.isUri(value)) {
19
return value.toString();
20
}
21
22
if (isUriComponents(value)) {
23
// This shouldn't be necessary but it seems that some URIs in ChatModels aren't properly revived
24
return URI.from(value).toString();
25
}
26
27
return value;
28
}
29
30
export function registerChatDeveloperActions() {
31
registerAction2(LogChatInputHistoryAction);
32
registerAction2(LogChatIndexAction);
33
registerAction2(InspectChatModelAction);
34
}
35
36
class LogChatInputHistoryAction extends Action2 {
37
static readonly ID = 'workbench.action.chat.logInputHistory';
38
39
constructor() {
40
super({
41
id: LogChatInputHistoryAction.ID,
42
title: localize2('workbench.action.chat.logInputHistory.label', "Log Chat Input History"),
43
icon: Codicon.attach,
44
category: Categories.Developer,
45
f1: true,
46
precondition: ChatContextKeys.enabled
47
});
48
}
49
50
override async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
51
const chatWidgetService = accessor.get(IChatWidgetService);
52
chatWidgetService.lastFocusedWidget?.logInputHistory();
53
}
54
}
55
56
class LogChatIndexAction extends Action2 {
57
static readonly ID = 'workbench.action.chat.logChatIndex';
58
59
constructor() {
60
super({
61
id: LogChatIndexAction.ID,
62
title: localize2('workbench.action.chat.logChatIndex.label', "Log Chat Index"),
63
icon: Codicon.attach,
64
category: Categories.Developer,
65
f1: true,
66
precondition: ChatContextKeys.enabled
67
});
68
}
69
70
override async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
71
const chatService = accessor.get(IChatService);
72
chatService.logChatIndex();
73
}
74
}
75
76
class InspectChatModelAction extends Action2 {
77
static readonly ID = 'workbench.action.chat.inspectChatModel';
78
79
constructor() {
80
super({
81
id: InspectChatModelAction.ID,
82
title: localize2('workbench.action.chat.inspectChatModel.label', "Inspect Chat Model"),
83
icon: Codicon.inspect,
84
category: Categories.Developer,
85
f1: true,
86
precondition: ChatContextKeys.enabled
87
});
88
}
89
90
override async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
91
const chatWidgetService = accessor.get(IChatWidgetService);
92
const editorService = accessor.get(IEditorService);
93
const widget = chatWidgetService.lastFocusedWidget;
94
95
if (!widget?.viewModel) {
96
return;
97
}
98
99
const model = widget.viewModel.model;
100
const modelData = model.toJSON();
101
102
// Build markdown output with latest response at the top
103
let output = '# Chat Model Inspection\n\n';
104
105
// Show latest response first if it exists
106
const requests = modelData.requests;
107
if (requests && requests.length > 0) {
108
const latestRequest = requests[requests.length - 1];
109
if (latestRequest.response) {
110
output += '## Latest Response\n\n';
111
output += '```json\n' + JSON.stringify(latestRequest.response, uriReplacer, 2) + '\n```\n\n';
112
}
113
}
114
115
// Show full model data
116
output += '## Full Chat Model\n\n';
117
output += '```json\n' + JSON.stringify(modelData, uriReplacer, 2) + '\n```\n';
118
119
await editorService.openEditor({
120
resource: undefined,
121
contents: output,
122
languageId: 'markdown',
123
options: {
124
pinned: true
125
}
126
});
127
}
128
}
129
130