@economic/agents 1.5.0 → 1.6.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.d.mts
CHANGED
|
@@ -134,6 +134,12 @@ declare abstract class Agent<Env extends Cloudflare.Env = Cloudflare.Env> extend
|
|
|
134
134
|
}): Promise<LLMParams>;
|
|
135
135
|
}
|
|
136
136
|
//#endregion
|
|
137
|
+
//#region src/server/agent-chat/features/conversations/rating.d.ts
|
|
138
|
+
interface MessageRating {
|
|
139
|
+
rating: number;
|
|
140
|
+
comment?: string;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
137
143
|
//#region src/server/agent-chat/ChatAgent.d.ts
|
|
138
144
|
/**
|
|
139
145
|
* Chat agent for Cloudflare Agents SDK: lazy skill loading, audit logging,
|
|
@@ -227,8 +233,8 @@ declare abstract class ChatAgent<Env extends Cloudflare.Env = Cloudflare.Env> ex
|
|
|
227
233
|
_deleteStaleRows?: boolean;
|
|
228
234
|
}): Promise<void>;
|
|
229
235
|
protected onChatResponse(result: ChatResponseResult): Promise<void>;
|
|
230
|
-
rateMessage(messageId: string, rating: number): Promise<void>;
|
|
231
|
-
getMessageRatings(): Promise<Record<string,
|
|
236
|
+
rateMessage(messageId: string, rating: number, comment?: string): Promise<void>;
|
|
237
|
+
getMessageRatings(): Promise<Record<string, MessageRating>>;
|
|
232
238
|
getConversations(): Promise<Record<string, unknown>[]>;
|
|
233
239
|
deleteConversation(id: string): Promise<boolean>;
|
|
234
240
|
destroy(): Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -799,17 +799,21 @@ function filterEphemeralMessages(messages) {
|
|
|
799
799
|
}
|
|
800
800
|
//#endregion
|
|
801
801
|
//#region src/server/agent-chat/features/conversations/rating.ts
|
|
802
|
-
async function rateMessage(db, durableObjectName, messageId, rating) {
|
|
802
|
+
async function rateMessage(db, durableObjectName, messageId, rating, comment) {
|
|
803
803
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
804
|
-
await db.prepare(`INSERT INTO message_ratings (message_id, durable_object_name, rating, created_at, updated_at)
|
|
805
|
-
VALUES (?, ?, ?, ?, ?)
|
|
804
|
+
await db.prepare(`INSERT INTO message_ratings (message_id, durable_object_name, rating, comment, created_at, updated_at)
|
|
805
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
806
806
|
ON CONFLICT (message_id, durable_object_name) DO UPDATE SET
|
|
807
807
|
rating = excluded.rating,
|
|
808
|
-
|
|
808
|
+
comment = excluded.comment,
|
|
809
|
+
updated_at = excluded.updated_at`).bind(messageId, durableObjectName, rating, comment ?? null, now, now).run();
|
|
809
810
|
}
|
|
810
811
|
async function getMessageRatings(db, durableObjectName) {
|
|
811
|
-
const result = await db.prepare(`SELECT message_id, rating FROM message_ratings WHERE durable_object_name = ?`).bind(durableObjectName).all();
|
|
812
|
-
return Object.fromEntries(result.results.map((row) => [row.message_id,
|
|
812
|
+
const result = await db.prepare(`SELECT message_id, rating, comment FROM message_ratings WHERE durable_object_name = ?`).bind(durableObjectName).all();
|
|
813
|
+
return Object.fromEntries(result.results.map((row) => [row.message_id, {
|
|
814
|
+
rating: row.rating,
|
|
815
|
+
...row.comment != null ? { comment: row.comment } : {}
|
|
816
|
+
}]));
|
|
813
817
|
}
|
|
814
818
|
//#endregion
|
|
815
819
|
//#region src/server/agent-chat/ChatAgent.ts
|
|
@@ -944,8 +948,8 @@ var ChatAgent = class extends AIChatAgent {
|
|
|
944
948
|
recordConversationSummary(this.env.AGENT_DB, this.name, this.messages, this.getFastModel());
|
|
945
949
|
this.scheduleConversationForAutoDeletion();
|
|
946
950
|
}
|
|
947
|
-
@callable({ description: "Rate a message by its id" }) async rateMessage(messageId, rating) {
|
|
948
|
-
await rateMessage(this.env.AGENT_DB, this.name, messageId, rating);
|
|
951
|
+
@callable({ description: "Rate a message by its id" }) async rateMessage(messageId, rating, comment) {
|
|
952
|
+
await rateMessage(this.env.AGENT_DB, this.name, messageId, rating, comment);
|
|
949
953
|
}
|
|
950
954
|
@callable({ description: "Returns all message ratings for the current conversation" }) async getMessageRatings() {
|
|
951
955
|
return getMessageRatings(this.env.AGENT_DB, this.name);
|
|
@@ -1032,7 +1036,7 @@ var ChatAgentHarness = class extends ChatAgent {
|
|
|
1032
1036
|
system: this.getSystemPrompt(ctx),
|
|
1033
1037
|
skills: this.getSkills(ctx),
|
|
1034
1038
|
tools: this.getTools(ctx)
|
|
1035
|
-
})).toUIMessageStreamResponse();
|
|
1039
|
+
})).toUIMessageStreamResponse({ sendSources: true });
|
|
1036
1040
|
}
|
|
1037
1041
|
};
|
|
1038
1042
|
//#endregion
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ALTER TABLE message_ratings ADD COLUMN comment TEXT;
|
|
File without changes
|
|
File without changes
|