@re-cinq/floor-client 0.6.1 → 0.7.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/README.md +31 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @re-cinq/floor-client
|
|
2
2
|
|
|
3
|
-
The floor over HTTP and its live socket, typed.
|
|
3
|
+
The floor over HTTP and its live socket, typed. It has every route a floor serves, and a watch that replays an assembly run from a cursor and reconnects without losing a frame.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
import { createFloorClient, serviceToken } from "@re-cinq/floor-client";
|
|
@@ -17,19 +17,29 @@ for await (const frame of floor.runs.watch(run.id)) {
|
|
|
17
17
|
}
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
`repo` is left out for
|
|
20
|
+
`repo` is left out for an assembly line with no `git` argument. The run then has none, and `run.repo` is `null`. `floor.runs.list({ withoutRepo: true })` lists those runs.
|
|
21
21
|
|
|
22
22
|
## Where this fits
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
Anything outside a floor reaches it through this package. [`apps/cluster-agent`](../../apps/cluster-agent/README.md), [`@re-cinq/floor-station`](../station/README.md), [`@re-cinq/floor-pipeline`](../pipeline/README.md), the lore converter and lore itself all use it.
|
|
25
|
+
|
|
26
|
+
It links no part of the floor's own storage. It links only [`@re-cinq/floor-contracts`](../contracts/README.md), for the shapes, so a floor's database cannot be reached through it even by accident.
|
|
25
27
|
|
|
26
28
|
See [the map](../../README.md).
|
|
27
29
|
|
|
28
30
|
## What it decides for you
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
### Two tokens that cannot be swapped
|
|
33
|
+
|
|
34
|
+
`ServiceToken` and `VisitToken` are branded, so one cannot be passed for the other.
|
|
35
|
+
|
|
36
|
+
`createVisitClient` binds the visit id at construction and takes one in no method, so a caller cannot address another visit. The floor refuses that with a 403. Here it does not compile.
|
|
37
|
+
|
|
38
|
+
The same client has no `events.post`. It has `report()`, which fills in the event's name, its visit and its dedupe key, because none of those are the caller's to choose.
|
|
31
39
|
|
|
32
|
-
|
|
40
|
+
### A status with meaning is in the return type
|
|
41
|
+
|
|
42
|
+
Absence is `null`, and an empty queue is `[]`. Where a refusal is a real decision it is a named union:
|
|
33
43
|
|
|
34
44
|
```ts
|
|
35
45
|
const outcome = await floor.stationRuns.brief(visitId);
|
|
@@ -38,28 +48,34 @@ if (outcome.kind === "reported") return ack(event); // 409: already done, r
|
|
|
38
48
|
if (outcome.kind === "absent") return deadLetter(event); // 404: asking again will never find it
|
|
39
49
|
```
|
|
40
50
|
|
|
41
|
-
|
|
51
|
+
Before this package, a station read both as `null` and could not tell them apart. The cluster agent threw on both and retried a settled visit until the event died.
|
|
52
|
+
|
|
53
|
+
Everything else a floor refuses throws a `FloorProblem` carrying the RFC 9457 body: `status`, `title`, `detail`, and the per-field `errors` a 400 lists.
|
|
42
54
|
|
|
43
|
-
|
|
55
|
+
### A filter the floor would 400 on does not compile
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
`runs.list`, `events.feed` and `costs.summary` each need at least one filter, and the types say so.
|
|
46
58
|
|
|
47
|
-
|
|
59
|
+
### No runtime validation
|
|
60
|
+
|
|
61
|
+
The client casts, in one place. The rule is to validate across a trust boundary you do not own and annotate across one you do. `apps/api` validates what a git credential provider answers, because that is somebody else's service. The floor's own handlers are annotated with these same types, so drift is a compile error on the server and never a throw in someone else's pod.
|
|
48
62
|
|
|
49
63
|
## The live socket
|
|
50
64
|
|
|
51
65
|
`runs.watch(runId, options)` is an async iterable. It replays the run's journal from `after`, emits `caught_up`, then follows it live.
|
|
52
66
|
|
|
53
|
-
|
|
67
|
+
A dropped watch reconnects by itself. Every frame but `unsupported` carries the `seq` to return with, so the watch reopens from the last seq it handed out and misses nothing.
|
|
68
|
+
|
|
69
|
+
It does not reconnect after a refusal: a bad cursor, a missing token, no such run, or too many viewers. The last one is deliberate. Sixteen viewers is a capacity signal, and a client that retried it silently would hammer a run that is already busy.
|
|
54
70
|
|
|
55
|
-
There is no idle timeout
|
|
71
|
+
There is no idle timeout, on purpose. A caught-up quiet run says nothing for minutes. The floor's own ping already finds a dead viewer, and a client-side timer would only reconnect healthy watches.
|
|
56
72
|
|
|
57
|
-
|
|
73
|
+
An assembly run reopened by a start by hand goes on past its `run_settled`. `run_reopened` follows it, and the watch ends only at the settling the journal ends on.
|
|
58
74
|
|
|
59
|
-
One caveat for a relay: `visit_opened` and `visit_reported` carry the whole visit, `agentSettings` included
|
|
75
|
+
One caveat for a relay: `visit_opened` and `visit_reported` carry the whole visit, `agentSettings` included, which holds the model, the prompt and the image. Filter those before they reach a browser.
|
|
60
76
|
|
|
61
|
-
`runs.watchFloor(options)` follows the whole floor instead of one run
|
|
77
|
+
`runs.watchFloor(options)` follows the whole floor instead of one run. It emits `run_started` and `run_changed`, each with a run's id and nothing else. It has no cursor. The floor opens every connection with `resync`, which means "read your list again", so a watch that drops reconnects with nothing to remember. It is refused without the service token and reconnects after everything else.
|
|
62
78
|
|
|
63
79
|
## Testing against it
|
|
64
80
|
|
|
65
|
-
Both seams are injectable and neither needs a server: `fetchFn` for HTTP, `socketFn` for the live socket. With `backoffMs: () => 0`, the whole reconnect table
|
|
81
|
+
Both seams are injectable and neither needs a server: `fetchFn` for HTTP, `socketFn` for the live socket. With `backoffMs: () => 0`, the whole reconnect table can be unit-tested in milliseconds. See `live.test.ts`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@re-cinq/floor-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The floor over HTTP and its live socket, typed: definitions, runs, visits, blobs, events, schedules and costs, plus a watch that replays a run from a cursor and reconnects without losing a frame.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typecheck": "tsc --noEmit"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@re-cinq/floor-contracts": "0.
|
|
48
|
+
"@re-cinq/floor-contracts": "0.7.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.20.1",
|