import { type Api, type Context, type Model, type SimpleStreamOptions } from '../ai/types.js';
import { type ShortcutXLModelStreamEvent, type ShortcutXLModelStreamFetchTrace, type ShortcutXLModelStreamMessage, type ShortcutXLModelStreamRequest } from '../contracts/model-stream.js';
type ShortcutRuntimeMessage = ShortcutXLModelStreamMessage;
export interface ShortcutRuntimeRequestBody {
    effort_level?: 'low' | 'medium' | 'high' | 'max';
    max_tokens?: number;
    messages: {
        content: string;
        role: ShortcutRuntimeMessage['role'];
        thinking?: string;
        thinking_signature?: string;
        tool_call_id?: string;
        tool_calls?: {
            arguments: string;
            id: string;
            name: string;
        }[];
    }[];
    model: string;
    user_message_id?: string;
    /**
     * Per-turn speed mode. The proxy's `LLMRequest.speed` field validates
     * `'fast' | 'standard'`. Server-side gating ensures fast mode only
     * applies to supported models.
     */
    speed?: 'fast' | 'standard';
    thinking_type?: 'adaptive' | 'off';
    tools?: {
        description: string;
        name: string;
        parameters: Record<string, unknown>;
    }[];
}
interface ShortcutXLModelStreamWorkspaceContext {
    readonly workspaceId?: string;
    readonly workspaceType?: 'file' | 'project' | 'global';
}
/**
 * Owned AI `thinkingLevel` ↔ proxy's `effort_level`. Exported so the
 * run-stats accumulator can stamp the same effort label on the run-stats
 * entry that the proxy actually used. Keeping a single source of truth
 * prevents drift between what the LLM saw and what the dropdown shows.
 */
export declare const ShortcutThinkingLevelToEffort: {
    readonly minimal: "low";
    readonly low: "low";
    readonly medium: "medium";
    readonly high: "high";
    readonly xhigh: "max";
};
/** Host plumbing the embedded runtime needs to reach the stream endpoint. */
export interface ShortcutXLModelStreamHostOptions {
    readonly baseUrl?: string;
    readonly clientPlatform?: string;
    readonly fetchImpl?: typeof fetch;
    /** Override only the legacy `/api/llm/stream` fetch URL. Defaults to `baseUrl`. */
    readonly streamBaseUrl?: string;
    readonly getAccessToken?: () => Promise<string | undefined>;
    /**
     * Refreshes host-owned credentials after a 401 from the stream proxy. Workers
     * cannot refresh auth directly, so they call back into the host through this
     * hook and retry the stream request once.
     */
    readonly refreshAccessToken?: () => Promise<string | undefined>;
    /**
     * Resolves the active conversation thread id at request time. Sent as the
     * `X-Session-Id` header — the backend `/api/llm/stream` proxy uses it for
     * `langfuse_session_id`, `thread_id` on token-event webhooks, and
     * trace grouping. Without this, every call is bucketed under the
     * synthetic fallback `llm-proxy-{user_id}` and per-thread reconciliation
     * breaks.
     */
    readonly getSessionId?: () => string | undefined;
    readonly getWorkspaceContext?: () => ShortcutXLModelStreamWorkspaceContext | undefined;
    /**
     * Observability hook fired after the runtime has normalized context/options
     * into the exact JSON payload shape sent to `/api/llm/stream`.
     * Credentials and transport headers are intentionally excluded.
     */
    readonly onRequest?: (request: ShortcutXLModelStreamRequest, body: ShortcutRuntimeRequestBody) => void;
    /**
     * Diagnostic hook fired when a stream fetch fails. Distinguishes failure
     * stages that aren't visible in the generic `recovery_started` telemetry:
     *   - `before_response`: `fetch()` rejected before any `Response` (DNS,
     *     CORS preflight, network unreachable, captive portal). The
     *     opaque "Failed to fetch" / "Load failed" case.
     *   - `non_ok_response`: backend returned a response with status outside 2xx.
     *   - `response_body`: the response started but the SSE read failed or
     *     idle-timed out mid-stream.
     * Headers/body intentionally excluded — only diagnostic metadata is sent.
     */
    readonly onFetchTrace?: (event: ShortcutXLModelStreamFetchTrace) => void;
    /** Retry budget for retryable stream transport failures. Defaults to 2 retries. */
    readonly maxStreamRetries?: number;
    readonly streamRetryBaseDelayMs?: number;
    readonly streamRetryMaxDelayMs?: number;
    /**
     * Ceiling for server-supplied `Retry-After` delays. Distinct from
     * `streamRetryMaxDelayMs` (which only bounds client-computed backoff).
     */
    readonly streamRetryServerMaxDelayMs?: number;
}
/** Inputs needed to assemble the wire-shape stream request. */
export interface CreateShortcutXLModelStreamRequestOptions {
    readonly context: Context;
    readonly model: Model<Api>;
    readonly options?: SimpleStreamOptions;
    readonly requestId: string;
}
/** Per-call options layered on top of host options for `runShortcutXL...`. */
export interface RunShortcutXLModelStreamRequestOptions extends ShortcutXLModelStreamHostOptions {
    readonly apiKey?: string;
    onEvent(event: ShortcutXLModelStreamEvent): void;
    readonly signal?: AbortSignal;
    readonly streamIdleTimeoutMs?: number;
}
/** Convert owned AI `Context` + model into the ShortcutXL stream request shape. */
export declare function createShortcutXLModelStreamRequest(options: CreateShortcutXLModelStreamRequestOptions): ShortcutXLModelStreamRequest;
export declare function buildShortcutRuntimeRequestBody(request: ShortcutXLModelStreamRequest): ShortcutRuntimeRequestBody;
/**
 * Drive one stream request to completion. Emits Start/Delta/.../Done|Error
 * events through `onEvent`. Always emits a terminal Error event on abort or
 * failure so consumers never need to time out.
 */
export declare function runShortcutXLModelStreamRequest(request: ShortcutXLModelStreamRequest, options: RunShortcutXLModelStreamRequestOptions): Promise<void>;
/**
 * Build a owned AI-compatible `streamFn` bound to the given host. The returned
 * function fires off one request per call and pushes events into a fresh
 * assistant-message event stream.
 */
export declare function createShortcutXLModelStream(hostOptions?: ShortcutXLModelStreamHostOptions): (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => import("../ai/event-stream.js").AssistantMessageEventStream;
export {};
//# sourceMappingURL=stream.d.ts.map