@happyvertical/smrt-config 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1098 @@
1
+ import { DomainKnowledgeConfig } from '@happyvertical/smrt-types';
2
+
3
+ /**
4
+ * Reset all cached configuration state.
5
+ *
6
+ * Clears three independent caches:
7
+ * 1. `globalThis.__smrtConfigCache` — the merged config loaded by {@link loadConfig}.
8
+ * 2. The internal loader cache (`globalThis.__smrtLoaderCachedConfig`) and the
9
+ * cosmiconfig explorer instance.
10
+ * 3. The runtime override store populated by {@link setConfig}.
11
+ *
12
+ * After calling this, {@link getConfig} returns `null` and a fresh
13
+ * {@link loadConfig} call will re-read from disk.
14
+ *
15
+ * WARNING: This is a global reset — it affects every module sharing the same
16
+ * runtime, not just the caller. Use with care outside of test teardown.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * afterEach(() => {
21
+ * clearCache(); // reset between tests
22
+ * });
23
+ * ```
24
+ *
25
+ * @see {@link loadConfig}
26
+ * @see {@link setConfig}
27
+ */
28
+ export declare function clearCache(): void;
29
+
30
+ /**
31
+ * Reset the runtime configuration override store to an empty object.
32
+ *
33
+ * Called by {@link clearCache} in `index.ts` as part of a full cache reset.
34
+ * Useful in tests to ensure a clean state between cases.
35
+ *
36
+ * @see {@link setConfig}
37
+ */
38
+ export declare function clearRuntimeConfig(): void;
39
+
40
+ /**
41
+ * CLI package configuration.
42
+ *
43
+ * Placed under the `cli` key in `smrt.config.js`. Consumed by
44
+ * `@happyvertical/smrt-cli` for `smrt db:*` and migration commands.
45
+ *
46
+ * @example
47
+ * ```js
48
+ * export default defineConfig({
49
+ * cli: {
50
+ * database: { type: 'sqlite', url: 'file:./local.db' },
51
+ * migrations: { mode: 'dynamic', directory: './migrations' },
52
+ * },
53
+ * });
54
+ * ```
55
+ *
56
+ * @see {@link DatabaseConfig}
57
+ * @see {@link MigrationsConfig}
58
+ */
59
+ export declare interface CliConfig {
60
+ /**
61
+ * Database connection settings
62
+ */
63
+ database?: DatabaseConfig;
64
+ /**
65
+ * Migration settings
66
+ */
67
+ migrations?: MigrationsConfig;
68
+ /**
69
+ * Required manifest/object/field/database-shape contract for schema commands.
70
+ */
71
+ schemaContract?: SchemaContractConfig;
72
+ }
73
+
74
+ /**
75
+ * Database connection configuration for CLI commands.
76
+ *
77
+ * Placed under `cli.database` in `smrt.config.js`. Used by
78
+ * `@happyvertical/smrt-cli` to connect for migration and inspection commands.
79
+ *
80
+ * @see {@link CliConfig}
81
+ */
82
+ export declare interface DatabaseConfig {
83
+ /**
84
+ * Database type
85
+ *
86
+ * @default 'sqlite'
87
+ */
88
+ type?: 'sqlite' | 'postgres' | 'duckdb';
89
+ /**
90
+ * Database connection URL
91
+ *
92
+ * For SQLite: file path or ':memory:'
93
+ * For PostgreSQL: postgresql://user:pass@host:port/dbname
94
+ */
95
+ url?: string;
96
+ }
97
+
98
+ /**
99
+ * Type-safe helper for authoring `smrt.config.js` files.
100
+ *
101
+ * This is an identity function — it returns its argument unchanged. Its sole
102
+ * purpose is to provide TypeScript type-checking and IDE auto-completion when
103
+ * writing the config object literal.
104
+ *
105
+ * @param config - The config object to validate against {@link SmrtConfig}.
106
+ * @returns The same object, unchanged.
107
+ *
108
+ * @example
109
+ * ```js
110
+ * // smrt.config.js
111
+ * import { defineConfig } from '@happyvertical/smrt-config';
112
+ *
113
+ * export default defineConfig({
114
+ * smrt: { logLevel: 'info' },
115
+ * site: { name: 'My Site', ... },
116
+ * });
117
+ * ```
118
+ *
119
+ * @see {@link SmrtConfig}
120
+ * @see {@link loadConfig}
121
+ */
122
+ export declare function defineConfig(config: SmrtConfig): SmrtConfig;
123
+
124
+ /**
125
+ * Export configuration for static site generation.
126
+ *
127
+ * Placed under the `export` key in `smrt.config.js`. Controls how database
128
+ * records are exported to static files during SSG builds. Each additional
129
+ * key beyond `fieldExportDefault` and `format` defines a named export file.
130
+ *
131
+ * @example
132
+ * ```js
133
+ * export default defineConfig({
134
+ * export: {
135
+ * fieldExportDefault: true,
136
+ * articles: { types: ['Article'], filters: { status: ['published'] } },
137
+ * games: { types: ['Game'], orderBy: '-date', format: 'ndjson' },
138
+ * },
139
+ * });
140
+ * ```
141
+ *
142
+ * @see {@link ExportFileConfig}
143
+ * @see {@link exportConfig}
144
+ */
145
+ export declare interface ExportConfig {
146
+ /**
147
+ * Default export behavior for fields without explicit `exported` annotation
148
+ *
149
+ * - true: Export all fields by default (simpler, for most sites)
150
+ * - false: Only export fields with explicit `exported: true`
151
+ *
152
+ * @default true
153
+ */
154
+ fieldExportDefault?: boolean;
155
+ /**
156
+ * Default output format for all exports
157
+ * @default 'json'
158
+ */
159
+ format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
160
+ /**
161
+ * Export file configurations
162
+ * Keys become filenames (e.g., 'contents' -> 'contents.json')
163
+ */
164
+ [filename: string]: ExportFileConfig | boolean | string | undefined;
165
+ }
166
+
167
+ /**
168
+ * Serialize a configuration object to a formatted string for SSG file output.
169
+ *
170
+ * By default, {@link sanitizeConfig} is applied before serialization to strip
171
+ * any keys that match secret patterns (API keys, passwords, tokens, etc.).
172
+ * Pass `includeSecrets: true` only in secured server-side contexts.
173
+ *
174
+ * @param config - Configuration object to export. Any JSON-serializable value.
175
+ * @param options - Format, indentation, and secret-inclusion options.
176
+ * @returns A JSON string, or an ES module string (`export default {...};\n`)
177
+ * when `format: 'js'`.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * // Write a sanitized JSON export file for SSG
182
+ * const json = exportConfig(agentConfig);
183
+ * await fs.writeFile('./public/config.json', json);
184
+ * ```
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * // ES module format (importable via `import config from './config.js'`)
189
+ * const js = exportConfig(agentConfig, { format: 'js' });
190
+ * ```
191
+ *
192
+ * @see {@link sanitizeConfig}
193
+ * @see {@link parseExportedConfig}
194
+ * @see {@link ExportConfigOptions}
195
+ */
196
+ export declare function exportConfig(config: unknown, options?: ExportConfigOptions): string;
197
+
198
+ /**
199
+ * Options accepted by {@link exportConfig}.
200
+ */
201
+ export declare interface ExportConfigOptions {
202
+ /**
203
+ * Include secrets in the export (use with caution!)
204
+ * @default false
205
+ */
206
+ includeSecrets?: boolean;
207
+ /**
208
+ * Output format
209
+ * - 'json': Plain JSON format
210
+ * - 'js': ES module format (export default)
211
+ * @default 'json'
212
+ */
213
+ format?: 'json' | 'js';
214
+ /**
215
+ * Number of spaces for indentation
216
+ * @default 2
217
+ */
218
+ indent?: number;
219
+ }
220
+
221
+ /**
222
+ * Configuration for a single SSG export file.
223
+ *
224
+ * Each key in {@link ExportConfig} (besides `fieldExportDefault` and `format`)
225
+ * becomes the output filename. Records are queried from the database, filtered,
226
+ * ordered, and written to `{key}.json` (or the specified format).
227
+ *
228
+ * @example
229
+ * ```js
230
+ * export default defineConfig({
231
+ * export: {
232
+ * articles: {
233
+ * types: ['Article'],
234
+ * filters: { status: ['published'] },
235
+ * orderBy: '-publishDate',
236
+ * limit: 500,
237
+ * },
238
+ * },
239
+ * });
240
+ * ```
241
+ *
242
+ * @see {@link ExportConfig}
243
+ * @see {@link ExportFilterValue}
244
+ */
245
+ export declare interface ExportFileConfig {
246
+ /**
247
+ * SMRT object types to include in this export
248
+ * Uses className (e.g., 'MeetingRecap', 'Game')
249
+ */
250
+ types: string[];
251
+ /**
252
+ * Field whitelist - only export these fields
253
+ * If specified, overrides exclude and fieldExportDefault
254
+ */
255
+ include?: string[];
256
+ /**
257
+ * Field blacklist - exclude these fields
258
+ * Applied after schema-level exported: false check
259
+ */
260
+ exclude?: string[];
261
+ /**
262
+ * Filters to apply when querying records
263
+ * Keys are field names, values are filter conditions
264
+ *
265
+ * @example
266
+ * filters: {
267
+ * status: ['published'], // shorthand for status IN ('published')
268
+ * publish_date: { gte: '2025-01-01' },
269
+ * council_slug: ['town-of-bentley'],
270
+ * }
271
+ */
272
+ filters?: Record<string, string[] | number[] | ExportFilterValue>;
273
+ /**
274
+ * Output format for this file
275
+ * @default 'json'
276
+ */
277
+ format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
278
+ /**
279
+ * Field to order by
280
+ * Prefix with '-' for descending (e.g., '-publish_date')
281
+ */
282
+ orderBy?: string;
283
+ /**
284
+ * Maximum records per file
285
+ * If exceeded, creates paginated files (e.g., contents-1.json, contents-2.json)
286
+ */
287
+ limit?: number;
288
+ /**
289
+ * Create separate files per unique value of this field
290
+ * e.g., shardBy: 'year' creates contents-2024.json, contents-2025.json
291
+ */
292
+ shardBy?: string;
293
+ }
294
+
295
+ /**
296
+ * Filter operators for export queries.
297
+ *
298
+ * Used as values in {@link ExportFileConfig.filters} to build SQL `WHERE`
299
+ * clauses when exporting records to static files.
300
+ *
301
+ * @example
302
+ * ```js
303
+ * filters: {
304
+ * publishDate: { gte: '2025-01-01', lt: '2026-01-01' },
305
+ * status: { in: ['published', 'featured'] },
306
+ * }
307
+ * ```
308
+ *
309
+ * @see {@link ExportFileConfig}
310
+ */
311
+ export declare interface ExportFilterValue {
312
+ /** Equals (shorthand: just the value) */
313
+ eq?: string | number | boolean;
314
+ /** Not equals */
315
+ ne?: string | number | boolean;
316
+ /** Greater than */
317
+ gt?: string | number;
318
+ /** Greater than or equal */
319
+ gte?: string | number;
320
+ /** Less than */
321
+ lt?: string | number;
322
+ /** Less than or equal */
323
+ lte?: string | number;
324
+ /** In array */
325
+ in?: (string | number)[];
326
+ /** Contains (text) */
327
+ contains?: string;
328
+ }
329
+
330
+ /**
331
+ * Return the full merged configuration synchronously.
332
+ *
333
+ * Reads from `globalThis.__smrtConfigCache` without triggering a file search.
334
+ * Returns `null` when {@link loadConfig} has not been called yet (or after
335
+ * {@link clearCache} resets the cache).
336
+ *
337
+ * @returns The cached {@link SmrtConfig}, or `null` if not yet loaded.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * const config = getConfig();
342
+ * if (config?.smrt?.logLevel === 'debug') {
343
+ * console.log('Debug logging enabled');
344
+ * }
345
+ * ```
346
+ *
347
+ * @see {@link loadConfig}
348
+ * @see {@link getSiteConfig}
349
+ * @see {@link getModuleConfig}
350
+ */
351
+ export declare function getConfig(): SmrtConfig | null;
352
+
353
+ /**
354
+ * Return the resolved configuration for a named module.
355
+ *
356
+ * Merges four layers in ascending priority order:
357
+ * 1. `defaults` (caller-supplied fallbacks)
358
+ * 2. Global `smrt` section of the loaded config
359
+ * 3. `modules[moduleName]` section of the loaded config
360
+ * 4. Runtime `modules[moduleName]` overrides set via {@link setConfig}
361
+ *
362
+ * Works synchronously — call {@link loadConfig} first to populate the cache.
363
+ * If no config has been loaded, only `defaults` are returned.
364
+ *
365
+ * @param moduleName - Key in `config.modules` (e.g., `'praeco'`).
366
+ * @param defaults - Optional fallback values used when a key is absent from all
367
+ * higher-priority layers.
368
+ * @returns The fully merged module config typed as `T`.
369
+ *
370
+ * @example
371
+ * ```ts
372
+ * const config = getModuleConfig('praeco', {
373
+ * rssLimit: 50,
374
+ * fetchTimeout: 10_000,
375
+ * });
376
+ * // config.rssLimit may be overridden by smrt.config.js or setConfig()
377
+ * ```
378
+ *
379
+ * @see {@link getPackageConfig}
380
+ * @see {@link setConfig}
381
+ * @see {@link SmrtConfig.modules}
382
+ */
383
+ export declare function getModuleConfig<T extends Record<string, unknown>>(moduleName: string, defaults?: T): T;
384
+
385
+ /**
386
+ * Return the resolved configuration for a named package.
387
+ *
388
+ * Identical to {@link getModuleConfig} but reads from `config.packages` instead
389
+ * of `config.modules`. Use this inside `@happyvertical/smrt-*` packages that
390
+ * want to expose their own config section without conflicting with user-defined
391
+ * module names.
392
+ *
393
+ * Merges four layers in ascending priority order:
394
+ * 1. `defaults` (caller-supplied fallbacks)
395
+ * 2. Global `smrt` section of the loaded config
396
+ * 3. `packages[packageName]` section of the loaded config
397
+ * 4. Runtime `packages[packageName]` overrides set via {@link setConfig}
398
+ *
399
+ * @param packageName - Key in `config.packages` (e.g., `'ai'`, `'spider'`).
400
+ * @param defaults - Optional fallback values.
401
+ * @returns The fully merged package config typed as `T`.
402
+ *
403
+ * @example
404
+ * ```ts
405
+ * // Inside @happyvertical/smrt-ai package
406
+ * const config = getPackageConfig('ai', {
407
+ * defaultModel: 'gpt-4o-mini',
408
+ * maxTokens: 2048,
409
+ * });
410
+ * ```
411
+ *
412
+ * @see {@link getModuleConfig}
413
+ * @see {@link setConfig}
414
+ * @see {@link SmrtConfig.packages}
415
+ */
416
+ export declare function getPackageConfig<T extends Record<string, unknown>>(packageName: string, defaults?: T): T;
417
+
418
+ /**
419
+ * Return the current runtime configuration override store.
420
+ *
421
+ * Used internally by {@link getModuleConfig} and {@link getPackageConfig} to
422
+ * layer runtime overrides on top of file-based config. Prefer those helpers
423
+ * for reading config; this is a low-level accessor.
424
+ *
425
+ * @returns The accumulated runtime config partial.
426
+ */
427
+ export declare function getRuntimeConfig(): Partial<SmrtConfig>;
428
+
429
+ /**
430
+ * Return the `site` section of the loaded configuration.
431
+ *
432
+ * Equivalent to `getConfig()?.site ?? null`. Returns `null` both when no
433
+ * config has been loaded and when the loaded config has no `site` key.
434
+ *
435
+ * @returns The {@link SiteConfig} object, or `null` if not defined.
436
+ *
437
+ * @example
438
+ * ```ts
439
+ * const site = getSiteConfig();
440
+ * const title = site?.name ?? 'Untitled Site';
441
+ * ```
442
+ *
443
+ * @see {@link SiteConfig}
444
+ * @see {@link getConfig}
445
+ */
446
+ export declare function getSiteConfig(): SiteConfig | null;
447
+
448
+ /**
449
+ * Load and parse configuration from the project root.
450
+ *
451
+ * Searches for `smrt.config.{js,mjs,cjs,json}` starting from the current
452
+ * working directory and walking up the tree (unless `searchParents: false`).
453
+ * The result is stored in `globalThis.__smrtConfigCache` so every module in
454
+ * the process — including pnpm workspace packages loaded from different paths
455
+ * — sees the same instance.
456
+ *
457
+ * Must be called before {@link getConfig}, {@link getModuleConfig}, or
458
+ * {@link getPackageConfig} return meaningful values (they fall back to an
459
+ * empty config if called before loading).
460
+ *
461
+ * @param options - Optional search path, parent traversal, and cache control.
462
+ * @returns The parsed {@link SmrtConfig}. Returns `{}` if no file is found.
463
+ *
464
+ * @example
465
+ * ```ts
466
+ * // Typical app startup
467
+ * import { loadConfig } from '@happyvertical/smrt-config';
468
+ * await loadConfig();
469
+ * ```
470
+ *
471
+ * @example
472
+ * ```ts
473
+ * // Load a specific file (tests / scripts)
474
+ * const config = await loadConfig({ configPath: './fixtures/smrt.config.js', cache: false });
475
+ * ```
476
+ *
477
+ * @see {@link getConfig}
478
+ * @see {@link clearCache}
479
+ * @see {@link LoadConfigOptions}
480
+ */
481
+ export declare function loadConfig(options?: LoadConfigOptions): Promise<SmrtConfig>;
482
+
483
+ /**
484
+ * Options accepted by {@link loadConfig}.
485
+ *
486
+ * All fields are optional; omitting them triggers cosmiconfig's default
487
+ * search behaviour (scan `cwd` upward for `smrt.config.{js,mjs,cjs,json}`).
488
+ */
489
+ export declare interface LoadConfigOptions {
490
+ /**
491
+ * Absolute or relative path to a specific config file.
492
+ * When provided, cosmiconfig loads this file directly instead of searching.
493
+ */
494
+ configPath?: string;
495
+ /**
496
+ * Whether to search parent directories when no config is found in `cwd`.
497
+ *
498
+ * @default true
499
+ */
500
+ searchParents?: boolean;
501
+ /**
502
+ * Whether to cache the loaded config in `globalThis.__smrtLoaderCachedConfig`.
503
+ * Disable for test isolation or hot-reload scenarios.
504
+ *
505
+ * @default true
506
+ */
507
+ cache?: boolean;
508
+ }
509
+
510
+ /**
511
+ * Merge three config layers in ascending priority order.
512
+ *
513
+ * Priority (highest to lowest):
514
+ * 1. `runtime` — runtime overrides set via {@link setConfig}
515
+ * 2. `fileConfig` — values loaded from `smrt.config.js`
516
+ * 3. `defaults` — caller-supplied fallback values
517
+ *
518
+ * Uses {@link deepMerge} internally, so `null` / `undefined` source values
519
+ * never overwrite existing target values.
520
+ *
521
+ * @param defaults - Lowest-priority base values (caller defaults).
522
+ * @param fileConfig - Mid-priority values from the loaded config file.
523
+ * @param runtime - Highest-priority runtime override values.
524
+ * @returns A new object with all three layers merged.
525
+ *
526
+ * @example
527
+ * ```ts
528
+ * const merged = mergeConfigs(
529
+ * { timeout: 5000, retries: 3 },
530
+ * { retries: 5 },
531
+ * { timeout: 1000 },
532
+ * );
533
+ * // => { timeout: 1000, retries: 5 }
534
+ * ```
535
+ */
536
+ export declare function mergeConfigs<T extends Record<string, unknown>>(defaults: T, fileConfig: Partial<T>, runtime: Partial<T>): T;
537
+
538
+ /**
539
+ * Shallow-merge an exported (DB-backed) config into a base (file-backed) config.
540
+ *
541
+ * Object values are deep-merged recursively. Primitive values and arrays from
542
+ * `exportedConfig` replace their counterparts in `baseConfig`. This is a
543
+ * one-level-smarter spread that lets file-based env overrides win when placed
544
+ * after the spread.
545
+ *
546
+ * Intended for the SSG pattern where an agent exports its runtime config to a
547
+ * static JSON file and `smrt.config.js` imports it as a base:
548
+ *
549
+ * @example
550
+ * ```js
551
+ * // smrt.config.js
552
+ * import exported from './smrt.exported.json' with { type: 'json' };
553
+ *
554
+ * export default defineConfig({
555
+ * modules: {
556
+ * praeco: mergeExportedConfig(exported, {
557
+ * apiEndpoint: process.env.API_URL, // env override wins
558
+ * }),
559
+ * },
560
+ * });
561
+ * ```
562
+ *
563
+ * @param baseConfig - Lower-priority base (typically from the DB export file).
564
+ * @param exportedConfig - Higher-priority overrides (typically env / file-based).
565
+ * @returns A new merged object of type `T`.
566
+ *
567
+ * @see {@link exportConfig}
568
+ * @see {@link parseExportedConfig}
569
+ */
570
+ export declare function mergeExportedConfig<T extends Record<string, unknown>>(baseConfig: T, exportedConfig: Partial<T>): T;
571
+
572
+ /**
573
+ * Database migrations configuration.
574
+ *
575
+ * Controls how migrations are generated, stored, and applied. Placed under
576
+ * the `cli.migrations` key in `smrt.config.js` and consumed by
577
+ * `@happyvertical/smrt-cli` migration commands (`smrt db:migrate`, etc.).
578
+ *
579
+ * @see {@link CliConfig}
580
+ */
581
+ export declare interface MigrationsConfig {
582
+ /**
583
+ * Directory for migration files (relative to project root)
584
+ *
585
+ * @default './migrations'
586
+ */
587
+ directory?: string;
588
+ /**
589
+ * Table name for tracking applied migrations
590
+ *
591
+ * @default '_smrt_schema_migrations'
592
+ */
593
+ table?: string;
594
+ /**
595
+ * Legacy file format setting. File-backed migration generation is not supported.
596
+ *
597
+ * @default 'sql'
598
+ */
599
+ format?: 'sql' | 'typescript';
600
+ /**
601
+ * Migration file naming strategy
602
+ *
603
+ * - 'sequence': Sequential numbers (0001, 0002, ...)
604
+ * - 'timestamp': Unix timestamp-based (20240115143052)
605
+ *
606
+ * @default 'sequence'
607
+ */
608
+ naming?: 'sequence' | 'timestamp';
609
+ /**
610
+ * Migration mode.
611
+ *
612
+ * SMRT schema migrations are manifest-driven. File-backed modes are not
613
+ * supported unless a future file migration executor is implemented.
614
+ *
615
+ * @default 'dynamic'
616
+ */
617
+ mode?: 'dynamic';
618
+ /**
619
+ * Configure mode per environment.
620
+ *
621
+ * Overrides the `mode` setting based on NODE_ENV
622
+ */
623
+ modeByEnvironment?: {
624
+ development?: 'dynamic';
625
+ test?: 'dynamic';
626
+ staging?: 'dynamic';
627
+ production?: 'dynamic';
628
+ };
629
+ /**
630
+ * Automatically generate DOWN scripts where safe
631
+ *
632
+ * Some operations (DROP COLUMN) may lose data and should be reviewed.
633
+ *
634
+ * @default true
635
+ */
636
+ autoGenerateDown?: boolean;
637
+ /**
638
+ * PostgreSQL-specific settings
639
+ */
640
+ postgres?: MigrationsPostgresConfig;
641
+ }
642
+
643
+ /**
644
+ * PostgreSQL-specific migration settings.
645
+ *
646
+ * Nested under `migrations.postgres` in {@link MigrationsConfig}.
647
+ */
648
+ export declare interface MigrationsPostgresConfig {
649
+ /**
650
+ * Use CREATE INDEX CONCURRENTLY for index creation
651
+ * Avoids table locks but cannot run in a transaction
652
+ *
653
+ * @default true
654
+ */
655
+ useConcurrently?: boolean;
656
+ /**
657
+ * Lock timeout for migration statements
658
+ *
659
+ * @default '30s'
660
+ */
661
+ lockTimeout?: string;
662
+ /**
663
+ * Statement timeout for migration execution
664
+ *
665
+ * @default '60s'
666
+ */
667
+ statementTimeout?: string;
668
+ }
669
+
670
+ /**
671
+ * Parse a config string previously produced by {@link exportConfig} back into
672
+ * a plain JavaScript object.
673
+ *
674
+ * Handles both output formats:
675
+ * - **JSON** — standard `JSON.parse`.
676
+ * - **JS module** — strips the `export default` prefix and trailing semicolon
677
+ * before parsing as JSON.
678
+ *
679
+ * Throws a `SyntaxError` if the content is not valid JSON after stripping.
680
+ *
681
+ * @param content - Exported config string (`'json'` or `'js'` format).
682
+ * @returns Parsed configuration value.
683
+ *
684
+ * @example
685
+ * ```ts
686
+ * const raw = await fs.readFile('./smrt.exported.json', 'utf8');
687
+ * const config = parseExportedConfig(raw);
688
+ * ```
689
+ *
690
+ * @see {@link exportConfig}
691
+ * @see {@link mergeExportedConfig}
692
+ */
693
+ export declare function parseExportedConfig(content: string): unknown;
694
+
695
+ /**
696
+ * Config export utilities for static site generation
697
+ *
698
+ * These utilities enable exporting database-backed agent configurations
699
+ * to static files for SSG sites.
700
+ *
701
+ * @module
702
+ */
703
+ /**
704
+ * Deep-clone a config object, removing every key that looks like a secret.
705
+ *
706
+ * Keys are tested (case-insensitively, across camelCase / snake_case / kebab /
707
+ * UPPER variants) against {@link SECRET_PATTERNS}, which cover secrets such as
708
+ * `apiKey`/`api_key`, `password`, `secret`, `token`, `credential`, `private`,
709
+ * `auth`/`authorization`/`oauth`, `accessKey`, `signingKey`, `encryptionKey`,
710
+ * `connectionString`, and `dbUrl`. The policy biases toward over-redaction
711
+ * because these exports are typically published as static, publicly served
712
+ * assets — see {@link SECRET_PATTERNS} for the full rationale.
713
+ *
714
+ * Nested objects are recursively sanitized; arrays are mapped element-by-element.
715
+ * `number` / `boolean` primitives pass through unchanged; `string` values are
716
+ * additionally run through value-level redaction that masks credentials embedded
717
+ * in a URL (`scheme://user:pass@host` → `scheme://***@host`) as well as
718
+ * high-confidence secret-token shapes pasted into otherwise-benign keys
719
+ * (OpenAI/Anthropic `sk-...`, AWS `AKIA...` access key IDs, GitHub/Slack/Google
720
+ * tokens, `Bearer ...` headers, and PEM private-key blocks) — catching secrets
721
+ * stored under a benign key the key-based patterns don't match.
722
+ *
723
+ * Own `__proto__` / `constructor` / `prototype` keys are dropped to prevent the
724
+ * cloned result's prototype from being reassigned via the `__proto__` setter.
725
+ *
726
+ * This function is called automatically by {@link exportConfig} unless
727
+ * `includeSecrets: true` is passed.
728
+ *
729
+ * @param config - Value to sanitize. Accepts any JSON-serializable structure.
730
+ * @returns A new value with all secret keys omitted. `null` / `undefined` are
731
+ * returned as-is.
732
+ *
733
+ * @example
734
+ * ```ts
735
+ * const sanitized = sanitizeConfig({
736
+ * apiEndpoint: 'https://api.example.com',
737
+ * apiKey: 'sk-secret-123',
738
+ * nested: { password: 'hunter2', name: 'test' },
739
+ * });
740
+ * // => { apiEndpoint: 'https://api.example.com', nested: { name: 'test' } }
741
+ * ```
742
+ *
743
+ * @see {@link exportConfig}
744
+ */
745
+ export declare function sanitizeConfig(config: unknown): unknown;
746
+
747
+ /**
748
+ * Semantic schema contract enforced by SMRT schema commands.
749
+ *
750
+ * Object and field requirements are checked against the loaded SMRT registry.
751
+ * Required fields are also translated to physical table/column checks after
752
+ * migration/status introspection. `requiredDatabaseShape` is reserved for
753
+ * database objects that SMRT cannot infer from manifests.
754
+ */
755
+ export declare interface SchemaContractConfig {
756
+ requiredObjects?: string[];
757
+ requiredFields?: string[];
758
+ requiredDatabaseShape?: {
759
+ tables?: string[];
760
+ columns?: string[];
761
+ indexes?: string[];
762
+ };
763
+ }
764
+
765
+ /**
766
+ * Apply runtime configuration overrides.
767
+ *
768
+ * Deep-merges `config` into an in-memory store that takes the highest priority
769
+ * in every subsequent {@link getModuleConfig} / {@link getPackageConfig} call.
770
+ * Successive calls accumulate — they do not replace earlier overrides.
771
+ *
772
+ * Common uses:
773
+ * - Inject test doubles or environment-specific values without a config file.
774
+ * - Apply feature flags from a remote source after startup.
775
+ *
776
+ * @param config - Partial {@link SmrtConfig} to merge into the runtime store.
777
+ * `null` values are ignored (they do not clear existing keys).
778
+ *
779
+ * @example
780
+ * ```ts
781
+ * setConfig({ modules: { ai: { defaultModel: 'gpt-4o' } } });
782
+ * ```
783
+ *
784
+ * @see {@link clearCache}
785
+ * @see {@link getModuleConfig}
786
+ */
787
+ export declare function setConfig(config: Partial<SmrtConfig>): void;
788
+
789
+ /**
790
+ * Site identity and configuration for SMRT site templates.
791
+ *
792
+ * Placed under the `site` key in `smrt.config.js`. Retrieved at runtime
793
+ * via {@link getSiteConfig}. Used by site templates
794
+ * (`template-sveltekit`, `template-site-static-json`) to define name,
795
+ * description, navigation, location, and theme.
796
+ *
797
+ * @example
798
+ * ```js
799
+ * export default defineConfig({
800
+ * site: {
801
+ * name: 'Bentley Alberta',
802
+ * description: 'Community news for Bentley, AB',
803
+ * url: 'https://bentley.ca',
804
+ * location: { name: 'Bentley', latitude: 52.4, longitude: -113.9, timezone: 'America/Edmonton' },
805
+ * navigation: { primary: [{ label: 'Home', href: '/' }] },
806
+ * },
807
+ * });
808
+ * ```
809
+ *
810
+ * @see {@link getSiteConfig}
811
+ * @see {@link SiteLocation}
812
+ * @see {@link SiteNavigation}
813
+ * @see {@link SiteTheme}
814
+ */
815
+ export declare interface SiteConfig {
816
+ /** Full site name (e.g., "Bentley Alberta") */
817
+ name: string;
818
+ /** Short name for mobile/compact displays */
819
+ shortName?: string;
820
+ /** Site description for SEO */
821
+ description: string;
822
+ /** Production URL */
823
+ url?: string;
824
+ /** Contact email for the site */
825
+ contactEmail?: string;
826
+ /** Publisher/organization info */
827
+ publisher?: SitePublisher;
828
+ /** Geographic location */
829
+ location: SiteLocation;
830
+ /** Navigation structure */
831
+ navigation: SiteNavigation;
832
+ /** Theme/branding */
833
+ theme?: SiteTheme;
834
+ /** Additional metadata */
835
+ meta?: {
836
+ /** Theme color for mobile browsers */
837
+ themeColor?: string;
838
+ /** Open Graph locale */
839
+ ogLocale?: string;
840
+ /** Google Tag Manager ID */
841
+ gtmId?: string;
842
+ };
843
+ }
844
+
845
+ /**
846
+ * Geographic location for the site, used for proximity search and display.
847
+ *
848
+ * @see {@link SiteConfig}
849
+ */
850
+ export declare interface SiteLocation {
851
+ /** Display name (e.g., "Bentley" or "Bentley, AB") */
852
+ name: string;
853
+ /** Latitude coordinate */
854
+ latitude: number;
855
+ /** Longitude coordinate */
856
+ longitude: number;
857
+ /** IANA timezone (e.g., "America/Edmonton") */
858
+ timezone: string;
859
+ }
860
+
861
+ /**
862
+ * Site navigation structure containing primary and optional footer links.
863
+ *
864
+ * @see {@link SiteConfig}
865
+ * @see {@link SiteNavigationLink}
866
+ */
867
+ export declare interface SiteNavigation {
868
+ /** Primary navigation links (header) */
869
+ primary: SiteNavigationLink[];
870
+ /** Footer navigation links */
871
+ footer?: SiteNavigationLink[];
872
+ }
873
+
874
+ /**
875
+ * A single navigation link item used in site menus.
876
+ *
877
+ * @see {@link SiteNavigation}
878
+ */
879
+ export declare interface SiteNavigationLink {
880
+ label: string;
881
+ href: string;
882
+ icon?: string;
883
+ }
884
+
885
+ /**
886
+ * Publisher or organization information displayed in site footers and metadata.
887
+ *
888
+ * @see {@link SiteConfig}
889
+ */
890
+ export declare interface SitePublisher {
891
+ /** Organization name (e.g., "Blindman Press") */
892
+ name: string;
893
+ /** Organization website URL */
894
+ url?: string;
895
+ /** GitHub organization URL */
896
+ github?: string;
897
+ }
898
+
899
+ /**
900
+ * Site theme and branding color palette.
901
+ *
902
+ * Colors should be provided as CSS hex values (e.g., `'#3b82f6'`).
903
+ *
904
+ * @see {@link SiteConfig}
905
+ */
906
+ export declare interface SiteTheme {
907
+ /** Primary brand color (hex) */
908
+ primaryColor: string;
909
+ /** Light variant of primary color */
910
+ primaryLight?: string;
911
+ /** Dark variant of primary color */
912
+ primaryDark?: string;
913
+ }
914
+
915
+ /**
916
+ * Root SMRT configuration structure.
917
+ *
918
+ * This is the shape of the object returned by `smrt.config.{js,ts,json}` and
919
+ * consumed by {@link loadConfig}. Use {@link defineConfig} for type-safe
920
+ * authoring with IDE auto-completion.
921
+ *
922
+ * Priority order (highest to lowest):
923
+ * 1. Runtime overrides set via {@link setConfig}
924
+ * 2. File-based config loaded by {@link loadConfig}
925
+ * 3. Defaults passed to {@link getModuleConfig} / {@link getPackageConfig}
926
+ *
927
+ * @example
928
+ * ```js
929
+ * // smrt.config.js
930
+ * import { defineConfig } from '@happyvertical/smrt-config';
931
+ *
932
+ * export default defineConfig({
933
+ * smrt: { logLevel: 'info', environment: 'production' },
934
+ * site: { name: 'My Site', ... },
935
+ * modules: { praeco: { rssLimit: 50 } },
936
+ * packages: { ai: { defaultModel: 'gpt-4o' } },
937
+ * });
938
+ * ```
939
+ *
940
+ * @see {@link loadConfig}
941
+ * @see {@link defineConfig}
942
+ * @see {@link SmrtGlobalConfig}
943
+ */
944
+ export declare interface SmrtConfig {
945
+ /** Global SMRT framework options — lowest-priority base for all modules. */
946
+ smrt?: SmrtGlobalConfig;
947
+ /** Site identity and configuration (for site templates). */
948
+ site?: SiteConfig;
949
+ /** Export configuration for static site generation. */
950
+ export?: ExportConfig;
951
+ /** Domain-scoped agent/developer knowledge generation and exposure. */
952
+ knowledge?: DomainKnowledgeConfig;
953
+ /**
954
+ * Module-scoped configurations keyed by module name.
955
+ * Retrieved via {@link getModuleConfig}.
956
+ */
957
+ modules?: {
958
+ [moduleName: string]: Record<string, unknown>;
959
+ };
960
+ /**
961
+ * Package-scoped configurations keyed by package name.
962
+ * Retrieved via {@link getPackageConfig}.
963
+ */
964
+ packages?: {
965
+ [packageName: string]: Record<string, unknown>;
966
+ };
967
+ }
968
+
969
+ /**
970
+ * Global SMRT framework options that apply to all modules unless overridden.
971
+ *
972
+ * Placed under the `smrt` key in `smrt.config.js`. Values here propagate
973
+ * as the lowest-priority base for every `getModuleConfig()` and
974
+ * `getPackageConfig()` call.
975
+ *
976
+ * @example
977
+ * ```js
978
+ * // smrt.config.js
979
+ * export default defineConfig({
980
+ * smrt: {
981
+ * logLevel: 'debug',
982
+ * environment: 'development',
983
+ * embeddings: { provider: 'local' },
984
+ * },
985
+ * });
986
+ * ```
987
+ *
988
+ * @see {@link SmrtConfig}
989
+ * @see {@link getModuleConfig}
990
+ * @see {@link getPackageConfig}
991
+ */
992
+ export declare interface SmrtGlobalConfig {
993
+ cacheDir?: string;
994
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
995
+ environment?: 'development' | 'production' | 'test';
996
+ /**
997
+ * Schema migration strategy when parent class schema changes
998
+ *
999
+ * Options:
1000
+ * - 'warn': Log warning about schema mismatch, require manual migration (safest)
1001
+ * - 'auto-add': Automatically ALTER TABLE to add new parent fields (default, convenient)
1002
+ *
1003
+ * Note: Removing columns is never automatic - always requires manual migration
1004
+ *
1005
+ * @default 'auto-add'
1006
+ */
1007
+ schemaMigration?: {
1008
+ strategy?: 'warn' | 'auto-add';
1009
+ };
1010
+ /**
1011
+ * Inheritance configuration
1012
+ */
1013
+ inheritance?: {
1014
+ /**
1015
+ * Behavior when an ancestor class is missing from the registry
1016
+ *
1017
+ * Options:
1018
+ * - 'error': Throw an error (strict, catches bugs)
1019
+ * - 'warn': Log warning and skip (lenient, default)
1020
+ *
1021
+ * @default 'warn'
1022
+ */
1023
+ onMissingAncestor?: 'error' | 'warn';
1024
+ /**
1025
+ * Size of LRU cache for inheritance chains and merged fields
1026
+ *
1027
+ * Higher values improve performance but use more memory.
1028
+ * Each entry stores one inheritance chain (array of strings).
1029
+ *
1030
+ * @default 200
1031
+ */
1032
+ cacheSize?: number;
1033
+ };
1034
+ /**
1035
+ * Embedding configuration for semantic search
1036
+ *
1037
+ * Project-level settings that apply to all SMRT objects
1038
+ * unless overridden in the @smrt() decorator.
1039
+ */
1040
+ embeddings?: {
1041
+ /**
1042
+ * Standard dimensions for embeddings in this project
1043
+ *
1044
+ * All embeddings should use the same dimensions for consistency.
1045
+ * Common values: 384, 768, 1536
1046
+ *
1047
+ * @default 768
1048
+ */
1049
+ dimensions?: number;
1050
+ /**
1051
+ * Embedding provider type
1052
+ *
1053
+ * - 'local': Use local Node.js model (@xenova/transformers)
1054
+ * - 'ai': Use AI library (OpenAI, etc.)
1055
+ * - 'auto': Try local first, fallback to AI
1056
+ *
1057
+ * @default 'local'
1058
+ */
1059
+ provider?: 'local' | 'ai' | 'auto';
1060
+ /**
1061
+ * Local model to use (when provider is 'local' or 'auto')
1062
+ *
1063
+ * Hugging Face model ID for @xenova/transformers.
1064
+ * Model is downloaded on first use (~440MB for bge-base-en-v1.5).
1065
+ *
1066
+ * @default 'Xenova/bge-base-en-v1.5'
1067
+ */
1068
+ localModel?: string;
1069
+ /**
1070
+ * AI model to use (when provider is 'ai' or fallback)
1071
+ *
1072
+ * OpenAI embedding model name.
1073
+ *
1074
+ * @default 'text-embedding-3-small'
1075
+ */
1076
+ aiModel?: string;
1077
+ /**
1078
+ * Whether to fallback to AI if local embedding fails
1079
+ *
1080
+ * Only applies when provider is 'auto'.
1081
+ *
1082
+ * @default true
1083
+ */
1084
+ fallbackToAI?: boolean;
1085
+ /**
1086
+ * Storage mode for embeddings
1087
+ *
1088
+ * - 'json': Store as JSON text, in-memory similarity (works everywhere)
1089
+ * - 'native': Use database vector operations when available, fallback to json
1090
+ *
1091
+ * @default 'json'
1092
+ */
1093
+ storage?: 'json' | 'native';
1094
+ };
1095
+ [key: string]: unknown;
1096
+ }
1097
+
1098
+ export { }