@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.
@@ -1,17 +1,15 @@
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
- declare const contentVisibilitySchema: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [
11
- typeof canonicalContentVisibilitySchema,
12
- z.ZodLiteral<"private">
13
- ]>>, z.ZodTransform<ContentVisibility, RawContentVisibility | undefined>>;
14
-
10
+ declare const contentVisibilitySchema: z.ZodPipe<z.ZodOptional<z.ZodUnion<readonly [typeof canonicalContentVisibilitySchema, z.ZodLiteral<"private">]>>, z.ZodTransform<ContentVisibility, RawContentVisibility | undefined>>;
11
+ //#endregion
12
+ //#region ../../shell/entity-service/src/types.d.ts
15
13
  /**
16
14
  * Entity type for unstructured notes (the "note" entity type).
17
15
  * Used as a sentinel for the default catch-all markdown file shape —
@@ -22,61 +20,60 @@ declare const NOTE_ENTITY_TYPE = "note";
22
20
  * Options for entity mutation operations (create, update, upsert)
23
21
  */
24
22
  interface EntityMutationEventContext {
25
- conversationId?: string;
26
- channelId?: string;
27
- runId?: string;
28
- toolCallId?: string;
23
+ conversationId?: string;
24
+ channelId?: string;
25
+ runId?: string;
26
+ toolCallId?: string;
29
27
  }
30
28
  interface EntityJobOptions {
31
- priority?: number;
32
- maxRetries?: number;
33
- eventContext?: EntityMutationEventContext;
29
+ priority?: number;
30
+ maxRetries?: number;
31
+ eventContext?: EntityMutationEventContext;
34
32
  }
35
-
36
33
  /**
37
34
  * Options for entity creation (extends EntityJobOptions with deduplication)
38
35
  */
39
36
  interface CreateEntityOptions extends EntityJobOptions {
40
- deduplicateId?: boolean;
37
+ deduplicateId?: boolean;
41
38
  }
42
39
  /**
43
40
  * Result of an entity mutation that triggers an embedding job.
44
41
  * When skipped is true, content was unchanged — no DB write, no event, no embedding job.
45
42
  */
46
43
  interface EntityMutationResult {
47
- entityId: string;
48
- jobId: string;
49
- skipped: boolean;
44
+ entityId: string;
45
+ jobId: string;
46
+ skipped: boolean;
50
47
  }
51
48
  /**
52
49
  * Input for adapter-validated direct creation from finalized markdown.
53
50
  */
54
51
  interface CreateEntityFromMarkdownInput {
55
- entityType: string;
56
- id: string;
57
- markdown: string;
52
+ entityType: string;
53
+ id: string;
54
+ markdown: string;
58
55
  }
59
56
  /**
60
57
  * Data for storing an embedding for an entity
61
58
  */
62
59
  interface StoreEmbeddingData {
63
- entityId: string;
64
- entityType: string;
65
- embedding: Float32Array;
66
- contentHash: string;
60
+ entityId: string;
61
+ entityType: string;
62
+ embedding: Float32Array;
63
+ contentHash: string;
67
64
  }
68
65
  /**
69
66
  * Base entity schema that all entities must extend
70
67
  */
71
68
  declare const baseEntitySchema: z.ZodObject<{
72
- id: z.ZodString;
73
- entityType: z.ZodString;
74
- content: z.ZodString;
75
- created: z.ZodString;
76
- updated: z.ZodString;
77
- visibility: typeof contentVisibilitySchema;
78
- metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
79
- contentHash: z.ZodString;
69
+ id: z.ZodString;
70
+ entityType: z.ZodString;
71
+ content: z.ZodString;
72
+ created: z.ZodString;
73
+ updated: z.ZodString;
74
+ visibility: typeof contentVisibilitySchema;
75
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
76
+ contentHash: z.ZodString;
80
77
  }>;
81
78
  type EntitySchema<T> = z.ZodType<T, unknown>;
82
79
  /**
@@ -84,121 +81,121 @@ type EntitySchema<T> = z.ZodType<T, unknown>;
84
81
  * TMetadata defaults to Record<string, unknown> for backward compatibility
85
82
  */
86
83
  interface BaseEntity<TMetadata = Record<string, unknown>> {
87
- id: string;
88
- entityType: string;
89
- content: string;
90
- created: string;
91
- updated: string;
92
- visibility: ContentVisibility;
93
- metadata: TMetadata;
94
- /** SHA256 hash of content for change detection */
95
- contentHash: string;
84
+ id: string;
85
+ entityType: string;
86
+ content: string;
87
+ created: string;
88
+ updated: string;
89
+ visibility: ContentVisibility;
90
+ metadata: TMetadata;
91
+ /** SHA256 hash of content for change detection */
92
+ contentHash: string;
96
93
  }
97
94
  /**
98
95
  * Entity input type for creation - allows partial entities with optional system fields
99
96
  * contentHash is excluded because it's computed automatically by the entity service
100
97
  */
101
98
  type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash" | "visibility"> & {
102
- id?: string;
103
- created?: string;
104
- updated?: string;
105
- visibility?: RawContentVisibility;
99
+ id?: string;
100
+ created?: string;
101
+ updated?: string;
102
+ visibility?: RawContentVisibility;
106
103
  };
107
104
  /**
108
105
  * Search result type
109
106
  */
110
107
  interface SearchResult<T extends BaseEntity = BaseEntity> {
111
- entity: T;
112
- score: number;
113
- excerpt: string;
108
+ entity: T;
109
+ score: number;
110
+ excerpt: string;
114
111
  }
115
112
  /**
116
113
  * Normalized system_create input shape used by plugin create interceptors.
117
114
  */
118
115
  interface CreateCoverImageInput {
119
- generate?: boolean | undefined;
120
- prompt?: string | undefined;
116
+ generate?: boolean | undefined;
117
+ prompt?: string | undefined;
121
118
  }
122
119
  interface CreateFromAttachmentInput {
123
- kind: "entity-attachment";
124
- sourceEntityType: string;
125
- sourceEntityId: string;
126
- attachmentType: string;
120
+ kind: "entity-attachment";
121
+ sourceEntityType: string;
122
+ sourceEntityId: string;
123
+ attachmentType: string;
127
124
  }
128
125
  interface CreateFromUploadInput {
129
- kind: "upload";
130
- id: string;
126
+ kind: "upload";
127
+ id: string;
131
128
  }
132
129
  interface CreateFromConversationMessageInput {
133
- kind: "conversation-message";
134
- messageId?: string | undefined;
130
+ kind: "conversation-message";
131
+ messageId?: string | undefined;
135
132
  }
136
133
  type CreateFromInput = CreateFromAttachmentInput | CreateFromUploadInput | CreateFromConversationMessageInput;
137
134
  type CreateTransform = "extract-markdown" | "preserve";
138
135
  interface CreateInput {
139
- entityType: string;
140
- prompt?: string;
141
- title?: string;
142
- content?: string;
143
- url?: string;
144
- from?: CreateFromInput;
145
- transform?: CreateTransform;
146
- replace?: boolean;
147
- sourceEntityType?: string;
148
- sourceEntityId?: string;
149
- sourceEntityIds?: string[];
150
- targetEntityType?: string;
151
- targetEntityId?: string;
152
- coverImage?: boolean | CreateCoverImageInput;
136
+ entityType: string;
137
+ prompt?: string;
138
+ title?: string;
139
+ content?: string;
140
+ url?: string;
141
+ from?: CreateFromInput;
142
+ transform?: CreateTransform;
143
+ replace?: boolean;
144
+ sourceEntityType?: string;
145
+ sourceEntityId?: string;
146
+ sourceEntityIds?: string[];
147
+ targetEntityType?: string;
148
+ targetEntityId?: string;
149
+ coverImage?: boolean | CreateCoverImageInput;
153
150
  }
154
151
  /**
155
152
  * Minimal caller context forwarded to plugin create interceptors.
156
153
  */
157
154
  interface CreateExecutionContext {
158
- interfaceType: string;
159
- userId: string;
160
- channelId?: string;
161
- channelName?: string;
155
+ interfaceType: string;
156
+ userId: string;
157
+ channelId?: string;
158
+ channelName?: string;
162
159
  }
163
160
  /**
164
161
  * Result returned to system_create when a plugin fully handles creation.
165
162
  */
166
163
  declare const createResultAttachmentSchema: z.ZodObject<{
167
- mediaType: z.ZodString;
168
- url: z.ZodString;
169
- downloadUrl: z.ZodOptional<z.ZodString>;
170
- previewUrl: z.ZodOptional<z.ZodString>;
171
- filename: z.ZodOptional<z.ZodString>;
172
- sizeBytes: z.ZodOptional<z.ZodNumber>;
173
- source: z.ZodOptional<z.ZodObject<{
174
- entityType: z.ZodOptional<z.ZodString>;
175
- entityId: z.ZodOptional<z.ZodString>;
176
- attachmentType: z.ZodOptional<z.ZodString>;
177
- }>>;
164
+ mediaType: z.ZodString;
165
+ url: z.ZodString;
166
+ downloadUrl: z.ZodOptional<z.ZodString>;
167
+ previewUrl: z.ZodOptional<z.ZodString>;
168
+ filename: z.ZodOptional<z.ZodString>;
169
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
170
+ source: z.ZodOptional<z.ZodObject<{
171
+ entityType: z.ZodOptional<z.ZodString>;
172
+ entityId: z.ZodOptional<z.ZodString>;
173
+ attachmentType: z.ZodOptional<z.ZodString>;
174
+ }>>;
178
175
  }>;
179
176
  type CreateResultAttachment = z.infer<typeof createResultAttachmentSchema>;
180
177
  type CreateResult = {
181
- success: true;
182
- data: {
183
- entityId?: string;
184
- jobId?: string;
185
- status: string;
186
- attachment?: CreateResultAttachment;
187
- };
178
+ success: true;
179
+ data: {
180
+ entityId?: string;
181
+ jobId?: string;
182
+ status: string;
183
+ attachment?: CreateResultAttachment;
184
+ };
188
185
  } | {
189
- success: false;
190
- error: string;
186
+ success: false;
187
+ error: string;
191
188
  };
192
189
  /**
193
190
  * Plugin create interceptors can either fully handle creation,
194
191
  * or continue with a rewritten normalized input.
195
192
  */
196
193
  type CreateInterceptionResult = {
197
- kind: "handled";
198
- result: CreateResult;
194
+ kind: "handled";
195
+ result: CreateResult;
199
196
  } | {
200
- kind: "continue";
201
- input: CreateInput;
197
+ kind: "continue";
198
+ input: CreateInput;
202
199
  };
203
200
  type CreateInterceptor = (input: CreateInput, executionContext: CreateExecutionContext) => Promise<CreateInterceptionResult>;
204
201
  /**
@@ -209,177 +206,177 @@ type CreateInterceptor = (input: CreateInput, executionContext: CreateExecutionC
209
206
  * @template TMetadata - The metadata type (defaults to Record<string, unknown>)
210
207
  */
211
208
  interface EntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata = Record<string, unknown>> {
212
- entityType: string;
213
- /**
214
- * One declarative sentence describing what this entity type is. This is the
215
- * data the model reads to select `entityType`, replacing hardcoded example
216
- * phrasings in system instructions. Required: every type must define itself.
217
- */
218
- purpose: string;
219
- schema: EntitySchema<TEntity>;
220
- toMarkdown(entity: TEntity): string;
221
- fromMarkdown(markdown: string): Partial<TEntity>;
222
- extractMetadata(entity: TEntity): TMetadata;
223
- parseFrontMatter<TFrontmatter>(markdown: string, schema: {
224
- parse(data: unknown): TFrontmatter;
225
- }): TFrontmatter;
226
- generateFrontMatter(entity: TEntity): string;
227
- /** Optional: Zod schema for frontmatter fields. Used by CMS config generation. */
228
- frontmatterSchema?: z.ZodObject<z.ZodRawShape>;
229
- /** Optional: Declares this entity type is a singleton (one file, e.g., identity/identity.md). Used by CMS to generate files collection. */
230
- isSingleton?: boolean;
231
- /** Optional: Whether this entity has a free-form markdown body below frontmatter. Defaults to true. When false, CMS omits the body widget. */
232
- hasBody?: boolean;
233
- /** Returns a markdown body template with section headings for this entity type. Empty string for free-form entities. */
234
- getBodyTemplate(): string;
235
- /** Optional: Declares that this entity type supports cover images via coverImageId in frontmatter */
236
- supportsCoverImage?: boolean;
237
- /** Optional: Extract coverImageId from entity content/frontmatter */
238
- getCoverImageId?(entity: TEntity): string | undefined;
239
- /**
240
- * Optional: build the markdown content and metadata for a queued-generation stub.
241
- * When undefined, this entity type does not support prompt-based queued creation
242
- * via system_create; the tool will reject the call rather than silently degrade.
243
- * The returned metadata must satisfy this entity's metadata schema (with
244
- * status set to "generating"); central code only stamps id/timestamps/visibility.
245
- */
246
- buildStub?(input: {
247
- id: string;
248
- title: string;
249
- }): {
250
- content: string;
251
- metadata: TMetadata;
252
- };
209
+ entityType: string;
210
+ /**
211
+ * One declarative sentence describing what this entity type is. This is the
212
+ * data the model reads to select `entityType`, replacing hardcoded example
213
+ * phrasings in system instructions. Required: every type must define itself.
214
+ */
215
+ purpose: string;
216
+ schema: EntitySchema<TEntity>;
217
+ toMarkdown(entity: TEntity): string;
218
+ fromMarkdown(markdown: string): Partial<TEntity>;
219
+ extractMetadata(entity: TEntity): TMetadata;
220
+ parseFrontMatter<TFrontmatter>(markdown: string, schema: {
221
+ parse(data: unknown): TFrontmatter;
222
+ }): TFrontmatter;
223
+ generateFrontMatter(entity: TEntity): string;
224
+ /** Optional: Zod schema for frontmatter fields. Used by CMS config generation. */
225
+ frontmatterSchema?: z.ZodObject<z.ZodRawShape>;
226
+ /** Optional: Declares this entity type is a singleton (one file, e.g., identity/identity.md). Used by CMS to generate files collection. */
227
+ isSingleton?: boolean;
228
+ /** Optional: Whether this entity has a free-form markdown body below frontmatter. Defaults to true. When false, CMS omits the body widget. */
229
+ hasBody?: boolean;
230
+ /** Returns a markdown body template with section headings for this entity type. Empty string for free-form entities. */
231
+ getBodyTemplate(): string;
232
+ /** Optional: Declares that this entity type supports cover images via coverImageId in frontmatter */
233
+ supportsCoverImage?: boolean;
234
+ /** Optional: Extract coverImageId from entity content/frontmatter */
235
+ getCoverImageId?(entity: TEntity): string | undefined;
236
+ /**
237
+ * Optional: build the markdown content and metadata for a queued-generation stub.
238
+ * When undefined, this entity type does not support prompt-based queued creation
239
+ * via system_create; the tool will reject the call rather than silently degrade.
240
+ * The returned metadata must satisfy this entity's metadata schema (with
241
+ * status set to "generating"); central code only stamps id/timestamps/visibility.
242
+ */
243
+ buildStub?(input: {
244
+ id: string;
245
+ title: string;
246
+ }): {
247
+ content: string;
248
+ metadata: TMetadata;
249
+ };
253
250
  }
254
251
  /**
255
252
  * Sort field specification for multi-field sorting
256
253
  */
257
254
  interface SortField {
258
- /** Field to sort by - "created", "updated", or a metadata field name */
259
- field: string;
260
- /** Sort direction */
261
- direction: "asc" | "desc";
262
- /** Sort NULL values before non-NULL values (default: false / SQLite default) */
263
- nullsFirst?: boolean;
255
+ /** Field to sort by - "created", "updated", or a metadata field name */
256
+ field: string;
257
+ /** Sort direction */
258
+ direction: "asc" | "desc";
259
+ /** Sort NULL values before non-NULL values (default: false / SQLite default) */
260
+ nullsFirst?: boolean;
264
261
  }
265
262
  /**
266
263
  * List entities options
267
264
  * Generic over metadata type for type-safe filtering
268
265
  */
269
266
  interface ListOptions<TMetadata = Record<string, unknown>> {
270
- limit?: number;
271
- offset?: number;
272
- /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
273
- sortFields?: SortField[];
274
- filter?: {
275
- metadata?: Partial<TMetadata>;
276
- visibilityScope?: ContentVisibility;
277
- };
278
- /** Filter to only entities with metadata.status = "published" */
279
- publishedOnly?: boolean;
267
+ limit?: number;
268
+ offset?: number;
269
+ /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
270
+ sortFields?: SortField[];
271
+ filter?: {
272
+ metadata?: Partial<TMetadata>;
273
+ visibilityScope?: ContentVisibility;
274
+ };
275
+ /** Filter to only entities with metadata.status = "published" */
276
+ publishedOnly?: boolean;
280
277
  }
281
278
  /**
282
279
  * Search options
283
280
  */
284
281
  interface SearchOptions {
285
- limit?: number;
286
- offset?: number;
287
- types?: string[];
288
- excludeTypes?: string[];
289
- sortBy?: "relevance" | "created" | "updated";
290
- sortDirection?: "asc" | "desc";
291
- /** Score multipliers per entity type - applied after initial search */
292
- weight?: Record<string, number>;
293
- visibilityScope?: ContentVisibility;
294
- /** Include queued/failed generation stubs in search results (default: false) */
295
- includeUngenerated?: boolean;
296
- /** Minimum relevance score to return. Omit for no score cutoff. */
297
- minScore?: number;
282
+ limit?: number;
283
+ offset?: number;
284
+ types?: string[];
285
+ excludeTypes?: string[];
286
+ sortBy?: "relevance" | "created" | "updated";
287
+ sortDirection?: "asc" | "desc";
288
+ /** Score multipliers per entity type - applied after initial search */
289
+ weight?: Record<string, number>;
290
+ visibilityScope?: ContentVisibility;
291
+ /** Include queued/failed generation stubs in search results (default: false) */
292
+ includeUngenerated?: boolean;
293
+ /** Minimum relevance score to return. Omit for no score cutoff. */
294
+ minScore?: number;
298
295
  }
299
296
  /**
300
297
  * Configuration for entity type registration
301
298
  */
302
299
  interface EntityTypeConfig {
303
- /** Score multiplier for search results (default: 1.0) */
304
- weight?: number;
305
- /** Whether to generate embeddings for this entity type (default: true).
306
- * Set to false for entity types with non-textual content (e.g., images). */
307
- embeddable?: boolean;
308
- /** Whether this entity type may be used as source material for derived projections (default: true).
309
- * Set to false for projection outputs that would create feedback loops. */
310
- projectionSource?: boolean;
311
- /** Publish semantics for status-bearing entity types. Statuses listed here
312
- * represent publication commitment/execution states and require the
313
- * `publish` entity action when entered or modified. */
314
- publish?: {
315
- publishStatuses: string[];
316
- };
300
+ /** Score multiplier for search results (default: 1.0) */
301
+ weight?: number;
302
+ /** Whether to generate embeddings for this entity type (default: true).
303
+ * Set to false for entity types with non-textual content (e.g., images). */
304
+ embeddable?: boolean;
305
+ /** Whether this entity type may be used as source material for derived projections (default: true).
306
+ * Set to false for projection outputs that would create feedback loops. */
307
+ projectionSource?: boolean;
308
+ /** Publish semantics for status-bearing entity types. Statuses listed here
309
+ * represent publication commitment/execution states and require the
310
+ * `publish` entity action when entered or modified. */
311
+ publish?: {
312
+ publishStatuses: string[];
313
+ };
317
314
  }
318
315
  /**
319
316
  * Core entity service interface for read-only operations
320
317
  * Used by core plugins that need entity access but shouldn't modify entities
321
318
  */
322
319
  interface GetEntityRequest {
323
- entityType: string;
324
- id: string;
325
- /**
326
- * Optional visibility scope. Undefined fails closed to "public" — callers
327
- * with elevated access must opt up explicitly.
328
- */
329
- visibilityScope?: ContentVisibility;
320
+ entityType: string;
321
+ id: string;
322
+ /**
323
+ * Optional visibility scope. Undefined fails closed to "public" — callers
324
+ * with elevated access must opt up explicitly.
325
+ */
326
+ visibilityScope?: ContentVisibility;
330
327
  }
331
328
  type GetEntityRawRequest = GetEntityRequest;
332
329
  interface ListEntitiesRequest {
333
- entityType: string;
334
- options?: ListOptions | undefined;
330
+ entityType: string;
331
+ options?: ListOptions | undefined;
335
332
  }
336
333
  interface CountEntitiesRequest {
337
- entityType: string;
338
- options?: Pick<ListOptions, "publishedOnly" | "filter"> | undefined;
334
+ entityType: string;
335
+ options?: Pick<ListOptions, "publishedOnly" | "filter"> | undefined;
339
336
  }
340
337
  interface CreateEntityRequest<T extends BaseEntity> {
341
- entity: EntityInput<T>;
342
- options?: CreateEntityOptions | undefined;
338
+ entity: EntityInput<T>;
339
+ options?: CreateEntityOptions | undefined;
343
340
  }
344
341
  interface CreateEntityFromMarkdownRequest {
345
- input: CreateEntityFromMarkdownInput;
346
- options?: CreateEntityOptions | undefined;
342
+ input: CreateEntityFromMarkdownInput;
343
+ options?: CreateEntityOptions | undefined;
347
344
  }
348
345
  interface UpdateEntityRequest<T extends BaseEntity> {
349
- entity: T;
350
- options?: EntityJobOptions | undefined;
346
+ entity: T;
347
+ options?: EntityJobOptions | undefined;
351
348
  }
352
349
  interface DeleteEntityRequest {
353
- entityType: string;
354
- id: string;
350
+ entityType: string;
351
+ id: string;
355
352
  }
356
353
  interface UpsertEntityRequest<T extends BaseEntity> {
357
- entity: T;
358
- options?: EntityJobOptions | undefined;
354
+ entity: T;
355
+ options?: EntityJobOptions | undefined;
359
356
  }
360
357
  interface EntitySearchRequest {
361
- query: string;
362
- options?: SearchOptions | undefined;
358
+ query: string;
359
+ options?: SearchOptions | undefined;
363
360
  }
364
361
  interface SearchWithDistancesRequest {
365
- query: string;
362
+ query: string;
366
363
  }
367
364
  /**
368
365
  * Context passed to all DataSource operations
369
366
  * Contains internal state that should not be mixed with user query parameters
370
367
  */
371
368
  interface BaseDataSourceContext {
372
- /**
373
- * Whether to filter to only published/complete content
374
- * Set by site-builder: true for production, false for preview
375
- */
376
- publishedOnly?: boolean;
377
- /**
378
- * Scoped entity service that auto-applies publishedOnly filter
379
- * Datasources should use this instead of their injected entityService
380
- * to ensure consistent filtering behavior across environments
381
- */
382
- entityService: EntityService;
369
+ /**
370
+ * Whether to filter to only published/complete content
371
+ * Set by site-builder: true for production, false for preview
372
+ */
373
+ publishedOnly?: boolean;
374
+ /**
375
+ * Scoped entity service that auto-applies publishedOnly filter
376
+ * Datasources should use this instead of their injected entityService
377
+ * to ensure consistent filtering behavior across environments
378
+ */
379
+ entityService: EntityService;
383
380
  }
384
381
  /**
385
382
  * DataSource Interface
@@ -389,138 +386,137 @@ interface BaseDataSourceContext {
389
386
  * via their dataSourceId property.
390
387
  */
391
388
  interface DataSource {
392
- /**
393
- * Unique identifier for this data source
394
- */
395
- id: string;
396
- /**
397
- * Human-readable name for this data source
398
- */
399
- name: string;
400
- /**
401
- * Optional description of what this data source provides
402
- */
403
- description?: string;
404
- /**
405
- * Optional: Fetch existing data
406
- * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
407
- * DataSources validate output using the provided schema
408
- * @param query - Query parameters for fetching data
409
- * @param outputSchema - Schema for validating output data
410
- * @param context - Context with environment
411
- */
412
- fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
413
- /**
414
- * Optional: Generate new content
415
- * Used by data sources that create content (e.g., AI-generated content, reports)
416
- */
417
- generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
418
- /**
419
- * Optional: Transform content between formats
420
- * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
421
- */
422
- transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
389
+ /**
390
+ * Unique identifier for this data source
391
+ */
392
+ id: string;
393
+ /**
394
+ * Human-readable name for this data source
395
+ */
396
+ name: string;
397
+ /**
398
+ * Optional description of what this data source provides
399
+ */
400
+ description?: string;
401
+ /**
402
+ * Optional: Fetch existing data
403
+ * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
404
+ * DataSources validate output using the provided schema
405
+ * @param query - Query parameters for fetching data
406
+ * @param outputSchema - Schema for validating output data
407
+ * @param context - Context with environment
408
+ */
409
+ fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
410
+ /**
411
+ * Optional: Generate new content
412
+ * Used by data sources that create content (e.g., AI-generated content, reports)
413
+ */
414
+ generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
415
+ /**
416
+ * Optional: Transform content between formats
417
+ * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
418
+ */
419
+ transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
423
420
  }
424
421
  /**
425
422
  * DataSource capabilities for discovery and validation
426
423
  */
427
424
  interface DataSourceCapabilities {
428
- canFetch: boolean;
429
- canGenerate: boolean;
430
- canTransform: boolean;
425
+ canFetch: boolean;
426
+ canGenerate: boolean;
427
+ canTransform: boolean;
431
428
  }
432
429
  interface ICoreEntityService {
433
- getEntity<T extends BaseEntity>(request: GetEntityRequest): Promise<T | null>;
434
- /**
435
- * Get entity without content resolution (raw)
436
- * Used internally to avoid recursion when resolving image references
437
- */
438
- getEntityRaw<T extends BaseEntity>(request: GetEntityRawRequest): Promise<T | null>;
439
- listEntities<T extends BaseEntity>(request: ListEntitiesRequest): Promise<T[]>;
440
- search<T extends BaseEntity = BaseEntity>(request: EntitySearchRequest): Promise<SearchResult<T>[]>;
441
- getEntityTypes(): string[];
442
- hasEntityType(type: string): boolean;
443
- countEntities(request: CountEntitiesRequest): Promise<number>;
444
- /**
445
- * Group counts by entity type. Fails closed: undefined visibilityScope
446
- * filters to public-only counts so aggregate insights cannot reveal
447
- * non-public entity existence.
448
- */
449
- getEntityCounts(visibilityScope?: ContentVisibility): Promise<Array<{
450
- entityType: string;
451
- count: number;
452
- }>>;
453
- /** Get configuration for a specific entity type */
454
- getEntityTypeConfig(type: string): EntityTypeConfig;
455
- /** Get weight map for all registered entity types with non-default weights */
456
- getWeightMap(): Record<string, number>;
430
+ getEntity<T extends BaseEntity>(request: GetEntityRequest): Promise<T | null>;
431
+ /**
432
+ * Get entity without content resolution (raw)
433
+ * Used internally to avoid recursion when resolving image references
434
+ */
435
+ getEntityRaw<T extends BaseEntity>(request: GetEntityRawRequest): Promise<T | null>;
436
+ listEntities<T extends BaseEntity>(request: ListEntitiesRequest): Promise<T[]>;
437
+ search<T extends BaseEntity = BaseEntity>(request: EntitySearchRequest): Promise<SearchResult<T>[]>;
438
+ getEntityTypes(): string[];
439
+ hasEntityType(type: string): boolean;
440
+ countEntities(request: CountEntitiesRequest): Promise<number>;
441
+ /**
442
+ * Group counts by entity type. Fails closed: undefined visibilityScope
443
+ * filters to public-only counts so aggregate insights cannot reveal
444
+ * non-public entity existence.
445
+ */
446
+ getEntityCounts(visibilityScope?: ContentVisibility): Promise<Array<{
447
+ entityType: string;
448
+ count: number;
449
+ }>>;
450
+ /** Get configuration for a specific entity type */
451
+ getEntityTypeConfig(type: string): EntityTypeConfig;
452
+ /** Get weight map for all registered entity types with non-default weights */
453
+ getWeightMap(): Record<string, number>;
457
454
  }
458
455
  interface EmbeddingBackfillResult {
459
- queued: number;
460
- skipped: number;
456
+ queued: number;
457
+ skipped: number;
461
458
  }
462
459
  interface EmbeddingIndexStats {
463
- missingEmbeddings: number;
464
- staleEmbeddings: number;
465
- failedEmbeddings: number;
466
- /** Entities whose type generates embeddings (non-embeddable types excluded). */
467
- embeddableEntities: number;
468
- /** Embeddable entities whose embedding is present and current. */
469
- embeddedEntities: number;
460
+ missingEmbeddings: number;
461
+ staleEmbeddings: number;
462
+ failedEmbeddings: number;
463
+ /** Entities whose type generates embeddings (non-embeddable types excluded). */
464
+ embeddableEntities: number;
465
+ /** Embeddable entities whose embedding is present and current. */
466
+ embeddedEntities: number;
470
467
  }
471
468
  interface IndexReadinessOptions {
472
- timeoutMs: number;
473
- intervalMs?: number;
469
+ timeoutMs: number;
470
+ intervalMs?: number;
474
471
  }
475
472
  interface IndexReadinessStatus extends EmbeddingIndexStats {
476
- ready: boolean;
477
- degraded: boolean;
478
- activeEmbeddingJobs: number;
473
+ ready: boolean;
474
+ degraded: boolean;
475
+ activeEmbeddingJobs: number;
479
476
  }
480
477
  interface EntityService extends ICoreEntityService {
481
- createEntity<T extends BaseEntity>(request: CreateEntityRequest<T>): Promise<EntityMutationResult>;
482
- createEntityFromMarkdown(request: CreateEntityFromMarkdownRequest): Promise<EntityMutationResult>;
483
- updateEntity<T extends BaseEntity>(request: UpdateEntityRequest<T>): Promise<EntityMutationResult>;
484
- deleteEntity(request: DeleteEntityRequest): Promise<boolean>;
485
- upsertEntity<T extends BaseEntity>(request: UpsertEntityRequest<T>): Promise<EntityMutationResult & {
486
- created: boolean;
487
- }>;
488
- storeEmbedding(data: StoreEmbeddingData): Promise<void>;
489
- backfillMissingEmbeddings(): Promise<EmbeddingBackfillResult>;
490
- isIndexReady(): boolean;
491
- awaitIndexReady(options: IndexReadinessOptions): Promise<IndexReadinessStatus>;
492
- serializeEntity(entity: BaseEntity): string;
493
- deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
494
- countEmbeddings(): Promise<number>;
495
- searchWithDistances(request: SearchWithDistancesRequest): Promise<Array<{
496
- entityId: string;
497
- entityType: string;
498
- distance: number;
499
- }>>;
500
- initialize(): Promise<void>;
501
- getAsyncJobStatus(jobId: string): Promise<{
502
- status: "pending" | "processing" | "completed" | "failed";
503
- error?: string;
504
- } | null>;
505
- }
506
-
478
+ createEntity<T extends BaseEntity>(request: CreateEntityRequest<T>): Promise<EntityMutationResult>;
479
+ createEntityFromMarkdown(request: CreateEntityFromMarkdownRequest): Promise<EntityMutationResult>;
480
+ updateEntity<T extends BaseEntity>(request: UpdateEntityRequest<T>): Promise<EntityMutationResult>;
481
+ deleteEntity(request: DeleteEntityRequest): Promise<boolean>;
482
+ upsertEntity<T extends BaseEntity>(request: UpsertEntityRequest<T>): Promise<EntityMutationResult & {
483
+ created: boolean;
484
+ }>;
485
+ storeEmbedding(data: StoreEmbeddingData): Promise<void>;
486
+ backfillMissingEmbeddings(): Promise<EmbeddingBackfillResult>;
487
+ isIndexReady(): boolean;
488
+ awaitIndexReady(options: IndexReadinessOptions): Promise<IndexReadinessStatus>;
489
+ serializeEntity(entity: BaseEntity): string;
490
+ deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
491
+ countEmbeddings(): Promise<number>;
492
+ searchWithDistances(request: SearchWithDistancesRequest): Promise<Array<{
493
+ entityId: string;
494
+ entityType: string;
495
+ distance: number;
496
+ }>>;
497
+ initialize(): Promise<void>;
498
+ getAsyncJobStatus(jobId: string): Promise<{
499
+ status: "pending" | "processing" | "completed" | "failed";
500
+ error?: string;
501
+ } | null>;
502
+ }
503
+ //#endregion
504
+ //#region ../../shell/entity-service/src/adapters/base-entity-adapter.d.ts
507
505
  /** Interface for objects that can generate a body template. */
508
506
  interface BodyTemplateProvider {
509
- generateBodyTemplate(): string;
507
+ generateBodyTemplate(): string;
510
508
  }
511
- type DefaultEntityFrontmatter<TMetadata extends object> = {
512
- [K in keyof TMetadata]?: TMetadata[K] | undefined;
513
- };
509
+ type DefaultEntityFrontmatter<TMetadata extends object> = { [K in keyof TMetadata]?: TMetadata[K] | undefined; };
514
510
  type BaseEntityFrontmatterSchema<TFrontmatter> = z.ZodObject<z.ZodRawShape> & z.ZodType<TFrontmatter>;
515
511
  interface BaseEntityAdapterConfig<TEntity extends BaseEntity<TMetadata>, TMetadata extends object, TFrontmatter = DefaultEntityFrontmatter<TMetadata>> {
516
- entityType: string;
517
- purpose: string;
518
- schema: EntitySchema<TEntity>;
519
- frontmatterSchema: BaseEntityFrontmatterSchema<TFrontmatter>;
520
- isSingleton?: boolean;
521
- hasBody?: boolean;
522
- supportsCoverImage?: boolean;
523
- bodyFormatter?: BodyTemplateProvider;
512
+ entityType: string;
513
+ purpose: string;
514
+ schema: EntitySchema<TEntity>;
515
+ frontmatterSchema: BaseEntityFrontmatterSchema<TFrontmatter>;
516
+ isSingleton?: boolean;
517
+ hasBody?: boolean;
518
+ supportsCoverImage?: boolean;
519
+ bodyFormatter?: BodyTemplateProvider;
524
520
  }
525
521
  /**
526
522
  * Abstract base class for entity adapters.
@@ -532,82 +528,79 @@ interface BaseEntityAdapterConfig<TEntity extends BaseEntity<TMetadata>, TMetada
532
528
  * Subclasses must implement toMarkdown() and fromMarkdown().
533
529
  */
534
530
  declare abstract class BaseEntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata extends object = Record<string, unknown>, TFrontmatter = DefaultEntityFrontmatter<TMetadata>> implements EntityAdapter<TEntity, TMetadata> {
535
- readonly entityType: string;
536
- readonly purpose: string;
537
- readonly schema: EntitySchema<TEntity>;
538
- readonly frontmatterSchema: z.ZodObject<z.ZodRawShape>;
539
- readonly isSingleton?: boolean;
540
- readonly hasBody?: boolean;
541
- readonly supportsCoverImage?: boolean;
542
- private readonly fmSchema;
543
- private readonly bodyFormatter;
544
- constructor(config: BaseEntityAdapterConfig<TEntity, TMetadata, TFrontmatter>);
545
- abstract fromMarkdown(markdown: string): Partial<TEntity>;
546
- /**
547
- * Serialize an entity to markdown.
548
- *
549
- * Rebuilds frontmatter from entity.metadata overlaid on any existing
550
- * frontmatter parsed from entity.content. Body comes from renderBody,
551
- * which defaults to the body portion of entity.content (frontmatter
552
- * stripped).
553
- *
554
- * Adapters that want the body to reflect typed fields (e.g. a
555
- * structured about/skills section) override renderBody. Adapters that
556
- * need entirely custom serialization override toMarkdown.
557
- */
558
- toMarkdown(entity: TEntity): string;
559
- /**
560
- * Render the body section of the entity.
561
- *
562
- * Default returns the body portion of entity.content (frontmatter
563
- * stripped). Override when the body should be rebuilt from typed
564
- * fields on the entity.
565
- */
566
- protected renderBody(entity: TEntity): string;
567
- private readExistingFrontmatter;
568
- extractMetadata(entity: TEntity): TMetadata;
569
- parseFrontMatter<T>(markdown: string, schema: {
570
- parse(data: unknown): T;
571
- }): T;
572
- getBodyTemplate(): string;
573
- generateFrontMatter(entity: TEntity): string;
574
- /** Strip frontmatter and return the body content. */
575
- protected extractBody(markdown: string): string;
576
- /** Parse frontmatter using this adapter's frontmatter schema. */
577
- protected parseFrontmatter(markdown: string): TFrontmatter;
578
- /** Combine body and frontmatter into a markdown string. */
579
- protected buildMarkdown(body: string, frontmatter: Record<string, unknown>): string;
580
- }
581
-
531
+ readonly entityType: string;
532
+ readonly purpose: string;
533
+ readonly schema: EntitySchema<TEntity>;
534
+ readonly frontmatterSchema: z.ZodObject<z.ZodRawShape>;
535
+ readonly isSingleton?: boolean;
536
+ readonly hasBody?: boolean;
537
+ readonly supportsCoverImage?: boolean;
538
+ private readonly fmSchema;
539
+ private readonly bodyFormatter;
540
+ constructor(config: BaseEntityAdapterConfig<TEntity, TMetadata, TFrontmatter>);
541
+ abstract fromMarkdown(markdown: string): Partial<TEntity>;
542
+ /**
543
+ * Serialize an entity to markdown.
544
+ *
545
+ * Rebuilds frontmatter from entity.metadata overlaid on any existing
546
+ * frontmatter parsed from entity.content. Body comes from renderBody,
547
+ * which defaults to the body portion of entity.content (frontmatter
548
+ * stripped).
549
+ *
550
+ * Adapters that want the body to reflect typed fields (e.g. a
551
+ * structured about/skills section) override renderBody. Adapters that
552
+ * need entirely custom serialization override toMarkdown.
553
+ */
554
+ toMarkdown(entity: TEntity): string;
555
+ /**
556
+ * Render the body section of the entity.
557
+ *
558
+ * Default returns the body portion of entity.content (frontmatter
559
+ * stripped). Override when the body should be rebuilt from typed
560
+ * fields on the entity.
561
+ */
562
+ protected renderBody(entity: TEntity): string;
563
+ private readExistingFrontmatter;
564
+ extractMetadata(entity: TEntity): TMetadata;
565
+ parseFrontMatter<T>(markdown: string, schema: {
566
+ parse(data: unknown): T;
567
+ }): T;
568
+ getBodyTemplate(): string;
569
+ generateFrontMatter(entity: TEntity): string;
570
+ /** Strip frontmatter and return the body content. */
571
+ protected extractBody(markdown: string): string;
572
+ /** Parse frontmatter using this adapter's frontmatter schema. */
573
+ protected parseFrontmatter(markdown: string): TFrontmatter;
574
+ /** Combine body and frontmatter into a markdown string. */
575
+ protected buildMarkdown(body: string, frontmatter: Record<string, unknown>): string;
576
+ }
577
+ //#endregion
578
+ //#region ../../shell/entity-service/src/frontmatter.d.ts
582
579
  /**
583
580
  * Configuration for frontmatter handling
584
581
  */
585
582
  interface FrontmatterConfig<T extends BaseEntity> {
586
- /**
587
- * Fields to explicitly include in frontmatter
588
- * If not specified, includes all non-system fields
589
- */
590
- includeFields?: (keyof T)[];
591
- /**
592
- * Fields to exclude from frontmatter
593
- * By default excludes: id, entityType, content, created, updated
594
- */
595
- excludeFields?: (keyof T)[];
596
- /**
597
- * Custom serializers for complex fields
598
- */
599
- customSerializers?: {
600
- [K in keyof T]?: (value: T[K]) => unknown;
601
- };
602
- /**
603
- * Custom deserializers for complex fields
604
- */
605
- customDeserializers?: {
606
- [K in keyof T]?: (value: unknown) => T[K];
607
- };
583
+ /**
584
+ * Fields to explicitly include in frontmatter
585
+ * If not specified, includes all non-system fields
586
+ */
587
+ includeFields?: (keyof T)[];
588
+ /**
589
+ * Fields to exclude from frontmatter
590
+ * By default excludes: id, entityType, content, created, updated
591
+ */
592
+ excludeFields?: (keyof T)[];
593
+ /**
594
+ * Custom serializers for complex fields
595
+ */
596
+ customSerializers?: { [K in keyof T]?: (value: T[K]) => unknown; };
597
+ /**
598
+ * Custom deserializers for complex fields
599
+ */
600
+ customDeserializers?: { [K in keyof T]?: (value: unknown) => T[K]; };
608
601
  }
609
602
  interface FrontmatterValidationSchema<T> {
610
- parse(data: unknown): T;
603
+ parse(data: unknown): T;
611
604
  }
612
605
  /**
613
606
  * Generate markdown with frontmatter from content and metadata
@@ -617,25 +610,26 @@ declare function generateMarkdownWithFrontmatter(content: string, metadata: Reco
617
610
  * Parse markdown with frontmatter into content and metadata
618
611
  */
619
612
  declare function parseMarkdownWithFrontmatter<T>(markdown: string, schema: FrontmatterValidationSchema<T>): {
620
- content: string;
621
- metadata: T;
613
+ content: string;
614
+ metadata: T;
622
615
  };
623
616
  /**
624
617
  * Generate frontmatter string from metadata
625
618
  */
626
619
  declare function generateFrontmatter(metadata: Record<string, unknown>): string;
627
-
620
+ //#endregion
621
+ //#region ../../shell/entity-service/src/pagination.d.ts
628
622
  /**
629
623
  * Schema for pagination information
630
624
  * Used by datasources that return paginated lists
631
625
  */
632
626
  declare const paginationInfoSchema: z.ZodObject<{
633
- currentPage: z.ZodNumber;
634
- totalPages: z.ZodNumber;
635
- totalItems: z.ZodNumber;
636
- pageSize: z.ZodNumber;
637
- hasNextPage: z.ZodBoolean;
638
- hasPrevPage: z.ZodBoolean;
627
+ currentPage: z.ZodNumber;
628
+ totalPages: z.ZodNumber;
629
+ totalItems: z.ZodNumber;
630
+ pageSize: z.ZodNumber;
631
+ hasNextPage: z.ZodBoolean;
632
+ hasPrevPage: z.ZodBoolean;
639
633
  }>;
640
634
  /**
641
635
  * Pagination information type
@@ -650,16 +644,16 @@ declare function buildPaginationInfo(totalItems: number, page: number, pageSize:
650
644
  * Options for paginating items
651
645
  */
652
646
  interface PaginateOptions {
653
- page?: number | undefined;
654
- limit?: number | undefined;
655
- pageSize?: number | undefined;
647
+ page?: number | undefined;
648
+ limit?: number | undefined;
649
+ pageSize?: number | undefined;
656
650
  }
657
651
  /**
658
652
  * Result of paginating items
659
653
  */
660
654
  interface PaginateResult<T> {
661
- items: T[];
662
- pagination: PaginationInfo | null;
655
+ items: T[];
656
+ pagination: PaginationInfo | null;
663
657
  }
664
658
  /**
665
659
  * Paginate a list of items
@@ -673,6 +667,5 @@ interface PaginateResult<T> {
673
667
  * @returns Paginated items and optional pagination info
674
668
  */
675
669
  declare function paginateItems<T>(items: T[], options: PaginateOptions): PaginateResult<T>;
676
-
677
- export { BaseEntityAdapter, NOTE_ENTITY_TYPE, baseEntitySchema, buildPaginationInfo, generateFrontmatter, generateMarkdownWithFrontmatter, paginateItems, paginationInfoSchema, parseMarkdownWithFrontmatter };
678
- export type { BaseDataSourceContext, BaseEntity, CreateExecutionContext, CreateInput, CreateInterceptionResult, CreateInterceptor, CreateResult, DataSource, DataSourceCapabilities, EntityAdapter, EntityInput, EntityMutationResult, EntityTypeConfig, FrontmatterConfig, ListOptions, PaginateOptions, PaginateResult, PaginationInfo, SearchOptions, SearchResult };
670
+ //#endregion
671
+ export { type BaseDataSourceContext, type BaseEntity, BaseEntityAdapter, type CreateExecutionContext, type CreateInput, type CreateInterceptionResult, type CreateInterceptor, type CreateResult, type DataSource, type DataSourceCapabilities, type EntityAdapter, type EntityInput, type EntityMutationResult, type EntityTypeConfig, type FrontmatterConfig, type ListOptions, NOTE_ENTITY_TYPE, type PaginateOptions, type PaginateResult, type PaginationInfo, type SearchOptions, type SearchResult, baseEntitySchema, buildPaginationInfo, generateFrontmatter, generateMarkdownWithFrontmatter, paginateItems, paginationInfoSchema, parseMarkdownWithFrontmatter };