@captra-ai/postgres

中文文档
0.12.0发布于 2026/10/30MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3240

Durable PostgreSQL conversation, run, memory, queue, and state adapters for Captra.

原始使用文档

@captra-ai/postgres

Durable PostgreSQL adapters for Captra conversations, runs, events, checkpoints, effect receipts, memory, queues, shared state, and optional pgvector semantic memory.

npm install @captra-ai/postgres @captra-ai/core @captra-ai/state pg
import { migrateCaptra, PostgresConversationStore, PostgresRunCompletionStore, PostgresRunStore, PostgresCheckpointStore } from '@captra-ai/postgres'

await migrateCaptra(pool)
const runtime = createRuntime(app, {
  conversations: new PostgresConversationStore(pool),
  runs: new PostgresRunStore(pool),
  completion: new PostgresRunCompletionStore(pool),
  checkpoints: new PostgresCheckpointStore(pool),
})

Always configure PostgresRunCompletionStore with durable chat. It uses one checked-out connection and one transaction to publish the assistant message, usage record, run.completed event, and terminal run state. A failed write rolls the entire completion back, while deterministic message and usage IDs make an uncertain post-commit retry safe.

Conversation IDs are scoped by tenant and bound to the user who creates them. Message IDs are deduplicated and history uses stable backward cursor pagination. All durable memory, shared state, conversations, and effect receipts are tenant-scoped. Run migrations during deployment before starting workers.

History compaction stores summaries in captra_conversation_summaries; original message rows remain unchanged. Each summary records its source message IDs, model, prompt version, timestamp, and covered sequence. Backups must include both tables so summarized model context remains reproducible and auditable.

Conversation lifecycle operations are available through the store and authenticated HTTP client:

await runtime.conversations.archive(conversationId, identity)
await runtime.conversations.restore(conversationId, identity)
await runtime.conversations.delete(conversationId, identity)

// Run from a scheduled maintenance worker, one tenant at a time.
await conversations.purgeArchived(tenantId, Date.now() - 90 * 86_400_000, 1_000)

Conversations also support titles, labels, owner/editor/viewer roles, listing, and ownership transfer. Owners control sharing, lifecycle state, transfer, and deletion; editors can append and update metadata; viewers have read-only access. migrateCaptra() adds the metadata columns and tenant-scoped membership table safely to existing installations.

purgeArchived() deletes only archived conversations older than the cutoff, uses bounded batches, and relies on cascading foreign keys to remove their messages. Back up the database before changing retention policy, run migrateCaptra() as a deployment migration, and monitor deleted row counts. PostgreSQL point-in-time recovery or regular pg_dump backups should cover the Captra schema; test restoration before enabling automated retention.

PostgreSQL documentation · GitHub · MIT

版本与发布记录

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

版本发布日期距今
0.12.0latest2026/10/3010 天前
0.11.02026/10/2911 天前
0.10.02026/10/2812 天前
0.9.02026/10/2713 天前
0.8.02026/10/2614 天前
0.7.02026/10/2514 天前

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

@captra-ai/postgres 是什么?

Durable PostgreSQL conversation, run, memory, queue, and state adapters for Captra.

如何安装 @captra-ai/postgres?

在项目目录运行 npm install @captra-ai/postgres,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@captra-ai/core(>=0.4.0 <1)、@captra-ai/state(>=0.4.0 <1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@captra-ai/postgres 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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