Upload files to "bridges"

This commit is contained in:
2026-01-17 15:48:59 +00:00
parent 7e5186aeab
commit de4cd7234e
3 changed files with 2356 additions and 2356 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -2,96 +2,96 @@
function defineCallGenerate(){ function defineCallGenerate(){
var parentOrigin; var parentOrigin;
try{parentOrigin=new URL(document.referrer).origin}catch(_){parentOrigin='*'} try{parentOrigin=new URL(document.referrer).origin}catch(_){parentOrigin='*'}
function sanitizeOptions(options){ function sanitizeOptions(options){
try{ try{
return JSON.parse(JSON.stringify(options,function(k,v){return(typeof v==='function')?undefined:v})) return JSON.parse(JSON.stringify(options,function(k,v){return(typeof v==='function')?undefined:v}))
}catch(_){ }catch(_){
try{ try{
const seen=new WeakSet(); const seen=new WeakSet();
const clone=(val)=>{ const clone=(val)=>{
if(val===null||val===undefined)return val; if(val===null||val===undefined)return val;
const t=typeof val; const t=typeof val;
if(t==='function')return undefined; if(t==='function')return undefined;
if(t!=='object')return val; if(t!=='object')return val;
if(seen.has(val))return undefined; if(seen.has(val))return undefined;
seen.add(val); seen.add(val);
if(Array.isArray(val)){ if(Array.isArray(val)){
const arr=[];for(let i=0;i<val.length;i++){const v=clone(val[i]);if(v!==undefined)arr.push(v)}return arr; const arr=[];for(let i=0;i<val.length;i++){const v=clone(val[i]);if(v!==undefined)arr.push(v)}return arr;
} }
const proto=Object.getPrototypeOf(val); const proto=Object.getPrototypeOf(val);
if(proto!==Object.prototype&&proto!==null)return undefined; if(proto!==Object.prototype&&proto!==null)return undefined;
const out={}; const out={};
for(const k in val){if(Object.prototype.hasOwnProperty.call(val,k)){const v=clone(val[k]);if(v!==undefined)out[k]=v}} for(const k in val){if(Object.prototype.hasOwnProperty.call(val,k)){const v=clone(val[k]);if(v!==undefined)out[k]=v}}
return out; return out;
}; };
return clone(options); return clone(options);
}catch(__){return{}} }catch(__){return{}}
} }
} }
function CallGenerateImpl(options){ function CallGenerateImpl(options){
return new Promise(function(resolve,reject){ return new Promise(function(resolve,reject){
try{ try{
function post(m){try{parent.postMessage(m,parentOrigin)}catch(e){}} function post(m){try{parent.postMessage(m,parentOrigin)}catch(e){}}
if(!options||typeof options!=='object'){reject(new Error('Invalid options'));return} if(!options||typeof options!=='object'){reject(new Error('Invalid options'));return}
var id=Date.now().toString(36)+Math.random().toString(36).slice(2); var id=Date.now().toString(36)+Math.random().toString(36).slice(2);
function onMessage(e){ function onMessage(e){
if(parentOrigin!=='*'&&e&&e.origin!==parentOrigin)return; if(parentOrigin!=='*'&&e&&e.origin!==parentOrigin)return;
var d=e&&e.data||{}; var d=e&&e.data||{};
if(d.source!=='xiaobaix-host'||d.id!==id)return; if(d.source!=='xiaobaix-host'||d.id!==id)return;
if(d.type==='generateStreamStart'&&options.streaming&&options.streaming.onStart){try{options.streaming.onStart(d.sessionId)}catch(_){}} if(d.type==='generateStreamStart'&&options.streaming&&options.streaming.onStart){try{options.streaming.onStart(d.sessionId)}catch(_){}}
else if(d.type==='generateStreamChunk'&&options.streaming&&options.streaming.onChunk){try{options.streaming.onChunk(d.chunk,d.accumulated)}catch(_){}} else if(d.type==='generateStreamChunk'&&options.streaming&&options.streaming.onChunk){try{options.streaming.onChunk(d.chunk,d.accumulated)}catch(_){}}
else if(d.type==='generateStreamComplete'){try{window.removeEventListener('message',onMessage)}catch(_){} else if(d.type==='generateStreamComplete'){try{window.removeEventListener('message',onMessage)}catch(_){}
resolve(d.result)} resolve(d.result)}
else if(d.type==='generateStreamError'){try{window.removeEventListener('message',onMessage)}catch(_){} else if(d.type==='generateStreamError'){try{window.removeEventListener('message',onMessage)}catch(_){}
reject(new Error(d.error||'Stream failed'))} reject(new Error(d.error||'Stream failed'))}
else if(d.type==='generateResult'){try{window.removeEventListener('message',onMessage)}catch(_){} else if(d.type==='generateResult'){try{window.removeEventListener('message',onMessage)}catch(_){}
resolve(d.result)} resolve(d.result)}
else if(d.type==='generateError'){try{window.removeEventListener('message',onMessage)}catch(_){} else if(d.type==='generateError'){try{window.removeEventListener('message',onMessage)}catch(_){}
reject(new Error(d.error||'Generation failed'))} reject(new Error(d.error||'Generation failed'))}
} }
// eslint-disable-next-line no-restricted-syntax -- origin checked via parentOrigin. // eslint-disable-next-line no-restricted-syntax -- origin checked via parentOrigin.
try{window.addEventListener('message',onMessage)}catch(_){} try{window.addEventListener('message',onMessage)}catch(_){}
var sanitized=sanitizeOptions(options); var sanitized=sanitizeOptions(options);
post({type:'generateRequest',id:id,options:sanitized}); post({type:'generateRequest',id:id,options:sanitized});
setTimeout(function(){ setTimeout(function(){
try{window.removeEventListener('message',onMessage)}catch(e){} try{window.removeEventListener('message',onMessage)}catch(e){}
reject(new Error('Generation timeout')); reject(new Error('Generation timeout'));
},300000); },300000);
}catch(e){reject(e)} }catch(e){reject(e)}
}) })
} }
try{window.CallGenerate=CallGenerateImpl}catch(e){} try{window.CallGenerate=CallGenerateImpl}catch(e){}
try{window.callGenerate=CallGenerateImpl}catch(e){} try{window.callGenerate=CallGenerateImpl}catch(e){}
try{window.__xb_callGenerate_loaded=true}catch(e){} try{window.__xb_callGenerate_loaded=true}catch(e){}
} }
try{defineCallGenerate()}catch(e){} try{defineCallGenerate()}catch(e){}
})(); })();
(function(){ (function(){
var parentOrigin; var parentOrigin;
try{parentOrigin=new URL(document.referrer).origin}catch(_){parentOrigin='*'} try{parentOrigin=new URL(document.referrer).origin}catch(_){parentOrigin='*'}
function applyAvatarCss(urls){ function applyAvatarCss(urls){
try{ try{
const root=document.documentElement; const root=document.documentElement;
root.style.setProperty('--xb-user-avatar',urls&&urls.user?`url("${urls.user}")`:'none'); root.style.setProperty('--xb-user-avatar',urls&&urls.user?`url("${urls.user}")`:'none');
root.style.setProperty('--xb-char-avatar',urls&&urls.char?`url("${urls.char}")`:'none'); root.style.setProperty('--xb-char-avatar',urls&&urls.char?`url("${urls.char}")`:'none');
if(!document.getElementById('xb-avatar-style')){ if(!document.getElementById('xb-avatar-style')){
const css=` const css=`
.xb-avatar,.xb-user-avatar,.xb-char-avatar{ .xb-avatar,.xb-user-avatar,.xb-char-avatar{
width:36px;height:36px;border-radius:50%; width:36px;height:36px;border-radius:50%;
background-size:cover;background-position:center;background-repeat:no-repeat; background-size:cover;background-position:center;background-repeat:no-repeat;
display:inline-block display:inline-block
} }
.xb-user-avatar{background-image:var(--xb-user-avatar)} .xb-user-avatar{background-image:var(--xb-user-avatar)}
.xb-char-avatar{background-image:var(--xb-char-avatar)} .xb-char-avatar{background-image:var(--xb-char-avatar)}
`; `;
const style=document.createElement('style'); const style=document.createElement('style');
style.id='xb-avatar-style'; style.id='xb-avatar-style';
style.textContent=css; style.textContent=css;
document.head.appendChild(style); document.head.appendChild(style);
} }
}catch(_){} }catch(_){}
} }
function requestAvatars(){ function requestAvatars(){
try{parent.postMessage({type:'getAvatars'},parentOrigin)}catch(_){} try{parent.postMessage({type:'getAvatars'},parentOrigin)}catch(_){}
} }
@@ -99,18 +99,18 @@
if(parentOrigin!=='*'&&e&&e.origin!==parentOrigin)return; if(parentOrigin!=='*'&&e&&e.origin!==parentOrigin)return;
const d=e&&e.data||{}; const d=e&&e.data||{};
if(d&&d.source==='xiaobaix-host'&&d.type==='avatars'){ if(d&&d.source==='xiaobaix-host'&&d.type==='avatars'){
applyAvatarCss(d.urls); applyAvatarCss(d.urls);
try{window.removeEventListener('message',onMessage)}catch(_){} try{window.removeEventListener('message',onMessage)}catch(_){}
} }
} }
try{ try{
// eslint-disable-next-line no-restricted-syntax -- origin checked via parentOrigin. // eslint-disable-next-line no-restricted-syntax -- origin checked via parentOrigin.
window.addEventListener('message',onMessage); window.addEventListener('message',onMessage);
if(document.readyState==='loading'){ if(document.readyState==='loading'){
document.addEventListener('DOMContentLoaded',requestAvatars,{once:true}); document.addEventListener('DOMContentLoaded',requestAvatars,{once:true});
}else{ }else{
requestAvatars(); requestAvatars();
} }
window.addEventListener('load',requestAvatars,{once:true}); window.addEventListener('load',requestAvatars,{once:true});
}catch(_){} }catch(_){}
})(); })();