mirror of
https://github.com/wavetermdev/waveterm
synced 2026-04-21 22:47:16 +00:00
lots of stuff here. introduces a streaming framework for the RPC system with flow control. new authentication primitives for the RPC system. this is used to create a persistent "job manager" process (via wsh) that can survive disconnects. and then a jobcontroller in the main server that can create, reconnect, and manage these new persistent jobs. code is currently not actively hooked up to anything minus some new debugging wsh commands, and a switch in the term block that lets me test viewing the output. after PRing this change the next steps are more testing and then integrating this functionality into the product.
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
// Copyright 2025, Command Line Inc.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package webcmd
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"github.com/wavetermdev/waveterm/pkg/tsgen/tsgenmeta"
|
|
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
|
"github.com/wavetermdev/waveterm/pkg/wshutil"
|
|
)
|
|
|
|
const (
|
|
WSCommand_Rpc = "rpc"
|
|
)
|
|
|
|
type WSCommandType interface {
|
|
GetWSCommand() string
|
|
}
|
|
|
|
func WSCommandTypeUnionMeta() tsgenmeta.TypeUnionMeta {
|
|
return tsgenmeta.TypeUnionMeta{
|
|
BaseType: reflect.TypeOf((*WSCommandType)(nil)).Elem(),
|
|
TypeFieldName: "wscommand",
|
|
Types: []reflect.Type{
|
|
reflect.TypeOf(WSRpcCommand{}),
|
|
},
|
|
}
|
|
}
|
|
|
|
type WSRpcCommand struct {
|
|
WSCommand string `json:"wscommand" tstype:"\"rpc\""`
|
|
Message *wshutil.RpcMessage `json:"message"`
|
|
}
|
|
|
|
func (cmd *WSRpcCommand) GetWSCommand() string {
|
|
return cmd.WSCommand
|
|
}
|
|
|
|
func ParseWSCommandMap(cmdMap map[string]any) (WSCommandType, error) {
|
|
cmdType, ok := cmdMap["wscommand"].(string)
|
|
if !ok {
|
|
return nil, fmt.Errorf("no wscommand field in command map")
|
|
}
|
|
switch cmdType {
|
|
case WSCommand_Rpc:
|
|
var cmd WSRpcCommand
|
|
err := utilfn.DoMapStructure(&cmd, cmdMap)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decoding WSRpcCommand: %w", err)
|
|
}
|
|
return &cmd, nil
|
|
default:
|
|
return nil, fmt.Errorf("unknown wscommand type %q", cmdType)
|
|
}
|
|
}
|