@mujian/js-sdk 0.0.6-beta.mjv.68 → 0.1.0-beta.0
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 +25 -5
- package/dist/index.d.ts +41 -2
- package/dist/index.js +143 -184
- package/dist/lite.d.ts +73 -0
- package/dist/lite.js +124 -0
- package/dist/modules/ai/chat/chat.d.ts +18 -26
- package/dist/modules/ai/chat/index.d.ts +1 -1
- package/dist/modules/ai/chat/message/index.d.ts +7 -16
- package/dist/modules/ai/chat/settings/index.d.ts +1 -2
- package/dist/modules/ai/chat/settings/persona.d.ts +0 -8
- package/dist/modules/ai/openai/chat.d.ts +0 -3
- package/dist/modules/ai/openai/completions.d.ts +0 -2
- package/dist/modules/ai/openai/images.d.ts +0 -2
- package/dist/modules/ai/openai/responses.d.ts +0 -2
- package/dist/modules/config.d.ts +17 -0
- package/dist/react/chat/useChat/index.d.ts +27 -5
- package/dist/react/chat/useChat/inner/chatStreaming.d.ts +8 -4
- package/dist/react/chat/useChat/inner/stream.d.ts +25 -2
- package/dist/react/chat/useChat/message.d.ts +27 -38
- package/dist/react/components/MdRenderer/index.d.ts +3 -2
- package/dist/react/components/MujianProvider/index.d.ts +4 -0
- package/dist/react/components/Thread/MessageItem.d.ts +6 -0
- package/dist/react/components/index.d.ts +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/mjEngine/index.d.ts +48 -0
- package/dist/react.js +446 -343
- package/dist/types/index.d.ts +1 -0
- package/dist/umd/index.js +1 -791
- package/dist/umd/lite.js +2 -0
- package/dist/umd/lite.js.LICENSE.txt +7 -0
- package/dist/umd/react.css +1 -343
- package/dist/umd/react.js +95 -8807
- package/dist/umd/react.js.LICENSE.txt +1 -1
- package/dist/utils/is-network-error.d.ts +1 -0
- package/package.json +14 -6
- package/dist/modules/ai/chat/settings/model.d.ts +0 -24
package/dist/lite.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import postmate from "postmate";
|
|
2
|
+
var events_EVENT = /*#__PURE__*/ function(EVENT) {
|
|
3
|
+
EVENT["MUJIAN_INIT"] = "mujian:init";
|
|
4
|
+
EVENT["MUJIAN_AI_CHAT_STOP"] = "mujian:ai:chat:stop";
|
|
5
|
+
EVENT["MUJIAN_AI_CHAT_COMPLETE"] = "mujian:ai:chat:complete";
|
|
6
|
+
EVENT["MUJIAN_AI_CHAT_APPLY_REGEX"] = "mujian:ai:chat:applyRegex";
|
|
7
|
+
EVENT["MUJIAN_AI_CHAT_RENDER_MESSAGE"] = "mujian:ai:chat:renderMessage";
|
|
8
|
+
EVENT["MUJIAN_AI_TEXT_GENERATE"] = "mujian:ai:text:generate";
|
|
9
|
+
EVENT["MUJIAN_AI_OPENAI_COMPLETIONS_CREATE"] = "mujian:ai:openai:completions:create";
|
|
10
|
+
EVENT["MUJIAN_AI_OPENAI_CHAT_COMPLETIONS_CREATE"] = "mujian:ai:openai:chat:completions:create";
|
|
11
|
+
EVENT["MUJIAN_AI_OPENAI_RESPONSES_CREATE"] = "mujian:ai:openai:responses:create";
|
|
12
|
+
EVENT["MUJIAN_AI_CHAT_MESSAGE_GET_ALL"] = "mujian:ai:chat:message:getAll";
|
|
13
|
+
EVENT["MUJIAN_AI_CHAT_MESSAGE_GET_PAGE"] = "mujian:ai:chat:message:getPage";
|
|
14
|
+
EVENT["MUJIAN_AI_CHAT_PROJECT_GET_INFO"] = "mujian:ai:chat:project:getInfo";
|
|
15
|
+
EVENT["MUJIAN_AI_CHAT_V2_COMPLETE"] = "mujian:ai:chat_v2:complete";
|
|
16
|
+
EVENT["MUJIAN_AI_CHAT_V2_RECOVER"] = "mujian:ai:chat_v2:recover";
|
|
17
|
+
EVENT["MUJIAN_AI_CHAT_V2_STOP"] = "mujian:ai:chat_v2:stop";
|
|
18
|
+
EVENT["MUJIAN_AI_CHAT_V2_MESSAGE_GET_PAGE"] = "mujian:ai:chat_v2:message:getPage";
|
|
19
|
+
EVENT["MUJIAN_AI_CHAT_V2_RENDER_MESSAGE"] = "mujian:ai:chat_v2:renderMessage";
|
|
20
|
+
EVENT["MUJIAN_AI_SETTINGS_PERSONA_GET_ACTIVE"] = "mujian:ai:settings:persona:getActive";
|
|
21
|
+
EVENT["MUJIAN_AI_SETTINGS_PERSONA_SET_ACTIVE"] = "mujian:ai:settings:persona:setActive";
|
|
22
|
+
EVENT["MUJIAN_AI_SETTINGS_MODEL_GET_ALL"] = "mujian:ai:settings:model:getAll";
|
|
23
|
+
EVENT["MUJIAN_AI_SETTINGS_MODEL_SET_ACTIVE"] = "mujian:ai:settings:model:setActive";
|
|
24
|
+
EVENT["MUJIAN_AI_SETTINGS_MODEL_GET_ACTIVE"] = "mujian:ai:settings:model:getActive";
|
|
25
|
+
EVENT["MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE"] = "mujian:ai:chat:message:deleteOne";
|
|
26
|
+
EVENT["MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE"] = "mujian:ai:chat:message:editOne";
|
|
27
|
+
EVENT["MUJIAN_AI_CHAT_MESSAGE_SWIPE"] = "mujian:ai:chat:message:swipe";
|
|
28
|
+
EVENT["MUJIAN_AI_OPENAI_IMAGES_GENERATE"] = "mujian:ai:openai:images:generate";
|
|
29
|
+
EVENT["MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT"] = "mujian:utils:clipboard:writeText";
|
|
30
|
+
EVENT["MUJIAN_GET_CONFIG"] = "mujian:getConfig";
|
|
31
|
+
return EVENT;
|
|
32
|
+
}({});
|
|
33
|
+
const Log = {
|
|
34
|
+
i (...msg) {
|
|
35
|
+
console.log('[MujianSDK] ', ...msg);
|
|
36
|
+
},
|
|
37
|
+
e (...msg) {
|
|
38
|
+
console.error('[MujianSDK] ', ...msg);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
class MujianSdkLite {
|
|
42
|
+
constructor(){}
|
|
43
|
+
static EVENT = events_EVENT;
|
|
44
|
+
static getInstance() {
|
|
45
|
+
if (!window.$mujian_lite) window.$mujian_lite = new MujianSdkLite();
|
|
46
|
+
return window.$mujian_lite;
|
|
47
|
+
}
|
|
48
|
+
parent = null;
|
|
49
|
+
ready = false;
|
|
50
|
+
get isReady() {
|
|
51
|
+
return this.ready;
|
|
52
|
+
}
|
|
53
|
+
pendingRequests = new Map();
|
|
54
|
+
_config;
|
|
55
|
+
get openapi() {
|
|
56
|
+
return this._config?.openapi;
|
|
57
|
+
}
|
|
58
|
+
initPromise = null;
|
|
59
|
+
async init() {
|
|
60
|
+
if (this.initPromise) return this.initPromise;
|
|
61
|
+
this.initPromise = (async ()=>{
|
|
62
|
+
const handshake = new postmate.Model({
|
|
63
|
+
reply: ({ id, complete, data, error })=>{
|
|
64
|
+
const call = this.pendingRequests.get(id);
|
|
65
|
+
if (!call) return;
|
|
66
|
+
if (error) {
|
|
67
|
+
call.reject(error);
|
|
68
|
+
this.pendingRequests.delete(id);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
call.onData?.(data);
|
|
72
|
+
if (complete) {
|
|
73
|
+
call.onComplete?.();
|
|
74
|
+
call.resolve(data);
|
|
75
|
+
this.pendingRequests.delete(id);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
const parent = await handshake;
|
|
81
|
+
this.parent = parent;
|
|
82
|
+
this.ready = true;
|
|
83
|
+
Log.i('mujian sdk lite client init');
|
|
84
|
+
await this.call(events_EVENT.MUJIAN_INIT);
|
|
85
|
+
this._config = await this.call(events_EVENT.MUJIAN_GET_CONFIG);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
Log.e('init error', error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
return this.initPromise;
|
|
92
|
+
}
|
|
93
|
+
ensureReady() {
|
|
94
|
+
if (!this.ready) throw new Error('MujianLite is not initialized');
|
|
95
|
+
}
|
|
96
|
+
emit(event, data) {
|
|
97
|
+
this.ensureReady();
|
|
98
|
+
this.parent?.emit(event, data);
|
|
99
|
+
}
|
|
100
|
+
nextCallId = 0;
|
|
101
|
+
getCallId() {
|
|
102
|
+
const id = this.nextCallId;
|
|
103
|
+
this.nextCallId += 1;
|
|
104
|
+
return `lite_${id}`;
|
|
105
|
+
}
|
|
106
|
+
async call(event, data, controller) {
|
|
107
|
+
this.ensureReady();
|
|
108
|
+
const callId = this.getCallId();
|
|
109
|
+
return new Promise((resolve, reject)=>{
|
|
110
|
+
this.pendingRequests.set(callId, {
|
|
111
|
+
resolve,
|
|
112
|
+
reject,
|
|
113
|
+
...controller
|
|
114
|
+
});
|
|
115
|
+
this.emit(event, {
|
|
116
|
+
id: callId,
|
|
117
|
+
data
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
MujianSdkLite.getInstance().init();
|
|
123
|
+
const lite = MujianSdkLite;
|
|
124
|
+
export { events_EVENT as EVENT, lite as default };
|
|
@@ -17,13 +17,6 @@ export type ParsedData = {
|
|
|
17
17
|
/** AI返回消息的ID */
|
|
18
18
|
replyId?: string;
|
|
19
19
|
};
|
|
20
|
-
/**
|
|
21
|
-
* 对话补全配置
|
|
22
|
-
*/
|
|
23
|
-
export type CompleteOption = {
|
|
24
|
-
/** 给onData传递的数据是否是解析后的,推荐true */
|
|
25
|
-
parseContent?: boolean;
|
|
26
|
-
};
|
|
27
20
|
/**
|
|
28
21
|
* 对话补全
|
|
29
22
|
* @returns {Promise<string>} 返回值
|
|
@@ -34,24 +27,11 @@ this: MujianSdk,
|
|
|
34
27
|
/**
|
|
35
28
|
* 消息
|
|
36
29
|
*/
|
|
37
|
-
message: string,
|
|
30
|
+
message: string, conversationVersion: number,
|
|
38
31
|
/**
|
|
39
32
|
* 数据生成时的回调
|
|
40
33
|
*/
|
|
41
|
-
onData: (data: string
|
|
42
|
-
/**
|
|
43
|
-
* 停止生成的信号
|
|
44
|
-
*/
|
|
45
|
-
signal?: AbortSignal | undefined,
|
|
46
|
-
/**
|
|
47
|
-
* 对话补全配置
|
|
48
|
-
*/
|
|
49
|
-
option?: CompleteOption | undefined) => Promise<void>;
|
|
50
|
-
export declare const applyRegex: (this: MujianSdk, props: {
|
|
51
|
-
message: Message;
|
|
52
|
-
index: number;
|
|
53
|
-
depth: number;
|
|
54
|
-
}) => Promise<Message>;
|
|
34
|
+
onData: (data: string) => void) => Promise<void>;
|
|
55
35
|
export declare const renderMessage: (this: MujianSdk, props: {
|
|
56
36
|
message: Message;
|
|
57
37
|
index: number;
|
|
@@ -60,18 +40,30 @@ export declare const renderMessage: (this: MujianSdk, props: {
|
|
|
60
40
|
/**
|
|
61
41
|
* 继续
|
|
62
42
|
* @param onData 数据
|
|
63
|
-
* @param signal 信号
|
|
64
43
|
* @returns
|
|
65
44
|
*/
|
|
66
45
|
export declare const continueComplete: (
|
|
67
46
|
/** @hidden */
|
|
68
|
-
this: MujianSdk, onData: (data: string) => void
|
|
47
|
+
this: MujianSdk, conversationVersion: number, onData: (data: string) => void) => Promise<string>;
|
|
69
48
|
/**
|
|
70
49
|
* 重新生成
|
|
71
50
|
* @param onData 数据
|
|
72
|
-
* @param signal 信号
|
|
73
51
|
* @returns
|
|
74
52
|
*/
|
|
75
53
|
export declare const regenerate: (
|
|
76
54
|
/** @hidden */
|
|
77
|
-
this: MujianSdk, onData: (data: string) => void
|
|
55
|
+
this: MujianSdk, conversationVersion: number, onData: (data: string) => void) => Promise<string>;
|
|
56
|
+
/**
|
|
57
|
+
* 停止生成
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare const stop: (
|
|
61
|
+
/** @hidden */
|
|
62
|
+
this: MujianSdk, conversationVersion: number, assisMsgId: string) => Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* 恢复生成
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
export declare const recover: (
|
|
68
|
+
/** @hidden */
|
|
69
|
+
this: MujianSdk, conversationVersion: number, assisMsgId: string, onData: (data: string) => void) => Promise<string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { complete, continueComplete, type ParsedData, recover, regenerate, renderMessage, stop, } from './chat';
|
|
2
2
|
export * as message from './message';
|
|
3
3
|
export * as project from './project';
|
|
4
4
|
export * as settings from './settings';
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { MujianSdk } from '../../../../index.ts';
|
|
2
2
|
import type { Message } from '../../../../react/chat/useChat/message';
|
|
3
3
|
import { Cursor } from '../../../../types';
|
|
4
|
-
/**
|
|
5
|
-
* 获取消息列表
|
|
6
|
-
* @returns 消息当前列表
|
|
7
|
-
*/
|
|
8
|
-
export declare const getAll: (
|
|
9
|
-
/** @hidden */
|
|
10
|
-
this: MujianSdk) => Promise<Message[]>;
|
|
11
4
|
/**
|
|
12
5
|
* 删除消息
|
|
13
6
|
* @param messageId 消息ID
|
|
@@ -34,14 +27,12 @@ this: MujianSdk, messageId: string, content: string) => Promise<unknown>;
|
|
|
34
27
|
export declare const messageSwipe: (
|
|
35
28
|
/** @hidden */
|
|
36
29
|
this: MujianSdk, messageId: string, swipeId: number) => Promise<unknown>;
|
|
37
|
-
/**
|
|
38
|
-
* 获取消息提示词
|
|
39
|
-
* @param messageId 消息ID
|
|
40
|
-
* @returns
|
|
41
|
-
*/
|
|
42
|
-
export declare const getPrompt: (
|
|
43
|
-
/** @hidden */
|
|
44
|
-
this: MujianSdk, messageId: string) => Promise<unknown>;
|
|
45
30
|
export declare function getPage(
|
|
46
31
|
/** @hidden */
|
|
47
|
-
this: MujianSdk, fromCursor: Cursor, pageSize: number): Promise<
|
|
32
|
+
this: MujianSdk, fromCursor: Cursor | undefined, pageSize: number): Promise<{
|
|
33
|
+
/** 分页游标,若为空则表示无下一页 */
|
|
34
|
+
nextCursor?: Cursor;
|
|
35
|
+
messages: Array<Message>;
|
|
36
|
+
total?: number;
|
|
37
|
+
conversationVersion: number;
|
|
38
|
+
}>;
|
|
@@ -7,11 +7,3 @@ import type { PersonaInfo } from '../../../../types';
|
|
|
7
7
|
export declare const getActive: (
|
|
8
8
|
/** @hidden */
|
|
9
9
|
this: MujianSdk) => Promise<PersonaInfo>;
|
|
10
|
-
/**
|
|
11
|
-
* 设置当前激活的个人设置
|
|
12
|
-
* @param personaId 个人设置ID
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
export declare const setActive: (
|
|
16
|
-
/** @hidden */
|
|
17
|
-
this: MujianSdk, personaId: string) => Promise<void>;
|
|
@@ -2,18 +2,15 @@ import { MujianSdk } from '../../../index';
|
|
|
2
2
|
import type OpenAI from 'openai';
|
|
3
3
|
/**
|
|
4
4
|
* @namespace openai.chat
|
|
5
|
-
* @description OpenAI 聊天补全
|
|
6
5
|
*/
|
|
7
6
|
export declare const chat: {
|
|
8
7
|
/**
|
|
9
8
|
* @namespace openai.chat.completions
|
|
10
|
-
* @description OpenAI 聊天补全
|
|
11
9
|
*/
|
|
12
10
|
completions: {
|
|
13
11
|
/**
|
|
14
12
|
* OpenAI 聊天补全
|
|
15
13
|
* @function openai.chat.completions.create
|
|
16
|
-
* @async
|
|
17
14
|
* @param {OpenAI.ChatCompletionCreateParams} params - 聊天补全参数
|
|
18
15
|
* @param {OpenAI.RequestOptions} options - 聊天补全选项
|
|
19
16
|
* @param {Function} onData - 数据生成时的回调
|
|
@@ -2,13 +2,11 @@ import { MujianSdk } from '../../../index';
|
|
|
2
2
|
import type OpenAI from 'openai';
|
|
3
3
|
/**
|
|
4
4
|
* @namespace openai.completions
|
|
5
|
-
* @description OpenAI 文本补全
|
|
6
5
|
*/
|
|
7
6
|
export declare const completions: {
|
|
8
7
|
/**
|
|
9
8
|
* OpenAI 文本补全
|
|
10
9
|
* @function openai.completions.create
|
|
11
|
-
* @async
|
|
12
10
|
* @param {OpenAI.CompletionCreateParams} params - 文本补全参数
|
|
13
11
|
* @param {OpenAI.RequestOptions} options - 文本补全选项
|
|
14
12
|
* @param {Function} onData - 数据生成时的回调
|
|
@@ -2,13 +2,11 @@ import { MujianSdk } from '../../../index';
|
|
|
2
2
|
import type OpenAI from 'openai';
|
|
3
3
|
/**
|
|
4
4
|
* @namespace openai.images
|
|
5
|
-
* @description OpenAI 图像生成
|
|
6
5
|
*/
|
|
7
6
|
export declare const images: {
|
|
8
7
|
/**
|
|
9
8
|
* OpenAI 图像生成
|
|
10
9
|
* @function openai.images.generate
|
|
11
|
-
* @async
|
|
12
10
|
* @param {OpenAI.ImageGenerateParams} params - 图像生成参数
|
|
13
11
|
* @param {OpenAI.RequestOptions} options - 图像生成选项
|
|
14
12
|
* @param {Function} onData - 数据生成时的回调
|
|
@@ -3,13 +3,11 @@ import type OpenAI from 'openai';
|
|
|
3
3
|
import type { ResponseCreateParams } from 'openai/resources/responses/responses.mjs';
|
|
4
4
|
/**
|
|
5
5
|
* @namespace openai.responses
|
|
6
|
-
* @description OpenAI 响应创建
|
|
7
6
|
*/
|
|
8
7
|
export declare const responses: {
|
|
9
8
|
/**
|
|
10
9
|
* OpenAI 响应创建
|
|
11
10
|
* @function openai.responses.create
|
|
12
|
-
* @async
|
|
13
11
|
* @param {ResponseCreateParams} params - 响应创建参数
|
|
14
12
|
* @param {OpenAI.RequestOptions} options - 响应创建选项
|
|
15
13
|
* @param {Function} onData - 数据生成时的回调
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MujianSdk } from '../index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* @interface Config
|
|
4
|
+
* @property {string} baseURL API 的 URL
|
|
5
|
+
* @property {string} apiKey API 的 KEY (当前用户唯一)
|
|
6
|
+
*/
|
|
7
|
+
export type Config = {
|
|
8
|
+
openapi: {
|
|
9
|
+
baseURL: string;
|
|
10
|
+
apiKey: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* 读取配置
|
|
15
|
+
*/
|
|
16
|
+
export declare function getConfig(
|
|
17
|
+
/** @hidden */ this: MujianSdk): Promise<Config>;
|
|
@@ -17,11 +17,22 @@ export type UseChatProps = {
|
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Use chat return
|
|
20
|
-
* @param {Message[]} messages -
|
|
21
|
-
* @param {string} status -
|
|
22
|
-
* @param {Error} error -
|
|
23
|
-
* @param {function} append -
|
|
24
|
-
* @param {function} regenerate -
|
|
20
|
+
* @param {Message[]} messages - 消息列表
|
|
21
|
+
* @param {string} status - 状态
|
|
22
|
+
* @param {Error} error - 错误
|
|
23
|
+
* @param {function} append - 添加消息
|
|
24
|
+
* @param {function} regenerate - 重新生成最后一条回答
|
|
25
|
+
* @param {function} continueGenerate - 让AI继续说
|
|
26
|
+
* @param {function} stop - 停止对话
|
|
27
|
+
* @param {function} setMessages - 设置消息
|
|
28
|
+
* @param {function} input - 用户输入
|
|
29
|
+
* @param {function} setInput - 设置输入
|
|
30
|
+
* @param {function} handleSubmit - 提交用户输入,让AI回答
|
|
31
|
+
* @param {function} setSwipe - 设置Swipe
|
|
32
|
+
* @param {function} editMessage - 编辑消息
|
|
33
|
+
* @param {function} deleteMessage - 删除消息
|
|
34
|
+
* @param {function} loadMoreMessage - 加载更多消息
|
|
35
|
+
* @param {string} messagesStatus - 消息状态
|
|
25
36
|
*/
|
|
26
37
|
export type UseChatReturn = {
|
|
27
38
|
messages: Message[];
|
|
@@ -54,6 +65,17 @@ export type UseChatCommon = {
|
|
|
54
65
|
};
|
|
55
66
|
/**
|
|
56
67
|
* Use chat
|
|
68
|
+
* @param {UseChatProps} props - The props of the chat.
|
|
69
|
+
* @param {object} props.body - The body of the chat.
|
|
70
|
+
* @param {function} props.onError - The function to call when an error occurs.
|
|
71
|
+
* @param {function} props.onFinish - The function to call when the chat is finished.
|
|
72
|
+
* @param {number} props.pageSize - The page size of the chat.
|
|
57
73
|
* @returns {UseChatReturn} The chat.
|
|
74
|
+
* @example
|
|
75
|
+
* const { messages, status, error, append, regenerate, continueGenerate, stop, setMessages, input, setInput, handleSubmit, setSwipe, editMessage, deleteMessage, loadMoreMessage, messagesStatus } = useChat({
|
|
76
|
+
* body: {
|
|
77
|
+
* model: 'gpt-4o-mini',
|
|
78
|
+
* },
|
|
79
|
+
* });
|
|
58
80
|
*/
|
|
59
81
|
export declare const useChat: ({ body, onError, onFinish, pageSize, }: UseChatProps) => UseChatReturn;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Dispatch, type SetStateAction } from 'react';
|
|
1
|
+
import { type Dispatch, RefObject, type SetStateAction } from 'react';
|
|
2
2
|
import type { MujianSdk } from '../../../../index.ts';
|
|
3
3
|
import type { UseChatCommon } from '..';
|
|
4
4
|
import type { Message } from '../message';
|
|
@@ -6,19 +6,23 @@ interface ChatStreamingProps {
|
|
|
6
6
|
common: UseChatCommon;
|
|
7
7
|
setError: (error: unknown) => void;
|
|
8
8
|
setMessages: Dispatch<SetStateAction<Message[]>>;
|
|
9
|
+
getMessages: () => Message[];
|
|
10
|
+
setInput: (input: string) => void;
|
|
9
11
|
mujian: MujianSdk;
|
|
12
|
+
conversationVersion: RefObject<number>;
|
|
10
13
|
}
|
|
11
14
|
export declare const NOT_SAVED_MSG_ID_PREFIX = "not_saved";
|
|
12
|
-
export declare const useChatStreaming: ({ common, setError, setMessages, mujian, }: ChatStreamingProps) => {
|
|
13
|
-
chatStreaming: ({ query, regenerate, is_continue,
|
|
15
|
+
export declare const useChatStreaming: ({ common, setError, setMessages, getMessages, setInput, mujian, conversationVersion: conversationVersionRef, }: ChatStreamingProps) => {
|
|
16
|
+
chatStreaming: ({ query, regenerate, is_continue, conversationVersion, }: {
|
|
14
17
|
/** 用户输入 */
|
|
15
18
|
query?: string;
|
|
16
19
|
/** 是否重说 */
|
|
17
20
|
regenerate?: boolean;
|
|
18
21
|
/** 是否继续 */
|
|
19
22
|
is_continue?: boolean;
|
|
20
|
-
|
|
23
|
+
conversationVersion: number;
|
|
21
24
|
}) => Promise<void>;
|
|
22
25
|
isStreaming: boolean;
|
|
26
|
+
recoverStreaming: (messageId: string, conversationVersion: number) => Promise<void>;
|
|
23
27
|
};
|
|
24
28
|
export {};
|
|
@@ -1,3 +1,26 @@
|
|
|
1
1
|
import type { MujianSdk } from '../../../../index.ts';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type MessageV2Content = string;
|
|
3
|
+
interface Mjv {
|
|
4
|
+
value: unknown;
|
|
5
|
+
delta: unknown;
|
|
6
|
+
schema: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface ChatMeta {
|
|
9
|
+
type: 'meta';
|
|
10
|
+
userMsgId: string;
|
|
11
|
+
assisMsgId: string;
|
|
12
|
+
newConversationVersion: number;
|
|
13
|
+
}
|
|
14
|
+
interface ChatError {
|
|
15
|
+
code: number;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
interface ChatData {
|
|
19
|
+
type: 'data';
|
|
20
|
+
content: MessageV2Content;
|
|
21
|
+
mjv?: Mjv;
|
|
22
|
+
finishReason?: string;
|
|
23
|
+
error?: ChatError;
|
|
24
|
+
}
|
|
25
|
+
export declare function callSdk(mujian: MujianSdk, content: string, type: "generate" | "regenerate" | "continue" | "recover" | undefined, conversationVersion: number, assisMsgId?: string): AsyncGenerator<ChatMeta | ChatData | undefined, void, unknown>;
|
|
26
|
+
export {};
|
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
export declare const Role: {
|
|
2
|
-
readonly User: "user";
|
|
3
|
-
readonly Assistant: "assistant";
|
|
4
|
-
readonly System: "system";
|
|
5
|
-
};
|
|
6
|
-
export type Role = (typeof Role)[keyof typeof Role];
|
|
7
1
|
type Mjv = {
|
|
8
2
|
value: unknown;
|
|
9
3
|
delta: unknown;
|
|
10
4
|
schema: unknown;
|
|
11
5
|
};
|
|
6
|
+
export type MessageV2Content = string;
|
|
7
|
+
export interface MessageV2Swipe {
|
|
8
|
+
content: MessageV2Content;
|
|
9
|
+
mjv?: Mjv;
|
|
10
|
+
}
|
|
12
11
|
export type Message = {
|
|
13
12
|
id: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
swipes: Array<string>;
|
|
13
|
+
isUser: boolean;
|
|
14
|
+
swipes: Array<MessageV2Swipe>;
|
|
17
15
|
activeSwipeId: number;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
swipeInfo: Array<{
|
|
22
|
-
mjv?: Mjv;
|
|
23
|
-
}>;
|
|
16
|
+
isGenerating?: boolean;
|
|
17
|
+
finishReason?: string;
|
|
18
|
+
error?: ChatError;
|
|
24
19
|
};
|
|
25
|
-
|
|
20
|
+
export interface ChatMeta {
|
|
26
21
|
type: 'meta';
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
type
|
|
43
|
-
type: 'mjv';
|
|
44
|
-
value: unknown;
|
|
45
|
-
delta: unknown;
|
|
46
|
-
schema: unknown;
|
|
47
|
-
};
|
|
48
|
-
export type RawData = MetaChunk | StreamChunk | MjvChunk;
|
|
22
|
+
userMsgId: string;
|
|
23
|
+
assisMsgId: string;
|
|
24
|
+
newConversationVersion: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ChatError {
|
|
27
|
+
code: number;
|
|
28
|
+
message: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ChatData {
|
|
31
|
+
type: 'data';
|
|
32
|
+
content: MessageV2Content;
|
|
33
|
+
mjv?: Mjv;
|
|
34
|
+
finishReason?: string;
|
|
35
|
+
error?: ChatError;
|
|
36
|
+
}
|
|
37
|
+
export type RawData = ChatMeta | ChatData;
|
|
49
38
|
export {};
|
|
@@ -7,15 +7,16 @@ export type MdRendererProps = {
|
|
|
7
7
|
content: string;
|
|
8
8
|
unsafe?: boolean;
|
|
9
9
|
extra?: Record<string, unknown>;
|
|
10
|
+
lang?: string;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* A React component that renders markdown content as HTML
|
|
13
14
|
*/
|
|
14
15
|
export declare const MdRendererBase: {
|
|
15
|
-
({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
({ content, unsafe, extra, lang, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
16
17
|
displayName: string;
|
|
17
18
|
};
|
|
18
19
|
export declare const MdRenderer: React.MemoExoticComponent<{
|
|
19
|
-
({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
({ content, unsafe, extra, lang, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
20
21
|
displayName: string;
|
|
21
22
|
}>;
|
|
@@ -15,3 +15,7 @@ export type MujianProviderProps = {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare const MujianProvider: ({ children, loadingComponent, }: MujianProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
17
17
|
export declare const useMujian: () => MujianSdk;
|
|
18
|
+
export declare const useChatContext: () => {
|
|
19
|
+
messageTypeWritingCount: number;
|
|
20
|
+
updateMessageTypeWritingCount: (direction: "add" | "sub") => void;
|
|
21
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { Message as MessageType } from '../../chat';
|
|
3
|
+
type TypingOpts = {
|
|
4
|
+
chunkSize: number;
|
|
5
|
+
delay: number;
|
|
6
|
+
};
|
|
3
7
|
export interface MessageItemProps {
|
|
4
8
|
/**
|
|
5
9
|
* Message
|
|
@@ -17,5 +21,7 @@ export interface MessageItemProps {
|
|
|
17
21
|
* Message depth, the latest messages is 0
|
|
18
22
|
*/
|
|
19
23
|
depth: number;
|
|
24
|
+
typingOpts?: TypingOpts;
|
|
20
25
|
}
|
|
21
26
|
export declare const MessageItem: (props: MessageItemProps) => ReactNode;
|
|
27
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { VListHandle } from 'virtua';
|
|
2
2
|
export { MdRenderer } from './MdRenderer';
|
|
3
|
-
export { MujianProvider, useMujian } from './MujianProvider';
|
|
3
|
+
export { MujianProvider, useChatContext, useMujian } from './MujianProvider';
|
|
4
4
|
export { MujianSpinner } from './MujianSpinner';
|
|
5
5
|
export { Thread } from './Thread';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { PersonaInfo, ProjectInfo } from '../../types';
|
|
2
|
+
import { useChat } from '../chat';
|
|
3
|
+
declare global {
|
|
4
|
+
interface MjEngineAiChat {
|
|
5
|
+
complete?: (message: string) => Promise<void>;
|
|
6
|
+
project?: ProjectInfo;
|
|
7
|
+
settings: {
|
|
8
|
+
persona?: PersonaInfo;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @param index 下标从1开始
|
|
12
|
+
*/
|
|
13
|
+
setFirstMesIndex?: (index: number) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
interface MjEngineAi {
|
|
16
|
+
chat: MjEngineAiChat;
|
|
17
|
+
}
|
|
18
|
+
interface MjEngine {
|
|
19
|
+
ai: MjEngineAi;
|
|
20
|
+
}
|
|
21
|
+
interface Window {
|
|
22
|
+
$mj_engine: MjEngine & {
|
|
23
|
+
bind: (extra: {
|
|
24
|
+
messageId: string;
|
|
25
|
+
swipeId: number;
|
|
26
|
+
}) => MjEngine & {
|
|
27
|
+
ai: {
|
|
28
|
+
chat: {
|
|
29
|
+
mjv: {
|
|
30
|
+
get: (path: string) => unknown;
|
|
31
|
+
getAll: () => unknown;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
type UseChatRet = ReturnType<typeof useChat>;
|
|
40
|
+
export type UseMjEngineOpts = {
|
|
41
|
+
projectInfo?: ProjectInfo;
|
|
42
|
+
activePersona?: PersonaInfo;
|
|
43
|
+
onSend: (query: string) => unknown;
|
|
44
|
+
messages: UseChatRet['messages'];
|
|
45
|
+
setSwipe: UseChatRet['setSwipe'];
|
|
46
|
+
};
|
|
47
|
+
export declare function useMjEngine({ projectInfo, activePersona, onSend, messages, setSwipe, }: UseMjEngineOpts): void;
|
|
48
|
+
export {};
|