4.8 KiB
4.8 KiB
| phase | plan | subsystem | tags | dependency_graph | tech_stack | key_files | decisions | metrics | requirements_satisfied | |||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 28-ollama-integration | 01 | server |
|
|
|
|
|
|
|
Phase 28 Plan 01: Ollama Service, Routes, and Model Catalog Summary
One-liner: Ollama detection + model listing service with AbortController timeouts, static 5-family model catalog for RAM-based recommendations, and Express routes at /companies/:companyId/ollama/status and /models.
Tasks Completed
| Task | Name | Commit | Files |
|---|---|---|---|
| TDD RED | Add failing tests for ollama service | 2169a21e | server/src/tests/ollama-service.test.ts |
| TDD GREEN (Task 1) | ollamaService + model catalog | 4fce48e1 | server/src/services/ollama.ts, server/src/data/ollama-model-catalog.json |
| Task 2 | Ollama HTTP routes + app mount | e45a2578 | server/src/routes/ollama.ts, routes/index.ts, app.ts |
What Was Built
ollamaService (server/src/services/ollama.ts)
detectOllama(): ProbesOLLAMA_BASE_URL/api/versionwith a 3s AbortController timeout. Returns{ installed: true, version }on success,{ installed: false, installUrl }on any error or timeout.listOllamaModels(): FetchesOLLAMA_BASE_URL/api/tags, maps Ollama's native response (withdetails.parameter_size,details.quantization_level,details.family) toOllamaModel[]. Returns[]on any error.getRecommendedModel(models, systemRamBytes): Reads the static catalog, computes usable RAM as 75% of total, ranks catalog variants by quality tier (best > reasoning > balanced > fast), and marks the single best-fitting model asrecommended: truewith a human-readablerecommendationReason.- Respects
process.env.OLLAMA_BASE_URLoverride — never hard-codeslocalhost:11434.
Model Catalog (server/src/data/ollama-model-catalog.json)
5 families with 11 total variants:
- qwen2: qwen2.5-coder 7b/14b/32b
- llama: llama3.2 3b, llama3.1 8b/70b
- mistral: mistral 7b/22b
- phi: phi4 14b
- deepseek: deepseek-r1 7b/32b
Ollama Routes (server/src/routes/ollama.ts)
GET /companies/:companyId/ollama/status— returnsOllamaStatusJSONGET /companies/:companyId/ollama/models— returns{ models: OllamaModel[], ramGb: number }. Short-circuits to{ models: [], ramGb: 0 }if Ollama not installed.- Both routes gated with
assertCompanyAccess(req, companyId). - Mounted in
app.tsasapi.use(ollamaRoutes())afteragentRoutes.
Test Coverage
12 unit tests (all passing):
detectOllama: success, ECONNREFUSED failure, AbortController timeout, non-ok responselistOllamaModels: success with full OllamaTagsResponse shape, ECONNREFUSED, non-okgetRecommendedModel: 8GB → 7b, 32GB → 32b, unknown models → all false, empty input, RAM too low → no recommendation
Deviations from Plan
Auto-fixed Issues
1. [Rule 3 - Blocking] server/src/data/ gitignored by root .gitignore
- Found during: Task 1 commit
- Issue: Root
.gitignorehasdata/pattern;server/src/data/ollama-model-catalog.jsonwas silently ignored - Fix: Used
git add -fto force-track the file. The catalog is source code (not generated data), so this is correct behavior. - Files modified:
.gitignorenot modified — file force-added - Commit: 4fce48e1
Known Stubs
None — all functions return real data structures. Routes wire directly to service functions. No placeholder values in the response paths.
Self-Check: PASSED
Files exist:
- server/src/services/ollama.ts: FOUND
- server/src/data/ollama-model-catalog.json: FOUND
- server/src/tests/ollama-service.test.ts: FOUND
- server/src/routes/ollama.ts: FOUND
Commits exist:
- 2169a21e: FOUND (test RED)
- 4fce48e1: FOUND (feat GREEN + catalog)
- e45a2578: FOUND (feat routes)