/** * This file was generated by @pikku/cli@0.12.89 */ /** * Core function, middleware, and permission types for all wirings */ import type { CorePikkuMiddleware, CorePermissionGroup, ListInput, ListOutput, PikkuWire, PickRequired } from '@pikku/core'; import type { CorePikkuFunctionConfig, CorePikkuAuth, CorePikkuAuthConfig, CorePikkuPermission } from '@pikku/core/function'; import { CreateWireServices } from '@pikku/core/internal'; import type { NodeType } from '@pikku/core/node'; import type { ScopeId } from '../scopes/pikku-scopes.gen.js'; import type { StandardSchemaV1 } from '@standard-schema/spec'; import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'; import type { UserSession } from '../../types/application-types.d.js'; import type { SingletonServices } from '../../types/application-types.d.js'; import type { Services } from '../../types/application-types.d.js'; import type { Config } from '../../types/application-types.d.js'; import type { TypedPikkuRPC, FlattenedRPCMap } from '../rpc/pikku-rpc-wirings-map.internal.gen.d.js'; import type { RequiredSingletonServices, RequiredWireServices } from '../pikku-services.gen.js'; import type { TypedWorkflow, TypedScenario } from '../workflow/pikku-workflow-types.gen.js'; export type { SingletonServices as SingletonServices }; export type { Services as Services }; export type Session = UserSession; /** * The services a wired function actually receives. The inspector records which * services each wired `func`, `permissions` and `middleware` destructures and * emits them as `RequiredSingletonServices`; intersecting that here makes those * services **non-optional** at every call site. A service is optional only when * nothing destructures it — in which case it is never created either. This is * why an `if (!service)` guard inside a function body is always dead code. */ export type WiredSingletonServices = RequiredSingletonServices & SingletonServices; export type WiredServices = RequiredSingletonServices & Services; /** * Inline node configuration for function definitions. */ export type NodeConfig = { displayName: string; category: string; type: NodeType; errorOutput?: boolean; }; /** * Type-safe API permission definition that integrates with your application's session type. * Use this to define authorization logic for your API endpoints. * * @template In - The input type that the permission check will receive * @template RequiredServices - The services required for this permission check */ export type PikkuPermission = CorePikkuPermission>; /** * Type-safe middleware definition that can access your application's services and session. * Use this to define reusable middleware that can be applied to multiple wirings. * * @template RequiredServices - The services required for this middleware */ export type PikkuMiddleware = CorePikkuMiddleware; /** * Configuration object for creating a permission with metadata */ export type PikkuPermissionConfig = { /** The permission function */ func: PikkuPermission; /** Optional human-readable name for the permission */ name?: string; /** Optional description of what the permission checks */ description?: string; }; /** * Factory function for creating permissions with tree-shaking support. * Supports both direct function and configuration object syntax. * * @example * ```typescript * // Direct function syntax * const permission = pikkuPermission(async ({ logger }, data, { session }) => { * const session = await session?.get() * return session?.role === 'admin' * }) * * // Configuration object syntax with metadata * const adminPermission = pikkuPermission({ * name: 'Admin Permission', * description: 'Checks if user has admin role', * func: async ({ logger }, data, { session }) => { * const session = await session?.get() * return session?.role === 'admin' * } * }) * ``` */ export declare const pikkuPermission: (permission: PikkuPermission | PikkuPermissionConfig) => PikkuPermission; /** * Type-safe auth-only permission that only needs services and session. * Use this for upfront authorization gates (MCP tools, AI agents, workflows) * where request data isn't available yet. * * @template RequiredServices - The services required for this auth check */ export type PikkuAuth = CorePikkuAuth; /** * Configuration object for creating an auth permission with metadata */ export type PikkuAuthConfig = CorePikkuAuthConfig; /** * Factory function for creating auth-only permissions with tree-shaking support. * Auth permissions only receive services and session (no request data), * making them evaluable before request data is available. * * @example * \`\`\`typescript * const isAuthenticated = pikkuAuth(async ({ logger }, session) => { * return !!session * }) * * const isAdmin = pikkuAuth({ * name: 'Admin Auth', * description: 'Checks if user is an admin', * func: async ({ logger }, session) => { * return session?.role === 'admin' * } * }) * \`\`\` */ export declare const pikkuAuth: (auth: PikkuAuth | PikkuAuthConfig) => PikkuPermission; /** * Configuration object for creating middleware with metadata */ export type PikkuMiddlewareConfig = { /** The middleware function */ func: PikkuMiddleware; /** Optional human-readable name for the middleware */ name?: string; /** Optional description of what the middleware does */ description?: string; }; /** * Factory function for creating middleware with tree-shaking support. * Supports both direct function and configuration object syntax. * * @example * ```typescript * // Direct function syntax * const middleware = pikkuMiddleware(({ logger }, wires, next) => { * logger.info('Middleware executed') * await next() * }) * * // Configuration object syntax with metadata * const logMiddleware = pikkuMiddleware({ * name: 'Request Logger', * description: 'Logs all incoming requests', * func: async ({ logger }, wires, next) => { * logger.info('Request started') * await next() * } * }) * ``` */ export declare const pikkuMiddleware: (middleware: PikkuMiddleware | PikkuMiddlewareConfig) => PikkuMiddleware; /** * Factory function for creating middleware factories * Use this when your middleware needs configuration/input parameters * * @example * ```typescript * export const logMiddleware = pikkuMiddlewareFactory(({ * message, * level = 'info' * }) => { * return pikkuMiddleware(async ({ logger }, next) => { * logger[level](message) * await next() * }) * }) * ``` */ export declare const pikkuMiddlewareFactory: (factory: (input: In) => PikkuMiddleware) => ((input: In) => PikkuMiddleware); /** * Factory function for creating permission factories * Use this when your permission needs configuration/input parameters * * @example * ```typescript * export const requireRole = pikkuPermissionFactory<{ role: string }>(({ * role * }) => { * return pikkuPermission(async ({ logger }, data, { session }) => { * if (!session || session.role !== role) { * logger.warn(`Permission denied: required role '${role}'`) * return false * } * return true * }) * }) * ``` */ export declare const pikkuPermissionFactory: (factory: (input: In) => PikkuPermission) => ((input: In) => PikkuPermission); /** * A function that generates a human-readable description of a pending approval action. * Used by AI agents to show meaningful approval prompts instead of raw tool arguments. * * @template In - The input type (same as the function it describes) * @template RequiredServices - The services required for this description function */ export type PikkuApprovalDescription = (services: RequiredServices, data: In) => Promise; /** * Factory function for creating approval description functions with tree-shaking support. * * @example * ```typescript * export const deleteTodoApproval = pikkuApprovalDescription( * async ({ todoStore }, { id }) => { * const todo = await todoStore.get(id) * return \`Delete todo: "${todo.title}"\` * } * ) * ``` */ export declare const pikkuApprovalDescription: (fn: PikkuApprovalDescription) => PikkuApprovalDescription; /** * A sessionless API function that doesn't require user authentication. * Use this for public endpoints, health checks, or operations that don't need user context. * * @template In - The input type * @template Out - The output type that the function returns * @template RequiredServices - Services required by this function */ export type PikkuFunctionSessionless = CorePikkuFunctionSessionless, RequiredWires>>; /** * A session-aware API function that requires user authentication. * Use this for protected endpoints that need access to user session data. * * @template In - The input type * @template Out - The output type that the function returns * @template RequiredServices - Services required by this function */ export type PikkuFunction = CorePikkuFunction, RequiredWires>>; /** * Helper type to infer the output type from a Standard Schema */ export type InferSchemaOutput = T extends StandardSchemaV1 ? Output : never; /** * Configuration object for Pikku functions with optional middleware, permissions, tags, and documentation. * This type wraps CorePikkuFunctionConfig with the user's custom types. * * @template In - The input type * @template Out - The output type * @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless) */ export type PikkuFunctionConfig | PikkuFunctionSessionless = PikkuFunction | PikkuFunctionSessionless, InputSchema extends StandardSchemaV1 | undefined = undefined, OutputSchema extends StandardSchemaV1 | undefined = undefined> = CorePikkuFunctionConfig, PikkuMiddleware, InputSchema, OutputSchema, ScopeId>; /** * Configuration object for Pikku functions with Zod schema validation. * Use this when you want to define input/output schemas using Zod. * Types are automatically inferred from the schemas. */ type SchemaInferred = S extends StandardSchemaV1 ? InferSchemaOutput : Fallback; /** * Schema-overload variant for pikkuFunc. Derived from CorePikkuFunctionConfig * so adding a field on the core type automatically propagates here. */ export type PikkuFunctionConfigWithSchema = Omit, SchemaInferred, RequiredWires> | PikkuFunctionSessionless, SchemaInferred, RequiredWires>, CorePikkuPermission, PikkuMiddleware, undefined, undefined, ScopeId>, 'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'> & { func: PikkuFunction, SchemaInferred, RequiredWires> | PikkuFunctionSessionless, SchemaInferred, RequiredWires>; input?: InputSchema; output?: OutputSchema; permissions?: InputSchema extends StandardSchemaV1 ? CorePermissionGroup>> : undefined; approvalDescription?: InputSchema extends StandardSchemaV1 ? PikkuApprovalDescription> : never; }; /** * Creates a Pikku function that can be either session-aware or sessionless. * This is the main function wrapper for creating API endpoints. * * Define the input and output with Zod schemas — the function's types are * inferred from them, and the schemas double as runtime validation. * * @param config - Function definition with `input`/`output` Zod schemas and `func`. * @returns The normalized configuration object * * @example * ```typescript * const createUserInput = z.object({ name: z.string(), email: z.string() }) * const createUserOutput = z.object({ id: z.number() }) * * const createUser = pikkuFunc({ * input: createUserInput, * output: createUserOutput, * func: async ({db}, input) => { * // input is typed as { name: string, email: string } * const user = await db.users.create(input) * return { id: user.id } // must match output schema * } * }) * ``` */ export declare function pikkuFunc(config: PikkuFunctionConfigWithSchema): PikkuFunctionConfig : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput : unknown, 'session' | 'rpc'>; export declare function pikkuFunc(func: PikkuFunction | PikkuFunctionConfig): PikkuFunctionConfig; export type PikkuListFunction = {}, Row = unknown, S extends string = never> = PikkuFunction, ListOutput, 'session' | 'rpc'> | PikkuFunctionSessionless, ListOutput, 'session' | 'rpc'>; export declare const pikkuListFunc: = {}, Row = unknown, S extends string = never>(config: PikkuFunctionConfig, ListOutput, "session" | "rpc">) => PikkuFunctionConfig, ListOutput, "session" | "rpc">; /** * Configuration object for sessionless Pikku functions with Zod schema validation. */ /** * Schema-overload variant for pikkuSessionlessFunc. Derived from * CorePikkuFunctionConfig to stay in sync with the generic-typed config. */ export type PikkuFunctionSessionlessConfigWithSchema = Omit, SchemaInferred, RequiredWires>>, 'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'> & { func: PikkuFunctionSessionless, SchemaInferred, RequiredWires>; input?: InputSchema; output?: OutputSchema; permissions?: InputSchema extends StandardSchemaV1 ? CorePermissionGroup>> : undefined; approvalDescription?: InputSchema extends StandardSchemaV1 ? PikkuApprovalDescription> : never; }; /** * Creates a sessionless Pikku function that doesn't require user authentication. * Use this for public endpoints, webhooks, or background tasks. * * Define the input and output with Zod schemas — the function's types are * inferred from them, and the schemas double as runtime validation. * * @param config - Function definition with `input`/`output` Zod schemas and `func`. * @returns The normalized configuration object * * @example * ```typescript * const greetInput = z.object({ name: z.string() }) * const greetOutput = z.object({ message: z.string() }) * * const greet = pikkuSessionlessFunc({ * input: greetInput, * output: greetOutput, * func: async (_services, { name }) => { * return { message: `Hello, ${name}!` } * } * }) * ``` */ export declare function pikkuSessionlessFunc(config: PikkuFunctionSessionlessConfigWithSchema): PikkuFunctionConfig : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput : unknown, 'session' | 'rpc'>; export declare function pikkuSessionlessFunc(func: PikkuFunctionSessionless | PikkuFunctionConfig): PikkuFunctionConfig; /** * Creates a function that takes no input and returns no output. * Useful for health checks, triggers, or cleanup operations. * * @param func - Function definition, either direct function or configuration object * @returns The normalized configuration object * * @example * ```typescript * const cleanupTempFiles = pikkuVoidFunc(async ({fileSystem, logger}) => { * logger.info('Starting cleanup of temporary files') * await fileSystem.deleteDirectory('/tmp/uploads') * logger.info('Cleanup completed') * }) * ``` */ export declare const pikkuVoidFunc: (func: PikkuFunctionSessionless | PikkuFunctionConfig) => PikkuFunctionConfig | PikkuFunction, undefined, undefined>; /** * References a registered function by name for use in any wiring. * Works for both local and addon functions — resolves via RPC at runtime. * * @template Name - The function name (must be a key in FlattenedRPCMap) * @param rpcName - The name of the function to reference * @returns A Pikku function config that proxies calls via RPC * * @example * ```typescript * // Use in agent tools * tools: [ref('todos:listTodos'), ref('myLocalFunc')] * * // Use in HTTP wiring * wireHTTP({ route: '/greet', method: 'post', func: ref('greet') }) * ``` */ export declare const ref: (rpcName: Name) => PikkuFunctionConfig; /** * Creates a Pikku config factory. * Use this to define your application's configuration factory. * * @param func - Config factory function that returns your application's config * @returns The config factory function * * @example * ```typescript * export const createConfig = pikkuConfig(async () => { * return { * apiUrl: process.env.API_URL || 'http://localhost:3000', * dbUrl: process.env.DATABASE_URL * } * }) * ``` */ export declare const pikkuConfig: (func: (variables?: any, ...args: any[]) => Promise) => (variables?: any, ...args: any[]) => Promise; /** * Creates a Pikku singleton services factory. * Use this to define services that are created once and shared across all requests. * * @param func - Singleton services factory function * @returns The singleton services factory function * * @example * ```typescript * export const createSingletonServices = pikkuServices(async (config, existingServices) => { * return { * config, * logger: new CustomLogger(), * db: await createDatabaseConnection(config.dbUrl) * } * }) * ``` */ export declare const pikkuServices: (func: (config: Config, existingServices: Partial) => Promise>>) => (config: Config, existingServices?: Partial) => Promise; /** * Creates a Pikku wire services factory. * Use this to define services that are created per-request/session. * * @param func - Wire services factory function * @returns The wire services factory function * * @example * ```typescript * export const createWireServices = pikkuWireServices(async (services, wire) => { * const session = await wire.session?.get() * return { * userCache: new UserCache(session?.userId) * } * }) * ``` */ export declare const pikkuWireServices: (func: (services: SingletonServices, wire: any) => Promise) => CreateWireServices; /** * Tag-scoped middleware. Applies to any wiring that carries the matching tag. * * @example * addTagMiddleware('admin', [adminMiddleware]) */ export declare const addTagMiddleware: (tag: string, middleware: PikkuMiddleware[]) => void; /** * Wire-agnostic global middleware. Runs at the top of every wiring's * middleware chain — before wire-, tag-, and function-level entries. * * Resolution order: global -> wire -> tag -> function. * * @example * addGlobalMiddleware([telemetryMiddleware]) */ export declare const addGlobalMiddleware: (middleware: PikkuMiddleware[]) => void; /** * Wire-agnostic global permissions. Runs at the top of every wiring's * permission resolution — before wire-, tag-, and function-level entries. * * Resolution order: global -> wire -> tag -> function. * * @example * addGlobalPermission([signedInUser]) */ export declare const addGlobalPermission: (permissions: CorePermissionGroup> | PikkuPermission[]) => void; export { wireAddon, wireRemoteAddon } from '@pikku/core/rpc'; export type { WireAddonConfig, WireRemoteAddonConfig, RemoteAddonAuth } from '@pikku/core/rpc'; /** * Addon contract references. Generated from each wired addon's published * contract metadata — no addon source is imported. Functions are proxied via * ref() (RPC) exactly like ref('namespace:fn'). */ declare const __addonHttp: {}; declare const __addonChannel: {}; declare const __addonCli: {}; export declare const refHTTP: (name: Name, options?: { basePath?: string; }) => (typeof __addonHttp)[Name]; export declare const refChannel: (name: Name) => (typeof __addonChannel)[Name]; export declare const refCLI: (name: Name) => (typeof __addonCli)[Name];