@mujian/js-sdk 0.0.6-beta.60 → 0.0.6-beta.62
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 +4 -0
- package/dist/index.js +6 -0
- package/dist/modules/ai/chat/chat.d.ts +5 -0
- package/dist/modules/ai/chat/index.d.ts +1 -1
- package/dist/react/chat/useChat/message.d.ts +9 -0
- package/dist/react.js +27 -7
- package/dist/umd/index.js +6 -0
- package/dist/umd/react.js +27 -7
- package/package.json +1 -1
package/dist/events/index.d.ts
CHANGED
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
|
|
@@ -258,6 +262,7 @@ class MujianSdk {
|
|
|
258
262
|
},
|
|
259
263
|
complete: chat_complete.bind(this),
|
|
260
264
|
applyRegex: applyRegex.bind(this),
|
|
265
|
+
renderMessage: renderMessage.bind(this),
|
|
261
266
|
continue: continueComplete.bind(this),
|
|
262
267
|
regenerate: regenerate.bind(this),
|
|
263
268
|
message: {
|
|
@@ -458,6 +463,7 @@ class src_MujianSdk {
|
|
|
458
463
|
},
|
|
459
464
|
complete: chat_complete.bind(this),
|
|
460
465
|
applyRegex: applyRegex.bind(this),
|
|
466
|
+
renderMessage: renderMessage.bind(this),
|
|
461
467
|
continue: continueComplete.bind(this),
|
|
462
468
|
regenerate: regenerate.bind(this),
|
|
463
469
|
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
|
@@ -463,9 +463,14 @@ const MdRendererBase = ({ content, unsafe = false })=>{
|
|
|
463
463
|
iframeIdList.forEach((id)=>{
|
|
464
464
|
const iframe = containerRef.current?.querySelector('#MJ-iframe-' + id);
|
|
465
465
|
if (!iframe) return;
|
|
466
|
-
|
|
466
|
+
const removeSpin = ()=>{
|
|
467
467
|
const spinElement = iframe.parentElement?.querySelector('#MJ-spin-' + id);
|
|
468
468
|
if (spinElement) spinElement.remove();
|
|
469
|
+
};
|
|
470
|
+
const timeout = setTimeout(removeSpin, 5000);
|
|
471
|
+
iframe.addEventListener('load', ()=>{
|
|
472
|
+
clearTimeout(timeout);
|
|
473
|
+
removeSpin();
|
|
469
474
|
});
|
|
470
475
|
});
|
|
471
476
|
return ()=>{
|
|
@@ -495,6 +500,7 @@ var events_EVENT = /*#__PURE__*/ function(EVENT) {
|
|
|
495
500
|
EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
|
|
496
501
|
EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
|
|
497
502
|
EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
|
|
503
|
+
EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
|
|
498
504
|
EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
|
|
499
505
|
EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
|
|
500
506
|
EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
|
|
@@ -570,6 +576,9 @@ const chat_complete = async function(message, onData, signal, option = {}) {
|
|
|
570
576
|
const applyRegex = async function(props) {
|
|
571
577
|
return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
|
|
572
578
|
};
|
|
579
|
+
const renderMessage = async function(props) {
|
|
580
|
+
return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
|
|
581
|
+
};
|
|
573
582
|
const continueComplete = async function(onData, signal) {
|
|
574
583
|
return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
|
|
575
584
|
isContinue: true
|
|
@@ -792,6 +801,7 @@ class MujianSdk {
|
|
|
792
801
|
},
|
|
793
802
|
complete: chat_complete.bind(this),
|
|
794
803
|
applyRegex: applyRegex.bind(this),
|
|
804
|
+
renderMessage: renderMessage.bind(this),
|
|
795
805
|
continue: continueComplete.bind(this),
|
|
796
806
|
regenerate: chat_regenerate.bind(this),
|
|
797
807
|
message: {
|
|
@@ -924,7 +934,7 @@ const MessageItem = (props)=>{
|
|
|
924
934
|
const { data: renderedMessage } = useRequest(async ()=>{
|
|
925
935
|
const { isStreaming } = message;
|
|
926
936
|
if (isStreaming) return message;
|
|
927
|
-
return await mujian.ai.chat.
|
|
937
|
+
return await mujian.ai.chat.renderMessage({
|
|
928
938
|
message,
|
|
929
939
|
depth,
|
|
930
940
|
index
|
|
@@ -1034,7 +1044,8 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
|
|
|
1034
1044
|
swipes: [],
|
|
1035
1045
|
activeSwipeId: 0,
|
|
1036
1046
|
isStreaming: false,
|
|
1037
|
-
sendAt: new Date()
|
|
1047
|
+
sendAt: new Date(),
|
|
1048
|
+
swipeInfo: []
|
|
1038
1049
|
};
|
|
1039
1050
|
const aiMessage = {
|
|
1040
1051
|
id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
|
|
@@ -1045,7 +1056,10 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
|
|
|
1045
1056
|
],
|
|
1046
1057
|
activeSwipeId: 0,
|
|
1047
1058
|
isStreaming: true,
|
|
1048
|
-
sendAt: new Date()
|
|
1059
|
+
sendAt: new Date(),
|
|
1060
|
+
swipeInfo: [
|
|
1061
|
+
{}
|
|
1062
|
+
]
|
|
1049
1063
|
};
|
|
1050
1064
|
if (regenerate) setMessages((prev)=>{
|
|
1051
1065
|
const newMessages = [
|
|
@@ -1188,7 +1202,10 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
|
|
|
1188
1202
|
const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
|
|
1189
1203
|
return {
|
|
1190
1204
|
cursor: resp.nextCursor,
|
|
1191
|
-
list: resp.messages
|
|
1205
|
+
list: resp.messages.map((m)=>({
|
|
1206
|
+
...m,
|
|
1207
|
+
mjv: m.swipeInfo[m.activeSwipeId]?.mjv
|
|
1208
|
+
})),
|
|
1192
1209
|
noMore: !resp.nextCursor
|
|
1193
1210
|
};
|
|
1194
1211
|
} finally{
|
|
@@ -1300,9 +1317,12 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
|
|
|
1300
1317
|
abortController?.abort();
|
|
1301
1318
|
};
|
|
1302
1319
|
const setSwipe = async (messageId, swipeId)=>{
|
|
1303
|
-
|
|
1320
|
+
if (swipeId < 0) return;
|
|
1321
|
+
setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
|
|
1304
1322
|
...msg,
|
|
1305
|
-
activeSwipeId: swipeId
|
|
1323
|
+
activeSwipeId: swipeId,
|
|
1324
|
+
content: msg.swipes[swipeId],
|
|
1325
|
+
mjv: msg.swipeInfo[swipeId].mjv
|
|
1306
1326
|
} : msg));
|
|
1307
1327
|
await mujian.ai.chat.message.swipe(messageId, swipeId);
|
|
1308
1328
|
};
|
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
|
|
@@ -516,6 +520,7 @@
|
|
|
516
520
|
},
|
|
517
521
|
complete: chat_complete.bind(this),
|
|
518
522
|
applyRegex: applyRegex.bind(this),
|
|
523
|
+
renderMessage: renderMessage.bind(this),
|
|
519
524
|
continue: continueComplete.bind(this),
|
|
520
525
|
regenerate: regenerate.bind(this),
|
|
521
526
|
message: {
|
|
@@ -716,6 +721,7 @@
|
|
|
716
721
|
},
|
|
717
722
|
complete: chat_complete.bind(this),
|
|
718
723
|
applyRegex: applyRegex.bind(this),
|
|
724
|
+
renderMessage: renderMessage.bind(this),
|
|
719
725
|
continue: continueComplete.bind(this),
|
|
720
726
|
regenerate: regenerate.bind(this),
|
|
721
727
|
message: {
|
package/dist/umd/react.js
CHANGED
|
@@ -7212,9 +7212,14 @@ ${content}
|
|
|
7212
7212
|
iframeIdList.forEach((id)=>{
|
|
7213
7213
|
const iframe = containerRef.current?.querySelector('#MJ-iframe-' + id);
|
|
7214
7214
|
if (!iframe) return;
|
|
7215
|
-
|
|
7215
|
+
const removeSpin = ()=>{
|
|
7216
7216
|
const spinElement = iframe.parentElement?.querySelector('#MJ-spin-' + id);
|
|
7217
7217
|
if (spinElement) spinElement.remove();
|
|
7218
|
+
};
|
|
7219
|
+
const timeout = setTimeout(removeSpin, 5000);
|
|
7220
|
+
iframe.addEventListener('load', ()=>{
|
|
7221
|
+
clearTimeout(timeout);
|
|
7222
|
+
removeSpin();
|
|
7218
7223
|
});
|
|
7219
7224
|
});
|
|
7220
7225
|
return ()=>{
|
|
@@ -7467,6 +7472,7 @@ ${content}
|
|
|
7467
7472
|
EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
|
|
7468
7473
|
EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
|
|
7469
7474
|
EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
|
|
7475
|
+
EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
|
|
7470
7476
|
EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
|
|
7471
7477
|
EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
|
|
7472
7478
|
EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
|
|
@@ -7542,6 +7548,9 @@ ${content}
|
|
|
7542
7548
|
const applyRegex = async function(props) {
|
|
7543
7549
|
return await this.call(events_EVENT.MUJIAN_AI_CHAT_APPLY_REGEX, props);
|
|
7544
7550
|
};
|
|
7551
|
+
const renderMessage = async function(props) {
|
|
7552
|
+
return await this.call(events_EVENT.MUJIAN_AI_CHAT_RENDER_MESSAGE, props);
|
|
7553
|
+
};
|
|
7545
7554
|
const continueComplete = async function(onData, signal) {
|
|
7546
7555
|
return await this.call(events_EVENT.MUJIAN_AI_CHAT_COMPLETE, {
|
|
7547
7556
|
isContinue: true
|
|
@@ -7764,6 +7773,7 @@ ${content}
|
|
|
7764
7773
|
},
|
|
7765
7774
|
complete: chat_complete.bind(this),
|
|
7766
7775
|
applyRegex: applyRegex.bind(this),
|
|
7776
|
+
renderMessage: renderMessage.bind(this),
|
|
7767
7777
|
continue: continueComplete.bind(this),
|
|
7768
7778
|
regenerate: chat_regenerate.bind(this),
|
|
7769
7779
|
message: {
|
|
@@ -7896,7 +7906,7 @@ ${content}
|
|
|
7896
7906
|
const { data: renderedMessage } = es_useRequest(async ()=>{
|
|
7897
7907
|
const { isStreaming } = message;
|
|
7898
7908
|
if (isStreaming) return message;
|
|
7899
|
-
return await mujian.ai.chat.
|
|
7909
|
+
return await mujian.ai.chat.renderMessage({
|
|
7900
7910
|
message,
|
|
7901
7911
|
depth,
|
|
7902
7912
|
index
|
|
@@ -8500,7 +8510,8 @@ ${content}
|
|
|
8500
8510
|
swipes: [],
|
|
8501
8511
|
activeSwipeId: 0,
|
|
8502
8512
|
isStreaming: false,
|
|
8503
|
-
sendAt: new Date()
|
|
8513
|
+
sendAt: new Date(),
|
|
8514
|
+
swipeInfo: []
|
|
8504
8515
|
};
|
|
8505
8516
|
const aiMessage = {
|
|
8506
8517
|
id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
|
|
@@ -8511,7 +8522,10 @@ ${content}
|
|
|
8511
8522
|
],
|
|
8512
8523
|
activeSwipeId: 0,
|
|
8513
8524
|
isStreaming: true,
|
|
8514
|
-
sendAt: new Date()
|
|
8525
|
+
sendAt: new Date(),
|
|
8526
|
+
swipeInfo: [
|
|
8527
|
+
{}
|
|
8528
|
+
]
|
|
8515
8529
|
};
|
|
8516
8530
|
if (regenerate) setMessages((prev)=>{
|
|
8517
8531
|
const newMessages = [
|
|
@@ -8654,7 +8668,10 @@ ${content}
|
|
|
8654
8668
|
const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
|
|
8655
8669
|
return {
|
|
8656
8670
|
cursor: resp.nextCursor,
|
|
8657
|
-
list: resp.messages
|
|
8671
|
+
list: resp.messages.map((m)=>({
|
|
8672
|
+
...m,
|
|
8673
|
+
mjv: m.swipeInfo[m.activeSwipeId]?.mjv
|
|
8674
|
+
})),
|
|
8658
8675
|
noMore: !resp.nextCursor
|
|
8659
8676
|
};
|
|
8660
8677
|
} finally{
|
|
@@ -8766,9 +8783,12 @@ ${content}
|
|
|
8766
8783
|
abortController?.abort();
|
|
8767
8784
|
};
|
|
8768
8785
|
const setSwipe = async (messageId, swipeId)=>{
|
|
8769
|
-
|
|
8786
|
+
if (swipeId < 0) return;
|
|
8787
|
+
setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
|
|
8770
8788
|
...msg,
|
|
8771
|
-
activeSwipeId: swipeId
|
|
8789
|
+
activeSwipeId: swipeId,
|
|
8790
|
+
content: msg.swipes[swipeId],
|
|
8791
|
+
mjv: msg.swipeInfo[swipeId].mjv
|
|
8772
8792
|
} : msg));
|
|
8773
8793
|
await mujian.ai.chat.message.swipe(messageId, swipeId);
|
|
8774
8794
|
};
|