MCPcopy Create free account
hub / github.com/Roy3838/Observer / stopAgentLoop

Function stopAgentLoop

app/src/utils/main_loop.ts:209–255  ·  view source on GitHub ↗
(agentId: string)

Source from the content-addressed store, hash-verified

207}
208
209export async function stopAgentLoop(agentId: string): Promise<void> {
210 const loop = activeLoops[agentId];
211 if (loop?.isRunning) {
212 if (loop.intervalId !== null) window.clearInterval(loop.intervalId);
213
214 // Clear any active sleep state
215 wakeAgentLoop(agentId);
216
217 // --- SUBSCRIBER CLEANUP ---
218 // Destroy all transcription subscribers for this agent
219 StreamManager.destroySubscribersForAgent(agentId);
220
221 // --- STREAM MANAGEMENT ---
222 // Tell the StreamManager this agent no longer needs these streams.
223 // The manager will handle stopping the hardware if it's the last user.
224 Logger.debug(agentId, "Releasing all potential streams for stopping agent.");
225
226 StreamManager.releaseStreamsForAgent(agentId);
227
228 // Clear change detection data
229 clearAgentChangeData(agentId);
230 resetNoulTrend(agentId);
231
232 // Note: Agent crop configurations are preserved across stop/start cycles
233
234
235 // End the current session and save to IndexedDB
236 await IterationStore.endSession(agentId);
237
238 // -------------------------
239
240 activeLoops[agentId] = { ...loop, isRunning: false, intervalId: null, sleepUntil: null };
241
242 if (getRunningAgentIds().length === 0) {
243 // This was the last running agent, so shut down the recorder.
244 recordingManager.forceStop();
245 }
246
247 // Logger dispatches the window event automatically
248 Logger.info(agentId, 'Agent stopped', {
249 logType: 'agent-status-changed',
250 content: { agentId, status: 'stopped' }
251 });
252 } else {
253 Logger.warn(agentId, `Attempted to stop agent that wasn't running`);
254 }
255}
256
257/**
258 * Execute a single iteration of the agent's loop

Callers 8

handleCommandMethod · 0.90
executeJavaScriptFunction · 0.90
createApiFunction · 0.90
registry.tsFile · 0.90
handleDeleteClickFunction · 0.90
toggleAgentFunction · 0.90
executeIterationFunction · 0.85
executeAgentIterationFunction · 0.85

Calls 11

clearAgentChangeDataFunction · 0.90
resetNoulTrendFunction · 0.90
wakeAgentLoopFunction · 0.85
getRunningAgentIdsFunction · 0.85
endSessionMethod · 0.80
forceStopMethod · 0.80
infoMethod · 0.80
warnMethod · 0.80
debugMethod · 0.45

Tested by

no test coverage detected