@economic/agents 2.1.2 → 2.1.3

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/v2.mjs +11 -14
  2. package/package.json +1 -1
package/dist/v2.mjs CHANGED
@@ -473,12 +473,11 @@ function ensureRatingsTableExists(sql) {
473
473
  try {
474
474
  sql`CREATE TABLE IF NOT EXISTS assistant_messages_ratings (
475
475
  message_id TEXT NOT NULL,
476
- durable_object_name TEXT NOT NULL,
477
476
  rating INTEGER,
478
477
  comment TEXT,
479
- created_at TEXT NOT NULL,
480
- updated_at TEXT NOT NULL,
481
- PRIMARY KEY (message_id, durable_object_name)
478
+ created_at INTEGER NOT NULL,
479
+ updated_at INTEGER NOT NULL,
480
+ PRIMARY KEY (message_id)
482
481
  )`;
483
482
  } catch (error) {
484
483
  console.error("[Agent] Failed to create ratings table", error);
@@ -488,15 +487,14 @@ function ensureRatingsTableExists(sql) {
488
487
  * Rates a message.
489
488
  * @param sql - The SQL function to use to execute the query.
490
489
  * @param messageId - The ID of the message to rate.
491
- * @param durable_object_name - The name of the Durable Object to rate the message for.
492
490
  * @param rating - The rating to give the message.
493
491
  * @param now - The date and time to use for the created_at and updated_at columns.
494
492
  */
495
- function rateMessage(sql, messageId, durable_object_name, rating, comment, now = /* @__PURE__ */ new Date()) {
493
+ function rateMessage(sql, messageId, rating, comment, now = /* @__PURE__ */ new Date()) {
496
494
  try {
497
- sql`INSERT INTO assistant_messages_ratings (message_id, durable_object_name, rating, comment, created_at, updated_at)
498
- VALUES (${messageId}, ${durable_object_name}, ${rating}, ${comment ?? null}, ${now.toISOString()}, ${now.toISOString()})
499
- ON CONFLICT (message_id, durable_object_name) DO UPDATE SET
495
+ sql`INSERT INTO assistant_messages_ratings (message_id, rating, comment, created_at, updated_at)
496
+ VALUES (${messageId}, ${rating}, ${comment ?? null}, ${now.getTime()}, ${now.getTime()})
497
+ ON CONFLICT (message_id) DO UPDATE SET
500
498
  rating = excluded.rating,
501
499
  comment = excluded.comment,
502
500
  updated_at = excluded.updated_at`;
@@ -507,12 +505,11 @@ function rateMessage(sql, messageId, durable_object_name, rating, comment, now =
507
505
  /**
508
506
  * Gets the ratings for a message.
509
507
  * @param sql - The SQL function to use to execute the query.
510
- * @param durable_object_name - The name of the Durable Object to get the ratings for.
511
508
  * @returns A record of message IDs and their ratings.
512
509
  */
513
- function getMessageRatings(sql, durable_object_name) {
510
+ function getMessageRatings(sql) {
514
511
  try {
515
- const ratings = sql`SELECT message_id, rating, comment FROM assistant_messages_ratings WHERE durable_object_name = ${durable_object_name}`;
512
+ const ratings = sql`SELECT message_id, rating, comment FROM assistant_messages_ratings`;
516
513
  return Object.fromEntries(ratings.map((row) => [row.message_id, {
517
514
  rating: row.rating,
518
515
  comment: row.comment
@@ -546,14 +543,14 @@ var ChatAgent = class extends Agent {
546
543
  * @returns The message id and the rating.
547
544
  */
548
545
  @callable({ description: "Rate a message by its id" }) async rateMessage(messageId, rating, comment) {
549
- return rateMessage(this.sql.bind(this), messageId, this.name, rating, comment);
546
+ return rateMessage(this.sql.bind(this), messageId, rating, comment);
550
547
  }
551
548
  /**
552
549
  * Returns all message ratings for the current chat.
553
550
  * @returns All message ratings for the current chat.
554
551
  */
555
552
  @callable({ description: "Returns all message ratings for the current chat" }) async getMessageRatings() {
556
- return getMessageRatings(this.sql.bind(this), this.name);
553
+ return getMessageRatings(this.sql.bind(this));
557
554
  }
558
555
  };
559
556
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@economic/agents",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
4
4
  "description": "A starter for creating a TypeScript package.",
5
5
  "license": "MIT",
6
6
  "bin": {