@agentskit/chat

中文文档
0.7.0发布于 2026/10/31MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1万

Cross-framework application definitions for AgentsKit Chat.

原始使用文档
文档目录6 节
  1. Verified proof
  2. Quick start
  3. Maturity and compatibility
  4. Contributing
  5. AgentsKit ecosystem
  6. Optional PostgreSQL session envelopes

@agentskit/chat

Profile: major-package

Framework-neutral application definitions that compile to AgentsKit configuration. Owns typed routes, policy composition, component manifests, session metadata, deterministic answer adapters, and semantic fallback envelopes while the upstream controller keeps lifecycle, memory, and tool execution.

Protocol, server, devtools, and all seven framework renderers ship as subpath exports:

import { decodeTurnEvent } from '@agentskit/chat/protocol'
import { createChatHandler } from '@agentskit/chat/server'
import { createTraceCapture } from '@agentskit/chat/devtools'
import { AgentChat } from '@agentskit/chat/react'

They remain isolated private workspace modules for ownership and testing, while npm consumers install only @agentskit/chat. The former standalone package names remain available until the separate deprecation phase.

Actionable choices use createActionConfirmation, which delegates validation, canonical confirmation state, approval, denial, and execution to AgentsKit.

Verified proof

SurfaceEvidence
Standard componentscatalog.generated.md
Deterministic planeADR-0024
Upstream adoptionupstream matrix

defineChat preserves the upstream ChatConfig; it does not create another runtime.

npm install @agentskit/chat @agentskit/core

Quick start

import { defineChat } from '@agentskit/chat'
import type { AdapterFactory } from '@agentskit/core'

export const createSupportChat = (adapter: AdapterFactory) => defineChat({
  id: 'support',
  chat: { adapter },
})

Use resumeChatSession(definition, { sessionId, storage }) for cross-client metadata and pass the returned session to any renderer. Custom UI flows through defineComponentManifest and resolveComponentFrame.

One definition fans out to protocol, server, and renderer packages

flowchart LR
  C["@agentskit/chat"] --> P["/protocol"]
  C --> S["/server"]
  C --> D["/devtools"]
  C --> R["seven renderer subpaths"]

Maturity and compatibility

Published at 0.7.0 with @agentskit/core ^1.15.0, @agentskit/memory ^0.12.0, @agentskit/statechart ^0.3.2, and @agentskit/eval ^0.7.0. See stability.

  • Node.js 22+
  • TypeScript strict mode

Contributing

Package ownership: packages/chat. Follow CONTRIBUTING.md and query doc-bridge before editing.

Tags: agentskit-chat, chat-definitions, deterministic-answers, typescript

AgentsKit ecosystem

Built on AgentsKit. Composes with Registry, Playbook, and Doc Bridge.

Optional PostgreSQL session envelopes

Install drizzle-orm and a PostgreSQL driver in the host, then import the optional subpath:

import { drizzle } from 'drizzle-orm/node-postgres'
import { chatSessionDDL, createDrizzleSessionStorage } from '@agentskit/chat/drizzle-pg'

// pool is the host-owned pg Pool (Node) or connected request Client (Workers).
// Apply chatSessionDDL once in a migration, never on every production request.
const storage = createDrizzleSessionStorage(drizzle(pool), authenticatedTenantId)

The adapter stores application envelopes, not messages. Continue using upstream ChatMemory for canonical history; a Drizzle ChatMemory backend is pending upstream. save returns false for a lost cursor CAS; persistence on the resumed session converts that into SessionConflictError, and the handler preserves HTTP 409 SESSION_CONFLICT. Keys and every read/update/delete include the trusted tenant ID. Supply tenant identity from authentication, never from an untrusted event.

On Workers connect a pg.Client per request (Hyperdrive connection string in production), and call client.end() in waitUntil after consuming/closing the chat stream. On Node reuse a pg.Pool and close it during server shutdown. The adapter imports no Neon or Cloudflare-specific API. Abort is checked before SQL dispatch; in-flight SQL is not cancelled.

The same subpath provides the durable store for confirmations decided in a later request. Apply chatDecisionDDL in a migration and pass the store to the handler's decisions option:

import { createDrizzleDecisionStore } from '@agentskit/chat/drizzle-pg'

const decisions = createDrizzleDecisionStore(drizzle(pool), authenticatedTenantId, sessionId)

It implements upstream ToolDecisionStore: one row per confirmation-required tool call, and a single conditional UPDATE as the claim, so concurrent approvals execute the tool once. See server.

Optional RLS defense in depth (configure tenant context with transaction-local set_config on the same connection, and use a non-owner role without BYPASSRLS):

ALTER TABLE agentskit_chat_sessions ENABLE ROW LEVEL SECURITY;
ALTER TABLE agentskit_chat_sessions FORCE ROW LEVEL SECURITY;
CREATE POLICY chat_tenant ON agentskit_chat_sessions
  USING (tenant_id = current_setting('app.tenant_id', true))
  WITH CHECK (tenant_id = current_setting('app.tenant_id', true));

See the reusable local contract for Postgres 16 and wrangler validation. RLS is optional and is not exercised by that suite.

版本与发布记录

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

版本发布日期距今
0.7.0latest2026/10/317 天前
0.6.02026/10/1128 天前
0.5.02026/10/071 个月前
0.4.12026/07/173 个月前
0.4.02026/07/163 个月前
0.3.02026/07/153 个月前

关于 @agentskit/chat 的常见问题

@agentskit/chat 是什么?

Cross-framework application definitions for AgentsKit Chat.

如何安装 @agentskit/chat?

在项目目录运行 npm install @agentskit/chat,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@agentskit/core(^1.15.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agentskit/chat 支持 TypeScript 吗?

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

@agentskit/chat 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@agentskit/chat 可以商用吗?

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

@agentskit/chat 的下载量有多少?

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

@agentskit/chat 还在维护吗?

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