From 6f0f0643fe8d9e8d997b944812f80888d090a867 Mon Sep 17 00:00:00 2001 From: Harivansh Rathi Date: Wed, 8 Apr 2026 01:52:39 +0000 Subject: [PATCH] feat: initial contracts --- contract/health.go | 5 +++++ contract/machines.go | 17 +++++++++++++++++ contract/types.go | 34 ++++++++++++++++++++++++++++++++++ internal/daemon/daemon.go | 12 ++++++++++++ internal/httpapi/handlers.go | 16 ++++++++++++++++ internal/model/types.go | 27 +++++++++++++++++++++++++++ internal/store/store.go | 16 ++++++++++++++++ 7 files changed, 127 insertions(+) create mode 100644 contract/health.go create mode 100644 contract/machines.go create mode 100644 contract/types.go create mode 100644 internal/daemon/daemon.go create mode 100644 internal/httpapi/handlers.go create mode 100644 internal/model/types.go create mode 100644 internal/store/store.go diff --git a/contract/health.go b/contract/health.go new file mode 100644 index 0000000..6f1e917 --- /dev/null +++ b/contract/health.go @@ -0,0 +1,5 @@ +package host + +type HealthResponse struct { + OK bool `json:"ok"` +} diff --git a/contract/machines.go b/contract/machines.go new file mode 100644 index 0000000..4c93d35 --- /dev/null +++ b/contract/machines.go @@ -0,0 +1,17 @@ +package host + +type CreateMachineRequest struct { + MachineID MachineID `json:"machine_id"` +} + +type CreateMachineResponse struct { + Machine Machine `json:"machine"` +} + +type GetMachineResponse struct { + Machine Machine `json:"machine"` +} + +type ListMachinesResponse struct { + Machines []Machine `json:"machines"` +} diff --git a/contract/types.go b/contract/types.go new file mode 100644 index 0000000..9470317 --- /dev/null +++ b/contract/types.go @@ -0,0 +1,34 @@ +package host + +import "time" + +type MachineID string + +type MachinePhase string + +type VolumeID string + +type VolumeKind string + +const ( + MachinePhasePending MachinePhase = "pending" + MachinePhaseRunning MachinePhase = "running" + MachinePhaseStopping MachinePhase = "stopping" + MachinePhaseStopped MachinePhase = "stopped" + MachinePhaseFailed MachinePhase = "failed" + MachinePhaseDeleting MachinePhase = "deleting" +) + +const ( + VolumeKindSystem VolumeKind = "system" + VolumeKindUser VolumeKind = "user" +) + +type Machine struct { + ID MachineID `json:"id"` + Phase MachinePhase `json:"phase"` + RuntimeHost string `json:"runtime_host,omitempty"` + Error string `json:"error,omitempty"` + CreatedAt time.Time `json:"created_at"` + StartedAt *time.Time `json:"started_at,omitempty"` +} diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go new file mode 100644 index 0000000..d3dd3b2 --- /dev/null +++ b/internal/daemon/daemon.go @@ -0,0 +1,12 @@ +package daemon + +import ( + "github.com/getcompanion-ai/computer-host/internal/store" +) + +type Runtime interface{} + +type Daemon struct { + Store store.Store + Runtime Runtime +} diff --git a/internal/httpapi/handlers.go b/internal/httpapi/handlers.go new file mode 100644 index 0000000..cadc5bb --- /dev/null +++ b/internal/httpapi/handlers.go @@ -0,0 +1,16 @@ +package httpapi + +import ( + "context" + + contracthost "github.com/getcompanion-ai/computer-host/contract" +) + +type Service interface { + CreateMachine(context.Context, contracthost.CreateMachineRequest) (*contracthost.CreateMachineResponse, error) + GetMachine(context.Context, contracthost.MachineID) (*contracthost.GetMachineResponse, error) + ListMachines(context.Context) (*contracthost.ListMachinesResponse, error) + StopMachine(context.Context, contracthost.MachineID) error + DeleteMachine(context.Context, contracthost.MachineID) error + Health(context.Context) (*contracthost.HealthResponse, error) +} diff --git a/internal/model/types.go b/internal/model/types.go new file mode 100644 index 0000000..7aa29f5 --- /dev/null +++ b/internal/model/types.go @@ -0,0 +1,27 @@ +package model + +import ( + "time" + + contracthost "github.com/getcompanion-ai/computer-host/contract" +) + +type MachineRecord struct { + ID contracthost.MachineID + Phase contracthost.MachinePhase + RuntimeHost string + Error string + CreatedAt time.Time + StartedAt *time.Time +} + +type StoragePool string + +type VolumeRecord struct { + ID contracthost.VolumeID + MachineID contracthost.MachineID + Kind contracthost.VolumeKind + Pool StoragePool + Path string + CreatedAt time.Time +} diff --git a/internal/store/store.go b/internal/store/store.go new file mode 100644 index 0000000..57db4b2 --- /dev/null +++ b/internal/store/store.go @@ -0,0 +1,16 @@ +package store + +import ( + "context" + + "github.com/getcompanion-ai/computer-host/internal/model" + contracthost "github.com/getcompanion-ai/computer-host/contract" +) + +type Store interface { + CreateMachine(context.Context, model.MachineRecord) error + GetMachine(context.Context, contracthost.MachineID) (*model.MachineRecord, error) + ListMachines(context.Context) ([]model.MachineRecord, error) + UpdateMachine(context.Context, model.MachineRecord) error + DeleteMachine(context.Context, contracthost.MachineID) error +}