fix(assistant): improve trip proposals and approvals

This commit is contained in:
Maurice
2026-12-02 22:03:28 +01:00
parent 01ad13623c
commit 62a3e63f3f
144 changed files with 4093 additions and 1336 deletions
@@ -118,6 +118,20 @@ const ERRORS: Record<AssistantErrorCode, AssistantErrorView> = {
/** The limits a provider sets; the line names the provider instead of guessing at its plan. */
const PROVIDER_LIMITS: ReadonlySet<AssistantErrorCode> = new Set(['rate_limited', 'usage_limit']);
/** A route produced for the latest question can still be inspected after an interrupted answer. */
export function hasCurrentTourProposal(messages: readonly AssistantMessage[]): boolean {
for (let index = messages.length - 1; index >= 0; index--) {
const message = messages[index];
if (!message || message.role === 'user') break;
const hasRoute = message.parts.some((part) => {
const card = part.type === 'data-trek-card' ? part.data.card : null;
return card?.kind === 'tourRoute' && card.source === 'proposal' && card.routed;
});
if (hasRoute) return true;
}
return false;
}
/**
* The line an error shows and its one action. The daily limit only offers
* connecting an own provider where the policy allows one. A provider's limit
@@ -126,10 +140,13 @@ const PROVIDER_LIMITS: ReadonlySet<AssistantErrorCode> = new Set(['rate_limited'
*/
export function errorView(
code: AssistantErrorCode,
opts: { canConnectOwn: boolean; provider?: string }
opts: { canConnectOwn: boolean; provider?: string; hasTourProposal?: boolean }
): AssistantErrorView {
const view = ERRORS[code];
if (code === 'daily_limit' && !opts.canConnectOwn) return { ...view, action: null };
if (code === 'rate_limited' && opts.provider && opts.hasTourProposal) {
return { ...view, messageKey: 'assistant.error.providerLimitAfterRoute' };
}
if (PROVIDER_LIMITS.has(code) && opts.provider) return { ...view, messageKey: 'assistant.error.providerLimit' };
return view;
}