apps/node 중심 구현 — TCP+JSON transport, Hexagonal Architecture, mock/cli adapter, fx DI, SQLite 실행 이력 저장. edge/control-plane/worker는 cobra placeholder. 유닛 테스트 및 통합 테스트 클라이언트 계획서 추가.
92 lines
3.2 KiB
Go
92 lines
3.2 KiB
Go
// Package protocol defines the IOP wire-level message types.
|
|
// The transport layer uses 4-byte big-endian length-prefixed frames.
|
|
// Each frame carries a JSON-encoded Envelope; Envelope.Payload holds
|
|
// the JSON-encoded inner message (RunRequest, RunEvent, etc.).
|
|
//
|
|
// TODO: replace JSON encoding with protobuf once proto/iop/runtime.proto
|
|
// is compiled with protoc-gen-go.
|
|
package protocol
|
|
|
|
const ProtocolVersion uint32 = 1
|
|
|
|
type MessageType string
|
|
|
|
const (
|
|
TypeRunRequest MessageType = "run.request"
|
|
TypeRunEvent MessageType = "run.event"
|
|
TypeHeartbeat MessageType = "heartbeat"
|
|
TypeCancelRequest MessageType = "cancel.request"
|
|
TypeError MessageType = "error"
|
|
TypeCapabilityRequest MessageType = "capability.request"
|
|
TypeCapabilityResponse MessageType = "capability.response"
|
|
)
|
|
|
|
// Envelope is the outer wrapper for every IOP TCP message.
|
|
type Envelope struct {
|
|
ProtocolVersion uint32 `json:"protocol_version"`
|
|
RequestID string `json:"request_id"`
|
|
RunID string `json:"run_id,omitempty"`
|
|
StreamID string `json:"stream_id,omitempty"`
|
|
Type MessageType `json:"type"`
|
|
Payload []byte `json:"payload"`
|
|
}
|
|
|
|
// RunRequest initiates a model execution on the node.
|
|
type RunRequest struct {
|
|
RunID string `json:"run_id"`
|
|
Adapter string `json:"adapter,omitempty"`
|
|
Model string `json:"model,omitempty"`
|
|
Workspace string `json:"workspace,omitempty"`
|
|
Policy map[string]any `json:"policy,omitempty"`
|
|
Input map[string]any `json:"input"`
|
|
TimeoutSec int `json:"timeout_sec,omitempty"`
|
|
Metadata map[string]string `json:"metadata,omitempty"`
|
|
}
|
|
|
|
// RunEvent is a streaming execution event sent from node to client.
|
|
type RunEvent struct {
|
|
RunID string `json:"run_id"`
|
|
Type string `json:"type"` // start | delta | complete | error
|
|
Delta string `json:"delta,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Usage *UsageInfo `json:"usage,omitempty"`
|
|
Metadata map[string]string `json:"metadata,omitempty"`
|
|
Timestamp int64 `json:"timestamp"` // unix nano
|
|
}
|
|
|
|
type UsageInfo struct {
|
|
InputTokens int `json:"input_tokens"`
|
|
OutputTokens int `json:"output_tokens"`
|
|
}
|
|
|
|
// Heartbeat keeps the TCP connection alive.
|
|
type Heartbeat struct {
|
|
Timestamp int64 `json:"timestamp"`
|
|
}
|
|
|
|
// CancelRequest asks the node to cancel a running execution.
|
|
type CancelRequest struct {
|
|
RunID string `json:"run_id"`
|
|
}
|
|
|
|
// ErrorMsg is returned when a request fails at the transport layer.
|
|
type ErrorMsg struct {
|
|
Code string `json:"code"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// CapabilityRequest asks the node what adapters/models it supports.
|
|
type CapabilityRequest struct{}
|
|
|
|
// CapabilityResponse lists the node's available adapters.
|
|
type CapabilityResponse struct {
|
|
NodeID string `json:"node_id"`
|
|
Adapters []AdapterInfo `json:"adapters"`
|
|
}
|
|
|
|
type AdapterInfo struct {
|
|
Name string `json:"name"`
|
|
Models []string `json:"models"`
|
|
MaxConcurrency int `json:"max_concurrency"`
|
|
}
|