( targetName: string, teamName?: string, reason?: string, )
| 829 | * @returns The request ID and target name |
| 830 | */ |
| 831 | export async function sendShutdownRequestToMailbox( |
| 832 | targetName: string, |
| 833 | teamName?: string, |
| 834 | reason?: string, |
| 835 | ): Promise<{ requestId: string; target: string }> { |
| 836 | const resolvedTeamName = teamName || getTeamName() |
| 837 | |
| 838 | // Get sender name (supports in-process teammates via AsyncLocalStorage) |
| 839 | const senderName = getAgentName() || TEAM_LEAD_NAME |
| 840 | |
| 841 | // Generate a deterministic request ID for this shutdown request |
| 842 | const requestId = generateRequestId('shutdown', targetName) |
| 843 | |
| 844 | // Create and send the shutdown request message |
| 845 | const shutdownMessage = createShutdownRequestMessage({ |
| 846 | requestId, |
| 847 | from: senderName, |
| 848 | reason, |
| 849 | }) |
| 850 | |
| 851 | await writeToMailbox( |
| 852 | targetName, |
| 853 | { |
| 854 | from: senderName, |
| 855 | text: jsonStringify(shutdownMessage), |
| 856 | timestamp: new Date().toISOString(), |
| 857 | color: getTeammateColor(), |
| 858 | }, |
| 859 | resolvedTeamName, |
| 860 | ) |
| 861 | |
| 862 | return { requestId, target: targetName } |
| 863 | } |
| 864 | |
| 865 | /** |
| 866 | * Checks if a message text contains a shutdown request |
no test coverage detected