fix(agent): reconcile agent stream mode and shared-agent readiness UX
Derive stream pipeline from selectedAgentId to fix quick-answer/isAgentEnabled drift, gate configure actions for shared agents, and polish selector detail panel positioning.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
const BUILTIN_QUICK_ANSWER_ID = 'builtin-quick-answer'
|
||||
const BUILTIN_SMART_REASONING_ID = 'builtin-smart-reasoning'
|
||||
|
||||
function isQuickAnswerAgentId(agentId) {
|
||||
return (agentId || BUILTIN_QUICK_ANSWER_ID) === BUILTIN_QUICK_ANSWER_ID
|
||||
}
|
||||
|
||||
function isAgentStreamAgentId(agentId, isAgentEnabled) {
|
||||
const id = agentId || BUILTIN_QUICK_ANSWER_ID
|
||||
if (id === BUILTIN_QUICK_ANSWER_ID) return false
|
||||
if (id === BUILTIN_SMART_REASONING_ID) return true
|
||||
return isAgentEnabled
|
||||
}
|
||||
|
||||
function reconcileBuiltinAgentMode(settings) {
|
||||
const agentId = settings.selectedAgentId || BUILTIN_QUICK_ANSWER_ID
|
||||
if (agentId === BUILTIN_QUICK_ANSWER_ID && settings.isAgentEnabled) {
|
||||
settings.isAgentEnabled = false
|
||||
return true
|
||||
}
|
||||
if (agentId === BUILTIN_SMART_REASONING_ID && !settings.isAgentEnabled) {
|
||||
settings.isAgentEnabled = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
test('isQuickAnswerAgentId treats builtin quick-answer as RAG mode', () => {
|
||||
assert.equal(isQuickAnswerAgentId('builtin-quick-answer'), true)
|
||||
assert.equal(isQuickAnswerAgentId(undefined), true)
|
||||
assert.equal(isQuickAnswerAgentId('builtin-smart-reasoning'), false)
|
||||
})
|
||||
|
||||
test('isAgentStreamAgentId prefers selectedAgentId for builtins', () => {
|
||||
assert.equal(
|
||||
isAgentStreamAgentId('builtin-quick-answer', true),
|
||||
false,
|
||||
'stale isAgentEnabled must not flip quick-answer into agent stream',
|
||||
)
|
||||
assert.equal(isAgentStreamAgentId('builtin-smart-reasoning', false), true)
|
||||
assert.equal(isAgentStreamAgentId('custom-agent', true), true)
|
||||
assert.equal(isAgentStreamAgentId('custom-agent', false), false)
|
||||
})
|
||||
|
||||
test('reconcileBuiltinAgentMode repairs drifted localStorage flags', () => {
|
||||
const quick = { selectedAgentId: 'builtin-quick-answer', isAgentEnabled: true }
|
||||
assert.equal(reconcileBuiltinAgentMode(quick), true)
|
||||
assert.equal(quick.isAgentEnabled, false)
|
||||
|
||||
const reasoning = { selectedAgentId: 'builtin-smart-reasoning', isAgentEnabled: false }
|
||||
assert.equal(reconcileBuiltinAgentMode(reasoning), true)
|
||||
assert.equal(reasoning.isAgentEnabled, true)
|
||||
|
||||
const custom = { selectedAgentId: 'custom-agent', isAgentEnabled: true }
|
||||
assert.equal(reconcileBuiltinAgentMode(custom), false)
|
||||
})
|
||||
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
BUILTIN_QUICK_ANSWER_ID,
|
||||
BUILTIN_SMART_REASONING_ID,
|
||||
} from '@/api/agent'
|
||||
|
||||
/** Whether the selected agent id is the builtin quick-answer (RAG) mode. */
|
||||
export function isQuickAnswerAgentId(agentId: string | null | undefined): boolean {
|
||||
return (agentId || BUILTIN_QUICK_ANSWER_ID) === BUILTIN_QUICK_ANSWER_ID
|
||||
}
|
||||
|
||||
/** Whether requests should use the Agent stream pipeline (not quick-answer RAG). */
|
||||
export function isAgentStreamAgentId(
|
||||
agentId: string | null | undefined,
|
||||
isAgentEnabled: boolean,
|
||||
): boolean {
|
||||
const id = agentId || BUILTIN_QUICK_ANSWER_ID
|
||||
if (id === BUILTIN_QUICK_ANSWER_ID) return false
|
||||
if (id === BUILTIN_SMART_REASONING_ID) return true
|
||||
return isAgentEnabled
|
||||
}
|
||||
|
||||
/** Reconcile builtin agent id with isAgentEnabled after localStorage reload. */
|
||||
export function reconcileBuiltinAgentMode(settings: {
|
||||
selectedAgentId?: string
|
||||
isAgentEnabled: boolean
|
||||
}): boolean {
|
||||
const agentId = settings.selectedAgentId || BUILTIN_QUICK_ANSWER_ID
|
||||
if (agentId === BUILTIN_QUICK_ANSWER_ID && settings.isAgentEnabled) {
|
||||
settings.isAgentEnabled = false
|
||||
return true
|
||||
}
|
||||
if (agentId === BUILTIN_SMART_REASONING_ID && !settings.isAgentEnabled) {
|
||||
settings.isAgentEnabled = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import test from 'node:test'
|
||||
import {
|
||||
agentHasConfiguredChatModel,
|
||||
agentRequiresRerankModel,
|
||||
canLocallyConfigureAgent,
|
||||
getAgentNotReadyReasonKeys,
|
||||
resolveAgentNotReadySection,
|
||||
resolveAgentNotReadyHighlight,
|
||||
@@ -100,3 +101,22 @@ test('getAgentNotReadyReasonKeys does not treat current shared context as shared
|
||||
{ isAgentMode: false, isSharedAgent: false },
|
||||
), ['summary_model'])
|
||||
})
|
||||
|
||||
test('getAgentNotReadyReasonKeys treats empty allowed_tools as ready via backend defaults', () => {
|
||||
assert.deepEqual(getAgentNotReadyReasonKeys(
|
||||
{
|
||||
model_id: 'chat-1',
|
||||
rerank_model_id: 'rerank-1',
|
||||
kb_selection_mode: 'all',
|
||||
allowed_tools: [],
|
||||
},
|
||||
[{ id: 'chat-1', type: 'KnowledgeQA' }, { id: 'rerank-1', type: 'Rerank' }],
|
||||
{ isAgentMode: true, isSharedAgent: false },
|
||||
), [])
|
||||
})
|
||||
|
||||
test('canLocallyConfigureAgent is false for shared agents', () => {
|
||||
assert.equal(canLocallyConfigureAgent('42'), false)
|
||||
assert.equal(canLocallyConfigureAgent(undefined), true)
|
||||
assert.equal(canLocallyConfigureAgent(''), true)
|
||||
})
|
||||
|
||||
@@ -67,13 +67,14 @@ export function getAgentNotReadyReasonKeys(
|
||||
}
|
||||
}
|
||||
|
||||
if (options.isAgentMode && (!config?.allowed_tools || config.allowed_tools.length === 0)) {
|
||||
reasons.push('allowed_tools')
|
||||
}
|
||||
|
||||
return reasons
|
||||
}
|
||||
|
||||
/** Shared agents are owned by another tenant; receivers cannot edit their config. */
|
||||
export function canLocallyConfigureAgent(sourceTenantId?: string): boolean {
|
||||
return !sourceTenantId
|
||||
}
|
||||
|
||||
/** Map missing-config reasons to the agent editor section that fixes them. */
|
||||
export function resolveAgentNotReadySection(reasons: AgentNotReadyReasonKey[]): string {
|
||||
if (reasons.includes('summary_model') || reasons.includes('rerank_model')) {
|
||||
|
||||
Reference in New Issue
Block a user