@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 53 lines 1.91 KB
Raw
1 import type { ProviderDriverKind, ProviderInstanceId } from "@t3tools/contracts";
2 import { msg } from "gt-react";
3
4 import { getActiveLocale, m, type MessageResolver } from "../../i18n/messages";
5 import {
6 resolveSelectableProviderInstanceEntry,
7 type ProviderInstanceEntry,
8 } from "../../providerInstances";
9
10 function providerSupportsManualCompaction(
11 provider: ProviderInstanceEntry | null | undefined,
12 ): boolean {
13 return provider?.snapshot.slashCommands.some((command) => command.name === "compact") ?? false;
14 }
15
16 export function hasAvailableCompactionProvider(input: {
17 readonly providers: ReadonlyArray<ProviderInstanceEntry>;
18 readonly driverKind: ProviderDriverKind;
19 readonly instanceId: ProviderInstanceId | null;
20 readonly lockedInstanceId: ProviderInstanceId | null;
21 }): boolean {
22 const driverProviders = input.providers.filter(
23 (provider) => provider.driverKind === input.driverKind,
24 );
25 const lockedContinuationGroupKey = input.lockedInstanceId
26 ? driverProviders.find((provider) => provider.instanceId === input.lockedInstanceId)
27 ?.continuationGroupKey
28 : undefined;
29 const compatibleProviders = lockedContinuationGroupKey
30 ? driverProviders.filter(
31 (provider) => provider.continuationGroupKey === lockedContinuationGroupKey,
32 )
33 : driverProviders;
34
35 return providerSupportsManualCompaction(
36 resolveSelectableProviderInstanceEntry(compatibleProviders, input.instanceId ?? undefined),
37 );
38 }
39
40 export function formatContextWindowCompactionMessage(
41 autoCompactThreshold?: number | null,
42 resolve: MessageResolver = m,
43 locale: string = getActiveLocale(),
44 ): string {
45 if (typeof autoCompactThreshold === "number" && autoCompactThreshold > 0) {
46 return resolve(
47 msg("Compacts automatically at about {tokens} tokens.", {
48 tokens: autoCompactThreshold.toLocaleString(locale),
49 }),
50 );
51 }
52 return resolve(msg("Context compacts automatically when needed."));
53 }