TypeScript Agent CLI
A TypeScript-first interactive command-line interface that connects to the Perplexity Agent API with streaming responses, runtime model selection, and integrated web search.Features
- Interactive REPL with streaming token output
- Runtime model selection from a curated list
- Web search integration via the
web_searchtool - TypeScript-specific patterns: type narrowing, const assertions, typed error classes
- Conversation history for multi-turn interactions
- Graceful error handling and clean shutdown
Installation
Usage
/search (enable web search), /nosearch (disable), /clear (reset history), /quit (exit).
Full Code
Save assrc/cli.ts:
Example Session
Key TypeScript Patterns
Const Assertions for Tool Types
Useas const to narrow tool type literals:
Streaming Event Type Narrowing
Checkchunk.type before accessing event-specific fields:
Typed Error Handling
Limitations
- The CLI uses Node.js
readline, which does not support arrow-key history navigation. For a richer experience, considerinquirerorprompts. - Conversation history is in-memory only and lost when the process exits.
- Streaming events may vary by model provider. The
response.output_text.deltaevent is consistent across all models.