Skip to content

Commit 148b336

Browse files
authored
feat: add genui sdk playground (#19)
* feat: init genui playground * fix: fix deploy error * feat: Optimize code details * feat: setup different env to genui-sdk * fix: resolve review comments
1 parent b2a18ea commit 148b336

File tree

16 files changed

+181
-26
lines changed

16 files changed

+181
-26
lines changed

.genui-alpha.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

.genui-production.env

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

.github/workflows/build-playground.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
types: [opened, reopened, synchronize, edited]
66
paths:
77
- '.vitepress/**'
8-
workflow_dispatch:
8+
- 'genui-sdk/**'
9+
workflow_dispatch: {}
910

1011
permissions:
1112
contents: read
@@ -20,8 +21,22 @@ jobs:
2021
build:
2122
runs-on: ubuntu-latest
2223
steps:
23-
- name: Checkout
24-
uses: actions/checkout@v3
24+
- uses: webfactory/ssh-agent@v0.8.0
25+
with:
26+
ssh-private-key: ${{ secrets.SUBMODULE_SSH_KEY }}
27+
- name: Checkout repository (with submodules)
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
submodules: false
32+
- name: Configure Git identity
33+
run: |
34+
git config --global user.name "GitHub Actions"
35+
git config --global user.email "actions@github.com"
36+
- name: Ensure submodules are up-to-date (pull latest from their remote)
37+
run: |
38+
git submodule sync --recursive
39+
git submodule update --init --recursive
2540
- name: Setup pnpm
2641
uses: pnpm/action-setup@v3
2742
with:

.github/workflows/deploy-github.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: [ dev, main ]
66
paths:
77
- '.vitepress/**'
8-
workflow_dispatch:
8+
workflow_dispatch: {}
99

1010
permissions:
1111
contents: read
@@ -20,8 +20,24 @@ 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
39+
- name: Setup alpha env to genui-sdk
40+
run: cp .genui-alpha.env genui-sdk/sites/playground/web/env/.env
2541
- name: Setup pnpm
2642
uses: pnpm/action-setup@v3
2743
with:

.github/workflows/deploy-obs.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,24 @@ 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
50+
- name: Setup production env to genui-sdk
51+
run: cp .genui-production.env genui-sdk/sites/playground/web/env/.env
3652
- name: Setup pnpm
3753
uses: pnpm/action-setup@v3
3854
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: 26 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 { 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,20 @@ 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+
// 添加插件来处理静态资源路径解析
29+
resolveStaticAssets(),
30+
],
31+
resolve: {
32+
// 确保能够正确解析 @opentiny 相关包的路径
33+
dedupe: ['vue'],
34+
},
35+
ssr: {
36+
noExternal: [/^@opentiny/],
37+
},
38+
},
39+
} as UserConfig)

.vitepress/plugins.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { fileURLToPath } from 'node:url'
2+
import path from 'node:path'
3+
import { existsSync } 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+
export function resolveStaticAssets(): Plugin {
12+
13+
const publicPathsMapper = {
14+
[path.resolve(root, 'genui-sdk/sites/playground/web')]:path.resolve(root, 'genui-sdk/sites/playground/web/public')
15+
}
16+
17+
return {
18+
name: 'resolve-static-assets',
19+
resolveId(id, importer) {
20+
21+
if (id.startsWith('/') && !id.startsWith('//') && !id.startsWith('/@')) {
22+
const publicPath = Object.entries(publicPathsMapper).find(([key, value]) => importer?.startsWith(key))?.[1]
23+
if (publicPath) {
24+
const filePath = path.resolve(publicPath, id.slice(1))
25+
if (existsSync(filePath)) {
26+
return filePath
27+
}
28+
}
29+
}
30+
31+
return null
32+
},
33+
}
34+
}

.vitepress/theme/Home.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
<div class="home-content">
88
<div class="big-box">
9-
<div class="small-box" v-for="(item, idx) in homeList" :key="idx">
9+
<a :href="item.link" class="small-box" v-for="(item, idx) in homeList" :key="idx">
1010
<!-- 第一行:左图右上下结构 -->
1111
<div class="row1">
1212
<img class="avatar" :src="getImgUrl(item.icon)" />
@@ -41,7 +41,7 @@
4141
>
4242
</div>
4343
<div v-if="item.link === ''" class="row5">敬请期待</div>
44-
</div>
44+
</a>
4545
</div>
4646
</div>
4747
</div>
@@ -124,6 +124,8 @@ const homeList = [
124124
flex: 0 0 calc((100% - 3 * 30px) / 4);
125125
max-width: calc((100% - 3 * 30px) / 4);
126126
position: relative;
127+
text-decoration: none;
128+
cursor: pointer;
127129
}
128130
.dark .small-box {
129131
background: rgba(38, 38, 38, 1);
@@ -149,6 +151,7 @@ const homeList = [
149151
font-weight: bold;
150152
margin-bottom: 4px;
151153
margin-top: -2px;
154+
color: #191919;
152155
}
153156
.row1-content {
154157
line-height: 18px;
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>

0 commit comments

Comments
 (0)