MCPcopy Create free account
hub / github.com/compozy/agh / agentChannelReplySendRequest

Function agentChannelReplySendRequest

internal/api/core/agent_channels.go:283–316  ·  view source on GitHub ↗
(
	caller agentidentity.Caller,
	source network.Envelope,
	req decodedAgentChannelReplyRequest,
	ext map[string]json.RawMessage,
)

Source from the content-addressed store, hash-verified

281}
282
283func agentChannelReplySendRequest(
284 caller agentidentity.Caller,
285 source network.Envelope,
286 req decodedAgentChannelReplyRequest,
287 ext map[string]json.RawMessage,
288) (network.SendRequest, error) {
289 callerPeerID := agentCallerPeerID(caller)
290 workspaceID := strings.TrimSpace(caller.Session.WorkspaceID)
291 sourceChannel := strings.TrimSpace(source.Channel)
292 targetPeerID := strings.TrimSpace(source.From)
293 directID, _, _, err := network.DirectRoomIdentity(workspaceID, sourceChannel, callerPeerID, targetPeerID)
294 if err != nil {
295 return network.SendRequest{}, err
296 }
297 sendReq := network.SendRequest{
298 SessionID: strings.TrimSpace(caller.Session.ID),
299 WorkspaceID: workspaceID,
300 Channel: sourceChannel,
301 Surface: new(network.SurfaceDirect),
302 DirectID: ptrString(directID),
303 Kind: network.KindSay,
304 To: ptrString(targetPeerID),
305 ReplyTo: ptrString(req.ReplyToMessageID),
306 Body: cloneRawMessage(req.Body),
307 Ext: ext,
308 }
309 if source.WorkID != nil && strings.TrimSpace(*source.WorkID) != "" {
310 sendReq.WorkID = ptrString(*source.WorkID)
311 }
312 if source.TraceID != nil && strings.TrimSpace(*source.TraceID) != "" {
313 sendReq.TraceID = ptrString(*source.TraceID)
314 }
315 return sendReq, nil
316}
317
318func agentCallerPeerID(caller agentidentity.Caller) string {
319 agentName := strings.ToLower(strings.TrimSpace(caller.Session.AgentName))

Callers 1

AgentChannelReplyMethod · 0.85

Calls 4

DirectRoomIdentityFunction · 0.92
agentCallerPeerIDFunction · 0.85
ptrStringFunction · 0.70
cloneRawMessageFunction · 0.70

Tested by

no test coverage detected