Skip to content

Conversation

@ulivz
Copy link
Member

@ulivz ulivz commented Sep 13, 2025

Summary

Implement comprehensive composable component API for @tarko/agent-ui enabling flexible, slot-based UI composition while maintaining full backward compatibility.

Key Features:

  • 🎯 Composable API: Slot-based component composition with lifecycle hooks
  • 🔧 Flexible Layouts: Default, minimal, and completely custom layout options
  • 🎨 Theme Support: Light, dark, and auto theme modes
  • 📱 Responsive Design: Built-in responsive layout handling
  • Zero Breaking Changes: Full backward compatibility maintained
  • 📚 TypeScript Support: Comprehensive type definitions

New Composable API

Basic Usage

import { App, Home, Sidebar, Navbar } from '@tarko/agent-ui';

const CustomLayout = () => (
  <App
    // Lifecycle hooks
    onBeforeInit={() => console.log('Initializing...')}
    onAfterInit={() => console.log('Ready!')}
    
    // Slot-based composition
    navbar={
      <Navbar 
        items={<CustomNavContent />}
        leftActions={<Logo />}
        rightActions={<UserMenu />}
      />
    }
    
    sidebar={
      <Sidebar 
        items={<CustomSidebarContent />}
        header={<div>Custom Header</div>}
        footer={<div>Custom Footer</div>}
        width={300}
      />
    }
    
    main={<Home />}
    
    // Configuration
    layout="default"
    theme="auto"
  />
);

Advanced Customization

// Custom Home Page
<Home
  welcomeMessage={<CustomWelcome />}
  quickActions={[
    <button>New Chat</button>,
    <button>Upload File</button>
  ]}
  customSections={[<StatsCard />, <RecentActivity />]}
  variant="dashboard"
  layout="grid"
/>

// Minimal Layout
<App
  layout="minimal"
  main={<ChatPanel />}
/>

// Completely Custom Layout
<App layout="custom">
  <div className="h-screen flex flex-col">
    <header>Custom Header</header>
    <main className="flex-1">
      <ChatPanel />
    </main>
    <footer>Custom Footer</footer>
  </div>
</App>

Component API

App Component

  • Lifecycle: onBeforeInit, onAfterInit hooks
  • Slots: navbar, sidebar, main composition
  • Layouts: default, minimal, custom variants
  • Themes: light, dark, auto modes

Home Component

  • Content: Custom welcome messages and sections
  • Actions: Configurable quick action buttons
  • Variants: default, minimal, dashboard layouts
  • Events: onNewChat, onUploadFile handlers

Sidebar Component

  • Content: Custom items, header, footer slots
  • Configuration: Width, variants, session management
  • Events: Session selection and management handlers

Navbar Component

  • Actions: Left and right action slots
  • Configuration: Model/agent selectors, settings
  • Events: Model change, agent change handlers

Exports

// Composable Components (New API)
export { App, Home, Sidebar, Navbar } from '@tarko/agent-ui';

// Original Components (Direct access)
export { 
  OriginalApp, 
  OriginalHome, 
  OriginalSidebar, 
  OriginalNavbar 
} from '@tarko/agent-ui';

// Legacy Support (Unchanged)
export { AgentWebUI, WebUIConfigProvider } from '@tarko/agent-ui';

// Hooks & State
export { 
  useSession, 
  useReplayMode, 
  layoutModeAtom 
} from '@tarko/agent-ui';

Migration Path

Current (Still Works):

import { AgentWebUI, WebUIConfigProvider } from '@tarko/agent-ui';

<WebUIConfigProvider>
  <AgentWebUI />
</WebUIConfigProvider>

New Composable API:

import { App, Navbar, Sidebar, ChatPanel } from '@tarko/agent-ui';

<App
  navbar={<Navbar />}
  sidebar={<Sidebar />}
  main={<ChatPanel />}
/>

File Structure

  • @tarko/agent-ui-app: 7 files (minimal wrapper)
  • @tarko/agent-ui: Enhanced with composable components
  • src/components/: New composable component implementations
  • src/examples/: Usage examples and patterns
  • README.md: Comprehensive documentation

Benefits

  • Flexible Composition: Mix and match components as needed
  • Lifecycle Control: Hook into initialization and setup
  • Custom Layouts: From minimal to completely custom
  • Event Handling: Full control over user interactions
  • TypeScript Support: Complete type safety
  • Zero Breaking Changes: Existing code continues to work
  • Progressive Enhancement: Adopt new API incrementally

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

@netlify
Copy link

netlify bot commented Sep 13, 2025

Deploy Preview for agent-tars-docs failed.

Name Link
🔨 Latest commit 1ae55fc
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/68c5f11db78e300008921465

@ulivz ulivz force-pushed the feat/refactor-agent-ui-to-components branch from cf8b780 to ccba6b8 Compare September 13, 2025 22:22
@ulivz ulivz changed the title feat(tarko-agent-ui): refactor agent-ui to support component library pattern feat(tarko-agent-ui): ui sdk Sep 13, 2025
@ulivz ulivz changed the title feat(tarko-agent-ui): ui sdk WIP: feat(tarko-agent-ui): ui sdk Sep 13, 2025
…l wrapper app

- Enhanced @tarko/agent-ui for component library exports (AgentWebUI, WebUIConfigProvider)
- Created @tarko/agent-ui-app as minimal wrapper (7 files only)
- Uses direct source imports with path alias for zero code duplication
- Maintains backward compatibility with existing build output
- Build output preserved to agent-ui-builder/static as expected

Architecture:
- @tarko/agent-ui: Enhanced package.json + component exports
- @tarko/agent-ui-app: Minimal wrapper using source imports
- Zero code duplication through intelligent source referencing
@ulivz ulivz force-pushed the feat/refactor-agent-ui-to-components branch from ccba6b8 to 71b5e87 Compare September 13, 2025 22:27
- Added ComposableApp with lifecycle hooks and slot-based composition
- Created ComposableHome with customizable sections and layouts
- Implemented ComposableSidebar with flexible content slots
- Built ComposableNavbar with configurable actions and items
- Enhanced exports: App, Home, Sidebar, Navbar (composable) + Original* (direct)
- Added comprehensive TypeScript interfaces for all components
- Created detailed README with usage examples and migration guide
- Included practical examples showing various layout patterns

API Features:
- Lifecycle hooks: onBeforeInit, onAfterInit
- Slot-based composition: navbar, sidebar, main slots
- Layout variants: default, minimal, custom
- Theme support: light, dark, auto
- Event handlers for all major interactions
- Full TypeScript support with proper type definitions

Usage:
import { App, Home, Sidebar, Navbar } from '@tarko/agent-ui';

<App
  onBeforeInit={() => {}}
  navbar={<Navbar items={<></>} />}
  sidebar={<Sidebar items={<></>} />}
  main={<Home />}
/>
@ulivz ulivz closed this Oct 7, 2025
@ulivz
Copy link
Member Author

ulivz commented Oct 7, 2025

Close this since we need more time to design well

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