summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-08-29 15:39:56 -0500
committerJeff Carr <[email protected]>2025-08-29 15:39:56 -0500
commitd021fcadadd100c11953d894de19f545626df618 (patch)
tree23958c428bb6b358d495190f9d3be5d9f3e5b7d7
parent148201b5c53a14f88b2032090f38976b5e7f29e2 (diff)
writes the JSON to files in /tmp/
-rw-r--r--packages/core/src/core/loggingContentGenerator.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/packages/core/src/core/loggingContentGenerator.ts b/packages/core/src/core/loggingContentGenerator.ts
index 2abe3dce..c4b89115 100644
--- a/packages/core/src/core/loggingContentGenerator.ts
+++ b/packages/core/src/core/loggingContentGenerator.ts
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import * as fs from 'fs';
+import * as path from 'path';
import {
Content,
CountTokensParameters,
@@ -37,6 +39,8 @@ interface StructuredError {
* A decorator that wraps a ContentGenerator to add logging to API calls.
*/
export class LoggingContentGenerator implements ContentGenerator {
+ private requestCounter = 1;
+
constructor(
private readonly wrapped: ContentGenerator,
private readonly config: Config,
@@ -108,6 +112,12 @@ export class LoggingContentGenerator implements ContentGenerator {
const startTime = Date.now();
this.logApiRequest(toContents(req.contents), req.model, userPromptId);
try {
+ const sessionId = this.config.getSessionId();
+ const fileName = `${sessionId}.gemini-api-request.${this.requestCounter}.json`;
+ const filePath = path.join('/tmp', fileName);
+ const jsonPayload = JSON.stringify(req, null, 2);
+ fs.writeFileSync(filePath, jsonPayload);
+ this.requestCounter++;
const response = await this.wrapped.generateContent(req, userPromptId);
const durationMs = Date.now() - startTime;
this._logApiResponse(
@@ -131,6 +141,12 @@ export class LoggingContentGenerator implements ContentGenerator {
const startTime = Date.now();
this.logApiRequest(toContents(req.contents), req.model, userPromptId);
+ const sessionId = this.config.getSessionId();
+ const fileName = `${sessionId}.gemini-api-request.${this.requestCounter}.json`;
+ const filePath = path.join('/tmp', fileName);
+ const jsonPayload = JSON.stringify(req, null, 2);
+ fs.writeFileSync(filePath, jsonPayload);
+ this.requestCounter++;
let stream: AsyncGenerator<GenerateContentResponse>;
try {
stream = await this.wrapped.generateContentStream(req, userPromptId);