opencode-aicodewith-auth 0.1.10 → 0.1.12
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 -6
- package/dist/lib/constants.d.ts +2 -1
- package/dist/lib/logger.d.ts +12 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -68,13 +68,14 @@ var PLUGIN_NAME = "opencode-aicodewith-auth";
|
|
|
68
68
|
var PROVIDER_ID = "aicodewith";
|
|
69
69
|
var AUTH_METHOD_LABEL = "AICodewith API Key";
|
|
70
70
|
var CODEX_BASE_URL = "https://api.aicodewith.com/chatgpt/v1";
|
|
71
|
-
var AICODEWITH_ANTHROPIC_BASE_URL = "https://api.aicodewith.com";
|
|
71
|
+
var AICODEWITH_ANTHROPIC_BASE_URL = "https://api.aicodewith.com/v1";
|
|
72
72
|
var AICODEWITH_GEMINI_BASE_URL = "https://api.aicodewith.com/gemini_cli";
|
|
73
73
|
var GEMINI_USER_AGENT = "GeminiCLI/v25.2.1 (darwin; arm64)";
|
|
74
74
|
var GEMINI_API_CLIENT = "google-genai-sdk/1.30.0 gl-node/v25.2.1";
|
|
75
75
|
var GEMINI_PRIVILEGED_USER_ID_ENV = "AICODEWITH_GEMINI_USER_ID";
|
|
76
76
|
var USER_AGENT = "codex_cli_rs/0.77.0 (Mac OS 26.2.0; arm64) iTerm.app/3.6.6";
|
|
77
77
|
var ORIGINATOR = "codex_cli_rs";
|
|
78
|
+
var SAVE_RAW_RESPONSE_ENV = "SAVE_RAW_RESPONSE";
|
|
78
79
|
var HEADER_NAMES = {
|
|
79
80
|
AUTHORIZATION: "authorization",
|
|
80
81
|
ORIGINATOR: "originator",
|
|
@@ -93,16 +94,21 @@ var HEADER_NAMES = {
|
|
|
93
94
|
// lib/logger.ts
|
|
94
95
|
import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
95
96
|
import { join } from "path";
|
|
96
|
-
import { homedir } from "os";
|
|
97
|
+
import { homedir, tmpdir } from "os";
|
|
97
98
|
var LOGGING_ENABLED = process.env.ENABLE_PLUGIN_REQUEST_LOGGING === "1";
|
|
98
99
|
var DEBUG_ENABLED = process.env.DEBUG_CODEX_PLUGIN === "1" || LOGGING_ENABLED;
|
|
100
|
+
var SAVE_RAW_RESPONSE_ENABLED = process.env[SAVE_RAW_RESPONSE_ENV] === "1";
|
|
99
101
|
var LOG_DIR = join(homedir(), ".opencode", "logs", PLUGIN_NAME);
|
|
102
|
+
var RAW_RESPONSE_DIR = join(tmpdir(), PLUGIN_NAME, "raw-responses");
|
|
100
103
|
if (LOGGING_ENABLED) {
|
|
101
104
|
console.log(`[${PLUGIN_NAME}] Request logging ENABLED - logs will be saved to:`, LOG_DIR);
|
|
102
105
|
}
|
|
103
106
|
if (DEBUG_ENABLED && !LOGGING_ENABLED) {
|
|
104
107
|
console.log(`[${PLUGIN_NAME}] Debug logging ENABLED`);
|
|
105
108
|
}
|
|
109
|
+
if (SAVE_RAW_RESPONSE_ENABLED) {
|
|
110
|
+
console.log(`[${PLUGIN_NAME}] Raw response saving ENABLED - responses will be saved to:`, RAW_RESPONSE_DIR);
|
|
111
|
+
}
|
|
106
112
|
var requestCounter = 0;
|
|
107
113
|
function logRequest(stage, data) {
|
|
108
114
|
if (!LOGGING_ENABLED)
|
|
@@ -144,6 +150,31 @@ function logWarn(message, data) {
|
|
|
144
150
|
console.warn(`[${PLUGIN_NAME}] ${message}`);
|
|
145
151
|
}
|
|
146
152
|
}
|
|
153
|
+
var rawResponseCounter = 0;
|
|
154
|
+
function saveRawResponse(provider, responseBody, metadata) {
|
|
155
|
+
if (!SAVE_RAW_RESPONSE_ENABLED)
|
|
156
|
+
return;
|
|
157
|
+
if (!existsSync(RAW_RESPONSE_DIR)) {
|
|
158
|
+
mkdirSync(RAW_RESPONSE_DIR, { recursive: true });
|
|
159
|
+
}
|
|
160
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
161
|
+
const responseId = ++rawResponseCounter;
|
|
162
|
+
const filename = join(RAW_RESPONSE_DIR, `${provider}-${timestamp}-${responseId}.json`);
|
|
163
|
+
try {
|
|
164
|
+
const content = {
|
|
165
|
+
timestamp: new Date().toISOString(),
|
|
166
|
+
responseId,
|
|
167
|
+
provider,
|
|
168
|
+
...metadata,
|
|
169
|
+
body: responseBody
|
|
170
|
+
};
|
|
171
|
+
writeFileSync(filename, JSON.stringify(content, null, 2), "utf8");
|
|
172
|
+
console.log(`[${PLUGIN_NAME}] Saved raw response to ${filename}`);
|
|
173
|
+
} catch (e) {
|
|
174
|
+
const error = e;
|
|
175
|
+
console.error(`[${PLUGIN_NAME}] Failed to save raw response:`, error.message);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
147
178
|
|
|
148
179
|
// lib/prompts/codex.ts
|
|
149
180
|
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "fs";
|
|
@@ -822,7 +853,6 @@ async function transformRequestBody(body, codexInstructions) {
|
|
|
822
853
|
hasTools: !!body.tools
|
|
823
854
|
});
|
|
824
855
|
body.model = normalizedModel;
|
|
825
|
-
body.store = false;
|
|
826
856
|
body.stream = true;
|
|
827
857
|
body.instructions = codexInstructions;
|
|
828
858
|
if (body.input && Array.isArray(body.input)) {
|
|
@@ -1624,6 +1654,14 @@ var isGeminiUrl = (url) => url.includes(":generateContent") || url.includes(":st
|
|
|
1624
1654
|
var isClaudeUrl = (url) => url.includes("/v1/messages");
|
|
1625
1655
|
var isModel = (model, prefix) => Boolean(model && model.startsWith(prefix));
|
|
1626
1656
|
var isCodexModel = (model) => Boolean(model && CODEX_MODEL_PREFIXES.some((prefix) => model.startsWith(prefix)));
|
|
1657
|
+
var saveResponseIfEnabled = async (response, provider, metadata) => {
|
|
1658
|
+
if (!SAVE_RAW_RESPONSE_ENABLED)
|
|
1659
|
+
return response;
|
|
1660
|
+
const cloned = response.clone();
|
|
1661
|
+
const body = await cloned.text();
|
|
1662
|
+
saveRawResponse(provider, body, { url: metadata.url, status: response.status, model: metadata.model });
|
|
1663
|
+
return response;
|
|
1664
|
+
};
|
|
1627
1665
|
var rewriteUrl = (originalUrl, baseUrl) => {
|
|
1628
1666
|
const base = new URL(baseUrl);
|
|
1629
1667
|
const original = new URL(originalUrl);
|
|
@@ -1636,7 +1674,11 @@ var rewriteUrl = (originalUrl, baseUrl) => {
|
|
|
1636
1674
|
const rewritten = new URL(original.toString());
|
|
1637
1675
|
rewritten.protocol = base.protocol;
|
|
1638
1676
|
rewritten.host = base.host;
|
|
1639
|
-
|
|
1677
|
+
let targetPath = original.pathname;
|
|
1678
|
+
if (basePath.endsWith("/v1") && targetPath.startsWith("/v1/")) {
|
|
1679
|
+
targetPath = targetPath.slice(3);
|
|
1680
|
+
}
|
|
1681
|
+
rewritten.pathname = `${basePath}${targetPath}`;
|
|
1640
1682
|
return rewritten.toString();
|
|
1641
1683
|
};
|
|
1642
1684
|
var ensureGeminiSseParam = (url) => {
|
|
@@ -1726,6 +1768,7 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1726
1768
|
...requestInit,
|
|
1727
1769
|
headers
|
|
1728
1770
|
});
|
|
1771
|
+
await saveResponseIfEnabled(response.clone(), "codex", { url: targetUrl, model });
|
|
1729
1772
|
if (!response.ok) {
|
|
1730
1773
|
return await handleErrorResponse(response);
|
|
1731
1774
|
}
|
|
@@ -1735,11 +1778,13 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1735
1778
|
const geminiUrl = buildGeminiUrl(originalUrl, isGeminiStreaming);
|
|
1736
1779
|
const headers = createGeminiHeaders(init, apiKey);
|
|
1737
1780
|
const requestInit = { ...init, headers };
|
|
1738
|
-
|
|
1781
|
+
const response = await fetch(geminiUrl, requestInit);
|
|
1782
|
+
return await saveResponseIfEnabled(response, "gemini", { url: geminiUrl, model });
|
|
1739
1783
|
}
|
|
1740
1784
|
if (isClaudeRequest) {
|
|
1741
1785
|
const targetUrl = rewriteUrl(originalUrl, AICODEWITH_ANTHROPIC_BASE_URL);
|
|
1742
|
-
|
|
1786
|
+
const response = await fetch(targetUrl, init);
|
|
1787
|
+
return await saveResponseIfEnabled(response, "claude", { url: targetUrl, model });
|
|
1743
1788
|
}
|
|
1744
1789
|
return await fetch(originalUrl, init);
|
|
1745
1790
|
}
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -10,13 +10,14 @@ export declare const PLUGIN_NAME = "opencode-aicodewith-auth";
|
|
|
10
10
|
export declare const PROVIDER_ID = "aicodewith";
|
|
11
11
|
export declare const AUTH_METHOD_LABEL = "AICodewith API Key";
|
|
12
12
|
export declare const CODEX_BASE_URL = "https://api.aicodewith.com/chatgpt/v1";
|
|
13
|
-
export declare const AICODEWITH_ANTHROPIC_BASE_URL = "https://api.aicodewith.com";
|
|
13
|
+
export declare const AICODEWITH_ANTHROPIC_BASE_URL = "https://api.aicodewith.com/v1";
|
|
14
14
|
export declare const AICODEWITH_GEMINI_BASE_URL = "https://api.aicodewith.com/gemini_cli";
|
|
15
15
|
export declare const GEMINI_USER_AGENT = "GeminiCLI/v25.2.1 (darwin; arm64)";
|
|
16
16
|
export declare const GEMINI_API_CLIENT = "google-genai-sdk/1.30.0 gl-node/v25.2.1";
|
|
17
17
|
export declare const GEMINI_PRIVILEGED_USER_ID_ENV = "AICODEWITH_GEMINI_USER_ID";
|
|
18
18
|
export declare const USER_AGENT = "codex_cli_rs/0.77.0 (Mac OS 26.2.0; arm64) iTerm.app/3.6.6";
|
|
19
19
|
export declare const ORIGINATOR = "codex_cli_rs";
|
|
20
|
+
export declare const SAVE_RAW_RESPONSE_ENV = "SAVE_RAW_RESPONSE";
|
|
20
21
|
export declare const HEADER_NAMES: {
|
|
21
22
|
readonly AUTHORIZATION: "authorization";
|
|
22
23
|
readonly ORIGINATOR: "originator";
|
package/dist/lib/logger.d.ts
CHANGED
|
@@ -8,6 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const LOGGING_ENABLED: boolean;
|
|
10
10
|
export declare const DEBUG_ENABLED: boolean;
|
|
11
|
+
export declare const SAVE_RAW_RESPONSE_ENABLED: boolean;
|
|
11
12
|
export declare function logRequest(stage: string, data: Record<string, unknown>): void;
|
|
12
13
|
export declare function logDebug(message: string, data?: unknown): void;
|
|
13
14
|
export declare function logWarn(message: string, data?: unknown): void;
|
|
15
|
+
/**
|
|
16
|
+
* Save raw response to temp directory
|
|
17
|
+
* @param provider - Provider name (codex, claude, gemini)
|
|
18
|
+
* @param responseBody - Raw response body string
|
|
19
|
+
* @param metadata - Optional metadata (url, status, etc.)
|
|
20
|
+
*/
|
|
21
|
+
export declare function saveRawResponse(provider: string, responseBody: string, metadata?: {
|
|
22
|
+
url?: string;
|
|
23
|
+
status?: number;
|
|
24
|
+
model?: string;
|
|
25
|
+
}): void;
|
package/package.json
CHANGED