Skip to content

Commit 90af475

Browse files
committed
feat: fallback GitHub latest tag resolution without api.github.com
1 parent 94fbacc commit 90af475

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

lib/prompts/codex.ts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { dirname, join } from "node:path";
44
import { fileURLToPath } from "node:url";
55
import type { CacheMetadata, GitHubRelease } from "../types.js";
66

7-
// Codex instructions constants
87
const 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";
1011
const CACHE_DIR = join(homedir(), ".opencode", "cache");
1112

1213
const __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
*/
6364
async 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(/\/openai\/codex\/releases\/tag\/([^"]+)/);
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

Comments
 (0)