Spaces:
Running
Running
| /** | |
| * Helper utilities for managing OpenAI Response IDs and their expiration | |
| */ | |
| /** | |
| * Check if an OpenAI response ID has expired. | |
| * OpenAI stores response objects for 30 days. We use a 29-day threshold | |
| * to provide a safety margin. | |
| * | |
| * @param timestamp ISO 8601 timestamp string when the response ID was created | |
| * @returns true if the response ID is expired or timestamp is missing | |
| */ | |
| export function isResponseIdExpired(timestamp: string | undefined): boolean { | |
| if (!timestamp) { | |
| // No timestamp means we can't verify age, treat as expired for safety | |
| return true; | |
| } | |
| try { | |
| const createdAt = new Date(timestamp); | |
| const now = new Date(); | |
| const daysSinceCreation = (now.getTime() - createdAt.getTime()) / (1000 * 60 * 60 * 24); | |
| // Use 29 days as threshold (1 day safety margin before OpenAI's 30-day limit) | |
| return daysSinceCreation > 29; | |
| } catch (error) { | |
| // Invalid timestamp format, treat as expired | |
| console.warn('Invalid response ID timestamp:', timestamp, error); | |
| return true; | |
| } | |
| } | |