UNPKG

@glyphtek/unspecd

Version:

A declarative UI framework for building internal tools and dashboards with TypeScript. Create interactive tables, forms, and dashboards using simple specifications.

137 lines 4.43 kB
/** * @fileoverview Public API for Unspec'd server functionality * * This module provides the public interface for starting and configuring * the Unspec'd development server. It acts as a clean wrapper around the * core server logic, providing a stable API for library users. * * The server supports three modes: * 1. Library Mode: Pass a pre-configured UnspecdUI instance * 2. Discovery Mode: Automatically discovers tools using unspecd.config.ts * 3. Direct Mode: Uses a specific entry point file * * @example * ```typescript * import { UnspecdUI, startServer } from 'unspecd'; * * // Library Mode: Pass UnspecdUI instance (recommended) * const app = new UnspecdUI({ tools: [myTool] }); * await startServer(app); * * // Discovery Mode: Auto-discover tools * await startServer({ * discovery: { cwd: './' }, * port: 3000 * }); * * // Direct Mode: Uses a specific entry point * await startServer({ * entryPoint: 'src/my-tools.ts', * port: 3000 * }); * ``` */ import { type DiscoveryConfig } from '../core/server.js'; import { UnspecdUI } from './index.js'; declare global { var __UNSPECD_UI_MODE__: boolean | undefined; var __UNSPECD_TOOLS_DATA__: { tools: Array<{ id: string; title: string; inputs: any; content: any; functionNames: string[]; filePath?: string; }>; toolCount: number; focusMode: boolean; title?: string; } | undefined; var __UNSPECD_APP_INSTANCE__: any | undefined; } /** * Configuration for discovery-based server startup */ export interface DiscoveryServerConfig { /** Discovery configuration for auto-finding tools */ discovery: DiscoveryConfig; /** The port to run the server on (defaults to 3000) */ port?: number; /** Whether to allow external network access (defaults to true) */ host?: boolean; } /** * Configuration for direct entry point server startup */ export interface DirectServerConfig { /** The entry point file path for the application */ entryPoint: string; /** The port to run the server on (defaults to 3000) */ port?: number; /** Whether to allow external network access (defaults to true) */ host?: boolean; } /** * Configuration for library mode server startup with UnspecdUI instance */ export interface LibraryServerConfig { /** The port to run the server on (defaults to 3000) */ port?: number; /** Whether to allow external network access (defaults to true) */ host?: boolean; } /** * Combined server configuration that supports discovery and direct entry point modes */ export type ServerConfig = DiscoveryServerConfig | DirectServerConfig; export type { DiscoveryConfig } from '../core/discovery.js'; /** * Starts the Unspec'd development server. * * This function supports multiple ways to start the server: * * **Library Mode** (Recommended): Pass a pre-configured UnspecdUI instance * **Discovery Mode**: Automatically discovers tools using unspecd.config.ts * **Direct Mode**: Uses a specific entry point file * * @param appOrConfig - UnspecdUI instance, or server configuration options * @param config - Optional server configuration when passing UnspecdUI instance * * @returns Promise that resolves when the server has started successfully * * @throws {Error} If the server fails to start, configuration is invalid, or no tools are found * * @example * ```typescript * import { UnspecdUI, startServer } from 'unspecd'; * * // Library Mode: Pass UnspecdUI instance (simplest) * const app = new UnspecdUI({ tools: [myTool, otherTool] }); * await startServer(app); * * // Library Mode: With custom port * const app = new UnspecdUI({ tools: [myTool] }); * await startServer(app, { port: 8080 }); * * // Discovery Mode: Auto-discover tools from current directory * await startServer({ * discovery: { cwd: './' } * }); * * // Discovery Mode: Auto-discover tools from specific directory * await startServer({ * discovery: { cwd: './my-project' }, * port: 8080, * host: false * }); * * // Direct Mode: Use specific entry point * await startServer({ * entryPoint: 'src/tools.ts', * port: 3000 * }); * ``` */ export declare function startServer(appOrConfig: UnspecdUI | ServerConfig, config?: LibraryServerConfig, targetFile?: string): Promise<void>; //# sourceMappingURL=server.d.ts.map