Zhivex 发布 TypeScript AI SDK:可移植、持久化的 AI 智能体开发框架
Zhivex/zhivex-ai-sdk
Zhivex 发布 TypeScript SDK @zhivex-ai/sdk,同一套 generateText、streamText、tools 和 agents 可在 Bun 与 Node.js 上运行,切换模型只需更换适配器。
A TypeScript SDK for portable, durable AI agents — native provider features, your own database, and a stability contract you can check in code.
Switch models, not code. The same generateText, streamText, tools, and agents run on Bun and Node.js. Install only the adapters you use.
Quick Start
Install the current release from the npm latest tag. The next tag can lag latest, so these commands install the current stable release.
bun add @zhivex-ai/sdk @zhivex-ai/openai npm install @zhivex-ai/sdk @zhivex-ai/openai
pnpm and Yarn install the same packages. See the consumer compatibility matrix. Keep provider keys on the server. Install zod when your app defines tool or object schemas. This is step 1 of the Quickstart.
The call below is the same with OpenAI or Qwen. Only the model line changes. gpt-6-astra and qwen3.8-flash are both in the SDK catalog.
import { generateText } from "@zhivex-ai/sdk"; import { createOpenAI } from "@zhivex-ai/openai"; // import { createQwen } from "@zhivex-ai/qwen"; const apiKey = process.env.OPENAI_API_KEY; if (!apiKey) throw new Error("Set OPENAI_API_KEY in the server environment."); const result = await generateText({ model: createOpenAI({ apiKey })("gpt-6-astra"), // model: createQwen({ apiKey: process.env.QWEN_API_KEY })("qwen3.8-flash"), prompt: "Describe Zhivex AI SDK in one sentence." }); console.log(result.text);
Server runtimes only: Node.js, Bun, route handlers, or workers. Browser clients call your backend. Bedrock requires Node.js 20+, and Vertex requires Node.js 22+. See SUPPORT.md.
Why Zhivex
- Portable. The same
generateText,streamText, tools, and agents. You change the adapter. - Native provider features. Qwen Cloud audio and realtime, DeepSeek FIM, Gemini and Vertex media, and Kimi Formula tools stay reachable on the shared contract.
- Durable on your own database. Sessions and
resumeAgentare stored in Postgres, SQLite, or a file you operate. UsecreatePostgresSessionService()in production. File stores are for local development. - An honest stability contract. Every runtime export is
stable,beta, orexperimental.getApiStability()reads that label, and CI fails if an export is unclassified. See STABILITY.md.
Human approval queues (createAgentApprovalQueue) are (beta).
Providers
Capability differs by adapter. Tiers describe agent support in this SDK:
| Tier | Providers |
|---|---|
| Tier A | OpenAI, Azure OpenAI, and Bedrock with runtime: "openai" |
| Tier B | xAI, Meta, Anthropic, Gemini, Vertex, Qwen, DeepSeek, and Z.ai |
| basic (Tier C) | OpenRouter, Kimi, Ollama, and Bedrock Converse |
Tier A includes approval-capable hosted tools or remote MCP. Tier B is strong tool-using agent support with provider-specific gaps. basic (Tier C) covers basic tool loops. Many unsupported combinations are rejected before the request is sent.
The full capability matrix is the source of truth.
When to use Zhivex
Use Zhivex for a TypeScript service that calls more than one provider, needs those providers' native features, and stores agent sessions in a database you already operate.
| Choose | When it fits |
|---|---|
| Zhivex AI SDK | Portable generation and agents, native features on Qwen, DeepSeek, Kimi, Z.ai, Meta, and xAI, sessions in your own Postgres or SQLite, and a per-export stability manifest. |
| Vercel AI SDK | You want the largest provider ecosystem, useChat as the default UI, or durable human-in-the-loop inside Vercel Workflows (WorkflowAgent). |
| Mastra | You want a full agent framework rather than a thin SDK layer. |
| OpenAI Agents SDK | The product stays on OpenAI, including that SDK's multi-agent, voice, and RunState approvals. |
Vercel AI SDK, Mastra, and OpenAI Agents also implement durable human-in-the-loop. Approvals here are (beta). Coming from Vercel AI SDK Core, start with the migration guide. An existing useChat UI can call a Zhivex backend through @zhivex-ai/react/compat (beta). The optional model resolver is (beta); see MODEL_RESOLVER.md.
This SDK is server-side, and one person maintains it.
The Zhivex family
Powers Zhivex Code. The coding agent and its governed runtime live in Zhivex Harness. This SDK is the layer underneath: generation, tools, agents, sessions, and gateway.
The same concepts exist for Python in the Zhivex AI SDK for Python (zhivex-ai-sdk on PyPI).
Documentation
- Docs site and the guide index
- Quickstart, agents, production, and Next.js
- Migration, workflows, MCP HTTP, and gateway routing
- Examples, stability, support, and versioning
Supported Packages
@zhivex-ai/sdk: public entry point. Re-exports the high-level API from core.@zhivex-ai/core: shared contracts, streams, catalog utilities, and generation primitives.@zhivex-ai/agents: agent-only facade for the portable runtime, stores, and safety helpers.@zhivex-ai/react: headless chat state, SSE transport, and accessible components.@zhivex-ai/openai@zhivex-ai/xai@zhivex-ai/meta@zhivex-ai/azure-openai@zhivex-ai/anthropic@zhivex-ai/gemini@zhivex-ai/vertex@zhivex-ai/qwen@zhivex-ai/kimi@zhivex-ai/deepseek@zhivex-ai/zai@zhivex-ai/openrouter@zhivex-ai/bedrock@zhivex-ai/ollama@zhivex-ai/gateway: in-process policy routing and fallback across registered adapters.
Repository Layout
packages/
core/ Shared contracts, runtime helpers, streams, middleware, catalog
sdk/ Aggregated public API
agents/ Agent-first facade over the core runtime
react/ React chat state, transport, components, and styles
openai/ OpenAI adapter
xai/ xAI Grok adapter
meta/ Meta Model API adapter
azure-openai/ Azure OpenAI adapter
anthropic/ Anthropic adapter
gemini/ Gemini adapter
vertex/ Vertex AI adapter
qwen/ Qwen adapter
kimi/ Kimi adapter
deepseek/ DeepSeek adapter
zai/ Z.ai GLM adapter
openrouter/ OpenRouter adapter
bedrock/ AWS Bedrock adapter
ollama/ Ollama adapter
gateway/ Routing and fallback package
Development uses Bun workspaces, TypeScript project references, and Vitest. See CONTRIBUTING.md.
bun install
bun run docs:check
bun run typecheck
bun run test
bun run buildLicense
MIT
来源:GitHub · github.com