58c19856fd
* feat(runtime): improve Lite gateway scheduling and proxy stability - Expand the runtime gateway port range to match 100 instances per pod - Scale runtime deployments based on pending backlog - Serialize gateway creation per pod and handle starting/creating states - Clean up missing gateway bindings from runtime agent reports - Improve Lite gateway proxy token stripping and auth header injection - Update deployment manifests, docs, and related tests * fix(runtime): harden Hermes Lite gateway recovery - Add hashed gateway token aliases for short-term token compatibility - Fix /resume conversations failing when old sessions use mismatched gateway tokens - Recover ports only from stale error bindings without affecting active gateways * feat(runtime): enable bidirectional desktop clipboard and direct proxy - Enable WebTop/Selkies/Kasm clipboard by default with per-instance overrides - Document clipboard verification, configuration pitfalls, and IME troubleshooting - Enable direct desktop proxy in the K8s and K3s manifests --------- Co-authored-by: litiantian03 <litiantian03@ieisystem.com>
84 lines
2.2 KiB
Go
84 lines
2.2 KiB
Go
package services
|
|
|
|
import (
|
|
"fmt"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
RuntimeTypeOpenClaw = "openclaw"
|
|
RuntimeTypeHermes = "hermes"
|
|
|
|
InstanceModeLite = "lite"
|
|
InstanceModePro = "pro"
|
|
|
|
RuntimeBackendGateway = "gateway"
|
|
RuntimeBackendDesktop = "desktop"
|
|
RuntimeBackendShell = "shell"
|
|
|
|
RuntimeGatewayPortStart = 20000
|
|
RuntimePodCapacity = 100
|
|
// OpenClaw gateway slots reserve adjacent service ports in addition to the
|
|
// public gateway port. Capacity is instance count, not raw port count.
|
|
RuntimeGatewayPortsPerInstance = 3
|
|
RuntimeGatewayPortEnd = RuntimeGatewayPortStart + RuntimePodCapacity*RuntimeGatewayPortsPerInstance - 1
|
|
RuntimeLinuxIDBase = 200000
|
|
)
|
|
|
|
func NormalizeV2RuntimeType(instanceType string) (string, bool) {
|
|
switch strings.ToLower(strings.TrimSpace(instanceType)) {
|
|
case RuntimeTypeOpenClaw:
|
|
return RuntimeTypeOpenClaw, true
|
|
case RuntimeTypeHermes:
|
|
return RuntimeTypeHermes, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
func NormalizeInstanceMode(mode string) (string, bool) {
|
|
switch strings.ToLower(strings.TrimSpace(mode)) {
|
|
case InstanceModeLite:
|
|
return InstanceModeLite, true
|
|
case InstanceModePro:
|
|
return InstanceModePro, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
func RuntimeTypeForInstanceMode(mode string) (string, bool) {
|
|
normalized, ok := NormalizeInstanceMode(mode)
|
|
if !ok {
|
|
return "", false
|
|
}
|
|
if normalized == InstanceModeLite {
|
|
return RuntimeBackendGateway, true
|
|
}
|
|
return RuntimeBackendDesktop, true
|
|
}
|
|
|
|
func InstanceModeForRuntimeType(runtimeType string) string {
|
|
if strings.EqualFold(strings.TrimSpace(runtimeType), RuntimeBackendGateway) {
|
|
return InstanceModeLite
|
|
}
|
|
return InstanceModePro
|
|
}
|
|
|
|
func RuntimeWorkspacePath(runtimeType string, userID int, instanceID int) string {
|
|
return RuntimeWorkspacePathWithRoot("/workspaces", runtimeType, userID, instanceID)
|
|
}
|
|
|
|
func RuntimeWorkspacePathWithRoot(root, runtimeType string, userID int, instanceID int) string {
|
|
root = strings.TrimSpace(root)
|
|
if root == "" {
|
|
root = "/workspaces"
|
|
}
|
|
return path.Join(root, fmt.Sprintf("%s/user-%d/instance-%d", runtimeType, userID, instanceID))
|
|
}
|
|
|
|
func RuntimeLinuxID(instanceID int) int {
|
|
return RuntimeLinuxIDBase + instanceID
|
|
}
|