Skip to content

feat: implement restore tab in chat client #933

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

Merged
merged 1 commit into from
Apr 10, 2025
Merged

Conversation

vidkhath
Copy link
Contributor

@vidkhath vidkhath commented Apr 9, 2025

Problem

Extend open tab chat client implementation to display historic chat to restore a tab

Solution

image

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@vidkhath vidkhath requested a review from a team as a code owner April 9, 2025 12:40
}, 30000)

const messageHandler = (message: any) => {
if (typeof webviewMessageId !== 'string' && message.webviewMessageId === webviewMessageId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How is it working? Don't we need to pass webviewMessageId back from chat.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasnt :D Fixed it in a new revision

reject(error)
}

webviewView.webview.onDidReceiveMessage(messageHandler, errorHandler)
Copy link
Contributor

Choose a reason for hiding this comment

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

This returns a disposable. Should we dispose it given there will be multiple registrations in this flow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense. Let me do that in a new revision

@vidkhath vidkhath force-pushed the vidkhath/open-tab branch from 6e206af to 9549cde Compare April 10, 2025 13:23
@@ -179,16 +178,15 @@ export class Messager {
this.chatApi.telemetry({ ...params, name: ERROR_MESSAGE_TELEMETRY_EVENT })
}

onOpenTab = (result: OpenTabResult | ErrorResult): void => {
this.chatApi.onOpenTab(result)
onOpenTab = (requestId: string, result: OpenTabResult | ErrorResult): void => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a test that requestId was propagated from inbound to outbound message? Can be separate PR.

const disposable = webviewView.webview.onDidReceiveMessage((message: any) => {
if (message.requestId === requestId) {
clearTimeout(timeout)
disposable.dispose()
Copy link
Contributor

@volodkevych volodkevych Apr 10, 2025

Choose a reason for hiding this comment

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

Do we also need to dispose in case of reject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes done

@@ -54,6 +54,7 @@ export type ServerMessageCommand =

export interface Message {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it's not clear why we have Message as a separate interface - you could merge it with ServerMessage.

@@ -224,9 +224,10 @@ export const createChat = (
disclaimerAcknowledged: () => {
sendMessageToClient({ command: DISCLAIMER_ACKNOWLEDGED })
},
onOpenTab: (params: OpenTabResult | ErrorResult) => {
onOpenTab: (requestId: string, params: OpenTabResult | ErrorResult) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to explain what requestId is somewhere. e.g. README

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I will add it in the README

@vidkhath vidkhath force-pushed the vidkhath/open-tab branch from 9549cde to c2829ba Compare April 10, 2025 14:57
@vidkhath vidkhath merged commit ad2c5d7 into main Apr 10, 2025
6 checks passed
@vidkhath vidkhath deleted the vidkhath/open-tab branch April 10, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants