This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-13 19:59:11 -06:00
1 parent b018feb741
commit 7d99b2716a
27 files changed
+1069 -111

No files matched your search

@@ -6,7 +6,7 @@
import StructuredOutputRenderer from './StructuredOutputRenderer.svelte';
import {
artifactCode,
chatId,
chatId as currentChatId,
mobile,
settings,
showArtifacts,
@@ -68,6 +68,7 @@
};
export let id;
export let chatId = '';
export let content;
/** @type {import('./structuredOutput').OutputItem[]} */
export let output = [];
@@ -153,7 +154,7 @@
hasClosingCodeFence(raw) &&
!autoOpenedArtifactIds.has(artifactId) &&
!$mobile &&
$chatId
$currentChatId
) {
autoOpenedArtifactIds.add(artifactId);
await tick();
@@ -283,6 +284,8 @@
{#if output?.length}
<StructuredOutputRenderer
{id}
{chatId}
{messageId}
{output}
{model}
{save}
@@ -304,6 +307,8 @@
<div class="markdown-prose">
<Markdown
{id}
{chatId}
{messageId}
content={formatMessageContent(content)}
{model}
{save}
@@ -326,7 +331,16 @@
{#if extracted.detailsContent}
<!-- Render structural blocks (tool calls, reasoning, etc.) through Markdown -->
<div class="markdown-prose">
<Markdown {id} content={extracted.detailsContent} {preview} {compactPreview} {done} />
<Markdown
{id}
{chatId}
{messageId}
content={extracted.detailsContent}
{save}
{preview}
{compactPreview}
{done}
/>
</div>
{/if}
{#if extracted.plainContent}
@@ -36,6 +36,8 @@
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
export let id = '';
export let chatId = '';
export let messageId = '';
export let content;
export let done = true;
export let model = null;
@@ -101,6 +103,8 @@
<MarkdownTokens
{tokens}
{id}
{chatId}
{messageId}
{done}
{save}
{preview}
@@ -7,9 +7,9 @@
import ChevronUp from '$lib/components/icons/ChevronUp.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import WrenchSolid from '$lib/components/icons/WrenchSolid.svelte';
import Sparkles from '$lib/components/icons/Sparkles.svelte';
import CheckCircle from '$lib/components/icons/CheckCircle.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import FullHeightIframe from '$lib/components/common/FullHeightIframe.svelte';
import { settings } from '$lib/stores';
@@ -23,6 +23,8 @@
type?: string;
name?: string;
done?: string;
id?: string;
status?: string;
duration?: string;
embeds?: string;
arguments?: string;
@@ -32,6 +34,9 @@
export let messageDone = true;
export let allowEmbeds = true;
export let compactPreview = false;
export let resolvable = false;
export let resolvingCallId = '';
export let onResolve: (callId: string, approved: boolean) => void = () => {};
let open = $settings?.expandDetails ?? false;
@@ -45,9 +50,13 @@
$: toolCallCount = tokens.filter((t) => t?.attributes?.type === 'tool_calls').length;
$: reasoningCount = tokens.filter((t) => t?.attributes?.type === 'reasoning').length;
$: hasPending =
!messageDone &&
tokens.some((t) => t?.attributes?.done !== undefined && t?.attributes?.done !== 'true');
$: pendingToolTokens = tokens.filter(
(t) => t?.attributes?.type === 'tool_calls' && t?.attributes?.status === 'pending'
);
$: hasPending = pendingToolTokens.length > 0;
$: hasRejected = tokens.some(
(t) => t?.attributes?.type === 'tool_calls' && t?.attributes?.status === 'rejected'
);
$: codeInterpreterCount = tokens.filter((t) => t?.attributes?.type === 'code_interpreter').length;
@@ -102,7 +111,6 @@
}
}
const prefix = hasPending ? $i18n.t('Exploring') : $i18n.t('Explored');
const detail = parts.join(', ');
return detail;
})();
@@ -110,54 +118,120 @@
$: prefixText = hasPending ? $i18n.t('Exploring') : $i18n.t('Explored');
</script>
<div {id} class="w-full">
<!-- svelte-ignore a11y-no-static-element-interactions -->
<button
class="w-fit py-0.5 text-left {compactPreview
? 'text-xs'
: 'text-[0.9375rem]'} text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition cursor-pointer"
aria-label={$i18n.t('Toggle details')}
aria-expanded={open}
on:click={() => {
open = !open;
}}
>
<div class="flex items-center gap-1.5">
<!-- Status icon -->
{#if hasPending}
<div>
<Spinner className="size-4" />
</div>
{:else if toolCallCount > 0}
<div class="text-emerald-500 dark:text-emerald-400">
<CheckCircle className="size-4" strokeWidth="2" />
</div>
{:else}
<div class="text-gray-400 dark:text-gray-500">
<Sparkles className="size-3.5" />
</div>
{/if}
<!-- Summary text -->
<div class="flex-1 line-clamp-1">
<span class="text-gray-600 dark:text-gray-300 {hasPending ? 'shimmer' : ''}"
>{prefixText}</span
>
{#if summaryText}
<span class="text-gray-400 dark:text-gray-500">{summaryText}</span>
{/if}
</div>
<!-- Chevron -->
<div class="flex shrink-0 self-center text-gray-400 dark:text-gray-500">
{#if open}
<ChevronUp strokeWidth="3.5" className="size-3" />
<div {id} class="w-full min-w-0">
<div class="flex w-full min-w-0 items-center gap-2">
<div
role="button"
tabindex="0"
class="flex-1 min-w-0 py-0.5 text-left {compactPreview
? 'text-xs'
: 'text-[0.9375rem]'} text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition cursor-pointer"
aria-label={$i18n.t('Toggle details')}
aria-expanded={open}
on:click={() => {
open = !open;
}}
on:keydown={(event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
open = !open;
}
}}
>
<div class="flex items-center gap-1.5 min-w-0">
<!-- Status icon -->
{#if hasPending}
<div>
<Spinner className="size-4" />
</div>
{:else if hasRejected}
<div class="text-red-400 dark:text-red-500">
<XMark className="size-4" strokeWidth="2.5" />
</div>
{:else if toolCallCount > 0}
<div class="text-emerald-500 dark:text-emerald-400">
<CheckCircle className="size-4" strokeWidth="2" />
</div>
{:else}
<ChevronDown strokeWidth="3.5" className="size-3" />
<div class="text-gray-400 dark:text-gray-500">
<Sparkles className="size-3.5" />
</div>
{/if}
<!-- Summary text -->
<div class="flex-1 line-clamp-1">
<span class="text-gray-600 dark:text-gray-300 {hasPending ? 'shimmer' : ''}"
>{prefixText}</span
>
{#if summaryText}
<span class="text-gray-400 dark:text-gray-500">{summaryText}</span>
{/if}
</div>
{#if resolvable && pendingToolTokens.length === 1}
{@const pendingCallId = pendingToolTokens[0]?.attributes?.id ?? ''}
<span class="flex gap-1 shrink-0">
<button
type="button"
class="text-[0.6875rem] px-2.5 py-0.5 rounded-md text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-white/8 hover:bg-gray-200 dark:hover:bg-white/12 transition-colors duration-100 disabled:opacity-50"
disabled={!pendingCallId || resolvingCallId === pendingCallId}
on:click|stopPropagation={() => onResolve(pendingCallId, true)}
>
{$i18n.t('Allow')}
</button>
<button
type="button"
class="text-[0.6875rem] px-2 py-0.5 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 disabled:opacity-50"
disabled={!pendingCallId || resolvingCallId === pendingCallId}
on:click|stopPropagation={() => onResolve(pendingCallId, false)}
>
{$i18n.t('Deny')}
</button>
</span>
{:else}
<!-- Chevron -->
<div class="flex shrink-0 self-center text-gray-400 dark:text-gray-500">
{#if open}
<ChevronUp strokeWidth="3.5" className="size-3" />
{:else}
<ChevronDown strokeWidth="3.5" className="size-3" />
{/if}
</div>
{/if}
</div>
</div>
</button>
</div>
{#if !open && resolvable && pendingToolTokens.length > 1}
<div class="mt-1 space-y-0.5">
{#each pendingToolTokens as token}
{@const pendingCallId = token?.attributes?.id ?? ''}
<div class="flex items-center gap-2 py-1 px-1">
<span class="text-xs text-gray-500 dark:text-gray-400 flex-1 min-w-0 line-clamp-1">
{token?.attributes?.name ?? $i18n.t('tool')}
</span>
<span class="flex gap-1 shrink-0">
<button
type="button"
class="text-[0.6875rem] px-2.5 py-0.5 rounded-md text-gray-600 dark:text-gray-300 bg-gray-100 dark:bg-white/8 hover:bg-gray-200 dark:hover:bg-white/12 transition-colors duration-100 disabled:opacity-50"
disabled={!pendingCallId || resolvingCallId === pendingCallId}
on:click={() => onResolve(pendingCallId, true)}
>
{$i18n.t('Allow')}
</button>
<button
type="button"
class="text-[0.6875rem] px-2 py-0.5 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-600 dark:hover:text-gray-300 transition-colors duration-100 disabled:opacity-50"
disabled={!pendingCallId || resolvingCallId === pendingCallId}
on:click={() => onResolve(pendingCallId, false)}
>
{$i18n.t('Deny')}
</button>
</span>
</div>
{/each}
</div>
{/if}
{#if open}
<div transition:slide={{ duration: 300, easing: quintOut, axis: 'y' }}>
@@ -8,9 +8,11 @@
import { marked, type Token } from 'marked';
import { copyToClipboard, unescapeHtml } from '$lib/utils';
import { resolveChatMessageToolCall } from '$lib/apis/chats';
import { WEBUI_BASE_URL } from '$lib/constants';
import { settings } from '$lib/stores';
import { toast } from 'svelte-sonner';
import CodeBlock from '$lib/components/chat/Messages/CodeBlock.svelte';
import MarkdownInlineTokens from '$lib/components/chat/Messages/Markdown/MarkdownInlineTokens.svelte';
@@ -27,6 +29,8 @@
import ColonFenceBlock from './ColonFenceBlock.svelte';
export let id: string;
export let chatId = '';
export let messageId = '';
export let tokens: Token[];
export let top = true;
export let attributes = {};
@@ -98,7 +102,30 @@
.trim();
};
$: detailButtonClassName = `w-fit py-0.5 ${
let resolvingCallId = '';
const resolveToolCall = async (callId: string, approved: boolean) => {
if (!chatId || !messageId || !callId || resolvingCallId) {
return;
}
resolvingCallId = callId;
try {
await resolveChatMessageToolCall(
localStorage.token,
chatId,
messageId,
callId,
approved ? 'approve' : 'reject'
);
} catch (err) {
toast.error(String(err));
} finally {
resolvingCallId = '';
}
};
$: detailButtonClassName = `py-0.5 ${
compactPreview ? 'text-xs' : 'text-[0.9375rem]'
} text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition`;
@@ -279,8 +306,11 @@
<blockquote dir="auto">
<svelte:self
id={`${id}-${tokenIdx}`}
{chatId}
{messageId}
tokens={token.tokens}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -315,9 +345,12 @@
<svelte:self
id={`${id}-${tokenIdx}-${itemIdx}`}
{chatId}
{messageId}
tokens={item.tokens}
top={token.loose}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -352,9 +385,12 @@
<div>
<svelte:self
id={`${id}-${tokenIdx}-${itemIdx}`}
{chatId}
{messageId}
tokens={item.tokens}
top={token.loose}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -366,9 +402,12 @@
{:else}
<svelte:self
id={`${id}-${tokenIdx}-${itemIdx}`}
{chatId}
{messageId}
tokens={item.tokens}
top={token.loose}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -388,6 +427,9 @@
messageDone={done}
{compactPreview}
{allowEmbeds}
resolvable={!!chatId && !!messageId && save}
{resolvingCallId}
onResolve={resolveToolCall}
>
<div slot="content">
{#each token.items as detailToken, detailIdx}
@@ -399,6 +441,9 @@
attributes={detailToken.attributes}
resultContent={getDetailTextContent(detailToken)}
grouped={true}
resolvable={!!chatId && !!messageId && save}
resolving={resolvingCallId === detailToken.attributes?.id}
onResolve={(approved) => resolveToolCall(detailToken.attributes?.id ?? '', approved)}
open={$settings?.expandDetails ?? false}
className="w-full"
buttonClassName={detailButtonClassName}
@@ -416,9 +461,12 @@
<div class="mb-1.5" slot="content">
<svelte:self
id={`${id}-${tokenIdx}-${detailIdx}-d`}
{chatId}
{messageId}
tokens={marked.lexer(decode(detailToken.text))}
attributes={detailToken?.attributes}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -452,6 +500,9 @@
id={`${id}-${tokenIdx}-tc`}
attributes={token.attributes}
resultContent={getDetailTextContent(token)}
resolvable={!!chatId && !!messageId && save}
resolving={resolvingCallId === token.attributes?.id}
onResolve={(approved) => resolveToolCall(token.attributes?.id ?? '', approved)}
open={$settings?.expandDetails ?? false}
className="w-full space-y-2"
buttonClassName={detailButtonClassName}
@@ -469,9 +520,12 @@
<div class=" mb-1.5" slot="content">
<svelte:self
id={`${id}-${tokenIdx}-d`}
{chatId}
{messageId}
tokens={marked.lexer(decode(token.text))}
attributes={token?.attributes}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -815,6 +815,8 @@
<!-- unless message.error === true which is legacy error handling, where the error message is stored in message.content -->
<ContentRenderer
id={`${chatId}-${message.id}`}
{chatId}
messageId={message.id}
content={message.content}
output={message.output}
sources={message.sources}
@@ -1,7 +1,9 @@
<script lang="ts">
import Collapsible from '$lib/components/common/Collapsible.svelte';
import ToolCallDisplay from '$lib/components/common/ToolCallDisplay.svelte';
import { resolveChatMessageToolCall } from '$lib/apis/chats';
import { settings } from '$lib/stores';
import { toast } from 'svelte-sonner';
import Markdown from './Markdown.svelte';
import ConsecutiveDetailsGroup from './Markdown/ConsecutiveDetailsGroup.svelte';
@@ -13,6 +15,8 @@
} from './structuredOutput';
export let id = '';
export let chatId = '';
export let messageId = '';
export let output: OutputItem[] = [];
export let done = true;
export let model = null;
@@ -32,8 +36,30 @@
const getDetailTitle = (detailToken: OutputDetailToken): any => detailToken.summary;
const getDetailAttributes = (detailToken: OutputDetailToken): any => detailToken.attributes;
let resolvingCallId = '';
$: detailButtonClassName = `w-fit py-0.5 ${
const resolveToolCall = async (callId: string, approved: boolean) => {
if (!chatId || !messageId || !callId || resolvingCallId) {
return;
}
resolvingCallId = callId;
try {
await resolveChatMessageToolCall(
localStorage.token,
chatId,
messageId,
callId,
approved ? 'approve' : 'reject'
);
} catch (err) {
toast.error(String(err));
} finally {
resolvingCallId = '';
}
};
$: detailButtonClassName = `py-0.5 ${
compactPreview ? 'text-xs' : 'text-[0.9375rem]'
} text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition`;
@@ -46,6 +72,8 @@
<div class="markdown-prose">
<Markdown
id={`${id}-${displayItem.id}`}
{chatId}
{messageId}
content={formatMessageContent(displayItem.text)}
{model}
{save}
@@ -71,6 +99,9 @@
tokens={displayItem.tokens}
messageDone={done}
{compactPreview}
resolvable={!!chatId && !!messageId && save}
{resolvingCallId}
onResolve={resolveToolCall}
>
<div slot="content">
{#each displayItem.tokens as detailToken, detailIndex}
@@ -80,6 +111,9 @@
attributes={detailToken.attributes}
resultContent={detailToken.text}
grouped={true}
resolvable={!!chatId && !!messageId && save}
resolving={resolvingCallId === detailToken.attributes?.id}
onResolve={(approved) => resolveToolCall(detailToken.attributes?.id ?? '', approved)}
open={$settings?.expandDetails ?? false}
className="w-full"
buttonClassName={detailButtonClassName}
@@ -97,8 +131,11 @@
<div class="markdown-prose">
<Markdown
id={`${id}-${displayItem.id}-${detailIndex}-detail`}
{chatId}
{messageId}
content={detailToken.text}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -127,6 +164,9 @@
id={`${id}-${displayItem.id}-tool-call`}
attributes={detailToken.attributes}
resultContent={detailToken.text}
resolvable={!!chatId && !!messageId && save}
resolving={resolvingCallId === detailToken.attributes?.id}
onResolve={(approved) => resolveToolCall(detailToken.attributes?.id ?? '', approved)}
open={$settings?.expandDetails ?? false}
className="w-full space-y-2"
buttonClassName={detailButtonClassName}
@@ -144,8 +184,11 @@
<div class="markdown-prose">
<Markdown
id={`${id}-${displayItem.id}-detail`}
{chatId}
{messageId}
content={detailToken.text}
{done}
{save}
{preview}
{compactPreview}
{editCodeBlock}
@@ -38,6 +38,7 @@ export type OutputDetailToken = {
files?: string;
embeds?: string;
output?: string;
status?: string;
};
};
@@ -124,8 +125,9 @@ function getToolResultText(item?: OutputItem): string {
}
function buildToolCallToken(item: OutputItem, toolOutputByCallId: Record<string, OutputItem>) {
const callId = item.call_id ?? '';
const callId = item.call_id ?? item.id ?? '';
const resultItem = toolOutputByCallId[callId];
const status = String(item.status ?? '');
const isDone = isDoneStatus(item.status) || !!resultItem;
let name = item.name ?? '';
if (name === 'delegate_task') {
@@ -143,13 +145,14 @@ function buildToolCallToken(item: OutputItem, toolOutputByCallId: Record<string,
}
return {
summary: isDone ? 'Tool Executed' : 'Executing...',
summary: status === 'pending' ? 'Tool Approval Needed' : isDone ? 'Tool Executed' : 'Executing...',
text: getToolResultText(resultItem),
attributes: {
type: 'tool_calls',
id: callId,
name,
done: isDone ? 'true' : 'false',
status,
arguments: stringifyAttribute(item.arguments ?? ''),
files: stringifyAttribute(resultItem?.files),
embeds: stringifyAttribute(resultItem?.embeds)