Skip to content
中文

SectionSelection ​

KIT · type · Type contract

Which part of a document a read returns.

Import ​

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

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/knowledge, @jangts/agent-core/kits.

Definition ​

Type: SectionSelection

Type expression
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[] };

Union branch structure ​

Optional shapes of SectionSelection: choose one shape; required fields for each branch are listed separately.

Branch 1
FieldTypeRequiredDescription
mode"document"RequiredRead-only. See the type definition and usage context.
Branch 2
FieldTypeRequiredDescription
mode"self" | "subtree"RequiredRead-only. See the type definition and usage context.
sectionIdsreadonly string[]RequiredRead-only. See the type definition and usage context.

Examples ​

First read one plain-object document ​

Beginner · 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);

Add sections and a budget to the same read ​

Configuration · 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);

API reference, usage examples and developer guides.