import { oCoreConfig } from './interfaces/o-core.config.js'; import { NodeState } from './interfaces/state.enum.js'; import { oAddress } from '../router/o-address.js'; import { NodeType } from './interfaces/node-type.enum.js'; import { oConnectionManager } from '../connection/o-connection-manager.js'; import { oResponse } from '../connection/o-response.js'; import { oMethod } from '@olane/o-protocol'; import { oDependency } from './o-dependency.js'; import { oObject } from './o-object.js'; import { oMetrics } from './lib/o-metrics.js'; import { oHierarchyManager } from './lib/o-hierarchy.manager.js'; import { oRequestManager } from './lib/o-request.manager.js'; import { oTransport } from '../transports/o-transport.js'; import { oRouter } from '../router/o-router.js'; import { oRequest } from '../connection/o-request.js'; import { oNotificationManager } from './lib/o-notification.manager.js'; import { oNotificationEvent, EventFilter, NotificationHandler, Subscription } from './lib/events/index.js'; import { UseOptions } from './interfaces/use-options.interface.js'; import { UseStreamOptions } from './interfaces/use-stream-options.interface.js'; import { UseDataConfig } from './interfaces/use-data.config.js'; import { oTokenManager } from '../auth/o-token-manager.js'; export declare abstract class oCore extends oObject { readonly config: oCoreConfig; address: oAddress; state: NodeState; errors: Error[]; connectionManager: oConnectionManager; hierarchyManager: oHierarchyManager; metrics: oMetrics; requestManager?: oRequestManager; router: oRouter; notificationManager: oNotificationManager; tokenManager?: oTokenManager; private heartbeatInterval?; constructor(config: oCoreConfig); get isLeader(): boolean; get leader(): oAddress | null; abstract configureTransports(): any[]; useStream(address: oAddress, data: UseDataConfig, options: UseStreamOptions): Promise; useDirect(address: oAddress, data?: UseDataConfig): Promise; /** * Sends a request to a remote node in the O-Lane network using the specified address and optional data payload. * * This method handles the complete communication flow: * 1. Validates the target address format * 2. Resolves the routing path through the network * 3. Establishes a connection to the target node * 4. Sends the request payload and waits for response * 5. Handles errors and throws them as oError instances * * @param address - The target node address in O-Lane format (must start with 'o://') * @param data - Optional request data containing method, parameters, and request ID * @param data.method - The method name to invoke on the target node * @param data.params - Key-value pairs of parameters to pass to the method * @param data.id - Unique identifier for the request (for tracking purposes) * @returns Promise that resolves to an oResponse containing the result from the target node * @throws {Error} When the address is invalid (doesn't pass validation) * @throws {oError} When the target node returns an error response * * @example * ```typescript * // Basic usage - call a method on a remote node * const response = await node.use( * new oAddress('o://calculator/add'), * { * method: 'add', * params: { a: 5, b: 3 }, * id: 'calc-001' * } * ); * console.log(response.result); // { result: 8 } * * // Minimal usage - just specify the address * const response = await node.use( * new oAddress('o://status/health') * ); * console.log(response.result); // { status: 'healthy' } * * // Error handling * try { * const response = await node.use( * new oAddress('o://calculator/divide'), * { method: 'divide', params: { a: 10, b: 0 } } * ); * } catch (error) { * if (error instanceof oError) { * console.error(`Node error ${error.code}: ${error.message}`); * } else { * console.error('Invalid address or connection error:', error.message); * } * } * ``` */ use(address: oAddress, data?: UseDataConfig, options?: UseOptions): Promise; abstract execute(request: oRequest): Promise; /** * Helper method to validate node is running * @throws Error if node is not running */ private validateRunning; /** * Injects _auth into request params if not already present. * * Resolution order: * 1. AsyncLocalStorage context (propagated auth from an incoming request) * 2. Node-level tokenManager (the node's own identity) * * This ensures every outbound request carries auth — whether it originates * from within a request chain or from a node-initiated call (registration, * heartbeat, etc.). */ private injectAuthContext; useSelf(data?: { method?: string; params?: { [key: string]: any; }; id?: string; }): Promise; useTool(toolName: string, data?: { params?: { [key: string]: any; }; }): Promise; useChild(childAddress: oAddress, data?: UseDataConfig, options?: UseOptions): Promise; addChildNode(node: oCore): void; removeChildNode(node: oCore): void; abstract initializeRouter(): void; abstract unregister(): Promise; abstract register(): Promise; protected abstract createNotificationManager(): oNotificationManager; /** * Emit a notification event */ protected notify(event: oNotificationEvent): void; /** * Subscribe to notification events */ protected onNotification(eventType: string, handler: NotificationHandler, filter?: EventFilter): Subscription; initialize(): Promise; get isRunning(): boolean; protected hookStartFinished(): Promise; /** * Starts the node by transitioning through initialization and registration phases. * * This method performs the following operations in sequence: * 1. Validates that the node is in STOPPED state * 2. Sets state to STARTING * 3. Calls initialize() to set up the node's core components * 4. Attempts registration with the network (registration errors are logged but don't fail startup) * 5. Sets state to RUNNING on success * * @throws {Error} If the node is not in STOPPED state or initialization fails * @returns {Promise} Resolves when the node is successfully started and running * * @example * ```typescript * const node = new oNode(config); * try { * await node.start(); * console.log('Node is now running'); * } catch (error) { * console.error('Failed to start node:', error); * } * ``` * * @remarks * - If the node is already running or starting, the method will log a warning and return early * - Registration failures are logged but do not prevent the node from starting * - On any initialization error, the node state is set to ERROR and teardown() is called * - The node must be in STOPPED state before calling this method */ start(): Promise; /** * Validation hook that runs before initialize()/register() in start(). * * Subclasses can override this to perform cheap, synchronous/async * configuration validation. Any error thrown here will surface * directly to the caller of start() and will prevent initialization * and resource allocation from occurring. */ protected validate(data?: any): Promise; /** * Stops the node by performing cleanup and transitioning to a stopped state. * * This method performs the following operations in sequence: * 1. Sets state to STOPPING * 2. Calls teardown() to clean up node resources and connections * 3. Sets state to STOPPED on successful completion * * @throws {Error} If teardown operations fail, the node state will be set to ERROR * @returns {Promise} Resolves when the node is successfully stopped * * @example * ```typescript * const node = new oNode(config); * await node.start(); * * // Later, when shutting down * try { * await node.stop(); * console.log('Node stopped successfully'); * } catch (error) { * console.error('Failed to stop node:', error); * } * ``` * * @remarks * - This method can be called from any node state * - If teardown fails, errors are logged and the node state is set to ERROR * - All cleanup operations are performed through the teardown() method * - The method will attempt to stop gracefully even if the node is in an error state */ stop(): Promise; teardown(): Promise; abstract initRequestManager(): void; /** * Reset node state to allow restart after stop * Called at the end of teardown() */ protected resetState(): void; get dependencies(): oDependency[]; /** * Start sending periodic heartbeats to the monitor node * This is optional and only runs if MONITOR_ENABLED=true and MONITOR_ADDRESS is set */ private startHeartbeat; get methods(): { [key: string]: oMethod; }; get description(): string; get staticAddress(): oAddress; get type(): NodeType; get transports(): oTransport[]; get parent(): oAddress | null; get parentTransports(): oTransport[]; whoami(): Promise; } //# sourceMappingURL=o-core.d.ts.map