diff --git a/frontend/src/lib/components/copilot/chat/RunScriptCard.svelte b/frontend/src/lib/components/copilot/chat/RunScriptCard.svelte index cb5ee7c324..f7a6181f9a 100644 --- a/frontend/src/lib/components/copilot/chat/RunScriptCard.svelte +++ b/frontend/src/lib/components/copilot/chat/RunScriptCard.svelte @@ -2,7 +2,8 @@ import { onMount } from 'svelte' import { cubicOut } from 'svelte/easing' import { prefersReducedMotion } from 'svelte/motion' - import { Ban, Loader2, TimerOff } from 'lucide-svelte' + import { Ban, Loader2, Maximize2, TimerOff } from 'lucide-svelte' + import Modal from '$lib/components/common/modal/Modal.svelte' import { twMerge } from 'tailwind-merge' import { Button, Tab, Tabs } from '$lib/components/common' import Toggle from '$lib/components/Toggle.svelte' @@ -339,22 +340,33 @@ // against it; logs and a result stand on the body's own ground and take it cleanly. const fadeBody = $derived(!rawView && (activeTab === 'logs' || activeTab === 'outcome')) + // The full screen copy of the body, rendered in the modal. + let modalBodyEl: HTMLElement | undefined = $state() + const modalFades = scrollFades() + // Keyed by call id for the same reason as the tab and the JSON toggle. + let fullscreenId = $state(undefined) + // One scroll region serves every tab, so a switch has to place it: logs open on their // end, which is where a run is read from, and everything else on its start — otherwise // the tab opened after the logs would begin part-way down its own content. - $effect(() => { + // One effect per copy: a shared one would re-place the card each time the modal mounts or + // unmounts, and the card would lose the place the user scrolled it to. + function placeScroll(el: HTMLElement | undefined) { void rawView - if (!bodyEl) return - bodyEl.scrollTop = activeTab === 'logs' && !rawView ? bodyEl.scrollHeight : 0 - }) + if (el) el.scrollTop = activeTab === 'logs' && !rawView ? el.scrollHeight : 0 + } + $effect(() => placeScroll(bodyEl)) + $effect(() => placeScroll(modalBodyEl)) // And stay on the end while the job writes: a log stream the user has to scroll to // read is not following the run. - $effect(() => { + function followLogs(el: HTMLElement | undefined) { void logs - if (!bodyEl || rawView || activeTab !== 'logs' || !running) return - bodyEl.scrollTop = bodyEl.scrollHeight - }) + if (!el || rawView || activeTab !== 'logs' || !running) return + el.scrollTop = el.scrollHeight + } + $effect(() => followLogs(bodyEl)) + $effect(() => followLogs(modalBodyEl)) // Ticks only while this card has a job in flight, so a transcript of settled runs // keeps no timers at all. @@ -555,232 +567,274 @@ {:else if pending && runForm} {:else} - + {#snippet runBody(inModal: boolean)} + {@const f = inModal ? modalFades : fades} + -
- +
+ - (userTab = { id: message.tool_call_id, value: e.detail })} - class="h-8 px-3 font-main" - wrapperClass="shrink-0" - slidingIndicator - > - {#if !rawView && !jobPending} - {#each tabs as tab (tab.value)} - - - - {#snippet extra()} - {#if tab.value === 'logs' && logLineCount > 0} - {logLineCount} - {/if} - {/snippet} - - - {/each} - {/if} -
- (jsonView = { id: message.tool_call_id, on: e.detail })} - size="2xs" - options={{ right: 'JSON', rightTooltip: 'Show this call as raw JSON' }} - lightMode - /> -
-
- - -
- -
- {#if rawView} -
- - - - + + {#snippet extra()} + {#if tab.value === 'logs' && logLineCount > 0} + {logLineCount} + {/if} + {/snippet} + + + {/each} + {/if} +
+ (jsonView = { id: message.tool_call_id, on: e.detail })} + size="2xs" + options={{ right: 'JSON', rightTooltip: 'Show this call as raw JSON' }} + lightMode + /> + {#if !inModal} +
- {:else if jobPending} - +
{ + if (inModal) modalBodyEl = el + else bodyEl = el + return () => { + if (inModal) modalBodyEl = undefined + else bodyEl = undefined + } + }} + use:f.container + onscroll={f.measure} + class={twMerge( + 'min-h-0 flex-1 px-3 py-2', + rawView && !inModal ? '' : 'overflow-auto', + !rawView && !jobPending && activeTab === 'logs' ? 'bg-surface-secondary/50' : '' + )} + > + +
+ {#if rawView} +
+ + + + +
+ {:else if jobPending} + -
- {#if fetchFailed === message.tool_call_id} - This run could not be read. It may have been deleted, or be in another workspace. - Its result is on the JSON toggle. - {:else} - - - Loading this run... - - {/if} -
- {:else} - - {#key activeTab} -
- {#if activeTab === 'input'} - - - {:else if activeTab === 'logs'} - {#if logs.trim()} - {#if logs.length >= MAX_LOG_LENGTH} -

- Tail of the logs, the last {MAX_LOG_LENGTH} characters. + + {:else if activeTab === 'logs'} + {#if logs.trim()} + {#if logs.length >= MAX_LOG_LENGTH} +

+ Tail of the logs, the last {MAX_LOG_LENGTH} characters. +

+ {/if} +
{logs}
+ {:else} +

+ {inspectedJob?.logsFailed + ? 'Logs could not be read.' + : running + ? 'No logs yet.' + : 'No logs.'}

{/if} -
{logs}
- {:else} -

- {inspectedJob?.logsFailed - ? 'Logs could not be read.' - : running - ? 'No logs yet.' - : 'No logs.'} -

- {/if} - {#if running && !waiting && !inspected} -
- - streaming -
- {/if} - - {:else if !inspected && failed} -
{message.error}
- {:else if streaming} - - - {:else if resultValue !== undefined} - - - {:else if canceled} - -
- -

{cancelReason}

- {#if !ran} -

- The inputs it would have run with are on the Inputs tab. -

- {/if} -
- {:else} -

This run returned no result.

- {/if} -
- {/key} - {/if} +
+ +

{cancelReason}

+ {#if !ran} +

+ The inputs it would have run with are on the Inputs tab. +

+ {/if} +
+ {:else} +

This run returned no result.

+ {/if} +
+ {/key} + {/if} +
-
- - {#if fades.bottom && fadeBody} -
- {#if activeTab === 'logs'} + {#if f.bottom && fadeBody}
+ {#if activeTab === 'logs'} +
+ {/if} {/if} - {/if} -
+
- {#if running && chatJob} - -
- +
+ +
+ {/if} + {/snippet} + + {@render runBody(false)} + + + fullscreenId === message.tool_call_id, + (v) => (fullscreenId = v ? message.tool_call_id : undefined) + } + title={`${verb} ${runnableName}`} + kind="X" + fillHeight + enterConfirms={false} + class="sm:max-w-none" + > +
+ {@render runBody(true)}
- {/if} +
{/if}