Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { ServicesAccessor } from '../../../../../editor/browser/editorExtensions
import { localize2 } from '../../../../../nls.js';
import { Categories } from '../../../../../platform/action/common/actionCommonCategories.js';
import { Action2, registerAction2 } from '../../../../../platform/actions/common/actions.js';
import { IEditorService } from '../../../../services/editor/common/editorService.js';
import { ChatContextKeys } from '../../common/actions/chatContextKeys.js';
import { IChatService } from '../../common/chatService/chatService.js';
import { IChatWidgetService } from '../chat.js';

export function registerChatDeveloperActions() {
registerAction2(LogChatInputHistoryAction);
registerAction2(LogChatIndexAction);
registerAction2(InspectChatModelAction);
}

class LogChatInputHistoryAction extends Action2 {
Expand Down Expand Up @@ -56,3 +58,57 @@ class LogChatIndexAction extends Action2 {
chatService.logChatIndex();
}
}

class InspectChatModelAction extends Action2 {
static readonly ID = 'workbench.action.chat.inspectChatModel';

constructor() {
super({
id: InspectChatModelAction.ID,
title: localize2('workbench.action.chat.inspectChatModel.label', "Inspect Chat Model"),
icon: Codicon.inspect,
category: Categories.Developer,
f1: true,
precondition: ChatContextKeys.enabled
});
}

override async run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void> {
const chatWidgetService = accessor.get(IChatWidgetService);
const editorService = accessor.get(IEditorService);
const widget = chatWidgetService.lastFocusedWidget;

if (!widget?.viewModel) {
return;
}

const model = widget.viewModel.model;
const modelData = model.toJSON();

// Build markdown output with latest response at the top
let output = '# Chat Model Inspection\n\n';

// Show latest response first if it exists
const requests = modelData.requests;
if (requests && requests.length > 0) {
const latestRequest = requests[requests.length - 1];
if (latestRequest.response) {
output += '## Latest Response\n\n';
output += '```json\n' + JSON.stringify(latestRequest.response, null, 2) + '\n```\n\n';
}
}

// Show full model data
output += '## Full Chat Model\n\n';
output += '```json\n' + JSON.stringify(modelData, null, 2) + '\n```\n';

await editorService.openEditor({
resource: undefined,
contents: output,
languageId: 'markdown',
options: {
pinned: true
}
});
Comment on lines +105 to +112
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the satisfies IUntitledTextResourceEditorInput keyword for type safety, similar to the pattern used in chatCodeblockActions.ts. This ensures the object literal is properly typed and catches any type errors at compile time.

Copilot uses AI. Check for mistakes.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ export class ChatWidgetService extends Disposable implements IChatWidgetService
this._widgets.push(newWidget);
this._onDidAddWidget.fire(newWidget);

if (!this._lastFocusedWidget) {
this.setLastFocusedWidget(newWidget);
}

return combinedDisposable(
newWidget.onDidFocus(() => this.setLastFocusedWidget(newWidget)),
newWidget.onDidChangeViewModel(({ previousSessionResource, currentSessionResource }) => {
Expand All @@ -245,7 +249,12 @@ export class ChatWidgetService extends Disposable implements IChatWidgetService
}
});
}),
toDisposable(() => this._widgets.splice(this._widgets.indexOf(newWidget), 1))
toDisposable(() => {
this._widgets.splice(this._widgets.indexOf(newWidget), 1);
if (this._lastFocusedWidget === newWidget) {
this.setLastFocusedWidget(undefined);
}
})
);
}
}
Loading