opencode-claude-code-wrapper 0.0.4 → 0.0.6

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.
Files changed (2) hide show
  1. package/index.mjs +48 -0
  2. 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,33 @@ 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
+ // Save requests with tools to a separate file
284
+ if (requestBody.tools?.length > 0) {
285
+ writeFileSync(
286
+ join(METRICS_DIR, "last_request_with_tools.json"),
287
+ JSON.stringify(requestBody, null, 2)
288
+ );
289
+ }
290
+ writeFileSync(
291
+ join(METRICS_DIR, "last_request.json"),
292
+ JSON.stringify(requestBody, null, 2)
293
+ );
294
+ } catch (e) {}
295
+
248
296
  const isStreaming = requestBody.stream === true;
249
297
  const cliArgs = transformRequestToCLIArgs(requestBody);
250
298
  const child = spawnClaudeCode(cliArgs, { streaming: isStreaming });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-claude-code-wrapper",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "OpenCode plugin that wraps Claude Code CLI for API-like access",
5
5
  "main": "./index.mjs",
6
6
  "type": "module",