Documentation
¶
Overview ¶
Package kernel implements an HTTP + WebSocket client for the Jupyter Server REST API. It covers kernel lifecycle (list/start/restart/interrupt/stop) and provides a Channel type for executing code via the Jupyter messaging protocol.
Index ¶
- func FormatOutputs(outputs []Output) string
- type Channel
- type Client
- func (c *Client) GetKernel(ctx context.Context, id string) (*KernelInfo, error)
- func (c *Client) InterruptKernel(ctx context.Context, id string) error
- func (c *Client) ListKernels(ctx context.Context) ([]KernelInfo, error)
- func (c *Client) OpenChannel(ctx context.Context, kernelID string) (*Channel, error)
- func (c *Client) RestartKernel(ctx context.Context, id string) error
- func (c *Client) StartKernel(ctx context.Context, name string) (*KernelInfo, error)
- func (c *Client) StopKernel(ctx context.Context, id string) error
- type Config
- type KernelInfo
- type Output
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatOutputs ¶
FormatOutputs converts a slice of Outputs into a human-readable string suitable for returning to the model. Images are represented as a placeholder referencing their MIME type.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is a multiplexed WebSocket connection to a Jupyter kernel. It implements the Jupyter Messaging Protocol v5 over a single WebSocket.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a minimal Jupyter Server REST client.
func (*Client) InterruptKernel ¶
InterruptKernel sends an interrupt signal to a running kernel.
func (*Client) ListKernels ¶
func (c *Client) ListKernels(ctx context.Context) ([]KernelInfo, error)
ListKernels returns all running kernels.
func (*Client) OpenChannel ¶
OpenChannel opens a WebSocket channel to a kernel for code execution.
func (*Client) RestartKernel ¶
RestartKernel restarts a kernel, clearing all state.
func (*Client) StartKernel ¶
StartKernel starts a new kernel with the given name (e.g. "python3").
type Config ¶
type Config struct {
ServerURL string // e.g. "http://localhost:8888"
Token string // Jupyter token
}
Config holds the connection parameters for a Jupyter server.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config populated from environment variables.
func MergeConfig ¶
MergeConfig merges explicit values (from tool input) onto a base config, keeping env-var defaults when the explicit value is empty.
type KernelInfo ¶
type KernelInfo struct {
ID string `json:"id"`
Name string `json:"name"`
LastActivity string `json:"last_activity"`
ExecutionState string `json:"execution_state"`
Connections int `json:"connections"`
}
KernelInfo represents a running Jupyter kernel.
type Output ¶
type Output struct {
Type string // "stream", "execute_result", "display_data", "error"
Name string // for stream: "stdout" or "stderr"
Text string // text representation
ImagePNG string // base64-encoded PNG (display_data)
ImageJPEG string // base64-encoded JPEG (display_data)
Data map[string]any // raw data dict from the message
}
Output is a parsed result from a single Jupyter kernel message.