Skip to content

[feat] canvas: optimize image and video prompts with model media input - #465

Merged
allendyu merged 5 commits into
ThinkFlowLab:mainfrom
Probiotics5333:main
Nov 25, 2026
Merged

allendyu merged 5 commits into
ThinkFlowLab:mainfrom
Probiotics5333:main

Conversation

@Probiotics5333

@Probiotics5333 Probiotics5333 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add prompt optimization for image and video drafts, and extend text models with the media inputs it needs to read a node's references.

  • A new application service rewrites the draft with the node's saved references and the chat model selected in the Agent panel, including the CLI default for Codex and Claude Code. It returns text only: no job, no asset, no canvas edit.
  • Chat models now declare text / image / video / audio input. The optimizer sends a full video to models with video input, samples frames for image-only models, and sends audio only when the model accepts it, reporting omitted audio in the result.
  • Video profiles map to built-in skills: H3 (official / vLLM-Omni / MiniMax) and Seedance 2.0. CLI runtimes rewrite through a shared prompt_rewrite bridge.
  • The same rewrite is available through POST /api/creation/projects/{project}/items/{item}/optimize-prompt, opendirector canvas optimize-prompt and the prompt_optimize Agent tool.
  • The composer adds a wand button and aborts on node switch or panel close. Progress appears as a slowly pulsing status line with a thin rotating band on the card border; success, warnings and failures arrive as canvas toasts. Ctrl+Z restores the previous draft after the replacement.
  • Both user guides describe the workflow.

Scope not covered here: text nodes do not offer the button yet, and the result replaces the draft with undo rather than a side-by-side compare/adopt layer. The issue lists both as open design points, so the linked issue is referenced, not closed.

Linked issue

  • Refs #N included

Refs #154

Labels

  • Labels applied: type:feat, area:canvas, area:agent

Test plan

  • Local:
    • pytest tests/test_prompt_optimization.py — 2 passed, 1 skipped.
    • npx tsc --noEmit in the rebased PR worktree — clean.
    • python scripts/generate_contracts.py --check — verified.
    • node scripts/check-i18n.mjs — 0 problems.
  • Left to CI: the static, Python, frontend and browser lanes in checks.

Evidence that it works

  • Media attached, or N/A because: the change adds a button, a status line and toasts to the existing composer; no new screen was added. The rewrite path, reference markers, skill mapping and media selection rules are asserted by Python tests against a mock transport.

Provider verification

  • Real-provider calls are described honestly, or none were made

No real chat or media model was called. The tests exercise the request shape, reference markers, video frame sampling and audio gating with a mock transport; rewrite quality on a real chat model and the new skills' effect remain unverified.

Bilingual UI

  • Both locales are updated

generation.optimize.*, the new error codes and both user guides ship in zh-CN and en-US.

@github-actions github-actions Bot added area:canvas Canvas, nodes and direct manipulation type:feat New capability or behaviour labels Nov 23, 2026
@Probiotics5333 Probiotics5333 added the area:agent Agent runtime, assistant chat and tools label Nov 23, 2026
- Add a prompt-optimization service that rewrites an image or video draft
  with its saved references and a configured text model. It returns text
  only: no job, no asset and no canvas edit.
- Extend chat model input types to video and audio. The optimizer sends a
  full video to models with video input, samples frames for image-only
  models, and sends audio only when the model accepts it, reporting omitted
  audio in the result.
- Expose the same rewrite through the canvas API, `canvas optimize-prompt`
  in the CLI and the `prompt_optimize` Agent tool, so both entry points share
  the service and the same validation.
- Add the composer wand, progress and failure notes, abort on node switch or
  panel close, and Ctrl+Z undo after the draft is replaced.
- Apply the built-in `h3-prompt-optimization` skill for H3 video models and
  document the workflow in both user guides.
- Text nodes and a side-by-side compare/adopt layer are not part of this
  change; the composer replaces the draft and undo restores the original.

- `pytest tests/test_prompt_optimization.py tests/test_model_configs.py`:
  36 passed.
- `tsc --noEmit` on the staged tree: clean.
- `python scripts/generate_contracts.py --check`: verified.
- `npm run check:i18n`: 0 problems.

Refs: ThinkFlowLab#154
@github-actions github-actions Bot added area:docs Documentation / 文档 area:provider Model providers and generation protocols labels Nov 24, 2026
@Probiotics5333
Probiotics5333 force-pushed the main branch 2 times, most recently from a85f52c to a3471d6 Compare November 24, 2026 17:39
## summary

- Follow the Agent panel's runtime, model and thinking level when optimizing a
  prompt, including the CLI default for Codex and Claude Code. The canvas sends
  the current selection with the request; the Agent tool passes the same
  selection, so both entry points share one model choice.
- Add a `prompt_rewrite` bridge for CLI runtimes and map H3 official and
  Seedance 2.0 video profiles to their built-in optimization skills.
- Report optimization progress, success and failure through canvas toasts;
  the running label keeps its three dots, slowly pulses between the muted and
  normal text colours, and the composer border shows a thin rotating band.
- Share the assistant model selection helper between chat sending and prompt
  optimization, and update both user guides.

## validation

- `npx tsc --noEmit` in the PR worktree: clean.
- `pytest tests/test_prompt_optimization.py` (main checkout, identical service
  and tests): 2 passed, 1 skipped.
- `python scripts/generate_contracts.py --check`: verified.
- `node scripts/check-i18n.mjs`: 0 problems.

Refs: ThinkFlowLab#154
…kFlowLab#154)

## summary

- Read saved references without acquiring or moving the canvas edit lease.
- Cancel local preview work when its HTTP client disconnects.
- Validate the Windows CLI launch path and probe Codex through the same
  executable used for the rewrite.
- Cover competing sessions, disconnects, and missing CLI entries.

Refs: ThinkFlowLab#154
…lowLab#154)

## summary

- Resolve Codex and Claude using literal installed command names so a
  request runtime cannot flow into executable path discovery.
- Keep Windows package entry validation and cover both launchers.

Refs: ThinkFlowLab#154
## summary

- Wait for both the saved reply and the cleared active turn ID.
- Document the race reproduced by delaying lease release on the PR base.

Refs: ThinkFlowLab#154
@ThinkFlowLab ThinkFlowLab deleted a comment from davidhe91 Nov 25, 2026
@Probiotics5333

Copy link
Copy Markdown
Collaborator Author

Review follow-up for prompt optimization:

  • Edit lease. Rewriting a prompt opened the project and could conflict with an existing editor session. The optimizer now reads the saved snapshot without taking an edit lease. Fixed in ec8a686f.
  • Cancellation. Closing the browser request left the server waiting for the model. The API now cancels the optimization when the browser disconnects. Fixed in ec8a686f.
  • Windows CLI launch. CodeQL flagged executable paths derived from the requested runtime. Codex and Claude now use fixed command names and validated installation paths. Fixed in e240c3bb.
  • Assistant browser test. The test could see the saved reply before the active turn ID was cleared. This also reproduced on the PR base. The test now waits for both conditions. Fixed in 20b32bc4.

Release checks, CodeQL, and DSH plugin checks passed on 20b32bc4. Release checks · CodeQL

@allendyu

Copy link
Copy Markdown
Collaborator

老哥挺猛

@allendyu
allendyu merged commit 9b91b21 into ThinkFlowLab:main Nov 25, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent runtime, assistant chat and tools area:canvas Canvas, nodes and direct manipulation area:docs Documentation / 文档 area:provider Model providers and generation protocols type:feat New capability or behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants