fmode-ng 0.0.24 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * @copyright © 未来飞马 © 未来全栈 www.fmode.cn
4
+ * 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
5
+ * 保留所有权利 All Rights Reserved.
6
+ * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2020/lib/aigc/agent/agent.prompt.mjs
7
+ */
8
+ import{PromptTemplate}from"@langchain/core/prompts";import Parse from"parse";import{finalize}from"rxjs";import{FmodeChatCompletion}from"../service-fmai/service-chat/chat-class";export class AgentPrompt{constructor(){}jsonCompletion(e,t){let r,o=new FmodeChatCompletion([{role:"user",content:e}]);return o.model=t||"fmode-3.6-16k",o.sendCompletion({isDirect:!0}).pipe(finalize((()=>{let e;console.log(r),r.json=this.extractAndParseJson(e),r.complete=!0})))}extractAndParseJson(e){let t=e.indexOf("{");if(-1===t)return{};let r=0,o=t;for(let l=t;l<e.length;l++)if("{"===e[l]?r++:"}"===e[l]&&r--,0===r){o=l;break}if(0!==r)return{};const l=e.slice(t,o+1);try{return JSON.parse(l)}catch(e){return console.error("Failed to parse JSON:",e),{}}}extractMarkdownToMultiArray(e){let t=e.split("\n"),r=[],o=r,l=[r];for(let e of t){if(!e.trim())continue;if(e.startsWith("#")){let t=e.replace(/^#+\s*/,"");o.push([t]);continue}let t=e.search(/\S/)/2,r=e.trim().replace(/^-+\s*/,"");for(;t<l.length-1;)l.pop();for(;t>l.length-1;){let e=[];l[l.length-1].push(e),l.push(e)}o=l[l.length-1],o.push(r)}return r}async getFormatTpl(e,t){let r=await this.getPromptTpl(e);return await r.format(t)}async getPromptTpl(e){let t=new Parse.Query("PromptTemplate");t.equalTo("code",e);let r=await t.first();return PromptTemplate.fromTemplate(r?.get("template"),{templateFormat:"mustache"})}getTokens(e){return e=e||"",2*e?.length}}
9
+ var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIwL2xpYi9haWdjL2FnZW50L2FnZW50LnByb21wdC5tanM=`
10
+
@@ -0,0 +1,10 @@
1
+
2
+ /**
3
+ * @copyright © 未来飞马 © 未来全栈 www.fmode.cn
4
+ * 版权所有 © 未来飞马 © 江西脑控科技有限公司 Copyright © Fmode Technology Co., Ltd.
5
+ * 保留所有权利 All Rights Reserved.
6
+ * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2020/lib/aigc/agent/index.mjs
7
+ */
8
+ export*from"./agent.prompt";
9
+ var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIwL2xpYi9haWdjL2FnZW50L2luZGV4Lm1qcw==`
10
+
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2020/lib/aigc/index.mjs
7
7
  */
8
- export*from"./service-fmai/fmai.service";export*from"./service-fmai/service-imagine";export*from"./service-fmai/service-chat";export*from"./comp-markdown-preview/plugins/md-mathjax/index";export*from"./comp-markdown-preview/markdown-parse";export*from"./comp-markdown-preview/markdown-preview.module";export*from"./comp-markdown-preview/markdown-preview.component";export*from"./comp-markdown-preview/clipboard.service";export*from"./voice";export*from"./avatar";
8
+ export*from"./service-fmai/fmai.service";export*from"./service-fmai/service-imagine";export*from"./service-fmai/service-chat";export*from"./comp-markdown-preview/plugins/md-mathjax/index";export*from"./comp-markdown-preview/markdown-parse";export*from"./comp-markdown-preview/markdown-preview.module";export*from"./comp-markdown-preview/markdown-preview.component";export*from"./comp-markdown-preview/clipboard.service";export*from"./voice";export*from"./avatar";export*from"./agent";
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIwL2xpYi9haWdjL2luZGV4Lm1qcw==`
10
10
 
@@ -5,6 +5,6 @@
5
5
  * 保留所有权利 All Rights Reserved.
6
6
  * /home/ryan/workspace/nova/nova-admin/dist/fmode-ng/esm2020/lib/aigc/service-fmai/service-chat/chat-class.mjs
7
7
  */
8
- import{bufferTime,concatMap,Observable,delay,finalize}from"rxjs";import Parse from"parse";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt";export function getMessageContentText(e){let t="";return"string"==typeof e&&(t=e),"object"==typeof e&&(t=e?.find((e=>e?.text))?.text||""),t}export function getMessageImageUrl(e){return"object"==typeof e?e?.find((e=>e?.image_url))?.image_url?.url||"":null}export class FmodeChat{constructor(e,t,s,i){this.ChatSession=Parse.Object.extend("ChatSession"),this.messageList=[{role:"system",content:"系统提示:AI仅供参考"}],this.latestAIResponse="",this.userInput="",this.userImage="",this.isTalkMode=!1,this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.playAnimation=e=>{console.log(e)},this.chatServ=i,this.role=t,this.sessionId=e,s?.id&&(this.chatSession=s,this.messageList=this.chatSession.get("messageList"),this.sessionId=s?.id)}loadTalkSystemPrompt(e){if(!this.isTalkMode)return;if(!e)return;"男"==e?.get("gender")?this.SSMLRoleVoice="zh-CN-YunyeNeural":this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.SSMLRoleVoice=e?.get("voiceConfig")?.voice||this.SSMLRoleVoice;let t=`您的语言简短且口语化,每句话都要用mstts:express-as标签,style属性情绪表达(advertisement_upbeat,affectionate,angry,assistant,calm,chat,cheerful,customerservice,depressed,disgruntled,documentary-narration,embarrassed,empathetic,envious,excited,fearful,friendly,gentle,hopeful,lyrical,narration-professional,narration-relaxed,newscast,newscast-casual,newscast-formal,poetry-reading,sad,serious,shouting,sports_commentary,sports_commentary_excited,whispering,terrified,unfriendly,),styledegree属性语气强度(默认1,从0.01最轻柔到2最强调),并适当用break增加自然停顿效果。并编写成带<speak xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="http://www.w3.org/2001/mstts" xmlns:emo="http://www.w3.org/2009/10/emotionml" version="1.0" xml:lang="zh-CN"><voice name="${this.SSMLRoleVoice}">标签的SSML返回。`,s=e.get("prompt")||"请你扮演脑控科技的人工智能专家。";s+=t;let i={role:"user",content:s,hidden:!0},n=this.messageList?.map((e=>e?.content)).join();if(n.indexOf(s)>-1)return;let o=this.messageList?.findIndex((e=>"system"==e?.role)),r=o+1;this.messageList.splice(r,0,i)}loadRolePrompt(){let e=this.role?.get("prompt"),t={role:"user",content:e,hidden:!0};if(!e)return;let s=this.messageList?.map((e=>e?.content)).join();if(s.indexOf(e)>-1)return;let i=this.messageList?.findIndex((e=>"system"==e?.role)),n=i+1;this.messageList.splice(n,0,t)}sendMessage(e="FmodeAiTest测试问题",t,s){this.loadTalkSystemPrompt(this.role),this.loadRolePrompt(),t?this.messageList.push({role:"user",content:[{type:"image_url",image_url:{url:t}},{type:"text",text:e}],complete:!0,createdAt:new Date}):this.messageList.push({role:"user",content:e,complete:!0,createdAt:new Date});let i=new FmodeChatCompletion(this.fixMessageList(this.messageList),{model:this.chatServ?.currentModel?.get("code")||"fmode-3.6-16k"}),n=!1;this.isTalkMode&&(n=!0);let o=i.sendCompletion({isDirect:n,onComplete:s||null}).pipe(finalize((()=>{this.messageList[i.indexOfList].complete=!0}))).subscribe((e=>{this.messageList[i.indexOfList]=e,this.latestAIResponse="string"==typeof e?.content?e?.content:e?.content?.[0]?.text||"";let t=this.chatSession?.get("messageList")?.length;this.messageList?.length>t&&this.saveChatSession(),e?.complete&&(this.saveChatSession(),o.unsubscribe())}))}async saveChatSession(){if("new"==this.sessionId&&(this.chatSession=new this.ChatSession),this.chatSession.set("title",this.genTitle()),this.chatSession.set("role",this.role?.toPointer()),this.chatSession.set("messageList",this.messageList),this.chatSession.set("user",Parse.User.current()?.toPointer()),this.chatSession=await this.chatSession.save(),this.sessionId=this.chatSession?.id,this.sessionId){let e=`${window.location.origin}/chat/pro/chat/${this.sessionId}`;e=this.getInviteUrl(e),window.history.replaceState(null,null,e);let t={sid:this.chatSession?.id,rid:this.role?.id,name:this.role?.get("name"),message:this.chatSession?.get("messageList")?.[this.chatSession?.get("messageList")?.length-1]?.content?.slice(0,20),latest:this.chatSession?.createdAt};this.chatServ?.chatList?.length||(this.chatServ.chatList=[]);let s=this.chatServ?.chatList?.find((e=>e?.sid==t?.sid));s>-1?this.chatServ.chatList[s]=t:this.chatServ?.chatList.unshift(t)}}getInviteUrl(e){let t="?";t=e?.indexOf("?")>-1?"&":"?";let s=Parse.User?.current()?.id;if(-1==e?.indexOf("invite="+s)){if(!s)return e;e+=t+"invite="+s}return e}genTitle(){if(this.title)return this.title;let e=this.messageList.find((e=>"user"==e.role))?.content;return"string"==typeof e&&(this.title=e?.slice(0,15)||""),"object"==typeof e&&(this.title=e?.find((e=>e?.text))?.text||""),this.title}fixMessageList(e){return e.map((e=>({role:e.role,content:e.content})))}nowStr(){let e=new Date;return`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()} ${e.getHours()}:${e.getMinutes()}:${e.getSeconds()}`}}export class FmodeChatCompletion{constructor(e,t){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(e.length),this.messages=e,this.model=t?.model||"fmode-3.6-16k"}sendCompletion(e={}){e.intTime=e?.intTime||50,e.isDirect=e?.isDirect||!1,e?.isDirect&&(e.intTime=1);let t={messages:this.messages,stream:!0,model:this.model,temperature:.5,presence_penalty:0,frequency_penalty:0};return new Observable((s=>{let i=RequestFmodeChatApi("/v1/chat/completions",t).subscribe((t=>{let n=String(t);if("data: [DONE]"==n&&(this.isCompleted=!0,e?.isDirect&&this.isCompleted&&(s.next({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),e?.onComplete&&e.onComplete({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),s.complete())),n.indexOf("data: {")>-1){let t=chunkToJson(n),o=t?.choices?.[0]?.delta?.content||"";this.contentBuffer.push(o),e?.isDirect&&(this.content+=o||"",this.isCompleted||s.next({role:"assistant",cid:t?.id,content:this.content,createdAt:new Date})),e?.isDirect||this.contentPusher||(this.contentPusher=setInterval((()=>{this.isCompleted&&0==this.contentBuffer?.length&&(s.next({role:"assistant",cid:t?.id,content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),clearInterval(this.contentPusher),s.complete()),this.contentBuffer?.length>=0&&(this.contentBuffer?.length>0&&(this.content+=this.contentBuffer.shift()),s.next({role:"assistant",cid:t?.id,content:this.content,createdAt:new Date}))}),e?.intTime))}}))})).pipe(bufferTime(100),concatMap((e=>e)),delay(200))}}function chunkToJson(e){let t;try{t=JSON.parse(e.replaceAll("data: ",""))}catch(e){console.error(e)}return t||{}}function RequestFmodeChatApi(e,t,s="POST"){return new Observable((i=>{let n=API_BASE+e,o=`Bearer ${Parse.User.current()?.getSessionToken()||localStorage.getItem("FMODE_AI_TOKEN")}`;return t.token=o,t&&(t=JSON.stringify(t)),fetch(n,{headers:{"Content-Type":"text/plain","Cache-Control":"no-cache"},body:t||null,method:s,credentials:"omit",mode:"cors"}).then((e=>{let t="";{let s=e.body?.getReader();const n=new TextDecoder;let o=new ReadableStream({start(e){!function read(){s.read().then((({done:t,value:s})=>{if(t)return e.close(),void i.complete();e.enqueue(s),read()}))}()}}).getReader();o.read().then((function processStream({done:e,value:s}){if(e)return;!function processData(e){let s=(t+e).split("\n");if(s?.length>1){for(let e=0;e<s.length-1;e++){let t=s[e];i.next(t)}t=s[s.length-1]}}(n.decode(s)),o.read().then(processStream)}))}})).catch((e=>i.error(e))),()=>{}}))}function JsonToFormData(e){const t=new FormData;return function appendFormData(e,s=""){Array.isArray(e)?e.forEach(((e,t)=>{appendFormData(e,`${s}[${t}]`)})):"object"==typeof e&&null!==e?Object.keys(e).forEach((t=>{const i=s?`${s}.${t}`:t;appendFormData(e[t],i)})):t.append(s,e)}(e),t}
8
+ import{bufferTime,concatMap,Observable,delay,finalize}from"rxjs";import Parse from"parse";import{AgentPrompt}from"../../agent";const API_BASE="https://server.fmode.cn/api/apig/aigc/gpt",agentPrompt=new AgentPrompt,PromptTplTalkSSMLOutputCode="talk-ssml-output-tpl";export function getMessageContentText(e){let t="";return"string"==typeof e&&(t=e),"object"==typeof e&&(t=e?.find((e=>e?.text))?.text||""),t}export function getMessageImageUrl(e){return"object"==typeof e?e?.find((e=>e?.image_url))?.image_url?.url||"":null}export class FmodeChat{constructor(e,t,s,i){this.ChatSession=Parse.Object.extend("ChatSession"),this.messageList=[{role:"system",content:"系统提示:AI仅供参考"}],this.latestAIResponse="",this.userInput="",this.userImage="",this.isTalkMode=!1,this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.playAnimation=e=>{console.log(e)},this.chatServ=i,this.role=t,this.sessionId=e,s?.id&&(this.chatSession=s,this.messageList=this.chatSession.get("messageList"),this.sessionId=s?.id)}async loadTalkSystemPrompt(e){if(!this.isTalkMode)return;if(!e)return;"男"==e?.get("gender")?this.SSMLRoleVoice="zh-CN-YunyeNeural":this.SSMLRoleVoice="zh-CN-XiaoxiaoNeural",this.SSMLRoleVoice=e?.get("voiceConfig")?.voice||this.SSMLRoleVoice;let t=await agentPrompt.getFormatTpl("talk-ssml-output-tpl",{SSMLRoleVoice:this.SSMLRoleVoice}),s=e.get("prompt")||"请你扮演脑控科技的人工智能专家。";s+=t;let i={role:"user",content:s,hidden:!0},n=this.messageList?.map((e=>e?.content)).join();if(n.indexOf(s)>-1)return;let o=this.messageList?.findIndex((e=>"system"==e?.role)),a=o+1;this.messageList.splice(a,0,i)}loadRolePrompt(){let e=this.role?.get("prompt"),t={role:"user",content:e,hidden:!0};if(!e)return;let s=this.messageList?.map((e=>e?.content)).join();if(s.indexOf(e)>-1)return;let i=this.messageList?.findIndex((e=>"system"==e?.role)),n=i+1;this.messageList.splice(n,0,t)}async sendMessage(e="FmodeAiTest测试问题",t,s){await this.loadTalkSystemPrompt(this.role),this.loadRolePrompt(),t?this.messageList.push({role:"user",content:[{type:"image_url",image_url:{url:t}},{type:"text",text:e}],complete:!0,createdAt:new Date}):this.messageList.push({role:"user",content:e,complete:!0,createdAt:new Date});let i=new FmodeChatCompletion(this.fixMessageList(this.messageList),{model:this.chatServ?.currentModel?.get("code")||"fmode-3.6-16k"}),n=!1;this.isTalkMode&&(n=!0);let o=i.sendCompletion({isDirect:n,onComplete:s||null}).pipe(finalize((()=>{this.messageList[i.indexOfList].complete=!0}))).subscribe((e=>{this.messageList[i.indexOfList]=e,this.latestAIResponse="string"==typeof e?.content?e?.content:e?.content?.[0]?.text||"";let t=this.chatSession?.get("messageList")?.length;this.messageList?.length>t&&this.saveChatSession(),e?.complete&&(this.saveChatSession(),o.unsubscribe())}))}async saveChatSession(){if("new"==this.sessionId&&(this.chatSession=new this.ChatSession),this.chatSession.set("title",this.genTitle()),this.chatSession.set("role",this.role?.toPointer()),this.chatSession.set("messageList",this.messageList),this.chatSession.set("user",Parse.User.current()?.toPointer()),this.chatSession=await this.chatSession.save(),this.sessionId=this.chatSession?.id,this.sessionId){let e=`${window.location.origin}/chat/pro/chat/${this.sessionId}`;e=this.getInviteUrl(e),window.history.replaceState(null,null,e);let t={sid:this.chatSession?.id,rid:this.role?.id,name:this.role?.get("name"),message:this.chatSession?.get("messageList")?.[this.chatSession?.get("messageList")?.length-1]?.content?.slice(0,20),latest:this.chatSession?.createdAt};this.chatServ?.chatList?.length||(this.chatServ.chatList=[]);let s=this.chatServ?.chatList?.find((e=>e?.sid==t?.sid));s>-1?this.chatServ.chatList[s]=t:this.chatServ?.chatList.unshift(t)}}getInviteUrl(e){let t="?";t=e?.indexOf("?")>-1?"&":"?";let s=Parse.User?.current()?.id;if(-1==e?.indexOf("invite="+s)){if(!s)return e;e+=t+"invite="+s}return e}genTitle(){if(this.title)return this.title;let e=this.messageList.find((e=>"user"==e.role))?.content;return"string"==typeof e&&(this.title=e?.slice(0,15)||""),"object"==typeof e&&(this.title=e?.find((e=>e?.text))?.text||""),this.title}fixMessageList(e){return e.map((e=>({role:e.role,content:e.content})))}nowStr(){let e=new Date;return`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()} ${e.getHours()}:${e.getMinutes()}:${e.getSeconds()}`}}export class FmodeChatCompletion{constructor(e,t){this.content="",this.contentBuffer=[],this.isCompleted=!1,this.indexOfList=Number(e.length),this.messages=e,this.model=t?.model||"fmode-3.6-16k"}sendCompletion(e={}){e.intTime=e?.intTime||50,e.isDirect=e?.isDirect||!1,e?.isDirect&&(e.intTime=1);let t={messages:this.messages,stream:!0,model:this.model,temperature:.5,presence_penalty:0,frequency_penalty:0};return new Observable((s=>{let i=RequestFmodeChatApi("/v1/chat/completions",t).subscribe((t=>{let n=String(t);if("data: [DONE]"==n&&(this.isCompleted=!0,e?.isDirect&&this.isCompleted&&(s.next({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),e?.onComplete&&e.onComplete({role:"assistant",content:this.content,complete:!0,createdAt:new Date}),s.complete())),n.indexOf("data: {")>-1){let t=chunkToJson(n),o=t?.choices?.[0]?.delta?.content||"";this.contentBuffer.push(o),e?.isDirect&&(this.content+=o||"",this.isCompleted||s.next({role:"assistant",cid:t?.id,content:this.content,createdAt:new Date})),e?.isDirect||this.contentPusher||(this.contentPusher=setInterval((()=>{this.isCompleted&&0==this.contentBuffer?.length&&(s.next({role:"assistant",cid:t?.id,content:this.content,complete:!0,createdAt:new Date}),i.unsubscribe(),clearInterval(this.contentPusher),s.complete()),this.contentBuffer?.length>=0&&(this.contentBuffer?.length>0&&(this.content+=this.contentBuffer.shift()),s.next({role:"assistant",cid:t?.id,content:this.content,createdAt:new Date}))}),e?.intTime))}}))})).pipe(bufferTime(100),concatMap((e=>e)),delay(200))}}function chunkToJson(e){let t;try{t=JSON.parse(e.replaceAll("data: ",""))}catch(e){console.error(e)}return t||{}}function RequestFmodeChatApi(e,t,s="POST"){return new Observable((i=>{let n=API_BASE+e,o=`Bearer ${Parse.User.current()?.getSessionToken()||localStorage.getItem("FMODE_AI_TOKEN")}`;return t.token=o,t&&(t=JSON.stringify(t)),fetch(n,{headers:{"Content-Type":"text/plain","Cache-Control":"no-cache"},body:t||null,method:s,credentials:"omit",mode:"cors"}).then((e=>{let t="";{let s=e.body?.getReader();const n=new TextDecoder;let o=new ReadableStream({start(e){!function read(){s.read().then((({done:t,value:s})=>{if(t)return e.close(),void i.complete();e.enqueue(s),read()}))}()}}).getReader();o.read().then((function processStream({done:e,value:s}){if(e)return;!function processData(e){let s=(t+e).split("\n");if(s?.length>1){for(let e=0;e<s.length-1;e++){let t=s[e];i.next(t)}t=s[s.length-1]}}(n.decode(s)),o.read().then(processStream)}))}})).catch((e=>i.error(e))),()=>{}}))}function JsonToFormData(e){const t=new FormData;return function appendFormData(e,s=""){Array.isArray(e)?e.forEach(((e,t)=>{appendFormData(e,`${s}[${t}]`)})):"object"==typeof e&&null!==e?Object.keys(e).forEach((t=>{const i=s?`${s}.${t}`:t;appendFormData(e[t],i)})):t.append(s,e)}(e),t}
9
9
  var MODULE_PATH_NEED = `6K+l5paH5Lu25piv5pys6aG555uu55qE5LiA6YOo5YiGIFRoaXMgZmlsZSBpcyBwYXJ0IG9mIHRoZSBDb21wb25lbnRzIGluIEZtb2RlIEluYy4KICAgIOeJiOadg+aJgOaciSDCqSDmnKrmnaXpo57pqawgwqkg5rGf6KW/6ISR5o6n56eR5oqA5pyJ6ZmQ5YWs5Y+4IENvcHlyaWdodCDCqSBGbW9kZSBUZWNobm9sb2d5IENvLiwgTHRkLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCBSaWdodHMgUmVzZXJ2ZWQuCiAgICDkuKXnpoHlnKjmnKrnu4/mjojmnYPnmoTmg4XlhrXkuIvvvIzpgJrov4fku7vkvZXlqpLku4vlpI3liLbmraTmlofku7YgVW5hdXRob3JpemVkIGNvcHlpbmcgb2YgdGhpcyBmaWxlLCB2aWEgYW55IG1lZGl1bSBpcyBzdHJpY3RseSBwcm9oaWJpdGVkCiAgICDor6Xmlofku7bmmK/kuJPmnInnmoTmnLrlr4bmlofku7YgUHJvcHJpZXRhcnkgYW5kIGNvbmZpZGVudGlhbAogICAKICAgIENvcHlyaWdodCAyMDIxLW5vdyBGbW9kZSBJbmMuIHN1cHBvcnRAZm1vZGUuY24uIDE4NjA3MDA3MDczLgogICAg5L+d55WZ5omA5pyJ5p2D5YipIEFsbCByaWdodHMgcmVzZXJ2ZWQuCgogICAgUEFUSDovaG9tZS9yeWFuL3dvcmtzcGFjZS9ub3ZhL25vdmEtYWRtaW4vZGlzdC9mbW9kZS1uZy9lc20yMDIwL2xpYi9haWdjL3NlcnZpY2UtZm1haS9zZXJ2aWNlLWNoYXQvY2hhdC1jbGFzcy5tanM=`
10
10