Skip to content

Commit 6b88e62

Browse files
committed
feat: init genui playground
1 parent b2a18ea commit 6b88e62

File tree

13 files changed

+187
-13
lines changed

13 files changed

+187
-13
lines changed

.genui.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_CHAT_URL=https://agent-alpha.opentiny.design/playground/genui-sdk/api/chat-genui
2+
VITE_GET_MODELS_URL=https://agent-alpha.opentiny.design/playground/genui-sdk/api/get-models
3+
VITE_CHECK_MCP_URL=https://agent-alpha.opentiny.design/playground/genui-sdk/api/check-mcp

.github/workflows/build-playground.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,22 @@ jobs:
2020
build:
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v3
23+
- uses: webfactory/ssh-agent@v0.8.0
24+
with:
25+
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
26+
- name: Checkout repository (with submodules)
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
submodules: false
31+
- name: Configure Git identity
32+
run: |
33+
git config --global user.name "GitHub Actions"
34+
git config --global user.email "actions@github.com"
35+
- name: Ensure submodules are up-to-date (pull latest from their remote)
36+
run: |
37+
git submodule sync --recursive
38+
git submodule update --init --recursive
2539
- name: Setup pnpm
2640
uses: pnpm/action-setup@v3
2741
with:

.github/workflows/deploy-github.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,22 @@ jobs:
2020
build:
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v3
23+
- uses: webfactory/ssh-agent@v0.8.0
24+
with:
25+
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
26+
- name: Checkout repository (with submodules)
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
submodules: false
31+
- name: Configure Git identity
32+
run: |
33+
git config --global user.name "GitHub Actions"
34+
git config --global user.email "actions@github.com"
35+
- name: Ensure submodules are up-to-date (pull latest from their remote)
36+
run: |
37+
git submodule sync --recursive
38+
git submodule update --init --recursive
2539
- name: Setup pnpm
2640
uses: pnpm/action-setup@v3
2741
with:

.github/workflows/deploy-obs.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,22 @@ jobs:
3131
outputs:
3232
version: ${{ steps.ver.outputs.value }}
3333
steps:
34-
- name: Checkout
35-
uses: actions/checkout@v3
34+
- uses: webfactory/ssh-agent@v0.8.0
35+
with:
36+
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
37+
- name: Checkout repository (with submodules)
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
submodules: false
42+
- name: Configure Git identity
43+
run: |
44+
git config --global user.name "GitHub Actions"
45+
git config --global user.email "actions@github.com"
46+
- name: Ensure submodules are up-to-date (pull latest from their remote)
47+
run: |
48+
git submodule sync --recursive
49+
git submodule update --init --recursive
3650
- name: Setup pnpm
3751
uses: pnpm/action-setup@v3
3852
with:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "genui-sdk"]
2+
path = genui-sdk
3+
url = git@github.com:opentiny/genui-sdk.git

.vitepress/config.mts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import { defineConfig } from 'vitepress'
2+
import { fileURLToPath } from 'node:url'
3+
import path from 'node:path'
4+
import type { UserConfig } from 'vitepress'
5+
import { resolveOpentinyThemeCSS, resolveStaticAssets } from './plugins'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
const root = path.resolve(__dirname, '..')
210

311
// https://vitepress.dev/reference/site-config
412
export default defineConfig({
513
title: "OpenTiny Playground",
14+
ignoreDeadLinks: true,
615
description: "OpenTiny 项目演练场",
716
base: process.env.VITEPRESS_BASE || '/',
817
outDir: 'dist',
@@ -11,5 +20,22 @@ export default defineConfig({
1120
socialLinks: [
1221
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
1322
]
14-
}
15-
})
23+
},
24+
vite: {
25+
// 配置环境变量目录,指向子项目的 env 目录,确保能读取 .env 文件
26+
envDir: path.resolve(root, 'genui-sdk/sites/playground/web/env'),
27+
plugins: [
28+
// 添加自定义插件处理 @opentiny/vue-theme 的 CSS 导入
29+
resolveOpentinyThemeCSS(),
30+
// 添加插件来处理静态资源路径解析
31+
resolveStaticAssets(),
32+
],
33+
resolve: {
34+
// 确保能够正确解析 @opentiny 相关包的路径
35+
dedupe: ['vue'],
36+
},
37+
ssr: {
38+
noExternal: [/^@opentiny/],
39+
},
40+
},
41+
} as UserConfig)

.vitepress/plugins.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { fileURLToPath } from 'node:url'
2+
import path from 'node:path'
3+
import { existsSync, readdirSync } from 'node:fs'
4+
// @ts-expect-error: vite types may not be present at build time
5+
import type { Plugin } from 'vite'
6+
7+
const __filename = fileURLToPath(import.meta.url)
8+
const __dirname = path.dirname(__filename)
9+
const root = path.resolve(__dirname, '..')
10+
11+
// 自定义插件:处理 @opentiny/vue-theme 的子路径 CSS 导入
12+
export function resolveOpentinyThemeCSS(): Plugin {
13+
return {
14+
name: 'resolve-opentiny-theme-css',
15+
resolveId(id) {
16+
// 处理 @opentiny/vue-theme/xxx/index.css 格式的导入
17+
if (id.startsWith('@opentiny/vue-theme/') && id.endsWith('.css')) {
18+
// 解析到实际的 CSS 文件路径
19+
const themePath = id.replace('@opentiny/vue-theme/', '')
20+
21+
const directPath = path.resolve(root, 'node_modules/@opentiny/vue-theme', themePath)
22+
if (existsSync(directPath)) {
23+
return directPath
24+
}
25+
26+
}
27+
return null
28+
},
29+
}
30+
}
31+
32+
// 处理静态资源路径解析,优先从子项目加载
33+
export function resolveStaticAssets(): Plugin {
34+
const publicDirs = [
35+
path.resolve(root, 'genui-sdk/sites/playground/web/public'),
36+
path.resolve(root, 'public'),
37+
]
38+
39+
return {
40+
name: 'resolve-static-assets',
41+
resolveId(id) {
42+
// 处理以 / 开头的绝对路径(静态资源)
43+
// 例如:/logo.svg, /images/xxx.png 等
44+
if (id.startsWith('/') && !id.startsWith('//') && !id.startsWith('/@')) {
45+
// 移除开头的 /,获取相对路径
46+
const relativePath = id.slice(1)
47+
48+
// 在所有可能的 public 目录中查找(优先子项目)
49+
for (const publicDir of publicDirs) {
50+
if (existsSync(publicDir)) {
51+
const filePath = path.resolve(publicDir, relativePath)
52+
if (existsSync(filePath)) {
53+
// 返回实际文件路径,Vite 会处理它
54+
return filePath
55+
}
56+
}
57+
}
58+
}
59+
60+
return null
61+
},
62+
}
63+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<ClientOnly>
3+
<component v-if="GenuiChat" :is="GenuiChat" class="genui-playground" />
4+
</ClientOnly>
5+
</template>
6+
7+
<script setup>
8+
import { ref, onMounted } from 'vue'
9+
10+
const GenuiChat = ref(null)
11+
12+
onMounted(async () => {
13+
const module = await import('../../../genui-sdk/sites/playground/web/src/App.vue')
14+
GenuiChat.value = module.default
15+
16+
})
17+
</script>
18+
19+
<style scoped>
20+
.genui-playground {
21+
height: 100vh !important;
22+
background: #fff;
23+
}
24+
</style>

.vitepress/theme/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import DefaultTheme from 'vitepress/theme'
22
import Layout from './Layout.vue'
33
import HomePage from './Home.vue'
44
import CustomContent from './components/customContent.vue'
5+
import GenuiSdk from './components/GenuiSdk.vue'
56
import './style.css'
67

78
export default {
@@ -10,5 +11,6 @@ export default {
1011
enhanceApp({ app }) {
1112
app.component('HomePage', HomePage)
1213
app.component('CustomContent', CustomContent)
14+
app.component('GenuiSdk', GenuiSdk)
1315
}
1416
}

genui-sdk

Submodule genui-sdk added at 75c9a2f

0 commit comments

Comments
 (0)