# AGENTS.md — 项目开发规范
## 项目概述
本项目是**沙鲁智能体工作流平台**前端应用,基于 Vue 3 + TypeScript + Vite 构建的企业级 SPA。
### 技术栈
| 类别 | 技术选型 |
|------|----------|
| 框架 | Vue 3.5 (Composition API, `
```
### 单向数据流
- 父 → 子: Props 传递,只读
- 子 → 父: Emits 事件
- 跨层级: Pinia Store
- 禁止直接修改 Props
### 组件拆分原则
- 单个组件不超过 300 行 (模板 + 逻辑)
- 可复用的 UI 片段抽取为独立组件
- 业务逻辑复杂时抽取到 `composables/`
- API 调用抽取到 `api/` 目录
---
## TypeScript 使用规范
### 编译配置 (tsconfig.app.json)
```json
{
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true
}
```
### 类型定义
- 优先使用 `interface` 定义对象类型,`type` 用于联合/交叉类型
- 模块级别类型定义放在 `types.ts`
- 全局通用类型放在 `src/types/`
- 避免 `any`,使用 `unknown` + 类型守卫,或具体类型
- Props 使用泛型 `defineProps()`,不推荐运行时声明
### 路径别名
```typescript
import { useI18n } from '@/composables/useI18n'
import MessageList from '@/components/Chat/MessageList.vue'
// @ 映射到 src/
```
---
## 状态管理 (Pinia)
### Store 定义模式
使用 **Setup Store** 语法 (组合式):
```typescript
// store/modules/dashboard.ts
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useDashboardStore = defineStore('dashboard', () => {
const activeTab = ref('flows')
const setActiveTab = (tab: string) => {
activeTab.value = tab
}
return { activeTab, setActiveTab }
})
```
### Store 使用规范
- Store 文件放在 `store/modules/` 下
- 按功能域拆分,避免单一巨型 store
- Store 命名: `use[Xxx]Store`
- 在 `store/index.ts` 中统一导出
- 优先使用 `ref` / `reactive` 而非 `state` 选项
- 暴露方法而非直接暴露状态修改
---
## API 调用规范
### 架构分层
```
UI 组件 / Composable
↓
@repo/api-service (自动生成的类型安全 API)
↓
@repo/api-client (统一 HTTP 客户端)
↓
Axios → 后端服务
```
### 自动生成的 API
`@repo/api-service` 由 `packages/api-service` 的 `openapi2ts` 从 OpenAPI schema 自动生成。各模块的 API 函数按服务拆分:
```typescript
import { knowledge, agentApplication, aiChat } from '@repo/api-service'
// 类型安全的 API 调用
const res = await knowledge.postAiFaqCreate({ ... })
const agents = await agentApplication.getAiAgentOptions()
```
### 通用 API 调用
`src/api/` 下放置非自动生成的手写接口:
```typescript
// api/index.ts
import request from '@repo/api-client'
export const uploadFile = (data: FormData) =>
request.post('/File/Upload', data)
```
### 全局拦截器
`src/api/interceptor.ts` 注册全局响应拦截器:统一的 `isSuccess === false` 错误提示。
### API 调用原则
- 页面级 API 调用放在模块 `api/` 目录下
- 不要在组件中直接写 `fetch` 或 `axios`
- 异步调用统一使用 `async/await` + `try/catch`
- 返回值始终检查 `isSuccess`
---
## 路由规范
### 路由配置
```typescript
// router/index.ts
const routes = [
{
path: '/',
component: MainLayout, // 布局组件
children: [ // 嵌套子路由
{ path: '', name: 'Dashboard', component: Dashboard },
{ path: 'chat', name: 'Chat', component: Chat },
]
},
{
path: '/workflow/:id', // 独立路由 (无布局)
name: 'Editor',
component: Editor
}
]
```
### 路由规范
- 使用 Hash 模式 (`createWebHashHistory`)
- 页面组件使用**懒加载**: `() => import('@/views/...')`
- 路由 name 使用 PascalCase
- path 使用 kebab-case
- 嵌套路由通过 `children` 配置
---
## 国际化规范
### 使用方式
```typescript
import { useI18n } from '@/composables/useI18n'
const { t } = useI18n()
// 模板中使用
{{ t('pages.chat.send') }}
// 带参数
t('pages.chat.messageCount', { count: 5 })
```
### 语言包结构
`i18n/locales/{locale}.ts` 采用层级嵌套结构:
```typescript
export default {
common: {
confirm: '确认',
cancel: '取消'
},
pages: {
chat: {
send: '发送',
emptyTitle: '开始对话'
}
}
}
```
### 规范
- Key 命名: `模块.页面.具体文案`,使用 `.` 分隔
- 禁止硬编码中文/英文到模板中
- 新增文案同时更新 `zh-cn.ts` 和 `en-us.ts`
---
## 样式规范
### 技术方案
- **CSS 框架**: UnoCSS (原子化 CSS)
- **预处理**: Less (组件级样式)
- **UI 库**: Element Plus (统一组件风格)
- **主题**: CSS 变量实现亮/暗色切换
### 组件样式规范
```vue
```
### 样式编写原则
- 优先使用 UnoCSS 原子类 (class 属性)
- 组件私有样式使用 `