OLLMrpc
Description:
Binary RPC client and wire types shared by apps and ollmfilesd.
The OLLMrpc namespace is the client library for talking to ollmfilesd over a Unix socket (or stdio/TCP), and for calling HTTPS JSON APIs
with the same Request / Response shape.
Client owns the channel. Request carries
method, positional args via args, and optional result_type.
Bin serializes Bin.Serializable
GObjects on the wire. Transport is the daemon listen/connection side.
Live is opt-in live GObject handles (ref, unref, subscribe).
Architecture Benefits
- Positional args: D-Bus signature packing via args, not ad-hoc JSON bags
- One client: Unix socket for ollmfilesd, HTTPS URL for Hub-style APIs
- Bin codec: compact wire with JIT property keys (Bin.Stream)
- Shared types: same Request/Response on client and daemon
Usage Examples
ollmfilesd (Unix socket)
OLLMrpc.Daemon.rpc_register();
var rpc = new OLLMrpc.Client(
GLib.Path.build_filename(
GLib.Environment.get_user_data_dir(), "ollmchat"),
"ollmfilesd.pid",
"ollmfilesd.sock"
);
if (!yield rpc.connect(new OLLMrpc.Request() {
method = "RPC-Daemon.hello",
args = OLLMrpc.args("is", 1, "my-app")
}, new OLLMrpc.ClientBoot())) {
GLib.error("%s", rpc.connect_error);
}
var resp = yield rpc.call(new OLLMrpc.Request() {
method = "ProjectManager.rpc_load_projects_from_db"
});
HTTPS JSON (e.g. Hugging Face Hub)
OLLMhf.rpc_register();
var rpc = new OLLMrpc.Client("", "", "https://huggingface.co");
yield rpc.connect(new OLLMrpc.Request());
var resp = yield rpc.call(new OLLMrpc.Request() {
method = "/api/models",
args = OLLMrpc.args("o", new OLLMhf.Param.Search() {
search = "llama",
filter = "gguf",
limit = 10
}),
result_type = typeof(OLLMhf.ModelArray)
});
Best Practices
- Registration: call each wire type's rpc_register() before connect
2. Args: pack with args onto
Request.args, not raw maps
3. Results: set result_type when the HTTP path should decode to a GType
4. Errors: check Response.error after every call
5. Bin round-trips: see Bin and docs/bin-rpc-protocol.md
Content:
Namespaces:
- Bin - Binary wire serialization for RPC payloads.
- Http - HTTP verb+path → RPC method and body GTypes.
- Live - Opt-in live GObject handles for
OLLMrpc.
- Transport - Server listen and connection layer
for OLLMrpc.
Interfaces:
Classes:
- Client - Bin RPC client for ollmfilesd, compositor
sockets, and HTTPS JSON APIs.
- ClientBoot - Ensure ollmfilesd is running when
passed to Client.connect.
- Daemon - Wire type for Daemon.hello (one
Daemon on
Response.retval). Client deserializes into this class. Server type is ollmfilesd/Daemon.vala (unchanged).
- Error - Wire error object (code, message,
domain, gerror_code).
- Ffi - Call listed RPC instance methods via libffi.
- FfiOwner - Handler singleton for one add_class
prefix (e.g. Folder).
- FfiSlot - One listed FFI method: C pointer, call
signature, and class.
- Gi - Register GObject types from a typelib and apply RPC
calls to them.
- GiMock - GIR lookup with typed empty replies (no
GI.FunctionInfo.invoke).
- Notification - Bin RPC notification (no matching
Response id).
- Request - Outbound RPC envelope (one root object per
call).
- Response - Inbound RPC envelope — matching
Request.id, plus retval or error.
Error domains:
- RpcErrorCode - JSON-RPC 2.0 standard and
application error codes (throw/catch).
Functions:
- public ArrayList<Value?> args (string signature, ...)
Pack mixed RPC arguments into a Gee.ArrayList
of GLib.Value.
- public void rpc_register (bool live = false)
Register stock envelope types, and optionally the live stack.
- public Value val (string signature, ...)