diff --git a/server/utils/openai.test.ts b/server/utils/openai.test.ts index dcdb545..c400a37 100644 --- a/server/utils/openai.test.ts +++ b/server/utils/openai.test.ts @@ -113,6 +113,7 @@ describe('routeDecision', () => { assert.equal(result.decision.next_state, 'ACK') assert.equal(result.trace?.calls.length ?? 0, 0) assert.equal(result.trace?.autoSelection?.id, 'ACK') + assert.equal(result.pilot_intent ?? null, null) }) it('falls back to heuristic selection when OpenAI call fails', async () => { @@ -131,6 +132,7 @@ describe('routeDecision', () => { assert.ok(result.trace?.calls[0]?.error) assert.equal(result.trace?.fallback?.used, true) assert.equal(result.decision.next_state, 'TAXI') + assert.equal(result.pilot_intent ?? null, null) }) }) diff --git a/server/utils/openai.ts b/server/utils/openai.ts index dc81ec7..0ed51df 100644 --- a/server/utils/openai.ts +++ b/server/utils/openai.ts @@ -914,6 +914,7 @@ export async function routeDecision(input: LLMDecisionInput): Promise 0) { + + if (parsed && typeof parsed === 'object') { callEntry.response = parsed + if (typeof (parsed as any).pilot_intent === 'string') { + const intentValue = ((parsed as any).pilot_intent as string).trim() + if (intentValue) { + pilotIntent = intentValue + } + } + } + + const nextState = + parsed && typeof parsed === 'object' && typeof (parsed as any).next_state === 'string' + ? ((parsed as any).next_state as string).trim() + : '' + + if (nextState.length > 0) { const resolved = - prepared.finalCandidateIndex.get(parsed.next_state) - || prepared.candidateIndex.get(parsed.next_state) + prepared.finalCandidateIndex.get(nextState) + || prepared.candidateIndex.get(nextState) if (resolved) { return { decision: { next_state: resolved.id }, trace, + pilot_intent: pilotIntent, } } return { - decision: { next_state: parsed.next_state }, + decision: { next_state: nextState }, trace, + pilot_intent: pilotIntent, } } @@ -1027,6 +1049,7 @@ export async function routeDecision(input: LLMDecisionInput): Promise