@wengine-ai/ccr-provider-codex 1.0.15 → 1.0.16
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/plugin.js +93 -9
- package/dist/plugin.json +1 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -1857,6 +1857,57 @@ var CodexAuthService = class {
|
|
|
1857
1857
|
}
|
|
1858
1858
|
};
|
|
1859
1859
|
|
|
1860
|
+
// src/service-tier.ts
|
|
1861
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1862
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
1863
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
1864
|
+
function isCodexServiceTierSetting(value) {
|
|
1865
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || !Object.hasOwn(value, "tier") || Object.keys(value).length !== 1) return false;
|
|
1866
|
+
const { tier } = value;
|
|
1867
|
+
return tier === "follow" || tier === "standard" || tier === "priority";
|
|
1868
|
+
}
|
|
1869
|
+
var CodexServiceTierStore = class _CodexServiceTierStore {
|
|
1870
|
+
constructor(path, current) {
|
|
1871
|
+
this.path = path;
|
|
1872
|
+
this.current = current;
|
|
1873
|
+
}
|
|
1874
|
+
writeTail = Promise.resolve();
|
|
1875
|
+
static async load(configDir, log) {
|
|
1876
|
+
const path = join2(configDir, "codex-service-tier.json");
|
|
1877
|
+
let tier = "follow";
|
|
1878
|
+
try {
|
|
1879
|
+
const setting = JSON.parse(await readFile(path, "utf8"));
|
|
1880
|
+
if (!isCodexServiceTierSetting(setting)) throw new Error("invalid service tier");
|
|
1881
|
+
tier = setting.tier;
|
|
1882
|
+
} catch (error) {
|
|
1883
|
+
if (error.code !== "ENOENT") {
|
|
1884
|
+
log.warn("Could not read Codex service tier. Following the request tier.");
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return new _CodexServiceTierStore(path, tier);
|
|
1888
|
+
}
|
|
1889
|
+
get tier() {
|
|
1890
|
+
return this.current;
|
|
1891
|
+
}
|
|
1892
|
+
set(tier) {
|
|
1893
|
+
const write = this.writeTail.then(async () => {
|
|
1894
|
+
await mkdir(dirname2(this.path), { recursive: true, mode: 448 });
|
|
1895
|
+
const temp = `${this.path}.${randomUUID2()}.tmp`;
|
|
1896
|
+
try {
|
|
1897
|
+
await writeFile(temp, JSON.stringify({ tier }), { flag: "wx", mode: 384 });
|
|
1898
|
+
await rename(temp, this.path);
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
await rm(temp, { force: true });
|
|
1901
|
+
throw error;
|
|
1902
|
+
}
|
|
1903
|
+
this.current = tier;
|
|
1904
|
+
});
|
|
1905
|
+
this.writeTail = write.catch(() => {
|
|
1906
|
+
});
|
|
1907
|
+
return write;
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
|
|
1860
1911
|
// src/finalize-body.ts
|
|
1861
1912
|
import { createHash as createHash2 } from "node:crypto";
|
|
1862
1913
|
var CODEX_PARALLEL_TOOL_CALLS_DEFAULT = true;
|
|
@@ -2014,7 +2065,13 @@ function codexFinalizeBody(body, options = {}) {
|
|
|
2014
2065
|
const source = isPlainObject(body) ? clone(body) : {};
|
|
2015
2066
|
const out = { ...source };
|
|
2016
2067
|
for (const key of DROP_FIELDS) delete out[key];
|
|
2017
|
-
if (
|
|
2068
|
+
if (options.serviceTier === "standard") {
|
|
2069
|
+
delete out.service_tier;
|
|
2070
|
+
} else if (options.serviceTier === "priority" || options.serviceTier === "follow" && out.service_tier === "fast") {
|
|
2071
|
+
out.service_tier = "priority";
|
|
2072
|
+
} else if (typeof out.service_tier === "string" && !ALLOWED_SERVICE_TIERS.has(out.service_tier)) {
|
|
2073
|
+
delete out.service_tier;
|
|
2074
|
+
}
|
|
2018
2075
|
out.store = false;
|
|
2019
2076
|
out.stream = true;
|
|
2020
2077
|
out.tool_choice = "auto";
|
|
@@ -2141,9 +2198,11 @@ var CodexTransformer = class {
|
|
|
2141
2198
|
name = "codex";
|
|
2142
2199
|
logger;
|
|
2143
2200
|
service;
|
|
2201
|
+
getServiceTier;
|
|
2144
2202
|
constructor(options) {
|
|
2145
2203
|
if (!options?.service) throw new Error("CodexTransformer requires { service }");
|
|
2146
2204
|
this.service = options.service;
|
|
2205
|
+
this.getServiceTier = options.getServiceTier;
|
|
2147
2206
|
this.logger = options.logger;
|
|
2148
2207
|
}
|
|
2149
2208
|
/**
|
|
@@ -2151,7 +2210,7 @@ var CodexTransformer = class {
|
|
|
2151
2210
|
* `openai-responses` transformer. The runtime performs auth injection later
|
|
2152
2211
|
* (after the body is final), so no token is touched here.
|
|
2153
2212
|
*/
|
|
2154
|
-
async transformRequestIn(request,
|
|
2213
|
+
async transformRequestIn(request, provider, context) {
|
|
2155
2214
|
const model = typeof request?.model === "string" ? request.model : "";
|
|
2156
2215
|
let modelInstructions;
|
|
2157
2216
|
try {
|
|
@@ -2160,7 +2219,10 @@ var CodexTransformer = class {
|
|
|
2160
2219
|
modelInstructions = void 0;
|
|
2161
2220
|
}
|
|
2162
2221
|
const sessionId = this.sessionIdFor(request, context);
|
|
2163
|
-
const
|
|
2222
|
+
const serviceTier = isCodexRuntime(provider) ? this.getServiceTier?.() ?? "follow" : void 0;
|
|
2223
|
+
const originalTier = context?.req?.body?.service_tier;
|
|
2224
|
+
const source = serviceTier === "follow" && request.service_tier === void 0 && typeof originalTier === "string" ? { ...request, service_tier: originalTier } : request;
|
|
2225
|
+
const body = codexFinalizeBody(source, { modelInstructions, sessionId, serviceTier });
|
|
2164
2226
|
if (context) context.codexSessionKey = codexSessionKey(body);
|
|
2165
2227
|
return { body };
|
|
2166
2228
|
}
|
|
@@ -2534,9 +2596,8 @@ function registerCodexAdminRoutes(app, deps) {
|
|
|
2534
2596
|
err.statusCode = 403;
|
|
2535
2597
|
throw err;
|
|
2536
2598
|
};
|
|
2537
|
-
const
|
|
2538
|
-
|
|
2539
|
-
if (!isLoopback) deny();
|
|
2599
|
+
const isLoopback = (ip) => ip === "127.0.0.1" || ip === "::1" || ip === "::ffff:127.0.0.1";
|
|
2600
|
+
if (!isLoopback(req.raw?.socket?.remoteAddress) || !isLoopback(req.ip)) deny();
|
|
2540
2601
|
const origin = req.headers?.origin;
|
|
2541
2602
|
let host = "";
|
|
2542
2603
|
try {
|
|
@@ -2606,6 +2667,28 @@ function registerCodexAdminRoutes(app, deps) {
|
|
|
2606
2667
|
reply.status(422);
|
|
2607
2668
|
return { ok: false, success: false, error: "codex_login_state_rejected" };
|
|
2608
2669
|
}
|
|
2670
|
+
app.get("/api/codex/service-tier", async (req, reply) => {
|
|
2671
|
+
try {
|
|
2672
|
+
assertLocalCodexRequest(req);
|
|
2673
|
+
return { tier: deps.serviceTier.tier };
|
|
2674
|
+
} catch (error) {
|
|
2675
|
+
return codexRouteError(error, reply, "service-tier", "codex_request_failed");
|
|
2676
|
+
}
|
|
2677
|
+
});
|
|
2678
|
+
app.put("/api/codex/service-tier", async (req, reply) => {
|
|
2679
|
+
try {
|
|
2680
|
+
assertLocalCodexRequest(req);
|
|
2681
|
+
if (req.headers["content-type"]?.split(";", 1)[0].trim().toLowerCase() !== "application/json" || !isCodexServiceTierSetting(req.body)) {
|
|
2682
|
+
reply.status(422);
|
|
2683
|
+
return { ok: false, success: false, error: "codex_service_tier_invalid" };
|
|
2684
|
+
}
|
|
2685
|
+
const { tier } = req.body;
|
|
2686
|
+
await deps.serviceTier.set(tier);
|
|
2687
|
+
return { tier };
|
|
2688
|
+
} catch (error) {
|
|
2689
|
+
return codexRouteError(error, reply, "service-tier", "codex_config_write_failed");
|
|
2690
|
+
}
|
|
2691
|
+
});
|
|
2609
2692
|
app.get("/api/codex/status", async (req, reply) => {
|
|
2610
2693
|
try {
|
|
2611
2694
|
assertLocalCodexRequest(req);
|
|
@@ -3085,7 +3168,7 @@ function replaceCodexTokenMaintenance(next) {
|
|
|
3085
3168
|
// src/plugin.ts
|
|
3086
3169
|
var manifest = {
|
|
3087
3170
|
name: "codex",
|
|
3088
|
-
version: "1.0.
|
|
3171
|
+
version: "1.0.16",
|
|
3089
3172
|
coreApi: "1",
|
|
3090
3173
|
description: "Codex subscription managed provider: chatgpt.com backend-api/codex data plane, browser OAuth login (PKCE, loopback 1455/1457 + paste), model sync, usage and admin routes."
|
|
3091
3174
|
};
|
|
@@ -3099,9 +3182,10 @@ async function activate(ctx) {
|
|
|
3099
3182
|
host: upstreamHost,
|
|
3100
3183
|
logger: ctx.log
|
|
3101
3184
|
});
|
|
3185
|
+
const serviceTier = await CodexServiceTierStore.load(ctx.host.configDir, ctx.log);
|
|
3102
3186
|
class ActivatedCodexTransformer extends CodexTransformer {
|
|
3103
3187
|
constructor() {
|
|
3104
|
-
super({ service, logger: ctx.log });
|
|
3188
|
+
super({ service, logger: ctx.log, getServiceTier: () => serviceTier.tier });
|
|
3105
3189
|
}
|
|
3106
3190
|
}
|
|
3107
3191
|
const runtime = createCodexManagedRuntime({ service, host: upstreamHost, log: ctx.log });
|
|
@@ -3113,7 +3197,7 @@ async function activate(ctx) {
|
|
|
3113
3197
|
replaceCodexTokenMaintenance(maintenance);
|
|
3114
3198
|
ctx.registerTransformer(ActivatedCodexTransformer);
|
|
3115
3199
|
ctx.registerManagedRuntime(runtime);
|
|
3116
|
-
ctx.registerAdminRoutes((app) => registerCodexAdminRoutes(app, { getService: () => service }));
|
|
3200
|
+
ctx.registerAdminRoutes((app) => registerCodexAdminRoutes(app, { getService: () => service, serviceTier }));
|
|
3117
3201
|
ctx.registerConfigProtector((next, prev) => protectCodexConfig(next, prev));
|
|
3118
3202
|
ctx.registerUiCard({ cardPath: "card.js" });
|
|
3119
3203
|
ctx.registerLocales(codexLocales);
|
package/dist/plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"coreApi": "1",
|
|
5
5
|
"description": "Codex subscription managed provider: chatgpt.com backend-api/codex data plane, browser OAuth login (PKCE, loopback 1455/1457 + paste), model sync, usage and admin routes."
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wengine-ai/ccr-provider-codex",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "Codex subscription provider plugin for claude-code-router: browser OAuth login, fixed-origin responses data plane, transformer, managed runtime, admin routes, config protector and UI card.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.js",
|