import { L as SessionStore, On as ToolResultContent, Tn as ToolBatchExecutor, Xt as AgentBehavior, Zt as AgentClock, b as ToolDef, ft as Provider, ht as StreamOptions, y as ToolContext } from "./agent-BHkvYIH9.js";
import { a as DetachedTasksCapability } from "./types-BibzMDjX.js";

//#region src/restate/types.d.ts
/**
 * Minimal structural types mirroring the subset of `@restatedev/restate-sdk`
 * the adapter touches. Kept in-house so:
 *
 *   1. `zidane/restate` typechecks **without** the SDK installed — useful in
 *      monorepos that vend `zidane` upstream of Restate.
 *   2. The contract is explicit at the seam: a handful of methods, not the
 *      full SDK surface. Drift between SDK versions surfaces as a single
 *      type error here instead of cascading through wrapper internals.
 *
 * Consumers wiring the real SDK pass `restate.Context` / `restate.ObjectContext`
 * directly — they're structurally assignable to the shapes below.
 */
/**
 * Subset of `restate.Context.run` used by the adapter.
 * The SDK's full signature accepts a richer options bag; this captures
 * what the adapter exercises.
 */
interface RestateRunOptions {
  /** Max retry attempts before surfacing a terminal error. */
  maxRetryAttempts?: number;
  /** Max retry duration before surfacing a terminal error. */
  maxRetryDuration?: unknown;
  /** Initial delay before the first retry. */
  initialRetryInterval?: unknown;
  /** Maximum delay between retries. */
  maxRetryInterval?: unknown;
  /** Exponential factor applied to retry intervals. */
  retryIntervalFactor?: number;
  /** Optional SDK serde passthrough for callers that need custom journal encoding. */
  serde?: unknown;
}
/**
 * Awakeable handle returned by {@link RestateContextLike.awakeable}.
 *
 * The SDK's full shape returns a `RestatePromise<T>`; we narrow to the
 * `Promise<T>` it extends because the adapter only awaits the result
 * (and a `RestatePromise<T>` is structurally assignable to `Promise<T>`).
 */
interface RestateAwakeable<T> {
  id: string;
  promise: Promise<T>;
}
/**
 * Structural subset of `restate.Context` covering everything the
 * adapter's pure wrappers need.
 *
 * `run` journals one side effect; on replay the journaled value returns
 * without re-executing `fn`. `date.now()` is async because the SDK
 * routes it through `ctx.run` internally — replay returns the journaled
 * timestamp. `rand.uuidv4()` is sync because the SDK seeds an in-memory
 * RNG from the invocation id, which is itself replay-stable.
 *
 * `awakeable<T>()` mints a journal-stable id paired with a pending
 * promise. The id is sent out-of-band (webhook, queue, collab stream)
 * and a separate handler resumes the wait via
 * `ctx.resolveAwakeable(id, …)` / `ctx.rejectAwakeable(id, …)`. The
 * adapter never resolves awakeables directly; consumers driving
 * human-in-the-loop tools (`ask_user`, `request_review`, …) do that
 * from the resumer side. Mirrors `@restatedev/restate-sdk` Context —
 * the real SDK accepts an optional `Serde<T>` we omit because the
 * adapter doesn't exercise it.
 */
interface RestateContextLike {
  run: <T>(name: string, fn: () => Promise<T> | T, options?: RestateRunOptions) => Promise<T>;
  date: {
    now: () => Promise<number>;
  };
  rand: {
    uuidv4: () => string;
  };
  awakeable: <T>() => RestateAwakeable<T>;
  /**
   * Durable timer — suspends the invocation for `millis` and survives
   * process death (replay resumes the same timer). Mirrors the SDK's
   * `Context.sleep(duration)`; we narrow the parameter to plain millis
   * (the SDK also accepts a `Duration`, which a wider implementation
   * signature satisfies structurally).
   *
   * What it's for in this adapter: durable timeouts. Racing
   * `awakeable.promise` against `sleep(timeoutMs)` is the canonical
   * "wait with a deadline" shape — see {@link awakeableWithTimeout},
   * which packages exactly that race for `waitBackground`-style parks.
   */
  sleep: (millis: number) => Promise<void>;
}
/**
 * Structural subset of `restate.ObjectContext` — adds keyed K/V state
 * scoped to the virtual-object instance the handler is bound to.
 *
 * `get` returns `null` for missing keys (SDK contract). `set` returns
 * void; the SDK journals the mutation transparently.
 */
interface RestateObjectContextLike extends RestateContextLike {
  key: string;
  get: <T>(name: string) => Promise<T | null>;
  set: <T>(name: string, value: T) => void;
  clear: (name: string) => void;
}
//#endregion
//#region src/restate/awakeable.d.ts
/**
 * Structural subset of the SDK's `RestatePromise` static surface used by
 * {@link awakeableWithTimeout} — mirrors `RestatePromiseAllLike` from
 * `./parallel`. Pass `RestatePromise` from `@restatedev/restate-sdk` so
 * the race goes through the journaled combinator; native `Promise.race`
 * over two durable promises leaves the winner to the runtime's replay
 * ordering instead of an explicit journal entry.
 */
interface RestatePromiseRaceLike<TPromise extends Promise<unknown> = Promise<unknown>> {
  race: (values: readonly TPromise[]) => Promise<unknown>;
}
interface AwakeableWithTimeoutOptions<TPromise extends Promise<unknown> = Promise<unknown>> {
  /**
   * Durable deadline in milliseconds. Unset / non-positive = no timeout
   * (the returned awakeable is the plain `ctx.awakeable()` passthrough).
   */
  timeoutMs?: number;
  /**
   * Durable race combinator — pass `RestatePromise` from the SDK. When
   * omitted, native `Promise.race` is used: correct at runtime and
   * replay-safe for THIS pattern (both branches are journaled
   * primitives), but the SDK combinator is the recommended belt-and-
   * braces choice for deterministic replay.
   */
  promises?: RestatePromiseRaceLike<TPromise>;
}
/**
 * Mint an awakeable that resolves with the resumer's payload, or `null`
 * when `timeoutMs` elapses first. The id is journal-stable (send it
 * out-of-band as usual); the timeout is a durable `ctx.sleep`, so a
 * parked invocation suspends instead of holding a worker.
 *
 * Timeout surfaces as `null` — a resumer that resolves `undefined` is
 * indistinguishable from a timeout, so resolve a concrete payload.
 *
 * ```ts
 * // waitBackground for a durable host, in three lines:
 * const { id, promise } = awakeableWithTimeout<TaskExitInfo>(ctx, { timeoutMs, promises: RestatePromise })
 * await registerExitResumer(taskId, id) // runner → ctx.resolveAwakeable(id, info)
 * return await promise                  // TaskExitInfo, or null on timeout
 * ```
 */
declare function awakeableWithTimeout<T, TPromise extends Promise<unknown> = Promise<unknown>>(ctx: RestateContextLike, options?: AwakeableWithTimeoutOptions<TPromise>): RestateAwakeable<T | null>;
//#endregion
//#region src/restate/awakeable-tool.d.ts
interface RestateAwakeableToolOptions<T = unknown> {
  /** Canonical tool name (what the model calls). */
  name: string;
  /** Model-facing tool description. */
  description: string;
  /** JSON schema for the tool input. */
  inputSchema: Record<string, unknown>;
  /** The Restate context the awakeable + journal entries bind to. */
  ctx: RestateContextLike;
  /**
   * Send the awakeable id (plus the call's input) out-of-band so a
   * resumer can later call `ctx.resolveAwakeable(awakeableId, value)`.
   * Runs inside `ctx.run` — fires exactly once across replays.
   */
  notify: (info: {
    awakeableId: string;
    input: Record<string, unknown>;
    toolCtx: ToolContext;
  }) => void | Promise<void>;
  /**
   * Map the resolved awakeable payload to the tool result. Default:
   * strings pass through, everything else is JSON-stringified.
   */
  toResult?: (value: T, input: Record<string, unknown>) => string | ToolResultContent[];
  /**
   * `ctx.run` options for the notify entry. Defaults to
   * `{ maxRetryAttempts: 1 }`, matching `restateTool`'s rationale.
   */
  runOptions?: RestateRunOptions;
  /**
   * Concurrency-safety flag passed through to the `ToolDef`. Defaults to
   * `false` — a parked wait holding a scheduler slot should barrier.
   */
  isConcurrencySafe?: boolean;
}
/**
 * Build a `ToolDef` that parks on a Restate awakeable until an external
 * resumer resolves it. See the module doc for the replay contract.
 *
 * Do NOT additionally wrap the returned tool in `restateTool` — the
 * journal discipline is already internal, and an outer `ctx.run` would
 * illegally nest the suspension point inside a journaled closure.
 */
declare function restateAwakeableTool<T = unknown>(options: RestateAwakeableToolOptions<T>): ToolDef;
//#endregion
//#region src/restate/behavior.d.ts
/**
 * Conservative behavior defaults for agents running inside Restate.
 *
 * The helper is opt-in and returns a plain AgentBehavior object, so callers can
 * spread or override it without changing non-Restate harness defaults.
 *
 * `disableBackgroundTasks: 'non-durable'` is capability-aware: background
 * tasks stay enabled for execution contexts whose
 * `capabilities.detachedTasks` is `'durable'` (tasks live on a remote
 * runner and survive worker crashes) and are disabled for everything
 * else (host-local processes don't survive process death). Hosts on
 * plain `ProcessContext` see the same effective behavior as the old
 * blanket `true`.
 */
declare function restateBehavior(overrides?: AgentBehavior): AgentBehavior;
//#endregion
//#region src/restate/clock.d.ts
/**
 * Wrap a Restate context's `date.now()` + `rand.uuidv4()` into the
 * {@link AgentClock} shape Zidane consumes for journaled metadata.
 *
 * The returned clock is a thin live view onto `ctx` — each call hits
 * the SDK afresh. No caching, no closure-captured values. Restate's
 * journal handles determinism on its end.
 */
declare function restateClock(ctx: RestateContextLike): AgentClock;
//#endregion
//#region src/restate/errors.d.ts
/**
 * Restate control-flow errors must escape the agent loop. If they are turned
 * into model-visible tool results, the runtime can retry/suspend incorrectly.
 *
 * Kept structural so `zidane/restate` does not need to import the SDK at
 * runtime just to recognize the common error shapes.
 */
declare function shouldRethrowRestateControlError(error: unknown): boolean;
//#endregion
//#region src/restate/parallel.d.ts
interface RestatePromiseAllLike<TPromise extends Promise<unknown> = RestatePromiseLike<unknown>> {
  all: (values: readonly TPromise[]) => Promise<readonly unknown[]>;
}
type RestatePromiseLike<T> = Promise<T> & {
  map: <U>(mapper: (value?: T, failure?: unknown) => U) => Promise<U>;
};
interface RestateToolBatchExecutorOptions<TPromise extends Promise<unknown> = RestatePromiseLike<unknown>> {
  /**
   * Wait for a safe fleet through Restate's durable combinator. Pass
   * `RestatePromise` from `@restatedev/restate-sdk` in real deployments.
   */
  promises: RestatePromiseAllLike<TPromise>;
}
/**
 * Tool batch scheduler for Restate-backed agents.
 *
 * It preserves unsafe-tool barriers and emits results in model submission
 * order. Safe fleets are started in submission order, capped by
 * `maxConcurrentTools`, and joined via the supplied durable `all()`.
 */
declare function restateToolBatchExecutor<TPromise extends Promise<unknown> = RestatePromiseLike<unknown>>(options: RestateToolBatchExecutorOptions<TPromise>): ToolBatchExecutor;
//#endregion
//#region src/restate/replay.d.ts
/**
 * Replay-state tracking + replay-aware abort for Restate-backed agents.
 *
 * ## The problem
 *
 * `agent.abort()` during a journal replay is undefined behavior: the
 * loop throws `AgentAbortedError` at whatever point the replay cursor
 * happens to be, the host's catch arm typically journals something
 * (`report-fail`, a status write) mid-journal, and the invocation dies
 * with `[570 Journal mismatch]` — permanently, because every retry
 * replays into the same mismatch. Hosts have been inferring liveness
 * from side channels (e.g. counting live provider stream calls), which
 * works only because `restateProvider` replays `llm-call-N` without
 * touching the live provider — incidental coupling, not API.
 *
 * ## The seam
 *
 * The wrappers already know the answer: on replay, `ctx.run` returns
 * the journaled value WITHOUT invoking the wrapped closure; the first
 * time a closure actually executes, the journal cursor is past the
 * replayed prefix and the invocation is live. {@link createReplayTracker}
 * packages that signal:
 *
 *   - `restateProvider(inner, ctx, { replayTracker })` and
 *     `restateTool(tool, ctx, { replayTracker })` mark the tracker live
 *     from inside their journaled closures.
 *   - `tracker.isReplaying()` is the public liveness probe.
 *   - `tracker.onLive(cb)` fires once at the replay→live transition
 *     (immediately when already live).
 *   - {@link replayAwareAbort} wraps `agent.abort` so external aborts
 *     queue during replay and apply at the first live boundary — the
 *     earliest point where the abort's side effects (loop throw, host
 *     catch-arm journaling) append to the journal instead of forking it.
 *
 * ## Wiring
 *
 * ```ts
 * const tracker = createReplayTracker({ hooks: agent.hooks })
 * const provider = restateProvider(inner, ctx, { replayTracker: tracker })
 * const tools = wrapAgentTools(agentTools, ctx, { replayTracker: tracker })
 * const abort = replayAwareAbort(tracker, () => agent.abort())
 * // external cancel signal → abort() instead of agent.abort()
 * ```
 *
 * One tracker per handler invocation — like the wrappers themselves, it
 * is constructed fresh each attempt and must not be reused across
 * invocations.
 *
 * ## Semantics fine print
 *
 * "Replaying" is defined conservatively: `isReplaying()` returns `true`
 * until the first live closure executes. A fresh (non-resumed)
 * invocation therefore reports "replaying" for the short window before
 * its first journaled call — harmless for the abort use case (the abort
 * applies moments later, at that first live execution) and the honest
 * answer for journal safety: before the first `ctx.run` settles you
 * cannot know whether the SDK is about to feed you journal entries.
 *
 * A replay that completes without ever going live (the journaled run
 * already finished; the handler exits during replay) never fires
 * `onLive` — queued aborts are dropped with the invocation, which is
 * correct: there is nothing left to abort.
 */
/** Minimal structural slice of the agent's Hookable for `replay:done`. */
interface ReplayDoneHooks {
  callHook: (name: 'replay:done', ctx: Record<string, never>) => unknown;
}
interface ReplayTrackerOptions {
  /**
   * Agent hooks to notify at the replay→live transition. When set, the
   * tracker fires `replay:done` exactly once, right after the `onLive`
   * callbacks. Rejections are swallowed (surfaced under `ZIDANE_DEBUG`)
   * — a misbehaving listener must not break the live execution that
   * triggered the transition.
   */
  hooks?: ReplayDoneHooks;
}
interface ReplayTracker {
  /**
   * `true` until the first live (non-journaled) execution of a wrapped
   * provider stream / tool body. See the module doc for the fresh-
   * invocation caveat.
   */
  isReplaying: () => boolean;
  /**
   * Register a callback for the replay→live transition. Fires once.
   * When the tracker is already live, the callback runs synchronously
   * before `onLive` returns. Returns an unregister function (no-op
   * after firing).
   */
  onLive: (cb: () => void) => () => void;
  /**
   * Mark the invocation live. Called by the wrappers from inside their
   * journaled closures — a closure only executes when the journal
   * cursor is past it. Idempotent; only the first call transitions.
   */
  markLive: () => void;
}
/**
 * Create a per-invocation replay tracker. Pass it to `restateProvider`
 * / `restateTool` / `wrapAgentTools` via their `replayTracker` option;
 * consume it via `isReplaying()` / `onLive()` / {@link replayAwareAbort}.
 */
declare function createReplayTracker(options?: ReplayTrackerOptions): ReplayTracker;
/**
 * Wrap an abort function so it defers during journal replay.
 *
 * Live invocation → `abort()` runs immediately, exactly like calling
 * `agent.abort()` directly. Replaying invocation → the abort is queued
 * and applied at the first live boundary (the start of the first
 * non-journaled provider stream or tool body), where the resulting
 * `AgentAbortedError` + host catch-arm journaling append to the journal
 * instead of forking it mid-replay. Multiple calls during replay
 * collapse into one queued abort.
 */
declare function replayAwareAbort(tracker: ReplayTracker, abort: () => void): () => void;
//#endregion
//#region src/restate/provider.d.ts
interface RestateProviderOptions {
  /**
   * `ctx.run` options forwarded on every wrapped stream call.
   *
   * Default depends on {@link streamCallbacks}:
   *
   * - `'suppress'` → `{ maxRetryAttempts: 3 }` — provider transients
   *   (rate limits, 5xx, connection resets) get retried inside the
   *   journal entry; nothing streams to the host, so a retry is
   *   invisible.
   * - `'live'` (the default) → `{ maxRetryAttempts: 1 }`. A live stream
   *   that fails AFTER emitting deltas would be re-run inside the same
   *   journal entry, re-firing `onText` into the loop's accumulating
   *   text buffer and producing duplicated partial1+full2 output. The
   *   loop's own retry (which only re-issues on a clean slate) is the
   *   correct retry layer in live mode.
   *
   * Once the cap is reached the failure becomes terminal and surfaces
   * through the loop's normal `AgentProviderError` path. Set this
   * explicitly to override either default — but with live callbacks,
   * `maxRetryAttempts > 1` re-introduces the duplicate-delta hazard.
   */
  runOptions?: RestateRunOptions;
  /**
   * Override the journal-entry name. Receives the 1-indexed sequence
   * number for this wrapper instance and the `StreamOptions` of the
   * call. Default: `llm-call-<n>`. Override to inject extra structure
   * (e.g. `${agentName}/llm-call-${n}`) when multiple agents share a
   * service.
   */
  entryName?: (seq: number, opts: StreamOptions) => string;
  /**
   * Whether live stream callbacks should fire during the original execution.
   * Use `'suppress'` for strict durable mode: the model call still returns a
   * full TurnResult, and UIs reconstruct from persisted session turns.
   *
   * Default: `'live'`.
   */
  streamCallbacks?: 'live' | 'suppress';
  /**
   * Per-invocation replay tracker (see `createReplayTracker`). When set,
   * the wrapper marks it live from inside the journaled closure — i.e.
   * the first time the inner provider is ACTUALLY invoked rather than
   * replayed from the journal. Share one tracker across the provider
   * and tool wrappers of the same handler invocation.
   */
  replayTracker?: ReplayTracker;
}
/**
 * Wrap a Zidane `Provider` so its `stream()` method journals each turn's
 * response inside `ctx.run`. All other Provider methods (`formatTools`,
 * `userMessage`, `toolResultsMessage`, `classifyError`, …) pass through
 * unchanged — they're pure functions over already-deterministic inputs.
 */
declare function restateProvider(inner: Provider, ctx: RestateContextLike, options?: RestateProviderOptions): Provider;
//#endregion
//#region src/restate/session.d.ts
/**
 * Construct a `SessionStore` backed by the bound virtual-object's K/V
 * state. The store is single-tenant — every method ignores the
 * `sessionId` argument because the virtual object is already keyed by
 * `ctx.key`. Calling `appendTurns('other-id', …)` writes to the
 * CURRENT object's state, not the one named in the argument. Bind one
 * virtual-object key per session and the contract holds.
 */
declare function restateSessionStore(ctx: RestateObjectContextLike): SessionStore;
//#endregion
//#region src/restate/tool.d.ts
/**
 * Opt-in two-phase journaling for long-running, re-attachable tools.
 *
 * The default `restateTool` wrapping journals only the COMPLETED result —
 * a crash mid-execute re-runs the tool on replay, which is unacceptable
 * for builds / migrations / deploys. `durableStart` splits the execution:
 *
 *   1. `start` runs inside its own `ctx.run` entry, journaled BEFORE the
 *      body — it kicks off the side effect and returns a re-attach token
 *      (a background task id, a job handle, an idempotency key).
 *   2. the wait — either `attach` (one `ctx.run` holding the wait in the
 *      result entry; only for short, bounded waits) or `wait` (awakeable
 *      park: register a resumer in a journaled entry, suspend outside
 *      the journal, synthesize the result in a final entry). On replay
 *      both receive the SAME token and re-attach to the already-running
 *      work instead of starting it again.
 *
 * The wrapped tool's own `execute` is bypassed; the start + wait pair IS
 * the execution.
 */
interface RestateDurableStart<Token = unknown, Resumed = unknown> {
  /** Kick off the side effect; journaled before `attach`. Must be cheap + idempotent-safe up to journal persistence. */
  start: (input: Record<string, unknown>, toolCtx: ToolContext) => Promise<Token> | Token;
  /**
   * Await / re-attach to the work identified by `token` and produce the
   * tool result. Runs inside ONE `ctx.run` entry, so the body must
   * settle within the runtime's attempt lifecycle — a long busy-poll in
   * here starves the journal, trips the server's inactivity/abort
   * timeouts, and each retry restarts the wait from scratch. Use this
   * only for waits bounded well below the inactivity timeout (or as the
   * degraded mode on hosts without a push seam); prefer {@link wait}
   * for anything long-running.
   *
   * Required unless {@link wait} is provided; ignored when both are set.
   */
  attach?: (token: Token, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<string | ToolResultContent[]>;
  /**
   * Awakeable-based completion wait — the durable alternative to
   * {@link attach} for long-running work on hosts with a push seam
   * (e.g. a runner that fires `task:exit` → resumer → `ctx.resolveAwakeable`).
   * `executeTwoPhase` orchestrates three phases with the same journal
   * discipline as `restateAwakeableTool`:
   *
   *   1. `register` — a short, journaled `ctx.run`: hand the awakeable
   *      id to the host as the exit resumer for `token`. Fires exactly
   *      once across replays (marker invariant included).
   *   2. park — `await awakeable.promise`, OUTSIDE any `ctx.run`. The
   *      invocation suspends cleanly: no held worker, immune to
   *      inactivity/abort timeouts. With `timeoutMs`, the park is a
   *      durable race against `ctx.sleep` (replay-stable — no
   *      `Date.now()` deadline that resets per attempt).
   *   3. `result` — a final journaled `ctx.run`: synthesize the tool
   *      result from the resumer payload (`null` = timeout; kill the
   *      job and shape the timeout result here).
   */
  wait?: RestateDurableWait<Token, Resumed>;
  /**
   * Best-effort cleanup when the per-call abort signal fires before the
   * wait settles — `attach` or the awakeable park alike (run abort,
   * `agent.cancelTool`, sibling-cascade
   * cancel, `agent.destroy()` mid-run). Without it, the journaled token
   * identifies a remote job that keeps running with nobody attached —
   * a leak for hosts whose jobs outlive the session.
   *
   * Contract:
   *   - Fires at most once per call, outside the journal (an aborting
   *     invocation can't open new `ctx.run` entries reliably) — journal
   *     your own cleanup on the host side if it must be durable.
   *   - May run concurrently with a still-unwinding `attach`; make it
   *     idempotent against "job already gone".
   *   - NOT called on process death — that's not termination: the
   *     journaled token re-attaches on replay instead. This seam is for
   *     deliberate aborts, where no replay is coming.
   *   - Errors are swallowed (surfaced under `ZIDANE_DEBUG`) — cleanup
   *     failure must not mask the abort itself.
   */
  onAbort?: (token: Token, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<void> | void;
}
/**
 * Awakeable-based completion wait for {@link RestateDurableStart.wait}.
 *
 * Replay contract (mirrors `restateAwakeableTool`):
 * - The awakeable is minted BEFORE the journaled `register` entry, so on
 *   replay both come back in the same order with the same id — a replayed
 *   call re-parks on the SAME awakeable without re-registering.
 * - The journaled marker records the awakeable id it was registered for;
 *   a mismatch on replay (journal drift) throws instead of parking on an
 *   id nobody will ever resolve.
 */
interface RestateDurableWait<Token = unknown, Resumed = unknown> {
  /**
   * Register `awakeableId` as the exit resumer for the work identified
   * by `token` — the host must call `ctx.resolveAwakeable(awakeableId,
   * payload)` when the work completes. Runs inside `ctx.run`; must be
   * short and idempotent-safe up to journal persistence.
   */
  register: (token: Token, awakeableId: string, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<void> | void;
  /**
   * Synthesize the tool result once the park settles. `resumed` is the
   * resumer's payload, or `null` when `timeoutMs` elapsed first — kill
   * the still-running job and shape the timeout result in that branch.
   * Runs inside the final journaled `ctx.run` (the result entry).
   */
  result: (token: Token, resumed: Resumed | null, input: Record<string, unknown>, toolCtx: ToolContext) => Promise<string | ToolResultContent[]> | string | ToolResultContent[];
  /**
   * Durable park deadline in milliseconds — becomes the
   * `awakeableWithTimeout` duration (a `ctx.sleep` raced against the
   * awakeable, replay-stable). A function receives the call's input so
   * the model's own `timeout` parameter can drive it. Unset /
   * non-positive = park indefinitely.
   */
  timeoutMs?: number | ((input: Record<string, unknown>, toolCtx: ToolContext) => number | undefined);
  /**
   * Durable race combinator for the timeout race — pass `RestatePromise`
   * from the SDK. See `awakeableWithTimeout`'s rationale; native
   * `Promise.race` is the fallback.
   */
  promises?: RestatePromiseRaceLike;
  /**
   * Per-call fast path: when this returns `true` for the journaled
   * `token`, the awakeable park is SKIPPED entirely — no awakeable is
   * minted, no `-register` entry is journaled, and the invocation never
   * suspends. `result` is invoked directly with `resumed = null` inside
   * the final result entry.
   *
   * This is for `start` phases that sometimes have nothing to wait on
   * (e.g. a shell tool that only spawns a real background task above a
   * duration threshold and otherwise runs the command inline in
   * `result`). Parking such calls pays a full suspend → resolve →
   * re-invoke → replay round-trip for nothing.
   *
   * MUST be a pure function of the journaled `token` (+ input) so the
   * decision is identical across replays — a token-derived branch keeps
   * the journal entry shape deterministic. When omitted, every call
   * parks (the original behaviour).
   */
  inline?: (token: Token, input: Record<string, unknown>, toolCtx: ToolContext) => boolean;
}
interface RestateToolOptions<Token = unknown, Resumed = unknown> {
  /**
   * `ctx.run` options forwarded on every wrapped tool call. Defaults to
   * `{ maxRetryAttempts: 1 }` — tool errors are typically deterministic
   * (validation failures, missing files) so blind retries waste budget.
   * Override per-tool for network-heavy custom tools that benefit from
   * SDK-level retries.
   */
  runOptions?: RestateRunOptions;
  /**
   * Override the journal-entry name. Receives the canonical tool name
   * and the call's input. Default: `tool-<name>-<seq>` where `<seq>` is
   * a per-wrapper monotonic counter. Override to inject the model's
   * `callId` (read it off `ToolContext.callId` inside `execute` if you
   * need an LLM-visible key — but the default counter is sufficient
   * for journal correctness).
   */
  entryName?: (seq: number, name: string, input: Record<string, unknown>) => string;
  /**
   * Hide and reject the built-in shell tool's background mode.
   *
   * Default: derived from {@link RestateToolOptions.detachedTasks} —
   * disabled unless the execution context declares `'durable'` detached
   * tasks. An explicit boolean always wins.
   */
  disableShellBackground?: boolean;
  /**
   * `detachedTasks` capability of the execution context the agent will
   * run with (see `ContextCapabilities.detachedTasks` /
   * `resolveDetachedTasksCapability`). Drives the
   * `disableShellBackground` default: a `'durable'` context keeps its
   * background tasks across worker crashes, so the wrapper leaves the
   * shell tool's background mode intact.
   *
   * Default: `undefined`, treated as non-durable (background disabled).
   */
  detachedTasks?: DetachedTasksCapability;
  /**
   * Two-phase start/attach journaling for crash-safe long tools — see
   * {@link RestateDurableStart}. Per-tool by nature; not accepted by
   * `wrapAgentTools` (a single start/attach pair can't fit a whole map).
   */
  durableStart?: RestateDurableStart<Token, Resumed>;
  /**
   * Per-invocation replay tracker (see `createReplayTracker`). When set,
   * the wrapper marks it live from inside its journaled closures — i.e.
   * the first time a tool body (or a `durableStart.start` phase)
   * ACTUALLY executes rather than replaying from the journal. Share one
   * tracker across the provider and tool wrappers of the same handler
   * invocation.
   */
  replayTracker?: ReplayTracker;
}
/**
 * Wrap a single `ToolDef` so its `execute` runs inside `ctx.run`. The
 * tool's `spec` and `isConcurrencySafe` pass through unchanged.
 */
declare function restateTool<Token = unknown, Resumed = unknown>(inner: ToolDef, ctx: RestateContextLike, options?: RestateToolOptions<Token, Resumed>): ToolDef;
/**
 * Wrap an entire tool map at once — convenience for the common case of
 * "journal every tool the agent has". Pass-through for tools whose
 * names are listed in `opts.exclude` (e.g. fully-deterministic local
 * helpers where journaling is pure overhead).
 *
 * The returned map is a fresh object; the input is untouched.
 */
declare function wrapAgentTools(tools: Record<string, ToolDef>, ctx: RestateContextLike, opts?: Omit<RestateToolOptions, 'durableStart'> & {
  exclude?: readonly string[];
}): Record<string, ToolDef>;
//#endregion
export { type AwakeableWithTimeoutOptions, type ReplayDoneHooks, type ReplayTracker, type ReplayTrackerOptions, type RestateAwakeable, type RestateAwakeableToolOptions, type RestateContextLike, type RestateDurableStart, type RestateDurableWait, type RestateObjectContextLike, type RestatePromiseAllLike, type RestatePromiseLike, type RestatePromiseRaceLike, type RestateProviderOptions, type RestateRunOptions, type RestateToolBatchExecutorOptions, type RestateToolOptions, awakeableWithTimeout, createReplayTracker, replayAwareAbort, restateAwakeableTool, restateBehavior, restateClock, restateProvider, restateSessionStore, restateTool, restateToolBatchExecutor, shouldRethrowRestateControlError, wrapAgentTools };
//# sourceMappingURL=restate.d.ts.map