@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, 03:37 UTC

main
ts 59 lines 2.22 KB
Raw
1 import * as Schema from "effect/Schema";
2 import { TrimmedNonEmptyString } from "./baseSchemas.ts";
3
4 export const BROWSER_PROFILE_NAME_MAX_LENGTH = 48;
5 export const BROWSER_PROFILE_MAX_COUNT = 24;
6
7 /** Control characters could collide with client cache-key delimiters and select another partition. */
8 export const BrowserProfileId = TrimmedNonEmptyString.check(
9 Schema.isMaxLength(64),
10 Schema.isPattern(/^[^\p{Cc}]+$/u),
11 );
12 export type BrowserProfileId = typeof BrowserProfileId.Type;
13
14 export const BrowserProfileName = TrimmedNonEmptyString.check(
15 Schema.isMaxLength(BROWSER_PROFILE_NAME_MAX_LENGTH),
16 );
17
18 export const BrowserProfileKind = Schema.Literals(["persistent", "incognito"]);
19 export type BrowserProfileKind = typeof BrowserProfileKind.Type;
20
21 export const BrowserProfile = Schema.Struct({
22 id: BrowserProfileId,
23 name: BrowserProfileName,
24 kind: BrowserProfileKind,
25 });
26 export type BrowserProfile = typeof BrowserProfile.Type;
27
28 export const DEFAULT_BROWSER_PROFILE_ID: BrowserProfileId = "default";
29 export const INCOGNITO_BROWSER_PROFILE_ID: BrowserProfileId = "incognito";
30
31 export const BUILT_IN_BROWSER_PROFILES: ReadonlyArray<BrowserProfile> = [
32 { id: DEFAULT_BROWSER_PROFILE_ID, name: "Default", kind: "persistent" },
33 { id: INCOGNITO_BROWSER_PROFILE_ID, name: "Incognito", kind: "incognito" },
34 ];
35
36 export function isBuiltInBrowserProfileId(id: string): boolean {
37 return BUILT_IN_BROWSER_PROFILES.some((profile) => profile.id === id);
38 }
39
40 /** Deduplicates ids sharing a partition; only the built-in incognito id is actually ephemeral. */
41 export function resolveBrowserProfiles(
42 userProfiles: ReadonlyArray<BrowserProfile>,
43 ): ReadonlyArray<BrowserProfile> {
44 const seen = new Set(BUILT_IN_BROWSER_PROFILES.map((profile) => profile.id));
45 const resolved = [...BUILT_IN_BROWSER_PROFILES];
46 for (const profile of userProfiles) {
47 if (seen.has(profile.id)) continue;
48 seen.add(profile.id);
49 resolved.push(profile.kind === "persistent" ? profile : { ...profile, kind: "persistent" });
50 }
51 return resolved;
52 }
53
54 export function findBrowserProfile(
55 profiles: ReadonlyArray<BrowserProfile>,
56 id: string | undefined,
57 ): BrowserProfile | undefined {
58 return id === undefined ? undefined : profiles.find((profile) => profile.id === id);
59 }