11// Versions used by cse-copilot
2- import { allVersions } from '@/versions/lib/all-versions'
32import { versionToIndexVersionMap } from '../elasticsearch-versions'
43const CSE_COPILOT_DOCS_VERSIONS = [ 'dotcom' , 'ghec' , 'ghes' ]
54
@@ -9,70 +8,22 @@ export function supportedCSECopilotLanguages() {
98 return DOCS_LANGUAGES
109}
1110
12- export function getCSECopilotSource (
13- version : ( typeof CSE_COPILOT_DOCS_VERSIONS ) [ number ] ,
14- language : ( typeof DOCS_LANGUAGES ) [ number ] ,
15- ) {
16- const mappedVersion = versionToIndexVersionMap [ version ]
17- const { cseCopilotDocsVersion, ghesButNotLatest } = getVersionInfo ( mappedVersion )
11+ export function getCSECopilotSource ( version : ( typeof CSE_COPILOT_DOCS_VERSIONS ) [ number ] ) {
12+ if ( ! version ) {
13+ throw new Error ( `Missing required key 'version' in request body` )
14+ }
1815
19- if ( ghesButNotLatest ) {
20- throw new Error (
21- `Only the latest version of GHES is supported for cse-copilot queries. Please use 'ghes@latest'` ,
22- )
16+ let mappedVersion = versionToIndexVersionMap [ version ]
17+ // CSE-Copilot uses 'dotcom' as the version name for free-pro-team
18+ if ( mappedVersion === 'fpt' ) {
19+ mappedVersion = 'dotcom'
2320 }
2421
25- if ( ! CSE_COPILOT_DOCS_VERSIONS . includes ( cseCopilotDocsVersion ) ) {
22+ if ( ! CSE_COPILOT_DOCS_VERSIONS . includes ( mappedVersion ) && ! mappedVersion ?. startsWith ( 'ghes-' ) ) {
2623 throw new Error (
2724 `Invalid 'version' in request body: '${ version } '. Must be one of: ${ CSE_COPILOT_DOCS_VERSIONS . join ( ', ' ) } ` ,
2825 )
2926 }
30- if ( ! DOCS_LANGUAGES . includes ( language ) ) {
31- throw new Error (
32- `Invalid 'language' in request body '${ language } '. Must be one of: ${ DOCS_LANGUAGES . join ( ', ' ) } ` ,
33- )
34- }
35- // cse-copilot uses version names in the form `docs_<shortName>_<language>`, e.g. `docs_ghes_en`
36- return `docs_${ cseCopilotDocsVersion } _${ language } `
37- }
38-
39- function getVersionInfo ( Version : string ) : {
40- cseCopilotDocsVersion : string
41- ghesButNotLatest : boolean
42- } {
43- const versionObject = Object . values ( allVersions ) . find (
44- ( info ) =>
45- info . shortName === Version ||
46- info . plan === Version ||
47- info . miscVersionName === Version ||
48- info . currentRelease === Version ,
49- )
50-
51- let cseCopilotDocsVersion = versionObject ?. shortName || ''
52- let ghesButNotLatest = false
53- if ( ! versionObject || ! cseCopilotDocsVersion ) {
54- return {
55- cseCopilotDocsVersion,
56- ghesButNotLatest,
57- }
58- }
59-
60- // CSE-Copilot uses 'dotcom' as the version name for free-pro-team
61- if ( cseCopilotDocsVersion === 'fpt' ) {
62- cseCopilotDocsVersion = 'dotcom'
63- }
64-
65- // If ghes, we only support the latest version for cse-copilot queries
66- // Since that's the only version cse-copilot scrapes from our docs
67- if (
68- versionObject . shortName === 'ghes' &&
69- versionObject . currentRelease !== versionObject . latestRelease
70- ) {
71- ghesButNotLatest = true
72- }
73-
74- return {
75- cseCopilotDocsVersion,
76- ghesButNotLatest,
77- }
27+ // cse-copilot uses version names in the form `docs_<version-shortName>`, e.g. `docs_ghes-3.16`
28+ return `docs_${ mappedVersion } `
7829}
0 commit comments