Documentation
¶
Overview ¶
Package ops tracks long-running MCP tool invocations so a local portal can list and cancel them. It is intentionally process-local: each LabLinkServer process keeps its own registry.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Event ¶
type Event struct {
Kind string `json:"kind"` // "started" | "progress" | "finished"
Op *Operation `json:"op"`
}
Event is a change notification published over the bus.
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is returned by Begin and used by the caller to mark completion.
func (*Handle) Done ¶
Done records terminal status. err==nil → succeeded; err set and the op was portal-cancelled → cancelled; otherwise → failed. The wrapped context is also cancelled to release any descendant work.
func (*Handle) Progress ¶ added in v0.4.1
Progress publishes a liveness/progress update for the operation. It is a no-op on a nil or noop handle, and on a finished operation. bytesTotal may be 0 when the total size is unknown. Intended for long-running streaming tools (push_file, pull_file, …) so MCP clients that honor "tool is alive" signals don't kill the call mid-transfer.
type Operation ¶
type Operation struct {
ID string `json:"id"`
Tool string `json:"tool"`
Node string `json:"node,omitempty"`
Summary string `json:"summary,omitempty"`
Args map[string]string `json:"args,omitempty"`
StartedAt time.Time `json:"started_at"`
FinishedAt *time.Time `json:"finished_at,omitempty"`
Status Status `json:"status"`
Error string `json:"error,omitempty"`
// Progress is an optional periodic liveness signal published by
// long-running streaming tools (push_file, pull_file, …). BytesTotal
// may be 0 when the total is not yet known. ProgressAt is the most
// recent update time. Updated via Handle.Progress.
BytesDone int64 `json:"bytes_done,omitempty"`
BytesTotal int64 `json:"bytes_total,omitempty"`
ProgressAt *time.Time `json:"progress_at,omitempty"`
// contains filtered or unexported fields
}
Operation is a single in-flight or recently-completed tool invocation.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry tracks operations and fans out change events to subscribers.
func NewRegistry ¶
NewRegistry constructs a Registry. maxHistory is the number of completed operations retained for display; 0 means unlimited.
func (*Registry) Begin ¶
func (r *Registry) Begin(parent context.Context, tool, node, summary string, args map[string]string) (context.Context, *Handle)
Begin records a new operation and returns a wrapped context whose cancellation can be triggered either by the caller or by the portal (Cancel by ID). Done must be called on the returned Handle when the work completes.
func (*Registry) Cancel ¶
Cancel marks the operation as cancelled-by-portal and triggers its context cancel. Returns false if the id is unknown or already finished.