Compare commits

...
3 Commits
Author SHA1 Message Date
ketle-manandClaude Sonnet 4.6 95266a20b8 v0.3.13: AI tab (Translation, VLM, Settings) for SPA and Library panel
- Add A tab to SPA (templates/index.html) with Translation, VLM, Settings sub-tabs
- Add new static/js/ai-tab.js module (Ollama / LM Studio backends, full i18n via t())
- Add A tab to Workflow Studio Library side panel (node_sets_menu.js)
- Settings shared between SPA and Library panel via localStorage (wfm_ai_settings)
- URL security: validate backend URL with new URL() before any network call
- Rename ollamaSettings to 'Ollama Settings (Prompt Tab)' in EN/JA/ZH to distinguish from AI tab
- Add AI tab help card and helpSidepanel16 to Help tab (index.html + i18n.js + app.js)
- Update docs/6_ws_library.png, README.md (v0.3.13), DEVLOG.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 14:42:40 +09:00
ketle-manandClaude Sonnet 4.6 d54234b18d v0.3.12: Raw JSON search, workflow analyzer extended model detection, README screenshots refresh
- GenerateUI: always-visible search bar in Raw JSON panel (match count, ↑/↓ nav, Escape/✕ clear, orange/yellow highlights, scroll sync)
- workflow_analyzer: CLIPLoader type-field detection (_CLIP_TYPE_TO_MODEL), subgraph node scanning, UnetLoaderGGUF support, NewBie/Ovis/HiDream/Wan/Cosmos/Lumina added
- README: screenshots replaced with 8 feature-focused images; v0.3.12 changelog

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 13:46:59 +09:00
ketle-manandClaude Sonnet 4.6 4298fd9ea2 v0.3.11: Metadata tab extended loader support + Settings text size slider
- metadata-tab.js: add UnetLoaderGGUF/UNETLoaderGGUF as Diffusion Model
  and QuadrupleCLIPLoader as Text Encoder (was already in node_sets_menu.js
  for the I tab; now consistent across both Metadata tab and side panel)
- settings-tab.js: add applyTextareaFontSize() + Text Size section (10-28px
  slider that applies to all 8 prompt/chat textareas at once)
- app.js: apply saved textareaFontSize on page load alongside theme
- templates/index.html: update help text for Metadata and Settings tabs
- README/DEVLOG: v0.3.11 documentation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 16:03:10 +09:00
31 changed files with 2424 additions and 58 deletions
+252
View File
@@ -1,5 +1,257 @@
# DEVLOG - ComfyUI-Workflow-Studio
## 2026-05-19: v0.3.13 — AI タブ(A)追加
### 概要
SPA および Workflow Studio Library サイドパネルの両方に AI タブ(A)を追加。Ollama・LM Studio をバックエンドとして翻訳・VLM(画像解析)機能を提供する。設定は `localStorage` 経由で両インターフェース間で共有。
### 変更内容
#### `templates/index.html`
- タブバーに `<button class="wfm-tab" data-tab="ai">A</button>` を右端に追加
- `<section id="wfm-tab-ai">` を新規追加(3 サブタブ構成)
- **翻訳サブタブ** (`wfm-ai-subtab-translate`): 入力テキストエリア・言語セレクター(日/英/中/Free)・⇄ 入替ボタン・翻訳ボタン・出力テキストエリア・コピーボタン・ステータス表示
- **VLM サブタブ** (`wfm-ai-subtab-vlm`): ドロップゾーン(110px)・タスクドロップダウン(画像の解説/プロンプト作成)・実行ボタン・結果エリア・コピーボタン
- **設定サブタブ** (`wfm-ai-subtab-settings`): バックエンド選択ラジオ・API URL 入力・接続テストボタン・モデル選択+更新ボタン・Free 言語入力(入力/出力)・保存ボタン
- ヘルプタブにAI タブ説明カード追加、Sidepanel カードに `wfm-help-sidepanel-16` を追加
#### `static/js/ai-tab.js`(新規)
- `import { showToast } from "./app.js"` / `import { t } from "./i18n.js"`
- **定数**: `SETTINGS_KEY = "wfm_ai_settings"`、`LANG_NAMES`、`VLM_PROMPTS`(describe / prompt)
- **`isValidBackendUrl(url)`**: `new URL()` で `http:` / `https:` スキームのみ許可
- **`fileToBase64(file)`**: FileReader → `{ base64, mimeType }`
- **`callVLM()`**: Ollama は `images:[b64]`、LM Studio は `image_url` コンテンツブロック
- **`callLLM()`**: テキスト翻訳用 LLM 呼び出し(Ollama / LM Studio)
- **`fetchModels()`**: Ollama `/api/tags`、LM Studio `/v1/models` からモデル一覧取得
- **`buildTranslationPrompt()`**: Free 言語設定対応の翻訳プロンプト生成
- **`initSubTabs()`** / **`initTranslateTab()`** / **`initVlmTab()`** / **`initSettingsTab()`**
- すべての動的文字列を `t()` 経由で i18n 対応済み
- **`export function initAiTab()`**: 全 init 関数のエントリポイント
#### `static/js/app.js`
- `import { initAiTab } from "./ai-tab.js"` を追加
- `DOMContentLoaded` 内に `initAiTab()` を追加
- `tabMap` に `ai: "tabAi"` を追加
- `applyI18nToHtml()` に AI タブの全要素 id マッピングを追加
- サブタブボタン、言語セレクター option、placeholder、ボタンテキスト、セクションタイトル、ラベル
- ヘルプタブ新規 id(`wfm-help-sidepanel-16`、`wfm-help-ai-title`、`wfm-help-ai-1`〜`6`)
#### `static/js/i18n.js`
- `tabAi: "A"` を EN/JA/ZH に追加(タブボタンラベル)
- AI タブ全キーブロックを EN/JA/ZH に追加(計 3 言語 × 約 40 キー)
- サブタブ名、言語オプション、placeholder、ボタンテキスト、ステータス文字列、トースト文字列
- `aiToastNoText`、`aiToastNoModel`、`aiToastInvalidUrl`、`aiToastInvalidUrlInput`
- `aiStatusTranslating`、`aiStatusRunning`、`aiStatusDone`、`aiStatusConnecting`、`aiStatusConnectOk`、`aiStatusConnectFail`
- `aiToastTransFailed`、`aiToastNoCopyText`、`aiToastCopied`、`aiToastNoModels`、`aiToastModelsFailed`
- `aiToastSettingsSaved`、`aiToastNoImage`、`aiToastVlmFailed`、`aiModels`
- ヘルプキー: `helpSidepanel16`、`helpAiTitle`、`helpAi1`〜`helpAi6`
- `ollamaSettings` を EN/JA/ZH で "(プロンプトタブ)" サフィックス付きに改名
#### `static/css/main.css`
- AI サブタブナビ: `.wfm-ai-subtab-nav`、`.wfm-ai-subtab-btn`(`.active` 状態含む)、`.wfm-ai-subtab-content`
- 翻訳タブ: `.wfm-ai-trans-container`、`.wfm-ai-trans-lang-row`、`.wfm-ai-lang-select`、`.wfm-ai-swap-btn`、`.wfm-ai-trans-textarea`、`.wfm-ai-trans-output`、`.wfm-ai-trans-actions`、`.wfm-ai-trans-status`
- ステータス色: `.wfm-ai-status-working`(amber)、`.wfm-ai-status-ok`(green)、`.wfm-ai-status-error`(red)
- VLM タブ: `.wfm-ai-vlm-container`、`.wfm-ai-vlm-drop`(height: 110px、破線ボーダー、I タブと統一)、`.wfm-ai-vlm-label`、`.wfm-ai-vlm-preview`、`.wfm-ai-vlm-task-row`、`.wfm-ai-vlm-result`、`.wfm-ai-vlm-copy-btn`
- 設定タブ: `.wfm-ai-settings-*` 各セクション
#### `web/comfyui/node_sets_menu.js`
- `state` に `aiSubTab: "ai-translate"` を追加
- トップタブバーに `data-toptab="ai"` の A ボタンを I タブの右に追加
- `rebuildSubTabs()`: AI ケースを追加(翻訳/VLM/設定 サブタブ)
- `renderContent()`: `topTab === "ai"` 分岐を追加、検索バー非表示、`renderAiTab()` を呼び出し
- 追加関数:
- `isValidAiUrl()`: URL セキュリティ検証
- `loadAiCfg()` / `saveAiCfg()`: `localStorage` への設定読み書き(SPA と共有)
- `aiFileToBase64()` / `aiCallVLM()` / `aiCallLLM()` / `aiFetchModels()`: バックエンド API ラッパー
- `renderAiTab(container)`: 初回のみ HTML を構築し `setupAiHandlers()` を呼び出す
- `renderAiSubContent()`: サブタブに応じてペインを表示切替
- `setupAiHandlers(container)`: 翻訳・VLM・設定の全イベントハンドラ
- `injectStyles()`: AI タブ CSS を追加(VLM ドロップゾーン高さ 110px を含む)
#### `docs/6_ws_library.png`
- A タブ追加後の Library パネルスクリーンショットに更新
#### `README.md`
- バージョンバッジを `0.3.13` に更新
- Features に **AI Tab (A)** セクションを追加
- Workflow Studio Library のタブ説明を `W/N/P/M/I` → `W/N/P/M/I/A` に更新、A タブ説明を追加
- Requirements — Optional に LM Studio を追記
- Project Structure に `ai-tab.js` を追加
- Changelog に v0.3.13 エントリを追加
---
## 2026-05-18: v0.3.12 リリース — README スクリーンショット刷新 / workflow_analyzer 拡張
### 概要
- README Screenshots を旧タブ別画像(12枚)から機能特徴別の新画像(8枚)に刷新
- `workflow_analyzer.py` に CLIPLoader type フィールド対応・新モデル種別検出を追加(NewBie / Ovis / HiDream / Wan / Cosmos / Lumina 等)
### 変更内容
#### `README.md`
- バージョンバッジを `0.3.12` に更新
- Screenshots セクションを全面刷新
- 旧: `docs/screenshot_*.png` 参照の 6 テーブル(タブ別 12 枚)
- 新: `docs/1_workflowtab.png`〜`docs/8_Customize.png` の機能特徴別 8 枚を 2 カラムグリッドで表示
- キャプションはファイル名のプレフィックスを除いて整形(例: `1_workflowtab` → **Workflow Tab**)
- `v0.3.12` changelog エントリを新規追加(RAW JSON 検索 + workflow_analyzer 拡張)
#### `docs/`
- 旧スクリーンショット 11 枚(`screenshot_*.png`)を削除
- 新スクリーンショット 8 枚(`1_workflowtab.png`〜`8_Customize.png`)を追加
#### `py/services/workflow_analyzer.py`
**`_CLIP_TYPE_TO_MODEL` 追加**
- CLIPLoader の type 文字列(`"flux"`, `"hidream_i"`, `"wan"`, `"cosmos"` 等)→ モデル種別名のマッピング辞書
**`_clip_type_from_ui_node(node)` 追加**
- UI フォーマットノードの `widgets_values` から CLIPLoader / DualCLIPLoader / TripleCLIPLoader の type 文字列を取得
**`_collect_all_ui_nodes(workflow_data)` 追加**
- `nodes[]` だけでなく `definitions.subgraphs[].nodes[]` も走査するジェネレータ
- サブグラフ内のローダーノードも model_type 検出の対象になった
**`_detect_model_type_from_name(mn_base, model_types)` 追加**
- モデルファイル名から種別を判定するヘルパー関数に切り出し(従来はインライン記述)
- 追加対応: NewBie / Ovis / HiDream / Wan(`wan-N` / `wan-video` パターン)
**`analyze_workflow()` 改修**
- ファイル名検出に NewBie / Ovis / HiDream / Wan を追加
- `UnetLoaderGGUF` 等を含む `UnetLoader` 系を一括マッチ (`"UnetLoader" in ntype`)
- CLIPLoader 系ノードで `clip_type` → `_CLIP_TYPE_TO_MODEL` → モデル種別を検出
- `_model_name_from_api_node` に `clip_name1` / `clip_name` を追加(CLIPLoader の API フォーマット対応)
- node_iter のタプルに `clip_type` を追加(`(ntype, title, mn, clip_type)`)
- タイトル検出に HiDream / Ovis / NewBie を追加
---
## 2026-05-17: RAW JSON パネルに検索機能を追加
### 概要
生成 UI タブの RAW JSON パネルに VSCode 風の検索バーを追加。常時表示で、マッチ間ナビゲーションとクリアボタンを備える。
### 変更内容
#### `templates/index.html`
- `#wfm-gen-rawjson-widget` 内にヘッダーとエディターの間で `.wfm-rawjson-search` バーを追加
- 検索入力 (`#wfm-gen-raw-search`)
- マッチ数表示 (`#wfm-gen-raw-search-count`、例: `3/12`)
- 前へ ↑ / 次へ ↓ ボタン
- ✕ クリアボタン
- JSON コンテナ内に検索ハイライト専用オーバーレイ `<pre id="wfm-gen-raw-json-search-overlay">` を追加(シンタックスハイライト層と textarea 層の間)
#### `static/css/main.css`
- `.wfm-rawjson-search` — 検索バー全体のレイアウト
- `.wfm-rawjson-search-input` — 検索入力フィールド(フォーカス時 accent カラーのボーダー)
- `.wfm-rawjson-search-count` — マッチ数表示(min-width: 56px、中央揃え)
- `.wfm-rawjson-search-btn` / `.wfm-rawjson-search-clear` — ナビ・クリアボタン
- `.wfm-json-search-overlay` — 文字色を透明にし `<mark>` の背景のみを表示するオーバーレイ
- `.wfm-search-match` — 通常マッチ: 黄色半透明
- `.wfm-search-current` — 現在マッチ: オレンジ強調 + アウトライン
- `.wfm-json-editor` の z-index を 2 → 3 に更新(オーバーレイが z-index: 2 を占有するため)
#### `static/js/generate-tab.js`
既存の「Raw JSON highlight sync on input/scroll」ブロックを拡張:
- `updateSearchOverlay()` — 検索語でテキストを走査し `matchPositions[]` を構築、オーバーレイ HTML を生成
- マッチなし時: カウント欄を赤字で "No results" 表示
- 現在マッチへ自動スクロール + テキストエリアのカーソルをマッチ位置に移動
- スクロール同期: エディター scroll イベントでオーバーレイの scrollTop/Left を追従
- エディター入力時: シンタックスハイライト更新と並行して検索オーバーレイも更新
- キーボード: Enter(次へ)/ Shift+Enter(前へ)/ Escape(クリア)対応
---
## 2026-05-17: v0.3.11 Metadata タブ対応ノードタイプ拡張 / Settings テキストサイズ UI 追加
### 概要
- `metadata-tab.js`(Metadata タブ本体)に `UnetLoaderGGUF` / `UNETLoaderGGUF` / `QuadrupleCLIPLoader` 対応を追加
- `node_sets_menu.js` の I タブには v0.3.10 で追加済みだったが、Metadata タブには未反映だった
- Settings タブに「Text Size」セクションを追加 — プロンプト・チャット系の全テキストエリアのフォントサイズを一括変更するスライダー
### 変更内容
#### `static/js/metadata-tab.js`
**`extractDiffusionModels` 拡張**
- `UNETLoader` のみ → `UNETLoader` / `UnetLoaderGGUF` / `UNETLoaderGGUF` に拡張(Set を使った判定に変更)
- HiDream i1 Full GGUF など GGUF 形式の Diffusion Model が Metadata タブでも正しく読み取れるようになった
**`extractTextEncoders` 拡張**
- `QuadrupleCLIPLoader`(`clip_name1`〜`clip_name4`)を追加、LiteGraph 形式・API 形式の両方に対応
- HiDream の 4-CLIP(clip_l / clip_g / t5xxl / llama_3.1)が全件表示されるようになった
#### `static/js/settings-tab.js`
**`applyTextareaFontSize(size)` 追加(export)**
- `<style id="wfm-ta-font-size-style">` を `<head>` に注入
- 対象セレクタ(対象を 8 箇所に一括適用):
| 対象 | ID |
|---|---|
| Generate UI — Positive Prompt | `#wfm-prompt-pos-text` |
| Generate UI — Negative Prompt | `#wfm-prompt-neg-text` |
| Prompt タブ — AI Assistant チャット | `#wfm-ollama-input` |
| Prompt タブ — Preset Positive | `#wfm-preset-pos` |
| Prompt タブ — Preset Negative | `#wfm-preset-neg` |
| Prompt タブ — Wildcard プロンプト | `#wfm-wc-prompt` |
| Prompt タブ — Wildcard ファイルエディタ | `#wfm-wc-editor-content` |
| Metadata タブ — PROMPT 全文プレビュー | `#wfm-meta-prompt-full` |
- 範囲: 10〜28px(clamp)、デフォルト 13px
**Settings タブ HTML「Text Size」セクション追加**
- Language Settings の下、Workflow Data Folder の上に新規 `<details>` セクション
- `<input type="range">` スライダー (min=10, max=28, step=1) + px 値表示
- スライダー操作でリアルタイム適用
- 「Save Settings」ボタンで `textareaFontSize` を localStorage に保存
#### `static/js/app.js`
- `applyTextareaFontSize` をインポート
- ページ読み込み直後(テーマ適用と同タイミング)に localStorage の保存値を読み込んで適用
#### `templates/index.html`
- `wfm-help-metadata-5`: 対応ローダーを明記(UNETLoader / UnetLoaderGGUF / UNETLoaderGGUF / CLIPLoader / DualCLIPLoader / TripleCLIPLoader / QuadrupleCLIPLoader)
- `wfm-help-settings-11` 新規追加: Text Size スライダーの説明
### 検証済みファイル
| ファイル | Metadata タブでの検出内容 |
|---|---|
| `n-hidream_i1_full.png` | Diffusion Model: `hidream-i1-full-Q5_0.gguf`(UnetLoaderGGUF)、Text Encoder: 4 件(QuadrupleCLIPLoader)、VAE: 1 件 |
---
## 2026-05-17: v0.3.10 Information タブ キャンバスドラッグ対応 / ノードタイプ拡張 / バグ修正
### 概要
+44 -22
View File
@@ -5,33 +5,25 @@ 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.3.10-green)
![Version](https://img.shields.io/badge/version-0.3.13-green)
## Screenshots
| Workflow Tab | GenerateUI Tab |
| Workflow Tab | Models Tab |
|:---:|:---:|
| ![Workflow](docs/screenshot_workflow.png) | ![GenerateUI](docs/screenshot_generate.png) |
| ![Workflow Tab](docs/1_workflowtab.png) | ![Models Tab](docs/2_modelstab.png) |
| Prompt Tab | Metadata Tab |
| Prompt Input Assistance | Gen UI Feeder |
|:---:|:---:|
| ![Prompt](docs/screenshot_prompt.png) | ![Metadata](docs/screenshot_metadata.png) |
| ![Prompt Input Assistance](docs/3_PromptInputAssistance.png) | ![Gen UI Feeder](docs/4_GenUI_feeder.png) |
| Settings Tab | Help & Support Tab |
| Top Bar | WS Library |
|:---:|:---:|
| ![Settings](docs/screenshot_settings.png) | ![Help](docs/screenshot_help.png) |
| ![Top Bar](docs/5_topbar.png) | ![WS Library](docs/6_ws_library.png) |
| Nodes Tab | Models Tab |
| Library Information | Customize |
|:---:|:---:|
| ![Nodes](docs/screenshot_nodes.png) | ![Models](docs/screenshot_models.png) |
| Gallery Tab | Nodes Tab |
|:---:|:---:|
| ![Gallery](docs/screenshot_gallery.png) | ![Nodes](docs/screenshot_nodes.png) |
| Workflow Studio Library (ComfyUI) | ComfyUI Integration |
|:---:|:---:|
| ![Workflow Studio Library](docs/screenshot_wf_node_library.png) | ![ComfyUI Top Bar](docs/screenshot_comfyui_topbar.png) |
| ![Library Information](docs/7_library_Infomation.png) | ![Customize](docs/8_Customize.png) |
---
@@ -59,7 +51,7 @@ Browse, organize, and execute workflows directly from a dedicated studio interfa
- **Input tab** — Prompt (top) and Image drag-and-drop (bottom) in the left column; Raw JSON (540px) in the right column
- **Model tab** — Checkpoint, VAE, LoRA, ControlNet, UNET, TextEncoder selectors with filter; Raw JSON on the right
- **Settings tab** — KSampler and Latent Image side by side at 50% width each; Raw JSON on the right
- **Always-visible Raw JSON** — edit the API-format JSON directly from any tab with syntax highlighting; Apply button reloads the workflow
- **Always-visible Raw JSON** — edit the API-format JSON directly from any tab with syntax highlighting; Apply button reloads the workflow; built-in **search bar** (always shown) finds all matches as you type with count display (`3/12`); navigate with ↑/↓ buttons or Enter / Shift+Enter; Escape or ✕ clears; current match highlighted in orange, other matches in yellow
- **One-click generation** — queue prompts to ComfyUI without leaving the studio
- **Seed control** — randomize, lock, or manually set seeds; seed input and mode selector stacked vertically for readability
- **Checkpoint Batch** — enable via checkbox in the right panel to sequentially generate with every checkpoint model; select checkpoints by folder from the dropdown (check a folder to select all its files, expand with ▶ for individual file selection, supports any subfolder depth); Filter input to search; All / None buttons for quick selection; **Pause/Resume** suspends processing between models; Stop aborts after the current generation; amber progress bar tracks per-model progress
@@ -95,7 +87,7 @@ Requires the **[comfyui-image-feeder](https://github.com/ketle-man/comfyui-image
### Metadata Tab (v0.3.8)
- **3-column layout** — Drop zone (left) | Model info (center) | LoRA + Prompt (right)
- **File drop** — drop a ComfyUI-generated PNG / WebP or workflow JSON onto the drop zone (or click to open a file picker); PNG/WebP images are shown as a preview
- **Model extraction** — automatically extracts Checkpoint, VAE, Diffusion Model, and Text Encoder names from the workflow; supports both standard and subgraph-based workflows (Flux.2 Dev/Klein, Qwen-Image-Edit/2511/Layered, Z-Image Base/Turbo, Ernie Image, WAN2.2)
- **Model extraction** — automatically extracts Checkpoint, VAE, Diffusion Model, and Text Encoder names from the workflow; supports both standard and subgraph-based workflows (Flux.2 Dev/Klein, Qwen-Image-Edit/2511/Layered, Z-Image Base/Turbo, Ernie Image, WAN2.2); node types covered: UNETLoader, UnetLoaderGGUF, UNETLoaderGGUF (e.g. HiDream GGUF), CLIPLoader, DualCLIPLoader, TripleCLIPLoader, QuadrupleCLIPLoader (e.g. HiDream 4-CLIP)
- **LoRA extraction** — lists all LoRA models with `strength_model / strength_clip` values
- **Prompt extraction** — lists prompts with POS / NEG badges when positive/negative can be determined; when distinction is not possible (e.g. `SamplerCustomAdvanced`, intermediate nodes, cross-level connections), prompts are shown without a badge as plain **Text**; click any entry to view the full text below
- **Prompt actions** — Copy to clipboard, **GenUI:P/N** (set GenerateUI positive/negative prompt), **Prompt:P/N** (set Prompt tab preset positive/negative)
@@ -113,6 +105,7 @@ Requires the **[comfyui-image-feeder](https://github.com/ketle-man/comfyui-image
- **Ollama connection** — configure Ollama server URL
- **Default workflow** — set a workflow to auto-load on startup
- **Data Management** — export all plugin data (settings, metadata, prompts, etc.) to a single JSON file; import to restore data (useful when migrating or reinstalling)
- **Text Size** — one slider (10–28 px) adjusts font size for all prompt and chat textareas at once: Generate UI positive/negative prompts, AI Assistant chat input, Preset prompts, Wildcard prompt and file editor, and Metadata prompt full preview; takes effect immediately and saved with Save Settings
- **Wildcard Integration** — link the WFS wildcard directory to ComfyUI-Impact-Pack's `wildcards/` directory (directory junction on Windows, symlink on other OS); existing WFS wildcard files are automatically migrated; requires [ComfyUI-Impact-Pack](https://github.com/ltdrdata/ComfyUI-Impact-Pack)
- **Language** — English / Japanese / Chinese
@@ -155,8 +148,16 @@ Requires the **[comfyui-image-feeder](https://github.com/ketle-man/comfyui-image
- **Enable / Disable models** — hide models from ComfyUI by renaming the file extension (`.disabled` suffix); toggle per card (⏸ button), per group (Enable All / Disable All), or filter by status (All / Enabled / Disabled)
- **Multi-select & bulk operations** — enter selection mode to check multiple models; bulk action bar supports add/remove from groups and permanent file deletion (model file + preview images + sidecar files such as `.json` / `.info`)
### AI Tab (A) (v0.3.13)
- **Translation sub-tab** — translate text between Japanese, English, Chinese, or a custom Free language using Ollama or LM Studio; language selectors with ⇄ swap button (swaps both language and text content); selections saved automatically
- **VLM sub-tab** — drop an image into the 110px drop zone, select a task (Describe Image / Create Prompt), and click Run to analyze with a vision model; result shown in the output area with a Copy button
- **Settings sub-tab** — choose backend (Ollama / LM Studio), set the API URL, test connection, select a model (with refresh button), and configure Free language names for translation source and destination
- **Settings shared** — settings saved to `localStorage` under `wfm_ai_settings`; shared with the Library panel's A tab so configuration is consistent across both interfaces
- **Backend support** — Ollama (`/api/generate` for text, `/api/tags` for model list); LM Studio OpenAI-compatible API (`/v1/chat/completions`, `/v1/models`); VLM images sent as base64 (`images:[]` for Ollama, `image_url` content block for LM Studio)
- **URL security** — backend URL validated via `new URL()` to enforce `http://` or `https://` scheme
### Workflow Studio Library (ComfyUI Side Panel) (v0.3.9)
- **Tab layout (W / N / P / M / I)** — compact single-letter tabs with full name shown on hover
- **Tab layout (W / N / P / M / I / A)** — compact single-letter tabs with full name shown on hover
- **W — Workflows tab** — browse favorite workflows (All / ★ Favorites / Groups / By Badge sub-tabs), ★ star shown for favorites in All view
- **N — Nodes tab** — browse favorite nodes (All / ★ Favorites / Groups / Sets / 📂 Category / 🧩 Package sub-tabs), ★ star shown for favorites in All view
- **Category sub-tab** — dropdown to filter nodes by top-level category
@@ -164,6 +165,7 @@ Requires the **[comfyui-image-feeder](https://github.com/ketle-man/comfyui-image
- **M — Models tab** — browse installed models (All / ★ Favorites / Groups / By Type sub-tabs)
- **P — Prompts tab** — browse prompt presets with All / Favorites / Categories sub-tabs
- **I — Information tab** — drop a ComfyUI-generated PNG/WebP or workflow JSON in the side panel to view its metadata; supports `UnetLoaderGGUF` and `QuadrupleCLIPLoader` node types; preview area fixed at 110px
- **A — AI Tools tab** — Translation sub-tab and VLM sub-tab powered by Ollama or LM Studio; settings (backend, URL, model) shared with the SPA AI tab via `localStorage`
- **model sub-tab** — Checkpoint, VAE, Diffusion Model, and Text Encoder; drag items to canvas to place the corresponding loader node (Checkpoint → `CheckpointLoaderSimple`, VAE → `VAELoader`, Diffusion Model → `UNETLoader`, Text Encoder → `CLIPLoader`); double-click also places at canvas center
- **lora sub-tab** — LoRA names with `strength_model / strength_clip` values; drag individual LoRA to place `LoraLoader`; **Multiple LORA** section (appears for 1+ LoRAs) drags all LoRAs into a single `Lora Loader (LoraManager)` node
- **Prompts sub-tab** — POS / NEG badge list; drag a prompt to place `CLIPTextEncode` with text pre-filled; click any entry to view full text + Copy button
@@ -233,7 +235,8 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
### Optional
- **[Ollama](https://ollama.com/)** — for AI chat assistant and translation features
- **[Ollama](https://ollama.com/)** — for AI chat assistant, translation, and VLM features
- **[LM Studio](https://lmstudio.ai/)** — alternative backend for translation and VLM (OpenAI-compatible API)
- **[Eagle](https://eagle.cool/)** — for auto-saving generated images with metadata
---
@@ -250,6 +253,24 @@ Click the **camera icon** (next to the W button) in ComfyUI's top bar to capture
## Changelog
### v0.3.13
- **AI Tab (A)** — new tab added to both the SPA and the Workflow Studio Library side panel (rightmost tab)
- **Translation sub-tab** — translate text via Ollama or LM Studio between Japanese, English, Chinese, or a custom Free language; ⇄ swap button exchanges both language selectors and text content simultaneously; language selections persisted automatically
- **VLM sub-tab** — drop zone (110px, matching the I tab) accepts images via drag & drop or click; task selector (Describe Image / Create Prompt); Run button streams result into output area with Copy button; Ollama uses `images:[base64]` payload, LM Studio uses `image_url` content block
- **Settings sub-tab** — backend radio (Ollama / LM Studio), API URL input, connection test with live status, model selector with refresh, Free language name fields (source and destination); saved to `localStorage` key `wfm_ai_settings` and shared between SPA and Library panel
- **URL security** — backend URL validated via `new URL()` to enforce `http://` or `https://` scheme before any network call
- **Settings Tab — Ollama section renamed** — "Ollama 設定" → "Ollama 設定(プロンプトタブ)" to distinguish it from the new AI tab's settings
- **Help Tab updated** — added AI Tab (A) feature card and Library panel A tab entry; i18n support in EN/JA/ZH
### v0.3.12
- **GenerateUI — Raw JSON search** — always-visible search bar above the Raw JSON editor; finds all matches as you type with match count (`3/12`); navigate forward/back with ↑/↓ buttons, Enter / Shift+Enter, or Escape / ✕ to clear; current match highlighted in orange, other matches in yellow; search overlay syncs with editor scroll and stays updated while editing
- **Workflow analyzer — extended model type detection** — added CLIPLoader `type` field mapping to model family (`flux`, `hidream_i`, `wan`, `cosmos`, `lumina`, `ovis`, etc.) via `_CLIP_TYPE_TO_MODEL`; subgraph nodes (`definitions.subgraphs`) now scanned for model detection; `UnetLoaderGGUF` and similar loaders matched via `"UnetLoader" in ntype`; new families added: NewBie, Ovis, HiDream, Wan, Cosmos, Lumina; model-name detection refactored into reusable `_detect_model_type_from_name()`
- **Screenshots refreshed** — replaced tab-by-tab screenshots with 8 feature-focused images
### v0.3.11
- **Metadata Tab — extended loader support** — `metadata-tab.js` now recognizes `UnetLoaderGGUF` and `UNETLoaderGGUF` as Diffusion Model (e.g. HiDream GGUF workflows), and `QuadrupleCLIPLoader` as Text Encoder (e.g. HiDream 4-CLIP); previously these were detected only in the side panel I tab, not in the Metadata tab itself
- **Settings Tab — Text Size** — new slider (10–28 px) in the Settings tab adjusts font size for all prompt and chat text areas at once: Generate UI positive/negative prompts, AI Assistant chat input, Preset prompts, Wildcard text area and file editor, and Metadata prompt full preview; applied immediately on drag and persisted with Save Settings
### v0.3.10
- **Information tab — drag to canvas** — model, lora, and Prompts sub-tabs in the side panel I tab now support drag & drop onto the ComfyUI canvas; double-click also places nodes at canvas center
- model sub-tab: each item places the corresponding loader node (Checkpoint → `CheckpointLoaderSimple`, VAE → `VAELoader`, Diffusion Model → `UNETLoader`, Text Encoder → `CLIPLoader`)
@@ -444,7 +465,7 @@ ComfyUI-Workflow-Studio/
│ ├── settings_service.py # Settings persistence
│ └── png_extractor.py # PNG metadata extraction
├── templates/
│ └── index.html # SPA template (Workflow/GenerateUI/Prompt/Metadata/Gallery/Nodes/Models/Settings/Help)
│ └── index.html # SPA template (Workflow/GenerateUI/Prompt/Metadata/Gallery/Nodes/Models/Settings/Help/AI)
├── static/
│ ├── favicon.svg # Browser tab icon (W+S Wave)
│ ├── css/main.css # Styles
@@ -459,6 +480,7 @@ ComfyUI-Workflow-Studio/
│ ├── comfyui-client.js # ComfyUI WebSocket/API client
│ ├── nodes-tab.js # Node browser & node sets
│ ├── models-tab.js # Model browser & CivitAI integration
│ ├── ai-tab.js # AI tab (Translation, VLM, Settings — Ollama / LM Studio)
│ ├── comfyui-workflow.js # UI-to-API format conversion
│ ├── comfyui-editor.js # Dynamic parameter editor
│ ├── json-highlight.js # JSON syntax highlighting
Binary file not shown.

After

Width:  |  Height:  |  Size: 330 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 116 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 975 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

+101 -20
View File
@@ -3,6 +3,23 @@
import os
import re
# CLIPLoader / DualCLIPLoader の type フィールド → モデル種別マッピング
_CLIP_TYPE_TO_MODEL = {
"flux": "Flux",
"flux2": "Flux2",
"newbie": "NewBie",
"ovis": "Ovis",
"qwen_image": "Qwen",
"sd3": "SD3",
"sd3.5": "SD3",
"hidream_i": "HiDream",
"hidream_e": "HiDream",
"hidream": "HiDream",
"wan": "Wan",
"cosmos": "Cosmos",
"lumina": "Lumina",
}
def _model_name_from_ui_node(node):
"""Extract model filename from UI format node (lowercase)."""
@@ -11,16 +28,65 @@ def _model_name_from_ui_node(node):
return val.lower() if isinstance(val, str) else ""
def _clip_type_from_ui_node(node):
"""Extract CLIPLoader type string from widgets_values (lowercase)."""
ntype = node.get("type", "")
vals = node.get("widgets_values", [])
if ntype == "CLIPLoader" and len(vals) > 1:
return str(vals[1]).lower() if isinstance(vals[1], str) else ""
if ntype in ("DualCLIPLoader", "TripleCLIPLoader") and len(vals) > 2:
return str(vals[2]).lower() if isinstance(vals[2], str) else ""
return ""
def _model_name_from_api_node(node):
"""Extract model filename from API format node (lowercase)."""
inputs = node.get("inputs", {})
for key in ("ckpt_name", "unet_name", "model_name"):
for key in ("ckpt_name", "unet_name", "model_name", "clip_name1", "clip_name"):
val = inputs.get(key, "")
if isinstance(val, str) and val:
return val.lower()
return ""
def _collect_all_ui_nodes(workflow_data):
"""Yield all UI-format nodes including those inside definitions.subgraphs."""
for node in workflow_data.get("nodes", []):
yield node
defs = workflow_data.get("definitions", {})
if isinstance(defs, dict):
for sg in defs.get("subgraphs", []):
if isinstance(sg, dict):
for node in sg.get("nodes", []):
yield node
def _detect_model_type_from_name(mn_base, model_types):
"""Detect model type from a model filename (already lowercased basename)."""
if re.search(r"sd1[._-]?5|v1[._-]5", mn_base):
model_types.add("SD1.5")
elif re.search(r"sdxl|[._-]xl[._-]|[._-]xl$|xl[._-]", mn_base):
model_types.add("SDXL")
elif re.search(r"flux[-_.]?2", mn_base):
model_types.add("Flux2")
elif "flux" in mn_base:
model_types.add("Flux")
elif re.search(r"sd[._-]?3", mn_base):
model_types.add("SD3")
elif "qwen" in mn_base:
model_types.add("Qwen")
elif "zimage" in mn_base or "z-image" in mn_base or "zit" in mn_base:
model_types.add("Z-IMAGE")
elif "newbie" in mn_base:
model_types.add("NewBie")
elif "ovis" in mn_base:
model_types.add("Ovis")
elif "hidream" in mn_base:
model_types.add("HiDream")
elif "wan" in mn_base and re.search(r"wan[-_.]?\d|wan[-_]video", mn_base):
model_types.add("Wan")
def analyze_workflow(workflow_data, filename=""):
"""Analyze workflow JSON and return model types, input/output node counts."""
model_types = set()
@@ -36,23 +102,33 @@ def analyze_workflow(workflow_data, filename=""):
model_types.add("Qwen")
if "zimage" in fn or "z-image" in fn or "zit" in fn:
model_types.add("Z-IMAGE")
if "flux2" in fn:
if re.search(r"flux[-_.]?2", fn):
model_types.add("Flux2")
elif "flux" in fn:
model_types.add("Flux")
if "sd3" in fn:
model_types.add("SD3")
if "newbie" in fn:
model_types.add("NewBie")
if "ovis" in fn:
model_types.add("Ovis")
if "hidream" in fn:
model_types.add("HiDream")
if "wan" in fn and re.search(r"wan[-_.]?\d|wan[-_]video", fn):
model_types.add("Wan")
# Support both UI format (nodes array) and API format (node ID object)
raw_nodes = workflow_data.get("nodes", None)
if raw_nodes is not None:
# UI / app format: collect all nodes including subgraph definitions
node_iter = [
(
node.get("type", ""),
node.get("title", "").lower(),
_model_name_from_ui_node(node),
_clip_type_from_ui_node(node),
)
for node in raw_nodes
for node in _collect_all_ui_nodes(workflow_data)
]
else:
node_iter = []
@@ -62,33 +138,32 @@ def analyze_workflow(workflow_data, filename=""):
ntype = node.get("class_type", "")
title = node.get("_meta", {}).get("title", "").lower()
mn = _model_name_from_api_node(node)
node_iter.append((ntype, title, mn))
node_iter.append((ntype, title, mn, ""))
for ntype, title, mn in node_iter:
for ntype, title, mn, clip_type in node_iter:
if (
"CheckpointLoader" in ntype
or "UNETLoader" in ntype
or "UnetLoader" in ntype # UnetLoaderGGUF 等を含む
or "unet_name" in ntype
):
mn_base = os.path.basename(mn.replace("\\", "/"))
if re.search(r"sd1[._-]?5|v1[._-]5", mn_base):
model_types.add("SD1.5")
elif re.search(r"sdxl|[._-]xl[._-]|[._-]xl$|xl[._-]", mn_base):
model_types.add("SDXL")
elif "flux2" in mn_base:
model_types.add("Flux2")
elif "flux" in mn_base:
model_types.add("Flux")
elif re.search(r"sd[._-]?3", mn_base):
model_types.add("SD3")
elif "qwen" in mn_base:
model_types.add("Qwen")
elif "zimage" in mn_base or "z-image" in mn_base or "zit" in mn_base:
model_types.add("Z-IMAGE")
_detect_model_type_from_name(mn_base, model_types)
# CLIPLoader 系: type フィールドまたはファイル名からモデル種別を検出
# QuadrupleCLIPLoader 等、type フィールドを持たない新型ローダーにも対応
if "CLIPLoader" in ntype:
if clip_type:
detected = _CLIP_TYPE_TO_MODEL.get(clip_type)
if detected:
model_types.add(detected)
mn_base = os.path.basename(mn.replace("\\", "/"))
if mn_base:
_detect_model_type_from_name(mn_base, model_types)
if "sdxl" in title:
model_types.add("SDXL")
if "flux2" in title:
if re.search(r"flux[-_.]?2", title):
model_types.add("Flux2")
elif "flux" in title:
model_types.add("Flux")
@@ -98,6 +173,12 @@ def analyze_workflow(workflow_data, filename=""):
model_types.add("Qwen")
if "zimage" in title or "z-image" in title or "zit" in title:
model_types.add("Z-IMAGE")
if "newbie" in title:
model_types.add("NewBie")
if "ovis" in title:
model_types.add("Ovis")
if "hidream" in title:
model_types.add("HiDream")
if ntype == "CLIPTextEncode" or "prompt" in title:
inputs["prompts"] += 1
+361 -1
View File
@@ -677,6 +677,69 @@ body {
height: auto !important;
}
/* RAW JSON search bar */
.wfm-rawjson-search {
display: flex;
align-items: center;
gap: 4px;
padding: 4px 8px;
background: var(--wfm-bg-secondary);
border-bottom: 1px solid var(--wfm-border);
flex-shrink: 0;
}
.wfm-rawjson-search-input {
flex: 1;
height: 22px;
padding: 0 6px;
background: var(--wfm-bg);
border: 1px solid var(--wfm-border);
border-radius: 3px;
color: var(--wfm-text);
font-size: 12px;
outline: none;
min-width: 0;
}
.wfm-rawjson-search-input:focus {
border-color: var(--wfm-accent);
}
.wfm-rawjson-search-count {
font-size: 11px;
color: var(--wfm-text-secondary);
white-space: nowrap;
min-width: 56px;
text-align: center;
}
.wfm-rawjson-search-btn {
width: 22px;
height: 22px;
padding: 0;
background: transparent;
border: 1px solid transparent;
border-radius: 3px;
color: var(--wfm-text-secondary);
font-size: 13px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
line-height: 1;
}
.wfm-rawjson-search-btn:hover {
background: rgba(255, 255, 255, 0.08);
border-color: var(--wfm-border);
color: var(--wfm-text);
}
.wfm-rawjson-search-clear {
font-size: 14px;
}
.wfm-gen-col-title {
font-size: 12px;
font-weight: 600;
@@ -1334,8 +1397,27 @@ body {
pointer-events: none;
}
.wfm-json-editor {
/* Search match overlay: transparent text, mark backgrounds only */
.wfm-json-search-overlay {
z-index: 2;
color: transparent !important;
}
.wfm-json-search-overlay mark.wfm-search-match {
background: rgba(234, 201, 70, 0.35);
color: transparent;
border-radius: 2px;
}
.wfm-json-search-overlay mark.wfm-search-current {
background: rgba(255, 150, 0, 0.65);
color: transparent;
border-radius: 2px;
outline: 1px solid rgba(255, 150, 0, 0.9);
}
.wfm-json-editor {
z-index: 3;
color: transparent;
caret-color: #ffffff;
outline: none;
@@ -4359,3 +4441,281 @@ body {
padding-top: 5px;
margin-top: 2px;
}
/* ============================================
AI Tab
============================================ */
#wfm-tab-ai {
display: none;
flex-direction: column;
height: 100%;
overflow: hidden;
}
#wfm-tab-ai.active {
display: flex;
}
/* Sub-tab navigation */
.wfm-ai-subtab-nav {
display: flex;
border-bottom: 1px solid var(--wfm-border);
flex-shrink: 0;
background: var(--wfm-surface);
}
.wfm-ai-subtab-btn {
flex: 1;
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-ai-subtab-btn:hover {
color: var(--wfm-text);
}
.wfm-ai-subtab-btn.active {
color: var(--wfm-text);
border-bottom-color: var(--wfm-primary);
font-weight: 600;
}
/* Sub-tab content */
.wfm-ai-subtab-content {
flex: 1;
display: none;
flex-direction: column;
overflow: hidden;
min-height: 0;
}
/* Translation tab */
.wfm-ai-trans-container {
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px;
flex: 1;
overflow: hidden;
min-height: 0;
}
.wfm-ai-trans-lang-row {
display: flex;
align-items: center;
gap: 8px;
}
.wfm-ai-lang-select {
flex: 1;
}
.wfm-ai-swap-btn {
flex-shrink: 0;
padding: 6px 10px;
font-size: 16px;
}
.wfm-ai-trans-textarea {
flex: 1;
min-height: 120px;
padding: 8px 10px;
background: var(--wfm-bg);
border: 1px solid var(--wfm-border);
border-radius: var(--wfm-radius-sm);
color: var(--wfm-text);
font-size: 13px;
font-family: inherit;
resize: none;
line-height: 1.5;
transition: border-color 0.15s;
}
.wfm-ai-trans-textarea:focus {
outline: none;
border-color: var(--wfm-primary);
}
.wfm-ai-trans-output {
background: var(--wfm-bg-secondary);
color: var(--wfm-text-secondary);
}
.wfm-ai-trans-output:focus {
border-color: var(--wfm-border);
}
.wfm-ai-trans-actions {
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.wfm-ai-trans-status {
font-size: 12px;
margin-left: 4px;
}
.wfm-ai-status-working { color: var(--wfm-warning); }
.wfm-ai-status-ok { color: var(--wfm-success); }
.wfm-ai-status-error { color: var(--wfm-danger); }
/* VLM placeholder */
.wfm-ai-placeholder-msg {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
color: var(--wfm-text-secondary);
font-size: 14px;
padding: 24px;
}
/* Settings tab */
.wfm-ai-settings-container {
display: flex;
flex-direction: column;
gap: 0;
padding: 12px;
overflow-y: auto;
flex: 1;
}
.wfm-ai-settings-section {
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px 0;
border-bottom: 1px solid var(--wfm-border);
}
.wfm-ai-settings-section:last-child {
border-bottom: none;
}
.wfm-ai-settings-title {
font-size: 12px;
font-weight: 600;
color: var(--wfm-text-secondary);
text-transform: uppercase;
letter-spacing: 0.05em;
}
.wfm-ai-settings-row {
display: flex;
align-items: center;
gap: 8px;
}
.wfm-ai-backend-row {
display: flex;
gap: 16px;
}
.wfm-ai-radio-label {
display: flex;
align-items: center;
gap: 6px;
cursor: pointer;
font-size: 13px;
color: var(--wfm-text);
}
.wfm-ai-label {
font-size: 12px;
color: var(--wfm-text-secondary);
white-space: nowrap;
width: 60px;
flex-shrink: 0;
}
.wfm-ai-url-input {
flex: 1;
}
.wfm-ai-model-select {
flex: 1;
}
.wfm-ai-test-result {
font-size: 12px;
margin-left: 4px;
}
/* VLM Tab */
.wfm-ai-vlm-container {
display: flex;
flex-direction: column;
gap: 8px;
padding: 12px;
flex: 1;
overflow: hidden;
min-height: 0;
}
.wfm-ai-vlm-drop {
height: 110px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
border: 2px dashed var(--wfm-border);
border-radius: var(--wfm-radius-sm);
background: var(--wfm-bg);
cursor: pointer;
overflow: hidden;
transition: border-color 0.15s, background 0.15s;
position: relative;
}
.wfm-ai-vlm-drop:hover,
.wfm-ai-vlm-drop.drag-over {
border-color: var(--wfm-primary);
background: rgba(74, 158, 255, 0.05);
}
.wfm-ai-vlm-label {
font-size: 12px;
color: var(--wfm-text-secondary);
pointer-events: none;
}
.wfm-ai-vlm-task-row {
display: flex;
align-items: center;
gap: 8px;
flex-shrink: 0;
}
.wfm-ai-vlm-task-row .wfm-select {
flex: 1;
}
.wfm-ai-vlm-result {
flex: 1;
min-height: 80px;
padding: 8px 10px;
background: var(--wfm-bg-secondary);
border: 1px solid var(--wfm-border);
border-radius: var(--wfm-radius-sm);
color: var(--wfm-text-secondary);
font-size: 13px;
font-family: inherit;
resize: none;
outline: none;
line-height: 1.5;
box-sizing: border-box;
}
.wfm-ai-vlm-copy-btn {
align-self: flex-end;
flex-shrink: 0;
}
+477
View File
@@ -0,0 +1,477 @@
/**
* AI Tab - Translation, VLM, Settings
* Supports Ollama and LM Studio as backends
*/
import { showToast } from "./app.js";
import { t } from "./i18n.js";
const SETTINGS_KEY = "wfm_ai_settings";
const LANG_NAMES = {
ja: "Japanese",
en: "English",
zh: "Chinese",
};
// ============================================
// Settings persistence
// ============================================
function loadAiSettings() {
try {
return JSON.parse(localStorage.getItem(SETTINGS_KEY) || "{}");
} catch {
return {};
}
}
function saveAiSettings(patch) {
const data = { ...loadAiSettings(), ...patch };
localStorage.setItem(SETTINGS_KEY, JSON.stringify(data));
return data;
}
const VLM_PROMPTS = {
describe: "Describe this image in detail.",
prompt: "Create a detailed Stable Diffusion image generation prompt based on this image. Output only the prompt text, nothing else.",
};
function fileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = e => {
const b64 = e.target.result.split(",")[1];
resolve({ base64: b64, mimeType: file.type });
};
reader.onerror = reject;
reader.readAsDataURL(file);
});
}
async function callVLM(url, backend, model, prompt, base64Image, mimeType) {
if (backend === "ollama") {
const res = await fetch(`${url}/api/generate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, prompt, images: [base64Image], stream: false }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return (await res.json()).response || "";
} else {
const res = await fetch(`${url}/v1/chat/completions`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model,
messages: [{ role: "user", content: [
{ type: "text", text: prompt },
{ type: "image_url", image_url: { url: `data:${mimeType};base64,${base64Image}` } },
]}],
stream: false,
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return (await res.json()).choices?.[0]?.message?.content || "";
}
}
// ============================================
// URL validation
// ============================================
function isValidBackendUrl(url) {
try {
const u = new URL(url);
return u.protocol === "http:" || u.protocol === "https:";
} catch {
return false;
}
}
// ============================================
// API helpers
// ============================================
async function fetchModels(url, backend) {
if (backend === "ollama") {
const res = await fetch(`${url}/api/tags`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return (data.models || []).map((m) => m.name);
} else {
// LM Studio (OpenAI-compatible)
const res = await fetch(`${url}/v1/models`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return (data.data || []).map((m) => m.id);
}
}
async function testConnection(url, backend) {
const models = await fetchModels(url, backend);
return models.length;
}
async function callLLM(url, backend, model, prompt) {
if (backend === "ollama") {
const res = await fetch(`${url}/api/generate`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, prompt, stream: false }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return data.response || "";
} else {
// LM Studio (OpenAI-compatible)
const res = await fetch(`${url}/v1/chat/completions`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model,
messages: [{ role: "user", content: prompt }],
stream: false,
}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
return data.choices?.[0]?.message?.content || "";
}
}
// ============================================
// Translation prompt builder
// ============================================
function buildTranslationPrompt(text, srcLang, dstLang, settings) {
const srcName = srcLang === "free" ? (settings.freeSrcLang || "Auto") : LANG_NAMES[srcLang];
const dstName = dstLang === "free" ? (settings.freeDstLang || "English") : LANG_NAMES[dstLang];
const fromPart = srcLang === "free" ? "" : `from ${srcName} `;
return `Translate the following text ${fromPart}to ${dstName}. Output only the translated text, nothing else.\n\n${text}`;
}
// ============================================
// Sub-tab switching
// ============================================
function initSubTabs() {
document.querySelectorAll(".wfm-ai-subtab-btn").forEach((btn) => {
btn.addEventListener("click", () => {
document.querySelectorAll(".wfm-ai-subtab-btn").forEach((b) => b.classList.remove("active"));
btn.classList.add("active");
const tabId = btn.dataset.aiSubtab;
document.querySelectorAll(".wfm-ai-subtab-content").forEach((c) => {
c.style.display = "none";
});
const target = document.getElementById(`wfm-ai-subtab-${tabId}`);
if (target) target.style.display = "flex";
});
});
// Show first sub-tab on init
const first = document.getElementById("wfm-ai-subtab-translate");
if (first) first.style.display = "flex";
}
// ============================================
// Translation tab
// ============================================
function initTranslateTab() {
const srcLangSel = document.getElementById("wfm-ai-src-lang");
const dstLangSel = document.getElementById("wfm-ai-dst-lang");
const swapBtn = document.getElementById("wfm-ai-trans-swap-btn");
const inputEl = document.getElementById("wfm-ai-trans-input");
const outputEl = document.getElementById("wfm-ai-trans-output");
const transBtn = document.getElementById("wfm-ai-trans-btn");
const copyBtn = document.getElementById("wfm-ai-trans-copy-btn");
const statusEl = document.getElementById("wfm-ai-trans-status");
if (!transBtn) return;
// Restore saved language selections
const saved = loadAiSettings();
if (saved.srcLang && srcLangSel) srcLangSel.value = saved.srcLang;
if (saved.dstLang && dstLangSel) dstLangSel.value = saved.dstLang;
// Persist language selections
srcLangSel?.addEventListener("change", () => saveAiSettings({ srcLang: srcLangSel.value }));
dstLangSel?.addEventListener("change", () => saveAiSettings({ dstLang: dstLangSel.value }));
// Swap languages
swapBtn?.addEventListener("click", () => {
const tmp = srcLangSel.value;
srcLangSel.value = dstLangSel.value;
dstLangSel.value = tmp;
saveAiSettings({ srcLang: srcLangSel.value, dstLang: dstLangSel.value });
// Swap text content too
const tmpText = inputEl.value;
inputEl.value = outputEl.value;
outputEl.value = tmpText;
});
// Translate
transBtn.addEventListener("click", async () => {
const text = inputEl.value.trim();
if (!text) {
showToast(t("aiToastNoText"), "error");
return;
}
const settings = loadAiSettings();
const { backend = "ollama", backendUrl, model } = settings;
const url = backendUrl || (backend === "ollama" ? "http://localhost:11434" : "http://localhost:1234");
if (!isValidBackendUrl(url)) {
showToast(t("aiToastInvalidUrl"), "error");
return;
}
if (!model) {
showToast(t("aiToastNoModel"), "error");
return;
}
transBtn.disabled = true;
statusEl.textContent = t("aiStatusTranslating");
statusEl.className = "wfm-ai-trans-status wfm-ai-status-working";
outputEl.value = "";
try {
const prompt = buildTranslationPrompt(text, srcLangSel.value, dstLangSel.value, settings);
const result = await callLLM(url, backend, model, prompt);
outputEl.value = result.trim();
statusEl.textContent = t("aiStatusDone");
statusEl.className = "wfm-ai-trans-status wfm-ai-status-ok";
} catch (err) {
statusEl.textContent = `${t("aiStatusConnectFail")}${err.message}`;
statusEl.className = "wfm-ai-trans-status wfm-ai-status-error";
showToast(t("aiToastTransFailed") + err.message, "error");
} finally {
transBtn.disabled = false;
}
});
// Copy translated text
copyBtn?.addEventListener("click", () => {
const text = outputEl.value;
if (!text) {
showToast(t("aiToastNoCopyText"), "error");
return;
}
navigator.clipboard.writeText(text).then(() => {
showToast(t("aiToastCopied"), "success");
});
});
}
// ============================================
// Settings tab
// ============================================
async function refreshModels() {
const settings = loadAiSettings();
const backend = document.querySelector("input[name='wfm-ai-backend']:checked")?.value || "ollama";
const url = document.getElementById("wfm-ai-backend-url")?.value?.trim() || "";
const modelSel = document.getElementById("wfm-ai-model-select");
const refreshBtn = document.getElementById("wfm-ai-model-refresh-btn");
if (!modelSel) return;
if (refreshBtn) refreshBtn.disabled = true;
try {
const models = await fetchModels(url, backend);
modelSel.innerHTML = `<option value="">-- ${t("aiSettingsModelPlaceholder")} --</option>`;
models.forEach((name) => {
const opt = document.createElement("option");
opt.value = name;
opt.textContent = name;
if (name === settings.model) opt.selected = true;
modelSel.appendChild(opt);
});
if (models.length === 0) showToast(t("aiToastNoModels"), "error");
} catch (err) {
showToast(t("aiToastModelsFailed") + err.message, "error");
} finally {
if (refreshBtn) refreshBtn.disabled = false;
}
}
function initSettingsTab() {
const saved = loadAiSettings();
// Restore saved values
const backendRadios = document.querySelectorAll("input[name='wfm-ai-backend']");
backendRadios.forEach((r) => {
if (r.value === (saved.backend || "ollama")) r.checked = true;
});
const urlInput = document.getElementById("wfm-ai-backend-url");
if (urlInput && saved.backendUrl) urlInput.value = saved.backendUrl;
// Update URL placeholder when backend changes
backendRadios.forEach((r) => {
r.addEventListener("change", () => {
if (!urlInput) return;
const defaultUrl = r.value === "ollama" ? "http://localhost:11434" : "http://localhost:1234";
if (!saved.backendUrl) urlInput.value = defaultUrl;
});
});
// Connection test
document.getElementById("wfm-ai-test-btn")?.addEventListener("click", async () => {
const testBtn = document.getElementById("wfm-ai-test-btn");
const resultEl = document.getElementById("wfm-ai-test-result");
const backend = document.querySelector("input[name='wfm-ai-backend']:checked")?.value || "ollama";
const url = urlInput?.value?.trim() || "";
if (!isValidBackendUrl(url)) {
if (resultEl) {
resultEl.textContent = t("aiToastInvalidUrlInput");
resultEl.className = "wfm-ai-test-result wfm-ai-status-error";
}
return;
}
if (testBtn) testBtn.disabled = true;
if (resultEl) {
resultEl.textContent = t("aiStatusConnecting");
resultEl.className = "wfm-ai-test-result wfm-ai-status-working";
}
try {
const count = await testConnection(url, backend);
if (resultEl) {
resultEl.textContent = `${t("aiStatusConnectOk")} (${count} ${t("aiModels")})`;
resultEl.className = "wfm-ai-test-result wfm-ai-status-ok";
}
await refreshModels();
} catch (err) {
if (resultEl) {
resultEl.textContent = `${t("aiStatusConnectFail")}${err.message}`;
resultEl.className = "wfm-ai-test-result wfm-ai-status-error";
}
} finally {
if (testBtn) testBtn.disabled = false;
}
});
// Model refresh
document.getElementById("wfm-ai-model-refresh-btn")?.addEventListener("click", () => refreshModels());
// Free language inputs
const freeSrcInput = document.getElementById("wfm-ai-free-src-lang");
const freeDstInput = document.getElementById("wfm-ai-free-dst-lang");
if (freeSrcInput && saved.freeSrcLang) freeSrcInput.value = saved.freeSrcLang;
if (freeDstInput && saved.freeDstLang) freeDstInput.value = saved.freeDstLang;
// Save settings
document.getElementById("wfm-ai-settings-save-btn")?.addEventListener("click", () => {
const backend = document.querySelector("input[name='wfm-ai-backend']:checked")?.value || "ollama";
const url = urlInput?.value?.trim() || "";
const model = document.getElementById("wfm-ai-model-select")?.value || "";
const freeSrcLang = freeSrcInput?.value?.trim() || "";
const freeDstLang = freeDstInput?.value?.trim() || "";
if (url && !isValidBackendUrl(url)) {
showToast(t("aiToastInvalidUrl"), "error");
return;
}
saveAiSettings({ backend, backendUrl: url, model, freeSrcLang, freeDstLang });
showToast(t("aiToastSettingsSaved"), "success");
});
// Load models on init if settings exist
if (saved.backendUrl && saved.backend) {
refreshModels().catch(() => {});
}
}
// ============================================
// VLM tab
// ============================================
function initVlmTab() {
const dropEl = document.getElementById("wfm-ai-vlm-drop");
const previewEl = document.getElementById("wfm-ai-vlm-preview");
const labelEl = document.getElementById("wfm-ai-vlm-label");
const fileInput = document.getElementById("wfm-ai-vlm-file");
const taskSel = document.getElementById("wfm-ai-vlm-task");
const runBtn = document.getElementById("wfm-ai-vlm-run");
const statusEl = document.getElementById("wfm-ai-vlm-status");
const resultEl = document.getElementById("wfm-ai-vlm-result");
const copyBtn = document.getElementById("wfm-ai-vlm-copy");
if (!dropEl) return;
let vlmImage = null; // { base64, mimeType }
const loadImage = async (file) => {
if (!file || !file.type.startsWith("image/")) return;
vlmImage = await fileToBase64(file);
previewEl.src = `data:${vlmImage.mimeType};base64,${vlmImage.base64}`;
previewEl.style.display = "block";
labelEl.style.display = "none";
};
dropEl.addEventListener("click", () => fileInput.click());
fileInput.addEventListener("change", e => { if (e.target.files[0]) loadImage(e.target.files[0]); });
dropEl.addEventListener("dragover", e => { e.preventDefault(); dropEl.classList.add("drag-over"); });
dropEl.addEventListener("dragleave", () => dropEl.classList.remove("drag-over"));
dropEl.addEventListener("drop", e => {
e.preventDefault();
dropEl.classList.remove("drag-over");
if (e.dataTransfer.files[0]) loadImage(e.dataTransfer.files[0]);
});
runBtn.addEventListener("click", async () => {
if (!vlmImage) { showToast(t("aiToastNoImage"), "error"); return; }
const settings = loadAiSettings();
const { backend = "ollama", backendUrl, model } = settings;
const url = backendUrl || (backend === "ollama" ? "http://localhost:11434" : "http://localhost:1234");
if (!isValidBackendUrl(url)) {
showToast(t("aiToastInvalidUrl"), "error");
return;
}
if (!model) { showToast(t("aiToastNoModel"), "error"); return; }
const task = taskSel?.value || "describe";
runBtn.disabled = true;
statusEl.textContent = t("aiStatusRunning");
statusEl.className = "wfm-ai-trans-status wfm-ai-status-working";
resultEl.value = "";
try {
const result = await callVLM(url, backend, model, VLM_PROMPTS[task], vlmImage.base64, vlmImage.mimeType);
resultEl.value = result.trim();
statusEl.textContent = t("aiStatusDone");
statusEl.className = "wfm-ai-trans-status wfm-ai-status-ok";
} catch (err) {
statusEl.textContent = `${t("aiStatusConnectFail")}${err.message}`;
statusEl.className = "wfm-ai-trans-status wfm-ai-status-error";
showToast(t("aiToastVlmFailed") + err.message, "error");
} finally {
runBtn.disabled = false;
}
});
copyBtn.addEventListener("click", () => {
const text = resultEl.value;
if (!text) { showToast(t("aiToastNoCopyText"), "error"); return; }
navigator.clipboard.writeText(text).then(() => showToast(t("aiToastCopied"), "success"));
});
}
// ============================================
// Export
// ============================================
export function initAiTab() {
initSubTabs();
initTranslateTab();
initVlmTab();
initSettingsTab();
}
+75 -2
View File
@@ -90,7 +90,7 @@ function initTabs() {
function applyI18nToHtml() {
// Tab labels
const tabMap = { workflow: "tabWorkflow", nodes: "tabNodes", models: "tabModels", generate: "tabGenerate", prompt: "tabPrompt", metadata: "tabMetadata", gallery: "tabGallery", settings: "tabSettings", help: "tabHelp" };
const tabMap = { workflow: "tabWorkflow", nodes: "tabNodes", models: "tabModels", generate: "tabGenerate", prompt: "tabPrompt", metadata: "tabMetadata", gallery: "tabGallery", settings: "tabSettings", help: "tabHelp", ai: "tabAi" };
document.querySelectorAll(".wfm-tab").forEach((tab) => {
const key = tabMap[tab.dataset.tab];
if (key) tab.textContent = t(key);
@@ -224,6 +224,67 @@ function applyI18nToHtml() {
const presetCopyNegBtn = document.getElementById("wfm-preset-copy-neg-btn");
if (presetCopyNegBtn) presetCopyNegBtn.textContent = t("copyNegativePrompt");
// AI tab
document.querySelectorAll(".wfm-ai-subtab-btn").forEach(btn => {
if (btn.dataset.aiSubtab === "translate") btn.textContent = t("aiSubTabTranslate");
if (btn.dataset.aiSubtab === "vlm") btn.textContent = t("aiSubTabVlm");
if (btn.dataset.aiSubtab === "ai-settings") btn.textContent = t("aiSubTabSettings");
});
const aiLangMap = { ja: "aiLangJa", en: "aiLangEn", zh: "aiLangZh", free: "aiLangFree" };
[document.getElementById("wfm-ai-src-lang"), document.getElementById("wfm-ai-dst-lang")].forEach(sel => {
if (!sel) return;
sel.querySelectorAll("option").forEach(opt => {
const key = aiLangMap[opt.value];
if (key) opt.textContent = t(key);
});
});
const aiTransInput = document.getElementById("wfm-ai-trans-input");
if (aiTransInput) aiTransInput.placeholder = t("aiTransInputPlaceholder");
const aiTransOutput = document.getElementById("wfm-ai-trans-output");
if (aiTransOutput) aiTransOutput.placeholder = t("aiTransOutputPlaceholder");
const aiTransBtn = document.getElementById("wfm-ai-trans-btn");
if (aiTransBtn) aiTransBtn.textContent = t("aiTranslateBtn");
const aiTransCopyBtn = document.getElementById("wfm-ai-trans-copy-btn");
if (aiTransCopyBtn) aiTransCopyBtn.textContent = t("aiCopyBtn");
const aiVlmLabel = document.getElementById("wfm-ai-vlm-label");
if (aiVlmLabel) aiVlmLabel.textContent = t("aiVlmDropLabel");
const aiVlmTask = document.getElementById("wfm-ai-vlm-task");
if (aiVlmTask) {
aiVlmTask.querySelectorAll("option").forEach(opt => {
if (opt.value === "describe") opt.textContent = t("aiVlmDescribe");
if (opt.value === "prompt") opt.textContent = t("aiVlmPromptCreate");
});
}
const aiVlmRunBtn = document.getElementById("wfm-ai-vlm-run");
if (aiVlmRunBtn) aiVlmRunBtn.textContent = t("aiVlmRunBtn");
const aiVlmResult = document.getElementById("wfm-ai-vlm-result");
if (aiVlmResult) aiVlmResult.placeholder = t("aiVlmResultPlaceholder");
const aiVlmCopyBtn = document.getElementById("wfm-ai-vlm-copy");
if (aiVlmCopyBtn) aiVlmCopyBtn.textContent = t("aiCopyBtn");
const aiBackendTitle = document.getElementById("wfm-ai-settings-backend-title");
if (aiBackendTitle) aiBackendTitle.textContent = t("aiSettingsBackend");
const aiConnTitle = document.getElementById("wfm-ai-settings-conn-title");
if (aiConnTitle) aiConnTitle.textContent = t("aiSettingsConnection");
const aiTestBtn = document.getElementById("wfm-ai-test-btn");
if (aiTestBtn) aiTestBtn.textContent = t("aiSettingsTestBtn");
const aiModelTitle = document.getElementById("wfm-ai-settings-model-title");
if (aiModelTitle) aiModelTitle.textContent = t("aiSettingsModelSection");
const aiModelSel = document.getElementById("wfm-ai-model-select");
if (aiModelSel) {
const firstOpt = aiModelSel.querySelector("option[value='']");
if (firstOpt) firstOpt.textContent = t("aiSettingsModelPlaceholder");
}
const aiModelRefreshBtn = document.getElementById("wfm-ai-model-refresh-btn");
if (aiModelRefreshBtn) aiModelRefreshBtn.textContent = t("aiSettingsRefreshBtn");
const aiFreeLangTitle = document.getElementById("wfm-ai-settings-freelang-title");
if (aiFreeLangTitle) aiFreeLangTitle.textContent = t("aiSettingsFreeLang");
const aiFreeSrcLabel = document.getElementById("wfm-ai-free-src-label");
if (aiFreeSrcLabel) aiFreeSrcLabel.textContent = t("aiSettingsInputLang");
const aiFreeDstLabel = document.getElementById("wfm-ai-free-dst-label");
if (aiFreeDstLabel) aiFreeDstLabel.textContent = t("aiSettingsOutputLang");
const aiSaveBtn = document.getElementById("wfm-ai-settings-save-btn");
if (aiSaveBtn) aiSaveBtn.textContent = t("aiSettingsSaveBtn");
// Group panel labels
const propTitle = document.querySelector("#wfm-side-tab-group .wfm-group-section-title");
if (propTitle) propTitle.textContent = t("properties");
@@ -308,6 +369,10 @@ function applyI18nToHtml() {
"wfm-help-sidepanel-11": "helpSidepanel11", "wfm-help-sidepanel-12": "helpSidepanel12",
"wfm-help-sidepanel-13": "helpSidepanel13",
"wfm-help-sidepanel-14": "helpSidepanel14", "wfm-help-sidepanel-15": "helpSidepanel15",
"wfm-help-sidepanel-16": "helpSidepanel16",
"wfm-help-ai-title": "helpAiTitle",
"wfm-help-ai-1": "helpAi1", "wfm-help-ai-2": "helpAi2", "wfm-help-ai-3": "helpAi3",
"wfm-help-ai-4": "helpAi4", "wfm-help-ai-5": "helpAi5", "wfm-help-ai-6": "helpAi6",
"wfm-help-shortcuts-title": "helpShortcutsTitle",
"wfm-help-shortcuts-1": "helpShortcuts1", "wfm-help-shortcuts-2": "helpShortcuts2",
"wfm-help-shortcuts-3": "helpShortcuts3", "wfm-help-shortcuts-4": "helpShortcuts4",
@@ -361,14 +426,21 @@ import { initWorkflowTab } from "./workflow-tab.js";
import { initNodesTab } from "./nodes-tab.js";
import { initGenerateTab } from "./generate-tab.js";
import { initPromptTab } from "./prompt-tab.js";
import { initSettingsTab, applyTheme, getSavedTheme } from "./settings-tab.js";
import { initSettingsTab, applyTheme, getSavedTheme, applyTextareaFontSize } from "./settings-tab.js";
import { initModelsTab } from "./models-tab.js";
import { initGalleryTab } from "./gallery-tab.js";
import { initMetadataTab } from "./metadata-tab.js";
import { initAiTab } from "./ai-tab.js";
// Apply saved theme immediately to prevent flash of default theme
applyTheme(getSavedTheme());
// Apply saved textarea font size
try {
const _s = JSON.parse(localStorage.getItem("wfm_settings") || "{}");
if (_s.textareaFontSize) applyTextareaFontSize(_s.textareaFontSize);
} catch {}
document.addEventListener("DOMContentLoaded", () => {
applyI18nToHtml();
initTabs();
@@ -381,6 +453,7 @@ document.addEventListener("DOMContentLoaded", () => {
initPromptTab();
initMetadataTab();
initGalleryTab();
initAiTab();
console.log("Workflow Studio: App initialized");
});
+109 -4
View File
@@ -731,14 +731,119 @@ export async function initGenerateTab() {
}
});
// Raw JSON highlight sync on input/scroll
// Raw JSON highlight sync + search
{
const editor = document.getElementById("wfm-gen-raw-json");
const highlight = document.getElementById("wfm-gen-raw-json-highlight");
if (editor && highlight) {
editor.addEventListener("input", () => syncJsonHighlight(highlight, editor.value));
editor.addEventListener("scroll", () => syncScroll(editor, highlight));
const searchOverlay = document.getElementById("wfm-gen-raw-json-search-overlay");
const searchInput = document.getElementById("wfm-gen-raw-search");
const searchCount = document.getElementById("wfm-gen-raw-search-count");
const searchPrev = document.getElementById("wfm-gen-raw-search-prev");
const searchNext = document.getElementById("wfm-gen-raw-search-next");
const searchClear = document.getElementById("wfm-gen-raw-search-clear");
let currentMatchIndex = 0;
let matchPositions = [];
function updateSearchOverlay() {
if (!editor || !searchOverlay || !searchInput) return;
const term = searchInput.value;
if (!term) {
searchOverlay.innerHTML = "";
if (searchCount) { searchCount.textContent = ""; searchCount.style.color = ""; }
matchPositions = [];
return;
}
const text = editor.value;
const escapedTerm = term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const regex = new RegExp(escapedTerm, "gi");
matchPositions = [];
let m;
while ((m = regex.exec(text)) !== null) matchPositions.push(m.index);
if (matchPositions.length === 0) {
searchOverlay.innerHTML = "";
if (searchCount) { searchCount.textContent = "No results"; searchCount.style.color = "#e06c75"; }
return;
}
if (searchCount) searchCount.style.color = "";
if (currentMatchIndex >= matchPositions.length) currentMatchIndex = 0;
if (searchCount) searchCount.textContent = `${currentMatchIndex + 1}/${matchPositions.length}`;
const escapedHtml = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
let matchIdx = 0;
const html = escapedHtml.replace(new RegExp(escapedTerm, "gi"), (match) => {
const cls = matchIdx === currentMatchIndex ? "wfm-search-current" : "wfm-search-match";
matchIdx++;
return `<mark class="${cls}">${match}</mark>`;
});
searchOverlay.innerHTML = html + "\n";
// Scroll editor to current match
const pos = matchPositions[currentMatchIndex];
editor.focus();
editor.setSelectionRange(pos, pos + term.length);
const lineNum = (text.slice(0, pos).match(/\n/g) || []).length;
const lineH = parseFloat(getComputedStyle(editor).lineHeight) || 18;
editor.scrollTop = Math.max(0, lineH * lineNum - editor.clientHeight / 2);
searchOverlay.scrollTop = editor.scrollTop;
searchOverlay.scrollLeft = editor.scrollLeft;
if (highlight) highlight.scrollTop = editor.scrollTop;
}
if (editor && highlight) {
editor.addEventListener("input", () => {
syncJsonHighlight(highlight, editor.value);
if (searchInput?.value) updateSearchOverlay();
});
editor.addEventListener("scroll", () => {
syncScroll(editor, highlight);
if (searchOverlay) {
searchOverlay.scrollTop = editor.scrollTop;
searchOverlay.scrollLeft = editor.scrollLeft;
}
});
}
searchInput?.addEventListener("input", () => { currentMatchIndex = 0; updateSearchOverlay(); });
searchNext?.addEventListener("click", () => {
if (!matchPositions.length) return;
currentMatchIndex = (currentMatchIndex + 1) % matchPositions.length;
updateSearchOverlay();
});
searchPrev?.addEventListener("click", () => {
if (!matchPositions.length) return;
currentMatchIndex = (currentMatchIndex - 1 + matchPositions.length) % matchPositions.length;
updateSearchOverlay();
});
function clearSearch() {
if (searchInput) searchInput.value = "";
currentMatchIndex = 0;
matchPositions = [];
if (searchOverlay) searchOverlay.innerHTML = "";
if (searchCount) { searchCount.textContent = ""; searchCount.style.color = ""; }
}
searchClear?.addEventListener("click", clearSearch);
searchInput?.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
if (!matchPositions.length) return;
currentMatchIndex = e.shiftKey
? (currentMatchIndex - 1 + matchPositions.length) % matchPositions.length
: (currentMatchIndex + 1) % matchPositions.length;
updateSearchOverlay();
e.preventDefault();
} else if (e.key === "Escape") {
clearSearch();
}
});
}
// Check for workflow loaded from Workflow tab (via sessionStorage)
+165 -3
View File
@@ -324,6 +324,52 @@ const LANGUAGES = {
galleryOutputDirLabel: "Output Folder Path",
galleryOutputDirHint: "Set the ComfyUI output folder to browse in the Gallery tab. Leave blank to use ComfyUI's default output directory.",
tabAi: "A",
// -- AI Tab --
aiSubTabTranslate: "Translate",
aiSubTabVlm: "VLM",
aiSubTabSettings: "Settings",
aiLangJa: "Japanese", aiLangEn: "English", aiLangZh: "Chinese", aiLangFree: "Free",
aiTransInputPlaceholder: "Enter text to translate...",
aiTransOutputPlaceholder: "Translation result will appear here...",
aiTranslateBtn: "Translate",
aiCopyBtn: "Copy",
aiVlmDropLabel: "Drop PNG / JPG / WebP here or click",
aiVlmDescribe: "Describe Image",
aiVlmPromptCreate: "Create Prompt",
aiVlmRunBtn: "Run",
aiVlmResultPlaceholder: "Result will appear here...",
aiSettingsBackend: "Backend",
aiSettingsConnection: "Connection",
aiSettingsTestBtn: "Test Connection",
aiSettingsModelSection: "Model",
aiSettingsRefreshBtn: "Refresh",
aiSettingsModelPlaceholder: "-- Select Model --",
aiSettingsFreeLang: "Free Language",
aiSettingsInputLang: "Input",
aiSettingsOutputLang: "Output",
aiSettingsSaveBtn: "Save Settings",
aiToastNoText: "Please enter text",
aiToastNoModel: "Please select a model in the Settings tab",
aiToastInvalidUrl: "URL must start with http:// or https://",
aiToastInvalidUrlInput: "Please enter a URL starting with http:// or https://",
aiStatusTranslating: "Translating...",
aiStatusRunning: "Running...",
aiStatusDone: "Done",
aiStatusConnecting: "Connecting...",
aiStatusConnectOk: "Connected",
aiStatusConnectFail: "Connection failed: ",
aiToastTransFailed: "Translation failed: ",
aiToastNoCopyText: "No text to copy",
aiToastCopied: "Copied",
aiToastNoModels: "No models found",
aiToastModelsFailed: "Failed to fetch models: ",
aiToastSettingsSaved: "Settings saved",
aiToastNoImage: "Please drop an image",
aiToastVlmFailed: "VLM failed: ",
aiModels: "models",
// -- Help & Support --
tabHelp: "Help",
helpManualTitle: "Features",
@@ -424,6 +470,14 @@ const LANGUAGES = {
helpSidepanel13: "I tab (Information): drop a ComfyUI PNG/WebP/JSON to inspect model, LoRA, and prompt metadata in the side panel — sub-tabs: model / lora / Prompts; supports UnetLoaderGGUF and QuadrupleCLIPLoader node types",
helpSidepanel14: "Information tab — drag items to canvas: model sub-tab places the loader node (Checkpoint → CheckpointLoaderSimple, VAE → VAELoader, Diffusion Model → UNETLoader, Text Encoder → CLIPLoader); double-click also places at canvas center",
helpSidepanel15: "Information tab — LoRA sub-tab: drag individual LoRA to place LoraLoader; \"Multiple LORA\" section at bottom places all LoRAs in a single Lora Loader (LoraManager) node; Prompts sub-tab: drag a prompt to place CLIPTextEncode node with text pre-filled; click prompt to view full text and copy",
helpSidepanel16: "A tab (AI Tools): Translation and VLM sub-tabs powered by Ollama or LM Studio; settings (backend, URL, model) are shared with the SPA AI tab via localStorage",
helpAiTitle: "AI Tab (A)",
helpAi1: "Translation sub-tab: translate text between Japanese, English, Chinese, or a custom Free language using Ollama or LM Studio",
helpAi2: "Language selectors for source and destination with ⇄ swap button; text content is also swapped; selections are saved automatically",
helpAi3: "VLM sub-tab: drop an image into the drop zone and select a task — Describe Image or Create Prompt — then click Run to analyze with a vision model",
helpAi4: "VLM result is displayed in the output area with a Copy button",
helpAi5: "Settings sub-tab: choose backend (Ollama / LM Studio), set the API URL, test connection, select model, and configure Free language names for translation",
helpAi6: "Settings are saved to localStorage and shared with the Library panel's A tab",
helpShortcutsTitle: "Keyboard Shortcuts",
helpShortcuts1: "Escape: Close modal/panel",
helpShortcuts2: "Enter: Confirm rename, send chat",
@@ -459,7 +513,7 @@ const LANGUAGES = {
comfyuiUrlHint: "When running as ComfyUI plugin, leave empty to use same origin. Only set if ComfyUI is on a different server.",
connectedCheck: "Connected \u2713",
failedConnect: "Failed to connect \u2717",
ollamaSettings: "Ollama Settings",
ollamaSettings: "Ollama Settings (Prompt Tab)",
ollamaUrl: "Ollama API URL",
ollamaDefaultModel: "Default Model",
selectModel: "Select model...",
@@ -897,6 +951,52 @@ const LANGUAGES = {
galleryOutputDirLabel: "Outputフォルダのパス",
galleryOutputDirHint: "ギャラリータブで参照するComfyUIのoutputフォルダを設定します。空欄の場合はComfyUIのデフォルトoutputディレクトリを使用します。",
tabAi: "A",
// -- AI Tab --
aiSubTabTranslate: "翻訳",
aiSubTabVlm: "VLM",
aiSubTabSettings: "設定",
aiLangJa: "日本語", aiLangEn: "英語", aiLangZh: "中国語", aiLangFree: "Free",
aiTransInputPlaceholder: "翻訳するテキストを入力...",
aiTransOutputPlaceholder: "翻訳結果がここに表示されます...",
aiTranslateBtn: "翻訳",
aiCopyBtn: "コピー",
aiVlmDropLabel: "PNG / JPG / WebP をドロップまたはクリック",
aiVlmDescribe: "画像の解説",
aiVlmPromptCreate: "プロンプト作成",
aiVlmRunBtn: "実行",
aiVlmResultPlaceholder: "実行結果がここに表示されます...",
aiSettingsBackend: "バックエンド",
aiSettingsConnection: "接続設定",
aiSettingsTestBtn: "接続テスト",
aiSettingsModelSection: "モデル選択",
aiSettingsRefreshBtn: "更新",
aiSettingsModelPlaceholder: "-- モデルを選択 --",
aiSettingsFreeLang: "Free 言語設定",
aiSettingsInputLang: "入力言語",
aiSettingsOutputLang: "翻訳言語",
aiSettingsSaveBtn: "設定を保存",
aiToastNoText: "テキストを入力してください",
aiToastNoModel: "設定タブでモデルを選択してください",
aiToastInvalidUrl: "URLは http:// または https:// で始まる必要があります",
aiToastInvalidUrlInput: "http:// または https:// で始まるURLを入力してください",
aiStatusTranslating: "翻訳中...",
aiStatusRunning: "実行中...",
aiStatusDone: "完了",
aiStatusConnecting: "接続中...",
aiStatusConnectOk: "接続成功",
aiStatusConnectFail: "接続失敗: ",
aiToastTransFailed: "翻訳に失敗しました: ",
aiToastNoCopyText: "コピーするテキストがありません",
aiToastCopied: "コピーしました",
aiToastNoModels: "モデルが見つかりません",
aiToastModelsFailed: "モデル取得失敗: ",
aiToastSettingsSaved: "設定を保存しました",
aiToastNoImage: "画像をドロップしてください",
aiToastVlmFailed: "VLM実行失敗: ",
aiModels: "モデル",
// -- Help & Support --
tabHelp: "ヘルプ",
helpManualTitle: "機能一覧",
@@ -997,6 +1097,14 @@ const LANGUAGES = {
helpSidepanel13: "I タブ(Information):ComfyUI の PNG / WebP / JSON をドロップするとサイドパネル内でモデル・LoRA・プロンプトのメタデータを確認可能 — サブタブ: model / lora / Prompts;UnetLoaderGGUF・QuadrupleCLIPLoader ノードタイプに対応",
helpSidepanel14: "Information タブ — キャンバスへドラッグ:model サブタブのアイテムをドラッグすると対応ローダーノードを配置(Checkpoint → CheckpointLoaderSimple、VAE → VAELoader、Diffusion Model → UNETLoader、Text Encoder → CLIPLoader);ダブルクリックでもキャンバス中央に配置可能",
helpSidepanel15: "Information タブ — lora サブタブ:個別 LoRA をドラッグで LoraLoader を配置;下部の「Multiple LORA」セクションをドラッグすると全 LoRA を一括で Lora Loader (LoraManager) に配置;Prompts サブタブ:プロンプトをドラッグするとテキスト入力済みの CLIPTextEncode ノードを配置;クリックで全文表示・コピー可能",
helpSidepanel16: "A タブ(AI ツール):翻訳・VLM サブタブ;設定(バックエンド・URL・モデル)は SPA の AI タブと localStorage で共有される",
helpAiTitle: "AI タブ(A)",
helpAi1: "翻訳サブタブ:Ollama または LM Studio を使って日本語・英語・中国語・カスタム言語(Free)間でテキストを翻訳",
helpAi2: "入力言語・出力言語セレクターと ⇄ 入替ボタン付き;テキスト内容も同時に入替;選択は自動保存",
helpAi3: "VLM サブタブ:画像をドロップゾーンにドロップしてタスクを選択(画像の解説 / プロンプト作成)し、実行ボタンでビジョンモデルに解析させる",
helpAi4: "VLM の結果は出力エリアに表示され、コピーボタンでクリップボードに取得可能",
helpAi5: "設定サブタブ:バックエンド(Ollama / LM Studio)・API URL・接続テスト・モデル選択・翻訳の Free 言語名を設定",
helpAi6: "設定は localStorage に保存され、Library パネルの A タブと共有される",
helpShortcutsTitle: "キーボード操作",
helpShortcuts1: "Escape:モーダル・パネルを閉じる",
helpShortcuts2: "Enter:名前変更の確定、チャット送信",
@@ -1032,7 +1140,7 @@ const LANGUAGES = {
comfyuiUrlHint: "ComfyUIプラグインとして動作する場合は空欄(同一オリジン推奨)。別サーバーの場合のみ設定してください。",
connectedCheck: "接続成功 \u2713",
failedConnect: "接続失敗 \u2717",
ollamaSettings: "Ollama 設定",
ollamaSettings: "Ollama 設定(プロンプトタブ)",
ollamaUrl: "Ollama API URL",
ollamaDefaultModel: "デフォルトモデル",
selectModel: "モデルを選択...",
@@ -1466,6 +1574,52 @@ const LANGUAGES = {
galleryOutputDirLabel: "输出文件夹路径",
galleryOutputDirHint: "设置图库标签页浏览的ComfyUI输出文件夹。留空则使用ComfyUI默认输出目录。",
tabAi: "A",
// -- AI Tab --
aiSubTabTranslate: "翻译",
aiSubTabVlm: "VLM",
aiSubTabSettings: "设置",
aiLangJa: "日语", aiLangEn: "英语", aiLangZh: "中文", aiLangFree: "Free",
aiTransInputPlaceholder: "输入要翻译的文字...",
aiTransOutputPlaceholder: "翻译结果将显示在这里...",
aiTranslateBtn: "翻译",
aiCopyBtn: "复制",
aiVlmDropLabel: "拖放 PNG / JPG / WebP 或点击",
aiVlmDescribe: "图像说明",
aiVlmPromptCreate: "生成提示词",
aiVlmRunBtn: "执行",
aiVlmResultPlaceholder: "执行结果将显示在这里...",
aiSettingsBackend: "后端",
aiSettingsConnection: "连接设置",
aiSettingsTestBtn: "连接测试",
aiSettingsModelSection: "选择模型",
aiSettingsRefreshBtn: "刷新",
aiSettingsModelPlaceholder: "-- 请选择模型 --",
aiSettingsFreeLang: "Free 语言设置",
aiSettingsInputLang: "输入语言",
aiSettingsOutputLang: "翻译语言",
aiSettingsSaveBtn: "保存设置",
aiToastNoText: "请输入文字",
aiToastNoModel: "请在设置标签中选择模型",
aiToastInvalidUrl: "URL必须以 http:// 或 https:// 开头",
aiToastInvalidUrlInput: "请输入以 http:// 或 https:// 开头的URL",
aiStatusTranslating: "翻译中...",
aiStatusRunning: "执行中...",
aiStatusDone: "完成",
aiStatusConnecting: "连接中...",
aiStatusConnectOk: "连接成功",
aiStatusConnectFail: "连接失败:",
aiToastTransFailed: "翻译失败:",
aiToastNoCopyText: "没有可复制的文字",
aiToastCopied: "已复制",
aiToastNoModels: "未找到模型",
aiToastModelsFailed: "获取模型失败:",
aiToastSettingsSaved: "设置已保存",
aiToastNoImage: "请拖放图像",
aiToastVlmFailed: "VLM执行失败:",
aiModels: "个模型",
// -- Help & Support --
tabHelp: "帮助",
helpManualTitle: "功能列表",
@@ -1566,6 +1720,14 @@ const LANGUAGES = {
helpSidepanel13: "I 标签(Information):拖放 ComfyUI PNG/WebP/JSON 即可在侧面板内查看模型、LoRA 和提示词元数据 — 子标签:model / lora / Prompts;支持 UnetLoaderGGUF 和 QuadrupleCLIPLoader 节点类型",
helpSidepanel14: "Information 标签 — 拖拽到画布:model 子标签拖拽可放置对应加载节点(Checkpoint → CheckpointLoaderSimple、VAE → VAELoader、Diffusion Model → UNETLoader、Text Encoder → CLIPLoader);双击也可放置到画布中央",
helpSidepanel15: "Information 标签 — lora 子标签:拖拽单个 LoRA 放置 LoraLoader;底部「Multiple LORA」区域可将全部 LoRA 一次性放入 Lora Loader (LoraManager) 节点;Prompts 子标签:拖拽提示词放置预填文本的 CLIPTextEncode 节点;点击可查看全文并复制",
helpSidepanel16: "A 标签(AI 工具):翻译子标签和 VLM 子标签;设置(后端、URL、模型)通过 localStorage 与 SPA 的 AI 标签共享",
helpAiTitle: "AI 标签页(A)",
helpAi1: "翻译子标签:使用 Ollama 或 LM Studio 在日语、英语、中文或自定义语言(Free)之间翻译文本",
helpAi2: "源语言和目标语言选择器,带 ⇄ 互换按钮;文本内容也同时互换;选择自动保存",
helpAi3: "VLM 子标签:将图像拖放到投放区域,选择任务(图像描述 / 提示词生成),点击执行按钮用视觉模型进行分析",
helpAi4: "VLM 结果显示在输出区域,可通过复制按钮复制到剪贴板",
helpAi5: "设置子标签:选择后端(Ollama / LM Studio)、设置 API URL、测试连接、选择模型、配置翻译的 Free 语言名称",
helpAi6: "设置保存至 localStorage,并与 Library 面板的 A 标签共享",
helpShortcutsTitle: "键盘操作",
helpShortcuts1: "Escape:关闭弹窗/面板",
helpShortcuts2: "Enter:确认重命名、发送聊天",
@@ -1601,7 +1763,7 @@ const LANGUAGES = {
comfyuiUrlHint: "作为ComfyUI插件运行时留空(推荐同源)。仅在不同服务器时设置。",
connectedCheck: "已连接 \u2713",
failedConnect: "连接失败 \u2717",
ollamaSettings: "Ollama 设置",
ollamaSettings: "Ollama 设置(提示词标签页)",
ollamaUrl: "Ollama API URL",
ollamaDefaultModel: "默认模型",
selectModel: "选择模型...",
+5 -2
View File
@@ -122,8 +122,9 @@ function extractVAEs(wf) {
}
function extractDiffusionModels(wf) {
if (!wf || typeof wf !== "object") return [];
if (Array.isArray(wf.nodes)) return collectUnique(collectAllNodes(wf).filter(n => n.type === "UNETLoader").map(n => n.widgets_values?.[0]));
return collectUnique(Object.values(wf).filter(n => n?.class_type === "UNETLoader").map(n => n.inputs?.unet_name));
const UNET_TYPES = new Set(["UNETLoader", "UnetLoaderGGUF", "UNETLoaderGGUF"]);
if (Array.isArray(wf.nodes)) return collectUnique(collectAllNodes(wf).filter(n => UNET_TYPES.has(n.type)).map(n => n.widgets_values?.[0]));
return collectUnique(Object.values(wf).filter(n => UNET_TYPES.has(n?.class_type)).map(n => n.inputs?.unet_name));
}
function extractTextEncoders(wf) {
if (!wf || typeof wf !== "object") return [];
@@ -133,6 +134,7 @@ function extractTextEncoders(wf) {
if (n.type === "CLIPLoader") { if (n.widgets_values?.[0]) names.push(n.widgets_values[0]); }
else if (n.type === "DualCLIPLoader") { [0,1].forEach(i => { if (n.widgets_values?.[i]) names.push(n.widgets_values[i]); }); }
else if (n.type === "TripleCLIPLoader") { [0,1,2].forEach(i => { if (n.widgets_values?.[i]) names.push(n.widgets_values[i]); }); }
else if (n.type === "QuadrupleCLIPLoader") { [0,1,2,3].forEach(i => { if (n.widgets_values?.[i]) names.push(n.widgets_values[i]); }); }
}
} else {
for (const n of Object.values(wf)) {
@@ -141,6 +143,7 @@ function extractTextEncoders(wf) {
if (ct === "CLIPLoader") { if (n.inputs?.clip_name) names.push(n.inputs.clip_name); }
else if (ct === "DualCLIPLoader") { if (n.inputs?.clip_name1) names.push(n.inputs.clip_name1); if (n.inputs?.clip_name2) names.push(n.inputs.clip_name2); }
else if (ct === "TripleCLIPLoader") { ["clip_name1","clip_name2","clip_name3"].forEach(k => { if (n.inputs?.[k]) names.push(n.inputs[k]); }); }
else if (ct === "QuadrupleCLIPLoader") { ["clip_name1","clip_name2","clip_name3","clip_name4"].forEach(k => { if (n.inputs?.[k]) names.push(n.inputs[k]); }); }
}
}
return collectUnique(names);
+52
View File
@@ -314,6 +314,30 @@ function clearCustomOverrides() {
if (fontEl) fontEl.remove();
}
const TEXTAREA_FONT_SIZE_DEFAULT = 13;
const TEXTAREA_FONT_SIZE_STYLE_ID = "wfm-ta-font-size-style";
const TEXTAREA_FONT_SIZE_TARGETS = [
"#wfm-prompt-pos-text",
"#wfm-prompt-neg-text",
"#wfm-ollama-input",
"#wfm-preset-pos",
"#wfm-preset-neg",
"#wfm-wc-prompt",
"#wfm-wc-editor-content",
"#wfm-meta-prompt-full",
].join(",\n ");
export function applyTextareaFontSize(size) {
const px = Math.max(10, Math.min(28, parseInt(size) || TEXTAREA_FONT_SIZE_DEFAULT));
let el = document.getElementById(TEXTAREA_FONT_SIZE_STYLE_ID);
if (!el) {
el = document.createElement("style");
el.id = TEXTAREA_FONT_SIZE_STYLE_ID;
document.head.appendChild(el);
}
el.textContent = `${TEXTAREA_FONT_SIZE_TARGETS} { font-size: ${px}px !important; }`;
}
export function applyTheme(themeId) {
if (themeId) {
document.documentElement.setAttribute("data-theme", themeId);
@@ -485,6 +509,24 @@ export async function initSettingsTab() {
</div>
</details>
<!-- Text Size -->
<details class="wfm-settings-section" open>
<summary class="wfm-settings-summary">${t("textSizeLabel") || "Text Size"}</summary>
<div class="wfm-form-group">
<label style="display:flex;align-items:center;justify-content:space-between;">
<span>${t("textSizeTextarea") || "Prompt / Chat Textarea"}</span>
<span id="wfm-ta-font-size-val" style="font-size:12px;color:var(--wfm-text-secondary);">${settings.textareaFontSize || TEXTAREA_FONT_SIZE_DEFAULT}px</span>
</label>
<input type="range" class="wfm-range" id="wfm-ta-font-size"
min="10" max="28" step="1"
value="${settings.textareaFontSize || TEXTAREA_FONT_SIZE_DEFAULT}"
style="width:100%;margin-top:4px;">
<small style="color:var(--wfm-text-secondary);font-size:11px;display:block;margin-top:4px;">
${t("textSizeHint") || "Applies to: Generate UI prompts, AI Assistant chat, Preset prompts, Wildcard textarea, Metadata prompt preview"}
</small>
</div>
</details>
<!-- Workflow Data Folder -->
<details class="wfm-settings-section">
<summary class="wfm-settings-summary">${t("workflowsDir")}</summary>
@@ -1032,8 +1074,17 @@ export async function initSettingsTab() {
showToast(t("defaultWorkflowCleared"), "success");
});
// --- Textarea font size slider ---
document.getElementById("wfm-ta-font-size")?.addEventListener("input", (e) => {
const px = parseInt(e.target.value);
const valEl = document.getElementById("wfm-ta-font-size-val");
if (valEl) valEl.textContent = `${px}px`;
applyTextareaFontSize(px);
});
// Save (local settings)
document.getElementById("wfm-settings-save")?.addEventListener("click", () => {
const taFontSize = parseInt(document.getElementById("wfm-ta-font-size")?.value) || TEXTAREA_FONT_SIZE_DEFAULT;
const patch = {
comfyuiUrl: document.getElementById("wfm-settings-comfyui-url")?.value.trim() || "",
eagleUrl: document.getElementById("wfm-settings-eagle-url")?.value.trim() || "http://localhost:41595",
@@ -1041,6 +1092,7 @@ export async function initSettingsTab() {
uiLang: getLang(),
summaryLang: getSummaryLang(),
theme: document.documentElement.getAttribute("data-theme") || "",
textareaFontSize: taFontSize,
};
saveLocalSettings(patch);
+148 -1
View File
@@ -24,6 +24,7 @@
<button class="wfm-tab" data-tab="gallery">Gallery</button>
<button class="wfm-tab" data-tab="settings">Settings</button>
<button class="wfm-tab" data-tab="help">Help</button>
<button class="wfm-tab" data-tab="ai">A</button>
</nav>
</header>
@@ -517,8 +518,16 @@
<span class="wfm-gen-rawjson-label">Raw JSON</span>
<button id="wfm-gen-apply-raw-btn" class="wfm-btn wfm-btn-sm">Apply</button>
</div>
<div class="wfm-rawjson-search">
<input type="text" id="wfm-gen-raw-search" class="wfm-rawjson-search-input" placeholder="Search...">
<span id="wfm-gen-raw-search-count" class="wfm-rawjson-search-count"></span>
<button id="wfm-gen-raw-search-prev" class="wfm-rawjson-search-btn" title="Previous match">↑</button>
<button id="wfm-gen-raw-search-next" class="wfm-rawjson-search-btn" title="Next match">↓</button>
<button id="wfm-gen-raw-search-clear" class="wfm-rawjson-search-btn wfm-rawjson-search-clear" title="Clear search">✕</button>
</div>
<div class="wfm-json-container wfm-gen-rawjson-editor">
<pre id="wfm-gen-raw-json-highlight" class="wfm-json-highlight"></pre>
<pre id="wfm-gen-raw-json-search-overlay" class="wfm-json-highlight wfm-json-search-overlay"></pre>
<textarea id="wfm-gen-raw-json" class="wfm-json-editor" spellcheck="false" placeholder="Paste workflow JSON here..."></textarea>
</div>
</div>
@@ -864,7 +873,7 @@
<li id="wfm-help-metadata-2">Center column: Checkpoint, VAE, Diffusion Model, and Text Encoder lists extracted from the workflow</li>
<li id="wfm-help-metadata-3">Right column: LoRA list (with strength values) and Prompt list (click to view full text below)</li>
<li id="wfm-help-metadata-4">Prompt actions — Copy: copy to clipboard; GenUI:P/N: set GenerateUI positive/negative prompt; Prompt:P/N: set Prompt tab preset positive/negative</li>
<li id="wfm-help-metadata-5">Supported: ComfyUI PNG/WebP/JSON (standard + Flux.2 / Qwen-Image / Z-Image subgraph workflows), SD WebUI, SD Forge, Fooocus.</li>
<li id="wfm-help-metadata-5">Supported: ComfyUI PNG/WebP/JSON (standard + Flux.2 / Qwen-Image / Z-Image subgraph workflows), SD WebUI, SD Forge, Fooocus. Model extraction covers UNETLoader, UnetLoaderGGUF, UNETLoaderGGUF (e.g. HiDream GGUF), CLIPLoader, DualCLIPLoader, TripleCLIPLoader, and QuadrupleCLIPLoader (e.g. HiDream 4-CLIP).</li>
</ul>
</div>
@@ -881,6 +890,7 @@
<li id="wfm-help-settings-8">Data Management: export all plugin data to JSON / import to restore</li>
<li id="wfm-help-settings-9">All sections are collapsible accordion panels</li>
<li id="wfm-help-settings-10">Wildcard Integration: link WFS wildcard dir to ComfyUI-Impact-Pack wildcards (junction/symlink); existing files migrated automatically</li>
<li id="wfm-help-settings-11">Text Size: one slider (10–28 px) adjusts font size for all prompt and chat textareas at once — Generate UI positive/negative prompts, AI Assistant chat input, Preset positive/negative, Wildcard prompt and file editor, and Metadata prompt full preview; takes effect immediately and saved with Save Settings</li>
</ul>
</div>
@@ -948,6 +958,19 @@
<li id="wfm-help-sidepanel-13">I tab (Information): drop a ComfyUI PNG/WebP/JSON to inspect model, LoRA, and prompt metadata in the side panel — sub-tabs: model / lora / Prompts; supports UnetLoaderGGUF and QuadrupleCLIPLoader node types</li>
<li id="wfm-help-sidepanel-14">Information tab — drag items to canvas: model sub-tab places the loader node (Checkpoint → CheckpointLoaderSimple, VAE → VAELoader, Diffusion Model → UNETLoader, Text Encoder → CLIPLoader); double-click also places at canvas center</li>
<li id="wfm-help-sidepanel-15">Information tab — LoRA sub-tab: drag individual LoRA to place LoraLoader; "Multiple LORA" section at bottom places all LoRAs in a single Lora Loader (LoraManager) node; Prompts sub-tab: drag a prompt to place CLIPTextEncode node with text pre-filled; click prompt to view full text and copy</li>
<li id="wfm-help-sidepanel-16">A tab (AI Tools): Translation and VLM sub-tabs powered by Ollama or LM Studio; settings (backend, URL, model) are shared with the SPA AI tab via localStorage</li>
</ul>
</div>
<div class="wfm-help-card">
<h3 id="wfm-help-ai-title">AI Tab (A)</h3>
<ul>
<li id="wfm-help-ai-1">Translation sub-tab: translate text between Japanese, English, Chinese, or a custom Free language using Ollama or LM Studio</li>
<li id="wfm-help-ai-2">Language selectors for source and destination with ⇄ swap button; text content is also swapped; selections are saved automatically</li>
<li id="wfm-help-ai-3">VLM sub-tab: drop an image into the drop zone and select a task — Describe Image or Create Prompt — then click Run to analyze with a vision model</li>
<li id="wfm-help-ai-4">VLM result is displayed in the output area with a Copy button</li>
<li id="wfm-help-ai-5">Settings sub-tab: choose backend (Ollama / LM Studio), set the API URL, test connection, select model, and configure Free language names for translation</li>
<li id="wfm-help-ai-6">Settings are saved to localStorage and shared with the Library panel's A tab</li>
</ul>
</div>
@@ -1129,6 +1152,130 @@
</div>
</div>
</section>
<!-- AI Tab -->
<section id="wfm-tab-ai" class="wfm-tab-content">
<!-- サブタブナビ -->
<div class="wfm-ai-subtab-nav">
<button class="wfm-ai-subtab-btn active" data-ai-subtab="translate">翻訳</button>
<button class="wfm-ai-subtab-btn" data-ai-subtab="vlm">VLM</button>
<button class="wfm-ai-subtab-btn" data-ai-subtab="ai-settings">設定</button>
</div>
<!-- 翻訳サブタブ -->
<div id="wfm-ai-subtab-translate" class="wfm-ai-subtab-content">
<div class="wfm-ai-trans-container">
<!-- 言語選択行 -->
<div class="wfm-ai-trans-lang-row">
<select id="wfm-ai-src-lang" class="wfm-select wfm-ai-lang-select">
<option value="ja">日本語</option>
<option value="en">英語</option>
<option value="zh">中国語</option>
<option value="free">Free</option>
</select>
<button id="wfm-ai-trans-swap-btn" class="wfm-btn wfm-ai-swap-btn" title="言語を入れ替え">⇄</button>
<select id="wfm-ai-dst-lang" class="wfm-select wfm-ai-lang-select">
<option value="en">英語</option>
<option value="ja">日本語</option>
<option value="zh">中国語</option>
<option value="free">Free</option>
</select>
</div>
<!-- 入力テキストエリア -->
<textarea id="wfm-ai-trans-input" class="wfm-ai-trans-textarea" placeholder="翻訳するテキストを入力..."></textarea>
<!-- アクションボタン行 -->
<div class="wfm-ai-trans-actions">
<button id="wfm-ai-trans-btn" class="wfm-btn wfm-btn-primary">翻訳</button>
<button id="wfm-ai-trans-copy-btn" class="wfm-btn">コピー</button>
<span id="wfm-ai-trans-status" class="wfm-ai-trans-status"></span>
</div>
<!-- 出力テキストエリア -->
<textarea id="wfm-ai-trans-output" class="wfm-ai-trans-textarea wfm-ai-trans-output" placeholder="翻訳結果がここに表示されます..." readonly></textarea>
</div>
</div>
<!-- VLM サブタブ -->
<div id="wfm-ai-subtab-vlm" class="wfm-ai-subtab-content" style="display:none">
<div class="wfm-ai-vlm-container">
<!-- ドロップゾーン -->
<div class="wfm-ai-vlm-drop" id="wfm-ai-vlm-drop">
<img id="wfm-ai-vlm-preview" style="display:none;max-width:100%;max-height:100%;object-fit:contain;pointer-events:none;">
<span id="wfm-ai-vlm-label" class="wfm-ai-vlm-label">PNG / JPG / WebP をドロップまたはクリック</span>
<input type="file" id="wfm-ai-vlm-file" accept="image/png,image/jpeg,image/webp" style="display:none;">
</div>
<!-- タスク選択行 -->
<div class="wfm-ai-vlm-task-row">
<select id="wfm-ai-vlm-task" class="wfm-select">
<option value="describe">画像の解説</option>
<option value="prompt">プロンプト作成</option>
</select>
<button id="wfm-ai-vlm-run" class="wfm-btn wfm-btn-primary">実行</button>
</div>
<!-- ステータス -->
<span id="wfm-ai-vlm-status" class="wfm-ai-trans-status"></span>
<!-- 結果表示 -->
<textarea id="wfm-ai-vlm-result" class="wfm-ai-vlm-result" placeholder="実行結果がここに表示されます..." readonly></textarea>
<!-- コピーボタン -->
<button id="wfm-ai-vlm-copy" class="wfm-btn wfm-ai-vlm-copy-btn">コピー</button>
</div>
</div>
<!-- 設定サブタブ -->
<div id="wfm-ai-subtab-ai-settings" class="wfm-ai-subtab-content" style="display:none">
<div class="wfm-ai-settings-container">
<!-- バックエンド選択 -->
<div class="wfm-ai-settings-section">
<div class="wfm-ai-settings-title" id="wfm-ai-settings-backend-title">バックエンド</div>
<div class="wfm-ai-backend-row">
<label class="wfm-ai-radio-label">
<input type="radio" name="wfm-ai-backend" value="ollama" checked> Ollama
</label>
<label class="wfm-ai-radio-label">
<input type="radio" name="wfm-ai-backend" value="lmstudio"> LM Studio
</label>
</div>
</div>
<!-- 接続設定 -->
<div class="wfm-ai-settings-section">
<div class="wfm-ai-settings-title" id="wfm-ai-settings-conn-title">接続設定</div>
<div class="wfm-ai-settings-row">
<label class="wfm-ai-label">URL</label>
<input type="text" id="wfm-ai-backend-url" class="wfm-input wfm-ai-url-input" value="http://localhost:11434">
</div>
<div class="wfm-ai-settings-row">
<button id="wfm-ai-test-btn" class="wfm-btn">接続テスト</button>
<span id="wfm-ai-test-result" class="wfm-ai-test-result"></span>
</div>
</div>
<!-- モデル選択 -->
<div class="wfm-ai-settings-section">
<div class="wfm-ai-settings-title" id="wfm-ai-settings-model-title">モデル選択</div>
<div class="wfm-ai-settings-row">
<select id="wfm-ai-model-select" class="wfm-select wfm-ai-model-select">
<option value="">-- モデルを選択 --</option>
</select>
<button id="wfm-ai-model-refresh-btn" class="wfm-btn">更新</button>
</div>
</div>
<!-- Free 言語設定 -->
<div class="wfm-ai-settings-section">
<div class="wfm-ai-settings-title" id="wfm-ai-settings-freelang-title">Free 言語設定</div>
<div class="wfm-ai-settings-row">
<label class="wfm-ai-label" id="wfm-ai-free-src-label">入力言語</label>
<input type="text" id="wfm-ai-free-src-lang" class="wfm-input" placeholder="例: French">
</div>
<div class="wfm-ai-settings-row">
<label class="wfm-ai-label" id="wfm-ai-free-dst-label">翻訳言語</label>
<input type="text" id="wfm-ai-free-dst-lang" class="wfm-input" placeholder="例: German">
</div>
</div>
<!-- 保存 -->
<div class="wfm-ai-settings-section">
<button id="wfm-ai-settings-save-btn" class="wfm-btn wfm-btn-primary">設定を保存</button>
</div>
</div>
</div>
</section>
</main>
<!-- Workflow Detail Modal -->
+635 -3
View File
@@ -58,6 +58,8 @@ const state = {
// Info (Metadata) tab
infoSubTab: "info-model", // "info-model" | "info-lora" | "info-prompt"
infoMeta: null, // parsed metadata from dropped file
// AI tab
aiSubTab: "ai-translate", // "ai-translate" | "ai-vlm" | "ai-settings"
};
// ============================================
@@ -693,6 +695,7 @@ const createPanel = () => {
<button class="wfm-nlp-tab wfm-nlp-top-tab" data-toptab="prompts" title="Prompts">P</button>
<button class="wfm-nlp-tab wfm-nlp-top-tab" data-toptab="models" title="Models">M</button>
<button class="wfm-nlp-tab wfm-nlp-top-tab" data-toptab="info" title="Information (Metadata)">I</button>
<button class="wfm-nlp-tab wfm-nlp-top-tab" data-toptab="ai" title="AI Tools (Translation)">A</button>
</div>
<div class="wfm-nlp-subtabs"></div>
<div class="wfm-nlp-subtabs wfm-nlp-subtabs-row2"></div>
@@ -715,7 +718,7 @@ const createPanel = () => {
const searchInput = panel.querySelector(".wfm-nlp-search-input");
if (searchInput) {
searchInput.value = "";
const placeholders = { workflows: "Search workflows...", nodes: "Search nodes...", prompts: "Search prompts...", models: "Search models...", info: "" };
const placeholders = { workflows: "Search workflows...", nodes: "Search nodes...", prompts: "Search prompts...", models: "Search models...", info: "", ai: "" };
searchInput.placeholder = placeholders[tab] ?? "Search...";
}
panel.querySelectorAll(".wfm-nlp-top-tab").forEach(b => b.classList.remove("active"));
@@ -804,7 +807,27 @@ const rebuildSubTabs = () => {
row2.querySelectorAll(".wfm-nlp-sub-tab").forEach(b => b.classList.remove("active"));
};
if (state.topTab === "info") {
if (state.topTab === "ai") {
const row1Tabs = [
{ key: "ai-translate", label: "翻訳" },
{ key: "ai-vlm", label: "VLM" },
{ key: "ai-settings", label: "設定" },
];
const activeKey = state.aiSubTab;
for (const t of row1Tabs) {
const btn = document.createElement("button");
btn.className = "wfm-nlp-tab wfm-nlp-sub-tab" + (activeKey === t.key ? " active" : "");
btn.dataset.subtab = t.key;
btn.textContent = t.label;
btn.addEventListener("click", () => {
state.aiSubTab = t.key;
updateAllActive();
btn.classList.add("active");
renderAiSubContent();
});
row1.appendChild(btn);
}
} else if (state.topTab === "info") {
const row1Tabs = [
{ key: "info-model", label: "model" },
{ key: "info-lora", label: "lora" },
@@ -980,7 +1003,7 @@ const renderContent = () => {
// Remove filter dropdowns from previous category/package views
panelEl.querySelectorAll(".wfm-nlp-filter-row").forEach(e => e.remove());
// Show/hide search bar and adjust overflow for info tab
// Show/hide search bar and adjust overflow for info/ai tab
const searchEl = panelEl?.querySelector(".wfm-nlp-search");
if (state.topTab === "info") {
if (searchEl) searchEl.style.display = "none";
@@ -988,6 +1011,12 @@ const renderContent = () => {
content.style.padding = "0";
renderInfoTab(content);
return;
} else if (state.topTab === "ai") {
if (searchEl) searchEl.style.display = "none";
content.style.overflowY = "hidden";
content.style.padding = "0";
renderAiTab(content);
return;
} else {
if (searchEl) searchEl.style.display = "";
content.style.overflowY = "auto";
@@ -2726,6 +2755,423 @@ const renderInfoTab = (container) => {
renderInfoSubContent();
};
// ============================================
// AI Tab
// ============================================
const AI_SETTINGS_KEY = "wfm_ai_settings";
const AI_LANG_NAMES = { ja: "Japanese", en: "English", zh: "Chinese" };
function isValidAiUrl(url) {
try {
const u = new URL(url);
return u.protocol === "http:" || u.protocol === "https:";
} catch {
return false;
}
}
function loadAiCfg() {
try { return JSON.parse(localStorage.getItem(AI_SETTINGS_KEY) || "{}"); } catch { return {}; }
}
function saveAiCfg(patch) {
const d = { ...loadAiCfg(), ...patch };
localStorage.setItem(AI_SETTINGS_KEY, JSON.stringify(d));
return d;
}
async function aiCallLLM(url, backend, model, prompt) {
if (backend === "ollama") {
const r = await fetch(`${url}/api/generate`, {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, prompt, stream: false }),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return (await r.json()).response || "";
} else {
const r = await fetch(`${url}/v1/chat/completions`, {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, messages: [{ role: "user", content: prompt }], stream: false }),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
const d = await r.json();
return d.choices?.[0]?.message?.content || "";
}
}
function aiFileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = e => {
const b64 = e.target.result.split(",")[1];
resolve({ base64: b64, mimeType: file.type });
};
reader.onerror = reject;
reader.readAsDataURL(file);
});
}
async function aiCallVLM(url, backend, model, prompt, base64Image, mimeType) {
if (backend === "ollama") {
const r = await fetch(`${url}/api/generate`, {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model, prompt, images: [base64Image], stream: false }),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return (await r.json()).response || "";
} else {
const r = await fetch(`${url}/v1/chat/completions`, {
method: "POST", headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model,
messages: [{ role: "user", content: [
{ type: "text", text: prompt },
{ type: "image_url", image_url: { url: `data:${mimeType};base64,${base64Image}` } },
]}],
stream: false,
}),
});
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return (await r.json()).choices?.[0]?.message?.content || "";
}
}
async function aiFetchModels(url, backend) {
if (backend === "ollama") {
const r = await fetch(`${url}/api/tags`);
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return ((await r.json()).models || []).map(m => m.name);
} else {
const r = await fetch(`${url}/v1/models`);
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return ((await r.json()).data || []).map(m => m.id);
}
}
const renderAiTab = (container) => {
if (!container.querySelector(".wfm-nlp-ai-layout")) {
container.innerHTML = `
<div class="wfm-nlp-ai-layout">
<!-- 翻訳サブ -->
<div id="wfm-nlp-ai-translate" class="wfm-nlp-ai-pane">
<div class="wfm-nlp-ai-lang-row">
<select id="wfm-nlp-ai-src" class="wfm-nlp-ai-sel">
<option value="ja">日本語</option>
<option value="en">英語</option>
<option value="zh">中国語</option>
<option value="free">Free</option>
</select>
<button id="wfm-nlp-ai-swap" class="wfm-nlp-ai-swap" title="入替">⇄</button>
<select id="wfm-nlp-ai-dst" class="wfm-nlp-ai-sel">
<option value="en">英語</option>
<option value="ja">日本語</option>
<option value="zh">中国語</option>
<option value="free">Free</option>
</select>
</div>
<textarea id="wfm-nlp-ai-input" class="wfm-nlp-ai-textarea" placeholder="翻訳するテキストを入力..."></textarea>
<div class="wfm-nlp-ai-actions">
<button id="wfm-nlp-ai-trans-btn" class="wfm-nlp-ai-btn wfm-nlp-ai-btn-primary">翻訳</button>
<button id="wfm-nlp-ai-copy-btn" class="wfm-nlp-ai-btn">コピー</button>
<span id="wfm-nlp-ai-status" class="wfm-nlp-ai-status"></span>
</div>
<textarea id="wfm-nlp-ai-output" class="wfm-nlp-ai-textarea wfm-nlp-ai-output" placeholder="翻訳結果..." readonly></textarea>
</div>
<!-- VLM サブ -->
<div id="wfm-nlp-ai-vlm" class="wfm-nlp-ai-pane" style="display:none;">
<div class="wfm-nlp-ai-vlm-drop" id="wfm-nlp-ai-vlm-drop">
<img id="wfm-nlp-ai-vlm-preview" style="display:none;max-width:100%;max-height:100%;object-fit:contain;pointer-events:none;">
<span id="wfm-nlp-ai-vlm-label" class="wfm-nlp-ai-vlm-label">PNG / JPG / WebP をドロップ</span>
<input type="file" id="wfm-nlp-ai-vlm-file" accept="image/png,image/jpeg,image/webp" style="display:none;">
</div>
<div class="wfm-nlp-ai-row">
<select id="wfm-nlp-ai-vlm-task" class="wfm-nlp-ai-sel" style="flex:1;">
<option value="describe">画像の解説</option>
<option value="prompt">プロンプト作成</option>
</select>
<button id="wfm-nlp-ai-vlm-run" class="wfm-nlp-ai-btn wfm-nlp-ai-btn-primary">実行</button>
</div>
<span id="wfm-nlp-ai-vlm-status" class="wfm-nlp-ai-status"></span>
<textarea id="wfm-nlp-ai-vlm-result" class="wfm-nlp-ai-textarea wfm-nlp-ai-output" style="flex:1;min-height:60px;" placeholder="実行結果がここに表示されます..." readonly></textarea>
<button id="wfm-nlp-ai-vlm-copy" class="wfm-nlp-ai-btn" style="align-self:flex-end;">コピー</button>
</div>
<!-- 設定サブ -->
<div id="wfm-nlp-ai-settings" class="wfm-nlp-ai-pane wfm-nlp-ai-settings-pane" style="display:none;">
<div class="wfm-nlp-ai-sec">
<div class="wfm-nlp-ai-sec-title">バックエンド</div>
<div class="wfm-nlp-ai-radio-row">
<label class="wfm-nlp-ai-radio"><input type="radio" name="wfm-nlp-ai-backend" value="ollama"> Ollama</label>
<label class="wfm-nlp-ai-radio"><input type="radio" name="wfm-nlp-ai-backend" value="lmstudio"> LM Studio</label>
</div>
</div>
<div class="wfm-nlp-ai-sec">
<div class="wfm-nlp-ai-sec-title">接続設定</div>
<input type="text" id="wfm-nlp-ai-url" class="wfm-nlp-ai-input" placeholder="http://localhost:11434">
<div class="wfm-nlp-ai-row">
<button id="wfm-nlp-ai-test" class="wfm-nlp-ai-btn">接続テスト</button>
<span id="wfm-nlp-ai-test-result" class="wfm-nlp-ai-status"></span>
</div>
</div>
<div class="wfm-nlp-ai-sec">
<div class="wfm-nlp-ai-sec-title">モデル選択</div>
<div class="wfm-nlp-ai-row">
<select id="wfm-nlp-ai-model" class="wfm-nlp-ai-sel" style="flex:1;">
<option value="">-- モデルを選択 --</option>
</select>
<button id="wfm-nlp-ai-model-refresh" class="wfm-nlp-ai-btn">↻</button>
</div>
</div>
<div class="wfm-nlp-ai-sec">
<div class="wfm-nlp-ai-sec-title">Free 言語設定</div>
<div class="wfm-nlp-ai-row">
<span class="wfm-nlp-ai-lbl">入力</span>
<input type="text" id="wfm-nlp-ai-free-src" class="wfm-nlp-ai-input" placeholder="例: French" style="flex:1;">
</div>
<div class="wfm-nlp-ai-row">
<span class="wfm-nlp-ai-lbl">翻訳</span>
<input type="text" id="wfm-nlp-ai-free-dst" class="wfm-nlp-ai-input" placeholder="例: German" style="flex:1;">
</div>
</div>
<div class="wfm-nlp-ai-sec">
<button id="wfm-nlp-ai-save" class="wfm-nlp-ai-btn wfm-nlp-ai-btn-primary" style="width:100%;">設定を保存</button>
</div>
</div>
</div>
`;
setupAiHandlers(container);
}
renderAiSubContent();
};
const renderAiSubContent = () => {
if (!panelEl) return;
const panes = { "ai-translate": "wfm-nlp-ai-translate", "ai-vlm": "wfm-nlp-ai-vlm", "ai-settings": "wfm-nlp-ai-settings" };
for (const [key, id] of Object.entries(panes)) {
const el = panelEl.querySelector(`#${id}`);
if (el) el.style.display = state.aiSubTab === key ? "flex" : "none";
}
};
const setupAiHandlers = (container) => {
const cfg = loadAiCfg();
// Restore settings
const backendRadios = container.querySelectorAll("input[name='wfm-nlp-ai-backend']");
backendRadios.forEach(r => { if (r.value === (cfg.backend || "ollama")) r.checked = true; });
const urlInput = container.querySelector("#wfm-nlp-ai-url");
if (urlInput && cfg.backendUrl) urlInput.value = cfg.backendUrl;
else if (urlInput) urlInput.value = "http://localhost:11434";
const freeSrcInput = container.querySelector("#wfm-nlp-ai-free-src");
const freeDstInput = container.querySelector("#wfm-nlp-ai-free-dst");
if (freeSrcInput && cfg.freeSrcLang) freeSrcInput.value = cfg.freeSrcLang;
if (freeDstInput && cfg.freeDstLang) freeDstInput.value = cfg.freeDstLang;
const srcSel = container.querySelector("#wfm-nlp-ai-src");
const dstSel = container.querySelector("#wfm-nlp-ai-dst");
if (srcSel && cfg.srcLang) srcSel.value = cfg.srcLang;
if (dstSel && cfg.dstLang) dstSel.value = cfg.dstLang;
// Swap
container.querySelector("#wfm-nlp-ai-swap")?.addEventListener("click", () => {
const tmp = srcSel.value; srcSel.value = dstSel.value; dstSel.value = tmp;
const inputEl = container.querySelector("#wfm-nlp-ai-input");
const outputEl = container.querySelector("#wfm-nlp-ai-output");
const tmpTxt = inputEl.value; inputEl.value = outputEl.value; outputEl.value = tmpTxt;
saveAiCfg({ srcLang: srcSel.value, dstLang: dstSel.value });
});
srcSel?.addEventListener("change", () => saveAiCfg({ srcLang: srcSel.value }));
dstSel?.addEventListener("change", () => saveAiCfg({ dstLang: dstSel.value }));
// Translate
container.querySelector("#wfm-nlp-ai-trans-btn")?.addEventListener("click", async () => {
const text = container.querySelector("#wfm-nlp-ai-input")?.value?.trim();
if (!text) { showToast("テキストを入力してください", "error"); return; }
const c = loadAiCfg();
const backend = c.backend || "ollama";
const url = c.backendUrl || (backend === "ollama" ? "http://localhost:11434" : "http://localhost:1234");
const model = c.model;
if (!isValidAiUrl(url)) { showToast("URLは http:// または https:// で始まる必要があります", "error"); return; }
if (!model) { showToast("設定タブでモデルを選択してください", "error"); return; }
const srcLang = srcSel?.value || "ja";
const dstLang = dstSel?.value || "en";
const srcName = srcLang === "free" ? (c.freeSrcLang || "Auto") : AI_LANG_NAMES[srcLang];
const dstName = dstLang === "free" ? (c.freeDstLang || "English") : AI_LANG_NAMES[dstLang];
const fromPart = srcLang === "free" ? "" : `from ${srcName} `;
const prompt = `Translate the following text ${fromPart}to ${dstName}. Output only the translated text, nothing else.\n\n${text}`;
const transBtn = container.querySelector("#wfm-nlp-ai-trans-btn");
const statusEl = container.querySelector("#wfm-nlp-ai-status");
const outputEl = container.querySelector("#wfm-nlp-ai-output");
transBtn.disabled = true;
statusEl.textContent = "翻訳中...";
statusEl.className = "wfm-nlp-ai-status wfm-nlp-ai-working";
outputEl.value = "";
try {
const result = await aiCallLLM(url, backend, model, prompt);
outputEl.value = result.trim();
statusEl.textContent = "完了";
statusEl.className = "wfm-nlp-ai-status wfm-nlp-ai-ok";
} catch (err) {
statusEl.textContent = `エラー: ${err.message}`;
statusEl.className = "wfm-nlp-ai-status wfm-nlp-ai-err";
} finally {
transBtn.disabled = false;
}
});
// Copy
container.querySelector("#wfm-nlp-ai-copy-btn")?.addEventListener("click", () => {
const text = container.querySelector("#wfm-nlp-ai-output")?.value;
if (!text) { showToast("コピーするテキストがありません", "error"); return; }
navigator.clipboard.writeText(text).then(() => showToast("コピーしました", "success"));
});
// Model refresh helper
const refreshModels = async () => {
const c = loadAiCfg();
const backend = container.querySelector("input[name='wfm-nlp-ai-backend']:checked")?.value || "ollama";
const url = container.querySelector("#wfm-nlp-ai-url")?.value?.trim() || "";
const modelSel = container.querySelector("#wfm-nlp-ai-model");
try {
const models = await aiFetchModels(url, backend);
modelSel.innerHTML = '<option value="">-- モデルを選択 --</option>';
models.forEach(name => {
const opt = document.createElement("option");
opt.value = name; opt.textContent = name;
if (name === c.model) opt.selected = true;
modelSel.appendChild(opt);
});
if (!models.length) showToast("モデルが見つかりません", "error");
} catch (err) {
showToast("モデル取得失敗: " + err.message, "error");
}
};
// Connection test
container.querySelector("#wfm-nlp-ai-test")?.addEventListener("click", async () => {
const testBtn = container.querySelector("#wfm-nlp-ai-test");
const resultEl = container.querySelector("#wfm-nlp-ai-test-result");
const backend = container.querySelector("input[name='wfm-nlp-ai-backend']:checked")?.value || "ollama";
const url = container.querySelector("#wfm-nlp-ai-url")?.value?.trim() || "";
if (!isValidAiUrl(url)) {
resultEl.textContent = "http:// または https:// で始まるURLを入力してください";
resultEl.className = "wfm-nlp-ai-status wfm-nlp-ai-err";
return;
}
testBtn.disabled = true;
resultEl.textContent = "接続中...";
resultEl.className = "wfm-nlp-ai-status wfm-nlp-ai-working";
try {
const models = await aiFetchModels(url, backend);
resultEl.textContent = `OK (${models.length} モデル)`;
resultEl.className = "wfm-nlp-ai-status wfm-nlp-ai-ok";
await refreshModels();
} catch (err) {
resultEl.textContent = `失敗: ${err.message}`;
resultEl.className = "wfm-nlp-ai-status wfm-nlp-ai-err";
} finally {
testBtn.disabled = false;
}
});
// Model refresh button
container.querySelector("#wfm-nlp-ai-model-refresh")?.addEventListener("click", () => refreshModels());
// Save settings
container.querySelector("#wfm-nlp-ai-save")?.addEventListener("click", () => {
const backend = container.querySelector("input[name='wfm-nlp-ai-backend']:checked")?.value || "ollama";
const url = container.querySelector("#wfm-nlp-ai-url")?.value?.trim() || "";
const model = container.querySelector("#wfm-nlp-ai-model")?.value || "";
const freeSrcLang = container.querySelector("#wfm-nlp-ai-free-src")?.value?.trim() || "";
const freeDstLang = container.querySelector("#wfm-nlp-ai-free-dst")?.value?.trim() || "";
if (url && !isValidAiUrl(url)) {
showToast("URLは http:// または https:// で始まる必要があります", "error");
return;
}
saveAiCfg({ backend, backendUrl: url, model, freeSrcLang, freeDstLang });
showToast("設定を保存しました", "success");
});
// Auto-load models if settings exist
if (cfg.backendUrl && cfg.backend) refreshModels().catch(() => {});
// ---- VLM handlers ----
let vlmImage = null; // { base64, mimeType }
const vlmDrop = container.querySelector("#wfm-nlp-ai-vlm-drop");
const vlmPreview = container.querySelector("#wfm-nlp-ai-vlm-preview");
const vlmLabel = container.querySelector("#wfm-nlp-ai-vlm-label");
const vlmFile = container.querySelector("#wfm-nlp-ai-vlm-file");
const vlmRunBtn = container.querySelector("#wfm-nlp-ai-vlm-run");
const vlmStatus = container.querySelector("#wfm-nlp-ai-vlm-status");
const vlmResult = container.querySelector("#wfm-nlp-ai-vlm-result");
const vlmCopy = container.querySelector("#wfm-nlp-ai-vlm-copy");
const loadVlmImage = async (file) => {
if (!file || !file.type.startsWith("image/")) return;
const data = await aiFileToBase64(file);
vlmImage = data;
vlmPreview.src = `data:${data.mimeType};base64,${data.base64}`;
vlmPreview.style.display = "block";
vlmLabel.style.display = "none";
};
vlmDrop?.addEventListener("click", () => vlmFile?.click());
vlmFile?.addEventListener("change", e => { if (e.target.files[0]) loadVlmImage(e.target.files[0]); });
vlmDrop?.addEventListener("dragover", e => { e.preventDefault(); vlmDrop.classList.add("drag-over"); });
vlmDrop?.addEventListener("dragleave", () => vlmDrop.classList.remove("drag-over"));
vlmDrop?.addEventListener("drop", e => {
e.preventDefault();
vlmDrop.classList.remove("drag-over");
const file = e.dataTransfer.files[0];
if (file) loadVlmImage(file);
});
const VLM_PROMPTS = {
describe: "Describe this image in detail.",
prompt: "Create a detailed Stable Diffusion image generation prompt based on this image. Output only the prompt text, nothing else.",
};
vlmRunBtn?.addEventListener("click", async () => {
if (!vlmImage) { showToast("画像をドロップしてください", "error"); return; }
const c = loadAiCfg();
const backend = c.backend || "ollama";
const url = c.backendUrl || (backend === "ollama" ? "http://localhost:11434" : "http://localhost:1234");
const model = c.model;
if (!isValidAiUrl(url)) { showToast("URLは http:// または https:// で始まる必要があります", "error"); return; }
if (!model) { showToast("設定タブでモデルを選択してください", "error"); return; }
const task = container.querySelector("#wfm-nlp-ai-vlm-task")?.value || "describe";
vlmRunBtn.disabled = true;
vlmStatus.textContent = "実行中...";
vlmStatus.className = "wfm-nlp-ai-status wfm-nlp-ai-working";
vlmResult.value = "";
try {
const result = await aiCallVLM(url, backend, model, VLM_PROMPTS[task], vlmImage.base64, vlmImage.mimeType);
vlmResult.value = result.trim();
vlmStatus.textContent = "完了";
vlmStatus.className = "wfm-nlp-ai-status wfm-nlp-ai-ok";
} catch (err) {
vlmStatus.textContent = `エラー: ${err.message}`;
vlmStatus.className = "wfm-nlp-ai-status wfm-nlp-ai-err";
} finally {
vlmRunBtn.disabled = false;
}
});
vlmCopy?.addEventListener("click", () => {
const text = vlmResult?.value;
if (!text) { showToast("コピーするテキストがありません", "error"); return; }
navigator.clipboard.writeText(text).then(() => showToast("コピーしました", "success"));
});
};
// ============================================
// Save selected nodes as Node Set (context menu)
// ============================================
@@ -3371,6 +3817,192 @@ const injectStyles = () => {
color: var(--descrip-text, #aaa);
}
.wfm-nlp-theme-reset-btn:hover { color: var(--input-text, #ddd); }
/* AI Tab */
.wfm-nlp-ai-layout {
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
}
.wfm-nlp-ai-pane {
display: flex;
flex-direction: column;
flex: 1;
overflow: hidden;
gap: 6px;
padding: 8px;
}
.wfm-nlp-ai-settings-pane {
overflow-y: auto;
}
.wfm-nlp-ai-lang-row {
display: flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
}
.wfm-nlp-ai-sel {
flex: 1;
padding: 4px 6px;
background: var(--comfy-input-bg, #2a2a2a);
border: 1px solid var(--border-color, #4e4e4e);
border-radius: 3px;
color: var(--input-text, #ddd);
font-size: 11px;
outline: none;
}
.wfm-nlp-ai-swap {
flex-shrink: 0;
padding: 4px 6px;
font-size: 14px;
}
.wfm-nlp-ai-textarea {
flex: 1;
min-height: 80px;
padding: 6px 8px;
background: var(--comfy-input-bg, #2a2a2a);
border: 1px solid var(--border-color, #4e4e4e);
border-radius: 3px;
color: var(--input-text, #ddd);
font-size: 11px;
font-family: inherit;
resize: none;
outline: none;
line-height: 1.5;
box-sizing: border-box;
}
.wfm-nlp-ai-textarea:focus {
border-color: var(--p-button-background, #4a9eff);
}
.wfm-nlp-ai-output {
background: var(--comfy-menu-bg, #1e1e1e);
color: var(--descrip-text, #aaa);
}
.wfm-nlp-ai-output:focus { border-color: var(--border-color, #4e4e4e); }
.wfm-nlp-ai-actions {
display: flex;
align-items: center;
gap: 6px;
flex-shrink: 0;
}
.wfm-nlp-ai-status {
font-size: 10px;
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.wfm-nlp-ai-working { color: var(--wfm-warning, #ffa502); }
.wfm-nlp-ai-ok { color: #2ed573; }
.wfm-nlp-ai-err { color: #ff4757; }
.wfm-nlp-ai-btn {
padding: 4px 10px;
font-size: 11px;
font-weight: 600;
cursor: pointer;
border: 1px solid var(--border-color, #555);
border-radius: 3px;
background: none;
color: var(--descrip-text, #aaa);
transition: background 0.15s, color 0.15s;
white-space: nowrap;
}
.wfm-nlp-ai-btn:hover {
background: rgba(74,158,255,0.2);
color: #4a9eff;
border-color: #4a9eff;
}
.wfm-nlp-ai-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.wfm-nlp-ai-btn-primary {
background: var(--p-button-background, #4a9eff);
color: #fff;
border-color: var(--p-button-background, #4a9eff);
}
.wfm-nlp-ai-btn-primary:hover { background: #3a8eef; border-color: #3a8eef; color: #fff; }
.wfm-nlp-ai-coming {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
font-size: 11px;
color: var(--descrip-text, #888);
text-align: center;
padding: 16px;
}
.wfm-nlp-ai-sec {
display: flex;
flex-direction: column;
gap: 5px;
padding: 8px 0;
border-bottom: 1px solid var(--border-color, #3a3a3a);
}
.wfm-nlp-ai-sec:last-child { border-bottom: none; }
.wfm-nlp-ai-sec-title {
font-size: 9px;
font-weight: 700;
color: var(--descrip-text, #888);
text-transform: uppercase;
letter-spacing: 0.05em;
}
.wfm-nlp-ai-radio-row {
display: flex;
gap: 12px;
}
.wfm-nlp-ai-radio {
display: flex;
align-items: center;
gap: 4px;
font-size: 11px;
color: var(--input-text, #ddd);
cursor: pointer;
}
.wfm-nlp-ai-input {
padding: 5px 8px;
background: var(--comfy-input-bg, #2a2a2a);
border: 1px solid var(--border-color, #4e4e4e);
border-radius: 3px;
color: var(--input-text, #ddd);
font-size: 11px;
outline: none;
box-sizing: border-box;
}
.wfm-nlp-ai-input:focus { border-color: var(--p-button-background, #4a9eff); }
.wfm-nlp-ai-row {
display: flex;
align-items: center;
gap: 6px;
}
.wfm-nlp-ai-lbl {
font-size: 10px;
color: var(--descrip-text, #888);
white-space: nowrap;
width: 28px;
flex-shrink: 0;
}
/* VLM drop zone */
.wfm-nlp-ai-vlm-drop {
height: 110px;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
border: 2px dashed var(--border-color, #4e4e4e);
border-radius: 6px;
cursor: pointer;
overflow: hidden;
transition: border-color 0.15s, background 0.15s;
position: relative;
}
.wfm-nlp-ai-vlm-drop:hover,
.wfm-nlp-ai-vlm-drop.drag-over {
border-color: var(--p-button-background, #4a9eff);
background: rgba(74,158,255,0.04);
}
.wfm-nlp-ai-vlm-label {
font-size: 11px;
color: var(--descrip-text, #999);
pointer-events: none;
}
`;
document.head.appendChild(style);
};