@open-mercato/cezar 0.20.0-pr1900.5133 → 0.20.0-pr1900.5151.2

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 (159) hide show
  1. package/dist/contract/index.js +58 -3
  2. package/dist/contract/phones.d.ts +115 -1
  3. package/dist/relay/account.d.ts +91 -0
  4. package/dist/relay/account.js +195 -0
  5. package/dist/relay/account.js.map +1 -0
  6. package/dist/relay/connection.d.ts +16 -0
  7. package/dist/relay/connection.js +64 -5
  8. package/dist/relay/connection.js.map +1 -1
  9. package/dist/relay/identity.d.ts +2 -0
  10. package/dist/relay/identity.js +4 -1
  11. package/dist/relay/identity.js.map +1 -1
  12. package/dist/relay/pairing.js +8 -2
  13. package/dist/relay/pairing.js.map +1 -1
  14. package/dist/relay/service.d.ts +40 -1
  15. package/dist/relay/service.js +250 -0
  16. package/dist/relay/service.js.map +1 -1
  17. package/dist/relay/socket.d.ts +2 -1
  18. package/dist/relay/socket.js +2 -2
  19. package/dist/relay/socket.js.map +1 -1
  20. package/dist/server/agent-setup-routes.d.ts +14 -14
  21. package/dist/server/dashboard.d.ts +54 -54
  22. package/dist/server/server.d.ts +3288 -3109
  23. package/dist/server/server.js +55 -3
  24. package/dist/server/server.js.map +1 -1
  25. package/dist/server/worktree-lifecycle.d.ts +90 -90
  26. package/package.json +3 -3
  27. package/web/dist/assets/{active-forge-CzSAqPFz.js → active-forge-UZ7E8-sS.js} +1 -1
  28. package/web/dist/assets/{agent-task-pickers-Ir-CZbG9.js → agent-task-pickers-B1p_ATZu.js} +1 -1
  29. package/web/dist/assets/{alert-dialog-CvVExB7x.js → alert-dialog-cEIxhuLt.js} +1 -1
  30. package/web/dist/assets/arrow-down-C7mu7iqM.js +1 -0
  31. package/web/dist/assets/arrow-left-4asvuLDD.js +1 -0
  32. package/web/dist/assets/arrow-up-BKt4OZPJ.js +1 -0
  33. package/web/dist/assets/{ask-answer-Cp0yH3Ln.js → ask-answer-7cw5Fa92.js} +1 -1
  34. package/web/dist/assets/{ask-card-DO_JhbbT.js → ask-card-D2IGyjPx.js} +1 -1
  35. package/web/dist/assets/{assets-view-pily90tM.js → assets-view-CuG0foO7.js} +1 -1
  36. package/web/dist/assets/{automation-format-DEPMorEr.js → automation-format-Czpzs0wz.js} +1 -1
  37. package/web/dist/assets/automations-route-Di5uXdef.js +1 -0
  38. package/web/dist/assets/{bot-DhfaX82K.js → bot-5lrR3eCX.js} +1 -1
  39. package/web/dist/assets/{button-CUeDwj5q.js → button-SP0mEuvT.js} +1 -1
  40. package/web/dist/assets/{centered-state-OgRsqTqY.js → centered-state-DeLonsBN.js} +1 -1
  41. package/web/dist/assets/check-81ea1Rpj.js +1 -0
  42. package/web/dist/assets/chevron-left-Gyvn1hdz.js +1 -0
  43. package/web/dist/assets/chevron-right-CIk6dDiP.js +1 -0
  44. package/web/dist/assets/{circle-alert-Bbw6DSml.js → circle-alert-D182oid6.js} +1 -1
  45. package/web/dist/assets/circle-check-DCi-kdt1.js +1 -0
  46. package/web/dist/assets/{circle-question-mark-DSH9GfrM.js → circle-question-mark-_lMyv3TR.js} +1 -1
  47. package/web/dist/assets/{collapsible-BeLPbAWo.js → collapsible-Cc5woWmg.js} +1 -1
  48. package/web/dist/assets/{command-DfBFNlQs.js → command-3LCWnZYm.js} +1 -1
  49. package/web/dist/assets/{commit-list-aOyHa6fW.js → commit-list-DQQf1Z6m.js} +1 -1
  50. package/web/dist/assets/{compare-variants-DEW-HJz7.js → compare-variants-pXfwQQQe.js} +1 -1
  51. package/web/dist/assets/{composer-DmXlHB97.js → composer-DhC5Qa97.js} +1 -1
  52. package/web/dist/assets/{composer-attachments-D5o_Quf4.js → composer-attachments-D66zFSy4.js} +2 -2
  53. package/web/dist/assets/{dashboard-9l_mczGu.js → dashboard-CKDHvWeV.js} +1 -1
  54. package/web/dist/assets/{diff-ktSMmtHf.js → diff-CBIDByNI.js} +2 -2
  55. package/web/dist/assets/{diff-stat-BZOrYZP5.js → diff-stat-BBvc8gwG.js} +1 -1
  56. package/web/dist/assets/{diff-view-amAuQZDG.js → diff-view-BPdLZ1NS.js} +1 -1
  57. package/web/dist/assets/{directional-usage-BXia49hZ.js → directional-usage-CI_Skpd6.js} +1 -1
  58. package/web/dist/assets/{dist-CpS2SIfN.js → dist-CktfOfwF.js} +1 -1
  59. package/web/dist/assets/{download-mQv2n7zn.js → download-G5Guc-Ro.js} +1 -1
  60. package/web/dist/assets/{dropdown-menu-DyjvOlHa.js → dropdown-menu-yUNXWbJt.js} +1 -1
  61. package/web/dist/assets/{external-link-wCVn7D4m.js → external-link-C4aG3no2.js} +1 -1
  62. package/web/dist/assets/{file-BA6UNbl0.js → file-DIKC0krB.js} +1 -1
  63. package/web/dist/assets/{file-preview-YjOcMody.js → file-preview-DZkoDUta.js} +1 -1
  64. package/web/dist/assets/{file-tree-BNmrVzk7.js → file-tree-ClXIwDMF.js} +1 -1
  65. package/web/dist/assets/{folder-BTOJgkPh.js → folder-D0J-jjhv.js} +1 -1
  66. package/web/dist/assets/{follow-up-engine-B9psktce.js → follow-up-engine-DfzLDEG0.js} +1 -1
  67. package/web/dist/assets/{git-pull-request-CcI8lB9x.js → git-pull-request-C_Kx4Pgy.js} +1 -1
  68. package/web/dist/assets/{git-pull-request-draft-BAMgkdm0.js → git-pull-request-draft-BCqX5DPP.js} +1 -1
  69. package/web/dist/assets/{git-tab-loading-BthLhlCZ.js → git-tab-loading-D47EHhCs.js} +1 -1
  70. package/web/dist/assets/{github-3Xm4Yy-Q.js → github-UDF07so2.js} +1 -1
  71. package/web/dist/assets/{host-usage-C45dulR5.js → host-usage-B5f4EYaY.js} +1 -1
  72. package/web/dist/assets/{icon-tooltip-DijsoNKK.js → icon-tooltip-ByatOjay.js} +1 -1
  73. package/web/dist/assets/{impact-control-CJDuv6AP.js → impact-control-Bkn0lrrX.js} +1 -1
  74. package/web/dist/assets/{impact-model-C7zHdMQz.js → impact-model-I4Dag7ef.js} +1 -1
  75. package/web/dist/assets/index-D-Kowl8R.js +33 -0
  76. package/web/dist/assets/{input-DS4bBFdA.js → input-CD3gvibI.js} +1 -1
  77. package/web/dist/assets/{layers-rli17pLA.js → layers-Y5-bK8qN.js} +1 -1
  78. package/web/dist/assets/{layout-cards-BEio_78e.js → layout-cards-o62o_NfK.js} +1 -1
  79. package/web/dist/assets/{layout-dashboard-BCU5wWbk.js → layout-dashboard-cQFK879o.js} +1 -1
  80. package/web/dist/assets/{layout-grid-BQNRl534.js → layout-grid-Ca0A9pGO.js} +1 -1
  81. package/web/dist/assets/loader-circle-BIF71adx.js +1 -0
  82. package/web/dist/assets/{loading-state-DQ892YKP.js → loading-state-Cud_uePU.js} +1 -1
  83. package/web/dist/assets/{manager-chat-odisUe8_.js → manager-chat-C0Tb2-7V.js} +3 -3
  84. package/web/dist/assets/{manager-index-BR1H09on.js → manager-index-D5bCwta-.js} +1 -1
  85. package/web/dist/assets/{manager-new-JeM8vcwp.js → manager-new-DRfi4g_D.js} +1 -1
  86. package/web/dist/assets/{managers-5e7JBCZX.js → managers-BUDay_M1.js} +1 -1
  87. package/web/dist/assets/{markdown-B_FKPYjR.js → markdown-Bb8UHbzM.js} +1 -1
  88. package/web/dist/assets/{markdown-BcHSuwit.js → markdown-r0HsgA4D.js} +1 -1
  89. package/web/dist/assets/{mascot-picker-BmIfMXZN.js → mascot-picker-y4_3CvDf.js} +1 -1
  90. package/web/dist/assets/{message-square-DYKiwfC4.js → message-square-BTQXqadJ.js} +1 -1
  91. package/web/dist/assets/new-task-form-Q8ghIJT0.js +2 -0
  92. package/web/dist/assets/{pencil-743qDcj1.js → pencil-DlSNAlCP.js} +1 -1
  93. package/web/dist/assets/{picker-pill-CDQXEJCb.js → picker-pill-DQNe5a76.js} +1 -1
  94. package/web/dist/assets/play-90YcYS6F.js +1 -0
  95. package/web/dist/assets/plus-CV0pwQ7B.js +1 -0
  96. package/web/dist/assets/{project-router-9U9UZZJU.js → project-router-CuZws18J.js} +1 -1
  97. package/web/dist/assets/queries-DmaB-XFK.js +1 -0
  98. package/web/dist/assets/{reasoning-effort-pill-DPJLFaPh.js → reasoning-effort-pill-Buwn9_BH.js} +1 -1
  99. package/web/dist/assets/{reference-chip-MXJd8SzF.js → reference-chip-DZzdTuXh.js} +1 -1
  100. package/web/dist/assets/{reference-conflict-action-BTLtpDo8.js → reference-conflict-action-gDOxxbiX.js} +1 -1
  101. package/web/dist/assets/{refresh-cw-DKMUTL8o.js → refresh-cw-zyOSzTVt.js} +1 -1
  102. package/web/dist/assets/{repo-git--uh_iiCE.js → repo-git-sXnog6xj.js} +1 -1
  103. package/web/dist/assets/{run-actions-D1FkAr1S.js → run-actions-Bgd_tZiu.js} +1 -1
  104. package/web/dist/assets/{run-diff-DRBT0TTQ.js → run-diff-D9ZBL-YN.js} +1 -1
  105. package/web/dist/assets/{save-DDov_HV-.js → save-C-rPGzZB.js} +1 -1
  106. package/web/dist/assets/{scroll-within-BxWFx9_t.js → scroll-within-C3qrWR84.js} +1 -1
  107. package/web/dist/assets/search-CnXzl19y.js +1 -0
  108. package/web/dist/assets/{search-x-VMCa-GjC.js → search-x-DLpr22Yi.js} +1 -1
  109. package/web/dist/assets/{settings-2-Dw2WNiG0.js → settings-2-DPiBY-Gy.js} +1 -1
  110. package/web/dist/assets/{sheet-CeauwoGn.js → sheet-CBH2WuoK.js} +1 -1
  111. package/web/dist/assets/{skills-B-Ylbppg.js → skills-BeET1HRw.js} +1 -1
  112. package/web/dist/assets/square-Bz0rSJKs.js +1 -0
  113. package/web/dist/assets/{status-dot-DU2tHvPT.js → status-dot-BPg_gvro.js} +1 -1
  114. package/web/dist/assets/{tabs-DFnTlzwx.js → tabs-Cipv4wx6.js} +1 -1
  115. package/web/dist/assets/{tag-DjDAVYvm.js → tag-Ba-HHVTn.js} +1 -1
  116. package/web/dist/assets/{task-commits-y5-O6WMh.js → task-commits-Bh0QzreG.js} +1 -1
  117. package/web/dist/assets/{task-graph-h5QlVMDE.js → task-graph-2-FRVqu4.js} +1 -1
  118. package/web/dist/assets/{task-notes-BVPo8HdE.js → task-notes-Bj7P2aZg.js} +1 -1
  119. package/web/dist/assets/{task-workspace-DTkTxrMK.js → task-workspace-DoQmtlBc.js} +5 -5
  120. package/web/dist/assets/terminal-CxQWNf9P.js +1 -0
  121. package/web/dist/assets/{terminal-drawer-DfpBdxfb.js → terminal-drawer-BLdzM_pY.js} +1 -1
  122. package/web/dist/assets/{terminal-pane-Dtjk3Hd0.js → terminal-pane-C2kKRlza.js} +1 -1
  123. package/web/dist/assets/{textarea-Csi959Ww.js → textarea-DJWjk-jj.js} +1 -1
  124. package/web/dist/assets/{toaster-CNxUYLeU.js → toaster-CAuDu6Hf.js} +1 -1
  125. package/web/dist/assets/{tooltip-B-gyUoDn.js → tooltip-BMyjxlwU.js} +1 -1
  126. package/web/dist/assets/{tracker-BICzzlIc.js → tracker-DUzslT6O.js} +1 -1
  127. package/web/dist/assets/{triangle-alert-ChvXl64f.js → triangle-alert-CM5F8wKV.js} +1 -1
  128. package/web/dist/assets/{upload-Be1xZgv-.js → upload-AxtWB0KT.js} +1 -1
  129. package/web/dist/assets/{use-now-BZYBTo-J.js → use-now-4FxFKeGB.js} +1 -1
  130. package/web/dist/assets/{use-submit-shortcut-Db6uHey3.js → use-submit-shortcut-BbPbFGX0.js} +1 -1
  131. package/web/dist/assets/user-round-DKIrjN__.js +1 -0
  132. package/web/dist/assets/utils-CWRklB5c.js +60 -0
  133. package/web/dist/assets/{workflow-D7edLPEx.js → workflow-B2qDYepx.js} +1 -1
  134. package/web/dist/assets/{workflow-graph-CTAfpHVP.js → workflow-graph-DzbKTVj5.js} +2 -2
  135. package/web/dist/assets/{worktree-lifecycle-B9PLGqmE.js → worktree-lifecycle-4cKn_ZGJ.js} +1 -1
  136. package/web/dist/assets/{worktree-lifecycle-operation-DfgqisqQ.js → worktree-lifecycle-operation-JuZIwyfH.js} +1 -1
  137. package/web/dist/assets/x-1zMuaIyY.js +1 -0
  138. package/web/dist/assets/{zoomable-image-BELB7rHR.js → zoomable-image-Db-U585p.js} +1 -1
  139. package/web/dist/index.html +71 -71
  140. package/web/dist/assets/arrow-down-Bun_cN1o.js +0 -1
  141. package/web/dist/assets/arrow-left-CtrOZUjt.js +0 -1
  142. package/web/dist/assets/arrow-up-D12qlZXz.js +0 -1
  143. package/web/dist/assets/automations-route-B4-9tRgb.js +0 -1
  144. package/web/dist/assets/check-7V5npz9m.js +0 -1
  145. package/web/dist/assets/chevron-left-CidsmNmH.js +0 -1
  146. package/web/dist/assets/chevron-right-Chkn8nIF.js +0 -1
  147. package/web/dist/assets/circle-check-BPCj_9Rk.js +0 -1
  148. package/web/dist/assets/index-BdUwQkiA.js +0 -33
  149. package/web/dist/assets/loader-circle-BA2wUtwP.js +0 -1
  150. package/web/dist/assets/new-task-form-zIl7FGwy.js +0 -2
  151. package/web/dist/assets/play-DqIVLsM-.js +0 -1
  152. package/web/dist/assets/plus-DC4R7IJX.js +0 -1
  153. package/web/dist/assets/queries-CClywfEj.js +0 -1
  154. package/web/dist/assets/search-CRhK6vrc.js +0 -1
  155. package/web/dist/assets/square-wCfA-AMW.js +0 -1
  156. package/web/dist/assets/terminal-DeEvkG4Y.js +0 -1
  157. package/web/dist/assets/user-round-CabgCVt_.js +0 -1
  158. package/web/dist/assets/utils-CSP2o_GU.js +0 -60
  159. package/web/dist/assets/x-ChVxX0QP.js +0 -1
@@ -5814,6 +5814,11 @@ import { z as z45 } from "zod";
5814
5814
  var phonePlatformSchema = z45.enum(["android", "ios"]);
5815
5815
  var phoneDeviceParamSchema = z45.object({ deviceId: z45.string().regex(/^[A-Za-z0-9_-]{22}$/) });
5816
5816
  var phonePairingParamSchema = z45.object({ id: z45.uuid() });
5817
+ var RELAY_TERMS = {
5818
+ version: "2026-11-13",
5819
+ termsUrl: "https://openmercatocloud.com/terms",
5820
+ privacyUrl: "https://openmercatocloud.com/privacy"
5821
+ };
5817
5822
  var relayStatusSchema = z45.enum([
5818
5823
  "off",
5819
5824
  "connecting",
@@ -5825,7 +5830,9 @@ var relayStatusSchema = z45.enum([
5825
5830
  "disabled",
5826
5831
  "update-required",
5827
5832
  "locked",
5828
- "error"
5833
+ "error",
5834
+ "email-unconfirmed",
5835
+ "account-required"
5829
5836
  ]);
5830
5837
  var phonePairingStatusSchema = z45.enum([
5831
5838
  "waiting",
@@ -5846,7 +5853,8 @@ var phonePairingFailureSchema = z45.enum([
5846
5853
  "contested",
5847
5854
  "bad-payload",
5848
5855
  "tunnel-unsupported",
5849
- "phone-left"
5856
+ "phone-left",
5857
+ "terms-required"
5850
5858
  ]);
5851
5859
  var phonePairingSchema = z45.object({
5852
5860
  id: z45.string(),
@@ -5885,13 +5893,51 @@ var setPhonePushGrantInputSchema = z45.object({
5885
5893
  expiresAt: z45.number().int().positive()
5886
5894
  }).strict();
5887
5895
  var phoneSignalEventSchema = z45.object({ managerId: z45.string().optional() });
5896
+ var relayAccountLocalSchema = z45.object({
5897
+ attached: z45.boolean(),
5898
+ email: z45.string().optional(),
5899
+ termsVersion: z45.string().optional(),
5900
+ prompt: z45.literal(true).optional()
5901
+ });
5888
5902
  var phonesResponseSchema = z45.object({
5889
5903
  relayOrigin: z45.string(),
5890
5904
  relay: z45.object({ status: relayStatusSchema, detail: z45.string().optional() }),
5891
5905
  phones: z45.array(phoneSchema),
5892
5906
  pairing: phonePairingSchema.nullable(),
5893
5907
  /** Grants a `too-many-grants` answer left alive, kept for R5 and shown as a warning. */
5894
- undeniedGrants: z45.number().optional()
5908
+ undeniedGrants: z45.number().optional(),
5909
+ /** What this computer knows of its relay account without asking the relay (§ 18). */
5910
+ account: relayAccountLocalSchema
5911
+ });
5912
+ var relayAccountStateSchema = z45.enum(["confirmed", "pending", "blocked"]);
5913
+ var relayAccountStatusSchema = z45.object({
5914
+ state: relayAccountStateSchema,
5915
+ email: z45.string().nullable(),
5916
+ termsVersion: z45.string().nullable(),
5917
+ acceptedAt: z45.number().nullable(),
5918
+ confirmedAt: z45.number().nullable(),
5919
+ graceEndsAt: z45.number().nullable(),
5920
+ secondsLeft: z45.number().nullable()
5921
+ });
5922
+ var relayAccountResponseSchema = z45.object({
5923
+ local: relayAccountLocalSchema,
5924
+ status: relayAccountStatusSchema.nullable(),
5925
+ problem: z45.enum(["unreachable", "unavailable", "unsupported", "no-keys"]).optional(),
5926
+ /** `POST /workspace/phones/account`: whether a code went out, and when one may be sent again. */
5927
+ codeSent: z45.boolean().optional(),
5928
+ retryAfter: z45.number().optional()
5929
+ });
5930
+ var setRelayAccountInputSchema = z45.object({
5931
+ email: z45.string().trim().min(3).max(254).regex(/^[^@\s]+@[^@\s]+$/),
5932
+ termsVersion: z45.string().regex(/^[A-Za-z0-9._-]{1,32}$/),
5933
+ accepted: z45.literal(true)
5934
+ }).strict();
5935
+ var confirmRelayAccountInputSchema = z45.object({ code: z45.string().trim().regex(/^[0-9]{6}$/) }).strict();
5936
+ var relayAccountResendResponseSchema = z45.object({ expiresAt: z45.number() });
5937
+ var relayAccountErrorSchema = z45.object({
5938
+ error: z45.string(),
5939
+ code: z45.string().optional(),
5940
+ retryAfter: z45.number().optional()
5895
5941
  });
5896
5942
  var startPhonePairingResponseSchema = z45.object({
5897
5943
  id: z45.string(),
@@ -5957,6 +6003,7 @@ export {
5957
6003
  PROMPT_TEMPLATE_TEXT_MAX,
5958
6004
  REASONING_EFFORT_RUNNERS,
5959
6005
  REFERENCE_STATUS_MAX,
6006
+ RELAY_TERMS,
5960
6007
  RUNNER_IDS,
5961
6008
  RUN_HISTORY_PAGE_ITEMS,
5962
6009
  SCHEDULE_HOURS_OPTIONS,
@@ -6089,6 +6136,7 @@ export {
6089
6136
  configBundlePreviewSchema,
6090
6137
  configBundleSchema,
6091
6138
  configResponseSchema,
6139
+ confirmRelayAccountInputSchema,
6092
6140
  continueInputSchema,
6093
6141
  continueResponseSchema,
6094
6142
  createAgentProfileInputSchema,
@@ -6396,6 +6444,12 @@ export {
6396
6444
  referenceStatusesByProjectSchema,
6397
6445
  registerProjectInputSchema,
6398
6446
  registerProjectResponseSchema,
6447
+ relayAccountErrorSchema,
6448
+ relayAccountLocalSchema,
6449
+ relayAccountResendResponseSchema,
6450
+ relayAccountResponseSchema,
6451
+ relayAccountStateSchema,
6452
+ relayAccountStatusSchema,
6399
6453
  relayStatusSchema,
6400
6454
  removeAgentProfileResponseSchema,
6401
6455
  removeProjectResponseSchema,
@@ -6482,6 +6536,7 @@ export {
6482
6536
  setConfigInputSchema,
6483
6537
  setConfigResponseSchema,
6484
6538
  setPhonePushGrantInputSchema,
6539
+ setRelayAccountInputSchema,
6485
6540
  setRunDraftInputSchema,
6486
6541
  setTelemetryConsentInputSchema,
6487
6542
  setWorkspaceConfigInputSchema,
@@ -11,11 +11,25 @@ export declare const phoneDeviceParamSchema: z.ZodObject<{
11
11
  export declare const phonePairingParamSchema: z.ZodObject<{
12
12
  id: z.ZodUUID;
13
13
  }, z.core.$strip>;
14
- /** `off` means no socket, which is the normal state with no phone paired. */
14
+ /**
15
+ * The terms a relay account accepts (RELAY_PROTOCOL.md § 18). The one place their URLs and version
16
+ * live: Settings links them and `POST /v1/accounts` sends `version`.
17
+ */
18
+ export declare const RELAY_TERMS: {
19
+ readonly version: '2026-11-13';
20
+ readonly termsUrl: 'https://openmercatocloud.com/terms';
21
+ readonly privacyUrl: 'https://openmercatocloud.com/privacy';
22
+ };
23
+ /**
24
+ * `off` means no socket, which is the normal state with no phone paired. `email-unconfirmed` and
25
+ * `account-required` are the relay's 4451 once the account grace is over (§ 18).
26
+ */
15
27
  export declare const relayStatusSchema: z.ZodEnum<{
28
+ "account-required": "account-required";
16
29
  connected: "connected";
17
30
  connecting: "connecting";
18
31
  disabled: "disabled";
32
+ "email-unconfirmed": "email-unconfirmed";
19
33
  error: "error";
20
34
  locked: "locked";
21
35
  off: "off";
@@ -45,6 +59,7 @@ export declare const phonePairingFailureSchema: z.ZodEnum<{
45
59
  "device-limit": "device-limit";
46
60
  "phone-left": "phone-left";
47
61
  "relay-error": "relay-error";
62
+ "terms-required": "terms-required";
48
63
  timeout: "timeout";
49
64
  "tunnel-unsupported": "tunnel-unsupported";
50
65
  }>;
@@ -83,6 +98,7 @@ export declare const phonePairingSchema: z.ZodObject<{
83
98
  "device-limit": "device-limit";
84
99
  "phone-left": "phone-left";
85
100
  "relay-error": "relay-error";
101
+ "terms-required": "terms-required";
86
102
  timeout: "timeout";
87
103
  "tunnel-unsupported": "tunnel-unsupported";
88
104
  }>>;
@@ -124,13 +140,26 @@ export declare const phoneSignalEventSchema: z.ZodObject<{
124
140
  }, z.core.$strip>;
125
141
  export type PhoneSignalEvent = z.infer<typeof phoneSignalEventSchema>;
126
142
  export type SetPhonePushGrantInput = z.infer<typeof setPhonePushGrantInputSchema>;
143
+ /**
144
+ * Local only, never a network call. `attached`: a token is held. `prompt`: phones paired before
145
+ * accounts existed and the user has not been asked yet, so the cockpit asks once.
146
+ */
147
+ export declare const relayAccountLocalSchema: z.ZodObject<{
148
+ attached: z.ZodBoolean;
149
+ email: z.ZodOptional<z.ZodString>;
150
+ termsVersion: z.ZodOptional<z.ZodString>;
151
+ prompt: z.ZodOptional<z.ZodLiteral<true>>;
152
+ }, z.core.$strip>;
153
+ export type RelayAccountLocal = z.infer<typeof relayAccountLocalSchema>;
127
154
  export declare const phonesResponseSchema: z.ZodObject<{
128
155
  relayOrigin: z.ZodString;
129
156
  relay: z.ZodObject<{
130
157
  status: z.ZodEnum<{
158
+ "account-required": "account-required";
131
159
  connected: "connected";
132
160
  connecting: "connecting";
133
161
  disabled: "disabled";
162
+ "email-unconfirmed": "email-unconfirmed";
134
163
  error: "error";
135
164
  locked: "locked";
136
165
  off: "off";
@@ -187,13 +216,97 @@ export declare const phonesResponseSchema: z.ZodObject<{
187
216
  "device-limit": "device-limit";
188
217
  "phone-left": "phone-left";
189
218
  "relay-error": "relay-error";
219
+ "terms-required": "terms-required";
190
220
  timeout: "timeout";
191
221
  "tunnel-unsupported": "tunnel-unsupported";
192
222
  }>>;
193
223
  }, z.core.$strip>>;
194
224
  undeniedGrants: z.ZodOptional<z.ZodNumber>;
225
+ account: z.ZodObject<{
226
+ attached: z.ZodBoolean;
227
+ email: z.ZodOptional<z.ZodString>;
228
+ termsVersion: z.ZodOptional<z.ZodString>;
229
+ prompt: z.ZodOptional<z.ZodLiteral<true>>;
230
+ }, z.core.$strip>;
195
231
  }, z.core.$strip>;
196
232
  export type PhonesResponse = z.infer<typeof phonesResponseSchema>;
233
+ export declare const relayAccountStateSchema: z.ZodEnum<{
234
+ blocked: "blocked";
235
+ confirmed: "confirmed";
236
+ pending: "pending";
237
+ }>;
238
+ export type RelayAccountState = z.infer<typeof relayAccountStateSchema>;
239
+ /** The relay's status object, as it sent it. Times are Unix seconds. */
240
+ export declare const relayAccountStatusSchema: z.ZodObject<{
241
+ state: z.ZodEnum<{
242
+ blocked: "blocked";
243
+ confirmed: "confirmed";
244
+ pending: "pending";
245
+ }>;
246
+ email: z.ZodNullable<z.ZodString>;
247
+ termsVersion: z.ZodNullable<z.ZodString>;
248
+ acceptedAt: z.ZodNullable<z.ZodNumber>;
249
+ confirmedAt: z.ZodNullable<z.ZodNumber>;
250
+ graceEndsAt: z.ZodNullable<z.ZodNumber>;
251
+ secondsLeft: z.ZodNullable<z.ZodNumber>;
252
+ }, z.core.$strip>;
253
+ export type RelayAccountStatus = z.infer<typeof relayAccountStatusSchema>;
254
+ /**
255
+ * `GET /workspace/phones/account` and the account actions. `status` is null when the relay could not
256
+ * be asked; `problem` then says why. `unsupported`: the relay has no accounts (a custom relay).
257
+ */
258
+ export declare const relayAccountResponseSchema: z.ZodObject<{
259
+ local: z.ZodObject<{
260
+ attached: z.ZodBoolean;
261
+ email: z.ZodOptional<z.ZodString>;
262
+ termsVersion: z.ZodOptional<z.ZodString>;
263
+ prompt: z.ZodOptional<z.ZodLiteral<true>>;
264
+ }, z.core.$strip>;
265
+ status: z.ZodNullable<z.ZodObject<{
266
+ state: z.ZodEnum<{
267
+ blocked: "blocked";
268
+ confirmed: "confirmed";
269
+ pending: "pending";
270
+ }>;
271
+ email: z.ZodNullable<z.ZodString>;
272
+ termsVersion: z.ZodNullable<z.ZodString>;
273
+ acceptedAt: z.ZodNullable<z.ZodNumber>;
274
+ confirmedAt: z.ZodNullable<z.ZodNumber>;
275
+ graceEndsAt: z.ZodNullable<z.ZodNumber>;
276
+ secondsLeft: z.ZodNullable<z.ZodNumber>;
277
+ }, z.core.$strip>>;
278
+ problem: z.ZodOptional<z.ZodEnum<{
279
+ "no-keys": "no-keys";
280
+ unavailable: "unavailable";
281
+ unreachable: "unreachable";
282
+ unsupported: "unsupported";
283
+ }>>;
284
+ codeSent: z.ZodOptional<z.ZodBoolean>;
285
+ retryAfter: z.ZodOptional<z.ZodNumber>;
286
+ }, z.core.$strip>;
287
+ export type RelayAccountResponse = z.infer<typeof relayAccountResponseSchema>;
288
+ export declare const setRelayAccountInputSchema: z.ZodObject<{
289
+ email: z.ZodString;
290
+ termsVersion: z.ZodString;
291
+ accepted: z.ZodLiteral<true>;
292
+ }, z.core.$strict>;
293
+ export type SetRelayAccountInput = z.infer<typeof setRelayAccountInputSchema>;
294
+ export declare const confirmRelayAccountInputSchema: z.ZodObject<{
295
+ code: z.ZodString;
296
+ }, z.core.$strict>;
297
+ export type ConfirmRelayAccountInput = z.infer<typeof confirmRelayAccountInputSchema>;
298
+ /** `resend`: when the new code expires, Unix seconds. */
299
+ export declare const relayAccountResendResponseSchema: z.ZodObject<{
300
+ expiresAt: z.ZodNumber;
301
+ }, z.core.$strip>;
302
+ export type RelayAccountResendResponse = z.infer<typeof relayAccountResendResponseSchema>;
303
+ /** Every refused account action: `code` is the relay's, so the screen can name the case. */
304
+ export declare const relayAccountErrorSchema: z.ZodObject<{
305
+ error: z.ZodString;
306
+ code: z.ZodOptional<z.ZodString>;
307
+ retryAfter: z.ZodOptional<z.ZodNumber>;
308
+ }, z.core.$strip>;
309
+ export type RelayAccountError = z.infer<typeof relayAccountErrorSchema>;
197
310
  /** Carries a credential, like the code below. Sent once, `no-store`, and never logged. */
198
311
  export declare const startPhonePairingResponseSchema: z.ZodObject<{
199
312
  id: z.ZodString;
@@ -251,6 +364,7 @@ export declare const phonePairingEventSchema: z.ZodObject<{
251
364
  "device-limit": "device-limit";
252
365
  "phone-left": "phone-left";
253
366
  "relay-error": "relay-error";
367
+ "terms-required": "terms-required";
254
368
  timeout: "timeout";
255
369
  "tunnel-unsupported": "tunnel-unsupported";
256
370
  }>>;
@@ -0,0 +1,91 @@
1
+ import { type RelayAccountStatus } from '../contract/index.js';
2
+ import { z } from 'zod';
3
+ import type { RelayIdentity } from './identity.ts';
4
+ export declare const ACCOUNT_PATHS: {
5
+ readonly start: '/v1/accounts';
6
+ readonly status: '/v1/accounts/status';
7
+ readonly resend: '/v1/accounts/resend';
8
+ readonly confirm: '/v1/accounts/confirm';
9
+ readonly devices: '/v1/accounts/devices';
10
+ readonly delete: '/v1/accounts/delete';
11
+ };
12
+ /** The header that carries the token on `GET /v1/cezar/{cezarId}`. */
13
+ export declare const ACCOUNT_HEADER = "X-Cezar-Relay-Account";
14
+ declare const fileSchema: z.ZodObject<{
15
+ origin: z.ZodCatch<z.ZodOptional<z.ZodString>>;
16
+ cezarId: z.ZodCatch<z.ZodOptional<z.ZodString>>;
17
+ email: z.ZodCatch<z.ZodOptional<z.ZodString>>;
18
+ termsVersion: z.ZodCatch<z.ZodOptional<z.ZodString>>;
19
+ sealed: z.ZodCatch<z.ZodOptional<z.ZodString>>;
20
+ prompted: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
21
+ }, z.core.$loose>;
22
+ type AccountFile = z.infer<typeof fileSchema>;
23
+ export declare class RelayAccountFile {
24
+ private readonly path;
25
+ private state;
26
+ constructor(directory: string);
27
+ read(): AccountFile;
28
+ write(patch: Partial<AccountFile>): void;
29
+ /** The token, if one was saved for this relay and these keys. A file from other keys is ignored. */
30
+ token(identity: RelayIdentity, origin: string): string | undefined;
31
+ saveToken(identity: RelayIdentity, origin: string, token: string, email: string, termsVersion: string): void;
32
+ /** `bad-token`, or another relay: what was attached here no longer is. The email stays as a hint. */
33
+ dropToken(): void;
34
+ }
35
+ export declare function seal(key: Buffer, text: string): string;
36
+ export declare function unseal(key: Buffer, sealed: string): string | null;
37
+ export type AccountPost = (url: string, init: {
38
+ headers: Record<string, string>;
39
+ body: Uint8Array;
40
+ }) => Promise<{
41
+ status: number;
42
+ json: unknown;
43
+ retryAfter?: number;
44
+ }>;
45
+ /** A refused account call. `code` is the relay's, or `unreachable` when nothing answered. */
46
+ export declare class RelayAccountCallError extends Error {
47
+ readonly status: number;
48
+ readonly code: string;
49
+ readonly retryAfter?: number | undefined;
50
+ readonly current?: string | undefined;
51
+ constructor(status: number, code: string, retryAfter?: number | undefined, current?: string | undefined);
52
+ }
53
+ declare const startAnswer: z.ZodObject<{
54
+ account: z.ZodString;
55
+ token: z.ZodString;
56
+ status: z.ZodObject<{
57
+ state: z.ZodEnum<{
58
+ blocked: "blocked";
59
+ confirmed: "confirmed";
60
+ pending: "pending";
61
+ }>;
62
+ email: z.ZodNullable<z.ZodString>;
63
+ termsVersion: z.ZodNullable<z.ZodString>;
64
+ acceptedAt: z.ZodNullable<z.ZodNumber>;
65
+ confirmedAt: z.ZodNullable<z.ZodNumber>;
66
+ graceEndsAt: z.ZodNullable<z.ZodNumber>;
67
+ secondsLeft: z.ZodNullable<z.ZodNumber>;
68
+ }, z.core.$strip>;
69
+ codeSent: z.ZodBoolean;
70
+ retryAfter: z.ZodOptional<z.ZodNumber>;
71
+ }, z.core.$strip>;
72
+ export declare class RelayAccountClient {
73
+ private readonly now;
74
+ private readonly post;
75
+ constructor(post?: AccountPost, now?: () => number);
76
+ private call;
77
+ private parse;
78
+ start(origin: string, identity: RelayIdentity, email: string, termsVersion: string): Promise<z.infer<typeof startAnswer>>;
79
+ status(origin: string, identity: RelayIdentity): Promise<{
80
+ account: string | null;
81
+ status: RelayAccountStatus;
82
+ }>;
83
+ resend(origin: string, identity: RelayIdentity, token: string): Promise<{
84
+ expiresAt: number;
85
+ }>;
86
+ /** Needs no proof: the code is the credential. */
87
+ confirm(origin: string, cezarId: string, code: string): Promise<RelayAccountStatus>;
88
+ devices(origin: string, identity: RelayIdentity, token: string, devices: string[]): Promise<void>;
89
+ delete(origin: string, identity: RelayIdentity, token: string): Promise<void>;
90
+ }
91
+ export {};
@@ -0,0 +1,195 @@
1
+ import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { relayAccountStatusSchema } from '../contract/index.js';
5
+ import { z } from 'zod';
6
+ import { atomicWriteJsonSync } from '../workspace/config.js';
7
+ import { b64u, postProof, proofHeaders } from './wire.js';
8
+ /**
9
+ * The relay account (RELAY_PROTOCOL.md § 18): who runs this cezar accepted the terms and named an
10
+ * email. The token is sealed with a key derived from the relay identity, which lives in the OS
11
+ * keychain, so `account.json` alone reveals the email and nothing that works.
12
+ */
13
+ const ACCOUNT_TIMEOUT_MS = 15_000;
14
+ const MAX_ANSWER_BYTES = 8_192;
15
+ export const ACCOUNT_PATHS = {
16
+ start: '/v1/accounts',
17
+ status: '/v1/accounts/status',
18
+ resend: '/v1/accounts/resend',
19
+ confirm: '/v1/accounts/confirm',
20
+ devices: '/v1/accounts/devices',
21
+ delete: '/v1/accounts/delete',
22
+ };
23
+ /** The header that carries the token on `GET /v1/cezar/{cezarId}`. */
24
+ export const ACCOUNT_HEADER = 'X-Cezar-Relay-Account';
25
+ const fileSchema = z.looseObject({
26
+ /** The relay the token came from: another relay never saw it. */
27
+ origin: z.string().max(300).optional().catch(undefined),
28
+ cezarId: z.string().max(64).optional().catch(undefined),
29
+ email: z.string().max(254).optional().catch(undefined),
30
+ termsVersion: z.string().max(32).optional().catch(undefined),
31
+ /** `iv ‖ ciphertext ‖ tag`, base64url, AES-256-GCM under `sealKey`. */
32
+ sealed: z.string().max(1024).optional().catch(undefined),
33
+ /** The one-time prompt for phones paired before accounts existed was shown. */
34
+ prompted: z.boolean().optional().catch(undefined),
35
+ });
36
+ export class RelayAccountFile {
37
+ path;
38
+ state;
39
+ constructor(directory) {
40
+ this.path = join(directory, 'account.json');
41
+ }
42
+ read() {
43
+ if (this.state)
44
+ return this.state;
45
+ let parsed = {};
46
+ try {
47
+ const result = fileSchema.safeParse(JSON.parse(readFileSync(this.path, 'utf8')));
48
+ if (result.success)
49
+ parsed = result.data;
50
+ }
51
+ catch {
52
+ // Missing or corrupt: no account. The user is asked again, and the relay keeps the truth.
53
+ }
54
+ this.state = parsed;
55
+ return parsed;
56
+ }
57
+ write(patch) {
58
+ const next = { ...this.read(), ...patch };
59
+ for (const key of Object.keys(next))
60
+ if (next[key] === undefined)
61
+ delete next[key];
62
+ atomicWriteJsonSync(this.path, { version: 1, ...next });
63
+ this.state = next;
64
+ }
65
+ /** The token, if one was saved for this relay and these keys. A file from other keys is ignored. */
66
+ token(identity, origin) {
67
+ const state = this.read();
68
+ if (!state.sealed || state.origin !== origin || state.cezarId !== identity.cezarId)
69
+ return undefined;
70
+ return unseal(identity.sealKey, state.sealed) ?? undefined;
71
+ }
72
+ saveToken(identity, origin, token, email, termsVersion) {
73
+ this.write({ origin, cezarId: identity.cezarId, email, termsVersion, sealed: seal(identity.sealKey, token), prompted: true });
74
+ }
75
+ /** `bad-token`, or another relay: what was attached here no longer is. The email stays as a hint. */
76
+ dropToken() {
77
+ this.write({ sealed: undefined, origin: undefined, cezarId: undefined });
78
+ }
79
+ }
80
+ export function seal(key, text) {
81
+ const iv = randomBytes(12);
82
+ const cipher = createCipheriv('aes-256-gcm', key, iv);
83
+ const body = Buffer.concat([cipher.update(text, 'utf8'), cipher.final()]);
84
+ return b64u(Buffer.concat([iv, body, cipher.getAuthTag()]));
85
+ }
86
+ export function unseal(key, sealed) {
87
+ try {
88
+ const bytes = Buffer.from(sealed, 'base64url');
89
+ if (bytes.length < 29)
90
+ return null;
91
+ const decipher = createDecipheriv('aes-256-gcm', key, bytes.subarray(0, 12));
92
+ decipher.setAuthTag(bytes.subarray(-16));
93
+ return Buffer.concat([decipher.update(bytes.subarray(12, -16)), decipher.final()]).toString('utf8');
94
+ }
95
+ catch {
96
+ return null;
97
+ }
98
+ }
99
+ const defaultPost = async (url, { headers, body }) => {
100
+ const response = await fetch(url, {
101
+ method: 'POST',
102
+ headers: { 'content-type': 'application/json', ...headers },
103
+ body,
104
+ signal: AbortSignal.timeout(ACCOUNT_TIMEOUT_MS),
105
+ });
106
+ const text = (await response.text()).slice(0, MAX_ANSWER_BYTES);
107
+ let json = null;
108
+ try {
109
+ json = text ? JSON.parse(text) : null;
110
+ }
111
+ catch {
112
+ // Not ours: the status alone decides.
113
+ }
114
+ const retryAfter = Number(response.headers.get('retry-after'));
115
+ return { status: response.status, json, ...(Number.isFinite(retryAfter) && retryAfter > 0 ? { retryAfter } : {}) };
116
+ };
117
+ /** A refused account call. `code` is the relay's, or `unreachable` when nothing answered. */
118
+ export class RelayAccountCallError extends Error {
119
+ status;
120
+ code;
121
+ retryAfter;
122
+ current;
123
+ constructor(status, code, retryAfter, current) {
124
+ super(code);
125
+ this.status = status;
126
+ this.code = code;
127
+ this.retryAfter = retryAfter;
128
+ this.current = current;
129
+ }
130
+ }
131
+ const startAnswer = z.object({
132
+ account: z.string(),
133
+ token: z.string().min(1).max(256),
134
+ status: relayAccountStatusSchema,
135
+ codeSent: z.boolean(),
136
+ retryAfter: z.number().optional(),
137
+ });
138
+ const statusAnswer = z.object({ account: z.string().nullable(), status: relayAccountStatusSchema });
139
+ const resendAnswer = z.object({ expiresAt: z.number() });
140
+ const confirmAnswer = z.object({ status: relayAccountStatusSchema });
141
+ export class RelayAccountClient {
142
+ now;
143
+ post;
144
+ constructor(post, now = Date.now) {
145
+ this.now = now;
146
+ this.post = post ?? defaultPost;
147
+ }
148
+ async call(origin, path, payload, identity) {
149
+ const body = Buffer.from(JSON.stringify(payload), 'utf8');
150
+ const time = Math.floor(this.now() / 1000);
151
+ const headers = identity ? { ...proofHeaders(identity.edSeed, postProof(path, body, time), time) } : {};
152
+ let answer;
153
+ try {
154
+ answer = await this.post(`${origin}${path}`, { headers, body });
155
+ }
156
+ catch {
157
+ throw new RelayAccountCallError(0, 'unreachable');
158
+ }
159
+ if (answer.status >= 200 && answer.status < 300)
160
+ return answer;
161
+ const refusal = (answer.json && typeof answer.json === 'object' ? answer.json : {});
162
+ const code = typeof refusal.code === 'string' ? refusal.code : answer.status >= 500 ? 'unavailable' : String(answer.status);
163
+ throw new RelayAccountCallError(answer.status, code, answer.retryAfter, typeof refusal.current === 'string' ? refusal.current : undefined);
164
+ }
165
+ parse(schema, json) {
166
+ const parsed = schema.safeParse(json);
167
+ if (!parsed.success)
168
+ throw new RelayAccountCallError(502, 'bad-answer');
169
+ return parsed.data;
170
+ }
171
+ async start(origin, identity, email, termsVersion) {
172
+ const { json } = await this.call(origin, ACCOUNT_PATHS.start, { email, termsVersion, accepted: true }, identity);
173
+ return this.parse(startAnswer, json);
174
+ }
175
+ async status(origin, identity) {
176
+ const { json } = await this.call(origin, ACCOUNT_PATHS.status, {}, identity);
177
+ return this.parse(statusAnswer, json);
178
+ }
179
+ async resend(origin, identity, token) {
180
+ const { json } = await this.call(origin, ACCOUNT_PATHS.resend, { token }, identity);
181
+ return this.parse(resendAnswer, json);
182
+ }
183
+ /** Needs no proof: the code is the credential. */
184
+ async confirm(origin, cezarId, code) {
185
+ const { json } = await this.call(origin, ACCOUNT_PATHS.confirm, { cezar: cezarId, code }, null);
186
+ return this.parse(confirmAnswer, json).status;
187
+ }
188
+ async devices(origin, identity, token, devices) {
189
+ await this.call(origin, ACCOUNT_PATHS.devices, { token, devices }, identity);
190
+ }
191
+ async delete(origin, identity, token) {
192
+ await this.call(origin, ACCOUNT_PATHS.delete, { token }, identity);
193
+ }
194
+ }
195
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/relay/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E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E,EAAE,QAAQ,CAAC,CAAC;IAC/E,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,QAAuB,EAAE,KAAa;QACjE,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,QAAQ,CAAC,CAAC;IACrE,CAAC;CACF"}
@@ -4,6 +4,9 @@ import type { SocketFactory } from './socket.ts';
4
4
  export declare const PING_MS = 45000;
5
5
  export declare const PONG_WAIT_MS = 15000;
6
6
  export declare const COMMAND_TIMEOUT_MS = 10000;
7
+ /** After a 4451, § 18: a fixed 10 minutes plus up to 60 s of jitter, never longer, and at once after a confirmation. */
8
+ export declare const ACCOUNT_RETRY_MS: number;
9
+ export declare const ACCOUNT_RETRY_JITTER_MS = 60000;
7
10
  export interface RelayLimits {
8
11
  frameBytes: number;
9
12
  controlBytes: number;
@@ -36,6 +39,10 @@ export interface RelayConnectionDeps {
36
39
  onPhoneLeft(deviceId: string): void;
37
40
  onData(deviceId: string, ciphertext: Buffer): void;
38
41
  onStatus(status: RelayStatus, detail?: string): void;
42
+ /** The relay account token for `X-Cezar-Relay-Account`, § 18. Optional on the wire. */
43
+ accountToken?(): string | undefined;
44
+ /** 401 `bad-token`: the token names an attachment that is gone. Drop it; the upgrade goes again without. */
45
+ onBadToken?(): void;
39
46
  }
40
47
  /** The long-lived `/v1/cezar/<cezarId>` socket: `cezar serve` only, while a device is paired. */
41
48
  export declare class RelayConnection {
@@ -48,6 +55,8 @@ export declare class RelayConnection {
48
55
  private clockSkewS;
49
56
  private proofRetried;
50
57
  private retryAfterS;
58
+ /** The `error` code a refused socket sends before its 4451, § 18. */
59
+ private closeReason;
51
60
  private reconnectTimer;
52
61
  private pingTimer;
53
62
  private pongTimer;
@@ -59,6 +68,8 @@ export declare class RelayConnection {
59
68
  constructor(deps: RelayConnectionDeps);
60
69
  get ready(): boolean;
61
70
  start(): void;
71
+ /** An account was attached or confirmed: try now instead of at the next 4451 retry. */
72
+ retryNow(): void;
62
73
  /** Closes for good. Idempotent. */
63
74
  stop(): void;
64
75
  whenReady(timeoutMs: number): Promise<void>;
@@ -72,6 +83,11 @@ export declare class RelayConnection {
72
83
  private onMessage;
73
84
  private onBinary;
74
85
  private onHello;
86
+ /**
87
+ * § 18: a `device-sync` that adds a device is refused as a whole without an account. `device-add`
88
+ * of a device the relay already holds is accepted, so that sorts the list; the rest syncs without the new ones.
89
+ */
90
+ private sync;
75
91
  private settle;
76
92
  private armPing;
77
93
  private teardown;