Skip to main content

Crate graphrt_ffi

Crate graphrt_ffi 

Source
Expand description

§graphrt-ffi

Embedding API for apps written in Kotlin (Android), Swift (iOS / macOS), Python and other languages supported by UniFFI.

The surface is deliberately small and JSON-string based so it stays stable across languages and versions:

Runtime::new(config_json)                       // providers, env, limits
  .register_wasm_plugin(bytes)                  // optional, sandboxed plugins
  .load_workflow(yaml_or_json) -> WorkflowHandle
WorkflowHandle.run(inputs_json, sys_json, listener) -> RunHandle
WorkflowHandle.resume(snapshot_json, inputs_json, secrets_json, listener) -> RunHandle
RunHandle.abort(reason) / pause(reason) / wait_json(timeout_ms)
Runtime.set_credential_provider(provider, callback)  // keys from Keychain / Keystore

Runs execute on a Tokio runtime owned by Runtime; listener callbacks are invoked from its worker threads, never from the caller’s thread. Nothing in this crate spawns processes, so every feature is usable on iOS and Android.

§Config JSON

{
  "providers": { "OPENAI_API_KEY": "sk-...", "OLLAMA_HOST": "http://10.0.2.2:11434" },
  "env": { "CRM_TOKEN": "..." },
  "limits": { "max_steps": 10000, "max_duration_ms": 60000, "default_node_timeout_ms": 30000 },
  "allow_private_network": false,
  "knowledge": { "...": "knowledge-retrieval datasets (see graphrt-rag)" },
  "mcp_servers": { "mcpServers": { "docs": { "url": "https://..." } } },
  "wasm": { "fuel": 1000000000, "memory_bytes": 67108864 },
  "credentials": {
    "openai": { "source": "external" },
    "proxy": { "source": "external", "kind": "openai", "base_url": "https://llm-proxy.example.com/v1" },
    "anthropic": { "source": "token_broker", "url": "https://api.example.com/llm-token", "app_auth": "external" }
  }
}

credentials declares providers whose keys never appear in the config: an external provider asks the CredentialProvider registered with Runtime::set_credential_provider; a token_broker provider fetches short-lived tokens from your backend. See docs/credentials.md.

providers uses the same variable names as the CLI’s environment (OPENAI_API_KEY, OPENAI_BASE_URL, ANTHROPIC_API_KEY, OLLAMA_HOST, GRAPHRT_OPENAI_COMPAT_<NAME>_BASE_URL…). env values are exposed to workflows only for the env variables a workflow declares.

Structs§

CredentialRecord
A credential returned by the host.
RunHandle
Controls one run.
Runtime
A configured runtime: node registry, host services and a thread pool. Create one per app and share it.
UniFfiTraitVtableEventListener
WorkflowHandle
A compiled workflow, ready to run any number of times concurrently.

Enums§

GraphrtError
Errors surfaced to foreign code as exceptions.

Traits§

CredentialProvider
Supplies model credentials. Implemented in the host language.
EventListener
Receives the events of one run. Implemented in the host language.

Functions§

graphrt_version
Version of the embedded runtime.
uniffi_graphrt_ffi_fn_init_callback_vtable_eventlistener