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(chat-panel): add vscode bundle script #2206

Merged
merged 12 commits into from
May 22, 2024
Merged

feat(chat-panel): add vscode bundle script #2206

merged 12 commits into from
May 22, 2024

Conversation

wwayne
Copy link
Contributor

@wwayne wwayne commented May 21, 2024

Context

In the VSCode chat panel, we generate a Webview using the following code snippet. It consists of HTML that loads a js script.

const agent = await createAgentInstance(this._context);
const { server } = agent.getConfig()
const scriptUri = getUri(webview, extensionUri, ['chat-panel', "index.js"]);
return `
      <!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Tabby</title>
        </head>
        <body>
          <div id="root"></div>
          <script>window.endpoint="${server.endpoint}"</script>
          <script>window.token="${server.token}"</script>
          <script type="module" src="${scriptUri}"></script>
        </body>
      </html>
`;

Goal

In clients/tabby-chat-panel, it can generate a bundled JS file used for the VSCode webview.

  1. In clients/tabby-chat-panel, command yarn build:vscode will generate a bundled JS file into clients/vscode/chat-panel/
  2. In clients/vscode, command yarn build will call clients/tabby-chat-panel to generate the JS file

@wwayne wwayne requested a review from wsxiaoys May 21, 2024 07:50
@wwayne wwayne marked this pull request as draft May 21, 2024 07:51
@wwayne wwayne force-pushed the chat-panel-vscode branch from b5eac9b to ab67c32 Compare May 21, 2024 08:01
@wwayne wwayne marked this pull request as ready for review May 21, 2024 08:04
@wwayne wwayne force-pushed the chat-panel-vscode branch from 25fcc48 to db24984 Compare May 21, 2024 10:30
@wsxiaoys wsxiaoys requested review from icycodes and removed request for wsxiaoys May 21, 2024 13:27
Comment on lines 10 to 13
useEffect(() => {
if (iframeRef.current && !clientRef.current) {
if (iframeRef.current && !clientRef.current)
clientRef.current = createClient(iframeRef.current, api)
}
Copy link
Member

@wsxiaoys wsxiaoys May 21, 2024

Choose a reason for hiding this comment

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

Please revert the change. always use {} with if except one line ifs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update the eslint

export default antfu({
  rules: {
    curly: ['off', 'all'],
  },
})

@wsxiaoys wsxiaoys removed the request for review from icycodes May 21, 2024 17:33
@wsxiaoys
Copy link
Member

cc @icycodes

Copy link
Member

@wsxiaoys wsxiaoys left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@@ -21,7 +20,8 @@ function useServer(api: ServerApi) {

useEffect(() => {
const isInIframe = window.self !== window.top
if (isInIframe && !serverRef.current) serverRef.current = createServer(api)
if (isInIframe && !serverRef.current)
serverRef.current = createServer(api)
Copy link
Member

Choose a reason for hiding this comment

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

ditto, use {}

Copy link
Member

Choose a reason for hiding this comment

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

ditto, revert changes to this file since they're all formatting related

Copy link
Member

Choose a reason for hiding this comment

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

i suggest revert change to this file as they're formatting changes.

Copy link
Member

Choose a reason for hiding this comment

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

rename this to iframe.tsx, since it's likely reuse by jetbrains as well

@@ -42,17 +42,21 @@
"start": "tsx src/index.ts",
"test": "vitest",
"test:once": "vitest run",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"build:vscode": "yarn && esbuild src/vscode.tsx --bundle --minify --outfile=../vscode/chat-panel/index.js --loader:.js=jsx",
Copy link
Member

Choose a reason for hiding this comment

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

edit build.config.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.

left a FIXME comment, because I have no idea how to edit the config file, I don't wanna spend time to check this document at the moment

@wwayne wwayne marked this pull request as draft May 22, 2024 01:44
@wwayne wwayne force-pushed the chat-panel-vscode branch from 94104b0 to 038b56b Compare May 22, 2024 01:45
@wwayne wwayne force-pushed the chat-panel-vscode branch from 54db2ae to 2c0b310 Compare May 22, 2024 06:50
@wwayne wwayne marked this pull request as ready for review May 22, 2024 07:17
@wwayne wwayne merged commit 8b073ce into main May 22, 2024
4 checks passed
@wwayne wwayne deleted the chat-panel-vscode branch May 22, 2024 07:39
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.

2 participants