import {
  _ as LifecycleJobContext,
  o as MemoryLimitContext,
  v as LifecycleJobOutcome,
  x as Connection
} from "./capability-runner-BUBa6Ake.js";
import { t as Lifecycle } from "./durable-object-lifecycle-ei7M7lqB.js";
import { AsyncLocalStorage } from "node:async_hooks";
import { DurableObject } from "cloudflare:workers";

//#region src/lifecycle/current-agent.d.ts
/**
 * A Durable Object that has installed the Agents SDK Lifecycle.
 *
 * Pass a more specific Lifecycle Object type to {@link getCurrentAgent} when
 * shared host code needs APIs implemented by a particular object.
 *
 * @experimental The API surface may change before stabilizing.
 */
interface LifecycleObject<
  Env extends object = Cloudflare.Env,
  Props extends Record<string, unknown> = Record<string, unknown>
> extends DurableObject<Env> {
  readonly lifecycle: Lifecycle<Env, Props>;
  onStart?(props?: Props): void | Promise<void>;
  onRequest?(request: Request): Response | Promise<Response>;
  onAlarm?(): void | Promise<void>;
  onJob?(
    context: LifecycleJobContext
  ): LifecycleJobOutcome | void | Promise<LifecycleJobOutcome | void>;
  /**
   * Host domain policy applied when the alarm memory-limit circuit breaker
   * records a strike (#1825), after every capability's `onMemoryLimit` hook.
   *
   * Lifecycle dispatches host hooks structurally through its internal host
   * cast, so TS visibility is the host's to choose: a framework host whose
   * implementation is internal machinery declares the hook `protected` (the
   * pattern — see `AIChatAgent`/`Think`) and keeps the real work in a
   * `private _cf_`-prefixed method, without falling out of this contract at
   * runtime.
   */
  onAlarmMemoryLimit?(context: MemoryLimitContext): void | Promise<void>;
}
/** Values associated with the currently executing Lifecycle host. */
type AgentContextStore = {
  /** Lifecycle host selected for this invocation. */ agent: unknown /** WebSocket connection selected for this invocation, when applicable. */;
  connection:
    | Connection
    | undefined /** HTTP request selected for this invocation, when applicable. */;
  request:
    | Request
    | undefined /** Extension-owned value selected for this invocation, when applicable. */;
  email: unknown;
};
/** Values returned by {@link getCurrentAgent}. */
type CurrentAgentContext<
  Host extends DurableObject = LifecycleObject,
  Email = unknown
> = {
  agent: Host | undefined;
  connection: Connection | undefined;
  request: Request | undefined;
  email: Email | undefined;
};
/**
 * Shared invocation context for Lifecycle, Agent, AIChatAgent, and Think.
 *
 * @internal Importing or relying on this symbol will break your code in a
 * future release. Use {@link getCurrentAgent} to read the public context.
 */
declare const __DO_NOT_USE_WILL_BREAK__agentContext: AsyncLocalStorage<AgentContextStore>;
/**
 * Return the current Agent or Lifecycle Object and invocation-specific values.
 *
 * Lifecycle host startup and alarm hooks receive the current object with no
 * request. Request hooks additionally receive the request being handled.
 * Lifecycle-managed WebSocket hooks receive their connection and, during
 * connect, its upgrade request. Agent extensions may also establish context
 * for email, chat turns, callable methods, and detached work. Capability hooks
 * do not run in this ambient context.
 */
declare function getCurrentAgent<
  Host extends DurableObject = LifecycleObject
>(): CurrentAgentContext<Host>;
//#endregion
export {
  getCurrentAgent as a,
  __DO_NOT_USE_WILL_BREAK__agentContext as i,
  CurrentAgentContext as n,
  LifecycleObject as r,
  AgentContextStore as t
};
//# sourceMappingURL=current-agent-C4w86kcN.d.ts.map
