返回 CodeWhale
product-map.ts
根目录 / web / lib / content / product-map.ts
1 import { runtimeCapabilityContext, capabilityAvailability, type CapabilityContext } from "../capabilities";
2 import { FACTS } from "../facts.generated";
3 import { FEATURE_CATALOGUE, type Feature } from "../features";
4 import type { HomeDict } from "../i18n/dictionaries/types";
5 import { surfaceState, type SurfaceContext, type SurfaceId, type SurfaceState } from "../surface-states";
6
7 export const PRODUCT_MAP_IDS = ["terminal", "localBrowser", "manyAgents", "desktop", "cloud", "oneSession"] as const;
8 export type ProductMapId = (typeof PRODUCT_MAP_IDS)[number];
9
10 export const PRODUCT_MAP_STATES = ["released", "developing", "inviteOnly", "beingBuilt"] as const;
11 export type ProductMapState = (typeof PRODUCT_MAP_STATES)[number];
12
13 export const PRODUCT_MAP_STATE_KEY = {
14 released: "mapStateReleased",
15 developing: "mapStateDeveloping",
16 inviteOnly: "mapStateInviteOnly",
17 beingBuilt: "mapStateBeingBuilt",
18 } as const satisfies Record<ProductMapState, keyof HomeDict>;
19
20 export const PRODUCT_MAP_TEXT_KEYS = {
21 terminal: { name: "mapTerminal", sentence: "mapTerminalSentence" },
22 localBrowser: { name: "mapLocalBrowser", sentence: "mapLocalBrowserSentence" },
23 manyAgents: { name: "mapManyAgents", sentence: "mapManyAgentsSentence" },
24 desktop: { name: "mapDesktop", sentence: "mapDesktopSentence" },
25 cloud: { name: "mapCloud", sentence: "mapCloudSentence" },
26 oneSession: { name: "mapOneSession", sentence: "mapOneSessionSentence" },
27 } as const satisfies Record<ProductMapId, { name: keyof HomeDict; sentence: keyof HomeDict }>;
28
29 const SURFACE_OF: Record<Exclude<ProductMapId, "manyAgents" | "oneSession">, SurfaceId> = {
30 terminal: "terminal",
31 localBrowser: "local-browser",
32 desktop: "desktop",
33 cloud: "cloud-computers",
34 };
35
36 const SENTENCE_STATE: Record<ProductMapId, ProductMapState> = {
37 terminal: "released",
38 localBrowser: "released",
39 manyAgents: "released",
40 desktop: "developing",
41 cloud: "inviteOnly",
42 oneSession: "beingBuilt",
43 };
44
45 const MANY_AGENT_FEATURES = ["subagents", "fleet", "workflows"] as const;
46
47 export interface ProductMapInput {
48 surface?: SurfaceContext;
49 capabilities?: CapabilityContext;
50 features?: readonly Feature[];
51 }
52
53 export interface ProductMapRow {
54 id: ProductMapId;
55 state: ProductMapState;
56 sentenceHolds: boolean;
57 }
58
59 function fromSurface(state: SurfaceState): ProductMapState {
60 switch (state) {
61 case "released":
62 case "available":
63 case "open":
64 return "released";
65 case "invite_only":
66 return "inviteOnly";
67 case "not_open":
68 case "not_public":
69 return "beingBuilt";
70 default:
71 return "developing";
72 }
73 }
74
75 function manyAgentsState(context: CapabilityContext, features: readonly Feature[]): ProductMapState {
76 const rows = MANY_AGENT_FEATURES.map((id) => features.find((feature) => feature.id === id));
77 if (rows.some((row) => !row)) return "beingBuilt";
78 const availability = rows.map((row) => capabilityAvailability(row!, context));
79 if (availability.every((value) => value === "released")) return "released";
80 return availability.some((value) => value === "hidden") ? "beingBuilt" : "developing";
81 }
82
83 export function productMap(input: ProductMapInput = {}): ProductMapRow[] {
84 const surface = input.surface ?? {};
85 const capabilities = input.capabilities ?? runtimeCapabilityContext(FACTS);
86 const features = input.features ?? FEATURE_CATALOGUE.features;
87 return PRODUCT_MAP_IDS.map((id) => {
88 const state: ProductMapState =
89 id === "manyAgents"
90 ? manyAgentsState(capabilities, features)
91 : id === "oneSession"
92 ? "beingBuilt"
93 : fromSurface(surfaceState(SURFACE_OF[id], surface));
94 return { id, state, sentenceHolds: state === SENTENCE_STATE[id] };
95 });
96 }
97
97 lines TYPESCRIPT