|
1 | | -import { usePageVisibility } from "@solid-primitives/page-visibility" |
2 | 1 | import { Component, createEffect, createMemo, createSignal, For, Match, on, Show, Switch, type JSX } from "solid-js" |
3 | 2 | import stripAnsi from "strip-ansi" |
4 | 3 | import { createStore } from "solid-js/store" |
@@ -39,7 +38,7 @@ import { TextShimmer } from "./text-shimmer" |
39 | 38 | import { list } from "./text-utils" |
40 | 39 | import { GrowBox } from "./grow-box" |
41 | 40 | import { COLLAPSIBLE_SPRING } from "./motion" |
42 | | -import { busy, hold, createThrottledValue, useToolFade, useContextToolPending } from "./tool-utils" |
| 41 | +import { busy, createThrottledValue, useToolFade, useContextToolPending } from "./tool-utils" |
43 | 42 | import { ContextToolGroupHeader, ContextToolExpandedList, ContextToolRollingResults } from "./context-tool-results" |
44 | 43 | import { ShellRollingResults } from "./shell-rolling-results" |
45 | 44 |
|
@@ -273,19 +272,6 @@ function createGroupOpenState() { |
273 | 272 | return { read, controlled, write } |
274 | 273 | } |
275 | 274 |
|
276 | | -function shouldCollapseGroup( |
277 | | - statuses: (string | undefined)[], |
278 | | - opts: { afterTool?: boolean; groupTail?: boolean; working?: boolean }, |
279 | | - pageVisible: () => boolean, |
280 | | -) { |
281 | | - if (opts.afterTool) return true |
282 | | - if (opts.groupTail === false) return true |
283 | | - if (!pageVisible()) return false |
284 | | - if (opts.working) return false |
285 | | - if (!statuses.length) return false |
286 | | - return !statuses.some((s) => busy(s)) |
287 | | -} |
288 | | - |
289 | 275 | function renderable(part: PartType, showReasoningSummaries = true) { |
290 | 276 | if (part.type === "tool") { |
291 | 277 | if (HIDDEN_TOOLS.has(part.tool)) return false |
@@ -363,7 +349,6 @@ export function AssistantParts(props: { |
363 | 349 | }) { |
364 | 350 | const data = useData() |
365 | 351 | const emptyParts: PartType[] = [] |
366 | | - const pageVisible = usePageVisibility() |
367 | 352 | const groupState = createGroupOpenState() |
368 | 353 | const grouped = createMemo(() => { |
369 | 354 | const keys: string[] = [] |
@@ -481,24 +466,9 @@ export function AssistantParts(props: { |
481 | 466 | return COLLAPSIBLE_SPRING |
482 | 467 | }) |
483 | 468 | const contextOpen = createMemo(() => { |
484 | | - const collapse = ( |
485 | | - afterTool?: boolean, |
486 | | - groupTail?: boolean, |
487 | | - group?: { part: ToolPart; message: AssistantMessage }[], |
488 | | - ) => |
489 | | - shouldCollapseGroup( |
490 | | - group?.map((item) => item.part.state.status) ?? [], |
491 | | - { |
492 | | - afterTool, |
493 | | - groupTail, |
494 | | - working: props.working, |
495 | | - }, |
496 | | - pageVisible, |
497 | | - ) |
498 | 469 | const value = ctx() |
499 | | - if (value) return groupState.read(value.groupKey, collapse(value.afterTool, value.tail, value.parts)) |
500 | | - const entry = part() |
501 | | - return groupState.read(entry?.groupKey, collapse(entry?.afterTool, entry?.groupTail, entry?.groupParts)) |
| 470 | + if (value) return groupState.read(value.groupKey, true) |
| 471 | + return groupState.read(part()?.groupKey, true) |
502 | 472 | }) |
503 | 473 | const visible = createMemo(() => { |
504 | 474 | if (!context()) return true |
@@ -544,9 +514,7 @@ export function AssistantParts(props: { |
544 | 514 | ctxPartsPrev = result |
545 | 515 | return result |
546 | 516 | }) |
547 | | - const ctxPendingRaw = useContextToolPending(ctxParts, () => !!(props.working && ctx()?.tail)) |
548 | | - const ctxPending = ctxPendingRaw |
549 | | - const ctxHoldOpen = hold(ctxPendingRaw) |
| 517 | + const ctxPending = useContextToolPending(ctxParts, () => !!(props.working && ctx()?.tail)) |
550 | 518 | const shell = createMemo(() => { |
551 | 519 | const value = part() |
552 | 520 | if (!value) return |
@@ -598,12 +566,20 @@ export function AssistantParts(props: { |
598 | 566 | onOpenChange={(value: boolean) => groupState.write(entry().groupKey, value)} |
599 | 567 | /> |
600 | 568 | </PartGrow> |
601 | | - <ContextToolExpandedList parts={ctxParts()} expanded={!ctxPending() && contextOpen()} /> |
602 | | - <ContextToolRollingResults parts={ctxParts()} pending={ctxHoldOpen()} /> |
| 569 | + <ContextToolExpandedList parts={ctxParts()} expanded={contextOpen() && !ctxPending()} /> |
| 570 | + <ContextToolRollingResults parts={ctxParts()} pending={contextOpen() && ctxPending()} /> |
603 | 571 | </> |
604 | 572 | )} |
605 | 573 | </Show> |
606 | | - <Show when={shell()}>{(value) => <ShellRollingResults part={value()} animate={props.animate} />}</Show> |
| 574 | + <Show when={shell()}> |
| 575 | + {(value) => ( |
| 576 | + <ShellRollingResults |
| 577 | + part={value()} |
| 578 | + animate={props.animate} |
| 579 | + defaultOpen={props.shellToolDefaultOpen} |
| 580 | + /> |
| 581 | + )} |
| 582 | + </Show> |
607 | 583 | <Show when={!shell() ? part() : undefined}> |
608 | 584 | {(entry) => ( |
609 | 585 | <Show when={!entry().context}> |
|
0 commit comments