@dikolab/kbdb 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +452 -144
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +452 -144
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +49 -7
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +1 -1
- package/dist/mod.cjs.map +1 -1
- package/dist/mod.mjs +1 -1
- package/dist/mod.mjs.map +1 -1
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
- package/dist/src/shared/cli/functions/learn-structured-document.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/learn-target-content.function.d.ts +5 -17
- package/dist/src/shared/cli/functions/split-markdown-sections.function.d.ts +4 -0
- package/dist/src/shared/cli/typings/learn-client.interface.d.ts +2 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +2 -0
- package/dist/src/shared/content-splitter/classes/heading-parent-tracker.class.d.ts +20 -0
- package/dist/src/shared/content-splitter/constants/content-type-maps.constant.d.ts +5 -0
- package/dist/src/shared/content-splitter/constants/split-strategy-map.constant.d.ts +4 -0
- package/dist/src/shared/content-splitter/functions/detect-content-type.function.d.ts +13 -0
- package/dist/src/shared/content-splitter/functions/flush-markdown-draft.function.d.ts +14 -0
- package/dist/src/shared/content-splitter/functions/flush-toml-draft.function.d.ts +15 -0
- package/dist/src/shared/content-splitter/functions/push-content-section.function.d.ts +16 -0
- package/dist/src/shared/content-splitter/functions/resolve-parent-ids.function.d.ts +14 -0
- package/dist/src/shared/content-splitter/functions/split-content.function.d.ts +11 -0
- package/dist/src/shared/content-splitter/functions/split-html.function.d.ts +12 -0
- package/dist/src/shared/content-splitter/functions/split-markdown.function.d.ts +13 -0
- package/dist/src/shared/content-splitter/functions/split-plain-text.function.d.ts +8 -0
- package/dist/src/shared/content-splitter/functions/split-toml.function.d.ts +12 -0
- package/dist/src/shared/content-splitter/index.d.ts +11 -0
- package/dist/src/shared/content-splitter/typings/content-format.type.d.ts +2 -0
- package/dist/src/shared/content-splitter/typings/content-section.interface.d.ts +17 -0
- package/dist/src/shared/content-splitter/typings/markdown-draft.interface.d.ts +12 -0
- package/dist/src/shared/content-splitter/typings/split-result.interface.d.ts +8 -0
- package/dist/src/shared/content-splitter/typings/split-strategy.interface.d.ts +3 -0
- package/dist/src/shared/content-splitter/typings/toml-draft.interface.d.ts +15 -0
- package/dist/src/shared/mcp/functions/build-learn-payload.function.d.ts +24 -0
- package/dist/src/shared/mcp/functions/determine-learn-split.function.d.ts +18 -0
- package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +3 -1
- package/dist/src/shared/mcp/functions/learn-with-splitting.function.d.ts +22 -0
- package/dist/src/shared/mcp/functions/parse-learn-args.function.d.ts +24 -0
- package/dist/src/shared/mcp/functions/store-split-learn-sections.function.d.ts +16 -0
- package/dist/src/shared/mcp/functions/unwrap-json-content.function.d.ts +9 -0
- package/dist/src/shared/mcp/typings/learn-section-params.interface.d.ts +20 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +4 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +4 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +2 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +2 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +2 -1
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +6 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +2 -1
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +2 -0
- package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +4 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +2 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +2 -0
- package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +4 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +2 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/worker.mjs +49 -7
- package/dist/worker.mjs.map +4 -4
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LearnClient } from '../typings/learn-client.interface.ts';
|
|
2
|
+
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
3
|
+
import type { LearnResult } from '../typings/learn-result.model.ts';
|
|
4
|
+
import type { SplitResult } from '../../content-splitter/index.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Stores each section of a split result as a separate
|
|
7
|
+
* knowledge-base section with parent resolution, then
|
|
8
|
+
* groups them under one document.
|
|
9
|
+
*/
|
|
10
|
+
export declare function learnStructuredDocument(client: LearnClient, options: CliOptions, path: string, splitResult: SplitResult, sourcePath?: string): Promise<LearnResult[]>;
|
|
@@ -2,23 +2,11 @@ import type { LearnClient } from '../typings/learn-client.interface.ts';
|
|
|
2
2
|
import type { CliOptions } from '../typings/cli-options.interface.ts';
|
|
3
3
|
import type { LearnResult } from '../typings/learn-result.model.ts';
|
|
4
4
|
/**
|
|
5
|
-
* Ingests one already-read target
|
|
6
|
-
*
|
|
7
|
-
* of sections grouped under one document.
|
|
5
|
+
* Ingests one already-read target as either a single section
|
|
6
|
+
* or, for eligible structured content (Markdown, HTML, TOML),
|
|
7
|
+
* a set of sections grouped under one document.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* an explicit title always maps to a single section. When splitting
|
|
12
|
-
* does not apply, `content` is ingested as-is via `addSection()`.
|
|
13
|
-
*
|
|
14
|
-
* @param client - learn client to delegate ingestion to
|
|
15
|
-
* @param options - parsed CLI options for this invocation
|
|
16
|
-
* @param path - source file path, or `'-'` for stdin
|
|
17
|
-
* @param content - raw text content already read from `path`
|
|
18
|
-
* @param sourcePath - absolute file path for supersession, or
|
|
19
|
-
* `undefined` for stdin input
|
|
20
|
-
* @param level - hierarchical level for the single-section
|
|
21
|
-
* fallback; ignored when markdown splitting applies
|
|
22
|
-
* @returns one `LearnResult` per ingested section
|
|
9
|
+
* Splitting is attempted when `options.title` is not set and
|
|
10
|
+
* the content produces 2+ sections with at least one heading.
|
|
23
11
|
*/
|
|
24
12
|
export declare function learnTargetContent(client: LearnClient, options: CliOptions, path: string, content: string, sourcePath?: string, level?: number): Promise<LearnResult[]>;
|
|
@@ -5,6 +5,10 @@ import type { MarkdownSection } from '../typings/markdown-section.interface.ts';
|
|
|
5
5
|
* fenced code blocks are treated as plain text. A document with
|
|
6
6
|
* no headings is returned as one titleless section.
|
|
7
7
|
*
|
|
8
|
+
* Thin backward-compatible wrapper over the shared
|
|
9
|
+
* `splitMarkdown` strategy in `content-splitter`, stripping its
|
|
10
|
+
* `parentIndex` field for callers that predate section nesting.
|
|
11
|
+
*
|
|
8
12
|
* @param content - raw markdown document text
|
|
9
13
|
* @returns sections in document order, with trailing whitespace
|
|
10
14
|
* trimmed from each section's body
|
|
@@ -28,6 +28,8 @@ export interface LearnClient {
|
|
|
28
28
|
sourcePath?: string;
|
|
29
29
|
/** Hierarchical level (1-6) assigned to the section. */
|
|
30
30
|
level?: number;
|
|
31
|
+
/** KBID of the parent section for nesting. */
|
|
32
|
+
parent?: string;
|
|
31
33
|
}): Promise<AddSectionResult>;
|
|
32
34
|
/**
|
|
33
35
|
* Groups a set of sections under a named document, creating the
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tracks nesting of headings by depth to resolve each new
|
|
3
|
+
* heading's parent section index. Shared by splitters whose
|
|
4
|
+
* sections nest by a numeric depth (markdown, HTML).
|
|
5
|
+
*/
|
|
6
|
+
export declare class HeadingParentTracker {
|
|
7
|
+
private readonly stack;
|
|
8
|
+
/**
|
|
9
|
+
* Resolves the parent index for a heading at `level`
|
|
10
|
+
* appearing at output position `index`, then records the
|
|
11
|
+
* heading so subsequent, deeper headings can nest under it.
|
|
12
|
+
*
|
|
13
|
+
* @param level - heading depth, shallower is smaller
|
|
14
|
+
* @param index - position of this heading in the output
|
|
15
|
+
* sections array
|
|
16
|
+
* @returns the parent's output index, or `null` when the
|
|
17
|
+
* heading is at the root
|
|
18
|
+
*/
|
|
19
|
+
resolve(level: number, index: number): number | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ContentFormat } from '../typings/content-format.type.ts';
|
|
2
|
+
/** Explicit type hints (MIME or short-form) mapped to format. */
|
|
3
|
+
export declare const HINT_FORMAT_MAP: Record<string, ContentFormat>;
|
|
4
|
+
/** File extensions (without the leading dot) mapped to format. */
|
|
5
|
+
export declare const EXTENSION_FORMAT_MAP: Record<string, ContentFormat>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ContentFormat } from '../typings/content-format.type.ts';
|
|
2
|
+
import type { SplitStrategy } from '../typings/split-strategy.interface.ts';
|
|
3
|
+
/** Maps each recognized content format to its split strategy. */
|
|
4
|
+
export declare const SPLIT_STRATEGY_MAP: Record<ContentFormat, SplitStrategy>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContentFormat } from '../typings/content-format.type.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Detects the content format of a document, preferring an
|
|
4
|
+
* explicit type hint, then a file extension, then sniffing
|
|
5
|
+
* the content itself, and finally falling back to plain text.
|
|
6
|
+
*
|
|
7
|
+
* @param content - raw document text
|
|
8
|
+
* @param typeHint - explicit MIME type or short-form hint
|
|
9
|
+
* (e.g. `'text/markdown'`, `'markdown'`)
|
|
10
|
+
* @param filePath - source file path used to infer format
|
|
11
|
+
* from its extension
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectContentType(content: string, typeHint?: string, filePath?: string): ContentFormat;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
import type { HeadingParentTracker } from '../classes/heading-parent-tracker.class.ts';
|
|
3
|
+
import type { MarkdownDraft } from '../typings/markdown-draft.interface.ts';
|
|
4
|
+
/**
|
|
5
|
+
* Appends `draft` to `sections`, resolving its parent index
|
|
6
|
+
* via `tracker`. An empty, titleless draft (no accumulated
|
|
7
|
+
* preamble) is skipped.
|
|
8
|
+
*
|
|
9
|
+
* @param draft - accumulated section awaiting output
|
|
10
|
+
* @param sections - output array to append to, mutated in
|
|
11
|
+
* place
|
|
12
|
+
* @param tracker - depth stack shared across a single split
|
|
13
|
+
*/
|
|
14
|
+
export declare function flushMarkdownDraft(draft: MarkdownDraft, sections: ContentSection[], tracker: HeadingParentTracker): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
import type { TomlDraft } from '../typings/toml-draft.interface.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Appends `draft` to `sections`, resolving its parent index
|
|
5
|
+
* via `pathIndex`. An empty, titleless draft (no accumulated
|
|
6
|
+
* preamble) is skipped. Registers titled drafts in
|
|
7
|
+
* `pathIndex` so later dotted headers can nest under them.
|
|
8
|
+
*
|
|
9
|
+
* @param draft - accumulated section awaiting output
|
|
10
|
+
* @param sections - output array to append to, mutated in
|
|
11
|
+
* place
|
|
12
|
+
* @param pathIndex - lookup from header path to output index,
|
|
13
|
+
* mutated in place
|
|
14
|
+
*/
|
|
15
|
+
export declare function flushTomlDraft(draft: TomlDraft, sections: ContentSection[], pathIndex: Map<string, number>): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
import type { HeadingParentTracker } from '../classes/heading-parent-tracker.class.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Appends a section to `sections`, resolving its
|
|
5
|
+
* `parentIndex` via `tracker` when it carries a heading
|
|
6
|
+
* `level`. Shared by depth-nested splitters (markdown, HTML)
|
|
7
|
+
* so nesting logic is defined once.
|
|
8
|
+
*
|
|
9
|
+
* @param sections - output array to append to, mutated in
|
|
10
|
+
* place
|
|
11
|
+
* @param tracker - depth stack shared across a single split
|
|
12
|
+
* @param content - section body content
|
|
13
|
+
* @param title - heading text, omitted for root content
|
|
14
|
+
* @param level - heading depth, omitted for root content
|
|
15
|
+
*/
|
|
16
|
+
export declare function pushContentSection(sections: ContentSection[], tracker: HeadingParentTracker, content: string, title?: string, level?: number): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves each section's `parentIndex` to the KBDB id of the
|
|
4
|
+
* section that was stored at that index. Used after sections
|
|
5
|
+
* have been persisted in order, to link children to parents.
|
|
6
|
+
*
|
|
7
|
+
* @param sections - split sections, in the same order as
|
|
8
|
+
* `kbids`
|
|
9
|
+
* @param kbids - persisted section ids, one per `sections`
|
|
10
|
+
* entry
|
|
11
|
+
* @returns one parent id per section, or `null` for
|
|
12
|
+
* root-level sections
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveParentIds(sections: readonly ContentSection[], kbids: readonly string[]): (string | null)[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SplitResult } from '../typings/split-result.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Splits `content` into sections using the strategy matching
|
|
4
|
+
* its detected format. Detection prefers `typeHint`, then
|
|
5
|
+
* `filePath`'s extension, then sniffs the content itself.
|
|
6
|
+
*
|
|
7
|
+
* @param content - raw document text
|
|
8
|
+
* @param typeHint - explicit MIME type or short-form hint
|
|
9
|
+
* @param filePath - source file path used to infer format
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitContent(content: string, typeHint?: string, filePath?: string): SplitResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Splits HTML content into sections on `<h1>` through `<h6>`
|
|
4
|
+
* tag boundaries, using regex matching rather than DOM
|
|
5
|
+
* parsing. Each heading section's `parentIndex` points to the
|
|
6
|
+
* nearest enclosing heading of a shallower depth.
|
|
7
|
+
*
|
|
8
|
+
* @param content - raw HTML document text
|
|
9
|
+
* @returns sections in document order, trailing whitespace
|
|
10
|
+
* trimmed from each section's body
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitHtml(content: string): ContentSection[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Splits markdown content into sections on ATX heading
|
|
4
|
+
* boundaries (`# Title` through `###### Title`). Headings
|
|
5
|
+
* inside fenced code blocks are treated as plain text. Each
|
|
6
|
+
* heading section's `parentIndex` points to the nearest
|
|
7
|
+
* enclosing heading of a shallower depth.
|
|
8
|
+
*
|
|
9
|
+
* @param content - raw markdown document text
|
|
10
|
+
* @returns sections in document order, trailing whitespace
|
|
11
|
+
* trimmed from each section's body
|
|
12
|
+
*/
|
|
13
|
+
export declare function splitMarkdown(content: string): ContentSection[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Passthrough splitter for unrecognized content formats.
|
|
4
|
+
* Wraps the entire input in a single root-level section.
|
|
5
|
+
*
|
|
6
|
+
* @param content - raw document text
|
|
7
|
+
*/
|
|
8
|
+
export declare function splitPlainText(content: string): ContentSection[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ContentSection } from '../typings/content-section.interface.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Splits TOML content into sections on `[table]` header
|
|
4
|
+
* boundaries. A dotted header (`[a.b]`) nests under the
|
|
5
|
+
* section matching its prefix (`[a]`); an undotted or quoted
|
|
6
|
+
* header is a root-level section.
|
|
7
|
+
*
|
|
8
|
+
* @param content - raw TOML document text
|
|
9
|
+
* @returns sections in document order, trailing whitespace
|
|
10
|
+
* trimmed from each section's body
|
|
11
|
+
*/
|
|
12
|
+
export declare function splitToml(content: string): ContentSection[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { splitContent } from './functions/split-content.function.ts';
|
|
2
|
+
export { splitMarkdown } from './functions/split-markdown.function.ts';
|
|
3
|
+
export { splitHtml } from './functions/split-html.function.ts';
|
|
4
|
+
export { splitToml } from './functions/split-toml.function.ts';
|
|
5
|
+
export { splitPlainText } from './functions/split-plain-text.function.ts';
|
|
6
|
+
export { detectContentType } from './functions/detect-content-type.function.ts';
|
|
7
|
+
export { resolveParentIds } from './functions/resolve-parent-ids.function.ts';
|
|
8
|
+
export type { ContentSection } from './typings/content-section.interface.ts';
|
|
9
|
+
export type { SplitResult } from './typings/split-result.interface.ts';
|
|
10
|
+
export type { SplitStrategy } from './typings/split-strategy.interface.ts';
|
|
11
|
+
export type { ContentFormat } from './typings/content-format.type.ts';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A section produced by a content splitter.
|
|
3
|
+
* Depth-first ordered within the document.
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentSection {
|
|
6
|
+
/** Section heading text, if any. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Heading depth (1-6), if detected. */
|
|
9
|
+
level?: number;
|
|
10
|
+
/** Section body content. */
|
|
11
|
+
content: string;
|
|
12
|
+
/**
|
|
13
|
+
* Index of the parent section in the output
|
|
14
|
+
* array, or `null` for root-level sections.
|
|
15
|
+
*/
|
|
16
|
+
parentIndex: number | null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-progress markdown section accumulated while scanning
|
|
3
|
+
* document lines, before it is flushed into a `ContentSection`.
|
|
4
|
+
*/
|
|
5
|
+
export interface MarkdownDraft {
|
|
6
|
+
/** Heading text, omitted while accumulating preamble. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** Heading depth (1-6), omitted while accumulating preamble. */
|
|
9
|
+
level?: number;
|
|
10
|
+
/** Body lines collected since the last heading. */
|
|
11
|
+
lines: string[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ContentSection } from './content-section.interface.ts';
|
|
2
|
+
/** Result of splitting content by format. */
|
|
3
|
+
export interface SplitResult {
|
|
4
|
+
/** Extracted sections, depth-first ordered. */
|
|
5
|
+
sections: ContentSection[];
|
|
6
|
+
/** Detected content format identifier. */
|
|
7
|
+
format: string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-progress TOML section accumulated while scanning
|
|
3
|
+
* document lines, before it is flushed into a `ContentSection`.
|
|
4
|
+
*/
|
|
5
|
+
export interface TomlDraft {
|
|
6
|
+
/** Header text, omitted while accumulating preamble. */
|
|
7
|
+
title?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Header text used for dotted-parent lookup, identical to
|
|
10
|
+
* `title` unless the header is quoted.
|
|
11
|
+
*/
|
|
12
|
+
path?: string;
|
|
13
|
+
/** Body lines collected since the last header. */
|
|
14
|
+
lines: string[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AddSectionResult, NearDuplicateEntry } from '../../worker-client/typings/add-section-result.model.ts';
|
|
2
|
+
/** JSON-serializable result envelope returned by the `learn` tool. */
|
|
3
|
+
export interface LearnPayload {
|
|
4
|
+
/** Knowledge-base identifiers of all stored sections. */
|
|
5
|
+
readonly items: string[];
|
|
6
|
+
/** Number of items in the result set. */
|
|
7
|
+
readonly total: number;
|
|
8
|
+
/** Offset into the result set (always 0 for learn). */
|
|
9
|
+
readonly offset: number;
|
|
10
|
+
/** Kbid of a superseded section, or `null` if none. */
|
|
11
|
+
readonly superseded: string | null;
|
|
12
|
+
/** Advisory warnings emitted during indexing. */
|
|
13
|
+
readonly warnings: string[];
|
|
14
|
+
/** Near-duplicate sections detected above the threshold. */
|
|
15
|
+
readonly near_duplicates: NearDuplicateEntry[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes an `AddSectionResult` into the `learn` tool's JSON
|
|
19
|
+
* result envelope, defaulting optional fields to their empty
|
|
20
|
+
* representation.
|
|
21
|
+
*
|
|
22
|
+
* @param result - the raw result from storing one or more sections
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildLearnPayload(result: AddSectionResult): LearnPayload;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SplitResult } from '../../content-splitter/index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Determines whether `learn` content should be imported as
|
|
4
|
+
* multiple linked sections instead of one, and returns the split
|
|
5
|
+
* result when it should.
|
|
6
|
+
*
|
|
7
|
+
* Splitting applies only when no explicit `title` is given, the
|
|
8
|
+
* section type is a splittable text format (`text/*` or the bare
|
|
9
|
+
* `'markdown'` alias), and splitting produces at least two
|
|
10
|
+
* sections with at least one heading title.
|
|
11
|
+
*
|
|
12
|
+
* @param content - raw content to evaluate for splitting
|
|
13
|
+
* @param sectionType - the section's semantic type label
|
|
14
|
+
* @param title - explicit title from the caller, if any
|
|
15
|
+
* @returns the split result when splitting should apply,
|
|
16
|
+
* otherwise `undefined`
|
|
17
|
+
*/
|
|
18
|
+
export declare function determineLearnSplit(content: string, sectionType: string, title: string | undefined): SplitResult | undefined;
|
|
@@ -4,7 +4,9 @@ import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
|
|
|
4
4
|
* Handles the `learn` MCP tool call.
|
|
5
5
|
*
|
|
6
6
|
* Validates that image content includes a title, then imports the
|
|
7
|
-
* content into the knowledge base via the worker client.
|
|
7
|
+
* content into the knowledge base via the worker client. Text
|
|
8
|
+
* content without an explicit title is automatically split into
|
|
9
|
+
* linked sections when it contains multiple headings.
|
|
8
10
|
*
|
|
9
11
|
* @param client - the worker client used to execute operations
|
|
10
12
|
* @param args - tool arguments from the MCP request
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
import type { LearnSectionParams } from '../typings/learn-section-params.interface.ts';
|
|
3
|
+
import type { SplitResult } from '../../content-splitter/index.ts';
|
|
4
|
+
/** Result of storing a split document's sections. */
|
|
5
|
+
export interface LearnWithSplittingResult {
|
|
6
|
+
/** Knowledge-base identifiers, one per stored section. */
|
|
7
|
+
readonly kbids: string[];
|
|
8
|
+
/** Resolved title for the document these sections belong to. */
|
|
9
|
+
readonly docTitle: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Stores each section of a `splitContent` result as a separate
|
|
13
|
+
* knowledge-base section, in depth-first order. Every section
|
|
14
|
+
* shares a single `docid`, and each child section is linked to
|
|
15
|
+
* its parent via the kbid assigned when that parent was stored.
|
|
16
|
+
*
|
|
17
|
+
* @param client - the worker client used to store sections
|
|
18
|
+
* @param splitResult - depth-first ordered sections to persist
|
|
19
|
+
* @param params - metadata shared across all stored sections
|
|
20
|
+
* @returns the persisted kbids and the resolved document title
|
|
21
|
+
*/
|
|
22
|
+
export declare function learnWithSplitting(client: McpWorkerClient, splitResult: SplitResult, params: LearnSectionParams): Promise<LearnWithSplittingResult>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Parsed and type-narrowed arguments for the `learn` tool call. */
|
|
2
|
+
export interface LearnArgs {
|
|
3
|
+
/** Section type, defaulting to `'text/markdown'`. */
|
|
4
|
+
readonly sectionType: string;
|
|
5
|
+
/** Explicit section title, if provided. */
|
|
6
|
+
readonly title?: string;
|
|
7
|
+
/** Optional section description. */
|
|
8
|
+
readonly description?: string;
|
|
9
|
+
/** Optional shared document ID. */
|
|
10
|
+
readonly docid?: string;
|
|
11
|
+
/** Optional tags for scoping and filtering. */
|
|
12
|
+
readonly tags?: string[];
|
|
13
|
+
/** Whether to replace an existing section (supersession). */
|
|
14
|
+
readonly replace?: boolean;
|
|
15
|
+
/** Optional hierarchical level (1-6). */
|
|
16
|
+
readonly level?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Narrows the raw `learn` tool call arguments into typed fields,
|
|
20
|
+
* applying `'text/markdown'` as the default section type.
|
|
21
|
+
*
|
|
22
|
+
* @param args - tool arguments from the MCP request
|
|
23
|
+
*/
|
|
24
|
+
export declare function parseLearnArgs(args: Record<string, unknown>): LearnArgs;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
+
import type { LearnSectionParams } from '../typings/learn-section-params.interface.ts';
|
|
3
|
+
import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
|
|
4
|
+
import type { SplitResult } from '../../content-splitter/index.ts';
|
|
5
|
+
/**
|
|
6
|
+
* Stores a split document's sections and groups them under a
|
|
7
|
+
* shared document manifest, returning the same result envelope
|
|
8
|
+
* shape as a single-section `learn` call.
|
|
9
|
+
*
|
|
10
|
+
* @param client - the worker client used to store and group
|
|
11
|
+
* sections
|
|
12
|
+
* @param splitResult - depth-first ordered sections to persist
|
|
13
|
+
* @param params - metadata shared across all stored sections
|
|
14
|
+
* @returns a learn-result envelope listing every stored kbid
|
|
15
|
+
*/
|
|
16
|
+
export declare function storeSplitLearnSections(client: McpWorkerClient, splitResult: SplitResult, params: LearnSectionParams): Promise<AddSectionResult>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unwraps content that AI clients accidentally wrap in a JSON
|
|
3
|
+
* object. If the string starts with `{` and parses as JSON with
|
|
4
|
+
* a `content` or `text` field, returns that inner field value.
|
|
5
|
+
* Otherwise returns the original string.
|
|
6
|
+
*
|
|
7
|
+
* @param raw - the raw content string from a tool call argument
|
|
8
|
+
*/
|
|
9
|
+
export declare function unwrapJsonContent(raw: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata shared across every section stored for a single
|
|
3
|
+
* `learn` tool call, whether stored as one section or split
|
|
4
|
+
* into several linked sections.
|
|
5
|
+
*/
|
|
6
|
+
export interface LearnSectionParams {
|
|
7
|
+
/** Semantic type label applied to every stored section. */
|
|
8
|
+
readonly sectionType: string;
|
|
9
|
+
/** Optional description applied to every stored section. */
|
|
10
|
+
readonly description?: string;
|
|
11
|
+
/** Optional document ID shared by every stored section. */
|
|
12
|
+
readonly docid?: string;
|
|
13
|
+
/** Optional tags applied to every stored section. */
|
|
14
|
+
readonly tags?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* When `true`, replaces an existing section that has the same
|
|
17
|
+
* source key (supersession).
|
|
18
|
+
*/
|
|
19
|
+
readonly replace?: boolean;
|
|
20
|
+
}
|
|
@@ -144,6 +144,10 @@ export interface McpWorkerClient {
|
|
|
144
144
|
* source key (supersession).
|
|
145
145
|
*/
|
|
146
146
|
readonly replace?: boolean;
|
|
147
|
+
/** Hierarchical level (1-6). */
|
|
148
|
+
readonly level?: number;
|
|
149
|
+
/** Kbid of the parent section for nesting. */
|
|
150
|
+
readonly parent?: string;
|
|
147
151
|
}): Promise<AddSectionResult>;
|
|
148
152
|
/**
|
|
149
153
|
* Removes a section from the knowledge base.
|
|
@@ -84,6 +84,10 @@ export interface McpWorkerClient {
|
|
|
84
84
|
* source key (supersession).
|
|
85
85
|
*/
|
|
86
86
|
readonly replace?: boolean;
|
|
87
|
+
/** Hierarchical level (1-6). */
|
|
88
|
+
readonly level?: number;
|
|
89
|
+
/** Kbid of the parent section for nesting. */
|
|
90
|
+
readonly parent?: string;
|
|
87
91
|
}): Promise<AddSectionResult>;
|
|
88
92
|
/**
|
|
89
93
|
* Removes a section from the knowledge base.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Current package version, kept in sync with package.json. */
|
|
2
|
-
export declare const VERSION = "0.6.
|
|
2
|
+
export declare const VERSION = "0.6.5";
|
|
@@ -3,7 +3,8 @@ import type { RecallResult } from '../../worker-client/typings/recall-result.mod
|
|
|
3
3
|
/**
|
|
4
4
|
* Decodes a single `RecallResult` record from WASM binary output.
|
|
5
5
|
*
|
|
6
|
-
* Wire format: kbid, heading, section_type, content,
|
|
6
|
+
* Wire format: kbid, heading, section_type, content, level
|
|
7
|
+
* (Option<u8>), parent (Option<String>), docid list,
|
|
7
8
|
* document list, back_references list, siblings list,
|
|
8
9
|
* references list.
|
|
9
10
|
*
|
|
@@ -5,7 +5,8 @@ import type { RecallDocument } from '../../worker-client/typings/recall-result.m
|
|
|
5
5
|
*
|
|
6
6
|
* Wire format: docid (String), title (String), section_count (u32),
|
|
7
7
|
* then each section as kbid (String), heading (Option<String>),
|
|
8
|
-
* section_type (String)
|
|
8
|
+
* section_type (String), level (Option<u8>), parent
|
|
9
|
+
* (Option<String>).
|
|
9
10
|
*
|
|
10
11
|
* @param bytes - raw binary buffer
|
|
11
12
|
* @param offset - byte position of the record start
|
|
@@ -14,6 +14,8 @@ import type { RecallResult } from '../../worker-client/typings/recall-result.mod
|
|
|
14
14
|
* Option<String> heading (0x00=null, 0x01 + String)
|
|
15
15
|
* String section_type
|
|
16
16
|
* String content
|
|
17
|
+
* Option<u8> level
|
|
18
|
+
* Option<String> parent
|
|
17
19
|
* u32 docids_count + String[] docids
|
|
18
20
|
* u32 documents_count + RecallDocument[]
|
|
19
21
|
* u32 back_references_count + RecallReference[]
|
|
@@ -4,7 +4,8 @@ import type { RecallSibling } from '../../worker-client/typings/recall-result.mo
|
|
|
4
4
|
* Decodes a single `RecallSibling` record from WASM binary output.
|
|
5
5
|
*
|
|
6
6
|
* Wire format: kbid (String), heading (Option<String>),
|
|
7
|
-
* section_type (String), content (String)
|
|
7
|
+
* section_type (String), content (String), level
|
|
8
|
+
* (Option<u8>), parent (Option<String>).
|
|
8
9
|
*
|
|
9
10
|
* @param bytes - raw binary buffer
|
|
10
11
|
* @param offset - byte position of the record start
|
|
@@ -28,6 +28,10 @@ export interface SectionMatch {
|
|
|
28
28
|
matched_fields: string[];
|
|
29
29
|
/** ISO 8601 creation timestamp of the section. */
|
|
30
30
|
created_at: string;
|
|
31
|
+
/** Heading level (1-6), or `null` when unset. */
|
|
32
|
+
level: number | null;
|
|
33
|
+
/** Kbid of the parent section, or `null`. */
|
|
34
|
+
parent: string | null;
|
|
31
35
|
}
|
|
32
36
|
/**
|
|
33
37
|
* Paginated search response envelope returned by the WASM engine.
|
|
@@ -71,5 +75,7 @@ export interface PagedSearchResult {
|
|
|
71
75
|
* - `matched_terms`: `u32` count + `String[]`
|
|
72
76
|
* - `matched_fields`: `u32` count + `String[]`
|
|
73
77
|
* - `created_at`: `String`
|
|
78
|
+
* - `level`: `Option<u8>`
|
|
79
|
+
* - `parent`: `Option<String>`
|
|
74
80
|
*/
|
|
75
81
|
export declare function decodePagedSearchResult(bytes: Uint8Array): PagedSearchResult;
|
|
@@ -6,7 +6,8 @@ import type { SectionMatch } from '../typings/section-match.model.ts';
|
|
|
6
6
|
* Wire format per item: kbid, heading (Option<String>),
|
|
7
7
|
* section_type, docids (u32 count + String[]), score (f32),
|
|
8
8
|
* confidence (f32), snippet, matched_terms (u32 + String[]),
|
|
9
|
-
* matched_fields (u32 + String[]), created_at
|
|
9
|
+
* matched_fields (u32 + String[]), created_at, level
|
|
10
|
+
* (Option<u8>), parent (Option<String>).
|
|
10
11
|
*
|
|
11
12
|
* @param bytes - raw binary buffer
|
|
12
13
|
* @param startOffset - byte position of the item start
|
|
@@ -67,6 +67,10 @@ export interface SectionRecord {
|
|
|
67
67
|
* Hierarchical level (1-6). `null` when not set.
|
|
68
68
|
*/
|
|
69
69
|
level?: number | null;
|
|
70
|
+
/**
|
|
71
|
+
* KBDB ID of the parent section for nesting. `null` for root.
|
|
72
|
+
*/
|
|
73
|
+
parent?: string | null;
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
72
76
|
* Decodes a list of `SectionRecord` values from WASM binary output.
|
|
@@ -15,5 +15,6 @@ import type { AddSectionInput } from '../typings/add-section-input.model.ts';
|
|
|
15
15
|
* - `tags`: `u32` count + each `String`
|
|
16
16
|
* - `replace`: `u8` (0 or 1)
|
|
17
17
|
* - `level`: `u8` flag + optional `u8` (`Option<u8>`)
|
|
18
|
+
* - `parent`: `u8` flag + optional `String`
|
|
18
19
|
*/
|
|
19
20
|
export declare function encodeAddSectionParams(params: AddSectionInput): Uint8Array;
|
|
@@ -28,4 +28,8 @@ export interface SectionMatch {
|
|
|
28
28
|
matched_fields: string[];
|
|
29
29
|
/** ISO 8601 creation timestamp of the section. */
|
|
30
30
|
created_at: string;
|
|
31
|
+
/** Heading level (1-6), or `null` when unset. */
|
|
32
|
+
level: number | null;
|
|
33
|
+
/** Kbid of the parent section, or `null`. */
|
|
34
|
+
parent: string | null;
|
|
31
35
|
}
|