MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / enqueueAndAwait

Function enqueueAndAwait

internal/bridge/commands.go:111–139  ·  view source on GitHub ↗

enqueueAndAwait builds a PendingAction, enqueues it, binds it to the task, and waits for the result. Returns nil if any step fails.

(ctx ModuleContext, sessionID string, taskID uint32, sess *sessions.Session, toolName, command string)

Source from the content-addressed store, hash-verified

109// enqueueAndAwait builds a PendingAction, enqueues it, binds it to the task,
110// and waits for the result. Returns nil if any step fails.
111func enqueueAndAwait(ctx ModuleContext, sessionID string, taskID uint32, sess *sessions.Session, toolName, command string) *sessions.CommandResult {
112 args := sessions.BuildCommandArguments(sess, toolName, command)
113 cmdID := sessions.GenerateCommandID()
114 action := &sessions.PendingAction{
115 ID: cmdID,
116 TaskID: taskID,
117 Type: sessions.ActionToolCall,
118 ToolName: toolName,
119 Arguments: args,
120 CreatedAt: time.Now(),
121 }
122 if !sessions.Global().EnqueueAction(sessionID, action) {
123 ctx.Tasks.Fail(sessionID, taskID, "enqueue failed")
124 return nil
125 }
126 ctx.Tasks.BindCommand(sessionID, taskID, cmdID)
127
128 ch := ctx.Tasks.AwaitResult(sessionID, taskID)
129 if ch == nil {
130 ctx.Tasks.Fail(sessionID, taskID, "await failed")
131 return nil
132 }
133 result, ok := awaitTaskResult(ch, taskID)
134 if !ok {
135 ctx.Tasks.Fail(sessionID, taskID, "channel closed")
136 return nil
137 }
138 return result
139}
140
141// enqueueToolAction builds a PendingAction, enqueues it, and binds to the task.
142// Returns the command ID and true on success, or ("", false) on failure.

Callers 2

HandleMethod · 0.85
HandleMethod · 0.85

Calls 8

BuildCommandArgumentsFunction · 0.92
GenerateCommandIDFunction · 0.92
GlobalFunction · 0.92
awaitTaskResultFunction · 0.85
EnqueueActionMethod · 0.80
FailMethod · 0.80
BindCommandMethod · 0.80
AwaitResultMethod · 0.80

Tested by

no test coverage detected