surplus

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package surplus is a scriptable fake of the Surplus Intelligence API (markets, models, balance, request lookup, chat/responses/embeddings with floor and ZDR prefixes, and scripted errors).

Index

Constants

View Source
const (
	ChargeInline   = "inline"
	ChargeRequests = "requests"
	ChargeNone     = "none"
)

ChargeIn values for Script.ChargeIn.

View Source
const (

	// DefaultChatContent holds two zero-width non-joiners (U+200C) so
	// byte-for-byte streaming fidelity is verified.
	DefaultChatContent = "می\u200cشود و نمی\u200cخواهم"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Fake

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

Fake is a multi-instance Surplus fake. Each /s/{name} has independent script and recorded state. It is safe for concurrent use.

func New

func New() *Fake

New returns an empty Fake.

func (*Fake) Headers added in v0.11.0

func (f *Fake) Headers(name string) []http.Header

Headers returns a copy of the request headers received by instance name in order.

func (*Fake) Paths

func (f *Fake) Paths(name string) []string

Paths returns a copy of the paths received by instance name in order.

func (*Fake) Requests

func (f *Fake) Requests(name string) []string

Requests returns a copy of the /v1/requests ids looked up on instance name.

func (*Fake) Reset

func (f *Fake) Reset()

Reset clears every instance's script, paths, and recorded requests.

func (*Fake) ServeHTTP

func (f *Fake) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles /s/{name}/... and /_control/surplus/{name}...

func (*Fake) SetScript

func (f *Fake) SetScript(name string, s Script)

SetScript replaces the script for instance name.

type Script

type Script struct {
	Markets       json.RawMessage `json:"markets,omitempty"`        // whole /api/markets body; default: four models
	Models        json.RawMessage `json:"models,omitempty"`         // whole /v1/models body; default: four models
	Balance       *string         `json:"balance,omitempty"`        // credit_balance_usdc; nil = default "5000000"
	Charge        *int64          `json:"charge,omitempty"`         // micro-USD; nil = omit header, body field and /v1/requests value
	ChargeIn      string          `json:"charge_in,omitempty"`      // "inline" (default) | "requests" | "none"
	Error         *ScriptedError  `json:"error,omitempty"`          // next N inference calls: status, code, param, retry_after
	MarketsStatus int             `json:"markets_status,omitempty"` // non-zero: /api/markets answers this status
}

Script configures a named fake Surplus instance (/s/{name}).

type ScriptedError

type ScriptedError struct {
	Status     int    `json:"status"`
	Code       string `json:"code"`
	Message    string `json:"message,omitempty"`
	Type       string `json:"type,omitempty"`
	Param      string `json:"param,omitempty"`
	RetryAfter string `json:"retry_after,omitempty"`
	Count      int    `json:"count,omitempty"` // 0 defaults to 1 call; negative repeats until reset
}

ScriptedError configures an error returned by the next N inference calls.

Jump to

Keyboard shortcuts

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