@mujian/js-sdk 0.0.6-beta.61 → 0.0.6-beta.63

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.
@@ -20,6 +20,10 @@ export declare enum EVENT {
20
20
  * 对消息应用正则表达式
21
21
  */
22
22
  MUJIAN_AI_CHAT_APPLY_REGEX = "mujian:ai:chat:applyRegex",
23
+ /**
24
+ * 对消息应用正则表达式并渲染模板
25
+ */
26
+ MUJIAN_AI_CHAT_RENDER_MESSAGE = "mujian:ai:chat:renderMessage",
23
27
  /**
24
28
  * 文本补全
25
29
  */
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
4
4
  EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
5
5
  EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
6
6
  EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
7
+ EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
7
8
  EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
8
9
  EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
9
10
  EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
@@ -79,6 +80,9 @@ const chat_complete = async function(message, onData, signal, option = {}) {
79
80
  const applyRegex = async function(props) {
80
81
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
81
82
  };
83
+ const renderMessage = async function(props) {
84
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
85
+ };
82
86
  const continueComplete = async function(onData, signal) {
83
87
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
84
88
  isContinue: true
@@ -206,6 +210,13 @@ class MujianSdk {
206
210
  style.textContent = projectInfo.config.customCss;
207
211
  document.head.appendChild(style);
208
212
  }
213
+ if (projectInfo.config?.customJs) {
214
+ const script = document.createElement("script");
215
+ script.setAttribute('type', "text/javascript");
216
+ script.setAttribute('id', 'mujian-custom-js');
217
+ script.textContent = projectInfo.config.customJs;
218
+ document.head.appendChild(script);
219
+ }
209
220
  } catch (error) {
210
221
  Log.e('init error', error);
211
222
  }
@@ -258,6 +269,7 @@ class MujianSdk {
258
269
  },
259
270
  complete: chat_complete.bind(this),
260
271
  applyRegex: applyRegex.bind(this),
272
+ renderMessage: renderMessage.bind(this),
261
273
  continue: continueComplete.bind(this),
262
274
  regenerate: regenerate.bind(this),
263
275
  message: {
@@ -406,6 +418,13 @@ class src_MujianSdk {
406
418
  style.textContent = projectInfo.config.customCss;
407
419
  document.head.appendChild(style);
408
420
  }
421
+ if (projectInfo.config?.customJs) {
422
+ const script = document.createElement("script");
423
+ script.setAttribute('type', "text/javascript");
424
+ script.setAttribute('id', 'mujian-custom-js');
425
+ script.textContent = projectInfo.config.customJs;
426
+ document.head.appendChild(script);
427
+ }
409
428
  } catch (error) {
410
429
  Log.e('init error', error);
411
430
  }
@@ -458,6 +477,7 @@ class src_MujianSdk {
458
477
  },
459
478
  complete: chat_complete.bind(this),
460
479
  applyRegex: applyRegex.bind(this),
480
+ renderMessage: renderMessage.bind(this),
461
481
  continue: continueComplete.bind(this),
462
482
  regenerate: regenerate.bind(this),
463
483
  message: {
@@ -52,6 +52,11 @@ export declare const applyRegex: (this: MujianSdk, props: {
52
52
  index: number;
53
53
  depth: number;
54
54
  }) => Promise<Message>;
55
+ export declare const renderMessage: (this: MujianSdk, props: {
56
+ message: Message;
57
+ index: number;
58
+ depth: number;
59
+ }) => Promise<Message>;
55
60
  /**
56
61
  * 继续
57
62
  * @param onData 数据
@@ -1,4 +1,4 @@
1
- export { applyRegex, type CompleteOption, complete, continueComplete, type ParsedData, regenerate, } from './chat';
1
+ export { applyRegex, type CompleteOption, complete, continueComplete, type ParsedData, regenerate, renderMessage, } from './chat';
2
2
  export * as message from './message';
3
3
  export * as project from './project';
4
4
  export * as settings from './settings';
@@ -4,6 +4,10 @@ export declare const Role: {
4
4
  readonly System: "system";
5
5
  };
6
6
  export type Role = (typeof Role)[keyof typeof Role];
7
+ type Mjv = {
8
+ value: unknown;
9
+ delta: unknown;
10
+ };
7
11
  export type Message = {
8
12
  id: string;
9
13
  role: Role;
@@ -12,6 +16,10 @@ export type Message = {
12
16
  activeSwipeId: number;
13
17
  sendAt: Date;
14
18
  isStreaming: boolean;
19
+ mjv?: Mjv;
20
+ swipeInfo: Array<{
21
+ mjv?: Mjv;
22
+ }>;
15
23
  };
16
24
  export type RawData = {
17
25
  id: string;
@@ -35,3 +43,4 @@ export type RawData = {
35
43
  question_id: string;
36
44
  reply_id: string;
37
45
  };
46
+ export {};
package/dist/react.js CHANGED
@@ -500,6 +500,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
500
500
  EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
501
501
  EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
502
502
  EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
503
+ EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
503
504
  EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
504
505
  EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
505
506
  EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
@@ -575,6 +576,9 @@ const chat_complete = async function(message, onData, signal, option = {}) {
575
576
  const applyRegex = async function(props) {
576
577
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
577
578
  };
579
+ const renderMessage = async function(props) {
580
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
581
+ };
578
582
  const continueComplete = async function(onData, signal) {
579
583
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
580
584
  isContinue: true
@@ -745,6 +749,13 @@ class MujianSdk {
745
749
  style.textContent = projectInfo.config.customCss;
746
750
  document.head.appendChild(style);
747
751
  }
752
+ if (projectInfo.config?.customJs) {
753
+ const script = document.createElement("script");
754
+ script.setAttribute('type', "text/javascript");
755
+ script.setAttribute('id', 'mujian-custom-js');
756
+ script.textContent = projectInfo.config.customJs;
757
+ document.head.appendChild(script);
758
+ }
748
759
  } catch (error) {
749
760
  Log.e('init error', error);
750
761
  }
@@ -797,6 +808,7 @@ class MujianSdk {
797
808
  },
798
809
  complete: chat_complete.bind(this),
799
810
  applyRegex: applyRegex.bind(this),
811
+ renderMessage: renderMessage.bind(this),
800
812
  continue: continueComplete.bind(this),
801
813
  regenerate: chat_regenerate.bind(this),
802
814
  message: {
@@ -929,7 +941,7 @@ const MessageItem = (props)=>{
929
941
  const { data: renderedMessage } = useRequest(async ()=>{
930
942
  const { isStreaming } = message;
931
943
  if (isStreaming) return message;
932
- return await mujian.ai.chat.applyRegex({
944
+ return await mujian.ai.chat.renderMessage({
933
945
  message,
934
946
  depth,
935
947
  index
@@ -1039,7 +1051,8 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
1039
1051
  swipes: [],
1040
1052
  activeSwipeId: 0,
1041
1053
  isStreaming: false,
1042
- sendAt: new Date()
1054
+ sendAt: new Date(),
1055
+ swipeInfo: []
1043
1056
  };
1044
1057
  const aiMessage = {
1045
1058
  id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
@@ -1050,7 +1063,10 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
1050
1063
  ],
1051
1064
  activeSwipeId: 0,
1052
1065
  isStreaming: true,
1053
- sendAt: new Date()
1066
+ sendAt: new Date(),
1067
+ swipeInfo: [
1068
+ {}
1069
+ ]
1054
1070
  };
1055
1071
  if (regenerate) setMessages((prev)=>{
1056
1072
  const newMessages = [
@@ -1193,7 +1209,10 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
1193
1209
  const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
1194
1210
  return {
1195
1211
  cursor: resp.nextCursor,
1196
- list: resp.messages,
1212
+ list: resp.messages.map((m)=>({
1213
+ ...m,
1214
+ mjv: m.swipeInfo[m.activeSwipeId]?.mjv
1215
+ })),
1197
1216
  noMore: !resp.nextCursor
1198
1217
  };
1199
1218
  } finally{
@@ -1305,9 +1324,12 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
1305
1324
  abortController?.abort();
1306
1325
  };
1307
1326
  const setSwipe = async (messageId, swipeId)=>{
1308
- setMessages((prev)=>prev.map((msg)=>msg.id === messageId ? {
1327
+ if (swipeId < 0) return;
1328
+ setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
1309
1329
  ...msg,
1310
- activeSwipeId: swipeId
1330
+ activeSwipeId: swipeId,
1331
+ content: msg.swipes[swipeId],
1332
+ mjv: msg.swipeInfo[swipeId].mjv
1311
1333
  } : msg));
1312
1334
  await mujian.ai.chat.message.swipe(messageId, swipeId);
1313
1335
  };
@@ -29,6 +29,7 @@ export type ModelInfo = {
29
29
  export type ProjectConfig = {
30
30
  qrConfig?: QuickReplyConfig;
31
31
  customCss?: string;
32
+ customJs?: string;
32
33
  };
33
34
  export type QuickReply = {
34
35
  id: number;
package/dist/umd/index.js CHANGED
@@ -262,6 +262,7 @@
262
262
  EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
263
263
  EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
264
264
  EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
265
+ EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
265
266
  EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
266
267
  EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
267
268
  EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
@@ -337,6 +338,9 @@
337
338
  const applyRegex = async function(props) {
338
339
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
339
340
  };
341
+ const renderMessage = async function(props) {
342
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
343
+ };
340
344
  const continueComplete = async function(onData, signal) {
341
345
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
342
346
  isContinue: true
@@ -464,6 +468,13 @@
464
468
  style.textContent = projectInfo.config.customCss;
465
469
  document.head.appendChild(style);
466
470
  }
471
+ if (projectInfo.config?.customJs) {
472
+ const script = document.createElement("script");
473
+ script.setAttribute('type', "text/javascript");
474
+ script.setAttribute('id', 'mujian-custom-js');
475
+ script.textContent = projectInfo.config.customJs;
476
+ document.head.appendChild(script);
477
+ }
467
478
  } catch (error) {
468
479
  Log.e('init error', error);
469
480
  }
@@ -516,6 +527,7 @@
516
527
  },
517
528
  complete: chat_complete.bind(this),
518
529
  applyRegex: applyRegex.bind(this),
530
+ renderMessage: renderMessage.bind(this),
519
531
  continue: continueComplete.bind(this),
520
532
  regenerate: regenerate.bind(this),
521
533
  message: {
@@ -664,6 +676,13 @@
664
676
  style.textContent = projectInfo.config.customCss;
665
677
  document.head.appendChild(style);
666
678
  }
679
+ if (projectInfo.config?.customJs) {
680
+ const script = document.createElement("script");
681
+ script.setAttribute('type', "text/javascript");
682
+ script.setAttribute('id', 'mujian-custom-js');
683
+ script.textContent = projectInfo.config.customJs;
684
+ document.head.appendChild(script);
685
+ }
667
686
  } catch (error) {
668
687
  Log.e('init error', error);
669
688
  }
@@ -716,6 +735,7 @@
716
735
  },
717
736
  complete: chat_complete.bind(this),
718
737
  applyRegex: applyRegex.bind(this),
738
+ renderMessage: renderMessage.bind(this),
719
739
  continue: continueComplete.bind(this),
720
740
  regenerate: regenerate.bind(this),
721
741
  message: {
package/dist/umd/react.js CHANGED
@@ -7472,6 +7472,7 @@ ${content}
7472
7472
  EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
7473
7473
  EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
7474
7474
  EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
7475
+ EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
7475
7476
  EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
7476
7477
  EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
7477
7478
  EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
@@ -7547,6 +7548,9 @@ ${content}
7547
7548
  const applyRegex = async function(props) {
7548
7549
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
7549
7550
  };
7551
+ const renderMessage = async function(props) {
7552
+ return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
7553
+ };
7550
7554
  const continueComplete = async function(onData, signal) {
7551
7555
  return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
7552
7556
  isContinue: true
@@ -7717,6 +7721,13 @@ ${content}
7717
7721
  style.textContent = projectInfo.config.customCss;
7718
7722
  document.head.appendChild(style);
7719
7723
  }
7724
+ if (projectInfo.config?.customJs) {
7725
+ const script = document.createElement("script");
7726
+ script.setAttribute('type', "text/javascript");
7727
+ script.setAttribute('id', 'mujian-custom-js');
7728
+ script.textContent = projectInfo.config.customJs;
7729
+ document.head.appendChild(script);
7730
+ }
7720
7731
  } catch (error) {
7721
7732
  Log.e('init error', error);
7722
7733
  }
@@ -7769,6 +7780,7 @@ ${content}
7769
7780
  },
7770
7781
  complete: chat_complete.bind(this),
7771
7782
  applyRegex: applyRegex.bind(this),
7783
+ renderMessage: renderMessage.bind(this),
7772
7784
  continue: continueComplete.bind(this),
7773
7785
  regenerate: chat_regenerate.bind(this),
7774
7786
  message: {
@@ -7901,7 +7913,7 @@ ${content}
7901
7913
  const { data: renderedMessage } = es_useRequest(async ()=>{
7902
7914
  const { isStreaming } = message;
7903
7915
  if (isStreaming) return message;
7904
- return await mujian.ai.chat.applyRegex({
7916
+ return await mujian.ai.chat.renderMessage({
7905
7917
  message,
7906
7918
  depth,
7907
7919
  index
@@ -8505,7 +8517,8 @@ ${content}
8505
8517
  swipes: [],
8506
8518
  activeSwipeId: 0,
8507
8519
  isStreaming: false,
8508
- sendAt: new Date()
8520
+ sendAt: new Date(),
8521
+ swipeInfo: []
8509
8522
  };
8510
8523
  const aiMessage = {
8511
8524
  id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
@@ -8516,7 +8529,10 @@ ${content}
8516
8529
  ],
8517
8530
  activeSwipeId: 0,
8518
8531
  isStreaming: true,
8519
- sendAt: new Date()
8532
+ sendAt: new Date(),
8533
+ swipeInfo: [
8534
+ {}
8535
+ ]
8520
8536
  };
8521
8537
  if (regenerate) setMessages((prev)=>{
8522
8538
  const newMessages = [
@@ -8659,7 +8675,10 @@ ${content}
8659
8675
  const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
8660
8676
  return {
8661
8677
  cursor: resp.nextCursor,
8662
- list: resp.messages,
8678
+ list: resp.messages.map((m)=>({
8679
+ ...m,
8680
+ mjv: m.swipeInfo[m.activeSwipeId]?.mjv
8681
+ })),
8663
8682
  noMore: !resp.nextCursor
8664
8683
  };
8665
8684
  } finally{
@@ -8771,9 +8790,12 @@ ${content}
8771
8790
  abortController?.abort();
8772
8791
  };
8773
8792
  const setSwipe = async (messageId, swipeId)=>{
8774
- setMessages((prev)=>prev.map((msg)=>msg.id === messageId ? {
8793
+ if (swipeId < 0) return;
8794
+ setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
8775
8795
  ...msg,
8776
- activeSwipeId: swipeId
8796
+ activeSwipeId: swipeId,
8797
+ content: msg.swipes[swipeId],
8798
+ mjv: msg.swipeInfo[swipeId].mjv
8777
8799
  } : msg));
8778
8800
  await mujian.ai.chat.message.swipe(messageId, swipeId);
8779
8801
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mujian/js-sdk",
3
- "version": "0.0.6-beta.61",
3
+ "version": "0.0.6-beta.63",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {