@happyvertical/smrt-config 0.51.32 → 0.51.33

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
@@ -1,1376 +1,10 @@
1
- import { DomainKnowledgeConfig } from '@happyvertical/smrt-types';
2
-
3
- /** Canonical config stored at `runtime` in `smrt.config.ts`. */
4
- export declare interface ApplicationRuntimeConfig {
5
- profile: ApplicationRuntimeProfile;
6
- providers?: RuntimeProviderOverrides;
7
- }
8
-
9
- /**
10
- * Stable application-runtime profile contract.
11
- *
12
- * Profiles select infrastructure composition only. Domain models, generated
13
- * surfaces, effect metadata, and approval policy are deliberately outside the
14
- * override surface so moving an application cannot silently change behavior.
15
- */
16
- export declare type ApplicationRuntimeProfile = 'local' | 'self-hosted' | 'cloud';
17
-
18
- export declare type AssetOwnership = 'user' | 'operator' | 'managed';
19
-
20
- export declare type AssetStorageProvider = 'local-files' | 's3-compatible' | 'managed-object-storage';
21
-
22
- export declare type AuthenticationProvider = 'owner-bootstrap' | 'oidc' | 'magic-link' | 'hosted-identity';
23
-
24
- export declare type BackupProvider = 'file-snapshot' | 'operator' | 'managed';
25
-
26
- /**
27
- * Reset all cached configuration state.
28
- *
29
- * Clears three independent caches:
30
- * 1. `globalThis.__smrtConfigCache` — the merged config loaded by {@link loadConfig}.
31
- * 2. The internal loader cache (`globalThis.__smrtLoaderCachedConfig`) and the
32
- * cosmiconfig explorer instance.
33
- * 3. The runtime override store populated by {@link setConfig}.
34
- *
35
- * After calling this, {@link getConfig} returns `null` and a fresh
36
- * {@link loadConfig} call will re-read from disk.
37
- *
38
- * WARNING: This is a global reset — it affects every module sharing the same
39
- * runtime, not just the caller. Use with care outside of test teardown.
40
- *
41
- * @example
42
- * ```ts
43
- * afterEach(() => {
44
- * clearCache(); // reset between tests
45
- * });
46
- * ```
47
- *
48
- * @see {@link loadConfig}
49
- * @see {@link setConfig}
50
- */
51
- export declare function clearCache(): void;
52
-
53
- /**
54
- * Reset the runtime configuration override store to an empty object.
55
- *
56
- * Called by {@link clearCache} in `index.ts` as part of a full cache reset.
57
- * Useful in tests to ensure a clean state between cases.
58
- *
59
- * @see {@link setConfig}
60
- */
61
- export declare function clearRuntimeConfig(): void;
62
-
63
- /**
64
- * CLI package configuration.
65
- *
66
- * Placed under the `cli` key in `smrt.config.js`. Consumed by
67
- * `@happyvertical/smrt-cli` for `smrt db:*` and migration commands.
68
- *
69
- * @example
70
- * ```js
71
- * export default defineConfig({
72
- * cli: {
73
- * database: { type: 'sqlite', url: 'file:./local.db' },
74
- * migrations: { mode: 'dynamic', directory: './migrations' },
75
- * },
76
- * });
77
- * ```
78
- *
79
- * @see {@link DatabaseConfig}
80
- * @see {@link MigrationsConfig}
81
- */
82
- export declare interface CliConfig {
83
- /**
84
- * Database connection settings
85
- */
86
- database?: DatabaseConfig;
87
- /**
88
- * Migration settings
89
- */
90
- migrations?: MigrationsConfig;
91
- /**
92
- * Required manifest/object/field/database-shape contract for schema commands.
93
- */
94
- schemaContract?: SchemaContractConfig;
95
- }
96
-
97
- export declare type ConnectionOwnership = 'user' | 'operator' | 'managed';
98
-
99
- /**
100
- * Database connection configuration for CLI commands.
101
- *
102
- * Placed under `cli.database` in `smrt.config.js`. Used by
103
- * `@happyvertical/smrt-cli` to connect for migration and inspection commands.
104
- *
105
- * @see {@link CliConfig}
106
- */
107
- export declare interface DatabaseConfig {
108
- /**
109
- * Database type
110
- *
111
- * @default 'sqlite'
112
- */
113
- type?: 'sqlite' | 'postgres' | 'duckdb';
114
- /**
115
- * Database connection URL
116
- *
117
- * For SQLite: file path or ':memory:'
118
- * For PostgreSQL: postgresql://user:pass@host:port/dbname
119
- */
120
- url?: string;
121
- }
122
-
123
- export declare type DatabaseEngine = 'sqlite' | 'postgres';
124
-
125
- /**
126
- * Type-safe helper for authoring `smrt.config.js` files.
127
- *
128
- * This is an identity function — it returns its argument unchanged. Its sole
129
- * purpose is to provide TypeScript type-checking and IDE auto-completion when
130
- * writing the config object literal.
131
- *
132
- * @param config - The config object to validate against {@link SmrtConfig}.
133
- * @returns The same object, unchanged.
134
- *
135
- * @example
136
- * ```js
137
- * // smrt.config.js
138
- * import { defineConfig } from '@happyvertical/smrt-config';
139
- *
140
- * export default defineConfig({
141
- * smrt: { logLevel: 'info' },
142
- * site: { name: 'My Site', ... },
143
- * });
144
- * ```
145
- *
146
- * @see {@link SmrtConfig}
147
- * @see {@link loadConfig}
148
- */
149
- export declare function defineConfig(config: SmrtConfig): SmrtConfig;
150
-
151
- /**
152
- * Export configuration for static site generation.
153
- *
154
- * Placed under the `export` key in `smrt.config.js`. Controls how database
155
- * records are exported to static files during SSG builds. Each additional
156
- * key beyond `fieldExportDefault` and `format` defines a named export file.
157
- *
158
- * @example
159
- * ```js
160
- * export default defineConfig({
161
- * export: {
162
- * fieldExportDefault: true,
163
- * articles: { types: ['Article'], filters: { status: ['published'] } },
164
- * games: { types: ['Game'], orderBy: '-date', format: 'ndjson' },
165
- * },
166
- * });
167
- * ```
168
- *
169
- * @see {@link ExportFileConfig}
170
- * @see {@link exportConfig}
171
- */
172
- export declare interface ExportConfig {
173
- /**
174
- * Default export behavior for fields without explicit `exported` annotation
175
- *
176
- * - true: Export all fields by default (simpler, for most sites)
177
- * - false: Only export fields with explicit `exported: true`
178
- *
179
- * @default true
180
- */
181
- fieldExportDefault?: boolean;
182
- /**
183
- * Default output format for all exports
184
- * @default 'json'
185
- */
186
- format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
187
- /**
188
- * Export file configurations
189
- * Keys become filenames (e.g., 'contents' -> 'contents.json')
190
- */
191
- [filename: string]: ExportFileConfig | boolean | string | undefined;
192
- }
193
-
194
- /**
195
- * Serialize a configuration object to a formatted string for SSG file output.
196
- *
197
- * By default, {@link sanitizeConfig} is applied before serialization to strip
198
- * any keys that match secret patterns (API keys, passwords, tokens, etc.).
199
- * Pass `includeSecrets: true` only in secured server-side contexts.
200
- *
201
- * @param config - Configuration object to export. Any JSON-serializable value.
202
- * @param options - Format, indentation, and secret-inclusion options.
203
- * @returns A JSON string, or an ES module string (`export default {...};\n`)
204
- * when `format: 'js'`.
205
- *
206
- * @example
207
- * ```ts
208
- * // Write a sanitized JSON export file for SSG
209
- * const json = exportConfig(agentConfig);
210
- * await fs.writeFile('./public/config.json', json);
211
- * ```
212
- *
213
- * @example
214
- * ```ts
215
- * // ES module format (importable via `import config from './config.js'`)
216
- * const js = exportConfig(agentConfig, { format: 'js' });
217
- * ```
218
- *
219
- * @see {@link sanitizeConfig}
220
- * @see {@link parseExportedConfig}
221
- * @see {@link ExportConfigOptions}
222
- */
223
- export declare function exportConfig(config: unknown, options?: ExportConfigOptions): string;
224
-
225
- /**
226
- * Options accepted by {@link exportConfig}.
227
- */
228
- export declare interface ExportConfigOptions {
229
- /**
230
- * Include secrets in the export (use with caution!)
231
- * @default false
232
- */
233
- includeSecrets?: boolean;
234
- /**
235
- * Output format
236
- * - 'json': Plain JSON format
237
- * - 'js': ES module format (export default)
238
- * @default 'json'
239
- */
240
- format?: 'json' | 'js';
241
- /**
242
- * Number of spaces for indentation
243
- * @default 2
244
- */
245
- indent?: number;
246
- }
247
-
248
- /**
249
- * Configuration for a single SSG export file.
250
- *
251
- * Each key in {@link ExportConfig} (besides `fieldExportDefault` and `format`)
252
- * becomes the output filename. Records are queried from the database, filtered,
253
- * ordered, and written to `{key}.json` (or the specified format).
254
- *
255
- * @example
256
- * ```js
257
- * export default defineConfig({
258
- * export: {
259
- * articles: {
260
- * types: ['Article'],
261
- * filters: { status: ['published'] },
262
- * orderBy: '-publishDate',
263
- * limit: 500,
264
- * },
265
- * },
266
- * });
267
- * ```
268
- *
269
- * @see {@link ExportConfig}
270
- * @see {@link ExportFilterValue}
271
- */
272
- export declare interface ExportFileConfig {
273
- /**
274
- * SMRT object types to include in this export
275
- * Uses className (e.g., 'MeetingRecap', 'Game')
276
- */
277
- types: string[];
278
- /**
279
- * Field whitelist - only export these fields
280
- * If specified, overrides exclude and fieldExportDefault
281
- */
282
- include?: string[];
283
- /**
284
- * Field blacklist - exclude these fields
285
- * Applied after schema-level exported: false check
286
- */
287
- exclude?: string[];
288
- /**
289
- * Filters to apply when querying records
290
- * Keys are field names, values are filter conditions
291
- *
292
- * @example
293
- * filters: {
294
- * status: ['published'], // shorthand for status IN ('published')
295
- * publish_date: { gte: '2025-01-01' },
296
- * council_slug: ['town-of-bentley'],
297
- * }
298
- */
299
- filters?: Record<string, string[] | number[] | ExportFilterValue>;
300
- /**
301
- * Output format for this file
302
- * @default 'json'
303
- */
304
- format?: 'json' | 'ndjson' | 'csv' | 'sqlite';
305
- /**
306
- * Field to order by
307
- * Prefix with '-' for descending (e.g., '-publish_date')
308
- */
309
- orderBy?: string;
310
- /**
311
- * Maximum records per file
312
- * If exceeded, creates paginated files (e.g., contents-1.json, contents-2.json)
313
- */
314
- limit?: number;
315
- /**
316
- * Create separate files per unique value of this field
317
- * e.g., shardBy: 'year' creates contents-2024.json, contents-2025.json
318
- */
319
- shardBy?: string;
320
- }
321
-
322
- /**
323
- * Filter operators for export queries.
324
- *
325
- * Used as values in {@link ExportFileConfig.filters} to build SQL `WHERE`
326
- * clauses when exporting records to static files.
327
- *
328
- * @example
329
- * ```js
330
- * filters: {
331
- * publishDate: { gte: '2025-01-01', lt: '2026-01-01' },
332
- * status: { in: ['published', 'featured'] },
333
- * }
334
- * ```
335
- *
336
- * @see {@link ExportFileConfig}
337
- */
338
- export declare interface ExportFilterValue {
339
- /** Equals (shorthand: just the value) */
340
- eq?: string | number | boolean;
341
- /** Not equals */
342
- ne?: string | number | boolean;
343
- /** Greater than */
344
- gt?: string | number;
345
- /** Greater than or equal */
346
- gte?: string | number;
347
- /** Less than */
348
- lt?: string | number;
349
- /** Less than or equal */
350
- lte?: string | number;
351
- /** In array */
352
- in?: (string | number)[];
353
- /** Contains (text) */
354
- contains?: string;
355
- }
356
-
357
- /** Return a fresh copy of the documented preset for inspection and tooling. */
358
- export declare function getApplicationRuntimePreset(profile: ApplicationRuntimeProfile): Readonly<RuntimeProviders>;
359
-
360
- /**
361
- * Return the loaded file configuration synchronously.
362
- *
363
- * Reads from `globalThis.__smrtConfigCache` without triggering a file search.
364
- * Returns `null` when {@link loadConfig} has not been called yet (or after
365
- * {@link clearCache} resets the cache).
366
- *
367
- * @returns The cached {@link SmrtConfig}, or `null` if not yet loaded.
368
- *
369
- * @example
370
- * ```ts
371
- * const config = getConfig();
372
- * if (config?.smrt?.logLevel === 'debug') {
373
- * console.log('Debug logging enabled');
374
- * }
375
- * ```
376
- *
377
- * @see {@link loadConfig}
378
- * @see {@link resolveConfiguredApplicationRuntime}
379
- * @see {@link getSiteConfig}
380
- * @see {@link getModuleConfig}
381
- */
382
- export declare function getConfig(): SmrtConfig | null;
383
-
384
- /**
385
- * Return the resolved configuration for a named module.
386
- *
387
- * Merges four layers in ascending priority order:
388
- * 1. `defaults` (caller-supplied fallbacks)
389
- * 2. Global `smrt` section of the loaded config
390
- * 3. `modules[moduleName]` section of the loaded config
391
- * 4. Runtime `modules[moduleName]` overrides set via {@link setConfig}
392
- *
393
- * Works synchronously — call {@link loadConfig} first to populate the cache.
394
- * If no config has been loaded, only `defaults` are returned.
395
- *
396
- * @param moduleName - Key in `config.modules` (e.g., `'praeco'`).
397
- * @param defaults - Optional fallback values used when a key is absent from all
398
- * higher-priority layers.
399
- * @returns The fully merged module config typed as `T`.
400
- *
401
- * @example
402
- * ```ts
403
- * const config = getModuleConfig('praeco', {
404
- * rssLimit: 50,
405
- * fetchTimeout: 10_000,
406
- * });
407
- * // config.rssLimit may be overridden by smrt.config.js or setConfig()
408
- * ```
409
- *
410
- * @see {@link getPackageConfig}
411
- * @see {@link setConfig}
412
- * @see {@link SmrtConfig.modules}
413
- */
414
- export declare function getModuleConfig<T extends Record<string, unknown>>(moduleName: string, defaults?: T): T;
415
-
416
- /**
417
- * Return the resolved configuration for a named package.
418
- *
419
- * Identical to {@link getModuleConfig} but reads from `config.packages` instead
420
- * of `config.modules`. Use this inside `@happyvertical/smrt-*` packages that
421
- * want to expose their own config section without conflicting with user-defined
422
- * module names.
423
- *
424
- * Merges four layers in ascending priority order:
425
- * 1. `defaults` (caller-supplied fallbacks)
426
- * 2. Global `smrt` section of the loaded config
427
- * 3. `packages[packageName]` section of the loaded config
428
- * 4. Runtime `packages[packageName]` overrides set via {@link setConfig}
429
- *
430
- * @param packageName - Key in `config.packages` (e.g., `'ai'`, `'spider'`).
431
- * @param defaults - Optional fallback values.
432
- * @returns The fully merged package config typed as `T`.
433
- *
434
- * @example
435
- * ```ts
436
- * // Inside @happyvertical/smrt-ai package
437
- * const config = getPackageConfig('ai', {
438
- * defaultModel: 'gpt-4o-mini',
439
- * maxTokens: 2048,
440
- * });
441
- * ```
442
- *
443
- * @see {@link getModuleConfig}
444
- * @see {@link setConfig}
445
- * @see {@link SmrtConfig.packages}
446
- */
447
- export declare function getPackageConfig<T extends Record<string, unknown>>(packageName: string, defaults?: T): T;
448
-
449
- /**
450
- * Return the current runtime configuration override store.
451
- *
452
- * Used internally by {@link getModuleConfig} and {@link getPackageConfig} to
453
- * layer runtime overrides on top of file-based config. Prefer those helpers
454
- * for reading config; this is a low-level accessor.
455
- *
456
- * @returns The accumulated runtime config partial.
457
- */
458
- export declare function getRuntimeConfig(): Partial<SmrtConfig>;
459
-
460
- /**
461
- * Return the `site` section of the loaded configuration.
462
- *
463
- * Equivalent to `getConfig()?.site ?? null`. Returns `null` both when no
464
- * config has been loaded and when the loaded config has no `site` key.
465
- *
466
- * @returns The {@link SiteConfig} object, or `null` if not defined.
467
- *
468
- * @example
469
- * ```ts
470
- * const site = getSiteConfig();
471
- * const title = site?.name ?? 'Untitled Site';
472
- * ```
473
- *
474
- * @see {@link SiteConfig}
475
- * @see {@link getConfig}
476
- */
477
- export declare function getSiteConfig(): SiteConfig | null;
478
-
479
- export declare type JobTopology = 'inline' | 'embedded' | 'external' | 'scalable';
480
-
481
- /**
482
- * Load and parse configuration from the project root.
483
- *
484
- * Searches for `smrt.config.{js,mjs,cjs,json}` starting from the current
485
- * working directory and walking up the tree (unless `searchParents: false`).
486
- * The result is stored in `globalThis.__smrtConfigCache` so every module in
487
- * the process — including pnpm workspace packages loaded from different paths
488
- * — sees the same instance.
489
- *
490
- * Must be called before {@link getConfig}, {@link getModuleConfig}, or
491
- * {@link getPackageConfig} return meaningful values (they fall back to an
492
- * empty config if called before loading).
493
- *
494
- * @param options - Optional search path, parent traversal, and cache control.
495
- * @returns The parsed {@link SmrtConfig}. Returns `{}` if no file is found.
496
- *
497
- * @example
498
- * ```ts
499
- * // Typical app startup
500
- * import { loadConfig } from '@happyvertical/smrt-config';
501
- * await loadConfig();
502
- * ```
503
- *
504
- * @example
505
- * ```ts
506
- * // Load a specific file (tests / scripts)
507
- * const config = await loadConfig({ configPath: './fixtures/smrt.config.js', cache: false });
508
- * ```
509
- *
510
- * @see {@link getConfig}
511
- * @see {@link clearCache}
512
- * @see {@link LoadConfigOptions}
513
- */
514
- export declare function loadConfig(options?: LoadConfigOptions): Promise<SmrtConfig>;
515
-
516
- /**
517
- * Options accepted by {@link loadConfig}.
518
- *
519
- * All fields are optional; omitting them triggers cosmiconfig's default
520
- * search behaviour (scan `cwd` upward for `smrt.config.{js,mjs,cjs,json}`).
521
- */
522
- export declare interface LoadConfigOptions {
523
- /**
524
- * Absolute or relative path to a specific config file.
525
- * When provided, cosmiconfig loads this file directly instead of searching.
526
- */
527
- configPath?: string;
528
- /**
529
- * Whether to search parent directories when no config is found in `cwd`.
530
- *
531
- * @default true
532
- */
533
- searchParents?: boolean;
534
- /**
535
- * Directory to start the config search from. Defaults to `process.cwd()`.
536
- * Ignored when `configPath` is provided. Useful for tests and for tools that
537
- * resolve config relative to a project root other than the current directory.
538
- */
539
- searchFrom?: string;
540
- /**
541
- * Whether to cache the loaded config in `globalThis.__smrtLoaderCachedConfig`.
542
- * Disable for test isolation or hot-reload scenarios.
543
- *
544
- * @default true
545
- */
546
- cache?: boolean;
547
- }
548
-
549
- /**
550
- * Merge three config layers in ascending priority order.
551
- *
552
- * Priority (highest to lowest):
553
- * 1. `runtime` — runtime overrides set via {@link setConfig}
554
- * 2. `fileConfig` — values loaded from `smrt.config.js`
555
- * 3. `defaults` — caller-supplied fallback values
556
- *
557
- * Uses {@link deepMerge} internally, so `null` / `undefined` source values
558
- * never overwrite existing target values.
559
- *
560
- * @param defaults - Lowest-priority base values (caller defaults).
561
- * @param fileConfig - Mid-priority values from the loaded config file.
562
- * @param runtime - Highest-priority runtime override values.
563
- * @returns A new object with all three layers merged.
564
- *
565
- * @example
566
- * ```ts
567
- * const merged = mergeConfigs(
568
- * { timeout: 5000, retries: 3 },
569
- * { retries: 5 },
570
- * { timeout: 1000 },
571
- * );
572
- * // => { timeout: 1000, retries: 5 }
573
- * ```
574
- */
575
- export declare function mergeConfigs<T extends Record<string, unknown>>(defaults: T, fileConfig: Partial<T>, runtime: Partial<T>): T;
576
-
577
- /**
578
- * Shallow-merge an exported (DB-backed) config into a base (file-backed) config.
579
- *
580
- * Object values are deep-merged recursively. Primitive values and arrays from
581
- * `exportedConfig` replace their counterparts in `baseConfig`. This is a
582
- * one-level-smarter spread that lets file-based env overrides win when placed
583
- * after the spread.
584
- *
585
- * Intended for the SSG pattern where an agent exports its runtime config to a
586
- * static JSON file and `smrt.config.js` imports it as a base:
587
- *
588
- * @example
589
- * ```js
590
- * // smrt.config.js
591
- * import exported from './smrt.exported.json' with { type: 'json' };
592
- *
593
- * export default defineConfig({
594
- * modules: {
595
- * praeco: mergeExportedConfig(exported, {
596
- * apiEndpoint: process.env.API_URL, // env override wins
597
- * }),
598
- * },
599
- * });
600
- * ```
601
- *
602
- * @param baseConfig - Lower-priority base (typically from the DB export file).
603
- * @param exportedConfig - Higher-priority overrides (typically env / file-based).
604
- * @returns A new merged object of type `T`.
605
- *
606
- * @see {@link exportConfig}
607
- * @see {@link parseExportedConfig}
608
- */
609
- export declare function mergeExportedConfig<T extends Record<string, unknown>>(baseConfig: T, exportedConfig: Partial<T>): T;
610
-
611
- /**
612
- * Database migrations configuration.
613
- *
614
- * Controls how migrations are generated, stored, and applied. Placed under
615
- * the `cli.migrations` key in `smrt.config.js` and consumed by
616
- * `@happyvertical/smrt-cli` migration commands (`smrt db:migrate`, etc.).
617
- *
618
- * @see {@link CliConfig}
619
- */
620
- export declare interface MigrationsConfig {
621
- /**
622
- * Directory for migration files (relative to project root)
623
- *
624
- * @default './migrations'
625
- */
626
- directory?: string;
627
- /**
628
- * Table name for tracking applied migrations
629
- *
630
- * @default '_smrt_schema_migrations'
631
- */
632
- table?: string;
633
- /**
634
- * Legacy file format setting. File-backed migration generation is not supported.
635
- *
636
- * @default 'sql'
637
- */
638
- format?: 'sql' | 'typescript';
639
- /**
640
- * Migration file naming strategy
641
- *
642
- * - 'sequence': Sequential numbers (0001, 0002, ...)
643
- * - 'timestamp': Unix timestamp-based (20240115143052)
644
- *
645
- * @default 'sequence'
646
- */
647
- naming?: 'sequence' | 'timestamp';
648
- /**
649
- * Migration mode.
650
- *
651
- * SMRT schema migrations are manifest-driven. File-backed modes are not
652
- * supported unless a future file migration executor is implemented.
653
- *
654
- * @default 'dynamic'
655
- */
656
- mode?: 'dynamic';
657
- /**
658
- * Configure mode per environment.
659
- *
660
- * Overrides the `mode` setting based on NODE_ENV
661
- */
662
- modeByEnvironment?: {
663
- development?: 'dynamic';
664
- test?: 'dynamic';
665
- staging?: 'dynamic';
666
- production?: 'dynamic';
667
- };
668
- /**
669
- * Automatically generate DOWN scripts where safe
670
- *
671
- * Some operations (DROP COLUMN) may lose data and should be reviewed.
672
- *
673
- * @default true
674
- */
675
- autoGenerateDown?: boolean;
676
- /**
677
- * PostgreSQL-specific settings
678
- */
679
- postgres?: MigrationsPostgresConfig;
680
- }
681
-
682
- /**
683
- * PostgreSQL-specific migration settings.
684
- *
685
- * Nested under `migrations.postgres` in {@link MigrationsConfig}.
686
- */
687
- export declare interface MigrationsPostgresConfig {
688
- /**
689
- * Allow `CREATE INDEX CONCURRENTLY` when concurrent-index mode is requested
690
- * with `smrt db:migrate --postgres-safe`.
691
- *
692
- * Concurrent builds avoid the batch's table locks but cannot run inside a
693
- * transaction, so that mode is not atomic. Setting this to `false` vetoes
694
- * the flag: index DDL then stays inside the atomic transaction, still bounded
695
- * by the timeouts below. The flag is the opt-in — this key alone does not
696
- * enable concurrent mode.
697
- *
698
- * @default true
699
- */
700
- useConcurrently?: boolean;
701
- /**
702
- * `lock_timeout` applied to every PostgreSQL migration statement.
703
- *
704
- * Accepts a bare millisecond count or an `ms`/`s`/`min`/`h` suffix. `'0'`
705
- * disables the timeout, as PostgreSQL defines it.
706
- *
707
- * @default '30s'
708
- */
709
- lockTimeout?: string;
710
- /**
711
- * `statement_timeout` applied to every PostgreSQL migration statement.
712
- *
713
- * Same accepted forms as {@link MigrationsPostgresConfig.lockTimeout}.
714
- *
715
- * @default '60s'
716
- */
717
- statementTimeout?: string;
718
- }
719
-
720
- export declare type NetworkExposure = 'loopback' | 'public';
721
-
722
- export declare type OwnerBootstrapMode = 'single-use' | 'disabled';
723
-
724
- /**
725
- * Parse a config string previously produced by {@link exportConfig} back into
726
- * a plain JavaScript object.
727
- *
728
- * Handles both output formats:
729
- * - **JSON** — standard `JSON.parse`.
730
- * - **JS module** — strips the `export default` prefix and trailing semicolon
731
- * before parsing as JSON.
732
- *
733
- * Throws a `SyntaxError` if the content is not valid JSON after stripping.
734
- *
735
- * @param content - Exported config string (`'json'` or `'js'` format).
736
- * @returns Parsed configuration value.
737
- *
738
- * @example
739
- * ```ts
740
- * const raw = await fs.readFile('./smrt.exported.json', 'utf8');
741
- * const config = parseExportedConfig(raw);
742
- * ```
743
- *
744
- * @see {@link exportConfig}
745
- * @see {@link mergeExportedConfig}
746
- */
747
- export declare function parseExportedConfig(content: string): unknown;
748
-
749
- /** PostgreSQL ACL contract. Applied only through explicit db:permissions. */
750
- export declare interface PostgresPermissionsConfig {
751
- schema: string;
752
- /** Assert this schema is dedicated to the managed application. */
753
- schemaExclusive: true;
754
- migrationOwner: string;
755
- runtimeRole: string;
756
- /** Additional managed tables beyond discovered models and present system tables. */
757
- managedTables?: string[];
758
- /** Existing operator-owned tables retained outside the runtime data surface. */
759
- retainedTables?: string[];
760
- /** Exact zero-argument trigger functions bound only to managed tables. */
761
- managedTriggerFunctions?: string[];
762
- /** Explicit safe monitoring columns; there is no default table-wide access. */
763
- monitor?: {
764
- role: string;
765
- tables: Record<string, string[]>;
766
- };
767
- }
768
-
769
- /**
770
- * Resolve a safe preset and explicit provider overrides into a stable snapshot.
771
- *
772
- * The resolver is pure: it reads no environment variables, paths, credentials,
773
- * clocks, or process state. Invalid and unknown fields fail before startup.
774
- */
775
- export declare function resolveApplicationRuntime(config: ApplicationRuntimeConfig): Readonly<ResolvedApplicationRuntime>;
776
-
777
- /**
778
- * Resolve the effective application runtime using the documented config
779
- * priority: runtime overrides set by {@link setConfig} > loaded file config >
780
- * profile defaults.
781
- *
782
- * This accessor is intentionally separate from {@link getConfig}, whose legacy
783
- * contract returns the loaded file object only. When a runtime override selects
784
- * a different profile, lower-priority provider overrides are discarded so they
785
- * cannot leak profile-specific choices (for example local files or inline jobs)
786
- * into the new profile. Provider overrides still deep-merge when the profile is
787
- * unchanged.
788
- *
789
- * @returns A validated, deterministic, secret-free runtime snapshot.
790
- * @throws {RuntimeProfileValidationError} When no profile is configured or the
791
- * effective provider composition violates a profile invariant.
792
- */
793
- export declare function resolveConfiguredApplicationRuntime(): Readonly<ResolvedApplicationRuntime>;
794
-
795
- /** Deterministic, secret-free runtime diagnostic snapshot. */
796
- export declare interface ResolvedApplicationRuntime {
797
- readonly schemaVersion: 1;
798
- readonly profile: ApplicationRuntimeProfile;
799
- readonly providers: RuntimeProviders;
800
- readonly capabilities: RuntimeCapabilities;
801
- readonly invariants: RuntimeInvariants;
802
- readonly diagnostics: {
803
- readonly secretValuesIncluded: false;
804
- readonly overrides: readonly RuntimeOverrideReport[];
805
- readonly unsafeOverrides: readonly [];
806
- };
807
- }
808
-
809
- export declare interface RuntimeAssetProvider {
810
- readonly provider: AssetStorageProvider;
811
- readonly ownership: AssetOwnership;
812
- }
813
-
814
- export declare interface RuntimeAuthenticationProvider {
815
- readonly provider: AuthenticationProvider;
816
- readonly ownerBootstrap: OwnerBootstrapMode;
817
- }
818
-
819
- /** Derived capabilities used by startup, doctor, tests, and agent inspection. */
820
- export declare interface RuntimeCapabilities {
821
- readonly ownerBootstrap: boolean;
822
- readonly publicAuthentication: boolean;
823
- readonly defaultTenant: boolean;
824
- readonly multiTenant: boolean;
825
- readonly localAssets: boolean;
826
- readonly externalWorkers: boolean;
827
- readonly backup: true;
828
- readonly logicalExport: true;
829
- readonly logicalImport: true;
830
- readonly diagnostics: true;
831
- readonly orchestrationHealth: boolean;
832
- }
833
-
834
- export declare interface RuntimeDatabaseProvider {
835
- readonly engine: DatabaseEngine;
836
- readonly connectionOwnership: ConnectionOwnership;
837
- }
838
-
839
- /** Behaviors that provider/profile selection is never allowed to change. */
840
- export declare interface RuntimeInvariants {
841
- readonly domainModels: 'identical';
842
- readonly generatedRest: 'identical';
843
- readonly generatedCli: 'identical';
844
- readonly generatedMcp: 'identical';
845
- readonly generatedWebMcp: 'identical';
846
- readonly mcpExposurePolicy: 'identical';
847
- readonly webMcpExposurePolicy: 'identical';
848
- readonly actionEffects: 'identical';
849
- readonly approvalPolicy: 'identical';
850
- readonly authorizationRecords: 'required';
851
- readonly jobInvocation: 'identical';
852
- readonly portability: 'logical-export-import';
853
- }
854
-
855
- export declare interface RuntimeJobProvider {
856
- readonly topology: JobTopology;
857
- }
858
-
859
- export declare interface RuntimeNetworkProvider {
860
- readonly exposure: NetworkExposure;
861
- readonly tls: boolean;
862
- }
863
-
864
- export declare interface RuntimeOverrideReport {
865
- readonly path: string;
866
- readonly from: string | boolean;
867
- readonly to: string | boolean;
868
- }
869
-
870
- export declare interface RuntimePortabilityProvider {
871
- readonly backup: BackupProvider;
872
- readonly logicalExport: true;
873
- readonly logicalImport: true;
874
- }
875
-
876
- /** Aggregates deterministic, actionable failures before application startup. */
877
- export declare class RuntimeProfileValidationError extends Error {
878
- readonly issues: readonly RuntimeProfileValidationIssue[];
879
- constructor(issues: RuntimeProfileValidationIssue[]);
880
- }
881
-
882
- export declare interface RuntimeProfileValidationIssue {
883
- code: 'invalid_config' | 'unsupported_field' | 'incompatible_provider';
884
- path: string;
885
- message: string;
886
- recovery: string;
887
- }
888
-
889
- /**
890
- * Explicit provider changes layered over a profile's safe preset.
891
- *
892
- * Every override is revalidated with the completed composition. Capability and
893
- * surface-policy fields are intentionally absent: providers cannot use this
894
- * seam to weaken cross-profile invariants.
895
- */
896
- export declare interface RuntimeProviderOverrides {
897
- database?: Partial<RuntimeDatabaseProvider>;
898
- authentication?: Partial<RuntimeAuthenticationProvider>;
899
- tenancy?: Partial<RuntimeTenancyProvider>;
900
- assets?: Partial<RuntimeAssetProvider>;
901
- secrets?: Partial<RuntimeSecretProvider>;
902
- jobs?: Partial<RuntimeJobProvider>;
903
- network?: Partial<RuntimeNetworkProvider>;
904
- }
905
-
906
- /** Fully selected infrastructure providers for an application runtime. */
907
- export declare interface RuntimeProviders {
908
- readonly database: RuntimeDatabaseProvider;
909
- readonly authentication: RuntimeAuthenticationProvider;
910
- readonly tenancy: RuntimeTenancyProvider;
911
- readonly assets: RuntimeAssetProvider;
912
- readonly secrets: RuntimeSecretProvider;
913
- readonly jobs: RuntimeJobProvider;
914
- readonly network: RuntimeNetworkProvider;
915
- readonly portability: RuntimePortabilityProvider;
916
- }
917
-
918
- export declare interface RuntimeSecretProvider {
919
- readonly provider: SecretProvider;
920
- readonly ownership: SecretOwnership;
921
- }
922
-
923
- export declare interface RuntimeTenancyProvider {
924
- readonly mode: TenancyMode;
925
- readonly context: TenantContextMode;
926
- readonly isolation: TenantIsolation;
927
- }
928
-
929
- /**
930
- * Config export utilities for static site generation
931
- *
932
- * These utilities enable exporting database-backed agent configurations
933
- * to static files for SSG sites.
934
- *
935
- * @module
936
- */
937
- /**
938
- * Deep-clone a config object, removing every key that looks like a secret.
939
- *
940
- * Keys are tested (case-insensitively, across camelCase / snake_case / kebab /
941
- * UPPER variants) against {@link SECRET_PATTERNS}, which cover secrets such as
942
- * `apiKey`/`api_key`, `password`, `secret`, `token`, `credential`, `private`,
943
- * `auth`/`authorization`/`oauth`, `accessKey`, `signingKey`, `encryptionKey`,
944
- * `connectionString`, and `dbUrl`. The policy biases toward over-redaction
945
- * because these exports are typically published as static, publicly served
946
- * assets — see {@link SECRET_PATTERNS} for the full rationale.
947
- *
948
- * Nested objects are recursively sanitized; arrays are mapped element-by-element.
949
- * `number` / `boolean` primitives pass through unchanged; `string` values are
950
- * additionally run through value-level redaction that masks credentials embedded
951
- * in a URL (`scheme://user:pass@host` → `scheme://***@host`) as well as
952
- * high-confidence secret-token shapes pasted into otherwise-benign keys
953
- * (OpenAI/Anthropic `sk-...`, AWS `AKIA...` access key IDs, GitHub/Slack/Google
954
- * tokens, `Bearer ...` headers, and PEM private-key blocks) — catching secrets
955
- * stored under a benign key the key-based patterns don't match.
956
- *
957
- * Own `__proto__` / `constructor` / `prototype` keys are dropped to prevent the
958
- * cloned result's prototype from being reassigned via the `__proto__` setter.
959
- *
960
- * This function is called automatically by {@link exportConfig} unless
961
- * `includeSecrets: true` is passed.
962
- *
963
- * @param config - Value to sanitize. Accepts any JSON-serializable structure.
964
- * @returns A new value with all secret keys omitted. `null` / `undefined` are
965
- * returned as-is.
966
- *
967
- * @example
968
- * ```ts
969
- * const sanitized = sanitizeConfig({
970
- * apiEndpoint: 'https://api.example.com',
971
- * apiKey: 'sk-secret-123',
972
- * nested: { password: 'hunter2', name: 'test' },
973
- * });
974
- * // => { apiEndpoint: 'https://api.example.com', nested: { name: 'test' } }
975
- * ```
976
- *
977
- * @see {@link exportConfig}
978
- */
979
- export declare function sanitizeConfig(config: unknown): unknown;
980
-
981
- /**
982
- * Semantic schema contract enforced by SMRT schema commands.
983
- *
984
- * Object and field requirements are checked against the loaded SMRT registry.
985
- * Required fields are also translated to physical table/column checks after
986
- * migration/status introspection. `requiredDatabaseShape` is reserved for
987
- * database objects that SMRT cannot infer from manifests.
988
- */
989
- export declare interface SchemaContractConfig {
990
- requiredObjects?: string[];
991
- requiredFields?: string[];
992
- requiredDatabaseShape?: {
993
- tables?: string[];
994
- columns?: string[];
995
- indexes?: string[];
996
- };
997
- }
998
-
999
- export declare type SecretOwnership = 'user' | 'operator' | 'managed';
1000
-
1001
- export declare type SecretProvider = 'local-file' | 'environment' | 'external' | 'managed';
1002
-
1003
- /**
1004
- * Apply runtime configuration overrides.
1005
- *
1006
- * Deep-merges `config` into an in-memory store that takes the highest priority
1007
- * in every subsequent {@link getModuleConfig} / {@link getPackageConfig} call.
1008
- * Successive calls accumulate. When a call explicitly changes the runtime
1009
- * profile, the stored runtime provider subtree is reset before merging so
1010
- * profile-specific selectors cannot leak into the new profile.
1011
- *
1012
- * Common uses:
1013
- * - Inject test doubles or environment-specific values without a config file.
1014
- * - Apply feature flags from a remote source after startup.
1015
- *
1016
- * @param config - Partial {@link SmrtConfig} to merge into the runtime store.
1017
- * `null` values are ignored (they do not clear existing keys).
1018
- *
1019
- * @example
1020
- * ```ts
1021
- * setConfig({ modules: { ai: { defaultModel: 'gpt-4o' } } });
1022
- * ```
1023
- *
1024
- * @see {@link clearCache}
1025
- * @see {@link getModuleConfig}
1026
- */
1027
- export declare function setConfig(config: Partial<SmrtConfig>): void;
1028
-
1029
- /**
1030
- * Site identity and configuration for SMRT site templates.
1031
- *
1032
- * Placed under the `site` key in `smrt.config.js`. Retrieved at runtime
1033
- * via {@link getSiteConfig}. Used by site templates
1034
- * (`template-sveltekit`, `template-site-static-json`) to define name,
1035
- * description, navigation, location, and theme.
1036
- *
1037
- * @example
1038
- * ```js
1039
- * export default defineConfig({
1040
- * site: {
1041
- * name: 'Bentley Alberta',
1042
- * description: 'Community news for Bentley, AB',
1043
- * url: 'https://bentley.ca',
1044
- * location: { name: 'Bentley', latitude: 52.4, longitude: -113.9, timezone: 'America/Edmonton' },
1045
- * navigation: { primary: [{ label: 'Home', href: '/' }] },
1046
- * },
1047
- * });
1048
- * ```
1049
- *
1050
- * @see {@link getSiteConfig}
1051
- * @see {@link SiteLocation}
1052
- * @see {@link SiteNavigation}
1053
- * @see {@link SiteTheme}
1054
- */
1055
- export declare interface SiteConfig {
1056
- /** Full site name (e.g., "Bentley Alberta") */
1057
- name: string;
1058
- /** Short name for mobile/compact displays */
1059
- shortName?: string;
1060
- /** Site description for SEO */
1061
- description: string;
1062
- /** Production URL */
1063
- url?: string;
1064
- /** Contact email for the site */
1065
- contactEmail?: string;
1066
- /** Publisher/organization info */
1067
- publisher?: SitePublisher;
1068
- /** Geographic location */
1069
- location: SiteLocation;
1070
- /** Navigation structure */
1071
- navigation: SiteNavigation;
1072
- /** Theme/branding */
1073
- theme?: SiteTheme;
1074
- /** Additional metadata */
1075
- meta?: {
1076
- /** Theme color for mobile browsers */
1077
- themeColor?: string;
1078
- /** Open Graph locale */
1079
- ogLocale?: string;
1080
- /** Google Tag Manager ID */
1081
- gtmId?: string;
1082
- };
1083
- }
1084
-
1085
- /**
1086
- * Geographic location for the site, used for proximity search and display.
1087
- *
1088
- * @see {@link SiteConfig}
1089
- */
1090
- export declare interface SiteLocation {
1091
- /** Display name (e.g., "Bentley" or "Bentley, AB") */
1092
- name: string;
1093
- /** Latitude coordinate */
1094
- latitude: number;
1095
- /** Longitude coordinate */
1096
- longitude: number;
1097
- /** IANA timezone (e.g., "America/Edmonton") */
1098
- timezone: string;
1099
- }
1100
-
1101
- /**
1102
- * Site navigation structure containing primary and optional footer links.
1103
- *
1104
- * @see {@link SiteConfig}
1105
- * @see {@link SiteNavigationLink}
1106
- */
1107
- export declare interface SiteNavigation {
1108
- /** Primary navigation links (header) */
1109
- primary: SiteNavigationLink[];
1110
- /** Footer navigation links */
1111
- footer?: SiteNavigationLink[];
1112
- }
1113
-
1114
- /**
1115
- * A single navigation link item used in site menus.
1116
- *
1117
- * @see {@link SiteNavigation}
1118
- */
1119
- export declare interface SiteNavigationLink {
1120
- label: string;
1121
- href: string;
1122
- icon?: string;
1123
- }
1124
-
1125
- /**
1126
- * Publisher or organization information displayed in site footers and metadata.
1127
- *
1128
- * @see {@link SiteConfig}
1129
- */
1130
- export declare interface SitePublisher {
1131
- /** Organization name (e.g., "Blindman Press") */
1132
- name: string;
1133
- /** Organization website URL */
1134
- url?: string;
1135
- /** GitHub organization URL */
1136
- github?: string;
1137
- }
1138
-
1139
- /**
1140
- * Site theme and branding color palette.
1141
- *
1142
- * Colors should be provided as CSS hex values (e.g., `'#3b82f6'`).
1143
- *
1144
- * @see {@link SiteConfig}
1145
- */
1146
- export declare interface SiteTheme {
1147
- /** Primary brand color (hex) */
1148
- primaryColor: string;
1149
- /** Light variant of primary color */
1150
- primaryLight?: string;
1151
- /** Dark variant of primary color */
1152
- primaryDark?: string;
1153
- }
1154
-
1155
- /**
1156
- * Root SMRT configuration structure.
1157
- *
1158
- * This is the shape of the object returned by `smrt.config.{js,ts,json}` and
1159
- * consumed by {@link loadConfig}. Use {@link defineConfig} for type-safe
1160
- * authoring with IDE auto-completion.
1161
- *
1162
- * Priority order (highest to lowest):
1163
- * 1. Runtime overrides set via {@link setConfig}
1164
- * 2. File-based config loaded by {@link loadConfig}
1165
- * 3. Defaults passed to {@link getModuleConfig} / {@link getPackageConfig}
1166
- *
1167
- * @example
1168
- * ```js
1169
- * // smrt.config.js
1170
- * import { defineConfig } from '@happyvertical/smrt-config';
1171
- *
1172
- * export default defineConfig({
1173
- * smrt: { logLevel: 'info', environment: 'production' },
1174
- * site: { name: 'My Site', ... },
1175
- * modules: { praeco: { rssLimit: 50 } },
1176
- * packages: { ai: { defaultModel: 'gpt-4o' } },
1177
- * });
1178
- * ```
1179
- *
1180
- * @see {@link loadConfig}
1181
- * @see {@link defineConfig}
1182
- * @see {@link SmrtGlobalConfig}
1183
- */
1184
- export declare interface SmrtConfig {
1185
- /** Global SMRT framework options — lowest-priority base for all modules. */
1186
- smrt?: SmrtGlobalConfig;
1187
- /** Site identity and configuration (for site templates). */
1188
- site?: SiteConfig;
1189
- /** Export configuration for static site generation. */
1190
- export?: ExportConfig;
1191
- /** Domain-scoped agent/developer knowledge generation and exposure. */
1192
- knowledge?: DomainKnowledgeConfig;
1193
- /** Validated application infrastructure composition. */
1194
- runtime?: ApplicationRuntimeConfig;
1195
- /**
1196
- * Module-scoped configurations keyed by module name.
1197
- * Retrieved via {@link getModuleConfig}.
1198
- */
1199
- modules?: {
1200
- [moduleName: string]: Record<string, unknown>;
1201
- };
1202
- /**
1203
- * Package-scoped configurations keyed by package name.
1204
- * Retrieved via {@link getPackageConfig}.
1205
- */
1206
- packages?: {
1207
- [packageName: string]: Record<string, unknown>;
1208
- };
1209
- }
1210
-
1211
- /**
1212
- * Global SMRT framework options that apply to all modules unless overridden.
1213
- *
1214
- * Placed under the `smrt` key in `smrt.config.js`. Values here propagate
1215
- * as the lowest-priority base for every `getModuleConfig()` and
1216
- * `getPackageConfig()` call.
1217
- *
1218
- * @example
1219
- * ```js
1220
- * // smrt.config.js
1221
- * export default defineConfig({
1222
- * smrt: {
1223
- * logLevel: 'debug',
1224
- * environment: 'development',
1225
- * embeddings: { provider: 'local' },
1226
- * },
1227
- * });
1228
- * ```
1229
- *
1230
- * @see {@link SmrtConfig}
1231
- * @see {@link getModuleConfig}
1232
- * @see {@link getPackageConfig}
1233
- */
1234
- export declare interface SmrtGlobalConfig {
1235
- postgresPermissions?: PostgresPermissionsConfig;
1236
- cacheDir?: string;
1237
- logLevel?: 'debug' | 'info' | 'warn' | 'error';
1238
- environment?: 'development' | 'production' | 'test';
1239
- /**
1240
- * Schema migration strategy when parent class schema changes
1241
- *
1242
- * Options:
1243
- * - 'warn': Log warning about schema mismatch, require manual migration (safest)
1244
- * - 'auto-add': Automatically ALTER TABLE to add new parent fields (default, convenient)
1245
- *
1246
- * Note: Removing columns is never automatic - always requires manual migration
1247
- *
1248
- * @default 'auto-add'
1249
- */
1250
- schemaMigration?: {
1251
- strategy?: 'warn' | 'auto-add';
1252
- };
1253
- /**
1254
- * Inheritance configuration
1255
- */
1256
- inheritance?: {
1257
- /**
1258
- * Behavior when an ancestor class is missing from the registry
1259
- *
1260
- * Options:
1261
- * - 'error': Throw an error (strict, catches bugs)
1262
- * - 'warn': Log warning and skip (lenient, default)
1263
- *
1264
- * @default 'warn'
1265
- */
1266
- onMissingAncestor?: 'error' | 'warn';
1267
- /**
1268
- * Size of LRU cache for inheritance chains and merged fields
1269
- *
1270
- * Higher values improve performance but use more memory.
1271
- * Each entry stores one inheritance chain (array of strings).
1272
- *
1273
- * @default 200
1274
- */
1275
- cacheSize?: number;
1276
- };
1277
- /**
1278
- * Embedding configuration for semantic search
1279
- *
1280
- * Project-level settings that apply to all SMRT objects
1281
- * unless overridden in the @smrt() decorator.
1282
- */
1283
- embeddings?: {
1284
- /**
1285
- * Standard dimensions for embeddings in this project
1286
- *
1287
- * All embeddings should use the same dimensions for consistency.
1288
- * Common values: 384, 768, 1536
1289
- *
1290
- * @default 768
1291
- */
1292
- dimensions?: number;
1293
- /**
1294
- * Embedding provider type
1295
- *
1296
- * - 'local': Use local Node.js model (@xenova/transformers)
1297
- * - 'ai': Use AI library (OpenAI, etc.)
1298
- * - 'auto': Try local first, fallback to AI
1299
- *
1300
- * @default 'local'
1301
- */
1302
- provider?: 'local' | 'ai' | 'auto';
1303
- /**
1304
- * Local model to use (when provider is 'local' or 'auto')
1305
- *
1306
- * Hugging Face model ID for @xenova/transformers.
1307
- * Model is downloaded on first use (~440MB for bge-base-en-v1.5).
1308
- *
1309
- * @default 'Xenova/bge-base-en-v1.5'
1310
- */
1311
- localModel?: string;
1312
- /**
1313
- * AI model to use (when provider is 'ai' or fallback)
1314
- *
1315
- * OpenAI embedding model name.
1316
- *
1317
- * @default 'text-embedding-3-small'
1318
- */
1319
- aiModel?: string;
1320
- /**
1321
- * Whether to fallback to AI if local embedding fails
1322
- *
1323
- * Only applies when provider is 'auto'.
1324
- *
1325
- * @default true
1326
- */
1327
- fallbackToAI?: boolean;
1328
- /**
1329
- * Storage mode for embeddings
1330
- *
1331
- * - 'json': Store as JSON text, in-memory similarity (works everywhere)
1332
- * - 'native': Use database vector operations when available, fallback to json
1333
- *
1334
- * @default 'json'
1335
- */
1336
- storage?: 'json' | 'native';
1337
- };
1338
- /**
1339
- * Optional typed-decision provider configuration. This is deliberately
1340
- * separate from generation configuration: configuring decisions never
1341
- * changes the client used by `do()` or `describe()`.
1342
- */
1343
- decisions?: {
1344
- /** The currently supported typed-decision provider. */
1345
- type: 'typesafe';
1346
- /** Provider credential. Prefer an environment-backed value in deployments. */
1347
- apiKey?: string;
1348
- /** Optional provider endpoint override, primarily for approved test hosts. */
1349
- baseUrl?: string;
1350
- /** Default decision model; individual evaluations may override it. */
1351
- defaultModel?: string;
1352
- /** Inclusive predicate threshold. A probability equal to it is true. */
1353
- threshold?: number;
1354
- /**
1355
- * Opt in to a generative tie-break only when the probability is inside the
1356
- * finite band centered on the threshold. Provider failures never use it.
1357
- */
1358
- uncertaintyFallback?: {
1359
- band: number;
1360
- };
1361
- };
1362
- [key: string]: unknown;
1363
- }
1364
-
1365
- export declare type TenancyMode = 'default-tenant' | 'single-tenant' | 'multi-tenant';
1366
-
1367
- export declare type TenantContextMode = 'defaulted' | 'required';
1368
-
1369
- export declare type TenantIsolation = 'application' | 'database-rls';
1370
-
1371
- export { }
1372
-
1373
-
1
+ import { type ResolvedApplicationRuntime } from './runtime-profile.js';
2
+ import type { LoadConfigOptions, SmrtConfig } from './types.js';
3
+ export { type ExportConfigOptions, exportConfig, mergeExportedConfig, parseExportedConfig, sanitizeConfig, } from './export.js';
4
+ export { clearRuntimeConfig, getRuntimeConfig, mergeConfigs } from './merge.js';
5
+ export type { ApplicationRuntimeConfig, ApplicationRuntimeProfile, AssetOwnership, AssetStorageProvider, AuthenticationProvider, BackupProvider, ConnectionOwnership, DatabaseEngine, JobTopology, NetworkExposure, OwnerBootstrapMode, ResolvedApplicationRuntime, RuntimeAssetProvider, RuntimeAuthenticationProvider, RuntimeCapabilities, RuntimeDatabaseProvider, RuntimeInvariants, RuntimeJobProvider, RuntimeNetworkProvider, RuntimeOverrideReport, RuntimePortabilityProvider, RuntimeProfileValidationIssue, RuntimeProviderOverrides, RuntimeProviders, RuntimeSecretProvider, RuntimeTenancyProvider, SecretOwnership, SecretProvider, TenancyMode, TenantContextMode, TenantIsolation, } from './runtime-profile.js';
6
+ export { getApplicationRuntimePreset, RuntimeProfileValidationError, resolveApplicationRuntime, } from './runtime-profile.js';
7
+ export type { CliConfig, DatabaseConfig, ExportConfig, ExportFileConfig, ExportFilterValue, LoadConfigOptions, MigrationsConfig, MigrationsPostgresConfig, PostgresPermissionsConfig, SchemaContractConfig, SiteConfig, SiteLocation, SiteNavigation, SiteNavigationLink, SitePublisher, SiteTheme, SmrtConfig, SmrtGlobalConfig, } from './types.js';
1374
8
  /**
1375
9
  * Extend globalThis to include our config cache properties.
1376
10
  * Using globalThis ensures all module instances share the same config,
@@ -1386,22 +20,235 @@ declare global {
1386
20
  var __smrtConfigCache: SmrtConfig | null | undefined;
1387
21
  var __smrtRuntimeConfig: Partial<SmrtConfig> | undefined;
1388
22
  }
1389
-
1390
-
1391
- declare global {
1392
- var __smrtRuntimeConfig: Partial<SmrtConfig> | undefined;
1393
- }
1394
-
1395
-
1396
23
  /**
1397
- * Extend globalThis to include loader cache properties.
1398
- * Using globalThis ensures all module instances share the same loader state,
1399
- * which is critical in monorepos where the same package can be loaded
1400
- * from different paths (e.g., pnpm store vs workspace symlink).
24
+ * Load and parse configuration from the project root.
1401
25
  *
1402
- * @see https://github.com/happyvertical/smrt/issues/543
26
+ * Searches for `smrt.config.{js,mjs,cjs,json}` starting from the current
27
+ * working directory and walking up the tree (unless `searchParents: false`).
28
+ * The result is stored in `globalThis.__smrtConfigCache` so every module in
29
+ * the process — including pnpm workspace packages loaded from different paths
30
+ * — sees the same instance.
31
+ *
32
+ * Must be called before {@link getConfig}, {@link getModuleConfig}, or
33
+ * {@link getPackageConfig} return meaningful values (they fall back to an
34
+ * empty config if called before loading).
35
+ *
36
+ * @param options - Optional search path, parent traversal, and cache control.
37
+ * @returns The parsed {@link SmrtConfig}. Returns `{}` if no file is found.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // Typical app startup
42
+ * import { loadConfig } from '@happyvertical/smrt-config';
43
+ * await loadConfig();
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * // Load a specific file (tests / scripts)
49
+ * const config = await loadConfig({ configPath: './fixtures/smrt.config.js', cache: false });
50
+ * ```
51
+ *
52
+ * @see {@link getConfig}
53
+ * @see {@link clearCache}
54
+ * @see {@link LoadConfigOptions}
1403
55
  */
1404
- declare global {
1405
- var __smrtLoaderCachedConfig: SmrtConfig | null | undefined;
1406
- var __smrtLoaderExplorer: ReturnType<typeof cosmiconfig> | null | undefined;
1407
- }
56
+ export declare function loadConfig(options?: LoadConfigOptions): Promise<SmrtConfig>;
57
+ /**
58
+ * Return the loaded file configuration synchronously.
59
+ *
60
+ * Reads from `globalThis.__smrtConfigCache` without triggering a file search.
61
+ * Returns `null` when {@link loadConfig} has not been called yet (or after
62
+ * {@link clearCache} resets the cache).
63
+ *
64
+ * @returns The cached {@link SmrtConfig}, or `null` if not yet loaded.
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * const config = getConfig();
69
+ * if (config?.smrt?.logLevel === 'debug') {
70
+ * console.log('Debug logging enabled');
71
+ * }
72
+ * ```
73
+ *
74
+ * @see {@link loadConfig}
75
+ * @see {@link resolveConfiguredApplicationRuntime}
76
+ * @see {@link getSiteConfig}
77
+ * @see {@link getModuleConfig}
78
+ */
79
+ export declare function getConfig(): SmrtConfig | null;
80
+ /**
81
+ * Resolve the effective application runtime using the documented config
82
+ * priority: runtime overrides set by {@link setConfig} > loaded file config >
83
+ * profile defaults.
84
+ *
85
+ * This accessor is intentionally separate from {@link getConfig}, whose legacy
86
+ * contract returns the loaded file object only. When a runtime override selects
87
+ * a different profile, lower-priority provider overrides are discarded so they
88
+ * cannot leak profile-specific choices (for example local files or inline jobs)
89
+ * into the new profile. Provider overrides still deep-merge when the profile is
90
+ * unchanged.
91
+ *
92
+ * @returns A validated, deterministic, secret-free runtime snapshot.
93
+ * @throws {RuntimeProfileValidationError} When no profile is configured or the
94
+ * effective provider composition violates a profile invariant.
95
+ */
96
+ export declare function resolveConfiguredApplicationRuntime(): Readonly<ResolvedApplicationRuntime>;
97
+ /**
98
+ * Return the `site` section of the loaded configuration.
99
+ *
100
+ * Equivalent to `getConfig()?.site ?? null`. Returns `null` both when no
101
+ * config has been loaded and when the loaded config has no `site` key.
102
+ *
103
+ * @returns The {@link SiteConfig} object, or `null` if not defined.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * const site = getSiteConfig();
108
+ * const title = site?.name ?? 'Untitled Site';
109
+ * ```
110
+ *
111
+ * @see {@link SiteConfig}
112
+ * @see {@link getConfig}
113
+ */
114
+ export declare function getSiteConfig(): import('./types.js').SiteConfig | null;
115
+ /**
116
+ * Return the resolved configuration for a named module.
117
+ *
118
+ * Merges four layers in ascending priority order:
119
+ * 1. `defaults` (caller-supplied fallbacks)
120
+ * 2. Global `smrt` section of the loaded config
121
+ * 3. `modules[moduleName]` section of the loaded config
122
+ * 4. Runtime `modules[moduleName]` overrides set via {@link setConfig}
123
+ *
124
+ * Works synchronously — call {@link loadConfig} first to populate the cache.
125
+ * If no config has been loaded, only `defaults` are returned.
126
+ *
127
+ * @param moduleName - Key in `config.modules` (e.g., `'praeco'`).
128
+ * @param defaults - Optional fallback values used when a key is absent from all
129
+ * higher-priority layers.
130
+ * @returns The fully merged module config typed as `T`.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * const config = getModuleConfig('praeco', {
135
+ * rssLimit: 50,
136
+ * fetchTimeout: 10_000,
137
+ * });
138
+ * // config.rssLimit may be overridden by smrt.config.js or setConfig()
139
+ * ```
140
+ *
141
+ * @see {@link getPackageConfig}
142
+ * @see {@link setConfig}
143
+ * @see {@link SmrtConfig.modules}
144
+ */
145
+ export declare function getModuleConfig<T extends Record<string, unknown>>(moduleName: string, defaults?: T): T;
146
+ /**
147
+ * Return the resolved configuration for a named package.
148
+ *
149
+ * Identical to {@link getModuleConfig} but reads from `config.packages` instead
150
+ * of `config.modules`. Use this inside `@happyvertical/smrt-*` packages that
151
+ * want to expose their own config section without conflicting with user-defined
152
+ * module names.
153
+ *
154
+ * Merges four layers in ascending priority order:
155
+ * 1. `defaults` (caller-supplied fallbacks)
156
+ * 2. Global `smrt` section of the loaded config
157
+ * 3. `packages[packageName]` section of the loaded config
158
+ * 4. Runtime `packages[packageName]` overrides set via {@link setConfig}
159
+ *
160
+ * @param packageName - Key in `config.packages` (e.g., `'ai'`, `'spider'`).
161
+ * @param defaults - Optional fallback values.
162
+ * @returns The fully merged package config typed as `T`.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * // Inside @happyvertical/smrt-ai package
167
+ * const config = getPackageConfig('ai', {
168
+ * defaultModel: 'gpt-4o-mini',
169
+ * maxTokens: 2048,
170
+ * });
171
+ * ```
172
+ *
173
+ * @see {@link getModuleConfig}
174
+ * @see {@link setConfig}
175
+ * @see {@link SmrtConfig.packages}
176
+ */
177
+ export declare function getPackageConfig<T extends Record<string, unknown>>(packageName: string, defaults?: T): T;
178
+ /**
179
+ * Apply runtime configuration overrides.
180
+ *
181
+ * Deep-merges `config` into an in-memory store that takes the highest priority
182
+ * in every subsequent {@link getModuleConfig} / {@link getPackageConfig} call.
183
+ * Successive calls accumulate. When a call explicitly changes the runtime
184
+ * profile, the stored runtime provider subtree is reset before merging so
185
+ * profile-specific selectors cannot leak into the new profile.
186
+ *
187
+ * Common uses:
188
+ * - Inject test doubles or environment-specific values without a config file.
189
+ * - Apply feature flags from a remote source after startup.
190
+ *
191
+ * @param config - Partial {@link SmrtConfig} to merge into the runtime store.
192
+ * `null` values are ignored (they do not clear existing keys).
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * setConfig({ modules: { ai: { defaultModel: 'gpt-4o' } } });
197
+ * ```
198
+ *
199
+ * @see {@link clearCache}
200
+ * @see {@link getModuleConfig}
201
+ */
202
+ export declare function setConfig(config: Partial<SmrtConfig>): void;
203
+ /**
204
+ * Reset all cached configuration state.
205
+ *
206
+ * Clears three independent caches:
207
+ * 1. `globalThis.__smrtConfigCache` — the merged config loaded by {@link loadConfig}.
208
+ * 2. The internal loader cache (`globalThis.__smrtLoaderCachedConfig`) and the
209
+ * cosmiconfig explorer instance.
210
+ * 3. The runtime override store populated by {@link setConfig}.
211
+ *
212
+ * After calling this, {@link getConfig} returns `null` and a fresh
213
+ * {@link loadConfig} call will re-read from disk.
214
+ *
215
+ * WARNING: This is a global reset — it affects every module sharing the same
216
+ * runtime, not just the caller. Use with care outside of test teardown.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * afterEach(() => {
221
+ * clearCache(); // reset between tests
222
+ * });
223
+ * ```
224
+ *
225
+ * @see {@link loadConfig}
226
+ * @see {@link setConfig}
227
+ */
228
+ export declare function clearCache(): void;
229
+ /**
230
+ * Type-safe helper for authoring `smrt.config.js` files.
231
+ *
232
+ * This is an identity function — it returns its argument unchanged. Its sole
233
+ * purpose is to provide TypeScript type-checking and IDE auto-completion when
234
+ * writing the config object literal.
235
+ *
236
+ * @param config - The config object to validate against {@link SmrtConfig}.
237
+ * @returns The same object, unchanged.
238
+ *
239
+ * @example
240
+ * ```js
241
+ * // smrt.config.js
242
+ * import { defineConfig } from '@happyvertical/smrt-config';
243
+ *
244
+ * export default defineConfig({
245
+ * smrt: { logLevel: 'info' },
246
+ * site: { name: 'My Site', ... },
247
+ * });
248
+ * ```
249
+ *
250
+ * @see {@link SmrtConfig}
251
+ * @see {@link loadConfig}
252
+ */
253
+ export declare function defineConfig(config: SmrtConfig): SmrtConfig;
254
+ //# sourceMappingURL=index.d.ts.map