/** * @license * Copyright 2025 Vybestack LLC * SPDX-License-Identifier: Apache-2.0 */ /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001 * @pseudocode runtime-state.md lines 18-48 * * AgentRuntimeState abstraction to replace stateful Config usage. * This is a STUB implementation for Phase 03 (TDD preparation). * Actual implementation happens in Phase 05. */ /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.1 * @pseudocode runtime-state.md lines 18-48 * * Core runtime state interface representing provider/model/auth configuration. */ export interface AgentRuntimeState { readonly runtimeId: string; readonly provider: string; readonly model: string; readonly baseUrl?: string; readonly proxyUrl?: string; readonly modelParams?: ModelParams; readonly sessionId: string; readonly updatedAt: number; } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.1 * * Model parameters for generation configuration. */ export interface ModelParams { temperature?: number; topP?: number; maxTokens?: number; [key: string]: unknown; } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.1 * @pseudocode runtime-state.md lines 73-105 * * Parameters for creating a new runtime state instance. */ export interface RuntimeStateParams { runtimeId: string; provider: string; model: string; baseUrl?: string; proxyUrl?: string; modelParams?: ModelParams; sessionId?: string; } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.3 * @pseudocode runtime-state.md lines 329-355 * * Serializable snapshot of runtime state for diagnostics. */ export interface RuntimeStateSnapshot { runtimeId: string; provider: string; model: string; baseUrl?: string; proxyUrl?: string; modelParams?: ModelParams; sessionId: string; updatedAt: number; version: number; } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.2 * @pseudocode runtime-state.md lines 209-243 * * Event payload emitted when runtime state changes. */ export interface RuntimeStateChangedEvent { runtimeId: string; changes: Record; snapshot: RuntimeStateSnapshot; timestamp: number; } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-003.2 * @pseudocode runtime-state.md lines 289-318 * * Callback for runtime state change events. */ export type RuntimeStateChangeCallback = (event: RuntimeStateChangedEvent) => void; /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-003.2 * * Function to unsubscribe from runtime state changes. */ export type UnsubscribeFunction = () => void; /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.1 * @pseudocode runtime-state.md lines 366-381 * * Error codes for runtime state validation failures. */ export declare enum RuntimeStateErrorCode { RUNTIME_ID_MISSING = "runtimeId.missing", PROVIDER_MISSING = "provider.missing", PROVIDER_INVALID = "provider.invalid", MODEL_MISSING = "model.missing", MODEL_INVALID = "model.invalid", BASE_URL_INVALID = "baseUrl.invalid", UPDATE_UNSUPPORTED = "update.unsupported", NOT_IMPLEMENTED = "not.implemented" } /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-001.1 * @pseudocode runtime-state.md lines 366-381 * * Error thrown during runtime state validation or update. */ export declare class RuntimeStateError extends Error { readonly code: RuntimeStateErrorCode; readonly details?: Record | undefined; constructor(code: RuntimeStateErrorCode, details?: Record | undefined); } /** * @plan PLAN-20251027-STATELESS5.P05 * @requirement REQ-STAT5-001.1 * @pseudocode runtime-state.md lines 73-105 * * Creates a new immutable runtime state instance. * Validates all required fields and auth consistency. */ export declare function createAgentRuntimeState(params: RuntimeStateParams): AgentRuntimeState; /** * @plan PLAN-20251027-STATELESS5.P05 * @requirement REQ-STAT5-001.2 * @pseudocode runtime-state.md lines 209-243 * * Updates runtime state immutably, returning a new instance. * Validates updates and emits synchronous change events. */ export declare function updateAgentRuntimeState(oldState: AgentRuntimeState, updates: Partial): AgentRuntimeState; /** * @plan PLAN-20251027-STATELESS5.P05 * @requirement REQ-STAT5-002.3 * @pseudocode runtime-state.md lines 252-278 * * Batch update for atomic multi-field changes (e.g., provider switch). * All updates validated together, single event emitted. */ export declare function updateAgentRuntimeStateBatch(oldState: AgentRuntimeState, updates: Partial): AgentRuntimeState; /** * @plan PLAN-20251027-STATELESS5.P05 * @requirement REQ-STAT5-001.3 * @pseudocode runtime-state.md lines 329-355 * * Returns a frozen snapshot of runtime state for diagnostics. * Sanitizes sensitive auth data. */ export declare function getAgentRuntimeStateSnapshot(state: AgentRuntimeState): RuntimeStateSnapshot; /** * @plan PLAN-20251027-STATELESS5.P05 * @requirement REQ-STAT5-003.2 * @pseudocode runtime-state.md lines 289-318 * * Subscribes to runtime state change events. * Returns unsubscribe function to remove callback. */ export declare function subscribeToAgentRuntimeState(runtimeId: string, callback: RuntimeStateChangeCallback, options?: { async: boolean; }): UnsubscribeFunction; /** * @plan PLAN-20251027-STATELESS5.P03 * @requirement REQ-STAT5-003.1 * @pseudocode runtime-state.md lines 150-173 * * Synchronous accessors for runtime state fields. * STUB: Minimal implementations for type safety. */ export declare function getProvider(state: AgentRuntimeState): string; export declare function getModel(state: AgentRuntimeState): string; export declare function getBaseUrl(state: AgentRuntimeState): string | undefined; export declare function getSessionId(state: AgentRuntimeState): string; export declare function getModelParams(state: AgentRuntimeState): Readonly | undefined;