import type { z } from "zod"; /** * UI visualization configuration for MCP Apps */ export interface UiConfig { /** Type of visualization to render */ type?: "table" | "chart" | "auto"; /** Chart type when type is "chart" */ chartType?: "line" | "bar"; /** Field to use for x-axis in charts */ xAxis?: string; /** Field(s) for left Y-axis */ leftYAxis?: string | string[]; /** Field(s) for right Y-axis */ rightYAxis?: string | string[]; /** @deprecated Use leftYAxis instead */ yAxis?: string; } /** * Configuration for an environment (dev, test, prod) */ export interface EnvironmentConfig { /** Enable debug mode */ debug?: boolean; /** Any additional environment-specific settings */ [key: string]: unknown; } /** * Configuration for an access group */ export interface AccessGroupConfig { /** Description of this access group */ description: string; } /** * Definition of an entity in the ontology */ export interface EntityDefinition { /** Human-readable description of this entity */ description: string; } /** * Option returned by functions used as field sources. * Functions referenced by `fieldFrom()` should return an array of these. */ export interface FieldOption { /** The stored value */ value: string; /** Human-readable label for display */ label: string; } /** * Context passed to resolvers */ export interface ResolverContext { /** Current environment name */ env: string; /** Environment configuration */ envConfig: EnvironmentConfig; /** Logger instance */ logger: { info: (message: string, ...args: unknown[]) => void; warn: (message: string, ...args: unknown[]) => void; error: (message: string, ...args: unknown[]) => void; debug: (message: string, ...args: unknown[]) => void; }; /** Access groups for the current request */ accessGroups: string[]; } /** * Resolver function signature */ export type ResolverFunction = ( ctx: ResolverContext, args: TArgs ) => Promise | TResult; /** * Definition of a function in the ontology */ export interface FunctionDefinition< TGroups extends string = string, TEntities extends string = string, TInputs extends z.ZodType = z.ZodType, TOutputs extends z.ZodType = z.ZodType, > { /** Human-readable description of what this function does */ description: string; /** Which access groups can call this function */ access: TGroups[]; /** Which entities this function relates to (use empty array [] if none) */ entities: TEntities[]; /** Zod schema for input validation */ inputs: TInputs; /** Zod schema for output validation */ outputs: TOutputs; /** Resolver function that handles this function's logic */ resolver: ResolverFunction, z.infer>; /** Enable UI visualization via MCP Apps. Set to true for auto-detection or provide config. */ ui?: boolean | UiConfig; /** Whether this function is read-only (query) or has side effects (mutation) */ isReadOnly: boolean; } /** * Result returned by the auth function */ export interface AuthResult { /** Access groups for the current request */ groups: string[]; /** Optional user identity for row-level access control */ user?: Record; /** Optional organization context for multi-tenant applications */ organization?: Record; } /** * Cloud service configuration */ export interface CloudConfig { /** Override the hosted URL (for testing or self-hosted) */ url?: string; } /** * Auth function that determines access groups for a request. * Can return either: * - `string[]` - just group names (backwards compatible) * - `AuthResult` - groups plus optional user identity */ export type AuthFunction = (req: Request) => Promise | string[] | AuthResult; /** * The main Ontology configuration object */ export interface OntologyConfig< TGroups extends string = string, TEntities extends string = string, TFunctions extends Record< string, FunctionDefinition > = Record>, > { /** Name of this ontology/API */ name: string; /** * Unique identifier for this ontology instance. * Auto-generated by `ont-run init`. Used for cloud service registration. */ uuid?: string; /** * Enable connection to ont-run.com cloud services. * Set to `true` to connect with defaults, or provide config object. * The cloud provides AI agent access, version history, and team features. */ cloud?: boolean | CloudConfig; /** Environment configurations */ environments: Record; /** Pluggable auth function */ auth: AuthFunction; /** Access group definitions */ accessGroups: Record; /** Entity definitions for categorization */ entities?: Record; /** Function definitions */ functions: TFunctions; }