You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
82 KiB
JavaScript
34 lines
82 KiB
JavaScript
|
9 months ago
|
exports.id=649,exports.ids=[649],exports.modules={17382:(e,t,s)=>{"use strict";s.d(t,{Z:()=>o});var a,n,r=s(6413);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let o=function(e){return r.createElement("svg",i({xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink",width:16,height:16,fill:"none"},e),a||(a=r.createElement("defs",null,r.createElement("path",{id:"clear_svg__a",d:"M0 0h16v16H0z"}))),r.createElement("g",null,n||(n=r.createElement("mask",{id:"clear_svg__b",fill:"#fff"},r.createElement("use",{xlinkHref:"#clear_svg__a"}))),r.createElement("g",{mask:"url(#clear_svg__b)"},r.createElement("path",{style:{stroke:"#333",strokeWidth:1.3333333333333333,strokeOpacity:1,strokeDasharray:"0 0"},d:"M1 9.67h8.67l1-9.67H0l1 9.67Z",transform:"translate(2.667 5)"}),r.createElement("path",{style:{stroke:"#333",strokeWidth:1.3333333333333333,strokeOpacity:1,strokeDasharray:"0 0"},d:"M0 0v3.33",transform:"translate(6.667 8.334)"}),r.createElement("path",{style:{stroke:"#333",strokeWidth:1.3333333333333333,strokeOpacity:1,strokeDasharray:"0 0"},d:"M0 0v3.33",transform:"translate(9.334 8.333)"}),r.createElement("path",{style:{stroke:"#333",strokeWidth:1.3333333333333333,strokeOpacity:1,strokeDasharray:"0 0"},d:"m0 4 5.44-4L8 4",transform:"translate(4 1)"}))))}},60403:(e,t,s)=>{"use strict";s.d(t,{Z:()=>o});var a,n,r=s(6413);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let o=function(e){return r.createElement("svg",i({xmlns:"http://www.w3.org/2000/svg",width:16,height:16,fill:"#fff"},e),a||(a=r.createElement("rect",{width:"100%",height:"100%",fill:"none"})),n||(n=r.createElement("g",{className:"loading_svg__currentLayer"},r.createElement("circle",{cx:4,cy:8,r:1.926,fill:"#333"},r.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:2,repeatCount:"indefinite",to:2,values:"2;1.2;2"}),r.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"})),r.createElement("circle",{cx:8,cy:8,r:1.274,fill:"#333",fillOpacity:.3},r.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:1.2,repeatCount:"indefinite",to:1.2,values:"1.2;2;1.2"}),r.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:.5,repeatCount:"indefinite",to:.5,values:".5;1;.5"})),r.createElement("circle",{cx:12,cy:8,r:1.926,fill:"#333"},r.createElement("animate",{attributeName:"r",begin:"0s",calcMode:"linear",dur:"0.8s",from:2,repeatCount:"indefinite",to:2,values:"2;1.2;2"}),r.createElement("animate",{attributeName:"fill-opacity",begin:"0s",calcMode:"linear",dur:"0.8s",from:1,repeatCount:"indefinite",to:1,values:"1;.5;1"})))))}},30892:(e,t,s)=>{"use strict";s.d(t,{Z:()=>i});var a,n=s(6413);function r(){return(r=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let i=function(e){return n.createElement("svg",r({xmlns:"http://www.w3.org/2000/svg",width:16,height:16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"},e),a||(a=n.createElement("rect",{x:3,y:3,width:18,height:18,rx:2,ry:2})))}},20733:(e,t,s)=>{"use strict";s.d(t,{Z:()=>o});var a,n,r=s(6413);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let o=function(e){return r.createElement("svg",i({xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/x
|
||
|
|
|
||
|
|
`+e.messages.map(e=>"user"===e.role?`## ${eB.ZP.Export.MessageFromYou}:
|
||
|
|
${(0,eD.YK)(e)}`:`## ${eB.ZP.Export.MessageFromChatGPT}:
|
||
|
|
${(0,eD.YK)(e).trim()}`).join("\n\n");return(0,H.jsxs)(H.Fragment,{children:[H.jsx(to,{copy:()=>{(0,eD.vQ)(t)},download:()=>{(0,eD.CP)(t,`${e.topic}.md`)},showCopy:!0,messages:e.messages}),H.jsx("div",{className:"markdown-body",children:H.jsx("pre",{className:e0()["export-content"],children:t})})]})}function td(e){let t={messages:[{role:"system",content:`${eB.ZP.FineTuned.Sysmessage} ${e.topic}`},...e.messages.map(e=>({role:e.role,content:e.content}))]},s="```json\n"+JSON.stringify(t,null,2)+"\n```",a=JSON.stringify(t),n=()=>{(0,eD.vQ)(a)};return(0,H.jsxs)(H.Fragment,{children:[H.jsx(to,{copy:n,download:()=>{(0,eD.CP)(JSON.stringify(t),`${e.topic}.json`)},showCopy:!1,messages:e.messages}),H.jsx("div",{className:"markdown-body",onClick:n,children:H.jsx(ts,{content:s})})]})}var tm=s(74255),tu=s(14300),tp=s(6113),tg=s(12781);(function(e){e.SILENT="silent",e.X_SOFT="x-soft",e.SOFT="soft",e.MEDIUM="medium",e.LOUD="loud",e.X_LOUD="x-LOUD",e.DEFAULT="default"})(T||(T={})),function(e){e.X_SLOW="x-slow",e.SLOW="slow",e.MEDIUM="medium",e.FAST="fast",e.X_FAST="x-fast",e.DEFAULT="default"}(A||(A={})),function(e){e.X_LOW="x-low",e.LOW="low",e.MEDIUM="medium",e.HIGH="high",e.X_HIGH="x-high",e.DEFAULT="default"}(L||(L={})),function(e){e.AUDIO_24KHZ_48KBITRATE_MONO_MP3="audio-24khz-48kbitrate-mono-mp3",e.AUDIO_24KHZ_96KBITRATE_MONO_MP3="audio-24khz-96kbitrate-mono-mp3",e.WEBM_24KHZ_16BIT_MONO_OPUS="webm-24khz-16bit-mono-opus"}(D||(D={}));class tf{constructor(){this.pitch="+0Hz",this.rate=1,this.volume=100}}class tx{static{this.OUTPUT_FORMAT=D}static{this.TRUSTED_CLIENT_TOKEN="6A5AA1D4EAFF4E9FB37E23D68491D6F4"}static{this.VOICES_URL=`https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=${tx.TRUSTED_CLIENT_TOKEN}`}static{this.SYNTH_URL=`wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=${tx.TRUSTED_CLIENT_TOKEN}`}static{this.BINARY_DELIM="Path:audio\r\n"}static{this.VOICE_LANG_REGEX=/\w{2}-\w{2}/}_log(...e){this._enableLogger&&console.log(...e)}constructor(e=!1){this._streams={},this._startTime=0,this._enableLogger=e}async _send(e){for(let e=1;e<=3&&this._ws.readyState!==this._ws.OPEN;e++)1==e&&(this._startTime=Date.now()),this._log("connecting: ",e),await this._initClient();this._ws.send(e)}_initClient(){return this._ws=new WebSocket(tx.SYNTH_URL),this._ws.binaryType="arraybuffer",new Promise((e,t)=>{this._ws.onopen=()=>{this._log("Connected in",(Date.now()-this._startTime)/1e3,"seconds"),this._send(`Content-Type:application/json; charset=utf-8\r
|
||
|
|
Path:speech.config\r
|
||
|
|
\r
|
||
|
|
|
||
|
|
{
|
||
|
|
"context": {
|
||
|
|
"synthesis": {
|
||
|
|
"audio": {
|
||
|
|
"metadataoptions": {
|
||
|
|
"sentenceBoundaryEnabled": "false",
|
||
|
|
"wordBoundaryEnabled": "false"
|
||
|
|
},
|
||
|
|
"outputFormat": "${this._outputFormat}"
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
`).then(e)},this._ws.onmessage=e=>{let t=tu.Buffer.from(e.data),s=t.toString(),a=/X-RequestId:(.*?)\r\n/gm.exec(s)[1];s.includes("Path:turn.start")||(s.includes("Path:turn.end")?this._streams[a].push(null):s.includes("Path:response")||(s.includes("Path:audio")&&e.data instanceof ArrayBuffer?this._pushAudioData(t,a):this._log("UNKNOWN MESSAGE",s)))},this._ws.onclose=()=>{for(let e in this._log("disconnected after:",(Date.now()-this._startTime)/1e3,"seconds"),this._streams)this._streams[e].push(null)},this._ws.onerror=function(e){t("Connect Error: "+e)}})}_pushAudioData(e,t){let s=e.indexOf(tx.BINARY_DELIM)+tx.BINARY_DELIM.length,a=e.subarray(s);this._streams[t].push(a),this._log("received audio chunk, size: ",a?.length)}_SSMLTemplate(e,t={}){return t={...new tf,...t},`<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${this._voiceLocale}">
|
||
|
|
<voice name="${this._voice}">
|
||
|
|
<prosody pitch="${t.pitch}" rate="${t.rate}" volume="${t.volume}">
|
||
|
|
${e}
|
||
|
|
</prosody>
|
||
|
|
</voice>
|
||
|
|
</speak>`}getVoices(){return fetch(tx.VOICES_URL).then(e=>{if(!e.ok)throw Error("Network response was not ok");return e.json()}).then(e=>e).catch(e=>{throw e})}async setMetadata(e,t,s){let a=this._voice,n=this._voiceLocale,r=this._outputFormat;if(this._voice=e,this._voiceLocale=s,!this._voiceLocale){let e=tx.VOICE_LANG_REGEX.exec(this._voice);if(!e)throw Error("Could not infer voiceLocale from voiceName!");this._voiceLocale=e[0]}this._outputFormat=t,(a!==this._voice||n!==this._voiceLocale||r!==this._outputFormat||this._ws.readyState!==this._ws.OPEN)&&(this._startTime=Date.now(),await this._initClient())}_metadataCheck(){if(!this._ws)throw Error("Speech synthesis not configured yet. Run setMetadata before calling toStream or toFile.")}close(){this._ws.close()}toStream(e,t){let{stream:s}=this._rawSSMLRequest(this._SSMLTemplate(e,t));return s}toArrayBuffer(e,t){return new Promise((s,a)=>{let n=[],r=this.toStream(e,t);r.on("data",e=>{n.push(e)}),r.on("end",()=>{s(tu.Buffer.concat(n).buffer)}),r.on("error",e=>{a(e)})})}rawToStream(e){let{stream:t}=this._rawSSMLRequest(e);return t}_rawSSMLRequest(e){this._metadataCheck();let t=(0,tp.randomBytes)(16).toString("hex"),s=`X-RequestId:${t}\r
|
||
|
|
Content-Type:application/ssml+xml\r
|
||
|
|
Path:ssml\r
|
||
|
|
\r
|
||
|
|
|
||
|
|
`+e.trim(),a=this,n=new tg.Readable({read(){},destroy(e,s){delete a._streams[t],s(e)}});return this._streams[t]=n,this._send(s).then(),{stream:n,requestId:t}}}var tv=s(20582),tw=s(6111);function ty(){return(ty=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let t_=function(e){return W.createElement("svg",ty({width:24,height:24,viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),I||(I=W.createElement("rect",{x:17,y:4,width:14,height:27,rx:7,stroke:"#333",strokeWidth:4,strokeLinejoin:"round"})),K||(K=W.createElement("path",{d:"M9 23c0 8.284 6.716 15 15 15 8.284 0 15-6.716 15-15M24 38v6",stroke:"#333",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round"})))};function tk(){return(tk=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let tj=function(e){return W.createElement("svg",tk({width:24,height:24,viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),R||(R=W.createElement("path",{d:"M31 24V11a7 7 0 1 0-14 0v13a7 7 0 1 0 14 0Z",stroke:"#d0021b",strokeWidth:4,strokeLinejoin:"round"})),F||(F=W.createElement("path",{d:"M9 23c0 8.284 6.716 15 15 15 1.753 0 3.436-.3 5-.853M39 23a14.95 14.95 0 0 1-1.248 6M24 38v6M42 42 6 6",stroke:"#d0021b",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round"})))};function tC(){return(tC=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var a in s)Object.prototype.hasOwnProperty.call(s,a)&&(e[a]=s[a])}return e}).apply(this,arguments)}let tb=function(e){return W.createElement("svg",tC({width:24,height:24,viewBox:"0 0 48 48",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e),B||(B=W.createElement("path",{d:"M14.5 8a19.05 19.05 0 0 0-4.75 3.84C6.794 15.146 5 19.49 5 24.245 5 34.603 13.507 43 24 43s19-8.397 19-18.755c0-4.756-1.794-9.099-4.75-12.405A19.02 19.02 0 0 0 33.5 8M24 4v20",stroke:"#333",strokeWidth:4,strokeLinecap:"round",strokeLinejoin:"round"})))};var tE=s(45136),tS=s.n(tE),tN=s(37824);class tM{constructor(){this.workletNode=null,this.stream=null,this.source=null,this.recordBuffer=[],this.sampleRate=24e3,this.nextPlayTime=0,this.isPlaying=!1,this.playbackQueue=[],this.playBuffer=[],this.context=new AudioContext({sampleRate:this.sampleRate}),this.mergeNode=new ChannelMergerNode(this.context,{numberOfInputs:2}),this.analyser=new AnalyserNode(this.context,{fftSize:256}),this.analyserData=new Uint8Array(this.analyser.frequencyBinCount),this.mergeNode.connect(this.analyser)}getByteFrequencyData(){return this.analyser.getByteFrequencyData(this.analyserData),this.analyserData}async initialize(){await this.context.audioWorklet.addModule("/audio-processor.js")}async startRecording(e){try{this.workletNode||await this.initialize(),this.stream=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,sampleRate:this.sampleRate,echoCancellation:!0,noiseSuppression:!0}}),await this.context.resume(),this.source=this.context.createMediaStreamSource(this.stream),this.workletNode=new AudioWorkletNode(this.context,"audio-recorder-processor"),this.workletNode.port.onmessage=t=>{if("audio"===t.data.eventType){let s=t.data.audioData,a=new Int16Array(s.length);for(let e=0;e<s.length;e++){let t=Math.max(-1,Math.min(1,s[e]));a[e]=t<0?32768*t:32767*t}let n=new Uint8Array(a.buffer);e(n),this.recordBuffer.push.apply(this.recordBuffer,a)}},this.source.connect(this.workletNode),this.source.connect(this.mergeNode,0,0),this.workletNode.connect(this.context.destination),this.workletNode.port.postMessage({command:"START_RECORDING"})}catch(e){throw console.error("Error starting recording:",e),e}}stopRecording(){if(!this.workletNode||!this.source||!this.stream)throw Error("Recording not started");this.workletNode.port.postMessage({command:"STOP_RECORDING"}),this.workletNode.disconnect(),this
|
||
|
|
${JSON.stringify(t,null,4)}`).then(e=>{e&&(t.key&&X.update(e=>e.openaiApiKey=t.key),t.url&&X.update(e=>e.openaiUrl=t.url),X.update(e=>e.useCustomConfig=!0))})}catch{console.error("[Command] failed to get settings from url: ",e)}}});let[eP,eO]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=(0,e$.AI)(t.id),s=tA.getItem(e);s&&0===c.length&&(h(s),tA.removeItem(e));let a=l.current;return()=>{tA.setItem(e,a?.value??"")}},[]);let eZ=(0,U.useCallback)(async t=>{let s=e.currentSession().mask.modelConfig.model;if((0,eD.Xf)(s)){for(let e of(t.clipboardData||window.clipboardData).items)if("file"===e.kind&&e.type.startsWith("image/")){t.preventDefault();let s=e.getAsFile();if(s){let e=[];e.push(...b),e.push(...await new Promise((e,t)=>{N(!0);let a=[];(0,eI.Ix)(s).then(t=>{a.push(t),N(!1),e(a)}).catch(e=>{N(!1),t(e)})}));let t=e.length;t>3&&e.splice(3,t-3),E(e)}}}},[b,e]);async function eT(){let e=[];e.push(...b),e.push(...await new Promise((e,t)=>{let s=document.createElement("input");s.type="file",s.accept="image/png, image/jpeg, image/webp, image/heic, image/heif",s.multiple=!0,s.onchange=s=>{N(!0);let a=s.target.files,n=[];for(let r=0;r<a.length;r++){let i=s.target.files[r];(0,eI.Ix)(i).then(t=>{n.push(t),(3===n.length||n.length===a.length)&&(N(!1),e(n))}).catch(e=>{N(!1),t(e)})}},s.click()}));let t=e.length;t>3&&e.splice(3,t-3),E(e)}let[eA,eK]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let s=s=>{if((s.metaKey||s.ctrlKey)&&s.shiftKey&&"o"===s.key.toLowerCase())s.preventDefault(),setTimeout(()=>{e.newSession(),C(e$.y$.Chat)},10);else if(s.shiftKey&&"escape"===s.key.toLowerCase())s.preventDefault(),l.current?.focus();else if((s.metaKey||s.ctrlKey)&&s.shiftKey&&"Semicolon"===s.code){s.preventDefault();let e=document.querySelectorAll(".copy-code-button");e.length>0&&e[e.length-1].click()}else if((s.metaKey||s.ctrlKey)&&s.shiftKey&&"c"===s.key.toLowerCase()){s.preventDefault();let e=ey.filter(e=>"user"!==e.role).pop();if(e){let t=(0,eD.YK)(e);(0,eD.vQ)(t)}}else(s.metaKey||s.ctrlKey)&&"/"===s.key?(s.preventDefault(),eK(!0)):(s.metaKey||s.ctrlKey)&&s.shiftKey&&"backspace"===s.key.toLowerCase()&&(s.preventDefault(),e.updateTargetSession(t,e=>{e.clearContextIndex===e.messages.length?e.clearContextIndex=void 0:(e.clearContextIndex=e.messages.length,e.memoryPrompt="")}))};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s)}},[ey,e,C,t]);let[ez,eq]=(0,U.useState)(!1);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:eU().chat,children:[(0,H.jsxs)("div",{className:"window-header","data-tauri-drag-region":!0,children:[j&&H.jsx("div",{className:"window-actions",children:H.jsx("div",{className:"window-action-button",children:H.jsx(eH.h,{icon:H.jsx(J.Z,{}),bordered:!0,title:eB.ZP.Chat.Actions.ChatList,onClick:()=>C(e$.y$.Home)})})}),(0,H.jsxs)("div",{className:(0,e8.Z)("window-header-title",eU()["chat-body-title"]),children:[H.jsx("div",{className:(0,e8.Z)("window-header-main-title",eU()["chat-body-main-title"]),onClickCapture:()=>eO(!0),children:t.topic?t.topic:eL.HX}),H.jsx("div",{className:"window-header-sub-title",children:eB.ZP.Chat.SubTitle(t.messages.length)})]}),(0,H.jsxs)("div",{className:"window-actions",children:[H.jsx("div",{className:"window-action-button",children:H.jsx(eH.h,{icon:H.jsx(ec.Z,{}),bordered:!0,title:eB.ZP.Chat.Actions.RefreshTitle,onClick:()=>{(0,eW.CF)(eB.ZP.Chat.Actions.RefreshToast),e.summarizeSession(!0,t)}})}),!j&&H.jsx("div",{className:"window-action-button",children:H.jsx(eH.h,{icon:H.jsx(Y,{}),bordered:!0,title:eB.ZP.Chat.EditMessage.Title,aria:eB.ZP.Chat.EditMessage.Title,onClick:()=>eO(!0)})}),H.jsx("div",{className:"window-action-button",children:H.jsx(eH.h,{icon:H.jsx(Q.Z,{}),bordered:!0,title:eB.ZP.Chat.Actions.Export,onClick:()=>{o(!0)}})}),eM&&H.jsx("div",{className:"window-action-button",children:H.jsx(eH.h,{icon:a.tightBorder?H.jsx(el.Z,{}):H.jsx(eo.Z,{}),bordered:!0,title:eB.ZP.Chat.Actions.FullScreen,aria:eB.ZP.Chat.Actions.FullScreen,onClick:()=>{a.update(e=>e.tightBorder=!e.tightBorder)}})})]}),H.jsx(tK,{showToast:!_,showModal:eb,setShowModal:eE
|