import { MswarmCodaliExecutor } from "./codali-executor.js"; import { type GenerativeModality, type GenerativeOperation, type MswarmArtifactStoreDescriptor, type MswarmGenericJobValidationIssue, type MswarmJobEvent, type MswarmJobRequest, type MswarmJobResult, type MswarmJobScheduling, type MswarmNodeCapabilitySnapshot, type MswarmOutputSpec, type MswarmPublicCapabilityProjection, type MswarmRegisteredArtifact, type MswarmSandboxProfile, type MswarmSignedCapabilityPayload } from "@mcoda/shared"; export type FetchLike = typeof fetch; export type SelfHostedDiscoveryMode = "mcoda" | "ollama"; export type SelfHostedRelayMode = "outbound" | "direct"; export type SelfHostedExposurePolicy = "all" | "none"; export type SelfHostedNodeClientKind = "domain" | "ip" | "uuid"; export type CommandRunner = (command: string, args: string[], options: { timeoutMs: number; maxBuffer: number; input?: string; signal?: AbortSignal; }) => Promise<{ stdout: string; stderr: string; }>; export type SelfHostedModelHealthStatus = "healthy" | "degraded" | "unreachable" | "unknown" | "blocked"; export type SelfHostedGenerativeOperationName = GenerativeOperation; export type SelfHostedGenerativeModality = GenerativeModality; export interface SelfHostedGenerativeOperationCatalogInput { type: SelfHostedGenerativeOperationName; path: string; method: "POST"; supported_parameters: string[]; response_formats?: string[]; output_mime_types?: string[]; limits?: { max_request_bytes?: number; max_output_bytes?: number; max_prompt_chars?: number; max_negative_prompt_chars?: number; max_n?: number; min_width?: number; max_width?: number; min_height?: number; max_height?: number; max_pixels?: number; min_duration_seconds?: number; max_duration_seconds?: number; max_sample_rate?: number; default_fps?: number; min_fps?: number; max_fps?: number; min_video_frames?: number; max_video_frames?: number; max_steps?: number; max_high_noise_steps?: number; }; } export interface SelfHostedNodeClientIdentity { kind: SelfHostedNodeClientKind; value: string; added_at?: string; } export interface SelfHostedModelInput { name: string; provider?: "mcoda" | "ollama"; adapter?: string | null; model?: string | null; source_agent_id?: string | null; source_agent_slug?: string | null; model_id?: string | null; public_model_id?: string | null; upstream_model?: string | null; base_url?: string | null; runner_kind?: string | null; auth_mode?: string | null; response_format_strategy?: string | null; health_path?: string | null; models_path?: string | null; display_name?: string | null; digest?: string | null; exposed?: boolean; family?: string | null; parameter_size?: string | null; quantization_level?: string | null; context_window?: number | null; max_output_tokens?: number | null; supports_tools?: boolean; supports_streaming?: boolean; supports_vision?: boolean; supports_json_schema?: boolean; supports_gbnf?: boolean; openai_compatible?: boolean; best_usage?: string | null; capabilities?: string[]; cost_per_million?: number | null; rating?: number | null; rating_source?: string | null; reasoning_rating?: number | null; max_complexity?: number | null; health_status?: SelfHostedModelHealthStatus; metadata_quality?: string | null; input_modalities?: SelfHostedGenerativeModality[]; output_modalities?: SelfHostedGenerativeModality[]; operations?: SelfHostedGenerativeOperationCatalogInput[]; } export interface SelfHostedNodeConfig { gatewayBaseUrl: string; jobsPollPath?: string | null; jobsStartPathTemplate?: string | null; jobsEventsPathTemplate?: string | null; jobsResultPathTemplate?: string | null; nodeId: string; serverName?: string | null; relayMode?: SelfHostedRelayMode; machineFingerprint?: string | null; directBaseUrl?: string | null; enrollmentToken?: string | null; runtimeToken?: string | null; discoveryMode: SelfHostedDiscoveryMode; mcodaBin: string; mcodaListArgs: string[]; ollamaBaseUrl: string; statePath: string; runtimeTokenPath: string; artifactStorePath?: string; invocationSigningSecret?: string | null; listenHost: string; listenPort: number; nodeVersion: string; heartbeatIntervalSeconds: number; requestTimeoutMs: number; jobTimeoutMs: number; maxConcurrentJobs?: number; maxConcurrentLlmJobs?: number; reservedLlmJobs?: number; reservedPriorityMax?: number; genericJobsEnabled: boolean; genericJobTimeoutMs: number; genericJobMaxConcurrency: number; capabilityProbeTimeoutMs?: number; drainMode?: boolean; loadReportingEnabled?: boolean; hardwareTelemetryEnabled?: boolean; exposeAllModels: boolean; modelAllowlist: string[]; modelBlocklist: string[]; clientAllowlist: SelfHostedNodeClientIdentity[]; } export interface SelfHostedNodeState { node_id?: string; server_name?: string; relay_mode?: SelfHostedRelayMode; machine_fingerprint?: string; direct_base_url?: string | null; runtime_token?: string; artifact_store_path?: string; config_version?: number; heartbeat_interval_seconds?: number; heartbeat_timeout_seconds?: number; enrolled_at?: string; updated_at?: string; gateway_base_url?: string; jobs_poll_path?: string; jobs_start_path_template?: string; jobs_events_path_template?: string; jobs_result_path_template?: string; lifecycle_health_status?: "healthy" | "degraded" | "unreachable"; lifecycle_health_reason?: string; lifecycle_health_message?: string; lifecycle_health_updated_at?: string; ollama_base_url?: string; discovery_mode?: SelfHostedDiscoveryMode; mcoda_bin?: string; mcoda_list_args?: string[]; node_version?: string; request_timeout_ms?: number; job_timeout_ms?: number; max_concurrent_jobs?: number; max_concurrent_llm_jobs?: number; reserved_llm_jobs?: number; reserved_priority_max?: number; generic_jobs_enabled?: boolean; generic_job_timeout_ms?: number; generic_job_max_concurrency?: number; capability_probe_timeout_ms?: number; drain_mode?: boolean; load_reporting_enabled?: boolean; hardware_telemetry_enabled?: boolean; expose_all_models?: boolean; exposure_policy?: SelfHostedExposurePolicy; model_allowlist?: string[]; model_blocklist?: string[]; client_allowlist?: SelfHostedNodeClientIdentity[]; } export interface SelfHostedOwnerSetupConfig { /** Set for handle-based install; apiKey is unused in that case. */ handle?: string; apiKey: string; gatewayBaseUrl: string; serverName: string; relayMode: SelfHostedRelayMode; directBaseUrl?: string | null; discoveryMode: SelfHostedDiscoveryMode; statePath: string; runtimeTokenPath: string; artifactStorePath?: string; machineIdPath: string; mcodaBin: string; mcodaListArgs: string[]; ollamaBaseUrl: string; nodeVersion: string; heartbeatIntervalSeconds: number; requestTimeoutMs: number; jobTimeoutMs: number; maxConcurrentJobs: number; maxConcurrentLlmJobs: number; reservedLlmJobs: number; reservedPriorityMax: number; genericJobsEnabled: boolean; genericJobTimeoutMs: number; genericJobMaxConcurrency: number; capabilityProbeTimeoutMs?: number; drainMode: boolean; loadReportingEnabled: boolean; hardwareTelemetryEnabled: boolean; exposeAllModels: boolean; modelAllowlist: string[]; modelBlocklist: string[]; clientAllowlist: SelfHostedNodeClientIdentity[]; start: boolean; } export interface GatewayRegisterResponse { created?: boolean; node_id?: string; status?: string; approval_code?: string | null; handle?: string; message?: string; } /** Same shape as a bootstrap response once approved, so setup can share the tail. */ export interface GatewayClaimResponse extends GatewayBootstrapResponse { status?: string; } export interface GatewayBootstrapResponse { created?: boolean; enrolled?: boolean; node?: { node_id?: string; server_name?: string; relay_mode?: SelfHostedRelayMode; }; runtime_token?: string; heartbeat_interval_seconds?: number; heartbeat_timeout_seconds?: number; config_version?: number; relay?: { mode?: SelfHostedRelayMode; gateway_base_url?: string; jobs_poll_path?: string; jobs_start_path_template?: string; jobs_events_path_template?: string; jobs_result_path_template?: string; }; } export interface SelfHostedNodeSetupResult { created: boolean; nodeId: string; serverName: string; modelCount: number; status: "online" | "degraded"; statePath: string; runtimeTokenPath: string; start: boolean; } export interface SelfHostedNodeUninstallNotificationResult { notified: boolean; response?: unknown; error?: string; } export interface SelfHostedOpenAIChatMessage { role: string; content: string | Array<{ type: string; text?: string; }>; } export interface SelfHostedNodeCodaliJobPayload { id?: string; job_type?: string; jobType?: string; input?: unknown; context?: Record; tenant?: Record; requester?: Record; tool_manifest?: Record; toolManifest?: Record; stages?: Array>; budgets?: Record; agent_policy?: Record; agentPolicy?: Record; response?: Record; metadata?: Record; } export interface SelfHostedNodeCodaliGatewayPayload { id?: string; query?: string; mode?: "fast" | "balanced" | "deep" | "cheap" | "image"; product?: Record; tenant?: Record; requester?: Record; conversation?: Record; docdex?: Record; tools?: Record; tool_manifest?: Record; toolManifest?: Record; policy?: Record; agent_policy?: Record; agentPolicy?: Record; response?: Record; metadata?: Record; } export interface SelfHostedNodeCodaliSessionPayload { id?: string; storage_dir?: string; storageDir?: string; resume?: boolean; compact_on_finish?: boolean; compactOnFinish?: boolean; load_instructions?: boolean; loadInstructions?: boolean; include_local_instructions?: boolean; includeLocalInstructions?: boolean; focus_paths?: string[]; focusPaths?: string[]; } export interface SelfHostedNodeInvocationJob { job_id: string; request_id: string; node_id: string; agent_slug: string; operation?: SelfHostedGenerativeOperationName; remote_slug?: string; provider?: "mcoda" | "ollama"; execution_runtime?: "codali" | "raw" | string; codali_gateway?: SelfHostedNodeCodaliGatewayPayload; codali_job?: SelfHostedNodeCodaliJobPayload; session?: SelfHostedNodeCodaliSessionPayload; adapter?: string | null; source_agent_slug?: string | null; model?: string | null; workspace?: { root?: string; read_only?: boolean; }; docdex?: { base_url?: string; repo_root?: string; repo_id?: string; dag_session_id?: string; apiKey?: string; api_key?: string; client_identity?: string; required?: boolean; allowed_operations?: string[]; credential_source?: "attached_mswarm_api_key" | string; immutableRuntimeContext?: boolean; immutable_runtime_context?: boolean; capabilities?: Record; initialize?: boolean; allow_web?: boolean; allow_memory_write?: boolean; allow_profile_write?: boolean; allow_index_rebuild?: boolean; tool_manifest?: Record; }; openai_request: { model: string; messages?: SelfHostedOpenAIChatMessage[]; prompt?: string; n?: number; size?: string; seed?: number; steps?: number; negative_prompt?: string; duration_seconds?: number; sample_rate?: number; fps?: number; video_frames?: number; high_noise_steps?: number; stream?: boolean; temperature?: number; top_p?: number; max_tokens?: number; stop?: string | string[]; response_format?: Record | string | null; tools?: Record[]; tool_choice?: unknown; [key: string]: unknown; }; scheduling?: MswarmJobScheduling; policy?: { /** * The scheduler's own name for this job's class, echoed back in capacity * telemetry rather than re-derived here. The gateway decides what a job is; * a node that inferred it independently would drift from the scheduler that * dispatched it, and drift between two correct-looking numbers is the * failure mode this field exists to remove. */ execution_class?: string; max_runtime_ms?: number; max_output_tokens?: number; allow_tools?: boolean; allow_images?: boolean; allowed_tools?: string[]; denied_tools?: string[]; app_tool_contracts?: Record | Array>; app_virtual_tools?: string[]; app_tool_gateway?: Record; allow_shell?: boolean; allow_writes?: boolean; allow_outside_workspace?: boolean; allow_destructive_operations?: boolean; max_tool_calls?: number; }; } export interface SelfHostedGenericNodeJob { job_id: string; request_id: string; node_id: string; job: MswarmJobRequest; } export interface SelfHostedNodeInvocationResult { job_id: string; request_id: string; operation?: SelfHostedGenerativeOperationName; status: "success" | "failed"; pre_start_failure?: boolean; openai_response?: Record; stream_events?: Record[]; progress_events?: Record[]; usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number; }; error?: { code: string; message: string; }; timing?: { local_latency_ms: number; }; } type SelfHostedRelayExecutionResult = { executed: boolean; job_id?: string; status?: "success" | "failed"; }; export interface SelfHostedJobExecutionOptions { onOpenAIChunk?: (chunk: Record) => void | Promise; onProgress?: (event: Record) => void | Promise; onStarted?: (event: { job_id: string; request_id: string; node_id: string; agent_slug: string; source_agent_slug?: string | null; model?: string | null; }) => void | Promise; /** * Per-invocation owner key attached by the mswarm execution envelope for * encrypted Docdex access. This must never be read from local model/provider * agent config or serialized into job/result payloads. */ attachedMswarmApiKey?: string; } export interface MswarmGenericJobRunnerContext { job: MswarmJobRequest; signal: AbortSignal; emitEvent: (event: Omit) => Promise; artifacts: MswarmGenericJobArtifactContext; sandbox: MswarmSandboxProfile; } export interface MswarmGenericJobRunner { readonly id: string; run(context: MswarmGenericJobRunnerContext): Promise; } export interface MswarmGenericJobArtifactContext { store: MswarmArtifactStoreDescriptor; workDir: string; inputDir: string; outputDir: string; registeredInputs: MswarmRegisteredArtifact[]; outputSpecs: MswarmOutputSpec[]; sandbox: MswarmSandboxProfile; } export interface MswarmGenericJobArtifactStore { prepareJobWorkspace(jobId: string, job: MswarmJobRequest): Promise; collectOutputs(context: MswarmGenericJobArtifactContext, jobId: string): Promise; } export interface MswarmGenericJobExecutionOptions { signal?: AbortSignal; onEvent?: (event: MswarmJobEvent) => void | Promise; } export interface MswarmGenericJobExecutionResult { job_id: string; request_id: string; status: MswarmJobResult["status"]; result: MswarmJobResult; events: MswarmJobEvent[]; validation_issues?: MswarmGenericJobValidationIssue[]; timing: { local_latency_ms: number; }; } export type SelfHostedRuntimeExecutionClass = "chat" | "agentic" | "generic_job"; export declare const SELF_HOSTED_RUNTIME_EXECUTION_CLASSES: readonly SelfHostedRuntimeExecutionClass[]; /** * Which physical pool a class draws on. `chat` and `agentic` are distinct kinds * of work sharing one set of GPUs, so their `active_jobs` differ while their * `free_slots` describe the same slots — summing free slots across classes * double-counts. Stated on the wire because a scheduler cannot otherwise tell a * shared pool from an independent one, and guessing wrong is silent. */ export type SelfHostedRuntimeExecutionPool = "llm" | "generic"; export interface SelfHostedRuntimeExecutionClassCapacity { pool: SelfHostedRuntimeExecutionPool; max_concurrency: number; active_jobs: number; queued_jobs: number; free_slots: number; } export interface SelfHostedRuntimeLoadTelemetry { runtime_protocol_version: number; load_balancer_protocol_version: number; catalog_metadata_version: number; catalog_fingerprint: string; max_concurrency: number; max_concurrent_llm_jobs: number; max_concurrent_generic_jobs: number; active_jobs: number; queued_jobs: number; free_slots: number; drain_mode: boolean; execution_class_capacity: Record; avg_latency_ms: number | null; recent_failure_count: number; recent_failures: Array<{ execution_class: SelfHostedRuntimeExecutionClass; code: string; at: string; }>; hardware_pressure?: Record; } export interface SelfHostedNodeHeartbeatResult { enrolled: boolean; status: "online" | "degraded"; model_count: number; discovery_source: "mcoda" | "ollama"; mcoda_agent_count?: number; ollama_version?: string | null; capacity?: SelfHostedRuntimeLoadTelemetry; heartbeat_response: unknown; } export interface SelfHostedNodeDaemonHandle { stop: () => void; } export interface SelfHostedNodeDoctorResult { ok: boolean; checks: Array<{ name: string; ok: boolean; message?: string; }>; } export interface SelfHostedNodeServiceInstallOptions { commandPath: string; nodePath?: string; platform?: NodeJS.Platform; homeDir?: string; env?: NodeJS.ProcessEnv; runner?: CommandRunner; } export type SelfHostedNodeServiceManager = "launchd" | "systemd" | "windows-task-scheduler"; export type SelfHostedNodeServiceControlAction = "start" | "stop" | "restart" | "status"; export interface SelfHostedNodeServiceInstallResult { manager: SelfHostedNodeServiceManager; serviceName: string; servicePath: string; wrapperPath: string; logPath: string; errorLogPath: string; started: boolean; } export interface SelfHostedNodeServiceControlOptions { platform?: NodeJS.Platform; homeDir?: string; runner?: CommandRunner; requestTimeoutMs?: number; } export interface SelfHostedNodeServiceControlResult { manager: SelfHostedNodeServiceManager; serviceName: string; servicePath: string; logPath: string; errorLogPath: string; action: SelfHostedNodeServiceControlAction | "uninstall"; ok: boolean; stdout: string; stderr: string; message?: string; } export interface SelfHostedNodeServiceLayout { platform: NodeJS.Platform; manager: SelfHostedNodeServiceManager; serviceName: string; servicePath: string; wrapperPath: string; logPath: string; errorLogPath: string; } interface OllamaTagModel { name?: string; digest?: string | null; details?: { family?: string | null; parameter_size?: string | null; quantization_level?: string | null; } | null; } interface McodaAgentListEntry { id?: string | null; slug?: string | null; adapter?: string | null; defaultModel?: string | null; default_model?: string | null; openaiCompatible?: boolean | null; openai_compatible?: boolean | null; contextWindow?: number | null; context_window?: number | null; maxOutputTokens?: number | null; max_output_tokens?: number | null; supportsTools?: boolean | null; supports_tools?: boolean | null; rating?: number | null; reasoningRating?: number | null; reasoning_rating?: number | null; bestUsage?: string | null; best_usage?: string | null; costPerMillion?: number | null; cost_per_million?: number | null; maxComplexity?: number | null; max_complexity?: number | null; capabilities?: unknown; health?: { status?: string | null; } | null; config?: Record | null; models?: Array<{ modelName?: string | null; model_name?: string | null; isDefault?: boolean | null; is_default?: boolean | null; }> | null; } type McodaAgentAuthResolver = (agent: McodaAgentListEntry) => Promise; interface GatewayEnrollmentResponse { runtime_token?: string; heartbeat_interval_seconds?: number; heartbeat_timeout_seconds?: number; config_version?: number; relay?: { mode?: SelfHostedRelayMode; gateway_base_url?: string; jobs_poll_path?: string; jobs_start_path_template?: string; jobs_events_path_template?: string; jobs_result_path_template?: string; }; } /** * How often a node the gateway has removed re-checks whether that was undone. Rare * enough to be invisible next to a normal heartbeat, frequent enough that restoring a * node in the console brings the machine back without anyone logging into it. */ export declare const REVOKED_RECHECK_INTERVAL_MS: number; /** * Backoff for a failing relay poll. A successful poll blocks at the gateway for * `wait_ms`, so on success the loop re-enters immediately; a failing one returns * straight away and needs a delay of its own or it becomes a busy loop. */ export declare function pollRetryDelayMs(failureStreak: number): number; export declare function normalizeSelfHostedGenerativeOperationName(value: unknown): SelfHostedGenerativeOperationName | null; export declare function resolveSelfHostedInvocationOperation(value: unknown): SelfHostedGenerativeOperationName; export declare function normalizeSelfHostedNodeClientIdentity(value: unknown): SelfHostedNodeClientIdentity | null; export declare function normalizeSelfHostedNodeClientAllowlist(value: unknown): SelfHostedNodeClientIdentity[]; export declare function addSelfHostedNodeClients(current: SelfHostedNodeClientIdentity[], additions: SelfHostedNodeClientIdentity[], now?: string): SelfHostedNodeClientIdentity[]; export declare function removeSelfHostedNodeClients(current: SelfHostedNodeClientIdentity[], removals: SelfHostedNodeClientIdentity[]): SelfHostedNodeClientIdentity[]; export declare function resolveDefaultServerName(): string; export declare function readOrCreateSelfHostedMachineId(machineIdPath?: string): Promise; export declare function machineFingerprintFromId(machineId: string): string; /** * Names the class a job should be accounted against. * * The scheduler's `policy.execution_class` wins whenever it is a class this * node knows. Only when it is absent does the node fall back to reading the * runtime it was asked to use, and that fallback exists for older gateways * rather than as a second opinion. * * An unrecognised label is deliberately not coerced into the nearest match: a * class this node cannot account for is a real disagreement about the * vocabulary, and quietly filing it under `chat` would let the two sides * schedule against different meanings while every number still looked sane. * The caller reports it and uses the derived class meanwhile. */ export declare function resolveJobExecutionClass(job: { policy?: { execution_class?: string; }; execution_runtime?: string; }): { executionClass: SelfHostedRuntimeExecutionClass; unrecognisedLabel: string | null; }; /** * Whether this agent is served by infrastructure this node owns. * * A node advertises the hardware it has. Exposure was gated on health and the * operator's allowlist alone, so an inventory full of hosted models was * published as though the box served them: 159 of one node's 181 agents were * OpenRouter, offered to callers who then paid a round trip to someone else's * public API through a node contributing nothing to it. * * The test is the endpoint, and the question it answers is "could the caller * have reached this themselves". Adapter names cannot answer it — `openai-api` * is equally an OpenRouter endpoint and a llama.cpp server on 127.0.0.1 — and * loopback alone is too narrow, because a private host on the operator's own * network is still theirs to serve and no one else's to reach. * * So: no endpoint means a CLI adapter running here by construction; an endpoint * must be one only this node can resolve. A publicly routable name is somebody * else's service and is not this node's to advertise. */ export declare function isPrivateEndpointHost(host: string): boolean; export declare function agentRunsOnThisNode(agent: McodaAgentListEntry): boolean; export declare function readSelfHostedNodeState(statePath: string): Promise; export declare function writeSelfHostedNodeState(statePath: string, state: SelfHostedNodeState): Promise; export declare function readSelfHostedRuntimeToken(tokenPath: string): Promise; export declare function writeSelfHostedRuntimeToken(tokenPath: string, runtimeToken: string): Promise; export declare function resolveSelfHostedNodeServiceLayout(input?: { platform?: NodeJS.Platform; homeDir?: string; }): SelfHostedNodeServiceLayout; export declare function installSelfHostedNodeService(config: SelfHostedNodeConfig, options: SelfHostedNodeServiceInstallOptions): Promise; export declare function controlSelfHostedNodeService(action: SelfHostedNodeServiceControlAction, options?: SelfHostedNodeServiceControlOptions): Promise; export declare function uninstallSelfHostedNodeService(options?: SelfHostedNodeServiceControlOptions): Promise; export declare function readSelfHostedNodeConfig(env?: NodeJS.ProcessEnv): Promise; export declare function readOwnerSetupConfig(argv?: string[], env?: NodeJS.ProcessEnv): Promise; export declare function mapOllamaModelToSelfHostedModel(model: OllamaTagModel, config: Pick): SelfHostedModelInput | null; export declare function mapMcodaAgentToSelfHostedModel(agent: McodaAgentListEntry, config: Pick): SelfHostedModelInput | null; export declare class McodaAgentInventoryClient { private readonly command; private readonly args; private readonly timeoutMs; private readonly runner; constructor(input: { command?: string; args?: string[]; timeoutMs?: number; runner?: CommandRunner; }); listRawAgents(): Promise; listAgents(config: Pick): Promise; } export declare class OllamaClient { private readonly baseUrl; private readonly fetchImpl; private readonly timeoutMs; constructor(input: { baseUrl: string; fetchImpl?: FetchLike; timeoutMs?: number; }); getVersion(): Promise; listModels(config: Pick): Promise; chat(input: { model: string; messages: SelfHostedOpenAIChatMessage[]; options?: Record; format?: unknown; }): Promise<{ content: string; promptTokens: number | null; completionTokens: number | null; raw: unknown; }>; } export declare class MswarmLocalArtifactStore implements MswarmGenericJobArtifactStore { private readonly rootDir; private readonly now; constructor(input?: { rootDir?: string; now?: () => Date; }); prepareJobWorkspace(jobId: string, job: MswarmJobRequest): Promise; collectOutputs(context: MswarmGenericJobArtifactContext, jobId: string): Promise; private registerInput; private collectDeclaredOutput; private collectOutputDirectory; private collectOutputFile; } export declare class MswarmTestEchoRunner implements MswarmGenericJobRunner { readonly id = "test.echo"; run(context: MswarmGenericJobRunnerContext): Promise; } export declare class MswarmBlenderRenderRunner implements MswarmGenericJobRunner { readonly id = "blender.render"; private readonly runner; constructor(runner?: CommandRunner); run(context: MswarmGenericJobRunnerContext): Promise; } export declare class MswarmCudaPackageRunner implements MswarmGenericJobRunner { readonly id = "cuda.package"; private readonly runner; constructor(runner?: CommandRunner); run(context: MswarmGenericJobRunnerContext): Promise; } export declare function genericJobCapabilityMismatch(job: MswarmJobRequest, snapshot: MswarmNodeCapabilitySnapshot): { code: string; message: string; } | null; export declare class McodaLocalAgentExecutor { private readonly command; private readonly timeoutMs; private readonly runner; constructor(input: { command?: string; timeoutMs?: number; runner?: CommandRunner; }); invoke(agentSlug: string, prompt: string): Promise<{ output: string; adapter?: string; model?: string; metadata?: Record; }>; } export declare class MswarmSelfHostedNodeClient { private readonly gatewayBaseUrl; private readonly jobsPollPath; private readonly jobsStartPathTemplate; private readonly jobsEventsPathTemplate; private readonly jobsResultPathTemplate; private readonly fetchImpl; private readonly timeoutMs; private readonly resultTimeoutMs; constructor(input: { gatewayBaseUrl: string; jobsPollPath?: string | null; jobsStartPathTemplate?: string | null; jobsEventsPathTemplate?: string | null; jobsResultPathTemplate?: string | null; fetchImpl?: FetchLike; timeoutMs?: number; resultTimeoutMs?: number; }); lifecycleEndpoint(kind: "poll" | "start" | "events" | "result"): string; lifecycleGatewayBaseUrl(): string; private lifecycleUrl; enroll(nodeId: string, enrollmentToken: string): Promise; /** * Registers this machine against an mswarm handle. Carries no credential: the * handle owner approving in the console is what authorises the node. */ registerByHandle(payload: Record): Promise; /** * Collects the runtime token once the owner has approved. The registration secret * proves this is the machine that registered. */ claimRegistration(nodeId: string, registrationSecret: string): Promise; bootstrap(apiKey: string, payload: Record): Promise; health(): Promise; heartbeat(runtimeToken: string, payload: Record): Promise; uninstall(runtimeToken: string, payload: Record): Promise; pushModels(runtimeToken: string, payload: { node_id: string; models: SelfHostedModelInput[]; }): Promise; pollJob(runtimeToken: string, payload: { node_id: string; capacity?: Record; wait_ms?: number; }): Promise<{ job?: SelfHostedNodeInvocationJob | null; attached_mswarm_api_key?: string | null; }>; postJobResult(runtimeToken: string, jobId: string, payload: SelfHostedNodeInvocationResult & { node_id: string; }): Promise; postJobStart(runtimeToken: string, jobId: string, payload: { node_id: string; agent_slug?: string | null; source_agent_slug?: string | null; model?: string | null; }): Promise; postJobEvents(runtimeToken: string, jobId: string, payload: { node_id: string; stream_events?: Record[]; progress_events?: Record[]; }): Promise; } export declare class SelfHostedNodeRuntime { private readonly config; private readonly gateway; private readonly mcoda; private readonly mcodaAgentAuthResolver; private readonly mcodaExecutor; private readonly codaliExecutor; private readonly ollama; private readonly jobOllama; private readonly fetchImpl; private readonly useDedicatedGenerativeDispatcher; private readonly genericRunners; private readonly artifactStore; private readonly capabilityRunner; private activeChatJobs; private activeAgenticJobs; private activeGenericJobs; private queuedLlmJobs; private queuedGenericJobs; private readonly latencySamplesMs; private readonly recentFailures; private lifecyclePollingDisabled; constructor(config: SelfHostedNodeConfig, deps?: { gateway?: MswarmSelfHostedNodeClient; mcoda?: McodaAgentInventoryClient; mcodaAgentAuthResolver?: McodaAgentAuthResolver; mcodaExecutor?: McodaLocalAgentExecutor; codaliExecutor?: MswarmCodaliExecutor; ollama?: OllamaClient; fetchImpl?: FetchLike; genericRunners?: MswarmGenericJobRunner[]; artifactStore?: MswarmGenericJobArtifactStore; capabilityRunner?: CommandRunner; }); updateLocalQueueTelemetry(input: { llmQueuedJobs?: number; genericQueuedJobs?: number; }): void; private beginExecutionTelemetry; /** * Reported as a failure rather than a log line because an unknown class means * this node and the scheduler disagree about the vocabulary, which is a fault * in the pair rather than in either job. `recent_failures` is where the * scheduler already looks, so it surfaces without a new field to notice. */ private reportUnrecognisedExecutionClass; private finishExecutionTelemetry; private lifecycleProtocolMismatch; private isLifecycleProtocolDegradedState; private readLifecycleState; private markLifecycleProtocolDegraded; private jobResultPayload; private averageLatencyMs; private buildLoadTelemetry; static setup(setupConfig: SelfHostedOwnerSetupConfig, deps?: { gateway?: MswarmSelfHostedNodeClient; mcoda?: McodaAgentInventoryClient; mcodaExecutor?: McodaLocalAgentExecutor; codaliExecutor?: MswarmCodaliExecutor; ollama?: OllamaClient; fetchImpl?: FetchLike; genericRunners?: MswarmGenericJobRunner[]; artifactStore?: MswarmGenericJobArtifactStore; capabilityRunner?: CommandRunner; }): Promise; private discoverModels; probeCapabilities(): Promise; publicCapabilityProjection(): Promise; /** * The capability snapshot a heartbeat carries, without making the heartbeat * wait for it. * * Probing shells out to nvidia-smi, docker, blender and ffmpeg. Each is * bounded, but the bound is two seconds and they sit in front of every beat, * so on a machine where one of them is wedged — a docker daemon that accepts * the connection and never answers is the common one — the node pays that * before it can say it is alive. With a short heartbeat interval it is * permanently late, and if the probe ever outlasts the gateway's heartbeat * timeout the node reads as unreachable while being perfectly healthy. That * is the same false-unreachable this daemon exists to avoid. * * Liveness does not depend on knowing whether blender is installed. The * snapshot is probed once and then refreshed alongside the beat instead of in * front of it, so only the first beat of a process ever waits. */ private cachedCapabilitySnapshot; private capabilityRefreshInFlight; private refreshCapabilitySnapshot; buildCapabilityHeartbeatPayload(runtimeToken: string): Promise; ensureEnrolled(): Promise<{ runtimeToken: string; state: SelfHostedNodeState; enrolled: boolean; }>; /** * Forwards an OpenAI-standard tool-calling request straight to the agent's * local runner and returns its raw response, tool_calls included. * * The Codali runtime deliberately owns tool execution and never surfaces raw * tool_calls to the caller, which is correct when Codali is orchestrating. A * client that supplies its own `tools` is orchestrating instead, so it needs * the model's unexecuted tool calls back. */ private executeOpenAiToolPassthrough; private generativeOperationForAgent; private prepareOpenAiGenerativePassthrough; private executeOpenAiGenerativePassthrough; private resolveMcodaAgentForJob; executeGenericJob(envelope: SelfHostedGenericNodeJob, options?: MswarmGenericJobExecutionOptions): Promise; executeJob(job: SelfHostedNodeInvocationJob, options?: SelfHostedJobExecutionOptions): Promise; runOnce(): Promise; notifyUninstall(input?: { reason?: string; source?: string; serviceManager?: string | null; }): Promise; pushModelsOnly(): Promise<{ count: number; response: unknown; }>; private pollRelayJob; private executeRelayJobClaim; pollAndExecuteJob(waitMs?: number): Promise; doctor(): Promise; startDaemon(): SelfHostedNodeDaemonHandle; } export {}; //# sourceMappingURL=runtime.d.ts.map