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; /** * Maximum time (ms) `run()` waits for the automatic flush before resolving. * Defaults to the `AIConfig.flushTimeoutMs` of the owning `AmplitudeAI` * (3000 ms unless configured). The flush continues in the background after * the timeout. */ flushTimeoutMs?: number; /** * 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 flushTimeoutMs: number | null; 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(fn: (session: Session) => T | Promise): Promise; /** * 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(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(childAgent: BoundAgent, fn: (session: Session) => T | Promise): Promise; /** * Synchronous version of {@link runAs}. */ runAsSync(childAgent: BoundAgent, fn: (session: Session) => T): T; private _autoEnd; private _effectiveFlushTimeoutMs; private _flush; private _awaitWithTimeout; private _inject; trackUserMessage(content: string, opts?: UserMessageOpts): string; trackAiMessage(content: string, model: string, provider: string, latencyMs: number, opts?: AiMessageOpts): string; trackRunCost(totalCostUsd: number, inputTokens: number, outputTokens: number, model: string, provider: string, opts?: Parameters[5]): 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