@happyvertical/smrt-messages 0.62.13 → 0.63.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/AGENTS.md +7 -1
- package/agents/send-approval.md +101 -0
- package/dist/access.d.ts +33 -1
- package/dist/access.d.ts.map +1 -1
- package/dist/chunks/{AttachmentCollection-Dzz2iKjx.js → AttachmentCollection-CQaFv6FD.js} +4 -4
- package/dist/chunks/{AttachmentCollection-Dzz2iKjx.js.map → AttachmentCollection-CQaFv6FD.js.map} +1 -1
- package/dist/chunks/{Email-DDMgkm_l.js → Email-YfrfXXmh.js} +185 -9
- package/dist/chunks/Email-YfrfXXmh.js.map +1 -0
- package/dist/chunks/EmailAccountCollection-DzSW5043.js +2472 -0
- package/dist/chunks/EmailAccountCollection-DzSW5043.js.map +1 -0
- package/dist/chunks/{EmailCollection-lo8WePl-.js → EmailCollection-BGtIdMhg.js} +3 -3
- package/dist/chunks/{EmailCollection-lo8WePl-.js.map → EmailCollection-BGtIdMhg.js.map} +1 -1
- package/dist/chunks/{EmailFolder-Bu7y8-VX.js → EmailFolder-DADdGZC0.js} +6 -6
- package/dist/chunks/{EmailFolder-Bu7y8-VX.js.map → EmailFolder-DADdGZC0.js.map} +1 -1
- package/dist/chunks/{EmailFolderCollection-BpzzKBhM.js → EmailFolderCollection-DSnVCTIB.js} +2 -2
- package/dist/chunks/{EmailFolderCollection-BpzzKBhM.js.map → EmailFolderCollection-DSnVCTIB.js.map} +1 -1
- package/dist/chunks/{EmailSender-B-Rtq9du.js → EmailSender-0Y6Bo_OK.js} +8 -1
- package/dist/chunks/EmailSender-0Y6Bo_OK.js.map +1 -0
- package/dist/chunks/{Message-BwW51pgG.js → Message-CGQywP0F.js} +139 -11
- package/dist/chunks/Message-CGQywP0F.js.map +1 -0
- package/dist/chunks/{MessageCollection-JjZybSMu.js → MessageCollection-Cw1T8ZxA.js} +2 -2
- package/dist/chunks/{MessageCollection-JjZybSMu.js.map → MessageCollection-Cw1T8ZxA.js.map} +1 -1
- package/dist/chunks/{MessagingEndpointCollection-FmbtiFJy.js → MessagingEndpointCollection-CX2ygSoD.js} +2 -2
- package/dist/chunks/{MessagingEndpointCollection-FmbtiFJy.js.map → MessagingEndpointCollection-CX2ygSoD.js.map} +1 -1
- package/dist/connect.js +1 -1
- package/dist/html-to-text.d.ts +13 -0
- package/dist/html-to-text.d.ts.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -14
- package/dist/index.js.map +1 -1
- package/dist/mail-drafts.d.ts +63 -0
- package/dist/mail-drafts.d.ts.map +1 -0
- package/dist/mail-triage.d.ts.map +1 -1
- package/dist/manifest.json +357 -33
- package/dist/models/Email.d.ts +5 -0
- package/dist/models/Email.d.ts.map +1 -1
- package/dist/models/EmailAccount.d.ts +8 -1
- package/dist/models/EmailAccount.d.ts.map +1 -1
- package/dist/models/Message.d.ts +11 -0
- package/dist/models/Message.d.ts.map +1 -1
- package/dist/models/SlackMessage.d.ts +10 -0
- package/dist/models/SlackMessage.d.ts.map +1 -1
- package/dist/send-approval.d.ts +275 -0
- package/dist/send-approval.d.ts.map +1 -0
- package/dist/senders/EmailSender.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +216 -8
- package/dist/smrt-knowledge.okf.md +7 -2
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -11
- package/dist/chunks/Email-DDMgkm_l.js.map +0 -1
- package/dist/chunks/EmailAccountCollection-CgZE9YAM.js +0 -1992
- package/dist/chunks/EmailAccountCollection-CgZE9YAM.js.map +0 -1
- package/dist/chunks/EmailSender-B-Rtq9du.js.map +0 -1
- package/dist/chunks/Message-BwW51pgG.js.map +0 -1
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-messages",
|
|
6
|
-
"packageVersion": "0.
|
|
6
|
+
"packageVersion": "0.63.0",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
12
|
-
"agents": "
|
|
10
|
+
"manifest": "20930e9fadaf5bba8e7602cb559f044a65b42336b37e2ebece38a76333cb99de",
|
|
11
|
+
"packageJson": "311b333ed306b5574a29e278c05ffe9a2b5fa4b4d3cf2f8ebc93a8fa9b8e37fc",
|
|
12
|
+
"agents": "b20f4c614caa7f5bd3abc7cd848729f457d6222dd1aa3fdbaf76688abd03cf06",
|
|
13
|
+
"moduleDoc:agents/send-approval.md": "cd83906c6ca259cfb3d5efd7caf2267f81e47e65abe90ece30d2df477d724df9",
|
|
13
14
|
"moduleDoc:agents/mail-search.md": "9dac1619a1486f2fa94980e141ebc5003851c27cd77ced6d5ff64d348429fdb1",
|
|
14
15
|
"moduleDoc:agents/notification-outbox.md": "0e9a870c4b2d5f0fec47af0dff6e61d216fb0121d384d99bccfc506beb6e38ad",
|
|
15
16
|
"moduleDoc:agents/profile-recipients.md": "1b6710bf646ddeafd6836df8270fcbb8e29226dceda716a693d945cc2e914606"
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"@happyvertical/smrt-users": "workspace:*",
|
|
43
44
|
"@happyvertical/sql": "catalog:",
|
|
44
45
|
"@happyvertical/utils": "catalog:",
|
|
46
|
+
"@happyvertical/smrt-approvals": "workspace:*",
|
|
45
47
|
"@happyvertical/smrt-ledgers": "workspace:*",
|
|
46
48
|
"@happyvertical/smrt-vitest": "workspace:*",
|
|
47
49
|
"@sveltejs/package": "^2.5.8",
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"@happyvertical/encryption": "*"
|
|
56
58
|
},
|
|
57
59
|
"smrtDependencies": [
|
|
60
|
+
"@happyvertical/smrt-approvals",
|
|
58
61
|
"@happyvertical/smrt-core",
|
|
59
62
|
"@happyvertical/smrt-jobs",
|
|
60
63
|
"@happyvertical/smrt-ledgers",
|
|
@@ -4326,6 +4329,30 @@
|
|
|
4326
4329
|
"columnType": "UUID",
|
|
4327
4330
|
"description": "The earlier message this one replies to."
|
|
4328
4331
|
},
|
|
4332
|
+
{
|
|
4333
|
+
"name": "handledById",
|
|
4334
|
+
"type": "text",
|
|
4335
|
+
"required": false,
|
|
4336
|
+
"columnType": "TEXT",
|
|
4337
|
+
"readonly": true,
|
|
4338
|
+
"description": "The person or assistant who last acted on this message."
|
|
4339
|
+
},
|
|
4340
|
+
{
|
|
4341
|
+
"name": "handledByKind",
|
|
4342
|
+
"type": "text",
|
|
4343
|
+
"required": false,
|
|
4344
|
+
"columnType": "TEXT",
|
|
4345
|
+
"readonly": true,
|
|
4346
|
+
"description": "Whether a person or an assistant last acted on this message."
|
|
4347
|
+
},
|
|
4348
|
+
{
|
|
4349
|
+
"name": "handledAt",
|
|
4350
|
+
"type": "datetime",
|
|
4351
|
+
"required": false,
|
|
4352
|
+
"columnType": "TIMESTAMP",
|
|
4353
|
+
"readonly": true,
|
|
4354
|
+
"description": "When someone last acted on this message."
|
|
4355
|
+
},
|
|
4329
4356
|
{
|
|
4330
4357
|
"name": "createdAt",
|
|
4331
4358
|
"type": "text",
|
|
@@ -4504,6 +4531,7 @@
|
|
|
4504
4531
|
"getEndpoint",
|
|
4505
4532
|
"getFlags",
|
|
4506
4533
|
"getFolder",
|
|
4534
|
+
"getHandledBy",
|
|
4507
4535
|
"getHeaders",
|
|
4508
4536
|
"getLabels",
|
|
4509
4537
|
"getMetadata",
|
|
@@ -4589,6 +4617,10 @@
|
|
|
4589
4617
|
"async": true,
|
|
4590
4618
|
"returns": "any"
|
|
4591
4619
|
},
|
|
4620
|
+
{
|
|
4621
|
+
"name": "getHandledBy",
|
|
4622
|
+
"returns": "object | null"
|
|
4623
|
+
},
|
|
4592
4624
|
{
|
|
4593
4625
|
"name": "getHeaders",
|
|
4594
4626
|
"returns": "Record<string, string | string[]>"
|
|
@@ -4883,6 +4915,12 @@
|
|
|
4883
4915
|
"operation": "send",
|
|
4884
4916
|
"objectName": "@happyvertical/smrt-messages:Email"
|
|
4885
4917
|
},
|
|
4918
|
+
{
|
|
4919
|
+
"kind": "cli",
|
|
4920
|
+
"name": "email_getHandledBy",
|
|
4921
|
+
"operation": "getHandledBy",
|
|
4922
|
+
"objectName": "@happyvertical/smrt-messages:Email"
|
|
4923
|
+
},
|
|
4886
4924
|
{
|
|
4887
4925
|
"kind": "cli",
|
|
4888
4926
|
"name": "email_isSendOutcomeUnknown",
|
|
@@ -5069,6 +5107,13 @@
|
|
|
5069
5107
|
"reason": "not listed in api.include",
|
|
5070
5108
|
"objectName": "@happyvertical/smrt-messages:Email"
|
|
5071
5109
|
},
|
|
5110
|
+
{
|
|
5111
|
+
"kind": "api",
|
|
5112
|
+
"operation": "getHandledBy",
|
|
5113
|
+
"code": "not-included",
|
|
5114
|
+
"reason": "not listed in api.include",
|
|
5115
|
+
"objectName": "@happyvertical/smrt-messages:Email"
|
|
5116
|
+
},
|
|
5072
5117
|
{
|
|
5073
5118
|
"kind": "api",
|
|
5074
5119
|
"operation": "getHeaders",
|
|
@@ -5403,6 +5448,14 @@
|
|
|
5403
5448
|
"columnType": "BOOLEAN",
|
|
5404
5449
|
"default": false,
|
|
5405
5450
|
"description": "Whether more mail was still waiting after the last check."
|
|
5451
|
+
},
|
|
5452
|
+
{
|
|
5453
|
+
"name": "agentSendPolicy",
|
|
5454
|
+
"type": "text",
|
|
5455
|
+
"required": false,
|
|
5456
|
+
"columnType": "TEXT",
|
|
5457
|
+
"readonly": true,
|
|
5458
|
+
"description": "Whether an assistant may send from this mailbox on its own, or needs a person to approve each message first."
|
|
5406
5459
|
}
|
|
5407
5460
|
],
|
|
5408
5461
|
"relationships": [
|
|
@@ -6842,6 +6895,30 @@
|
|
|
6842
6895
|
"columnType": "UUID",
|
|
6843
6896
|
"description": "The earlier message this one replies to."
|
|
6844
6897
|
},
|
|
6898
|
+
{
|
|
6899
|
+
"name": "handledById",
|
|
6900
|
+
"type": "text",
|
|
6901
|
+
"required": false,
|
|
6902
|
+
"columnType": "TEXT",
|
|
6903
|
+
"readonly": true,
|
|
6904
|
+
"description": "The person or assistant who last acted on this message."
|
|
6905
|
+
},
|
|
6906
|
+
{
|
|
6907
|
+
"name": "handledByKind",
|
|
6908
|
+
"type": "text",
|
|
6909
|
+
"required": false,
|
|
6910
|
+
"columnType": "TEXT",
|
|
6911
|
+
"readonly": true,
|
|
6912
|
+
"description": "Whether a person or an assistant last acted on this message."
|
|
6913
|
+
},
|
|
6914
|
+
{
|
|
6915
|
+
"name": "handledAt",
|
|
6916
|
+
"type": "datetime",
|
|
6917
|
+
"required": false,
|
|
6918
|
+
"columnType": "TIMESTAMP",
|
|
6919
|
+
"readonly": true,
|
|
6920
|
+
"description": "When someone last acted on this message."
|
|
6921
|
+
},
|
|
6845
6922
|
{
|
|
6846
6923
|
"name": "createdAt",
|
|
6847
6924
|
"type": "text",
|
|
@@ -6895,6 +6972,7 @@
|
|
|
6895
6972
|
"getAccount",
|
|
6896
6973
|
"getAttachments",
|
|
6897
6974
|
"getEndpoint",
|
|
6975
|
+
"getHandledBy",
|
|
6898
6976
|
"getMetadata",
|
|
6899
6977
|
"getPreview",
|
|
6900
6978
|
"getThreadMessages",
|
|
@@ -6955,6 +7033,10 @@
|
|
|
6955
7033
|
"async": true,
|
|
6956
7034
|
"returns": "any"
|
|
6957
7035
|
},
|
|
7036
|
+
{
|
|
7037
|
+
"name": "getHandledBy",
|
|
7038
|
+
"returns": "object | null"
|
|
7039
|
+
},
|
|
6958
7040
|
{
|
|
6959
7041
|
"name": "getMetadata",
|
|
6960
7042
|
"returns": "Record<string, unknown>"
|
|
@@ -7190,6 +7272,12 @@
|
|
|
7190
7272
|
"operation": "send",
|
|
7191
7273
|
"objectName": "@happyvertical/smrt-messages:Message"
|
|
7192
7274
|
},
|
|
7275
|
+
{
|
|
7276
|
+
"kind": "cli",
|
|
7277
|
+
"name": "message_getHandledBy",
|
|
7278
|
+
"operation": "getHandledBy",
|
|
7279
|
+
"objectName": "@happyvertical/smrt-messages:Message"
|
|
7280
|
+
},
|
|
7193
7281
|
{
|
|
7194
7282
|
"kind": "cli",
|
|
7195
7283
|
"name": "message_isSendOutcomeUnknown",
|
|
@@ -7276,6 +7364,13 @@
|
|
|
7276
7364
|
"reason": "not listed in api.include",
|
|
7277
7365
|
"objectName": "@happyvertical/smrt-messages:Message"
|
|
7278
7366
|
},
|
|
7367
|
+
{
|
|
7368
|
+
"kind": "api",
|
|
7369
|
+
"operation": "getHandledBy",
|
|
7370
|
+
"code": "not-included",
|
|
7371
|
+
"reason": "not listed in api.include",
|
|
7372
|
+
"objectName": "@happyvertical/smrt-messages:Message"
|
|
7373
|
+
},
|
|
7279
7374
|
{
|
|
7280
7375
|
"kind": "api",
|
|
7281
7376
|
"operation": "getMetadata",
|
|
@@ -8657,6 +8752,30 @@
|
|
|
8657
8752
|
"columnType": "UUID",
|
|
8658
8753
|
"description": "The earlier message this one replies to."
|
|
8659
8754
|
},
|
|
8755
|
+
{
|
|
8756
|
+
"name": "handledById",
|
|
8757
|
+
"type": "text",
|
|
8758
|
+
"required": false,
|
|
8759
|
+
"columnType": "TEXT",
|
|
8760
|
+
"readonly": true,
|
|
8761
|
+
"description": "The person or assistant who last acted on this message."
|
|
8762
|
+
},
|
|
8763
|
+
{
|
|
8764
|
+
"name": "handledByKind",
|
|
8765
|
+
"type": "text",
|
|
8766
|
+
"required": false,
|
|
8767
|
+
"columnType": "TEXT",
|
|
8768
|
+
"readonly": true,
|
|
8769
|
+
"description": "Whether a person or an assistant last acted on this message."
|
|
8770
|
+
},
|
|
8771
|
+
{
|
|
8772
|
+
"name": "handledAt",
|
|
8773
|
+
"type": "datetime",
|
|
8774
|
+
"required": false,
|
|
8775
|
+
"columnType": "TIMESTAMP",
|
|
8776
|
+
"readonly": true,
|
|
8777
|
+
"description": "When someone last acted on this message."
|
|
8778
|
+
},
|
|
8660
8779
|
{
|
|
8661
8780
|
"name": "createdAt",
|
|
8662
8781
|
"type": "text",
|
|
@@ -8768,6 +8887,7 @@
|
|
|
8768
8887
|
"getAttachments",
|
|
8769
8888
|
"getBlocks",
|
|
8770
8889
|
"getEndpoint",
|
|
8890
|
+
"getHandledBy",
|
|
8771
8891
|
"getMetadata",
|
|
8772
8892
|
"getPreview",
|
|
8773
8893
|
"getReactions",
|
|
@@ -8799,14 +8919,14 @@
|
|
|
8799
8919
|
},
|
|
8800
8920
|
{
|
|
8801
8921
|
"name": "createForward",
|
|
8802
|
-
"returns": "
|
|
8922
|
+
"returns": "SlackMessage"
|
|
8803
8923
|
},
|
|
8804
8924
|
{
|
|
8805
8925
|
"name": "createReply",
|
|
8806
8926
|
"params": [
|
|
8807
|
-
"
|
|
8927
|
+
"options?: object"
|
|
8808
8928
|
],
|
|
8809
|
-
"returns": "
|
|
8929
|
+
"returns": "SlackMessage"
|
|
8810
8930
|
},
|
|
8811
8931
|
{
|
|
8812
8932
|
"name": "delete",
|
|
@@ -8835,6 +8955,10 @@
|
|
|
8835
8955
|
"async": true,
|
|
8836
8956
|
"returns": "any"
|
|
8837
8957
|
},
|
|
8958
|
+
{
|
|
8959
|
+
"name": "getHandledBy",
|
|
8960
|
+
"returns": "object | null"
|
|
8961
|
+
},
|
|
8838
8962
|
{
|
|
8839
8963
|
"name": "getMetadata",
|
|
8840
8964
|
"returns": "Record<string, unknown>"
|
|
@@ -9079,6 +9203,12 @@
|
|
|
9079
9203
|
"operation": "send",
|
|
9080
9204
|
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
9081
9205
|
},
|
|
9206
|
+
{
|
|
9207
|
+
"kind": "cli",
|
|
9208
|
+
"name": "slackmessage_getHandledBy",
|
|
9209
|
+
"operation": "getHandledBy",
|
|
9210
|
+
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
9211
|
+
},
|
|
9082
9212
|
{
|
|
9083
9213
|
"kind": "cli",
|
|
9084
9214
|
"name": "slackmessage_isSendOutcomeUnknown",
|
|
@@ -9196,6 +9326,13 @@
|
|
|
9196
9326
|
"reason": "not listed in api.include",
|
|
9197
9327
|
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
9198
9328
|
},
|
|
9329
|
+
{
|
|
9330
|
+
"kind": "api",
|
|
9331
|
+
"operation": "getHandledBy",
|
|
9332
|
+
"code": "not-included",
|
|
9333
|
+
"reason": "not listed in api.include",
|
|
9334
|
+
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
9335
|
+
},
|
|
9199
9336
|
{
|
|
9200
9337
|
"kind": "api",
|
|
9201
9338
|
"operation": "getMetadata",
|
|
@@ -9880,6 +10017,30 @@
|
|
|
9880
10017
|
"columnType": "UUID",
|
|
9881
10018
|
"description": "The earlier message this one replies to."
|
|
9882
10019
|
},
|
|
10020
|
+
{
|
|
10021
|
+
"name": "handledById",
|
|
10022
|
+
"type": "text",
|
|
10023
|
+
"required": false,
|
|
10024
|
+
"columnType": "TEXT",
|
|
10025
|
+
"readonly": true,
|
|
10026
|
+
"description": "The person or assistant who last acted on this message."
|
|
10027
|
+
},
|
|
10028
|
+
{
|
|
10029
|
+
"name": "handledByKind",
|
|
10030
|
+
"type": "text",
|
|
10031
|
+
"required": false,
|
|
10032
|
+
"columnType": "TEXT",
|
|
10033
|
+
"readonly": true,
|
|
10034
|
+
"description": "Whether a person or an assistant last acted on this message."
|
|
10035
|
+
},
|
|
10036
|
+
{
|
|
10037
|
+
"name": "handledAt",
|
|
10038
|
+
"type": "datetime",
|
|
10039
|
+
"required": false,
|
|
10040
|
+
"columnType": "TIMESTAMP",
|
|
10041
|
+
"readonly": true,
|
|
10042
|
+
"description": "When someone last acted on this message."
|
|
10043
|
+
},
|
|
9883
10044
|
{
|
|
9884
10045
|
"name": "createdAt",
|
|
9885
10046
|
"type": "text",
|
|
@@ -9993,6 +10154,7 @@
|
|
|
9993
10154
|
"getAttachments",
|
|
9994
10155
|
"getEndpoint",
|
|
9995
10156
|
"getEngagement",
|
|
10157
|
+
"getHandledBy",
|
|
9996
10158
|
"getHashtags",
|
|
9997
10159
|
"getMediaUrls",
|
|
9998
10160
|
"getMentions",
|
|
@@ -10060,6 +10222,10 @@
|
|
|
10060
10222
|
"name": "getEngagement",
|
|
10061
10223
|
"returns": "number"
|
|
10062
10224
|
},
|
|
10225
|
+
{
|
|
10226
|
+
"name": "getHandledBy",
|
|
10227
|
+
"returns": "object | null"
|
|
10228
|
+
},
|
|
10063
10229
|
{
|
|
10064
10230
|
"name": "getHashtags",
|
|
10065
10231
|
"returns": "string[]"
|
|
@@ -10304,6 +10470,12 @@
|
|
|
10304
10470
|
"operation": "send",
|
|
10305
10471
|
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
10306
10472
|
},
|
|
10473
|
+
{
|
|
10474
|
+
"kind": "cli",
|
|
10475
|
+
"name": "tweet_getHandledBy",
|
|
10476
|
+
"operation": "getHandledBy",
|
|
10477
|
+
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
10478
|
+
},
|
|
10307
10479
|
{
|
|
10308
10480
|
"kind": "cli",
|
|
10309
10481
|
"name": "tweet_isSendOutcomeUnknown",
|
|
@@ -10421,6 +10593,13 @@
|
|
|
10421
10593
|
"reason": "not listed in api.include",
|
|
10422
10594
|
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
10423
10595
|
},
|
|
10596
|
+
{
|
|
10597
|
+
"kind": "api",
|
|
10598
|
+
"operation": "getHandledBy",
|
|
10599
|
+
"code": "not-included",
|
|
10600
|
+
"reason": "not listed in api.include",
|
|
10601
|
+
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
10602
|
+
},
|
|
10424
10603
|
{
|
|
10425
10604
|
"kind": "api",
|
|
10426
10605
|
"operation": "getHashtags",
|
|
@@ -12649,6 +12828,12 @@
|
|
|
12649
12828
|
"operation": "send",
|
|
12650
12829
|
"objectName": "@happyvertical/smrt-messages:Email"
|
|
12651
12830
|
},
|
|
12831
|
+
{
|
|
12832
|
+
"kind": "cli",
|
|
12833
|
+
"name": "email_getHandledBy",
|
|
12834
|
+
"operation": "getHandledBy",
|
|
12835
|
+
"objectName": "@happyvertical/smrt-messages:Email"
|
|
12836
|
+
},
|
|
12652
12837
|
{
|
|
12653
12838
|
"kind": "cli",
|
|
12654
12839
|
"name": "email_isSendOutcomeUnknown",
|
|
@@ -13215,6 +13400,12 @@
|
|
|
13215
13400
|
"operation": "send",
|
|
13216
13401
|
"objectName": "@happyvertical/smrt-messages:Message"
|
|
13217
13402
|
},
|
|
13403
|
+
{
|
|
13404
|
+
"kind": "cli",
|
|
13405
|
+
"name": "message_getHandledBy",
|
|
13406
|
+
"operation": "getHandledBy",
|
|
13407
|
+
"objectName": "@happyvertical/smrt-messages:Message"
|
|
13408
|
+
},
|
|
13218
13409
|
{
|
|
13219
13410
|
"kind": "cli",
|
|
13220
13411
|
"name": "message_isSendOutcomeUnknown",
|
|
@@ -13515,6 +13706,12 @@
|
|
|
13515
13706
|
"operation": "send",
|
|
13516
13707
|
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
13517
13708
|
},
|
|
13709
|
+
{
|
|
13710
|
+
"kind": "cli",
|
|
13711
|
+
"name": "slackmessage_getHandledBy",
|
|
13712
|
+
"operation": "getHandledBy",
|
|
13713
|
+
"objectName": "@happyvertical/smrt-messages:SlackMessage"
|
|
13714
|
+
},
|
|
13518
13715
|
{
|
|
13519
13716
|
"kind": "cli",
|
|
13520
13717
|
"name": "slackmessage_isSendOutcomeUnknown",
|
|
@@ -13759,6 +13956,12 @@
|
|
|
13759
13956
|
"operation": "send",
|
|
13760
13957
|
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
13761
13958
|
},
|
|
13959
|
+
{
|
|
13960
|
+
"kind": "cli",
|
|
13961
|
+
"name": "tweet_getHandledBy",
|
|
13962
|
+
"operation": "getHandledBy",
|
|
13963
|
+
"objectName": "@happyvertical/smrt-messages:Tweet"
|
|
13964
|
+
},
|
|
13762
13965
|
{
|
|
13763
13966
|
"kind": "cli",
|
|
13764
13967
|
"name": "tweet_isSendOutcomeUnknown",
|
|
@@ -14027,8 +14230,13 @@
|
|
|
14027
14230
|
"polymorphicAssociations": 0,
|
|
14028
14231
|
"uuidColumns": 138
|
|
14029
14232
|
},
|
|
14030
|
-
"agentDoc": "# @happyvertical/smrt-messages\n\nMulti-channel messaging with STI hierarchies for both messages and accounts. Credential encryption via smrt-secrets.\n\n## STI Hierarchies\n\n**Messages** (share `messages` table):\n- `Message` (base): accountId, personaId, endpointId, correlationId, threadId, subject, body, fromAddress, toAddresses (JSON), sendStatus (draft/sending/sent/failed), retryCount\n- `Email`: messageId (RFC 822), inReplyTo, ccAddresses, bccAddresses, htmlBody, textBody, folderId, labels, headers\n- `Tweet`: tweetId, retweetCount, likeCount, mediaUrls, hashtags, mentions\n- `SlackMessage`: channelId, slackTs, slackThreadTs, reactions, blocks\n\n**Accounts** (share `accounts` table):\n- `Account` (base): channelType, providerType, public configuration,\n credentialSecretId, isActive, lastSyncAt, deprecated sensitive settings\n- `EmailAccount`, `TwitterAccount`, `SlackAccount`, `ZulipAccount`,\n `TelegramAccount`: provider-specific identity/sender behavior\n\n## Persona messaging\n\n- `MessagingEndpoint`: tenant-owned, write-only destination JSON with masked\n display helper.\n- `PersonaMessageRoute`: persona → account + endpoint, selected by purpose and\n descending priority.\n- `PersonaMessagingService`: persists and sends through an enabled route.\n- Provider registry: public setup descriptors + optional sender factory. Keep\n channel (`sms`) separate from provider (`twilio`).\n- Permissions: `messages.send`, `messages.manage-routes`,\n `messages.manage-credentials`.\n- `MessagingSettingsService` is the permissioned server boundary;\n its host-supplied `resolvePersonaTenantId` proves cross-package ownership.\n `MessagingSettingsPanel` is the callback-driven Svelte surface.\n- Account, endpoint, and route generated surfaces are read-only. Do not add\n generated mutations around the settings service or make secret fields writable.\n- **Recipe `messages.slack`** (`src/recipes.ts`, help in `src/help/slack.md`): lists Slack messages and workspaces beside the Mailbox and Notifications recipes; workspaces stay read-only and sending goes through the senders, not generated routes. Fields it shows carry `@field({ description })` in plain words; keep them when editing the models.\n\n## Per-account mail access (owner + grants)\n\nOptional by default: `Account.ownerUserId` is nullable, and an account without\nan owner stays tenant-wide. Apps that want private or shared mailboxes set\nowners and call `configureMailAccess({ options, resolvePrincipal })` at startup\n(`access.ts`); smrt never knows the host's credential model, the host returns a\n`MailPrincipal` (`userId` + tenant, optional `scopes` / `accountIds` ceilings).\n\n- Scopes `read`, `triage`, `draft`, `send` are `ResourceGrant` rows (resource\n type `messages:account`, permission `messages.<scope>`) checked by\n `checkResourceOperationPermission`, so the grantee also needs the tenant\n `messages.<scope>` permission (the ceiling). The owner holds every scope\n implicitly. Agents are `User` rows the host maps its credential to; the\n principal ceilings are intersected with the grant, never added to it.\n- `access-enforcement.ts` is a `GlobalInterceptors` entry registered at package\n load. Emails, folders and attachments (matched by STI ancestry) are filtered\n in `beforeList`/`afterList`/`afterGet`; raw `query()` on them is refused while\n any account is closed to the principal. Fail closed: no principal, no\n resolver or a foreign tenant means owned accounts are invisible. No tenant\n admin or super-admin bypass; trusted work (sync, outbox) uses\n `runWithMailSystemAccess()`. `EmailAccount.syncFrom()` does so itself.\n- Attachments carry a denormalized `accountId` (always derived from the message in a\n `beforeSave` interceptor, never caller-supplied) so lists, projections and counts filter in SQL; run\n `AttachmentCollection.backfillAccountIds()` once after upgrading (legacy rows\n without it are hidden from every read until then).\n- `connectMailbox` refuses by default: give the service `allowedMailHosts`\n (and optionally `allowedMailPorts`) or your own `validateMailbox`. The\n built-in validator never connects to private, loopback or link-local\n addresses and returns only a generic error. It checks every target field\n present (`host`, `endpoint`, and the `jmap` provider's `url`): https only, no\n userinfo, listed host and port. The `jmap` provider stays `available: false`\n on purpose (`available` means outbound transport; JMAP is receive and sync\n only), and `connectMailbox` still connects it. Policy lookups use the\n configured db handle, not a caller's transaction.\n- `Message.send()` needs the `send` scope on an owned account. Account rows are\n not filtered (senders, routes and the outbox read them without a principal).\n- `MailAccessService` (`grant`, `revoke`, `list`, `setOwner`) needs tenant\n `messages.manage-access` AND ownership (or delegation); an administrator\n cannot read, self-grant or take over an owned mailbox. Unowned accounts can be\n claimed once with `messages.manage-credentials`.\n- `MessagingSettingsService.listAccounts({ limit, cursor })` is the account\n discovery for a principal: only accounts it owns or holds an active grant on\n (never unowned or foreign accounts), with effective `scopes` and\n `relation: 'owner' | 'shared'`, via `decideMailAccess`. Fail closed with no\n principal user, a tenant mismatch or no `configureMailAccess`.\n- `seedMessagesRolePermissions({ db })` seeds the tenant `messages.*` slugs for\n the system roles (owner/admin: read, triage, draft, send, manage-credentials,\n manage-access; member: the four scopes; viewer: read). Idempotent, additive,\n system roles only; without it grants and `manage-access` fail closed on a\n fresh app. The matrix is `MESSAGES_ROLE_PERMISSION_MATRIX`.\n- Before `configureMailAccess` is called the policy still fails closed on\n owned accounts: every collection operation on a mail class (the core `onCollectionReady`\n interceptor hook, so STI subclasses on a default collection are covered) registers its\n database, per database, and the policy hides every owned account's mail\n through list, count, projections, facets and raw queries; it learns the database from the first mail or account row it\n sees and, with no principal resolver, hides every owned account's mail.\n Direct hydration (`new Email({ id }).initialize()`, `loadRelated()`) is gated\n in the models' `loadFromId`/`loadFromSlug`.\n- `connectionStatus` (`connected` / `needs_reconnect`) and `statusMessage` mark\n an account whose sign-in the server refused; `syncFrom()` sets it.\n\n## Mail search and private correspondents (#5132)\n\n`MailSearchService` searches only `read`-scoped accounts from `listAccounts()`;\n`CorrespondentService` derives owner-private contacts (optional `Profile` link).\nBoth fail closed. Details: [agents/mail-search.md](agents/mail-search.md).\n\n## Mailbox connect (provider-neutral)\n\nCredentials reach smrt-secrets in two ways; neither writes the plaintext `settings` fallback.\n\n- **Write-only app password**: `MessagingSettingsService.connectMailbox()`\n (permission `messages.manage-credentials`). The candidate credential is\n validated by opening a session first (`validateMailbox` option, default the\n provider's email client); a refusal leaves no account and no secret, and the\n error text has the secret redacted. The connecting user becomes the owner;\n `label` and the per-account endpoint (`configuration`) are stored; reconnect\n replaces the secret and is owner-only. `setAccountActive()` pauses/resumes\n (`isActive`), `removeAccount()` deletes the secret, the synced mail and the\n account. IMAP/POP3 are admitted here (receive-only), not by `saveAccount`.\n- **Generic OAuth 2.0 / OIDC**: `@happyvertical/smrt-messages/connect`\n (`startMailOAuthConnect`, `completeMailOAuthConnect`, `MailOAuthProvider`)\n on the shared kernel `@happyvertical/smrt-secrets/connect` (single-use\n tenant- and user-bound `ConnectState`, PKCE, safe return path, OIDC\n discovery with issuer check). The signed-in user becomes the owner; an\n account owned by someone else or by no one is never taken over. No role\n checks in the flow: authorize before calling.\n- **Reconnect**: `syncFrom()` marks an auth failure `connectionStatus =\n 'needs_reconnect'` (`Account.markNeedsReconnect/markConnected`) instead of\n failing silently.\n- The Google provider is a later step (sdk#1405), not part of this flow.\n\n## In-app notifications (`UserNotification`)\n\nThe in-app channel: one stored row per person, with read state.\n`user_notifications`: `tenantId` (required), `recipientUserId`\n(`@crossPackageRef` smrt-users:User, uuid), `kind`, `title`, `body`, `href`,\n`severity` (info/success/warning/error), `sourceRef`, `occurredAt`, `readAt`,\n`dismissedAt`. Conflict identity `(tenant_id, recipient_user_id, source_ref)`.\n\n- `UserNotificationService` is the only access path: `notify()` /\n `notifyMany()` (dedupe on `sourceRef`, existing row returned untouched;\n a unique ref is generated when omitted), `listForUser()` / `countUnread()`\n across explicit `tenantIds` (each read under `withTenant`), `markRead()`,\n `dismiss()` (also marks read), `markAllRead()`. Every write filters on the\n recipient, so another user's id matches nothing.\n- Generated REST/MCP/CLI are off (`api`/`mcp`/`cli: false`): a tenant-scoped\n list would expose every member's rows. Hosts expose their own routes that\n pass the signed-in user's id, never a request-chosen one.\n- Hosts decide who is told (e.g. `SocialPost.createdByUserId` for a failed\n post). New table: consumers run `db:migrate`.\n\n## Notification email outbox (`NotificationDelivery`)\n\n`NotificationOutboxService` is the external-channel counterpart of\n`UserNotificationService`: `enqueueEmail()` stores one delivery per\n`(tenant, recipient, channel, sourceRef)` after the host resolves the\nrecipient address and same-tenant sender account (callers never choose an\naddress); `dispatchDue()` leases due rows by compare-and-set\n(`NotificationDelivery.transition()`), creates the single outbound `Email`\nunder the lease, and settles sent/retry/failed/uncertain. Never resend an\n`uncertain` row automatically. Contract, retry, and reconciliation policy:\n[agents/notification-outbox.md](agents/notification-outbox.md). New table:\nconsumers run `db:migrate`.\n\n`NotificationOptOut` (`notification_opt_outs`, tenant-required, generated\nsurfaces off) is the per-recipient opt-out ledger for the outbox's\n`isSuppressed` hook, keyed `(tenant, recipient, channel, scope)` with scope `*`\nor `project:<uuid>`-style keys. `NotificationOptOutService`: idempotent\n`optOut`/`optIn` (with a `principal` only `userId === recipientUserId` may\nchange a row, and only in the principal's own `tenantId`, else\n`NotificationOptOutDeniedError`; no principal = trusted host code), trusted `isOptedOut` (a `*` row matches every scope), `listForRecipient`\n(principal required). `optOutSuppression(service, scopeOf)` builds the\n`isSuppressed` function. Details in the outbox doc; consumers run `db:migrate`.\n\n## Credential Security\n\nAccount credentials stored via tenant-bound `credentialSecretId` →\nsmrt-secrets. Use `setCredentials()`/`getCredentials()` — never store passwords\ndirectly. Credential descriptor schemas contain field definitions, never values.\n\n## Send Lifecycle\n\n`message.send()`: resolves account → creates provider sender → updates sendStatus. Retry support with `maxRetries` budget.\nA failure the provider may still have accepted carries\n`MessageSendResult.outcomeUnknown` (set by `EmailSender` unless\n`isDefiniteSendRejection()` proves a refusal, and when a sender throws) and is\npersisted as `metadata.sendOutcomeUnknown`; never auto-resend it.\n`EmailSender` attaches the message's stored `Attachment` rows (read through\n`Attachment.readContent()`, under the message's tenant context) plus\n`SendEmailOptions.attachments` bytes; an unreadable or file-less row fails the\nsend with the error on `sendError`, never a silent drop (#3808).\n`PersonaMessagingService.send({ attachments })` accepts them on email routes only.\n\n## Provider entry points (bundle boundary, #1979)\n\nThe package root is provider-neutral: models, collections, services,\npermissions, and the provider registry carry **zero provider-SDK weight**.\nProvider SDK wrappers (`@happyvertical/email`, `@happyvertical/messages`) are\nreachable only through explicit entry points, imported once at server startup:\n\n```ts\nimport '@happyvertical/smrt-messages/providers/email'; // smtp/imap/pop3/gmail\nimport '@happyvertical/smrt-messages/providers/slack';\nimport '@happyvertical/smrt-messages/providers/twitter';\nimport '@happyvertical/smrt-messages/providers/all'; // all of the above\n```\n\n- Without the matching entry, `EmailAccount.createClient()` (send + mailbox\n sync) throws an actionable error and `SlackSender`/`TweetSender` return a\n failure result naming the entry to import. Telegram and Zulip are\n fetch-based and always work from the root.\n- Builtin registry definitions stay metadata-only (setup fields for UIs); the\n entries upgrade them with `createEmailClient`/`createMessageClient`/\n `createSender` hooks. Never import a provider SDK from any module reachable\n from `src/index.ts` — the consumer bundle gate (`packages/bundle-gate`)\n fails CI when one becomes reachable.\n- `Attachment.readContent()` loads `@happyvertical/files` through core's\n `importOptionalDependency` boundary and keeps its null-on-failure contract\n in builds where the SDK is absent.\n\n## Gotchas\n\n- **Manifest before decorators**: every decorated model imports\n `../__smrt-register__.js`, and `package.json#sideEffects` lists\n `./src/__smrt-register__.ts`. Without both, the library build dropped or\n reordered the self-registration, so dist classes registered with only their\n decorated fields and could adopt smrt-ledgers' same-named `Account` (#3098).\n- **`Account` is not unique**: smrt-ledgers also declares `Account` (on\n `ledger_accounts`). Resolve by constructor or qualified name; the\n coexistence tests (`ledger-account-identity-*`, and the PostgreSQL lane\n `pnpm test:postgres`) load both packages in both orders.\n Both declare the `accounts` collection, so registering the ledgers `Account`\n auto-loads this family from its manifest as STI siblings. Core loads this\n base with them and never takes the ledgers `Account` for it (#4735,\n `ledger-account-identity-sti-siblings.test.ts`).\n- **STI `_meta_type`**: qualified format `@happyvertical/smrt-messages:Email`\n- **JSON fields**: all address/metadata fields are JSON strings with `getX()`/`setX()` helpers\n- **RFC 822 threading**: Email uses `inReplyTo`/`messageId`/`references` — manual management required\n- **Attachment.messageId**: use this field (not `emailId`); old getter/setter mapped via deprecation wrapper\n- **Optional tenancy**: `@TenantScoped({ mode: 'optional' })` on Message, Account, Attachment\n- **Required tenancy**: endpoints and persona routes are always tenant scoped\n- **Secrets are write-only**: never serialize credentials or endpoint.address to an app\n\n## Intake byte snapshots\n\n`EmailAccount.readIntakeMessage(providerLookup, maxBytes, imapIdentity?)` is the authorized host seam for\nopt-in ingestion. It copies full-message attachment bytes from the registered\nemail provider and fails when only attachment metadata is available; it never\nreads provider-supplied paths or advances sync checkpoints. Keep this path\nprovider-neutral and exclude arbitrary headers/credentials from its snapshot.\nIMAP lookup must include folder/UIDVALIDITY/UID verification; sender Message-ID\nis a lookup hint, never the durable delivery identity.\n\nProtected notification Emails carry durable delivery provenance. Their canonical\n`send`/`retrySend`, ordinary save/delete, and default EmailSender handoff are\nconstrained by `protected-notification-handoff.ts` (package-private, never a root\nexport). Only the outbox enters its exact one-use scope after current trusted\npolicy/byte validation. Preserve old-row/constructor identity checks, current\npersisted lease checks at the actual provider boundary, copied byte buffers and\nunknown-outcome marker protection. See the outbox contract and shared protected\nhandoff suite (SQLite and migrated PostgreSQL).\n\n## Protected external contacts\n\nProfile email uses exclusive `recipientProfileId` plus `resolveProfileRecipient`, a reserved `profileNotificationPolicy` and exact current tenant-owned public Profile email. No User account is required. Before activating profiles, run normal framework schema migration and public `planNotificationProfileRecipients` / `migrateNotificationProfileRecipients`; runtime verifies physical constraints and never applies DDL. Legacy User notification and opt-out paths remain User-only. See [profile recipient contract and matrix](agents/profile-recipients.md).\n\n## Incremental mail sync (change feed)\n\n`EmailAccount.syncChanges({ limit?, maxBatches?, since? })` (`mail-sync.ts`) drives\n`EmailClient.getChanges()` (JMAP provider `jmap`; `@happyvertical/email` 0.114+).\n`syncFrom()` stays the polling path for IMAP/POP3.\n\n- `EmailAccount.syncCursor` is the opaque feed cursor (sensitive + readonly, never\n on generated surfaces). It is saved only after its batch is applied; a failure\n anywhere leaves it where it was, so the job just retries.\n- Rows are keyed on `Email.providerMessageId` (the server's own id, per account),\n so applying a batch twice changes nothing. Added/changed messages upsert,\n `removed` deletes, `folders` upserts `EmailFolder` by path and counts are\n recomputed for touched folders. Metadata-only changes keep stored bodies.\n- `resync-required` clears the cursor and runs a full pass in the same run; a\n full pass from no cursor deletes stored messages (with a `providerMessageId`)\n the server no longer has. A second resync request in one run throws.\n- One lane per account: runs queue behind each other in-process, work on the\n stored (revision-guarded) row, and the job is deduplicated per tenant+account.\n Inactive and `needs_reconnect` accounts, and clients without `getChanges`,\n return `{ status: 'skipped' }`. Auth failures call `markNeedsReconnect()` and\n throw with `retryable: false`. The sync runs under `runWithMailSystemAccess()`.\n- Job: `enqueueMailSync(account)` / `enqueueDueMailSyncs(accounts)`\n (`mail-sync-jobs.ts`, queue `mail-sync`, dedupe key `mail-sync:<accountId>`)\n target `EmailAccount.syncChanges` through `@happyvertical/smrt-jobs` (optional\n peer). The host runs the `TaskRunner` and schedules `enqueueDueMailSyncs`.\n- Backfill horizon (#5200): optional `EmailAccount.backfillSince` (null = whole\n mailbox, the default) or per-run `since` (`Date`/ISO string, `null` lifts the\n stored one; `enqueueMailSync({ since })` forwards it as an ISO string). A\n message dated before it is not stored unless it already is; undated mail is\n kept; `MailSyncResult.beforeHorizon` counts the skips. The SDK change feed\n cannot filter by date, so the server still sends the older mail and it is\n dropped here (saves rows, not transfer; a server-side horizon needs an SDK change).\n- Horizon vs cursor: `cursorHorizon` records the horizon the saved cursor was\n built under (null = unbounded, also legacy cursors). If a run's effective\n horizon is earlier than it, or cleared (`since: null`), the cursor is dropped\n and the run does a full pass with prune; narrowing or an unchanged horizon\n keeps the cursor.\n- Persisted health (#5200): `lastSyncError` is set on any failed run (also\n client-build failures and sign-in refusals, which additionally set\n `needs_reconnect`) and cleared by the next successful run; a transient failure\n never changes `connectionStatus`. `backlog` mirrors `MailSyncResult.hasMore`\n of the last successful run. Both are plain optional columns (additive).\n- Known gaps: attachment rows are not created (only `hasAttachments`/`size`);\n a renamed server folder creates a new folder row (stored messages keep the old\n path until they change); `jmap` has no connect-flow validator yet and is not an\n outbound transport.\n\n## Triage write-back\n\n`EmailAccount.triage(action, emailIds)` (and `Email.triage(action)`,\n`mail-triage.ts`) writes mark read/unread, star/unstar, archive, spam/not spam,\nlabel add/remove and move to the server, then updates the local row. Actions are\n`{ kind: 'markRead' | 'markUnread' | 'star' | 'unstar' | 'archive' | 'markSpam' |\n'unmarkSpam' }`, `{ kind: 'addLabels' | 'removeLabels', labels }` and\n`{ kind: 'move', folder }`; ids are local `Email` row ids.\n\n- Access: needs `read` **and** `triage` on the account (`assertMailAccess`, fail\n closed; `MailAccessError`) before any server call or local write.\n- Server first, per message: the result is `{ updated, failed, stale }`. Only ids\n the server accepted are written; refusals (and ids that are missing, on another\n account, or not yet synced) come back in `failed`. A thrown client error\n changes nothing. Auth failures mark the account `needs_reconnect`.\n- Convergence: an accepted message is read back (`getMessage`) and stored through\n `applyServerMessage`, exactly as sync stores it, so the next sync is a no-op.\n If the read-back fails the id is `stale` and sync fixes the row. Triage runs in\n the account's sync lane (`inLane`), so it never interleaves with a sync here.\n- Providers whose `getCapabilities().writeBack` lacks the needed key (`flags`,\n `labels`, `archive`, `spam`) throw `MailWriteBackUnsupportedError` first.\n- `move` removes a message from the mailboxes it is in now (from its stored\n labels) and adds `folder`; pass a path as stored on `EmailFolder`.\n- Every public method on an `@smrt()` class becomes a `<collection>.<method>`\n permission; `Email.triage` is why `messages.triage` in `permissions.ts` carries\n the generated name and description (the catalog rejects two for one slug).\n- Known gaps: drafts and send, the acting principal is not recorded (#5141), and\n a mailbox the server has not reported yet has no `EmailFolder` row until sync.\n",
|
|
14233
|
+
"agentDoc": "# @happyvertical/smrt-messages\n\nMulti-channel messaging with STI hierarchies for both messages and accounts. Credential encryption via smrt-secrets.\n\n## STI Hierarchies\n\n**Messages** (share `messages` table):\n- `Message` (base): accountId, personaId, endpointId, correlationId, threadId, subject, body, fromAddress, toAddresses (JSON), sendStatus (draft/sending/sent/failed), retryCount\n- `Email`: messageId (RFC 822), inReplyTo, ccAddresses, bccAddresses, htmlBody, textBody, folderId, labels, headers\n- `Tweet`: tweetId, retweetCount, likeCount, mediaUrls, hashtags, mentions\n- `SlackMessage`: channelId, slackTs, slackThreadTs, reactions, blocks\n\n**Accounts** (share `accounts` table):\n- `Account` (base): channelType, providerType, public configuration,\n credentialSecretId, isActive, lastSyncAt, deprecated sensitive settings\n- `EmailAccount`, `TwitterAccount`, `SlackAccount`, `ZulipAccount`,\n `TelegramAccount`: provider-specific identity/sender behavior\n\n## Persona messaging\n\n- `MessagingEndpoint`: tenant-owned, write-only destination JSON with masked\n display helper.\n- `PersonaMessageRoute`: persona → account + endpoint, selected by purpose and\n descending priority.\n- `PersonaMessagingService`: persists and sends through an enabled route.\n- Provider registry: public setup descriptors + optional sender factory. Keep\n channel (`sms`) separate from provider (`twilio`).\n- Permissions: `messages.send`, `messages.manage-routes`,\n `messages.manage-credentials`.\n- `MessagingSettingsService` is the permissioned server boundary;\n its host-supplied `resolvePersonaTenantId` proves cross-package ownership.\n `MessagingSettingsPanel` is the callback-driven Svelte surface.\n- Account, endpoint, and route generated surfaces are read-only. Do not add\n generated mutations around the settings service or make secret fields writable.\n- **Recipe `messages.slack`** (`src/recipes.ts`, help in `src/help/slack.md`): lists Slack messages and workspaces beside the Mailbox and Notifications recipes; workspaces stay read-only and sending goes through the senders, not generated routes. Fields it shows carry `@field({ description })` in plain words; keep them when editing the models.\n\n## Per-account mail access (owner + grants)\n\nOptional by default: `Account.ownerUserId` is nullable, and an account without\nan owner stays tenant-wide. Apps that want private or shared mailboxes set\nowners and call `configureMailAccess({ options, resolvePrincipal })` at startup\n(`access.ts`); smrt never knows the host's credential model, the host returns a\n`MailPrincipal` (`userId` + tenant, optional `scopes` / `accountIds` ceilings).\n\n- Scopes `read`, `triage`, `draft`, `send` are `ResourceGrant` rows (resource\n type `messages:account`, permission `messages.<scope>`) checked by\n `checkResourceOperationPermission`, so the grantee also needs the tenant\n `messages.<scope>` permission (the ceiling). The owner holds every scope\n implicitly. Agents are `User` rows the host maps its credential to; the\n principal ceilings are intersected with the grant, never added to it.\n- `access-enforcement.ts` is a `GlobalInterceptors` entry registered at package\n load. Emails, folders and attachments (matched by STI ancestry) are filtered\n in `beforeList`/`afterList`/`afterGet`; raw `query()` on them is refused while\n any account is closed to the principal. Fail closed: no principal, no\n resolver or a foreign tenant means owned accounts are invisible. No tenant\n admin or super-admin bypass; trusted work (sync, outbox) uses\n `runWithMailSystemAccess()`. `EmailAccount.syncFrom()` does so itself.\n- Attachments carry a denormalized `accountId` (always derived from the message in a\n `beforeSave` interceptor, never caller-supplied) so lists, projections and counts filter in SQL; run\n `AttachmentCollection.backfillAccountIds()` once after upgrading (legacy rows\n without it are hidden from every read until then).\n- `connectMailbox` refuses by default: give the service `allowedMailHosts`\n (and optionally `allowedMailPorts`) or your own `validateMailbox`. The\n built-in validator never connects to private, loopback or link-local\n addresses and returns only a generic error. It checks every target field\n present (`host`, `endpoint`, and the `jmap` provider's `url`): https only, no\n userinfo, listed host and port. The `jmap` provider stays `available: false`\n on purpose (`available` means outbound transport; JMAP is receive and sync\n only), and `connectMailbox` still connects it. Policy lookups use the\n configured db handle, not a caller's transaction.\n- `Message.send()` needs the `send` scope on an owned account. Agent sends\n (principal `kind` other than `person`/`human`) on a mail account are held\n for a person's approval unless the owner opted in to `auto_send`;\n approve / edit-then-approve / reject / release (as an approving person,\n never the agent) through `MailSendApprovalService`,\n drafts through `MailDraftService`, \"handled by\" on every message. Gate,\n binding and bypass rules: [agents/send-approval.md](agents/send-approval.md). Account rows are\n not filtered (senders, routes and the outbox read them without a principal).\n- `MailAccessService` (`grant`, `revoke`, `list`, `setOwner`) needs tenant\n `messages.manage-access` AND ownership (or delegation); an administrator\n cannot read, self-grant or take over an owned mailbox. Unowned accounts can be\n claimed once with `messages.manage-credentials`.\n- `MessagingSettingsService.listAccounts({ limit, cursor })` is the account\n discovery for a principal: only accounts it owns or holds an active grant on\n (never unowned or foreign accounts), with effective `scopes` and\n `relation: 'owner' | 'shared'`, via `decideMailAccess`. Fail closed with no\n principal user, a tenant mismatch or no `configureMailAccess`.\n- `seedMessagesRolePermissions({ db })` seeds the tenant `messages.*` slugs for\n the system roles (owner/admin: read, triage, draft, send, manage-credentials,\n manage-access; member: the four scopes; viewer: read). Idempotent, additive,\n system roles only; without it grants and `manage-access` fail closed on a\n fresh app. The matrix is `MESSAGES_ROLE_PERMISSION_MATRIX`.\n- Before `configureMailAccess` is called the policy still fails closed on\n owned accounts: every collection operation on a mail class (the core `onCollectionReady`\n interceptor hook, so STI subclasses on a default collection are covered) registers its\n database, per database, and the policy hides every owned account's mail\n through list, count, projections, facets and raw queries; it learns the database from the first mail or account row it\n sees and, with no principal resolver, hides every owned account's mail.\n Direct hydration (`new Email({ id }).initialize()`, `loadRelated()`) is gated\n in the models' `loadFromId`/`loadFromSlug`.\n- `connectionStatus` (`connected` / `needs_reconnect`) and `statusMessage` mark\n an account whose sign-in the server refused; `syncFrom()` sets it.\n\n## Mail search and private correspondents (#5132)\n\n`MailSearchService` searches only `read`-scoped accounts from `listAccounts()`;\n`CorrespondentService` derives owner-private contacts (optional `Profile` link).\nBoth fail closed. Details: [agents/mail-search.md](agents/mail-search.md).\n\n## Mailbox connect (provider-neutral)\n\nCredentials reach smrt-secrets in two ways; neither writes the plaintext `settings` fallback.\n\n- **Write-only app password**: `MessagingSettingsService.connectMailbox()`\n (permission `messages.manage-credentials`). The candidate credential is\n validated by opening a session first (`validateMailbox` option, default the\n provider's email client); a refusal leaves no account and no secret, and the\n error text has the secret redacted. The connecting user becomes the owner;\n `label` and the per-account endpoint (`configuration`) are stored; reconnect\n replaces the secret and is owner-only. `setAccountActive()` pauses/resumes\n (`isActive`), `removeAccount()` deletes the secret, the synced mail and the\n account. IMAP/POP3 are admitted here (receive-only), not by `saveAccount`.\n- **Generic OAuth 2.0 / OIDC**: `@happyvertical/smrt-messages/connect`\n (`startMailOAuthConnect`, `completeMailOAuthConnect`, `MailOAuthProvider`)\n on the shared kernel `@happyvertical/smrt-secrets/connect` (single-use\n tenant- and user-bound `ConnectState`, PKCE, safe return path, OIDC\n discovery with issuer check). The signed-in user becomes the owner; an\n account owned by someone else or by no one is never taken over. No role\n checks in the flow: authorize before calling.\n- **Reconnect**: `syncFrom()` marks an auth failure `connectionStatus =\n 'needs_reconnect'` (`Account.markNeedsReconnect/markConnected`) instead of\n failing silently.\n- The Google provider is a later step (sdk#1405), not part of this flow.\n\n## In-app notifications (`UserNotification`)\n\nThe in-app channel: one stored row per person, with read state.\n`user_notifications`: `tenantId` (required), `recipientUserId`\n(`@crossPackageRef` smrt-users:User, uuid), `kind`, `title`, `body`, `href`,\n`severity` (info/success/warning/error), `sourceRef`, `occurredAt`, `readAt`,\n`dismissedAt`. Conflict identity `(tenant_id, recipient_user_id, source_ref)`.\n\n- `UserNotificationService` is the only access path: `notify()` /\n `notifyMany()` (dedupe on `sourceRef`, existing row returned untouched;\n a unique ref is generated when omitted), `listForUser()` / `countUnread()`\n across explicit `tenantIds` (each read under `withTenant`), `markRead()`,\n `dismiss()` (also marks read), `markAllRead()`. Every write filters on the\n recipient, so another user's id matches nothing.\n- Generated REST/MCP/CLI are off (`api`/`mcp`/`cli: false`): a tenant-scoped\n list would expose every member's rows. Hosts expose their own routes that\n pass the signed-in user's id, never a request-chosen one.\n- Hosts decide who is told (e.g. `SocialPost.createdByUserId` for a failed\n post). New table: consumers run `db:migrate`.\n\n## Notification email outbox (`NotificationDelivery`)\n\n`NotificationOutboxService` is the external-channel counterpart of\n`UserNotificationService`: `enqueueEmail()` stores one delivery per\n`(tenant, recipient, channel, sourceRef)` after the host resolves the\nrecipient address and same-tenant sender account (callers never choose an\naddress); `dispatchDue()` leases due rows by compare-and-set\n(`NotificationDelivery.transition()`), creates the single outbound `Email`\nunder the lease, and settles sent/retry/failed/uncertain. Never resend an\n`uncertain` row automatically. Contract, retry, and reconciliation policy:\n[agents/notification-outbox.md](agents/notification-outbox.md). New table:\nconsumers run `db:migrate`.\n\n`NotificationOptOut` (`notification_opt_outs`, tenant-required, generated\nsurfaces off) is the per-recipient opt-out ledger for the outbox's\n`isSuppressed` hook, keyed `(tenant, recipient, channel, scope)` with scope `*`\nor `project:<uuid>`-style keys. `NotificationOptOutService`: idempotent\n`optOut`/`optIn` (with a `principal` only `userId === recipientUserId` may\nchange a row, and only in the principal's own `tenantId`, else\n`NotificationOptOutDeniedError`; no principal = trusted host code), trusted `isOptedOut` (a `*` row matches every scope), `listForRecipient`\n(principal required). `optOutSuppression(service, scopeOf)` builds the\n`isSuppressed` function. Details in the outbox doc; consumers run `db:migrate`.\n\n## Credential Security\n\nAccount credentials stored via tenant-bound `credentialSecretId` →\nsmrt-secrets. Use `setCredentials()`/`getCredentials()` — never store passwords\ndirectly. Credential descriptor schemas contain field definitions, never values.\n\n## Send Lifecycle\n\n`message.send()`: resolves account → creates provider sender → updates sendStatus. Retry support with `maxRetries` budget.\nA failure the provider may still have accepted carries\n`MessageSendResult.outcomeUnknown` (set by `EmailSender` unless\n`isDefiniteSendRejection()` proves a refusal, and when a sender throws) and is\npersisted as `metadata.sendOutcomeUnknown`; never auto-resend it.\n`EmailSender` attaches the message's stored `Attachment` rows (read through\n`Attachment.readContent()`, under the message's tenant context) plus\n`SendEmailOptions.attachments` bytes; an unreadable or file-less row fails the\nsend with the error on `sendError`, never a silent drop (#3808).\n`PersonaMessagingService.send({ attachments })` accepts them on email routes only.\n\n## Provider entry points (bundle boundary, #1979)\n\nThe package root is provider-neutral: models, collections, services,\npermissions, and the provider registry carry **zero provider-SDK weight**.\nProvider SDK wrappers (`@happyvertical/email`, `@happyvertical/messages`) are\nreachable only through explicit entry points, imported once at server startup:\n\n```ts\nimport '@happyvertical/smrt-messages/providers/email'; // smtp/imap/pop3/gmail\nimport '@happyvertical/smrt-messages/providers/slack';\nimport '@happyvertical/smrt-messages/providers/twitter';\nimport '@happyvertical/smrt-messages/providers/all'; // all of the above\n```\n\n- Without the matching entry, `EmailAccount.createClient()` (send + mailbox\n sync) throws an actionable error and `SlackSender`/`TweetSender` return a\n failure result naming the entry to import. Telegram and Zulip are\n fetch-based and always work from the root.\n- Builtin registry definitions stay metadata-only (setup fields for UIs); the\n entries upgrade them with `createEmailClient`/`createMessageClient`/\n `createSender` hooks. Never import a provider SDK from any module reachable\n from `src/index.ts` — the consumer bundle gate (`packages/bundle-gate`)\n fails CI when one becomes reachable.\n- `Attachment.readContent()` loads `@happyvertical/files` through core's\n `importOptionalDependency` boundary and keeps its null-on-failure contract\n in builds where the SDK is absent.\n\n## Gotchas\n\n- **Manifest before decorators**: every decorated model imports\n `../__smrt-register__.js`, and `package.json#sideEffects` lists\n `./src/__smrt-register__.ts`. Without both, the library build dropped or\n reordered the self-registration, so dist classes registered with only their\n decorated fields and could adopt smrt-ledgers' same-named `Account` (#3098).\n- **`Account` is not unique**: smrt-ledgers also declares `Account` (on\n `ledger_accounts`). Resolve by constructor or qualified name; the\n coexistence tests (`ledger-account-identity-*`, and the PostgreSQL lane\n `pnpm test:postgres`) load both packages in both orders.\n Both declare the `accounts` collection, so registering the ledgers `Account`\n auto-loads this family from its manifest as STI siblings. Core loads this\n base with them and never takes the ledgers `Account` for it (#4735,\n `ledger-account-identity-sti-siblings.test.ts`).\n- **STI `_meta_type`**: qualified format `@happyvertical/smrt-messages:Email`\n- **JSON fields**: all address/metadata fields are JSON strings with `getX()`/`setX()` helpers\n- **RFC 822 threading**: Email uses `inReplyTo`/`messageId`/`references` — manual management required\n- **Attachment.messageId**: use this field (not `emailId`); old getter/setter mapped via deprecation wrapper\n- **Optional tenancy**: `@TenantScoped({ mode: 'optional' })` on Message, Account, Attachment\n- **Required tenancy**: endpoints and persona routes are always tenant scoped\n- **Secrets are write-only**: never serialize credentials or endpoint.address to an app\n\n## Intake byte snapshots\n\n`EmailAccount.readIntakeMessage(providerLookup, maxBytes, imapIdentity?)` is the authorized host seam for\nopt-in ingestion. It copies full-message attachment bytes from the registered\nemail provider and fails when only attachment metadata is available; it never\nreads provider-supplied paths or advances sync checkpoints. Keep this path\nprovider-neutral and exclude arbitrary headers/credentials from its snapshot.\nIMAP lookup must include folder/UIDVALIDITY/UID verification; sender Message-ID\nis a lookup hint, never the durable delivery identity.\n\nProtected notification Emails carry durable delivery provenance. Their canonical\n`send`/`retrySend`, ordinary save/delete, and default EmailSender handoff are\nconstrained by `protected-notification-handoff.ts` (package-private, never a root\nexport). Only the outbox enters its exact one-use scope after current trusted\npolicy/byte validation. Preserve old-row/constructor identity checks, current\npersisted lease checks at the actual provider boundary, copied byte buffers and\nunknown-outcome marker protection. See the outbox contract and shared protected\nhandoff suite (SQLite and migrated PostgreSQL).\n\n## Protected external contacts\n\nProfile email uses exclusive `recipientProfileId` plus `resolveProfileRecipient`, a reserved `profileNotificationPolicy` and exact current tenant-owned public Profile email. No User account is required. Before activating profiles, run normal framework schema migration and public `planNotificationProfileRecipients` / `migrateNotificationProfileRecipients`; runtime verifies physical constraints and never applies DDL. Legacy User notification and opt-out paths remain User-only. See [profile recipient contract and matrix](agents/profile-recipients.md).\n\n## Incremental mail sync (change feed)\n\n`EmailAccount.syncChanges({ limit?, maxBatches?, since? })` (`mail-sync.ts`) drives\n`EmailClient.getChanges()` (JMAP provider `jmap`; `@happyvertical/email` 0.114+).\n`syncFrom()` stays the polling path for IMAP/POP3.\n\n- `EmailAccount.syncCursor` is the opaque feed cursor (sensitive + readonly, never\n on generated surfaces). It is saved only after its batch is applied; a failure\n anywhere leaves it where it was, so the job just retries.\n- Rows are keyed on `Email.providerMessageId` (the server's own id, per account),\n so applying a batch twice changes nothing. Added/changed messages upsert,\n `removed` deletes, `folders` upserts `EmailFolder` by path and counts are\n recomputed for touched folders. Metadata-only changes keep stored bodies.\n- `resync-required` clears the cursor and runs a full pass in the same run; a\n full pass from no cursor deletes stored messages (with a `providerMessageId`)\n the server no longer has. A second resync request in one run throws.\n- One lane per account: runs queue behind each other in-process, work on the\n stored (revision-guarded) row, and the job is deduplicated per tenant+account.\n Inactive and `needs_reconnect` accounts, and clients without `getChanges`,\n return `{ status: 'skipped' }`. Auth failures call `markNeedsReconnect()` and\n throw with `retryable: false`. The sync runs under `runWithMailSystemAccess()`.\n- Job: `enqueueMailSync(account)` / `enqueueDueMailSyncs(accounts)`\n (`mail-sync-jobs.ts`, queue `mail-sync`, dedupe key `mail-sync:<accountId>`)\n target `EmailAccount.syncChanges` through `@happyvertical/smrt-jobs` (optional\n peer). The host runs the `TaskRunner` and schedules `enqueueDueMailSyncs`.\n- Backfill horizon (#5200): optional `EmailAccount.backfillSince` (null = whole\n mailbox, the default) or per-run `since` (`Date`/ISO string, `null` lifts the\n stored one; `enqueueMailSync({ since })` forwards it as an ISO string). A\n message dated before it is not stored unless it already is; undated mail is\n kept; `MailSyncResult.beforeHorizon` counts the skips. The SDK change feed\n cannot filter by date, so the server still sends the older mail and it is\n dropped here (saves rows, not transfer; a server-side horizon needs an SDK change).\n- Horizon vs cursor: `cursorHorizon` records the horizon the saved cursor was\n built under (null = unbounded, also legacy cursors). If a run's effective\n horizon is earlier than it, or cleared (`since: null`), the cursor is dropped\n and the run does a full pass with prune; narrowing or an unchanged horizon\n keeps the cursor.\n- Persisted health (#5200): `lastSyncError` is set on any failed run (also\n client-build failures and sign-in refusals, which additionally set\n `needs_reconnect`) and cleared by the next successful run; a transient failure\n never changes `connectionStatus`. `backlog` mirrors `MailSyncResult.hasMore`\n of the last successful run. Both are plain optional columns (additive).\n- Known gaps: attachment rows are not created (only `hasAttachments`/`size`);\n a renamed server folder creates a new folder row (stored messages keep the old\n path until they change); `jmap` has no connect-flow validator yet and is not an\n outbound transport.\n\n## Triage write-back\n\n`EmailAccount.triage(action, emailIds)` (and `Email.triage(action)`,\n`mail-triage.ts`) writes mark read/unread, star/unstar, archive, spam/not spam,\nlabel add/remove and move to the server, then updates the local row. Actions are\n`{ kind: 'markRead' | 'markUnread' | 'star' | 'unstar' | 'archive' | 'markSpam' |\n'unmarkSpam' }`, `{ kind: 'addLabels' | 'removeLabels', labels }` and\n`{ kind: 'move', folder }`; ids are local `Email` row ids.\n\n- Access: needs `read` **and** `triage` on the account (`assertMailAccess`, fail\n closed; `MailAccessError`) before any server call or local write.\n- Server first, per message: the result is `{ updated, failed, stale }`. Only ids\n the server accepted are written; refusals (and ids that are missing, on another\n account, or not yet synced) come back in `failed`. A thrown client error\n changes nothing. Auth failures mark the account `needs_reconnect`.\n- Convergence: an accepted message is read back (`getMessage`) and stored through\n `applyServerMessage`, exactly as sync stores it, so the next sync is a no-op.\n If the read-back fails the id is `stale` and sync fixes the row. Triage runs in\n the account's sync lane (`inLane`), so it never interleaves with a sync here.\n- Providers whose `getCapabilities().writeBack` lacks the needed key (`flags`,\n `labels`, `archive`, `spam`) throw `MailWriteBackUnsupportedError` first.\n- `move` removes a message from the mailboxes it is in now (from its stored\n labels) and adds `folder`; pass a path as stored on `EmailFolder`.\n- Every public method on an `@smrt()` class becomes a `<collection>.<method>`\n permission; `Email.triage` is why `messages.triage` in `permissions.ts` carries\n the generated name and description (the catalog rejects two for one slug).\n- Known gaps: drafts and send, the acting principal is not recorded (#5141), and\n a mailbox the server has not reported yet has no `EmailFolder` row until sync.\n",
|
|
14031
14234
|
"moduleDocs": [
|
|
14235
|
+
{
|
|
14236
|
+
"path": "agents/send-approval.md",
|
|
14237
|
+
"module": "send-approval",
|
|
14238
|
+
"content": "# Agent send policy, held sends, drafts and \"handled by\" (#5141)\n\nEpic I (happyvertical.com#585). Code: `src/send-approval.ts`,\n`src/mail-drafts.ts`, the send path in `src/models/Message.ts`.\n\n## Who is an agent\n\nThe host supplies the acting principal through `configureMailAccess`'s\n`resolvePrincipal`. Only `kind: 'person'` (or `'human'`) is a person;\nanything else, including no label, is an agent. A persona route\n(`message.personaId`, `PersonaMessagingService`) is an agent send whoever\ninvoked it (requester `persona:<id>`). Trusted system work\n(`runWithMailSystemAccess`: sync, the outbox) is never held. With no\nprincipal: when a gate is configured, a persona send is held and any other\nsend is refused; without a gate, behaviour is unchanged.\n\n## Policy\n\n`EmailAccount.agentSendPolicy`: null or `require_approval` (default) holds an\nagent's send; `auto_send` lets it leave. Only the account owner, as a person,\nwith tenant `messages.manage-access`, changes it\n(`MailAccessService.setAgentSendPolicy`); raising to `auto_send` needs\n`confirmAutoSend: true` (the smrt-social public-latch pattern), lowering is\ninstant, and a change of owner resets it to null. A host per-rule hook (`configureMailSendApprovals({\nresolveAgentSendPolicy })`) may answer either way for one send; null falls\nback to the account. Non-mail accounts have no policy and are not held.\n\n## Held send\n\n`Message.send()` checks `send` scope, then send-as (on an owned account a\nprincipal sends only from the account's own address), then\n`holdAgentSend()`. Send-as applies to every mail account (owned or not)\noutside system access. For an agent under `require_approval` it:\n\n1. refuses without a configured gate, without a tenant, for an unsaved draft\n or a caller copy that differs from the stored row, and for send-time\n attachment bytes;\n2. hashes the stored draft (`mailSendBindingHash`: account, from, to/cc/bcc,\n subject, bodies, threading headers, stored attachment rows and a SHA-256\n of each attachment file's bytes);\n3. calls the gate's `check`, which only reports: `pending` or `approved`\n both return `pendingApproval` and send nothing. The agent never sends a\n held draft itself; it goes out once, as the approving person.\n\nA held message is set to `draft` (a persona route creates it `pending`), so\nit leaves every pending/scheduled outbox and a person can decide it. A\npersona message is held even under system access, so a system drain never\nsends it around its approval. Send-time attachment bytes (for example\n`PersonaMessagingService` `attachments`) are refused on a held send: they are\nnot stored, so no person could review them and nothing could bind them;\nstore them as `Attachment` rows on the message instead. A refused send of a\n`pending`/`scheduled` message is marked `failed` (definite), never left\nqueued.\n\nAfter the row is claimed, a send an approval released re-hashes the draft\n(attachment rows included); a mismatch fails definitely and sends nothing.\nThe approval request carries a neutral summary, never mail content: request\nand event rows are readable tenant-wide.\n\nThe gate is structural; smrt-approvals' `createApprovalMailSendGate`\nimplements it (kind `messages.mail.send`). smrt-messages has a dev dependency\non smrt-approvals for tests only.\n\n## Deciding\n\n`MailSendApprovalService` acts as the resolved principal, which must be a\nperson holding `read` and `send` on the draft's account in the same tenant.\nDeciding also needs the tenant `messages.send` permission, checked through\nsmrt-users with no bypass (on an unowned account the per-account decision\nchecks none). `approve(id, { edits? })` refuses a draft that changed since\nthe request (`draft_changed`); with edits it approves the revised hash first\n(edit-then-approve), then saves the edits; once the approval is complete it\nconsumes it and sends as the person. `release(id)` sends a request already\napproved elsewhere (a generic inbox), only by one of its approvers. Before\nany consume every counted approver is re-verified (tenant `messages.send`\nand `send` on the account). `reject(id, reason)` keeps the draft.\nDouble release is prevented by the single-use consume and the send claim.\n\n## Audit and \"handled by\"\n\nTriage, draft saves and sends stamp `handledById` / `handledByKind` /\n`handledAt` on the message (`getHandledBy()`, `threadHandledBy()` for a\nthread). When the host runs the action inside smrt-core `withAuditContext()`,\n`auditMailAction` writes `messages.draft.save`, `messages.send.held`,\n`messages.send.approved[-with-edits]`, `messages.send.rejected`,\n`messages.send` (before the provider call; a writer failure stops the send)\nand `messages.triage.<action>`. Mail models are not `audit: true`: that makes\nevery sync and outbox write demand a writer.\n\nDeciding needs an unsent draft or a definitely failed send (`not_a_draft`\notherwise; an outcome-unknown send is never re-approved). On an unowned\n(tenant-wide) account the per-account checks pass for any tenant person, the\nsame authority as sending directly from it.\n\n## Known gaps\n\n- No approval-queue or handled-by Svelte component yet.\n- Attachment bytes are re-read by the sender after the post-claim check, a\n narrow window.\n- A crash between consume and send leaves a consumed approval and an unsent\n draft; the agent resubmits for a new approval.\n"
|
|
14239
|
+
},
|
|
14032
14240
|
{
|
|
14033
14241
|
"path": "agents/mail-search.md",
|
|
14034
14242
|
"module": "mail-search",
|
|
@@ -5,10 +5,10 @@ description: "Unified multi-channel messaging with STI-based hierarchies"
|
|
|
5
5
|
status: "stable"
|
|
6
6
|
generated:
|
|
7
7
|
by: "smrt/scripts/generate-knowledge-okf.ts"
|
|
8
|
-
at: "2026-11-
|
|
8
|
+
at: "2026-11-19T19:29:17Z"
|
|
9
9
|
audience: "internal"
|
|
10
10
|
evidence_level: "source-inspected"
|
|
11
|
-
source_revision: "sha256:
|
|
11
|
+
source_revision: "sha256:8f8b85d9d8a0a2d1d4caca84fe0e039d2f55d577865e4d6068d1314d28c8a835"
|
|
12
12
|
sources:
|
|
13
13
|
- id: "manifest"
|
|
14
14
|
resource: "https://github.com/happyvertical/smrt/blob/main/packages/messages/package.json"
|
|
@@ -25,6 +25,9 @@ sources:
|
|
|
25
25
|
- id: "agents-4"
|
|
26
26
|
resource: "https://github.com/happyvertical/smrt/blob/main/packages/messages/agents/profile-recipients.md"
|
|
27
27
|
title: "@happyvertical/smrt-messages packages/messages/agents/profile-recipients.md"
|
|
28
|
+
- id: "agents-5"
|
|
29
|
+
resource: "https://github.com/happyvertical/smrt/blob/main/packages/messages/agents/send-approval.md"
|
|
30
|
+
title: "@happyvertical/smrt-messages packages/messages/agents/send-approval.md"
|
|
28
31
|
---
|
|
29
32
|
|
|
30
33
|
# @happyvertical/smrt-messages
|
|
@@ -42,9 +45,11 @@ sources:
|
|
|
42
45
|
- `packages/messages/agents/mail-search.md`
|
|
43
46
|
- `packages/messages/agents/notification-outbox.md`
|
|
44
47
|
- `packages/messages/agents/profile-recipients.md`
|
|
48
|
+
- `packages/messages/agents/send-approval.md`
|
|
45
49
|
|
|
46
50
|
## Framework dependencies
|
|
47
51
|
|
|
52
|
+
- [smrt-approvals](/components/smrt-approvals.md)
|
|
48
53
|
- [smrt-core](/components/smrt-core.md)
|
|
49
54
|
- [smrt-jobs](/components/smrt-jobs.md)
|
|
50
55
|
- [smrt-ledgers](/components/smrt-ledgers.md)
|
package/dist/types.d.ts
CHANGED
|
@@ -80,6 +80,15 @@ export interface MessageSendResult {
|
|
|
80
80
|
* opposed to a definite rejection. Callers must not blindly resend it.
|
|
81
81
|
*/
|
|
82
82
|
outcomeUnknown?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Set when an agent's send was held for a person's approval instead of
|
|
85
|
+
* leaving (see `send-approval.ts`). Nothing was sent; the draft is
|
|
86
|
+
* unchanged and waits under `approvalId`.
|
|
87
|
+
*/
|
|
88
|
+
pendingApproval?: {
|
|
89
|
+
approvalId: string;
|
|
90
|
+
created: boolean;
|
|
91
|
+
};
|
|
83
92
|
sentAt: Date;
|
|
84
93
|
}
|
|
85
94
|
/** Result shape returned by SDK message-client `send()` implementations. */
|
|
@@ -142,6 +151,9 @@ export interface MessageOptions extends SmrtObjectOptions {
|
|
|
142
151
|
maxRetries?: number;
|
|
143
152
|
scheduledSendAt?: Date | null;
|
|
144
153
|
inReplyToMessageId?: string;
|
|
154
|
+
handledById?: string | null;
|
|
155
|
+
handledByKind?: string | null;
|
|
156
|
+
handledAt?: Date | null;
|
|
145
157
|
}
|
|
146
158
|
/**
|
|
147
159
|
* Options for creating Account (base)
|
|
@@ -256,7 +268,15 @@ export interface EmailAccountOptions extends AccountOptions {
|
|
|
256
268
|
lastSyncError?: string | null;
|
|
257
269
|
/** More changes were waiting when the last run stopped. */
|
|
258
270
|
backlog?: boolean;
|
|
271
|
+
/** Agent send policy; null means `require_approval`. */
|
|
272
|
+
agentSendPolicy?: AgentSendPolicy | null;
|
|
259
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* What happens when an agent sends from a mail account. `require_approval`
|
|
276
|
+
* (the default, also what null means) holds the draft until a person with
|
|
277
|
+
* `send` approves it; `auto_send` lets it leave. Person sends are unaffected.
|
|
278
|
+
*/
|
|
279
|
+
export type AgentSendPolicy = 'require_approval' | 'auto_send';
|
|
260
280
|
/**
|
|
261
281
|
* Options for creating EmailFolder
|
|
262
282
|
*/
|