PageSourceSearch

https://kuaipao.ai/assets/index-Q5OaQjS6.js

js kuaipao.ai collected 2026-10-05 14:38:28 UTC 74,136 bytes, 42 lines download raw bytes

1import{r as z,M as ue,j as e,T as E,B as k,J as is,O as se,l as je,bi as Ne,H as vs,F as ls,k as Ae,bj as Ts,aR as Ce,G as ks,C as Me,i as qe,aG as ee,$ as He,c as Rs,d as ke,bk as Os,aN as Re}from"./semi-ui-DaREz2Dk.js";import{r as x,R as V,d as Is}from"./react-core-CbTnFS3E.js";import{b3 as q,b4 as F,b5 as G,b6 as Oe,b7 as J,b8 as I,b9 as os,ba as he,bb as de,bc as Se,W as Ve,bd as ce,be as zs,bf as ze,bg as cs,A as We,bh as _s,s as be,bi as As,I as Ms,aB as Ds,X as Ke,e as Xe,U as Fs,c as Ls,f as Ze,bj as Qe,$ as Ps,bk as Ye}from"./index-DIEzcWSf.js";import{u as M}from"./i18n-Bx9xRaoE.js";import{e as $s}from"./base64-C94kA9SO.js";import{M as we}from"./MarkdownRenderer-_lNZSwUP.js";import{a9 as Js,aa as ds,a as us,ab as Us,ac as hs,_ as De,a4 as U,a1 as Q,R as Bs,C as _e,ad as ms,U as Gs,T as qs,ae as Hs,af as Vs,ag as Ws,ah as Ks,H as Xs,S as Zs,ai as Qs,P as Ys,aj as es,k as ss,i as ts,ak as et,al as xs,K as st,s as tt,am as nt,J as gs,b as rt,c as at,q as it,an as Fe,ao as lt,e as ot,ap as ct,aq as fs}from"./icons-B20TY-5b.js";import{C as Ie}from"./CodeViewer-DTr7Rsvv.js";import"./tools-C_1hZ9u4.js";import"./react-components-BCk5goEb.js";import"./dayjs.min-CnW1CkYn.js";import"./Serializer-PsS1Hlpf.js";import"./index-xDewR2Kz.js";import"./index-LW9wZsud.js";import"./index-DwbdS1R8.js";const dt=new Set(Object.values(G)),ut=t=>typeof t=="string"?t:Array.isArray(t)?t.map(s=>{var n;if(!s||typeof s!="object")return null;if(s.type==="text")return{type:"text",text:typeof s.text=="string"?s.text:""};if(s.type==="image_url"){const r=typeof s.image_url=="string"?s.image_url:(n=s.image_url)==null?void 0:n.url;return r?{type:"image_url",image_url:{url:r}}:null}return null}).filter(Boolean):"",ht=(t,s)=>{if(!t||typeof t!="object")return null;const n=dt.has(t.role)?t.role:G.USER,r=typeof t.id=="string"||typeof t.id=="number"?String(t.id):`cached-${s}-${Date.now()}`;return{...t,id:r,role:n,content:ut(t.content),createAt:Number(t.createAt)||Date.now()}},mt=t=>{try{const s={...t,timestamp:new Date().toISOString()};localStorage.setItem(q.CONFIG,JSON.stringify(s))}catch(s){console.error("保存配置失败:",s)}},Le=t=>{try{const s={messages:t,timestamp:new Date().toISOString()};localStorage.setItem(q.MESSAGES,JSON.stringify(s))}catch(s){console.error("保存消息失败:",s)}},xt=()=>{var t,s;try{const n=localStorage.getItem(q.CONFIG);if(n){const r=JSON.parse(n),l=parseInt((t=r==null?void 0:r.inputs)==null?void 0:t.max_tokens,10);return{inputs:{...F.inputs,...r.inputs,max_tokens:Number.isNaN(l)?(s=r==null?void 0:r.inputs)==null?void 0:s.max_tokens:l},parameterEnabled:{...F.parameterEnabled,...r.parameterEnabled},showDebugPanel:r.showDebugPanel||F.showDebugPanel,customRequestMode:r.customRequestMode||F.customRequestMode,customRequestBody:r.customRequestBody||F.customRequestBody}}}catch(n){console.error("加载配置失败:",n)}return F},ps=()=>{try{const t=localStorage.getItem(q.MESSAGES);if(t){const s=JSON.parse(t),n=Array.isArray(s)?s:s==null?void 0:s.messages;if(!Array.isArray(n))return localStorage.removeItem(q.MESSAGES),null;const r=n.map(ht).filter(Boolean);return r.length!==n.length&&Le(r),r.length>0?r:null}}catch(t){console.error("加载消息失败:",t),localStorage.removeItem(q.MESSAGES)}return null},ns=()=>{try{localStorage.removeItem(q.CONFIG),localStorage.removeItem(q.MESSAGES)}catch(t){console.error("清除配置失败:",t)}},gt=()=>{try{return localStorage.getItem(q.CONFIG)!==null}catch(t){return console.error("检查配置失败:",t),!1}},ft=()=>{try{const t=localStorage.getItem(q.CONFIG);if(t)return JSON.parse(t).timestamp||null}catch(t){console.error("获取配置时间戳失败:",t)}return null},pt=(t,s=null)=>{try{const n={...t,messages:s||ps(),exportTime:new Date().toISOString(),version:"1.0"},r=JSON.stringify(n,null,2),l=new Blob([r],{type:"application/json"}),i=document.createElement("a");i.href=URL.createObjectURL(l),i.download=`playground-config-${new Date().toISOString().split("T")[0]}.json`,i.click(),URL.revokeObjectURL(i.href)}catch(n){console.error("导出配置失败:",n)}},yt=t=>new Promise((s,n)=>{try{const r=new FileReader;r.onload=l=>{try{const i=JSON.parse(l.target.result);i.inputs&&i.parameterEnabled?(i.messages&&Array.isArray(i.messages)&&Le(i.messages),s(i)):n(new Error("配置文件格式无效"))}catch(i){n(new Error("解析配置文件失败: "+i.message))}},r.onerror=()=>n(new Error("读取文件失败")),r.readAsText(t)}catch(r){n(new Error("导入配置失败: "+r.message))}}),jt=()=>{const{t}=M(),[s]=x.useState(()=>xt()),[n]=x.useState(()=>{const T=ps();return T&&T.length===2&&T[0].id==="2"&&T[1].id==="3"&&(T[0].content==="你好"||T[1].content==="你好,请问有什么可以帮助您的吗?"||T[1].content==="你好!很高兴见到你。有什么我可以帮助ä
1½ çš„吗?")?(localStorage.removeItem("playground_messages"),null):T}),[r,l]=x.useState(s.inputs||F.inputs),[i,a]=x.useState(s.parameterEnabled||F.parameterEnabled),[y,j]=x.useState(s.showDebugPanel||F.showDebugPanel),[u,g]=x.useState(s.customRequestMode||F.customRequestMode),[f,d]=x.useState(s.customRequestBody||F.customRequestBody),[o,c]=x.useState(!1),[h,m]=x.useState([]),[C,N]=x.useState([]),[p,w]=x.useState({}),[b,S]=x.useState(()=>n||Oe(t));x.useEffect(()=>{n||S(Oe(t))},[t,n]);const[v,_]=x.useState({request:null,response:null,timestamp:null,previewRequest:null,previewTimestamp:null}),[L,P]=x.useState(J.PREVIEW),[ne,Ee]=x.useState(null),[$,re]=x.useState(null),[ae,me]=x.useState(""),ie=x.useRef(null),ve=x.useRef(null),H=x.useRef(null);x.useRef(null);const le=x.useCallback((T,A)=>{l(W=>({...W,[T]:A}))},[]),Te=x.useCallback(T=>{a(A=>({...A,[T]:!A[T]}))},[]),Y=x.useCallback(T=>{Le(T||b)},[b]),xe=x.useCallback(()=>{H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{mt({inputs:r,parameterEnabled:i,showDebugPanel:y,customRequestMode:u,customRequestBody:f})},1e3)},[r,i,y,u,f]),ge=x.useCallback(T=>{if(T.inputs){const A=parseInt(T.inputs.max_tokens,10);l(W=>({...W,...T.inputs,max_tokens:Number.isNaN(A)?T.inputs.max_tokens:A}))}T.parameterEnabled&&a(A=>({...A,...T.parameterEnabled})),typeof T.showDebugPanel=="boolean"&&j(T.showDebugPanel),T.customRequestMode&&g(T.customRequestMode),T.customRequestBody&&d(T.customRequestBody),T.messages&&Array.isArray(T.messages)&&S(T.messages)},[]),fe=x.useCallback((T={})=>{const{resetMessages:A=!1}=T;l(F.inputs),a(F.parameterEnabled),j(F.showDebugPanel),g(F.customRequestMode),d(F.customRequestBody),A&&(S([]),setTimeout(()=>{S(Oe(t))},0))},[]);return x.useEffect(()=>()=>{H.current&&clearTimeout(H.current)},[]),x.useEffect(()=>{if(!Array.isArray(b)||b.length===0)return;const T=b[b.length-1];if(T.status===I.LOADING||T.status===I.INCOMPLETE){const A=os(T.content||"",T.reasoningContent||""),W={...T,status:I.COMPLETE,content:A.content,reasoningContent:A.reasoningContent||null,isThinkingComplete:!0},oe=[...b.slice(0,-1),W];S(oe),setTimeout(()=>Y(oe),0)}},[]),{inputs:r,parameterEnabled:i,showDebugPanel:y,customRequestMode:u,customRequestBody:f,showSettings:o,models:h,groups:C,status:p,message:b,debugData:v,activeDebugTab:L,previewPayload:ne,editingMessageId:$,editValue:ae,sseSourceRef:ie,chatRef:ve,saveConfigTimeoutRef:H,setInputs:l,setParameterEnabled:a,setShowDebugPanel:j,setCustomRequestMode:g,setCustomRequestBody:d,setShowSettings:c,setModels:m,setGroups:N,setStatus:w,setMessage:S,setDebugData:_,setActiveDebugTab:P,setPreviewPayload:Ee,setEditingMessageId:re,setEditValue:me,handleInputChange:le,handleParameterToggle:Te,debouncedSaveConfig:xe,saveMessagesImmediately:Y,handleConfigImport:ge,handleConfigReset:fe}},Nt=(t,s,n,r)=>{const{t:l}=M(),i=x.useCallback(u=>{const g=he(u);if(!g){z.warning({content:l(de.NO_TEXT_CONTENT),duration:2});return}const f=async o=>{var c;if((c=navigator.clipboard)!=null&&c.writeText)try{await navigator.clipboard.writeText(o),z.success({content:l("消息已复制到剪贴板"),duration:2})}catch(h){console.error("Clipboard API 复制失败:",h),d(o)}else d(o)},d=o=>{try{const c=document.createElement("textarea");c.value=o,c.style.cssText=`
2          position: fixed;
3          top: -9999px;
4          left: -9999px;
5          opacity: 0;
6          pointer-events: none;
7          z-index: -1;
8        `,c.setAttribute("readonly",""),document.body.appendChild(c),c.select(),c.setSelectionRange(0,o.length);const h=document.execCommand("copy");if(document.body.removeChild(c),h)z.success({content:l("消息已复制到剪贴板"),duration:2});else throw new Error("execCommand copy failed")}catch(c){console.error("回退复制方案也失败:",c);let h=l(de.COPY_FAILED);window.location.protocol==="http:"&&window.location.hostname!=="localhost"?h=l(de.COPY_HTTPS_REQUIRED):!navigator.clipboard&&!document.execCommand&&(h=l(de.BROWSER_NOT_SUPPORTED)),z.error({content:h,duration:4})}};f(g)},[l]),a=x.useCallback(u=>{s(g=>{let f=g.findIndex(d=>d===u);if(f===-1&&(f=g.findIndex(d=>d.id===u.id)),f===-1)return g;if(u.role==="user"){const d=g.slice(0,f),o=he(u);return setTimeout(()=>{n(o)},100),d}else if(u.role==="assistant"||u.role==="system"){let d=f-1;for(;d>=0&&g[d].role!=="user";)d--;if(d>=0){const o=g[d],c=g.slice(0,d),h=he(o);return setTimeout(()=>{n(h)},100),c}}return g})},[s,n]),y=x.useCallback(u=>{ue.confirm({title:l("确认删除"),content:l("确定要删除这条消息吗?"),okText:l("确定"),cancelText:l("取消"),okButtonProps:{type:"danger"},onOk:()=>{s(g=>{let f=g.findIndex(o=>o===u);if(f===-1&&(f=g.findIndex(o=>o.id===u.id)),f===-1)return g;let d;
8return u.role==="user"&&f<g.length-1?g[f+1].role==="assistant"?(z.success({content:l("已删除消息及其回复"),duration:2}),d=g.filter((c,h)=>h!==f&&h!==f+1)):(z.success({content:l("消息已删除"),duration:2}),d=g.filter(c=>c.id!==u.id)):(z.success({content:l("消息已删除"),duration:2}),d=g.filter(o=>o.id!==u.id)),setTimeout(()=>r(d),0),d})}})},[s,l,r]),j=x.useCallback(u=>{if(!(u.role==="assistant"||u.role==="system"))return;const g=u.role==="assistant"?"system":"assistant";s(f=>{const d=f.map(o=>o.id===u.id&&(o.role==="assistant"||o.role==="system")?{...o,role:g}:o);return setTimeout(()=>r(d),0),d}),z.success({content:l(`已切换为${g==="system"?"System":"Assistant"}角色`),duration:2})},[s,l,r]);return{handleMessageCopy:i,handleMessageReset:a,handleMessageDelete:y,handleRoleToggle:j}};var B=function(t,s){if(!(this instanceof B))return new B(t,s);this.url=t,s=s||{},this.headers=s.headers||{},this.payload=s.payload!==void 0?s.payload:"",this.method=s.method||this.payload&&"POST"||"GET",this.withCredentials=!!s.withCredentials,this.debug=!!s.debug,this.autoReconnect=s.autoReconnect!==void 0?s.autoReconnect:!1,this.reconnectDelay=s.reconnectDelay!==void 0?s.reconnectDelay:3e3,this.maxRetries=s.maxRetries!==void 0?s.maxRetries:null,this.retryCount=0,this.reconnectTimer=null,this.useLastEventId=s.useLastEventId!==void 0?s.useLastEventId:!0,this.FIELD_SEPARATOR=":",this.listeners={},this.xhr=null,this.readyState=B.INITIALIZING,this.progress=0,this.chunk="",this.lastEventId="",this._hasParsedBom=!1,this.addEventListener=function(n,r){this.listeners[n]===void 0&&(this.listeners[n]=[]),this.listeners[n].indexOf(r)===-1&&this.listeners[n].push(r)},this.removeEventListener=function(n,r){if(this.listeners[n]===void 0)return;const l=[];this.listeners[n].forEach(function(i){i!==r&&l.push(i)}),l.length===0?delete this.listeners[n]:this.listeners[n]=l},this.dispatchEvent=function(n){if(!n)return!0;this.debug&&console.debug(n),n.source=this;const r="on"+n.type;return this.hasOwnProperty(r)&&(this[r].call(this,n),n.defaultPrevented)?!1:this.listeners[n.type]?this.listeners[n.type].every(function(l){return l(n),!n.defaultPrevented}):!0},this._markClosed=function(){if(this.xhr=null,this.progress=0,this.chunk="",this._setReadyState(B.CLOSED),this.autoReconnect){if(this.maxRetries!==null&&this.retryCount>=this.maxRetries){this.debug&&console.debug(`SSE max retries (${this.maxRetries}) reached, stopping reconnection attempts`),this.autoReconnect=!1,this.close();return}this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.debug&&console.debug(`SSE will attempt to reconnect in ${this.reconnectDelay}ms (attempt ${this.retryCount+1}${this.maxRetries?"/"+this.maxRetries:""})`),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.retryCount++,this.stream()},this.reconnectDelay)}},this._setReadyState=function(n){const r=new CustomEvent("readystatechange");r.readyState=n,this.readyState=n,this.dispatchEvent(r)},this._onStreamFailure=function(n){const r=new CustomEvent("error");r.responseCode=n.currentTarget.status,r.data=n.currentTarget.response,this.dispatchEvent(r),this._markClosed()},this._onStreamAbort=function(){this.dispatchEvent(new CustomEvent("abort")),this._markClosed()},this._onStreamProgress=function(n){if(!this.xhr)return;if(this.xhr.status<200||this.xhr.status>=300){this._onStreamFailure(n);return}this.retryCount=0;let r=this.xhr.responseText.substring(this.progress);this.progress+=r.length,!this._hasParsedBom&&this.chunk.length===0&&(r.charCodeAt(0)===65279&&(r=r.substring(1)),this._hasParsedBom=!0);const l=(this.chunk+r).split(/(\r\n\r\n|\r\r|\n\n)/g),i=l.pop();l.forEach((function(a){a.trim().length>0&&this.dispatchEvent(this._parseEventChunk(a))}).bind(this)),this.chunk=i},this._onStreamLoaded=function(n){this._onStreamProgress(n),this.dispatchEvent(this._parseEventChunk(this.chunk)),this.chunk="",this._markClosed()},this._parseEventChunk=function(n){if(!n||n.length===0)return null;this.debug&&console.debug(n);const r={id:null,retry:null,data:null,event:null};
8if(n.split(/\n|\r\n|\r/).forEach((function(i){const a=i.indexOf(this.FIELD_SEPARATOR);let y,j;if(a>0){const u=i[a+1]===" "?2:1;y=i.substring(0,a),j=i.substring(a+u)}else if(a<0)y=i,j="";else return;y in r&&(y==="data"&&r[y]!==null?r.data+=`
9`+j:r[y]=j)}).bind(this)),r.id!==null&&r.id.indexOf("\0")===-1&&(this.lastEventId=r.id),r.retry!==null&&/^[0-9]+$/.test(r.retry)&&(this.reconnectDelay=parseInt(r.retry,10)),r.data===null)return null;const l=new CustomEvent(r.event||"message");return l.id=r.id,l.data=r.data||"",l.lastEventId=this.lastEventId,l},this._onReadyStateChange=function(){if(this.xhr&&this.xhr.readyState===XMLHttpRequest.HEADERS_RECEIVED){const n={},r=this.xhr.getAllResponseHeaders().trim().split(`\r
10`);for(const i of r){const[a,...y]=i.split(":"),j=y.join(":").trim();n[a.trim().toLowerCase()]=n[a.trim().toLowerCase()]||[],n[a.trim().toLowerCase()].push(j)}const l=new CustomEvent("open");l.responseCode=this.xhr.status,l.headers=n,this.dispatchEvent(l),this._setReadyState(B.OPEN)}},this.stream=function(){if(!this.xhr){this._setReadyState(B.CONNECTING),this.xhr=new XMLHttpRequest,this.xhr.addEventListener("progress",this._onStreamProgress.bind(this)),this.xhr.addEventListener("load",this._onStreamLoaded.bind(this)),this.xhr.addEventListener("readystatechange",this._onReadyStateChange.bind(this)),this.xhr.addEventListener("error",this._onStreamFailure.bind(this)),this.xhr.addEventListener("abort",this._onStreamAbort.bind(this)),this.xhr.open(this.method,this.url);for(let n in this.headers)this.xhr.setRequestHeader(n,this.headers[n]);this.useLastEventId&&this.lastEventId.length>0&&this.xhr.setRequestHeader("Last-Event-ID",this.lastEventId),this.xhr.withCredentials=this.withCredentials,this.xhr.send(this.payload)}},this.close=function(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.autoReconnect=!1,this.xhr&&this.xhr.abort()},(s.start===void 0||s.start)&&this.stream()};B.INITIALIZING=-1;B.CONNECTING=0;B.OPEN=1;B.CLOSED=2;const bt=(t,s,n,r,l)=>{const{t:i}=M(),a=x.useCallback((o,c=!0)=>{const h=c&&!o.hasAutoCollapsed;return{isThinkingComplete:c,hasAutoCollapsed:h||o.hasAutoCollapsed,isReasoningExpanded:h?!1:o.isReasoningExpanded}},[]),y=x.useCallback((o,c)=>{t(h=>{const m=h[h.length-1];if(!m||m.role!=="assistant"||m.status===I.ERROR)return h;if(m.status===I.LOADING||m.status===I.INCOMPLETE){let C={...m};if(c==="reasoning")C={...C,reasoningContent:(m.reasoningContent||"")+o,status:I.INCOMPLETE,isThinkingComplete:!1};else if(c==="content"){!m.content&&m.reasoningContent;const N=(m.content||"")+o;let p=m.isThinkingComplete;if(m.isReasoningExpanded&&N.includes("</think>")){const S=N.match(/<think>/g),v=N.match(/<\/think>/g);S&&v&&v.length>=S.length&&(p=!0)}const w=m.reasoningContent&&!m.isThinkingComplete||p,b=a(m,w);C={...C,content:N,status:I.INCOMPLETE,...b}}return[...h.slice(0,-1),C]}return h})},[t,a]),j=x.useCallback((o=I.COMPLETE)=>{t(c=>{const h=c[c.length-1];if(h.status===I.COMPLETE||h.status===I.ERROR)return c;const m=a(h,!0),C=[...c.slice(0,-1),{...h,status:o,...m}];return(o===I.COMPLETE||o===I.ERROR)&&setTimeout(()=>l(C),0),C})},[t,a,l]),u=x.useCallback(async o=>{var c,h,m,C;s(N=>({...N,request:o,timestamp:new Date().toISOString(),response:null,sseMessages:null,isStreaming:!1})),n(J.REQUEST);try{const N=await fetch(Se.CHAT_COMPLETIONS,{method:"POST",headers:{"Content-Type":"application/json","New-Api-User":Ve()},body:JSON.stringify(o)});if(!N.ok){let w="",b=null;try{w=await N.text();const _=JSON.parse(w);_!=null&&_.error&&(b=_.error)}catch{w||(w="无法读取错误响应体")}const S=ce(new Error(`HTTP error! status: ${N.status}, body: ${w}`),N);s(_=>({..._,response:JSON.stringify(S,null,2)})),n(J.RESPONSE);const v=new Error((b==null?void 0:b.message)||`HTTP error! status: ${N.status}, body: ${w}`);throw v.errorCode=(b==null?void 0:b.code)||null,v.errorType=(b==null?void 0:b.type)||null,v}const p=await N.json();if(s(w=>({...w,response:JSON.stringify(p,null,2)})),n(J.RESPONSE),(c=p.choices)!=null&&c[0]){const w=p.choices[0];let b=((h=w.message)==null?void 0:h.content)||"",S=((m=w.message)==null?void 0:m.reasoning_content)||((C=w.message)==null?void 0:C.reasoning)||"";const v=zs(b,S);t(_=>{const L=[..._],P=L[L.length-1];if((P==null?void 0:P.status)===I.LOADING){const ne=a(P,!0);L[L.length-1]={...P,content:v.content,reasoningContent:v.reasoningContent,status:I.COMPLETE,...ne}}return L})}}catch(N){console.error("Non-stream request error:",N);const p=ce(N);s(w=>({...w,response:JSON.stringify(p,null,2)})),n(J.RESPONSE),t(w=>{const b=[...w],S=b[b.length-1];if((S==null?void 0:S.status)===I.LOADING){const v=a(S,!0);b[b.length-1]={...S,content:i("请求发生错误: ")+N.message,errorCode:N.errorCode||null,status:I.ERROR,...v}}return b})}},[s,n,t,i,a]),g=x.useCallback(o=>{s(N=>({...N,request:o,timestamp:new Date().toISOString(),response:null,sseMessages:[],isStreaming:!0})),n(J.REQUEST);const c=new B(Se.CHAT_COMPLETIONS,{headers:{"Content-Type":"application/json","New-Api-User":Ve()},method:"POST",payload:JSON.stringify(o)});r.current=c;let h="",m=!1,C=!1;c.addEventListener("message",N=>{var p,w;if(N.data==="[DONE]"){C=!0,c.close(),r.current=null,s(b=>({...b,response:h,sseMessages:[...b.sseMessages||[],"[DONE]"],isStreaming:!1})),j();return}try{const b=JSON.parse(N.data);h+=N.data+`
11`,m||(n(J.RESPONSE),m=!0),s(v=>({...v,sseMessages:[...v.sseMessages||[],N.data]}));const S=(w=(p=b.choices)==null?void 0:p[0])==null?void 0:w.delta;S&&(S.reasoning_content&&y(S.reasoning_content,"reasoning"),S.reasoning&&y(S.reasoning,"reasoning"),S.content&&y(S.content,"content"))}catch(b){console.error("Failed to parse SSE message:",b);const S=`解析错误: ${b.message}`;s(v=>({...v,response:h+`
12
13Error: ${S}`,sseMessages:[...v.sseMessages||[],N.data],isStreaming:!1}
13)),n(J.RESPONSE),y(i("解析响应数据时发生错误"),"content"),j(I.ERROR)}}),c.addEventListener("error",N=>{if(!C&&c.readyState!==2){console.error("SSE Error:",N);let p=N.data||i("请求发生错误"),w=null;if(N.data)try{const S=JSON.parse(N.data);S!=null&&S.error&&(p=S.error.message||p,w=S.error.code||null)}catch{}const b=ce(new Error(p));b.readyState=c.readyState,s(S=>({...S,response:h+`
14
15SSE Error:
16`+JSON.stringify(b,null,2)})),n(J.RESPONSE),t(S=>{const v=[...S],_=v[v.length-1];return _&&_.status!==I.COMPLETE&&_.status!==I.ERROR&&(v[v.length-1]={..._,content:(_.content||"")+p,errorCode:w,status:I.ERROR}),v}),r.current=null,c.close()}}),c.addEventListener("readystatechange",N=>{if(N.readyState>=2&&c.status!==void 0&&c.status!==200&&!C){const p=ce(new Error("HTTP状态错误"));p.status=c.status,p.readyState=c.readyState,s(w=>({...w,response:h+`
17
18HTTP Error:
19`+JSON.stringify(p,null,2)})),n(J.RESPONSE),c.close(),y(i("连接已断开"),"content"),j(I.ERROR)}});try{c.stream()}catch(N){console.error("Failed to start SSE stream:",N);const p=ce(N);s(w=>({...w,response:`Stream启动失败:
20`+JSON.stringify(p,null,2)})),n(J.RESPONSE),y(i("建立连接时发生错误"),"content"),j(I.ERROR)}},[s,n,t,y,j,i,a]),f=x.useCallback(()=>{r.current&&(r.current.close(),r.current=null),t(o=>{if(o.length===0)return o;const c=o[o.length-1];if(c.status===I.LOADING||c.status===I.INCOMPLETE){const h=os(c.content||"",c.reasoningContent||""),m=a(c,!0),C=[...o.slice(0,-1),{...c,status:I.COMPLETE,reasoningContent:h.reasoningContent||null,content:h.content,...m}];return setTimeout(()=>l(C),0),C}return o})},[t,a,l]);return{sendRequest:x.useCallback((o,c)=>{c?g(o):u(o)},[g,u]),onStopGenerator:f,streamMessageUpdate:y,completeMessage:j}},Ct=(t,s,n,r,l,i,a)=>{const y=x.useRef(!1),j=x.useRef(!1),u=x.useRef(""),g=x.useRef(""),f=x.useCallback(h=>JSON.stringify(h.map(m=>({id:m.id,role:m.role,content:m.content}))),[]),d=x.useCallback(h=>{try{const m=JSON.parse(h);return JSON.stringify(m.messages||[])}catch{return""}},[]),o=x.useCallback(()=>{if(!t||j.current)return;const h=f(n);if(h!==u.current)try{y.current=!0;let m;try{m=JSON.parse(s||"{}")}catch{m={model:r.model||"gpt-4o",messages:[],temperature:r.temperature||.7,stream:r.stream!==!1}}m.messages=n.map(N=>({role:N.role,content:N.content}));const C=JSON.stringify(m,null,2);l(C),u.current=h,g.current=d(C),setTimeout(()=>{a()},0)}finally{y.current=!1}},[t,s,n,r.model,r.temperature,r.stream,f,d,l,a]),c=x.useCallback(()=>{if(!t||y.current)return;const h=d(s);if(h!==g.current)try{j.current=!0;const m=JSON.parse(s||"{}");if(m.messages&&Array.isArray(m.messages)){const C=m.messages.map((N,p)=>({id:N.id||(p+1).toString(),role:N.role||G.USER,content:N.content||"",createAt:Date.now(),...N.role===G.ASSISTANT&&{reasoningContent:N.reasoningContent||"",isReasoningExpanded:!1}}));i(C),g.current=h,u.current=f(C)}}catch(m){console.warn("同步自定义请求体到消息失败:",m)}finally{j.current=!1}},[t,s,d,f,i]);return{syncMessageToCustomBody:o,syncCustomBodyToMessage:c}},wt=(t,s,n,r,l)=>{const{t:i}=M(),[a,y]=x.useState(null),[j,u]=x.useState(""),g=x.useRef(null),f=x.useCallback(c=>{const h=he(c);y(c.id),g.current=c,u(h)},[]),d=x.useCallback(()=>{!a||!j.trim()||(t(c=>{let h=c.findIndex(p=>p===g.current);h===-1&&(h=c.findIndex(p=>p.id===a));const m=c[h];let C;Array.isArray(m.content)?C=m.content.map(p=>p.type==="text"?{...p,text:j.trim()}:p):C=j.trim();const N=c.map(p=>p.id===a?{...p,content:C}:p);return m.role===G.USER&&h<c.length-1&&c[h+1].role===G.ASSISTANT?(ue.confirm({title:i("消息已编辑"),content:i("检测到该消息后有AI回复,是否删除后续回复并重新生成?"),okText:i("重新生成"),cancelText:i("仅保存"),onOk:()=>{const w=N.slice(0,h+1);t(w),setTimeout(()=>l(w),0),setTimeout(()=>{const b=ze(w,null,s,n);t(S=>[...S,cs()]),r(b,s.stream)},100)},onCancel:()=>{t(N),setTimeout(()=>l(N),0)}}),c):(setTimeout(()=>l(N),0),N)}),y(null),g.current=null,u(""),z.success({content:i("消息已更新"),duration:2}))},[a,j,i,s,n,r,t,l]),o=x.useCallback(()=>{y(null),g.current=null,u("")},[]);return{editingMessageId:a,editValue:j,setEditValue:u,handleMessageEdit:f,handleEditSave:d,handleEditCancel:o}},St=(t,s,n,r,l)=>{const{t:i}=M(),a=x.useCallback(async()=>{try{const j=await We.get(Se.USER_MODELS),{success:u,message:g,data:f}=j.data;if(u){const{modelOptions:d,selectedModel:o}=_s(f,s.model);r(d),o!==s.model&&n("model",o)}else be(i(g))}catch{be(i("加载模型失败"))}},[s.model,n,r,i]),y=x.useCallback(async()=>{var j,u,g;try{const f=await We.get(Se.USER_GROUPS),{success:d,message:o,data:c}=f.data;if(d){const h=((j=t==null?void 0:t.user)==null?void 0:j.group)||((u=JSON.parse(localStorage.getItem("user")))==null?void 0:u.group),m=As(c,h);l(m),m.some(N=>N.value===s.group)||n("group",((g=m[0])==null?void 0:g.value)||"")}else be(i(o))}catch{be(i("加载分组失败"))}},[t,s.group,n,l,i]);return x.useEffect(()=>{t!=null&&t.user&&(a(),y())},[t==null?void 0:t.user,a,y]),{loadModels:a,loadGroups:y}},Et=({message:t,finalExtractedThinkingContent:s,thinkingSource:n,styleState:r,onToggleReasoningExpansion:l})=>{const{t:i}=M(),a=x.useRef(null),y=x.useRef(""),j=t.status==="loading"||t.status==="incomplete",u=j&&!t.isThinkingComplete?i("思考中..."):i("思考过程");if(x.useEffect(()=>{a.current&&s&&t.isReasoningExpanded&&(a.current.scrollTop=a.current.scrollHeight)},[s,t.isReasoningExpanded]),x.useEffect(()=>{j||(y.current="")},[j]),!s)return null;let g=0;return j&&y.current&&s.startsWith(y.current)&&(g=y.current.length),j&&(y.current=s),e.jsxs("div",{className:"rounded-xl sm:rounded-2xl mb-2 sm:mb-4 overflow-hidden shadow-sm backdrop-blur-sm",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 cursor-pointer hover:bg-gradient-to-r hover:from-white/20 hover:to-purple-50/30 transition-all",style:{background:"linear-gradient(135deg, #4c1d95 0%, #6d28d9 50%, #7c3aed 100%)",position:"relative"},onClick:()=>l(t.id),children:[e.jsxs("div",{className:"absolute inset-0 overflow-hidden",children:[e.jsx("div",{className:"absolute -top-10 -right-10 w-40 h-40 bg-white opacity-5 rounded-full"}),e.jsx("div",{className:"absolute -bottom-8 -left-8 w-24 h-24 bg-white opacity-10 rounded-full"})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-4 relative",children:[e.jsx("div",{className:"w-6 h-6 sm:w-8 sm:h-8 rounded-full bg-white/20 flex items-center justify-center shadow-lg",children:e.jsx(Js,{style:{color:"white"},size:r.isMobile?12:16})}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(E.Text,{strong:!0,style:{color:"white"},className:"text-sm sm:text-base",children:u}),n&&e.jsxs(E.Text,{style:{color:"white"},className:"text-xs mt-0.5 opacity-80 hidden sm:block",children:["来源: ",n]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 relative",children:[j&&!t.isThinkingComplete&&e.jsxs("div",{className:"flex items-center gap-1 sm:gap-2",children:[e.jsx(ds,{style:{color:"white"},className:"animate-spin",size:r.isMobile?14:18}),e.jsx(E.Text,{style:{color:"white"},className:"text-xs sm:text-sm font-medium opacity-90",children:"思考中"})]}),(!j||t.isThinkingComplete)&&e.jsx("div",{className:"w-5 h-5 sm:w-6 sm:h-6 rounded-full bg-white/20 flex items-center justify-center",children:t.isReasoningExpanded?e.jsx(us,{size:r.isMobile?12:16,style:{color:"white"}}):e.jsx(Us,{size:r.isMobile?12:16,style:{color:"white"}})})]})]}),e.jsx("div",{className:`transition-all duration-500 ease-out ${t.isReasoningExpanded?"max-h-96 opacity-100":"max-h-0 opacity-0"} overflow-hidden bg-gradient-to-br from-purple-50 via-indigo-50 to-violet-50`,children:t.isReasoningExpanded&&e.jsx("div",{className:"p-3 sm:p-5 pt-2 sm:pt-4",children:e.jsx("div",{ref:a,className:"bg-white/70 backdrop-blur-sm rounded-lg sm:rounded-xl p-2 shadow-inner overflow-x-auto overflow-y-auto thinking-content-scroll",style:{maxHeight:"200px",scrollbarWidth:"thin",scrollbarColor:"rgba(0, 0, 0, 0.3) transparent"},children:e.jsx("div",{className:"prose prose-xs sm:prose-sm prose-purple max-w-none text-xs sm:text-sm",children:e.jsx(we,{c
20ontent:s,className:"",animated:j,previousContentLength:g})})})})})]})},vt=({message:t,className:s,styleState:n,onToggleReasoningExpansion:r,isEditing:l=!1,onEditSave:i,onEditCancel:a,editValue:y,onEditValueChange:j})=>{const{t:u}=M(),g=x.useRef(0),f=x.useRef(""),d=t.status==="loading"||t.status==="incomplete";if(x.useEffect(()=>{d||(g.current=0,f.current="")},[d]),t.status==="error"){let p;if(Array.isArray(t.content)){const w=t.content.find(b=>b.type==="text");p=w&&w.text&&typeof w.text=="string"?w.text:u("请求发生错误")}else typeof t.content=="string"?p=t.content:p=u("请求发生错误");return t.errorCode==="model_price_error"?e.jsx("div",{className:`${s}`,children:e.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:"var(--semi-color-bg-0)",border:"1px solid var(--semi-color-border)"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hs,{size:16,className:"text-orange-500 shrink-0"}),e.jsx(E.Text,{strong:!0,className:"!text-[var(--semi-color-text-0)]",children:u("模型价格未配置")})]}),e.jsx(E.Paragraph,{className:"!text-[var(--semi-color-text-1)] !text-sm !mb-0",style:{wordBreak:"break-word"},children:p}),Ms()&&e.jsx(k,{size:"small",theme:"light",type:"warning",icon:e.jsx(De,{size:14}),onClick:()=>window.open("/console/setting?tab=ratio","_blank"),children:u("前往设置")})]})}):e.jsx("div",{className:`${s}`,children:e.jsx(E.Text,{className:"text-white",children:p})})}let o=null,c="",h=null;const m=p=>{if(Array.isArray(p)){const w=p.find(b=>b.type==="text");return w&&w.text&&typeof w.text=="string"?w.text:""}else if(typeof p=="string")return p;return""};if(c=m(t.content),t.role==="assistant"){let p=m(t.content),w="";if(t.reasoningContent&&(w=t.reasoningContent,h="reasoningContent"),p.includes("<think>")){const b=/<think>([\s\S]*?)<\/think>/g;let S,v=[],_=[],L=0;for(;(S=b.exec(p))!==null;)_.push(p.substring(L,S.index)),v.push(S[1]),L=S.index+S[0].length;if(_.push(p.substring(L)),v.length>0){const P=v.join(`
21
22---
23
24`);w?w+=`
25
26---
27
28`+P:w=P,h=h?h+" & <think> tags":"<think> tags"}p=_.join("")}if(d){const b=p.lastIndexOf("<think>");if(b!==-1){const S=p.substring(b);if(!S.includes("</think>")){const v=S.substring(7).trim();v&&(w?w+=`
29
30---
31
32`+v:w=v,h=h?h+" + streaming <think>":"streaming <think>"),p=p.substring(0,b)}}}o=w||null,c=p.replace(/<\/?think>/g,"").trim()}const C=o,N=c;return t.role==="assistant"&&d&&!C&&(!N||N.trim()==="")?e.jsx("div",{className:`${s} flex items-center gap-2 sm:gap-4 bg-gradient-to-r from-purple-50 to-indigo-50`,children:e.jsx("div",{className:"w-5 h-5 rounded-full bg-gradient-to-br from-purple-500 to-indigo-600 flex items-center justify-center shadow-lg",children:e.jsx(ds,{className:"animate-spin text-white",size:n.isMobile?16:20})})}):e.jsxs("div",{className:s,children:[t.role==="system"&&e.jsx("div",{className:"mb-2 sm:mb-4",children:e.jsxs("div",{className:"flex items-center gap-2 p-2 sm:p-3 bg-gradient-to-r from-amber-50 to-orange-50 rounded-lg",style:{border:"1px solid var(--semi-color-border)"},children:[e.jsx("div",{className:"w-4 h-4 sm:w-5 sm:h-5 rounded-full bg-gradient-to-br from-amber-500 to-orange-600 flex items-center justify-center shadow-sm",children:e.jsx(E.Text,{className:"text-white text-xs font-bold",children:"S"})}),e.jsx(E.Text,{className:"text-amber-700 text-xs sm:text-sm font-medium",children:u("系统消息")})]})}),t.role==="assistant"&&e.jsx(Et,{message:t,finalExtractedThinkingContent:C,thinkingSource:h,styleState:n,onToggleReasoningExpansion:r}),l?e.jsxs("div",{className:"space-y-3",children:[e.jsx(is,{value:y,onChange:p=>j(p),placeholder:u("请输入消息内容..."),autosize:{minRows:3,maxRows:12},style:{resize:"vertical",fontSize:n.isMobile?"14px":"15px",lineHeight:"1.6"},className:"!border-blue-200 focus:!border-blue-400 !bg-blue-50/50"}),e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx(k,{size:"small",type:"danger",theme:"light",icon:e.jsx(U,{size:14}),onClick:a,className:"flex-1",children:u("取消")}),e.jsx(k,{size:"small",type:"warning",theme:"solid",icon:e.jsx(Q,{size:14}),onClick:i,disabled:!y||y.trim()==="",className:"flex-1",children:u("保存")})]})]}):(()=>
32{if(Array.isArray(t.content)){const p=t.content.find(b=>b.type==="text"),w=t.content.filter(b=>b.type==="image_url").map(b=>({...b,image_url:typeof b.image_url=="string"?{url:b.image_url}:b.image_url})).filter(b=>{var S;return(S=b.image_url)==null?void 0:S.url});return e.jsxs("div",{children:[w.length>0&&e.jsx("div",{className:"mb-3 space-y-2",children:w.map((b,S)=>e.jsxs("div",{className:"max-w-sm",children:[e.jsx("img",{src:b.image_url.url,alt:`用户上传的图片 ${S+1}`,className:"rounded-lg max-w-full h-auto shadow-sm border",style:{maxHeight:"300px"},onError:v=>{v.target.style.display="none",v.target.nextSibling.style.display="block"}}),e.jsxs("div",{className:"text-red-500 text-sm p-2 bg-red-50 rounded-lg border border-red-200",style:{display:"none"},children:["图片加载失败: ",b.image_url.url]})]},S))}),p&&p.text&&typeof p.text=="string"&&p.text.trim()!==""&&e.jsx("div",{className:`prose prose-xs sm:prose-sm prose-gray max-w-none overflow-x-auto text-xs sm:text-sm ${t.role==="user"?"user-message":""}`,children:e.jsx(we,{content:p.text,className:t.role==="user"?"user-message":"",animated:!1,previousContentLength:0})})]})}if(typeof t.content=="string")if(t.role==="assistant"){if(N&&N.trim()!==""){let p=0;return d&&f.current&&N.startsWith(f.current)&&(p=f.current.length),d&&(f.current=N),e.jsx("div",{className:"prose prose-xs sm:prose-sm prose-gray max-w-none overflow-x-auto text-xs sm:text-sm",children:e.jsx(we,{content:N,className:"",animated:d,previousContentLength:p})})}}else return e.jsx("div",{className:`prose prose-xs sm:prose-sm prose-gray max-w-none overflow-x-auto text-xs sm:text-sm ${t.role==="user"?"user-message":""}`,children:e.jsx(we,{content:t.content,className:t.role==="user"?"user-message":"",animated:!1,previousContentLength:0})});return null})()]})},Tt=({message:t,styleState:s,onMessageReset:n,onMessageCopy:r,onMessageDelete:l,onRoleToggle:i,onMessageEdit:a,isAnyMessageGenerating:y=!1,isEditing:j=!1})=>{const{t:u}=M(),g=t.status==="loading"||t.status==="incomplete",f=y||j,d=t.role==="assistant"||t.role==="system",o=!g&&t.content&&typeof a=="function"&&!j;return e.jsxs("div",{className:"flex items-center gap-0.5",children:[!g&&e.jsx(se,{content:u(f?"操作暂时被禁用":"重试"),position:"top",children:e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(Bs,{size:s.isMobile?12:14}),onClick:()=>!f&&n(t),disabled:f,className:`!rounded-full ${f?"!text-gray-300 !cursor-not-allowed":"!text-gray-400 hover:!text-blue-600 hover:!bg-blue-50"} ${s.isMobile?"!w-6 !h-6":"!w-7 !h-7"} !p-0 transition-all`,"aria-label":u("重试")})}),t.content&&e.jsx(se,{content:u("复制"),position:"top",children:e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(_e,{size:s.isMobile?12:14}),onClick:()=>r(t),className:`!rounded-full !text-gray-400 hover:!text-green-600 hover:!bg-green-50 ${s.isMobile?"!w-6 !h-6":"!w-7 !h-7"} !p-0 transition-all`,"aria-label":u("复制")})}),o&&e.jsx(se,{content:u(f?"操作暂时被禁用":"编辑"),position:"top",children:e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(ms,{size:s.isMobile?12:14}),onClick:()=>!f&&a(t),disabled:f,className:`!rounded-full ${f?"!text-gray-300 !cursor-not-allowed":"!text-gray-400 hover:!text-yellow-600 hover:!bg-yellow-50"} ${s.isMobile?"!w-6 !h-6":"!w-7 !h-7"} !p-0 transition-all`,"aria-label":u("编辑")})}),d&&!g&&e.jsx(se,{content:f?u("操作暂时被禁用"):t.role==="assistant"?u("切换为System角色"):u("切换为Assistant角色"),position:"top",children:e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(Gs,{size:s.isMobile?12:14}),onClick:()=>!f&&i&&i(t),disabled:f,className:`!rounded-full ${f?"!text-gray-300 !cursor-not-allowed":t.role==="system"?"!text-purple-500 hover:!text-purple-700 hover:!bg-purple-50":"!text-gray-400 hover:!text-purple-600 hover:!bg-purple-50"} ${s.isMobile?"!w-6 !h-6":"!w-7 !h-7"} !p-0 transition-all`,"aria-label":t.role==="assistant"?u("切换为System角色"):u("切换为Assistant角色")})}),!g&&e.jsx(se,{content:u(f?"操作暂时被禁用":"删除"),position:"top",children:e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(qs,{size:s.isMobile?12:14}),onClick:()=>!f&&l(t),disabled:f,className:`!rounded-full ${f?"!text-gray-300 !cursor-not-allowed":"!text-gray-400 hover:!text-red-600 hover:!bg-red-50"}
32 ${s.isMobile?"!w-6 !h-6":"!w-7 !h-7"} !p-0 transition-all`,"aria-label":u("删除")})})]})},kt=({inputs:t,parameterEnabled:s,onInputChange:n,onParameterToggle:r,disabled:l=!1})=>{const{t:i}=M();return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.temperature||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Hs,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Temperature"}),e.jsx(je,{size:"small",shape:"circle",children:t.temperature})]}),e.jsx(k,{theme:s.temperature?"solid":"borderless",type:s.temperature?"primary":"tertiary",size:"small",icon:s.temperature?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("temperature"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2",children:i("控制输出的随机性和创造性")}),e.jsx(Ne,{step:.1,min:.
321,max:1,value:t.temperature,onChange:a=>n("temperature",a),className:"mt-2",disabled:!s.temperature||l})]}),e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.top_p||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vs,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Top P"}),e.jsx(je,{size:"small",shape:"circle",children:t.top_p})]}),e.jsx(k,{theme:s.top_p?"solid":"borderless",type:s.top_p?"primary":"tertiary",size:"small",icon:s.top_p?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("top_p"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2",children:i("核采样,控制词汇选择的多样性")}),e.jsx(Ne,{step:.1,min:.1,max:1,value:t.top_p,onChange:a=>n("top_p",a),className:"mt-2",disabled:!s.top_p||l})]}),e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.frequency_penalty||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ws,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Frequency Penalty"}),e.jsx(je,{size:"small",shape:"circle",children:t.frequency_penalty})]}),e.jsx(k,{theme:s.frequency_penalty?"solid":"borderless",type:s.frequency_penalty?"primary":"tertiary",size:"small",icon:s.frequency_penalty?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("frequency_penalty"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2",children:i("频率惩罚,减少重复词汇的出现")}),e.jsx(Ne,{step:.1,min:-2,max:2,value:t.frequency_penalty,onChange:a=>n("frequency_penalty",a),className:"mt-2",disabled:!s.frequency_penalty||l})]}),e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.presence_penalty||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Presence Penalty"}),e.jsx(je,{size:"small",shape:"circle",children:t.presence_penalty})]}),e.jsx(k,{theme:s.presence_penalty?"solid":"borderless",type:s.presence_penalty?"primary":"tertiary",size:"small",icon:s.presence_penalty?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("presence_penalty"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2",children:i("存在惩罚,鼓励讨论新话题")}),e.jsx(Ne,{step:.1,min:-2,max:2,value:t.presence_penalty,onChange:a=>n("presence_penalty",a),className:"mt-2",disabled:!s.presence_penalty||l})]}),e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.max_tokens||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xs,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Max Tokens"})]}),e.jsx(k,{theme:s.max_tokens?"solid":"borderless",type:s.max_tokens?"primary":"tertiary",size:"small",icon:s.max_tokens?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("max_tokens"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(vs,{placeholder:"MaxTokens",name:"max_tokens",value:t.max_tokens,onNumberChange:a=>n("max_tokens",a),min:0,precision:0,style:{width:"100%"},disabled:!s.max_tokens||l})]}),e.jsxs("div",{className:`transition-opacity duration-200 mb-4 ${!s.seed||l?"opacity-50":""}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zs,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:"Seed"}),e.jsxs(E.Text,{className:"text-xs text-gray-400",children:["(",i("可选,用于复现结果"),")"]})]}),e.jsx(k,{theme:s.seed?"solid":"borderless",type:s.seed?"primary":"tertiary",size:"small",icon:s.seed?e.jsx(Q,{size:10}):e.jsx(U,{size:10}),onClick:()=>r("seed"),className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:l})]}),e.jsx(ls,{placeholder:i("随机种子 (留空为随机)"),name:"seed",autoComplete:"new-password",value:t.seed||"",onChange:a=>n("seed",a===""?null:a),className:"!rounded-lg",disabled:!s.seed||l})]})]})},Rt=({imageUrls:t,imageEnabled:s,onImageUrlsChange:n,onImageEnabledChange:r,disabled:l=!1})=>{const{t:i}=M(),a=()=>{const u=[...t,""];n(u)},y=(u,g)=>{const f=[...t];f[u]=g,n(f)},j=u=>{const g=t.filter((f,d)=>d!==u);n(g)};return e.jsxs("div",{className:l?"opacity-50":"",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Qs,{size:16,className:s&&!l?"text-blue-500":"text-gray-400"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:i("图片地址")}),l&&e.jsxs(E.Text,{className:"text-xs text-orange-600",children:["(",i("已在自定义模式中忽略"),")"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ae,{checked:s,onChange:r,checkedText:i("启用"),uncheckedText:i("停用"),size:"small",className:"flex-shrink-0",disabled:l}),e.jsx(k,{icon:e.jsx(Ys,{size:14}),size:"small",theme:"solid",type:"primary",onClick:a,className:"!rounded-full !w-4 !h-4 !p-0 !min-w-0",disabled:!s||l})]})]}),s?t.length===0?e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2 block",children:i(l?"图片功能在自定义请求体模式下不可用":"点击 + 按钮添加图片URL进行多模态对话")}):e.jsxs(E.Text,{className:"text-xs text-gray-500 mb-2 block",children:[i("已添加")," ",t.length," ",i("张图片"),l?` (${i("自定义模式下不可用")})`:""]}):e.jsx(E.Text,{className:"text-xs text-gray-500 mb-2 block",children:i(l?"图片功能在自定义请求体模式下不可用":"启用后可添加图片URL进行多模态对话")}),e.jsx("div",{className:`space-y-2 max-h-32 overflow-y-auto image-list-scroll ${!s||l?"opacity-50":""}`,children:t.map((u,g)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1",children:e.jsx(ls,{placeholder:`https://example.com/image${g+1}.jpg`,value:u,onChange:f=>y(g,f),className:"!rounded-lg",size:"small",prefix:e.jsx(Ts,{size:"small"}),disabled:!s||l})}),e.jsx(k,{icon:e.jsx(U,{size:12}),size:"small",theme:"borderless",type:"danger",onClick:()=>j(g),className:"!rounded-full !w-6 !h-6 !p-0 !min-w-0 !text-red-500 hover:!bg-red-50 flex-shrink-0",disabled:!s||l})]},g))})]})},rs=({currentConfig:t,onConfigImport:s,onConfigReset:n,styleState:r,messages:l})=>{const{t:i}=M(),a=x.useRef(null),y=()=>{try{const o={...t,timestamp:new Date().toISOString()};localStorage.setItem("playground_config",JSON.stringify(o)),pt(t,l),z.success({content:i("配置已导出到下载文件夹"),duration:3})}catch(o){z.error({content:i("导出配置失败: ")+o.message,duration:3})}},j=()=>{var o;(o=a.current)==null||o.click()},u=async o=>{const c=o.target.files[0];if(c)try{const h=await yt(c);ue.confirm({title:i("确认导入配置"),content:i("导入的配置将覆盖当前设置,是否继续?"),okText:i("确定导入"),cancelText:i("取消"),onOk:()=>{s(h),z.success({content:i("配置导入成功"),duration:3})}})}catch(h){z.error({content:i("导入配置失败: ")+h.message,duration:3})}finally{o.target.value=""}},g=()=>{ue.confirm({title:i("重置配置"),content:i("将清除所有保存的配置并恢复默认设置,此操作不可撤销。是否继续?"),okText:i("确定重置"),cancelText:i("取消"),okButtonProps:{type:"danger"},onOk:()=>{ue.confirm({title:i("重置选项"),content:i('是否同时重置对话消息?选择"是"将清空所有对话记录并恢复默认示例;选择"否"将保留当前对话记录。'),okText:i("同时重置消息"),cancelText:i("仅重置配置"),okButtonProps:{type:"danger"},onOk:()=>{ns(),n({resetMessages:!0}),z.success({content:i("配置和消息已全部重置"),duration:3})},onCancel:()=>{ns(),n({resetMessages:!1}),z.success({content:i("配置已重置,对话消息已保留"),duration:3})}})}})},f=()=>{if(gt()){const o=ft();if(o){const c=new Date(o);
32return i("上次保存: ")+c.toLocaleString()}return i("已有保存的配置")}return i("暂无保存的配置")},d=[{node:"item",name:"export",onClick:y,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(es,{size:14}),i("导出配置")]})},{node:"item",name:"import",onClick:j,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ss,{size:14}),i("导入配置")]})},{node:"divider"},{node:"item",name:"reset",onClick:g,children:e.jsxs("div",{className:"flex items-center gap-2 text-red-600",children:[e.jsx(ts,{size:14}),i("重置配置")]})}];return r.isMobile?e.jsxs(e.Fragment,{children:[e.jsx(Ce,{trigger:"click",position:"bottomLeft",showTick:!0,menu:d,children:e.jsx(k,{icon:e.jsx(et,{size:14}),theme:"borderless",type:"tertiary",size:"small",className:"!rounded-lg !text-gray-600 hover:!text-blue-600 hover:!bg-blue-50"})}),e.jsx("input",{ref:a,type:"file",accept:".json",onChange:u,style:{display:"none"}})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E.Text,{className:"text-xs text-gray-500",children:f()}),e.jsx(k,{icon:e.jsx(ts,{size:12}),size:"small",theme:"borderless",type:"danger",onClick:g,className:"!rounded-full !text-xs !px-2"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(k,{icon:e.jsx(es,{size:12}),size:"small",theme:"solid",type:"primary",onClick:y,className:"!rounded-lg flex-1 !text-xs !h-7",children:i("导出")}),e.jsx(k,{icon:e.jsx(ss,{size:12}),size:"small",theme:"outline",type:"primary",onClick:j,className:"!rounded-lg flex-1 !text-xs !h-7",children:i("导入")})]}),e.jsx("input",{ref:a,type:"file",accept:".json",onChange:u,style:{display:"none"}})]})},Ot=({customRequestMode:t,customRequestBody:s,onCustomRequestModeChange:n,onCustomRequestBodyChange:r,defaultPayload:l})=>{const{t:i}=M(),[a,y]=x.useState(!0),[j,u]=x.useState(""),[g,f]=x.useState(s||"");x.useEffect(()=>{if(t&&(!s||s.trim()==="")){const m=l?JSON.stringify(l,null,2):"";f(m),r(m)}},[t,l,s,r]),x.useEffect(()=>{s!==g&&(f(s||""),d(s||""))},[s]);const d=m=>{if(!m.trim())return y(!0),u(""),!0;try{return JSON.parse(m),y(!0),u(""),!0}catch(C){return y(!1),u(`${i("JSON格式错误")}: ${C.message}`),!1}},o=m=>{f(m),d(m),r(m)},c=m=>{if(n(m),m&&l){const C=JSON.stringify(l,null,2);f(C),r(C)}},h=()=>{try{const m=JSON.parse(g),C=JSON.stringify(m,null,2);f(C),r(C),y(!0),u("")}catch{}};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:i("自定义请求体模式")})]}),e.jsx(Ae,{checked:t,onChange:c,checkedText:i("开"),uncheckedText:i("关"),size:"small"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx(ks,{type:"warning",description:i("启用此模式后,将使用您自定义的请求体发送API请求,模型配置面板的参数设置将被忽略。"),icon:e.jsx(hs,{size:16}),className:"!rounded-lg",closeIcon:null}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx(E.Text,{strong:!0,className:"text-sm",children:i("请求体 JSON")}),e.jsxs("div",{className:"flex items-center gap-2",children:[a?e.jsxs("div",{className:"flex items-center gap-1 text-green-600",children:[e.jsx(Q,{size:14}),e.jsx(E.Text,{className:"text-xs",children:i("格式正确")})]}):e.jsxs("div",{className:"flex items-center gap-1 text-red-600",children:[e.jsx(U,{size:14}),e.jsx(E.Text,{className:"text-xs",children:i("格式错误")})]}),e.jsx(k,{theme:"borderless",type:"tertiary",size:"small",icon:e.jsx(ms,{size:14}),onClick:h,disabled:!a,className:"!rounded-lg",children:i("格式化")})]})]}),e.jsx(is,{value:g,onChange:o,placeholder:'{"model": "gpt-4o", "messages": [...], ...}',autosize:{minRows:8,maxRows:20},className:`custom-request-textarea !rounded-lg font-mono text-sm ${a?"":"!border-red-500"}`,style:{fontFamily:'Consolas, Monaco, "Courier New", monospace',lineHeight:"1.5"}}),!a&&j&&e.jsx(E.Text,{type:"danger",className:"text-xs mt-1 block",children:j}),e.jsx(E.Text,{className:"text-xs text-gray-500 mt-2 block",children:i("请输入有效的JSON格式的请求体。您可以参考预览面板中的默认请求体格式。")})]})]})]})},It=({inputs:t,parameterEnabled:s,models:n,groups:r,styleState:l,showDebugPanel:i,customRequestMode:
32a,customRequestBody:y,onInputChange:j,onParameterToggle:u,onCloseSettings:g,onConfigImport:f,onConfigReset:d,onCustomRequestModeChange:o,onCustomRequestBodyChange:c,previewPayload:h,messages:m})=>{const{t:C}=M(),N={inputs:t,parameterEnabled:s,showDebugPanel:i,customRequestMode:a,customRequestBody:y};return e.jsxs(Me,{className:"h-full flex flex-col",bordered:!1,bodyStyle:{padding:l.isMobile?"16px":"24px",height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-r from-purple-500 to-pink-500 flex items-center justify-center mr-3",children:e.jsx(De,{size:20,className:"text-white"})}),e.jsx(E.Title,{heading:5,className:"mb-0",children:C("模型配置")})]}),l.isMobile&&g&&e.jsx(k,{icon:e.jsx(U,{size:16}),onClick:g,theme:"borderless",type:"tertiary",size:"small",className:"!rounded-lg"})]}),l.isMobile&&e.jsx("div",{className:"mb-4 flex-shrink-0",children:e.jsx(rs,{currentConfig:N,onConfigImport:f,onConfigReset:d,styleState:{...l,isMobile:!1},messages:m})}),e.jsxs("div",{className:"space-y-6 overflow-y-auto flex-1 pr-2 model-settings-scroll",children:[e.jsx(Ot,{customRequestMode:a,customRequestBody:y,onCustomRequestModeChange:o,onCustomRequestBodyChange:c,defaultPayload:h}),e.jsxs("div",{className:a?"opacity-50":"",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(st,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:C("分组")}),a&&e.jsxs(E.Text,{className:"text-xs text-orange-600",children:["(",C("已在自定义模式中忽略"),")"]})]}),e.jsx(qe,{placeholder:C("请选择分组"),name:"group",required:!0,selection:!0,filter:Ke,autoClearSearchValue:!1,onChange:p=>j("group",p),value:t.group,autoComplete:"new-password",optionList:r,renderOptionItem:Ds,style:{width:"100%"},dropdownStyle:{width:"100%",maxWidth:"100%"},className:"!rounded-lg",disabled:a})]}),e.jsxs("div",{className:a?"opacity-50":"",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(tt,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:C("模型")}),a&&e.jsxs(E.Text,{className:"text-xs text-orange-600",children:["(",C("已在自定义模式中忽略"),")"]})]}),e.jsx(qe,{placeholder:C("请选择模型"),name:"model",required:!0,selection:!0,filter:Ke,autoClearSearchValue:!1,onChange:p=>j("model",p),value:t.model,autoComplete:"new-password",optionList:n,style:{width:"100%"},dropdownStyle:{width:"100%",maxWidth:"100%"},className:"!rounded-lg",disabled:a})]}),e.jsx("div",{className:a?"opacity-50":"",children:e.jsx(Rt,{imageUrls:t.imageUrls,imageEnabled:t.imageEnabled,onImageUrlsChange:p=>j("imageUrls",p),onImageEnabledChange:p=>j("imageEnabled",p),disabled:a})}),e.jsx("div",{className:a?"opacity-50":"",children:e.jsx(kt,{inputs:t,parameterEnabled:s,onInputChange:j,onParameterToggle:u,disabled:a})}),e.jsx("div",{className:a?"opacity-50":"",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(nt,{size:16,className:"text-gray-500"}),e.jsx(E.Text,{strong:!0,className:"text-sm",children:C("流式输出")}),a&&e.jsxs(E.Text,{className:"text-xs text-orange-600",children:["(",C("已在自定义模式中忽略"),")"]})]}),e.jsx(Ae,{checked:t.stream,onChange:p=>j("stream",p),checkedText:C("开"),uncheckedText:C("关"),size:"small",disabled:a})]})})]}),!l.isMobile&&e.jsx("div",{className:"flex-shrink-0 pt-3",children:e.jsx(rs,{currentConfig:N,onConfigImport:f,onConfigReset:d,styleState:l,messages:m})})]})},zt=({sseData:t})=>{const{t:s}=M(),[n,r]=x.useState([]),[l,i]=x.useState(!1),a=x.useMemo(()=>!t||!Array.isArray(t)?[]:t.map((d,o)=>{let c=null,h=null,m=!1;if(d==="[DONE]")m=!0;else try{c=typeof d=="string"?JSON.parse(d):d}catch(C){h=C.message}return{index:o,raw:d,parsed:c,error:h,isDone:m,key:`sse-${o}`}}),[t]),y=x.useMemo(()=>{const d=a.length,o=a.filter(m=>m.error).length,c=a.filter(m=>m.isDone).length,h=d-o-c;return{total:d,errors:o,done:c,valid:h}},[a]),j=x.useCallback(()=>{r(d=>d.length===a.length?[]:a.map(o=>o.key))},[a]),u=x.useCallback(async()=>{try{const d=a.map(o=>o.parsed?JSON.stringify(o.parsed,null,2):o.raw).join(`
33
34`);await Xe(d),i(!0),z.success(s("已复制全部数据")),setTimeout(()=>i(!1),2e3)}catch(d){z.error(s("复制失败")),console.error("Copy failed:",d)}},[a,s]),g=x.useCallback(async d=>{try{const o=d.parsed?JSON.stringify(d.parsed,null,2):d.raw;await Xe(o),z.success(s("已复制"))}catch{z.error(s("复制失败"))}},[s]),f=d=>{var o,c,h,m;return d.isDone?e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-green-50 dark:bg-green-900/20 rounded-lg",children:[e.jsx(at,{size:16,className:"text-green-600"}),e.jsxs(E.Text,{className:"text-green-600 font-medium",children:[s("流式响应完成")," [DONE]"]})]}):d.error?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-red-50 dark:bg-red-900/20 rounded-lg",children:[e.jsx(it,{size:16,className:"text-red-600"}),e.jsxs(E.Text,{className:"text-red-600",children:[s("解析错误"),": ",d.error]})]}),e.jsx("div",{className:"p-3 bg-gray-100 dark:bg-gray-800 rounded-lg font-mono text-xs overflow-auto",children:e.jsx("pre",{children:d.raw})})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx("pre",{className:"p-4 bg-gray-900 text-gray-100 rounded-lg overflow-auto text-xs font-mono leading-relaxed",children:JSON.stringify(d.parsed,null,2)}),e.jsx(k,{icon:e.jsx(_e,{size:12}),size:"small",theme:"borderless",onClick:()=>g(d),className:"absolute top-2 right-2 !bg-gray-800/80 !text-gray-300 hover:!bg-gray-700"})]}),((c=(o=d.parsed)==null?void 0:o.choices)==null?void 0:c[0])&&e.jsxs("div",{className:"flex flex-wrap gap-2 text-xs",children:[((h=d.parsed.choices[0].delta)==null?void 0:h.content)&&e.jsx(ee,{count:`${s("内容")}
34: "${String(d.parsed.choices[0].delta.content).substring(0,20)}..."`,type:"primary"}),((m=d.parsed.choices[0].delta)==null?void 0:m.reasoning_content)&&e.jsx(ee,{count:s("有 Reasoning"),type:"warning"}),d.parsed.choices[0].finish_reason&&e.jsx(ee,{count:`${s("完成")}: ${d.parsed.choices[0].finish_reason}`,type:"success"}),d.parsed.usage&&e.jsx(ee,{count:`${s("令牌")}: ${d.parsed.usage.prompt_tokens||0}/${d.parsed.usage.completion_tokens||0}`,type:"tertiary"})]})]})};return!a||a.length===0?e.jsx("div",{className:"flex items-center justify-center h-full min-h-[200px] text-gray-500",children:e.jsx("span",{children:s("暂无SSE响应数据")})}):e.jsxs("div",{className:"h-full flex flex-col bg-gray-50 dark:bg-gray-900/50 rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(gs,{size:16,className:"text-blue-500"}),e.jsx(E.Text,{strong:!0,children:s("SSE数据流")}),e.jsx(ee,{count:y.total,type:"primary"}),y.errors>0&&e.jsx(ee,{count:`${y.errors} ${s("错误")}`,type:"danger"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{content:s("复制全部"),children:e.jsx(k,{icon:e.jsx(_e,{size:14}),size:"small",onClick:u,theme:"borderless",children:s(l?"已复制":"复制全部")})}),e.jsx(se,{content:n.length===a.length?s("全部收起"):s("全部展开"),children:e.jsx(k,{icon:n.length===a.length?e.jsx(us,{size:14}):e.jsx(rt,{size:14}),size:"small",onClick:j,theme:"borderless",children:n.length===a.length?s("收起"):s("展开")})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:e.jsx(He,{activeKey:n,onChange:r,accordion:!1,className:"bg-white dark:bg-gray-800 rounded-lg",children:a.map(d=>{var o,c,h,m,C;return e.jsx(He.Panel,{header:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{count:`#${d.index+1}`,type:"tertiary"}),d.isDone?e.jsx("span",{className:"text-green-600 font-medium",children:"[DONE]"}):d.error?e.jsx("span",{className:"text-red-600",children:s("解析错误")}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-gray-600",children:((o=d.parsed)==null?void 0:o.id)||((c=d.parsed)==null?void 0:c.object)||s("SSE 事件")}),((C=(m=(h=d.parsed)==null?void 0:h.choices)==null?void 0:m[0])==null?void 0:C.delta)&&e.jsxs("span",{className:"text-xs text-gray-400",children:["•"," ",Object.keys(d.parsed.choices[0].delta).filter(N=>d.parsed.choices[0].delta[N]).join(", ")]})]})]}),children:f(d)},d.key)})})})]})},_t=({debugData:t,activeDebugTab:s,onActiveDebugTabChange:n,styleState:r,onCloseDebugPanel:l,customRequestMode:i})=>{const{t:a}=M(),[y,j]=x.useState(s);x.useEffect(()=>{j(s)},[s]);const u=f=>{j(f),n(f)},g=(f,d,o,c)=>{const h={width:32,height:32,margin:"0 12px",display:"flex",justifyContent:"center",alignItems:"center",borderRadius:"100%",background:"rgba(var(--semi-grey-1), 1)",color:"var(--semi-color-text)",cursor:"pointer"};return e.jsx(Ce,{render:e.jsx(Ce.Menu,{children:f.map(m=>e.jsx(Ce.Item,{onClick:()=>u(m.itemKey),children:m.tab},m.itemKey))}),children:d==="start"?e.jsx("div",{style:h,onClick:o,children:"←"}):e.jsx("div",{style:h,onClick:o,children:"→"})})};return e.jsxs(Me,{className:"h-full flex flex-col",bordered:!1,bodyStyle:{padding:r.isMobile?"16px":"24px",height:"100%",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-r from-green-500 to-blue-500 flex items-center justify-center mr-3",children:e.jsx(xs,{size:20,className:"text-white"})}),e.jsx(E.Title,{heading:5,className:"mb-0",children:a("调试信息")})]}),r.isMobile&&l&&e.jsx(k,{icon:e.jsx(U,{size:16}),onClick:l,theme:"borderless",type:"tertiary",size:"small",className:"!rounded-lg"})]}),e.jsx("div",{className:"flex-1 overflow-hidden debug-panel",children:e.jsxs(Rs,{renderArrow:g,type:"card",collapsible:!0,className:"h-full",style:{height:"100%",display:"flex",flexDirection:"column"},activeKey:y,onChange:u,children:[e.jsx(ke,{tab:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{size:16}),a("预览请求体"),i&&e.jsx("span",{className:"px-1.5 py-0.5 text-xs bg-orange-100 text-orange-600 rounded-full",children:"自定义"})]}),itemKey:"preview",children:e.jsx(Ie,{content:t.previewRequest,title:"preview",language:"json"})}),e.jsx(ke,{tab:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(lt,{size:16}),a("实际请求体")]}),itemKey:"request",children:e.jsx(Ie,{content:t.request,title:"request",language:"json"})}),e.jsx(ke,{tab:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gs,{size:16}),a("响应"),t.sseMessages&&t.sseMessages.length>0&&e.jsxs("span",{className:"px-1.5 py-0.5 text-xs bg-blue-100 text-blue-600 rounded-full",children:["SSE (",t.sseMessages.length,")"]})]}),itemKey:"response",children:t.sseMessages&&t.sseMessages.length>0?e.jsx(zt,{sseData:t.sseMessages,title:"response"}):e.jsx(Ie,{content:t.response,title:"response",language:"json"})})]})}),e.jsx("div",{className:"flex items-center justify-between mt-4 pt-4 flex-shrink-0",children:(t.timestamp||t.previewTimestamp)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ot,{size:14,className:"text-gray-500"}),e.jsx(E.Text,{className:"text-xs text-gray-500",children:y==="preview"&&t.previewTimestamp?`${a("预览更新")}
34: ${new Date(t.previewTimestamp).toLocaleString()}`:t.timestamp?`${a("最后请求")}: ${new Date(t.timestamp).toLocaleString()}`:""})]})})]})},At=V.memo(vt,(t,s)=>t.message.id===s.message.id&&t.message.content===s.message.content&&t.message.status===s.message.status&&t.message.role===s.message.role&&t.message.reasoningContent===s.message.reasoningContent&&t.message.isReasoningExpanded===s.message.isReasoningExpanded&&t.isEditing===s.isEditing&&t.editValue===s.editValue&&t.styleState.isMobile===s.styleState.isMobile),Mt=V.memo(Tt,(t,s)=>t.message.id===s.message.id&&t.message.role===s.message.role&&t.isAnyMessageGenerating===s.isAnyMessageGenerating&&t.isEditing===s.isEditing&&t.onMessageReset===s.onMessageReset),Dt=V.memo(It,(t,s)=>JSON.stringify(t.inputs)===JSON.stringify(s.inputs)&&JSON.stringify(t.parameterEnabled)===JSON.stringify(s.parameterEnabled)&&JSON.stringify(t.models)===JSON.stringify(s.models)&&JSON.stringify(t.groups)===JSON.stringify(s.groups)&&t.customRequestMode===s.customRequestMode&&t.customRequestBody===s.customRequestBody&&t.showDebugPanel===s.showDebugPanel&&t.showSettings===s.showSettings&&JSON.stringify(t.previewPayload)===JSON.stringify(s.previewPayload)&&JSON.stringify(t.messages)===JSON.stringify(s.messages)),as=V.memo(_t,(t,s)=>t.show===s.show&&t.activeTab===s.activeTab&&JSON.stringify(t.debugData)===JSON.stringify(s.debugData)&&JSON.stringify(t.previewPayload)===JSON.stringify(s.previewPayload)&&t.customRequestMode===s.customRequestMode&&t.showDebugPanel===s.showDebugPanel),ys=x.createContext(null),Ft=()=>{const t=x.useContext(ys);return t||{onPasteImage:()=>{console.warn("PlaygroundContext not provided")},imageUrls:[],imageEnabled:!1}},Lt=({children:t,value:s})=>e.jsx(ys.Provider,{value:s,children:t}),Pt=t=>{const{t:s}=M(),{onPasteImage:n,imageEnabled:r}=Ft(),{detailProps:l}=t,{clearContextNode:i,inputNode:a,sendNode:y,onClick:j}=l||{},u=x.useRef(null),g=x.useCallback(async o=>{var h;const c=(h=o.clipboardData)==null?void 0:h.items;if(c)for(let m=0;m<c.length;m++){const C=c[m];if(C.type.indexOf("image")!==-1){o.preventDefault();const N=C.getAsFile();if(N)try{if(!r){z.warning({content:s("请先在设置中启用图片功能"),duration:3});return}const p=new FileReader;p.onload=w=>{const b=w.target.result;n?(n(b),z.success({content:s("图片已添加"),duration:2})):z.error({content:s("无法添加图片"),duration:2})},p.onerror=()=>{console.error("Failed to read image file:",p.error),z.error({content:s("粘贴图片失败"),duration:2})},p.readAsDataURL(N)}catch(p){console.error("Failed to paste image:",p),z.error({content:s("粘贴图片失败"),duration:2})}break}}},[n,r,s]);x.useEffect(()=>{const o=u.current;if(o)return o.addEventListener("paste",g),()=>{o.removeEventListener("paste",g)}},[g]);const f=V.isValidElement(i)?V.cloneElement(i,{className:`!rounded-full !bg-gray-100 hover:!bg-red-500 hover:!text-white flex-shrink-0 transition-all ${i.props.className||""}`,style:{...i.props.style,width:"32px",height:"32px",minWidth:"32px",padding:0,display:"flex",alignItems:"center",justifyContent:"center"}}):i||null,d=V.isValidElement(y)?V.cloneElement(y,{className:`!rounded-full !bg-purple-500 hover:!bg-purple-600 flex-shrink-0 transition-all ${y.props.className||""}`,style:{...y.props.style,width:"32px",height:"32px",minWidth:"32px",padding:0,display:"flex",alignItems:"center",justifyContent:"center"}}):y||null;return e.jsx("div",{className:"p-2 sm:p-4",ref:u,children:e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 p-2 bg-gray-50 rounded-xl sm:rounded-2xl shadow-sm hover:shadow-md transition-shadow",style:{border:"1px solid var(--semi-color-border)"},onClick:j,title:s("支持 Ctrl+V 粘贴图片"),children:[f,e.jsx("div",{className:"flex-1",children:a||null}),d]})})},$t=({chatRef:t,message:s,inputs:n,styleState:r,showDebugPanel:l,roleInfo:i,onMessageSend:a,onMessageCopy:y,onMessageReset:j,onMessageDelete:u,onStopGenerator:g,onClearMessages:f,onToggleDebugPanel:d,renderCustomChatContent:o,renderChatBoxAction:c})=>{const{t:h}=M(),m=V.useCallback(C=>e.jsx(Pt,{...C}),[]);return e.jsxs(Me,{className:"h-full",bordered:!1,bodyStyle:{padding:0,height:"calc(100vh - 66px)",display:"flex",flexDirection:"column",overflow:"hidden"},children:[r.isMobile?e.jsx("div",{className:"pt-4"}):e.jsx("div",{className:"px-6 py-4 bg-gradient-to-r from-purple-500 to-blue-500 rounded-t-2xl",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/20 backdrop-blur flex items-center justify-center",children:e.jsx(ct,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx(E.Title,{heading:5,className:"!text-white mb-0",children:h("AI 对
34话")}),e.jsx(E.Text,{className:"!text-white/80 text-sm hidden sm:inline",children:n.model||h("选择模型开始对话")})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(k,{icon:l?e.jsx(fs,{size:14}):e.jsx(Fe,{size:14}),onClick:d,theme:"borderless",type:"primary",size:"small",className:"!rounded-lg !text-white/80 hover:!text-white hover:!bg-white/10",children:h(l?"隐藏调试":"显示调试")})})]})}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx(Os,{ref:t,chatBoxRenderConfig:{renderChatBoxContent:o,renderChatBoxAction:c,renderChatBoxTitle:()=>null},renderInputArea:m,roleConfig:i,style:{height:"100%",maxWidth:"100%",overflow:"hidden"},chats:s,onMessageSend:a,onMessageCopy:y,onMessageReset:j,onMessageDelete:u,showClearContext:!0,showStopGenerate:!0,onStopGenerator:g,onClear:f,className:"h-full",placeholder:h("请输入您的问题...")})})]})},Jt=({styleState:t,showSettings:s,showDebugPanel:n,onToggleSettings:r,onToggleDebugPanel:l})=>t.isMobile?e.jsxs(e.Fragment,{children:[!s&&e.jsx(k,{icon:e.jsx(De,{size:18}),style:{position:"fixed",right:16,bottom:90,zIndex:1e3,width:36,height:36,borderRadius:"50%",padding:0,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.2)",background:"linear-gradient(to right, #8b5cf6, #6366f1)"},onClick:r,theme:"solid",type:"primary",className:"lg:hidden"}),!s&&e.jsx(k,{icon:n?e.jsx(fs,{size:18}):e.jsx(Fe,{size:18}),onClick:l,theme:"solid",type:n?"danger":"primary",style:{position:"fixed",right:16,bottom:140,zIndex:1e3,width:36,height:36,borderRadius:"50%",padding:0,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.2)",background:n?"linear-gradient(to right, #e11d48, #be123c)":"linear-gradient(to right, #4f46e5, #6366f1)"},className:"lg:hidden"})]}):null,Ut=t=>{if(!t)return"https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png";const s=t[0].toUpperCase(),r=`
35    <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
36      <circle cx="16" cy="16" r="16" fill="${Ps(t)}" />
37      <text x="50%" y="50%" dominant-baseline="central" text-anchor="middle" font-size="16" fill="#ffffff" font-family="sans-serif">${s}</text>
38    </svg>
39  `;return`data:image/svg+xml;base64,${$s(r)}`},an=()=>{var Ue,Be;const{t}=M(),[s]=x.useContext(Fs),n=Ls(),r={isMobile:n},[l]=Is(),i=jt(),{inputs:a,parameterEnabled:y,showDebugPanel:j,customRequestMode:u,customRequestBody:g,showSettings:f,models:d,groups:o,message:c,debugData:h,activeDebugTab:m,previewPayload:C,sseSourceRef:N,chatRef:p,handleInputChange:w,handleParameterToggle:b,debouncedSaveConfig:S,saveMessagesImmediately:v,handleConfigImport:_,handleConfigReset:L,setShowSettings:P,setModels:ne,setGroups:Ee,setMessage:$,setDebugData:re,setActiveDebugTab:ae,setPreviewPayload:me,setShowDebugPanel:ie,setCustomRequestMode:ve,setCustomRequestBody:H}=i,{sendRequest:le,onStopGenerator:Te}=bt($,re,ae,N,v);St(s,a,w,ne,Ee);const{editingMessageId:Y,editValue:xe,setEditValue:ge,handleMessageEdit:fe,handleEditSave:T,handleEditCancel:A}=wt($,a,y,le,v),{syncMessageToCustomBody:W,syncCustomBodyToMessage:oe}=Ct(u,g,c,a,H,$,S),js={user:{name:((Ue=s==null?void 0:s.user)==null?void 0:Ue.username)||"User",avatar:Ut((Be=s==null?void 0:s.user)==null?void 0:Be.username)},assistant:{name:"Assistant",avatar:Ze()},system:{name:"System",avatar:Ze()}},K=Nt(c,$,$e,v),Pe=x.useCallback(()=>{try{if(u&&g&&g.trim())try{return JSON.parse(g)}catch(R){console.warn("自定义请求体JSON解析失败,回退到默认预览:",R)}let O=[...c];if(!(O.length===0||O.every(R=>R.role!==G.USER))){for(let R=O.length-1;R>=0;R--)if(O[R].role===G.USER){if(a.imageEnabled&&a.imageUrls){const D=a.imageUrls.filter(X=>X.trim()!=="");if(D.length>0){const X=he(O[R])||"示例消息",te=Qe(X,D,!0);O[R]={...O[R],content:te}}}break}}return ze(O,null,a,y)}catch(O){return console.error("构造预览请求体失败:",O),null}},[a,y,c,u,g]);function $e(O,R){console.log("attachment: ",R);const D=Ye(G.USER,O),X=cs();if(u&&g)try{const Z=JSON.parse(g);$(pe=>{const ye=[...pe,D,X];return le(Z,Z.stream!==!1),setTimeout(()=>v(ye),0),ye});return}catch(Z){console.error("自定义请求体JSON解析失败:",Z),z.error(de.JSON_PARSE_ERROR);return}const te=a.imageUrls.filter(Z=>Z.trim()!==""),Ss=Qe(O,te,a.imageEnabled),Es=Ye(G.USER,Ss);$(Z=>{const pe=[...Z,Es],ye=ze(pe,null,a,y);le(ye,a.stream),a.imageEnabled&&setTimeout(()=>{w("imageEnabled",!1)},100);const Ge=[...pe,X];return setTimeout(()=>v(Ge),0),Ge})}const Je=x.useCallback(O=>{$(R=>R.map(D=>D.id===O&&D.role===G.ASSISTANT?{...D,isReasoningExpanded:!D.isReasoningExpanded}:D))},[$]),Ns=x.useCallback(({message:O,className:R})=>{if(!O)return null;const D=Y===O.id;return e.jsx(At,{message:O,className:R,styleState:r,onToggleReasoningExpansion:Je,isEditing:D,onEditSave:T,onEditCancel:A,editValue:xe,onEditValueChange:ge})},[r,Y,xe,T,A,ge,Je]),bs=x.useCallback(O=>{const{message:R}=O;if(!R)return O.defaultActions||null;const D=c.some(te=>te.status==="loading"||te.status==="incomplete"),X=Y===R.id;return e.jsx(Mt,{message:R,styleState:r,onMessageReset:K.handleMessageReset,onMessageCopy:K.handleMessageCopy,onMessageDelete:K.handleMessageDelete,onRoleToggle:K.handleRoleToggle,onMessageEdit:fe,isAnyMessageGenerating:D,isEditing:X})},[K,r,c,Y,fe]);x.useEffect(()=>{W()},[c,W]),x.useEffect(()=>{oe()},[g,oe]),x.useEffect(()=>{l.get("expired")&&z.warning(t("登录过期,请重新登录!"))},[l,t]),x.useEffect(()=>{const O=setTimeout(()=>{const R=Pe();me(R),re(D=>({...D,previewRequest:R?JSON.stringify(R,null,2):null,previewTimestamp:R?new Date().toISOString():null}))},300);return()=>clearTimeout(O)},[c,a,y,u,g,Pe,me,re]),x.useEffect(()=>{S()},[a,y,j,u,g,S]);const Cs=x.useCallback(()=>{$([]),setTimeout(()=>v([]),0)},[$,v]),ws={onPasteImage:x.useCallback(O=>{if(!a.imageEnabled)return;const R=[...a.imageUrls||[],O];w("imageUrls",R)},[a.imageEnabled,a.imageUrls,w]),imageUrls:a.imageUrls||[],imageEnabled:a.imageEnabled||!1};return e.jsx(Lt,{value:ws,children:e.jsx("div",{className:"h-full",children:e.jsxs(Re,{className:"h-full bg-transparent flex flex-col md:flex-row",children:[(f||!n)&&e.jsx(Re.Sider,{className:`
40              bg-transparent border-r-0 flex-shrink-0 overflow-auto
41              ${n?"fixed top-0 left-0 right-0 bottom-0 z-[1000] w-full h-auto bg-white shadow-lg":"relative z-[1] w-80 h-[calc(100vh-66px)]"}
42            `,width:n?"100%":320,children:e.jsx(Dt,{inputs:a,parameterEnabled:y,models:d,groups:o,styleState:r,showSettings:f,showDebugPanel:j,customRequestMode:u,customRequestBody:g,onInputChange:w,onParameterToggle:b,onCloseSettings:()=>P(!1),onConfigImport:_,onConfigReset:L,onCustomRequestModeChange:ve,onCustomRequestBodyChange:H,previewPayload:C,messages:c})}),e.jsxs(Re.Content,{className:"relative flex-1 overflow-hidden",children:[e.jsxs("div",{className:"overflow-hidden flex flex-col lg:flex-row h-[calc(100vh-66px)]",children:[e.jsx("div",{className:"flex-1 flex flex-col",children:e.jsx($t,{chatRef:p,message:c,inputs:a,styleState:r,showDebugPanel:j,roleInfo:js,onMessageSend:$e,onMessageCopy:K.handleMessageCopy,onMessageReset:K.handleMessageReset,onMessageDelete:K.handleMessageDelete,onStopGenerator:Te,onClearMessages:Cs,onToggleDebugPanel:()=>ie(!j),renderCustomChatContent:Ns,renderChatBoxAction:bs})}),j&&!n&&e.jsx("div",{className:"w-96 flex-shrink-0 h-full",children:e.jsx(as,{debugData:h,activeDebugTab:m,onActiveDebugTabChange:ae,styleState:r,customRequestMode:u})})]}),j&&n&&e.jsx("div",{className:"fixed top-0 left-0 right-0 bottom-0 z-[1000] bg-white overflow-auto shadow-lg",children:e.jsx(as,{debugData:h,activeDebugTab:m,onActiveDebugTabChange:ae,styleState:r,showDebugPanel:j,onCloseDebugPanel:()=>ie(!1),customRequestMode:u})}),e.jsx(Jt,{styleState:r,showSettings:f,showDebugPanel:j,onToggleSettings:()=>P(!f),onToggleDebugPanel:()=>ie(!j)})]})]})})})};export{an as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.