@rizom/brain 0.2.0-alpha.150 → 0.2.0-alpha.152

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.
@@ -1,222 +1,222 @@
1
- import { z } from 'zod/v4';
2
-
1
+ import { z } from "zod/v4";
2
+ //#region ../../shell/entity-service/src/visibility.d.ts
3
3
  declare const canonicalContentVisibilitySchema: z.ZodEnum<{
4
- public: "public";
5
- shared: "shared";
6
- restricted: "restricted";
4
+ public: "public";
5
+ shared: "shared";
6
+ restricted: "restricted";
7
7
  }>;
8
8
  type ContentVisibility = z.infer<typeof canonicalContentVisibilitySchema>;
9
9
  type RawContentVisibility = ContentVisibility | "private";
10
-
10
+ //#endregion
11
+ //#region ../../shell/entity-service/src/types.d.ts
11
12
  /**
12
13
  * Options for entity mutation operations (create, update, upsert)
13
14
  */
14
15
  interface EntityMutationEventContext {
15
- conversationId?: string;
16
- channelId?: string;
17
- runId?: string;
18
- toolCallId?: string;
16
+ conversationId?: string;
17
+ channelId?: string;
18
+ runId?: string;
19
+ toolCallId?: string;
19
20
  }
20
21
  interface EntityJobOptions {
21
- priority?: number;
22
- maxRetries?: number;
23
- eventContext?: EntityMutationEventContext;
22
+ priority?: number;
23
+ maxRetries?: number;
24
+ eventContext?: EntityMutationEventContext;
24
25
  }
25
-
26
26
  /**
27
27
  * Options for entity creation (extends EntityJobOptions with deduplication)
28
28
  */
29
29
  interface CreateEntityOptions extends EntityJobOptions {
30
- deduplicateId?: boolean;
30
+ deduplicateId?: boolean;
31
31
  }
32
32
  /**
33
33
  * Result of an entity mutation that triggers an embedding job.
34
34
  * When skipped is true, content was unchanged — no DB write, no event, no embedding job.
35
35
  */
36
36
  interface EntityMutationResult {
37
- entityId: string;
38
- jobId: string;
39
- skipped: boolean;
37
+ entityId: string;
38
+ jobId: string;
39
+ skipped: boolean;
40
40
  }
41
41
  /**
42
42
  * Input for adapter-validated direct creation from finalized markdown.
43
43
  */
44
44
  interface CreateEntityFromMarkdownInput {
45
- entityType: string;
46
- id: string;
47
- markdown: string;
45
+ entityType: string;
46
+ id: string;
47
+ markdown: string;
48
48
  }
49
49
  /**
50
50
  * Data for storing an embedding for an entity
51
51
  */
52
52
  interface StoreEmbeddingData {
53
- entityId: string;
54
- entityType: string;
55
- embedding: Float32Array;
56
- contentHash: string;
53
+ entityId: string;
54
+ entityType: string;
55
+ embedding: Float32Array;
56
+ contentHash: string;
57
57
  }
58
58
  /**
59
59
  * Base entity type - generic to support typed metadata
60
60
  * TMetadata defaults to Record<string, unknown> for backward compatibility
61
61
  */
62
62
  interface BaseEntity<TMetadata = Record<string, unknown>> {
63
- id: string;
64
- entityType: string;
65
- content: string;
66
- created: string;
67
- updated: string;
68
- visibility: ContentVisibility;
69
- metadata: TMetadata;
70
- /** SHA256 hash of content for change detection */
71
- contentHash: string;
63
+ id: string;
64
+ entityType: string;
65
+ content: string;
66
+ created: string;
67
+ updated: string;
68
+ visibility: ContentVisibility;
69
+ metadata: TMetadata;
70
+ /** SHA256 hash of content for change detection */
71
+ contentHash: string;
72
72
  }
73
73
  /**
74
74
  * Entity input type for creation - allows partial entities with optional system fields
75
75
  * contentHash is excluded because it's computed automatically by the entity service
76
76
  */
77
77
  type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash" | "visibility"> & {
78
- id?: string;
79
- created?: string;
80
- updated?: string;
81
- visibility?: RawContentVisibility;
78
+ id?: string;
79
+ created?: string;
80
+ updated?: string;
81
+ visibility?: RawContentVisibility;
82
82
  };
83
83
  /**
84
84
  * Search result type
85
85
  */
86
86
  interface SearchResult<T extends BaseEntity = BaseEntity> {
87
- entity: T;
88
- score: number;
89
- excerpt: string;
87
+ entity: T;
88
+ score: number;
89
+ excerpt: string;
90
90
  }
91
91
  /**
92
92
  * Sort field specification for multi-field sorting
93
93
  */
94
94
  interface SortField {
95
- /** Field to sort by - "created", "updated", or a metadata field name */
96
- field: string;
97
- /** Sort direction */
98
- direction: "asc" | "desc";
99
- /** Sort NULL values before non-NULL values (default: false / SQLite default) */
100
- nullsFirst?: boolean;
95
+ /** Field to sort by - "created", "updated", or a metadata field name */
96
+ field: string;
97
+ /** Sort direction */
98
+ direction: "asc" | "desc";
99
+ /** Sort NULL values before non-NULL values (default: false / SQLite default) */
100
+ nullsFirst?: boolean;
101
101
  }
102
102
  /**
103
103
  * List entities options
104
104
  * Generic over metadata type for type-safe filtering
105
105
  */
106
106
  interface ListOptions<TMetadata = Record<string, unknown>> {
107
- limit?: number;
108
- offset?: number;
109
- /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
110
- sortFields?: SortField[];
111
- filter?: {
112
- metadata?: Partial<TMetadata>;
113
- visibilityScope?: ContentVisibility;
114
- };
115
- /** Filter to only entities with metadata.status = "published" */
116
- publishedOnly?: boolean;
107
+ limit?: number;
108
+ offset?: number;
109
+ /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
110
+ sortFields?: SortField[];
111
+ filter?: {
112
+ metadata?: Partial<TMetadata>;
113
+ visibilityScope?: ContentVisibility;
114
+ };
115
+ /** Filter to only entities with metadata.status = "published" */
116
+ publishedOnly?: boolean;
117
117
  }
118
118
  /**
119
119
  * Search options
120
120
  */
121
121
  interface SearchOptions {
122
- limit?: number;
123
- offset?: number;
124
- types?: string[];
125
- excludeTypes?: string[];
126
- sortBy?: "relevance" | "created" | "updated";
127
- sortDirection?: "asc" | "desc";
128
- /** Score multipliers per entity type - applied after initial search */
129
- weight?: Record<string, number>;
130
- visibilityScope?: ContentVisibility;
131
- /** Include queued/failed generation stubs in search results (default: false) */
132
- includeUngenerated?: boolean;
133
- /** Minimum relevance score to return. Omit for no score cutoff. */
134
- minScore?: number;
122
+ limit?: number;
123
+ offset?: number;
124
+ types?: string[];
125
+ excludeTypes?: string[];
126
+ sortBy?: "relevance" | "created" | "updated";
127
+ sortDirection?: "asc" | "desc";
128
+ /** Score multipliers per entity type - applied after initial search */
129
+ weight?: Record<string, number>;
130
+ visibilityScope?: ContentVisibility;
131
+ /** Include queued/failed generation stubs in search results (default: false) */
132
+ includeUngenerated?: boolean;
133
+ /** Minimum relevance score to return. Omit for no score cutoff. */
134
+ minScore?: number;
135
135
  }
136
136
  /**
137
137
  * Configuration for entity type registration
138
138
  */
139
139
  interface EntityTypeConfig {
140
- /** Score multiplier for search results (default: 1.0) */
141
- weight?: number;
142
- /** Whether to generate embeddings for this entity type (default: true).
143
- * Set to false for entity types with non-textual content (e.g., images). */
144
- embeddable?: boolean;
145
- /** Whether this entity type may be used as source material for derived projections (default: true).
146
- * Set to false for projection outputs that would create feedback loops. */
147
- projectionSource?: boolean;
148
- /** Publish semantics for status-bearing entity types. Statuses listed here
149
- * represent publication commitment/execution states and require the
150
- * `publish` entity action when entered or modified. */
151
- publish?: {
152
- publishStatuses: string[];
153
- };
140
+ /** Score multiplier for search results (default: 1.0) */
141
+ weight?: number;
142
+ /** Whether to generate embeddings for this entity type (default: true).
143
+ * Set to false for entity types with non-textual content (e.g., images). */
144
+ embeddable?: boolean;
145
+ /** Whether this entity type may be used as source material for derived projections (default: true).
146
+ * Set to false for projection outputs that would create feedback loops. */
147
+ projectionSource?: boolean;
148
+ /** Publish semantics for status-bearing entity types. Statuses listed here
149
+ * represent publication commitment/execution states and require the
150
+ * `publish` entity action when entered or modified. */
151
+ publish?: {
152
+ publishStatuses: string[];
153
+ };
154
154
  }
155
155
  /**
156
156
  * Core entity service interface for read-only operations
157
157
  * Used by core plugins that need entity access but shouldn't modify entities
158
158
  */
159
159
  interface GetEntityRequest {
160
- entityType: string;
161
- id: string;
162
- /**
163
- * Optional visibility scope. Undefined fails closed to "public" — callers
164
- * with elevated access must opt up explicitly.
165
- */
166
- visibilityScope?: ContentVisibility;
160
+ entityType: string;
161
+ id: string;
162
+ /**
163
+ * Optional visibility scope. Undefined fails closed to "public" — callers
164
+ * with elevated access must opt up explicitly.
165
+ */
166
+ visibilityScope?: ContentVisibility;
167
167
  }
168
168
  type GetEntityRawRequest = GetEntityRequest;
169
169
  interface ListEntitiesRequest {
170
- entityType: string;
171
- options?: ListOptions | undefined;
170
+ entityType: string;
171
+ options?: ListOptions | undefined;
172
172
  }
173
173
  interface CountEntitiesRequest {
174
- entityType: string;
175
- options?: Pick<ListOptions, "publishedOnly" | "filter"> | undefined;
174
+ entityType: string;
175
+ options?: Pick<ListOptions, "publishedOnly" | "filter"> | undefined;
176
176
  }
177
177
  interface CreateEntityRequest<T extends BaseEntity> {
178
- entity: EntityInput<T>;
179
- options?: CreateEntityOptions | undefined;
178
+ entity: EntityInput<T>;
179
+ options?: CreateEntityOptions | undefined;
180
180
  }
181
181
  interface CreateEntityFromMarkdownRequest {
182
- input: CreateEntityFromMarkdownInput;
183
- options?: CreateEntityOptions | undefined;
182
+ input: CreateEntityFromMarkdownInput;
183
+ options?: CreateEntityOptions | undefined;
184
184
  }
185
185
  interface UpdateEntityRequest<T extends BaseEntity> {
186
- entity: T;
187
- options?: EntityJobOptions | undefined;
186
+ entity: T;
187
+ options?: EntityJobOptions | undefined;
188
188
  }
189
189
  interface DeleteEntityRequest {
190
- entityType: string;
191
- id: string;
190
+ entityType: string;
191
+ id: string;
192
192
  }
193
193
  interface UpsertEntityRequest<T extends BaseEntity> {
194
- entity: T;
195
- options?: EntityJobOptions | undefined;
194
+ entity: T;
195
+ options?: EntityJobOptions | undefined;
196
196
  }
197
197
  interface EntitySearchRequest {
198
- query: string;
199
- options?: SearchOptions | undefined;
198
+ query: string;
199
+ options?: SearchOptions | undefined;
200
200
  }
201
201
  interface SearchWithDistancesRequest {
202
- query: string;
202
+ query: string;
203
203
  }
204
204
  /**
205
205
  * Context passed to all DataSource operations
206
206
  * Contains internal state that should not be mixed with user query parameters
207
207
  */
208
208
  interface BaseDataSourceContext {
209
- /**
210
- * Whether to filter to only published/complete content
211
- * Set by site-builder: true for production, false for preview
212
- */
213
- publishedOnly?: boolean;
214
- /**
215
- * Scoped entity service that auto-applies publishedOnly filter
216
- * Datasources should use this instead of their injected entityService
217
- * to ensure consistent filtering behavior across environments
218
- */
219
- entityService: EntityService;
209
+ /**
210
+ * Whether to filter to only published/complete content
211
+ * Set by site-builder: true for production, false for preview
212
+ */
213
+ publishedOnly?: boolean;
214
+ /**
215
+ * Scoped entity service that auto-applies publishedOnly filter
216
+ * Datasources should use this instead of their injected entityService
217
+ * to ensure consistent filtering behavior across environments
218
+ */
219
+ entityService: EntityService;
220
220
  }
221
221
  type DataSourceSchema<T> = z.ZodType<T, unknown>;
222
222
  /**
@@ -227,113 +227,114 @@ type DataSourceSchema<T> = z.ZodType<T, unknown>;
227
227
  * via their dataSourceId property.
228
228
  */
229
229
  interface DataSource {
230
- /**
231
- * Unique identifier for this data source
232
- */
233
- id: string;
234
- /**
235
- * Human-readable name for this data source
236
- */
237
- name: string;
238
- /**
239
- * Optional description of what this data source provides
240
- */
241
- description?: string;
242
- /**
243
- * Optional: Fetch existing data
244
- * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
245
- * DataSources validate output using the provided schema
246
- * @param query - Query parameters for fetching data
247
- * @param outputSchema - Schema for validating output data
248
- * @param context - Context with environment
249
- */
250
- fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
251
- /**
252
- * Optional: Generate new content
253
- * Used by data sources that create content (e.g., AI-generated content, reports)
254
- */
255
- generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
256
- /**
257
- * Optional: Transform content between formats
258
- * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
259
- */
260
- transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
230
+ /**
231
+ * Unique identifier for this data source
232
+ */
233
+ id: string;
234
+ /**
235
+ * Human-readable name for this data source
236
+ */
237
+ name: string;
238
+ /**
239
+ * Optional description of what this data source provides
240
+ */
241
+ description?: string;
242
+ /**
243
+ * Optional: Fetch existing data
244
+ * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
245
+ * DataSources validate output using the provided schema
246
+ * @param query - Query parameters for fetching data
247
+ * @param outputSchema - Schema for validating output data
248
+ * @param context - Context with environment
249
+ */
250
+ fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
251
+ /**
252
+ * Optional: Generate new content
253
+ * Used by data sources that create content (e.g., AI-generated content, reports)
254
+ */
255
+ generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
256
+ /**
257
+ * Optional: Transform content between formats
258
+ * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
259
+ */
260
+ transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
261
261
  }
262
262
  interface ICoreEntityService {
263
- getEntity<T extends BaseEntity>(request: GetEntityRequest): Promise<T | null>;
264
- /**
265
- * Get entity without content resolution (raw)
266
- * Used internally to avoid recursion when resolving image references
267
- */
268
- getEntityRaw<T extends BaseEntity>(request: GetEntityRawRequest): Promise<T | null>;
269
- listEntities<T extends BaseEntity>(request: ListEntitiesRequest): Promise<T[]>;
270
- search<T extends BaseEntity = BaseEntity>(request: EntitySearchRequest): Promise<SearchResult<T>[]>;
271
- getEntityTypes(): string[];
272
- hasEntityType(type: string): boolean;
273
- countEntities(request: CountEntitiesRequest): Promise<number>;
274
- /**
275
- * Group counts by entity type. Fails closed: undefined visibilityScope
276
- * filters to public-only counts so aggregate insights cannot reveal
277
- * non-public entity existence.
278
- */
279
- getEntityCounts(visibilityScope?: ContentVisibility): Promise<Array<{
280
- entityType: string;
281
- count: number;
282
- }>>;
283
- /** Get configuration for a specific entity type */
284
- getEntityTypeConfig(type: string): EntityTypeConfig;
285
- /** Get weight map for all registered entity types with non-default weights */
286
- getWeightMap(): Record<string, number>;
263
+ getEntity<T extends BaseEntity>(request: GetEntityRequest): Promise<T | null>;
264
+ /**
265
+ * Get entity without content resolution (raw)
266
+ * Used internally to avoid recursion when resolving image references
267
+ */
268
+ getEntityRaw<T extends BaseEntity>(request: GetEntityRawRequest): Promise<T | null>;
269
+ listEntities<T extends BaseEntity>(request: ListEntitiesRequest): Promise<T[]>;
270
+ search<T extends BaseEntity = BaseEntity>(request: EntitySearchRequest): Promise<SearchResult<T>[]>;
271
+ getEntityTypes(): string[];
272
+ hasEntityType(type: string): boolean;
273
+ countEntities(request: CountEntitiesRequest): Promise<number>;
274
+ /**
275
+ * Group counts by entity type. Fails closed: undefined visibilityScope
276
+ * filters to public-only counts so aggregate insights cannot reveal
277
+ * non-public entity existence.
278
+ */
279
+ getEntityCounts(visibilityScope?: ContentVisibility): Promise<Array<{
280
+ entityType: string;
281
+ count: number;
282
+ }>>;
283
+ /** Get configuration for a specific entity type */
284
+ getEntityTypeConfig(type: string): EntityTypeConfig;
285
+ /** Get weight map for all registered entity types with non-default weights */
286
+ getWeightMap(): Record<string, number>;
287
287
  }
288
288
  interface EmbeddingBackfillResult {
289
- queued: number;
290
- skipped: number;
289
+ queued: number;
290
+ skipped: number;
291
291
  }
292
292
  interface EmbeddingIndexStats {
293
- missingEmbeddings: number;
294
- staleEmbeddings: number;
295
- failedEmbeddings: number;
296
- /** Entities whose type generates embeddings (non-embeddable types excluded). */
297
- embeddableEntities: number;
298
- /** Embeddable entities whose embedding is present and current. */
299
- embeddedEntities: number;
293
+ missingEmbeddings: number;
294
+ staleEmbeddings: number;
295
+ failedEmbeddings: number;
296
+ /** Entities whose type generates embeddings (non-embeddable types excluded). */
297
+ embeddableEntities: number;
298
+ /** Embeddable entities whose embedding is present and current. */
299
+ embeddedEntities: number;
300
300
  }
301
301
  interface IndexReadinessOptions {
302
- timeoutMs: number;
303
- intervalMs?: number;
302
+ timeoutMs: number;
303
+ intervalMs?: number;
304
304
  }
305
305
  interface IndexReadinessStatus extends EmbeddingIndexStats {
306
- ready: boolean;
307
- degraded: boolean;
308
- activeEmbeddingJobs: number;
306
+ ready: boolean;
307
+ degraded: boolean;
308
+ activeEmbeddingJobs: number;
309
309
  }
310
310
  interface EntityService extends ICoreEntityService {
311
- createEntity<T extends BaseEntity>(request: CreateEntityRequest<T>): Promise<EntityMutationResult>;
312
- createEntityFromMarkdown(request: CreateEntityFromMarkdownRequest): Promise<EntityMutationResult>;
313
- updateEntity<T extends BaseEntity>(request: UpdateEntityRequest<T>): Promise<EntityMutationResult>;
314
- deleteEntity(request: DeleteEntityRequest): Promise<boolean>;
315
- upsertEntity<T extends BaseEntity>(request: UpsertEntityRequest<T>): Promise<EntityMutationResult & {
316
- created: boolean;
317
- }>;
318
- storeEmbedding(data: StoreEmbeddingData): Promise<void>;
319
- backfillMissingEmbeddings(): Promise<EmbeddingBackfillResult>;
320
- isIndexReady(): boolean;
321
- awaitIndexReady(options: IndexReadinessOptions): Promise<IndexReadinessStatus>;
322
- serializeEntity(entity: BaseEntity): string;
323
- deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
324
- countEmbeddings(): Promise<number>;
325
- searchWithDistances(request: SearchWithDistancesRequest): Promise<Array<{
326
- entityId: string;
327
- entityType: string;
328
- distance: number;
329
- }>>;
330
- initialize(): Promise<void>;
331
- getAsyncJobStatus(jobId: string): Promise<{
332
- status: "pending" | "processing" | "completed" | "failed";
333
- error?: string;
334
- } | null>;
335
- }
336
-
311
+ createEntity<T extends BaseEntity>(request: CreateEntityRequest<T>): Promise<EntityMutationResult>;
312
+ createEntityFromMarkdown(request: CreateEntityFromMarkdownRequest): Promise<EntityMutationResult>;
313
+ updateEntity<T extends BaseEntity>(request: UpdateEntityRequest<T>): Promise<EntityMutationResult>;
314
+ deleteEntity(request: DeleteEntityRequest): Promise<boolean>;
315
+ upsertEntity<T extends BaseEntity>(request: UpsertEntityRequest<T>): Promise<EntityMutationResult & {
316
+ created: boolean;
317
+ }>;
318
+ storeEmbedding(data: StoreEmbeddingData): Promise<void>;
319
+ backfillMissingEmbeddings(): Promise<EmbeddingBackfillResult>;
320
+ isIndexReady(): boolean;
321
+ awaitIndexReady(options: IndexReadinessOptions): Promise<IndexReadinessStatus>;
322
+ serializeEntity(entity: BaseEntity): string;
323
+ deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
324
+ countEmbeddings(): Promise<number>;
325
+ searchWithDistances(request: SearchWithDistancesRequest): Promise<Array<{
326
+ entityId: string;
327
+ entityType: string;
328
+ distance: number;
329
+ }>>;
330
+ initialize(): Promise<void>;
331
+ getAsyncJobStatus(jobId: string): Promise<{
332
+ status: "pending" | "processing" | "completed" | "failed";
333
+ error?: string;
334
+ } | null>;
335
+ }
336
+ //#endregion
337
+ //#region ../../shared/utils/src/logger.d.ts
337
338
  /**
338
339
  * Logger interface for consistent logging across the application
339
340
  * Simplified version without Winston dependency
@@ -342,13 +343,13 @@ interface EntityService extends ICoreEntityService {
342
343
  * Log levels
343
344
  */
344
345
  declare const LogLevel: {
345
- readonly SILLY: 0;
346
- readonly VERBOSE: 1;
347
- readonly DEBUG: 2;
348
- readonly INFO: 3;
349
- readonly WARN: 4;
350
- readonly ERROR: 5;
351
- readonly NONE: 6;
346
+ readonly SILLY: 0;
347
+ readonly VERBOSE: 1;
348
+ readonly DEBUG: 2;
349
+ readonly INFO: 3;
350
+ readonly WARN: 4;
351
+ readonly ERROR: 5;
352
+ readonly NONE: 6;
352
353
  };
353
354
  type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
354
355
  /**
@@ -356,97 +357,99 @@ type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
356
357
  */
357
358
  type LogFormat = "text" | "json";
358
359
  interface LoggerOptions {
359
- level?: LogLevel;
360
- context?: string;
361
- useStderr?: boolean;
362
- format?: LogFormat;
363
- /** Path to a log file. Always writes JSON, one line per entry. */
364
- logFile?: string;
360
+ level?: LogLevel;
361
+ context?: string;
362
+ useStderr?: boolean;
363
+ format?: LogFormat;
364
+ /** Path to a log file. Always writes JSON, one line per entry. */
365
+ logFile?: string;
365
366
  }
366
367
  declare class Logger {
367
- /** The singleton instance */
368
- private static instance;
369
- private level;
370
- private context;
371
- private useStderr;
372
- private format;
373
- private logFile;
374
- private fileHandle;
375
- /**
376
- * Private constructor to enforce singleton pattern
377
- */
378
- private constructor();
379
- /**
380
- * Get the singleton instance of Logger
381
- */
382
- static getInstance(options?: LoggerOptions): Logger;
383
- /**
384
- * Reset the singleton instance (primarily for testing)
385
- */
386
- static resetInstance(): void;
387
- /**
388
- * Create a fresh instance without affecting the singleton
389
- */
390
- static createFresh(options?: LoggerOptions): Logger;
391
- /**
392
- * Format a log entry for output.
393
- * Text: [timestamp] [context] message
394
- * JSON: {"ts":"...","level":"...","ctx":"...","msg":"...","data":[...]}
395
- */
396
- private formatEntry;
397
- /**
398
- * Log a message at the 'silly' level
399
- */
400
- /**
401
- * Write a formatted log entry to the appropriate output stream.
402
- * JSON format: single string argument (no spread).
403
- * Text format: message + spread args for console formatting.
404
- */
405
- private write;
406
- /**
407
- * Format a JSON log entry (used for file output regardless of console format).
408
- */
409
- private formatJsonEntry;
410
- silly(message: string, ...args: unknown[]): void;
411
- verbose(message: string, ...args: unknown[]): void;
412
- debug(message: string, ...args: unknown[]): void;
413
- info(message: string, ...args: unknown[]): void;
414
- warn(message: string, ...args: unknown[]): void;
415
- error(message: string, ...args: unknown[]): void;
416
- /**
417
- * Create a child logger with a specific context
418
- */
419
- child(context: string): Logger;
420
- /**
421
- * Configure the logger to use stderr for all output
422
- * Useful for MCP servers that need stdout for JSON-RPC
423
- */
424
- setUseStderr(useStderr: boolean): void;
425
- }
426
-
368
+ /** The singleton instance */
369
+ private static instance;
370
+ private level;
371
+ private context;
372
+ private useStderr;
373
+ private format;
374
+ private logFile;
375
+ private fileHandle;
376
+ /**
377
+ * Private constructor to enforce singleton pattern
378
+ */
379
+ private constructor();
380
+ /**
381
+ * Get the singleton instance of Logger
382
+ */
383
+ static getInstance(options?: LoggerOptions): Logger;
384
+ /**
385
+ * Reset the singleton instance (primarily for testing)
386
+ */
387
+ static resetInstance(): void;
388
+ /**
389
+ * Create a fresh instance without affecting the singleton
390
+ */
391
+ static createFresh(options?: LoggerOptions): Logger;
392
+ /**
393
+ * Format a log entry for output.
394
+ * Text: [timestamp] [context] message
395
+ * JSON: {"ts":"...","level":"...","ctx":"...","msg":"...","data":[...]}
396
+ */
397
+ private formatEntry;
398
+ /**
399
+ * Log a message at the 'silly' level
400
+ */
401
+ /**
402
+ * Write a formatted log entry to the appropriate output stream.
403
+ * JSON format: single string argument (no spread).
404
+ * Text format: message + spread args for console formatting.
405
+ */
406
+ private write;
407
+ /**
408
+ * Format a JSON log entry (used for file output regardless of console format).
409
+ */
410
+ private formatJsonEntry;
411
+ silly(message: string, ...args: unknown[]): void;
412
+ verbose(message: string, ...args: unknown[]): void;
413
+ debug(message: string, ...args: unknown[]): void;
414
+ info(message: string, ...args: unknown[]): void;
415
+ warn(message: string, ...args: unknown[]): void;
416
+ error(message: string, ...args: unknown[]): void;
417
+ /**
418
+ * Create a child logger with a specific context
419
+ */
420
+ child(context: string): Logger;
421
+ /**
422
+ * Configure the logger to use stderr for all output
423
+ * Useful for MCP servers that need stdout for JSON-RPC
424
+ */
425
+ setUseStderr(useStderr: boolean): void;
426
+ }
427
+ //#endregion
428
+ //#region ../../shell/entity-service/src/pagination.d.ts
427
429
  /**
428
430
  * Schema for pagination information
429
431
  * Used by datasources that return paginated lists
430
432
  */
431
433
  declare const paginationInfoSchema: z.ZodObject<{
432
- currentPage: z.ZodNumber;
433
- totalPages: z.ZodNumber;
434
- totalItems: z.ZodNumber;
435
- pageSize: z.ZodNumber;
436
- hasNextPage: z.ZodBoolean;
437
- hasPrevPage: z.ZodBoolean;
434
+ currentPage: z.ZodNumber;
435
+ totalPages: z.ZodNumber;
436
+ totalItems: z.ZodNumber;
437
+ pageSize: z.ZodNumber;
438
+ hasNextPage: z.ZodBoolean;
439
+ hasPrevPage: z.ZodBoolean;
438
440
  }>;
439
441
  /**
440
442
  * Pagination information type
441
443
  */
442
444
  type PaginationInfo = z.output<typeof paginationInfoSchema>;
443
-
445
+ //#endregion
446
+ //#region ../../shell/plugins/src/service/base-entity-datasource.d.ts
444
447
  interface BaseQuerySchemaShape {
445
- id: z.ZodOptional<z.ZodString>;
446
- limit: z.ZodOptional<z.ZodNumber>;
447
- page: z.ZodOptional<z.ZodNumber>;
448
- pageSize: z.ZodOptional<z.ZodNumber>;
449
- baseUrl: z.ZodOptional<z.ZodString>;
448
+ id: z.ZodOptional<z.ZodString>;
449
+ limit: z.ZodOptional<z.ZodNumber>;
450
+ page: z.ZodOptional<z.ZodNumber>;
451
+ pageSize: z.ZodOptional<z.ZodNumber>;
452
+ baseUrl: z.ZodOptional<z.ZodString>;
450
453
  }
451
454
  type BaseQuerySchema = ReturnType<typeof z.looseObject<BaseQuerySchemaShape>>;
452
455
  /**
@@ -459,8 +462,8 @@ declare const baseQuerySchema: BaseQuerySchema;
459
462
  * Subclasses can extend the inner query via `baseQuerySchema.extend()`.
460
463
  */
461
464
  interface BaseInputSchemaShape {
462
- entityType: z.ZodOptional<z.ZodString>;
463
- query: z.ZodOptional<typeof baseQuerySchema>;
465
+ entityType: z.ZodOptional<z.ZodString>;
466
+ query: z.ZodOptional<typeof baseQuerySchema>;
464
467
  }
465
468
  type BaseInputSchema = ReturnType<typeof z.looseObject<BaseInputSchemaShape>>;
466
469
  declare const baseInputSchema: BaseInputSchema;
@@ -473,29 +476,29 @@ type BaseQuery = z.output<typeof baseQuerySchema>;
473
476
  * Navigation context for detail views (prev/next entities).
474
477
  */
475
478
  interface NavigationResult<T> {
476
- prev: T | null;
477
- next: T | null;
479
+ prev: T | null;
480
+ next: T | null;
478
481
  }
479
482
  /**
480
483
  * Configuration for a BaseEntityDataSource.
481
484
  */
482
485
  interface EntityDataSourceConfig {
483
- /** Entity type to query (e.g., "post", "deck", "project") */
484
- entityType: string;
485
- /** Default sort order for list and navigation queries */
486
- defaultSort: SortField[];
487
- /** Default limit for list queries (defaults to 100) */
488
- defaultLimit?: number;
489
- /**
490
- * How to look up a single entity by the `id` query param.
491
- * - "slug": filter by `metadata.slug` (default)
492
- * - "id": direct `getEntity()` lookup
493
- */
494
- lookupField?: "slug" | "id";
495
- /** Enable prev/next navigation on detail views (defaults to false) */
496
- enableNavigation?: boolean;
497
- /** Max entities to fetch when resolving prev/next navigation (defaults to 1000) */
498
- navigationLimit?: number;
486
+ /** Entity type to query (e.g., "post", "deck", "project") */
487
+ entityType: string;
488
+ /** Default sort order for list and navigation queries */
489
+ defaultSort: SortField[];
490
+ /** Default limit for list queries (defaults to 100) */
491
+ defaultLimit?: number;
492
+ /**
493
+ * How to look up a single entity by the `id` query param.
494
+ * - "slug": filter by `metadata.slug` (default)
495
+ * - "id": direct `getEntity()` lookup
496
+ */
497
+ lookupField?: "slug" | "id";
498
+ /** Enable prev/next navigation on detail views (defaults to false) */
499
+ enableNavigation?: boolean;
500
+ /** Max entities to fetch when resolving prev/next navigation (defaults to 1000) */
501
+ navigationLimit?: number;
499
502
  }
500
503
  /**
501
504
  * Base class for entity datasources that follow the list/detail pattern.
@@ -517,81 +520,80 @@ interface EntityDataSourceConfig {
517
520
  * override `fetch()` to handle those first, then call `super.fetch()` for the standard path.
518
521
  */
519
522
  declare abstract class BaseEntityDataSource<TEntity extends BaseEntity = BaseEntity, TTransformed = TEntity> implements DataSource {
520
- protected readonly logger: Logger;
521
- abstract readonly id: string;
522
- abstract readonly name: string;
523
- abstract readonly description: string;
524
- protected abstract readonly config: EntityDataSourceConfig;
525
- constructor(logger: Logger);
526
- /**
527
- * Transform a raw entity into the display format used by templates.
528
- * Called for both list items and detail views.
529
- */
530
- protected abstract transformEntity(entity: TEntity): TTransformed;
531
- /**
532
- * Build the detail response object.
533
- * Override this if using the base class's standard detail path.
534
- * Datasources that fully override `fetch()` for detail views need not implement this.
535
- *
536
- * @param item - The transformed entity
537
- * @param navigation - Prev/next entities (null if navigation is disabled)
538
- */
539
- protected buildDetailResult(_item: TTransformed, _navigation: NavigationResult<TTransformed> | null): unknown;
540
- /**
541
- * Build the list response object.
542
- * @param items - Transformed entities
543
- * @param pagination - Pagination info (null if no page param was provided)
544
- * @param query - The parsed query params (for passing through baseUrl, etc.)
545
- */
546
- protected abstract buildListResult(items: TTransformed[], pagination: PaginationInfo | null, query: BaseQuery): unknown;
547
- /**
548
- * Parse and validate the incoming query with Zod.
549
- * Override to support additional query parameters beyond the base set.
550
- * Use `baseQuerySchema.extend()` or `baseInputSchema` for validation.
551
- */
552
- protected parseQuery(query: unknown): {
553
- entityType: string;
554
- query: BaseQuery;
555
- };
556
- /**
557
- * Standard fetch implementation: dispatch to detail or list based on query.id.
558
- *
559
- * Override to handle custom query cases before falling through to the standard path:
560
- * ```typescript
561
- * async fetch<T>(query, outputSchema, context) {
562
- * const params = this.parseQuery(query);
563
- * if (params.query.latest) {
564
- * return this.fetchLatest(outputSchema, context.entityService);
565
- * }
566
- * return super.fetch(query, outputSchema, context);
567
- * }
568
- * ```
569
- */
570
- fetch<T>(query: unknown, outputSchema: DataSourceSchema<T>, context: BaseDataSourceContext): Promise<T>;
571
- /**
572
- * Fetch a single entity and optionally resolve prev/next navigation.
573
- */
574
- protected fetchDetail(id: string, entityService: EntityService): Promise<{
575
- item: TTransformed;
576
- navigation: NavigationResult<TTransformed> | null;
577
- }>;
578
- /**
579
- * Fetch a paginated list of entities.
580
- */
581
- protected fetchList(query: BaseQuery, entityService: EntityService, listOptions?: Partial<ListOptions>): Promise<{
582
- items: TTransformed[];
583
- pagination: PaginationInfo | null;
584
- }>;
585
- /**
586
- * Resolve prev/next navigation for a given entity within the sorted list.
587
- */
588
- protected resolveNavigation(entity: TEntity, entityService: EntityService, sortFields?: SortField[]): Promise<NavigationResult<TTransformed>>;
589
- /**
590
- * Look up a single entity by id or slug.
591
- * Uses `config.lookupField` to determine the strategy.
592
- */
593
- protected lookupEntity(id: string, entityService: EntityService): Promise<TEntity>;
594
- }
595
-
596
- export { BaseEntityDataSource, baseInputSchema, baseQuerySchema };
597
- export type { BaseQuery, EntityDataSourceConfig, NavigationResult, SortField };
523
+ protected readonly logger: Logger;
524
+ abstract readonly id: string;
525
+ abstract readonly name: string;
526
+ abstract readonly description: string;
527
+ protected abstract readonly config: EntityDataSourceConfig;
528
+ constructor(logger: Logger);
529
+ /**
530
+ * Transform a raw entity into the display format used by templates.
531
+ * Called for both list items and detail views.
532
+ */
533
+ protected abstract transformEntity(entity: TEntity): TTransformed;
534
+ /**
535
+ * Build the detail response object.
536
+ * Override this if using the base class's standard detail path.
537
+ * Datasources that fully override `fetch()` for detail views need not implement this.
538
+ *
539
+ * @param item - The transformed entity
540
+ * @param navigation - Prev/next entities (null if navigation is disabled)
541
+ */
542
+ protected buildDetailResult(_item: TTransformed, _navigation: NavigationResult<TTransformed> | null): unknown;
543
+ /**
544
+ * Build the list response object.
545
+ * @param items - Transformed entities
546
+ * @param pagination - Pagination info (null if no page param was provided)
547
+ * @param query - The parsed query params (for passing through baseUrl, etc.)
548
+ */
549
+ protected abstract buildListResult(items: TTransformed[], pagination: PaginationInfo | null, query: BaseQuery): unknown;
550
+ /**
551
+ * Parse and validate the incoming query with Zod.
552
+ * Override to support additional query parameters beyond the base set.
553
+ * Use `baseQuerySchema.extend()` or `baseInputSchema` for validation.
554
+ */
555
+ protected parseQuery(query: unknown): {
556
+ entityType: string;
557
+ query: BaseQuery;
558
+ };
559
+ /**
560
+ * Standard fetch implementation: dispatch to detail or list based on query.id.
561
+ *
562
+ * Override to handle custom query cases before falling through to the standard path:
563
+ * ```typescript
564
+ * async fetch<T>(query, outputSchema, context) {
565
+ * const params = this.parseQuery(query);
566
+ * if (params.query.latest) {
567
+ * return this.fetchLatest(outputSchema, context.entityService);
568
+ * }
569
+ * return super.fetch(query, outputSchema, context);
570
+ * }
571
+ * ```
572
+ */
573
+ fetch<T>(query: unknown, outputSchema: DataSourceSchema<T>, context: BaseDataSourceContext): Promise<T>;
574
+ /**
575
+ * Fetch a single entity and optionally resolve prev/next navigation.
576
+ */
577
+ protected fetchDetail(id: string, entityService: EntityService): Promise<{
578
+ item: TTransformed;
579
+ navigation: NavigationResult<TTransformed> | null;
580
+ }>;
581
+ /**
582
+ * Fetch a paginated list of entities.
583
+ */
584
+ protected fetchList(query: BaseQuery, entityService: EntityService, listOptions?: Partial<ListOptions>): Promise<{
585
+ items: TTransformed[];
586
+ pagination: PaginationInfo | null;
587
+ }>;
588
+ /**
589
+ * Resolve prev/next navigation for a given entity within the sorted list.
590
+ */
591
+ protected resolveNavigation(entity: TEntity, entityService: EntityService, sortFields?: SortField[]): Promise<NavigationResult<TTransformed>>;
592
+ /**
593
+ * Look up a single entity by id or slug.
594
+ * Uses `config.lookupField` to determine the strategy.
595
+ */
596
+ protected lookupEntity(id: string, entityService: EntityService): Promise<TEntity>;
597
+ }
598
+ //#endregion
599
+ export { BaseEntityDataSource, type BaseQuery, type EntityDataSourceConfig, type NavigationResult, type SortField, baseInputSchema, baseQuerySchema };