@sealant/sdk-next 0.40.0-next.978 → 0.40.0-next.980

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.
@@ -52,7 +52,9 @@ export const attachSession = (target) => Effect.gen(function* () {
52
52
  : { headers: { authorization: `Bearer ${Redacted.value(target.token)}` } }),
53
53
  });
54
54
  const writer = yield* socket.writer;
55
- const failWith = (error) => Effect.all([Deferred.fail(exit, error), Queue.fail(output, error)], { discard: true });
55
+ // `output` first: a holder that ends the attachment once `exit` settles closes the scope, and
56
+ // the scope's `Queue.end` must not beat the error to `output`.
57
+ const failWith = (error) => Effect.uninterruptible(Effect.all([Queue.fail(output, error), Deferred.fail(exit, error)], { discard: true }));
56
58
  /** One connection: frames until the session's `end` or the socket closes. */
57
59
  const connection = Effect.scoped(Effect.gen(function* () {
58
60
  const reader = yield* socket.reader;
@@ -15,15 +15,17 @@ import { bindPolling, captureTrace } from "./context.js";
15
15
  * its key) and the API key the upgrade's `Authorization` header, never the URL. A socket closed
16
16
  * without `end` is reopened from the record after the last one received.
17
17
  *
18
- * The attachment is one call held on the runtime until `close()` (or the client's `close()`); its
19
- * frames are sent in order, one at a time.
18
+ * The attachment is one call held on the runtime until it ends, whichever way comes first: the
19
+ * session's `end`, the socket given up on (cut too many times in a row), `close()`, or the
20
+ * client's `close()`. Each releases the socket and settles `closed` and `exit` together; records
21
+ * already received stay in `output` for a consumer still draining it. Frames are sent in order,
22
+ * one at a time.
20
23
  */
21
24
  const openAttachment = async (ctx, sessionId, options) => {
22
25
  const trace = captureTrace(ctx);
23
26
  const opened = Promise.withResolvers();
24
27
  const detach = Deferred.makeUnsafe();
25
- // The attachment lives in one call held on the runtime until `close()`: the client's `close()`
26
- // interrupts it too, closing the socket.
28
+ // The session's end when it came first; `none` when the attachment ended without it.
27
29
  const held = ctx.runtime.run(Effect.scoped(Effect.gen(function* () {
28
30
  const config = yield* SealantConfig;
29
31
  const attached = yield* attachSession({
@@ -34,33 +36,37 @@ const openAttachment = async (ctx, sessionId, options) => {
34
36
  token: Option.getOrUndefined(config.apiKey),
35
37
  });
36
38
  opened.resolve(attached);
37
- yield* Deferred.await(detach);
39
+ // An attachment that gave up fails `exit`; its error reaches the consumer through
40
+ // `output`, so here it only ends the attachment.
41
+ return yield* Effect.raceFirst(Deferred.await(detach).pipe(Effect.as(Option.none())), attached.exit.pipe(Effect.map(Option.some), Effect.orElseSucceed(() => Option.none())));
38
42
  })), trace);
39
43
  const closed = Promise.withResolvers();
40
44
  const exit = Promise.withResolvers();
41
- // Settled once the attachment's scope closed: by `close()`, the client's `close()`, or a failure.
42
- const released = held.then(() => undefined, (error) => {
43
- opened.reject(error);
44
- return undefined;
45
- });
46
- void released.then(() => {
47
- exit.resolve(null);
48
- closed.resolve("closed");
49
- return undefined;
50
- });
51
- const attached = await opened.promise;
52
- void ctx.runtime.run(attached.exit, NO_TRACE).then((ended) => {
53
- exit.resolve({
54
- status: ended.status,
55
- ...(ended.exitCode === undefined ? {} : { exitCode: ended.exitCode }),
56
- ...(ended.exitSignal === undefined ? {} : { exitSignal: ended.exitSignal }),
57
- });
58
- closed.resolve("end");
59
- return undefined;
60
- }, () => undefined);
61
45
  // One frame at a time, in the order they were sent: a later keystroke never overtakes one that
62
46
  // waits for a reconnect.
63
47
  let detached = false;
48
+ const settle = (ended) => {
49
+ detached = true;
50
+ if (Option.isSome(ended)) {
51
+ const { status, exitCode, exitSignal } = ended.value;
52
+ exit.resolve({
53
+ status,
54
+ ...(exitCode === undefined ? {} : { exitCode }),
55
+ ...(exitSignal === undefined ? {} : { exitSignal }),
56
+ });
57
+ closed.resolve("end");
58
+ }
59
+ else {
60
+ exit.resolve(null);
61
+ closed.resolve("closed");
62
+ }
63
+ };
64
+ // Settled once the attachment's scope closed, however it ended.
65
+ void held.then(settle, (error) => {
66
+ opened.reject(error);
67
+ settle(Option.none());
68
+ });
69
+ const attached = await opened.promise;
64
70
  let sending = Promise.resolve();
65
71
  const enqueue = (frame) => {
66
72
  if (detached)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealant/sdk-next",
3
- "version": "0.40.0-next.978",
3
+ "version": "0.40.0-next.980",
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.978"
29
+ "@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.980"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "effect": "^4.0.5"
33
33
  },
34
- "gitHead": "b9433c317787909c22b74e6cb6cab08c41183504",
34
+ "gitHead": "547b65e5916e52ed583f59e8d6e98c985f6d9bf7",
35
35
  "publishConfig": {
36
36
  "access": "public"
37
37
  }