@mujian/js-sdk 0.0.6-beta.61 → 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 +21 -6
- package/dist/umd/index.js +6 -0
- package/dist/umd/react.js +21 -6
- 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
|
@@ -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
|
|
@@ -797,6 +801,7 @@ class MujianSdk {
|
|
|
797
801
|
},
|
|
798
802
|
complete: chat_complete.bind(this),
|
|
799
803
|
applyRegex: applyRegex.bind(this),
|
|
804
|
+
renderMessage: renderMessage.bind(this),
|
|
800
805
|
continue: continueComplete.bind(this),
|
|
801
806
|
regenerate: chat_regenerate.bind(this),
|
|
802
807
|
message: {
|
|
@@ -929,7 +934,7 @@ const MessageItem = (props)=>{
|
|
|
929
934
|
const { data: renderedMessage } = useRequest(async ()=>{
|
|
930
935
|
const { isStreaming } = message;
|
|
931
936
|
if (isStreaming) return message;
|
|
932
|
-
return await mujian.ai.chat.
|
|
937
|
+
return await mujian.ai.chat.renderMessage({
|
|
933
938
|
message,
|
|
934
939
|
depth,
|
|
935
940
|
index
|
|
@@ -1039,7 +1044,8 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
|
|
|
1039
1044
|
swipes: [],
|
|
1040
1045
|
activeSwipeId: 0,
|
|
1041
1046
|
isStreaming: false,
|
|
1042
|
-
sendAt: new Date()
|
|
1047
|
+
sendAt: new Date(),
|
|
1048
|
+
swipeInfo: []
|
|
1043
1049
|
};
|
|
1044
1050
|
const aiMessage = {
|
|
1045
1051
|
id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
|
|
@@ -1050,7 +1056,10 @@ const useChatStreaming = ({ common, setError, setMessages, mujian })=>{
|
|
|
1050
1056
|
],
|
|
1051
1057
|
activeSwipeId: 0,
|
|
1052
1058
|
isStreaming: true,
|
|
1053
|
-
sendAt: new Date()
|
|
1059
|
+
sendAt: new Date(),
|
|
1060
|
+
swipeInfo: [
|
|
1061
|
+
{}
|
|
1062
|
+
]
|
|
1054
1063
|
};
|
|
1055
1064
|
if (regenerate) setMessages((prev)=>{
|
|
1056
1065
|
const newMessages = [
|
|
@@ -1193,7 +1202,10 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
|
|
|
1193
1202
|
const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
|
|
1194
1203
|
return {
|
|
1195
1204
|
cursor: resp.nextCursor,
|
|
1196
|
-
list: resp.messages
|
|
1205
|
+
list: resp.messages.map((m)=>({
|
|
1206
|
+
...m,
|
|
1207
|
+
mjv: m.swipeInfo[m.activeSwipeId]?.mjv
|
|
1208
|
+
})),
|
|
1197
1209
|
noMore: !resp.nextCursor
|
|
1198
1210
|
};
|
|
1199
1211
|
} finally{
|
|
@@ -1305,9 +1317,12 @@ const useChat = ({ body, onError, onFinish, pageSize })=>{
|
|
|
1305
1317
|
abortController?.abort();
|
|
1306
1318
|
};
|
|
1307
1319
|
const setSwipe = async (messageId, swipeId)=>{
|
|
1308
|
-
|
|
1320
|
+
if (swipeId < 0) return;
|
|
1321
|
+
setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
|
|
1309
1322
|
...msg,
|
|
1310
|
-
activeSwipeId: swipeId
|
|
1323
|
+
activeSwipeId: swipeId,
|
|
1324
|
+
content: msg.swipes[swipeId],
|
|
1325
|
+
mjv: msg.swipeInfo[swipeId].mjv
|
|
1311
1326
|
} : msg));
|
|
1312
1327
|
await mujian.ai.chat.message.swipe(messageId, swipeId);
|
|
1313
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
|
@@ -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
|
|
@@ -7769,6 +7773,7 @@ ${content}
|
|
|
7769
7773
|
},
|
|
7770
7774
|
complete: chat_complete.bind(this),
|
|
7771
7775
|
applyRegex: applyRegex.bind(this),
|
|
7776
|
+
renderMessage: renderMessage.bind(this),
|
|
7772
7777
|
continue: continueComplete.bind(this),
|
|
7773
7778
|
regenerate: chat_regenerate.bind(this),
|
|
7774
7779
|
message: {
|
|
@@ -7901,7 +7906,7 @@ ${content}
|
|
|
7901
7906
|
const { data: renderedMessage } = es_useRequest(async ()=>{
|
|
7902
7907
|
const { isStreaming } = message;
|
|
7903
7908
|
if (isStreaming) return message;
|
|
7904
|
-
return await mujian.ai.chat.
|
|
7909
|
+
return await mujian.ai.chat.renderMessage({
|
|
7905
7910
|
message,
|
|
7906
7911
|
depth,
|
|
7907
7912
|
index
|
|
@@ -8505,7 +8510,8 @@ ${content}
|
|
|
8505
8510
|
swipes: [],
|
|
8506
8511
|
activeSwipeId: 0,
|
|
8507
8512
|
isStreaming: false,
|
|
8508
|
-
sendAt: new Date()
|
|
8513
|
+
sendAt: new Date(),
|
|
8514
|
+
swipeInfo: []
|
|
8509
8515
|
};
|
|
8510
8516
|
const aiMessage = {
|
|
8511
8517
|
id: `${NOT_SAVED_MSG_ID_PREFIX}_assistant_${Date.now()}`,
|
|
@@ -8516,7 +8522,10 @@ ${content}
|
|
|
8516
8522
|
],
|
|
8517
8523
|
activeSwipeId: 0,
|
|
8518
8524
|
isStreaming: true,
|
|
8519
|
-
sendAt: new Date()
|
|
8525
|
+
sendAt: new Date(),
|
|
8526
|
+
swipeInfo: [
|
|
8527
|
+
{}
|
|
8528
|
+
]
|
|
8520
8529
|
};
|
|
8521
8530
|
if (regenerate) setMessages((prev)=>{
|
|
8522
8531
|
const newMessages = [
|
|
@@ -8659,7 +8668,10 @@ ${content}
|
|
|
8659
8668
|
const resp = await mujian.ai.chat.message.getPage(current?.cursor, pageSize);
|
|
8660
8669
|
return {
|
|
8661
8670
|
cursor: resp.nextCursor,
|
|
8662
|
-
list: resp.messages
|
|
8671
|
+
list: resp.messages.map((m)=>({
|
|
8672
|
+
...m,
|
|
8673
|
+
mjv: m.swipeInfo[m.activeSwipeId]?.mjv
|
|
8674
|
+
})),
|
|
8663
8675
|
noMore: !resp.nextCursor
|
|
8664
8676
|
};
|
|
8665
8677
|
} finally{
|
|
@@ -8771,9 +8783,12 @@ ${content}
|
|
|
8771
8783
|
abortController?.abort();
|
|
8772
8784
|
};
|
|
8773
8785
|
const setSwipe = async (messageId, swipeId)=>{
|
|
8774
|
-
|
|
8786
|
+
if (swipeId < 0) return;
|
|
8787
|
+
setMessages((prev)=>prev.map((msg)=>msg.id === messageId && swipeId < msg.swipes.length ? {
|
|
8775
8788
|
...msg,
|
|
8776
|
-
activeSwipeId: swipeId
|
|
8789
|
+
activeSwipeId: swipeId,
|
|
8790
|
+
content: msg.swipes[swipeId],
|
|
8791
|
+
mjv: msg.swipeInfo[swipeId].mjv
|
|
8777
8792
|
} : msg));
|
|
8778
8793
|
await mujian.ai.chat.message.swipe(messageId, swipeId);
|
|
8779
8794
|
};
|