@economic/agents 2.10.0 → 2.10.1
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.mjs +14 -5
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1487,11 +1487,12 @@ function registerChat(sql, durableObjectName, dateTime) {
|
|
|
1487
1487
|
function renameChat(sql, durableObjectName, title, dateTime = Date.now()) {
|
|
1488
1488
|
const trimmed = title.trim();
|
|
1489
1489
|
if (!trimmed) throw new Error("Chat title cannot be empty");
|
|
1490
|
-
sql`UPDATE chats
|
|
1490
|
+
if (!sql`UPDATE chats
|
|
1491
1491
|
SET title = ${trimmed},
|
|
1492
1492
|
title_set_by_user = 1,
|
|
1493
1493
|
updated_at = ${dateTime}
|
|
1494
|
-
WHERE durable_object_name = ${durableObjectName}
|
|
1494
|
+
WHERE durable_object_name = ${durableObjectName}
|
|
1495
|
+
RETURNING durable_object_name`.length) throw new Error(`Chat not found: ${durableObjectName}`);
|
|
1495
1496
|
}
|
|
1496
1497
|
function deleteChat(sql, durableObjectName) {
|
|
1497
1498
|
sql`DELETE FROM chats WHERE durable_object_name = ${durableObjectName}`;
|
|
@@ -1504,6 +1505,7 @@ async function getChats(sql) {
|
|
|
1504
1505
|
return sql`SELECT * FROM chats ORDER BY updated_at DESC`;
|
|
1505
1506
|
}
|
|
1506
1507
|
function recordChatFeedback(sql, durableObjectName, messageId, rating, dateTime = Date.now()) {
|
|
1508
|
+
if (rating !== 1 && rating !== -1 && rating !== 0) throw new RangeError("Message feedback rating must be 1, -1, or 0");
|
|
1507
1509
|
if (!getChat(sql, durableObjectName)) throw new Error(`Chat not found: ${durableObjectName}`);
|
|
1508
1510
|
if (rating === 0) sql`DELETE FROM chat_message_feedback
|
|
1509
1511
|
WHERE chat_id = ${durableObjectName} AND message_id = ${messageId}`;
|
|
@@ -1836,9 +1838,15 @@ var Assistant = class extends Agent$1 {
|
|
|
1836
1838
|
registerChat(this.sql.bind(this), durableObjectName, Date.now());
|
|
1837
1839
|
}
|
|
1838
1840
|
async recordChatTurn(durableObjectName, messages) {
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1841
|
+
this.keepAliveWhile(async () => {
|
|
1842
|
+
await Promise.all([summariseChatWithAI(this.sql.bind(this), durableObjectName, messages, this.fastModel), this.scheduleChatForAutoDeletion(durableObjectName).catch((error) => {
|
|
1843
|
+
console.error("[Assistant] Failed to reschedule chat deletion", {
|
|
1844
|
+
durableObjectName,
|
|
1845
|
+
error
|
|
1846
|
+
});
|
|
1847
|
+
})]);
|
|
1848
|
+
}).catch((error) => {
|
|
1849
|
+
console.error("[Assistant] Failed to record chat metadata", {
|
|
1842
1850
|
durableObjectName,
|
|
1843
1851
|
error
|
|
1844
1852
|
});
|
|
@@ -1939,6 +1947,7 @@ function ensureFeedbackTableExists(sql) {
|
|
|
1939
1947
|
* @param now - The date and time to use for the created_at and updated_at columns.
|
|
1940
1948
|
*/
|
|
1941
1949
|
function submitMessageFeedback(sql, messageId, rating, comment, now = /* @__PURE__ */ new Date()) {
|
|
1950
|
+
if (rating !== 1 && rating !== -1 && rating !== 0) throw new RangeError("Message feedback rating must be 1, -1, or 0");
|
|
1942
1951
|
try {
|
|
1943
1952
|
if (rating === 0) {
|
|
1944
1953
|
sql`DELETE FROM assistant_messages_feedback WHERE message_id = ${messageId}`;
|