detailed logs

This commit is contained in:
Julian Freeman
2026-03-28 19:41:05 -04:00
parent f3150f06fa
commit ac951c31b1
4 changed files with 88 additions and 29 deletions

View File

@@ -19,9 +19,20 @@ watch(() => settings.logs, (newVal) => {
}
}, { immediate: true });
const decodeUnicode = (str: string) => {
if (!str) return str;
try {
return str.replace(/\\u([0-9a-fA-F]{4})/g, (_match, grp) => {
return String.fromCharCode(parseInt(grp, 16));
});
} catch {
return str;
}
};
const getLogSummary = (log: any) => {
if (log.type === 'error') return String(log.content);
if (typeof log.content === 'string') return log.content;
if (typeof log.content === 'string') return decodeUnicode(log.content);
if (log.content && log.content.model) return `Model: ${log.content.model}`;
if (log.content && log.content.score) return `Score: ${log.content.score}`;
return 'JSON Data';
@@ -92,18 +103,37 @@ const getLogSummary = (log: any) => {
)"
>{{ selectedLogItem.type === 'request' ? 'Request' : selectedLogItem.type === 'response' ? 'Response' : 'Error' }}</span>
</div>
<button
@click="copyWithFeedback(typeof selectedLogItem.content === 'object' ? JSON.stringify(selectedLogItem.content, null, 2) : String(selectedLogItem.content), `log-${selectedLogItem.id}`)"
class="flex items-center gap-2 px-3 py-2 text-xs font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800 rounded-lg transition-colors border border-slate-200 dark:border-slate-700"
>
<Check v-if="activeCopyId === `log-${selectedLogItem.id}`" class="w-4 h-4 text-green-600" />
<Copy v-else class="w-4 h-4" />
复制内容
</button>
<div class="flex gap-2">
<button
v-if="selectedLogItem.curl"
@click="copyWithFeedback(decodeUnicode(selectedLogItem.curl), `curl-${selectedLogItem.id}`)"
class="flex items-center gap-2 px-3 py-2 text-xs font-medium text-blue-600 hover:bg-blue-50 dark:text-blue-400 dark:hover:bg-blue-900/30 rounded-lg transition-colors border border-blue-100 dark:border-blue-900/50"
>
<Check v-if="activeCopyId === `curl-${selectedLogItem.id}`" class="w-4 h-4" />
<Copy v-else class="w-4 h-4" />
复制 cURL
</button>
<button
@click="copyWithFeedback(decodeUnicode(typeof selectedLogItem.content === 'object' ? JSON.stringify(selectedLogItem.content, null, 2) : String(selectedLogItem.content)), `log-${selectedLogItem.id}`)"
class="flex items-center gap-2 px-3 py-2 text-xs font-medium text-slate-600 hover:bg-slate-100 dark:text-slate-300 dark:hover:bg-slate-800 rounded-lg transition-colors border border-slate-200 dark:border-slate-700"
>
<Check v-if="activeCopyId === `log-${selectedLogItem.id}`" class="w-4 h-4 text-green-600" />
<Copy v-else class="w-4 h-4" />
复制内容
</button>
</div>
</div>
<div class="flex-1 overflow-auto p-6 bg-slate-50/30 dark:bg-slate-900/50 custom-scrollbar">
<pre class="font-mono text-xs leading-relaxed text-slate-700 dark:text-slate-300 whitespace-pre-wrap break-all">{{ typeof selectedLogItem.content === 'object' ? JSON.stringify(selectedLogItem.content, null, 2) : selectedLogItem.content }}</pre>
<div class="flex-1 overflow-auto p-6 bg-slate-50/30 dark:bg-slate-900/50 custom-scrollbar space-y-6">
<div v-if="selectedLogItem.curl" class="space-y-2">
<h3 class="text-[10px] font-bold text-slate-400 uppercase tracking-widest px-1">cURL 请求命令</h3>
<pre class="font-mono text-[11px] leading-relaxed p-4 bg-slate-950 text-blue-400 rounded-xl border border-slate-800 whitespace-pre-wrap break-all shadow-inner">{{ decodeUnicode(selectedLogItem.curl) }}</pre>
</div>
<div class="space-y-2">
<h3 class="text-[10px] font-bold text-slate-400 uppercase tracking-widest px-1">{{ selectedLogItem.type === 'request' ? 'Payload (JSON)' : 'Response Data' }}</h3>
<pre class="font-mono text-[11px] leading-relaxed p-4 bg-slate-950 text-slate-300 rounded-xl border border-slate-800 whitespace-pre-wrap break-all shadow-inner">{{ decodeUnicode(typeof selectedLogItem.content === 'object' ? JSON.stringify(selectedLogItem.content, null, 2) : selectedLogItem.content) }}</pre>
</div>
</div>
</template>
<div v-else class="flex-1 flex flex-col items-center justify-center text-slate-300 dark:text-slate-800 p-10 text-center space-y-4">