feat: initial text-translate v0.1.0 (text.translate@0.1.0)
All checks were successful
CI / Linux x86_64 (Forgejo) (push) Successful in 1m34s

Ollama-backed translation module — third real F∆I capability,
following text.extract and llm.chat. Used for the second leg of
a regulated document workflow (extract -> translate -> review
-> summarise).

Capability:
  Inputs:
    text             : text   (source text)
    target_language  : text   (e.g. "German", "French")
    source_language  : text   (optional hint; empty = auto)
    endpoint         : text   (Ollama /api/chat URL)
    model            : text
    api_key          : text   (optional)

  Outputs:
    translation      : text
    source_language  : text   (echo for audit)
    target_language  : text   (echo for audit)
    model_endpoint   : text
    model_name       : text
    model_digest     : text   (Ollama /api/show probe; empty
                                for non-Ollama or transient
                                failures)

  Permissions: net to localhost / 127.0.0.1 / api.openai.com /
               api.anthropic.com.

The translation prompt is conservative: a fixed system prompt
demands faithful translation with structure preservation and
emits no metadata, no quoting. The user prompt names the target
language and (when supplied) the source language. The LLM
client + digest-probe pattern is reused verbatim from llm-chat;
when a third module joins, the shared client moves into a small
crate.

14 host-side tests cover prompt-building, Ollama-shaped response
parsing, URL transform, digest extraction (top-level + nested),
end-to-end success, end-to-end probe-failure swallow, and
end-to-end skip-for-non-Ollama.

Wasm artifact verified to build with v1.0 fai:platform imports
baked in. Bootstrapped via 'fai new module text.translate'.

Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
flemming-it 2026-05-04 10:53:10 +02:00
commit a4c2c0e14e
11 changed files with 1440 additions and 0 deletions

46
README.md Normal file
View file

@ -0,0 +1,46 @@
# text-translate
Provides the `text.translate` capability for F∆I Platform.
## Build
```bash
cargo build --release --target wasm32-wasip2
```
## Test
```bash
cargo test # host-side unit + integration tests
fai test . # load the wasm component in the runtime sandbox
```
## Authoring with fai-module-sdk
The module body is one decorated function:
```rust
#[fai_module]
pub fn invoke(_ctx: Context, inputs: Inputs) -> Result<Outputs, ModuleError> {
let message = inputs.require_text("message")?;
Ok(Outputs::new().with_text("reply", format!("got: {message}")))
}
```
The macro hides the wit_bindgen call, the Guest impl, the
Payload variant matching, and the `wit_bindgen::export!`
invocation. See `fai-module-sdk` documentation for the full
surface.
## SDK source
The Cargo.toml git-deps `fai-module-sdk` from
`https://git.flemming.ws/fai/module-sdk.git`. If your environment requires
authentication for that host (e.g. Forgejo with
`REQUIRE_SIGNIN_VIEW=true`), set up `git config insteadOf` with
your PAT, or use `cargo:net.git-fetch-with-cli=true` plus a
credential helper.
## License
Apache-2.0