@dikolab/kbdb 0.6.3 → 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 +681 -249
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +638 -206
- 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-markdown-document.function.d.ts +22 -0
- 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 +12 -0
- package/dist/src/shared/cli/functions/map-add-section-result.function.d.ts +12 -0
- package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +13 -9
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +10 -59
- package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +11 -7
- package/dist/src/shared/cli/functions/split-markdown-sections.function.d.ts +16 -0
- package/dist/src/shared/cli/typings/learn-client.interface.d.ts +16 -28
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +2 -0
- package/dist/src/shared/cli/typings/markdown-section.interface.d.ts +23 -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-agent-list.function.d.ts +11 -21
- package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +1 -15
- package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +3 -1
- package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +13 -3
- 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/query-filter/functions/matches-query.function.d.ts +17 -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/default-embedding/kbdb_default_embedding_bg.wasm +0 -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/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.mjs +49 -7
- package/dist/worker.mjs.map +4 -4
- package/package.json +1 -1
|
@@ -1,27 +1,17 @@
|
|
|
1
1
|
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
-
|
|
3
|
-
interface ToolContent {
|
|
4
|
-
/** Content type identifier, typically `'text'`. */
|
|
5
|
-
readonly type: string;
|
|
6
|
-
/** The text payload. */
|
|
7
|
-
readonly text: string;
|
|
8
|
-
}
|
|
9
|
-
/** Result returned by the agent-list tool handler. */
|
|
10
|
-
interface ToolCallResult {
|
|
11
|
-
/** One or more content items describing the result. */
|
|
12
|
-
readonly content: ToolContent[];
|
|
13
|
-
/** Set to `true` when the tool encountered an error. */
|
|
14
|
-
readonly isError?: boolean;
|
|
15
|
-
}
|
|
2
|
+
import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
|
|
16
3
|
/**
|
|
17
|
-
* Handles the `agent
|
|
4
|
+
* Handles the `agent-list` MCP tool call.
|
|
18
5
|
*
|
|
19
|
-
* Retrieves all documents with `doc_type: 'agent'
|
|
20
|
-
*
|
|
21
|
-
*
|
|
6
|
+
* Retrieves all documents with `doc_type: 'agent'`. When
|
|
7
|
+
* `args.query` is a non-empty string, results are filtered by a
|
|
8
|
+
* case-insensitive substring match against each agent's name or
|
|
9
|
+
* description before being returned.
|
|
22
10
|
*
|
|
23
11
|
* @param client - the worker client used to execute operations
|
|
24
|
-
* @
|
|
12
|
+
* @param args - tool arguments; a string `query` filters results
|
|
13
|
+
* by name or description
|
|
14
|
+
* @returns content items with a JSON envelope
|
|
15
|
+
* (`{ items, total, offset }`) of matching agent names
|
|
25
16
|
*/
|
|
26
|
-
export declare function handleAgentList(client: McpWorkerClient): Promise<ToolCallResult>;
|
|
27
|
-
export {};
|
|
17
|
+
export declare function handleAgentList(client: McpWorkerClient, args?: Record<string, unknown>): Promise<ToolCallResult>;
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
2
|
-
|
|
3
|
-
interface ToolContent {
|
|
4
|
-
/** Content type identifier, typically 'text'. */
|
|
5
|
-
readonly type: string;
|
|
6
|
-
/** The text payload. */
|
|
7
|
-
readonly text: string;
|
|
8
|
-
}
|
|
9
|
-
/** Result returned by a tool call handler. */
|
|
10
|
-
interface ToolCallResult {
|
|
11
|
-
/** One or more content items describing the result. */
|
|
12
|
-
readonly content: ToolContent[];
|
|
13
|
-
/** Set to `true` when the tool encountered an error. */
|
|
14
|
-
readonly isError?: boolean;
|
|
15
|
-
}
|
|
2
|
+
import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
|
|
16
3
|
/**
|
|
17
4
|
* Dispatches an MCP tool call to the appropriate knowledge-base
|
|
18
5
|
* operation and returns the result formatted as MCP content.
|
|
@@ -23,4 +10,3 @@ interface ToolCallResult {
|
|
|
23
10
|
* @returns content items with optional isError flag
|
|
24
11
|
*/
|
|
25
12
|
export declare function handleToolCall(client: McpWorkerClient, name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
|
|
26
|
-
export {};
|
|
@@ -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
|
|
@@ -3,9 +3,19 @@ import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
|
|
|
3
3
|
/**
|
|
4
4
|
* Handles the `skill-list` MCP tool call.
|
|
5
5
|
*
|
|
6
|
-
* Lists
|
|
7
|
-
*
|
|
6
|
+
* Lists skills stored in the knowledge base as a JSON envelope
|
|
7
|
+
* of matching skill names. When `args.query` is a non-empty
|
|
8
|
+
* string, results are filtered by a case-insensitive substring
|
|
9
|
+
* match against each skill's name or description.
|
|
10
|
+
*
|
|
11
|
+
* This handler is not currently wired into `handleToolCall`'s
|
|
12
|
+
* dispatch (see `handle-tool-call.function.ts`'s inline
|
|
13
|
+
* `handleSkillList`), but is kept behaviourally in sync with it.
|
|
8
14
|
*
|
|
9
15
|
* @param client - the worker client used to execute operations
|
|
16
|
+
* @param args - tool arguments; a string `query` filters results
|
|
17
|
+
* by name or description
|
|
18
|
+
* @returns content items with a JSON envelope
|
|
19
|
+
* (`{ items, total, offset }`) of matching skill names
|
|
10
20
|
*/
|
|
11
|
-
export declare function handleToolSkillList(client: McpWorkerClient): Promise<ToolCallResult>;
|
|
21
|
+
export declare function handleToolSkillList(client: McpWorkerClient, args?: Record<string, unknown>): Promise<ToolCallResult>;
|
|
@@ -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.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests whether any of the given fields contains `query` as a
|
|
3
|
+
* case-insensitive substring.
|
|
4
|
+
*
|
|
5
|
+
* Used to filter list results (skills, agents) against a
|
|
6
|
+
* free-text query built from CLI positional arguments or an MCP
|
|
7
|
+
* tool's `query` parameter. An empty `query` always matches,
|
|
8
|
+
* which lets callers filter unconditionally without a separate
|
|
9
|
+
* "no filter" branch. `null` and `undefined` fields never match
|
|
10
|
+
* a non-empty query.
|
|
11
|
+
*
|
|
12
|
+
* @param query - the substring to search for; matches
|
|
13
|
+
* everything when empty
|
|
14
|
+
* @param fields - candidate field values to search, in order
|
|
15
|
+
* @returns `true` when `query` is empty or found in any field
|
|
16
|
+
*/
|
|
17
|
+
export declare function matchesQuery(query: string, ...fields: readonly (string | null | undefined)[]): boolean;
|
|
@@ -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
|
}
|
|
@@ -27,6 +27,10 @@ export interface RecallDocument {
|
|
|
27
27
|
readonly heading: string | null;
|
|
28
28
|
/** Semantic type label for the section. */
|
|
29
29
|
readonly type: string;
|
|
30
|
+
/** Heading level (1-6), or `null`. */
|
|
31
|
+
readonly level?: number | null;
|
|
32
|
+
/** Kbid of the parent section, or `null`. */
|
|
33
|
+
readonly parent?: string | null;
|
|
30
34
|
}[];
|
|
31
35
|
}
|
|
32
36
|
/** A sibling section adjacent to the recalled section. */
|
|
@@ -39,6 +43,10 @@ export interface RecallSibling {
|
|
|
39
43
|
readonly type: string;
|
|
40
44
|
/** Full text content of the sibling section. */
|
|
41
45
|
readonly content: string;
|
|
46
|
+
/** Heading level (1-6), or `null`. */
|
|
47
|
+
readonly level?: number | null;
|
|
48
|
+
/** Kbid of the parent section, or `null`. */
|
|
49
|
+
readonly parent?: string | null;
|
|
42
50
|
}
|
|
43
51
|
/** A section that references or is referenced by the recalled section. */
|
|
44
52
|
export interface RecallReference {
|
|
@@ -65,6 +73,10 @@ export interface RecallResult {
|
|
|
65
73
|
readonly type: string;
|
|
66
74
|
/** Full text content of the section. */
|
|
67
75
|
readonly content: string;
|
|
76
|
+
/** Heading level (1-6), or `null`. */
|
|
77
|
+
readonly level?: number | null;
|
|
78
|
+
/** Kbid of the parent section, or `null`. */
|
|
79
|
+
readonly parent?: string | null;
|
|
68
80
|
/** Identifiers of documents that contain this section. */
|
|
69
81
|
readonly docids: readonly string[];
|
|
70
82
|
/**
|
|
@@ -26,6 +26,10 @@ export interface SearchResult {
|
|
|
26
26
|
readonly confidence?: number;
|
|
27
27
|
/** ISO 8601 creation timestamp of the section. */
|
|
28
28
|
readonly created_at?: string;
|
|
29
|
+
/** Heading level (1-6), or `null` when unset. */
|
|
30
|
+
readonly level?: number | null;
|
|
31
|
+
/** Kbid of the parent section, or `null`. */
|
|
32
|
+
readonly parent?: string | null;
|
|
29
33
|
}
|
|
30
34
|
/** Paginated search result envelope. */
|
|
31
35
|
export interface PagedSearchResult {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/worker.mjs
CHANGED
|
@@ -1006,6 +1006,7 @@ function encodeAddSectionParams(params) {
|
|
|
1006
1006
|
params.replace === true ? 1 : 0
|
|
1007
1007
|
]);
|
|
1008
1008
|
const levelBytes = params.level != null ? new Uint8Array([1, params.level]) : new Uint8Array([0]);
|
|
1009
|
+
const parentBytes = encodeOptionString(params.parent);
|
|
1009
1010
|
const parts = [
|
|
1010
1011
|
encodeSectionType(params.sectionType, params.mimeType),
|
|
1011
1012
|
encodeString(params.content),
|
|
@@ -1018,7 +1019,8 @@ function encodeAddSectionParams(params) {
|
|
|
1018
1019
|
tagsCountBytes,
|
|
1019
1020
|
...tagParts,
|
|
1020
1021
|
replaceByte,
|
|
1021
|
-
levelBytes
|
|
1022
|
+
levelBytes,
|
|
1023
|
+
parentBytes
|
|
1022
1024
|
];
|
|
1023
1025
|
const totalLen = parts.reduce((sum, p) => sum + p.length, 0);
|
|
1024
1026
|
const result = new Uint8Array(totalLen);
|
|
@@ -1156,6 +1158,15 @@ function decodeU64(bytes, offset) {
|
|
|
1156
1158
|
};
|
|
1157
1159
|
}
|
|
1158
1160
|
|
|
1161
|
+
// src/shared/wasm-codec/functions/decode-option-u8.function.ts
|
|
1162
|
+
function decodeOptionU8(bytes, offset) {
|
|
1163
|
+
const tag = bytes[offset];
|
|
1164
|
+
if (tag === 1) {
|
|
1165
|
+
return { value: bytes[offset + 1], bytesRead: 2 };
|
|
1166
|
+
}
|
|
1167
|
+
return { value: null, bytesRead: 1 };
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1159
1170
|
// src/shared/wasm-codec/functions/decode-scored-results.function.ts
|
|
1160
1171
|
function decodeOptionString(bytes, offset) {
|
|
1161
1172
|
const tag = bytes[offset];
|
|
@@ -1221,6 +1232,10 @@ function decodePagedSearchResult(bytes) {
|
|
|
1221
1232
|
}
|
|
1222
1233
|
const createdAt = decodeString(bytes, offset);
|
|
1223
1234
|
offset += createdAt.bytesRead;
|
|
1235
|
+
const optLevel = decodeOptionU8(bytes, offset);
|
|
1236
|
+
offset += optLevel.bytesRead;
|
|
1237
|
+
const optParent = decodeOptionString(bytes, offset);
|
|
1238
|
+
offset += optParent.bytesRead;
|
|
1224
1239
|
items.push({
|
|
1225
1240
|
kbid: kbid.value,
|
|
1226
1241
|
heading: heading.value,
|
|
@@ -1231,7 +1246,9 @@ function decodePagedSearchResult(bytes) {
|
|
|
1231
1246
|
snippet: snippet.value,
|
|
1232
1247
|
matched_terms,
|
|
1233
1248
|
matched_fields,
|
|
1234
|
-
created_at: createdAt.value
|
|
1249
|
+
created_at: createdAt.value,
|
|
1250
|
+
level: optLevel.value,
|
|
1251
|
+
parent: optParent.value
|
|
1235
1252
|
});
|
|
1236
1253
|
}
|
|
1237
1254
|
return {
|
|
@@ -1245,7 +1262,7 @@ function decodePagedSearchResult(bytes) {
|
|
|
1245
1262
|
}
|
|
1246
1263
|
|
|
1247
1264
|
// src/shared/wasm-codec/functions/decode-section-records.function.ts
|
|
1248
|
-
function
|
|
1265
|
+
function decodeOptionU82(bytes, offset) {
|
|
1249
1266
|
const tag = bytes[offset];
|
|
1250
1267
|
if (tag === 1) {
|
|
1251
1268
|
return { value: bytes[offset + 1], bytesRead: 2 };
|
|
@@ -1350,10 +1367,16 @@ function decodeSectionRecords(bytes) {
|
|
|
1350
1367
|
}
|
|
1351
1368
|
let level = null;
|
|
1352
1369
|
if (offset < bytes.length) {
|
|
1353
|
-
const v =
|
|
1370
|
+
const v = decodeOptionU82(bytes, offset);
|
|
1354
1371
|
offset += v.bytesRead;
|
|
1355
1372
|
level = v.value;
|
|
1356
1373
|
}
|
|
1374
|
+
let parent = null;
|
|
1375
|
+
if (offset < bytes.length) {
|
|
1376
|
+
const v = decodeOptionString2(bytes, offset);
|
|
1377
|
+
offset += v.bytesRead;
|
|
1378
|
+
parent = v.value;
|
|
1379
|
+
}
|
|
1357
1380
|
const record = {
|
|
1358
1381
|
kbid: kbid.value,
|
|
1359
1382
|
docid: docid.value,
|
|
@@ -1375,7 +1398,8 @@ function decodeSectionRecords(bytes) {
|
|
|
1375
1398
|
updatedAt,
|
|
1376
1399
|
tags,
|
|
1377
1400
|
supersedes,
|
|
1378
|
-
level
|
|
1401
|
+
level,
|
|
1402
|
+
parent
|
|
1379
1403
|
};
|
|
1380
1404
|
if (st.mimeType !== void 0) {
|
|
1381
1405
|
record.mimeType = st.mimeType;
|
|
@@ -1588,12 +1612,18 @@ function decodeSibling(bytes, offset) {
|
|
|
1588
1612
|
pos += sectionType.bytesRead;
|
|
1589
1613
|
const content = decodeString(bytes, pos);
|
|
1590
1614
|
pos += content.bytesRead;
|
|
1615
|
+
const optLevel = decodeOptionU8(bytes, pos);
|
|
1616
|
+
pos += optLevel.bytesRead;
|
|
1617
|
+
const optParent = decodeOptionString3(bytes, pos);
|
|
1618
|
+
pos += optParent.bytesRead;
|
|
1591
1619
|
return {
|
|
1592
1620
|
value: {
|
|
1593
1621
|
kbid: kbid.value,
|
|
1594
1622
|
heading: heading.value,
|
|
1595
1623
|
type: sectionType.value,
|
|
1596
|
-
content: content.value
|
|
1624
|
+
content: content.value,
|
|
1625
|
+
level: optLevel.value,
|
|
1626
|
+
parent: optParent.value
|
|
1597
1627
|
},
|
|
1598
1628
|
bytesRead: pos - offset
|
|
1599
1629
|
};
|
|
@@ -1614,10 +1644,16 @@ function decodeDocument(bytes, offset) {
|
|
|
1614
1644
|
pos += secHeading.bytesRead;
|
|
1615
1645
|
const secType = decodeString(bytes, pos);
|
|
1616
1646
|
pos += secType.bytesRead;
|
|
1647
|
+
const secLevel = decodeOptionU8(bytes, pos);
|
|
1648
|
+
pos += secLevel.bytesRead;
|
|
1649
|
+
const secParent = decodeOptionString3(bytes, pos);
|
|
1650
|
+
pos += secParent.bytesRead;
|
|
1617
1651
|
sections.push({
|
|
1618
1652
|
kbid: secKbid.value,
|
|
1619
1653
|
heading: secHeading.value,
|
|
1620
|
-
type: secType.value
|
|
1654
|
+
type: secType.value,
|
|
1655
|
+
level: secLevel.value,
|
|
1656
|
+
parent: secParent.value
|
|
1621
1657
|
});
|
|
1622
1658
|
}
|
|
1623
1659
|
return {
|
|
@@ -1639,6 +1675,10 @@ function decodeOneResult(bytes, startOffset) {
|
|
|
1639
1675
|
pos += sectionType.bytesRead;
|
|
1640
1676
|
const content = decodeString(bytes, pos);
|
|
1641
1677
|
pos += content.bytesRead;
|
|
1678
|
+
const optLevel = decodeOptionU8(bytes, pos);
|
|
1679
|
+
pos += optLevel.bytesRead;
|
|
1680
|
+
const optParent = decodeOptionString3(bytes, pos);
|
|
1681
|
+
pos += optParent.bytesRead;
|
|
1642
1682
|
const docidCount = decodeU32(bytes, pos);
|
|
1643
1683
|
pos += docidCount.bytesRead;
|
|
1644
1684
|
const docids = [];
|
|
@@ -1685,6 +1725,8 @@ function decodeOneResult(bytes, startOffset) {
|
|
|
1685
1725
|
heading: heading.value,
|
|
1686
1726
|
type: sectionType.value,
|
|
1687
1727
|
content: content.value,
|
|
1728
|
+
level: optLevel.value,
|
|
1729
|
+
parent: optParent.value,
|
|
1688
1730
|
docids,
|
|
1689
1731
|
documents,
|
|
1690
1732
|
back_references,
|