@captra-ai/core

中文文档
0.21.0发布于 2026/10/30MITTypeScriptES Module构建来源已验证近 30 天下载 5678

Typed capability contracts and durable runtime for Captra.

原始使用文档

@captra-ai/core

The typed contract and execution runtime behind Captra: capabilities, agents, tools, scoped memory, approvals, budgets, durable runs, cancellation, checkpoints, effect receipts, telemetry, replay, and evaluations.

Use chat() for a streaming conversation that keeps those same guarantees. It emits chat.delta events, enforces token and cost reservations, records provider usage, supports scoped memory, and remains an ordinary discoverable Captra capability.

Set durable:true to persist message history through the runtime's tenant-safe ConversationStore. InMemoryConversationStore supports local development and cursor pagination; production adapters implement the same small interface.

The conversation contract also exposes metadata lookup, archive, restore, and permanent delete operations. Archived conversations remain readable but reject new messages until restored.

runtime.usage records every model-provider attempt and can summarize cost, tokens, reliability, and latency by run, capability, user, tenant, provider, or model. Use InMemoryUsageStore locally and PostgresUsageStore for durable deployments.

npm install @captra-ai/core zod
import { capability, capabilityViews, createRuntime, defineApp } from '@captra-ai/core'
import { z } from 'zod'

const greet = capability({
  name: 'greet', description: 'Greet a user',
  input: z.object({ name: z.string() }),
  output: z.object({ message: z.string() }),
  run: async ({ name }) => ({ message: `Hello, ${name}!` }),
  view: { name: 'Greeting' },
})

const app = defineApp({ name: 'Demo', scopes: [], capabilities: [greet], surface: capabilityViews() })
const runtime = createRuntime(app)

External writes should be declared as write tools with a stable idempotencyKey. Human approval records an independent approver identity and denies requester self-approval by default.

Structured generation uses provider-native JSON Schema when supported, then normalizes fences, validates with Zod, and performs one bounded repair attempt before returning a typed StructuredOutputError.

Evaluation suites support portable JSON/JSONL datasets, independent schema-constrained model judges, repeated runs, 95% confidence intervals, persistent history, and CI formats including JUnit and GitHub Actions annotations.

Core documentation · GitHub · MIT

Network tools are opt-in. Use createFetchJsonTool({allowedOrigins:[...]}); builtinTools contains only scoped memory operations.

Use createModelFallback() to compose named model adapters with bounded retries, timeouts, total deadlines, circuit breaking, sticky continuation state, and usage-aware fallback history.

版本与发布记录

@captra-ai/core 共发布 23 个版本,首次发布于 2026/10/24;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.21.0latest2026/10/3010 天前
0.20.02026/10/3010 天前
0.19.02026/10/2911 天前
0.18.02026/10/2812 天前
0.17.02026/10/2713 天前
0.16.02026/10/2614 天前

关于 @captra-ai/core 的常见问题

@captra-ai/core 是什么?

Typed capability contracts and durable runtime for Captra.

如何安装 @captra-ai/core?

在项目目录运行 npm install @captra-ai/core,或使用 pnpm add / yarn add / bun add。

@captra-ai/core 支持 TypeScript 吗?

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

@captra-ai/core 支持 ESM 还是 CommonJS?

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

@captra-ai/core 可以商用吗?

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

@captra-ai/core 的下载量有多少?

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

@captra-ai/core 还在维护吗?

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