serve

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: BSD-3-Clause Imports: 13 Imported by: 1 module, 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 serve is the HTTP face of agentscope: it serves the wasm UI and the gRPC-over-WebSocket endpoint on one loopback origin.

What a page served here can reach is the whole point of the design, so it is narrow and stated:

  • the listener is bound to a loopback address and refuses any other;
  • every request, the WebSocket upgrade included, must carry a Host header naming the loopback address and port actually bound -- a DNS-rebinding page reaches this server with its own name in Host, and is answered 421;
  • the WebSocket handshake additionally checks Origin against Host (the transport's same-origin default), so a page on another origin cannot open the stream even if it knew the port;
  • the only methods are GET and HEAD, the only data is the read-only snapshot, and there is no endpoint that writes to the machine;
  • responses carry a CSP that allows the page's own scripts and the wasm it instantiates, nothing from elsewhere.

Index

Constants

View Source
const GRPCPath = "/grpc"

GRPCPath is where the WebSocket carrying gRPC is mounted.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Addr  string // host:port; the host must be a loopback IP; port 0 picks one
	Web   fs.FS  // the UI: index.html, app.wasm, wasm_exec.js, ...
	Scope wire.Scope
}

Config configures a Server.

type Server

type Server struct {

	// Hosts are the Host header values accepted.
	Hosts []string
	// contains filtered or unexported fields
}

Server is a bound, not yet serving, agentscope server.

func New

func New(c Config) (*Server, error)

New binds the listener and builds the handlers.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve runs until ctx ends, then shuts down.

func (*Server) URL

func (s *Server) URL() string

URL is the address to open.

Jump to

Keyboard shortcuts

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