@@ -494,7 +494,8 @@ func (b *Bridge) proxyOpenAIRequest(w http.ResponseWriter, r *http.Request) {
494
494
appendedPrevMsg := false
495
495
// Process each pending tool call
496
496
for _ , tc := range pendingToolCalls {
497
- if ! b .isInjectedTool (tc .ID ) {
497
+ fn := tc .Function .Name
498
+ if ! b .isInjectedTool (fn ) {
498
499
// Not an MCP proxy call, don't do anything.
499
500
continue
500
501
}
@@ -508,7 +509,7 @@ func (b *Bridge) proxyOpenAIRequest(w http.ResponseWriter, r *http.Request) {
508
509
_ , err = coderdClient .TrackToolUsage (ctx , & proto.TrackToolUsageRequest {
509
510
Model : string (in .Model ),
510
511
Input : tc .Function .Arguments ,
511
- Tool : tc . Function . Name ,
512
+ Tool : fn ,
512
513
Injected : true ,
513
514
})
514
515
if err != nil {
@@ -521,7 +522,7 @@ func (b *Bridge) proxyOpenAIRequest(w http.ResponseWriter, r *http.Request) {
521
522
)
522
523
_ = json .NewEncoder (& buf ).Encode (tc .Function .Arguments )
523
524
_ = json .NewDecoder (& buf ).Decode (& args )
524
- res , err := b .tools [tc . ID ].Call (ctx , args )
525
+ res , err := b .tools [fn ].Call (ctx , args )
525
526
if err != nil {
526
527
// Always provide a tool result even if the tool call failed
527
528
errorResponse := map [string ]interface {}{
@@ -759,6 +760,7 @@ func (b *Bridge) proxyAnthropicRequest(w http.ResponseWriter, r *http.Request) {
759
760
break
760
761
}
761
762
763
+ // TODO: implement injected tool calling.
762
764
if resp .StopReason == anthropic .BetaStopReasonToolUse {
763
765
var (
764
766
toolUse anthropic.BetaToolUseBlock
@@ -809,12 +811,6 @@ func (b *Bridge) proxyAnthropicRequest(w http.ResponseWriter, r *http.Request) {
809
811
810
812
es := newEventStream (anthropicEventStream )
811
813
812
- // var buf strings.Builder
813
- // in.Messages[0].Content = []anthropic.BetaContentBlockParamUnion{in.Messages[0].Content[len(in.Messages[0].Content) - 1]}
814
- //
815
- // json.NewEncoder(&buf).Encode(in)
816
- // fmt.Println(strings.Replace(buf.String(), "'", "\\'", -1))
817
-
818
814
var wg sync.WaitGroup
819
815
wg .Add (1 )
820
816
@@ -862,8 +858,6 @@ func (b *Bridge) proxyAnthropicRequest(w http.ResponseWriter, r *http.Request) {
862
858
// Don't relay this event back, otherwise the client will try invoke the tool as well.
863
859
continue
864
860
}
865
- default :
866
- fmt .Printf ("[%s] %s\n " , event .Type , event .RawJSON ())
867
861
}
868
862
case string (constant .ValueOf [ant_constant.ContentBlockDelta ]()):
869
863
if len (pendingToolCalls ) > 0 && b .isInjectedTool (lastToolName ) {
@@ -1179,19 +1173,6 @@ func (b *Bridge) proxyAnthropicRequest(w http.ResponseWriter, r *http.Request) {
1179
1173
}
1180
1174
1181
1175
<- streamCtx .Done ()
1182
-
1183
- // TODO: do we need to do this?
1184
- // // Close the underlying connection by hijacking it
1185
- // if hijacker, ok := w.(http.Hijacker); ok {
1186
- // conn, _, err := hijacker.Hijack()
1187
- // if err != nil {
1188
- // b.logger.Error(ctx, "failed to hijack connection", slog.Error(err))
1189
- // } else {
1190
- // conn.Close() // This closes the TCP connection entirely
1191
- // b.logger.Debug(ctx, "connection closed, stream over")
1192
- // }
1193
- // }
1194
-
1195
1176
break
1196
1177
}
1197
1178
}
0 commit comments