opencode-claude-code-wrapper 0.0.4 → 0.0.5
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/index.mjs +41 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { generatePKCE } from "@openauthjs/openauth/pkce";
|
|
2
|
+
import { writeFileSync, appendFileSync, mkdirSync } from "fs";
|
|
3
|
+
import { homedir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
2
5
|
import {
|
|
3
6
|
transformRequestToCLIArgs,
|
|
4
7
|
spawnClaudeCode,
|
|
@@ -210,6 +213,24 @@ async function createNonStreamingResponse(child, requestBody) {
|
|
|
210
213
|
});
|
|
211
214
|
}
|
|
212
215
|
|
|
216
|
+
// Metrics logging
|
|
217
|
+
const METRICS_DIR = join(homedir(), ".opencode-claude-code-wrapper");
|
|
218
|
+
const METRICS_FILE = join(METRICS_DIR, "metrics.jsonl");
|
|
219
|
+
|
|
220
|
+
function logMetric(type, data) {
|
|
221
|
+
try {
|
|
222
|
+
mkdirSync(METRICS_DIR, { recursive: true });
|
|
223
|
+
const entry = {
|
|
224
|
+
timestamp: new Date().toISOString(),
|
|
225
|
+
type,
|
|
226
|
+
...data,
|
|
227
|
+
};
|
|
228
|
+
appendFileSync(METRICS_FILE, JSON.stringify(entry) + "\n");
|
|
229
|
+
} catch (e) {
|
|
230
|
+
console.error("[metrics] Failed to log:", e.message);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
213
234
|
/**
|
|
214
235
|
* Handle request via Claude Code CLI
|
|
215
236
|
*/
|
|
@@ -245,6 +266,26 @@ async function handleClaudeCodeRequest(input, init) {
|
|
|
245
266
|
});
|
|
246
267
|
}
|
|
247
268
|
|
|
269
|
+
// Log the incoming request for debugging
|
|
270
|
+
logMetric("request", {
|
|
271
|
+
model: requestBody.model,
|
|
272
|
+
stream: requestBody.stream,
|
|
273
|
+
system: requestBody.system ? (typeof requestBody.system === "string" ? requestBody.system.substring(0, 200) : "[array]") : null,
|
|
274
|
+
messages_count: requestBody.messages?.length,
|
|
275
|
+
tools_count: requestBody.tools?.length,
|
|
276
|
+
tool_names: requestBody.tools?.map((t) => t.name),
|
|
277
|
+
first_message: requestBody.messages?.[0],
|
|
278
|
+
last_message: requestBody.messages?.[requestBody.messages?.length - 1],
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Log full request body to separate file for detailed inspection
|
|
282
|
+
try {
|
|
283
|
+
writeFileSync(
|
|
284
|
+
join(METRICS_DIR, "last_request.json"),
|
|
285
|
+
JSON.stringify(requestBody, null, 2)
|
|
286
|
+
);
|
|
287
|
+
} catch (e) {}
|
|
288
|
+
|
|
248
289
|
const isStreaming = requestBody.stream === true;
|
|
249
290
|
const cliArgs = transformRequestToCLIArgs(requestBody);
|
|
250
291
|
const child = spawnClaudeCode(cliArgs, { streaming: isStreaming });
|