server

package
v0.0.0-...-26bf2cd Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultToolArgs = `{"file_path":"README.md"}`
View Source
const DefaultToolName = "Read"

Variables

View Source
var LLMHosts = []string{
	"api.openai.com",
	"api.anthropic.com",
	"generativelanguage.googleapis.com",
	"api.x.ai",
	"openrouter.ai",
	"api.moonshot.cn",
	"dashscope.aliyuncs.com",
	"api.factory.ai",
	"kilo.codes",
	"opencode.ai",

	"q.us-east-1.amazonaws.com",
	"q.eu-central-1.amazonaws.com",
	"runtime.us-east-1.kiro.dev",
	"runtime.eu-central-1.kiro.dev",
	"app.kiro.dev",
	"prod.us-east-1.auth.desktop.kiro.dev",
	"management.us-east-1.kiro.dev",
	"cognito-identity.us-east-1.amazonaws.com",
	"client-telemetry.us-east-1.amazonaws.com",
	"prod.us-east-1.telemetry-v2.kiro.dev",
}

LLMHosts are API domains that agents call. Used by --intercept mode to map these to 127.0.0.1 via /etc/hosts so all LLM traffic hits the mock.

Functions

func HostsEntries

func HostsEntries() string

HostsEntries returns /etc/hosts lines mapping LLM API domains to 127.0.0.1.

Types

type AntUsage

type AntUsage struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
}

type AnthropicMessage

type AnthropicMessage struct {
	ID         string         `json:"id"`
	Type       string         `json:"type"`
	Role       string         `json:"role"`
	Model      string         `json:"model"`
	Content    []ContentBlock `json:"content"`
	StopReason string         `json:"stop_reason,omitempty"`
	Usage      *AntUsage      `json:"usage,omitempty"`
}

type ChatChoice

type ChatChoice struct {
	Index        int          `json:"index"`
	Message      *ChatMessage `json:"message,omitempty"`
	Delta        *ChatMessage `json:"delta,omitempty"`
	FinishReason string       `json:"finish_reason,omitempty"`
}

type ChatCompletion

type ChatCompletion struct {
	ID      string       `json:"id"`
	Object  string       `json:"object"`
	Created int64        `json:"created"`
	Model   string       `json:"model"`
	Choices []ChatChoice `json:"choices"`
	Usage   *Usage       `json:"usage,omitempty"`
}

type ChatMessage

type ChatMessage struct {
	Role      string     `json:"role,omitempty"`
	Content   any        `json:"content"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
}

type ContentBlock

type ContentBlock struct {
	Type  string `json:"type"`
	Text  string `json:"text,omitempty"`
	ID    string `json:"id,omitempty"`
	Name  string `json:"name,omitempty"`
	Input any    `json:"input,omitempty"`
}

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

type LogEntry

type LogEntry struct {
	Timestamp time.Time         `json:"ts"`
	Method    string            `json:"method"`
	Path      string            `json:"path"`
	Headers   map[string]string `json:"headers,omitempty"`
	Body      json.RawMessage   `json:"body,omitempty"`
	Model     string            `json:"model,omitempty"`
}

type MockServer

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

func New

func New() *MockServer

func (*MockServer) CAPem

func (s *MockServer) CAPem() []byte

CAPem returns the PEM-encoded CA certificate used by the MITM listener. Returns nil if StartIntercept hasn't been called.

func (*MockServer) ClearLog

func (s *MockServer) ClearLog()

func (*MockServer) Close

func (s *MockServer) Close()

func (*MockServer) Log

func (s *MockServer) Log() []LogEntry

func (*MockServer) LogCount

func (s *MockServer) LogCount() int

func (*MockServer) PrepareToolCall

func (s *MockServer) PrepareToolCall(name, args, path string)

func (*MockServer) ProxyAddr

func (s *MockServer) ProxyAddr() string

ProxyAddr returns the MITM proxy address (e.g. "http://127.0.0.1:34567") for use as HTTPS_PROXY. Returns empty if StartProxy hasn't been called.

func (*MockServer) SetResponse

func (s *MockServer) SetResponse(text string)

func (*MockServer) Start

func (s *MockServer) Start() (string, error)

func (*MockServer) StartIntercept

func (s *MockServer) StartIntercept() (string, error)

StartIntercept starts both HTTP (random port) and HTTPS (port 443) listeners. Uses a CA cert to sign server certs for all LLM API domains. The CA PEM is available via CAPem() for injection into runtimes (NODE_EXTRA_CA_CERTS etc.).

func (*MockServer) StartProxy

func (s *MockServer) StartProxy() (string, error)

StartProxy starts an HTTP CONNECT proxy on a random port. Agents that set HTTPS_PROXY to this address will have their TLS connections MITM'd: the proxy terminates TLS using the CA cert from StartIntercept, then routes the decrypted HTTP requests through the mock server's mux.

Must be called after StartIntercept (needs the CA-signed TLS cert).

type ModelEntry

type ModelEntry struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	OwnedBy string `json:"owned_by"`
}

type ModelList

type ModelList struct {
	Data []ModelEntry `json:"data"`
}

type ResponseItem

type ResponseItem struct {
	Type      string         `json:"type"`
	ID        string         `json:"id,omitempty"`
	CallID    string         `json:"call_id,omitempty"`
	Role      string         `json:"role,omitempty"`
	Name      string         `json:"name,omitempty"`
	Arguments string         `json:"arguments,omitempty"`
	Status    string         `json:"status,omitempty"`
	Content   []ResponsePart `json:"content,omitempty"`
}

type ResponseObject

type ResponseObject struct {
	ID     string         `json:"id"`
	Object string         `json:"object,omitempty"`
	Ts     int64          `json:"created"`
	TsAlt  int64          `json:"created_at"`
	Status string         `json:"status"`
	Output []ResponseItem `json:"output"`
	Usage  *Usage         `json:"usage,omitempty"`
}

type ResponsePart

type ResponsePart struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

type ToolCall

type ToolCall struct {
	Index    int          `json:"index"`
	ID       string       `json:"id,omitempty"`
	Type     string       `json:"type,omitempty"`
	Function FunctionCall `json:"function"`
}

type Usage

type Usage struct {
	PromptTokens     int `json:"prompt_tokens,omitempty"`
	CompletionTokens int `json:"completion_tokens,omitempty"`
	InputTokens      int `json:"input_tokens,omitempty"`
	OutputTokens     int `json:"output_tokens,omitempty"`
	TotalTokens      int `json:"total_tokens"`
}

Jump to

Keyboard shortcuts

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