xonecas.io
53129
Pa

PAT / commit ba296a1

chore: less debug

xonecas2025-12-18 ba296a137ebf22a754b0614e9c1a8395adce5651 parent 969c758

13 files changed

app/api/chat/route.ts+1−1
@@ -82,7 +82,7 @@ export async function POST(request: Request) {
8282 },
8383 });
8484 } catch (err) {
85- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
85+ debug(`[Chat API] Error:`, err instanceof Error ? err.message : "Unknown error");
8686 return NextResponse.json({ answer: "Sorry, something went wrong." }, { status: 500 });
8787 }
8888 }
app/api/models/route.ts+0−2
@@ -1,6 +1,5 @@
11 import { NextResponse } from "next/server";
22 import ollama from "ollama";
3-import { debug } from "@/src/lib/debug";
43
54 export async function GET() {
65 try {
@@ -11,7 +10,6 @@ export async function GET() {
1110 }));
1211 return NextResponse.json({ models });
1312 } catch (err) {
14- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
1513 return NextResponse.json({ error: "Failed to fetch models" }, { status: 500 });
1614 }
1715 }
app/api/settings/route.ts+0−3
@@ -1,7 +1,6 @@
11 import { NextResponse } from "next/server";
22 import { getCache, setCache } from "@/src/lib/cache";
33 import { getFirstAvailableModel } from "@/src/lib/ollama/models";
4-import { debug } from "@/src/lib/debug";
54
65 const SETTINGS_CACHE_KEY = "app_settings";
76
@@ -26,7 +25,6 @@ export async function GET() {
2625
2726 return NextResponse.json({ settings: defaultSettings });
2827 } catch (err) {
29- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
3028 return NextResponse.json({ error: "Failed to get settings" }, { status: 500 });
3129 }
3230 }
@@ -69,7 +67,6 @@ export async function POST(request: Request) {
6967
7068 return NextResponse.json({ settings: settings });
7169 } catch (err) {
72- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
7370 return NextResponse.json({ error: "Failed to set settings" }, { status: 500 });
7471 }
7572 }
app/api/threads/[id]/messages/[messageId]/route.ts+0−2
@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { messages } from "@/src/lib/db/schema";
44 import { eq, and } from "drizzle-orm";
5-import { debug } from "@/src/lib/debug";
65
76 export async function DELETE(
87 request: Request,
@@ -32,7 +31,6 @@ export async function DELETE(
3231
3332 return NextResponse.json({ success: true });
3433 } catch (err) {
35- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
3634 return NextResponse.json({ error: "Failed to delete message" }, { status: 500 });
3735 }
3836 }
app/api/threads/[id]/messages/route.ts+0−2
@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { messages } from "@/src/lib/db/schema";
44 import { eq, asc, and, notInArray } from "drizzle-orm";
5-import { debug } from "@/src/lib/debug";
65
76 export async function GET(request: Request, { params }: { params: Promise<{ id: string }> }) {
87 try {
@@ -20,7 +19,6 @@ export async function GET(request: Request, { params }: { params: Promise<{ id:
2019
2120 return NextResponse.json({ messages: messagesList });
2221 } catch (err) {
23- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
2422 return NextResponse.json({ error: "Failed to get messages" }, { status: 500 });
2523 }
2624 }
app/api/threads/[id]/route.ts+0−3
@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { threads } from "@/src/lib/db/schema";
44 import { eq } from "drizzle-orm";
5-import { debug } from "@/src/lib/debug";
65
76 export async function PATCH(request: Request, { params }: { params: Promise<{ id: string }> }) {
87 try {
@@ -40,7 +39,6 @@ export async function PATCH(request: Request, { params }: { params: Promise<{ id
4039
4140 return NextResponse.json({ thread: updatedThread[0] });
4241 } catch (err) {
43- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
4442 return NextResponse.json({ error: "Failed to update thread" }, { status: 500 });
4543 }
4644 }
@@ -62,7 +60,6 @@ export async function DELETE(request: Request, { params }: { params: Promise<{ i
6260
6361 return NextResponse.json({ success: true });
6462 } catch (err) {
65- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
6663 return NextResponse.json({ error: "Failed to delete thread" }, { status: 500 });
6764 }
6865 }
app/api/threads/route.ts+0−3
@@ -2,7 +2,6 @@ import { NextResponse } from "next/server";
22 import { db } from "@/src/lib/db";
33 import { threads, messages } from "@/src/lib/db/schema";
44 import { desc, count } from "drizzle-orm";
5-import { debug } from "@/src/lib/debug";
65
76 export async function POST(request: Request) {
87 try {
@@ -35,7 +34,6 @@ export async function POST(request: Request) {
3534
3635 return NextResponse.json({ thread: newThread[0] });
3736 } catch (err) {
38- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
3937 return NextResponse.json({ error: "Failed to create thread" }, { status: 500 });
4038 }
4139 }
@@ -59,7 +57,6 @@ export async function GET(request: Request) {
5957
6058 return NextResponse.json({ threads: threadsList, hasMore, totalCount });
6159 } catch (err) {
62- debug(`[API] Error: ${err instanceof Error ? err.message : "Unknown error"}`);
6360 return NextResponse.json({ error: "Failed to get threads" }, { status: 500 });
6461 }
6562 }
src/lib/cache/index.ts+0−9
@@ -1,6 +1,5 @@
11 /* personal-assistant-thing/src/lib/cache/index.ts */
22
3-import { debug } from "../debug";
43 import ValKey from "iovalkey";
54
65 const valkey = new ValKey(process.env.VALKEY_URL);
@@ -21,14 +20,10 @@ export async function setCache<T>(key: string, value: T, ttlMs?: number): Promis
2120 // Convert milliseconds to seconds for Valkey
2221 const ttlSeconds = Math.ceil(ttlMs / 1000);
2322 await valkey.setex(key, ttlSeconds, serialized);
24- debug(`[Cache] Set key: ${key} (TTL: ${ttlMs}ms)`);
2523 } else {
2624 await valkey.set(key, serialized);
27- debug(`[Cache] Set key: ${key}`);
2825 }
2926 } catch (error: unknown) {
30- const message = error instanceof Error ? error.message : String(error);
31- debug(`[Cache] Error setting cache: ${message}`);
3227 // Don't throw - cache operations should continue even if persistence fails
3328 }
3429 }
@@ -44,15 +39,11 @@ export async function getCache<T>(key: string): Promise<T | null> {
4439 const serialized = await valkey.get(key);
4540
4641 if (!serialized) {
47- debug(`[Cache] Cache miss for key: ${key}`);
4842 return null;
4943 }
5044
51- debug(`[Cache] Cache hit for key: ${key}`);
5245 return JSON.parse(serialized) as T;
5346 } catch (error: unknown) {
54- const message = error instanceof Error ? error.message : String(error);
55- debug(`[Cache] Error getting cache: ${message}`);
5647 return null;
5748 }
5849 }
src/lib/ollama/duckduckgo.ts+0−6
@@ -1,6 +1,5 @@
11 /* personal-assistant-thing/src/lib/ollama/duckduckgo.ts */
22
3-import { debug } from "../debug";
43 import { getCache, setCache } from "../cache";
54 import { createRateLimiter } from "../ratelimit";
65
@@ -19,12 +18,9 @@ export async function queryDuckDuckGo(query: string): Promise<string> {
1918 const cacheKey = `duckduckgo:${query.toLowerCase().trim()}`;
2019 const cached = await getCache<string>(cacheKey);
2120 if (cached !== null) {
22- debug(`[DuckDuckGo] Cache hit for: "${query}"`);
2321 return cached;
2422 }
2523
26- debug(`[DuckDuckGo] Querying: "${query}"`);
27-
2824 const rateLimitCheck = await duckDuckGoRateLimiter.check();
2925 if (!rateLimitCheck.allowed) {
3026 throw new Error("Service temporarily unavailable");
@@ -41,7 +37,6 @@ export async function queryDuckDuckGo(query: string): Promise<string> {
4137
4238 const response = await fetch(`${url}?${params.toString()}`);
4339 if (!response.ok) {
44- debug(`[DuckDuckGo] Error: HTTP ${response.status}`);
4540 throw new Error("Service error");
4641 }
4742
@@ -54,7 +49,6 @@ export async function queryDuckDuckGo(query: string): Promise<string> {
5449 if (data.Heading && !parts.length) parts.push(data.Heading);
5550
5651 if (parts.length === 0) {
57- debug(`[DuckDuckGo] No instant answer data available for this query type`);
5852 const result = `No answer found for: ${query}`;
5953 await setCache(cacheKey, result, CACHE_TTL_MS);
6054 return result;
src/lib/ollama/index.ts+3−6
@@ -35,7 +35,7 @@ async function executeToolCall(toolCall: ToolCall): Promise<Message> {
3535 } else {
3636 result = await tools[name](query);
3737 }
38- debug(`[Tool] ${name} completed, result length: ${result.length} chars`);
38+ debug(`[Tool] ${name} completed (${result.length} chars)`);
3939 } catch (error) {
4040 const errorMessage = error instanceof Error ? error.message : "Unknown error";
4141 debug(`[Tool] ${name} failed: ${errorMessage}`);
@@ -158,7 +158,7 @@ export async function fetchOllamaResponse(
158158 totalDuration += iterationDuration;
159159 const iterationDurationMs = Math.round(iterationDuration / 1_000_000);
160160
161- debug(`[Ollama] Response received (${iterationDurationMs}ms), tool_calls: ${toolCalls.length}`);
161+ debug(`[Ollama] Response (${iterationDurationMs}ms), tool_calls: ${toolCalls.length}`);
162162
163163 // Append accumulated fields to messages
164164 if (thinking || content || toolCalls.length) {
@@ -179,9 +179,7 @@ export async function fetchOllamaResponse(
179179 if (!toolCalls.length) {
180180 const generationTimeMs = Math.round(totalDuration / 1_000_000);
181181
182- debug(
183- `[Ollama] Final response (${generationTimeMs}ms total), content length: ${content.length} chars`
184- );
182+ debug(`[Ollama] Final response (${generationTimeMs}ms, ${content.length} chars)`);
185183
186184 return {
187185 content,
@@ -217,6 +215,5 @@ export async function fetchOllamaResponse(
217215 }
218216 }
219217
220- debug(`[Ollama] Tool responses received, continuing conversation...`);
221218 }
222219 }
src/lib/ollama/weather.ts+0−10
@@ -1,6 +1,5 @@
11 /* personal-assistant-thing/src/lib/ollama/weather.ts */
22
3-import { debug } from "../debug";
43 import { getCache, setCache } from "../cache";
54 import { createRateLimiter } from "../ratelimit";
65
@@ -37,14 +36,9 @@ export async function queryWeather(
3736 const cacheKey = `weather:${query.toLowerCase().trim()}:${timezone}:${days}`;
3837 const cached = await getCache<string>(cacheKey);
3938 if (cached !== null) {
40- debug(`[Weather] Cache hit for: "${query}"`);
4139 return cached;
4240 }
4341
44- debug(
45- `[Weather] Querying weather for: "${query}" (${days > 0 ? `${days} days` : "current only"}, ${timezone})`
46- );
47-
4842 // Check rate limit before making the request
4943 const rateLimitCheck = await weatherRateLimiter.check();
5044 if (!rateLimitCheck.allowed) {
@@ -68,7 +62,6 @@ export async function queryWeather(
6862
6963 const geocodeResponse = await fetch(`${geocodeUrl}?${geocodeParams.toString()}`);
7064 if (!geocodeResponse.ok) {
71- debug(`[Weather] Geocoding error: HTTP ${geocodeResponse.status}`);
7265 throw new Error(`Failed to geocode location "${query}" (${geocodeResponse.status})`);
7366 }
7467
@@ -83,8 +76,6 @@ export async function queryWeather(
8376 const { latitude, longitude, name, country, admin1 } = geocodeData.results[0];
8477 const locationName = `${name}${admin1 ? `, ${admin1}` : ""}${country ? `, ${country}` : ""}`;
8578
86- debug(`[Weather] Found location: ${locationName} (${latitude}, ${longitude})`);
87-
8879 // Now fetch weather data - focus on temperature and precipitation
8980 const weatherUrl = "https://api.open-meteo.com/v1/forecast";
9081 const weatherParams = new URLSearchParams({
@@ -102,7 +93,6 @@ export async function queryWeather(
10293
10394 const weatherResponse = await fetch(`${weatherUrl}?${weatherParams.toString()}`);
10495 if (!weatherResponse.ok) {
105- debug(`[Weather] Weather API error: HTTP ${weatherResponse.status}`);
10696 throw new Error(
10797 `Failed to fetch weather data for "${locationName}" (${weatherResponse.status})`
10898 );
src/lib/ollama/websearch.ts+0−8
@@ -1,7 +1,6 @@
11 /* personal-assistant-thing/src/lib/ollama/websearch.ts */
22
33 import { google } from "googleapis";
4-import { debug } from "../debug";
54 import { getCache, setCache } from "../cache";
65 import { createRateLimiter } from "../ratelimit";
76
@@ -21,17 +20,13 @@ export async function queryWebSearch(query: string): Promise<string> {
2120 const cacheKey = `websearch:${query.toLowerCase().trim()}`;
2221 const cached = await getCache<string>(cacheKey);
2322 if (cached !== null) {
24- debug(`[WebSearch] Cache hit for: "${query}"`);
2523 return cached;
2624 }
2725
28- debug(`[WebSearch] Querying: "${query}"`);
29-
3026 const apiKey = process.env.GOOGLE_CUSTOM_SEARCH_API_KEY;
3127 const cx = process.env.GOOGLE_CUSTOM_SEARCH_ENGINE_ID;
3228
3329 if (!apiKey || !cx) {
34- debug(`[WebSearch] Missing API credentials`);
3530 throw new Error("Service unavailable");
3631 }
3732
@@ -50,14 +45,11 @@ export async function queryWebSearch(query: string): Promise<string> {
5045 });
5146
5247 if (!res.data.items || res.data.items.length === 0) {
53- debug(`[WebSearch] No results found for query: "${query}"`);
5448 const result = `No results for: ${query}`;
5549 await setCache(cacheKey, result, CACHE_TTL_MS);
5650 return result;
5751 }
5852
59- debug(`[WebSearch] Found ${res.data.items.length} results`);
60-
6153 const results = res.data.items
6254 .slice(0, 5)
6355 .map((item) => {
src/lib/ratelimit.ts+0−12
@@ -1,6 +1,5 @@
11 /* personal-assistant-thing/src/lib/ratelimit.ts */
22
3-import { debug } from "./debug";
43 import { getCache, setCache } from "./cache";
54
65 /**
@@ -69,7 +68,6 @@ export function createRateLimiter(config: RateLimitConfig) {
6968 requestCount: 0,
7069 };
7170 await setCache(cacheKey, newState);
72- debug(`[RateLimit:${config.identifier}] Window reset`);
7371 return newState;
7472 }
7573
@@ -100,9 +98,6 @@ export function createRateLimiter(config: RateLimitConfig) {
10098
10199 // Check if we've exceeded the limit
102100 if (state.requestCount >= config.maxRequests) {
103- debug(
104- `[RateLimit:${config.identifier}] Rate limit exceeded: ${state.requestCount}/${config.maxRequests} requests used, ${hoursUntilReset} hours until reset`
105- );
106101 return {
107102 allowed: false,
108103 remaining: 0,
@@ -112,9 +107,6 @@ export function createRateLimiter(config: RateLimitConfig) {
112107 }
113108
114109 const remaining = config.maxRequests - state.requestCount;
115- debug(
116- `[RateLimit:${config.identifier}] ${state.requestCount}/${config.maxRequests} requests used, ${remaining} remaining`
117- );
118110
119111 return {
120112 allowed: true,
@@ -132,9 +124,6 @@ export function createRateLimiter(config: RateLimitConfig) {
132124 const state = await loadState();
133125 state.requestCount++;
134126 await saveState(state);
135- debug(
136- `[RateLimit:${config.identifier}] Incremented to ${state.requestCount}/${config.maxRequests} requests`
137- );
138127 }
139128
140129 /**
@@ -146,7 +135,6 @@ export function createRateLimiter(config: RateLimitConfig) {
146135 requestCount: 0,
147136 };
148137 await saveState(newState);
149- debug(`[RateLimit:${config.identifier}] Manually reset`);
150138 }
151139
152140 /**