protocol

package
v0.0.0-...-311e34c Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package protocol defines the WebSocket message protocol between Runner and Flashduty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BashArgs

type BashArgs struct {
	Command string `json:"command"`
	Workdir string `json:"workdir,omitempty"`
	Timeout int    `json:"timeout,omitempty"` // seconds
}

BashArgs are the arguments for bash operation.

type BashResult

type BashResult struct {
	Stdout    string `json:"stdout"`
	Stderr    string `json:"stderr"`
	ExitCode  int    `json:"exit_code"`
	Truncated bool   `json:"truncated,omitempty"`  // Whether content was truncated
	FilePath  string `json:"file_path,omitempty"`  // Path to full content if truncated
	TotalSize int64  `json:"total_size,omitempty"` // Original content size
}

BashResult is the result of a bash operation.

type EnvironmentInfo

type EnvironmentInfo struct {
	OS            string `json:"os"`              // e.g., "darwin", "linux", "windows"
	OSVersion     string `json:"os_version"`      // e.g., "24.6.0" for macOS
	Arch          string `json:"arch"`            // e.g., "amd64", "arm64"
	Hostname      string `json:"hostname"`        // Machine hostname
	Shell         string `json:"shell"`           // Default shell, e.g., "/bin/zsh"
	HomeDir       string `json:"home_dir"`        // User home directory
	WorkspaceRoot string `json:"workspace_root"`  // Configured workspace root
	Username      string `json:"username"`        // Current user
	NumCPU        int    `json:"num_cpu"`         // Number of CPUs
	TotalMemoryMB int64  `json:"total_memory_mb"` // Total memory in MB
	CurrentTime   string `json:"current_time"`    // Current time in RFC3339 format
	Timezone      string `json:"timezone"`        // Timezone name, e.g., "Asia/Shanghai"
	UTCOffset     string `json:"utc_offset"`      // UTC offset, e.g., "+08:00"
}

EnvironmentInfo contains detailed environment information for LLM context. This is similar to Cursor's system reminder format.

type GlobArgs

type GlobArgs struct {
	Pattern string `json:"pattern"`
}

GlobArgs are the arguments for glob operation.

type GlobResult

type GlobResult struct {
	Matches []string `json:"matches"`
}

GlobResult is the result of a glob operation.

type GrepArgs

type GrepArgs struct {
	Pattern string   `json:"pattern"`
	Include []string `json:"include,omitempty"`
}

GrepArgs are the arguments for grep operation.

type GrepMatch

type GrepMatch struct {
	Path       string `json:"path"`
	LineNumber int    `json:"line_number"`
	Content    string `json:"content"`
}

GrepMatch is a single match in a grep result.

type GrepResult

type GrepResult struct {
	Matches   []GrepMatch `json:"matches"`
	Content   string      `json:"content"`              // Formatted content (may be truncated)
	Truncated bool        `json:"truncated,omitempty"`  // Whether content was truncated
	FilePath  string      `json:"file_path,omitempty"`  // Path to full content if truncated
	TotalSize int64       `json:"total_size,omitempty"` // Original content size
}

GrepResult is the result of a grep operation.

type HeartbeatMetrics

type HeartbeatMetrics struct {
	CPUPercent    float64 `json:"cpu_percent,omitempty"`
	MemoryPercent float64 `json:"memory_percent,omitempty"`
	DiskPercent   float64 `json:"disk_percent,omitempty"`
}

HeartbeatMetrics contains system metrics.

type HeartbeatPayload

type HeartbeatPayload struct {
	WorknodeID  string            `json:"worknode_id"`
	Name        string            `json:"name"`
	Labels      []string          `json:"labels"`
	Version     string            `json:"version"`
	Environment *EnvironmentInfo  `json:"environment,omitempty"`
	Metrics     *HeartbeatMetrics `json:"metrics,omitempty"`
}

HeartbeatPayload is the payload for heartbeat messages.

type ListArgs

type ListArgs struct {
	Path      string   `json:"path"`
	Recursive bool     `json:"recursive,omitempty"`
	Ignore    []string `json:"ignore,omitempty"`
}

ListArgs are the arguments for list operation.

type ListEntry

type ListEntry struct {
	Path  string `json:"path"`
	IsDir bool   `json:"is_dir"`
	Size  int64  `json:"size"`
}

ListEntry is a single entry in a list result.

type ListResult

type ListResult struct {
	Entries []ListEntry `json:"entries"`
}

ListResult is the result of a list operation.

type MCPCallArgs

type MCPCallArgs struct {
	Server   MCPServerConfig `json:"server"`
	ToolName string          `json:"tool_name"`
	Args     json.RawMessage `json:"args"`
	Timeout  int             `json:"timeout,omitempty"` // seconds
}

MCPCallArgs are the arguments for mcp_call operation.

type MCPCallPayload

type MCPCallPayload struct {
	CallID    string          `json:"call_id"`
	Server    MCPServerConfig `json:"server"`
	ToolName  string          `json:"tool_name"`
	Arguments json.RawMessage `json:"arguments"`
}

MCPCallPayload is the payload for MCP tool calls. Server configuration is passed from cloud (stored in database).

type MCPCallResult

type MCPCallResult struct {
	Content   string `json:"content"`
	IsError   bool   `json:"is_error,omitempty"`   // Whether the tool returned an error
	Truncated bool   `json:"truncated,omitempty"`  // Whether content was truncated
	FilePath  string `json:"file_path,omitempty"`  // Path to full content if truncated
	TotalSize int64  `json:"total_size,omitempty"` // Original content size
}

MCPCallResult is the result of an mcp_call operation.

type MCPListToolsArgs

type MCPListToolsArgs struct {
	Server MCPServerConfig `json:"server"`
}

MCPListToolsArgs are the arguments for mcp_list_tools operation.

type MCPListToolsResult

type MCPListToolsResult struct {
	Tools []MCPToolInfo `json:"tools"`
}

MCPListToolsResult is the result of an mcp_list_tools operation.

type MCPResultPayload

type MCPResultPayload struct {
	CallID  string          `json:"call_id"`
	Success bool            `json:"success"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   string          `json:"error,omitempty"`
}

MCPResultPayload is the payload for MCP call results.

type MCPServerConfig

type MCPServerConfig struct {
	Name           string            `json:"name"`
	Transport      string            `json:"transport"` // stdio, sse
	Command        string            `json:"command,omitempty"`
	Args           []string          `json:"args,omitempty"`
	Env            map[string]string `json:"env,omitempty"`
	URL            string            `json:"url,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	DynamicHeaders map[string]string `json:"dynamic_headers,omitempty"`
}

MCPServerConfig is the MCP server configuration passed from cloud.

type MCPToolInfo

type MCPToolInfo struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	InputSchema any    `json:"input_schema,omitempty"`
}

MCPToolInfo represents metadata for an MCP tool.

type Message

type Message struct {
	ID        string          `json:"id"`
	Type      MessageType     `json:"type"`
	Payload   json.RawMessage `json:"payload"`
	Timestamp int64           `json:"timestamp"`
}

Message is the base WebSocket message structure.

func NewMessage

func NewMessage(msgType MessageType, payload any) (*Message, error)

NewMessage creates a new message with the given type and payload.

type MessageType

type MessageType string

MessageType defines the type of WebSocket message.

const (
	// Flashduty -> Runner (initial)
	MessageTypeWelcome MessageType = "welcome"

	// Runner -> Flashduty
	MessageTypeHeartbeat  MessageType = "heartbeat"
	MessageTypeTaskOutput MessageType = "task.output"
	MessageTypeTaskResult MessageType = "task.result"
	MessageTypeMCPResult  MessageType = "mcp.result"

	// Flashduty -> Runner
	MessageTypeTaskRequest MessageType = "task.request"
	MessageTypeTaskCancel  MessageType = "task.cancel"
	MessageTypeMCPCall     MessageType = "mcp.call"
)

type ReadArgs

type ReadArgs struct {
	Path   string `json:"path"`
	Offset int64  `json:"offset,omitempty"`
	Limit  int64  `json:"limit,omitempty"`
}

ReadArgs are the arguments for read operation.

type ReadResult

type ReadResult struct {
	Content   string `json:"content"` // base64 encoded
	TotalSize int64  `json:"total_size"`
}

ReadResult is the result of a read operation.

type SyncSkillArgs

type SyncSkillArgs struct {
	SkillName string `json:"skill_name"`
	SkillDir  string `json:"skill_dir"`
	ZipData   string `json:"zip_data"` // base64 encoded zip
	Checksum  string `json:"checksum"`
}

SyncSkillArgs are the arguments for sync_skill operation.

type SyncSkillResult

type SyncSkillResult struct {
	Success bool   `json:"success"`
	Path    string `json:"path"` // Local path where skill was extracted
}

SyncSkillResult is the result of a sync_skill operation.

type TaskCancelPayload

type TaskCancelPayload struct {
	TaskID string `json:"task_id"`
}

TaskCancelPayload is the payload for task cancellation.

type TaskOperation

type TaskOperation string

TaskOperation defines the type of workspace operation.

const (
	TaskOpRead         TaskOperation = "read"
	TaskOpWrite        TaskOperation = "write"
	TaskOpList         TaskOperation = "list"
	TaskOpGlob         TaskOperation = "glob"
	TaskOpGrep         TaskOperation = "grep"
	TaskOpBash         TaskOperation = "bash"
	TaskOpWebFetch     TaskOperation = "webfetch"
	TaskOpMCPCall      TaskOperation = "mcp_call"
	TaskOpMCPListTools TaskOperation = "mcp_list_tools"
	TaskOpSyncSkill    TaskOperation = "sync_skill"
)

type TaskOutputPayload

type TaskOutputPayload struct {
	TaskID string `json:"task_id"`
	Stream string `json:"stream"` // stdout, stderr
	Data   string `json:"data"`
}

TaskOutputPayload is the payload for streaming task output.

type TaskRequestPayload

type TaskRequestPayload struct {
	TaskID           string          `json:"task_id"`
	TraceID          string          `json:"trace_id,omitempty"`
	SourceInstanceID string          `json:"source_instance_id,omitempty"` // Safari instance ID
	Operation        TaskOperation   `json:"operation"`
	Args             json.RawMessage `json:"args"`
}

TaskRequestPayload is the payload for task request messages.

type TaskResultPayload

type TaskResultPayload struct {
	TaskID           string          `json:"task_id"`
	SourceInstanceID string          `json:"source_instance_id,omitempty"` // Safari instance ID
	Success          bool            `json:"success"`
	Result           json.RawMessage `json:"result,omitempty"`
	Error            string          `json:"error,omitempty"`
	ExitCode         int             `json:"exit_code,omitempty"`
}

TaskResultPayload is the payload for task completion.

type WebFetchArgs

type WebFetchArgs struct {
	URL     string `json:"url"`
	Format  string `json:"format,omitempty"`  // markdown, text, html (default: markdown)
	Timeout int    `json:"timeout,omitempty"` // seconds (default: 30, max: 120)
}

WebFetchArgs are the arguments for webfetch operation.

type WebFetchResult

type WebFetchResult struct {
	Content   string `json:"content"`
	URL       string `json:"url"`                  // Final URL after redirects
	Truncated bool   `json:"truncated,omitempty"`  // Whether content was truncated
	FilePath  string `json:"file_path,omitempty"`  // Path to full content if truncated
	TotalSize int64  `json:"total_size,omitempty"` // Original content size
}

WebFetchResult is the result of a webfetch operation.

type WelcomePayload

type WelcomePayload struct {
	WorknodeID string   `json:"worknode_id"`
	Name       string   `json:"name"`
	Labels     []string `json:"labels"`
}

WelcomePayload is the payload for the welcome message sent by server after connection. Contains worknode info (name, labels) managed via Web UI.

type WriteArgs

type WriteArgs struct {
	Path    string `json:"path"`
	Content string `json:"content"` // base64 encoded
}

WriteArgs are the arguments for write operation.

Jump to

Keyboard shortcuts

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