cmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cmd defines the commands that drive an execution. A command is a request (start, complete a task, deliver a signal, fire a timer, …) published on the execution's partition of the command stream; the engine decides which events it produces. Every command carries an id: the stream deduplicates on it (Nats-Msg-Id) and the decision is idempotent, so redelivery is harmless.

The JSON encoding is the wire protocol shared by every SDK.

Index

Constants

View Source
const (
	HeaderMsgID       = "Nats-Msg-Id"
	HeaderType        = "Pt-Cmd-Type"
	HeaderTraceparent = "traceparent"
)

Headers.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelData

type CancelData struct {
	Reason string `json:"reason,omitempty"`
}

CancelData is the payload of Cancel.

type ChildDoneData

type ChildDoneData struct {
	ChildID  string             `json:"child_id"`
	Status   string             `json:"status"`
	Output   json.RawMessage    `json:"output,omitempty"`
	Error    string             `json:"error,omitempty"`
	Counters map[string]float64 `json:"counters,omitempty"`
}

ChildDoneData is the payload of ChildDone, sent to the parent.

type Command

type Command struct {
	ID     string          `json:"id"`
	Type   Type            `json:"type"`
	ExecID string          `json:"exec_id"`
	Time   time.Time       `json:"time,omitzero"`
	Data   json.RawMessage `json:"data,omitempty"`
	// Reply, when set, is a subject the engine answers on once the command is
	// decided (stored, a no-op, or rejected): wire.Reply.
	Reply string `json:"reply,omitempty"`
}

Command is the envelope of every command.

func Decode

func Decode(body []byte) (Command, error)

Decode parses a command body and validates the envelope.

func New

func New(id string, t Type, execID string, data any) (Command, error)

New builds a command with payload data.

func (Command) Payload

func (c Command) Payload(v any) error

Payload decodes the command payload into v.

func (Command) Validate

func (c Command) Validate() error

Validate checks the envelope.

type CompleteData

type CompleteData struct {
	TaskRef

	Output   json.RawMessage            `json:"output,omitempty"`
	Writes   map[string]json.RawMessage `json:"writes,omitempty"`
	Next     string                     `json:"next,omitempty"`
	Usage    map[string]float64         `json:"usage,omitempty"`
	CacheKey string                     `json:"cache_key,omitempty"`
	Cached   bool                       `json:"cached,omitempty"`
}

CompleteData is the payload of Complete.

type FailData

type FailData struct {
	TaskRef

	Error     string             `json:"error"`
	Retryable bool               `json:"retryable"`
	Reason    string             `json:"reason,omitempty"`
	Usage     map[string]float64 `json:"usage,omitempty"`
}

FailData is the payload of Fail.

type ForkData

type ForkData struct {
	From string `json:"from"`
	Seq  uint64 `json:"seq"`
	// Writes edit the fork's channels (through their reducers) before it
	// resumes: LangGraph's update_state then continue.
	Writes map[string]json.RawMessage `json:"writes,omitempty"`
}

ForkData is the payload of Fork: create ExecID from the state of From at sequence Seq (the end of a decision).

type InterruptData

type InterruptData struct {
	TaskRef

	Payload json.RawMessage    `json:"payload,omitempty"`
	Usage   map[string]float64 `json:"usage,omitempty"`
}

InterruptData is the payload of Interrupt.

type ResumeData

type ResumeData struct {
	Node  string          `json:"node"`
	Key   string          `json:"key,omitempty"`
	Value json.RawMessage `json:"value,omitempty"`
}

ResumeData is the payload of Resume: re-run the interrupted node with Value available to the worker as `resume`.

type SignalData

type SignalData struct {
	Name    string          `json:"name"`
	Payload json.RawMessage `json:"payload,omitempty"`
}

SignalData is the payload of Signal. The command id is the signal id.

type StartData

type StartData struct {
	Flow string `json:"flow"`
	// Version pins a flow hash; empty means the latest registered version.
	Version string           `json:"version,omitempty"`
	Input   json.RawMessage  `json:"input,omitempty"`
	Parent  *event.ParentRef `json:"parent,omitempty"`
}

StartData is the payload of Start.

type TaskRef

type TaskRef struct {
	Key        string `json:"key"`
	Generation int    `json:"generation"`
	Attempt    int    `json:"attempt"`
}

TaskRef identifies one attempt of a task instance; a completion for any other attempt is stale and ignored.

type TimerData

type TimerData struct {
	TimerID string `json:"timer_id"`
}

TimerData is the payload of Timer (published by a JetStream schedule).

type Type

type Type string

Type names a command.

const (
	Start     Type = "start"
	Fork      Type = "fork"
	Complete  Type = "complete"
	Fail      Type = "fail"
	Interrupt Type = "interrupt"
	Resume    Type = "resume"
	Signal    Type = "signal"
	Cancel    Type = "cancel"
	// Update writes channels of a running execution (synchronous: the
	// command carries a reply subject).
	Update    Type = "update"
	Timer     Type = "timer"
	ChildDone Type = "child_done"
	Archive   Type = "archive"
	// Redispatch lifts the quarantine of an execution (dispatcher replay).
	Redispatch Type = "redispatch"
)

Command types.

type UpdateData

type UpdateData struct {
	Writes map[string]json.RawMessage `json:"writes"`
}

UpdateData is the payload of Update. The command id is the update id: an update is applied once, however often it is delivered.

Jump to

Keyboard shortcuts

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