@segmentstream/ontology 0.167.0 → 0.168.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.168.0
4
+
5
+ A mailbox in `chat` takes `signature: true` beside its connection: the ontology's replies to mail,
6
+ a draft a member approves and a staff reply from the inbox, end their HTML with the mailbox's own
7
+ signature, as its owner set it in Gmail for its address. The signature is read through the
8
+ connection with `users.settings.sendAs` and kept for 10 minutes per mailbox; a reply whose
9
+ signature Gmail refuses to read goes unsigned. Off when absent; `check` refuses it on a channel
10
+ that is no mailbox.
11
+
12
+ `@segmentstream/ontology/email` exports the reader the agent shares, `mailboxSignature` (and
13
+ `mailboxSignatures` for a reader with its own clock), and `withEmailSignature`.
14
+
3
15
  ## 0.167.0
4
16
 
5
17
  Staff answer an email thread's chat (`chats: "thread"`) from the inbox. `agent_chat.postMessage`,
package/dist/analyze.d.ts CHANGED
@@ -273,6 +273,12 @@ export interface ChatChannelConfig {
273
273
  * long as the chat's messages (`retentionDays`); otherwise it expires 24 hours after it arrives.
274
274
  */
275
275
  readonly files?: ChatFilesConfig;
276
+ /**
277
+ * On a mailbox (`kind` `email`) only: whether the ontology's replies to mail, a draft a member
278
+ * approves and staff's replies from the inbox, end with the mailbox's own signature, as the
279
+ * mailbox's owner set it in Gmail. Off when absent.
280
+ */
281
+ readonly signature?: boolean;
276
282
  }
277
283
  /** `files` of a chat channel: whether its chats keep their files with their messages. */
278
284
  export interface ChatFilesConfig {
@@ -298,6 +304,8 @@ export interface ChatConfig {
298
304
  readonly email?: {
299
305
  readonly connection: AnyConnectionHandle;
300
306
  readonly files?: ChatFilesConfig;
307
+ /** Whether replies to mail end with the mailbox's own signature; see {@link ChatChannelConfig}. */
308
+ readonly signature?: boolean;
301
309
  };
302
310
  readonly attribution?: ChatAttributionSettings;
303
311
  /**
package/dist/analyze.js CHANGED
@@ -192,7 +192,10 @@ export function analyze(config, options = {}) {
192
192
  const malformed = entries.find(([name, value]) => {
193
193
  const named = !CHAT_PROVIDER_KEYS.includes(name);
194
194
  return (!isPlainObject(value) ||
195
- Object.keys(value).some((key) => key !== "connection" && key !== "kind" && key !== "files") ||
195
+ Object.keys(value).some((key) => key !== "connection" && key !== "kind" && key !== "files" && key !== "signature") ||
196
+ // Only a mailbox has a signature of its own.
197
+ (value.signature !== undefined &&
198
+ (typeof value.signature !== "boolean" || (named ? value.kind : name) !== "email")) ||
196
199
  (value.files !== undefined &&
197
200
  (!isPlainObject(value.files) ||
198
201
  Object.keys(value.files).some((key) => key !== "keep") ||
@@ -213,11 +216,14 @@ export function analyze(config, options = {}) {
213
216
  entry.connection,
214
217
  entry.kind ?? name,
215
218
  entry.files?.keep === true,
219
+ entry.signature === true,
216
220
  ];
217
221
  })
218
222
  : [];
219
223
  // Written only for a channel that keeps its files: older readers keep none.
220
224
  const keptFiles = (keep) => (keep ? { files: { keep: true } } : {});
225
+ // Written only for a mailbox that signs its replies: older readers sign none.
226
+ const signed = (signature) => (signature ? { signature: true } : {});
221
227
  const handles = channels.flatMap(([name, handle, kind]) => handle === undefined ? [] : [[name, handle, kind]]);
222
228
  const unlisted = handles.find(([, handle]) => !(config.connections ?? []).includes(handle));
223
229
  const shared = handles.find(([, handle], index) => handles.findIndex(([, other]) => other === handle) !== index);
@@ -230,7 +236,7 @@ export function analyze(config, options = {}) {
230
236
  report("invalid-connection", "chat", `chat.${malformed}.connection must reference a declared connection handle, and a ` +
231
237
  `channel not named after its kind needs kind: ${CHAT_KINDS.join(", ")}; a ` +
232
238
  `${WORKSPACE_CHANNEL_KIND} channel takes none, as the agent sends through it. ` +
233
- `files takes keep, true or false.`);
239
+ `files takes keep, true or false, and a mailbox (email) takes signature, true or false.`);
234
240
  }
235
241
  else if (unlisted !== undefined) {
236
242
  report("invalid-connection", `chat.${unlisted[0]}.connection`, "The chat channel connection must be listed in connections.");
@@ -243,16 +249,19 @@ export function analyze(config, options = {}) {
243
249
  chat = {
244
250
  ...Object.fromEntries(channels
245
251
  .filter(([name]) => CHAT_PROVIDER_KEYS.includes(name))
246
- .flatMap(([name, handle, , keep]) => handle === undefined ? [] : [[name, { connection: handle.key, ...keptFiles(keep) }]])),
252
+ .flatMap(([name, handle, , keep, signature]) => handle === undefined
253
+ ? []
254
+ : [[name, { connection: handle.key, ...keptFiles(keep), ...signed(signature) }]])),
247
255
  ...(named.length === 0
248
256
  ? {}
249
257
  : {
250
- channels: Object.fromEntries(named.map(([name, handle, kind, keep]) => [
258
+ channels: Object.fromEntries(named.map(([name, handle, kind, keep, signature]) => [
251
259
  name,
252
260
  {
253
261
  kind,
254
262
  ...(handle === undefined ? {} : { connection: handle.key }),
255
263
  ...keptFiles(keep),
264
+ ...signed(signature),
256
265
  },
257
266
  ])),
258
267
  }),
package/dist/email.d.ts CHANGED
@@ -48,6 +48,11 @@ export declare const EMAIL_ATTACHMENTS_LIMIT = 25000000;
48
48
  * carry no markup, image or script the platform did not render from Markdown itself.
49
49
  */
50
50
  export declare function renderEmailHtml(text: string): string;
51
+ /**
52
+ * A reply's HTML ending with the mailbox's own signature, as the mailbox's owner wrote it in their
53
+ * mail program: the platform adds no words, separator or quoted mail of its own.
54
+ */
55
+ export declare function withEmailSignature(html: string, signature: string | undefined): string;
51
56
  /** The subject a reply in a thread carries: the thread's own, prefixed `Re:` once. */
52
57
  export declare function replySubject(subject: string | null | undefined): string;
53
58
  /** A file a reply carries. */
@@ -98,4 +103,4 @@ export declare function emailReplyMessage(reply: EmailReply): string;
98
103
  /** Bytes as URL-safe base64 without padding, as the Gmail API takes a raw message. */
99
104
  export declare function base64Url(text: string): string;
100
105
  export type { ChannelCall, ChannelReply, ChannelRequest } from "./channel-files.js";
101
- export { EMAIL_FILES_BYTES, GmailError, gmailExplanation, GmailMaybeSent, gmailJson, sendGmailMessage, } from "./gmail-send.js";
106
+ export { EMAIL_FILES_BYTES, GmailError, gmailExplanation, GmailMaybeSent, gmailJson, mailboxSignature, mailboxSignatures, MAILBOX_SIGNATURE_LIFETIME_MS, sendGmailMessage, } from "./gmail-send.js";
package/dist/email.js CHANGED
@@ -178,6 +178,18 @@ export function renderEmailHtml(text) {
178
178
  const body = markdown.parse(text);
179
179
  return `<!doctype html><html><body>${body}</body></html>`;
180
180
  }
181
+ /**
182
+ * A reply's HTML ending with the mailbox's own signature, as the mailbox's owner wrote it in their
183
+ * mail program: the platform adds no words, separator or quoted mail of its own.
184
+ */
185
+ export function withEmailSignature(html, signature) {
186
+ if (signature === undefined || signature.trim() === "") {
187
+ return html;
188
+ }
189
+ const block = `<br><div>${signature}</div>`;
190
+ const end = html.lastIndexOf("</body>");
191
+ return end === -1 ? `${html}${block}` : `${html.slice(0, end)}${block}${html.slice(end)}`;
192
+ }
181
193
  /** The subject a reply in a thread carries: the thread's own, prefixed `Re:` once. */
182
194
  export function replySubject(subject) {
183
195
  const flat = (subject ?? "").replace(/[\r\n]+/g, " ").trim();
@@ -302,4 +314,4 @@ export function emailReplyMessage(reply) {
302
314
  export function base64Url(text) {
303
315
  return Buffer.from(text, "utf8").toString("base64url");
304
316
  }
305
- export { EMAIL_FILES_BYTES, GmailError, gmailExplanation, GmailMaybeSent, gmailJson, sendGmailMessage, } from "./gmail-send.js";
317
+ export { EMAIL_FILES_BYTES, GmailError, gmailExplanation, GmailMaybeSent, gmailJson, mailboxSignature, mailboxSignatures, MAILBOX_SIGNATURE_LIFETIME_MS, sendGmailMessage, } from "./gmail-send.js";
@@ -47,3 +47,23 @@ export declare function sendGmailMessage(options: {
47
47
  readonly message: Uint8Array;
48
48
  readonly threadId: string;
49
49
  }): Promise<Record<string, unknown>>;
50
+ /** How long a mailbox's signature is kept before it is read from Gmail again. */
51
+ export declare const MAILBOX_SIGNATURE_LIFETIME_MS: number;
52
+ /**
53
+ * A reader of mailboxes' own signatures, each kept for {@link MAILBOX_SIGNATURE_LIFETIME_MS} by its
54
+ * `mailbox` key, such as the connection's name. It reads the mailbox's send-as addresses
55
+ * (`users.settings.sendAs.list`, which `gmail.readonly` and `gmail.settings.basic` both cover) and
56
+ * resolves the signature of its own address, the primary one replies leave from, or `undefined`
57
+ * when it has none. Throws {@link GmailError} when Gmail refuses the read; a failed read is not kept.
58
+ */
59
+ export declare function mailboxSignatures(options?: {
60
+ readonly now?: () => number;
61
+ }): (input: {
62
+ readonly request: ChannelRequest;
63
+ readonly mailbox: string;
64
+ }) => Promise<string | undefined>;
65
+ /** The process's reader of mailboxes' signatures, which the agent's and the ontology's mail share. */
66
+ export declare const mailboxSignature: (input: {
67
+ readonly request: ChannelRequest;
68
+ readonly mailbox: string;
69
+ }) => Promise<string | undefined>;
@@ -199,3 +199,48 @@ export async function sendGmailMessage(options) {
199
199
  offset = held === undefined ? 0 : Number(held) + 1;
200
200
  }
201
201
  }
202
+ /** How long a mailbox's signature is kept before it is read from Gmail again. */
203
+ export const MAILBOX_SIGNATURE_LIFETIME_MS = 10 * 60 * 1000;
204
+ /** How many mailboxes' signatures one process keeps; the oldest read is forgotten first. */
205
+ const MAILBOX_SIGNATURES_KEPT = 100;
206
+ /**
207
+ * A reader of mailboxes' own signatures, each kept for {@link MAILBOX_SIGNATURE_LIFETIME_MS} by its
208
+ * `mailbox` key, such as the connection's name. It reads the mailbox's send-as addresses
209
+ * (`users.settings.sendAs.list`, which `gmail.readonly` and `gmail.settings.basic` both cover) and
210
+ * resolves the signature of its own address, the primary one replies leave from, or `undefined`
211
+ * when it has none. Throws {@link GmailError} when Gmail refuses the read; a failed read is not kept.
212
+ */
213
+ export function mailboxSignatures(options = {}) {
214
+ const now = options.now ?? Date.now;
215
+ const kept = new Map();
216
+ return async (input) => {
217
+ const found = kept.get(input.mailbox);
218
+ if (found !== undefined && found.until > now()) {
219
+ return found.signature;
220
+ }
221
+ const reply = await input.request({
222
+ api: "gmail",
223
+ method: "GET",
224
+ path: "/users/me/settings/sendAs",
225
+ headers: [],
226
+ body: new Uint8Array(),
227
+ });
228
+ if (reply.status < 200 || reply.status >= 300) {
229
+ throw new GmailError("settings.sendAs.list", reply.status, gmailExplanation(reply));
230
+ }
231
+ const addresses = gmailJson(reply).sendAs;
232
+ const own = (Array.isArray(addresses) ? addresses : []).find((address) => address?.isPrimary === true);
233
+ const signature = typeof own?.signature === "string" && own.signature.trim() !== "" ? own.signature : undefined;
234
+ kept.delete(input.mailbox);
235
+ kept.set(input.mailbox, { signature, until: now() + MAILBOX_SIGNATURE_LIFETIME_MS });
236
+ for (const mailbox of kept.keys()) {
237
+ if (kept.size <= MAILBOX_SIGNATURES_KEPT) {
238
+ break;
239
+ }
240
+ kept.delete(mailbox);
241
+ }
242
+ return signature;
243
+ };
244
+ }
245
+ /** The process's reader of mailboxes' signatures, which the agent's and the ontology's mail share. */
246
+ export const mailboxSignature = mailboxSignatures();
@@ -108,6 +108,8 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
108
108
  * Within version 16, `inbox` may carry `channels`, written only when declared: the channels whose
109
109
  * chats with people who are no users the agent registers as `agent_chat` records of kind
110
110
  * `private` without members. Older readers ignore it and register no chat without members.
111
+ * Within version 16, a mailbox in `chat` may carry `signature: true`, written only when declared:
112
+ * the ontology's replies to mail end with the mailbox's own signature. Older readers ignore it.
111
113
  */
112
114
  export declare const MANIFEST_VERSION = 16;
113
115
  /** The phrase used for a direction the author did not phrase. */
@@ -1300,7 +1302,10 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1300
1302
  * staff's replies in the inbox leave from; no other chat post goes to it, nor to another channel
1301
1303
  * of its kind. Within version 16, a
1302
1304
  * channel may carry `files: { keep: true }`, written only when declared: its chats keep their
1303
- * files as long as their messages. Older readers ignore it and keep files 24 hours.
1305
+ * files as long as their messages. Older readers ignore it and keep files 24 hours. Within
1306
+ * version 16, a mailbox (`email`, or a channel of that kind) may carry `signature: true`, written
1307
+ * only when declared: the ontology's replies to mail end with the mailbox's own signature. Older
1308
+ * readers ignore it and send them unsigned.
1304
1309
  */
1305
1310
  readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
1306
1311
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -1308,24 +1313,28 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1308
1313
  readonly files: Schema.optionalKey<Schema.Struct<{
1309
1314
  readonly keep: Schema.Boolean;
1310
1315
  }>>;
1316
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
1311
1317
  }>>;
1312
1318
  readonly slack: Schema.optionalKey<Schema.Struct<{
1313
1319
  readonly connection: Schema.String;
1314
1320
  readonly files: Schema.optionalKey<Schema.Struct<{
1315
1321
  readonly keep: Schema.Boolean;
1316
1322
  }>>;
1323
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
1317
1324
  }>>;
1318
1325
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
1319
1326
  readonly connection: Schema.String;
1320
1327
  readonly files: Schema.optionalKey<Schema.Struct<{
1321
1328
  readonly keep: Schema.Boolean;
1322
1329
  }>>;
1330
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
1323
1331
  }>>;
1324
1332
  readonly email: Schema.optionalKey<Schema.Struct<{
1325
1333
  readonly connection: Schema.String;
1326
1334
  readonly files: Schema.optionalKey<Schema.Struct<{
1327
1335
  readonly keep: Schema.Boolean;
1328
1336
  }>>;
1337
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
1329
1338
  }>>;
1330
1339
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
1331
1340
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -1333,6 +1342,7 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1333
1342
  readonly files: Schema.optionalKey<Schema.Struct<{
1334
1343
  readonly keep: Schema.Boolean;
1335
1344
  }>>;
1345
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
1336
1346
  }>>>;
1337
1347
  readonly attribution: Schema.optionalKey<Schema.Struct<{
1338
1348
  readonly template: Schema.optionalKey<Schema.String>;
@@ -1647,24 +1657,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1647
1657
  readonly files?: {
1648
1658
  readonly keep: boolean;
1649
1659
  } | undefined;
1660
+ readonly signature?: boolean | undefined;
1650
1661
  } | undefined;
1651
1662
  readonly slack?: {
1652
1663
  readonly connection: string;
1653
1664
  readonly files?: {
1654
1665
  readonly keep: boolean;
1655
1666
  } | undefined;
1667
+ readonly signature?: boolean | undefined;
1656
1668
  } | undefined;
1657
1669
  readonly whatsapp?: {
1658
1670
  readonly connection: string;
1659
1671
  readonly files?: {
1660
1672
  readonly keep: boolean;
1661
1673
  } | undefined;
1674
+ readonly signature?: boolean | undefined;
1662
1675
  } | undefined;
1663
1676
  readonly email?: {
1664
1677
  readonly connection: string;
1665
1678
  readonly files?: {
1666
1679
  readonly keep: boolean;
1667
1680
  } | undefined;
1681
+ readonly signature?: boolean | undefined;
1668
1682
  } | undefined;
1669
1683
  readonly channels?: {
1670
1684
  readonly [x: string]: {
@@ -1673,6 +1687,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1673
1687
  readonly keep: boolean;
1674
1688
  } | undefined;
1675
1689
  readonly connection?: string | undefined;
1690
+ readonly signature?: boolean | undefined;
1676
1691
  };
1677
1692
  } | undefined;
1678
1693
  readonly attribution?: {
@@ -2019,24 +2034,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2019
2034
  readonly files?: {
2020
2035
  readonly keep: boolean;
2021
2036
  } | undefined;
2037
+ readonly signature?: boolean | undefined;
2022
2038
  } | undefined;
2023
2039
  readonly slack?: {
2024
2040
  readonly connection: string;
2025
2041
  readonly files?: {
2026
2042
  readonly keep: boolean;
2027
2043
  } | undefined;
2044
+ readonly signature?: boolean | undefined;
2028
2045
  } | undefined;
2029
2046
  readonly whatsapp?: {
2030
2047
  readonly connection: string;
2031
2048
  readonly files?: {
2032
2049
  readonly keep: boolean;
2033
2050
  } | undefined;
2051
+ readonly signature?: boolean | undefined;
2034
2052
  } | undefined;
2035
2053
  readonly email?: {
2036
2054
  readonly connection: string;
2037
2055
  readonly files?: {
2038
2056
  readonly keep: boolean;
2039
2057
  } | undefined;
2058
+ readonly signature?: boolean | undefined;
2040
2059
  } | undefined;
2041
2060
  readonly channels?: {
2042
2061
  readonly [x: string]: {
@@ -2045,6 +2064,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2045
2064
  readonly keep: boolean;
2046
2065
  } | undefined;
2047
2066
  readonly connection?: string | undefined;
2067
+ readonly signature?: boolean | undefined;
2048
2068
  };
2049
2069
  } | undefined;
2050
2070
  readonly attribution?: {
@@ -2391,24 +2411,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2391
2411
  readonly files?: {
2392
2412
  readonly keep: boolean;
2393
2413
  } | undefined;
2414
+ readonly signature?: boolean | undefined;
2394
2415
  } | undefined;
2395
2416
  readonly slack?: {
2396
2417
  readonly connection: string;
2397
2418
  readonly files?: {
2398
2419
  readonly keep: boolean;
2399
2420
  } | undefined;
2421
+ readonly signature?: boolean | undefined;
2400
2422
  } | undefined;
2401
2423
  readonly whatsapp?: {
2402
2424
  readonly connection: string;
2403
2425
  readonly files?: {
2404
2426
  readonly keep: boolean;
2405
2427
  } | undefined;
2428
+ readonly signature?: boolean | undefined;
2406
2429
  } | undefined;
2407
2430
  readonly email?: {
2408
2431
  readonly connection: string;
2409
2432
  readonly files?: {
2410
2433
  readonly keep: boolean;
2411
2434
  } | undefined;
2435
+ readonly signature?: boolean | undefined;
2412
2436
  } | undefined;
2413
2437
  readonly channels?: {
2414
2438
  readonly [x: string]: {
@@ -2417,6 +2441,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2417
2441
  readonly keep: boolean;
2418
2442
  } | undefined;
2419
2443
  readonly connection?: string | undefined;
2444
+ readonly signature?: boolean | undefined;
2420
2445
  };
2421
2446
  } | undefined;
2422
2447
  readonly attribution?: {
@@ -2763,24 +2788,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2763
2788
  readonly files?: {
2764
2789
  readonly keep: boolean;
2765
2790
  } | undefined;
2791
+ readonly signature?: boolean | undefined;
2766
2792
  } | undefined;
2767
2793
  readonly slack?: {
2768
2794
  readonly connection: string;
2769
2795
  readonly files?: {
2770
2796
  readonly keep: boolean;
2771
2797
  } | undefined;
2798
+ readonly signature?: boolean | undefined;
2772
2799
  } | undefined;
2773
2800
  readonly whatsapp?: {
2774
2801
  readonly connection: string;
2775
2802
  readonly files?: {
2776
2803
  readonly keep: boolean;
2777
2804
  } | undefined;
2805
+ readonly signature?: boolean | undefined;
2778
2806
  } | undefined;
2779
2807
  readonly email?: {
2780
2808
  readonly connection: string;
2781
2809
  readonly files?: {
2782
2810
  readonly keep: boolean;
2783
2811
  } | undefined;
2812
+ readonly signature?: boolean | undefined;
2784
2813
  } | undefined;
2785
2814
  readonly channels?: {
2786
2815
  readonly [x: string]: {
@@ -2789,6 +2818,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2789
2818
  readonly keep: boolean;
2790
2819
  } | undefined;
2791
2820
  readonly connection?: string | undefined;
2821
+ readonly signature?: boolean | undefined;
2792
2822
  };
2793
2823
  } | undefined;
2794
2824
  readonly attribution?: {
@@ -3306,7 +3336,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3306
3336
  * staff's replies in the inbox leave from; no other chat post goes to it, nor to another channel
3307
3337
  * of its kind. Within version 16, a
3308
3338
  * channel may carry `files: { keep: true }`, written only when declared: its chats keep their
3309
- * files as long as their messages. Older readers ignore it and keep files 24 hours.
3339
+ * files as long as their messages. Older readers ignore it and keep files 24 hours. Within
3340
+ * version 16, a mailbox (`email`, or a channel of that kind) may carry `signature: true`, written
3341
+ * only when declared: the ontology's replies to mail end with the mailbox's own signature. Older
3342
+ * readers ignore it and send them unsigned.
3310
3343
  */
3311
3344
  readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
3312
3345
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -3314,24 +3347,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3314
3347
  readonly files: Schema.optionalKey<Schema.Struct<{
3315
3348
  readonly keep: Schema.Boolean;
3316
3349
  }>>;
3350
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3317
3351
  }>>;
3318
3352
  readonly slack: Schema.optionalKey<Schema.Struct<{
3319
3353
  readonly connection: Schema.String;
3320
3354
  readonly files: Schema.optionalKey<Schema.Struct<{
3321
3355
  readonly keep: Schema.Boolean;
3322
3356
  }>>;
3357
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3323
3358
  }>>;
3324
3359
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
3325
3360
  readonly connection: Schema.String;
3326
3361
  readonly files: Schema.optionalKey<Schema.Struct<{
3327
3362
  readonly keep: Schema.Boolean;
3328
3363
  }>>;
3364
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3329
3365
  }>>;
3330
3366
  readonly email: Schema.optionalKey<Schema.Struct<{
3331
3367
  readonly connection: Schema.String;
3332
3368
  readonly files: Schema.optionalKey<Schema.Struct<{
3333
3369
  readonly keep: Schema.Boolean;
3334
3370
  }>>;
3371
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3335
3372
  }>>;
3336
3373
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
3337
3374
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -3339,6 +3376,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3339
3376
  readonly files: Schema.optionalKey<Schema.Struct<{
3340
3377
  readonly keep: Schema.Boolean;
3341
3378
  }>>;
3379
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3342
3380
  }>>>;
3343
3381
  readonly attribution: Schema.optionalKey<Schema.Struct<{
3344
3382
  readonly template: Schema.optionalKey<Schema.String>;
@@ -3810,7 +3848,10 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3810
3848
  * staff's replies in the inbox leave from; no other chat post goes to it, nor to another channel
3811
3849
  * of its kind. Within version 16, a
3812
3850
  * channel may carry `files: { keep: true }`, written only when declared: its chats keep their
3813
- * files as long as their messages. Older readers ignore it and keep files 24 hours.
3851
+ * files as long as their messages. Older readers ignore it and keep files 24 hours. Within
3852
+ * version 16, a mailbox (`email`, or a channel of that kind) may carry `signature: true`, written
3853
+ * only when declared: the ontology's replies to mail end with the mailbox's own signature. Older
3854
+ * readers ignore it and send them unsigned.
3814
3855
  */
3815
3856
  readonly chat: Schema.optionalKey<Schema.encodeKeys<Schema.Struct<{
3816
3857
  readonly telegram: Schema.optionalKey<Schema.Struct<{
@@ -3818,24 +3859,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3818
3859
  readonly files: Schema.optionalKey<Schema.Struct<{
3819
3860
  readonly keep: Schema.Boolean;
3820
3861
  }>>;
3862
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3821
3863
  }>>;
3822
3864
  readonly slack: Schema.optionalKey<Schema.Struct<{
3823
3865
  readonly connection: Schema.String;
3824
3866
  readonly files: Schema.optionalKey<Schema.Struct<{
3825
3867
  readonly keep: Schema.Boolean;
3826
3868
  }>>;
3869
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3827
3870
  }>>;
3828
3871
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
3829
3872
  readonly connection: Schema.String;
3830
3873
  readonly files: Schema.optionalKey<Schema.Struct<{
3831
3874
  readonly keep: Schema.Boolean;
3832
3875
  }>>;
3876
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3833
3877
  }>>;
3834
3878
  readonly email: Schema.optionalKey<Schema.Struct<{
3835
3879
  readonly connection: Schema.String;
3836
3880
  readonly files: Schema.optionalKey<Schema.Struct<{
3837
3881
  readonly keep: Schema.Boolean;
3838
3882
  }>>;
3883
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3839
3884
  }>>;
3840
3885
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
3841
3886
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -3843,6 +3888,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3843
3888
  readonly files: Schema.optionalKey<Schema.Struct<{
3844
3889
  readonly keep: Schema.Boolean;
3845
3890
  }>>;
3891
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
3846
3892
  }>>>;
3847
3893
  readonly attribution: Schema.optionalKey<Schema.Struct<{
3848
3894
  readonly template: Schema.optionalKey<Schema.String>;
@@ -4149,24 +4195,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4149
4195
  readonly files?: {
4150
4196
  readonly keep: boolean;
4151
4197
  } | undefined;
4198
+ readonly signature?: boolean | undefined;
4152
4199
  } | undefined;
4153
4200
  readonly slack?: {
4154
4201
  readonly connection: string;
4155
4202
  readonly files?: {
4156
4203
  readonly keep: boolean;
4157
4204
  } | undefined;
4205
+ readonly signature?: boolean | undefined;
4158
4206
  } | undefined;
4159
4207
  readonly whatsapp?: {
4160
4208
  readonly connection: string;
4161
4209
  readonly files?: {
4162
4210
  readonly keep: boolean;
4163
4211
  } | undefined;
4212
+ readonly signature?: boolean | undefined;
4164
4213
  } | undefined;
4165
4214
  readonly email?: {
4166
4215
  readonly connection: string;
4167
4216
  readonly files?: {
4168
4217
  readonly keep: boolean;
4169
4218
  } | undefined;
4219
+ readonly signature?: boolean | undefined;
4170
4220
  } | undefined;
4171
4221
  readonly channels?: {
4172
4222
  readonly [x: string]: {
@@ -4175,6 +4225,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4175
4225
  readonly keep: boolean;
4176
4226
  } | undefined;
4177
4227
  readonly connection?: string | undefined;
4228
+ readonly signature?: boolean | undefined;
4178
4229
  };
4179
4230
  } | undefined;
4180
4231
  readonly attribution?: {
@@ -4521,24 +4572,28 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4521
4572
  readonly files?: {
4522
4573
  readonly keep: boolean;
4523
4574
  } | undefined;
4575
+ readonly signature?: boolean | undefined;
4524
4576
  } | undefined;
4525
4577
  readonly slack?: {
4526
4578
  readonly connection: string;
4527
4579
  readonly files?: {
4528
4580
  readonly keep: boolean;
4529
4581
  } | undefined;
4582
+ readonly signature?: boolean | undefined;
4530
4583
  } | undefined;
4531
4584
  readonly whatsapp?: {
4532
4585
  readonly connection: string;
4533
4586
  readonly files?: {
4534
4587
  readonly keep: boolean;
4535
4588
  } | undefined;
4589
+ readonly signature?: boolean | undefined;
4536
4590
  } | undefined;
4537
4591
  readonly email?: {
4538
4592
  readonly connection: string;
4539
4593
  readonly files?: {
4540
4594
  readonly keep: boolean;
4541
4595
  } | undefined;
4596
+ readonly signature?: boolean | undefined;
4542
4597
  } | undefined;
4543
4598
  readonly channels?: {
4544
4599
  readonly [x: string]: {
@@ -4547,6 +4602,7 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4547
4602
  readonly keep: boolean;
4548
4603
  } | undefined;
4549
4604
  readonly connection?: string | undefined;
4605
+ readonly signature?: boolean | undefined;
4550
4606
  };
4551
4607
  } | undefined;
4552
4608
  readonly attribution?: {
@@ -4899,24 +4955,28 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4899
4955
  readonly files?: {
4900
4956
  readonly keep: boolean;
4901
4957
  } | undefined;
4958
+ readonly signature?: boolean | undefined;
4902
4959
  } | undefined;
4903
4960
  readonly slack?: {
4904
4961
  readonly connection: string;
4905
4962
  readonly files?: {
4906
4963
  readonly keep: boolean;
4907
4964
  } | undefined;
4965
+ readonly signature?: boolean | undefined;
4908
4966
  } | undefined;
4909
4967
  readonly whatsapp?: {
4910
4968
  readonly connection: string;
4911
4969
  readonly files?: {
4912
4970
  readonly keep: boolean;
4913
4971
  } | undefined;
4972
+ readonly signature?: boolean | undefined;
4914
4973
  } | undefined;
4915
4974
  readonly email?: {
4916
4975
  readonly connection: string;
4917
4976
  readonly files?: {
4918
4977
  readonly keep: boolean;
4919
4978
  } | undefined;
4979
+ readonly signature?: boolean | undefined;
4920
4980
  } | undefined;
4921
4981
  readonly channels?: {
4922
4982
  readonly [x: string]: {
@@ -4925,6 +4985,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4925
4985
  readonly keep: boolean;
4926
4986
  } | undefined;
4927
4987
  readonly connection?: string | undefined;
4988
+ readonly signature?: boolean | undefined;
4928
4989
  };
4929
4990
  } | undefined;
4930
4991
  readonly attribution?: {
@@ -5271,24 +5332,28 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5271
5332
  readonly files?: {
5272
5333
  readonly keep: boolean;
5273
5334
  } | undefined;
5335
+ readonly signature?: boolean | undefined;
5274
5336
  } | undefined;
5275
5337
  readonly slack?: {
5276
5338
  readonly connection: string;
5277
5339
  readonly files?: {
5278
5340
  readonly keep: boolean;
5279
5341
  } | undefined;
5342
+ readonly signature?: boolean | undefined;
5280
5343
  } | undefined;
5281
5344
  readonly whatsapp?: {
5282
5345
  readonly connection: string;
5283
5346
  readonly files?: {
5284
5347
  readonly keep: boolean;
5285
5348
  } | undefined;
5349
+ readonly signature?: boolean | undefined;
5286
5350
  } | undefined;
5287
5351
  readonly email?: {
5288
5352
  readonly connection: string;
5289
5353
  readonly files?: {
5290
5354
  readonly keep: boolean;
5291
5355
  } | undefined;
5356
+ readonly signature?: boolean | undefined;
5292
5357
  } | undefined;
5293
5358
  readonly channels?: {
5294
5359
  readonly [x: string]: {
@@ -5297,6 +5362,7 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5297
5362
  readonly keep: boolean;
5298
5363
  } | undefined;
5299
5364
  readonly connection?: string | undefined;
5365
+ readonly signature?: boolean | undefined;
5300
5366
  };
5301
5367
  } | undefined;
5302
5368
  readonly attribution?: {
@@ -5553,6 +5619,11 @@ export declare function declaredChatRetentionDaysOf(manifest: Pick<OntologyManif
5553
5619
  * number in range, else the default.
5554
5620
  */
5555
5621
  export declare function chatRetentionDaysOf(manifest: Pick<OntologyManifest, "chat">): number;
5622
+ /**
5623
+ * Whether the ontology's replies to mail through the agent's channel `name` end with the mailbox's
5624
+ * own signature, as the channel's `signature: true` in `chat` declares.
5625
+ */
5626
+ export declare function signsMail(manifest: Pick<OntologyManifest, "chat">, name: string): boolean;
5556
5627
  /**
5557
5628
  * Whether the chats of the agent's channel `name` keep their files as long as their messages, as
5558
5629
  * the channel's `files: { keep: true }` in `chat` declares; otherwise a file expires 24 hours after
package/dist/manifest.js CHANGED
@@ -109,6 +109,8 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
109
109
  * Within version 16, `inbox` may carry `channels`, written only when declared: the channels whose
110
110
  * chats with people who are no users the agent registers as `agent_chat` records of kind
111
111
  * `private` without members. Older readers ignore it and register no chat without members.
112
+ * Within version 16, a mailbox in `chat` may carry `signature: true`, written only when declared:
113
+ * the ontology's replies to mail end with the mailbox's own signature. Older readers ignore it.
112
114
  */
113
115
  export const MANIFEST_VERSION = 16;
114
116
  /** The first version whose documents use snake_case names on the wire. */
@@ -571,10 +573,14 @@ export const EmailDocumentManifest = Schema.Struct({
571
573
  export const EmailTemplateManifest = Schema.Union([EmailDocumentManifest, EmailLayoutManifest]);
572
574
  /** What a chat channel keeps of its chats' files: `keep`, for as long as their messages. */
573
575
  const ChatFilesManifest = Schema.Struct({ keep: Schema.Boolean });
574
- /** A chat channel named after its kind: the connection posts go through, and what it keeps. */
576
+ /**
577
+ * A chat channel named after its kind: the connection posts go through, what it keeps, and for a
578
+ * mailbox whether its replies end with its own signature.
579
+ */
575
580
  const ChatChannelManifest = Schema.Struct({
576
581
  connection: Schema.String,
577
582
  files: Schema.optionalKey(ChatFilesManifest),
583
+ signature: Schema.optionalKey(Schema.Boolean),
578
584
  });
579
585
  /**
580
586
  * The ontology catalog: the contract between the SDK, backend-next, the console and the CLI. Decoding
@@ -613,7 +619,10 @@ const OntologyManifestModel = Schema.Struct({
613
619
  * staff's replies in the inbox leave from; no other chat post goes to it, nor to another channel
614
620
  * of its kind. Within version 16, a
615
621
  * channel may carry `files: { keep: true }`, written only when declared: its chats keep their
616
- * files as long as their messages. Older readers ignore it and keep files 24 hours.
622
+ * files as long as their messages. Older readers ignore it and keep files 24 hours. Within
623
+ * version 16, a mailbox (`email`, or a channel of that kind) may carry `signature: true`, written
624
+ * only when declared: the ontology's replies to mail end with the mailbox's own signature. Older
625
+ * readers ignore it and send them unsigned.
617
626
  */
618
627
  chat: Schema.optionalKey(Schema.Struct({
619
628
  telegram: Schema.optionalKey(ChatChannelManifest),
@@ -625,6 +634,7 @@ const OntologyManifestModel = Schema.Struct({
625
634
  // A workspace channel (`custom`) has none: the agent sends through it.
626
635
  connection: Schema.optionalKey(Schema.String),
627
636
  files: Schema.optionalKey(ChatFilesManifest),
637
+ signature: Schema.optionalKey(Schema.Boolean),
628
638
  }))),
629
639
  attribution: Schema.optionalKey(Schema.Struct({
630
640
  template: Schema.optionalKey(Schema.String),
@@ -768,6 +778,17 @@ export function chatRetentionDaysOf(manifest) {
768
778
  ? days
769
779
  : CHAT_RETENTION_DAYS.default;
770
780
  }
781
+ /**
782
+ * Whether the ontology's replies to mail through the agent's channel `name` end with the mailbox's
783
+ * own signature, as the channel's `signature: true` in `chat` declares.
784
+ */
785
+ export function signsMail(manifest, name) {
786
+ const chat = manifest.chat;
787
+ const channel = name === "telegram" || name === "slack" || name === "whatsapp" || name === "email"
788
+ ? chat?.[name]
789
+ : chat?.channels?.[name];
790
+ return channel?.signature === true;
791
+ }
771
792
  /**
772
793
  * Whether the chats of the agent's channel `name` keep their files as long as their messages, as
773
794
  * the channel's `files: { keep: true }` in `chat` declares; otherwise a file expires 24 hours after
@@ -411,24 +411,28 @@ export declare const MigrationPlan: Schema.Struct<{
411
411
  readonly files?: {
412
412
  readonly keep: boolean;
413
413
  } | undefined;
414
+ readonly signature?: boolean | undefined;
414
415
  } | undefined;
415
416
  readonly slack?: {
416
417
  readonly connection: string;
417
418
  readonly files?: {
418
419
  readonly keep: boolean;
419
420
  } | undefined;
421
+ readonly signature?: boolean | undefined;
420
422
  } | undefined;
421
423
  readonly whatsapp?: {
422
424
  readonly connection: string;
423
425
  readonly files?: {
424
426
  readonly keep: boolean;
425
427
  } | undefined;
428
+ readonly signature?: boolean | undefined;
426
429
  } | undefined;
427
430
  readonly email?: {
428
431
  readonly connection: string;
429
432
  readonly files?: {
430
433
  readonly keep: boolean;
431
434
  } | undefined;
435
+ readonly signature?: boolean | undefined;
432
436
  } | undefined;
433
437
  readonly channels?: {
434
438
  readonly [x: string]: {
@@ -437,6 +441,7 @@ export declare const MigrationPlan: Schema.Struct<{
437
441
  readonly keep: boolean;
438
442
  } | undefined;
439
443
  readonly connection?: string | undefined;
444
+ readonly signature?: boolean | undefined;
440
445
  };
441
446
  } | undefined;
442
447
  readonly attribution?: {
@@ -783,24 +788,28 @@ export declare const MigrationPlan: Schema.Struct<{
783
788
  readonly files?: {
784
789
  readonly keep: boolean;
785
790
  } | undefined;
791
+ readonly signature?: boolean | undefined;
786
792
  } | undefined;
787
793
  readonly slack?: {
788
794
  readonly connection: string;
789
795
  readonly files?: {
790
796
  readonly keep: boolean;
791
797
  } | undefined;
798
+ readonly signature?: boolean | undefined;
792
799
  } | undefined;
793
800
  readonly whatsapp?: {
794
801
  readonly connection: string;
795
802
  readonly files?: {
796
803
  readonly keep: boolean;
797
804
  } | undefined;
805
+ readonly signature?: boolean | undefined;
798
806
  } | undefined;
799
807
  readonly email?: {
800
808
  readonly connection: string;
801
809
  readonly files?: {
802
810
  readonly keep: boolean;
803
811
  } | undefined;
812
+ readonly signature?: boolean | undefined;
804
813
  } | undefined;
805
814
  readonly channels?: {
806
815
  readonly [x: string]: {
@@ -809,6 +818,7 @@ export declare const MigrationPlan: Schema.Struct<{
809
818
  readonly keep: boolean;
810
819
  } | undefined;
811
820
  readonly connection?: string | undefined;
821
+ readonly signature?: boolean | undefined;
812
822
  };
813
823
  } | undefined;
814
824
  readonly attribution?: {
@@ -1155,24 +1165,28 @@ export declare const MigrationPlan: Schema.Struct<{
1155
1165
  readonly files?: {
1156
1166
  readonly keep: boolean;
1157
1167
  } | undefined;
1168
+ readonly signature?: boolean | undefined;
1158
1169
  } | undefined;
1159
1170
  readonly slack?: {
1160
1171
  readonly connection: string;
1161
1172
  readonly files?: {
1162
1173
  readonly keep: boolean;
1163
1174
  } | undefined;
1175
+ readonly signature?: boolean | undefined;
1164
1176
  } | undefined;
1165
1177
  readonly whatsapp?: {
1166
1178
  readonly connection: string;
1167
1179
  readonly files?: {
1168
1180
  readonly keep: boolean;
1169
1181
  } | undefined;
1182
+ readonly signature?: boolean | undefined;
1170
1183
  } | undefined;
1171
1184
  readonly email?: {
1172
1185
  readonly connection: string;
1173
1186
  readonly files?: {
1174
1187
  readonly keep: boolean;
1175
1188
  } | undefined;
1189
+ readonly signature?: boolean | undefined;
1176
1190
  } | undefined;
1177
1191
  readonly channels?: {
1178
1192
  readonly [x: string]: {
@@ -1181,6 +1195,7 @@ export declare const MigrationPlan: Schema.Struct<{
1181
1195
  readonly keep: boolean;
1182
1196
  } | undefined;
1183
1197
  readonly connection?: string | undefined;
1198
+ readonly signature?: boolean | undefined;
1184
1199
  };
1185
1200
  } | undefined;
1186
1201
  readonly attribution?: {
@@ -1527,24 +1542,28 @@ export declare const MigrationPlan: Schema.Struct<{
1527
1542
  readonly files?: {
1528
1543
  readonly keep: boolean;
1529
1544
  } | undefined;
1545
+ readonly signature?: boolean | undefined;
1530
1546
  } | undefined;
1531
1547
  readonly slack?: {
1532
1548
  readonly connection: string;
1533
1549
  readonly files?: {
1534
1550
  readonly keep: boolean;
1535
1551
  } | undefined;
1552
+ readonly signature?: boolean | undefined;
1536
1553
  } | undefined;
1537
1554
  readonly whatsapp?: {
1538
1555
  readonly connection: string;
1539
1556
  readonly files?: {
1540
1557
  readonly keep: boolean;
1541
1558
  } | undefined;
1559
+ readonly signature?: boolean | undefined;
1542
1560
  } | undefined;
1543
1561
  readonly email?: {
1544
1562
  readonly connection: string;
1545
1563
  readonly files?: {
1546
1564
  readonly keep: boolean;
1547
1565
  } | undefined;
1566
+ readonly signature?: boolean | undefined;
1548
1567
  } | undefined;
1549
1568
  readonly channels?: {
1550
1569
  readonly [x: string]: {
@@ -1553,6 +1572,7 @@ export declare const MigrationPlan: Schema.Struct<{
1553
1572
  readonly keep: boolean;
1554
1573
  } | undefined;
1555
1574
  readonly connection?: string | undefined;
1575
+ readonly signature?: boolean | undefined;
1556
1576
  };
1557
1577
  } | undefined;
1558
1578
  readonly attribution?: {
@@ -2009,24 +2029,28 @@ export declare const MigrationPlan: Schema.Struct<{
2009
2029
  readonly files: Schema.optionalKey<Schema.Struct<{
2010
2030
  readonly keep: Schema.Boolean;
2011
2031
  }>>;
2032
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2012
2033
  }>>;
2013
2034
  readonly slack: Schema.optionalKey<Schema.Struct<{
2014
2035
  readonly connection: Schema.String;
2015
2036
  readonly files: Schema.optionalKey<Schema.Struct<{
2016
2037
  readonly keep: Schema.Boolean;
2017
2038
  }>>;
2039
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2018
2040
  }>>;
2019
2041
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
2020
2042
  readonly connection: Schema.String;
2021
2043
  readonly files: Schema.optionalKey<Schema.Struct<{
2022
2044
  readonly keep: Schema.Boolean;
2023
2045
  }>>;
2046
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2024
2047
  }>>;
2025
2048
  readonly email: Schema.optionalKey<Schema.Struct<{
2026
2049
  readonly connection: Schema.String;
2027
2050
  readonly files: Schema.optionalKey<Schema.Struct<{
2028
2051
  readonly keep: Schema.Boolean;
2029
2052
  }>>;
2053
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2030
2054
  }>>;
2031
2055
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
2032
2056
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -2034,6 +2058,7 @@ export declare const MigrationPlan: Schema.Struct<{
2034
2058
  readonly files: Schema.optionalKey<Schema.Struct<{
2035
2059
  readonly keep: Schema.Boolean;
2036
2060
  }>>;
2061
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2037
2062
  }>>>;
2038
2063
  readonly attribution: Schema.optionalKey<Schema.Struct<{
2039
2064
  readonly template: Schema.optionalKey<Schema.String>;
@@ -2379,24 +2404,28 @@ export declare const MigrationPlan: Schema.Struct<{
2379
2404
  readonly files: Schema.optionalKey<Schema.Struct<{
2380
2405
  readonly keep: Schema.Boolean;
2381
2406
  }>>;
2407
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2382
2408
  }>>;
2383
2409
  readonly slack: Schema.optionalKey<Schema.Struct<{
2384
2410
  readonly connection: Schema.String;
2385
2411
  readonly files: Schema.optionalKey<Schema.Struct<{
2386
2412
  readonly keep: Schema.Boolean;
2387
2413
  }>>;
2414
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2388
2415
  }>>;
2389
2416
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
2390
2417
  readonly connection: Schema.String;
2391
2418
  readonly files: Schema.optionalKey<Schema.Struct<{
2392
2419
  readonly keep: Schema.Boolean;
2393
2420
  }>>;
2421
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2394
2422
  }>>;
2395
2423
  readonly email: Schema.optionalKey<Schema.Struct<{
2396
2424
  readonly connection: Schema.String;
2397
2425
  readonly files: Schema.optionalKey<Schema.Struct<{
2398
2426
  readonly keep: Schema.Boolean;
2399
2427
  }>>;
2428
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2400
2429
  }>>;
2401
2430
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
2402
2431
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -2404,6 +2433,7 @@ export declare const MigrationPlan: Schema.Struct<{
2404
2433
  readonly files: Schema.optionalKey<Schema.Struct<{
2405
2434
  readonly keep: Schema.Boolean;
2406
2435
  }>>;
2436
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
2407
2437
  }>>>;
2408
2438
  readonly attribution: Schema.optionalKey<Schema.Struct<{
2409
2439
  readonly template: Schema.optionalKey<Schema.String>;
@@ -2653,24 +2683,28 @@ export declare const MigrationPlan: Schema.Struct<{
2653
2683
  readonly files?: {
2654
2684
  readonly keep: boolean;
2655
2685
  } | undefined;
2686
+ readonly signature?: boolean | undefined;
2656
2687
  } | undefined;
2657
2688
  readonly slack?: {
2658
2689
  readonly connection: string;
2659
2690
  readonly files?: {
2660
2691
  readonly keep: boolean;
2661
2692
  } | undefined;
2693
+ readonly signature?: boolean | undefined;
2662
2694
  } | undefined;
2663
2695
  readonly whatsapp?: {
2664
2696
  readonly connection: string;
2665
2697
  readonly files?: {
2666
2698
  readonly keep: boolean;
2667
2699
  } | undefined;
2700
+ readonly signature?: boolean | undefined;
2668
2701
  } | undefined;
2669
2702
  readonly email?: {
2670
2703
  readonly connection: string;
2671
2704
  readonly files?: {
2672
2705
  readonly keep: boolean;
2673
2706
  } | undefined;
2707
+ readonly signature?: boolean | undefined;
2674
2708
  } | undefined;
2675
2709
  readonly channels?: {
2676
2710
  readonly [x: string]: {
@@ -2679,6 +2713,7 @@ export declare const MigrationPlan: Schema.Struct<{
2679
2713
  readonly keep: boolean;
2680
2714
  } | undefined;
2681
2715
  readonly connection?: string | undefined;
2716
+ readonly signature?: boolean | undefined;
2682
2717
  };
2683
2718
  } | undefined;
2684
2719
  readonly attribution?: {
@@ -3025,24 +3060,28 @@ export declare const MigrationPlan: Schema.Struct<{
3025
3060
  readonly files?: {
3026
3061
  readonly keep: boolean;
3027
3062
  } | undefined;
3063
+ readonly signature?: boolean | undefined;
3028
3064
  } | undefined;
3029
3065
  readonly slack?: {
3030
3066
  readonly connection: string;
3031
3067
  readonly files?: {
3032
3068
  readonly keep: boolean;
3033
3069
  } | undefined;
3070
+ readonly signature?: boolean | undefined;
3034
3071
  } | undefined;
3035
3072
  readonly whatsapp?: {
3036
3073
  readonly connection: string;
3037
3074
  readonly files?: {
3038
3075
  readonly keep: boolean;
3039
3076
  } | undefined;
3077
+ readonly signature?: boolean | undefined;
3040
3078
  } | undefined;
3041
3079
  readonly email?: {
3042
3080
  readonly connection: string;
3043
3081
  readonly files?: {
3044
3082
  readonly keep: boolean;
3045
3083
  } | undefined;
3084
+ readonly signature?: boolean | undefined;
3046
3085
  } | undefined;
3047
3086
  readonly channels?: {
3048
3087
  readonly [x: string]: {
@@ -3051,6 +3090,7 @@ export declare const MigrationPlan: Schema.Struct<{
3051
3090
  readonly keep: boolean;
3052
3091
  } | undefined;
3053
3092
  readonly connection?: string | undefined;
3093
+ readonly signature?: boolean | undefined;
3054
3094
  };
3055
3095
  } | undefined;
3056
3096
  readonly attribution?: {
@@ -1,5 +1,5 @@
1
1
  import { validateTelegramPreviews } from "../../telegram.js";
2
- import { chatRetentionDaysOf, inboxAttributionOf, takeoverChannelsOf } from "../../manifest.js";
2
+ import { chatRetentionDaysOf, inboxAttributionOf, signsMail, 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";
@@ -775,6 +775,7 @@ chats) {
775
775
  ? { chatId: place.chatId }
776
776
  : {}),
777
777
  transport,
778
+ ...(signsMail(ontology.manifest, target.provider) ? { signature: true } : {}),
778
779
  });
779
780
  if (outcome.cause !== undefined) {
780
781
  yield* report("provider", outcome.cause);
@@ -1,8 +1,10 @@
1
1
  import { Effect } from "effect";
2
2
  import { AGENT_DRAFT_FILES_LIMIT } from "../../../agent-draft.js";
3
- import { base64Url, EMAIL_FILES_BYTES, EMAIL_MESSAGE_LIMIT, emailReplyMessage, GmailError, gmailExplanation, GmailMaybeSent, renderEmailHtml, replyAllRecipients, sendGmailMessage, } from "../../../email.js";
3
+ import { base64Url, EMAIL_FILES_BYTES, EMAIL_MESSAGE_LIMIT, emailReplyMessage, GmailError, gmailExplanation, GmailMaybeSent, renderEmailHtml, replyAllRecipients, sendGmailMessage, withEmailSignature, } from "../../../email.js";
4
+ import { mailboxSignature } from "../../../gmail-send.js";
4
5
  import { ActionRejected } from "../../../errors.js";
5
6
  import { EMAIL_PATTERN } from "../../../property.js";
7
+ import { describeChatError } from "../diagnostics.js";
6
8
  import { channelRequest, definiteTransportFailure, filesWithBytes, record, transportFailure, } from "./provider.js";
7
9
  /** A Gmail id, of a thread or a message. */
8
10
  const GMAIL_ID = /^[A-Za-z0-9_-]{1,512}$/;
@@ -88,6 +90,21 @@ function threadHeaders(received) {
88
90
  references: last.get("references") ?? null,
89
91
  };
90
92
  }
93
+ /**
94
+ * The mailbox's own signature, read through the connection and kept a while per mailbox, as the
95
+ * agent's replies read it; `undefined` when it has none or Gmail refused the read, which is logged
96
+ * and sends the reply unsigned rather than not at all.
97
+ */
98
+ function signatureOf(input) {
99
+ return Effect.tryPromise({
100
+ try: () => mailboxSignature({
101
+ mailbox: input.connection,
102
+ request: (call) => Effect.runPromise(input.transport.request({ connection: input.connection, ...call })),
103
+ }),
104
+ // The original failure, Gmail's explanation or the connection's, with its causes and stack.
105
+ catch: (cause) => cause,
106
+ }).pipe(Effect.catch((cause) => Effect.logWarning("ontology.chat.email_signature_unavailable").pipe(Effect.annotateLogs({ error: describeChatError(cause, (text) => text) }), Effect.as(undefined))));
107
+ }
91
108
  /**
92
109
  * One reply in the person's email thread, from the mailbox the ontology's `chat.email` names, to
93
110
  * its `recipients`, `To` and `Cc`, or else to the destination alone. It reads the thread's subject
@@ -146,6 +163,10 @@ export function sendEmail(input) {
146
163
  const key = input.operationId !== undefined && input.operationId !== input.destination.id
147
164
  ? `post-${input.operationId}`
148
165
  : `review-${input.destination.id}`;
166
+ // With the channel's `signature`, the HTML ends with the mailbox's own signature.
167
+ const html = input.signature === true
168
+ ? withEmailSignature(input.finalText, yield* signatureOf(input))
169
+ : input.finalText;
149
170
  const to = input.recipients?.to ?? [input.destination.external_id];
150
171
  const cc = input.recipients?.cc ?? [];
151
172
  const files = input.files ?? [];
@@ -156,7 +177,7 @@ export function sendEmail(input) {
156
177
  inReplyTo: answered.inReplyTo,
157
178
  references: answered.references,
158
179
  text: input.plainText,
159
- html: input.finalText,
180
+ html,
160
181
  autoSubmitted: true,
161
182
  ...(/^[A-Za-z0-9_-]{1,128}$/.test(key) ? { replyKey: key } : {}),
162
183
  ...(files.length === 0 ? {} : { attachments: filesWithBytes(files) }),
@@ -165,7 +186,7 @@ export function sendEmail(input) {
165
186
  threadId,
166
187
  to,
167
188
  cc,
168
- html: input.finalText,
189
+ html,
169
190
  text: input.plainText,
170
191
  ...(files.length === 0 ? {} : { files: files.map((file) => file.filename) }),
171
192
  };
@@ -126,6 +126,8 @@ export interface ChatSend {
126
126
  * the thread; without them the provider reads the thread itself. Others ignore them.
127
127
  */
128
128
  readonly thread?: ThreadHeaders;
129
+ /** Whether a reply to mail ends with the mailbox's own signature; others ignore it. */
130
+ readonly signature?: boolean;
129
131
  }
130
132
  /**
131
133
  * A channel the platform posts exact chat messages to. Each provider names its own ids, renders
@@ -6,7 +6,7 @@ import { effectiveScope } from "../../permissions.js";
6
6
  import { describeChatError } from "./diagnostics.js";
7
7
  import { deliveryFingerprint, deliveryKeyDigest, deliveryScopeDigest } from "./idempotency.js";
8
8
  import { WORKSPACE_CHANNEL_KIND } from "../../chat-channel.js";
9
- import { chatRetentionDaysOf } from "../../manifest.js";
9
+ import { chatRetentionDaysOf, signsMail } from "../../manifest.js";
10
10
  import { channelProvider, chatConnection, chatKind } from "./providers/index.js";
11
11
  import { storeDeliveryArchive } from "./store-delivery.js";
12
12
  import { readDraftFiles, refuseChatFiles } from "./draft-files.js";
@@ -468,6 +468,7 @@ export function reviewSender(input) {
468
468
  ...(sendFiles.length === 0 ? {} : { files: sendFiles }),
469
469
  ...(recipients === undefined ? {} : { recipients }),
470
470
  ...(input.agent === undefined ? {} : { agent: input.agent }),
471
+ ...(signsMail(input.ontology.manifest, providerName) ? { signature: true } : {}),
471
472
  ...(input.previews === undefined ? {} : { previews: input.previews }),
472
473
  transport: input.connections({
473
474
  identityToken: input.identityToken,
@@ -533,24 +533,28 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
533
533
  readonly files: Schema.optionalKey<Schema.Struct<{
534
534
  readonly keep: Schema.Boolean;
535
535
  }>>;
536
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
536
537
  }>>;
537
538
  readonly slack: Schema.optionalKey<Schema.Struct<{
538
539
  readonly connection: Schema.String;
539
540
  readonly files: Schema.optionalKey<Schema.Struct<{
540
541
  readonly keep: Schema.Boolean;
541
542
  }>>;
543
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
542
544
  }>>;
543
545
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
544
546
  readonly connection: Schema.String;
545
547
  readonly files: Schema.optionalKey<Schema.Struct<{
546
548
  readonly keep: Schema.Boolean;
547
549
  }>>;
550
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
548
551
  }>>;
549
552
  readonly email: Schema.optionalKey<Schema.Struct<{
550
553
  readonly connection: Schema.String;
551
554
  readonly files: Schema.optionalKey<Schema.Struct<{
552
555
  readonly keep: Schema.Boolean;
553
556
  }>>;
557
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
554
558
  }>>;
555
559
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
556
560
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -558,6 +562,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
558
562
  readonly files: Schema.optionalKey<Schema.Struct<{
559
563
  readonly keep: Schema.Boolean;
560
564
  }>>;
565
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
561
566
  }>>>;
562
567
  readonly attribution: Schema.optionalKey<Schema.Struct<{
563
568
  readonly template: Schema.optionalKey<Schema.String>;
@@ -917,24 +922,28 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
917
922
  readonly files: Schema.optionalKey<Schema.Struct<{
918
923
  readonly keep: Schema.Boolean;
919
924
  }>>;
925
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
920
926
  }>>;
921
927
  readonly slack: Schema.optionalKey<Schema.Struct<{
922
928
  readonly connection: Schema.String;
923
929
  readonly files: Schema.optionalKey<Schema.Struct<{
924
930
  readonly keep: Schema.Boolean;
925
931
  }>>;
932
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
926
933
  }>>;
927
934
  readonly whatsapp: Schema.optionalKey<Schema.Struct<{
928
935
  readonly connection: Schema.String;
929
936
  readonly files: Schema.optionalKey<Schema.Struct<{
930
937
  readonly keep: Schema.Boolean;
931
938
  }>>;
939
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
932
940
  }>>;
933
941
  readonly email: Schema.optionalKey<Schema.Struct<{
934
942
  readonly connection: Schema.String;
935
943
  readonly files: Schema.optionalKey<Schema.Struct<{
936
944
  readonly keep: Schema.Boolean;
937
945
  }>>;
946
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
938
947
  }>>;
939
948
  readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
940
949
  readonly kind: Schema.Literals<readonly ["telegram", "slack", "whatsapp", "email", "custom"]>;
@@ -942,6 +951,7 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
942
951
  readonly files: Schema.optionalKey<Schema.Struct<{
943
952
  readonly keep: Schema.Boolean;
944
953
  }>>;
954
+ readonly signature: Schema.optionalKey<Schema.Boolean>;
945
955
  }>>>;
946
956
  readonly attribution: Schema.optionalKey<Schema.Struct<{
947
957
  readonly template: Schema.optionalKey<Schema.String>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.167.0",
3
+ "version": "0.168.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",