An interactive AI assistant demonstrating TermUI's AI-focused widgets and streaming capabilities.
- Dual-mode operation:
- Mock Mode: Works without any API key, streams predefined responses
- Real Mode: Connects to Claude (Anthropic) when
ANTHROPIC_API_KEYis set
- ChatMessage - Displays conversation history with role badges and timestamps
- StreamingText - Streams AI responses character-by-character
- ToolCall - Shows AI tool invocations with status indicators
- ToolApproval - Interactive tool approval flow with [y/n] prompts
- Token Usage Display - Shows input and output token counts
- Interactive Input - Type messages and press Enter to chat
ai-assistant/
├── package.json
├── README.md
└── src/
└── index.tsx
cd examples/ai-assistant
bun install
bun run devThe app will run in mock mode, responding with pre-defined messages.
Set the ANTHROPIC_API_KEY environment variable, then run:
export ANTHROPIC_API_KEY=sk-ant-...
cd examples/ai-assistant
bun install
bun run devThe app will stream real responses from Claude.
- Enter - Send message
- Backspace - Delete character
- [y] - Approve tool call (when shown)
- [n] - Deny tool call (when shown)
- Ctrl+C - Quit application
- useAI Hook - Initializes the AI adapter (mock or real)
- ChatMessage Widget - Renders conversation history with timestamps
- StreamingText - Streams tokens as they arrive
- ToolCall & ToolApproval - Demonstrates tool invocation and approval flow
- Token Tracking - Displays token usage statistics
- Dual-mode Architecture - Gracefully handles both mock and real operations
- When
ANTHROPIC_API_KEYis missing, the app automatically falls back to mock mode - Tool calls are demonstrated randomly after assistant responses
- Token counts are tracked and displayed in the header
- The tool approval system shows a prompt allowing users to approve or deny tool execution
bun run build@termuijs/core- Core framework@termuijs/widgets- Widget library (ChatMessage, StreamingText, ToolCall, ToolApproval)@termuijs/adapters- useAI hook for AI provider integration@termuijs/jsx- JSX runtime and hooks@termuijs/tss- Theming system