@owlmeans/client-socket 0.1.18-rc.3 → 0.1.18-rc.30

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 CHANGED
@@ -1,29 +1,33 @@
1
1
  # @owlmeans/client-socket
2
2
 
3
- React hook and factory for WebSocket connections via OwlMeans module routing.
3
+ React hook and factory for WebSocket connections via OwlMeans entrypoint routing.
4
4
 
5
5
  ## Overview
6
6
 
7
- - `ws(module, request?)` — creates a `Connection` by resolving the module URL and opening a WebSocket
8
- - `useWs(module, request?)` — React hook wrapping `ws()` with lifecycle management
7
+ - `ws(entrypoint, request?)` — creates a `Connection` from the entrypoint's URL and opens a WebSocket
8
+ - `useWs(entrypoint, request?)` — React hook wrapping `ws()` with lifecycle management; pass a
9
+ protocol-bound entrypoint directly
9
10
  - The returned `Connection` implements `@owlmeans/socket`'s `Connection` interface
10
11
 
11
12
  ## Installation
12
13
 
13
14
  ```bash
14
- bun add @owlmeans/client-socket
15
+ bun add @owlmeans/client-socket@^0.1.18-rc.30
15
16
  ```
16
17
 
17
18
  ## Usage
18
19
 
19
- Connect to a WebSocket module and observe events:
20
+ Connect to a WebSocket entrypoint and observe events:
20
21
 
21
22
  ```typescript
22
23
  import { useWs } from '@owlmeans/client-socket'
23
24
  import { MessageType } from '@owlmeans/socket'
25
+ import { useContext } from '@owlmeans/web-client'
26
+ import { appProtocols } from 'my-app-common'
24
27
 
25
28
  function ThinkingPanel({ storyId }: { storyId: string }) {
26
- const conn = useWs('story-thinking', { params: { id: storyId } })
29
+ const context = useContext()
30
+ const conn = useWs(context.entrypoint(appProtocols.api.storyThinking), { params: { id: storyId } })
27
31
 
28
32
  useEffect(() => {
29
33
  if (!conn) return
@@ -39,27 +43,29 @@ Direct connection (non-hook):
39
43
 
40
44
  ```typescript
41
45
  import { ws } from '@owlmeans/client-socket'
42
- import type { ClientModule } from '@owlmeans/client-module'
46
+ import { appProtocols } from 'my-app-common'
43
47
 
44
- const wsModule = context.module<ClientModule<string>>('story-thinking')
45
- const connection = await ws(wsModule, { params: { id: storyId } })
48
+ const wsEntrypoint = context.entrypoint(appProtocols.api.storyThinking)
49
+ const connection = await ws(wsEntrypoint, { params: { id: storyId } })
46
50
  ```
47
51
 
48
52
  ## API
49
53
 
50
- ### `ws(module, request?): Promise<Connection>`
54
+ ### `ws(entrypoint, request?): Promise<Connection>`
51
55
 
52
- Resolves the module URL, opens a WebSocket, and returns a `Connection` once the socket opens.
56
+ Builds the entrypoint's URL, opens a WebSocket, and returns a `Connection` once the socket opens.
53
57
 
54
- ### `useWs(module, request?): Connection | null`
58
+ ### `useWs(entrypoint, request?): Connection | null`
55
59
 
56
- React hook version of `ws()`. Returns `null` while connecting. Manages connection lifecycle (opens on mount, closes on unmount).
60
+ React hook version of `ws()`. Returns `null` while connecting. Manages connection lifecycle (opens
61
+ on mount, closes on unmount). Alias input is reserved for a dynamic external boundary; application
62
+ code calls `context.entrypoint(protocol)` first.
57
63
 
58
64
  ## Related Packages
59
65
 
60
66
  - [`@owlmeans/socket`](../socket) — `Connection` interface with `notify`, `observe`, `call` methods
61
67
  - [`@owlmeans/server-socket`](../server-socket) — server-side connection handler
62
- - [`@owlmeans/client-module`](../client-module) — `ClientModule` passed to `ws()`
68
+ - [`@owlmeans/client-entrypoint`](../client-entrypoint) — protocol bindings passed to `ws()`
63
69
 
64
70
  <!-- owlmeans:agent-guidance:start -->
65
71
  ## Agent guidance
@@ -69,7 +75,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
69
75
  your project's skill store (`.agents/skills/`):
70
76
 
71
77
  ```sh
72
- npx @owlmeans/agent-skills
78
+ npx @owlmeans/agent-skills@^0.1.18-rc.28
73
79
  ```
74
80
 
75
81
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/client-socket",
4
- "version": "0.1.18-rc.0",
5
- "generatedAt": "2026-08-16T22:20:50.502Z",
4
+ "version": "0.1.18-rc.30",
5
+ "generatedAt": "2026-09-17T08:16:11.216Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: client-socket
3
- description: How to use @owlmeans/client-socket — client-side WebSocket connection helpers for browsers and native clients. Auto-invoked when importing client socket primitives.
3
+ description: How to use @owlmeans/client-socket — opening a self-restoring WebSocket Connection to a socket entrypoint from browsers and native clients, the reconnect policy and its options, the socket-status aggregator, the useWs hook and the system frames a carrier emits. Auto-invoked when importing client socket primitives or wiring a browser subscription.
4
4
  user-invocable: false
5
5
  ---
6
6
  <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
@@ -8,23 +8,166 @@ user-invocable: false
8
8
  # @owlmeans/client-socket
9
9
 
10
10
  **Layer:** Client
11
- **Install:** `"@owlmeans/client-socket": "^0.1.18-rc.0"` in `dependencies`
11
+ **Install:** `"@owlmeans/client-socket": "^0.1.18-rc.30"` in `dependencies`
12
+
13
+ The browser carrier for `@owlmeans/socket`. It supplies the four members the connection model
14
+ leaves abstract — `send`, `close`, `prepare`, `authenticate` — and hands back a plain `Connection`,
15
+ so everything a screen does with the socket is the vocabulary of that package — `observe`,
16
+ `notify`, `call`, `listen`. It also restores a dropped WebSocket on its own, on the SAME
17
+ `Connection` model, so nothing a caller registered with `observe`/`listen` needs to be
18
+ re-registered after a network blip.
12
19
 
13
20
  ## Key Exports
14
21
 
15
22
  | Export | Description |
16
23
  |--------|-------------|
17
- | `Socket` types | Client socket connection shape |
18
- | Helpers | Connect, send, subscribe to channels |
24
+ | `ws(entrypoint, request?, options?)` | Open a `Connection` to a socket entrypoint. Resolves once the FIRST attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget elapses first |
25
+ | `useWs(protocol \| alias, request?, options?)` | React hook — `Connection \| null` until it opens (or gives up); re-opens on `alias`/`AUTH_QUERY`/`params` change and closes on unmount |
26
+ | `connect(address, ctx, options?)` | The same machinery with no entrypoint behind it — an `address` callback returning the URL, for an adapter or a test |
27
+ | `appendSocketStatus(ctx, alias?)` / `useSocketStatus()` | The status aggregator — see below |
28
+ | `Config` / `Context` | The client config (`socket?: SocketClientSettings`) and context types this package expects |
29
+ | `ReconnectPolicy` / `SocketClientSettings` / `ConnectOptions` / `WsOptions` | The reconnect policy shape and where it can be set — config, or per-call `options` |
30
+
31
+ ## How the address is built
32
+
33
+ A socket entrypoint is **addressed, not called**: `entrypointUrl` from
34
+ `@owlmeans/client-entrypoint/utils` turns the declaration plus the asking context into the `wss://`
35
+ URL — `:params` filled in, query appended, protocol and TLS taken from the entrypoint's address —
36
+ and the connection is opened on that. Nothing is hand-concatenated, so the same declaration the
37
+ server binds is the one the client dials. It is re-resolved on EVERY attempt, first one included,
38
+ so a `beforeConnect` hook that mutates the request's query (a refreshed token, most often) reaches
39
+ every reconnect too, not just the first handshake.
40
+
41
+ Authentication rides on the query, because a WebSocket handshake carries no Authorization header a
42
+ browser can set: the token goes under `AUTH_QUERY`, and the server derives the connection's subject
43
+ from it.
44
+
45
+ **Take the authenticated hook, not this one.** `@owlmeans/client-auth` exports its own `useWs` that
46
+ wraps this one, fills `AUTH_QUERY` from `ctx.auth().token`, and refreshes it via `beforeConnect` on
47
+ every reconnect — unless the request already carried its own token, in which case that caller's
48
+ value is left alone across reconnects too. Import `useWs` from there for anything a guard
49
+ protects, and from here only for an entrypoint that is open to everyone.
50
+
51
+ The in-band auth sequence is a different thing from the query token, and only half of it is here.
52
+ `connection.auth(stage, payload)` sends the frame and resolves on the server's reply — that is the
53
+ client-initiated exchange, and it works. This carrier's own `authenticate` is a stub answering an
54
+ empty tuple, so an `Auth` frame the SERVER opens finds no stage to answer with and is dropped
55
+ without a reply: a browser can start an exchange, never answer one.
56
+
57
+ **A reconnect is a brand-new server-side connection.** If a server sets up subscriptions only
58
+ after an in-band `authenticate` frame (as this platform's own handlers do — see the `socket`
59
+ memory in `viable`), the carrier does NOT replay that frame by itself; it only reopens the pipe.
60
+ A caller that authenticates in-band must listen for `SocketSystemEvent.Reconnected` and resend it
61
+ — `viable`'s `sources/manager-web/src/lib/ws.ts` `useAuthWs` is the worked example.
19
62
 
20
63
  ## Usage
21
64
 
22
65
  ```typescript
23
- import { connectSocket } from '@owlmeans/client-socket'
24
- const socket = await connectSocket(context, { url: 'wss://api/ws' })
25
- socket.subscribe('projects', msg => console.log(msg))
66
+ // A guarded entrypoint: this useWs fills AUTH_QUERY from the current session and keeps it fresh
67
+ // across reconnects.
68
+ import { useWs } from '@owlmeans/client-auth'
69
+
70
+ // An open one: this useWs sends whatever query it is given, and nothing more.
71
+ // import { useWs } from '@owlmeans/client-socket'
72
+
73
+ const connection = useWs(app.api.project.stream, { params: { id } })
74
+
75
+ useEffect(() => {
76
+ if (connection == null) {
77
+ return
78
+ }
79
+ const stop = connection.observe<Update>('update', async msg => apply(msg.payload))
80
+
81
+ return () => stop()
82
+ }, [connection])
26
83
  ```
27
84
 
85
+ Pass the immutable socket protocol declaration in application code. A string alias is reserved
86
+ for an adapter whose remote declaration is unavailable to import. Both hooks re-open when the
87
+ protocol, `AUTH_QUERY` value, or params change — the params are compared by content, so a fresh
88
+ object literal each render does not re-open. Both close the connection when the component unmounts,
89
+ and both answer `null` until the socket is open, so every effect that touches one guards on that.
90
+
91
+ ## Disconnects and reconnects
92
+
93
+ The carrier keeps the same `Connection` MODEL for the life of the hook/call and swaps only the
94
+ underlying `WebSocket` underneath it — every `observe`/`listen` a caller registered survives a
95
+ reconnect, because it was registered on the model, not on the socket.
96
+
97
+ **The retry policy** (`ReconnectPolicy`, defaults in `DEFAULT_RECONNECT_POLICY`):
98
+
99
+ | Field | Default | Meaning |
100
+ |---|---|---|
101
+ | `minDelay` | 200ms | First retry delay |
102
+ | `maxDelay` | 3000ms | Delay ceiling — backoff never grows past this |
103
+ | `factor` | 2 | Geometric growth per failed attempt |
104
+ | `jitter` | 0.1 | ±10% randomization on each computed delay |
105
+ | `budget` | 600000ms (10 min) | Total retry time before the carrier gives up |
106
+ | `stableAfter` | 10000ms | How long a reopened socket must stay up before the attempt count and the outage clock reset |
107
+ | `heartbeat` | 30000ms | Ping interval — runs even with `reconnect: false` |
108
+ | `pongTimeout` | 10000ms | No frame of ANY kind since the last ping past this long ⇒ the carrier force-closes the socket itself (code 4000, `SOCKET_HEARTBEAT_TIMEOUT_CODE`) — the only way a silently half-open TCP connection is noticed before the OS would, minutes later |
109
+
110
+ Set it on `ctx.cfg.socket.reconnect` (app-wide) or per call via `options.reconnect` (which wins).
111
+ `reconnect: false` disables retries — a drop is reported once and stays dropped, the
112
+ pre-reconnect-support behaviour — while the heartbeat/liveness check above still runs. Use it for
113
+ a stateful one-shot handshake a reconnect could never resume correctly (the wallet-tunnel rely
114
+ session in `client-auth` sets it for exactly this reason).
115
+
116
+ **System frames** (`SocketSystemEvent`, from `@owlmeans/socket`) reach every `connection.listen`
117
+ subscriber:
118
+
119
+ | Event | When |
120
+ |---|---|
121
+ | `disconnected` | The socket dropped and a retry IS scheduled — `{ code }` |
122
+ | `reconnecting` | Before each retry attempt — `{ attempt, delay }` |
123
+ | `reconnected` | A retry succeeded — `{ attempts }` |
124
+ | `lost` | The retry budget elapsed with no success — no payload |
125
+ | `close` | The connection is gone for GOOD: a client-initiated close, a terminal server code (1000/1008), `reconnect: false` and the one attempt failed, or right after `lost` |
126
+
127
+ ```typescript
128
+ connection.listen(async message => {
129
+ const msg = message as EventMessage<unknown>
130
+ if (typeof message !== 'object' || msg.type !== 'system') return
131
+ if (msg.event === SocketSystemEvent.Reconnected) await resubscribe()
132
+ if (msg.event === SocketSystemEvent.Close) await release()
133
+ })
134
+ ```
135
+
136
+ **The status aggregator.** `appendSocketStatus(ctx)` registers a shared service every
137
+ `ws()`/`useWs()` connection reports its state into; `useSocketStatus()` reads the WORST state
138
+ across all of them (`'online' | 'reconnecting' | 'lost'`). A connection that ends in `'lost'` is
139
+ NOT released from the aggregate — there is no `Connection` for the caller to close, since `ws()`
140
+ rejected — so the aggregate latches at `'lost'` until the page reloads. That is deliberate: it is
141
+ what `@owlmeans/web-panel`'s `SocketReloadDialog` reads to put up a global, blocking "reload the
142
+ page" prompt once every socket in the app has given up (`cfg.socket.reloadDialog`). Calling
143
+ `appendSocketStatus` unconditionally is cheap and safe for a host package — nothing reports into
144
+ it unless something calls `ws()`/`useWs()`, so an app that never does behaves exactly as before.
145
+
146
+ `useSocketStatus()` tolerates being called before the context's own `configure()`/`init()` has
147
+ run (it defaults to `'online'` and re-attaches once `ctx.waitForInitialized()` resolves) — a
148
+ component mounted as a sibling of the router, as `SocketReloadDialog` is, renders on React's
149
+ first commit, before the router's effect has had a chance to initialize the context.
150
+
151
+ Outbound frames are stamped with `dt` and dropped rather than queued while the socket is not
152
+ `OPEN`, so a `notify` issued while the socket is down is lost rather than delivered late. Nothing
153
+ here replays events the SERVER sent while the socket was down either — a caller that cannot
154
+ tolerate a gap re-syncs its own state on `reconnected` (viable's file-watch editor re-lists files;
155
+ its thinking/slot socket relies on a separate periodic API push for the same reason).
156
+
28
157
  ## Depends On
29
158
 
30
- - `@owlmeans/socket`, `@owlmeans/client-context`
159
+ - `@owlmeans/socket` — `createBasicConnection`, `MessageType`, `SocketSystemEvent`,
160
+ `SOCKET_HEARTBEAT_TIMEOUT_CODE`, `SocketConnectionError`, the `Connection` contract
161
+ - `@owlmeans/client-entrypoint` — `entrypointUrl`, `provideRequest`
162
+ - `@owlmeans/client` — `useContext`, `useValue`; `@owlmeans/client-context` — the config type
163
+ - `@owlmeans/auth` — `AUTH_QUERY`, `AuthenticationStage`
164
+ - `@owlmeans/basic-ids` — `createIdOfLength`, for the per-connection status-tracking id
165
+ - `react` (peer)
166
+
167
+ ## Related
168
+
169
+ - `socket` — the message model every verb here belongs to, and the `SocketSystemEvent` vocabulary
170
+ - `server-socket` — the far side: guard enforcement, and what it stamps on a frame
171
+ - `client-auth` — the `useWs` that carries the token and refreshes it across reconnects;
172
+ `client-job` — `useJobFeed`, a worked subscription built on it
173
+ - `web-panel` — `SocketReloadDialog`, the global blocking prompt built on `useSocketStatus()`
@@ -0,0 +1,7 @@
1
+ import type { ReconnectPolicy } from './types.js';
2
+ /**
3
+ * 0.2s → 3s geometric backoff, retried for up to 10 minutes before the carrier gives up and
4
+ * reports the connection lost. See the client-socket skill's "Disconnects" section.
5
+ */
6
+ export declare const DEFAULT_RECONNECT_POLICY: ReconnectPolicy;
7
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,eAStC,CAAA"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 0.2s → 3s geometric backoff, retried for up to 10 minutes before the carrier gives up and
3
+ * reports the connection lost. See the client-socket skill's "Disconnects" section.
4
+ */
5
+ export const DEFAULT_RECONNECT_POLICY = {
6
+ minDelay: 200,
7
+ maxDelay: 3_000,
8
+ factor: 2,
9
+ jitter: 0.1,
10
+ budget: 600_000,
11
+ stableAfter: 10_000,
12
+ heartbeat: 30_000,
13
+ pongTimeout: 10_000,
14
+ };
15
+ //# sourceMappingURL=consts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.js","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,QAAQ,EAAE,GAAG;IACb,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,GAAG;IACX,MAAM,EAAE,OAAO;IACf,WAAW,EAAE,MAAM;IACnB,SAAS,EAAE,MAAM;IACjB,WAAW,EAAE,MAAM;CACpB,CAAA"}
package/build/helper.d.ts CHANGED
@@ -1,8 +1,32 @@
1
1
  import type { ClientEntrypoint } from '@owlmeans/client-entrypoint';
2
2
  import type { AbstractRequest } from '@owlmeans/entrypoint';
3
3
  import type { Connection } from '@owlmeans/socket';
4
+ import type { EntrypointReference } from '@owlmeans/context';
5
+ import type { Context, ConnectOptions, WsOptions } from './types.js';
6
+ /**
7
+ * Open a socket with no declared entrypoint behind it — the primitive `ws()` builds on, and what
8
+ * a test drives directly against a bare WebSocket server.
9
+ */
10
+ export declare const connect: (address: () => Promise<string> | string, ctx: Context, options?: ConnectOptions) => Promise<Connection>;
11
+ /**
12
+ * Open a socket through a declared entrypoint protocol, restoring it on its own after a network
13
+ * failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
14
+ * once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
15
+ * elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
16
+ */
4
17
  export declare const ws: (module: ClientEntrypoint<string>, request?: AbstractRequest<{
5
18
  token?: string;
6
- }>) => Promise<Connection>;
7
- export declare const useWs: (module: string | ClientEntrypoint<any>, request?: Partial<AbstractRequest<any>>) => Connection | null;
19
+ }>, options?: WsOptions) => Promise<Connection>;
20
+ /**
21
+ * Open a socket through a declared entrypoint protocol.
22
+ *
23
+ * String aliases remain an adapter input for dynamically addressed integrations, while
24
+ * application callers pass their immutable protocol declaration and receive its bound client
25
+ * entrypoint here at the transport boundary.
26
+ *
27
+ * Re-opens on its own after a network drop (see `ws()`). `null` until the first attempt opens,
28
+ * and again once the retry budget elapses without one ever opening — a screen that must tell
29
+ * those two apart reads `useSocketStatus()` (from `./status.js`) alongside this.
30
+ */
31
+ export declare const useWs: (module: EntrypointReference | string, request?: Partial<AbstractRequest<any>>, options?: WsOptions) => Connection | null;
8
32
  //# sourceMappingURL=helper.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAA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,UAAU,GAAG,IAqCf,CAAA"}
package/build/helper.js CHANGED
@@ -1,44 +1,113 @@
1
1
  import { provideRequest } from '@owlmeans/client-entrypoint';
2
- import { EntrypointOutcome } from '@owlmeans/entrypoint';
3
- import { SocketInitializationError } from '@owlmeans/socket';
2
+ import { SocketConnectionError } from '@owlmeans/socket';
4
3
  import { makeConnection } from './utils/connection.js';
5
4
  import { assertContext } from '@owlmeans/context';
6
5
  import { useContext, useValue } from '@owlmeans/client';
7
6
  import { AUTH_QUERY } from '@owlmeans/auth';
8
- import { urlCall } from '@owlmeans/client-entrypoint/utils';
7
+ import { entrypointUrl } from '@owlmeans/client-entrypoint/utils';
9
8
  import { useEffect, useMemo } from 'react';
10
- export const ws = async (module, request) => {
11
- const ctx = assertContext(module.ctx, 'client-ws');
12
- request = request ?? provideRequest(module.getAlias(), module.getPath());
13
- const [url, state] = await urlCall({ ref: module })(request);
14
- if (state !== EntrypointOutcome.Ok) {
15
- throw new SocketInitializationError;
16
- }
9
+ import { createIdOfLength } from '@owlmeans/basic-ids';
10
+ import { DEFAULT_RECONNECT_POLICY } from './consts.js';
11
+ import { SOCKET_STATUS } from './status.js';
12
+ const resolvePolicy = (ctx, options) => {
13
+ const requested = options?.reconnect !== undefined ? options.reconnect : ctx.cfg.socket?.reconnect;
14
+ const retry = requested !== false;
15
+ const overrides = requested === false || requested == null ? {} : requested;
16
+ return { policy: { ...DEFAULT_RECONNECT_POLICY, ...overrides }, retry };
17
+ };
18
+ const openRawSocket = async (url) => {
17
19
  const socket = new WebSocket(url);
18
- return new Promise(resolve => {
19
- socket.onopen = () => {
20
- const heartbeat = setInterval(() => {
21
- if (socket.readyState === WebSocket.OPEN) {
22
- socket.send(JSON.stringify({ type: 'ping' }));
23
- }
24
- }, 30_000);
25
- socket.addEventListener('close', () => {
26
- console.info('WebSocket connection closed, clearing heartbeat interval.');
27
- clearInterval(heartbeat);
28
- });
29
- resolve(makeConnection(socket, ctx));
20
+ return await new Promise((resolve, reject) => {
21
+ const cleanup = () => {
22
+ socket.removeEventListener('open', onOpen);
23
+ socket.removeEventListener('error', onFail);
24
+ socket.removeEventListener('close', onFail);
30
25
  };
26
+ const onOpen = () => { cleanup(); resolve(socket); };
27
+ const onFail = () => { cleanup(); reject(new SocketConnectionError('handshake')); };
28
+ socket.addEventListener('open', onOpen);
29
+ socket.addEventListener('error', onFail);
30
+ socket.addEventListener('close', onFail);
31
+ });
32
+ };
33
+ const establish = async (ctx, policy, retry, open) => {
34
+ const statusId = createIdOfLength(8);
35
+ const status = ctx.hasService(SOCKET_STATUS)
36
+ ? ctx.socketStatus() : null;
37
+ const { connection, ready } = makeConnection({
38
+ policy, retry, open, onStatus: state => status?.report(statusId, state)
31
39
  });
40
+ const baseClose = connection.close;
41
+ connection.close = async () => {
42
+ await baseClose();
43
+ status?.release(statusId);
44
+ };
45
+ // A rejection here means `finish()` already ran and reported this id's terminal state —
46
+ // `'lost'` in every case, since the budget-exhausted path is the only one that rejects
47
+ // `ready`. Deliberately NOT released: there is no `Connection` to hand back for a caller to
48
+ // close, so the aggregate stays `'lost'` — the whole reason `SocketReloadDialog` exists — until
49
+ // the page reloads. Only a connection this function actually returns can be released, and only
50
+ // by the caller closing it on purpose.
51
+ await ready;
52
+ return connection;
53
+ };
54
+ /**
55
+ * Open a socket with no declared entrypoint behind it — the primitive `ws()` builds on, and what
56
+ * a test drives directly against a bare WebSocket server.
57
+ */
58
+ export const connect = async (address, ctx, options) => {
59
+ const { policy, retry } = resolvePolicy(ctx, options);
60
+ return await establish(ctx, policy, retry, async () => openRawSocket(await address()));
32
61
  };
33
- export const useWs = (module, request) => {
62
+ /**
63
+ * Open a socket through a declared entrypoint protocol, restoring it on its own after a network
64
+ * failure — see the client-socket skill's "Disconnects" section for the full policy. Resolves
65
+ * once the first attempt opens; rejects with `SocketConnectionError('lost')` if the retry budget
66
+ * elapses before that ever happens (or the single attempt fails, with `reconnect: false`).
67
+ */
68
+ export const ws = async (module, request, options) => {
69
+ const ctx = assertContext(module.ctx, 'client-ws');
70
+ request = request ?? provideRequest(module.alias, module.path());
71
+ const { policy, retry } = resolvePolicy(ctx, options);
72
+ return await establish(ctx, policy, retry, async () => {
73
+ await options?.beforeConnect?.(request);
74
+ const url = await entrypointUrl({ ref: module }, request);
75
+ return await openRawSocket(url);
76
+ });
77
+ };
78
+ /**
79
+ * Open a socket through a declared entrypoint protocol.
80
+ *
81
+ * String aliases remain an adapter input for dynamically addressed integrations, while
82
+ * application callers pass their immutable protocol declaration and receive its bound client
83
+ * entrypoint here at the transport boundary.
84
+ *
85
+ * Re-opens on its own after a network drop (see `ws()`). `null` until the first attempt opens,
86
+ * and again once the retry budget elapses without one ever opening — a screen that must tell
87
+ * those two apart reads `useSocketStatus()` (from `./status.js`) alongside this.
88
+ */
89
+ export const useWs = (module, request, options) => {
34
90
  const ctx = useContext();
35
- const mod = useMemo(() => typeof module === 'string' ? ctx.entrypoint(module) : module, [module]);
36
- const connection = useValue(async () => {
37
- const _request = provideRequest(mod.getAlias(), mod.getPath());
91
+ const mod = useMemo(() => ctx.entrypoint(module), [module]);
92
+ const connection = useValue(async (cancel) => {
93
+ const _request = provideRequest(mod.alias, mod.path());
38
94
  Object.assign(_request, request);
39
- return await ws(mod, _request);
95
+ try {
96
+ const conn = await ws(mod, _request, options);
97
+ if (cancel?.current) {
98
+ // The component unmounted while the handshake (or its retries) were still in flight —
99
+ // there is no `useEffect` cleanup coming for this value, so close it here instead of
100
+ // leaving a live socket and its retry timers attached to nothing.
101
+ void conn.close();
102
+ return null;
103
+ }
104
+ return conn;
105
+ }
106
+ catch {
107
+ return null;
108
+ }
40
109
  }, [
41
- mod.getAlias(),
110
+ mod.alias,
42
111
  request?.query?.[AUTH_QUERY],
43
112
  request?.params ? JSON.stringify(request.params) : undefined
44
113
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CA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sF;gBACtF,qFAAqF;gBACrF,kEAAkE;gBAClE,KAAK,IAAI,CAAC,KAAK,EAAE,CAAA;gBACjB,OAAO,IAAI,CAAA;YACb,CAAC;YACD,OAAO,IAAI,CAAA;QACb,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAA;QACb,CAAC;IACH,CAAC,EAAE;QACD,GAAG,CAAC,KAAK;QACT,OAAO,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC;QAC5B,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS;KAC7D,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,OAAO,GAAG,EAAE;gBACV,KAAK,UAAU,CAAC,KAAK,EAAE,CAAA;YACzB,CAAC,CAAA;QACH,CAAC;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAEhB,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export type * from './types.js';
2
+ export * from './consts.js';
2
3
  export * from './helper.js';
4
+ export * from './status.js';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,mBAAmB,YAAY,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
package/build/index.js CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './consts.js';
1
2
  export * from './helper.js';
3
+ export * from './status.js';
2
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,22 @@
1
+ import type { Config, Context, SocketConnectionState, SocketStatusService, SocketStatusServiceAppend } from './types.js';
2
+ export declare const SOCKET_STATUS = "socket-status";
3
+ /**
4
+ * Aggregates the coarse health of every `ws()`/`useWs()` connection an app has open into one
5
+ * worst-of-all state. A page with several sockets (thinking stream, file watch, notifications…)
6
+ * still shows one dialog, not one per socket — so the aggregate, not any single connection, is
7
+ * what a UI like `SocketReloadDialog` reads.
8
+ */
9
+ export declare const createSocketStatusService: (alias?: string) => SocketStatusService;
10
+ /**
11
+ * Register the shared socket-status aggregator. Idempotent, and cheap enough for a host package
12
+ * (`@owlmeans/web-panel`) to call unconditionally on every context: every `ws()`/`useWs()`
13
+ * connection reports itself here if — and only if — the context carries this service, so an app
14
+ * that never calls this behaves exactly as it did before reconnect support existed.
15
+ */
16
+ export declare const appendSocketStatus: <C extends Config = Config, T extends Context<C> = Context<C>>(ctx: T, alias?: string) => T & SocketStatusServiceAppend;
17
+ /**
18
+ * The worst state across every live `ws()`/`useWs()` connection, or `'online'` if the app never
19
+ * registered the status service (`appendSocketStatus`) or has not finished initializing yet.
20
+ */
21
+ export declare const useSocketStatus: () => SocketConnectionState;
22
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../src/status.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,MAAM,EAAE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,yBAAyB,EACvF,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAI5C;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,WAAW,MAAM,KAAmB,mBAyBzE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,OACxF,CAAC,UAAS,MAAM,KACpB,CAAC,GAAG,yBAON,CAAA;AAiBD;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAO,qBA2BlC,CAAA"}