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
| 1 | import type { ClientSettings } from "@t3tools/contracts"; |
| 2 | import { msg } from "gt-react"; |
| 3 | |
| 4 | // Ids are stored in client settings, so never rename one. |
| 5 | export const THREAD_DETAILS_ITEMS = [ |
| 6 | { id: "environment", label: msg("Environment and worktree"), defaultVisible: true }, |
| 7 | { id: "openIn", label: msg("Open in editor"), defaultVisible: true }, |
| 8 | { id: "scripts", label: msg("Project scripts"), defaultVisible: true }, |
| 9 | { id: "branch", label: msg("Branch and pull request"), defaultVisible: true }, |
| 10 | { id: "gitActions", label: msg("Git actions"), defaultVisible: true }, |
| 11 | { |
| 12 | id: "changes", |
| 13 | label: msg("Changes", { $context: "thread details item: version control changes" }), |
| 14 | defaultVisible: true, |
| 15 | }, |
| 16 | { |
| 17 | id: "servers", |
| 18 | label: msg("Servers", { $context: "thread details item: running dev servers" }), |
| 19 | defaultVisible: true, |
| 20 | }, |
| 21 | { id: "automations", label: msg("Automations"), defaultVisible: true }, |
| 22 | { |
| 23 | id: "lineage", |
| 24 | label: msg("Lineage", { $context: "thread details item: parent and child agents" }), |
| 25 | defaultVisible: true, |
| 26 | }, |
| 27 | { id: "sideChats", label: msg("Side chats"), defaultVisible: true }, |
| 28 | { id: "usage", label: msg("Usage limits"), defaultVisible: false }, |
| 29 | { id: "context", label: msg("Context window"), defaultVisible: false }, |
| 30 | ] as const; |
| 31 | |
| 32 | export type ThreadDetailsItemId = (typeof THREAD_DETAILS_ITEMS)[number]["id"]; |
| 33 | export type ThreadDetailsVisibility = Readonly<Record<ThreadDetailsItemId, boolean>>; |
| 34 | |
| 35 | type ThreadDetailsItem = (typeof THREAD_DETAILS_ITEMS)[number]; |
| 36 | type ThreadDetailsItemSettings = Pick< |
| 37 | ClientSettings, |
| 38 | "threadDetailsItems" | "threadDetailsUsageEnabled" |
| 39 | >; |
| 40 | |
| 41 | // People who turned on the retired Labs toggle keep Usage and Context until they change them here. |
| 42 | function defaultVisible(item: ThreadDetailsItem, settings: ThreadDetailsItemSettings) { |
| 43 | return item.id === "usage" || item.id === "context" |
| 44 | ? settings.threadDetailsUsageEnabled |
| 45 | : item.defaultVisible; |
| 46 | } |
| 47 | |
| 48 | export function resolveThreadDetailsVisibility( |
| 49 | settings: ThreadDetailsItemSettings, |
| 50 | ): ThreadDetailsVisibility { |
| 51 | return Object.fromEntries( |
| 52 | THREAD_DETAILS_ITEMS.map((item) => [ |
| 53 | item.id, |
| 54 | settings.threadDetailsItems[item.id] ?? defaultVisible(item, settings), |
| 55 | ]), |
| 56 | ) as Record<ThreadDetailsItemId, boolean>; |
| 57 | } |
| 58 | |
| 59 | /** Stores only choices that differ from the default, so a later default change reaches everyone else. */ |
| 60 | export function setThreadDetailsItem( |
| 61 | settings: ThreadDetailsItemSettings, |
| 62 | item: ThreadDetailsItem, |
| 63 | visible: boolean, |
| 64 | ): ClientSettings["threadDetailsItems"] { |
| 65 | const { [item.id]: _previous, ...rest } = settings.threadDetailsItems; |
| 66 | return visible === defaultVisible(item, settings) ? rest : { ...rest, [item.id]: visible }; |
| 67 | } |
| 68 | |
| 69 | export function isDefaultThreadDetailsVisibility(visibility: ThreadDetailsVisibility) { |
| 70 | return THREAD_DETAILS_ITEMS.every((item) => visibility[item.id] === item.defaultVisible); |
| 71 | } |
| 72 | |
| 73 | /** Also clears the retired Labs flag, so Usage and Context return to off. */ |
| 74 | export const RESET_THREAD_DETAILS_ITEMS = { |
| 75 | threadDetailsItems: {}, |
| 76 | threadDetailsUsageEnabled: false, |
| 77 | } satisfies Partial<ClientSettings>; |