@rizom/brain 0.2.0-alpha.47 → 0.2.0-alpha.49

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,154 +1,521 @@
1
- import type { z } from "zod";
1
+ import { z } from 'zod';
2
2
 
3
- export interface BaseEntity {
4
- id: string;
5
- entityType: string;
6
- content: string;
7
- created: string;
8
- updated: string;
9
- metadata: Record<string, unknown>;
10
- contentHash?: string;
11
- }
12
- export type EntityInput<T extends BaseEntity = BaseEntity> = Omit<
13
- T,
14
- "created" | "updated" | "contentHash"
15
- > &
16
- Partial<Pick<T, "created" | "updated" | "contentHash">>;
17
- export interface EntityMutationResult {
18
- entityId: string;
19
- jobId: string;
20
- }
21
- export interface CreateInput {
22
- entityType: string;
23
- title?: string;
24
- content?: string;
25
- prompt?: string;
26
- url?: string;
27
- [key: string]: unknown;
28
- }
29
- export interface CreateExecutionContext {
30
- interfaceType?: string;
31
- userId?: string;
32
- channelId?: string;
33
- [key: string]: unknown;
34
- }
35
- export interface CreateResult {
36
- entityId: string;
37
- jobId?: string;
38
- entityType: string;
39
- }
40
- export type CreateInterceptionResult =
41
- | { kind: "continue"; input: CreateInput }
42
- | { kind: "handled"; result: CreateResult };
43
- export type CreateInterceptor = (
44
- input: CreateInput,
45
- context: CreateExecutionContext,
46
- ) => Promise<CreateInterceptionResult> | CreateInterceptionResult;
47
-
48
- export interface EntityAdapter<TEntity extends BaseEntity = BaseEntity> {
49
- entityType: string;
50
- schema: z.ZodSchema<TEntity>;
51
- frontmatterSchema?: z.ZodTypeAny;
52
- toMarkdown(entity: TEntity): string;
53
- fromMarkdown(markdown: string, id?: string): TEntity;
54
- }
55
- export interface EntityTypeConfig {
56
- embeddable?: boolean;
57
- weight?: number;
58
- [key: string]: unknown;
59
- }
60
- export class BaseEntityAdapter<
61
- TEntity extends BaseEntity = BaseEntity,
62
- > implements EntityAdapter<TEntity> {
63
- readonly entityType: string;
64
- readonly schema: z.ZodSchema<TEntity>;
65
- readonly frontmatterSchema?: z.ZodTypeAny;
66
- constructor(config: {
3
+ /**
4
+ * Entity type for unstructured notes (the "base" entity type).
5
+ * Used as a sentinel for the default catch-all markdown file shape —
6
+ * no typed frontmatter schema required, content is the entire file body.
7
+ */
8
+ declare const BASE_ENTITY_TYPE = "base";
9
+ /**
10
+ * Options for entity mutation operations (create, update, upsert)
11
+ */
12
+ interface EntityJobOptions {
13
+ priority?: number;
14
+ maxRetries?: number;
15
+ }
16
+ /**
17
+ * Options for entity creation (extends EntityJobOptions with deduplication)
18
+ */
19
+ interface CreateEntityOptions extends EntityJobOptions {
20
+ deduplicateId?: boolean;
21
+ }
22
+ /**
23
+ * Result of an entity mutation that triggers an embedding job.
24
+ * When skipped is true, content was unchanged — no DB write, no event, no embedding job.
25
+ */
26
+ interface EntityMutationResult {
27
+ entityId: string;
28
+ jobId: string;
29
+ skipped: boolean;
30
+ }
31
+ /**
32
+ * Input for adapter-validated direct creation from finalized markdown.
33
+ */
34
+ interface CreateEntityFromMarkdownInput {
35
+ entityType: string;
36
+ id: string;
37
+ markdown: string;
38
+ }
39
+ /**
40
+ * Data for storing an embedding for an entity
41
+ */
42
+ interface StoreEmbeddingData {
43
+ entityId: string;
44
+ entityType: string;
45
+ embedding: Float32Array;
46
+ contentHash: string;
47
+ }
48
+ /**
49
+ * Base entity schema that all entities must extend
50
+ */
51
+ declare const baseEntitySchema: z.ZodObject<{
52
+ id: z.ZodString;
53
+ entityType: z.ZodString;
54
+ content: z.ZodString;
55
+ created: z.ZodString;
56
+ updated: z.ZodString;
57
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
58
+ contentHash: z.ZodString;
59
+ }, "strip", z.ZodTypeAny, {
60
+ id: string;
61
+ entityType: string;
62
+ content: string;
63
+ created: string;
64
+ updated: string;
65
+ metadata: Record<string, unknown>;
66
+ contentHash: string;
67
+ }, {
68
+ id: string;
69
+ entityType: string;
70
+ content: string;
71
+ created: string;
72
+ updated: string;
73
+ metadata: Record<string, unknown>;
74
+ contentHash: string;
75
+ }>;
76
+ /**
77
+ * Base entity type - generic to support typed metadata
78
+ * TMetadata defaults to Record<string, unknown> for backward compatibility
79
+ */
80
+ interface BaseEntity<TMetadata = Record<string, unknown>> {
81
+ id: string;
82
+ entityType: string;
83
+ content: string;
84
+ created: string;
85
+ updated: string;
86
+ metadata: TMetadata;
87
+ /** SHA256 hash of content for change detection */
88
+ contentHash: string;
89
+ }
90
+ /**
91
+ * Entity input type for creation - allows partial entities with optional system fields
92
+ * contentHash is excluded because it's computed automatically by the entity service
93
+ */
94
+ type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash"> & {
95
+ id?: string;
96
+ created?: string;
97
+ updated?: string;
98
+ };
99
+ /**
100
+ * Search result type
101
+ */
102
+ interface SearchResult<T extends BaseEntity = BaseEntity> {
103
+ entity: T;
104
+ score: number;
105
+ excerpt: string;
106
+ }
107
+ /**
108
+ * Normalized system_create input shape used by plugin create interceptors.
109
+ */
110
+ interface CreateInput {
111
+ entityType: string;
112
+ prompt?: string;
113
+ title?: string;
114
+ content?: string;
115
+ url?: string;
116
+ targetEntityType?: string;
117
+ targetEntityId?: string;
118
+ }
119
+ /**
120
+ * Minimal caller context forwarded to plugin create interceptors.
121
+ */
122
+ interface CreateExecutionContext {
123
+ interfaceType: string;
124
+ userId: string;
125
+ channelId?: string;
126
+ channelName?: string;
127
+ }
128
+ /**
129
+ * Result returned to system_create when a plugin fully handles creation.
130
+ */
131
+ type CreateResult = {
132
+ success: true;
133
+ data: {
134
+ entityId?: string;
135
+ jobId?: string;
136
+ status: string;
137
+ };
138
+ } | {
139
+ success: false;
140
+ error: string;
141
+ };
142
+ /**
143
+ * Plugin create interceptors can either fully handle creation,
144
+ * or continue with a rewritten normalized input.
145
+ */
146
+ type CreateInterceptionResult = {
147
+ kind: "handled";
148
+ result: CreateResult;
149
+ } | {
150
+ kind: "continue";
151
+ input: CreateInput;
152
+ };
153
+ type CreateInterceptor = (input: CreateInput, executionContext: CreateExecutionContext) => Promise<CreateInterceptionResult>;
154
+ /**
155
+ * Interface for entity adapter - handles conversion between entities and markdown
156
+ * following the hybrid storage model
157
+ *
158
+ * @template TEntity - The full entity type
159
+ * @template TMetadata - The metadata type (defaults to Record<string, unknown>)
160
+ */
161
+ interface EntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata = Record<string, unknown>> {
67
162
  entityType: string;
68
163
  schema: z.ZodSchema<TEntity>;
69
- frontmatterSchema?: z.ZodTypeAny;
70
- });
71
- toMarkdown(entity: TEntity): string;
72
- fromMarkdown(markdown: string, id?: string): TEntity;
164
+ toMarkdown(entity: TEntity): string;
165
+ fromMarkdown(markdown: string): Partial<TEntity>;
166
+ extractMetadata(entity: TEntity): TMetadata;
167
+ parseFrontMatter<TFrontmatter>(markdown: string, schema: z.ZodSchema<TFrontmatter>): TFrontmatter;
168
+ generateFrontMatter(entity: TEntity): string;
169
+ /** Optional: Zod schema for frontmatter fields. Used by CMS config generation. */
170
+ frontmatterSchema?: z.ZodObject<z.ZodRawShape>;
171
+ /** Optional: Declares this entity type is a singleton (one file, e.g., identity/identity.md). Used by CMS to generate files collection. */
172
+ isSingleton?: boolean;
173
+ /** Optional: Whether this entity has a free-form markdown body below frontmatter. Defaults to true. When false, CMS omits the body widget. */
174
+ hasBody?: boolean;
175
+ /** Returns a markdown body template with section headings for this entity type. Empty string for free-form entities. */
176
+ getBodyTemplate(): string;
177
+ /** Optional: Declares that this entity type supports cover images via coverImageId in frontmatter */
178
+ supportsCoverImage?: boolean;
179
+ /** Optional: Extract coverImageId from entity content/frontmatter */
180
+ getCoverImageId?(entity: TEntity): string | undefined;
181
+ }
182
+ /**
183
+ * Sort field specification for multi-field sorting
184
+ */
185
+ interface SortField {
186
+ /** Field to sort by - "created", "updated", or a metadata field name */
187
+ field: string;
188
+ /** Sort direction */
189
+ direction: "asc" | "desc";
190
+ /** Sort NULL values before non-NULL values (default: false / SQLite default) */
191
+ nullsFirst?: boolean;
192
+ }
193
+ /**
194
+ * List entities options
195
+ * Generic over metadata type for type-safe filtering
196
+ */
197
+ interface ListOptions<TMetadata = Record<string, unknown>> {
198
+ limit?: number;
199
+ offset?: number;
200
+ /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
201
+ sortFields?: SortField[];
202
+ filter?: {
203
+ metadata?: Partial<TMetadata>;
204
+ };
205
+ /** Filter to only entities with metadata.status = "published" */
206
+ publishedOnly?: boolean;
207
+ }
208
+ /**
209
+ * Search options
210
+ */
211
+ interface SearchOptions {
212
+ limit?: number;
213
+ offset?: number;
214
+ types?: string[];
215
+ excludeTypes?: string[];
216
+ sortBy?: "relevance" | "created" | "updated";
217
+ sortDirection?: "asc" | "desc";
218
+ /** Score multipliers per entity type - applied after initial search */
219
+ weight?: Record<string, number>;
220
+ }
221
+ /**
222
+ * Configuration for entity type registration
223
+ */
224
+ interface EntityTypeConfig {
225
+ /** Score multiplier for search results (default: 1.0) */
226
+ weight?: number;
227
+ /** Whether to generate embeddings for this entity type (default: true).
228
+ * Set to false for entity types with non-textual content (e.g., images). */
229
+ embeddable?: boolean;
230
+ }
231
+ /**
232
+ * Core entity service interface for read-only operations
233
+ * Used by core plugins that need entity access but shouldn't modify entities
234
+ */
235
+ interface ICoreEntityService {
236
+ getEntity<T extends BaseEntity>(entityType: string, id: string): Promise<T | null>;
237
+ /**
238
+ * Get entity without content resolution (raw)
239
+ * Used internally to avoid recursion when resolving image references
240
+ */
241
+ getEntityRaw<T extends BaseEntity>(entityType: string, id: string): Promise<T | null>;
242
+ listEntities<T extends BaseEntity>(type: string, options?: ListOptions): Promise<T[]>;
243
+ search<T extends BaseEntity = BaseEntity>(query: string, options?: SearchOptions): Promise<SearchResult<T>[]>;
244
+ getEntityTypes(): string[];
245
+ hasEntityType(type: string): boolean;
246
+ countEntities(entityType: string, options?: Pick<ListOptions, "publishedOnly" | "filter">): Promise<number>;
247
+ getEntityCounts(): Promise<Array<{
248
+ entityType: string;
249
+ count: number;
250
+ }>>;
251
+ /** Get weight map for all registered entity types with non-default weights */
252
+ getWeightMap(): Record<string, number>;
253
+ }
254
+ /**
255
+ * Entity service interface for managing brain entities
256
+ */
257
+ interface EntityService extends ICoreEntityService {
258
+ createEntity<T extends BaseEntity>(entity: EntityInput<T>, options?: CreateEntityOptions): Promise<EntityMutationResult>;
259
+ createEntityFromMarkdown(input: CreateEntityFromMarkdownInput, options?: CreateEntityOptions): Promise<EntityMutationResult>;
260
+ updateEntity<T extends BaseEntity>(entity: T, options?: EntityJobOptions): Promise<EntityMutationResult>;
261
+ deleteEntity(entityType: string, id: string): Promise<boolean>;
262
+ upsertEntity<T extends BaseEntity>(entity: T, options?: EntityJobOptions): Promise<EntityMutationResult & {
263
+ created: boolean;
264
+ }>;
265
+ storeEmbedding(data: StoreEmbeddingData): Promise<void>;
266
+ serializeEntity(entity: BaseEntity): string;
267
+ deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
268
+ countEmbeddings(): Promise<number>;
269
+ searchWithDistances(query: string): Promise<Array<{
270
+ entityId: string;
271
+ entityType: string;
272
+ distance: number;
273
+ }>>;
274
+ initialize(): Promise<void>;
275
+ getAsyncJobStatus(jobId: string): Promise<{
276
+ status: "pending" | "processing" | "completed" | "failed";
277
+ error?: string;
278
+ } | null>;
73
279
  }
74
- export const baseEntitySchema: z.ZodSchema<BaseEntity>;
75
- export const BASE_ENTITY_TYPE: "base";
76
280
 
77
- export interface SearchResult<TEntity extends BaseEntity = BaseEntity> {
78
- entity: TEntity;
79
- score: number;
80
- excerpt?: string;
281
+ /** Interface for objects that can generate a body template. */
282
+ interface BodyTemplateProvider {
283
+ generateBodyTemplate(): string;
81
284
  }
82
- export interface ListOptions {
83
- limit?: number;
84
- offset?: number;
85
- publishedOnly?: boolean;
86
- [key: string]: unknown;
285
+ interface BaseEntityAdapterConfig<TEntity extends BaseEntity<TMetadata>, TMetadata extends object> {
286
+ entityType: string;
287
+ schema: z.ZodSchema<TEntity>;
288
+ frontmatterSchema: z.ZodObject<z.ZodRawShape>;
289
+ isSingleton?: boolean;
290
+ hasBody?: boolean;
291
+ supportsCoverImage?: boolean;
292
+ bodyFormatter?: BodyTemplateProvider;
87
293
  }
88
- export interface SearchOptions extends ListOptions {
89
- entityType?: string;
294
+ /**
295
+ * Abstract base class for entity adapters.
296
+ *
297
+ * Provides default implementations for the 3 boilerplate methods
298
+ * (extractMetadata, parseFrontMatter, generateFrontMatter) and
299
+ * protected helpers for common patterns in toMarkdown/fromMarkdown.
300
+ *
301
+ * Subclasses must implement toMarkdown() and fromMarkdown().
302
+ */
303
+ declare abstract class BaseEntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata extends object = Record<string, unknown>, TFrontmatter = TMetadata> implements EntityAdapter<TEntity, TMetadata> {
304
+ readonly entityType: string;
305
+ readonly schema: z.ZodSchema<TEntity>;
306
+ readonly frontmatterSchema: z.ZodObject<z.ZodRawShape>;
307
+ readonly isSingleton?: boolean;
308
+ readonly hasBody?: boolean;
309
+ readonly supportsCoverImage?: boolean;
310
+ private readonly fmSchema;
311
+ private readonly bodyFormatter;
312
+ constructor(config: BaseEntityAdapterConfig<TEntity, TMetadata>);
313
+ abstract fromMarkdown(markdown: string): Partial<TEntity>;
314
+ /**
315
+ * Serialize an entity to markdown.
316
+ *
317
+ * Rebuilds frontmatter from entity.metadata overlaid on any existing
318
+ * frontmatter parsed from entity.content. Body comes from renderBody,
319
+ * which defaults to the body portion of entity.content (frontmatter
320
+ * stripped).
321
+ *
322
+ * Adapters that want the body to reflect typed fields (e.g. a
323
+ * structured about/skills section) override renderBody. Adapters that
324
+ * need entirely custom serialization override toMarkdown.
325
+ */
326
+ toMarkdown(entity: TEntity): string;
327
+ /**
328
+ * Render the body section of the entity.
329
+ *
330
+ * Default returns the body portion of entity.content (frontmatter
331
+ * stripped). Override when the body should be rebuilt from typed
332
+ * fields on the entity.
333
+ */
334
+ protected renderBody(entity: TEntity): string;
335
+ private readExistingFrontmatter;
336
+ extractMetadata(entity: TEntity): TMetadata;
337
+ parseFrontMatter<T>(markdown: string, schema: z.ZodSchema<T>): T;
338
+ getBodyTemplate(): string;
339
+ generateFrontMatter(entity: TEntity): string;
340
+ /** Strip frontmatter and return the body content. */
341
+ protected extractBody(markdown: string): string;
342
+ /** Parse frontmatter using this adapter's frontmatter schema. */
343
+ protected parseFrontmatter(markdown: string): TFrontmatter;
344
+ /** Combine body and frontmatter into a markdown string. */
345
+ protected buildMarkdown(body: string, frontmatter: Record<string, unknown>): string;
90
346
  }
91
347
 
92
- export interface DataSourceCapabilities {
93
- list?: boolean;
94
- get?: boolean;
95
- search?: boolean;
96
- generate?: boolean;
97
- transform?: boolean;
98
- }
99
- export interface BaseDataSourceContext {
100
- entityService?: unknown;
101
- [key: string]: unknown;
102
- }
103
- export interface DataSource<TQuery = unknown, TResult = unknown> {
104
- id: string;
105
- name?: string;
106
- capabilities?: DataSourceCapabilities;
107
- fetch(query?: TQuery, context?: BaseDataSourceContext): Promise<TResult>;
348
+ /**
349
+ * Configuration for frontmatter handling
350
+ */
351
+ interface FrontmatterConfig<T extends BaseEntity> {
352
+ /**
353
+ * Fields to explicitly include in frontmatter
354
+ * If not specified, includes all non-system fields
355
+ */
356
+ includeFields?: (keyof T)[];
357
+ /**
358
+ * Fields to exclude from frontmatter
359
+ * By default excludes: id, entityType, content, created, updated
360
+ */
361
+ excludeFields?: (keyof T)[];
362
+ /**
363
+ * Custom serializers for complex fields
364
+ */
365
+ customSerializers?: {
366
+ [K in keyof T]?: (value: T[K]) => unknown;
367
+ };
368
+ /**
369
+ * Custom deserializers for complex fields
370
+ */
371
+ customDeserializers?: {
372
+ [K in keyof T]?: (value: unknown) => T[K];
373
+ };
374
+ }
375
+ /**
376
+ * Generate markdown with frontmatter from content and metadata
377
+ */
378
+ declare function generateMarkdownWithFrontmatter(content: string, metadata: Record<string, unknown>): string;
379
+ /**
380
+ * Parse markdown with frontmatter into content and metadata
381
+ */
382
+ declare function parseMarkdownWithFrontmatter<T>(markdown: string, schema: z.ZodSchema<T>): {
383
+ content: string;
384
+ metadata: T;
385
+ };
386
+ /**
387
+ * Generate frontmatter string from metadata
388
+ */
389
+ declare function generateFrontmatter(metadata: Record<string, unknown>): string;
390
+
391
+ /**
392
+ * Context passed to all DataSource operations
393
+ * Contains internal state that should not be mixed with user query parameters
394
+ */
395
+ interface BaseDataSourceContext {
396
+ /**
397
+ * Whether to filter to only published/complete content
398
+ * Set by site-builder: true for production, false for preview
399
+ */
400
+ publishedOnly?: boolean;
401
+ /**
402
+ * Scoped entity service that auto-applies publishedOnly filter
403
+ * Datasources should use this instead of their injected entityService
404
+ * to ensure consistent filtering behavior across environments
405
+ */
406
+ entityService: EntityService;
407
+ }
408
+ /**
409
+ * DataSource Interface
410
+ *
411
+ * Provides data for templates through fetch, generate, or transform operations.
412
+ * DataSources are registered in the DataSourceRegistry and referenced by templates
413
+ * via their dataSourceId property.
414
+ */
415
+ interface DataSource {
416
+ /**
417
+ * Unique identifier for this data source
418
+ */
419
+ id: string;
420
+ /**
421
+ * Human-readable name for this data source
422
+ */
423
+ name: string;
424
+ /**
425
+ * Optional description of what this data source provides
426
+ */
427
+ description?: string;
428
+ /**
429
+ * Optional: Fetch existing data
430
+ * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
431
+ * DataSources validate output using the provided schema
432
+ * @param query - Query parameters for fetching data
433
+ * @param outputSchema - Schema for validating output data
434
+ * @param context - Context with environment
435
+ */
436
+ fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
437
+ /**
438
+ * Optional: Generate new content
439
+ * Used by data sources that create content (e.g., AI-generated content, reports)
440
+ */
441
+ generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
442
+ /**
443
+ * Optional: Transform content between formats
444
+ * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
445
+ */
446
+ transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
447
+ }
448
+ /**
449
+ * DataSource capabilities for discovery and validation
450
+ */
451
+ interface DataSourceCapabilities {
452
+ canFetch: boolean;
453
+ canGenerate: boolean;
454
+ canTransform: boolean;
108
455
  }
109
456
 
110
- export interface PaginationInfo {
111
- page: number;
112
- pageSize: number;
113
- totalItems: number;
114
- totalPages: number;
115
- hasNext: boolean;
116
- hasPrevious: boolean;
117
- }
118
- export interface PaginateOptions {
119
- page?: number;
120
- pageSize?: number;
121
- limit?: number;
122
- offset?: number;
123
- }
124
- export interface PaginateResult<T> {
125
- items: T[];
126
- pagination: PaginationInfo;
127
- }
128
- export const paginationInfoSchema: z.ZodSchema<PaginationInfo>;
129
- export function paginateItems<T>(
130
- items: T[],
131
- options?: PaginateOptions,
132
- ): PaginateResult<T>;
133
- export function buildPaginationInfo(
134
- totalItems: number,
135
- options?: PaginateOptions,
136
- ): PaginationInfo;
457
+ /**
458
+ * Schema for pagination information
459
+ * Used by datasources that return paginated lists
460
+ */
461
+ declare const paginationInfoSchema: z.ZodObject<{
462
+ currentPage: z.ZodNumber;
463
+ totalPages: z.ZodNumber;
464
+ totalItems: z.ZodNumber;
465
+ pageSize: z.ZodNumber;
466
+ hasNextPage: z.ZodBoolean;
467
+ hasPrevPage: z.ZodBoolean;
468
+ }, "strip", z.ZodTypeAny, {
469
+ currentPage: number;
470
+ totalPages: number;
471
+ totalItems: number;
472
+ pageSize: number;
473
+ hasNextPage: boolean;
474
+ hasPrevPage: boolean;
475
+ }, {
476
+ currentPage: number;
477
+ totalPages: number;
478
+ totalItems: number;
479
+ pageSize: number;
480
+ hasNextPage: boolean;
481
+ hasPrevPage: boolean;
482
+ }>;
483
+ /**
484
+ * Pagination information type
485
+ */
486
+ type PaginationInfo = z.infer<typeof paginationInfoSchema>;
487
+ /**
488
+ * Build pagination info from total count and page parameters
489
+ * Used for database-level pagination where we have a separate count query
490
+ */
491
+ declare function buildPaginationInfo(totalItems: number, page: number, pageSize: number): PaginationInfo;
492
+ /**
493
+ * Options for paginating items
494
+ */
495
+ interface PaginateOptions {
496
+ page?: number | undefined;
497
+ limit?: number | undefined;
498
+ pageSize?: number | undefined;
499
+ }
500
+ /**
501
+ * Result of paginating items
502
+ */
503
+ interface PaginateResult<T> {
504
+ items: T[];
505
+ pagination: PaginationInfo | null;
506
+ }
507
+ /**
508
+ * Paginate a list of items
509
+ *
510
+ * When `page` is specified, returns paginated results with pagination info.
511
+ * When only `limit` is specified, returns first N items without pagination info.
512
+ * When neither is specified, returns all items without pagination info.
513
+ *
514
+ * @param items - The full list of items to paginate (should already be sorted)
515
+ * @param options - Pagination options
516
+ * @returns Paginated items and optional pagination info
517
+ */
518
+ declare function paginateItems<T>(items: T[], options: PaginateOptions): PaginateResult<T>;
137
519
 
138
- export interface FrontmatterConfig {
139
- includeFields?: string[];
140
- excludeFields?: string[];
141
- }
142
- export function generateMarkdownWithFrontmatter(
143
- content: string,
144
- metadata?: Record<string, unknown>,
145
- config?: FrontmatterConfig,
146
- ): string;
147
- export function parseMarkdownWithFrontmatter(markdown: string): {
148
- content: string;
149
- metadata: Record<string, unknown>;
150
- };
151
- export function generateFrontmatter(
152
- metadata: Record<string, unknown>,
153
- config?: FrontmatterConfig,
154
- ): string;
520
+ export { BASE_ENTITY_TYPE, BaseEntityAdapter, baseEntitySchema, buildPaginationInfo, generateFrontmatter, generateMarkdownWithFrontmatter, paginateItems, paginationInfoSchema, parseMarkdownWithFrontmatter };
521
+ export type { BaseDataSourceContext, BaseEntity, CreateExecutionContext, CreateInput, CreateInterceptionResult, CreateInterceptor, CreateResult, DataSource, DataSourceCapabilities, EntityAdapter, EntityInput, EntityMutationResult, EntityTypeConfig, FrontmatterConfig, ListOptions, PaginateOptions, PaginateResult, PaginationInfo, SearchOptions, SearchResult };