From f9dd9297b8b516b10c245dcebc02f27c11643024 Mon Sep 17 00:00:00 2001
From: zhanjunhao <642307404@qq.com>
Date: Tue, 27 Oct 2026 17:25:25 +0800
Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=20Playground=20?=
=?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E7=9B=AE=E5=BD=95=E4=B8=8E=E5=BC=95?=
=?UTF-8?q?=E7=94=A8=E8=B7=AF=E5=BE=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 3 +--
docs/PROJECT_ANALYSIS.zh-CN.md | 5 ++---
src/components/playground/ChatArea.jsx | 2 +-
src/components/playground/CustomInputRender.jsx | 2 +-
src/components/playground/MessageContent.jsx | 2 +-
.../Playground/index.ts} | 10 +++-------
src/pages/Playground/index.jsx | 2 +-
7 files changed, 10 insertions(+), 16 deletions(-)
rename src/{contexts/PlaygroundContext.jsx => context/Playground/index.ts} (90%)
diff --git a/README.md b/README.md
index 1a723c75..9ef73139 100644
--- a/README.md
+++ b/README.md
@@ -117,8 +117,7 @@ monkey-ai-web/
│ ├── components/ # 通用及业务组件,含 layout、auth、settings
│ ├── pages/ # 页面和业务模块
│ ├── hooks/ # 按业务拆分的数据与交互逻辑
-│ ├── context/ # User、Status、Theme、Org 等状态
-│ ├── contexts/ # PlaygroundContext;与 context/ 均为现有目录
+│ ├── context/ # User、Status、Theme、Org、Playground 等状态
│ ├── helpers/ # API 实例、鉴权、配置、主题、通用工具
│ ├── services/ # 会话、安全验证等服务封装
│ ├── constants/ # 业务常量和接口定义
diff --git a/docs/PROJECT_ANALYSIS.zh-CN.md b/docs/PROJECT_ANALYSIS.zh-CN.md
index 81b082d2..a9d258e9 100644
--- a/docs/PROJECT_ANALYSIS.zh-CN.md
+++ b/docs/PROJECT_ANALYSIS.zh-CN.md
@@ -205,8 +205,7 @@ monkey-ai-web/
│ ├── pages/ 业务页面;部分包含自己的组件和子路由
│ ├── components/ 公共组件及跨页面业务组件
│ ├── hooks/ 按业务分类的数据、状态与交互逻辑
-│ ├── context/ User、Status、Theme、Org 等 Context 定义
-│ ├── contexts/ PlaygroundContext,现有独立目录
+│ ├── context/ User、Status、Theme、Org、Playground 等 Context 定义
│ ├── services/ 会话、安全验证等可复用服务调用
│ ├── helpers/ API、权限、配置、主题和工具函数
│ ├── constants/ 接口地址、消息状态、菜单和业务常量
@@ -555,7 +554,7 @@ npm run preview
| 依赖管理已统一 | 删除旧 Bun 锁并保留匹配清单的 npm 锁 | npm ci 已验证,依赖更新须同步提交锁文件 |
| 运行时约束 | engines 与 packageManager 已声明 Node/npm 要求 | CI 应使用已验证版本 |
| 部分说明落后于源码 | 体验中心子目录 README 仍使用 `web/src` 并描述图片、视频为占位功能 | 阅读时以当前入口、Hook 和接口调用为准 |
-| 分层与命名存在历史差异 | `context/` 与 `contexts/` 并存,部分页面直接请求接口 | 新改动保持局部一致,按业务收益渐进整理,避免无目标的大规模搬迁 |
+| 分层与命名存在历史差异 | Context 已统一至 `context/`,部分页面仍直接请求接口 | 新改动保持局部一致,按业务收益渐进整理,避免无目标的大规模搬迁 |
统计脚本由 Vite 的 `loadEnv` 按当前 mode 读取 `VITE_UMAMI_WEBSITE_ID`、`VITE_UMAMI_SCRIPT_URL`、`VITE_GOOGLE_ANALYTICS_ID`;支持开发/生产环境文件与本地覆盖文件,终端或 CI 的同名变量优先,ID 留空时禁用注入。
diff --git a/src/components/playground/ChatArea.jsx b/src/components/playground/ChatArea.jsx
index 8a88e362..697accd7 100644
--- a/src/components/playground/ChatArea.jsx
+++ b/src/components/playground/ChatArea.jsx
@@ -61,7 +61,7 @@ import {
selectFilter,
countRounds,
} from '../../helpers';
-import { usePlayground } from '../../contexts/PlaygroundContext';
+import { usePlayground } from '../../context/Playground';
import { StatusContext } from '../../context/Status';
const ChatArea = ({
diff --git a/src/components/playground/CustomInputRender.jsx b/src/components/playground/CustomInputRender.jsx
index f0f29a7e..da48c182 100644
--- a/src/components/playground/CustomInputRender.jsx
+++ b/src/components/playground/CustomInputRender.jsx
@@ -35,7 +35,7 @@ import {
} from 'lucide-react';
import { useSpeechRecognition } from '../../hooks/playground/useSpeechRecognition';
import { useTranslation } from 'react-i18next';
-import { usePlayground } from '../../contexts/PlaygroundContext';
+import { usePlayground } from '../../context/Playground';
import {
getExperienceCenterBool,
getExperienceCenterPositiveInt,
diff --git a/src/components/playground/MessageContent.jsx b/src/components/playground/MessageContent.jsx
index 8c218e39..2f4ec81a 100644
--- a/src/components/playground/MessageContent.jsx
+++ b/src/components/playground/MessageContent.jsx
@@ -41,7 +41,7 @@ import { useTranslation } from 'react-i18next';
// 同名遮蔽在 Vite/terser 生产构建里会把两者缩成同一个变量名,触发 TDZ 错误:
// "Cannot access 'Oe' before initialization"
// 本地函数签名是 (content) 而非 helpers 里的 (message),调用时记得传 message.content。
-import { usePlayground } from '../../contexts/PlaygroundContext';
+import { usePlayground } from '../../context/Playground';
import { useSpeechSynthesis } from '../../hooks/playground/useSpeechSynthesis';
const MessageContent = ({
diff --git a/src/contexts/PlaygroundContext.jsx b/src/context/Playground/index.ts
similarity index 90%
rename from src/contexts/PlaygroundContext.jsx
rename to src/context/Playground/index.ts
index f0f06173..eff24e49 100644
--- a/src/contexts/PlaygroundContext.jsx
+++ b/src/context/Playground/index.ts
@@ -17,10 +17,10 @@ along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
-import React, { createContext, useContext } from 'react';
+import { createContext, createElement, useContext } from 'react';
/**
- * Context for Playground component to share image handling functionality
+ * Share Playground input, upload, search, and image generation functionality.
*/
const PlaygroundContext = createContext(null);
@@ -73,11 +73,7 @@ export const usePlayground = () => {
* @returns {JSX.Element} Provider component
*/
export const PlaygroundProvider = ({ children, value }) => {
- return (
-
- {children}
-
- );
+ return createElement(PlaygroundContext.Provider, { value }, children);
};
export default PlaygroundContext;
diff --git a/src/pages/Playground/index.jsx b/src/pages/Playground/index.jsx
index 5c7e4c5a..512abfda 100644
--- a/src/pages/Playground/index.jsx
+++ b/src/pages/Playground/index.jsx
@@ -95,7 +95,7 @@ import MessageSelectableWrapper from '../../components/playground/MessageSelecta
import FloatingButtons from '../../components/playground/FloatingButtons';
import SessionSidebar from '../../components/playground/SessionSidebar';
import KeyboardShortcutsModal from '../../components/playground/KeyboardShortcutsModal';
-import { PlaygroundProvider } from '../../contexts/PlaygroundContext';
+import { PlaygroundProvider } from '../../context/Playground';
const Playground = ({ isExperienceMode = false }) => {
const { t } = useTranslation();