auto(14b5ea1b9bd9): session end @ 2026-07-25T17:18:06 (+2f)
This commit is contained in:
1 parent
84d7882118
commit
c0e59a3e1d
2 files changed
+97
-64
No files matched your search
+90
-47
@@ -207,55 +207,23 @@ async function callNcpfBackendWithRetry(
|
||||
}
|
||||
|
||||
export async function callAiForm(keyword: string): Promise<AiFormResponse> {
|
||||
const aiChain: string[] = [] // v0.19+ BS-新72: 调用链, 失败时给用户看
|
||||
let r: JnpfResp<AiFormResponse>
|
||||
try {
|
||||
r = await callNcpfBackendWithRetry(keyword)
|
||||
} catch (e) {
|
||||
aiChain.push(`NCPF: 重试耗尽 ${(e as Error).message?.slice(0, 60) || ''}`)
|
||||
// 重试耗尽仍 429: fallback SSW (SSW 自己调 LLM, 不走 jnpf token plan)
|
||||
log.warn(`! NCPF 重试耗尽 → fallback SSW 修复 (BS-新113)`)
|
||||
return await callSswAiRepair(keyword, 'NCPF 429 retry exhausted', aiChain)
|
||||
// v0.22+ (2026-07-25 BS-新131~133, tdd3 P1-5 闭环): SSW /build-form 单一来源
|
||||
// 旁路 NCPF backend (4+3 限制真根因: 硬编码白名单 + 强制改名 + 子表排除 + 输出长度限制)
|
||||
// NCPF 路径已废弃 (P1-5 闭环后), 全部走 SSW 一条路径, 避免 NCPF/SSW 双重处理逻辑
|
||||
const sswResult = await callSswBuildForm(keyword)
|
||||
if (sswResult.enCode) {
|
||||
log.ok(`✓ callAiForm 走 SSW /build-form 路径 (v0.22+ P1-5 闭环)`)
|
||||
return sswResult
|
||||
}
|
||||
|
||||
// 场景 A: NCPF 错误 → fallback SSW
|
||||
// 所有非 200 都走 SSW, 不再区分截断类型
|
||||
// NCPF 配了 AI 会用, 没配就 fail — SSW 自己有 DeepSeek, 不需要 NCPF
|
||||
if (r.code !== 200) {
|
||||
// P1-7 Login expired 全局阻塞场景
|
||||
// 根因: NCPF 后端 AI 服务 token 失效, SSW /ssw/ai/repair 也走同 token 必 fail
|
||||
// 检测 Login expired 后跳过 SSW fallback (浪费 2 次重试), 直接返回
|
||||
// loginExpired=true 让 create.ts 走 web buildFormData 默认空 schema
|
||||
if (isLoginExpired(r)) {
|
||||
aiChain.push(`NCPF: Login expired (code=${r.code}, msg=${(r.msg || '').slice(0, 80)})`)
|
||||
log.warn(`! NCPF Login expired → AI 后端 token 失效, 跳过 SSW fallback (BS-新113 P1-7)`)
|
||||
log.warn(` SSW 同 token 失效, 不重试 (会浪费 5s/10s/20s), 走 web buildFormData 默认空 schema`)
|
||||
return { _aiChain: aiChain, loginExpired: true }
|
||||
}
|
||||
aiChain.push(`NCPF: code=${r.code} ${(r.msg || '').slice(0, 60)}`)
|
||||
log.warn(`! NCPF AI 建表失败 (code=${r.code}): ${r.msg} → fallback SSW 修复`)
|
||||
return await callSswAiRepair(keyword, 'NCPF 错误', aiChain)
|
||||
// SSW Login expired 透传 (与之前 NCPF Login expired 行为一致: 走 web buildFormData 默认空 schema)
|
||||
if ((sswResult as any).loginExpired) {
|
||||
log.warn(`! callAiForm SSW Login expired → 走 web buildFormData 默认空 schema`)
|
||||
return sswResult
|
||||
}
|
||||
|
||||
// 场景 B: 静默截断 (code=200 但 data 空) → fallback SSW
|
||||
// 修复 加 fieldCount 检测, 避免中间截断 (enCode 有但 fields=[]) 漏判
|
||||
const data: AiFormResponse = r.data ?? {}
|
||||
const isEmpty = !data.enCode && !data.fullName && (!data.aiModelList || data.aiModelList.length === 0)
|
||||
// 估算 keyword 实际要求字段数 (每个"/"或"字段"/"列"分隔符 +1)
|
||||
const requiredFieldCount = estimateFieldCount(keyword)
|
||||
// 实际返回字段数 (aiModelList[0].fields.length)
|
||||
const actualFieldCount = (data.aiModelList && data.aiModelList[0]?.fields?.length) || 0
|
||||
// 截断判定: 用户要求 N 字段, 但 N=0 或 (N>=3 但实际 0) → 中间截断
|
||||
const isSilentTruncation = isEmpty || (requiredFieldCount >= 3 && actualFieldCount === 0)
|
||||
if (isSilentTruncation) {
|
||||
aiChain.push(`NCPF: 静默截断 (要求 ${requiredFieldCount} 字段, 实际 ${actualFieldCount})`)
|
||||
log.warn(`! jnpf 后端 AI 响应截断 → fallback SSW 修复 (要求 ${requiredFieldCount} 字段, 实际 ${actualFieldCount})`)
|
||||
return await callSswAiRepair(keyword, 'jnpf 后端静默截断', aiChain)
|
||||
}
|
||||
|
||||
// 成功路径: 把 chain 也带回去 (虽然空, 表明尝试了 NCPF)
|
||||
data._aiChain = aiChain.length > 0 ? aiChain : ['NCPF: 200 OK']
|
||||
return data
|
||||
// SSW 失败: 走 web buildFormData 默认空 schema (NCPF 路径已废弃, 不再 fallback)
|
||||
log.warn(`! SSW /build-form 失败: ${(sswResult._aiChain || []).join(' / ')}`)
|
||||
log.warn(` 走 web buildFormData 默认空 schema (NCPF 路径已废弃, 不再 fallback)`)
|
||||
return sswResult
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,6 +289,81 @@ async function callSswAiRepair(keyword: string, reason: string, aiChain: string[
|
||||
return { _aiChain: aiChain }
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.22+ (2026-07-25 BS-新131~133, tdd3 P1-5 闭环): SSW 直调 /build-form 端点
|
||||
*
|
||||
* 旁路 NCPF backend /api/visualdev/ai/form (NCPF 4+3 限制真根因):
|
||||
* - NCPF 硬编码 jnpfKey 白名单 + 强制字段改名 (xxx_num001) + 子表排除
|
||||
* - NCPF 输出长度限制, prompt 不可见不可改
|
||||
*
|
||||
* 直调 ssw-common /api/ssw/ai/build-form (我们写的端点):
|
||||
* - prompt 完全可控, 显式禁用 NCPF 4+3 限制
|
||||
* - 强制 7 字段 relationForm 完整 schema
|
||||
* - 强制 f_<entity>_<purpose> snake_case 字段命名
|
||||
* - 同一 base_ai LLM (无 token plan 限制)
|
||||
*
|
||||
* @param keyword --ai 业务描述
|
||||
* @returns VisualAiModel 兼容结构; 失败时返回 { _aiChain, loginExpired? }
|
||||
*/
|
||||
export async function callSswBuildForm(keyword: string): Promise<AiFormResponse> {
|
||||
const aiChain: string[] = []
|
||||
const c = await JnpfClient.fromToken()
|
||||
|
||||
// 1. 拉候选 form + dict 列表 (供 prompt 推理用)
|
||||
let formsJson = '[]'
|
||||
let dictsJson = '[]'
|
||||
try {
|
||||
const formsResp = await c.get<{ list?: Array<{ id?: string; enCode?: string; fullName?: string }> }>(
|
||||
'/visualdev/Base', { currentPage: 1, pageSize: 200 },
|
||||
)
|
||||
formsJson = JSON.stringify((formsResp.data?.list || []).map(f => ({
|
||||
id: f.id, enCode: f.enCode, fullName: f.fullName,
|
||||
})))
|
||||
} catch (e) {
|
||||
log.warn(`callSswBuildForm: 拉 form list 失败 (${(e as Error).message?.slice(0, 60)}), 用空列表`)
|
||||
}
|
||||
try {
|
||||
const dictsResp = await c.get<{ list?: Array<{ id?: string; enCode?: string; fullName?: string }> }>(
|
||||
'/system/DictionaryType', { currentPage: 1, pageSize: 200 },
|
||||
)
|
||||
dictsJson = JSON.stringify((dictsResp.data?.list || []).map(d => ({
|
||||
id: d.id, enCode: d.enCode, fullName: d.fullName,
|
||||
})))
|
||||
} catch (e) {
|
||||
log.warn(`callSswBuildForm: 拉 dict list 失败 (${(e as Error).message?.slice(0, 60)}), 用空列表`)
|
||||
}
|
||||
|
||||
// 2. 调 SSW /build-form (我们 v0.22+ 新加的端点)
|
||||
log.info(`[SSW /build-form] POST /api/ssw/ai/build-form forms=${formsJson.length}B dicts=${dictsJson.length}B`)
|
||||
try {
|
||||
const r = await c.postJson<AiFormResponse>('/ssw/ai/build-form', {
|
||||
formDesc: keyword,
|
||||
appCode: c.appCode,
|
||||
formsJson,
|
||||
dictsJson,
|
||||
})
|
||||
if (r.code === 200 && r.data && r.data.enCode) {
|
||||
const fieldCount = r.data.aiModelList?.[0]?.fields?.length || 0
|
||||
log.ok(`✓ SSW /build-form 成功: enCode=${r.data.enCode}, fullName=${r.data.fullName}, fields=${fieldCount}`)
|
||||
r.data._aiChain = ['SSW /build-form: 200 OK']
|
||||
return r.data
|
||||
}
|
||||
// Login expired 检测 (跟 NCPF 同 token 失效)
|
||||
if (isLoginExpired(r as unknown as { code?: number; msg?: string })) {
|
||||
aiChain.push(`SSW /build-form: Login expired (code=${(r as any).code}, msg=${((r as any).msg || '').slice(0, 80)})`)
|
||||
log.warn(`! SSW /build-form Login expired → AI 后端 token 失效 (BS-新113 P1-7)`)
|
||||
return { _aiChain: aiChain, loginExpired: true }
|
||||
}
|
||||
aiChain.push(`SSW /build-form: code=${r.code} ${(r.msg || '').slice(0, 100)}`)
|
||||
log.warn(`! SSW /build-form 失败 (code=${r.code}): ${r.msg}`)
|
||||
return { _aiChain: aiChain }
|
||||
} catch (e) {
|
||||
aiChain.push(`SSW /build-form: 异常 ${(e as Error).message?.slice(0, 100)}`)
|
||||
log.warn(`! SSW /build-form 异常: ${(e as Error).message?.slice(0, 100)}`)
|
||||
return { _aiChain: aiChain }
|
||||
}
|
||||
}
|
||||
|
||||
/** 5.10.3 — AI 创建流程 (NCPF backend + SSW 修复 fallback)
|
||||
* 镜像 web/apps/jnpf-web-apps-main/src/api/workFlow/template.ts: getAiInfo → POST /api/workflow/ai
|
||||
* (workflow, 2026-07-02): 加 SSW 修复层, 跟 form --ai 模式一致
|
||||
|
||||
@@ -579,25 +579,15 @@ export function buildFormCreateCommand(): Command {
|
||||
// buildFormData 100% 注入 formId/renderKey/isSubTable/options
|
||||
await initBuildFormData()
|
||||
const aiModelListForBfd = data.aiModelList || []
|
||||
// wire up relationForm 自动注入 (AI 不会生成关联字段, dacli 启发式补救)
|
||||
// v0.22+ (2026-07-25 BS-新131~133, tdd3 P1-5 闭环): SSW /build-form 路径下 autoDetect 跳过
|
||||
// 原因: SSW prompt 显式禁用 select 替代 relationForm (含 _id 后缀字段), jnpfKey 已正确
|
||||
// autoDetect 是 NCPF 时代 band-aid (AI 用 select 替代 relationForm), 现在不需要
|
||||
// 关闭: --no-relation-form-auto
|
||||
if ((opts as any).relationFormAuto !== false) {
|
||||
try {
|
||||
const { autoDetectAndInjectRelationForm } = await import('./_relationForm_auto.ts')
|
||||
// cast: aiModelListForBfd 含 billRule/unique 等 extra fields, 函数签名只关心 4 项
|
||||
const injected = await autoDetectAndInjectRelationForm(
|
||||
aiModelListForBfd as unknown as Parameters<typeof autoDetectAndInjectRelationForm>[0],
|
||||
)
|
||||
if (injected > 0) {
|
||||
log.info(` ↳ relationForm 自动注入 (BS-新117 R17): ${injected} 个字段`)
|
||||
}
|
||||
} catch (e) {
|
||||
// v2.3+ L3: 落 suggest, AI 自检 fail 模式
|
||||
log.warn(`relationForm 自动注入跳过 (${(e as Error).message?.slice(0, 80)})`)
|
||||
ctx.addSuggestion(remindRelationFormAutoSkip((e as Error).message?.slice(0, 80) || 'unknown'))
|
||||
}
|
||||
} else {
|
||||
if ((opts as any).relationFormAuto === false) {
|
||||
log.info(` ↳ --no-relation-form-auto, 跳过 relationForm 自动注入`)
|
||||
} else {
|
||||
// 默认: SSW 路径下不再 autoDetect (P1-5 闭环), 仅 --table 路径才需要 (因为 --table 不走 LLM, 字段需手注)
|
||||
log.dim(` ↳ SSW 路径下 autoDetect 跳过 (P1-5 闭环, NCPF 时代 band-aid 已废)`)
|
||||
}
|
||||
|
||||
// v2.0+ auto_fix pipeline: 在 buildFormData 前修正字段
|
||||
|
||||
Reference in new issue
Block a user