fix(chat): show Codex generated images in the thread #6441
Closedsambhavthakkar(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/6441/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- apps/server/src/assets/AssetAccess.ts lines 258 to 266Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -209,3 +264,3 @@209264 }),210265 ),211266 );
- apps/server/src/assets/AssetAccess.ts lines 258 to 266Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -209,3 +264,3 @@209264 }),210265 ),211266 );
- @@ -127,3 +133,10 @@127133128134 const nowIso = Effect.map(DateTime.now, DateTime.formatIso);129135 const EDITOR_DISCOVERY_TIMEOUT = Duration.seconds(5);136+const decodeCodexSettings = Schema.decodeUnknownOption(CodexSettings);137+138+const resolveCodexGeneratedImagesRoots = Effect.fn("resolveCodexGeneratedImagesRoots")(139+ function* (settings: ServerSettingsValue) {140+ const path = yield* Path.Path;141+ const roots: string[] = [];142+ const instances = Object.values(settings.providerInstances)@@ -795,4 +801,5 @@795801 payload: {796802 itemType: event.payload.itemType,797803 ...(event.payload.status ? { status: event.payload.status } : {}),798- ...(event.payload.detail ? { detail: truncateDetail(event.payload.detail) } : {}),804+ ...(event.payload.detail805+ ? { detail: toolLifecycleDetail(event.payload.itemType, event.payload.detail) }@@ -264,9 +264,20 @@264264 case "image_view":265- return "Image view";265+ return item?.type === "imageGeneration" ? "Generated image" : "Image view";266266 case "error":267267 return "Error";268268 default:269269 return undefined;270270 }271271 }272272273+const IMAGE_GENERATION_RESULT_PATH_MAX_CHARS = 1024;274+275+function imageGenerationResultPath(result: string | undefined): string | undefined {276+ const trimmed = trimText(result);277+ if (!trimmed || trimmed.length > IMAGE_GENERATION_RESULT_PATH_MAX_CHARS) {278+ return undefined;279+ }280+ if (trimmed.includes("\n") || /\s/.test(trimmed)) {281+ return undefined;282+ }283+ if (trimmed.includes("/") || trimmed.includes("\\")) {
- @@ -273 +275,21 @@275+function imageGenerationResultPath(result: string | undefined): string | undefined {276+ const trimmed = trimText(result);277+ if (!trimmed || trimmed.length > IMAGE_GENERATION_RESULT_PATH_MAX_CHARS) {278+ return undefined;279+ }280+ if (trimmed.includes("\n") || /\s/.test(trimmed)) {281+ return undefined;282+ }283+ if (trimmed.includes("/") || trimmed.includes("\\")) {284+ return trimmed;285+ }286+ return undefined;287+}288+273289 function itemDetail(itemType: CanonicalItemType, item: CodexLifecycleItem): string | undefined {290+ if (item.type === "imageGeneration") {291+ return (292+ trimText(item.savedPath ?? undefined) ??293+ imageGenerationResultPath(item.result) ??294+ trimText(item.revisedPrompt ?? undefined)295+ );@@ -1542,3 +1545,20 @@15421545 />15431546 );15441547 },1548+ img({ src, alt }) {1549+ const fileLinkMeta = src ? resolveMarkdownFileLinkMeta(src, cwd) : null;1550+ if (1551+ fileLinkMeta &&1552+ isWorkspaceImagePreviewPath(fileLinkMeta.filePath) &&1553+ threadRef1554+ ) {1555+ return (1556+ <ChatWorkspaceImage1557+ environmentId={threadRef.environmentId}1558+ threadRef={threadRef}1559+ path={fileLinkMeta.filePath}1560+ alt={alt ?? fileLinkMeta.basename}1561+ />1562+ );1563+ }1564+ if (src && /^https?:\/\//i.test(src)) {@@ -1821,3 +1965,5 @@18211965 (info: { item: ThreadFeedEntry; index: number }) =>18221966 renderFeedEntry(info, {18231967 environmentId: props.environmentId,1968+ threadId: props.threadId,1969+ workspaceRoot: props.workspaceRoot,@@ -0,0 +22,21 @@22+ Unable to load image{props.alt ? ` “${props.alt}”` : ""}.23+ </div>24+ );25+ }26+27+ return (28+ <>29+ <button30+ type="button"31+ className={cn(32+ "my-2 block max-w-full cursor-zoom-in overflow-hidden rounded-lg border border-border/80 bg-background/70",33+ props.className,34+ )}35+ aria-label={`Preview ${name}`}36+ onClick={() => setExpanded(true)}37+ >38+ <img39+ src={props.src}40+ alt={name}41+ className="block h-auto max-h-[360px] max-w-full object-contain"42+ onError={() => setFailed(true)}@@ -2367,3 +2394,5 @@23672394 </div>23682395 </div>23692396 </div>2397+ {imagePath && threadRef ? (2398+ <div className="ms-7 mt-1" onClick={stopRowToggle} onPointerDown={stopRowToggle}>
- @@ -1443,3 +1446,13 @@14431446 };14441447 }144514481449+function extractImageViewPath(payload: Record<string, unknown> | null): string | null {1450+ const data = asRecord(payload?.data);1451+ const item = asRecord(data?.item);1452+ for (const candidate of [item?.savedPath, item?.path, payload?.detail]) {1453+ if (typeof candidate === "string" && candidate.trim().length > 0) {1454+ return candidate.trim();1455+ }1456+ }1457+ return null;1458+}
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
140d9003-d0d1-4b7e-a057-eccf5aa815a3You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share