@segmentstream/ontology 0.151.0 → 0.153.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.
- package/CHANGELOG.md +39 -0
- package/README.md +2 -2
- package/dist/agent-chat.d.ts +6 -1
- package/dist/agent-chat.js +9 -6
- package/dist/analyze.d.ts +14 -0
- package/dist/analyze.js +31 -11
- package/dist/chat.d.ts +17 -3
- package/dist/chat.js +17 -1
- package/dist/files.d.ts +7 -0
- package/dist/files.js +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/manifest.d.ts +243 -51
- package/dist/manifest.js +27 -5
- package/dist/migrate/model.d.ts +156 -36
- package/dist/runtime/chat-messages.d.ts +7 -2
- package/dist/runtime/chat-messages.js +41 -14
- package/dist/service/chat/delivery.js +3 -1
- package/dist/service/chat/history-import.d.ts +19 -5
- package/dist/service/chat/history-import.js +183 -8
- package/dist/service/schemas.d.ts +30 -0
- package/dist/storage/attachments.d.ts +40 -9
- package/dist/storage/attachments.js +185 -21
- package/dist/storage/sessions.js +16 -8
- package/dist/storage/tables.d.ts +2 -1
- package/dist/storage/tables.js +2 -1
- package/package.json +1 -1
package/dist/manifest.js
CHANGED
|
@@ -569,6 +569,13 @@ export const EmailDocumentManifest = Schema.Struct({
|
|
|
569
569
|
}).pipe(Schema.encodeKeys({ replyTo: "reply_to" }));
|
|
570
570
|
/** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
|
|
571
571
|
export const EmailTemplateManifest = Schema.Union([EmailDocumentManifest, EmailLayoutManifest]);
|
|
572
|
+
/** What a chat channel keeps of its chats' files: `keep`, for as long as their messages. */
|
|
573
|
+
const ChatFilesManifest = Schema.Struct({ keep: Schema.Boolean });
|
|
574
|
+
/** A chat channel named after its kind: the connection posts go through, and what it keeps. */
|
|
575
|
+
const ChatChannelManifest = Schema.Struct({
|
|
576
|
+
connection: Schema.String,
|
|
577
|
+
files: Schema.optionalKey(ChatFilesManifest),
|
|
578
|
+
});
|
|
572
579
|
/**
|
|
573
580
|
* The ontology catalog: the contract between the SDK, backend-next, the console and the CLI. Decoding
|
|
574
581
|
* ignores unknown fields and accepts any `version`. The closed sets (property types, cardinalities,
|
|
@@ -603,17 +610,20 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
603
610
|
* declared connection, and the attribution it adds. Absent, or without a channel, delivers
|
|
604
611
|
* nowhere. The channel named after each kind has its key; `channels` holds the others by name,
|
|
605
612
|
* with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
|
|
606
|
-
* from; no chat post goes to it, nor to another channel of its kind.
|
|
613
|
+
* from; no chat post goes to it, nor to another channel of its kind. Within version 16, a
|
|
614
|
+
* channel may carry `files: { keep: true }`, written only when declared: its chats keep their
|
|
615
|
+
* files as long as their messages. Older readers ignore it and keep files 24 hours.
|
|
607
616
|
*/
|
|
608
617
|
chat: Schema.optionalKey(Schema.Struct({
|
|
609
|
-
telegram: Schema.optionalKey(
|
|
610
|
-
slack: Schema.optionalKey(
|
|
611
|
-
whatsapp: Schema.optionalKey(
|
|
612
|
-
email: Schema.optionalKey(
|
|
618
|
+
telegram: Schema.optionalKey(ChatChannelManifest),
|
|
619
|
+
slack: Schema.optionalKey(ChatChannelManifest),
|
|
620
|
+
whatsapp: Schema.optionalKey(ChatChannelManifest),
|
|
621
|
+
email: Schema.optionalKey(ChatChannelManifest),
|
|
613
622
|
channels: Schema.optionalKey(Schema.Record(Schema.String.check(Schema.isPattern(CHAT_CHANNEL_NAME)), Schema.Struct({
|
|
614
623
|
kind: Schema.Literals(CHAT_KINDS),
|
|
615
624
|
// A workspace channel (`custom`) has none: the agent sends through it.
|
|
616
625
|
connection: Schema.optionalKey(Schema.String),
|
|
626
|
+
files: Schema.optionalKey(ChatFilesManifest),
|
|
617
627
|
}))),
|
|
618
628
|
attribution: Schema.optionalKey(Schema.Struct({
|
|
619
629
|
template: Schema.optionalKey(Schema.String),
|
|
@@ -757,6 +767,18 @@ export function chatRetentionDaysOf(manifest) {
|
|
|
757
767
|
? days
|
|
758
768
|
: CHAT_RETENTION_DAYS.default;
|
|
759
769
|
}
|
|
770
|
+
/**
|
|
771
|
+
* Whether the chats of the agent's channel `name` keep their files as long as their messages, as
|
|
772
|
+
* the channel's `files: { keep: true }` in `chat` declares; otherwise a file expires 24 hours after
|
|
773
|
+
* it arrives.
|
|
774
|
+
*/
|
|
775
|
+
export function keepsChatFiles(manifest, name) {
|
|
776
|
+
const chat = manifest.chat;
|
|
777
|
+
const channel = name === "telegram" || name === "slack" || name === "whatsapp" || name === "email"
|
|
778
|
+
? chat?.[name]
|
|
779
|
+
: chat?.channels?.[name];
|
|
780
|
+
return channel?.files?.keep === true;
|
|
781
|
+
}
|
|
760
782
|
/** The wire names of the roles whose people's private chats join the inbox; empty without one. */
|
|
761
783
|
export function inboxRolesOf(manifest) {
|
|
762
784
|
return new Set(manifest.inbox?.roles ?? []);
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -361,13 +361,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
361
361
|
readonly [x: string]: Schema.Json;
|
|
362
362
|
};
|
|
363
363
|
readonly permission?: string | undefined;
|
|
364
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
365
|
-
readonly writes?: readonly string[] | undefined;
|
|
366
|
-
readonly connections?: readonly string[] | undefined;
|
|
367
364
|
readonly files?: readonly {
|
|
368
365
|
readonly entity: string;
|
|
369
366
|
readonly property: string;
|
|
370
367
|
}[] | undefined;
|
|
368
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
369
|
+
readonly writes?: readonly string[] | undefined;
|
|
370
|
+
readonly connections?: readonly string[] | undefined;
|
|
371
371
|
readonly hints?: {
|
|
372
372
|
readonly readOnly?: boolean | undefined;
|
|
373
373
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -408,19 +408,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
408
408
|
readonly chat?: {
|
|
409
409
|
readonly telegram?: {
|
|
410
410
|
readonly connection: string;
|
|
411
|
+
readonly files?: {
|
|
412
|
+
readonly keep: boolean;
|
|
413
|
+
} | undefined;
|
|
411
414
|
} | undefined;
|
|
412
415
|
readonly slack?: {
|
|
413
416
|
readonly connection: string;
|
|
417
|
+
readonly files?: {
|
|
418
|
+
readonly keep: boolean;
|
|
419
|
+
} | undefined;
|
|
414
420
|
} | undefined;
|
|
415
421
|
readonly whatsapp?: {
|
|
416
422
|
readonly connection: string;
|
|
423
|
+
readonly files?: {
|
|
424
|
+
readonly keep: boolean;
|
|
425
|
+
} | undefined;
|
|
417
426
|
} | undefined;
|
|
418
427
|
readonly email?: {
|
|
419
428
|
readonly connection: string;
|
|
429
|
+
readonly files?: {
|
|
430
|
+
readonly keep: boolean;
|
|
431
|
+
} | undefined;
|
|
420
432
|
} | undefined;
|
|
421
433
|
readonly channels?: {
|
|
422
434
|
readonly [x: string]: {
|
|
423
435
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
436
|
+
readonly files?: {
|
|
437
|
+
readonly keep: boolean;
|
|
438
|
+
} | undefined;
|
|
424
439
|
readonly connection?: string | undefined;
|
|
425
440
|
};
|
|
426
441
|
} | undefined;
|
|
@@ -630,13 +645,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
630
645
|
readonly [x: string]: Schema.Json;
|
|
631
646
|
};
|
|
632
647
|
readonly permission?: string | undefined;
|
|
633
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
634
|
-
readonly writes?: readonly string[] | undefined;
|
|
635
|
-
readonly connections?: readonly string[] | undefined;
|
|
636
648
|
readonly files?: readonly {
|
|
637
649
|
readonly entity: string;
|
|
638
650
|
readonly property: string;
|
|
639
651
|
}[] | undefined;
|
|
652
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
653
|
+
readonly writes?: readonly string[] | undefined;
|
|
654
|
+
readonly connections?: readonly string[] | undefined;
|
|
640
655
|
readonly hints?: {
|
|
641
656
|
readonly readOnly?: boolean | undefined;
|
|
642
657
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -718,13 +733,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
718
733
|
readonly [x: string]: Schema.Json;
|
|
719
734
|
};
|
|
720
735
|
readonly permission?: string | undefined;
|
|
721
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
722
|
-
readonly writes?: readonly string[] | undefined;
|
|
723
|
-
readonly connections?: readonly string[] | undefined;
|
|
724
736
|
readonly files?: readonly {
|
|
725
737
|
readonly entity: string;
|
|
726
738
|
readonly property: string;
|
|
727
739
|
}[] | undefined;
|
|
740
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
741
|
+
readonly writes?: readonly string[] | undefined;
|
|
742
|
+
readonly connections?: readonly string[] | undefined;
|
|
728
743
|
readonly hints?: {
|
|
729
744
|
readonly readOnly?: boolean | undefined;
|
|
730
745
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -765,19 +780,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
765
780
|
readonly chat?: {
|
|
766
781
|
readonly telegram?: {
|
|
767
782
|
readonly connection: string;
|
|
783
|
+
readonly files?: {
|
|
784
|
+
readonly keep: boolean;
|
|
785
|
+
} | undefined;
|
|
768
786
|
} | undefined;
|
|
769
787
|
readonly slack?: {
|
|
770
788
|
readonly connection: string;
|
|
789
|
+
readonly files?: {
|
|
790
|
+
readonly keep: boolean;
|
|
791
|
+
} | undefined;
|
|
771
792
|
} | undefined;
|
|
772
793
|
readonly whatsapp?: {
|
|
773
794
|
readonly connection: string;
|
|
795
|
+
readonly files?: {
|
|
796
|
+
readonly keep: boolean;
|
|
797
|
+
} | undefined;
|
|
774
798
|
} | undefined;
|
|
775
799
|
readonly email?: {
|
|
776
800
|
readonly connection: string;
|
|
801
|
+
readonly files?: {
|
|
802
|
+
readonly keep: boolean;
|
|
803
|
+
} | undefined;
|
|
777
804
|
} | undefined;
|
|
778
805
|
readonly channels?: {
|
|
779
806
|
readonly [x: string]: {
|
|
780
807
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
808
|
+
readonly files?: {
|
|
809
|
+
readonly keep: boolean;
|
|
810
|
+
} | undefined;
|
|
781
811
|
readonly connection?: string | undefined;
|
|
782
812
|
};
|
|
783
813
|
} | undefined;
|
|
@@ -987,13 +1017,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
987
1017
|
readonly [x: string]: Schema.Json;
|
|
988
1018
|
};
|
|
989
1019
|
readonly permission?: string | undefined;
|
|
990
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
991
|
-
readonly writes?: readonly string[] | undefined;
|
|
992
|
-
readonly connections?: readonly string[] | undefined;
|
|
993
1020
|
readonly files?: readonly {
|
|
994
1021
|
readonly entity: string;
|
|
995
1022
|
readonly property: string;
|
|
996
1023
|
}[] | undefined;
|
|
1024
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
1025
|
+
readonly writes?: readonly string[] | undefined;
|
|
1026
|
+
readonly connections?: readonly string[] | undefined;
|
|
997
1027
|
readonly hints?: {
|
|
998
1028
|
readonly readOnly?: boolean | undefined;
|
|
999
1029
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -1075,13 +1105,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1075
1105
|
readonly [x: string]: Schema.Json;
|
|
1076
1106
|
};
|
|
1077
1107
|
readonly permission?: string | undefined;
|
|
1078
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
1079
|
-
readonly writes?: readonly string[] | undefined;
|
|
1080
|
-
readonly connections?: readonly string[] | undefined;
|
|
1081
1108
|
readonly files?: readonly {
|
|
1082
1109
|
readonly entity: string;
|
|
1083
1110
|
readonly property: string;
|
|
1084
1111
|
}[] | undefined;
|
|
1112
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
1113
|
+
readonly writes?: readonly string[] | undefined;
|
|
1114
|
+
readonly connections?: readonly string[] | undefined;
|
|
1085
1115
|
readonly hints?: {
|
|
1086
1116
|
readonly readOnly?: boolean | undefined;
|
|
1087
1117
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -1122,19 +1152,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1122
1152
|
readonly chat?: {
|
|
1123
1153
|
readonly telegram?: {
|
|
1124
1154
|
readonly connection: string;
|
|
1155
|
+
readonly files?: {
|
|
1156
|
+
readonly keep: boolean;
|
|
1157
|
+
} | undefined;
|
|
1125
1158
|
} | undefined;
|
|
1126
1159
|
readonly slack?: {
|
|
1127
1160
|
readonly connection: string;
|
|
1161
|
+
readonly files?: {
|
|
1162
|
+
readonly keep: boolean;
|
|
1163
|
+
} | undefined;
|
|
1128
1164
|
} | undefined;
|
|
1129
1165
|
readonly whatsapp?: {
|
|
1130
1166
|
readonly connection: string;
|
|
1167
|
+
readonly files?: {
|
|
1168
|
+
readonly keep: boolean;
|
|
1169
|
+
} | undefined;
|
|
1131
1170
|
} | undefined;
|
|
1132
1171
|
readonly email?: {
|
|
1133
1172
|
readonly connection: string;
|
|
1173
|
+
readonly files?: {
|
|
1174
|
+
readonly keep: boolean;
|
|
1175
|
+
} | undefined;
|
|
1134
1176
|
} | undefined;
|
|
1135
1177
|
readonly channels?: {
|
|
1136
1178
|
readonly [x: string]: {
|
|
1137
1179
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
1180
|
+
readonly files?: {
|
|
1181
|
+
readonly keep: boolean;
|
|
1182
|
+
} | undefined;
|
|
1138
1183
|
readonly connection?: string | undefined;
|
|
1139
1184
|
};
|
|
1140
1185
|
} | undefined;
|
|
@@ -1307,13 +1352,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1307
1352
|
readonly [x: string]: Schema.Json;
|
|
1308
1353
|
};
|
|
1309
1354
|
readonly permission?: string | undefined;
|
|
1310
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
1311
|
-
readonly writes?: readonly string[] | undefined;
|
|
1312
|
-
readonly connections?: readonly string[] | undefined;
|
|
1313
1355
|
readonly files?: readonly {
|
|
1314
1356
|
readonly entity: string;
|
|
1315
1357
|
readonly property: string;
|
|
1316
1358
|
}[] | undefined;
|
|
1359
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
1360
|
+
readonly writes?: readonly string[] | undefined;
|
|
1361
|
+
readonly connections?: readonly string[] | undefined;
|
|
1317
1362
|
readonly hints?: {
|
|
1318
1363
|
readonly readOnly?: boolean | undefined;
|
|
1319
1364
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -1432,13 +1477,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1432
1477
|
readonly [x: string]: Schema.Json;
|
|
1433
1478
|
};
|
|
1434
1479
|
readonly permission?: string | undefined;
|
|
1435
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
1436
|
-
readonly writes?: readonly string[] | undefined;
|
|
1437
|
-
readonly connections?: readonly string[] | undefined;
|
|
1438
1480
|
readonly files?: readonly {
|
|
1439
1481
|
readonly entity: string;
|
|
1440
1482
|
readonly property: string;
|
|
1441
1483
|
}[] | undefined;
|
|
1484
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
1485
|
+
readonly writes?: readonly string[] | undefined;
|
|
1486
|
+
readonly connections?: readonly string[] | undefined;
|
|
1442
1487
|
readonly hints?: {
|
|
1443
1488
|
readonly readOnly?: boolean | undefined;
|
|
1444
1489
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -1479,19 +1524,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1479
1524
|
readonly chat?: {
|
|
1480
1525
|
readonly telegram?: {
|
|
1481
1526
|
readonly connection: string;
|
|
1527
|
+
readonly files?: {
|
|
1528
|
+
readonly keep: boolean;
|
|
1529
|
+
} | undefined;
|
|
1482
1530
|
} | undefined;
|
|
1483
1531
|
readonly slack?: {
|
|
1484
1532
|
readonly connection: string;
|
|
1533
|
+
readonly files?: {
|
|
1534
|
+
readonly keep: boolean;
|
|
1535
|
+
} | undefined;
|
|
1485
1536
|
} | undefined;
|
|
1486
1537
|
readonly whatsapp?: {
|
|
1487
1538
|
readonly connection: string;
|
|
1539
|
+
readonly files?: {
|
|
1540
|
+
readonly keep: boolean;
|
|
1541
|
+
} | undefined;
|
|
1488
1542
|
} | undefined;
|
|
1489
1543
|
readonly email?: {
|
|
1490
1544
|
readonly connection: string;
|
|
1545
|
+
readonly files?: {
|
|
1546
|
+
readonly keep: boolean;
|
|
1547
|
+
} | undefined;
|
|
1491
1548
|
} | undefined;
|
|
1492
1549
|
readonly channels?: {
|
|
1493
1550
|
readonly [x: string]: {
|
|
1494
1551
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
1552
|
+
readonly files?: {
|
|
1553
|
+
readonly keep: boolean;
|
|
1554
|
+
} | undefined;
|
|
1495
1555
|
readonly connection?: string | undefined;
|
|
1496
1556
|
};
|
|
1497
1557
|
} | undefined;
|
|
@@ -1701,13 +1761,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1701
1761
|
readonly [x: string]: Schema.Json;
|
|
1702
1762
|
};
|
|
1703
1763
|
readonly permission?: string | undefined;
|
|
1704
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
1705
|
-
readonly writes?: readonly string[] | undefined;
|
|
1706
|
-
readonly connections?: readonly string[] | undefined;
|
|
1707
1764
|
readonly files?: readonly {
|
|
1708
1765
|
readonly entity: string;
|
|
1709
1766
|
readonly property: string;
|
|
1710
1767
|
}[] | undefined;
|
|
1768
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
1769
|
+
readonly writes?: readonly string[] | undefined;
|
|
1770
|
+
readonly connections?: readonly string[] | undefined;
|
|
1711
1771
|
readonly hints?: {
|
|
1712
1772
|
readonly readOnly?: boolean | undefined;
|
|
1713
1773
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -1946,19 +2006,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1946
2006
|
readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
|
|
1947
2007
|
readonly telegram: Schema.optionalKey<Schema.Struct<{
|
|
1948
2008
|
readonly connection: Schema.String;
|
|
2009
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2010
|
+
readonly keep: Schema.Boolean;
|
|
2011
|
+
}>>;
|
|
1949
2012
|
}>>;
|
|
1950
2013
|
readonly slack: Schema.optionalKey<Schema.Struct<{
|
|
1951
2014
|
readonly connection: Schema.String;
|
|
2015
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2016
|
+
readonly keep: Schema.Boolean;
|
|
2017
|
+
}>>;
|
|
1952
2018
|
}>>;
|
|
1953
2019
|
readonly whatsapp: Schema.optionalKey<Schema.Struct<{
|
|
1954
2020
|
readonly connection: Schema.String;
|
|
2021
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2022
|
+
readonly keep: Schema.Boolean;
|
|
2023
|
+
}>>;
|
|
1955
2024
|
}>>;
|
|
1956
2025
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
1957
2026
|
readonly connection: Schema.String;
|
|
2027
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2028
|
+
readonly keep: Schema.Boolean;
|
|
2029
|
+
}>>;
|
|
1958
2030
|
}>>;
|
|
1959
2031
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
1960
2032
|
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
1961
2033
|
readonly connection: Schema.optionalKey<Schema.String>;
|
|
2034
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2035
|
+
readonly keep: Schema.Boolean;
|
|
2036
|
+
}>>;
|
|
1962
2037
|
}>>>;
|
|
1963
2038
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
1964
2039
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
@@ -2301,19 +2376,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2301
2376
|
readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
|
|
2302
2377
|
readonly telegram: Schema.optionalKey<Schema.Struct<{
|
|
2303
2378
|
readonly connection: Schema.String;
|
|
2379
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2380
|
+
readonly keep: Schema.Boolean;
|
|
2381
|
+
}>>;
|
|
2304
2382
|
}>>;
|
|
2305
2383
|
readonly slack: Schema.optionalKey<Schema.Struct<{
|
|
2306
2384
|
readonly connection: Schema.String;
|
|
2385
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2386
|
+
readonly keep: Schema.Boolean;
|
|
2387
|
+
}>>;
|
|
2307
2388
|
}>>;
|
|
2308
2389
|
readonly whatsapp: Schema.optionalKey<Schema.Struct<{
|
|
2309
2390
|
readonly connection: Schema.String;
|
|
2391
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2392
|
+
readonly keep: Schema.Boolean;
|
|
2393
|
+
}>>;
|
|
2310
2394
|
}>>;
|
|
2311
2395
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
2312
2396
|
readonly connection: Schema.String;
|
|
2397
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2398
|
+
readonly keep: Schema.Boolean;
|
|
2399
|
+
}>>;
|
|
2313
2400
|
}>>;
|
|
2314
2401
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
2315
2402
|
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
2316
2403
|
readonly connection: Schema.optionalKey<Schema.String>;
|
|
2404
|
+
readonly files: Schema.optionalKey<Schema.Struct<{
|
|
2405
|
+
readonly keep: Schema.Boolean;
|
|
2406
|
+
}>>;
|
|
2317
2407
|
}>>>;
|
|
2318
2408
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
2319
2409
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
@@ -2513,13 +2603,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2513
2603
|
readonly [x: string]: Schema.Json;
|
|
2514
2604
|
};
|
|
2515
2605
|
readonly permission?: string | undefined;
|
|
2516
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
2517
|
-
readonly writes?: readonly string[] | undefined;
|
|
2518
|
-
readonly connections?: readonly string[] | undefined;
|
|
2519
2606
|
readonly files?: readonly {
|
|
2520
2607
|
readonly entity: string;
|
|
2521
2608
|
readonly property: string;
|
|
2522
2609
|
}[] | undefined;
|
|
2610
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
2611
|
+
readonly writes?: readonly string[] | undefined;
|
|
2612
|
+
readonly connections?: readonly string[] | undefined;
|
|
2523
2613
|
readonly hints?: {
|
|
2524
2614
|
readonly readOnly?: boolean | undefined;
|
|
2525
2615
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -2560,19 +2650,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2560
2650
|
readonly chat?: {
|
|
2561
2651
|
readonly telegram?: {
|
|
2562
2652
|
readonly connection: string;
|
|
2653
|
+
readonly files?: {
|
|
2654
|
+
readonly keep: boolean;
|
|
2655
|
+
} | undefined;
|
|
2563
2656
|
} | undefined;
|
|
2564
2657
|
readonly slack?: {
|
|
2565
2658
|
readonly connection: string;
|
|
2659
|
+
readonly files?: {
|
|
2660
|
+
readonly keep: boolean;
|
|
2661
|
+
} | undefined;
|
|
2566
2662
|
} | undefined;
|
|
2567
2663
|
readonly whatsapp?: {
|
|
2568
2664
|
readonly connection: string;
|
|
2665
|
+
readonly files?: {
|
|
2666
|
+
readonly keep: boolean;
|
|
2667
|
+
} | undefined;
|
|
2569
2668
|
} | undefined;
|
|
2570
2669
|
readonly email?: {
|
|
2571
2670
|
readonly connection: string;
|
|
2671
|
+
readonly files?: {
|
|
2672
|
+
readonly keep: boolean;
|
|
2673
|
+
} | undefined;
|
|
2572
2674
|
} | undefined;
|
|
2573
2675
|
readonly channels?: {
|
|
2574
2676
|
readonly [x: string]: {
|
|
2575
2677
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
2678
|
+
readonly files?: {
|
|
2679
|
+
readonly keep: boolean;
|
|
2680
|
+
} | undefined;
|
|
2576
2681
|
readonly connection?: string | undefined;
|
|
2577
2682
|
};
|
|
2578
2683
|
} | undefined;
|
|
@@ -2782,13 +2887,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2782
2887
|
readonly [x: string]: Schema.Json;
|
|
2783
2888
|
};
|
|
2784
2889
|
readonly permission?: string | undefined;
|
|
2785
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
2786
|
-
readonly writes?: readonly string[] | undefined;
|
|
2787
|
-
readonly connections?: readonly string[] | undefined;
|
|
2788
2890
|
readonly files?: readonly {
|
|
2789
2891
|
readonly entity: string;
|
|
2790
2892
|
readonly property: string;
|
|
2791
2893
|
}[] | undefined;
|
|
2894
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
2895
|
+
readonly writes?: readonly string[] | undefined;
|
|
2896
|
+
readonly connections?: readonly string[] | undefined;
|
|
2792
2897
|
readonly hints?: {
|
|
2793
2898
|
readonly readOnly?: boolean | undefined;
|
|
2794
2899
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -2870,13 +2975,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2870
2975
|
readonly [x: string]: Schema.Json;
|
|
2871
2976
|
};
|
|
2872
2977
|
readonly permission?: string | undefined;
|
|
2873
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
2874
|
-
readonly writes?: readonly string[] | undefined;
|
|
2875
|
-
readonly connections?: readonly string[] | undefined;
|
|
2876
2978
|
readonly files?: readonly {
|
|
2877
2979
|
readonly entity: string;
|
|
2878
2980
|
readonly property: string;
|
|
2879
2981
|
}[] | undefined;
|
|
2982
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
2983
|
+
readonly writes?: readonly string[] | undefined;
|
|
2984
|
+
readonly connections?: readonly string[] | undefined;
|
|
2880
2985
|
readonly hints?: {
|
|
2881
2986
|
readonly readOnly?: boolean | undefined;
|
|
2882
2987
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -2917,19 +3022,34 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2917
3022
|
readonly chat?: {
|
|
2918
3023
|
readonly telegram?: {
|
|
2919
3024
|
readonly connection: string;
|
|
3025
|
+
readonly files?: {
|
|
3026
|
+
readonly keep: boolean;
|
|
3027
|
+
} | undefined;
|
|
2920
3028
|
} | undefined;
|
|
2921
3029
|
readonly slack?: {
|
|
2922
3030
|
readonly connection: string;
|
|
3031
|
+
readonly files?: {
|
|
3032
|
+
readonly keep: boolean;
|
|
3033
|
+
} | undefined;
|
|
2923
3034
|
} | undefined;
|
|
2924
3035
|
readonly whatsapp?: {
|
|
2925
3036
|
readonly connection: string;
|
|
3037
|
+
readonly files?: {
|
|
3038
|
+
readonly keep: boolean;
|
|
3039
|
+
} | undefined;
|
|
2926
3040
|
} | undefined;
|
|
2927
3041
|
readonly email?: {
|
|
2928
3042
|
readonly connection: string;
|
|
3043
|
+
readonly files?: {
|
|
3044
|
+
readonly keep: boolean;
|
|
3045
|
+
} | undefined;
|
|
2929
3046
|
} | undefined;
|
|
2930
3047
|
readonly channels?: {
|
|
2931
3048
|
readonly [x: string]: {
|
|
2932
3049
|
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
3050
|
+
readonly files?: {
|
|
3051
|
+
readonly keep: boolean;
|
|
3052
|
+
} | undefined;
|
|
2933
3053
|
readonly connection?: string | undefined;
|
|
2934
3054
|
};
|
|
2935
3055
|
} | undefined;
|
|
@@ -3139,13 +3259,13 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
3139
3259
|
readonly [x: string]: Schema.Json;
|
|
3140
3260
|
};
|
|
3141
3261
|
readonly permission?: string | undefined;
|
|
3142
|
-
readonly retryOnDeadlock?: boolean | undefined;
|
|
3143
|
-
readonly writes?: readonly string[] | undefined;
|
|
3144
|
-
readonly connections?: readonly string[] | undefined;
|
|
3145
3262
|
readonly files?: readonly {
|
|
3146
3263
|
readonly entity: string;
|
|
3147
3264
|
readonly property: string;
|
|
3148
3265
|
}[] | undefined;
|
|
3266
|
+
readonly retryOnDeadlock?: boolean | undefined;
|
|
3267
|
+
readonly writes?: readonly string[] | undefined;
|
|
3268
|
+
readonly connections?: readonly string[] | undefined;
|
|
3149
3269
|
readonly hints?: {
|
|
3150
3270
|
readonly readOnly?: boolean | undefined;
|
|
3151
3271
|
readonly connectionsReadOnly?: boolean | undefined;
|
|
@@ -95,6 +95,11 @@ export interface ChatMessageInput {
|
|
|
95
95
|
readonly sessionId?: string;
|
|
96
96
|
readonly turnId?: string;
|
|
97
97
|
readonly meta?: unknown;
|
|
98
|
+
/**
|
|
99
|
+
* When the message was imported: history from before the chat was recorded, which no session
|
|
100
|
+
* reads as new and no figure counts. The runtime routes never take it.
|
|
101
|
+
*/
|
|
102
|
+
readonly importedAt?: string;
|
|
98
103
|
}
|
|
99
104
|
/** The message a change is to, by the provider's id of it. */
|
|
100
105
|
interface Target {
|
|
@@ -250,8 +255,8 @@ export interface ChatMessageStore {
|
|
|
250
255
|
readonly applied: boolean;
|
|
251
256
|
}, ChatMessageConflict>;
|
|
252
257
|
readonly read: (input: ChatMessageQuery) => Effect.Effect<ChatMessagePage>;
|
|
253
|
-
/** Whether the store holds a message of the chat. */
|
|
254
|
-
readonly holds: (chat
|
|
258
|
+
/** Whether the store holds a message of the chat; without one, a message of any chat. */
|
|
259
|
+
readonly holds: (chat?: {
|
|
255
260
|
readonly channel: string;
|
|
256
261
|
readonly chatId: string;
|
|
257
262
|
}) => Effect.Effect<boolean>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { CHAT_MESSAGE_REVISIONS, CHAT_MESSAGES_TABLE } from "../migrate/storage.js";
|
|
3
|
+
import { ATTACHMENTS_TABLE } from "../storage/tables.js";
|
|
3
4
|
import { uuidv7 } from "./ids.js";
|
|
4
5
|
/**
|
|
5
6
|
* The workspace's chat store: one row per message in `_chat_messages` (docs/agent-chat-storage.md,
|
|
@@ -218,12 +219,14 @@ export function sqlChatMessageStore(sql) {
|
|
|
218
219
|
params.add(input.sessionId ?? null),
|
|
219
220
|
params.add(input.turnId ?? null),
|
|
220
221
|
params.add(input.meta === undefined ? null : JSON.stringify(input.meta), "jsonb"),
|
|
222
|
+
params.add(input.importedAt ?? null, "timestamptz"),
|
|
221
223
|
];
|
|
222
224
|
// Any of the keys may be taken: a redelivery, an echo, a retried send. Nothing changes then.
|
|
223
225
|
const [inserted] = yield* rows(`INSERT INTO ${TABLE} ("id", "channel", "chat_id", "thread_id", "chat_type", ` +
|
|
224
226
|
`"participants", "direction", "author", "sender_id", "sender_name", "user_id", ` +
|
|
225
227
|
`"message_id", "reply_to", "text", "parts", "files", "at", "status", "operation", ` +
|
|
226
|
-
`"fingerprint", "session_id", "turn_id", "meta"
|
|
228
|
+
`"fingerprint", "session_id", "turn_id", "meta", "imported_at") ` +
|
|
229
|
+
`VALUES (${values.join(", ")}) ` +
|
|
227
230
|
`ON CONFLICT DO NOTHING RETURNING "id"::text AS "id"`, params.values);
|
|
228
231
|
if (inserted !== undefined) {
|
|
229
232
|
return { id: String(inserted.id), first: true };
|
|
@@ -327,6 +330,39 @@ export function sqlChatMessageStore(sql) {
|
|
|
327
330
|
]);
|
|
328
331
|
return { applied: true };
|
|
329
332
|
}));
|
|
333
|
+
/**
|
|
334
|
+
* The person retracted the message: its content goes, the row stays as the message's place. The
|
|
335
|
+
* channel's `meta` goes with it: it holds the message's file references and what a turn read of
|
|
336
|
+
* it, and the dispatch fence that outlives the deletion is the disposition. The files it held, its
|
|
337
|
+
* chat's stored attachments, are discarded with it, as a channel that keeps them would otherwise
|
|
338
|
+
* keep them for as long as the chat's messages.
|
|
339
|
+
*/
|
|
340
|
+
const remove = (input) => inChat(input.channel, input.chatId, Effect.gen(function* () {
|
|
341
|
+
const [deleted] = yield* rows(`WITH "before" AS (SELECT "id", "files" FROM ${TABLE} WHERE "channel" = $1 ` +
|
|
342
|
+
`AND "chat_id" = $2 AND "message_id" = $3 AND "purged_at" IS NULL ` +
|
|
343
|
+
`AND "deleted_at" IS NULL FOR UPDATE) ` +
|
|
344
|
+
`UPDATE ${TABLE} SET "text" = NULL, "parts" = '[]', "files" = '[]', ` +
|
|
345
|
+
`"reactions" = '[]', "meta" = NULL, ` +
|
|
346
|
+
`"deleted_at" = date_trunc('milliseconds', coalesce($4::timestamptz, now())), ` +
|
|
347
|
+
`${revised} FROM "before" WHERE ${TABLE}."id" = "before"."id" ` +
|
|
348
|
+
`RETURNING "before"."files"::text AS "files"`, [input.channel, input.chatId, input.messageId, input.at ?? null]);
|
|
349
|
+
if (deleted === undefined) {
|
|
350
|
+
return { applied: false };
|
|
351
|
+
}
|
|
352
|
+
const files = jsonArray(deleted.files).flatMap((file) => {
|
|
353
|
+
const id = file.id;
|
|
354
|
+
return typeof id === "string" ? [id] : [];
|
|
355
|
+
});
|
|
356
|
+
const [storage] = files.length === 0
|
|
357
|
+
? []
|
|
358
|
+
: yield* rows(`SELECT to_regclass('"${ATTACHMENTS_TABLE}"') IS NOT NULL AS "present"`);
|
|
359
|
+
if (storage?.present === true || storage?.present === "t") {
|
|
360
|
+
yield* rows(`UPDATE "${ATTACHMENTS_TABLE}" SET "state" = 'discarded', "expires_at" = now() ` +
|
|
361
|
+
`WHERE "id"::text = ANY($1::text[]) AND "conversation" = $2 ` +
|
|
362
|
+
`AND "state" IN ('received', 'ready')`, [files, `${input.channel}:${input.chatId}`]);
|
|
363
|
+
}
|
|
364
|
+
return { applied: true };
|
|
365
|
+
}));
|
|
330
366
|
const change = (input) => {
|
|
331
367
|
const params = parameters();
|
|
332
368
|
switch (input.change) {
|
|
@@ -358,18 +394,7 @@ export function sqlChatMessageStore(sql) {
|
|
|
358
394
|
]);
|
|
359
395
|
}
|
|
360
396
|
case "delete":
|
|
361
|
-
|
|
362
|
-
// channel's `meta` goes with it: it holds the message's file references and what a turn
|
|
363
|
-
// read of it, and the dispatch fence that outlives the deletion is the disposition.
|
|
364
|
-
return update(input, params, [
|
|
365
|
-
`"text" = NULL`,
|
|
366
|
-
`"parts" = '[]'`,
|
|
367
|
-
`"files" = '[]'`,
|
|
368
|
-
`"reactions" = '[]'`,
|
|
369
|
-
`"meta" = NULL`,
|
|
370
|
-
`"deleted_at" = date_trunc('milliseconds', coalesce(${params.add(input.at ?? null, "timestamptz")}, now()))`,
|
|
371
|
-
revised,
|
|
372
|
-
], [`"deleted_at" IS NULL`]);
|
|
397
|
+
return remove(input);
|
|
373
398
|
case "reaction": {
|
|
374
399
|
const sender = params.add(input.senderId, "text");
|
|
375
400
|
const emoji = params.add(input.emoji, "text");
|
|
@@ -537,7 +562,9 @@ export function sqlChatMessageStore(sql) {
|
|
|
537
562
|
conditions.push(`(${rules.join(" OR ")})`);
|
|
538
563
|
return page(conditions, params, input);
|
|
539
564
|
};
|
|
540
|
-
const holds = (
|
|
565
|
+
const holds = (chat) => rows(chat === undefined
|
|
566
|
+
? `SELECT EXISTS (SELECT 1 FROM ${TABLE}) AS "holds"`
|
|
567
|
+
: `SELECT EXISTS (SELECT 1 FROM ${TABLE} WHERE "channel" = $1 AND "chat_id" = $2) AS "holds"`, chat === undefined ? [] : [chat.channel, chat.chatId]).pipe(Effect.map(([row]) => row?.holds === true || row?.holds === "t"));
|
|
541
568
|
const purge = ({ retentionDays }) => Effect.gen(function* () {
|
|
542
569
|
let deleted = 0;
|
|
543
570
|
let scrubbed = 0;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateTelegramPreviews } from "../../telegram.js";
|
|
2
|
-
import { inboxAttributionOf, takeoverChannelsOf } from "../../manifest.js";
|
|
2
|
+
import { chatRetentionDaysOf, inboxAttributionOf, takeoverChannelsOf } from "../../manifest.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { Cause, Effect } from "effect";
|
|
5
5
|
import { chatOperationId, chatPreviewDigest, } from "../../chat.js";
|
|
@@ -465,6 +465,8 @@ chats) {
|
|
|
465
465
|
identityToken: context.identityToken,
|
|
466
466
|
requestId: context.requestId,
|
|
467
467
|
archive: history,
|
|
468
|
+
retentionDays: chatRetentionDaysOf(ontology.manifest),
|
|
469
|
+
channelKind: (name) => chatKind(ontology.manifest.chat, name),
|
|
468
470
|
}),
|
|
469
471
|
}),
|
|
470
472
|
reviseReview: reviewReviser({
|