@segmentstream/ontology 0.147.0 → 0.149.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +24 -15
  3. package/dist/analyze.d.ts +11 -3
  4. package/dist/analyze.js +21 -4
  5. package/dist/connection.d.ts +20 -3
  6. package/dist/connection.js +36 -8
  7. package/dist/diagnostics.d.ts +3 -3
  8. package/dist/diagnostics.js +1 -0
  9. package/dist/files.d.ts +21 -0
  10. package/dist/index.d.ts +3 -3
  11. package/dist/index.js +2 -2
  12. package/dist/internal/diagnostics.js +3 -0
  13. package/dist/manifest.d.ts +125 -77
  14. package/dist/manifest.js +34 -2
  15. package/dist/migrate/model.d.ts +68 -56
  16. package/dist/migrate/plan.js +1 -1
  17. package/dist/migrate/preview.js +4 -1
  18. package/dist/migrate/storage.d.ts +15 -3
  19. package/dist/migrate/storage.js +86 -3
  20. package/dist/runtime/agents.js +2 -0
  21. package/dist/runtime/chat-messages.d.ts +233 -0
  22. package/dist/runtime/chat-messages.js +523 -0
  23. package/dist/runtime/pipeline.js +1 -0
  24. package/dist/service/agent/archive-routes.d.ts +2 -0
  25. package/dist/service/agent/archive-routes.js +2 -1
  26. package/dist/service/agent/chat-archive.d.ts +12 -3
  27. package/dist/service/agent/chat-archive.js +5 -1
  28. package/dist/service/agent/chat-message-routes.d.ts +124 -0
  29. package/dist/service/agent/chat-message-routes.js +235 -0
  30. package/dist/service/agent/server.d.ts +5 -1
  31. package/dist/service/agent/server.js +15 -0
  32. package/dist/service/chat/local-reads.d.ts +71 -0
  33. package/dist/service/chat/local-reads.js +148 -0
  34. package/dist/service/chat/reads.js +7 -0
  35. package/dist/service/chat/routes.js +4 -1
  36. package/dist/service/chat/schemas.d.ts +5 -0
  37. package/dist/service/chat/schemas.js +5 -0
  38. package/dist/service/connection-stream.d.ts +7 -0
  39. package/dist/service/connection-stream.js +9 -1
  40. package/dist/service/connections.js +56 -5
  41. package/dist/service/cron-secret.d.ts +6 -0
  42. package/dist/service/cron-secret.js +14 -0
  43. package/dist/service/discovery-search.d.ts +1 -1
  44. package/dist/service/mcp/server.js +4 -2
  45. package/dist/service/runtime-contract.d.ts +2 -0
  46. package/dist/service/schemas.d.ts +8 -2
  47. package/dist/service/service.js +4 -1
  48. package/dist/service/workflows.js +6 -12
  49. package/dist/storage/sessions.js +26 -0
  50. package/package.json +1 -1
package/dist/manifest.js CHANGED
@@ -101,8 +101,13 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
101
101
  * older publication check refuses the scheme. A signature may carry `generated: true` instead of
102
102
  * `secret`: the platform derives the webhook's secret. Older readers find no secret name; an older
103
103
  * publication check refuses it.
104
+ * Version 16 changes no other field: it marks an SDK whose service keeps the chats' messages in
105
+ * the workspace's own database and purges them at `/api/ontology/agent/chats/purge`, so
106
+ * publication adds a daily cron for that route. Within version 16, `chat` may carry
107
+ * `retention_days`, written only when declared, and then also without a channel: how many days
108
+ * the workspace keeps its chats' messages. Older readers ignore it and keep them 365 days.
104
109
  */
105
- export const MANIFEST_VERSION = 15;
110
+ export const MANIFEST_VERSION = 16;
106
111
  /** The first version whose documents use snake_case names on the wire. */
107
112
  const WIRE_MANIFEST_VERSION = 4;
108
113
  /** The first version whose documents name metrics as this SDK does; earlier ones keep theirs. */
@@ -611,7 +616,9 @@ const OntologyManifestModel = Schema.Struct({
611
616
  template: Schema.optionalKey(Schema.String),
612
617
  separator: Schema.optionalKey(Schema.String),
613
618
  })),
614
- })),
619
+ /** How many days the workspace keeps its chats' messages; absent keeps them 365. */
620
+ retentionDays: Schema.optionalKey(Schema.Int),
621
+ }).pipe(Schema.encodeKeys({ retentionDays: "retention_days" }))),
615
622
  /**
616
623
  * Whose private chats join the inbox, within version 15: the wire names of their roles, the
617
624
  * channels whose chats staff may take over from the agent, and `attribution: "none"` when a
@@ -719,6 +726,31 @@ export function signUpRolesOf(manifest, channel) {
719
726
  ? roles
720
727
  : undefined;
721
728
  }
729
+ /**
730
+ * `chat.retentionDays` of `defineOntology`: how many days the workspace keeps its chats' messages,
731
+ * a whole number in this range; 365 when the ontology declares none.
732
+ */
733
+ export const CHAT_RETENTION_DAYS = { default: 365, minimum: 1, maximum: 3650 };
734
+ /**
735
+ * The days the ontology declares it keeps its chats' messages, as {@link chatRetentionDaysOf}
736
+ * reads them; `undefined` when it declares none.
737
+ */
738
+ export function declaredChatRetentionDaysOf(manifest) {
739
+ return manifest.chat?.retentionDays === undefined ? undefined : chatRetentionDaysOf(manifest);
740
+ }
741
+ /**
742
+ * How many days the workspace keeps its chats' messages: `chat.retentionDays` where it is a whole
743
+ * number in range, else the default.
744
+ */
745
+ export function chatRetentionDaysOf(manifest) {
746
+ const days = manifest.chat?.retentionDays;
747
+ return typeof days === "number" &&
748
+ Number.isInteger(days) &&
749
+ days >= CHAT_RETENTION_DAYS.minimum &&
750
+ days <= CHAT_RETENTION_DAYS.maximum
751
+ ? days
752
+ : CHAT_RETENTION_DAYS.default;
753
+ }
722
754
  /** The wire names of the roles whose people's private chats join the inbox; empty without one. */
723
755
  export function inboxRolesOf(manifest) {
724
756
  return new Set(manifest.inbox?.roles ?? []);
@@ -292,8 +292,8 @@ export declare const MigrationPlan: Schema.Struct<{
292
292
  readonly target: Schema.declareConstructor<{
293
293
  readonly version: number;
294
294
  readonly roles: readonly {
295
- readonly name: string;
296
295
  readonly description: string;
296
+ readonly name: string;
297
297
  readonly builtIn: boolean;
298
298
  readonly scopes?: readonly {
299
299
  readonly permission: string;
@@ -306,8 +306,8 @@ export declare const MigrationPlan: Schema.Struct<{
306
306
  readonly hash: string;
307
307
  readonly entities: readonly {
308
308
  readonly id: string;
309
- readonly name: string;
310
309
  readonly description: string;
310
+ readonly name: string;
311
311
  readonly label: string;
312
312
  readonly properties: readonly {
313
313
  readonly optional: boolean;
@@ -336,8 +336,8 @@ export declare const MigrationPlan: Schema.Struct<{
336
336
  readonly items?: "number" | "boolean" | "email" | "text" | "url" | "date" | "timestamp" | "select" | "integer" | "json" | "blob" | "list" | undefined;
337
337
  }[];
338
338
  readonly relationships: readonly {
339
- readonly name: string;
340
339
  readonly description: string;
340
+ readonly name: string;
341
341
  readonly to: string;
342
342
  readonly cardinality: "one" | "many";
343
343
  readonly phrase: readonly [string, string];
@@ -355,8 +355,8 @@ export declare const MigrationPlan: Schema.Struct<{
355
355
  readonly unique: boolean;
356
356
  }[];
357
357
  readonly actions: readonly {
358
- readonly name: string;
359
358
  readonly description: string;
359
+ readonly name: string;
360
360
  readonly input: {
361
361
  readonly [x: string]: Schema.Json;
362
362
  };
@@ -385,8 +385,8 @@ export declare const MigrationPlan: Schema.Struct<{
385
385
  readonly currency?: string | undefined;
386
386
  } | undefined;
387
387
  readonly metrics?: readonly {
388
- readonly name: string;
389
388
  readonly description: string;
389
+ readonly name: string;
390
390
  readonly label: string;
391
391
  readonly unit: "number" | "currency" | "ratio" | "percent";
392
392
  readonly format: "decimal" | "currency" | "percent";
@@ -428,10 +428,11 @@ export declare const MigrationPlan: Schema.Struct<{
428
428
  readonly template?: string | undefined;
429
429
  readonly separator?: string | undefined;
430
430
  } | undefined;
431
+ readonly retentionDays?: number | undefined;
431
432
  } | undefined;
432
433
  readonly workflows?: readonly {
433
- readonly name: string;
434
434
  readonly description: string;
435
+ readonly name: string;
435
436
  readonly input: {
436
437
  readonly [x: string]: Schema.Json;
437
438
  };
@@ -446,13 +447,13 @@ export declare const MigrationPlan: Schema.Struct<{
446
447
  } | {
447
448
  readonly kind: "action";
448
449
  readonly entity: string;
449
- readonly name: string;
450
450
  readonly description: string;
451
+ readonly name: string;
451
452
  readonly action?: string | undefined;
452
453
  } | {
453
454
  readonly kind: "webhook";
454
- readonly name: string;
455
455
  readonly description: string;
456
+ readonly name: string;
456
457
  readonly connection?: string | undefined;
457
458
  readonly headers?: readonly string[] | undefined;
458
459
  readonly signature?: {
@@ -622,8 +623,8 @@ export declare const MigrationPlan: Schema.Struct<{
622
623
  };
623
624
  }[];
624
625
  readonly actions: readonly {
625
- readonly name: string;
626
626
  readonly description: string;
627
+ readonly name: string;
627
628
  readonly input: {
628
629
  readonly [x: string]: Schema.Json;
629
630
  };
@@ -647,8 +648,8 @@ export declare const MigrationPlan: Schema.Struct<{
647
648
  } | {
648
649
  readonly version: number;
649
650
  readonly roles: readonly {
650
- readonly name: string;
651
651
  readonly description: string;
652
+ readonly name: string;
652
653
  readonly builtIn: boolean;
653
654
  readonly scopes?: readonly {
654
655
  readonly permission: string;
@@ -661,8 +662,8 @@ export declare const MigrationPlan: Schema.Struct<{
661
662
  readonly hash: string;
662
663
  readonly entities: readonly {
663
664
  readonly id: string;
664
- readonly name: string;
665
665
  readonly description: string;
666
+ readonly name: string;
666
667
  readonly label: string;
667
668
  readonly properties: readonly {
668
669
  readonly optional: boolean;
@@ -691,8 +692,8 @@ export declare const MigrationPlan: Schema.Struct<{
691
692
  readonly items?: "number" | "boolean" | "email" | "text" | "url" | "date" | "timestamp" | "select" | "integer" | "json" | "blob" | "list" | undefined;
692
693
  }[];
693
694
  readonly relationships: readonly {
694
- readonly name: string;
695
695
  readonly description: string;
696
+ readonly name: string;
696
697
  readonly to: string;
697
698
  readonly cardinality: "one" | "many";
698
699
  readonly phrase: readonly [string, string];
@@ -710,8 +711,8 @@ export declare const MigrationPlan: Schema.Struct<{
710
711
  readonly unique: boolean;
711
712
  }[];
712
713
  readonly actions: readonly {
713
- readonly name: string;
714
714
  readonly description: string;
715
+ readonly name: string;
715
716
  readonly input: {
716
717
  readonly [x: string]: Schema.Json;
717
718
  };
@@ -740,8 +741,8 @@ export declare const MigrationPlan: Schema.Struct<{
740
741
  readonly currency?: string | undefined;
741
742
  } | undefined;
742
743
  readonly metrics?: readonly {
743
- readonly name: string;
744
744
  readonly description: string;
745
+ readonly name: string;
745
746
  readonly label: string;
746
747
  readonly unit: "number" | "currency" | "ratio" | "percent";
747
748
  readonly format: "decimal" | "currency" | "percent";
@@ -783,10 +784,11 @@ export declare const MigrationPlan: Schema.Struct<{
783
784
  readonly template?: string | undefined;
784
785
  readonly separator?: string | undefined;
785
786
  } | undefined;
787
+ readonly retentionDays?: number | undefined;
786
788
  } | undefined;
787
789
  readonly workflows?: readonly {
788
- readonly name: string;
789
790
  readonly description: string;
791
+ readonly name: string;
790
792
  readonly input: {
791
793
  readonly [x: string]: Schema.Json;
792
794
  };
@@ -801,13 +803,13 @@ export declare const MigrationPlan: Schema.Struct<{
801
803
  } | {
802
804
  readonly kind: "action";
803
805
  readonly entity: string;
804
- readonly name: string;
805
806
  readonly description: string;
807
+ readonly name: string;
806
808
  readonly action?: string | undefined;
807
809
  } | {
808
810
  readonly kind: "webhook";
809
- readonly name: string;
810
811
  readonly description: string;
812
+ readonly name: string;
811
813
  readonly connection?: string | undefined;
812
814
  readonly headers?: readonly string[] | undefined;
813
815
  readonly signature?: {
@@ -977,8 +979,8 @@ export declare const MigrationPlan: Schema.Struct<{
977
979
  };
978
980
  }[];
979
981
  readonly actions: readonly {
980
- readonly name: string;
981
982
  readonly description: string;
983
+ readonly name: string;
982
984
  readonly input: {
983
985
  readonly [x: string]: Schema.Json;
984
986
  };
@@ -1002,8 +1004,8 @@ export declare const MigrationPlan: Schema.Struct<{
1002
1004
  }, {
1003
1005
  readonly version: number;
1004
1006
  readonly roles: readonly {
1005
- readonly name: string;
1006
1007
  readonly description: string;
1008
+ readonly name: string;
1007
1009
  readonly built_in: boolean;
1008
1010
  readonly scopes?: readonly {
1009
1011
  readonly permission: string;
@@ -1016,8 +1018,8 @@ export declare const MigrationPlan: Schema.Struct<{
1016
1018
  readonly hash: string;
1017
1019
  readonly entities: readonly {
1018
1020
  readonly id: string;
1019
- readonly name: string;
1020
1021
  readonly description: string;
1022
+ readonly name: string;
1021
1023
  readonly label: string;
1022
1024
  readonly properties: readonly {
1023
1025
  readonly optional: boolean;
@@ -1046,8 +1048,8 @@ export declare const MigrationPlan: Schema.Struct<{
1046
1048
  readonly exclude_from_replication?: boolean | undefined;
1047
1049
  }[];
1048
1050
  readonly relationships: readonly {
1049
- readonly name: string;
1050
1051
  readonly description: string;
1052
+ readonly name: string;
1051
1053
  readonly to: string;
1052
1054
  readonly cardinality: "one" | "many";
1053
1055
  readonly phrase: readonly [string, string];
@@ -1065,8 +1067,8 @@ export declare const MigrationPlan: Schema.Struct<{
1065
1067
  readonly unique: boolean;
1066
1068
  }[];
1067
1069
  readonly actions: readonly {
1068
- readonly name: string;
1069
1070
  readonly description: string;
1071
+ readonly name: string;
1070
1072
  readonly input: {
1071
1073
  readonly [x: string]: Schema.Json;
1072
1074
  };
@@ -1095,8 +1097,8 @@ export declare const MigrationPlan: Schema.Struct<{
1095
1097
  readonly currency?: string | undefined;
1096
1098
  } | undefined;
1097
1099
  readonly metrics?: readonly {
1098
- readonly name: string;
1099
1100
  readonly description: string;
1101
+ readonly name: string;
1100
1102
  readonly label: string;
1101
1103
  readonly unit: "number" | "currency" | "ratio" | "percent";
1102
1104
  readonly format: "decimal" | "currency" | "percent";
@@ -1138,10 +1140,11 @@ export declare const MigrationPlan: Schema.Struct<{
1138
1140
  readonly template?: string | undefined;
1139
1141
  readonly separator?: string | undefined;
1140
1142
  } | undefined;
1143
+ readonly retention_days?: number | undefined;
1141
1144
  } | undefined;
1142
1145
  readonly workflows?: readonly {
1143
- readonly name: string;
1144
1146
  readonly description: string;
1147
+ readonly name: string;
1145
1148
  readonly input: {
1146
1149
  readonly [x: string]: Schema.Json;
1147
1150
  };
@@ -1158,13 +1161,13 @@ export declare const MigrationPlan: Schema.Struct<{
1158
1161
  } | {
1159
1162
  readonly kind: "action";
1160
1163
  readonly entity: string;
1161
- readonly name: string;
1162
1164
  readonly description: string;
1165
+ readonly name: string;
1163
1166
  readonly action?: string | undefined;
1164
1167
  } | {
1165
1168
  readonly kind: "webhook";
1166
- readonly name: string;
1167
1169
  readonly description: string;
1170
+ readonly name: string;
1168
1171
  readonly connection?: string | undefined;
1169
1172
  readonly headers?: readonly string[] | undefined;
1170
1173
  readonly signature?: {
@@ -1295,8 +1298,8 @@ export declare const MigrationPlan: Schema.Struct<{
1295
1298
  };
1296
1299
  }[];
1297
1300
  readonly actions: readonly {
1298
- readonly name: string;
1299
1301
  readonly description: string;
1302
+ readonly name: string;
1300
1303
  readonly input: {
1301
1304
  readonly [x: string]: Schema.Json;
1302
1305
  };
@@ -1357,8 +1360,8 @@ export declare const MigrationPlan: Schema.Struct<{
1357
1360
  } | {
1358
1361
  readonly version: number;
1359
1362
  readonly roles: readonly {
1360
- readonly name: string;
1361
1363
  readonly description: string;
1364
+ readonly name: string;
1362
1365
  readonly builtIn: boolean;
1363
1366
  readonly scopes?: readonly {
1364
1367
  readonly permission: string;
@@ -1371,8 +1374,8 @@ export declare const MigrationPlan: Schema.Struct<{
1371
1374
  readonly hash: string;
1372
1375
  readonly entities: readonly {
1373
1376
  readonly id: string;
1374
- readonly name: string;
1375
1377
  readonly description: string;
1378
+ readonly name: string;
1376
1379
  readonly label: string;
1377
1380
  readonly properties: readonly {
1378
1381
  readonly optional: boolean;
@@ -1401,8 +1404,8 @@ export declare const MigrationPlan: Schema.Struct<{
1401
1404
  readonly items?: "number" | "boolean" | "email" | "text" | "url" | "date" | "timestamp" | "select" | "integer" | "json" | "blob" | "list" | undefined;
1402
1405
  }[];
1403
1406
  readonly relationships: readonly {
1404
- readonly name: string;
1405
1407
  readonly description: string;
1408
+ readonly name: string;
1406
1409
  readonly to: string;
1407
1410
  readonly cardinality: "one" | "many";
1408
1411
  readonly phrase: readonly [string, string];
@@ -1420,8 +1423,8 @@ export declare const MigrationPlan: Schema.Struct<{
1420
1423
  readonly unique: boolean;
1421
1424
  }[];
1422
1425
  readonly actions: readonly {
1423
- readonly name: string;
1424
1426
  readonly description: string;
1427
+ readonly name: string;
1425
1428
  readonly input: {
1426
1429
  readonly [x: string]: Schema.Json;
1427
1430
  };
@@ -1450,8 +1453,8 @@ export declare const MigrationPlan: Schema.Struct<{
1450
1453
  readonly currency?: string | undefined;
1451
1454
  } | undefined;
1452
1455
  readonly metrics?: readonly {
1453
- readonly name: string;
1454
1456
  readonly description: string;
1457
+ readonly name: string;
1455
1458
  readonly label: string;
1456
1459
  readonly unit: "number" | "currency" | "ratio" | "percent";
1457
1460
  readonly format: "decimal" | "currency" | "percent";
@@ -1493,10 +1496,11 @@ export declare const MigrationPlan: Schema.Struct<{
1493
1496
  readonly template?: string | undefined;
1494
1497
  readonly separator?: string | undefined;
1495
1498
  } | undefined;
1499
+ readonly retention_days?: number | undefined;
1496
1500
  } | undefined;
1497
1501
  readonly workflows?: readonly {
1498
- readonly name: string;
1499
1502
  readonly description: string;
1503
+ readonly name: string;
1500
1504
  readonly input: {
1501
1505
  readonly [x: string]: Schema.Json;
1502
1506
  };
@@ -1513,13 +1517,13 @@ export declare const MigrationPlan: Schema.Struct<{
1513
1517
  } | {
1514
1518
  readonly kind: "action";
1515
1519
  readonly entity: string;
1516
- readonly name: string;
1517
1520
  readonly description: string;
1521
+ readonly name: string;
1518
1522
  readonly action?: string | undefined;
1519
1523
  } | {
1520
1524
  readonly kind: "webhook";
1521
- readonly name: string;
1522
1525
  readonly description: string;
1526
+ readonly name: string;
1523
1527
  readonly connection?: string | undefined;
1524
1528
  readonly headers?: readonly string[] | undefined;
1525
1529
  readonly signature?: {
@@ -1687,8 +1691,8 @@ export declare const MigrationPlan: Schema.Struct<{
1687
1691
  };
1688
1692
  }[];
1689
1693
  readonly actions: readonly {
1690
- readonly name: string;
1691
1694
  readonly description: string;
1695
+ readonly name: string;
1692
1696
  readonly input: {
1693
1697
  readonly [x: string]: Schema.Json;
1694
1698
  };
@@ -1935,7 +1939,7 @@ export declare const MigrationPlan: Schema.Struct<{
1935
1939
  readonly description: Schema.String;
1936
1940
  readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
1937
1941
  }>>>;
1938
- readonly chat: Schema.optionalKey<Schema.Struct<{
1942
+ readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
1939
1943
  readonly telegram: Schema.optionalKey<Schema.Struct<{
1940
1944
  readonly connection: Schema.String;
1941
1945
  }>>;
@@ -1956,6 +1960,9 @@ export declare const MigrationPlan: Schema.Struct<{
1956
1960
  readonly template: Schema.optionalKey<Schema.String>;
1957
1961
  readonly separator: Schema.optionalKey<Schema.String>;
1958
1962
  }>>;
1963
+ readonly retentionDays: Schema.optionalKey<Schema.Int>;
1964
+ }>, {
1965
+ readonly retentionDays: "retention_days";
1959
1966
  }>>;
1960
1967
  readonly inbox: Schema.optionalKey<Schema.Struct<{
1961
1968
  readonly roles: Schema.$Array<Schema.String>;
@@ -2286,7 +2293,7 @@ export declare const MigrationPlan: Schema.Struct<{
2286
2293
  readonly description: Schema.String;
2287
2294
  readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
2288
2295
  }>>>;
2289
- readonly chat: Schema.optionalKey<Schema.Struct<{
2296
+ readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
2290
2297
  readonly telegram: Schema.optionalKey<Schema.Struct<{
2291
2298
  readonly connection: Schema.String;
2292
2299
  }>>;
@@ -2307,6 +2314,9 @@ export declare const MigrationPlan: Schema.Struct<{
2307
2314
  readonly template: Schema.optionalKey<Schema.String>;
2308
2315
  readonly separator: Schema.optionalKey<Schema.String>;
2309
2316
  }>>;
2317
+ readonly retentionDays: Schema.optionalKey<Schema.Int>;
2318
+ }>, {
2319
+ readonly retentionDays: "retention_days";
2310
2320
  }>>;
2311
2321
  readonly inbox: Schema.optionalKey<Schema.Struct<{
2312
2322
  readonly roles: Schema.$Array<Schema.String>;
@@ -2428,8 +2438,8 @@ export declare const MigrationPlan: Schema.Struct<{
2428
2438
  }>]>], {
2429
2439
  readonly version: number;
2430
2440
  readonly roles: readonly {
2431
- readonly name: string;
2432
2441
  readonly description: string;
2442
+ readonly name: string;
2433
2443
  readonly builtIn: boolean;
2434
2444
  readonly scopes?: readonly {
2435
2445
  readonly permission: string;
@@ -2442,8 +2452,8 @@ export declare const MigrationPlan: Schema.Struct<{
2442
2452
  readonly hash: string;
2443
2453
  readonly entities: readonly {
2444
2454
  readonly id: string;
2445
- readonly name: string;
2446
2455
  readonly description: string;
2456
+ readonly name: string;
2447
2457
  readonly label: string;
2448
2458
  readonly properties: readonly {
2449
2459
  readonly optional: boolean;
@@ -2472,8 +2482,8 @@ export declare const MigrationPlan: Schema.Struct<{
2472
2482
  readonly items?: "number" | "boolean" | "email" | "text" | "url" | "date" | "timestamp" | "select" | "integer" | "json" | "blob" | "list" | undefined;
2473
2483
  }[];
2474
2484
  readonly relationships: readonly {
2475
- readonly name: string;
2476
2485
  readonly description: string;
2486
+ readonly name: string;
2477
2487
  readonly to: string;
2478
2488
  readonly cardinality: "one" | "many";
2479
2489
  readonly phrase: readonly [string, string];
@@ -2491,8 +2501,8 @@ export declare const MigrationPlan: Schema.Struct<{
2491
2501
  readonly unique: boolean;
2492
2502
  }[];
2493
2503
  readonly actions: readonly {
2494
- readonly name: string;
2495
2504
  readonly description: string;
2505
+ readonly name: string;
2496
2506
  readonly input: {
2497
2507
  readonly [x: string]: Schema.Json;
2498
2508
  };
@@ -2521,8 +2531,8 @@ export declare const MigrationPlan: Schema.Struct<{
2521
2531
  readonly currency?: string | undefined;
2522
2532
  } | undefined;
2523
2533
  readonly metrics?: readonly {
2524
- readonly name: string;
2525
2534
  readonly description: string;
2535
+ readonly name: string;
2526
2536
  readonly label: string;
2527
2537
  readonly unit: "number" | "currency" | "ratio" | "percent";
2528
2538
  readonly format: "decimal" | "currency" | "percent";
@@ -2564,10 +2574,11 @@ export declare const MigrationPlan: Schema.Struct<{
2564
2574
  readonly template?: string | undefined;
2565
2575
  readonly separator?: string | undefined;
2566
2576
  } | undefined;
2577
+ readonly retentionDays?: number | undefined;
2567
2578
  } | undefined;
2568
2579
  readonly workflows?: readonly {
2569
- readonly name: string;
2570
2580
  readonly description: string;
2581
+ readonly name: string;
2571
2582
  readonly input: {
2572
2583
  readonly [x: string]: Schema.Json;
2573
2584
  };
@@ -2582,13 +2593,13 @@ export declare const MigrationPlan: Schema.Struct<{
2582
2593
  } | {
2583
2594
  readonly kind: "action";
2584
2595
  readonly entity: string;
2585
- readonly name: string;
2586
2596
  readonly description: string;
2597
+ readonly name: string;
2587
2598
  readonly action?: string | undefined;
2588
2599
  } | {
2589
2600
  readonly kind: "webhook";
2590
- readonly name: string;
2591
2601
  readonly description: string;
2602
+ readonly name: string;
2592
2603
  readonly connection?: string | undefined;
2593
2604
  readonly headers?: readonly string[] | undefined;
2594
2605
  readonly signature?: {
@@ -2758,8 +2769,8 @@ export declare const MigrationPlan: Schema.Struct<{
2758
2769
  };
2759
2770
  }[];
2760
2771
  readonly actions: readonly {
2761
- readonly name: string;
2762
2772
  readonly description: string;
2773
+ readonly name: string;
2763
2774
  readonly input: {
2764
2775
  readonly [x: string]: Schema.Json;
2765
2776
  };
@@ -2783,8 +2794,8 @@ export declare const MigrationPlan: Schema.Struct<{
2783
2794
  } | {
2784
2795
  readonly version: number;
2785
2796
  readonly roles: readonly {
2786
- readonly name: string;
2787
2797
  readonly description: string;
2798
+ readonly name: string;
2788
2799
  readonly builtIn: boolean;
2789
2800
  readonly scopes?: readonly {
2790
2801
  readonly permission: string;
@@ -2797,8 +2808,8 @@ export declare const MigrationPlan: Schema.Struct<{
2797
2808
  readonly hash: string;
2798
2809
  readonly entities: readonly {
2799
2810
  readonly id: string;
2800
- readonly name: string;
2801
2811
  readonly description: string;
2812
+ readonly name: string;
2802
2813
  readonly label: string;
2803
2814
  readonly properties: readonly {
2804
2815
  readonly optional: boolean;
@@ -2827,8 +2838,8 @@ export declare const MigrationPlan: Schema.Struct<{
2827
2838
  readonly items?: "number" | "boolean" | "email" | "text" | "url" | "date" | "timestamp" | "select" | "integer" | "json" | "blob" | "list" | undefined;
2828
2839
  }[];
2829
2840
  readonly relationships: readonly {
2830
- readonly name: string;
2831
2841
  readonly description: string;
2842
+ readonly name: string;
2832
2843
  readonly to: string;
2833
2844
  readonly cardinality: "one" | "many";
2834
2845
  readonly phrase: readonly [string, string];
@@ -2846,8 +2857,8 @@ export declare const MigrationPlan: Schema.Struct<{
2846
2857
  readonly unique: boolean;
2847
2858
  }[];
2848
2859
  readonly actions: readonly {
2849
- readonly name: string;
2850
2860
  readonly description: string;
2861
+ readonly name: string;
2851
2862
  readonly input: {
2852
2863
  readonly [x: string]: Schema.Json;
2853
2864
  };
@@ -2876,8 +2887,8 @@ export declare const MigrationPlan: Schema.Struct<{
2876
2887
  readonly currency?: string | undefined;
2877
2888
  } | undefined;
2878
2889
  readonly metrics?: readonly {
2879
- readonly name: string;
2880
2890
  readonly description: string;
2891
+ readonly name: string;
2881
2892
  readonly label: string;
2882
2893
  readonly unit: "number" | "currency" | "ratio" | "percent";
2883
2894
  readonly format: "decimal" | "currency" | "percent";
@@ -2919,10 +2930,11 @@ export declare const MigrationPlan: Schema.Struct<{
2919
2930
  readonly template?: string | undefined;
2920
2931
  readonly separator?: string | undefined;
2921
2932
  } | undefined;
2933
+ readonly retentionDays?: number | undefined;
2922
2934
  } | undefined;
2923
2935
  readonly workflows?: readonly {
2924
- readonly name: string;
2925
2936
  readonly description: string;
2937
+ readonly name: string;
2926
2938
  readonly input: {
2927
2939
  readonly [x: string]: Schema.Json;
2928
2940
  };
@@ -2937,13 +2949,13 @@ export declare const MigrationPlan: Schema.Struct<{
2937
2949
  } | {
2938
2950
  readonly kind: "action";
2939
2951
  readonly entity: string;
2940
- readonly name: string;
2941
2952
  readonly description: string;
2953
+ readonly name: string;
2942
2954
  readonly action?: string | undefined;
2943
2955
  } | {
2944
2956
  readonly kind: "webhook";
2945
- readonly name: string;
2946
2957
  readonly description: string;
2958
+ readonly name: string;
2947
2959
  readonly connection?: string | undefined;
2948
2960
  readonly headers?: readonly string[] | undefined;
2949
2961
  readonly signature?: {
@@ -3113,8 +3125,8 @@ export declare const MigrationPlan: Schema.Struct<{
3113
3125
  };
3114
3126
  }[];
3115
3127
  readonly actions: readonly {
3116
- readonly name: string;
3117
3128
  readonly description: string;
3129
+ readonly name: string;
3118
3130
  readonly input: {
3119
3131
  readonly [x: string]: Schema.Json;
3120
3132
  };
@@ -213,7 +213,7 @@ export function planMigration(input) {
213
213
  draft.runtimeTables.push(step({
214
214
  kind: "createCatalog",
215
215
  classification: "additive",
216
- description: "Create the runtime's agent tables, which pair channel accounts with members.",
216
+ description: "Create the runtime's agent tables, which pair channel accounts with members and keep chats' messages.",
217
217
  sql: AGENT_TABLES_DDL,
218
218
  }));
219
219
  }
@@ -2,7 +2,7 @@ import { Effect } from "effect";
2
2
  import { AGENT_TASKS_TABLE, ATTACHMENTS_TABLE, SIGN_IN_EMAILS_TABLE, WORKFLOW_STARTS_TABLE, } from "../storage/tables.js";
3
3
  import { CONFIRMATION_TABLE } from "../runtime/confirmations.js";
4
4
  import { CHANNEL_ORIGIN_SQL, USER_IDENTITY_TABLE } from "../runtime/user-identity-sql.js";
5
- import { AGENT_COUNTERS_TABLE, AGENT_GUEST_LINKS_TABLE, AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, API_KEYS_TABLE, IDENTITY_NOTICES_TABLE, OAUTH_TABLES, quoteIdentifier, } from "./storage.js";
5
+ import { AGENT_COUNTERS_TABLE, AGENT_GUEST_LINKS_TABLE, AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, API_KEYS_TABLE, CHAT_MESSAGES_TABLE, IDENTITY_NOTICES_TABLE, OAUTH_TABLES, quoteIdentifier, } from "./storage.js";
6
6
  /**
7
7
  * Invalidate copied SDK credentials and runnable state on a verified, unexposed child database.
8
8
  * The caller owns branch verification and provider-side Neon Auth invalidation/configuration.
@@ -32,6 +32,9 @@ export function preparePreviewDatabase({ sql, }) {
32
32
  IDENTITY_NOTICES_TABLE,
33
33
  AGENT_PAIRINGS_TABLE,
34
34
  AGENT_GUEST_LINKS_TABLE,
35
+ // A preview is a child branch of production: production's chats, people's messages
36
+ // among them, must not reach it, nor a preview's agent read them as its own.
37
+ CHAT_MESSAGES_TABLE,
35
38
  AGENT_TASKS_TABLE,
36
39
  SIGN_IN_EMAILS_TABLE,
37
40
  WORKFLOW_STARTS_TABLE,
@@ -205,13 +205,25 @@ export declare const CHANNEL_LIMITS_TABLE = "_channel_limits";
205
205
  * other user, nor a queued sign-in email, which needs an existing user, holds these.
206
206
  */
207
207
  export declare const AGENT_GUEST_LINKS_TABLE = "_agent_guest_links";
208
+ /**
209
+ * The chats' messages, one row per message: what people and staff saw, with what the agent did
210
+ * with each inbound message (`disposition`) and the latest delivery state of each outbound one.
211
+ * A system table beside `agent_chat`, which stays the chat's record: no entity, history,
212
+ * replication or generated tools. See docs/agent-chat-storage.md.
213
+ */
214
+ export declare const CHAT_MESSAGES_TABLE = "_chat_messages";
215
+ /**
216
+ * Where a chat message's `revision` comes from: set on insert and on every change readers see, so
217
+ * that "what changed since my bookmark" is one indexed range of a chat.
218
+ */
219
+ export declare const CHAT_MESSAGE_REVISIONS = "_chat_messages_revision";
208
220
  /** The agent's tables, in the order they are created. */
209
221
  export declare const AGENT_TABLES: ReadonlyArray<string>;
210
222
  /**
211
223
  * The tables of the app's agent: pairing codes, stored only as SHA-256 hashes, the legacy channel
212
- * identities they create, and the first-contact notices of `user_identity` channel accounts. An
213
- * account and a member each have at most one live identity per provider. Every statement is
214
- * idempotent.
224
+ * identities they create, the first-contact notices of `user_identity` channel accounts, and the
225
+ * chats' messages. An account and a member each have at most one live identity per provider.
226
+ * Every statement is idempotent.
215
227
  */
216
228
  export declare const AGENT_TABLES_DDL: ReadonlyArray<string>;
217
229
  /**