mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user