wolbarg 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -43,7 +43,155 @@ declare const meta: {
43
43
  };
44
44
 
45
45
  /**
46
- * Public configuration and domain types for Wolbarg v0.2.
46
+ * Telemetry event types, latency breakdown, and query shapes.
47
+ * Schema is intentionally extensible for future providers (Postgres, cloud).
48
+ */
49
+ /** Public operation names recorded as telemetry events. */
50
+ type TelemetryOperation = "remember" | "recall" | "forget" | "compress" | "rememberBatch" | "recallBatch" | "export" | "import" | "checkpoint" | "rollback" | "error" | "startup" | "shutdown" | "ingest" | "history" | "stats" | "clear" | "deleteCheckpoint" | "listCheckpoints" | "getCheckpoint";
51
+ type TelemetryStatus = "ok" | "error" | "cancelled";
52
+ type TelemetryLogLevel = "off" | "error" | "warn" | "info" | "debug" | "trace";
53
+ /** Stage-level latency breakdown recorded on each event. */
54
+ interface LatencyBreakdown {
55
+ embeddingMs?: number;
56
+ vectorSearchMs?: number;
57
+ metadataFilteringMs?: number;
58
+ rankingMs?: number;
59
+ serializationMs?: number;
60
+ databaseWriteMs?: number;
61
+ databaseReadMs?: number;
62
+ totalMs: number;
63
+ }
64
+ /** A measured stage within an operation, relative to the operation start. */
65
+ interface StageSpan {
66
+ name: keyof Omit<LatencyBreakdown, "totalMs"> | (string & {});
67
+ startMs: number;
68
+ durationMs: number;
69
+ }
70
+ /** Compact, JSON-safe recall explanation persisted with telemetry events. */
71
+ interface PersistedRecallExplainPayload {
72
+ enabled: true;
73
+ providerUsed: string;
74
+ rankingStrategy: string;
75
+ signals: {
76
+ semantic: "enabled";
77
+ keyword: "enabled" | "disabled" | "unknown";
78
+ reranker: "enabled" | "disabled" | "unknown";
79
+ mmr: "enabled" | "disabled";
80
+ recency: "disabled" | "unknown";
81
+ };
82
+ results: Array<{
83
+ memoryId: string;
84
+ score: number;
85
+ distance: number;
86
+ rankingReason: string;
87
+ matchedFields: string[];
88
+ metadataMatch: boolean;
89
+ }>;
90
+ searchTimeMs: number;
91
+ rankingTimeMs: number;
92
+ totalTimeMs: number;
93
+ }
94
+ /** Input accepted by TelemetryProvider.emit (id / timestamp may be filled). */
95
+ interface TelemetryEventInput {
96
+ id?: string;
97
+ timestamp?: string;
98
+ operation: TelemetryOperation;
99
+ provider?: string | null;
100
+ durationMs?: number | null;
101
+ status: TelemetryStatus;
102
+ query?: string | null;
103
+ filters?: unknown;
104
+ returnedCount?: number | null;
105
+ memoryIds?: string[] | null;
106
+ similarityScores?: number[] | null;
107
+ metadata?: Record<string, unknown> | null;
108
+ embeddingProvider?: string | null;
109
+ model?: string | null;
110
+ error?: string | null;
111
+ errorStack?: string | null;
112
+ sessionId: string;
113
+ traceId: string;
114
+ parentTraceId?: string | null;
115
+ organization?: string | null;
116
+ agentId?: string | null;
117
+ tags?: string[] | null;
118
+ checkpointId?: string | null;
119
+ userMetadata?: Record<string, unknown> | null;
120
+ extra?: Record<string, unknown> | null;
121
+ latency?: LatencyBreakdown | null;
122
+ explain?: PersistedRecallExplainPayload | null;
123
+ spans?: StageSpan[] | null;
124
+ }
125
+ /** Fully persisted telemetry event row. */
126
+ interface TelemetryEvent extends Required<Pick<TelemetryEventInput, "id" | "timestamp" | "operation" | "status" | "sessionId" | "traceId">> {
127
+ provider: string | null;
128
+ durationMs: number | null;
129
+ query: string | null;
130
+ filters: unknown;
131
+ returnedCount: number | null;
132
+ memoryIds: string[] | null;
133
+ similarityScores: number[] | null;
134
+ metadata: Record<string, unknown> | null;
135
+ embeddingProvider: string | null;
136
+ model: string | null;
137
+ error: string | null;
138
+ errorStack: string | null;
139
+ parentTraceId: string | null;
140
+ organization: string | null;
141
+ agentId: string | null;
142
+ tags: string[] | null;
143
+ checkpointId: string | null;
144
+ userMetadata: Record<string, unknown> | null;
145
+ extra: Record<string, unknown> | null;
146
+ latency: LatencyBreakdown | null;
147
+ explain: PersistedRecallExplainPayload | null;
148
+ spans: StageSpan[] | null;
149
+ }
150
+ interface TelemetryQuery {
151
+ operation?: TelemetryOperation | TelemetryOperation[];
152
+ status?: TelemetryStatus;
153
+ traceId?: string;
154
+ sessionId?: string;
155
+ organization?: string;
156
+ agentId?: string;
157
+ tag?: string;
158
+ checkpointId?: string;
159
+ memoryId?: string;
160
+ queryText?: string;
161
+ since?: string;
162
+ until?: string;
163
+ limit?: number;
164
+ offset?: number;
165
+ sortBy?: "timestamp" | "duration_ms";
166
+ sortDir?: "asc" | "desc";
167
+ }
168
+ interface TelemetryQueryResult {
169
+ events: TelemetryEvent[];
170
+ total: number;
171
+ limit: number;
172
+ offset: number;
173
+ }
174
+ /** Database config for the independent telemetry EventDatabase. */
175
+ interface TelemetryDatabaseConfig {
176
+ provider: "sqlite" | "postgres";
177
+ /** Preferred v0.3 field. */
178
+ url?: string;
179
+ /** Back-compat alias for url. */
180
+ connectionString?: string;
181
+ }
182
+ interface TelemetryConfig {
183
+ enabled?: boolean;
184
+ database: TelemetryDatabaseConfig;
185
+ level?: TelemetryLogLevel;
186
+ captureQueries?: boolean;
187
+ captureLatency?: boolean;
188
+ captureErrors?: boolean;
189
+ captureSimilarity?: boolean;
190
+ captureEmbeddings?: boolean;
191
+ }
192
+
193
+ /**
194
+ * Public configuration and domain types for Wolbarg v0.3.
47
195
  */
48
196
 
49
197
  /** Opaque, user-defined metadata. Never validated or modified by the SDK. */
@@ -63,14 +211,19 @@ interface SqliteDatabaseConfig {
63
211
  /**
64
212
  * Path to the SQLite database file, or `:memory:` for an in-memory database.
65
213
  * Relative paths are resolved from `process.cwd()`.
214
+ * Prefer `url` in v0.3; `connectionString` remains supported.
66
215
  */
67
- connectionString: string;
216
+ connectionString?: string;
217
+ /** v0.3 preferred alias for the SQLite path / connection. */
218
+ url?: string;
68
219
  }
69
220
  /** PostgreSQL database configuration. */
70
221
  interface PostgresDatabaseConfig {
71
222
  provider: "postgres";
72
223
  /** Postgres connection string (e.g. `postgres://user:pass@host:5432/db`). */
73
- connectionString: string;
224
+ connectionString?: string;
225
+ /** v0.3 preferred alias for the Postgres connection string. */
226
+ url?: string;
74
227
  /** Optional max pool size. Defaults to 10. */
75
228
  maxPoolSize?: number;
76
229
  }
@@ -78,6 +231,7 @@ interface PostgresDatabaseConfig {
78
231
  type DatabaseConfig = SqliteDatabaseConfig | PostgresDatabaseConfig;
79
232
  /** Alias used by the constructor-based API. */
80
233
  type StorageConfig = DatabaseConfig;
234
+
81
235
  /**
82
236
  * OpenAI-compatible embedding endpoint configuration.
83
237
  * Works with OpenAI, Ollama, LM Studio, OpenRouter, Azure OpenAI, Gemini, etc.
@@ -194,6 +348,10 @@ interface RecallOptions {
194
348
  * Falls back to semantic-only when keyword search is not configured.
195
349
  */
196
350
  hybrid?: boolean | HybridConfig;
351
+ /**
352
+ * When `true`, return enriched explain results instead of plain RecallResult[].
353
+ */
354
+ explain?: boolean;
197
355
  }
198
356
  /** A single recalled memory with similarity score. */
199
357
  interface RecallResult {
@@ -207,6 +365,53 @@ interface RecallResult {
207
365
  createdAt: Date;
208
366
  updatedAt: Date;
209
367
  }
368
+ /** Enriched recall hit when `explain: true`. */
369
+ interface RecallExplanationHit {
370
+ memory: RecallResult;
371
+ score: number;
372
+ distance: number;
373
+ rankingReason: string;
374
+ matchedFields: string[];
375
+ metadataMatch: boolean;
376
+ providerUsed: string;
377
+ searchTime: number;
378
+ rankingTime: number;
379
+ }
380
+ /** Full explain-mode response. */
381
+ interface RecallExplainResponse {
382
+ results: RecallExplanationHit[];
383
+ providerUsed: string;
384
+ searchTime: number;
385
+ rankingTime: number;
386
+ totalTime: number;
387
+ traceId: string;
388
+ }
389
+ /** Options for creating a named checkpoint. */
390
+ interface CheckpointOptions {
391
+ description?: string;
392
+ }
393
+ /** Checkpoint metadata returned by checkpoint APIs. */
394
+ interface CheckpointInfo {
395
+ name: string;
396
+ description: string | null;
397
+ createdAt: string;
398
+ sdkVersion: string;
399
+ provider: string;
400
+ snapshotPath: string;
401
+ sourcePath: string;
402
+ sizeBytes: number;
403
+ }
404
+ /** Result of export(). */
405
+ interface ExportResult {
406
+ path: string;
407
+ sizeBytes: number;
408
+ exportedAt: string;
409
+ }
410
+ /** Result of import(). */
411
+ interface ImportResult {
412
+ path: string;
413
+ importedAt: string;
414
+ }
210
415
  /** Persisted memory record (without embedding vector). */
211
416
  interface MemoryRecord {
212
417
  id: string;
@@ -692,6 +897,67 @@ interface StorageProvider {
692
897
  /** Back-compat alias. */
693
898
  type DatabaseProvider = StorageProvider;
694
899
 
900
+ /**
901
+ * Database-agnostic checkpoint contract.
902
+ * Snapshots memory state so callers can rollback without third-party libs.
903
+ */
904
+ interface CheckpointMeta {
905
+ name: string;
906
+ description: string | null;
907
+ createdAt: string;
908
+ sdkVersion: string;
909
+ provider: string;
910
+ /** Absolute path or URI of the snapshot artifact. */
911
+ snapshotPath: string;
912
+ /** Absolute path or URI of the source memory database at creation time. */
913
+ sourcePath: string;
914
+ sizeBytes: number;
915
+ }
916
+ interface CreateCheckpointOptions {
917
+ description?: string;
918
+ }
919
+ interface CheckpointProvider {
920
+ readonly name: string;
921
+ /** Prepare checkpoint storage (directories / tables). */
922
+ open(): Promise<void>;
923
+ close(): Promise<void>;
924
+ /**
925
+ * Create a named snapshot of the current memory database.
926
+ * Must fail if the name already exists (never overwrite).
927
+ */
928
+ checkpoint(name: string, sourcePath: string, options?: CreateCheckpointOptions): Promise<CheckpointMeta>;
929
+ /** Restore the memory database from a named checkpoint. */
930
+ rollback(name: string, targetPath: string): Promise<CheckpointMeta>;
931
+ /** Permanently remove a checkpoint and its snapshot files. */
932
+ deleteCheckpoint(name: string): Promise<boolean>;
933
+ listCheckpoints(): Promise<CheckpointMeta[]>;
934
+ getCheckpoint(name: string): Promise<CheckpointMeta | null>;
935
+ }
936
+
937
+ /**
938
+ * Database-agnostic telemetry persistence contract.
939
+ * Telemetry MUST use a separate database from memory storage.
940
+ */
941
+
942
+ interface TelemetryProvider {
943
+ readonly name: string;
944
+ /** Open the independent event database connection. */
945
+ open(): Promise<void>;
946
+ /** Close the event database connection. Flush pending writes first. */
947
+ close(): Promise<void>;
948
+ /**
949
+ * Persist a telemetry event. Must not block callers of memory operations.
950
+ * Implementations may queue and flush asynchronously.
951
+ */
952
+ emit(event: TelemetryEventInput): void;
953
+ /** Wait until the write queue is empty (used by tests / shutdown). */
954
+ flush(): Promise<void>;
955
+ /** Read events (primarily for Studio / debugging). Optional for write-only backends. */
956
+ query?(options: TelemetryQuery): Promise<TelemetryQueryResult>;
957
+ /** Fetch a single event by id. */
958
+ getEvent?(id: string): Promise<TelemetryEvent | null>;
959
+ }
960
+
695
961
  /**
696
962
  * Optional vision provider — captions / descriptions / entities from images.
697
963
  */
@@ -718,19 +984,32 @@ declare function openaiVision(options: {
718
984
  }): VisionProvider;
719
985
 
720
986
  /**
721
- * Constructor options for Wolbarg v0.2.
987
+ * Constructor options for Wolbarg v0.3.
722
988
  */
723
989
 
724
990
  type EmbeddingInput = EmbeddingProvider | EmbeddingConfig;
725
991
  type LlmInput = LlmProvider | LlmConfig;
726
- type StorageInput = StorageProvider | StorageConfig;
992
+ type StorageInput = StorageProvider | StorageConfig | DatabaseConfig;
727
993
  interface WolbargOptionsBase {
728
994
  /** Organization namespace isolating memories within a shared database. */
729
995
  organization: string;
730
- /** Storage provider instance or config. */
731
- storage: StorageInput;
996
+ /**
997
+ * Storage provider instance or config.
998
+ * Prefer `database` in v0.3 docs; `storage` remains fully supported.
999
+ */
1000
+ storage?: StorageInput;
1001
+ /**
1002
+ * v0.3 alias for `storage`. Accepts `{ provider, url }` or `{ provider, connectionString }`.
1003
+ */
1004
+ database?: StorageInput;
732
1005
  /** Embedding provider instance or config. */
733
1006
  embedding: EmbeddingInput;
1007
+ /** Optional independent telemetry system (separate database). */
1008
+ telemetry?: TelemetryConfig | TelemetryProvider;
1009
+ /** Optional checkpoint provider override (defaults to SQLite when file-backed). */
1010
+ checkpoint?: CheckpointProvider;
1011
+ /** Optional directory for SQLite checkpoints. */
1012
+ checkpointDirectory?: string;
734
1013
  /** Optional reranker — skipped when absent. */
735
1014
  reranker?: RerankerProvider;
736
1015
  /** Optional keyword search — enables hybrid recall when present. */
@@ -756,23 +1035,24 @@ interface WolbargOptionsWithLlm extends WolbargOptionsBase {
756
1035
  type WolbargOptions = WolbargOptionsWithoutLlm | WolbargOptionsWithLlm;
757
1036
 
758
1037
  /**
759
- * Wolbarg — modular semantic memory SDK for AI agents (v0.2).
1038
+ * Wolbarg — modular semantic memory SDK for AI agents (v0.3).
760
1039
  *
761
1040
  * @example
762
1041
  * ```ts
763
- * import { Wolbarg, sqlite, openaiEmbedding, openaiLlm } from "wolbarg";
1042
+ * import { wolbarg, openaiEmbedding, openaiLlm } from "wolbarg";
764
1043
  *
765
- * const ctx = new Wolbarg({
1044
+ * const ctx = wolbarg({
766
1045
  * organization: "my-org",
767
- * storage: sqlite("./memory.db"),
1046
+ * database: { provider: "sqlite", url: "./memory.db" },
768
1047
  * embedding: openaiEmbedding({
769
1048
  * apiKey: process.env.OPENAI_API_KEY!,
770
1049
  * model: "text-embedding-3-small",
771
1050
  * }),
772
- * llm: openaiLlm({
773
- * apiKey: process.env.OPENAI_API_KEY!,
774
- * model: "gpt-4.1-mini",
775
- * }),
1051
+ * telemetry: {
1052
+ * enabled: true,
1053
+ * database: { provider: "sqlite", url: "./telemetry.db" },
1054
+ * level: "debug",
1055
+ * },
776
1056
  * });
777
1057
  *
778
1058
  * await ctx.ready();
@@ -782,7 +1062,6 @@ type WolbargOptions = WolbargOptionsWithoutLlm | WolbargOptionsWithLlm;
782
1062
  */
783
1063
 
784
1064
  declare class Wolbarg<HasLlm extends boolean = false> {
785
- /** Compile-time capability flag — `true` when constructed with `llm`. */
786
1065
  readonly __hasLlm: HasLlm;
787
1066
  private initialized;
788
1067
  private booting;
@@ -799,106 +1078,151 @@ declare class Wolbarg<HasLlm extends boolean = false> {
799
1078
  private retrievalConfig;
800
1079
  private embeddingDimensions;
801
1080
  private readonly writeMutex;
802
- /**
803
- * Create an Wolbarg instance.
804
- * When options are provided, providers are wired immediately and
805
- * storage opens lazily on the first API call (or {@link ready}).
806
- *
807
- * Pass `llm` to enable {@link compress} (typed at compile time).
808
- */
1081
+ private telemetry;
1082
+ private checkpointProvider;
1083
+ private memoryDbPath;
1084
+ private readonly transfer;
809
1085
  constructor(options: WolbargOptionsWithLlm);
810
1086
  constructor(options: WolbargOptionsWithoutLlm);
811
1087
  constructor();
812
1088
  /**
813
1089
  * Backwards-compatible initialization (v0.1 API).
814
- * Prefer the constructor with `storage` / `embedding` / optional `llm`.
815
1090
  */
816
1091
  init(options: InitOptions): Promise<void>;
817
- /** Ensure storage is open and embedding dimensions are known. */
1092
+ /** Ensure storage (and optional telemetry) are open. */
818
1093
  ready(): Promise<void>;
819
1094
  private boot;
820
1095
  /** Store a semantic memory for an agent. */
821
1096
  remember(options: RememberOptions): Promise<MemoryRecord>;
1097
+ /** Batch remember — one parent event + child traces per item. */
1098
+ rememberBatch(items: RememberOptions[]): Promise<MemoryRecord[]>;
822
1099
  /**
823
1100
  * Semantic / hybrid search over stored memories.
824
- * Optional keyword, metadata, MMR, and rerank stages degrade gracefully.
825
- */
826
- recall(options: RecallOptions): Promise<RecallResult[]>;
827
- /**
828
- * Compress related memories for an agent into a single summarized memory.
829
- * Only available when `llm` (or `compression`) was configured at construction.
1101
+ * Pass `{ explain: true }` for enriched ranking diagnostics.
830
1102
  */
1103
+ recall(options: RecallOptions & {
1104
+ explain: true;
1105
+ }): Promise<RecallExplainResponse>;
1106
+ recall(options: RecallOptions & {
1107
+ explain?: false;
1108
+ }): Promise<RecallResult[]>;
1109
+ recall(options: RecallOptions): Promise<RecallResult[] | RecallExplainResponse>;
1110
+ /** Batch recall — parent event + child traces. */
1111
+ recallBatch(queries: Array<Omit<RecallOptions, "explain">>): Promise<RecallResult[][]>;
831
1112
  compress(this: Wolbarg<true>, options: CompressOptions): Promise<CompressResult>;
832
1113
  /** @internal */
833
1114
  private runCompress;
834
- /** Ingest a document: parse → OCR/vision (optional) → chunk → embed → store. */
835
1115
  ingest(options: IngestOptions): Promise<IngestResult>;
836
- /** Delete memories by ID or filter. */
837
1116
  forget(options: ForgetOptions): Promise<number>;
838
- /** Return the history of a memory. */
839
1117
  history(options: HistoryOptions): Promise<HistoryResult>;
840
- /** Aggregate statistics for the current organization. */
841
1118
  stats(): Promise<StatsResult>;
842
- /** Delete every memory in the current organization. */
843
1119
  clear(options: ClearOptions): Promise<number>;
844
- /**
845
- * Serialize writes for SQLite (single connection). Postgres uses a pool and
846
- * per-statement atomic CTEs locking here only serializes throughput.
847
- */
1120
+ /** Create an immutable named checkpoint of the memory database. */
1121
+ checkpoint(name: string, options?: CheckpointOptions): Promise<CheckpointInfo>;
1122
+ /** Restore the memory database from a named checkpoint. */
1123
+ rollback(name: string): Promise<CheckpointInfo>;
1124
+ deleteCheckpoint(name: string): Promise<boolean>;
1125
+ listCheckpoints(): Promise<CheckpointInfo[]>;
1126
+ getCheckpoint(name: string): Promise<CheckpointInfo | null>;
1127
+ /** Export the memory database to a portable SQLite + manifest bundle. */
1128
+ export(exportPath: string): Promise<ExportResult>;
1129
+ /** Import a previously exported memory database, replacing the current file. */
1130
+ import(exportPath: string): Promise<ImportResult>;
1131
+ /** Flush pending telemetry (useful in tests). */
1132
+ flushTelemetry(): Promise<void>;
1133
+ /** Session id for this SDK instance (telemetry traces). */
1134
+ get sessionId(): string;
848
1135
  private withWriteLock;
849
- /** Close the database connection and release resources. */
850
1136
  close(): Promise<void>;
851
- /** Whether providers are ready for API calls. */
852
1137
  get isInitialized(): boolean;
853
1138
  private requireReady;
854
1139
  private assertEmbeddingDimensions;
1140
+ private requireCheckpointProvider;
1141
+ private requireMemoryDbPath;
855
1142
  }
1143
+ /** Preferred v0.3 entry — re-exported from factories as well. */
1144
+ declare function wolbarg$1(options: WolbargOptions): Wolbarg;
856
1145
 
857
1146
  /**
858
- * Custom error hierarchy for Wolbarg.
859
- * Raw SQLite / network errors are never exposed to consumers.
1147
+ * Operation-scoped errors with reason + suggestion for developer experience.
860
1148
  */
861
1149
  /** Base class for all Wolbarg errors. */
862
1150
  declare class WolbargError extends Error {
863
1151
  readonly code: string;
864
- constructor(message: string, code: string, options?: ErrorOptions);
1152
+ readonly reason?: string;
1153
+ readonly suggestion?: string;
1154
+ readonly operation?: string;
1155
+ constructor(message: string, code: string, options?: ErrorOptions & {
1156
+ reason?: string;
1157
+ suggestion?: string;
1158
+ operation?: string;
1159
+ });
865
1160
  }
866
1161
  /** Thrown when SDK initialization fails. */
867
1162
  declare class InitializationError extends WolbargError {
868
- constructor(message: string, options?: ErrorOptions);
1163
+ constructor(message: string, options?: ErrorOptions & {
1164
+ reason?: string;
1165
+ suggestion?: string;
1166
+ operation?: string;
1167
+ });
869
1168
  }
870
1169
  /** Thrown when configuration values are missing or invalid. */
871
1170
  declare class ConfigurationError extends WolbargError {
872
- constructor(message: string, options?: ErrorOptions);
1171
+ constructor(message: string, options?: ErrorOptions & {
1172
+ reason?: string;
1173
+ suggestion?: string;
1174
+ operation?: string;
1175
+ });
873
1176
  }
874
1177
  /** Thrown when method arguments fail validation. */
875
1178
  declare class ValidationError extends WolbargError {
876
- constructor(message: string, options?: ErrorOptions);
1179
+ constructor(message: string, options?: ErrorOptions & {
1180
+ reason?: string;
1181
+ suggestion?: string;
1182
+ operation?: string;
1183
+ });
877
1184
  }
878
1185
  /** Thrown when a database operation fails. */
879
1186
  declare class DatabaseError extends WolbargError {
880
- constructor(message: string, options?: ErrorOptions);
1187
+ constructor(message: string, options?: ErrorOptions & {
1188
+ reason?: string;
1189
+ suggestion?: string;
1190
+ operation?: string;
1191
+ });
881
1192
  }
882
1193
  /** Thrown when an embedding request fails. */
883
1194
  declare class EmbeddingError extends WolbargError {
884
- constructor(message: string, options?: ErrorOptions);
1195
+ constructor(message: string, options?: ErrorOptions & {
1196
+ reason?: string;
1197
+ suggestion?: string;
1198
+ operation?: string;
1199
+ });
885
1200
  }
886
1201
  /** Thrown when compression (LLM summarization) fails. */
887
1202
  declare class CompressionError extends WolbargError {
888
- constructor(message: string, options?: ErrorOptions);
1203
+ constructor(message: string, options?: ErrorOptions & {
1204
+ reason?: string;
1205
+ suggestion?: string;
1206
+ operation?: string;
1207
+ });
889
1208
  }
890
1209
  /** Thrown when a requested memory does not exist. */
891
1210
  declare class MemoryNotFoundError extends WolbargError {
892
- constructor(message: string, options?: ErrorOptions);
1211
+ constructor(message: string, options?: ErrorOptions & {
1212
+ reason?: string;
1213
+ suggestion?: string;
1214
+ operation?: string;
1215
+ });
893
1216
  }
894
1217
  /**
895
1218
  * Thrown when a method requires an optional provider that was not configured.
896
- * Prefer TypeScript narrowing (e.g. compress without llm) when possible.
897
1219
  */
898
1220
  declare class ProviderNotConfiguredError extends ConfigurationError {
899
1221
  readonly provider: string;
900
1222
  constructor(provider: string, method: string, hint: string);
901
1223
  }
1224
+ /** Map low-level SQLite / driver errors into actionable operation errors. */
1225
+ declare function wrapOperationError(operation: string, error: unknown): WolbargError;
902
1226
 
903
1227
  /**
904
1228
  * Public factory helpers for storage / providers.
@@ -917,6 +1241,16 @@ declare function postgres(options: string | {
917
1241
  declare function postgresConfig(connectionString: string, options?: {
918
1242
  maxPoolSize?: number;
919
1243
  }): PostgresDatabaseConfig;
1244
+ /** Create a SQLite telemetry provider for an independent event database. */
1245
+ declare function sqliteTelemetry(url: string): TelemetryProvider;
1246
+ /** Create a SQLite checkpoint provider. */
1247
+ declare function sqliteCheckpoint(directory?: string): CheckpointProvider;
1248
+ /** Create a telemetry provider from config (SQLite only in v0.3). */
1249
+ declare function createTelemetryProvider(config: TelemetryConfig): TelemetryProvider;
1250
+ /**
1251
+ * Preferred v0.3 factory. Equivalent to `new Wolbarg(options)`.
1252
+ */
1253
+ declare function wolbarg(options: WolbargOptions): Wolbarg;
920
1254
 
921
1255
  /**
922
1256
  * SQLite + sqlite-vec database provider (Node.js built-in `node:sqlite`).
@@ -947,6 +1281,8 @@ declare class SqliteStorageProvider implements StorageProvider {
947
1281
  /** Resolved absolute path (or `:memory:`) — avoid re-resolving on size checks. */
948
1282
  private resolvedPath;
949
1283
  constructor(options: SqliteProviderOptions);
1284
+ /** Absolute or relative path / `:memory:` used by this provider. */
1285
+ get path(): string;
950
1286
  open(): Promise<void>;
951
1287
  close(): Promise<void>;
952
1288
  ensureVectorSchema(dimensions: number): Promise<void>;
@@ -1146,4 +1482,212 @@ declare function createStorageProvider(config: StorageConfig | DatabaseConfig):
1146
1482
  /** @deprecated Prefer {@link createStorageProvider}. */
1147
1483
  declare function createDatabaseProvider(config: DatabaseConfig): StorageProvider;
1148
1484
 
1149
- export { type ChatMessage, type Chunk, type ChunkingOptions, type ChunkingStrategy, type ClearOptions, type CompressOptions, type CompressResult, CompressionError, type CompressionProvider, ConfigurationError, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, HeadingChunkingStrategy, type HistoryEvent, type HistoryOptions, type HistoryResult, type HybridConfig, type IngestOptions, type IngestResult, type InitOptions, InitializationError, type KeywordDocument, type KeywordSearchHit, type KeywordSearchProvider, LlmCompressionProvider, type LlmConfig, type LlmProvider, MarkdownChunkingStrategy, type MemoryContent, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallOptions, type RecallResult, type RememberOptions, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SentenceChunkingStrategy, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteStorageProvider, type StatsResult, type StorageConfig, type StorageProvider, type StorageProviderName, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, crossEncoder, geminiEmbedding, geminiVision, jinaReranker, lmStudioEmbedding, meta, ollamaEmbedding, ollamaLlm, openRouterEmbedding, openRouterLlm, openaiCompatibleEmbedding, openaiCompatibleLlm, openaiEmbedding, openaiLlm, openaiReranker, openaiVision, postgres, postgresConfig, sqlite, sqliteConfig, tesseract, togetherEmbedding, vllmEmbedding };
1485
+ /**
1486
+ * Database-agnostic memory persistence contract.
1487
+ * Alias of StorageProvider for the v0.3 provider architecture.
1488
+ */
1489
+
1490
+ /** Memory / vector storage provider. Implementations: SQLite, PostgreSQL. */
1491
+ type MemoryProvider = StorageProvider;
1492
+
1493
+ /**
1494
+ * Internal event persistence contract.
1495
+ * Distinct from MemoryDatabase / StorageProvider — telemetry never shares tables.
1496
+ */
1497
+
1498
+ interface EventDatabase {
1499
+ readonly name: string;
1500
+ open(): Promise<void>;
1501
+ close(): Promise<void>;
1502
+ /** Insert one event row. */
1503
+ insertEvent(event: TelemetryEventInput): Promise<TelemetryEvent>;
1504
+ /** Insert many events in one batch (optional optimization). */
1505
+ insertEvents?(events: TelemetryEventInput[]): Promise<TelemetryEvent[]>;
1506
+ query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
1507
+ getEvent(id: string): Promise<TelemetryEvent | null>;
1508
+ /** Aggregate helpers used by Studio backends. */
1509
+ countEvents?(filter?: {
1510
+ since?: string;
1511
+ operation?: string;
1512
+ }): Promise<number>;
1513
+ }
1514
+
1515
+ /**
1516
+ * SQLite EventDatabase — completely separate from the memory database.
1517
+ */
1518
+
1519
+ interface SqliteEventDatabaseOptions {
1520
+ url: string;
1521
+ /** When true, open read-only (Studio). */
1522
+ readonly?: boolean;
1523
+ }
1524
+ declare class SqliteEventDatabase implements EventDatabase {
1525
+ readonly name = "sqlite";
1526
+ private readonly url;
1527
+ private readonly readonly;
1528
+ private db;
1529
+ private insertStmt;
1530
+ private columns;
1531
+ constructor(options: SqliteEventDatabaseOptions);
1532
+ open(): Promise<void>;
1533
+ close(): Promise<void>;
1534
+ insertEvent(input: TelemetryEventInput): Promise<TelemetryEvent>;
1535
+ insertEvents(inputs: TelemetryEventInput[]): Promise<TelemetryEvent[]>;
1536
+ query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
1537
+ getEvent(id: string): Promise<TelemetryEvent | null>;
1538
+ countEvents(filter?: {
1539
+ since?: string;
1540
+ operation?: string;
1541
+ }): Promise<number>;
1542
+ private requireDb;
1543
+ private migrateToV2;
1544
+ private addOptionalColumnFilter;
1545
+ private resolvePath;
1546
+ }
1547
+
1548
+ /**
1549
+ * SQLite TelemetryProvider backed by an independent EventDatabase.
1550
+ * Writes are queued and flushed asynchronously so memory ops stay fast.
1551
+ */
1552
+
1553
+ interface SqliteTelemetryProviderOptions {
1554
+ url: string;
1555
+ }
1556
+ declare class SqliteTelemetryProvider implements TelemetryProvider {
1557
+ readonly name = "sqlite";
1558
+ private readonly db;
1559
+ private queue;
1560
+ private flushing;
1561
+ private closed;
1562
+ private openPromise;
1563
+ constructor(options: SqliteTelemetryProviderOptions);
1564
+ open(): Promise<void>;
1565
+ close(): Promise<void>;
1566
+ emit(event: TelemetryEventInput): void;
1567
+ flush(): Promise<void>;
1568
+ query(options: TelemetryQuery): Promise<TelemetryQueryResult>;
1569
+ getEvent(id: string): Promise<TelemetryEvent | null>;
1570
+ private scheduleFlush;
1571
+ private runFlush;
1572
+ }
1573
+
1574
+ /**
1575
+ * First-party SQLite checkpoint provider.
1576
+ * Creates immutable named snapshots of the memory database.
1577
+ */
1578
+
1579
+ interface SqliteCheckpointProviderOptions {
1580
+ /** Directory that stores checkpoint snapshots + metadata. */
1581
+ directory?: string;
1582
+ }
1583
+ declare class SqliteCheckpointProvider implements CheckpointProvider {
1584
+ readonly name = "sqlite";
1585
+ private readonly directory;
1586
+ private ready;
1587
+ constructor(options?: SqliteCheckpointProviderOptions);
1588
+ open(): Promise<void>;
1589
+ close(): Promise<void>;
1590
+ checkpoint(name: string, sourcePath: string, options?: CreateCheckpointOptions): Promise<CheckpointMeta>;
1591
+ rollback(name: string, targetPath: string): Promise<CheckpointMeta>;
1592
+ deleteCheckpoint(name: string): Promise<boolean>;
1593
+ listCheckpoints(): Promise<CheckpointMeta[]>;
1594
+ getCheckpoint(name: string): Promise<CheckpointMeta | null>;
1595
+ private metaPath;
1596
+ private snapshotPath;
1597
+ private requireReady;
1598
+ }
1599
+
1600
+ /**
1601
+ * Cross-platform structured logger gated by TelemetryLogLevel.
1602
+ */
1603
+
1604
+ declare class WolbargLogger {
1605
+ private level;
1606
+ constructor(level?: TelemetryLogLevel);
1607
+ setLevel(level: TelemetryLogLevel): void;
1608
+ getLevel(): TelemetryLogLevel;
1609
+ error(message: string, extra?: unknown): void;
1610
+ warn(message: string, extra?: unknown): void;
1611
+ info(message: string, extra?: unknown): void;
1612
+ debug(message: string, extra?: unknown): void;
1613
+ trace(message: string, extra?: unknown): void;
1614
+ private write;
1615
+ }
1616
+
1617
+ /**
1618
+ * Trace context helpers — session_id, trace_id, parent_trace_id.
1619
+ */
1620
+ interface TraceContext {
1621
+ sessionId: string;
1622
+ traceId: string;
1623
+ parentTraceId: string | null;
1624
+ }
1625
+
1626
+ /**
1627
+ * Async telemetry emitter that never blocks memory operations.
1628
+ */
1629
+
1630
+ declare class NoopTelemetryProvider implements TelemetryProvider {
1631
+ readonly name = "noop";
1632
+ open(): Promise<void>;
1633
+ close(): Promise<void>;
1634
+ emit(_event: TelemetryEventInput): void;
1635
+ flush(): Promise<void>;
1636
+ }
1637
+ interface OperationTraceHandle {
1638
+ context: TraceContext;
1639
+ startedAt: number;
1640
+ latency: Partial<LatencyBreakdown>;
1641
+ child(operation: TelemetryOperation): OperationTraceHandle;
1642
+ mark(stage: keyof Omit<LatencyBreakdown, "totalMs">, ms: number): void;
1643
+ success(fields?: Partial<TelemetryEventInput>): void;
1644
+ failure(error: unknown, fields?: Partial<TelemetryEventInput>): void;
1645
+ }
1646
+ interface TelemetryEmitterContext {
1647
+ organization?: string | null;
1648
+ }
1649
+ declare class TelemetryEmitter {
1650
+ readonly sessionId: string;
1651
+ readonly logger: WolbargLogger;
1652
+ private provider;
1653
+ private readonly config;
1654
+ private readonly context;
1655
+ constructor(provider: TelemetryProvider | null, config?: Partial<TelemetryConfig>, context?: TelemetryEmitterContext);
1656
+ get enabled(): boolean;
1657
+ setProvider(provider: TelemetryProvider): void;
1658
+ open(): Promise<void>;
1659
+ close(): Promise<void>;
1660
+ flush(): Promise<void>;
1661
+ start(operation: TelemetryOperation, parent?: TraceContext): OperationTraceHandle;
1662
+ emitStartup(provider: string): void;
1663
+ emitShutdown(provider: string): void;
1664
+ }
1665
+
1666
+ /**
1667
+ * Internal benchmark helpers for CLI / Studio later.
1668
+ * @internal
1669
+ */
1670
+ interface BenchmarkSample {
1671
+ name: string;
1672
+ durationMs: number;
1673
+ ok: boolean;
1674
+ error?: string;
1675
+ }
1676
+ interface BenchmarkReport {
1677
+ startedAt: string;
1678
+ finishedAt: string;
1679
+ samples: BenchmarkSample[];
1680
+ summary: {
1681
+ count: number;
1682
+ ok: number;
1683
+ failed: number;
1684
+ avgMs: number;
1685
+ p50Ms: number;
1686
+ p95Ms: number;
1687
+ p99Ms: number;
1688
+ };
1689
+ }
1690
+ declare function runBenchmark(name: string, iterations: number, fn: () => Promise<void> | void): Promise<BenchmarkSample[]>;
1691
+ declare function summarizeBenchmark(samples: BenchmarkSample[], startedAt: string, finishedAt: string): BenchmarkReport;
1692
+
1693
+ 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, ConfigurationError, type CreateCheckpointOptions, type DatabaseConfig, DatabaseError, type DatabaseProvider, type DatabaseProviderName, type EmbeddingConfig, EmbeddingError, type EmbeddingProvider, type EventDatabase, type ExportResult, FixedChunkingStrategy, type ForgetByFilterOptions, type ForgetByIdOptions, type ForgetOptions, 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 MemoryContent, type MemoryFilter, type MemoryMetadata, MemoryNotFoundError, type MemoryProvider, type MemoryRecord, type MetadataFilter as MetaFilter, type MetadataComparison, type MetadataFilter, type MmrConfig, NoopTelemetryProvider, type OCRProvider, type OcrResult, ParagraphChunkingStrategy, type PersistedRecallExplainPayload, type PostgresDatabaseConfig, PostgresStorageProvider, ProviderNotConfiguredError, type RecallExplainResponse, type RecallExplanationHit, type RecallOptions, type RecallResult, type RememberOptions, type RerankDocument, type RerankHit, type RerankerProvider, type RetrievalConfig, SentenceChunkingStrategy, SqliteCheckpointProvider, type SqliteDatabaseConfig, SqliteDatabaseProvider, SqliteEventDatabase, SqliteStorageProvider, SqliteTelemetryProvider, type StageSpan, type StatsResult, type StorageConfig, type StorageProvider, type StorageProviderName, type TelemetryConfig, TelemetryEmitter, type TelemetryEvent, type TelemetryEventInput, type TelemetryLogLevel, type TelemetryOperation, type TelemetryProvider, type TelemetryQuery, type TelemetryQueryResult, type TelemetryStatus, ValidationError, type VisionProvider, type VisionResult, Wolbarg, WolbargError, WolbargLogger, type WolbargOptions, type WolbargOptionsWithLlm, type WolbargOptionsWithoutLlm, bgeReranker, bm25, cohereReranker, createChunkingStrategy, createCompressionProvider, createDatabaseProvider, createEmbeddingProvider, createLlmProvider, createStorageProvider, createTelemetryProvider, wolbarg as createWolbarg, crossEncoder, geminiEmbedding, geminiVision, jinaReranker, lmStudioEmbedding, meta, ollamaEmbedding, ollamaLlm, openRouterEmbedding, openRouterLlm, openaiCompatibleEmbedding, openaiCompatibleLlm, openaiEmbedding, openaiLlm, openaiReranker, openaiVision, postgres, postgresConfig, runBenchmark, sqlite, sqliteCheckpoint, sqliteConfig, sqliteTelemetry, summarizeBenchmark, tesseract, togetherEmbedding, vllmEmbedding, wolbarg$1 as wolbarg, wrapOperationError };