@mujian/js-sdk 0.0.6-beta.8 → 0.0.6-beta.81

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.
Files changed (43) hide show
  1. package/dist/events/index.d.ts +34 -2
  2. package/dist/index.d.ts +17 -39
  3. package/dist/index.js +369 -30
  4. package/dist/lite.d.ts +74 -0
  5. package/dist/lite.js +120 -0
  6. package/dist/modules/ai/chat/chat.d.ts +46 -4
  7. package/dist/modules/ai/chat/index.d.ts +1 -1
  8. package/dist/modules/ai/chat/message/index.d.ts +4 -0
  9. package/dist/modules/ai/index.d.ts +3 -2
  10. package/dist/modules/ai/openai/chat.d.ts +25 -0
  11. package/dist/modules/ai/openai/completions.d.ts +19 -0
  12. package/dist/modules/ai/openai/images.d.ts +19 -0
  13. package/dist/modules/ai/openai/index.d.ts +4 -0
  14. package/dist/modules/ai/openai/responses.d.ts +20 -0
  15. package/dist/modules/ai/text/index.d.ts +9 -2
  16. package/dist/modules/config.d.ts +18 -0
  17. package/dist/modules/utils/clipboard.d.ts +5 -0
  18. package/dist/modules/utils/index.d.ts +4 -0
  19. package/dist/react/chat/useChat/index.d.ts +34 -8
  20. package/dist/react/chat/useChat/inner/chatStreaming.d.ts +5 -2
  21. package/dist/react/chat/useChat/message.d.ts +31 -13
  22. package/dist/react/components/MdRenderer/index.d.ts +6 -4
  23. package/dist/react/components/MdRenderer/utils/height.d.ts +0 -0
  24. package/dist/react/components/MdRenderer/utils/iframe.d.ts +9 -0
  25. package/dist/react/components/MdRenderer/utils/scripts.d.ts +4 -0
  26. package/dist/react/components/MujianSpinner/index.d.ts +7 -0
  27. package/dist/react/components/index.d.ts +1 -0
  28. package/dist/react/index.d.ts +1 -0
  29. package/dist/react/mjEngine/index.d.ts +48 -0
  30. package/dist/react.css +65 -4
  31. package/dist/react.js +841 -199
  32. package/dist/types/index.d.ts +38 -0
  33. package/dist/umd/index.js +2 -0
  34. package/dist/umd/index.js.LICENSE.txt +7 -0
  35. package/dist/umd/lite.js +2 -0
  36. package/dist/umd/lite.js.LICENSE.txt +7 -0
  37. package/dist/umd/react.css +1 -0
  38. package/dist/umd/react.js +138 -0
  39. package/dist/umd/react.js.LICENSE.txt +31 -0
  40. package/dist/utils/is-network-error.d.ts +1 -0
  41. package/dist/utils/log.d.ts +4 -0
  42. package/package.json +16 -6
  43. /package/dist/react/components/MdRenderer/{utils.d.ts → utils/md.d.ts} +0 -0
package/dist/lite.js ADDED
@@ -0,0 +1,120 @@
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_SETTINGS_PERSONA_GET_ACTIVE"] = "mujian:ai:settings:persona:getActive";
16
+ EVENT["MUJIAN_AI_SETTINGS_PERSONA_SET_ACTIVE"] = "mujian:ai:settings:persona:setActive";
17
+ EVENT["MUJIAN_AI_SETTINGS_MODEL_GET_ALL"] = "mujian:ai:settings:model:getAll";
18
+ EVENT["MUJIAN_AI_SETTINGS_MODEL_SET_ACTIVE"] = "mujian:ai:settings:model:setActive";
19
+ EVENT["MUJIAN_AI_SETTINGS_MODEL_GET_ACTIVE"] = "mujian:ai:settings:model:getActive";
20
+ EVENT["MUJIAN_AI_CHAT_MESSAGE_DELETE_ONE"] = "mujian:ai:chat:message:deleteOne";
21
+ EVENT["MUJIAN_AI_CHAT_MESSAGE_EDIT_ONE"] = "mujian:ai:chat:message:editOne";
22
+ EVENT["MUJIAN_AI_CHAT_MESSAGE_SWIPE"] = "mujian:ai:chat:message:swipe";
23
+ EVENT["MUJIAN_AI_CHAT_MESSAGE_GET_PROMPT"] = "mujian:ai:chat:message:getPrompt";
24
+ EVENT["MUJIAN_AI_OPENAI_IMAGES_GENERATE"] = "mujian:ai:openai:images:generate";
25
+ EVENT["MUJIAN_UTILS_CLIPBOARD_WRITE_TEXT"] = "mujian:utils:clipboard:writeText";
26
+ EVENT["MUJIAN_GET_CONFIG"] = "mujian:getConfig";
27
+ return EVENT;
28
+ }({});
29
+ const Log = {
30
+ i (...msg) {
31
+ console.log('[MujianSDK] ', ...msg);
32
+ },
33
+ e (...msg) {
34
+ console.error('[MujianSDK] ', ...msg);
35
+ }
36
+ };
37
+ class MujianSdkLite {
38
+ constructor(){}
39
+ static EVENT = events_EVENT;
40
+ static getInstance() {
41
+ if (!window.$mujian_lite) window.$mujian_lite = new MujianSdkLite();
42
+ return window.$mujian_lite;
43
+ }
44
+ parent = null;
45
+ ready = false;
46
+ get isReady() {
47
+ return this.ready;
48
+ }
49
+ pendingRequests = new Map();
50
+ _config;
51
+ get openapi() {
52
+ return this._config?.openapi;
53
+ }
54
+ initPromise = null;
55
+ async init() {
56
+ if (this.initPromise) return this.initPromise;
57
+ this.initPromise = (async ()=>{
58
+ const handshake = new postmate.Model({
59
+ reply: ({ id, complete, data, error })=>{
60
+ const call = this.pendingRequests.get(id);
61
+ if (!call) return;
62
+ if (error) {
63
+ call.reject(error);
64
+ this.pendingRequests.delete(id);
65
+ return;
66
+ }
67
+ call.onData?.(data);
68
+ if (complete) {
69
+ call.onComplete?.();
70
+ call.resolve(data);
71
+ this.pendingRequests.delete(id);
72
+ }
73
+ }
74
+ });
75
+ try {
76
+ const parent = await handshake;
77
+ this.parent = parent;
78
+ this.ready = true;
79
+ Log.i('mujian sdk lite client init');
80
+ await this.call(events_EVENT.MUJIAN_INIT);
81
+ this._config = await this.call(events_EVENT.MUJIAN_GET_CONFIG);
82
+ } catch (error) {
83
+ Log.e('init error', error);
84
+ throw error;
85
+ }
86
+ })();
87
+ return this.initPromise;
88
+ }
89
+ ensureReady() {
90
+ if (!this.ready) throw new Error('MujianLite is not initialized');
91
+ }
92
+ emit(event, data) {
93
+ this.ensureReady();
94
+ this.parent?.emit(event, data);
95
+ }
96
+ nextCallId = 0;
97
+ getCallId() {
98
+ const id = this.nextCallId;
99
+ this.nextCallId += 1;
100
+ return `lite_${id}`;
101
+ }
102
+ async call(event, data, controller) {
103
+ this.ensureReady();
104
+ const callId = this.getCallId();
105
+ return new Promise((resolve, reject)=>{
106
+ this.pendingRequests.set(callId, {
107
+ resolve,
108
+ reject,
109
+ ...controller
110
+ });
111
+ this.emit(event, {
112
+ id: callId,
113
+ data
114
+ });
115
+ });
116
+ }
117
+ }
118
+ MujianSdkLite.getInstance().init();
119
+ const lite = MujianSdkLite;
120
+ export { events_EVENT as EVENT, lite as default };
@@ -1,20 +1,62 @@
1
1
  import type { MujianSdk } from '../../../index.ts';
2
2
  import { Message } from '../../../react';
3
+ /**
4
+ * LLM生成返回的数据
5
+ */
6
+ export type ParsedData = {
7
+ /** 是否已完成生成,最后一块数据时为true */
8
+ isFinished: boolean;
9
+ /** LLM生成的delta content */
10
+ deltaContent: string;
11
+ /** LLM生成的累积内容 */
12
+ fullContent: string;
13
+ /** 出错时非空 */
14
+ error?: unknown;
15
+ /** 用户发送消息的ID */
16
+ questionId?: string;
17
+ /** AI返回消息的ID */
18
+ replyId?: string;
19
+ };
20
+ /**
21
+ * 对话补全配置
22
+ */
23
+ export type CompleteOption = {
24
+ /** 给onData传递的数据是否是解析后的,推荐true */
25
+ parseContent?: boolean;
26
+ };
3
27
  /**
4
28
  * 对话补全
5
- * @param {string} message 消息
6
- * @param {Function} onData 数据
7
- * @param {AbortSignal} signal 信号
8
29
  * @returns {Promise<string>} 返回值
9
30
  */
10
31
  export declare const complete: (
11
32
  /** @hidden */
12
- this: MujianSdk, message: string, onData: (data: string) => void, signal?: AbortSignal) => Promise<string>;
33
+ this: MujianSdk,
34
+ /**
35
+ * 消息
36
+ */
37
+ message: string,
38
+ /**
39
+ * 数据生成时的回调
40
+ */
41
+ onData: (data: string | ParsedData) => void,
42
+ /**
43
+ * 停止生成的信号
44
+ */
45
+ signal?: AbortSignal | undefined,
46
+ /**
47
+ * 对话补全配置
48
+ */
49
+ option?: CompleteOption | undefined) => Promise<void>;
13
50
  export declare const applyRegex: (this: MujianSdk, props: {
14
51
  message: Message;
15
52
  index: number;
16
53
  depth: number;
17
54
  }) => Promise<Message>;
55
+ export declare const renderMessage: (this: MujianSdk, props: {
56
+ message: Message;
57
+ index: number;
58
+ depth: number;
59
+ }) => Promise<Message>;
18
60
  /**
19
61
  * 继续
20
62
  * @param onData 数据
@@ -1,4 +1,4 @@
1
- export { applyRegex, complete, continueComplete, 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';
@@ -1,5 +1,6 @@
1
1
  import type { MujianSdk } from '../../../../index.ts';
2
2
  import type { Message } from '../../../../react/chat/useChat/message';
3
+ import { Cursor } from '../../../../types';
3
4
  /**
4
5
  * 获取消息列表
5
6
  * @returns 消息当前列表
@@ -41,3 +42,6 @@ this: MujianSdk, messageId: string, swipeId: number) => Promise<unknown>;
41
42
  export declare const getPrompt: (
42
43
  /** @hidden */
43
44
  this: MujianSdk, messageId: string) => Promise<unknown>;
45
+ export declare function getPage(
46
+ /** @hidden */
47
+ this: MujianSdk, fromCursor: Cursor, pageSize: number): Promise<unknown>;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * @module ai
3
3
  */
4
- export * as chat from './chat';
5
- export * as text from './text';
4
+ export * as chat from "./chat";
5
+ export * as text from "./text";
6
+ export * as openai from "./openai";
@@ -0,0 +1,25 @@
1
+ import { MujianSdk } from '../../../index';
2
+ import type OpenAI from 'openai';
3
+ /**
4
+ * @namespace openai.chat
5
+ * @description OpenAI 聊天补全
6
+ */
7
+ export declare const chat: {
8
+ /**
9
+ * @namespace openai.chat.completions
10
+ * @description OpenAI 聊天补全
11
+ */
12
+ completions: {
13
+ /**
14
+ * OpenAI 聊天补全
15
+ * @function openai.chat.completions.create
16
+ * @async
17
+ * @param {OpenAI.ChatCompletionCreateParams} params - 聊天补全参数
18
+ * @param {OpenAI.RequestOptions} options - 聊天补全选项
19
+ * @param {Function} onData - 数据生成时的回调
20
+ * @param {AbortSignal} signal - 停止生成的信号
21
+ * @returns {Promise<void>} 聊天补全结果
22
+ */
23
+ create: (this: MujianSdk, params: OpenAI.ChatCompletionCreateParams, options?: OpenAI.RequestOptions, onData?: (data: unknown) => void, signal?: AbortSignal | undefined) => Promise<OpenAI.ChatCompletion>;
24
+ };
25
+ };
@@ -0,0 +1,19 @@
1
+ import { MujianSdk } from '../../../index';
2
+ import type OpenAI from 'openai';
3
+ /**
4
+ * @namespace openai.completions
5
+ * @description OpenAI 文本补全
6
+ */
7
+ export declare const completions: {
8
+ /**
9
+ * OpenAI 文本补全
10
+ * @function openai.completions.create
11
+ * @async
12
+ * @param {OpenAI.CompletionCreateParams} params - 文本补全参数
13
+ * @param {OpenAI.RequestOptions} options - 文本补全选项
14
+ * @param {Function} onData - 数据生成时的回调
15
+ * @param {AbortSignal} signal - 停止生成的信号
16
+ * @returns {Promise<void>} 文本补全结果
17
+ */
18
+ create: (this: MujianSdk, params: OpenAI.CompletionCreateParams, options?: OpenAI.RequestOptions, onData?: (data: unknown) => void, signal?: AbortSignal | undefined) => Promise<OpenAI.Completion>;
19
+ };
@@ -0,0 +1,19 @@
1
+ import { MujianSdk } from '../../../index';
2
+ import type OpenAI from 'openai';
3
+ /**
4
+ * @namespace openai.images
5
+ * @description OpenAI 图像生成
6
+ */
7
+ export declare const images: {
8
+ /**
9
+ * OpenAI 图像生成
10
+ * @function openai.images.generate
11
+ * @async
12
+ * @param {OpenAI.ImageGenerateParams} params - 图像生成参数
13
+ * @param {OpenAI.RequestOptions} options - 图像生成选项
14
+ * @param {Function} onData - 数据生成时的回调
15
+ * @param {AbortSignal} signal - 停止生成的信号
16
+ * @returns {Promise<OpenAI.ImagesResponse>} 图像生成结果
17
+ */
18
+ generate: (this: MujianSdk, params: OpenAI.ImageGenerateParams, options?: OpenAI.RequestOptions, onData?: (data: unknown) => void, signal?: AbortSignal | undefined) => Promise<OpenAI.ImagesResponse>;
19
+ };
@@ -0,0 +1,4 @@
1
+ export * from './chat';
2
+ export * from './completions';
3
+ export * from './responses';
4
+ export * from './images';
@@ -0,0 +1,20 @@
1
+ import { MujianSdk } from '../../../index';
2
+ import type OpenAI from 'openai';
3
+ import type { ResponseCreateParams } from 'openai/resources/responses/responses.mjs';
4
+ /**
5
+ * @namespace openai.responses
6
+ * @description OpenAI 响应创建
7
+ */
8
+ export declare const responses: {
9
+ /**
10
+ * OpenAI 响应创建
11
+ * @function openai.responses.create
12
+ * @async
13
+ * @param {ResponseCreateParams} params - 响应创建参数
14
+ * @param {OpenAI.RequestOptions} options - 响应创建选项
15
+ * @param {Function} onData - 数据生成时的回调
16
+ * @param {AbortSignal} signal - 停止生成的信号
17
+ * @returns {Promise<void>} 响应创建结果
18
+ */
19
+ create: (this: MujianSdk, params: ResponseCreateParams, options?: OpenAI.RequestOptions, onData?: (data: unknown) => void, signal?: AbortSignal | undefined) => Promise<OpenAI.Responses>;
20
+ };
@@ -1,2 +1,9 @@
1
- import type { MujianSdk } from '../../../index';
2
- export declare const generate: (this: MujianSdk) => Promise<void>;
1
+ import { MujianSdk } from "../../../index";
2
+ /**
3
+ * 文本补全
4
+ * @param content 文本内容
5
+ * @returns 文本补全结果
6
+ */
7
+ export declare const generate: (
8
+ /** @hidden */
9
+ this: MujianSdk, content: string) => Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { type MujianSdk } from '../index.ts';
2
+ /**
3
+ * @interface Config
4
+ * @description 配置接口
5
+ * @property {string} baseURL API 的 URL
6
+ * @property {string} apiKey API 的 KEY (当前用户唯一)
7
+ */
8
+ export type Config = {
9
+ openapi: {
10
+ baseURL: string;
11
+ apiKey: string;
12
+ };
13
+ };
14
+ /**
15
+ * 读取配置
16
+ */
17
+ export declare function getConfig(
18
+ /** @hidden */ this: MujianSdk): Promise<Config>;
@@ -0,0 +1,5 @@
1
+ import { type MujianSdk } from '../../index.ts';
2
+ /**
3
+ * 写入剪贴版
4
+ */
5
+ export declare function writeText(/** @hidden */ this: MujianSdk, text: string): Promise<unknown>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @module game
3
+ */
4
+ export * as clipboard from './clipboard';
@@ -10,21 +10,34 @@ export type { Message };
10
10
  */
11
11
  export type UseChatProps = {
12
12
  body?: object;
13
- onError?: (e: Error) => void;
13
+ onError?: (e: unknown) => void;
14
14
  onFinish?: (message: Message) => void;
15
+ /** 消息分页大小,不传时不分页 */
16
+ pageSize?: number;
15
17
  };
16
18
  /**
17
19
  * Use chat return
18
- * @param {Message[]} messages - The messages of the chat.
19
- * @param {string} status - The status of the chat.
20
- * @param {Error} error - The error of the chat.
21
- * @param {function} append - The function to call when the chat is finished.
22
- * @param {function} regenerate - The function to call when the chat is finished.
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 - 消息状态
23
36
  */
24
37
  export type UseChatReturn = {
25
38
  messages: Message[];
26
39
  status: 'uninitialized' | 'ready' | 'streaming' | 'error';
27
- error?: Error;
40
+ error?: unknown;
28
41
  /** 提交用户输入,让AI回答 */
29
42
  append: (query: string) => Promise<void>;
30
43
  /** 重新生成最后一条回答 */
@@ -39,6 +52,8 @@ export type UseChatReturn = {
39
52
  setSwipe: (messageId: string, swipeId: number) => Promise<void>;
40
53
  editMessage: (messageId: string, content: string) => Promise<void>;
41
54
  deleteMessage: (messageId: string) => Promise<void>;
55
+ loadMoreMessage: () => Promise<void>;
56
+ messagesStatus: 'all-loaded' | 'loading' | 'has-more' | 'error';
42
57
  };
43
58
  /**
44
59
  * Use chat common
@@ -50,6 +65,17 @@ export type UseChatCommon = {
50
65
  };
51
66
  /**
52
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.
53
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
+ * });
54
80
  */
55
- export declare const useChat: ({ body, onError, onFinish, }: UseChatProps) => UseChatReturn;
81
+ export declare const useChat: ({ body, onError, onFinish, pageSize, }: UseChatProps) => UseChatReturn;
@@ -4,11 +4,14 @@ import type { UseChatCommon } from '..';
4
4
  import type { Message } from '../message';
5
5
  interface ChatStreamingProps {
6
6
  common: UseChatCommon;
7
- setError: (error: Error | undefined) => void;
7
+ setError: (error: unknown) => void;
8
8
  setMessages: Dispatch<SetStateAction<Message[]>>;
9
+ getMessages: () => Message[];
10
+ setInput: (input: string) => void;
9
11
  mujian: MujianSdk;
10
12
  }
11
- export declare const useChatStreaming: ({ common, setError, setMessages, mujian, }: ChatStreamingProps) => {
13
+ export declare const NOT_SAVED_MSG_ID_PREFIX = "not_saved";
14
+ export declare const useChatStreaming: ({ common, setError, setMessages, getMessages, setInput, mujian, }: ChatStreamingProps) => {
12
15
  chatStreaming: ({ query, regenerate, is_continue, signal, }: {
13
16
  /** 用户输入 */
14
17
  query?: string;
@@ -4,6 +4,11 @@ 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
+ schema: unknown;
11
+ };
7
12
  export type Message = {
8
13
  id: string;
9
14
  role: Role;
@@ -12,26 +17,39 @@ export type Message = {
12
17
  activeSwipeId: number;
13
18
  sendAt: Date;
14
19
  isStreaming: boolean;
20
+ mjv?: Mjv;
21
+ swipeInfo: Array<{
22
+ mjv?: Mjv;
23
+ }>;
24
+ flags: {
25
+ saved?: boolean;
26
+ emptyResponse?: boolean;
27
+ contentFilter?: boolean;
28
+ };
15
29
  };
16
- export type RawData = {
17
- id: string;
18
- provider: string;
19
- model: string;
20
- object: string;
21
- created: number;
30
+ type MetaChunk = {
31
+ type: 'meta';
32
+ question_id: string;
33
+ reply_id: string;
34
+ };
35
+ type StreamChunk = {
36
+ type: 'stream';
22
37
  choices: [
23
38
  {
24
- index: number;
25
39
  delta: {
26
- role: string;
27
40
  content: string;
28
41
  reasoning: string;
29
42
  };
30
- finish_reason: string | null;
31
- native_finish_reason: string | null;
32
- logprobs: string | null;
43
+ finish_reason?: string;
33
44
  }
34
45
  ];
35
- question_id: string;
36
- reply_id: string;
46
+ isFinished: boolean;
47
+ };
48
+ type MjvChunk = {
49
+ type: 'mjv';
50
+ value: unknown;
51
+ delta: unknown;
52
+ schema: unknown;
37
53
  };
54
+ export type RawData = MetaChunk | StreamChunk | MjvChunk;
55
+ export {};
@@ -1,19 +1,21 @@
1
- import React from "react";
2
- import "./MdTheme.css";
1
+ import React from 'react';
2
+ import './MdTheme.css';
3
3
  export type MdRendererProps = {
4
4
  /**
5
5
  * The markdown content to render
6
6
  */
7
7
  content: string;
8
+ unsafe?: boolean;
9
+ extra?: Record<string, unknown>;
8
10
  };
9
11
  /**
10
12
  * A React component that renders markdown content as HTML
11
13
  */
12
14
  export declare const MdRendererBase: {
13
- ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
15
+ ({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
14
16
  displayName: string;
15
17
  };
16
18
  export declare const MdRenderer: React.MemoExoticComponent<{
17
- ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
19
+ ({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
18
20
  displayName: string;
19
21
  }>;
@@ -0,0 +1,9 @@
1
+ export declare const unescapeHTML: (str: string) => string;
2
+ export declare const replaceVhInContent: (content: string) => string;
3
+ /**
4
+ * 转义 HTML 属性值中的引号,防止破坏 HTML 属性
5
+ * @param value 需要转义的属性值
6
+ * @returns 转义后的值
7
+ */
8
+ export declare function escapeHtmlAttribute(value: string): string;
9
+ export declare function createSrcContent(content: string, iframeId: string, unsafe: boolean, extra: Record<string, unknown>): string;
@@ -0,0 +1,4 @@
1
+ export declare const adjustIframeHeight: (iframeId: string) => string;
2
+ export declare const iframeAdjustViewport: (parentHeight: number) => string;
3
+ export declare const init: (_iframeId: string, unsafe: boolean, extra: Record<string, unknown>) => string;
4
+ export declare const thirdParty = "\n<script src=\"https://cdn.jsdmirror.com/npm/@fortawesome/fontawesome-free/js/all.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/@tailwindcss/browser/dist/index.global.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/jquery/dist/jquery.min.js\"></script>\n<script src=\"https://cdn.jsdmirror.com/npm/jquery-ui/dist/jquery-ui.min.js\"></script>\n<link rel=\"stylesheet\" href=\"https://cdn.jsdmirror.com/npm/jquery-ui/themes/base/theme.min.css\" />\n<script src=\"https://cdn.jsdmirror.com/npm/jquery-ui-touch-punch\"></script>\n";
@@ -0,0 +1,7 @@
1
+ import type { CSSProperties } from 'react';
2
+ interface Props {
3
+ className?: string;
4
+ style: CSSProperties;
5
+ }
6
+ export declare const MujianSpinner: ({ className, style }: Props) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -1,4 +1,5 @@
1
1
  export type { VListHandle } from 'virtua';
2
2
  export { MdRenderer } from './MdRenderer';
3
3
  export { MujianProvider, useMujian } from './MujianProvider';
4
+ export { MujianSpinner } from './MujianSpinner';
4
5
  export { Thread } from './Thread';
@@ -1,2 +1,3 @@
1
1
  export * from './chat';
2
2
  export * from './components';
3
+ export * from './mjEngine';
@@ -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 {};