@mujian/js-sdk 0.0.6-beta.7 → 0.0.6-beta.71
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.
- package/dist/events/index.d.ts +34 -2
- package/dist/index.d.ts +16 -39
- package/dist/index.js +345 -16
- package/dist/lite.d.ts +54 -0
- package/dist/modules/ai/chat/chat.d.ts +46 -4
- package/dist/modules/ai/chat/index.d.ts +1 -1
- package/dist/modules/ai/chat/message/index.d.ts +4 -0
- package/dist/modules/ai/index.d.ts +3 -2
- package/dist/modules/ai/openai/chat.d.ts +25 -0
- package/dist/modules/ai/openai/completions.d.ts +19 -0
- package/dist/modules/ai/openai/images.d.ts +19 -0
- package/dist/modules/ai/openai/index.d.ts +4 -0
- package/dist/modules/ai/openai/responses.d.ts +20 -0
- package/dist/modules/ai/text/index.d.ts +9 -2
- package/dist/modules/config.d.ts +12 -0
- package/dist/modules/utils/clipboard.d.ts +5 -0
- package/dist/modules/utils/index.d.ts +4 -0
- package/dist/react/chat/useChat/index.d.ts +34 -8
- package/dist/react/chat/useChat/inner/chatStreaming.d.ts +2 -1
- package/dist/react/chat/useChat/message.d.ts +25 -13
- package/dist/react/components/MdRenderer/index.d.ts +6 -4
- package/dist/react/components/MdRenderer/utils/height.d.ts +0 -0
- package/dist/react/components/MdRenderer/utils/iframe.d.ts +9 -0
- package/dist/react/components/MdRenderer/utils/scripts.d.ts +4 -0
- package/dist/react/components/MujianSpinner/index.d.ts +7 -0
- package/dist/react/components/index.d.ts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/mjEngine/index.d.ts +48 -0
- package/dist/react.css +65 -4
- package/dist/react.js +780 -143
- package/dist/types/index.d.ts +38 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.LICENSE.txt +7 -0
- package/dist/umd/lite.js +2 -0
- package/dist/umd/lite.js.LICENSE.txt +7 -0
- package/dist/umd/react.css +1 -0
- package/dist/umd/react.js +139 -0
- package/dist/umd/react.js.LICENSE.txt +31 -0
- package/dist/utils/log.d.ts +4 -0
- package/package.json +6 -1
- /package/dist/react/components/MdRenderer/{utils.d.ts → utils/md.d.ts} +0 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type ProjectInfo = {
|
|
|
12
12
|
starCount?: number;
|
|
13
13
|
messageCount?: number;
|
|
14
14
|
};
|
|
15
|
+
config?: ProjectConfig;
|
|
15
16
|
};
|
|
16
17
|
export type PersonaInfo = {
|
|
17
18
|
name: string;
|
|
@@ -25,3 +26,40 @@ export type ModelInfo = {
|
|
|
25
26
|
description?: string;
|
|
26
27
|
price: number;
|
|
27
28
|
};
|
|
29
|
+
export type ProjectConfig = {
|
|
30
|
+
qrConfig?: QuickReplyConfig;
|
|
31
|
+
customCss?: string;
|
|
32
|
+
customJs?: string;
|
|
33
|
+
};
|
|
34
|
+
export type QuickReply = {
|
|
35
|
+
id: number;
|
|
36
|
+
showLabel: boolean;
|
|
37
|
+
label: string;
|
|
38
|
+
title: string;
|
|
39
|
+
message: string;
|
|
40
|
+
contextList: string[];
|
|
41
|
+
preventAutoExecute: boolean;
|
|
42
|
+
isHidden: boolean;
|
|
43
|
+
executeOnStartup: boolean;
|
|
44
|
+
executeOnUser: boolean;
|
|
45
|
+
executeOnAi: boolean;
|
|
46
|
+
executeOnChatChange: boolean;
|
|
47
|
+
executeOnGroupMemberDraft: boolean;
|
|
48
|
+
executeOnNewChat: boolean;
|
|
49
|
+
automationId: string;
|
|
50
|
+
};
|
|
51
|
+
export type QuickReplyConfig = {
|
|
52
|
+
version: number;
|
|
53
|
+
name: string;
|
|
54
|
+
disableSend: boolean;
|
|
55
|
+
placeBeforeInput: boolean;
|
|
56
|
+
injectInput: boolean;
|
|
57
|
+
color: string;
|
|
58
|
+
onlyBorderColor: boolean;
|
|
59
|
+
qrList: Array<QuickReply>;
|
|
60
|
+
idIndex: number;
|
|
61
|
+
};
|
|
62
|
+
export type Cursor = {
|
|
63
|
+
index: number;
|
|
64
|
+
messageId: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.MujianUMD=e():t.MujianUMD=e()}(globalThis,()=>(()=>{"use strict";var t,e={};e.d=(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},e.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),e.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};e.r(i),e.d(i,{MujianSdk:()=>k,EVENT:()=>u});var n="application/x-postmate-v1+json",a=0,s=function(t){var e=document.createElement("a");e.href=t;var i=e.protocol.length>4?e.protocol:window.location.protocol,n=e.host.length?"80"===e.port||"443"===e.port?e.hostname:e.host:window.location.host;return e.origin||i+"//"+n},r={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},o=function(t,e){return("string"!=typeof e||t.origin===e)&&!!t.data&&("object"!=typeof t.data||"postmate"in t.data)&&t.data.type===n&&!!r[t.data.postmate]},c=function(t,e){var i="function"==typeof t[e]?t[e]():t[e];return h.Promise.resolve(i)},l=function(){function t(t){var e=this;this.parent=t.parent,this.frame=t.frame,this.child=t.child,this.childOrigin=t.childOrigin,this.events={},this.listener=function(t){if(!o(t,e.childOrigin))return!1;var i=((t||{}).data||{}).value||{},n=i.data,a=i.name;"emit"===t.data.postmate&&a in e.events&&e.events[a].call(e,n)},this.parent.addEventListener("message",this.listener,!1)}var e=t.prototype;return e.get=function(t){var e=this;return new h.Promise(function(i){var s=++a;e.parent.addEventListener("message",function t(n){n.data.uid===s&&"reply"===n.data.postmate&&(e.parent.removeEventListener("message",t,!1),i(n.data.value))},!1),e.child.postMessage({postmate:"request",type:n,property:t,uid:s},e.childOrigin)})},e.call=function(t,e){this.child.postMessage({postmate:"call",type:n,property:t,data:e},this.childOrigin)},e.on=function(t,e){this.events[t]=e},e.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},t}(),d=function(){function t(t){var e=this;this.model=t.model,this.parent=t.parent,this.parentOrigin=t.parentOrigin,this.child=t.child,this.child.addEventListener("message",function(t){if(o(t,e.parentOrigin)){var i=t.data,a=i.property,s=i.uid,r=i.data;if("call"===t.data.postmate){a in e.model&&"function"==typeof e.model[a]&&e.model[a](r);return}c(e.model,a).then(function(e){return t.source.postMessage({property:a,postmate:"reply",type:n,uid:s,value:e},t.origin)})}})}return t.prototype.emit=function(t,e){this.parent.postMessage({postmate:"emit",type:n,value:{name:t,data:e}},this.parentOrigin)},t}(),h=function(){function t(t){var e=t.container,i=void 0===e?void 0!==i?i:document.body:e,n=t.model,a=t.url,s=t.name,r=t.classListArray;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=s||"",this.frame.classList.add.apply(this.frame.classList,void 0===r?[]:r),i.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=n||{},this.sendHandshake(a)}return t.prototype.sendHandshake=function(e){var i,a=this,r=s(e),c=0;return new t.Promise(function(t,s){a.parent.addEventListener("message",function e(n){return!!o(n,r)&&("handshake-reply"===n.data.postmate?(clearInterval(i),a.parent.removeEventListener("message",e,!1),a.childOrigin=n.origin,t(new l(a))):s("Failed handshake"))},!1);var d=function(){c++,a.child.postMessage({postmate:"handshake",type:n,model:a.model},r),5===c&&clearInterval(i)},h=function(){d(),i=setInterval(d,500)};a.frame.attachEvent?a.frame.attachEvent("onload",h):a.frame.onload=h,a.frame.src=e})},t}();h.debug=!1,h.Promise=function(){try{return window?window.Promise:Promise}catch(t){return null}}(),h.Model=function(){function t(t){return this.child=window,this.model=t,this.parent=this.child.parent,this.sendHandshakeReply()}return t.prototype.sendHandshakeReply=function(){var t=this;return new h.Promise(function(e,i){t.child.addEventListener("message",function a(s){if(s.data.postmate){if("handshake"===s.data.postmate){t.child.removeEventListener("message",a,!1),s.source.postMessage({postmate:"handshake-reply",type:n},s.origin),t.parentOrigin=s.origin;var r=s.data.model;return r&&Object.keys(r).forEach(function(e){t.model[e]=r[e]}),e(new d(t))}return i("Handshake Reply Failed")}},!1)})},t}();var u=((t={}).MUJIAN_INIT="mujian:init",t.MUJIAN_AI_CHAT_STOP="mujian:ai:chat:stop",t.MUJIAN_AI_CHAT_COMPLETE="mujian:ai:chat:complete",t.MUJIAN_AI_CHAT_APPLY_REGEX="mujian:ai:chat:applyRegex",t.MUJIAN_AI_CHAT_RENDER_MESSAGE="mujian:ai:chat:renderMessage",t.MUJIAN_AI_TEXT_GENERATE="mujian:ai:text:generate",t.MUJIAN_AI_OPENAI_COMPLETIONS_CREATE="mujian:ai:openai:completions:create",t.MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE="mujian:ai:openai:chat:completions:create",t.MUJIAN_AI_OPENAI_RESPONSES_CREATE="mujian:ai:openai:responses:create",t.MUJIAN_AI_CHAT_MESSAGE_GET_ALL="mujian:ai:chat:message:getAll",t.MUJIAN_AI_CHAT_MESSAGE_GET_PAGE="mujian:ai:chat:message:getPage",t.MUJIAN_AI_CHAT_PROJECT_GET_INFO="mujian:ai:chat:project:getInfo",t.MUJIAN_AI_SETTINGS_PERSONA_GET_ACTIVE="mujian:ai:settings:persona:getActive",t.MUJIAN_AI_SETTINGS_PERSONA_SET_ACTIVE="mujian:ai:settings:persona:setActive",t.MUJIAN_AI_SETTINGS_MODEL_GET_ALL="mujian:ai:settings:model:getAll",t.MUJIAN_AI_SETTINGS_MODEL_SET_ACTIVE="mujian:ai:settings:model:setActive",t.MUJIAN_AI_SETTINGS_MODEL_GET_ACTIVE="mujian:ai:settings:model:getActive",t.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE="mujian:ai:chat:message:deleteOne",t.MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE="mujian:ai:chat:message:editOne",t.MUJIAN_AI_CHAT_MESSAGE_SWIPE="mujian:ai:chat:message:swipe",t.MUJIAN_AI_CHAT_MESSAGE_GET_PROMPT="mujian:ai:chat:message:getPrompt",t.MUJIAN_AI_OPENAI_IMAGES_GENERATE="mujian:ai:openai:images:generate",t.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT="mujian:utils:clipboard:writeText",t.MUJIAN_GET_CONFIG="mujian:getConfig",t);let _=async function(t,e,i,n={}){let a,s,r,o;await this.call(u.MUJIAN_AI_CHAT_COMPLETE,{content:t},{onData:n.parseContent?(a="",s="",function(t){let i=(s+=t).split("\n");for(let t of(s=i.pop()||"",i))if(t.startsWith("data: "))try{let i=JSON.parse(t.slice(6));if(i.question_id&&(r=i.question_id),i.reply_id&&(o=i.reply_id),i.isFinished)return void e({isFinished:!0,deltaContent:"",fullContent:a,questionId:r,replyId:o});let n=i?.choices?.[0]?.delta?.content;n?.length>0&&(a+=n,e({isFinished:!1,deltaContent:n,fullContent:a,questionId:r,replyId:o}))}catch(t){e({isFinished:!0,error:t,deltaContent:"",fullContent:a,questionId:r,replyId:o});return}}):e,signal:i})},A=async function(t){return await this.call(u.MUJIAN_AI_CHAT_APPLY_REGEX,t)},m=async function(t){return await this.call(u.MUJIAN_AI_CHAT_RENDER_MESSAGE,t)},p=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_COMPLETE,{isContinue:!0},{onData:t,signal:e})},E=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_COMPLETE,{isRegenerate:!0},{onData:t,signal:e})},I=async function(){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_GET_ALL)},g=async function(t){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE,{messageId:t})},f=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE,{messageId:t,content:e})},T=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_SWIPE,{messageId:t,swipeId:e})},M=async function(t){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_GET_PROMPT,{messageId:t})};async function y(t,e){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_GET_PAGE,{fromCursor:t,pageSize:e})}let N=async function(){return await this.call(u.MUJIAN_AI_CHAT_PROJECT_GET_INFO)},C=async function(){return await this.call(u.MUJIAN_AI_SETTINGS_PERSONA_GET_ACTIVE)},w=async function(t){return await this.call(u.MUJIAN_AI_SETTINGS_PERSONA_SET_ACTIVE,{personaId:t})},S=async function(){return await this.call(u.MUJIAN_AI_SETTINGS_MODEL_GET_ACTIVE)},b=async function(t){return await this.call(u.MUJIAN_AI_SETTINGS_MODEL_SET_ACTIVE,{modelId:t})},v=async function(){return await this.call(u.MUJIAN_AI_SETTINGS_MODEL_GET_ALL)};async function O(){return await this.call(u.MUJIAN_GET_CONFIG)}let j=async function(){},P=async function(){};async function J(t){return await this.call(u.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT,t)}let G={i(...t){console.log("[MujianSDK] ",...t)},e(...t){console.error("[MujianSDK] ",...t)}};class U{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new U),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get config(){return this._config}async init(){let t=new h.Model({reply:({id:t,complete:e,data:i,error:n})=>{let a=this.pendingRequests.get(t);if(a){if(n){a.reject(n),this.pendingRequests.delete(t);return}a.onData?.(i),e&&(a.onComplete?.(),a.resolve(i),this.pendingRequests.delete(t))}}});try{let e=await t;this.ready=!0,this.parent=e,G.i("mujian sdk client init"),await this.call(u.MUJIAN_INIT);let i=await this.ai.chat.project.getInfo();if(i.config?.customCss){let t=document.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("id","mujian-custom-css"),t.textContent=i.config.customCss,document.head.appendChild(t)}if(i.config?.customJs){let t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("id","mujian-custom-js"),t.textContent=i.config.customJs,document.head.appendChild(t)}let n=await O.call(this);n&&(this._config=n)}catch(t){G.e("init error",t)}}emit(t,e){if(!this.ready)throw Error("Mujian is not initialized");this.parent?.emit(t,e)}nextCallId=0;getCallId(){let t=this.nextCallId;return this.nextCallId+=1,t}async call(t,e,i){if(!this.ready)throw Error("Mujian is not initialized");let n=this.getCallId();return new Promise((a,s)=>{this.pendingRequests.set(n,{resolve:a,reject:s,...i}),this.emit(t,{id:n,data:e}),i?.signal?.addEventListener("abort",()=>{this.emit(u.MUJIAN_AI_CHAT_STOP,{id:n})})})}ai={chat:{project:{getInfo:N.bind(this)},settings:{model:{getAll:v.bind(this),getActive:S.bind(this),setActive:b.bind(this)},persona:{getActive:C.bind(this),setActive:w.bind(this)}},complete:_.bind(this),applyRegex:A.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:E.bind(this),message:{getAll:I.bind(this),deleteOne:g.bind(this),editOne:f.bind(this),swipe:T.bind(this),getPrompt:M.bind(this),getPage:y.bind(this)}},text:{complete:R.bind(this)},openai:{completions:{create:H.create.bind(this)},chat:{completions:{create:L.completions.create.bind(this)}},responses:{create:x.create.bind(this)},images:{generate:D.generate.bind(this)}}};ui={};utils={clipboard:{writeText:J.bind(this)}};hybrid={};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:j.bind(this),loadGame:P.bind(this)},ranking:()=>{console.log("ranking")}}}let R=async function(t){return await this.call(U.EVENT.MUJIAN_AI_TEXT_GENERATE,{content:t})},L={completions:{create:async function(t,e,i,n){return await this.call(U.EVENT.MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}}},H={create:async function(t,e,i,n){return await this.call(U.EVENT.MUJIAN_AI_OPENAI_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}},x={create:async function(t,e,i,n){return await this.call(U.EVENT.MUJIAN_AI_OPENAI_RESPONSES_CREATE,{params:t,options:e},{onData:i,signal:n})}},D={generate:async function(t,e,i,n){return await this.call(U.EVENT.MUJIAN_AI_OPENAI_IMAGES_GENERATE,{params:t,options:e},{onData:i,signal:n})}};class k{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new k),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get config(){return this._config}async init(){let t=new h.Model({reply:({id:t,complete:e,data:i,error:n})=>{let a=this.pendingRequests.get(t);if(a){if(n){a.reject(n),this.pendingRequests.delete(t);return}a.onData?.(i),e&&(a.onComplete?.(),a.resolve(i),this.pendingRequests.delete(t))}}});try{let e=await t;this.ready=!0,this.parent=e,G.i("mujian sdk client init"),await this.call(u.MUJIAN_INIT);let i=await this.ai.chat.project.getInfo();if(i.config?.customCss){let t=document.createElement("style");t.setAttribute("type","text/css"),t.setAttribute("id","mujian-custom-css"),t.textContent=i.config.customCss,document.head.appendChild(t)}if(i.config?.customJs){let t=document.createElement("script");t.setAttribute("type","text/javascript"),t.setAttribute("id","mujian-custom-js"),t.textContent=i.config.customJs,document.head.appendChild(t)}let n=await O.call(this);n&&(this._config=n)}catch(t){G.e("init error",t)}}emit(t,e){if(!this.ready)throw Error("Mujian is not initialized");this.parent?.emit(t,e)}nextCallId=0;getCallId(){let t=this.nextCallId;return this.nextCallId+=1,t}async call(t,e,i){if(!this.ready)throw Error("Mujian is not initialized");let n=this.getCallId();return new Promise((a,s)=>{this.pendingRequests.set(n,{resolve:a,reject:s,...i}),this.emit(t,{id:n,data:e}),i?.signal?.addEventListener("abort",()=>{this.emit(u.MUJIAN_AI_CHAT_STOP,{id:n})})})}ai={chat:{project:{getInfo:N.bind(this)},settings:{model:{getAll:v.bind(this),getActive:S.bind(this),setActive:b.bind(this)},persona:{getActive:C.bind(this),setActive:w.bind(this)}},complete:_.bind(this),applyRegex:A.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:E.bind(this),message:{getAll:I.bind(this),deleteOne:g.bind(this),editOne:f.bind(this),swipe:T.bind(this),getPrompt:M.bind(this),getPage:y.bind(this)}},text:{complete:R.bind(this)},openai:{completions:{create:H.create.bind(this)},chat:{completions:{create:L.completions.create.bind(this)}},responses:{create:x.create.bind(this)},images:{generate:D.generate.bind(this)}}};ui={};utils={clipboard:{writeText:J.bind(this)}};hybrid={};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:j.bind(this),loadGame:P.bind(this)},ranking:()=>{console.log("ranking")}}}return i})());
|
package/dist/umd/lite.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see lite.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MujianLite=t():e.MujianLite=t()}(globalThis,()=>(()=>{"use strict";var e,t={};t.d=(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},t.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};t.r(i),t.d(i,{EVENT:()=>u,default:()=>_});var n="application/x-postmate-v1+json",a=0,r=function(e){var t=document.createElement("a");t.href=e;var i=t.protocol.length>4?t.protocol:window.location.protocol,n=t.host.length?"80"===t.port||"443"===t.port?t.hostname:t.host:window.location.host;return t.origin||i+"//"+n},s={handshake:1,"handshake-reply":1,call:1,emit:1,reply:1,request:1},o=function(e,t){return("string"!=typeof t||e.origin===t)&&!!e.data&&("object"!=typeof e.data||"postmate"in e.data)&&e.data.type===n&&!!s[e.data.postmate]},l=function(e,t){var i="function"==typeof e[t]?e[t]():e[t];return m.Promise.resolve(i)},d=function(){function e(e){var t=this;this.parent=e.parent,this.frame=e.frame,this.child=e.child,this.childOrigin=e.childOrigin,this.events={},this.listener=function(e){if(!o(e,t.childOrigin))return!1;var i=((e||{}).data||{}).value||{},n=i.data,a=i.name;"emit"===e.data.postmate&&a in t.events&&t.events[a].call(t,n)},this.parent.addEventListener("message",this.listener,!1)}var t=e.prototype;return t.get=function(e){var t=this;return new m.Promise(function(i){var r=++a;t.parent.addEventListener("message",function e(n){n.data.uid===r&&"reply"===n.data.postmate&&(t.parent.removeEventListener("message",e,!1),i(n.data.value))},!1),t.child.postMessage({postmate:"request",type:n,property:e,uid:r},t.childOrigin)})},t.call=function(e,t){this.child.postMessage({postmate:"call",type:n,property:e,data:t},this.childOrigin)},t.on=function(e,t){this.events[e]=t},t.destroy=function(){window.removeEventListener("message",this.listener,!1),this.frame.parentNode.removeChild(this.frame)},e}(),c=function(){function e(e){var t=this;this.model=e.model,this.parent=e.parent,this.parentOrigin=e.parentOrigin,this.child=e.child,this.child.addEventListener("message",function(e){if(o(e,t.parentOrigin)){var i=e.data,a=i.property,r=i.uid,s=i.data;if("call"===e.data.postmate){a in t.model&&"function"==typeof t.model[a]&&t.model[a](s);return}l(t.model,a).then(function(t){return e.source.postMessage({property:a,postmate:"reply",type:n,uid:r,value:t},e.origin)})}})}return e.prototype.emit=function(e,t){this.parent.postMessage({postmate:"emit",type:n,value:{name:e,data:t}},this.parentOrigin)},e}(),m=function(){function e(e){var t=e.container,i=void 0===t?void 0!==i?i:document.body:t,n=e.model,a=e.url,r=e.name,s=e.classListArray;return this.parent=window,this.frame=document.createElement("iframe"),this.frame.name=r||"",this.frame.classList.add.apply(this.frame.classList,void 0===s?[]:s),i.appendChild(this.frame),this.child=this.frame.contentWindow||this.frame.contentDocument.parentWindow,this.model=n||{},this.sendHandshake(a)}return e.prototype.sendHandshake=function(t){var i,a=this,s=r(t),l=0;return new e.Promise(function(e,r){a.parent.addEventListener("message",function t(n){return!!o(n,s)&&("handshake-reply"===n.data.postmate?(clearInterval(i),a.parent.removeEventListener("message",t,!1),a.childOrigin=n.origin,e(new d(a))):r("Failed handshake"))},!1);var c=function(){l++,a.child.postMessage({postmate:"handshake",type:n,model:a.model},s),5===l&&clearInterval(i)},m=function(){c(),i=setInterval(c,500)};a.frame.attachEvent?a.frame.attachEvent("onload",m):a.frame.onload=m,a.frame.src=t})},e}();m.debug=!1,m.Promise=function(){try{return window?window.Promise:Promise}catch(e){return null}}(),m.Model=function(){function e(e){return this.child=window,this.model=e,this.parent=this.child.parent,this.sendHandshakeReply()}return e.prototype.sendHandshakeReply=function(){var e=this;return new m.Promise(function(t,i){e.child.addEventListener("message",function a(r){if(r.data.postmate){if("handshake"===r.data.postmate){e.child.removeEventListener("message",a,!1),r.source.postMessage({postmate:"handshake-reply",type:n},r.origin),e.parentOrigin=r.origin;var s=r.data.model;return s&&Object.keys(s).forEach(function(t){e.model[t]=s[t]}),t(new c(e))}return i("Handshake Reply Failed")}},!1)})},e}();var u=((e={}).MUJIAN_INIT="mujian:init",e.MUJIAN_AI_CHAT_STOP="mujian:ai:chat:stop",e.MUJIAN_AI_CHAT_COMPLETE="mujian:ai:chat:complete",e.MUJIAN_AI_CHAT_APPLY_REGEX="mujian:ai:chat:applyRegex",e.MUJIAN_AI_CHAT_RENDER_MESSAGE="mujian:ai:chat:renderMessage",e.MUJIAN_AI_TEXT_GENERATE="mujian:ai:text:generate",e.MUJIAN_AI_OPENAI_COMPLETIONS_CREATE="mujian:ai:openai:completions:create",e.MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE="mujian:ai:openai:chat:completions:create",e.MUJIAN_AI_OPENAI_RESPONSES_CREATE="mujian:ai:openai:responses:create",e.MUJIAN_AI_CHAT_MESSAGE_GET_ALL="mujian:ai:chat:message:getAll",e.MUJIAN_AI_CHAT_MESSAGE_GET_PAGE="mujian:ai:chat:message:getPage",e.MUJIAN_AI_CHAT_PROJECT_GET_INFO="mujian:ai:chat:project:getInfo",e.MUJIAN_AI_SETTINGS_PERSONA_GET_ACTIVE="mujian:ai:settings:persona:getActive",e.MUJIAN_AI_SETTINGS_PERSONA_SET_ACTIVE="mujian:ai:settings:persona:setActive",e.MUJIAN_AI_SETTINGS_MODEL_GET_ALL="mujian:ai:settings:model:getAll",e.MUJIAN_AI_SETTINGS_MODEL_SET_ACTIVE="mujian:ai:settings:model:setActive",e.MUJIAN_AI_SETTINGS_MODEL_GET_ACTIVE="mujian:ai:settings:model:getActive",e.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE="mujian:ai:chat:message:deleteOne",e.MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE="mujian:ai:chat:message:editOne",e.MUJIAN_AI_CHAT_MESSAGE_SWIPE="mujian:ai:chat:message:swipe",e.MUJIAN_AI_CHAT_MESSAGE_GET_PROMPT="mujian:ai:chat:message:getPrompt",e.MUJIAN_AI_OPENAI_IMAGES_GENERATE="mujian:ai:openai:images:generate",e.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT="mujian:utils:clipboard:writeText",e.MUJIAN_GET_CONFIG="mujian:getConfig",e);let h={i(...e){console.log("[MujianSDK] ",...e)},e(...e){console.error("[MujianSDK] ",...e)}};class p{constructor(){}static EVENT=u;static getInstance(){return window.$mujian_lite||(window.$mujian_lite=new p),window.$mujian_lite}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get config(){return this._config}initPromise=null;async init(){return(console.log("call init"),this.ready)?Promise.resolve():(this.initPromise||(this.initPromise=(async()=>{let e=new m.Model({reply:({id:e,complete:t,data:i,error:n})=>{let a=this.pendingRequests.get(e);if(a){if(n){a.reject(n),this.pendingRequests.delete(e);return}a.onData?.(i),t&&(a.onComplete?.(),a.resolve(i),this.pendingRequests.delete(e))}}});try{let t=await e;this.parent=t,this.ready=!0,h.i("mujian sdk lite client init"),await this.call(u.MUJIAN_INIT),this._config=await this.call(u.MUJIAN_GET_CONFIG)}catch(e){throw h.e("init error",e),e}})()),this.initPromise)}ensureReady(){if(!this.ready)throw Error("MujianLite is not initialized")}emit(e,t){this.ensureReady(),this.parent?.emit(e,t)}nextCallId=0;getCallId(){let e=this.nextCallId;return this.nextCallId+=1,`lite_${e}`}async call(e,t,i){this.ensureReady();let n=this.getCallId();return new Promise((a,r)=>{this.pendingRequests.set(n,{resolve:a,reject:r,...i}),this.emit(e,{id:n,data:t})})}}p.getInstance().init();let _=p;return i})());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{interpolate-size:allow-keywords;--doc-height:100%;--transparent:#0000;--black30a:#0000004d;--black50a:#00000080;--black60a:#0009;--black70a:#000000b3;--black90a:#000000e6;--black100:#000;--white20a:#fff3;--white30a:#ffffff4d;--white50a:#ffffff80;--white60a:#fff9;--white70a:#ffffffb3;--white100:#fff;--grey10:#191919;--grey30:#4b4b4b;--grey50:#7d7d7d;--grey5020a:#7d7d7d33;--grey5050a:#7d7d7d80;--grey70:#afafaf;--grey75:#bebebe;--grey30a:#3232324d;--grey7070a:#afafafb3;--fullred:red;--crimson70a:#640000b3;--crimson-hover:#96323280;--okGreen70a:#006400b3;--cobalt30a:#6464ff4d;--greyCAIbg:#242425;--ivory:#dcdcd2;--golden:#f8d300;--warning:#ff0000e6;--active:#58b600;--preferred:#f44336;--interactable-outline-color:var(--white100);--interactable-outline-color-faint:var(--white20a);--reasoning-body-color:var(--SmartThemeEmColor);--reasoning-em-color:color-mix(in srgb,var(--SmartThemeEmColor)67%,var(--SmartThemeBlurTintColor)33%);--reasoning-saturation:.5;--SmartThemeBodyColor:#abc6df;--SmartThemeEmColor:#fff;--SmartThemeUnderlineColor:#bce7cf;--SmartThemeQuoteColor:#b983ff;--SmartThemeBlurTintColor:#171717;--SmartThemeChatTintColor:#171717;--SmartThemeUserMesBlurTintColor:#0000004d;--SmartThemeBotMesBlurTintColor:#3c3c3c4d;--SmartThemeBlurStrength:calc(var(--blurStrength)*1px);--SmartThemeShadowColor:#00000080;--SmartThemeBorderColor:#00000080;--SmartThemeCheckboxBgColorR:220;--SmartThemeCheckboxBgColorG:220;--SmartThemeCheckboxBgColorB:210;--SmartThemeCheckboxTickColorValue:calc(((((var(--SmartThemeCheckboxBgColorR)*299) + (var(--SmartThemeCheckboxBgColorG)*587) + (var(--SmartThemeCheckboxBgColorB)*114))/1000) - 128)*-1000);--SmartThemeCheckboxTickColor:rgb(var(--SmartThemeCheckboxTickColorValue),var(--SmartThemeCheckboxTickColorValue),var(--SmartThemeCheckboxTickColorValue));--sheldWidth:50vw;--fontScale:1;--mainFontSize:calc(var(--fontScale)*15px);--mainFontFamily:"Noto Sans",sans-serif;--monoFontFamily:"Noto Sans Mono","Courier New",Consolas,monospace;--blurStrength:10;--shadowWidth:2;--bottomFormBlockPadding:calc(var(--mainFontSize)/2.5);--bottomFormIconSize:calc(var(--mainFontSize)*1.9);--bottomFormBlockSize:calc(var(--bottomFormIconSize) + var(--bottomFormBlockPadding));--topBarIconSize:calc(var(--mainFontSize)*2);--topBarBlockSize:calc(var(--topBarIconSize) + var(--topBarBlockPadding));--topBarBlockPadding:calc(var(--mainFontSize)/3);--tool-cool-color-picker-btn-bg:transparent;--tool-cool-color-picker-btn-border-color:transparent;--mes-right-spacing:30px;--avatar-base-height:50px;--avatar-base-width:50px;--avatar-base-border-radius:2px;--avatar-base-border-radius-round:50%;--avatar-base-border-radius-rounded:10px;--inline-avatar-small-factor:.6;--animation-duration:.125s;--animation-duration-2x:calc(var(--animation-duration)*2);--animation-duration-3x:calc(var(--animation-duration)*3);--animation-duration-slow:var(--animation-duration-3x)}*{box-sizing:border-box;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.spin-overlay{background-color:#000;animation:3s ease-in-out infinite breath}@keyframes breath{0%{background-color:#0009}50%{background-color:#00000080}to{background-color:#0009}}.wave-text span{font-family:var(--mainFontFamily);animation:2s ease-in-out infinite wave;display:inline-block}.wave-text span:first-child{animation-delay:0s}.wave-text span:nth-child(2){animation-delay:.2s}.wave-text span:nth-child(3){animation-delay:.4s}.wave-text span:nth-child(4){animation-delay:.6s}.wave-text span:nth-child(5){animation-delay:.8s}.wave-text span:nth-child(6){animation-delay:1s}.wave-text span:nth-child(7){animation-delay:1.2s}@keyframes wave{0%,to{transform:translateY(0)}50%{transform:translateY(-8px)}}body{font-size:var(--mainFontSize);color:var(--SmartThemeBodyColor)}.mes_text table,.mes_reasoning table{border-spacing:0;border-collapse:collapse;margin-bottom:10px}.mes_text td,.mes_text th,.mes_reasoning td,.mes_reasoning th{border-collapse:collapse;border:1px solid;padding:.25em}.mes_text p,.mes_reasoning p{margin-top:0;margin-bottom:10px}.mes_text li tt,.mes_reasoning li tt{display:inline-block}.mes_text ol,.mes_text ul,.mes_reasoning ol,.mes_reasoning ul{margin-top:5px;margin-bottom:5px}.mes_text br,.mes_bias br,.mes_reasoning br{content:" "}.mes q:before,.mes q:after,.mes_text q:before,.mes_text q:after{content:""}.mes_text br{display:none}.mes_text table{border-spacing:0;border-collapse:collapse;margin-bottom:16px}.mes_text td,.mes_text th{border-collapse:collapse;border:1px solid;padding:.25em}.mes_text p{color:var(--SmartThemeBodyColor);margin-top:0;margin-bottom:16px}.mes_text,.mes_reasoning{line-height:calc(var(--mainFontSize) + .5rem);overflow-wrap:anywhere;max-width:100%}.mes_text p:only-child,.mes_text p:only-of-type{margin-bottom:0}.mes_text ol{unicode-bidi:isolate;margin-block:1em;margin-inline:0;padding-inline-start:24px;list-style-type:decimal;display:block}.mes_text li tt{display:inline-block}.mes_text li{position:relative}.mes_text ol,.mes_text ul{margin-top:5px;margin-bottom:5px}.mes_text br,.mes_bias br{content:" ";margin:2px 0;display:block}.mes_bias{font-size:calc(var(--mainFontSize) - .1rem);color:var(--SmartThemeQuoteColor);font-weight:500;display:block}.mes_text i,.mes_text em{color:var(--SmartThemeEmColor)}.mes_reasoning i,.mes_reasoning em{color:hsl(from var(--reasoning-em-color)h calc(s*var(--reasoning-saturation))l)}.mes_text q i,.mes_text q em{color:inherit}.mes_reasoning q i,.mes_reasoning q em{color:hsl(from var(--SmartThemeQuoteColor)h calc(s*var(--reasoning-saturation))l)}.mes_text u{color:var(--SmartThemeUnderlineColor)}.mes_reasoning u{color:hsl(from var(--SmartThemeUnderlineColor)h calc(s*var(--reasoning-saturation))l)}.mes_text q{color:var(--SmartThemeQuoteColor)}.mes_reasoning q{color:hsl(from var(--SmartThemeQuoteColor)h calc(s*var(--reasoning-saturation))l)}.mes_text font[color] em,.mes_text font[color] i,.mes_text font[color] u,.mes_text font[color] q,.mes_reasoning font[color] em,.mes_reasoning font[color] i,.mes_reasoning font[color] u,.mes_reasoning font[color] q{color:inherit}.mes_text rp{display:block}.mes_text blockquote,.mes_reasoning blockquote{border-left:3px solid var(--SmartThemeQuoteColor);background-color:var(--black30a);margin:0;padding-left:10px}.mes_text strong em,.mes_text strong,.mes_text h2,.mes_text h1,.mes_reasoning strong em,.mes_reasoning strong,.mes_reasoning h2,.mes_reasoning h1{font-weight:700}.mes_text pre code,.mes_reasoning pre code{padding:1em;display:block;position:relative;overflow-x:auto}.mes_text img:not(.mes_img),.mes_reasoning img:not(.mes_img){max-width:100%;max-height:var(--doc-height)}code{font-family:var(--monoFontFamily);white-space:pre-wrap;line-height:var(--mainFontSize);color:var(--white70a);border:1px solid #fff;padding:0 3px}.mes-dialogue{background:var(--SmartThemeQuoteBg);-webkit-text-fill-color:transparent;color:#0000;background-clip:text}.mes_text img{width:100%}
|