Skip to content
English

知识候选:编译检查与显式发布 ​

候选准备与发布复用 Knowledge 编译器,真实存储通过 CAS 提交正式资料。

propose 检查完整替换后的资料集合,只写候选。publish 重新核对授权、来源、有效期及 publishedRevision,再原子替换正式集合。reject 删除候选。

store.revision 协调全部写入,publishedRevision 标识正式集合变化。正文或元信息发生变化时,文档需要新的 revision。普通知识读取使用 documents,候选不进入事实目录。

由简到繁的同业务示例 ​

绑定资料存储与来源授权 ​

入门 · Node.js

ts
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
import type { KnowledgePublicationOptions } from '@jangts/agent-core/kits/knowledge';

export function publication<App>(store: KnowledgePublicationOptions<App>['store'],
  authorize: KnowledgePublicationOptions<App>['authorize'],
  verifySources: KnowledgePublicationOptions<App>['verifySources']) {
  return defineKnowledgePublication({ store, authorize, verifySources, maxReadChars: 12000 });
}
js
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
export function publication(store, authorize, verifySources) {
    return defineKnowledgePublication({ store, authorize, verifySources, maxReadChars: 12000 });
}

发布已批准的候选资料 ​

配置 · Node.js

在 App 的真实审批流程后调用。来源变化、候选过期或版本冲突会拒绝提交。

ts
import type { KnowledgePublication } from '@jangts/agent-core/kits/knowledge';
import type { OperationContext } from '@jangts/agent-core';

export async function publish<App>(publication: KnowledgePublication<App>, candidateId: string,
  context: OperationContext<App>) {
  const record = await publication.read(context);
  return publication.publish({ revision: record.revision, candidateId }, context);
}
js
export async function publish(publication, candidateId, context) {
    const record = await publication.read(context);
    return publication.publish({ revision: record.revision, candidateId }, context);
}

策略与实现 ​

接口参考、使用示例与开发指南。