This build was committed by a bot.

This commit is contained in:
github-actions[bot]
2025-11-12 04:12:32 +00:00
parent 0ecab9db7d
commit 062a86266e
3 changed files with 15 additions and 31 deletions

View File

@@ -213,25 +213,17 @@ const SUNE = window.SUNE = new Proxy({ get list() {
state.messages.push(assistantMsg);
THREAD.persist(false);
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
let contentBuf = "", reasoningBuf = "", completed = false, reasoningEl = null;
let buf = "", completed = false;
const onDelta = (delta, done) => {
contentBuf += delta.content;
reasoningBuf += delta.reasoning;
state.stream.text = contentBuf;
renderMarkdown(suneBubble, contentBuf, { enhance: false });
assistantMsg.content[0].text = contentBuf;
if (reasoningBuf && !reasoningEl) {
reasoningEl = document.createElement("div");
reasoningEl.className = "markdown-body rounded-none px-4 py-3 w-full bg-blue-50 border-l-4 border-blue-300 text-sm text-gray-600";
suneBubble.parentElement.insertBefore(reasoningEl, suneBubble);
}
if (reasoningEl) renderMarkdown(reasoningEl, reasoningBuf, { enhance: false });
buf += delta;
state.stream.text = buf;
renderMarkdown(suneBubble, buf, { enhance: false });
assistantMsg.content[0].text = buf;
if (done && !completed) {
completed = true;
setBtnSend();
state.busy = false;
enhanceCodeBlocks(suneBubble, true);
if (reasoningEl) enhanceCodeBlocks(reasoningEl, true);
THREAD.persist(true);
el.composer.dispatchEvent(new CustomEvent("sune:newSuneResponse", { detail: { message: assistantMsg } }));
state.stream = { rid: null, bubble: null, meta: null, text: "", done: false };
@@ -805,25 +797,17 @@ $(el.composer).on("submit", async (e) => {
state.messages.push(assistantMsg);
THREAD.persist(false);
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
let contentBuf = "", reasoningBuf = "", completed = false, reasoningEl = null;
let buf = "", completed = false;
const onDelta = (delta, done) => {
contentBuf += delta.content;
reasoningBuf += delta.reasoning;
state.stream.text = contentBuf;
renderMarkdown(suneBubble, contentBuf, { enhance: false });
assistantMsg.content[0].text = contentBuf;
if (reasoningBuf && !reasoningEl) {
reasoningEl = document.createElement("div");
reasoningEl.className = "markdown-body rounded-none px-4 py-3 w-full bg-blue-50 border-l-4 border-blue-300 text-sm text-gray-600";
suneBubble.parentElement.insertBefore(reasoningEl, suneBubble);
}
if (reasoningEl) renderMarkdown(reasoningEl, reasoningBuf, { enhance: false });
buf += delta;
state.stream.text = buf;
renderMarkdown(suneBubble, buf, { enhance: false });
assistantMsg.content[0].text = buf;
if (done && !completed) {
completed = true;
setBtnSend();
state.busy = false;
enhanceCodeBlocks(suneBubble, true);
if (reasoningEl) enhanceCodeBlocks(reasoningEl, true);
THREAD.persist(true);
el.composer.dispatchEvent(new CustomEvent("sune:newSuneResponse", { detail: { message: assistantMsg } }));
state.stream = { rid: null, bubble: null, meta: null, text: "", done: false };
@@ -1211,7 +1195,7 @@ const buildBody = () => {
async function askOpenRouterStreaming(onDelta, streamId) {
const model = SUNE.model, provider = model.startsWith("oai:") ? "openai" : model.startsWith("g:") ? "google" : model.startsWith("cla:") ? "claude" : model.startsWith("cf:") ? "cloudflare" : model.startsWith("or:") ? "openrouter" : USER.provider, apiKey = provider === "openai" ? USER.apiKeyOpenAI : provider === "google" ? USER.apiKeyGoogle : provider === "claude" ? USER.apiKeyClaude : provider === "cloudflare" ? USER.apiKeyCloudflare : USER.apiKeyOpenRouter;
if (!apiKey) {
onDelta({ content: localDemoReply(), reasoning: "" }, true);
onDelta(localDemoReply(), true);
return { ok: true, rid: streamId || null };
}
const r = { rid: streamId || gid(), seq: -1, done: false, signaled: false, ws: null };
@@ -1219,7 +1203,7 @@ async function askOpenRouterStreaming(onDelta, streamId) {
const signal = (t) => {
if (!r.signaled) {
r.signaled = true;
onDelta({ content: t || "", reasoning: "" }, true);
onDelta(t || "", true);
}
};
const ws = new WebSocket(HTTP_BASE.replace("https", "wss") + "?uid=" + encodeURIComponent(r.rid));
@@ -1234,7 +1218,7 @@ async function askOpenRouterStreaming(onDelta, streamId) {
}
if (m.type === "delta" && typeof m.seq === "number" && m.seq > r.seq) {
r.seq = m.seq;
onDelta({ content: m.content || "", reasoning: m.reasoning || "" }, false);
onDelta(m.text || "", false);
} else if (m.type === "done" || m.type === "err") {
r.done = true;
cacheStore.setItem(r.rid, "done");