/** * OpenAPI schema collapsing utilities for agentic clients. * * These utilities implement a three-tier disclosure model for OpenAPI schemas: * - **Collapsed** (default): Show structure only - paths as method names, schemas as keys * - **Selective expansion**: Full details for specific items only * - **Full expansion**: Complete schema without any collapsing * * This approach addresses context length concerns when working with large OpenAPI * schemas in agentic/LLM contexts. * * @module schemas/collapse */ /** * Options for collapsing an OpenAPI schema. */ export interface SchemaCollapseOptions { /** * Paths to fully expand (e.g., ["/products", "/orders"]). * When provided, only these paths will have full operation details. * Other paths will show only their HTTP method names. */ expandPaths?: string[]; /** * Schema names to fully expand (e.g., ["Product", "Order"]). * When provided, only these schemas will have full definitions. * Other schemas will be shown as empty objects. */ expandSchemas?: string[]; /** * Example names to fully expand (e.g., ["ProductExample"]). * When provided, only these examples will have full content. * Other examples will be shown as empty objects. */ expandExamples?: string[]; } /** * Represents an OpenAPI 3.x schema structure. * This is a simplified type that captures the structure we need for collapsing. */ export interface OpenApiSchemaInput { openapi?: string; info?: Record; servers?: unknown[]; paths?: Record>; components?: { schemas?: Record; examples?: Record; parameters?: Record; responses?: Record; requestBodies?: Record; headers?: Record; securitySchemes?: Record; links?: Record; callbacks?: Record; }; security?: unknown[]; tags?: unknown[]; externalDocs?: unknown; [key: string]: unknown; } /** * Represents a collapsed path entry. * When collapsed, a path only shows the HTTP methods it supports. */ export type CollapsedPath = string[] | Record; /** * The output schema structure after collapsing. */ export interface CollapsedOpenApiSchema { openapi?: string; info?: Record; servers?: unknown[]; paths?: Record; components?: { schemas?: Record; examples?: Record; parameters?: Record; responses?: Record; requestBodies?: Record; headers?: Record; securitySchemes?: Record; links?: Record; callbacks?: Record; }; security?: unknown[]; tags?: unknown[]; externalDocs?: unknown; [key: string]: unknown; } /** * Collapses an OpenAPI schema for context-efficient representation. * * This function implements a three-tier disclosure model: * * 1. **No options provided (default):** * - Paths: `{"/products": ["get", "post"]}` (method names only) * - Schemas: `{"Product": {}}` (keys only) * - Examples: `{"ProductExample": {}}` (keys only) * * 2. **Selective expansion:** * - Only specified paths/schemas/examples are fully expanded * - Everything else remains collapsed * * Non-collapsible sections (info, servers, security, tags, etc.) are preserved as-is. * * @param schema - The OpenAPI schema to collapse * @param options - Options controlling what to expand * @returns The collapsed schema * * @example * // Collapse everything (default behavior) * const collapsed = collapseOpenApiSchema(fullSchema); * * @example * // Expand only /products path and Product schema * const collapsed = collapseOpenApiSchema(fullSchema, { * expandPaths: ['/products'], * expandSchemas: ['Product'] * }); */ export declare function collapseOpenApiSchema(schema: OpenApiSchemaInput, options?: SchemaCollapseOptions): CollapsedOpenApiSchema; /** * Checks if a schema has been collapsed (i.e., is in outline form). * * @param schema - The schema to check * @returns true if paths are collapsed (arrays) or schemas are empty objects */ export declare function isCollapsedSchema(schema: CollapsedOpenApiSchema): boolean; /** * Gets the list of available path keys from a schema. * * @param schema - The OpenAPI schema * @returns Array of path keys (e.g., ["/products", "/orders"]) */ export declare function getPathKeys(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[]; /** * Gets the list of available schema names from a schema. * * @param schema - The OpenAPI schema * @returns Array of schema names (e.g., ["Product", "Order"]) */ export declare function getSchemaNames(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[]; /** * Gets the list of available example names from a schema. * * @param schema - The OpenAPI schema * @returns Array of example names */ export declare function getExampleNames(schema: OpenApiSchemaInput | CollapsedOpenApiSchema): string[];