Compare commits

1 Commits

Author SHA1 Message Date
github-actions[bot]
4fcda90f81 This build was committed by a bot. 2026-05-16 05:24:24 +00:00
5 changed files with 12 additions and 71 deletions

View File

@@ -526,38 +526,6 @@ var parseGhUrl = (u) => {
apiPath: `${owner}/${repo}/contents${path ? "/" + path : ""}`
};
};
var ghGetFileContent = async (info, fileName) => {
const meta = await ghApi(`${info.apiPath}/${fileName}?ref=${info.branch}`);
if (!meta) {
console.warn("[Sune] GH file not found:", fileName);
return null;
}
console.log("[Sune] GH file meta:", {
name: fileName,
size: meta.size,
encoding: meta.encoding,
hasContent: !!(meta.content && meta.content.trim()),
sha: meta.sha
});
if (meta.content && meta.encoding === "base64") try {
return btou(meta.content);
} catch (e) {
console.error("[Sune] decode (contents) failed:", e);
}
if (meta.sha) try {
const blob = await ghApi(`${info.owner}/${info.repo}/git/blobs/${meta.sha}`);
console.log("[Sune] GH blob:", {
size: blob?.size,
encoding: blob?.encoding,
hasContent: !!(blob?.content && blob.content.trim())
});
if (blob && blob.content && blob.encoding === "base64") return btou(blob.content);
} catch (e) {
console.error("[Sune] blob fetch failed:", e);
}
console.warn("[Sune] Could not retrieve content for", fileName);
return null;
};
//#endregion
//#region src/markdown.js
var md = window.md = window.markdownit({
@@ -839,7 +807,7 @@ var __vitePreload = function preload(baseModule, deps, importerUrl) {
o != k && ((k = o) ? (history.pushState({ k: 1 }, ""), addEventListener("popstate", f)) : (removeEventListener("popstate", f), history.state?.k && history.back()));
};
})();
var DEFAULT_MODEL = "anthropic/claude-opus-4.8";
var DEFAULT_MODEL = "anthropic/claude-opus-4.7";
var icons = () => window.lucide && lucide.createIcons();
var haptic = () => /android/i.test(navigator.userAgent) && navigator.vibrate?.(1);
var su = {
@@ -1363,19 +1331,16 @@ $(el.threadList).on("click", async (e) => {
clearChat();
const u = el.threadRepoInput.value.trim(), prefix = u.startsWith("gh://") ? "rem_t_" : "t_";
let msgs = await localforage.getItem(prefix + id);
if ((!msgs || !Array.isArray(msgs) || !msgs.length) && u.startsWith("gh://")) try {
const info = parseGhUrl(u), fileName = serializeThreadName(th), text = await ghGetFileContent(info, fileName);
if (text) try {
msgs = JSON.parse(text);
if (!msgs && u.startsWith("gh://")) try {
const info = parseGhUrl(u), fileName = serializeThreadName(th), res = await ghApi(`${info.apiPath}/${fileName}?ref=${info.branch}`);
if (res && res.content) {
msgs = JSON.parse(btou(res.content));
await localforage.setItem(prefix + id, msgs);
th.status = "synced";
await THREAD.save();
} catch (pe) {
console.error("[Sune] Thread JSON parse failed for", fileName, "len", text.length, pe);
}
else console.warn("[Sune] Remote thread returned no content:", fileName);
} catch (e) {
console.error("[Sune] Remote fetch failed", e);
console.error("Remote fetch failed", e);
}
state.messages = Array.isArray(msgs) ? [...msgs] : [];
for (const m of state.messages) {
@@ -2420,7 +2385,6 @@ Object.assign(window, {
cacheStore,
ghApi,
parseGhUrl,
ghGetFileContent,
pullThreads
});
//#endregion

2
dist/index.html vendored
View File

@@ -13,7 +13,7 @@
<script defer src="//unpkg.com/alpinejs"></script>
<script type="module" crossorigin src="/assets/index-9zVLqMQh.js"></script>
<script type="module" crossorigin src="/assets/index-DVG7SzRn.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DaGRC7Kr.css">
<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')">

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 d=e=>i(e,t),l={module:{uri:t},exports:o,require:d};s[t]=Promise.all(n.map(e=>l[e]||d(e))).then(e=>(r(...e),o))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"2e999fe2405d57f21cdfaa97eb92df18"},{url:"assets/index-DaGRC7Kr.css",revision:null},{url:"assets/index-9zVLqMQh.js",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 d=e=>i(e,t),l={module:{uri:t},exports:o,require:d};s[t]=Promise.all(n.map(e=>l[e]||d(e))).then(e=>(r(...e),o))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"af2178b9db3800fa6deda68db3fe0707"},{url:"assets/index-DaGRC7Kr.css",revision:null},{url:"assets/index-DVG7SzRn.js",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});

View File

@@ -1,5 +1,4 @@
import { USER } from './user.js';
import { btou } from './utils.js';
export const ghApi = async (path, method = 'GET', body = null) => {
const t = USER.githubToken;
@@ -23,25 +22,3 @@ export const parseGhUrl = u => {
repo = repoPart.split('@')[0], path = p.slice(2).join('/').replace(/\/$/, '');
return { owner, repo, branch, path, apiPath: `${owner}/${repo}/contents${path ? '/' + path : ''}` };
};
// Fetch a file's text content, transparently handling GitHub's 1MB Contents API
// limit. Files >1MB come back from the Contents API with encoding "none" and an
// empty `content` field, so we fall back to the Git Blobs API (supports up to 100MB).
export const ghGetFileContent = async (info, fileName) => {
const meta = await ghApi(`${info.apiPath}/${fileName}?ref=${info.branch}`);
if (!meta) { console.warn('[Sune] GH file not found:', fileName); return null; }
console.log('[Sune] GH file meta:', { name: fileName, size: meta.size, encoding: meta.encoding, hasContent: !!(meta.content && meta.content.trim()), sha: meta.sha });
if (meta.content && meta.encoding === 'base64') {
try { return btou(meta.content); } catch (e) { console.error('[Sune] decode (contents) failed:', e); }
}
// Large file path: Contents API omitted the body, retrieve the raw blob by sha.
if (meta.sha) {
try {
const blob = await ghApi(`${info.owner}/${info.repo}/git/blobs/${meta.sha}`);
console.log('[Sune] GH blob:', { size: blob?.size, encoding: blob?.encoding, hasContent: !!(blob?.content && blob.content.trim()) });
if (blob && blob.content && blob.encoding === 'base64') return btou(blob.content);
} catch (e) { console.error('[Sune] blob fetch failed:', e); }
}
console.warn('[Sune] Could not retrieve content for', fileName);
return null;
};

View File

@@ -4,7 +4,7 @@ import {STICKY_SUNES} from './sticky-sunes.js';
import {generateTitleWithAI} from './title-generator.js';
import { el } from './dom.js';
import { clamp, num, int, gid, esc, positionPopover, sid, fmtSize, asDataURL, imgToWebp, b64, utob, btou, dl, ts, partsToText } from './utils.js';
import { ghApi, parseGhUrl, ghGetFileContent } from './github.js';
import { ghApi, parseGhUrl } from './github.js';
import { USER } from './user.js';
import { md, enhanceCodeBlocks, renderMarkdown } from './markdown.js';
import { kbUpdate, kbBind } from './keyboard.js';
@@ -13,7 +13,7 @@ import { titleFrom, serializeThreadName, deserializeThreadName } from './threads
import { resolveSuneSrc, processSuneIncludes, renderSuneHTML } from './sune-html.js';
(()=>{let k,v=visualViewport;const f=()=>{removeEventListener('popstate',f),document.activeElement?.blur()};v.onresize=()=>{let o=v.height<innerHeight;o!=k&&((k=o)?(history.pushState({k:1},''),addEventListener('popstate',f)):(removeEventListener('popstate',f),history.state?.k&&history.back()))}})()
const DEFAULT_MODEL='anthropic/claude-opus-4.8'
const DEFAULT_MODEL='anthropic/claude-opus-4.7'
const icons=()=>window.lucide&&lucide.createIcons()
const haptic=()=>/android/i.test(navigator.userAgent)&&navigator.vibrate?.(1)
@@ -58,7 +58,7 @@ let menuThreadId=null;const hideThreadPopover=()=>{el.threadPopover.classList.ad
function showThreadPopover(btn,id){menuThreadId=id;el.threadPopover.classList.remove('hidden');positionPopover(btn,el.threadPopover);icons()}
let menuSuneId=null;const hideSunePopover=()=>{el.sunePopover.classList.add('hidden');menuSuneId=null}
function showSunePopover(btn,id){menuSuneId=id;el.sunePopover.classList.remove('hidden');positionPopover(btn,el.sunePopover);icons()}
$(el.threadList).on('click',async e=>{const openBtn=e.target.closest('[data-open-thread]'),menuBtn=e.target.closest('[data-thread-menu]');if(openBtn){const id=openBtn.getAttribute('data-open-thread'),type=openBtn.getAttribute('data-type');if(type==='file'){const u=el.threadRepoInput.value.trim();if(u.startsWith('gh://')){const info=parseGhUrl(u);window.open(`https://github.com/${info.owner}/${info.repo}/blob/${info.branch}/${id}`,'_blank')}return}if(type==='folder'){const u=el.threadRepoInput.value.trim();el.threadRepoInput.value=u+(u.endsWith('/')?'':'/')+id;el.threadRepoInput.dispatchEvent(new Event('change'));return}if(id!==state.currentThreadId&&state.busy){state.controller?.disconnect?.();setBtnSend();state.busy=false;state.controller=null}const th=THREAD.get(id);if(!th)return;if(id===state.currentThreadId){el.sidebarRight.classList.add('translate-x-full');el.sidebarOverlayRight.classList.add('hidden');hideThreadPopover();return}state.currentThreadId=id;clearChat();const u=el.threadRepoInput.value.trim(),prefix=u.startsWith('gh://')?'rem_t_':'t_';let msgs=await localforage.getItem(prefix+id);if((!msgs||!Array.isArray(msgs)||!msgs.length)&&u.startsWith('gh://')){try{const info=parseGhUrl(u),fileName=serializeThreadName(th),text=await ghGetFileContent(info,fileName);if(text){try{msgs=JSON.parse(text);await localforage.setItem(prefix+id,msgs);th.status='synced';await THREAD.save()}catch(pe){console.error('[Sune] Thread JSON parse failed for',fileName,'len',text.length,pe)}}else{console.warn('[Sune] Remote thread returned no content:',fileName)}}catch(e){console.error('[Sune] Remote fetch failed',e)}}state.messages=Array.isArray(msgs)?[...msgs]:[];for(const m of state.messages){const b=msgRow(m);b.dataset.mid=m.id||'';renderMarkdown(b,partsToText(m))}await renderSuneHTML();syncWhileBusy();queueMicrotask(()=>el.chat.scrollTo({top:el.chat.scrollHeight,behavior:'smooth'}));el.sidebarRight.classList.add('translate-x-full');el.sidebarOverlayRight.classList.add('hidden');hideThreadPopover();return}if(menuBtn){e.stopPropagation();showThreadPopover(menuBtn,menuBtn.getAttribute('[data-thread-menu]')?menuBtn.getAttribute('[data-thread-menu]'):menuBtn.getAttribute('data-thread-menu'))}})
$(el.threadList).on('click',async e=>{const openBtn=e.target.closest('[data-open-thread]'),menuBtn=e.target.closest('[data-thread-menu]');if(openBtn){const id=openBtn.getAttribute('data-open-thread'),type=openBtn.getAttribute('data-type');if(type==='file'){const u=el.threadRepoInput.value.trim();if(u.startsWith('gh://')){const info=parseGhUrl(u);window.open(`https://github.com/${info.owner}/${info.repo}/blob/${info.branch}/${id}`,'_blank')}return}if(type==='folder'){const u=el.threadRepoInput.value.trim();el.threadRepoInput.value=u+(u.endsWith('/')?'':'/')+id;el.threadRepoInput.dispatchEvent(new Event('change'));return}if(id!==state.currentThreadId&&state.busy){state.controller?.disconnect?.();setBtnSend();state.busy=false;state.controller=null}const th=THREAD.get(id);if(!th)return;if(id===state.currentThreadId){el.sidebarRight.classList.add('translate-x-full');el.sidebarOverlayRight.classList.add('hidden');hideThreadPopover();return}state.currentThreadId=id;clearChat();const u=el.threadRepoInput.value.trim(),prefix=u.startsWith('gh://')?'rem_t_':'t_';let msgs=await localforage.getItem(prefix+id);if(!msgs&&u.startsWith('gh://')){try{const info=parseGhUrl(u),fileName=serializeThreadName(th),res=await ghApi(`${info.apiPath}/${fileName}?ref=${info.branch}`);if(res&&res.content){msgs=JSON.parse(btou(res.content));await localforage.setItem(prefix+id,msgs);th.status='synced';await THREAD.save()}}catch(e){console.error('Remote fetch failed',e)}}state.messages=Array.isArray(msgs)?[...msgs]:[];for(const m of state.messages){const b=msgRow(m);b.dataset.mid=m.id||'';renderMarkdown(b,partsToText(m))}await renderSuneHTML();syncWhileBusy();queueMicrotask(()=>el.chat.scrollTo({top:el.chat.scrollHeight,behavior:'smooth'}));el.sidebarRight.classList.add('translate-x-full');el.sidebarOverlayRight.classList.add('hidden');hideThreadPopover();return}if(menuBtn){e.stopPropagation();showThreadPopover(menuBtn,menuBtn.getAttribute('[data-thread-menu]')?menuBtn.getAttribute('[data-thread-menu]'):menuBtn.getAttribute('data-thread-menu'))}})
$(el.threadList).on('scroll',()=>{
if(isAddingThreads||el.threadList.scrollTop+el.threadList.clientHeight<el.threadList.scrollHeight-200)return;
const c=el.threadList.children.length;
@@ -178,4 +178,4 @@ const getActiveJar=()=>!el.htmlEditor.classList.contains('hidden')?jars.html:jar
$(el.copyHTML).on('click',async()=>{try{const jar=getActiveJar();await navigator.clipboard.writeText(jar?jar.toString():'')}catch{}})
$(el.pasteHTML).on('click',async()=>{try{const t=await navigator.clipboard.readText();const jar=getActiveJar();if(jar)jar.updateCode(t)}catch{}})
Object.assign(window,{icons,haptic,clamp,num,int,gid,esc,positionPopover,sid,fmtSize,asDataURL,b64,makeSune,getModelShort,resolveSuneSrc,processSuneIncludes,renderSuneHTML,reflectActiveSune,suneRow,enhanceCodeBlocks,getSuneLabel,_createMessageRow,msgRow,partsToText,addSuneBubbleStreaming,clearChat,payloadWithSampling,setBtnStop,setBtnSend,localDemoReply,titleFrom,serializeThreadName,deserializeThreadName,ensureThreadOnFirstUser,generateTitleWithAI,threadRow,renderThreads,hideThreadPopover,showThreadPopover,hideSunePopover,showSunePopover,updateAttachBadge,toAttach,ensureJars,openSettings,closeSettings,showTab,dl,ts,kbUpdate,kbBind,activeMeta,init,showHtmlTab,showAccountTab,openAccountSettings,closeAccountSettings,getBubbleById,syncActiveThread,syncWhileBusy,onForeground,getActiveJar,imgToWebp,cacheStore,ghApi,parseGhUrl,ghGetFileContent,pullThreads});
Object.assign(window,{icons,haptic,clamp,num,int,gid,esc,positionPopover,sid,fmtSize,asDataURL,b64,makeSune,getModelShort,resolveSuneSrc,processSuneIncludes,renderSuneHTML,reflectActiveSune,suneRow,enhanceCodeBlocks,getSuneLabel,_createMessageRow,msgRow,partsToText,addSuneBubbleStreaming,clearChat,payloadWithSampling,setBtnStop,setBtnSend,localDemoReply,titleFrom,serializeThreadName,deserializeThreadName,ensureThreadOnFirstUser,generateTitleWithAI,threadRow,renderThreads,hideThreadPopover,showThreadPopover,hideSunePopover,showSunePopover,updateAttachBadge,toAttach,ensureJars,openSettings,closeSettings,showTab,dl,ts,kbUpdate,kbBind,activeMeta,init,showHtmlTab,showAccountTab,openAccountSettings,closeAccountSettings,getBubbleById,syncActiveThread,syncWhileBusy,onForeground,getActiveJar,imgToWebp,cacheStore,ghApi,parseGhUrl,pullThreads});