feat: initial contracts

This commit is contained in:
Harivansh Rathi 2026-04-08 01:52:39 +00:00
parent 58f95324f4
commit 6f0f0643fe
7 changed files with 127 additions and 0 deletions

5
contract/health.go Normal file
View file

@ -0,0 +1,5 @@
package host
type HealthResponse struct {
OK bool `json:"ok"`
}

17
contract/machines.go Normal file
View file

@ -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"`
}

34
contract/types.go Normal file
View file

@ -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"`
}

12
internal/daemon/daemon.go Normal file
View file

@ -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
}

View file

@ -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)
}

27
internal/model/types.go Normal file
View file

@ -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
}

16
internal/store/store.go Normal file
View file

@ -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
}