Skip to content
English

SectionSelection ​

KIT · type · 类型合同

Which part of a document a read returns.

导入 ​

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

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

定义 ​

类型: SectionSelection

类型表达式
ts
type SectionSelection = | { readonly mode: 'document' }
  /** `self` returns only the named sections; `subtree` also includes their descendants. */
  | { readonly mode: 'self' | 'subtree'; readonly sectionIds: readonly string[] };

联合分支结构 ​

SectionSelection的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1
字段类型必需说明
mode"document"必需只读。见类型定义及调用场景。
分支 2
字段类型必需说明
mode"self" | "subtree"必需只读。见类型定义及调用场景。
sectionIdsreadonly string[]必需只读。见类型定义及调用场景。

使用示例 ​

先读取一份普通对象资料 ​

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

在相同 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);
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);

相关策略源码 ​

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