@rizom/brain 0.2.0-alpha.149 → 0.2.0-alpha.151
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/brain.js +707 -707
- package/dist/deploy.d.ts +8 -8
- package/dist/entities.d.ts +414 -421
- package/dist/index.d.ts +39 -45
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/interfaces.d.ts +211 -132
- package/dist/plugins.d.ts +967 -954
- package/dist/services.d.ts +399 -397
- package/dist/site.d.ts +63 -66
- package/dist/site.js +4 -4
- package/dist/site.js.map +1 -1
- package/dist/templates.d.ts +117 -115
- package/dist/themes.d.ts +3 -2
- package/package.json +4 -4
package/dist/services.d.ts
CHANGED
|
@@ -1,222 +1,222 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
|
|
1
|
+
import { z } from "zod/v4";
|
|
2
|
+
//#region ../../shell/entity-service/src/visibility.d.ts
|
|
3
3
|
declare const canonicalContentVisibilitySchema: z.ZodEnum<{
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
conversationId?: string;
|
|
17
|
+
channelId?: string;
|
|
18
|
+
runId?: string;
|
|
19
|
+
toolCallId?: string;
|
|
19
20
|
}
|
|
20
21
|
interface EntityJobOptions {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
171
|
-
|
|
170
|
+
entityType: string;
|
|
171
|
+
options?: ListOptions | undefined;
|
|
172
172
|
}
|
|
173
173
|
interface CountEntitiesRequest {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
entityType: string;
|
|
175
|
+
options?: Pick<ListOptions, "publishedOnly" | "filter"> | undefined;
|
|
176
176
|
}
|
|
177
177
|
interface CreateEntityRequest<T extends BaseEntity> {
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
entity: EntityInput<T>;
|
|
179
|
+
options?: CreateEntityOptions | undefined;
|
|
180
180
|
}
|
|
181
181
|
interface CreateEntityFromMarkdownRequest {
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
input: CreateEntityFromMarkdownInput;
|
|
183
|
+
options?: CreateEntityOptions | undefined;
|
|
184
184
|
}
|
|
185
185
|
interface UpdateEntityRequest<T extends BaseEntity> {
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
entity: T;
|
|
187
|
+
options?: EntityJobOptions | undefined;
|
|
188
188
|
}
|
|
189
189
|
interface DeleteEntityRequest {
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
entityType: string;
|
|
191
|
+
id: string;
|
|
192
192
|
}
|
|
193
193
|
interface UpsertEntityRequest<T extends BaseEntity> {
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
entity: T;
|
|
195
|
+
options?: EntityJobOptions | undefined;
|
|
196
196
|
}
|
|
197
197
|
interface EntitySearchRequest {
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
query: string;
|
|
199
|
+
options?: SearchOptions | undefined;
|
|
200
200
|
}
|
|
201
201
|
interface SearchWithDistancesRequest {
|
|
202
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
290
|
-
|
|
289
|
+
queued: number;
|
|
290
|
+
skipped: number;
|
|
291
291
|
}
|
|
292
292
|
interface EmbeddingIndexStats {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
303
|
-
|
|
302
|
+
timeoutMs: number;
|
|
303
|
+
intervalMs?: number;
|
|
304
304
|
}
|
|
305
305
|
interface IndexReadinessStatus extends EmbeddingIndexStats {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
ready: boolean;
|
|
307
|
+
degraded: boolean;
|
|
308
|
+
activeEmbeddingJobs: number;
|
|
309
309
|
}
|
|
310
310
|
interface EntityService extends ICoreEntityService {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
463
|
-
|
|
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
|
-
|
|
477
|
-
|
|
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
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
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
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
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 };
|