From 05969b3fd0b3073bee38b6a919b3979916f33203 Mon Sep 17 00:00:00 2001 From: CanisMinor Date: Sat, 27 Jan 2024 13:01:46 +0800 Subject: [PATCH] Initial commit --- .bunfig.toml | 3 + .changelogrc.js | 1 + .commitlintrc.js | 1 + .editorconfig | 16 ++ .eslintignore | 30 +++ .eslintrc.js | 1 + .github/ISSUE_TEMPLATE/1_bug_report.yml | 45 ++++ .github/ISSUE_TEMPLATE/2_feature_request.yml | 21 ++ .github/ISSUE_TEMPLATE/3_question.yml | 15 ++ .github/ISSUE_TEMPLATE/other.md | 7 + .github/PULL_REQUEST_TEMPLATE.md | 17 ++ .github/workflows/issue-auto-comments.yml | 72 ++++++ .github/workflows/issue-check-inactive.yml | 23 ++ .github/workflows/issue-close-require.yml | 52 +++++ .github/workflows/release.yml | 33 +++ .github/workflows/test.yml | 27 +++ .gitignore | 52 +++++ .husky/commit-msg | 4 + .husky/pre-commit | 4 + .npmrc | 11 + .prettierignore | 61 +++++ .prettierrc.js | 1 + .releaserc.js | 1 + .remarkrc.js | 1 + .stylelintrc.js | 1 + CHANGELOG.md | 230 +++++++++++++++++++ LICENSE | 21 ++ README.md | 175 ++++++++++++++ docs/.dumirc.ts | 56 +++++ docs/docs/changelog.md | 9 + docs/docs/data.ts | 7 + docs/docs/demo.tsx | 7 + docs/docs/index.md | 7 + docs/package.json | 14 ++ docs/tsconfig.json | 29 +++ next-env.d.ts | 5 + next.config.mjs | 25 ++ package.json | 90 ++++++++ public/manifest-dev.json | 42 ++++ public/manifest-markdown.json | 38 +++ public/manifest-standalone.json | 41 ++++ renovate.json | 13 ++ src/components/Render.tsx | 38 +++ src/data.ts | 173 ++++++++++++++ src/pages/_app.tsx | 12 + src/pages/api/clothes-md.ts | 26 +++ src/pages/api/clothes.ts | 24 ++ src/pages/api/gateway.ts | 13 ++ src/pages/global.css | 12 + src/pages/iframe/index.tsx | 53 +++++ src/pages/index.tsx | 19 ++ src/services/clothes.ts | 10 + src/type.ts | 16 ++ tsconfig.json | 30 +++ vitest.config.ts | 8 + 55 files changed, 1743 insertions(+) create mode 100644 .bunfig.toml create mode 100644 .changelogrc.js create mode 100644 .commitlintrc.js create mode 100644 .editorconfig create mode 100644 .eslintignore create mode 100644 .eslintrc.js create mode 100644 .github/ISSUE_TEMPLATE/1_bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/2_feature_request.yml create mode 100644 .github/ISSUE_TEMPLATE/3_question.yml create mode 100644 .github/ISSUE_TEMPLATE/other.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/issue-auto-comments.yml create mode 100644 .github/workflows/issue-check-inactive.yml create mode 100644 .github/workflows/issue-close-require.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-commit create mode 100644 .npmrc create mode 100644 .prettierignore create mode 100644 .prettierrc.js create mode 100644 .releaserc.js create mode 100644 .remarkrc.js create mode 100644 .stylelintrc.js create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docs/.dumirc.ts create mode 100644 docs/docs/changelog.md create mode 100644 docs/docs/data.ts create mode 100644 docs/docs/demo.tsx create mode 100644 docs/docs/index.md create mode 100644 docs/package.json create mode 100644 docs/tsconfig.json create mode 100644 next-env.d.ts create mode 100644 next.config.mjs create mode 100644 package.json create mode 100644 public/manifest-dev.json create mode 100644 public/manifest-markdown.json create mode 100644 public/manifest-standalone.json create mode 100644 renovate.json create mode 100644 src/components/Render.tsx create mode 100644 src/data.ts create mode 100644 src/pages/_app.tsx create mode 100644 src/pages/api/clothes-md.ts create mode 100644 src/pages/api/clothes.ts create mode 100644 src/pages/api/gateway.ts create mode 100644 src/pages/global.css create mode 100644 src/pages/iframe/index.tsx create mode 100644 src/pages/index.tsx create mode 100644 src/services/clothes.ts create mode 100644 src/type.ts create mode 100644 tsconfig.json create mode 100644 vitest.config.ts diff --git a/.bunfig.toml b/.bunfig.toml new file mode 100644 index 0000000..d6bb75b --- /dev/null +++ b/.bunfig.toml @@ -0,0 +1,3 @@ +[install.lockfile] + +save = false diff --git a/.changelogrc.js b/.changelogrc.js new file mode 100644 index 0000000..9a2f5f9 --- /dev/null +++ b/.changelogrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').changelog; diff --git a/.commitlintrc.js b/.commitlintrc.js new file mode 100644 index 0000000..9b8c6ac --- /dev/null +++ b/.commitlintrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').commitlint; diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3331d70 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_style = tab \ No newline at end of file diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..305d1ef --- /dev/null +++ b/.eslintignore @@ -0,0 +1,30 @@ +# Eslintignore for LobeHub +################################################################ + +# dependencies +node_modules + +# ci +coverage +.coverage + +# test +jest* +_test_ +__test__ + +# umi +.umi +.umi-production +.umi-test +.dumi/tmp* +!.dumirc.ts + +# production +dist +es +lib +logs + +# misc +# add other ignore file below diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..bc75953 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').eslint; diff --git a/.github/ISSUE_TEMPLATE/1_bug_report.yml b/.github/ISSUE_TEMPLATE/1_bug_report.yml new file mode 100644 index 0000000..d181c38 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/1_bug_report.yml @@ -0,0 +1,45 @@ +name: '🐛 反馈缺陷 Bug Report' +description: '反馈一个问题缺陷 | Report an bug' +title: '[Bug] ' +labels: '🐛 Bug' +body: + - type: dropdown + attributes: + label: '💻 系统环境 | Operating System' + options: + - Windows + - macOS + - Ubuntu + - Other Linux + - Other + validations: + required: true + - type: dropdown + attributes: + label: '🌐 浏览器 | Browser' + options: + - Chrome + - Edge + - Safari + - Firefox + - Other + validations: + required: true + - type: textarea + attributes: + label: '🐛 问题描述 | Bug Description' + description: A clear and concise description of the bug. + validations: + required: true + - type: textarea + attributes: + label: '🚦 期望结果 | Expected Behavior' + description: A clear and concise description of what you expected to happen. + - type: textarea + attributes: + label: '📷 复现步骤 | Recurrence Steps' + description: A clear and concise description of how to recurrence. + - type: textarea + attributes: + label: '📝 补充信息 | Additional Information' + description: If your problem needs further explanation, or if the issue you're seeing cannot be reproduced in a gist, please add more information here. diff --git a/.github/ISSUE_TEMPLATE/2_feature_request.yml b/.github/ISSUE_TEMPLATE/2_feature_request.yml new file mode 100644 index 0000000..edcf7d0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/2_feature_request.yml @@ -0,0 +1,21 @@ +name: '🌠 功能需求 Feature Request' +description: '需求或建议 | Suggest an idea' +title: '[Request] ' +labels: '🌠 Feature Request' +body: + - type: textarea + attributes: + label: '🥰 需求描述 | Feature Description' + description: Please add a clear and concise description of the problem you are seeking to solve with this feature request. + validations: + required: true + - type: textarea + attributes: + label: '🧐 解决方案 | Proposed Solution' + description: Describe the solution you'd like in a clear and concise manner. + validations: + required: true + - type: textarea + attributes: + label: '📝 补充信息 | Additional Information' + description: Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/3_question.yml b/.github/ISSUE_TEMPLATE/3_question.yml new file mode 100644 index 0000000..f989f7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/3_question.yml @@ -0,0 +1,15 @@ +name: '😇 疑问或帮助 Help Wanted' +description: '疑问或需要帮助 | Need help' +title: '[Question] ' +labels: '😇 Help Wanted' +body: + - type: textarea + attributes: + label: '🧐 问题描述 | Proposed Solution' + description: A clear and concise description of the proplem. + validations: + required: true + - type: textarea + attributes: + label: '📝 补充信息 | Additional Information' + description: Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/other.md b/.github/ISSUE_TEMPLATE/other.md new file mode 100644 index 0000000..215dd1f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/other.md @@ -0,0 +1,7 @@ +--- +name: '📝 其他 Other' +about: '其他问题 | Other issues' +title: '' +labels: '' +assignees: '' +--- diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7707b1a --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +#### 💻 变更类型 | Change Type + + + +- [ ] ✨ feat +- [ ] 🐛 fix +- [ ] 💄 style +- [ ] 🔨 chore +- [ ] 📝 docs + +#### 🔀 变更说明 | Description of Change + + + +#### 📝 补充信息 | Additional Information + + diff --git a/.github/workflows/issue-auto-comments.yml b/.github/workflows/issue-auto-comments.yml new file mode 100644 index 0000000..65b3c98 --- /dev/null +++ b/.github/workflows/issue-auto-comments.yml @@ -0,0 +1,72 @@ +name: Issue Auto Comment +on: + issues: + types: + - opened + - closed + - assigned + pull_request_target: + types: + - opened + - closed + +permissions: + contents: read + +jobs: + run: + permissions: + issues: write # for actions-cool/issues-helper to update issues + pull-requests: write # for actions-cool/issues-helper to update PRs + runs-on: ubuntu-latest + steps: + - name: Auto Comment on Issues Opened + uses: wow-actions/auto-comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} + issuesOpened: | + 👀 @{{ author }} + Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible. + Please make sure you have given us as much context as possible.\ + 非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。 + - name: Auto Comment on Issues Closed + uses: wow-actions/auto-comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} + issuesClosed: | + ✅ @{{ author }} +
+ This issue is closed, If you have any questions, you can comment and reply.\ + 此问题已经关闭。如果您有任何问题,可以留言并回复。 + - name: Auto Comment on Pull Request Opened + uses: wow-actions/auto-comment@v1 + with: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN}} + pullRequestOpened: | + 👍 @{{ author }} +
+ Thank you for raising your pull request and contributing to our Community + Please make sure you have followed our contributing guidelines. We will review it as soon as possible. + If you encounter any problems, please feel free to connect with us.\ + 非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。 + 如果您遇到任何问题,请随时与我们联系。 + - name: Auto Comment on Pull Request Merged + uses: actions-cool/pr-welcome@main + if: github.event.pull_request.merged == true + with: + token: ${{ secrets.GH_TOKEN }} + comment: | + ❤️ Great PR @${{ github.event.pull_request.user.login }} ❤️ +
+ The growth of project is inseparable from user feedback and contribution, thanks for your contribution!\ + 项目的成长离不开用户反馈和贡献,感谢您的贡献! + emoji: 'hooray' + pr-emoji: '+1, heart' + - name: Remove inactive + if: github.event.issue.state == 'open' && github.actor == github.event.issue.user.login + uses: actions-cool/issues-helper@v3 + with: + actions: 'remove-labels' + token: ${{ secrets.GH_TOKEN }} + issue-number: ${{ github.event.issue.number }} + labels: 'Inactive' diff --git a/.github/workflows/issue-check-inactive.yml b/.github/workflows/issue-check-inactive.yml new file mode 100644 index 0000000..a5ae1fb --- /dev/null +++ b/.github/workflows/issue-check-inactive.yml @@ -0,0 +1,23 @@ +name: Issue Check Inactive + +on: + schedule: + - cron: '0 0 */15 * *' + +permissions: + contents: read + +jobs: + issue-check-inactive: + permissions: + issues: write # for actions-cool/issues-helper to update issues + pull-requests: write # for actions-cool/issues-helper to update PRs + runs-on: ubuntu-latest + steps: + - name: check-inactive + uses: actions-cool/issues-helper@v3 + with: + actions: 'check-inactive' + token: ${{ secrets.GH_TOKEN }} + inactive-label: 'Inactive' + inactive-day: 30 diff --git a/.github/workflows/issue-close-require.yml b/.github/workflows/issue-close-require.yml new file mode 100644 index 0000000..e64d0cd --- /dev/null +++ b/.github/workflows/issue-close-require.yml @@ -0,0 +1,52 @@ +name: Issue Close Require + +on: + schedule: + - cron: '0 0 * * *' + +permissions: + contents: read + +jobs: + issue-close-require: + permissions: + issues: write # for actions-cool/issues-helper to update issues + pull-requests: write # for actions-cool/issues-helper to update PRs + runs-on: ubuntu-latest + steps: + - name: need reproduce + uses: actions-cool/issues-helper@v3 + with: + actions: 'close-issues' + token: ${{ secrets.GH_TOKEN }} + labels: '✅ Fixed' + inactive-day: 3 + body: | + 👋 @{{ github.event.issue.user.login }} +
+ Since the issue was labeled with `✅ Fixed`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\ + 由于该 issue 被标记为已修复,同时 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。 + - name: need reproduce + uses: actions-cool/issues-helper@v3 + with: + actions: 'close-issues' + token: ${{ secrets.GH_TOKEN }} + labels: '🤔 Need Reproduce' + inactive-day: 3 + body: | + 👋 @{{ github.event.issue.user.login }} +
+ Since the issue was labeled with `🤔 Need Reproduce`, but no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\ + 由于该 issue 被标记为需要更多信息,却 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。 + - name: need reproduce + uses: actions-cool/issues-helper@v3 + with: + actions: 'close-issues' + token: ${{ secrets.GH_TOKEN }} + labels: "🙅🏻‍♀️ WON'T DO" + inactive-day: 3 + body: | + 👋 @{{ github.event.issue.user.login }} +
+ Since the issue was labeled with `🙅🏻‍♀️ WON'T DO`, and no response in 3 days. This issue will be closed. If you have any questions, you can comment and reply.\ + 由于该 issue 被标记为暂不处理,同时 3 天未收到回应。现关闭 issue,若有任何问题,可评论回复。 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3d3572b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,33 @@ +name: Release CI +on: + push: + branches: + - main + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install bun + uses: oven-sh/setup-bun@v1 + + - name: Install deps + run: bun i + + - name: CI + run: bun run ci + + - name: Test + run: bun run test + + - name: build + run: bun run build + + - name: release + run: bun run release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9e0238f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: Test CI +on: + pull_request: + push: + branches: + - '!main' +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install bun + uses: oven-sh/setup-bun@v1 + + - name: Install deps + run: bun i + + - name: CI + run: bun run ci + + - name: Test and coverage + run: bun run test:coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7a21d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Gitignore for LobeHub +################################################################ + +# general +.DS_Store +.idea +.vscode +.history +.temp +.env.local +venv +temp +tmp + +# dependencies +node_modules +*.log +*.lock +package-lock.json + +# ci +coverage +.coverage +.eslintcache +.stylelintcache + +# production +dist +es +lib +logs +test-output + +# umi +.umi +.umi-production +.umi-test +.dumi/tmp* + +# husky +.husky/prepare-commit-msg + +# misc +# add other ignore file below +.vercel +.next +build +public/dist +docs-dist +bun.lockb +docs/.dumi/* +public/docs \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..c160a77 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no -- commitlint --edit ${1} diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..cf0c46b --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no-install lint-staged diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..d9ed3d3 --- /dev/null +++ b/.npmrc @@ -0,0 +1,11 @@ +lockfile=false +resolution-mode=highest +public-hoist-pattern[]=*@umijs/lint* +public-hoist-pattern[]=*changelog* +public-hoist-pattern[]=*commitlint* +public-hoist-pattern[]=*eslint* +public-hoist-pattern[]=*postcss* +public-hoist-pattern[]=*prettier* +public-hoist-pattern[]=*remark* +public-hoist-pattern[]=*semantic-release* +public-hoist-pattern[]=*stylelint* diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..51fdf94 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,61 @@ +# Prettierignore for LobeHub +################################################################ + +# general +.DS_Store +.editorconfig +.idea +.vscode +.history +.temp +.env.local +.husky +.npmrc +.gitkeep +venv +temp +tmp +LICENSE + +# dependencies +node_modules +*.log +*.lock +package-lock.json + +# ci +coverage +.coverage +.eslintcache +.stylelintcache +test-output +__snapshots__ +*.snap + +# production +dist +es +lib +logs + +# umi +.umi +.umi-production +.umi-test +.dumi/tmp* + +# ignore files +.*ignore + +# docker +docker +Dockerfile* + +# image +*.webp +*.gif +*.png +*.jpg + +# misc +# add other ignore file below diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..f0355a9 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').prettier; diff --git a/.releaserc.js b/.releaserc.js new file mode 100644 index 0000000..3793001 --- /dev/null +++ b/.releaserc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').semanticRelease; diff --git a/.remarkrc.js b/.remarkrc.js new file mode 100644 index 0000000..b673c10 --- /dev/null +++ b/.remarkrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').remarklint; diff --git a/.stylelintrc.js b/.stylelintrc.js new file mode 100644 index 0000000..294d72f --- /dev/null +++ b/.stylelintrc.js @@ -0,0 +1 @@ +module.exports = require('@lobehub/lint').stylelint; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..f546842 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,230 @@ + + +# Changelog + +### [Version 1.5.1](https://github.com/lobehub/chat-plugin-template/compare/v1.5.0...v1.5.1) + +Released on **2024-01-11** + +#### 🐛 Bug Fixes + +- **misc**: Fix gateway runtime, fix gateway runtime. + +
+ +
+Improvements and Fixes + +#### What's fixed + +- **misc**: Fix gateway runtime ([f181fa3](https://github.com/lobehub/chat-plugin-template/commit/f181fa3)) +- **misc**: Fix gateway runtime, closes [#24](https://github.com/lobehub/chat-plugin-template/issues/24) ([8b1a443](https://github.com/lobehub/chat-plugin-template/commit/8b1a443)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## [Version 1.5.0](https://github.com/lobehub/chat-plugin-template/compare/v1.4.0...v1.5.0) + +Released on **2023-12-30** + +#### ✨ Features + +- **misc**: Support markdown type. + +#### 💄 Styles + +- **misc**: Improve manifest info. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: Support markdown type ([0a6e154](https://github.com/lobehub/chat-plugin-template/commit/0a6e154)) + +#### Styles + +- **misc**: Improve manifest info ([0f51c54](https://github.com/lobehub/chat-plugin-template/commit/0f51c54)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## [Version 1.4.0](https://github.com/lobehub/chat-plugin-template/compare/v1.3.0...v1.4.0) + +Released on **2023-12-02** + +#### ✨ Features + +- **misc**: Add meta into manifest. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: Add meta into manifest ([48da33e](https://github.com/lobehub/chat-plugin-template/commit/48da33e)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## [Version 1.3.0](https://github.com/lobehub/chat-plugin-template/compare/v1.2.1...v1.3.0) + +Released on **2023-11-16** + +#### ✨ Features + +- **misc**: Update manifest example. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: Update manifest example, closes [#17](https://github.com/lobehub/chat-plugin-template/issues/17) ([abf44f0](https://github.com/lobehub/chat-plugin-template/commit/abf44f0)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +### [Version 1.2.1](https://github.com/lobehub/chat-plugin-template/compare/v1.2.0...v1.2.1) + +Released on **2023-11-06** + +#### ♻ Code Refactoring + +- **misc**: Refactor to use new lobeChat api. + +
+ +
+Improvements and Fixes + +#### Code refactoring + +- **misc**: Refactor to use new lobeChat api ([1f0a533](https://github.com/lobehub/chat-plugin-template/commit/1f0a533)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## [Version 1.2.0](https://github.com/lobehub/chat-plugin-template/compare/v1.1.0...v1.2.0) + +Released on **2023-10-23** + +#### ✨ Features + +- **misc**: Add standalone type. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: Add standalone type ([3a432f5](https://github.com/lobehub/chat-plugin-template/commit/3a432f5)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## [Version 1.1.0](https://github.com/lobehub/chat-plugin-template/compare/v1.0.0...v1.1.0) + +Released on **2023-09-09** + +#### ✨ Features + +- **misc**: 新增展示文档. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: 新增展示文档 ([fdff07f](https://github.com/lobehub/chat-plugin-template/commit/fdff07f)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
+ +## Version 1.0.0 + +Released on **2023-09-08** + +#### ✨ Features + +- **misc**: 完善插件开发模板的基础内容. + +#### 🐛 Bug Fixes + +- **misc**: Fix ci, Fix import. + +#### 💄 Styles + +- **misc**: Update lint, 优化暗色主题表现. + +
+ +
+Improvements and Fixes + +#### What's improved + +- **misc**: 完善插件开发模板的基础内容 ([8d354b4](https://github.com/lobehub/chat-plugin-template/commit/8d354b4)) + +#### What's fixed + +- **misc**: Fix ci ([34fe03a](https://github.com/lobehub/chat-plugin-template/commit/34fe03a)) +- **misc**: Fix import ([d8473af](https://github.com/lobehub/chat-plugin-template/commit/d8473af)) + +#### Styles + +- **misc**: Update lint ([d48fb19](https://github.com/lobehub/chat-plugin-template/commit/d48fb19)) +- **misc**: 优化暗色主题表现 ([47004c5](https://github.com/lobehub/chat-plugin-template/commit/47004c5)) + +
+ +
+ +[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top) + +
diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1dd53d2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 LobeHub + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..394b007 --- /dev/null +++ b/README.md @@ -0,0 +1,175 @@ + + +
+ + + + + +

Plugin Template
LobeChat Plugin

+ +This is the plugin template for LobeChat plugin development + +[![][🤯-🧩-lobehub-shield]][🤯-🧩-lobehub-link] +[![][github-release-shield]][github-release-link] +[![][github-releasedate-shield]][github-releasedate-link] +[![][github-action-test-shield]][github-action-test-link] +[![][github-action-release-shield]][github-action-release-link]
+[![][github-contributors-shield]][github-contributors-link] +[![][github-forks-shield]][github-forks-link] +[![][github-stars-shield]][github-stars-link] +[![][github-issues-shield]][github-issues-link] +[![][github-license-shield]][github-license-link] + +[Changelog](./CHANGELOG.md) · [Report Bug][github-issues-link] · [Request Feature][github-issues-link] + +![](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/rainbow.png) + +
+ +
+Table of contents + +#### TOC + +- [🌟 Features](#-features) +- [🤯 Usage](#-usage) +- [⌨️ Local Development](#️-local-development) +- [🤝 Contributing](#-contributing) +- [🔗 Links](#-links) + +#### + +
+ +## 🌟 Features + +- [x] 💨 **Quick start with low learning curve**: This template provides a quick start option, allowing users to get started quickly. Additionally, the template includes detailed documentation to help users understand and use the features easily. +- [x] 📚 **Beautiful and comprehensive documentation**: The template aims for aesthetics, with carefully designed interfaces and layouts that make the documentation more intuitive, readable, and user-friendly. Moreover, the template offers a wide range of styles and components for users to customize the appearance and functionality of their documentation. +- [x] 🔄 **Complete workflow, automatic publishing and partner updates**: The template provides a complete workflow, including automatic publishing and automatic partner updates. Users can easily complete the publishing and updating tasks by following the specified steps. +- [x] 🖱️ **One-click document generation**: The template offers a one-click document generation feature, allowing users to quickly generate complete documentation with simple operations. This saves users a significant amount of time and effort, allowing them to focus on improving the content and quality of their documentation. + +
+ +[![][back-to-top]](#readme-top) + +
+ +## 🤯 Usage + +> [!IMPORTANT]\ +> See detail on [📘 Template usage](https://chat-plugin-sdk.lobehub.com/guides/template) + +> [!Note]\ +> Plugins provide a means to extend the [Function Calling][fc-link] capabilities of LobeChat. They can be used to introduce new function calls, and even new ways to render message results. If you are interested in plugin development, please refer to our [📘 Plugin Development Guide](https://github.com/lobehub/lobe-chat/wiki/Plugin-Development) in the Wiki. +> +> - [@lobehub/lobe-chat-plugins][lobe-chat-plugins]: This is the plugin index for LobeChat. It accesses index.json from this repository to display a list of available plugins for LobeChat to the user. +> - [@lobehub/chat-plugin-sdk][chat-plugin-sdk]: The LobeChat Plugin SDK assists you in creating exceptional chat plugins for Lobe Chat. +> - [@lobehub/chat-plugins-gateway][chat-plugins-gateway]: The LobeChat Plugins Gateway is a backend service that serves as a gateway for LobeChat plugins. We deploy this service using Vercel. The primary API POST /api/v1/runner is deployed as an Edge Function. + +| Official Plugin | Description | +| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | +| [SearchEngine][chat-plugin-search-engine] | This plugin allows for the use of the SerpApi search engine. | +| [RealtimeWeather][chat-plugin-realtime-weather] | This plugin provides practical weather information by obtaining real-time weather data and can automatically update based on the user's location. | +| [WebsiteCrawler][chat-plugin-web-crawler] | This plugin automatically crawls the main content of a specified URL webpage and uses it as context input. | + +
+ +[![][back-to-top]](#readme-top) + +
+ +## ⌨️ Local Development + +You can use Github Codespaces for online development: + +[![][github-codespace-shield]][github-codespace-link] + +Or clone it for local development: + +[![][bun-shield]][bun-link] + +```bash +$ git clone https://github.com/lobehub/chat-plugin-template.git +$ cd chat-plugin-template +$ bun install +$ bun dev +``` + +
+ +[![][back-to-top]](#readme-top) + +
+ +## 🤝 Contributing + +Contributions of all types are more than welcome, if you are interested in contributing plugin, feel free to show us what you’re made of. + +[![][pr-welcome-shield]][pr-welcome-link] + +[![][github-contrib-shield]][github-contrib-link] + +
+ +[![][back-to-top]](#readme-top) + +
+ +## 🔗 Links + +- **[🤖 Lobe Chat](https://github.com/lobehub/lobe-chat)** - An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application. +- **[🧩 / 🏪 Plugin Index](https://github.com/lobehub/lobe-chat-plugins)** - This is the plugin index for LobeChat. It accesses index.json from this repository to display a list of available plugins for Function Calling to the user. + +
+ +[![][back-to-top]](#readme-top) + +
+ +--- + +#### 📝 License + +Copyright © 2023 [LobeHub][profile-url].
+This project is [MIT](./LICENSE) licensed. + + + +[🤯-🧩-lobehub-link]: https://github.com/lobehub/lobe-chat-plugins +[🤯-🧩-lobehub-shield]: https://img.shields.io/badge/%F0%9F%A4%AF%20%26%20%F0%9F%A7%A9%20LobeHub-Plugin-95f3d9?labelColor=black&style=flat-square +[back-to-top]: https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square +[bun-link]: https://bun.sh +[bun-shield]: https://img.shields.io/badge/-speedup%20with%20bun-black?logo=bun&style=for-the-badge +[chat-plugin-realtime-weather]: https://github.com/lobehub/chat-plugin-realtime-weather +[chat-plugin-sdk]: https://github.com/lobehub/chat-plugin-sdk +[chat-plugin-search-engine]: https://github.com/lobehub/chat-plugin-search-engine +[chat-plugin-web-crawler]: https://github.com/lobehub/chat-plugin-web-crawler +[chat-plugins-gateway]: https://github.com/lobehub/chat-plugins-gateway +[fc-link]: https://sspai.com/post/81986 +[github-action-release-link]: https://github.com/lobehub/chat-plugin-template/actions/workflows/release.yml +[github-action-release-shield]: https://img.shields.io/github/actions/workflow/status/lobehub/chat-plugin-template/release.yml?label=release&labelColor=black&logo=githubactions&logoColor=white&style=flat-square +[github-action-test-link]: https://github.com/lobehub/chat-plugin-template/actions/workflows/test.yml +[github-action-test-shield]: https://img.shields.io/github/actions/workflow/status/lobehub/chat-plugin-template/test.yml?label=test&labelColor=black&logo=githubactions&logoColor=white&style=flat-square +[github-codespace-link]: https://codespaces.new/lobehub/chat-plugin-template +[github-codespace-shield]: https://github.com/codespaces/badge.svg +[github-contrib-link]: https://github.com/lobehub/chat-plugin-template/graphs/contributors +[github-contrib-shield]: https://contrib.rocks/image?repo=lobehub%2Fchat-plugin-template +[github-contributors-link]: https://github.com/lobehub/chat-plugin-template/graphs/contributors +[github-contributors-shield]: https://img.shields.io/github/contributors/lobehub/chat-plugin-template?color=c4f042&labelColor=black&style=flat-square +[github-forks-link]: https://github.com/lobehub/chat-plugin-template/network/members +[github-forks-shield]: https://img.shields.io/github/forks/lobehub/chat-plugin-template?color=8ae8ff&labelColor=black&style=flat-square +[github-issues-link]: https://github.com/lobehub/chat-plugin-template/issues +[github-issues-shield]: https://img.shields.io/github/issues/lobehub/chat-plugin-template?color=ff80eb&labelColor=black&style=flat-square +[github-license-link]: https://github.com/lobehub/chat-plugin-template/blob/main/LICENSE +[github-license-shield]: https://img.shields.io/github/license/lobehub/chat-plugin-template?color=white&labelColor=black&style=flat-square +[github-release-link]: https://github.com/lobehub/chat-plugin-template/releases +[github-release-shield]: https://img.shields.io/github/v/release/lobehub/chat-plugin-template?color=369eff&labelColor=black&logo=github&style=flat-square +[github-releasedate-link]: https://github.com/lobehub/chat-plugin-template/releases +[github-releasedate-shield]: https://img.shields.io/github/release-date/lobehub/chat-plugin-template?labelColor=black&style=flat-square +[github-stars-link]: https://github.com/lobehub/chat-plugin-template/network/stargazers +[github-stars-shield]: https://img.shields.io/github/stars/lobehub/chat-plugin-template?color=ffcb47&labelColor=black&style=flat-square +[lobe-chat-plugins]: https://github.com/lobehub/lobe-chat-plugins +[pr-welcome-link]: https://github.com/lobehub/chat-plugin-template/pulls +[pr-welcome-shield]: https://img.shields.io/badge/%F0%9F%A4%AF%20PR%20WELCOME-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge +[profile-url]: https://github.com/lobehub diff --git a/docs/.dumirc.ts b/docs/.dumirc.ts new file mode 100644 index 0000000..a2bd2c4 --- /dev/null +++ b/docs/.dumirc.ts @@ -0,0 +1,56 @@ +import { defineConfig } from 'dumi'; +import path from 'node:path'; + +import { homepage } from '../package.json'; + +const isWin = process.platform === 'win32'; + +const isProd = process.env.NODE_ENV === 'production'; + +const themeConfig = { + actions: [ + { + link: homepage, + openExternal: true, + text: 'Github', + }, + { + link: 'https://github.com/lobehub/lobe-chat', + text: 'Try it on LobeChat', + type: 'primary', + }, + ], + footer: 'Made with 🤯 by LobeHub', + name: 'Project Template', + socialLinks: { + discord: 'https://discord.gg/AYFPHvv2jT', + github: homepage, + }, +}; + +export default defineConfig({ + alias: { + '@': path.join(__dirname, '../src'), + }, + base: isProd ? '/docs/' : '/', + extraBabelPlugins: ['babel-plugin-antd-style'], + favicons: [ + 'https://registry.npmmirror.com/@lobehub/assets-emoji/1.3.0/files/assets/package.webp', + ], + mfsu: isWin ? undefined : {}, + npmClient: 'pnpm', + outputPath: '../public/docs', + + publicPath: isProd ? '/docs/' : '/', + // ssr: isProduction ? {} : false, + styles: [ + `html, body { background: transparent; } + + @media (prefers-color-scheme: dark) { + html, body { background: #000; } + }`, + ], + + themeConfig, + title: 'Project Template - Lobe Chat Plugin', +}); diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md new file mode 100644 index 0000000..0c4fa12 --- /dev/null +++ b/docs/docs/changelog.md @@ -0,0 +1,9 @@ +--- +title: Changelog +description: New updates and improvements to @lobehub/chat-plugin-realtime-weather +nav: + title: Changelog + order: 999 +--- + + diff --git a/docs/docs/data.ts b/docs/docs/data.ts new file mode 100644 index 0000000..1df73ca --- /dev/null +++ b/docs/docs/data.ts @@ -0,0 +1,7 @@ +import { manClothes } from '@/data'; + +export const data = { + clothes: manClothes['happy'], + mood: 'happy', + today: Date.now(), +}; diff --git a/docs/docs/demo.tsx b/docs/docs/demo.tsx new file mode 100644 index 0000000..73024d8 --- /dev/null +++ b/docs/docs/demo.tsx @@ -0,0 +1,7 @@ +import Render from '@/components/Render'; + +import { data } from './data'; + +export default () => { + return ; +}; diff --git a/docs/docs/index.md b/docs/docs/index.md new file mode 100644 index 0000000..a4853ae --- /dev/null +++ b/docs/docs/index.md @@ -0,0 +1,7 @@ +--- +hero: + title: Project Template + description: This is the plugin template for LobeChat plugin development +--- + + diff --git a/docs/package.json b/docs/package.json new file mode 100644 index 0000000..00274d5 --- /dev/null +++ b/docs/package.json @@ -0,0 +1,14 @@ +{ + "name": "docs", + "version": "0.0.0", + "private": true, + "scripts": { + "build": "dumi build", + "dev": "dumi dev" + }, + "devDependencies": { + "babel-plugin-antd-style": "^1", + "dumi": "^2", + "dumi-theme-lobehub": "latest" + } +} diff --git a/docs/tsconfig.json b/docs/tsconfig.json new file mode 100644 index 0000000..b1927a7 --- /dev/null +++ b/docs/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "target": "ES5", + "lib": ["dom", "dom.iterable", "esnext"], + "sourceMap": true, + "skipDefaultLibCheck": true, + "jsx": "react-jsx", + "baseUrl": ".", + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "paths": { + "@@/*": ["./dumi/tmp/*"], + "@/*": ["../src/*"] + }, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "isolatedModules": true + }, + "exclude": ["node_modules"], + "include": [".", ".dumirc.ts", "../src"] +} diff --git a/next-env.d.ts b/next-env.d.ts new file mode 100644 index 0000000..4f11a03 --- /dev/null +++ b/next-env.d.ts @@ -0,0 +1,5 @@ +/// +/// + +// NOTE: This file should not be edited +// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/next.config.mjs b/next.config.mjs new file mode 100644 index 0000000..c81fa3b --- /dev/null +++ b/next.config.mjs @@ -0,0 +1,25 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, + transpilePackages: ['@lobehub/ui'], + async headers() { + return [ + { + // matching all API routes + source: '/:path*', + headers: [ + { key: 'Access-Control-Allow-Credentials', value: 'true' }, + { key: 'Access-Control-Allow-Origin', value: '*' }, + { key: 'Access-Control-Allow-Methods', value: 'GET,OPTIONS,PATCH,DELETE,POST,PUT' }, + { + key: 'Access-Control-Allow-Headers', + value: + 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version', + }, + ], + }, + ]; + }, +}; + +export default nextConfig; diff --git a/package.json b/package.json new file mode 100644 index 0000000..c2848f7 --- /dev/null +++ b/package.json @@ -0,0 +1,90 @@ +{ + "name": "plugin-identifier", + "version": "1.5.1", + "private": true, + "description": "This is the plugin template for LobeChat plugin development", + "homepage": "https://github.com/lobehub/chat-plugin-template", + "repository": "https://github.com/lobehub/chat-plugin-template.git", + "workspaces": [ + "docs/*", + "./*" + ], + "scripts": { + "build": "npm run docs:build && next build", + "ci": "npm run lint && npm run type-check", + "dev": "next dev -p 3400", + "docs:build": "cd docs && npm run build", + "docs:dev": "cd docs && npm run dev", + "lint": "eslint \"{src,api,docs}/**/*.{js,jsx,ts,tsx}\" --fix", + "lint:md": "remark . --quiet --frail --output", + "lint:style": "stylelint \"src/**/*.{js,jsx,ts,tsx}\" --fix", + "prepare": "husky install", + "prepublishOnly": "npm run doctor && npm run build", + "prettier": "prettier -c --write \"**/**\"", + "release": "semantic-release", + "start": "next start", + "test": "vitest --passWithNoTests", + "test:coverage": "vitest --coverage --passWithNoTests", + "type-check": "tsc --noEmit" + }, + "lint-staged": { + "*.md": [ + "remark --quiet --output --", + "prettier --write --no-error-on-unmatched-pattern" + ], + "*.json": [ + "prettier --write --no-error-on-unmatched-pattern" + ], + "*.{js,jsx}": [ + "prettier --write", + "stylelint --fix", + "eslint --fix" + ], + "*.{ts,tsx}": [ + "prettier --parser=typescript --write", + "stylelint --fix", + "eslint --fix" + ] + }, + "browserslist": [ + "> 1%", + "last 2 versions", + "not ie <= 10" + ], + "dependencies": { + "@lobehub/chat-plugin-sdk": "^1", + "@lobehub/chat-plugins-gateway": "^1", + "@lobehub/ui": "latest", + "antd": "^5", + "antd-style": "^3", + "dayjs": "^1", + "next": "13.4.7", + "react": "^18", + "react-dom": "^18", + "react-layout-kit": "^1" + }, + "devDependencies": { + "@commitlint/cli": "^18", + "@lobehub/lint": "latest", + "@types/react": "18", + "@vercel/node": "^2", + "@vitest/coverage-v8": "latest", + "commitlint": "^18", + "cross-env": "^7", + "eslint": "^8", + "father": "4.3.1", + "husky": "^8", + "lint-staged": "^15", + "prettier": "^3", + "remark": "^14", + "remark-cli": "^11", + "semantic-release": "^21", + "stylelint": "^15", + "typescript": "^5", + "vitest": "latest" + }, + "peerDependencies": { + "react": ">=18", + "react-dom": ">=18" + } +} diff --git a/public/manifest-dev.json b/public/manifest-dev.json new file mode 100644 index 0000000..564947c --- /dev/null +++ b/public/manifest-dev.json @@ -0,0 +1,42 @@ +{ + "$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json", + "api": [ + { + "url": "http://localhost:3400/api/clothes", + "name": "recommendClothes", + "description": "根据用户的心情,给用户推荐他有的衣服", + "parameters": { + "properties": { + "mood": { + "description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)", + "enum": ["happy", "sad", "anger", "fear", "surprise", "disgust"], + "type": "string" + }, + "gender": { + "type": "string", + "enum": ["man", "woman"], + "description": "对话用户的性别,需要询问用户后才知道这个信息" + } + }, + "required": ["mood", "gender"], + "type": "object" + } + } + ], + "author": "LobeHub", + "createdAt": "2023-09-03", + "gateway": "http://localhost:3400/api/gateway", + "homepage": "https://github.com/lobehub/chat-plugin-template", + "identifier": "plugin-identifier", + "meta": { + "avatar": "🚀", + "tags": ["template"], + "title": "Chat Plugin Template", + "description": "This is the plugin template for LobeChat plugin development" + }, + "ui": { + "url": "http://localhost:3400", + "height": 200 + }, + "version": "1" +} diff --git a/public/manifest-markdown.json b/public/manifest-markdown.json new file mode 100644 index 0000000..4464f70 --- /dev/null +++ b/public/manifest-markdown.json @@ -0,0 +1,38 @@ +{ + "$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json", + "api": [ + { + "url": "http://localhost:3400/api/clothes-md", + "name": "recommendClothes", + "description": "根据用户的心情,给用户推荐他有的衣服", + "parameters": { + "properties": { + "mood": { + "description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)", + "enum": ["happy", "sad", "anger", "fear", "surprise", "disgust"], + "type": "string" + }, + "gender": { + "type": "string", + "enum": ["man", "woman"], + "description": "对话用户的性别,需要询问用户后才知道这个信息" + } + }, + "required": ["mood", "gender"], + "type": "object" + } + } + ], + "author": "LobeHub", + "createdAt": "2023-09-03", + "identifier": "plugin-identifier-markdown", + "meta": { + "avatar": "🚀", + "tags": ["template"], + "title": "Chat Plugin Template", + "description": "This is the plugin template for LobeChat plugin development" + }, + "systemRole": "根据用户的心情,给用户推荐适合他穿的衣服,你需要知道他的性别后才进行推荐,否则推荐不准确。", + "type": "markdown", + "version": "1" +} diff --git a/public/manifest-standalone.json b/public/manifest-standalone.json new file mode 100644 index 0000000..e5bc5f6 --- /dev/null +++ b/public/manifest-standalone.json @@ -0,0 +1,41 @@ +{ + "$schema": "../node_modules/@lobehub/chat-plugin-sdk/schema.json", + "api": [ + { + "url": "http://localhost:3400/api/clothes", + "name": "recommendClothes", + "description": "根据用户的心情,给用户推荐他有的衣服", + "parameters": { + "properties": { + "mood": { + "description": "用户当前的心情,可选值有:开心(happy), 难过(sad),生气 (anger),害怕(fear),惊喜( surprise),厌恶 (disgust)", + "enum": ["happy", "sad", "anger", "fear", "surprise", "disgust"], + "type": "string" + }, + "gender": { + "type": "string", + "enum": ["man", "woman"], + "description": "对话用户的性别,需要询问用户后才知道这个信息" + } + }, + "required": ["mood", "gender"], + "type": "object" + } + } + ], + "author": "LobeHub", + "createdAt": "2023-09-03", + "identifier": "plugin-identifier-standalone", + "meta": { + "avatar": "🚀", + "tags": ["template"], + "title": "Chat Plugin Template", + "description": "This is the plugin template for LobeChat plugin development" + }, + "type": "standalone", + "ui": { + "url": "http://localhost:3400/iframe", + "height": 200 + }, + "version": "1" +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..99c84e1 --- /dev/null +++ b/renovate.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "automerge": false, + "dependencyDashboard": true, + "ignoreDeps": [], + "labels": ["dependencies"], + "postUpdateOptions": ["yarnDedupeHighest"], + "prConcurrentLimit": 30, + "prHourlyLimit": 0, + "rebaseWhen": "conflicted", + "schedule": "on sunday before 6:00am", + "timezone": "UTC" +} diff --git a/src/components/Render.tsx b/src/components/Render.tsx new file mode 100644 index 0000000..312d411 --- /dev/null +++ b/src/components/Render.tsx @@ -0,0 +1,38 @@ +import { Card } from 'antd'; +import { createStyles } from 'antd-style'; +import dayjs from 'dayjs'; +import { memo } from 'react'; +import { Flexbox } from 'react-layout-kit'; + +import { ResponseData } from '@/type'; + +const useStyles = createStyles(({ css, token }) => ({ + date: css` + color: ${token.colorTextQuaternary}; + `, +})); + +const Render = memo>(({ mood, clothes, today }) => { + const { styles } = useStyles(); + + return ( + + + 🌟心情:{mood} + {dayjs(today).format('YYYY/MM/DD')} + + + 推荐衣物 + + {clothes?.map((item) => ( + + {item.description} + + ))} + + + + ); +}); + +export default Render; diff --git a/src/data.ts b/src/data.ts new file mode 100644 index 0000000..78947a8 --- /dev/null +++ b/src/data.ts @@ -0,0 +1,173 @@ +export const manClothes = { + anger: [ + { + description: '这款黑色皮夹克可以让你在生气时释放压力。', + name: '黑色皮夹克', + }, + { + description: '这款深红色的衬衫可以让你在生气时感到力量。', + name: '深红色长袖衬衫', + }, + { + description: '这款军绿色的工装裤可以让你在生气时感到坚韧。', + name: '军绿色工装裤', + }, + ], + disgust: [ + { + description: '这款黑色的T恤可以让你在厌恶时感到冷静。', + name: '黑色修身T恤', + }, + { + description: '这款深色的裤子可以让你在厌恶时感到自在。', + name: '深色直筒休闲裤', + }, + { + description: '这款军绿色的夹克可以让你在厌恶时感到坚定。', + name: '军绿色工装夹克', + }, + ], + fear: [ + { + description: '这款宽松的卫衣可以让你在害怕时感到安全。', + name: '灰色宽松连帽卫衣', + }, + { + description: '这款黑色的裤子可以让你在害怕时感到舒适。', + name: '黑色直筒休闲裤', + }, + { + description: '这款深色的夹克可以让你在害怕时感到保护。', + name: '深蓝色牛仔夹克', + }, + ], + happy: [ + { + description: '这款明亮的T恤可以增强你的快乐气氛。', + name: '亮黄色夏日T恤', + }, + { + description: '这款活泼的短裤可以让你的心情保持愉快。', + name: '卡通图案运动短裤', + }, + { + description: '这款色彩明亮的衬衫可以让你看起来更加开朗。', + name: '彩色条纹休闲衬衫', + }, + ], + sad: [ + { + description: '舒适的卫衣可以让你在难过的时候感到舒适。', + name: '深色宽松卫衣', + }, + { + description: '这款深色的夹克可以让你在难过的时候感到安慰。', + name: '黑色牛仔夹克', + }, + { + description: '简单的黑色T恤可以让你在难过的时候感到平静。', + name: '简洁黑色长袖T恤', + }, + ], + surprise: [ + { + description: '这款亮色的T恤可以让你在惊喜时感到愉悦。', + name: '亮色图案T恤', + }, + { + description: '这款鲜艳的短裤可以让你在惊喜时感到活力。', + name: '鲜艳色彩运动短裤', + }, + { + description: '这款多彩条纹的衬衫可以让你在惊喜时感到快乐。', + name: '多彩条纹衬衫', + }, + ], +}; + +export const womanClothes = { + anger: [ + { + description: '这款黑色皮夹克可以让你在生气时释放压力。', + name: '黑色皮夹克', + }, + { + description: '这款深红色的衬衫可以让你在生气时感到力量。', + name: '深红色长袖衬衫', + }, + { + description: '这款军绿色的工装裤可以让你在生气时感到坚韧。', + name: '军绿色工装裤', + }, + ], + disgust: [ + { + description: '这款黑色的连衣裙可以让你在厌恶时感到冷静。', + name: '黑色修身连衣裙', + }, + { + description: '这款深色的裤子可以让你在厌恶时感到自在。', + name: '深色直筒休闲裤', + }, + { + description: '这款军绿色的夹克可以让你在厌恶时感到坚定。', + name: '军绿色工装夹克', + }, + ], + fear: [ + { + description: '这款宽松的卫衣可以让你在害怕时感到安全。', + name: '灰色宽松连帽卫衣', + }, + { + description: '这款黑色的裤子可以让你在害怕时感到舒适。', + name: '黑色直筒休闲裤', + }, + { + description: '这款深色的夹克可以让你在害怕时感到保护。', + name: '深蓝色牛仔夹克', + }, + ], + happy: [ + { + description: '这款明亮的连衣裙可以增强你的快乐气氛。', + name: '亮黄色夏日连衣裙', + }, + { + description: '这款活泼的短裤可以让你的心情保持愉快。', + name: '卡通图案运动短裤', + }, + { + description: '这款色彩明亮的衬衫可以让你看起来更加开朗。', + name: '彩色条纹休闲衬衫', + }, + ], + sad: [ + { + description: '舒适的连衣裙可以让你在难过的时候感到舒适。', + name: '深色宽松连衣裙', + }, + { + description: '这款深色的夹克可以让你在难过的时候感到安慰。', + name: '黑色牛仔夹克', + }, + { + description: '简单的黑色T恤可以让你在难过的时候感到平静。', + name: '简洁黑色长袖T恤', + }, + ], + surprise: [ + { + description: '这款亮色的连衣裙可以让你在惊喜时感到愉悦。', + name: '亮色图案连衣裙', + }, + { + description: '这款鲜艳的短裤可以让你在惊喜时感到活力。', + name: '鲜艳色彩运动短裤', + }, + { + description: '这款多彩条纹的衬衫可以让你在惊喜时感到快乐。', + name: '多彩条纹衬衫', + }, + ], +}; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx new file mode 100644 index 0000000..8fe3c1f --- /dev/null +++ b/src/pages/_app.tsx @@ -0,0 +1,12 @@ +import { ThemeProvider } from '@lobehub/ui'; +import type { AppProps } from 'next/app'; + +import './global.css'; + +export default function App({ Component, pageProps }: AppProps) { + return ( + + + + ); +} diff --git a/src/pages/api/clothes-md.ts b/src/pages/api/clothes-md.ts new file mode 100644 index 0000000..2634501 --- /dev/null +++ b/src/pages/api/clothes-md.ts @@ -0,0 +1,26 @@ +import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk'; + +import { manClothes, womanClothes } from '@/data'; +import { RequestData, ResponseData } from '@/type'; + +export const config = { + runtime: 'edge', +}; + +export default async (req: Request) => { + if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed); + + const { gender, mood } = (await req.json()) as RequestData; + + const clothes = gender === 'man' ? manClothes : womanClothes; + + const result: ResponseData = { + clothes: mood ? clothes[mood] : Object.values(clothes).flat(), + mood, + today: Date.now(), + }; + + return new Response( + `由于你的心情是${result.mood},我推荐你穿 ${result.clothes.map((c) => c.name).join('、')}。`, + ); +}; diff --git a/src/pages/api/clothes.ts b/src/pages/api/clothes.ts new file mode 100644 index 0000000..df97c99 --- /dev/null +++ b/src/pages/api/clothes.ts @@ -0,0 +1,24 @@ +import { PluginErrorType, createErrorResponse } from '@lobehub/chat-plugin-sdk'; + +import { manClothes, womanClothes } from '@/data'; +import { RequestData, ResponseData } from '@/type'; + +export const config = { + runtime: 'edge', +}; + +export default async (req: Request) => { + if (req.method !== 'POST') return createErrorResponse(PluginErrorType.MethodNotAllowed); + + const { gender, mood } = (await req.json()) as RequestData; + + const clothes = gender === 'man' ? manClothes : womanClothes; + + const result: ResponseData = { + clothes: mood ? clothes[mood] : Object.values(clothes).flat(), + mood, + today: Date.now(), + }; + + return new Response(JSON.stringify(result)); +}; diff --git a/src/pages/api/gateway.ts b/src/pages/api/gateway.ts new file mode 100644 index 0000000..20776b7 --- /dev/null +++ b/src/pages/api/gateway.ts @@ -0,0 +1,13 @@ +export const config = { + runtime: 'edge', +}; + +export default async (req: Request) => { + if (process.env.NODE_ENV === 'development') { + const { createGatewayOnEdgeRuntime } = await import('@lobehub/chat-plugins-gateway'); + + return createGatewayOnEdgeRuntime()(req); + } + + return new Response('gateway'); +}; diff --git a/src/pages/global.css b/src/pages/global.css new file mode 100644 index 0000000..0621692 --- /dev/null +++ b/src/pages/global.css @@ -0,0 +1,12 @@ +html, +body { + background: transparent !important; + + /* + When using iframe embedding, if you still need to keep the transparent background in dark mode + you need to force the color-scheme to light + + 使用 iframe 嵌入时,如果在暗色模式下仍需要保持透明背景,需要强制设定 color-scheme 为 light + */ + color-scheme: light !important; +} diff --git a/src/pages/iframe/index.tsx b/src/pages/iframe/index.tsx new file mode 100644 index 0000000..6f9e44a --- /dev/null +++ b/src/pages/iframe/index.tsx @@ -0,0 +1,53 @@ +import { lobeChat } from '@lobehub/chat-plugin-sdk/client'; +import { Button } from 'antd'; +import { memo, useEffect, useState } from 'react'; +import { Center } from 'react-layout-kit'; + +import Data from '@/components/Render'; +import { fetchClothes } from '@/services/clothes'; +import { ResponseData } from '@/type'; + +const Render = memo(() => { + // 初始化渲染状态 + const [data, setData] = useState(); + + // 初始化时从主应用同步状态 + useEffect(() => { + lobeChat.getPluginMessage().then(setData); + }, []); + + // 记录请求参数 + const [payload, setPayload] = useState(); + + useEffect(() => { + lobeChat.getPluginPayload().then((payload) => { + if (payload.name === 'recommendClothes') { + setPayload(payload.arguments); + } + }); + }, []); + + const fetchData = async () => { + const data = await fetchClothes(payload); + setData(data); + lobeChat.setPluginMessage(data); + }; + + return data ? ( + + ) : ( +
+ +
+ ); +}); + +export default Render; diff --git a/src/pages/index.tsx b/src/pages/index.tsx new file mode 100644 index 0000000..2efbd12 --- /dev/null +++ b/src/pages/index.tsx @@ -0,0 +1,19 @@ +import { lobeChat } from '@lobehub/chat-plugin-sdk/client'; +import { memo, useEffect, useState } from 'react'; + +import Data from '@/components/Render'; +import { ResponseData } from '@/type'; + +const Render = memo(() => { + const [data, setData] = useState(); + + useEffect(() => { + lobeChat.getPluginMessage().then((e: ResponseData) => { + setData(e); + }); + }, []); + + return ; +}); + +export default Render; diff --git a/src/services/clothes.ts b/src/services/clothes.ts new file mode 100644 index 0000000..ba3e2b2 --- /dev/null +++ b/src/services/clothes.ts @@ -0,0 +1,10 @@ +import { RequestData } from '@/type'; + +export const fetchClothes = async (params: RequestData) => { + const res = await fetch('/api/clothes', { + body: JSON.stringify(params), + method: 'POST', + }); + + return res.json(); +}; diff --git a/src/type.ts b/src/type.ts new file mode 100644 index 0000000..48f016d --- /dev/null +++ b/src/type.ts @@ -0,0 +1,16 @@ +export interface ClothesItem { + description: string; + name: string; +} +type Mood = 'happy' | 'sad' | 'anger' | 'fear' | 'surprise' | 'disgust'; + +export interface ResponseData { + clothes: ClothesItem[]; + mood: Mood; + today: number; +} + +export interface RequestData { + gender: 'man' | 'woman'; + mood: Mood; +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6b47e76 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "target": "ES5", + "lib": ["dom", "dom.iterable", "esnext"], + "sourceMap": true, + "skipDefaultLibCheck": true, + "jsx": "preserve", + "baseUrl": ".", + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "noUnusedLocals": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "paths": { + "@/*": ["src/*"] + }, + "types": ["vitest/globals"], + "allowJs": true, + "noEmit": true, + "incremental": true, + "esModuleInterop": true, + "isolatedModules": true + }, + "exclude": ["node_modules"], + "include": ["src", "next-env.d.ts", "*.ts"] +} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..014f97e --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + environment: 'node', + globals: true, + }, +});