opencode-aicodewith-auth 0.1.10 → 0.1.11
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 +45 -3
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/logger.d.ts +12 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75,6 +75,7 @@ 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";
|
|
@@ -1624,6 +1655,14 @@ var isGeminiUrl = (url) => url.includes(":generateContent") || url.includes(":st
|
|
|
1624
1655
|
var isClaudeUrl = (url) => url.includes("/v1/messages");
|
|
1625
1656
|
var isModel = (model, prefix) => Boolean(model && model.startsWith(prefix));
|
|
1626
1657
|
var isCodexModel = (model) => Boolean(model && CODEX_MODEL_PREFIXES.some((prefix) => model.startsWith(prefix)));
|
|
1658
|
+
var saveResponseIfEnabled = async (response, provider, metadata) => {
|
|
1659
|
+
if (!SAVE_RAW_RESPONSE_ENABLED)
|
|
1660
|
+
return response;
|
|
1661
|
+
const cloned = response.clone();
|
|
1662
|
+
const body = await cloned.text();
|
|
1663
|
+
saveRawResponse(provider, body, { url: metadata.url, status: response.status, model: metadata.model });
|
|
1664
|
+
return response;
|
|
1665
|
+
};
|
|
1627
1666
|
var rewriteUrl = (originalUrl, baseUrl) => {
|
|
1628
1667
|
const base = new URL(baseUrl);
|
|
1629
1668
|
const original = new URL(originalUrl);
|
|
@@ -1726,6 +1765,7 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1726
1765
|
...requestInit,
|
|
1727
1766
|
headers
|
|
1728
1767
|
});
|
|
1768
|
+
await saveResponseIfEnabled(response.clone(), "codex", { url: targetUrl, model });
|
|
1729
1769
|
if (!response.ok) {
|
|
1730
1770
|
return await handleErrorResponse(response);
|
|
1731
1771
|
}
|
|
@@ -1735,11 +1775,13 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1735
1775
|
const geminiUrl = buildGeminiUrl(originalUrl, isGeminiStreaming);
|
|
1736
1776
|
const headers = createGeminiHeaders(init, apiKey);
|
|
1737
1777
|
const requestInit = { ...init, headers };
|
|
1738
|
-
|
|
1778
|
+
const response = await fetch(geminiUrl, requestInit);
|
|
1779
|
+
return await saveResponseIfEnabled(response, "gemini", { url: geminiUrl, model });
|
|
1739
1780
|
}
|
|
1740
1781
|
if (isClaudeRequest) {
|
|
1741
1782
|
const targetUrl = rewriteUrl(originalUrl, AICODEWITH_ANTHROPIC_BASE_URL);
|
|
1742
|
-
|
|
1783
|
+
const response = await fetch(targetUrl, init);
|
|
1784
|
+
return await saveResponseIfEnabled(response, "claude", { url: targetUrl, model });
|
|
1743
1785
|
}
|
|
1744
1786
|
return await fetch(originalUrl, init);
|
|
1745
1787
|
}
|
package/dist/lib/constants.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const GEMINI_API_CLIENT = "google-genai-sdk/1.30.0 gl-node/v25.2.
|
|
|
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