opencode-aicodewith-auth 0.1.8 → 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
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";
|
|
@@ -1309,6 +1340,7 @@ function invalidatePackage(packageName = PACKAGE_NAME) {
|
|
|
1309
1340
|
// lib/hooks/auto-update/index.ts
|
|
1310
1341
|
var DISPLAY_NAME = "AICodewith";
|
|
1311
1342
|
var SPINNER_FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1343
|
+
var STARTUP_TOAST_DELAY = 6000;
|
|
1312
1344
|
function createAutoUpdateHook(ctx, options = {}) {
|
|
1313
1345
|
const { autoUpdate = true, showStartupToast = true } = options;
|
|
1314
1346
|
let hasChecked = false;
|
|
@@ -1327,13 +1359,17 @@ function createAutoUpdateHook(ctx, options = {}) {
|
|
|
1327
1359
|
const displayVersion = localDevVersion ?? cachedVersion ?? "unknown";
|
|
1328
1360
|
if (localDevVersion) {
|
|
1329
1361
|
if (showStartupToast) {
|
|
1330
|
-
|
|
1362
|
+
setTimeout(() => {
|
|
1363
|
+
showStartupToastWithSpinner(ctx, `${displayVersion} (dev)`, "Local development mode").catch(() => {});
|
|
1364
|
+
}, STARTUP_TOAST_DELAY);
|
|
1331
1365
|
}
|
|
1332
1366
|
log("Local development mode, skipping update check");
|
|
1333
1367
|
return;
|
|
1334
1368
|
}
|
|
1335
1369
|
if (showStartupToast) {
|
|
1336
|
-
|
|
1370
|
+
setTimeout(() => {
|
|
1371
|
+
showStartupToastWithSpinner(ctx, displayVersion, "GPT-5.2 \xB7 Claude \xB7 Gemini").catch(() => {});
|
|
1372
|
+
}, STARTUP_TOAST_DELAY);
|
|
1337
1373
|
}
|
|
1338
1374
|
runBackgroundUpdateCheck(ctx, autoUpdate).catch((err) => {
|
|
1339
1375
|
log("Background update check failed:", err);
|
|
@@ -1619,6 +1655,14 @@ var isGeminiUrl = (url) => url.includes(":generateContent") || url.includes(":st
|
|
|
1619
1655
|
var isClaudeUrl = (url) => url.includes("/v1/messages");
|
|
1620
1656
|
var isModel = (model, prefix) => Boolean(model && model.startsWith(prefix));
|
|
1621
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
|
+
};
|
|
1622
1666
|
var rewriteUrl = (originalUrl, baseUrl) => {
|
|
1623
1667
|
const base = new URL(baseUrl);
|
|
1624
1668
|
const original = new URL(originalUrl);
|
|
@@ -1721,6 +1765,7 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1721
1765
|
...requestInit,
|
|
1722
1766
|
headers
|
|
1723
1767
|
});
|
|
1768
|
+
await saveResponseIfEnabled(response.clone(), "codex", { url: targetUrl, model });
|
|
1724
1769
|
if (!response.ok) {
|
|
1725
1770
|
return await handleErrorResponse(response);
|
|
1726
1771
|
}
|
|
@@ -1730,11 +1775,13 @@ var AicodewithCodexAuthPlugin = async (ctx) => {
|
|
|
1730
1775
|
const geminiUrl = buildGeminiUrl(originalUrl, isGeminiStreaming);
|
|
1731
1776
|
const headers = createGeminiHeaders(init, apiKey);
|
|
1732
1777
|
const requestInit = { ...init, headers };
|
|
1733
|
-
|
|
1778
|
+
const response = await fetch(geminiUrl, requestInit);
|
|
1779
|
+
return await saveResponseIfEnabled(response, "gemini", { url: geminiUrl, model });
|
|
1734
1780
|
}
|
|
1735
1781
|
if (isClaudeRequest) {
|
|
1736
1782
|
const targetUrl = rewriteUrl(originalUrl, AICODEWITH_ANTHROPIC_BASE_URL);
|
|
1737
|
-
|
|
1783
|
+
const response = await fetch(targetUrl, init);
|
|
1784
|
+
return await saveResponseIfEnabled(response, "claude", { url: targetUrl, model });
|
|
1738
1785
|
}
|
|
1739
1786
|
return await fetch(originalUrl, init);
|
|
1740
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";
|
|
@@ -7,4 +7,5 @@ export declare function findPluginEntry(directory: string): PluginEntryInfo | nu
|
|
|
7
7
|
export declare function getCachedVersion(): string | null;
|
|
8
8
|
export declare function updatePinnedVersion(configPath: string, oldEntry: string, newVersion: string): boolean;
|
|
9
9
|
export declare function getLatestVersion(): Promise<string | null>;
|
|
10
|
+
export declare function hasOhMyOpencode(directory: string): boolean;
|
|
10
11
|
export { log };
|
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