@segmentstream/ontology 0.109.0 → 0.111.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 (79) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/README.md +28 -1
  3. package/dist/agent-review.d.ts +2 -0
  4. package/dist/agent-review.js +11 -1
  5. package/dist/analyze.d.ts +34 -34
  6. package/dist/analyze.js +104 -29
  7. package/dist/chat-channel.d.ts +22 -0
  8. package/dist/chat-channel.js +35 -0
  9. package/dist/index.d.ts +8 -6
  10. package/dist/index.js +3 -2
  11. package/dist/manifest.d.ts +194 -29
  12. package/dist/manifest.js +54 -10
  13. package/dist/migrate/apply.d.ts +4 -3
  14. package/dist/migrate/apply.js +8 -3
  15. package/dist/migrate/model.d.ts +90 -2
  16. package/dist/migrate/plan.js +1 -1
  17. package/dist/migrate/preview.js +2 -1
  18. package/dist/migrate/storage.d.ts +13 -1
  19. package/dist/migrate/storage.js +33 -1
  20. package/dist/runtime/agent-counters.d.ts +36 -0
  21. package/dist/runtime/agent-counters.js +84 -0
  22. package/dist/runtime/agent-web.d.ts +1 -1
  23. package/dist/runtime/agent-web.js +175 -3
  24. package/dist/runtime/agents.js +3 -0
  25. package/dist/runtime/batch.js +4 -6
  26. package/dist/runtime/history.d.ts +24 -0
  27. package/dist/runtime/history.js +35 -1
  28. package/dist/runtime/pipeline.js +3 -0
  29. package/dist/runtime/principals.d.ts +6 -0
  30. package/dist/runtime/principals.js +25 -6
  31. package/dist/runtime/reads.js +9 -2
  32. package/dist/runtime/sign-in-links.d.ts +10 -0
  33. package/dist/runtime/sign-in-links.js +26 -25
  34. package/dist/runtime/sql-runtime.d.ts +1 -1
  35. package/dist/runtime/sql-runtime.js +3 -2
  36. package/dist/runtime/writes.js +4 -6
  37. package/dist/runtime-source.d.ts +4 -0
  38. package/dist/runtime-source.js +5 -0
  39. package/dist/runtime.d.ts +21 -0
  40. package/dist/service/agent/authentication.d.ts +3 -2
  41. package/dist/service/agent/authentication.js +2 -11
  42. package/dist/service/agent/bot-check.d.ts +42 -0
  43. package/dist/service/agent/bot-check.js +32 -0
  44. package/dist/service/agent/guest-sign-up.d.ts +140 -0
  45. package/dist/service/agent/guest-sign-up.js +545 -0
  46. package/dist/service/agent/protocol.d.ts +34 -1
  47. package/dist/service/agent/protocol.js +46 -1
  48. package/dist/service/agent/server.d.ts +17 -0
  49. package/dist/service/agent/server.js +53 -3
  50. package/dist/service/agent/web-tokens.d.ts +21 -3
  51. package/dist/service/agent/web-tokens.js +79 -6
  52. package/dist/service/authentication.d.ts +9 -1
  53. package/dist/service/authentication.js +31 -5
  54. package/dist/service/chat/delivery.js +9 -5
  55. package/dist/service/chat/envelope.d.ts +6 -0
  56. package/dist/service/chat/providers/index.d.ts +19 -9
  57. package/dist/service/chat/providers/index.js +31 -11
  58. package/dist/service/chat/reads.d.ts +6 -3
  59. package/dist/service/chat/reads.js +26 -14
  60. package/dist/service/chat/resolve.d.ts +6 -2
  61. package/dist/service/chat/resolve.js +7 -3
  62. package/dist/service/chat/review-delivery.d.ts +2 -2
  63. package/dist/service/chat/review-delivery.js +16 -8
  64. package/dist/service/chat/routes.js +2 -1
  65. package/dist/service/chat/schemas.d.ts +2 -0
  66. package/dist/service/chat/schemas.js +8 -1
  67. package/dist/service/config.d.ts +10 -0
  68. package/dist/service/mcp/server.js +2 -1
  69. package/dist/service/operations.d.ts +5 -0
  70. package/dist/service/runtime-contract.d.ts +133 -1
  71. package/dist/service/runtime-identity.d.ts +23 -0
  72. package/dist/service/runtime-identity.js +31 -0
  73. package/dist/service/schemas.d.ts +54 -2
  74. package/dist/service/service.js +27 -1
  75. package/dist/service/webhooks.d.ts +15 -0
  76. package/dist/service/webhooks.js +15 -4
  77. package/dist/sign-in.d.ts +29 -0
  78. package/dist/sign-in.js +8 -0
  79. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import type { ChatAttributionSettings } from "./chat.js";
2
+ import { CHAT_CHANNEL_KINDS } from "./chat-channel.js";
2
3
  import { Effect, Schema } from "effect";
3
4
  import type { ResolvedConnection, ResolvedEntity } from "./analyze.js";
4
5
  import type { ResolvedFeedback } from "./feedback-config.js";
@@ -73,6 +74,13 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
73
74
  * declared: the wire name of the email the platform sends instead of its own invitation. Older
74
75
  * readers ignore `sections` and `invitationEmail`, leave the two values empty and send the
75
76
  * platform's invitation.
77
+ * Within version 15, `guest` may carry `bot_check`, `{ scheme, secret }`, the challenge a new
78
+ * guest passes and the workspace secret its verification reads, and `confirmations: true`, written
79
+ * only when declared. Older readers ignore both: they ask new guests for no challenge, and keep
80
+ * refusing guests the actions that need a confirmation.
81
+ * Within version 15, `chat` may carry `channels`, written only when declared: the agent's channels
82
+ * not named after their kind, such as `sales_whatsapp`, each with its `kind` and connection. Older
83
+ * readers ignore it and send nothing through those channels.
76
84
  */
77
85
  export declare const MANIFEST_VERSION = 15;
78
86
  /** The phrase used for a direction the author did not phrase. */
@@ -634,9 +642,18 @@ export declare const SignUpManifest: Schema.Struct<{
634
642
  * permissions are the built-in `guest` role's. Read as text: channels and origins a reader does not
635
643
  * know admit nobody.
636
644
  */
637
- export declare const GuestManifest: Schema.Struct<{
645
+ export declare const GuestManifest: Schema.encodeKeys<Schema.Struct<{
638
646
  readonly channels: Schema.$Array<Schema.String>;
639
647
  readonly origins: Schema.$Array<Schema.String>;
648
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
649
+ readonly botCheck: Schema.optionalKey<Schema.Struct<{
650
+ readonly scheme: Schema.String;
651
+ readonly secret: Schema.String;
652
+ }>>;
653
+ /** Guests may confirm actions that need a confirmation. */
654
+ readonly confirmations: Schema.optionalKey<Schema.Boolean>;
655
+ }>, {
656
+ readonly botCheck: "bot_check";
640
657
  }>;
641
658
  export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
642
659
  readonly browser: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
@@ -658,9 +675,18 @@ export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
658
675
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
659
676
  }>>;
660
677
  readonly onSignUp: Schema.optionalKey<Schema.String>;
661
- readonly guest: Schema.optionalKey<Schema.Struct<{
678
+ readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
662
679
  readonly channels: Schema.$Array<Schema.String>;
663
680
  readonly origins: Schema.$Array<Schema.String>;
681
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
682
+ readonly botCheck: Schema.optionalKey<Schema.Struct<{
683
+ readonly scheme: Schema.String;
684
+ readonly secret: Schema.String;
685
+ }>>;
686
+ /** Guests may confirm actions that need a confirmation. */
687
+ readonly confirmations: Schema.optionalKey<Schema.Boolean>;
688
+ }>, {
689
+ readonly botCheck: "bot_check";
664
690
  }>>;
665
691
  /** The wire name of the email the platform sends instead of its own invitation. */
666
692
  readonly invitationEmail: Schema.optionalKey<Schema.String>;
@@ -960,9 +986,18 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
960
986
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
961
987
  }>>;
962
988
  readonly onSignUp: Schema.optionalKey<Schema.String>;
963
- readonly guest: Schema.optionalKey<Schema.Struct<{
989
+ readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
964
990
  readonly channels: Schema.$Array<Schema.String>;
965
991
  readonly origins: Schema.$Array<Schema.String>;
992
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
993
+ readonly botCheck: Schema.optionalKey<Schema.Struct<{
994
+ readonly scheme: Schema.String;
995
+ readonly secret: Schema.String;
996
+ }>>;
997
+ /** Guests may confirm actions that need a confirmation. */
998
+ readonly confirmations: Schema.optionalKey<Schema.Boolean>;
999
+ }>, {
1000
+ readonly botCheck: "bot_check";
966
1001
  }>>;
967
1002
  /** The wire name of the email the platform sends instead of its own invitation. */
968
1003
  readonly invitationEmail: Schema.optionalKey<Schema.String>;
@@ -1012,10 +1047,11 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1012
1047
  readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
1013
1048
  }>>>;
1014
1049
  /**
1015
- * The providers whose chats the built-in exact chat post delivers to, each through its declared
1016
- * connection, and the attribution it adds. Absent, or without a provider, delivers nowhere.
1017
- * `email`, within version 15, is the mailbox reviewed replies to mail leave from; no chat post
1018
- * goes to it.
1050
+ * The agent's channels whose chats the built-in exact chat post delivers to, each through its
1051
+ * declared connection, and the attribution it adds. Absent, or without a channel, delivers
1052
+ * nowhere. The channel named after each kind has its key; `channels` holds the others by name,
1053
+ * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
1054
+ * from; no chat post goes to it, nor to another channel of its kind.
1019
1055
  */
1020
1056
  readonly chat: Schema.optionalKey<Schema.Struct<{
1021
1057
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -1030,6 +1066,10 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1030
1066
  readonly email: Schema.optionalKey<Schema.Struct<{
1031
1067
  readonly connection: Schema.String;
1032
1068
  }>>;
1069
+ readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
1070
+ readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email"]>;
1071
+ readonly connection: Schema.String;
1072
+ }>>>;
1033
1073
  readonly attribution: Schema.optionalKey<Schema.Struct<{
1034
1074
  readonly template: Schema.optionalKey<Schema.String>;
1035
1075
  readonly separator: Schema.optionalKey<Schema.String>;
@@ -1281,6 +1321,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1281
1321
  readonly slack?: {
1282
1322
  readonly connection: string;
1283
1323
  } | undefined;
1324
+ readonly channels?: {
1325
+ readonly [x: string]: {
1326
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
1327
+ readonly connection: string;
1328
+ };
1329
+ } | undefined;
1284
1330
  readonly attribution?: {
1285
1331
  readonly template?: string | undefined;
1286
1332
  readonly separator?: string | undefined;
@@ -1356,6 +1402,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1356
1402
  readonly guest?: {
1357
1403
  readonly channels: readonly string[];
1358
1404
  readonly origins: readonly string[];
1405
+ readonly botCheck?: {
1406
+ readonly scheme: string;
1407
+ readonly secret: string;
1408
+ } | undefined;
1409
+ readonly confirmations?: boolean | undefined;
1359
1410
  } | undefined;
1360
1411
  readonly browser?: {
1361
1412
  readonly methods: readonly string[];
@@ -1572,6 +1623,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1572
1623
  readonly slack?: {
1573
1624
  readonly connection: string;
1574
1625
  } | undefined;
1626
+ readonly channels?: {
1627
+ readonly [x: string]: {
1628
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
1629
+ readonly connection: string;
1630
+ };
1631
+ } | undefined;
1575
1632
  readonly attribution?: {
1576
1633
  readonly template?: string | undefined;
1577
1634
  readonly separator?: string | undefined;
@@ -1647,6 +1704,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1647
1704
  readonly guest?: {
1648
1705
  readonly channels: readonly string[];
1649
1706
  readonly origins: readonly string[];
1707
+ readonly botCheck?: {
1708
+ readonly scheme: string;
1709
+ readonly secret: string;
1710
+ } | undefined;
1711
+ readonly confirmations?: boolean | undefined;
1650
1712
  } | undefined;
1651
1713
  readonly browser?: {
1652
1714
  readonly methods: readonly string[];
@@ -1863,6 +1925,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1863
1925
  readonly slack?: {
1864
1926
  readonly connection: string;
1865
1927
  } | undefined;
1928
+ readonly channels?: {
1929
+ readonly [x: string]: {
1930
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
1931
+ readonly connection: string;
1932
+ };
1933
+ } | undefined;
1866
1934
  readonly attribution?: {
1867
1935
  readonly template?: string | undefined;
1868
1936
  readonly separator?: string | undefined;
@@ -2003,6 +2071,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2003
2071
  readonly guest?: {
2004
2072
  readonly channels: readonly string[];
2005
2073
  readonly origins: readonly string[];
2074
+ readonly confirmations?: boolean | undefined;
2075
+ readonly bot_check?: {
2076
+ readonly scheme: string;
2077
+ readonly secret: string;
2078
+ } | undefined;
2006
2079
  } | undefined;
2007
2080
  readonly browser?: {
2008
2081
  readonly methods: readonly string[];
@@ -2154,6 +2227,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2154
2227
  readonly slack?: {
2155
2228
  readonly connection: string;
2156
2229
  } | undefined;
2230
+ readonly channels?: {
2231
+ readonly [x: string]: {
2232
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
2233
+ readonly connection: string;
2234
+ };
2235
+ } | undefined;
2157
2236
  readonly attribution?: {
2158
2237
  readonly template?: string | undefined;
2159
2238
  readonly separator?: string | undefined;
@@ -2229,6 +2308,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2229
2308
  readonly guest?: {
2230
2309
  readonly channels: readonly string[];
2231
2310
  readonly origins: readonly string[];
2311
+ readonly confirmations?: boolean | undefined;
2312
+ readonly bot_check?: {
2313
+ readonly scheme: string;
2314
+ readonly secret: string;
2315
+ } | undefined;
2232
2316
  } | undefined;
2233
2317
  readonly browser?: {
2234
2318
  readonly methods: readonly string[];
@@ -2518,9 +2602,18 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2518
2602
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
2519
2603
  }>>;
2520
2604
  readonly onSignUp: Schema.optionalKey<Schema.String>;
2521
- readonly guest: Schema.optionalKey<Schema.Struct<{
2605
+ readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
2522
2606
  readonly channels: Schema.$Array<Schema.String>;
2523
2607
  readonly origins: Schema.$Array<Schema.String>;
2608
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
2609
+ readonly botCheck: Schema.optionalKey<Schema.Struct<{
2610
+ readonly scheme: Schema.String;
2611
+ readonly secret: Schema.String;
2612
+ }>>;
2613
+ /** Guests may confirm actions that need a confirmation. */
2614
+ readonly confirmations: Schema.optionalKey<Schema.Boolean>;
2615
+ }>, {
2616
+ readonly botCheck: "bot_check";
2524
2617
  }>>;
2525
2618
  /** The wire name of the email the platform sends instead of its own invitation. */
2526
2619
  readonly invitationEmail: Schema.optionalKey<Schema.String>;
@@ -2570,10 +2663,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2570
2663
  readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
2571
2664
  }>>>;
2572
2665
  /**
2573
- * The providers whose chats the built-in exact chat post delivers to, each through its declared
2574
- * connection, and the attribution it adds. Absent, or without a provider, delivers nowhere.
2575
- * `email`, within version 15, is the mailbox reviewed replies to mail leave from; no chat post
2576
- * goes to it.
2666
+ * The agent's channels whose chats the built-in exact chat post delivers to, each through its
2667
+ * declared connection, and the attribution it adds. Absent, or without a channel, delivers
2668
+ * nowhere. The channel named after each kind has its key; `channels` holds the others by name,
2669
+ * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
2670
+ * from; no chat post goes to it, nor to another channel of its kind.
2577
2671
  */
2578
2672
  readonly chat: Schema.optionalKey<Schema.Struct<{
2579
2673
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -2588,6 +2682,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2588
2682
  readonly email: Schema.optionalKey<Schema.Struct<{
2589
2683
  readonly connection: Schema.String;
2590
2684
  }>>;
2685
+ readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
2686
+ readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email"]>;
2687
+ readonly connection: Schema.String;
2688
+ }>>>;
2591
2689
  readonly attribution: Schema.optionalKey<Schema.Struct<{
2592
2690
  readonly template: Schema.optionalKey<Schema.String>;
2593
2691
  readonly separator: Schema.optionalKey<Schema.String>;
@@ -2899,9 +2997,18 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2899
2997
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
2900
2998
  }>>;
2901
2999
  readonly onSignUp: Schema.optionalKey<Schema.String>;
2902
- readonly guest: Schema.optionalKey<Schema.Struct<{
3000
+ readonly guest: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
2903
3001
  readonly channels: Schema.$Array<Schema.String>;
2904
3002
  readonly origins: Schema.$Array<Schema.String>;
3003
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
3004
+ readonly botCheck: Schema.optionalKey<Schema.Struct<{
3005
+ readonly scheme: Schema.String;
3006
+ readonly secret: Schema.String;
3007
+ }>>;
3008
+ /** Guests may confirm actions that need a confirmation. */
3009
+ readonly confirmations: Schema.optionalKey<Schema.Boolean>;
3010
+ }>, {
3011
+ readonly botCheck: "bot_check";
2905
3012
  }>>;
2906
3013
  /** The wire name of the email the platform sends instead of its own invitation. */
2907
3014
  readonly invitationEmail: Schema.optionalKey<Schema.String>;
@@ -2951,10 +3058,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2951
3058
  readonly delivers: Schema.optionalKey<Schema.Literal<true>>;
2952
3059
  }>>>;
2953
3060
  /**
2954
- * The providers whose chats the built-in exact chat post delivers to, each through its declared
2955
- * connection, and the attribution it adds. Absent, or without a provider, delivers nowhere.
2956
- * `email`, within version 15, is the mailbox reviewed replies to mail leave from; no chat post
2957
- * goes to it.
3061
+ * The agent's channels whose chats the built-in exact chat post delivers to, each through its
3062
+ * declared connection, and the attribution it adds. Absent, or without a channel, delivers
3063
+ * nowhere. The channel named after each kind has its key; `channels` holds the others by name,
3064
+ * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
3065
+ * from; no chat post goes to it, nor to another channel of its kind.
2958
3066
  */
2959
3067
  readonly chat: Schema.optionalKey<Schema.Struct<{
2960
3068
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -2969,6 +3077,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2969
3077
  readonly email: Schema.optionalKey<Schema.Struct<{
2970
3078
  readonly connection: Schema.String;
2971
3079
  }>>;
3080
+ readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
3081
+ readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email"]>;
3082
+ readonly connection: Schema.String;
3083
+ }>>>;
2972
3084
  readonly attribution: Schema.optionalKey<Schema.Struct<{
2973
3085
  readonly template: Schema.optionalKey<Schema.String>;
2974
3086
  readonly separator: Schema.optionalKey<Schema.String>;
@@ -3212,6 +3324,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3212
3324
  readonly slack?: {
3213
3325
  readonly connection: string;
3214
3326
  } | undefined;
3327
+ readonly channels?: {
3328
+ readonly [x: string]: {
3329
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
3330
+ readonly connection: string;
3331
+ };
3332
+ } | undefined;
3215
3333
  readonly attribution?: {
3216
3334
  readonly template?: string | undefined;
3217
3335
  readonly separator?: string | undefined;
@@ -3287,6 +3405,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3287
3405
  readonly guest?: {
3288
3406
  readonly channels: readonly string[];
3289
3407
  readonly origins: readonly string[];
3408
+ readonly botCheck?: {
3409
+ readonly scheme: string;
3410
+ readonly secret: string;
3411
+ } | undefined;
3412
+ readonly confirmations?: boolean | undefined;
3290
3413
  } | undefined;
3291
3414
  readonly browser?: {
3292
3415
  readonly methods: readonly string[];
@@ -3503,6 +3626,12 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3503
3626
  readonly slack?: {
3504
3627
  readonly connection: string;
3505
3628
  } | undefined;
3629
+ readonly channels?: {
3630
+ readonly [x: string]: {
3631
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
3632
+ readonly connection: string;
3633
+ };
3634
+ } | undefined;
3506
3635
  readonly attribution?: {
3507
3636
  readonly template?: string | undefined;
3508
3637
  readonly separator?: string | undefined;
@@ -3578,6 +3707,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3578
3707
  readonly guest?: {
3579
3708
  readonly channels: readonly string[];
3580
3709
  readonly origins: readonly string[];
3710
+ readonly botCheck?: {
3711
+ readonly scheme: string;
3712
+ readonly secret: string;
3713
+ } | undefined;
3714
+ readonly confirmations?: boolean | undefined;
3581
3715
  } | undefined;
3582
3716
  readonly browser?: {
3583
3717
  readonly methods: readonly string[];
@@ -3800,6 +3934,12 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3800
3934
  readonly slack?: {
3801
3935
  readonly connection: string;
3802
3936
  } | undefined;
3937
+ readonly channels?: {
3938
+ readonly [x: string]: {
3939
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
3940
+ readonly connection: string;
3941
+ };
3942
+ } | undefined;
3803
3943
  readonly attribution?: {
3804
3944
  readonly template?: string | undefined;
3805
3945
  readonly separator?: string | undefined;
@@ -3875,6 +4015,11 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
3875
4015
  readonly guest?: {
3876
4016
  readonly channels: readonly string[];
3877
4017
  readonly origins: readonly string[];
4018
+ readonly botCheck?: {
4019
+ readonly scheme: string;
4020
+ readonly secret: string;
4021
+ } | undefined;
4022
+ readonly confirmations?: boolean | undefined;
3878
4023
  } | undefined;
3879
4024
  readonly browser?: {
3880
4025
  readonly methods: readonly string[];
@@ -4091,6 +4236,12 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4091
4236
  readonly slack?: {
4092
4237
  readonly connection: string;
4093
4238
  } | undefined;
4239
+ readonly channels?: {
4240
+ readonly [x: string]: {
4241
+ readonly kind: "telegram" | "email" | "whatsapp" | "slack";
4242
+ readonly connection: string;
4243
+ };
4244
+ } | undefined;
4094
4245
  readonly attribution?: {
4095
4246
  readonly template?: string | undefined;
4096
4247
  readonly separator?: string | undefined;
@@ -4166,6 +4317,11 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4166
4317
  readonly guest?: {
4167
4318
  readonly channels: readonly string[];
4168
4319
  readonly origins: readonly string[];
4320
+ readonly botCheck?: {
4321
+ readonly scheme: string;
4322
+ readonly secret: string;
4323
+ } | undefined;
4324
+ readonly confirmations?: boolean | undefined;
4169
4325
  } | undefined;
4170
4326
  readonly browser?: {
4171
4327
  readonly methods: readonly string[];
@@ -4293,21 +4449,30 @@ export declare function manifestHash(manifest: Readonly<Record<string, unknown>>
4293
4449
  * aggregates, top-level or inside arithmetic: `check` lets them name one property at most.
4294
4450
  */
4295
4451
  export declare function metricsManifest(resolved: ResolvedEntity): ReadonlyArray<MetricManifest>;
4452
+ /** `chat` as the manifest writes it: the channel of each kind, the other channels, attribution. */
4453
+ export interface ChatManifestInput {
4454
+ readonly telegram?: {
4455
+ readonly connection: string;
4456
+ };
4457
+ readonly slack?: {
4458
+ readonly connection: string;
4459
+ };
4460
+ readonly whatsapp?: {
4461
+ readonly connection: string;
4462
+ };
4463
+ readonly email?: {
4464
+ readonly connection: string;
4465
+ };
4466
+ readonly channels?: Readonly<Record<string, {
4467
+ readonly kind: (typeof CHAT_CHANNEL_KINDS)[number];
4468
+ readonly connection: string;
4469
+ }>>;
4470
+ readonly attribution?: ChatAttributionSettings;
4471
+ }
4296
4472
  /** Builds the manifest of a resolved ontology that passed `check`. */
4297
4473
  export declare function buildManifest(input: {
4298
4474
  readonly feedback?: ResolvedFeedback;
4299
- readonly chat?: {
4300
- readonly telegram?: {
4301
- readonly connection: string;
4302
- };
4303
- readonly slack?: {
4304
- readonly connection: string;
4305
- };
4306
- readonly whatsapp?: {
4307
- readonly connection: string;
4308
- };
4309
- readonly attribution?: ChatAttributionSettings;
4310
- };
4475
+ readonly chat?: ChatManifestInput;
4311
4476
  readonly entities: ReadonlyArray<ResolvedEntity>;
4312
4477
  readonly roles: ReadonlyArray<Role>;
4313
4478
  readonly signIn: ResolvedSignInOptions;
package/dist/manifest.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME } 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";
4
5
  import { humanize, MEMBER_ROLE, FEEDBACK_REPORTER_ROLE, GUEST_ROLE } from "./names.js";
5
6
  import { PROPERTY_TYPES } from "./property.js";
6
7
  import { ON_DELETE } from "./relationship.js";
7
- import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
8
+ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
8
9
  /**
9
10
  * The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
10
11
  * 2 replaced the actions' `allow` with `permission`, and added the roles' `permissions` and the
@@ -73,6 +74,13 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestChannel, isSignInPoli
73
74
  * declared: the wire name of the email the platform sends instead of its own invitation. Older
74
75
  * readers ignore `sections` and `invitationEmail`, leave the two values empty and send the
75
76
  * platform's invitation.
77
+ * Within version 15, `guest` may carry `bot_check`, `{ scheme, secret }`, the challenge a new
78
+ * guest passes and the workspace secret its verification reads, and `confirmations: true`, written
79
+ * only when declared. Older readers ignore both: they ask new guests for no challenge, and keep
80
+ * refusing guests the actions that need a confirmation.
81
+ * Within version 15, `chat` may carry `channels`, written only when declared: the agent's channels
82
+ * not named after their kind, such as `sales_whatsapp`, each with its `kind` and connection. Older
83
+ * readers ignore it and send nothing through those channels.
76
84
  */
77
85
  export const MANIFEST_VERSION = 15;
78
86
  /** The first version whose documents use snake_case names on the wire. */
@@ -415,7 +423,11 @@ export const SignUpManifest = Schema.Struct({
415
423
  export const GuestManifest = Schema.Struct({
416
424
  channels: Schema.Array(Schema.String),
417
425
  origins: Schema.Array(Schema.String),
418
- });
426
+ /** The challenge a new guest passes, and the workspace secret holding its secret key. */
427
+ botCheck: Schema.optionalKey(Schema.Struct({ scheme: Schema.String, secret: Schema.String })),
428
+ /** Guests may confirm actions that need a confirmation. */
429
+ confirmations: Schema.optionalKey(Schema.Boolean),
430
+ }).pipe(Schema.encodeKeys({ botCheck: "bot_check" }));
419
431
  export const SignInManifest = Schema.Struct({
420
432
  browser: Schema.optionalKey(BrowserSignInManifest),
421
433
  policy: Schema.String,
@@ -487,16 +499,21 @@ const OntologyManifestModel = Schema.Struct({
487
499
  /** The connections the actions call. Written only when there are some; absent reads as none. */
488
500
  connections: Schema.optionalKey(Schema.Array(ConnectionManifest)),
489
501
  /**
490
- * The providers whose chats the built-in exact chat post delivers to, each through its declared
491
- * connection, and the attribution it adds. Absent, or without a provider, delivers nowhere.
492
- * `email`, within version 15, is the mailbox reviewed replies to mail leave from; no chat post
493
- * goes to it.
502
+ * The agent's channels whose chats the built-in exact chat post delivers to, each through its
503
+ * declared connection, and the attribution it adds. Absent, or without a channel, delivers
504
+ * nowhere. The channel named after each kind has its key; `channels` holds the others by name,
505
+ * with their kinds. `email`, within version 15, is the mailbox reviewed replies to mail leave
506
+ * from; no chat post goes to it, nor to another channel of its kind.
494
507
  */
495
508
  chat: Schema.optionalKey(Schema.Struct({
496
509
  telegram: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
497
510
  slack: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
498
511
  whatsapp: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
499
512
  email: Schema.optionalKey(Schema.Struct({ connection: Schema.String })),
513
+ channels: Schema.optionalKey(Schema.Record(Schema.String.check(Schema.isPattern(CHAT_CHANNEL_NAME)), Schema.Struct({
514
+ kind: Schema.Literals(CHAT_CHANNEL_KINDS),
515
+ connection: Schema.String,
516
+ }))),
500
517
  attribution: Schema.optionalKey(Schema.Struct({
501
518
  template: Schema.optionalKey(Schema.String),
502
519
  separator: Schema.optionalKey(Schema.String),
@@ -622,7 +639,7 @@ export function guestOf(manifest) {
622
639
  if (typeof declared !== "object" || declared === null) {
623
640
  return undefined;
624
641
  }
625
- const { channels, origins } = declared;
642
+ const { channels, origins, botCheck, confirmations } = declared;
626
643
  const known = Array.isArray(channels) ? channels.filter(isGuestChannel) : [];
627
644
  const websites = Array.isArray(origins)
628
645
  ? origins.flatMap((candidate) => {
@@ -630,9 +647,27 @@ export function guestOf(manifest) {
630
647
  return origin === undefined ? [] : [origin];
631
648
  })
632
649
  : [];
633
- return known.length === 0 || websites.length === 0
634
- ? undefined
635
- : { channels: [...new Set(known)], origins: websites };
650
+ const check = botCheck;
651
+ if (known.length === 0 || websites.length === 0) {
652
+ return undefined;
653
+ }
654
+ // A bot check this reader cannot verify admits no new guest, rather than none without a check.
655
+ if (check !== undefined &&
656
+ (typeof check !== "object" ||
657
+ check === null ||
658
+ !isGuestBotCheckScheme(check.scheme) ||
659
+ typeof check.secret !== "string" ||
660
+ check.secret === "")) {
661
+ return undefined;
662
+ }
663
+ return {
664
+ channels: [...new Set(known)],
665
+ origins: websites,
666
+ ...(check === undefined
667
+ ? {}
668
+ : { botCheck: { scheme: check.scheme, secret: check.secret } }),
669
+ ...(confirmations === true ? { confirmations: true } : {}),
670
+ };
636
671
  }
637
672
  // @legacy ontology.legacy-channel-admission
638
673
  /** Unsupported providers and missing or unknown channel policies require invitation. */
@@ -899,6 +934,15 @@ export function buildManifest(input) {
899
934
  guest: {
900
935
  channels: [...input.signIn.guest.channels],
901
936
  origins: [...input.signIn.guest.origins],
937
+ ...(input.signIn.guest.botCheck === undefined
938
+ ? {}
939
+ : {
940
+ botCheck: {
941
+ scheme: input.signIn.guest.botCheck.scheme,
942
+ secret: input.signIn.guest.botCheck.secret,
943
+ },
944
+ }),
945
+ ...(input.signIn.guest.confirmations === true ? { confirmations: true } : {}),
902
946
  },
903
947
  }),
904
948
  },
@@ -88,9 +88,10 @@ export declare const RUNTIME_TABLES: ReadonlyArray<string>;
88
88
  * The runtime tables the database has, for `planMigration`'s `existingTables`: a database that an
89
89
  * earlier SDK migrated lacks the tables added since.
90
90
  * A grants table without app-session binding is reported incomplete so the idempotent OAuth DDL
91
- * also upgrades an unchanged manifest, and so is an API keys table without `delegation` and an
92
- * attachments table whose source check predates one of {@link ATTACHMENT_SOURCES}, which the
93
- * idempotent API key and attachment DDL add and widen.
91
+ * also upgrades an unchanged manifest, and so is an action attribution table without `chat`, an
92
+ * API keys table without `delegation` and an attachments table whose source check predates one of
93
+ * {@link ATTACHMENT_SOURCES}, which the idempotent attribution, API key and attachment DDL add and
94
+ * widen.
94
95
  */
95
96
  export declare const readRuntimeTables: (input: CatalogInput) => Effect.Effect<ReadonlySet<string>, SqlError>;
96
97
  /** Only valid, complete covering indexes satisfy the upgrade; failed builds are retried. */
@@ -491,9 +491,10 @@ export const RUNTIME_TABLES = [
491
491
  * The runtime tables the database has, for `planMigration`'s `existingTables`: a database that an
492
492
  * earlier SDK migrated lacks the tables added since.
493
493
  * A grants table without app-session binding is reported incomplete so the idempotent OAuth DDL
494
- * also upgrades an unchanged manifest, and so is an API keys table without `delegation` and an
495
- * attachments table whose source check predates one of {@link ATTACHMENT_SOURCES}, which the
496
- * idempotent API key and attachment DDL add and widen.
494
+ * also upgrades an unchanged manifest, and so is an action attribution table without `chat`, an
495
+ * API keys table without `delegation` and an attachments table whose source check predates one of
496
+ * {@link ATTACHMENT_SOURCES}, which the idempotent attribution, API key and attachment DDL add and
497
+ * widen.
497
498
  */
498
499
  export const readRuntimeTables = (input) => input.sql
499
500
  .unsafe(`SELECT "tablename" AS "name" FROM "pg_catalog"."pg_tables" ` +
@@ -513,6 +514,10 @@ export const readRuntimeTables = (input) => input.sql
513
514
  `AND ("tablename" <> ${quoteLiteral(CHANNEL_USERS_TABLE)} OR EXISTS (` +
514
515
  `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
515
516
  `AND table_name = ${quoteLiteral(CHANNEL_USERS_TABLE)} AND column_name = 'signed_up')) ` +
517
+ // Without `chat` the attribution DDL runs again and adds it.
518
+ `AND ("tablename" <> ${quoteLiteral(ACTION_ATTRIBUTION_TABLE)} OR EXISTS (` +
519
+ `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
520
+ `AND table_name = ${quoteLiteral(ACTION_ATTRIBUTION_TABLE)} AND column_name = 'chat')) ` +
516
521
  `AND ("tablename" <> ${quoteLiteral(API_KEYS_TABLE)} OR EXISTS (` +
517
522
  `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
518
523
  `AND table_name = ${quoteLiteral(API_KEYS_TABLE)} AND column_name = 'delegation')) ` +