npcts
v0.1.5
Published
NPC TypeScript SDK - A comprehensive UI component library for building AI-powered applications
Maintainers
Readme
npcts
TypeScript library for building NPC-powered applications with split-pane layouts, file editors, terminals, chat interfaces, spatial UI systems, and VM management.
Architecture
Core Interfaces
core/types.ts- Base types (ModelInfo, Attachment, ToolCall)core/chat.ts- Chat client interfacecore/files.ts- File system client interfacecore/browser.ts- Browser client interfacecore/jobs.ts- Jobs/cron client interfacecore/layout.ts- Layout node typescore/spatial.ts- Spatial room/character typescore/vm.ts- Virtual machine management
Adapters
Platform-specific implementations of core interfaces:
adapters/base.ts- AppServices interface definitionadapters/electron/bridge.ts- Electron/window.api implementationadapters/http/spatialServices.ts- HTTP client for spatial backend
UI Components
Layout System
LayoutProvider- Context for split pane state managementLayoutNodeComponent- Recursive layout tree rendererSplitView- Resizable horizontal/vertical splitsPaneHeader- Pane title bar with close/renameContentPaneContainer- Content type routerAppShell- Complete application with sidebar + layout
Spatial UI System
Components for building explorable 2D room-based interfaces:
SpatialProvider- Context for room/character state managementSpatialWorld- Main container combining room, character, and inputRoom- Room renderer with walls, floor, doors, applicationsCharacter- Animated sprite character with directional movementWall- Wall segment rendererDoor- Door/portal component for room transitionsApplication- Interactive application icon in roomsFloorPattern- Floor texture/pattern rendererMinimap- Overview minimap of current roomKeyLegend- Keyboard controls legendHelpOverlay- Full help overlay with all keybindingsEditModeOverlay- Edit mode indicator overlay
Spatial Hooks
useKeyboardInput- Keyboard movement and interactionuseCharacter- Character state and movementuseCollisionDetection- Wall/door/app collision detection
Spatial Utilities
transforms.ts- Coordinate transforms (percent to pixels, door positioning)collision.ts- Collision detection algorithms
File Management
FileSystemProvider- File operations contextFileTree- Recursive directory treeSidebar- Workspace sidebar with search
Content Viewers
CodeEditor- CodeMirror-based editor with syntax highlightingTerminal- Basic terminal emulatorBrowserViewer- Embedded browser framePdfViewer- PDF document viewerCsvViewer- Spreadsheet table viewImageViewer- Image display with zoom/rotate
Chat
ChatProvider- Chat state management with streamingChatInterface- Complete chat UIChatView- Message list with auto-scrollInputArea- Message input with file attachmentsConversationList- Conversation sidebar
Primitives
AutosizeTextarea- Auto-growing textareaSpinner- Loading indicator
Server Components
Backend utilities for spatial applications:
server/spatial/routes.ts- Express routes for spatial APIserver/spatial/configStore.ts- Configuration storageserver/spatial/imageHandler.ts- Image/sprite handlingserver/spatial/commandExecutor.ts- Command execution
Quick Start
With Electron
import { createElectronAdapter, AppShell } from "npcts";
const services = createElectronAdapter(window.api);
function App() {
return (
<AppShell
services={services}
workspacePath="/path/to/workspace"
/>
);
}Spatial UI
import { SpatialProvider, SpatialWorld, createHttpSpatialServices } from "npcts";
const spatialServices = createHttpSpatialServices("http://localhost:5000");
function App() {
return (
<SpatialProvider
services={spatialServices}
configPath="/path/to/config.json"
>
<SpatialWorld
width={window.innerWidth}
height={window.innerHeight}
showMinimap={true}
showKeyLegend={true}
onAppOpen={(app, name) => console.log(`Opening ${name}`)}
onRoomChange={(newRoom, oldRoom) => console.log(`Room: ${oldRoom} -> ${newRoom}`)}
/>
</SpatialProvider>
);
}VM Management
import { createHttpVMClient, createCommandVMClient } from "npcts/core/vm";
// HTTP-based VM control
const vmClient = createHttpVMClient("http://localhost:5000");
await vmClient.start("my-vm");
await vmClient.connect("my-vm");
// Command-based VM control
const cmdVMClient = createCommandVMClient();
await cmdVMClient.start("my-vm", { command: "virsh start my-vm" });Custom Adapter
import type { AppServices, ChatClient, FileSystemClient } from "npcts";
const customServices: AppServices = {
chat: customChatClient,
files: customFileClient,
browser: customBrowserClient,
jobs: customJobsClient,
};Layout Only
import { LayoutProvider, Studio } from "npcts";
function App() {
return <Studio services={services} />;
}Project Structure
src/
├── adapters/ # Platform implementations
│ ├── base.ts
│ ├── electron/
│ └── http/
│ └── spatialServices.ts
├── core/ # Core interface definitions
│ ├── types.ts
│ ├── chat.ts
│ ├── files.ts
│ ├── browser.ts
│ ├── jobs.ts
│ ├── layout.ts
│ ├── spatial.ts # Spatial types
│ └── vm.ts # VM management
├── server/ # Backend components
│ └── spatial/
│ ├── routes.ts
│ ├── configStore.ts
│ ├── imageHandler.ts
│ └── commandExecutor.ts
└── ui/ # React components
├── chat/ # Chat UI components
├── layout/ # Split pane system
├── viewers/ # Content viewers
├── files/ # File management
├── primitives/ # Base components
├── markdown/ # Markdown rendering
└── spatial/ # Spatial UI system
├── components/ # Room, Character, Door, etc.
├── context/ # SpatialProvider
├── hooks/ # useKeyboardInput, etc.
├── utils/ # transforms, collision
└── editors/ # ConfigEditorSpatial UI Controls
| Key | Action | |-----|--------| | wasd / arrows | Move character | | o | Open/interact with nearby item | | f | Toggle edit mode | | e | Add new application (edit mode) | | r | Add new room (edit mode) | | ? | Show help overlay | | esc | Close overlay / exit edit mode |
Development
npm install # Install dependencies
npm run build # Compile TypeScript
npm run dev # Watch mode
npm run check # Type check onlyFeatures
- 🎨 Split-pane layout system with drag-to-split
- 📁 File tree navigation with context menus
- 💬 Real-time chat with streaming support
- ✏️ Code editor with syntax highlighting
- 🖥️ Terminal emulator
- 🌐 Browser viewer
- 📄 PDF, CSV, and image viewers
- 🗺️ Spatial room-based UI with character navigation
- 🚪 Room transitions via doors
- 🎮 Keyboard-driven interaction
- 💻 VM management (start/stop/connect)
- 🔌 Pluggable adapter system
- 📦 TypeScript-first with full type safety
- ⚛️ React 18+ compatible
License
MIT
