Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(assistant): one tap plans the tour for real, and a clear request gets a proposal

Mauriced6b624e400b3
diff --git a/client/src/components/Assistant/assistantFollowUpRules.test.ts b/client/src/components/Assistant/assistantFollowUpRules.test.ts
index bf0b7ae92..16c8d584c 100644
--- a/client/src/components/Assistant/assistantFollowUpRules.test.ts
+++ b/client/src/components/Assistant/assistantFollowUpRules.test.ts
@@ -111,6 +111,14 @@ describe('the questions an answer offers', () => {
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([]);
+ // Not the found places' chips either, but the model's own answers to its question.
+ const asked = of([
+ { type: 'data-trek-places', data: { toolCallId: 's', places: [], more: 0 } },
+ { type: 'text', text: 'Shall I plan it there?' },
+ ]);
+ expect(followUpsFor(asked, true)).toEqual([]);
+ const offered = of([...asked.parts, { type: 'data-trek-follow-ups', data: { questions: ['Yes, plan it'] } }]);
+ expect(followUpsFor(offered, true).map((f) => f.text)).toEqual(['Yes, plan it']);
expect(followUpsFor(of([{ type: 'text', text: 'Here it is.' }]), true).map((f) => f.id)).toEqual(['more', 'next']);
});
});
diff --git a/client/src/components/Assistant/assistantFollowUpRules.ts b/client/src/components/Assistant/assistantFollowUpRules.ts
index 9a7940572..c2f9de2bf 100644
--- a/client/src/components/Assistant/assistantFollowUpRules.ts
+++ b/client/src/components/Assistant/assistantFollowUpRules.ts
@@ -126,11 +126,12 @@ export function followUpsFor(message: AssistantMessage, canEdit: boolean): reado
if (fromModel.length > 0) return fromModel;
const fromCards = cardFollowUps(message, canEdit);
if (fromCards.length > 0) return fromCards;
+ // An answer that asks the user something waits for their answer: only the model's own offer fits it.
+ if (endsWithQuestion(message)) return [];
const fromChanges = changeFollowUps(message, canEdit);
if (fromChanges !== null) return fromChanges.length > 0 ? fromChanges : GENERAL;
const types = new Set(message.parts.map((part) => part.type));
if (types.has('data-trek-places')) return PLACES;
if (types.has('data-trek-weather')) return WEATHER;
- // An answer that asks the user something waits for their answer, not for "tell me more".
- return types.has('text') && !endsWithQuestion(message) ? GENERAL : [];
+ return types.has('text') ? GENERAL : [];
}
diff --git a/client/src/components/Assistant/cards/tour/TourRouteCard.test.tsx b/client/src/components/Assistant/cards/tour/TourRouteCard.test.tsx
index 644b31146..4c326ac59 100644
--- a/client/src/components/Assistant/cards/tour/TourRouteCard.test.tsx
+++ b/client/src/components/Assistant/cards/tour/TourRouteCard.test.tsx
@@ -234,18 +234,21 @@ describe('TourRouteCard', () => {
const decide = vi.fn(async (_key: number, decisions: { toolCallId: string; approved: boolean }[]) => {
// The server applies the take; the thread shows it applied with the new tour's place.
const chat = chatOf(useAssistantStore.getState(), TRIP);
- const applied = heldTake(true);
- applied.parts.push({
+ // The server sends the answer back with the take joined to it, now applied with the new tour's place.
+ const applied = proposed();
+ applied.parts.push(...heldTake(true).parts, {
type: 'data-trek-applied',
data: { toolCallId: decisions[0]?.toolCallId ?? '', entity: 'tour', ids: [77], dayId: 22, undoUntil: null },
});
- useAssistantStore.setState({ byTrip: { [TRIP]: { ...chat, messages: [proposed(), applied] } } });
+ useAssistantStore.setState({ byTrip: { [TRIP]: { ...chat, messages: [applied] } } });
});
seed([proposed()]);
useAssistantStore.setState({ decide });
takeProposal.mockImplementationOnce(async () => {
const chat = chatOf(useAssistantStore.getState(), TRIP);
- useAssistantStore.setState({ byTrip: { [TRIP]: { ...chat, messages: [proposed(), heldTake(undefined)] } } });
+ const joined = proposed();
+ joined.parts.push(...heldTake(undefined).parts);
+ useAssistantStore.setState({ byTrip: { [TRIP]: { ...chat, messages: [joined] } } });
return 'held';
});
renderCard(HIKE, { onOpen });
diff --git a/client/src/components/Assistant/cards/tour/tourTakeModel.test.ts b/client/src/components/Assistant/cards/tour/tourTakeModel.test.ts
index 719cfb6ee..1b2b53029 100644
--- a/client/src/components/Assistant/cards/tour/tourTakeModel.test.ts
+++ b/client/src/components/Assistant/cards/tour/tourTakeModel.test.ts
@@ -67,6 +67,9 @@ describe('takeInThread', () => {
it('FE-AI-TOUR-048: a take that names its proposal is matched by it, not by its way', () => {
const other = { ...GENTLE, line: [[47.9, 12.8, 600], ...GENTLE.line.slice(1)] } satisfies TourRouteCard;
expect(takeInThread([proposal, take(other, {}, 'take_proposal', 'call_1')], 'call_1', HIKE)).toBe('waiting');
+ // The server joins a take to the answer that drew the proposal: found there too.
+ const joined = { ...proposal, parts: [...proposal.parts, ...take(other, {}, 'take_proposal', 'call_1').parts] };
+ expect(takeInThread([joined], 'call_1', HIKE)).toBe('waiting');
// The same way taken from another proposal leaves this one free.
expect(
takeInThread([proposal, take(HIKE, { approved: true }, 'take_proposal', 'call_2')], 'call_1', HIKE)
diff --git a/client/src/components/Assistant/cards/tour/tourTakeModel.ts b/client/src/components/Assistant/cards/tour/tourTakeModel.ts
index d970acb91..b22ae3cbd 100644
--- a/client/src/components/Assistant/cards/tour/tourTakeModel.ts
+++ b/client/src/components/Assistant/cards/tour/tourTakeModel.ts
@@ -45,7 +45,8 @@ export function takeOfProposal(
): { id: string; state: 'waiting' | 'applied'; placeId: number | null } | null {
const from = proposalIndex(messages, toolCallId);
if (from < 0) return null;
- for (const message of messages.slice(from + 1)) {
+ // The server joins a take to the answer that drew its proposal, so that answer is searched as well as the later ones.
+ for (const message of messages.slice(from)) {
const open = new Map<string, 'waiting' | 'applied'>();
for (const part of message.parts) {
if (part.type !== 'tool-call' || part.toolName !== TAKE_TOOL || part.approval?.resolution) continue;
diff --git a/server/src/nest/assistant/assistant.prompt.ts b/server/src/nest/assistant/assistant.prompt.ts
index 77aaf0c3f..399b244e1 100644
--- a/server/src/nest/assistant/assistant.prompt.ts
+++ b/server/src/nest/assistant/assistant.prompt.ts
@@ -34,7 +34,7 @@ How you work:
- Expenses and their ids come from list_budget_items. Change an existing one with update_budget_item; never add a second entry to correct one. For what each person's share comes to, use get_budget_per_person; for who pays whom, get_settlement_summary.
- For the wind on a day (a paddle, a sail, a ridge walk), use get_wind_forecast: it has the gusts and the direction hour by hour.
- End every answer with one suggest_follow_ups call, alone in its step after your text: up to three short messages the user would plausibly send next, about what you just discussed (a hike you planned: an easier variant, what to pack; never the day plan when the answer was not about it). When you asked the user a question, offer its likely answers instead ("Yes, plan it anyway", "Rather in the Harz"). Skip it only while changes wait for the user's decision.
-- If the request is unclear, ask one short question instead of guessing.`;
+- If the request is unclear, ask one short question instead of guessing. A request that names what and roughly where is clear: propose it at once (a proposal saves nothing) and say in a sentence what you assumed, rather than asking whether you may.`;
/** The instructions with the packages' lines about their cards, built once so the provider's cache holds. */
const STANDING = INSTRUCTIONS + CARD_PROMPT_LINES.map((line) => `\n- ${line}`).join('');
diff --git a/server/src/nest/assistant/cards/tour/index.ts b/server/src/nest/assistant/cards/tour/index.ts
index e3e5f1bd1..59ce02f34 100644
--- a/server/src/nest/assistant/cards/tour/index.ts
+++ b/server/src/nest/assistant/cards/tour/index.ts
@@ -85,7 +85,7 @@ export const TOUR_CARDS: DomainCards = {
},
},
prompt: [
- 'Hikes: call propose_hike with a name, and day_id and start_time when known; to compare ways, call it up to three times in one step, each with a variant_label and along false. Call create_hike only once the user chose a way.',
+ 'Hikes: call propose_hike with a name, and day_id and start_time when known; to compare ways, call it up to three times in one step, each with a variant_label and along false, the way you recommend first (the card shows the first one chosen). Call create_hike only once the user chose a way.',
'The app draws a proposed, planned or saved tour (route, profile, stops, times, weather, warnings) and lists of tours as cards: do not repeat their figures or list them again, say in one sentence what matters.',
],
};