refactor: route TransportFor by provider name (#25650)

Delegate `aibridge` routing responsibility to the in-memory transport
layer.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Danny Kopping
2026-05-25 18:04:12 +02:00
committed by GitHub
parent 0a45f96d30
commit 8652ef3e3b
5 changed files with 101 additions and 32 deletions
+8 -4
View File
@@ -3,8 +3,6 @@ package aibridge
import (
"context"
"net/http"
"github.com/google/uuid"
)
// Source identifies the call site that asked aibridge for a transport. It is
@@ -53,14 +51,20 @@ func DelegatedAPIKeyIDFromContext(ctx context.Context) (string, bool) {
}
// TransportFactory returns an [http.RoundTripper] that dispatches an aibridge
// request in-process for a given ai_providers row.
// request in-process for a given provider instance name.
//
// Implementations live in coderd/aibridged. coderd registers an in-process
// factory on coderd.API.AIBridgeTransportFactory at startup so callers route
// traffic through the daemon without going through the gated HTTP route.
//
// The returned RoundTripper is responsible for adapting the caller's request
// to the aibridge daemon's mount path: callers hand it an upstream-shaped
// request and the transport rewrites URL.Path to "/api/v2/aibridge/<name>/..."
// before dispatching. Routing keys on the provider's instance name so callers
// can use the same string the proxy daemon and the bridge mount use.
//
// Source is informational: implementations must not gate on it. It is attached
// to the request context so handlers can include it in logs and metrics.
type TransportFactory interface {
TransportFor(providerID uuid.UUID, source Source) (http.RoundTripper, error)
TransportFor(providerName string, source Source) (http.RoundTripper, error)
}