/** * Model-facing projections for cross-session monitoring tools. * * `session_events` reads are selected tail/forward and filtered in PostgreSQL; * this module is the independent final guard before JSON enters a manager * model's context. It measures the exact pretty-printed MCP text, trims fat * payload fields, and—only if still required—removes rows from the pagination * edge while preserving a usable cursor. It never manufactures an event or * advances across an event it did not return. */ import type { Rig, Session, SessionEvent, SessionEventCompactResult, SessionEventPayloadMode, SessionEventReadDirection, SessionEventReadMode, SessionMcpMonitoringSource, SessionQueueSnapshot } from "@opengeni/contracts"; export declare const SESSION_EVENT_MCP_MAX_BYTES: number; export declare const SESSION_EVENT_MCP_FIELD_MAX_CHARS = 4000; export declare const DEFAULT_SESSION_DETAIL_CHARS = 6000; export declare const SESSION_DETAIL_MCP_MAX_BYTES: number; export declare const RIG_DETAIL_MCP_MAX_BYTES: number; /** * Keep the single-result MCP response below the same pretty-JSON envelope as * event pages. The contracts projection bounds each value independently for * HTTP/SDK use; this second boundary accounts for the result identity, * failure/truncation metadata, and MCP's pretty-printing overhead. */ export declare function boundSessionEventCompactResult(result: SessionEventCompactResult, maxBytes?: number): SessionEventCompactResult; /** Recursively clamp fat leaves and collapse pathological containers. */ export declare function capPayloadValue(value: unknown, perFieldChars: number, depth?: number): unknown; export declare function capEventPayload(event: SessionEvent, perFieldChars: number): SessionEvent; export type SessionEventMcpPageInput = { events: readonly SessionEvent[]; mode: SessionEventReadMode; payloadMode: SessionEventPayloadMode; direction: SessionEventReadDirection; sourceHasMore: boolean; sourceTruncatedBy: "count" | "bytes" | null; after: number; before: number | null; maxBytes?: number | undefined; }; export type SessionEventMcpPage = { mode: SessionEventReadMode; payloadMode: SessionEventPayloadMode; direction: SessionEventReadDirection; events: SessionEvent[]; coveredSequence: { first: number; last: number; } | null; nextAfter: number | null; nextBefore: number | null; hasMore: boolean; truncated: boolean; truncation?: { reasons: Array<"source_count" | "source_bytes" | "model_payload" | "model_bytes">; omittedSide: "before" | "after"; resumeCursor: number | null; }; bytes: number; maxBytes: number; }; /** * Build the exact model-visible page. Returned `bytes` includes all metadata * and pretty-printing used by the MCP JSON adapter. */ export declare function boundSessionEventMcpPage(input: SessionEventMcpPageInput): SessionEventMcpPage; type SessionDetailFieldFact = { truncated: boolean; originalBytes: number | null; deliveredBytes: number; originalCount?: number; deliveredCount?: number; measurementBounded?: boolean; }; /** Compact management state; configuration is deliberately excluded, not truncated. */ export declare function boundSessionCompactDetailMcp(session: Session, monitoring: SessionMcpMonitoringSource, queue: SessionQueueSnapshot | null, maxBytes?: number): { id: string; projectId?: string; title: string | null; status: "cancelled" | "failed" | "idle" | "queued" | "recovering" | "requires_action" | "running" | "waiting_capacity"; titleTruncated?: boolean; parentSessionId?: string; activeTurnId?: string; lastSequence: number; goal?: { status: "active" | "completed" | "paused"; summary: string | null; summaryTruncated?: boolean; evidence?: string | null; evidenceTruncated?: true; pausedReason?: string | null; pausedReasonTruncated?: true; rationale?: string | null; rationaleTruncated?: true; }; progress?: { sequence: number; text: string | null; occurredAt: string; textTruncated?: boolean; }; pause?: { state: string; source?: { kind: "session" | "workspace"; sessionId?: string; displayName: string | null; displayNameTruncated?: boolean; reason?: string | null; reasonTruncated?: boolean; }; additionalBlockerCount?: number; }; wait?: { reason: string | null; until: string; reasonTruncated?: boolean; }; queue?: { queuedTurns: number; pendingInputs: number; stoppingPreviousAttempt?: boolean; }; stopping?: { attempts?: number; backgroundCommands?: number; }; updatedAt: string; }; /** Legacy bounded configuration projection for explicit `session_get detail=full`. */ export declare function boundSessionDetailMcp(session: Session, effectiveControl?: unknown, maxBytes?: number): { id: string; workspaceId: string; accountId: string; status: "cancelled" | "failed" | "idle" | "queued" | "recovering" | "requires_action" | "running" | "waiting_capacity"; title: string | null; titleSource: "agent" | "user" | null; initialMessage: string; instructions: string | null; resources: unknown; tools: unknown; metadata: unknown; model: string; sandboxBackend: string; sandboxOs: "linux" | "macos" | "windows"; sandboxGroupId: string; activeSandboxId: string | null; activeEpoch: number; variableSetIds: string[]; variableSetId: string | null; environmentId: string | null; rigId: string | null; rigVersionId: string | null; firstPartyMcpPermissions: unknown; effectiveToolPolicy: unknown; mcpServers: unknown; parentSessionId: string | null; createIdempotencyKey: string | null; temporalWorkflowId: string | null; activeTurnId: string | null; lastInputTokens: number | null; queueVersion: number; queueHeadPosition: number; queueTailPosition: number; effectiveControl: unknown; lastSequence: number; codexPinnedCredentialId: string | null; codexLastCredentialId: string | null; codexCompactionMode: "portable" | "remote_v2"; pinned: boolean; pinnedAt: string | null; pinVersion: number; treeStats?: { directChildren: number; totalDescendants: number; runningDescendants: number; queuedDescendants: number; waitingDescendants?: number | undefined; attentionDescendants: number; pausedDescendants: number; failedDescendants: number; unreadDescendants?: number | undefined; unreadFailedDescendants?: number | undefined; activelyWorkingDescendants?: number | undefined; attentionSince?: string | null | undefined; truncated: boolean; }; createdAt: string; updatedAt: string; projection: { truncated: boolean; fields: Record; details: string[]; bytes: number; maxBytes: number; }; }; /** @deprecated use boundSessionDetailMcp for the actual MCP response. */ export declare function capSessionDetail(session: T, perFieldChars?: number): T; /** Bounded current definition plus compact-by-query historical rig summaries. */ export declare function boundRigDetailMcp(rig: Rig, versionsPage: { versions: unknown[]; total: number; hasMore: boolean; }, changesPage: { changes: unknown[]; total: number; hasMore: boolean; }, maxBytes?: number): { rig: { id: string; accountId: string; workspaceId: string; name: string; description: string | null; createdBy: string | null; activeVersion: { id: string; rigId: string; version: number; image: string | null; setupScript: string | null; checks: unknown; credentialHooks: unknown; defaultVariableSetIds: unknown; changelog: string | null; createdBy: string | null; active: boolean; createdAt: string; } | null; activeVersionHealth: { checkHealth: "failing" | "passing" | "unknown"; lastVerifiedAt: string | null; } | null; versionCount: number; createdAt: string; updatedAt: string; }; versions: unknown; versionsTotal: number; versionsTruncated: boolean; changes: unknown; changesTotal: number; changesTruncated: boolean; projection: { truncated: boolean; fields: Record; details: string[]; bytes: number; maxBytes: number; }; }; export {};