@plurnk/plurnk-schemes-http 1.3.11 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.defaults CHANGED
@@ -1,9 +1,9 @@
1
1
  # @plurnk/plurnk-schemes-http — .env.defaults (operator config + defaults floor).
2
2
  #
3
3
  # Every knob this package reads, family-namespaced PLURNK_SCHEMES_HTTP_*. This
4
- # file IS the operator documentation, and the daemon assembles every installed
5
- # member's .env.defaults into one operative floor at boot — set-if-unset under
6
- # the operator's env (service SPEC §operator-config-env-defaults, schemes#31).
4
+ # file is the canonical value registry; {§http-config} owns policy. The daemon
5
+ # assembles every installed member's .env.defaults into one operative floor at
6
+ # boot, set-if-unset under the operator's env {§operator-config-env-defaults}.
7
7
  # UNCOMMENTED keys are real defaults the floor sets. COMMENTED keys are modes
8
8
  # whose ABSENCE is meaningful (unset = the documented behavior) — the floor
9
9
  # must not set them. Standalone (no daemon), the required numerics fail hard
@@ -21,8 +21,8 @@ PLURNK_SCHEMES_HTTP_SALVAGE_MIN_BODY_CHARS=200
21
21
  PLURNK_SCHEMES_HTTP_IDLE_TIMEOUT=900000
22
22
 
23
23
  # ── Defaults (floor-set; override to change) ────────────────────────────────
24
- # Playwright BrowserType method. "launch" uses the compatible bundled Chromium
25
- # unless CHANNEL or EXECUTABLE_PATH selects another local browser. "connect"
24
+ # Playwright BrowserType method. "launch" uses an operator-provisioned compatible
25
+ # Chromium unless CHANNEL or EXECUTABLE_PATH selects another local browser. "connect"
26
26
  # uses a Playwright protocol endpoint; "connectOverCDP" attaches to a running
27
27
  # Chromium browser; "disabled" explicitly removes rendered HTML retrieval.
28
28
  PLURNK_SCHEMES_HTTP_PLAYWRIGHT_METHOD=launch
@@ -44,13 +44,16 @@ PLURNK_SCHEMES_HTTP_MOBILE=1
44
44
  # 0 opts into revalidation on every read via ETag/304.
45
45
  # Required read: unset crashes, naming the var.
46
46
  PLURNK_SCHEMES_HTTP_TTL_MS=300000
47
- # Max HTTP redirect hops the SSRF-guarded fetch follows (WebFetcher). Each hop is
48
- # re-guarded — a public URL redirecting into private space is refused. 0 follows
49
- # none (strictest). Required read: unset crashes, naming the var.
47
+ # Max HTTP redirect hops automatic WebFetcher acquisition follows. Every hop is
48
+ # checked; 0 follows none. Required read: unset crashes, naming the var.
50
49
  PLURNK_SCHEMES_HTTP_REDIRECTS=5
51
50
  # Maximum buffered characters in one incomplete SSE line/event. Exceeding this
52
51
  # bound terminates the remote stream instead of allowing unbounded memory growth.
53
52
  PLURNK_SCHEMES_HTTP_SSE_MAX_BUFFER_CHARS=1048576
53
+ # Maximum characters retained from a caught fetch, render, or transport
54
+ # diagnostic in a model-facing Problem detail. Complete errors remain in daemon
55
+ # diagnostics.
56
+ PLURNK_SCHEMES_HTTP_ERROR_DETAIL_LIMIT=512
54
57
 
55
58
  # ── Optional modes (absence IS the mode — never floor-set) ──────────────────
56
59
  # Required by connect/connectOverCDP: the Playwright or CDP endpoint.
@@ -63,7 +66,6 @@ PLURNK_SCHEMES_HTTP_SSE_MAX_BUFFER_CHARS=1048576
63
66
  # Chromium JS heap cap in MB (--max-old-space-size). Unset → chromium default.
64
67
  # PLURNK_SCHEMES_HTTP_CHROMIUM_HEAP_MB=2048
65
68
 
66
- # Native Playwright installation controls remain authoritative and pass through
67
- # unchanged. These examples are intentionally unset.
69
+ # Native Playwright browser-location controls remain authoritative. This example
70
+ # is intentionally unset; the package never supplies its own path.
68
71
  # PLAYWRIGHT_BROWSERS_PATH=/var/cache/ms-playwright
69
- # PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1
package/README.md CHANGED
@@ -1,41 +1,88 @@
1
1
  # plurnk-schemes-http
2
2
 
3
- `http(s)://` URI scheme handler for the [plurnk](https://github.com/plurnk/plurnk-service) agent runtime. The **first greenfield `@plurnk/plurnk-schemes-*` sibling** — authored entirely against the DB-free capability contract ([`@plurnk/plurnk-schemes`](https://github.com/plurnk/plurnk-service/tree/main/plurnk-schemes) `SchemeCtx`), importing zero plurnk-service internals.
3
+ HTTP(S) request/response and WebSocket scheme handlers for the
4
+ [plurnk](https://github.com/plurnk/plurnk-service) agent runtime. The package is
5
+ authored against the DB-free
6
+ [`@plurnk/plurnk-schemes`](https://github.com/plurnk/plurnk-service/tree/main/plurnk-schemes)
7
+ `SchemeCtx` contract.
4
8
 
5
- ## What it does
9
+ ## HTTP operations
6
10
 
7
- Lets the model treat any web URL as an addressable, streamable resource:
11
+ | Operation | Behavior |
12
+ | --------------------------------- | ----------------------------------------------------------------------------------------- |
13
+ | Unscoped `READ(http(s)://…)` | Fetch or reuse/revalidate a GET representation, then stream the selected response channel |
14
+ | Scoped `READ(http(s)://…)<scope>` | Apply the standard entry READ to an already-materialized response without refetching |
15
+ | `FIND(http(s)://…):matcher` | Materialize an exact URL when required, then use the universal entry query and matcher |
16
+ | `SEND[200](http(s)://…):body:` | POST the body and stream the response |
17
+ | `EDIT(http(s)://…):body:` | PUT a whole-resource replacement; line-scoped HTTP edits are invalid |
18
+ | `KILL(http(s)://…)` | DELETE the remote resource and stream the response |
19
+ | `SEND[499](http(s)://…)` | Cancel the routed in-flight subscription |
20
+ | `SEND[410](http(s)://…)` | Delete the local stored response entry |
8
21
 
9
- | Op | Behavior |
10
- |---|---|
11
- | `READ(http(s)://host/path)` | Without `<scope>`, fetch/revalidate the URL and stream its readable body. With `<scope>`, read that range from the materialized response without refetching. |
12
- | `FIND(http(s)://host/path):matcher` | Materialize an exact URL when necessary, then query it through the standard entry FIND contract. Glob/regex scopes query already-materialized web entries. |
13
- | `SEND[200](http(s)://…)` | Request with a body (POST); response streams back the same way. |
14
- | `SEND[499](http(s)://…)` | Cancel an in-flight request (abort the fetch). |
15
- | `SEND[410](http(s)://…)` | Delete the cached response entry. |
22
+ A path-pattern FIND surveys already-materialized web entries; it does not crawl
23
+ or discover the remote web. Exact FIND and matcher READ share the standard
24
+ catalog, matcher evidence, weighting, pagination, and status contract.
16
25
 
17
- Response status + headers land in the `header` channel; the body in `body` (the default).
26
+ ## HTTP channels
18
27
 
19
- ## Channels
28
+ | Channel | Content |
29
+ | -------- | ----------------------------------------------------------------------- |
30
+ | `body` | Text, derived Unicode, typed binary marker, SSE data, or readable HTML |
31
+ | `header` | HTTP status line, headers, and package acquisition metadata |
32
+ | `html` | Faithful HTML used to produce the readable body |
20
33
 
21
- - `body` — response payload (default channel).
22
- - `header` — `HTTP <status> <statusText>` line + response headers.
34
+ A fragmentless operation publishes only `body`; auxiliary channels remain
35
+ durable and can be addressed explicitly. Remote HTTP status is stored in
36
+ `header`; the PLURNK operation result reports the streaming lifecycle.
37
+ Binary responses use an installed bounded readable projection when available;
38
+ only derived Unicode becomes durable. Otherwise direct operations preserve a
39
+ typed empty marker and return `415`, while exact query preparation prunes the
40
+ unreadable result from automatic search ingestion. Input above the common
41
+ projection ceiling returns `413`.
23
42
 
24
43
  ## Design
25
44
 
26
- - **Streaming via the capability `subscriptions` lifecycle** (`open` → `notifyChunk` → `close`). `open()` returns the worker+teardown-composed `AbortSignal`; a `SubscriptionHandle` is registered so the engine routes `SEND[499]` cancellation to the in-flight `fetch`.
27
- - **Batteries-included rendering** — installation provisions Playwright's compatible Chromium and daemon boot verifies it. The shipped `.env.defaults` also exposes Playwright `launch`, `connect`, and `connectOverCDP`: launch may select an installed browser channel or executable, while connection methods target an operator-managed browser. Rendering may be explicitly disabled; incompatible choices fail instead of falling back silently.
28
- - **DB-free** — reaches the substrate only through `ctx` capabilities (`subscriptions`, `entries`), never a raw DB handle (plurnk-schemes SPEC §5). This is what the keystone capability ctx made possible.
45
+ - WebFetcher checks automatic byte targets and redirects; direct HTTP,
46
+ Playwright, and WebSocket use their ordinary configured transports.
47
+ - Direct GET HTML is rendered through Playwright, projected into `body`, and
48
+ retained faithfully in `html`.
49
+ - GET representations carry method, acquisition-time, and single-variant cache
50
+ metadata; derived representations also carry projection identity. Explicit
51
+ request metadata, `Vary`, `no-store`, expired origin freshness, or a reader
52
+ change prevents unsafe reuse; the operator TTL remains an independent ceiling.
53
+ - HTTP(S) and WS(S) entry identity retains protocol, authority, path, ordered
54
+ query, and explicit empty query; a fragment selects a channel.
55
+ - Handler-owned browser and socket state follows the shared readiness, drain,
56
+ and aggregate-shutdown lifecycle.
57
+ - All storage and streaming work uses `SchemeCtx` capabilities rather than a
58
+ raw database handle.
59
+
60
+ The same package registers `wss` (with `ws` routing to it) for
61
+ workspace-scoped full-duplex connections. See [`docs/wss.md`](docs/wss.md) for
62
+ its operation surface and current transport limits.
29
63
 
30
64
  ## Install
31
65
 
32
- ```
33
- npm i @plurnk/plurnk-schemes-http && plurnk start
66
+ Requires Node.js 26 or newer.
67
+
68
+ ```sh
69
+ npm i @plurnk/plurnk-schemes-http
70
+ plurnk start
34
71
  ```
35
72
 
36
- Plugin discovery registers it at boot (`package.json#plurnk.kind === "scheme"`).
37
- No browser setup is required for the default installation.
73
+ The Playwright client is included. Provision a compatible local browser
74
+ separately, select an external Playwright/CDP endpoint, or disable rendering.
75
+ The shipped `.env.defaults` is the canonical operator configuration registry.
38
76
 
39
- ## Tests
77
+ For local `launch`:
40
78
 
41
- `test:lint` (tsc) + `test:unit` (conformant `SchemeCtx` stub + mock `fetch`).
79
+ ```sh
80
+ npx playwright install chromium
81
+ ```
82
+
83
+ ## Verify
84
+
85
+ ```sh
86
+ npm test
87
+ npm run test:intg
88
+ ```