@@ -4,9 +4,10 @@ import { dirname, join } from "node:path";
44import { fileURLToPath } from "node:url" ;
55import type { CacheMetadata , GitHubRelease } from "../types.js" ;
66
7- // Codex instructions constants
87const GITHUB_API_RELEASES =
98 "https://api.github.com/repos/openai/codex/releases/latest" ;
9+ const GITHUB_HTML_RELEASES =
10+ "https://github.com/openai/codex/releases/latest" ;
1011const CACHE_DIR = join ( homedir ( ) , ".opencode" , "cache" ) ;
1112
1213const __filename = fileURLToPath ( import . meta. url ) ;
@@ -61,11 +62,40 @@ export function getModelFamily(normalizedModel: string): ModelFamily {
6162 * @returns Release tag name (e.g., "rust-v0.43.0")
6263 */
6364async function getLatestReleaseTag ( ) : Promise < string > {
64- const response = await fetch ( GITHUB_API_RELEASES ) ;
65- if ( ! response . ok )
66- throw new Error ( `Failed to fetch latest release: ${ response . status } ` ) ;
67- const data = ( await response . json ( ) ) as GitHubRelease ;
68- return data . tag_name ;
65+ try {
66+ const response = await fetch ( GITHUB_API_RELEASES ) ;
67+ if ( response . ok ) {
68+ const data = ( await response . json ( ) ) as GitHubRelease ;
69+ if ( data . tag_name ) {
70+ return data . tag_name ;
71+ }
72+ }
73+ } catch {
74+ }
75+
76+ const htmlResponse = await fetch ( GITHUB_HTML_RELEASES ) ;
77+ if ( ! htmlResponse . ok ) {
78+ throw new Error (
79+ `Failed to fetch latest release: ${ htmlResponse . status } ` ,
80+ ) ;
81+ }
82+
83+ const finalUrl = htmlResponse . url ;
84+ if ( finalUrl ) {
85+ const parts = finalUrl . split ( "/tag/" ) ;
86+ const last = parts [ parts . length - 1 ] ;
87+ if ( last && ! last . includes ( "/" ) ) {
88+ return last ;
89+ }
90+ }
91+
92+ const html = await htmlResponse . text ( ) ;
93+ const match = html . match ( / \/ o p e n a i \/ c o d e x \/ r e l e a s e s \/ t a g \/ ( [ ^ " ] + ) / ) ;
94+ if ( match && match [ 1 ] ) {
95+ return match [ 1 ] ;
96+ }
97+
98+ throw new Error ( "Failed to determine latest release tag from GitHub" ) ;
6999}
70100
71101/**
0 commit comments