core

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package core implements the core functionality for orla that is shared across all components.

Package core implements the core functionality for orla that is shared across all components.

Package core implements the core functionality for orla that is shared across all components.

Package core implements the core functionality for orla that is shared across all components.

Index

Constants

View Source
const (
	MaintainerLink    = "https://github.com/dorcha-inc/orla/blob/main/MAINTAINERS.md"
	BugReportTemplate = "\n\n[NOTE]This is most likely a bug in orla, please reach out to the maintainers at %s"
)
View Source
const (
	GOOSDarwin  = "darwin"
	GOOSLinux   = "linux"
	GOOSWindows = "windows"
)
View Source
const (
	DefaultCapsuleStartupTimeoutMs = 5000
)

Variables

This section is empty.

Functions

func BugReportMessage added in v0.2.0

func BugReportMessage() string

func CopyDirectory

func CopyDirectory(src, dst string, skipDirs []string) error

CopyDirectory recursively copies a directory using os.Root and fs.WalkDir. Skips directories in the skipDirs slice. This provides secure directory copying with automatic path traversal prevention.

func FileStat added in v0.3.0

func FileStat(path string, notFoundMessage string, otherMessage string) (os.FileInfo, error)

FileStat returns the file info for a given path. If the path is not found, it returns an error with the notFoundMessage. If there is another error, it returns an error with the otherMessage.

func GetEnv added in v0.3.0

func GetEnv(key string) string

GetEnv retrieves an environment variable, checking both the standard name and an ORLA-prefixed version. Returns the first non-empty value found. This allows environment variables to be set with or without the ORLA_ prefix.

func Init

func Init(pretty bool) error

Init initializes zap's global logger After calling this, we use zap.L() directly. The logger is explicitly configured to write to stderr to avoid interfering with tool stdout (especially important in stdio mode where stdout is used for MCP protocol).

func IsExecutable

func IsExecutable(info fs.FileInfo) bool

IsExecutable checks if a file mode has any executable bits set. It checks the executable bits for owner, group, and others (0111).

func IsLocalMachine added in v1.0.0

func IsLocalMachine() bool

func JoinMapKeys added in v0.3.0

func JoinMapKeys[T comparable](m map[T]struct{}) string

JoinMapKeys joins the keys of a map into a comma-separated string. Useful for error messages that need to list valid values.

func LogDeferredError

func LogDeferredError(fn func() error)

LogDeferredError takes a function that returns an error, calls it, and logs the error if it is not nil

func LogDeferredError1 added in v0.3.0

func LogDeferredError1[T any](fn func(T) error, arg T)

LogDeferredError1 takes a function that returns an error, calls it with the given argument, and logs the error if it is not nil

func LogPanicRecovery

func LogPanicRecovery(component string, r interface{})

LogPanicRecovery logs a recovered panic with stack trace

func LogRequest

func LogRequest(method string, duration float64, err error)

LogRequest logs an MCP request using zap's global logger

func LogToolExecution

func LogToolExecution(toolName string, duration float64, err error)

LogToolExecution logs a tool execution event using zap's global logger

func MustFprintf added in v0.3.0

func MustFprintf(w io.Writer, format string, a ...any)

MustFprintf is a wrapper around fmt.Fprintf that exits the program if it fails.

Types

type CapsuleManager added in v0.3.0

type CapsuleManager struct {
	// contains filtered or unexported fields
}

CapsuleManager manages the lifecycle of a capsule-mode tool

func NewCapsuleManager added in v0.3.0

func NewCapsuleManager(tool *ToolManifest) *CapsuleManager

NewCapsuleManager creates a new capsule manager for a tool

func NewCapsuleManagerWithClock added in v0.3.0

func NewCapsuleManagerWithClock(tool *ToolManifest, clock clockwork.Clock) *CapsuleManager

NewCapsuleManagerWithClock creates a new capsule manager for a tool with a custom clock This is useful for testing with a fake clock

func (*CapsuleManager) CallTool added in v0.3.0

func (cm *CapsuleManager) CallTool(ctx context.Context, input map[string]any) (*JSONRPCResponse, error)

CallTool sends a JSON-RPC tools/call request to the capsule and waits for the response

func (*CapsuleManager) GetState added in v0.3.0

func (cm *CapsuleManager) GetState() CapsuleState

GetState returns the current state of the capsule

func (*CapsuleManager) IsReady added in v0.3.0

func (cm *CapsuleManager) IsReady() bool

IsReady returns true if the capsule is in READY state

func (*CapsuleManager) Start added in v0.3.0

func (cm *CapsuleManager) Start() error

Start starts the capsule process and waits for the handshake

func (*CapsuleManager) Stop added in v0.3.0

func (cm *CapsuleManager) Stop() error

Stop stops the capsule process

type CapsuleState added in v0.3.0

type CapsuleState string

CapsuleState represents the lifecycle state of a capsule

const (
	CapsuleStateCreated   CapsuleState = "CREATED"
	CapsuleStateStarting  CapsuleState = "STARTING"
	CapsuleStateReady     CapsuleState = "READY"
	CapsuleStateReloading CapsuleState = "RELOADING"
	CapsuleStateCrashed   CapsuleState = "CRASHED"
	CapsuleStateStopped   CapsuleState = "STOPPED"
)

type Command

type Command interface {
	StdinPipe() (io.WriteCloser, error)
	StdoutPipe() (io.ReadCloser, error)
	StderrPipe() (io.ReadCloser, error)
	SetStdin(io.Reader)
	SetEnv([]string)
	Start() error
	Wait() error
}

Command is an interface for exec.Cmd, allowing for testing with mocks

type CommandRunner

type CommandRunner interface {
	CommandContext(ctx context.Context, name string, arg ...string) Command
}

CommandRunner is an interface for running commands, allowing for testing with mocks

type HotLoadConfig added in v0.3.0

type HotLoadConfig struct {
	// Watch is a list of paths to watch for changes
	Watch []string `yaml:"watch,omitempty"`
	// Mode is the reload strategy. Currently only "restart" is supported
	Mode HotLoadMode `yaml:"mode,omitempty"`
	// DebounceMs is the minimum debounce interval for file change events in milliseconds
	DebounceMs int `yaml:"debounce_ms,omitempty"`
}

HotLoadConfig represents an RFC 3 compliant hot-reload configuration See RFC 3 section 5.3 for more details on the hot-load configuration

type HotLoadMode added in v0.3.0

type HotLoadMode string

HotLoadMode represents the reload strategy for hot-load

const (
	// HotLoadModeRestart restarts the tool when a watched file changes
	HotLoadModeRestart HotLoadMode = "restart"
)

type JSONRPCError added in v0.3.0

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error

type JSONRPCRequest added in v0.3.0

type JSONRPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	ID      int64       `json:"id"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
}

JSONRPCRequest represents a JSON-RPC request

type JSONRPCResponse added in v0.3.0

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      int64         `json:"id"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
}

JSONRPCResponse represents a JSON-RPC response

type LLMBackend added in v0.4.0

type LLMBackend struct {
	// Endpoint is the URL of the LLM inference server
	Endpoint string `yaml:"endpoint,omitempty" mapstructure:"endpoint"`
	// Type is the type of the LLM inference API
	Type LLMInferenceAPIType `yaml:"type,omitempty" mapstructure:"type"`
	// APIKeyEnvVar is the *ENVIRONMENT VARIABLE*  storing the API key for the LLM inference API
	// Orla *does not* allow you to store the API key in the config file. You must use an environment variable.
	// This is to prevent the API key from being accidentally logged or leaked.
	APIKeyEnvVar string `yaml:"api_key_env_var,omitempty" mapstructure:"api_key_env_var"`
}

LLMBackend represents an LLM inference server. This allows configuring remote Ollama servers, OpenAI-compatible APIs, and other LLM inference servers.

type LLMInferenceAPIType added in v0.4.0

type LLMInferenceAPIType string

LLMInferenceAPIType represents the type of LLM inference API

const (
	// LLMInferenceAPITypeOllama represents the Ollama API (RFC 4)
	LLMInferenceAPITypeOllama LLMInferenceAPIType = "ollama"
	// LLMInferenceAPITypeOpenAI represents any inference server that has an
	// OpenAI-compatible API.
	LLMInferenceAPITypeOpenAI LLMInferenceAPIType = "openai"
	// LLMInferenceAPITypeSGLang represents SGLang, which provides an Ollama-compatible
	// API for inference and a separate /flush_cache endpoint for cache control.
	LLMInferenceAPITypeSGLang LLMInferenceAPIType = "sglang"
)

type MCPConfig added in v0.3.0

type MCPConfig struct {
	InputSchema  map[string]any `yaml:"input_schema,omitempty"`
	OutputSchema map[string]any `yaml:"output_schema,omitempty"`
}

MCPConfig represents MCP-specific metadata from RFC 3

type OrlaHelloNotification added in v0.3.0

type OrlaHelloNotification struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  OrlaHelloParams `json:"params"`
}

OrlaHelloNotification represents the orla.hello handshake notification as defined in RFC 3 Section 5.3.1

type OrlaHelloParams added in v0.3.0

type OrlaHelloParams struct {
	Name         string   `json:"name"`
	Version      string   `json:"version"`
	Capabilities []string `json:"capabilities"`
}

OrlaHelloParams represents the parameters of the orla.hello notification

type OrlaToolExecutionResult

type OrlaToolExecutionResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code"`
	Error    error  `json:"-"`
}

OrlaToolExecutionResult represents the result of a tool execution

type OrlaToolExecutor

type OrlaToolExecutor struct {
	// contains filtered or unexported fields
}

OrlaToolExecutor handles tool execution

func NewOrlaToolExecutor

func NewOrlaToolExecutor(timeoutSeconds int) *OrlaToolExecutor

NewOrlaToolExecutor creates a new tool executor with a real clock

func NewOrlaToolExecutorWithClock

func NewOrlaToolExecutorWithClock(timeoutSeconds int, clock clockwork.Clock) *OrlaToolExecutor

NewOrlaToolExecutorWithClock creates a new tool executor with a custom clock This is useful for testing with a fake clock

func NewOrlaToolExecutorWithClockAndRunner

func NewOrlaToolExecutorWithClockAndRunner(timeoutSeconds int, clock clockwork.Clock, runner CommandRunner) *OrlaToolExecutor

NewOrlaToolExecutorWithClockAndRunner creates a new tool executor with a custom clock and command runner This is useful for testing with a fake clock and mocked command execution

func (*OrlaToolExecutor) Execute

func (e *OrlaToolExecutor) Execute(ctx context.Context, tool *ToolManifest, args []string, stdin string) (*OrlaToolExecutionResult, error)

Execute executes a tool with the given arguments and input

type RuntimeConfig added in v0.3.0

type RuntimeConfig struct {
	// Mode is the runtime mode. Currently only "simple" and "capsule" are supported
	Mode RuntimeMode `yaml:"mode,omitempty"`
	// StartupTimeoutMs is the maximum time Orla will wait for the startup handshake in milliseconds
	StartupTimeoutMs int `yaml:"startup_timeout_ms,omitempty"`
	// HotLoad is the hot-reload configuration as defined in RFC 3 section 5.3
	HotLoad *HotLoadConfig `yaml:"hot_load,omitempty"`
	// Env is a map of environment variables to inject into the tool process
	Env map[string]string `yaml:"env,omitempty"`
	// Args is a list of command-line arguments to append to the entrypoint
	Args []string `yaml:"args,omitempty"`
}

RuntimeConfig represents RFC 3 compliant runtime configuration

type RuntimeMode added in v0.3.0

type RuntimeMode string

RuntimeMode represents the execution mode of a tool

const (
	// RuntimeModeSimple executes on-demand per request
	RuntimeModeSimple RuntimeMode = "simple"
	// RuntimeModeCapsule executes as a long-running process with lifecycle management
	RuntimeModeCapsule RuntimeMode = "capsule"
)

type ToolManifest added in v0.3.0

type ToolManifest struct {
	Name         string         `yaml:"name" validate:"required"`
	Version      string         `yaml:"version" validate:"required"`
	Description  string         `yaml:"description" validate:"required"`
	Entrypoint   string         `yaml:"entrypoint" validate:"required"`
	Author       string         `yaml:"author,omitempty"`
	License      string         `yaml:"license,omitempty"`
	Repository   string         `yaml:"repository,omitempty"`
	Homepage     string         `yaml:"homepage,omitempty"`
	Keywords     []string       `yaml:"keywords,omitempty"`
	Dependencies []string       `yaml:"dependencies,omitempty"`
	MCP          *MCPConfig     `yaml:"mcp,omitempty"`
	Runtime      *RuntimeConfig `yaml:"runtime,omitempty"`
	Path         string         `yaml:"path,omitempty"`        // Absolute path to entrypoint
	Interpreter  string         `yaml:"interpreter,omitempty"` // Interpreter parsed from shebang
}

ToolManifest represents an RFC 3 compliant tool.yaml manifest It is used both for parsing manifests and for tool execution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL