Merge pull request #49: remove orphaned stream helpers

This commit is contained in:
Jason Xu committed 2026-10-07 19:34:34 +08:00
commit 3cb9837d25
3 files changed
+1 -32

No files matched your search

+1 -1
View File
@@ -230,7 +230,7 @@ func (g *Gateway) handleInference(external wire.Protocol) http.HandlerFunc {
if upstreamRoute.Anonymous || (meta != nil && meta.Shaped) {
// Key-tier shaped requests were force-streamed like the
// anonymous lane; collapse the same way.
// The anonymous lane is served streaming (see forceStreamBody);
// The anonymous lane is served streaming (see prepareAnonymousBody);
// collapse the events back into the single document this
// non-streaming client asked for.
collapsed, err := wire.CollapseStream(bytes.NewReader(responseBody), upstreamRoute.Protocol, model)
-18
View File
@@ -470,24 +470,6 @@ func anonymousTool(protocol wire.Protocol, name string) map[string]any {
}
}
// forceStreamBody returns a copy of body with streaming enabled. Bodies
// that already stream (or are not JSON objects) are returned unchanged.
func forceStreamBody(body []byte) []byte {
var payload map[string]any
if err := json.Unmarshal(body, &payload); err != nil {
return body
}
if streaming, ok := payload["stream"].(bool); ok && streaming {
return body
}
payload["stream"] = true
encoded, err := json.Marshal(payload)
if err != nil {
return body
}
return encoded
}
// requestBodyDumpLimit caps how much of an outbound body is written to the log.
const requestBodyDumpLimit = 64 << 10
-13
View File
@@ -41,15 +41,6 @@ type bridgeStreamEvent struct {
Usage *Usage
}
func transcodeStream(w http.ResponseWriter, reader io.Reader, from, to Protocol, model string) error {
_, _, err := transcodeStreamWithUsage(w, reader, from, to, model)
return err
}
func transcodeStreamWithUsage(w http.ResponseWriter, reader io.Reader, from, to Protocol, model string) (Usage, bool, error) {
return TranscodeStream(context.Background(), w, reader, from, to, model)
}
// TranscodeStream is the request-aware form used by the
// gateway. A cancelled client must not receive a synthetic upstream error
// after its connection has gone away.
@@ -158,10 +149,6 @@ func (writer *sseFlushWriter) Write(data []byte) (int, error) {
return n, err
}
func forwardSSEWithUsage(w http.ResponseWriter, reader io.Reader, protocol Protocol, model string) (Usage, bool, error) {
return ForwardStream(context.Background(), w, reader, protocol, model)
}
func ForwardStream(ctx context.Context, w http.ResponseWriter, reader io.Reader, protocol Protocol, model string) (Usage, bool, error) {
flusher, ok := w.(http.Flusher)
if !ok {