Unverified 提交 3ac759c4 authored 作者: Mohamed Aziz Mejri's avatar Mohamed Aziz Mejri 提交者: GitHub

Showing used model for generated message (#2003)

close #1994 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Show the model used for each assistant message in chat and persist it in the database for transparency. Addresses #1994. - **New Features** - Add model field to messages schema and Message type. - Set the model on assistant messages when streaming. - Display the model with a Bot icon next to approval status in ChatMessage. <sup>Written for commit 181b7f919a9c29c0627b3dc74f49cf5989b7243d. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds transparent model tracking for assistant messages. > > - Schema: add `model` to `messages` (migration + Drizzle schema) and `Message` type > - Streaming: set `model` on placeholder assistant messages in `chat_stream_handlers.ts` > - UI: show `message.model` with a Bot icon next to approval status in `ChatMessage` > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 6411d57704648f3d92263b72681cd3fa08583152. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
上级 6a5efb94
ALTER TABLE `messages` ADD `model` text;
\ No newline at end of file
差异被折叠。
...@@ -141,6 +141,13 @@ ...@@ -141,6 +141,13 @@
"when": 1766529533747, "when": 1766529533747,
"tag": "0019_cute_carnage", "tag": "0019_cute_carnage",
"breakpoints": true "breakpoints": true
},
{
"idx": 20,
"version": "6",
"when": 1766619976318,
"tag": "0020_nebulous_patch",
"breakpoints": true
} }
] ]
} }
\ No newline at end of file
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
Copy, Copy,
Check, Check,
Info, Info,
Bot,
} from "lucide-react"; } from "lucide-react";
import { formatDistanceToNow, format } from "date-fns"; import { formatDistanceToNow, format } from "date-fns";
import { useVersions } from "@/hooks/useVersions"; import { useVersions } from "@/hooks/useVersions";
...@@ -158,10 +159,7 @@ const ChatMessage = ({ message, isLastMessage }: ChatMessageProps) => { ...@@ -158,10 +159,7 @@ const ChatMessage = ({ message, isLastMessage }: ChatMessageProps) => {
message.approvalState ? ( message.approvalState ? (
<div <div
className={`mt-2 flex items-center ${ className={`mt-2 flex items-center ${
message.role === "assistant" && message.role === "assistant" && message.content && !isStreaming
message.content &&
!isStreaming &&
message.approvalState
? "justify-between" ? "justify-between"
: "" : ""
} text-xs`} } text-xs`}
...@@ -191,21 +189,29 @@ const ChatMessage = ({ message, isLastMessage }: ChatMessageProps) => { ...@@ -191,21 +189,29 @@ const ChatMessage = ({ message, isLastMessage }: ChatMessageProps) => {
</Tooltip> </Tooltip>
</TooltipProvider> </TooltipProvider>
)} )}
{message.approvalState && ( <div className="flex flex-wrap gap-2">
<div className="flex items-center space-x-1"> {message.approvalState && (
{message.approvalState === "approved" ? ( <div className="flex items-center space-x-1">
<> {message.approvalState === "approved" ? (
<CheckCircle className="h-4 w-4 text-green-500" /> <>
<span>Approved</span> <CheckCircle className="h-4 w-4 text-green-500" />
</> <span>Approved</span>
) : message.approvalState === "rejected" ? ( </>
<> ) : message.approvalState === "rejected" ? (
<XCircle className="h-4 w-4 text-red-500" /> <>
<span>Rejected</span> <XCircle className="h-4 w-4 text-red-500" />
</> <span>Rejected</span>
) : null} </>
</div> ) : null}
)} </div>
)}
{message.role === "assistant" && message.model && (
<div className="flex items-center gap-1 text-gray-500 dark:text-gray-400 w-full sm:w-auto">
<Bot className="h-4 w-4 flex-shrink-0" />
<span>{message.model}</span>
</div>
)}
</div>
</div> </div>
) : null} ) : null}
</div> </div>
......
...@@ -89,6 +89,8 @@ export const messages = sqliteTable("messages", { ...@@ -89,6 +89,8 @@ export const messages = sqliteTable("messages", {
requestId: text("request_id"), requestId: text("request_id"),
// Max tokens used for this message (only for assistant messages) // Max tokens used for this message (only for assistant messages)
maxTokensUsed: integer("max_tokens_used"), maxTokensUsed: integer("max_tokens_used"),
// Model name used for this message (only for assistant messages)
model: text("model"),
// AI SDK messages (v5 envelope) for preserving tool calls/results in agent mode // AI SDK messages (v5 envelope) for preserving tool calls/results in agent mode
aiMessagesJson: text("ai_messages_json", { aiMessagesJson: text("ai_messages_json", {
mode: "json", mode: "json",
......
...@@ -422,6 +422,7 @@ ${componentSnippet} ...@@ -422,6 +422,7 @@ ${componentSnippet}
role: "assistant", role: "assistant",
content: "", // Start with empty content content: "", // Start with empty content
requestId: dyadRequestId, requestId: dyadRequestId,
model: settings.selectedModel.name,
sourceCommitHash: await getCurrentCommitHash({ sourceCommitHash: await getCurrentCommitHash({
path: getDyadAppPath(chat.app.path), path: getDyadAppPath(chat.app.path),
}), }),
......
...@@ -85,6 +85,7 @@ export interface Message { ...@@ -85,6 +85,7 @@ export interface Message {
createdAt?: Date | string; createdAt?: Date | string;
requestId?: string | null; requestId?: string | null;
totalTokens?: number | null; totalTokens?: number | null;
model?: string | null;
} }
export interface Chat { export interface Chat {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论