@segmentstream/ontology 0.110.0 → 0.113.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 +54 -0
- package/README.md +15 -3
- package/dist/agent-review.d.ts +2 -0
- package/dist/agent-review.js +11 -1
- package/dist/analyze.d.ts +38 -34
- package/dist/analyze.js +109 -41
- package/dist/chat-channel.d.ts +47 -0
- package/dist/chat-channel.js +69 -0
- package/dist/email-html.d.ts +23 -0
- package/dist/email-html.js +249 -0
- package/dist/emails.d.ts +38 -6
- package/dist/emails.js +71 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +3 -0
- package/dist/manifest.d.ts +282 -50
- package/dist/manifest.js +41 -6
- package/dist/migrate/model.d.ts +126 -18
- package/dist/runtime/agents.js +3 -0
- package/dist/runtime/resolve-agent-identity.js +4 -1
- package/dist/runtime-source.d.ts +4 -0
- package/dist/runtime-source.js +5 -0
- package/dist/runtime.d.ts +4 -1
- package/dist/service/agent/protocol.d.ts +5 -1
- package/dist/service/agent/protocol.js +12 -3
- package/dist/service/agent/server.js +17 -0
- package/dist/service/authentication.d.ts +5 -3
- package/dist/service/authentication.js +20 -5
- package/dist/service/chat/delivery.d.ts +10 -1
- package/dist/service/chat/delivery.js +30 -8
- package/dist/service/chat/envelope.d.ts +8 -2
- package/dist/service/chat/providers/custom.d.ts +13 -0
- package/dist/service/chat/providers/custom.js +103 -0
- package/dist/service/chat/providers/index.d.ts +20 -9
- package/dist/service/chat/providers/index.js +41 -12
- package/dist/service/chat/providers/provider.d.ts +19 -0
- package/dist/service/chat/reads.d.ts +6 -3
- package/dist/service/chat/reads.js +26 -14
- package/dist/service/chat/resolve.d.ts +7 -2
- package/dist/service/chat/resolve.js +11 -3
- package/dist/service/chat/review-delivery.d.ts +5 -2
- package/dist/service/chat/review-delivery.js +23 -9
- package/dist/service/chat/routes.js +2 -1
- package/dist/service/chat/schemas.d.ts +2 -0
- package/dist/service/chat/schemas.js +8 -1
- package/dist/service/config.d.ts +6 -2
- package/dist/service/mcp/server.js +2 -1
- package/dist/service/runtime-contract.d.ts +9 -0
- package/dist/service/schemas.d.ts +34 -4
- package/dist/service/service.js +6 -1
- package/dist/sign-in.d.ts +22 -1
- package/dist/sign-in.js +3 -1
- package/dist/storage/tables.d.ts +4 -3
- package/dist/storage/tables.js +11 -3
- package/dist/workspace-channel.d.ts +54 -0
- package/dist/workspace-channel.js +36 -0
- package/package.json +5 -1
package/dist/manifest.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CHAT_CHANNEL_NAME, CHAT_KINDS } from "./chat-channel.js";
|
|
1
2
|
import { balancesOf, metricExpression } from "./metric.js";
|
|
2
3
|
import { Effect, Schema, SchemaTransformation } from "effect";
|
|
3
4
|
import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legacy.js";
|
|
@@ -77,6 +78,17 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
77
78
|
* guest passes and the workspace secret its verification reads, and `confirmations: true`, written
|
|
78
79
|
* only when declared. Older readers ignore both: they ask new guests for no challenge, and keep
|
|
79
80
|
* refusing guests the actions that need a confirmation.
|
|
81
|
+
* Within version 15, `signIn` may also carry `linkEmail` and `codeEmail`, written only when
|
|
82
|
+
* declared: the wire names of the emails the platform sends instead of its own sign-in link and
|
|
83
|
+
* sign-in code; the code email fills `{{code}}`. Older readers ignore both and send the platform's.
|
|
84
|
+
* Within version 15, an email may instead be a document the workspace lays out itself: `subject`,
|
|
85
|
+
* `html` and `text`, whose placeholders include `{{link}}`, the sign-in link. Older readers do not
|
|
86
|
+
* decode such an email and send the platform's own in its place where they can.
|
|
87
|
+
* Within version 15, `chat` may carry `channels`, written only when declared: the agent's channels
|
|
88
|
+
* not named after their kind, such as `sales_whatsapp`, each with its `kind` and connection. Older
|
|
89
|
+
* readers ignore it and send nothing through those channels. A channel the workspace defines in
|
|
90
|
+
* its own code has kind `custom` and no connection, as the agent sends through it; sign-up may open
|
|
91
|
+
* `channel:<name>`, its people's accounts.
|
|
80
92
|
*/
|
|
81
93
|
export const MANIFEST_VERSION = 15;
|
|
82
94
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -435,15 +447,21 @@ export const SignInManifest = Schema.Struct({
|
|
|
435
447
|
guest: Schema.optionalKey(GuestManifest),
|
|
436
448
|
/** The wire name of the email the platform sends instead of its own invitation. */
|
|
437
449
|
invitationEmail: Schema.optionalKey(Schema.String),
|
|
450
|
+
/** The wire name of the email the platform sends instead of its own sign-in link. */
|
|
451
|
+
linkEmail: Schema.optionalKey(Schema.String),
|
|
452
|
+
/** The wire name of the email the platform sends instead of its own sign-in code. */
|
|
453
|
+
codeEmail: Schema.optionalKey(Schema.String),
|
|
438
454
|
}).pipe(Schema.encodeKeys({
|
|
439
455
|
onNewUser: "on_new_user",
|
|
440
456
|
codeLink: "code_link",
|
|
441
457
|
signUp: "sign_up",
|
|
442
458
|
onSignUp: "on_sign_up",
|
|
443
459
|
invitationEmail: "invitation_email",
|
|
460
|
+
linkEmail: "link_email",
|
|
461
|
+
codeEmail: "code_email",
|
|
444
462
|
}));
|
|
445
|
-
/**
|
|
446
|
-
export const
|
|
463
|
+
/** An email as fields the platform lays out; see `EmailLayout`. */
|
|
464
|
+
export const EmailLayoutManifest = Schema.Struct({
|
|
447
465
|
subject: Schema.String,
|
|
448
466
|
eyebrow: Schema.optionalKey(Schema.String),
|
|
449
467
|
heading: Schema.String,
|
|
@@ -465,6 +483,15 @@ export const EmailTemplateManifest = Schema.Struct({
|
|
|
465
483
|
footer: Schema.optionalKey(Schema.String),
|
|
466
484
|
replyTo: Schema.optionalKey(Schema.String),
|
|
467
485
|
}).pipe(Schema.encodeKeys({ replyTo: "reply_to" }));
|
|
486
|
+
/** An email the workspace lays out itself: subject, HTML and plain text; see `EmailDocument`. */
|
|
487
|
+
export const EmailDocumentManifest = Schema.Struct({
|
|
488
|
+
subject: Schema.String,
|
|
489
|
+
html: Schema.String,
|
|
490
|
+
text: Schema.String,
|
|
491
|
+
replyTo: Schema.optionalKey(Schema.String),
|
|
492
|
+
}).pipe(Schema.encodeKeys({ replyTo: "reply_to" }));
|
|
493
|
+
/** One of the workspace's emails, as `defineOntology({ emails })` declares it; see `EmailTemplate`. */
|
|
494
|
+
export const EmailTemplateManifest = Schema.Union([EmailDocumentManifest, EmailLayoutManifest]);
|
|
468
495
|
/**
|
|
469
496
|
* The ontology catalog: the contract between the SDK, backend-next, the console and the CLI. Decoding
|
|
470
497
|
* ignores unknown fields and accepts any `version`. The closed sets (property types, cardinalities,
|
|
@@ -495,16 +522,22 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
495
522
|
/** The connections the actions call. Written only when there are some; absent reads as none. */
|
|
496
523
|
connections: Schema.optionalKey(Schema.Array(ConnectionManifest)),
|
|
497
524
|
/**
|
|
498
|
-
* The
|
|
499
|
-
* connection, and the attribution it adds. Absent, or without a
|
|
500
|
-
*
|
|
501
|
-
*
|
|
525
|
+
* The agent's channels whose chats the built-in exact chat post delivers to, each through its
|
|
526
|
+
* declared connection, and the attribution it adds. Absent, or without a channel, delivers
|
|
527
|
+
* nowhere. The channel named after each kind has its key; `channels` holds the others by name,
|
|
528
|
+
* with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
|
|
529
|
+
* from; no chat post goes to it, nor to another channel of its kind.
|
|
502
530
|
*/
|
|
503
531
|
chat: Schema.optionalKey(Schema.Struct({
|
|
504
532
|
telegram: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
|
|
505
533
|
slack: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
|
|
506
534
|
whatsapp: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
|
|
507
535
|
email: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
|
|
536
|
+
channels: Schema.optionalKey(Schema.Record(Schema.String.check(Schema.isPattern(CHAT_CHANNEL_NAME)), Schema.Struct({
|
|
537
|
+
kind: Schema.Literals(CHAT_KINDS),
|
|
538
|
+
// A workspace channel (`custom`) has none: the agent sends through it.
|
|
539
|
+
connection: Schema.optionalKey(Schema.String),
|
|
540
|
+
}))),
|
|
508
541
|
attribution: Schema.optionalKey(Schema.Struct({
|
|
509
542
|
template: Schema.optionalKey(Schema.String),
|
|
510
543
|
separator: Schema.optionalKey(Schema.String),
|
|
@@ -902,6 +935,8 @@ export function buildManifest(input) {
|
|
|
902
935
|
...(input.signIn.invitationEmail === undefined
|
|
903
936
|
? {}
|
|
904
937
|
: { invitationEmail: input.signIn.invitationEmail }),
|
|
938
|
+
...(input.signIn.linkEmail === undefined ? {} : { linkEmail: input.signIn.linkEmail }),
|
|
939
|
+
...(input.signIn.codeEmail === undefined ? {} : { codeEmail: input.signIn.codeEmail }),
|
|
905
940
|
...(Object.keys(input.signIn.channels ?? {}).length > 0
|
|
906
941
|
? { channels: input.signIn.channels }
|
|
907
942
|
: {}),
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -400,15 +400,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
400
400
|
readonly telegram?: {
|
|
401
401
|
readonly connection: string;
|
|
402
402
|
} | undefined;
|
|
403
|
-
readonly
|
|
403
|
+
readonly slack?: {
|
|
404
404
|
readonly connection: string;
|
|
405
405
|
} | undefined;
|
|
406
406
|
readonly whatsapp?: {
|
|
407
407
|
readonly connection: string;
|
|
408
408
|
} | undefined;
|
|
409
|
-
readonly
|
|
409
|
+
readonly email?: {
|
|
410
410
|
readonly connection: string;
|
|
411
411
|
} | undefined;
|
|
412
|
+
readonly channels?: {
|
|
413
|
+
readonly [x: string]: {
|
|
414
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
415
|
+
readonly connection?: string | undefined;
|
|
416
|
+
};
|
|
417
|
+
} | undefined;
|
|
412
418
|
readonly attribution?: {
|
|
413
419
|
readonly template?: string | undefined;
|
|
414
420
|
readonly separator?: string | undefined;
|
|
@@ -511,9 +517,16 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
511
517
|
} | undefined;
|
|
512
518
|
readonly onSignUp?: string | undefined;
|
|
513
519
|
readonly invitationEmail?: string | undefined;
|
|
520
|
+
readonly linkEmail?: string | undefined;
|
|
521
|
+
readonly codeEmail?: string | undefined;
|
|
514
522
|
} | undefined;
|
|
515
523
|
readonly emails?: {
|
|
516
524
|
readonly [x: string]: {
|
|
525
|
+
readonly subject: string;
|
|
526
|
+
readonly text: string;
|
|
527
|
+
readonly html: string;
|
|
528
|
+
readonly replyTo?: string | undefined;
|
|
529
|
+
} | {
|
|
517
530
|
readonly subject: string;
|
|
518
531
|
readonly action: string;
|
|
519
532
|
readonly heading: string;
|
|
@@ -696,15 +709,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
696
709
|
readonly telegram?: {
|
|
697
710
|
readonly connection: string;
|
|
698
711
|
} | undefined;
|
|
699
|
-
readonly
|
|
712
|
+
readonly slack?: {
|
|
700
713
|
readonly connection: string;
|
|
701
714
|
} | undefined;
|
|
702
715
|
readonly whatsapp?: {
|
|
703
716
|
readonly connection: string;
|
|
704
717
|
} | undefined;
|
|
705
|
-
readonly
|
|
718
|
+
readonly email?: {
|
|
706
719
|
readonly connection: string;
|
|
707
720
|
} | undefined;
|
|
721
|
+
readonly channels?: {
|
|
722
|
+
readonly [x: string]: {
|
|
723
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
724
|
+
readonly connection?: string | undefined;
|
|
725
|
+
};
|
|
726
|
+
} | undefined;
|
|
708
727
|
readonly attribution?: {
|
|
709
728
|
readonly template?: string | undefined;
|
|
710
729
|
readonly separator?: string | undefined;
|
|
@@ -807,9 +826,16 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
807
826
|
} | undefined;
|
|
808
827
|
readonly onSignUp?: string | undefined;
|
|
809
828
|
readonly invitationEmail?: string | undefined;
|
|
829
|
+
readonly linkEmail?: string | undefined;
|
|
830
|
+
readonly codeEmail?: string | undefined;
|
|
810
831
|
} | undefined;
|
|
811
832
|
readonly emails?: {
|
|
812
833
|
readonly [x: string]: {
|
|
834
|
+
readonly subject: string;
|
|
835
|
+
readonly text: string;
|
|
836
|
+
readonly html: string;
|
|
837
|
+
readonly replyTo?: string | undefined;
|
|
838
|
+
} | {
|
|
813
839
|
readonly subject: string;
|
|
814
840
|
readonly action: string;
|
|
815
841
|
readonly heading: string;
|
|
@@ -992,15 +1018,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
992
1018
|
readonly telegram?: {
|
|
993
1019
|
readonly connection: string;
|
|
994
1020
|
} | undefined;
|
|
995
|
-
readonly
|
|
1021
|
+
readonly slack?: {
|
|
996
1022
|
readonly connection: string;
|
|
997
1023
|
} | undefined;
|
|
998
1024
|
readonly whatsapp?: {
|
|
999
1025
|
readonly connection: string;
|
|
1000
1026
|
} | undefined;
|
|
1001
|
-
readonly
|
|
1027
|
+
readonly email?: {
|
|
1002
1028
|
readonly connection: string;
|
|
1003
1029
|
} | undefined;
|
|
1030
|
+
readonly channels?: {
|
|
1031
|
+
readonly [x: string]: {
|
|
1032
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
1033
|
+
readonly connection?: string | undefined;
|
|
1034
|
+
};
|
|
1035
|
+
} | undefined;
|
|
1004
1036
|
readonly attribution?: {
|
|
1005
1037
|
readonly template?: string | undefined;
|
|
1006
1038
|
readonly separator?: string | undefined;
|
|
@@ -1073,9 +1105,15 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1073
1105
|
} | undefined;
|
|
1074
1106
|
readonly emails?: {
|
|
1075
1107
|
readonly [x: string]: {
|
|
1108
|
+
readonly subject: string;
|
|
1109
|
+
readonly text: string;
|
|
1110
|
+
readonly html: string;
|
|
1111
|
+
readonly reply_to?: string | undefined;
|
|
1112
|
+
} | {
|
|
1076
1113
|
readonly subject: string;
|
|
1077
1114
|
readonly action: string;
|
|
1078
1115
|
readonly heading: string;
|
|
1116
|
+
readonly reply_to?: string | undefined;
|
|
1079
1117
|
readonly eyebrow?: string | undefined;
|
|
1080
1118
|
readonly card?: {
|
|
1081
1119
|
readonly title: string;
|
|
@@ -1098,7 +1136,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1098
1136
|
} | undefined;
|
|
1099
1137
|
}[] | undefined;
|
|
1100
1138
|
readonly footer?: string | undefined;
|
|
1101
|
-
readonly reply_to?: string | undefined;
|
|
1102
1139
|
};
|
|
1103
1140
|
} | undefined;
|
|
1104
1141
|
readonly toolsets?: readonly {
|
|
@@ -1168,6 +1205,8 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1168
1205
|
} | undefined;
|
|
1169
1206
|
readonly on_sign_up?: string | undefined;
|
|
1170
1207
|
readonly invitation_email?: string | undefined;
|
|
1208
|
+
readonly link_email?: string | undefined;
|
|
1209
|
+
readonly code_email?: string | undefined;
|
|
1171
1210
|
} | undefined;
|
|
1172
1211
|
} | {
|
|
1173
1212
|
readonly version: number;
|
|
@@ -1288,15 +1327,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1288
1327
|
readonly telegram?: {
|
|
1289
1328
|
readonly connection: string;
|
|
1290
1329
|
} | undefined;
|
|
1291
|
-
readonly
|
|
1330
|
+
readonly slack?: {
|
|
1292
1331
|
readonly connection: string;
|
|
1293
1332
|
} | undefined;
|
|
1294
1333
|
readonly whatsapp?: {
|
|
1295
1334
|
readonly connection: string;
|
|
1296
1335
|
} | undefined;
|
|
1297
|
-
readonly
|
|
1336
|
+
readonly email?: {
|
|
1298
1337
|
readonly connection: string;
|
|
1299
1338
|
} | undefined;
|
|
1339
|
+
readonly channels?: {
|
|
1340
|
+
readonly [x: string]: {
|
|
1341
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
1342
|
+
readonly connection?: string | undefined;
|
|
1343
|
+
};
|
|
1344
|
+
} | undefined;
|
|
1300
1345
|
readonly attribution?: {
|
|
1301
1346
|
readonly template?: string | undefined;
|
|
1302
1347
|
readonly separator?: string | undefined;
|
|
@@ -1399,12 +1444,20 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1399
1444
|
} | undefined;
|
|
1400
1445
|
readonly on_sign_up?: string | undefined;
|
|
1401
1446
|
readonly invitation_email?: string | undefined;
|
|
1447
|
+
readonly link_email?: string | undefined;
|
|
1448
|
+
readonly code_email?: string | undefined;
|
|
1402
1449
|
} | undefined;
|
|
1403
1450
|
readonly emails?: {
|
|
1404
1451
|
readonly [x: string]: {
|
|
1452
|
+
readonly subject: string;
|
|
1453
|
+
readonly text: string;
|
|
1454
|
+
readonly html: string;
|
|
1455
|
+
readonly reply_to?: string | undefined;
|
|
1456
|
+
} | {
|
|
1405
1457
|
readonly subject: string;
|
|
1406
1458
|
readonly action: string;
|
|
1407
1459
|
readonly heading: string;
|
|
1460
|
+
readonly reply_to?: string | undefined;
|
|
1408
1461
|
readonly eyebrow?: string | undefined;
|
|
1409
1462
|
readonly card?: {
|
|
1410
1463
|
readonly title: string;
|
|
@@ -1427,7 +1480,6 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1427
1480
|
} | undefined;
|
|
1428
1481
|
}[] | undefined;
|
|
1429
1482
|
readonly footer?: string | undefined;
|
|
1430
|
-
readonly reply_to?: string | undefined;
|
|
1431
1483
|
};
|
|
1432
1484
|
} | undefined;
|
|
1433
1485
|
readonly toolsets?: readonly {
|
|
@@ -1634,14 +1686,25 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1634
1686
|
readonly botCheck: "bot_check";
|
|
1635
1687
|
}>>;
|
|
1636
1688
|
readonly invitationEmail: Schema.optionalKey<Schema.String>;
|
|
1689
|
+
readonly linkEmail: Schema.optionalKey<Schema.String>;
|
|
1690
|
+
readonly codeEmail: Schema.optionalKey<Schema.String>;
|
|
1637
1691
|
}>, {
|
|
1638
1692
|
readonly onNewUser: "on_new_user";
|
|
1639
1693
|
readonly codeLink: "code_link";
|
|
1640
1694
|
readonly signUp: "sign_up";
|
|
1641
1695
|
readonly onSignUp: "on_sign_up";
|
|
1642
1696
|
readonly invitationEmail: "invitation_email";
|
|
1697
|
+
readonly linkEmail: "link_email";
|
|
1698
|
+
readonly codeEmail: "code_email";
|
|
1643
1699
|
}>>;
|
|
1644
|
-
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
1700
|
+
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.encodeKeys<Schema.Struct<{
|
|
1701
|
+
readonly subject: Schema.String;
|
|
1702
|
+
readonly html: Schema.String;
|
|
1703
|
+
readonly text: Schema.String;
|
|
1704
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
1705
|
+
}>, {
|
|
1706
|
+
readonly replyTo: "reply_to";
|
|
1707
|
+
}>, Schema.encodeKeys<Schema.Struct<{
|
|
1645
1708
|
readonly subject: Schema.String;
|
|
1646
1709
|
readonly eyebrow: Schema.optionalKey<Schema.String>;
|
|
1647
1710
|
readonly heading: Schema.String;
|
|
@@ -1670,7 +1733,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1670
1733
|
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
1671
1734
|
}>, {
|
|
1672
1735
|
readonly replyTo: "reply_to";
|
|
1673
|
-
}>>>;
|
|
1736
|
+
}>]>>>;
|
|
1674
1737
|
readonly connections: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
1675
1738
|
readonly key: Schema.String;
|
|
1676
1739
|
readonly description: Schema.String;
|
|
@@ -1689,6 +1752,10 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1689
1752
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
1690
1753
|
readonly connection: Schema.String;
|
|
1691
1754
|
}>>;
|
|
1755
|
+
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
1756
|
+
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
1757
|
+
readonly connection: Schema.optionalKey<Schema.String>;
|
|
1758
|
+
}>>>;
|
|
1692
1759
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
1693
1760
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
1694
1761
|
readonly separator: Schema.optionalKey<Schema.String>;
|
|
@@ -1924,14 +1991,25 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1924
1991
|
readonly botCheck: "bot_check";
|
|
1925
1992
|
}>>;
|
|
1926
1993
|
readonly invitationEmail: Schema.optionalKey<Schema.String>;
|
|
1994
|
+
readonly linkEmail: Schema.optionalKey<Schema.String>;
|
|
1995
|
+
readonly codeEmail: Schema.optionalKey<Schema.String>;
|
|
1927
1996
|
}>, {
|
|
1928
1997
|
readonly onNewUser: "on_new_user";
|
|
1929
1998
|
readonly codeLink: "code_link";
|
|
1930
1999
|
readonly signUp: "sign_up";
|
|
1931
2000
|
readonly onSignUp: "on_sign_up";
|
|
1932
2001
|
readonly invitationEmail: "invitation_email";
|
|
2002
|
+
readonly linkEmail: "link_email";
|
|
2003
|
+
readonly codeEmail: "code_email";
|
|
1933
2004
|
}>>;
|
|
1934
|
-
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
2005
|
+
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Union<readonly [Schema.encodeKeys<Schema.Struct<{
|
|
2006
|
+
readonly subject: Schema.String;
|
|
2007
|
+
readonly html: Schema.String;
|
|
2008
|
+
readonly text: Schema.String;
|
|
2009
|
+
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
2010
|
+
}>, {
|
|
2011
|
+
readonly replyTo: "reply_to";
|
|
2012
|
+
}>, Schema.encodeKeys<Schema.Struct<{
|
|
1935
2013
|
readonly subject: Schema.String;
|
|
1936
2014
|
readonly eyebrow: Schema.optionalKey<Schema.String>;
|
|
1937
2015
|
readonly heading: Schema.String;
|
|
@@ -1960,7 +2038,7 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1960
2038
|
readonly replyTo: Schema.optionalKey<Schema.String>;
|
|
1961
2039
|
}>, {
|
|
1962
2040
|
readonly replyTo: "reply_to";
|
|
1963
|
-
}>>>;
|
|
2041
|
+
}>]>>>;
|
|
1964
2042
|
readonly connections: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
1965
2043
|
readonly key: Schema.String;
|
|
1966
2044
|
readonly description: Schema.String;
|
|
@@ -1979,6 +2057,10 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1979
2057
|
readonly email: Schema.optionalKey<Schema.Struct<{
|
|
1980
2058
|
readonly connection: Schema.String;
|
|
1981
2059
|
}>>;
|
|
2060
|
+
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
|
|
2061
|
+
readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
|
|
2062
|
+
readonly connection: Schema.optionalKey<Schema.String>;
|
|
2063
|
+
}>>>;
|
|
1982
2064
|
readonly attribution: Schema.optionalKey<Schema.Struct<{
|
|
1983
2065
|
readonly template: Schema.optionalKey<Schema.String>;
|
|
1984
2066
|
readonly separator: Schema.optionalKey<Schema.String>;
|
|
@@ -2177,15 +2259,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2177
2259
|
readonly telegram?: {
|
|
2178
2260
|
readonly connection: string;
|
|
2179
2261
|
} | undefined;
|
|
2180
|
-
readonly
|
|
2262
|
+
readonly slack?: {
|
|
2181
2263
|
readonly connection: string;
|
|
2182
2264
|
} | undefined;
|
|
2183
2265
|
readonly whatsapp?: {
|
|
2184
2266
|
readonly connection: string;
|
|
2185
2267
|
} | undefined;
|
|
2186
|
-
readonly
|
|
2268
|
+
readonly email?: {
|
|
2187
2269
|
readonly connection: string;
|
|
2188
2270
|
} | undefined;
|
|
2271
|
+
readonly channels?: {
|
|
2272
|
+
readonly [x: string]: {
|
|
2273
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
2274
|
+
readonly connection?: string | undefined;
|
|
2275
|
+
};
|
|
2276
|
+
} | undefined;
|
|
2189
2277
|
readonly attribution?: {
|
|
2190
2278
|
readonly template?: string | undefined;
|
|
2191
2279
|
readonly separator?: string | undefined;
|
|
@@ -2288,9 +2376,16 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2288
2376
|
} | undefined;
|
|
2289
2377
|
readonly onSignUp?: string | undefined;
|
|
2290
2378
|
readonly invitationEmail?: string | undefined;
|
|
2379
|
+
readonly linkEmail?: string | undefined;
|
|
2380
|
+
readonly codeEmail?: string | undefined;
|
|
2291
2381
|
} | undefined;
|
|
2292
2382
|
readonly emails?: {
|
|
2293
2383
|
readonly [x: string]: {
|
|
2384
|
+
readonly subject: string;
|
|
2385
|
+
readonly text: string;
|
|
2386
|
+
readonly html: string;
|
|
2387
|
+
readonly replyTo?: string | undefined;
|
|
2388
|
+
} | {
|
|
2294
2389
|
readonly subject: string;
|
|
2295
2390
|
readonly action: string;
|
|
2296
2391
|
readonly heading: string;
|
|
@@ -2473,15 +2568,21 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2473
2568
|
readonly telegram?: {
|
|
2474
2569
|
readonly connection: string;
|
|
2475
2570
|
} | undefined;
|
|
2476
|
-
readonly
|
|
2571
|
+
readonly slack?: {
|
|
2477
2572
|
readonly connection: string;
|
|
2478
2573
|
} | undefined;
|
|
2479
2574
|
readonly whatsapp?: {
|
|
2480
2575
|
readonly connection: string;
|
|
2481
2576
|
} | undefined;
|
|
2482
|
-
readonly
|
|
2577
|
+
readonly email?: {
|
|
2483
2578
|
readonly connection: string;
|
|
2484
2579
|
} | undefined;
|
|
2580
|
+
readonly channels?: {
|
|
2581
|
+
readonly [x: string]: {
|
|
2582
|
+
readonly kind: "telegram" | "slack" | "whatsapp" | "email" | "custom";
|
|
2583
|
+
readonly connection?: string | undefined;
|
|
2584
|
+
};
|
|
2585
|
+
} | undefined;
|
|
2485
2586
|
readonly attribution?: {
|
|
2486
2587
|
readonly template?: string | undefined;
|
|
2487
2588
|
readonly separator?: string | undefined;
|
|
@@ -2584,9 +2685,16 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2584
2685
|
} | undefined;
|
|
2585
2686
|
readonly onSignUp?: string | undefined;
|
|
2586
2687
|
readonly invitationEmail?: string | undefined;
|
|
2688
|
+
readonly linkEmail?: string | undefined;
|
|
2689
|
+
readonly codeEmail?: string | undefined;
|
|
2587
2690
|
} | undefined;
|
|
2588
2691
|
readonly emails?: {
|
|
2589
2692
|
readonly [x: string]: {
|
|
2693
|
+
readonly subject: string;
|
|
2694
|
+
readonly text: string;
|
|
2695
|
+
readonly html: string;
|
|
2696
|
+
readonly replyTo?: string | undefined;
|
|
2697
|
+
} | {
|
|
2590
2698
|
readonly subject: string;
|
|
2591
2699
|
readonly action: string;
|
|
2592
2700
|
readonly heading: string;
|
package/dist/runtime/agents.js
CHANGED
|
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { Effect } from "effect";
|
|
4
4
|
import { SqlClient } from "effect/unstable/sql";
|
|
5
5
|
import { AgentChat } from "../agent-chat.js";
|
|
6
|
+
import { chatChannelKind } from "../chat-channel.js";
|
|
6
7
|
import { AgentReview } from "../agent-review.js";
|
|
7
8
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
8
9
|
import { MAX_QUERY_LIMIT } from "../query.js";
|
|
@@ -300,6 +301,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
300
301
|
? principal
|
|
301
302
|
: { ...principal, authenticatedVia: provider };
|
|
302
303
|
}),
|
|
304
|
+
channelKind: (name) => chatChannelKind(ontology.manifest.chat?.channels, name),
|
|
303
305
|
seeChat: ({ provider, externalId, title, memberId, leftMemberId, agentLeft, migratedFrom }) => sql
|
|
304
306
|
.withTransaction(Effect.gen(function* () {
|
|
305
307
|
yield* beginReplicationWrite(sql);
|
|
@@ -473,6 +475,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
473
475
|
values: {
|
|
474
476
|
key: input.key,
|
|
475
477
|
provider: input.provider,
|
|
478
|
+
channel: input.channel,
|
|
476
479
|
chat_id: input.chatId,
|
|
477
480
|
recipient: input.recipient,
|
|
478
481
|
// Telegram's groups and channels have negative ids; WhatsApp chats are private.
|
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import { Effect, Option, Schema } from "effect";
|
|
3
3
|
import { isSqlError } from "effect/unstable/sql/SqlError";
|
|
4
4
|
import { Conflict } from "../errors.js";
|
|
5
|
+
import { workspaceChannelOf } from "../chat-channel.js";
|
|
5
6
|
import { channelPolicyOf, signUpRolesOf } from "../manifest.js";
|
|
6
7
|
import { AGENT_IDENTITIES_TABLE, CHANNEL_USERS_TABLE, USER_TABLE } from "../migrate/storage.js";
|
|
7
8
|
import { EMAIL_PATTERN } from "../property.js";
|
|
@@ -101,7 +102,9 @@ export function resolveAgentIdentity(ontology, sql, store, requested, context =
|
|
|
101
102
|
}
|
|
102
103
|
const display = input.display?.trim() || null;
|
|
103
104
|
const username = input.username?.trim().replace(/^@/, "");
|
|
104
|
-
|
|
105
|
+
// A workspace channel's account is named after the channel, as the workspace named it.
|
|
106
|
+
const providerName = workspaceChannelOf(input.provider) ??
|
|
107
|
+
input.provider.charAt(0).toUpperCase() + input.provider.slice(1);
|
|
105
108
|
const actionId = randomUUID();
|
|
106
109
|
const writer = makePrincipalUserWriter(ontology, sql, {
|
|
107
110
|
action: "user.provision",
|
package/dist/runtime-source.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { Schema } from "effect";
|
|
|
2
2
|
/** Decoded only at a verified runtime boundary; ordinary action arguments never establish provenance. */
|
|
3
3
|
export declare const RuntimeSource: Schema.Union<readonly [Schema.Struct<{
|
|
4
4
|
readonly provider: Schema.Literal<"telegram">;
|
|
5
|
+
/** The bot's channel when it is not the channel named `telegram`. */
|
|
6
|
+
readonly channel: Schema.optionalKey<Schema.String>;
|
|
5
7
|
readonly chat_id: Schema.String;
|
|
6
8
|
readonly thread_id: Schema.String;
|
|
7
9
|
readonly message_id: Schema.optionalKey<Schema.String>;
|
|
@@ -23,6 +25,8 @@ export declare const RuntimeSource: Schema.Union<readonly [Schema.Struct<{
|
|
|
23
25
|
}>>>;
|
|
24
26
|
}>, Schema.Struct<{
|
|
25
27
|
readonly provider: Schema.Literals<readonly ["slack", "whatsapp"]>;
|
|
28
|
+
/** The channel when it is not the one named after its kind. */
|
|
29
|
+
readonly channel: Schema.optionalKey<Schema.String>;
|
|
26
30
|
readonly chat_id: Schema.String;
|
|
27
31
|
readonly thread_id: Schema.String;
|
|
28
32
|
readonly kind: Schema.Literals<readonly ["private", "group"]>;
|
package/dist/runtime-source.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { ChatChannelName } from "./chat-channel.js";
|
|
2
3
|
const Id = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
|
|
3
4
|
/**
|
|
4
5
|
* The location a Telegram message shared, as the Bot API sends it: a live location's latest update
|
|
@@ -13,6 +14,8 @@ const TelegramLocation = Schema.Struct({
|
|
|
13
14
|
/** A Telegram chat, with the references Telegram's own actions and attachments use. */
|
|
14
15
|
const TelegramRuntimeSource = Schema.Struct({
|
|
15
16
|
provider: Schema.Literal("telegram"),
|
|
17
|
+
/** The bot's channel when it is not the channel named `telegram`. */
|
|
18
|
+
channel: Schema.optionalKey(ChatChannelName),
|
|
16
19
|
chat_id: Id,
|
|
17
20
|
thread_id: Schema.String.check(Schema.isMaxLength(512)),
|
|
18
21
|
message_id: Schema.optionalKey(Id),
|
|
@@ -44,6 +47,8 @@ const TelegramRuntimeSource = Schema.Struct({
|
|
|
44
47
|
*/
|
|
45
48
|
const ChannelRuntimeSource = Schema.Struct({
|
|
46
49
|
provider: Schema.Literals(["slack", "whatsapp"]),
|
|
50
|
+
/** The channel when it is not the one named after its kind. */
|
|
51
|
+
channel: Schema.optionalKey(ChatChannelName),
|
|
47
52
|
chat_id: Id,
|
|
48
53
|
thread_id: Schema.String.check(Schema.isMaxLength(512)),
|
|
49
54
|
kind: Schema.Literals(["private", "group"]),
|
package/dist/runtime.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ import type { WorkloadExecution } from "./runtime/workload.js";
|
|
|
11
11
|
* guest it acts for.
|
|
12
12
|
*/
|
|
13
13
|
export interface ChatProvenance {
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The chat's channel, by its name as the archive keys it: `web`, or the agent's channel, such as
|
|
16
|
+
* `telegram` or `sales_whatsapp`.
|
|
17
|
+
*/
|
|
15
18
|
readonly provider: string;
|
|
16
19
|
/** The chat's id there, such as `guest:<id>` or `member:<id>` on the web, or `-100123`. */
|
|
17
20
|
readonly chatId: string;
|
|
@@ -17,7 +17,10 @@ export declare function newPairingCode(): string;
|
|
|
17
17
|
* without the spaces or dashes someone may type between groups. `undefined` when it cannot be one.
|
|
18
18
|
*/
|
|
19
19
|
export declare function canonicalPairingCode(value: string): string | undefined;
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* A channel's name: `telegram`, `slack`. It is part of a URL path and of every identity. The
|
|
22
|
+
* accounts of a channel the workspace defines in its own code are its own, `channel:<name>`.
|
|
23
|
+
*/
|
|
21
24
|
export declare const Provider: Schema.String;
|
|
22
25
|
/** `POST /api/ontology/agent/pairings`: the account an unknown sender writes from. */
|
|
23
26
|
export declare const PairingRequest: Schema.Struct<{
|
|
@@ -128,6 +131,7 @@ export declare const ChatSeenRequest: Schema.Struct<{
|
|
|
128
131
|
export declare const ReviewRequest: Schema.Struct<{
|
|
129
132
|
readonly key: Schema.String;
|
|
130
133
|
readonly provider: Schema.String;
|
|
134
|
+
readonly channel: Schema.optionalKey<Schema.String>;
|
|
131
135
|
readonly chat_id: Schema.String;
|
|
132
136
|
readonly recipient: Schema.String;
|
|
133
137
|
readonly thread_id: Schema.String;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomInt } from "node:crypto";
|
|
2
2
|
import { Schema } from "effect";
|
|
3
|
+
import { ChatChannelName } from "../../chat-channel.js";
|
|
3
4
|
import { GUEST_USD_CEILINGS, MAX_GUEST_USAGE_REPORT_USD } from "../../runtime/agent-counters.js";
|
|
4
5
|
/** How long a member has to open the connect link, sign in and approve the pairing. */
|
|
5
6
|
export const PAIRING_TTL_MS = 10 * 60 * 1000;
|
|
@@ -29,9 +30,13 @@ export function canonicalPairingCode(value) {
|
|
|
29
30
|
}
|
|
30
31
|
const MAX_EXTERNAL_ID_LENGTH = 256;
|
|
31
32
|
const MAX_DISPLAY_LENGTH = 200;
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* A channel's name: `telegram`, `slack`. It is part of a URL path and of every identity. The
|
|
35
|
+
* accounts of a channel the workspace defines in its own code are its own, `channel:<name>`.
|
|
36
|
+
*/
|
|
37
|
+
export const Provider = Schema.String.check(Schema.isPattern(/^(?:[a-z][a-z0-9_-]{0,31}|channel:[a-z][a-z0-9_]{0,31})$/)).annotate({
|
|
38
|
+
description: "The channel, such as telegram: lower case letters, digits, - and _; or channel:<name>, the " +
|
|
39
|
+
"accounts of a channel the workspace defines.",
|
|
35
40
|
});
|
|
36
41
|
/** `POST /api/ontology/agent/pairings`: the account an unknown sender writes from. */
|
|
37
42
|
export const PairingRequest = Schema.Struct({
|
|
@@ -156,6 +161,10 @@ export const ReviewRequest = Schema.Struct({
|
|
|
156
161
|
description: "The agent's key for the reply: its session and content part.",
|
|
157
162
|
}),
|
|
158
163
|
provider: Provider,
|
|
164
|
+
channel: Schema.optionalKey(ChatChannelName.annotate({
|
|
165
|
+
description: "The channel the chat is on, by name, when it is not the one named after its kind, " +
|
|
166
|
+
"such as sales_whatsapp: approval sends the reply through its connection.",
|
|
167
|
+
})),
|
|
159
168
|
chat_id: ChatId.annotate({ description: "The chat's id on the channel." }),
|
|
160
169
|
recipient: ChatId.annotate({
|
|
161
170
|
description: "Whom the provider sends the reply to: the chat's id, or the person's number.",
|
|
@@ -3,6 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { Effect, Layer, Redacted, Result, Schema } from "effect";
|
|
4
4
|
import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";
|
|
5
5
|
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
6
|
+
import { isChatChannelKind, WORKSPACE_CHANNEL_KIND } from "../../chat-channel.js";
|
|
6
7
|
import { API_KEY_PREFIX } from "../../runtime/principals.js";
|
|
7
8
|
import { schemaIssues } from "../../runtime/validation.js";
|
|
8
9
|
import { BASE_PATH } from "../api.js";
|
|
@@ -305,9 +306,24 @@ function holdReply(store) {
|
|
|
305
306
|
return toServerResponse(notFound(requestId, "This ontology service holds no replies."));
|
|
306
307
|
}
|
|
307
308
|
const body = decoded.success;
|
|
309
|
+
// A channel named after a kind is that kind, and a workspace channel has a name of its own.
|
|
310
|
+
if (body.channel !== undefined &&
|
|
311
|
+
isChatChannelKind(body.channel) &&
|
|
312
|
+
body.channel !== body.provider) {
|
|
313
|
+
return invalidBody(requestId, [
|
|
314
|
+
{ path: ["channel"], message: "A channel named after a kind is that kind." },
|
|
315
|
+
]);
|
|
316
|
+
}
|
|
317
|
+
if (body.provider === WORKSPACE_CHANNEL_KIND &&
|
|
318
|
+
(body.channel === undefined || body.channel === WORKSPACE_CHANNEL_KIND)) {
|
|
319
|
+
return invalidBody(requestId, [
|
|
320
|
+
{ path: ["channel"], message: "A workspace channel's reply names its channel." },
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
308
323
|
const review = yield* store.holdReply({
|
|
309
324
|
key: body.key,
|
|
310
325
|
provider: body.provider,
|
|
326
|
+
channel: body.channel ?? body.provider,
|
|
311
327
|
chatId: body.chat_id,
|
|
312
328
|
recipient: body.recipient,
|
|
313
329
|
threadId: body.thread_id,
|
|
@@ -324,6 +340,7 @@ function holdReply(store) {
|
|
|
324
340
|
yield* Effect.logInfo("ontology.agent.reply_held").pipe(Effect.annotateLogs({
|
|
325
341
|
requestId,
|
|
326
342
|
provider: body.provider,
|
|
343
|
+
channel: body.channel ?? body.provider,
|
|
327
344
|
reviewId: review.id,
|
|
328
345
|
created: review.created,
|
|
329
346
|
mode: body.mode,
|