| 1 | import { getReferenceSearchSections } from "./reference-guides"; |
| 2 | import type { DocSearchSection } from "./doc-search-match"; |
| 3 | import { |
| 4 | getDocsAuth, getDocsClaudeCode, getDocsConfiguration, getDocsFleet, |
| 5 | getDocsHooks, getDocsMcp, getDocsModes, getDocsPet, getDocsReview, |
| 6 | getDocsRuntimeApi, getDocsSandbox, getDocsSkills, getDocsSubagents, |
| 7 | getDocsTroubleshooting, getDocsTrust, getDocsWeb, getDocsWork, getDocsFirstTime, |
| 8 | getDocsGuide, getDocsVocabulary, getConstitution, getChrome, getHome, fill, pickText, |
| 9 | } from "./i18n/dictionaries"; |
| 10 | import type { DocsBlock, DocsPageDict } from "./i18n/dictionaries/types"; |
| 11 | import { GETTING_STARTED_STEPS } from "./content/getting-started"; |
| 12 | import { INSTALL_COPY, INSTALL_COMMANDS, INSTALL_PAGE_COMMANDS } from "./content/install"; |
| 13 | import { FACTS } from "./facts.generated"; |
| 14 | import { MODELS_COPY, formatModelTokens, formatModelDate } from "./content/models"; |
| 15 | import { PLUGINS_COPY, PLUGINS_COMING, pluginsComingApplies, PLUGIN_KINDS, CATALOG_FEATURED, PLUGIN_SOURCES, PLUGIN_COMMANDS, PLUGIN_COMPATIBILITY } from "./content/plugins"; |
| 16 | import { CONNECTORS } from "./content/connectors.generated"; |
| 17 | import { CONSTITUTION_LAYERS, CONSTITUTION_SCENES } from "./content/constitution"; |
| 18 | import { getDocsAccount } from "./content/docs-account"; |
| 19 | import type { LocalizedText } from "./content/vocabulary"; |
| 20 | import { TOOLS_COPY, toolRowsFor } from "./content/tools"; |
| 21 | import { resolveDocsPage } from "./docs-release"; |
| 22 | import { runtimeCapabilityContext } from "./capabilities"; |
| 23 | import { BUILD_FACTS } from "./facts"; |
| 24 | import { |
| 25 | ADVISORY_ROLE, MEASUREMENT_PRINCIPLES, PRODUCT_TERMS, ROUTE_IDENTITY, controlTermsFor, |
| 26 | } from "./content/vocabulary"; |
| 27 | |
| 28 | const ARTICLES: Record<string, (locale: string) => DocsPageDict> = { |
| 29 | account: getDocsAccount, auth: getDocsAuth, "claude-code": getDocsClaudeCode, configuration: getDocsConfiguration, |
| 30 | fleet: getDocsFleet, hooks: getDocsHooks, mcp: getDocsMcp, modes: getDocsModes, |
| 31 | pet: getDocsPet, review: getDocsReview, "runtime-api": getDocsRuntimeApi, |
| 32 | sandbox: getDocsSandbox, skills: getDocsSkills, subagents: getDocsSubagents, |
| 33 | troubleshooting: getDocsTroubleshooting, trust: getDocsTrust, web: getDocsWeb, |
| 34 | work: getDocsWork, "first-time": getDocsFirstTime, |
| 35 | }; |
| 36 | |
| 37 | function blockText(block: DocsBlock): string { |
| 38 | if ("p" in block) return block.p; |
| 39 | if ("code" in block) return block.code; |
| 40 | if ("rows" in block) return block.rows.flat().join(" "); |
| 41 | if ("steps" in block) return block.steps.join(" "); |
| 42 | if ("list" in block) return block.list.join(" "); |
| 43 | return block.note; |
| 44 | } |
| 45 | |
| 46 | export function getDocSearchSections(locale: string): DocSearchSection[] { |
| 47 | const context = runtimeCapabilityContext(BUILD_FACTS); |
| 48 | const tools = toolRowsFor(context); |
| 49 | const sections = Object.entries(ARTICLES).flatMap(([slug, getArticle]) => { |
| 50 | const article = getArticle(locale); |
| 51 | return [ |
| 52 | { id: "overview", title: article.title, text: article.lede }, |
| 53 | ...resolveDocsPage(article, context).sections.map((section) => ({ |
| 54 | id: section.id, title: section.title, text: section.blocks.map(blockText).join(" "), |
| 55 | })), |
| 56 | ].map((section) => ({ |
| 57 | href: `/docs/${slug}#${section.id}`, pageTitle: article.title, |
| 58 | title: section.title, text: section.text, |
| 59 | })); |
| 60 | }); |
| 61 | const guide = getDocsGuide(locale); |
| 62 | sections.push(...GETTING_STARTED_STEPS.map((step) => ({ |
| 63 | href: `/docs/guide#${step.id}`, pageTitle: guide.overviewTitle, |
| 64 | title: pickText(step.title, locale), |
| 65 | text: [pickText(step.body, locale), ...step.commands, step.prompt ? pickText(step.prompt, locale) : ""].join(" "), |
| 66 | }))); |
| 67 | const vocabulary = getDocsVocabulary(locale); |
| 68 | sections.push( |
| 69 | { href: "/docs/tools#overview", pageTitle: pickText(TOOLS_COPY.title, locale), title: pickText(TOOLS_COPY.title, locale), text: [pickText(tools.released ? TOOLS_COPY.lead : TOOLS_COPY.leadSource, locale), ...tools.body.flatMap((row) => [row.name, pickText(row.detail, locale)])].join(" ") }, |
| 70 | { href: "/docs/tools#lsp", pageTitle: pickText(TOOLS_COPY.title, locale), title: pickText(TOOLS_COPY.lspTitle, locale), text: pickText(TOOLS_COPY.lspBody, locale) }, |
| 71 | { href: "/docs/tools#compatibility", pageTitle: pickText(TOOLS_COPY.title, locale), title: pickText(TOOLS_COPY.compatibilityTitle, locale), text: pickText(TOOLS_COPY.compatibility, locale) }, |
| 72 | { href: "/docs/vocabulary#execution-nouns", pageTitle: vocabulary.title, title: vocabulary.executionHeading, text: PRODUCT_TERMS.flatMap((row) => [row.term, pickText(row.short, locale), pickText(row.long, locale)]).join(" ") }, |
| 73 | { href: "/docs/vocabulary#control-nouns", pageTitle: vocabulary.title, title: vocabulary.controlHeading, text: controlTermsFor(context).body.flatMap((row) => [row.term, pickText(row.description, locale)]).join(" ") }, |
| 74 | { href: "/docs/vocabulary#route-identity", pageTitle: vocabulary.title, title: vocabulary.routeHeading, text: ROUTE_IDENTITY.flatMap((row) => [row.term, pickText(row.description, locale)]).join(" ") }, |
| 75 | { href: "/docs/vocabulary#advisory-role", pageTitle: vocabulary.title, title: vocabulary.advisoryHeading, text: `${ADVISORY_ROLE.term} ${pickText(ADVISORY_ROLE.description, locale)}` }, |
| 76 | { href: "/docs/vocabulary#measurement", pageTitle: vocabulary.title, title: vocabulary.measurementHeading, text: MEASUREMENT_PRINCIPLES.map((row) => pickText(row, locale)).join(" ") }, |
| 77 | ); |
| 78 | sections.push(...getCustomDocSearchSections(locale), ...getReferenceSearchSections(locale)); |
| 79 | return sections; |
| 80 | } |
| 81 | |
| 82 | function getCustomDocSearchSections(locale: string): DocSearchSection[] { |
| 83 | const t = (copy: LocalizedText) => fill(pickText(copy, locale), { |
| 84 | version: FACTS.version ?? "—", model: FACTS.defaultModel ?? "—", |
| 85 | }); |
| 86 | const section = (path: string, id: string, pageTitle: string, title: string, text: string[]): DocSearchSection => ({ |
| 87 | href: `${path}#${id}`, pageTitle, title, text: text.join(" "), |
| 88 | }); |
| 89 | const installTitle = getHome(locale).sectionStartHeading; |
| 90 | const modelTitle = t(MODELS_COPY.modelsTitle); |
| 91 | const pluginTitle = t(PLUGINS_COPY.title); |
| 92 | const constitution = getConstitution(locale); |
| 93 | const sections = [ |
| 94 | section("/install", "install-overview", installTitle, installTitle, [ |
| 95 | getHome(locale).sectionStartBody, ...Object.values(INSTALL_COMMANDS), t(INSTALL_COPY.windowsNote), |
| 96 | t(INSTALL_COPY.cargoNote), t(INSTALL_COPY.scriptLink), |
| 97 | ]), |
| 98 | section("/install", "install-path", installTitle, t(INSTALL_COPY.pathTitle), [ |
| 99 | t(INSTALL_COPY.pathPlaces), t(INSTALL_COPY.pathBlockAfter), t(INSTALL_COPY.pathOptOut), t(INSTALL_COPY.pathManualIntro), |
| 100 | INSTALL_PAGE_COMMANDS.pathBlock, INSTALL_PAGE_COMMANDS.pathNow, INSTALL_PAGE_COMMANDS.noModifyPath, |
| 101 | ]), |
| 102 | section("/install", "install-verify", installTitle, t(INSTALL_COPY.verifyTitle), [ |
| 103 | t(INSTALL_COPY.verifyBodyUnknown), INSTALL_PAGE_COMMANDS.version, |
| 104 | ]), |
| 105 | section("/install", "install-first-task", installTitle, t(INSTALL_COPY.firstTitle), [ |
| 106 | t(INSTALL_COPY.firstStep1), t(INSTALL_COPY.firstStep2), t(INSTALL_COPY.firstStep3), |
| 107 | ]), |
| 108 | section("/install", "install-usage", installTitle, t(INSTALL_COPY.usageTitle), [ |
| 109 | t(INSTALL_COPY.usageBody), t(INSTALL_COPY.usageInstaller), |
| 110 | ]), |
| 111 | section("/install", "install-update", installTitle, t(INSTALL_COPY.updateTitle), [t(INSTALL_COPY.updateBody)]), |
| 112 | section("/install", "install-remove", installTitle, t(INSTALL_COPY.removeTitle), [ |
| 113 | t(INSTALL_COPY.removePath), t(INSTALL_COPY.removeData), INSTALL_PAGE_COMMANDS.removeFiles, INSTALL_PAGE_COMMANDS.removeData, |
| 114 | ]), |
| 115 | section("/install", "install-troubleshooting", installTitle, t(INSTALL_COPY.troubleTitle), [ |
| 116 | t(INSTALL_COPY.troubleNotFound), t(INSTALL_COPY.troubleQueued), t(INSTALL_COPY.troubleLegacy), |
| 117 | ]), |
| 118 | section("/install", "install-channels", installTitle, t(INSTALL_COPY.channelsTitle), [ |
| 119 | t(INSTALL_COPY.windowsPackage), t(INSTALL_COPY.windowsSandbox), t(INSTALL_COPY.npmBody), t(INSTALL_COPY.cargoBody), |
| 120 | t(INSTALL_COPY.brewBody), INSTALL_PAGE_COMMANDS.brewInstall, INSTALL_PAGE_COMMANDS.npmUpdate, |
| 121 | ]), |
| 122 | section("/install", "mirrors", installTitle, t(INSTALL_COPY.mirrorsTitle), [ |
| 123 | t(INSTALL_COPY.mirrorsNpm), t(INSTALL_COPY.mirrorsCnb), INSTALL_PAGE_COMMANDS.cnbVerify, |
| 124 | ]), |
| 125 | section("/models", "models-overview", modelTitle, t(MODELS_COPY.title), [t(MODELS_COPY.lead)]), |
| 126 | section("/models", "models-setup", modelTitle, t(MODELS_COPY.setupTitle), [ |
| 127 | t(MODELS_COPY.setupLead), t(MODELS_COPY.providerDocs), |
| 128 | ...MODELS_COPY.steps.flatMap(step => [t(step.title), t(step.detail).replaceAll("`", "")]), |
| 129 | t(MODELS_COPY.routeDeepseekTitle), t(MODELS_COPY.routeDeepseekBody), "DEEPSEEK_API_KEY", |
| 130 | t(MODELS_COPY.routeFirstPartyTitle), t(MODELS_COPY.routeFirstPartyBody), |
| 131 | t(MODELS_COPY.routeCompatTitle), t(MODELS_COPY.routeCompatBody), t(MODELS_COPY.routeCompatConfig).replaceAll("`", ""), |
| 132 | ]), |
| 133 | section("/models", "models-title", modelTitle, t(MODELS_COPY.modelsTitle), [ |
| 134 | t(MODELS_COPY.modelsLead), t(MODELS_COPY.colModel), t(MODELS_COPY.colContext), t(MODELS_COPY.colAdded), |
| 135 | ...FACTS.models.flatMap(model => [model.id, model.provider ?? "", model.reasoning ? t(MODELS_COPY.reasoning) : "", formatModelTokens(model.contextWindow), formatModelDate(model.addedAt, getChrome(locale).dateLocale)]), |
| 136 | ]), |
| 137 | section("/models", "providers-title", modelTitle, t(MODELS_COPY.listTitle), [ |
| 138 | t(MODELS_COPY.provider), t(MODELS_COPY.id), t(MODELS_COPY.credential), |
| 139 | ...FACTS.providers.flatMap(provider => [provider.label, provider.id, provider.env]), |
| 140 | t(MODELS_COPY.missing), t(MODELS_COPY.request), |
| 141 | ]), |
| 142 | section("/plugins", "plugins-overview", pluginTitle, pluginTitle, [ |
| 143 | t(PLUGINS_COPY.lead), t(PLUGINS_COPY.marketplaceCta), t(PLUGINS_COPY.docsCta), |
| 144 | ]), |
| 145 | section("/plugins", "kinds-title", pluginTitle, t(PLUGINS_COPY.kindsTitle), [ |
| 146 | ...PLUGIN_KINDS.flatMap(kind => [t(kind.title), t(kind.detail)]), |
| 147 | t(PLUGINS_COPY.originBefore) + t(PLUGINS_COPY.originName) + t(PLUGINS_COPY.originAfter), t(PLUGINS_COPY.dshStatus), t(PLUGINS_COPY.dshLink), |
| 148 | ]), |
| 149 | ...(pluginsComingApplies(runtimeCapabilityContext(BUILD_FACTS).release) ? [section("/plugins", "coming-title", pluginTitle, t(PLUGINS_COPY.comingTitle), [ |
| 150 | t(PLUGINS_COPY.comingLead), ...PLUGINS_COMING.flatMap(item => [t(item.title), t(item.detail)]), |
| 151 | ])] : []), |
| 152 | section("/plugins", "connectors-title", pluginTitle, t(PLUGINS_COPY.connectorsTitle), [ |
| 153 | t(PLUGINS_COPY.connectorsLead), ...CONNECTORS.map(connector => connector.name), t(PLUGINS_COPY.connectorsNote), |
| 154 | t(PLUGINS_COPY.connectorsGoogle), t(PLUGINS_COPY.connectorsLink), |
| 155 | ]), |
| 156 | section("/plugins", "catalog-title", pluginTitle, t(PLUGINS_COPY.catalogTitle), [ |
| 157 | t(PLUGINS_COPY.catalogLead), ...CATALOG_FEATURED.flatMap(entry => [entry.title, t(entry.detail), `/plugin marketplace install codewhale ${entry.name}`]), |
| 158 | ]), |
| 159 | section("/plugins", "safe-title", pluginTitle, t(PLUGINS_COPY.safeTitle), [ |
| 160 | t(PLUGINS_COPY.safeLead), ...PLUGINS_COPY.safeSteps.flatMap(step => [t(step.title), step.command, t(step.detail)]), |
| 161 | t(PLUGINS_COPY.safeHashes), t(PLUGINS_COPY.sourcesLead), PLUGIN_SOURCES, |
| 162 | ]), |
| 163 | section("/plugins", "reference-title", pluginTitle, t(PLUGINS_COPY.referenceTitle), [ |
| 164 | ...PLUGIN_COMMANDS, ...PLUGIN_COMPATIBILITY.flatMap(format => [t(format.title), t(format.detail)]), |
| 165 | ]), |
| 166 | section("/plugins", "contribute-title", pluginTitle, t(PLUGINS_COPY.contributeTitle), [ |
| 167 | t(PLUGINS_COPY.contributeLead), t(PLUGINS_COPY.docsCta), t(PLUGINS_COPY.contributeLink), |
| 168 | ]), |
| 169 | section("/constitution", "constitution-overview", constitution.title, constitution.title, [ |
| 170 | constitution.kicker, constitution.titleAside, constitution.lede, constitution.since, constitution.sinceBody, |
| 171 | ]), |
| 172 | section("/constitution", "constitution-rank", constitution.title, constitution.rankTitle, [ |
| 173 | constitution.rankScope, ...CONSTITUTION_LAYERS.flatMap(layer => [t(layer.name), t(layer.path), t(layer.body)]), |
| 174 | constitution.boundaryTitle, constitution.boundaryBody, |
| 175 | ]), |
| 176 | section("/constitution", "constitution-trace", constitution.title, constitution.traceTitle, [ |
| 177 | constitution.traceScope, constitution.illustration, |
| 178 | ...CONSTITUTION_SCENES.flatMap(scene => [t(scene.context), scene.trace, ...scene.cites, t(scene.decision)]), |
| 179 | ]), |
| 180 | section("/constitution", "constitution-next", constitution.title, constitution.configuration, [constitution.install]), |
| 181 | ]; |
| 182 | return sections; |
| 183 | } |
| 184 |