TypeScript Runtime
for AI-Protocol.
Protocol-driven, streaming-first TypeScript/Node.js runtime. V2 manifest parsing, standard error codes, Resilience patterns, Model routing, MCP bridge, and multimodal support.
npm install @hiddenpath/ai-lib-ts Key Features
V2 Manifest Parsing
Parse and load V2 protocol manifests with standard error codes (13 codes). Provider-agnostic configuration with zero hardcoded logic.
Resilience Patterns
Built-in RetryPolicy, CircuitBreaker, RateLimiter, and Backpressure. PreflightChecker for unified request gating.
Model Routing
ModelManager with CostBasedSelector, QualityBasedSelector, and FallbackChain. Smart model selection for cost and quality optimization.
Multimodal Support
SttClient for speech-to-text, TtsClient for text-to-speech, RerankerClient for document reranking. Full multimodal content block support.
MCP Tool Bridge
Bridge MCP tools to AI-Protocol format. Seamlessly integrate MCP servers with unified tool calling interface.
Batch & Plugins
BatchExecutor for parallel processing with configurable concurrency. Plugin system with hooks for request/response interception.
Simple, Unified API
The same code works across all 37 providers. Just change the model identifier — the protocol manifest handles everything else.
- 1 Create client with model ID
- 2 Build chat request with fluent API
- 3 Execute or stream the response
import { AiClient, Message } from '@hiddenpath/ai-lib-ts';
const client = await AiClient.new('openai/gpt-4o');
const response = await client
.chat([
Message.system('You are helpful.'),
Message.user('Hello!'),
])
.temperature(0.7)
.execute();
console.log(response.content); Internal Architecture
Protocol-driven architecture with type-safe execution, resilient by default, and fully extensible.
Module Overview
client/ + errors/
AiClient, ChatRequestBuilder, ChatResponse, CallStats, CancelToken, CancellableStream, Unified error codes.
protocol/
ProtocolLoader (local/fetch/GitHub), V2 manifest definitions, JSON Schema Validator, Provider-agnostic models.
pipeline/
Decoder (SSE, JSON Lines), Selector (JSONPath), Accumulator, FanOut, EventMapper (protocol-driven).
resilience/
RetryPolicy, CircuitBreaker, RateLimiter, Backpressure, PreflightChecker, SignalsSnapshot, FallbackChain.
routing/
ModelManager, QualityBasedSelector, CostBasedSelector, FallbackChain for intelligent model selection.
mcp/
McpBridge, McpTool definitions to seamlessly integrate Model Context Protocol servers.
multimodal/
SttClient, TtsClient, RerankerClient, fully supporting multimodal inputs and specialized models.
plugins/ + batch/
PluginRegistry, Hooks. BatchExecutor for concurrent batch execution with concurrency limits.