KnowledgePublication
KIT · interface · 类型合同
Compiled publication workflow.
导入
import type { KnowledgePublication } from '@jangts/agent-core/kits/knowledge';/** @typedef {import('@jangts/agent-core/kits/knowledge').KnowledgePublication} KnowledgePublication */其他公开入口:@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/knowledge、@jangts/agent-core/kits。
定义
interface KnowledgePublication<App>泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
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. |
成员目录
| 成员 | 用途 |
|---|---|
read | Returns the current record, with expired candidates already pruned. |
propose | Adds a candidate based on revision; fails when the record moved on. |
publish | Publishes one candidate and removes it from the pending list. |
reject | Discards one candidate without touching the published documents. |
成员详情
read
Returns the current record, with expired candidates already pruned.
KnowledgePublication.read(context: OperationContext<App>): Promise<KnowledgePublicationRecord>Returns the current record, with expired candidates already pruned.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
context | OperationContext<App> | 必需 | — |
context 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | 必需 | 只读。见类型定义及调用场景。 |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
返回: 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. |
propose
Adds a candidate based on revision; fails when the record moved on.
KnowledgePublication.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.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | { revision: number; document: KnowledgeDocument; sources: readonly KnowledgeSourceReference[]; } | 必需 | — |
context | OperationContext<App> | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
revision | number | 必需 | 见类型定义及调用场景。 |
document | KnowledgeDocument | 必需 | 见类型定义及调用场景。 |
sources | readonly KnowledgeSourceReference[] | 必需 | 见类型定义及调用场景。 |
context 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | 必需 | 只读。见类型定义及调用场景。 |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
返回: 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. |
publish
Publishes one candidate and removes it from the pending list.
KnowledgePublication.publish(request: { revision: number; candidateId: string; }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>Publishes one candidate and removes it from the pending list.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | { revision: number; candidateId: string; } | 必需 | — |
context | OperationContext<App> | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
revision | number | 必需 | 见类型定义及调用场景。 |
candidateId | string | 必需 | 见类型定义及调用场景。 |
context 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | 必需 | 只读。见类型定义及调用场景。 |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
返回: 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. |
reject
Discards one candidate without touching the published documents.
KnowledgePublication.reject(request: { revision: number; candidateId: string; }, context: OperationContext<App>): Promise<KnowledgePublicationRecord>Discards one candidate without touching the published documents.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
request | { revision: number; candidateId: string; } | 必需 | — |
context | OperationContext<App> | 必需 | — |
request 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
revision | number | 必需 | 见类型定义及调用场景。 |
candidateId | string | 必需 | 见类型定义及调用场景。 |
context 的字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
app | unknown extends App ? App : Readonly<App> | 必需 | 只读。见类型定义及调用场景。 |
logger | SubFlowLog | undefined | 可省略 | 只读。Explicit optional recorder for this operation; never inferred from diagnostics. |
signal | AbortSignal | 必需 | 只读。Non-optional cancellation signal; never undefined once execution has started. |
diagnostics | DiagnosticContext | undefined | 可省略 | 只读。Diagnostic scope of the enclosing call, when recording is enabled. |
返回: 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. |
使用示例
- 知识候选:编译检查与显式发布:候选准备与发布复用 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);
}