types.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package common
  2. import (
  3. "time"
  4. "google.golang.org/grpc/health/grpc_health_v1"
  5. )
  6. // CoreInstanceInfo represents a discovered Cline instance
  7. // This is the canonical definition used across all CLI packages
  8. type CoreInstanceInfo struct {
  9. // Full core address including port
  10. Address string `json:"address"`
  11. // Host bridge service address that core holds (host is ALWAYS running on localhost FYI)
  12. HostServiceAddress string `json:"host_port"`
  13. Status grpc_health_v1.HealthCheckResponse_ServingStatus `json:"status"`
  14. LastSeen time.Time `json:"last_seen"`
  15. ProcessPID int `json:"process_pid,omitempty"`
  16. Version string `json:"version,omitempty"`
  17. }
  18. func (c *CoreInstanceInfo) CorePort() int {
  19. _, port, _ := ParseHostPort(c.Address)
  20. return port
  21. }
  22. func (c *CoreInstanceInfo) HostPort() int {
  23. _, port, _ := ParseHostPort(c.HostServiceAddress)
  24. return port
  25. }
  26. func (c *CoreInstanceInfo) StatusString() string {
  27. return c.Status.String()
  28. }
  29. // LockRow represents a row in the locks table
  30. type LockRow struct {
  31. ID int64 `json:"id"`
  32. HeldBy string `json:"held_by"`
  33. LockType string `json:"lock_type"`
  34. LockTarget string `json:"lock_target"`
  35. LockedAt int64 `json:"locked_at"`
  36. }
  37. // InstancesOutput represents the JSON output format for instance listing
  38. type InstancesOutput struct {
  39. DefaultInstance string `json:"default_instance"`
  40. CoreInstances []CoreInstanceInfo `json:"instances"`
  41. }
  42. type DefaultCoreInstance struct {
  43. Address string `json:"default_instance"`
  44. LastUpdated string `json:"last_updated"`
  45. }