Documentation
¶
Overview ¶
Package claudebox provides a Go client for the claudebox API — a runtime harness for Claude Code running in Docker containers.
The Claudebox interface enables mocking for tests. Use New to create a concrete *Client.
Package claudebox provides a Go client for the claudebox direct API.
Index ¶
- func FilePath(parts ...string) string
- type APIError
- type AsyncRunResponse
- type CacheCreation
- type CancelResponse
- type Claudebox
- type Client
- func (c *Client) Cancel(ctx context.Context, workspace string) (*CancelResponse, error)
- func (c *Client) CancelRun(ctx context.Context, runID string) (*CancelResponse, error)
- func (c *Client) DeleteFile(ctx context.Context, filePath string) (*DeleteFileResponse, error)
- func (c *Client) Health(ctx context.Context) (*HealthResponse, error)
- func (c *Client) ListFiles(ctx context.Context, dirPath string) (*ListFilesResponse, error)
- func (c *Client) ReadFile(ctx context.Context, filePath string) (*ReadFileResponse, error)
- func (c *Client) Run(ctx context.Context, req *RunRequest) (*RunResponse, error)
- func (c *Client) RunAsync(ctx context.Context, req *RunRequest) (*AsyncRunResponse, error)
- func (c *Client) RunResult(ctx context.Context, runID string) (*RunResultResponse, error)
- func (c *Client) Status(ctx context.Context) (*StatusResponse, error)
- func (c *Client) WriteFile(ctx context.Context, filePath string, content []byte) (*WriteFileResponse, error)
- type ContentBlock
- type DeleteFileResponse
- type FileEntry
- type HealthResponse
- type ListFilesResponse
- type ModelStats
- type Option
- type ReadFileResponse
- type RunInfo
- type RunRequest
- type RunResponse
- type RunResultResponse
- type ServerToolUse
- type StatusResponse
- type SystemInfo
- type Turn
- type Usage
- type WriteFileResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AsyncRunResponse ¶
type AsyncRunResponse struct {
RunID string `json:"runId"`
Workspace string `json:"workspace"`
Status string `json:"status"`
}
AsyncRunResponse is returned by POST /run when async mode is enabled.
type CacheCreation ¶
type CacheCreation struct {
Ephemeral1hInputTokens int `json:"ephemeral1hInputTokens"`
Ephemeral5mInputTokens int `json:"ephemeral5mInputTokens"`
}
CacheCreation holds cache creation token breakdown.
type CancelResponse ¶
type CancelResponse struct {
Status string `json:"status"`
RunID string `json:"runId,omitempty"`
Workspace string `json:"workspace"`
}
CancelResponse is the response from POST /run/cancel.
type Claudebox ¶
type Claudebox interface {
// Health checks if the server is up.
Health(ctx context.Context) (*HealthResponse, error)
// Status returns currently busy workspaces.
Status(ctx context.Context) (*StatusResponse, error)
// Run executes a prompt via POST /run.
Run(
ctx context.Context,
req *RunRequest,
) (*RunResponse, error)
// RunAsync starts an async run and returns
// immediately. Poll with RunResult.
RunAsync(
ctx context.Context,
req *RunRequest,
) (*AsyncRunResponse, error)
// RunResult polls for the result of an async run.
RunResult(
ctx context.Context,
runID string,
) (*RunResultResponse, error)
// Cancel kills a running process in the given
// workspace (empty = default).
Cancel(
ctx context.Context,
workspace string,
) (*CancelResponse, error)
// CancelRun cancels a running async job by run ID.
CancelRun(
ctx context.Context,
runID string,
) (*CancelResponse, error)
// ListFiles lists files at the given path
// (empty = workspace root).
ListFiles(
ctx context.Context,
dirPath string,
) (*ListFilesResponse, error)
// ReadFile downloads a file. The caller must close
// the returned ReadFileResponse.Body when done.
ReadFile(
ctx context.Context,
filePath string,
) (*ReadFileResponse, error)
// WriteFile uploads content to the given path.
WriteFile(
ctx context.Context,
filePath string,
content []byte,
) (*WriteFileResponse, error)
// DeleteFile deletes a file at the given path.
DeleteFile(
ctx context.Context,
filePath string,
) (*DeleteFileResponse, error)
}
Claudebox is the interface for all claudebox API operations. Implement this for mocking in tests.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a claudebox API server.
func New ¶
New creates a claudebox client. baseURL is the server root, e.g. "http://localhost:8080".
func (*Client) DeleteFile ¶
DeleteFile deletes a file at the given path.
func (*Client) Health ¶
func (c *Client) Health( ctx context.Context, ) (*HealthResponse, error)
Health checks if the server is up.
func (*Client) ReadFile ¶
ReadFile downloads a file and returns a streaming response. The caller must close Body when done.
func (*Client) Run ¶
func (c *Client) Run( ctx context.Context, req *RunRequest, ) (*RunResponse, error)
Run executes a prompt via POST /run and returns the parsed response.
func (*Client) RunAsync ¶
func (c *Client) RunAsync( ctx context.Context, req *RunRequest, ) (*AsyncRunResponse, error)
RunAsync starts an async run and returns immediately. Poll with RunResult to get the outcome.
func (*Client) RunResult ¶
RunResult polls for the result of an async run. Results are purged after first read (except running).
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
// text block fields
Text string `json:"text,omitempty"`
// tool_use block fields
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Input json.RawMessage `json:"input,omitempty"`
// tool_result block fields
ToolUseID string `json:"toolUseId,omitempty"`
IsError bool `json:"isError,omitempty"`
Content string `json:"content,omitempty"`
Truncated bool `json:"truncated,omitempty"`
TotalLength int `json:"totalLength,omitempty"`
SHA256 string `json:"sha256,omitempty"`
}
ContentBlock is a single block within a turn. The Type field determines which other fields are set.
Type "text": Text is set. Type "tool_use": ID, Name, Input are set. Type "tool_result": ToolUseID, IsError, Content, and optionally Truncated/TotalLength/SHA256 are set.
type DeleteFileResponse ¶
DeleteFileResponse is the response from DELETE /files/{path}.
type FileEntry ¶
type FileEntry struct {
Name string `json:"name"`
Type string `json:"type"`
Size int64 `json:"size,omitempty"`
}
FileEntry is a single item in a directory listing.
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
}
HealthResponse is the response from GET /health.
type ListFilesResponse ¶
ListFilesResponse is the response from GET /files or GET /files/{path} on a directory.
type ModelStats ¶
type ModelStats struct {
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CacheReadInputTokens int `json:"cacheReadInputTokens"`
CacheCreationInputTokens int `json:"cacheCreationInputTokens"`
WebSearchRequests int `json:"webSearchRequests"`
CostUSD float64 `json:"costUSD"` //nolint:tagliatelle // server sends costUSD
ContextWindow int `json:"contextWindow"`
MaxOutputTokens int `json:"maxOutputTokens"`
}
ModelStats holds per-model usage and cost info.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithHTTPClient ¶
WithHTTPClient overrides the default http.Client.
type ReadFileResponse ¶
type ReadFileResponse struct {
// ContentType is the MIME type from the server
// (e.g. "text/plain", "application/octet-stream").
ContentType string
// ContentLength is the file size in bytes, or -1
// if the server did not send Content-Length.
ContentLength int64
// Body is the file data stream. The caller must
// close it when done.
Body io.ReadCloser
}
ReadFileResponse wraps a streamed file download. The caller must close Body when done reading.
type RunInfo ¶
type RunInfo struct {
RunID string `json:"runId"`
Workspace string `json:"workspace"`
Status string `json:"status"`
}
RunInfo is a summary of an async run, returned by GET /status.
type RunRequest ¶
type RunRequest struct {
Prompt string `json:"prompt"`
Workspace string `json:"workspace,omitempty"`
Model string `json:"model,omitempty"`
SystemPrompt string `json:"systemPrompt,omitempty"`
AppendSystemPrompt string `json:"appendSystemPrompt,omitempty"`
JSONSchema string `json:"jsonSchema,omitempty"`
Effort string `json:"effort,omitempty"`
OutputFormat string `json:"outputFormat,omitempty"`
NoContinue bool `json:"noContinue,omitempty"`
Resume string `json:"resume,omitempty"`
FireAndForget bool `json:"fireAndForget,omitempty"`
}
RunRequest is the body for POST /run.
type RunResponse ¶
type RunResponse struct {
RunID string `json:"runId,omitempty"`
Type string `json:"type"`
Subtype string `json:"subtype"`
Result string `json:"result"`
IsError bool `json:"isError"`
NumTurns int `json:"numTurns"`
DurationMs int64 `json:"durationMs"`
DurationAPIMs int64 `json:"durationApiMs"`
StopReason string `json:"stopReason"`
SessionID string `json:"sessionId"`
TotalCostUSD float64 `json:"totalCostUsd"`
UUID string `json:"uuid"`
FastModeState string `json:"fastModeState"`
Usage Usage `json:"usage"`
ModelUsage map[string]ModelStats `json:"modelUsage,omitempty"`
Turns []Turn `json:"turns,omitempty"`
System *SystemInfo `json:"system,omitempty"`
// PermissionDenials lists any permission denials
// that occurred during the run.
PermissionDenials []json.RawMessage `json:"permissionDenials,omitempty"`
// contains filtered or unexported fields
}
RunResponse is the JSON response from POST /run.
func (*RunResponse) Raw ¶
func (r *RunResponse) Raw() json.RawMessage
Raw returns the full unparsed JSON response body.
type RunResultResponse ¶
type RunResultResponse struct {
RunID string `json:"runId"`
Workspace string `json:"workspace,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
// Result is set when Status is "completed".
Result *RunResponse `json:"-"`
}
RunResultResponse is the response from GET /run/result. Check Status to determine the outcome:
- "running": still in progress
- "completed": Result is populated
- "cancelled": run was cancelled
- "failed": Error contains the failure message
type ServerToolUse ¶
type ServerToolUse struct {
WebSearchRequests int `json:"webSearchRequests"`
WebFetchRequests int `json:"webFetchRequests"`
}
ServerToolUse holds server-side tool usage counters.
type StatusResponse ¶
type StatusResponse struct {
BusyWorkspaces []string `json:"busyWorkspaces"`
Runs []RunInfo `json:"runs,omitempty"`
}
StatusResponse is the response from GET /status.
type SystemInfo ¶
type SystemInfo struct {
SessionID string `json:"sessionId"`
Model string `json:"model"`
Cwd string `json:"cwd"`
Tools []string `json:"tools"`
}
SystemInfo holds session metadata from verbose output.
type Turn ¶
type Turn struct {
Role string `json:"role"`
Content []ContentBlock `json:"content"`
}
Turn represents a conversation turn in verbose output.
type Usage ¶
type Usage struct {
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CacheCreationInputTokens int `json:"cacheCreationInputTokens"`
CacheReadInputTokens int `json:"cacheReadInputTokens"`
ServerToolUse *ServerToolUse `json:"serverToolUse,omitempty"`
ServiceTier string `json:"serviceTier,omitempty"`
CacheCreation *CacheCreation `json:"cacheCreation,omitempty"`
InferenceGeo string `json:"inferenceGeo,omitempty"`
Iterations []json.RawMessage `json:"iterations,omitempty"`
Speed string `json:"speed,omitempty"`
}
Usage holds token usage stats.
type WriteFileResponse ¶
type WriteFileResponse struct {
Status string `json:"status"`
Path string `json:"path"`
Size int `json:"size"`
}
WriteFileResponse is the response from PUT /files/{path}.