feat(web): AI 意图规划置信度阈值与动作策略细化
- workbenchAiIntentPlannerModel 新增 WORKBENCH_AI_INTENT_CONFIDENCE_THRESHOLD 与 isLowConfidenceTravelApplicationPlan,shouldRequestWorkbenchAiIntentPlan 增加业务关键词前置过滤 - resolveExecutableTravelApplicationPlan 区分 requestedSubmit 与提交确认(submitRequiresConfirmation),autoSubmit 不再直接置真 - workbenchIntentActionPolicy 改用 policyDecision 路由(need_confirmation/query_candidates),透传 riskLevel/requiresSelection/requiresConfirmation - workbenchIntentFrameModel 补充 query 动作识别,usePersonalWorkbenchAiMode/useWorkbenchAiActionRouter/useWorkbenchAiApplicationPreviewFlow 接入低置信度与确认流程 - 更新 intent-planner-model/intent-frame-model/application-gate-model/fast-preview 测试
This commit is contained in:
@@ -12,11 +12,13 @@ import {
|
||||
WORKBENCH_AI_STEP_SUBMIT_APPLICATION,
|
||||
WORKBENCH_AI_STEP_VALIDATE_REQUIRED_FIELDS,
|
||||
buildRuleFallbackWorkbenchAiIntentPlan,
|
||||
isLowConfidenceTravelApplicationPlan,
|
||||
normalizeWorkbenchAiIntentPlan,
|
||||
resolveExecutableTravelApplicationPlan,
|
||||
shouldRequestWorkbenchAiIntentPlan
|
||||
} from '../src/composables/workbenchAiMode/workbenchAiIntentPlannerModel.js'
|
||||
import { buildInlineApplicationPreview } from '../src/composables/workbenchAiMode/workbenchAiApplicationPreviewModel.js'
|
||||
import { createWorkbenchAiMessageRuntime } from '../src/composables/workbenchAiMode/workbenchAiMessageModel.js'
|
||||
|
||||
const personalWorkbenchAiModeScript = readFileSync(
|
||||
fileURLToPath(new URL('../src/composables/workbenchAiMode/usePersonalWorkbenchAiMode.js', import.meta.url)),
|
||||
@@ -144,7 +146,9 @@ test('workbench AI intent planner detects compact travel save-draft variant befo
|
||||
sourceText: prompt,
|
||||
ontologyFields: {},
|
||||
autoSubmit: false,
|
||||
autoSaveDraft: true
|
||||
autoSaveDraft: true,
|
||||
requestedSubmit: false,
|
||||
submitRequiresConfirmation: false
|
||||
})
|
||||
})
|
||||
|
||||
@@ -178,7 +182,9 @@ test('workbench AI intent planner turns model fields and action into executable
|
||||
transport_mode: '火车'
|
||||
},
|
||||
autoSubmit: false,
|
||||
autoSaveDraft: true
|
||||
autoSaveDraft: true,
|
||||
requestedSubmit: false,
|
||||
submitRequiresConfirmation: false
|
||||
})
|
||||
})
|
||||
|
||||
@@ -220,7 +226,9 @@ test('workbench AI intent planner turns single application candidate flow into e
|
||||
transport_mode: '火车'
|
||||
},
|
||||
autoSubmit: false,
|
||||
autoSaveDraft: false
|
||||
autoSaveDraft: false,
|
||||
requestedSubmit: false,
|
||||
submitRequiresConfirmation: false
|
||||
})
|
||||
})
|
||||
|
||||
@@ -245,7 +253,7 @@ test('workbench AI application preview prefers model ontology fields over local
|
||||
assert.equal(preview.fields.transportMode, '火车')
|
||||
})
|
||||
|
||||
test('workbench AI intent planner rejects policy question and resolves executable application request', () => {
|
||||
test('workbench AI intent planner rejects policy question and requires confirmation for direct-submit request', () => {
|
||||
assert.equal(buildRuleFallbackWorkbenchAiIntentPlan('帮我查询上海差旅标准'), null)
|
||||
|
||||
const request = resolveExecutableTravelApplicationPlan(
|
||||
@@ -257,11 +265,30 @@ test('workbench AI intent planner rejects policy question and resolves executabl
|
||||
expenseTypeLabel: '差旅费',
|
||||
sourceText: '去上海出差,辅助国网仿生产服务器部署,交通火车,直接提交',
|
||||
ontologyFields: {},
|
||||
autoSubmit: true,
|
||||
autoSaveDraft: false
|
||||
autoSubmit: false,
|
||||
autoSaveDraft: false,
|
||||
requestedSubmit: true,
|
||||
submitRequiresConfirmation: true
|
||||
})
|
||||
})
|
||||
|
||||
test('workbench AI message runtime persists direct-submit confirmation metadata', () => {
|
||||
const { createInlineMessage, normalizeRuntimeMessage, serializeRuntimeMessage } = createWorkbenchAiMessageRuntime()
|
||||
const message = createInlineMessage('assistant', '申请核对表', {
|
||||
applicationPreview: { fields: { location: '上海' } },
|
||||
requestedSubmit: true,
|
||||
submitRequiresConfirmation: true
|
||||
})
|
||||
|
||||
const serialized = serializeRuntimeMessage(message)
|
||||
assert.equal(serialized.requestedSubmit, true)
|
||||
assert.equal(serialized.submitRequiresConfirmation, true)
|
||||
|
||||
const normalized = normalizeRuntimeMessage(serialized)
|
||||
assert.equal(normalized.requestedSubmit, true)
|
||||
assert.equal(normalized.submitRequiresConfirmation, true)
|
||||
})
|
||||
|
||||
test('workbench AI mode asks steward model plan before fallback execution', () => {
|
||||
assert.match(stewardFlowScript, /async function resolveInlineExecutionPlan\(prompt, entry = \{\}, files = \[\], options = \{\}\)/)
|
||||
assert.match(stewardFlowScript, /fetchStewardPlan\(planRequest/)
|
||||
@@ -274,8 +301,11 @@ test('workbench AI mode asks steward model plan before fallback execution', () =
|
||||
assert.match(personalWorkbenchAiModeScript, /resolveExecutableTravelApplicationPlan\(intentPlan\)/)
|
||||
assert.doesNotMatch(personalWorkbenchAiModeScript, /fallbackIntentPlan/)
|
||||
assert.match(personalWorkbenchAiModeScript, /autoSaveDraft:\s*travelApplicationRequest\.autoSaveDraft/)
|
||||
assert.match(personalWorkbenchAiModeScript, /requestedSubmit:\s*travelApplicationRequest\.requestedSubmit/)
|
||||
assert.match(personalWorkbenchAiModeScript, /submitRequiresConfirmation:\s*travelApplicationRequest\.submitRequiresConfirmation/)
|
||||
assert.match(personalWorkbenchAiModeScript, /ontologyFields:\s*travelApplicationRequest\.ontologyFields/)
|
||||
assert.match(applicationPreviewFlowScript, /options\.autoSaveDraft/)
|
||||
assert.doesNotMatch(applicationPreviewFlowScript, /options\.autoSubmit && normalizeApplicationPreview\(preview\)\.readyToSubmit/)
|
||||
assert.match(applicationPreviewFlowScript, /ontologyFields:\s*options\.ontologyFields/)
|
||||
assert.match(applicationPreviewFlowScript, /executeInlineApplicationPreviewAction\(AI_APPLICATION_ACTION_SAVE_DRAFT/)
|
||||
assert.match(applicationPreviewFlowScript, /buildInlineApplicationPreview\([\s\S]*ontologyFields:\s*options\.ontologyFields/)
|
||||
@@ -329,3 +359,72 @@ test('workbench AI mode reuses planning pending message for regular steward repl
|
||||
assert.match(stewardFlowScript, /const reusablePendingMessageId = String\(options\.pendingMessageId \|\| ''\)\.trim\(\)/)
|
||||
assert.match(stewardFlowScript, /reusablePendingMessageId \? replaceInlineMessage\(reusablePendingMessageId, pendingMessage\) : conversationMessages\.value\.push\(pendingMessage\)/)
|
||||
})
|
||||
|
||||
test('isLowConfidenceTravelApplicationPlan gates preview behind confirmation when model confidence is low', () => {
|
||||
const lowConfidenceModelPlan = normalizeWorkbenchAiIntentPlan({
|
||||
planning_source: 'llm_function_call',
|
||||
tasks: [{
|
||||
task_type: 'expense_application',
|
||||
assigned_agent: 'application_assistant',
|
||||
requested_action: 'preview',
|
||||
confidence: 0.4,
|
||||
ontology_fields: { location: '上海', reason: '部署' }
|
||||
}]
|
||||
}, { prompt: '上海那边好像要过去一趟搞部署' })
|
||||
|
||||
assert.equal(lowConfidenceModelPlan.source, WORKBENCH_AI_INTENT_SOURCE_MODEL)
|
||||
assert.equal(isLowConfidenceTravelApplicationPlan(lowConfidenceModelPlan), true)
|
||||
|
||||
const highConfidenceModelPlan = normalizeWorkbenchAiIntentPlan({
|
||||
planning_source: 'llm_function_call',
|
||||
tasks: [{
|
||||
task_type: 'expense_application',
|
||||
assigned_agent: 'application_assistant',
|
||||
requested_action: 'preview',
|
||||
confidence: 0.9,
|
||||
ontology_fields: { location: '上海' }
|
||||
}]
|
||||
}, { prompt: '去上海出差' })
|
||||
|
||||
assert.equal(isLowConfidenceTravelApplicationPlan(highConfidenceModelPlan), false)
|
||||
|
||||
const ruleFallbackPlan = buildRuleFallbackWorkbenchAiIntentPlan('去上海出差,辅助部署,交通火车')
|
||||
assert.equal(ruleFallbackPlan.source, WORKBENCH_AI_INTENT_SOURCE_RULE_FALLBACK)
|
||||
assert.equal(isLowConfidenceTravelApplicationPlan(ruleFallbackPlan), false)
|
||||
|
||||
const explicitSubmitLowConfidence = normalizeWorkbenchAiIntentPlan({
|
||||
planning_source: 'llm_function_call',
|
||||
tasks: [{
|
||||
task_type: 'expense_application',
|
||||
assigned_agent: 'application_assistant',
|
||||
requested_action: 'submit',
|
||||
confidence: 0.3,
|
||||
ontology_fields: { location: '上海' }
|
||||
}]
|
||||
}, { prompt: '直接提交' })
|
||||
|
||||
assert.equal(explicitSubmitLowConfidence.requestedAction, 'submit')
|
||||
assert.equal(isLowConfidenceTravelApplicationPlan(explicitSubmitLowConfidence), false)
|
||||
|
||||
assert.equal(isLowConfidenceTravelApplicationPlan(null), false)
|
||||
})
|
||||
|
||||
test('workbench AI mode routes low confidence travel application plan to confirmation prompt', () => {
|
||||
assert.match(personalWorkbenchAiModeScript, /isLowConfidenceTravelApplicationPlan\(intentPlan\)/)
|
||||
assert.match(personalWorkbenchAiModeScript, /function startModelPlannedTravelApplicationConfirmation\(/)
|
||||
assert.match(personalWorkbenchAiModeScript, /action_type:\s*'ai_application_confirm_intent'/)
|
||||
assert.match(personalWorkbenchAiModeScript, /需要确认:您是要发起出差申请吗/)
|
||||
})
|
||||
|
||||
test('shouldRequestWorkbenchAiIntentPlan skips chitchat and only triggers on business keywords', () => {
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('你好'), false)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('谢谢'), false)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('嗯'), false)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('ok'), false)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('1'), false)
|
||||
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('帮我查报销'), true)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('我要出差'), true)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('帮我查询上海差旅标准'), true)
|
||||
assert.equal(shouldRequestWorkbenchAiIntentPlan('删除3天前的草稿'), true)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user