mirror of
https://github.com/multipleof4/sune.git
synced 2026-01-14 00:27:56 +00:00
This build was committed by a bot.
This commit is contained in:
@@ -93,7 +93,7 @@ const __vitePreload = function preload(baseModule, deps, importerUrl) {
|
||||
};
|
||||
})();
|
||||
const DEFAULT_MODEL = "google/gemini-2.5-pro", DEFAULT_API_KEY = "";
|
||||
const el = window.el = Object.fromEntries(["topbar", "chat", "messages", "composer", "input", "sendBtn", "suneBtnTop", "suneModal", "suneURL", "settingsForm", "closeSettings", "cancelSettings", "tabModel", "tabPrompt", "tabScript", "panelModel", "panelPrompt", "panelScript", "set_model", "set_temperature", "set_top_p", "set_top_k", "set_frequency_penalty", "set_repetition_penalty", "set_min_p", "set_top_a", "set_verbosity", "set_reasoning_effort", "set_system_prompt", "set_hide_composer", "set_include_thoughts", "set_json_output", "set_ignore_master_prompt", "deleteSuneBtn", "sidebarLeft", "sidebarOverlayLeft", "sidebarBtnLeft", "suneList", "newSuneBtn", "userMenuBtn", "userMenu", "accountSettingsOption", "sunesImportOption", "sunesExportOption", "threadsImportOption", "threadsExportOption", "importInput", "sidebarBtnRight", "sidebarRight", "sidebarOverlayRight", "threadList", "closeThreads", "threadPopover", "sunePopover", "footer", "attachBtn", "attachBadge", "fileInput", "htmlEditor", "extensionHtmlEditor", "jsonSchemaEditor", "htmlTab_index", "htmlTab_extension", "suneHtml", "accountSettingsModal", "accountSettingsForm", "closeAccountSettings", "cancelAccountSettings", "set_master_prompt", "set_provider", "set_api_key_or", "set_api_key_oai", "set_api_key_g", "set_api_key_claude", "set_api_key_cf", "set_title_model", "copySystemPrompt", "pasteSystemPrompt", "copyHTML", "pasteHTML", "accountTabGeneral", "accountTabAPI", "accountPanelGeneral", "accountPanelAPI", "set_gh_token", "gcpSAInput", "gcpSAUploadBtn", "importAccountSettings", "exportAccountSettings", "importAccountSettingsInput", "accountTabUser", "accountPanelUser", "set_user_name", "userAvatarPreview", "setUserAvatarBtn", "userAvatarInput", "set_donor"].map((id) => [id, $("#" + id)[0]]));
|
||||
const el = window.el = Object.fromEntries(["topbar", "chat", "messages", "composer", "input", "sendBtn", "suneBtnTop", "suneModal", "suneURL", "settingsForm", "closeSettings", "cancelSettings", "tabModel", "tabPrompt", "tabScript", "panelModel", "panelPrompt", "panelScript", "set_model", "set_temperature", "set_top_p", "set_top_k", "set_frequency_penalty", "set_repetition_penalty", "set_min_p", "set_top_a", "set_verbosity", "set_reasoning_effort", "set_system_prompt", "set_hide_composer", "set_include_thoughts", "set_json_output", "set_img_output", "set_ignore_master_prompt", "deleteSuneBtn", "sidebarLeft", "sidebarOverlayLeft", "sidebarBtnLeft", "suneList", "newSuneBtn", "userMenuBtn", "userMenu", "accountSettingsOption", "sunesImportOption", "sunesExportOption", "threadsImportOption", "threadsExportOption", "importInput", "sidebarBtnRight", "sidebarRight", "sidebarOverlayRight", "threadList", "closeThreads", "threadPopover", "sunePopover", "footer", "attachBtn", "attachBadge", "fileInput", "htmlEditor", "extensionHtmlEditor", "jsonSchemaEditor", "htmlTab_index", "htmlTab_extension", "suneHtml", "accountSettingsModal", "accountSettingsForm", "closeAccountSettings", "cancelAccountSettings", "set_master_prompt", "set_provider", "set_api_key_or", "set_api_key_oai", "set_api_key_g", "set_api_key_claude", "set_api_key_cf", "set_title_model", "copySystemPrompt", "pasteSystemPrompt", "copyHTML", "pasteHTML", "accountTabGeneral", "accountTabAPI", "accountPanelGeneral", "accountPanelAPI", "set_gh_token", "gcpSAInput", "gcpSAUploadBtn", "importAccountSettings", "exportAccountSettings", "importAccountSettingsInput", "accountTabUser", "accountPanelUser", "set_user_name", "userAvatarPreview", "setUserAvatarBtn", "userAvatarInput", "set_donor"].map((id) => [id, $("#" + id)[0]]));
|
||||
const icons = () => window.lucide && lucide.createIcons();
|
||||
const haptic = () => /android/i.test(navigator.userAgent) && navigator.vibrate?.(1);
|
||||
const clamp = (v, min, max) => Math.max(min, Math.min(max, v)), num = (v, d) => v == null || v === "" || isNaN(+v) ? d : +v, int = (v, d) => v == null || v === "" || isNaN(parseInt(v)) ? d : parseInt(v), gid = () => Math.random().toString(36).slice(2, 9), esc = (s) => String(s).replace(/[&<>'"`]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'", "`": "`" })[c]), positionPopover = (a, p) => {
|
||||
@@ -146,7 +146,7 @@ const su = { key: "sunes_v1", activeKey: "active_sune_id", load() {
|
||||
}, setActiveId(id) {
|
||||
localStorage.setItem(this.activeKey, id || "");
|
||||
} };
|
||||
const defaultSettings = { model: DEFAULT_MODEL, temperature: "", top_p: "", top_k: "", frequency_penalty: "", repetition_penalty: "", min_p: "", top_a: "", verbosity: "", reasoning_effort: "default", system_prompt: "", html: "", extension_html: "<sune src='https://raw.githubusercontent.com/sune-org/store/refs/heads/main/sync.sune' private></sune>", hide_composer: false, include_thoughts: false, json_output: false, ignore_master_prompt: false, json_schema: "" };
|
||||
const defaultSettings = { model: DEFAULT_MODEL, temperature: "", top_p: "", top_k: "", frequency_penalty: "", repetition_penalty: "", min_p: "", top_a: "", verbosity: "", reasoning_effort: "default", system_prompt: "", html: "", extension_html: "<sune src='https://raw.githubusercontent.com/sune-org/store/refs/heads/main/sync.sune' private></sune>", hide_composer: false, include_thoughts: false, json_output: false, img_output: false, ignore_master_prompt: false, json_schema: "" };
|
||||
const makeSune = (p = {}) => ({ id: p.id || gid(), name: p.name?.trim() || "Default", pinned: !!p.pinned, avatar: p.avatar || "", url: p.url || "", updatedAt: p.updatedAt || Date.now(), settings: Object.assign({}, defaultSettings, p.settings || {}), storage: p.storage || {} });
|
||||
let sunes = (su.load() || []).map(makeSune);
|
||||
const SUNE = window.SUNE = new Proxy({ get list() {
|
||||
@@ -214,11 +214,29 @@ const SUNE = window.SUNE = new Proxy({ get list() {
|
||||
THREAD.persist(false);
|
||||
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
|
||||
let buf = "", completed = false;
|
||||
const onDelta = (delta, done) => {
|
||||
buf += delta;
|
||||
state.stream.text = buf;
|
||||
renderMarkdown(suneBubble, buf, { enhance: false });
|
||||
assistantMsg.content[0].text = buf;
|
||||
const onDelta = (chunk, done) => {
|
||||
const deltaText = chunk.text || "", deltaImages = chunk.images || [];
|
||||
if (deltaText) {
|
||||
buf += deltaText;
|
||||
state.stream.text = buf;
|
||||
renderMarkdown(suneBubble, buf, { enhance: false });
|
||||
assistantMsg.content[0].text = buf;
|
||||
}
|
||||
if (deltaImages.length) {
|
||||
let c = suneBubble.querySelector(".img-container");
|
||||
if (!c) {
|
||||
c = document.createElement("div");
|
||||
c.className = "img-container mt-2 flex flex-wrap gap-2";
|
||||
suneBubble.appendChild(c);
|
||||
}
|
||||
deltaImages.forEach((img) => {
|
||||
const i = document.createElement("img");
|
||||
i.src = img.image_url.url;
|
||||
i.className = "max-w-xs rounded-lg border";
|
||||
c.appendChild(i);
|
||||
assistantMsg.content.push(img);
|
||||
});
|
||||
}
|
||||
if (done && !completed) {
|
||||
completed = true;
|
||||
setBtnSend();
|
||||
@@ -404,7 +422,7 @@ const renderMarkdown = window.renderMarkdown = function(node, text, opt = { enha
|
||||
};
|
||||
function partsToText(parts) {
|
||||
if (!parts) return "";
|
||||
if (Array.isArray(parts)) return parts.map((p) => p?.type === "text" ? p.text : p?.type === "image_url" ? `` : p?.type === "file" ? `[${p.file?.filename || "file"}]` : p?.type === "input_audio" ? `(audio:${p.input_audio?.format || ""})` : "").join("\n");
|
||||
if (Array.isArray(parts)) return parts.map((p) => p?.type === "text" ? p.text : p?.type === "file" ? `[${p.file?.filename || "file"}]` : p?.type === "input_audio" ? `(audio:${p.input_audio?.format || ""})` : "").filter(Boolean).join("\n");
|
||||
return String(parts);
|
||||
}
|
||||
const addMessage = window.addMessage = function(m, track = true) {
|
||||
@@ -415,6 +433,8 @@ const addMessage = window.addMessage = function(m, track = true) {
|
||||
const bubble = msgRow(m);
|
||||
bubble.dataset.mid = m.id;
|
||||
renderMarkdown(bubble, partsToText(m.content));
|
||||
const imageParts = (Array.isArray(m.content) ? m.content : []).filter((p) => p.type === "image_url");
|
||||
if (imageParts.length) bubble.insertAdjacentHTML("beforeend", `<div class="mt-2 flex flex-wrap gap-2">${imageParts.map((p) => `<img src="${esc(p.image_url.url)}" class="max-w-xs rounded-lg border">`).join("")}</div>`);
|
||||
if (track) state.messages.push(m);
|
||||
if (m.role === "assistant") el.composer.dispatchEvent(new CustomEvent("sune:newSuneResponse", { detail: { message: m } }));
|
||||
return bubble;
|
||||
@@ -582,11 +602,7 @@ $(el.threadList).on("click", async (e) => {
|
||||
state.currentThreadId = id;
|
||||
clearChat();
|
||||
state.messages = Array.isArray(th.messages) ? [...th.messages] : [];
|
||||
for (const m of state.messages) {
|
||||
const b = msgRow(m);
|
||||
b.dataset.mid = m.id || "";
|
||||
renderMarkdown(b, partsToText(m.content));
|
||||
}
|
||||
for (const m of state.messages) addMessage(m, false);
|
||||
await renderSuneHTML();
|
||||
syncWhileBusy();
|
||||
queueMicrotask(() => el.chat.scrollTo({ top: el.chat.scrollHeight, behavior: "smooth" }));
|
||||
@@ -798,11 +814,29 @@ $(el.composer).on("submit", async (e) => {
|
||||
THREAD.persist(false);
|
||||
state.stream = { rid: streamId, bubble: suneBubble, meta: suneMeta, text: "", done: false };
|
||||
let buf = "", completed = false;
|
||||
const onDelta = (delta, done) => {
|
||||
buf += delta;
|
||||
state.stream.text = buf;
|
||||
renderMarkdown(suneBubble, buf, { enhance: false });
|
||||
assistantMsg.content[0].text = buf;
|
||||
const onDelta = (chunk, done) => {
|
||||
const deltaText = chunk.text || "", deltaImages = chunk.images || [];
|
||||
if (deltaText) {
|
||||
buf += deltaText;
|
||||
state.stream.text = buf;
|
||||
renderMarkdown(suneBubble, buf, { enhance: false });
|
||||
assistantMsg.content[0].text = buf;
|
||||
}
|
||||
if (deltaImages.length) {
|
||||
let c = suneBubble.querySelector(".img-container");
|
||||
if (!c) {
|
||||
c = document.createElement("div");
|
||||
c.className = "img-container mt-2 flex flex-wrap gap-2";
|
||||
suneBubble.appendChild(c);
|
||||
}
|
||||
deltaImages.forEach((img) => {
|
||||
const i = document.createElement("img");
|
||||
i.src = img.image_url.url;
|
||||
i.className = "max-w-xs rounded-lg border";
|
||||
c.appendChild(i);
|
||||
assistantMsg.content.push(img);
|
||||
});
|
||||
}
|
||||
if (done && !completed) {
|
||||
completed = true;
|
||||
setBtnSend();
|
||||
@@ -844,6 +878,7 @@ function openSettings() {
|
||||
el.set_system_prompt.value = s.system_prompt;
|
||||
el.set_hide_composer.checked = !!s.hide_composer;
|
||||
el.set_json_output.checked = !!s.json_output;
|
||||
el.set_img_output.checked = !!s.img_output;
|
||||
el.set_include_thoughts.checked = !!s.include_thoughts;
|
||||
el.set_ignore_master_prompt.checked = !!s.ignore_master_prompt;
|
||||
showTab("Model");
|
||||
@@ -891,6 +926,7 @@ $(el.settingsForm).on("submit", async (e) => {
|
||||
SUNE.system_prompt = el.set_system_prompt.value.trim();
|
||||
SUNE.hide_composer = el.set_hide_composer.checked;
|
||||
SUNE.json_output = el.set_json_output.checked;
|
||||
SUNE.img_output = el.set_img_output.checked;
|
||||
SUNE.include_thoughts = el.set_include_thoughts.checked;
|
||||
SUNE.ignore_master_prompt = el.set_ignore_master_prompt.checked;
|
||||
SUNE.json_schema = el.jsonSchemaEditor.textContent;
|
||||
@@ -1191,6 +1227,7 @@ const buildBody = () => {
|
||||
b.response_format = { type: "json_object" };
|
||||
}
|
||||
}
|
||||
if (SUNE.img_output) b.modalities = ["image", "text"];
|
||||
b.reasoning = { ...SUNE.reasoning_effort && SUNE.reasoning_effort !== "default" ? { effort: SUNE.reasoning_effort } : {}, exclude: !SUNE.include_thoughts };
|
||||
if (SUNE.verbosity) b.verbosity = SUNE.verbosity;
|
||||
return b;
|
||||
@@ -1198,7 +1235,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(localDemoReply(), true);
|
||||
onDelta({ text: localDemoReply() }, true);
|
||||
return { ok: true, rid: streamId || null };
|
||||
}
|
||||
const r = { rid: streamId || gid(), seq: -1, done: false, signaled: false, ws: null };
|
||||
@@ -1206,7 +1243,7 @@ async function askOpenRouterStreaming(onDelta, streamId) {
|
||||
const signal = (t) => {
|
||||
if (!r.signaled) {
|
||||
r.signaled = true;
|
||||
onDelta(t || "", true);
|
||||
onDelta({ text: t || "" }, true);
|
||||
}
|
||||
};
|
||||
const ws = new WebSocket(HTTP_BASE.replace("https", "wss") + "?uid=" + encodeURIComponent(r.rid));
|
||||
@@ -1221,7 +1258,7 @@ async function askOpenRouterStreaming(onDelta, streamId) {
|
||||
}
|
||||
if (m.type === "delta" && typeof m.seq === "number" && m.seq > r.seq) {
|
||||
r.seq = m.seq;
|
||||
onDelta(m.text || "", false);
|
||||
onDelta(m, false);
|
||||
} else if (m.type === "done" || m.type === "err") {
|
||||
r.done = true;
|
||||
cacheStore.setItem(r.rid, "done");
|
||||
Reference in New Issue
Block a user