/** * Function runtime — the Bun process that loads and executes TypeScript functions. * * Protocol: NDJSON over stdin/stdout. * * Usage: * bun run packages/functions/src/runtime.ts ./functions * * Design: * - A single reader consumes lines from stdin and dispatches by message type. * - Incoming `call` messages launch a handler. * - Incoming `result` messages resolve a pending RPC keyed by call_id. * - Each call's handler has at most ONE outstanding RPC at a time (it awaits * each ctx.db / ctx.scheduler / ctx.runMutation call), so the map never * needs to queue multiple RPCs per call_id. */ import type { DbReader, DbWriter, Llm, Rooms, Workflows } from "./types"; export declare function buildDbReader(callId: string, ssrRead?: boolean): DbReader; export declare function buildSsrFnCaller(callId: string): (name: string, args?: Record) => Promise; export declare function buildDbWriter(callId: string): DbWriter; /** * Build the LLM client that round-trips through the host runtime. * * Each call emits an `llm_complete` protocol message; the runtime * forwards to the configured provider (PYLON_LLM_PROVIDER) and replies * with the parsed response. The host enforces model-allowlist gating * for non-admin callers — that's why the API key never leaves the * server process. * * Errors carry an `err.code` so handlers can branch on `LLM_NOT_CONFIGURED` * vs `PROVIDER_HTTP_429` vs `MODEL_NOT_ALLOWED` without parsing message * strings. */ export declare function buildLlm(callId: string): Llm; /** * Build the room broadcaster. One `room_broadcast` message per call; * the host fans the event out through the same RoomManager the * `/api/rooms/*` routes use, so a server push and a member push land * on subscribers identically. */ export declare function buildRooms(callId: string): Rooms; /** * Build `ctx.workflows` — start a durable workflow or deliver an event * to a waiting one, from mutation/action code. Round-trips a * `workflow_op` frame to the host's WorkflowEngine; the engine's driver * takes it from there, so `start` returns the instance id immediately. * Uses the queued call_id-keyed `rpc` (the reply carries no op_id). */ export declare function buildWorkflows(callId: string): Workflows;