@wordbricks/persona 0.1.0

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.
@@ -0,0 +1,788 @@
1
+ // src/schema/persona-memory.ts
2
+ import { sql } from "drizzle-orm";
3
+ import {
4
+ boolean,
5
+ check,
6
+ index,
7
+ integer,
8
+ jsonb,
9
+ real,
10
+ text,
11
+ timestamp,
12
+ uniqueIndex,
13
+ vector
14
+ } from "drizzle-orm/pg-core";
15
+
16
+ // src/schema/table.ts
17
+ import { pgTable as basePgTable } from "drizzle-orm/pg-core";
18
+ var pgTable = ((...args) => basePgTable(...args).enableRLS());
19
+
20
+ // src/schema/ulid.ts
21
+ import { ulid } from "ulid";
22
+
23
+ // src/schema/persona-memory.ts
24
+ var PERSONA_EMBEDDING_DIMENSION = 1536;
25
+ var PERSONA_PROFILE_TYPES = [
26
+ "simulated_character",
27
+ "living_public_figure",
28
+ "deceased_public_figure",
29
+ "private_authorized_person",
30
+ "synthetic_role"
31
+ ];
32
+ var PERSONA_CONSENT_STATUSES = [
33
+ "explicit_consent",
34
+ "authorized",
35
+ "fictional_or_authorized",
36
+ "public_material_only",
37
+ "unknown"
38
+ ];
39
+ var PERSONA_PROFILE_STATES = [
40
+ "draft",
41
+ "review_pending",
42
+ "active",
43
+ "archived",
44
+ "deleted"
45
+ ];
46
+ var PERSONA_ALIAS_SURFACES = ["slack", "web", "cli"];
47
+ var PERSONA_ALIAS_STATES = ["active", "disabled", "deleted"];
48
+ var PERSONA_ALIAS_SURFACES_SQL = PERSONA_ALIAS_SURFACES.map(
49
+ (surface) => `'${surface}'`
50
+ ).join(", ");
51
+ var PERSONA_ALIAS_STATES_SQL = PERSONA_ALIAS_STATES.map(
52
+ (state) => `'${state}'`
53
+ ).join(", ");
54
+ var PERSONA_SOURCE_TYPES = [
55
+ "interview_transcript",
56
+ "book",
57
+ "essay",
58
+ "speech",
59
+ "conversation",
60
+ "biography",
61
+ "profile_document",
62
+ "seed",
63
+ "external_source",
64
+ "synthetic"
65
+ ];
66
+ var PERSONA_SOURCE_PRIORITIES = [
67
+ "first_person_private",
68
+ "first_person_public",
69
+ "authored_work",
70
+ "direct_interview",
71
+ "recorded_speech",
72
+ "verified_correspondence",
73
+ "authorized_biography",
74
+ "third_party_biography",
75
+ "news_article",
76
+ "unverified_secondary",
77
+ "synthetic"
78
+ ];
79
+ var PERSONA_RIGHTS_STATUSES = [
80
+ "licensed",
81
+ "owned",
82
+ "public",
83
+ "fair_use_reviewed",
84
+ "unknown"
85
+ ];
86
+ var PERSONA_PRIVACY_LEVELS = [
87
+ "public",
88
+ "internal",
89
+ "private",
90
+ "sensitive"
91
+ ];
92
+ var PERSONA_MEMORY_STATES = [
93
+ "draft",
94
+ "active",
95
+ "conflicted",
96
+ "superseded",
97
+ "archived",
98
+ "deleted"
99
+ ];
100
+ var PERSONA_BELIEF_TYPES = [
101
+ "moral_principle",
102
+ "epistemic_principle",
103
+ "political_belief",
104
+ "aesthetic_preference",
105
+ "relationship_belief",
106
+ "self_concept",
107
+ "professional_norm",
108
+ "conflict_strategy"
109
+ ];
110
+ var PERSONA_BELIEF_STANCES = [
111
+ "support",
112
+ "oppose",
113
+ "ambivalent",
114
+ "revised"
115
+ ];
116
+ var PERSONA_FACT_TYPES = [
117
+ "uses_product",
118
+ "prefers_brand",
119
+ "recommends",
120
+ "dislikes",
121
+ "owns_item",
122
+ "wears_item",
123
+ "uses_tool",
124
+ "eats_or_drinks",
125
+ "works_with",
126
+ "located_at",
127
+ "mentions_entity",
128
+ "other"
129
+ ];
130
+ var PERSONA_FACT_OBJECT_TYPES = [
131
+ "brand",
132
+ "product",
133
+ "tool",
134
+ "clothing",
135
+ "food",
136
+ "place",
137
+ "person",
138
+ "organization",
139
+ "work",
140
+ "event",
141
+ "concept",
142
+ "text"
143
+ ];
144
+ var PERSONA_INTERACTION_MEMORY_STATES = [
145
+ "recorded",
146
+ "consolidation_candidate",
147
+ "consolidated",
148
+ "discarded",
149
+ "deleted"
150
+ ];
151
+ var PERSONA_LIFECYCLE_EFFECT_TYPES = [
152
+ "extract_episode",
153
+ "annotate_emotion",
154
+ "extract_belief",
155
+ "extract_habit",
156
+ "distill_style",
157
+ "consolidate_memory",
158
+ "apply_correction",
159
+ "apply_forget",
160
+ "grounding_review"
161
+ ];
162
+ var PERSONA_LIFECYCLE_EFFECT_STATUSES = [
163
+ "pending",
164
+ "running",
165
+ "completed",
166
+ "retry_scheduled",
167
+ "failed",
168
+ "cancelled"
169
+ ];
170
+ var PERSONA_EXTERNAL_MEMORY_PROVIDERS = ["hindsight"];
171
+ var PERSONA_EXTERNAL_MEMORY_REF_STATES = [
172
+ "active",
173
+ "deleted",
174
+ "failed",
175
+ "disabled"
176
+ ];
177
+ var PERSONA_EXTERNAL_MEMORY_LOCAL_TARGET_KINDS = [
178
+ "episode",
179
+ "fact",
180
+ "belief",
181
+ "habit",
182
+ "style",
183
+ "interaction",
184
+ "source_document",
185
+ "source_chunk"
186
+ ];
187
+ var PERSONA_EXTERNAL_MEMORY_PROVIDERS_SQL = PERSONA_EXTERNAL_MEMORY_PROVIDERS.map((provider) => `'${provider}'`).join(
188
+ ", "
189
+ );
190
+ var PERSONA_EXTERNAL_MEMORY_REF_STATES_SQL = PERSONA_EXTERNAL_MEMORY_REF_STATES.map((state) => `'${state}'`).join(", ");
191
+ var PERSONA_EXTERNAL_MEMORY_LOCAL_TARGET_KINDS_SQL = PERSONA_EXTERNAL_MEMORY_LOCAL_TARGET_KINDS.map((kind) => `'${kind}'`).join(
192
+ ", "
193
+ );
194
+ var PERSONA_SCOPES = ["organization", "public"];
195
+ var personaProfiles = pgTable(
196
+ "persona_profiles",
197
+ {
198
+ consentStatus: text("consent_status").notNull().$type(),
199
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
200
+ displayName: text("display_name").notNull(),
201
+ id: text("id").primaryKey().$defaultFn(ulid),
202
+ organizationId: text("organization_id"),
203
+ personaKey: text("persona_key").notNull(),
204
+ personaScope: text("persona_scope").notNull().$type().default("organization"),
205
+ personaType: text("persona_type").notNull().$type(),
206
+ personaVersion: text("persona_version").notNull().default("v1"),
207
+ policy: jsonb("policy").$type().notNull(),
208
+ profile: jsonb("profile").$type().notNull(),
209
+ sourceRef: text("source_ref"),
210
+ state: text("state").notNull().$type().default("active"),
211
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
212
+ updatedByUserId: text("updated_by_user_id")
213
+ },
214
+ (table) => [
215
+ // Partial: public persona templates have a null organization id; org
216
+ // uniqueness only applies to org-scoped rows. Writers using ON CONFLICT
217
+ // against this index must pass the same predicate via targetWhere or
218
+ // Postgres cannot match the index.
219
+ uniqueIndex("idx_persona_profiles_org_key").on(table.organizationId, table.personaKey).where(sql`organization_id is not null`),
220
+ uniqueIndex("idx_persona_profiles_public_key").on(table.personaKey).where(sql`organization_id is null`),
221
+ index("idx_persona_profiles_org_state").on(
222
+ table.organizationId,
223
+ table.state
224
+ ),
225
+ index("idx_persona_profiles_scope_state").on(
226
+ table.personaScope,
227
+ table.state
228
+ )
229
+ ]
230
+ );
231
+ var personaAliases = pgTable(
232
+ "persona_aliases",
233
+ {
234
+ aliasKey: text("alias_key").notNull(),
235
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
236
+ createdByUserId: text("created_by_user_id"),
237
+ id: text("id").primaryKey().$defaultFn(ulid),
238
+ organizationId: text("organization_id").notNull(),
239
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
240
+ state: text("state").notNull().$type().default("active"),
241
+ surface: text("surface").notNull().$type().default("slack"),
242
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
243
+ updatedByUserId: text("updated_by_user_id")
244
+ },
245
+ (table) => [
246
+ index("idx_persona_aliases_persona").on(table.personaId),
247
+ index("idx_persona_aliases_org_surface_state").on(
248
+ table.organizationId,
249
+ table.surface,
250
+ table.state
251
+ ),
252
+ uniqueIndex("idx_persona_aliases_org_surface_alias").on(table.organizationId, table.surface, table.aliasKey).where(sql`state <> 'deleted'`),
253
+ check(
254
+ "persona_aliases_alias_key_length_check",
255
+ sql`char_length(${table.aliasKey}) between 1 and 80`
256
+ ),
257
+ check(
258
+ "persona_aliases_alias_key_no_whitespace_check",
259
+ sql`${table.aliasKey} !~ '\\s'`
260
+ ),
261
+ check(
262
+ "persona_aliases_surface_check",
263
+ sql`${table.surface} in (${sql.raw(PERSONA_ALIAS_SURFACES_SQL)})`
264
+ ),
265
+ check(
266
+ "persona_aliases_state_check",
267
+ sql`${table.state} in (${sql.raw(PERSONA_ALIAS_STATES_SQL)})`
268
+ )
269
+ ]
270
+ );
271
+ var personaSourceDocuments = pgTable(
272
+ "persona_source_documents",
273
+ {
274
+ author: text("author"),
275
+ consentStatus: text("consent_status").notNull().$type(),
276
+ contentHash: text("content_hash"),
277
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
278
+ id: text("id").primaryKey().$defaultFn(ulid),
279
+ ingestedAt: timestamp("ingested_at", { withTimezone: true }).notNull().defaultNow(),
280
+ metadata: jsonb("metadata").$type().notNull().default({}),
281
+ organizationId: text("organization_id"),
282
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
283
+ privacyLevel: text("privacy_level").notNull().$type().default("internal"),
284
+ publicationDate: text("publication_date"),
285
+ reliability: real("reliability").notNull().default(0.75),
286
+ rightsStatus: text("rights_status").notNull().$type(),
287
+ sourcePriority: text("source_priority").notNull().$type(),
288
+ sourceType: text("source_type").notNull().$type(),
289
+ sourceUri: text("source_uri"),
290
+ state: text("state").notNull().$type().default("active"),
291
+ title: text("title").notNull(),
292
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
293
+ },
294
+ (table) => [
295
+ index("idx_persona_source_documents_persona").on(
296
+ table.organizationId,
297
+ table.personaId,
298
+ table.state
299
+ ),
300
+ uniqueIndex("idx_persona_source_documents_hash").on(table.organizationId, table.personaId, table.contentHash).where(sql`${table.contentHash} is not null`)
301
+ ]
302
+ );
303
+ var personaSourceChunks = pgTable(
304
+ "persona_source_chunks",
305
+ {
306
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
307
+ embeddingId: text("embedding_id"),
308
+ emotions: jsonb("emotions").$type().notNull().default([]),
309
+ endChar: integer("end_char"),
310
+ entities: jsonb("entities").$type().notNull().default([]),
311
+ id: text("id").primaryKey().$defaultFn(ulid),
312
+ organizationId: text("organization_id"),
313
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
314
+ sourceDocumentId: text("source_document_id").notNull().references(() => personaSourceDocuments.id, { onDelete: "cascade" }),
315
+ startChar: integer("start_char"),
316
+ text: text("text").notNull(),
317
+ themes: jsonb("themes").$type().notNull().default([]),
318
+ timeMentions: jsonb("time_mentions").$type().notNull().default([])
319
+ },
320
+ (table) => [
321
+ index("idx_persona_source_chunks_document").on(table.sourceDocumentId),
322
+ index("idx_persona_source_chunks_persona").on(
323
+ table.organizationId,
324
+ table.personaId
325
+ )
326
+ ]
327
+ );
328
+ var personaFacts = pgTable(
329
+ "persona_facts",
330
+ {
331
+ activationCount: integer("activation_count").notNull().default(0),
332
+ claimText: text("claim_text").notNull(),
333
+ confidence: real("confidence").notNull(),
334
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
335
+ evidenceSpan: text("evidence_span"),
336
+ factType: text("fact_type").notNull().$type(),
337
+ firstPersonForm: text("first_person_form"),
338
+ id: text("id").primaryKey().$defaultFn(ulid),
339
+ lastActivatedAt: timestamp("last_activated_at", { withTimezone: true }),
340
+ objectKey: text("object_key"),
341
+ objectName: text("object_name").notNull(),
342
+ objectType: text("object_type").notNull().$type(),
343
+ organizationId: text("organization_id"),
344
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
345
+ privacyLevel: text("privacy_level").notNull().$type().default("internal"),
346
+ sourceChunkId: text("source_chunk_id").references(
347
+ () => personaSourceChunks.id,
348
+ { onDelete: "set null" }
349
+ ),
350
+ sourceDocumentId: text("source_document_id").notNull().references(() => personaSourceDocuments.id, { onDelete: "cascade" }),
351
+ sourceRefs: jsonb("source_refs").$type().notNull().default([]),
352
+ state: text("state").notNull().$type().default("active"),
353
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
354
+ },
355
+ (table) => [
356
+ index("idx_persona_facts_persona").on(
357
+ table.organizationId,
358
+ table.personaId,
359
+ table.state
360
+ ),
361
+ index("idx_persona_facts_object").on(
362
+ table.personaId,
363
+ table.objectType,
364
+ table.objectKey
365
+ ),
366
+ index("idx_persona_facts_source").on(
367
+ table.sourceDocumentId,
368
+ table.sourceChunkId
369
+ )
370
+ ]
371
+ );
372
+ var personaEpisodeMemories = pgTable(
373
+ "persona_episode_memories",
374
+ {
375
+ activationCount: integer("activation_count").notNull().default(0),
376
+ confidence: real("confidence").notNull(),
377
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
378
+ eventSummary: text("event_summary").notNull(),
379
+ firstPersonRecollection: text("first_person_recollection"),
380
+ id: text("id").primaryKey().$defaultFn(ulid),
381
+ lastActivatedAt: timestamp("last_activated_at", { withTimezone: true }),
382
+ location: jsonb("location").$type(),
383
+ organizationId: text("organization_id"),
384
+ people: jsonb("people").$type().notNull().default([]),
385
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
386
+ privacyLevel: text("privacy_level").notNull().$type().default("internal"),
387
+ sourceRefs: jsonb("source_refs").$type().notNull().default([]),
388
+ state: text("state").notNull().$type().default("active"),
389
+ themes: jsonb("themes").$type().notNull().default([]),
390
+ thoughtAnnotations: jsonb("thought_annotations").$type().notNull().default([]),
391
+ time: jsonb("time").$type().notNull().default({}),
392
+ title: text("title").notNull(),
393
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
394
+ },
395
+ (table) => [
396
+ index("idx_persona_episode_memories_persona").on(
397
+ table.organizationId,
398
+ table.personaId,
399
+ table.state
400
+ ),
401
+ index("idx_persona_episode_memories_created").on(table.createdAt)
402
+ ]
403
+ );
404
+ var personaEmotionalSalience = pgTable(
405
+ "persona_emotional_salience",
406
+ {
407
+ arousal: real("arousal").notNull(),
408
+ confidence: real("confidence").notNull().default(0.75),
409
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
410
+ dominance: real("dominance").notNull(),
411
+ emotions: jsonb("emotions").$type().notNull().default([]),
412
+ episodeMemoryId: text("episode_memory_id").notNull().references(() => personaEpisodeMemories.id, { onDelete: "cascade" }),
413
+ id: text("id").primaryKey().$defaultFn(ulid),
414
+ notes: text("notes"),
415
+ organizationId: text("organization_id"),
416
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
417
+ retrievalBoost: real("retrieval_boost").notNull().default(1),
418
+ salienceScore: real("salience_score").notNull(),
419
+ selfRelevance: real("self_relevance").notNull(),
420
+ socialRelevance: real("social_relevance").notNull().default(0),
421
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
422
+ valence: real("valence").notNull()
423
+ },
424
+ (table) => [
425
+ uniqueIndex("idx_persona_emotional_salience_episode").on(
426
+ table.episodeMemoryId
427
+ ),
428
+ index("idx_persona_emotional_salience_persona").on(
429
+ table.organizationId,
430
+ table.personaId
431
+ )
432
+ ]
433
+ );
434
+ var personaMoodStates = pgTable(
435
+ "persona_mood_states",
436
+ {
437
+ arousal: real("arousal").notNull().default(0.3),
438
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
439
+ dominance: real("dominance").notNull().default(0.5),
440
+ id: text("id").primaryKey().$defaultFn(ulid),
441
+ organizationId: text("organization_id").notNull(),
442
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
443
+ turnCount: integer("turn_count").notNull().default(0),
444
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
445
+ userId: text("user_id").notNull(),
446
+ valence: real("valence").notNull().default(0.1)
447
+ },
448
+ (table) => [
449
+ uniqueIndex("idx_persona_mood_states_scope").on(
450
+ table.organizationId,
451
+ table.personaId,
452
+ table.userId
453
+ )
454
+ ]
455
+ );
456
+ var personaSemanticBeliefs = pgTable(
457
+ "persona_semantic_beliefs",
458
+ {
459
+ activationCount: integer("activation_count").notNull().default(0),
460
+ beliefType: text("belief_type").notNull().$type(),
461
+ confidence: real("confidence").notNull(),
462
+ contradictingSourceIds: jsonb("contradicting_source_ids").$type().notNull().default([]),
463
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
464
+ domain: text("domain").notNull(),
465
+ exceptions: jsonb("exceptions").$type().notNull().default([]),
466
+ firstPersonForm: text("first_person_form"),
467
+ id: text("id").primaryKey().$defaultFn(ulid),
468
+ lastActivatedAt: timestamp("last_activated_at", { withTimezone: true }),
469
+ organizationId: text("organization_id"),
470
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
471
+ privacyLevel: text("privacy_level").notNull().$type().default("internal"),
472
+ proposition: text("proposition").notNull(),
473
+ stance: text("stance").notNull().$type(),
474
+ state: text("state").notNull().$type().default("active"),
475
+ strength: real("strength").notNull(),
476
+ supportingMemoryIds: jsonb("supporting_memory_ids").$type().notNull().default([]),
477
+ supportingSourceIds: jsonb("supporting_source_ids").$type().notNull().default([]),
478
+ temporalValidity: jsonb("temporal_validity").$type().notNull().default({}),
479
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
480
+ },
481
+ (table) => [
482
+ index("idx_persona_semantic_beliefs_persona").on(
483
+ table.organizationId,
484
+ table.personaId,
485
+ table.state
486
+ ),
487
+ index("idx_persona_semantic_beliefs_domain").on(table.domain)
488
+ ]
489
+ );
490
+ var personaHabitPatterns = pgTable(
491
+ "persona_habit_patterns",
492
+ {
493
+ activationCount: integer("activation_count").notNull().default(0),
494
+ avoidPatterns: jsonb("avoid_patterns").$type().notNull().default([]),
495
+ confidence: real("confidence").notNull(),
496
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
497
+ defaultResponsePattern: jsonb("default_response_pattern").$type().notNull(),
498
+ id: text("id").primaryKey().$defaultFn(ulid),
499
+ lastActivatedAt: timestamp("last_activated_at", { withTimezone: true }),
500
+ organizationId: text("organization_id"),
501
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
502
+ rhetoricalMoves: jsonb("rhetorical_moves").$type().notNull().default([]),
503
+ state: text("state").notNull().$type().default("active"),
504
+ strength: real("strength").notNull(),
505
+ supportingExampleIds: jsonb("supporting_example_ids").$type().notNull().default([]),
506
+ tone: jsonb("tone").$type().notNull().default({}),
507
+ trigger: jsonb("trigger").$type().notNull(),
508
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
509
+ },
510
+ (table) => [
511
+ index("idx_persona_habit_patterns_persona").on(
512
+ table.organizationId,
513
+ table.personaId,
514
+ table.state
515
+ )
516
+ ]
517
+ );
518
+ var personaStyleProfiles = pgTable(
519
+ "persona_style_profiles",
520
+ {
521
+ activationCount: integer("activation_count").notNull().default(0),
522
+ avoidPhrases: jsonb("avoid_phrases").$type().notNull().default([]),
523
+ commonPhrases: jsonb("common_phrases").$type().notNull().default([]),
524
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
525
+ id: text("id").primaryKey().$defaultFn(ulid),
526
+ lastActivatedAt: timestamp("last_activated_at", { withTimezone: true }),
527
+ lexicalPreferences: jsonb("lexical_preferences").$type().notNull().default({}),
528
+ organizationId: text("organization_id"),
529
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
530
+ preferredRhetoricalMoves: jsonb("preferred_rhetorical_moves").$type().notNull().default([]),
531
+ register: text("register").notNull(),
532
+ sentenceLength: text("sentence_length").notNull(),
533
+ state: text("state").notNull().$type().default("active"),
534
+ toneVector: jsonb("tone_vector").$type().notNull().default({}),
535
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
536
+ },
537
+ (table) => [
538
+ index("idx_persona_style_profiles_persona").on(
539
+ table.organizationId,
540
+ table.personaId,
541
+ table.state
542
+ )
543
+ ]
544
+ );
545
+ var personaWorkspaceStates = pgTable(
546
+ "persona_workspace_states",
547
+ {
548
+ chatMessageId: text("chat_message_id"),
549
+ chatSessionId: text("chat_session_id"),
550
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
551
+ id: text("id").primaryKey().$defaultFn(ulid),
552
+ organizationId: text("organization_id").notNull(),
553
+ payload: jsonb("payload").$type().notNull(),
554
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
555
+ userId: text("user_id"),
556
+ userMessage: text("user_message").notNull()
557
+ },
558
+ (table) => [
559
+ index("idx_persona_workspace_states_session").on(table.chatSessionId),
560
+ index("idx_persona_workspace_states_persona").on(
561
+ table.organizationId,
562
+ table.personaId
563
+ )
564
+ ]
565
+ );
566
+ var personaInteractionMemories = pgTable(
567
+ "persona_interaction_memories",
568
+ {
569
+ chatMessageId: text("chat_message_id"),
570
+ chatSessionId: text("chat_session_id"),
571
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
572
+ id: text("id").primaryKey().$defaultFn(ulid),
573
+ interactionSummary: text("interaction_summary").notNull(),
574
+ newPersonaMemory: jsonb("new_persona_memory").$type(),
575
+ newUserPreference: text("new_user_preference"),
576
+ organizationId: text("organization_id").notNull(),
577
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
578
+ shouldConsolidate: boolean("should_consolidate").notNull().default(false),
579
+ state: text("state").notNull().$type().default("recorded"),
580
+ ttlDays: integer("ttl_days").notNull().default(30),
581
+ userId: text("user_id")
582
+ },
583
+ (table) => [
584
+ index("idx_persona_interaction_memories_persona").on(
585
+ table.organizationId,
586
+ table.personaId,
587
+ table.state
588
+ ),
589
+ index("idx_persona_interaction_memories_session").on(table.chatSessionId)
590
+ ]
591
+ );
592
+ var personaExternalMemoryRefs = pgTable(
593
+ "persona_external_memory_refs",
594
+ {
595
+ chatMessageId: text("chat_message_id"),
596
+ chatSessionId: text("chat_session_id"),
597
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
598
+ externalBankId: text("external_bank_id").notNull(),
599
+ externalMemoryId: text("external_memory_id"),
600
+ externalObservationId: text("external_observation_id"),
601
+ id: text("id").primaryKey().$defaultFn(ulid),
602
+ lastError: text("last_error"),
603
+ localTargetId: text("local_target_id"),
604
+ localTargetKind: text("local_target_kind").$type(),
605
+ metadata: jsonb("metadata").$type().notNull().default({}),
606
+ organizationId: text("organization_id").notNull(),
607
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
608
+ privacyLevel: text("privacy_level").notNull().$type(),
609
+ provider: text("provider").notNull().$type().default("hindsight"),
610
+ state: text("state").notNull().$type().default("active"),
611
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
612
+ userId: text("user_id")
613
+ },
614
+ (table) => [
615
+ index("idx_persona_external_memory_refs_persona_provider").on(
616
+ table.organizationId,
617
+ table.personaId,
618
+ table.provider
619
+ ),
620
+ index("idx_persona_external_memory_refs_user_provider").on(
621
+ table.organizationId,
622
+ table.personaId,
623
+ table.userId,
624
+ table.provider
625
+ ),
626
+ index("idx_persona_external_memory_refs_external").on(
627
+ table.provider,
628
+ table.externalBankId,
629
+ table.externalMemoryId
630
+ ),
631
+ index("idx_persona_external_memory_refs_local").on(
632
+ table.localTargetKind,
633
+ table.localTargetId,
634
+ table.provider
635
+ ),
636
+ uniqueIndex("idx_persona_external_memory_refs_local_unique").on(
637
+ table.localTargetKind,
638
+ table.localTargetId,
639
+ table.provider
640
+ ),
641
+ check(
642
+ "persona_external_memory_refs_provider_check",
643
+ sql`${table.provider} in (${sql.raw(PERSONA_EXTERNAL_MEMORY_PROVIDERS_SQL)})`
644
+ ),
645
+ check(
646
+ "persona_external_memory_refs_state_check",
647
+ sql`${table.state} in (${sql.raw(PERSONA_EXTERNAL_MEMORY_REF_STATES_SQL)})`
648
+ ),
649
+ check(
650
+ "persona_external_memory_refs_local_target_kind_check",
651
+ sql`${table.localTargetKind} is null or ${table.localTargetKind} in (${sql.raw(PERSONA_EXTERNAL_MEMORY_LOCAL_TARGET_KINDS_SQL)})`
652
+ )
653
+ ]
654
+ );
655
+ var personaLifecycleEffects = pgTable(
656
+ "persona_lifecycle_effects",
657
+ {
658
+ attempt: integer("attempt").notNull().default(0),
659
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
660
+ effectType: text("effect_type").notNull().$type(),
661
+ id: text("id").primaryKey().$defaultFn(ulid),
662
+ idempotencyKey: text("idempotency_key").notNull(),
663
+ lastError: text("last_error"),
664
+ maxAttempts: integer("max_attempts").notNull().default(3),
665
+ nextRunAt: timestamp("next_run_at", { withTimezone: true }),
666
+ operationId: text("operation_id").notNull(),
667
+ organizationId: text("organization_id").notNull(),
668
+ payload: jsonb("payload").$type().notNull(),
669
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
670
+ status: text("status").notNull().$type().default("pending"),
671
+ targetId: text("target_id").notNull(),
672
+ targetKind: text("target_kind").notNull(),
673
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date()),
674
+ userId: text("user_id")
675
+ },
676
+ (table) => [
677
+ uniqueIndex("idx_persona_lifecycle_effects_operation").on(
678
+ table.operationId
679
+ ),
680
+ uniqueIndex("idx_persona_lifecycle_effects_idempotency").on(
681
+ table.idempotencyKey
682
+ ),
683
+ index("idx_persona_lifecycle_effects_status_due").on(
684
+ table.status,
685
+ table.nextRunAt
686
+ )
687
+ ]
688
+ );
689
+ var PERSONA_EMBEDDING_TARGET_KINDS = [
690
+ "episode",
691
+ "fact",
692
+ "belief",
693
+ "habit",
694
+ "style",
695
+ "source_chunk"
696
+ ];
697
+ var personaMemoryEmbeddings = pgTable(
698
+ "persona_memory_embeddings",
699
+ {
700
+ contentHash: text("content_hash").notNull(),
701
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
702
+ embedding: vector("embedding", {
703
+ dimensions: PERSONA_EMBEDDING_DIMENSION
704
+ }).notNull(),
705
+ id: text("id").primaryKey().$defaultFn(ulid),
706
+ organizationId: text("organization_id").notNull(),
707
+ personaId: text("persona_id").notNull().references(() => personaProfiles.id, { onDelete: "cascade" }),
708
+ targetId: text("target_id").notNull(),
709
+ targetKind: text("target_kind").notNull().$type(),
710
+ updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow().$onUpdate(() => /* @__PURE__ */ new Date())
711
+ },
712
+ (table) => [
713
+ uniqueIndex("idx_persona_memory_embeddings_target").on(
714
+ table.targetKind,
715
+ table.targetId
716
+ ),
717
+ index("idx_persona_memory_embeddings_persona").on(
718
+ table.organizationId,
719
+ table.personaId
720
+ )
721
+ ]
722
+ );
723
+ var personaAuditLogs = pgTable(
724
+ "persona_audit_logs",
725
+ {
726
+ action: text("action").notNull(),
727
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
728
+ id: text("id").primaryKey().$defaultFn(ulid),
729
+ metadata: jsonb("metadata").$type().notNull(),
730
+ organizationId: text("organization_id").notNull(),
731
+ personaId: text("persona_id").references(() => personaProfiles.id, {
732
+ onDelete: "set null"
733
+ }),
734
+ userId: text("user_id")
735
+ },
736
+ (table) => [
737
+ index("idx_persona_audit_logs_persona").on(
738
+ table.organizationId,
739
+ table.personaId
740
+ ),
741
+ index("idx_persona_audit_logs_created").on(table.createdAt)
742
+ ]
743
+ );
744
+
745
+ export {
746
+ ulid,
747
+ PERSONA_EMBEDDING_DIMENSION,
748
+ PERSONA_PROFILE_TYPES,
749
+ PERSONA_CONSENT_STATUSES,
750
+ PERSONA_PROFILE_STATES,
751
+ PERSONA_ALIAS_SURFACES,
752
+ PERSONA_ALIAS_STATES,
753
+ PERSONA_SOURCE_TYPES,
754
+ PERSONA_SOURCE_PRIORITIES,
755
+ PERSONA_RIGHTS_STATUSES,
756
+ PERSONA_PRIVACY_LEVELS,
757
+ PERSONA_MEMORY_STATES,
758
+ PERSONA_BELIEF_TYPES,
759
+ PERSONA_BELIEF_STANCES,
760
+ PERSONA_FACT_TYPES,
761
+ PERSONA_FACT_OBJECT_TYPES,
762
+ PERSONA_INTERACTION_MEMORY_STATES,
763
+ PERSONA_LIFECYCLE_EFFECT_TYPES,
764
+ PERSONA_LIFECYCLE_EFFECT_STATUSES,
765
+ PERSONA_EXTERNAL_MEMORY_PROVIDERS,
766
+ PERSONA_EXTERNAL_MEMORY_REF_STATES,
767
+ PERSONA_EXTERNAL_MEMORY_LOCAL_TARGET_KINDS,
768
+ PERSONA_SCOPES,
769
+ personaProfiles,
770
+ personaAliases,
771
+ personaSourceDocuments,
772
+ personaSourceChunks,
773
+ personaFacts,
774
+ personaEpisodeMemories,
775
+ personaEmotionalSalience,
776
+ personaMoodStates,
777
+ personaSemanticBeliefs,
778
+ personaHabitPatterns,
779
+ personaStyleProfiles,
780
+ personaWorkspaceStates,
781
+ personaInteractionMemories,
782
+ personaExternalMemoryRefs,
783
+ personaLifecycleEffects,
784
+ PERSONA_EMBEDDING_TARGET_KINDS,
785
+ personaMemoryEmbeddings,
786
+ personaAuditLogs
787
+ };
788
+ //# sourceMappingURL=chunk-2MUEPA24.js.map