import * as React from 'react'; import { Box, Text, setClipboard, useInput } from '@anthropic/ink'; import type { ArtifactInfo } from './scanner.js'; import { openBrowser } from 'src/utils/browser.js'; type Props = { artifacts: ArtifactInfo[]; onExit: () => void; }; export function ArtifactsMenu({ artifacts, onExit }: Props): React.ReactElement { const [selected, setSelected] = React.useState(0); useInput((input, key) => { if (input === 'q' || key.escape) { onExit(); return; } if (artifacts.length === 0) return; if (key.upArrow) { setSelected(s => (s - 1 + artifacts.length) % artifacts.length); return; } if (key.downArrow) { setSelected(s => (s + 1) % artifacts.length); return; } if (key.return) { const target = artifacts[selected]; if (target.url) { void openBrowser(target.url); } return; } if (input === 'c') { const target = artifacts[selected]; if (target.url) { void setClipboard(target.url).then(raw => { if (raw) process.stdout.write(raw); }); } } }); return ( Artifacts ({artifacts.length}) {artifacts.length === 0 ? ( No artifacts uploaded this session. Run /use-artifacts to learn how. ) : ( {artifacts.map((a, idx) => ( ))} {'↑/↓ select · Enter open · c copy URL · Esc exit'} )} ); } function ArtifactRow({ artifact, isSelected }: { artifact: ArtifactInfo; isSelected: boolean }): React.ReactElement { const marker = isSelected ? '›' : ' '; return ( {marker} {artifact.basename} {artifact.hash ? ({artifact.hash}) : null} {artifact.url ? ( {artifact.url} ) : ( {artifact.rawContent} )} {artifact.expiresAt ? ( expires: {artifact.expiresAt} ) : null} ); }