wolbarg 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/index.cjs +1542 -396
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2011 -140
- package/dist/index.d.ts +2011 -140
- package/dist/index.js +1542 -396
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,19 @@ import { DatabaseSync } from 'node:sqlite';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Metadata filter AST for advanced recall filtering.
|
|
5
|
+
*
|
|
6
|
+
* Build filters with the {@link meta} helper or compose `{ field, op }` nodes directly.
|
|
7
|
+
* Filters compile to SQL JSON predicates when possible ({@link compileMetadataFilterToSql}).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { meta } from "wolbarg/filters";
|
|
12
|
+
*
|
|
13
|
+
* const filter = meta.and(
|
|
14
|
+
* meta.eq("category", "billing"),
|
|
15
|
+
* meta.gte("priority", 2),
|
|
16
|
+
* );
|
|
17
|
+
* ```
|
|
5
18
|
*/
|
|
6
19
|
/** Comparison operators on a single metadata field. */
|
|
7
20
|
type MetadataComparison = {
|
|
@@ -30,8 +43,9 @@ type MetadataFilter = {
|
|
|
30
43
|
} | {
|
|
31
44
|
not: MetadataFilter;
|
|
32
45
|
};
|
|
33
|
-
/**
|
|
46
|
+
/** Fluent builders for {@link MetadataFilter} AST nodes. */
|
|
34
47
|
declare const meta: {
|
|
48
|
+
/** Field equals value (strict equality). */
|
|
35
49
|
eq: (field: string, value: unknown) => MetadataFilter;
|
|
36
50
|
contains: (field: string, value: string) => MetadataFilter;
|
|
37
51
|
gt: (field: string, value: number | string) => MetadataFilter;
|
|
@@ -49,8 +63,10 @@ declare const meta: {
|
|
|
49
63
|
* Schema is intentionally extensible for future providers (Postgres, cloud).
|
|
50
64
|
*/
|
|
51
65
|
/** Public operation names recorded as telemetry events. */
|
|
52
|
-
type TelemetryOperation = "remember" | "recall" | "forget" | "compress" | "rememberBatch" | "recallBatch" | "export" | "import" | "checkpoint" | "rollback" | "error" | "startup" | "shutdown" | "ingest" | "history" | "stats" | "clear" | "deleteCheckpoint" | "listCheckpoints" | "getCheckpoint" | "linkMemories" | "getRelated" | "graphQuery" | "rememberFromMessages";
|
|
66
|
+
type TelemetryOperation = "remember" | "update" | "recall" | "forget" | "compress" | "rememberBatch" | "recallBatch" | "export" | "import" | "checkpoint" | "rollback" | "error" | "startup" | "shutdown" | "ingest" | "history" | "stats" | "clear" | "deleteCheckpoint" | "listCheckpoints" | "getCheckpoint" | "linkMemories" | "getRelated" | "graphQuery" | "rememberFromMessages";
|
|
67
|
+
/** Outcome recorded on each telemetry event. */
|
|
53
68
|
type TelemetryStatus = "ok" | "error" | "cancelled";
|
|
69
|
+
/** Minimum log level for {@link WolbargLogger} and telemetry console output. */
|
|
54
70
|
type TelemetryLogLevel = "off" | "error" | "warn" | "info" | "debug" | "trace";
|
|
55
71
|
/** Stage-level latency breakdown recorded on each event. */
|
|
56
72
|
interface LatencyBreakdown {
|
|
@@ -149,46 +165,78 @@ interface TelemetryEvent extends Required<Pick<TelemetryEventInput, "id" | "time
|
|
|
149
165
|
explain: PersistedRecallExplainPayload | null;
|
|
150
166
|
spans: StageSpan[] | null;
|
|
151
167
|
}
|
|
168
|
+
/** Filter and pagination options for querying persisted telemetry events. */
|
|
152
169
|
interface TelemetryQuery {
|
|
170
|
+
/** Filter by one or more operation names. */
|
|
153
171
|
operation?: TelemetryOperation | TelemetryOperation[];
|
|
172
|
+
/** Filter by completion status. */
|
|
154
173
|
status?: TelemetryStatus;
|
|
174
|
+
/** Match events whose trace or parent trace equals this id. */
|
|
155
175
|
traceId?: string;
|
|
176
|
+
/** Filter by Wolbarg instance session id. */
|
|
156
177
|
sessionId?: string;
|
|
178
|
+
/** Filter by organization namespace. */
|
|
157
179
|
organization?: string;
|
|
180
|
+
/** Filter by agent id recorded on the event. */
|
|
158
181
|
agentId?: string;
|
|
182
|
+
/** Require a tag in the event's `tags` array. */
|
|
159
183
|
tag?: string;
|
|
184
|
+
/** Filter by checkpoint id when the operation touched checkpoints. */
|
|
160
185
|
checkpointId?: string;
|
|
186
|
+
/** Require the memory id in the event's `memoryIds` list. */
|
|
161
187
|
memoryId?: string;
|
|
188
|
+
/** Case-sensitive substring match on the recorded query text. */
|
|
162
189
|
queryText?: string;
|
|
190
|
+
/** ISO-8601 lower bound (inclusive). */
|
|
163
191
|
since?: string;
|
|
192
|
+
/** ISO-8601 upper bound (inclusive). */
|
|
164
193
|
until?: string;
|
|
194
|
+
/** Page size (default 50). */
|
|
165
195
|
limit?: number;
|
|
196
|
+
/** Page offset (default 0). */
|
|
166
197
|
offset?: number;
|
|
198
|
+
/** Sort column. */
|
|
167
199
|
sortBy?: "timestamp" | "duration_ms";
|
|
200
|
+
/** Sort direction. */
|
|
168
201
|
sortDir?: "asc" | "desc";
|
|
169
202
|
}
|
|
203
|
+
/** Paginated telemetry query result. */
|
|
170
204
|
interface TelemetryQueryResult {
|
|
205
|
+
/** Matching events for the current page. */
|
|
171
206
|
events: TelemetryEvent[];
|
|
207
|
+
/** Total rows matching filters (ignoring limit/offset). */
|
|
172
208
|
total: number;
|
|
209
|
+
/** Applied page size. */
|
|
173
210
|
limit: number;
|
|
211
|
+
/** Applied page offset. */
|
|
174
212
|
offset: number;
|
|
175
213
|
}
|
|
176
214
|
/** Database config for the independent telemetry EventDatabase. */
|
|
177
215
|
interface TelemetryDatabaseConfig {
|
|
216
|
+
/** Storage engine for telemetry (SQLite today; Postgres planned). */
|
|
178
217
|
provider: "sqlite" | "postgres";
|
|
179
|
-
/** Preferred v0.3 field. */
|
|
218
|
+
/** Preferred v0.3 field — filesystem path or Postgres URL. */
|
|
180
219
|
url?: string;
|
|
181
|
-
/** Back-compat alias for url. */
|
|
220
|
+
/** Back-compat alias for {@link TelemetryDatabaseConfig.url}. */
|
|
182
221
|
connectionString?: string;
|
|
183
222
|
}
|
|
223
|
+
/** Wolbarg constructor `telemetry` option — independent observability database. */
|
|
184
224
|
interface TelemetryConfig {
|
|
225
|
+
/** Master switch (default `true` when a provider is configured). */
|
|
185
226
|
enabled?: boolean;
|
|
227
|
+
/** Separate SQLite (or future Postgres) database for event storage. */
|
|
186
228
|
database: TelemetryDatabaseConfig;
|
|
229
|
+
/** Console log level for {@link WolbargLogger}. */
|
|
187
230
|
level?: TelemetryLogLevel;
|
|
231
|
+
/** Persist recall/remember query strings on events. */
|
|
188
232
|
captureQueries?: boolean;
|
|
233
|
+
/** Persist {@link LatencyBreakdown} and stage spans. */
|
|
189
234
|
captureLatency?: boolean;
|
|
235
|
+
/** Persist error message and stack on failed operations. */
|
|
190
236
|
captureErrors?: boolean;
|
|
237
|
+
/** Persist per-hit similarity scores on recall events. */
|
|
191
238
|
captureSimilarity?: boolean;
|
|
239
|
+
/** Persist raw embedding vectors (off by default — large payloads). */
|
|
192
240
|
captureEmbeddings?: boolean;
|
|
193
241
|
}
|
|
194
242
|
|
|
@@ -282,7 +330,7 @@ interface MmrConfig {
|
|
|
282
330
|
}
|
|
283
331
|
/** Retrieval pipeline defaults applied when constructing Wolbarg. */
|
|
284
332
|
interface RetrievalConfig {
|
|
285
|
-
/** Default over-fetch multiplier for candidate generation. Defaults to 4. */
|
|
333
|
+
/** Default over-fetch multiplier for candidate generation. Defaults to 2 (no filters) or 4 (with metadata filters). */
|
|
286
334
|
overFetchFactor?: number;
|
|
287
335
|
/** Default hybrid fusion weights. */
|
|
288
336
|
hybrid?: HybridConfig;
|
|
@@ -645,19 +693,29 @@ interface IngestResult {
|
|
|
645
693
|
/** Direction for {@link GraphProvider.getRelated}. */
|
|
646
694
|
type GraphDirection = "in" | "out" | "both";
|
|
647
695
|
interface GetRelatedOptions {
|
|
696
|
+
/** Relation type filter (e.g. `"follows"`, `"references"`). Omit for any relation. */
|
|
648
697
|
relation?: string;
|
|
649
|
-
/** Traversal depth (default 1). */
|
|
698
|
+
/** Traversal depth from the start memory (default `1`). */
|
|
650
699
|
depth?: number;
|
|
700
|
+
/** Edge direction: incoming, outgoing, or both (default `"both"`). */
|
|
651
701
|
direction?: GraphDirection;
|
|
652
702
|
}
|
|
703
|
+
/** Input for {@link GraphProvider.upsertEntity}. */
|
|
653
704
|
interface GraphEntityInput {
|
|
705
|
+
/** Human-readable entity name. */
|
|
654
706
|
name: string;
|
|
707
|
+
/** Entity type label (e.g. `"person"`, `"project"`). */
|
|
655
708
|
type: string;
|
|
709
|
+
/** Optional opaque metadata stored on the entity node. */
|
|
656
710
|
metadata?: Record<string, unknown>;
|
|
657
711
|
}
|
|
712
|
+
/** Result of {@link GraphProvider.health}. */
|
|
658
713
|
interface GraphHealthResult {
|
|
714
|
+
/** Whether the graph backend is reachable and schema-ready. */
|
|
659
715
|
ok: boolean;
|
|
716
|
+
/** Backend identifier (e.g. `"sqlite-graph"`, `"neo4j"`). */
|
|
660
717
|
backend: string;
|
|
718
|
+
/** Backend-specific details (file path, cluster info, etc.). */
|
|
661
719
|
details?: unknown;
|
|
662
720
|
}
|
|
663
721
|
/**
|
|
@@ -671,250 +729,863 @@ interface GraphProvider {
|
|
|
671
729
|
readonly name: string;
|
|
672
730
|
/** Open connection / embedded database and ensure schema. */
|
|
673
731
|
open(): Promise<void>;
|
|
674
|
-
/** Close the underlying connection. */
|
|
732
|
+
/** Close the underlying connection and release resources. */
|
|
675
733
|
close(): Promise<void>;
|
|
676
734
|
/**
|
|
677
735
|
* Create (or ensure) a directed relation between two memory nodes.
|
|
678
736
|
* Implementations create stub Memory nodes when missing.
|
|
737
|
+
*
|
|
738
|
+
* @param fromId - Source memory UUID.
|
|
739
|
+
* @param toId - Target memory UUID.
|
|
740
|
+
* @param relation - Relation type label (e.g. `"references"`).
|
|
741
|
+
* @param metadata - Optional edge properties.
|
|
679
742
|
*/
|
|
680
743
|
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
681
|
-
/**
|
|
744
|
+
/**
|
|
745
|
+
* Remove relation(s) between two memory nodes.
|
|
746
|
+
*
|
|
747
|
+
* @param fromId - Source memory UUID.
|
|
748
|
+
* @param toId - Target memory UUID.
|
|
749
|
+
* @param relation - When set, only remove edges of this type; omit to remove all between the pair.
|
|
750
|
+
*/
|
|
682
751
|
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
683
752
|
/**
|
|
684
753
|
* Traverse from a memory node and return related Memory records as stored
|
|
685
754
|
* in the graph (facade may re-hydrate from SQL storage).
|
|
755
|
+
*
|
|
756
|
+
* @param memoryId - Start memory UUID.
|
|
757
|
+
* @param options - Relation filter, depth, and direction.
|
|
758
|
+
* @returns Related memories in graph-native form.
|
|
686
759
|
*/
|
|
687
760
|
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
688
|
-
/**
|
|
761
|
+
/**
|
|
762
|
+
* Upsert an entity node; returns stable entity id.
|
|
763
|
+
*
|
|
764
|
+
* @param entity - Entity name, type, and optional metadata.
|
|
765
|
+
* @returns Stable entity UUID for {@link linkEntityToMemory}.
|
|
766
|
+
*/
|
|
689
767
|
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
690
|
-
/**
|
|
768
|
+
/**
|
|
769
|
+
* Link an entity to a memory with an optional role.
|
|
770
|
+
*
|
|
771
|
+
* @param entityId - Entity UUID from {@link upsertEntity}.
|
|
772
|
+
* @param memoryId - Memory UUID to link.
|
|
773
|
+
* @param role - Optional relationship role (e.g. `"author"`, `"subject"`).
|
|
774
|
+
*/
|
|
691
775
|
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
692
776
|
/**
|
|
693
777
|
* Hard-delete a memory node and all incident edges (cascade for forget/clear).
|
|
778
|
+
*
|
|
779
|
+
* @param memoryId - Memory UUID to remove from the graph.
|
|
694
780
|
*/
|
|
695
781
|
deleteMemory(memoryId: string): Promise<void>;
|
|
696
782
|
/**
|
|
697
783
|
* Raw Cypher escape hatch. Supported on Neo4j only — the SQLite provider
|
|
698
784
|
* throws a typed error. See module portability contract above.
|
|
785
|
+
*
|
|
786
|
+
* @param cypher - Cypher query string.
|
|
787
|
+
* @param params - Bound parameters for the query.
|
|
788
|
+
* @returns Driver-specific result rows.
|
|
699
789
|
*/
|
|
700
790
|
query(cypher: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
791
|
+
/**
|
|
792
|
+
* Lightweight connectivity / schema health check.
|
|
793
|
+
* @returns {@link GraphHealthResult} with `ok`, `backend`, and optional `details`.
|
|
794
|
+
*/
|
|
701
795
|
health(): Promise<GraphHealthResult>;
|
|
702
796
|
/**
|
|
703
797
|
* When true, checkpoint/export may snapshot {@link getDataPath}.
|
|
704
798
|
* Network-backed providers (Neo4j) return false.
|
|
705
799
|
*/
|
|
706
800
|
supportsFileSnapshot(): boolean;
|
|
707
|
-
/**
|
|
801
|
+
/**
|
|
802
|
+
* Absolute path to the embedded graph data directory/file, if any.
|
|
803
|
+
* Returns `null` for networked backends (Neo4j).
|
|
804
|
+
*/
|
|
708
805
|
getDataPath(): string | null;
|
|
709
806
|
}
|
|
710
807
|
/** Config shape accepted by `wolbarg({ graph: … })` when not passing an instance. */
|
|
711
808
|
type GraphConfig = {
|
|
712
809
|
provider: "sqlite";
|
|
810
|
+
/** File path for the embedded SQLite graph database. */
|
|
713
811
|
path: string;
|
|
714
812
|
} | {
|
|
715
813
|
provider: "neo4j";
|
|
814
|
+
/** Bolt or Neo4j URI (e.g. `bolt://localhost:7687`). */
|
|
716
815
|
url: string;
|
|
816
|
+
/** Neo4j username. */
|
|
717
817
|
username: string;
|
|
818
|
+
/** Neo4j password. */
|
|
718
819
|
password: string;
|
|
820
|
+
/** Optional Neo4j database name (default database when omitted). */
|
|
719
821
|
database?: string;
|
|
720
822
|
};
|
|
823
|
+
/** Either a {@link GraphProvider} instance or a {@link GraphConfig} object. */
|
|
721
824
|
type GraphInput$1 = GraphProvider | GraphConfig;
|
|
722
825
|
|
|
723
826
|
/**
|
|
724
827
|
* Chunking strategies for document ingestion.
|
|
828
|
+
*
|
|
829
|
+
* Long documents are split into overlapping chunks before embedding and storage.
|
|
830
|
+
* Choose a strategy via {@link createChunkingStrategy} or let ingest auto-detect
|
|
831
|
+
* with {@link inferChunkingStrategy}.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* import { createChunkingStrategy } from "wolbarg/chunking";
|
|
836
|
+
*
|
|
837
|
+
* const chunker = createChunkingStrategy("sentence");
|
|
838
|
+
* const chunks = chunker.chunk(documentText, { chunkSize: 800, overlap: 100 });
|
|
839
|
+
* ```
|
|
725
840
|
*/
|
|
841
|
+
/** A single text chunk with stable index for ordering. */
|
|
726
842
|
interface Chunk {
|
|
843
|
+
/** Chunk body text. */
|
|
727
844
|
text: string;
|
|
845
|
+
/** Zero-based position in the original document. */
|
|
728
846
|
index: number;
|
|
729
847
|
}
|
|
848
|
+
/** Options controlling chunk size and overlap. */
|
|
730
849
|
interface ChunkingOptions {
|
|
850
|
+
/** Target characters per chunk (default `800`, minimum `32`). */
|
|
731
851
|
chunkSize?: number;
|
|
852
|
+
/** Overlap between consecutive chunks (default `100`, capped at half of chunkSize). */
|
|
732
853
|
overlap?: number;
|
|
733
854
|
}
|
|
855
|
+
/**
|
|
856
|
+
* Contract for document chunking strategies.
|
|
857
|
+
*
|
|
858
|
+
* Implement this interface for custom splitters (token-based, semantic, etc.).
|
|
859
|
+
* Wolbarg ingest calls {@link ChunkingStrategy.chunk} after parsing a document.
|
|
860
|
+
*/
|
|
734
861
|
interface ChunkingStrategy {
|
|
862
|
+
/** Strategy name (e.g. `"sentence"`, `"markdown"`). */
|
|
735
863
|
readonly name: string;
|
|
864
|
+
/**
|
|
865
|
+
* Split `text` into ordered chunks.
|
|
866
|
+
* @param text - Full document text.
|
|
867
|
+
* @param options - Optional size and overlap overrides.
|
|
868
|
+
* @returns Non-overlapping or sliding-window chunks with indices.
|
|
869
|
+
*/
|
|
736
870
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
737
871
|
}
|
|
872
|
+
/** Character-based fixed window chunking (ignores sentence boundaries). */
|
|
738
873
|
declare class FixedChunkingStrategy implements ChunkingStrategy {
|
|
739
874
|
readonly name = "fixed";
|
|
875
|
+
/** @inheritdoc */
|
|
740
876
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
741
877
|
}
|
|
878
|
+
/** Sentence-boundary-aware chunking (splits on `.!?` followed by whitespace). */
|
|
742
879
|
declare class SentenceChunkingStrategy implements ChunkingStrategy {
|
|
743
880
|
readonly name = "sentence";
|
|
881
|
+
/** @inheritdoc */
|
|
744
882
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
745
883
|
}
|
|
884
|
+
/** Paragraph-boundary-aware chunking (splits on blank lines). */
|
|
746
885
|
declare class ParagraphChunkingStrategy implements ChunkingStrategy {
|
|
747
886
|
readonly name = "paragraph";
|
|
887
|
+
/** @inheritdoc */
|
|
748
888
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
749
889
|
}
|
|
890
|
+
/** Markdown heading-aware chunking (splits on `#` headings; falls back to paragraph). */
|
|
750
891
|
declare class MarkdownChunkingStrategy implements ChunkingStrategy {
|
|
751
892
|
readonly name = "markdown";
|
|
893
|
+
/** @inheritdoc */
|
|
752
894
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
753
895
|
}
|
|
896
|
+
/** Alias for {@link MarkdownChunkingStrategy}. */
|
|
754
897
|
declare class HeadingChunkingStrategy implements ChunkingStrategy {
|
|
755
898
|
readonly name = "heading";
|
|
899
|
+
/** @inheritdoc */
|
|
756
900
|
chunk(text: string, options?: ChunkingOptions): Chunk[];
|
|
757
901
|
}
|
|
902
|
+
/**
|
|
903
|
+
* Factory for built-in chunking strategies.
|
|
904
|
+
*
|
|
905
|
+
* @param name - Strategy name (default `"sentence"`).
|
|
906
|
+
* @returns A {@link ChunkingStrategy} instance.
|
|
907
|
+
*
|
|
908
|
+
* @example
|
|
909
|
+
* ```ts
|
|
910
|
+
* const chunker = createChunkingStrategy("markdown");
|
|
911
|
+
* ```
|
|
912
|
+
*/
|
|
758
913
|
declare function createChunkingStrategy(name?: "fixed" | "sentence" | "paragraph" | "markdown" | "heading"): ChunkingStrategy;
|
|
759
914
|
|
|
760
915
|
/**
|
|
761
916
|
* LLM provider abstractions and OpenAI-compatible chat implementation.
|
|
762
|
-
*
|
|
917
|
+
*
|
|
918
|
+
* Used for memory compression ({@link Wolbarg.compress}) and experimental
|
|
919
|
+
* {@link Wolbarg.rememberFromMessages} extract mode.
|
|
920
|
+
*
|
|
921
|
+
* ## Custom LLM providers
|
|
922
|
+
*
|
|
923
|
+
* Pass any object that implements {@link LlmProvider} as `llm` in
|
|
924
|
+
* {@link WolbargOptions}:
|
|
925
|
+
*
|
|
926
|
+
* ```ts
|
|
927
|
+
* const myLlm: LlmProvider = {
|
|
928
|
+
* model: "my-model",
|
|
929
|
+
* async complete(messages) {
|
|
930
|
+
* // Call your backend; return the assistant text
|
|
931
|
+
* return "...";
|
|
932
|
+
* },
|
|
933
|
+
* async validate() {
|
|
934
|
+
* await this.complete([{ role: "user", content: "ok" }]);
|
|
935
|
+
* },
|
|
936
|
+
* };
|
|
937
|
+
*
|
|
938
|
+
* const ctx = wolbarg({
|
|
939
|
+
* organization: "acme",
|
|
940
|
+
* database: { provider: "sqlite", url: "./memory.db" },
|
|
941
|
+
* embedding: openaiEmbedding({ apiKey: "...", model: "text-embedding-3-small" }),
|
|
942
|
+
* llm: myLlm, // or openaiLlm({ ... }) / openaiCompatibleLlm({ ... })
|
|
943
|
+
* });
|
|
944
|
+
* ```
|
|
945
|
+
*
|
|
946
|
+
* Built-in factories (`openaiLlm`, `ollamaLlm`, `openRouterLlm`,
|
|
947
|
+
* `openaiCompatibleLlm`) wrap any OpenAI-compatible `/v1/chat/completions` API.
|
|
763
948
|
*/
|
|
764
949
|
|
|
950
|
+
/**
|
|
951
|
+
* One message in a chat completion request.
|
|
952
|
+
*
|
|
953
|
+
* @property role - Speaker role. Use `"system"` for instructions, `"user"` for
|
|
954
|
+
* prompts, `"assistant"` for prior model turns.
|
|
955
|
+
* @property content - Plain-text message body (non-empty for useful completions).
|
|
956
|
+
*/
|
|
765
957
|
interface ChatMessage {
|
|
766
958
|
role: "system" | "user" | "assistant";
|
|
767
959
|
content: string;
|
|
768
960
|
}
|
|
769
|
-
/**
|
|
961
|
+
/**
|
|
962
|
+
* Contract for any chat completion backend used by Wolbarg.
|
|
963
|
+
*
|
|
964
|
+
* Implement this interface to plug in a custom LLM (Anthropic, local GGUF via
|
|
965
|
+
* a custom HTTP bridge, Azure OpenAI with extra headers, etc.). The SDK only
|
|
966
|
+
* requires {@link LlmProvider.complete} to return the assistant reply as a
|
|
967
|
+
* string; streaming is not used.
|
|
968
|
+
*
|
|
969
|
+
* @example Custom provider
|
|
970
|
+
* ```ts
|
|
971
|
+
* const anthropicLike: LlmProvider = {
|
|
972
|
+
* model: "claude-sonnet",
|
|
973
|
+
* async complete(messages) {
|
|
974
|
+
* const res = await fetch("https://api.example.com/complete", {
|
|
975
|
+
* method: "POST",
|
|
976
|
+
* body: JSON.stringify({ messages }),
|
|
977
|
+
* });
|
|
978
|
+
* const data = await res.json();
|
|
979
|
+
* return String(data.text);
|
|
980
|
+
* },
|
|
981
|
+
* async validate() {
|
|
982
|
+
* const reply = await this.complete([{ role: "user", content: "ping" }]);
|
|
983
|
+
* if (!reply.trim()) throw new Error("empty reply");
|
|
984
|
+
* },
|
|
985
|
+
* };
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
770
988
|
interface LlmProvider {
|
|
989
|
+
/** Model identifier reported in telemetry / logs (any non-empty string). */
|
|
771
990
|
readonly model: string;
|
|
991
|
+
/**
|
|
992
|
+
* Run a chat completion and return the assistant message text.
|
|
993
|
+
*
|
|
994
|
+
* @param messages - Ordered conversation turns. The last message is typically
|
|
995
|
+
* the user (or system+user) prompt the SDK builds for compression / extract.
|
|
996
|
+
* @returns Trimmed assistant text. Empty responses should throw.
|
|
997
|
+
* @throws When the backend fails, times out, or returns no text.
|
|
998
|
+
*/
|
|
772
999
|
complete(messages: ChatMessage[]): Promise<string>;
|
|
773
|
-
/**
|
|
1000
|
+
/**
|
|
1001
|
+
* Lightweight connectivity probe invoked during boot when an LLM is configured.
|
|
1002
|
+
* Implementations typically call {@link LlmProvider.complete} with a tiny prompt.
|
|
1003
|
+
*
|
|
1004
|
+
* @throws When the endpoint is unreachable or misconfigured.
|
|
1005
|
+
*/
|
|
774
1006
|
validate(): Promise<void>;
|
|
775
1007
|
}
|
|
1008
|
+
/**
|
|
1009
|
+
* Build an {@link LlmProvider} from {@link LlmConfig}.
|
|
1010
|
+
*
|
|
1011
|
+
* Prefer named helpers ({@link openaiLlm}, {@link ollamaLlm}, …) when the
|
|
1012
|
+
* default `baseUrl` matches your host; use this (or {@link openaiCompatibleLlm})
|
|
1013
|
+
* when you need a fully custom base URL.
|
|
1014
|
+
*
|
|
1015
|
+
* @param config - Full OpenAI-compatible config including `baseUrl`.
|
|
1016
|
+
* @returns A ready-to-use {@link OpenAICompatibleLlmProvider}.
|
|
1017
|
+
*
|
|
1018
|
+
* @example
|
|
1019
|
+
* ```ts
|
|
1020
|
+
* const llm = createLlmProvider({
|
|
1021
|
+
* baseUrl: "https://api.openai.com/v1",
|
|
1022
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1023
|
+
* model: "gpt-4o-mini",
|
|
1024
|
+
* temperature: 0.2,
|
|
1025
|
+
* maxTokens: 4096,
|
|
1026
|
+
* });
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
776
1029
|
declare function createLlmProvider(config: LlmConfig): LlmProvider;
|
|
1030
|
+
/**
|
|
1031
|
+
* OpenAI-compatible LLM with an explicit `baseUrl` (any compatible host).
|
|
1032
|
+
*
|
|
1033
|
+
* @param config - Full {@link LlmConfig} including `baseUrl`, `apiKey`, `model`.
|
|
1034
|
+
* @returns {@link LlmProvider} instance.
|
|
1035
|
+
*
|
|
1036
|
+
* @example
|
|
1037
|
+
* ```ts
|
|
1038
|
+
* llm: openaiCompatibleLlm({
|
|
1039
|
+
* baseUrl: "https://my-proxy.example.com/v1",
|
|
1040
|
+
* apiKey: process.env.API_KEY!,
|
|
1041
|
+
* model: "gpt-4o-mini",
|
|
1042
|
+
* })
|
|
1043
|
+
* ```
|
|
1044
|
+
*/
|
|
777
1045
|
declare const openaiCompatibleLlm: (config: LlmConfig) => LlmProvider;
|
|
1046
|
+
/**
|
|
1047
|
+
* OpenAI Chat Completions (`https://api.openai.com/v1`).
|
|
1048
|
+
*
|
|
1049
|
+
* @param config - `apiKey` and `model` required; optional `temperature`,
|
|
1050
|
+
* `maxTokens`, `timeoutMs`, and override `baseUrl`.
|
|
1051
|
+
* @returns {@link LlmProvider} for use as `llm` in {@link WolbargOptions}.
|
|
1052
|
+
*
|
|
1053
|
+
* @example
|
|
1054
|
+
* ```ts
|
|
1055
|
+
* llm: openaiLlm({
|
|
1056
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1057
|
+
* model: "gpt-4o-mini",
|
|
1058
|
+
* })
|
|
1059
|
+
* ```
|
|
1060
|
+
*/
|
|
778
1061
|
declare const openaiLlm: (config: Omit<LlmConfig, "baseUrl"> & {
|
|
779
1062
|
baseUrl?: string;
|
|
780
1063
|
}) => LlmProvider;
|
|
1064
|
+
/**
|
|
1065
|
+
* Local Ollama OpenAI-compatible API (`http://127.0.0.1:11434/v1`).
|
|
1066
|
+
*
|
|
1067
|
+
* @param config - `apiKey` may be any non-empty string (Ollama often ignores it);
|
|
1068
|
+
* `model` is the Ollama model name (e.g. `"llama3.2"`).
|
|
1069
|
+
* @returns {@link LlmProvider} pointing at the local Ollama server.
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* llm: ollamaLlm({ apiKey: "ollama", model: "llama3.2" })
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
781
1076
|
declare const ollamaLlm: (config: Omit<LlmConfig, "baseUrl"> & {
|
|
782
1077
|
baseUrl?: string;
|
|
783
1078
|
}) => LlmProvider;
|
|
1079
|
+
/**
|
|
1080
|
+
* OpenRouter chat API (`https://openrouter.ai/api/v1`).
|
|
1081
|
+
*
|
|
1082
|
+
* @param config - Use your OpenRouter API key and a routed model id
|
|
1083
|
+
* (e.g. `"openai/gpt-4o-mini"`).
|
|
1084
|
+
* @returns {@link LlmProvider} for OpenRouter.
|
|
1085
|
+
*
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```ts
|
|
1088
|
+
* llm: openRouterLlm({
|
|
1089
|
+
* apiKey: process.env.OPENROUTER_API_KEY!,
|
|
1090
|
+
* model: "openai/gpt-4o-mini",
|
|
1091
|
+
* })
|
|
1092
|
+
* ```
|
|
1093
|
+
*/
|
|
784
1094
|
declare const openRouterLlm: (config: Omit<LlmConfig, "baseUrl"> & {
|
|
785
1095
|
baseUrl?: string;
|
|
786
1096
|
}) => LlmProvider;
|
|
787
1097
|
|
|
788
1098
|
/**
|
|
789
|
-
* Memory compression — provider-based summarization.
|
|
1099
|
+
* Memory compression — provider-based summarization of related memories.
|
|
1100
|
+
*
|
|
1101
|
+
* Compression collapses multiple memories into one summary via an LLM, archiving
|
|
1102
|
+
* the originals with lineage. Use {@link createCompressionProvider} or call
|
|
1103
|
+
* {@link compressMemories} directly when building custom pipelines.
|
|
1104
|
+
*
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```ts
|
|
1107
|
+
* import { createCompressionProvider } from "wolbarg/compression";
|
|
1108
|
+
* import { openaiLlm } from "wolbarg/llm";
|
|
1109
|
+
*
|
|
1110
|
+
* const compression = createCompressionProvider(openaiLlm({ apiKey, model: "gpt-4o-mini" }));
|
|
1111
|
+
* const summary = await compression.compress(memories);
|
|
1112
|
+
* ```
|
|
790
1113
|
*/
|
|
791
1114
|
|
|
792
|
-
/**
|
|
1115
|
+
/**
|
|
1116
|
+
* Contract for memory compression backends.
|
|
1117
|
+
*
|
|
1118
|
+
* Implement this interface to swap LLM vendors or use rule-based summarizers.
|
|
1119
|
+
* Wolbarg's `compress()` facade delegates to the configured provider.
|
|
1120
|
+
*
|
|
1121
|
+
* @example Custom provider
|
|
1122
|
+
* ```ts
|
|
1123
|
+
* const rules: CompressionProvider = {
|
|
1124
|
+
* name: "truncate",
|
|
1125
|
+
* async compress(memories) {
|
|
1126
|
+
* return memories.map((m) => m.content.text).join(" | ").slice(0, 500);
|
|
1127
|
+
* },
|
|
1128
|
+
* };
|
|
1129
|
+
* ```
|
|
1130
|
+
*/
|
|
793
1131
|
interface CompressionProvider {
|
|
1132
|
+
/** Provider identifier (e.g. `"llm"`, `"truncate"`). */
|
|
794
1133
|
readonly name: string;
|
|
1134
|
+
/**
|
|
1135
|
+
* Produce a single summary string from related memories.
|
|
1136
|
+
* @param memories - Non-empty list of memories to collapse.
|
|
1137
|
+
* @returns Plain-text summary.
|
|
1138
|
+
* @throws {@link CompressionError} when compression fails or input is empty.
|
|
1139
|
+
*/
|
|
795
1140
|
compress(memories: MemoryRecord[]): Promise<string>;
|
|
796
1141
|
}
|
|
797
|
-
/**
|
|
1142
|
+
/**
|
|
1143
|
+
* Default compression provider wrapping an {@link LlmProvider}.
|
|
1144
|
+
*
|
|
1145
|
+
* Delegates to {@link compressMemories} with the standard system prompt.
|
|
1146
|
+
*/
|
|
798
1147
|
declare class LlmCompressionProvider implements CompressionProvider {
|
|
799
1148
|
readonly name = "llm";
|
|
800
1149
|
private readonly llm;
|
|
1150
|
+
/** @param llm - Configured LLM used for summarization. */
|
|
801
1151
|
constructor(llm: LlmProvider);
|
|
1152
|
+
/** @inheritdoc */
|
|
802
1153
|
compress(memories: MemoryRecord[]): Promise<string>;
|
|
803
1154
|
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Factory for the default LLM-backed {@link CompressionProvider}.
|
|
1157
|
+
*
|
|
1158
|
+
* @param llm - LLM used for summarization.
|
|
1159
|
+
* @returns A {@link CompressionProvider} named `"llm"`.
|
|
1160
|
+
*/
|
|
804
1161
|
declare function createCompressionProvider(llm: LlmProvider): CompressionProvider;
|
|
805
1162
|
|
|
806
1163
|
/**
|
|
807
1164
|
* Embedding providers and named factories.
|
|
1165
|
+
*
|
|
1166
|
+
* ## Custom embedding providers
|
|
1167
|
+
*
|
|
1168
|
+
* Pass any object that implements {@link EmbeddingProvider} as `embedding` in
|
|
1169
|
+
* {@link WolbargOptions}:
|
|
1170
|
+
*
|
|
1171
|
+
* ```ts
|
|
1172
|
+
* const myEmbedder: EmbeddingProvider = {
|
|
1173
|
+
* model: "my-embed-model",
|
|
1174
|
+
* async embed(text) {
|
|
1175
|
+
* // Return a Float32Array of fixed dimensionality
|
|
1176
|
+
* return new Float32Array([...]);
|
|
1177
|
+
* },
|
|
1178
|
+
* // Optional — if omitted, the SDK parallelizes `embed` via embedMany
|
|
1179
|
+
* async embedBatch(texts) {
|
|
1180
|
+
* return Promise.all(texts.map((t) => this.embed(t)));
|
|
1181
|
+
* },
|
|
1182
|
+
* async validate() {
|
|
1183
|
+
* const v = await this.embed("health check");
|
|
1184
|
+
* return { dimensions: v.length };
|
|
1185
|
+
* },
|
|
1186
|
+
* };
|
|
1187
|
+
*
|
|
1188
|
+
* const ctx = wolbarg({
|
|
1189
|
+
* organization: "acme",
|
|
1190
|
+
* database: { provider: "sqlite", url: "./memory.db" },
|
|
1191
|
+
* embedding: myEmbedder, // or openaiEmbedding({ ... })
|
|
1192
|
+
* });
|
|
1193
|
+
* ```
|
|
1194
|
+
*
|
|
1195
|
+
* Built-in factories wrap OpenAI-compatible `POST {baseUrl}/embeddings` APIs.
|
|
1196
|
+
* **Important:** keep the same model (and dimensions) for the lifetime of a
|
|
1197
|
+
* database — mixing models will cause dimension mismatch errors.
|
|
808
1198
|
*/
|
|
809
1199
|
|
|
810
|
-
/**
|
|
1200
|
+
/**
|
|
1201
|
+
* Contract for any embedding backend used by Wolbarg.
|
|
1202
|
+
*
|
|
1203
|
+
* Implement this to plug in Voyage, Cohere, a local ONNX model, etc. Vectors
|
|
1204
|
+
* must be finite floats; dimensionality is fixed after the first successful
|
|
1205
|
+
* {@link EmbeddingProvider.validate} / remember.
|
|
1206
|
+
*/
|
|
811
1207
|
interface EmbeddingProvider {
|
|
1208
|
+
/** Embedding model id (telemetry + cache key namespace). */
|
|
812
1209
|
readonly model: string;
|
|
813
|
-
/**
|
|
1210
|
+
/**
|
|
1211
|
+
* Produce a float embedding for the given text.
|
|
1212
|
+
*
|
|
1213
|
+
* @param text - Non-empty content to embed (memory text or recall query).
|
|
1214
|
+
* @returns Dense vector as `Float32Array` (same length for every call).
|
|
1215
|
+
*/
|
|
814
1216
|
embed(text: string): Promise<Float32Array>;
|
|
815
|
-
/**
|
|
1217
|
+
/**
|
|
1218
|
+
* Optional batch embedding. When present, {@link embedMany} and ingest prefer it.
|
|
1219
|
+
* When absent, the SDK falls back to concurrent single {@link embed} calls.
|
|
1220
|
+
*
|
|
1221
|
+
* @param texts - Texts to embed in one request when the API supports batching.
|
|
1222
|
+
* @returns One vector per input text, same order as `texts`.
|
|
1223
|
+
*/
|
|
816
1224
|
embedBatch?(texts: string[]): Promise<Float32Array[]>;
|
|
817
|
-
/**
|
|
1225
|
+
/**
|
|
1226
|
+
* Connectivity + dimension probe used during {@link Wolbarg.ready}.
|
|
1227
|
+
*
|
|
1228
|
+
* @returns Object with `dimensions` equal to the vector length.
|
|
1229
|
+
* @throws When the endpoint is unreachable or returns an empty vector.
|
|
1230
|
+
*/
|
|
818
1231
|
validate(): Promise<{
|
|
819
1232
|
dimensions: number;
|
|
820
1233
|
}>;
|
|
821
1234
|
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Build an {@link EmbeddingProvider} from {@link EmbeddingConfig}.
|
|
1237
|
+
*
|
|
1238
|
+
* @param config - Full config including `baseUrl`, `apiKey`, and `model`.
|
|
1239
|
+
* @returns A ready-to-use {@link OpenAICompatibleEmbeddingProvider}.
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```ts
|
|
1243
|
+
* const embedding = createEmbeddingProvider({
|
|
1244
|
+
* baseUrl: "https://api.openai.com/v1",
|
|
1245
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1246
|
+
* model: "text-embedding-3-small",
|
|
1247
|
+
* });
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
822
1250
|
declare function createEmbeddingProvider(config: EmbeddingConfig): EmbeddingProvider;
|
|
1251
|
+
/**
|
|
1252
|
+
* OpenAI-compatible embeddings with an explicit `baseUrl`.
|
|
1253
|
+
*
|
|
1254
|
+
* @param config - Full {@link EmbeddingConfig} including `baseUrl`.
|
|
1255
|
+
* @returns {@link EmbeddingProvider} instance.
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* embedding: openaiCompatibleEmbedding({
|
|
1260
|
+
* baseUrl: "https://my-proxy.example.com/v1",
|
|
1261
|
+
* apiKey: process.env.API_KEY!,
|
|
1262
|
+
* model: "text-embedding-3-small",
|
|
1263
|
+
* })
|
|
1264
|
+
* ```
|
|
1265
|
+
*/
|
|
823
1266
|
declare const openaiCompatibleEmbedding: (config: EmbeddingConfig) => EmbeddingProvider;
|
|
1267
|
+
/**
|
|
1268
|
+
* OpenAI Embeddings API (`https://api.openai.com/v1`).
|
|
1269
|
+
*
|
|
1270
|
+
* @param config - `apiKey` and `model` required (e.g. `"text-embedding-3-small"`);
|
|
1271
|
+
* optional `timeoutMs` and override `baseUrl`.
|
|
1272
|
+
* @returns {@link EmbeddingProvider} for use as `embedding` in {@link WolbargOptions}.
|
|
1273
|
+
*
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```ts
|
|
1276
|
+
* embedding: openaiEmbedding({
|
|
1277
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1278
|
+
* model: "text-embedding-3-small",
|
|
1279
|
+
* })
|
|
1280
|
+
* ```
|
|
1281
|
+
*/
|
|
824
1282
|
declare const openaiEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
825
1283
|
baseUrl?: string;
|
|
826
1284
|
}) => EmbeddingProvider;
|
|
1285
|
+
/**
|
|
1286
|
+
* Local Ollama embeddings (`http://127.0.0.1:11434/v1`).
|
|
1287
|
+
*
|
|
1288
|
+
* @param config - `apiKey` may be any non-empty string; `model` is the Ollama
|
|
1289
|
+
* embedding model (e.g. `"nomic-embed-text"`).
|
|
1290
|
+
* @returns {@link EmbeddingProvider} for local Ollama.
|
|
1291
|
+
*/
|
|
827
1292
|
declare const ollamaEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
828
1293
|
baseUrl?: string;
|
|
829
1294
|
}) => EmbeddingProvider;
|
|
1295
|
+
/**
|
|
1296
|
+
* OpenRouter embeddings (`https://openrouter.ai/api/v1`).
|
|
1297
|
+
*
|
|
1298
|
+
* @param config - OpenRouter API key and routed embedding model id.
|
|
1299
|
+
* @returns {@link EmbeddingProvider} for OpenRouter.
|
|
1300
|
+
*/
|
|
830
1301
|
declare const openRouterEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
831
1302
|
baseUrl?: string;
|
|
832
1303
|
}) => EmbeddingProvider;
|
|
1304
|
+
/**
|
|
1305
|
+
* LM Studio local server embeddings (`http://127.0.0.1:1234/v1`).
|
|
1306
|
+
*
|
|
1307
|
+
* @param config - Local API key (often unused) and the loaded embedding model name.
|
|
1308
|
+
* @returns {@link EmbeddingProvider} for LM Studio.
|
|
1309
|
+
*/
|
|
833
1310
|
declare const lmStudioEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
834
1311
|
baseUrl?: string;
|
|
835
1312
|
}) => EmbeddingProvider;
|
|
1313
|
+
/**
|
|
1314
|
+
* Google Gemini embeddings via the OpenAI-compatible endpoint.
|
|
1315
|
+
* Default base: `https://generativelanguage.googleapis.com/v1beta/openai`.
|
|
1316
|
+
*
|
|
1317
|
+
* @param config - Gemini API key and embedding model (e.g. `"text-embedding-004"`).
|
|
1318
|
+
* @returns {@link EmbeddingProvider} for Gemini.
|
|
1319
|
+
*/
|
|
836
1320
|
declare const geminiEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
837
1321
|
baseUrl?: string;
|
|
838
1322
|
}) => EmbeddingProvider;
|
|
1323
|
+
/**
|
|
1324
|
+
* Together AI embeddings (`https://api.together.xyz/v1`).
|
|
1325
|
+
*
|
|
1326
|
+
* @param config - Together API key and embedding model id.
|
|
1327
|
+
* @returns {@link EmbeddingProvider} for Together.
|
|
1328
|
+
*/
|
|
839
1329
|
declare const togetherEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
840
1330
|
baseUrl?: string;
|
|
841
1331
|
}) => EmbeddingProvider;
|
|
1332
|
+
/**
|
|
1333
|
+
* vLLM OpenAI-compatible embeddings (`http://127.0.0.1:8000/v1`).
|
|
1334
|
+
*
|
|
1335
|
+
* @param config - Local/server API key (if required) and the served model name.
|
|
1336
|
+
* @returns {@link EmbeddingProvider} for vLLM.
|
|
1337
|
+
*/
|
|
842
1338
|
declare const vllmEmbedding: (config: Omit<EmbeddingConfig, "baseUrl"> & {
|
|
843
1339
|
baseUrl?: string;
|
|
844
1340
|
}) => EmbeddingProvider;
|
|
845
1341
|
|
|
846
1342
|
/**
|
|
847
|
-
* Keyword / BM25 search providers.
|
|
1343
|
+
* Keyword / BM25 search providers for hybrid recall.
|
|
1344
|
+
*
|
|
1345
|
+
* Use these when you want lexical (BM25) scoring alongside semantic vector search.
|
|
1346
|
+
* Pass a {@link KeywordSearchProvider} to Wolbarg retrieval config, or rely on
|
|
1347
|
+
* native FTS when the storage backend supports it.
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```ts
|
|
1351
|
+
* import { bm25 } from "wolbarg/keyword";
|
|
1352
|
+
*
|
|
1353
|
+
* const keyword = bm25({ k1: 1.2, b: 0.75 });
|
|
1354
|
+
* const hits = await keyword.search("billing issue", documents, 10);
|
|
1355
|
+
* ```
|
|
848
1356
|
*/
|
|
1357
|
+
/** A single keyword search hit with memory id and BM25 score. */
|
|
849
1358
|
interface KeywordSearchHit {
|
|
1359
|
+
/** Memory UUID that matched the query. */
|
|
850
1360
|
memoryId: string;
|
|
1361
|
+
/** BM25 relevance score (higher is better). */
|
|
851
1362
|
score: number;
|
|
852
1363
|
}
|
|
1364
|
+
/** Document passed to keyword search — typically memory id + text body. */
|
|
853
1365
|
interface KeywordDocument {
|
|
1366
|
+
/** Memory UUID. */
|
|
854
1367
|
id: string;
|
|
1368
|
+
/** Searchable text content. */
|
|
855
1369
|
text: string;
|
|
856
1370
|
}
|
|
857
|
-
/**
|
|
1371
|
+
/**
|
|
1372
|
+
* Contract for keyword / lexical search backends.
|
|
1373
|
+
*
|
|
1374
|
+
* Implement this interface to plug in a custom BM25, Elasticsearch, or FTS adapter.
|
|
1375
|
+
* Wolbarg calls {@link KeywordSearchProvider.search} during hybrid recall when no
|
|
1376
|
+
* native storage keyword index is available.
|
|
1377
|
+
*
|
|
1378
|
+
* @example Custom provider
|
|
1379
|
+
* ```ts
|
|
1380
|
+
* const myKeyword: KeywordSearchProvider = {
|
|
1381
|
+
* name: "my-fts",
|
|
1382
|
+
* async search(query, documents, topK) {
|
|
1383
|
+
* // score documents and return topK hits
|
|
1384
|
+
* return [{ memoryId: documents[0]!.id, score: 1.0 }];
|
|
1385
|
+
* },
|
|
1386
|
+
* };
|
|
1387
|
+
* ```
|
|
1388
|
+
*/
|
|
858
1389
|
interface KeywordSearchProvider {
|
|
1390
|
+
/** Provider identifier (e.g. `"bm25"`, `"fts5"`). */
|
|
859
1391
|
readonly name: string;
|
|
1392
|
+
/**
|
|
1393
|
+
* Rank documents by lexical relevance to `query`.
|
|
1394
|
+
* @param query - User search string.
|
|
1395
|
+
* @param documents - Candidate memories to score.
|
|
1396
|
+
* @param topK - Maximum hits to return.
|
|
1397
|
+
* @returns Hits sorted by score descending.
|
|
1398
|
+
*/
|
|
860
1399
|
search(query: string, documents: KeywordDocument[], topK: number): Promise<KeywordSearchHit[]>;
|
|
861
1400
|
}
|
|
862
|
-
/**
|
|
1401
|
+
/**
|
|
1402
|
+
* Factory for the default in-memory BM25 keyword provider.
|
|
1403
|
+
*
|
|
1404
|
+
* @param options - Optional BM25 tuning (`k1`, `b`).
|
|
1405
|
+
* @returns A {@link KeywordSearchProvider} ready for hybrid recall.
|
|
1406
|
+
*
|
|
1407
|
+
* @example
|
|
1408
|
+
* ```ts
|
|
1409
|
+
* const keyword = bm25();
|
|
1410
|
+
* ```
|
|
1411
|
+
*/
|
|
863
1412
|
declare function bm25(options?: {
|
|
864
1413
|
k1?: number;
|
|
865
1414
|
b?: number;
|
|
866
1415
|
}): KeywordSearchProvider;
|
|
867
1416
|
|
|
868
1417
|
/**
|
|
869
|
-
* Optional OCR
|
|
1418
|
+
* Optional OCR providers — extract text from images during ingest.
|
|
1419
|
+
*
|
|
1420
|
+
* OCR is used when ingesting image files without accompanying text. Install the
|
|
1421
|
+
* optional peer `tesseract.js` before calling {@link tesseract}.
|
|
1422
|
+
*
|
|
1423
|
+
* @example
|
|
1424
|
+
* ```ts
|
|
1425
|
+
* import { tesseract } from "wolbarg/ocr";
|
|
1426
|
+
*
|
|
1427
|
+
* const ocr = tesseract();
|
|
1428
|
+
* const { text } = await ocr.recognize(imageBuffer, "image/png");
|
|
1429
|
+
* ```
|
|
870
1430
|
*/
|
|
1431
|
+
/** Result of optical character recognition on an image. */
|
|
871
1432
|
interface OcrResult {
|
|
1433
|
+
/** Extracted plain text (may be empty if OCR finds nothing). */
|
|
872
1434
|
text: string;
|
|
873
1435
|
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Contract for OCR backends.
|
|
1438
|
+
*
|
|
1439
|
+
* Implement this interface to plug in Google Vision, Azure OCR, or another engine.
|
|
1440
|
+
* Wolbarg calls {@link OCRProvider.recognize} during ingest when a document parser
|
|
1441
|
+
* marks the source as an image.
|
|
1442
|
+
*
|
|
1443
|
+
* @example Custom provider
|
|
1444
|
+
* ```ts
|
|
1445
|
+
* const myOcr: OCRProvider = {
|
|
1446
|
+
* name: "cloud-ocr",
|
|
1447
|
+
* async recognize(image, mimeType) {
|
|
1448
|
+
* const text = await callMyApi(image, mimeType);
|
|
1449
|
+
* return { text };
|
|
1450
|
+
* },
|
|
1451
|
+
* };
|
|
1452
|
+
* ```
|
|
1453
|
+
*/
|
|
874
1454
|
interface OCRProvider {
|
|
1455
|
+
/** Provider identifier (e.g. `"tesseract"`, `"cloud-ocr"`). */
|
|
875
1456
|
readonly name: string;
|
|
1457
|
+
/**
|
|
1458
|
+
* Extract text from a raster image buffer.
|
|
1459
|
+
* @param image - Raw image bytes.
|
|
1460
|
+
* @param mimeType - Optional MIME hint (e.g. `"image/png"`).
|
|
1461
|
+
* @returns Recognized text.
|
|
1462
|
+
*/
|
|
876
1463
|
recognize(image: Buffer, mimeType?: string): Promise<OcrResult>;
|
|
877
1464
|
}
|
|
878
1465
|
/**
|
|
879
|
-
*
|
|
880
|
-
*
|
|
1466
|
+
* Tesseract.js OCR adapter.
|
|
1467
|
+
*
|
|
1468
|
+
* Requires the optional peer package `tesseract.js`. Throws
|
|
1469
|
+
* {@link ConfigurationError} with install instructions when the peer is missing.
|
|
1470
|
+
*
|
|
1471
|
+
* @returns An {@link OCRProvider} using English (`"eng"`) by default.
|
|
1472
|
+
*
|
|
1473
|
+
* @example
|
|
1474
|
+
* ```ts
|
|
1475
|
+
* // npm install tesseract.js
|
|
1476
|
+
* const ocr = tesseract();
|
|
1477
|
+
* const result = await ocr.recognize(buffer);
|
|
1478
|
+
* ```
|
|
881
1479
|
*/
|
|
882
1480
|
declare function tesseract(): OCRProvider;
|
|
883
1481
|
|
|
884
1482
|
/**
|
|
885
|
-
* Reranker provider abstractions.
|
|
1483
|
+
* Reranker provider abstractions for second-stage recall ranking.
|
|
1484
|
+
*
|
|
1485
|
+
* Rerankers reorder vector/keyword candidates using cross-encoders or LLM scoring.
|
|
1486
|
+
* Pass a {@link RerankerProvider} to Wolbarg retrieval config or call factories
|
|
1487
|
+
* directly in custom pipelines.
|
|
1488
|
+
*
|
|
1489
|
+
* @example
|
|
1490
|
+
* ```ts
|
|
1491
|
+
* import { cohereReranker } from "wolbarg/rerank";
|
|
1492
|
+
*
|
|
1493
|
+
* const reranker = cohereReranker({ apiKey: process.env.COHERE_API_KEY! });
|
|
1494
|
+
* const hits = await reranker.rerank(query, documents, 5);
|
|
1495
|
+
* ```
|
|
886
1496
|
*/
|
|
1497
|
+
/** Document passed to a reranker — memory id + searchable text. */
|
|
887
1498
|
interface RerankDocument {
|
|
1499
|
+
/** Memory UUID. */
|
|
888
1500
|
id: string;
|
|
1501
|
+
/** Text body used for relevance scoring. */
|
|
889
1502
|
text: string;
|
|
890
1503
|
}
|
|
1504
|
+
/** A reranked hit with relevance score. */
|
|
891
1505
|
interface RerankHit {
|
|
1506
|
+
/** Memory UUID. */
|
|
892
1507
|
id: string;
|
|
1508
|
+
/** Relevance score (higher is better; provider-specific scale). */
|
|
893
1509
|
score: number;
|
|
894
1510
|
}
|
|
895
|
-
/**
|
|
1511
|
+
/**
|
|
1512
|
+
* Contract for cross-encoder and API rerankers.
|
|
1513
|
+
*
|
|
1514
|
+
* Implement this interface to plug in Cohere, Jina, local cross-encoders, or
|
|
1515
|
+
* custom scoring. On failure, built-in HTTP adapters fall back to identity order
|
|
1516
|
+
* so recall never returns zero hits.
|
|
1517
|
+
*
|
|
1518
|
+
* @example Custom provider
|
|
1519
|
+
* ```ts
|
|
1520
|
+
* const myReranker: RerankerProvider = {
|
|
1521
|
+
* name: "local-ce",
|
|
1522
|
+
* async rerank(query, documents, topK) {
|
|
1523
|
+
* return documents.slice(0, topK).map((d, i) => ({ id: d.id, score: 1 - i * 0.1 }));
|
|
1524
|
+
* },
|
|
1525
|
+
* };
|
|
1526
|
+
* ```
|
|
1527
|
+
*/
|
|
896
1528
|
interface RerankerProvider {
|
|
1529
|
+
/** Provider identifier (e.g. `"cohere"`, `"openai"`). */
|
|
897
1530
|
readonly name: string;
|
|
1531
|
+
/**
|
|
1532
|
+
* Reorder documents by query relevance.
|
|
1533
|
+
* @param query - User search string.
|
|
1534
|
+
* @param documents - Candidate memories to rerank.
|
|
1535
|
+
* @param topK - Maximum hits to return.
|
|
1536
|
+
* @returns Hits sorted by score descending.
|
|
1537
|
+
*/
|
|
898
1538
|
rerank(query: string, documents: RerankDocument[], topK: number): Promise<RerankHit[]>;
|
|
899
1539
|
}
|
|
900
|
-
/**
|
|
1540
|
+
/**
|
|
1541
|
+
* Generic cross-encoder reranker for OpenAI-compatible `/rerank` endpoints.
|
|
1542
|
+
*
|
|
1543
|
+
* Falls back to identity order when the HTTP call fails or returns an unexpected shape.
|
|
1544
|
+
*
|
|
1545
|
+
* @param options - Remote endpoint configuration.
|
|
1546
|
+
* @param options.baseUrl - API base URL (appends `/rerank`).
|
|
1547
|
+
* @param options.apiKey - Bearer token for authorization.
|
|
1548
|
+
* @param options.model - Optional model name sent in the request body.
|
|
1549
|
+
* @param options.timeoutMs - Request timeout (default `30000`).
|
|
1550
|
+
*/
|
|
901
1551
|
declare function crossEncoder(options: {
|
|
902
1552
|
baseUrl: string;
|
|
903
1553
|
apiKey: string;
|
|
904
1554
|
model?: string;
|
|
905
1555
|
timeoutMs?: number;
|
|
906
1556
|
}): RerankerProvider;
|
|
1557
|
+
/**
|
|
1558
|
+
* Jina AI reranker (`jina-reranker-v2-base-multilingual` by default).
|
|
1559
|
+
*
|
|
1560
|
+
* @param options.apiKey - Jina API key.
|
|
1561
|
+
* @param options.model - Model id override.
|
|
1562
|
+
* @param options.timeoutMs - Request timeout (default `30000`).
|
|
1563
|
+
*/
|
|
907
1564
|
declare function jinaReranker(options: {
|
|
908
1565
|
apiKey: string;
|
|
909
1566
|
model?: string;
|
|
910
1567
|
timeoutMs?: number;
|
|
911
1568
|
}): RerankerProvider;
|
|
1569
|
+
/**
|
|
1570
|
+
* Cohere Rerank v3.5 API adapter.
|
|
1571
|
+
*
|
|
1572
|
+
* @param options.apiKey - Cohere API key.
|
|
1573
|
+
* @param options.model - Model id (default `"rerank-v3.5"`).
|
|
1574
|
+
* @param options.timeoutMs - Request timeout (default `30000`).
|
|
1575
|
+
*/
|
|
912
1576
|
declare function cohereReranker(options: {
|
|
913
1577
|
apiKey: string;
|
|
914
1578
|
model?: string;
|
|
915
1579
|
timeoutMs?: number;
|
|
916
1580
|
}): RerankerProvider;
|
|
917
|
-
/**
|
|
1581
|
+
/**
|
|
1582
|
+
* BGE-style remote reranker for self-hosted endpoints with Jina/Cohere response shape.
|
|
1583
|
+
*
|
|
1584
|
+
* @param options.apiKey - Bearer token for the remote service.
|
|
1585
|
+
* @param options.baseUrl - Service base URL (appends `/rerank`).
|
|
1586
|
+
* @param options.model - Optional model name.
|
|
1587
|
+
* @param options.timeoutMs - Request timeout (default `30000`).
|
|
1588
|
+
*/
|
|
918
1589
|
declare function bgeReranker(options: {
|
|
919
1590
|
apiKey: string;
|
|
920
1591
|
baseUrl: string;
|
|
@@ -922,8 +1593,20 @@ declare function bgeReranker(options: {
|
|
|
922
1593
|
timeoutMs?: number;
|
|
923
1594
|
}): RerankerProvider;
|
|
924
1595
|
/**
|
|
925
|
-
* OpenAI chat-based reranker (no
|
|
926
|
-
*
|
|
1596
|
+
* OpenAI chat-based reranker (no dedicated rerank API key required).
|
|
1597
|
+
*
|
|
1598
|
+
* Scores query–document relevance via JSON-mode chat completions and reorders hits.
|
|
1599
|
+
* Falls back to identity order on parse or network errors.
|
|
1600
|
+
*
|
|
1601
|
+
* @param options.apiKey - OpenAI API key.
|
|
1602
|
+
* @param options.model - Chat model (default `"gpt-4.1-mini"`).
|
|
1603
|
+
* @param options.baseUrl - API base (default `"https://api.openai.com/v1"`).
|
|
1604
|
+
* @param options.timeoutMs - Request timeout (default `60000`).
|
|
1605
|
+
*
|
|
1606
|
+
* @example
|
|
1607
|
+
* ```ts
|
|
1608
|
+
* const reranker = openaiReranker({ apiKey: process.env.OPENAI_API_KEY! });
|
|
1609
|
+
* ```
|
|
927
1610
|
*/
|
|
928
1611
|
declare function openaiReranker(options: {
|
|
929
1612
|
apiKey: string;
|
|
@@ -933,21 +1616,36 @@ declare function openaiReranker(options: {
|
|
|
933
1616
|
}): RerankerProvider;
|
|
934
1617
|
|
|
935
1618
|
/**
|
|
936
|
-
* Shared provider contracts for Wolbarg
|
|
1619
|
+
* Shared provider contracts for Wolbarg storage layer.
|
|
1620
|
+
*
|
|
1621
|
+
* {@link StorageProvider} is the low-level contract implemented by SQLite and
|
|
1622
|
+
* PostgreSQL backends. Custom storage engines must implement every required method;
|
|
1623
|
+
* optional methods enable performance optimizations (batch fetch, native keyword search).
|
|
937
1624
|
*/
|
|
938
1625
|
|
|
939
|
-
/** Row shape returned from the memories table. */
|
|
1626
|
+
/** Row shape returned from the `memories` table. */
|
|
940
1627
|
interface MemoryRow {
|
|
1628
|
+
/** Memory UUID primary key. */
|
|
941
1629
|
id: string;
|
|
1630
|
+
/** Organization namespace. */
|
|
942
1631
|
organization: string;
|
|
1632
|
+
/** Owning agent id. */
|
|
943
1633
|
agent: string;
|
|
1634
|
+
/** Plain-text memory body. */
|
|
944
1635
|
content_text: string;
|
|
1636
|
+
/** Serialized JSON metadata. */
|
|
945
1637
|
metadata_json: string;
|
|
1638
|
+
/** `1` when soft-archived, `0` when active. */
|
|
946
1639
|
archived: number;
|
|
1640
|
+
/** Summary memory id when archived via compression, else `null`. */
|
|
947
1641
|
compressed_into: string | null;
|
|
1642
|
+
/** SHA-256 of normalized content for exact dedupe, when present. */
|
|
948
1643
|
content_hash?: string | null;
|
|
1644
|
+
/** ISO-8601 creation timestamp. */
|
|
949
1645
|
created_at: string;
|
|
1646
|
+
/** ISO-8601 last update timestamp. */
|
|
950
1647
|
updated_at: string;
|
|
1648
|
+
/** SQLite integer rowid used by vec0 / vector index (when applicable). */
|
|
951
1649
|
rowid?: number;
|
|
952
1650
|
}
|
|
953
1651
|
/** Row shape for memory history events. */
|
|
@@ -994,48 +1692,112 @@ interface VectorSearchHit {
|
|
|
994
1692
|
}
|
|
995
1693
|
/**
|
|
996
1694
|
* Low-level storage provider contract.
|
|
997
|
-
*
|
|
1695
|
+
*
|
|
1696
|
+
* Public Wolbarg API never depends on a specific engine — implement this interface
|
|
1697
|
+
* to add a custom backend (e.g. another SQL dialect or hosted vector store wrapper).
|
|
1698
|
+
*
|
|
1699
|
+
* @example Implementing a custom provider
|
|
1700
|
+
* ```ts
|
|
1701
|
+
* class MyStorage implements StorageProvider {
|
|
1702
|
+
* readonly name = "my-storage";
|
|
1703
|
+
* async open() { /* connect + migrate *\/ }
|
|
1704
|
+
* async close() { /* disconnect *\/ }
|
|
1705
|
+
* // ... implement remaining required methods
|
|
1706
|
+
* }
|
|
1707
|
+
* ```
|
|
998
1708
|
*/
|
|
999
1709
|
interface StorageProvider {
|
|
1710
|
+
/** Backend identifier (e.g. `"sqlite"`, `"postgres"`). */
|
|
1000
1711
|
readonly name: string;
|
|
1001
1712
|
/** Open connection, enable WAL / pragmas, run migrations, prepare statements. */
|
|
1002
1713
|
open(): Promise<void>;
|
|
1003
|
-
/** Close the underlying connection. */
|
|
1714
|
+
/** Close the underlying connection pool or file handle. */
|
|
1004
1715
|
close(): Promise<void>;
|
|
1005
|
-
/**
|
|
1716
|
+
/**
|
|
1717
|
+
* Ensure the vector table exists for the given embedding dimensionality.
|
|
1718
|
+
* @param dimensions - Embedding vector length from the configured model.
|
|
1719
|
+
*/
|
|
1006
1720
|
ensureVectorSchema(dimensions: number): Promise<void>;
|
|
1007
|
-
/**
|
|
1721
|
+
/** @returns Stored embedding dimensions from meta table, or `null` if unset. */
|
|
1008
1722
|
getEmbeddingDimensions(): Promise<number | null>;
|
|
1009
|
-
/**
|
|
1723
|
+
/**
|
|
1724
|
+
* Persist embedding dimensionality in the meta table.
|
|
1725
|
+
* @param dimensions - Vector length to record.
|
|
1726
|
+
*/
|
|
1010
1727
|
setEmbeddingDimensions(dimensions: number): Promise<void>;
|
|
1011
|
-
/**
|
|
1728
|
+
/**
|
|
1729
|
+
* Insert a memory + embedding inside a single ACID transaction.
|
|
1730
|
+
* @param input - Full insert payload including embedding vector.
|
|
1731
|
+
* @returns Inserted row including generated `rowid` when applicable.
|
|
1732
|
+
*/
|
|
1012
1733
|
insertMemory(input: InsertMemoryInput): Promise<MemoryRow>;
|
|
1013
|
-
/**
|
|
1734
|
+
/**
|
|
1735
|
+
* Batch insert memories + embeddings in one transaction.
|
|
1736
|
+
* @param inputs - Non-empty array of insert payloads.
|
|
1737
|
+
*/
|
|
1014
1738
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
1015
|
-
/**
|
|
1739
|
+
/**
|
|
1740
|
+
* Update memory fields and optionally replace embedding.
|
|
1741
|
+
* @param input - Fields to patch; omitted fields are left unchanged.
|
|
1742
|
+
* @returns Updated row, or `null` when id not found.
|
|
1743
|
+
*/
|
|
1016
1744
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
1017
1745
|
/**
|
|
1018
1746
|
* Find an active (non-archived) memory by content hash within org+agent.
|
|
1019
|
-
* Used by write-time exact dedupe.
|
|
1747
|
+
* Used by write-time exact dedupe. Optional — omit when dedupe is disabled.
|
|
1748
|
+
*
|
|
1749
|
+
* @param organization - Organization namespace.
|
|
1750
|
+
* @param agent - Agent id scope.
|
|
1751
|
+
* @param contentHash - SHA-256 from {@link hashMemoryContent}.
|
|
1020
1752
|
*/
|
|
1021
1753
|
findActiveByContentHash?(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
1022
|
-
/**
|
|
1754
|
+
/**
|
|
1755
|
+
* Fetch a memory by UUID.
|
|
1756
|
+
* @param id - Memory id.
|
|
1757
|
+
* @param organization - Organization namespace (authorization scope).
|
|
1758
|
+
*/
|
|
1023
1759
|
getMemoryById(id: string, organization: string): Promise<MemoryRow | null>;
|
|
1024
|
-
/**
|
|
1760
|
+
/**
|
|
1761
|
+
* Fetch a memory by its integer rowid (vector index key).
|
|
1762
|
+
* @param rowid - SQLite rowid or equivalent.
|
|
1763
|
+
* @param organization - Organization namespace.
|
|
1764
|
+
*/
|
|
1025
1765
|
getMemoryByRowid(rowid: number, organization: string): Promise<MemoryRow | null>;
|
|
1026
1766
|
/**
|
|
1027
1767
|
* Batch fetch memories by rowids (one query). Optional — Wolbarg falls
|
|
1028
|
-
* back to parallel getMemoryByRowid when absent.
|
|
1768
|
+
* back to parallel `getMemoryByRowid` when absent.
|
|
1769
|
+
*
|
|
1770
|
+
* @param rowids - Vector index row identifiers.
|
|
1771
|
+
* @param organization - Organization namespace.
|
|
1772
|
+
* @returns Map from rowid to row for hits only.
|
|
1029
1773
|
*/
|
|
1030
1774
|
getMemoriesByRowids?(rowids: number[], organization: string): Promise<Map<number, MemoryRow>>;
|
|
1031
|
-
/**
|
|
1775
|
+
/**
|
|
1776
|
+
* List memories matching a filter.
|
|
1777
|
+
* @param filter - Organization, optional agent, archive, and metadata scope.
|
|
1778
|
+
* @param limit - Maximum rows (backend default when omitted).
|
|
1779
|
+
*/
|
|
1032
1780
|
listMemories(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
1033
|
-
/**
|
|
1781
|
+
/**
|
|
1782
|
+
* Search memories by metadata filter only (no vector query).
|
|
1783
|
+
* @param filter - Must include organization; optional metadata AST.
|
|
1784
|
+
* @param limit - Maximum rows to return.
|
|
1785
|
+
*/
|
|
1034
1786
|
searchByMetadata(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
1035
|
-
/**
|
|
1787
|
+
/**
|
|
1788
|
+
* KNN search against the vector index.
|
|
1789
|
+
* @param embedding - Query vector (same dimensionality as stored memories).
|
|
1790
|
+
* @param topK - Number of nearest neighbors.
|
|
1791
|
+
* @returns Hits with cosine distance (lower is more similar for sqlite-vec).
|
|
1792
|
+
*/
|
|
1036
1793
|
searchVectors(embedding: Float32Array, topK: number): Promise<VectorSearchHit[]>;
|
|
1037
1794
|
/**
|
|
1038
1795
|
* Optional: KNN + memory rows in one round-trip, org-scoped.
|
|
1796
|
+
*
|
|
1797
|
+
* @param embedding - Query vector.
|
|
1798
|
+
* @param topK - Neighbor count.
|
|
1799
|
+
* @param organization - Organization filter applied in SQL.
|
|
1800
|
+
* @param options - Optional agent filter and archive inclusion.
|
|
1039
1801
|
*/
|
|
1040
1802
|
searchVectorsWithMemories?(embedding: Float32Array, topK: number, organization: string, options?: {
|
|
1041
1803
|
agent?: string;
|
|
@@ -1047,6 +1809,10 @@ interface StorageProvider {
|
|
|
1047
1809
|
/**
|
|
1048
1810
|
* Optional: native keyword / BM25 search (e.g. SQLite FTS5).
|
|
1049
1811
|
* When present, hybrid recall can skip loading the full corpus.
|
|
1812
|
+
*
|
|
1813
|
+
* @param query - User search string.
|
|
1814
|
+
* @param organization - Organization namespace.
|
|
1815
|
+
* @param topK - Maximum lexical hits.
|
|
1050
1816
|
*/
|
|
1051
1817
|
searchKeyword?(query: string, organization: string, topK: number): Promise<Array<{
|
|
1052
1818
|
memoryId: string;
|
|
@@ -1054,20 +1820,40 @@ interface StorageProvider {
|
|
|
1054
1820
|
}>>;
|
|
1055
1821
|
/**
|
|
1056
1822
|
* Soft-archive memories and record lineage linking them to a summary.
|
|
1057
|
-
*
|
|
1823
|
+
*
|
|
1824
|
+
* @param ids - Memory UUIDs to archive.
|
|
1825
|
+
* @param organization - Organization namespace.
|
|
1826
|
+
* @param compressedIntoId - New summary memory id.
|
|
1827
|
+
* @param archivedAt - ISO timestamp for the archive event.
|
|
1828
|
+
* @returns The archived memory ids actually updated.
|
|
1058
1829
|
*/
|
|
1059
1830
|
archiveMemories(ids: string[], organization: string, compressedIntoId: string, archivedAt: string): Promise<string[]>;
|
|
1060
|
-
/**
|
|
1831
|
+
/**
|
|
1832
|
+
* Hard-delete a single memory and its embedding.
|
|
1833
|
+
* @returns `true` when a row was deleted.
|
|
1834
|
+
*/
|
|
1061
1835
|
deleteMemoryById(id: string, organization: string): Promise<boolean>;
|
|
1062
|
-
/**
|
|
1836
|
+
/**
|
|
1837
|
+
* Hard-delete memories matching a filter.
|
|
1838
|
+
* @returns Count of deleted rows.
|
|
1839
|
+
*/
|
|
1063
1840
|
deleteMemoriesByFilter(filter: RepositoryFilter): Promise<number>;
|
|
1064
|
-
/**
|
|
1841
|
+
/**
|
|
1842
|
+
* Delete every memory for an organization.
|
|
1843
|
+
* @returns Count of deleted rows.
|
|
1844
|
+
*/
|
|
1065
1845
|
clearOrganization(organization: string): Promise<number>;
|
|
1066
|
-
/**
|
|
1846
|
+
/**
|
|
1847
|
+
* History events for a memory, oldest first.
|
|
1848
|
+
* @param memoryId - Memory UUID.
|
|
1849
|
+
*/
|
|
1067
1850
|
getHistory(memoryId: string): Promise<HistoryRow[]>;
|
|
1068
|
-
/** Append a history event. */
|
|
1851
|
+
/** Append a history event (created, archived, compressed, updated). */
|
|
1069
1852
|
insertHistoryEvent(event: HistoryRow): Promise<void>;
|
|
1070
|
-
/**
|
|
1853
|
+
/**
|
|
1854
|
+
* Count memories / distinct agents for an organization.
|
|
1855
|
+
* @param organization - Organization namespace.
|
|
1856
|
+
*/
|
|
1071
1857
|
getStats(organization: string): Promise<{
|
|
1072
1858
|
totalMemories: number;
|
|
1073
1859
|
activeMemories: number;
|
|
@@ -1076,55 +1862,121 @@ interface StorageProvider {
|
|
|
1076
1862
|
}>;
|
|
1077
1863
|
/** Approximate on-disk database size in bytes. */
|
|
1078
1864
|
getDatabaseSizeBytes(): Promise<number>;
|
|
1079
|
-
/**
|
|
1865
|
+
/**
|
|
1866
|
+
* Run `fn` inside a single ACID transaction.
|
|
1867
|
+
* @param fn - Synchronous or async work executed atomically.
|
|
1868
|
+
* @returns Value returned by `fn`.
|
|
1869
|
+
*/
|
|
1080
1870
|
withTransaction<T>(fn: () => T | Promise<T>): T | Promise<T>;
|
|
1081
1871
|
}
|
|
1082
|
-
/** Back-compat alias. */
|
|
1872
|
+
/** Back-compat alias for {@link StorageProvider}. */
|
|
1083
1873
|
type DatabaseProvider = StorageProvider;
|
|
1084
1874
|
|
|
1085
1875
|
/**
|
|
1086
|
-
* Database-agnostic checkpoint contract.
|
|
1087
|
-
*
|
|
1876
|
+
* Database-agnostic checkpoint contract for memory snapshots.
|
|
1877
|
+
*
|
|
1878
|
+
* Checkpoints copy file-backed SQLite memory databases so callers can rollback
|
|
1879
|
+
* without third-party backup libraries.
|
|
1088
1880
|
*/
|
|
1881
|
+
/** Metadata recorded for each named checkpoint. */
|
|
1089
1882
|
interface CheckpointMeta {
|
|
1883
|
+
/** User-provided checkpoint name (unique). */
|
|
1090
1884
|
name: string;
|
|
1885
|
+
/** Optional human description. */
|
|
1091
1886
|
description: string | null;
|
|
1887
|
+
/** ISO-8601 creation time. */
|
|
1092
1888
|
createdAt: string;
|
|
1889
|
+
/** Wolbarg SDK version that created the checkpoint. */
|
|
1093
1890
|
sdkVersion: string;
|
|
1891
|
+
/** Storage provider name (e.g. `"sqlite"`). */
|
|
1094
1892
|
provider: string;
|
|
1095
1893
|
/** Absolute path or URI of the snapshot artifact. */
|
|
1096
1894
|
snapshotPath: string;
|
|
1097
1895
|
/** Absolute path or URI of the source memory database at creation time. */
|
|
1098
1896
|
sourcePath: string;
|
|
1897
|
+
/** On-disk snapshot size in bytes. */
|
|
1099
1898
|
sizeBytes: number;
|
|
1100
1899
|
}
|
|
1900
|
+
/** Options passed to {@link CheckpointProvider.checkpoint}. */
|
|
1101
1901
|
interface CreateCheckpointOptions {
|
|
1902
|
+
/** Optional description stored in {@link CheckpointMeta}. */
|
|
1102
1903
|
description?: string;
|
|
1103
1904
|
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Checkpoint provider contract — create, list, restore, and delete snapshots.
|
|
1907
|
+
*
|
|
1908
|
+
* Implement this interface for custom snapshot storage (S3, tarball, etc.).
|
|
1909
|
+
* Built-in: {@link SqliteCheckpointProvider}.
|
|
1910
|
+
*
|
|
1911
|
+
* @example
|
|
1912
|
+
* ```ts
|
|
1913
|
+
* await checkpointProvider.checkpoint("pre-migration", sourceDbPath, {
|
|
1914
|
+
* description: "Before schema migration",
|
|
1915
|
+
* });
|
|
1916
|
+
* ```
|
|
1917
|
+
*/
|
|
1104
1918
|
interface CheckpointProvider {
|
|
1919
|
+
/** Provider identifier. */
|
|
1105
1920
|
readonly name: string;
|
|
1106
1921
|
/** Prepare checkpoint storage (directories / tables). */
|
|
1107
1922
|
open(): Promise<void>;
|
|
1923
|
+
/** Close checkpoint storage handles. */
|
|
1108
1924
|
close(): Promise<void>;
|
|
1109
1925
|
/**
|
|
1110
1926
|
* Create a named snapshot of the current memory database.
|
|
1111
1927
|
* Must fail if the name already exists (never overwrite).
|
|
1928
|
+
*
|
|
1929
|
+
* @param name - Unique checkpoint name.
|
|
1930
|
+
* @param sourcePath - Live memory database path to snapshot.
|
|
1931
|
+
* @param options - Optional description.
|
|
1112
1932
|
*/
|
|
1113
1933
|
checkpoint(name: string, sourcePath: string, options?: CreateCheckpointOptions): Promise<CheckpointMeta>;
|
|
1114
|
-
/**
|
|
1934
|
+
/**
|
|
1935
|
+
* Restore the memory database from a named checkpoint.
|
|
1936
|
+
*
|
|
1937
|
+
* @param name - Existing checkpoint name.
|
|
1938
|
+
* @param targetPath - Path to overwrite with the snapshot.
|
|
1939
|
+
*/
|
|
1115
1940
|
rollback(name: string, targetPath: string): Promise<CheckpointMeta>;
|
|
1116
|
-
/**
|
|
1941
|
+
/**
|
|
1942
|
+
* Permanently remove a checkpoint and its snapshot files.
|
|
1943
|
+
* @returns `true` when a checkpoint was deleted.
|
|
1944
|
+
*/
|
|
1117
1945
|
deleteCheckpoint(name: string): Promise<boolean>;
|
|
1946
|
+
/** List all checkpoints ordered by creation time. */
|
|
1118
1947
|
listCheckpoints(): Promise<CheckpointMeta[]>;
|
|
1948
|
+
/**
|
|
1949
|
+
* Fetch metadata for one checkpoint.
|
|
1950
|
+
* @param name - Checkpoint name.
|
|
1951
|
+
*/
|
|
1119
1952
|
getCheckpoint(name: string): Promise<CheckpointMeta | null>;
|
|
1120
1953
|
}
|
|
1121
1954
|
|
|
1122
1955
|
/**
|
|
1123
1956
|
* Database-agnostic telemetry persistence contract.
|
|
1124
|
-
*
|
|
1957
|
+
*
|
|
1958
|
+
* Telemetry MUST use a separate database from memory storage — never share tables.
|
|
1125
1959
|
*/
|
|
1126
1960
|
|
|
1961
|
+
/**
|
|
1962
|
+
* Telemetry provider contract — async, non-blocking event emission.
|
|
1963
|
+
*
|
|
1964
|
+
* Implement this interface for custom observability sinks (OpenTelemetry export,
|
|
1965
|
+
* cloud logging, etc.). Built-in: SQLite telemetry via {@link SqliteTelemetryProvider}.
|
|
1966
|
+
*
|
|
1967
|
+
* @example Custom write-only provider
|
|
1968
|
+
* ```ts
|
|
1969
|
+
* const provider: TelemetryProvider = {
|
|
1970
|
+
* name: "console",
|
|
1971
|
+
* async open() {},
|
|
1972
|
+
* async close() {},
|
|
1973
|
+
* emit(event) { console.log(event.operation, event.durationMs); },
|
|
1974
|
+
* async flush() {},
|
|
1975
|
+
* };
|
|
1976
|
+
* ```
|
|
1977
|
+
*/
|
|
1127
1978
|
interface TelemetryProvider {
|
|
1979
|
+
/** Provider identifier (e.g. `"sqlite-telemetry"`, `"noop"`). */
|
|
1128
1980
|
readonly name: string;
|
|
1129
1981
|
/** Open the independent event database connection. */
|
|
1130
1982
|
open(): Promise<void>;
|
|
@@ -1133,34 +1985,106 @@ interface TelemetryProvider {
|
|
|
1133
1985
|
/**
|
|
1134
1986
|
* Persist a telemetry event. Must not block callers of memory operations.
|
|
1135
1987
|
* Implementations may queue and flush asynchronously.
|
|
1988
|
+
*
|
|
1989
|
+
* @param event - Fully or partially populated event input.
|
|
1136
1990
|
*/
|
|
1137
1991
|
emit(event: TelemetryEventInput): void;
|
|
1138
|
-
/** Wait until the write queue is empty (used by tests / shutdown). */
|
|
1992
|
+
/** Wait until the write queue is empty (used by tests / graceful shutdown). */
|
|
1139
1993
|
flush(): Promise<void>;
|
|
1140
|
-
/**
|
|
1994
|
+
/**
|
|
1995
|
+
* Read events (primarily for Studio / debugging). Optional for write-only backends.
|
|
1996
|
+
* @param options - Query filters and pagination.
|
|
1997
|
+
*/
|
|
1141
1998
|
query?(options: TelemetryQuery): Promise<TelemetryQueryResult>;
|
|
1142
|
-
/**
|
|
1999
|
+
/**
|
|
2000
|
+
* Fetch a single event by id.
|
|
2001
|
+
* @param id - Event UUID.
|
|
2002
|
+
*/
|
|
1143
2003
|
getEvent?(id: string): Promise<TelemetryEvent | null>;
|
|
1144
2004
|
}
|
|
1145
2005
|
|
|
1146
2006
|
/**
|
|
1147
|
-
* Optional vision
|
|
2007
|
+
* Optional vision providers — captions, descriptions, and entities from images.
|
|
2008
|
+
*
|
|
2009
|
+
* Vision analysis enriches image ingest when OCR alone is insufficient. Both
|
|
2010
|
+
* {@link openaiVision} and {@link geminiVision} use OpenAI-compatible chat
|
|
2011
|
+
* endpoints with multimodal messages.
|
|
2012
|
+
*
|
|
2013
|
+
* @example
|
|
2014
|
+
* ```ts
|
|
2015
|
+
* import { openaiVision } from "wolbarg/vision";
|
|
2016
|
+
*
|
|
2017
|
+
* const vision = openaiVision({ apiKey: process.env.OPENAI_API_KEY! });
|
|
2018
|
+
* const result = await vision.analyze(imageBuffer, "image/jpeg");
|
|
2019
|
+
* console.log(result.caption, result.entities);
|
|
2020
|
+
* ```
|
|
1148
2021
|
*/
|
|
2022
|
+
/** Structured output from a vision analysis call. */
|
|
1149
2023
|
interface VisionResult {
|
|
2024
|
+
/** Short one-line caption. */
|
|
1150
2025
|
caption: string;
|
|
2026
|
+
/** Longer natural-language description. */
|
|
1151
2027
|
description: string;
|
|
2028
|
+
/** Named entities or objects detected in the image. */
|
|
1152
2029
|
entities: string[];
|
|
1153
2030
|
}
|
|
2031
|
+
/**
|
|
2032
|
+
* Contract for vision / multimodal analysis backends.
|
|
2033
|
+
*
|
|
2034
|
+
* Implement this interface to plug in Claude, local VLMs, or custom APIs.
|
|
2035
|
+
* Wolbarg merges vision output into ingest metadata when processing images.
|
|
2036
|
+
*
|
|
2037
|
+
* @example Custom provider
|
|
2038
|
+
* ```ts
|
|
2039
|
+
* const myVision: VisionProvider = {
|
|
2040
|
+
* name: "my-vlm",
|
|
2041
|
+
* async analyze(image, mimeType) {
|
|
2042
|
+
* return { caption: "...", description: "...", entities: ["cat"] };
|
|
2043
|
+
* },
|
|
2044
|
+
* };
|
|
2045
|
+
* ```
|
|
2046
|
+
*/
|
|
1154
2047
|
interface VisionProvider {
|
|
2048
|
+
/** Provider identifier (e.g. `"openai-vision"`, `"gemini"`). */
|
|
1155
2049
|
readonly name: string;
|
|
2050
|
+
/**
|
|
2051
|
+
* Analyze an image and return structured caption data.
|
|
2052
|
+
* @param image - Raw image bytes.
|
|
2053
|
+
* @param mimeType - MIME type for the data URL (default `"image/png"`).
|
|
2054
|
+
*/
|
|
1156
2055
|
analyze(image: Buffer, mimeType?: string): Promise<VisionResult>;
|
|
1157
2056
|
}
|
|
2057
|
+
/**
|
|
2058
|
+
* Google Gemini vision via the OpenAI-compatible Generative Language API.
|
|
2059
|
+
*
|
|
2060
|
+
* @param options - API credentials and model selection.
|
|
2061
|
+
* @param options.apiKey - Gemini API key.
|
|
2062
|
+
* @param options.model - Model id (default `"gemini-2.0-flash"`).
|
|
2063
|
+
* @param options.baseUrl - Override API base (default Google OpenAI-compat endpoint).
|
|
2064
|
+
* @param options.timeoutMs - Request timeout in milliseconds (default `60000`).
|
|
2065
|
+
* @returns A {@link VisionProvider} instance.
|
|
2066
|
+
*/
|
|
1158
2067
|
declare function geminiVision(options: {
|
|
1159
2068
|
apiKey: string;
|
|
1160
2069
|
model?: string;
|
|
1161
2070
|
baseUrl?: string;
|
|
1162
2071
|
timeoutMs?: number;
|
|
1163
2072
|
}): VisionProvider;
|
|
2073
|
+
/**
|
|
2074
|
+
* OpenAI vision via `/chat/completions` with image_url content parts.
|
|
2075
|
+
*
|
|
2076
|
+
* @param options - API credentials and model selection.
|
|
2077
|
+
* @param options.apiKey - OpenAI API key.
|
|
2078
|
+
* @param options.model - Vision-capable model (default `"gpt-4o-mini"`).
|
|
2079
|
+
* @param options.baseUrl - Override API base (default `"https://api.openai.com/v1"`).
|
|
2080
|
+
* @param options.timeoutMs - Request timeout in milliseconds (default `60000`).
|
|
2081
|
+
* @returns A {@link VisionProvider} instance.
|
|
2082
|
+
*
|
|
2083
|
+
* @example
|
|
2084
|
+
* ```ts
|
|
2085
|
+
* const vision = openaiVision({ apiKey: process.env.OPENAI_API_KEY! });
|
|
2086
|
+
* ```
|
|
2087
|
+
*/
|
|
1164
2088
|
declare function openaiVision(options: {
|
|
1165
2089
|
apiKey: string;
|
|
1166
2090
|
model?: string;
|
|
@@ -1169,40 +2093,104 @@ declare function openaiVision(options: {
|
|
|
1169
2093
|
}): VisionProvider;
|
|
1170
2094
|
|
|
1171
2095
|
/**
|
|
1172
|
-
* Constructor options for Wolbarg v0.
|
|
2096
|
+
* Constructor options for Wolbarg (v0.5.5).
|
|
2097
|
+
*
|
|
2098
|
+
* Pass **provider instances** (custom implementations of the interfaces) or
|
|
2099
|
+
* **config objects / factory helpers**. Discriminated at runtime via
|
|
2100
|
+
* {@link isEmbeddingProvider}, {@link isLlmProvider}, {@link isStorageProvider},
|
|
2101
|
+
* {@link isTelemetryProvider}, and {@link isGraphProvider}.
|
|
1173
2102
|
*/
|
|
1174
2103
|
|
|
2104
|
+
/**
|
|
2105
|
+
* Embedding input: a live {@link EmbeddingProvider} **or** an
|
|
2106
|
+
* {@link EmbeddingConfig} / factory result (`openaiEmbedding(...)`, etc.).
|
|
2107
|
+
*
|
|
2108
|
+
* Custom provider example:
|
|
2109
|
+
* ```ts
|
|
2110
|
+
* const embedding: EmbeddingProvider = {
|
|
2111
|
+
* model: "custom",
|
|
2112
|
+
* embed: async (text) => { /* return Float32Array *\/ },
|
|
2113
|
+
* validate: async () => ({ dimensions: 768 }),
|
|
2114
|
+
* };
|
|
2115
|
+
* ```
|
|
2116
|
+
*/
|
|
1175
2117
|
type EmbeddingInput = EmbeddingProvider | EmbeddingConfig;
|
|
2118
|
+
/**
|
|
2119
|
+
* LLM input: a live {@link LlmProvider} **or** an {@link LlmConfig} /
|
|
2120
|
+
* factory result (`openaiLlm(...)`, `ollamaLlm(...)`, etc.).
|
|
2121
|
+
*
|
|
2122
|
+
* Required for {@link Wolbarg.compress} and `rememberFromMessages({ mode: "extract" })`.
|
|
2123
|
+
*
|
|
2124
|
+
* Custom provider example:
|
|
2125
|
+
* ```ts
|
|
2126
|
+
* const llm: LlmProvider = {
|
|
2127
|
+
* model: "my-model",
|
|
2128
|
+
* complete: async (messages) => { /* return assistant text *\/ },
|
|
2129
|
+
* validate: async () => { /* ping endpoint *\/ },
|
|
2130
|
+
* };
|
|
2131
|
+
* ```
|
|
2132
|
+
*/
|
|
1176
2133
|
type LlmInput = LlmProvider | LlmConfig;
|
|
2134
|
+
/**
|
|
2135
|
+
* Storage input: a live {@link StorageProvider} **or** a
|
|
2136
|
+
* {@link StorageConfig} / {@link DatabaseConfig} (`{ provider: "sqlite", url }`).
|
|
2137
|
+
*/
|
|
1177
2138
|
type StorageInput = StorageProvider | StorageConfig | DatabaseConfig;
|
|
2139
|
+
/**
|
|
2140
|
+
* Graph input: a live {@link GraphProvider} **or** a {@link GraphConfig}
|
|
2141
|
+
* (`sqliteGraph({ path })` / `neo4jGraph({ url, username, password })`).
|
|
2142
|
+
*/
|
|
1178
2143
|
type GraphInput = GraphProvider | GraphConfig;
|
|
2144
|
+
/**
|
|
2145
|
+
* Shared constructor fields (with or without LLM).
|
|
2146
|
+
*/
|
|
1179
2147
|
interface WolbargOptionsBase {
|
|
1180
2148
|
/** Organization namespace isolating memories within a shared database. */
|
|
1181
2149
|
organization: string;
|
|
1182
2150
|
/**
|
|
1183
2151
|
* Storage provider instance or config.
|
|
1184
|
-
* Prefer `database` in
|
|
2152
|
+
* Prefer `database` in docs; `storage` remains fully supported.
|
|
1185
2153
|
*/
|
|
1186
2154
|
storage?: StorageInput;
|
|
1187
2155
|
/**
|
|
1188
|
-
*
|
|
2156
|
+
* Alias for `storage`. Accepts `{ provider, url }` or `{ provider, connectionString }`,
|
|
2157
|
+
* or a custom {@link StorageProvider}.
|
|
1189
2158
|
*/
|
|
1190
2159
|
database?: StorageInput;
|
|
1191
|
-
/**
|
|
2160
|
+
/**
|
|
2161
|
+
* Embedding provider instance or config.
|
|
2162
|
+
* Use {@link openaiEmbedding} / {@link ollamaEmbedding} / etc., raw
|
|
2163
|
+
* {@link EmbeddingConfig}, or any custom {@link EmbeddingProvider}.
|
|
2164
|
+
*/
|
|
1192
2165
|
embedding: EmbeddingInput;
|
|
1193
|
-
/**
|
|
2166
|
+
/**
|
|
2167
|
+
* Optional independent telemetry system (separate database or custom
|
|
2168
|
+
* {@link TelemetryProvider}).
|
|
2169
|
+
*/
|
|
1194
2170
|
telemetry?: TelemetryConfig | TelemetryProvider;
|
|
1195
2171
|
/** Optional checkpoint provider override (defaults to SQLite when file-backed). */
|
|
1196
2172
|
checkpoint?: CheckpointProvider;
|
|
1197
2173
|
/** Optional directory for SQLite checkpoints. */
|
|
1198
2174
|
checkpointDirectory?: string;
|
|
1199
|
-
/**
|
|
2175
|
+
/**
|
|
2176
|
+
* Optional reranker — skipped when absent.
|
|
2177
|
+
* Implement {@link RerankerProvider} or use `jinaReranker` / `cohereReranker` / etc.
|
|
2178
|
+
*/
|
|
1200
2179
|
reranker?: RerankerProvider;
|
|
1201
|
-
/**
|
|
2180
|
+
/**
|
|
2181
|
+
* Optional keyword search — enables hybrid recall when present.
|
|
2182
|
+
* Implement {@link KeywordSearchProvider} or use {@link bm25}.
|
|
2183
|
+
*/
|
|
1202
2184
|
keywordSearch?: KeywordSearchProvider;
|
|
1203
|
-
/**
|
|
2185
|
+
/**
|
|
2186
|
+
* Optional OCR for image ingest.
|
|
2187
|
+
* Implement {@link OCRProvider} or use {@link tesseract}.
|
|
2188
|
+
*/
|
|
1204
2189
|
ocr?: OCRProvider;
|
|
1205
|
-
/**
|
|
2190
|
+
/**
|
|
2191
|
+
* Optional vision model for image captions during ingest.
|
|
2192
|
+
* Implement {@link VisionProvider} or use {@link openaiVision} / {@link geminiVision}.
|
|
2193
|
+
*/
|
|
1206
2194
|
vision?: VisionProvider;
|
|
1207
2195
|
/**
|
|
1208
2196
|
* Optional graph memory layer (SQLite embedded or Neo4j networked).
|
|
@@ -1210,11 +2198,17 @@ interface WolbargOptionsBase {
|
|
|
1210
2198
|
* Accepts a {@link GraphProvider} instance or a recognized config shape.
|
|
1211
2199
|
*/
|
|
1212
2200
|
graph?: GraphInput;
|
|
1213
|
-
/**
|
|
2201
|
+
/**
|
|
2202
|
+
* Optional compression provider (overrides the default LLM-backed compressor).
|
|
2203
|
+
* Implement {@link CompressionProvider} for a fully custom compress pipeline.
|
|
2204
|
+
*/
|
|
1214
2205
|
compression?: CompressionProvider;
|
|
1215
|
-
/**
|
|
2206
|
+
/**
|
|
2207
|
+
* Optional default chunking strategy for ingest.
|
|
2208
|
+
* Implement {@link ChunkingStrategy} or use `createChunkingStrategy(...)`.
|
|
2209
|
+
*/
|
|
1216
2210
|
chunking?: ChunkingStrategy;
|
|
1217
|
-
/** Optional retrieval defaults. */
|
|
2211
|
+
/** Optional retrieval defaults (over-fetch, hybrid weights, MMR). */
|
|
1218
2212
|
retrieval?: RetrievalConfig;
|
|
1219
2213
|
/** SQLite multi-writer concurrency tuning (ignored for Postgres). */
|
|
1220
2214
|
concurrency?: ConcurrencyConfig$1;
|
|
@@ -1222,43 +2216,86 @@ interface WolbargOptionsBase {
|
|
|
1222
2216
|
embeddingCache?: EmbeddingCacheConfig;
|
|
1223
2217
|
/** Memory write-path options (dedupe / upsert). */
|
|
1224
2218
|
memory?: {
|
|
2219
|
+
/** Exact / near-duplicate detection on remember. See {@link MemoryDedupeConfig}. */
|
|
1225
2220
|
dedupe?: MemoryDedupeConfig;
|
|
1226
2221
|
};
|
|
1227
2222
|
}
|
|
2223
|
+
/**
|
|
2224
|
+
* Options when no LLM is configured (`compress` / extract mode unavailable).
|
|
2225
|
+
*/
|
|
1228
2226
|
interface WolbargOptionsWithoutLlm extends WolbargOptionsBase {
|
|
1229
2227
|
llm?: undefined;
|
|
1230
2228
|
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Options when an LLM is configured (enables {@link Wolbarg.compress}).
|
|
2231
|
+
*/
|
|
1231
2232
|
interface WolbargOptionsWithLlm extends WolbargOptionsBase {
|
|
1232
|
-
/**
|
|
2233
|
+
/**
|
|
2234
|
+
* Chat model used for compression and extract-mode rememberFromMessages.
|
|
2235
|
+
* Pass a custom {@link LlmProvider} (`complete` + `validate`) or a config /
|
|
2236
|
+
* factory such as {@link openaiLlm} / {@link ollamaLlm} /
|
|
2237
|
+
* {@link openaiCompatibleLlm}.
|
|
2238
|
+
*/
|
|
1233
2239
|
llm: LlmInput;
|
|
1234
2240
|
}
|
|
2241
|
+
/** Discriminated union of constructor options. */
|
|
1235
2242
|
type WolbargOptions = WolbargOptionsWithoutLlm | WolbargOptionsWithLlm;
|
|
1236
2243
|
|
|
1237
2244
|
/**
|
|
1238
2245
|
* Public subscribe() types for real-time memory change events.
|
|
2246
|
+
*
|
|
2247
|
+
* Agents and dashboards use these types with `wolbarg.subscribe()` to receive
|
|
2248
|
+
* push notifications when memories are created, updated, forgotten, compressed, or ingested.
|
|
2249
|
+
*
|
|
2250
|
+
* @example
|
|
2251
|
+
* ```ts
|
|
2252
|
+
* const unsub = wolbarg.subscribe(
|
|
2253
|
+
* { organization: "acme", event: "remember" },
|
|
2254
|
+
* (event) => console.log(event.memoryId),
|
|
2255
|
+
* );
|
|
2256
|
+
* ```
|
|
1239
2257
|
*/
|
|
2258
|
+
/** Event names that can be filtered in {@link SubscribeFilter.event}. */
|
|
1240
2259
|
type SubscribableEvent = "remember" | "update" | "forget" | "compress" | "ingest" | "*";
|
|
2260
|
+
/** Filter passed to `wolbarg.subscribe()` to scope notifications. */
|
|
1241
2261
|
interface SubscribeFilter {
|
|
2262
|
+
/** Organization namespace (required). */
|
|
1242
2263
|
organization: string;
|
|
2264
|
+
/** Optional agent id — omit to receive events for all agents. */
|
|
1243
2265
|
agent?: string;
|
|
2266
|
+
/** Single event, list of events, or `"*"` for all (default all when omitted). */
|
|
1244
2267
|
event?: SubscribableEvent | SubscribableEvent[];
|
|
1245
2268
|
}
|
|
2269
|
+
/** Payload delivered to {@link MemoryChangeCallback} listeners. */
|
|
1246
2270
|
interface MemoryChangeEvent {
|
|
2271
|
+
/** Operation that triggered the notification. */
|
|
1247
2272
|
event: Exclude<SubscribableEvent, "*">;
|
|
2273
|
+
/** Organization namespace. */
|
|
1248
2274
|
organization: string;
|
|
2275
|
+
/** Agent that performed the operation. */
|
|
1249
2276
|
agent: string;
|
|
2277
|
+
/** Affected memory id, or multiple ids for batch operations. */
|
|
1250
2278
|
memoryId: string | string[];
|
|
2279
|
+
/** ISO-8601 timestamp when the change occurred. */
|
|
1251
2280
|
timestamp: string;
|
|
2281
|
+
/** Optional telemetry trace id linking to observability events. */
|
|
1252
2282
|
traceId?: string;
|
|
2283
|
+
/** Optional session id from the originating SDK instance. */
|
|
1253
2284
|
sessionId?: string;
|
|
1254
2285
|
/** Present when upsert path ran during remember/ingest. */
|
|
1255
2286
|
upsertAction?: "created" | "updated" | "skipped";
|
|
1256
2287
|
}
|
|
2288
|
+
/** Callback invoked for each matching memory change event. */
|
|
1257
2289
|
type MemoryChangeCallback = (event: MemoryChangeEvent) => void;
|
|
2290
|
+
/** Function returned from subscribe — call to remove the listener. */
|
|
1258
2291
|
type Unsubscribe = () => void;
|
|
1259
2292
|
|
|
1260
2293
|
/**
|
|
1261
|
-
* Wolbarg — modular semantic memory SDK for AI agents (v0.
|
|
2294
|
+
* Wolbarg — modular semantic memory SDK for AI agents (v0.5.5).
|
|
2295
|
+
*
|
|
2296
|
+
* Construct with {@link wolbarg} or `new Wolbarg(options)`. Pass provider
|
|
2297
|
+
* **instances** (custom implementations) or **configs / factory helpers**
|
|
2298
|
+
* for embedding, LLM, storage, graph, and optional plugins.
|
|
1262
2299
|
*
|
|
1263
2300
|
* @example
|
|
1264
2301
|
* ```ts
|
|
@@ -1271,6 +2308,11 @@ type Unsubscribe = () => void;
|
|
|
1271
2308
|
* apiKey: process.env.OPENAI_API_KEY!,
|
|
1272
2309
|
* model: "text-embedding-3-small",
|
|
1273
2310
|
* }),
|
|
2311
|
+
* // Optional — required for compress() and rememberFromMessages({ mode: "extract" })
|
|
2312
|
+
* llm: openaiLlm({
|
|
2313
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
2314
|
+
* model: "gpt-4o-mini",
|
|
2315
|
+
* }),
|
|
1274
2316
|
* telemetry: {
|
|
1275
2317
|
* enabled: true,
|
|
1276
2318
|
* database: { provider: "sqlite", url: "./telemetry.db" },
|
|
@@ -1284,7 +2326,14 @@ type Unsubscribe = () => void;
|
|
|
1284
2326
|
* ```
|
|
1285
2327
|
*/
|
|
1286
2328
|
|
|
2329
|
+
/**
|
|
2330
|
+
* Main Wolbarg facade: remember / recall / ingest / graph / checkpoints.
|
|
2331
|
+
*
|
|
2332
|
+
* @typeParam HasLlm - `true` when constructed with an `llm` (enables
|
|
2333
|
+
* {@link Wolbarg.compress} at the type level).
|
|
2334
|
+
*/
|
|
1287
2335
|
declare class Wolbarg<HasLlm extends boolean = false> {
|
|
2336
|
+
/** Compile-time marker: `true` when an LLM was configured at construction. */
|
|
1288
2337
|
readonly __hasLlm: HasLlm;
|
|
1289
2338
|
private initialized;
|
|
1290
2339
|
private booting;
|
|
@@ -1311,19 +2360,67 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1311
2360
|
private memoryDedupe;
|
|
1312
2361
|
private embeddingCacheConfig;
|
|
1313
2362
|
private rawEmbedding;
|
|
2363
|
+
/**
|
|
2364
|
+
* Create a Wolbarg instance with an LLM (enables {@link Wolbarg.compress}).
|
|
2365
|
+
*
|
|
2366
|
+
* @param options - See {@link WolbargOptionsWithLlm}. `llm` may be a custom
|
|
2367
|
+
* {@link LlmProvider} (`{ model, complete, validate }`) or a config /
|
|
2368
|
+
* factory result such as {@link openaiLlm}.
|
|
2369
|
+
*/
|
|
1314
2370
|
constructor(options: WolbargOptionsWithLlm);
|
|
2371
|
+
/**
|
|
2372
|
+
* Create a Wolbarg instance without an LLM (compress / extract mode unavailable).
|
|
2373
|
+
*
|
|
2374
|
+
* @param options - See {@link WolbargOptionsWithoutLlm}.
|
|
2375
|
+
*/
|
|
1315
2376
|
constructor(options: WolbargOptionsWithoutLlm);
|
|
2377
|
+
/**
|
|
2378
|
+
* Empty constructor for the legacy {@link Wolbarg.init} flow.
|
|
2379
|
+
* Prefer passing options to the constructor or {@link wolbarg}.
|
|
2380
|
+
*/
|
|
1316
2381
|
constructor();
|
|
1317
2382
|
/**
|
|
1318
2383
|
* Backwards-compatible initialization (v0.1 API).
|
|
2384
|
+
* Prefer constructing with options + {@link Wolbarg.ready} instead.
|
|
2385
|
+
*
|
|
2386
|
+
* @param options - Organization, database, embedding, and optional LLM config.
|
|
2387
|
+
* @returns Resolves when storage is open and the vector schema is ready.
|
|
2388
|
+
* @throws {InitializationError} If already initialized.
|
|
2389
|
+
* @throws {ConfigurationError} | {ValidationError} On invalid options.
|
|
1319
2390
|
*/
|
|
1320
2391
|
init(options: InitOptions): Promise<void>;
|
|
1321
|
-
/**
|
|
2392
|
+
/**
|
|
2393
|
+
* Open storage, optional telemetry / checkpoint / graph providers, wrap the
|
|
2394
|
+
* embedding cache, and probe embedding dimensions. Safe to call multiple times;
|
|
2395
|
+
* concurrent callers share one boot promise.
|
|
2396
|
+
*
|
|
2397
|
+
* @returns Resolves when the instance is ready for remember/recall.
|
|
2398
|
+
* @throws {InitializationError} If neither constructor options nor {@link init} were used.
|
|
2399
|
+
*/
|
|
1322
2400
|
ready(): Promise<void>;
|
|
2401
|
+
/** Internal boot sequence invoked by {@link Wolbarg.ready}. */
|
|
1323
2402
|
private boot;
|
|
1324
|
-
/**
|
|
2403
|
+
/**
|
|
2404
|
+
* Store a semantic memory for an agent. Embeds `content.text`, writes the row,
|
|
2405
|
+
* and may **upsert** an existing active memory when dedupe is enabled
|
|
2406
|
+
* (constructor `memory.dedupe` or per-call `options.dedupe`).
|
|
2407
|
+
*
|
|
2408
|
+
* @param options - Agent id, text content, optional metadata / dedupe overrides.
|
|
2409
|
+
* See {@link RememberOptions}.
|
|
2410
|
+
* @returns The stored record plus `action` (`"created"` | `"updated"`).
|
|
2411
|
+
* @throws {ValidationError} On empty agent/content.
|
|
2412
|
+
* @throws {InitializationError} If not configured / ready.
|
|
2413
|
+
*/
|
|
1325
2414
|
remember(options: RememberOptions): Promise<RememberResult>;
|
|
1326
|
-
/**
|
|
2415
|
+
/**
|
|
2416
|
+
* Remember many memories in one call. Runs sequentially when any item (or the
|
|
2417
|
+
* global config) enables dedupe; otherwise embeds in batch and inserts in one
|
|
2418
|
+
* transaction for throughput.
|
|
2419
|
+
*
|
|
2420
|
+
* @param items - Non-empty list of {@link RememberOptions}.
|
|
2421
|
+
* @returns One {@link RememberResult} per input, same order.
|
|
2422
|
+
* @throws {ValidationError} If `items` is empty or an entry is invalid.
|
|
2423
|
+
*/
|
|
1327
2424
|
rememberBatch(items: RememberOptions[]): Promise<RememberResult[]>;
|
|
1328
2425
|
/**
|
|
1329
2426
|
* Store memories from a chat transcript.
|
|
@@ -1331,11 +2428,26 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1331
2428
|
* **Experimental** until 1.0 — API shape may change.
|
|
1332
2429
|
*
|
|
1333
2430
|
* - `mode: "raw"` (default) — remember user message text (no LLM).
|
|
1334
|
-
* - `mode: "extract"` —
|
|
2431
|
+
* - `mode: "extract"` — requires configured `llm`; extracts atomic facts then
|
|
2432
|
+
* remembers each. Pass a custom {@link LlmProvider} or {@link openaiLlm}
|
|
2433
|
+
* in the constructor.
|
|
2434
|
+
*
|
|
2435
|
+
* @param messages - Conversation turns (`role` + `content`).
|
|
2436
|
+
* @param options - Agent, mode, optional metadata/dedupe. See
|
|
2437
|
+
* {@link RememberFromMessagesOptions}.
|
|
2438
|
+
* @returns One {@link RememberResult} per remembered fact/message.
|
|
2439
|
+
* @throws {ProviderNotConfiguredError} When `mode: "extract"` but no `llm` was configured.
|
|
1335
2440
|
*/
|
|
1336
2441
|
rememberFromMessages(messages: ConversationMessage[], options: RememberFromMessagesOptions): Promise<RememberResult[]>;
|
|
1337
2442
|
/**
|
|
1338
|
-
* Update an existing memory by id
|
|
2443
|
+
* Update an existing memory by id. Re-embeds when `content` changes; merges
|
|
2444
|
+
* metadata when provided.
|
|
2445
|
+
*
|
|
2446
|
+
* @param options.id - Memory id to update.
|
|
2447
|
+
* @param options.content - Optional new `{ text }` (triggers re-embed + content hash).
|
|
2448
|
+
* @param options.metadata - Optional metadata merged onto the existing record.
|
|
2449
|
+
* @returns Updated record with `action: "updated"`.
|
|
2450
|
+
* @throws {MemoryNotFoundError} If the id is unknown in this organization.
|
|
1339
2451
|
*/
|
|
1340
2452
|
update(options: {
|
|
1341
2453
|
id: string;
|
|
@@ -1345,62 +2457,206 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1345
2457
|
metadata?: MemoryMetadata;
|
|
1346
2458
|
}): Promise<RememberResult>;
|
|
1347
2459
|
/**
|
|
1348
|
-
* Subscribe to memory change events.
|
|
2460
|
+
* Subscribe to memory change events (remember / update / forget / compress / clear).
|
|
1349
2461
|
*
|
|
1350
2462
|
* **SQLite:** delivers events only within this Node.js process.
|
|
1351
2463
|
* A second process writing the same `memory.db` will not notify subscribers here.
|
|
2464
|
+
*
|
|
2465
|
+
* **Postgres:** uses LISTEN/NOTIFY across processes (lazy connection on first subscribe).
|
|
2466
|
+
*
|
|
2467
|
+
* @param filter - Scope by `organization` (defaults to this instance’s org),
|
|
2468
|
+
* optional `agent`, and optional `events` allow-list. See {@link SubscribeFilter}.
|
|
2469
|
+
* @param callback - Invoked with each {@link MemoryChangeEvent}.
|
|
2470
|
+
* @returns {@link Unsubscribe} function — call to stop receiving events.
|
|
2471
|
+
* @throws {ValidationError} If organization cannot be resolved.
|
|
1352
2472
|
*/
|
|
1353
2473
|
subscribe(filter: SubscribeFilter, callback: (event: MemoryChangeEvent) => void): Unsubscribe;
|
|
2474
|
+
/** Broadcast a memory change event to in-process or Postgres NOTIFY subscribers. */
|
|
1354
2475
|
private emitChange;
|
|
1355
2476
|
/** Internal remember with optional upsert/dedupe. */
|
|
1356
2477
|
private rememberOne;
|
|
2478
|
+
/**
|
|
2479
|
+
* Find the best active near-duplicate memory for upsert (cosine similarity ≥ threshold).
|
|
2480
|
+
*
|
|
2481
|
+
* @param storage - Open storage provider.
|
|
2482
|
+
* @param organization - Org namespace.
|
|
2483
|
+
* @param agent - Agent scope for the search.
|
|
2484
|
+
* @param vector - Embedding of the candidate text.
|
|
2485
|
+
* @param threshold - Minimum similarity (0–1) to treat as a duplicate.
|
|
2486
|
+
* @param limit - Max vector candidates to inspect.
|
|
2487
|
+
* @returns Matching memory row, or `null` if none qualify.
|
|
2488
|
+
*/
|
|
1357
2489
|
private findNearDuplicate;
|
|
1358
2490
|
/**
|
|
1359
|
-
* Semantic
|
|
2491
|
+
* Semantic (and optional hybrid / MMR / rerank / graph) search over stored memories.
|
|
1360
2492
|
* Pass `{ explain: true }` for enriched ranking diagnostics.
|
|
2493
|
+
*
|
|
2494
|
+
* @param options - Query text plus optional `topK` (default 5), `threshold`,
|
|
2495
|
+
* `filter`, `hybrid`, `mmr`, `rerank`, `includeGraph`, `explain`.
|
|
2496
|
+
* See {@link RecallOptions}.
|
|
2497
|
+
* @returns Ranked {@link RecallResult}[] normally, or {@link RecallExplainResponse}
|
|
2498
|
+
* when `explain: true`.
|
|
1361
2499
|
*/
|
|
1362
2500
|
recall(options: RecallOptions & {
|
|
1363
2501
|
explain: true;
|
|
1364
2502
|
}): Promise<RecallExplainResponse>;
|
|
2503
|
+
/**
|
|
2504
|
+
* @param options - Recall options with `explain` omitted or `false`.
|
|
2505
|
+
* @returns Ranked memory hits.
|
|
2506
|
+
*/
|
|
1365
2507
|
recall(options: RecallOptions & {
|
|
1366
2508
|
explain?: false;
|
|
1367
2509
|
}): Promise<RecallResult[]>;
|
|
1368
2510
|
recall(options: RecallOptions): Promise<RecallResult[] | RecallExplainResponse>;
|
|
1369
|
-
/**
|
|
2511
|
+
/**
|
|
2512
|
+
* Run multiple recalls sequentially under one parent telemetry span.
|
|
2513
|
+
*
|
|
2514
|
+
* @param queries - Non-empty list of recall options (`explain` is forced off).
|
|
2515
|
+
* @returns One hit array per query, same order.
|
|
2516
|
+
* @throws {ValidationError} If `queries` is empty.
|
|
2517
|
+
*/
|
|
1370
2518
|
recallBatch(queries: Array<Omit<RecallOptions, "explain">>): Promise<RecallResult[][]>;
|
|
2519
|
+
/**
|
|
2520
|
+
* Compress the newest active memories for an agent into one summary memory
|
|
2521
|
+
* and archive the sources. Requires an `llm` (or custom `compression`) at
|
|
2522
|
+
* construction — typed only on `Wolbarg<true>`.
|
|
2523
|
+
*
|
|
2524
|
+
* @param options - `agent` required; optional `limit` (default 50, min 2).
|
|
2525
|
+
* See {@link CompressOptions}.
|
|
2526
|
+
* @returns Summary record plus archived source ids. See {@link CompressResult}.
|
|
2527
|
+
* @throws {ProviderNotConfiguredError} If no LLM/compression provider is set.
|
|
2528
|
+
* @throws {ValidationError} If fewer than 2 active memories exist for the agent.
|
|
2529
|
+
*/
|
|
1371
2530
|
compress(this: Wolbarg<true>, options: CompressOptions): Promise<CompressResult>;
|
|
1372
|
-
/** @internal */
|
|
2531
|
+
/** @internal Runs compress for both typed and untyped call sites. */
|
|
1373
2532
|
private runCompress;
|
|
2533
|
+
/**
|
|
2534
|
+
* Ingest a document (path, URL, Buffer, or text), chunk it, embed chunks, and
|
|
2535
|
+
* store each as a memory. Images use optional `ocr` / `vision` providers from
|
|
2536
|
+
* the constructor.
|
|
2537
|
+
*
|
|
2538
|
+
* @param options - `agent`, `source`, optional chunking overrides / metadata.
|
|
2539
|
+
* See {@link IngestOptions}.
|
|
2540
|
+
* @returns Counts and created memory ids. See {@link IngestResult}.
|
|
2541
|
+
* @throws {ValidationError} If no text can be extracted or chunking yields zero chunks.
|
|
2542
|
+
*/
|
|
1374
2543
|
ingest(options: IngestOptions): Promise<IngestResult>;
|
|
1375
2544
|
/**
|
|
1376
|
-
* Link two memories in the optional graph layer.
|
|
1377
|
-
*
|
|
2545
|
+
* Link two memories in the optional graph layer with a typed relation edge.
|
|
2546
|
+
*
|
|
2547
|
+
* @param fromId - Source memory id.
|
|
2548
|
+
* @param toId - Target memory id.
|
|
2549
|
+
* @param relation - Edge label (e.g. `"supports"`, `"caused_by"`).
|
|
2550
|
+
* @param metadata - Optional edge properties stored on the graph provider.
|
|
2551
|
+
* @throws {ProviderNotConfiguredError} When no `graph` was configured.
|
|
2552
|
+
* @throws {ValidationError} On empty ids/relation.
|
|
1378
2553
|
*/
|
|
1379
2554
|
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
1380
2555
|
/**
|
|
1381
2556
|
* Traverse related memories via the optional graph layer.
|
|
1382
|
-
*
|
|
1383
|
-
*
|
|
2557
|
+
* Neighbor stubs from the graph are re-hydrated from SQL storage when available.
|
|
2558
|
+
*
|
|
2559
|
+
* @param memoryId - Seed memory id.
|
|
2560
|
+
* @param options - Optional `relation`, `direction`, `depth`, `limit`.
|
|
2561
|
+
* See {@link GetRelatedOptions}.
|
|
2562
|
+
* @returns Related {@link MemoryRecord} list (may be empty).
|
|
2563
|
+
* @throws {ProviderNotConfiguredError} When no `graph` was configured.
|
|
1384
2564
|
*/
|
|
1385
2565
|
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
2566
|
+
/**
|
|
2567
|
+
* Delete memories by id or by agent filter. Cascades graph nodes/edges when
|
|
2568
|
+
* a graph provider is configured.
|
|
2569
|
+
*
|
|
2570
|
+
* @param options - Either `{ id }` or `{ filter: { agent } }`. See {@link ForgetOptions}.
|
|
2571
|
+
* @returns Number of memories deleted.
|
|
2572
|
+
* @throws {ValidationError} If neither `id` nor `filter.agent` is provided.
|
|
2573
|
+
*/
|
|
1386
2574
|
forget(options: ForgetOptions): Promise<number>;
|
|
2575
|
+
/**
|
|
2576
|
+
* Return the audit/history timeline for a single memory.
|
|
2577
|
+
*
|
|
2578
|
+
* @param options - `{ id }` of the memory. See {@link HistoryOptions}.
|
|
2579
|
+
* @returns Memory record plus ordered {@link HistoryEvent} list.
|
|
2580
|
+
* @throws {MemoryNotFoundError} If the id is unknown.
|
|
2581
|
+
*/
|
|
1387
2582
|
history(options: HistoryOptions): Promise<HistoryResult>;
|
|
2583
|
+
/**
|
|
2584
|
+
* Aggregate counts for this organization (active / archived / agents / etc.).
|
|
2585
|
+
*
|
|
2586
|
+
* @returns {@link StatsResult} snapshot.
|
|
2587
|
+
*/
|
|
1388
2588
|
stats(): Promise<StatsResult>;
|
|
2589
|
+
/**
|
|
2590
|
+
* Delete all memories for this organization (optionally scoped by agent).
|
|
2591
|
+
* Cascades graph cleanup when a graph provider is configured.
|
|
2592
|
+
*
|
|
2593
|
+
* @param options - Optional `{ agent }` scope. See {@link ClearOptions}.
|
|
2594
|
+
* @returns Number of memories deleted.
|
|
2595
|
+
*/
|
|
1389
2596
|
clear(options: ClearOptions): Promise<number>;
|
|
1390
|
-
/**
|
|
2597
|
+
/**
|
|
2598
|
+
* Create an immutable named checkpoint of the file-backed SQLite memory DB
|
|
2599
|
+
* (and SQLite graph snapshot when applicable).
|
|
2600
|
+
*
|
|
2601
|
+
* @param name - Checkpoint name (unique).
|
|
2602
|
+
* @param options - Optional metadata. See {@link CheckpointOptions}.
|
|
2603
|
+
* @returns {@link CheckpointInfo} for the new checkpoint.
|
|
2604
|
+
* @throws {ProviderNotConfiguredError} Without a checkpoint provider / file DB.
|
|
2605
|
+
* @throws {GraphCheckpointNotSupportedError} For Neo4j graph backends.
|
|
2606
|
+
*/
|
|
1391
2607
|
checkpoint(name: string, options?: CheckpointOptions): Promise<CheckpointInfo>;
|
|
1392
|
-
/**
|
|
2608
|
+
/**
|
|
2609
|
+
* Restore the memory database from a named checkpoint (replaces the live DB file).
|
|
2610
|
+
*
|
|
2611
|
+
* @param name - Checkpoint name previously created with {@link Wolbarg.checkpoint}.
|
|
2612
|
+
* @returns {@link CheckpointInfo} of the restored checkpoint.
|
|
2613
|
+
*/
|
|
1393
2614
|
rollback(name: string): Promise<CheckpointInfo>;
|
|
2615
|
+
/**
|
|
2616
|
+
* Delete a named checkpoint from disk / the checkpoint store.
|
|
2617
|
+
*
|
|
2618
|
+
* @param name - Checkpoint name.
|
|
2619
|
+
* @returns `true` if a checkpoint was removed.
|
|
2620
|
+
*/
|
|
1394
2621
|
deleteCheckpoint(name: string): Promise<boolean>;
|
|
2622
|
+
/**
|
|
2623
|
+
* List all known checkpoints for this instance.
|
|
2624
|
+
*
|
|
2625
|
+
* @returns Array of {@link CheckpointInfo} (may be empty).
|
|
2626
|
+
*/
|
|
1395
2627
|
listCheckpoints(): Promise<CheckpointInfo[]>;
|
|
2628
|
+
/**
|
|
2629
|
+
* Look up a single checkpoint by name.
|
|
2630
|
+
*
|
|
2631
|
+
* @param name - Checkpoint name.
|
|
2632
|
+
* @returns {@link CheckpointInfo} or `null` if missing.
|
|
2633
|
+
*/
|
|
1396
2634
|
getCheckpoint(name: string): Promise<CheckpointInfo | null>;
|
|
1397
|
-
/**
|
|
2635
|
+
/**
|
|
2636
|
+
* Export the memory database to a portable SQLite + manifest bundle
|
|
2637
|
+
* (includes SQLite graph sidecar when applicable).
|
|
2638
|
+
*
|
|
2639
|
+
* @param exportPath - Destination file path for the export bundle.
|
|
2640
|
+
* @returns {@link ExportResult} with path, size, and timestamp.
|
|
2641
|
+
*/
|
|
1398
2642
|
export(exportPath: string): Promise<ExportResult>;
|
|
1399
|
-
/**
|
|
2643
|
+
/**
|
|
2644
|
+
* Import a previously exported memory database, replacing the current file.
|
|
2645
|
+
* Closes and reopens storage around the swap.
|
|
2646
|
+
*
|
|
2647
|
+
* @param exportPath - Path to a bundle produced by {@link Wolbarg.export}.
|
|
2648
|
+
* @returns {@link ImportResult} with restored path and timestamp.
|
|
2649
|
+
*/
|
|
1400
2650
|
import(exportPath: string): Promise<ImportResult>;
|
|
1401
|
-
/**
|
|
2651
|
+
/**
|
|
2652
|
+
* Flush pending telemetry writes (useful in tests / before process exit).
|
|
2653
|
+
*
|
|
2654
|
+
* @returns Resolves when the telemetry provider has flushed.
|
|
2655
|
+
*/
|
|
1402
2656
|
flushTelemetry(): Promise<void>;
|
|
1403
|
-
/**
|
|
2657
|
+
/**
|
|
2658
|
+
* Session id for this SDK instance (attached to telemetry traces and change events).
|
|
2659
|
+
*/
|
|
1404
2660
|
get sessionId(): string;
|
|
1405
2661
|
/**
|
|
1406
2662
|
* Optional process-wide lock for SQLite read-modify-write (dedupe upsert).
|
|
@@ -1408,67 +2664,144 @@ declare class Wolbarg<HasLlm extends boolean = false> {
|
|
|
1408
2664
|
* insertMemory calls under a single BEGIN IMMEDIATE for multi-writer throughput.
|
|
1409
2665
|
*/
|
|
1410
2666
|
private withWriteLock;
|
|
2667
|
+
/**
|
|
2668
|
+
* Close storage, graph, telemetry, checkpoints, and subscribe backends.
|
|
2669
|
+
* The instance can be discarded afterward; construct a new one to reopen.
|
|
2670
|
+
*
|
|
2671
|
+
* @returns Resolves when all providers have closed (errors are swallowed per-provider).
|
|
2672
|
+
*/
|
|
1411
2673
|
close(): Promise<void>;
|
|
2674
|
+
/** Whether {@link Wolbarg.ready} / {@link Wolbarg.init} has completed successfully. */
|
|
1412
2675
|
get isInitialized(): boolean;
|
|
2676
|
+
/** Ensure {@link Wolbarg.ready} completed and core providers are available. */
|
|
1413
2677
|
private requireReady;
|
|
2678
|
+
/** Reject embeddings whose dimensionality differs from the initialized model. */
|
|
1414
2679
|
private assertEmbeddingDimensions;
|
|
2680
|
+
/** Return the configured checkpoint provider or throw {@link ProviderNotConfiguredError}. */
|
|
1415
2681
|
private requireCheckpointProvider;
|
|
2682
|
+
/** Return the configured graph provider or throw with a setup hint for `method`. */
|
|
1416
2683
|
private requireGraph;
|
|
2684
|
+
/** Throw when graph checkpoint pairing is requested on a non-file-backed graph backend. */
|
|
1417
2685
|
private assertGraphCheckpointSupported;
|
|
2686
|
+
/** Directory path where a graph file snapshot is stored alongside a memory checkpoint. */
|
|
1418
2687
|
private graphSnapshotDir;
|
|
2688
|
+
/** Close the graph provider before copying files; returns whether a close occurred. */
|
|
1419
2689
|
private closeGraphForSnapshot;
|
|
2690
|
+
/** Copy the SQLite graph database next to a memory checkpoint directory. */
|
|
1420
2691
|
private snapshotGraphAlongside;
|
|
2692
|
+
/** Restore a graph file snapshot written by {@link snapshotGraphAlongside}. */
|
|
1421
2693
|
private restoreGraphAlongside;
|
|
2694
|
+
/** Run graph traversal then re-hydrate stub records from storage when rows exist. */
|
|
1422
2695
|
private hydrateRelated;
|
|
2696
|
+
/** Resolve the on-disk SQLite memory database path (throws for Postgres / `:memory:`). */
|
|
1423
2697
|
private requireMemoryDbPath;
|
|
1424
2698
|
}
|
|
1425
|
-
/**
|
|
2699
|
+
/**
|
|
2700
|
+
* Preferred factory — equivalent to `new Wolbarg(options)`.
|
|
2701
|
+
*
|
|
2702
|
+
* @param options - Full {@link WolbargOptions}. Pass custom provider instances
|
|
2703
|
+
* (`embedding`, `llm`, `storage`, `graph`, …) or factory helpers
|
|
2704
|
+
* (`openaiEmbedding`, `openaiLlm`, `sqliteGraph`, …). See constructor docs
|
|
2705
|
+
* on {@link Wolbarg} for every option field.
|
|
2706
|
+
* @returns A configured {@link Wolbarg} instance (call {@link Wolbarg.ready} before use).
|
|
2707
|
+
*
|
|
2708
|
+
* @example
|
|
2709
|
+
* ```ts
|
|
2710
|
+
* const memory = wolbarg({
|
|
2711
|
+
* organization: "acme",
|
|
2712
|
+
* database: { provider: "sqlite", url: "./memory.db" },
|
|
2713
|
+
* embedding: openaiEmbedding({
|
|
2714
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
2715
|
+
* model: "text-embedding-3-small",
|
|
2716
|
+
* }),
|
|
2717
|
+
* llm: openaiLlm({
|
|
2718
|
+
* apiKey: process.env.OPENAI_API_KEY!,
|
|
2719
|
+
* model: "gpt-4o-mini",
|
|
2720
|
+
* }),
|
|
2721
|
+
* });
|
|
2722
|
+
* await memory.ready();
|
|
2723
|
+
* ```
|
|
2724
|
+
*/
|
|
1426
2725
|
declare function wolbarg$1(options: WolbargOptions): Wolbarg;
|
|
1427
2726
|
|
|
1428
|
-
/** Published SDK semver — keep in sync with package.json `version`. */
|
|
1429
|
-
declare const SDK_VERSION = "0.5.
|
|
2727
|
+
/** Published SDK semver — keep in sync with `package.json` `version`. */
|
|
2728
|
+
declare const SDK_VERSION = "0.5.5";
|
|
1430
2729
|
|
|
1431
2730
|
/**
|
|
1432
|
-
* Operation-scoped errors with
|
|
2731
|
+
* Operation-scoped errors with stable `code`, human `reason`, and actionable `suggestion`.
|
|
2732
|
+
*
|
|
2733
|
+
* All Wolbarg errors extend {@link WolbargError} so callers can use `instanceof`
|
|
2734
|
+
* checks and read structured fields in IDE hover docs.
|
|
2735
|
+
*/
|
|
2736
|
+
/**
|
|
2737
|
+
* Base class for all Wolbarg SDK errors.
|
|
2738
|
+
*
|
|
2739
|
+
* @property code - Stable machine-readable error code (e.g. `"VALIDATION_ERROR"`).
|
|
2740
|
+
* @property reason - Short explanation of why the operation failed.
|
|
2741
|
+
* @property suggestion - Actionable fix hint for developers.
|
|
2742
|
+
* @property operation - Facade method name when applicable (e.g. `"recall"`).
|
|
1433
2743
|
*/
|
|
1434
|
-
/** Base class for all Wolbarg errors. */
|
|
1435
2744
|
declare class WolbargError extends Error {
|
|
1436
2745
|
readonly code: string;
|
|
1437
2746
|
readonly reason?: string;
|
|
1438
2747
|
readonly suggestion?: string;
|
|
1439
2748
|
readonly operation?: string;
|
|
2749
|
+
/**
|
|
2750
|
+
* @param message - Human-readable error message.
|
|
2751
|
+
* @param code - Stable error code string.
|
|
2752
|
+
* @param options - Optional cause, reason, suggestion, and operation name.
|
|
2753
|
+
*/
|
|
1440
2754
|
constructor(message: string, code: string, options?: ErrorOptions & {
|
|
1441
2755
|
reason?: string;
|
|
1442
2756
|
suggestion?: string;
|
|
1443
2757
|
operation?: string;
|
|
1444
2758
|
});
|
|
1445
2759
|
}
|
|
1446
|
-
/** Thrown when SDK initialization fails. */
|
|
2760
|
+
/** Thrown when SDK initialization or `open()` fails. */
|
|
1447
2761
|
declare class InitializationError extends WolbargError {
|
|
2762
|
+
/**
|
|
2763
|
+
* @param message - Description of the initialization failure.
|
|
2764
|
+
* @param options - Optional cause and structured hints.
|
|
2765
|
+
*/
|
|
1448
2766
|
constructor(message: string, options?: ErrorOptions & {
|
|
1449
2767
|
reason?: string;
|
|
1450
2768
|
suggestion?: string;
|
|
1451
2769
|
operation?: string;
|
|
1452
2770
|
});
|
|
1453
2771
|
}
|
|
1454
|
-
/**
|
|
2772
|
+
/**
|
|
2773
|
+
* Thrown when configuration values are missing, invalid, or incompatible.
|
|
2774
|
+
* Also used for missing optional peer packages (PDF, OCR, Neo4j, etc.).
|
|
2775
|
+
*/
|
|
1455
2776
|
declare class ConfigurationError extends WolbargError {
|
|
2777
|
+
/**
|
|
2778
|
+
* @param message - Description of the misconfiguration.
|
|
2779
|
+
* @param options - Optional cause, reason, suggestion, and operation name.
|
|
2780
|
+
*/
|
|
1456
2781
|
constructor(message: string, options?: ErrorOptions & {
|
|
1457
2782
|
reason?: string;
|
|
1458
2783
|
suggestion?: string;
|
|
1459
2784
|
operation?: string;
|
|
1460
2785
|
});
|
|
1461
2786
|
}
|
|
1462
|
-
/** Thrown when method arguments fail validation. */
|
|
2787
|
+
/** Thrown when method arguments fail validation before reaching storage. */
|
|
1463
2788
|
declare class ValidationError extends WolbargError {
|
|
2789
|
+
/**
|
|
2790
|
+
* @param message - Which argument failed and why.
|
|
2791
|
+
* @param options - Optional cause and structured hints.
|
|
2792
|
+
*/
|
|
1464
2793
|
constructor(message: string, options?: ErrorOptions & {
|
|
1465
2794
|
reason?: string;
|
|
1466
2795
|
suggestion?: string;
|
|
1467
2796
|
operation?: string;
|
|
1468
2797
|
});
|
|
1469
2798
|
}
|
|
1470
|
-
/** Thrown when a database
|
|
2799
|
+
/** Thrown when a low-level database read/write fails. */
|
|
1471
2800
|
declare class DatabaseError extends WolbargError {
|
|
2801
|
+
/**
|
|
2802
|
+
* @param message - Operation-scoped failure message.
|
|
2803
|
+
* @param options - Optional underlying `cause` and hints.
|
|
2804
|
+
*/
|
|
1472
2805
|
constructor(message: string, options?: ErrorOptions & {
|
|
1473
2806
|
reason?: string;
|
|
1474
2807
|
suggestion?: string;
|
|
@@ -1477,33 +2810,49 @@ declare class DatabaseError extends WolbargError {
|
|
|
1477
2810
|
}
|
|
1478
2811
|
/**
|
|
1479
2812
|
* Thrown when SQLite write-lock retries are exhausted.
|
|
1480
|
-
* Stable code: WOLBARG_STORAGE_LOCKED
|
|
2813
|
+
* Stable code: `WOLBARG_STORAGE_LOCKED`.
|
|
1481
2814
|
*/
|
|
1482
2815
|
declare class StorageLockedError extends WolbargError {
|
|
2816
|
+
/**
|
|
2817
|
+
* @param message - Lock contention description.
|
|
2818
|
+
* @param options - Typically includes suggestion to tune concurrency or use Postgres.
|
|
2819
|
+
*/
|
|
1483
2820
|
constructor(message: string, options?: ErrorOptions & {
|
|
1484
2821
|
reason?: string;
|
|
1485
2822
|
suggestion?: string;
|
|
1486
2823
|
operation?: string;
|
|
1487
2824
|
});
|
|
1488
2825
|
}
|
|
1489
|
-
/** Thrown when an embedding request fails. */
|
|
2826
|
+
/** Thrown when an embedding API request fails or returns invalid vectors. */
|
|
1490
2827
|
declare class EmbeddingError extends WolbargError {
|
|
2828
|
+
/**
|
|
2829
|
+
* @param message - Embedding failure description.
|
|
2830
|
+
* @param options - Optional HTTP cause and provider hints.
|
|
2831
|
+
*/
|
|
1491
2832
|
constructor(message: string, options?: ErrorOptions & {
|
|
1492
2833
|
reason?: string;
|
|
1493
2834
|
suggestion?: string;
|
|
1494
2835
|
operation?: string;
|
|
1495
2836
|
});
|
|
1496
2837
|
}
|
|
1497
|
-
/** Thrown when compression (
|
|
2838
|
+
/** Thrown when LLM-based memory compression (summarization) fails. */
|
|
1498
2839
|
declare class CompressionError extends WolbargError {
|
|
2840
|
+
/**
|
|
2841
|
+
* @param message - Compression failure description.
|
|
2842
|
+
* @param options - Optional LLM cause chain.
|
|
2843
|
+
*/
|
|
1499
2844
|
constructor(message: string, options?: ErrorOptions & {
|
|
1500
2845
|
reason?: string;
|
|
1501
2846
|
suggestion?: string;
|
|
1502
2847
|
operation?: string;
|
|
1503
2848
|
});
|
|
1504
2849
|
}
|
|
1505
|
-
/** Thrown when a requested memory does not exist. */
|
|
2850
|
+
/** Thrown when a requested memory id does not exist or is archived. */
|
|
1506
2851
|
declare class MemoryNotFoundError extends WolbargError {
|
|
2852
|
+
/**
|
|
2853
|
+
* @param message - Which memory was not found.
|
|
2854
|
+
* @param options - Optional operation context.
|
|
2855
|
+
*/
|
|
1507
2856
|
constructor(message: string, options?: ErrorOptions & {
|
|
1508
2857
|
reason?: string;
|
|
1509
2858
|
suggestion?: string;
|
|
@@ -1511,10 +2860,16 @@ declare class MemoryNotFoundError extends WolbargError {
|
|
|
1511
2860
|
});
|
|
1512
2861
|
}
|
|
1513
2862
|
/**
|
|
1514
|
-
* Thrown when a method requires an optional provider that was not configured
|
|
2863
|
+
* Thrown when a method requires an optional provider that was not configured
|
|
2864
|
+
* (reranker, OCR, graph, LLM for extract mode, etc.).
|
|
1515
2865
|
*/
|
|
1516
2866
|
declare class ProviderNotConfiguredError extends ConfigurationError {
|
|
1517
2867
|
readonly provider: string;
|
|
2868
|
+
/**
|
|
2869
|
+
* @param provider - Provider name (e.g. `"reranker"`, `"graph"`).
|
|
2870
|
+
* @param method - Facade method that requires the provider.
|
|
2871
|
+
* @param hint - Install or config instruction shown to the developer.
|
|
2872
|
+
*/
|
|
1518
2873
|
constructor(provider: string, method: string, hint: string);
|
|
1519
2874
|
}
|
|
1520
2875
|
/**
|
|
@@ -1523,52 +2878,161 @@ declare class ProviderNotConfiguredError extends ConfigurationError {
|
|
|
1523
2878
|
* snapshots; Neo4j does not in v1 — we refuse rather than silently skip.
|
|
1524
2879
|
*/
|
|
1525
2880
|
declare class GraphCheckpointNotSupportedError extends WolbargError {
|
|
2881
|
+
/**
|
|
2882
|
+
* @param backend - Graph backend name (e.g. `"neo4j"`).
|
|
2883
|
+
* @param operation - Requested operation (e.g. `"checkpoint"`).
|
|
2884
|
+
*/
|
|
1526
2885
|
constructor(backend: string, operation: string);
|
|
1527
2886
|
}
|
|
1528
|
-
/**
|
|
2887
|
+
/**
|
|
2888
|
+
* Map low-level SQLite / driver errors into actionable {@link WolbargError} subclasses.
|
|
2889
|
+
*
|
|
2890
|
+
* Preserves existing {@link WolbargError} instances unchanged. Recognizes lock
|
|
2891
|
+
* contention, missing files, and read-only database errors.
|
|
2892
|
+
*
|
|
2893
|
+
* @param operation - Facade method name for the error message (e.g. `"remember"`).
|
|
2894
|
+
* @param error - Raw thrown value from the driver.
|
|
2895
|
+
* @returns A typed {@link WolbargError} subclass with `reason` and `suggestion`.
|
|
2896
|
+
*/
|
|
1529
2897
|
declare function wrapOperationError(operation: string, error: unknown): WolbargError;
|
|
1530
2898
|
|
|
1531
2899
|
/**
|
|
1532
|
-
* Public factory helpers for storage
|
|
2900
|
+
* Public factory helpers for storage, telemetry, checkpoints, and graph providers (v0.5.5).
|
|
1533
2901
|
*/
|
|
1534
2902
|
|
|
1535
|
-
/**
|
|
2903
|
+
/**
|
|
2904
|
+
* Create a SQLite {@link StorageProvider} from a filesystem path or `:memory:`.
|
|
2905
|
+
*
|
|
2906
|
+
* @param connectionString - Absolute/relative `.db` path, or `":memory:"` for ephemeral.
|
|
2907
|
+
* @returns Ready-to-pass storage provider (Wolbarg still calls `open()` via `ready()`).
|
|
2908
|
+
*
|
|
2909
|
+
* @example
|
|
2910
|
+
* ```ts
|
|
2911
|
+
* wolbarg({ organization: "acme", storage: sqlite("./memory.db"), embedding: ... })
|
|
2912
|
+
* ```
|
|
2913
|
+
*/
|
|
1536
2914
|
declare function sqlite(connectionString: string): StorageProvider;
|
|
1537
|
-
/**
|
|
2915
|
+
/**
|
|
2916
|
+
* Create a SQLite storage **config object** (for `database` / `init` options).
|
|
2917
|
+
*
|
|
2918
|
+
* @param connectionString - Path or `:memory:`.
|
|
2919
|
+
* @returns `{ provider: "sqlite", connectionString, url }`.
|
|
2920
|
+
*/
|
|
1538
2921
|
declare function sqliteConfig(connectionString: string): SqliteDatabaseConfig;
|
|
1539
|
-
/**
|
|
2922
|
+
/**
|
|
2923
|
+
* Create a PostgreSQL {@link StorageProvider}. Requires optional peer `pg`.
|
|
2924
|
+
*
|
|
2925
|
+
* @param options - Connection string, or an object with:
|
|
2926
|
+
* - `connectionString` — Postgres URL
|
|
2927
|
+
* - `maxPoolSize` — optional pool size
|
|
2928
|
+
* - `durableWrites` — default `true`; set `false` for higher write throughput (async commit)
|
|
2929
|
+
* @returns Postgres storage provider instance.
|
|
2930
|
+
*
|
|
2931
|
+
* @example
|
|
2932
|
+
* ```ts
|
|
2933
|
+
* postgres(process.env.DATABASE_URL!)
|
|
2934
|
+
* postgres({ connectionString: process.env.DATABASE_URL!, maxPoolSize: 10 })
|
|
2935
|
+
* ```
|
|
2936
|
+
*/
|
|
1540
2937
|
declare function postgres(options: string | {
|
|
1541
2938
|
connectionString: string;
|
|
1542
2939
|
maxPoolSize?: number;
|
|
1543
2940
|
/** Default true. Set false for higher write throughput (async commit). */
|
|
1544
2941
|
durableWrites?: boolean;
|
|
1545
2942
|
}): StorageProvider;
|
|
1546
|
-
/**
|
|
2943
|
+
/**
|
|
2944
|
+
* Create a PostgreSQL storage **config object**.
|
|
2945
|
+
*
|
|
2946
|
+
* @param connectionString - Postgres connection URL.
|
|
2947
|
+
* @param options.maxPoolSize - Optional pool size.
|
|
2948
|
+
* @param options.durableWrites - Optional durability flag (default true).
|
|
2949
|
+
* @returns `{ provider: "postgres", connectionString, url, ... }`.
|
|
2950
|
+
*/
|
|
1547
2951
|
declare function postgresConfig(connectionString: string, options?: {
|
|
1548
2952
|
maxPoolSize?: number;
|
|
1549
2953
|
durableWrites?: boolean;
|
|
1550
2954
|
}): PostgresDatabaseConfig;
|
|
1551
|
-
/**
|
|
2955
|
+
/**
|
|
2956
|
+
* Create a SQLite {@link TelemetryProvider} for an independent event database.
|
|
2957
|
+
*
|
|
2958
|
+
* @param url - Path to the telemetry SQLite file (separate from memory DB).
|
|
2959
|
+
* @returns Telemetry provider for `telemetry:` constructor option.
|
|
2960
|
+
*/
|
|
1552
2961
|
declare function sqliteTelemetry(url: string): TelemetryProvider;
|
|
1553
|
-
/**
|
|
2962
|
+
/**
|
|
2963
|
+
* Create a SQLite {@link CheckpointProvider}.
|
|
2964
|
+
*
|
|
2965
|
+
* @param directory - Optional directory for checkpoint files (default under cwd).
|
|
2966
|
+
* @returns Checkpoint provider for `checkpoint:` constructor option.
|
|
2967
|
+
*/
|
|
1554
2968
|
declare function sqliteCheckpoint(directory?: string): CheckpointProvider;
|
|
1555
|
-
/**
|
|
2969
|
+
/**
|
|
2970
|
+
* Create an embedded SQLite {@link GraphProvider} (file-backed, local/dev).
|
|
2971
|
+
*
|
|
2972
|
+
* @param options.path - Filesystem path for the graph SQLite database
|
|
2973
|
+
* (separate from the memory DB).
|
|
2974
|
+
* @returns Graph provider for `graph:` in {@link WolbargOptions}.
|
|
2975
|
+
*
|
|
2976
|
+
* @example
|
|
2977
|
+
* ```ts
|
|
2978
|
+
* graph: sqliteGraph({ path: "./graph.db" })
|
|
2979
|
+
* ```
|
|
2980
|
+
*/
|
|
1556
2981
|
declare function sqliteGraph(options: {
|
|
1557
2982
|
path: string;
|
|
1558
2983
|
}): GraphProvider;
|
|
1559
|
-
/**
|
|
2984
|
+
/**
|
|
2985
|
+
* Create a Neo4j {@link GraphProvider} (networked). Requires optional peer `neo4j-driver`.
|
|
2986
|
+
*
|
|
2987
|
+
* @param options.url - Bolt URL, e.g. `neo4j://localhost:7687` or `bolt://…`.
|
|
2988
|
+
* @param options.username - Neo4j username.
|
|
2989
|
+
* @param options.password - Neo4j password.
|
|
2990
|
+
* @param options.database - Optional database name (Neo4j 4+ multi-DB).
|
|
2991
|
+
* @returns Graph provider for `graph:` in {@link WolbargOptions}.
|
|
2992
|
+
*
|
|
2993
|
+
* @example
|
|
2994
|
+
* ```ts
|
|
2995
|
+
* graph: neo4jGraph({
|
|
2996
|
+
* url: "neo4j://localhost:7687",
|
|
2997
|
+
* username: "neo4j",
|
|
2998
|
+
* password: process.env.NEO4J_PASSWORD!,
|
|
2999
|
+
* })
|
|
3000
|
+
* ```
|
|
3001
|
+
*/
|
|
1560
3002
|
declare function neo4jGraph(options: {
|
|
1561
3003
|
url: string;
|
|
1562
3004
|
username: string;
|
|
1563
3005
|
password: string;
|
|
1564
3006
|
database?: string;
|
|
1565
3007
|
}): GraphProvider;
|
|
1566
|
-
/**
|
|
3008
|
+
/**
|
|
3009
|
+
* Create a {@link TelemetryProvider} from {@link TelemetryConfig}.
|
|
3010
|
+
* Currently only SQLite telemetry databases are implemented.
|
|
3011
|
+
*
|
|
3012
|
+
* @param config - Telemetry config with `database.provider` and `database.url`.
|
|
3013
|
+
* @returns SQLite telemetry provider instance.
|
|
3014
|
+
* @throws {ConfigurationError} If provider is not `"sqlite"` or url is missing.
|
|
3015
|
+
*/
|
|
1567
3016
|
declare function createTelemetryProvider(config: TelemetryConfig): TelemetryProvider;
|
|
1568
3017
|
/**
|
|
1569
|
-
* Preferred
|
|
3018
|
+
* Preferred factory. Equivalent to `new Wolbarg(options)`.
|
|
3019
|
+
*
|
|
3020
|
+
* @param options - Full {@link WolbargOptions} (providers, database, embedding, optional llm).
|
|
3021
|
+
* @returns Configured {@link Wolbarg} instance — call `ready()` before use.
|
|
3022
|
+
*
|
|
3023
|
+
* @example
|
|
3024
|
+
* ```ts
|
|
3025
|
+
* const ctx = wolbarg({
|
|
3026
|
+
* organization: "acme",
|
|
3027
|
+
* database: sqliteConfig("./memory.db"),
|
|
3028
|
+
* embedding: openaiEmbedding({ apiKey: "...", model: "text-embedding-3-small" }),
|
|
3029
|
+
* });
|
|
3030
|
+
* await ctx.ready();
|
|
3031
|
+
* ```
|
|
1570
3032
|
*/
|
|
1571
3033
|
declare function wolbarg(options: WolbargOptions): Wolbarg;
|
|
3034
|
+
/** @deprecated Alias of {@link wolbarg}. */
|
|
3035
|
+
declare const createWolbarg: typeof wolbarg;
|
|
1572
3036
|
|
|
1573
3037
|
/**
|
|
1574
3038
|
* SQLite multi-writer concurrency defaults and validation.
|
|
@@ -1597,9 +3061,14 @@ interface ConcurrencyConfig {
|
|
|
1597
3061
|
*/
|
|
1598
3062
|
|
|
1599
3063
|
interface SqliteProviderOptions {
|
|
3064
|
+
/** Filesystem path or `:memory:` connection string. */
|
|
1600
3065
|
connectionString: string;
|
|
3066
|
+
/** Optional write-lock tuning for concurrent async callers. */
|
|
1601
3067
|
concurrency?: ConcurrencyConfig;
|
|
1602
3068
|
}
|
|
3069
|
+
/**
|
|
3070
|
+
* SQLite + sqlite-vec {@link StorageProvider} (Node.js built-in `node:sqlite`).
|
|
3071
|
+
*/
|
|
1603
3072
|
declare class SqliteStorageProvider implements StorageProvider {
|
|
1604
3073
|
readonly name = "sqlite";
|
|
1605
3074
|
private readonly connectionString;
|
|
@@ -1609,6 +3078,10 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1609
3078
|
private vectorDimensions;
|
|
1610
3079
|
private vectorBackend;
|
|
1611
3080
|
private sqliteVecLoaded;
|
|
3081
|
+
/** Tracks nesting depth for {@link withTransaction} so we can use savepoints. */
|
|
3082
|
+
private transactionDepth;
|
|
3083
|
+
/** Incrementing counter for deterministic savepoint names. */
|
|
3084
|
+
private savepointCounter;
|
|
1612
3085
|
/** Hot in-process ANN for blob backend (sqlite-vec unavailable platforms). */
|
|
1613
3086
|
private memoryIndex;
|
|
1614
3087
|
private memoryIndexDirty;
|
|
@@ -1630,40 +3103,65 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1630
3103
|
/** Coalesce concurrent insertMemory callers into one IMMEDIATE transaction. */
|
|
1631
3104
|
private insertQueue;
|
|
1632
3105
|
private insertFlushScheduled;
|
|
3106
|
+
/**
|
|
3107
|
+
* @param options - SQLite path / `:memory:` and optional concurrency config.
|
|
3108
|
+
*/
|
|
1633
3109
|
constructor(options: SqliteProviderOptions);
|
|
1634
3110
|
/** Absolute or relative path / `:memory:` used by this provider. */
|
|
1635
3111
|
get path(): string;
|
|
1636
3112
|
/** Expose DB for embedding cache store (same connection). */
|
|
1637
3113
|
getDatabase(): DatabaseSync | null;
|
|
3114
|
+
/** Register a callback invoked when SQLite busy retries occur (tests / diagnostics). */
|
|
1638
3115
|
setRetryLogger(fn: ((msg: string) => void) | null): void;
|
|
3116
|
+
/** Open the database, run migrations, and prepare statements. */
|
|
1639
3117
|
open(): Promise<void>;
|
|
3118
|
+
/** Drain pending inserts, optimize, and close the SQLite connection. */
|
|
1640
3119
|
close(): Promise<void>;
|
|
3120
|
+
/**
|
|
3121
|
+
* Create or validate vec0 / blob vector storage for the given dimensionality.
|
|
3122
|
+
*
|
|
3123
|
+
* @param dimensions - Embedding length from the configured model.
|
|
3124
|
+
*/
|
|
1641
3125
|
ensureVectorSchema(dimensions: number): Promise<void>;
|
|
3126
|
+
/** @inheritdoc StorageProvider.getEmbeddingDimensions */
|
|
1642
3127
|
getEmbeddingDimensions(): Promise<number | null>;
|
|
3128
|
+
/** @inheritdoc StorageProvider.setEmbeddingDimensions */
|
|
1643
3129
|
setEmbeddingDimensions(dimensions: number): Promise<void>;
|
|
3130
|
+
/** Insert a single memory row (coalesced under concurrent writers). */
|
|
1644
3131
|
insertMemory(input: InsertMemoryInput): Promise<MemoryRow>;
|
|
1645
3132
|
private scheduleInsertFlush;
|
|
1646
3133
|
private flushInsertQueue;
|
|
1647
3134
|
/** Single-row insert without coalescing (used by flush of size 1). */
|
|
1648
3135
|
private insertMemoryImmediate;
|
|
3136
|
+
/** Batch insert memories in chunked multi-row transactions. */
|
|
1649
3137
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
3138
|
+
/** Update memory content, metadata, embedding, and content hash. */
|
|
1650
3139
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
3140
|
+
/** Find an active memory by org, agent, and content hash (dedupe). */
|
|
1651
3141
|
findActiveByContentHash(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
3142
|
+
/** Scan memories matching metadata filters (may paginate in SQL). */
|
|
1652
3143
|
searchByMetadata(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
1653
3144
|
/** Keyword search via FTS5 BM25. Returns memory IDs ranked by relevance. */
|
|
3145
|
+
/** BM25 keyword search via FTS5 (`memories_fts`). */
|
|
1654
3146
|
searchKeyword(query: string, organization: string, topK: number): Promise<Array<{
|
|
1655
3147
|
memoryId: string;
|
|
1656
3148
|
score: number;
|
|
1657
3149
|
}>>;
|
|
3150
|
+
/** Fetch a memory row by UUID within an organization. */
|
|
1658
3151
|
getMemoryById(id: string, organization: string): Promise<MemoryRow | null>;
|
|
3152
|
+
/** Fetch a memory row by SQLite integer rowid within an organization. */
|
|
1659
3153
|
getMemoryByRowid(rowid: number, organization: string): Promise<MemoryRow | null>;
|
|
3154
|
+
/** Batch-fetch memory rows by SQLite rowids within an organization. */
|
|
1660
3155
|
getMemoriesByRowids(rowids: number[], organization: string): Promise<Map<number, MemoryRow>>;
|
|
3156
|
+
/** List memories matching repository filters with optional limit. */
|
|
1661
3157
|
listMemories(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
3158
|
+
/** Approximate nearest-neighbor search (vec0 or in-memory blob index). */
|
|
1662
3159
|
searchVectors(embedding: Float32Array, topK: number): Promise<VectorSearchHit[]>;
|
|
1663
3160
|
/**
|
|
1664
3161
|
* Org-scoped KNN + memory rows with adaptive overfetch.
|
|
1665
3162
|
* Global ANN is post-filtered by org/agent/archived; underfill triggers larger k.
|
|
1666
3163
|
*/
|
|
3164
|
+
/** ANN search joined with memory rows and org/archived post-filters. */
|
|
1667
3165
|
searchVectorsWithMemories(embedding: Float32Array, topK: number, organization: string, options?: {
|
|
1668
3166
|
agent?: string;
|
|
1669
3167
|
includeArchived?: boolean;
|
|
@@ -1671,18 +3169,26 @@ declare class SqliteStorageProvider implements StorageProvider {
|
|
|
1671
3169
|
row: MemoryRow;
|
|
1672
3170
|
distance: number;
|
|
1673
3171
|
}>>;
|
|
3172
|
+
/** Soft-archive memories (compression / forget paths). */
|
|
1674
3173
|
archiveMemories(ids: string[], organization: string, compressedIntoId: string, archivedAt: string): Promise<string[]>;
|
|
3174
|
+
/** Hard-delete a single memory by id; returns whether a row was removed. */
|
|
1675
3175
|
deleteMemoryById(id: string, organization: string): Promise<boolean>;
|
|
3176
|
+
/** Hard-delete memories matching org / agent / metadata filters. */
|
|
1676
3177
|
deleteMemoriesByFilter(filter: RepositoryFilter): Promise<number>;
|
|
3178
|
+
/** Remove all memories (and side tables) for an organization. */
|
|
1677
3179
|
clearOrganization(organization: string): Promise<number>;
|
|
3180
|
+
/** List audit history events for a memory id. */
|
|
1678
3181
|
getHistory(memoryId: string): Promise<HistoryRow[]>;
|
|
3182
|
+
/** Append a history row (created / archived / compressed / updated). */
|
|
1679
3183
|
insertHistoryEvent(event: HistoryRow): Promise<void>;
|
|
3184
|
+
/** Aggregate memory counts for an organization (single-pass SQL). */
|
|
1680
3185
|
getStats(organization: string): Promise<{
|
|
1681
3186
|
totalMemories: number;
|
|
1682
3187
|
activeMemories: number;
|
|
1683
3188
|
archivedMemories: number;
|
|
1684
3189
|
totalAgents: number;
|
|
1685
3190
|
}>;
|
|
3191
|
+
/** On-disk database file size in bytes (0 for `:memory:`). */
|
|
1686
3192
|
getDatabaseSizeBytes(): Promise<number>;
|
|
1687
3193
|
withTransaction<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
1688
3194
|
private tryLoadSqliteVec;
|
|
@@ -1795,6 +3301,7 @@ interface PostgresProviderOptions {
|
|
|
1795
3301
|
*/
|
|
1796
3302
|
durableWrites?: boolean;
|
|
1797
3303
|
}
|
|
3304
|
+
/** PostgreSQL + pgvector {@link StorageProvider} (`pg` optional peer). */
|
|
1798
3305
|
declare class PostgresStorageProvider implements StorageProvider {
|
|
1799
3306
|
readonly name = "postgres";
|
|
1800
3307
|
private readonly connectionString;
|
|
@@ -1813,7 +3320,11 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1813
3320
|
private insertFlushScheduled;
|
|
1814
3321
|
private insertFlushTimer;
|
|
1815
3322
|
private insertFlushInFlight;
|
|
3323
|
+
/**
|
|
3324
|
+
* @param options - Connection string, pool size, and durability flags.
|
|
3325
|
+
*/
|
|
1816
3326
|
constructor(options: PostgresProviderOptions);
|
|
3327
|
+
/** Current pg pool occupancy stats (for diagnostics / subscribe setup). */
|
|
1817
3328
|
getPoolStats(): {
|
|
1818
3329
|
max: number;
|
|
1819
3330
|
total: number;
|
|
@@ -1822,7 +3333,9 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1822
3333
|
};
|
|
1823
3334
|
/** Dedicated pool accessor for LISTEN/NOTIFY subscribe backend. */
|
|
1824
3335
|
getPool(): PgPool | null;
|
|
3336
|
+
/** Open the connection pool and run migrations. */
|
|
1825
3337
|
open(): Promise<void>;
|
|
3338
|
+
/** Drain coalesced inserts and end the connection pool. */
|
|
1826
3339
|
close(): Promise<void>;
|
|
1827
3340
|
/**
|
|
1828
3341
|
* Run a search query. HNSW GUCs are baked into pool startup options —
|
|
@@ -1836,24 +3349,39 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1836
3349
|
dropVectorIndex(): Promise<void>;
|
|
1837
3350
|
/** Force HNSW build now (e.g. before timed recall benches). */
|
|
1838
3351
|
ensureVectorIndex(): Promise<void>;
|
|
3352
|
+
/**
|
|
3353
|
+
* Create pgvector tables and HNSW index for the given dimensionality.
|
|
3354
|
+
*
|
|
3355
|
+
* @param dimensions - Embedding length from the configured model.
|
|
3356
|
+
*/
|
|
1839
3357
|
ensureVectorSchema(dimensions: number): Promise<void>;
|
|
1840
3358
|
private ensureVectorTables;
|
|
1841
3359
|
/** Cross-process subscribe: NOTIFY after a committed write. */
|
|
3360
|
+
/**
|
|
3361
|
+
* Issue `pg_notify` for cross-process {@link subscribe} delivery.
|
|
3362
|
+
*
|
|
3363
|
+
* @param event - Memory change payload (IDs + metadata only).
|
|
3364
|
+
*/
|
|
1842
3365
|
notifyChange(event: MemoryChangeEvent): Promise<void>;
|
|
1843
3366
|
/**
|
|
1844
3367
|
* Soft reset for a single organization. Drops HNSW only when the embeddings
|
|
1845
3368
|
* table is empty so other corpora on a shared bench DB stay intact.
|
|
1846
3369
|
*/
|
|
3370
|
+
/** Delete all rows for an organization (dev / test helper). */
|
|
1847
3371
|
resetOrganization(organization: string): Promise<void>;
|
|
1848
3372
|
/**
|
|
1849
3373
|
* Wipe all Wolbarg tables (explicit opt-in). Prefer {@link resetOrganization}.
|
|
1850
3374
|
*/
|
|
3375
|
+
/** Truncate all Wolbarg tables (dev / test helper). */
|
|
1851
3376
|
wipeAllData(): Promise<void>;
|
|
1852
3377
|
/** Build HNSW once before the first KNN query (bulk-friendly inserts). */
|
|
1853
3378
|
private ensureHnswIndex;
|
|
1854
3379
|
private buildHnswIndex;
|
|
3380
|
+
/** @inheritdoc StorageProvider.getEmbeddingDimensions */
|
|
1855
3381
|
getEmbeddingDimensions(): Promise<number | null>;
|
|
3382
|
+
/** @inheritdoc StorageProvider.setEmbeddingDimensions */
|
|
1856
3383
|
setEmbeddingDimensions(dimensions: number): Promise<void>;
|
|
3384
|
+
/** Insert a single memory row (coalesced under concurrent writers). */
|
|
1857
3385
|
insertMemory(input: InsertMemoryInput): Promise<MemoryRow>;
|
|
1858
3386
|
private clearInsertFlushTimer;
|
|
1859
3387
|
/** Flush coalesced inserts after a turn so concurrent remember() can join. */
|
|
@@ -1861,23 +3389,34 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1861
3389
|
private flushInsertQueue;
|
|
1862
3390
|
/** Single-row insert without coalescing (used by flush + batch of 1). */
|
|
1863
3391
|
private insertMemoryImmediate;
|
|
3392
|
+
/** Batch insert via unnest / COPY paths with optional HNSW deferral. */
|
|
1864
3393
|
insertMemoriesBatch(inputs: InsertMemoryInput[]): Promise<MemoryRow[]>;
|
|
1865
3394
|
private insertBatchPgvector;
|
|
1866
3395
|
/** Parallel unnest when HNSW is absent; sequential when index must stay consistent. */
|
|
1867
3396
|
private insertBatchChunked;
|
|
1868
3397
|
private insertOneBlob;
|
|
3398
|
+
/** Update memory content, metadata, embedding, and content hash. */
|
|
1869
3399
|
updateMemory(input: UpdateMemoryInput): Promise<MemoryRow | null>;
|
|
3400
|
+
/** Find an active memory by org, agent, and content hash (dedupe). */
|
|
1870
3401
|
findActiveByContentHash(organization: string, agent: string, contentHash: string): Promise<MemoryRow | null>;
|
|
3402
|
+
/** Fetch a memory row by UUID within an organization. */
|
|
1871
3403
|
getMemoryById(id: string, organization: string): Promise<MemoryRow | null>;
|
|
3404
|
+
/** Fetch a memory row by internal rowid within an organization. */
|
|
1872
3405
|
getMemoryByRowid(rowid: number, organization: string): Promise<MemoryRow | null>;
|
|
3406
|
+
/** Batch-fetch memory rows by rowids within an organization. */
|
|
1873
3407
|
getMemoriesByRowids(rowids: number[], organization: string): Promise<Map<number, MemoryRow>>;
|
|
3408
|
+
/** List memories matching repository filters with optional limit. */
|
|
1874
3409
|
listMemories(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
3410
|
+
/** Scan memories matching metadata filters. */
|
|
1875
3411
|
searchByMetadata(filter: RepositoryFilter, limit?: number): Promise<MemoryRow[]>;
|
|
3412
|
+
/** Full-text keyword search via `tsvector` / GIN index. */
|
|
1876
3413
|
searchKeyword(query: string, organization: string, topK: number): Promise<Array<{
|
|
1877
3414
|
memoryId: string;
|
|
1878
3415
|
score: number;
|
|
1879
3416
|
}>>;
|
|
3417
|
+
/** pgvector cosine ANN search (HNSW when index is present). */
|
|
1880
3418
|
searchVectors(embedding: Float32Array, topK: number): Promise<VectorSearchHit[]>;
|
|
3419
|
+
/** ANN search joined with memory rows and org/archived post-filters. */
|
|
1881
3420
|
searchVectorsWithMemories(embedding: Float32Array, topK: number, organization: string, options?: {
|
|
1882
3421
|
agent?: string;
|
|
1883
3422
|
includeArchived?: boolean;
|
|
@@ -1885,18 +3424,26 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1885
3424
|
row: MemoryRow;
|
|
1886
3425
|
distance: number;
|
|
1887
3426
|
}>>;
|
|
3427
|
+
/** Soft-archive memories (compression / forget paths). */
|
|
1888
3428
|
archiveMemories(ids: string[], organization: string, compressedIntoId: string, archivedAt: string): Promise<string[]>;
|
|
3429
|
+
/** Hard-delete a single memory by id; returns whether a row was removed. */
|
|
1889
3430
|
deleteMemoryById(id: string, organization: string): Promise<boolean>;
|
|
3431
|
+
/** Hard-delete memories matching org / agent / metadata filters. */
|
|
1890
3432
|
deleteMemoriesByFilter(filter: RepositoryFilter): Promise<number>;
|
|
3433
|
+
/** Remove all memories for an organization. */
|
|
1891
3434
|
clearOrganization(organization: string): Promise<number>;
|
|
3435
|
+
/** List audit history events for a memory id. */
|
|
1892
3436
|
getHistory(memoryId: string): Promise<HistoryRow[]>;
|
|
3437
|
+
/** Append a history row (created / archived / compressed / updated). */
|
|
1893
3438
|
insertHistoryEvent(event: HistoryRow): Promise<void>;
|
|
3439
|
+
/** Aggregate memory counts for an organization. */
|
|
1894
3440
|
getStats(organization: string): Promise<{
|
|
1895
3441
|
totalMemories: number;
|
|
1896
3442
|
activeMemories: number;
|
|
1897
3443
|
archivedMemories: number;
|
|
1898
3444
|
totalAgents: number;
|
|
1899
3445
|
}>;
|
|
3446
|
+
/** Approximate on-disk database size in bytes (`pg_database_size`). */
|
|
1900
3447
|
getDatabaseSizeBytes(): Promise<number>;
|
|
1901
3448
|
withTransaction<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
1902
3449
|
private runMigrations;
|
|
@@ -1914,10 +3461,31 @@ declare class PostgresStorageProvider implements StorageProvider {
|
|
|
1914
3461
|
private describe;
|
|
1915
3462
|
}
|
|
1916
3463
|
|
|
3464
|
+
/**
|
|
3465
|
+
* Create a storage provider from SQLite or PostgreSQL configuration.
|
|
3466
|
+
*
|
|
3467
|
+
* @param config - Storage or database config with `provider` and connection URL.
|
|
3468
|
+
* @param options - Optional SQLite concurrency tuning.
|
|
3469
|
+
* @param options.concurrency - Lock retry / timeout settings for SQLite writes.
|
|
3470
|
+
* @returns An unopened {@link StorageProvider} — call `open()` before use.
|
|
3471
|
+
* @throws {@link ConfigurationError} when URL or provider is invalid.
|
|
3472
|
+
*
|
|
3473
|
+
* @example
|
|
3474
|
+
* ```ts
|
|
3475
|
+
* const storage = createStorageProvider(
|
|
3476
|
+
* { provider: "postgres", url: process.env.DATABASE_URL! },
|
|
3477
|
+
* { concurrency: { maxRetries: 5 } },
|
|
3478
|
+
* );
|
|
3479
|
+
* ```
|
|
3480
|
+
*/
|
|
1917
3481
|
declare function createStorageProvider(config: StorageConfig | DatabaseConfig, options?: {
|
|
1918
3482
|
concurrency?: ConcurrencyConfig$1;
|
|
1919
3483
|
}): StorageProvider;
|
|
1920
|
-
/**
|
|
3484
|
+
/**
|
|
3485
|
+
* @deprecated Prefer {@link createStorageProvider}.
|
|
3486
|
+
* @param config - Legacy database configuration object.
|
|
3487
|
+
* @returns A {@link StorageProvider} instance.
|
|
3488
|
+
*/
|
|
1921
3489
|
declare function createDatabaseProvider(config: DatabaseConfig): StorageProvider;
|
|
1922
3490
|
|
|
1923
3491
|
/**
|
|
@@ -1938,18 +3506,43 @@ interface SqliteGraphProviderOptions {
|
|
|
1938
3506
|
/** Optional write-concurrency tuning (same shape as memory SQLite). */
|
|
1939
3507
|
concurrency?: ConcurrencyConfig;
|
|
1940
3508
|
}
|
|
3509
|
+
/**
|
|
3510
|
+
* File-backed {@link GraphProvider} using recursive SQL CTEs over `graph_nodes` / `graph_edges`.
|
|
3511
|
+
*/
|
|
1941
3512
|
declare class SqliteGraphProvider implements GraphProvider {
|
|
1942
3513
|
readonly name = "sqlite";
|
|
1943
3514
|
private readonly dbPath;
|
|
1944
3515
|
private readonly concurrency;
|
|
1945
3516
|
private db;
|
|
1946
3517
|
private opened;
|
|
3518
|
+
/**
|
|
3519
|
+
* @param options - Graph SQLite path and optional concurrency tuning.
|
|
3520
|
+
*/
|
|
1947
3521
|
constructor(options: SqliteGraphProviderOptions);
|
|
3522
|
+
/** Whether this provider supports file snapshots for checkpoint / export. */
|
|
1948
3523
|
supportsFileSnapshot(): boolean;
|
|
3524
|
+
/** Absolute graph database path, or `null` for `:memory:`. */
|
|
1949
3525
|
getDataPath(): string | null;
|
|
3526
|
+
/** Open the graph SQLite file, apply pragmas, and create schema if needed. */
|
|
1950
3527
|
open(): Promise<void>;
|
|
3528
|
+
/** Close the graph database connection. */
|
|
1951
3529
|
close(): Promise<void>;
|
|
3530
|
+
/**
|
|
3531
|
+
* Create or replace a directed memory↔memory edge.
|
|
3532
|
+
*
|
|
3533
|
+
* @param fromId - Source memory UUID.
|
|
3534
|
+
* @param toId - Target memory UUID.
|
|
3535
|
+
* @param relation - Edge label (e.g. `"related_to"`, `"caused_by"`).
|
|
3536
|
+
* @param metadata - Optional JSON metadata stored on the edge.
|
|
3537
|
+
*/
|
|
1952
3538
|
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
3539
|
+
/**
|
|
3540
|
+
* Remove edges between two memories.
|
|
3541
|
+
*
|
|
3542
|
+
* @param fromId - Source memory UUID.
|
|
3543
|
+
* @param toId - Target memory UUID.
|
|
3544
|
+
* @param relation - When set, only delete edges with this relation label.
|
|
3545
|
+
*/
|
|
1953
3546
|
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
1954
3547
|
/**
|
|
1955
3548
|
* Bounded recursive CTE over `graph_edges`.
|
|
@@ -1962,14 +3555,33 @@ declare class SqliteGraphProvider implements GraphProvider {
|
|
|
1962
3555
|
* re-hydrates full rows via `toMemoryRecord` from storage when possible.
|
|
1963
3556
|
*/
|
|
1964
3557
|
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
3558
|
+
/**
|
|
3559
|
+
* Insert or update a named entity node.
|
|
3560
|
+
*
|
|
3561
|
+
* @param entity - Entity name, type, and optional metadata.
|
|
3562
|
+
* @returns Stable entity id ({@link entityIdFrom}).
|
|
3563
|
+
*/
|
|
1965
3564
|
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
3565
|
+
/**
|
|
3566
|
+
* Link an entity to a memory via a `MENTIONS` edge (not traversed by {@link getRelated}).
|
|
3567
|
+
*
|
|
3568
|
+
* @param entityId - Entity id from {@link upsertEntity}.
|
|
3569
|
+
* @param memoryId - Target memory UUID.
|
|
3570
|
+
* @param role - Optional role string stored on the edge metadata.
|
|
3571
|
+
*/
|
|
1966
3572
|
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
3573
|
+
/**
|
|
3574
|
+
* Remove the memory node and incident edges when a memory is hard-deleted.
|
|
3575
|
+
*
|
|
3576
|
+
* @param memoryId - Wolbarg memory UUID.
|
|
3577
|
+
*/
|
|
1967
3578
|
deleteMemory(memoryId: string): Promise<void>;
|
|
1968
3579
|
/**
|
|
1969
3580
|
* Raw Cypher escape hatch — **not supported** on the SQLite graph provider.
|
|
1970
3581
|
* Use the typed methods, or open the underlying SQLite file yourself for raw SQL.
|
|
1971
3582
|
*/
|
|
1972
3583
|
query(_cypher: string, _params?: Record<string, unknown>): Promise<unknown>;
|
|
3584
|
+
/** Lightweight connectivity and schema statistics check. */
|
|
1973
3585
|
health(): Promise<GraphHealthResult>;
|
|
1974
3586
|
private withTx;
|
|
1975
3587
|
private requireDb;
|
|
@@ -1988,11 +3600,18 @@ declare class SqliteGraphProvider implements GraphProvider {
|
|
|
1988
3600
|
*/
|
|
1989
3601
|
|
|
1990
3602
|
interface Neo4jGraphProviderOptions {
|
|
3603
|
+
/** Bolt / Neo4j URI (e.g. `neo4j://localhost:7687`). */
|
|
1991
3604
|
url: string;
|
|
3605
|
+
/** Neo4j username. */
|
|
1992
3606
|
username: string;
|
|
3607
|
+
/** Neo4j password. */
|
|
1993
3608
|
password: string;
|
|
3609
|
+
/** Optional multi-database name (Neo4j 4+). */
|
|
1994
3610
|
database?: string;
|
|
1995
3611
|
}
|
|
3612
|
+
/**
|
|
3613
|
+
* Networked {@link GraphProvider} backed by Neo4j (`neo4j-driver` optional peer).
|
|
3614
|
+
*/
|
|
1996
3615
|
declare class Neo4jGraphProvider implements GraphProvider {
|
|
1997
3616
|
readonly name = "neo4j";
|
|
1998
3617
|
private readonly url;
|
|
@@ -2001,53 +3620,156 @@ declare class Neo4jGraphProvider implements GraphProvider {
|
|
|
2001
3620
|
private readonly database;
|
|
2002
3621
|
private driver;
|
|
2003
3622
|
private opened;
|
|
3623
|
+
/**
|
|
3624
|
+
* @param options - Bolt URL, credentials, and optional database name.
|
|
3625
|
+
*/
|
|
2004
3626
|
constructor(options: Neo4jGraphProviderOptions);
|
|
3627
|
+
/** Neo4j does not support local file snapshots for checkpoint pairing. */
|
|
2005
3628
|
supportsFileSnapshot(): boolean;
|
|
3629
|
+
/** Always `null` — graph data lives in the remote Neo4j cluster. */
|
|
2006
3630
|
getDataPath(): string | null;
|
|
3631
|
+
/** Connect to Neo4j, verify connectivity, and ensure uniqueness constraints. */
|
|
2007
3632
|
open(): Promise<void>;
|
|
3633
|
+
/** Close the neo4j-driver connection. */
|
|
2008
3634
|
close(): Promise<void>;
|
|
2009
3635
|
private requireDriver;
|
|
2010
3636
|
private withSession;
|
|
2011
3637
|
private run;
|
|
3638
|
+
private runOnSession;
|
|
2012
3639
|
private ensureMemoryNode;
|
|
3640
|
+
/**
|
|
3641
|
+
* MERGE a directed `RELATED` relationship between two memory nodes.
|
|
3642
|
+
*
|
|
3643
|
+
* @param fromId - Source memory UUID.
|
|
3644
|
+
* @param toId - Target memory UUID.
|
|
3645
|
+
* @param relation - Relationship label stored on `RELATED.relation`.
|
|
3646
|
+
* @param metadata - Optional JSON metadata on the relationship.
|
|
3647
|
+
*/
|
|
2013
3648
|
linkMemories(fromId: string, toId: string, relation: string, metadata?: Record<string, unknown>): Promise<void>;
|
|
3649
|
+
/**
|
|
3650
|
+
* Delete `RELATED` relationship(s) between two memories.
|
|
3651
|
+
*
|
|
3652
|
+
* @param fromId - Source memory UUID.
|
|
3653
|
+
* @param toId - Target memory UUID.
|
|
3654
|
+
* @param relation - When set, only delete edges with this relation property.
|
|
3655
|
+
*/
|
|
2014
3656
|
unlinkMemories(fromId: string, toId: string, relation?: string): Promise<void>;
|
|
2015
3657
|
/**
|
|
2016
3658
|
* Native Neo4j variable-length path traversal.
|
|
2017
3659
|
* Relationship filter uses RELATED.relation property for parity with Kuzu.
|
|
2018
3660
|
*/
|
|
2019
3661
|
getRelated(memoryId: string, options?: GetRelatedOptions): Promise<MemoryRecord[]>;
|
|
3662
|
+
/**
|
|
3663
|
+
* MERGE an `Entity` node keyed by deterministic id.
|
|
3664
|
+
*
|
|
3665
|
+
* @param entity - Entity name, type, and optional metadata.
|
|
3666
|
+
* @returns Stable entity id ({@link entityIdFrom}).
|
|
3667
|
+
*/
|
|
2020
3668
|
upsertEntity(entity: GraphEntityInput): Promise<string>;
|
|
3669
|
+
/**
|
|
3670
|
+
* MERGE a `MENTIONS` relationship from entity to memory.
|
|
3671
|
+
*
|
|
3672
|
+
* @param entityId - Entity id from {@link upsertEntity}.
|
|
3673
|
+
* @param memoryId - Target memory UUID.
|
|
3674
|
+
* @param role - Optional role string on the relationship.
|
|
3675
|
+
*/
|
|
2021
3676
|
linkEntityToMemory(entityId: string, memoryId: string, role?: string): Promise<void>;
|
|
3677
|
+
/**
|
|
3678
|
+
* DETACH DELETE the memory node and all incident relationships.
|
|
3679
|
+
*
|
|
3680
|
+
* @param memoryId - Wolbarg memory UUID.
|
|
3681
|
+
*/
|
|
2022
3682
|
deleteMemory(memoryId: string): Promise<void>;
|
|
3683
|
+
/**
|
|
3684
|
+
* Run arbitrary parameterized Cypher (escape hatch for advanced graph queries).
|
|
3685
|
+
*
|
|
3686
|
+
* @param cypher - Cypher query string.
|
|
3687
|
+
* @param params - Bound parameters for the query.
|
|
3688
|
+
* @returns Raw row objects from the driver.
|
|
3689
|
+
*/
|
|
2023
3690
|
query(cypher: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
3691
|
+
/** Verify connectivity and return server metadata when available. */
|
|
2024
3692
|
health(): Promise<GraphHealthResult>;
|
|
2025
3693
|
}
|
|
2026
3694
|
|
|
2027
3695
|
/**
|
|
2028
3696
|
* Database-agnostic memory persistence contract.
|
|
2029
|
-
*
|
|
3697
|
+
*
|
|
3698
|
+
* Alias of {@link StorageProvider} for the v0.3+ provider architecture naming.
|
|
3699
|
+
* Custom memory backends should implement {@link StorageProvider} in
|
|
3700
|
+
* `sdk/src/storage/types.ts` — this type is a semantic alias only.
|
|
2030
3701
|
*/
|
|
2031
3702
|
|
|
2032
|
-
/**
|
|
3703
|
+
/**
|
|
3704
|
+
* Memory / vector storage provider.
|
|
3705
|
+
*
|
|
3706
|
+
* Built-in implementations: {@link SqliteStorageProvider}, {@link PostgresStorageProvider}.
|
|
3707
|
+
*
|
|
3708
|
+
* @example
|
|
3709
|
+
* ```ts
|
|
3710
|
+
* import type { MemoryProvider } from "wolbarg/providers";
|
|
3711
|
+
*
|
|
3712
|
+
* function useStorage(provider: MemoryProvider) {
|
|
3713
|
+
* return provider.getMemoryById(id, org);
|
|
3714
|
+
* }
|
|
3715
|
+
* ```
|
|
3716
|
+
*/
|
|
2033
3717
|
type MemoryProvider = StorageProvider;
|
|
2034
3718
|
|
|
2035
3719
|
/**
|
|
2036
|
-
* Internal event persistence contract.
|
|
2037
|
-
*
|
|
3720
|
+
* Internal event persistence contract for telemetry storage.
|
|
3721
|
+
*
|
|
3722
|
+
* Distinct from {@link MemoryProvider} — telemetry MUST use separate tables/database.
|
|
2038
3723
|
*/
|
|
2039
3724
|
|
|
3725
|
+
/**
|
|
3726
|
+
* Low-level event database used by {@link TelemetryProvider} implementations.
|
|
3727
|
+
*
|
|
3728
|
+
* Implement this interface when adding a new telemetry backend (e.g. Postgres events).
|
|
3729
|
+
*
|
|
3730
|
+
* @example
|
|
3731
|
+
* ```ts
|
|
3732
|
+
* class MyEventDb implements EventDatabase {
|
|
3733
|
+
* readonly name = "my-events";
|
|
3734
|
+
* async open() { /* migrate schema *\/ }
|
|
3735
|
+
* async close() {}
|
|
3736
|
+
* async insertEvent(input) { /* persist *\/ return { ...input, id: "...", timestamp: "..." }; }
|
|
3737
|
+
* async query(options) { return { events: [], total: 0, limit: 0, offset: 0 }; }
|
|
3738
|
+
* async getEvent(id) { return null; }
|
|
3739
|
+
* }
|
|
3740
|
+
* ```
|
|
3741
|
+
*/
|
|
2040
3742
|
interface EventDatabase {
|
|
3743
|
+
/** Backend identifier. */
|
|
2041
3744
|
readonly name: string;
|
|
3745
|
+
/** Open connection and ensure event schema. */
|
|
2042
3746
|
open(): Promise<void>;
|
|
3747
|
+
/** Close connection and flush pending writes. */
|
|
2043
3748
|
close(): Promise<void>;
|
|
2044
|
-
/**
|
|
3749
|
+
/**
|
|
3750
|
+
* Insert one telemetry event row.
|
|
3751
|
+
* @param event - Event input (id/timestamp may be assigned by the backend).
|
|
3752
|
+
*/
|
|
2045
3753
|
insertEvent(event: TelemetryEventInput): Promise<TelemetryEvent>;
|
|
2046
|
-
/**
|
|
3754
|
+
/**
|
|
3755
|
+
* Batch insert events (optional optimization).
|
|
3756
|
+
* @param events - Non-empty event batch.
|
|
3757
|
+
*/
|
|
2047
3758
|
insertEvents?(events: TelemetryEventInput[]): Promise<TelemetryEvent[]>;
|
|
3759
|
+
/**
|
|
3760
|
+
* Query persisted events (Studio / debugging).
|
|
3761
|
+
* @param options - Filters, pagination, and sort order.
|
|
3762
|
+
*/
|
|
2048
3763
|
query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
|
|
3764
|
+
/**
|
|
3765
|
+
* Fetch a single event by id.
|
|
3766
|
+
* @param id - Event UUID.
|
|
3767
|
+
*/
|
|
2049
3768
|
getEvent(id: string): Promise<TelemetryEvent | null>;
|
|
2050
|
-
/**
|
|
3769
|
+
/**
|
|
3770
|
+
* Aggregate helpers used by Studio dashboards (optional).
|
|
3771
|
+
* @param filter - Optional time and operation filters.
|
|
3772
|
+
*/
|
|
2051
3773
|
countEvents?(filter?: {
|
|
2052
3774
|
since?: string;
|
|
2053
3775
|
operation?: string;
|
|
@@ -2070,13 +3792,24 @@ declare class SqliteEventDatabase implements EventDatabase {
|
|
|
2070
3792
|
private db;
|
|
2071
3793
|
private insertStmt;
|
|
2072
3794
|
private columns;
|
|
3795
|
+
/**
|
|
3796
|
+
* @param options.url - Path to the telemetry SQLite file.
|
|
3797
|
+
* @param options.readonly - Open read-only (Studio / analytics).
|
|
3798
|
+
*/
|
|
2073
3799
|
constructor(options: SqliteEventDatabaseOptions);
|
|
3800
|
+
/** Open the telemetry database and run schema migrations. */
|
|
2074
3801
|
open(): Promise<void>;
|
|
3802
|
+
/** Close the telemetry database connection. */
|
|
2075
3803
|
close(): Promise<void>;
|
|
3804
|
+
/** Insert one normalized telemetry event row. */
|
|
2076
3805
|
insertEvent(input: TelemetryEventInput): Promise<TelemetryEvent>;
|
|
3806
|
+
/** Insert many events in a single transaction. */
|
|
2077
3807
|
insertEvents(inputs: TelemetryEventInput[]): Promise<TelemetryEvent[]>;
|
|
3808
|
+
/** Query telemetry events with filters, sort, and pagination. */
|
|
2078
3809
|
query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
|
|
3810
|
+
/** Fetch one event by primary key. */
|
|
2079
3811
|
getEvent(id: string): Promise<TelemetryEvent | null>;
|
|
3812
|
+
/** Count events optionally filtered by time and operation. */
|
|
2080
3813
|
countEvents(filter?: {
|
|
2081
3814
|
since?: string;
|
|
2082
3815
|
operation?: string;
|
|
@@ -2102,12 +3835,27 @@ declare class SqliteTelemetryProvider implements TelemetryProvider {
|
|
|
2102
3835
|
private flushing;
|
|
2103
3836
|
private closed;
|
|
2104
3837
|
private openPromise;
|
|
3838
|
+
private warnedQueueDrop;
|
|
3839
|
+
private warnedFlushFailure;
|
|
3840
|
+
/**
|
|
3841
|
+
* @param options.url - Path to the independent telemetry SQLite database file.
|
|
3842
|
+
*/
|
|
2105
3843
|
constructor(options: SqliteTelemetryProviderOptions);
|
|
3844
|
+
/** Open the telemetry EventDatabase (lazy — also invoked on first emit). */
|
|
2106
3845
|
open(): Promise<void>;
|
|
3846
|
+
/** Flush pending events and close the telemetry database. */
|
|
2107
3847
|
close(): Promise<void>;
|
|
3848
|
+
/**
|
|
3849
|
+
* Enqueue a telemetry event for async persistence (never throws).
|
|
3850
|
+
*
|
|
3851
|
+
* @param event - Partial or complete {@link TelemetryEventInput}.
|
|
3852
|
+
*/
|
|
2108
3853
|
emit(event: TelemetryEventInput): void;
|
|
3854
|
+
/** Block until all queued events are written (or dropped on failure). */
|
|
2109
3855
|
flush(): Promise<void>;
|
|
3856
|
+
/** Query persisted telemetry events with filters and pagination. */
|
|
2110
3857
|
query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
|
|
3858
|
+
/** Fetch a single telemetry event by id. */
|
|
2111
3859
|
getEvent(id: string): Promise<TelemetryEvent | null>;
|
|
2112
3860
|
private scheduleFlush;
|
|
2113
3861
|
private runFlush;
|
|
@@ -2126,13 +3874,34 @@ declare class SqliteCheckpointProvider implements CheckpointProvider {
|
|
|
2126
3874
|
readonly name = "sqlite";
|
|
2127
3875
|
private readonly directory;
|
|
2128
3876
|
private ready;
|
|
3877
|
+
/**
|
|
3878
|
+
* @param options.directory - Folder for `.json` metadata and `.db` snapshot files.
|
|
3879
|
+
*/
|
|
2129
3880
|
constructor(options?: SqliteCheckpointProviderOptions);
|
|
3881
|
+
/** Ensure the checkpoint directory exists. */
|
|
2130
3882
|
open(): Promise<void>;
|
|
3883
|
+
/** Mark the provider closed (does not delete snapshots). */
|
|
2131
3884
|
close(): Promise<void>;
|
|
3885
|
+
/**
|
|
3886
|
+
* Create an immutable SQLite backup of `sourcePath` under a unique name.
|
|
3887
|
+
*
|
|
3888
|
+
* @param name - Checkpoint label (must not already exist).
|
|
3889
|
+
* @param sourcePath - Live memory database path to snapshot.
|
|
3890
|
+
* @param options.description - Optional human-readable description stored in metadata.
|
|
3891
|
+
*/
|
|
2132
3892
|
checkpoint(name: string, sourcePath: string, options?: CreateCheckpointOptions): Promise<CheckpointMeta>;
|
|
3893
|
+
/**
|
|
3894
|
+
* Restore a named checkpoint over `targetPath` (replaces WAL/SHM side files).
|
|
3895
|
+
*
|
|
3896
|
+
* @param name - Existing checkpoint name.
|
|
3897
|
+
* @param targetPath - Live memory database path to overwrite.
|
|
3898
|
+
*/
|
|
2133
3899
|
rollback(name: string, targetPath: string): Promise<CheckpointMeta>;
|
|
3900
|
+
/** Delete checkpoint metadata and snapshot files for `name`. */
|
|
2134
3901
|
deleteCheckpoint(name: string): Promise<boolean>;
|
|
3902
|
+
/** List all checkpoints sorted by creation time. */
|
|
2135
3903
|
listCheckpoints(): Promise<CheckpointMeta[]>;
|
|
3904
|
+
/** Load checkpoint metadata by name, or `null` if missing / corrupt. */
|
|
2136
3905
|
getCheckpoint(name: string): Promise<CheckpointMeta | null>;
|
|
2137
3906
|
/**
|
|
2138
3907
|
* Consistent SQLite file backup (WAL checkpoint + backup API / copy).
|
|
@@ -2156,28 +3925,56 @@ declare class SqliteCheckpointProvider implements CheckpointProvider {
|
|
|
2156
3925
|
}
|
|
2157
3926
|
|
|
2158
3927
|
/**
|
|
2159
|
-
* Cross-platform structured logger gated by TelemetryLogLevel.
|
|
3928
|
+
* Cross-platform structured logger gated by {@link TelemetryLogLevel}.
|
|
3929
|
+
*
|
|
3930
|
+
* Used internally by {@link TelemetryEmitter}; also exported for adapter packages.
|
|
2160
3931
|
*/
|
|
2161
3932
|
|
|
2162
3933
|
declare class WolbargLogger {
|
|
2163
3934
|
private level;
|
|
3935
|
+
/** @param level - Minimum level to print (default `"info"`). */
|
|
2164
3936
|
constructor(level?: TelemetryLogLevel);
|
|
3937
|
+
/** Change the minimum log level at runtime. */
|
|
2165
3938
|
setLevel(level: TelemetryLogLevel): void;
|
|
3939
|
+
/** @returns Current minimum log level. */
|
|
2166
3940
|
getLevel(): TelemetryLogLevel;
|
|
3941
|
+
/** Log at error level. */
|
|
2167
3942
|
error(message: string, extra?: unknown): void;
|
|
3943
|
+
/** Log at warn level.
|
|
3944
|
+
* @param message - Primary log line.
|
|
3945
|
+
* @param extra - Optional structured payload.
|
|
3946
|
+
*/
|
|
2168
3947
|
warn(message: string, extra?: unknown): void;
|
|
3948
|
+
/** Log at info level.
|
|
3949
|
+
* @param message - Primary log line.
|
|
3950
|
+
* @param extra - Optional structured payload.
|
|
3951
|
+
*/
|
|
2169
3952
|
info(message: string, extra?: unknown): void;
|
|
3953
|
+
/** Log at debug level.
|
|
3954
|
+
* @param message - Primary log line.
|
|
3955
|
+
* @param extra - Optional structured payload.
|
|
3956
|
+
*/
|
|
2170
3957
|
debug(message: string, extra?: unknown): void;
|
|
3958
|
+
/** Log at trace level.
|
|
3959
|
+
* @param message - Primary log line.
|
|
3960
|
+
* @param extra - Optional structured payload.
|
|
3961
|
+
*/
|
|
2171
3962
|
trace(message: string, extra?: unknown): void;
|
|
2172
3963
|
private write;
|
|
2173
3964
|
}
|
|
2174
3965
|
|
|
2175
3966
|
/**
|
|
2176
|
-
* Trace context helpers — session_id
|
|
3967
|
+
* Trace context helpers — `session_id`, `trace_id`, `parent_trace_id`.
|
|
3968
|
+
*
|
|
3969
|
+
* Used by {@link TelemetryEmitter} to correlate memory operations in Studio.
|
|
2177
3970
|
*/
|
|
3971
|
+
/** Distributed trace context attached to telemetry events. */
|
|
2178
3972
|
interface TraceContext {
|
|
3973
|
+
/** Wolbarg instance session id (stable for process lifetime). */
|
|
2179
3974
|
sessionId: string;
|
|
3975
|
+
/** Unique id for this operation span. */
|
|
2180
3976
|
traceId: string;
|
|
3977
|
+
/** Parent span id when nested, else `null`. */
|
|
2181
3978
|
parentTraceId: string | null;
|
|
2182
3979
|
}
|
|
2183
3980
|
|
|
@@ -2185,56 +3982,114 @@ interface TraceContext {
|
|
|
2185
3982
|
* Async telemetry emitter that never blocks memory operations.
|
|
2186
3983
|
*/
|
|
2187
3984
|
|
|
3985
|
+
/** No-op telemetry provider used when observability is disabled. */
|
|
2188
3986
|
declare class NoopTelemetryProvider implements TelemetryProvider {
|
|
2189
3987
|
readonly name = "noop";
|
|
3988
|
+
/** @inheritdoc TelemetryProvider.open */
|
|
2190
3989
|
open(): Promise<void>;
|
|
3990
|
+
/** @inheritdoc TelemetryProvider.close */
|
|
2191
3991
|
close(): Promise<void>;
|
|
3992
|
+
/** @inheritdoc TelemetryProvider.emit */
|
|
2192
3993
|
emit(_event: TelemetryEventInput): void;
|
|
3994
|
+
/** @inheritdoc TelemetryProvider.flush */
|
|
2193
3995
|
flush(): Promise<void>;
|
|
2194
3996
|
}
|
|
3997
|
+
/**
|
|
3998
|
+
* Handle for an in-flight traced operation.
|
|
3999
|
+
*
|
|
4000
|
+
* Created by {@link TelemetryEmitter.start}. Call `success()` or `failure()`
|
|
4001
|
+
* exactly once when the operation completes.
|
|
4002
|
+
*/
|
|
2195
4003
|
interface OperationTraceHandle {
|
|
4004
|
+
/** Distributed trace context (session, trace, parent ids). */
|
|
2196
4005
|
context: TraceContext;
|
|
4006
|
+
/** `performance.now()` at operation start. */
|
|
2197
4007
|
startedAt: number;
|
|
4008
|
+
/** Partial latency breakdown filled via {@link OperationTraceHandle.mark}. */
|
|
2198
4009
|
latency: Partial<LatencyBreakdown>;
|
|
4010
|
+
/** Start a child trace for nested operations. */
|
|
2199
4011
|
child(operation: TelemetryOperation): OperationTraceHandle;
|
|
4012
|
+
/** Record stage latency in milliseconds. */
|
|
2200
4013
|
mark(stage: keyof Omit<LatencyBreakdown, "totalMs">, ms: number): void;
|
|
4014
|
+
/** Emit a successful completion event. */
|
|
2201
4015
|
success(fields?: Partial<TelemetryEventInput>): void;
|
|
4016
|
+
/** Emit a failed completion event. */
|
|
2202
4017
|
failure(error: unknown, fields?: Partial<TelemetryEventInput>): void;
|
|
2203
4018
|
}
|
|
4019
|
+
/** Default organization injected into events when not overridden per-call. */
|
|
2204
4020
|
interface TelemetryEmitterContext {
|
|
4021
|
+
/** Organization namespace from Wolbarg constructor. */
|
|
2205
4022
|
organization?: string | null;
|
|
2206
4023
|
}
|
|
4024
|
+
/**
|
|
4025
|
+
* Async telemetry emitter — never blocks memory operations.
|
|
4026
|
+
*
|
|
4027
|
+
* Wraps a {@link TelemetryProvider} with session/trace lifecycle helpers and
|
|
4028
|
+
* configurable capture flags (queries, latency, errors, similarity scores).
|
|
4029
|
+
*/
|
|
2207
4030
|
declare class TelemetryEmitter {
|
|
4031
|
+
/** Stable session id for this Wolbarg instance lifetime. */
|
|
2208
4032
|
readonly sessionId: string;
|
|
4033
|
+
/** Structured logger gated by telemetry log level. */
|
|
2209
4034
|
readonly logger: WolbargLogger;
|
|
2210
4035
|
private provider;
|
|
2211
4036
|
private readonly config;
|
|
2212
4037
|
private readonly context;
|
|
4038
|
+
/**
|
|
4039
|
+
* @param provider - Telemetry backend, or `null` for {@link NoopTelemetryProvider}.
|
|
4040
|
+
* @param config - Capture flags and log level.
|
|
4041
|
+
* @param context - Default organization injected into events.
|
|
4042
|
+
*/
|
|
2213
4043
|
constructor(provider: TelemetryProvider | null, config?: Partial<TelemetryConfig>, context?: TelemetryEmitterContext);
|
|
4044
|
+
/** Whether telemetry is enabled and backed by a non-noop provider. */
|
|
2214
4045
|
get enabled(): boolean;
|
|
4046
|
+
/** Replace the underlying telemetry provider (e.g. after lazy init). */
|
|
2215
4047
|
setProvider(provider: TelemetryProvider): void;
|
|
4048
|
+
/** Open the underlying telemetry provider when enabled. */
|
|
2216
4049
|
open(): Promise<void>;
|
|
4050
|
+
/** Flush pending events and close the telemetry provider. */
|
|
2217
4051
|
close(): Promise<void>;
|
|
4052
|
+
/** Flush pending telemetry events without closing the provider. */
|
|
2218
4053
|
flush(): Promise<void>;
|
|
4054
|
+
/**
|
|
4055
|
+
* Begin tracing an operation.
|
|
4056
|
+
*
|
|
4057
|
+
* @param operation - Public telemetry operation name.
|
|
4058
|
+
* @param parent - Optional parent trace for nested spans.
|
|
4059
|
+
* @returns Handle — call `success()` or `failure()` when done.
|
|
4060
|
+
*/
|
|
2219
4061
|
start(operation: TelemetryOperation, parent?: TraceContext): OperationTraceHandle;
|
|
4062
|
+
/** Emit a startup telemetry event. */
|
|
2220
4063
|
emitStartup(provider: string): void;
|
|
4064
|
+
/** Emit a shutdown telemetry event. */
|
|
2221
4065
|
emitShutdown(provider: string): void;
|
|
2222
4066
|
}
|
|
2223
4067
|
|
|
2224
4068
|
/**
|
|
2225
|
-
* Internal benchmark helpers for CLI
|
|
2226
|
-
*
|
|
4069
|
+
* Internal benchmark helpers for CLI and Studio performance tooling.
|
|
4070
|
+
*
|
|
4071
|
+
* @internal Exported for harness scripts — not part of the stable public API surface.
|
|
2227
4072
|
*/
|
|
4073
|
+
/** Single timed iteration result. */
|
|
2228
4074
|
interface BenchmarkSample {
|
|
4075
|
+
/** Benchmark scenario name. */
|
|
2229
4076
|
name: string;
|
|
4077
|
+
/** Wall-clock duration in milliseconds. */
|
|
2230
4078
|
durationMs: number;
|
|
4079
|
+
/** Whether the iteration completed without throwing. */
|
|
2231
4080
|
ok: boolean;
|
|
4081
|
+
/** Error message when `ok` is false. */
|
|
2232
4082
|
error?: string;
|
|
2233
4083
|
}
|
|
4084
|
+
/** Aggregated benchmark report with percentile summary. */
|
|
2234
4085
|
interface BenchmarkReport {
|
|
4086
|
+
/** ISO-8601 start timestamp. */
|
|
2235
4087
|
startedAt: string;
|
|
4088
|
+
/** ISO-8601 end timestamp. */
|
|
2236
4089
|
finishedAt: string;
|
|
4090
|
+
/** Raw per-iteration samples. */
|
|
2237
4091
|
samples: BenchmarkSample[];
|
|
4092
|
+
/** Rollup statistics across successful iterations. */
|
|
2238
4093
|
summary: {
|
|
2239
4094
|
count: number;
|
|
2240
4095
|
ok: number;
|
|
@@ -2245,7 +4100,23 @@ interface BenchmarkReport {
|
|
|
2245
4100
|
p99Ms: number;
|
|
2246
4101
|
};
|
|
2247
4102
|
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Run a benchmark function for a fixed number of iterations.
|
|
4105
|
+
*
|
|
4106
|
+
* @param name - Scenario label attached to each sample.
|
|
4107
|
+
* @param iterations - Number of times to invoke `fn`.
|
|
4108
|
+
* @param fn - Async or sync work to measure.
|
|
4109
|
+
* @returns One {@link BenchmarkSample} per iteration (failures captured, not thrown).
|
|
4110
|
+
*/
|
|
2248
4111
|
declare function runBenchmark(name: string, iterations: number, fn: () => Promise<void> | void): Promise<BenchmarkSample[]>;
|
|
4112
|
+
/**
|
|
4113
|
+
* Summarize benchmark samples into a report with avg / p50 / p95 / p99 latencies.
|
|
4114
|
+
*
|
|
4115
|
+
* @param samples - Output from {@link runBenchmark}.
|
|
4116
|
+
* @param startedAt - ISO start time for the run.
|
|
4117
|
+
* @param finishedAt - ISO end time for the run.
|
|
4118
|
+
* @returns {@link BenchmarkReport} suitable for JSON export.
|
|
4119
|
+
*/
|
|
2249
4120
|
declare function summarizeBenchmark(samples: BenchmarkSample[], startedAt: string, finishedAt: string): BenchmarkReport;
|
|
2250
4121
|
|
|
2251
|
-
export { type BenchmarkReport, type BenchmarkSample, type ChatMessage, type CheckpointInfo, type CheckpointMeta, type CheckpointOptions, type CheckpointProvider, type Chunk, type ChunkingOptions, type ChunkingStrategy, type ClearOptions, type CompressOptions, type CompressResult, CompressionError, type CompressionProvider, type ConcurrencyConfig$1 as ConcurrencyConfig, ConfigurationError, type ConversationMessage, type CreateCheckpointOptions, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingCacheConfig, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, type EventDatabase, type ExportResult, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, type GetRelatedOptions, GraphCheckpointNotSupportedError, type GraphConfig, type GraphDirection, type GraphEntityInput, type GraphHealthResult, type GraphInput$1 as GraphInput, type GraphProvider, HeadingChunkingStrategy, type HistoryEvent, type HistoryOptions, type HistoryResult, type HybridConfig, type ImportResult, type IngestOptions, type IngestResult, type InitOptions, InitializationError, type KeywordDocument, type KeywordSearchHit, type KeywordSearchProvider, type LatencyBreakdown, LlmCompressionProvider, type LlmConfig, type LlmProvider, MarkdownChunkingStrategy, type MemoryChangeCallback, type MemoryChangeEvent, type MemoryContent, type MemoryDedupeConfig, type MemoryDedupeStrategy, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryProvider, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, Neo4jGraphProvider, NoopTelemetryProvider, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PersistedRecallExplainPayload, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallExplainResponse, type RecallExplanationHit, type RecallOptions, type RecallResult, type RememberAction, type RememberFromMessagesOptions, type RememberFromMessagesRawStrategy, type RememberOptions, type RememberResult, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SDK_VERSION, SentenceChunkingStrategy, SqliteCheckpointProvider, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteEventDatabase, SqliteGraphProvider, SqliteStorageProvider, SqliteTelemetryProvider, type StageSpan, type StatsResult, type StorageConfig, StorageLockedError, type StorageProvider, type StorageProviderName, type SubscribableEvent, type SubscribeFilter, type TelemetryConfig, TelemetryEmitter, type TelemetryEvent, type TelemetryEventInput, type TelemetryLogLevel, type TelemetryOperation, type TelemetryProvider, type TelemetryQuery, type TelemetryQueryResult, type TelemetryStatus, type Unsubscribe, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, WolbargLogger, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, createTelemetryProvider,
|
|
4122
|
+
export { type BenchmarkReport, type BenchmarkSample, type ChatMessage, type CheckpointInfo, type CheckpointMeta, type CheckpointOptions, type CheckpointProvider, type Chunk, type ChunkingOptions, type ChunkingStrategy, type ClearOptions, type CompressOptions, type CompressResult, CompressionError, type CompressionProvider, type ConcurrencyConfig$1 as ConcurrencyConfig, ConfigurationError, type ConversationMessage, type CreateCheckpointOptions, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingCacheConfig, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, type EventDatabase, type ExportResult, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, type GetRelatedOptions, GraphCheckpointNotSupportedError, type GraphConfig, type GraphDirection, type GraphEntityInput, type GraphHealthResult, type GraphInput$1 as GraphInput, type GraphProvider, HeadingChunkingStrategy, type HistoryEvent, type HistoryOptions, type HistoryResult, type HybridConfig, type ImportResult, type IngestOptions, type IngestResult, type InitOptions, InitializationError, type KeywordDocument, type KeywordSearchHit, type KeywordSearchProvider, type LatencyBreakdown, LlmCompressionProvider, type LlmConfig, type LlmProvider, MarkdownChunkingStrategy, type MemoryChangeCallback, type MemoryChangeEvent, type MemoryContent, type MemoryDedupeConfig, type MemoryDedupeStrategy, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryProvider, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, Neo4jGraphProvider, NoopTelemetryProvider, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PersistedRecallExplainPayload, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallExplainResponse, type RecallExplanationHit, type RecallOptions, type RecallResult, type RememberAction, type RememberFromMessagesOptions, type RememberFromMessagesRawStrategy, type RememberOptions, type RememberResult, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SDK_VERSION, SentenceChunkingStrategy, SqliteCheckpointProvider, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteEventDatabase, SqliteGraphProvider, SqliteStorageProvider, SqliteTelemetryProvider, type StageSpan, type StatsResult, type StorageConfig, StorageLockedError, type StorageProvider, type StorageProviderName, type SubscribableEvent, type SubscribeFilter, type TelemetryConfig, TelemetryEmitter, type TelemetryEvent, type TelemetryEventInput, type TelemetryLogLevel, type TelemetryOperation, type TelemetryProvider, type TelemetryQuery, type TelemetryQueryResult, type TelemetryStatus, type Unsubscribe, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, WolbargLogger, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, createTelemetryProvider, createWolbarg, crossEncoder, geminiEmbedding, geminiVision, jinaReranker, lmStudioEmbedding, meta, neo4jGraph, ollamaEmbedding, ollamaLlm, openRouterEmbedding, openRouterLlm, openaiCompatibleEmbedding, openaiCompatibleLlm, openaiEmbedding, openaiLlm, openaiReranker, openaiVision, postgres, postgresConfig, runBenchmark, sqlite, sqliteCheckpoint, sqliteConfig, sqliteGraph, sqliteTelemetry, summarizeBenchmark, tesseract, togetherEmbedding, vllmEmbedding, wolbarg$1 as wolbarg, wrapOperationError };
|