defineKnowledgePublication
KIT · function · 运行时值
Compile a publication lifecycle over one App-owned atomic record.
Candidate preparation and publication share the same compiler and an App-owned atomic revision. propose compiles and validates a candidate but leaves published documents alone; publish re-verifies sources and the base revision before swapping, so a stale candidate can never overwrite newer content.
导入
import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/knowledge、@jangts/agent-core/kits。
定义
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
App | — | — |
调用
defineKnowledgePublication<App>(options: KnowledgePublicationOptions<App>): KnowledgePublication<App>Compile a publication lifecycle over one App-owned atomic record.
Candidate preparation and publication share the same compiler and an App-owned atomic revision. propose compiles and validates a candidate but leaves published documents alone; publish re-verifies sources and the base revision before swapping, so a stale candidate can never overwrite newer content.
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
App | — | — |
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
options | KnowledgePublicationOptions<App> | 必需 | — |
options 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
store | KnowledgePublicationStore | 必需 | 只读。见类型定义及调用场景。 |
requiredReads | readonly KnowledgeRead[] | undefined | 可省略 | 只读。Reads that must succeed against every compiled document set, proving sections still exist. |
maxReadChars | number | undefined | 可省略 | 只读。Per-read character budget applied by the catalog compiler. |
maxCandidates | number | undefined | 可省略 | 只读。Maximum pending candidates retained; defaults to 32 and must be a positive integer. |
candidateRetentionMs | number | undefined | 可省略 | 只读。Candidate retention window; defaults to seven days. |
now | (() => number) | undefined | 可省略 | 只读。Clock override for timestamps and expiry; defaults to Date.now. |
authorize | (operation: (typeof knowledgePublicationOperations)[number], context: OperationContext<App>) => MaybePromise<void> | 必需 | Guards one operation before any read or write. |
verifySources | (sources: readonly KnowledgeSourceReference[], context: OperationContext<App>) => MaybePromise<void> | 必需 | Validate real provenance/revisions/visibility. A model's source list is not a grant. |
返回: KnowledgePublication<App>。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
read | (context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | 必需 | Returns the current record, with expired candidates already pruned. |
propose | (request: { revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | 必需 | Adds a candidate based on revision; fails when the record moved on. |
publish | (request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | 必需 | Publishes one candidate and removes it from the pending list. |
reject | (request: { revision: number; candidateId: string; }, context: OperationContext<App>) => Promise<KnowledgePublicationRecord> | 必需 | Discards one candidate without touching the published documents. |
使用示例
- 知识候选:编译检查与显式发布:候选准备与发布复用 Knowledge 编译器,真实存储通过 CAS 提交正式资料。
绑定资料存储与来源授权
入门 · Node.js
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 });
}import { defineKnowledgePublication } from '@jangts/agent-core/kits/knowledge';
export function publication(store, authorize, verifySources) {
return defineKnowledgePublication({ store, authorize, verifySources, maxReadChars: 12000 });
}发布已批准的候选资料
配置 · Node.js
在 App 的真实审批流程后调用。来源变化、候选过期或版本冲突会拒绝提交。
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);
}export async function publish(publication, candidateId, context) {
const record = await publication.read(context);
return publication.publish({ revision: record.revision, candidateId }, context);
}