@yh-ui/yh-ui-skill 1.0.38 → 1.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/llms-full.txt +2 -0
- package/assets/llms.txt +2 -0
- package/assets/metadata.json +1 -1
- package/assets/skills/yh-ui/README.md +35 -32
- package/assets/skills/yh-ui/README.zh-CN.md +55 -0
- package/assets/skills/yh-ui/SKILL.md +57 -2
- package/assets/skills/yh-ui/references/codegen-rubric.md +16 -12
- package/assets/skills/yh-ui/references/nuxt.md +49 -3
- package/assets/skills/yh-ui/references/recipes-ai.md +129 -37
- package/assets/skills/yh-ui/references/recipes-flow.md +143 -37
- package/assets/skills/yh-ui/references/recipes-form-schema.md +147 -42
- package/assets/skills/yh-ui/references/recipes-icons.md +126 -0
- package/assets/skills/yh-ui/references/recipes-table.md +98 -47
- package/assets/skills/yh-ui/references/recipes-theme.md +141 -0
- package/assets/skills/yh-ui/references/request.md +98 -19
- package/assets/skills/yh-ui/references/vue-component-practices.md +82 -19
- package/package.json +1 -1
package/assets/llms-full.txt
CHANGED
|
@@ -20,6 +20,8 @@ Read `skills/yh-ui/SKILL.md` first. Then load only the references relevant to th
|
|
|
20
20
|
- `skills/yh-ui/references/recipes-form-schema.md`
|
|
21
21
|
- `skills/yh-ui/references/recipes-ai.md`
|
|
22
22
|
- `skills/yh-ui/references/recipes-flow.md`
|
|
23
|
+
- `skills/yh-ui/references/recipes-theme.md`
|
|
24
|
+
- `skills/yh-ui/references/recipes-icons.md`
|
|
23
25
|
- `skills/yh-ui/references/codegen-rubric.md`
|
|
24
26
|
- `skills/yh-ui/references/eval-scenarios.md`
|
|
25
27
|
|
package/assets/llms.txt
CHANGED
|
@@ -18,5 +18,7 @@ High-value references:
|
|
|
18
18
|
- `skills/yh-ui/references/recipes-form-schema.md`: YhFormSchema deep recipe.
|
|
19
19
|
- `skills/yh-ui/references/recipes-ai.md`: YhAi component deep recipe.
|
|
20
20
|
- `skills/yh-ui/references/recipes-flow.md`: Flow deep recipe.
|
|
21
|
+
- `skills/yh-ui/references/recipes-theme.md`: Theme deep recipe.
|
|
22
|
+
- `skills/yh-ui/references/recipes-icons.md`: Icons deep recipe.
|
|
21
23
|
|
|
22
24
|
Use `@yh-ui/nuxt` for Nuxt, `@yh-ui/components` for component-only imports, `@yh-ui/yh-ui` for all-in-one Vue install, `@yh-ui/request` for request state, `@yh-ui/flow` for flow editors, and `@yh-ui/ai-sdk` for AI SDK integrations.
|
package/assets/metadata.json
CHANGED
|
@@ -1,53 +1,56 @@
|
|
|
1
1
|
# YH-UI Agent Skill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[中文文档 (Chinese Documentation)](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
This directory packages YH-UI knowledge for modern AI coding agents. It is designed as a small, progressive cross-platform skill: one `SKILL.md` file acting as the entry point, plus progressively loaded reference files.
|
|
4
6
|
|
|
5
7
|
## Use Cases
|
|
6
8
|
|
|
7
|
-
- Generate Vue 3 or Nuxt code with YH-UI components.
|
|
8
|
-
- Choose the
|
|
9
|
-
- Avoid hallucinated component names,
|
|
10
|
-
-
|
|
11
|
-
-
|
|
9
|
+
- Generate Vue 3 or Nuxt 3 code with YH-UI components.
|
|
10
|
+
- Choose the correct YH-UI package boundary for a task.
|
|
11
|
+
- Avoid hallucinated component names, packages, theme options, and locale paths.
|
|
12
|
+
- Enforce 100% prioritization of YH-UI's built-in components and utilities over writing custom HTML elements.
|
|
13
|
+
- Provide AI agents with precise recipes for data tables, form schemas, AI chat bubbles, flow canvases, themes, and icons.
|
|
12
14
|
|
|
13
15
|
## Design Principles
|
|
14
16
|
|
|
15
|
-
- `SKILL.md`
|
|
16
|
-
- Reference files are loaded progressively by task, keeping agent context small.
|
|
17
|
-
- `source-truth.md` is the
|
|
18
|
-
- `
|
|
19
|
-
- Deep recipe files hold
|
|
20
|
-
- `
|
|
21
|
-
- `
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
- `SKILL.md` is the trigger surface and central manual for the AI.
|
|
18
|
+
- Reference files are loaded progressively by task, keeping the agent's context small and efficient.
|
|
19
|
+
- `references/source-truth.md` is the compiled export map generated from source packages.
|
|
20
|
+
- `references/vue-component-practices.md` defines Vue 3.5+ setup guidelines, TS type-safety structures, and component encapsulation decisions.
|
|
21
|
+
- Deep recipe files hold high-value code blocks for advanced scenarios:
|
|
22
|
+
- `recipes-table.md`: Virtual scrolls, cell slots, data export, printing.
|
|
23
|
+
- `recipes-form-schema.md`: Repeating lists (`type: 'list'`), custom renderers.
|
|
24
|
+
- `recipes-ai.md`: DeepSeek-R1 thinking steps (`YhAiThoughtChain`), code execution, Mermaid diagrams.
|
|
25
|
+
- `recipes-flow.md`: BPMN and AI workflow nodes, resizers, toolbars, undo/redo logs.
|
|
26
|
+
- `recipes-theme.md`: Global config providers, density, preset themes, WCAG contrast.
|
|
27
|
+
- `recipes-icons.md`: Iconify collection loads, inline SVG.
|
|
28
|
+
- `codegen-rubric.md` provides strict evaluation rules (fails the AI if it writes custom CSS/HTML for controls supported by YH-UI).
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
## Installation & Usage
|
|
28
31
|
|
|
29
|
-
|
|
32
|
+
You can deploy these rules into your local IDE setups using the monorepo CLI:
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
```bash
|
|
35
|
+
# Install to Cursor (.cursor/rules/)
|
|
36
|
+
npx @yh-ui/yh-ui-skill install --target cursor
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
# Install to Trae (.traerules or root config)
|
|
39
|
+
npx @yh-ui/yh-ui-skill install --target cursor
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
# Export to general project directory (.yh-ui/)
|
|
42
|
+
npx @yh-ui/yh-ui-skill install --target project
|
|
43
|
+
```
|
|
36
44
|
|
|
37
|
-
###
|
|
45
|
+
### Manual Configuration
|
|
38
46
|
|
|
39
|
-
|
|
47
|
+
- **Cursor**: Create/update `.cursorrules` or drop these files into `.cursor/rules/`.
|
|
48
|
+
- **Trae**: Create/update `.traerules` at the project root with the core rules from `SKILL.md`. In chats, use `#SKILL.md` to reference rules.
|
|
49
|
+
- **Claude Project / Custom GPTs**: Upload `SKILL.md` and the `references/` files as custom knowledge documents.
|
|
40
50
|
|
|
41
51
|
## Release Checklist
|
|
42
52
|
|
|
43
53
|
- Run `pnpm verify:yh-ui-skill`.
|
|
44
54
|
- Run `pnpm generate:yh-ui-skill` when component exports or priority APIs change.
|
|
45
|
-
- Confirm package
|
|
46
|
-
- Confirm `references/source-truth.md` matches package exports when components are added or renamed.
|
|
55
|
+
- Confirm `references/source-truth.md` and `references/api-cheatsheet.md` matches package exports when components are added or renamed.
|
|
47
56
|
- Run the prompts in `references/eval-scenarios.md` against at least one target AI model before a major skill release.
|
|
48
|
-
- Confirm README links still resolve.
|
|
49
|
-
- Regenerate the skill if component package boundaries change.
|
|
50
|
-
|
|
51
|
-
## License
|
|
52
|
-
|
|
53
|
-
MIT. See `LICENSE.txt`.
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# YH-UI Agent Skill (智能 Agent 辅助开发规则库)
|
|
2
|
+
|
|
3
|
+
[English Documentation (英文文档)](./README.md)
|
|
4
|
+
|
|
5
|
+
此目录封装了 YH-UI 组件库的专业知识,专为现代 AI 编码助手(如 Cursor、Trae、Claude Code 等)设计。它采用轻量化的跨平台 Skill 设计结构:由一个作为入口导向的 `SKILL.md` 文件以及一组按需加载的 Reference 参考文件组成。
|
|
6
|
+
|
|
7
|
+
## 主要用途
|
|
8
|
+
|
|
9
|
+
- 生成符合 YH-UI 规范的 Vue 3 或 Nuxt 3 页面与组件代码。
|
|
10
|
+
- 引导 AI 选择正确的 YH-UI 模块包边界,避免引入多余的三方依赖。
|
|
11
|
+
- 杜绝 AI 凭空捏造不存在的组件名、属性、主题配置或语言包路径。
|
|
12
|
+
- **100% 强制 AI 优先使用已有的 YH-UI 组件**,严禁在组件库有支持时手写原生 HTML/CSS 重复造轮子。
|
|
13
|
+
- 为 AI 助手提供高价值的进阶 Recipes(表格虚拟滚动、嵌套表单 Schema、AI 思维链、可视化流程图、全局国际化及主题配置)。
|
|
14
|
+
|
|
15
|
+
## 设计原则
|
|
16
|
+
|
|
17
|
+
- **`SKILL.md`**:作为 AI 的系统指令入口与核心操作指南,定义了严格的防错守卫。
|
|
18
|
+
- **按需渐进加载**:参考文件按职责细分,AI 仅在处理特定任务(如 Table 或 Flow)时才读取对应文件,保持上下文体积小巧高效。
|
|
19
|
+
- **`references/source-truth.md`**:由源码 AST 自动提取生成的导出真相图谱,确保名字 100% 准确。
|
|
20
|
+
- **`references/vue-component-practices.md`**:定义了 Vue 3.5+ 响应式属性解构、严格 TypeScript 类型、组件销毁内存清理以及组件库二次封装工作流。
|
|
21
|
+
- **核心业务 Recipes**:
|
|
22
|
+
- `recipes-table.md`:大列表虚拟滚动、表格插槽自定义、Excel 导入导出与打印 API。
|
|
23
|
+
- `recipes-form-schema.md`:动态表单 Schema、重复嵌套列表(`type: 'list'`)、自定义 render 渲染 VNode。
|
|
24
|
+
- `recipes-ai.md`:AI 聊天气泡、DeepSeek-R1 思维链(`YhAiThoughtChain`)渲染、代码沙箱执行、Mermaid 图表渲染。
|
|
25
|
+
- `recipes-flow.md`:BPMN 与 AI 智能工作流节点注册、NodeResizer、NodeToolbar、撤销/重做历史记录。
|
|
26
|
+
- `recipes-theme.md`:全局 ConfigProvider 国际化配置、Preset 预设、密度调整、色盲友好模式、WCAG 2.1 对比度无障碍校验。
|
|
27
|
+
- `recipes-icons.md`:Iconify 图标集异步加载、自定义 SVG 渲染、旋转动画。
|
|
28
|
+
- **`codegen-rubric.md`**:代码生成评审准则,若 AI 绕过 YH-UI 手写重复控制,则判定生成失败。
|
|
29
|
+
|
|
30
|
+
## 安装与集成方法
|
|
31
|
+
|
|
32
|
+
您可以使用 Monorepo 提供的命令行工具将这些规则自动同步到本地 IDE 配置中:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# 自动部署到 Cursor 规则目录 (.cursor/rules/)
|
|
36
|
+
npx @yh-ui/yh-ui-skill install --target cursor
|
|
37
|
+
|
|
38
|
+
# 自动部署到 Trae 规则目录
|
|
39
|
+
npx @yh-ui/yh-ui-skill install --target cursor
|
|
40
|
+
|
|
41
|
+
# 导出到项目当前目录 (.yh-ui/)
|
|
42
|
+
npx @yh-ui/yh-ui-skill install --target project
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 手动引入上下文
|
|
46
|
+
|
|
47
|
+
- **Cursor**:将 `SKILL.md` 的内容粘贴至根目录的 `.cursorrules` 文件中,或将 references 下的文件直接拖入 `.cursor/rules/` 文件夹。
|
|
48
|
+
- **Trae**:在根目录下创建 `.traerules` 并粘贴 `SKILL.md` 内容。在提问时,使用 **`#SKILL.md`** 引入对应规则作为对话上下文。
|
|
49
|
+
- **Claude Project / Custom GPTs**:将 `SKILL.md` 和 `references/` 目录上传至知识库(Knowledge)中。
|
|
50
|
+
|
|
51
|
+
## 维护与发布流程
|
|
52
|
+
|
|
53
|
+
- 开发中如新增组件,应运行 `pnpm generate:yh-ui-skill` 重新生成 API 导出。
|
|
54
|
+
- 修改规则后,执行 `pnpm verify:yh-ui-skill` 进行链接与 frontmatter 静态校验(通过 21 个文档的测试方可提交)。
|
|
55
|
+
- 执行 `pnpm format` 以对齐 Markdown 排版。
|
|
@@ -25,8 +25,9 @@ Do not use this skill for:
|
|
|
25
25
|
|
|
26
26
|
## Core Rules
|
|
27
27
|
|
|
28
|
-
-
|
|
29
|
-
-
|
|
28
|
+
- **Strict YH-UI Prioritization**: Under no circumstances should you generate custom HTML/CSS controls (e.g. custom buttons, inputs, tables, dialogs, drawers, scrollbars, markdown cards) or manually construct network fetches/stream connections when YH-UI packages support them. You must 100% prioritize utilizing YH-UI components and utilities.
|
|
29
|
+
- **Extension & Re-encapsulation Principle**: If a YH-UI component does not fully meet a specific UI requirement, you must first try to extend it using slot customisation, CSS overrides, or component composition. Writing custom elements from scratch is a last resort, and you must justify why YH-UI could not be extended.
|
|
30
|
+
- Do not invent components, props, hooks, package paths, or theme APIs. Check `references/source-truth.md` to ensure names are real.
|
|
30
31
|
- Use `@yh-ui/yh-ui` for ordinary Vue apps that want the all-in-one entry.
|
|
31
32
|
- Use `@yh-ui/nuxt` for Nuxt apps and rely on auto-imported components/composables.
|
|
32
33
|
- Use `@yh-ui/components` when the user asks for component-only usage.
|
|
@@ -73,6 +74,33 @@ import App from './App.vue'
|
|
|
73
74
|
createApp(App).use(YhUI).mount('#app')
|
|
74
75
|
```
|
|
75
76
|
|
|
77
|
+
### Global Config & i18n (Root Setup)
|
|
78
|
+
|
|
79
|
+
```vue
|
|
80
|
+
<script setup lang="ts">
|
|
81
|
+
import { ref } from 'vue'
|
|
82
|
+
import { YhConfigProvider } from '@yh-ui/components'
|
|
83
|
+
import zhCn from '@yh-ui/locale/lang/zh-cn'
|
|
84
|
+
import en from '@yh-ui/locale/lang/en'
|
|
85
|
+
|
|
86
|
+
const locale = ref(zhCn)
|
|
87
|
+
const currentSize = ref<'default' | 'small' | 'large'>('default')
|
|
88
|
+
|
|
89
|
+
function toggleLang() {
|
|
90
|
+
locale.value = locale.value.name === 'zh-cn' ? en : zhCn
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<YhConfigProvider :locale="locale" :size="currentSize">
|
|
96
|
+
<button @click="toggleLang">Switch Language</button>
|
|
97
|
+
<AppLayout>
|
|
98
|
+
<router-view />
|
|
99
|
+
</AppLayout>
|
|
100
|
+
</YhConfigProvider>
|
|
101
|
+
</template>
|
|
102
|
+
```
|
|
103
|
+
|
|
76
104
|
### On-Demand Components
|
|
77
105
|
|
|
78
106
|
```vue
|
|
@@ -147,6 +175,31 @@ const edges: FlowEdge[] = []
|
|
|
147
175
|
</template>
|
|
148
176
|
```
|
|
149
177
|
|
|
178
|
+
### Theme
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import { ThemePlugin } from '@yh-ui/theme'
|
|
182
|
+
|
|
183
|
+
app.use(ThemePlugin, {
|
|
184
|
+
preset: 'blue',
|
|
185
|
+
dark: false,
|
|
186
|
+
persist: true
|
|
187
|
+
})
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Icons
|
|
191
|
+
|
|
192
|
+
```vue
|
|
193
|
+
<script setup lang="ts">
|
|
194
|
+
import { Icon } from '@yh-ui/icons/vue'
|
|
195
|
+
</script>
|
|
196
|
+
|
|
197
|
+
<template>
|
|
198
|
+
<Icon icon="mdi:home" :size="20" color="var(--yh-color-primary)" />
|
|
199
|
+
<Icon icon="mdi:loading" spin />
|
|
200
|
+
</template>
|
|
201
|
+
```
|
|
202
|
+
|
|
150
203
|
## Progressive References
|
|
151
204
|
|
|
152
205
|
Read only the file needed for the task:
|
|
@@ -165,6 +218,8 @@ Read only the file needed for the task:
|
|
|
165
218
|
- Deep form schema recipe: `references/recipes-form-schema.md`
|
|
166
219
|
- Deep AI recipe: `references/recipes-ai.md`
|
|
167
220
|
- Deep Flow recipe: `references/recipes-flow.md`
|
|
221
|
+
- Deep Theme recipe: `references/recipes-theme.md`
|
|
222
|
+
- Deep Icons recipe: `references/recipes-icons.md`
|
|
168
223
|
- Code generation acceptance rubric: `references/codegen-rubric.md`
|
|
169
224
|
- Evaluation prompts for regression testing: `references/eval-scenarios.md`
|
|
170
225
|
|
|
@@ -4,29 +4,33 @@ Use this checklist before returning YH-UI code.
|
|
|
4
4
|
|
|
5
5
|
## Must Pass
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
7
|
+
- **Prioritize YH-UI**: 100% of UI elements and utility actions (like tables, dropdowns, dialogs, scrolls, loading icons, fetch hooks) use YH-UI packages if supported. Writing custom elements when YH-UI supports them **fails** code generation.
|
|
8
|
+
- **Strict Extensions**: Any customization or gaps in YH-UI controls are addressed via slot templates, custom style parameters, or composites. Writing raw custom controls is only permitted as a last resort and must be documented.
|
|
9
|
+
- **Real Exports Only**: Imports use actual package boundaries and names listed inside `source-truth.md`. Hallucinated names or paths **fail** code generation.
|
|
10
|
+
- Vue examples include required component CSS when importing `@yh-ui/components` on-demand.
|
|
11
|
+
- Nuxt examples use `@yh-ui/nuxt` and rely on auto-imports (without manually importing YH-UI components in pages).
|
|
12
|
+
- Locale imports use `@yh-ui/locale/lang/zh-cn`, `@yh-ui/locale/lang/en`, or other real locale paths.
|
|
13
|
+
- Theme customization uses `@yh-ui/theme`, `ThemePlugin`, `useTheme`, or standard CSS design variables.
|
|
14
|
+
- Request client instances use `createRequest` and `useRequest` from `@yh-ui/request` (no custom axios or raw fetch queries).
|
|
15
|
+
- Flow examples wrap editor canvases inside explicitly dimensioned heights, and use `<ClientOnly>` in SSR.
|
|
16
|
+
- AI examples do not expose provider keys in client-side script code.
|
|
17
|
+
- Vue SFC files strictly match block sequences, TS variables structure, reactivity parameters, and onUnmounted cleanups detailed in `vue-component-practices.md`.
|
|
17
18
|
|
|
18
19
|
## Should Pass
|
|
19
20
|
|
|
20
21
|
- Pick the smallest YH-UI surface that solves the task.
|
|
21
22
|
- Prefer composable AI UI for custom products and `YhAiChat` for complete chat surfaces.
|
|
22
23
|
- Include empty, loading, and error states for data-heavy pages.
|
|
23
|
-
- Keep
|
|
24
|
-
- Avoid unrelated dependencies when YH-UI already provides the capability.
|
|
24
|
+
- Keep templates TypeScript-friendly: use `import type`, type template refs with `InstanceType<typeof YhComponent>`, and define typed interface objects.
|
|
25
|
+
- Avoid unrelated dependencies (like lodash, element-plus, custom hooks) when YH-UI already provides the capability.
|
|
25
26
|
- Keep generated UI code readable and production-shaped, not demo-only.
|
|
26
27
|
- Use stable `:key` values, computed derived state, and explicit loading/error/empty states where relevant.
|
|
27
28
|
|
|
28
29
|
## Red Flags
|
|
29
30
|
|
|
31
|
+
- **Hallucinated Controls**: Reinventing standard visual controls (e.g. custom scroll elements, custom select components, custom modal popups) instead of using the corresponding YH-UI components.
|
|
32
|
+
- **Custom Fetches**: Initiating direct `fetch` / `axios` connections in views instead of utilizing `createRequest` or `useRequest` from `@yh-ui/request`.
|
|
33
|
+
- **Untyped Ref Handles**: Declaring component template refs without type-casting them using `InstanceType<typeof ...>` (e.g. `const refVal = ref(null)`).
|
|
30
34
|
- Invented `Yh*` components.
|
|
31
35
|
- Old APIs such as `createYhTheme` or `createRequestInstance`.
|
|
32
36
|
- Nuxt pages manually importing many YH-UI components despite auto-import.
|
|
@@ -42,9 +42,55 @@ The module auto-imports common hooks and utilities such as `useNamespace`, `useZ
|
|
|
42
42
|
|
|
43
43
|
`useId` is imported as `useYhId` to avoid conflicts with Vue/Nuxt native `useId`.
|
|
44
44
|
|
|
45
|
+
## SSR Request Fetching
|
|
46
|
+
|
|
47
|
+
When fetching data during Nuxt server-side rendering (SSR), integrate `@yh-ui/request` within Nuxt's `useAsyncData` to ensure proper hydration and prevent duplicate requests on the client side:
|
|
48
|
+
|
|
49
|
+
```vue
|
|
50
|
+
<script setup lang="ts">
|
|
51
|
+
import { createRequest } from '@yh-ui/request'
|
|
52
|
+
|
|
53
|
+
const api = createRequest({ baseURL: '/api' })
|
|
54
|
+
|
|
55
|
+
// Fetch data using Nuxt's useAsyncData to support SSR hydration
|
|
56
|
+
const { data: users, pending, error } = await useAsyncData('users', () => api.get('/users'))
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<div v-if="pending">Loading...</div>
|
|
61
|
+
<div v-else-if="error">{{ error.message }}</div>
|
|
62
|
+
<YhTable v-else :data="users" :columns="[{ prop: 'name', label: 'Name' }]" />
|
|
63
|
+
</template>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## AI & Private Server Routes
|
|
67
|
+
|
|
68
|
+
Never make AI provider calls (OpenAI, DeepSeek, Anthropic) directly from client code. Always proxy them through Nuxt Server Routes (`server/api/*`) using Nitro's server capabilities:
|
|
69
|
+
|
|
70
|
+
### Server Route (`server/api/chat.ts`)
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { defineEventHandler, readBody } from 'h3'
|
|
74
|
+
import { createProviderAdapter } from '@yh-ui/ai-sdk'
|
|
75
|
+
|
|
76
|
+
export default defineEventHandler(async (event) => {
|
|
77
|
+
const { messages } = await readBody(event)
|
|
78
|
+
const config = useRuntimeConfig()
|
|
79
|
+
|
|
80
|
+
const provider = createProviderAdapter({
|
|
81
|
+
provider: 'deepseek',
|
|
82
|
+
apiKey: config.deepseekApiKey,
|
|
83
|
+
defaultModel: 'deepseek-chat'
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
// Return the streamed response securely from the server
|
|
87
|
+
return provider.chatStream(messages)
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
45
91
|
## SSR Rules
|
|
46
92
|
|
|
47
|
-
- Use `<ClientOnly>` around browser-heavy flow editors.
|
|
48
|
-
- Do not assume `window`, `document`,
|
|
49
|
-
- Keep API keys on the server side
|
|
93
|
+
- Use `<ClientOnly>` around browser-heavy flow editors, Monaco code editors, charts, or SVG animators.
|
|
94
|
+
- Do not assume `window`, `document`, `localStorage`, or browser event listeners exist during server-side compilation.
|
|
95
|
+
- Keep API keys and model keys on the server side; inject them via `useRuntimeConfig()` in Nitro event handlers.
|
|
50
96
|
- Let the module inject CSS unless the user explicitly disabled `importStyle`.
|
|
@@ -1,58 +1,150 @@
|
|
|
1
|
-
# Deep Recipe:
|
|
1
|
+
# Deep Recipe: YH-UI AI Components
|
|
2
2
|
|
|
3
|
-
Use this recipe
|
|
3
|
+
Use this recipe when building rich AI chat applications, assistant portals, Copilot interfaces, reasoning process visualisations, interactive code environments, and AI server integrations.
|
|
4
4
|
|
|
5
5
|
## Default Choice
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Compose `YhAiBubbleList`, `YhAiBubble`, `YhAiSender`, `YhAiSources`, `YhAiAttachments`, and `YhAiActionGroup` for custom products.
|
|
9
|
-
- Use `@yh-ui/ai-sdk/vue` for Vue chat state.
|
|
10
|
-
- Keep provider secrets in server routes.
|
|
7
|
+
Combine `@yh-ui/components` (for frontend AI components) with `@yh-ui/ai-sdk/vue` (for Vue composition API chat hooks) and `@yh-ui/ai-sdk` (for server provider adapters, security filters, and tracing).
|
|
11
8
|
|
|
12
|
-
##
|
|
9
|
+
## AI Frontend Component Selection
|
|
13
10
|
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- `
|
|
11
|
+
- **`YhAiBubble`**: Renders message bubbles. It supports typed animations, markdown parsing, syntax highlighting, and custom sanitization filters.
|
|
12
|
+
- **`YhAiThoughtChain`**: Visualises multi-step reasoning processes (e.g. DeepSeek-R1 thinking logs).
|
|
13
|
+
- **`YhAiCodeRunner` / `YhAiCodeEditor`**: Provides interactive playgrounds where AI-generated code can be edited and executed directly.
|
|
14
|
+
- **`YhAiMermaid`**: Renders standard Mermaid graph syntax dynamically in real-time.
|
|
15
|
+
- **`YhAiSources`**: Shows cited articles, files, or document passages with relevance scores.
|
|
17
16
|
|
|
18
|
-
## Pattern:
|
|
17
|
+
## Pattern: Interactive Chat Interface with Code Execution
|
|
18
|
+
|
|
19
|
+
This template implements streamed text answers, rendering of reasoning logs, interactive code execution inside Pyodide/python runtimes, and Mermaid diagrams:
|
|
19
20
|
|
|
20
21
|
```vue
|
|
21
22
|
<script setup lang="ts">
|
|
22
|
-
import {
|
|
23
|
+
import { ref } from 'vue'
|
|
24
|
+
import {
|
|
25
|
+
YhAiBubble,
|
|
26
|
+
YhAiSender,
|
|
27
|
+
YhAiThoughtChain,
|
|
28
|
+
YhAiMermaid,
|
|
29
|
+
YhAiCodeRunner
|
|
30
|
+
} from '@yh-ui/components'
|
|
23
31
|
import { useAIChat } from '@yh-ui/ai-sdk/vue'
|
|
24
32
|
|
|
33
|
+
// Custom interface for message structures
|
|
34
|
+
interface ChatMessage {
|
|
35
|
+
id: string
|
|
36
|
+
role: 'user' | 'assistant'
|
|
37
|
+
content: string
|
|
38
|
+
thinkingSteps?: Array<{ title: string; content: string; status: 'thinking' | 'done' }>
|
|
39
|
+
codeToRun?: string
|
|
40
|
+
mermaidSyntax?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
25
43
|
const { messages, input, isLoading, sendMessage, stop } = useAIChat({
|
|
26
|
-
api: '/api/chat'
|
|
44
|
+
api: '/api/chat',
|
|
45
|
+
onResponse: () => console.log('Streaming response started')
|
|
27
46
|
})
|
|
47
|
+
|
|
48
|
+
const activeTab = ref<'chat' | 'runner'>('chat')
|
|
49
|
+
const currentCode = ref('print("Hello from YH-UI AI!")')
|
|
28
50
|
</script>
|
|
29
51
|
|
|
30
52
|
<template>
|
|
31
|
-
<
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
<div class="ai-chat-layout">
|
|
54
|
+
<div class="chat-main">
|
|
55
|
+
<div class="message-feed">
|
|
56
|
+
<div v-for="msg in messages" :key="msg.id" class="message-row">
|
|
57
|
+
<!-- Render Reasoning Chain if available -->
|
|
58
|
+
<YhAiThoughtChain
|
|
59
|
+
v-if="msg.thinkingSteps && msg.thinkingSteps.length"
|
|
60
|
+
:items="msg.thinkingSteps"
|
|
61
|
+
title="Reasoning Chain"
|
|
62
|
+
auto-collapse
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
<!-- Main Message Bubble -->
|
|
66
|
+
<YhAiBubble
|
|
67
|
+
:role="msg.role"
|
|
68
|
+
:content="msg.content"
|
|
69
|
+
:markdown="true"
|
|
70
|
+
:enable-sanitizer="true"
|
|
71
|
+
streaming
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
<!-- Mermaid syntax parsed and rendered dynamically -->
|
|
75
|
+
<YhAiMermaid v-if="msg.mermaidSyntax" :code="msg.mermaidSyntax" class="mermaid-block" />
|
|
76
|
+
|
|
77
|
+
<!-- Live Python/JS execution if generated code block is present -->
|
|
78
|
+
<YhAiCodeRunner
|
|
79
|
+
v-if="msg.codeToRun"
|
|
80
|
+
:code="msg.codeToRun"
|
|
81
|
+
language="python"
|
|
82
|
+
autorun
|
|
83
|
+
class="runner-block"
|
|
84
|
+
/>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<YhAiSender
|
|
89
|
+
v-model="input"
|
|
90
|
+
:loading="isLoading"
|
|
91
|
+
clearable
|
|
92
|
+
placeholder="Type a message or mention prompts using /..."
|
|
93
|
+
@send="sendMessage"
|
|
94
|
+
@cancel="stop"
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
49
98
|
</template>
|
|
50
99
|
```
|
|
51
100
|
|
|
52
|
-
##
|
|
101
|
+
## Pattern: AI Server Configuration, Tracing & Safety Filters
|
|
102
|
+
|
|
103
|
+
Configure standard LLM adapters, safety moderation filters, and telemetry tracers on the backend (`@yh-ui/ai-sdk`):
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import { createProviderAdapter, createSafetyFilter, createTracer } from '@yh-ui/ai-sdk'
|
|
107
|
+
|
|
108
|
+
// 1. Setup provider adapter (DeepSeek endpoint example)
|
|
109
|
+
const provider = createProviderAdapter({
|
|
110
|
+
provider: 'deepseek',
|
|
111
|
+
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
112
|
+
defaultModel: 'deepseek-reasoner'
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
// 2. Setup safety and content guardrails
|
|
116
|
+
const guardrail = createSafetyFilter({
|
|
117
|
+
blockHostileContent: true,
|
|
118
|
+
censorProfanity: true,
|
|
119
|
+
customBlockWords: ['private_token', 'db_password']
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
// 3. Setup telemetry and tracing
|
|
123
|
+
const tracer = createTracer({
|
|
124
|
+
projectName: 'yh-ui-ai-ops',
|
|
125
|
+
serviceName: 'assistant-service'
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
export async function processAiRequest(prompt: string, history: any[]) {
|
|
129
|
+
// Check user input against safety filters
|
|
130
|
+
const scanResult = await guardrail.scanInput(prompt)
|
|
131
|
+
if (!scanResult.safe) {
|
|
132
|
+
throw new Error(`Input violated safety rules: ${scanResult.reason}`)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Trace the LLM execution call
|
|
136
|
+
return await tracer.traceSpan('llm_generation', async () => {
|
|
137
|
+
const stream = await provider.chatStream([...history, { role: 'user', content: prompt }])
|
|
138
|
+
|
|
139
|
+
// Scan stream chunks to prevent secret leakage
|
|
140
|
+
return guardrail.pipeOutput(stream)
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Agent Rules
|
|
53
146
|
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
- Use `YhAiCodeBlock`, `YhAiCodeEditor`, and `YhAiCodeRunner` for code-centric responses instead of raw `<pre>` blocks when interaction matters.
|
|
147
|
+
- **Client Sanitization**: Keep `:enable-sanitizer="true"` on `YhAiBubble` to ensure user inputs and raw markdown rendering cannot inject hostile scripts.
|
|
148
|
+
- **Explicit Reasoning**: Never hide thinking logs inside ordinary paragraph text. Always use `YhAiThoughtChain` for models that output logical step arrays.
|
|
149
|
+
- **Python Runtime URL**: When using python code execution in `YhAiCodeRunner`, ensure a valid Pyodide URL or remote execution API endpoint is supplied if defaults are disabled.
|
|
150
|
+
- **API Secret Keys**: Never output provider secret API keys inside frontend environment variables (`VITE_`). Keep adapters configured strictly inside server endpoints.
|