fix(server): generate personas through the built-in proxy (UF-045)

POST /api/personas/generate posted to /api/anthropic/v1/messages, a route
that does not exist, with no session token and a port built from
address().toString(), so the URL did not even parse. It also pinned
claude-sonnet-4-6, which needs an Anthropic key.

The route now calls the built-in proxy through self-request.ts, reads the
OpenAI-format reply, and picks the model from the user's default with the
same fallback chat uses, so a local Ollama model works too. An end-to-end
test with localhost trust off checks the generated persona comes back.
This commit is contained in:
shumeiko.it
2026-10-26 01:50:47 +01:00
parent d6217ad7c2
commit 48bdab8087
3 changed files with 96 additions and 12 deletions

View File

@@ -73,7 +73,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`.
| UF-042 | Sidebar hints repeat the visible labels and are partly hidden behind the main area | Fixed | Web UI |
| UF-043 | The chat composer draws two focus outlines | Fixed | Web UI |
| UF-044 | A working API key shows as not responding, and other internal model calls fail | Fixed | Sidecar, models, auth |
| UF-045 | Generating a persona from a description calls a route that does not exist | Open | Sidecar, agents |
| UF-045 | Generating a persona from a description calls a route that does not exist | Fixed | Sidecar, agents |
## Entries
@@ -448,10 +448,10 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
- Recommendation: apply the same change in the main project, and run the auth-sensitive suites with localhost trust off.
### UF-045. Generating a persona from a description calls a route that does not exist
- Status: Open
- Status: Fixed
- Found: 2026-10-26
- Where: at commit `b20b138`, `packages/server/src/local/routes/personas.ts:160` (`POST /api/personas/generate`, used by the agent templates view)
- Symptom: generating an agent persona from a text description cannot get an answer from the model.
- Cause: the route posts to `/api/anthropic/v1/messages`, which no route serves. The request also has no session token, and its port comes from `address().toString()`, which is `[object Object]`.
- What we did: nothing yet. The fix means moving the call to the built-in proxy (`/v1/chat/completions` through `self-request.ts`) and reading its OpenAI-format reply.
- Recommendation: move the call to the built-in proxy in the main project as well.
- Cause: the route posts to `/api/anthropic/v1/messages`, which no route serves. The request also has no session token, and its port comes from `address().toString()`, which is `[object Object]`, so the URL does not even parse. The model was fixed to `claude-sonnet-4-6`, so without an Anthropic key the call could not work either.
- What we did: the route calls the built-in proxy (`/v1/chat/completions` through `self-request.ts`, UF-044) and reads its OpenAI-format reply with `parseOpenAiTextCompletion`. The model starts from the user's default and falls back through `resolveUsableModel`, the way chat does, so a local Ollama model works too. An end-to-end test with localhost trust off checks that the persona the model wrote comes back; before the fix it got HTTP 500.
- Recommendation: apply the same change in the main project.