Skip to content
English

KnowledgeCandidate ​

KIT · interface · 类型合同

A proposed document awaiting publish or reject.

导入 ​

ts
import type { KnowledgeCandidate } from '@jangts/agent-core/kits/knowledge';
js
/** @typedef {import('@jangts/agent-core/kits/knowledge').KnowledgeCandidate} KnowledgeCandidate */

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

定义 ​

ts
interface KnowledgeCandidate

字段结构 ​

字段类型必需说明
idstring必需只读。Candidate id, generated by the Kit.
baseRevisionnumber必需只读。Record revision the candidate was proposed against, used for stale-proposal detection.
documentKnowledgeDocument必需只读。Complete document that would replace the published revision with the same id.
sourcesreadonly KnowledgeSourceReference[]必需只读。Provenance the candidate depends on; verified by the App, never trusted from the model.
createdAtMsnumber必需只读。见类型定义及调用场景。
expiresAtMsnumber必需只读。Instant after which the candidate is discarded.

使用示例 ​

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

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

相关策略源码 ​

相关定义 ​

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