-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Open generated images from tool activity #4427
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
Open
colonelpanic8
wants to merge
4
commits into
pingdotgg:main
Choose a base branch
from
colonelpanic8:t3code/inline-image-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2140074
Open generated images from tool activity
colonelpanic8 e81d69a
fix(server): retry generated image projection lookup
colonelpanic8 cd0faf8
Retry generated images when reopened
colonelpanic8 2738a59
fix(web): migrate generated image panel state
colonelpanic8 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import { EventId, type OrchestrationThreadActivity } from "@t3tools/contracts"; | ||
| import { it as effectIt } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { | ||
| findGeneratedImagePath, | ||
| isGeneratedImageFileLookupRetryable, | ||
| retryGeneratedImageFileLookup, | ||
| } from "./GeneratedImageResolver.ts"; | ||
|
|
||
| const ACTIVITY_ID = EventId.make("activity-generated-image"); | ||
|
|
||
| function activity( | ||
| item: Record<string, unknown>, | ||
| overrides: Partial<OrchestrationThreadActivity> = {}, | ||
| ): OrchestrationThreadActivity { | ||
| return { | ||
| id: ACTIVITY_ID, | ||
| tone: "tool", | ||
| kind: "tool.completed", | ||
| summary: "Image view", | ||
| payload: { data: { item } }, | ||
| turnId: null, | ||
| createdAt: "2026-07-24T00:00:00.000Z", | ||
| ...overrides, | ||
| }; | ||
| } | ||
|
|
||
| describe("generated image resolution", () => { | ||
| it("reads the saved path from a completed image generation activity", () => { | ||
| const path = "/provider/session/generated.png"; | ||
| expect( | ||
| findGeneratedImagePath( | ||
| [ | ||
| activity({ | ||
| type: "imageGeneration", | ||
| status: "completed", | ||
| savedPath: path, | ||
| }), | ||
| ], | ||
| ACTIVITY_ID, | ||
| ), | ||
| ).toBe(path); | ||
| }); | ||
|
|
||
| it("rejects non-generation, incomplete, and mismatched activities", () => { | ||
| expect( | ||
| findGeneratedImagePath( | ||
| [activity({ type: "imageView", status: "completed", path: "/tmp/viewed.png" })], | ||
| ACTIVITY_ID, | ||
| ), | ||
| ).toBeNull(); | ||
| expect( | ||
| findGeneratedImagePath( | ||
| [ | ||
| activity({ | ||
| type: "imageGeneration", | ||
| status: "inProgress", | ||
| savedPath: "/tmp/generated.png", | ||
| }), | ||
| ], | ||
| ACTIVITY_ID, | ||
| ), | ||
| ).toBeNull(); | ||
| expect( | ||
| findGeneratedImagePath( | ||
| [ | ||
| activity( | ||
| { | ||
| type: "imageGeneration", | ||
| status: "completed", | ||
| savedPath: "/tmp/generated.png", | ||
| }, | ||
| { kind: "tool.updated" }, | ||
| ), | ||
| ], | ||
| ACTIVITY_ID, | ||
| ), | ||
| ).toBeNull(); | ||
| expect( | ||
| findGeneratedImagePath( | ||
| [ | ||
| activity({ | ||
| type: "imageGeneration", | ||
| status: "completed", | ||
| savedPath: "/tmp/generated.png", | ||
| }), | ||
| ], | ||
| EventId.make("activity-other"), | ||
| ), | ||
| ).toBeNull(); | ||
| }); | ||
|
|
||
| effectIt.live("retries the projection lookup until the generated image appears", () => | ||
| Effect.gen(function* () { | ||
| let attempts = 0; | ||
| const result = yield* retryGeneratedImageFileLookup( | ||
| Effect.suspend(() => { | ||
| attempts += 1; | ||
| const generatedImagePath = findGeneratedImagePath( | ||
| attempts < 3 | ||
| ? [] | ||
| : [ | ||
| activity({ | ||
| type: "imageGeneration", | ||
| status: "completed", | ||
| savedPath: "/tmp/generated.png", | ||
| }), | ||
| ], | ||
| ACTIVITY_ID, | ||
| ); | ||
| return generatedImagePath | ||
| ? Effect.succeed(generatedImagePath) | ||
| : Effect.fail({ _tag: "AssetGeneratedImageNotFoundError" as const }); | ||
| }), | ||
| ); | ||
|
|
||
| expect(result).toBe("/tmp/generated.png"); | ||
| expect(attempts).toBe(3); | ||
| expect( | ||
| isGeneratedImageFileLookupRetryable({ _tag: "AssetGeneratedImageNotFoundError" }), | ||
| ).toBe(true); | ||
| expect( | ||
| isGeneratedImageFileLookupRetryable({ _tag: "AssetGeneratedImageInspectionError" }), | ||
| ).toBe(false); | ||
| }), | ||
| ); | ||
| }); |
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,52 @@ | ||
| import type { EventId, OrchestrationThreadActivity } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Schedule from "effect/Schedule"; | ||
|
|
||
| const GENERATED_IMAGE_LOOKUP_RETRY_COUNT = 20; | ||
| const GENERATED_IMAGE_LOOKUP_RETRY_INTERVAL = "250 millis"; | ||
|
|
||
| function asRecord(value: unknown): Record<string, unknown> | null { | ||
| return value !== null && typeof value === "object" && !Array.isArray(value) | ||
| ? (value as Record<string, unknown>) | ||
| : null; | ||
| } | ||
|
|
||
| export function findGeneratedImagePath( | ||
| activities: ReadonlyArray<OrchestrationThreadActivity>, | ||
| activityId: EventId, | ||
| ): string | null { | ||
| const activity = activities.find((candidate) => candidate.id === activityId); | ||
| if (!activity || activity.kind !== "tool.completed") { | ||
| return null; | ||
| } | ||
|
|
||
| const payload = asRecord(activity.payload); | ||
| const data = asRecord(payload?.data); | ||
| const item = asRecord(data?.item); | ||
| if ( | ||
| item?.type !== "imageGeneration" || | ||
| item.status !== "completed" || | ||
| typeof item.savedPath !== "string" | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| const savedPath = item.savedPath.trim(); | ||
| return savedPath.length > 0 ? savedPath : null; | ||
| } | ||
|
|
||
| export function isGeneratedImageFileLookupRetryable(error: unknown): boolean { | ||
| return asRecord(error)?._tag === "AssetGeneratedImageNotFoundError"; | ||
| } | ||
|
|
||
| export function retryGeneratedImageFileLookup<A, E, R>( | ||
| lookup: Effect.Effect<A, E, R>, | ||
| ): Effect.Effect<A, E, R> { | ||
| return lookup.pipe( | ||
| Effect.retry({ | ||
| times: GENERATED_IMAGE_LOOKUP_RETRY_COUNT, | ||
| schedule: Schedule.spaced(GENERATED_IMAGE_LOOKUP_RETRY_INTERVAL), | ||
| while: isGeneratedImageFileLookupRetryable, | ||
| }), | ||
| ); | ||
| } | ||
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.