import { t as StandardSchemaV1 } from "./index-CeEtxDmK.mjs"; //#region src/rpc/utils.d.ts /** Infers a TypeScript argument tuple from a Standard Schema array */ type InferArgsType = S extends readonly [] ? [] : S extends readonly [infer H, ...infer T] ? H extends StandardSchemaV1 ? T extends readonly StandardSchemaV1[] ? [StandardSchemaV1.InferInput, ...InferArgsType] : never : never : never; /** Infers a TypeScript return type from a Standard Schema */ type InferReturnType = S extends StandardSchemaV1 ? StandardSchemaV1.InferInput : void; //#endregion //#region src/rpc/types.d.ts type Thenable = T | Promise; type EntriesToObject = { [K in T[number] as K[0]]: K[1]; }; /** * Type of the RPC function, * - static: A function that returns a static data, no arguments (can be cached and dumped) * - action: A function that performs an action (no data returned) * - event: A function that emits an event (no data returned), and does not wait for a response * - query: A function that queries a resource * * By default, the function is a query function. */ type RpcFunctionType = 'static' | 'action' | 'event' | 'query'; /** * Agent exposure settings for an RPC function. When this field is set, * the function is surfaced to agents (e.g. via the devframe MCP adapter) * as a callable tool. Functions without an `agent` field are not exposed; * default-deny. */ interface RpcFunctionAgentOptions { /** * Human-readable description shown to the agent. Required, since agents * rely on this to decide when to invoke the tool. Keep it to ~1–3 * sentences explaining what the tool does and when to use it. */ description: string; /** * Optional human-friendly display title. Maps to the MCP tool `title` * annotation. Falls back to the RPC function `name` when omitted. */ title?: string; /** * Safety classification. Drives MCP annotations (`readOnlyHint`, * `destructiveHint`) downstream. * - `'read'`: no side effects; safe to call freely. * - `'action'`: mutates state but not destructive. * - `'destructive'`: may perform destructive updates. * * When omitted it is inferred from the function `type`: * - `'static'` / `'query'` → `'read'` * - `'action'` / `'event'` → `'action'` */ safety?: 'read' | 'action' | 'destructive'; /** Free-form tags for grouping or filtering. */ tags?: readonly string[]; /** * Optional example invocations shown to agents. Returned verbatim in * the agent manifest. */ examples?: readonly { args: unknown[]; description?: string; }[]; } /** * Manages dynamic function registration and provides a type-safe proxy for accessing functions. */ interface RpcFunctionsCollector { /** User-provided context passed to setup functions */ context: SetupContext; /** Type-safe proxy for calling registered functions */ readonly functions: LocalFunctions; /** Map of registered function definitions keyed by function name */ readonly definitions: Map>; /** Register a new function definition. Pass `force` to overwrite an existing one. */ register: (fn: RpcFunctionDefinitionAnyWithContext, force?: boolean) => void; /** Update an existing function definition. Pass `force` to register it if it doesn't exist yet. */ update: (fn: RpcFunctionDefinitionAnyWithContext, force?: boolean) => void; /** Subscribe to function changes, returns unsubscribe function */ onChanged: (fn: (id?: string) => void) => (() => void); } /** * Result returned by a function's setup method. */ interface RpcFunctionSetupResult { /** Function handler */ handler?: (...args: ARGS) => RETURN; /** Optional dump definition (overrides definition-level dump) */ dump?: RpcDumpDefinition; } /** * Positional argument schemas for an RPC function. Each entry is any * [Standard Schema](https://standardschema.dev)-compliant validator * (valibot, zod, arktype, …); the entry at index `i` validates argument * `i` at call time and drives that argument's inferred type. */ type RpcArgsSchema = readonly StandardSchemaV1[]; /** * Return-value schema for an RPC function. Any * [Standard Schema](https://standardschema.dev)-compliant validator; it * validates the handler's resolved return value and drives its inferred * type. */ type RpcReturnSchema = StandardSchemaV1; /** * Serialized representation of a thrown value in a dump record. * * Errors are stored as plain objects so they round-trip through both the * strict-JSON and structured-clone codecs. `message` and `name` are always * present; `cause` and any own enumerable properties of the original * `Error` are preserved on a best-effort basis. Non-`Error` throws are * normalized to `{ name: 'Error', message: String(thrown) }`. */ interface RpcDumpRecordError { /** Error message (mirrors `Error.message`). */ message: string; /** Error type name (e.g., "Error", "TypeError"). */ name: string; /** `Error.cause`, recursively serialized when it is itself an `Error`. */ cause?: unknown; /** Own enumerable properties of the original error (excluding `message`/`name`/`cause`). */ [key: string]: unknown; } /** * Single record in a dump store with pre-computed results. */ interface RpcDumpRecord { /** Function arguments */ inputs: ARGS; /** Result (value or lazy function) */ output?: RETURN; /** Error if execution failed */ error?: RpcDumpRecordError; } /** * Defines argument combinations to pre-compute for a function. */ interface RpcDumpDefinition { /** Argument combinations to pre-compute by executing handler */ inputs?: ARGS[]; /** Pre-computed records to use directly (bypasses handler execution) */ records?: RpcDumpRecord[]; /** Fallback value when no match found */ fallback?: RETURN; } /** * Dynamically generates dump definitions based on context. */ type RpcDumpGetter = (context: CONTEXT, handler: (...args: ARGS) => RETURN) => Thenable>; /** * Dump configuration (static object or dynamic function). */ type RpcDump = RpcDumpDefinition | RpcDumpGetter; /** Shared fields for an RPC function definition. */ interface RpcFunctionDefinitionBase { /** Function name (unique identifier) */ name: NAME; /** Function type (static, action, event, or query) */ type?: TYPE; /** Whether the function results should be cached */ cacheable?: boolean; /** * Selects the serialization format for arguments and return values. * * - `true`: uses strict JSON encoding (default when `agent` is set). * - `false` (default otherwise): uses structured-clone encoding and supports values * such as `Map`, `Set`, `Date`, and cycles. Functions using this mode * cannot be agent-exposed. */ jsonSerializable?: boolean; /** * Expose this function to agents (e.g. via the MCP adapter). * When omitted, the function is not agent-exposed (default-deny). */ agent?: RpcFunctionAgentOptions; /** Setup function called with context to initialize handler and dump */ setup?: (context: CONTEXT) => Thenable>; /** Function implementation (required if setup doesn't provide one) */ handler?: (...args: ARGS) => RETURN; /** Dump definition (setup dump takes priority) */ dump?: RpcDump; /** * Sugar for "query in dev, single baked snapshot in build": when * `true` and no `dump` is provided, the build adapter runs the * handler once with no arguments and stores the result as both a * no-args record and the fallback so any call variant resolves * to the same snapshot. Only valid on `query` (or untyped) * functions; `static` already has equivalent default behavior. */ snapshot?: boolean; /** Per-context setup-result cache, populated by `getRpcResolvedSetupResult`. @internal */ __cache?: WeakMap>>; /** Single-slot fallback for primitive contexts. @internal */ __promise?: Thenable>; } /** * Dump store containing pre-computed results. * Flat structure for serialization and efficient lookups. */ interface RpcDumpStore { /** Function definitions keyed by name */ definitions: Record>; /** Records keyed by '---' or '---fallback' */ records: Record Promise)>; /** @internal */ _functions?: T; } /** RPC function definition whose handler supplies its argument and return types. */ interface RpcFunctionDefinitionWithoutSchemas extends RpcFunctionDefinitionBase { /** Standard Schema array validating (and typing) the arguments */ args?: AS; /** Standard Schema validating (and typing) the return value */ returns?: RS; } /** RPC function definition whose argument and return types come from schemas. */ interface RpcFunctionDefinitionWithSchemas extends RpcFunctionDefinitionBase, Thenable>, CONTEXT> { /** Standard Schema array validating (and typing) the arguments */ args: AS; /** Standard Schema validating (and typing) the resolved return value */ returns: RS; } /** * Dump client options. */ interface RpcDumpClientOptions { /** Called when arguments don't match any pre-computed entry */ onMiss?: (functionName: string, args: any[]) => void; } /** * Options for collecting dumps. */ interface RpcDumpCollectionOptions { /** * Concurrency control for parallel execution. * - `false` or `undefined`: sequential execution (default) * - `true`: parallel execution with concurrency limit of 5 * - `number`: parallel execution with specified concurrency limit */ concurrency?: boolean | number | null; } /** * RPC function definition with optional dump support. */ type RpcFunctionDefinition = [AS, RS] extends [undefined, undefined] ? RpcFunctionDefinitionWithoutSchemas : RpcFunctionDefinitionWithSchemas; type RpcFunctionDefinitionToFunction = T extends { args: infer AS; returns: infer RS; } ? AS extends RpcArgsSchema ? RS extends RpcReturnSchema ? (...args: InferArgsType) => InferReturnType : never : never : T extends RpcFunctionDefinition ? (...args: ARGS) => RETURN : never; type RpcFunctionDefinitionAny = RpcFunctionDefinition; type RpcFunctionDefinitionAnyWithContext = RpcFunctionDefinition; type RpcDefinitionsToFunctions = EntriesToObject<{ [K in keyof T]: [T[K]['name'], RpcFunctionDefinitionToFunction]; }>; /** * Like {@link RpcDefinitionsToFunctions}, but prefixes every (bare) * definition name with `:`. Use this when functions are defined with * bare names and registered through a scoped context * (`ctx.scope(NS).rpc.register(...)`), so the augmented registry keys * match the namespaced ids stored at runtime. */ type RpcDefinitionsToFunctionsWithNamespace = EntriesToObject<{ [K in keyof T]: [`${NS}:${T[K]['name'] & string}`, RpcFunctionDefinitionToFunction]; }>; type RpcDefinitionsFilter = { [K in keyof T]: T[K] extends { type: Type; } ? T[K] : never; }; //#endregion export { RpcFunctionType as C, InferArgsType as D, Thenable as E, InferReturnType as O, RpcFunctionSetupResult as S, RpcReturnSchema as T, RpcFunctionDefinitionAnyWithContext as _, RpcDefinitionsToFunctionsWithNamespace as a, RpcFunctionDefinitionWithSchemas as b, RpcDumpCollectionOptions as c, RpcDumpRecord as d, RpcDumpRecordError as f, RpcFunctionDefinitionAny as g, RpcFunctionDefinition as h, RpcDefinitionsToFunctions as i, RpcDumpDefinition as l, RpcFunctionAgentOptions as m, RpcArgsSchema as n, RpcDump as o, RpcDumpStore as p, RpcDefinitionsFilter as r, RpcDumpClientOptions as s, EntriesToObject as t, RpcDumpGetter as u, RpcFunctionDefinitionBase as v, RpcFunctionsCollector as w, RpcFunctionDefinitionWithoutSchemas as x, RpcFunctionDefinitionToFunction as y };