AgentScope Spark Design Documentation

repository·main·Indexed 19 days ago

https://github.com/agentscope-ai/agentscope-spark-design

An Alibaba Cloud Feitian Lab UI Component Library monorepo providing a design system and specialized LLM conversation components for AI-driven user interfaces. It includes @agentscope-ai/design for themed UI components, @agentscope-ai/chat for chat containers like ChatAnywhere and Bubble, and the Clawd Chat UI hybrid application for web and native (Expo) platforms.

Tokens
232.1K
Snippets
666
Records
846
Agent score
65%

What's inside AgentScope Spark Design

  1. Overview of Alibaba Cloud Spark Design

    main

    Alibaba Cloud Spark Design is a React UI library built on top of Ant Design. It is specifically designed for building Large Language Model (LLM) products, providing both basic components and specialized scenario components.

    Key Capabilities

    • Ant Design Compatibility: It is compatible with the Ant Design ecosystem, allowing for seamless transitions between the two.
    • LLM-Oriented: Includes a variety of scenario components tailored for LLM applications.
    • Ecosystem Integration: Works with @agentscope-ai/chat and @agentscope-ai/flow to build enterprise-level LLM applications.
    • TypeScript Support: Written in TypeScript with predictable static types and complete definition files.
    • Theming: Supports multiple preset themes and easy switching between light and dark modes.
  2. Overview of Alibaba Cloud Spark Chat

    main

    Alibaba Cloud Spark Chat is a free, open-source React conversation framework built on top of Alibaba Cloud Spark Design. It is designed to help developers build high-quality LLM (Large Language Model) chat experiences quickly by leveraging best practices from Alibaba Cloud's business scenarios.

    Key features include:

    • OpenAI-compatible model integration: Easily connect to model inference services that follow the OpenAI standard.
    • Extensibility via Cards: Support for custom components (cards) to display various model output formats.
    • Full TypeScript support: Provides complete type definitions for improved developer experience and reliability.
    • CSS-in-JS: Uses a modern CSS-in-JS approach where styles are loaded on demand, minimizing dependency on specific build tool configurations.
  3. Overview of Alibaba Cloud Spark Design features

    main

    Alibaba Cloud Spark Design is a React UI component library based on Ant Design, specifically optimized for building Large Language Model (LLM) products.

    Key features include:

    • Ant Design Compatibility: Seamlessly switch to Spark Design within the Ant Design ecosystem.
    • TypeScript Support: Written in TypeScript with predictable static types and full definition files.
    • LLM-Specific Components: Includes various scenario-based components designed for LLM applications.
    • Ecosystem Integration: Designed to work with @agentscope-ai/chat and @agentscope-ai/flow for building enterprise-grade LLM applications.
    • Theming: Supports multiple preset themes and easy switching between light and dark modes.
  4. Overview of AgentScope Spark Design sub-packages

    main

    The project is a monorepo containing two primary sub-packages:

    1. @agentscope-ai/design (packages/spark-design): The core design system component library. It provides enhanced UI components (like Button, Modal, Select) encapsulated based on Ant Design 5, supports mobile components, a custom icon system, and internationalization.

    2. @agentscope-ai/chat (packages/spark-chat): An LLM conversation component library designed for building AI chat experiences. It features out-of-the-box LLM dialogue support, Markdown rendering (math formulas, code highlighting), Mermaid flowchart support, streaming responses, and voice input support.

  5. Overview of AgentScope Spark Design packages

    main

    The project is a monorepo containing two primary packages:

    1. @agentscope-ai/design (located in packages/spark-design): A core design system component library. It provides enhanced UI components based on Ant Design 5, including mobile component support, a custom theme system, and internationalization.
    2. @agentscope-ai/chat (located in packages/spark-chat): An LLM conversation component library designed for building AI chat experiences. It includes features like Markdown rendering (with math and code highlighting), Mermaid diagram support, streaming response support, and voice input support.
  6. What is ChatAnywhere?

    main
    ChatAnywhere is an out-of-the-box conversation container built using Alibaba Cloud Spark Chat base components. It simplifies the development of LLM chat experiences by managing conversation message states internally. Instead of manually managing message arrays with React state (e.g., setMessages(...)), you use the core updateMessage(...) API to update the UI in real-time.
  7. Apply Preset Themes

    main

    Spark Design provides several preset themes via the ConfigProvider. You can choose between Carbon and Bailian themes in light or dark modes.

    Available themes:

    • carbonTheme: Carbon light theme
    • carbonDarkTheme: Carbon dark theme
    • bailianTheme: Bailian light theme
    • bailianDarkTheme: Bailian dark theme
    import { 
      ConfigProvider,
      carbonTheme,
      carbonDarkTheme,
      bailianTheme,
      bailianDarkTheme,
    } from '@agentscope-ai/design';
    
    // Use Carbon theme
    <ConfigProvider {...carbonTheme}>
      <App />
    </ConfigProvider>
    
    // Use Bailian dark theme
    <ConfigProvider {...bailianDarkTheme}>
      <App />
    </ConfigProvider>
  8. How to style custom cards with theme-aware tokens

    main

    When building custom cards, use createStyles from antd-style to access the token object. This allows you to use theme variables (like token.colorBorderSecondary or token.colorBgElevated) so your component automatically adapts to light and dark modes.

    Example usage:

    import { createStyles } from 'antd-style';
    
    const useStyles = createStyles(({ token, css }) => ({
      wrapper: css`
        border-radius: 12px;
        border: 1px solid ${token.colorBorderSecondary};
        background: ${token.colorBgElevated};
        overflow: hidden;
      `,
      // ...
    }));
  9. Use ChatAnywhere for out-of-the-box chat containers

    main

    ChatAnywhere is a pre-built chat container component from @agentscope-ai/chat that integrates Alibaba Cloud Spark Chat components. It abstracts away the manual management of chat message state (e.g., setMessages(...)), allowing you to focus on the LLM logic. Instead of managing a local state array, you use the updateMessage method via a component ref to handle real-time message updates and conversation flows.

    import { ChatAnywhere } from '@agentscope-ai/chat';
    
    // Use the ref to interact with the chat state
    const ref = useRef<ChatAnywhereRef>();
    
    <ChatAnywhere ref={ref} />
  10. Use Custom Cards in Spark Chat

    main

    You can extend the chat experience by using CustomCardsProvider from @agentscope-ai/chat to render interactive UI components (cards) within the chat stream.

    1. Define a Card Component: Create a React component that uses the MessagesContext to access and update the chat state (messages, setMessages, loading, setLoading).
    2. Register the Card: Wrap your application in CustomCardsProvider and pass your component in the cardConfig object.
    3. Trigger the Card: When an assistant message is received, include the card identifier in the cards array of the message object: cards: [{ code: 'YourCardName' }].

    This allows you to build complex interfaces like forms or specialized controls that interact directly with the agent's workflow.

    // 1. Register the card
    <CustomCardsProvider cardConfig={{ TranslateStart }}>
      <MessagesContext.Provider value={{ messages, setMessages, loading, setLoading }}>
        {/* ... chat UI ... */}
      </MessagesContext.Provider>
    </CustomCardsProvider>
    
    // 2. Trigger the card via an assistant message
    setMessages((v) => [...v, {
      role: 'assistant',
      cards: [{ code: 'TranslateStart' }],
      id: 'msg_id',
    }]);
  11. Define Menu items using ItemType

    main

    The items property of the Menu component accepts an array of ItemType. ItemType is a union of several specific types:

    1. MenuItemType: A standard clickable menu item.
    2. SubMenuType: A menu item that contains a children array of other ItemTypes.
    3. MenuGroupType: A logical grouping of items, defined by setting type: 'group'.
    4. MenuDividerType: A visual separator, defined by setting type: 'divider'.
    type ItemType = MenuItemType | SubMenuType | MenuItemGroupType | MenuDividerType;