Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: render welcome message questions near input #195405

Merged
merged 1 commit into from
Oct 11, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/vs/workbench/api/browser/mainThreadChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export class MainThreadChat extends Disposable implements MainThreadChatShape {
provideWelcomeMessage: (token) => {
return this._proxy.$provideWelcomeMessage(handle, token);
},
provideSampleQuestions: (token) => {
return this._proxy.$provideSampleQuestions(handle, token);
},
provideSlashCommands: (session, token) => {
return this._proxy.$provideSlashCommands(handle, session.id, token);
},
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,7 @@ export interface MainThreadChatShape extends IDisposable {
export interface ExtHostChatShape {
$prepareChat(handle: number, initialState: any, token: CancellationToken): Promise<IChatDto | undefined>;
$provideWelcomeMessage(handle: number, token: CancellationToken): Promise<(string | IChatReplyFollowup[])[] | undefined>;
$provideSampleQuestions(handle: number, token: CancellationToken): Promise<IChatReplyFollowup[] | undefined>;
$provideFollowups(handle: number, sessionId: number, token: CancellationToken): Promise<IChatFollowup[] | undefined>;
$provideReply(handle: number, sessionId: number, request: IChatRequestDto, token: CancellationToken): Promise<IChatResponseDto | undefined>;
$removeRequest(handle: number, sessionId: number, requestId: string): void;
Expand Down
18 changes: 18 additions & 0 deletions src/vs/workbench/api/common/extHostChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ export class ExtHostChat implements ExtHostChatShape {
return rawFollowups?.map(f => typeConvert.ChatFollowup.from(f));
}

async $provideSampleQuestions(handle: number, token: CancellationToken): Promise<IChatReplyFollowup[] | undefined> {
const entry = this._chatProvider.get(handle);
if (!entry) {
return undefined;
}

if (!entry.provider.provideSampleQuestions) {
return undefined;
}

const rawFollowups = await entry.provider.provideSampleQuestions(token);
if (!rawFollowups) {
return undefined;
}

return rawFollowups?.map(f => typeConvert.ChatReplyFollowup.from(f));
}

$removeRequest(handle: number, sessionId: number, requestId: string): void {
const entry = this._chatProvider.get(handle);
if (!entry) {
Expand Down
2 changes: 2 additions & 0 deletions src/vs/workbench/contrib/chat/browser/chatWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export class ChatWidget extends Disposable implements IChatWidget {
const lastItem = treeItems[treeItems.length - 1]?.element;
if (lastItem && isResponseVM(lastItem) && lastItem.isComplete) {
this.renderFollowups(lastItem.replyFollowups);
} else if (lastItem && isWelcomeVM(lastItem)) {
this.renderFollowups(lastItem.sampleQuestions);
} else {
this.renderFollowups(undefined);
}
Expand Down
4 changes: 3 additions & 1 deletion src/vs/workbench/contrib/chat/common/chatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export class ChatModel extends Disposable implements IChatModel {

if (obj.welcomeMessage) {
const content = obj.welcomeMessage.map(item => typeof item === 'string' ? new MarkdownString(item) : item);
this._welcomeMessage = new ChatWelcomeMessageModel(this, content);
this._welcomeMessage = new ChatWelcomeMessageModel(this, content, []);
}

try {
Expand Down Expand Up @@ -796,6 +796,7 @@ export type IChatWelcomeMessageContent = IMarkdownString | IChatReplyFollowup[];
export interface IChatWelcomeMessageModel {
readonly id: string;
readonly content: IChatWelcomeMessageContent[];
readonly sampleQuestions: IChatReplyFollowup[];
readonly username: string;
readonly avatarIconUri?: URI;

Expand All @@ -812,6 +813,7 @@ export class ChatWelcomeMessageModel implements IChatWelcomeMessageModel {
constructor(
private readonly session: ChatModel,
public readonly content: IChatWelcomeMessageContent[],
public readonly sampleQuestions: IChatReplyFollowup[]
) {
this._id = 'welcome_' + ChatWelcomeMessageModel.nextId++;
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface IChatProvider {
readonly iconUrl?: string;
prepareSession(initialState: IPersistedChatState | undefined, token: CancellationToken): ProviderResult<IChat | undefined>;
provideWelcomeMessage?(token: CancellationToken): ProviderResult<(string | IChatReplyFollowup[])[] | undefined>;
provideSampleQuestions?(token: CancellationToken): ProviderResult<IChatReplyFollowup[] | undefined>;
provideFollowups?(session: IChat, token: CancellationToken): ProviderResult<IChatFollowup[] | undefined>;
provideReply(request: IChatRequest, progress: (progress: IChatProgress) => void, token: CancellationToken): ProviderResult<IChatResponse>;
provideSlashCommands?(session: IChat, token: CancellationToken): ProviderResult<ISlashCommand[]>;
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/chat/common/chatServiceImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ export class ChatService extends Disposable implements IChatService {

const welcomeMessage = model.welcomeMessage ? undefined : await provider.provideWelcomeMessage?.(token) ?? undefined;
const welcomeModel = welcomeMessage && new ChatWelcomeMessageModel(
model, welcomeMessage.map(item => typeof item === 'string' ? new MarkdownString(item) : item as IChatReplyFollowup[]));
model,
welcomeMessage.map(item => typeof item === 'string' ? new MarkdownString(item) : item as IChatReplyFollowup[]),
await provider.provideSampleQuestions?.(token) ?? []
);

model.initialize(session, welcomeModel);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/chat/common/chatViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,6 @@ export interface IChatWelcomeMessageViewModel {
readonly username: string;
readonly avatarIconUri?: URI;
readonly content: IChatWelcomeMessageContent[];
readonly sampleQuestions: IChatReplyFollowup[];
currentRenderedHeight?: number;
}
1 change: 1 addition & 0 deletions src/vscode-dts/vscode.proposed.interactive.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ declare module 'vscode' {

export interface InteractiveSessionProvider<S extends InteractiveSession = InteractiveSession> {
provideWelcomeMessage?(token: CancellationToken): ProviderResult<InteractiveWelcomeMessageContent[]>;
provideSampleQuestions?(token: CancellationToken): ProviderResult<InteractiveSessionReplyFollowup[]>;
provideFollowups?(session: S, token: CancellationToken): ProviderResult<(string | InteractiveSessionFollowup)[]>;
provideSlashCommands?(session: S, token: CancellationToken): ProviderResult<InteractiveSessionSlashCommand[]>;

Expand Down