import { T as TCloudConfig, a as TCloudClient } from './client-CaPP4njg.js'; import '@tangle-network/sandbox'; /** * Instance — programmatic harness for spinning up a local Tangle dev environment. * * Wraps `cargo tangle harness up` as a child process and exposes health * checks, log streaming, and a pre-configured {@link TCloudClient} pointed * at the local stack. * * NODE-ONLY. This module uses `child_process` and `fs` and must not be * imported in browser or edge runtime bundles. Always import from * `@tangle-network/tcloud/instance`, never the package root. * * ## Example * * ```ts * import { Instance } from '@tangle-network/tcloud/instance' * * const instance = await Instance.start({ * config: './harness.dev.toml', * only: ['llm'], * }) * * const client = instance.client({ model: 'llama-3.1-8b' }) * const res = await client.chat({ * messages: [{ role: 'user', content: 'hello' }], * }) * console.log(res.choices[0].message.content) * * await instance.stop() * ``` */ interface InstanceOptions { /** Path to harness config TOML. Defaults to ./harness.toml or ~/.tangle/harness.toml */ config?: string; /** Only start these blueprints (subset) */ only?: string[]; /** Working directory for `cargo tangle harness` (default: current) */ cwd?: string; /** Stream anvil logs (default false) */ includeAnvilLogs?: boolean; /** Suppress stdout passthrough (default false) */ quiet?: boolean; /** Startup timeout in ms — how long to wait for "Harness up" marker (default 300_000) */ timeoutMs?: number; /** Router URL the instance exposes. Defaults to http://localhost:3000 */ routerUrl?: string; /** Override the `cargo tangle` binary path. Defaults to resolving `cargo-tangle` from PATH */ cargoBinary?: string; } interface InstanceConfig { /** URL of the router the instance is serving on */ routerUrl: string; /** Names of blueprints that were started */ blueprints: string[]; } /** * Append a line to a bounded log buffer, evicting the oldest entry once the * buffer exceeds `maxLines`. Exported for unit testing. */ declare function appendLogLine(buffer: string[], line: string, maxLines?: number): void; /** * A running Tangle dev environment. Hold one per test file or dev session. */ declare class Instance { private child; private _config; private _stopped; private logBuffer; private readonly maxLogLines; private constructor(); /** * Start a new harness instance. Resolves once `cargo tangle harness up` * prints its "Harness up" marker, indicating all blueprints are healthy. * * Throws on timeout, process exit before ready, or missing `cargo-tangle`. */ static start(options?: InstanceOptions): Promise; /** URL of the router serving this instance */ get routerUrl(): string; /** Names of blueprints that were started */ get blueprints(): string[]; /** * Create a pre-configured {@link TCloudClient} pointed at this instance's router. * Merges any passed config with the instance's routerUrl (instance wins). */ client(config?: Partial): TCloudClient; /** Return the last N log lines from the harness */ logs(lines?: number): string[]; /** Whether the harness process is still running */ get isRunning(): boolean; /** * Stop the harness. Sends SIGTERM, waits up to 10s for clean shutdown, * then SIGKILL. */ stop(timeoutMs?: number): Promise; } /** * Write a temporary harness.toml with the given blueprints, for inline test configs. * Returns the path to the created file. The caller is responsible for cleanup. */ declare function writeTempHarnessConfig(blueprints: Array<{ name: string; path: string; port?: number; env?: Record; }>): string; export { Instance, type InstanceConfig, type InstanceOptions, appendLogLine, writeTempHarnessConfig };