qwen-code/packages/webui
易良 87f03cf2e9
feat(vscode-ide-companion): add image paste support (#1978)
* feat(vscode-ide-companion): add image paste support

  - Add clipboard image paste functionality with drag-and-drop support
  - Implement image preview component with removal capability
  - Support multimodal content in ACP session manager for text and images
  - Save pasted images to temporary .gemini-clipboard directory
  - Add image attachment display in user messages
  - Update CSP to allow data: URIs for inline image display
  - Add comprehensive image utilities with size validation (max 10MB)
  - Include tests for image processing utilities

* refactor: simplify VS Code paste image implementation

- Remove dead code and redundant error handling
- Extract common isAuthError() helper function
- Simplify SessionMessageHandler methods (80% reduction)
- Change temp directory from .gemini-clipboard to clipboard (aligned with CLI)
- Keep multimodal image sending format (type: image + base64)

Stats:
- 6 files changed
- 367 insertions (+)
- 1176 deletions (-)

* refactor: align paste image handling

* chore: trim paste image diff

* refactor(vscode-ide-companion): remove unused attachments logic

- Remove unused ImageAttachment type imports
- Remove attachments field from TextMessage interface
- Remove attachments from message data sent to WebView
- Clean up debug console.log statements
- Simplify SessionMessageHandler handleSendMessage method

This removes dead code from the previous image paste implementation
that was no longer needed after switching to @path reference approach.

* refactor(vscode-ide-companion/webview): extract image handling into dedicated hooks and utils

- extract ImagePreview and ImageMessageRenderer components from App.tsx
- create useImageAttachments hook for managing image attachments
- create useImageResolution hook for image path resolution
- add imageAttachmentHandler for saving images to temp files
- add imageMessageUtils for message expansion and resolution
- add imagePathResolver for resolving image paths in webview
- integrate image resolution in useWebViewMessages
- extract shouldSendMessage utility from useMessageSubmit
- add getLocalResourceRoots in PanelManager for resource access

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix: harden vscode image handling and webview hosts

* fix: remove this alias in acp connection

* feat: add path escaping utility functions and tests

* feat: add support for image attachments and improve prompt handling

* refactor(webview): Optimize editing mode switching function

* refactor(vscode-ide-companion): move path escaping utilities to local module

- Move escapePath and unescapePath functions from qwen-code-core to local utils
- Add pathEscaping.ts with shell special characters handling
- Update imports in imageFormats.ts, imageAttachmentHandler.ts, and imageMessageUtils.ts
- Add unit tests for path escaping round-trip and browser bundle verification
- Fix browser bundling issue by avoiding node-only module dependencies in webview

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* refactor: consolidate image handling logic across vscode-ide-companion and webui

- Merge分散的 image hooks (useImageAttachments, useImageResolution, usePasteHandler) into unified useImage hook
- Replace image utils (imageMessageUtils, imagePathResolver, imageUtils) with imageHandler and imageSupport
- Remove clipboard image storage from core package
- Consolidate webui image components into ImageComponents.tsx
- Update imports and tests to reflect new structure

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* chore: drop unrelated core tool changes

* test: fix webview provider mocks and drop unrelated core diffs

* fix(cli): resolve original prompt through standard path in no_command case

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-03-20 13:47:09 +08:00
..
.storybook feat(webui/storybook): add full height container support for ChatViewer 2026-01-20 23:57:30 +08:00
docs chore(docs): remove obsolete documentation files 2026-01-21 20:50:45 +08:00
examples style: apply formatting and linting fixes across codebase 2026-03-06 21:58:22 +08:00
scripts feat(webui): migrate icons, Tooltip, WaitingMessage from vscode-ide-companion 2026-01-15 19:53:19 +08:00
src feat(vscode-ide-companion): add image paste support (#1978) 2026-03-20 13:47:09 +08:00
.npmignore feat(webui): Add UMD build format and CDN usage support 2026-01-22 15:47:56 +08:00
package.json chore: bump version to 0.13.0 2026-03-18 10:41:32 +08:00
postcss.config.cjs feat(webui): Infrastructure Setup (Prerequisites) 2026-01-15 14:32:21 +08:00
README.md feat(webui): Add UMD build format and CDN usage support 2026-01-22 15:47:56 +08:00
tailwind.config.cjs feat(webui): Infrastructure Setup (Prerequisites) 2026-01-15 14:32:21 +08:00
tailwind.preset.cjs refactor(vscode-ide-companion/webui): migrate PermissionDrawer to shared webui package 2026-01-16 19:48:44 +08:00
tsconfig.json feat(webui): Infrastructure Setup (Prerequisites) 2026-01-15 14:32:21 +08:00
vite.config.ts feat(webui): publish webui 2026-01-28 17:24:31 +08:00

@qwen-code/webui

A shared React component library for Qwen Code applications, providing cross-platform UI components with consistent styling and behavior.

Features

  • Cross-platform support: Components work seamlessly across VS Code extension, web, and other platforms
  • Platform Context: Abstraction layer for platform-specific capabilities
  • Tailwind CSS: Shared styling preset for consistent design
  • TypeScript: Full type definitions for all components
  • Storybook: Interactive component documentation and development
  • Multiple Build Formats: Supports ESM, CJS, and UMD formats for different environments
  • CDN Usage: Can be loaded directly in browsers via CDN

Installation

npm install @qwen-code/webui

CDN Usage

You can also use this library directly in the browser via CDN:

Option 1: With JSX Support (using Babel)

<!DOCTYPE html>
<html>
  <head>
    <!-- Load React -->
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.production.min.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
    ></script>

    <!-- Load Babel Standalone for JSX processing -->
    <script src="https://unpkg.com/@babel/standalone@7.23.6/babel.min.js"></script>

    <!-- Manually create the jsxRuntime object to satisfy the dependency -->
    <script>
      // Provide a minimal JSX runtime for builds that expect react/jsx-runtime globals.
      const withKey = (props, key) =>
        key == null ? props : Object.assign({}, props, { key });
      const jsx = (type, props, key) =>
        React.createElement(type, withKey(props, key));
      const jsxRuntime = {
        Fragment: React.Fragment,
        jsx,
        jsxs: jsx,
        jsxDEV: jsx,
      };

      window.ReactJSXRuntime = jsxRuntime;
      window['react/jsx-runtime'] = jsxRuntime;
      window['react/jsx-dev-runtime'] = jsxRuntime;
    </script>

    <!-- Load the webui library -->
    <script src="https://unpkg.com/@qwen-code/webui@0.1.0-beta.2/dist/index.umd.js"></script>

    <!-- Load the CSS -->
    <link
      rel="stylesheet"
      href="https://unpkg.com/@qwen-code/webui@0.1.0-beta.2/dist/styles.css"
    />
  </head>
  <body>
    <div id="root"></div>

    <script type="text/babel">
      // Access components from the global QwenCodeWebUI object
      const { ChatViewer } = QwenCodeWebUI;

      // Use the components with JSX support
      const App = () => (
        <ChatViewer messages={/* your messages */} />
      );

      ReactDOM.render(<App />, document.getElementById('root'));
    </script>
  </body>
</html>

Option 2: Without JSX (using React.createElement directly)

<!DOCTYPE html>
<html>
  <head>
    <!-- Load React -->
    <script
      crossorigin
      src="https://unpkg.com/react@18/umd/react.production.min.js"
    ></script>
    <script
      crossorigin
      src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
    ></script>

    <!-- Manually create the jsxRuntime object to satisfy the dependency -->
    <script>
      // Provide a minimal JSX runtime for builds that expect react/jsx-runtime globals.
      const withKey = (props, key) =>
        key == null ? props : Object.assign({}, props, { key });
      const jsx = (type, props, key) =>
        React.createElement(type, withKey(props, key));
      const jsxRuntime = {
        Fragment: React.Fragment,
        jsx,
        jsxs: jsx,
        jsxDEV: jsx,
      };

      window.ReactJSXRuntime = jsxRuntime;
      window['react/jsx-runtime'] = jsxRuntime;
      window['react/jsx-dev-runtime'] = jsxRuntime;
    </script>

    <!-- Load the webui library -->
    <script src="https://unpkg.com/@qwen-code/webui@0.1.0-beta.2/dist/index.umd.js"></script>

    <!-- Load the CSS -->
    <link
      rel="stylesheet"
      href="https://unpkg.com/@qwen-code/webui@0.1.0-beta.2/dist/styles.css"
    />
  </head>
  <body>
    <div id="root"></div>

    <script>
      // Access components from the global QwenCodeWebUI object
      const { ChatViewer } = QwenCodeWebUI;

      // Use the components with React.createElement (no JSX)
      const App = React.createElement(ChatViewer, {
        messages: [
          /* your messages */
        ],
      });

      ReactDOM.render(App, document.getElementById('root'));
    </script>
  </body>
</html>

For a complete working example, see examples/cdn-usage-demo.html.

Quick Start

import { Button, Input, Tooltip } from '@qwen-code/webui';
import { PlatformProvider } from '@qwen-code/webui/context';

function App() {
  return (
    <PlatformProvider value={platformContext}>
      <Button variant="primary" onClick={handleClick}>
        Click me
      </Button>
    </PlatformProvider>
  );
}

Components

UI Components

Button

import { Button } from '@qwen-code/webui';

<Button variant="primary" size="md" loading={false}>
  Submit
</Button>;

Props:

  • variant: 'primary' | 'secondary' | 'danger' | 'ghost' | 'outline'
  • size: 'sm' | 'md' | 'lg'
  • loading: boolean
  • leftIcon: ReactNode
  • rightIcon: ReactNode
  • fullWidth: boolean

Input

import { Input } from '@qwen-code/webui';

<Input
  label="Email"
  placeholder="Enter email"
  error={hasError}
  errorMessage="Invalid email"
/>;

Props:

  • size: 'sm' | 'md' | 'lg'
  • error: boolean
  • errorMessage: string
  • label: string
  • helperText: string
  • leftElement: ReactNode
  • rightElement: ReactNode

Tooltip

import { Tooltip } from '@qwen-code/webui';

<Tooltip content="Helpful tip">
  <span>Hover me</span>
</Tooltip>;

Icons

import { FileIcon, FolderIcon, CheckIcon } from '@qwen-code/webui/icons';

<FileIcon size={16} className="text-gray-500" />;

Available icon categories:

  • FileIcons: FileIcon, FolderIcon, SaveDocumentIcon
  • StatusIcons: CheckIcon, ErrorIcon, WarningIcon, LoadingIcon
  • NavigationIcons: ArrowLeftIcon, ArrowRightIcon, ChevronIcon
  • EditIcons: EditIcon, DeleteIcon, CopyIcon
  • SpecialIcons: SendIcon, StopIcon, CloseIcon

Layout Components

  • Container: Main layout wrapper
  • Header: Application header
  • Footer: Application footer
  • Sidebar: Side navigation
  • Main: Main content area

Message Components

  • Message: Chat message display
  • MessageList: List of messages
  • MessageInput: Message input field
  • WaitingMessage: Loading/waiting state
  • InterruptedMessage: Interrupted state display

Platform Context

The Platform Context provides an abstraction layer for platform-specific capabilities:

import { PlatformProvider, usePlatform } from '@qwen-code/webui/context';

const platformContext = {
  postMessage: (message) => vscode.postMessage(message),
  onMessage: (handler) => {
    window.addEventListener('message', handler);
    return () => window.removeEventListener('message', handler);
  },
  openFile: (path) => {
    /* platform-specific */
  },
  platform: 'vscode',
};

function App() {
  return (
    <PlatformProvider value={platformContext}>
      <YourApp />
    </PlatformProvider>
  );
}

function Component() {
  const { postMessage, platform } = usePlatform();
  // Use platform capabilities
}

Tailwind Preset

Use the shared Tailwind preset for consistent styling:

// tailwind.config.js
module.exports = {
  presets: [require('@qwen-code/webui/tailwind.preset.cjs')],
  // your customizations
};

Development

Running Storybook

cd packages/webui
npm run storybook

Building

npm run build

Type Checking

npm run typecheck

Project Structure

packages/webui/
├── src/
│   ├── components/
│   │   ├── icons/          # Icon components
│   │   ├── layout/         # Layout components
│   │   ├── messages/       # Message components
│   │   └── ui/             # UI primitives
│   ├── context/            # Platform context
│   ├── hooks/              # Custom hooks
│   └── types/              # Type definitions
├── .storybook/             # Storybook config
├── tailwind.preset.cjs     # Shared Tailwind preset
└── vite.config.ts          # Build configuration

License

Apache-2.0