Skip to content

Commit e880dde

Browse files
committed
feat(ai): Phase 6 AI CLI Builder — streaming components, chat UI, and provider hooks (v1.2.0)
Tier 1 - Core primitives: - StreamingText: controlled text prop, AsyncIterable stream, blinking cursor, typing animation - Markdown: streaming prop + cursor; partial code fence recovery - DiffView: LCS diff, unified/split/inline modes, line numbers, hunk headers Tier 2 - Chat UI (termui/components/ai): - ChatMessage + ChatThread: role-based colours, animated typing indicator, autoScroll - ToolCall: pending/running/success/error icons, live elapsed timer, collapsible result - ThinkingBlock: collapsible chain-of-thought, token count, streaming indicator - ToolApproval: risk-level border, y/n/a keybindings, countdown auto-deny Tier 3 - Integration layer: - TokenUsage + ContextMeter: compact cost display, warn/critical thresholds - ModelSelector: provider grouping, context size, built on Select - FileChange: M/A/D file list, keyboard nav, inline DiffView expansion - useChat + useCompletion (termui/ai): Anthropic/OpenAI/Ollama/custom providers, tokenUsage populated from each provider native usage events Tier 4 - Ecosystem: - createConversationStore (termui/conversation-store): JSONL/JSON persistence Bug fixes: - useChat: replaced setMessages-capture pattern with messagesRef for correct history on all turns - tokenUsage: wired setTokenUsage callback into all three provider streams - DiffView inline mode: implemented proper InlineView distinct from unified - TS2307 on optional peer SDKs: variable-specifier dynamic imports bypass tsc static resolution - tsconfig.json: added missing paths for @termui/components/ai and new adapter subpaths
1 parent 5ad5679 commit e880dde

28 files changed

Lines changed: 2194 additions & 5 deletions

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ node_modules/
4444

4545
# Packed tarballs
4646
*.tgz
47+
48+
# Temporary/scratch directories
49+
.tmp/
50+
__tmp_*/

CHANGELOG.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,51 @@
22

33
All notable changes to TermUI are documented here.
44

5-
## [1.1.7] — 2026-03-24
5+
## [1.2.0] - 2026-03-25
6+
7+
### Added - Phase 6: AI CLI Builder
8+
9+
#### Tier 1 - Core Primitives
10+
11+
- **`StreamingText`** (`termui/components/typography`) - renders LLM token streams in real time; accepts a controlled `text` prop, an `AsyncIterable<string>` via `stream`, a blinking `cursor`, and a typing `animate`/`speed` mode for pre-buffered responses
12+
- **`Markdown` streaming mode** - new `streaming` and `cursor` props on the existing component; partial code fences are closed gracefully so the component never crashes mid-stream
13+
- **`DiffView`** (`termui/components/data`) - unified, split, and inline diff views with an internal LCS algorithm (no extra dependency); supports `context` lines, `showLineNumbers`, and coloured `+`/`-` lines with `@@` hunk headers
14+
15+
#### Tier 2 - Chat UI Components
16+
17+
- **`ChatMessage` + `ChatThread`** (`termui/components/ai`) - role-based message styling (user/assistant/system/error), animated `...` typing indicator while `streaming`, collapsible system messages, and optional `autoScroll`
18+
- **`ToolCall`** - status icons for pending/running/success/error states, live elapsed timer, and collapsible args and result display
19+
- **`ThinkingBlock`** - collapsible chain-of-thought block; shows token count and duration when collapsed; `streaming` prop shows a pulsing indicator
20+
- **`ToolApproval`** - risk-level border colour (green/yellow/red), `y`/`n`/`a` keybindings, and a countdown timer that auto-denies on timeout
21+
22+
#### Tier 3 - AI Integration Layer
23+
24+
- **`TokenUsage` + `ContextMeter`** - compact token and cost display (`1.2k in / 850 out - $0.003`) with a threshold-aware progress meter (warn/critical colour steps)
25+
- **`ModelSelector`** - built on `Select`; supports provider grouping, context window size, and provider badges
26+
- **`FileChange`** - file list with M/A/D icons, keyboard navigation, and inline `DiffView` expansion per file
27+
- **`useChat` + `useCompletion`** (`termui/ai`) - provider-agnostic streaming hooks for Anthropic, OpenAI, Ollama, and custom `fetchFn`; `tokenUsage` is populated from each provider's native usage events
28+
29+
#### Tier 4 - Ecosystem
30+
31+
- **`createConversationStore`** (`termui/conversation-store`) - JSONL/JSON persistence with `save`/`load`/`list`/`delete`/`search`; auto-titles from the first user message
32+
33+
#### New exports
34+
35+
- `termui/components/ai` - all AI UI components
36+
- `termui/ai` - `useChat`, `useCompletion`
37+
- `termui/conversation-store` - `createConversationStore`
38+
39+
### Fixed
40+
41+
- `useChat` history bug: replaced the `setMessages` functional-updater capture pattern with a `messagesRef` that is updated synchronously; the stream now always receives the full, correct message list on every turn including the first
42+
- `tokenUsage` never updated: `useChat` now passes a `setTokenUsage` callback into each provider stream; Anthropic reads `message_start`/`message_delta` usage events, OpenAI enables `stream_options: { include_usage: true }`, Ollama reads `prompt_eval_count`/`eval_count` from the done line
43+
- `DiffView` inline mode was identical to unified; replaced with a proper `InlineView` that renders all ops linearly without hunk headers
44+
- DTS build failure (`TS2307`) for `@anthropic-ai/sdk` and `openai`: dynamic imports now use a variable specifier so tsc does not attempt static module resolution during declaration emit
45+
- `tsconfig.json` was missing path entries for `@termui/components/ai`, `@termui/adapters/ai`, and `@termui/adapters/conversation-store`; added all three so the root DTS build resolves them correctly
46+
47+
---
48+
49+
## [1.1.7] - 2026-03-24
650

751
### Performance
852

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "termui",
33
"private": false,
4-
"version": "1.1.8",
4+
"version": "1.2.0",
55
"description": "A TypeScript/React terminal UI framework with 100+ components, 8 themes, and a shadcn-style CLI",
66
"keywords": [
77
"terminal",
@@ -151,6 +151,18 @@
151151
"./color-env": {
152152
"import": "./dist/color-env.js",
153153
"types": "./dist/color-env.d.ts"
154+
},
155+
"./components/ai": {
156+
"import": "./dist/components-ai.js",
157+
"types": "./dist/components-ai.d.ts"
158+
},
159+
"./ai": {
160+
"import": "./dist/ai.js",
161+
"types": "./dist/ai.d.ts"
162+
},
163+
"./conversation-store": {
164+
"import": "./dist/conversation-store.js",
165+
"types": "./dist/conversation-store.d.ts"
154166
}
155167
},
156168
"dependencies": {

0 commit comments

Comments
 (0)