Appearance
Function: defineApp()
ts
function defineApp<M>(spec): App<M>;Turns an author's spec into the module's exports. Each export reads its envelope with Host.inputString(), builds the context over the host functions (Host.getFunctions(), each called with the offset of a Memory block holding its JSON request and answering the offset of its JSON answer), runs the handler, and answers with Host.outputString(): { status: 'ok', output }, { status: 'pending', externalId } or { status: 'error', message, retryable? } for invoke; { status: 'event', event }, { status: 'ignored' }, { status: 'rejected', message } for handle_webhook; { status: 'ok', handoff } for handoff. An action's input is parsed with its zod schema (defaults applied) and the config with configSchema; a thrown AppError becomes the error answer with its retryable, any other throw an error answer without it. A handler may return a Promise: its answer is written when the Promise settles, which happens before the export returns. Every export answers 0; the failures are in the answers.
Calling defineApp installs fetch on globalThis (fetch.ts) for the module's lifetime.
Type Parameters
M
M extends AppManifestSpec<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>, Record<string, ActionSpec<ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>>>
Parameters
spec
AppSpec<M>
Returns
App<M>