@sealant/sdk-next 0.40.0-next.986 → 0.40.0-next.987
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.
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* its place across cuts. The wire frames are `sessionAttachServerFrameSchema` and
|
|
4
4
|
* `sessionAttachClientFrameSchema` in `@sealant/api-contracts`:
|
|
5
5
|
*
|
|
6
|
-
* server → client binary = one output record; text `
|
|
6
|
+
* server → client binary = one output record; text `ready` = where the journal stood as the
|
|
7
|
+
* socket opened, `seq` = the next binary frame's sequence,
|
|
7
8
|
* `skipped` = records the journal no longer holds were passed over,
|
|
8
9
|
* `error` = a client frame was refused, `end` = the session ended (then close)
|
|
9
10
|
* client → server binary = input; text `resize` | `signal`
|
|
@@ -19,6 +20,11 @@
|
|
|
19
20
|
* it was cut starts the count of cuts in a row again, so a session held open for hours behind a
|
|
20
21
|
* proxy that closes idle sockets is not given up on.
|
|
21
22
|
*
|
|
23
|
+
* `replayTarget` is the first connection's `ready`, or none once any other frame comes first (a
|
|
24
|
+
* control plane that predates it, or a replay from the run's record) or the attachment ends. A
|
|
25
|
+
* connection cut before its first frame leaves it to the next. A frame refusing input (`error`)
|
|
26
|
+
* says nothing about the replay and does not settle it.
|
|
27
|
+
*
|
|
22
28
|
* `output` holds at most {@link MAX_QUEUED_RECORDS} unread records. The socket is read whether or
|
|
23
29
|
* not anyone reads `output`, so `end` always reaches `exit`; a reader that falls further behind
|
|
24
30
|
* gets an error on `output` instead of a process that grows without bound, and `exit`, `write`,
|
|
@@ -45,6 +51,8 @@ const RECONNECT_MAX = Duration.seconds(5);
|
|
|
45
51
|
const OPEN_TIMEOUT = Duration.seconds(10);
|
|
46
52
|
const reconnectDelay = (attempt) => Effect.map(Random.nextBetween(0.8, 1.2), (factor) => Duration.times(Duration.min(Duration.times(RECONNECT_FIRST, 2 ** attempt), RECONNECT_MAX), factor));
|
|
47
53
|
const encoder = new TextEncoder();
|
|
54
|
+
/** A `ready` frame's journal sequence, or none when it is not a decimal integer. */
|
|
55
|
+
const journalSequence = (decimal) => /^\d+$/.test(decimal) ? Option.some(BigInt(decimal)) : Option.none();
|
|
48
56
|
/** The socket's URL for a connection that starts at `from`. The token never goes in it. */
|
|
49
57
|
const attachUrl = (target, from) => {
|
|
50
58
|
const url = new URL(`/v1/sessions/${encodeURIComponent(target.sessionId)}/attach`, target.baseUrl);
|
|
@@ -72,8 +80,12 @@ export const attachSession = (target) => Effect.gen(function* () {
|
|
|
72
80
|
let overflowed = false;
|
|
73
81
|
const exit = yield* Deferred.make();
|
|
74
82
|
const opened = yield* Deferred.make();
|
|
75
|
-
//
|
|
76
|
-
yield*
|
|
83
|
+
// Settled once, by the first frame or the attachment's end; later settles are no-ops.
|
|
84
|
+
const replayTarget = yield* Deferred.make();
|
|
85
|
+
const noReplayTarget = Deferred.succeed(replayTarget, Option.none());
|
|
86
|
+
// Closing the scope ends `output` for a consumer still reading it, and settles `replayTarget`
|
|
87
|
+
// for one still waiting on it.
|
|
88
|
+
yield* Effect.addFinalizer(() => Effect.andThen(Queue.end(output), noReplayTarget));
|
|
77
89
|
const socket = yield* Socket.makeWebSocket(Effect.map(Ref.get(next), (from) => attachUrl(target, from)), {
|
|
78
90
|
openTimeout: OPEN_TIMEOUT,
|
|
79
91
|
...(target.token === undefined
|
|
@@ -83,7 +95,9 @@ export const attachSession = (target) => Effect.gen(function* () {
|
|
|
83
95
|
const writer = yield* socket.writer;
|
|
84
96
|
// `output` first: a holder that ends the attachment once `exit` settles closes the scope, and
|
|
85
97
|
// the scope's `Queue.end` must not beat the error to `output`.
|
|
86
|
-
const failWith = (error) => Effect.uninterruptible(Effect.all([Queue.fail(output, error), Deferred.fail(exit, error)], {
|
|
98
|
+
const failWith = (error) => Effect.uninterruptible(Effect.all([Queue.fail(output, error), Deferred.fail(exit, error), noReplayTarget], {
|
|
99
|
+
discard: true,
|
|
100
|
+
}));
|
|
87
101
|
/** One connection: frames until the session's `end` or the socket closes. */
|
|
88
102
|
const connection = Effect.scoped(Effect.gen(function* () {
|
|
89
103
|
const reader = yield* socket.reader;
|
|
@@ -99,6 +113,12 @@ export const attachSession = (target) => Effect.gen(function* () {
|
|
|
99
113
|
if (Option.isNone(decoded))
|
|
100
114
|
continue;
|
|
101
115
|
const server = decoded.value;
|
|
116
|
+
if (server.t === "ready") {
|
|
117
|
+
yield* Deferred.succeed(replayTarget, journalSequence(server.nextSequence));
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (server.t !== "error")
|
|
121
|
+
yield* noReplayTarget;
|
|
102
122
|
if (server.t === "seq")
|
|
103
123
|
named = BigInt(server.sequence);
|
|
104
124
|
else if (server.t === "skipped") {
|
|
@@ -130,6 +150,7 @@ export const attachSession = (target) => Effect.gen(function* () {
|
|
|
130
150
|
}
|
|
131
151
|
continue;
|
|
132
152
|
}
|
|
153
|
+
yield* noReplayTarget;
|
|
133
154
|
const wanted = yield* Ref.get(next);
|
|
134
155
|
const sequence = named ?? wanted;
|
|
135
156
|
named = undefined;
|
|
@@ -229,5 +250,6 @@ export const attachSession = (target) => Effect.gen(function* () {
|
|
|
229
250
|
resize: (cols, rows) => control({ t: "resize", cols, rows }),
|
|
230
251
|
signal: (signal) => control({ t: "signal", signal }),
|
|
231
252
|
exit: Deferred.await(exit),
|
|
253
|
+
replayTarget: Deferred.await(replayTarget),
|
|
232
254
|
};
|
|
233
255
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* protocol over stdio attaches instead (`attach`): one held socket, both ways, that survives a cut.
|
|
5
5
|
*/
|
|
6
6
|
import type { CreateSessionAsUserRequest, CreateSessionRequest, ListSessionsQuery, ListSessionsResponse, SessionEnded, SessionWire } from "@sealant/api-contracts";
|
|
7
|
-
import { Context, type Effect, type Redacted, type Scope, type Stream } from "effect";
|
|
7
|
+
import { Context, type Effect, type Option, type Redacted, type Scope, type Stream } from "effect";
|
|
8
8
|
import type { EndpointError } from "../endpoint.js";
|
|
9
9
|
import type { SealantStreamRefusedError, SealantTransportError, SessionAttachError, SessionEndedError } from "../errors.js";
|
|
10
10
|
/** One output record of a session: its journal sequence and its bytes, exactly as recorded. */
|
|
@@ -57,6 +57,20 @@ export interface AttachedSession {
|
|
|
57
57
|
* not held up by a reader that is slow or gone.
|
|
58
58
|
*/
|
|
59
59
|
readonly output: Stream.Stream<SessionOutputChunk, SessionAttachError>;
|
|
60
|
+
/**
|
|
61
|
+
* Where the replay ends: the journal sequence the session's next record took when the
|
|
62
|
+
* attachment was opened, so every record before it was already written (`0n`: none was). The
|
|
63
|
+
* replay has caught up once `output` has delivered, or skipped, the records before it. Compare
|
|
64
|
+
* it with chunk sequences only, never with a run's `outputHighWater`, which counts something
|
|
65
|
+
* else.
|
|
66
|
+
*
|
|
67
|
+
* `None` when the control plane does not say: one that predates it, or a settled session
|
|
68
|
+
* replayed from the run's record, whose output ends with its `end`. It settles on the first
|
|
69
|
+
* frame received, or once the attachment ends or fails, and a reconnect never changes it.
|
|
70
|
+
* Against a control plane that predates it, an idle session attached at the end of its output
|
|
71
|
+
* receives no frame, so this waits until output arrives: bound it with a timeout there.
|
|
72
|
+
*/
|
|
73
|
+
readonly replayTarget: Effect.Effect<Option.Option<bigint>>;
|
|
60
74
|
/** Keystrokes for a `pty` session, stdin for a `pipe` one. A string is sent as UTF-8. */
|
|
61
75
|
readonly write: (data: Uint8Array | string) => Effect.Effect<void, SessionEndedError | SessionAttachError>;
|
|
62
76
|
/** Resizes a `pty` session's terminal; the control plane refuses it for a `pipe` session. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealant/sdk-next",
|
|
3
|
-
"version": "0.40.0-next.
|
|
3
|
+
"version": "0.40.0-next.987",
|
|
4
4
|
"description": "The fluent public SDK for Sealant — create a workspace, run a harness, replay the record.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"node": ">=20"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.
|
|
29
|
+
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.987"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"effect": "^4.0.5"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "2e8adb97c2ff519a2ebcf7aa3c8d788e5fd935a5",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|