@inflatable-cookie/longhorn 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.
Files changed (178) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -0
  3. package/package.json +205 -0
  4. package/src/agent-control/index.ts +20 -0
  5. package/src/agent-control/inject.ts +4 -0
  6. package/src/agent-control/shim.ts +722 -0
  7. package/src/bridge/direct.ts +22 -0
  8. package/src/bridge/generated/fields.ts +32 -0
  9. package/src/bridge/generated/protocol.ts +218 -0
  10. package/src/bridge/generated/variant-fields.ts +10 -0
  11. package/src/bridge/index.ts +15 -0
  12. package/src/bridge/job.ts +51 -0
  13. package/src/bridge/loopback.ts +84 -0
  14. package/src/bridge/operation.ts +166 -0
  15. package/src/bridge/router.ts +71 -0
  16. package/src/bridge/runtime/connection.ts +318 -0
  17. package/src/bridge/runtime/policy.ts +89 -0
  18. package/src/bridge/runtime/retry.ts +60 -0
  19. package/src/bridge/runtime.ts +3 -0
  20. package/src/bridge/session.ts +67 -0
  21. package/src/bridge/stream/connection.ts +146 -0
  22. package/src/bridge/stream/source.ts +61 -0
  23. package/src/bridge/stream/tracker.ts +109 -0
  24. package/src/bridge/stream.ts +6 -0
  25. package/src/bridge/supervision.ts +204 -0
  26. package/src/bridge/validation/base.ts +164 -0
  27. package/src/bridge/validation/jobs.ts +105 -0
  28. package/src/bridge/validation/negotiation.ts +242 -0
  29. package/src/bridge/validation/operations.ts +213 -0
  30. package/src/bridge/validation/streams.ts +47 -0
  31. package/src/bridge/validation.ts +5 -0
  32. package/src/commands/client.ts +124 -0
  33. package/src/commands/controller.ts +411 -0
  34. package/src/commands/generated/fields.ts +43 -0
  35. package/src/commands/generated/protocol.ts +876 -0
  36. package/src/commands/generated/variant-fields.ts +88 -0
  37. package/src/commands/index.ts +13 -0
  38. package/src/commands/keyboard.ts +361 -0
  39. package/src/commands/ports.ts +82 -0
  40. package/src/commands/projectors.ts +306 -0
  41. package/src/commands/validation.ts +444 -0
  42. package/src/config/client.ts +215 -0
  43. package/src/config/generated/base.ts +714 -0
  44. package/src/config/generated/fields.ts +54 -0
  45. package/src/config/generated/label-template.ts +14 -0
  46. package/src/config/generated/labels.ts +30 -0
  47. package/src/config/generated/protocol.ts +3 -0
  48. package/src/config/generated/restore.ts +658 -0
  49. package/src/config/generated/variant-fields.ts +129 -0
  50. package/src/config/index.ts +12 -0
  51. package/src/config/names.ts +19 -0
  52. package/src/config/validation/commands.ts +155 -0
  53. package/src/config/validation/outcomes.ts +243 -0
  54. package/src/config/validation/primitives.ts +174 -0
  55. package/src/config/validation/projection.ts +351 -0
  56. package/src/config/validation.ts +7 -0
  57. package/src/core/connection.ts +252 -0
  58. package/src/core/index.ts +2 -0
  59. package/src/core/transport.ts +24 -0
  60. package/src/history/client.ts +65 -0
  61. package/src/history/controller.ts +385 -0
  62. package/src/history/direct.ts +21 -0
  63. package/src/history/generated/fields.ts +18 -0
  64. package/src/history/generated/protocol.ts +389 -0
  65. package/src/history/generated/variant-fields.ts +27 -0
  66. package/src/history/index.ts +13 -0
  67. package/src/history/ports.ts +31 -0
  68. package/src/history/serialized.ts +38 -0
  69. package/src/history/validation.ts +334 -0
  70. package/src/history-tree/client.ts +16 -0
  71. package/src/history-tree/controller.ts +199 -0
  72. package/src/history-tree/direct.ts +3 -0
  73. package/src/history-tree/generated/fields.ts +26 -0
  74. package/src/history-tree/generated/protocol.ts +711 -0
  75. package/src/history-tree/generated/variant-fields.ts +39 -0
  76. package/src/history-tree/index.ts +13 -0
  77. package/src/history-tree/ports.ts +43 -0
  78. package/src/history-tree/serialized.ts +15 -0
  79. package/src/history-tree/validation.ts +269 -0
  80. package/src/layout/generated/protocol.ts +289 -0
  81. package/src/layout/index.ts +4 -0
  82. package/src/layout/ratio.ts +22 -0
  83. package/src/layout/validation.ts +110 -0
  84. package/src/layout/visibility.ts +30 -0
  85. package/src/licence/client.ts +32 -0
  86. package/src/licence/controller.ts +301 -0
  87. package/src/licence/direct.ts +3 -0
  88. package/src/licence/generated/fields.ts +17 -0
  89. package/src/licence/generated/key-conformance.json +42 -0
  90. package/src/licence/generated/protocol.ts +249 -0
  91. package/src/licence/generated/variant-fields.ts +34 -0
  92. package/src/licence/index.ts +14 -0
  93. package/src/licence/key.ts +125 -0
  94. package/src/licence/ports.ts +39 -0
  95. package/src/licence/serialized.ts +13 -0
  96. package/src/licence/validation.ts +226 -0
  97. package/src/native-content/client.ts +474 -0
  98. package/src/native-content/direct.ts +16 -0
  99. package/src/native-content/generated/fields.ts +32 -0
  100. package/src/native-content/generated/protocol.ts +498 -0
  101. package/src/native-content/generated/variant-fields.ts +77 -0
  102. package/src/native-content/index.ts +12 -0
  103. package/src/native-content/ports.ts +46 -0
  104. package/src/native-content/serialized.ts +50 -0
  105. package/src/native-content/validation/base.ts +194 -0
  106. package/src/native-content/validation/messages.ts +192 -0
  107. package/src/native-content/validation/state.ts +404 -0
  108. package/src/native-content/validation.ts +7 -0
  109. package/src/notifications/client.ts +106 -0
  110. package/src/notifications/controller.ts +240 -0
  111. package/src/notifications/direct.ts +12 -0
  112. package/src/notifications/generated/fields.ts +19 -0
  113. package/src/notifications/generated/labels.ts +20 -0
  114. package/src/notifications/generated/protocol.ts +522 -0
  115. package/src/notifications/generated/variant-fields.ts +37 -0
  116. package/src/notifications/index.ts +16 -0
  117. package/src/notifications/ports.ts +22 -0
  118. package/src/notifications/serialized.ts +27 -0
  119. package/src/notifications/toast.ts +41 -0
  120. package/src/notifications/tone.ts +27 -0
  121. package/src/notifications/validation.ts +246 -0
  122. package/src/operation/bridge.ts +168 -0
  123. package/src/operation/client.ts +167 -0
  124. package/src/operation/controller.ts +321 -0
  125. package/src/operation/direct.ts +15 -0
  126. package/src/operation/generated/fields.ts +20 -0
  127. package/src/operation/generated/labels.ts +15 -0
  128. package/src/operation/generated/protocol.ts +762 -0
  129. package/src/operation/generated/variant-fields.ts +60 -0
  130. package/src/operation/index.ts +14 -0
  131. package/src/operation/ports.ts +29 -0
  132. package/src/operation/serialized.ts +39 -0
  133. package/src/operation/validation.ts +479 -0
  134. package/src/settings/client.ts +142 -0
  135. package/src/settings/connection.ts +246 -0
  136. package/src/settings/generated/fields.ts +34 -0
  137. package/src/settings/generated/protocol.ts +668 -0
  138. package/src/settings/generated/variant-fields.ts +26 -0
  139. package/src/settings/index.ts +12 -0
  140. package/src/settings/names.ts +8 -0
  141. package/src/settings/registry.ts +141 -0
  142. package/src/settings/validation/authority.ts +66 -0
  143. package/src/settings/validation/command.ts +165 -0
  144. package/src/settings/validation/error.ts +33 -0
  145. package/src/settings/validation/primitives.ts +203 -0
  146. package/src/settings/validation/projection.ts +50 -0
  147. package/src/settings/validation/registry.ts +170 -0
  148. package/src/settings/validation.ts +4 -0
  149. package/src/surface-transfer/client.ts +54 -0
  150. package/src/surface-transfer/generated/fields.ts +12 -0
  151. package/src/surface-transfer/generated/protocol.ts +61 -0
  152. package/src/surface-transfer/generated/variant-fields.ts +30 -0
  153. package/src/surface-transfer/index.ts +9 -0
  154. package/src/surface-transfer/validation.ts +209 -0
  155. package/src/surfaces/client.ts +140 -0
  156. package/src/surfaces/generated/fields.ts +19 -0
  157. package/src/surfaces/generated/protocol.ts +217 -0
  158. package/src/surfaces/generated/variant-fields.ts +42 -0
  159. package/src/surfaces/index.ts +9 -0
  160. package/src/surfaces/validation.ts +199 -0
  161. package/src/transfer/client.ts +133 -0
  162. package/src/transfer/connection.ts +87 -0
  163. package/src/transfer/generated/fields.ts +23 -0
  164. package/src/transfer/generated/protocol.ts +171 -0
  165. package/src/transfer/generated/variant-fields.ts +45 -0
  166. package/src/transfer/index.ts +11 -0
  167. package/src/transfer/payload.ts +71 -0
  168. package/src/transfer/validation.ts +282 -0
  169. package/src/update/client.ts +29 -0
  170. package/src/update/controller.ts +255 -0
  171. package/src/update/direct.ts +3 -0
  172. package/src/update/generated/fields.ts +14 -0
  173. package/src/update/generated/protocol.ts +238 -0
  174. package/src/update/generated/variant-fields.ts +44 -0
  175. package/src/update/index.ts +14 -0
  176. package/src/update/ports.ts +36 -0
  177. package/src/update/serialized.ts +12 -0
  178. package/src/update/validation.ts +191 -0
@@ -0,0 +1,87 @@
1
+ import {
2
+ CheckedSnapshotConnection,
3
+ type ConnectionFailure,
4
+ type ConnectionFailureReporter,
5
+ type EventTransport,
6
+ } from "@inflatable-cookie/longhorn/core";
7
+
8
+ import type { TransferClientSnapshot } from "./generated/protocol.ts";
9
+ import { assertValidTransferClientSnapshot } from "./validation.ts";
10
+
11
+ export const TRANSFER_CLIENT_CHANGED_EVENT =
12
+ "longhorn://transfer/client-changed";
13
+
14
+ export type TransferClientSnapshotListener = (
15
+ snapshot: TransferClientSnapshot,
16
+ ) => void;
17
+
18
+ export class TransferClientConnection {
19
+ readonly ready: Promise<TransferClientSnapshot>;
20
+
21
+ readonly #connection: CheckedSnapshotConnection<TransferClientSnapshot>;
22
+
23
+ constructor(
24
+ transport: EventTransport,
25
+ loadSnapshot: () => Promise<TransferClientSnapshot>,
26
+ listener?: TransferClientSnapshotListener,
27
+ onFailure?: ConnectionFailureReporter,
28
+ ) {
29
+ this.#connection = new CheckedSnapshotConnection({
30
+ listen: (receive) =>
31
+ transport.listen(TRANSFER_CLIENT_CHANGED_EVENT, receive),
32
+ loadSnapshot,
33
+ validateSnapshot: parseTransferClientSnapshot,
34
+ handleEvent: (value) => ({ kind: "snapshot", value }),
35
+ isNewer: isCurrentTransferClientSnapshot,
36
+ onSnapshot: listener,
37
+ onFailure,
38
+ disposedBeforeReadyError: () =>
39
+ new TransferClientConnectionDisposedError(),
40
+ });
41
+ this.ready = this.#connection.ready.then((snapshot) => {
42
+ if (snapshot === undefined) {
43
+ throw new TransferClientConnectionDisposedError();
44
+ }
45
+ return snapshot;
46
+ });
47
+ }
48
+
49
+ current(): TransferClientSnapshot | undefined {
50
+ return this.#connection.current();
51
+ }
52
+
53
+ failures(): readonly ConnectionFailure[] {
54
+ return this.#connection.failures();
55
+ }
56
+
57
+ dispose(): Promise<void> {
58
+ return this.#connection.dispose();
59
+ }
60
+ }
61
+
62
+ export class TransferClientConnectionDisposedError extends Error {
63
+ constructor() {
64
+ super("transfer client connection was disposed during registration");
65
+ this.name = "TransferClientConnectionDisposedError";
66
+ }
67
+ }
68
+
69
+ function parseTransferClientSnapshot(
70
+ value: unknown,
71
+ ): TransferClientSnapshot {
72
+ assertValidTransferClientSnapshot(value);
73
+ return value;
74
+ }
75
+
76
+ function isCurrentTransferClientSnapshot(
77
+ candidate: TransferClientSnapshot,
78
+ current: TransferClientSnapshot | undefined,
79
+ ): boolean {
80
+ if (current === undefined || candidate.client_epoch > current.client_epoch) {
81
+ return true;
82
+ }
83
+ return (
84
+ candidate.client_epoch === current.client_epoch &&
85
+ candidate.client_id === current.client_id
86
+ );
87
+ }
@@ -0,0 +1,23 @@
1
+ // @generated by `effigy generate:transfer`; do not edit.
2
+ // Allowed field names per protocol type, from the Rust structs.
3
+ // A `record()` given one of these rejects unknown and missing keys —
4
+ // contract 010's Boundary Validation Target.
5
+
6
+ export const TRANSFER_FIELDS: Record<string, readonly string[]> = {
7
+ "ClientPoint": ["x", "y"],
8
+ "ClientSize": ["width", "height"],
9
+ "ClientRect": ["origin", "size"],
10
+ "TransferPayload": ["protocol_version", "session_id"],
11
+ "PanelSessionStartRequest": ["protocol_version", "request_id", "panel_instance_id"],
12
+ "TransferCancelRequest": ["protocol_version", "request_id", "session_id"],
13
+ "ClientDropZone": ["id", "bounds", "insertion_position", "accepted_capability", "target"],
14
+ "TransferLeaseRequest": ["protocol_version", "request_id", "client_id", "client_epoch", "generation", "zones"],
15
+ "PanelTransferCommand": ["protocol_version", "request_id", "session_id", "selector"],
16
+ "TransferClientSnapshot": ["protocol_version", "client_id", "client_epoch", "current_lease_generation"],
17
+ "TransferSessionStarted": ["protocol_version", "request_id", "payload"],
18
+ "TransferLeaseReceipt": ["protocol_version", "request_id", "client_id", "client_epoch", "generation", "zone_count"],
19
+ "TransferCancelReceipt": ["protocol_version", "request_id", "session_id", "status"],
20
+ "TransferCommittedTarget": ["path", "window_id", "drop_zone_id", "insertion_position", "binding"],
21
+ "PanelTransferCompletion": ["protocol_version", "request_id", "session_id", "source_host_binding_id", "target_host_binding_id", "source_binding_kind", "target_binding_kind", "previous_revision", "committed_revision", "authoritative_document", "target"],
22
+ "TransferAbort": ["protocol_version", "request_id", "source", "message", "retryable", "session_consumed"],
23
+ };
@@ -0,0 +1,171 @@
1
+ // @generated by `effigy generate:transfer`; do not edit.
2
+ // Rust serde types are the wire authority.
3
+
4
+ import type { SurfaceId, SurfaceDocument, SurfaceRevision, PanelInstanceId, RegionId } from "@inflatable-cookie/longhorn/layout";
5
+
6
+ export const TRANSFER_PROTOCOL_VERSION = 1 as const;
7
+ export const TRANSFER_TARGET_BINDING_KINDS = ["panel_region","surface_window"] as const;
8
+ export const TRANSFER_COMMIT_SELECTOR_KINDS = ["explicit_zone","screen_point"] as const;
9
+ export const TRANSFER_ABORT_DOMAINS = ["transfer","panel"] as const;
10
+ export const TRANSFER_SESSION_RESPONSE_STATUSES = ["started","aborted"] as const;
11
+ export const TRANSFER_LEASE_RESPONSE_STATUSES = ["published","aborted"] as const;
12
+ export const TRANSFER_CANCEL_RESPONSE_STATUSES = ["cancelled","aborted"] as const;
13
+ export const PANEL_TRANSFER_RESPONSE_STATUSES = ["committed","aborted"] as const;
14
+ export const TRANSFER_ERROR_CODES = ["clock_regressed","invalid_lifetime","session_capacity","session_id_allocation","session_id_collision","unknown_session","session_expired","session_cancelled","session_replayed","source_window_destroyed","source_client_changed","client_window_capacity","unknown_client_epoch","stale_client_epoch","stale_lease_generation","lease_capacity","invalid_lease","lease_expired","invalid_live_windows","target_window_missing","stale_window_geometry","no_target","ambiguous_window","ambiguous_zone","ineligible_capability"] as const;
15
+ export const PANEL_TRANSFER_ERROR_CODES = ["invalid_binding_snapshot","unknown_host_binding","stale_host_binding","layout_load_failed","layout_unavailable","unknown_panel","panel_not_movable","source_changed","unsupported_source","unsupported_target","cross_document","copy_unsupported","stale_surface_revision","target_changed","ineligible_target","instance_policy_exceeded","invalid_insertion_position","layout_mutation_rejected","publication_failed","transfer_rejected"] as const;
16
+
17
+ export type DomainId = string;
18
+
19
+ export type DropZoneId = string;
20
+
21
+ export type TransferClientId = string;
22
+
23
+ export type TransferHostBindingId = string;
24
+
25
+ export type TransferRequestId = string;
26
+
27
+ export type WindowId = string;
28
+
29
+ export type ClientLogicalPx = number;
30
+
31
+ export type ClientPoint = { x: ClientLogicalPx, y: ClientLogicalPx, };
32
+
33
+ export type ClientSize = { width: ClientLogicalPx, height: ClientLogicalPx, };
34
+
35
+ export type ClientRect = { origin: ClientPoint, size: ClientSize, };
36
+
37
+ export type DragSessionId = string;
38
+
39
+ export type ClientEpoch = number;
40
+
41
+ export type LeaseGeneration = number;
42
+
43
+ export type TransferRevision = number;
44
+
45
+ export type InsertionPosition = number;
46
+
47
+ export type TransferProtocolVersion = number;
48
+
49
+ export type TransferCapability = "move_panel" | "move_surface";
50
+
51
+ export type TransferTargetBinding = { "kind": "panel_region",
52
+ /**
53
+ * Current panel-host binding.
54
+ */
55
+ host_binding_id: TransferHostBindingId,
56
+ /**
57
+ * Authoritative layout document identity.
58
+ */
59
+ document_id: DomainId,
60
+ /**
61
+ * Advertised layout revision.
62
+ */
63
+ revision: TransferRevision,
64
+ /**
65
+ * Target layout container.
66
+ */
67
+ surface_id: SurfaceId,
68
+ /**
69
+ * Target semantic region.
70
+ */
71
+ region_id: RegionId, } | { "kind": "surface_window",
72
+ /**
73
+ * Current target host binding.
74
+ */
75
+ host_binding_id: TransferHostBindingId,
76
+ /**
77
+ * Authoritative Surface document identity.
78
+ */
79
+ document_id: DomainId,
80
+ /**
81
+ * Advertised Surface revision.
82
+ */
83
+ revision: TransferRevision, };
84
+
85
+ export type TransferPayload = { protocol_version: number, session_id: DragSessionId, };
86
+
87
+ export type SessionCancellationStatus = "cancelled" | "already_cancelled";
88
+
89
+ export type TargetResolutionPath = "explicit_zone" | "screen_point";
90
+
91
+ export type PanelHostBindingKind = "direct_window" | "surface_container";
92
+
93
+ export type TransferErrorCode = "clock_regressed" | "invalid_lifetime" | "session_capacity" | "session_id_allocation" | "session_id_collision" | "unknown_session" | "session_expired" | "session_cancelled" | "session_replayed" | "source_window_destroyed" | "source_client_changed" | "client_window_capacity" | "unknown_client_epoch" | "stale_client_epoch" | "stale_lease_generation" | "lease_capacity" | "invalid_lease" | "lease_expired" | "invalid_live_windows" | "target_window_missing" | "stale_window_geometry" | "no_target" | "ambiguous_window" | "ambiguous_zone" | "ineligible_capability";
94
+
95
+ export type PanelTransferErrorCode = "invalid_binding_snapshot" | "unknown_host_binding" | "stale_host_binding" | "layout_load_failed" | "layout_unavailable" | "unknown_panel" | "panel_not_movable" | "source_changed" | "unsupported_source" | "unsupported_target" | "cross_document" | "copy_unsupported" | "stale_surface_revision" | "target_changed" | "ineligible_target" | "instance_policy_exceeded" | "invalid_insertion_position" | "layout_mutation_rejected" | "publication_failed" | "transfer_rejected";
96
+
97
+ export type PanelSessionStartRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, panel_instance_id: PanelInstanceId, };
98
+
99
+ export type TransferCancelRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, };
100
+
101
+ export type ClientDropZone = { id: DropZoneId, bounds: ClientRect, insertion_position: InsertionPosition | null, accepted_capability: TransferCapability, target: TransferTargetBinding, };
102
+
103
+ export type TransferLeaseRequest = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, client_id: TransferClientId, client_epoch: ClientEpoch, generation: LeaseGeneration, zones: Array<ClientDropZone>, };
104
+
105
+ export type TransferCommitSelector = { "kind": "explicit_zone",
106
+ /**
107
+ * Current lease-local zone identity.
108
+ */
109
+ drop_zone_id: DropZoneId, } | { "kind": "screen_point",
110
+ /**
111
+ * Screen-DIP point with no target or mutation authority.
112
+ */
113
+ point: { x: number; y: number }, };
114
+
115
+ export type PanelTransferCommand = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, selector: TransferCommitSelector, };
116
+
117
+ export type TransferClientSnapshot = { protocol_version: TransferProtocolVersion, client_id: TransferClientId, client_epoch: ClientEpoch, current_lease_generation: LeaseGeneration | null, };
118
+
119
+ export type TransferSessionStarted = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, payload: TransferPayload, };
120
+
121
+ export type TransferLeaseReceipt = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, client_id: TransferClientId, client_epoch: ClientEpoch, generation: LeaseGeneration, zone_count: number, };
122
+
123
+ export type TransferCancelReceipt = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, status: SessionCancellationStatus, };
124
+
125
+ export type TransferCommittedTarget = { path: TargetResolutionPath, window_id: WindowId, drop_zone_id: DropZoneId, insertion_position: InsertionPosition | null, binding: TransferTargetBinding, };
126
+
127
+ export type PanelTransferCompletion = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, session_id: DragSessionId, source_host_binding_id: TransferHostBindingId, target_host_binding_id: TransferHostBindingId, source_binding_kind: PanelHostBindingKind, target_binding_kind: PanelHostBindingKind, previous_revision: SurfaceRevision, committed_revision: SurfaceRevision, authoritative_document: SurfaceDocument, target: TransferCommittedTarget, };
128
+
129
+ export type TransferAbortSource = { "domain": "transfer", "code": TransferErrorCode } | { "domain": "panel", "code": PanelTransferErrorCode };
130
+
131
+ export type TransferAbort = { protocol_version: TransferProtocolVersion, request_id: TransferRequestId, source: TransferAbortSource, message: string, retryable: boolean, session_consumed: boolean, };
132
+
133
+ export type TransferSessionResponse = { "status": "started",
134
+ /**
135
+ * Renderer-visible id-only session evidence.
136
+ */
137
+ session: TransferSessionStarted, } | { "status": "aborted",
138
+ /**
139
+ * Typed rejection.
140
+ */
141
+ abort: TransferAbort, };
142
+
143
+ export type TransferLeaseResponse = { "status": "published",
144
+ /**
145
+ * Renderer-visible replacement evidence.
146
+ */
147
+ lease: TransferLeaseReceipt, } | { "status": "aborted",
148
+ /**
149
+ * Typed rejection.
150
+ */
151
+ abort: TransferAbort, };
152
+
153
+ export type TransferCancelResponse = { "status": "cancelled",
154
+ /**
155
+ * Idempotent cancellation evidence.
156
+ */
157
+ cancellation: TransferCancelReceipt, } | { "status": "aborted",
158
+ /**
159
+ * Typed rejection.
160
+ */
161
+ abort: TransferAbort, };
162
+
163
+ export type PanelTransferResponse = { "status": "committed",
164
+ /**
165
+ * Current layout snapshot and target evidence.
166
+ */
167
+ completion: PanelTransferCompletion, } | { "status": "aborted",
168
+ /**
169
+ * Typed rejection and consumption evidence.
170
+ */
171
+ abort: TransferAbort, };
@@ -0,0 +1,45 @@
1
+ // @generated by `effigy generate:transfer`; do not edit.
2
+ // Allowed field names per tagged-union variant, from the Rust enums.
3
+ // Keyed by type, then by discriminant. The discriminant itself is in
4
+ // each list, because `exact()` compares every key.
5
+
6
+ export const TRANSFER_VARIANT_FIELDS: Record<string, Record<string, readonly string[]>> = {
7
+ "TransferTargetBinding": {
8
+ "panel_region": ["kind", "host_binding_id", "document_id", "revision", "surface_id", "region_id"],
9
+ "surface_window": ["kind", "host_binding_id", "document_id", "revision"],
10
+ },
11
+ "TransferCommitSelector": {
12
+ "explicit_zone": ["kind", "drop_zone_id"],
13
+ "screen_point": ["kind", "point"],
14
+ },
15
+ "TransferAbortSource": {
16
+ "transfer": ["domain", "code"],
17
+ "panel": ["domain", "code"],
18
+ },
19
+ "TransferSessionResponse": {
20
+ "started": ["status", "session"],
21
+ "aborted": ["status", "abort"],
22
+ },
23
+ "TransferLeaseResponse": {
24
+ "published": ["status", "lease"],
25
+ "aborted": ["status", "abort"],
26
+ },
27
+ "TransferCancelResponse": {
28
+ "cancelled": ["status", "cancellation"],
29
+ "aborted": ["status", "abort"],
30
+ },
31
+ "PanelTransferResponse": {
32
+ "committed": ["status", "completion"],
33
+ "aborted": ["status", "abort"],
34
+ },
35
+ };
36
+
37
+ export const TRANSFER_VARIANT_FIELDS_DISCRIMINANTS: Record<string, string> = {
38
+ "TransferTargetBinding": "kind",
39
+ "TransferCommitSelector": "kind",
40
+ "TransferAbortSource": "domain",
41
+ "TransferSessionResponse": "status",
42
+ "TransferLeaseResponse": "status",
43
+ "TransferCancelResponse": "status",
44
+ "PanelTransferResponse": "status",
45
+ };
@@ -0,0 +1,11 @@
1
+ export * from "./generated/protocol.ts";
2
+ // The generated field map is public API. A consumer that mirrors these
3
+ // types structurally -- Poodle does, because it may not depend on Longhorn --
4
+ // has no compile-time link to them, so a field added here is silent on their
5
+ // side. Whoever sees both can assert their shape against this map and fail
6
+ // when it drifts.
7
+ export * from "./generated/fields.ts";
8
+ export * from "./validation.ts";
9
+ export * from "./client.ts";
10
+ export * from "./connection.ts";
11
+ export * from "./payload.ts";
@@ -0,0 +1,71 @@
1
+ import {
2
+ TRANSFER_PROTOCOL_VERSION,
3
+ type TransferPayload,
4
+ } from "./generated/protocol.ts";
5
+
6
+ export const LONGHORN_TRANSFER_MIME_TYPE =
7
+ "application/vnd.longhorn.transfer+json";
8
+
9
+ export class InvalidTransferPayloadError extends TypeError {
10
+ constructor(message: string) {
11
+ super(message);
12
+ this.name = "InvalidTransferPayloadError";
13
+ }
14
+ }
15
+
16
+ export function serializeTransferPayload(payload: TransferPayload): string {
17
+ assertTransferPayload(payload);
18
+ return JSON.stringify({
19
+ protocol_version: payload.protocol_version,
20
+ session_id: payload.session_id,
21
+ });
22
+ }
23
+
24
+ export function parseTransferPayload(value: string): TransferPayload {
25
+ let parsed: unknown;
26
+ try {
27
+ parsed = JSON.parse(value);
28
+ } catch {
29
+ throw new InvalidTransferPayloadError("transfer payload is not valid JSON");
30
+ }
31
+ assertTransferPayload(parsed);
32
+ return parsed;
33
+ }
34
+
35
+ export function assertTransferPayload(
36
+ value: unknown,
37
+ ): asserts value is TransferPayload {
38
+ if (
39
+ typeof value !== "object" ||
40
+ value === null ||
41
+ Array.isArray(value)
42
+ ) {
43
+ throw new InvalidTransferPayloadError(
44
+ "transfer payload must be an object",
45
+ );
46
+ }
47
+ const record = value as Record<string, unknown>;
48
+ const keys = Object.keys(record).sort();
49
+ if (
50
+ keys.length !== 2 ||
51
+ keys[0] !== "protocol_version" ||
52
+ keys[1] !== "session_id"
53
+ ) {
54
+ throw new InvalidTransferPayloadError(
55
+ "transfer payload must contain only protocol_version and session_id",
56
+ );
57
+ }
58
+ if (record.protocol_version !== TRANSFER_PROTOCOL_VERSION) {
59
+ throw new InvalidTransferPayloadError(
60
+ "transfer payload protocol version is unsupported",
61
+ );
62
+ }
63
+ if (
64
+ typeof record.session_id !== "string" ||
65
+ !/^[0-9a-f]{32}$/.test(record.session_id)
66
+ ) {
67
+ throw new InvalidTransferPayloadError(
68
+ "transfer session id must be 32 lowercase hexadecimal characters",
69
+ );
70
+ }
71
+ }