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

49
Cargo.toml Normal file
View file

@ -0,0 +1,49 @@
# Standalone Cargo.toml — targets wasm32-wasip2.
#
# Build with:
# cargo build --release --target wasm32-wasip2
[package]
name = "text_translate"
version = "0.1.0"
edition = "2024"
license = "Apache-2.0"
publish = false
description = "F∆I module providing text.translate"
[lib]
# cdylib for the wasm artifact, rlib so integration tests can
# link against the module's `invoke` function on the host.
crate-type = ["cdylib", "rlib"]
[dependencies]
fai-module-sdk = { git = "https://git.flemming.ws/fai/module-sdk.git", branch = "main" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
# WASI-0.2 HTTP client. Only compiled into the wasm32-wasip2 build.
[target.'cfg(target_arch = "wasm32")'.dependencies]
waki = "0.5"
[dev-dependencies]
serde_json = "1"
[profile.release]
opt-level = "s"
lto = true
codegen-units = 1
strip = "symbols"
[lints.rust]
unsafe_op_in_unsafe_fn = "warn"
[lints.clippy]
unwrap_used = "deny"
expect_used = "deny"
panic = "deny"
print_stdout = "deny"
print_stderr = "deny"
[workspace]
# Empty so this package is NOT picked up by a parent.