import { SessionEnrichments } from "./core/enrichments.js";
import { AiMessageOpts, BoundAgent, EmbeddingOpts, ScoreOpts, SpanOpts, ToolCallOpts, UserMessageOpts } from "./bound-agent.js";

//#region src/session.d.ts

/** @internal Reset the one-time warning flag. For test isolation only. */
declare function _resetRunSyncWarning(): void;
interface SessionOptions {
  sessionId?: string | null;
  /**
   * Idle-timeout hint for the enrichment pipeline (minutes). Defaults to the
   * pipeline default (~30 min); positive values are honored up to 90 days
   * (129600, values above are clamped). `-1` means "rely on an explicit
   * `[Agent] Session End`" — the session is enriched early on an explicit end,
   * with a 90-day inactivity backstop so it never leaks open forever. See
   * {@link BoundAgent.session}.
   */
  idleTimeoutMinutes?: number | null;
  userId?: string | null;
  deviceId?: string | null;
  browserSessionId?: string | null;
  /**
   * User-defined tags for filtering/segmentation.
   */
  tags?: string[] | null;
  /**
   * Automatically flush pending events when `run()` completes.
   *
   * - `true`  — always flush (recommended for serverless)
   * - `false` — never flush (for long-running servers where the periodic timer handles it)
   * - `undefined` (default) — auto-detect: flush if a serverless environment is detected
   */
  autoFlush?: boolean;
  /**
   * Emit `[Agent] Session End` when `run()` finishes.
   *
   * - `true` (default) — always emit session-end
   * - `false` — suppress, useful for middleware/delegation contexts
   *   where the caller manages session lifecycle externally
   */
  trackSessionEnd?: boolean;
}
declare class Session {
  readonly sessionId: string;
  traceId: string | null;
  readonly idleTimeoutMinutes: number | null;
  readonly userId: string | null;
  readonly deviceId: string | null;
  readonly browserSessionId: string | null;
  readonly tags: string[] | null;
  readonly autoFlush: boolean;
  readonly trackSessionEnd: boolean;
  /** @internal Set by `runAs()` to suppress auto user-message tracking in delegation contexts. */
  _skipAutoUserTracking: boolean;
  private _agent;
  private _enrichments;
  private _sessionReplayId;
  constructor(agent: BoundAgent, opts?: SessionOptions);
  private _buildSessionContext;
  newTrace(): string;
  setEnrichments(enrichments: SessionEnrichments): void;
  /**
   * Run a callback within this session context.
   * This is the Node.js equivalent of Python's `with session as s:` block.
   *
   * When {@link autoFlush} is `true` (default in serverless environments),
   * all pending events are flushed before the promise resolves. This
   * prevents event loss when the serverless runtime freezes or terminates
   * after the handler returns.
   */
  run<T>(fn: (session: Session) => T | Promise<T>): Promise<T>;
  /**
   * Synchronous version of run() for non-async code.
   *
   * Note: `autoFlush` has no effect here because `runSync` cannot await
   * the asynchronous flush.  Use `session.run()` (async) or call
   * `await ai.flush()` manually after `runSync` returns.
   */
  runSync<T>(fn: (session: Session) => T): T;
  /**
   * Run a callback as a child agent within this session.
   *
   * Provider wrappers automatically pick up the child agent's identity
   * (`agentId`, `parentAgentId`) while sharing this session's `sessionId`,
   * `traceId`, and turn counter. No `[Agent] Session End` is emitted.
   *
   * @example
   * ```typescript
   * const child = parentAgent.child('researcher');
   * await session.run(async (s) => {
   *   const result = await s.runAs(child, async (cs) => {
   *     // provider wrappers see agentId='researcher'
   *     return openai.chat.completions.create({ ... });
   *   });
   * });
   * ```
   */
  runAs<T>(childAgent: BoundAgent, fn: (session: Session) => T | Promise<T>): Promise<T>;
  /**
   * Synchronous version of {@link runAs}.
   */
  runAsSync<T>(childAgent: BoundAgent, fn: (session: Session) => T): T;
  private _autoEnd;
  private _flush;
  private _inject;
  trackUserMessage(content: string, opts?: UserMessageOpts): string;
  trackAiMessage(content: string, model: string, provider: string, latencyMs: number, opts?: AiMessageOpts): string;
  trackToolCall(toolName: string, latencyMs: number, success: boolean, opts?: ToolCallOpts): string;
  trackEmbedding(model: string, provider: string, latencyMs: number, opts?: EmbeddingOpts): string;
  trackSpan(spanName: string, latencyMs: number, opts?: SpanOpts): string;
  score(name: string, value: number, targetId: string, opts?: ScoreOpts): void;
}
//#endregion
export { Session, SessionOptions, _resetRunSyncWarning };
//# sourceMappingURL=session.d.ts.map