@mujian/js-sdk 0.0.6-beta.9 → 0.0.6-beta.mjv.67

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 (35) hide show
  1. package/dist/events/index.d.ts +30 -2
  2. package/dist/index.d.ts +13 -39
  3. package/dist/index.js +323 -15
  4. package/dist/modules/ai/chat/chat.d.ts +46 -4
  5. package/dist/modules/ai/chat/index.d.ts +1 -1
  6. package/dist/modules/ai/chat/message/index.d.ts +4 -0
  7. package/dist/modules/ai/index.d.ts +3 -2
  8. package/dist/modules/ai/openai/chat.d.ts +25 -0
  9. package/dist/modules/ai/openai/completions.d.ts +19 -0
  10. package/dist/modules/ai/openai/images.d.ts +19 -0
  11. package/dist/modules/ai/openai/index.d.ts +4 -0
  12. package/dist/modules/ai/openai/responses.d.ts +20 -0
  13. package/dist/modules/ai/text/index.d.ts +9 -2
  14. package/dist/modules/utils/clipboard.d.ts +5 -0
  15. package/dist/modules/utils/index.d.ts +4 -0
  16. package/dist/react/chat/useChat/index.d.ts +7 -3
  17. package/dist/react/chat/useChat/inner/chatStreaming.d.ts +1 -1
  18. package/dist/react/chat/useChat/message.d.ts +25 -13
  19. package/dist/react/components/MdRenderer/index.d.ts +4 -3
  20. package/dist/react/components/MdRenderer/utils/height.d.ts +0 -0
  21. package/dist/react/components/MdRenderer/utils/iframe.d.ts +9 -0
  22. package/dist/react/components/MdRenderer/utils/scripts.d.ts +4 -0
  23. package/dist/react/components/MujianSpinner/index.d.ts +7 -0
  24. package/dist/react/components/index.d.ts +1 -0
  25. package/dist/react.css +65 -4
  26. package/dist/react.js +687 -112
  27. package/dist/types/index.d.ts +38 -0
  28. package/dist/umd/index.js +792 -0
  29. package/dist/umd/index.js.LICENSE.txt +7 -0
  30. package/dist/umd/react.css +343 -0
  31. package/dist/umd/react.js +8881 -0
  32. package/dist/umd/react.js.LICENSE.txt +31 -0
  33. package/dist/utils/log.d.ts +4 -0
  34. package/package.json +4 -1
  35. /package/dist/react/components/MdRenderer/{utils.d.ts → utils/md.d.ts} +0 -0
@@ -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,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,8 +10,10 @@ 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
@@ -24,7 +26,7 @@ export type UseChatProps = {
24
26
  export type UseChatReturn = {
25
27
  messages: Message[];
26
28
  status: 'uninitialized' | 'ready' | 'streaming' | 'error';
27
- error?: Error;
29
+ error?: unknown;
28
30
  /** 提交用户输入,让AI回答 */
29
31
  append: (query: string) => Promise<void>;
30
32
  /** 重新生成最后一条回答 */
@@ -39,6 +41,8 @@ export type UseChatReturn = {
39
41
  setSwipe: (messageId: string, swipeId: number) => Promise<void>;
40
42
  editMessage: (messageId: string, content: string) => Promise<void>;
41
43
  deleteMessage: (messageId: string) => Promise<void>;
44
+ loadMoreMessage: () => Promise<void>;
45
+ messagesStatus: 'all-loaded' | 'loading' | 'has-more' | 'error';
42
46
  };
43
47
  /**
44
48
  * Use chat common
@@ -52,4 +56,4 @@ export type UseChatCommon = {
52
56
  * Use chat
53
57
  * @returns {UseChatReturn} The chat.
54
58
  */
55
- export declare const useChat: ({ body, onError, onFinish, }: UseChatProps) => UseChatReturn;
59
+ export declare const useChat: ({ body, onError, onFinish, pageSize, }: UseChatProps) => UseChatReturn;
@@ -4,7 +4,7 @@ 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
  }
@@ -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,4 +1,3 @@
1
- /** biome-ignore-all lint/security/noDangerouslySetInnerHtml: <explanation> */
2
1
  import React from 'react';
3
2
  import './MdTheme.css';
4
3
  export type MdRendererProps = {
@@ -6,15 +5,17 @@ export type MdRendererProps = {
6
5
  * The markdown content to render
7
6
  */
8
7
  content: string;
8
+ unsafe?: boolean;
9
+ extra?: Record<string, unknown>;
9
10
  };
10
11
  /**
11
12
  * A React component that renders markdown content as HTML
12
13
  */
13
14
  export declare const MdRendererBase: {
14
- ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
15
+ ({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
15
16
  displayName: string;
16
17
  };
17
18
  export declare const MdRenderer: React.MemoExoticComponent<{
18
- ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
19
+ ({ content, unsafe, extra, }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
19
20
  displayName: string;
20
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';
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