process

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager spawns a tool process, communicates via protobuf over a unix socket, and handles handshake, tool calls, reload, and crash detection.

func NewManager

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a new process manager with the given configuration.

func NewManagerForTest

func NewManagerForTest(cfg ManagerConfig, conn net.Conn) *Manager

NewManagerForTest creates a Manager with a pre-established connection.

func (*Manager) CallTool

func (m *Manager) CallTool(ctx context.Context, name, argsJSON string) (*pb.CallToolResponse, error)

CallTool sends a CallToolRequest and waits for the matching CallToolResponse.

func (*Manager) CallToolStream

func (m *Manager) CallToolStream(ctx context.Context, name, argsJSON string) (<-chan StreamEvent, error)

CallToolStream sends a CallToolRequest and returns a channel that receives stream events. If the tool responds with a single (non-chunked) message, the channel receives one StreamEvent with Result set. If the tool streams, it receives a Header event followed by Chunk events.

func (*Manager) Complete

func (m *Manager) Complete(ctx context.Context, refType, refName, argName, argValue string) (*pb.CompletionResponse, error)

Complete sends a CompletionRequest and waits for the matching CompletionResponse.

func (*Manager) GetPrompt

func (m *Manager) GetPrompt(ctx context.Context, name, argsJSON string) (*pb.GetPromptResponse, error)

GetPrompt sends a GetPromptRequest and waits for the matching GetPromptResponse.

func (*Manager) ListPrompts

func (m *Manager) ListPrompts(ctx context.Context) ([]*pb.PromptDefinition, error)

ListPrompts sends a ListPromptsRequest and waits for the matching PromptListResponse.

func (*Manager) ListResourceTemplates

func (m *Manager) ListResourceTemplates(ctx context.Context) ([]*pb.ResourceTemplateDefinition, error)

ListResourceTemplates sends a ListResourceTemplatesRequest and waits for the matching ResourceTemplateListResponse.

func (*Manager) ListResources

func (m *Manager) ListResources(ctx context.Context) ([]*pb.ResourceDefinition, error)

ListResources sends a ListResourcesRequest and waits for the matching ResourceListResponse.

func (*Manager) Middlewares

func (m *Manager) Middlewares() []RegisteredMiddleware

Middlewares returns the list of middleware registered during handshake.

func (*Manager) OnCrash

func (m *Manager) OnCrash() <-chan error

OnCrash returns a channel that receives an error when the child process exits unexpectedly.

func (*Manager) OnDisableTools

func (m *Manager) OnDisableTools(fn func([]string))

OnDisableTools sets a callback for disable-tools requests from the tool process.

func (*Manager) OnEnableTools

func (m *Manager) OnEnableTools(fn func([]string))

OnEnableTools sets a callback for enable-tools requests from the tool process.

func (*Manager) OnListRoots

func (m *Manager) OnListRoots(fn func(string))

OnListRoots sets a callback for list-roots requests from the SDK process.

func (*Manager) OnLog

func (m *Manager) OnLog(fn func(*pb.LogMessage))

OnLog sets a callback for log messages from the tool process.

func (*Manager) OnProgress

func (m *Manager) OnProgress(fn func(*pb.ProgressNotification))

OnProgress sets a callback for progress notifications from the tool process.

func (*Manager) OnSampling

func (m *Manager) OnSampling(fn func(*pb.SamplingRequest, string))

OnSampling sets a callback for sampling requests from the SDK process.

func (*Manager) ReadResource

func (m *Manager) ReadResource(ctx context.Context, uri string) (*pb.ReadResourceResponse, error)

ReadResource sends a ReadResourceRequest and waits for the matching ReadResourceResponse.

func (*Manager) RegisterPending

func (m *Manager) RegisterPending(reqID string) chan *pb.Envelope

RegisterPending registers a pending request channel and returns it.

func (*Manager) Reload

func (m *Manager) Reload(ctx context.Context) ([]*pb.ToolDefinition, error)

Reload sends a ReloadRequest, waits for ReloadResponse, then receives the updated ToolListResponse.

func (*Manager) SendListRootsResponse

func (m *Manager) SendListRootsResponse(reqID string, resp *pb.ListRootsResponse) error

SendListRootsResponse sends a ListRootsResponse back to the SDK process.

func (*Manager) SendMiddlewareIntercept

func (m *Manager) SendMiddlewareIntercept(ctx context.Context, mwName, phase, toolName, argsJSON, resultJSON string, isError bool) (*pb.MiddlewareInterceptResponse, error)

SendMiddlewareIntercept sends a middleware intercept request and waits for the response.

func (*Manager) SendSamplingResponse

func (m *Manager) SendSamplingResponse(reqID string, resp *pb.SamplingResponse) error

SendSamplingResponse sends a SamplingResponse back to the SDK process.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) ([]*pb.ToolDefinition, error)

Start spawns the child process, performs the handshake (ListToolsRequest), and returns the list of tools the process provides.

func (*Manager) StartReadLoop

func (m *Manager) StartReadLoop()

StartReadLoop starts the readLoop (blocking).

func (*Manager) Stop

func (m *Manager) Stop()

Stop kills the child process and cleans up resources.

func (*Manager) Tools

func (m *Manager) Tools() []*pb.ToolDefinition

Tools returns the current list of tool definitions.

type ManagerConfig

type ManagerConfig struct {
	File        string
	RuntimeCmd  string
	RuntimeArgs []string
	SocketPath  string
	MaxRetries  int
	CallTimeout time.Duration
}

ManagerConfig configures how the process manager spawns and communicates with a tool process.

type RegisteredMiddleware

type RegisteredMiddleware struct {
	Name     string
	Priority int32
}

RegisteredMiddleware represents a middleware registered by the tool process during handshake.

type StreamEvent

type StreamEvent struct {
	// Header is set for the first event (stream start).
	Header *pb.StreamHeader
	// Chunk is set for data events.
	Chunk []byte
	// Final is true when this is the last chunk.
	Final bool
	// Result is set when the tool returns a non-streamed response
	// (payload was below threshold).
	Result *pb.CallToolResponse
}

StreamEvent represents one event in a chunked tool call response.

Jump to

Keyboard shortcuts

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