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

Function handleBroadcast

src/tools/SendMessageTool/SendMessageTool.ts:237–312  ·  view source on GitHub ↗
(
  content: string,
  summary: string | undefined,
  context: ToolUseContext,
)

Source from the content-addressed store, hash-verified

235}
236
237async function handleBroadcast(
238 content: string,
239 summary: string | undefined,
240 context: ToolUseContext,
241): Promise<{ data: BroadcastOutput }> {
242 const appState = context.getAppState()
243 const teamName = getTeamName(appState.teamContext)
244
245 if (!teamName) {
246 throw new Error(
247 'Not in a team context. Create a team with Teammate spawnTeam first, or set CLAUDE_CODE_TEAM_NAME.',
248 )
249 }
250
251 const teamFile = await readTeamFileAsync(teamName)
252 if (!teamFile) {
253 throw new Error(`Team "${teamName}" does not exist`)
254 }
255
256 const senderName =
257 getAgentName() || (isTeammate() ? 'teammate' : TEAM_LEAD_NAME)
258 if (!senderName) {
259 throw new Error(
260 'Cannot broadcast: sender name is required. Set CLAUDE_CODE_AGENT_NAME.',
261 )
262 }
263
264 const senderColor = getTeammateColor()
265
266 const recipients: string[] = []
267 for (const member of teamFile.members) {
268 if (member.name.toLowerCase() === senderName.toLowerCase()) {
269 continue
270 }
271 recipients.push(member.name)
272 }
273
274 if (recipients.length === 0) {
275 return {
276 data: {
277 success: true,
278 message: 'No teammates to broadcast to (you are the only team member)',
279 recipients: [],
280 },
281 }
282 }
283
284 for (const recipientName of recipients) {
285 await writeToMailbox(
286 recipientName,
287 {
288 from: senderName,
289 text: content,
290 summary,
291 timestamp: new Date().toISOString(),
292 color: senderColor,
293 },
294 teamName,

Callers 1

callFunction · 0.85

Calls 6

getTeamNameFunction · 0.85
readTeamFileAsyncFunction · 0.85
getAgentNameFunction · 0.85
isTeammateFunction · 0.85
writeToMailboxFunction · 0.85
getTeammateColorFunction · 0.50

Tested by

no test coverage detected