@mujian/js-sdk 0.1.0-beta.9 → 0.13.0-alpha.2

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.
@@ -112,6 +112,10 @@ export declare enum EVENT {
112
112
  * 写入剪贴版
113
113
  */
114
114
  MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT = "mujian:utils:clipboard:writeText",
115
+ /**
116
+ * 打开角色信息弹窗
117
+ */
118
+ MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL = "mujian:hybrid:showCharacterDetail",
115
119
  /**
116
120
  * 获取配置
117
121
  */
package/dist/index.d.ts CHANGED
@@ -73,21 +73,15 @@ declare class MujianSdk {
73
73
  stop: (conversationVersion: number, assisMsgId: string) => Promise<string>;
74
74
  recover: (conversationVersion: number, assisMsgId: string, onData: (data: string) => void) => Promise<string>;
75
75
  message: {
76
+ getAll: () => Promise<import("./react").Message[]>;
76
77
  deleteOne: (messageId: string) => Promise<unknown>;
77
78
  editOne: (messageId: string, content: string) => Promise<unknown>;
78
79
  swipe: (messageId: string, swipeId: number) => Promise<unknown>;
79
- getPage: (fromCursor: import("./types").Cursor | undefined, pageSize: number) => Promise<{
80
- messages: {
81
- swipes: (string & import("./react/chat/useChat/message").MessageV2Swipe)[];
82
- content: string;
83
- id: string;
84
- isUser: boolean;
85
- activeSwipeId: number;
86
- isGenerating?: boolean;
87
- finishReason?: string;
88
- error?: import("./react/chat/useChat/message").ChatError;
89
- }[];
80
+ getPage: (fromCursor: import("./types").Cursor | undefined, pageSize: number, options?: {
81
+ compatMode: boolean;
82
+ } | undefined) => Promise<{
90
83
  nextCursor?: import("./types").Cursor;
84
+ messages: Array<import("./react").Message>;
91
85
  total?: number;
92
86
  conversationVersion: number;
93
87
  }>;
@@ -104,7 +98,9 @@ declare class MujianSdk {
104
98
  writeText: (text: string) => Promise<unknown>;
105
99
  };
106
100
  };
107
- hybrid: {};
101
+ hybrid: {
102
+ showCharacterDetail: (characterId: string) => Promise<unknown>;
103
+ };
108
104
  player: {};
109
105
  game: {
110
106
  assets: () => void;
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
27
27
  EVENT["MUJIAN_AI_CHAT_MESSAGE_SWIPE"] = "mujian:ai:chat:message:swipe";
28
28
  EVENT["MUJIAN_AI_OPENAI_IMAGES_GENERATE"] = "mujian:ai:openai:images:generate";
29
29
  EVENT["MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT"] = "mujian:utils:clipboard:writeText";
30
+ EVENT["MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL"] = "mujian:hybrid:showCharacterDetail";
30
31
  EVENT["MUJIAN_GET_CONFIG"] = "mujian:getConfig";
31
32
  return EVENT;
32
33
  }({});
@@ -71,6 +72,9 @@ const recover = async function(conversationVersion, assisMsgId, onData) {
71
72
  onData
72
73
  });
73
74
  };
75
+ const getAll = async function() {
76
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_MESSAGE_GET_ALL);
77
+ };
74
78
  const messageDeleteOne = async function(messageId) {
75
79
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE, {
76
80
  messageId
@@ -88,23 +92,40 @@ const messageSwipe = async function(messageId, swipeId) {
88
92
  swipeId
89
93
  });
90
94
  };
91
- async function getPage(fromCursor, pageSize) {
95
+ async function getPage(fromCursor, pageSize, options = {
96
+ compatMode: true
97
+ }) {
92
98
  const resp = await this.call(events_EVENT.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE, {
93
99
  fromCursor,
94
100
  pageSize
95
101
  });
102
+ if (!options.compatMode) return resp;
96
103
  return {
97
104
  ...resp,
98
105
  messages: resp.messages.map((m)=>({
99
106
  ...m,
100
107
  swipes: m.swipes.map((s)=>{
101
- const ret = Object.assign(s.content, s);
102
- return ret;
108
+ if ('string' == typeof s.content) return s.content;
109
+ return s.content.map((c)=>{
110
+ switch(c.type){
111
+ case 'narrative':
112
+ return c.content;
113
+ case 'character':
114
+ return `${c.name}: ${c.content}`;
115
+ }
116
+ }).filter(Boolean).join('\n\n');
103
117
  }),
104
- content: m.swipes[m.activeSwipeId].content
118
+ content: m.swipes[m.activeSwipeId].content,
119
+ role: m.isUser ? 'user' : 'assistant',
120
+ sendAt: extractDateFromObjectId(m.id)
105
121
  }))
106
122
  };
107
123
  }
124
+ function extractDateFromObjectId(id) {
125
+ const timestampInSeconds = parseInt(id.substring(0, 8), 16);
126
+ const date = new Date(1000 * timestampInSeconds);
127
+ return date;
128
+ }
108
129
  const getInfo = async function() {
109
130
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_PROJECT_GET_INFO);
110
131
  };
@@ -116,6 +137,11 @@ async function getConfig() {
116
137
  }
117
138
  const saveGame = async function() {};
118
139
  const loadGame = async function() {};
140
+ const showCharacterDetail = async function(characterId) {
141
+ return await this.call(events_EVENT.MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL, {
142
+ characterId
143
+ });
144
+ };
119
145
  async function writeText(text) {
120
146
  return await this.call(events_EVENT.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT, text);
121
147
  }
@@ -241,6 +267,7 @@ class MujianSdk {
241
267
  stop: stop.bind(this),
242
268
  recover: recover.bind(this),
243
269
  message: {
270
+ getAll: getAll.bind(this),
244
271
  deleteOne: messageDeleteOne.bind(this),
245
272
  editOne: messageEditOne.bind(this),
246
273
  swipe: messageSwipe.bind(this),
@@ -273,7 +300,9 @@ class MujianSdk {
273
300
  writeText: writeText.bind(this)
274
301
  }
275
302
  };
276
- hybrid = {};
303
+ hybrid = {
304
+ showCharacterDetail: showCharacterDetail.bind(this)
305
+ };
277
306
  player = {};
278
307
  game = {
279
308
  assets: ()=>{
@@ -453,6 +482,7 @@ class src_MujianSdk {
453
482
  stop: stop.bind(this),
454
483
  recover: recover.bind(this),
455
484
  message: {
485
+ getAll: getAll.bind(this),
456
486
  deleteOne: messageDeleteOne.bind(this),
457
487
  editOne: messageEditOne.bind(this),
458
488
  swipe: messageSwipe.bind(this),
@@ -485,7 +515,9 @@ class src_MujianSdk {
485
515
  writeText: writeText.bind(this)
486
516
  }
487
517
  };
488
- hybrid = {};
518
+ hybrid = {
519
+ showCharacterDetail: showCharacterDetail.bind(this)
520
+ };
489
521
  player = {};
490
522
  game = {
491
523
  assets: ()=>{
package/dist/lite.js CHANGED
@@ -27,6 +27,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
27
27
  EVENT["MUJIAN_AI_CHAT_MESSAGE_SWIPE"] = "mujian:ai:chat:message:swipe";
28
28
  EVENT["MUJIAN_AI_OPENAI_IMAGES_GENERATE"] = "mujian:ai:openai:images:generate";
29
29
  EVENT["MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT"] = "mujian:utils:clipboard:writeText";
30
+ EVENT["MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL"] = "mujian:hybrid:showCharacterDetail";
30
31
  EVENT["MUJIAN_GET_CONFIG"] = "mujian:getConfig";
31
32
  return EVENT;
32
33
  }({});
@@ -1,5 +1,13 @@
1
1
  import type { MujianSdk } from '../../../../index.ts';
2
+ import type { Message } from '../../../../react/chat/useChat/message';
2
3
  import { Cursor } from '../../../../types';
4
+ /**
5
+ * 获取消息列表
6
+ * @returns 消息当前列表
7
+ */
8
+ export declare const getAll: (
9
+ /** @hidden */
10
+ this: MujianSdk) => Promise<Message[]>;
3
11
  /**
4
12
  * 删除消息
5
13
  * @param messageId 消息ID
@@ -26,21 +34,16 @@ this: MujianSdk, messageId: string, content: string) => Promise<unknown>;
26
34
  export declare const messageSwipe: (
27
35
  /** @hidden */
28
36
  this: MujianSdk, messageId: string, swipeId: number) => Promise<unknown>;
29
- export declare function getPage(
30
- /** @hidden */
31
- this: MujianSdk, fromCursor: Cursor | undefined, pageSize: number): Promise<{
32
- messages: {
33
- swipes: (string & import("../../../../react/chat/useChat/message").MessageV2Swipe)[];
34
- content: string;
35
- id: string;
36
- isUser: boolean;
37
- activeSwipeId: number;
38
- isGenerating?: boolean;
39
- finishReason?: string;
40
- error?: import("../../../../react/chat/useChat/message").ChatError;
41
- }[];
37
+ type GetPageResp = {
42
38
  /** 分页游标,若为空则表示无下一页 */
43
39
  nextCursor?: Cursor;
40
+ messages: Array<Message>;
44
41
  total?: number;
45
42
  conversationVersion: number;
46
- }>;
43
+ };
44
+ export declare function getPage(
45
+ /** @hidden */
46
+ this: MujianSdk, fromCursor: Cursor | undefined, pageSize: number, options?: {
47
+ compatMode: boolean;
48
+ }): Promise<GetPageResp>;
49
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { MujianSdk } from '../../index.ts';
2
+ export declare const showCharacterDetail: (
3
+ /** @hidden */
4
+ this: MujianSdk, characterId: string) => Promise<unknown>;
@@ -1 +1,2 @@
1
1
  export { type Message, useChat } from './useChat';
2
+ export { type CharacterChunk, getMessageContentLength, type ImageChunk, type MessageChunk, type MessageV2Content, type NarrativeChunk, sliceMessageContent, type UnlockedImageChunk, type VideoChunk, } from './useChat/message';
@@ -3,7 +3,42 @@ type Mjv = {
3
3
  delta: unknown;
4
4
  schema: unknown;
5
5
  };
6
- export type MessageV2Content = string;
6
+ export type MessageV2Content = string | Array<MessageChunk>;
7
+ export type MessageChunk = CharacterChunk | NarrativeChunk | ImageChunk | VideoChunk | UnlockedImageChunk;
8
+ export interface CharacterChunk {
9
+ type: 'character';
10
+ character_id?: string;
11
+ name: string;
12
+ avatarUrl?: string;
13
+ content: string;
14
+ }
15
+ export interface NarrativeChunk {
16
+ type: 'narrative';
17
+ content: string;
18
+ }
19
+ export interface ImageChunk {
20
+ type: 'assets-image';
21
+ url: string;
22
+ }
23
+ export interface VideoChunk {
24
+ type: 'assets-video';
25
+ url: string;
26
+ }
27
+ export interface UnlockedImageChunk {
28
+ type: 'unlocked-image';
29
+ id?: string;
30
+ url?: string;
31
+ }
32
+ /**
33
+ * 获取消息内容的文本长度。
34
+ * 只有 character/narrative 的 content 计入长度,图片、视频等为 0。
35
+ */
36
+ export declare function getMessageContentLength(content: MessageV2Content): number;
37
+ /**
38
+ * 按文本字符位置裁剪消息内容。
39
+ * 图片、视频等零长度块不占打字进度,前面的文本显示完后就会展示。
40
+ */
41
+ export declare function sliceMessageContent(content: MessageV2Content, pos: number): MessageV2Content;
7
42
  export interface MessageV2Swipe {
8
43
  content: MessageV2Content;
9
44
  mjv?: Mjv;
package/dist/react.js CHANGED
@@ -530,6 +530,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
530
530
  EVENT["MUJIAN_AI_CHAT_MESSAGE_SWIPE"] = "mujian:ai:chat:message:swipe";
531
531
  EVENT["MUJIAN_AI_OPENAI_IMAGES_GENERATE"] = "mujian:ai:openai:images:generate";
532
532
  EVENT["MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT"] = "mujian:utils:clipboard:writeText";
533
+ EVENT["MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL"] = "mujian:hybrid:showCharacterDetail";
533
534
  EVENT["MUJIAN_GET_CONFIG"] = "mujian:getConfig";
534
535
  return EVENT;
535
536
  }({});
@@ -574,6 +575,9 @@ const recover = async function(conversationVersion, assisMsgId, onData) {
574
575
  onData
575
576
  });
576
577
  };
578
+ const getAll = async function() {
579
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_MESSAGE_GET_ALL);
580
+ };
577
581
  const messageDeleteOne = async function(messageId) {
578
582
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE, {
579
583
  messageId
@@ -591,23 +595,40 @@ const messageSwipe = async function(messageId, swipeId) {
591
595
  swipeId
592
596
  });
593
597
  };
594
- async function getPage(fromCursor, pageSize) {
598
+ async function getPage(fromCursor, pageSize, options = {
599
+ compatMode: true
600
+ }) {
595
601
  const resp = await this.call(events_EVENT.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE, {
596
602
  fromCursor,
597
603
  pageSize
598
604
  });
605
+ if (!options.compatMode) return resp;
599
606
  return {
600
607
  ...resp,
601
608
  messages: resp.messages.map((m)=>({
602
609
  ...m,
603
610
  swipes: m.swipes.map((s)=>{
604
- const ret = Object.assign(s.content, s);
605
- return ret;
611
+ if ('string' == typeof s.content) return s.content;
612
+ return s.content.map((c)=>{
613
+ switch(c.type){
614
+ case 'narrative':
615
+ return c.content;
616
+ case 'character':
617
+ return `${c.name}: ${c.content}`;
618
+ }
619
+ }).filter(Boolean).join('\n\n');
606
620
  }),
607
- content: m.swipes[m.activeSwipeId].content
621
+ content: m.swipes[m.activeSwipeId].content,
622
+ role: m.isUser ? 'user' : 'assistant',
623
+ sendAt: extractDateFromObjectId(m.id)
608
624
  }))
609
625
  };
610
626
  }
627
+ function extractDateFromObjectId(id) {
628
+ const timestampInSeconds = parseInt(id.substring(0, 8), 16);
629
+ const date = new Date(1000 * timestampInSeconds);
630
+ return date;
631
+ }
611
632
  const getInfo = async function() {
612
633
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_PROJECT_GET_INFO);
613
634
  };
@@ -670,6 +691,11 @@ async function getConfig() {
670
691
  }
671
692
  const saveGame = async function() {};
672
693
  const loadGame = async function() {};
694
+ const showCharacterDetail = async function(characterId) {
695
+ return await this.call(events_EVENT.MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL, {
696
+ characterId
697
+ });
698
+ };
673
699
  async function writeText(text) {
674
700
  return await this.call(events_EVENT.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT, text);
675
701
  }
@@ -787,6 +813,7 @@ class MujianSdk {
787
813
  stop: chat_stop.bind(this),
788
814
  recover: recover.bind(this),
789
815
  message: {
816
+ getAll: getAll.bind(this),
790
817
  deleteOne: messageDeleteOne.bind(this),
791
818
  editOne: messageEditOne.bind(this),
792
819
  swipe: messageSwipe.bind(this),
@@ -819,7 +846,9 @@ class MujianSdk {
819
846
  writeText: writeText.bind(this)
820
847
  }
821
848
  };
822
- hybrid = {};
849
+ hybrid = {
850
+ showCharacterDetail: showCharacterDetail.bind(this)
851
+ };
823
852
  player = {};
824
853
  game = {
825
854
  assets: ()=>{
@@ -962,7 +991,7 @@ const MessageItem = (props)=>{
962
991
  const posIncrement = frames * typingOpts.chunkSize;
963
992
  const message = latestMessage.current;
964
993
  const content = message.swipes[message.activeSwipeId].content;
965
- const maxPos = content.length;
994
+ const maxPos = getMessageContentLength(content);
966
995
  const nextPos = Math.min((p || 0) + posIncrement, maxPos);
967
996
  if (!message.isGenerating && maxPos === nextPos) {
968
997
  stopTypeWriting();
@@ -978,7 +1007,7 @@ const MessageItem = (props)=>{
978
1007
  useEffect(()=>{
979
1008
  if (message.isGenerating) {
980
1009
  const content = message.swipes[message.activeSwipeId].content;
981
- setTypeWritingPos(content.length);
1010
+ setTypeWritingPos(getMessageContentLength(content));
982
1011
  startTypeWriting();
983
1012
  }
984
1013
  }, [
@@ -986,7 +1015,7 @@ const MessageItem = (props)=>{
986
1015
  ]);
987
1016
  const prevMessageBrief = useRef(null);
988
1017
  useEffect(()=>{
989
- const length = message.swipes[message.activeSwipeId].content.length;
1018
+ const length = getMessageContentLength(message.swipes[message.activeSwipeId].content);
990
1019
  if (prevMessageBrief.current) {
991
1020
  const { length: prevLength } = prevMessageBrief.current;
992
1021
  if (0 === prevLength) setTypeWritingPos(length);
@@ -999,7 +1028,7 @@ const MessageItem = (props)=>{
999
1028
  ]);
1000
1029
  useEffect(()=>{
1001
1030
  if ('user_stopped' === message.finishReason) {
1002
- const length = message.swipes[message.activeSwipeId].content.length;
1031
+ const length = getMessageContentLength(message.swipes[message.activeSwipeId].content);
1003
1032
  setTypeWritingPos(length);
1004
1033
  }
1005
1034
  }, [
@@ -1014,16 +1043,20 @@ const MessageItem = (props)=>{
1014
1043
  if (i !== message.activeSwipeId) return s;
1015
1044
  return {
1016
1045
  ...s,
1017
- content: s.content.slice(0, pos)
1046
+ content: sliceMessageContent(s.content, pos)
1018
1047
  };
1019
1048
  })
1020
1049
  };
1021
1050
  }
1022
- return await mujian.ai.chat.renderMessage({
1023
- message,
1024
- depth,
1025
- index
1026
- });
1051
+ try {
1052
+ return await mujian.ai.chat.renderMessage({
1053
+ message,
1054
+ depth,
1055
+ index
1056
+ });
1057
+ } catch {
1058
+ return message;
1059
+ }
1027
1060
  }, {
1028
1061
  refreshDeps: [
1029
1062
  message,
@@ -1372,7 +1405,9 @@ const useChat = ({ body, onFinish, pageSize = 10 })=>{
1372
1405
  list: []
1373
1406
  };
1374
1407
  try {
1375
- const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
1408
+ const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize, {
1409
+ compatMode: false
1410
+ });
1376
1411
  conversationVersion.current = resp.conversationVersion;
1377
1412
  const lastMessage = resp.messages.at(-1);
1378
1413
  if (lastMessage?.isGenerating) recoverStreaming(lastMessage.id, conversationVersion.current);
@@ -1448,7 +1483,7 @@ const useChat = ({ body, onFinish, pageSize = 10 })=>{
1448
1483
  const lastMessage = messages.findLast((message)=>message.isUser);
1449
1484
  const query = lastMessage ? lastMessage.swipes[lastMessage.activeSwipeId].content : '';
1450
1485
  await chatStreaming({
1451
- query,
1486
+ query: 'string' == typeof query ? query : '',
1452
1487
  regenerate: true,
1453
1488
  conversationVersion: conversationVersion.current
1454
1489
  });
@@ -1540,4 +1575,42 @@ const useChat = ({ body, onFinish, pageSize = 10 })=>{
1540
1575
  refresh
1541
1576
  };
1542
1577
  };
1543
- export { MdRenderer, MujianProvider, MujianSpinner, Thread, useChat, useChatContext, useMjEngine, useMujian };
1578
+ function isTextChunk(chunk) {
1579
+ return 'character' === chunk.type || 'narrative' === chunk.type;
1580
+ }
1581
+ function getChunkTextLength(chunk) {
1582
+ return isTextChunk(chunk) ? chunk.content.length : 0;
1583
+ }
1584
+ function getMessageContentLength(content) {
1585
+ if ('string' == typeof content) return content.length;
1586
+ return content.reduce((total, chunk)=>total + getChunkTextLength(chunk), 0);
1587
+ }
1588
+ function sliceMessageContent(content, pos) {
1589
+ if ('string' == typeof content) return content.slice(0, Math.max(pos, 0));
1590
+ const visible = [];
1591
+ let remaining = Math.max(pos, 0);
1592
+ for (const chunk of content){
1593
+ if (!isTextChunk(chunk)) {
1594
+ visible.push(chunk);
1595
+ continue;
1596
+ }
1597
+ const text = chunk.content;
1598
+ if (0 === text.length) {
1599
+ visible.push(chunk);
1600
+ continue;
1601
+ }
1602
+ if (remaining <= 0) break;
1603
+ if (remaining >= text.length) {
1604
+ visible.push(chunk);
1605
+ remaining -= text.length;
1606
+ continue;
1607
+ }
1608
+ visible.push({
1609
+ ...chunk,
1610
+ content: text.slice(0, remaining)
1611
+ });
1612
+ break;
1613
+ }
1614
+ return visible;
1615
+ }
1616
+ export { MdRenderer, MujianProvider, MujianSpinner, Thread, getMessageContentLength, sliceMessageContent, useChat, useChatContext, useMjEngine, useMujian };
package/dist/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
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:()=>G,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_CHAT_V2_COMPLETE="mujian:ai:chat_v2:complete",t.MUJIAN_AI_CHAT_V2_RECOVER="mujian:ai:chat_v2:recover",t.MUJIAN_AI_CHAT_V2_STOP="mujian:ai:chat_v2:stop",t.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE="mujian:ai:chat_v2:message:getPage",t.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE="mujian:ai:chat_v2:renderMessage",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_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){await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{content:t,conversationVersion:e},{onData:i})},m=async function(t){return await this.call(u.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE,t)},p=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{isContinue:!0,conversationVersion:t},{onData:e})},A=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{isRegenerate:!0,conversationVersion:t},{onData:e})},E=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_STOP,{conversationVersion:t,assisMsgId:e})},I=async function(t,e,i){return await this.call(u.MUJIAN_AI_CHAT_V2_RECOVER,{conversationVersion:t,assisMsgId:e},{onData:i})},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})};async function M(t,e){let i=await this.call(u.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE,{fromCursor:t,pageSize:e});return{...i,messages:i.messages.map(t=>({...t,swipes:t.swipes.map(t=>Object.assign(t.content,t)),content:t.swipes[t.activeSwipeId].content}))}}let y=async function(){return await this.call(u.MUJIAN_AI_CHAT_PROJECT_GET_INFO)},N=async function(){return await this.call(u.MUJIAN_AI_SETTINGS_PERSONA_GET_ACTIVE)};async function C(){return await this.call(u.MUJIAN_GET_CONFIG)}let w=async function(){},v=async function(){};async function S(t){return await this.call(u.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT,t)}let b={i(...t){console.log("[MujianSDK] ",...t)},e(...t){console.error("[MujianSDK] ",...t)}};class O{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new O),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get openapi(){return this._config?.openapi}initPromise=null;async init(){return this.initPromise||(this.initPromise=(async()=>{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,b.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 C.call(this);n&&(this._config=n)}catch(t){b.e("init error",t)}})()),this.initPromise}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:y.bind(this)},settings:{persona:{getActive:N.bind(this)}},complete:_.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:A.bind(this),stop:E.bind(this),recover:I.bind(this),message:{deleteOne:g.bind(this),editOne:f.bind(this),swipe:T.bind(this),getPage:M.bind(this)}},text:{complete:j.bind(this)},openai:{completions:{create:J.create.bind(this)},chat:{completions:{create:P.completions.create.bind(this)}},responses:{create:U.create.bind(this)},images:{generate:R.generate.bind(this)}}};ui={};utils={clipboard:{writeText:S.bind(this)}};hybrid={};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:w.bind(this),loadGame:v.bind(this)},ranking:()=>{console.log("ranking")}}}let j=async function(t){return await this.call(O.EVENT.MUJIAN_AI_TEXT_GENERATE,{content:t})},P={completions:{create:async function(t,e,i,n){return await this.call(O.EVENT.MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}}},J={create:async function(t,e,i,n){return await this.call(O.EVENT.MUJIAN_AI_OPENAI_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}},U={create:async function(t,e,i,n){return await this.call(O.EVENT.MUJIAN_AI_OPENAI_RESPONSES_CREATE,{params:t,options:e},{onData:i,signal:n})}},R={generate:async function(t,e,i,n){return await this.call(O.EVENT.MUJIAN_AI_OPENAI_IMAGES_GENERATE,{params:t,options:e},{onData:i,signal:n})}};class G{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new G),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get openapi(){return this._config?.openapi}initPromise=null;async init(){return this.initPromise||(this.initPromise=(async()=>{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,b.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 C.call(this);n&&(this._config=n)}catch(t){b.e("init error",t)}})()),this.initPromise}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:y.bind(this)},settings:{persona:{getActive:N.bind(this)}},complete:_.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:A.bind(this),stop:E.bind(this),recover:I.bind(this),message:{deleteOne:g.bind(this),editOne:f.bind(this),swipe:T.bind(this),getPage:M.bind(this)}},text:{complete:j.bind(this)},openai:{completions:{create:J.create.bind(this)},chat:{completions:{create:P.completions.create.bind(this)}},responses:{create:U.create.bind(this)},images:{generate:R.generate.bind(this)}}};ui={};utils={clipboard:{writeText:S.bind(this)}};hybrid={};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:w.bind(this),loadGame:v.bind(this)},ranking:()=>{console.log("ranking")}}}return i})());
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:()=>L,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_CHAT_V2_COMPLETE="mujian:ai:chat_v2:complete",t.MUJIAN_AI_CHAT_V2_RECOVER="mujian:ai:chat_v2:recover",t.MUJIAN_AI_CHAT_V2_STOP="mujian:ai:chat_v2:stop",t.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE="mujian:ai:chat_v2:message:getPage",t.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE="mujian:ai:chat_v2:renderMessage",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_OPENAI_IMAGES_GENERATE="mujian:ai:openai:images:generate",t.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT="mujian:utils:clipboard:writeText",t.MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL="mujian:hybrid:showCharacterDetail",t.MUJIAN_GET_CONFIG="mujian:getConfig",t);let _=async function(t,e,i){await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{content:t,conversationVersion:e},{onData:i})},m=async function(t){return await this.call(u.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE,t)},p=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{isContinue:!0,conversationVersion:t},{onData:e})},A=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_COMPLETE,{isRegenerate:!0,conversationVersion:t},{onData:e})},E=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_V2_STOP,{conversationVersion:t,assisMsgId:e})},I=async function(t,e,i){return await this.call(u.MUJIAN_AI_CHAT_V2_RECOVER,{conversationVersion:t,assisMsgId:e},{onData:i})},g=async function(){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_GET_ALL)},f=async function(t){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE,{messageId:t})},T=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE,{messageId:t,content:e})},M=async function(t,e){return await this.call(u.MUJIAN_AI_CHAT_MESSAGE_SWIPE,{messageId:t,swipeId:e})};async function y(t,e,i={compatMode:!0}){let n=await this.call(u.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE,{fromCursor:t,pageSize:e});return i.compatMode?{...n,messages:n.messages.map(t=>({...t,swipes:t.swipes.map(t=>"string"==typeof t.content?t.content:t.content.map(t=>{switch(t.type){case"narrative":return t.content;case"character":return`${t.name}: ${t.content}`}}).filter(Boolean).join("\n\n")),content:t.swipes[t.activeSwipeId].content,role:t.isUser?"user":"assistant",sendAt:new Date(1e3*parseInt(t.id.substring(0,8),16))}))}:n}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)};async function w(){return await this.call(u.MUJIAN_GET_CONFIG)}let v=async function(){},b=async function(){},S=async function(t){return await this.call(u.MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL,{characterId:t})};async function O(t){return await this.call(u.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT,t)}let j={i(...t){console.log("[MujianSDK] ",...t)},e(...t){console.error("[MujianSDK] ",...t)}};class P{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new P),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get openapi(){return this._config?.openapi}initPromise=null;async init(){return this.initPromise||(this.initPromise=(async()=>{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,j.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 w.call(this);n&&(this._config=n)}catch(t){j.e("init error",t)}})()),this.initPromise}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:{persona:{getActive:C.bind(this)}},complete:_.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:A.bind(this),stop:E.bind(this),recover:I.bind(this),message:{getAll:g.bind(this),deleteOne:f.bind(this),editOne:T.bind(this),swipe:M.bind(this),getPage:y.bind(this)}},text:{complete:J.bind(this)},openai:{completions:{create:R.create.bind(this)},chat:{completions:{create:U.completions.create.bind(this)}},responses:{create:G.create.bind(this)},images:{generate:H.generate.bind(this)}}};ui={};utils={clipboard:{writeText:O.bind(this)}};hybrid={showCharacterDetail:S.bind(this)};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:v.bind(this),loadGame:b.bind(this)},ranking:()=>{console.log("ranking")}}}let J=async function(t){return await this.call(P.EVENT.MUJIAN_AI_TEXT_GENERATE,{content:t})},U={completions:{create:async function(t,e,i,n){return await this.call(P.EVENT.MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}}},R={create:async function(t,e,i,n){return await this.call(P.EVENT.MUJIAN_AI_OPENAI_COMPLETIONS_CREATE,{params:t,options:e},{onData:i,signal:n})}},G={create:async function(t,e,i,n){return await this.call(P.EVENT.MUJIAN_AI_OPENAI_RESPONSES_CREATE,{params:t,options:e},{onData:i,signal:n})}},H={generate:async function(t,e,i,n){return await this.call(P.EVENT.MUJIAN_AI_OPENAI_IMAGES_GENERATE,{params:t,options:e},{onData:i,signal:n})}};class L{constructor(){}static EVENT=u;static getInstance(){return window.$mujian||(window.$mujian=new L),window.$mujian}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get openapi(){return this._config?.openapi}initPromise=null;async init(){return this.initPromise||(this.initPromise=(async()=>{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,j.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 w.call(this);n&&(this._config=n)}catch(t){j.e("init error",t)}})()),this.initPromise}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:{persona:{getActive:C.bind(this)}},complete:_.bind(this),renderMessage:m.bind(this),continue:p.bind(this),regenerate:A.bind(this),stop:E.bind(this),recover:I.bind(this),message:{getAll:g.bind(this),deleteOne:f.bind(this),editOne:T.bind(this),swipe:M.bind(this),getPage:y.bind(this)}},text:{complete:J.bind(this)},openai:{completions:{create:R.create.bind(this)},chat:{completions:{create:U.completions.create.bind(this)}},responses:{create:G.create.bind(this)},images:{generate:H.generate.bind(this)}}};ui={};utils={clipboard:{writeText:O.bind(this)}};hybrid={showCharacterDetail:S.bind(this)};player={};game={assets:()=>{console.log("assets")},saves:{saveGame:v.bind(this),loadGame:b.bind(this)},ranking:()=>{console.log("ranking")}}}return i})());
package/dist/umd/lite.js CHANGED
@@ -1,2 +1,2 @@
1
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]},d=function(e,t){var i="function"==typeof e[t]?e[t]():e[t];return m.Promise.resolve(i)},l=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}d(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),d=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 l(a))):r("Failed handshake"))},!1);var c=function(){d++,a.child.postMessage({postmate:"handshake",type:n,model:a.model},s),5===d&&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_CHAT_V2_COMPLETE="mujian:ai:chat_v2:complete",e.MUJIAN_AI_CHAT_V2_RECOVER="mujian:ai:chat_v2:recover",e.MUJIAN_AI_CHAT_V2_STOP="mujian:ai:chat_v2:stop",e.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE="mujian:ai:chat_v2:message:getPage",e.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE="mujian:ai:chat_v2:renderMessage",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_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 openapi(){return this._config?.openapi}initPromise=null;async init(){return 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})());
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:()=>p});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]},d=function(e,t){var i="function"==typeof e[t]?e[t]():e[t];return m.Promise.resolve(i)},l=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}d(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),d=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 l(a))):r("Failed handshake"))},!1);var c=function(){d++,a.child.postMessage({postmate:"handshake",type:n,model:a.model},s),5===d&&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_CHAT_V2_COMPLETE="mujian:ai:chat_v2:complete",e.MUJIAN_AI_CHAT_V2_RECOVER="mujian:ai:chat_v2:recover",e.MUJIAN_AI_CHAT_V2_STOP="mujian:ai:chat_v2:stop",e.MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE="mujian:ai:chat_v2:message:getPage",e.MUJIAN_AI_CHAT_V2_RENDER_MESSAGE="mujian:ai:chat_v2:renderMessage",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_OPENAI_IMAGES_GENERATE="mujian:ai:openai:images:generate",e.MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT="mujian:utils:clipboard:writeText",e.MUJIAN_HYBRID_SHOW_CHARACTER_DETAIL="mujian:hybrid:showCharacterDetail",e.MUJIAN_GET_CONFIG="mujian:getConfig",e);let h={i(...e){console.log("[MujianSDK] ",...e)},e(...e){console.error("[MujianSDK] ",...e)}};class _{constructor(){}static EVENT=u;static getInstance(){return window.$mujian_lite||(window.$mujian_lite=new _),window.$mujian_lite}parent=null;ready=!1;get isReady(){return this.ready}pendingRequests=new Map;_config;get openapi(){return this._config?.openapi}initPromise=null;async init(){return 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})})}}_.getInstance().init();let p=_;return i})());