Skip to content
中文

KnowledgeCatalog ​

KIT · interface · Type contract

Compiled catalog of knowledge documents.

Import ​

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

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

Definition ​

ts
interface KnowledgeCatalog

Extends or implements: ReadonlyCatalog<KnowledgeDocument>.

Field structure ​

FieldTypeRequiredDescription
sectionIds(documentId: string) => readonly string[]RequiredSection ids of one document, in declaration order; throws for an unknown document.
assertSelection(read: KnowledgeRead) => voidRequiredValidates a read without producing content; throws when the selection is invalid.
read(read: KnowledgeRead) => KnowledgeSnapshotRequiredProduces a snapshot for the read; throws for unknown documents, sections or budget excess.
definitionsreadonly Readonly<KnowledgeDocument>[]RequiredRead-only. Definitions in registration order; each entry is frozen by the implementation.
ids() => readonly string[]RequiredIds in the same order as definitions.
values() => IterableIterator<Readonly<KnowledgeDocument>>RequiredSee the type definition and usage context.
entries() => IterableIterator<readonly [string, Readonly<KnowledgeDocument>]>RequiredSee the type definition and usage context.
has(id: string) => booleanRequiredSee the type definition and usage context.
get(id: string) => Readonly<KnowledgeDocument> | undefinedRequiredReturns the definition or undefined; the caller decides whether absence is an error.
require(id: string) => Readonly<KnowledgeDocument>RequiredReturns the definition or throws; use when the id is a required reference.

Member index ​

MemberPurpose
sectionIdsSection ids of one document, in declaration order; throws for an unknown document.
assertSelectionValidates a read without producing content; throws when the selection is invalid.
readProduces a snapshot for the read; throws for unknown documents, sections or budget excess.
idsIds in the same order as definitions.
valuesSee the overload below for full inputs and outputs.
entriesSee the overload below for full inputs and outputs.
hasSee the overload below for full inputs and outputs.
getReturns the definition or undefined; the caller decides whether absence is an error.
requireReturns the definition or throws; use when the id is a required reference.

Member details ​

sectionIds ​

Section ids of one document, in declaration order; throws for an unknown document.

ts
KnowledgeCatalog.sectionIds(documentId: string): readonly string[]

Section ids of one document, in declaration order; throws for an unknown document.

ParameterTypePassingDescription
documentIdstringRequired—

Returns: readonly string[].

assertSelection ​

Validates a read without producing content; throws when the selection is invalid.

ts
KnowledgeCatalog.assertSelection(read: KnowledgeRead): void

Validates a read without producing content; throws when the selection is invalid.

ParameterTypePassingDescription
readKnowledgeReadRequired—
Fields of read
FieldTypeRequiredDescription
documentIdstringRequiredRead-only. See the type definition and usage context.
selectionSectionSelectionRequiredRead-only. Must reference existing sections; an invalid selection throws.

Returns: void.

read ​

Produces a snapshot for the read; throws for unknown documents, sections or budget excess.

ts
KnowledgeCatalog.read(read: KnowledgeRead): KnowledgeSnapshot

Produces a snapshot for the read; throws for unknown documents, sections or budget excess.

ParameterTypePassingDescription
readKnowledgeReadRequired—
Fields of read
FieldTypeRequiredDescription
documentIdstringRequiredRead-only. See the type definition and usage context.
selectionSectionSelectionRequiredRead-only. Must reference existing sections; an invalid selection throws.

Returns: KnowledgeSnapshot.

Return value structure
FieldTypeRequiredDescription
idstringRequiredRead-only. Deterministic identity derived from document, revision and selection.
revisionstringRequiredRead-only. Revision of the document that produced this content.
localestring | undefinedOptionalRead-only. See the type definition and usage context.
contentstringRequiredRead-only. Rendered text, trimmed; sections are separated by blank lines.
documentIdstringRequiredRead-only. See the type definition and usage context.
selectionSectionSelectionRequiredRead-only. Must reference existing sections; an invalid selection throws.

ids ​

Ids in the same order as definitions.

ts
KnowledgeCatalog.ids(): readonly string[]

Ids in the same order as definitions.

No call parameters.

Returns: readonly string[].

values ​

ts
KnowledgeCatalog.values(): IterableIterator<Readonly<KnowledgeDocument>>

No call parameters.

Returns: IterableIterator<Readonly<KnowledgeDocument>>.

entries ​

ts
KnowledgeCatalog.entries(): IterableIterator<readonly [string, Readonly<KnowledgeDocument>]>

No call parameters.

Returns: IterableIterator<readonly [string, Readonly<KnowledgeDocument>]>.

has ​

ts
KnowledgeCatalog.has(id: string): boolean
ParameterTypePassingDescription
idstringRequired—

Returns: boolean.

get ​

Returns the definition or undefined; the caller decides whether absence is an error.

ts
KnowledgeCatalog.get(id: string): Readonly<KnowledgeDocument> | undefined

Returns the definition or undefined; the caller decides whether absence is an error.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<KnowledgeDocument> \| undefined.

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

Branch 1

undefined

Branch 2
FieldTypeRequiredDescription
idstringRequiredRead-only. Stable document id; duplicate ids are rejected by the catalog.
revisionstringRequiredRead-only. Revision label recorded in every snapshot so a citation names the exact content.
localestring | undefinedOptionalRead-only. Locale of the content, when the App maintains translations.
partsreadonly KnowledgePart[]RequiredRead-only. Ordered content.

require ​

Returns the definition or throws; use when the id is a required reference.

ts
KnowledgeCatalog.require(id: string): Readonly<KnowledgeDocument>

Returns the definition or throws; use when the id is a required reference.

ParameterTypePassingDescription
idstringRequired—

Returns: Readonly<KnowledgeDocument>.

Return value structure
FieldTypeRequiredDescription
idstringRequiredRead-only. Stable document id; duplicate ids are rejected by the catalog.
revisionstringRequiredRead-only. Revision label recorded in every snapshot so a citation names the exact content.
localestring | undefinedOptionalRead-only. Locale of the content, when the App maintains translations.
partsreadonly KnowledgePart[]RequiredRead-only. Ordered content.

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.