server

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 23 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 server hosts ARCP agents. Accept consumes a transport pair and runs one session over it; agents are registered via RegisterAgent / RegisterAgentVersion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentFunc

type AgentFunc func(ctx context.Context, input json.RawMessage, jc *JobContext) (any, error)

AgentFunc is the agent body. The runtime invokes it inside a job; returning (any, nil) produces job.result with the marshalled output, returning a non-nil error produces job.error. To stream results, call jc.StreamResult and return (nil, nil) after the writer is closed.

type Job

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

Job is the runtime-side representation of an accepted job.

func (*Job) Agent

func (j *Job) Agent() string

Agent returns the resolved "name@version" string.

func (*Job) ID

func (j *Job) ID() string

ID returns the job identifier.

func (*Job) Lease

func (j *Job) Lease() arcp.Lease

Lease returns a snapshot of the job's lease.

func (*Job) Principal

func (j *Job) Principal() string

Principal returns the submitting principal.

type JobContext

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

JobContext is the agent-facing surface inside an AgentFunc. It is the only sanctioned way to emit events, validate lease ops, debit budget counters, and stream chunked results.

func (*JobContext) ArtifactRef

func (jc *JobContext) ArtifactRef(uri, contentType string, byteSize uint64, sha256 string)

ArtifactRef emits an "artifact_ref" event.

func (*JobContext) Budget

func (jc *JobContext) Budget() map[arcp.Currency]float64

Budget returns a snapshot of remaining per-currency budget.

func (*JobContext) Context

func (jc *JobContext) Context() context.Context

Context returns the cancellable context bound to this job's lifecycle.

func (*JobContext) JobID

func (jc *JobContext) JobID() string

JobID returns the owning job id.

func (*JobContext) Lease

func (jc *JobContext) Lease() arcp.Lease

Lease returns a snapshot of the job's lease grant.

func (*JobContext) Log

func (jc *JobContext) Log(level slog.Level, msg string, attrs ...slog.Attr)

Log emits a "log" job event.

func (*JobContext) Metric

func (jc *JobContext) Metric(name string, value float64, unit string, dims map[string]string)

Metric emits a "metric" event. If name begins with "cost." and unit matches a budgeted currency, the runtime debits the counter and may emit a follow-up cost.budget.remaining metric.

func (*JobContext) Progress

func (jc *JobContext) Progress(current uint64, total uint64, units, message string)

Progress emits a "progress" event.

func (*JobContext) RotateCredential

func (jc *JobContext) RotateCredential(id, newValue string) error

RotateCredential updates a stored credential value, emits a submitter status event, and revokes the prior upstream credential.

func (*JobContext) SessionID

func (jc *JobContext) SessionID() string

SessionID returns the owning session id.

func (*JobContext) Status

func (jc *JobContext) Status(phase, message string)

Status emits a "status" event.

func (*JobContext) StreamResult

func (jc *JobContext) StreamResult(encoding string) (io.WriteCloser, error)

StreamResult opens a writer that emits result_chunk events. Close terminates the stream; the runtime emits the final job.result with result_id and result_size when the AgentFunc returns.

func (*JobContext) Thought

func (jc *JobContext) Thought(text string)

Thought emits a "thought" job event.

func (*JobContext) ToolCall

func (jc *JobContext) ToolCall(tool string, args any) string

ToolCall emits a "tool_call" event and returns the generated call_id the agent should reuse in the matching ToolResult / ToolError.

func (*JobContext) ToolError

func (jc *JobContext) ToolError(callID string, err error)

ToolError emits a failed "tool_result" event.

func (*JobContext) ToolResult

func (jc *JobContext) ToolResult(callID string, result any)

ToolResult emits a successful "tool_result" event.

func (*JobContext) TraceID

func (jc *JobContext) TraceID() string

TraceID returns the trace identifier propagated from job.submit.

func (*JobContext) ValidateLeaseOp

func (jc *JobContext) ValidateLeaseOp(cap arcp.Capability, target string) error

ValidateLeaseOp checks that (cap, target) is permitted under the lease at the current clock time.

type Options

type Options struct {
	// Name is the runtime's advertised name in session.welcome.
	Name string
	// Version is the runtime's advertised version.
	Version string
	// HeartbeatInterval seeds heartbeat_interval_sec in welcome. Zero
	// disables heartbeats unless the client negotiates them; default
	// is 30s.
	HeartbeatInterval time.Duration
	// ResumeWindow seeds resume_window_sec; default 600s.
	ResumeWindow time.Duration
	// Verifier authenticates session.hello tokens. nil accepts no
	// tokens.
	Verifier auth.Verifier
	// Logger is the slog.Logger used by the runtime. nil uses
	// slog.Default().
	Logger *slog.Logger
	// Clock is the time source. nil uses clock.Real().
	Clock clock.Clock
	// AckLagThreshold is the number of unacked events that triggers a
	// back_pressure status emission. Zero disables.
	AckLagThreshold uint64
	// Features overrides the advertised feature list. Empty uses the
	// SDK default.
	Features []string
	// Provisioner mints lease-bound credentials for accepted jobs. When
	// nil, provisioned_credentials is not advertised.
	Provisioner credentials.Provisioner
	// MaxResultBytes caps a single streamed result. Zero uses 32MiB.
	MaxResultBytes int64
	// ChunkSize caps an individual result_chunk body. Zero uses 1MiB.
	ChunkSize int64
}

Options configures a Server.

type Server

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

Server is the runtime. Construct with New and call Accept once per session.

func New

func New(opts Options) *Server

New returns a Server initialised with opts.

func (*Server) Accept

func (s *Server) Accept(ctx context.Context, t transport.Transport) error

Accept runs one session over t. It blocks until t is closed, ctx is cancelled, or an unrecoverable error fires.

func (*Server) Close

func (s *Server) Close() error

Close terminates all sessions and active jobs.

func (*Server) RegisterAgent

func (s *Server) RegisterAgent(name string, fn AgentFunc)

RegisterAgent registers fn under the bare name.

func (*Server) RegisterAgentVersion

func (s *Server) RegisterAgentVersion(name, version string, fn AgentFunc)

RegisterAgentVersion registers fn under name@version.

func (*Server) SetDefaultAgentVersion

func (s *Server) SetDefaultAgentVersion(name, version string) error

SetDefaultAgentVersion records the version returned for bare-name resolution.

Jump to

Keyboard shortcuts

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