Skip to content

feat: design merch from the agent tab - #91

Closed
jsnapoli1 wants to merge 0 commit into
AJFrio:mainfrom
jsnapoli1:feat/agent-merch-designer
Closed

feat: design merch from the agent tab#91
jsnapoli1 wants to merge 0 commit into
AJFrio:mainfrom
jsnapoli1:feat/agent-merch-designer

Conversation

@jsnapoli1

Copy link
Copy Markdown

Stacked on #89 (image providers) and #90 (product id fix). #90 in particular is a hard dependency — without it create_product returns 201 and the product vanishes, so this feature would appear to work and produce nothing.

What it does

Selling a new item currently means generating an image elsewhere, uploading it, then describing the product again to create the listing. This makes it one conversation:

"List this as a hoodie for $45" — with a photo of the model, a blank hoodie, and the logo attached.

The agent generates the mockup, stores it, and creates the product with the image attached.

Four fields, not one prompt

The agent tab gains model / pose / product / logo, each able to carry a reference image.

A single free-text prompt tends to lose whichever element the model decides to skip, and passing several unlabelled images leaves it guessing which is the garment and which is the artwork. So:

  • Each field becomes its own clause, and a blank field emits nothing — "worn by an unspecified model" steers a picture as firmly as a real description would, just not where anyone asked.
  • References are ordered by role and captioned (Image 2 is the artwork or logo to place on the item). A model told the second image is the logo will use the wrong picture if the order drifts.
  • Pose is optional and text-only. Blank means "keep the pose from the reference image" — but only when there's a model reference to inherit one from.

Endpoint and tool

POST /api/admin/ai/generate-merch-image generates, stores to R2, adds to the media library, returns a URL.

Deliberately separate from /generate-image, which returns base64 for the media picker to preview. The agent needs a persisted URL; round-tripping base64 through the model's context would be slow and expensive.

The agent gets generate_product_image and is instructed to call it before create_product, passing the URL through. Reference images never enter the chat history — they're attached to the request and read by the tool when it runs, which keeps the context window intact.

A storage failure says so explicitly:

Image generated, but could not be saved: R2 bucket not configured.
Check the R2 bucket binding.

...rather than a generic 500, because retrying would repeat the expensive half for the same reason.

Also fixes the agent's "not configured" error, which still told users to run wrangler secret put even though Developer Settings (#87) exists.

Verification

Adds tests/integration/merch-designer.test.js (9 cases): each field appears as its own clause, blank pose inherits from the reference, no pose language without a model, blank fields omitted entirely, reference ordering matches the caption legend, the cap holds, malformed references are dropped, and storage failure is distinguished from generation failure.

Test Files  27 passed (27)
     Tests  309 passed (309)

npm run lint — 0 errors. Build clean; verified both halves reach their bundles (UI strings in the client, tool + prompt in the worker).

Not verified end-to-end. I have no image-generation API key, so no real image was produced. Prompt composition, reference ordering, tool wiring and error paths are covered by tests against mocked providers, but the actual generate → store → attach round trip needs a smoke test with real credentials.

Requires an R2 bucket. Storage uses the existing IMAGES binding; a worker without it gets the explicit 503 above rather than a crash.

https://claude.ai/code/session_015XLFFfHWNeazSuz6UcsQ4C

@AJFrio
AJFrio force-pushed the feat/agent-merch-designer branch from 363713f to 6b80873 Compare September 11, 2026 00:25
@AJFrio AJFrio closed this Sep 11, 2026
@AJFrio
AJFrio force-pushed the feat/agent-merch-designer branch from 6b80873 to 7956c15 Compare September 11, 2026 00:25
@AJFrio

AJFrio commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Merged into main via cceb03d (merge commit), after rebasing the branch onto the updated image-generation stack.

Note on status: the branch was rebased before merging (to pick up the OpenRouter-only refactor), so GitHub's auto-merge detection lost track of the original head and this PR shows as closed rather than merged. All of its content — the merch designer, generate_product_image agent tool, /api/admin/ai/generate-merch-image, and the product-id fix it depended on — is on main and covered by the 316 passing tests there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants