feat(assistant): the model offers the follow-up questions that fit the conversation

A turn may end on suggest_follow_ups: the server answers the call itself, keeps
its questions as data-trek-follow-ups and the chat shows them as chips under
the answer. Without them the chips fall back to what the answer holds, now by
the kind of change: a tour asks about the tour, the day plan's questions only
follow a change to the day plan, and an answer that asks the user something
offers no "tell me more".
This commit is contained in:
Maurice
2026-10-23 13:10:55 +02:00
parent 199a6f03a7
commit d6b15efa63
13 changed files with 330 additions and 21 deletions
@@ -1,12 +1,15 @@
/**
* FE-AI-FOLLOW-001 to FE-AI-FOLLOW-003
* FE-AI-FOLLOW-001 to FE-AI-FOLLOW-007
*
* The follow-ups a card offers under an answer that ends on it: the ones that
* ask for a change only for someone who may make it, the answer's own when
* none is left for a reader, and the ones with a condition only when a card of
* the answer meets it.
* the answer meets it. The questions the model offered win over all of them; a
* change asks what its own kind offers, the day plan's questions come only
* after a change to the day plan, and an answer that asks the user something
* offers no "tell me more".
*/
import type { AssistantMessage, TrekCard } from '@trek/shared';
import type { AssistantChangePreview, AssistantMessage, TrekCard } from '@trek/shared';
import { afterEach, describe, expect, it } from 'vitest';
import { followUpsFor } from './assistantFollowUpRules';
@@ -60,3 +63,54 @@ describe('card follow-ups', () => {
expect(asked).toEqual([{ kind: 'vacay' }]);
});
});
/** An answer of the given parts. */
const of = (parts: AssistantMessage['parts']): AssistantMessage => ({ ...answer, parts });
/** A proposed change, with the card of what it does. */
const change = (card?: TrekCard): AssistantChangePreview => ({
toolCallId: 'c1',
verbKey: 'addPlace',
subject: 'Something',
rows: [],
dayId: null,
placeIds: [],
undoable: true,
...(card ? { card } : {}),
});
describe('the questions an answer offers', () => {
it('FE-AI-FOLLOW-004: the questions the model offered win, sent as written, the last offer only', () => {
const offered = of([
{ type: 'text', text: 'Done.' },
{ type: 'data-trek-follow-ups', data: { questions: ['Old'] } },
{ type: 'data-trek-follow-ups', data: { questions: ['An easier variant', 'What to pack?'] } },
]);
expect(followUpsFor(offered, true).map((f) => f.text)).toEqual(['An easier variant', 'What to pack?']);
});
it('FE-AI-FOLLOW-005: a proposed tour asks about the tour, never to plan the next day the same way', () => {
const tour = { kind: 'tourRoute', source: 'proposal', activity: 'hike' } as TrekCard;
const ids = followUpsFor(of([{ type: 'data-trek-change', data: change(tour) }]), true).map((f) => f.id);
expect(ids).toContain('tourEasier');
expect(ids).not.toContain('nextDay');
});
it('FE-AI-FOLLOW-006: an applied expense offers the general questions, an applied stop the day plan', () => {
const applied = (entity: 'budget' | 'assignment') =>
of([
{ type: 'text', text: 'Added.' },
{
type: 'data-trek-applied',
data: { toolCallId: 'c1', entity, ids: [1], dayId: null, undoUntil: null },
},
]);
expect(followUpsFor(applied('budget'), true).map((f) => f.id)).toEqual(['more', 'next']);
expect(followUpsFor(applied('assignment'), true).map((f) => f.id)).toContain('nextDay');
});
it('FE-AI-FOLLOW-007: an answer that asks the user something waits for their answer, not for "tell me more"', () => {
expect(followUpsFor(of([{ type: 'text', text: 'Should I plan it anyway?' }]), true)).toEqual([]);
expect(followUpsFor(of([{ type: 'text', text: 'Here it is.' }]), true).map((f) => f.id)).toEqual(['more', 'next']);
});
});