protocol

package
v0.1.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const Version = "1.0"

Variables

Functions

func DefaultSchemasDir

func DefaultSchemasDir() (string, error)

func IsKnownMessageType

func IsKnownMessageType(typ MessageType) bool

func Marshal

func Marshal(envelope Envelope) ([]byte, error)

Types

type ChatMessage

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatRequest

type ChatRequest struct {
	Messages    []ChatMessage `json:"messages"`
	Temperature *float64      `json:"temperature,omitempty"`
	MaxTokens   int           `json:"max_tokens"`
	Seed        *int64        `json:"seed,omitempty"`
	Stream      bool          `json:"stream"`
}

type Envelope

type Envelope struct {
	ProtocolVersion string          `json:"protocol_version"`
	MessageID       string          `json:"message_id"`
	Type            MessageType     `json:"type"`
	SentAt          time.Time       `json:"sent_at"`
	Payload         json.RawMessage `json:"payload"`
}

func NewEnvelope

func NewEnvelope(messageID string, typ MessageType, sentAt time.Time, payload any) (Envelope, error)

func Unmarshal

func Unmarshal(data []byte) (Envelope, error)

type GPUStatus

type GPUStatus struct {
	Name               string `json:"name"`
	VRAMTotalMB        int64  `json:"vram_total_mb"`
	VRAMFreeMB         int64  `json:"vram_free_mb"`
	TemperatureC       int    `json:"temperature_c"`
	PowerW             int    `json:"power_w"`
	PowerLimitW        int    `json:"power_limit_w"`
	UtilizationPercent int    `json:"utilization_percent"`
}

type JobAcceptedPayload

type JobAcceptedPayload struct {
	JobID      string    `json:"job_id"`
	AttemptID  string    `json:"attempt_id"`
	AcceptedAt time.Time `json:"accepted_at"`
}

type JobCancelPayload

type JobCancelPayload struct {
	JobID       string    `json:"job_id"`
	AttemptID   string    `json:"attempt_id,omitempty"`
	Reason      string    `json:"reason"`
	CancelledAt time.Time `json:"cancelled_at"`
}

type JobCompletedPayload

type JobCompletedPayload struct {
	JobID          string         `json:"job_id"`
	AttemptID      string         `json:"attempt_id"`
	ModelID        string         `json:"model_id"`
	RuntimeHash    string         `json:"runtime_hash"`
	ModelHash      string         `json:"model_hash"`
	Message        *ChatMessage   `json:"message,omitempty"`
	Usage          Usage          `json:"usage"`
	DurationMillis int64          `json:"duration_millis"`
	FinishReason   string         `json:"finish_reason"`
	CompletedAt    time.Time      `json:"completed_at"`
	Signature      *NodeSignature `json:"signature,omitempty"`
}

type JobFailedPayload

type JobFailedPayload struct {
	JobID     string    `json:"job_id"`
	AttemptID string    `json:"attempt_id"`
	ErrorCode string    `json:"error_code"`
	Message   string    `json:"message"`
	Retryable bool      `json:"retryable"`
	FailedAt  time.Time `json:"failed_at"`
}

type JobOfferPayload

type JobOfferPayload struct {
	JobID          string          `json:"job_id"`
	AttemptID      string          `json:"attempt_id"`
	LeaseExpiresAt time.Time       `json:"lease_expires_at"`
	DeadlineAt     time.Time       `json:"deadline_at"`
	ModelID        string          `json:"model_id"`
	Request        ChatRequest     `json:"request"`
	Verification   JobVerification `json:"verification"`
}

type JobRejectedPayload

type JobRejectedPayload struct {
	JobID      string    `json:"job_id"`
	AttemptID  string    `json:"attempt_id"`
	ReasonCode string    `json:"reason_code"`
	Message    string    `json:"message"`
	Retryable  bool      `json:"retryable"`
	RejectedAt time.Time `json:"rejected_at"`
}

type JobStartedPayload

type JobStartedPayload struct {
	JobID     string    `json:"job_id"`
	AttemptID string    `json:"attempt_id"`
	StartedAt time.Time `json:"started_at"`
}

type JobVerification

type JobVerification struct {
	Kind        string  `json:"kind"`
	ChallengeID *string `json:"challenge_id"`
}

type MessageType

type MessageType string
const (
	TypeNodeHello              MessageType = "node.hello"
	TypeNodeHeartbeat          MessageType = "node.heartbeat"
	TypeNodeStateChanged       MessageType = "node.state_changed"
	TypeModelDownloadProgress  MessageType = "model.download_progress"
	TypeModelReady             MessageType = "model.ready"
	TypeJobAccepted            MessageType = "job.accepted"
	TypeJobRejected            MessageType = "job.rejected"
	TypeJobStarted             MessageType = "job.started"
	TypeJobCompleted           MessageType = "job.completed"
	TypeJobFailed              MessageType = "job.failed"
	TypeNodeSafetyEvent        MessageType = "node.safety_event"
	TypeNodeLogEvent           MessageType = "node.log_event"
	TypeSessionAccepted        MessageType = "session.accepted"
	TypeNodeConfigUpdated      MessageType = "node.config_updated"
	TypeModelAssign            MessageType = "model.assign"
	TypeModelUnload            MessageType = "model.unload"
	TypeJobOffer               MessageType = "job.offer"
	TypeJobCancel              MessageType = "job.cancel"
	TypeNodeDrain              MessageType = "node.drain"
	TypeRuntimeUpdateAvailable MessageType = "runtime.update_available"
)

type ModelAssignPayload

type ModelAssignPayload struct {
	AssignmentID string    `json:"assignment_id"`
	ModelID      string    `json:"model_id"`
	VersionID    string    `json:"version_id"`
	ManifestURL  string    `json:"manifest_url"`
	ManifestHash string    `json:"manifest_hash"`
	AssignedAt   time.Time `json:"assigned_at"`
}

type ModelDownloadProgressPayload

type ModelDownloadProgressPayload struct {
	NodeID          string    `json:"node_id"`
	ModelID         string    `json:"model_id"`
	ArtifactID      string    `json:"artifact_id"`
	BytesDownloaded int64     `json:"bytes_downloaded"`
	BytesTotal      int64     `json:"bytes_total"`
	Percent         float64   `json:"percent"`
	Timestamp       time.Time `json:"timestamp"`
}

type ModelReadyPayload

type ModelReadyPayload struct {
	NodeID      string    `json:"node_id"`
	ModelID     string    `json:"model_id"`
	ModelHash   string    `json:"model_hash"`
	RuntimeHash string    `json:"runtime_hash"`
	LoadedAt    time.Time `json:"loaded_at"`
}

type ModelUnloadPayload

type ModelUnloadPayload struct {
	ModelID    string    `json:"model_id"`
	Reason     string    `json:"reason"`
	DeadlineAt time.Time `json:"deadline_at"`
}

type NodeConfigUpdatedPayload

type NodeConfigUpdatedPayload struct {
	ConfigVersion            string    `json:"config_version"`
	HeartbeatIntervalSeconds int       `json:"heartbeat_interval_seconds"`
	MaxJobSeconds            int       `json:"max_job_seconds"`
	UpdatedAt                time.Time `json:"updated_at"`
}

type NodeDrainPayload

type NodeDrainPayload struct {
	Reason  string     `json:"reason"`
	DrainBy *time.Time `json:"drain_by,omitempty"`
}

type NodeHeartbeatPayload

type NodeHeartbeatPayload struct {
	NodeID        string    `json:"node_id"`
	Sequence      int64     `json:"sequence"`
	State         string    `json:"state"`
	ModelID       string    `json:"model_id,omitempty"`
	RuntimeHash   string    `json:"runtime_hash,omitempty"`
	ModelHash     string    `json:"model_hash,omitempty"`
	GPU           GPUStatus `json:"gpu"`
	ActiveJobID   *string   `json:"active_job_id"`
	ScheduleState string    `json:"schedule_state,omitempty"`
	ThermalState  string    `json:"thermal_state,omitempty"`
	Paused        bool      `json:"paused,omitempty"`
	Draining      bool      `json:"draining,omitempty"`
	UptimeSeconds int64     `json:"uptime_seconds"`
	Timestamp     time.Time `json:"timestamp"`
}

type NodeHelloPayload

type NodeHelloPayload struct {
	NodeID                    string   `json:"node_id"`
	AgentVersion              string   `json:"agent_version"`
	SupportedProtocolVersions []string `json:"supported_protocol_versions"`
	Capabilities              []string `json:"capabilities"`
	Hostname                  string   `json:"hostname,omitempty"`
}

type NodeLogEventPayload

type NodeLogEventPayload struct {
	NodeID   string            `json:"node_id"`
	Level    string            `json:"level"`
	Message  string            `json:"message"`
	Fields   map[string]string `json:"fields,omitempty"`
	LoggedAt time.Time         `json:"logged_at"`
}

type NodeSafetyEventPayload

type NodeSafetyEventPayload struct {
	NodeID       string    `json:"node_id"`
	EventCode    string    `json:"event_code"`
	Severity     string    `json:"severity"`
	Message      string    `json:"message"`
	TemperatureC *int      `json:"temperature_c,omitempty"`
	PowerW       *int      `json:"power_w,omitempty"`
	OccurredAt   time.Time `json:"occurred_at"`
}

type NodeSignature

type NodeSignature struct {
	KeyID     string    `json:"key_id"`
	Algorithm string    `json:"algorithm"`
	Value     string    `json:"value"`
	SignedAt  time.Time `json:"signed_at"`
}

type NodeStateChangedPayload

type NodeStateChangedPayload struct {
	NodeID        string    `json:"node_id"`
	PreviousState string    `json:"previous_state"`
	State         string    `json:"state"`
	Reason        string    `json:"reason,omitempty"`
	Timestamp     time.Time `json:"timestamp"`
}

type RuntimeUpdateAvailablePayload

type RuntimeUpdateAvailablePayload struct {
	RuntimeID       string    `json:"runtime_id"`
	Version         string    `json:"version"`
	ManifestURL     string    `json:"manifest_url"`
	BinarySHA256    string    `json:"binary_sha256"`
	Required        bool      `json:"required"`
	ReleaseNotesURL string    `json:"release_notes_url,omitempty"`
	AvailableAt     time.Time `json:"available_at"`
}

type SessionAcceptedPayload

type SessionAcceptedPayload struct {
	NodeID                   string    `json:"node_id"`
	SessionID                string    `json:"session_id"`
	HeartbeatIntervalSeconds int       `json:"heartbeat_interval_seconds"`
	AcceptedAt               time.Time `json:"accepted_at"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is safe for concurrent use: the coordinator shares one validator across every node session goroutine.

func NewValidator

func NewValidator(schemasDir string) (*Validator, error)

func (*Validator) MarshalAndValidate

func (v *Validator) MarshalAndValidate(envelope Envelope) ([]byte, error)

func (*Validator) ValidateEnvelope

func (v *Validator) ValidateEnvelope(data []byte) (Envelope, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL