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)
| 109 | // enqueueAndAwait builds a PendingAction, enqueues it, binds it to the task, |
| 110 | // and waits for the result. Returns nil if any step fails. |
| 111 | func 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. |
no test coverage detected