Compare commits

...
3 Commits
Author SHA1 Message Date
ketle-manandClaude Opus 4.6 a5e481a6a5 v0.1.2: Add Canvas Snapshot and Thumbnail preview
- Add canvas snapshot button (camera icon) to ComfyUI top bar
- Capture workflow canvas as PNG with embedded workflow metadata (tEXt chunk)
- Auto-import captured snapshots to Workflow tab with thumbnails
- Add Thumbnail tab to workflow side panel for visual preview
- Add Thumbnail section to workflow detail modal
- Update README with v0.1.2 features, screenshots, and acknowledgements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 14:19:45 +09:00
ketle-manandClaude Opus 4.6 635522a689 v0.1.1: Add favicon and split Prompt tab into side-by-side layout
- Add W+S Wave SVG favicon matching the launch button design
- Replace Prompt tab's subtab switching with left/right split panel
  (AI Assistant + Presets displayed simultaneously)
- Update screenshot, README, and DEVLOG

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-19 09:04:47 +09:00
ketle-manandClaude Opus 4.6 3184060063 Update DEVLOG: JSON highlight, ZH translation, v0.1.0 release
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-18 22:20:39 +09:00
15 changed files with 689 additions and 122 deletions
+71 -4
View File
@@ -1,5 +1,30 @@
# DEVLOG - ComfyUI-Workflow-Studio
## 2026-03-19: v0.1.1 リリース
### 概要
- ファビコン追加
- プロンプトタブをサブタブ切り替え方式から左右2分割レイアウトに変更
### 変更内容
#### ファビコン追加
- `static/favicon.svg` — 起動ボタンと同じ W + S Wave デザインの SVG ファビコンを新規作成
- `templates/index.html` — `<link rel="icon">` タグ追加
#### プロンプトタブ 2分割レイアウト
- **課題:** Assistant / Presets のサブタブ切り替え方式では画面幅が広い場合に視点移動が大きく使いづらい
- **対応:** サブタブナビゲーションを廃止し、左パネル(AIアシスタント)・右パネル(プリセット)の同時表示レイアウトに変更
- `templates/index.html` — サブタブ構造を `.wfm-prompt-split` 左右分割構造に変更
- `static/css/main.css` — `.wfm-prompt-subtab-*` スタイルを `.wfm-prompt-split` / `.wfm-prompt-split-header` に置換
- `static/js/prompt-tab.js` — サブタブ切り替えイベントリスナー削除
- `static/js/app.js` — 翻訳対象をサブタブボタンからパネルヘッダーに変更
### スクリーンショット
![Prompt Tab](docs/screenshot_prompt.png)
---
## 2026-03-18: プロジェクトリネーム & アイコン適用
### 概要
@@ -85,7 +110,49 @@ ComfyUI-Workflow-Studio/
└── data/ # ワークフロー・メタデータ・設定
```
### 次のステップ
- Promptタブの実装完了 (CSS・app.js登録)
- GitHub公開準備
- ComfyUI Manager登録
---
## 2026-03-18: JSONシンタックスハイライト
### 概要
ワークフロータブ・生成UIタブのJSON表示にシンタックスハイライトを追加
### 色分け (eagle_comic_creater_webと同じOne Atomテーマ風)
- 黄 `#e5c07b` — name, scheduler
- ピンク `#c678dd` — title
- 緑 `#98c379` — width, height
- 水色 `#61afef` — text, prompt
- 赤 `#e06c75` — image, file
- ベース `#abb2bf` — その他
### 変更ファイル
- `static/js/json-highlight.js` — 新規: `highlightJSON`, `syncJsonHighlight`, `syncScroll`
- `static/js/workflow-tab.js` — サイドパネルJSON表示に `highlightJSON` 適用
- `templates/index.html` — Raw JSONを `<pre>` + `<textarea>` レイヤー構造に変更
- `static/js/generate-tab.js` — ハイライト同期、input/scrollイベント追加
- `static/js/comfyui-editor.js` — `_syncRawJson` にハイライト同期追加
- `static/css/main.css` — `.wfm-json-container`, `.wfm-json-highlight`, `.json-key-*` スタイル追加
---
## 2026-03-18: プロンプトタブ 中国語↔英語翻訳追加
### 概要
プロンプトタブの翻訳機能に ZH→EN / EN→ZH を追加
### 変更ファイル
- `templates/index.html` — `ZH→EN` / `EN→ZH` ボタン追加
- `static/js/prompt-tab.js` — `sendTranslate` に `zh2en` / `en2zh` プロンプト追加、イベントリスナー追加
---
## 2026-03-18: v0.1.0 リリース
### 概要
GitHub公開・ComfyUI Manager登録・初回リリース
### 実施内容
- GitHub リポジトリ作成: https://github.com/ketle-man/ComfyUI-Workflow-Studio
- README.md 作成(スクリーンショット4枚付き)
- ComfyUI Manager 登録PR: https://github.com/Comfy-Org/ComfyUI-Manager/pull/2706
- GitHub Release v0.1.0: https://github.com/ketle-man/ComfyUI-Workflow-Studio/releases/tag/v0.1.0
+37 -4
View File
@@ -5,6 +5,7 @@ A comprehensive workflow management and generation UI plugin for [ComfyUI](https
Browse, organize, and execute workflows directly from a dedicated studio interface — without switching between windows or manually editing JSON.
![Workflow Studio](https://img.shields.io/badge/ComfyUI-Custom_Node-blue)
![Version](https://img.shields.io/badge/version-0.1.2-green)
## Screenshots
@@ -16,20 +17,31 @@ Browse, organize, and execute workflows directly from a dedicated studio interfa
|:---:|:---:|
| ![Prompt](docs/screenshot_prompt.png) | ![Settings](docs/screenshot_settings.png) |
| ComfyUI Integration |
|:---:|
| ![ComfyUI Top Bar](docs/screenshot_comfyui_topbar.png) |
---
## Features
### Workflow Tab
- **Thumbnail / Card / Table views** — switch between view modes to browse your workflow library
- **Thumbnail side panel** — preview workflow canvas snapshots in the side panel
- **Tag-based filtering** — filter by base model (SD1.5, SDXL, etc.) and custom groups
- **Search** — full-text search across workflow names and metadata
- **Side panel** — view workflow JSON with syntax highlighting, format badge (UI/API), and copy button
- **Side panel tabs** — Thumbnail preview, JSON viewer with syntax highlighting, and Group management
- **Batch analysis** — auto-detect checkpoint, model type, prompt, and I/O node counts
- **AI summary** — generate workflow descriptions using Ollama
- **Import / Export** — import workflows from files or clipboard, open in ComfyUI directly
- **Default view setting** — persist your preferred view mode (Thumbnail / Card / Table)
### Canvas Snapshot (v0.1.2)
- **One-click capture** — click the camera button in ComfyUI's top bar to snapshot the current workflow canvas
- **Auto-save as thumbnail** — the snapshot is saved directly to the workflow data folder as a PNG thumbnail
- **Embedded workflow metadata** — workflow JSON is embedded in the PNG (tEXt chunk), compatible with ComfyUI's drag-and-drop import
- **Auto-import** — the captured workflow is automatically imported and appears in the Workflow tab
### GenerateUI Tab
- **Auto-generated parameter UI** — prompt, model, sampler, image, and other settings extracted from the workflow
- **One-click generation** — queue prompts to ComfyUI without leaving the studio
@@ -39,6 +51,7 @@ Browse, organize, and execute workflows directly from a dedicated studio interfa
- **Eagle integration** — auto-save generated images to [Eagle](https://eagle.cool/) with metadata
### Prompt Tab
- **Split-panel layout** — AI assistant and presets displayed side-by-side for simultaneous use
- **AI chat assistant** — powered by [Ollama](https://ollama.com/), generate and refine prompts interactively
- **Image attachment** — attach reference images for vision-capable models
- **Translation** — JA/EN/ZH translation buttons for multilingual prompt creation
@@ -75,18 +88,22 @@ Restart ComfyUI after installation.
### Launch
Click the **WS** button in the ComfyUI top menu bar, or navigate to:
Click the **W** button in the ComfyUI top menu bar, or navigate to:
```
http://127.0.0.1:8188/wfm
```
> **Tip:** Shift+Click the WS button to open in a new window.
> **Tip:** Shift+Click the W button to open in a new window.
### Canvas Snapshot
Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture the current workflow canvas as a thumbnail. The image is automatically saved to the workflow data folder and appears in Workflow Studio's workflow list.
### Quick Start
1. **Workflow Tab** — Your workflows from `ComfyUI/user/default/workflows/` are automatically listed
2. **Click a workflow** — View JSON details and metadata in the side panel
2. **Click a workflow** — View thumbnail, JSON details, and metadata in the side panel
3. **Load in GenerateUI** — Click the button to load a workflow into the generation interface
4. **Adjust parameters** — Modify prompts, models, seeds, and settings via the auto-generated UI
5. **Generate** — Hit the Generate button to queue the prompt
@@ -116,6 +133,19 @@ http://127.0.0.1:8188/wfm
---
## Changelog
### v0.1.2
- Added **Canvas Snapshot** button to ComfyUI top bar — capture workflow canvas as PNG thumbnail with embedded workflow metadata
- Added **Thumbnail tab** to the workflow side panel for quick visual preview
- Added **Thumbnail section** to the workflow detail modal
- Snapshot images are auto-imported as workflows with thumbnails
### v0.1.1
- Initial feature set: Workflow management, GenerateUI, Prompt assistant, Settings
---
## Project Structure
```
@@ -137,6 +167,7 @@ ComfyUI-Workflow-Studio/
├── templates/
│ └── index.html # SPA template
├── static/
│ ├── favicon.svg # Browser tab icon (W+S Wave)
│ ├── css/main.css # Styles
│ └── js/
│ ├── app.js # App initialization & routing
@@ -165,5 +196,7 @@ MIT License
## Acknowledgements
- [ComfyUI](https://github.com/comfyanonymous/ComfyUI) by comfyanonymous
- [ComfyUI-Custom-Scripts](https://github.com/pythongosssss/ComfyUI-Custom-Scripts) by pythongosssss — Canvas snapshot and PNG workflow embedding implementation reference
- [ComfyUI-Lora-Manager](https://github.com/willchil/ComfyUI-Lora-Manager) — Plugin architecture and UI pattern reference
- [Ollama](https://ollama.com/) for local LLM inference
- [Eagle](https://eagle.cool/) for image management
Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

After

Width:  |  Height:  |  Size: 56 KiB

+41
View File
@@ -27,6 +27,9 @@ def setup_routes(app: web.Application):
app.router.add_post(
"/api/wfm/workflows/change-thumbnail", handle_change_thumbnail
)
app.router.add_post(
"/api/wfm/workflows/save-canvas-image", handle_save_canvas_image
)
async def handle_list(request: web.Request) -> web.Response:
@@ -157,6 +160,44 @@ async def handle_reanalyze_all(request: web.Request) -> web.Response:
return web.json_response({"error": str(e)}, status=500)
async def handle_save_canvas_image(request: web.Request) -> web.Response:
"""POST /api/wfm/workflows/save-canvas-image - Import canvas PNG as workflow + thumbnail."""
try:
reader = await request.multipart()
filename = None
image_data = None
while True:
part = await reader.next()
if part is None:
break
if part.name == "filename":
filename = (await part.read()).decode("utf-8")
elif part.name == "image":
image_data = await part.read()
if not filename or not _service._validate_filename(filename):
return web.json_response({"error": "invalid filename"}, status=400)
if image_data is None:
return web.json_response({"error": "image required"}, status=400)
# Use import_files to extract workflow from PNG and save both JSON + thumbnail
stem = filename[:-5] if filename.endswith(".json") else filename
png_name = stem + ".png"
results = await asyncio.to_thread(
_service.import_files, [(png_name, image_data)]
)
if results and results[0].get("status") == "success":
return web.json_response({"status": "ok", "filename": results[0].get("name", filename)})
else:
error_msg = results[0].get("message", "Import failed") if results else "Import failed"
return web.json_response({"error": error_msg}, status=400)
except Exception as e:
logger.error("Error saving canvas image: %s", e)
return web.json_response({"error": str(e)}, status=500)
async def handle_change_thumbnail(request: web.Request) -> web.Response:
"""POST /api/wfm/workflows/change-thumbnail - Change workflow thumbnail."""
try:
+105 -32
View File
@@ -1315,46 +1315,34 @@ body {
============================================ */
/* Subtab navigation */
.wfm-prompt-subtab-nav {
.wfm-prompt-split {
display: flex;
flex: 1;
min-height: 0;
gap: 0;
border-bottom: 1px solid var(--wfm-border);
background: var(--wfm-surface);
flex-shrink: 0;
}
.wfm-prompt-subtab-btn {
.wfm-prompt-split-left,
.wfm-prompt-split-right {
flex: 1;
display: flex;
flex-direction: column;
min-height: 0;
overflow: hidden;
}
.wfm-prompt-split-left {
border-right: 1px solid var(--wfm-border);
}
.wfm-prompt-split-header {
padding: 8px 12px;
font-size: 13px;
border: none;
border-bottom: 2px solid transparent;
background: transparent;
color: var(--wfm-text-secondary);
cursor: pointer;
transition: color 0.15s, border-color 0.15s;
}
.wfm-prompt-subtab-btn:hover {
color: var(--wfm-text);
}
.wfm-prompt-subtab-btn.active {
color: var(--wfm-text);
border-bottom-color: var(--wfm-primary);
font-weight: bold;
}
.wfm-prompt-subtab-content {
display: none;
flex-direction: column;
flex: 1;
overflow: hidden;
min-height: 0;
}
.wfm-prompt-subtab-content.active {
display: flex;
color: var(--wfm-text);
background: var(--wfm-surface);
border-bottom: 1px solid var(--wfm-border);
flex-shrink: 0;
}
/* Ollama Assistant */
@@ -1660,3 +1648,88 @@ body {
color: var(--wfm-text-secondary);
line-height: 24px;
}
/* ============================================
Side Panel - Thumbnail Tab
============================================ */
.wfm-side-thumb-container {
display: flex;
flex-direction: column;
flex: 1;
overflow-y: auto;
padding: 10px;
gap: 10px;
}
.wfm-side-thumb-img-wrap {
width: 100%;
aspect-ratio: 1 / 1;
background: var(--wfm-bg);
border: 1px solid var(--wfm-border);
border-radius: var(--wfm-radius);
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.wfm-side-thumb-img-wrap img {
width: 100%;
height: 100%;
object-fit: contain;
cursor: pointer;
transition: transform 0.2s ease;
}
.wfm-side-thumb-img-wrap img:hover {
transform: scale(1.02);
}
.wfm-side-thumb-placeholder {
font-size: 13px;
color: var(--wfm-text-secondary);
}
.wfm-side-thumb-name {
font-size: 13px;
font-weight: 600;
word-break: break-all;
}
.wfm-side-thumb-meta {
font-size: 12px;
color: var(--wfm-text-secondary);
display: flex;
gap: 8px;
flex-wrap: wrap;
}
/* ============================================
Modal - Thumbnail Section
============================================ */
.wfm-modal-thumb-section {
display: flex;
align-items: center;
justify-content: center;
background: var(--wfm-bg);
border: 1px solid var(--wfm-border);
border-radius: var(--wfm-radius);
margin-bottom: 16px;
max-height: 280px;
overflow: hidden;
}
.wfm-modal-thumb-img {
max-width: 100%;
max-height: 280px;
object-fit: contain;
display: block;
}
.wfm-modal-thumb-placeholder {
padding: 32px;
font-size: 13px;
color: var(--wfm-text-secondary);
}
+5
View File
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="#4a9eff" stroke-linecap="round" stroke-linejoin="round">
<rect width="24" height="24" rx="4" fill="#1a1a2e" stroke="none"/>
<path d="M3 5 L7 17 L12 7 L17 17 L21 5" stroke-width="2.3"/>
<path d="M5 20 Q9 17 12 20 Q15 23 19 20" stroke-width="1.8"/>
</svg>

After

Width:  |  Height:  |  Size: 346 B

+4 -4
View File
@@ -143,10 +143,10 @@ function applyI18nToHtml() {
if (copyBtn) copyBtn.textContent = t("copy");
// Prompt tab
document.querySelectorAll(".wfm-prompt-subtab-btn").forEach((btn) => {
if (btn.dataset.promptSubtab === "assistant") btn.textContent = t("assistantSubtab");
if (btn.dataset.promptSubtab === "presets") btn.textContent = t("presetsSubtab");
});
const assistantHeader = document.querySelector(".wfm-prompt-split-left .wfm-prompt-split-header");
if (assistantHeader) assistantHeader.textContent = t("assistantSubtab");
const presetsHeader = document.querySelector(".wfm-prompt-split-right .wfm-prompt-split-header");
if (presetsHeader) presetsHeader.textContent = t("presetsSubtab");
const ollamaRefreshBtn = document.getElementById("wfm-ollama-refresh-btn");
if (ollamaRefreshBtn) ollamaRefreshBtn.textContent = t("refresh");
const ollamaTestBtn = document.getElementById("wfm-ollama-test-btn");
-12
View File
@@ -302,18 +302,6 @@ function renderPresets() {
// ============================================
export function initPromptTab() {
// Subtab switching
document.querySelectorAll(".wfm-prompt-subtab-btn").forEach((btn) => {
btn.addEventListener("click", () => {
document.querySelectorAll(".wfm-prompt-subtab-btn").forEach((b) => b.classList.remove("active"));
btn.classList.add("active");
const tab = btn.dataset.promptSubtab;
document.querySelectorAll(".wfm-prompt-subtab-content").forEach((c) => {
c.classList.toggle("active", c.id === `wfm-prompt-subtab-${tab}`);
});
});
});
// Ollama model refresh
async function refreshModels() {
const select = document.getElementById("wfm-ollama-model");
+46
View File
@@ -458,6 +458,9 @@ async function showSidePanel(wf, cardEl) {
);
if (cardEl) cardEl.classList.add("wfm-card-selected");
// Update thumbnail tab
sidePanelThumbUpdate(wf);
// Update group tab
sidePanelGroupUpdate();
@@ -495,6 +498,34 @@ function closeSidePanel() {
sidePanelGroupUpdate();
}
// ============================================
// Thumbnail Tab in Side Panel
// ============================================
function sidePanelThumbUpdate(wf) {
const imgWrap = document.getElementById("wfm-side-thumb-img-wrap");
const nameEl = document.getElementById("wfm-side-thumb-name");
const metaEl = document.getElementById("wfm-side-thumb-meta");
if (!imgWrap) return;
if (wf && wf.thumbnail) {
imgWrap.innerHTML = `<img src="${wf.thumbnail}" alt="${wf.filename}" />`;
} else {
imgWrap.innerHTML = `<span class="wfm-side-thumb-placeholder">${t("noImage")}</span>`;
}
if (nameEl) {
nameEl.textContent = wf ? wf.filename.replace(/\.json$/, "") : "";
}
if (metaEl && wf) {
const badges = (wf.analysis.modelTypes || []).map((mt) => badgeHtml(mt)).join(" ");
const io = `P:${wf.analysis.inputs?.prompts || 0} I:${wf.analysis.inputs?.images || 0} → ${wf.analysis.outputs?.images || 0}`;
metaEl.innerHTML = `${badges} <span style="margin-left:4px;">${io}</span>`;
} else if (metaEl) {
metaEl.innerHTML = "";
}
}
// ============================================
// Group Tab in Side Panel
// ============================================
@@ -646,7 +677,14 @@ function openDetailModal(wf) {
const overrideText = (meta.modelTypesOverride || []).join(", ");
const isFav = !!meta.favorite;
const thumbSrc = wf.thumbnail || "";
const html = `
<div class="wfm-modal-thumb-section">
${thumbSrc
? `<img src="${thumbSrc}" class="wfm-modal-thumb-img" />`
: `<div class="wfm-modal-thumb-placeholder">${t("noImage")}</div>`
}
</div>
<div class="wfm-modal-two-col">
<div class="wfm-modal-left">
<section>
@@ -893,6 +931,14 @@ function openDetailModal(wf) {
const cached = state.workflows.find((w) => w.filename === wf.filename);
if (cached) cached.thumbnail = newUrl;
renderGrid();
sidePanelThumbUpdate(wf);
// Update modal thumbnail if visible
const modalThumbImg = document.querySelector(".wfm-modal-thumb-img");
if (modalThumbImg) modalThumbImg.src = newUrl;
const modalThumbPlaceholder = document.querySelector(".wfm-modal-thumb-placeholder");
if (modalThumbPlaceholder) {
modalThumbPlaceholder.outerHTML = `<img src="${newUrl}" class="wfm-modal-thumb-img" />`;
}
showToast(t("thumbnailChanged"), "success");
} catch (err) {
showToast(t("thumbnailError") + ": " + err.message, "error");
+75 -62
View File
@@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Workflow Studio</title>
<link rel="icon" type="image/svg+xml" href="/wfm_static/favicon.svg">
<link rel="stylesheet" href="/wfm_static/css/main.css">
</head>
<body>
@@ -68,11 +69,24 @@
<button id="wfm-side-panel-close" class="wfm-side-panel-close">&times;</button>
</div>
<div class="wfm-side-tab-nav">
<button class="wfm-side-tab-btn active" data-side-tab="json">JSON</button>
<button class="wfm-side-tab-btn active" data-side-tab="thumb">Thumbnail</button>
<button class="wfm-side-tab-btn" data-side-tab="json">JSON</button>
<button class="wfm-side-tab-btn" data-side-tab="group">Group</button>
</div>
<!-- Thumbnail Tab -->
<div id="wfm-side-tab-thumb" class="wfm-side-tab-content active">
<div class="wfm-side-thumb-container">
<div id="wfm-side-thumb-img-wrap" class="wfm-side-thumb-img-wrap">
<span class="wfm-side-thumb-placeholder">No thumbnail</span>
</div>
<div class="wfm-side-thumb-info">
<div id="wfm-side-thumb-name" class="wfm-side-thumb-name"></div>
<div id="wfm-side-thumb-meta" class="wfm-side-thumb-meta"></div>
</div>
</div>
</div>
<!-- JSON Tab -->
<div id="wfm-side-tab-json" class="wfm-side-tab-content active">
<div id="wfm-side-tab-json" class="wfm-side-tab-content" style="display:none;">
<div class="wfm-side-json-meta">
<span id="wfm-json-format-badge" class="wfm-format-badge"></span>
<button id="wfm-json-copy-btn" class="wfm-btn wfm-btn-sm" style="margin-left:auto;">Copy</button>
@@ -222,71 +236,70 @@
<!-- Prompt Tab -->
<section id="wfm-tab-prompt" class="wfm-tab-content">
<div class="wfm-prompt-subtab-nav">
<button class="wfm-prompt-subtab-btn active" data-prompt-subtab="assistant">Assistant</button>
<button class="wfm-prompt-subtab-btn" data-prompt-subtab="presets">Presets</button>
</div>
<!-- Assistant Subtab -->
<div id="wfm-prompt-subtab-assistant" class="wfm-prompt-subtab-content active">
<div class="wfm-ollama-assistant">
<div class="wfm-ollama-controls">
<select id="wfm-ollama-model" class="wfm-select" style="flex:1;min-width:120px;">
<option value="">Loading models...</option>
</select>
<button id="wfm-ollama-refresh-btn" class="wfm-btn wfm-btn-sm">Refresh</button>
<button id="wfm-ollama-test-btn" class="wfm-btn wfm-btn-sm">Test</button>
<span id="wfm-ollama-status" class="wfm-ollama-status">Disconnected</span>
</div>
<div class="wfm-ollama-controls" style="margin-top:6px;">
<button id="wfm-ollama-attach-btn" class="wfm-btn wfm-btn-sm">Attach Image</button>
<input type="file" id="wfm-ollama-file-input" accept="image/*" style="display:none">
<button id="wfm-ollama-clear-btn" class="wfm-btn wfm-btn-sm" style="margin-left:auto;">Clear Chat</button>
</div>
<div id="wfm-ollama-attachments" class="wfm-ollama-attachments"></div>
<div id="wfm-ollama-chat" class="wfm-ollama-chat">
<div class="wfm-ollama-welcome">
<p>AI Assistant (Ollama)</p>
<p>Attach images, generate prompts, translate, or ask for improvements.</p>
<div class="wfm-prompt-split">
<!-- Left: Assistant -->
<div class="wfm-prompt-split-left">
<div class="wfm-prompt-split-header">Assistant</div>
<div class="wfm-ollama-assistant">
<div class="wfm-ollama-controls">
<select id="wfm-ollama-model" class="wfm-select" style="flex:1;min-width:120px;">
<option value="">Loading models...</option>
</select>
<button id="wfm-ollama-refresh-btn" class="wfm-btn wfm-btn-sm">Refresh</button>
<button id="wfm-ollama-test-btn" class="wfm-btn wfm-btn-sm">Test</button>
<span id="wfm-ollama-status" class="wfm-ollama-status">Disconnected</span>
</div>
<div class="wfm-ollama-controls" style="margin-top:6px;">
<button id="wfm-ollama-attach-btn" class="wfm-btn wfm-btn-sm">Attach Image</button>
<input type="file" id="wfm-ollama-file-input" accept="image/*" style="display:none">
<button id="wfm-ollama-clear-btn" class="wfm-btn wfm-btn-sm" style="margin-left:auto;">Clear Chat</button>
</div>
<div id="wfm-ollama-attachments" class="wfm-ollama-attachments"></div>
<div id="wfm-ollama-chat" class="wfm-ollama-chat">
<div class="wfm-ollama-welcome">
<p>AI Assistant (Ollama)</p>
<p>Attach images, generate prompts, translate, or ask for improvements.</p>
</div>
</div>
<div class="wfm-ollama-translate-row">
<span style="font-size:12px;color:var(--wfm-text-secondary);">Translate:</span>
<button id="wfm-ollama-ja2en-btn" class="wfm-btn wfm-btn-sm">JA→EN</button>
<button id="wfm-ollama-en2ja-btn" class="wfm-btn wfm-btn-sm">EN→JA</button>
<button id="wfm-ollama-zh2en-btn" class="wfm-btn wfm-btn-sm">ZH→EN</button>
<button id="wfm-ollama-en2zh-btn" class="wfm-btn wfm-btn-sm">EN→ZH</button>
</div>
<div class="wfm-ollama-input-wrap">
<textarea id="wfm-ollama-input" class="wfm-textarea" rows="3" placeholder="Ask AI... (Enter to send, Shift+Enter for newline)"></textarea>
<button id="wfm-ollama-send-btn" class="wfm-btn wfm-btn-primary" style="width:72px;align-self:flex-end;">Send</button>
</div>
</div>
<div class="wfm-ollama-translate-row">
<span style="font-size:12px;color:var(--wfm-text-secondary);">Translate:</span>
<button id="wfm-ollama-ja2en-btn" class="wfm-btn wfm-btn-sm">JA→EN</button>
<button id="wfm-ollama-en2ja-btn" class="wfm-btn wfm-btn-sm">EN→JA</button>
<button id="wfm-ollama-zh2en-btn" class="wfm-btn wfm-btn-sm">ZH→EN</button>
<button id="wfm-ollama-en2zh-btn" class="wfm-btn wfm-btn-sm">EN→ZH</button>
</div>
<div class="wfm-ollama-input-wrap">
<textarea id="wfm-ollama-input" class="wfm-textarea" rows="3" placeholder="Ask AI... (Enter to send, Shift+Enter for newline)"></textarea>
<button id="wfm-ollama-send-btn" class="wfm-btn wfm-btn-primary" style="width:72px;align-self:flex-end;">Send</button>
</div>
</div>
</div>
<!-- Presets Subtab -->
<div id="wfm-prompt-subtab-presets" class="wfm-prompt-subtab-content">
<div class="wfm-preset-panel">
<div style="display:flex;gap:6px;margin-bottom:10px;align-items:center;">
<select id="wfm-preset-select" class="wfm-select" style="flex:1;">
<option value="">New Preset (none selected)</option>
</select>
<button id="wfm-preset-apply-btn" class="wfm-btn wfm-btn-sm wfm-btn-primary">Apply to GenerateUI</button>
<button id="wfm-preset-delete-btn" class="wfm-btn wfm-btn-sm wfm-btn-danger">Delete</button>
<!-- Right: Presets -->
<div class="wfm-prompt-split-right">
<div class="wfm-prompt-split-header">Presets</div>
<div class="wfm-preset-panel">
<div style="display:flex;gap:6px;margin-bottom:10px;align-items:center;">
<select id="wfm-preset-select" class="wfm-select" style="flex:1;">
<option value="">New Preset (none selected)</option>
</select>
<button id="wfm-preset-apply-btn" class="wfm-btn wfm-btn-sm wfm-btn-primary">Apply to GenerateUI</button>
<button id="wfm-preset-delete-btn" class="wfm-btn wfm-btn-sm wfm-btn-danger">Delete</button>
</div>
<div class="wfm-form-group">
<label>Preset Name</label>
<input type="text" id="wfm-preset-name" class="wfm-input" placeholder="Enter preset name...">
</div>
<div class="wfm-form-group">
<label>Positive Prompt</label>
<textarea id="wfm-preset-pos" class="wfm-textarea" rows="4" placeholder="Positive prompt..."></textarea>
</div>
<div class="wfm-form-group">
<label>Negative Prompt</label>
<textarea id="wfm-preset-neg" class="wfm-textarea" rows="3" placeholder="Negative prompt..."></textarea>
</div>
<button id="wfm-preset-save-btn" class="wfm-btn wfm-btn-primary" style="width:100%;">Save Preset</button>
</div>
<div class="wfm-form-group">
<label>Preset Name</label>
<input type="text" id="wfm-preset-name" class="wfm-input" placeholder="Enter preset name...">
</div>
<div class="wfm-form-group">
<label>Positive Prompt</label>
<textarea id="wfm-preset-pos" class="wfm-textarea" rows="4" placeholder="Positive prompt..."></textarea>
</div>
<div class="wfm-form-group">
<label>Negative Prompt</label>
<textarea id="wfm-preset-neg" class="wfm-textarea" rows="3" placeholder="Negative prompt..."></textarea>
</div>
<button id="wfm-preset-save-btn" class="wfm-btn wfm-btn-primary" style="width:100%;">Save Preset</button>
</div>
</div>
</section>
+305 -4
View File
@@ -1,6 +1,7 @@
import { app } from "../../scripts/app.js";
const BUTTON_TOOLTIP = "Launch Workflow Studio (Shift+Click opens in new window)";
const SNAPSHOT_TOOLTIP = "Save workflow canvas image as thumbnail";
const WFM_PATH = "/wfm";
const NEW_WINDOW_FEATURES = "width=1400,height=900,resizable=yes,scrollbars=yes,status=yes";
const MAX_ATTACH_ATTEMPTS = 120;
@@ -19,6 +20,239 @@ const openWorkflowStudio = (event) => {
window.open(url, "_blank");
};
// ============================================
// Canvas Snapshot - Export workflow as PNG thumbnail
// ============================================
const getWorkflowFilename = () => {
const now = new Date();
const pad = (n) => String(n).padStart(2, "0");
const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
return `wf_${stamp}.json`;
};
// ---- PNG tEXt chunk embedding helpers ----
const n2b = (n) => new Uint8Array([(n >> 24) & 0xff, (n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]);
const joinArrayBuffer = (...bufs) => {
const result = new Uint8Array(bufs.reduce((total, buf) => total + buf.byteLength, 0));
bufs.reduce((offset, buf) => {
result.set(buf, offset);
return offset + buf.byteLength;
}, 0);
return result;
};
let _crcTable = null;
const crc32 = (data) => {
if (!_crcTable) {
_crcTable = [];
for (let n = 0; n < 256; n++) {
let c = n;
for (let k = 0; k < 8; k++) {
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
}
_crcTable[n] = c;
}
}
let crc = 0 ^ -1;
for (let i = 0; i < data.byteLength; i++) {
crc = (crc >>> 8) ^ _crcTable[(crc ^ data[i]) & 0xff];
}
return (crc ^ -1) >>> 0;
};
const embedWorkflowInPng = async (blob, workflowJson) => {
const buffer = await blob.arrayBuffer();
const typedArr = new Uint8Array(buffer);
const view = new DataView(buffer);
// Create tEXt chunk: "tEXtworkflow\0{json}"
const data = new TextEncoder().encode(`tEXtworkflow\0${workflowJson}`);
const chunk = joinArrayBuffer(n2b(data.byteLength - 4), data, n2b(crc32(data)));
// Insert after IHDR chunk (8-byte signature + IHDR length field(4) + IHDR type(4) + IHDR data + CRC(4))
const ihdrDataLen = view.getUint32(8);
const sz = ihdrDataLen + 20; // 8(sig) + 4(len) + 4(type) + ihdrDataLen + 4(crc)
const result = joinArrayBuffer(typedArr.subarray(0, sz), chunk, typedArr.subarray(sz));
return new Blob([result], { type: "image/png" });
};
// ---- Canvas capture ----
const captureCanvasSnapshot = () => {
return new Promise((resolve, reject) => {
try {
const graph = app.graph;
const canvas = app.canvas;
if (!graph || !canvas || !graph._nodes?.length) {
reject(new Error("No workflow loaded"));
return;
}
// Serialize workflow data before changing canvas state
const workflowJson = JSON.stringify(graph.serialize());
// Calculate bounds of all nodes
const bounds = graph._nodes.reduce(
(p, n) => {
if (n.pos[0] < p[0]) p[0] = n.pos[0];
if (n.pos[1] < p[1]) p[1] = n.pos[1];
const b = n.getBounding();
const r = n.pos[0] + b[2];
const bot = n.pos[1] + b[3];
if (r > p[2]) p[2] = r;
if (bot > p[3]) p[3] = bot;
return p;
},
[99999, 99999, -99999, -99999]
);
// Add padding
const padding = 80;
bounds[0] -= padding;
bounds[1] -= padding;
bounds[2] += padding;
bounds[3] += padding;
// Save current canvas state
const savedState = {
scale: canvas.ds.scale,
width: canvas.canvas.width,
height: canvas.canvas.height,
offset: [...canvas.ds.offset],
transform: canvas.canvas.getContext("2d").getTransform(),
};
// Set canvas to render full workflow
const dpr = window.devicePixelRatio || 1;
canvas.ds.scale = 1;
canvas.canvas.width = (bounds[2] - bounds[0]) * dpr;
canvas.canvas.height = (bounds[3] - bounds[1]) * dpr;
canvas.ds.offset = [-bounds[0], -bounds[1]];
canvas.canvas.getContext("2d").setTransform(dpr, 0, 0, dpr, 0, 0);
// Render
canvas.draw(true, true);
// Capture to blob
canvas.canvas.toBlob(async (rawBlob) => {
// Restore canvas state
canvas.ds.scale = savedState.scale;
canvas.canvas.width = savedState.width;
canvas.canvas.height = savedState.height;
canvas.ds.offset = savedState.offset;
canvas.canvas.getContext("2d").setTransform(savedState.transform);
canvas.draw(true, true);
if (!rawBlob) {
reject(new Error("Failed to generate canvas image"));
return;
}
try {
// Embed workflow JSON into PNG tEXt chunk
const blob = await embedWorkflowInPng(rawBlob, workflowJson);
resolve(blob);
} catch (embedErr) {
console.warn("Workflow Studio: failed to embed workflow metadata, saving without it:", embedErr);
resolve(rawBlob);
}
}, "image/png");
} catch (err) {
reject(err);
}
});
};
const saveCanvasToWorkflowStudio = async () => {
const filename = getWorkflowFilename();
try {
showNotification("Capturing workflow image...", "info");
const blob = await captureCanvasSnapshot();
const fd = new FormData();
fd.append("filename", filename);
fd.append("image", blob, "canvas.png");
const res = await fetch("/api/wfm/workflows/save-canvas-image", {
method: "POST",
body: fd,
});
const data = await res.json();
if (data.error) {
throw new Error(data.error);
}
showNotification(`Workflow saved: ${filename.replace(/\.json$/, "")}`, "success");
} catch (err) {
showNotification("Error: " + err.message, "error");
}
};
const showNotification = (message, type = "info") => {
// Try using ComfyUI's built-in toast if available
try {
if (app.ui?.dialog) {
// Fallback: use a simple temporary notification
}
} catch (e) { /* ignore */ }
// Simple toast notification
const existing = document.getElementById("wfm-snapshot-toast");
if (existing) existing.remove();
const toast = document.createElement("div");
toast.id = "wfm-snapshot-toast";
const colors = {
success: { bg: "rgba(46,213,115,0.95)", color: "#fff" },
error: { bg: "rgba(255,71,87,0.95)", color: "#fff" },
info: { bg: "rgba(74,158,255,0.95)", color: "#fff" },
};
const c = colors[type] || colors.info;
Object.assign(toast.style, {
position: "fixed",
bottom: "24px",
left: "50%",
transform: "translateX(-50%)",
padding: "10px 24px",
background: c.bg,
color: c.color,
borderRadius: "8px",
fontSize: "14px",
fontWeight: "500",
zIndex: "99999",
boxShadow: "0 4px 16px rgba(0,0,0,0.3)",
transition: "opacity 0.3s ease",
whiteSpace: "nowrap",
});
toast.textContent = message;
document.body.appendChild(toast);
if (type !== "info") {
setTimeout(() => {
toast.style.opacity = "0";
setTimeout(() => toast.remove(), 300);
}, 3000);
} else {
// Info messages will be replaced by success/error
setTimeout(() => {
if (toast.parentNode) {
toast.style.opacity = "0";
setTimeout(() => toast.remove(), 300);
}
}, 10000);
}
};
// ============================================
// Version Detection & UI
// ============================================
const getComfyUIFrontendVersion = async () => {
try {
if (window["__COMFYUI_FRONTEND_VERSION__"]) {
@@ -87,6 +321,20 @@ const getWfmIcon = () => {
`;
};
const getSnapshotIcon = () => {
return `
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
<rect x="3" y="5" width="18" height="14" rx="2"/>
<circle cx="12" cy="12" r="3"/>
<path d="M8 5 L9 3 L15 3 L16 5"/>
</svg>
`;
};
// ============================================
// Button Creation
// ============================================
const createTopMenuButton = async () => {
const { ComfyButton } = await import("../../scripts/ui/components/button.js");
@@ -111,6 +359,30 @@ const createTopMenuButton = async () => {
return button;
};
const createSnapshotButton = async () => {
const { ComfyButton } = await import("../../scripts/ui/components/button.js");
const button = new ComfyButton({
icon: "snapshot",
tooltip: SNAPSHOT_TOOLTIP,
app,
enabled: true,
classList: "comfyui-button comfyui-menu-mobile-collapse",
});
button.element.setAttribute("aria-label", SNAPSHOT_TOOLTIP);
button.element.title = SNAPSHOT_TOOLTIP;
if (button.iconElement) {
button.iconElement.innerHTML = getSnapshotIcon();
button.iconElement.style.width = "1.2rem";
button.iconElement.style.height = "1.2rem";
}
button.element.addEventListener("click", saveCanvasToWorkflowStudio);
return button;
};
const attachTopMenuButton = async (attempt = 0) => {
if (document.querySelector(`.${BUTTON_GROUP_CLASS}`)) {
return;
@@ -128,9 +400,10 @@ const attachTopMenuButton = async (attempt = 0) => {
}
const wfmButton = await createTopMenuButton();
const snapshotButton = await createSnapshotButton();
const { ComfyButtonGroup } = await import("../../scripts/ui/components/buttonGroup.js");
const buttonGroup = new ComfyButtonGroup(wfmButton);
const buttonGroup = new ComfyButtonGroup(wfmButton, snapshotButton);
buttonGroup.element.classList.add(BUTTON_GROUP_CLASS);
settingsGroup.element.before(buttonGroup.element);
@@ -161,14 +434,22 @@ const createExtensionObject = (useActionBar) => {
button[aria-label="${BUTTON_TOOLTIP}"].wfm-top-menu-button:hover {
background-color: var(--primary-hover-bg) !important;
}
button[aria-label="${SNAPSHOT_TOOLTIP}"].wfm-snapshot-button {
transition: all 0.2s ease;
border: 1px solid transparent;
}
button[aria-label="${SNAPSHOT_TOOLTIP}"].wfm-snapshot-button:hover {
background-color: var(--primary-hover-bg) !important;
}
`;
document.head.appendChild(style);
};
injectStyles();
const replaceButtonIcon = () => {
const buttons = document.querySelectorAll(`button[aria-label="${BUTTON_TOOLTIP}"]`);
buttons.forEach((button) => {
// WFM launch button
const wfmButtons = document.querySelectorAll(`button[aria-label="${BUTTON_TOOLTIP}"]`);
wfmButtons.forEach((button) => {
button.classList.add("wfm-top-menu-button");
button.innerHTML = getWfmIcon();
button.style.borderRadius = "4px";
@@ -180,7 +461,22 @@ const createExtensionObject = (useActionBar) => {
svg.style.height = "20px";
}
});
if (buttons.length === 0) {
// Snapshot button
const snapButtons = document.querySelectorAll(`button[aria-label="${SNAPSHOT_TOOLTIP}"]`);
snapButtons.forEach((button) => {
button.classList.add("wfm-snapshot-button");
button.innerHTML = getSnapshotIcon();
button.style.borderRadius = "4px";
button.style.padding = "6px";
const svg = button.querySelector("svg");
if (svg) {
svg.style.width = "20px";
svg.style.height = "20px";
}
});
if (wfmButtons.length === 0) {
requestAnimationFrame(replaceButtonIcon);
}
};
@@ -195,6 +491,11 @@ const createExtensionObject = (useActionBar) => {
tooltip: BUTTON_TOOLTIP,
onClick: openWorkflowStudio,
},
{
icon: "icon-[mdi--camera] size-4",
tooltip: SNAPSHOT_TOOLTIP,
onClick: saveCanvasToWorkflowStudio,
},
];
}