MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createSendMessageTimerController

Function createSendMessageTimerController

cli/src/utils/send-message-timer.ts:41–110  ·  view source on GitHub ↗
(
  options: SendMessageTimerControllerOptions,
)

Source from the content-addressed store, hash-verified

39}
40
41export const createSendMessageTimerController = (
42 options: SendMessageTimerControllerOptions,
43): SendMessageTimerController => {
44 const {
45 mainAgentTimer,
46 onTimerEvent,
47 agentId,
48 now = () => Date.now(),
49 } = options
50
51 let timerStartedAt: number | null = null
52 let timerMessageId: string | null = null
53 let timerActive = false
54
55 const start = (messageId: string) => {
56 if (timerActive) {
57 return
58 }
59 timerActive = true
60 timerMessageId = messageId
61 timerStartedAt = now()
62 mainAgentTimer.start()
63 const startEvent: SendMessageTimerEvent = {
64 type: 'start',
65 startedAt: timerStartedAt,
66 messageId,
67 }
68 if (agentId) {
69 startEvent.agentId = agentId
70 }
71 onTimerEvent(startEvent)
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

Callers 3

useSendMessageFunction · 0.90
createControllerFunction · 0.90

Calls

no outgoing calls

Tested by 1

createControllerFunction · 0.72