import { createPiOAuthApiKeyResolver } from "@mono-agent/agent-runtime"; import type { MonoRuntimeBackendDescriptor, MonoRuntimeHostOptions, MonoRuntimeLike, MonoRuntimeSupportDescription, RuntimeModelReference, RuntimeRunOptions } from "./types.js"; export type RuntimeAdapterErrorCode = "invalid_model_reference" | "runtime_backend_unavailable" | "invalid_runtime_options" | "invalid_local_provider"; export interface RuntimeAdapterErrorDetails { readonly code?: RuntimeAdapterErrorCode; readonly [key: string]: unknown; } export declare class RuntimeAdapterError extends Error { readonly code: RuntimeAdapterErrorCode; readonly details: RuntimeAdapterErrorDetails; constructor(code: RuntimeAdapterErrorCode, message: string, details?: RuntimeAdapterErrorDetails); } /** * A model reference is operator-supplied and otherwise unbounded: nothing stops a token, an * API key, or a URL with credentials being pasted into a model field by mistake. Whatever * lands there is echoed back by `mono-agent validate`, `doctor`, the daemon log and launchd's * captured stdout -- all durable and routinely shared. Those surfaces are also line-oriented, * so an embedded newline lets one config value forge diagnostic lines that read as the * loader's own. * * The rule, therefore, is not "trim model ids": it is that no operator-supplied text reaches a * diagnostic without being reduced to printable single-line text AND bounded. * * This is a DISPLAY budget, and it is the ONLY bound a model reference has left, because it is * the only kind of bound that costs nobody a working model. Two rounds tried to make the parser * share it, or share something like it: first as `MAX_MODEL_REFERENCE_BYTES` = 96 on the rule "a * reference is accepted exactly when every operator surface can quote it whole", which duly * refused a Hugging Face GGUF repo Ollama serves today at 100 bytes; then at 160, derived from a * sampled distribution, which refused an `ollama::` reference whose two halves Ollama * itself validates at 80 bytes each. The parser now has no length rule at all -- what a model may * be called is decided by providers -- and this number stayed exactly where it was. * * That asymmetry is the point, not an accident of which side moved. An echo is bounded by * TRUNCATING it, which `sanitizeModelReferenceText` does, marking the cut; a reference cannot be * truncated into validity, so a ceiling there can only ever refuse. Truncating an echo costs a * diagnostic some characters. Refusing a reference costs an operator a route that runs. * * Keeping this at 96 therefore costs nothing real. Every consumer is on a REJECTION path -- * `modelReferenceEcho` in @mono-agent/config, `echoValue` in agent-app's request-model-override, * `echo` in its trigger-overrides -- so it never truncates a reference that parsed. It stays * large enough to show a mistyped one in full: 96 bytes covers every reference in Pi's * 1312-entry built-in catalog (longest 77) and every ref this machine's Ollama and LM Studio * discovery returns (longest 52), and a longer value is shown as much of itself as fits, plus * the marker. A reference that DID parse and is genuinely longer than this -- which is now * possible at any size -- is clamped here rather than refused there; the model-reference bound * suite asserts that at 100, 168, 400, 70,000 and 270,000 bytes. */ export declare const MODEL_REFERENCE_ECHO_MAX_BYTES = 96; /** * A parser reason is one fixed repair sentence plus at most one echo of the operator's value, * so its budget is the sum. Deriving it rather than picking a number is what keeps the repair * -- the actionable half an operator actually needs -- from ever being clamped away. */ export declare const MODEL_REFERENCE_REASON_MAX_BYTES: number; /** * Escape, then clamp: escaping expands, so clamping last is what makes the returned byte * length an actual bound. Clamping walks code points (never splitting one) on a UTF-8 byte * budget, the same convention as `clampUtf8Bytes` in agent-harness and `clampUtf8` in the * agent-app skill registry, and marks the cut so a clamped echo is distinguishable from a * short value. Escaping is idempotent and clamping is monotone, so applying this twice -- * which happens when config re-bounds a reason the adapter already bounded -- is a no-op. */ export declare function sanitizeModelReferenceText(value: string, maxBytes: number): string; export declare function parseMonoRuntimeModelReference(value: string): RuntimeModelReference; /** Stable canonical string used for model comparison, caching, and display. */ export declare function modelReferenceKey(model: RuntimeModelReference): string; export declare function listMonoRuntimeBackends(): readonly MonoRuntimeBackendDescriptor[]; export declare function runtimeBackendForModel(model: RuntimeModelReference): MonoRuntimeBackendDescriptor; export declare function monoRuntimeSupportsSessionResume(): boolean; export declare function monoRuntimeSupportsLiveInput(): boolean; export declare function monoRuntimeSupportsMcpApps(): boolean; export declare function describeMonoRuntimeSupport(model: RuntimeModelReference): MonoRuntimeSupportDescription; export interface MonoRuntimeFallbackChainEntry { readonly model: RuntimeModelReference; /** String pins this route, `null` selects the provider default, omitted inherits the run effort. */ readonly effort?: string | null; /** * Total attempts on this route including the first, 1–10. Omitted means a * single shot. A retry re-runs the whole logical turn on the same model and * only fires for transient provider failures. */ readonly attempts?: number; } export interface MonoRuntimeRetryPolicy { /** Delay before the first retry; doubles per retry. Defaults to 1000. */ readonly backoffMs?: number; /** Ceiling for the doubled delay. Defaults to 15000. */ readonly maxBackoffMs?: number; } export interface MonoRuntimeAttemptContext { readonly model: RuntimeModelReference; /** Index of this route in the chain. Stable across same-model retries. */ readonly attemptIndex: number; /** 0 for the first try of a route, then 1, 2, … for each same-model retry. */ readonly retryIndex: number; } export interface MonoRuntimeAttemptResolution { /** Optional isolated runtime for this route. */ readonly runtime?: MonoRuntimeLike; /** Private per-attempt provider options. These are never copied into router telemetry. */ readonly options?: Readonly> & { /** The sandbox implementation is owned by createMonoRuntime. */ readonly sandbox?: never; /** Attempt plugins cannot replace the host's durable process-job owner. */ readonly processJobs?: never; /** Attempt plugins cannot replace the host's durable monitor owner. */ readonly monitors?: never; /** Attempt plugins cannot replace the host's run-bound artifact sink. */ readonly persistArtifact?: never; }; /** Provider-specific projection of the logical tool policy for this attempt. */ readonly policyOptions?: Readonly>; readonly cleanup?: () => void | Promise; } export type MonoRuntimeAttemptResolver = (context: MonoRuntimeAttemptContext) => MonoRuntimeAttemptResolution | undefined | Promise; export interface CreateMonoRuntimeOptions extends MonoRuntimeHostOptions { /** The sandbox implementation is owned and injected by runtime-adapter. */ readonly sandbox?: never; /** * Ordered model chain for provider failover. When present, runs are served by * the agent-runtime fallback router: the first entry is attempted first and * each retryable provider failure advances to the next entry, so callers * should put the primary model at index 0. The router overrides the per-run * `model` with chain entries; failover details are reported on the result as * `failoverHistory`. */ readonly fallbackChain?: readonly MonoRuntimeFallbackChainEntry[]; /** Backoff shape for same-model retries. Per-route counts live on each chain entry's `attempts`. */ readonly retry?: MonoRuntimeRetryPolicy; /** Private host seam for actual-model provider options and route-owned runtimes. */ readonly resolveAttempt?: MonoRuntimeAttemptResolver; } export declare function createMonoRuntime(options?: CreateMonoRuntimeOptions): MonoRuntimeLike; export { createPiOAuthApiKeyResolver }; export declare function assertParsedRuntimeModelReference(value: unknown): asserts value is RuntimeModelReference; //# sourceMappingURL=runtime-adapter.d.ts.map