Skip to content
English

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.

导入 ​

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

其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/knowledge、@jangts/agent-core/kits。

定义 ​

泛型参数 ​

类型参数约束默认类型
App——

调用 ​

ts
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——
参数类型传递说明
optionsKnowledgePublicationOptions<App>必需—
options 的字段
字段类型必需说明
storeKnowledgePublicationStore必需只读。见类型定义及调用场景。
requiredReadsreadonly KnowledgeRead[] | undefined可省略只读。Reads that must succeed against every compiled document set, proving sections still exist.
maxReadCharsnumber | undefined可省略只读。Per-read character budget applied by the catalog compiler.
maxCandidatesnumber | undefined可省略只读。Maximum pending candidates retained; defaults to 32 and must be a positive integer.
candidateRetentionMsnumber | 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.

使用示例 ​

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

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

相关策略源码 ​

相关定义 ​

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