@mujian/js-sdk 0.0.6-beta.1

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 (37) hide show
  1. package/README.md +23 -0
  2. package/dist/events/index.d.ts +71 -0
  3. package/dist/index.d.ts +96 -0
  4. package/dist/index.js +220 -0
  5. package/dist/modules/ai/chat/chat.d.ts +35 -0
  6. package/dist/modules/ai/chat/index.d.ts +4 -0
  7. package/dist/modules/ai/chat/message/index.d.ts +43 -0
  8. package/dist/modules/ai/chat/project/index.d.ts +3 -0
  9. package/dist/modules/ai/chat/settings/index.d.ts +3 -0
  10. package/dist/modules/ai/chat/settings/model.d.ts +24 -0
  11. package/dist/modules/ai/chat/settings/persona.d.ts +17 -0
  12. package/dist/modules/ai/chat/settings/style.d.ts +0 -0
  13. package/dist/modules/ai/index.d.ts +5 -0
  14. package/dist/modules/ai/text/index.d.ts +2 -0
  15. package/dist/modules/game/index.d.ts +4 -0
  16. package/dist/modules/game/saves.d.ts +3 -0
  17. package/dist/modules/ui/index.d.ts +0 -0
  18. package/dist/react/chat/index.d.ts +1 -0
  19. package/dist/react/chat/useChat/error.d.ts +15 -0
  20. package/dist/react/chat/useChat/index.d.ts +55 -0
  21. package/dist/react/chat/useChat/inner/chatStreaming.d.ts +23 -0
  22. package/dist/react/chat/useChat/inner/stream.d.ts +3 -0
  23. package/dist/react/chat/useChat/message.d.ts +37 -0
  24. package/dist/react/components/MdRenderer/index.d.ts +20 -0
  25. package/dist/react/components/MdRenderer/utils.d.ts +38 -0
  26. package/dist/react/components/MujianProvider/index.d.ts +17 -0
  27. package/dist/react/components/Thread/MessageItem.d.ts +21 -0
  28. package/dist/react/components/Thread/MessageList.d.ts +19 -0
  29. package/dist/react/components/Thread/index.d.ts +4 -0
  30. package/dist/react/components/button.d.ts +14 -0
  31. package/dist/react/components/index.d.ts +4 -0
  32. package/dist/react/index.d.ts +2 -0
  33. package/dist/react.css +156 -0
  34. package/dist/react.js +832 -0
  35. package/dist/types/index.d.ts +27 -0
  36. package/dist/utils/index.d.ts +0 -0
  37. package/package.json +89 -0
@@ -0,0 +1,37 @@
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
+ export type Message = {
8
+ id: string;
9
+ role: Role;
10
+ content: string;
11
+ swipes: Array<string>;
12
+ activeSwipeId: number;
13
+ sendAt: Date;
14
+ isStreaming: boolean;
15
+ };
16
+ export type RawData = {
17
+ id: string;
18
+ provider: string;
19
+ model: string;
20
+ object: string;
21
+ created: number;
22
+ choices: [
23
+ {
24
+ index: number;
25
+ delta: {
26
+ role: string;
27
+ content: string;
28
+ reasoning: string;
29
+ };
30
+ finish_reason: string | null;
31
+ native_finish_reason: string | null;
32
+ logprobs: string | null;
33
+ }
34
+ ];
35
+ question_id: string;
36
+ reply_id: string;
37
+ };
@@ -0,0 +1,20 @@
1
+ /** biome-ignore-all lint/security/noDangerouslySetInnerHtml: <explanation> */
2
+ import React from 'react';
3
+ import './MdTheme.css';
4
+ export type MdRendererProps = {
5
+ /**
6
+ * The markdown content to render
7
+ */
8
+ content: string;
9
+ };
10
+ /**
11
+ * A React component that renders markdown content as HTML
12
+ */
13
+ export declare const MdRendererBase: {
14
+ ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
17
+ export declare const MdRenderer: React.MemoExoticComponent<{
18
+ ({ content }: MdRendererProps): import("react/jsx-runtime").JSX.Element;
19
+ displayName: string;
20
+ }>;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Replaces style tags in the message text with custom tags with encoded content.
3
+ * @param {string} text
4
+ * @returns {string} Encoded message text
5
+ * @copyright https://github.com/kwaroran/risuAI
6
+ */
7
+ export declare function encodeStyleTags(text: string): string;
8
+ /**
9
+ * Sanitizes custom style tags in the message text to prevent DOM pollution.
10
+ * @param {string} text Message text
11
+ * @param {object} options Options object
12
+ * @param {string} options.prefix Prefix the selectors with this value
13
+ * @returns {string} Sanitized message text
14
+ * @copyright https://github.com/kwaroran/risuAI
15
+ */
16
+ export declare function decodeStyleTags(text: string, { prefix }?: {
17
+ prefix: string;
18
+ }): string;
19
+ export declare const markdownUnderscoreExt: () => {
20
+ type: string;
21
+ regex: RegExp;
22
+ replace: (match: string, tagContent: string, italicContent: string) => string;
23
+ }[];
24
+ /**
25
+ * @enum {number} Where the regex script should be applied
26
+ */
27
+ /**
28
+ * Formats the message text into an HTML string using Markdown and other formatting.
29
+ * @param {string} mes Message text
30
+ * @param {string} ch_name Character name
31
+ * @param {boolean} isSystem If the message was sent by the system
32
+ * @param {boolean} isUser If the message was sent by the user
33
+ * @param {number} messageId Message index in chat array
34
+ * @param {object} [sanitizerOverrides] DOMPurify sanitizer option overrides
35
+ * @param {boolean} [isReasoning] If the message is reasoning output
36
+ * @returns {string} HTML string
37
+ */
38
+ export declare function messageFormatting(mes: any, sanitizerOverrides?: any): any;
@@ -0,0 +1,17 @@
1
+ import { type ReactNode } from 'react';
2
+ import { MujianSdk } from '../../../index.ts';
3
+ export type MujianProviderProps = {
4
+ /**
5
+ * Children to be rendered
6
+ */
7
+ children: ReactNode;
8
+ /**
9
+ * Loading component to be rendered
10
+ */
11
+ loadingComponent?: ReactNode;
12
+ };
13
+ /**
14
+ * A React component that provides the Mujian SDK instance to its children
15
+ */
16
+ export declare const MujianProvider: ({ children, loadingComponent, }: MujianProviderProps) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const useMujian: () => MujianSdk;
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from 'react';
2
+ import { Message as MessageType } from '../../chat';
3
+ export interface MessageItemProps {
4
+ /**
5
+ * Message
6
+ */
7
+ message: MessageType;
8
+ /**
9
+ * Children to be rendered
10
+ */
11
+ children: (message: MessageType, originalMessage: MessageType) => ReactNode;
12
+ /**
13
+ * Message index, the oldest message is 0
14
+ */
15
+ index: number;
16
+ /**
17
+ * Message depth, the latest messages is 0
18
+ */
19
+ depth: number;
20
+ }
21
+ export declare const MessageItem: (props: MessageItemProps) => ReactNode;
@@ -0,0 +1,19 @@
1
+ import { ReactElement } from 'react';
2
+ import { VListHandle, VListProps } from 'virtua';
3
+ import { Message as MessageType } from '../../chat';
4
+ import { MessageItemProps } from './MessageItem';
5
+ export interface MessageListProps {
6
+ /**
7
+ * Messages
8
+ */
9
+ messages: Array<MessageType>;
10
+ /**
11
+ * Children to be rendered
12
+ */
13
+ children: (props: Omit<MessageItemProps, 'children'>) => ReactElement;
14
+ /**
15
+ * Virtua props
16
+ */
17
+ vListProps?: Omit<VListProps, 'children' | 'data'>;
18
+ }
19
+ export declare const MessageList: import("react").ForwardRefExoticComponent<MessageListProps & import("react").RefAttributes<VListHandle>>;
@@ -0,0 +1,4 @@
1
+ export declare const Thread: {
2
+ MessageItem: (props: import("./MessageItem").MessageItemProps) => import("react").ReactNode;
3
+ MessageList: import("react").ForwardRefExoticComponent<import("./MessageList").MessageListProps & import("react").RefAttributes<import("virtua").VListHandle>>;
4
+ };
@@ -0,0 +1,14 @@
1
+ export type ButtonProps = {
2
+ /**
3
+ * Whether to disable the button
4
+ * - This is extra line a
5
+ * - This is extra line b
6
+ */
7
+ disabled?: boolean;
8
+ /**
9
+ * Type of Button
10
+ * @default 'default'
11
+ */
12
+ size?: 'mini' | 'small' | 'default' | 'large';
13
+ };
14
+ export declare const Button: (_props?: ButtonProps) => void;
@@ -0,0 +1,4 @@
1
+ export type { VListHandle } from 'virtua';
2
+ export { MdRenderer } from './MdRenderer';
3
+ export { MujianProvider, useMujian } from './MujianProvider';
4
+ export { Thread } from './Thread';
@@ -0,0 +1,2 @@
1
+ export * from './chat';
2
+ export * from './components';
package/dist/react.css ADDED
@@ -0,0 +1,156 @@
1
+ :root {
2
+ --doc-height: 1102px;
3
+ --SmartThemeBodyColor: #abc6df;
4
+ --SmartThemeCheckboxBgColorR: 171;
5
+ --SmartThemeCheckboxBgColorG: 198;
6
+ --SmartThemeCheckboxBgColorB: 223;
7
+ --SmartThemeCheckboxBgColorA: 1;
8
+ --SmartThemeEmColor: #fff;
9
+ --SmartThemeUnderlineColor: #bce7cf;
10
+ --SmartThemeQuoteColor: #6f85fd;
11
+ --SmartThemeBlurTintColor: #171e219c;
12
+ --SmartThemeChatTintColor: #17171700;
13
+ --SmartThemeUserMesBlurTintColor: #001cae33;
14
+ --SmartThemeBotMesBlurTintColor: #000d3938;
15
+ --SmartThemeShadowColor: #000;
16
+ --SmartThemeBorderColor: #00000080;
17
+ --animation-duration: .125s;
18
+ --fontScale: 1;
19
+ --sheldWidth: 50vw;
20
+ --blurStrength: 11;
21
+ --shadowWidth: 5;
22
+ --black30a: #0000004d;
23
+ --SmartThemeQuoteBg: linear-gradient(90deg, #00e1ff 39%, #ff04e6 100%) text;
24
+ }
25
+
26
+ .mes q:before, .mes q:after, .mes_text q:before, .mes_text q:after {
27
+ content: "";
28
+ }
29
+
30
+ .mes_text br {
31
+ display: none;
32
+ }
33
+
34
+ .mes_text table {
35
+ border-spacing: 0;
36
+ border-collapse: collapse;
37
+ margin-bottom: 16px;
38
+ }
39
+
40
+ .mes_text td, .mes_text th {
41
+ border-collapse: collapse;
42
+ border: 1px solid;
43
+ padding: .25em;
44
+ }
45
+
46
+ .mes_text p {
47
+ color: var(--SmartThemeBodyColor);
48
+ margin-top: 0;
49
+ margin-bottom: 16px;
50
+ }
51
+
52
+ .mes_text {
53
+ color: var(--SmartThemeBodyColor);
54
+ }
55
+
56
+ .mes_text p:only-child, .mes_text p:only-of-type {
57
+ margin-bottom: 0;
58
+ }
59
+
60
+ .mes_text ol {
61
+ unicode-bidi: isolate;
62
+ margin-block: 1em;
63
+ margin-inline: 0;
64
+ padding-inline-start: 40px;
65
+ list-style-type: decimal;
66
+ display: block;
67
+ }
68
+
69
+ .mes_text li tt {
70
+ display: inline-block;
71
+ }
72
+
73
+ .mes_text li {
74
+ position: relative;
75
+ }
76
+
77
+ .mes_text ol, .mes_text ul {
78
+ margin-top: 5px;
79
+ margin-bottom: 5px;
80
+ }
81
+
82
+ .mes_text br, .mes_bias br {
83
+ content: " ";
84
+ margin: 2px 0;
85
+ display: block;
86
+ }
87
+
88
+ .mes_bias {
89
+ font-size: calc(var(--mainFontSize) - .1rem);
90
+ color: var(--SmartThemeQuoteColor);
91
+ font-weight: 500;
92
+ display: block;
93
+ }
94
+
95
+ .mes_text i, .mes_text em {
96
+ color: var(--SmartThemeEmColor);
97
+ }
98
+
99
+ .mes_text u {
100
+ color: var(--SmartThemeUnderlineColor);
101
+ }
102
+
103
+ .mes_text q {
104
+ color: #00e1ff;
105
+ }
106
+
107
+ .mes_text font[color] em, .mes_text font[color] i, .mes_text font[color] q {
108
+ color: inherit;
109
+ }
110
+
111
+ .mes_text rp {
112
+ display: block;
113
+ }
114
+
115
+ .mes_text blockquote {
116
+ border-left: 3px solid var(--SmartThemeQuoteColor);
117
+ background-color: var(--black30a);
118
+ width: 100%;
119
+ margin-bottom: 16px;
120
+ padding-left: 10px;
121
+
122
+ & p {
123
+ margin: 0;
124
+ }
125
+ }
126
+
127
+ .mes_text strong em, .mes_text strong, .mes_text h2, .mes_text h1 {
128
+ font-weight: bold;
129
+ }
130
+
131
+ .mes_text pre code, code {
132
+ padding: 1em;
133
+ display: block;
134
+ position: relative;
135
+ overflow-x: auto;
136
+ }
137
+
138
+ .mes_text img:not(.mes_img), .mes_reasoning img:not(.mes_img) {
139
+ max-width: 100%;
140
+ max-height: var(--doc-height);
141
+ object-fit: contain;
142
+ height: auto !important;
143
+ }
144
+
145
+ .mes-dialogue {
146
+ background: var(--SmartThemeQuoteBg);
147
+ -webkit-text-fill-color: transparent;
148
+ color: #0000;
149
+ -webkit-background-clip: text;
150
+ background-clip: text;
151
+ }
152
+
153
+ .mes_text img {
154
+ width: 100%;
155
+ }
156
+