| 12 | }; |
| 13 | |
| 14 | class ProgressStore { |
| 15 | private executions = new Map<string, ProgressExecution>(); |
| 16 | private inputHashToExecutionId = new Map<string, string>(); |
| 17 | |
| 18 | create(id: string, inputHash?: string): void { |
| 19 | this.executions.set(id, { |
| 20 | id, |
| 21 | messages: [], |
| 22 | completed: false, |
| 23 | subscribers: new Set(), |
| 24 | }); |
| 25 | |
| 26 | // Store input hash mapping if provided |
| 27 | if (inputHash) { |
| 28 | this.inputHashToExecutionId.set(inputHash, id); |
| 29 | } |
| 30 | |
| 31 | // Clean up after 5 minutes |
| 32 | setTimeout(() => { |
| 33 | this.executions.delete(id); |
| 34 | if (inputHash) { |
| 35 | this.inputHashToExecutionId.delete(inputHash); |
| 36 | } |
| 37 | }, 5 * 60 * 1000); |
| 38 | } |
| 39 | |
| 40 | getExecutionIdByInputHash(inputHash: string): string | null { |
| 41 | return this.inputHashToExecutionId.get(inputHash) || null; |
| 42 | } |
| 43 | |
| 44 | update(id: string, message: string, type: "info" | "success" | "error" = "info"): void { |
| 45 | const execution = this.executions.get(id); |
| 46 | if (!execution) { |
| 47 | console.warn(`No execution found for id: ${id}`); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | const lastMessage = execution.messages[execution.messages.length - 1]; |
| 52 | |
| 53 | if (lastMessage && lastMessage.message === message && lastMessage.type === type) { |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | const progressMessage: ProgressMessage = { |
| 58 | timestamp: new Date().toISOString(), |
| 59 | message, |
| 60 | type, |
| 61 | }; |
| 62 | |
| 63 | execution.messages.push(progressMessage); |
| 64 | |
| 65 | // Notify all subscribers |
| 66 | execution.subscribers.forEach((callback) => callback(progressMessage)); |
| 67 | } |
| 68 | |
| 69 | complete(id: string, success: boolean = true): void { |
| 70 | const execution = this.executions.get(id); |
| 71 | if (!execution) { |
nothing calls this directly
no outgoing calls
no test coverage detected