@haklex/rich-agent-core

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

Headless AI agent protocol, diff engine, and store for Lexical editor

原始使用文档
文档目录22 节
  1. Installation
  2. Peer Dependencies
  3. Usage
  4. Create an agent store
  5. Build document context for the agent
  6. Create an agent executor
  7. Create document editing tools
  8. Create and compare snapshots
  9. Use selectors
  10. Exports
  11. Agent Store
  12. Agent Executor
  13. Document Tools
  14. LiteXML Integration
  15. Provider
  16. Diff & Review
  17. Messages Engine
  18. Snapshots
  19. Types
  20. Selectors
  21. Part of Haklex
  22. License

@haklex/rich-agent-core

Headless AI agent protocol for Lexical rich text editing. Provides a diff-aware editing engine, document context snapshots, LiteXML-based edits, and a Zustand-backed agent store — all framework-agnostic and UI-free.

Installation

pnpm add @haklex/rich-agent-core

Peer Dependencies

PackageVersion
@haklex/rich-editorworkspace
lexical^0.45.0

Usage

Create an agent store

import { createAgentStore, createInitialAgentStoreState } from '@haklex/rich-agent-core';

const store = createAgentStore(
  createInitialAgentStoreState({
    // initial state configuration
  }),
);

Build document context for the agent

import { buildDocumentContext } from '@haklex/rich-agent-core';

const context = buildDocumentContext(editorState, {
  /* options */
});

Create an agent executor

import { createAgentExecutor } from '@haklex/rich-agent-core';

const executor = createAgentExecutor({
  store,
  provider: myProvider,
  config: {
    /* executor config */
  },
});

const result = await executor.execute({ prompt: 'Improve this paragraph' });

Create document editing tools

import { createDocumentTools } from '@haklex/rich-agent-core';

const tools = createDocumentTools({ store, editor });

Create and compare snapshots

import { createSnapshot, compareBlockContent } from '@haklex/rich-agent-core';

const snapshot = createSnapshot(editorState);
const hasChanged = compareBlockContent(snapshotA, snapshotB);

Use selectors

import { agentStoreSelectors } from '@haklex/rich-agent-core';

const messages = agentStoreSelectors.messages(store.getState());
const status = agentStoreSelectors.status(store.getState());

Exports

Agent Store

ExportDescription
createAgentStore(state)Create a Zustand agent store
createInitialAgentStoreState(config)Create initial store state
agentStoreSelectorsTyped selector functions for store state
flattenActions(actions)Flatten nested action groups

Agent Executor

ExportDescription
createAgentExecutor(config)Create an agent executor for running prompts
AgentExecutorConfigConfiguration type for the executor
AgentExecutorResultResult type from executor runs

Document Tools

ExportDescription
createDocumentTools(config)Create document editing tools for the agent
buildDocumentContext(state, options?)Build document context for agent consumption

LiteXML Integration

ExportDescription
createLitexmlEditHandler(config)Create a handler that applies LiteXML edits to the editor
createLitexmlParseHandler(config)Create a handler that parses LiteXML from agent responses
createLitexmlRegistry(options?)Create a LiteXML registry for agent use
LitexmlRegistryOptionsOptions for LiteXML registry creation
LitexmlRegistryProviderProvider interface for LiteXML registries

Provider

ExportDescription
createProvider(config)Create an AI provider instance
createDirectTransport(config)Create a direct transport adapter
createProxyTransport(config)Create a proxy transport adapter
ProviderTypeUnion type of supported provider types
TransportAdapterTransport adapter interface

Diff & Review

ExportDescription
createDiffEngine(config)Create a diff engine for edit operations
createReviewEngine(config)Create a review engine for AI-suggested edits
DiffEngineConfig, ReviewEngineConfigConfiguration types
DiffHunk, DiffResultDiff result types
ReviewBlock, ReviewStateReview state types

Messages Engine

ExportDescription
createMessagesEngine(config)Create a messages engine for chat state
MessagesEngineConfigConfiguration type
ChatMessage, MessageRoleMessage types

Snapshots

ExportDescription
createSnapshot(state)Create an editor state snapshot
compareBlockContent(a, b)Compare two snapshots by block content
EditorSnapshotSnapshot type

Types

ExportDescription
AgentStore, AgentStoreState, AgentStoreSliceStore types
AgentStoreStatusStore status enum
ChatBubbleChat bubble type for UI rendering
ToolCallGroupItem, ToolCallItemStatusTool call type definitions
StoreSetterStore setter function type

Selectors

ExportDescription
agentStoreSelectors.messagesGet all messages
agentStoreSelectors.statusGet current store status
agentStoreSelectors.sessionGet current session info
agentStoreSelectors.toolCallsGet tool call state
agentStoreSelectors.diffGet diff review state
agentStoreSelectors.modelGet selected model info

Part of Haklex

This package is part of the Haklex rich editor ecosystem.

License

MIT

版本与发布记录

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

版本发布日期距今
0.66.0latest2026/11/151 天前
0.65.72026/11/143 天前
0.65.62026/11/124 天前
0.65.52026/11/124 天前
0.65.42026/11/124 天前
0.65.32026/11/124 天前

关于 @haklex/rich-agent-core 的常见问题

@haklex/rich-agent-core 是什么?

Headless AI agent protocol, diff engine, and store for Lexical editor

如何安装 @haklex/rich-agent-core?

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

@haklex/rich-agent-core 支持 TypeScript 吗?

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

@haklex/rich-agent-core 支持 ESM 还是 CommonJS?

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

@haklex/rich-agent-core 可以商用吗?

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

@haklex/rich-agent-core 的下载量有多少?

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

@haklex/rich-agent-core 还在维护吗?

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