opencode-aicodewith-auth 0.1.52 → 0.1.54
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/index.js +49 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -235,15 +235,11 @@ var AUTH_METHOD_LABEL = "AICodewith API Key";
|
|
|
235
235
|
var CODEX_BASE_URL = "https://api.aicodewith.com/chatgpt/v1";
|
|
236
236
|
var AICODEWITH_ANTHROPIC_BASE_URL = "https://api.aicodewith.com/v1";
|
|
237
237
|
var AICODEWITH_LITE_URL = "https://api.aicodewith.com/lite";
|
|
238
|
-
var AICODEWITH_GEMINI_BASE_URL = "https://api.aicodewith.com/gemini_cli";
|
|
239
|
-
var GEMINI_USER_AGENT = "GeminiCLI/v25.2.1 (darwin; arm64)";
|
|
240
|
-
var GEMINI_API_CLIENT = "google-genai-sdk/1.30.0 gl-node/v25.2.1";
|
|
241
|
-
var GEMINI_PRIVILEGED_USER_ID_ENV = "AICODEWITH_GEMINI_USER_ID";
|
|
242
238
|
var USER_AGENT = "codex_cli_rs/0.77.0 (Mac OS 26.2.0; arm64) iTerm.app/3.6.6";
|
|
243
239
|
var ORIGINATOR = "codex_cli_rs";
|
|
244
240
|
var SAVE_RAW_RESPONSE_ENV = "SAVE_RAW_RESPONSE";
|
|
245
|
-
var
|
|
246
|
-
var
|
|
241
|
+
var MODEL_MIGRATIONS2 = buildModelMigrations();
|
|
242
|
+
var HEADER_NAMES2 = {
|
|
247
243
|
AUTHORIZATION: "authorization",
|
|
248
244
|
ORIGINATOR: "originator",
|
|
249
245
|
SESSION_ID: "session_id",
|
|
@@ -862,12 +858,23 @@ function ensureContentType(headers) {
|
|
|
862
858
|
}
|
|
863
859
|
|
|
864
860
|
// lib/request/fetch-helpers.ts
|
|
865
|
-
function
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
861
|
+
function sanitizeRequestBody(bodyStr) {
|
|
862
|
+
try {
|
|
863
|
+
const body = JSON.parse(bodyStr);
|
|
864
|
+
delete body.previousResponseId;
|
|
865
|
+
delete body.previous_response_id;
|
|
866
|
+
if (Array.isArray(body.input)) {
|
|
867
|
+
body.input = body.input.filter((item) => item.type !== "item_reference").map((item) => {
|
|
868
|
+
if (item.type === "call")
|
|
869
|
+
return item;
|
|
870
|
+
const { id, ...rest } = item;
|
|
871
|
+
return rest;
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
return JSON.stringify(body);
|
|
875
|
+
} catch {
|
|
876
|
+
return bodyStr;
|
|
877
|
+
}
|
|
871
878
|
}
|
|
872
879
|
async function transformRequestForCodex(init) {
|
|
873
880
|
if (!init?.body || typeof init.body !== "string")
|
|
@@ -886,29 +893,36 @@ async function transformRequestForCodex(init) {
|
|
|
886
893
|
body: transformedBody,
|
|
887
894
|
updatedInit: { ...init, body: JSON.stringify(transformedBody) }
|
|
888
895
|
};
|
|
889
|
-
} catch {
|
|
890
|
-
|
|
896
|
+
} catch (error) {
|
|
897
|
+
logDebug("codex-transform-error", {
|
|
898
|
+
error: error instanceof Error ? error.message : String(error)
|
|
899
|
+
});
|
|
900
|
+
const sanitized = sanitizeRequestBody(init.body);
|
|
901
|
+
return {
|
|
902
|
+
body: JSON.parse(sanitized),
|
|
903
|
+
updatedInit: { ...init, body: sanitized }
|
|
904
|
+
};
|
|
891
905
|
}
|
|
892
906
|
}
|
|
893
907
|
function createAicodewithHeaders(init, apiKey, opts) {
|
|
894
908
|
const headers = new Headers(init?.headers ?? {});
|
|
895
|
-
headers.delete(
|
|
896
|
-
headers.delete(
|
|
909
|
+
headers.delete(HEADER_NAMES2.OPENAI_BETA);
|
|
910
|
+
headers.delete(HEADER_NAMES2.CHATGPT_ACCOUNT_ID);
|
|
897
911
|
headers.delete("x-api-key");
|
|
898
|
-
headers.set(
|
|
899
|
-
headers.set(
|
|
900
|
-
headers.set(
|
|
901
|
-
headers.set(
|
|
902
|
-
if (!headers.has(
|
|
903
|
-
headers.set(
|
|
912
|
+
headers.set(HEADER_NAMES2.AUTHORIZATION, `Bearer ${apiKey}`);
|
|
913
|
+
headers.set(HEADER_NAMES2.ORIGINATOR, ORIGINATOR);
|
|
914
|
+
headers.set(HEADER_NAMES2.USER_AGENT, USER_AGENT);
|
|
915
|
+
headers.set(HEADER_NAMES2.ACCEPT, "text/event-stream");
|
|
916
|
+
if (!headers.has(HEADER_NAMES2.CONTENT_TYPE)) {
|
|
917
|
+
headers.set(HEADER_NAMES2.CONTENT_TYPE, "application/json");
|
|
904
918
|
}
|
|
905
919
|
const cacheKey = opts?.promptCacheKey;
|
|
906
920
|
if (cacheKey) {
|
|
907
|
-
headers.set(
|
|
908
|
-
headers.set(
|
|
921
|
+
headers.set(HEADER_NAMES2.CONVERSATION_ID, cacheKey);
|
|
922
|
+
headers.set(HEADER_NAMES2.SESSION_ID, cacheKey);
|
|
909
923
|
} else {
|
|
910
|
-
headers.delete(
|
|
911
|
-
headers.delete(
|
|
924
|
+
headers.delete(HEADER_NAMES2.CONVERSATION_ID);
|
|
925
|
+
headers.delete(HEADER_NAMES2.SESSION_ID);
|
|
912
926
|
}
|
|
913
927
|
return headers;
|
|
914
928
|
}
|
|
@@ -1556,14 +1570,14 @@ var syncAgentsAndCategories = (userConfig, defaultConfig) => {
|
|
|
1556
1570
|
userConfig.categories = {};
|
|
1557
1571
|
}
|
|
1558
1572
|
for (const agent of Object.values(userConfig.agents)) {
|
|
1559
|
-
if (agent.model &&
|
|
1560
|
-
agent.model =
|
|
1573
|
+
if (agent.model && MODEL_MIGRATIONS2[agent.model]) {
|
|
1574
|
+
agent.model = MODEL_MIGRATIONS2[agent.model];
|
|
1561
1575
|
changed = true;
|
|
1562
1576
|
}
|
|
1563
1577
|
}
|
|
1564
1578
|
for (const category of Object.values(userConfig.categories)) {
|
|
1565
|
-
if (category.model &&
|
|
1566
|
-
category.model =
|
|
1579
|
+
if (category.model && MODEL_MIGRATIONS2[category.model]) {
|
|
1580
|
+
category.model = MODEL_MIGRATIONS2[category.model];
|
|
1567
1581
|
changed = true;
|
|
1568
1582
|
}
|
|
1569
1583
|
}
|
|
@@ -1976,7 +1990,11 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1976
1990
|
const isCodexRequest = !isClaudeRequest && !isGeminiRequest && isCodexModel(model);
|
|
1977
1991
|
if (isCodexRequest) {
|
|
1978
1992
|
const transformation = await transformRequestForCodex(init);
|
|
1979
|
-
|
|
1993
|
+
let requestInit = transformation?.updatedInit ?? init;
|
|
1994
|
+
if (!transformation && init.body) {
|
|
1995
|
+
const sanitized = sanitizeRequestBody(init.body);
|
|
1996
|
+
requestInit = { ...init, body: sanitized };
|
|
1997
|
+
}
|
|
1980
1998
|
const headers = createAicodewithHeaders(requestInit, apiKey, {
|
|
1981
1999
|
promptCacheKey: transformation?.body.prompt_cache_key
|
|
1982
2000
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-aicodewith-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54",
|
|
4
4
|
"description": "OpenCode plugin for AICodewith authentication - Access GPT-5.3 Codex, GPT-5.2, Claude, and Gemini models through AICodewith API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|