@economic/agents 2.4.0 → 2.5.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/dist/index.d.mts CHANGED
@@ -286,6 +286,7 @@ type Chat = {
286
286
  durable_object_name: string;
287
287
  title?: string;
288
288
  summary?: string;
289
+ title_set_by_user: number;
289
290
  created_at: number;
290
291
  updated_at: number;
291
292
  positive_feedback_count: number;
@@ -302,6 +303,7 @@ declare abstract class Assistant<State = unknown> extends Agent$1<Cloudflare.Env
302
303
  onConnect(connection: Connection, ctx: ConnectionContext): Promise<void>;
303
304
  createChat(): Promise<string>;
304
305
  deleteChat(id: string): Promise<void>;
306
+ renameChat(id: string, title: string): Promise<void>;
305
307
  getChats(): Promise<Chat[]>;
306
308
  getChatAgentClassName(): Promise<string>;
307
309
  recordChatTurn(durableObjectName: string, messages: UIMessage[]): Promise<void>;
package/dist/index.mjs CHANGED
@@ -504,6 +504,7 @@ function ensureChatsTableExists(sql) {
504
504
  durable_object_name TEXT NOT NULL,
505
505
  title TEXT,
506
506
  summary TEXT,
507
+ title_set_by_user INTEGER NOT NULL DEFAULT 0,
507
508
  created_at INTEGER NOT NULL,
508
509
  updated_at INTEGER NOT NULL,
509
510
  positive_feedback_count INTEGER NOT NULL DEFAULT 0,
@@ -511,6 +512,7 @@ function ensureChatsTableExists(sql) {
511
512
  PRIMARY KEY (durable_object_name)
512
513
  )`;
513
514
  ensureChatsFeedbackColumnsExist(sql);
515
+ ensureChatsTitleSetByUserColumnExists(sql);
514
516
  ensureChatMessageFeedbackTableExists(sql);
515
517
  } catch (error) {
516
518
  console.error("[Agent] Failed to create chats table", error);
@@ -524,6 +526,11 @@ function ensureChatsFeedbackColumnsExist(sql) {
524
526
  sql`ALTER TABLE chats ADD COLUMN negative_feedback_count INTEGER NOT NULL DEFAULT 0`;
525
527
  } catch {}
526
528
  }
529
+ function ensureChatsTitleSetByUserColumnExists(sql) {
530
+ try {
531
+ sql`ALTER TABLE chats ADD COLUMN title_set_by_user INTEGER NOT NULL DEFAULT 0`;
532
+ } catch {}
533
+ }
527
534
  function ensureChatMessageFeedbackTableExists(sql) {
528
535
  sql`CREATE TABLE IF NOT EXISTS chat_message_feedback (
529
536
  chat_id TEXT NOT NULL,
@@ -552,6 +559,19 @@ function registerChatWithMetadata(sql, durableObjectName, metadata) {
552
559
  VALUES (${durableObjectName}, ${title ?? null}, ${summary ?? null}, ${createdAt}, ${updatedAt})
553
560
  ON CONFLICT (durable_object_name) DO NOTHING`;
554
561
  }
562
+ /**
563
+ * Sets a chat's title on the user's behalf. Marks the title as user-set so
564
+ * the AI summariser stops overwriting it (it keeps updating the summary).
565
+ */
566
+ function renameChat(sql, durableObjectName, title, dateTime = Date.now()) {
567
+ const trimmed = title.trim();
568
+ if (!trimmed) throw new Error("Chat title cannot be empty");
569
+ sql`UPDATE chats
570
+ SET title = ${trimmed},
571
+ title_set_by_user = 1,
572
+ updated_at = ${dateTime}
573
+ WHERE durable_object_name = ${durableObjectName}`;
574
+ }
555
575
  function deleteChat(sql, durableObjectName) {
556
576
  sql`DELETE FROM chats WHERE durable_object_name = ${durableObjectName}`;
557
577
  sql`DELETE FROM chat_message_feedback WHERE chat_id = ${durableObjectName}`;
@@ -623,7 +643,7 @@ async function summariseChatWithAI(sql, durableObjectName, messages, model) {
623
643
  return;
624
644
  }
625
645
  sql`UPDATE chats
626
- SET title = ${title},
646
+ SET title = CASE WHEN title_set_by_user = 1 THEN title ELSE ${title} END,
627
647
  summary = ${summary},
628
648
  updated_at = ${Date.now()}
629
649
  WHERE durable_object_name = ${durableObjectName}`;
@@ -870,6 +890,11 @@ var Assistant = class extends Agent$1 {
870
890
  2,
871
891
  "deleteChat"
872
892
  ],
893
+ [
894
+ callable(),
895
+ 2,
896
+ "renameChat"
897
+ ],
873
898
  [
874
899
  callable(),
875
900
  2,
@@ -933,6 +958,9 @@ var Assistant = class extends Agent$1 {
933
958
  await this.deleteSubAgent(this.agent, id);
934
959
  deleteChat(this.sql.bind(this), id);
935
960
  }
961
+ async renameChat(id, title) {
962
+ renameChat(this.sql.bind(this), id, title);
963
+ }
936
964
  async getChats() {
937
965
  return getChats(this.sql.bind(this));
938
966
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "files": [