backend

package
v0.107.6-beta.4 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Overview

Package backend exposes K-brain's canonical session and Agent runtime over HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendHook

type BackendHook struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Description string        `json:"description,omitempty"`
	Event       string        `json:"event"`
	Enabled     bool          `json:"enabled"`
	Type        HookType      `json:"type"`
	Script      string        `json:"script,omitempty"`
	Requests    []HookRequest `json:"requests,omitempty"`
	TimeoutMS   int           `json:"timeoutMs,omitempty"`
}

type BackendHookRunner

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

func NewBackendHookRunner

func NewBackendHookRunner(store *HookStore) *BackendHookRunner

func (*BackendHookRunner) Scope

func (r *BackendHookRunner) Scope(ctx context.Context, conversationID, runID, cwd string, warn func(BackendHook, string, error)) func(string)

Scope snapshots configuration once; event replay never invokes this callback.

type CronApplyInput

type CronApplyInput struct {
	BaseRevision uint64          `json:"baseRevision"`
	Ops          []CronOperation `json:"ops"`
}

type CronApplyResponse

type CronApplyResponse struct {
	Status string       `json:"status"`
	Cron   CronSnapshot `json:"cron"`
}

type CronHTTPRequest

type CronHTTPRequest struct {
	ID      string            `json:"id"`
	URL     string            `json:"url"`
	Method  string            `json:"method"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    json.RawMessage   `json:"body,omitempty"`
}

type CronModelRef

type CronModelRef struct {
	CustomProviderID string `json:"customProviderId"`
	Model            string `json:"model"`
}

type CronOperation

type CronOperation struct {
	Op    string         `json:"op"`
	ID    string         `json:"id,omitempty"`
	Item  map[string]any `json:"item,omitempty"`
	Patch map[string]any `json:"patch,omitempty"`
	IDs   []string       `json:"ids,omitempty"`
}

type CronRunNowResponse

type CronRunNowResponse struct {
	ExecutionID string `json:"executionId"`
	StartedAt   int64  `json:"startedAt"`
}

type CronRunRecord

type CronRunRecord struct {
	SessionID         string `json:"sessionId,omitempty"`
	RunID             string `json:"runId,omitempty"`
	Counted           bool   `json:"counted"`
	ID                string `json:"id"`
	TaskID            string `json:"taskId"`
	State             string `json:"state"`
	Success           bool   `json:"success"`
	StartedAt         int64  `json:"startedAt"`
	FinishedAt        *int64 `json:"finishedAt,omitempty"`
	DurationMs        uint64 `json:"durationMs"`
	ExitCode          *int   `json:"exitCode,omitempty"`
	Output            string `json:"output"`
	TerminationReason string `json:"terminationReason,omitempty"`
}

type CronSnapshot

type CronSnapshot struct {
	Revision uint64      `json:"revision"`
	Tasks    []*CronTask `json:"tasks"`
}

type CronTask

type CronTask struct {
	ID string `json:"id"`
	// SessionID binds prompt tasks to one durable canonical conversation.
	SessionID           string            `json:"sessionId,omitempty"`
	Name                string            `json:"name"`
	Description         string            `json:"description"`
	Cron                string            `json:"cron"`
	Enabled             bool              `json:"enabled"`
	RemainingExecutions *uint64           `json:"remainingExecutions,omitempty"`
	TimeoutSeconds      uint64            `json:"timeoutSeconds"`
	Type                string            `json:"type"`
	Script              string            `json:"script,omitempty"`
	Requests            []CronHTTPRequest `json:"requests,omitempty"`
	Prompt              string            `json:"prompt,omitempty"`
	SelectedModel       *CronModelRef     `json:"selectedModel,omitempty"`
	Reasoning           string            `json:"reasoning,omitempty"`
	Workdir             string            `json:"workdir,omitempty"`
	LastError           string            `json:"lastError,omitempty"`
}

type Factory

type Factory func(context.Context, string, protocol.ModelRef) (*agent.Agent, error)

type HookOperation

type HookOperation struct {
	Op    string         `json:"op"`
	ID    string         `json:"id,omitempty"`
	Item  map[string]any `json:"item,omitempty"`
	Patch map[string]any `json:"patch,omitempty"`
	IDs   []string       `json:"ids,omitempty"`
}

type HookRequest

type HookRequest struct {
	ID      string            `json:"id"`
	URL     string            `json:"url"`
	Method  string            `json:"method"`
	Headers map[string]string `json:"headers,omitempty"`
	Body    any               `json:"body,omitempty"`
}

type HookStore

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

func NewHookStore

func NewHookStore(path string) (*HookStore, error)

func (*HookStore) Apply

func (*HookStore) Snapshot

func (s *HookStore) Snapshot() HooksSnapshot

type HookType

type HookType string
const (
	HookCommand HookType = "command"
	HookHTTP    HookType = "http"
)

type HooksApplyInput

type HooksApplyInput struct {
	BaseRevision uint64          `json:"baseRevision"`
	Ops          []HookOperation `json:"ops"`
}

type HooksApplyResponse

type HooksApplyResponse struct {
	Status string        `json:"status"`
	Hooks  HooksSnapshot `json:"hooks"`
}

type HooksSnapshot

type HooksSnapshot struct {
	Revision uint64        `json:"revision"`
	Hooks    []BackendHook `json:"hooks"`
}

type Options

type Options struct {
	Store                   *session.Store
	Factory                 Factory
	EventDir                string
	Token                   string
	Models                  []protocol.ModelRef
	DefaultCWD              string
	Settings                *SettingsStore
	Prompts                 *resources.PromptStore
	MemoryRoot              string
	MemoryStore             *memory.Store
	MemoryRuntimeFactory    MemoryRuntimeFactory
	MemoryOrganizerInterval time.Duration
	QuestionTimeout         time.Duration
	MCP                     *mcp.LiveManager
	MCPCredentialBridge     mcp.CredentialBridge
}

type ProviderUsageResult

type ProviderUsageResult struct {
	Data      []UsageData `json:"data"`
	QueriedAt *int64      `json:"queriedAt"`
	Error     *string     `json:"error"`
	IsStale   bool        `json:"isStale"`
}

type ProviderUsageService

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

func NewProviderUsageService

func NewProviderUsageService(settings *SettingsStore) *ProviderUsageService

func (*ProviderUsageService) ProviderExists

func (s *ProviderUsageService) ProviderExists(id string) bool

func (*ProviderUsageService) Query

func (s *ProviderUsageService) Query(ctx context.Context, providerID string, refresh bool) ProviderUsageResult

func (*ProviderUsageService) Test

func (s *ProviderUsageService) Test(ctx context.Context, providerID string, draft usageConfig) ProviderUsageResult

type Server

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

func New

func New(opts Options) (*Server, error)

func (*Server) Close

func (s *Server) Close() error

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SettingsStore

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

SettingsStore publishes immutable snapshots only after persistence succeeds.

func NewSettingsStore

func NewSettingsStore(cfg *config.Config, save func(*config.Config) error) *SettingsStore

func (*SettingsStore) Revision

func (s *SettingsStore) Revision() uint64

func (*SettingsStore) Snapshot

func (s *SettingsStore) Snapshot() *config.Config

type UsageData

type UsageData struct {
	PlanName       string   `json:"planName,omitempty"`
	Extra          string   `json:"extra,omitempty"`
	IsValid        *bool    `json:"isValid,omitempty"`
	InvalidMessage string   `json:"invalidMessage,omitempty"`
	Total          *float64 `json:"total,omitempty"`
	Used           *float64 `json:"used,omitempty"`
	Remaining      *float64 `json:"remaining,omitempty"`
	Unit           string   `json:"unit,omitempty"`
}

Jump to

Keyboard shortcuts

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