xonecas.io
64875
Mc

mini-coder / commit 174f808

fix(logging): drastically reduce log noise

Remove stream chunk logging for all but tool-call and tool-result events.
Remove prompt caching configured event (low value).
Remove Provider Request fetch interceptor entirely — was logging full
message history to the DB on every request (massive data, privacy risk).

Expected: ~10 rows/turn instead of 186.

xonecas2026-03-21 174f80843cabaefe32025cadcd4e69d9f0338762 parent ecf92fb

2 files changed

src/llm-api/providers.ts+9−56
@@ -3,7 +3,6 @@ import { createGoogleGenerativeAI } from "@ai-sdk/google";
33 import { createOpenAI } from "@ai-sdk/openai";
44 import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
55 import type { LanguageModel } from "ai";
6-import { logApiEvent } from "../logging/context.ts";
76 import { getAccessToken, isLoggedIn } from "../session/oauth/auth-storage.ts";
87 import {
98 type AvailableModelsSnapshot,
@@ -33,56 +32,10 @@ type GoogleProvider = ReturnType<typeof createGoogleGenerativeAI>;
3332 type OpenAICompatProvider = ReturnType<typeof createOpenAICompatible>;
3433 type ModelResolver = (modelId: string) => LanguageModel;
3534
36-const REDACTED_HEADERS = new Set(["authorization", "x-api-key"]);
37-
38-function redactHeaders(
39- headers: RequestInit["headers"],
40-): Record<string, string> | undefined {
41- if (!headers) return undefined;
42- const h = new Headers(headers as ConstructorParameters<typeof Headers>[0]);
43- const out: Record<string, string> = {};
44- h.forEach((v, k) => {
45- out[k] = REDACTED_HEADERS.has(k) ? "[REDACTED]" : v;
46- });
47- return out;
48-}
49-
50-function createFetchWithLogging(): ProviderFetch {
51- const customFetch = async (
52- input: Parameters<ProviderFetch>[0],
53- init?: Parameters<ProviderFetch>[1],
54- ): Promise<Response> => {
55- if (init?.body) {
56- try {
57- const bodyStr = init.body.toString();
58- const bodyJson = JSON.parse(bodyStr);
59- logApiEvent("Provider Request", {
60- url: input.toString(),
61- method: init.method,
62- headers: redactHeaders(init.headers),
63- body: bodyJson,
64- });
65- } catch {
66- logApiEvent("Provider Request", {
67- url: input.toString(),
68- method: init.method,
69- headers: redactHeaders(init.headers),
70- body: init.body,
71- });
72- }
73- }
74- return fetch(input, init);
75- };
76- return customFetch as ProviderFetch;
77-}
78-
79-const fetchWithLogging = createFetchWithLogging();
80-
8135 /** Betas the AI SDK adds that are not compatible with the OAuth endpoint. */
8236 const OAUTH_STRIP_BETAS = new Set<string>();
8337
8438 function createOAuthFetch(accessToken: string): ProviderFetch {
85- const baseFetch = createFetchWithLogging();
8639 const oauthFetch = async (
8740 input: Parameters<ProviderFetch>[0],
8841 init?: Parameters<ProviderFetch>[1],
@@ -106,7 +59,7 @@ function createOAuthFetch(accessToken: string): ProviderFetch {
10659 h.set("x-app", "cli");
10760 opts = { ...opts, headers: Object.fromEntries(h.entries()) };
10861 }
109- return baseFetch(input, opts);
62+ return fetch(input, opts);
11063 };
11164 return oauthFetch as ProviderFetch;
11265 }
@@ -138,28 +91,28 @@ function lazy<T>(factory: () => T): () => T {
13891 const zenProviders = {
13992 anthropic: lazy<AnthropicProvider>(() =>
14093 createAnthropic({
141- fetch: fetchWithLogging,
94+ fetch,
14295 apiKey: requireEnv("OPENCODE_API_KEY"),
14396 baseURL: ZEN_BASE,
14497 }),
14598 ),
14699 openai: lazy<OpenAIProvider>(() =>
147100 createOpenAI({
148- fetch: fetchWithLogging,
101+ fetch,
149102 apiKey: requireEnv("OPENCODE_API_KEY"),
150103 baseURL: ZEN_BASE,
151104 }),
152105 ),
153106 google: lazy<GoogleProvider>(() =>
154107 createGoogleGenerativeAI({
155- fetch: fetchWithLogging,
108+ fetch,
156109 apiKey: requireEnv("OPENCODE_API_KEY"),
157110 baseURL: ZEN_BASE,
158111 }),
159112 ),
160113 compat: lazy<OpenAICompatProvider>(() =>
161114 createOpenAICompatible({
162- fetch: fetchWithLogging,
115+ fetch,
163116 name: "zen-compat",
164117 apiKey: requireEnv("OPENCODE_API_KEY"),
165118 baseURL: ZEN_BASE,
@@ -170,19 +123,19 @@ const zenProviders = {
170123 const directProviders = {
171124 anthropic: lazy<AnthropicProvider>(() =>
172125 createAnthropic({
173- fetch: fetchWithLogging,
126+ fetch,
174127 apiKey: requireEnv("ANTHROPIC_API_KEY"),
175128 }),
176129 ),
177130 openai: lazy<OpenAIProvider>(() =>
178131 createOpenAI({
179- fetch: fetchWithLogging,
132+ fetch,
180133 apiKey: requireEnv("OPENAI_API_KEY"),
181134 }),
182135 ),
183136 google: lazy<GoogleProvider>(() =>
184137 createGoogleGenerativeAI({
185- fetch: fetchWithLogging,
138+ fetch,
186139 apiKey: requireAnyEnv(["GOOGLE_API_KEY", "GEMINI_API_KEY"]),
187140 }),
188141 ),
@@ -192,7 +145,7 @@ const directProviders = {
192145 name: "ollama",
193146 baseURL: `${baseURL}/v1`,
194147 apiKey: "ollama",
195- fetch: fetchWithLogging,
148+ fetch,
196149 });
197150 }),
198151 };
src/llm-api/turn.ts+12−15
@@ -1,5 +1,5 @@
11 import { streamText } from "ai";
2-import { getLogContext, logApiEvent } from "../logging/context.ts";
2+import { logApiEvent } from "../logging/context.ts";
33 import { normalizeUnknownError } from "./error-utils.ts";
44 import type { ThinkingEffort } from "./provider-options.ts";
55 import {
@@ -90,12 +90,6 @@ export async function* runTurn(options: {
9090 };
9191 }
9292
93- if (getLogContext() !== null) {
94- logApiEvent("prompt caching configured", {
95- cacheFamily: providerOptionsResult.cacheFamily,
96- });
97- }
98-
9993 const stepPruneQueue: StepPruneRecord[] = [];
10094
10195 const result = streamText(
@@ -115,14 +109,17 @@ export async function* runTurn(options: {
115109 for await (const event of mapFullStreamToTurnEvents(result.fullStream, {
116110 stepPruneQueue,
117111 onChunk: (streamChunk) => {
118- logApiEvent("stream chunk", {
119- type: streamChunk.type,
120- toolCallId: streamChunk.toolCallId,
121- toolName: streamChunk.toolName,
122- isError: streamChunk.isError,
123- hasArgs: "args" in streamChunk || "input" in streamChunk,
124- hasOutput: "output" in streamChunk || "result" in streamChunk,
125- });
112+ if (
113+ streamChunk.type === "tool-call" ||
114+ streamChunk.type === "tool-result"
115+ ) {
116+ logApiEvent("stream chunk", {
117+ type: streamChunk.type,
118+ toolCallId: streamChunk.toolCallId,
119+ toolName: streamChunk.toolName,
120+ isError: streamChunk.isError,
121+ });
122+ }
126123 },
127124 })) {
128125 yield event;