9
9
"net"
10
10
"os"
11
11
"path"
12
+ "slices"
12
13
"time"
13
14
)
14
15
@@ -19,12 +20,17 @@ type PluginRpcStatus struct {
19
20
20
21
var (
21
22
PluginRpcStatusDisconnected = PluginRpcStatus {"disconnected" , "" }
23
+ PluginRpcStatusUnknown = PluginRpcStatus {"unknown" , "" }
22
24
PluginRpcStatusLoading = PluginRpcStatus {"loading" , "" }
23
25
PluginRpcStatusPendingConfiguration = PluginRpcStatus {"pending-configuration" , "" }
24
26
PluginRpcStatusRunning = PluginRpcStatus {"running" , "" }
25
27
PluginRpcStatusError = PluginRpcStatus {"error" , "" }
26
28
)
27
29
30
+ type PluginRpcSupportedMethods struct {
31
+ SupportedRpcMethods []string `json:"supported_rpc_methods"`
32
+ }
33
+
28
34
type PluginRpcServer struct {
29
35
install * PluginInstall
30
36
workingDir string
@@ -103,10 +109,10 @@ func (s *PluginRpcServer) handleConnection(conn net.Conn) {
103
109
// TODO: if read 65k bytes, then likey there is more data to read... figure out how to handle this
104
110
n , err := conn .Read (buf )
105
111
if err != nil {
106
- log .Printf ("Failed to read message: %v" , err )
107
112
if errors .Is (err , net .ErrClosed ) {
108
113
s .status = PluginRpcStatusDisconnected
109
114
} else {
115
+ log .Printf ("Failed to read message: %v" , err )
110
116
s .status = PluginRpcStatusError
111
117
s .status .Message = fmt .Errorf ("failed to read message: %v" , err ).Error ()
112
118
}
@@ -124,21 +130,23 @@ func (s *PluginRpcServer) handleConnection(conn net.Conn) {
124
130
}
125
131
126
132
func (s * PluginRpcServer ) handleRpcStatus (ctx context.Context , rpcserver * jsonrpc.JSONRPCServer ) {
127
- // log.Printf("Plugin rpc server started. Getting supported methods...")
128
- // supportedMethodsResponse, err := rpcserver.Request("getPluginSupportedMethods", map[string]interface{}{})
129
- // if err != nil {
130
- // log.Printf("Failed to get supported methods: %v", err)
131
- // s.status = PluginRpcStatusError
132
- // s.status.Message = fmt.Errorf("error getting supported methods: %v", err).Error()
133
- // }
134
-
135
- // if supportedMethodsResponse.Error != nil {
136
- // log.Printf("Failed to get supported methods: %v", supportedMethodsResponse.Error)
137
- // s.status = PluginRpcStatusError
138
- // s.status.Message = fmt.Errorf("error getting supported methods: %v", supportedMethodsResponse.Error).Error()
139
- // }
140
-
141
- // log.Printf("Plugin has supported methods: %v", supportedMethodsResponse.Result)
133
+ s .status = PluginRpcStatusUnknown
134
+
135
+ log .Printf ("Plugin rpc server started. Getting supported methods..." )
136
+ var supportedMethodsResponse PluginRpcSupportedMethods
137
+ err := rpcserver .Request ("getPluginSupportedMethods" , nil , & supportedMethodsResponse )
138
+ if err != nil {
139
+ log .Printf ("Failed to get supported methods: %v" , err )
140
+ s .status = PluginRpcStatusError
141
+ s .status .Message = fmt .Errorf ("error getting supported methods: %v" , err .Message ).Error ()
142
+ }
143
+
144
+ log .Printf ("Plugin has supported methods: %v" , supportedMethodsResponse .SupportedRpcMethods )
145
+
146
+ if ! slices .Contains (supportedMethodsResponse .SupportedRpcMethods , "getPluginStatus" ) {
147
+ log .Printf ("Plugin does not support getPluginStatus method" )
148
+ return
149
+ }
142
150
143
151
ticker := time .NewTicker (1 * time .Second )
144
152
for {
@@ -147,7 +155,7 @@ func (s *PluginRpcServer) handleRpcStatus(ctx context.Context, rpcserver *jsonrp
147
155
return
148
156
case <- ticker .C :
149
157
var statusResponse PluginRpcStatus
150
- err := rpcserver .Request ("getPluginStatus" , map [ string ] interface {}{} , & statusResponse )
158
+ err := rpcserver .Request ("getPluginStatus" , nil , & statusResponse )
151
159
if err != nil {
152
160
log .Printf ("Failed to get status: %v" , err )
153
161
if err , ok := err .Data .(error ); ok && errors .Is (err , net .ErrClosed ) {
0 commit comments