@workglow/knowledge-base 0.0.125 → 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ export * from "./common";
7
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,UAAU,CAAC"}
package/dist/browser.js CHANGED
@@ -342,7 +342,9 @@ var ChunkRecordArraySchema = {
342
342
  description: "Array of chunk records"
343
343
  };
344
344
  // src/chunk/ChunkVectorStorageSchema.ts
345
- import { TypedArraySchema } from "@workglow/util/schema";
345
+ import {
346
+ TypedArraySchema
347
+ } from "@workglow/util/schema";
346
348
  var ChunkVectorStorageSchema = {
347
349
  type: "object",
348
350
  properties: {
@@ -388,6 +390,18 @@ class Document {
388
390
  }
389
391
  static fromJSON(json, doc_id) {
390
392
  const obj = JSON.parse(json);
393
+ if (!obj || typeof obj !== "object") {
394
+ throw new Error("Document.fromJSON: expected a JSON object");
395
+ }
396
+ if (!obj.root || typeof obj.root !== "object" || !obj.root.kind) {
397
+ throw new Error("Document.fromJSON: missing or invalid 'root' node");
398
+ }
399
+ if (!obj.metadata || typeof obj.metadata !== "object" || typeof obj.metadata.title !== "string") {
400
+ throw new Error("Document.fromJSON: missing or invalid 'metadata' (requires 'title' string)");
401
+ }
402
+ if (obj.chunks !== undefined && !Array.isArray(obj.chunks)) {
403
+ throw new Error("Document.fromJSON: 'chunks' must be an array if present");
404
+ }
391
405
  return new Document(obj.root, obj.metadata, obj.chunks, doc_id);
392
406
  }
393
407
  }
@@ -524,6 +538,9 @@ class KnowledgeBase {
524
538
  async similaritySearch(query, options) {
525
539
  return this.chunkStorage.similaritySearch(query, options);
526
540
  }
541
+ supportsHybridSearch() {
542
+ return typeof this.chunkStorage.hybridSearch === "function";
543
+ }
527
544
  async hybridSearch(query, options) {
528
545
  if (typeof this.chunkStorage.hybridSearch !== "function") {
529
546
  throw new Error("Hybrid search is not supported by the configured chunk storage backend. " + "Please use a vector storage implementation that provides `hybridSearch`.");
@@ -700,7 +717,6 @@ function setGlobalKnowledgeBaseRepository(repository) {
700
717
  }
701
718
  async function registerKnowledgeBase(id, kb) {
702
719
  const kbs = getGlobalKnowledgeBases();
703
- kbs.set(id, kb);
704
720
  const now = new Date().toISOString();
705
721
  const tableNames = knowledgeBaseTableNames(id);
706
722
  const record = {
@@ -715,6 +731,7 @@ async function registerKnowledgeBase(id, kb) {
715
731
  };
716
732
  const repo = getGlobalKnowledgeBaseRepository();
717
733
  await repo.addKnowledgeBase(record);
734
+ kbs.set(id, kb);
718
735
  }
719
736
  function getKnowledgeBase(id) {
720
737
  return getGlobalKnowledgeBases().get(id);
@@ -767,6 +784,12 @@ async function createKnowledgeBase(options) {
767
784
  title,
768
785
  description
769
786
  } = options;
787
+ if (!name || typeof name !== "string" || name.trim().length === 0) {
788
+ throw new Error("createKnowledgeBase: 'name' must be a non-empty string");
789
+ }
790
+ if (typeof vectorDimensions !== "number" || !Number.isInteger(vectorDimensions) || vectorDimensions < 1) {
791
+ throw new Error("createKnowledgeBase: 'vectorDimensions' must be a positive integer");
792
+ }
770
793
  const tabularStorage = new InMemoryTabularStorage2(DocumentStorageSchema, DocumentStorageKey);
771
794
  await tabularStorage.setupDatabase();
772
795
  const vectorStorage = new InMemoryVectorStorage(ChunkVectorStorageSchema, ChunkVectorPrimaryKey, [], vectorDimensions, vectorType);
@@ -815,24 +838,31 @@ function getChildren(node) {
815
838
  }
816
839
  return [];
817
840
  }
818
- function* traverseDepthFirst(node) {
841
+ var MAX_TRAVERSAL_DEPTH = 200;
842
+ function* traverseDepthFirst(node, depth = 0) {
843
+ if (depth > MAX_TRAVERSAL_DEPTH) {
844
+ throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);
845
+ }
819
846
  yield node;
820
847
  if (hasChildren(node)) {
821
848
  for (const child of node.children) {
822
- yield* traverseDepthFirst(child);
849
+ yield* traverseDepthFirst(child, depth + 1);
823
850
  }
824
851
  }
825
852
  }
826
853
  function getNodePath(root, targetNodeId) {
827
854
  const path = [];
828
- function search(node) {
855
+ function search(node, depth) {
856
+ if (depth > MAX_TRAVERSAL_DEPTH) {
857
+ throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);
858
+ }
829
859
  path.push(node.nodeId);
830
860
  if (node.nodeId === targetNodeId) {
831
861
  return true;
832
862
  }
833
863
  if (hasChildren(node)) {
834
864
  for (const child of node.children) {
835
- if (search(child)) {
865
+ if (search(child, depth + 1)) {
836
866
  return true;
837
867
  }
838
868
  }
@@ -840,7 +870,7 @@ function getNodePath(root, targetNodeId) {
840
870
  path.pop();
841
871
  return false;
842
872
  }
843
- return search(root) ? path : undefined;
873
+ return search(root, 0) ? path : undefined;
844
874
  }
845
875
  function getDocumentRange(root, nodePath) {
846
876
  let currentNode = root;
@@ -1068,4 +1098,4 @@ export {
1068
1098
  ChunkRecordArraySchema
1069
1099
  };
1070
1100
 
1071
- //# debugId=C250E01932058F3464756E2164756E21
1101
+ //# debugId=3CEA980CAC08F84F64756E2164756E21
@@ -4,20 +4,20 @@
4
4
  "sourcesContent": [
5
5
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DataPortSchema, FromSchema } from \"@workglow/util/schema\";\n\n/**\n * Node kind discriminator for hierarchical document structure\n */\nexport const NodeKind = {\n DOCUMENT: \"document\",\n SECTION: \"section\",\n PARAGRAPH: \"paragraph\",\n SENTENCE: \"sentence\",\n TOPIC: \"topic\",\n} as const;\n\nexport type NodeKind = (typeof NodeKind)[keyof typeof NodeKind];\n\n// =============================================================================\n// Schema Definitions\n// =============================================================================\n\n/**\n * Schema for source range of a node (character offsets)\n */\nexport const NodeRangeSchema = {\n type: \"object\",\n properties: {\n startOffset: {\n type: \"integer\",\n title: \"Start Offset\",\n description: \"Starting character offset\",\n },\n endOffset: {\n type: \"integer\",\n title: \"End Offset\",\n description: \"Ending character offset\",\n },\n },\n required: [\"startOffset\", \"endOffset\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\nexport type NodeRange = FromSchema<typeof NodeRangeSchema>;\n\n/**\n * Schema for named entity extracted from text\n */\nexport const EntitySchema = {\n type: \"object\",\n properties: {\n text: {\n type: \"string\",\n title: \"Text\",\n description: \"Entity text\",\n },\n type: {\n type: \"string\",\n title: \"Type\",\n description: \"Entity type (e.g., PERSON, ORG, LOC)\",\n },\n score: {\n type: \"number\",\n title: \"Score\",\n description: \"Confidence score\",\n },\n },\n required: [\"text\", \"type\", \"score\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\nexport type Entity = FromSchema<typeof EntitySchema>;\n\n/**\n * Schema for enrichment data attached to a node\n */\nexport const NodeEnrichmentSchema = {\n type: \"object\",\n properties: {\n summary: {\n type: \"string\",\n title: \"Summary\",\n description: \"Summary of the node content\",\n },\n entities: {\n type: \"array\",\n items: EntitySchema,\n title: \"Entities\",\n description: \"Named entities extracted from the node\",\n },\n keywords: {\n type: \"array\",\n items: { type: \"string\" },\n title: \"Keywords\",\n description: \"Keywords associated with the node\",\n },\n },\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\nexport type NodeEnrichment = FromSchema<typeof NodeEnrichmentSchema>;\n\n/**\n * Schema for base document node fields (used for runtime validation)\n * Note: Individual node types and DocumentNode union are defined as interfaces\n * below because FromSchema cannot properly infer recursive discriminated unions.\n */\nexport const DocumentNodeBaseSchema = {\n type: \"object\",\n properties: {\n nodeId: {\n type: \"string\",\n title: \"Node ID\",\n description: \"Unique identifier for this node\",\n },\n kind: {\n type: \"string\",\n enum: Object.values(NodeKind),\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n range: NodeRangeSchema,\n text: {\n type: \"string\",\n title: \"Text\",\n description: \"Text content of the node\",\n },\n enrichment: NodeEnrichmentSchema,\n },\n required: [\"nodeId\", \"kind\", \"range\", \"text\"],\n additionalProperties: true,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for document node (generic, for runtime validation)\n * This is a simplified schema for task input/output validation.\n * The actual TypeScript types use a proper discriminated union.\n */\nexport const DocumentNodeSchema = {\n type: \"object\",\n title: \"Document Node\",\n description: \"A node in the hierarchical document tree\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n level: {\n type: \"integer\",\n title: \"Level\",\n description: \"Header level for section nodes\",\n },\n title: {\n type: \"string\",\n title: \"Title\",\n description: \"Section title\",\n },\n children: {\n type: \"array\",\n title: \"Children\",\n description: \"Child nodes\",\n },\n },\n required: [...DocumentNodeBaseSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for paragraph node\n */\nexport const ParagraphNodeSchema = {\n type: \"object\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n kind: {\n type: \"string\",\n const: NodeKind.PARAGRAPH,\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n },\n required: [...DocumentNodeBaseSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for sentence node\n */\nexport const SentenceNodeSchema = {\n type: \"object\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n kind: {\n type: \"string\",\n const: NodeKind.SENTENCE,\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n },\n required: [...DocumentNodeBaseSchema.required],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for section node\n */\nexport const SectionNodeSchema = {\n type: \"object\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n kind: {\n type: \"string\",\n const: NodeKind.SECTION,\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n level: {\n type: \"integer\",\n minimum: 1,\n maximum: 6,\n title: \"Level\",\n description: \"Header level (1-6 for markdown)\",\n },\n title: {\n type: \"string\",\n title: \"Title\",\n description: \"Section title\",\n },\n children: {\n type: \"array\",\n items: DocumentNodeSchema,\n title: \"Children\",\n description: \"Child nodes\",\n },\n },\n required: [...DocumentNodeBaseSchema.required, \"level\", \"title\", \"children\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for topic node\n */\nexport const TopicNodeSchema = {\n type: \"object\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n kind: {\n type: \"string\",\n const: NodeKind.TOPIC,\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n children: {\n type: \"array\",\n items: DocumentNodeSchema,\n title: \"Children\",\n description: \"Child nodes\",\n },\n },\n required: [...DocumentNodeBaseSchema.required, \"children\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n/**\n * Schema for document root node\n */\nexport const DocumentRootNodeSchema = {\n type: \"object\",\n properties: {\n ...DocumentNodeBaseSchema.properties,\n kind: {\n type: \"string\",\n const: NodeKind.DOCUMENT,\n title: \"Kind\",\n description: \"Node type discriminator\",\n },\n title: {\n type: \"string\",\n title: \"Title\",\n description: \"Document title\",\n },\n children: {\n type: \"array\",\n items: DocumentNodeSchema,\n title: \"Children\",\n description: \"Child nodes\",\n },\n },\n required: [...DocumentNodeBaseSchema.required, \"title\", \"children\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\n// =============================================================================\n// Manually-defined interfaces for recursive discriminated union types\n// These provide better TypeScript inference than FromSchema for recursive types\n// =============================================================================\n\n/**\n * Base document node fields\n */\ninterface DocumentNodeBase {\n readonly nodeId: string;\n readonly kind: NodeKind;\n readonly range: NodeRange;\n readonly text: string;\n readonly enrichment?: NodeEnrichment;\n}\n\n/**\n * Document root node\n */\nexport interface DocumentRootNode extends DocumentNodeBase {\n readonly kind: typeof NodeKind.DOCUMENT;\n readonly title: string;\n readonly children: DocumentNode[];\n}\n\n/**\n * Section node (from markdown headers or structural divisions)\n */\nexport interface SectionNode extends DocumentNodeBase {\n readonly kind: typeof NodeKind.SECTION;\n readonly level: number;\n readonly title: string;\n readonly children: DocumentNode[];\n}\n\n/**\n * Paragraph node\n */\nexport interface ParagraphNode extends DocumentNodeBase {\n readonly kind: typeof NodeKind.PARAGRAPH;\n}\n\n/**\n * Sentence node (optional fine-grained segmentation)\n */\nexport interface SentenceNode extends DocumentNodeBase {\n readonly kind: typeof NodeKind.SENTENCE;\n}\n\n/**\n * Topic segment node (from TopicSegmenter)\n */\nexport interface TopicNode extends DocumentNodeBase {\n readonly kind: typeof NodeKind.TOPIC;\n readonly children: DocumentNode[];\n}\n\n/**\n * Discriminated union of all document node types\n */\nexport type DocumentNode =\n | DocumentRootNode\n | SectionNode\n | ParagraphNode\n | SentenceNode\n | TopicNode;\n\n// =============================================================================\n// Token Budget\n// =============================================================================\n\n/**\n * Schema for token budget configuration\n */\nexport const TokenBudgetSchema = {\n type: \"object\",\n properties: {\n maxTokensPerChunk: {\n type: \"integer\",\n title: \"Max Tokens Per Chunk\",\n description: \"Maximum tokens allowed per chunk\",\n },\n overlapTokens: {\n type: \"integer\",\n title: \"Overlap Tokens\",\n description: \"Number of tokens to overlap between chunks\",\n },\n reservedTokens: {\n type: \"integer\",\n title: \"Reserved Tokens\",\n description: \"Tokens reserved for metadata or context\",\n },\n },\n required: [\"maxTokensPerChunk\", \"overlapTokens\", \"reservedTokens\"],\n additionalProperties: false,\n} as const satisfies DataPortSchema;\n\nexport type TokenBudget = FromSchema<typeof TokenBudgetSchema>;\n\n// =============================================================================\n// Document Metadata\n// =============================================================================\n\n/**\n * Schema for document metadata\n */\nexport const DocumentMetadataSchema = {\n type: \"object\",\n properties: {\n title: {\n type: \"string\",\n title: \"Title\",\n description: \"Document title\",\n },\n sourceUri: {\n type: \"string\",\n title: \"Source URI\",\n description: \"Original source URI of the document\",\n },\n createdAt: {\n type: \"string\",\n title: \"Created At\",\n description: \"ISO timestamp of creation\",\n },\n },\n required: [\"title\"],\n additionalProperties: true,\n} as const satisfies DataPortSchema;\n\nexport type DocumentMetadata = FromSchema<typeof DocumentMetadataSchema>;\n",
6
6
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DataPortSchema, FromSchema, JsonSchema } from \"@workglow/util/schema\";\nimport { EntitySchema } from \"../document/DocumentSchema\";\n\n/**\n * Schema for a unified chunk record.\n * Replaces ChunkNode, ChunkMetadata, and EnrichedChunkMetadata with a single flat type.\n */\nexport const ChunkRecordSchema = () =>\n ({\n type: \"object\",\n properties: {\n chunkId: {\n type: \"string\",\n title: \"Chunk ID\",\n description: \"Unique identifier for this chunk\",\n },\n doc_id: {\n type: \"string\",\n title: \"Document ID\",\n description: \"ID of the parent document\",\n },\n text: {\n type: \"string\",\n title: \"Text\",\n description: \"Text content of the chunk\",\n },\n nodePath: {\n type: \"array\",\n items: { type: \"string\" },\n title: \"Node Path\",\n description: \"Node IDs from root to leaf\",\n },\n depth: {\n type: \"integer\",\n title: \"Depth\",\n description: \"Depth in the document tree\",\n },\n leafNodeId: {\n type: \"string\",\n title: \"Leaf Node ID\",\n description: \"ID of the leaf node this chunk belongs to\",\n },\n summary: {\n type: \"string\",\n title: \"Summary\",\n description: \"Summary of the chunk content\",\n },\n entities: {\n type: \"array\",\n items: EntitySchema,\n title: \"Entities\",\n description: \"Named entities extracted from the chunk\",\n },\n parentSummaries: {\n type: \"array\",\n items: { type: \"string\" },\n title: \"Parent Summaries\",\n description: \"Summaries from ancestor nodes\",\n },\n sectionTitles: {\n type: \"array\",\n items: { type: \"string\" },\n title: \"Section Titles\",\n description: \"Titles of ancestor section nodes\",\n },\n doc_title: {\n type: \"string\",\n title: \"Document Title\",\n description: \"Title of the parent document\",\n },\n },\n required: [\"chunkId\", \"doc_id\", \"text\", \"nodePath\", \"depth\"],\n additionalProperties: true,\n }) as const satisfies DataPortSchema;\n\nexport type ChunkRecord = FromSchema<ReturnType<typeof ChunkRecordSchema>>;\n\n/**\n * Schema for chunk record array (for use in task schemas)\n */\nexport const ChunkRecordArraySchema = {\n type: \"array\",\n items: ChunkRecordSchema(),\n title: \"Chunk Records\",\n description: \"Array of chunk records\",\n} as const satisfies JsonSchema;\n",
7
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { IVectorStorage } from \"@workglow/storage\";\nimport { TypedArraySchema, type DataPortSchemaObject, type TypedArray } from \"@workglow/util/schema\";\nimport type { ChunkRecord } from \"./ChunkSchema\";\n\n/**\n * Schema for chunk vector storage with typed metadata.\n * Replaces DocumentChunkSchema with ChunkRecord as the metadata type.\n */\nexport const ChunkVectorStorageSchema = {\n type: \"object\",\n properties: {\n chunk_id: { type: \"string\", \"x-auto-generated\": true },\n doc_id: { type: \"string\" },\n vector: TypedArraySchema(),\n metadata: { type: \"object\", format: \"metadata\", additionalProperties: true },\n },\n required: [\"chunk_id\", \"doc_id\", \"vector\", \"metadata\"],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\nexport type ChunkVectorStorageSchema = typeof ChunkVectorStorageSchema;\n\nexport const ChunkVectorPrimaryKey = [\"chunk_id\"] as const;\nexport type ChunkVectorPrimaryKey = typeof ChunkVectorPrimaryKey;\n\nexport interface ChunkVectorEntity<\n Metadata extends ChunkRecord = ChunkRecord,\n Vector extends TypedArray = TypedArray,\n> {\n chunk_id: string;\n doc_id: string;\n vector: Vector;\n metadata: Metadata;\n}\n\n/**\n * Type for inserting chunk vectors - chunk_id is optional (auto-generated)\n */\nexport type InsertChunkVectorEntity<\n Metadata extends ChunkRecord = ChunkRecord,\n Vector extends TypedArray = TypedArray,\n> = Omit<ChunkVectorEntity<Metadata, Vector>, \"chunk_id\"> &\n Partial<Pick<ChunkVectorEntity<Metadata, Vector>, \"chunk_id\">>;\n\n/**\n * Type for the primary key of chunk vectors\n */\nexport type ChunkVectorKey = { chunk_id: string };\n\nexport type ChunkVectorStorage = IVectorStorage<\n ChunkRecord,\n typeof ChunkVectorStorageSchema,\n ChunkVectorEntity,\n ChunkVectorPrimaryKey\n>;\n\n/**\n * Search result with score\n */\nexport type ChunkSearchResult = ChunkVectorEntity & { score: number };\n",
8
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ChunkRecord } from \"../chunk/ChunkSchema\";\nimport type { DocumentMetadata, DocumentNode } from \"./DocumentSchema\";\n\n/**\n * Document represents a hierarchical document with chunks\n *\n * Key features:\n * - Single source-of-truth tree structure (root node)\n * - Single set of chunks\n * - Separate persistence for document structure vs vectors\n */\nexport class Document {\n public doc_id: string | undefined;\n public readonly metadata: DocumentMetadata;\n public readonly root: DocumentNode;\n private chunks: ChunkRecord[];\n\n constructor(\n root: DocumentNode,\n metadata: DocumentMetadata,\n chunks: ChunkRecord[] = [],\n doc_id?: string\n ) {\n this.doc_id = doc_id;\n this.root = root;\n this.metadata = metadata;\n this.chunks = chunks || [];\n }\n\n /**\n * Set chunks for the document\n */\n setChunks(chunks: ChunkRecord[]): void {\n this.chunks = chunks;\n }\n\n /**\n * Get all chunks\n */\n getChunks(): ChunkRecord[] {\n return this.chunks;\n }\n\n /**\n * Set the document ID\n */\n setDocId(doc_id: string): void {\n this.doc_id = doc_id;\n }\n\n /**\n * Find chunks by nodeId\n */\n findChunksByNodeId(nodeId: string): ChunkRecord[] {\n return this.chunks.filter((chunk) => chunk.nodePath.includes(nodeId));\n }\n\n /**\n * Serialize to JSON\n */\n toJSON(): {\n metadata: DocumentMetadata;\n root: DocumentNode;\n chunks: ChunkRecord[];\n } {\n return {\n metadata: this.metadata,\n root: this.root,\n chunks: this.chunks,\n };\n }\n\n /**\n * Deserialize from JSON\n */\n static fromJSON(json: string, doc_id?: string): Document {\n const obj = JSON.parse(json);\n return new Document(obj.root, obj.metadata, obj.chunks, doc_id);\n }\n}\n",
9
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HybridSearchOptions, VectorSearchOptions } from \"@workglow/storage\";\nimport type { TypedArray } from \"@workglow/util/schema\";\nimport type { ChunkRecord } from \"../chunk/ChunkSchema\";\nimport type {\n ChunkSearchResult,\n ChunkVectorEntity,\n ChunkVectorStorage,\n InsertChunkVectorEntity,\n} from \"../chunk/ChunkVectorStorageSchema\";\nimport { Document } from \"../document/Document\";\nimport type { DocumentNode } from \"../document/DocumentSchema\";\nimport type {\n DocumentStorageEntity,\n DocumentTabularStorage,\n InsertDocumentStorageEntity,\n} from \"../document/DocumentStorageSchema\";\n\n/**\n * Unified KnowledgeBase that owns both document and vector storage,\n * providing lifecycle management and cascading deletes.\n */\nexport class KnowledgeBase {\n readonly name: string;\n readonly title: string;\n readonly description: string;\n private tabularStorage: DocumentTabularStorage;\n private chunkStorage: ChunkVectorStorage;\n\n constructor(\n name: string,\n documentStorage: DocumentTabularStorage,\n chunkStorage: ChunkVectorStorage,\n title?: string,\n description?: string\n ) {\n this.name = name;\n this.title = title ?? name;\n this.description = description ?? \"\";\n this.tabularStorage = documentStorage;\n this.chunkStorage = chunkStorage;\n }\n\n // ===========================================================================\n // Document CRUD\n // ===========================================================================\n\n /**\n * Upsert a document.\n * @returns The document with the generated doc_id if it was auto-generated\n */\n async upsertDocument(document: Document): Promise<Document> {\n const serialized = JSON.stringify(document.toJSON());\n\n const insertEntity: InsertDocumentStorageEntity = {\n doc_id: document.doc_id,\n data: serialized,\n };\n const entity = await this.tabularStorage.put(insertEntity);\n\n if (document.doc_id !== entity.doc_id) {\n document.setDocId(entity.doc_id);\n }\n return document;\n }\n\n /**\n * Get a document by ID\n */\n async getDocument(doc_id: string): Promise<Document | undefined> {\n const entity = await this.tabularStorage.get({ doc_id });\n if (!entity) {\n return undefined;\n }\n return Document.fromJSON(entity.data, entity.doc_id);\n }\n\n /**\n * Delete a document and all its chunks (cascading delete).\n */\n async deleteDocument(doc_id: string): Promise<void> {\n await this.deleteChunksForDocument(doc_id);\n await this.tabularStorage.delete({ doc_id });\n }\n\n /**\n * List all document IDs\n */\n async listDocuments(): Promise<string[]> {\n const entities = await this.tabularStorage.getAll();\n if (!entities) {\n return [];\n }\n return entities.map((e: DocumentStorageEntity) => e.doc_id);\n }\n\n // ===========================================================================\n // Tree traversal\n // ===========================================================================\n\n /**\n * Get a specific node by ID from a document\n */\n async getNode(doc_id: string, nodeId: string): Promise<DocumentNode | undefined> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return undefined;\n }\n\n const traverse = (node: DocumentNode): DocumentNode | undefined => {\n if (node.nodeId === nodeId) {\n return node;\n }\n if (\"children\" in node && Array.isArray(node.children)) {\n for (const child of node.children) {\n const found = traverse(child);\n if (found) return found;\n }\n }\n return undefined;\n };\n\n return traverse(doc.root);\n }\n\n /**\n * Get ancestors of a node (from root to target node)\n */\n async getAncestors(doc_id: string, nodeId: string): Promise<DocumentNode[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n\n const path: string[] = [];\n const findPath = (node: DocumentNode): boolean => {\n path.push(node.nodeId);\n if (node.nodeId === nodeId) {\n return true;\n }\n if (\"children\" in node && Array.isArray(node.children)) {\n for (const child of node.children) {\n if (findPath(child)) {\n return true;\n }\n }\n }\n path.pop();\n return false;\n };\n\n if (!findPath(doc.root)) {\n return [];\n }\n\n const ancestors: DocumentNode[] = [];\n let currentNode: DocumentNode = doc.root;\n ancestors.push(currentNode);\n\n for (let i = 1; i < path.length; i++) {\n const targetId = path[i];\n if (\"children\" in currentNode && Array.isArray(currentNode.children)) {\n const found = currentNode.children.find((child: DocumentNode) => child.nodeId === targetId);\n if (found) {\n currentNode = found;\n ancestors.push(currentNode);\n } else {\n break;\n }\n } else {\n break;\n }\n }\n\n return ancestors;\n }\n\n // ===========================================================================\n // Chunk CRUD\n // ===========================================================================\n\n /**\n * Upsert a single chunk vector entity\n */\n async upsertChunk(chunk: InsertChunkVectorEntity): Promise<ChunkVectorEntity> {\n if (chunk.vector.length !== this.getVectorDimensions()) {\n throw new Error(\n `Vector dimension mismatch: expected ${this.getVectorDimensions()}, got ${chunk.vector.length}.`\n );\n }\n return this.chunkStorage.put(chunk);\n }\n\n /**\n * Upsert multiple chunk vector entities\n */\n async upsertChunksBulk(chunks: InsertChunkVectorEntity[]): Promise<ChunkVectorEntity[]> {\n const expected = this.getVectorDimensions();\n for (const chunk of chunks) {\n if (chunk.vector.length !== expected) {\n throw new Error(\n `Vector dimension mismatch: expected ${expected}, got ${chunk.vector.length}.`\n );\n }\n }\n return this.chunkStorage.putBulk(chunks);\n }\n\n /**\n * Delete all chunks for a specific document\n */\n async deleteChunksForDocument(doc_id: string): Promise<void> {\n await this.chunkStorage.deleteSearch({ doc_id });\n }\n\n /**\n * Get all chunks for a specific document\n */\n async getChunksForDocument(doc_id: string): Promise<ChunkVectorEntity[]> {\n const results = await this.chunkStorage.query({ doc_id });\n return (results ?? []) as ChunkVectorEntity[];\n }\n\n // ===========================================================================\n // Search\n // ===========================================================================\n\n /**\n * Search for similar chunks using vector similarity\n */\n async similaritySearch(\n query: TypedArray,\n options?: VectorSearchOptions<ChunkRecord>\n ): Promise<ChunkSearchResult[]> {\n return this.chunkStorage.similaritySearch(query, options);\n }\n\n /**\n * Hybrid search combining vector similarity and full-text search\n */\n async hybridSearch(\n query: TypedArray,\n options: HybridSearchOptions<ChunkRecord>\n ): Promise<ChunkSearchResult[]> {\n if (typeof this.chunkStorage.hybridSearch !== \"function\") {\n throw new Error(\n \"Hybrid search is not supported by the configured chunk storage backend. \" +\n \"Please use a vector storage implementation that provides `hybridSearch`.\"\n );\n }\n return this.chunkStorage.hybridSearch(query, options);\n }\n\n // ===========================================================================\n // Lifecycle\n // ===========================================================================\n\n /**\n * Prepare a document for re-indexing: deletes all chunks but keeps the document.\n * @returns The document if found, undefined otherwise\n */\n async prepareReindex(doc_id: string): Promise<Document | undefined> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return undefined;\n }\n await this.deleteChunksForDocument(doc_id);\n return doc;\n }\n\n /**\n * Setup the underlying databases\n */\n async setupDatabase(): Promise<void> {\n await this.tabularStorage.setupDatabase();\n await this.chunkStorage.setupDatabase();\n }\n\n /**\n * Destroy storage instances\n */\n destroy(): void {\n this.tabularStorage.destroy();\n this.chunkStorage.destroy();\n }\n\n // ===========================================================================\n // Accessors\n // ===========================================================================\n\n /**\n * Get a chunk by ID\n */\n async getChunk(chunk_id: string): Promise<ChunkVectorEntity | undefined> {\n return this.chunkStorage.get({ chunk_id });\n }\n\n /**\n * Store a single chunk (alias for upsertChunk)\n */\n async put(chunk: InsertChunkVectorEntity): Promise<ChunkVectorEntity> {\n return this.chunkStorage.put(chunk);\n }\n\n /**\n * Store multiple chunks (alias for upsertChunksBulk)\n */\n async putBulk(chunks: InsertChunkVectorEntity[]): Promise<ChunkVectorEntity[]> {\n return this.chunkStorage.putBulk(chunks);\n }\n\n /**\n * Get all chunks\n */\n async getAllChunks(): Promise<ChunkVectorEntity[] | undefined> {\n return this.chunkStorage.getAll() as Promise<ChunkVectorEntity[] | undefined>;\n }\n\n /**\n * Get chunk count\n */\n async chunkCount(): Promise<number> {\n return this.chunkStorage.size();\n }\n\n /**\n * Clear all chunks\n */\n async clearChunks(): Promise<void> {\n return this.chunkStorage.deleteAll();\n }\n\n /**\n * Get vector dimensions\n */\n getVectorDimensions(): number {\n return this.chunkStorage.getVectorDimensions();\n }\n\n // ===========================================================================\n // Document chunk helpers\n // ===========================================================================\n\n /**\n * Get chunks from the document JSON (not from vector storage)\n */\n async getDocumentChunks(doc_id: string): Promise<ChunkRecord[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n return doc.getChunks();\n }\n\n /**\n * Find chunks in document JSON that contain a specific nodeId in their path\n */\n async findChunksByNodeId(doc_id: string, nodeId: string): Promise<ChunkRecord[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n return doc.findChunksByNodeId(nodeId);\n }\n}\n",
7
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { IVectorStorage } from \"@workglow/storage\";\nimport {\n TypedArraySchema,\n type DataPortSchemaObject,\n type TypedArray,\n} from \"@workglow/util/schema\";\nimport type { ChunkRecord } from \"./ChunkSchema\";\n\n/**\n * Schema for chunk vector storage with typed metadata.\n * Replaces DocumentChunkSchema with ChunkRecord as the metadata type.\n */\nexport const ChunkVectorStorageSchema = {\n type: \"object\",\n properties: {\n chunk_id: { type: \"string\", \"x-auto-generated\": true },\n doc_id: { type: \"string\" },\n vector: TypedArraySchema(),\n metadata: { type: \"object\", format: \"metadata\", additionalProperties: true },\n },\n required: [\"chunk_id\", \"doc_id\", \"vector\", \"metadata\"],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\nexport type ChunkVectorStorageSchema = typeof ChunkVectorStorageSchema;\n\nexport const ChunkVectorPrimaryKey = [\"chunk_id\"] as const;\nexport type ChunkVectorPrimaryKey = typeof ChunkVectorPrimaryKey;\n\nexport interface ChunkVectorEntity<\n Metadata extends ChunkRecord = ChunkRecord,\n Vector extends TypedArray = TypedArray,\n> {\n chunk_id: string;\n doc_id: string;\n vector: Vector;\n metadata: Metadata;\n}\n\n/**\n * Type for inserting chunk vectors - chunk_id is optional (auto-generated)\n */\nexport type InsertChunkVectorEntity<\n Metadata extends ChunkRecord = ChunkRecord,\n Vector extends TypedArray = TypedArray,\n> = Omit<ChunkVectorEntity<Metadata, Vector>, \"chunk_id\"> &\n Partial<Pick<ChunkVectorEntity<Metadata, Vector>, \"chunk_id\">>;\n\n/**\n * Type for the primary key of chunk vectors\n */\nexport type ChunkVectorKey = { chunk_id: string };\n\nexport type ChunkVectorStorage = IVectorStorage<\n ChunkRecord,\n typeof ChunkVectorStorageSchema,\n ChunkVectorEntity,\n ChunkVectorPrimaryKey\n>;\n\n/**\n * Search result with score\n */\nexport type ChunkSearchResult = ChunkVectorEntity & { score: number };\n",
8
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ChunkRecord } from \"../chunk/ChunkSchema\";\nimport type { DocumentMetadata, DocumentNode } from \"./DocumentSchema\";\n\n/**\n * Document represents a hierarchical document with chunks\n *\n * Key features:\n * - Single source-of-truth tree structure (root node)\n * - Single set of chunks\n * - Separate persistence for document structure vs vectors\n */\nexport class Document {\n public doc_id: string | undefined;\n public readonly metadata: DocumentMetadata;\n public readonly root: DocumentNode;\n private chunks: ChunkRecord[];\n\n constructor(\n root: DocumentNode,\n metadata: DocumentMetadata,\n chunks: ChunkRecord[] = [],\n doc_id?: string\n ) {\n this.doc_id = doc_id;\n this.root = root;\n this.metadata = metadata;\n this.chunks = chunks || [];\n }\n\n /**\n * Set chunks for the document\n */\n setChunks(chunks: ChunkRecord[]): void {\n this.chunks = chunks;\n }\n\n /**\n * Get all chunks\n */\n getChunks(): ChunkRecord[] {\n return this.chunks;\n }\n\n /**\n * Set the document ID\n */\n setDocId(doc_id: string): void {\n this.doc_id = doc_id;\n }\n\n /**\n * Find chunks by nodeId\n */\n findChunksByNodeId(nodeId: string): ChunkRecord[] {\n return this.chunks.filter((chunk) => chunk.nodePath.includes(nodeId));\n }\n\n /**\n * Serialize to JSON\n */\n toJSON(): {\n metadata: DocumentMetadata;\n root: DocumentNode;\n chunks: ChunkRecord[];\n } {\n return {\n metadata: this.metadata,\n root: this.root,\n chunks: this.chunks,\n };\n }\n\n /**\n * Deserialize from JSON\n */\n static fromJSON(json: string, doc_id?: string): Document {\n const obj = JSON.parse(json);\n if (!obj || typeof obj !== \"object\") {\n throw new Error(\"Document.fromJSON: expected a JSON object\");\n }\n if (!obj.root || typeof obj.root !== \"object\" || !obj.root.kind) {\n throw new Error(\"Document.fromJSON: missing or invalid 'root' node\");\n }\n if (!obj.metadata || typeof obj.metadata !== \"object\" || typeof obj.metadata.title !== \"string\") {\n throw new Error(\"Document.fromJSON: missing or invalid 'metadata' (requires 'title' string)\");\n }\n if (obj.chunks !== undefined && !Array.isArray(obj.chunks)) {\n throw new Error(\"Document.fromJSON: 'chunks' must be an array if present\");\n }\n return new Document(obj.root, obj.metadata, obj.chunks, doc_id);\n }\n}\n",
9
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { HybridSearchOptions, VectorSearchOptions } from \"@workglow/storage\";\nimport type { TypedArray } from \"@workglow/util/schema\";\nimport type { ChunkRecord } from \"../chunk/ChunkSchema\";\nimport type {\n ChunkSearchResult,\n ChunkVectorEntity,\n ChunkVectorStorage,\n InsertChunkVectorEntity,\n} from \"../chunk/ChunkVectorStorageSchema\";\nimport { Document } from \"../document/Document\";\nimport type { DocumentNode } from \"../document/DocumentSchema\";\nimport type {\n DocumentStorageEntity,\n DocumentTabularStorage,\n InsertDocumentStorageEntity,\n} from \"../document/DocumentStorageSchema\";\n\n/**\n * Unified KnowledgeBase that owns both document and vector storage,\n * providing lifecycle management and cascading deletes.\n */\nexport class KnowledgeBase {\n readonly name: string;\n readonly title: string;\n readonly description: string;\n private tabularStorage: DocumentTabularStorage;\n private chunkStorage: ChunkVectorStorage;\n\n constructor(\n name: string,\n documentStorage: DocumentTabularStorage,\n chunkStorage: ChunkVectorStorage,\n title?: string,\n description?: string\n ) {\n this.name = name;\n this.title = title ?? name;\n this.description = description ?? \"\";\n this.tabularStorage = documentStorage;\n this.chunkStorage = chunkStorage;\n }\n\n // ===========================================================================\n // Document CRUD\n // ===========================================================================\n\n /**\n * Upsert a document.\n * @returns The document with the generated doc_id if it was auto-generated\n */\n async upsertDocument(document: Document): Promise<Document> {\n const serialized = JSON.stringify(document.toJSON());\n\n const insertEntity: InsertDocumentStorageEntity = {\n doc_id: document.doc_id,\n data: serialized,\n };\n const entity = await this.tabularStorage.put(insertEntity);\n\n if (document.doc_id !== entity.doc_id) {\n document.setDocId(entity.doc_id);\n }\n return document;\n }\n\n /**\n * Get a document by ID\n */\n async getDocument(doc_id: string): Promise<Document | undefined> {\n const entity = await this.tabularStorage.get({ doc_id });\n if (!entity) {\n return undefined;\n }\n return Document.fromJSON(entity.data, entity.doc_id);\n }\n\n /**\n * Delete a document and all its chunks (cascading delete).\n */\n async deleteDocument(doc_id: string): Promise<void> {\n await this.deleteChunksForDocument(doc_id);\n await this.tabularStorage.delete({ doc_id });\n }\n\n /**\n * List all document IDs\n */\n async listDocuments(): Promise<string[]> {\n const entities = await this.tabularStorage.getAll();\n if (!entities) {\n return [];\n }\n return entities.map((e: DocumentStorageEntity) => e.doc_id);\n }\n\n // ===========================================================================\n // Tree traversal\n // ===========================================================================\n\n /**\n * Get a specific node by ID from a document\n */\n async getNode(doc_id: string, nodeId: string): Promise<DocumentNode | undefined> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return undefined;\n }\n\n const traverse = (node: DocumentNode): DocumentNode | undefined => {\n if (node.nodeId === nodeId) {\n return node;\n }\n if (\"children\" in node && Array.isArray(node.children)) {\n for (const child of node.children) {\n const found = traverse(child);\n if (found) return found;\n }\n }\n return undefined;\n };\n\n return traverse(doc.root);\n }\n\n /**\n * Get ancestors of a node (from root to target node)\n */\n async getAncestors(doc_id: string, nodeId: string): Promise<DocumentNode[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n\n const path: string[] = [];\n const findPath = (node: DocumentNode): boolean => {\n path.push(node.nodeId);\n if (node.nodeId === nodeId) {\n return true;\n }\n if (\"children\" in node && Array.isArray(node.children)) {\n for (const child of node.children) {\n if (findPath(child)) {\n return true;\n }\n }\n }\n path.pop();\n return false;\n };\n\n if (!findPath(doc.root)) {\n return [];\n }\n\n const ancestors: DocumentNode[] = [];\n let currentNode: DocumentNode = doc.root;\n ancestors.push(currentNode);\n\n for (let i = 1; i < path.length; i++) {\n const targetId = path[i];\n if (\"children\" in currentNode && Array.isArray(currentNode.children)) {\n const found = currentNode.children.find((child: DocumentNode) => child.nodeId === targetId);\n if (found) {\n currentNode = found;\n ancestors.push(currentNode);\n } else {\n break;\n }\n } else {\n break;\n }\n }\n\n return ancestors;\n }\n\n // ===========================================================================\n // Chunk CRUD\n // ===========================================================================\n\n /**\n * Upsert a single chunk vector entity\n */\n async upsertChunk(chunk: InsertChunkVectorEntity): Promise<ChunkVectorEntity> {\n if (chunk.vector.length !== this.getVectorDimensions()) {\n throw new Error(\n `Vector dimension mismatch: expected ${this.getVectorDimensions()}, got ${chunk.vector.length}.`\n );\n }\n return this.chunkStorage.put(chunk);\n }\n\n /**\n * Upsert multiple chunk vector entities\n */\n async upsertChunksBulk(chunks: InsertChunkVectorEntity[]): Promise<ChunkVectorEntity[]> {\n const expected = this.getVectorDimensions();\n for (const chunk of chunks) {\n if (chunk.vector.length !== expected) {\n throw new Error(\n `Vector dimension mismatch: expected ${expected}, got ${chunk.vector.length}.`\n );\n }\n }\n return this.chunkStorage.putBulk(chunks);\n }\n\n /**\n * Delete all chunks for a specific document\n */\n async deleteChunksForDocument(doc_id: string): Promise<void> {\n await this.chunkStorage.deleteSearch({ doc_id });\n }\n\n /**\n * Get all chunks for a specific document\n */\n async getChunksForDocument(doc_id: string): Promise<ChunkVectorEntity[]> {\n const results = await this.chunkStorage.query({ doc_id });\n return (results ?? []) as ChunkVectorEntity[];\n }\n\n // ===========================================================================\n // Search\n // ===========================================================================\n\n /**\n * Search for similar chunks using vector similarity\n */\n async similaritySearch(\n query: TypedArray,\n options?: VectorSearchOptions<ChunkRecord>\n ): Promise<ChunkSearchResult[]> {\n return this.chunkStorage.similaritySearch(query, options);\n }\n\n /**\n * Check if the configured storage backend supports hybrid search\n */\n supportsHybridSearch(): boolean {\n return typeof this.chunkStorage.hybridSearch === \"function\";\n }\n\n /**\n * Hybrid search combining vector similarity and full-text search\n */\n async hybridSearch(\n query: TypedArray,\n options: HybridSearchOptions<ChunkRecord>\n ): Promise<ChunkSearchResult[]> {\n if (typeof this.chunkStorage.hybridSearch !== \"function\") {\n throw new Error(\n \"Hybrid search is not supported by the configured chunk storage backend. \" +\n \"Please use a vector storage implementation that provides `hybridSearch`.\"\n );\n }\n return this.chunkStorage.hybridSearch(query, options);\n }\n\n // ===========================================================================\n // Lifecycle\n // ===========================================================================\n\n /**\n * Prepare a document for re-indexing: deletes all chunks but keeps the document.\n * @returns The document if found, undefined otherwise\n */\n async prepareReindex(doc_id: string): Promise<Document | undefined> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return undefined;\n }\n await this.deleteChunksForDocument(doc_id);\n return doc;\n }\n\n /**\n * Setup the underlying databases\n */\n async setupDatabase(): Promise<void> {\n await this.tabularStorage.setupDatabase();\n await this.chunkStorage.setupDatabase();\n }\n\n /**\n * Destroy storage instances\n */\n destroy(): void {\n this.tabularStorage.destroy();\n this.chunkStorage.destroy();\n }\n\n // ===========================================================================\n // Accessors\n // ===========================================================================\n\n /**\n * Get a chunk by ID\n */\n async getChunk(chunk_id: string): Promise<ChunkVectorEntity | undefined> {\n return this.chunkStorage.get({ chunk_id });\n }\n\n /**\n * Store a single chunk (alias for upsertChunk)\n */\n async put(chunk: InsertChunkVectorEntity): Promise<ChunkVectorEntity> {\n return this.chunkStorage.put(chunk);\n }\n\n /**\n * Store multiple chunks (alias for upsertChunksBulk)\n */\n async putBulk(chunks: InsertChunkVectorEntity[]): Promise<ChunkVectorEntity[]> {\n return this.chunkStorage.putBulk(chunks);\n }\n\n /**\n * Get all chunks\n */\n async getAllChunks(): Promise<ChunkVectorEntity[] | undefined> {\n return this.chunkStorage.getAll() as Promise<ChunkVectorEntity[] | undefined>;\n }\n\n /**\n * Get chunk count\n */\n async chunkCount(): Promise<number> {\n return this.chunkStorage.size();\n }\n\n /**\n * Clear all chunks\n */\n async clearChunks(): Promise<void> {\n return this.chunkStorage.deleteAll();\n }\n\n /**\n * Get vector dimensions\n */\n getVectorDimensions(): number {\n return this.chunkStorage.getVectorDimensions();\n }\n\n // ===========================================================================\n // Document chunk helpers\n // ===========================================================================\n\n /**\n * Get chunks from the document JSON (not from vector storage)\n */\n async getDocumentChunks(doc_id: string): Promise<ChunkRecord[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n return doc.getChunks();\n }\n\n /**\n * Find chunks in document JSON that contain a specific nodeId in their path\n */\n async findChunksByNodeId(doc_id: string, nodeId: string): Promise<ChunkRecord[]> {\n const doc = await this.getDocument(doc_id);\n if (!doc) {\n return [];\n }\n return doc.findChunksByNodeId(nodeId);\n }\n}\n",
10
10
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { DataPortSchemaObject, FromSchema } from \"@workglow/util/schema\";\n\n/**\n * Schema for persisting KnowledgeBase metadata to tabular storage.\n */\nexport const KnowledgeBaseRecordSchema = {\n type: \"object\",\n properties: {\n kb_id: { type: \"string\" },\n title: { type: \"string\" },\n description: { type: \"string\" },\n vector_dimensions: { type: \"integer\" },\n document_table: { type: \"string\" },\n chunk_table: { type: \"string\" },\n created_at: { type: \"string\" },\n updated_at: { type: \"string\" },\n },\n required: [\n \"kb_id\",\n \"title\",\n \"description\",\n \"vector_dimensions\",\n \"document_table\",\n \"chunk_table\",\n \"created_at\",\n \"updated_at\",\n ],\n additionalProperties: false,\n} as const satisfies DataPortSchemaObject;\n\nexport type KnowledgeBaseRecord = FromSchema<typeof KnowledgeBaseRecordSchema>;\nexport const KnowledgeBasePrimaryKeyNames = [\"kb_id\"] as const;\n\n/**\n * Generates SQL-safe table names for a knowledge base's document and chunk storage.\n */\nexport function knowledgeBaseTableNames(kbId: string): {\n readonly documentTable: string;\n readonly chunkTable: string;\n} {\n const safe = kbId.replace(/[^a-zA-Z0-9_]/g, \"_\");\n return {\n documentTable: `kb_docs_${safe}`,\n chunkTable: `kb_chunks_${safe}`,\n };\n}\n",
11
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type ITabularStorage } from \"@workglow/storage\";\nimport { EventEmitter, type EventParameters } from \"@workglow/util\";\n\nimport {\n KnowledgeBasePrimaryKeyNames,\n type KnowledgeBaseRecord,\n KnowledgeBaseRecordSchema,\n} from \"./KnowledgeBaseSchema\";\n\n/**\n * Events that can be emitted by the KnowledgeBaseRepository\n */\n\nexport type KnowledgeBaseEventListeners = {\n knowledge_base_added: (record: KnowledgeBaseRecord) => void;\n knowledge_base_removed: (record: KnowledgeBaseRecord) => void;\n knowledge_base_updated: (record: KnowledgeBaseRecord) => void;\n};\n\nexport type KnowledgeBaseEvents = keyof KnowledgeBaseEventListeners;\n\nexport type KnowledgeBaseEventListener<Event extends KnowledgeBaseEvents> =\n KnowledgeBaseEventListeners[Event];\n\nexport type KnowledgeBaseEventParameters<Event extends KnowledgeBaseEvents> = EventParameters<\n KnowledgeBaseEventListeners,\n Event\n>;\n\n/**\n * Repository for persisting KnowledgeBase metadata to tabular storage.\n * Follows the same pattern as ModelRepository.\n */\nexport class KnowledgeBaseRepository {\n /**\n * Storage for KnowledgeBase records\n */\n protected readonly storage: ITabularStorage<\n typeof KnowledgeBaseRecordSchema,\n typeof KnowledgeBasePrimaryKeyNames\n >;\n\n constructor(\n storage: ITabularStorage<\n typeof KnowledgeBaseRecordSchema,\n typeof KnowledgeBasePrimaryKeyNames\n >\n ) {\n this.storage = storage;\n }\n\n /** Event emitter for repository events */\n protected events = new EventEmitter<KnowledgeBaseEventListeners>();\n\n /**\n * Sets up the database for the repository.\n * Must be called before using any other methods.\n */\n async setupDatabase(): Promise<void> {\n await this.storage.setupDatabase?.();\n }\n\n /**\n * Registers an event listener for the specified event\n */\n on<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.on(name, fn);\n }\n\n /**\n * Removes an event listener for the specified event\n */\n off<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.off(name, fn);\n }\n\n /**\n * Adds an event listener that will only be called once\n */\n once<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.once(name, fn);\n }\n\n /**\n * Returns when the event was emitted (promise form of once)\n */\n waitOn<Event extends KnowledgeBaseEvents>(name: Event) {\n return this.events.waitOn(name);\n }\n\n /**\n * Adds a new knowledge base record to the repository\n */\n async addKnowledgeBase(record: KnowledgeBaseRecord): Promise<KnowledgeBaseRecord> {\n await this.storage.put(record);\n this.events.emit(\"knowledge_base_added\", record);\n return record;\n }\n\n /**\n * Removes a knowledge base record from the repository\n */\n async removeKnowledgeBase(kb_id: string): Promise<void> {\n const record = await this.storage.get({ kb_id });\n if (!record) {\n throw new Error(`KnowledgeBase with id \"${kb_id}\" not found`);\n }\n await this.storage.delete({ kb_id });\n this.events.emit(\"knowledge_base_removed\", record);\n }\n\n /**\n * Retrieves a knowledge base record by ID\n */\n async getKnowledgeBase(kb_id: string): Promise<KnowledgeBaseRecord | undefined> {\n if (typeof kb_id !== \"string\") return undefined;\n const record = await this.storage.get({ kb_id });\n return record ?? undefined;\n }\n\n /**\n * Enumerates all knowledge base records\n */\n async enumerateAll(): Promise<KnowledgeBaseRecord[]> {\n const records = await this.storage.getAll();\n if (!records || records.length === 0) return [];\n return records;\n }\n\n /**\n * Gets the total number of knowledge base records\n */\n async size(): Promise<number> {\n return await this.storage.size();\n }\n}\n",
11
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { type ITabularStorage } from \"@workglow/storage\";\nimport { EventEmitter, type EventParameters } from \"@workglow/util\";\n\nimport {\n KnowledgeBasePrimaryKeyNames,\n type KnowledgeBaseRecord,\n KnowledgeBaseRecordSchema,\n} from \"./KnowledgeBaseSchema\";\n\n/**\n * Events that can be emitted by the KnowledgeBaseRepository\n */\n\nexport type KnowledgeBaseEventListeners = {\n knowledge_base_added: (record: KnowledgeBaseRecord) => void;\n knowledge_base_removed: (record: KnowledgeBaseRecord) => void;\n knowledge_base_updated: (record: KnowledgeBaseRecord) => void;\n};\n\nexport type KnowledgeBaseEvents = keyof KnowledgeBaseEventListeners;\n\nexport type KnowledgeBaseEventListener<Event extends KnowledgeBaseEvents> =\n KnowledgeBaseEventListeners[Event];\n\nexport type KnowledgeBaseEventParameters<Event extends KnowledgeBaseEvents> = EventParameters<\n KnowledgeBaseEventListeners,\n Event\n>;\n\n/**\n * Repository for persisting KnowledgeBase metadata to tabular storage.\n * Follows the same pattern as ModelRepository.\n */\nexport class KnowledgeBaseRepository {\n /**\n * Storage for KnowledgeBase records\n */\n protected readonly storage: ITabularStorage<\n typeof KnowledgeBaseRecordSchema,\n typeof KnowledgeBasePrimaryKeyNames\n >;\n\n constructor(\n storage: ITabularStorage<typeof KnowledgeBaseRecordSchema, typeof KnowledgeBasePrimaryKeyNames>\n ) {\n this.storage = storage;\n }\n\n /** Event emitter for repository events */\n protected events = new EventEmitter<KnowledgeBaseEventListeners>();\n\n /**\n * Sets up the database for the repository.\n * Must be called before using any other methods.\n */\n async setupDatabase(): Promise<void> {\n await this.storage.setupDatabase?.();\n }\n\n /**\n * Registers an event listener for the specified event\n */\n on<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.on(name, fn);\n }\n\n /**\n * Removes an event listener for the specified event\n */\n off<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.off(name, fn);\n }\n\n /**\n * Adds an event listener that will only be called once\n */\n once<Event extends KnowledgeBaseEvents>(name: Event, fn: KnowledgeBaseEventListener<Event>) {\n this.events.once(name, fn);\n }\n\n /**\n * Returns when the event was emitted (promise form of once)\n */\n waitOn<Event extends KnowledgeBaseEvents>(name: Event) {\n return this.events.waitOn(name);\n }\n\n /**\n * Adds a new knowledge base record to the repository\n */\n async addKnowledgeBase(record: KnowledgeBaseRecord): Promise<KnowledgeBaseRecord> {\n await this.storage.put(record);\n this.events.emit(\"knowledge_base_added\", record);\n return record;\n }\n\n /**\n * Removes a knowledge base record from the repository\n */\n async removeKnowledgeBase(kb_id: string): Promise<void> {\n const record = await this.storage.get({ kb_id });\n if (!record) {\n throw new Error(`KnowledgeBase with id \"${kb_id}\" not found`);\n }\n await this.storage.delete({ kb_id });\n this.events.emit(\"knowledge_base_removed\", record);\n }\n\n /**\n * Retrieves a knowledge base record by ID\n */\n async getKnowledgeBase(kb_id: string): Promise<KnowledgeBaseRecord | undefined> {\n if (typeof kb_id !== \"string\") return undefined;\n const record = await this.storage.get({ kb_id });\n return record ?? undefined;\n }\n\n /**\n * Enumerates all knowledge base records\n */\n async enumerateAll(): Promise<KnowledgeBaseRecord[]> {\n const records = await this.storage.getAll();\n if (!records || records.length === 0) return [];\n return records;\n }\n\n /**\n * Gets the total number of knowledge base records\n */\n async size(): Promise<number> {\n return await this.storage.size();\n }\n}\n",
12
12
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { InMemoryTabularStorage } from \"@workglow/storage\";\nimport { KnowledgeBaseRepository } from \"./KnowledgeBaseRepository\";\nimport { KnowledgeBasePrimaryKeyNames, KnowledgeBaseRecordSchema } from \"./KnowledgeBaseSchema\";\n\n/**\n * In-memory implementation of a knowledge base repository.\n */\nexport class InMemoryKnowledgeBaseRepository extends KnowledgeBaseRepository {\n constructor() {\n super(new InMemoryTabularStorage(KnowledgeBaseRecordSchema, KnowledgeBasePrimaryKeyNames));\n }\n}\n",
13
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createServiceToken,\n globalServiceRegistry,\n registerInputResolver,\n ServiceRegistry,\n} from \"@workglow/util\";\nimport { InMemoryKnowledgeBaseRepository } from \"./InMemoryKnowledgeBaseRepository\";\nimport type { KnowledgeBase } from \"./KnowledgeBase\";\nimport { KnowledgeBaseRepository } from \"./KnowledgeBaseRepository\";\nimport { knowledgeBaseTableNames, type KnowledgeBaseRecord } from \"./KnowledgeBaseSchema\";\n\n/**\n * Service token for the knowledge base registry\n * Maps knowledge base IDs to KnowledgeBase instances\n */\nexport const KNOWLEDGE_BASES =\n createServiceToken<Map<string, KnowledgeBase>>(\"knowledge-base.registry\");\n\n/**\n * Service token for the knowledge base repository\n */\nexport const KNOWLEDGE_BASE_REPOSITORY = createServiceToken<KnowledgeBaseRepository>(\n \"knowledge-base.repository\"\n);\n\n// Register default factory for live KB map if not already registered\nif (!globalServiceRegistry.has(KNOWLEDGE_BASES)) {\n globalServiceRegistry.register(\n KNOWLEDGE_BASES,\n (): Map<string, KnowledgeBase> => new Map(),\n true\n );\n}\n\n// Register default factory for KB repository if not already registered\nif (!globalServiceRegistry.has(KNOWLEDGE_BASE_REPOSITORY)) {\n globalServiceRegistry.register(\n KNOWLEDGE_BASE_REPOSITORY,\n (): KnowledgeBaseRepository => new InMemoryKnowledgeBaseRepository(),\n true\n );\n}\n\n/**\n * Gets the global knowledge base registry\n */\nexport function getGlobalKnowledgeBases(): Map<string, KnowledgeBase> {\n return globalServiceRegistry.get(KNOWLEDGE_BASES);\n}\n\n/**\n * Gets the global knowledge base repository instance\n */\nexport function getGlobalKnowledgeBaseRepository(): KnowledgeBaseRepository {\n return globalServiceRegistry.get(KNOWLEDGE_BASE_REPOSITORY);\n}\n\n/**\n * Sets the global knowledge base repository instance\n */\nexport function setGlobalKnowledgeBaseRepository(repository: KnowledgeBaseRepository): void {\n globalServiceRegistry.registerInstance(KNOWLEDGE_BASE_REPOSITORY, repository);\n}\n\n/**\n * Registers a knowledge base globally by ID.\n * Adds to both the live Map and the persistent repository.\n */\nexport async function registerKnowledgeBase(id: string, kb: KnowledgeBase): Promise<void> {\n const kbs = getGlobalKnowledgeBases();\n kbs.set(id, kb);\n\n const now = new Date().toISOString();\n const tableNames = knowledgeBaseTableNames(id);\n const record: KnowledgeBaseRecord = {\n kb_id: id,\n title: kb.title,\n description: kb.description,\n vector_dimensions: kb.getVectorDimensions(),\n document_table: tableNames.documentTable,\n chunk_table: tableNames.chunkTable,\n created_at: now,\n updated_at: now,\n };\n const repo = getGlobalKnowledgeBaseRepository();\n await repo.addKnowledgeBase(record);\n}\n\n/**\n * Gets a knowledge base by ID from the global registry\n */\nexport function getKnowledgeBase(id: string): KnowledgeBase | undefined {\n return getGlobalKnowledgeBases().get(id);\n}\n\n/**\n * Resolves a knowledge base ID from the registry.\n * Used by the input resolver system.\n */\nasync function resolveKnowledgeBaseFromRegistry(\n id: string,\n format: string,\n registry: ServiceRegistry\n): Promise<KnowledgeBase> {\n const kbs = registry.has(KNOWLEDGE_BASES)\n ? registry.get<Map<string, KnowledgeBase>>(KNOWLEDGE_BASES)\n : getGlobalKnowledgeBases();\n\n const kb = kbs.get(id);\n if (!kb) {\n throw new Error(`Knowledge base \"${id}\" not found in registry`);\n }\n return kb;\n}\n\n// Register the resolver for format: \"knowledge-base\"\nregisterInputResolver(\"knowledge-base\", resolveKnowledgeBaseFromRegistry);\n",
14
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { InMemoryTabularStorage, InMemoryVectorStorage } from \"@workglow/storage\";\nimport type { TypedArray } from \"@workglow/util/schema\";\nimport { ChunkVectorPrimaryKey, ChunkVectorStorageSchema } from \"../chunk/ChunkVectorStorageSchema\";\nimport type { ChunkVectorStorage } from \"../chunk/ChunkVectorStorageSchema\";\nimport { DocumentStorageKey, DocumentStorageSchema } from \"../document/DocumentStorageSchema\";\nimport type { DocumentTabularStorage } from \"../document/DocumentStorageSchema\";\nimport { KnowledgeBase } from \"./KnowledgeBase\";\nimport { registerKnowledgeBase } from \"./KnowledgeBaseRegistry\";\n\nexport interface CreateKnowledgeBaseOptions {\n readonly name: string;\n readonly vectorDimensions: number;\n readonly vectorType?: { new (array: number[]): TypedArray };\n readonly register?: boolean;\n readonly title?: string;\n readonly description?: string;\n}\n\n/**\n * Factory function to create a KnowledgeBase with minimal configuration.\n *\n * @example\n * ```typescript\n * const kb = await createKnowledgeBase({\n * name: \"my-kb\",\n * vectorDimensions: 1024,\n * });\n * ```\n */\nexport async function createKnowledgeBase(\n options: CreateKnowledgeBaseOptions\n): Promise<KnowledgeBase> {\n const {\n name,\n vectorDimensions,\n vectorType = Float32Array,\n register: shouldRegister = true,\n title,\n description,\n } = options;\n\n const tabularStorage = new InMemoryTabularStorage(DocumentStorageSchema, DocumentStorageKey);\n await tabularStorage.setupDatabase();\n\n const vectorStorage = new InMemoryVectorStorage(\n ChunkVectorStorageSchema,\n ChunkVectorPrimaryKey,\n [],\n vectorDimensions,\n vectorType\n );\n await vectorStorage.setupDatabase();\n\n const kb = new KnowledgeBase(\n name,\n tabularStorage as unknown as DocumentTabularStorage,\n vectorStorage as unknown as ChunkVectorStorage,\n title,\n description\n );\n\n if (shouldRegister) {\n await registerKnowledgeBase(name, kb);\n }\n\n return kb;\n}\n",
13
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n createServiceToken,\n globalServiceRegistry,\n registerInputResolver,\n ServiceRegistry,\n} from \"@workglow/util\";\nimport { InMemoryKnowledgeBaseRepository } from \"./InMemoryKnowledgeBaseRepository\";\nimport type { KnowledgeBase } from \"./KnowledgeBase\";\nimport { KnowledgeBaseRepository } from \"./KnowledgeBaseRepository\";\nimport { knowledgeBaseTableNames, type KnowledgeBaseRecord } from \"./KnowledgeBaseSchema\";\n\n/**\n * Service token for the knowledge base registry\n * Maps knowledge base IDs to KnowledgeBase instances\n */\nexport const KNOWLEDGE_BASES =\n createServiceToken<Map<string, KnowledgeBase>>(\"knowledge-base.registry\");\n\n/**\n * Service token for the knowledge base repository\n */\nexport const KNOWLEDGE_BASE_REPOSITORY = createServiceToken<KnowledgeBaseRepository>(\n \"knowledge-base.repository\"\n);\n\n// Register default factory for live KB map if not already registered\nif (!globalServiceRegistry.has(KNOWLEDGE_BASES)) {\n globalServiceRegistry.register(\n KNOWLEDGE_BASES,\n (): Map<string, KnowledgeBase> => new Map(),\n true\n );\n}\n\n// Register default factory for KB repository if not already registered\nif (!globalServiceRegistry.has(KNOWLEDGE_BASE_REPOSITORY)) {\n globalServiceRegistry.register(\n KNOWLEDGE_BASE_REPOSITORY,\n (): KnowledgeBaseRepository => new InMemoryKnowledgeBaseRepository(),\n true\n );\n}\n\n/**\n * Gets the global knowledge base registry\n */\nexport function getGlobalKnowledgeBases(): Map<string, KnowledgeBase> {\n return globalServiceRegistry.get(KNOWLEDGE_BASES);\n}\n\n/**\n * Gets the global knowledge base repository instance\n */\nexport function getGlobalKnowledgeBaseRepository(): KnowledgeBaseRepository {\n return globalServiceRegistry.get(KNOWLEDGE_BASE_REPOSITORY);\n}\n\n/**\n * Sets the global knowledge base repository instance\n */\nexport function setGlobalKnowledgeBaseRepository(repository: KnowledgeBaseRepository): void {\n globalServiceRegistry.registerInstance(KNOWLEDGE_BASE_REPOSITORY, repository);\n}\n\n/**\n * Registers a knowledge base globally by ID.\n * Adds to both the live Map and the persistent repository.\n */\nexport async function registerKnowledgeBase(id: string, kb: KnowledgeBase): Promise<void> {\n const kbs = getGlobalKnowledgeBases();\n\n const now = new Date().toISOString();\n const tableNames = knowledgeBaseTableNames(id);\n const record: KnowledgeBaseRecord = {\n kb_id: id,\n title: kb.title,\n description: kb.description,\n vector_dimensions: kb.getVectorDimensions(),\n document_table: tableNames.documentTable,\n chunk_table: tableNames.chunkTable,\n created_at: now,\n updated_at: now,\n };\n\n // Write to persistent repository first so a failure doesn't leave stale in-memory state\n const repo = getGlobalKnowledgeBaseRepository();\n await repo.addKnowledgeBase(record);\n\n // Only add to live map after successful persistence\n kbs.set(id, kb);\n}\n\n/**\n * Gets a knowledge base by ID from the global registry\n */\nexport function getKnowledgeBase(id: string): KnowledgeBase | undefined {\n return getGlobalKnowledgeBases().get(id);\n}\n\n/**\n * Resolves a knowledge base ID from the registry.\n * Used by the input resolver system.\n */\nasync function resolveKnowledgeBaseFromRegistry(\n id: string,\n format: string,\n registry: ServiceRegistry\n): Promise<KnowledgeBase> {\n const kbs = registry.has(KNOWLEDGE_BASES)\n ? registry.get<Map<string, KnowledgeBase>>(KNOWLEDGE_BASES)\n : getGlobalKnowledgeBases();\n\n const kb = kbs.get(id);\n if (!kb) {\n throw new Error(`Knowledge base \"${id}\" not found in registry`);\n }\n return kb;\n}\n\n// Register the resolver for format: \"knowledge-base\"\nregisterInputResolver(\"knowledge-base\", resolveKnowledgeBaseFromRegistry);\n",
14
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { InMemoryTabularStorage, InMemoryVectorStorage } from \"@workglow/storage\";\nimport type { TypedArray } from \"@workglow/util/schema\";\nimport { ChunkVectorPrimaryKey, ChunkVectorStorageSchema } from \"../chunk/ChunkVectorStorageSchema\";\nimport type { ChunkVectorStorage } from \"../chunk/ChunkVectorStorageSchema\";\nimport { DocumentStorageKey, DocumentStorageSchema } from \"../document/DocumentStorageSchema\";\nimport type { DocumentTabularStorage } from \"../document/DocumentStorageSchema\";\nimport { KnowledgeBase } from \"./KnowledgeBase\";\nimport { registerKnowledgeBase } from \"./KnowledgeBaseRegistry\";\n\nexport interface CreateKnowledgeBaseOptions {\n readonly name: string;\n readonly vectorDimensions: number;\n readonly vectorType?: { new (array: number[]): TypedArray };\n readonly register?: boolean;\n readonly title?: string;\n readonly description?: string;\n}\n\n/**\n * Factory function to create a KnowledgeBase with minimal configuration.\n *\n * @example\n * ```typescript\n * const kb = await createKnowledgeBase({\n * name: \"my-kb\",\n * vectorDimensions: 1024,\n * });\n * ```\n */\nexport async function createKnowledgeBase(\n options: CreateKnowledgeBaseOptions\n): Promise<KnowledgeBase> {\n const {\n name,\n vectorDimensions,\n vectorType = Float32Array,\n register: shouldRegister = true,\n title,\n description,\n } = options;\n\n if (!name || typeof name !== \"string\" || name.trim().length === 0) {\n throw new Error(\"createKnowledgeBase: 'name' must be a non-empty string\");\n }\n if (\n typeof vectorDimensions !== \"number\" ||\n !Number.isInteger(vectorDimensions) ||\n vectorDimensions < 1\n ) {\n throw new Error(\"createKnowledgeBase: 'vectorDimensions' must be a positive integer\");\n }\n\n const tabularStorage = new InMemoryTabularStorage(DocumentStorageSchema, DocumentStorageKey);\n await tabularStorage.setupDatabase();\n\n const vectorStorage = new InMemoryVectorStorage(\n ChunkVectorStorageSchema,\n ChunkVectorPrimaryKey,\n [],\n vectorDimensions,\n vectorType\n );\n await vectorStorage.setupDatabase();\n\n const kb = new KnowledgeBase(\n name,\n tabularStorage as unknown as DocumentTabularStorage,\n vectorStorage as unknown as ChunkVectorStorage,\n title,\n description\n );\n\n if (shouldRegister) {\n await registerKnowledgeBase(name, kb);\n }\n\n return kb;\n}\n",
15
15
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ITabularStorage } from \"@workglow/storage\";\nimport {\n TypedArraySchemaOptions,\n type DataPortSchemaObject,\n type FromSchema,\n} from \"@workglow/util/schema\";\n\n/**\n * Schema for storing documents in tabular storage\n */\nexport const DocumentStorageSchema = {\n type: \"object\",\n properties: {\n doc_id: {\n type: \"string\",\n \"x-auto-generated\": true,\n title: \"Document ID\",\n description: \"Unique identifier for the document\",\n },\n data: {\n type: \"string\",\n title: \"Document Data\",\n description: \"JSON-serialized document\",\n },\n metadata: {\n type: \"object\",\n title: \"Metadata\",\n description: \"Metadata of the document\",\n },\n },\n required: [\"doc_id\", \"data\"],\n additionalProperties: true,\n} as const satisfies DataPortSchemaObject;\nexport type DocumentStorageSchema = typeof DocumentStorageSchema;\n\nexport const DocumentStorageKey = [\"doc_id\"] as const;\nexport type DocumentStorageKey = typeof DocumentStorageKey;\n\nexport type DocumentStorageEntity = FromSchema<DocumentStorageSchema, TypedArraySchemaOptions>;\n\n/**\n * Type for inserting documents - doc_id is optional (auto-generated)\n */\nexport type InsertDocumentStorageEntity = Omit<DocumentStorageEntity, \"doc_id\"> &\n Partial<Pick<DocumentStorageEntity, \"doc_id\">>;\n\nexport type DocumentTabularStorage = ITabularStorage<\n typeof DocumentStorageSchema,\n DocumentStorageKey,\n DocumentStorageEntity\n>;\n",
16
16
  "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { JsonSchema } from \"@workglow/util/schema\";\n\n/**\n * Creates a JSON schema for a tabular dataset input.\n * The schema accepts either a string ID (resolved from registry) or a direct dataset instance.\n */\nexport function TypeTabularStorage<O extends Record<string, unknown> = {}>(options: O = {} as O) {\n return {\n title: \"Tabular Storage\",\n description: \"Storage ID or instance for tabular data storage\",\n ...options,\n format: \"storage:tabular\" as const,\n oneOf: [\n { type: \"string\" as const, title: \"Storage ID\" },\n { title: \"Storage Instance\", additionalProperties: true },\n ],\n } as const satisfies JsonSchema;\n}\n\n/**\n * Creates a JSON schema for a knowledge base input.\n * The schema accepts either a string ID (resolved from registry) or a direct KnowledgeBase instance.\n */\nexport function TypeKnowledgeBase<O extends Record<string, unknown> = {}>(options: O = {} as O) {\n return {\n title: \"Knowledge Base\",\n description: \"Knowledge base ID or instance\",\n ...options,\n format: \"knowledge-base\" as const,\n anyOf: [\n { type: \"string\" as const, title: \"Knowledge Base ID\" },\n { title: \"Knowledge Base Instance\", additionalProperties: true },\n ],\n } as const satisfies JsonSchema;\n}\n",
17
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n NodeKind,\n type DocumentNode,\n type DocumentRootNode,\n type NodeRange,\n type SectionNode,\n type TopicNode,\n} from \"./DocumentSchema\";\n\n/**\n * Approximate token counting (v1) -- ~4 characters per token.\n * Used as a fallback when no real tokenizer is available.\n */\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Helper to check if a node has children\n */\nexport function hasChildren(\n node: DocumentNode\n): node is DocumentRootNode | SectionNode | TopicNode {\n return (\n node.kind === NodeKind.DOCUMENT ||\n node.kind === NodeKind.SECTION ||\n node.kind === NodeKind.TOPIC\n );\n}\n\n/**\n * Helper to get all children of a node\n */\nexport function getChildren(node: DocumentNode): DocumentNode[] {\n if (hasChildren(node)) {\n return node.children;\n }\n return [];\n}\n\n/**\n * Traverse document tree depth-first\n */\nexport function* traverseDepthFirst(node: DocumentNode): Generator<DocumentNode> {\n yield node;\n if (hasChildren(node)) {\n for (const child of node.children) {\n yield* traverseDepthFirst(child);\n }\n }\n}\n\n/**\n * Get node path from root to target node\n */\nexport function getNodePath(root: DocumentNode, targetNodeId: string): string[] | undefined {\n const path: string[] = [];\n\n function search(node: DocumentNode): boolean {\n path.push(node.nodeId);\n if (node.nodeId === targetNodeId) {\n return true;\n }\n if (hasChildren(node)) {\n for (const child of node.children) {\n if (search(child)) {\n return true;\n }\n }\n }\n path.pop();\n return false;\n }\n\n return search(root) ? path : undefined;\n}\n\n/**\n * Get document range for a node path\n */\nexport function getDocumentRange(root: DocumentNode, nodePath: string[]): NodeRange {\n let currentNode = root as DocumentRootNode | SectionNode | TopicNode;\n\n // Start from index 1 since nodePath[0] is the root\n for (let i = 1; i < nodePath.length; i++) {\n const targetId = nodePath[i];\n const children = currentNode.children;\n let found: DocumentNode | undefined;\n\n for (let j = 0; j < children.length; j++) {\n if (children[j].nodeId === targetId) {\n found = children[j];\n break;\n }\n }\n\n if (!found) {\n throw new Error(`Node with id ${targetId} not found in path`);\n }\n\n currentNode = found as DocumentRootNode | SectionNode | TopicNode;\n }\n\n return currentNode.range;\n}\n",
18
- "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { uuid4 } from \"@workglow/util\";\nimport {\n type DocumentRootNode,\n NodeKind,\n type ParagraphNode,\n type SectionNode,\n} from \"./DocumentSchema\";\n\n/**\n * Parse markdown into a hierarchical DocumentNode tree\n */\nexport class StructuralParser {\n /**\n * Parse markdown text into a hierarchical document tree\n */\n static async parseMarkdown(\n doc_id: string,\n text: string,\n title: string\n ): Promise<DocumentRootNode> {\n const lines = text.split(\"\\n\");\n let currentOffset = 0;\n\n const root: DocumentRootNode = {\n nodeId: uuid4(),\n kind: NodeKind.DOCUMENT,\n range: { startOffset: 0, endOffset: text.length },\n text: title,\n title,\n children: [],\n };\n\n let currentParentStack: Array<DocumentRootNode | SectionNode> = [root];\n let textBuffer: string[] = [];\n let textBufferStartOffset = 0;\n\n const flushTextBuffer = async () => {\n if (textBuffer.length > 0) {\n const content = textBuffer.join(\"\\n\").trim();\n if (content) {\n const paragraphStartOffset = textBufferStartOffset;\n const paragraphEndOffset = currentOffset;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset: paragraphStartOffset,\n endOffset: paragraphEndOffset,\n },\n text: content,\n };\n\n currentParentStack[currentParentStack.length - 1].children.push(paragraph);\n }\n textBuffer = [];\n }\n };\n\n for (const line of lines) {\n const lineLength = line.length + 1; // +1 for newline\n\n // Check if line is a header\n const headerMatch = line.match(/^(#{1,6})\\s+(.*)$/);\n if (headerMatch) {\n await flushTextBuffer();\n\n const level = headerMatch[1].length;\n const headerTitle = headerMatch[2];\n\n // Pop stack until we find appropriate parent\n while (\n currentParentStack.length > 1 &&\n currentParentStack[currentParentStack.length - 1].kind === NodeKind.SECTION &&\n (currentParentStack[currentParentStack.length - 1] as SectionNode).level >= level\n ) {\n const poppedSection = currentParentStack.pop() as SectionNode;\n // Update endOffset of popped section\n const updatedSection: SectionNode = {\n ...poppedSection,\n range: {\n ...poppedSection.range,\n endOffset: currentOffset,\n },\n };\n // Replace in parent's children\n const parent = currentParentStack[currentParentStack.length - 1];\n parent.children[parent.children.length - 1] = updatedSection;\n }\n\n const sectionStartOffset = currentOffset;\n const section: SectionNode = {\n nodeId: uuid4(),\n kind: NodeKind.SECTION,\n level,\n title: headerTitle,\n range: {\n startOffset: sectionStartOffset,\n endOffset: text.length,\n },\n text: headerTitle,\n children: [],\n };\n\n currentParentStack[currentParentStack.length - 1].children.push(section);\n currentParentStack.push(section);\n } else {\n // Accumulate text\n if (textBuffer.length === 0) {\n textBufferStartOffset = currentOffset;\n }\n textBuffer.push(line);\n }\n\n currentOffset += lineLength;\n }\n\n await flushTextBuffer();\n\n // Close any remaining sections\n while (currentParentStack.length > 1) {\n const section = currentParentStack.pop() as SectionNode;\n const updatedSection: SectionNode = {\n ...section,\n range: {\n ...section.range,\n endOffset: text.length,\n },\n };\n const parent = currentParentStack[currentParentStack.length - 1];\n parent.children[parent.children.length - 1] = updatedSection;\n }\n\n return root;\n }\n\n /**\n * Parse plain text into a hierarchical document tree\n * Splits by double newlines to create paragraphs\n */\n static async parsePlainText(\n doc_id: string,\n text: string,\n title: string\n ): Promise<DocumentRootNode> {\n const root: DocumentRootNode = {\n nodeId: uuid4(),\n kind: NodeKind.DOCUMENT,\n range: { startOffset: 0, endOffset: text.length },\n text: title,\n title,\n children: [],\n };\n\n // Split by double newlines to get paragraphs while tracking offsets\n const paragraphRegex = /\\n\\s*\\n/g;\n let lastIndex = 0;\n let paragraphIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = paragraphRegex.exec(text)) !== null) {\n const rawParagraph = text.slice(lastIndex, match.index);\n const paragraphText = rawParagraph.trim();\n\n if (paragraphText.length > 0) {\n const trimmedRelativeStart = rawParagraph.indexOf(paragraphText);\n const startOffset = lastIndex + trimmedRelativeStart;\n const endOffset = startOffset + paragraphText.length;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset,\n endOffset,\n },\n text: paragraphText,\n };\n\n root.children.push(paragraph);\n paragraphIndex++;\n }\n\n lastIndex = paragraphRegex.lastIndex;\n }\n\n // Handle trailing paragraph after the last double newline, if any\n if (lastIndex < text.length) {\n const rawParagraph = text.slice(lastIndex);\n const paragraphText = rawParagraph.trim();\n\n if (paragraphText.length > 0) {\n const trimmedRelativeStart = rawParagraph.indexOf(paragraphText);\n const startOffset = lastIndex + trimmedRelativeStart;\n const endOffset = startOffset + paragraphText.length;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset,\n endOffset,\n },\n text: paragraphText,\n };\n\n root.children.push(paragraph);\n }\n }\n return root;\n }\n\n /**\n * Auto-detect format and parse\n */\n static parse(\n doc_id: string,\n text: string,\n title: string,\n format?: \"markdown\" | \"text\"\n ): Promise<DocumentRootNode> {\n if (format === \"markdown\" || (!format && this.looksLikeMarkdown(text))) {\n return this.parseMarkdown(doc_id, text, title);\n }\n return this.parsePlainText(doc_id, text, title);\n }\n\n /**\n * Check if text contains markdown header patterns\n * Looks for lines starting with 1-6 hash symbols followed by whitespace\n */\n private static looksLikeMarkdown(text: string): boolean {\n // Check for markdown header patterns: line starting with # followed by space\n return /^#{1,6}\\s/m.test(text);\n }\n}\n"
17
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n NodeKind,\n type DocumentNode,\n type DocumentRootNode,\n type NodeRange,\n type SectionNode,\n type TopicNode,\n} from \"./DocumentSchema\";\n\n/**\n * Approximate token counting (v1) -- ~4 characters per token.\n * Used as a fallback when no real tokenizer is available.\n */\nexport function estimateTokens(text: string): number {\n return Math.ceil(text.length / 4);\n}\n\n/**\n * Helper to check if a node has children\n */\nexport function hasChildren(\n node: DocumentNode\n): node is DocumentRootNode | SectionNode | TopicNode {\n return (\n node.kind === NodeKind.DOCUMENT ||\n node.kind === NodeKind.SECTION ||\n node.kind === NodeKind.TOPIC\n );\n}\n\n/**\n * Helper to get all children of a node\n */\nexport function getChildren(node: DocumentNode): DocumentNode[] {\n if (hasChildren(node)) {\n return node.children;\n }\n return [];\n}\n\n/** Maximum recursion depth for tree traversal to prevent stack overflow */\nconst MAX_TRAVERSAL_DEPTH = 200;\n\n/**\n * Traverse document tree depth-first\n */\nexport function* traverseDepthFirst(\n node: DocumentNode,\n depth: number = 0\n): Generator<DocumentNode> {\n if (depth > MAX_TRAVERSAL_DEPTH) {\n throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);\n }\n yield node;\n if (hasChildren(node)) {\n for (const child of node.children) {\n yield* traverseDepthFirst(child, depth + 1);\n }\n }\n}\n\n/**\n * Get node path from root to target node\n */\nexport function getNodePath(root: DocumentNode, targetNodeId: string): string[] | undefined {\n const path: string[] = [];\n\n function search(node: DocumentNode, depth: number): boolean {\n if (depth > MAX_TRAVERSAL_DEPTH) {\n throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);\n }\n path.push(node.nodeId);\n if (node.nodeId === targetNodeId) {\n return true;\n }\n if (hasChildren(node)) {\n for (const child of node.children) {\n if (search(child, depth + 1)) {\n return true;\n }\n }\n }\n path.pop();\n return false;\n }\n\n return search(root, 0) ? path : undefined;\n}\n\n/**\n * Get document range for a node path\n */\nexport function getDocumentRange(root: DocumentNode, nodePath: string[]): NodeRange {\n let currentNode = root as DocumentRootNode | SectionNode | TopicNode;\n\n // Start from index 1 since nodePath[0] is the root\n for (let i = 1; i < nodePath.length; i++) {\n const targetId = nodePath[i];\n const children = currentNode.children;\n let found: DocumentNode | undefined;\n\n for (let j = 0; j < children.length; j++) {\n if (children[j].nodeId === targetId) {\n found = children[j];\n break;\n }\n }\n\n if (!found) {\n throw new Error(`Node with id ${targetId} not found in path`);\n }\n\n currentNode = found as DocumentRootNode | SectionNode | TopicNode;\n }\n\n return currentNode.range;\n}\n",
18
+ "/**\n * @license\n * Copyright 2025 Steven Roussey <sroussey@gmail.com>\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { uuid4 } from \"@workglow/util\";\nimport {\n type DocumentRootNode,\n NodeKind,\n type ParagraphNode,\n type SectionNode,\n} from \"./DocumentSchema\";\n\n/**\n * Parse markdown into a hierarchical DocumentNode tree\n */\nexport class StructuralParser {\n /**\n * Parse markdown text into a hierarchical document tree.\n *\n * Note: Offsets are measured in UTF-16 code units (consistent with\n * `String.prototype.length` and `String.prototype.slice()`).\n */\n static async parseMarkdown(\n doc_id: string,\n text: string,\n title: string\n ): Promise<DocumentRootNode> {\n const lines = text.split(\"\\n\");\n let currentOffset = 0;\n\n const root: DocumentRootNode = {\n nodeId: uuid4(),\n kind: NodeKind.DOCUMENT,\n range: { startOffset: 0, endOffset: text.length },\n text: title,\n title,\n children: [],\n };\n\n let currentParentStack: Array<DocumentRootNode | SectionNode> = [root];\n let textBuffer: string[] = [];\n let textBufferStartOffset = 0;\n\n const flushTextBuffer = async () => {\n if (textBuffer.length > 0) {\n const content = textBuffer.join(\"\\n\").trim();\n if (content) {\n const paragraphStartOffset = textBufferStartOffset;\n const paragraphEndOffset = currentOffset;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset: paragraphStartOffset,\n endOffset: paragraphEndOffset,\n },\n text: content,\n };\n\n currentParentStack[currentParentStack.length - 1].children.push(paragraph);\n }\n textBuffer = [];\n }\n };\n\n for (const line of lines) {\n const lineLength = line.length + 1; // +1 for newline\n\n // Check if line is a header\n const headerMatch = line.match(/^(#{1,6})\\s+(.*)$/);\n if (headerMatch) {\n await flushTextBuffer();\n\n const level = headerMatch[1].length;\n const headerTitle = headerMatch[2];\n\n // Pop stack until we find appropriate parent — set endOffset to currentOffset\n // (the start of this new header line) rather than text.length\n while (\n currentParentStack.length > 1 &&\n currentParentStack[currentParentStack.length - 1].kind === NodeKind.SECTION &&\n (currentParentStack[currentParentStack.length - 1] as SectionNode).level >= level\n ) {\n const poppedSection = currentParentStack.pop() as SectionNode;\n // Update endOffset of popped section to where the next section begins\n const updatedSection: SectionNode = {\n ...poppedSection,\n range: {\n ...poppedSection.range,\n endOffset: currentOffset,\n },\n };\n // Replace in parent's children\n const parent = currentParentStack[currentParentStack.length - 1];\n parent.children[parent.children.length - 1] = updatedSection;\n }\n\n const sectionStartOffset = currentOffset;\n const section: SectionNode = {\n nodeId: uuid4(),\n kind: NodeKind.SECTION,\n level,\n title: headerTitle,\n range: {\n startOffset: sectionStartOffset,\n // Will be updated to the correct endOffset when popped or at end of parsing\n endOffset: text.length,\n },\n text: headerTitle,\n children: [],\n };\n\n currentParentStack[currentParentStack.length - 1].children.push(section);\n currentParentStack.push(section);\n } else {\n // Accumulate text\n if (textBuffer.length === 0) {\n textBufferStartOffset = currentOffset;\n }\n textBuffer.push(line);\n }\n\n currentOffset += lineLength;\n }\n\n await flushTextBuffer();\n\n // Close any remaining sections — final sections extend to the end of the text\n while (currentParentStack.length > 1) {\n const section = currentParentStack.pop() as SectionNode;\n const updatedSection: SectionNode = {\n ...section,\n range: {\n ...section.range,\n endOffset: text.length,\n },\n };\n const parent = currentParentStack[currentParentStack.length - 1];\n parent.children[parent.children.length - 1] = updatedSection;\n }\n\n return root;\n }\n\n /**\n * Parse plain text into a hierarchical document tree\n * Splits by double newlines to create paragraphs\n */\n static async parsePlainText(\n doc_id: string,\n text: string,\n title: string\n ): Promise<DocumentRootNode> {\n const root: DocumentRootNode = {\n nodeId: uuid4(),\n kind: NodeKind.DOCUMENT,\n range: { startOffset: 0, endOffset: text.length },\n text: title,\n title,\n children: [],\n };\n\n // Split by double newlines to get paragraphs while tracking offsets\n const paragraphRegex = /\\n\\s*\\n/g;\n let lastIndex = 0;\n let paragraphIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = paragraphRegex.exec(text)) !== null) {\n const rawParagraph = text.slice(lastIndex, match.index);\n const paragraphText = rawParagraph.trim();\n\n if (paragraphText.length > 0) {\n const trimmedRelativeStart = rawParagraph.indexOf(paragraphText);\n const startOffset = lastIndex + trimmedRelativeStart;\n const endOffset = startOffset + paragraphText.length;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset,\n endOffset,\n },\n text: paragraphText,\n };\n\n root.children.push(paragraph);\n paragraphIndex++;\n }\n\n lastIndex = paragraphRegex.lastIndex;\n }\n\n // Handle trailing paragraph after the last double newline, if any\n if (lastIndex < text.length) {\n const rawParagraph = text.slice(lastIndex);\n const paragraphText = rawParagraph.trim();\n\n if (paragraphText.length > 0) {\n const trimmedRelativeStart = rawParagraph.indexOf(paragraphText);\n const startOffset = lastIndex + trimmedRelativeStart;\n const endOffset = startOffset + paragraphText.length;\n\n const paragraph: ParagraphNode = {\n nodeId: uuid4(),\n kind: NodeKind.PARAGRAPH,\n range: {\n startOffset,\n endOffset,\n },\n text: paragraphText,\n };\n\n root.children.push(paragraph);\n }\n }\n return root;\n }\n\n /**\n * Auto-detect format and parse\n */\n static parse(\n doc_id: string,\n text: string,\n title: string,\n format?: \"markdown\" | \"text\"\n ): Promise<DocumentRootNode> {\n if (format === \"markdown\" || (!format && this.looksLikeMarkdown(text))) {\n return this.parseMarkdown(doc_id, text, title);\n }\n return this.parsePlainText(doc_id, text, title);\n }\n\n /**\n * Check if text contains markdown header patterns\n * Looks for lines starting with 1-6 hash symbols followed by whitespace\n */\n private static looksLikeMarkdown(text: string): boolean {\n // Check for markdown header patterns: line starting with # followed by space\n return /^#{1,6}\\s/m.test(text);\n }\n}\n"
19
19
  ],
20
- "mappings": ";AAWO,IAAM,WAAW;AAAA,EACtB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAO;AACT;AAWO,IAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,YAAY;AAAA,IACV,aAAa;AAAA,MACX,MAAM;AAAA,MACN,OAAO;AAAA,MACP,aAAa;AAAA,IACf;AAAA,IACA,WAAW;AAAA,MACT,MAAM;AAAA,MACN,OAAO;AAAA,MACP,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,UAAU,CAAC,eAAe,WAAW;AAAA,EACrC,sBAAsB;AACxB;AAOO,IAAM,eAAe;AAAA,EAC1B,MA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CEA980CAC08F84F64756E2164756E21",
22
22
  "names": []
23
23
  }
@@ -4,4 +4,4 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  export * from "./common-server";
7
- //# sourceMappingURL=types.d.ts.map
7
+ //# sourceMappingURL=bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bun.d.ts","sourceRoot":"","sources":["../src/bun.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,iBAAiB,CAAC"}
package/dist/bun.js CHANGED
@@ -343,7 +343,9 @@ var ChunkRecordArraySchema = {
343
343
  description: "Array of chunk records"
344
344
  };
345
345
  // src/chunk/ChunkVectorStorageSchema.ts
346
- import { TypedArraySchema } from "@workglow/util/schema";
346
+ import {
347
+ TypedArraySchema
348
+ } from "@workglow/util/schema";
347
349
  var ChunkVectorStorageSchema = {
348
350
  type: "object",
349
351
  properties: {
@@ -389,6 +391,18 @@ class Document {
389
391
  }
390
392
  static fromJSON(json, doc_id) {
391
393
  const obj = JSON.parse(json);
394
+ if (!obj || typeof obj !== "object") {
395
+ throw new Error("Document.fromJSON: expected a JSON object");
396
+ }
397
+ if (!obj.root || typeof obj.root !== "object" || !obj.root.kind) {
398
+ throw new Error("Document.fromJSON: missing or invalid 'root' node");
399
+ }
400
+ if (!obj.metadata || typeof obj.metadata !== "object" || typeof obj.metadata.title !== "string") {
401
+ throw new Error("Document.fromJSON: missing or invalid 'metadata' (requires 'title' string)");
402
+ }
403
+ if (obj.chunks !== undefined && !Array.isArray(obj.chunks)) {
404
+ throw new Error("Document.fromJSON: 'chunks' must be an array if present");
405
+ }
392
406
  return new Document(obj.root, obj.metadata, obj.chunks, doc_id);
393
407
  }
394
408
  }
@@ -525,6 +539,9 @@ class KnowledgeBase {
525
539
  async similaritySearch(query, options) {
526
540
  return this.chunkStorage.similaritySearch(query, options);
527
541
  }
542
+ supportsHybridSearch() {
543
+ return typeof this.chunkStorage.hybridSearch === "function";
544
+ }
528
545
  async hybridSearch(query, options) {
529
546
  if (typeof this.chunkStorage.hybridSearch !== "function") {
530
547
  throw new Error("Hybrid search is not supported by the configured chunk storage backend. " + "Please use a vector storage implementation that provides `hybridSearch`.");
@@ -701,7 +718,6 @@ function setGlobalKnowledgeBaseRepository(repository) {
701
718
  }
702
719
  async function registerKnowledgeBase(id, kb) {
703
720
  const kbs = getGlobalKnowledgeBases();
704
- kbs.set(id, kb);
705
721
  const now = new Date().toISOString();
706
722
  const tableNames = knowledgeBaseTableNames(id);
707
723
  const record = {
@@ -716,6 +732,7 @@ async function registerKnowledgeBase(id, kb) {
716
732
  };
717
733
  const repo = getGlobalKnowledgeBaseRepository();
718
734
  await repo.addKnowledgeBase(record);
735
+ kbs.set(id, kb);
719
736
  }
720
737
  function getKnowledgeBase(id) {
721
738
  return getGlobalKnowledgeBases().get(id);
@@ -768,6 +785,12 @@ async function createKnowledgeBase(options) {
768
785
  title,
769
786
  description
770
787
  } = options;
788
+ if (!name || typeof name !== "string" || name.trim().length === 0) {
789
+ throw new Error("createKnowledgeBase: 'name' must be a non-empty string");
790
+ }
791
+ if (typeof vectorDimensions !== "number" || !Number.isInteger(vectorDimensions) || vectorDimensions < 1) {
792
+ throw new Error("createKnowledgeBase: 'vectorDimensions' must be a positive integer");
793
+ }
771
794
  const tabularStorage = new InMemoryTabularStorage2(DocumentStorageSchema, DocumentStorageKey);
772
795
  await tabularStorage.setupDatabase();
773
796
  const vectorStorage = new InMemoryVectorStorage(ChunkVectorStorageSchema, ChunkVectorPrimaryKey, [], vectorDimensions, vectorType);
@@ -816,24 +839,31 @@ function getChildren(node) {
816
839
  }
817
840
  return [];
818
841
  }
819
- function* traverseDepthFirst(node) {
842
+ var MAX_TRAVERSAL_DEPTH = 200;
843
+ function* traverseDepthFirst(node, depth = 0) {
844
+ if (depth > MAX_TRAVERSAL_DEPTH) {
845
+ throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);
846
+ }
820
847
  yield node;
821
848
  if (hasChildren(node)) {
822
849
  for (const child of node.children) {
823
- yield* traverseDepthFirst(child);
850
+ yield* traverseDepthFirst(child, depth + 1);
824
851
  }
825
852
  }
826
853
  }
827
854
  function getNodePath(root, targetNodeId) {
828
855
  const path = [];
829
- function search(node) {
856
+ function search(node, depth) {
857
+ if (depth > MAX_TRAVERSAL_DEPTH) {
858
+ throw new Error(`Document tree exceeds maximum depth of ${MAX_TRAVERSAL_DEPTH}`);
859
+ }
830
860
  path.push(node.nodeId);
831
861
  if (node.nodeId === targetNodeId) {
832
862
  return true;
833
863
  }
834
864
  if (hasChildren(node)) {
835
865
  for (const child of node.children) {
836
- if (search(child)) {
866
+ if (search(child, depth + 1)) {
837
867
  return true;
838
868
  }
839
869
  }
@@ -841,7 +871,7 @@ function getNodePath(root, targetNodeId) {
841
871
  path.pop();
842
872
  return false;
843
873
  }
844
- return search(root) ? path : undefined;
874
+ return search(root, 0) ? path : undefined;
845
875
  }
846
876
  function getDocumentRange(root, nodePath) {
847
877
  let currentNode = root;
@@ -1069,4 +1099,4 @@ export {
1069
1099
  ChunkRecordArraySchema
1070
1100
  };
1071
1101
 
1072
- //# debugId=C2C0AF9D153FAB9064756E2164756E21
1102
+ //# debugId=E518FA75797167F364756E2164756E21