Skip to content

Code Interpreter

Signatures and descriptions are generated from the published module's GoDoc.

go
import "github.com/abox-dev/sdk/packages/go-sdk/codeinterpreter"

Package codeinterpreter runs Python, JavaScript, and TypeScript in AgentBox.

Index

Constants

go
const (
    // DefaultTemplate is the template used when Create receives no template.
    DefaultTemplate = "code-interpreter"
    // JupyterPort is the internal Code Interpreter service port.
    JupyterPort = 49999
)

type Chart

Chart retains typed common chart properties and unknown fields in Extra.

go
type Chart struct {
    Type     ChartType                  `json:"type"`
    Title    string                     `json:"title"`
    Elements []json.RawMessage          `json:"elements"`
    XLabel   string                     `json:"x_label,omitempty"`
    YLabel   string                     `json:"y_label,omitempty"`
    XUnit    string                     `json:"x_unit,omitempty"`
    YUnit    string                     `json:"y_unit,omitempty"`
    XScale   ScaleType                  `json:"x_scale,omitempty"`
    YScale   ScaleType                  `json:"y_scale,omitempty"`
    Extra    map[string]json.RawMessage `json:"-"`
}

func (*Chart) UnmarshalJSON

go
func (chart *Chart) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes known chart fields and preserves unknown fields in Extra.

type ChartType

ChartType identifies a supported chart representation.

go
type ChartType string

go
const (
    // ChartLine identifies a line chart.
    ChartLine ChartType = "line"
    // ChartScatter identifies a scatter chart.
    ChartScatter ChartType = "scatter"
    // ChartBar identifies a bar chart.
    ChartBar ChartType = "bar"
    // ChartPie identifies a pie chart.
    ChartPie ChartType = "pie"
    // ChartBoxAndWhisker identifies a box-and-whisker chart.
    ChartBoxAndWhisker ChartType = "box_and_whisker"
    // ChartSuper identifies a composite chart.
    ChartSuper ChartType = "superchart"
    // ChartUnknown identifies a chart type unknown to this SDK version.
    ChartUnknown ChartType = "unknown"
)

type Client

Client wraps the core client with Code Interpreter creation helpers.

go
type Client struct{ Core *agentbox.Client }

func NewClient

go
func NewClient(options ...agentbox.ClientOption) (*Client, error)

NewClient creates a Code Interpreter client using the core client options.

func (*Client) Connect

go
func (client *Client) Connect(ctx context.Context, id string, options *agentbox.ConnectSandboxOptions) (*Sandbox, error)

Connect attaches to an existing Code Interpreter sandbox.

func (*Client) Create

go
func (client *Client) Create(ctx context.Context, options *agentbox.CreateSandboxOptions) (*Sandbox, error)

Create creates a Code Interpreter sandbox.

type Context

Context identifies a persistent kernel context.

go
type Context struct {
    ID       string `json:"id"`
    Language string `json:"language"`
    Cwd      string `json:"cwd"`
}

type CreateContextOptions

CreateContextOptions configures a persistent kernel context.

go
type CreateContextOptions struct {
    Language       Language      `json:"language,omitempty"`
    Cwd            string        `json:"cwd,omitempty"`
    RequestTimeout time.Duration `json:"-"`
}

type Execution

Execution contains the complete result of one code execution.

go
type Execution struct {
    Results        []Result        `json:"results"`
    Logs           Logs            `json:"logs"`
    Error          *ExecutionError `json:"error,omitempty"`
    ExecutionCount int             `json:"execution_count,omitempty"`
}

func (Execution) Text

go
func (execution Execution) Text() string

Text returns the text representation of the main result, if present.

type ExecutionError

ExecutionError is a kernel error and traceback.

go
type ExecutionError struct {
    Name      string `json:"name"`
    Value     string `json:"value"`
    Traceback string `json:"traceback"`
}

func (ExecutionError) Error

go
func (e ExecutionError) Error() string

Error formats the kernel error name and value.

type Language

Language is a Code Interpreter runtime language.

go
type Language string

go
const (
    // Python selects a Python kernel.
    Python Language = "python"
    // JavaScript selects a JavaScript kernel.
    JavaScript Language = "javascript"
    // TypeScript selects a TypeScript kernel.
    TypeScript Language = "typescript"
)

type Logs

Logs contains collected standard output and standard error lines.

go
type Logs struct {
    Stdout []string `json:"stdout"`
    Stderr []string `json:"stderr"`
}

type OutputMessage

OutputMessage is one stdout or stderr line.

go
type OutputMessage struct {
    Line      string
    Timestamp int64
    Error     bool
}

func (OutputMessage) String

go
func (message OutputMessage) String() string

String returns the output line.

type RawData

RawData preserves every MIME representation returned by the kernel.

go
type RawData map[string]json.RawMessage

type Result

Result contains the decoded and raw MIME representations of one result.

go
type Result struct {
    Text, HTML, Markdown, SVG, PNG, JPEG, PDF, LaTeX, JSON, JavaScript string
    Data                                                               map[string]any
    Chart                                                              *Chart
    Extra                                                              map[string]json.RawMessage
    Raw                                                                RawData
    IsMainResult                                                       bool
}

func (Result) Formats

go
func (result Result) Formats() []string

Formats returns the available raw MIME keys in sorted order.

type RunCodeOptions

RunCodeOptions configures code execution and streaming callbacks.

go
type RunCodeOptions struct {
    Language         Language
    Context          *Context
    Env              map[string]string
    RequestTimeout   time.Duration
    ExecutionTimeout time.Duration
    OnStdout         func(OutputMessage)
    OnStderr         func(OutputMessage)
    OnResult         func(Result)
    OnError          func(ExecutionError)
}

type Sandbox

Sandbox is a core sandbox with notebook-kernel APIs.

go
type Sandbox struct{ *agentbox.Sandbox }

func (*Sandbox) CreateContext

go
func (sandbox *Sandbox) CreateContext(ctx context.Context, options *CreateContextOptions) (*Context, error)

CreateContext creates a persistent kernel context.

func (*Sandbox) ListContexts

go
func (sandbox *Sandbox) ListContexts(ctx context.Context) ([]Context, error)

ListContexts returns all persistent kernel contexts in the sandbox.

func (*Sandbox) RemoveContext

go
func (sandbox *Sandbox) RemoveContext(ctx context.Context, contextID string) error

RemoveContext removes a persistent kernel context.

func (*Sandbox) RestartContext

go
func (sandbox *Sandbox) RestartContext(ctx context.Context, contextID string) error

RestartContext restarts a persistent kernel context.

func (*Sandbox) RunCode

go
func (sandbox *Sandbox) RunCode(ctx context.Context, code string, options *RunCodeOptions) (*Execution, error)

RunCode executes source code and collects streamed NDJSON output.

type ScaleType

ScaleType identifies a chart axis scale.

go
type ScaleType string

go
const (
    // ScaleLinear identifies a linear scale.
    ScaleLinear ScaleType = "linear"
    // ScaleDatetime identifies a date and time scale.
    ScaleDatetime ScaleType = "datetime"
    // ScaleCategorical identifies a categorical scale.
    ScaleCategorical ScaleType = "categorical"
    // ScaleLog identifies a logarithmic scale.
    ScaleLog ScaleType = "log"
    // ScaleSymlog identifies a symmetric logarithmic scale.
    ScaleSymlog ScaleType = "symlog"
    // ScaleLogit identifies a logit scale.
    ScaleLogit ScaleType = "logit"
    // ScaleFunction identifies a custom function scale.
    ScaleFunction ScaleType = "function"
    // ScaleFunctionLog identifies a logarithmic custom function scale.
    ScaleFunctionLog ScaleType = "functionlog"
    // ScaleAsinh identifies an inverse hyperbolic sine scale.
    ScaleAsinh ScaleType = "asinh"
)

Generated by gomarkdoc