okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
1.4 KiB32 linesraw
1import { tr } from './i18n';
2import { sendOversized, startNewChat, summarizeAndContinue } from './store';
3
4/**
5 * What the error card of a chat offers when the model's window is the problem. A conversation that no longer fits can be summarised and
6 * carried on, or left for a new chat; a single message that is too large can go as a file the assistant reads in parts, or as a shortened
7 * preview. "Try the message again" would only fail the same way, so the card never says it for these.
8 */
9export function contextRecovery(code: string | undefined): {
10  next: string;
11  action?: string;
12  onRetry?: () => void;
13  secondary?: { label: string; onClick: () => void };
14} {
15  if (code === 'CONTEXT_MESSAGE_TOO_LARGE') {
16    return {
17      next: tr('Attach it as a file for the assistant to read in parts, or send a shortened preview.'),
18      action: 'Attach as a file',
19      onRetry: () => void sendOversized('file'),
20      secondary: { label: 'Send a shortened preview', onClick: () => void sendOversized('preview') },
21    };
22  }
23  if (code === 'CONTEXT_WINDOW_EXCEEDED') {
24    return {
25      next: tr('Summarize it now and continue, or start a new chat.'),
26      action: 'Summarize and continue',
27      onRetry: () => void summarizeAndContinue(),
28      secondary: { label: 'Start a new chat', onClick: () => startNewChat() },
29    };
30  }
31  return { next: tr('Try sending the message again.') };
32}