Compare commits
1 Commits
main
...
ec383596db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec383596db |
@@ -18,7 +18,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@heroui/react": "2.8.3",
|
"@heroui/react": "2.8.3",
|
||||||
"@heroui/theme": "2.4.21",
|
"@heroui/theme": "2.4.21",
|
||||||
"@mujian/js-sdk": "0.0.6-beta.69",
|
"@mujian/js-sdk": "0.0.6-beta.mjv.68",
|
||||||
"@tailwindcss/vite": "4.1.12",
|
"@tailwindcss/vite": "4.1.12",
|
||||||
"ahooks": "3.9.5",
|
"ahooks": "3.9.5",
|
||||||
"axios": "1.11.0",
|
"axios": "1.11.0",
|
||||||
|
|||||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@@ -15,8 +15,8 @@ importers:
|
|||||||
specifier: 2.4.21
|
specifier: 2.4.21
|
||||||
version: 2.4.21(tailwindcss@4.1.12)
|
version: 2.4.21(tailwindcss@4.1.12)
|
||||||
'@mujian/js-sdk':
|
'@mujian/js-sdk':
|
||||||
specifier: 0.0.6-beta.69
|
specifier: 0.0.6-beta.mjv.68
|
||||||
version: 0.0.6-beta.69(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
version: 0.0.6-beta.mjv.68(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||||
'@tailwindcss/vite':
|
'@tailwindcss/vite':
|
||||||
specifier: 4.1.12
|
specifier: 4.1.12
|
||||||
version: 4.1.12(vite@7.1.2(@types/node@22.13.9)(jiti@2.5.1)(lightningcss@1.30.1))
|
version: 4.1.12(vite@7.1.2(@types/node@22.13.9)(jiti@2.5.1)(lightningcss@1.30.1))
|
||||||
@@ -996,8 +996,8 @@ packages:
|
|||||||
'@jridgewell/trace-mapping@0.3.30':
|
'@jridgewell/trace-mapping@0.3.30':
|
||||||
resolution: {integrity: sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==}
|
resolution: {integrity: sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==}
|
||||||
|
|
||||||
'@mujian/js-sdk@0.0.6-beta.69':
|
'@mujian/js-sdk@0.0.6-beta.mjv.68':
|
||||||
resolution: {integrity: sha512-hdiKHrbq+AngnV9e7woBTqnPhROJaejDgkFhh4IYpgAloIrarWuNbH1ZUvZU2G6Gqn1o4MwkymrXSmDXe9rMQA==}
|
resolution: {integrity: sha512-bsuev++lvRmS+fD36XljHIw6DnUTFzVrqV69IXKMTb7Vr8W70qQ1rMrn9gN8Lva996JZrXKQ39f3jFrRo1o53g==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: ~19.1.1
|
react: ~19.1.1
|
||||||
react-dom: ~19.1.1
|
react-dom: ~19.1.1
|
||||||
@@ -3942,12 +3942,11 @@ snapshots:
|
|||||||
'@jridgewell/resolve-uri': 3.1.2
|
'@jridgewell/resolve-uri': 3.1.2
|
||||||
'@jridgewell/sourcemap-codec': 1.5.5
|
'@jridgewell/sourcemap-codec': 1.5.5
|
||||||
|
|
||||||
'@mujian/js-sdk@0.0.6-beta.69(react-dom@19.1.1(react@19.1.1))(react@19.1.1)':
|
'@mujian/js-sdk@0.0.6-beta.mjv.68(react-dom@19.1.1(react@19.1.1))(react@19.1.1)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@adobe/css-tools': 4.4.4
|
'@adobe/css-tools': 4.4.4
|
||||||
ahooks: 3.9.5(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
ahooks: 3.9.5(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||||
dompurify: 3.3.1
|
dompurify: 3.3.1
|
||||||
lodash-es: 4.17.21
|
|
||||||
postmate: 1.5.2
|
postmate: 1.5.2
|
||||||
react: 19.1.1
|
react: 19.1.1
|
||||||
react-dom: 19.1.1(react@19.1.1)
|
react-dom: 19.1.1(react@19.1.1)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Alert, ScrollShadow, Spinner, ToastProvider } from '@heroui/react';
|
import { Alert, ScrollShadow, Spinner, ToastProvider } from '@heroui/react';
|
||||||
import { useChat, useMjEngine, useMujian } from '@mujian/js-sdk/react';
|
import { useChat, useMujian } from '@mujian/js-sdk/react';
|
||||||
|
import type { PersonaInfo, ProjectInfo } from '@mujian/js-sdk/types';
|
||||||
|
import * as _ from 'lodash-es';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useGlobalStore } from '@/store/global';
|
import { useGlobalStore } from '@/store/global';
|
||||||
import { mjChatCls } from '@/utils/cls';
|
import { mjChatCls } from '@/utils/cls';
|
||||||
@@ -8,6 +10,99 @@ import { MsgSend } from './MsgSend';
|
|||||||
import { PanicContext } from './PanicContext';
|
import { PanicContext } from './PanicContext';
|
||||||
import { QuickReply } from './QuickReply';
|
import { QuickReply } from './QuickReply';
|
||||||
|
|
||||||
|
let $mj_ai_chat_complete: ((message: string) => Promise<void>) | undefined;
|
||||||
|
let $mj_ai_chat_project: ProjectInfo | undefined;
|
||||||
|
let $mj_ai_chat_settings_persona: PersonaInfo | undefined;
|
||||||
|
let $mj_ai_chat_setFirstMesIndex:
|
||||||
|
| ((index: number) => Promise<void>)
|
||||||
|
| undefined;
|
||||||
|
let $mj_ai_chat_mjv_get:
|
||||||
|
| ((messageId: string, swipeId: number, path: string) => unknown)
|
||||||
|
| undefined;
|
||||||
|
let $mj_ai_chat_mjv_getAll:
|
||||||
|
| ((messageId: string, swipeId: number) => unknown)
|
||||||
|
| undefined;
|
||||||
|
|
||||||
|
// 扩展Window接口以包含chat对象
|
||||||
|
declare global {
|
||||||
|
interface MjEngineAiChat {
|
||||||
|
complete?: (message: string) => Promise<void>;
|
||||||
|
project?: ProjectInfo;
|
||||||
|
settings: {
|
||||||
|
persona?: PersonaInfo;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @param index 下标从1开始
|
||||||
|
*/
|
||||||
|
setFirstMesIndex?: (index: number) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MjEngineAi {
|
||||||
|
chat: MjEngineAiChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MjEngine {
|
||||||
|
ai: MjEngineAi;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Window {
|
||||||
|
$mj_engine: MjEngine & {
|
||||||
|
bind: (extra: { messageId: string; swipeId: number }) => MjEngine & {
|
||||||
|
ai: {
|
||||||
|
chat: {
|
||||||
|
mjv: {
|
||||||
|
get: (path: string) => unknown;
|
||||||
|
getAll: () => unknown;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const $mj_engine: MjEngine = {
|
||||||
|
ai: {
|
||||||
|
chat: {
|
||||||
|
get complete() {
|
||||||
|
return $mj_ai_chat_complete;
|
||||||
|
},
|
||||||
|
get project() {
|
||||||
|
return $mj_ai_chat_project;
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
get persona() {
|
||||||
|
return $mj_ai_chat_settings_persona;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
get setFirstMesIndex() {
|
||||||
|
return $mj_ai_chat_setFirstMesIndex;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
window.$mj_engine = {
|
||||||
|
...$mj_engine,
|
||||||
|
bind({ messageId, swipeId }) {
|
||||||
|
return {
|
||||||
|
ai: {
|
||||||
|
chat: {
|
||||||
|
...$mj_engine.ai.chat,
|
||||||
|
mjv: {
|
||||||
|
get(path) {
|
||||||
|
return $mj_ai_chat_mjv_get?.(messageId, swipeId, path);
|
||||||
|
},
|
||||||
|
getAll() {
|
||||||
|
return $mj_ai_chat_mjv_getAll?.(messageId, swipeId) ?? {};
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
export const Chat = () => {
|
export const Chat = () => {
|
||||||
const { init, projectInfo, activePersona } = useGlobalStore();
|
const { init, projectInfo, activePersona } = useGlobalStore();
|
||||||
const mujian = useMujian();
|
const mujian = useMujian();
|
||||||
@@ -31,6 +126,11 @@ export const Chat = () => {
|
|||||||
pageSize: 20,
|
pageSize: 20,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
$mj_ai_chat_project = projectInfo ?? undefined;
|
||||||
|
$mj_ai_chat_settings_persona = activePersona ?? undefined;
|
||||||
|
}, [projectInfo, activePersona]);
|
||||||
|
|
||||||
// 自定义删除消息函数
|
// 自定义删除消息函数
|
||||||
const handleDeleteMessage = async (messageId: string) => {
|
const handleDeleteMessage = async (messageId: string) => {
|
||||||
// 找到要删除的消息
|
// 找到要删除的消息
|
||||||
@@ -90,13 +190,35 @@ export const Chat = () => {
|
|||||||
[append, projectInfo, activePersona],
|
[append, projectInfo, activePersona],
|
||||||
);
|
);
|
||||||
|
|
||||||
useMjEngine({
|
// 将chat对象挂载到window上
|
||||||
projectInfo: projectInfo ?? undefined,
|
useEffect(() => {
|
||||||
activePersona: activePersona ?? undefined,
|
$mj_ai_chat_complete = async (message) => {
|
||||||
onSend,
|
await onSend(message);
|
||||||
messages,
|
};
|
||||||
setSwipe,
|
$mj_ai_chat_setFirstMesIndex = async (oneBasedIndex) => {
|
||||||
});
|
if (messages.length > 1) {
|
||||||
|
throw new Error('已有新消息,不允许切换开场白');
|
||||||
|
}
|
||||||
|
if (messages.length === 0) {
|
||||||
|
throw new Error('断言失败:没有开场消息,无法切换开场白');
|
||||||
|
}
|
||||||
|
const zeroBasedIndex = Math.floor(oneBasedIndex) - 1;
|
||||||
|
const swipeLength = messages[0].swipes.length;
|
||||||
|
if (zeroBasedIndex < 0 || zeroBasedIndex >= swipeLength) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setSwipe(messages[0].id, zeroBasedIndex);
|
||||||
|
};
|
||||||
|
$mj_ai_chat_mjv_getAll = (messageId, swipeId) =>
|
||||||
|
messages.find((m) => m.id === messageId)?.swipeInfo[swipeId]?.mjv?.value;
|
||||||
|
$mj_ai_chat_mjv_get = (messageId, swipeId, path) => {
|
||||||
|
const mjv = $mj_ai_chat_mjv_getAll?.(messageId, swipeId);
|
||||||
|
if (!mjv) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return _.get(mjv, path);
|
||||||
|
};
|
||||||
|
}, [onSend, messages, setSwipe]);
|
||||||
|
|
||||||
const handleInputChange = (value: string) => {
|
const handleInputChange = (value: string) => {
|
||||||
setInputValue(value);
|
setInputValue(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user