botinabox 1.8.1 → 1.8.2
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/dist/index.d.ts +5 -0
- package/dist/index.js +27 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1090,6 +1090,10 @@ declare class MessageStore {
|
|
|
1090
1090
|
* Get recent outbound messages in a thread for redundancy checking.
|
|
1091
1091
|
*/
|
|
1092
1092
|
getRecentOutbound(threadId: string, limit?: number): Promise<Array<Record<string, unknown>>>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Get recent messages from a specific user across all threads.
|
|
1095
|
+
*/
|
|
1096
|
+
getUserHistory(userId: string, channel: string, limit?: number): Promise<Array<Record<string, unknown>>>;
|
|
1093
1097
|
/**
|
|
1094
1098
|
* Get attachments for a message.
|
|
1095
1099
|
*/
|
|
@@ -1147,6 +1151,7 @@ declare class ChatResponder {
|
|
|
1147
1151
|
channel: string;
|
|
1148
1152
|
userName?: string;
|
|
1149
1153
|
capabilities?: string;
|
|
1154
|
+
additionalContext?: string;
|
|
1150
1155
|
}): Promise<string>;
|
|
1151
1156
|
/**
|
|
1152
1157
|
* Filter any outbound message through the LLM for human readability.
|
package/dist/index.js
CHANGED
|
@@ -1263,6 +1263,16 @@ var MessageStore = class {
|
|
|
1263
1263
|
});
|
|
1264
1264
|
return messages;
|
|
1265
1265
|
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Get recent messages from a specific user across all threads.
|
|
1268
|
+
*/
|
|
1269
|
+
async getUserHistory(userId, channel, limit = 50) {
|
|
1270
|
+
return this.db.query("messages", {
|
|
1271
|
+
where: { from_user: userId, channel },
|
|
1272
|
+
orderBy: "created_at",
|
|
1273
|
+
limit
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1266
1276
|
/**
|
|
1267
1277
|
* Get attachments for a message.
|
|
1268
1278
|
*/
|
|
@@ -1329,6 +1339,9 @@ ${opts.capabilities}`;
|
|
|
1329
1339
|
|
|
1330
1340
|
You are talking to: ${opts.userName}`;
|
|
1331
1341
|
}
|
|
1342
|
+
if (opts.additionalContext) {
|
|
1343
|
+
system += opts.additionalContext;
|
|
1344
|
+
}
|
|
1332
1345
|
const result = await this.llmCall({
|
|
1333
1346
|
model: this.model,
|
|
1334
1347
|
messages,
|
|
@@ -1663,11 +1676,24 @@ var ChatPipeline = class {
|
|
|
1663
1676
|
this.threadChannelMap.set(threadTs, channelId);
|
|
1664
1677
|
}
|
|
1665
1678
|
const { messageId } = await this.messageStore.storeInbound(msg);
|
|
1679
|
+
const userHistory = await this.messageStore.getUserHistory(
|
|
1680
|
+
msg.from,
|
|
1681
|
+
this.channel,
|
|
1682
|
+
50
|
|
1683
|
+
);
|
|
1684
|
+
const historyContext = userHistory.map((m) => {
|
|
1685
|
+
const dir = m.direction === "inbound" ? "User" : "Bot";
|
|
1686
|
+
return `${dir}: ${m.body?.slice(0, 200) ?? ""}`;
|
|
1687
|
+
}).join("\n");
|
|
1666
1688
|
const ackResponse = await this.responder.respond({
|
|
1667
1689
|
messageBody: msg.body,
|
|
1668
1690
|
threadId: threadTs,
|
|
1669
1691
|
channel: this.channel,
|
|
1670
|
-
capabilities: this.capabilities
|
|
1692
|
+
capabilities: this.capabilities,
|
|
1693
|
+
additionalContext: historyContext ? `
|
|
1694
|
+
|
|
1695
|
+
Recent conversation history:
|
|
1696
|
+
${historyContext}` : void 0
|
|
1671
1697
|
});
|
|
1672
1698
|
await this.responder.sendResponse({
|
|
1673
1699
|
text: ackResponse,
|