MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / callPlugin

Function callPlugin

internal/pluginhost/rpc_client.go:140–162  ·  view source on GitHub ↗
(ctx context.Context, client pluginClient, method string, request any)

Source from the content-addressed store, hash-verified

138}
139
140func callPlugin[T any](ctx context.Context, client pluginClient, method string, request any) (T, error) {
141 var zero T
142 rawRequest, errMarshal := json.Marshal(sanitizePluginRequest(request))
143 if errMarshal != nil {
144 return zero, fmt.Errorf("marshal plugin request %s: %w", method, errMarshal)
145 }
146 rawResp, errCall := client.Call(ctx, method, rawRequest)
147 if errCall != nil {
148 return zero, errCall
149 }
150 var envelope pluginabi.Envelope
151 if errUnmarshal := json.Unmarshal(rawResp, &envelope); errUnmarshal != nil {
152 return zero, fmt.Errorf("decode plugin envelope %s: %w", method, errUnmarshal)
153 }
154 out, errDecode := decodeEnvelopeResult[T](envelope)
155 if errDecode != nil {
156 if !envelope.OK {
157 return zero, errDecode
158 }
159 return zero, fmt.Errorf("decode plugin result %s: %w", method, errDecode)
160 }
161 return out, nil
162}
163
164func sanitizePluginRequest(request any) any {
165 switch req := request.(type) {

Callers 15

RegisterModelsMethod · 0.85
StaticModelsMethod · 0.85
ModelsForAuthMethod · 0.85
PickMethod · 0.85
RouteModelMethod · 0.85
ParseAuthMethod · 0.85
StartLoginMethod · 0.85
PollLoginMethod · 0.85
RefreshAuthMethod · 0.85
AuthenticateMethod · 0.85
ExecuteMethod · 0.85
CountTokensMethod · 0.85

Calls 2

sanitizePluginRequestFunction · 0.85
CallMethod · 0.65

Tested by

no test coverage detected