543
544
private _startSession(props: IStartSessionProps): ChatModel {
545
>
const { initialData, location, sessionResource, canUseTools, transferEditingSession, disableBackgroundKeepAlive, inputState, isReadOnly } = props;
chatServiceImpl.ts
546
>
const model = this.instantiationService.createInstance(ChatModel, initialData, { initialLocation: location, canUseTools, resource: sessionResource, disableBackgroundKeepAlive, inputState, isReadOnly });
547
>
if (location === ChatAgentLocation.Chat) {
548
>
model.startEditingSession(true, transferEditingSession);
549
>
}
550
>
551
>
this.initializeSession(model);
552
>
return model;
553
>
}
554
555
private initializeSession(model: ChatModel): void {
556
>
this.trace('initializeSession', `Initialize session ${model.sessionResource}`);
chatServiceImpl.ts
557
>
558
>
// Activate the default extension provided agent but do not wait
559
>
// for it to be ready so that the session can be used immediately
560
>
// without having to wait for the agent to be ready.
561
>
this.activateDefaultAgent(model.initialLocation).catch(e => this.logService.error(e));
562
>
}
563
564
async activateDefaultAgent(location: ChatAgentLocation): Promise<void> {
566
>
567
>
const defaultAgentData = this.chatAgentService.getContributedDefaultAgent(location) ?? this.chatAgentService.getContributedDefaultAgent(ChatAgentLocation.Chat);
568
>
if (!defaultAgentData) {
569
throw new ErrorNoTelemetry('No default agent contributed');
570
}
572
>
// Await activation of the extension provided agent
573
>
// Using `activateById` as workaround for the issue
574
>
// https://github.com/microsoft/vscode/issues/250590
575
>
if (!defaultAgentData.isCore) {
576
>
await this.extensionService.activateById(defaultAgentData.extensionId, {
577
>
activationEvent: `onChatParticipant:${defaultAgentData.id}`,
578
>
extensionId: defaultAgentData.extensionId,
579
>
startup: false
580
>
});
581
>
}
582
>
583
>
const defaultAgent = this.chatAgentService.getActivatedAgents().find(agent => agent.id === defaultAgentData.id);
584
>
if (!defaultAgent) {
585
throw new ErrorNoTelemetry('No default agent registered');
586
}
588
589
getSession(sessionResource: URI): IChatModel | undefined {