@synra/protocol 0.0.7 → 0.0.11
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 +21 -0
- package/dist/generated/events.d.ts +162 -0
- package/dist/generated/events.d.ts.map +1 -0
- package/dist/generated/ui.d.ts +338 -0
- package/dist/generated/ui.d.ts.map +1 -0
- package/dist/generated/wire.d.ts +227 -0
- package/dist/generated/wire.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/package.json +28 -14
- package/README.md +0 -3
- package/dist/index.d.mts +0 -496
- package/dist/index.mjs +0 -193
package/dist/index.d.mts
DELETED
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
//#region src/file-transfer.d.ts
|
|
2
|
-
/** Discriminator for file transfer payloads; extend in protocol when adding kinds. */
|
|
3
|
-
type FileTransferKind = 'plugin-bundle' | 'attachment';
|
|
4
|
-
type FileTransferRequestPayload = {
|
|
5
|
-
transferId: string;
|
|
6
|
-
kind: 'plugin-bundle';
|
|
7
|
-
pluginId: string;
|
|
8
|
-
version: string;
|
|
9
|
-
byteLength?: number;
|
|
10
|
-
syncSessionId?: string;
|
|
11
|
-
} | {
|
|
12
|
-
transferId: string;
|
|
13
|
-
kind: 'attachment';
|
|
14
|
-
fileName: string;
|
|
15
|
-
byteLength?: number;
|
|
16
|
-
mimeType?: string;
|
|
17
|
-
contextId?: string;
|
|
18
|
-
syncSessionId?: string;
|
|
19
|
-
};
|
|
20
|
-
type FileTransferChunkPayload = {
|
|
21
|
-
transferId: string;
|
|
22
|
-
kind: 'plugin-bundle';
|
|
23
|
-
pluginId: string;
|
|
24
|
-
version: string;
|
|
25
|
-
chunkIndex: number;
|
|
26
|
-
totalChunks: number;
|
|
27
|
-
chunkBase64: string;
|
|
28
|
-
syncSessionId?: string;
|
|
29
|
-
} | {
|
|
30
|
-
transferId: string;
|
|
31
|
-
kind: 'attachment';
|
|
32
|
-
fileName: string;
|
|
33
|
-
chunkIndex: number;
|
|
34
|
-
totalChunks: number;
|
|
35
|
-
chunkBase64: string;
|
|
36
|
-
syncSessionId?: string;
|
|
37
|
-
contextId?: string;
|
|
38
|
-
};
|
|
39
|
-
type FileTransferCompletePayload = {
|
|
40
|
-
transferId: string;
|
|
41
|
-
kind: 'plugin-bundle';
|
|
42
|
-
pluginId: string;
|
|
43
|
-
version: string;
|
|
44
|
-
totalChunks: number;
|
|
45
|
-
sha256?: string;
|
|
46
|
-
syncSessionId?: string;
|
|
47
|
-
} | {
|
|
48
|
-
transferId: string;
|
|
49
|
-
kind: 'attachment';
|
|
50
|
-
fileName: string;
|
|
51
|
-
totalChunks: number;
|
|
52
|
-
sha256?: string;
|
|
53
|
-
syncSessionId?: string;
|
|
54
|
-
contextId?: string;
|
|
55
|
-
};
|
|
56
|
-
type FileTransferAbortPayload = {
|
|
57
|
-
transferId: string;
|
|
58
|
-
reason?: string; /** Prefer values from SynraErrorCode when emitted by app logic. */
|
|
59
|
-
code?: string;
|
|
60
|
-
};
|
|
61
|
-
/** Session-level progress / checkpoint (optional wire event). Not TCP frame ACK. */
|
|
62
|
-
type FileTransferProgressPayload = {
|
|
63
|
-
transferId: string; /** Inclusive highest chunk index processed (0-based). */
|
|
64
|
-
receivedThroughChunkIndex: number;
|
|
65
|
-
syncSessionId?: string;
|
|
66
|
-
};
|
|
67
|
-
declare function fileTransferChunkCount(byteLength: number, chunkSize: number): number;
|
|
68
|
-
/**
|
|
69
|
-
* Outbound plugin-bundle chunks over `file.transfer.chunk` payloads (session layer).
|
|
70
|
-
* SYNRA-COMM::FILE_TRANSFER::SEND::CHUNK_ENCODE
|
|
71
|
-
*/
|
|
72
|
-
declare function iteratePluginBundleChunks(options: {
|
|
73
|
-
transferId: string;
|
|
74
|
-
buffer: Uint8Array;
|
|
75
|
-
chunkSize: number;
|
|
76
|
-
pluginId: string;
|
|
77
|
-
version: string;
|
|
78
|
-
syncSessionId?: string;
|
|
79
|
-
}): Generator<Extract<FileTransferChunkPayload, {
|
|
80
|
-
kind: 'plugin-bundle';
|
|
81
|
-
}>>;
|
|
82
|
-
/** Observable receive progress for UI/analytics later; no wire event required. */
|
|
83
|
-
type PluginBundleTransferProgressSnapshot = {
|
|
84
|
-
transferId: string;
|
|
85
|
-
pluginId: string;
|
|
86
|
-
version: string;
|
|
87
|
-
chunksReceived: number;
|
|
88
|
-
totalChunks: number;
|
|
89
|
-
bytesReceived: number;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Assembles plugin-bundle transfer chunks in memory (receive path).
|
|
93
|
-
* SYNRA-COMM::FILE_TRANSFER::RECEIVE::ASSEMBLE_BUFFER
|
|
94
|
-
*/
|
|
95
|
-
declare class PluginBundleTransferAssembly {
|
|
96
|
-
readonly transferId: string;
|
|
97
|
-
private readonly chunks;
|
|
98
|
-
private expectedTotalChunks;
|
|
99
|
-
private pluginId;
|
|
100
|
-
private version;
|
|
101
|
-
constructor(transferId: string);
|
|
102
|
-
/** Returns error message if chunk is invalid for this assembly. */
|
|
103
|
-
push(payload: Extract<FileTransferChunkPayload, {
|
|
104
|
-
kind: 'plugin-bundle';
|
|
105
|
-
}>): string | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* Chunk/session stats for progress bars or logging without `file.transfer.progress` on the wire.
|
|
108
|
-
*/
|
|
109
|
-
getProgressSnapshot(): PluginBundleTransferProgressSnapshot;
|
|
110
|
-
isComplete(): boolean;
|
|
111
|
-
/** Concatenates in chunk index order; only call when `isComplete()`. */
|
|
112
|
-
concat(): Uint8Array;
|
|
113
|
-
}
|
|
114
|
-
//#endregion
|
|
115
|
-
//#region src/lan-events.d.ts
|
|
116
|
-
/** Wire `LanFrame` type === `event`: payload uses this envelope (JSON). */
|
|
117
|
-
type LanWireEventEnvelope = {
|
|
118
|
-
event: LanWireEventName; /** Event-specific body; validated per handler. */
|
|
119
|
-
payload: unknown;
|
|
120
|
-
schemaVersion?: number;
|
|
121
|
-
eventId?: string;
|
|
122
|
-
};
|
|
123
|
-
declare const LAN_WIRE_EVENT_NAMES: readonly ["device.display-name.changed", "device.pairing.request", "device.pairing.response", "device.pairing.peer-reset", "device.pairing.unpair-required"];
|
|
124
|
-
type LanWireEventName = (typeof LAN_WIRE_EVENT_NAMES)[number];
|
|
125
|
-
declare function isLanWireEventName(value: string): value is LanWireEventName;
|
|
126
|
-
type LanDeviceDisplayNameChangedPayload = {
|
|
127
|
-
deviceId: string;
|
|
128
|
-
displayName: string;
|
|
129
|
-
};
|
|
130
|
-
/** Same shape as frontend `PairRequestPayload` for wire compatibility. */
|
|
131
|
-
type LanPairingRequestPayload = {
|
|
132
|
-
/** Opaque token or nonce for matching response. */requestId: string;
|
|
133
|
-
from: string;
|
|
134
|
-
target: string;
|
|
135
|
-
initiator: {
|
|
136
|
-
deviceId: string;
|
|
137
|
-
name: string;
|
|
138
|
-
ipAddress: string;
|
|
139
|
-
port?: number;
|
|
140
|
-
source?: string;
|
|
141
|
-
connectable?: boolean;
|
|
142
|
-
platform?: string;
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
type LanPairingResponsePayload = {
|
|
146
|
-
requestId: string;
|
|
147
|
-
from: string;
|
|
148
|
-
target: string;
|
|
149
|
-
replyRequestId?: string;
|
|
150
|
-
accepted: boolean;
|
|
151
|
-
reason?: string;
|
|
152
|
-
};
|
|
153
|
-
/** Peer treats us as unpaired (e.g. cleared list); receiver updates local state. */
|
|
154
|
-
type LanPairingPeerResetPayload = {
|
|
155
|
-
from: string; /** Human-readable; optional. */
|
|
156
|
-
reason?: string;
|
|
157
|
-
};
|
|
158
|
-
/** Ask the receiver to drop local pairing for this active peer link. */
|
|
159
|
-
type LanPairingUnpairRequiredPayload = {
|
|
160
|
-
reason?: string;
|
|
161
|
-
mode?: 'fresh' | 'stale';
|
|
162
|
-
};
|
|
163
|
-
//#endregion
|
|
164
|
-
//#region src/event-names.d.ts
|
|
165
|
-
/**
|
|
166
|
-
* Cross-platform communication annotation taxonomy (search-only comments).
|
|
167
|
-
*
|
|
168
|
-
* Prefix:
|
|
169
|
-
* SYNRA-COMM::<Domain>::<Stage>::<NodeId>
|
|
170
|
-
*
|
|
171
|
-
* Domains:
|
|
172
|
-
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE | FILE_TRANSFER
|
|
173
|
-
*
|
|
174
|
-
* Stages:
|
|
175
|
-
* CONNECT | SEND | RECEIVE | ACK | HEARTBEAT | CLOSE | ERROR
|
|
176
|
-
*
|
|
177
|
-
* Shared NodeId vocabulary:
|
|
178
|
-
* OPEN_TRANSPORT
|
|
179
|
-
* PROBE_SINGLE
|
|
180
|
-
* INBOUND_ACCEPT
|
|
181
|
-
* OUTBOUND_RECV_LOOP
|
|
182
|
-
* LAN_EVENT_ROUTE
|
|
183
|
-
* MESSAGE_SEND
|
|
184
|
-
* MESSAGE_RECV
|
|
185
|
-
* TRANSPORT_CLOSE
|
|
186
|
-
* TRANSPORT_HEARTBEAT
|
|
187
|
-
* TRANSPORT_ERROR
|
|
188
|
-
*
|
|
189
|
-
* Keep the same Domain/Stage/NodeId triplet across Node.js, Android, and iOS.
|
|
190
|
-
*/
|
|
191
|
-
declare const DEVICE_TCP_CONNECT_EVENT: 'device.tcp.connect';
|
|
192
|
-
declare const DEVICE_TCP_CONNECT_ACK_EVENT: 'device.tcp.connect.ack';
|
|
193
|
-
declare const DEVICE_TCP_ACK_EVENT: 'device.tcp.ack';
|
|
194
|
-
declare const DEVICE_TCP_CLOSE_EVENT: 'device.tcp.close';
|
|
195
|
-
declare const DEVICE_TCP_ERROR_EVENT: 'device.tcp.error';
|
|
196
|
-
declare const DEVICE_TCP_HEARTBEAT_EVENT: 'device.tcp.heartbeat';
|
|
197
|
-
declare const DEVICE_HOST_RETIRE_EVENT: 'device.host.retire';
|
|
198
|
-
declare const DEVICE_MEMBER_OFFLINE_EVENT: 'device.member.offline';
|
|
199
|
-
declare const DEVICE_DISPLAY_NAME_CHANGED_EVENT: 'device.display-name.changed';
|
|
200
|
-
declare const DEVICE_PAIRING_PREFIX: 'device.pairing.';
|
|
201
|
-
declare const DEVICE_PAIRING_REQUEST_EVENT: 'device.pairing.request';
|
|
202
|
-
declare const DEVICE_PAIRING_RESPONSE_EVENT: 'device.pairing.response';
|
|
203
|
-
declare const DEVICE_PAIRING_PEER_RESET_EVENT: 'device.pairing.peer-reset';
|
|
204
|
-
declare const DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT: 'device.pairing.unpair-required';
|
|
205
|
-
declare function isDevicePairingEvent(event: string): boolean;
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/discovery-timing.d.ts
|
|
208
|
-
/** Single wall-clock budget for one LAN discovery run (mDNS/UDP window + Synra TCP probe slice). */
|
|
209
|
-
declare const DEFAULT_SYNRA_SCAN_BUDGET_MS = 2200;
|
|
210
|
-
/**
|
|
211
|
-
* Splits scan budget between native browse/broadcast and Synra probe without a second JS-level timeout knob.
|
|
212
|
-
*/
|
|
213
|
-
declare function synraDiscoveryTimeoutsFromBudget(scanBudgetMs: number): {
|
|
214
|
-
discoveryTimeoutMs: number;
|
|
215
|
-
probeTimeoutMs: number;
|
|
216
|
-
};
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/index.d.ts
|
|
219
|
-
declare const PROTOCOL_VERSION: '1.0';
|
|
220
|
-
type DeviceId = string;
|
|
221
|
-
type TraceId = string;
|
|
222
|
-
type MessageId = string;
|
|
223
|
-
type ActionId = string;
|
|
224
|
-
type LegacySynraMessageType = 'share.detected' | 'action.proposed' | 'action.selected' | 'action.executing' | 'action.completed' | 'action.failed';
|
|
225
|
-
type TransportMessageType = 'transport.opened' | 'transport.closed' | 'transport.message.received' | 'transport.message.ack' | 'transport.error';
|
|
226
|
-
type RelayMessageType = 'relay.request' | 'relay.ack' | 'relay.result';
|
|
227
|
-
type ClusterHostMessageType = 'host.announce' | 'host.retire' | 'host.member.offline' | 'host.heartbeat';
|
|
228
|
-
type ElectionMessageType = 'election.vote.request' | 'election.vote.response' | 'election.win';
|
|
229
|
-
type CustomMessageType = `custom.${string}`;
|
|
230
|
-
type SynraMessageType = LegacySynraMessageType | TransportMessageType | RelayMessageType | ClusterHostMessageType | ElectionMessageType | CustomMessageType;
|
|
231
|
-
type RuntimeMessageType = 'runtime.request' | 'runtime.received' | 'runtime.started' | 'runtime.finished' | 'runtime.error';
|
|
232
|
-
type PluginSyncMessageType = 'plugin.catalog.request' | 'plugin.catalog.response' | 'file.transfer.request' | 'file.transfer.chunk' | 'file.transfer.complete' | 'file.transfer.abort' | 'file.transfer.progress';
|
|
233
|
-
type ProtocolMessageType = RuntimeMessageType | PluginSyncMessageType;
|
|
234
|
-
type ShareDetectedPayload = {
|
|
235
|
-
inputType: 'text' | 'url' | 'file';
|
|
236
|
-
raw: string;
|
|
237
|
-
metadata?: Record<string, unknown>;
|
|
238
|
-
};
|
|
239
|
-
type ActionProposedPayload = {
|
|
240
|
-
actionId: ActionId;
|
|
241
|
-
pluginId: string;
|
|
242
|
-
actionType: string;
|
|
243
|
-
label: string;
|
|
244
|
-
requiresConfirm: boolean;
|
|
245
|
-
payload: unknown;
|
|
246
|
-
};
|
|
247
|
-
type ActionExecutingPayload = {
|
|
248
|
-
actionId: ActionId;
|
|
249
|
-
pluginId: string;
|
|
250
|
-
startedAt: number;
|
|
251
|
-
};
|
|
252
|
-
type ActionCompletedPayload = {
|
|
253
|
-
actionId: ActionId;
|
|
254
|
-
pluginId: string;
|
|
255
|
-
finishedAt: number;
|
|
256
|
-
output?: unknown;
|
|
257
|
-
};
|
|
258
|
-
type ActionFailedPayload = {
|
|
259
|
-
actionId: ActionId;
|
|
260
|
-
pluginId: string;
|
|
261
|
-
finishedAt: number;
|
|
262
|
-
code: SynraErrorCode;
|
|
263
|
-
message: string;
|
|
264
|
-
retryable: boolean;
|
|
265
|
-
details?: unknown;
|
|
266
|
-
};
|
|
267
|
-
type TransportOpenedPayload = {
|
|
268
|
-
deviceId: DeviceId;
|
|
269
|
-
host?: string;
|
|
270
|
-
port?: number;
|
|
271
|
-
openedAt: number;
|
|
272
|
-
};
|
|
273
|
-
type TransportClosedPayload = {
|
|
274
|
-
deviceId: DeviceId;
|
|
275
|
-
closedAt: number;
|
|
276
|
-
reason?: string;
|
|
277
|
-
};
|
|
278
|
-
type TransportMessageReceivedPayload = {
|
|
279
|
-
requestId: string;
|
|
280
|
-
event: string;
|
|
281
|
-
target: DeviceId;
|
|
282
|
-
from: DeviceId;
|
|
283
|
-
replyRequestId?: string;
|
|
284
|
-
payload: unknown;
|
|
285
|
-
timestamp: number;
|
|
286
|
-
};
|
|
287
|
-
type TransportMessageAckPayload = {
|
|
288
|
-
requestId: string;
|
|
289
|
-
target: DeviceId;
|
|
290
|
-
event?: string;
|
|
291
|
-
from?: DeviceId;
|
|
292
|
-
replyRequestId: string;
|
|
293
|
-
timestamp: number;
|
|
294
|
-
};
|
|
295
|
-
type TransportErrorPayload = {
|
|
296
|
-
deviceId?: DeviceId;
|
|
297
|
-
code: SynraErrorCode | 'TRANSPORT_IO_ERROR';
|
|
298
|
-
message: string;
|
|
299
|
-
retryable?: boolean;
|
|
300
|
-
details?: unknown;
|
|
301
|
-
};
|
|
302
|
-
type RelayRequestPayload = {
|
|
303
|
-
requestId: string;
|
|
304
|
-
routeTo: DeviceId;
|
|
305
|
-
data: unknown;
|
|
306
|
-
};
|
|
307
|
-
type RelayAckPayload = {
|
|
308
|
-
requestId: string;
|
|
309
|
-
ackedAt: number;
|
|
310
|
-
};
|
|
311
|
-
type RelayResultPayload = {
|
|
312
|
-
requestId: string;
|
|
313
|
-
ok: boolean;
|
|
314
|
-
result?: unknown;
|
|
315
|
-
error?: ProtocolErrorPayload;
|
|
316
|
-
};
|
|
317
|
-
type HostAnnouncePayload = {
|
|
318
|
-
hostId: DeviceId;
|
|
319
|
-
term: number;
|
|
320
|
-
epoch: number;
|
|
321
|
-
};
|
|
322
|
-
type HostRetirePayload = {
|
|
323
|
-
hostId: DeviceId;
|
|
324
|
-
term: number;
|
|
325
|
-
retireAt: number;
|
|
326
|
-
reason?: string;
|
|
327
|
-
};
|
|
328
|
-
type HostMemberOfflinePayload = {
|
|
329
|
-
nodeId: DeviceId;
|
|
330
|
-
requestId?: string;
|
|
331
|
-
offlineAt: number;
|
|
332
|
-
reason?: string;
|
|
333
|
-
};
|
|
334
|
-
type HostHeartbeatPayload = {
|
|
335
|
-
hostId: DeviceId;
|
|
336
|
-
term?: number;
|
|
337
|
-
epoch?: number;
|
|
338
|
-
timestamp: number;
|
|
339
|
-
};
|
|
340
|
-
type ElectionVoteRequestPayload = {
|
|
341
|
-
candidateId: DeviceId;
|
|
342
|
-
term: number;
|
|
343
|
-
candidateEpochHint?: number;
|
|
344
|
-
};
|
|
345
|
-
type ElectionVoteResponsePayload = {
|
|
346
|
-
voterId: DeviceId;
|
|
347
|
-
term: number;
|
|
348
|
-
granted: boolean;
|
|
349
|
-
};
|
|
350
|
-
type ElectionWinPayload = {
|
|
351
|
-
hostId: DeviceId;
|
|
352
|
-
term: number;
|
|
353
|
-
epoch: number;
|
|
354
|
-
};
|
|
355
|
-
type SynraCrossDevicePayloadByType = {
|
|
356
|
-
'share.detected': ShareDetectedPayload;
|
|
357
|
-
'action.proposed': ActionProposedPayload;
|
|
358
|
-
'action.selected': SynraActionRequest;
|
|
359
|
-
'action.executing': ActionExecutingPayload;
|
|
360
|
-
'action.completed': ActionCompletedPayload;
|
|
361
|
-
'action.failed': ActionFailedPayload;
|
|
362
|
-
'transport.opened': TransportOpenedPayload;
|
|
363
|
-
'transport.closed': TransportClosedPayload;
|
|
364
|
-
'transport.message.received': TransportMessageReceivedPayload;
|
|
365
|
-
'transport.message.ack': TransportMessageAckPayload;
|
|
366
|
-
'transport.error': TransportErrorPayload;
|
|
367
|
-
'relay.request': RelayRequestPayload;
|
|
368
|
-
'relay.ack': RelayAckPayload;
|
|
369
|
-
'relay.result': RelayResultPayload;
|
|
370
|
-
'host.announce': HostAnnouncePayload;
|
|
371
|
-
'host.retire': HostRetirePayload;
|
|
372
|
-
'host.member.offline': HostMemberOfflinePayload;
|
|
373
|
-
'host.heartbeat': HostHeartbeatPayload;
|
|
374
|
-
'election.vote.request': ElectionVoteRequestPayload;
|
|
375
|
-
'election.vote.response': ElectionVoteResponsePayload;
|
|
376
|
-
'election.win': ElectionWinPayload;
|
|
377
|
-
} & { [K in CustomMessageType]: unknown };
|
|
378
|
-
type SynraCrossDeviceMessage<TType extends SynraMessageType = SynraMessageType, TPayload = SynraCrossDevicePayloadByType[TType]> = {
|
|
379
|
-
protocolVersion: typeof PROTOCOL_VERSION;
|
|
380
|
-
requestId: string;
|
|
381
|
-
replyRequestId?: string;
|
|
382
|
-
event: string;
|
|
383
|
-
traceId: TraceId;
|
|
384
|
-
sentAt: number;
|
|
385
|
-
ttlMs: number;
|
|
386
|
-
from: DeviceId;
|
|
387
|
-
target: DeviceId;
|
|
388
|
-
payload: TPayload;
|
|
389
|
-
};
|
|
390
|
-
type ProtocolEnvelope<TType extends ProtocolMessageType, TPayload> = {
|
|
391
|
-
protocolVersion: typeof PROTOCOL_VERSION;
|
|
392
|
-
requestId: string;
|
|
393
|
-
replyRequestId?: string;
|
|
394
|
-
event: TType;
|
|
395
|
-
timestamp: number;
|
|
396
|
-
payload: TPayload;
|
|
397
|
-
};
|
|
398
|
-
type SynraActionRequest<TPayload = unknown> = {
|
|
399
|
-
actionId: ActionId;
|
|
400
|
-
pluginId: string;
|
|
401
|
-
actionType: string;
|
|
402
|
-
payload: TPayload;
|
|
403
|
-
};
|
|
404
|
-
type SynraErrorCode = 'INVALID_PARAMS' | 'UNAUTHORIZED' | 'NOT_FOUND' | 'TIMEOUT' | 'UNSUPPORTED_OPERATION' | 'INTERNAL_ERROR' | 'TRANSPORT_DISCONNECTED' | 'TRANSPORT_UNREACHABLE' | 'PAIRING_REQUIRED' | 'PAIRING_EXPIRED' | 'RUNTIME_NOT_READY' | 'RUNTIME_EXECUTION_FAILED' | 'PLUGIN_NOT_FOUND' | 'PLUGIN_ACTION_INVALID' | 'USER_CANCELLED';
|
|
405
|
-
type ProtocolErrorCode = SynraErrorCode;
|
|
406
|
-
type RuntimeFinishedStatus = 'success' | 'failed' | 'cancelled';
|
|
407
|
-
type RuntimeRequestPayload<TInput = unknown> = {
|
|
408
|
-
input: TInput;
|
|
409
|
-
requestedAt: number;
|
|
410
|
-
};
|
|
411
|
-
type RuntimeReceivedPayload = {
|
|
412
|
-
acknowledgedAt: number;
|
|
413
|
-
};
|
|
414
|
-
type RuntimeStartedPayload = {
|
|
415
|
-
startedAt: number;
|
|
416
|
-
};
|
|
417
|
-
type ProtocolErrorPayload = {
|
|
418
|
-
code: ProtocolErrorCode;
|
|
419
|
-
message: string;
|
|
420
|
-
details?: unknown;
|
|
421
|
-
};
|
|
422
|
-
type RuntimeFinishedPayload<TResult = unknown> = {
|
|
423
|
-
status: RuntimeFinishedStatus;
|
|
424
|
-
finishedAt: number;
|
|
425
|
-
result?: TResult;
|
|
426
|
-
error?: ProtocolErrorPayload;
|
|
427
|
-
};
|
|
428
|
-
type RuntimeErrorPayload = {
|
|
429
|
-
code: ProtocolErrorCode;
|
|
430
|
-
message: string;
|
|
431
|
-
retryable?: boolean;
|
|
432
|
-
details?: unknown;
|
|
433
|
-
};
|
|
434
|
-
type PluginCatalogRequestPayload = {
|
|
435
|
-
knownPluginIds?: string[]; /** Registry keyword or full Synra package name; triggers npm metadata merge when non-empty. */
|
|
436
|
-
query?: string; /** Optional registry base URL used for npm metadata lookup. */
|
|
437
|
-
registryUrl?: string;
|
|
438
|
-
};
|
|
439
|
-
type SynraPluginManifestEntriesWire = Partial<Record<'ui' | 'host' | 'worker' | 'shared', string>>;
|
|
440
|
-
type PluginCatalogItem = {
|
|
441
|
-
pluginId: string;
|
|
442
|
-
version: string;
|
|
443
|
-
displayName: string;
|
|
444
|
-
status?: 'installed' | 'available';
|
|
445
|
-
builtin?: boolean;
|
|
446
|
-
defaultPage?: string;
|
|
447
|
-
icon?: string;
|
|
448
|
-
logoPath?: string;
|
|
449
|
-
packageName?: string;
|
|
450
|
-
entries?: SynraPluginManifestEntriesWire;
|
|
451
|
-
};
|
|
452
|
-
type PluginCatalogResponsePayload = {
|
|
453
|
-
plugins: PluginCatalogItem[];
|
|
454
|
-
generatedAt: number;
|
|
455
|
-
};
|
|
456
|
-
type ProtocolPayloadByType = {
|
|
457
|
-
'runtime.request': RuntimeRequestPayload;
|
|
458
|
-
'runtime.received': RuntimeReceivedPayload;
|
|
459
|
-
'runtime.started': RuntimeStartedPayload;
|
|
460
|
-
'runtime.finished': RuntimeFinishedPayload;
|
|
461
|
-
'runtime.error': RuntimeErrorPayload;
|
|
462
|
-
'plugin.catalog.request': PluginCatalogRequestPayload;
|
|
463
|
-
'plugin.catalog.response': PluginCatalogResponsePayload;
|
|
464
|
-
'file.transfer.request': FileTransferRequestPayload;
|
|
465
|
-
'file.transfer.chunk': FileTransferChunkPayload;
|
|
466
|
-
'file.transfer.complete': FileTransferCompletePayload;
|
|
467
|
-
'file.transfer.abort': FileTransferAbortPayload;
|
|
468
|
-
'file.transfer.progress': FileTransferProgressPayload;
|
|
469
|
-
};
|
|
470
|
-
type MessageByType<K extends keyof ProtocolPayloadByType> = ProtocolEnvelope<K, ProtocolPayloadByType[K]>;
|
|
471
|
-
type SynraRuntimeMessage = MessageByType<'runtime.request'> | MessageByType<'runtime.received'> | MessageByType<'runtime.started'> | MessageByType<'runtime.finished'> | MessageByType<'runtime.error'>;
|
|
472
|
-
type SynraPluginSyncMessage = MessageByType<'plugin.catalog.request'> | MessageByType<'plugin.catalog.response'> | MessageByType<'file.transfer.request'> | MessageByType<'file.transfer.chunk'> | MessageByType<'file.transfer.complete'> | MessageByType<'file.transfer.abort'> | MessageByType<'file.transfer.progress'>;
|
|
473
|
-
type SynraProtocolMessage = SynraRuntimeMessage | SynraPluginSyncMessage;
|
|
474
|
-
type SynraActionReceipt = {
|
|
475
|
-
ok: true;
|
|
476
|
-
actionId: ActionId;
|
|
477
|
-
handledBy: string;
|
|
478
|
-
durationMs: number;
|
|
479
|
-
output?: unknown;
|
|
480
|
-
} | {
|
|
481
|
-
ok: false;
|
|
482
|
-
actionId: ActionId;
|
|
483
|
-
handledBy: string;
|
|
484
|
-
durationMs: number;
|
|
485
|
-
retryable: boolean;
|
|
486
|
-
error: {
|
|
487
|
-
code: SynraErrorCode;
|
|
488
|
-
message: string;
|
|
489
|
-
details?: unknown;
|
|
490
|
-
};
|
|
491
|
-
};
|
|
492
|
-
declare function unknownToErrorMessage(error: unknown, fallback: string): string;
|
|
493
|
-
declare function createMessage<TPayload>(input: Omit<SynraCrossDeviceMessage<SynraMessageType, TPayload>, 'protocolVersion'>): SynraCrossDeviceMessage<SynraMessageType, TPayload>;
|
|
494
|
-
declare function createProtocolMessage<TType extends keyof ProtocolPayloadByType>(input: Omit<ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>, 'protocolVersion'>): ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>;
|
|
495
|
-
//#endregion
|
|
496
|
-
export { ActionCompletedPayload, ActionExecutingPayload, ActionFailedPayload, ActionId, ActionProposedPayload, ClusterHostMessageType, CustomMessageType, DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, DeviceId, ElectionMessageType, ElectionVoteRequestPayload, ElectionVoteResponsePayload, ElectionWinPayload, FileTransferAbortPayload, FileTransferChunkPayload, FileTransferCompletePayload, FileTransferKind, FileTransferProgressPayload, FileTransferRequestPayload, HostAnnouncePayload, HostHeartbeatPayload, HostMemberOfflinePayload, HostRetirePayload, LAN_WIRE_EVENT_NAMES, LanDeviceDisplayNameChangedPayload, LanPairingPeerResetPayload, LanPairingRequestPayload, LanPairingResponsePayload, LanPairingUnpairRequiredPayload, LanWireEventEnvelope, LanWireEventName, LegacySynraMessageType, MessageId, PROTOCOL_VERSION, PluginBundleTransferAssembly, PluginBundleTransferProgressSnapshot, PluginCatalogItem, PluginCatalogRequestPayload, PluginCatalogResponsePayload, PluginSyncMessageType, ProtocolEnvelope, ProtocolErrorCode, ProtocolErrorPayload, ProtocolMessageType, ProtocolPayloadByType, RelayAckPayload, RelayMessageType, RelayRequestPayload, RelayResultPayload, RuntimeErrorPayload, RuntimeFinishedPayload, RuntimeFinishedStatus, RuntimeMessageType, RuntimeReceivedPayload, RuntimeRequestPayload, RuntimeStartedPayload, ShareDetectedPayload, SynraActionReceipt, SynraActionRequest, SynraCrossDeviceMessage, SynraCrossDevicePayloadByType, SynraErrorCode, SynraMessageType, SynraPluginManifestEntriesWire, SynraPluginSyncMessage, SynraProtocolMessage, SynraRuntimeMessage, TraceId, TransportClosedPayload, TransportErrorPayload, TransportMessageAckPayload, TransportMessageReceivedPayload, TransportMessageType, TransportOpenedPayload, createMessage, createProtocolMessage, fileTransferChunkCount, isDevicePairingEvent, isLanWireEventName, iteratePluginBundleChunks, synraDiscoveryTimeoutsFromBudget, unknownToErrorMessage };
|
package/dist/index.mjs
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
//#region src/event-names.ts
|
|
2
|
-
/**
|
|
3
|
-
* Cross-platform communication annotation taxonomy (search-only comments).
|
|
4
|
-
*
|
|
5
|
-
* Prefix:
|
|
6
|
-
* SYNRA-COMM::<Domain>::<Stage>::<NodeId>
|
|
7
|
-
*
|
|
8
|
-
* Domains:
|
|
9
|
-
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE | FILE_TRANSFER
|
|
10
|
-
*
|
|
11
|
-
* Stages:
|
|
12
|
-
* CONNECT | SEND | RECEIVE | ACK | HEARTBEAT | CLOSE | ERROR
|
|
13
|
-
*
|
|
14
|
-
* Shared NodeId vocabulary:
|
|
15
|
-
* OPEN_TRANSPORT
|
|
16
|
-
* PROBE_SINGLE
|
|
17
|
-
* INBOUND_ACCEPT
|
|
18
|
-
* OUTBOUND_RECV_LOOP
|
|
19
|
-
* LAN_EVENT_ROUTE
|
|
20
|
-
* MESSAGE_SEND
|
|
21
|
-
* MESSAGE_RECV
|
|
22
|
-
* TRANSPORT_CLOSE
|
|
23
|
-
* TRANSPORT_HEARTBEAT
|
|
24
|
-
* TRANSPORT_ERROR
|
|
25
|
-
*
|
|
26
|
-
* Keep the same Domain/Stage/NodeId triplet across Node.js, Android, and iOS.
|
|
27
|
-
*/
|
|
28
|
-
const DEVICE_TCP_CONNECT_EVENT = "device.tcp.connect";
|
|
29
|
-
const DEVICE_TCP_CONNECT_ACK_EVENT = "device.tcp.connect.ack";
|
|
30
|
-
const DEVICE_TCP_ACK_EVENT = "device.tcp.ack";
|
|
31
|
-
const DEVICE_TCP_CLOSE_EVENT = "device.tcp.close";
|
|
32
|
-
const DEVICE_TCP_ERROR_EVENT = "device.tcp.error";
|
|
33
|
-
const DEVICE_TCP_HEARTBEAT_EVENT = "device.tcp.heartbeat";
|
|
34
|
-
const DEVICE_HOST_RETIRE_EVENT = "device.host.retire";
|
|
35
|
-
const DEVICE_MEMBER_OFFLINE_EVENT = "device.member.offline";
|
|
36
|
-
const DEVICE_DISPLAY_NAME_CHANGED_EVENT = "device.display-name.changed";
|
|
37
|
-
const DEVICE_PAIRING_PREFIX = "device.pairing.";
|
|
38
|
-
const DEVICE_PAIRING_REQUEST_EVENT = "device.pairing.request";
|
|
39
|
-
const DEVICE_PAIRING_RESPONSE_EVENT = "device.pairing.response";
|
|
40
|
-
const DEVICE_PAIRING_PEER_RESET_EVENT = "device.pairing.peer-reset";
|
|
41
|
-
const DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT = "device.pairing.unpair-required";
|
|
42
|
-
function isDevicePairingEvent(event) {
|
|
43
|
-
return event.startsWith(DEVICE_PAIRING_PREFIX);
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/lan-events.ts
|
|
47
|
-
const LAN_WIRE_EVENT_NAMES = [
|
|
48
|
-
DEVICE_DISPLAY_NAME_CHANGED_EVENT,
|
|
49
|
-
DEVICE_PAIRING_REQUEST_EVENT,
|
|
50
|
-
DEVICE_PAIRING_RESPONSE_EVENT,
|
|
51
|
-
DEVICE_PAIRING_PEER_RESET_EVENT,
|
|
52
|
-
DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT
|
|
53
|
-
];
|
|
54
|
-
function isLanWireEventName(value) {
|
|
55
|
-
return LAN_WIRE_EVENT_NAMES.includes(value);
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/discovery-timing.ts
|
|
59
|
-
/** Single wall-clock budget for one LAN discovery run (mDNS/UDP window + Synra TCP probe slice). */
|
|
60
|
-
const DEFAULT_SYNRA_SCAN_BUDGET_MS = 2200;
|
|
61
|
-
/**
|
|
62
|
-
* Splits scan budget between native browse/broadcast and Synra probe without a second JS-level timeout knob.
|
|
63
|
-
*/
|
|
64
|
-
function synraDiscoveryTimeoutsFromBudget(scanBudgetMs) {
|
|
65
|
-
const budget = Math.max(600, Math.floor(scanBudgetMs));
|
|
66
|
-
const probeTimeoutMs = Math.min(900, Math.max(350, Math.floor(budget * .38)));
|
|
67
|
-
return {
|
|
68
|
-
discoveryTimeoutMs: Math.max(200, budget - probeTimeoutMs - 80),
|
|
69
|
-
probeTimeoutMs
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/file-transfer.ts
|
|
74
|
-
function fileTransferChunkCount(byteLength, chunkSize) {
|
|
75
|
-
return Math.max(1, Math.ceil(byteLength / chunkSize));
|
|
76
|
-
}
|
|
77
|
-
function uint8ToBase64Chunk(bytes) {
|
|
78
|
-
if (typeof Buffer !== "undefined") return Buffer.from(bytes).toString("base64");
|
|
79
|
-
let binary = "";
|
|
80
|
-
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
81
|
-
return btoa(binary);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Outbound plugin-bundle chunks over `file.transfer.chunk` payloads (session layer).
|
|
85
|
-
* SYNRA-COMM::FILE_TRANSFER::SEND::CHUNK_ENCODE
|
|
86
|
-
*/
|
|
87
|
-
function* iteratePluginBundleChunks(options) {
|
|
88
|
-
const totalChunks = fileTransferChunkCount(options.buffer.length, options.chunkSize);
|
|
89
|
-
for (let chunkIndex = 0; chunkIndex < totalChunks; chunkIndex += 1) {
|
|
90
|
-
const start = chunkIndex * options.chunkSize;
|
|
91
|
-
const slice = options.buffer.subarray(start, Math.min(options.buffer.length, start + options.chunkSize));
|
|
92
|
-
yield {
|
|
93
|
-
transferId: options.transferId,
|
|
94
|
-
kind: "plugin-bundle",
|
|
95
|
-
pluginId: options.pluginId,
|
|
96
|
-
version: options.version,
|
|
97
|
-
chunkIndex,
|
|
98
|
-
totalChunks,
|
|
99
|
-
chunkBase64: uint8ToBase64Chunk(slice),
|
|
100
|
-
syncSessionId: options.syncSessionId
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function base64ToUint8(base64) {
|
|
105
|
-
if (typeof Buffer !== "undefined") return new Uint8Array(Buffer.from(base64, "base64"));
|
|
106
|
-
const bin = atob(base64);
|
|
107
|
-
const out = new Uint8Array(bin.length);
|
|
108
|
-
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
109
|
-
return out;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Assembles plugin-bundle transfer chunks in memory (receive path).
|
|
113
|
-
* SYNRA-COMM::FILE_TRANSFER::RECEIVE::ASSEMBLE_BUFFER
|
|
114
|
-
*/
|
|
115
|
-
var PluginBundleTransferAssembly = class {
|
|
116
|
-
chunks = /* @__PURE__ */ new Map();
|
|
117
|
-
expectedTotalChunks = 0;
|
|
118
|
-
pluginId = "";
|
|
119
|
-
version = "";
|
|
120
|
-
constructor(transferId) {
|
|
121
|
-
this.transferId = transferId;
|
|
122
|
-
}
|
|
123
|
-
/** Returns error message if chunk is invalid for this assembly. */
|
|
124
|
-
push(payload) {
|
|
125
|
-
if (payload.transferId !== this.transferId) return "transferId mismatch";
|
|
126
|
-
if (payload.kind !== "plugin-bundle") return "kind mismatch";
|
|
127
|
-
if (payload.chunkIndex < 0 || payload.totalChunks < 1) return "invalid chunk indices";
|
|
128
|
-
if (this.expectedTotalChunks === 0) this.expectedTotalChunks = payload.totalChunks;
|
|
129
|
-
else if (payload.totalChunks !== this.expectedTotalChunks) return "totalChunks changed";
|
|
130
|
-
if (payload.chunkIndex >= this.expectedTotalChunks) return "chunkIndex out of range";
|
|
131
|
-
if (this.chunks.has(payload.chunkIndex)) return;
|
|
132
|
-
if (this.pluginId.length === 0) {
|
|
133
|
-
this.pluginId = payload.pluginId;
|
|
134
|
-
this.version = payload.version;
|
|
135
|
-
}
|
|
136
|
-
this.chunks.set(payload.chunkIndex, base64ToUint8(payload.chunkBase64));
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Chunk/session stats for progress bars or logging without `file.transfer.progress` on the wire.
|
|
140
|
-
*/
|
|
141
|
-
getProgressSnapshot() {
|
|
142
|
-
let bytesReceived = 0;
|
|
143
|
-
for (const u8 of this.chunks.values()) bytesReceived += u8.length;
|
|
144
|
-
return {
|
|
145
|
-
transferId: this.transferId,
|
|
146
|
-
pluginId: this.pluginId,
|
|
147
|
-
version: this.version,
|
|
148
|
-
chunksReceived: this.chunks.size,
|
|
149
|
-
totalChunks: this.expectedTotalChunks,
|
|
150
|
-
bytesReceived
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
isComplete() {
|
|
154
|
-
return this.expectedTotalChunks > 0 && this.chunks.size === this.expectedTotalChunks;
|
|
155
|
-
}
|
|
156
|
-
/** Concatenates in chunk index order; only call when `isComplete()`. */
|
|
157
|
-
concat() {
|
|
158
|
-
let totalLen = 0;
|
|
159
|
-
for (let i = 0; i < this.expectedTotalChunks; i++) {
|
|
160
|
-
const part = this.chunks.get(i);
|
|
161
|
-
if (!part) throw new Error("missing chunk");
|
|
162
|
-
totalLen += part.length;
|
|
163
|
-
}
|
|
164
|
-
const out = new Uint8Array(totalLen);
|
|
165
|
-
let offset = 0;
|
|
166
|
-
for (let i = 0; i < this.expectedTotalChunks; i++) {
|
|
167
|
-
const part = this.chunks.get(i);
|
|
168
|
-
out.set(part, offset);
|
|
169
|
-
offset += part.length;
|
|
170
|
-
}
|
|
171
|
-
return out;
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
//#endregion
|
|
175
|
-
//#region src/index.ts
|
|
176
|
-
const PROTOCOL_VERSION = "1.0";
|
|
177
|
-
function unknownToErrorMessage(error, fallback) {
|
|
178
|
-
return error instanceof Error ? error.message : fallback;
|
|
179
|
-
}
|
|
180
|
-
function createMessage(input) {
|
|
181
|
-
return {
|
|
182
|
-
...input,
|
|
183
|
-
protocolVersion: "1.0"
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
function createProtocolMessage(input) {
|
|
187
|
-
return {
|
|
188
|
-
...input,
|
|
189
|
-
protocolVersion: "1.0"
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
193
|
-
export { DEFAULT_SYNRA_SCAN_BUDGET_MS, DEVICE_DISPLAY_NAME_CHANGED_EVENT, DEVICE_HOST_RETIRE_EVENT, DEVICE_MEMBER_OFFLINE_EVENT, DEVICE_PAIRING_PEER_RESET_EVENT, DEVICE_PAIRING_PREFIX, DEVICE_PAIRING_REQUEST_EVENT, DEVICE_PAIRING_RESPONSE_EVENT, DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT, DEVICE_TCP_ACK_EVENT, DEVICE_TCP_CLOSE_EVENT, DEVICE_TCP_CONNECT_ACK_EVENT, DEVICE_TCP_CONNECT_EVENT, DEVICE_TCP_ERROR_EVENT, DEVICE_TCP_HEARTBEAT_EVENT, LAN_WIRE_EVENT_NAMES, PROTOCOL_VERSION, PluginBundleTransferAssembly, createMessage, createProtocolMessage, fileTransferChunkCount, isDevicePairingEvent, isLanWireEventName, iteratePluginBundleChunks, synraDiscoveryTimeoutsFromBudget, unknownToErrorMessage };
|