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

Function toggleAgent

app/src/web/App.tsx:450–528  ·  view source on GitHub ↗
(id: string, isCurrentlyRunning: boolean)

Source from the content-addressed store, hash-verified

448 };
449
450 const toggleAgent = async (id: string, isCurrentlyRunning: boolean): Promise<void> => {
451 if (isUsingObServer && !isAuthenticated) {
452 Logger.info('AUTH', 'User attempted to use a protected feature while logged out. Redirecting to login.');
453 login();
454 return;
455 }
456
457 try {
458 setError(null);
459 const agent = agents.find(a => a.id === id);
460
461 if (!agent) {
462 throw new Error(`Agent ${id} not found`);
463 }
464 const isStartingUp = startingAgents.has(id);
465
466 if (isStartingUp || isCurrentlyRunning) {
467 Logger.info(id, `Stopping agent "${agent.name}"`);
468 stopAgentLoop(id);
469 if (isStartingUp) {
470 setStartingAgents(prev => {
471 const updated = new Set(prev);
472 updated.delete(id);
473 return updated;
474 });
475 }
476 } else {
477 Logger.info(id, `Starting agent "${agent.name}"`);
478 setStartingAgents(prev => {
479 const updated = new Set(prev);
480 updated.add(id);
481 return updated;
482 });
483
484 try {
485 await startAgentLoop(id, getToken);
486 } catch (err: any) {
487 if (err.whitelistCheck) {
488 const { phoneNumbers, channel } = err.whitelistCheck;
489
490 setWhitelistModalInfo({
491 phoneNumbers,
492 agentId: id,
493 channel,
494 onStartAgent: () => {
495 setWhitelistModalInfo(null);
496 toggleAgent(id, false);
497 }
498 });
499 setStartingAgents(prev => {
500 const updated = new Set(prev);
501 updated.delete(id);
502 return updated;
503 });
504 return;
505 }
506 throw err;
507 } finally {

Callers

nothing calls this directly

Calls 7

stopAgentLoopFunction · 0.90
startAgentLoopFunction · 0.90
loginFunction · 0.85
fetchAgentsFunction · 0.85
infoMethod · 0.80
deleteMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected