MCPcopy Index your code
hub / github.com/anus-dev/ANUS / LoggingContentGenerator

Class LoggingContentGenerator

packages/core/src/core/loggingContentGenerator.ts:48–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 * A decorator that wraps a ContentGenerator to add logging to API calls.
47 */
48export class LoggingContentGenerator implements ContentGenerator {
49 constructor(
50 private readonly wrapped: ContentGenerator,
51 private readonly config: Config,
52 ) {}
53
54 private logApiRequest(
55 contents: Content[],
56 model: string,
57 promptId: string,
58 ): void {
59 const requestText = JSON.stringify(contents);
60 logApiRequest(
61 this.config,
62 new ApiRequestEvent(model, promptId, requestText),
63 );
64 }
65
66 private _logApiResponse(
67 durationMs: number,
68 prompt_id: string,
69 usageMetadata?: GenerateContentResponseUsageMetadata,
70 responseText?: string,
71 ): void {
72 logApiResponse(
73 this.config,
74 new ApiResponseEvent(
75 this.config.getModel(),
76 durationMs,
77 prompt_id,
78 this.config.getContentGeneratorConfig()?.authType,
79 usageMetadata,
80 responseText,
81 ),
82 );
83 }
84
85 private _logApiError(
86 durationMs: number,
87 error: unknown,
88 prompt_id: string,
89 ): void {
90 const errorMessage = error instanceof Error ? error.message : String(error);
91 const errorType = error instanceof Error ? error.name : 'unknown';
92
93 logApiError(
94 this.config,
95 new ApiErrorEvent(
96 this.config.getModel(),
97 errorMessage,
98 durationMs,
99 prompt_id,
100 this.config.getContentGeneratorConfig()?.authType,
101 errorType,
102 isStructuredError(error)
103 ? (error as StructuredError).status
104 : undefined,
105 ),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected