feat: studio.translate.ollama v0.1.0 — Ollama-backed translate hook

First plugin to exercise the Studio-plugin translate hook
end-to-end. Routes through an Ollama-shaped /api/chat
endpoint configured via OLLAMA_ENDPOINT (default
http://localhost:11434/api/chat).

System prompt constrains the model to ONLY the translation —
no commentary, no markdown frames — so the translate hook
contract (plain string in, plain string out) stays honest.

Declared permissions: net: localhost + net: 127.0.0.1 +
net: ollama. Operator policy extends the ceiling for
remote / cloud LLM endpoints.

v0.1 limits: no glossary, no batching, no caching. Same SDK
v0.1 single-world contract — declares Declined stubs for the
theme and output-view hooks.

Built artefact: ~108 KiB stripped wasm. Uploaded to
releases.fai.flemming.ai (sha256 0101ed6e…) and reachable via
`fai install studio.translate.ollama`.

Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
flemming-it 2026-05-25 23:02:44 +02:00
commit 884e275b0e
8 changed files with 976 additions and 0 deletions

72
MODULE.md Normal file
View file

@ -0,0 +1,72 @@
# studio.translate.ollama
Translate-hook plugin for F∆I Studio. Routes the `translate`
call through a configured Ollama-shaped `/api/chat` endpoint
so server-supplied English text (MCP tool descriptions, n8n
endpoint names, `[EN]`-badged strings) gets translated into
the active Studio locale on the fly.
## Capability
- `studio.translate.ollama@0.1.0`
## Hook implemented
- `translate(text, from_locale, to_locale) -> string`
The other two Studio-plugin hooks (`theme`, `output-view`)
return `PluginError::Declined` — this plugin only translates.
## Configuration
Reads two environment variables that the operator exposes via
the plugin's `env:` permission:
| Variable | Default |
| ----------------- | ------------------------------------ |
| `OLLAMA_ENDPOINT` | `http://localhost:11434/api/chat` |
| `OLLAMA_MODEL` | `qwen2.5:14b` |
To point at a different endpoint (e.g. a remote inference
node), set `OLLAMA_ENDPOINT` before starting `fai serve` and
make sure the host appears in the `net:` permissions below.
## Permissions
```yaml
permissions:
- "net: localhost"
- "net: 127.0.0.1"
- "net: ollama"
```
Operators that route through a non-loopback endpoint extend
their operator-policy ceiling to include the upstream host.
## How the system prompt works
The plugin sends two messages to the model: a fixed system
prompt that constrains the output to ONLY the translation
(no quotation marks, no commentary, no explanation) and a
user message with the source text. The locale hint goes in
the system prompt so the model treats it as a directive, not
as translatable content.
This keeps the translate hook's contract honest: caller
expects a plain string back, not a markdown-wrapped LLM
response.
## Limits in v0.1.0
- No glossary / terminology list — the model relies on its
general training.
- No batching. Each call is one HTTP request.
- No caching. Studio's plugin-host may add a per-call cache
in a future iteration.
## Build
```bash
cargo build --release --target wasm32-wasip2
# Output: target/wasm32-wasip2/release/studio_translate_ollama.wasm
```