GeezerVison is showing github.com — Merge remote-tracking branch 'origin/main' into fix/issue-28207 · pingdotgg/t3code@885cc3c
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/chat
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +66-20Lines changed: 66 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -import { memo, Suspense, use, type ReactNode } from "react"; | | 1 | +import { memo, useLayoutEffect, useState, type ReactNode } from "react"; | | 2 | + | | 3 | +import { cn } from "~/lib/utils"; | 2 | 4 |
| 3 | 5 | import { | 4 | 6 | createComposerImageThumbnail, | | 7 | + isHeicImageFile, | | 8 | + MAX_COMPRESSIBLE_SOURCE_BYTES, | 5 | 9 | readComposerImageThumbnail, | 6 | 10 | } from "../../lib/imageCompression"; | 7 | 11 |
| 8 | | -export const ComposerImageThumbnail = memo(function ComposerImageThumbnail(props: { | 9 | | - file: File; | 10 | | - alt: string; | 11 | | - className: string; | 12 | | - fallback: ReactNode; | 13 | | -}) { | 14 | | - return ( | 15 | | - <Suspense fallback={props.fallback}> | 16 | | - <ThumbnailImage {...props} /> | 17 | | - </Suspense> | 18 | | - ); | 19 | | -}); | 20 | | - | 21 | | -function ThumbnailImage({ | | 12 | +export const ComposerImageThumbnail = memo(function ComposerImageThumbnail({ | 22 | 13 | file, | 23 | 14 | alt, | 24 | 15 | className, | @@ -29,8 +20,63 @@ function ThumbnailImage({ | 29 | 20 | className: string; | 30 | 21 | fallback: ReactNode; | 31 | 22 | }) { | 32 | | - // A settled thumbnail paints synchronously instead of suspending for a tick. | 33 | | - const settled = readComposerImageThumbnail(file); | 34 | | - const src = settled === undefined ? use(createComposerImageThumbnail(file)) : settled; | 35 | | - return src ? <img src={src} alt={alt} className={className} /> : fallback; | 36 | | -} | | 23 | + const [preview, setPreview] = useState(() => ({ | | 24 | + file, | | 25 | + src: readComposerImageThumbnail(file), | | 26 | + })); | | 27 | + const [loadedSrc, setLoadedSrc] = useState<string | null>(null); | | 28 | + const [failedSrc, setFailedSrc] = useState<string | null>(null); | | 29 | + const src = preview.file === file ? preview.src : readComposerImageThumbnail(file); | | 30 | + | | 31 | + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- owns the local blob URL and decodes its replacement before swapping the visible image | | 32 | + useLayoutEffect(() => { | | 33 | + let disposed = false; | | 34 | + let localUrl: string | undefined; | | 35 | + const cached = readComposerImageThumbnail(file); | | 36 | + if ( | | 37 | + file.size <= MAX_COMPRESSIBLE_SOURCE_BYTES && | | 38 | + !isHeicImageFile(file) && | | 39 | + cached === undefined | | 40 | + ) { | | 41 | + localUrl = URL.createObjectURL(file); | | 42 | + // oxlint-disable-next-line react/set-state-in-effect -- the blob URL is created and revoked by this effect | | 43 | + setPreview({ file, src: localUrl }); | | 44 | + } | | 45 | + if (cached === undefined) { | | 46 | + void createComposerImageThumbnail(file).then(async (thumbnail) => { | | 47 | + if (disposed) return; | | 48 | + if (!thumbnail) { | | 49 | + if (!localUrl) setPreview({ file, src: null }); | | 50 | + return; | | 51 | + } | | 52 | + const image = new Image(); | | 53 | + image.src = thumbnail; | | 54 | + try { | | 55 | + await image.decode(); | | 56 | + if (!disposed) setPreview({ file, src: thumbnail }); | | 57 | + } catch { | | 58 | + // Keep the local preview if the thumbnail cannot be decoded. | | 59 | + } | | 60 | + }); | | 61 | + } | | 62 | + return () => { | | 63 | + disposed = true; | | 64 | + if (localUrl) URL.revokeObjectURL(localUrl); | | 65 | + }; | | 66 | + }, [file]); | | 67 | + | | 68 | + return src && failedSrc !== src ? ( | | 69 | + <img | | 70 | + ref={(image) => { | | 71 | + if (image?.complete && image.naturalWidth > 0) setLoadedSrc(src); | | 72 | + }} | | 73 | + src={src} | | 74 | + alt={alt} | | 75 | + onLoad={() => setLoadedSrc(src)} | | 76 | + onError={() => setFailedSrc(src)} | | 77 | + className={cn(className, loadedSrc !== src && "invisible")} | | 78 | + /> | | 79 | + ) : src === undefined ? null : ( | | 80 | + fallback | | 81 | + ); | | 82 | +}); |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/entities.test.ts +3-13Lines changed: 3 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,7 +22,7 @@ import { canSnooze, effectiveSnoozed } from "./threadSettled.ts"; | 22 | 22 | const environmentId = EnvironmentId.make("environment-v2"); | 23 | 23 |
| 24 | 24 | describe("V2 client presentation", () => { | 25 | | - it("keeps async questions in Working until the run completes", () => { | | 25 | + it("an async question blocks snooze and wakes a snoozed thread", () => { | 26 | 26 | const runId = RunId.make("run-async-question"); | 27 | 27 | const running = { | 28 | 28 | ...v2ThreadShell, | @@ -39,22 +39,12 @@ describe("V2 client presentation", () => { | 39 | 39 | }, | 40 | 40 | }; | 41 | 41 | const active = presentThreadShell(environmentId, running); | 42 | | - expect(active.hasPendingUserInput).toBe(false); | 43 | | - expect(isThreadWorking(active)).toBe(true); | 44 | 42 | expect(canSnooze(active, { now: "2026-06-20T00:05:00.000Z" })).toBe(false); | 45 | | - | 46 | | - const completed = presentThreadShell(environmentId, { | 47 | | - ...running, | 48 | | - activeRunId: null, | 49 | | - status: "completed", | 50 | | - }); | 51 | | - expect(completed.hasPendingUserInput).toBe(true); | 52 | | - expect(isThreadWorking(completed)).toBe(false); | 53 | 43 | expect(effectiveSnoozed(active, { now: "2026-06-20T00:05:00.000Z" })).toBe(false); | 54 | 44 | }); | 55 | 45 |
| 56 | | - it("keeps blocking and legacy questions out of Working", () => { | 57 | | - for (const capability of [{ blocking: true }, {}]) { | | 46 | + it("moves a running thread with any question out of Working", () => { | | 47 | + for (const capability of [{ blocking: false }, { blocking: true }, {}]) { | 58 | 48 | const shell = presentThreadShell(environmentId, { | 59 | 49 | ...v2ThreadShell, | 60 | 50 | latestRunId: RunId.make("run-blocking-question"), | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/models.ts +2-12Lines changed: 2 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -216,17 +216,6 @@ function terminalRunStatus(status: OrchestrationV2RunStatus): boolean { | 216 | 216 | ); | 217 | 217 | } | 218 | 218 |
| 219 | | -/** An async question waits for an answer only once its run stops working. */ | 220 | | -export function shellHasPendingUserInput(thread: OrchestrationV2ThreadShell): boolean { | 221 | | - const status = shellRuntime(thread)?.status; | 222 | | - // Waiting runs have ended their provider turn and are only draining effects. | 223 | | - const working = status === "preparing" || status === "starting" || status === "running"; | 224 | | - return ( | 225 | | - thread.pendingRuntimeRequest?.kind === "user_input" && | 226 | | - (thread.pendingRuntimeRequest.blocking !== false || !working) | 227 | | - ); | 228 | | -} | 229 | | - | 230 | 219 | // Only work the agent waits on holds it: commands and monitors it left running | 231 | 220 | // unmarked, such as a dev server, present the run's own status. The | 232 | 221 | // server suppresses the roster while an interruptible activity run exists, so a | @@ -321,7 +310,8 @@ export function presentThreadShell( | 321 | 310 | thread.pendingRuntimeRequest !== null && | 322 | 311 | thread.pendingRuntimeRequest.kind !== "user_input" && | 323 | 312 | thread.pendingRuntimeRequest.kind !== "auth_refresh", | 324 | | - hasPendingUserInput: shellHasPendingUserInput(thread), | | 313 | + // Async questions count too, so a thread with any open question leaves Working. | | 314 | + hasPendingUserInput: thread.pendingRuntimeRequest?.kind === "user_input", | 325 | 315 | pendingSubagentRequest, | 326 | 316 | pendingGuestMessageCount: thread.pendingGuestMessageCount ?? 0, | 327 | 317 | hasActionableProposedPlan: thread.hasActionableProposedPlan, | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadSettled.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,7 +125,7 @@ export function canSnooze( | 125 | 125 | options: { readonly now: string }, | 126 | 126 | ): boolean { | 127 | 127 | if (shell.hasPendingApprovals || shell.hasPendingUserInput) return false; | 128 | | - // The server rejects snoozing even for nonblocking questions. | | 128 | + // The server rejects snoozing for any pending request. | 129 | 129 | if (shell.source?.pendingRuntimeRequest != null) return false; | 130 | 130 | if (shell.pendingSubagentRequest != null) return false; | 131 | 131 | // A waiting guest message would wake it at once. | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadShell.test.ts +1-6Lines changed: 1 addition & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -181,15 +181,14 @@ describe("v2 thread shell lists", () => { | 181 | 181 | const disposeNavigation = registry.mount(threads.navigationThreadShellsAtom); | 182 | 182 | const withRequest = ( | 183 | 183 | kind: "user_input" | "command", | 184 | | - options: { readonly blocking?: boolean; readonly settled?: boolean } = {}, | | 184 | + options: { readonly blocking?: boolean } = {}, | 185 | 185 | ) => | 186 | 186 | registry.set(snapshotAtom(environmentId), { | 187 | 187 | ...v2ShellSnapshot, | 188 | 188 | threads: [ | 189 | 189 | root, | 190 | 190 | { | 191 | 191 | ...sideChat, | 192 | | - ...(options.settled ? { status: "completed" as const, activityRunStatus: null } : {}), | 193 | 192 | pendingRuntimeRequest: { | 194 | 193 | ...request, | 195 | 194 | kind, | @@ -206,11 +205,7 @@ describe("v2 thread shell lists", () => { | 206 | 205 | root.id, | 207 | 206 | ]); | 208 | 207 |
| 209 | | - // An async question waits while the side chat works, like its own row's indicator. | 210 | 208 | withRequest("user_input", { blocking: false }); | 211 | | - expect(registry.get(parent)?.pendingSubagentRequest).toBeNull(); | 212 | | - expect(registry.get(inputs)).toEqual([]); | 213 | | - withRequest("user_input", { blocking: false, settled: true }); | 214 | 209 | expect(registry.get(parent)?.pendingSubagentRequest).toBe("user_input"); | 215 | 210 |
| 216 | 211 | withRequest("command"); | |
Collapse file Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/threadShell.ts +3-7Lines changed: 3 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,7 +15,7 @@ import * as Schema from "effect/Schema"; | 15 | 15 | import { Atom } from "effect/reactivity"; | 16 | 16 |
| 17 | 17 | import type { EnvironmentThreadShell, PendingSubagentRequest } from "./models.ts"; | 18 | | -import { presentThreadShell, shellHasPendingUserInput, threadRuntimeIsActive } from "./models.ts"; | | 18 | +import { presentThreadShell, threadRuntimeIsActive } from "./models.ts"; | 19 | 19 | import { type EnvironmentCatalogState, enabledEnvironmentIds } from "./connections.ts"; | 20 | 20 | import { | 21 | 21 | arrayElementsEqual, | @@ -84,17 +84,13 @@ function subagentRequest(thread: OrchestrationV2ThreadShell): PendingSubagentReq | 84 | 84 | return kind === "user_input" ? "user_input" : "approval"; | 85 | 85 | } | 86 | 86 |
| 87 | | -/** | 88 | | - * A side chat asks its user directly, so questions roll up to the parent as well as approvals, | 89 | | - * when its own row would show them. | 90 | | - */ | | 87 | +/** A side chat asks its user directly, so questions roll up to the parent as well as approvals. */ | 91 | 88 | function sideChatRequest(thread: OrchestrationV2ThreadShell): PendingSubagentRequest | null { | 92 | 89 | const kind = thread.pendingRuntimeRequest?.kind; | 93 | 90 | if (kind === undefined || kind === "auth_refresh" || thread.lineage.sideChat !== true) { | 94 | 91 | return null; | 95 | 92 | } | 96 | | - if (kind !== "user_input") return "approval"; | 97 | | - return shellHasPendingUserInput(thread) ? "user_input" : null; | | 93 | + return kind === "user_input" ? "user_input" : "approval"; | 98 | 94 | } | 99 | 95 |
| 100 | 96 | /** | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/agentAwareness.test.ts +3-6Lines changed: 3 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -183,7 +183,7 @@ describe("projectThreadAwarenessV2", () => { | 183 | 183 | ).toMatchObject({ phase }); | 184 | 184 | }); | 185 | 185 |
| 186 | | - it("reports an async question as input only after the working run completes", () => { | | 186 | + it("reports an async question as input while the run keeps working", () => { | 187 | 187 | const input = { | 188 | 188 | environmentId: "env-1" as EnvironmentId, | 189 | 189 | project, | @@ -197,12 +197,9 @@ describe("projectThreadAwarenessV2", () => { | 197 | 197 | }), | 198 | 198 | }; | 199 | 199 | expect(projectThreadAwarenessV2(input)).toMatchObject({ | 200 | | - phase: "running", | 201 | | - headline: "Agent is working", | | 200 | + phase: "waiting_for_input", | | 201 | + headline: "Waiting for input", | 202 | 202 | }); | 203 | | - expect( | 204 | | - projectThreadAwarenessV2({ ...input, thread: { ...input.thread, status: "completed" } }), | 205 | | - ).toMatchObject({ phase: "waiting_for_input", headline: "Waiting for input" }); | 206 | 203 | }); | 207 | 204 |
| 208 | 205 | it("does not present authentication refreshes as user approvals", () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/shared/src/agentAwareness.ts +2-10Lines changed: 2 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -98,22 +98,14 @@ export function projectThreadAwarenessV2( | 98 | 98 | function resolveThreadAwarenessPhaseV2( | 99 | 99 | thread: ProjectThreadAwarenessV2Input["thread"], | 100 | 100 | ): AgentAwarenessPhase | null { | 101 | | - const runStatus = thread.activityRunStatus ?? thread.status; | 102 | | - if ( | 103 | | - thread.pendingRuntimeRequest?.kind === "user_input" && | 104 | | - (thread.pendingRuntimeRequest.blocking !== false || | 105 | | - !(runStatus === "preparing" || runStatus === "starting" || runStatus === "running")) | 106 | | - ) { | 107 | | - return "waiting_for_input"; | 108 | | - } | | 101 | + if (thread.pendingRuntimeRequest?.kind === "user_input") return "waiting_for_input"; | 109 | 102 | if ( | 110 | 103 | thread.pendingRuntimeRequest !== null && | 111 | | - thread.pendingRuntimeRequest.kind !== "user_input" && | 112 | 104 | thread.pendingRuntimeRequest.kind !== "auth_refresh" | 113 | 105 | ) { | 114 | 106 | return "waiting_for_approval"; | 115 | 107 | } | 116 | | - switch (runStatus) { | | 108 | + switch (thread.activityRunStatus ?? thread.status) { | 117 | 109 | case "preparing": | 118 | 110 | case "starting": | 119 | 111 | return "starting"; | |
|