Files
Local-Cursor/internal/backend/forwarder/interrupt.go
FuDie0915 db73cf5a39 chore: import Local-Cursor v1.1.8 source snapshot
Includes the current working directory changes. Historical commits and release binaries are excluded to limit Gitea storage.
Source base: d7515973fbfd6dd2001fa156c483455b8081c7cb
2026-11-10 01:24:28 +08:00

43 lines
1.0 KiB
Go

package forwarder
import (
"context"
"errors"
"strings"
)
var errProviderLoopInterrupted = errors.New("provider loop interrupted")
func isTerminalStreamStatus(status StreamStatus) bool {
switch status {
case StreamStatusCanceled, StreamStatusCompleted, StreamStatusFailed:
return true
default:
return false
}
}
func providerLoopInterruptErr(ctx context.Context, stream *ActiveStream, modelCallID string) error {
if ctx != nil && ctx.Err() != nil {
return errProviderLoopInterrupted
}
if stream == nil {
return nil
}
stream.mu.Lock()
defer stream.mu.Unlock()
if isTerminalStreamStatus(stream.Status) {
return errProviderLoopInterrupted
}
switch stream.Phase {
case TurnPhaseCanceled, TurnPhaseCompleted, TurnPhaseFailed:
return errProviderLoopInterrupted
}
expectedModelCallID := strings.TrimSpace(modelCallID)
currentModelCallID := strings.TrimSpace(stream.CurrentModelCallID)
if expectedModelCallID != "" && currentModelCallID != "" && currentModelCallID != expectedModelCallID {
return errProviderLoopInterrupted
}
return nil
}