mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
chore: remove orphaned stream helpers
transcodeStream, transcodeStreamWithUsage, forwardSSEWithUsage and forceStreamBody have no callers since the package refactor; the live paths use the request-aware TranscodeStream/ForwardStream and prepareAnonymousBody directly. Also fix the stale comment reference.
This commit is contained in:
1 parent
79a208a467
commit
51639af3ef
3 files changed
+1
-32
No files matched your search
@@ -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)
|
||||
|
||||
@@ -469,24 +469,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
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user