mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 01:28:55 +00:00
fix(assistant): improve trip proposals and approvals
This commit is contained in:
@@ -19,6 +19,15 @@ export interface RouteCardEntry {
|
||||
card: TrekCard;
|
||||
}
|
||||
|
||||
/** Use the first calculated route unless the user chose a particular way. */
|
||||
export function preferredRouteEntry<T extends RouteCardEntry>(entries: readonly T[], picked?: string): T | undefined {
|
||||
return (
|
||||
entries.find((entry) => entry.toolCallId === picked) ??
|
||||
entries.find(({ card }) => card.kind === 'tourRoute' && card.routed) ??
|
||||
entries[0]
|
||||
);
|
||||
}
|
||||
|
||||
/** The letters the ways of one answer go by, in the order the answer gave them. */
|
||||
type RouteWayKey = 'a' | 'b' | 'c';
|
||||
const WAY_KEYS: readonly RouteWayKey[] = ['a', 'b', 'c'];
|
||||
@@ -101,7 +110,7 @@ function standsOnMap(part: ToolCallPart, receipt: AssistantApplied | undefined,
|
||||
/**
|
||||
* The cards of the latest answer that draws any, laid out as the chat lays
|
||||
* them out: a group of several is a choice of ways, each with its letter, the
|
||||
* chosen one (by `picks`, else the first) picked. Older answers drop, and so
|
||||
* chosen one (by `picks`, else the first calculated route) picked. Older answers drop, and so
|
||||
* do the ways of a group once one of them was taken into the trip.
|
||||
*/
|
||||
function lookRefs(
|
||||
@@ -111,7 +120,6 @@ function lookRefs(
|
||||
look: CardMapLook,
|
||||
layout: AnswerLayout
|
||||
): RouteRef[] {
|
||||
const chosenIds = new Set(Object.values(picks));
|
||||
const taken = takenProposals(messages);
|
||||
for (let index = messages.length - 1; index >= 0; index--) {
|
||||
const answers = (messages[index]?.parts ?? []).flatMap((part): RouteCardEntry[] =>
|
||||
@@ -125,7 +133,7 @@ function lookRefs(
|
||||
return layout(answers).flatMap((group) => {
|
||||
if (group.some((entry) => taken.has(entry.toolCallId))) return [];
|
||||
const ways = group.length >= 2;
|
||||
const chosen = group.find((entry) => chosenIds.has(entry.toolCallId)) ?? group[0];
|
||||
const chosen = preferredRouteEntry(group, picks[`tour:${group[0]?.toolCallId ?? ''}`]);
|
||||
return group.flatMap((entry, position): RouteRef[] => {
|
||||
if (!drawn.has(entry.toolCallId)) return [];
|
||||
const way = ways ? (WAY_KEYS[position] ?? null) : null;
|
||||
|
||||
Reference in New Issue
Block a user