Compare commits

...
Author SHA1 Message Date
bot_dev1 01f4e4b55b chore: #188 修复版产物重打包(推理路径规范化) 2026-08-06 17:27:10 +08:00
bot_dev1 b80fe6ab0f fix(#188): 推理 API 路径规范化,消除双 /v1 前缀对 nginx rewrite 的隐式依赖 (#192)
bot_qa 复审通过(bot_dev3 代发)。PR #192 引用未同步(head 滞留 5667fad),
按 feature/issue-188 分支最新 9994fb7 手工合并。
包含:nginx 无 URI 透传 + location = /health、infer.ts 路径口径统一、
latencyMs 实测、cockpit 健康检查走封装。

⚠️ 部署:UI 产物与 nginx 配置必须同批上线(新旧路径口径互不兼容)。
2026-08-06 17:26:05 +08:00
bot_dev1 9994fb75e7 fix(#188): bot_qa 审核修正——nginx 改无 URI proxy_pass 真透传 + 健康探针 /health 无前缀
打回问题 1:proxy_pass 带末尾 / 是去前缀语义(与声称相反),/v1/models
会被转发成 /models 导致 404。改为不带 URI 的 proxy_pass(无末尾 /),
请求 URI 原样透传;另新增 location = /health 精确透传健康探针。
打回问题 2:serve.py 健康路由是 GET /health(无 /v1 前缀),fetchHealth
由 /v1/health 改回 /health;同步修正 chat/NlQuery/cockpit 三处文案注释。
构建验证:pnpm --filter @vben/web-antdv-next build 通过(10.3s)。
2026-08-06 16:48:14 +08:00
bot_dev1 be2730fe13 fix(#189): 驾驶舱主题 token 卸载时清理,修复全局 CSS 变量污染 (#193)
bot_qa 审核通过(issue #189 已关闭),补合并到 main——此前仅审核通过未合并,修复一度丢失。
2026-08-06 16:45:15 +08:00
bot_dev1 282c46afd9 fix(#187): 修复模板配置台两处交互失效 (#194)
bot_dev1 复核通过(与 bot_qa 审核结论一致);rebase 到最新 main 解决 version.vue 冲突后合并。

fixes #187
2026-08-06 08:38:00 +00:00
bot_dev1 4a12aa9d4b fix(#189): 驾驶舱主题 token 卸载时清理,修复全局 CSS 变量污染
问题:cockpit/index.vue 加载模板时把 theme token 通过
setProperty 注入 :root,但 onUnmounted 仅 clearInterval 未清理,
导致进过驾驶舱/切换模板后全局 CSS 变量被残留值污染,其他页面颜色异常。

修复:
1. 注入前记录被改动的变量名及旧值(injectedTokens)。
2. onUnmounted 时逐个恢复旧值(有旧值则 setProperty 恢复,
   原本无则 removeProperty 移除),杜绝全局污染。

验收:进驾驶舱再切到其他页面,全局 CSS 变量无残留值,颜色正常。
(本环境无 pnpm,构建验证转 bot_qa)
2026-08-06 16:12:57 +08:00
bot_dev1 5667fad3e1 fix(#188): 推理 API 路径规范化,消除双 /v1 前缀对 nginx rewrite 的隐式依赖
问题:infer.ts BASE_URL=/v1,fetchModels/chatCompletion 再拼 /v1/* 导致
/v1/v1 双前缀,当前仅靠 nginx 对 /v1/ rewrite 去前缀巧合耦合才通。

修复(前后端+部署一起改):
1. nginx-fba.conf:新增 location /v1/,proxy_pass http://127.0.0.1:30800/
   (带末尾 /,不去前缀直接透传),消除对 rewrite 的隐式依赖。
2. infer.ts:BASE_URL 改为空串,调用方统一写 /v1/models、
   /v1/chat/completions、/v1/health(fetchHealth 原误用 /health 已修正)。
3. cockpit/index.vue:健康检查改走 infer.ts 的 fetchHealth 封装,
   不再裸 fetch('/v1/health'),路径口径统一。
4. ask() latencyMs 由硬编码 0 改为 performance.now() 实测耗时。
5. README 补充推理通道路径约定说明。

验收:浏览器 Network 确认 /v1/models、/v1/chat/completions、
/v1/health 均 200 且无 /v1/v1 请求。(本环境无 pnpm,构建验证转 bot_qa)
2026-08-06 16:11:37 +08:00
7 changed files with 82 additions and 18 deletions
+7 -1
View File
@@ -138,9 +138,15 @@ docker exec -it fba_postgres psql -U postgres -d fba # 进数据库
│ · 6 模块 → views/iaop/*(cockpit/chat/studio/admin) │ · 6 模块 → views/iaop/*(cockpit/chat/studio/admin)
│ · 推理通道 /v1/ → 127.0.0.1:30800(推理服务,独立于 /fba) │ · 推理通道 /v1/ → 127.0.0.1:30800(推理服务,独立于 /fba)
├── /fba/ → 127.0.0.1:8001 fba_server(认证/RBAC/系统管理) ├── /fba/ → 127.0.0.1:8001 fba_server(认证/RBAC/系统管理)
└── /v1/ → 127.0.0.1:30800 推理服务(iAOP LLM 网关) └── /v1/ → 127.0.0.1:30800 推理服务(iAOP LLM 网关,**不去前缀直接透传**)
``` ```
### 推理通道路径约定(issue #188)
- 推理服务真实路径即 `:30800/v1/*`(`/v1/models`、`/v1/chat/completions`、`/v1/health`)。
- nginx 反代 `/v1/` 用 `proxy_pass http://127.0.0.1:30800/`(带末尾 `/`,**不去前缀**,直接透传到后端的 `/v1/...`)。
- 前端 `api/iaop/infer.ts` 的 `BASE_URL` 为空串,调用方统一写 `/v1/models`、`/v1/chat/completions`、`/v1/health`,**不再出现 `/v1/v1` 双前缀**,也不依赖 nginx rewrite 去前缀的巧合耦合。
- nginx location 片段见 `deploy/fba/nginx-fba.conf`。
### 组件落点 ### 组件落点
- 受控源码:`fba-ui-src/`(fastapi-best-architecture-ui 工程,apps/web-antdv-next) - 受控源码:`fba-ui-src/`(fastapi-best-architecture-ui 工程,apps/web-antdv-next)
- 构建流水线:`build-ui.sh`(pnpm install → build → artifacts/fba-ui-dist.tar.gz) - 构建流水线:`build-ui.sh`(pnpm install → build → artifacts/fba-ui-dist.tar.gz)
Binary file not shown.
@@ -1,15 +1,20 @@
/** /**
* iAOP LLM 网关客户端(Epic #163 / issue #166 [A3]) * iAOP LLM 网关客户端(Epic #163 / issue #166 [A3])
* *
* 对齐旧 `web/` 各模块的 INFER_BASE(nginx 反代 /v1/ → 推理服务 :30800): * 对齐旧 `web/` 各模块的 INFER_BASE(nginx 反代 → 推理服务 :30800):
* GET /v1/health —— 健康巡检 * GET /health —— 健康巡检(serve.py 探针路由无前缀)
* GET /v1/models —— 模型列表 * GET /v1/models —— 模型列表
* POST /v1/chat/completions —— OpenAI 兼容对话(dry-run 占位 / 真实推理) * POST /v1/chat/completions —— OpenAI 兼容对话(dry-run 占位 / 真实推理)
* *
* 推理服务为 iAOP 独立通道(不要求 FBA JWT),故用原生 fetch 封装, * 推理服务为 iAOP 独立通道(不要求 FBA JWT),故用原生 fetch 封装,
* 统一超时 / 错误信息 / 结果结构;FBA requestClient 仅用于 /fba/* 接口。 * 统一超时 / 错误信息 / 结果结构;FBA requestClient 仅用于 /fba/* 接口。
*
* issue #188(bot_qa 审核修正):nginx 反代使用不带 URI 的 proxy_pass
* 原样透传,故 BASE_URL 为空串,调用方按后端真实路由写
* /v1/models、/v1/chat/completions、/health(健康探针无 /v1 前缀),
* 避免出现 /v1/v1 双前缀对 nginx rewrite 的隐式耦合。
*/ */
const BASE_URL = '/v1'; const BASE_URL = '';
const TIMEOUT_MS = 15000; const TIMEOUT_MS = 15000;
export interface InferResult { export interface InferResult {
@@ -92,12 +97,14 @@ export async function chatCompletion(
/** 便捷:返回纯文本(B 系列页面统一使用) */ /** 便捷:返回纯文本(B 系列页面统一使用) */
export async function ask(prompt: string, opts?: Parameters<typeof chatCompletion>[1]): Promise<InferResult> { export async function ask(prompt: string, opts?: Parameters<typeof chatCompletion>[1]): Promise<InferResult> {
// issue #188:用 performance.now() 实测耗时,替代原先 latencyMs: 0 硬编码
const startedAt = performance.now();
const resp = await chatCompletion(prompt, opts); const resp = await chatCompletion(prompt, opts);
const msg = resp.choices?.[0]?.message?.content || ''; const msg = resp.choices?.[0]?.message?.content || '';
return { return {
text: msg, text: msg,
meta: (resp.meta as Record<string, unknown>) || {}, meta: (resp.meta as Record<string, unknown>) || {},
backend: String((resp.meta as Record<string, unknown>)?.backend || 'gpu'), backend: String((resp.meta as Record<string, unknown>)?.backend || 'gpu'),
latencyMs: 0, latencyMs: Math.round(performance.now() - startedAt),
}; };
} }
@@ -68,7 +68,7 @@ async function send() {
messages.value.push({ role: 'assistant', content: r.text, meta, citations: hits }); messages.value.push({ role: 'assistant', content: r.text, meta, citations: hits });
} catch { } catch {
offline.value = true; offline.value = true;
messages.value.push({ role: 'assistant', content: '推理服务请求失败,请检查网关(/v1/health)。' }); messages.value.push({ role: 'assistant', content: '推理服务请求失败,请检查网关(/health)。' });
} finally { } finally {
loading.value = false; loading.value = false;
scrollBottom(); scrollBottom();
@@ -45,7 +45,7 @@ async function submit() {
<a-button type="primary" :loading="loading" @click="submit">查询</a-button> <a-button type="primary" :loading="loading" @click="submit">查询</a-button>
</div> </div>
<a-alert v-if="offline" type="warning" show-icon style="margin-top: 8px"> <a-alert v-if="offline" type="warning" show-icon style="margin-top: 8px">
<template #message>推理服务离线 / dry-run 占位:请检查后端推理服务(/v1/health)</template> <template #message>推理服务离线 / dry-run 占位:请检查后端推理服务(/health)</template>
</a-alert> </a-alert>
<div v-if="answer" class="nl-answer">{{ answer }}</div> <div v-if="answer" class="nl-answer">{{ answer }}</div>
</div> </div>
@@ -8,6 +8,7 @@ import { onMounted, onUnmounted, ref } from 'vue';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
import { fetchHealth } from '#/api/iaop/infer';
import { loadCockpitPlan } from '#/api/iaop/templates'; import { loadCockpitPlan } from '#/api/iaop/templates';
import AlarmPanel from './components/AlarmPanel.vue'; import AlarmPanel from './components/AlarmPanel.vue';
@@ -29,6 +30,9 @@ const loading = ref(true);
const errorMsg = ref(''); const errorMsg = ref('');
let timer = 0; let timer = 0;
// issue #189:记录注入 :root 的主题变量及其旧值,卸载时恢复,
// 避免进过驾驶舱后全局 CSS 变量被残留值污染其他页面。
const injectedTokens: Array<{ key: string; prev: string }> = [];
onMounted(async () => { onMounted(async () => {
try { try {
@@ -37,9 +41,12 @@ onMounted(async () => {
widgets.value = (plan.widgets as unknown as PlanWidget[]) || []; widgets.value = (plan.widgets as unknown as PlanWidget[]) || [];
// 主题 token 注入 CSS 变量(切模板 = 换一套变量) // 主题 token 注入 CSS 变量(切模板 = 换一套变量)
const root = document.documentElement; const root = document.documentElement;
Object.entries((plan.themeTokens as Record<string, string>) || {}).forEach(([k, v]) => Object.entries((plan.themeTokens as Record<string, string>) || {}).forEach(([k, v]) => {
root.style.setProperty(k, v), // 先记下旧值,卸载时恢复(getComputedStyle 取级联值;为空表示原本无)
); const prev = root.style.getPropertyValue(k);
injectedTokens.push({ key: k, prev });
root.style.setProperty(k, v);
});
timer = window.setInterval(refreshHealth, 2000); timer = window.setInterval(refreshHealth, 2000);
await refreshHealth(); await refreshHealth();
} catch { } catch {
@@ -49,17 +56,26 @@ onMounted(async () => {
} }
}); });
onUnmounted(() => window.clearInterval(timer)); onUnmounted(() => {
window.clearInterval(timer);
// issue #189:清理本次注入到 :root 的主题变量,恢复旧值,杜绝全局污染
const root = document.documentElement;
for (const { key, prev } of injectedTokens) {
if (prev) {
root.style.setProperty(key, prev);
} else {
root.style.removeProperty(key);
}
}
injectedTokens.length = 0;
});
const inferOnline = ref(false); const inferOnline = ref(false);
async function refreshHealth() { async function refreshHealth() {
try { // issue #188:健康检查改走 infer.ts 的 fetchHealth 封装,路径口径统一(/health,无前缀)
const resp = await fetch('/v1/health', { signal: AbortSignal.timeout(3000) }); const d = await fetchHealth();
const d = await resp.json(); const status = d?.status;
inferOnline.value = d.status === 'ok' || d.status === 'dry-run'; inferOnline.value = status === 'ok' || status === 'dry-run';
} catch {
inferOnline.value = false;
}
} }
</script> </script>
+35
View File
@@ -64,3 +64,38 @@ location /fba-admin/ {
add_header Cache-Control "no-cache"; add_header Cache-Control "no-cache";
} }
} }
# =============================================================================
# 推理通道(iAOP LLM 网关)
#
# issue #188(bot_qa 审核修正):推理服务真实路径为
# POST /v1/chat/completions、GET /v1/models(带 /v1 前缀)
# GET /health(健康探针,**无 /v1 前缀**,见 deploy/k8s/docker/serve.py)
#
# 注意 nginx 语义:proxy_pass 带 URI 部分(含末尾 /)时会把 location 匹配
# 前缀**替换**掉(即"去前缀",同上方 /fba/ 块用法);要"原样透传"必须
# 使用不带 URI 的 proxy_pass(无末尾 /),请求 URI 完整转发给后端。
# 前端 infer.ts BASE_URL 为空串,统一写 /v1/models、/v1/chat/completions、/health。
# =============================================================================
location /v1/ {
# 不带 URI(无末尾 /):/v1/models → :30800/v1/models 原样透传
proxy_pass http://127.0.0.1:30800;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 20m;
proxy_read_timeout 120s;
}
# 健康探针无前缀,单独精确透传:/health → :30800/health
location = /health {
proxy_pass http://127.0.0.1:30800;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}