Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
94 lines
2.5 KiB
Go
94 lines
2.5 KiB
Go
package agentruntime
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
type pendingInteractiveRequestState string
|
|
|
|
const (
|
|
pendingInteractiveRequestStatePending pendingInteractiveRequestState = "pending"
|
|
pendingInteractiveRequestStateResolving pendingInteractiveRequestState = "resolving"
|
|
pendingInteractiveRequestStateAnswered pendingInteractiveRequestState = "answered"
|
|
pendingInteractiveRequestStateSuperseded pendingInteractiveRequestState = "superseded"
|
|
pendingInteractiveRequestStateInterrupted pendingInteractiveRequestState = "interrupted"
|
|
)
|
|
|
|
var errAppServerServerRequestResolved = fmt.Errorf("codex app-server server request resolved out of band")
|
|
|
|
func appServerRequestIDParam(value any) string {
|
|
switch typed := value.(type) {
|
|
case string:
|
|
return strings.TrimSpace(typed)
|
|
case json.Number:
|
|
return strings.TrimSpace(typed.String())
|
|
case float64:
|
|
if typed == math.Trunc(typed) {
|
|
return strconv.FormatInt(int64(typed), 10)
|
|
}
|
|
return strings.TrimSpace(strconv.FormatFloat(typed, 'f', -1, 64))
|
|
case float32:
|
|
value := float64(typed)
|
|
if value == math.Trunc(value) {
|
|
return strconv.FormatInt(int64(value), 10)
|
|
}
|
|
return strings.TrimSpace(strconv.FormatFloat(value, 'f', -1, 32))
|
|
case int:
|
|
return strconv.Itoa(typed)
|
|
case int64:
|
|
return strconv.FormatInt(typed, 10)
|
|
case int32:
|
|
return strconv.FormatInt(int64(typed), 10)
|
|
case uint:
|
|
return strconv.FormatUint(uint64(typed), 10)
|
|
case uint64:
|
|
return strconv.FormatUint(typed, 10)
|
|
case uint32:
|
|
return strconv.FormatUint(uint64(typed), 10)
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func (a *CodexAppServerAdapter) resolvePendingRequestFromProvider(
|
|
agentSessionID string,
|
|
params map[string]any,
|
|
) bool {
|
|
if a == nil {
|
|
return false
|
|
}
|
|
requestID := appServerRequestIDParam(params["requestId"])
|
|
if requestID == "" {
|
|
return false
|
|
}
|
|
a.mu.Lock()
|
|
_, appSession := a.appServerSessionForAgentSessionIDLocked(agentSessionID)
|
|
var pending *pendingInteractiveRequest
|
|
if appSession != nil && appSession.pendingRequests != nil {
|
|
pending = appSession.pendingRequests[requestID]
|
|
}
|
|
if pending != nil && strings.TrimSpace(pending.agentSessionID) != strings.TrimSpace(agentSessionID) {
|
|
pending = nil
|
|
}
|
|
a.mu.Unlock()
|
|
if pending != nil && !pending.finish(pendingInteractiveRequestStateSuperseded) {
|
|
pending = nil
|
|
}
|
|
if pending == nil {
|
|
return false
|
|
}
|
|
select {
|
|
case pending.response <- pendingInteractiveResponse{
|
|
action: "resolved",
|
|
err: errAppServerServerRequestResolved,
|
|
outOfBandResolved: true,
|
|
}:
|
|
default:
|
|
}
|
|
return true
|
|
}
|