Expand description
The guest side of a Subako function: a WASI preview 1 program the worker
runs with argv = [package, tool], the tool’s input JSON on stdin, and the
output JSON expected on stdout. Exit 0 is a result; exit 1 carries
{"error": ...}, which the model reads as a failed call.
A package is written as typed functions. Each one’s name, doc comment, and
input and output types become its tool, and the program prints the
package’s subako-package.json when run with --subako-manifest:
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use subako_function_sdk::{ToolError, function, package};
#[derive(Deserialize, JsonSchema)]
struct GreetInput {
/// Who to greet.
name: String,
}
#[derive(Serialize, JsonSchema)]
struct Greeting {
message: String,
}
/// Greet someone by name.
#[function]
fn greet(input: GreetInput) -> Result<Greeting, ToolError> {
Ok(Greeting { message: format!("Hello, {}!", input.name) })
}
package! {
name: "hello",
description: "Says hello.",
functions: [greet],
}The same crate built for the host prints the same manifest, so packaging
needs no WebAssembly runtime: cargo run -- --subako-manifest.
Modules§
- http
- HTTP from a guest. The worker makes the request on the guest’s behalf, under the invocation’s egress policy: which hosts it may reach and which credential headers ride along to which origins. A file body or a file response moves between the socket and the volume without passing through guest memory.
Macros§
- package
- Declares the package:
pub fn package()building it and, unlessmain: false, the program’smainserving it.
Structs§
- Function
- One function a package serves as a tool.
- Input
- A call’s input, held until the tool says which shape it takes.
- Manifest
- What
subako-package.jsonholds. - Manifest
Function - Output
- A call’s result, already JSON.
- Package
- A package: its name, its description, and the functions it serves.
- Tool
Error - A failure the model should read: the message is all it is told.
Constants§
- MANIFEST_
FLAG - The argument that prints the manifest instead of calling a function.
Functions§
- execute
- The whole call as a pure function of its arguments and stdin, so a host test drives exactly what the guest runs.
- run
- The guest’s
main: reads argv and stdin, routes, writes stdout.
Attribute Macros§
- function
- Makes a function a tool: its name is the tool’s, its doc comment the
description the model reads, and its one argument and
Oktype the input and output schemas. The function itself is left as written.