debug: 添加自动命名调试日志
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
517d8e493c
commit
6464135cf6
@ -375,30 +375,42 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
}
|
||||
|
||||
// 如果是第一次上传图片,自动识别并设置画布标题和缩略图
|
||||
console.log('[CanvasChat] 检查是否需要自动命名:', {
|
||||
firstImageUrl: !!firstImageUrl,
|
||||
hasSetCanvasTitle: hasSetCanvasTitle.current
|
||||
});
|
||||
|
||||
if (firstImageUrl && !hasSetCanvasTitle.current) {
|
||||
hasSetCanvasTitle.current = true;
|
||||
console.log('[CanvasChat] 开始调用 auto-title API...');
|
||||
|
||||
// 异步调用 AI 识别图片主体并更新画布
|
||||
(async () => {
|
||||
try {
|
||||
// 调用 auto-title API 识别图片主体
|
||||
console.log('[CanvasChat] 发送 auto-title 请求:', firstImageUrl);
|
||||
const response = await fetch('/api/canvas/auto-title', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ imageUrl: firstImageUrl }),
|
||||
});
|
||||
|
||||
console.log('[CanvasChat] auto-title 响应状态:', response.status);
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
const title = data.title || '未命名画布';
|
||||
console.log('[CanvasChat] 识别到的标题:', title);
|
||||
|
||||
// 提取纯 UUID(去掉 canvas- 前缀)
|
||||
const rawId = chatId.startsWith('canvas-')
|
||||
? chatId.replace('canvas-', '')
|
||||
: chatId;
|
||||
|
||||
console.log('[CanvasChat] 更新画布:', rawId);
|
||||
|
||||
// 更新画布标题和缩略图
|
||||
await fetch(`/api/canvas/${rawId}`, {
|
||||
const updateResponse = await fetch(`/api/canvas/${rawId}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
@ -407,8 +419,16 @@ export function CanvasChatPanel({ chatId, initialMessages = [], onClose, onOpenF
|
||||
}),
|
||||
});
|
||||
|
||||
console.log('[CanvasChat] 画布已自动命名为:', title);
|
||||
toast.success(`画布已命名为: ${title}`);
|
||||
console.log('[CanvasChat] 画布更新响应:', updateResponse.status);
|
||||
|
||||
if (updateResponse.ok) {
|
||||
console.log('[CanvasChat] 画布已自动命名为:', title);
|
||||
toast.success(`画布已命名为: ${title}`);
|
||||
} else {
|
||||
console.error('[CanvasChat] 画布更新失败');
|
||||
}
|
||||
} else {
|
||||
console.error('[CanvasChat] auto-title API 请求失败:', response.status);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[CanvasChat] 自动命名失败:', error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user