theclawbay 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/commands/setup.js
CHANGED
|
@@ -208,7 +208,7 @@ async function writeCodexConfig(params) {
|
|
|
208
208
|
'name = "OpenAI"',
|
|
209
209
|
`base_url = "${proxyRoot}/backend-api/codex"`,
|
|
210
210
|
'wire_api = "responses"',
|
|
211
|
-
"requires_openai_auth =
|
|
211
|
+
"requires_openai_auth = false",
|
|
212
212
|
`experimental_bearer_token = "${params.apiKey}"`,
|
|
213
213
|
MANAGED_END,
|
|
214
214
|
]);
|
|
@@ -12,6 +12,7 @@ const node_child_process_1 = require("node:child_process");
|
|
|
12
12
|
const node_os_1 = __importDefault(require("node:os"));
|
|
13
13
|
const MODELS_CACHE_FILE = "models_cache.json";
|
|
14
14
|
const MODELS_CACHE_STATE_FILE = "theclawbay.models-cache.json";
|
|
15
|
+
const STATE_DB_FILE_PATTERN = /^state_\d+\.sqlite$/;
|
|
15
16
|
const TARGET_MODEL_ID = "gpt-5.4";
|
|
16
17
|
const SEED_MARKER_KEY = "_theclawbay_seeded";
|
|
17
18
|
const SEED_MARKER_VALUE = "gpt-5.4";
|
|
@@ -208,21 +209,110 @@ function runVersionCommand(command, args) {
|
|
|
208
209
|
return null;
|
|
209
210
|
return parseCodexVersion(`${run.stdout ?? ""}\n${run.stderr ?? ""}`);
|
|
210
211
|
}
|
|
211
|
-
function
|
|
212
|
+
function resolvePythonCommand() {
|
|
213
|
+
const candidates = [
|
|
214
|
+
{ command: "python3", args: ["-c", "import sqlite3"] },
|
|
215
|
+
{ command: "python", args: ["-c", "import sqlite3"] },
|
|
216
|
+
{ command: "py", args: ["-3", "-c", "import sqlite3"] },
|
|
217
|
+
];
|
|
218
|
+
for (const candidate of candidates) {
|
|
219
|
+
const result = (0, node_child_process_1.spawnSync)(candidate.command, candidate.args, { stdio: "ignore" });
|
|
220
|
+
if (result.status === 0) {
|
|
221
|
+
return {
|
|
222
|
+
command: candidate.command,
|
|
223
|
+
args: candidate.args.slice(0, -2),
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
async function listStateDbs(codexHome) {
|
|
230
|
+
let entries = [];
|
|
231
|
+
try {
|
|
232
|
+
entries = await promises_1.default.readdir(codexHome, { withFileTypes: true });
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
const err = error;
|
|
236
|
+
if (err.code === "ENOENT")
|
|
237
|
+
return [];
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
return entries
|
|
241
|
+
.filter((entry) => entry.isFile() && STATE_DB_FILE_PATTERN.test(entry.name))
|
|
242
|
+
.map((entry) => node_path_1.default.join(codexHome, entry.name));
|
|
243
|
+
}
|
|
244
|
+
async function inferCodexClientVersionFromStateDb(codexHome) {
|
|
245
|
+
const python = resolvePythonCommand();
|
|
246
|
+
if (!python)
|
|
247
|
+
return null;
|
|
248
|
+
const dbs = await listStateDbs(codexHome);
|
|
249
|
+
if (dbs.length === 0)
|
|
250
|
+
return null;
|
|
251
|
+
const dated = await Promise.all(dbs.map(async (dbPath) => {
|
|
252
|
+
try {
|
|
253
|
+
const stats = await promises_1.default.stat(dbPath);
|
|
254
|
+
return { dbPath, mtimeMs: stats.mtimeMs };
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
return { dbPath, mtimeMs: 0 };
|
|
258
|
+
}
|
|
259
|
+
}));
|
|
260
|
+
dated.sort((left, right) => right.mtimeMs - left.mtimeMs);
|
|
261
|
+
const script = [
|
|
262
|
+
"import sqlite3, sys",
|
|
263
|
+
"db_path = sys.argv[1]",
|
|
264
|
+
"query = \"\"\"",
|
|
265
|
+
"SELECT cli_version",
|
|
266
|
+
"FROM threads",
|
|
267
|
+
"WHERE cli_version IS NOT NULL AND TRIM(cli_version) != ''",
|
|
268
|
+
"ORDER BY updated_at DESC",
|
|
269
|
+
"LIMIT 50",
|
|
270
|
+
"\"\"\"",
|
|
271
|
+
"conn = sqlite3.connect(db_path)",
|
|
272
|
+
"cur = conn.cursor()",
|
|
273
|
+
"try:",
|
|
274
|
+
" rows = cur.execute(query).fetchall()",
|
|
275
|
+
"except Exception:",
|
|
276
|
+
" rows = []",
|
|
277
|
+
"finally:",
|
|
278
|
+
" conn.close()",
|
|
279
|
+
"for row in rows:",
|
|
280
|
+
" value = row[0] if row else ''",
|
|
281
|
+
" if isinstance(value, str) and value.strip():",
|
|
282
|
+
" print(value.strip())",
|
|
283
|
+
].join("\n");
|
|
284
|
+
for (const entry of dated) {
|
|
285
|
+
const run = (0, node_child_process_1.spawnSync)(python.command, [...python.args, "-c", script, entry.dbPath], {
|
|
286
|
+
encoding: "utf8",
|
|
287
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
288
|
+
});
|
|
289
|
+
if (run.status !== 0)
|
|
290
|
+
continue;
|
|
291
|
+
const versions = (run.stdout ?? "")
|
|
292
|
+
.split(/\r?\n/)
|
|
293
|
+
.map((line) => parseCodexVersion(line))
|
|
294
|
+
.filter((line) => Boolean(line));
|
|
295
|
+
if (versions.length > 0) {
|
|
296
|
+
return versions[0] ?? null;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return null;
|
|
300
|
+
}
|
|
301
|
+
async function inferCodexClientVersion(codexHome) {
|
|
212
302
|
if (node_os_1.default.platform() === "win32") {
|
|
213
303
|
for (const commandLine of ["codex --version", "codex-cli --version", "codex.cmd --version", "codex-cli.cmd --version"]) {
|
|
214
304
|
const parsed = runVersionCommand("cmd.exe", ["/d", "/s", "/c", commandLine]);
|
|
215
305
|
if (parsed)
|
|
216
306
|
return parsed;
|
|
217
307
|
}
|
|
218
|
-
return
|
|
308
|
+
return await inferCodexClientVersionFromStateDb(codexHome);
|
|
219
309
|
}
|
|
220
310
|
for (const command of ["codex", "codex-cli"]) {
|
|
221
311
|
const parsed = runVersionCommand(command, ["--version"]);
|
|
222
312
|
if (parsed)
|
|
223
313
|
return parsed;
|
|
224
314
|
}
|
|
225
|
-
return
|
|
315
|
+
return await inferCodexClientVersionFromStateDb(codexHome);
|
|
226
316
|
}
|
|
227
317
|
function normalizeCacheDocument(value) {
|
|
228
318
|
const doc = objectRecordOr(value);
|
|
@@ -240,7 +330,7 @@ async function ensureCodexModelCacheHasGpt54(params) {
|
|
|
240
330
|
const existingState = await readPatchState(statePath);
|
|
241
331
|
const parsed = await readJsonIfExists(cachePath);
|
|
242
332
|
if (parsed === null) {
|
|
243
|
-
const clientVersion = inferCodexClientVersion();
|
|
333
|
+
const clientVersion = await inferCodexClientVersion(params.codexHome);
|
|
244
334
|
if (!clientVersion) {
|
|
245
335
|
await removeFileIfExists(statePath);
|
|
246
336
|
return {
|