KnowledgePublicationStore
KIT · interface · 类型合同
Single-writer store for the publication record.
导入
ts
import type { KnowledgePublicationStore } from '@jangts/agent-core/kits/knowledge';js
/** @typedef {import('@jangts/agent-core/kits/knowledge').KnowledgePublicationStore} KnowledgePublicationStore */其他公开入口:@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/knowledge、@jangts/agent-core/kits。
定义
ts
interface KnowledgePublicationStore字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
load | () => Promise<KnowledgePublicationRecord> | 必需 | Returns the current record; it must always be readable. |
compareAndSwap | (expectedRevision: number, next: KnowledgePublicationRecord) => Promise<boolean> | 必需 | Atomically replaces the record when the stored revision still equals expectedRevision. |
成员目录
| 成员 | 用途 |
|---|---|
load | Returns the current record; it must always be readable. |
compareAndSwap | Atomically replaces the record when the stored revision still equals expectedRevision. |
成员详情
load
Returns the current record; it must always be readable.
ts
KnowledgePublicationStore.load(): Promise<KnowledgePublicationRecord>Returns the current record; it must always be readable.
无调用参数。
返回: Promise<KnowledgePublicationRecord>。
等待后的值: KnowledgePublicationRecord。
返回值结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
revision | number | 必需 | 只读。Monotonic record revision; every accepted mutation increments it. |
publishedRevision | number | 必需 | 只读。Revision number of the currently published document set. |
documents | readonly KnowledgeDocument[] | 必需 | 只读。Published documents, in catalog order. |
candidates | readonly KnowledgeCandidate[] | 必需 | 只读。Pending candidates; expired entries are removed before use. |
compareAndSwap
Atomically replaces the record when the stored revision still equals expectedRevision.
ts
KnowledgePublicationStore.compareAndSwap(expectedRevision: number, next: KnowledgePublicationRecord): Promise<boolean>Atomically replaces the record when the stored revision still equals expectedRevision.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
expectedRevision | number | 必需 | — |
next | KnowledgePublicationRecord | 必需 | — |
next 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
revision | number | 必需 | 只读。Monotonic record revision; every accepted mutation increments it. |
publishedRevision | number | 必需 | 只读。Revision number of the currently published document set. |
documents | readonly KnowledgeDocument[] | 必需 | 只读。Published documents, in catalog order. |
candidates | readonly KnowledgeCandidate[] | 必需 | 只读。Pending candidates; expired entries are removed before use. |
返回: Promise<boolean>。
等待后的值: boolean。
使用示例
- 知识候选:编译检查与显式发布:候选准备与发布复用 Knowledge 编译器,真实存储通过 CAS 提交正式资料。
绑定资料存储与来源授权
入门 · 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);
}