mirror of
https://github.com/open-webui/computer.git
synced 2026-11-20 21:41:54 +03:00
refac
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
content: string;
|
||||
done: boolean;
|
||||
output: any[] | null;
|
||||
usage: Record<string, number> | null;
|
||||
chatId: string | null;
|
||||
messageId: string;
|
||||
siblingIndex?: number;
|
||||
@@ -24,6 +25,7 @@
|
||||
content,
|
||||
done,
|
||||
output,
|
||||
usage,
|
||||
chatId,
|
||||
messageId,
|
||||
siblingIndex = 0,
|
||||
@@ -38,6 +40,7 @@
|
||||
let editedContent = $state('');
|
||||
let editedOutput = $state<any[] | null>(null);
|
||||
let copied = $state(false);
|
||||
let showUsageTooltip = $state(false);
|
||||
let textareaEl: HTMLTextAreaElement;
|
||||
|
||||
// Track which tool call outputs are expanded
|
||||
@@ -279,6 +282,23 @@
|
||||
function groupHasRejected(calls: any[]): boolean {
|
||||
return calls.some((c: any) => c.status === 'rejected');
|
||||
}
|
||||
|
||||
/** Format usage data for tooltip display */
|
||||
function formatUsageLabel(key: string): string {
|
||||
return key.replace(/_/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase());
|
||||
}
|
||||
|
||||
function formatUsageValue(key: string, value: number): string {
|
||||
if (key.includes('time') || key.includes('duration') || key.includes('latency')) {
|
||||
if (value >= 1000) return `${(value / 1000).toFixed(2)}s`;
|
||||
return `${value.toFixed(0)}ms`;
|
||||
}
|
||||
if (key.includes('token') || key.includes('count')) {
|
||||
return value.toLocaleString();
|
||||
}
|
||||
if (Number.isInteger(value)) return value.toLocaleString();
|
||||
return value.toFixed(2);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
@@ -934,6 +954,56 @@
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
{#if done && usage && Object.keys(usage).length > 0}
|
||||
<div class="relative flex items-center">
|
||||
<button
|
||||
class="p-0.5 rounded text-gray-400 dark:text-gray-600 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100"
|
||||
onclick={() => (showUsageTooltip = !showUsageTooltip)}
|
||||
onmouseenter={() => (showUsageTooltip = true)}
|
||||
onmouseleave={() => (showUsageTooltip = false)}
|
||||
aria-label="Usage info"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke-width="2"
|
||||
stroke="currentColor"
|
||||
class="w-3.5 h-3.5"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
{#if showUsageTooltip}
|
||||
<div
|
||||
class="absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 z-50
|
||||
bg-gray-900 dark:bg-gray-800 text-gray-100 dark:text-gray-100
|
||||
rounded-lg shadow-lg px-2.5 py-1.5 text-[10px] font-mono
|
||||
whitespace-nowrap pointer-events-none
|
||||
min-w-[160px] border border-transparent dark:border-gray-700"
|
||||
>
|
||||
<div class="space-y-0.5">
|
||||
{#each Object.entries(usage) as [key, value]}
|
||||
<div class="flex justify-between gap-4">
|
||||
<span class="text-gray-400 dark:text-gray-400">{formatUsageLabel(key)}</span>
|
||||
<span class="tabular-nums text-white dark:text-gray-200">{formatUsageValue(key, value)}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<!-- Arrow -->
|
||||
<div class="absolute top-full left-1/2 -translate-x-1/2 w-0 h-0
|
||||
border-l-[5px] border-l-transparent
|
||||
border-r-[5px] border-r-transparent
|
||||
border-t-[5px] border-t-gray-900 dark:border-t-gray-800"
|
||||
></div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -929,6 +929,7 @@
|
||||
content={msg.content}
|
||||
done={msg.done}
|
||||
output={msg.output}
|
||||
usage={msg.usage}
|
||||
{chatId}
|
||||
messageId={msg.id}
|
||||
{siblingIndex}
|
||||
|
||||
Reference in New Issue
Block a user