Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions ui/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ ui/
│ ├── constants/ # Cross-feature constants grouped by domain
│ │ └── CONSTANT_README.md # Shared constant placement and naming rules
│ ├── layout/ # Shared application shells, headers, sidebars, types, and helpers
│ ├── locales/ # Reserved for internationalization messages and locale setup
│ ├── permission/ # Permission policies, business permission methods, and Admin $perm plugin
│ ├── workflow-canvas/ # LogicFlow canvas and workflow domain components
│ │ ├── component/ # Reusable workflow canvas UI
│ │ ├── config/ # Maintainable node data, menus, mappings, and constants
│ │ ├── core/ # Stable canvas behavior and shared node infrastructure
│ │ ├── details/ # Node execution detail dispatch and shared presentation
│ │ ├── icons/ # Workflow node icons
│ │ ├── node-menu/ # Basic, tool, and application node selection menus
│ │ ├── nodes/ # Workflow node definitions and components
│ │ ├── plugins/ # Canvas-local plugins
│ │ ├── store/ # Resource API adapters, query caching, and request deduplication
│ │ ├── WORKFLOW_README.md # Canvas boundaries and maintenance rules
│ │ ├── types.ts # Workflow canvas protocol types
│ │ └── index.vue # MkWorkflow canvas entry
│ │ └── index.vue # WorkflowCanvas canvas entry
│ ├── router/ # Vue Router routes and router instance
│ │ └── ROUTE_README.md # Routing conventions and rules
│ ├── stores/ # Shared Pinia instance and state stores
Expand All @@ -95,16 +98,27 @@ ui/
│ ├── views/ # Route-level page components grouped by feature
│ │ ├── VIEW_README.md # Page responsibilities and feature-local code rules
│ │ ├── home/ # Workspace home page
│ │ ├── application/ # Application list and creation
│ │ ├── application-detail/ # Application overview and settings
│ │ ├── knowledge/ # Knowledge base list and cards
│ │ ├── knowledge-detail/ # Knowledge base and document details
│ │ ├── model/ # Model list, creation, and settings
│ │ ├── tool/ # Tool list, forms, and tool store
│ │ ├── trigger/ # Workspace trigger list
│ │ ├── system/ # System-management pages
│ │ ├── login/ # Reserved for admin login pages
│ │ ├── chat/ # Chat-side pages, including user login
│ │ ├── login/ # Admin login, account recovery, and login modes
│ │ ├── chat/ # Chat entry placeholder page
│ │ ├── error/ # Not-found page
│ │ ├── details-demo/ # Temporary execution-detail preview page
│ │ └── workflow/ # Full-screen workflow route pages
├── vite.config.ts # Vite entries, plugins, aliases, proxy, and build output
├── tsconfig*.json # TypeScript configuration
└── package.json # Dependencies and npm scripts
```

Directories marked as reserved may be empty while their feature is being introduced. Add files to the matching feature directory instead of creating parallel top-level structures.
Internationalization is not yet integrated; `src/locales/` has not been created. Chat currently has a
placeholder route page and a reserved independent API directory. Add files to the matching feature
directory instead of creating parallel top-level structures.

Structural responsibilities:

Expand All @@ -113,7 +127,7 @@ Structural responsibilities:
- Put reusable application chrome in `layout/`, not in individual route views.
- Keep LogicFlow initialization, node registration, and canvas behavior inside `workflow-canvas/`.
Every page rendering this canvas belongs in `views/workflow/`; those Views own the page header,
route and page-level actions around `MkWorkflow`.
route and page-level actions around `WorkflowCanvas`.
- Put server communication in `api/`, isolate Admin and Chat request systems, and group business APIs
by domain and resource according to `src/api/API_README.md`.
- Put backend fixed-value enums in `api/enums/` and import them through `@/api/enums`; keep
Expand Down Expand Up @@ -149,7 +163,8 @@ Important variables:
- `VITE_APP_PORT`: local dev server port
- `VITE_APP_TITLE`: HTML title
- `VITE_ENTRY`: HTML entry file
- `VITE_API_TARGET`: optional backend proxy target, defaults to `http://127.0.0.1:8080`
- `VITE_API_TARGET`: optional backend proxy target; currently defaults to `http://47.120.55.164:38080`
through `defaultBackendTarget` in `vite.config.ts`. Override it locally for a different backend.

Build output mirrors the v2 layout:

Expand All @@ -169,10 +184,14 @@ npm run chat # chat dev server
npm run build # default admin build with type-check
npm run build-chat # chat build with type-check
npm run type-check
npm run lint
npm run format
```

Node.js must satisfy `^22.18.0 || >=24.12.0` as declared in `package.json`.
Admin and Chat use ports 3000 and 3001 respectively, with `strictPort` enabled.
`npm run lint` currently delegates to `lint:*`, but no matching scripts are defined. Use
`npx eslint <changed-files>` for targeted linting until those scripts are configured.

## Vite Configuration

Main config: `vite.config.ts`.
Expand Down
119 changes: 85 additions & 34 deletions ui/README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,99 @@
# ui
# MaxKB v3 前端

This template should help get you started developing with Vue 3 in Vite.
MaxKB 企业级 AI 智能体平台的前端工程,使用 Vue 3.5、TypeScript 6、Vite 8、Element Plus、
Tailwind CSS 4、Pinia 3 和 Vue Router 5,工作流画布基于 LogicFlow。

## Recommended IDE Setup
项目采用 Admin 和 Chat 双入口。Admin 包含登录、工作空间资源、系统管理和工作流编辑等功能;
Chat 已配置独立入口与路由,当前 `ChatView.vue` 仍为空白占位页,`src/api/chat/` 的独立请求体系尚未实现。

[VS Code](https://code.visualstudio.com/) + [Vue (Official)](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
## 本地开发

## Recommended Browser Setup
Node.js 版本要求为 `^22.18.0 || >=24.12.0`,以 `package.json` 的 `engines` 为准。
以下命令均在 `ui/` 目录执行:

- Chromium-based browsers (Chrome, Edge, Brave, etc.):
- [Vue.js devtools](https://chromewebstore.google.com/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd)
- [Turn on Custom Object Formatter in Chrome DevTools](http://bit.ly/object-formatters)
- Firefox:
- [Vue.js devtools](https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/)
- [Turn on Custom Object Formatter in Firefox DevTools](https://fxdx.dev/firefox-devtools-custom-object-formatters/)

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.

## Customize configuration

See [Vite Configuration Reference](https://vite.dev/config/).

## Project Setup

```sh
```bash
npm install
npm run dev
```

### Compile and Hot-Reload for Development
Admin 默认访问地址为 `http://localhost:3000/admin/`。在另一个终端运行 `npm run chat`,
可通过 `http://localhost:3001/chat/` 访问 Chat 入口。开发服务器启用 `strictPort`,端口被占用时不会自动换端口。

```sh
npm run dev
```
### 后端代理与环境变量

### Type-Check, Compile and Minify for Production
公共及 Admin 默认配置在 `env/.env`,Chat 模式通过 `env/.env.chat` 覆盖入口、路径和端口。
本地覆盖可放在 `env/.env.local`,Chat 专属覆盖可放在 `env/.env.chat.local`。

```sh
npm run build
```
| 变量 | Admin 默认值 | Chat 默认值 | 用途 |
| ----------------- | ------------ | ----------- | -------------------------- |
| `VITE_APP_NAME` | `admin` | `chat` | 应用名称 |
| `VITE_BASE_PATH` | `/admin/` | `/chat/` | 路由基础路径与构建输出目录 |
| `VITE_APP_PORT` | `3000` | `3001` | 开发服务端口 |
| `VITE_APP_TITLE` | `MaxKB` | `MaxKB` | HTML 标题 |
| `VITE_ENTRY` | `admin.html` | `chat.html` | HTML 入口 |
| `VITE_API_TARGET` | 未设置 | 未设置 | 覆盖开发代理的后端地址 |

### Lint with [ESLint](https://eslint.org/)
当前未设置 `VITE_API_TARGET` 时,使用 `vite.config.ts` 中的 `defaultBackendTarget`,
值为 `http://47.120.55.164:38080`。连接本地后端时,在 `env/.env.local` 中配置:

```sh
npm run lint
```dotenv
VITE_API_TARGET=http://127.0.0.1:8080
```

开发代理覆盖 `/admin/api`、`/chat/api`、`/doc`、`/schema`、`/static` 和当前应用基础路径下的
OSS 文件接口。前端业务接口需要可用的后端服务。

## 构建与检查

| 命令 | 作用 |
| -------------------------------- | ------------------------------- |
| `npm run dev` | 启动 Admin 开发服务 |
| `npm run chat` | 启动 Chat 开发服务 |
| `npm run build` | 类型检查并构建 Admin |
| `npm run build-chat` | 类型检查并构建 Chat |
| `npm run build-only` | 仅构建 Admin |
| `npm run build-only-chat` | 仅构建 Chat |
| `npm run type-check` | 使用 `vue-tsc --build` 检查类型 |
| `npm run preview` | 预览 Admin 构建产物 |
| `npm run preview -- --mode chat` | 预览 Chat 构建产物 |
| `npm run format` | 使用 Prettier 格式化 `src/` |

`npm run lint` 当前仅配置了 `run-s "lint:*"`,但尚未定义任何 `lint:*` 子脚本,不能作为已执行
ESLint 检查的依据。需要检查代码时,可运行 `npx eslint <待检查的文件或目录>`。

默认构建分别输出 `dist/admin/index.html` 和 `dist/chat/index.html`,HTML 由构建插件统一重命名。
静态资源使用相对路径(`base: './'`);部署时仍需为 History 路由配置对应入口回退,
并由部署服务转发 API 和文件请求。Vite 的开发代理不会随静态构建产物部署。

## 代码目录

| 目录或文件 | 职责 |
| ------------------------------- | ---------------------------------------------------- |
| `src/main.ts` / `src/chat.ts` | Admin / Chat 启动入口 |
| `src/api/` | 请求基础设施、业务 API、后端枚举与共享类型 |
| `src/components/` | 全局 Mk 组件、跨页面业务组件及其他共享组件 |
| `src/layout/` | 应用头部、侧栏与资源详情布局 |
| `src/views/` | 登录、工作空间、系统管理、资源详情和工作流等路由页面 |
| `src/workflow-canvas/` | 画布内核、节点配置、节点实现、执行详情与资源查询缓存 |
| `src/router/` | Admin / Chat 独立路由 |
| `src/permission/` | 权限策略、分业务权限方法与 Admin `$perm` 插件 |
| `src/stores/` | 共享 Pinia 实例及认证、用户、主题状态 |
| `src/styles/` | 主题变量、Tailwind、Element Plus 集成与全局样式 |
| `src/constants/` / `src/utils/` | 跨功能常量与工具函数 |
| `src/assets/` / `public/` | 源码导入资源 / 保留原始路径的静态资源 |

## 开发约定与文档

修改前先阅读 [AGENTS.md](AGENTS.md),再阅读涉及领域的规则文档:

- [样式](src/styles/STYLE_README.md)
- [组件](src/components/COMPONENT_README.md)
- [路由](src/router/ROUTE_README.md)
- [API](src/api/API_README.md)
- [页面](src/views/VIEW_README.md)
- [工作流画布](src/workflow-canvas/WORKFLOW_README.md)
- [常量](src/constants/CONSTANT_README.md)
- [工具函数](src/utils/UTILS_README.md)

详细规则由各领域 README 维护;目录、公共接口或使用约定变化时同步对应文档。
`src/components.d.ts` 由组件自动注册插件生成,不手动编辑。
38 changes: 11 additions & 27 deletions ui/src/api/admin/core/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,36 +256,20 @@ export function post<TData = unknown, T = unknown>(url: string, data?: TData, pa
}

/** 发送 POST 请求并返回可逐块读取的原始响应。 */
export async function postStream<TData = unknown>(url: string, data?: TData, config: StreamRequestConfig = {}) {
export function postStream(base: string, path: string, data?: unknown) {
const { auth, user } = useStore()
const headers = new Headers({ 'Content-Type': 'application/json' })
if (auth.token) headers.set('Authorization', `Bearer ${auth.token}`)
if (user.language) headers.set('Accept-Language', user.language)

const baseUrl = String(request.defaults.baseURL ?? '').replace(/\/+$/, '')
const response = await fetch(`${baseUrl}/${url.replace(/^\/+/, '')}`, {
body: JSON.stringify(data ?? {}),
headers,
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
if (auth.token) {
headers['Authorization'] = `Bearer ${auth.token}`
}
if (user.language) {
headers['Accept-Language'] = user.language
}
return fetch(`${base}${path.startsWith('/') ? path : `/${path}`}`, {
method: 'POST',
signal: config.signal,
headers,
body: data === undefined ? undefined : JSON.stringify(data),
})

if (response.ok) return response

const errorMessage = (await getFetchErrorMessage(response)) || response.statusText
if (response.status === 401) {
auth.clearToken()
void router.push({ name: 'login' })
} else if (response.status === 403) {
MsgError(errorMessage || 'No permission to access')
} else if (response.status === 404) {
void router.replace({ name: 'not-found', params: { pathMatch: ['404'] } })
} else {
MsgError(errorMessage)
}
const error = new Error(errorMessage)
error.name = 'StreamRequestError'
throw error
}

/** 发送 PUT 请求。 */
Expand Down
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/file-audio-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/file-document-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ui/src/assets/file-type/file-image-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions ui/src/assets/file-type/file-video-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading