From d021fcadadd100c11953d894de19f545626df618 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Aug 2025 15:39:56 -0500 Subject: [PATCH] writes the JSON to files in /tmp/ --- .../core/src/core/loggingContentGenerator.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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; try { stream = await this.wrapped.generateContentStream(req, userPromptId);