@draht/router

中文文档
2026.11.5发布于 2026/11/06TypeScriptES Module近 30 天下载 2762

Role-based model routing with direct API calls, auto-fallback, and cost tracking

原始使用文档
文档目录8 节
  1. Overview
  2. Configuration
  3. Example .draht/router.json
  4. Default Role Mapping
  5. CLI Usage
  6. Fallback Behavior
  7. Cost Tracking
  8. Coding Agent Extension

@draht/router

Role-based model routing with direct API calls, automatic fallback, and cost tracking.

Overview

The router maps task roles to LLM provider/model combinations with ordered fallback chains. Calls go directly to each provider API; OpenRouter is used only for models it hosts (the DeepSeek fallbacks below).

Configuration

Config is loaded from (in priority order):

  1. .draht/router.json (project-level)
  2. ~/.draht/router.json (global)
  3. Built-in defaults

Example .draht/router.json

{
  "architect": {
    "primary": { "provider": "anthropic", "model": "claude-opus-5-5" },
    "fallbacks": [{ "provider": "google", "model": "gemini-2.5-pro" }]
  },
  "implement": {
    "primary": { "provider": "anthropic", "model": "claude-sonnet-5" },
    "fallbacks": [
      { "provider": "openai", "model": "gpt-6.1-sol" },
      { "provider": "openrouter", "model": "deepseek/deepseek-v3.2" }
    ]
  }
}

Default Role Mapping

RolePrimaryFallbacks
architectanthropic/claude-opus-5-5google/gemini-2.5-pro
implementanthropic/claude-sonnet-5openai/gpt-6.1-sol → openrouter/deepseek/deepseek-v3.2
boilerplateopenrouter/deepseek/deepseek-v3.2google/gemini-2.5-flash
quickgoogle/gemini-2.5-flashopenrouter/deepseek/deepseek-v3.2
reviewanthropic/claude-sonnet-5—
docsopenai/gpt-6.1-solanthropic/claude-sonnet-5
rlm-rootanthropic/claude-opus-5-5google/gemini-2.5-pro
rlm-subgoogle/gemini-2.5-flashopenrouter/deepseek/deepseek-v3.2

CLI Usage

# Show current configuration
draht router show

# Set model for a role
draht router set implement anthropic/claude-sonnet-5 --fallback openai/gpt-6.1-sol,openrouter/deepseek/deepseek-v3.2

# Test resolution (dry-run)
draht router test
draht router test architect

# View cost summary
draht router cost

Fallback Behavior

When the primary model fails with a retryable error (429, 5xx, timeout), the router automatically tries the next model in the fallback chain. Non-retryable errors (401, 400) are thrown immediately.

Cost Tracking

Every API call is logged to .draht/cost-log.jsonl with:

  • Timestamp, role, provider/model
  • Input/output token counts
  • Estimated cost in USD
  • Session ID

Coding Agent Extension

import { createRouterExtension } from "@draht/router/extension";

const ext = createRouterExtension();
const model = ext.selectModel("implementation"); // → anthropic/claude-sonnet-5
const chain = ext.selectModelWithFallbacks("architecture"); // → full fallback chain

Task types are automatically mapped to roles:

  • planning, architecture → architect
  • implementation, coding → implement
  • scaffold, boilerplate → boilerplate
  • question, quick → quick
  • review, pr-review → review
  • documentation, readme → docs

版本与发布记录

@draht/router 共发布 24 个版本,首次发布于 2026/07/13;过去 12 个月发布了 24 个版本。

版本发布日期距今
2026.11.5latest2026/11/067 天前
2026.11.5-12026/11/058 天前
2026.10.312026/11/0112 天前
2026.10.31-12026/10/3113 天前
2026.10.232026/10/2420 天前
2026.10.23-12026/10/2321 天前

关于 @draht/router 的常见问题

@draht/router 是什么?

Role-based model routing with direct API calls, auto-fallback, and cost tracking

如何安装 @draht/router?

在项目目录运行 npm install @draht/router,或使用 pnpm add / yarn add / bun add。

@draht/router 支持 TypeScript 吗?

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

@draht/router 支持 ESM 还是 CommonJS?

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

@draht/router 可以商用吗?

@draht/router 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@draht/router 的下载量有多少?

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

@draht/router 还在维护吗?

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