import type { DeliverPayload, SessionAuthContext, SubagentInputRequestHookPayload } from "#channel/types.js";
import { deserializeContext } from "#context/serialize.js";
import type { HarnessSession, StepInput } from "#harness/types.js";
import type { JsonObject } from "#shared/json.js";
import type { RunMode } from "#shared/run-mode.js";
import { type DurableSessionState } from "#execution/durable-session-store.js";
import { type TurnStepInput, type TurnWorkflowDispatchInput } from "#execution/durable-session-migrations/turn-workflow.js";
/**
 * Result of one durable harness step, consumed by the turn workflow.
 *
 * `park` carries `hasPendingInputBatch`, `hasPendingAuthorization`, and
 * `pendingRuntimeActionKeys` so the turn workflow can pick the right
 * {@link import("#execution/next-driver-action.js").NextDriverAction}
 * arm without re-reading the session.
 */
export type DurableStepResult = {
    readonly action: "continue" | "done";
    readonly output?: unknown;
    readonly isError?: boolean;
    readonly serializedContext: Record<string, unknown>;
    readonly sessionState: DurableSessionState;
} | {
    readonly action: "park";
    readonly authorizationNames?: readonly string[];
    readonly hasPendingAuthorization: boolean;
    readonly hasPendingInputBatch: boolean;
    readonly pendingRuntimeActionKeys?: readonly string[];
    readonly serializedContext: Record<string, unknown>;
    readonly sessionState: DurableSessionState;
} | {
    readonly action: "dispatch-code-mode-runtime-actions";
    readonly pendingRuntimeActionKeys: readonly string[];
    readonly serializedContext: Record<string, unknown>;
    readonly sessionState: DurableSessionState;
};
export type { TurnStepInput };
/**
 * Runs one atomic harness step inside a durable `"use step"` boundary.
 */
export declare function turnStep(rawInput: TurnStepInput): Promise<DurableStepResult>;
/**
 * Re-stamps `session.continuationToken` from `ContinuationTokenKey`
 * after channels call `setContinuationToken(...)`. Idempotent when the
 * token is unchanged.
 */
export declare function reconcileSessionContinuationToken(ctx: Awaited<ReturnType<typeof deserializeContext>>, session: HarnessSession): HarnessSession;
/**
 * Resolves the single output schema in effect for this turn, decoupling schema
 * enforcement from {@link RunMode}: downstream the harness reads
 * `session.outputSchema` unconditionally and never re-derives it from mode.
 *
 * A run-scoped (client-supplied) schema on the turn's {@link StepInput} always
 * wins. With no run-scoped schema, a task run adopts the agent's declared
 * return schema — its function-output contract, which only applies when the
 * agent is invoked as a function (subagent / schedule / job), i.e. task mode.
 * A conversation run with no run-scoped schema enforces nothing. Continuation
 * steps (no new `StepInput`) preserve whatever is already in effect.
 */
export declare function resolveEffectiveOutputSchema(input: {
    readonly agentOutputSchema: JsonObject | undefined;
    readonly input: StepInput | undefined;
    readonly mode: RunMode;
    readonly session: HarnessSession;
}): HarnessSession;
/** Emits a terminal `session.failed` to the adapter and durable stream. */
export declare function emitTerminalSessionFailureStep(input: {
    readonly error: unknown;
    readonly parentWritable: WritableStream<Uint8Array>;
    readonly serializedContext: Record<string, unknown>;
}): Promise<void>;
export interface ProxyInputRequestResult {
    readonly serializedContext: Record<string, unknown>;
    readonly sessionState: DurableSessionState;
}
/**
 * Emits a proxied `input.requested` event through the parent's adapter
 * and records the routing entries on the parent session.
 */
export declare function runProxyInputRequestStep(input: {
    readonly hookPayload: SubagentInputRequestHookPayload;
    readonly parentWritable: WritableStream<Uint8Array>;
    readonly serializedContext: Record<string, unknown>;
    readonly sessionState: DurableSessionState;
}): Promise<ProxyInputRequestResult>;
export interface RoutedDeliverResult {
    /** `undefined` when the entire payload was routed to descendants. */
    readonly remainder: DeliverPayload | undefined;
}
/**
 * Splits an inbound deliver payload into parent-local and
 * proxied-child buckets and forwards the child buckets via
 * `resumeHook`. Read-only: never appends a snapshot.
 */
export declare function routeProxiedDeliverStep(input: {
    readonly auth?: SessionAuthContext | null;
    readonly parentWritable: WritableStream<Uint8Array>;
    readonly payload: DeliverPayload;
    readonly sessionState: DurableSessionState;
}): Promise<RoutedDeliverResult>;
/** Starts a per-turn child workflow for the current driver session. */
export declare function dispatchTurnStep(input: TurnWorkflowDispatchInput): Promise<{
    readonly runId: string;
}>;
