Documentation
¶
Overview ¶
Package e2b provides an e2b client for pegwings-go.
Index ¶
- type APIError
- type ErrMissingRequiredArgument
- type ErrToolArgument
- type ErrToolNotFound
- type Event
- type EventParams
- type EventResult
- type LsResult
- type Method
- type Option
- func WithBaseURL(baseURL string) Option
- func WithClient(client *http.Client) Option
- func WithCwd(cwd string) Option
- func WithLogger(logger *slog.Logger) Option
- func WithMetaData(metaData map[string]string) Option
- func WithTemplate(template SandboxTemplate) Option
- func WithWsURL(wsURL func(s *Sandbox) string) Option
- type Params
- type Process
- func (p *Process) Done() <-chan struct{}
- func (p *Process) Start(ctx context.Context) (err error)
- func (p *Process) SubscribeExit(ctx context.Context) (chan Event, chan error)
- func (p *Process) SubscribeStderr(ctx context.Context) (chan Event, chan error)
- func (p *Process) SubscribeStdout(ctx context.Context) (chan Event, chan error)
- type ProcessEvents
- type ProcessOption
- type Request
- type Response
- type Sandbox
- func (s *Sandbox) GetTools() []tools.Tool
- func (s *Sandbox) KeepAlive(ctx context.Context, timeout time.Duration) error
- func (s *Sandbox) Ls(ctx context.Context, path string) ([]LsResult, error)
- func (s *Sandbox) Mkdir(ctx context.Context, path string) error
- func (s *Sandbox) NewProcess(cmd string, opts ...ProcessOption) (*Process, error)
- func (s *Sandbox) Read(ctx context.Context, path string) (string, error)
- func (s *Sandbox) ReadBytes(ctx context.Context, path string) ([]byte, error)
- func (s *Sandbox) Reconnect(ctx context.Context) (err error)
- func (s *Sandbox) RunTooling(ctx context.Context, response pegwings.ChatCompletionResponse) ([]pegwings.ChatCompletionMessage, error)
- func (s *Sandbox) Stop(ctx context.Context) error
- func (s *Sandbox) Watch(ctx context.Context, path string, eCh chan<- Event) error
- func (s *Sandbox) Write(ctx context.Context, path string, data []byte) error
- type SandboxTemplate
- type SbFn
- type ToolingWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
Code int `json:"code,omitempty"` // Code is the code of the error.
Message string `json:"message"` // Message is the message of the error.
}
APIError is the error of the API.
type ErrMissingRequiredArgument ¶
ErrMissingRequiredArgument is returned when a required argument is missing.
func (ErrMissingRequiredArgument) Error ¶
func (e ErrMissingRequiredArgument) Error() string
Error implements the error interface for ErrMissingRequiredArgument.
type ErrToolArgument ¶
ErrToolArgument is returned when an argument is invalid.
func (ErrToolArgument) Error ¶
func (e ErrToolArgument) Error() string
Error implements the error interface for ErrToolArgument.
type ErrToolNotFound ¶
type ErrToolNotFound struct {
ToolName string
}
ErrToolNotFound is returned when a tool is not found.
func (ErrToolNotFound) Error ¶
func (e ErrToolNotFound) Error() string
Error implements the error interface for ErrToolNotFound.
type Event ¶
type Event struct {
Path string `json:"path"` // Path is the path of the event.
Name string `json:"name"` // Name is the name of file or directory.
Timestamp int64 `json:"timestamp"` // Timestamp is the timestamp of the event.
Error string `json:"error"` // Error is the possible error of the event.
Params EventParams `json:"params"` // Params is the parameters of the event.
}
Event is a file system event.
type EventParams ¶
type EventParams struct {
Subscription string `json:"subscription"` // Subscription is the subscription id of the event.
Result EventResult `json:"result"` // Result is the result of the event.
}
EventParams is the params for subscribing to a process event.
type EventResult ¶
type EventResult struct {
Type string `json:"type"`
Line string `json:"line"`
Timestamp int64 `json:"timestamp"`
IsDirectory bool `json:"isDirectory"`
Error string `json:"error"`
}
EventResult is a file system event response.
type LsResult ¶
type LsResult struct {
Name string `json:"name"` // Name is the name of the file or directory.
IsDir bool `json:"isDir"` // isDir is true if the entry is a directory.
}
LsResult is a result of the list request.
type Option ¶
type Option func(*Sandbox)
Option is an option for the sandbox.
func WithBaseURL ¶
WithBaseURL sets the base URL for the e2b sandbox.
func WithClient ¶
WithClient sets the client for the e2b sandbox.
func WithLogger ¶
WithLogger sets the logger for the e2b sandbox.
func WithMetaData ¶
WithMetaData sets the meta data for the e2b sandbox.
func WithTemplate ¶
func WithTemplate(template SandboxTemplate) Option
WithTemplate sets the template for the e2b sandbox.
type Params ¶
type Params struct {
Path string `json:"path"`
Data string `json:"data"`
Cmd string `json:"cmd"`
Timeout int `json:"timeout"`
Cwd string `json:"cwd"`
Name string `json:"name"`
}
Params are the parameters for any function call.
type Process ¶
type Process struct {
Cwd string // cwd is process's current working directory.
Env map[string]string // env is process's environment variables.
// contains filtered or unexported fields
}
Process is a process in the sandbox.
func (*Process) Done ¶
func (p *Process) Done() <-chan struct{}
Done returns a channel that is closed when the process is done.
func (*Process) SubscribeExit ¶
SubscribeExit subscribes to the process's exit.
func (*Process) SubscribeStderr ¶
SubscribeStderr subscribes to the process's stderr.
type ProcessEvents ¶
type ProcessEvents string
ProcessEvents is a process event type. string
const ( OnStdout ProcessEvents = "onStdout" // OnStdout is the event for the stdout. OnStderr ProcessEvents = "onStderr" // OnStderr is the event for the stderr. OnExit ProcessEvents = "onExit" // OnExit is the event for the exit. )
type ProcessOption ¶
type ProcessOption func(*Process)
ProcessOption is an option for the process.
func ProcessWithCwd ¶
func ProcessWithCwd(cwd string) ProcessOption
ProcessWithCwd sets the current working directory for the process.
func ProcessWithEnv ¶
func ProcessWithEnv(env map[string]string) ProcessOption
ProcessWithEnv sets the environment variables for the process.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"` // JSONRPC is the JSON-RPC version of the request.
Method Method `json:"method"` // Method is the request method.
ID int `json:"id"` // ID of the request.
Params []any `json:"params"` // Params of the request.
}
Request is a JSON-RPC request.
type Response ¶
type Response[T any, Q any] struct { ID int `json:"id"` // ID of the response. Result T `json:"result"` // Result of the response. Error Q `json:"error"` // Error of the message. }
Response is a JSON-RPC response.
type Sandbox ¶
type Sandbox struct {
ID string `json:"sandboxID"` // ID of the sandbox.
ClientID string `json:"clientID"` // ClientID of the sandbox.
Cwd string `json:"cwd"` // Cwd is the sandbox's current working directory.
Template SandboxTemplate `json:"templateID"` // Template of the sandbox.
Metadata map[string]string `json:"metadata"` // Metadata of the sandbox.
Map *sync.Map `json:"-"` // Map is the map of the sandbox.
// contains filtered or unexported fields
}
Sandbox is a code sandbox.
The sandbox is like an isolated, but interactive system.
func NewSandbox ¶
NewSandbox creates a new sandbox.
func (*Sandbox) Ls ¶
Ls lists the files and/or directories in the sandbox file system at the given path.
func (*Sandbox) NewProcess ¶
func (s *Sandbox) NewProcess( cmd string, opts ...ProcessOption, ) (*Process, error)
NewProcess creates a new process startable in the sandbox.
func (*Sandbox) RunTooling ¶
func (s *Sandbox) RunTooling( ctx context.Context, response pegwings.ChatCompletionResponse, ) ([]pegwings.ChatCompletionMessage, error)
RunTooling runs the toolcalls in the response.
type SbFn ¶
type SbFn func(ctx context.Context, s *Sandbox, params *Params) (pegwings.ChatCompletionMessage, error)
SbFn is a function that can be used to run a tool.
type ToolingWrapper ¶
ToolingWrapper is a wrapper for tools.Tool that allows for custom functions working with a sandbox.