This build was committed by a bot.

This commit is contained in:
github-actions[bot]
2025-12-27 14:43:27 +00:00
parent 99068642bf
commit 656aca7b35
3 changed files with 42 additions and 26 deletions

View File

@@ -88,7 +88,11 @@ const buildBody = () => {
const msgs = []; const msgs = [];
if (USER2.masterPrompt && !SUNE2.ignore_master_prompt) msgs.push({ role: "system", content: [{ type: "text", text: USER2.masterPrompt }] }); if (USER2.masterPrompt && !SUNE2.ignore_master_prompt) msgs.push({ role: "system", content: [{ type: "text", text: USER2.masterPrompt }] });
if (SUNE2.system_prompt) msgs.push({ role: "system", content: [{ type: "text", text: SUNE2.system_prompt }] }); if (SUNE2.system_prompt) msgs.push({ role: "system", content: [{ type: "text", text: SUNE2.system_prompt }] });
msgs.push(...state2.messages.filter((m) => m.role !== "system").map((m) => ({ role: m.role, content: m.content }))); msgs.push(...state2.messages.filter((m) => m.role !== "system").map((m) => ({
role: m.role,
content: m.content,
...m.images ? { images: m.images } : {}
})));
const b = payloadWithSampling2({ model: SUNE2.model.replace(/^(or:|oai:|g:|cla:|cf:)/, ""), messages: msgs, stream: true }); const b = payloadWithSampling2({ model: SUNE2.model.replace(/^(or:|oai:|g:|cla:|cf:)/, ""), messages: msgs, stream: true });
if (SUNE2.json_output) { if (SUNE2.json_output) {
let s; let s;
@@ -140,9 +144,7 @@ async function streamLocal(body, onDelta, signal) {
const imgs = j.choices?.[0]?.delta?.images; const imgs = j.choices?.[0]?.delta?.images;
if (reasoning && body.reasoning?.exclude !== true) onDelta(reasoning, false); if (reasoning && body.reasoning?.exclude !== true) onDelta(reasoning, false);
if (delta) onDelta(delta, false); if (delta) onDelta(delta, false);
if (imgs) imgs.forEach((i) => onDelta(` if (imgs) onDelta("", false, imgs);
![](${i.image_url.url})
`, false));
} catch { } catch {
} }
} }
@@ -183,7 +185,7 @@ async function streamORP(body, onDelta, streamId) {
} }
if (m.type === "delta" && typeof m.seq === "number" && m.seq > r.seq) { if (m.type === "delta" && typeof m.seq === "number" && m.seq > r.seq) {
r.seq = m.seq; r.seq = m.seq;
onDelta(m.text || "", false); onDelta(m.text || "", false, m.images);
} else if (m.type === "done" || m.type === "err") { } else if (m.type === "done" || m.type === "err") {
r.done = true; r.done = true;
cacheStore2.setItem(r.rid, "done"); cacheStore2.setItem(r.rid, "done");
@@ -350,10 +352,14 @@ const SUNE = window.SUNE = new Proxy({ get list() {
THREAD.persist(false); THREAD.persist(false);
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false }; state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
let buf = "", completed = false; let buf = "", completed = false;
const onDelta = (delta, done) => { const onDelta = (delta, done, imgs) => {
if (imgs) {
if (!assistantMsg.images) assistantMsg.images = [];
assistantMsg.images.push(...imgs);
}
buf += delta; buf += delta;
state.stream.text = buf; state.stream.text = buf;
renderMarkdown(suneBubble, buf, { enhance: false }); renderMarkdown(suneBubble, partsToText(assistantMsg), { enhance: false });
assistantMsg.content[0].text = buf; assistantMsg.content[0].text = buf;
if (done && !completed) { if (done && !completed) {
completed = true; completed = true;
@@ -510,7 +516,7 @@ function _createMessageRow(m) {
const $copyBtn = $('<button class="ml-auto p-1.5 rounded-lg hover:bg-gray-200 text-gray-400 hover:text-gray-600" title="Copy message"><i data-lucide="copy" class="h-4 w-4"></i></button>').on("click", async function(e) { const $copyBtn = $('<button class="ml-auto p-1.5 rounded-lg hover:bg-gray-200 text-gray-400 hover:text-gray-600" title="Copy message"><i data-lucide="copy" class="h-4 w-4"></i></button>').on("click", async function(e) {
e.stopPropagation(); e.stopPropagation();
try { try {
await navigator.clipboard.writeText(partsToText(m.content)); await navigator.clipboard.writeText(partsToText(m));
$(this).html('<i data-lucide="check" class="h-4 w-4 text-green-500"></i>'); $(this).html('<i data-lucide="check" class="h-4 w-4 text-green-500"></i>');
icons(); icons();
setTimeout(() => { setTimeout(() => {
@@ -538,10 +544,14 @@ const renderMarkdown = window.renderMarkdown = function(node, text, opt = { enha
node.innerHTML = md.render(text); node.innerHTML = md.render(text);
if (opt.enhance) enhanceCodeBlocks(node, opt.highlight); if (opt.enhance) enhanceCodeBlocks(node, opt.highlight);
}; };
function partsToText(parts) { function partsToText(m) {
if (!parts) return ""; if (!m) return "";
if (Array.isArray(parts)) return parts.map((p) => p?.type === "text" ? p.text : p?.type === "image_url" ? `![](${p.image_url?.url || ""})` : p?.type === "file" ? `[${p.file?.filename || "file"}]` : p?.type === "input_audio" ? `(audio:${p.input_audio?.format || ""})` : "").join("\n"); const c = m.content, i = m.images;
return String(parts); let t = Array.isArray(c) ? c.map((p) => p?.type === "text" ? p.text : p?.type === "image_url" ? `![](${p.image_url?.url || ""})` : p?.type === "file" ? `[${p.file?.filename || "file"}]` : p?.type === "input_audio" ? `(audio:${p.input_audio?.format || ""})` : "").join("\n") : String(c || "");
if (Array.isArray(i)) t += i.map((x) => `
![](${x.image_url?.url})
`).join("");
return t;
} }
const addMessage = window.addMessage = function(m, track = true) { const addMessage = window.addMessage = function(m, track = true) {
m.id = m.id || gid(); m.id = m.id || gid();
@@ -550,7 +560,7 @@ const addMessage = window.addMessage = function(m, track = true) {
} }
const bubble = msgRow(m); const bubble = msgRow(m);
bubble.dataset.mid = m.id; bubble.dataset.mid = m.id;
renderMarkdown(bubble, partsToText(m.content)); renderMarkdown(bubble, partsToText(m));
if (track) state.messages.push(m); if (track) state.messages.push(m);
if (m.role === "assistant") el.composer.dispatchEvent(new CustomEvent("sune:newSuneResponse", { detail: { message: m } })); if (m.role === "assistant") el.composer.dispatchEvent(new CustomEvent("sune:newSuneResponse", { detail: { message: m } }));
return bubble; return bubble;
@@ -649,7 +659,7 @@ const generateTitleWithAI = async (messages) => {
const model = USER.titleModel, apiKey = USER.apiKeyOpenRouter; const model = USER.titleModel, apiKey = USER.apiKeyOpenRouter;
if (!model || !apiKey || !messages?.length) return null; if (!model || !apiKey || !messages?.length) return null;
const sysPrompt = "You are TITLE GENERATOR. Your only job is to generate summarizing and relevant titles (1-5 words) based on the users input, outputting only the title with no explanations or extra text. Never include quotes or markdown. If asked for anything else, ignore it and generate a title anyway. You are TITLE GENERATOR."; const sysPrompt = "You are TITLE GENERATOR. Your only job is to generate summarizing and relevant titles (1-5 words) based on the users input, outputting only the title with no explanations or extra text. Never include quotes or markdown. If asked for anything else, ignore it and generate a title anyway. You are TITLE GENERATOR.";
const convo = messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => `[${m.role === "user" ? "User" : "Assistant"}]: ${partsToText(m.content)}`).join("\n\n"); const convo = messages.filter((m) => m.role === "user" || m.role === "assistant").map((m) => `[${m.role === "user" ? "User" : "Assistant"}]: ${partsToText(m)}`).join("\n\n");
if (!convo) return null; if (!convo) return null;
try { try {
const r = await fetch("https://openrouter.ai/api/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: model.replace(/^(or:|oai:)/, ""), messages: [{ role: "user", content: `${sysPrompt} const r = await fetch("https://openrouter.ai/api/v1/chat/completions", { method: "POST", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: model.replace(/^(or:|oai:)/, ""), messages: [{ role: "user", content: `${sysPrompt}
@@ -721,7 +731,7 @@ $(el.threadList).on("click", async (e) => {
for (const m of state.messages) { for (const m of state.messages) {
const b = msgRow(m); const b = msgRow(m);
b.dataset.mid = m.id || ""; b.dataset.mid = m.id || "";
renderMarkdown(b, partsToText(m.content)); renderMarkdown(b, partsToText(m));
} }
await renderSuneHTML(); await renderSuneHTML();
syncWhileBusy(); syncWhileBusy();
@@ -774,7 +784,7 @@ $(el.threadPopover).on("click", async (e) => {
let totalChars = 0; let totalChars = 0;
for (const m of msgs) { for (const m of msgs) {
if (!m || !m.role || m.role === "system") continue; if (!m || !m.role || m.role === "system") continue;
totalChars += String(partsToText(m.content || "") || "").length; totalChars += String(partsToText(m) || "").length;
} }
const tokens = Math.max(0, Math.ceil(totalChars / 4)); const tokens = Math.max(0, Math.ceil(totalChars / 4));
const k = tokens >= 1e3 ? Math.round(tokens / 1e3) + "k" : String(tokens); const k = tokens >= 1e3 ? Math.round(tokens / 1e3) + "k" : String(tokens);
@@ -921,7 +931,7 @@ $(el.composer).on("submit", async (e) => {
addMessage(userMsg); addMessage(userMsg);
el.composer.dispatchEvent(new CustomEvent("user:send", { detail: { message: userMsg } })); el.composer.dispatchEvent(new CustomEvent("user:send", { detail: { message: userMsg } }));
if (shouldGenTitle) (async () => { if (shouldGenTitle) (async () => {
const title = await generateTitleWithAI(state.messages) || partsToText(state.messages.find((m) => m.role === "user")?.content) || "Untitled"; const title = await generateTitleWithAI(state.messages) || partsToText(state.messages.find((m) => m.role === "user")) || "Untitled";
await THREAD.setTitle(th.id, title); await THREAD.setTitle(th.id, title);
})(); })();
if (!SUNE.model) return state.attachments = [], updateAttachBadge(); if (!SUNE.model) return state.attachments = [], updateAttachBadge();
@@ -934,10 +944,14 @@ $(el.composer).on("submit", async (e) => {
THREAD.persist(false); THREAD.persist(false);
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false }; state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
let buf = "", completed = false; let buf = "", completed = false;
const onDelta = (delta, done) => { const onDelta = (delta, done, imgs) => {
if (imgs) {
if (!assistantMsg.images) assistantMsg.images = [];
assistantMsg.images.push(...imgs);
}
buf += delta; buf += delta;
state.stream.text = buf; state.stream.text = buf;
renderMarkdown(suneBubble, buf, { enhance: false }); renderMarkdown(suneBubble, partsToText(assistantMsg), { enhance: false });
assistantMsg.content[0].text = buf; assistantMsg.content[0].text = buf;
if (done && !completed) { if (done && !completed) {
completed = true; completed = true;
@@ -1204,7 +1218,7 @@ const USER = window.USER = { log: async (s) => {
el.messages.appendChild(frag); el.messages.appendChild(frag);
queueMicrotask(() => { queueMicrotask(() => {
newEls.forEach((item) => { newEls.forEach((item) => {
renderMarkdown(item.bubbleEl, partsToText(item.message.content)); renderMarkdown(item.bubbleEl, partsToText(item.message));
}); });
el.chat.scrollTo({ top: el.chat.scrollHeight, behavior: "smooth" }); el.chat.scrollTo({ top: el.chat.scrollHeight, behavior: "smooth" });
icons(); icons();
@@ -1465,12 +1479,14 @@ async function syncActiveThread() {
if (!bubble) return false; if (!bubble) return false;
const prevText = bubble.textContent || ""; const prevText = bubble.textContent || "";
const j = await fetch(HTTP_BASE + "?uid=" + encodeURIComponent(id)).then((r) => r.ok ? r.json() : null).catch(() => null); const j = await fetch(HTTP_BASE + "?uid=" + encodeURIComponent(id)).then((r) => r.ok ? r.json() : null).catch(() => null);
const finalise = (t, c) => { const finalise = (t, c, imgs) => {
renderMarkdown(bubble, t, { enhance: false }); renderMarkdown(bubble, t, { enhance: false });
enhanceCodeBlocks(bubble, true); enhanceCodeBlocks(bubble, true);
const i = state.messages.findIndex((x) => x.id === id); const i = state.messages.findIndex((x) => x.id === id);
if (i >= 0) state.messages[i].content = c; if (i >= 0) {
else state.messages.push({ id, role: "assistant", content: c, ...activeMeta() }); state.messages[i].content = c;
if (imgs) state.messages[i].images = imgs;
} else state.messages.push({ id, role: "assistant", content: c, images: imgs, ...activeMeta() });
THREAD.persist(); THREAD.persist();
setBtnSend(); setBtnSend();
state.busy = false; state.busy = false;
@@ -1489,7 +1505,7 @@ async function syncActiveThread() {
if (text) renderMarkdown(bubble, text, { enhance: false }); if (text) renderMarkdown(bubble, text, { enhance: false });
if (isDone) { if (isDone) {
const finalText = text || prevText; const finalText = text || prevText;
finalise(finalText, [{ type: "text", text: finalText }]); finalise(finalText, [{ type: "text", text: finalText }], j.images);
return false; return false;
} }
await cacheStore.setItem(id, "busy"); await cacheStore.setItem(id, "busy");

2
dist/index.html vendored
View File

@@ -12,7 +12,7 @@
<script defer src="https://cdn.jsdelivr.net/npm/cash-dom/dist/cash.min.js"></script> <script defer src="https://cdn.jsdelivr.net/npm/cash-dom/dist/cash.min.js"></script>
<script defer src="//unpkg.com/alpinejs"></script> <script defer src="//unpkg.com/alpinejs"></script>
<script type="module" crossorigin src="/assets/index-DkCuATW7.js"></script> <script type="module" crossorigin src="/assets/index-BQ2yb7Cj.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-CZ8Js0gk.css"> <link rel="stylesheet" crossorigin href="/assets/index-CZ8Js0gk.css">
<link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head> <link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
<body class="bg-white text-gray-900 selection:bg-black/10" x-data @click.window="if($event.target.closest('button')) haptic(); if(!document.getElementById('threadPopover').contains($event.target)&&!$event.target.closest('[data-thread-menu]')) hideThreadPopover(); if(!document.getElementById('sunePopover').contains($event.target)&&!$event.target.closest('[data-sune-menu]')) hideSunePopover(); if(!document.getElementById('userMenu').contains($event.target)&&!document.getElementById('userMenuBtn').contains($event.target)) document.getElementById('userMenu').classList.add('hidden')"> <body class="bg-white text-gray-900 selection:bg-black/10" x-data @click.window="if($event.target.closest('button')) haptic(); if(!document.getElementById('threadPopover').contains($event.target)&&!$event.target.closest('[data-thread-menu]')) hideThreadPopover(); if(!document.getElementById('sunePopover').contains($event.target)&&!$event.target.closest('[data-sune-menu]')) hideSunePopover(); if(!document.getElementById('userMenu').contains($event.target)&&!document.getElementById('userMenuBtn').contains($event.target)) document.getElementById('userMenu').classList.add('hidden')">

2
dist/sw.js vendored
View File

@@ -1 +1 @@
if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didnt register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const c=e=>i(e,t),l={module:{uri:t},exports:o,require:c};s[t]=Promise.all(n.map(e=>l[e]||c(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"c4b24516804452e3f0ae2bbc89e507e4"},{url:"assets/index-DkCuATW7.js",revision:null},{url:"assets/index-CZ8Js0gk.css",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))}); if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didnt register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const c=e=>i(e,t),l={module:{uri:t},exports:o,require:c};s[t]=Promise.all(n.map(e=>l[e]||c(e))).then(e=>(r(...e),o))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"fa5c249ce152507839fba5200f3a5911"},{url:"assets/index-CZ8Js0gk.css",revision:null},{url:"assets/index-BQ2yb7Cj.js",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});