{"modulePath":"github.com/MiniMax-AI/OpenAgentCore","version":"v0.0.14","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package dispatch\n\nPackage dispatch wires inbound WebSocket frames to the agent layer. It owns one Turn per active RunID and a per-Turn output goroutine that forwards the agent's events to the transport.\n\nConcurrency: Handle is safe for one goroutine (typically the read loop). Each session runs its own goroutine. Internal state is mutex-protected.\n\n## Variables\n\n```go\nvar ErrRouterBusy = errors.New(\"dispatch: router has unsettled work\")\n```\n\n```go\nvar ErrRouterClosed = errors.New(\"dispatch: router closed\")\n```\n\n```go\nvar ErrRouterQuiesced = errors.New(\"dispatch: router quiesced\")\n```\nErrRouterQuiesced also wraps failed quiesce attempts that have fenced admission.\n\n## Types\n\n```go\ntype Config struct {\n\tRegistry           *agent.Registry\n\tSender             Sender\n\tLog                *slog.Logger\n\tIdleTimeout        time.Duration\n\tPreparationTimeout time.Duration\n\tLocalWorkspace     *localworkspace.Binding\n}\n```\nConfig is the constructor input. Registry and Sender are required; Log is optional (defaults to slog.Default()).\n\n```go\ntype Router struct {\n\t// contains filtered or unexported fields\n}\n```\nRouter maps inbound Envelopes to agent sessions.\n\n```go\nfunc New(cfg Config) (*Router, error)\n```\nNew returns a Router ready to Handle inbound frames.\n\n```go\nfunc (r *Router) ActiveRuns() int\n```\nActiveRuns returns the in-flight run count. Wired into the heartbeat payload supplier.\n\n```go\nfunc (r *Router) Handle(ctx context.Context, env proto.Envelope) error\n```\nHandle dispatches one inbound Envelope. Errors are returned for programmer-visible problems (bad shape, registry miss); transient session-level failures are logged and swallowed.\n\nAdopts env.Trace into ctx so every downstream log under it inherits the same trace\\_id, making a single grep cover both sides.\n\n```go\nfunc (r *Router) Quiesce(ctx context.Context, request proto.EnvironmentSuspendPayload) error\n```\nQuiesce serializes against admission, then drains every admitted output and receipt while retaining settled idle Executors for suspension. Busy rejection leaves admission open; a drain timeout keeps it closed until the caller shuts the connection down.\n\n```go\nfunc (r *Router) Resume(request proto.EnvironmentSuspendPayload, sender Sender) error\n```\nResume opens admission only after the caller authenticated a new connection and Core confirmed the exact suspension identity on that connection.\n\n```go\nfunc (r *Router) Shutdown(ctx context.Context) error\n```\nShutdown stops admission and waits for owned cleanup. A later call retries only failed cleanup; caller timeouts never abandon or duplicate in-flight work.\n\n```go\ntype Sender interface {\n\tSend(ctx context.Context, env proto.Envelope) error\n}\n```\nSender is the subset of transport.Conn the dispatcher needs. Tests supply a fake; production wires this to \\*transport.Conn.Send.\n\n","path":"github.com/MiniMax-AI/OpenAgentCore/apps/daemon/internal/dispatch","name":"dispatch","synopsis":"Package dispatch wires inbound WebSocket frames to the agent layer.","isRedistributable":true}
