@karmaniverous/jeeves-watcher 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.schema.json +69 -14
- package/dist/cjs/index.js +996 -562
- package/dist/cli/jeeves-watcher/index.js +824 -396
- package/dist/index.d.ts +160 -16
- package/dist/index.iife.js +824 -397
- package/dist/index.iife.min.js +1 -1
- package/dist/mjs/index.js +992 -564
- package/package.json +12 -4
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import pino from 'pino';
|
|
|
3
3
|
import * as _karmaniverous_jsonmap from '@karmaniverous/jsonmap';
|
|
4
4
|
import { JsonMapMap } from '@karmaniverous/jsonmap';
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
+
import Handlebars from 'handlebars';
|
|
6
7
|
import { Stats } from 'node:fs';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -78,6 +79,7 @@ declare const inferenceRuleSchema: z.ZodObject<{
|
|
|
78
79
|
match: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
79
80
|
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
80
81
|
map: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>, z.ZodString]>>;
|
|
82
|
+
template: z.ZodOptional<z.ZodString>;
|
|
81
83
|
}, z.core.$strip>;
|
|
82
84
|
/** An inference rule: JSON Schema match condition, set fields, and optional JsonMap transformation. */
|
|
83
85
|
type InferenceRule = z.infer<typeof inferenceRuleSchema>;
|
|
@@ -123,8 +125,13 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
|
|
|
123
125
|
match: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
124
126
|
set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
125
127
|
map: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>, z.ZodString]>>;
|
|
128
|
+
template: z.ZodOptional<z.ZodString>;
|
|
126
129
|
}, z.core.$strip>>>;
|
|
127
130
|
maps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>>>;
|
|
131
|
+
templates: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
132
|
+
templateHelpers: z.ZodOptional<z.ZodObject<{
|
|
133
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
|
+
}, z.core.$strip>>;
|
|
128
135
|
logging: z.ZodOptional<z.ZodObject<{
|
|
129
136
|
level: z.ZodOptional<z.ZodString>;
|
|
130
137
|
file: z.ZodOptional<z.ZodString>;
|
|
@@ -163,6 +170,104 @@ interface EmbeddingProvider {
|
|
|
163
170
|
*/
|
|
164
171
|
declare function createEmbeddingProvider(config: EmbeddingConfig, logger?: pino.Logger): EmbeddingProvider;
|
|
165
172
|
|
|
173
|
+
/**
|
|
174
|
+
* @module templates/engine
|
|
175
|
+
* Handlebars template compilation, caching, and resolution (file path vs named ref vs inline).
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
/** A compiled Handlebars template function. */
|
|
179
|
+
type CompiledTemplate = HandlebarsTemplateDelegate;
|
|
180
|
+
/**
|
|
181
|
+
* Resolve a template value to its source string.
|
|
182
|
+
*
|
|
183
|
+
* Resolution order:
|
|
184
|
+
* 1. Ends in `.hbs` or `.handlebars` → file path (resolve relative to configDir)
|
|
185
|
+
* 2. Matches a key in namedTemplates → named ref (recursively resolve)
|
|
186
|
+
* 3. Otherwise → inline Handlebars template string
|
|
187
|
+
*
|
|
188
|
+
* @param value - The template reference (inline, file path, or named ref).
|
|
189
|
+
* @param namedTemplates - Named template definitions from config.
|
|
190
|
+
* @param configDir - Directory to resolve relative file paths against.
|
|
191
|
+
* @param visited - Set of visited named refs for cycle detection.
|
|
192
|
+
* @returns The resolved template source string.
|
|
193
|
+
*/
|
|
194
|
+
declare function resolveTemplateSource(value: string, namedTemplates: Record<string, string> | undefined, configDir: string, visited?: Set<string>): string;
|
|
195
|
+
/**
|
|
196
|
+
* Create a configured Handlebars instance with built-in helpers registered.
|
|
197
|
+
*
|
|
198
|
+
* @returns A Handlebars instance with helpers.
|
|
199
|
+
*/
|
|
200
|
+
declare function createHandlebarsInstance(): typeof Handlebars;
|
|
201
|
+
/**
|
|
202
|
+
* Load custom helpers from file paths.
|
|
203
|
+
*
|
|
204
|
+
* Each file should export a default function that receives the Handlebars instance.
|
|
205
|
+
*
|
|
206
|
+
* @param hbs - The Handlebars instance.
|
|
207
|
+
* @param paths - File paths to custom helper modules.
|
|
208
|
+
* @param configDir - Directory to resolve relative paths against.
|
|
209
|
+
*/
|
|
210
|
+
declare function loadCustomHelpers(hbs: typeof Handlebars, paths: string[], configDir: string): Promise<void>;
|
|
211
|
+
/**
|
|
212
|
+
* The template engine: holds compiled templates and renders them against context.
|
|
213
|
+
*/
|
|
214
|
+
declare class TemplateEngine {
|
|
215
|
+
private readonly hbs;
|
|
216
|
+
private readonly compiled;
|
|
217
|
+
constructor(hbs: typeof Handlebars);
|
|
218
|
+
/**
|
|
219
|
+
* Compile and cache a template from its source string.
|
|
220
|
+
*
|
|
221
|
+
* @param key - Cache key (rule index or named template).
|
|
222
|
+
* @param source - Handlebars template source.
|
|
223
|
+
* @returns The compiled template.
|
|
224
|
+
*/
|
|
225
|
+
compile(key: string, source: string): CompiledTemplate;
|
|
226
|
+
/**
|
|
227
|
+
* Get a previously compiled template by key.
|
|
228
|
+
*
|
|
229
|
+
* @param key - The cache key.
|
|
230
|
+
* @returns The compiled template, or undefined.
|
|
231
|
+
*/
|
|
232
|
+
get(key: string): CompiledTemplate | undefined;
|
|
233
|
+
/**
|
|
234
|
+
* Render a compiled template against a context.
|
|
235
|
+
*
|
|
236
|
+
* @param key - The cache key of the compiled template.
|
|
237
|
+
* @param context - The data context for rendering.
|
|
238
|
+
* @returns The rendered string, or null if the template was not found.
|
|
239
|
+
*/
|
|
240
|
+
render(key: string, context: Record<string, unknown>): string | null;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @module templates/buildTemplateEngine
|
|
245
|
+
* Factory to build a TemplateEngine from config, compiling all rule templates at load time.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Build a TemplateEngine from configuration, pre-compiling all rule templates.
|
|
250
|
+
*
|
|
251
|
+
* @param rules - The inference rules (may contain template fields).
|
|
252
|
+
* @param namedTemplates - Named template definitions from config.
|
|
253
|
+
* @param templateHelperPaths - Paths to custom helper modules.
|
|
254
|
+
* @param configDir - Directory to resolve relative paths against.
|
|
255
|
+
* @returns The configured TemplateEngine, or undefined if no templates are used.
|
|
256
|
+
*/
|
|
257
|
+
declare function buildTemplateEngine(rules: InferenceRule[], namedTemplates?: Record<string, string>, templateHelperPaths?: string[], configDir?: string): Promise<TemplateEngine | undefined>;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* @module templates/helpers
|
|
261
|
+
* Registers built-in Handlebars helpers for content templates.
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Register all built-in helpers on a Handlebars instance.
|
|
266
|
+
*
|
|
267
|
+
* @param hbs - The Handlebars instance.
|
|
268
|
+
*/
|
|
269
|
+
declare function registerBuiltinHelpers(hbs: typeof Handlebars): void;
|
|
270
|
+
|
|
166
271
|
/**
|
|
167
272
|
* @module rules/attributes
|
|
168
273
|
* Builds file attribute objects for rule matching. Pure function: derives attributes from path, stats, and extracted data.
|
|
@@ -238,7 +343,16 @@ interface RuleLogger {
|
|
|
238
343
|
warn(msg: string): void;
|
|
239
344
|
}
|
|
240
345
|
/**
|
|
241
|
-
*
|
|
346
|
+
* Result of applying inference rules.
|
|
347
|
+
*/
|
|
348
|
+
interface ApplyRulesResult {
|
|
349
|
+
/** Merged metadata from all matching rules. */
|
|
350
|
+
metadata: Record<string, unknown>;
|
|
351
|
+
/** Rendered template content from the last matching rule with a template, or null. */
|
|
352
|
+
renderedContent: string | null;
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Apply compiled inference rules to file attributes, returning merged metadata and optional rendered content.
|
|
242
356
|
*
|
|
243
357
|
* Rules are evaluated in order; later rules override earlier ones.
|
|
244
358
|
* If a rule has a `map`, the JsonMap transformation is applied after `set` resolution,
|
|
@@ -248,9 +362,11 @@ interface RuleLogger {
|
|
|
248
362
|
* @param attributes - The file attributes to match against.
|
|
249
363
|
* @param namedMaps - Optional record of named JsonMap definitions.
|
|
250
364
|
* @param logger - Optional logger for warnings (falls back to console.warn).
|
|
251
|
-
* @
|
|
365
|
+
* @param templateEngine - Optional template engine for rendering content templates.
|
|
366
|
+
* @param configDir - Optional config directory for resolving .json map file paths.
|
|
367
|
+
* @returns The merged metadata and optional rendered content.
|
|
252
368
|
*/
|
|
253
|
-
declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, namedMaps?: Record<string, JsonMapMap>, logger?: RuleLogger): Promise<
|
|
369
|
+
declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, namedMaps?: Record<string, JsonMapMap>, logger?: RuleLogger, templateEngine?: TemplateEngine, configDir?: string): Promise<ApplyRulesResult>;
|
|
254
370
|
|
|
255
371
|
/**
|
|
256
372
|
* A point to upsert into the vector store.
|
|
@@ -398,6 +514,8 @@ interface ProcessorConfig {
|
|
|
398
514
|
chunkOverlap?: number;
|
|
399
515
|
/** Named JsonMap definitions for rule transformations. */
|
|
400
516
|
maps?: Record<string, JsonMapMap>;
|
|
517
|
+
/** Config directory for resolving relative file paths. */
|
|
518
|
+
configDir?: string;
|
|
401
519
|
}
|
|
402
520
|
/**
|
|
403
521
|
* Core document processing pipeline.
|
|
@@ -410,6 +528,7 @@ declare class DocumentProcessor {
|
|
|
410
528
|
private readonly vectorStore;
|
|
411
529
|
private compiledRules;
|
|
412
530
|
private readonly logger;
|
|
531
|
+
private templateEngine?;
|
|
413
532
|
/**
|
|
414
533
|
* Create a new DocumentProcessor.
|
|
415
534
|
*
|
|
@@ -418,8 +537,9 @@ declare class DocumentProcessor {
|
|
|
418
537
|
* @param vectorStore - The vector store client.
|
|
419
538
|
* @param compiledRules - The compiled inference rules.
|
|
420
539
|
* @param logger - The logger instance.
|
|
540
|
+
* @param templateEngine - Optional template engine for content templates.
|
|
421
541
|
*/
|
|
422
|
-
constructor(config: ProcessorConfig, embeddingProvider: EmbeddingProvider, vectorStore: VectorStoreClient, compiledRules: CompiledRule[], logger: pino.Logger);
|
|
542
|
+
constructor(config: ProcessorConfig, embeddingProvider: EmbeddingProvider, vectorStore: VectorStoreClient, compiledRules: CompiledRule[], logger: pino.Logger, templateEngine?: TemplateEngine);
|
|
423
543
|
/**
|
|
424
544
|
* Process a file through the full pipeline: extract, hash, chunk, embed, upsert.
|
|
425
545
|
*
|
|
@@ -454,7 +574,13 @@ declare class DocumentProcessor {
|
|
|
454
574
|
*
|
|
455
575
|
* @param compiledRules - The newly compiled rules.
|
|
456
576
|
*/
|
|
457
|
-
|
|
577
|
+
/**
|
|
578
|
+
* Update compiled inference rules and optionally the template engine.
|
|
579
|
+
*
|
|
580
|
+
* @param compiledRules - The newly compiled rules.
|
|
581
|
+
* @param templateEngine - Optional updated template engine.
|
|
582
|
+
*/
|
|
583
|
+
updateRules(compiledRules: CompiledRule[], templateEngine?: TemplateEngine): void;
|
|
458
584
|
}
|
|
459
585
|
|
|
460
586
|
/**
|
|
@@ -693,6 +819,7 @@ declare class FileSystemWatcher {
|
|
|
693
819
|
private readonly logger;
|
|
694
820
|
private readonly health;
|
|
695
821
|
private readonly gitignoreFilter?;
|
|
822
|
+
private globMatches;
|
|
696
823
|
private watcher;
|
|
697
824
|
/**
|
|
698
825
|
* Create a new FileSystemWatcher.
|
|
@@ -732,6 +859,11 @@ declare class FileSystemWatcher {
|
|
|
732
859
|
private wrapProcessing;
|
|
733
860
|
}
|
|
734
861
|
|
|
862
|
+
/**
|
|
863
|
+
* @module app/factories
|
|
864
|
+
* Component factory interfaces and defaults for {@link JeevesWatcher}. Override in tests to inject mocks.
|
|
865
|
+
*/
|
|
866
|
+
|
|
735
867
|
/**
|
|
736
868
|
* Component factories for {@link JeevesWatcher}. Override in tests to inject mocks.
|
|
737
869
|
*/
|
|
@@ -747,7 +879,7 @@ interface JeevesWatcherFactories {
|
|
|
747
879
|
/** Compile inference rules from config. */
|
|
748
880
|
compileRules: typeof compileRules;
|
|
749
881
|
/** Create a document processor for file ingestion. */
|
|
750
|
-
createDocumentProcessor: (config: ConstructorParameters<typeof DocumentProcessor>[0], embeddingProvider: EmbeddingProvider, vectorStore: VectorStoreClient, compiledRules: ConstructorParameters<typeof DocumentProcessor>[3], logger: pino.Logger) => DocumentProcessor;
|
|
882
|
+
createDocumentProcessor: (config: ConstructorParameters<typeof DocumentProcessor>[0], embeddingProvider: EmbeddingProvider, vectorStore: VectorStoreClient, compiledRules: ConstructorParameters<typeof DocumentProcessor>[3], logger: pino.Logger, templateEngine?: ConstructorParameters<typeof DocumentProcessor>[5]) => DocumentProcessor;
|
|
751
883
|
/** Create an event queue for batching file-system events. */
|
|
752
884
|
createEventQueue: (options: ConstructorParameters<typeof EventQueue>[0]) => EventQueue;
|
|
753
885
|
/** Create a file-system watcher for the configured watch paths. */
|
|
@@ -755,9 +887,25 @@ interface JeevesWatcherFactories {
|
|
|
755
887
|
/** Create the HTTP API server. */
|
|
756
888
|
createApiServer: typeof createApiServer;
|
|
757
889
|
}
|
|
890
|
+
|
|
758
891
|
/**
|
|
759
|
-
*
|
|
892
|
+
* @module app/startFromConfig
|
|
893
|
+
* Convenience entry point: loads config from disk and starts a {@link JeevesWatcher}.
|
|
894
|
+
*/
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Create and start a JeevesWatcher from a config file path.
|
|
898
|
+
*
|
|
899
|
+
* @param configPath - Optional path to the configuration file.
|
|
900
|
+
* @returns The running JeevesWatcher instance.
|
|
901
|
+
*/
|
|
902
|
+
declare function startFromConfig(configPath?: string): Promise<JeevesWatcher>;
|
|
903
|
+
|
|
904
|
+
/**
|
|
905
|
+
* @module app
|
|
906
|
+
* Main application orchestrator. Wires components, manages lifecycle (start/stop/reload).
|
|
760
907
|
*/
|
|
908
|
+
|
|
761
909
|
/**
|
|
762
910
|
* Runtime options for {@link JeevesWatcher} that aren't serializable in config.
|
|
763
911
|
*/
|
|
@@ -796,17 +944,13 @@ declare class JeevesWatcher {
|
|
|
796
944
|
* Gracefully stop all components.
|
|
797
945
|
*/
|
|
798
946
|
stop(): Promise<void>;
|
|
947
|
+
private initEmbeddingAndStore;
|
|
948
|
+
private createWatcher;
|
|
949
|
+
private startApiServer;
|
|
799
950
|
private startConfigWatch;
|
|
800
951
|
private stopConfigWatch;
|
|
801
952
|
private reloadConfig;
|
|
802
953
|
}
|
|
803
|
-
/**
|
|
804
|
-
* Create and start a JeevesWatcher from a config file path.
|
|
805
|
-
*
|
|
806
|
-
* @param configPath - Optional path to the configuration file.
|
|
807
|
-
* @returns The running JeevesWatcher instance.
|
|
808
|
-
*/
|
|
809
|
-
declare function startFromConfig(configPath?: string): Promise<JeevesWatcher>;
|
|
810
954
|
|
|
811
955
|
/**
|
|
812
956
|
* Load the jeeves-watcher configuration.
|
|
@@ -891,5 +1035,5 @@ declare function deleteMetadata(filePath: string, metadataDir: string): Promise<
|
|
|
891
1035
|
*/
|
|
892
1036
|
declare function pointId(filePath: string, chunkIndex?: number): string;
|
|
893
1037
|
|
|
894
|
-
export { DocumentProcessor, EventQueue, FileSystemWatcher, GitignoreFilter, JeevesWatcher, SystemHealth, VectorStoreClient, apiConfigSchema, applyRules, buildAttributes, compileRules, configWatchConfigSchema, contentHash, createApiServer, createEmbeddingProvider, createLogger, deleteMetadata, embeddingConfigSchema, extractText, inferenceRuleSchema, jeevesWatcherConfigSchema, loadConfig, loggingConfigSchema, metadataPath, pointId, readMetadata, startFromConfig, vectorStoreConfigSchema, watchConfigSchema, writeMetadata };
|
|
895
|
-
export type { ApiConfig, ApiServerOptions, CollectionInfo, CompiledRule, ConfigWatchConfig, EmbeddingConfig, EmbeddingProvider, EventQueueOptions, ExtractedText, FileAttributes, FileSystemWatcherOptions, InferenceRule, JeevesWatcherConfig, JeevesWatcherFactories, JeevesWatcherRuntimeOptions, LoggingConfig, PayloadFieldSchema, ProcessFn, ProcessorConfig, RuleLogger, ScrolledPoint, SearchResult, SystemHealthOptions, VectorPoint, VectorStoreConfig, WatchConfig, WatchEvent };
|
|
1038
|
+
export { DocumentProcessor, EventQueue, FileSystemWatcher, GitignoreFilter, JeevesWatcher, SystemHealth, TemplateEngine, VectorStoreClient, apiConfigSchema, applyRules, buildAttributes, buildTemplateEngine, compileRules, configWatchConfigSchema, contentHash, createApiServer, createEmbeddingProvider, createHandlebarsInstance, createLogger, deleteMetadata, embeddingConfigSchema, extractText, inferenceRuleSchema, jeevesWatcherConfigSchema, loadConfig, loadCustomHelpers, loggingConfigSchema, metadataPath, pointId, readMetadata, registerBuiltinHelpers, resolveTemplateSource, startFromConfig, vectorStoreConfigSchema, watchConfigSchema, writeMetadata };
|
|
1039
|
+
export type { ApiConfig, ApiServerOptions, ApplyRulesResult, CollectionInfo, CompiledRule, CompiledTemplate, ConfigWatchConfig, EmbeddingConfig, EmbeddingProvider, EventQueueOptions, ExtractedText, FileAttributes, FileSystemWatcherOptions, InferenceRule, JeevesWatcherConfig, JeevesWatcherFactories, JeevesWatcherRuntimeOptions, LoggingConfig, PayloadFieldSchema, ProcessFn, ProcessorConfig, RuleLogger, ScrolledPoint, SearchResult, SystemHealthOptions, VectorPoint, VectorStoreConfig, WatchConfig, WatchEvent };
|