opencode-aicodewith-auth 0.1.50 → 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 +51 -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",
|
|
@@ -768,6 +764,8 @@ async function transformRequestBody(body, codexInstructions) {
|
|
|
768
764
|
body.model = normalizedModel;
|
|
769
765
|
body.stream = true;
|
|
770
766
|
body.store = false;
|
|
767
|
+
delete body.previousResponseId;
|
|
768
|
+
delete body.previous_response_id;
|
|
771
769
|
body.instructions = codexInstructions;
|
|
772
770
|
if (body.input && Array.isArray(body.input)) {
|
|
773
771
|
body.input = sanitizeItemIds(body.input);
|
|
@@ -860,12 +858,23 @@ function ensureContentType(headers) {
|
|
|
860
858
|
}
|
|
861
859
|
|
|
862
860
|
// lib/request/fetch-helpers.ts
|
|
863
|
-
function
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
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
|
+
}
|
|
869
878
|
}
|
|
870
879
|
async function transformRequestForCodex(init) {
|
|
871
880
|
if (!init?.body || typeof init.body !== "string")
|
|
@@ -884,29 +893,36 @@ async function transformRequestForCodex(init) {
|
|
|
884
893
|
body: transformedBody,
|
|
885
894
|
updatedInit: { ...init, body: JSON.stringify(transformedBody) }
|
|
886
895
|
};
|
|
887
|
-
} catch {
|
|
888
|
-
|
|
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
|
+
};
|
|
889
905
|
}
|
|
890
906
|
}
|
|
891
907
|
function createAicodewithHeaders(init, apiKey, opts) {
|
|
892
908
|
const headers = new Headers(init?.headers ?? {});
|
|
893
|
-
headers.delete(
|
|
894
|
-
headers.delete(
|
|
909
|
+
headers.delete(HEADER_NAMES2.OPENAI_BETA);
|
|
910
|
+
headers.delete(HEADER_NAMES2.CHATGPT_ACCOUNT_ID);
|
|
895
911
|
headers.delete("x-api-key");
|
|
896
|
-
headers.set(
|
|
897
|
-
headers.set(
|
|
898
|
-
headers.set(
|
|
899
|
-
headers.set(
|
|
900
|
-
if (!headers.has(
|
|
901
|
-
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");
|
|
902
918
|
}
|
|
903
919
|
const cacheKey = opts?.promptCacheKey;
|
|
904
920
|
if (cacheKey) {
|
|
905
|
-
headers.set(
|
|
906
|
-
headers.set(
|
|
921
|
+
headers.set(HEADER_NAMES2.CONVERSATION_ID, cacheKey);
|
|
922
|
+
headers.set(HEADER_NAMES2.SESSION_ID, cacheKey);
|
|
907
923
|
} else {
|
|
908
|
-
headers.delete(
|
|
909
|
-
headers.delete(
|
|
924
|
+
headers.delete(HEADER_NAMES2.CONVERSATION_ID);
|
|
925
|
+
headers.delete(HEADER_NAMES2.SESSION_ID);
|
|
910
926
|
}
|
|
911
927
|
return headers;
|
|
912
928
|
}
|
|
@@ -1554,14 +1570,14 @@ var syncAgentsAndCategories = (userConfig, defaultConfig) => {
|
|
|
1554
1570
|
userConfig.categories = {};
|
|
1555
1571
|
}
|
|
1556
1572
|
for (const agent of Object.values(userConfig.agents)) {
|
|
1557
|
-
if (agent.model &&
|
|
1558
|
-
agent.model =
|
|
1573
|
+
if (agent.model && MODEL_MIGRATIONS2[agent.model]) {
|
|
1574
|
+
agent.model = MODEL_MIGRATIONS2[agent.model];
|
|
1559
1575
|
changed = true;
|
|
1560
1576
|
}
|
|
1561
1577
|
}
|
|
1562
1578
|
for (const category of Object.values(userConfig.categories)) {
|
|
1563
|
-
if (category.model &&
|
|
1564
|
-
category.model =
|
|
1579
|
+
if (category.model && MODEL_MIGRATIONS2[category.model]) {
|
|
1580
|
+
category.model = MODEL_MIGRATIONS2[category.model];
|
|
1565
1581
|
changed = true;
|
|
1566
1582
|
}
|
|
1567
1583
|
}
|
|
@@ -1974,7 +1990,11 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1974
1990
|
const isCodexRequest = !isClaudeRequest && !isGeminiRequest && isCodexModel(model);
|
|
1975
1991
|
if (isCodexRequest) {
|
|
1976
1992
|
const transformation = await transformRequestForCodex(init);
|
|
1977
|
-
|
|
1993
|
+
let requestInit = transformation?.updatedInit ?? init;
|
|
1994
|
+
if (!transformation && init.body) {
|
|
1995
|
+
const sanitized = sanitizeRequestBody(init.body);
|
|
1996
|
+
requestInit = { ...init, body: sanitized };
|
|
1997
|
+
}
|
|
1978
1998
|
const headers = createAicodewithHeaders(requestInit, apiKey, {
|
|
1979
1999
|
promptCacheKey: transformation?.body.prompt_cache_key
|
|
1980
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",
|