Documentation
¶
Overview ¶
Package bridge provides a gRPC client for the workspace container bridge service. Each bot container runs a gRPC server listening on a Unix domain socket. This client wraps the generated gRPC stubs with connection pooling and a simplified API for callers.
Index ¶
- Constants
- Variables
- func WithWorkspaceTarget(ctx context.Context, targetID string) context.Context
- func WorkspaceTargetFromContext(ctx context.Context) string
- type Client
- func (c *Client) Close() error
- func (c *Client) DeleteFile(ctx context.Context, path string, recursive bool) error
- func (c *Client) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (c *Client) Exec(ctx context.Context, command, workDir string, timeout int32) (*ExecResult, error)
- func (c *Client) ExecStream(ctx context.Context, command, workDir string, timeout int32) (*ExecStream, error)
- func (c *Client) ExecStreamPTY(ctx context.Context, command, workDir string, cols, rows uint32) (*ExecStream, error)
- func (c *Client) ExecStreamPTYWithOptions(ctx context.Context, command, workDir string, cols, rows uint32, ...) (*ExecStream, error)
- func (c *Client) ExecStreamWithEnv(ctx context.Context, command, workDir string, timeout int32, env []string) (*ExecStream, error)
- func (c *Client) ExecStreamWithOptions(ctx context.Context, command, workDir string, timeout int32, opts ExecOptions) (*ExecStream, error)
- func (c *Client) ExecWithEnv(ctx context.Context, command, workDir string, timeout int32, env []string) (*ExecResult, error)
- func (c *Client) ExecWithOptions(ctx context.Context, command, workDir string, timeout int32, stdinData []byte, ...) (*ExecResult, error)
- func (c *Client) ExecWithStdin(ctx context.Context, command, workDir string, timeout int32, stdinData []byte) (*ExecResult, error)
- func (c *Client) ExecWithStdinEnv(ctx context.Context, command, workDir string, timeout int32, stdinData []byte, ...) (*ExecResult, error)
- func (c *Client) ListDir(ctx context.Context, path string, recursive bool, ...) (*ListDirResult, error)
- func (c *Client) ListDirAll(ctx context.Context, path string, recursive bool) ([]*pb.FileEntry, error)
- func (c *Client) ListDirBounded(ctx context.Context, path string, recursive bool, maxEntries int32) ([]*pb.FileEntry, error)
- func (c *Client) Mkdir(ctx context.Context, path string) error
- func (c *Client) ReadFile(ctx context.Context, path string, lineOffset, nLines int32) (*pb.ReadFileResponse, error)
- func (c *Client) ReadRaw(ctx context.Context, path string) (io.ReadCloser, error)
- func (c *Client) Rename(ctx context.Context, oldPath, newPath string) error
- func (c *Client) ServeReverseHTTP(ctx context.Context, handler http.Handler) (func(), error)
- func (c *Client) ServeReverseHTTPRoute(ctx context.Context, route string, handler http.Handler) (func(), error)
- func (c *Client) Stat(ctx context.Context, path string) (*pb.FileEntry, error)
- func (c *Client) WithOutgoingMetadata(values map[string]string) *Client
- func (c *Client) WriteFile(ctx context.Context, path string, content []byte) error
- func (c *Client) WriteRaw(ctx context.Context, path string, r io.Reader) (int64, error)
- type ExecOptions
- type ExecResult
- type ExecStream
- type ListDirResult
- type Pool
- type Provider
- type TLSOptions
- type WorkspaceInfo
- type WorkspaceInfoProvider
Constants ¶
const ( WorkspaceBackendContainer = "container" WorkspaceBackendRemote = "remote" ToolsProxyAddr = "127.0.0.1:18732" ToolsProxyHTTPURL = "http://" + ToolsProxyAddr + "/mcp" )
Variables ¶
Functions ¶
func WithWorkspaceTarget ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps a gRPC connection to a single MCP container.
func Dial ¶
Dial creates a new Client connected to the given gRPC target. For UDS use "unix:///path/to/sock", for TCP use "host:port".
func DialTLS ¶
DialTLS dials with optional mTLS. A nil TLS config or UDS target uses the local trust model; TCP targets use strict mTLS when configured.
func NewClientFromConn ¶
func NewClientFromConn(conn *grpc.ClientConn) *Client
NewClientFromConn wraps an existing gRPC connection into a Client. Intended for testing with in-process transports such as bufconn.
func (*Client) DeleteFile ¶
func (*Client) DialContext ¶
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, command, workDir string, timeout int32) (*ExecResult, error)
Exec runs a command and collects all output. For streaming, use ExecStream.
func (*Client) ExecStream ¶
func (c *Client) ExecStream(ctx context.Context, command, workDir string, timeout int32) (*ExecStream, error)
ExecStream returns a bidirectional stream for interactive exec. Caller can send stdin data and receive stdout/stderr in real-time.
func (*Client) ExecStreamPTY ¶
func (c *Client) ExecStreamPTY(ctx context.Context, command, workDir string, cols, rows uint32) (*ExecStream, error)
ExecStreamPTY opens a bidirectional PTY exec stream. The command runs inside a pseudo-terminal with the given initial size.
func (*Client) ExecStreamPTYWithOptions ¶
func (c *Client) ExecStreamPTYWithOptions(ctx context.Context, command, workDir string, cols, rows uint32, opts ExecOptions) (*ExecStream, error)
func (*Client) ExecStreamWithEnv ¶
func (c *Client) ExecStreamWithEnv(ctx context.Context, command, workDir string, timeout int32, env []string) (*ExecStream, error)
ExecStreamWithEnv returns a bidirectional exec stream with additional env.
func (*Client) ExecStreamWithOptions ¶
func (c *Client) ExecStreamWithOptions(ctx context.Context, command, workDir string, timeout int32, opts ExecOptions) (*ExecStream, error)
ExecStreamWithOptions returns a bidirectional exec stream with environment controls.
func (*Client) ExecWithEnv ¶
func (c *Client) ExecWithEnv(ctx context.Context, command, workDir string, timeout int32, env []string) (*ExecResult, error)
ExecWithEnv runs a command with additional environment variables.
func (*Client) ExecWithOptions ¶
func (c *Client) ExecWithOptions(ctx context.Context, command, workDir string, timeout int32, stdinData []byte, opts ExecOptions) (*ExecResult, error)
func (*Client) ExecWithStdin ¶
func (c *Client) ExecWithStdin(ctx context.Context, command, workDir string, timeout int32, stdinData []byte) (*ExecResult, error)
ExecWithStdin runs a command with optional stdin data.
func (*Client) ExecWithStdinEnv ¶
func (c *Client) ExecWithStdinEnv(ctx context.Context, command, workDir string, timeout int32, stdinData []byte, env []string) (*ExecResult, error)
ExecWithStdinEnv runs a command with optional stdin data and additional environment variables.
func (*Client) ListDirAll ¶
func (c *Client) ListDirAll(ctx context.Context, path string, recursive bool) ([]*pb.FileEntry, error)
ListDirAll lists all entries without pagination (offset=0, limit=0, no collapsing).
func (*Client) ListDirBounded ¶
func (c *Client) ListDirBounded(ctx context.Context, path string, recursive bool, maxEntries int32) ([]*pb.FileEntry, error)
ListDirBounded lists at most maxEntries entries. The bridge stops traversing once the bound is exceeded and fails with a resource-exhausted error, so server-side memory stays bounded before collection. Callers with a hard ceiling use this instead of judging an unbounded listing after the fact.
func (*Client) ServeReverseHTTP ¶
func (*Client) ServeReverseHTTPRoute ¶
func (*Client) WithOutgoingMetadata ¶
WithOutgoingMetadata returns a non-owning view of the same gRPC connection. Every unary and streaming RPC sent through the view carries the supplied metadata. Closing the view is intentionally a no-op: the root client owns the device connection and may be shared by multiple Bot workspaces.
type ExecOptions ¶
ExecOptions controls how a workspace command is launched.
Env entries are KEY=value overrides. By default the bridge preserves its process environment and appends Env, matching the historical ExecWithEnv behavior. CleanEnv starts from an empty environment instead. UnsetEnv scrubs inherited environment keys before Env is appended, so explicit Env entries remain authoritative.
type ExecResult ¶
ExecResult holds the output of a non-streaming exec call.
type ExecStream ¶
type ExecStream struct {
// contains filtered or unexported fields
}
ExecStream wraps a bidirectional exec stream.
func (*ExecStream) CloseSend ¶ added in v0.20.0
func (s *ExecStream) CloseSend() error
CloseSend half-closes the send side so the process sees stdin EOF while its output keeps streaming. Close() cancels the stream; this does not.
func (*ExecStream) Recv ¶
func (s *ExecStream) Recv() (*pb.ExecOutput, error)
Recv receives output from the process.
func (*ExecStream) Resize ¶
func (s *ExecStream) Resize(cols, rows uint32) error
Resize sends a terminal resize event to the running process.
func (*ExecStream) SendStdin ¶
func (s *ExecStream) SendStdin(data []byte) error
SendStdin sends data to the process stdin.
type ListDirResult ¶
ListDirResult holds the paginated result of a directory listing.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages cached gRPC clients keyed by bot ID.
func NewPool ¶
NewPool creates a client pool. dialTargetFunc maps bot ID to a gRPC target string (e.g. "unix:///path/sock" or "host:port").
func (*Pool) Get ¶
Get returns a cached client or dials a new one. Stale connections (Shutdown / TransientFailure / stuck Connecting) are evicted automatically.
func (*Pool) SetTLSOptions ¶
func (p *Pool) SetTLSOptions(opts *TLSOptions)
SetTLSOptions enables strict mTLS for subsequent TCP dials (UDS targets are exempt). Call once during startup, before the pool serves traffic.
type TLSOptions ¶
type TLSOptions struct {
// ServerName 是 synthetic TLS ServerName(memoh-bridge.<instance-id>.bridge.memoh.internal)。
// 连接目标是 PodIP(或 port-forward 的 localhost),证书校验必须用稳定名字
// 而不是关闭 hostname verification。
ServerName string
// ExpectedServerURI 是 bridge server cert 必须携带的 URI SAN
// (spiffe://memoh/instance/<instance-id>/bridge)。
ExpectedServerURI string
ClientCertFile string
ClientKeyFile string
// ServerCAFile 是 bridge-server CA bundle(bridge-server-ca.crt)。
ServerCAFile string
}
TLSOptions 配置 Memoh Server → bridge 的 TCP gRPC mTLS(设计 §8.2)。 nil 表示 disabled(开源/本地默认)。strict 下握手或身份校验失败一律拒绝, 不回退明文;UDS target 不论 mode 始终走本地信任模型(insecure)。
type WorkspaceInfo ¶
type WorkspaceInfoProvider ¶
type WorkspaceInfoProvider interface {
WorkspaceInfo(ctx context.Context, botID string) (WorkspaceInfo, error)
}