@synra/protocol 0.0.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/README.md +3 -0
- package/dist/index.d.mts +362 -0
- package/dist/index.mjs +76 -0
- package/package.json +29 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
//#region src/lan-events.d.ts
|
|
2
|
+
/** Wire `LanFrame` type === `event`: payload uses this envelope (JSON). */
|
|
3
|
+
type LanWireEventEnvelope = {
|
|
4
|
+
event: LanWireEventName; /** Event-specific body; validated per handler. */
|
|
5
|
+
payload: unknown;
|
|
6
|
+
schemaVersion?: number;
|
|
7
|
+
eventId?: string;
|
|
8
|
+
};
|
|
9
|
+
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"];
|
|
10
|
+
type LanWireEventName = (typeof LAN_WIRE_EVENT_NAMES)[number];
|
|
11
|
+
declare function isLanWireEventName(value: string): value is LanWireEventName;
|
|
12
|
+
type LanDeviceDisplayNameChangedPayload = {
|
|
13
|
+
deviceId: string;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|
|
16
|
+
/** Same shape as frontend `PairRequestPayload` for wire compatibility. */
|
|
17
|
+
type LanPairingRequestPayload = {
|
|
18
|
+
/** Opaque token or nonce for matching response. */requestId: string;
|
|
19
|
+
from: string;
|
|
20
|
+
target: string;
|
|
21
|
+
initiator: {
|
|
22
|
+
deviceId: string;
|
|
23
|
+
name: string;
|
|
24
|
+
ipAddress: string;
|
|
25
|
+
port?: number;
|
|
26
|
+
source?: string;
|
|
27
|
+
connectable?: boolean;
|
|
28
|
+
platform?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
type LanPairingResponsePayload = {
|
|
32
|
+
requestId: string;
|
|
33
|
+
from: string;
|
|
34
|
+
target: string;
|
|
35
|
+
replyRequestId?: string;
|
|
36
|
+
accepted: boolean;
|
|
37
|
+
reason?: string;
|
|
38
|
+
};
|
|
39
|
+
/** Peer treats us as unpaired (e.g. cleared list); receiver updates local state. */
|
|
40
|
+
type LanPairingPeerResetPayload = {
|
|
41
|
+
from: string; /** Human-readable; optional. */
|
|
42
|
+
reason?: string;
|
|
43
|
+
};
|
|
44
|
+
/** Ask the receiver to drop local pairing for this active peer link. */
|
|
45
|
+
type LanPairingUnpairRequiredPayload = {
|
|
46
|
+
reason?: string;
|
|
47
|
+
mode?: 'fresh' | 'stale';
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/event-names.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Cross-platform communication annotation taxonomy (search-only comments).
|
|
53
|
+
*
|
|
54
|
+
* Prefix:
|
|
55
|
+
* SYNRA-COMM::<Domain>::<Stage>::<NodeId>
|
|
56
|
+
*
|
|
57
|
+
* Domains:
|
|
58
|
+
* TCP | UDP_DISCOVERY | DEVICE_HANDSHAKE | PLUGIN_BRIDGE | MESSAGE_ENVELOPE
|
|
59
|
+
*
|
|
60
|
+
* Stages:
|
|
61
|
+
* CONNECT | SEND | RECEIVE | ACK | HEARTBEAT | CLOSE | ERROR
|
|
62
|
+
*
|
|
63
|
+
* Shared NodeId vocabulary:
|
|
64
|
+
* OPEN_TRANSPORT
|
|
65
|
+
* PROBE_SINGLE
|
|
66
|
+
* INBOUND_ACCEPT
|
|
67
|
+
* OUTBOUND_RECV_LOOP
|
|
68
|
+
* LAN_EVENT_ROUTE
|
|
69
|
+
* MESSAGE_SEND
|
|
70
|
+
* MESSAGE_RECV
|
|
71
|
+
* TRANSPORT_CLOSE
|
|
72
|
+
* TRANSPORT_HEARTBEAT
|
|
73
|
+
* TRANSPORT_ERROR
|
|
74
|
+
*
|
|
75
|
+
* Keep the same Domain/Stage/NodeId triplet across Node.js, Android, and iOS.
|
|
76
|
+
*/
|
|
77
|
+
declare const DEVICE_TCP_CONNECT_EVENT: 'device.tcp.connect';
|
|
78
|
+
declare const DEVICE_TCP_CONNECT_ACK_EVENT: 'device.tcp.connect.ack';
|
|
79
|
+
declare const DEVICE_TCP_ACK_EVENT: 'device.tcp.ack';
|
|
80
|
+
declare const DEVICE_TCP_CLOSE_EVENT: 'device.tcp.close';
|
|
81
|
+
declare const DEVICE_TCP_ERROR_EVENT: 'device.tcp.error';
|
|
82
|
+
declare const DEVICE_TCP_HEARTBEAT_EVENT: 'device.tcp.heartbeat';
|
|
83
|
+
declare const DEVICE_HOST_RETIRE_EVENT: 'device.host.retire';
|
|
84
|
+
declare const DEVICE_MEMBER_OFFLINE_EVENT: 'device.member.offline';
|
|
85
|
+
declare const DEVICE_DISPLAY_NAME_CHANGED_EVENT: 'device.display-name.changed';
|
|
86
|
+
declare const DEVICE_PAIRING_PREFIX: 'device.pairing.';
|
|
87
|
+
declare const DEVICE_PAIRING_REQUEST_EVENT: 'device.pairing.request';
|
|
88
|
+
declare const DEVICE_PAIRING_RESPONSE_EVENT: 'device.pairing.response';
|
|
89
|
+
declare const DEVICE_PAIRING_PEER_RESET_EVENT: 'device.pairing.peer-reset';
|
|
90
|
+
declare const DEVICE_PAIRING_UNPAIR_REQUIRED_EVENT: 'device.pairing.unpair-required';
|
|
91
|
+
declare function isDevicePairingEvent(event: string): boolean;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/index.d.ts
|
|
94
|
+
declare const PROTOCOL_VERSION: '1.0';
|
|
95
|
+
type DeviceId = string;
|
|
96
|
+
type TraceId = string;
|
|
97
|
+
type MessageId = string;
|
|
98
|
+
type ActionId = string;
|
|
99
|
+
type LegacySynraMessageType = 'share.detected' | 'action.proposed' | 'action.selected' | 'action.executing' | 'action.completed' | 'action.failed';
|
|
100
|
+
type TransportMessageType = 'transport.opened' | 'transport.closed' | 'transport.message.received' | 'transport.message.ack' | 'transport.error';
|
|
101
|
+
type RelayMessageType = 'relay.request' | 'relay.ack' | 'relay.result';
|
|
102
|
+
type ClusterHostMessageType = 'host.announce' | 'host.retire' | 'host.member.offline' | 'host.heartbeat';
|
|
103
|
+
type ElectionMessageType = 'election.vote.request' | 'election.vote.response' | 'election.win';
|
|
104
|
+
type CustomMessageType = `custom.${string}`;
|
|
105
|
+
type SynraMessageType = LegacySynraMessageType | TransportMessageType | RelayMessageType | ClusterHostMessageType | ElectionMessageType | CustomMessageType;
|
|
106
|
+
type RuntimeMessageType = 'runtime.request' | 'runtime.received' | 'runtime.started' | 'runtime.finished' | 'runtime.error';
|
|
107
|
+
type PluginSyncMessageType = 'plugin.catalog.request' | 'plugin.catalog.response';
|
|
108
|
+
type ProtocolMessageType = RuntimeMessageType | PluginSyncMessageType;
|
|
109
|
+
type ShareDetectedPayload = {
|
|
110
|
+
inputType: 'text' | 'url' | 'file';
|
|
111
|
+
raw: string;
|
|
112
|
+
metadata?: Record<string, unknown>;
|
|
113
|
+
};
|
|
114
|
+
type ActionProposedPayload = {
|
|
115
|
+
actionId: ActionId;
|
|
116
|
+
pluginId: string;
|
|
117
|
+
actionType: string;
|
|
118
|
+
label: string;
|
|
119
|
+
requiresConfirm: boolean;
|
|
120
|
+
payload: unknown;
|
|
121
|
+
};
|
|
122
|
+
type ActionExecutingPayload = {
|
|
123
|
+
actionId: ActionId;
|
|
124
|
+
pluginId: string;
|
|
125
|
+
startedAt: number;
|
|
126
|
+
};
|
|
127
|
+
type ActionCompletedPayload = {
|
|
128
|
+
actionId: ActionId;
|
|
129
|
+
pluginId: string;
|
|
130
|
+
finishedAt: number;
|
|
131
|
+
output?: unknown;
|
|
132
|
+
};
|
|
133
|
+
type ActionFailedPayload = {
|
|
134
|
+
actionId: ActionId;
|
|
135
|
+
pluginId: string;
|
|
136
|
+
finishedAt: number;
|
|
137
|
+
code: SynraErrorCode;
|
|
138
|
+
message: string;
|
|
139
|
+
retryable: boolean;
|
|
140
|
+
details?: unknown;
|
|
141
|
+
};
|
|
142
|
+
type TransportOpenedPayload = {
|
|
143
|
+
deviceId: DeviceId;
|
|
144
|
+
host?: string;
|
|
145
|
+
port?: number;
|
|
146
|
+
openedAt: number;
|
|
147
|
+
};
|
|
148
|
+
type TransportClosedPayload = {
|
|
149
|
+
deviceId: DeviceId;
|
|
150
|
+
closedAt: number;
|
|
151
|
+
reason?: string;
|
|
152
|
+
};
|
|
153
|
+
type TransportMessageReceivedPayload = {
|
|
154
|
+
requestId: string;
|
|
155
|
+
event: string;
|
|
156
|
+
target: DeviceId;
|
|
157
|
+
from: DeviceId;
|
|
158
|
+
replyRequestId?: string;
|
|
159
|
+
payload: unknown;
|
|
160
|
+
timestamp: number;
|
|
161
|
+
};
|
|
162
|
+
type TransportMessageAckPayload = {
|
|
163
|
+
requestId: string;
|
|
164
|
+
target: DeviceId;
|
|
165
|
+
event?: string;
|
|
166
|
+
from?: DeviceId;
|
|
167
|
+
replyRequestId: string;
|
|
168
|
+
timestamp: number;
|
|
169
|
+
};
|
|
170
|
+
type TransportErrorPayload = {
|
|
171
|
+
deviceId?: DeviceId;
|
|
172
|
+
code: SynraErrorCode | 'TRANSPORT_IO_ERROR';
|
|
173
|
+
message: string;
|
|
174
|
+
retryable?: boolean;
|
|
175
|
+
details?: unknown;
|
|
176
|
+
};
|
|
177
|
+
type RelayRequestPayload = {
|
|
178
|
+
requestId: string;
|
|
179
|
+
routeTo: DeviceId;
|
|
180
|
+
data: unknown;
|
|
181
|
+
};
|
|
182
|
+
type RelayAckPayload = {
|
|
183
|
+
requestId: string;
|
|
184
|
+
ackedAt: number;
|
|
185
|
+
};
|
|
186
|
+
type RelayResultPayload = {
|
|
187
|
+
requestId: string;
|
|
188
|
+
ok: boolean;
|
|
189
|
+
result?: unknown;
|
|
190
|
+
error?: ProtocolErrorPayload;
|
|
191
|
+
};
|
|
192
|
+
type HostAnnouncePayload = {
|
|
193
|
+
hostId: DeviceId;
|
|
194
|
+
term: number;
|
|
195
|
+
epoch: number;
|
|
196
|
+
};
|
|
197
|
+
type HostRetirePayload = {
|
|
198
|
+
hostId: DeviceId;
|
|
199
|
+
term: number;
|
|
200
|
+
retireAt: number;
|
|
201
|
+
reason?: string;
|
|
202
|
+
};
|
|
203
|
+
type HostMemberOfflinePayload = {
|
|
204
|
+
nodeId: DeviceId;
|
|
205
|
+
requestId?: string;
|
|
206
|
+
offlineAt: number;
|
|
207
|
+
reason?: string;
|
|
208
|
+
};
|
|
209
|
+
type HostHeartbeatPayload = {
|
|
210
|
+
hostId: DeviceId;
|
|
211
|
+
term?: number;
|
|
212
|
+
epoch?: number;
|
|
213
|
+
timestamp: number;
|
|
214
|
+
};
|
|
215
|
+
type ElectionVoteRequestPayload = {
|
|
216
|
+
candidateId: DeviceId;
|
|
217
|
+
term: number;
|
|
218
|
+
candidateEpochHint?: number;
|
|
219
|
+
};
|
|
220
|
+
type ElectionVoteResponsePayload = {
|
|
221
|
+
voterId: DeviceId;
|
|
222
|
+
term: number;
|
|
223
|
+
granted: boolean;
|
|
224
|
+
};
|
|
225
|
+
type ElectionWinPayload = {
|
|
226
|
+
hostId: DeviceId;
|
|
227
|
+
term: number;
|
|
228
|
+
epoch: number;
|
|
229
|
+
};
|
|
230
|
+
type SynraCrossDevicePayloadByType = {
|
|
231
|
+
'share.detected': ShareDetectedPayload;
|
|
232
|
+
'action.proposed': ActionProposedPayload;
|
|
233
|
+
'action.selected': SynraActionRequest;
|
|
234
|
+
'action.executing': ActionExecutingPayload;
|
|
235
|
+
'action.completed': ActionCompletedPayload;
|
|
236
|
+
'action.failed': ActionFailedPayload;
|
|
237
|
+
'transport.opened': TransportOpenedPayload;
|
|
238
|
+
'transport.closed': TransportClosedPayload;
|
|
239
|
+
'transport.message.received': TransportMessageReceivedPayload;
|
|
240
|
+
'transport.message.ack': TransportMessageAckPayload;
|
|
241
|
+
'transport.error': TransportErrorPayload;
|
|
242
|
+
'relay.request': RelayRequestPayload;
|
|
243
|
+
'relay.ack': RelayAckPayload;
|
|
244
|
+
'relay.result': RelayResultPayload;
|
|
245
|
+
'host.announce': HostAnnouncePayload;
|
|
246
|
+
'host.retire': HostRetirePayload;
|
|
247
|
+
'host.member.offline': HostMemberOfflinePayload;
|
|
248
|
+
'host.heartbeat': HostHeartbeatPayload;
|
|
249
|
+
'election.vote.request': ElectionVoteRequestPayload;
|
|
250
|
+
'election.vote.response': ElectionVoteResponsePayload;
|
|
251
|
+
'election.win': ElectionWinPayload;
|
|
252
|
+
} & { [K in CustomMessageType]: unknown };
|
|
253
|
+
type SynraCrossDeviceMessage<TType extends SynraMessageType = SynraMessageType, TPayload = SynraCrossDevicePayloadByType[TType]> = {
|
|
254
|
+
protocolVersion: typeof PROTOCOL_VERSION;
|
|
255
|
+
requestId: string;
|
|
256
|
+
replyRequestId?: string;
|
|
257
|
+
event: string;
|
|
258
|
+
traceId: TraceId;
|
|
259
|
+
sentAt: number;
|
|
260
|
+
ttlMs: number;
|
|
261
|
+
from: DeviceId;
|
|
262
|
+
target: DeviceId;
|
|
263
|
+
payload: TPayload;
|
|
264
|
+
};
|
|
265
|
+
type ProtocolEnvelope<TType extends ProtocolMessageType, TPayload> = {
|
|
266
|
+
protocolVersion: typeof PROTOCOL_VERSION;
|
|
267
|
+
requestId: string;
|
|
268
|
+
replyRequestId?: string;
|
|
269
|
+
event: TType;
|
|
270
|
+
timestamp: number;
|
|
271
|
+
payload: TPayload;
|
|
272
|
+
};
|
|
273
|
+
type SynraActionRequest<TPayload = unknown> = {
|
|
274
|
+
actionId: ActionId;
|
|
275
|
+
pluginId: string;
|
|
276
|
+
actionType: string;
|
|
277
|
+
payload: TPayload;
|
|
278
|
+
};
|
|
279
|
+
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';
|
|
280
|
+
type ProtocolErrorCode = SynraErrorCode;
|
|
281
|
+
type RuntimeFinishedStatus = 'success' | 'failed' | 'cancelled';
|
|
282
|
+
type RuntimeRequestPayload<TInput = unknown> = {
|
|
283
|
+
input: TInput;
|
|
284
|
+
requestedAt: number;
|
|
285
|
+
};
|
|
286
|
+
type RuntimeReceivedPayload = {
|
|
287
|
+
acknowledgedAt: number;
|
|
288
|
+
};
|
|
289
|
+
type RuntimeStartedPayload = {
|
|
290
|
+
startedAt: number;
|
|
291
|
+
};
|
|
292
|
+
type ProtocolErrorPayload = {
|
|
293
|
+
code: ProtocolErrorCode;
|
|
294
|
+
message: string;
|
|
295
|
+
details?: unknown;
|
|
296
|
+
};
|
|
297
|
+
type RuntimeFinishedPayload<TResult = unknown> = {
|
|
298
|
+
status: RuntimeFinishedStatus;
|
|
299
|
+
finishedAt: number;
|
|
300
|
+
result?: TResult;
|
|
301
|
+
error?: ProtocolErrorPayload;
|
|
302
|
+
};
|
|
303
|
+
type RuntimeErrorPayload = {
|
|
304
|
+
code: ProtocolErrorCode;
|
|
305
|
+
message: string;
|
|
306
|
+
retryable?: boolean;
|
|
307
|
+
details?: unknown;
|
|
308
|
+
};
|
|
309
|
+
type PluginCatalogRequestPayload = {
|
|
310
|
+
knownPluginIds?: string[];
|
|
311
|
+
};
|
|
312
|
+
type PluginCatalogItem = {
|
|
313
|
+
pluginId: string;
|
|
314
|
+
version: string;
|
|
315
|
+
displayName: string;
|
|
316
|
+
status?: 'installed' | 'available';
|
|
317
|
+
builtin?: boolean;
|
|
318
|
+
defaultPage?: string;
|
|
319
|
+
icon?: string;
|
|
320
|
+
logoPath?: string;
|
|
321
|
+
packageName?: string;
|
|
322
|
+
};
|
|
323
|
+
type PluginCatalogResponsePayload = {
|
|
324
|
+
plugins: PluginCatalogItem[];
|
|
325
|
+
generatedAt: number;
|
|
326
|
+
};
|
|
327
|
+
type ProtocolPayloadByType = {
|
|
328
|
+
'runtime.request': RuntimeRequestPayload;
|
|
329
|
+
'runtime.received': RuntimeReceivedPayload;
|
|
330
|
+
'runtime.started': RuntimeStartedPayload;
|
|
331
|
+
'runtime.finished': RuntimeFinishedPayload;
|
|
332
|
+
'runtime.error': RuntimeErrorPayload;
|
|
333
|
+
'plugin.catalog.request': PluginCatalogRequestPayload;
|
|
334
|
+
'plugin.catalog.response': PluginCatalogResponsePayload;
|
|
335
|
+
};
|
|
336
|
+
type MessageByType<K extends keyof ProtocolPayloadByType> = ProtocolEnvelope<K, ProtocolPayloadByType[K]>;
|
|
337
|
+
type SynraRuntimeMessage = MessageByType<'runtime.request'> | MessageByType<'runtime.received'> | MessageByType<'runtime.started'> | MessageByType<'runtime.finished'> | MessageByType<'runtime.error'>;
|
|
338
|
+
type SynraPluginSyncMessage = MessageByType<'plugin.catalog.request'> | MessageByType<'plugin.catalog.response'>;
|
|
339
|
+
type SynraProtocolMessage = SynraRuntimeMessage | SynraPluginSyncMessage;
|
|
340
|
+
type SynraActionReceipt = {
|
|
341
|
+
ok: true;
|
|
342
|
+
actionId: ActionId;
|
|
343
|
+
handledBy: string;
|
|
344
|
+
durationMs: number;
|
|
345
|
+
output?: unknown;
|
|
346
|
+
} | {
|
|
347
|
+
ok: false;
|
|
348
|
+
actionId: ActionId;
|
|
349
|
+
handledBy: string;
|
|
350
|
+
durationMs: number;
|
|
351
|
+
retryable: boolean;
|
|
352
|
+
error: {
|
|
353
|
+
code: SynraErrorCode;
|
|
354
|
+
message: string;
|
|
355
|
+
details?: unknown;
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
declare function unknownToErrorMessage(error: unknown, fallback: string): string;
|
|
359
|
+
declare function createMessage<TPayload>(input: Omit<SynraCrossDeviceMessage<SynraMessageType, TPayload>, 'protocolVersion'>): SynraCrossDeviceMessage<SynraMessageType, TPayload>;
|
|
360
|
+
declare function createProtocolMessage<TType extends keyof ProtocolPayloadByType>(input: Omit<ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>, 'protocolVersion'>): ProtocolEnvelope<TType, ProtocolPayloadByType[TType]>;
|
|
361
|
+
//#endregion
|
|
362
|
+
export { ActionCompletedPayload, ActionExecutingPayload, ActionFailedPayload, ActionId, ActionProposedPayload, ClusterHostMessageType, CustomMessageType, 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, HostAnnouncePayload, HostHeartbeatPayload, HostMemberOfflinePayload, HostRetirePayload, LAN_WIRE_EVENT_NAMES, LanDeviceDisplayNameChangedPayload, LanPairingPeerResetPayload, LanPairingRequestPayload, LanPairingResponsePayload, LanPairingUnpairRequiredPayload, LanWireEventEnvelope, LanWireEventName, LegacySynraMessageType, MessageId, PROTOCOL_VERSION, 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, SynraPluginSyncMessage, SynraProtocolMessage, SynraRuntimeMessage, TraceId, TransportClosedPayload, TransportErrorPayload, TransportMessageAckPayload, TransportMessageReceivedPayload, TransportMessageType, TransportOpenedPayload, createMessage, createProtocolMessage, isDevicePairingEvent, isLanWireEventName, unknownToErrorMessage };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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
|
|
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/index.ts
|
|
59
|
+
const PROTOCOL_VERSION = "1.0";
|
|
60
|
+
function unknownToErrorMessage(error, fallback) {
|
|
61
|
+
return error instanceof Error ? error.message : fallback;
|
|
62
|
+
}
|
|
63
|
+
function createMessage(input) {
|
|
64
|
+
return {
|
|
65
|
+
...input,
|
|
66
|
+
protocolVersion: "1.0"
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function createProtocolMessage(input) {
|
|
70
|
+
return {
|
|
71
|
+
...input,
|
|
72
|
+
protocolVersion: "1.0"
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { 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, createMessage, createProtocolMessage, isDevicePairingEvent, isLanWireEventName, unknownToErrorMessage };
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@synra/protocol",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared cross-device protocol contracts for Synra.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^25.6.0",
|
|
19
|
+
"bumpp": "^11.0.1",
|
|
20
|
+
"typescript": "^6.0.3",
|
|
21
|
+
"vite-plus": "^0.1.19"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vp pack",
|
|
25
|
+
"dev": "vp pack --watch",
|
|
26
|
+
"test": "vp test",
|
|
27
|
+
"check": "vp check"
|
|
28
|
+
}
|
|
29
|
+
}
|