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
16 changes: 16 additions & 0 deletions src/vs/workbench/api/browser/mainThreadChatAgents2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ export class MainThreadChatAgents2 extends Disposable implements MainThreadChatA
if (newItem) {
chatSessionResource = newItem.resource;
isUntitled = false;

// Update the model's contributed session with the resolved resource
// so subsequent requests don't re-invoke newChatSessionItemHandler
// and getChatSessionFromInternalUri returns the real resource.
chatSession?.setContributedChatSession({
chatSessionType: contributedSession.chatSessionType,
chatSessionResource,
isUntitled: false,
initialSessionOptions: contributedSession.initialSessionOptions,
});

// Register alias so session-option lookups work with the new resource
this._chatSessionService.registerSessionResourceAlias(
contributedSession.chatSessionResource,
chatSessionResource
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
private readonly _sessionTypeInputPlaceholders: Map<string, string> = new Map();

private readonly _sessions = new ResourceMap<ContributedChatSessionData>();
private readonly _resourceAliases = new ResourceMap<URI>(); // real resource -> untitled resource

private readonly _hasCanDelegateProvidersKey: IContextKey<boolean>;

Expand Down Expand Up @@ -1078,20 +1079,33 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
}

public hasAnySessionOptions(sessionResource: URI): boolean {
const session = this._sessions.get(sessionResource);
const session = this._sessions.get(this._resolveResource(sessionResource));
return !!session && !!session.options && Object.keys(session.options).length > 0;
}

public getSessionOption(sessionResource: URI, optionId: string): string | IChatSessionProviderOptionItem | undefined {
const session = this._sessions.get(sessionResource);
const session = this._sessions.get(this._resolveResource(sessionResource));
return session?.getOption(optionId);
}

public setSessionOption(sessionResource: URI, optionId: string, value: string | IChatSessionProviderOptionItem): boolean {
const session = this._sessions.get(sessionResource);
const session = this._sessions.get(this._resolveResource(sessionResource));
return !!session?.setOption(optionId, value);
}

/**
* Resolve a resource through the alias map. If the resource is a real
* resource that has been aliased to an untitled resource, return the
* untitled resource (the canonical key in {@link _sessions}).
*/
private _resolveResource(resource: URI): URI {
return this._resourceAliases.get(resource) ?? resource;
}

public registerSessionResourceAlias(untitledResource: URI, realResource: URI): void {
this._resourceAliases.set(realResource, untitledResource);
}

/**
* Store option groups for a session type
*/
Expand Down Expand Up @@ -1134,7 +1148,7 @@ export class ChatSessionsService extends Disposable implements IChatSessionsServ
for (const u of updates) {
this.setSessionOption(sessionResource, u.optionId, u.value);
}
this._onDidChangeSessionOptions.fire(sessionResource);
this._onDidChangeSessionOptions.fire(this._resolveResource(sessionResource));
this._logService.trace(`[ChatSessionsService] notifySessionOptionsChange: finished for ${sessionResource}`);
}

Expand Down
6 changes: 6 additions & 0 deletions src/vs/workbench/contrib/chat/common/chatSessionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ export interface IChatSessionsService {
* Returns undefined if the controller doesn't have a handler or if no controller is registered.
*/
createNewChatSessionItem(chatSessionType: string, request: IChatAgentRequest, token: CancellationToken): Promise<IChatSessionItem | undefined>;

/**
* Registers an alias so that session-option lookups by the real resource
* are redirected to the canonical (untitled) resource in the internal session map.
*/
registerSessionResourceAlias(untitledResource: URI, realResource: URI): void;
}

export function isSessionInProgressStatus(state: ChatSessionStatus): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export class MockChatSessionsService implements IChatSessionsService {
return undefined;
}

registerSessionResourceAlias(_untitledResource: URI, _realResource: URI): void {
// noop
}

registerChatModelChangeListeners(chatService: IChatService, chatSessionType: string, onChange: () => void): IDisposable {
// Store the emitter so tests can trigger it
this.onChange = onChange;
Expand Down
Loading