@mujian/js-sdk 0.0.6-beta.7 → 0.0.6-beta.71

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 (41) hide show
  1. package/dist/events/index.d.ts +34 -2
  2. package/dist/index.d.ts +16 -39
  3. package/dist/index.js +345 -16
  4. package/dist/lite.d.ts +54 -0
  5. package/dist/modules/ai/chat/chat.d.ts +46 -4
  6. package/dist/modules/ai/chat/index.d.ts +1 -1
  7. package/dist/modules/ai/chat/message/index.d.ts +4 -0
  8. package/dist/modules/ai/index.d.ts +3 -2
  9. package/dist/modules/ai/openai/chat.d.ts +25 -0
  10. package/dist/modules/ai/openai/completions.d.ts +19 -0
  11. package/dist/modules/ai/openai/images.d.ts +19 -0
  12. package/dist/modules/ai/openai/index.d.ts +4 -0
  13. package/dist/modules/ai/openai/responses.d.ts +20 -0
  14. package/dist/modules/ai/text/index.d.ts +9 -2
  15. package/dist/modules/config.d.ts +12 -0
  16. package/dist/modules/utils/clipboard.d.ts +5 -0
  17. package/dist/modules/utils/index.d.ts +4 -0
  18. package/dist/react/chat/useChat/index.d.ts +34 -8
  19. package/dist/react/chat/useChat/inner/chatStreaming.d.ts +2 -1
  20. package/dist/react/chat/useChat/message.d.ts +25 -13
  21. package/dist/react/components/MdRenderer/index.d.ts +6 -4
  22. package/dist/react/components/MdRenderer/utils/height.d.ts +0 -0
  23. package/dist/react/components/MdRenderer/utils/iframe.d.ts +9 -0
  24. package/dist/react/components/MdRenderer/utils/scripts.d.ts +4 -0
  25. package/dist/react/components/MujianSpinner/index.d.ts +7 -0
  26. package/dist/react/components/index.d.ts +1 -0
  27. package/dist/react/index.d.ts +1 -0
  28. package/dist/react/mjEngine/index.d.ts +48 -0
  29. package/dist/react.css +65 -4
  30. package/dist/react.js +780 -143
  31. package/dist/types/index.d.ts +38 -0
  32. package/dist/umd/index.js +2 -0
  33. package/dist/umd/index.js.LICENSE.txt +7 -0
  34. package/dist/umd/lite.js +2 -0
  35. package/dist/umd/lite.js.LICENSE.txt +7 -0
  36. package/dist/umd/react.css +1 -0
  37. package/dist/umd/react.js +139 -0
  38. package/dist/umd/react.js.LICENSE.txt +31 -0
  39. package/dist/utils/log.d.ts +4 -0
  40. package/package.json +6 -1
  41. /package/dist/react/components/MdRenderer/{utils.d.ts → utils/md.d.ts} +0 -0
@@ -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,12 @@
1
+ import { type MujianSdk } from '../index.ts';
2
+ export type Config = {
3
+ openapi: {
4
+ baseUrl: string;
5
+ apiKey: string;
6
+ };
7
+ };
8
+ /**
9
+ * 读取配置
10
+ */
11
+ export declare function getConfig(
12
+ /** @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,10 +4,11 @@ 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
9
  mujian: MujianSdk;
10
10
  }
11
+ export declare const NOT_SAVED_MSG_ID_PREFIX = "not_saved";
11
12
  export declare const useChatStreaming: ({ common, setError, setMessages, mujian, }: ChatStreamingProps) => {
12
13
  chatStreaming: ({ query, regenerate, is_continue, signal, }: {
13
14
  /** 用户输入 */
@@ -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,33 @@ 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
+ }>;
15
24
  };
16
- export type RawData = {
17
- id: string;
18
- provider: string;
19
- model: string;
20
- object: string;
21
- created: number;
25
+ type MetaChunk = {
26
+ type: 'meta';
27
+ question_id: string;
28
+ reply_id: string;
29
+ };
30
+ type StreamChunk = {
31
+ type: 'stream';
22
32
  choices: [
23
33
  {
24
- index: number;
25
34
  delta: {
26
- role: string;
27
35
  content: string;
28
36
  reasoning: string;
29
37
  };
30
- finish_reason: string | null;
31
- native_finish_reason: string | null;
32
- logprobs: string | null;
33
38
  }
34
39
  ];
35
- question_id: string;
36
- reply_id: string;
40
+ isFinished: boolean;
41
+ };
42
+ type MjvChunk = {
43
+ type: 'mjv';
44
+ value: unknown;
45
+ delta: unknown;
46
+ schema: unknown;
37
47
  };
48
+ export type RawData = MetaChunk | StreamChunk | MjvChunk;
49
+ 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 {};
package/dist/react.css CHANGED
@@ -42,7 +42,7 @@
42
42
  --SmartThemeBodyColor: #abc6df;
43
43
  --SmartThemeEmColor: #fff;
44
44
  --SmartThemeUnderlineColor: #bce7cf;
45
- --SmartThemeQuoteColor: #6f85fd;
45
+ --SmartThemeQuoteColor: #b983ff;
46
46
  --SmartThemeBlurTintColor: #171717;
47
47
  --SmartThemeChatTintColor: #171717;
48
48
  --SmartThemeUserMesBlurTintColor: #0000004d;
@@ -89,6 +89,69 @@
89
89
  -moz-osx-font-smoothing: grayscale;
90
90
  }
91
91
 
92
+ .spin-overlay {
93
+ background-color: #000;
94
+ animation: 3s ease-in-out infinite breath;
95
+ }
96
+
97
+ @keyframes breath {
98
+ 0% {
99
+ background-color: #0009;
100
+ }
101
+
102
+ 50% {
103
+ background-color: #00000080;
104
+ }
105
+
106
+ 100% {
107
+ background-color: #0009;
108
+ }
109
+ }
110
+
111
+ .wave-text span {
112
+ font-family: var(--mainFontFamily);
113
+ animation: 2s ease-in-out infinite wave;
114
+ display: inline-block;
115
+ }
116
+
117
+ .wave-text span:first-child {
118
+ animation-delay: 0s;
119
+ }
120
+
121
+ .wave-text span:nth-child(2) {
122
+ animation-delay: .2s;
123
+ }
124
+
125
+ .wave-text span:nth-child(3) {
126
+ animation-delay: .4s;
127
+ }
128
+
129
+ .wave-text span:nth-child(4) {
130
+ animation-delay: .6s;
131
+ }
132
+
133
+ .wave-text span:nth-child(5) {
134
+ animation-delay: .8s;
135
+ }
136
+
137
+ .wave-text span:nth-child(6) {
138
+ animation-delay: 1s;
139
+ }
140
+
141
+ .wave-text span:nth-child(7) {
142
+ animation-delay: 1.2s;
143
+ }
144
+
145
+ @keyframes wave {
146
+ 0%, 100% {
147
+ transform: translateY(0);
148
+ }
149
+
150
+ 50% {
151
+ transform: translateY(-8px);
152
+ }
153
+ }
154
+
92
155
  body {
93
156
  font-size: var(--mainFontSize);
94
157
  color: var(--SmartThemeBodyColor);
@@ -261,11 +324,9 @@ body {
261
324
  code {
262
325
  font-family: var(--monoFontFamily);
263
326
  white-space: pre-wrap;
264
- border: 1px solid var(--SmartThemeBorderColor);
265
- background-color: var(--black70a);
266
327
  line-height: var(--mainFontSize);
267
328
  color: var(--white70a);
268
- border-radius: 5px;
329
+ border: 1px solid #fff;
269
330
  padding: 0 3px;
270
331
  }
271
332