@codeworksh/aikit

中文文档
0.14.1发布于 2026/11/15MITTypeScriptES Module构建来源已验证近 30 天下载 2万

TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, and more.

原始使用文档
文档目录10 节
  1. Table of Contents
  2. Installation
  3. Supported Providers
  4. Quick Start
  5. Tools
  6. Providers and Models
  7. CLI Tools
  8. Model Generation
  9. OAuth Providers
  10. Contribute

@codeworksh/aikit

AiKit is a TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, provider configurations, token and cost tracking, and mid-session hand-off to other models. It gives you the basic primitives for streaming LLM responses without the extra bloat, letting you handle the orchestration yourself.

Table of Contents

Installation

npm install @codeworksh/aikit

Node >=22.0.0 is required.

Supported Providers

Built on top of the Vercel AI SDK, @codeworksh/aikit supports a wide array of providers natively:

  • Anthropic (@ai-sdk/anthropic)
  • OpenAI (@ai-sdk/openai)
  • Google (@ai-sdk/google)
  • Google Vertex AI (@ai-sdk/google-vertex)
  • xAI (@ai-sdk/xai)
  • OpenRouter (@openrouter/ai-sdk-provider)
  • OpenAI Compatible APIs (@ai-sdk/openai-compatible)

Quick Start

import { llm, stream, Message } from "@codeworksh/aikit";

// Resolve a model from the built-in registry
const model = await llm("anthropic", "claude-haiku-4-5-20251001");
if (!model) throw new Error("Model not found");

// Setup conversation context
const context: Message.Context = {
    systemPrompt: "You are a helpful coding assistant.",
    messages: [
        Message.createUserMessage({
            role: "user",
            time: { created: Date.now() },
            parts: [{ type: "text", text: "Write a simple loop in TypeScript." }],
        }),
    ],
};

// Option 1: Stream events
const s = stream(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });

for await (const event of s) {
    if (event.type === "text.delta") {
        process.stdout.write(event.delta);
    }
}

const finalMessage = await s.result();
console.log(`\nMessage ID: ${finalMessage.messageId}`);

// Option 2: Get complete response without streaming
const message = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
console.log(message.parts);

Tools

Tools enable LLMs to interact with external systems. @codeworksh/aikit provides native support for function calling and schema validation using TypeBox.

import { Type, llm, stream, Message, validateToolArguments } from "@codeworksh/aikit";

const calculatorTool = {
    name: "calculator",
    description: "Evaluate arithmetic expressions",
    parameters: Type.Object({
        expression: Type.String(),
    }),
};

const context: Message.Context = {
    messages: [
        Message.createUserMessage({
            role: "user",
            time: { created: Date.now() },
            parts: [{ type: "text", text: "What is 25 * 18?" }],
        }),
    ],
    tools: [calculatorTool],
};

const response = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });

// Check for tool calls in the response
for (const part of response.parts) {
    if (part.type === "toolCall") {
        console.log(`Executing tool: ${part.name}`);

        // Validates arguments against TypeBox schema automatically
        const args = validateToolArguments(calculatorTool.parameters, part.arguments);
        // Execute your tool logic here...
    }
}

Providers and Models

@codeworksh/aikit uses a registry to fetch model specifications and metadata.

import { llm } from "@codeworksh/aikit";

// Get all available providers
const providers = await llm.providers();
console.log(providers);

// Get all models for a specific provider
const anthropicModels = await llm.models("anthropic");

// Get a specific model directly
const gpt4 = await llm.model("openai", "gpt-4o");

CLI Tools

@codeworksh/aikit ships with a CLI tool for managing local metadata and authentication.

You can invoke it using npx aikit or pnpm aikit.

Model Generation

Generate a models.gen.json file fetching the latest metadata about providers and their available models from models.dev.

pnpm aikit modelgen [path]

OAuth Providers

Manage OAuth credentials for providers that require it, such as OpenAI Codex and GitHub Copilot.

# Start an OAuth login flow in your browser
pnpm aikit auth --openai-codex

# Codex with a device code instead: no localhost callback port, so it works
# over SSH, in containers, and when something else holds port 1455
pnpm aikit auth --openai-codex --device

# GitHub Copilot uses the device flow; add --enterprise <domain> for GitHub Enterprise
pnpm aikit auth --github-copilot

# Check the status of your stored credentials
pnpm aikit auth --openai-codex --status
pnpm aikit auth --github-copilot --status

# Refresh your current credentials
pnpm aikit auth --openai-codex --refresh

# Clear stored credentials
pnpm aikit auth --openai-codex --logout
pnpm aikit auth --github-copilot --logout

Contribute

@codeworksh/aikit is open to community contribution. Please ensure you submit an issue before submitting a pull request. The project prefers open community discussion before accepting new features.

版本与发布记录

@codeworksh/aikit 共发布 206 个版本,首次发布于 2026/04/02;过去 12 个月发布了 206 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.14.1latest2026/11/15今天
0.14.1-dev.20261115060350dev2026/11/15今天
0.14.0-canary.154.1.g51a2e58acanary2026/11/15今天
0.14.0-canary.153.1.gb9173fe62026/11/151 天前
0.14.0-canary.152.1.g0c0579e72026/11/151 天前
0.14.0-canary.151.1.g648247082026/11/141 天前

关于 @codeworksh/aikit 的常见问题

@codeworksh/aikit 是什么?

TypeScript SDK that provides a unified API for working with multiple LLM providers, automatic model discovery, and more.

如何安装 @codeworksh/aikit?

在项目目录运行 npm install @codeworksh/aikit,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 aikit,可以用 npx aikit 直接运行。

@codeworksh/aikit 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@codeworksh/aikit 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@codeworksh/aikit 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@codeworksh/aikit 可以商用吗?

@codeworksh/aikit 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codeworksh/aikit 的下载量有多少?

根据 npm 官方下载统计,@codeworksh/aikit 在 2026/10/10 – 2026/11/08 这 30 天内被下载 19,998 次,日均约 667 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codeworksh/aikit 还在维护吗?

最新版本 0.14.1 发布于 2026/11/15(今天);至今共发布 206 个版本,其中过去 12 个月发布了 206 个;首次发布于 2026/04/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。