feat(seatpool): the seat pool and the board several drivers share
The seats of .env and the ledger, the probe, placement, settling a
finished pass, the child's credentials, the OpenRouter seats, and the
board every driver on the machine shares, in one shape and under one
lock. A driver is alive while its lifetime lock is held; with no lock file
natively its pid and start time decide, and in the sandbox it is taken for
alive.
:Http is the HTTP the driver needs, on FetchHTTP1: a status outside 2xx is
HttpError, every other failure carries a fixed text. :Platform gains
MakeDirs, with the last directory's own mode, and errno texts for its
writes and locks.
The tests cover the seat pool and several drivers at once, less the checks
that drive the pool's Scheduler, Admission and Stacks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 08:15:03 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
|
|
|
|
|
|
|
|
|
export module Crafter.Review:Http;
|
|
|
|
|
import std;
|
|
|
|
|
import :Json;
|
|
|
|
|
|
|
|
|
|
// The HTTP the driver needs: app_ready's preflight, the OpenRouter catalogue
|
2026-10-31 20:46:13 +01:00
|
|
|
// and key probe. On Crafter.Network's ClientHTTP1::Fetch, which follows redirects; on
|
feat(seatpool): the seat pool and the board several drivers share
The seats of .env and the ledger, the probe, placement, settling a
finished pass, the child's credentials, the OpenRouter seats, and the
board every driver on the machine shares, in one shape and under one
lock. A driver is alive while its lifetime lock is held; with no lock file
natively its pid and start time decide, and in the sandbox it is taken for
alive.
:Http is the HTTP the driver needs, on FetchHTTP1: a status outside 2xx is
HttpError, every other failure carries a fixed text. :Platform gains
MakeDirs, with the last directory's own mode, and errno texts for its
writes and locks.
The tests cover the seat pool and several drivers at once, less the checks
that drive the pool's Scheduler, Admission and Stacks.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 08:15:03 +01:00
|
|
|
// top of it a status outside 2xx thrown as HttpError, and every other failure
|
|
|
|
|
// as Error with a fixed text, because those texts reach the run log and
|
|
|
|
|
// app_ready's detail. Proxies are not consulted (AGENTS.md).
|
|
|
|
|
export namespace Crafter::Review::Http {
|
|
|
|
|
struct Response {
|
|
|
|
|
std::int32_t status = 0;
|
|
|
|
|
std::string body;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A status outside 2xx. what(): "HTTP Error 404: Not Found", with the
|
|
|
|
|
// standard reason phrase rather than the server's.
|
|
|
|
|
class HttpError : public std::runtime_error {
|
|
|
|
|
public:
|
|
|
|
|
HttpError(std::int32_t code, const std::string& message);
|
|
|
|
|
explicit HttpError(std::int32_t code);
|
|
|
|
|
std::int32_t Code() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::int32_t code;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Every other failure. What fails while the request goes out reads
|
|
|
|
|
// "<urlopen error [Errno 111] Connection refused>" or "<urlopen error
|
|
|
|
|
// timed out>"; what fails while the response comes in reads as it is:
|
|
|
|
|
// "timed out".
|
|
|
|
|
class Error : public std::runtime_error {
|
|
|
|
|
public:
|
|
|
|
|
using std::runtime_error::runtime_error;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A GET of `url`, read whole. Header names in any case; Accept-Encoding:
|
|
|
|
|
// identity and Connection: close always go out, and a User-Agent unless
|
|
|
|
|
// one is given.
|
|
|
|
|
Response UrlOpen(std::string_view url, const std::map<std::string, std::string>& headers, double timeout);
|
|
|
|
|
// The body as JSON: Dyn::Error JSONDecodeError (or UnicodeDecodeError)
|
|
|
|
|
// with the scanner's message for a body that is not.
|
|
|
|
|
Json JsonBody(const Response& response);
|
|
|
|
|
// http.HTTPStatus(code).phrase, "" for a code it does not know.
|
|
|
|
|
std::string_view Reason(std::int32_t code);
|
|
|
|
|
}
|