@@ -48,13 +48,11 @@ type Server struct {
48
48
shuttingDownB bool
49
49
// shuttingDownCh will receive when we start graceful shutdown
50
50
shuttingDownCh chan struct {}
51
-
52
- bridge * Bridge
53
51
}
54
52
55
53
var _ proto.DRPCAIBridgeDaemonServer = & Server {}
56
54
57
- func New (rpcDialer Dialer , httpAddr string , logger slog.Logger , bridgeCfg codersdk. AIBridgeConfig , tools [] * MCPTool ) (* Server , error ) {
55
+ func New (rpcDialer Dialer , httpAddr string , logger slog.Logger ) (* Server , error ) {
58
56
if rpcDialer == nil {
59
57
return nil , xerrors .Errorf ("nil rpcDialer given" )
60
58
}
@@ -71,29 +69,13 @@ func New(rpcDialer Dialer, httpAddr string, logger slog.Logger, bridgeCfg coders
71
69
initConnectionCh : make (chan struct {}),
72
70
}
73
71
74
- // TODO: improve error handling here; if this fails it prevents the whole server from starting up!
75
-
76
- bridge , err := NewBridge (bridgeCfg , httpAddr , logger .Named ("ai_bridge" ), daemon .client , tools )
77
- if err != nil {
78
- return nil , xerrors .Errorf ("create new bridge server: %w" , err )
79
- }
80
-
81
- daemon .bridge = bridge
82
-
83
72
daemon .wg .Add (1 )
84
73
go daemon .connect ()
85
74
86
- daemon .wg .Add (1 )
87
- go func () {
88
- defer daemon .wg .Done ()
89
- err := bridge .Serve ()
90
- // TODO: better error handling.
91
- // TODO: close on shutdown.
92
- logger .Error (ctx , "bridge server stopped" , slog .Error (err ))
93
- }()
94
-
95
75
return daemon , nil
96
- } // Connect establishes a connection to coderd.
76
+ }
77
+
78
+ // Connect establishes a connection to coderd.
97
79
func (s * Server ) connect () {
98
80
defer s .logger .Debug (s .closeContext , "connect loop exited" )
99
81
defer s .wg .Done ()
@@ -155,7 +137,7 @@ connectLoop:
155
137
}
156
138
}
157
139
158
- func (s * Server ) client () (proto.DRPCAIBridgeDaemonClient , bool ) {
140
+ func (s * Server ) Client () (proto.DRPCAIBridgeDaemonClient , bool ) {
159
141
select {
160
142
case <- s .closeContext .Done ():
161
143
return nil , false
@@ -168,7 +150,7 @@ func (s *Server) client() (proto.DRPCAIBridgeDaemonClient, bool) {
168
150
}
169
151
170
152
func (s * Server ) TrackTokenUsage (ctx context.Context , in * proto.TrackTokenUsageRequest ) (* proto.TrackTokenUsageResponse , error ) {
171
- out , err := clientDoWithRetries (ctx , s .client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackTokenUsageResponse , error ) {
153
+ out , err := clientDoWithRetries (ctx , s .Client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackTokenUsageResponse , error ) {
172
154
return client .TrackTokenUsage (ctx , in )
173
155
})
174
156
if err != nil {
@@ -178,7 +160,7 @@ func (s *Server) TrackTokenUsage(ctx context.Context, in *proto.TrackTokenUsageR
178
160
}
179
161
180
162
func (s * Server ) TrackUserPrompt (ctx context.Context , in * proto.TrackUserPromptRequest ) (* proto.TrackUserPromptResponse , error ) {
181
- out , err := clientDoWithRetries (ctx , s .client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackUserPromptResponse , error ) {
163
+ out , err := clientDoWithRetries (ctx , s .Client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackUserPromptResponse , error ) {
182
164
return client .TrackUserPrompt (ctx , in )
183
165
})
184
166
if err != nil {
@@ -188,7 +170,7 @@ func (s *Server) TrackUserPrompt(ctx context.Context, in *proto.TrackUserPromptR
188
170
}
189
171
190
172
func (s * Server ) TrackToolUsage (ctx context.Context , in * proto.TrackToolUsageRequest ) (* proto.TrackToolUsageResponse , error ) {
191
- out , err := clientDoWithRetries (ctx , s .client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackToolUsageResponse , error ) {
173
+ out , err := clientDoWithRetries (ctx , s .Client , func (ctx context.Context , client proto.DRPCAIBridgeDaemonClient ) (* proto.TrackToolUsageResponse , error ) {
192
174
return client .TrackToolUsage (ctx , in )
193
175
})
194
176
if err != nil {
@@ -197,63 +179,6 @@ func (s *Server) TrackToolUsage(ctx context.Context, in *proto.TrackToolUsageReq
197
179
return out , nil
198
180
}
199
181
200
- // func (s *Server) ChatCompletions(payload *proto.JSONPayload, stream proto.DRPCOpenAIService_ChatCompletionsStream) error {
201
- // // TODO: call OpenAI API.
202
- //
203
- // select {
204
- // case <-stream.Context().Done():
205
- // return nil
206
- // default:
207
- // }
208
- //
209
- // err := stream.Send(&proto.JSONPayload{
210
- // Content: `
211
- //{
212
- // "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
213
- // "object": "chat.completion",
214
- // "created": 1741569952,
215
- // "model": "gpt-4.1-2025-04-14",
216
- // "choices": [
217
- // {
218
- // "index": 0,
219
- // "message": {
220
- // "role": "assistant",
221
- // "content": "Hello! How can I assist you today?",
222
- // "refusal": null,
223
- // "annotations": []
224
- // },
225
- // "logprobs": null,
226
- // "finish_reason": "stop"
227
- // }
228
- // ],
229
- // "usage": {
230
- // "prompt_tokens": 19,
231
- // "completion_tokens": 10,
232
- // "total_tokens": 29,
233
- // "prompt_tokens_details": {
234
- // "cached_tokens": 0,
235
- // "audio_tokens": 0
236
- // },
237
- // "completion_tokens_details": {
238
- // "reasoning_tokens": 0,
239
- // "audio_tokens": 0,
240
- // "accepted_prediction_tokens": 0,
241
- // "rejected_prediction_tokens": 0
242
- // }
243
- // },
244
- // "service_tier": "default"
245
- //}
246
- // `})
247
- // if err != nil {
248
- // return xerrors.Errorf("stream chat completion response: %w", err)
249
- // }
250
- // return nil
251
- //}
252
-
253
- func (s * Server ) BridgeAddr () string {
254
- return s .bridge .Addr ()
255
- }
256
-
257
182
// TODO: direct copy/paste from provisionerd, abstract into common util.
258
183
func retryable (err error ) bool {
259
184
return xerrors .Is (err , yamux .ErrSessionShutdown ) || xerrors .Is (err , io .EOF ) || xerrors .Is (err , fasthttputil .ErrInmemoryListenerClosed ) ||
0 commit comments