@devicerail/client 0.1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 DeviceRail contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @devicerail/client
2
+
3
+ Typed Node.js client for the DeviceRail public protocol. The stdio/NDJSON
4
+ connection is the control plane and supports bounded writes, concurrent
5
+ response correlation, request cancellation, and graceful shutdown.
6
+
7
+ Every inbound method response is validated as a complete JSON-RPC envelope
8
+ against its canonical generated response Schema before the pending request is
9
+ settled. A Schema violation is terminal and rejects all pending work. The
10
+ response Schemas are generated into the published client, and their validators
11
+ are compiled once and cached for the process.
12
+
13
+ The stock stdio/NDJSON and WebSocket receive paths also apply a fixed
14
+ pure-JSON defensive complexity budget before Schema validation: at most
15
+ 100,000 visited JSON values and a maximum nesting depth of 256. This budget is
16
+ independent of the transports' byte limits, so an exceptionally complex
17
+ message can be rejected before it reaches the configured byte ceiling.
18
+
19
+ Protocol 1.4's optional `session.export.page.v1` keeps legacy
20
+ `session.export({sessionId})` unchanged. When the Feature is enabled, callers
21
+ may add `limit` (1–1000) and optional `afterSequence`, then follow the returned
22
+ `nextAfterSequence` until it is omitted. Both the Node and Python clients reject
23
+ paged parameters locally when the Feature was not negotiated.
24
+
25
+ Protocol 1.5 keeps three boundaries independently negotiable. The client
26
+ requires `observation.uiSnapshot.v1` before `ui.snapshot.get`,
27
+ `device.semanticActions.v1` before sending any of the five canonical semantic
28
+ Action names through `device.execute`, and `verdict.record.v1` before
29
+ `verdict.record`. UI Snapshot reads are scoped to an Observation in the
30
+ current active Session. `verdict.record` persists a caller-produced Verdict;
31
+ the client and daemon do not infer pass/fail or run model-based assertions.
32
+
33
+ When `media.stream.v1` is negotiated, the typed production lifecycle is:
34
+
35
+ ```ts
36
+ const streamId = crypto.randomUUID();
37
+ await client.call("media.stream.start", { kind: "screenshot", streamId });
38
+ const captured = await client.call(
39
+ "media.stream.capture",
40
+ { frameIndex: 1, streamId },
41
+ { timeoutMs: 15_000 },
42
+ );
43
+ await client.call("media.stream.end", { streamId });
44
+ ```
45
+
46
+ Reuse the same `frameIndex` only to retry an identical capture whose response
47
+ was lost. A video capture additionally requires a positive `durationMs`; it
48
+ produces a timed PNG key frame rather than an encoded video container. The
49
+ client rejects all three calls locally unless the Feature was negotiated.
50
+
51
+ When Protocol 1.3 negotiates `events.stream.v1`, `openEventStream()` obtains a
52
+ short-lived loopback capability over stdio and opens the separate WebSocket
53
+ data plane:
54
+
55
+ ```ts
56
+ const stream = await client.openEventStream({ sessionId });
57
+
58
+ for await (const item of stream) {
59
+ await persist(item.event);
60
+ const durableCursor = item.confirm();
61
+ await saveCursor(durableCursor);
62
+ }
63
+ ```
64
+
65
+ Receiving or yielding an event does not confirm it. `item.confirm()` must be
66
+ called once, in contiguous sequence order, after the application has durably
67
+ accepted the event. If the socket fails, `stream.resume()` requests a fresh
68
+ single-use capability from only the last confirmed cursor. Abort, local queue
69
+ overflow, cursor mismatch, remote terminal states, and early socket closure
70
+ surface as explicit typed errors.
71
+
72
+ The WebSocket offers exactly the protocol version selected by the control
73
+ connection. Protocol 1.3 rejects 1.4 media lifecycle payloads; Protocol 1.4
74
+ accepts them without weakening strict event validation.
75
+
76
+ The default Node WebSocket sends no browser Origin. Browser callers must issue
77
+ the capability with one exact canonical `http(s)://127.0.0.1:<non-default-port>`
78
+ Origin policy. Remote hosts, ambient credentials, compression, and remote
79
+ authentication are not part of this loopback transport.
@@ -0,0 +1,76 @@
1
+ import type { EventsStreamTermination, RpcError, RpcId } from "@devicerail/protocol";
2
+ export type ClientErrorCode = "duplicate_request_id" | "event_stream_aborted" | "event_stream_closed" | "event_stream_cursor" | "event_stream_queue_overflow" | "event_stream_remote_termination" | "feature_not_negotiated" | "handshake_state" | "incomplete_ndjson_frame" | "invalid_ndjson_utf8" | "ndjson_frame_too_large" | "protocol_violation" | "pending_request_limit" | "request_aborted" | "remote_rpc_error" | "transport_closed" | "write_frame_too_large" | "write_queue_overflow";
3
+ export declare class DeviceRailClientError extends Error {
4
+ readonly code: ClientErrorCode;
5
+ constructor(code: ClientErrorCode, message: string, options?: ErrorOptions);
6
+ }
7
+ export declare class NdjsonFrameTooLargeError extends DeviceRailClientError {
8
+ readonly actualBytes: number;
9
+ readonly limitBytes: number;
10
+ constructor(limitBytes: number, actualBytes: number);
11
+ }
12
+ export declare class NdjsonInvalidUtf8Error extends DeviceRailClientError {
13
+ constructor(cause: unknown);
14
+ }
15
+ export declare class NdjsonIncompleteFrameError extends DeviceRailClientError {
16
+ readonly bufferedBytes: number;
17
+ constructor(bufferedBytes: number);
18
+ }
19
+ export declare class WriteFrameTooLargeError extends DeviceRailClientError {
20
+ readonly actualBytes: number;
21
+ readonly limitBytes: number;
22
+ constructor(limitBytes: number, actualBytes: number);
23
+ }
24
+ export declare class WriteQueueOverflowError extends DeviceRailClientError {
25
+ constructor(message: string);
26
+ }
27
+ export declare class TransportClosedError extends DeviceRailClientError {
28
+ constructor(message?: string, options?: ErrorOptions);
29
+ }
30
+ export declare class ProtocolViolationError extends DeviceRailClientError {
31
+ constructor(message: string, options?: ErrorOptions);
32
+ }
33
+ export declare class HandshakeStateError extends DeviceRailClientError {
34
+ constructor(message: string);
35
+ }
36
+ export declare class DuplicateRequestIdError extends DeviceRailClientError {
37
+ readonly requestId: RpcId;
38
+ constructor(requestId: RpcId);
39
+ }
40
+ export declare class RpcRemoteError extends DeviceRailClientError {
41
+ readonly requestId: RpcId;
42
+ readonly rpcError: RpcError;
43
+ constructor(requestId: RpcId, rpcError: RpcError);
44
+ }
45
+ export declare class FeatureNotNegotiatedError extends DeviceRailClientError {
46
+ readonly feature: string;
47
+ readonly method: string;
48
+ constructor(method: string, feature: string);
49
+ }
50
+ export declare class PendingRequestLimitError extends DeviceRailClientError {
51
+ readonly limit: number;
52
+ constructor(limit: number);
53
+ }
54
+ export declare class RequestAbortedError extends DeviceRailClientError {
55
+ constructor();
56
+ }
57
+ export declare class EventStreamAbortedError extends DeviceRailClientError {
58
+ constructor(message?: string);
59
+ }
60
+ export declare class EventStreamClosedError extends DeviceRailClientError {
61
+ readonly closeCode: number;
62
+ readonly closeReason: string;
63
+ constructor(closeCode: number, closeReason: string);
64
+ }
65
+ export declare class EventStreamCursorError extends DeviceRailClientError {
66
+ constructor(message: string);
67
+ }
68
+ export declare class EventStreamQueueOverflowError extends DeviceRailClientError {
69
+ readonly limitBytes: number;
70
+ readonly limitEvents: number;
71
+ constructor(limitEvents: number, limitBytes: number);
72
+ }
73
+ export declare class EventStreamRemoteTerminationError extends DeviceRailClientError {
74
+ readonly termination: EventsStreamTermination;
75
+ constructor(termination: EventsStreamTermination);
76
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,132 @@
1
+ export class DeviceRailClientError extends Error {
2
+ code;
3
+ constructor(code, message, options) {
4
+ super(message, options);
5
+ this.name = new.target.name;
6
+ this.code = code;
7
+ }
8
+ }
9
+ export class NdjsonFrameTooLargeError extends DeviceRailClientError {
10
+ actualBytes;
11
+ limitBytes;
12
+ constructor(limitBytes, actualBytes) {
13
+ super("ndjson_frame_too_large", `NDJSON frame is ${actualBytes} bytes; the limit is ${limitBytes} bytes`);
14
+ this.limitBytes = limitBytes;
15
+ this.actualBytes = actualBytes;
16
+ }
17
+ }
18
+ export class NdjsonInvalidUtf8Error extends DeviceRailClientError {
19
+ constructor(cause) {
20
+ super("invalid_ndjson_utf8", "NDJSON frame is not valid UTF-8", {
21
+ cause,
22
+ });
23
+ }
24
+ }
25
+ export class NdjsonIncompleteFrameError extends DeviceRailClientError {
26
+ bufferedBytes;
27
+ constructor(bufferedBytes) {
28
+ super("incomplete_ndjson_frame", `transport ended with an incomplete ${bufferedBytes}-byte NDJSON frame`);
29
+ this.bufferedBytes = bufferedBytes;
30
+ }
31
+ }
32
+ export class WriteFrameTooLargeError extends DeviceRailClientError {
33
+ actualBytes;
34
+ limitBytes;
35
+ constructor(limitBytes, actualBytes) {
36
+ super("write_frame_too_large", `outbound NDJSON frame is ${actualBytes} bytes; the limit is ${limitBytes} bytes`);
37
+ this.limitBytes = limitBytes;
38
+ this.actualBytes = actualBytes;
39
+ }
40
+ }
41
+ export class WriteQueueOverflowError extends DeviceRailClientError {
42
+ constructor(message) {
43
+ super("write_queue_overflow", message);
44
+ }
45
+ }
46
+ export class TransportClosedError extends DeviceRailClientError {
47
+ constructor(message = "DeviceRail transport is closed", options) {
48
+ super("transport_closed", message, options);
49
+ }
50
+ }
51
+ export class ProtocolViolationError extends DeviceRailClientError {
52
+ constructor(message, options) {
53
+ super("protocol_violation", message, options);
54
+ }
55
+ }
56
+ export class HandshakeStateError extends DeviceRailClientError {
57
+ constructor(message) {
58
+ super("handshake_state", message);
59
+ }
60
+ }
61
+ export class DuplicateRequestIdError extends DeviceRailClientError {
62
+ requestId;
63
+ constructor(requestId) {
64
+ super("duplicate_request_id", `RPC request id is already pending: ${String(requestId)}`);
65
+ this.requestId = requestId;
66
+ }
67
+ }
68
+ export class RpcRemoteError extends DeviceRailClientError {
69
+ requestId;
70
+ rpcError;
71
+ constructor(requestId, rpcError) {
72
+ super("remote_rpc_error", rpcError.message);
73
+ this.requestId = requestId;
74
+ this.rpcError = rpcError;
75
+ }
76
+ }
77
+ export class FeatureNotNegotiatedError extends DeviceRailClientError {
78
+ feature;
79
+ method;
80
+ constructor(method, feature) {
81
+ super("feature_not_negotiated", `${method} requires negotiated protocol feature ${feature}`);
82
+ this.method = method;
83
+ this.feature = feature;
84
+ }
85
+ }
86
+ export class PendingRequestLimitError extends DeviceRailClientError {
87
+ limit;
88
+ constructor(limit) {
89
+ super("pending_request_limit", `the client already has ${limit} pending requests`);
90
+ this.limit = limit;
91
+ }
92
+ }
93
+ export class RequestAbortedError extends DeviceRailClientError {
94
+ constructor() {
95
+ super("request_aborted", "the request AbortSignal was already aborted");
96
+ }
97
+ }
98
+ export class EventStreamAbortedError extends DeviceRailClientError {
99
+ constructor(message = "the event stream was aborted") {
100
+ super("event_stream_aborted", message);
101
+ }
102
+ }
103
+ export class EventStreamClosedError extends DeviceRailClientError {
104
+ closeCode;
105
+ closeReason;
106
+ constructor(closeCode, closeReason) {
107
+ super("event_stream_closed", `the WebSocket closed before an events.stream.terminal notification (code ${closeCode}${closeReason ? `: ${closeReason}` : ""})`);
108
+ this.closeCode = closeCode;
109
+ this.closeReason = closeReason;
110
+ }
111
+ }
112
+ export class EventStreamCursorError extends DeviceRailClientError {
113
+ constructor(message) {
114
+ super("event_stream_cursor", message);
115
+ }
116
+ }
117
+ export class EventStreamQueueOverflowError extends DeviceRailClientError {
118
+ limitBytes;
119
+ limitEvents;
120
+ constructor(limitEvents, limitBytes) {
121
+ super("event_stream_queue_overflow", `the event stream receive queue exceeded ${limitEvents} events or ${limitBytes} bytes`);
122
+ this.limitEvents = limitEvents;
123
+ this.limitBytes = limitBytes;
124
+ }
125
+ }
126
+ export class EventStreamRemoteTerminationError extends DeviceRailClientError {
127
+ termination;
128
+ constructor(termination) {
129
+ super("event_stream_remote_termination", `the event stream terminated remotely: ${termination.reason}`);
130
+ this.termination = structuredClone(termination);
131
+ }
132
+ }
@@ -0,0 +1,66 @@
1
+ import type { EventStreamCursor, EventStreamOriginPolicy, EventsStreamOpenResult, EventsStreamTerminalParams, EventsSubscribeParams, PeerInfo, ProtocolVersion, TestEvent } from "@devicerail/protocol";
2
+ export declare const DEFAULT_EVENT_STREAM_MAX_MESSAGE_BYTES: number;
3
+ export declare const DEFAULT_EVENT_STREAM_MAX_QUEUED_BYTES: number;
4
+ export declare const DEFAULT_EVENT_STREAM_MAX_QUEUED_EVENTS = 64;
5
+ export interface EventStreamWebSocketEvent {
6
+ readonly code?: number;
7
+ readonly data?: unknown;
8
+ readonly reason?: string;
9
+ }
10
+ export type EventStreamWebSocketEventType = "close" | "error" | "message" | "open";
11
+ /** The minimal WebSocket surface used by the Node client and its deterministic tests. */
12
+ export interface EventStreamWebSocket {
13
+ readonly protocol: string;
14
+ addEventListener(type: EventStreamWebSocketEventType, listener: (event: EventStreamWebSocketEvent) => void): void;
15
+ close(code?: number, reason?: string): void;
16
+ removeEventListener(type: EventStreamWebSocketEventType, listener: (event: EventStreamWebSocketEvent) => void): void;
17
+ send(data: string): void;
18
+ }
19
+ export type EventStreamWebSocketFactory = (endpoint: string, subprotocol: "devicerail.events.v1") => EventStreamWebSocket;
20
+ export interface EventStreamOptions {
21
+ readonly maxMessageBytes?: number;
22
+ readonly maxQueuedBytes?: number;
23
+ readonly maxQueuedEvents?: number;
24
+ /** Defaults to `absent` for Node; browser callers bind the capability to one exact Origin. */
25
+ readonly originPolicy?: EventStreamOriginPolicy;
26
+ readonly signal?: AbortSignal;
27
+ readonly webSocketFactory?: EventStreamWebSocketFactory;
28
+ }
29
+ export interface EventStreamItem {
30
+ readonly cursor: EventStreamCursor;
31
+ readonly event: TestEvent;
32
+ /** Advances the resumable cursor only when this is the next delivered event. */
33
+ confirm(): EventStreamCursor;
34
+ }
35
+ type EventStreamCapabilityOpener = (sessionId: string, originPolicy: EventStreamOriginPolicy, signal?: AbortSignal) => Promise<EventsStreamOpenResult>;
36
+ interface StreamSettings {
37
+ readonly maxMessageBytes: number;
38
+ readonly maxQueuedBytes: number;
39
+ readonly maxQueuedEvents: number;
40
+ readonly originPolicy: EventStreamOriginPolicy;
41
+ readonly webSocketFactory: EventStreamWebSocketFactory;
42
+ }
43
+ /**
44
+ * A single resumable Session stream. Socket receipt, iterator delivery, and
45
+ * application confirmation are deliberately separate cursor boundaries.
46
+ */
47
+ export declare class DeviceRailEventStream implements AsyncIterable<EventStreamItem> {
48
+ #private;
49
+ constructor(capabilityOpener: EventStreamCapabilityOpener, clientPeer: PeerInfo, eventProtocol: ProtocolVersion, sessionId: string, afterCursor: EventStreamCursor | undefined, streamEpoch: string, socket: EventStreamWebSocket, settings: StreamSettings, signal?: AbortSignal);
50
+ get confirmedCursor(): EventStreamCursor | undefined;
51
+ get receivedCursor(): EventStreamCursor | undefined;
52
+ get sessionId(): string;
53
+ get terminal(): EventsStreamTerminalParams | undefined;
54
+ [Symbol.asyncIterator](): AsyncIterator<EventStreamItem>;
55
+ next(): Promise<IteratorResult<EventStreamItem>>;
56
+ return(): Promise<IteratorResult<EventStreamItem>>;
57
+ /** Marks exactly one delivered event as durably accepted by the application. */
58
+ confirm(cursor: EventStreamCursor): EventStreamCursor;
59
+ /** Aborts this socket without advancing the confirmed application cursor. */
60
+ cancel(): void;
61
+ /** Opens a fresh single-use capability from the last explicitly confirmed cursor. */
62
+ resume(options?: EventStreamOptions): Promise<DeviceRailEventStream>;
63
+ waitUntilReady(): Promise<void>;
64
+ }
65
+ export declare function connectEventStream(capabilityOpener: EventStreamCapabilityOpener, clientPeer: PeerInfo, eventProtocol: ProtocolVersion, params: EventsSubscribeParams, options: EventStreamOptions): Promise<DeviceRailEventStream>;
66
+ export {};