MCPcopy Create free account
hub / github.com/Noumena-Network/code / handleShutdownApproval

Function handleShutdownApproval

src/tools/SendMessageTool/SendMessageTool.ts:351–445  ·  view source on GitHub ↗
(
  requestId: string,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

349}
350
351async function handleShutdownApproval(
352 requestId: string,
353 context: ToolUseContext,
354): Promise<{ data: ResponseOutput }> {
355 const teamName = getTeamName()
356 const agentId = getAgentId()
357 const agentName = getAgentName() || 'teammate'
358
359 logForDebugging(
360 `[SendMessageTool] handleShutdownApproval: teamName=${teamName}, agentId=${agentId}, agentName=${agentName}`,
361 )
362
363 let ownPaneId: string | undefined
364 let ownBackendType: BackendType | undefined
365 if (teamName) {
366 const teamFile = await readTeamFileAsync(teamName)
367 if (teamFile && agentId) {
368 const selfMember = teamFile.members.find(m => m.agentId === agentId)
369 if (selfMember) {
370 ownPaneId = selfMember.tmuxPaneId
371 ownBackendType = selfMember.backendType
372 }
373 }
374 }
375
376 const approvedMessage = createShutdownApprovedMessage({
377 requestId,
378 from: agentName,
379 paneId: ownPaneId,
380 backendType: ownBackendType,
381 })
382
383 await writeToMailbox(
384 TEAM_LEAD_NAME,
385 {
386 from: agentName,
387 text: jsonStringify(approvedMessage),
388 timestamp: new Date().toISOString(),
389 color: getTeammateColor(),
390 },
391 teamName,
392 )
393
394 if (ownBackendType === 'in-process') {
395 logForDebugging(
396 `[SendMessageTool] In-process teammate ${agentName} approving shutdown - signaling abort`,
397 )
398
399 if (agentId) {
400 const appState = context.getAppState()
401 const task = findTeammateTaskByAgentId(agentId, appState.tasks)
402 if (task?.abortController) {
403 task.abortController.abort()
404 logForDebugging(
405 `[SendMessageTool] Aborted controller for in-process teammate ${agentName}`,
406 )
407 } else {
408 logForDebugging(

Callers 1

callFunction · 0.85

Calls 11

getTeamNameFunction · 0.85
getAgentIdFunction · 0.85
getAgentNameFunction · 0.85
readTeamFileAsyncFunction · 0.85
writeToMailboxFunction · 0.85
jsonStringifyFunction · 0.85
gracefulShutdownFunction · 0.85
logForDebuggingFunction · 0.70
getTeammateColorFunction · 0.50

Tested by

no test coverage detected