@rizom/brain 0.2.0-alpha.81 → 0.2.0-alpha.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brain.js +687 -687
- package/dist/entities.d.ts +25 -5
- package/dist/entities.js +64 -64
- package/dist/entities.js.map +11 -10
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/migrations/entity-service/0001_sleepy_mandroid.sql +1 -0
- package/dist/migrations/entity-service/meta/0001_snapshot.json +139 -0
- package/dist/migrations/entity-service/meta/_journal.json +7 -0
- package/dist/plugins.d.ts +22 -5
- package/dist/plugins.js +71 -71
- package/dist/plugins.js.map +19 -18
- package/dist/services.d.ts +19 -2
- package/dist/services.js +68 -68
- package/dist/services.js.map +10 -9
- package/dist/site.js +178 -178
- package/dist/site.js.map +34 -30
- package/dist/templates.d.ts +3 -3
- package/dist/templates.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE `entities` ADD `visibility` text DEFAULT 'public' NOT NULL CHECK (`visibility` IN ('public', 'shared', 'restricted'));
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "6",
|
|
3
|
+
"dialect": "sqlite",
|
|
4
|
+
"id": "3614c8be-8121-4f23-bfab-2d863ca03c28",
|
|
5
|
+
"prevId": "99d7ed2f-bc45-4bec-ab00-657cc53cd21c",
|
|
6
|
+
"tables": {
|
|
7
|
+
"entities": {
|
|
8
|
+
"name": "entities",
|
|
9
|
+
"columns": {
|
|
10
|
+
"id": {
|
|
11
|
+
"name": "id",
|
|
12
|
+
"type": "text",
|
|
13
|
+
"primaryKey": false,
|
|
14
|
+
"notNull": true,
|
|
15
|
+
"autoincrement": false
|
|
16
|
+
},
|
|
17
|
+
"entityType": {
|
|
18
|
+
"name": "entityType",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": true,
|
|
22
|
+
"autoincrement": false
|
|
23
|
+
},
|
|
24
|
+
"content": {
|
|
25
|
+
"name": "content",
|
|
26
|
+
"type": "text",
|
|
27
|
+
"primaryKey": false,
|
|
28
|
+
"notNull": true,
|
|
29
|
+
"autoincrement": false
|
|
30
|
+
},
|
|
31
|
+
"contentHash": {
|
|
32
|
+
"name": "contentHash",
|
|
33
|
+
"type": "text",
|
|
34
|
+
"primaryKey": false,
|
|
35
|
+
"notNull": true,
|
|
36
|
+
"autoincrement": false
|
|
37
|
+
},
|
|
38
|
+
"visibility": {
|
|
39
|
+
"name": "visibility",
|
|
40
|
+
"type": "text",
|
|
41
|
+
"primaryKey": false,
|
|
42
|
+
"notNull": true,
|
|
43
|
+
"autoincrement": false,
|
|
44
|
+
"default": "'public'"
|
|
45
|
+
},
|
|
46
|
+
"metadata": {
|
|
47
|
+
"name": "metadata",
|
|
48
|
+
"type": "text",
|
|
49
|
+
"primaryKey": false,
|
|
50
|
+
"notNull": true,
|
|
51
|
+
"autoincrement": false,
|
|
52
|
+
"default": "'{}'"
|
|
53
|
+
},
|
|
54
|
+
"created": {
|
|
55
|
+
"name": "created",
|
|
56
|
+
"type": "integer",
|
|
57
|
+
"primaryKey": false,
|
|
58
|
+
"notNull": true,
|
|
59
|
+
"autoincrement": false
|
|
60
|
+
},
|
|
61
|
+
"updated": {
|
|
62
|
+
"name": "updated",
|
|
63
|
+
"type": "integer",
|
|
64
|
+
"primaryKey": false,
|
|
65
|
+
"notNull": true,
|
|
66
|
+
"autoincrement": false
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"indexes": {},
|
|
70
|
+
"foreignKeys": {},
|
|
71
|
+
"compositePrimaryKeys": {
|
|
72
|
+
"entities_id_entityType_pk": {
|
|
73
|
+
"columns": ["id", "entityType"],
|
|
74
|
+
"name": "entities_id_entityType_pk"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"uniqueConstraints": {},
|
|
78
|
+
"checkConstraints": {
|
|
79
|
+
"entities_visibility_check": {
|
|
80
|
+
"name": "entities_visibility_check",
|
|
81
|
+
"value": "\"entities\".\"visibility\" IN ('public', 'shared', 'restricted')"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
"embeddings": {
|
|
86
|
+
"name": "embeddings",
|
|
87
|
+
"columns": {
|
|
88
|
+
"entity_id": {
|
|
89
|
+
"name": "entity_id",
|
|
90
|
+
"type": "text",
|
|
91
|
+
"primaryKey": false,
|
|
92
|
+
"notNull": true,
|
|
93
|
+
"autoincrement": false
|
|
94
|
+
},
|
|
95
|
+
"entity_type": {
|
|
96
|
+
"name": "entity_type",
|
|
97
|
+
"type": "text",
|
|
98
|
+
"primaryKey": false,
|
|
99
|
+
"notNull": true,
|
|
100
|
+
"autoincrement": false
|
|
101
|
+
},
|
|
102
|
+
"embedding": {
|
|
103
|
+
"name": "embedding",
|
|
104
|
+
"type": "F32_BLOB(1536)",
|
|
105
|
+
"primaryKey": false,
|
|
106
|
+
"notNull": true,
|
|
107
|
+
"autoincrement": false
|
|
108
|
+
},
|
|
109
|
+
"content_hash": {
|
|
110
|
+
"name": "content_hash",
|
|
111
|
+
"type": "text",
|
|
112
|
+
"primaryKey": false,
|
|
113
|
+
"notNull": true,
|
|
114
|
+
"autoincrement": false
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"indexes": {},
|
|
118
|
+
"foreignKeys": {},
|
|
119
|
+
"compositePrimaryKeys": {
|
|
120
|
+
"embeddings_entity_id_entity_type_pk": {
|
|
121
|
+
"columns": ["entity_id", "entity_type"],
|
|
122
|
+
"name": "embeddings_entity_id_entity_type_pk"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"uniqueConstraints": {},
|
|
126
|
+
"checkConstraints": {}
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"views": {},
|
|
130
|
+
"enums": {},
|
|
131
|
+
"_meta": {
|
|
132
|
+
"schemas": {},
|
|
133
|
+
"tables": {},
|
|
134
|
+
"columns": {}
|
|
135
|
+
},
|
|
136
|
+
"internal": {
|
|
137
|
+
"indexes": {}
|
|
138
|
+
}
|
|
139
|
+
}
|
package/dist/plugins.d.ts
CHANGED
|
@@ -65,6 +65,9 @@ interface EntityJobOptions {
|
|
|
65
65
|
priority?: number;
|
|
66
66
|
maxRetries?: number;
|
|
67
67
|
}
|
|
68
|
+
declare const canonicalContentVisibilitySchema: z.ZodEnum<["public", "shared", "restricted"]>;
|
|
69
|
+
type ContentVisibility = z.infer<typeof canonicalContentVisibilitySchema>;
|
|
70
|
+
type RawContentVisibility = ContentVisibility | "private";
|
|
68
71
|
/**
|
|
69
72
|
* Options for entity creation (extends EntityJobOptions with deduplication)
|
|
70
73
|
*/
|
|
@@ -107,6 +110,7 @@ interface BaseEntity<TMetadata = Record<string, unknown>> {
|
|
|
107
110
|
content: string;
|
|
108
111
|
created: string;
|
|
109
112
|
updated: string;
|
|
113
|
+
visibility: ContentVisibility;
|
|
110
114
|
metadata: TMetadata;
|
|
111
115
|
/** SHA256 hash of content for change detection */
|
|
112
116
|
contentHash: string;
|
|
@@ -115,10 +119,11 @@ interface BaseEntity<TMetadata = Record<string, unknown>> {
|
|
|
115
119
|
* Entity input type for creation - allows partial entities with optional system fields
|
|
116
120
|
* contentHash is excluded because it's computed automatically by the entity service
|
|
117
121
|
*/
|
|
118
|
-
type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash"> & {
|
|
122
|
+
type EntityInput<T extends BaseEntity> = Omit<T, "id" | "created" | "updated" | "contentHash" | "visibility"> & {
|
|
119
123
|
id?: string;
|
|
120
124
|
created?: string;
|
|
121
125
|
updated?: string;
|
|
126
|
+
visibility?: RawContentVisibility;
|
|
122
127
|
};
|
|
123
128
|
/**
|
|
124
129
|
* Search result type
|
|
@@ -189,7 +194,7 @@ type CreateInterceptor = (input: CreateInput, executionContext: CreateExecutionC
|
|
|
189
194
|
*/
|
|
190
195
|
interface EntityAdapter<TEntity extends BaseEntity<TMetadata>, TMetadata = Record<string, unknown>> {
|
|
191
196
|
entityType: string;
|
|
192
|
-
schema: z.
|
|
197
|
+
schema: z.ZodType<TEntity, z.ZodTypeDef, unknown>;
|
|
193
198
|
toMarkdown(entity: TEntity): string;
|
|
194
199
|
fromMarkdown(markdown: string): Partial<TEntity>;
|
|
195
200
|
extractMetadata(entity: TEntity): TMetadata;
|
|
@@ -230,6 +235,7 @@ interface ListOptions<TMetadata = Record<string, unknown>> {
|
|
|
230
235
|
sortFields?: SortField[];
|
|
231
236
|
filter?: {
|
|
232
237
|
metadata?: Partial<TMetadata>;
|
|
238
|
+
visibilityScope?: ContentVisibility;
|
|
233
239
|
};
|
|
234
240
|
/** Filter to only entities with metadata.status = "published" */
|
|
235
241
|
publishedOnly?: boolean;
|
|
@@ -246,6 +252,7 @@ interface SearchOptions {
|
|
|
246
252
|
sortDirection?: "asc" | "desc";
|
|
247
253
|
/** Score multipliers per entity type - applied after initial search */
|
|
248
254
|
weight?: Record<string, number>;
|
|
255
|
+
visibilityScope?: ContentVisibility;
|
|
249
256
|
}
|
|
250
257
|
/**
|
|
251
258
|
* Configuration for entity type registration
|
|
@@ -267,6 +274,11 @@ interface EntityTypeConfig {
|
|
|
267
274
|
interface GetEntityRequest {
|
|
268
275
|
entityType: string;
|
|
269
276
|
id: string;
|
|
277
|
+
/**
|
|
278
|
+
* Optional visibility scope. Undefined fails closed to "public" — callers
|
|
279
|
+
* with elevated access must opt up explicitly.
|
|
280
|
+
*/
|
|
281
|
+
visibilityScope?: ContentVisibility;
|
|
270
282
|
}
|
|
271
283
|
type GetEntityRawRequest = GetEntityRequest;
|
|
272
284
|
interface ListEntitiesRequest {
|
|
@@ -316,7 +328,12 @@ interface ICoreEntityService {
|
|
|
316
328
|
getEntityTypes(): string[];
|
|
317
329
|
hasEntityType(type: string): boolean;
|
|
318
330
|
countEntities(request: CountEntitiesRequest): Promise<number>;
|
|
319
|
-
|
|
331
|
+
/**
|
|
332
|
+
* Group counts by entity type. Fails closed: undefined visibilityScope
|
|
333
|
+
* filters to public-only counts so aggregate insights cannot reveal
|
|
334
|
+
* non-public entity existence.
|
|
335
|
+
*/
|
|
336
|
+
getEntityCounts(visibilityScope?: ContentVisibility): Promise<Array<{
|
|
320
337
|
entityType: string;
|
|
321
338
|
count: number;
|
|
322
339
|
}>>;
|
|
@@ -330,7 +347,7 @@ interface ICoreEntityService {
|
|
|
330
347
|
*/
|
|
331
348
|
interface IEntitiesNamespace {
|
|
332
349
|
/** Register a new entity type with schema and adapter */
|
|
333
|
-
register<TEntity extends BaseEntity>(entityType: string, schema: z.
|
|
350
|
+
register<TEntity extends BaseEntity>(entityType: string, schema: z.ZodType<TEntity, z.ZodTypeDef, unknown>, adapter: EntityAdapter<TEntity>, config?: EntityTypeConfig): void;
|
|
334
351
|
/** Get the adapter for an entity type */
|
|
335
352
|
getAdapter<TEntity extends BaseEntity>(entityType: string): EntityAdapter<TEntity> | undefined;
|
|
336
353
|
/** Extend an adapter's frontmatterSchema with additional fields */
|
|
@@ -1175,7 +1192,7 @@ interface IMessagingNamespace {
|
|
|
1175
1192
|
subscribe<T = unknown, R = unknown>(channel: string | Channel<T, R>, handler: (message: MessageWithPayload<T>) => Promise<MessageResponse<R>>): () => void;
|
|
1176
1193
|
}
|
|
1177
1194
|
type EvalHandler<TInput = unknown, TOutput = unknown> = (input: TInput) => Promise<TOutput>;
|
|
1178
|
-
type InsightHandler = (entityService: IEntityService) => Promise<Record<string, unknown>>;
|
|
1195
|
+
type InsightHandler = (entityService: IEntityService, visibilityScope: ContentVisibility) => Promise<Record<string, unknown>>;
|
|
1179
1196
|
interface IEvalNamespace {
|
|
1180
1197
|
registerHandler(handlerId: string, handler: EvalHandler): void;
|
|
1181
1198
|
}
|