1
0
mirror of synced 2025-12-21 10:57:10 -05:00

Implementation of API between Docs and CSE Copilot (#52892)

Co-authored-by: Evan Bonsignori <evanabonsignori@gmail.com>
Co-authored-by: Evan Bonsignori <ebonsignori@github.com>
This commit is contained in:
Ashish Keshan
2024-11-14 14:29:34 -05:00
committed by GitHub
parent d35127dfa9
commit ff3bd583b4
11 changed files with 490 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
// Versions used by cse-copilot
import { allVersions } from '@/versions/lib/all-versions'
const CSE_COPILOT_DOCS_VERSIONS = ['dotcom', 'ghec', 'ghes']
// Languages supported by cse-copilot
const DOCS_LANGUAGES = ['en']
export function supportedCSECopilotLanguages() {
return DOCS_LANGUAGES
}
export function getCSECopilotSource(
version: (typeof CSE_COPILOT_DOCS_VERSIONS)[number],
language: (typeof DOCS_LANGUAGES)[number],
) {
const cseCopilotDocsVersion = getMiscBaseNameFromVersion(version)
if (!CSE_COPILOT_DOCS_VERSIONS.includes(cseCopilotDocsVersion)) {
throw new Error(
`Invalid 'version' in request body: '${version}'. Must be one of: ${CSE_COPILOT_DOCS_VERSIONS.join(', ')}`,
)
}
if (!DOCS_LANGUAGES.includes(language)) {
throw new Error(
`Invalid 'language' in request body '${language}'. Must be one of: ${DOCS_LANGUAGES.join(', ')}`,
)
}
return `docs_${version}_${language}`
}
function getMiscBaseNameFromVersion(Version: string): string {
const miscBaseName =
Object.values(allVersions).find(
(info) =>
info.shortName === Version ||
info.plan === Version ||
info.miscVersionName === Version ||
info.currentRelease === Version,
)?.miscBaseName || ''
if (!miscBaseName) {
return ''
}
return miscBaseName
}