@economic/agents 2.10.1 → 2.10.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.
Files changed (2) hide show
  1. package/dist/index.mjs +12 -7
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1480,6 +1480,11 @@ function registerChat(sql, durableObjectName, dateTime) {
1480
1480
  VALUES (${durableObjectName}, ${dateTime}, ${dateTime})
1481
1481
  ON CONFLICT (durable_object_name) DO NOTHING`;
1482
1482
  }
1483
+ function touchChat(sql, durableObjectName, dateTime = Date.now()) {
1484
+ sql`UPDATE chats
1485
+ SET updated_at = ${dateTime}
1486
+ WHERE durable_object_name = ${durableObjectName}`;
1487
+ }
1483
1488
  /**
1484
1489
  * Sets a chat's title on the user's behalf. Marks the title as user-set so
1485
1490
  * the AI summariser stops overwriting it (it keeps updating the summary).
@@ -1528,15 +1533,14 @@ function recordChatFeedback(sql, durableObjectName, messageId, rating, dateTime
1528
1533
  function getDeleteChatScheduleIds(schedules, durableObjectName) {
1529
1534
  return schedules.filter((schedule) => schedule.callback === "deleteChatCallback" && schedule.payload === durableObjectName).map((schedule) => schedule.id);
1530
1535
  }
1531
- /**
1532
- * Number of recent messages passed to `generateSummary` for rolling
1533
- * summarization. Keeping this bounded prevents the prompt growing
1534
- * unboundedly regardless of chat length.
1535
- */
1536
- const CHAT_RECENT_MESSAGES_COUNT = 20;
1536
+ const CHAT_SUMMARY_TURN_INTERVAL = 5;
1537
+ function isChatSummaryDue(messages) {
1538
+ const completedTurns = messages.filter((message) => message.role === "user").length;
1539
+ return completedTurns > 0 && completedTurns % CHAT_SUMMARY_TURN_INTERVAL === 0;
1540
+ }
1537
1541
  async function summariseChatWithAI(sql, durableObjectName, messages, model) {
1538
1542
  const chat = getChat(sql, durableObjectName);
1539
- if (!(!chat || !chat.title || messages.length % CHAT_RECENT_MESSAGES_COUNT === 0)) return;
1543
+ if (!(!chat || !chat.title || isChatSummaryDue(messages))) return;
1540
1544
  let systemPrompt = `
1541
1545
  You are a helpful assistant that summarises chats.
1542
1546
  You will be given a list of messages and you need to generate a title and summary for the chat.
@@ -1838,6 +1842,7 @@ var Assistant = class extends Agent$1 {
1838
1842
  registerChat(this.sql.bind(this), durableObjectName, Date.now());
1839
1843
  }
1840
1844
  async recordChatTurn(durableObjectName, messages) {
1845
+ touchChat(this.sql.bind(this), durableObjectName);
1841
1846
  this.keepAliveWhile(async () => {
1842
1847
  await Promise.all([summariseChatWithAI(this.sql.bind(this), durableObjectName, messages, this.fastModel), this.scheduleChatForAutoDeletion(durableObjectName).catch((error) => {
1843
1848
  console.error("[Assistant] Failed to reschedule chat deletion", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.10.1",
3
+ "version": "2.10.2",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "files": [