Skip to content
API reference

backend-definition

Import
import * as api from "@fungi.computer/agar/backend-definition";
Kind Export Description
type alias AppSendBudgetRefusal A declined Session send, with how long to wait before retrying.
type alias MethodPolicy A method’s schemas own both its TypeScript contract and JSON boundary.
type alias ResultRowCodec Decodes and bounds result rows; see resultRows in @fungi.computer/agar/method-presentation.
type alias MethodPresentation How a finished call reads to a person: a pure projection run in the App backend. rows is resultRows from @fungi.computer/agar/method-presentation; only a backend that presents imports it, so one without presentations carries no row decoder.
type alias AppBackendMethod Prepared method export consumed by the backend and its build.
type alias AppBackendMethods The prepared methods of one backend, keyed by their public names.
type alias AppBackendClass Typed backend export shared by a build and its runtime method admission.
type alias AppBackendDefinition A backend’s full generated API: its declared methods, the facet installer, and runtime dispatch by method name.
constant appEventEmitResultSchema EVENTS.emit acknowledges delivery with native void, not a JSON value.
constant appSendBudgetRefusalSchema App-originated Session send refusal; retry advice is a duration, not a timestamp.
constant presentMethodName Name of the generated, hidden read method that projects a finished call into its row.
function defineAppMethod() Define a typed method once; neither discovery nor builds execute its handler.
function defineAppBackend() Generate the API from the method exports; callers cannot supply a second catalog.

AppSendBudgetRefusaltype alias

Section titled “AppSendBudgetRefusal”
Signature
type AppSendBudgetRefusal = z.output<typeof appSendBudgetRefusalSchema>;

A declined Session send, with how long to wait before retrying.


MethodPolicytype alias

Section titled “MethodPolicy”
Signature
type MethodPolicy = Readonly<{
description: string;
effect: "read" | "write" | "external";
requires: readonly AppCapabilityId[];
hidden?: true;
anonymous?: true;
pending?: true;
present?: Readonly<{
verb: string;
}>;
}>;

A method’s schemas own both its TypeScript contract and JSON boundary.


ResultRowCodectype alias

Section titled “ResultRowCodec”
Signature
type ResultRowCodec = Readonly<{
decode: (row) => ResultRow;
schema: z.ZodType;
}>;

Decodes and bounds result rows; see resultRows in @fungi.computer/agar/method-presentation.


MethodPresentationtype alias

Section titled “MethodPresentation”
Signature
type MethodPresentation<I, O> = Readonly<{
verb: string;
row: (call) => ResultRow;
rows: ResultRowCodec;
}>;

How a finished call reads to a person: a pure projection run in the App backend. rows is resultRows from @fungi.computer/agar/method-presentation; only a backend that presents imports it, so one without presentations carries no row decoder.

Type Parameter
I
O

AppBackendMethodtype alias

Section titled “AppBackendMethod”
Signature
type AppBackendMethod<Context> = Readonly<{
policy: MethodPolicy;
input: z.ZodType;
output: z.ZodType;
present?: (input, output) => ResultRow;
presentRow?: z.ZodType;
call: (input, context, caller) => Promise<WhistleJsonValue>;
}>;

Prepared method export consumed by the backend and its build.

Type Parameter Default type
Context void

AppBackendMethodstype alias

Section titled “AppBackendMethods”
Signature
type AppBackendMethods<Context> = Readonly<
Record<string, AppBackendMethod<Context>>
>;

The prepared methods of one backend, keyed by their public names.

Type Parameter Default type
Context void

AppBackendClasstype alias

Section titled “AppBackendClass”
Signature
type AppBackendClass = (...args) => object & object;

Typed backend export shared by a build and its runtime method admission.

Name Type
prototype object

AppBackendDefinitiontype alias

Section titled “AppBackendDefinition”
Signature
type AppBackendDefinition<Context> = Readonly<{
methods: Readonly<Record<string, AppBackendMethod<Context>>>;
sync?: Readonly<{
method: string;
}>;
gills?: readonly AppBackendGill[];
gill: (input, context, caller) => Promise<GillReply>;
toolFamily?: AppApi["toolFamily"];
events?: Readonly<
Record<
string,
Readonly<{
description: string;
payload: z.ZodType;
}>
>
>;
implement: <C>(implementation) => C;
call: (method, input, context, caller) => Promise<WhistleJsonValue>;
}>;

A backend’s full generated API: its declared methods, the facet installer, and runtime dispatch by method name.

Type Parameter Default type
Context void

appEventEmitResultSchemaconstant

Section titled “appEventEmitResultSchema”
Signature
const appEventEmitResultSchema: ZodUndefined;

EVENTS.emit acknowledges delivery with native void, not a JSON value.


appSendBudgetRefusalSchemaconstant

Section titled “appSendBudgetRefusalSchema”
Signature
const appSendBudgetRefusalSchema: ZodLazy<
ZodObject<
{
error: ZodLiteral<"send_budget_exceeded">;
retryAfterMs: ZodNumber;
},
$strict
>
>;

App-originated Session send refusal; retry advice is a duration, not a timestamp.


presentMethodNameconstant

Section titled “presentMethodName”
Signature
const presentMethodName: "present" = "present";

Name of the generated, hidden read method that projects a finished call into its row.

defineAppMethod()function

Section titled “defineAppMethod()”
Signature
function defineAppMethod<I, O, Context>(method): AppBackendMethod<Context>;

Define a typed method once; neither discovery nor builds execute its handler.

Type Parameter Default type
I extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> -
O extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> -
Context void
Parameter Type
method Omit<Readonly<{ description: string; effect: "external" | "read" | "write"; requires: readonly ( | "agent.list" | "agent.manage" | "agent.read" | "agent.send" | "computer.list" | "computer.readFile" | "computer.writeFile" | "computer.execute" | "agent.rename" | "agent.avatar" | "agent.toolPolicy" | "approvals" | "apps.open" | "apps.call" | "llm.generation" | "media.generation" | "games:servers" | "git.repository" | "app.storage" | "app.events.emit" | "team.workbenchHost" | "marketplace.browse" | "marketplace.purchase" | "workflow.run" | "workflow.publish" | "workflow.arm" | "world" | "channels.read" | "channels.personal.manage")[]; hidden?: true; anonymous?: true; pending?: true; present?: Readonly<{ verb: string; }>; }>, "present"> & { input: I; output: O; present?: Readonly<{ verb: string; row: (call: Readonly<{ input: output<I>; output: output<O>; }>) => { readonly id: string; readonly title: string; … 4 more …; readonly media?: { …; } | undefined; }; rows: Readonly<…>; }> | undefined; } & ({ …; } | { …; })

AppBackendMethod<Context>


defineAppBackend()function

Section titled “defineAppBackend()”
Signature
function defineAppBackend<Context>(options): AppBackendDefinition<Context>;

Generate the API from the method exports; callers cannot supply a second catalog.

Type Parameter Default type
Context void
Parameter Type
options Readonly<{ methods: Readonly<Record<string, AppBackendMethod<Context>>>; events?: AppBackendDefinition<Context>["events"]; gills?: readonly AppBackendGill[]; sync?: AppBackendDefinition<Context>["sync"]; toolFamily?: AppBackendDefinition<Context>["toolFamily"]; }>

AppBackendDefinition<Context>

Re-exports AppBackendGill


Re-exports pending


Re-exports pendingSchema


Re-exports Pending