From 240d6d5f15607e24f9baa46e993da84b055d9bcd Mon Sep 17 00:00:00 2001 From: qnsh Date: Sat, 29 Aug 2026 20:43:10 +0800 Subject: [PATCH] clean code --- openai/openai_text_node.py | 7 ++- web/js/preview_api_result.js | 100 ++++++++++++++++------------------- 2 files changed, 50 insertions(+), 57 deletions(-) diff --git a/openai/openai_text_node.py b/openai/openai_text_node.py index 85ca4f4..976f0c2 100644 --- a/openai/openai_text_node.py +++ b/openai/openai_text_node.py @@ -6,7 +6,7 @@ from aiohttp import web from server import PromptServer from comfy_api.latest import io -from ..utils.config_utils import get_api_config, get_api_names, get_openai_apis +from ..utils.config_utils import get_api_config, get_openai_apis from ..utils.image_utils import tensor_to_base64_string from ..utils.request_utils import ( get_proxy_config, @@ -343,10 +343,9 @@ class OpenAITextAPI(io.ComfyNode): if protocol == "openai-completions": history = list(cls._conversation_history.get(key, [])) if persist_context and not skill.enabled else [] - effective_system = system_prompt request_history = [] if skill.enabled else history - if not request_history and effective_system: - request_history.append({"role": "system", "content": effective_system}) + if not request_history and system_prompt: + request_history.append({"role": "system", "content": system_prompt}) content = [{"type": "text", "text": user_prompt}] + _image_parts(images, protocol) if video_uri: content.append({"type": "video_url", "video_url": {"url": video_uri}}) diff --git a/web/js/preview_api_result.js b/web/js/preview_api_result.js index f482272..9ab6430 100644 --- a/web/js/preview_api_result.js +++ b/web/js/preview_api_result.js @@ -170,7 +170,6 @@ function typingRate(state) { function renderNow(state) { const followTail = isNearBottom(state.content); const raw = state.displayedText || ""; - state.host.dataset.hasContent = raw ? "true" : "false"; if (!raw) { state.content.replaceChildren(); if (!["waiting", "loading_skill", "reading_skill", "reasoning", "drafting", "tool_running", "promoting", "generating", "displaying", "error"].includes(state.statusKey)) { @@ -184,6 +183,7 @@ function renderNow(state) { if (!parser?.parse) { state.content.textContent = raw; setStatus(state, "error", "marked.umd.js unavailable"); + renderActivity(state); } else { const html = parser.parse(raw, { gfm: true, breaks: true }); state.content.innerHTML = sanitizeMarkedHtml(html); @@ -222,16 +222,11 @@ function setStatus(state, key, detail = "") { ? `${message("error")}: ${detail}` : message(key); state.status.hidden = !visible; - // Status is rendered in the dedicated lower process box, so update its - // visibility whenever the state changes. - renderActivity(state); } function appendActivity(state, entry) { - state.activityLog.push({ ...entry, time: Date.now() }); + state.activityLog.push(entry); if (state.activityLog.length > 20) state.activityLog.splice(0, state.activityLog.length - 20); - state.activityExpanded = true; - renderActivity(state); } function renderActivity(state) { @@ -274,9 +269,7 @@ function renderActivity(state) { } function updateCopyAvailability(state) { - // Only confirmed answer text is copyable. Intermediate candidate text, - // reasoning and activity records must never leak through the copy action. - state.copyButton.disabled = !(state.answerText || state.finalText); + state.copyButton.disabled = !state.finalText; } function setCopyState(state, copyState) { @@ -306,7 +299,7 @@ function showCopyToast(success) { } async function copyRawText(state) { - const text = state.answerText || state.finalText; + const text = state.finalText; if (!text) return; try { if (navigator.clipboard?.writeText && window.isSecureContext) { @@ -356,7 +349,6 @@ function finishTypingIfReady(state) { state.receivedText = state.finalText; state.streaming = false; state.activeRunId = null; - state.promptId = null; if (state.terminalError) { setStatus(state, "error", state.terminalError); } else { @@ -523,7 +515,7 @@ function createPreview(node) { .preview[data-state="loading_skill"] .status, .preview[data-state="reading_skill"] .status, .preview[data-state="reasoning"] .status, - .preview[data-state="error"][data-has-content="false"] .status { transform: none; } + .preview[data-state="error"] .status { transform: none; } .preview[data-state="error"] .status { color: #fca5a5; opacity: .95; } h1, h2, h3, h4, h5, h6 { margin: 1.1em 0 .55em; line-height: 1.25; } h1 { font-size: 1.55em; } h2 { font-size: 1.35em; } h3 { font-size: 1.18em; } @@ -546,7 +538,7 @@ function createPreview(node) { .preview[data-state="displaying"] .content::after { display: none; } } -
+