This commit is contained in:
Timothy Jaeryang Baek committed 2026-10-31 08:06:23 +09:00
1 parent f9d1d8cdaf
commit b6c46ab00a
5 files changed
+245 -34

No files matched your search

@@ -32,6 +32,49 @@
onapprove
}: Props = $props();
function isToolResultError(value: unknown): boolean {
if (typeof value === 'string') {
const text = value.trim().toLowerCase();
if (
text.startsWith('error:') ||
text.startsWith('exception:') ||
text.startsWith('traceback') ||
text.startsWith('http error!')
) {
return true;
}
}
let parsed = value;
while (typeof parsed === 'string') {
try {
parsed = JSON.parse(parsed);
} catch {
break;
}
}
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return false;
const result = parsed as Record<string, unknown>;
const error = result.error;
if (
(typeof error === 'string' && error.trim().length > 0) ||
(typeof error === 'object' && error !== null)
) {
return true;
}
const status = typeof result.status === 'string' ? result.status.trim().toLowerCase() : '';
if (status === 'error' || status === 'failed') return true;
const message = result.message;
return (
(result.success === false || result.ok === false) &&
((typeof message === 'string' && message.trim().length > 0) ||
(typeof message === 'object' && message !== null))
);
}
let expanded = $state($expandToolDetails);
$effect(() => {
expanded = $expandToolDetails;
@@ -41,14 +84,19 @@
reasoning.some((ri: any) => ri.status === 'in_progress' || ri.status === 'running')
);
const hasPending = $derived(
(!done && calls.some((c: any) => c.status !== 'completed' && c.status !== 'rejected')) ||
(!done && calls.some((c: any) => !['completed', 'failed', 'rejected'].includes(c.status))) ||
hasReasoningPending
);
const allDone = $derived(
(calls.length === 0 || calls.every((c: any) => c.status === 'completed')) &&
(calls.length === 0 || calls.every((c: any) => ['completed', 'failed'].includes(c.status))) &&
!hasReasoningPending
);
const hasRejected = $derived(calls.some((c: any) => c.status === 'rejected'));
const hasError = $derived(
calls.some(
(c: any) => c.status === 'failed' || isToolResultError(outputs.get(c.call_id)?.output ?? '')
)
);
const pendingCalls = $derived(calls.filter((c: any) => c.status === 'pending'));
const hasPendingApproval = $derived(pendingCalls.length > 0);
const isThoughtOnly = $derived(calls.length === 0);
@@ -132,6 +180,36 @@
/>
</svg>
</div>
{:else if hasRejected}
<div class="text-red-400 dark:text-red-500">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.5"
stroke="currentColor"
class="size-4"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
{:else if hasError}
<div class="text-red-500 dark:text-red-400">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v4m0 4h.01M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
</div>
{:else if allDone}
<div class="text-emerald-500 dark:text-emerald-400">
<svg
@@ -149,19 +227,6 @@
/>
</svg>
</div>
{:else if hasRejected}
<div class="text-red-400 dark:text-red-500">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2.5"
stroke="currentColor"
class="size-4"
>
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
{:else}
<div class="text-gray-400 dark:text-gray-500">
<svg
@@ -16,6 +16,49 @@
let { item, pairedOutput, done, chatId, messageId, toolLabel, onapprove }: Props = $props();
function isToolResultError(value: unknown): boolean {
if (typeof value === 'string') {
const text = value.trim().toLowerCase();
if (
text.startsWith('error:') ||
text.startsWith('exception:') ||
text.startsWith('traceback') ||
text.startsWith('http error!')
) {
return true;
}
}
let parsed = value;
while (typeof parsed === 'string') {
try {
parsed = JSON.parse(parsed);
} catch {
break;
}
}
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return false;
const result = parsed as Record<string, unknown>;
const error = result.error;
if (
(typeof error === 'string' && error.trim().length > 0) ||
(typeof error === 'object' && error !== null)
) {
return true;
}
const status = typeof result.status === 'string' ? result.status.trim().toLowerCase() : '';
if (status === 'error' || status === 'failed') return true;
const message = result.message;
return (
(result.success === false || result.ok === false) &&
((typeof message === 'string' && message.trim().length > 0) ||
(typeof message === 'object' && message !== null))
);
}
let expanded = $state($expandToolDetails || item.name === 'ask_user');
$effect(() => {
expanded = $expandToolDetails || item.name === 'ask_user';
@@ -27,7 +70,10 @@
const isExecuting = $derived(
item.status === 'running' || item.status === 'in_progress' || (!item.status && !done)
);
const isDone = $derived(item.status === 'completed');
const isError = $derived(
item.status === 'failed' || isToolResultError(pairedOutput?.output ?? '')
);
const isDone = $derived(item.status === 'completed' || isError);
const isRejected = $derived(item.status === 'rejected');
const isPending = $derived(item.status === 'pending');
const isAskUser = $derived(toolName === 'ask_user');
@@ -126,6 +172,23 @@
<path stroke-linecap="round" stroke-linejoin="round" d="M13 7h6M13 12h6M13 17h6" />
</svg>
</div>
{:else if isError}
<div class="text-red-500 dark:text-red-400">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="2"
stroke="currentColor"
class="size-4"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M12 9v4m0 4h.01M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
/>
</svg>
</div>
{:else if isDone}
<div class="text-emerald-500 dark:text-emerald-400">
<svg