xonecas.io
53129
Pa

PAT / commit a04f73e

chore: repo healthcare :D

xonecas2025-12-18 a04f73e7447f48cdb932bc04a7aac6791f145791 parent 51dd4c5

9 files changed

AGENTS.md+3−92
@@ -58,24 +58,19 @@ Add tests when prompted only.
5858 - API routes should return `NextResponse` objects
5959
6060 6. **Styling**:
61- - Avoid using CSS whenever possible
61+ - Avoid using CSS
6262 - Use TailwindCSS utility classes exclusively
6363 - Inline Tailwind classes in JSX
64- - Use responsive design utilities when appropriate
65- - **Markdown Styling**: Use Tailwind Typography plugin with `prose` classes for markdown content
66- - Use `prose prose-neutral dark:prose-invert max-w-none` for assistant messages
67- - The typography plugin is configured in `tailwind.config.js`
68- - Custom syntax highlighting styles are in `app/highlight-theme.css` using `.prose` selectors
6964
7065 7. **Code Formatting**:
7166 - Use Prettier for code formatting: `npm run format` to format all files
7267 - Prettier configuration is in `.prettierrc`
73- - Prettier automatically sorts Tailwind CSS classes via `prettier-plugin-tailwindcss`
7468
7569 8. **Error Handling**:
7670 - Use `lib/debug` for debug information
7771 - Return user-friendly error messages in API responses
7872 - Handle API errors gracefully with try/catch blocks
73+ - The UI should always reflect errors to the user
7974
8075 9. **Imports**:
8176 - Use absolute imports with `@/` prefix for local files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
@@ -84,86 +79,12 @@ Add tests when prompted only.
8479 - Use default imports for component files (e.g., `import PaperPlaneIcon from "@/src/components/icons/PaperPlaneIcon"`)
8580 - Path alias `@/` is configured in `tsconfig.json` to point to the project root
8681
87-## Key Implementation Details
88-
89-### Ollama Integration
90-
91-- Default model: `gpt-oss`
92-- Function: `fetchOllamaResponse(messages: OllamaMessageInput[], model?: string)`
93-- Returns: Promise<OllamaResponse> with `{ content: string, generationTimeMs: number, toolCalls?: any[] }`
94-- Uses `ollama.chat()` API with full conversation history
95-- **Tool Calling Support**: Supports tool calling with automatic iteration to exhaust tool calls
96- - Tools are executed and results are sent back to the model until a final response is generated
97- - Maximum 10 iterations to prevent infinite loops
98- - Currently supports: `query_duckduckgo` tool for DuckDuckGo Instant Answer API queries, `query_weather` tool for Open-Meteo weather API queries, and `query_web_search` tool for Google Custom Search API queries
99-- Located in: `src/lib/ollama/index.ts`
100-- Tool implementations are modularized in separate files: `duckduckgo.ts`, `weather.ts`, `websearch.ts`
101-
102-### Tool Integration
103-
104-- **DuckDuckGo Tool** (`query_duckduckgo`): Queries DuckDuckGo's Instant Answer API for quick information
105- - Function: `queryDuckDuckGo(query: string): Promise<string>`
106- - Returns formatted information including heading, abstract, answer, definition, and related topics
107- - Handles cases where no instant answer is available (limited API coverage)
108- - Enforces rate limit of 500 requests per 24 hours using the rate limit utility (persisted across restarts via cache)
109- - Results are cached for 6 hours using the cache utility
110- - Located in: `src/lib/ollama/duckduckgo.ts`
111-
112-- **Weather Tool** (`query_weather`): Queries Open-Meteo's weather API for current conditions and forecasts
113- - Function: `queryWeather(location: string): Promise<string>`
114- - Automatically geocodes location names to coordinates using Open-Meteo's geocoding API
115- - Returns current weather conditions (temperature, humidity, wind speed, conditions) and 3-day forecast
116- - Supports any location worldwide (city names, cities with countries, etc.)
117- - Uses WMO weather codes converted to human-readable descriptions
118- - Enforces rate limit of 1000 requests per 24 hours using the rate limit utility (persisted across restarts via cache)
119- - Results are cached for 6 hours using the cache utility
120- - Located in: `src/lib/ollama/weather.ts`
121-
122-- **Web Search Tool** (`query_web_search`): Performs web searches using Google Custom Search API
123- - Function: `queryWebSearch(query: string): Promise<string>`
124- - Returns formatted search results with titles, URLs, and snippets
125- - Enforces rate limit of 100 requests per 24 hours using the rate limit utility (persisted across restarts via cache)
126- - Results are cached for 6 hours using the cache utility
127- - Requires `GOOGLE_CUSTOM_SEARCH_API_KEY` and `GOOGLE_CUSTOM_SEARCH_ENGINE_ID` environment variables
128- - Located in: `src/lib/ollama/websearch.ts`
129-
130-### Cache Utility
131-
132-- **Valkey-based Caching** (`src/lib/cache/`): Persistent caching utility with TTL support using Valkey (Redis-compatible)
133- - Functions: `getCache<T>(key: string)`, `setCache<T>(key: string, value: T, ttlMs?: number)`
134- - Cache API located in: `src/lib/cache/index.ts`
135- - Valkey connection logic in: `src/lib/cache/valkey.ts`
136- - Uses Valkey (Redis-compatible in-memory data store) for persistence
137- - Automatically connects to Valkey on first cache operation
138- - Uses Valkey's native TTL support (converts milliseconds to seconds)
139- - Requires `VALKEY_URL` environment variable (format: `redis://:password@host:port`)
140- - Used by tool implementations to cache API responses (6-hour TTL)
141- - Graceful error handling - cache operations continue even if persistence fails
142-
143-### Rate Limit Utility
144-
145-- **Rate Limiting** (`src/lib/ratelimit.ts`): Reusable rate limiting utility using the cache system
146- - Function: `createRateLimiter(config: RateLimitConfig)` - Creates a rate limiter instance
147- - Configuration: `{ maxRequests: number, windowMs: number, identifier: string }`
148- - Methods: `check()`, `increment()`, `reset()`, `getState()`
149- - Uses the cache utility for persistence across restarts
150- - Automatically handles window resets when the time window expires
151- - Returns detailed rate limit information including remaining requests and reset time
152-
153-### Debug Utility
154-
155-- **Debug Logging** (`src/lib/debug.ts`): Development-only debug logging utility
156- - Function: `debug(...args: any[]): void`
157- - Only logs when `NODE_ENV === "development"`
158-
15982 ### Testing
16083
161-- **Test Framework**: Vitest (v4.0.16) - Fast unit test framework
16284 - **Configuration**: `vitest.config.ts` - Configures Vitest with TypeScript support and path aliases
16385 - **Test Files**: Test files use `.test.ts` or `.test.tsx` extension and are located alongside the code they test
16486 - **Test Commands**:
16587 - `npm test` - Run tests in watch mode
166- - `npm run test:ui` - Open Vitest UI for interactive testing
16788 - `npm run test:run` - Run tests once and exit
16889 - **Mocking**: Tests use Vitest's mocking capabilities to isolate units (e.g., cache module is mocked in rate limiter tests)
16990
@@ -179,15 +100,9 @@ Add tests when prompted only.
179100 - Requires `POSTGRES_PASSWORD` environment variable
180101 - Data persisted in Docker volume `postgres_data`
181102 - **Schema**: Defined in `src/lib/db/schema.ts`
182-- **Connection**: Exported from `src/lib/db/index.ts` as `db`
183-- **Tables**:
184- - `threads`: Stores conversation threads with id, title, createdAt, updatedAt
185- - `messages`: Stores messages with id, threadId, role, content, createdAt, generationTimeMs, toolCalls (JSON string of tool calls made to generate assistant messages)
186-- **Relations**: Messages belong to threads (one-to-many)
187103 - **Types**: Type definitions for `Thread` and `Message` are exported from `src/lib/db/schema` using Drizzle's `$inferSelect` (import directly from schema, e.g., `import type { Thread, Message } from "@/src/lib/db/schema"`)
188104 - **Configuration**: `drizzle.config.ts` defines schema path and database connection
189105 - **Migrations**: Generated in `drizzle/` directory using `npm run db:generate`
190-- **Foreign Keys**: Enabled automatically in database connection
191106 - **Usage**: Import `db` from `src/lib/db/index.ts` to query the database
192107
193108 ## Development Workflow
@@ -196,20 +111,16 @@ Add tests when prompted only.
196111 2. Ask the user to test in browser
197112 3. Update existing tests and add more if prompted to.
198113 4. Format code: `npm run format`
114+5. Check for errors in compilation: `npm run typecheck`
199115 5. Run linter: `npm run lint`
200116 6. Run tests: `npm run test:run` (verify all tests pass)
201117
202118 ## Important Constraints
203119
204120 - **DO NOT** add new npm packages without explicit approval
205-- **DO NOT** change TypeScript strict mode settings
206-- **DO NOT** modify Next.js or React versions
207121 - **DO NOT** Commit secrets or API keys, edit `node_modules/` or `vendor/`
208122 - **DO NOT** Erase any data without explicit approval
209123 - **DO** maintain existing code style and patterns
210-- **DO** use existing utility functions from `src/lib/`
211-- **DO** follow the App Router conventions for Next.js 16
212-- **DO** ALWAYS keep this file up to date as changes are made in the code
213124
214125 # Known issues:
215126
app/api/chat/route.ts+25−15
@@ -1,24 +1,34 @@
11 import { NextResponse } from "next/server";
2-import { fetchOllamaResponse, type OllamaMessageInput } from "@/src/lib/ollama";
2+import {
3+ fetchOllamaResponse,
4+ type OllamaMessageInput,
5+ type OllamaMessageRole,
6+ type MaxPromptLength,
7+} from "@/src/lib/ollama";
38 import { db } from "@/src/lib/db";
49 import { messages, threads } from "@/src/lib/db/schema";
510 import { eq, asc } from "drizzle-orm";
611
712 export async function POST(request: Request) {
8- const { message, threadId } = await request.json();
13+ const { message, threadId: threadIdRaw } = await request.json();
914 const signal = request.signal;
1015
11- if (!threadId) {
16+ if (!threadIdRaw) {
1217 return NextResponse.json({ error: "threadId is required" }, { status: 400 });
1318 }
1419
20+ const threadId: number = Number(threadIdRaw);
21+ if (isNaN(threadId)) {
22+ return NextResponse.json({ error: "Invalid threadId" }, { status: 400 });
23+ }
24+
1525 try {
1626 // 1. Fetch thread to get its model and maxPromptLength settings
1727 // These thread-specific settings override any global settings
1828 const thread = await db
1929 .select()
2030 .from(threads)
21- .where(eq(threads.id, parseInt(threadId)))
31+ .where(eq(threads.id, threadId))
2232 .limit(1);
2333 if (thread.length === 0) {
2434 return NextResponse.json({ error: "Thread not found" }, { status: 404 });
@@ -28,19 +38,19 @@ export async function POST(request: Request) {
2838 // Use thread-specific maxPromptLength (stored in thread table, can be null, 1024, or 4096)
2939 // Type assertion ensures compatibility with fetchOllamaResponse which expects "none" | 1024 | 4096 | null
3040 // Note: null from database means "none" (no limit), which fetchOllamaResponse handles correctly
31- const threadMaxPromptLength: "none" | 1024 | 4096 | null =
32- thread[0].maxPromptLength === null ? null : (thread[0].maxPromptLength as 1024 | 4096);
41+ const threadMaxPromptLength: MaxPromptLength =
42+ thread[0].maxPromptLength === null ? 'none' : thread[0].maxPromptLength as MaxPromptLength;
3343
3444 // 2. Fetch previous messages from thread
3545 const previousMessages = await db
3646 .select()
3747 .from(messages)
38- .where(eq(messages.threadId, parseInt(threadId)))
48+ .where(eq(messages.threadId, threadId))
3949 .orderBy(asc(messages.createdAt));
4050
4151 // 3. Store user message
4252 await db.insert(messages).values({
43- threadId: parseInt(threadId),
53+ threadId: threadId,
4454 role: "user",
4555 content: message,
4656 createdAt: new Date(),
@@ -48,7 +58,7 @@ export async function POST(request: Request) {
4858
4959 // 4. Build messages array for Ollama
5060 const ollamaMessages: OllamaMessageInput[] = previousMessages.map((msg) => ({
51- role: msg.role as "user" | "assistant" | "system",
61+ role: msg.role as OllamaMessageRole,
5262 content: msg.content,
5363 toolCalls: msg.toolCalls || undefined,
5464 }));
@@ -169,11 +179,11 @@ export async function POST(request: Request) {
169179 // Save partial content if any was generated
170180 if (accumulatedContent) {
171181 await db.insert(messages).values({
172- threadId: parseInt(threadId),
182+ threadId: threadId,
173183 role: "assistant",
174184 content: accumulatedContent,
175185 model: threadModel,
176- maxPromptLength: threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
186+ maxPromptLength: threadMaxPromptLength === "none" ? null : threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
177187 createdAt: new Date(),
178188 generationTimeMs: null,
179189 toolCalls: allToolCalls.length > 0 ? JSON.stringify(allToolCalls) : null,
@@ -181,7 +191,7 @@ export async function POST(request: Request) {
181191 await db
182192 .update(threads)
183193 .set({ updatedAt: new Date() })
184- .where(eq(threads.id, parseInt(threadId)));
194+ .where(eq(threads.id, threadId));
185195
186196 // Send done message with metadata for aborted generation
187197 if (!isControllerClosed) {
@@ -207,11 +217,11 @@ export async function POST(request: Request) {
207217
208218 // 6. Store assistant message with model, maxPromptLength, generation time and tool calls
209219 await db.insert(messages).values({
210- threadId: parseInt(threadId),
220+ threadId: threadId,
211221 role: "assistant",
212222 content: accumulatedContent,
213223 model: threadModel,
214- maxPromptLength: threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
224+ maxPromptLength: threadMaxPromptLength === "none" ? null : threadMaxPromptLength, // null means "none" (no limit), otherwise 1024 or 4096
215225 createdAt: new Date(),
216226 generationTimeMs,
217227 toolCalls: toolCalls ? JSON.stringify(toolCalls) : null,
@@ -221,7 +231,7 @@ export async function POST(request: Request) {
221231 await db
222232 .update(threads)
223233 .set({ updatedAt: new Date() })
224- .where(eq(threads.id, parseInt(threadId)));
234+ .where(eq(threads.id, threadId));
225235
226236 // Send final message with metadata
227237 if (!isControllerClosed) {
app/api/models/route.ts+3−25
@@ -1,34 +1,12 @@
11 import { NextResponse } from "next/server";
22 import ollama from "ollama";
33
4-/**
5- * Model response from Ollama API
6- * Based on OpenAPI spec: /api/tags returns { models: ModelSummary[] }
7- */
8-interface ModelSummary {
9- name: string;
10- modified_at?: string;
11- size?: number;
12- digest?: string;
13- details?: {
14- format?: string;
15- family?: string;
16- families?: string[];
17- parameter_size?: string;
18- quantization_level?: string;
19- };
20-}
21-
22-interface ListResponse {
23- models: ModelSummary[];
24-}
25-
264 export async function GET() {
275 try {
28- const response = (await ollama.list()) as ListResponse;
29- // ollama.list() returns { models: ModelSummary[] }
6+ const response = await ollama.list();
7+ // ollama.list() returns { models: ModelResponse[] }
308 // Each model has a 'name' property that is used as the model identifier
31- const models = (response.models || []).map((model: ModelSummary) => ({
9+ const models = (response.models || []).map((model) => ({
3210 name: model.name,
3311 model: model.name, // Use name as the model identifier
3412 }));
eslint.config.mjs+21−0
@@ -0,0 +1,21 @@
1+import { defineConfig, globalIgnores } from 'eslint/config'
2+import nextVitals from 'eslint-config-next/core-web-vitals'
3+import nextTs from 'eslint-config-next/typescript'
4+import prettier from 'eslint-config-prettier/flat'
5+
6+const eslintConfig = defineConfig([
7+ ...nextVitals,
8+ ...nextTs,
9+ prettier,
10+ // Override default ignores of eslint-config-next.
11+ globalIgnores([
12+ // Default ignores of eslint-config-next:
13+ '.next/**',
14+ 'out/**',
15+ 'build/**',
16+ 'next-env.d.ts',
17+ ]),
18+])
19+
20+export default eslintConfig
21+
package-lock.json+20−23
@@ -35,9 +35,13 @@
3535 "@vitest/ui": "^4.0.16",
3636 "eslint": "^9.39.2",
3737 "eslint-config-next": "^16.0.10",
38+ "eslint-config-prettier": "^10.1.8",
3839 "prettier": "^3.2.5",
3940 "prettier-plugin-tailwindcss": "^0.5.11",
4041 "vitest": "^4.0.16"
42+ },
43+ "engines": {
44+ "node": ">=25.0.0"
4145 }
4246 },
4347 "node_modules/@alloc/quick-lru": {
@@ -83,7 +87,6 @@
8387 "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
8488 "dev": true,
8589 "license": "MIT",
86- "peer": true,
8790 "dependencies": {
8891 "@babel/code-frame": "^7.27.1",
8992 "@babel/generator": "^7.28.5",
@@ -2661,7 +2664,6 @@
26612664 "integrity": "sha512-N2clP5pJhB2YnZJ3PIHFk5RkygRX5WO/5f0WC08tp0wd+sv0rsJk3MqWn3CbNmT2J505a5336jaQj4ph1AdMug==",
26622665 "dev": true,
26632666 "license": "MIT",
2664- "peer": true,
26652667 "dependencies": {
26662668 "undici-types": "~6.21.0"
26672669 }
@@ -2677,7 +2679,6 @@
26772679 "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.27.tgz",
26782680 "integrity": "sha512-cisd7gxkzjBKU2GgdYrTdtQx1SORymWyaAFhaxQPK9bYO9ot3Y5OikQRvY0VYQtvwjeQnizCINJAenh/V7MK2w==",
26792681 "license": "MIT",
2680- "peer": true,
26812682 "dependencies": {
26822683 "@types/prop-types": "*",
26832684 "csstype": "^3.2.2"
@@ -2744,7 +2745,6 @@
27442745 "integrity": "sha512-6/cmF2piao+f6wSxUsJLZjck7OQsYyRtcOZS02k7XINSNlz93v6emM8WutDQSXnroG2xwYlEVHJI+cPA7CPM3Q==",
27452746 "dev": true,
27462747 "license": "MIT",
2747- "peer": true,
27482748 "dependencies": {
27492749 "@typescript-eslint/scope-manager": "8.50.0",
27502750 "@typescript-eslint/types": "8.50.0",
@@ -3347,7 +3347,6 @@
33473347 "integrity": "sha512-rkoPH+RqWopVxDnCBE/ysIdfQ2A7j1eDmW8tCxxrR9nnFBa9jKf86VgsSAzxBd1x+ny0GC4JgiD3SNfRHv3pOg==",
33483348 "dev": true,
33493349 "license": "MIT",
3350- "peer": true,
33513350 "dependencies": {
33523351 "@vitest/utils": "4.0.16",
33533352 "fflate": "^0.8.2",
@@ -3384,7 +3383,6 @@
33843383 "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
33853384 "dev": true,
33863385 "license": "MIT",
3387- "peer": true,
33883386 "bin": {
33893387 "acorn": "bin/acorn"
33903388 },
@@ -3861,7 +3859,6 @@
38613859 }
38623860 ],
38633861 "license": "MIT",
3864- "peer": true,
38653862 "dependencies": {
38663863 "baseline-browser-mapping": "^2.9.0",
38673864 "caniuse-lite": "^1.0.30001759",
@@ -4750,7 +4747,6 @@
47504747 "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==",
47514748 "hasInstallScript": true,
47524749 "license": "MIT",
4753- "peer": true,
47544750 "bin": {
47554751 "esbuild": "bin/esbuild"
47564752 },
@@ -4826,7 +4822,6 @@
48264822 "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==",
48274823 "dev": true,
48284824 "license": "MIT",
4829- "peer": true,
48304825 "dependencies": {
48314826 "@eslint-community/eslint-utils": "^4.8.0",
48324827 "@eslint-community/regexpp": "^4.12.1",
@@ -4921,6 +4916,22 @@
49214916 "url": "https://github.com/sponsors/sindresorhus"
49224917 }
49234918 },
4919+ "node_modules/eslint-config-prettier": {
4920+ "version": "10.1.8",
4921+ "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz",
4922+ "integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==",
4923+ "dev": true,
4924+ "license": "MIT",
4925+ "bin": {
4926+ "eslint-config-prettier": "bin/cli.js"
4927+ },
4928+ "funding": {
4929+ "url": "https://opencollective.com/eslint-config-prettier"
4930+ },
4931+ "peerDependencies": {
4932+ "eslint": ">=7.0.0"
4933+ }
4934+ },
49244935 "node_modules/eslint-import-resolver-node": {
49254936 "version": "0.3.9",
49264937 "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.9.tgz",
@@ -5012,7 +5023,6 @@
50125023 "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
50135024 "dev": true,
50145025 "license": "MIT",
5015- "peer": true,
50165026 "dependencies": {
50175027 "@rtsao/scc": "^1.1.0",
50185028 "array-includes": "^3.1.9",
@@ -6728,7 +6738,6 @@
67286738 "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.7.tgz",
67296739 "integrity": "sha512-/imKNG4EbWNrVjoNC/1H5/9GFy+tqjGBHCaSsN+P2RnPqjsLmv6UD3Ej+Kj8nBWaRAwyk7kK5ZUc+OEatnTR3A==",
67306740 "license": "MIT",
6731- "peer": true,
67326741 "bin": {
67336742 "jiti": "bin/jiti.js"
67346743 }
@@ -8489,7 +8498,6 @@
84898498 }
84908499 ],
84918500 "license": "MIT",
8492- "peer": true,
84938501 "dependencies": {
84948502 "nanoid": "^3.3.11",
84958503 "picocolors": "^1.1.1",
@@ -8632,7 +8640,6 @@
86328640 "resolved": "https://registry.npmjs.org/postgres/-/postgres-3.4.7.tgz",
86338641 "integrity": "sha512-Jtc2612XINuBjIl/QTWsV5UvE8UHuNblcO3vVADSrKsrc6RqGX6lOW1cEo3CM2v0XG4Nat8nI+YM7/f26VxXLw==",
86348642 "license": "Unlicense",
8635- "peer": true,
86368643 "engines": {
86378644 "node": ">=12"
86388645 },
@@ -8657,7 +8664,6 @@
86578664 "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==",
86588665 "dev": true,
86598666 "license": "MIT",
8660- "peer": true,
86618667 "bin": {
86628668 "prettier": "bin/prettier.cjs"
86638669 },
@@ -8815,7 +8821,6 @@
88158821 "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
88168822 "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",
88178823 "license": "MIT",
8818- "peer": true,
88198824 "dependencies": {
88208825 "loose-envify": "^1.1.0"
88218826 },
@@ -8828,7 +8833,6 @@
88288833 "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
88298834 "integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==",
88308835 "license": "MIT",
8831- "peer": true,
88328836 "dependencies": {
88338837 "loose-envify": "^1.1.0",
88348838 "scheduler": "^0.23.0"
@@ -9884,7 +9888,6 @@
98849888 "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",
98859889 "integrity": "sha512-3ofp+LL8E+pK/JuPLPggVAIaEuhvIz4qNcf3nA1Xn2o/7fb7s/TYpHhwGDv1ZU3PkBluUVaF8PyCHcm48cKLWQ==",
98869890 "license": "MIT",
9887- "peer": true,
98889891 "dependencies": {
98899892 "@alloc/quick-lru": "^5.2.0",
98909893 "arg": "^5.0.2",
@@ -9993,7 +9996,6 @@
99939996 "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz",
99949997 "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
99959998 "license": "MIT",
9996- "peer": true,
99979999 "engines": {
999810000 "node": ">=12"
999910001 },
@@ -10187,7 +10189,6 @@
1018710189 "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
1018810190 "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
1018910191 "license": "Apache-2.0",
10190- "peer": true,
1019110192 "bin": {
1019210193 "tsc": "bin/tsc",
1019310194 "tsserver": "bin/tsserver"
@@ -10468,7 +10469,6 @@
1046810469 "integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==",
1046910470 "dev": true,
1047010471 "license": "MIT",
10471- "peer": true,
1047210472 "dependencies": {
1047310473 "esbuild": "^0.27.0",
1047410474 "fdir": "^6.5.0",
@@ -11046,7 +11046,6 @@
1104611046 "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==",
1104711047 "dev": true,
1104811048 "license": "MIT",
11049- "peer": true,
1105011049 "engines": {
1105111050 "node": ">=12"
1105211051 },
@@ -11060,7 +11059,6 @@
1106011059 "integrity": "sha512-E4t7DJ9pESL6E3I8nFjPa4xGUd3PmiWDLsDztS2qXSJWfHtbQnwAWylaBvSNY48I3vr8PTqIZlyK8TE3V3CA4Q==",
1106111060 "dev": true,
1106211061 "license": "MIT",
11063- "peer": true,
1106411062 "dependencies": {
1106511063 "@vitest/expect": "4.0.16",
1106611064 "@vitest/mocker": "4.0.16",
@@ -11412,7 +11410,6 @@
1141211410 "integrity": "sha512-0wZ1IRqGGhMP76gLqz8EyfBXKk0J2qo2+H3fi4mcUP/KtTocoX08nmIAHl1Z2kJIZbZee8KOpBCSNPRgauucjw==",
1141311411 "dev": true,
1141411412 "license": "MIT",
11415- "peer": true,
1141611413 "funding": {
1141711414 "url": "https://github.com/sponsors/colinhacks"
1141811415 }
package.json+4−2
@@ -9,7 +9,8 @@
99 "dev": "next dev",
1010 "build": "next build",
1111 "start": "next start",
12- "lint": "next lint",
12+ "lint": "eslint .",
13+ "typecheck": "tsc --noEmit",
1314 "format": "prettier --write .",
1415 "format:check": "prettier --check .",
1516 "test": "vitest",
@@ -26,7 +27,6 @@
2627 "@googleapis/customsearch": "^7.0.1",
2728 "@tailwindcss/typography": "^0.5.19",
2829 "autoprefixer": "^10.4.17",
29- "postgres": "^3.4.5",
3030 "drizzle-kit": "^0.31.8",
3131 "drizzle-orm": "^0.45.1",
3232 "googleapis": "^169.0.0",
@@ -35,6 +35,7 @@
3535 "next": "^16.0.10",
3636 "ollama": "^0.6.3",
3737 "postcss": "^8.4.30",
38+ "postgres": "^3.4.5",
3839 "react": "18.2.0",
3940 "react-dom": "18.2.0",
4041 "react-markdown": "^10.1.0",
@@ -50,6 +51,7 @@
5051 "@vitest/ui": "^4.0.16",
5152 "eslint": "^9.39.2",
5253 "eslint-config-next": "^16.0.10",
54+ "eslint-config-prettier": "^10.1.8",
5355 "prettier": "^3.2.5",
5456 "prettier-plugin-tailwindcss": "^0.5.11",
5557 "vitest": "^4.0.16"
src/lib/ollama/index.ts+18−22
@@ -6,27 +6,23 @@ import { debug } from "../debug";
66 import { duckDuckGoTool, queryDuckDuckGo } from "./duckduckgo";
77 import { queryWeather, weatherTool } from "./weather";
88 import { queryWebSearch, webSearchTool } from "./websearch";
9-
10-// Use types compatible with ollama package - use any to work around strict typing
11-type OllamaMessage = any;
12-
13-export interface OllamaMessageInput {
14- role: "user" | "assistant" | "system";
15- content: string;
16- toolCalls?: string; // Optional JSON string of tool calls (from database)
17-}
18-
19-export interface OllamaResponse {
20- content: string;
21- generationTimeMs: number;
22- toolCalls?: any[]; // Array of tool calls made during the conversation
23-}
24-
25-export interface OllamaChunk {
26- content?: string;
27- thinking?: string;
28- toolCalls?: any[];
29-}
9+import type {
10+ OllamaMessage,
11+ OllamaMessageInput,
12+ OllamaChunk,
13+ OllamaResponse,
14+ MaxPromptLength,
15+} from "./types";
16+
17+// Re-export types for convenience
18+export type {
19+ OllamaMessage,
20+ OllamaMessageRole,
21+ OllamaMessageInput,
22+ OllamaChunk,
23+ OllamaResponse,
24+ MaxPromptLength,
25+} from "./types";
3026
3127 /**
3228 * Executes a tool call and returns the result.
@@ -102,7 +98,7 @@ export async function fetchOllamaResponse(
10298 onChunk?: (chunk: OllamaChunk) => void,
10399 model = "gpt-oss",
104100 signal?: AbortSignal,
105- maxPromptLength?: "none" | 1024 | 4096 | null
101+ maxPromptLength?: MaxPromptLength
106102 ): Promise<OllamaResponse> {
107103 const tools = [duckDuckGoTool, weatherTool, webSearchTool];
108104 let totalDuration = 0;
src/lib/ollama/types.ts+28−0
@@ -0,0 +1,28 @@
1+/* personal-assistant-thing/src/lib/ollama/types.ts */
2+// Type definitions for Ollama integration
3+
4+// Use types compatible with ollama package - use any to work around strict typing
5+export type OllamaMessage = any;
6+
7+export type OllamaMessageRole = "user" | "assistant" | "system";
8+
9+export interface OllamaMessageInput {
10+ role: OllamaMessageRole;
11+ content: string;
12+ toolCalls?: string; // Optional JSON string of tool calls (from database)
13+}
14+
15+export interface OllamaResponse {
16+ content: string;
17+ generationTimeMs: number;
18+ toolCalls?: any[]; // Array of tool calls made during the conversation
19+}
20+
21+export interface OllamaChunk {
22+ content?: string;
23+ thinking?: string;
24+ toolCalls?: any[];
25+}
26+
27+export type MaxPromptLength = "none" | 1024 | 4096 | null;
28+
tsconfig.tsbuildinfo+1−0
@@ -0,0 +1 @@
1+{"fileNames":["./node_modules/typescript/lib/lib.es5.d.ts","./node_modules/typescript/lib/lib.es2015.d.ts","./node_modules/typescript/lib/lib.es2016.d.ts","./node_modules/typescript/lib/lib.es2017.d.ts","./node_modules/typescript/lib/lib.es2018.d.ts","./node_modules/typescript/lib/lib.es2019.d.ts","./node_modules/typescript/lib/lib.es2020.d.ts","./node_modules/typescript/lib/lib.es2021.d.ts","./node_modules/typescript/lib/lib.es2022.d.ts","./node_modules/typescript/lib/lib.es2023.d.ts","./node_m …