Fix bridge lint blockers
This commit is contained in:
parent
cce9833689
commit
dfead14145
@ -5,14 +5,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveSingleAgentForwardEndpointFromExampleConfig(t *testing.T) {
|
func TestResolveSingleAgentForwardEndpointFromExampleConfig(t *testing.T) {
|
||||||
// Set the config path to example/config.yaml relative to this test file
|
// Set the config path to example/config.yaml relative to this test file
|
||||||
os.Setenv("BRIDGE_CONFIG_PATH", "../../example/config.yaml")
|
t.Setenv("BRIDGE_CONFIG_PATH", "../../example/config.yaml")
|
||||||
defer os.Unsetenv("BRIDGE_CONFIG_PATH")
|
|
||||||
|
|
||||||
_, catalog, order := newProductionProviderCatalog()
|
_, catalog, order := newProductionProviderCatalog()
|
||||||
if len(order) == 0 {
|
if len(order) == 0 {
|
||||||
|
|||||||
@ -395,7 +395,9 @@ func (c *externalACPCompat) callHTTPRPC(ctx context.Context, method string, para
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer func() {
|
||||||
|
_ = response.Body.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
body, _ := io.ReadAll(io.LimitReader(response.Body, 2048))
|
body, _ := io.ReadAll(io.LimitReader(response.Body, 2048))
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package acp
|
package acp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"xworkmate-bridge/internal/gatewayruntime"
|
"xworkmate-bridge/internal/gatewayruntime"
|
||||||
@ -15,28 +14,26 @@ type session struct {
|
|||||||
provider string // The Provider ID
|
provider string // The Provider ID
|
||||||
target string // The Execution Target ID
|
target string // The Execution Target ID
|
||||||
compat ProviderCompat
|
compat ProviderCompat
|
||||||
cancel context.CancelFunc
|
|
||||||
closed bool
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
history []string
|
history []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
config *BridgeConfig
|
config *BridgeConfig
|
||||||
sessions map[string]*session
|
sessions map[string]*session
|
||||||
|
|
||||||
// Core Control Plane Components
|
// Core Control Plane Components
|
||||||
routingEngine RoutingEngine
|
routingEngine RoutingEngine
|
||||||
providers map[string]ProviderCompat
|
providers map[string]ProviderCompat
|
||||||
catalog *CapabilityCatalog
|
catalog *CapabilityCatalog
|
||||||
orchestrator *SessionOrchestrator
|
orchestrator *SessionOrchestrator
|
||||||
memoryService memory.Service
|
memoryService memory.Service
|
||||||
|
|
||||||
providerOrder []string
|
providerOrder []string
|
||||||
gateway *gatewayruntime.Manager
|
gateway *gatewayruntime.Manager
|
||||||
|
|
||||||
// Legacy / Common
|
// Legacy / Common
|
||||||
authService interface{} // Minimal auth dependency
|
authService interface{} // Minimal auth dependency
|
||||||
allowedOrigins []string
|
allowedOrigins []string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -252,23 +252,3 @@ func isTimeoutError(err error) bool {
|
|||||||
}
|
}
|
||||||
return strings.Contains(strings.ToLower(err.Error()), "timeout")
|
return strings.Contains(strings.ToLower(err.Error()), "timeout")
|
||||||
}
|
}
|
||||||
|
|
||||||
func isHermesFinalSessionUpdate(notification map[string]any) bool {
|
|
||||||
if notification == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
method := strings.TrimSpace(fmt.Sprint(notification["method"]))
|
|
||||||
if method != "session.update" && method != "session/update" && method != "acp.session.update" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
params, _ := notification["params"].(map[string]any)
|
|
||||||
if len(params) == 0 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
update, _ := params["update"].(map[string]any)
|
|
||||||
if len(update) == 0 {
|
|
||||||
update = params
|
|
||||||
}
|
|
||||||
sessionUpdate := strings.TrimSpace(fmt.Sprint(update["sessionUpdate"]))
|
|
||||||
return sessionUpdate == "agent_message_text"
|
|
||||||
}
|
|
||||||
|
|||||||
@ -70,8 +70,7 @@ func TestHandleCapabilitiesSynthesizesProviderResponse(t *testing.T) {
|
|||||||
func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
|
func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
|
||||||
isolateHermesConfig(t)
|
isolateHermesConfig(t)
|
||||||
|
|
||||||
var stub *stubClient
|
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
||||||
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
|
||||||
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
||||||
switch method {
|
switch method {
|
||||||
case "session/new":
|
case "session/new":
|
||||||
@ -138,8 +137,7 @@ func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
|
|||||||
func TestHandleRPCSessionStartRejectsEmptyUpstreamResponse(t *testing.T) {
|
func TestHandleRPCSessionStartRejectsEmptyUpstreamResponse(t *testing.T) {
|
||||||
isolateHermesConfig(t)
|
isolateHermesConfig(t)
|
||||||
|
|
||||||
var stub *stubClient
|
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
||||||
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
|
||||||
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
||||||
switch method {
|
switch method {
|
||||||
case "session/new":
|
case "session/new":
|
||||||
@ -200,8 +198,7 @@ func TestNewServerDefaultsHermesToSessionPrompt(t *testing.T) {
|
|||||||
func TestHandleRPCSessionMessageReusesUpstreamSession(t *testing.T) {
|
func TestHandleRPCSessionMessageReusesUpstreamSession(t *testing.T) {
|
||||||
isolateHermesConfig(t)
|
isolateHermesConfig(t)
|
||||||
|
|
||||||
var stub *stubClient
|
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
||||||
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
|
||||||
promptCalls := 0
|
promptCalls := 0
|
||||||
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
||||||
switch method {
|
switch method {
|
||||||
@ -314,8 +311,7 @@ func TestHandleRPCSessionStartUsesConfiguredHermesModelBeforePrompt(t *testing.T
|
|||||||
t.Setenv("HOME", home)
|
t.Setenv("HOME", home)
|
||||||
t.Setenv("HERMES_HOME", "")
|
t.Setenv("HERMES_HOME", "")
|
||||||
|
|
||||||
var stub *stubClient
|
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
||||||
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
|
|
||||||
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
|
||||||
switch method {
|
switch method {
|
||||||
case "session/new":
|
case "session/new":
|
||||||
|
|||||||
@ -45,7 +45,9 @@ func (c *opencodeHTTPClient) Initialize() (initializeResult, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return initializeResult{}, err
|
return initializeResult{}, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
|
||||||
return initializeResult{}, fmt.Errorf("opencode health failed (%d): %s", resp.StatusCode, strings.TrimSpace(string(body)))
|
return initializeResult{}, fmt.Errorf("opencode health failed (%d): %s", resp.StatusCode, strings.TrimSpace(string(body)))
|
||||||
@ -110,7 +112,9 @@ func (c *opencodeHTTPClient) CreateSession(title string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
raw, err := io.ReadAll(resp.Body)
|
raw, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -213,7 +217,9 @@ func (c *opencodeHTTPClient) postSessionMessage(sessionID, prompt string, params
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer func() {
|
||||||
|
_ = resp.Body.Close()
|
||||||
|
}()
|
||||||
raw, err := io.ReadAll(resp.Body)
|
raw, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -213,7 +213,6 @@ func (s *Server) handleCapabilities() map[string]any {
|
|||||||
|
|
||||||
type opencodeSessionState struct {
|
type opencodeSessionState struct {
|
||||||
upstreamSessionID string
|
upstreamSessionID string
|
||||||
title string
|
|
||||||
lastOutput string
|
lastOutput string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
main.go
11
main.go
@ -12,9 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
buildCommit = ""
|
buildCommit = ""
|
||||||
buildVersion = "v1.1.0"
|
buildVersion = "v1.1.0"
|
||||||
buildDate = ""
|
buildDate = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -37,7 +37,10 @@ func main() {
|
|||||||
case "stdio":
|
case "stdio":
|
||||||
acp.RunStdio(os.Stdin, os.Stdout)
|
acp.RunStdio(os.Stdin, os.Stdout)
|
||||||
case "version", "-v", "--version":
|
case "version", "-v", "--version":
|
||||||
printBridgeVersionInfo()
|
if err := printBridgeVersionInfo(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
// Backward compatibility for old subcommands (optional, but we said no backward compatibility)
|
// Backward compatibility for old subcommands (optional, but we said no backward compatibility)
|
||||||
// However, for the transition, we can be nice or just fail.
|
// However, for the transition, we can be nice or just fail.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user