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
| Field | Type | Required | Description |
|---|---|---|---|
mode | "document" | Required | Read-only. See the type definition and usage context. |
Branch 2
| Field | Type | Required | Description |
|---|---|---|---|
mode | "self" | "subtree" | Required | Read-only. See the type definition and usage context. |
sectionIds | readonly string[] | Required | Read-only. See the type definition and usage context. |
Examples
- Knowledge: documents, sections, and evidence snapshots: One document contract supports plain objects and anchored text; a selection yields an evidence snapshot with an explicit version.
- Knowledge candidates: compilation checks and explicit publication: Candidate preparation and publication reuse the Knowledge compiler, and the real store commits official documents through CAS.
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);