This commit is contained in:
rex
2025-11-24 21:13:06 +08:00
parent 60b278045e
commit f7bdb20332
11 changed files with 224 additions and 93 deletions

8
.cursor/mcp.json Normal file
View File

@@ -0,0 +1,8 @@
{
"mcpServers": {
// "mujian": {
// "command": "npx",
// "args": ["-y", "@mujian/mcp-docs-server"]
// }
}
}

26
.cursor/rules/general.mdc Normal file
View File

@@ -0,0 +1,26 @@
---
description: 工程全局规则
alwaysApply: true
---
你是一个游戏开发Agent需要在本工程中协助我开发一个 HTML 游戏。
## 本工程介绍
- 这是一个模版工程,开发者会基于这个工程进行拓展开发
- 本工程采用 Vite + React 框架是一个React SPA架构的游戏/应用
- 本工程强烈建议使用如下前端NPM包
- react-router: 用于管理页面和路由
- zustand: 用于React状态管理
- TailwindCSS: 用于编写样式和管理主题
- axios用于发起http请求。包括上传和SSE场景。
- dayjs: 用于处理日期
- localforage: 用于管理Storage
- react-icons: 用于使用图标
- motion: 动效库
- loadsh-es: 用于提供一些常用的utils函数
## 你需要遵循的规则
- Always respond in 中文
- 只能新增、修改和删除 src 目录里的文件或者文件夹,严禁修改其他文件或者文件夹!

2
.trae/.ignore Normal file
View File

@@ -0,0 +1,2 @@
!src/**
!public/**

View File

View File

@@ -1,93 +0,0 @@
# h5-boilerplate
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.lbyc.dev/mujian/frontend/ugc-boilerplate/h5-boilerplate.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.lbyc.dev/mujian/frontend/ugc-boilerplate/h5-boilerplate/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

5
assets/css/index.css Normal file
View File

@@ -0,0 +1,5 @@
#project-info-img {
width: 64px;
height: 64px;
object-fit: cover;
}

9
assets/img/logo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 23 KiB

59
assets/js/chat.js Normal file
View File

@@ -0,0 +1,59 @@
const mujianSdk = new window.MujianUMD.MujianSdk();
async function chat(
query,
cb,
) {
let lastChunk = '';
// 让缓冲区跨回调持久,防止分包导致的半行重复解析
let buffer = '';
await mujianSdk.ai.chat.complete(query, (data) => {
// data 可能是块状字符串;避免逐字符遍历
buffer += data;
const lines = buffer.split('\n');
buffer = lines.pop() || '';
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const payload = line.slice(6);
try {
const parsedData = JSON.parse(payload);
if (parsedData?.isFinished) {
// 结束标志,交给外层 await 完成
continue;
}
let content = parsedData?.choices?.[0]?.delta?.content;
// if (content && typeof window !== 'undefined') {
// const username = localStorage.getItem(USERNAME_KEY) || 'User';
// content = content?.replace(new RegExp(FAKE_USERNAME, 'g'), username);
// }
if (content !== undefined && content !== null) {
if (content.length > 0) {
lastChunk += content;
cb && cb(lastChunk);
}
} else {
console.error('data', payload);
}
} catch (error) {
console.log('error', error);
throw error;
}
}
});
// console.log('lastChunk', lastChunk);
return lastChunk;
}
mujianSdk.init().then(() => {
chat('你好', (res) => {
// console.log('res', res)
$('#message').text(res);
})
});

16
assets/js/index.js Normal file
View File

@@ -0,0 +1,16 @@
const mujianSdk = new window.MujianUMD.MujianSdk();
mujianSdk.init().then(() => {
console.log('init success');
mujianSdk.ai.chat.project.getInfo().then((res) => {
console.log('getProjectInfo success', res);
window.document.getElementById('project-info').innerHTML = `<pre>${JSON.stringify(res, null, 2)}</pre>`;
window.document.getElementById('project-info-img').src = res.coverImageUrl;
});
mujianSdk.ai.chat.settings.persona.getActive().then((res) => {
console.log('getPersonaInfo success', res);
// 支持 JQuery 操作页面元素
$('#persona-info').html(JSON.stringify(res));
});
});

36
chat.html Normal file
View File

@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chat示例</title>
<!-- 第三方库JQuery-UI - 主要用于提供基础的UI控件 -->
<link
rel="stylesheet"
href="https://npm.onmicrosoft.cn/jquery-ui@1.14.1/dist/themes/base/theme.css"
/>
<!-- 你的 CSS 样式代码,都放在这里 -->
<link rel="stylesheet" href="assets/css/index.css" />
</head>
<body>
<div id="message"></div>
<!-- 幕间官方SDK -->
<script src="https://npm.onmicrosoft.cn/@mujian/js-sdk@0.0.6-beta.35/dist/umd/index.js"></script>
<!-- 第三方库JQuery - 主要用于提供便利地操作页面元素的函数 -->
<script src="https://npm.onmicrosoft.cn/jquery@3.7.1/dist/jquery.min.js"></script>
<!-- 第三方库JQuery-UI - 主要用于提供基础的UI控件 -->
<script src="https://npm.onmicrosoft.cn/jquery-ui@1.14.1/dist/jquery-ui.min.js"></script>
<!-- 第三方库fontawesome - 主要用于提供图标 -->
<script src="https://npm.onmicrosoft.cn/@fortawesome/fontawesome-free@7.1.0/js/all.min.js"></script>
<!-- 你的 JS 代码,都放在这里 -->
<script src="assets/js/chat.js"></script>
</body>
</html>

63
index.html Normal file
View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>幕间UGC自定义界面项目模版</title>
<!-- 第三方库JQuery-UI - 主要用于提供基础的UI控件 -->
<link
rel="stylesheet"
href="https://npm.onmicrosoft.cn/jquery-ui@1.14.1/dist/themes/base/theme.css"
/>
<!-- 你的 CSS 样式代码,都放在这里 -->
<link rel="stylesheet" href="assets/css/index.css" />
</head>
<body>
<h2>
<img
id="logo"
src="assets/img/logo.svg"
alt="幕间UGC模版"
/>幕间UGC自定义界面项目模版
</h2>
<h3>获取项目信息</h3>
<div id="project-info"></div>
<div>
这是作品封面,你可以获取到
<img id="project-info-img" src="" alt="封面图" />
</div>
<h3>Chat示例</h3>
<button class="ui-button ui-widget ui-corner-all" onclick="window.location.href = '/chat'">前往Chat示例</button>
<h3>获取当前人设</h3>
<div id="persona-info"></div>
<h3>三方库示例</h3>
<i class="fa-solid fa-user"></i>
<button class="ui-button ui-widget ui-corner-all">jquery-ui按钮</button>
<!-- 幕间官方SDK -->
<script src="https://npm.onmicrosoft.cn/@mujian/js-sdk@0.0.6-beta.35/dist/umd/index.js"></script>
<!-- 第三方库JQuery - 主要用于提供便利地操作页面元素的函数 -->
<script src="https://npm.onmicrosoft.cn/jquery@3.7.1/dist/jquery.min.js"></script>
<!-- 第三方库JQuery-UI - 主要用于提供基础的UI控件 -->
<script src="https://npm.onmicrosoft.cn/jquery-ui@1.14.1/dist/jquery-ui.min.js"></script>
<!-- 第三方库fontawesome - 主要用于提供图标 -->
<script src="https://npm.onmicrosoft.cn/@fortawesome/fontawesome-free@7.1.0/js/all.min.js"></script>
<!-- 你的 JS 代码,都放在这里 -->
<script src="assets/js/index.js"></script>
<!-- 可以把不同功能的代码,拆分到不同文件内,方便管理和修改 -->
<!-- <script src="assets/js/other.js"></script> -->
</body>
</html>