Open History to see the last commit
1import { CircleAlertIcon, SettingsIcon } from "lucide-react";
2
3import { Button } from "../ui/button";
4import type { ComposerBannerStackItem } from "./ComposerBannerStack";
5
6interface ContextLimitBannerInput {
7 readonly threadId: string;
8 readonly tokenLimit: number;
9 readonly canChangeTokenLimit: boolean;
10 readonly supportsGeneration: boolean;
11 readonly isGeneratingHandover: boolean;
12 readonly hasSavedHandover: boolean;
13 readonly onChangeTokenLimit: () => void;
14 readonly onGenerateHandover: () => void;
15}
16
17export function buildContextLimitBannerItem({
18 threadId,
19 tokenLimit,
20 canChangeTokenLimit,
21 supportsGeneration,
22 isGeneratingHandover,
23 hasSavedHandover,
24 onChangeTokenLimit,
25 onGenerateHandover,
26}: ContextLimitBannerInput): ComposerBannerStackItem {
27 return {
28 id: `context-limit:${threadId}`,
29 variant: "info",
30 priority: "urgent",
31 icon: <CircleAlertIcon />,
32 title: (
33 <span className="flex min-w-0 items-center gap-1">
34 <span>This thread has reached {tokenLimit.toLocaleString("en-US")} tokens</span>
35 {canChangeTokenLimit ? (
36 <Button
37 size="icon-xs"
38 variant="ghost"
39 aria-label="Change thread token limit"
40 onClick={onChangeTokenLimit}
41 >
42 <SettingsIcon className="size-3.5" />
43 <span className="sr-only">Change thread token limit</span>
44 </Button>
45 ) : null}
46 </span>
47 ),
48 description: hasSavedHandover
49 ? "Your saved handover is ready. Open it in a new draft to review it before choosing the next model and reasoning level."
50 : supportsGeneration
51 ? "T3 will not start another turn here. Create a compact handover, then review it in a new draft before choosing the next model and reasoning level."
52 : "T3 will not start another turn here. Update the connected server to create an automatic handover, or start a new thread manually.",
53 actions:
54 supportsGeneration || hasSavedHandover ? (
55 <Button
56 size="xs"
57 variant="outline"
58 disabled={isGeneratingHandover}
59 onClick={onGenerateHandover}
60 >
61 {isGeneratingHandover
62 ? "Creating handover..."
63 : hasSavedHandover
64 ? "Open saved handover"
65 : "Handover to new thread"}
66 </Button>
67 ) : undefined,
68 };
69}