@mondaydotcomorg/atp-runtime
Version:
Runtime SDK injected into sandbox for Agent Tool Protocol
122 lines • 4.14 kB
TypeScript
/**
* Execution-scoped state
*/
interface APICallRecord {
type: string;
operation: string;
payload: unknown;
result: unknown;
timestamp: number;
sequenceNumber: number;
}
/**
* Sets the current execution ID for this call
* Called by executor before each runtime API invocation
*/
export declare function setCurrentExecutionId(executionId: string): void;
/**
* Clears the current execution ID after a call
* Called by executor after each runtime API invocation
*/
export declare function clearCurrentExecutionId(): void;
/**
* Initialize execution state with correct values at execution start
* This must be called before any state access to ensure correct pause mode
*/
export declare function initializeExecutionState(shouldPause: boolean): void;
/**
* Runs a function within an execution context
* @param executionId - Unique ID for this execution
* @param fn - Function to run within the context
*/
export declare function runInExecutionContext<T>(executionId: string, fn: () => T): T;
/**
* Configures whether to pause execution for client services
* @param pause - If true, throws PauseExecutionError instead of calling callback
*/
export declare function setPauseForClient(pause: boolean): void;
/**
* Checks if should pause for client
*/
export declare function shouldPauseForClient(): boolean;
/**
* Sets up replay mode for resumption
* @param results - Map of sequence number to result for replaying callbacks
*/
export declare function setReplayMode(results: Map<number, unknown> | undefined): void;
/**
* Gets current call sequence number
*/
export declare function getCallSequenceNumber(): number;
/**
* Increments and returns the next sequence number
*/
export declare function nextSequenceNumber(): number;
/**
* Check if we have a cached result for the current sequence
*/
export declare function getCachedResult(sequenceNumber: number): unknown | undefined;
/**
* Check if we're in replay mode
*/
export declare function isReplayMode(): boolean;
/**
* Store an API call result during execution
* This is used to track server-side API calls so they can be cached on resume
*/
export declare function storeAPICallResult(record: {
type: string;
operation: string;
payload: unknown;
result: unknown;
timestamp: number;
sequenceNumber: number;
}): void;
/**
* Get all API call results tracked during this execution
* Used when building callback history on pause
*/
export declare function getAPICallResults(): APICallRecord[];
/**
* Clear API call results (used when execution completes or fails)
*/
export declare function clearAPICallResults(): void;
/**
* Set up API result cache for resume (operation-based, not sequence-based)
* This allows API calls to find their cached results even if execution order changes
*/
export declare function setAPIResultCache(cache: Map<string, unknown> | undefined): void;
/**
* Get API result from cache by operation name
*/
export declare function getAPIResultFromCache(operation: string): unknown | undefined;
/**
* Store API result in cache by operation name (for initial execution)
*/
export declare function storeAPIResultInCache(operation: string, result: unknown): void;
/**
* Cleanup a specific execution's state
* This should be called when an execution completes, fails, or is no longer needed
*/
export declare function cleanupExecutionState(executionId: string): void;
/**
* Cleanup old execution states to prevent memory leaks
* Removes states older than the specified max age (default: 1 hour)
*/
export declare function cleanupOldExecutionStates(maxAgeMs?: number): number;
/**
* Reset ALL execution state - for testing purposes only
* WARNING: This will clear all execution states, breaking any in-flight executions
*/
export declare function resetAllExecutionState(): void;
/**
* Get execution state statistics - for monitoring/debugging
*/
export declare function getExecutionStateStats(): {
totalStates: number;
oldestStateAge: number | null;
newestStateAge: number | null;
executionIds: string[];
};
export {};
//# sourceMappingURL=replay.d.ts.map