@happyvertical/smrt-chat 0.38.24 → 0.38.26
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 +24 -2
- package/README.md +123 -3
- package/dist/chunks/{ChatService-BRsE5HmY.js → ChatService-B9rJuwtb.js} +269 -110
- package/dist/chunks/ChatService-B9rJuwtb.js.map +1 -0
- package/dist/collections/VoiceGatewayTurnCollection.d.ts +13 -0
- package/dist/collections/VoiceGatewayTurnCollection.d.ts.map +1 -0
- package/dist/collections/VoiceSessionCollection.d.ts +11 -0
- package/dist/collections/VoiceSessionCollection.d.ts.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +495 -13
- package/dist/index.js.map +1 -1
- package/dist/internal/agent-runtime.js +1 -1
- package/dist/manifest.json +2795 -1892
- package/dist/models/VoiceGatewayTurn.d.ts +20 -0
- package/dist/models/VoiceGatewayTurn.d.ts.map +1 -0
- package/dist/models/VoiceSession.d.ts +40 -0
- package/dist/models/VoiceSession.d.ts.map +1 -0
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/persona-conversation.d.ts +8 -0
- package/dist/persona-conversation.d.ts.map +1 -1
- package/dist/services/ChatService.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +597 -125
- package/dist/svelte/components/layout/ChatLayout.svelte +7 -3
- package/dist/svelte/components/messages/MessageInput.svelte +22 -15
- package/dist/svelte/components/messages/MessageInput.svelte.d.ts.map +1 -1
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +4 -2
- package/dist/ui.js.map +1 -1
- package/dist/voice.d.ts +127 -0
- package/dist/voice.d.ts.map +1 -0
- package/package.json +16 -14
- package/dist/chunks/ChatService-BRsE5HmY.js.map +0 -1
package/dist/smrt-knowledge.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"generatedAt": "2026-07-
|
|
3
|
+
"generatedAt": "2026-07-10T12:54:56.500Z",
|
|
4
4
|
"packageName": "@happyvertical/smrt-chat",
|
|
5
|
-
"packageVersion": "0.38.
|
|
5
|
+
"packageVersion": "0.38.26",
|
|
6
6
|
"sourceManifestPath": "dist/manifest.json",
|
|
7
7
|
"agentDocPath": "AGENTS.md",
|
|
8
8
|
"sourceHashes": {
|
|
9
|
-
"manifest": "
|
|
10
|
-
"packageJson": "
|
|
11
|
-
"agents": "
|
|
9
|
+
"manifest": "66abcc6e33b44cc9b2f94aa592c89a4d913fc79a599c853e492340fdfa9d0ad9",
|
|
10
|
+
"packageJson": "d3cbae82592618c9e03bb44885e6078fd61c04fc61270b851f3d9cbba2eee506",
|
|
11
|
+
"agents": "6cd3406a8954dd51b7c3354115a022333c96f125c9e2ac1ede272951da2a1f10"
|
|
12
12
|
},
|
|
13
13
|
"exports": [
|
|
14
14
|
".",
|
|
@@ -29,8 +29,10 @@
|
|
|
29
29
|
"@happyvertical/smrt-ui": "workspace:*",
|
|
30
30
|
"@happyvertical/smrt-users": "workspace:*",
|
|
31
31
|
"@happyvertical/sql": "catalog:",
|
|
32
|
+
"@happyvertical/smrt-playground": "workspace:*",
|
|
32
33
|
"@happyvertical/smrt-profiles": "workspace:*",
|
|
33
34
|
"@happyvertical/smrt-vitest": "workspace:*",
|
|
35
|
+
"@sveltejs/kit": "^2.69.1",
|
|
34
36
|
"@sveltejs/package": "^2.5.8",
|
|
35
37
|
"@sveltejs/vite-plugin-svelte": "^7.1.2",
|
|
36
38
|
"@types/node": "24.13.2",
|
|
@@ -45,6 +47,7 @@
|
|
|
45
47
|
"@happyvertical/smrt-agents",
|
|
46
48
|
"@happyvertical/smrt-core",
|
|
47
49
|
"@happyvertical/smrt-personas",
|
|
50
|
+
"@happyvertical/smrt-playground",
|
|
48
51
|
"@happyvertical/smrt-profiles",
|
|
49
52
|
"@happyvertical/smrt-tenancy",
|
|
50
53
|
"@happyvertical/smrt-types",
|
|
@@ -59,6 +62,184 @@
|
|
|
59
62
|
"tags": [],
|
|
60
63
|
"risks": [],
|
|
61
64
|
"objects": [
|
|
65
|
+
{
|
|
66
|
+
"name": "AgentSessionCollection",
|
|
67
|
+
"qualifiedName": "@happyvertical/smrt-chat:AgentSessionCollection",
|
|
68
|
+
"collection": "agentsessions",
|
|
69
|
+
"tableName": "agent_sessions",
|
|
70
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
71
|
+
"extends": "SmrtCollection",
|
|
72
|
+
"fields": [],
|
|
73
|
+
"relationships": [],
|
|
74
|
+
"methods": [
|
|
75
|
+
"expireStale",
|
|
76
|
+
"findActiveByParticipant",
|
|
77
|
+
"findActiveSession",
|
|
78
|
+
"findByAgent",
|
|
79
|
+
"findOrCreate"
|
|
80
|
+
],
|
|
81
|
+
"surfaces": [],
|
|
82
|
+
"relationshipFeatures": [
|
|
83
|
+
"uuidColumns"
|
|
84
|
+
],
|
|
85
|
+
"tags": [],
|
|
86
|
+
"risks": []
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"name": "ChatMessageCollection",
|
|
90
|
+
"qualifiedName": "@happyvertical/smrt-chat:ChatMessageCollection",
|
|
91
|
+
"collection": "chatmessages",
|
|
92
|
+
"tableName": "chat_messages",
|
|
93
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
94
|
+
"extends": "SmrtCollection",
|
|
95
|
+
"fields": [],
|
|
96
|
+
"relationships": [],
|
|
97
|
+
"methods": [
|
|
98
|
+
"getByAgentSession",
|
|
99
|
+
"getByRoom",
|
|
100
|
+
"getByThread",
|
|
101
|
+
"getLatestPerRoom",
|
|
102
|
+
"getUnreadCount",
|
|
103
|
+
"search"
|
|
104
|
+
],
|
|
105
|
+
"surfaces": [],
|
|
106
|
+
"relationshipFeatures": [
|
|
107
|
+
"uuidColumns"
|
|
108
|
+
],
|
|
109
|
+
"tags": [],
|
|
110
|
+
"risks": []
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "ChatParticipantCollection",
|
|
114
|
+
"qualifiedName": "@happyvertical/smrt-chat:ChatParticipantCollection",
|
|
115
|
+
"collection": "chatparticipants",
|
|
116
|
+
"tableName": "chat_participants",
|
|
117
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
118
|
+
"extends": "SmrtCollection",
|
|
119
|
+
"fields": [],
|
|
120
|
+
"relationships": [],
|
|
121
|
+
"methods": [
|
|
122
|
+
"countInRoom",
|
|
123
|
+
"findActiveMembership",
|
|
124
|
+
"findMembership",
|
|
125
|
+
"getAdminsInRoom",
|
|
126
|
+
"getByProfile",
|
|
127
|
+
"getByRoom",
|
|
128
|
+
"getOnlineInRoom",
|
|
129
|
+
"isActiveMember"
|
|
130
|
+
],
|
|
131
|
+
"surfaces": [],
|
|
132
|
+
"relationshipFeatures": [
|
|
133
|
+
"uuidColumns"
|
|
134
|
+
],
|
|
135
|
+
"tags": [],
|
|
136
|
+
"risks": []
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "ChatReactionCollection",
|
|
140
|
+
"qualifiedName": "@happyvertical/smrt-chat:ChatReactionCollection",
|
|
141
|
+
"collection": "chatreactions",
|
|
142
|
+
"tableName": "chat_reactions",
|
|
143
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
144
|
+
"extends": "SmrtCollection",
|
|
145
|
+
"fields": [],
|
|
146
|
+
"relationships": [],
|
|
147
|
+
"methods": [
|
|
148
|
+
"getByMessage",
|
|
149
|
+
"getReactionCounts",
|
|
150
|
+
"toggle"
|
|
151
|
+
],
|
|
152
|
+
"surfaces": [],
|
|
153
|
+
"relationshipFeatures": [
|
|
154
|
+
"uuidColumns"
|
|
155
|
+
],
|
|
156
|
+
"tags": [],
|
|
157
|
+
"risks": []
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"name": "ChatRoomCollection",
|
|
161
|
+
"qualifiedName": "@happyvertical/smrt-chat:ChatRoomCollection",
|
|
162
|
+
"collection": "chatrooms",
|
|
163
|
+
"tableName": "chat_rooms",
|
|
164
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
165
|
+
"extends": "SmrtCollection",
|
|
166
|
+
"fields": [],
|
|
167
|
+
"relationships": [],
|
|
168
|
+
"methods": [
|
|
169
|
+
"findAgentRooms",
|
|
170
|
+
"findByType",
|
|
171
|
+
"findDMs",
|
|
172
|
+
"findOrCreateDM",
|
|
173
|
+
"findPublic",
|
|
174
|
+
"search"
|
|
175
|
+
],
|
|
176
|
+
"surfaces": [],
|
|
177
|
+
"relationshipFeatures": [
|
|
178
|
+
"uuidColumns"
|
|
179
|
+
],
|
|
180
|
+
"tags": [],
|
|
181
|
+
"risks": []
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "ChatThreadCollection",
|
|
185
|
+
"qualifiedName": "@happyvertical/smrt-chat:ChatThreadCollection",
|
|
186
|
+
"collection": "chatthreads",
|
|
187
|
+
"tableName": "chat_threads",
|
|
188
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
189
|
+
"extends": "SmrtCollection",
|
|
190
|
+
"fields": [],
|
|
191
|
+
"relationships": [],
|
|
192
|
+
"methods": [
|
|
193
|
+
"getActive",
|
|
194
|
+
"getByRoom",
|
|
195
|
+
"getUnresolved"
|
|
196
|
+
],
|
|
197
|
+
"surfaces": [],
|
|
198
|
+
"relationshipFeatures": [
|
|
199
|
+
"uuidColumns"
|
|
200
|
+
],
|
|
201
|
+
"tags": [],
|
|
202
|
+
"risks": []
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "VoiceGatewayTurnCollection",
|
|
206
|
+
"qualifiedName": "@happyvertical/smrt-chat:VoiceGatewayTurnCollection",
|
|
207
|
+
"collection": "voicegatewayturns",
|
|
208
|
+
"tableName": "voice_gateway_turns",
|
|
209
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
210
|
+
"extends": "SmrtCollection",
|
|
211
|
+
"fields": [],
|
|
212
|
+
"relationships": [],
|
|
213
|
+
"methods": [
|
|
214
|
+
"reserveTurn"
|
|
215
|
+
],
|
|
216
|
+
"surfaces": [],
|
|
217
|
+
"relationshipFeatures": [
|
|
218
|
+
"uuidColumns"
|
|
219
|
+
],
|
|
220
|
+
"tags": [],
|
|
221
|
+
"risks": []
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"name": "VoiceSessionCollection",
|
|
225
|
+
"qualifiedName": "@happyvertical/smrt-chat:VoiceSessionCollection",
|
|
226
|
+
"collection": "voicesessions",
|
|
227
|
+
"tableName": "voice_sessions",
|
|
228
|
+
"packageName": "@happyvertical/smrt-chat",
|
|
229
|
+
"extends": "SmrtCollection",
|
|
230
|
+
"fields": [],
|
|
231
|
+
"relationships": [],
|
|
232
|
+
"methods": [
|
|
233
|
+
"expireStale",
|
|
234
|
+
"getActiveById"
|
|
235
|
+
],
|
|
236
|
+
"surfaces": [],
|
|
237
|
+
"relationshipFeatures": [
|
|
238
|
+
"uuidColumns"
|
|
239
|
+
],
|
|
240
|
+
"tags": [],
|
|
241
|
+
"risks": []
|
|
242
|
+
},
|
|
62
243
|
{
|
|
63
244
|
"name": "AgentSession",
|
|
64
245
|
"qualifiedName": "@happyvertical/smrt-chat:AgentSession",
|
|
@@ -1058,139 +1239,344 @@
|
|
|
1058
1239
|
"risks": []
|
|
1059
1240
|
},
|
|
1060
1241
|
{
|
|
1061
|
-
"name": "
|
|
1062
|
-
"qualifiedName": "@happyvertical/smrt-chat:
|
|
1063
|
-
"collection": "
|
|
1064
|
-
"tableName": "
|
|
1242
|
+
"name": "VoiceGatewayTurn",
|
|
1243
|
+
"qualifiedName": "@happyvertical/smrt-chat:VoiceGatewayTurn",
|
|
1244
|
+
"collection": "voicegatewayturns",
|
|
1245
|
+
"tableName": "voice_gateway_turns",
|
|
1065
1246
|
"packageName": "@happyvertical/smrt-chat",
|
|
1066
|
-
"extends": "
|
|
1067
|
-
"fields": [
|
|
1068
|
-
|
|
1247
|
+
"extends": "SmrtObject",
|
|
1248
|
+
"fields": [
|
|
1249
|
+
{
|
|
1250
|
+
"name": "tenantId",
|
|
1251
|
+
"type": "text",
|
|
1252
|
+
"required": true,
|
|
1253
|
+
"columnType": "UUID"
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
"name": "voiceSessionId",
|
|
1257
|
+
"type": "foreignKey",
|
|
1258
|
+
"required": true,
|
|
1259
|
+
"related": "VoiceSession",
|
|
1260
|
+
"columnType": "UUID"
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
"name": "gatewaySessionId",
|
|
1264
|
+
"type": "text",
|
|
1265
|
+
"required": true,
|
|
1266
|
+
"columnType": "TEXT"
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
"name": "gatewayTurnId",
|
|
1270
|
+
"type": "text",
|
|
1271
|
+
"required": true,
|
|
1272
|
+
"columnType": "TEXT"
|
|
1273
|
+
},
|
|
1274
|
+
{
|
|
1275
|
+
"name": "target",
|
|
1276
|
+
"type": "text",
|
|
1277
|
+
"required": true,
|
|
1278
|
+
"columnType": "TEXT"
|
|
1279
|
+
},
|
|
1280
|
+
{
|
|
1281
|
+
"name": "status",
|
|
1282
|
+
"type": "text",
|
|
1283
|
+
"required": true,
|
|
1284
|
+
"columnType": "TEXT"
|
|
1285
|
+
},
|
|
1286
|
+
{
|
|
1287
|
+
"name": "completedAt",
|
|
1288
|
+
"type": "datetime",
|
|
1289
|
+
"required": false,
|
|
1290
|
+
"columnType": "TIMESTAMP"
|
|
1291
|
+
},
|
|
1292
|
+
{
|
|
1293
|
+
"name": "failedAt",
|
|
1294
|
+
"type": "datetime",
|
|
1295
|
+
"required": false,
|
|
1296
|
+
"columnType": "TIMESTAMP"
|
|
1297
|
+
}
|
|
1298
|
+
],
|
|
1299
|
+
"relationships": [
|
|
1300
|
+
{
|
|
1301
|
+
"name": "voiceSessionId",
|
|
1302
|
+
"type": "foreignKey",
|
|
1303
|
+
"required": true,
|
|
1304
|
+
"related": "VoiceSession",
|
|
1305
|
+
"columnType": "UUID"
|
|
1306
|
+
}
|
|
1307
|
+
],
|
|
1069
1308
|
"methods": [
|
|
1070
|
-
"
|
|
1071
|
-
"
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1309
|
+
"complete",
|
|
1310
|
+
"fail"
|
|
1311
|
+
],
|
|
1312
|
+
"surfaces": [
|
|
1313
|
+
{
|
|
1314
|
+
"kind": "api",
|
|
1315
|
+
"name": "voicegatewayturns.list",
|
|
1316
|
+
"operation": "list",
|
|
1317
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn",
|
|
1318
|
+
"path": "/voicegatewayturns",
|
|
1319
|
+
"method": "GET"
|
|
1320
|
+
},
|
|
1321
|
+
{
|
|
1322
|
+
"kind": "api",
|
|
1323
|
+
"name": "voicegatewayturns.get",
|
|
1324
|
+
"operation": "get",
|
|
1325
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn",
|
|
1326
|
+
"path": "/voicegatewayturns/[id]",
|
|
1327
|
+
"method": "GET"
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
"kind": "mcp",
|
|
1331
|
+
"name": "voicegatewayturn_list",
|
|
1332
|
+
"operation": "list",
|
|
1333
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn"
|
|
1334
|
+
},
|
|
1335
|
+
{
|
|
1336
|
+
"kind": "mcp",
|
|
1337
|
+
"name": "voicegatewayturn_get",
|
|
1338
|
+
"operation": "get",
|
|
1339
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn"
|
|
1340
|
+
}
|
|
1075
1341
|
],
|
|
1076
|
-
"surfaces": [],
|
|
1077
1342
|
"relationshipFeatures": [
|
|
1343
|
+
"foreignKey",
|
|
1078
1344
|
"uuidColumns"
|
|
1079
1345
|
],
|
|
1080
1346
|
"tags": [],
|
|
1081
1347
|
"risks": []
|
|
1082
1348
|
},
|
|
1083
1349
|
{
|
|
1084
|
-
"name": "
|
|
1085
|
-
"qualifiedName": "@happyvertical/smrt-chat:
|
|
1086
|
-
"collection": "
|
|
1087
|
-
"tableName": "
|
|
1088
|
-
"packageName": "@happyvertical/smrt-chat",
|
|
1089
|
-
"extends": "SmrtCollection",
|
|
1090
|
-
"fields": [],
|
|
1091
|
-
"relationships": [],
|
|
1092
|
-
"methods": [
|
|
1093
|
-
"getByAgentSession",
|
|
1094
|
-
"getByRoom",
|
|
1095
|
-
"getByThread",
|
|
1096
|
-
"getLatestPerRoom",
|
|
1097
|
-
"getUnreadCount",
|
|
1098
|
-
"search"
|
|
1099
|
-
],
|
|
1100
|
-
"surfaces": [],
|
|
1101
|
-
"relationshipFeatures": [
|
|
1102
|
-
"uuidColumns"
|
|
1103
|
-
],
|
|
1104
|
-
"tags": [],
|
|
1105
|
-
"risks": []
|
|
1106
|
-
},
|
|
1107
|
-
{
|
|
1108
|
-
"name": "ChatParticipantCollection",
|
|
1109
|
-
"qualifiedName": "@happyvertical/smrt-chat:ChatParticipantCollection",
|
|
1110
|
-
"collection": "chatparticipants",
|
|
1111
|
-
"tableName": "chat_participants",
|
|
1112
|
-
"packageName": "@happyvertical/smrt-chat",
|
|
1113
|
-
"extends": "SmrtCollection",
|
|
1114
|
-
"fields": [],
|
|
1115
|
-
"relationships": [],
|
|
1116
|
-
"methods": [
|
|
1117
|
-
"countInRoom",
|
|
1118
|
-
"findActiveMembership",
|
|
1119
|
-
"findMembership",
|
|
1120
|
-
"getAdminsInRoom",
|
|
1121
|
-
"getByProfile",
|
|
1122
|
-
"getByRoom",
|
|
1123
|
-
"getOnlineInRoom",
|
|
1124
|
-
"isActiveMember"
|
|
1125
|
-
],
|
|
1126
|
-
"surfaces": [],
|
|
1127
|
-
"relationshipFeatures": [
|
|
1128
|
-
"uuidColumns"
|
|
1129
|
-
],
|
|
1130
|
-
"tags": [],
|
|
1131
|
-
"risks": []
|
|
1132
|
-
},
|
|
1133
|
-
{
|
|
1134
|
-
"name": "ChatReactionCollection",
|
|
1135
|
-
"qualifiedName": "@happyvertical/smrt-chat:ChatReactionCollection",
|
|
1136
|
-
"collection": "chatreactions",
|
|
1137
|
-
"tableName": "chat_reactions",
|
|
1350
|
+
"name": "VoiceSession",
|
|
1351
|
+
"qualifiedName": "@happyvertical/smrt-chat:VoiceSession",
|
|
1352
|
+
"collection": "voicesessions",
|
|
1353
|
+
"tableName": "voice_sessions",
|
|
1138
1354
|
"packageName": "@happyvertical/smrt-chat",
|
|
1139
|
-
"extends": "
|
|
1140
|
-
"fields": [
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1355
|
+
"extends": "SmrtObject",
|
|
1356
|
+
"fields": [
|
|
1357
|
+
{
|
|
1358
|
+
"name": "tenantId",
|
|
1359
|
+
"type": "text",
|
|
1360
|
+
"required": true,
|
|
1361
|
+
"columnType": "UUID"
|
|
1362
|
+
},
|
|
1363
|
+
{
|
|
1364
|
+
"name": "gatewaySessionId",
|
|
1365
|
+
"type": "text",
|
|
1366
|
+
"required": true,
|
|
1367
|
+
"columnType": "TEXT"
|
|
1368
|
+
},
|
|
1369
|
+
{
|
|
1370
|
+
"name": "actorProfileId",
|
|
1371
|
+
"type": "crossPackageRef",
|
|
1372
|
+
"required": true,
|
|
1373
|
+
"related": "@happyvertical/smrt-profiles:Profile",
|
|
1374
|
+
"columnType": "UUID"
|
|
1375
|
+
},
|
|
1376
|
+
{
|
|
1377
|
+
"name": "actorUserId",
|
|
1378
|
+
"type": "crossPackageRef",
|
|
1379
|
+
"required": false,
|
|
1380
|
+
"related": "@happyvertical/smrt-users:User",
|
|
1381
|
+
"columnType": "UUID"
|
|
1382
|
+
},
|
|
1383
|
+
{
|
|
1384
|
+
"name": "personaId",
|
|
1385
|
+
"type": "crossPackageRef",
|
|
1386
|
+
"required": true,
|
|
1387
|
+
"related": "@happyvertical/smrt-personas:AgentPersona",
|
|
1388
|
+
"columnType": "UUID"
|
|
1389
|
+
},
|
|
1390
|
+
{
|
|
1391
|
+
"name": "agentSessionId",
|
|
1392
|
+
"type": "foreignKey",
|
|
1393
|
+
"required": true,
|
|
1394
|
+
"related": "AgentSession",
|
|
1395
|
+
"columnType": "UUID"
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
"name": "chatRoomId",
|
|
1399
|
+
"type": "foreignKey",
|
|
1400
|
+
"required": true,
|
|
1401
|
+
"related": "ChatRoom",
|
|
1402
|
+
"columnType": "UUID"
|
|
1403
|
+
},
|
|
1404
|
+
{
|
|
1405
|
+
"name": "threadId",
|
|
1406
|
+
"type": "foreignKey",
|
|
1407
|
+
"required": false,
|
|
1408
|
+
"related": "ChatThread",
|
|
1409
|
+
"columnType": "UUID"
|
|
1410
|
+
},
|
|
1411
|
+
{
|
|
1412
|
+
"name": "target",
|
|
1413
|
+
"type": "text",
|
|
1414
|
+
"required": true,
|
|
1415
|
+
"columnType": "TEXT"
|
|
1416
|
+
},
|
|
1417
|
+
{
|
|
1418
|
+
"name": "status",
|
|
1419
|
+
"type": "text",
|
|
1420
|
+
"required": true,
|
|
1421
|
+
"columnType": "TEXT"
|
|
1422
|
+
},
|
|
1423
|
+
{
|
|
1424
|
+
"name": "expiresAt",
|
|
1425
|
+
"type": "datetime",
|
|
1426
|
+
"required": true,
|
|
1427
|
+
"columnType": "TIMESTAMP"
|
|
1428
|
+
},
|
|
1429
|
+
{
|
|
1430
|
+
"name": "lastTurnAt",
|
|
1431
|
+
"type": "datetime",
|
|
1432
|
+
"required": false,
|
|
1433
|
+
"columnType": "TIMESTAMP"
|
|
1434
|
+
},
|
|
1435
|
+
{
|
|
1436
|
+
"name": "lastGatewayTurnId",
|
|
1437
|
+
"type": "text",
|
|
1438
|
+
"required": false,
|
|
1439
|
+
"columnType": "TEXT"
|
|
1440
|
+
},
|
|
1441
|
+
{
|
|
1442
|
+
"name": "personaSnapshot",
|
|
1443
|
+
"type": "text",
|
|
1444
|
+
"required": false,
|
|
1445
|
+
"columnType": "TEXT"
|
|
1446
|
+
},
|
|
1447
|
+
{
|
|
1448
|
+
"name": "metadata",
|
|
1449
|
+
"type": "text",
|
|
1450
|
+
"required": false,
|
|
1451
|
+
"columnType": "TEXT"
|
|
1452
|
+
},
|
|
1453
|
+
{
|
|
1454
|
+
"name": "processedTurnIds",
|
|
1455
|
+
"type": "text",
|
|
1456
|
+
"required": false,
|
|
1457
|
+
"columnType": "TEXT"
|
|
1458
|
+
}
|
|
1146
1459
|
],
|
|
1147
|
-
"
|
|
1148
|
-
|
|
1149
|
-
|
|
1460
|
+
"relationships": [
|
|
1461
|
+
{
|
|
1462
|
+
"name": "actorProfileId",
|
|
1463
|
+
"type": "crossPackageRef",
|
|
1464
|
+
"required": true,
|
|
1465
|
+
"related": "@happyvertical/smrt-profiles:Profile",
|
|
1466
|
+
"columnType": "UUID"
|
|
1467
|
+
},
|
|
1468
|
+
{
|
|
1469
|
+
"name": "actorUserId",
|
|
1470
|
+
"type": "crossPackageRef",
|
|
1471
|
+
"required": false,
|
|
1472
|
+
"related": "@happyvertical/smrt-users:User",
|
|
1473
|
+
"columnType": "UUID"
|
|
1474
|
+
},
|
|
1475
|
+
{
|
|
1476
|
+
"name": "personaId",
|
|
1477
|
+
"type": "crossPackageRef",
|
|
1478
|
+
"required": true,
|
|
1479
|
+
"related": "@happyvertical/smrt-personas:AgentPersona",
|
|
1480
|
+
"columnType": "UUID"
|
|
1481
|
+
},
|
|
1482
|
+
{
|
|
1483
|
+
"name": "agentSessionId",
|
|
1484
|
+
"type": "foreignKey",
|
|
1485
|
+
"required": true,
|
|
1486
|
+
"related": "AgentSession",
|
|
1487
|
+
"columnType": "UUID"
|
|
1488
|
+
},
|
|
1489
|
+
{
|
|
1490
|
+
"name": "chatRoomId",
|
|
1491
|
+
"type": "foreignKey",
|
|
1492
|
+
"required": true,
|
|
1493
|
+
"related": "ChatRoom",
|
|
1494
|
+
"columnType": "UUID"
|
|
1495
|
+
},
|
|
1496
|
+
{
|
|
1497
|
+
"name": "threadId",
|
|
1498
|
+
"type": "foreignKey",
|
|
1499
|
+
"required": false,
|
|
1500
|
+
"related": "ChatThread",
|
|
1501
|
+
"columnType": "UUID"
|
|
1502
|
+
}
|
|
1150
1503
|
],
|
|
1151
|
-
"tags": [],
|
|
1152
|
-
"risks": []
|
|
1153
|
-
},
|
|
1154
|
-
{
|
|
1155
|
-
"name": "ChatRoomCollection",
|
|
1156
|
-
"qualifiedName": "@happyvertical/smrt-chat:ChatRoomCollection",
|
|
1157
|
-
"collection": "chatrooms",
|
|
1158
|
-
"tableName": "chat_rooms",
|
|
1159
|
-
"packageName": "@happyvertical/smrt-chat",
|
|
1160
|
-
"extends": "SmrtCollection",
|
|
1161
|
-
"fields": [],
|
|
1162
|
-
"relationships": [],
|
|
1163
1504
|
"methods": [
|
|
1164
|
-
"
|
|
1165
|
-
"
|
|
1166
|
-
"
|
|
1167
|
-
"
|
|
1168
|
-
"
|
|
1169
|
-
"
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
"
|
|
1505
|
+
"expire",
|
|
1506
|
+
"getMetadata",
|
|
1507
|
+
"getPersonaSnapshot",
|
|
1508
|
+
"getProcessedTurnIds",
|
|
1509
|
+
"hasProcessedTurn",
|
|
1510
|
+
"isActive",
|
|
1511
|
+
"isExpired",
|
|
1512
|
+
"recordGatewayTurn",
|
|
1513
|
+
"revoke",
|
|
1514
|
+
"setMetadata",
|
|
1515
|
+
"setPersonaSnapshot"
|
|
1174
1516
|
],
|
|
1175
|
-
"
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1517
|
+
"surfaces": [
|
|
1518
|
+
{
|
|
1519
|
+
"kind": "api",
|
|
1520
|
+
"name": "voicesessions.list",
|
|
1521
|
+
"operation": "list",
|
|
1522
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession",
|
|
1523
|
+
"path": "/voicesessions",
|
|
1524
|
+
"method": "GET"
|
|
1525
|
+
},
|
|
1526
|
+
{
|
|
1527
|
+
"kind": "api",
|
|
1528
|
+
"name": "voicesessions.get",
|
|
1529
|
+
"operation": "get",
|
|
1530
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession",
|
|
1531
|
+
"path": "/voicesessions/[id]",
|
|
1532
|
+
"method": "GET"
|
|
1533
|
+
},
|
|
1534
|
+
{
|
|
1535
|
+
"kind": "cli",
|
|
1536
|
+
"name": "voicesession_list",
|
|
1537
|
+
"operation": "list",
|
|
1538
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1539
|
+
},
|
|
1540
|
+
{
|
|
1541
|
+
"kind": "cli",
|
|
1542
|
+
"name": "voicesession_get",
|
|
1543
|
+
"operation": "get",
|
|
1544
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1545
|
+
},
|
|
1546
|
+
{
|
|
1547
|
+
"kind": "cli",
|
|
1548
|
+
"name": "voicesession_create",
|
|
1549
|
+
"operation": "create",
|
|
1550
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1551
|
+
},
|
|
1552
|
+
{
|
|
1553
|
+
"kind": "cli",
|
|
1554
|
+
"name": "voicesession_update",
|
|
1555
|
+
"operation": "update",
|
|
1556
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1557
|
+
},
|
|
1558
|
+
{
|
|
1559
|
+
"kind": "cli",
|
|
1560
|
+
"name": "voicesession_delete",
|
|
1561
|
+
"operation": "delete",
|
|
1562
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
"kind": "mcp",
|
|
1566
|
+
"name": "voicesession_list",
|
|
1567
|
+
"operation": "list",
|
|
1568
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
"kind": "mcp",
|
|
1572
|
+
"name": "voicesession_get",
|
|
1573
|
+
"operation": "get",
|
|
1574
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1575
|
+
}
|
|
1191
1576
|
],
|
|
1192
|
-
"surfaces": [],
|
|
1193
1577
|
"relationshipFeatures": [
|
|
1578
|
+
"crossPackageRef",
|
|
1579
|
+
"foreignKey",
|
|
1194
1580
|
"uuidColumns"
|
|
1195
1581
|
],
|
|
1196
1582
|
"tags": [],
|
|
@@ -1501,16 +1887,102 @@
|
|
|
1501
1887
|
"name": "chatthread_get",
|
|
1502
1888
|
"operation": "get",
|
|
1503
1889
|
"objectName": "@happyvertical/smrt-chat:ChatThread"
|
|
1890
|
+
},
|
|
1891
|
+
{
|
|
1892
|
+
"kind": "api",
|
|
1893
|
+
"name": "voicegatewayturns.list",
|
|
1894
|
+
"operation": "list",
|
|
1895
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn",
|
|
1896
|
+
"path": "/voicegatewayturns",
|
|
1897
|
+
"method": "GET"
|
|
1898
|
+
},
|
|
1899
|
+
{
|
|
1900
|
+
"kind": "api",
|
|
1901
|
+
"name": "voicegatewayturns.get",
|
|
1902
|
+
"operation": "get",
|
|
1903
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn",
|
|
1904
|
+
"path": "/voicegatewayturns/[id]",
|
|
1905
|
+
"method": "GET"
|
|
1906
|
+
},
|
|
1907
|
+
{
|
|
1908
|
+
"kind": "mcp",
|
|
1909
|
+
"name": "voicegatewayturn_list",
|
|
1910
|
+
"operation": "list",
|
|
1911
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn"
|
|
1912
|
+
},
|
|
1913
|
+
{
|
|
1914
|
+
"kind": "mcp",
|
|
1915
|
+
"name": "voicegatewayturn_get",
|
|
1916
|
+
"operation": "get",
|
|
1917
|
+
"objectName": "@happyvertical/smrt-chat:VoiceGatewayTurn"
|
|
1918
|
+
},
|
|
1919
|
+
{
|
|
1920
|
+
"kind": "api",
|
|
1921
|
+
"name": "voicesessions.list",
|
|
1922
|
+
"operation": "list",
|
|
1923
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession",
|
|
1924
|
+
"path": "/voicesessions",
|
|
1925
|
+
"method": "GET"
|
|
1926
|
+
},
|
|
1927
|
+
{
|
|
1928
|
+
"kind": "api",
|
|
1929
|
+
"name": "voicesessions.get",
|
|
1930
|
+
"operation": "get",
|
|
1931
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession",
|
|
1932
|
+
"path": "/voicesessions/[id]",
|
|
1933
|
+
"method": "GET"
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
"kind": "cli",
|
|
1937
|
+
"name": "voicesession_list",
|
|
1938
|
+
"operation": "list",
|
|
1939
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1940
|
+
},
|
|
1941
|
+
{
|
|
1942
|
+
"kind": "cli",
|
|
1943
|
+
"name": "voicesession_get",
|
|
1944
|
+
"operation": "get",
|
|
1945
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
"kind": "cli",
|
|
1949
|
+
"name": "voicesession_create",
|
|
1950
|
+
"operation": "create",
|
|
1951
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1952
|
+
},
|
|
1953
|
+
{
|
|
1954
|
+
"kind": "cli",
|
|
1955
|
+
"name": "voicesession_update",
|
|
1956
|
+
"operation": "update",
|
|
1957
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1958
|
+
},
|
|
1959
|
+
{
|
|
1960
|
+
"kind": "cli",
|
|
1961
|
+
"name": "voicesession_delete",
|
|
1962
|
+
"operation": "delete",
|
|
1963
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1964
|
+
},
|
|
1965
|
+
{
|
|
1966
|
+
"kind": "mcp",
|
|
1967
|
+
"name": "voicesession_list",
|
|
1968
|
+
"operation": "list",
|
|
1969
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1970
|
+
},
|
|
1971
|
+
{
|
|
1972
|
+
"kind": "mcp",
|
|
1973
|
+
"name": "voicesession_get",
|
|
1974
|
+
"operation": "get",
|
|
1975
|
+
"objectName": "@happyvertical/smrt-chat:VoiceSession"
|
|
1504
1976
|
}
|
|
1505
1977
|
],
|
|
1506
1978
|
"prompts": [],
|
|
1507
1979
|
"relationshipsV2": {
|
|
1508
|
-
"foreignKeyFields":
|
|
1509
|
-
"crossPackageRefFields":
|
|
1980
|
+
"foreignKeyFields": 14,
|
|
1981
|
+
"crossPackageRefFields": 8,
|
|
1510
1982
|
"junctionCollections": 0,
|
|
1511
1983
|
"hierarchicalObjects": 0,
|
|
1512
1984
|
"polymorphicAssociations": 0,
|
|
1513
|
-
"uuidColumns":
|
|
1985
|
+
"uuidColumns": 46
|
|
1514
1986
|
},
|
|
1515
|
-
"agentDoc": "# @happyvertical/smrt-chat\n\nChat rooms, threads, and agent sessions with app-controlled tool whitelisting.\n\n## Models\n\nInternal models — all mutations go through the membership/owner-checked `ChatService` (S5 #1392). EVERY `@smrt()` model in this package (ChatRoom, ChatMessage, ChatParticipant, ChatThread, ChatReaction, AgentSession) has a READ-ONLY generated REST/MCP surface (`list`/`get` only); `create`/`update`/`delete` are intentionally NOT generated so the raw collection routes cannot skip the service-layer authorization. A structural regression test enumerates the registry to assert no chat model exposes a mutating op.\n\n`ChatService` is a CLOSED FACADE (S5 #1392). The raw collections (`rooms`, `messages`, `participants`, `threads`, `agentSessions`, `reactions`) are ES `#private` fields — they are NOT on the public `ChatService` type and the package index does NOT export the collection classes, so a consumer cannot do `chat.messages.create({senderProfileId, role})` / `new ChatParticipantCollection(...)` to mutate around the authorization. The security-sensitive internals (`#writeMessage`, `#emitAgentReply`, `#enrollParticipant`, `#loadActiveSession`, `#requireActiveMembership`, `#requireRoomAdmin`, `#extractToolName`) are ES `#private` too, so they are unreachable at runtime — TypeScript `private` alone is erased and would leave them callable on the prototype. The agent-reply bridge is a `Symbol`-keyed static (not the old enumerable `_runAgentReply`), reachable only by the module-local `sendAgentReply` that holds the non-exported symbol.\n\n- **ChatRoom**: `roomType` (public/private/dm/agent), `status`, `topic`, `maxParticipants`, `lastMessageAt`. Tenant-scoped (required).\n- **ChatMessage**: shared by users + agents. `role` (user/assistant/system/tool), `messageType` (text/system/action/file/tool_call/tool_result), `toolCallData` JSON. Unified model — no separate agent message type. Tenant-scoped (required).\n- **ChatParticipant**: `role` (owner/admin/member/viewer), `onlineStatus`, `lastReadMessageId`, `isMuted`. Tenant-scoped (required).\n- **ChatThread**: `rootMessageId`, `isResolved`, `messageCount`. Created via `ChatService.startThread()` (member-checked). Tenant-scoped (required).\n- **ChatReaction**: `messageId`, `profileId`, `emoji`. Added/removed via `ChatService.addReaction()`/`removeReaction()` (member-checked, self-keyed). Tenant-scoped (required).\n- **AgentSession**: `agentId` (string ref, not FK), `allowedTools` (JSON string array), `sessionContext` (JSON), `systemPrompt`, limits (`maxTokens`/`maxMessages`/`expiresAt`). Optional tenancy.\n\n## ChatService\n\nEvery public write takes an explicit server-supplied `actorProfileId` (the authenticated principal the route injects) — never a caller-controlled `senderProfileId`/`role` (S5 #1392).\n\nFacade: `sendMessage()` (authors as the actor with `role: 'user'`; room-membership-checked; no caller-supplied sender/role and no public membership-skip), `createRoom()` (acting actor becomes owner — no caller-supplied `createdByProfileId`), `startThread()` (member-checked; optional `rootMessageId` bound to the same room+tenant), `addParticipant()`/`removeParticipant()` (owner/admin-checked; self-leave allowed), `updateRoom()` (owner/admin-checked), `addReaction()`/`removeReaction()` (member-checked, self-keyed), `getOrCreateDM()` (actor must be a DM participant), `createAgentSession()` (acting actor becomes the session participant — no caller-supplied `participantProfileId`; the existing-session room lookup is tenant-bound; optional `sessionKey` scopes session identity to a conversation subject so distinct keys get distinct sessions/rooms and a session opened for one subject is never reused/rewritten for another). Tenant-bound read facade (replaces raw-collection reach-ins; consumers apply their own ownership/context checks on the returned rows): `getAgentSession({agentSessionId, tenantId})`, `findActiveAgentSessions({tenantId, agentId, participantProfileId})`, `getThread({threadId, tenantId})`, `listRoomThreads({roomId, actorProfileId, tenantId})` (membership-gated), `getThreadMessages({threadId, actorProfileId, tenantId, limit?})` (membership-gated, chronological), `getRoomMessages({roomId, actorProfileId, tenantId})`/`getRoomForMember(roomId, actorProfileId, tenantId)` (membership-checked reads gated on the server-supplied `actorProfileId`, never a caller-controlled subject id — confused-deputy avoidance; `tenantId` required), `updateAgentSessionConfig()` (owner-checked; `tenantId` mandatory and bound into the lookup). Agent session messaging is split by authority: `sendAgentUserMessage()` (caller `actorProfileId` must be the session participant; always authored as the participant). The agent-authored reply path `sendAgentReply(service, params)` is an exported **function — NOT a `ChatService` method and NOT on the package index**; it is reachable only via the dedicated `@happyvertical/smrt-chat/internal/agent-runtime` subpath (S5 #1392), so only trusted in-process agent-runtime code that explicitly opts into that subpath can author as the agent. It authors as `session.agentId`, accepts an optional same-room/tenant `threadId`, and gates tool calls fail-closed against `allowedTools`. The shared internal persistence path (`writeMessage`) is private — it alone may author an arbitrary profile/role or skip the membership check, and is unreachable from any route; it also validates every supplied `threadId`/`agentSessionId`/`replyToMessageId` belongs to the SAME room AND tenant (tenant/room-bound lookups) before use, rejecting cross-room/cross-tenant references. Auto-creates rooms/sessions/participants via an internal `enrollParticipant`.\n\n## Agent Tool Whitelisting\n\n`allowedTools` is a JSON array controlled by the consuming app. Fail-closed: an empty/unparseable whitelist permits NO tools. The internal `sendAgentReply(service, params)` function enforces the whitelist before emitting any `tool`/`tool_call` message; a caller cannot supply a `senderProfileId`/`role` to post as the agent, and the function is not reachable from the package index.\n\n## Conversational Harness (L3, #1891)\n\nThe \"chat with your learning agent\" surface — the real agentic runtime for `AgentSession` (the only shipping chat runtime before this was a single-shot completion). This is the new **acyclic `chat → personas` / `chat → agents` / `chat → users` edge**; keep it that way (personas/agents/users never depend back on chat).\n\n- **`runToolLoop(options)`** (`tool-loop.ts`) — a bounded `tool_call → observe → respond` loop. Tools are **manifest operations** of installed packages: `buildManifestToolCatalog({ allowedTools })` reads the `PermissionCatalogService` catalog and keeps only the `(collection, action)` entries named in the persona's allow-list (the **offer gate**; absent/empty ⇒ NO tools). The loop runs inside one `executeAsPrincipal` context, and `invokeManifestTool` executes each op **in-process (\"side door\")** against `run.context.database` (the RLS tx when Postgres RLS is on), after re-asserting the fail-closed allow-list (`run.assertToolAllowed`) AND the catalog permission (`run.assertOperation`) — the **execution gate**. Bounded by a max-steps ceiling (`DEFAULT_MAX_STEPS = 8`): on the ceiling it disables tools for one final completion so the turn always terminates with text.\n- **`runPersonaConversationTurn(options)`** (`persona-conversation.ts`) — binds a conversation to an `AgentPersona`/`ResolvedPersona`: runs as its principal (`runAsUserId`), offers only its `allowedTools`, speaks its instructions (`resolvePersonaInstructions`, layering approved learned directives), and injects its **recalled learning memory** (`personaLearningMemory`, isolated per `memoryScope`) into the system prompt. `bindPersonaToSession()` mirrors the persona's `allowedTools`/instructions onto the `AgentSession` so the chat authoring gate agrees with the loop's offer gate. Authors the reply (and each executed tool) via the internal `sendAgentReply` bridge.\n- **Agent orchestration** (L3, #1892) — the loop accepts non-manifest **`extraTools`** (`PrincipalTool[]`, from `@happyvertical/smrt-agents`), gated by the *same* fail-closed allow-list. The standard **`invoke-agent`** tool (`createInvokeAgentTool`, slug `agents.invoke`) lets a conversational agent delegate to a **worker agent under its own principal** — the worker runs via `executeAsPrincipal` as the originating user (never its own authority), the principal is immutable along the chain, and its completion is surfaced back into the conversation. `runPersonaConversationTurn` filters `extraTools` by the persona's `allowedTools` (offer gate); the tool's `execute` re-asserts `assertToolAllowed` (execution gate). See `@happyvertical/smrt-agents` for the delegation envelope + transports.\n- **Chat feedback capture** (`chat-feedback.ts`) — `captureChatFeedback()` + `acceptAppliedChange`/`rejectAppliedChange`/`correctResponse`/`rateResponse`/`thumbsUp`/`thumbsDown` write a `Feedback` row (personas) carrying the conversation's **correlation-id**, and (by default) reinforce the persona's learning memory (`reinforceFromFeedback`). So an in-chat reject decays a strategy below the reuse floor and it stops being recalled; a correction supersedes its stored value.\n\n## Gotchas\n\n- **sessionContext, not context**: `context` is reserved for slug scoping. Use `getSessionContext()`/`updateSessionContext()` for agent memory.\n- **Agent rooms auto-created**: `roomType: 'agent'`, `maxParticipants` defaults to 2; the agent is enrolled as a member so its replies pass the membership check. `createAgentSession()` re-enrolls the participant AND the agent on the existing-session path, so legacy sessions created before the agent was enrolled self-heal.\n- **Per-subject sessions need `sessionKey`**: `createAgentSession()` reuses ANY active session for the same `(agentId, participantProfileId, tenantId)`. Callers that open separate conversations per subject (e.g. one content-editor session per content id) MUST pass a stable `sessionKey` (stored in `sessionContext.__sessionKey`, read via `AgentSession.getSessionKey()`); otherwise a session opened for one subject is reused and its context overwritten for another, surfacing the wrong room/threads (S5 #1392). A keyed create never reuses a keyless/legacy session.\n- **Session expiry**: check `isActive()` before allowing messages (expiresAt or limit-based)\n- **DM identity**: derived from the deterministic per-tenant `canonicalDmRoomId()` and the authoritative `chat_participants` join, not client metadata; concurrent creates upsert onto one row.\n- **Tenant-bound lookups**: membership/session/DM lookups REQUIRE `tenantId` and always bind it into the WHERE clause (`findActiveMembership`/`isActiveMember`/`findActiveSession` take a required `tenantId`; AgentSession's `null` tenant is an explicit bound scope, not \"any tenant\") so they can never resolve a row from another tenant.\n"
|
|
1987
|
+
"agentDoc": "# @happyvertical/smrt-chat\n\nChat rooms, threads, and agent sessions with app-controlled tool whitelisting.\n\n## Dev Server\n\n`pnpm --dir packages/chat dev` runs a package-local SvelteKit workbench. The root\nroute is an interactive chat surface with a dev-only `/api/dev-chat` endpoint:\nit uses `@happyvertical/ai` when local provider credentials are present and\nfalls back to a deterministic local assistant otherwise. `/previews` hosts the\nshared component playground entries from `src/svelte/playground.ts`.\n\nThe root workbench also has a dev-only voice conversation mode. It reads voice\ngateway connection details through `/api/dev-voice/config`, streams browser mic\naudio to `WS /ws/voice` as PCM16 mono, appends gateway transcripts/responses to\nthe chat, and plays returned TTS audio. Exposing\n`SMRT_CHAT_DEV_VOICE_GATEWAY_TOKEN` to the browser requires\n`SMRT_CHAT_DEV_VOICE_GATEWAY_EXPOSE_TOKEN=true`; keep that local-only.\n\n## Models\n\nInternal models — all mutations go through the membership/owner-checked `ChatService` (S5 #1392) or the voice adapter's binding-checked flow. EVERY `@smrt()` model in this package (ChatRoom, ChatMessage, ChatParticipant, ChatThread, ChatReaction, AgentSession, VoiceSession) has a READ-ONLY generated REST/MCP surface (`list`/`get` only); `create`/`update`/`delete` are intentionally NOT generated so the raw collection routes cannot skip the service-layer authorization. A structural regression test enumerates the registry to assert no chat model exposes a mutating op.\n\n`ChatService` is a CLOSED FACADE (S5 #1392). The raw collections (`rooms`, `messages`, `participants`, `threads`, `agentSessions`, `reactions`, `voiceSessions`) are ES `#private` fields — they are NOT on the public `ChatService` type and the package index does NOT export the collection classes, so a consumer cannot do `chat.messages.create({senderProfileId, role})` / `new ChatParticipantCollection(...)` to mutate around the authorization. The security-sensitive internals (`#writeMessage`, `#emitAgentReply`, `#enrollParticipant`, `#loadActiveSession`, `#requireActiveMembership`, `#requireRoomAdmin`, `#extractToolName`) are ES `#private` too, so they are unreachable at runtime — TypeScript `private` alone is erased and would leave them callable on the prototype. The agent-reply bridge is a `Symbol`-keyed static (not the old enumerable `_runAgentReply`), reachable only by the module-local `sendAgentReply` that holds the non-exported symbol.\n\n- **ChatRoom**: `roomType` (public/private/dm/agent), `status`, `topic`, `maxParticipants`, `lastMessageAt`. Tenant-scoped (required).\n- **ChatMessage**: shared by users + agents. `role` (user/assistant/system/tool), `messageType` (text/system/action/file/tool_call/tool_result), `toolCallData` JSON. Unified model — no separate agent message type. Tenant-scoped (required).\n- **ChatParticipant**: `role` (owner/admin/member/viewer), `onlineStatus`, `lastReadMessageId`, `isMuted`. Tenant-scoped (required).\n- **ChatThread**: `rootMessageId`, `isResolved`, `messageCount`. Created via `ChatService.startThread()` (member-checked). Tenant-scoped (required).\n- **ChatReaction**: `messageId`, `profileId`, `emoji`. Added/removed via `ChatService.addReaction()`/`removeReaction()` (member-checked, self-keyed). Tenant-scoped (required).\n- **AgentSession**: `agentId` (string ref, not FK), `allowedTools` (JSON string array), `sessionContext` (JSON), `systemPrompt`, limits (`maxTokens`/`maxMessages`/`expiresAt`). Optional tenancy.\n- **VoiceSession**: short-lived voice-gateway binding over `(tenant, actorProfileId, personaId, room/thread/agentSession)` plus a persona snapshot, gateway `session_id`, expiry, replay tracking, and metadata. Tenant-scoped (required). Generated surface is read-only; creation and turns go through `createVoiceChatSession()` / `handleVoiceGatewayTurn()`.\n\n## ChatService\n\nEvery public write takes an explicit server-supplied `actorProfileId` (the authenticated principal the route injects) — never a caller-controlled `senderProfileId`/`role` (S5 #1392).\n\nFacade: `sendMessage()` (authors as the actor with `role: 'user'`; room-membership-checked; no caller-supplied sender/role and no public membership-skip), `createRoom()` (acting actor becomes owner — no caller-supplied `createdByProfileId`), `startThread()` (member-checked; optional `rootMessageId` bound to the same room+tenant), `addParticipant()`/`removeParticipant()` (owner/admin-checked; self-leave allowed), `updateRoom()` (owner/admin-checked), `addReaction()`/`removeReaction()` (member-checked, self-keyed), `getOrCreateDM()` (actor must be a DM participant), `createAgentSession()` (acting actor becomes the session participant — no caller-supplied `participantProfileId`; the existing-session room lookup is tenant-bound; optional `sessionKey` scopes session identity to a conversation subject so distinct keys get distinct sessions/rooms and a session opened for one subject is never reused/rewritten for another). Tenant-bound read facade (replaces raw-collection reach-ins; consumers apply their own ownership/context checks on the returned rows): `getAgentSession({agentSessionId, tenantId})`, `findActiveAgentSessions({tenantId, agentId, participantProfileId})`, `getThread({threadId, tenantId})`, `listRoomThreads({roomId, actorProfileId, tenantId})` (membership-gated), `getThreadMessages({threadId, actorProfileId, tenantId, limit?})` (membership-gated, chronological), `getRoomMessages({roomId, actorProfileId, tenantId})`/`getRoomForMember(roomId, actorProfileId, tenantId)` (membership-checked reads gated on the server-supplied `actorProfileId`, never a caller-controlled subject id — confused-deputy avoidance; `tenantId` required), `updateAgentSessionConfig()` (owner-checked; `tenantId` mandatory and bound into the lookup). Agent session messaging is split by authority: `sendAgentUserMessage()` (caller `actorProfileId` must be the session participant; always authored as the participant). The agent-authored reply path `sendAgentReply(service, params)` is an exported **function — NOT a `ChatService` method and NOT on the package index**; it is reachable only via the dedicated `@happyvertical/smrt-chat/internal/agent-runtime` subpath (S5 #1392), so only trusted in-process agent-runtime code that explicitly opts into that subpath can author as the agent. It authors as `session.agentId`, accepts an optional same-room/tenant `threadId`, and gates tool calls fail-closed against `allowedTools`. The shared internal persistence path (`writeMessage`) is private — it alone may author an arbitrary profile/role or skip the membership check, and is unreachable from any route; it also validates every supplied `threadId`/`agentSessionId`/`replyToMessageId` belongs to the SAME room AND tenant (tenant/room-bound lookups) before use, rejecting cross-room/cross-tenant references. Auto-creates rooms/sessions/participants via an internal `enrollParticipant`.\n\n## Agent Tool Whitelisting\n\n`allowedTools` is a JSON array controlled by the consuming app. Fail-closed: an empty/unparseable whitelist permits NO tools. The internal `sendAgentReply(service, params)` function enforces the whitelist before emitting any `tool`/`tool_call` message; a caller cannot supply a `senderProfileId`/`role` to post as the agent, and the function is not reachable from the package index.\n\n## Conversational Harness (L3, #1891)\n\nThe \"chat with your learning agent\" surface — the real agentic runtime for `AgentSession` (the only shipping chat runtime before this was a single-shot completion). This is the new **acyclic `chat → personas` / `chat → agents` / `chat → users` edge**; keep it that way (personas/agents/users never depend back on chat).\n\n- **`runToolLoop(options)`** (`tool-loop.ts`) — a bounded `tool_call → observe → respond` loop. Tools are **manifest operations** of installed packages: `buildManifestToolCatalog({ allowedTools })` reads the `PermissionCatalogService` catalog and keeps only the `(collection, action)` entries named in the persona's allow-list (the **offer gate**; absent/empty ⇒ NO tools). The loop runs inside one `executeAsPrincipal` context, and `invokeManifestTool` executes each op **in-process (\"side door\")** against `run.context.database` (the RLS tx when Postgres RLS is on), after re-asserting the fail-closed allow-list (`run.assertToolAllowed`) AND the catalog permission (`run.assertOperation`) — the **execution gate**. Bounded by a max-steps ceiling (`DEFAULT_MAX_STEPS = 8`): on the ceiling it disables tools for one final completion so the turn always terminates with text.\n- **`runPersonaConversationTurn(options)`** (`persona-conversation.ts`) — binds a conversation to an `AgentPersona`/`ResolvedPersona`: runs as its principal (`runAsUserId`), offers only its `allowedTools`, speaks its instructions (`resolvePersonaInstructions`, layering approved learned directives), and injects its **recalled learning memory** (`personaLearningMemory`, isolated per `memoryScope`) into the system prompt. `bindPersonaToSession()` mirrors the persona's `allowedTools`/instructions onto the `AgentSession` so the chat authoring gate agrees with the loop's offer gate. Authors the reply (and each executed tool) via the internal `sendAgentReply` bridge.\n- **Agent orchestration** (L3, #1892) — the loop accepts non-manifest **`extraTools`** (`PrincipalTool[]`, from `@happyvertical/smrt-agents`), gated by the *same* fail-closed allow-list. The standard **`invoke-agent`** tool (`createInvokeAgentTool`, slug `agents.invoke`) lets a conversational agent delegate to a **worker agent under its own principal** — the worker runs via `executeAsPrincipal` as the originating user (never its own authority), the principal is immutable along the chain, and its completion is surfaced back into the conversation. `runPersonaConversationTurn` filters `extraTools` by the persona's `allowedTools` (offer gate); the tool's `execute` re-asserts `assertToolAllowed` (execution gate). See `@happyvertical/smrt-agents` for the delegation envelope + transports.\n- **Chat feedback capture** (`chat-feedback.ts`) — `captureChatFeedback()` + `acceptAppliedChange`/`rejectAppliedChange`/`correctResponse`/`rateResponse`/`thumbsUp`/`thumbsDown` write a `Feedback` row (personas) carrying the conversation's **correlation-id**, and (by default) reinforce the persona's learning memory (`reinforceFromFeedback`). So an in-chat reject decays a strategy below the reuse floor and it stops being recalled; a correction supersedes its stored value.\n\n## Voice Gateway Turns (#1910)\n\nVoice is an input mode for the existing persona chat harness, not a separate chat runtime. `createVoiceChatSession()` creates a short-lived `VoiceSession` for an authenticated actor/profile, binding tenant, persona, agent session, room, and optional thread. `handleVoiceGatewayTurn()` resolves that binding from `metadata.voiceSessionId`, checks the gateway's `session_id` and any supplied tenant/profile/persona/session/thread metadata against the server-side binding, persists the transcript through `ChatService.sendAgentUserMessage()`, runs `runPersonaConversationTurn()`, stamps voice/correlation metadata onto the persisted user/assistant/tool messages, records the gateway `turn_id`, and returns the gateway response contract. The Fetch-compatible `createVoiceGatewayTurnHandler()` adds the coarse gateway bearer-token check.\n\nThe gateway bearer token proves only \"this request came from the gateway\"; it never authorizes the end user. The short-lived `VoiceSession` binding is the user/session proof, and untrusted gateway metadata must be validated against that binding before any chat write or tool loop. Tool execution remains fail-closed through the persona allow-list mirrored onto `AgentSession` by `bindPersonaToSession()`.\n\n## Gotchas\n\n- **sessionContext, not context**: `context` is reserved for slug scoping. Use `getSessionContext()`/`updateSessionContext()` for agent memory.\n- **Agent rooms auto-created**: `roomType: 'agent'`, `maxParticipants` defaults to 2; the agent is enrolled as a member so its replies pass the membership check. `createAgentSession()` re-enrolls the participant AND the agent on the existing-session path, so legacy sessions created before the agent was enrolled self-heal.\n- **Per-subject sessions need `sessionKey`**: `createAgentSession()` reuses ANY active session for the same `(agentId, participantProfileId, tenantId)`. Callers that open separate conversations per subject (e.g. one content-editor session per content id) MUST pass a stable `sessionKey` (stored in `sessionContext.__sessionKey`, read via `AgentSession.getSessionKey()`); otherwise a session opened for one subject is reused and its context overwritten for another, surfacing the wrong room/threads (S5 #1392). A keyed create never reuses a keyless/legacy session.\n- **Session expiry**: check `isActive()` before allowing messages (expiresAt or limit-based)\n- **DM identity**: derived from the deterministic per-tenant `canonicalDmRoomId()` and the authoritative `chat_participants` join, not client metadata; concurrent creates upsert onto one row.\n- **Tenant-bound lookups**: membership/session/DM lookups REQUIRE `tenantId` and always bind it into the WHERE clause (`findActiveMembership`/`isActiveMember`/`findActiveSession` take a required `tenantId`; AgentSession's `null` tenant is an explicit bound scope, not \"any tenant\") so they can never resolve a row from another tenant.\n"
|
|
1516
1988
|
}
|