Sync upstream Gemini-CLI v0.8.2 (#838)

This commit is contained in:
tanzhenxin
2025-10-23 09:27:04 +08:00
committed by GitHub
parent 096fabb5d6
commit eb95c131be
644 changed files with 70389 additions and 23709 deletions

View File

@@ -0,0 +1,39 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import stripAnsi from 'strip-ansi';
import type { SessionMetrics } from '../telemetry/uiTelemetry.js';
import type { JsonError, JsonOutput } from './types.js';
export class JsonFormatter {
format(response?: string, stats?: SessionMetrics, error?: JsonError): string {
const output: JsonOutput = {};
if (response !== undefined) {
output.response = stripAnsi(response);
}
if (stats) {
output.stats = stats;
}
if (error) {
output.error = error;
}
return JSON.stringify(output, null, 2);
}
formatError(error: Error, code?: string | number): string {
const jsonError: JsonError = {
type: error.constructor.name,
message: stripAnsi(error.message),
...(code && { code }),
};
return this.format(undefined, undefined, jsonError);
}
}