UNPKG

@monitoro/herd

Version:

Automate your browser, build AI web tools and MCP servers with Monitoro Herd

124 lines (123 loc) 3.78 kB
import { EventEmitter } from 'events'; import { RequestInit } from 'node-fetch'; import type { DeviceInfo } from './types.js'; import { Device } from './Device.js'; import { TrailEngine, TrailEngineOptions, RunTrailOptions } from './TrailEngine.js'; export type HerdClientOptions = { baseUrl?: string; token?: string; } | { baseUrl?: string; apiKey: string; }; declare class Trail { private client; private trailIdentifier; private version?; constructor(client: HerdClient, trailIdentifier: string, version?: string | undefined); /** * Run a trail action * @param actionOrParams Either the action name to run, or the parameters for the default action * @param params Optional parameters if an action name is provided */ run(actionOrParams?: string | Record<string, any>, params?: Record<string, any>): Promise<any>; } export declare class HerdClient extends EventEmitter { private baseUrl; private natsUrl; private token; private deviceMap; private natsConnection; private natsServiceUserJwt; private natsAccountId; private jc; private _initialized; private _trailEngine; constructor(options: HerdClientOptions); init(): Promise<void>; /** * Make an HTTP request to the Herd API */ request(path: string, options?: RequestInit): Promise<any>; /** * Get the base URL for the Herd API */ getBaseUrl(): string; /** * Get current user information */ me(): Promise<{ id: string; email: string; natsUrl?: string; }>; /** * Get cache encryption key */ getCacheKey(): Promise<string>; /** * Initialize the client by fetching the NATS service user JWT and connecting to NATS */ initialize(): Promise<void>; private connectToNats; /** * Send a command to a device via NATS */ private sendNatsCommand; /** * List all available devices */ listDevices(): Promise<Device[]>; /** * Get a specific device by ID */ getDevice(deviceId: string): Promise<Device>; /** * Register a new device */ registerDevice(options: { deviceId: string; name?: string; type: 'browser' | 'headless'; }): Promise<DeviceInfo>; /** * Send an RPC command to a device */ sendCommand(deviceId: string, command: string, params?: Record<string, any>): Promise<unknown>; /** * Subscribe to all events from a device */ subscribeToDeviceEvents(deviceId: string, callback: (event: any) => void): () => void; /** * Subscribe to a specific event from a device */ subscribeToDeviceEvent(deviceId: string, eventName: string, callback: (event: any) => void): () => void; /** * Close the client and clean up resources */ close(): Promise<void>; /** * Check if the client has been initialized */ isInitialized(): boolean; /** * Get the trail engine instance, creating it if it doesn't exist * @param options Options for the trail engine */ trails(options?: TrailEngineOptions): TrailEngine; /** * Get a trail instance for running actions * @param trailIdentifier The trail name or path * @param version Optional version for remote trails */ trail(trailIdentifier: string, version?: string): Trail; /** * Run a trail by identifier (internal implementation used by Trail class) * @param trailIdentifier Local path or organization/trail identifier * @param options Run options including version if specified */ runTrail(trailIdentifier: string, options?: RunTrailOptions & { version?: string; }): Promise<any>; } export {};