useService is a focused wrapper for talking to your own pack’s backend. It picks the right transport automatically — NATS when your pack runs under KhalOS, Tauri IPC when it runs as a standalone desktop export — and exposes a single interface either way.
Use useService when the other end is your pack’s own service. Use useNats directly when you need broadcast, cross-pack pub/sub, or subjects outside your pack’s prefix.
Signature
Your pack’s
id (matches the id in khal-app.json). Used as the NATS subject prefix.true when the underlying transport is online.Which transport the hook is using right now. Detected from
window.__TAURI__.RPC-style call. The hook forms the full subject from
appId + action — you pass short action names like 'agents.list'.Fire-and-forget publish to your service’s action subject.
Subscribe to events your service publishes under
events.<event>.Port mappings the platform exposes for your service. Populated after first connect.
Resolve an
internalPort declared in your manifest to a local proxy URL. Returns null if no mapping exists yet.Example — request / reply
msg.respond(...) — the same pattern pack-terminal’s spawn handler uses.
Example — subscribe to events
When to use useService vs useNats
Use useService
Calling your own pack’s backend. Short action names, automatic subject prefixing, works the same in desktop export mode.
Use useNats
Broadcasting to the org, listening to other packs, or using any subject outside
khal.<orgId>.<yourAppId>.*.HTTP ports
If your service also serves HTTP (health checks, a small API), declare the ports in your manifest and resolve the local proxy URL withgetUrl:
What’s next
Backend overview
The other side of the wire — what a pack service looks like.
Full-stack pack
End-to-end pattern: frontend hook + Bun service + NATS.