Skip to content
Quickstart

Quickstart

App contract for fungi.computer: typed backend methods, host capabilities and the App frontend connection

Define an App backend once. Its Zod schemas give the handler its TypeScript contract and produce the JSON Schema API a host shows to Agents as tools. This example runs in plain Node; no host is needed to define or call a method.

quickstart.ts
import * as z from "zod";
import {
defineAppBackend,
defineAppMethod,
} from "@fungi.computer/agar/backend-definition";
import { buildAppApi } from "@fungi.computer/agar/backend-declaration";
const notes = new Map<string, string>();
const appBackend = defineAppBackend({
methods: {
saveNote: defineAppMethod({
description: "Save a note under a title",
effect: "write",
requires: [],
input: z.object({ title: z.string().min(1), text: z.string() }),
output: z.object({ saved: z.boolean() }),
handler: ({ title, text }) => {
notes.set(title, text);
return { saved: true };
},
}),
},
});
const api = buildAppApi(appBackend);
console.log(Object.keys(api.methods)); // ["saveNote"]
const result = await appBackend.call(
"saveNote",
{ title: "hello", text: "from Agar" },
undefined,
{ computerId: null, actor: { kind: "member", memberId: "member_example" } },
);
console.log(result); // { saved: true }

An App imports connectApp from @fungi.computer/agar and operation helpers from the declared subpaths. A plain top-level page has no Fungi parent to connect to. Use a host-mounted App or the existing host fixtures for development.