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

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/plugins.d.ts CHANGED
@@ -1,523 +1,1112 @@
1
- import type { z } from "zod";
1
+ import { z } from 'zod';
2
2
 
3
- export interface Logger {
4
- debug(message: string, data?: unknown): void;
5
- info(message: string, data?: unknown): void;
6
- warn(message: string, data?: unknown): void;
7
- error(message: string, data?: unknown): void;
8
- child(context: string): Logger;
9
- }
10
- import type {
11
- BaseEntity,
12
- CreateExecutionContext,
13
- CreateInput,
14
- CreateInterceptionResult,
15
- CreateInterceptor,
16
- EntityAdapter,
17
- EntityTypeConfig,
18
- DataSource,
19
- ListOptions,
20
- SearchOptions,
21
- SearchResult,
22
- } from "./entities";
23
- import type { Template, ViewTemplate, WebRenderer } from "./templates";
24
- import type {
25
- Daemon,
26
- UserPermissionLevel,
27
- ApiRouteDefinition,
28
- WebRouteDefinition,
29
- MessageResponse,
30
- MessageSender,
31
- MessageWithPayload,
32
- MessageContext,
33
- } from "./interfaces";
34
- import type { BatchOperation, JobHandler, JobOptions } from "./services";
35
-
36
- export interface ToolContext extends MessageContext {
37
- progressToken?: string | number;
38
- sendProgress?: (notification: {
39
- progress?: number;
40
- total?: number;
41
- message?: string;
42
- }) => Promise<void>;
43
- }
44
- export interface ToolResponse<T = unknown> {
45
- success: boolean;
46
- data?: T;
47
- error?: string;
48
- }
49
- export type ToolVisibility = UserPermissionLevel;
50
- export interface ToolConfirmation {
51
- required: boolean;
52
- message?: string;
53
- }
54
- export interface Tool<TArgs = unknown, TResult = unknown> {
55
- name: string;
56
- description: string;
57
- inputSchema: z.ZodRawShape;
58
- handler: (args: TArgs, context: ToolContext) => Promise<TResult> | TResult;
59
- visibility?: ToolVisibility;
60
- confirmation?: ToolConfirmation;
61
- }
62
- export interface Resource<TResult = unknown> {
63
- uri: string;
64
- name: string;
65
- description?: string;
66
- mimeType?: string;
67
- handler: () => Promise<TResult> | TResult;
68
- }
69
- export interface ResourceTemplate<K extends string = string> {
70
- uriTemplate: K;
71
- name: string;
72
- description?: string;
73
- mimeType?: string;
74
- }
75
- export interface Prompt {
76
- name: string;
77
- description?: string;
78
- arguments?: Array<{ name: string; description?: string; required?: boolean }>;
79
- }
80
- export function createTool<TArgs = unknown, TResult = unknown>(
81
- tool: Tool<TArgs, TResult>,
82
- ): Tool<TArgs, TResult>;
83
- export function createResource<TResult = unknown>(
84
- resource: Resource<TResult>,
85
- ): Resource<TResult>;
86
- export function toolSuccess<T = unknown>(data?: T): ToolResponse<T>;
87
- export function toolError(error: string): ToolResponse<never>;
88
-
89
- export interface PluginCapabilities {
90
- tools: Tool[];
91
- resources: Resource[];
92
- instructions?: string;
93
- }
94
- export interface Plugin {
95
- readonly id: string;
96
- readonly version: string;
97
- readonly type: "core" | "entity" | "service" | "interface";
98
- readonly packageName: string;
99
- readonly description?: string;
100
- readonly dependencies?: string[];
101
- ready?(): Promise<void>;
102
- shutdown?(): Promise<void>;
103
- requiresDaemonStartup?(): boolean;
104
- }
105
- export type PluginFactory = (config: PluginConfig) => Plugin | Plugin[];
106
- export type PluginConfig = Record<string, unknown>;
107
- export type PluginConfigInput<T extends z.ZodTypeAny> = z.input<T>;
108
- export type InferPluginConfig<T extends z.ZodTypeAny> = z.infer<T>;
109
- export const basePluginConfigSchema: z.ZodSchema<{
110
- enabled: boolean;
111
- debug: boolean;
112
- }>;
113
-
114
- export interface Channel<TPayload, TResponse = unknown> {
115
- readonly name: string;
116
- readonly schema: z.ZodType<TPayload>;
117
- readonly _response?: TResponse;
118
- }
119
- export function defineChannel<TPayload, TResponse = unknown>(
120
- name: string,
121
- schema: z.ZodType<TPayload>,
122
- ): Channel<TPayload, TResponse>;
123
-
124
- export interface BaseJobTrackingInfo {
125
- rootJobId: string;
3
+ /**
4
+ * Options for entity mutation operations (create, update, upsert)
5
+ */
6
+ interface EntityJobOptions {
7
+ priority?: number;
8
+ maxRetries?: number;
126
9
  }
127
- export interface MessageJobTrackingInfo extends BaseJobTrackingInfo {
128
- messageId?: string;
129
- channelId?: string;
10
+ /**
11
+ * Options for entity creation (extends EntityJobOptions with deduplication)
12
+ */
13
+ interface CreateEntityOptions extends EntityJobOptions {
14
+ deduplicateId?: boolean;
130
15
  }
131
-
132
- export interface BrainCharacter {
133
- name: string;
134
- role: string;
135
- purpose: string;
136
- values: string[];
16
+ /**
17
+ * Result of an entity mutation that triggers an embedding job.
18
+ * When skipped is true, content was unchanged — no DB write, no event, no embedding job.
19
+ */
20
+ interface EntityMutationResult {
21
+ entityId: string;
22
+ jobId: string;
23
+ skipped: boolean;
137
24
  }
138
-
139
- export interface AnchorProfile {
140
- name: string;
141
- kind: "professional" | "team" | "collective";
142
- organization?: string;
143
- description?: string;
144
- avatar?: string;
145
- website?: string;
146
- email?: string;
147
- socialLinks?: Array<{
148
- platform: "github" | "instagram" | "linkedin" | "email" | "website";
149
- url: string;
150
- label?: string;
151
- }>;
25
+ /**
26
+ * Input for adapter-validated direct creation from finalized markdown.
27
+ */
28
+ interface CreateEntityFromMarkdownInput {
29
+ entityType: string;
30
+ id: string;
31
+ markdown: string;
152
32
  }
153
-
154
- export interface AppInfo {
155
- model: string;
156
- version: string;
157
- uptime: number;
158
- entities: number;
159
- embeddings: number;
160
- ai: { model: string; embeddingModel: string };
161
- daemons: unknown[];
162
- endpoints: Array<{
163
- label: string;
164
- url: string;
165
- pluginId: string;
166
- priority: number;
167
- }>;
33
+ /**
34
+ * Data for storing an embedding for an entity
35
+ */
36
+ interface StoreEmbeddingData {
37
+ entityId: string;
38
+ entityType: string;
39
+ embedding: Float32Array;
40
+ contentHash: string;
168
41
  }
169
-
170
- export interface Conversation {
171
- id: string;
172
- sessionId: string;
173
- interfaceType: string;
174
- channelId: string;
175
- channelName: string;
176
- metadata: string | null;
177
- createdAt: string;
178
- updatedAt: string;
42
+ /**
43
+ * Base entity type - generic to support typed metadata
44
+ * TMetadata defaults to Record<string, unknown> for backward compatibility
45
+ */
46
+ interface BaseEntity<TMetadata = Record<string, unknown>> {
47
+ id: string;
48
+ entityType: string;
49
+ content: string;
50
+ created: string;
51
+ updated: string;
52
+ metadata: TMetadata;
53
+ /** SHA256 hash of content for change detection */
54
+ contentHash: string;
55
+ }
56
+ /**
57
+ * Entity input type for creation - allows partial entities with optional system fields
58
+ * contentHash is excluded because it's computed automatically by the entity service
59
+ */
60
+ type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash"> & {
61
+ id?: string;
62
+ created?: string;
63
+ updated?: string;
64
+ };
65
+ /**
66
+ * Search result type
67
+ */
68
+ interface SearchResult<T extends BaseEntity = BaseEntity> {
69
+ entity: T;
70
+ score: number;
71
+ excerpt: string;
72
+ }
73
+ /**
74
+ * Normalized system_create input shape used by plugin create interceptors.
75
+ */
76
+ interface CreateInput {
77
+ entityType: string;
78
+ prompt?: string;
79
+ title?: string;
80
+ content?: string;
81
+ url?: string;
82
+ targetEntityType?: string;
83
+ targetEntityId?: string;
84
+ }
85
+ /**
86
+ * Minimal caller context forwarded to plugin create interceptors.
87
+ */
88
+ interface CreateExecutionContext {
89
+ interfaceType: string;
90
+ userId: string;
91
+ channelId?: string;
92
+ channelName?: string;
93
+ }
94
+ /**
95
+ * Result returned to system_create when a plugin fully handles creation.
96
+ */
97
+ type CreateResult = {
98
+ success: true;
99
+ data: {
100
+ entityId?: string;
101
+ jobId?: string;
102
+ status: string;
103
+ };
104
+ } | {
105
+ success: false;
106
+ error: string;
107
+ };
108
+ /**
109
+ * Plugin create interceptors can either fully handle creation,
110
+ * or continue with a rewritten normalized input.
111
+ */
112
+ type CreateInterceptionResult = {
113
+ kind: "handled";
114
+ result: CreateResult;
115
+ } | {
116
+ kind: "continue";
117
+ input: CreateInput;
118
+ };
119
+ /**
120
+ * Interface for entity adapter - handles conversion between entities and markdown
121
+ * following the hybrid storage model
122
+ *
123
+ * @template TEntity - The full entity type
124
+ * @template TMetadata - The metadata type (defaults to Record<string, unknown>)
125
+ */
126
+ interface EntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata = Record<string, unknown>> {
127
+ entityType: string;
128
+ schema: z.ZodSchema<TEntity>;
129
+ toMarkdown(entity: TEntity): string;
130
+ fromMarkdown(markdown: string): Partial<TEntity>;
131
+ extractMetadata(entity: TEntity): TMetadata;
132
+ parseFrontMatter<TFrontmatter>(markdown: string, schema: z.ZodSchema<TFrontmatter>): TFrontmatter;
133
+ generateFrontMatter(entity: TEntity): string;
134
+ /** Optional: Zod schema for frontmatter fields. Used by CMS config generation. */
135
+ frontmatterSchema?: z.ZodObject<z.ZodRawShape>;
136
+ /** Optional: Declares this entity type is a singleton (one file, e.g., identity/identity.md). Used by CMS to generate files collection. */
137
+ isSingleton?: boolean;
138
+ /** Optional: Whether this entity has a free-form markdown body below frontmatter. Defaults to true. When false, CMS omits the body widget. */
139
+ hasBody?: boolean;
140
+ /** Returns a markdown body template with section headings for this entity type. Empty string for free-form entities. */
141
+ getBodyTemplate(): string;
142
+ /** Optional: Declares that this entity type supports cover images via coverImageId in frontmatter */
143
+ supportsCoverImage?: boolean;
144
+ /** Optional: Extract coverImageId from entity content/frontmatter */
145
+ getCoverImageId?(entity: TEntity): string | undefined;
146
+ }
147
+ /**
148
+ * Sort field specification for multi-field sorting
149
+ */
150
+ interface SortField {
151
+ /** Field to sort by - "created", "updated", or a metadata field name */
152
+ field: string;
153
+ /** Sort direction */
154
+ direction: "asc" | "desc";
155
+ /** Sort NULL values before non-NULL values (default: false / SQLite default) */
156
+ nullsFirst?: boolean;
157
+ }
158
+ /**
159
+ * List entities options
160
+ * Generic over metadata type for type-safe filtering
161
+ */
162
+ interface ListOptions<TMetadata = Record<string, unknown>> {
163
+ limit?: number;
164
+ offset?: number;
165
+ /** Multi-field sorting - supports system fields (created, updated) and metadata fields */
166
+ sortFields?: SortField[];
167
+ filter?: {
168
+ metadata?: Partial<TMetadata>;
169
+ };
170
+ /** Filter to only entities with metadata.status = "published" */
171
+ publishedOnly?: boolean;
172
+ }
173
+ /**
174
+ * Search options
175
+ */
176
+ interface SearchOptions {
177
+ limit?: number;
178
+ offset?: number;
179
+ types?: string[];
180
+ excludeTypes?: string[];
181
+ sortBy?: "relevance" | "created" | "updated";
182
+ sortDirection?: "asc" | "desc";
183
+ /** Score multipliers per entity type - applied after initial search */
184
+ weight?: Record<string, number>;
185
+ }
186
+ /**
187
+ * Configuration for entity type registration
188
+ */
189
+ interface EntityTypeConfig {
190
+ /** Score multiplier for search results (default: 1.0) */
191
+ weight?: number;
192
+ /** Whether to generate embeddings for this entity type (default: true).
193
+ * Set to false for entity types with non-textual content (e.g., images). */
194
+ embeddable?: boolean;
195
+ }
196
+ /**
197
+ * Core entity service interface for read-only operations
198
+ * Used by core plugins that need entity access but shouldn't modify entities
199
+ */
200
+ interface ICoreEntityService {
201
+ getEntity<T extends BaseEntity>(entityType: string, id: string): Promise<T | null>;
202
+ /**
203
+ * Get entity without content resolution (raw)
204
+ * Used internally to avoid recursion when resolving image references
205
+ */
206
+ getEntityRaw<T extends BaseEntity>(entityType: string, id: string): Promise<T | null>;
207
+ listEntities<T extends BaseEntity>(type: string, options?: ListOptions): Promise<T[]>;
208
+ search<T extends BaseEntity = BaseEntity>(query: string, options?: SearchOptions): Promise<SearchResult<T>[]>;
209
+ getEntityTypes(): string[];
210
+ hasEntityType(type: string): boolean;
211
+ countEntities(entityType: string, options?: Pick<ListOptions, "publishedOnly" | "filter">): Promise<number>;
212
+ getEntityCounts(): Promise<Array<{
213
+ entityType: string;
214
+ count: number;
215
+ }>>;
216
+ /** Get weight map for all registered entity types with non-default weights */
217
+ getWeightMap(): Record<string, number>;
218
+ }
219
+ /**
220
+ * Entity service interface for managing brain entities
221
+ */
222
+ interface EntityService extends ICoreEntityService {
223
+ createEntity<T extends BaseEntity>(entity: EntityInput<T>, options?: CreateEntityOptions): Promise<EntityMutationResult>;
224
+ createEntityFromMarkdown(input: CreateEntityFromMarkdownInput, options?: CreateEntityOptions): Promise<EntityMutationResult>;
225
+ updateEntity<T extends BaseEntity>(entity: T, options?: EntityJobOptions): Promise<EntityMutationResult>;
226
+ deleteEntity(entityType: string, id: string): Promise<boolean>;
227
+ upsertEntity<T extends BaseEntity>(entity: T, options?: EntityJobOptions): Promise<EntityMutationResult & {
228
+ created: boolean;
229
+ }>;
230
+ storeEmbedding(data: StoreEmbeddingData): Promise<void>;
231
+ serializeEntity(entity: BaseEntity): string;
232
+ deserializeEntity(markdown: string, entityType: string): Partial<BaseEntity>;
233
+ countEmbeddings(): Promise<number>;
234
+ searchWithDistances(query: string): Promise<Array<{
235
+ entityId: string;
236
+ entityType: string;
237
+ distance: number;
238
+ }>>;
239
+ initialize(): Promise<void>;
240
+ getAsyncJobStatus(jobId: string): Promise<{
241
+ status: "pending" | "processing" | "completed" | "failed";
242
+ error?: string;
243
+ } | null>;
179
244
  }
180
245
 
181
- export interface Message {
182
- id: string;
183
- conversationId: string;
184
- role: string;
185
- content: string;
186
- timestamp: string;
187
- metadata: string | null;
246
+ /**
247
+ * Context passed to all DataSource operations
248
+ * Contains internal state that should not be mixed with user query parameters
249
+ */
250
+ interface BaseDataSourceContext {
251
+ /**
252
+ * Whether to filter to only published/complete content
253
+ * Set by site-builder: true for production, false for preview
254
+ */
255
+ publishedOnly?: boolean;
256
+ /**
257
+ * Scoped entity service that auto-applies publishedOnly filter
258
+ * Datasources should use this instead of their injected entityService
259
+ * to ensure consistent filtering behavior across environments
260
+ */
261
+ entityService: EntityService;
262
+ }
263
+ /**
264
+ * DataSource Interface
265
+ *
266
+ * Provides data for templates through fetch, generate, or transform operations.
267
+ * DataSources are registered in the DataSourceRegistry and referenced by templates
268
+ * via their dataSourceId property.
269
+ */
270
+ interface DataSource {
271
+ /**
272
+ * Unique identifier for this data source
273
+ */
274
+ id: string;
275
+ /**
276
+ * Human-readable name for this data source
277
+ */
278
+ name: string;
279
+ /**
280
+ * Optional description of what this data source provides
281
+ */
282
+ description?: string;
283
+ /**
284
+ * Optional: Fetch existing data
285
+ * Used by data sources that aggregate or retrieve data (e.g., dashboard stats, API data)
286
+ * DataSources validate output using the provided schema
287
+ * @param query - Query parameters for fetching data
288
+ * @param outputSchema - Schema for validating output data
289
+ * @param context - Context with environment
290
+ */
291
+ fetch?: <T>(query: unknown, outputSchema: z.ZodSchema<T>, context: BaseDataSourceContext) => Promise<T>;
292
+ /**
293
+ * Optional: Generate new content
294
+ * Used by data sources that create content (e.g., AI-generated content, reports)
295
+ */
296
+ generate?: <T>(request: unknown, schema: z.ZodSchema<T>) => Promise<T>;
297
+ /**
298
+ * Optional: Transform content between formats
299
+ * Used by data sources that convert content (e.g., markdown to HTML, data formatting)
300
+ */
301
+ transform?: <T>(content: unknown, format: string, schema: z.ZodSchema<T>) => Promise<T>;
188
302
  }
189
303
 
190
- export interface GetMessagesOptions {
191
- limit?: number;
192
- range?: { start: number; end: number };
304
+ declare const ChatContextSchema: z.ZodObject<{
305
+ userPermissionLevel: z.ZodOptional<z.ZodEnum<["public", "trusted", "anchor"]>>;
306
+ interfaceType: z.ZodOptional<z.ZodString>;
307
+ channelId: z.ZodOptional<z.ZodString>;
308
+ channelName: z.ZodOptional<z.ZodString>;
309
+ }, "strip", z.ZodTypeAny, {
310
+ userPermissionLevel?: "public" | "trusted" | "anchor" | undefined;
311
+ interfaceType?: string | undefined;
312
+ channelId?: string | undefined;
313
+ channelName?: string | undefined;
314
+ }, {
315
+ userPermissionLevel?: "public" | "trusted" | "anchor" | undefined;
316
+ interfaceType?: string | undefined;
317
+ channelId?: string | undefined;
318
+ channelName?: string | undefined;
319
+ }>;
320
+ type ChatContext = z.infer<typeof ChatContextSchema>;
321
+ declare const PendingConfirmationSchema: z.ZodObject<{
322
+ toolName: z.ZodString;
323
+ description: z.ZodString;
324
+ args: z.ZodUnknown;
325
+ }, "strip", z.ZodTypeAny, {
326
+ toolName: string;
327
+ description: string;
328
+ args?: unknown;
329
+ }, {
330
+ toolName: string;
331
+ description: string;
332
+ args?: unknown;
333
+ }>;
334
+ type PendingConfirmation = z.infer<typeof PendingConfirmationSchema>;
335
+ declare const ToolResultDataSchema: z.ZodObject<{
336
+ toolName: z.ZodString;
337
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
338
+ jobId: z.ZodOptional<z.ZodString>;
339
+ data: z.ZodOptional<z.ZodUnknown>;
340
+ }, "strip", z.ZodTypeAny, {
341
+ toolName: string;
342
+ args?: Record<string, unknown> | undefined;
343
+ jobId?: string | undefined;
344
+ data?: unknown;
345
+ }, {
346
+ toolName: string;
347
+ args?: Record<string, unknown> | undefined;
348
+ jobId?: string | undefined;
349
+ data?: unknown;
350
+ }>;
351
+ type ToolResultData = z.infer<typeof ToolResultDataSchema>;
352
+ declare const AgentResponseSchema: z.ZodObject<{
353
+ text: z.ZodString;
354
+ toolResults: z.ZodOptional<z.ZodArray<z.ZodObject<{
355
+ toolName: z.ZodString;
356
+ args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
357
+ jobId: z.ZodOptional<z.ZodString>;
358
+ data: z.ZodOptional<z.ZodUnknown>;
359
+ }, "strip", z.ZodTypeAny, {
360
+ toolName: string;
361
+ args?: Record<string, unknown> | undefined;
362
+ jobId?: string | undefined;
363
+ data?: unknown;
364
+ }, {
365
+ toolName: string;
366
+ args?: Record<string, unknown> | undefined;
367
+ jobId?: string | undefined;
368
+ data?: unknown;
369
+ }>, "many">>;
370
+ pendingConfirmation: z.ZodOptional<z.ZodObject<{
371
+ toolName: z.ZodString;
372
+ description: z.ZodString;
373
+ args: z.ZodUnknown;
374
+ }, "strip", z.ZodTypeAny, {
375
+ toolName: string;
376
+ description: string;
377
+ args?: unknown;
378
+ }, {
379
+ toolName: string;
380
+ description: string;
381
+ args?: unknown;
382
+ }>>;
383
+ usage: z.ZodObject<{
384
+ promptTokens: z.ZodNumber;
385
+ completionTokens: z.ZodNumber;
386
+ totalTokens: z.ZodNumber;
387
+ }, "strip", z.ZodTypeAny, {
388
+ promptTokens: number;
389
+ completionTokens: number;
390
+ totalTokens: number;
391
+ }, {
392
+ promptTokens: number;
393
+ completionTokens: number;
394
+ totalTokens: number;
395
+ }>;
396
+ }, "strip", z.ZodTypeAny, {
397
+ text: string;
398
+ usage: {
399
+ promptTokens: number;
400
+ completionTokens: number;
401
+ totalTokens: number;
402
+ };
403
+ toolResults?: {
404
+ toolName: string;
405
+ args?: Record<string, unknown> | undefined;
406
+ jobId?: string | undefined;
407
+ data?: unknown;
408
+ }[] | undefined;
409
+ pendingConfirmation?: {
410
+ toolName: string;
411
+ description: string;
412
+ args?: unknown;
413
+ } | undefined;
414
+ }, {
415
+ text: string;
416
+ usage: {
417
+ promptTokens: number;
418
+ completionTokens: number;
419
+ totalTokens: number;
420
+ };
421
+ toolResults?: {
422
+ toolName: string;
423
+ args?: Record<string, unknown> | undefined;
424
+ jobId?: string | undefined;
425
+ data?: unknown;
426
+ }[] | undefined;
427
+ pendingConfirmation?: {
428
+ toolName: string;
429
+ description: string;
430
+ args?: unknown;
431
+ } | undefined;
432
+ }>;
433
+ type AgentResponse = z.infer<typeof AgentResponseSchema>;
434
+ interface AgentNamespace {
435
+ chat(message: string, conversationId: string, context?: ChatContext): Promise<AgentResponse>;
436
+ confirmPendingAction(conversationId: string, confirmed: boolean): Promise<AgentResponse>;
437
+ invalidate(): void;
193
438
  }
194
439
 
195
- export interface IEntityService {
196
- getEntity<T extends BaseEntity>(
197
- entityType: string,
198
- id: string,
199
- ): Promise<T | null>;
200
- listEntities<T extends BaseEntity>(
201
- type: string,
202
- options?: ListOptions,
203
- ): Promise<T[]>;
204
- search<T extends BaseEntity = BaseEntity>(
205
- query: string,
206
- options?: SearchOptions,
207
- ): Promise<SearchResult<T>[]>;
208
- getEntityTypes(): string[];
209
- hasEntityType(type: string): boolean;
210
- countEntities(
211
- entityType: string,
212
- options?: Pick<ListOptions, "publishedOnly">,
213
- ): Promise<number>;
214
- getEntityCounts(): Promise<Array<{ entityType: string; count: number }>>;
440
+ declare const WebRouteMethods: readonly ["GET", "POST", "PUT", "DELETE", "OPTIONS"];
441
+ type WebRouteMethod = (typeof WebRouteMethods)[number];
442
+ type WebRouteHandler = (request: Request) => Response | Promise<Response>;
443
+ interface WebRouteDefinition {
444
+ /** Absolute mounted path (e.g. "/cms" or "/cms-config") */
445
+ path: string;
446
+ /** HTTP method */
447
+ method?: WebRouteMethod;
448
+ /** Allow unauthenticated access */
449
+ public?: boolean;
450
+ /** Request handler */
451
+ handler: WebRouteHandler;
215
452
  }
216
453
 
217
- export type EvalHandler<TInput = unknown, TOutput = unknown> = (
218
- input: TInput,
219
- ) => Promise<TOutput>;
454
+ declare const AppInfoSchema: z.ZodObject<{
455
+ model: z.ZodString;
456
+ version: z.ZodString;
457
+ uptime: z.ZodNumber;
458
+ entities: z.ZodNumber;
459
+ embeddings: z.ZodNumber;
460
+ ai: z.ZodObject<{
461
+ model: z.ZodString;
462
+ embeddingModel: z.ZodString;
463
+ }, "strip", z.ZodTypeAny, {
464
+ model: string;
465
+ embeddingModel: string;
466
+ }, {
467
+ model: string;
468
+ embeddingModel: string;
469
+ }>;
470
+ daemons: z.ZodArray<z.ZodObject<{
471
+ name: z.ZodString;
472
+ pluginId: z.ZodString;
473
+ status: z.ZodString;
474
+ health: z.ZodOptional<z.ZodObject<{
475
+ status: z.ZodEnum<["healthy", "warning", "error", "unknown"]>;
476
+ message: z.ZodOptional<z.ZodString>;
477
+ lastCheck: z.ZodOptional<z.ZodString>;
478
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
479
+ }, "strip", z.ZodTypeAny, {
480
+ status: "unknown" | "healthy" | "warning" | "error";
481
+ message?: string | undefined;
482
+ lastCheck?: string | undefined;
483
+ details?: Record<string, unknown> | undefined;
484
+ }, {
485
+ status: "unknown" | "healthy" | "warning" | "error";
486
+ message?: string | undefined;
487
+ lastCheck?: string | undefined;
488
+ details?: Record<string, unknown> | undefined;
489
+ }>>;
490
+ }, "strip", z.ZodTypeAny, {
491
+ status: string;
492
+ name: string;
493
+ pluginId: string;
494
+ health?: {
495
+ status: "unknown" | "healthy" | "warning" | "error";
496
+ message?: string | undefined;
497
+ lastCheck?: string | undefined;
498
+ details?: Record<string, unknown> | undefined;
499
+ } | undefined;
500
+ }, {
501
+ status: string;
502
+ name: string;
503
+ pluginId: string;
504
+ health?: {
505
+ status: "unknown" | "healthy" | "warning" | "error";
506
+ message?: string | undefined;
507
+ lastCheck?: string | undefined;
508
+ details?: Record<string, unknown> | undefined;
509
+ } | undefined;
510
+ }>, "many">;
511
+ endpoints: z.ZodArray<z.ZodObject<{
512
+ label: z.ZodString;
513
+ url: z.ZodString;
514
+ pluginId: z.ZodString;
515
+ priority: z.ZodNumber;
516
+ }, "strip", z.ZodTypeAny, {
517
+ pluginId: string;
518
+ label: string;
519
+ url: string;
520
+ priority: number;
521
+ }, {
522
+ pluginId: string;
523
+ label: string;
524
+ url: string;
525
+ priority: number;
526
+ }>, "many">;
527
+ }, "strip", z.ZodTypeAny, {
528
+ model: string;
529
+ version: string;
530
+ uptime: number;
531
+ entities: number;
532
+ embeddings: number;
533
+ ai: {
534
+ model: string;
535
+ embeddingModel: string;
536
+ };
537
+ daemons: {
538
+ status: string;
539
+ name: string;
540
+ pluginId: string;
541
+ health?: {
542
+ status: "unknown" | "healthy" | "warning" | "error";
543
+ message?: string | undefined;
544
+ lastCheck?: string | undefined;
545
+ details?: Record<string, unknown> | undefined;
546
+ } | undefined;
547
+ }[];
548
+ endpoints: {
549
+ pluginId: string;
550
+ label: string;
551
+ url: string;
552
+ priority: number;
553
+ }[];
554
+ }, {
555
+ model: string;
556
+ version: string;
557
+ uptime: number;
558
+ entities: number;
559
+ embeddings: number;
560
+ ai: {
561
+ model: string;
562
+ embeddingModel: string;
563
+ };
564
+ daemons: {
565
+ status: string;
566
+ name: string;
567
+ pluginId: string;
568
+ health?: {
569
+ status: "unknown" | "healthy" | "warning" | "error";
570
+ message?: string | undefined;
571
+ lastCheck?: string | undefined;
572
+ details?: Record<string, unknown> | undefined;
573
+ } | undefined;
574
+ }[];
575
+ endpoints: {
576
+ pluginId: string;
577
+ label: string;
578
+ url: string;
579
+ priority: number;
580
+ }[];
581
+ }>;
582
+ type AppInfo = z.infer<typeof AppInfoSchema>;
220
583
 
221
- export type InsightHandler = (
222
- entityService: IEntityService,
223
- ) => Promise<Record<string, unknown>>;
584
+ declare const ConversationSchema: z.ZodObject<{
585
+ id: z.ZodString;
586
+ sessionId: z.ZodString;
587
+ interfaceType: z.ZodString;
588
+ channelId: z.ZodString;
589
+ channelName: z.ZodOptional<z.ZodString>;
590
+ startedAt: z.ZodString;
591
+ lastActiveAt: z.ZodString;
592
+ createdAt: z.ZodString;
593
+ updatedAt: z.ZodString;
594
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
595
+ }, "strip", z.ZodTypeAny, {
596
+ interfaceType: string;
597
+ channelId: string;
598
+ id: string;
599
+ sessionId: string;
600
+ startedAt: string;
601
+ lastActiveAt: string;
602
+ createdAt: string;
603
+ updatedAt: string;
604
+ metadata: Record<string, unknown>;
605
+ channelName?: string | undefined;
606
+ }, {
607
+ interfaceType: string;
608
+ channelId: string;
609
+ id: string;
610
+ sessionId: string;
611
+ startedAt: string;
612
+ lastActiveAt: string;
613
+ createdAt: string;
614
+ updatedAt: string;
615
+ metadata: Record<string, unknown>;
616
+ channelName?: string | undefined;
617
+ }>;
618
+ type Conversation = z.infer<typeof ConversationSchema>;
619
+ declare const messageRoleSchema: z.ZodEnum<["user", "assistant", "system"]>;
620
+ type MessageRole = z.infer<typeof messageRoleSchema>;
621
+ declare const MessageSchema: z.ZodObject<{
622
+ id: z.ZodString;
623
+ conversationId: z.ZodString;
624
+ role: z.ZodEnum<["user", "assistant", "system"]>;
625
+ content: z.ZodString;
626
+ timestamp: z.ZodString;
627
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
628
+ }, "strip", z.ZodTypeAny, {
629
+ id: string;
630
+ metadata: Record<string, unknown>;
631
+ conversationId: string;
632
+ role: "user" | "assistant" | "system";
633
+ content: string;
634
+ timestamp: string;
635
+ }, {
636
+ id: string;
637
+ metadata: Record<string, unknown>;
638
+ conversationId: string;
639
+ role: "user" | "assistant" | "system";
640
+ content: string;
641
+ timestamp: string;
642
+ }>;
643
+ type Message = z.infer<typeof MessageSchema>;
224
644
 
225
- export interface PendingConfirmation {
226
- toolName: string;
227
- description: string;
228
- args: unknown;
229
- }
645
+ declare const BrainCharacterSchema: z.ZodObject<{
646
+ name: z.ZodString;
647
+ role: z.ZodString;
648
+ purpose: z.ZodString;
649
+ values: z.ZodArray<z.ZodString, "many">;
650
+ }, "strip", z.ZodTypeAny, {
651
+ values: string[];
652
+ name: string;
653
+ role: string;
654
+ purpose: string;
655
+ }, {
656
+ values: string[];
657
+ name: string;
658
+ role: string;
659
+ purpose: string;
660
+ }>;
661
+ type BrainCharacter = z.infer<typeof BrainCharacterSchema>;
662
+ declare const AnchorProfileSchema: z.ZodObject<{
663
+ name: z.ZodString;
664
+ kind: z.ZodEnum<["professional", "team", "collective"]>;
665
+ organization: z.ZodOptional<z.ZodString>;
666
+ description: z.ZodOptional<z.ZodString>;
667
+ avatar: z.ZodOptional<z.ZodString>;
668
+ website: z.ZodOptional<z.ZodString>;
669
+ email: z.ZodOptional<z.ZodString>;
670
+ socialLinks: z.ZodOptional<z.ZodArray<z.ZodObject<{
671
+ platform: z.ZodEnum<["github", "instagram", "linkedin", "email", "website"]>;
672
+ url: z.ZodString;
673
+ label: z.ZodOptional<z.ZodString>;
674
+ }, "strip", z.ZodTypeAny, {
675
+ url: string;
676
+ platform: "website" | "email" | "github" | "instagram" | "linkedin";
677
+ label?: string | undefined;
678
+ }, {
679
+ url: string;
680
+ platform: "website" | "email" | "github" | "instagram" | "linkedin";
681
+ label?: string | undefined;
682
+ }>, "many">>;
683
+ }, "strip", z.ZodTypeAny, {
684
+ name: string;
685
+ kind: "professional" | "team" | "collective";
686
+ description?: string | undefined;
687
+ organization?: string | undefined;
688
+ avatar?: string | undefined;
689
+ website?: string | undefined;
690
+ email?: string | undefined;
691
+ socialLinks?: {
692
+ url: string;
693
+ platform: "website" | "email" | "github" | "instagram" | "linkedin";
694
+ label?: string | undefined;
695
+ }[] | undefined;
696
+ }, {
697
+ name: string;
698
+ kind: "professional" | "team" | "collective";
699
+ description?: string | undefined;
700
+ organization?: string | undefined;
701
+ avatar?: string | undefined;
702
+ website?: string | undefined;
703
+ email?: string | undefined;
704
+ socialLinks?: {
705
+ url: string;
706
+ platform: "website" | "email" | "github" | "instagram" | "linkedin";
707
+ label?: string | undefined;
708
+ }[] | undefined;
709
+ }>;
710
+ type AnchorProfile = z.infer<typeof AnchorProfileSchema>;
230
711
 
231
- export interface ToolResultData {
232
- toolName: string;
233
- args?: Record<string, unknown>;
234
- jobId?: string;
235
- data?: unknown;
712
+ declare const MessageResponseSchema: z.ZodUnion<[z.ZodObject<{
713
+ success: z.ZodBoolean;
714
+ data: z.ZodOptional<z.ZodUnknown>;
715
+ error: z.ZodOptional<z.ZodString>;
716
+ }, "strip", z.ZodTypeAny, {
717
+ success: boolean;
718
+ data?: unknown;
719
+ error?: string | undefined;
720
+ }, {
721
+ success: boolean;
722
+ data?: unknown;
723
+ error?: string | undefined;
724
+ }>, z.ZodObject<{
725
+ noop: z.ZodLiteral<true>;
726
+ }, "strip", z.ZodTypeAny, {
727
+ noop: true;
728
+ }, {
729
+ noop: true;
730
+ }>]>;
731
+ type MessageResponse<T = unknown> = ({
732
+ success: boolean;
733
+ error?: string | undefined;
734
+ } & {
735
+ data?: T | undefined;
736
+ }) | {
737
+ noop: true;
738
+ };
739
+ declare const BaseMessageSchema: z.ZodObject<{
740
+ id: z.ZodString;
741
+ timestamp: z.ZodString;
742
+ type: z.ZodString;
743
+ source: z.ZodString;
744
+ target: z.ZodOptional<z.ZodString>;
745
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
746
+ }, "strip", z.ZodTypeAny, {
747
+ type: string;
748
+ id: string;
749
+ timestamp: string;
750
+ source: string;
751
+ metadata?: Record<string, unknown> | undefined;
752
+ target?: string | undefined;
753
+ }, {
754
+ type: string;
755
+ id: string;
756
+ timestamp: string;
757
+ source: string;
758
+ metadata?: Record<string, unknown> | undefined;
759
+ target?: string | undefined;
760
+ }>;
761
+ type BaseMessage = z.infer<typeof BaseMessageSchema>;
762
+ type MessageWithPayload<T = unknown> = BaseMessage & {
763
+ payload: T;
764
+ };
765
+ interface MessageSendOptions {
766
+ broadcast?: boolean;
236
767
  }
237
-
238
- export interface AgentResponse {
239
- text: string;
240
- toolResults?: ToolResultData[];
241
- pendingConfirmation?: PendingConfirmation;
242
- usage: {
243
- promptTokens: number;
244
- completionTokens: number;
245
- totalTokens: number;
246
- };
768
+ type MessageSender<T = unknown, R = unknown> = (type: string, payload: T, options?: MessageSendOptions) => Promise<MessageResponse<R>>;
769
+ interface MessageContext {
770
+ userId?: string;
771
+ channelId?: string;
772
+ messageId?: string;
773
+ timestamp?: string;
774
+ interfaceType?: string;
775
+ userPermissionLevel?: "public" | "trusted" | "anchor";
776
+ threadId?: string;
247
777
  }
248
778
 
249
- export interface ChatContext {
250
- userPermissionLevel?: UserPermissionLevel;
251
- interfaceType?: string;
252
- channelId?: string;
253
- channelName?: string;
779
+ type PluginConfig = Record<string, unknown>;
780
+ type PluginConfigInput<T extends z.ZodTypeAny> = z.input<T>;
781
+ interface Plugin {
782
+ readonly id: string;
783
+ readonly version: string;
784
+ readonly type: "core" | "entity" | "service" | "interface";
785
+ readonly packageName: string;
786
+ readonly description?: string;
787
+ readonly dependencies?: string[];
788
+ ready?(): Promise<void>;
789
+ shutdown?(): Promise<void>;
790
+ requiresDaemonStartup?(): boolean;
254
791
  }
255
-
256
- export interface IAgentService {
257
- chat(
258
- message: string,
259
- conversationId: string,
260
- context?: ChatContext,
261
- ): Promise<AgentResponse>;
792
+ type PluginFactory = (config: PluginConfig) => Plugin | Plugin[];
793
+ interface Logger {
794
+ debug(message: string, data?: unknown): void;
795
+ info(message: string, data?: unknown): void;
796
+ warn(message: string, data?: unknown): void;
797
+ error(message: string, data?: unknown): void;
798
+ child(context: string): Logger;
262
799
  }
263
-
264
- export interface BasePluginContext {
265
- readonly pluginId: string;
266
- readonly logger: Logger;
267
- readonly dataDir: string;
268
- readonly domain: string | undefined;
269
- readonly siteUrl: string | undefined;
270
- readonly previewUrl: string | undefined;
271
- readonly appInfo: () => Promise<AppInfo>;
272
- readonly entityService: IEntityService;
273
- readonly identity: {
800
+ interface ToolContext {
801
+ progressToken?: string | number;
802
+ sendProgress?: (notification: {
803
+ progress?: number;
804
+ total?: number;
805
+ message?: string;
806
+ }) => Promise<void>;
807
+ interfaceType?: string;
808
+ userId?: string;
809
+ channelId?: string;
810
+ channelName?: string;
811
+ }
812
+ interface ToolResponse<T = unknown> {
813
+ success: boolean;
814
+ data?: T;
815
+ error?: string;
816
+ }
817
+ type ToolVisibility = "public" | "trusted" | "anchor";
818
+ interface ToolConfirmation {
819
+ required: boolean;
820
+ message?: string;
821
+ }
822
+ interface Tool<TArgs = unknown, TResult = unknown> {
823
+ name: string;
824
+ description: string;
825
+ inputSchema: z.ZodRawShape;
826
+ handler: (args: TArgs, context: ToolContext) => Promise<TResult> | TResult;
827
+ visibility?: ToolVisibility;
828
+ confirmation?: ToolConfirmation;
829
+ }
830
+ interface Resource<TResult = unknown> {
831
+ uri: string;
832
+ name: string;
833
+ description?: string;
834
+ mimeType?: string;
835
+ handler: () => Promise<TResult> | TResult;
836
+ }
837
+ interface ResourceTemplate<K extends string = string> {
838
+ uriTemplate: K;
839
+ name: string;
840
+ description?: string;
841
+ mimeType?: string;
842
+ }
843
+ interface Prompt {
844
+ name: string;
845
+ description?: string;
846
+ arguments?: Array<{
847
+ name: string;
848
+ description?: string;
849
+ required?: boolean;
850
+ }>;
851
+ }
852
+ declare function createTool<TArgs = unknown, TResult = unknown>(tool: Tool<TArgs, TResult>): Tool<TArgs, TResult>;
853
+ declare function createResource<TResult = unknown>(resource: Resource<TResult>): Resource<TResult>;
854
+ declare function toolSuccess<T = unknown>(data?: T): ToolResponse<T>;
855
+ declare function toolError(error: string): ToolResponse<never>;
856
+ interface BaseJobTrackingInfo {
857
+ rootJobId: string;
858
+ }
859
+ interface MessageJobTrackingInfo extends BaseJobTrackingInfo {
860
+ messageId?: string;
861
+ channelId?: string;
862
+ }
863
+ type JobProgressStatus = "pending" | "processing" | "completed" | "failed";
864
+ interface JobProgressContext {
865
+ rootJobId: string;
866
+ operationType: "file_operations" | "content_operations" | "data_processing" | "batch_processing";
867
+ pluginId?: string | undefined;
868
+ progressToken?: string | number | undefined;
869
+ operationTarget?: string | undefined;
870
+ interfaceType?: string | undefined;
871
+ channelId?: string | undefined;
872
+ }
873
+ interface JobProgressEvent {
874
+ id: string;
875
+ type: "job" | "batch";
876
+ status: JobProgressStatus;
877
+ message?: string | undefined;
878
+ progress?: {
879
+ current: number;
880
+ total: number;
881
+ percentage: number;
882
+ } | undefined;
883
+ aggregationKey?: string | undefined;
884
+ batchDetails?: {
885
+ totalOperations: number;
886
+ completedOperations: number;
887
+ failedOperations: number;
888
+ currentOperation?: string | undefined;
889
+ errors?: string[] | undefined;
890
+ } | undefined;
891
+ jobDetails?: {
892
+ jobType: string;
893
+ priority: number;
894
+ retryCount: number;
895
+ } | undefined;
896
+ metadata: JobProgressContext;
897
+ }
898
+ declare const urlCaptureConfigSchema: z.ZodObject<{
899
+ captureUrls: z.ZodDefault<z.ZodBoolean>;
900
+ blockedUrlDomains: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
901
+ }, "strip", z.ZodTypeAny, {
902
+ captureUrls: boolean;
903
+ blockedUrlDomains: string[];
904
+ }, {
905
+ captureUrls?: boolean | undefined;
906
+ blockedUrlDomains?: string[] | undefined;
907
+ }>;
908
+ interface Channel<TPayload, TResponse = unknown> {
909
+ readonly name: string;
910
+ readonly schema: z.ZodType<TPayload>;
911
+ readonly _response?: TResponse;
912
+ }
913
+ declare function defineChannel<TPayload, TResponse = unknown>(name: string, schema: z.ZodType<TPayload>): Channel<TPayload, TResponse>;
914
+ interface IEntityService {
915
+ getEntity<T = unknown>(entityType: string, id: string): Promise<T | null>;
916
+ listEntities<T = unknown>(type: string, options?: unknown): Promise<T[]>;
917
+ search<T = unknown>(query: string, options?: unknown): Promise<T[]>;
918
+ getEntityTypes(): string[];
919
+ hasEntityType(type: string): boolean;
920
+ countEntities(entityType: string, options?: unknown): Promise<number>;
921
+ getEntityCounts(): Promise<Array<{
922
+ entityType: string;
923
+ count: number;
924
+ }>>;
925
+ }
926
+ interface IIdentityNamespace {
274
927
  get: () => BrainCharacter;
275
928
  getProfile: () => AnchorProfile;
276
929
  getAppInfo: () => Promise<AppInfo>;
277
- };
278
- readonly messaging: {
279
- send: MessageSender;
280
- subscribe: <T = unknown, R = unknown>(
281
- channel: string | Channel<T, R>,
282
- handler: (
283
- message: MessageWithPayload<T> | T,
284
- ) => Promise<MessageResponse<R>> | MessageResponse<R>,
285
- ) => () => void;
286
- };
287
- readonly jobs: {
288
- enqueue(
289
- type: string,
290
- data: unknown,
291
- toolContext?: ToolContext | null,
292
- options?: JobOptions,
293
- ): Promise<string>;
294
- enqueueBatch(
295
- operations: BatchOperation[],
296
- options?: JobOptions,
297
- ): Promise<string>;
298
- registerHandler(type: string, handler: JobHandler): void;
299
- };
300
- readonly conversations: {
930
+ }
931
+ interface IConversationsNamespace {
301
932
  get(conversationId: string): Promise<Conversation | null>;
302
933
  search(query: string): Promise<Conversation[]>;
303
- getMessages(
304
- conversationId: string,
305
- options?: GetMessagesOptions,
306
- ): Promise<Message[]>;
307
- };
308
- readonly eval: {
309
- registerHandler<TInput = unknown, TOutput = unknown>(
310
- handlerId: string,
311
- handler: EvalHandler<TInput, TOutput>,
312
- ): void;
313
- };
314
- readonly insights: {
934
+ getMessages(conversationId: string, options?: {
935
+ limit?: number;
936
+ range?: {
937
+ start: number;
938
+ end: number;
939
+ };
940
+ }): Promise<Message[]>;
941
+ }
942
+ interface IMessagingNamespace {
943
+ send: MessageSender;
944
+ subscribe<T = unknown, R = unknown>(channel: string | Channel<T, R>, handler: (message: MessageWithPayload<T>) => Promise<MessageResponse<R>>): () => void;
945
+ }
946
+ type EvalHandler<TInput = unknown, TOutput = unknown> = (input: TInput) => Promise<TOutput>;
947
+ type InsightHandler = (entityService: IEntityService) => Promise<Record<string, unknown>>;
948
+ interface IEvalNamespace {
949
+ registerHandler<TInput = unknown, TOutput = unknown>(handlerId: string, handler: EvalHandler<TInput, TOutput>): void;
950
+ }
951
+ interface IInsightsNamespace {
315
952
  register(type: string, handler: InsightHandler): void;
316
- };
317
- readonly endpoints: {
318
- register(endpoint: { label: string; url: string; priority?: number }): void;
319
- };
320
953
  }
321
-
322
- export interface EntityPluginContext extends BasePluginContext {
323
- readonly entityService: IEntityService;
324
- readonly entities: {
325
- register<T extends BaseEntity>(
326
- entityType: string,
327
- schema: z.ZodSchema<T>,
328
- adapter: EntityAdapter<T>,
329
- config?: EntityTypeConfig,
330
- ): void;
331
- getAdapter<T extends BaseEntity>(
332
- entityType: string,
333
- ): EntityAdapter<T> | undefined;
334
- extendFrontmatterSchema(
335
- type: string,
336
- extension: z.ZodObject<z.ZodRawShape>,
337
- ): void;
338
- getEffectiveFrontmatterSchema(
339
- type: string,
340
- ): z.ZodObject<z.ZodRawShape> | undefined;
341
- update<T extends BaseEntity>(
342
- entity: T,
343
- ): Promise<{ entityId: string; jobId: string }>;
954
+ interface BasePluginContext {
955
+ readonly pluginId: string;
956
+ readonly logger: Logger;
957
+ readonly dataDir: string;
958
+ readonly domain: string | undefined;
959
+ readonly siteUrl: string | undefined;
960
+ readonly previewUrl: string | undefined;
961
+ readonly appInfo: () => Promise<AppInfo>;
962
+ readonly entityService: IEntityService;
963
+ readonly identity: IIdentityNamespace;
964
+ readonly messaging: IMessagingNamespace;
965
+ readonly conversations: IConversationsNamespace;
966
+ readonly eval: IEvalNamespace;
967
+ readonly insights: IInsightsNamespace;
968
+ }
969
+ interface IEntitiesNamespace {
970
+ register<TEntity extends BaseEntity>(entityType: string, schema: z.ZodSchema<TEntity>, adapter: EntityAdapter<TEntity>, config?: EntityTypeConfig): void;
971
+ getAdapter<TEntity extends BaseEntity>(entityType: string): EntityAdapter<TEntity> | undefined;
972
+ update<TEntity extends BaseEntity>(entity: TEntity): Promise<{
973
+ entityId: string;
974
+ jobId: string;
975
+ }>;
344
976
  registerDataSource(dataSource: DataSource): void;
345
- registerCreateInterceptor(
346
- entityType: string,
347
- interceptor: CreateInterceptor,
348
- ): void;
349
- };
350
- readonly ai: {
351
- query(prompt: string, context?: ChatContext): Promise<AgentResponse>;
352
- generate<T = unknown>(config: Record<string, unknown>): Promise<T>;
353
- generateObject<T>(
354
- prompt: string,
355
- schema: z.ZodType<T>,
356
- ): Promise<{ object: T }>;
357
- generateImage(
358
- prompt: string,
359
- options?: Record<string, unknown>,
360
- ): Promise<{ url?: string; data?: Uint8Array; mimeType?: string }>;
361
- canGenerateImages(): boolean;
362
- };
363
- readonly prompts: {
977
+ registerCreateInterceptor(entityType: string, interceptor: (input: CreateInput, executionContext: CreateExecutionContext) => Promise<CreateInterceptionResult>): void;
978
+ }
979
+ interface IPromptsNamespace {
364
980
  resolve(target: string, fallback: string): Promise<string>;
365
- };
366
- }
367
- export interface ServicePluginContext extends BasePluginContext {
368
- readonly entityService: IEntityService;
369
- readonly entities: EntityPluginContext["entities"];
370
- readonly templates: {
371
- register(templates: Record<string, Template>, namespace?: string): void;
372
- format<T = unknown>(templateName: string, data: T): string;
373
- parse<T = unknown>(templateName: string, content: string): T;
374
- resolve<T = unknown>(
375
- templateName: string,
376
- options?: Record<string, unknown>,
377
- ): Promise<T | null>;
378
- };
379
- readonly views: {
380
- get(name: string): ViewTemplate | undefined;
381
- list(): ViewTemplate[];
382
- hasRenderer(templateName: string): boolean;
383
- getRenderer(templateName: string): WebRenderer | undefined;
384
- validate(templateName: string, content: unknown): boolean;
385
- };
386
- readonly prompts: EntityPluginContext["prompts"];
387
- registerInstructions(instructions: string): void;
388
- }
389
- export interface InterfacePluginContext extends BasePluginContext {
390
- readonly mcpTransport: unknown;
391
- readonly agentService: IAgentService;
392
- readonly permissions: {
393
- getUserLevel(interfaceType: string, userId: string): UserPermissionLevel;
394
- };
395
- readonly daemons: { register(name: string, daemon: Daemon): void };
396
- readonly conversations: BasePluginContext["conversations"] & {
397
- start(
398
- conversationId: string,
399
- interfaceType: string,
400
- channelId: string,
401
- metadata: Record<string, unknown>,
402
- ): Promise<string>;
403
- addMessage(
404
- conversationId: string,
405
- role: string,
406
- content: string,
407
- metadata?: Record<string, unknown>,
408
- ): Promise<void>;
409
- };
410
- readonly tools: {
411
- listForPermissionLevel(level: UserPermissionLevel): unknown[];
412
- };
413
- readonly apiRoutes: { getRoutes(): unknown[]; getMessageBus(): unknown };
414
- readonly webRoutes: { getRoutes(): unknown[] };
415
- readonly plugins: { has(pluginId: string): boolean };
416
981
  }
417
-
418
- export type DeriveEvent = "created" | "updated" | "deleted" | "extract";
419
- export abstract class EntityPlugin<
420
- TEntity extends BaseEntity = BaseEntity,
421
- TConfig = Record<string, never>,
422
- > implements Plugin {
423
- readonly type: "entity";
424
- readonly id: string;
425
- readonly version: string;
426
- readonly packageName: string;
427
- readonly description?: string;
428
- abstract readonly entityType: string;
429
- abstract readonly schema: z.ZodSchema<TEntity>;
430
- abstract readonly adapter: EntityAdapter<TEntity>;
431
- protected constructor(
432
- id: string,
433
- packageJson: { name: string; version: string; description?: string },
434
- config?: Partial<TConfig>,
435
- configSchema?: z.ZodTypeAny,
436
- );
437
- protected onRegister(context: EntityPluginContext): Promise<void>;
438
- protected onReady(context: EntityPluginContext): Promise<void>;
439
- protected onShutdown(): Promise<void>;
440
- protected interceptCreate(
441
- input: CreateInput,
442
- executionContext: CreateExecutionContext,
443
- context: EntityPluginContext,
444
- ): Promise<CreateInterceptionResult>;
445
- protected createGenerationHandler(
446
- context: EntityPluginContext,
447
- ): JobHandler | null;
448
- protected getTemplates(): Record<string, Template> | null;
449
- protected getDataSources(): DataSource[];
450
- protected getEntityTypeConfig(): EntityTypeConfig | undefined;
451
- protected derive(
452
- source: BaseEntity,
453
- event: DeriveEvent,
454
- context: EntityPluginContext,
455
- ): Promise<void>;
456
- protected deriveAll(context: EntityPluginContext): Promise<void>;
457
- protected rebuildAll(context: EntityPluginContext): Promise<void>;
458
- ready?(): Promise<void>;
459
- shutdown?(): Promise<void>;
460
- }
461
- export abstract class ServicePlugin<TConfig = unknown> implements Plugin {
462
- readonly type: "service";
463
- readonly id: string;
464
- readonly version: string;
465
- readonly packageName: string;
466
- readonly description?: string;
467
- protected constructor(
468
- id: string,
469
- packageJson: { name: string; version: string; description?: string },
470
- config?: Partial<TConfig>,
471
- configSchema?: z.ZodTypeAny,
472
- );
473
- protected onRegister(context: ServicePluginContext): Promise<void>;
474
- protected onReady(context: ServicePluginContext): Promise<void>;
475
- protected onShutdown(): Promise<void>;
476
- protected getTools(): Promise<Tool[]>;
477
- protected getResources(): Promise<Resource[]>;
478
- protected getInstructions(): Promise<string | undefined>;
479
- getApiRoutes(): ApiRouteDefinition[];
480
- getWebRoutes(): WebRouteDefinition[];
481
- ready?(): Promise<void>;
482
- shutdown?(): Promise<void>;
483
- }
484
- export abstract class InterfacePlugin<
485
- TConfig = unknown,
486
- TTrackingInfo extends BaseJobTrackingInfo = BaseJobTrackingInfo,
487
- > implements Plugin {
488
- readonly type: "interface";
489
- readonly id: string;
490
- readonly version: string;
491
- readonly packageName: string;
492
- readonly description?: string;
493
- protected readonly jobTrackingEntries: Map<string, TTrackingInfo>;
494
- protected constructor(
495
- id: string,
496
- packageJson: { name: string; version: string; description?: string },
497
- config?: Partial<TConfig>,
498
- configSchema?: z.ZodTypeAny,
499
- );
500
- protected onRegister(context: InterfacePluginContext): Promise<void>;
501
- protected onReady(context: InterfacePluginContext): Promise<void>;
502
- protected onShutdown(): Promise<void>;
503
- protected createDaemon(): Daemon | undefined;
504
- requiresDaemonStartup(): boolean;
505
- getWebRoutes(): WebRouteDefinition[];
506
- ready?(): Promise<void>;
507
- shutdown?(): Promise<void>;
508
- }
509
- export abstract class MessageInterfacePlugin<
510
- TConfig = unknown,
511
- TTrackingInfo extends MessageJobTrackingInfo = MessageJobTrackingInfo,
512
- > extends InterfacePlugin<TConfig, TTrackingInfo> {
513
- protected isUploadableTextFile(filename: string, mimetype?: string): boolean;
514
- protected isFileSizeAllowed(size: number): boolean;
515
- protected formatFileUploadMessage(filename: string, content: string): string;
982
+ interface IServiceTemplatesNamespace {
983
+ register(templates: unknown): void;
984
+ }
985
+ interface IViewsNamespace {
986
+ register(views: unknown): void;
987
+ }
988
+ interface ServicePluginContext extends BasePluginContext {
989
+ readonly entities: IEntitiesNamespace;
990
+ readonly templates: IServiceTemplatesNamespace;
991
+ readonly views: IViewsNamespace;
992
+ readonly prompts: IPromptsNamespace;
993
+ registerInstructions(instructions: string): void;
994
+ }
995
+ interface EntityPluginContext extends BasePluginContext {
996
+ readonly entities: IEntitiesNamespace;
997
+ readonly prompts: IPromptsNamespace;
998
+ }
999
+ interface InterfacePluginContext extends BasePluginContext {
1000
+ readonly agent: AgentNamespace;
1001
+ }
1002
+ declare abstract class EntityPlugin<TEntity extends BaseEntity = BaseEntity, TConfig = unknown> implements Plugin {
1003
+ readonly type: "entity";
1004
+ readonly id: string;
1005
+ readonly version: string;
1006
+ readonly packageName: string;
1007
+ readonly description?: string;
1008
+ abstract readonly entityType: string;
1009
+ abstract readonly schema: z.ZodSchema<TEntity>;
1010
+ abstract readonly adapter: EntityAdapter<TEntity>;
1011
+ private readonly delegate;
1012
+ protected constructor(id: string, packageJson: {
1013
+ name: string;
1014
+ version: string;
1015
+ description?: string;
1016
+ }, config: Partial<TConfig>, configSchema: z.ZodTypeAny);
1017
+ protected onRegister(_context: EntityPluginContext): Promise<void>;
1018
+ protected onReady(_context: EntityPluginContext): Promise<void>;
1019
+ protected onShutdown(): Promise<void>;
1020
+ protected getInstructions(): Promise<string | undefined>;
1021
+ protected getEntityTypeConfig(): EntityTypeConfig | undefined;
1022
+ protected getDataSources(): DataSource[];
1023
+ protected interceptCreate(input: CreateInput, _executionContext: CreateExecutionContext, _context: EntityPluginContext): Promise<CreateInterceptionResult>;
1024
+ ready(): Promise<void>;
1025
+ shutdown(): Promise<void>;
1026
+ }
1027
+ declare abstract class InterfacePlugin<TConfig = unknown, TTrackingInfo extends BaseJobTrackingInfo = BaseJobTrackingInfo> implements Plugin {
1028
+ readonly type: "interface";
1029
+ readonly id: string;
1030
+ readonly version: string;
1031
+ readonly packageName: string;
1032
+ readonly description?: string;
1033
+ private readonly delegate;
1034
+ protected constructor(id: string, packageJson: {
1035
+ name: string;
1036
+ version: string;
1037
+ description?: string;
1038
+ }, config: Partial<TConfig>, configSchema: z.ZodTypeAny);
1039
+ protected onRegister(_context: InterfacePluginContext): Promise<void>;
1040
+ protected onReady(_context: InterfacePluginContext): Promise<void>;
1041
+ protected onShutdown(): Promise<void>;
1042
+ protected getTools(): Promise<Tool[]>;
1043
+ protected getResources(): Promise<Resource[]>;
1044
+ protected getInstructions(): Promise<string | undefined>;
1045
+ getWebRoutes(): WebRouteDefinition[];
1046
+ requiresDaemonStartup(): boolean;
1047
+ ready(): Promise<void>;
1048
+ shutdown(): Promise<void>;
1049
+ }
1050
+ declare abstract class MessageInterfacePlugin<TConfig = unknown, TTrackingInfo extends MessageJobTrackingInfo = MessageJobTrackingInfo> extends InterfacePlugin<TConfig, TTrackingInfo> {
1051
+ private readonly messageDelegate;
1052
+ protected constructor(id: string, packageJson: {
1053
+ name: string;
1054
+ version: string;
1055
+ description?: string;
1056
+ }, config: Partial<TConfig>, configSchema: z.ZodTypeAny);
1057
+ protected abstract sendMessageToChannel(channelId: string | null, message: string): void;
1058
+ protected onRegister(_context: InterfacePluginContext): Promise<void>;
1059
+ protected onReady(_context: InterfacePluginContext): Promise<void>;
1060
+ protected onShutdown(): Promise<void>;
1061
+ protected getTools(): Promise<Tool[]>;
1062
+ protected getResources(): Promise<Resource[]>;
1063
+ protected getInstructions(): Promise<string | undefined>;
1064
+ protected sendMessageWithId(_channelId: string | null, _message: string): Promise<string | undefined>;
1065
+ protected editMessage(_channelId: string, _messageId: string, _newMessage: string): Promise<boolean>;
1066
+ protected supportsMessageEditing(): boolean;
1067
+ protected onProgressUpdate(_event: JobProgressEvent): Promise<void>;
1068
+ protected trackAgentResponseForJob(jobId: string, messageId: string, channelId: string): void;
1069
+ registerProgressCallback(callback: (events: JobProgressEvent[]) => void): void;
1070
+ unregisterProgressCallback(): void;
1071
+ getProgressEvents(): JobProgressEvent[];
1072
+ getActiveProgressEvents(): JobProgressEvent[];
1073
+ startProcessingInput(channelId?: string | null): void;
1074
+ endProcessingInput(): void;
1075
+ protected getCurrentChannelId(): string | null;
1076
+ ready(): Promise<void>;
1077
+ shutdown(): Promise<void>;
1078
+ }
1079
+ declare abstract class ServicePlugin<TConfig = unknown> implements Plugin {
1080
+ readonly type: "service";
1081
+ readonly id: string;
1082
+ readonly version: string;
1083
+ readonly packageName: string;
1084
+ readonly description?: string;
1085
+ private readonly delegate;
1086
+ protected constructor(id: string, packageJson: {
1087
+ name: string;
1088
+ version: string;
1089
+ description?: string;
1090
+ }, config: Partial<TConfig>, configSchema: z.ZodTypeAny);
1091
+ protected onRegister(_context: ServicePluginContext): Promise<void>;
1092
+ protected onReady(_context: ServicePluginContext): Promise<void>;
1093
+ protected onShutdown(): Promise<void>;
1094
+ protected getTools(): Promise<Tool[]>;
1095
+ protected getResources(): Promise<Resource[]>;
1096
+ protected getInstructions(): Promise<string | undefined>;
1097
+ ready(): Promise<void>;
1098
+ shutdown(): Promise<void>;
516
1099
  }
517
1100
 
518
- export const urlCaptureConfigSchema: z.ZodSchema<{
519
- captureUrls: boolean;
520
- blockedUrlDomains: string[];
521
- }>;
522
- export function parseConfirmationResponse(input: string): boolean | undefined;
523
- export function formatConfirmationPrompt(action: string): string;
1101
+ /**
1102
+ * Best-effort extension metadata carried across public DTO boundaries.
1103
+ *
1104
+ * Individual keys are not stable public API. When a metadata value becomes a
1105
+ * documented contract, hoist it to a typed top-level field on the owning DTO
1106
+ * schema and keep this bag only as optional extension data.
1107
+ */
1108
+ declare const ExtensionMetadataSchema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
1109
+ type ExtensionMetadata = z.infer<typeof ExtensionMetadataSchema>;
1110
+
1111
+ export { AgentResponseSchema, AnchorProfileSchema, AppInfoSchema, BaseMessageSchema, BrainCharacterSchema, ChatContextSchema, ConversationSchema, EntityPlugin, ExtensionMetadataSchema, InterfacePlugin, MessageInterfacePlugin, MessageResponseSchema, MessageSchema, PendingConfirmationSchema, ServicePlugin, ToolResultDataSchema, createResource, createTool, defineChannel, toolError, toolSuccess, urlCaptureConfigSchema };
1112
+ export type { AgentNamespace, AgentResponse, AnchorProfile, AppInfo, BaseJobTrackingInfo, BaseMessage, BasePluginContext, BrainCharacter, Channel, ChatContext, Conversation, EntityPluginContext, ExtensionMetadata, IConversationsNamespace, IEntitiesNamespace, IEvalNamespace, IIdentityNamespace, IInsightsNamespace, IMessagingNamespace, IPromptsNamespace, IServiceTemplatesNamespace, IViewsNamespace, InterfacePluginContext, JobProgressContext, JobProgressEvent, JobProgressStatus, Message, MessageContext, MessageJobTrackingInfo, MessageResponse, MessageRole, MessageSendOptions, MessageSender, MessageWithPayload, PendingConfirmation, Plugin, PluginConfig, PluginConfigInput, PluginFactory, Prompt, Resource, ResourceTemplate, ServicePluginContext, Tool, ToolConfirmation, ToolContext, ToolResponse, ToolResultData, ToolVisibility };