Repository navigation
🤖 feat: artifact versions, the artifact tool and pinned files #5427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c08e1af
🤖 feat: artifact versions, the artifact tool and pinned files
ThomasK33 2433d0b
fix(artifacts L6): always hash runtime files at turn end (Codex r4 QjUr)
ThomasK33 1a9c7cd
fix(artifacts L6): infer deleted artifacts only from a complete listi…
ThomasK33 16d931d
fix(artifacts L6): keep the exact pinned file name (Codex r4 QjVD)
ThomasK33 1d27a29
fix(artifacts L6): start a logical turn for a send admitted during th…
ThomasK33 7075157
fix(artifacts L6): abort the running turn-end snapshot when a send is…
ThomasK33 4ea72f5
fix(artifacts L6): keep the exact path passed to the artifact tool (C…
ThomasK33 d6c74d0
fix(artifacts L6): keep edge whitespace in palette file paths (Codex …
ThomasK33 27672f4
fix(artifacts L6): hash host artifacts at turn end even when size and…
ThomasK33 cdb1ee9
fix(artifacts L6): read dev container pins only with descriptor verif…
ThomasK33 60e0f37
style(artifacts L6): format r5 regression tests
ThomasK33 1fdb016
fix(artifacts L6): publish dev container artifacts only through race-…
ThomasK33 af95003
fix(artifacts L6): serialize version and pinned-file store writes acr…
ThomasK33 af5cbe9
fix(artifacts L6): skip unchanged host artifacts at turn end by size,…
ThomasK33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
src/browser/features/RightSidebar/ArtifactsTab/ArtifactVersionMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import React, { useEffect, useRef, useState } from "react"; | ||
| import { Check, ChevronDown } from "lucide-react"; | ||
| import { TooltipIfPresent } from "@/browser/components/Tooltip/Tooltip"; | ||
| import { stopKeyboardPropagation } from "@/browser/utils/events"; | ||
| import { formatRelativeTime } from "@/browser/utils/ui/dateTime"; | ||
| import { cn } from "@/common/lib/utils"; | ||
| import type { ArtifactVersion } from "@/common/orpc/schemas/artifacts"; | ||
|
|
||
| /** Label for a stored version: its publish title, or a plain name for turn-end snapshots. */ | ||
| function versionLabel(version: ArtifactVersion): string { | ||
| if (version.label != null && version.label.length > 0) return version.label; | ||
| return version.source === "turn-end" ? "Turn snapshot" : "Untitled"; | ||
| } | ||
|
|
||
| /** | ||
| * Toolbar version menu ("v<N>"): "Latest (live)" follows the working file, every other entry | ||
| * shows a stored version. Rendered inline (not through a Radix portal) so it opens in | ||
| * happy-dom tests and inside the panel's fullscreen overlay alike. | ||
| */ | ||
| export function ArtifactVersionMenu(props: { | ||
| /** Newest first; the caller hides the menu when there are none. */ | ||
| versions: readonly ArtifactVersion[]; | ||
| /** null = Latest (live). */ | ||
| selectedVersion: number | null; | ||
| onSelect: (version: number | null) => void; | ||
| }) { | ||
| const [open, setOpen] = useState(false); | ||
| const containerRef = useRef<HTMLDivElement | null>(null); | ||
| const triggerRef = useRef<HTMLButtonElement | null>(null); | ||
| const listRef = useRef<HTMLDivElement | null>(null); | ||
|
|
||
| // Close when clicking anywhere outside the trigger and its list. | ||
| useEffect(() => { | ||
| if (!open) return; | ||
| const handleMouseDown = (event: MouseEvent) => { | ||
| if (containerRef.current?.contains(event.target as Node)) return; | ||
| setOpen(false); | ||
| }; | ||
| document.addEventListener("mousedown", handleMouseDown); | ||
| return () => document.removeEventListener("mousedown", handleMouseDown); | ||
| }, [open]); | ||
|
|
||
| // Keyboard users land on the checked entry when the list opens. | ||
| useEffect(() => { | ||
| if (!open) return; | ||
| listRef.current?.querySelector<HTMLElement>('[aria-checked="true"]')?.focus(); | ||
| }, [open]); | ||
|
|
||
| const choose = (version: number | null) => { | ||
| setOpen(false); | ||
| triggerRef.current?.focus(); | ||
| props.onSelect(version); | ||
| }; | ||
|
|
||
| const handleListKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => { | ||
| if (event.key === "Escape") { | ||
| // Closing the menu must not also exit fullscreen or interrupt the stream. | ||
| event.preventDefault(); | ||
| stopKeyboardPropagation(event); | ||
| setOpen(false); | ||
| triggerRef.current?.focus(); | ||
| return; | ||
| } | ||
| if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return; | ||
| event.preventDefault(); | ||
| const items = Array.from( | ||
| listRef.current?.querySelectorAll<HTMLElement>('[role="menuitemradio"]') ?? [] | ||
| ); | ||
| const index = items.findIndex((item) => item === document.activeElement); | ||
| const next = event.key === "ArrowDown" ? index + 1 : index - 1; | ||
| items[Math.min(Math.max(next, 0), items.length - 1)]?.focus(); | ||
| }; | ||
|
|
||
| const triggerText = props.selectedVersion == null ? "Live" : `v${props.selectedVersion}`; | ||
| const itemClassName = | ||
| "hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-left text-xs outline-none"; | ||
|
|
||
| return ( | ||
| <div ref={containerRef} className="relative shrink-0"> | ||
| <TooltipIfPresent tooltip="Version"> | ||
| <button | ||
| ref={triggerRef} | ||
| type="button" | ||
| aria-label={`Version: ${props.selectedVersion == null ? "Latest (live)" : triggerText}`} | ||
| aria-haspopup="menu" | ||
| aria-expanded={open} | ||
| onClick={() => setOpen(!open)} | ||
| className="border-border-light text-muted hover:text-foreground bg-background flex h-6 items-center gap-0.5 rounded border pr-1 pl-1.5 text-[11px]" | ||
| > | ||
| <span className="counter-nums">{triggerText}</span> | ||
| <ChevronDown className="h-3 w-3" /> | ||
| </button> | ||
| </TooltipIfPresent> | ||
| {open && ( | ||
| <div | ||
| ref={listRef} | ||
| role="menu" | ||
| aria-label="Artifact versions" | ||
| onKeyDown={handleListKeyDown} | ||
| className="bg-dark border-border text-foreground absolute top-full right-0 z-[1600] mt-1 max-h-72 w-64 max-w-[calc(100vw-1rem)] overflow-y-auto rounded-md border p-1 shadow-md" | ||
| > | ||
| <button | ||
| type="button" | ||
| role="menuitemradio" | ||
| aria-checked={props.selectedVersion == null} | ||
| onClick={() => choose(null)} | ||
| className={itemClassName} | ||
| > | ||
| <MenuCheck checked={props.selectedVersion == null} /> | ||
| <span className="min-w-0 flex-1 truncate">Latest (live)</span> | ||
| </button> | ||
| {props.versions.map((version) => { | ||
| const checked = props.selectedVersion === version.version; | ||
| return ( | ||
| <button | ||
| key={version.version} | ||
| type="button" | ||
| role="menuitemradio" | ||
| aria-checked={checked} | ||
| onClick={() => choose(version.version)} | ||
| className={itemClassName} | ||
| > | ||
| <MenuCheck checked={checked} /> | ||
| <span className="counter-nums shrink-0 font-medium">v{version.version}</span> | ||
| <span className="min-w-0 flex-1 truncate">{versionLabel(version)}</span> | ||
| <span className="text-muted shrink-0 text-[10px]"> | ||
| {formatRelativeTime(version.createdAtMs)} | ||
| </span> | ||
| </button> | ||
| ); | ||
| })} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| function MenuCheck(props: { checked: boolean }) { | ||
| return ( | ||
| <span className="flex h-3.5 w-3.5 shrink-0 items-center justify-center"> | ||
| <Check className={cn("h-3 w-3", !props.checked && "invisible")} /> | ||
| </span> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.