0.6.1-patch-1
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"dependencies": {
|
||||
"@heroui/react": "2.8.3",
|
||||
"@heroui/theme": "2.4.21",
|
||||
"@mujian/js-sdk": "0.0.6-beta.mjv.68",
|
||||
"@mujian/js-sdk": "0.0.6-beta.69",
|
||||
"@tailwindcss/vite": "4.1.12",
|
||||
"ahooks": "3.9.5",
|
||||
"axios": "1.11.0",
|
||||
|
||||
11
pnpm-lock.yaml
generated
11
pnpm-lock.yaml
generated
@@ -15,8 +15,8 @@ importers:
|
||||
specifier: 2.4.21
|
||||
version: 2.4.21(tailwindcss@4.1.12)
|
||||
'@mujian/js-sdk':
|
||||
specifier: 0.0.6-beta.mjv.68
|
||||
version: 0.0.6-beta.mjv.68(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
specifier: 0.0.6-beta.69
|
||||
version: 0.0.6-beta.69(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
'@tailwindcss/vite':
|
||||
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))
|
||||
@@ -996,8 +996,8 @@ packages:
|
||||
'@jridgewell/trace-mapping@0.3.30':
|
||||
resolution: {integrity: sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==}
|
||||
|
||||
'@mujian/js-sdk@0.0.6-beta.mjv.68':
|
||||
resolution: {integrity: sha512-bsuev++lvRmS+fD36XljHIw6DnUTFzVrqV69IXKMTb7Vr8W70qQ1rMrn9gN8Lva996JZrXKQ39f3jFrRo1o53g==}
|
||||
'@mujian/js-sdk@0.0.6-beta.69':
|
||||
resolution: {integrity: sha512-hdiKHrbq+AngnV9e7woBTqnPhROJaejDgkFhh4IYpgAloIrarWuNbH1ZUvZU2G6Gqn1o4MwkymrXSmDXe9rMQA==}
|
||||
peerDependencies:
|
||||
react: ~19.1.1
|
||||
react-dom: ~19.1.1
|
||||
@@ -3942,11 +3942,12 @@ snapshots:
|
||||
'@jridgewell/resolve-uri': 3.1.2
|
||||
'@jridgewell/sourcemap-codec': 1.5.5
|
||||
|
||||
'@mujian/js-sdk@0.0.6-beta.mjv.68(react-dom@19.1.1(react@19.1.1))(react@19.1.1)':
|
||||
'@mujian/js-sdk@0.0.6-beta.69(react-dom@19.1.1(react@19.1.1))(react@19.1.1)':
|
||||
dependencies:
|
||||
'@adobe/css-tools': 4.4.4
|
||||
ahooks: 3.9.5(react-dom@19.1.1(react@19.1.1))(react@19.1.1)
|
||||
dompurify: 3.3.1
|
||||
lodash-es: 4.17.21
|
||||
postmate: 1.5.2
|
||||
react: 19.1.1
|
||||
react-dom: 19.1.1(react@19.1.1)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { Alert, ScrollShadow, Spinner, ToastProvider } from '@heroui/react';
|
||||
import { useChat, useMujian } from '@mujian/js-sdk/react';
|
||||
import type { PersonaInfo, ProjectInfo } from '@mujian/js-sdk/types';
|
||||
import * as _ from 'lodash-es';
|
||||
import { useChat, useMjEngine, useMujian } from '@mujian/js-sdk/react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useGlobalStore } from '@/store/global';
|
||||
import { mjChatCls } from '@/utils/cls';
|
||||
@@ -10,99 +8,6 @@ import { MsgSend } from './MsgSend';
|
||||
import { PanicContext } from './PanicContext';
|
||||
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 = () => {
|
||||
const { init, projectInfo, activePersona } = useGlobalStore();
|
||||
const mujian = useMujian();
|
||||
@@ -126,11 +31,6 @@ export const Chat = () => {
|
||||
pageSize: 20,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
$mj_ai_chat_project = projectInfo ?? undefined;
|
||||
$mj_ai_chat_settings_persona = activePersona ?? undefined;
|
||||
}, [projectInfo, activePersona]);
|
||||
|
||||
// 自定义删除消息函数
|
||||
const handleDeleteMessage = async (messageId: string) => {
|
||||
// 找到要删除的消息
|
||||
@@ -190,35 +90,13 @@ export const Chat = () => {
|
||||
[append, projectInfo, activePersona],
|
||||
);
|
||||
|
||||
// 将chat对象挂载到window上
|
||||
useEffect(() => {
|
||||
$mj_ai_chat_complete = async (message) => {
|
||||
await onSend(message);
|
||||
};
|
||||
$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]);
|
||||
useMjEngine({
|
||||
projectInfo: projectInfo ?? undefined,
|
||||
activePersona: activePersona ?? undefined,
|
||||
onSend,
|
||||
messages,
|
||||
setSwipe,
|
||||
});
|
||||
|
||||
const handleInputChange = (value: string) => {
|
||||
setInputValue(value);
|
||||
|
||||
Reference in New Issue
Block a user