| 72 | } |
| 73 | |
| 74 | const stop = (outcome: SendMessageTimerOutcome) => { |
| 75 | if (!timerActive || timerStartedAt == null || !timerMessageId) { |
| 76 | return null |
| 77 | } |
| 78 | timerActive = false |
| 79 | mainAgentTimer.stop() |
| 80 | const finishedAt = now() |
| 81 | const elapsedMs = Math.max(0, finishedAt - timerStartedAt) |
| 82 | const stopEvent: SendMessageTimerEvent = { |
| 83 | type: 'stop', |
| 84 | startedAt: timerStartedAt, |
| 85 | finishedAt, |
| 86 | elapsedMs, |
| 87 | messageId: timerMessageId, |
| 88 | outcome, |
| 89 | } |
| 90 | if (agentId) { |
| 91 | stopEvent.agentId = agentId |
| 92 | } |
| 93 | onTimerEvent(stopEvent) |
| 94 | timerStartedAt = null |
| 95 | timerMessageId = null |
| 96 | return { finishedAt, elapsedMs } |
| 97 | } |
| 98 | |
| 99 | const pause = () => { |
| 100 | mainAgentTimer.pause() |