import { ServiceBroker } from 'moleculer';
import { InternalAddonContext, AddonDeclaration, IEventBus, IStorageProvider, SystemEvent, IScopedLogger, IClusterBroker } from '@camstack/types';
import { DeviceRegistry } from '../device-registry.js';
import { CapabilityRegistry } from '../capability-registry.js';
/**
 * Adapt a Moleculer ServiceBroker to the camstack-types `IClusterBroker`
 * structural interface so addons can consume cluster-level RPC without
 * pulling a moleculer dependency. Method signatures differ slightly
 * (Moleculer's overloads are wider than the camstack contract), so we
 * forward through a thin object instead of casting at the boundary.
 */
declare function adaptBrokerToCluster(broker: ServiceBroker): IClusterBroker;
/** Call after broker.waitForServices('$hub') to enable log forwarding. */
declare function setHubConnected(_broker?: ServiceBroker): void;
declare function withAddonScope<T>(addonId: string, fn: () => T): T;
/** Exported for test harnesses that drive the factory manually. */
export { withAddonScope };
/** Update the preferred provider for a capability (called from binding-changed subscribers). */
declare function setPreferredProvider(capabilityName: string, addonId: string | null, brokerNodeId?: string): void;
export { setPreferredProvider };
declare function __resetBindingSubscriptionForTests(): void;
export { __resetBindingSubscriptionForTests };
/** Moleculer broadcast event name carrying distributed EventBus events. */
declare const CLUSTER_EVENT_NAME = "camstack.cluster.event";
/**
 * Register the `$cluster-events` service on a broker. Must be called
 * BEFORE `broker.start()` — Moleculer announces service subscriptions
 * to remote nodes as part of the discovery handshake, not dynamically
 * after a late `createService()` (the post-start propagation relies on
 * the heartbeat cycle, which takes 10+ seconds and makes broadcasts
 * unreliable in the meantime).
 *
 * Idempotent — calling twice on the same broker is a no-op. The service
 * is a Moleculer "internal" service (name prefixed with `$`) so it
 * doesn't show up in the addon / capability graph.
 *
 * Callers:
 *  - hub backend (`MoleculerService.onModuleInit`), before `broker.start()`
 *  - agent bootstrap, before `broker.start()`
 *  - forkable process runner, before `broker.start()`
 *
 * `createAddonContext` does NOT auto-register because by then the broker
 * has already started (addons init after boot).
 */
export declare function registerClusterEventsService(broker: ServiceBroker): void;
/**
 * Register a handler that fires for every `camstack.cluster.event`
 * broadcast this broker receives. Used by the hub's `EventBusService`
 * to ingest cross-process events without spinning up a full
 * `createBrokerEventBus` (the hub owns a shared `SystemEventBus` with
 * a ring buffer that the `system-events` tRPC router queries).
 *
 * Idempotent against `registerClusterEventsService(broker)` — calls
 * it as a fallback if the caller forgot.
 */
export declare function addClusterEventDispatcher(broker: ServiceBroker, handler: (event: SystemEvent) => void): () => void;
declare function getBrokerEventBus(broker: ServiceBroker): IEventBus;
export { getBrokerEventBus };
/**
 * Expose the per-process worker device registry so the process-runner can
 * mount the `device-ops-bridge` Moleculer service on top of the same live
 * IDevice instances that `createBrokerDeviceManagerApi` writes to.
 *
 * Hub-side contexts also share this module, but they pass their own
 * `opts.deviceRegistry` explicitly — nothing hub-side uses this accessor.
 */
export declare function getWorkerDeviceRegistry(): DeviceRegistry;
/**
 * Options for enriching the addon context with infrastructure providers.
 * When the agent boots with core addons (storage, settings-store),
 * pass them here so deployed addons get full capabilities.
 */
interface AddonContextOptions {
    readonly storageProvider?: IStorageProvider;
    readonly addonConfig?: Record<string, unknown>;
    /** Custom logger factory — when set, overrides the default remote logger */
    readonly createLogger?: (addonId: string) => IScopedLogger;
    /**
     * Hub `CapabilityRegistry`. When set, the `DeviceManagerApi` created
     * for this context wires `DeviceContext.registerNativeCap` through it
     * so device-driver addons can publish per-device native capability
     * providers. Forked-worker processes don't carry a CapabilityRegistry,
     * so this field is left undefined there — `registerNativeCap` becomes
     * unavailable on workers, which throw at runtime if called.
     */
    readonly capabilityRegistry?: CapabilityRegistry;
}
declare function createAddonContext(broker: ServiceBroker, declaration: AddonDeclaration, dataDir: string, options?: AddonContextOptions): InternalAddonContext;
/**
 * Drain (and forget) the disposer chain for a worker-side addon. Idempotent:
 * subsequent calls are no-ops. Called by process-runner / group-runner
 * before reload or graceful shutdown so resources clean up before the
 * next addon instance loads.
 */
declare function drainWorkerDisposerChain(nodeId: string, addonId: string): Promise<void>;
export { createAddonContext, setHubConnected, adaptBrokerToCluster, CLUSTER_EVENT_NAME, drainWorkerDisposerChain, };
export type { AddonContextOptions };
//# sourceMappingURL=addon-context-factory.d.ts.map