Skip to content
English

KnowledgePublication ​

KIT · interface · 类型合同

Compiled publication workflow.

导入 ​

ts
import type { KnowledgePublication } from '@jangts/agent-core/kits/knowledge';
js
/** @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。

定义 ​

ts
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.

成员目录 ​

成员用途
readReturns the current record, with expired candidates already pruned.
proposeAdds a candidate based on revision; fails when the record moved on.
publishPublishes one candidate and removes it from the pending list.
rejectDiscards one candidate without touching the published documents.

成员详情 ​

read ​

Returns the current record, with expired candidates already pruned.

ts
KnowledgePublication.read(context: OperationContext<App>): Promise<KnowledgePublicationRecord>

Returns the current record, with expired candidates already pruned.

参数类型传递说明
contextOperationContext<App>必需—
context 的字段
字段类型必需说明
appunknown extends App ? App : Readonly<App>必需只读。见类型定义及调用场景。
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: Promise<KnowledgePublicationRecord>。

等待后的值: KnowledgePublicationRecord。

返回值结构
字段类型必需说明
revisionnumber必需只读。Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumber必需只读。Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]必需只读。Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]必需只读。Pending candidates; expired entries are removed before use.

propose ​

Adds a candidate based on revision; fails when the record moved on.

ts
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[]; }必需—
contextOperationContext<App>必需—
request 的字段
字段类型必需说明
revisionnumber必需见类型定义及调用场景。
documentKnowledgeDocument必需见类型定义及调用场景。
sourcesreadonly KnowledgeSourceReference[]必需见类型定义及调用场景。
context 的字段
字段类型必需说明
appunknown extends App ? App : Readonly<App>必需只读。见类型定义及调用场景。
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: Promise<KnowledgePublicationRecord>。

等待后的值: KnowledgePublicationRecord。

返回值结构
字段类型必需说明
revisionnumber必需只读。Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumber必需只读。Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]必需只读。Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]必需只读。Pending candidates; expired entries are removed before use.

publish ​

Publishes one candidate and removes it from the pending list.

ts
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; }必需—
contextOperationContext<App>必需—
request 的字段
字段类型必需说明
revisionnumber必需见类型定义及调用场景。
candidateIdstring必需见类型定义及调用场景。
context 的字段
字段类型必需说明
appunknown extends App ? App : Readonly<App>必需只读。见类型定义及调用场景。
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: Promise<KnowledgePublicationRecord>。

等待后的值: KnowledgePublicationRecord。

返回值结构
字段类型必需说明
revisionnumber必需只读。Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumber必需只读。Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]必需只读。Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]必需只读。Pending candidates; expired entries are removed before use.

reject ​

Discards one candidate without touching the published documents.

ts
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; }必需—
contextOperationContext<App>必需—
request 的字段
字段类型必需说明
revisionnumber必需见类型定义及调用场景。
candidateIdstring必需见类型定义及调用场景。
context 的字段
字段类型必需说明
appunknown extends App ? App : Readonly<App>必需只读。见类型定义及调用场景。
loggerSubFlowLog | undefined可省略只读。Explicit optional recorder for this operation; never inferred from diagnostics.
signalAbortSignal必需只读。Non-optional cancellation signal; never undefined once execution has started.
diagnosticsDiagnosticContext | undefined可省略只读。Diagnostic scope of the enclosing call, when recording is enabled.

返回: Promise<KnowledgePublicationRecord>。

等待后的值: KnowledgePublicationRecord。

返回值结构
字段类型必需说明
revisionnumber必需只读。Monotonic record revision; every accepted mutation increments it.
publishedRevisionnumber必需只读。Revision number of the currently published document set.
documentsreadonly KnowledgeDocument[]必需只读。Published documents, in catalog order.
candidatesreadonly KnowledgeCandidate[]必需只读。Pending candidates; expired entries are removed before use.

使用示例 ​

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

入门 · 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);
}

相关策略源码 ​

相关定义 ​

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