mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-15 07:28:05 +00:00
agent sessions - show errors opening sessions (#289662)
This commit is contained in:
@@ -13,6 +13,10 @@ import { IEditorOptions } from '../../../../../platform/editor/common/editor.js'
|
||||
import { IChatSessionsService } from '../../common/chatSessionsService.js';
|
||||
import { Schemas } from '../../../../../base/common/network.js';
|
||||
import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js';
|
||||
import { INotificationService } from '../../../../../platform/notification/common/notification.js';
|
||||
import { localize } from '../../../../../nls.js';
|
||||
import { toErrorMessage } from '../../../../../base/common/errorMessage.js';
|
||||
import { ILogService } from '../../../../../platform/log/common/log.js';
|
||||
|
||||
//#region Session Opener Registry
|
||||
|
||||
@@ -50,12 +54,17 @@ export const sessionOpenerRegistry = new SessionOpenerRegistry();
|
||||
|
||||
export async function openSession(accessor: ServicesAccessor, session: IAgentSession, openOptions?: ISessionOpenOptions): Promise<IChatWidget | undefined> {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const logService = accessor.get(ILogService);
|
||||
|
||||
// First, give registered participants a chance to handle the session
|
||||
for (const participant of sessionOpenerRegistry.getParticipants()) {
|
||||
const handled = await instantiationService.invokeFunction(accessor => participant.handleOpenSession(accessor, session, openOptions));
|
||||
if (handled) {
|
||||
return undefined; // Participant handled the session, skip default opening
|
||||
try {
|
||||
const handled = await instantiationService.invokeFunction(accessor => participant.handleOpenSession(accessor, session, openOptions));
|
||||
if (handled) {
|
||||
return undefined; // Participant handled the session, skip default opening
|
||||
}
|
||||
} catch (error) {
|
||||
logService.error(error); // log error but continue to support opening from default logic
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,36 +75,42 @@ export async function openSession(accessor: ServicesAccessor, session: IAgentSes
|
||||
async function openSessionDefault(accessor: ServicesAccessor, session: IAgentSession, openOptions?: ISessionOpenOptions): Promise<IChatWidget | undefined> {
|
||||
const chatSessionsService = accessor.get(IChatSessionsService);
|
||||
const chatWidgetService = accessor.get(IChatWidgetService);
|
||||
const notificationService = accessor.get(INotificationService);
|
||||
|
||||
session.setRead(true); // mark as read when opened
|
||||
try {
|
||||
session.setRead(true); // mark as read when opened
|
||||
|
||||
let sessionOptions: IChatEditorOptions;
|
||||
if (isLocalAgentSessionItem(session)) {
|
||||
sessionOptions = {};
|
||||
} else {
|
||||
sessionOptions = { title: { preferred: session.label } };
|
||||
let sessionOptions: IChatEditorOptions;
|
||||
if (isLocalAgentSessionItem(session)) {
|
||||
sessionOptions = {};
|
||||
} else {
|
||||
sessionOptions = { title: { preferred: session.label } };
|
||||
}
|
||||
|
||||
let options: IChatEditorOptions = {
|
||||
...sessionOptions,
|
||||
...openOptions?.editorOptions,
|
||||
revealIfOpened: true, // always try to reveal if already opened
|
||||
};
|
||||
|
||||
await chatSessionsService.activateChatSessionItemProvider(session.providerType); // ensure provider is activated before trying to open
|
||||
|
||||
let target: typeof SIDE_GROUP | typeof ACTIVE_GROUP | typeof ChatViewPaneTarget | undefined;
|
||||
if (openOptions?.sideBySide) {
|
||||
target = ACTIVE_GROUP;
|
||||
} else {
|
||||
target = ChatViewPaneTarget;
|
||||
}
|
||||
|
||||
const isLocalChatSession = session.resource.scheme === Schemas.vscodeChatEditor || session.resource.scheme === Schemas.vscodeLocalChatSession;
|
||||
if (!isLocalChatSession && !(await chatSessionsService.canResolveChatSession(session.resource))) {
|
||||
target = openOptions?.sideBySide ? SIDE_GROUP : ACTIVE_GROUP; // force to open in editor if session cannot be resolved in panel
|
||||
options = { ...options, revealIfOpened: true };
|
||||
}
|
||||
|
||||
return await chatWidgetService.openSession(session.resource, target, options);
|
||||
} catch (error) {
|
||||
notificationService.error(localize('chat.openSessionFailed', "Failed to open chat session: {0}", toErrorMessage(error)));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let options: IChatEditorOptions = {
|
||||
...sessionOptions,
|
||||
...openOptions?.editorOptions,
|
||||
revealIfOpened: true, // always try to reveal if already opened
|
||||
};
|
||||
|
||||
await chatSessionsService.activateChatSessionItemProvider(session.providerType); // ensure provider is activated before trying to open
|
||||
|
||||
let target: typeof SIDE_GROUP | typeof ACTIVE_GROUP | typeof ChatViewPaneTarget | undefined;
|
||||
if (openOptions?.sideBySide) {
|
||||
target = ACTIVE_GROUP;
|
||||
} else {
|
||||
target = ChatViewPaneTarget;
|
||||
}
|
||||
|
||||
const isLocalChatSession = session.resource.scheme === Schemas.vscodeChatEditor || session.resource.scheme === Schemas.vscodeLocalChatSession;
|
||||
if (!isLocalChatSession && !(await chatSessionsService.canResolveChatSession(session.resource))) {
|
||||
target = openOptions?.sideBySide ? SIDE_GROUP : ACTIVE_GROUP; // force to open in editor if session cannot be resolved in panel
|
||||
options = { ...options, revealIfOpened: true };
|
||||
}
|
||||
|
||||
return chatWidgetService.openSession(session.resource, target, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user