KnowledgePublicationOptions
KIT · interface · 类型合同
App-owned guards, store and limits for a publication workflow.
导入
ts
import type { KnowledgePublicationOptions } from '@jangts/agent-core/kits/knowledge';1
js
/** @typedef {import('@jangts/agent-core/kits/knowledge').KnowledgePublicationOptions} KnowledgePublicationOptions */1
其他公开入口:@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/kits/knowledge、@jangts/agent-core/kits。
定义
ts
interface KnowledgePublicationOptions<App>1
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
App | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
store | KnowledgePublicationStore | 必需 | 只读。见类型定义及调用场景。 |
requiredReads | readonly KnowledgeRead[] | undefined | 可省略 | 只读。Reads that must succeed against every compiled document set, proving sections still exist. |
maxReadChars | number | undefined | 可省略 | 只读。Per-read character budget applied by the catalog compiler. |
maxCandidates | number | undefined | 可省略 | 只读。Maximum pending candidates retained; defaults to 32 and must be a positive integer. |
candidateRetentionMs | number | 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. |
成员目录
| 成员 | 用途 |
|---|---|
authorize | Guards one operation before any read or write. |
verifySources | Validate real provenance/revisions/visibility. A model's source list is not a grant. |
成员详情
authorize
Guards one operation before any read or write.
ts
KnowledgePublicationOptions.authorize(operation: (typeof knowledgePublicationOperations)[number], context: OperationContext<App>): MaybePromise<void>1
Guards one operation before any read or write.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
operation | "reject" | "propose" | "publish" | 必需 | — |
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. |
返回: MaybePromise<void>。
等待后的值: void。
verifySources
Validate real provenance/revisions/visibility. A model's source list is not a grant.
ts
KnowledgePublicationOptions.verifySources(sources: readonly KnowledgeSourceReference[], context: OperationContext<App>): MaybePromise<void>1
Validate real provenance/revisions/visibility. A model's source list is not a grant.
| 参数 | 类型 | 传递 | 说明 |
|---|---|---|---|
sources | readonly KnowledgeSourceReference[] | 必需 | — |
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. |
返回: MaybePromise<void>。
等待后的值: void。
使用示例
- Knowledge:资料、章节与证据快照:同一份资料合同支持普通对象与带锚点的文本;选读后得到明确版本的证据快照。
- 知识候选:编译检查与显式发布:候选准备与发布复用 Knowledge 编译器,真实存储通过 CAS 提交正式资料。
先读取一份普通对象资料
入门 · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);1
2
3
4
5
6
2
3
4
5
6
js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '1', parts: ['Agent Core 支持普通 Workflow 节点。'] },
]);
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'document' } });
console.log(snapshot.content, snapshot.revision);1
2
3
4
5
6
2
3
4
5
6
在相同 read 上增加章节与预算
配置 · Node.js
ts
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { Knowledge } from '@jangts/agent-core/kits/knowledge';
const catalog = Knowledge.defineKnowledgeCatalog([
{ id: 'manual', revision: '2', parts: [
{ id: 'start', parts: ['先运行一个节点。', { id: 'advanced', parts: ['再增加模型和工具。'] }] },
] },
], { maxChars: 2000 });
console.log(catalog.sectionIds('manual'));
const snapshot = catalog.read({ documentId: 'manual', selection: { mode: 'subtree', sectionIds: ['start'] } });
console.log(snapshot.content, snapshot.id);1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9