feat: real LLM call via wasi-http (Ollama adapter) — v0.2.0

The orchestrator now calls a configured Ollama-compatible LLM
endpoint over wasi-http and emits the LLM-generated plan back
to the hub. When llm_endpoint is empty, the v0.1.0 deterministic
stub is preserved as fallback (useful for tests and air-gapped
environments).

- module.yaml: bump to 0.2.0; new inputs llm_endpoint,
  llm_model, llm_api_key; net: permissions for OpenAI,
  Anthropic, localhost, 127.0.0.1 (Ollama defaults)
- src/llm.rs: LlmClient trait, OllamaParams, build_user_prompt,
  build_ollama_body, extract_ollama_content, generate_plan;
  9 unit tests for prompt-building and response-parsing
- src/plan.rs: tagged enum with Explain/SaveFlow/RunFlow/
  InstallModule variants; parse_and_validate; build_stub_plan
  (renamed from build_plan); validate(); 6 unit tests
- src/lib.rs: WakiClient implementing LlmClient over the waki
  WASI-0.2 HTTP crate (wasm32-only); empty endpoint → stub
- Cargo.toml: 0.2.0; thiserror dep; waki dep gated on wasm32

17 host-side tests pass. WASM bundle is 386KB (was 74KB; the
delta is wasi-http via waki, expected). The deny path is
exercised by the platform-side integration test in
fai_platform/crates/fai_hub/tests/orchestrator_llm_path.rs.

Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
flemming-it 2026-04-29 21:27:07 +02:00
parent 3bb8fc9e70
commit 7d07937913
6 changed files with 568 additions and 79 deletions

View file

@ -1,15 +1,24 @@
schema_version: 1
name: orchestrator-llm
version: 0.1.0
version: 0.2.0
# Capability provided by this module.
provides:
- capability: orchestrator.plan
version: 0.1.0
version: 0.2.0
# Inputs the invoke function accepts.
inputs:
goal: text
# LLM HTTP endpoint, e.g. "http://localhost:11434/api/chat"
# for Ollama, "https://api.openai.com/v1/chat/completions",
# or "https://api.anthropic.com/v1/messages".
llm_endpoint: text
# Model identifier, e.g. "qwen2.5:14b" for Ollama or "gpt-4o-mini".
llm_model: text
# Optional bearer token for cloud providers. Empty string means
# no Authorization header is sent.
llm_api_key: text
# Optional JSON-encoded list of installed capabilities. If
# omitted or empty, the module plans without capability context.
available_capabilities: text
@ -25,7 +34,13 @@ outputs:
# Permissions required.
#
# v0.1.0 is a deterministic stub — no network, no fs, no env.
# v0.2.0 will add `net: <llm-endpoint>` once the platform exposes
# wasi-http to permitted modules.
permissions: []
# The module makes outbound HTTP to the configured LLM endpoint.
# Default declarations cover the common providers (cloud OpenAI,
# Anthropic, local Ollama on loopback). Operators with different
# LLM endpoints add a host-level entry via operator config
# (Phase 1+) — for Phase 0.5 they fork module.yaml.
permissions:
- "net: api.openai.com"
- "net: api.anthropic.com"
- "net: localhost"
- "net: 127.0.0.1"