@codemem/core 0.41.0 → 0.43.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 (106) hide show
  1. package/dist/api-types.d.ts +14 -0
  2. package/dist/api-types.d.ts.map +1 -1
  3. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  4. package/dist/claude-hooks.d.ts +12 -4
  5. package/dist/claude-hooks.d.ts.map +1 -1
  6. package/dist/codex-hooks.d.ts +7 -3
  7. package/dist/codex-hooks.d.ts.map +1 -1
  8. package/dist/coordinator-actions.d.ts +2 -0
  9. package/dist/coordinator-actions.d.ts.map +1 -1
  10. package/dist/{coordinator-api-Bxw5Q3py.js → coordinator-api-DGTIU3Ri.js} +484 -445
  11. package/dist/coordinator-api-DGTIU3Ri.js.map +1 -0
  12. package/dist/coordinator-api.d.ts.map +1 -1
  13. package/dist/coordinator-enrollment-reconciler.d.ts +1 -0
  14. package/dist/coordinator-enrollment-reconciler.d.ts.map +1 -1
  15. package/dist/coordinator-runtime.d.ts +2 -1
  16. package/dist/coordinator-runtime.d.ts.map +1 -1
  17. package/dist/coordinator-store-contract.d.ts +7 -0
  18. package/dist/coordinator-store-contract.d.ts.map +1 -1
  19. package/dist/coordinator-store-test-harness.d.ts.map +1 -1
  20. package/dist/coordinator-store.d.ts +1 -0
  21. package/dist/coordinator-store.d.ts.map +1 -1
  22. package/dist/d1-coordinator-store.d.ts.map +1 -1
  23. package/dist/db.d.ts +3 -1
  24. package/dist/db.d.ts.map +1 -1
  25. package/dist/device-identity-binding.d.ts +50 -0
  26. package/dist/device-identity-binding.d.ts.map +1 -0
  27. package/dist/device-identity-inventory.d.ts +72 -0
  28. package/dist/device-identity-inventory.d.ts.map +1 -0
  29. package/dist/hook-transcript.d.ts +25 -0
  30. package/dist/hook-transcript.d.ts.map +1 -0
  31. package/dist/identity-device-assignment.d.ts +40 -0
  32. package/dist/identity-device-assignment.d.ts.map +1 -0
  33. package/dist/identity-target.d.ts +16 -0
  34. package/dist/identity-target.d.ts.map +1 -0
  35. package/dist/index.d.ts +26 -10
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +10278 -7001
  38. package/dist/index.js.map +1 -1
  39. package/dist/internal/cloudflare-coordinator.js +300 -295
  40. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  41. package/dist/legacy-recipient-policy-projection.d.ts +31 -0
  42. package/dist/legacy-recipient-policy-projection.d.ts.map +1 -1
  43. package/dist/legacy-team-assignment-expectation.d.ts +8 -0
  44. package/dist/legacy-team-assignment-expectation.d.ts.map +1 -0
  45. package/dist/legacy-team-candidate.d.ts +61 -0
  46. package/dist/legacy-team-candidate.d.ts.map +1 -0
  47. package/dist/legacy-team-project-canonical-preflight.d.ts +36 -0
  48. package/dist/legacy-team-project-canonical-preflight.d.ts.map +1 -0
  49. package/dist/legacy-team-setup-activation.d.ts +44 -0
  50. package/dist/legacy-team-setup-activation.d.ts.map +1 -0
  51. package/dist/legacy-team-setup-attempt.d.ts +10 -0
  52. package/dist/legacy-team-setup-attempt.d.ts.map +1 -0
  53. package/dist/legacy-team-setup-draft.d.ts +118 -0
  54. package/dist/legacy-team-setup-draft.d.ts.map +1 -0
  55. package/dist/legacy-team-setup-errors.d.ts +34 -0
  56. package/dist/legacy-team-setup-errors.d.ts.map +1 -0
  57. package/dist/legacy-team-setup-limits.d.ts +11 -0
  58. package/dist/legacy-team-setup-limits.d.ts.map +1 -0
  59. package/dist/policy-team-device-eligibility.d.ts.map +1 -1
  60. package/dist/project-invite-identity.d.ts +2 -0
  61. package/dist/project-invite-identity.d.ts.map +1 -1
  62. package/dist/project-scope-settings.d.ts +3 -0
  63. package/dist/project-scope-settings.d.ts.map +1 -1
  64. package/dist/prompt-transport.d.ts +36 -0
  65. package/dist/prompt-transport.d.ts.map +1 -0
  66. package/dist/raw-event-flush.d.ts +1 -0
  67. package/dist/raw-event-flush.d.ts.map +1 -1
  68. package/dist/raw-event-ingest.d.ts +19 -0
  69. package/dist/raw-event-ingest.d.ts.map +1 -0
  70. package/dist/raw-event-sweeper.d.ts +6 -1
  71. package/dist/raw-event-sweeper.d.ts.map +1 -1
  72. package/dist/recipient-policy-actor-eligibility.d.ts +12 -0
  73. package/dist/recipient-policy-actor-eligibility.d.ts.map +1 -0
  74. package/dist/recipient-policy-contract.d.ts +52 -0
  75. package/dist/recipient-policy-contract.d.ts.map +1 -1
  76. package/dist/recipient-policy-edges.d.ts.map +1 -1
  77. package/dist/recipient-policy-identifiers.d.ts +41 -0
  78. package/dist/recipient-policy-identifiers.d.ts.map +1 -0
  79. package/dist/recipient-policy-migration.d.ts +13 -1
  80. package/dist/recipient-policy-migration.d.ts.map +1 -1
  81. package/dist/recipient-policy-onboarding.d.ts.map +1 -1
  82. package/dist/recipient-policy-reconciler.d.ts.map +1 -1
  83. package/dist/recipient-policy-reconciliation.d.ts +2 -0
  84. package/dist/recipient-policy-reconciliation.d.ts.map +1 -1
  85. package/dist/recipient-policy-review.d.ts +17 -0
  86. package/dist/recipient-policy-review.d.ts.map +1 -1
  87. package/dist/schema-bootstrap.d.ts +10 -0
  88. package/dist/schema-bootstrap.d.ts.map +1 -1
  89. package/dist/schema.d.ts +5634 -3055
  90. package/dist/schema.d.ts.map +1 -1
  91. package/dist/share-operation.d.ts.map +1 -1
  92. package/dist/store.d.ts +1 -1
  93. package/dist/store.d.ts.map +1 -1
  94. package/dist/sync-auth.d.ts +62 -2
  95. package/dist/sync-auth.d.ts.map +1 -1
  96. package/dist/sync-bootstrap.d.ts +2 -0
  97. package/dist/sync-bootstrap.d.ts.map +1 -1
  98. package/dist/sync-http-client.d.ts +1 -0
  99. package/dist/sync-http-client.d.ts.map +1 -1
  100. package/dist/sync-pass.d.ts.map +1 -1
  101. package/dist/team-ownership-transitions.d.ts +22 -0
  102. package/dist/team-ownership-transitions.d.ts.map +1 -0
  103. package/dist/test-schema.generated.d.ts +1 -1
  104. package/dist/test-schema.generated.d.ts.map +1 -1
  105. package/package.json +1 -1
  106. package/dist/coordinator-api-Bxw5Q3py.js.map +0 -1
@@ -81,203 +81,230 @@ function p(e) {
81
81
  function m(e) {
82
82
  return String(e.kind === "team_member" ? e.assigned_identity_id ?? "" : e.target_identity_id ?? "").trim();
83
83
  }
84
- //#endregion
85
- //#region src/project-invite-identity.ts
86
- var h = 120;
87
- function g(e, t) {
84
+ var h = "reciprocal_approval_request_changed", g = class extends Error {
85
+ code = h;
86
+ constructor() {
87
+ super(h), this.name = "CoordinatorReciprocalApprovalRequestChangedError";
88
+ }
89
+ }, _ = 120, v = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/iu, y = /^(?:actor|device|identity|local):\S+$/iu, b = /^(?:actor|device|identity)[_-][a-z0-9][a-z0-9._:-]{4,}$/iu, x = /^pending[_-]\S+$/iu, S = /^[a-f0-9]{12,64}$/iu;
90
+ function C(e, t) {
88
91
  if ([...e].some((e) => /[\p{Cc}\p{Cf}]/u.test(e))) throw Error(`${t}_invalid`);
89
92
  let n = e.replace(/\s+/gu, " ").trim();
90
93
  if (!n) throw Error(`${t}_required`);
91
- if ([...n].length > h) throw Error(`${t}_too_long`);
94
+ if ([...n].length > _) throw Error(`${t}_too_long`);
95
+ return n;
96
+ }
97
+ function w(e) {
98
+ if (typeof e != "string") return !1;
99
+ let t;
100
+ try {
101
+ t = C(e, "display_name");
102
+ } catch {
103
+ return !1;
104
+ }
105
+ return ![
106
+ v,
107
+ y,
108
+ b,
109
+ x,
110
+ S
111
+ ].some((e) => e.test(t));
112
+ }
113
+ function T(e, t) {
114
+ let n = C(e, t);
115
+ if (!w(n)) throw Error(`${t}_invalid`);
92
116
  return n;
93
117
  }
94
- function _(e) {
118
+ function E(e) {
95
119
  let t = String(e ?? "").replace(/\.local$/iu, "");
96
- return t.trim() ? g(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
120
+ return t.trim() ? C(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
97
121
  }
98
- function v(e) {
122
+ function D(e) {
99
123
  for (let t of [
100
124
  e.explicitName,
101
125
  e.osName,
102
126
  e.coordinatorName
103
127
  ]) {
104
- let e = _(t);
105
- if (e) return e;
128
+ let e = String(t ?? "").replace(/\.local$/iu, "").trim();
129
+ if (!(!e || !w(e))) try {
130
+ let e = E(t);
131
+ if (e && w(e)) return e;
132
+ } catch {}
106
133
  }
107
134
  let t = String(e.fallbackSeed ?? "").replace(/[^a-z0-9]/giu, "").slice(0, 6);
108
135
  return t ? `Codemem device ${t}` : "Codemem device";
109
136
  }
110
- function y(e) {
137
+ function ee(e) {
111
138
  if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("project_summaries_invalid");
112
139
  return e.map((e) => {
113
140
  if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_summaries_invalid");
114
141
  let t = e;
115
142
  if (!Number.isSafeInteger(t.existing_memory_count) || Number(t.existing_memory_count) < 0) throw Error("project_summaries_invalid");
116
143
  return {
117
- display_name: g(String(t.display_name ?? ""), "project_name"),
144
+ display_name: C(String(t.display_name ?? ""), "project_name"),
118
145
  existing_memory_count: Number(t.existing_memory_count)
119
146
  };
120
147
  });
121
148
  }
122
149
  //#endregion
123
150
  //#region src/recipient-reviewed-intent.ts
124
- var b = 1, x = class extends Error {
151
+ var O = 1, k = class extends Error {
125
152
  code;
126
153
  constructor(e) {
127
154
  super(e), this.name = "RecipientReviewedIntentError", this.code = e;
128
155
  }
129
- }, S = /[\p{Cc}\p{Cf}]/u, C = 100, w = 64 * 1024;
130
- function T() {
131
- throw new x("recipient_reviewed_intent_invalid");
156
+ }, A = /[\p{Cc}\p{Cf}]/u, te = 100, ne = 64 * 1024;
157
+ function j() {
158
+ throw new k("recipient_reviewed_intent_invalid");
132
159
  }
133
- function E(e) {
134
- return (!e || typeof e != "object" || Array.isArray(e)) && T(), e;
160
+ function M(e) {
161
+ return (!e || typeof e != "object" || Array.isArray(e)) && j(), e;
135
162
  }
136
- function D(e, t) {
137
- Object.keys(e).some((e) => !t.includes(e)) && T();
163
+ function N(e, t) {
164
+ Object.keys(e).some((e) => !t.includes(e)) && j();
138
165
  }
139
- function O(e, t) {
140
- return (typeof e != "string" || !e || e !== e.trim() || e.length > t || S.test(e)) && T(), e;
166
+ function P(e, t) {
167
+ return (typeof e != "string" || !e || e !== e.trim() || e.length > t || A.test(e)) && j(), e;
141
168
  }
142
- function k(e) {
143
- (typeof e != "string" || S.test(e)) && T();
169
+ function re(e) {
170
+ (typeof e != "string" || A.test(e)) && j();
144
171
  let t = e.trim().replace(/\s+/gu, " ");
145
- return (!t || t.length > 256) && T(), t;
172
+ return (!t || t.length > 256) && j(), t;
146
173
  }
147
- function A(e) {
148
- typeof e != "string" && T();
174
+ function ie(e) {
175
+ typeof e != "string" && j();
149
176
  try {
150
- return g(e, "identity_display_name");
177
+ return C(e, "identity_display_name");
151
178
  } catch {
152
- return T();
179
+ return j();
153
180
  }
154
181
  }
155
- function j(e) {
156
- return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && T(), e;
182
+ function ae(e) {
183
+ return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && j(), e;
157
184
  }
158
- function M(e, t) {
185
+ function oe(e, t) {
159
186
  return e < t ? -1 : +(e > t);
160
187
  }
161
- function ee(e) {
188
+ function se(e) {
162
189
  return e.kind === "direct" ? "direct" : `team\u0000${e.teamId}`;
163
190
  }
164
- function te(e) {
165
- let t = E(e);
166
- return t.kind === "direct" ? (D(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && T(), D(t, [
191
+ function ce(e) {
192
+ let t = M(e);
193
+ return t.kind === "direct" ? (N(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && j(), N(t, [
167
194
  "kind",
168
195
  "teamId",
169
196
  "displayName"
170
197
  ]), {
171
198
  kind: "team",
172
- teamId: O(t.teamId, 256),
173
- displayName: k(t.displayName)
199
+ teamId: P(t.teamId, 256),
200
+ displayName: re(t.displayName)
174
201
  });
175
202
  }
176
- function ne(e) {
177
- let t = E(e);
178
- D(t, [
203
+ function le(e) {
204
+ let t = M(e);
205
+ N(t, [
179
206
  "canonicalProjectIdentity",
180
207
  "displayName",
181
208
  "existingMemoryCount",
182
209
  "futureMemoriesShared",
183
210
  "sources"
184
- ]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && T();
185
- let n = t.sources.map(te).toSorted((e, t) => M(ee(e), ee(t)));
186
- return new Set(n.map(ee)).size !== n.length && T(), {
187
- canonicalProjectIdentity: O(t.canonicalProjectIdentity, 512),
188
- displayName: k(t.displayName),
189
- existingMemoryCount: j(t.existingMemoryCount),
211
+ ]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && j();
212
+ let n = t.sources.map(ce).toSorted((e, t) => oe(se(e), se(t)));
213
+ return new Set(n.map(se)).size !== n.length && j(), {
214
+ canonicalProjectIdentity: P(t.canonicalProjectIdentity, 512),
215
+ displayName: re(t.displayName),
216
+ existingMemoryCount: ae(t.existingMemoryCount),
190
217
  futureMemoriesShared: !0,
191
218
  sources: n
192
219
  };
193
220
  }
194
- function re(e) {
195
- let t = E(e);
196
- return D(t, [
221
+ function ue(e) {
222
+ let t = M(e);
223
+ return N(t, [
197
224
  "canonicalProjectIdentity",
198
225
  "displayName",
199
226
  "existingMemoryCount"
200
227
  ]), {
201
- canonicalProjectIdentity: O(t.canonicalProjectIdentity, 512),
202
- displayName: k(t.displayName),
203
- existingMemoryCount: j(t.existingMemoryCount)
228
+ canonicalProjectIdentity: P(t.canonicalProjectIdentity, 512),
229
+ displayName: re(t.displayName),
230
+ existingMemoryCount: ae(t.existingMemoryCount)
204
231
  };
205
232
  }
206
- function ie(e) {
207
- (!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > C) && T();
208
- let t = e.projects.map(ne).toSorted((e, t) => M(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(re).toSorted((e, t) => M(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
209
- return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && T(), {
233
+ function de(e) {
234
+ (!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > te) && j();
235
+ let t = e.projects.map(le).toSorted((e, t) => oe(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(ue).toSorted((e, t) => oe(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
236
+ return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && j(), {
210
237
  projects: t,
211
238
  excludedProjects: n
212
239
  };
213
240
  }
214
- function ae(e, t) {
215
- if (!(e.journey === "team" && t.kind === "team_member" && e.team.teamId === t.policyTeamId || e.journey === "add_device" && t.kind === "add_device" && e.targetIdentity.identityId === t.targetIdentityId)) throw new x("recipient_invite_intent_mismatch");
241
+ function fe(e, t) {
242
+ if (!(e.journey === "team" && t.kind === "team_member" && e.team.teamId === t.policyTeamId || e.journey === "add_device" && t.kind === "add_device" && e.targetIdentity.identityId === t.targetIdentityId)) throw new k("recipient_invite_intent_mismatch");
216
243
  }
217
- function N(e, t) {
218
- let n = E(e);
219
- n.version !== 1 && T();
220
- let r = ie(n), i;
244
+ function pe(e, t) {
245
+ let n = M(e);
246
+ n.version !== 1 && j();
247
+ let r = de(n), i;
221
248
  if (n.journey === "team") {
222
- D(n, [
249
+ N(n, [
223
250
  "version",
224
251
  "journey",
225
252
  "team",
226
253
  "projects",
227
254
  "excludedProjects"
228
255
  ]);
229
- let e = E(n.team);
230
- D(e, [
256
+ let e = M(n.team);
257
+ N(e, [
231
258
  "teamId",
232
259
  "displayName",
233
260
  "futureProjectsInherit"
234
- ]), e.futureProjectsInherit !== !0 && T(), i = {
261
+ ]), e.futureProjectsInherit !== !0 && j(), i = {
235
262
  version: 1,
236
263
  journey: "team",
237
264
  team: {
238
- teamId: O(e.teamId, 256),
239
- displayName: k(e.displayName),
265
+ teamId: P(e.teamId, 256),
266
+ displayName: re(e.displayName),
240
267
  futureProjectsInherit: !0
241
268
  },
242
269
  ...r
243
270
  };
244
271
  } else if (n.journey === "add_device") {
245
- D(n, [
272
+ N(n, [
246
273
  "version",
247
274
  "journey",
248
275
  "targetIdentity",
249
276
  "projects",
250
277
  "excludedProjects"
251
278
  ]);
252
- let e = E(n.targetIdentity);
253
- D(e, ["identityId", "displayName"]), i = {
279
+ let e = M(n.targetIdentity);
280
+ N(e, ["identityId", "displayName"]), i = {
254
281
  version: 1,
255
282
  journey: "add_device",
256
283
  targetIdentity: {
257
- identityId: O(e.identityId, 256),
258
- displayName: A(e.displayName)
284
+ identityId: P(e.identityId, 256),
285
+ displayName: ie(e.displayName)
259
286
  },
260
287
  ...r
261
288
  };
262
- } else T();
263
- return t && ae(i, t), new TextEncoder().encode(P(i)).byteLength > w && T(), i;
289
+ } else j();
290
+ return t && fe(i, t), new TextEncoder().encode(F(i)).byteLength > ne && j(), i;
264
291
  }
265
- function P(e) {
266
- return Array.isArray(e) ? `[${e.map(P).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => M(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${P(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
292
+ function F(e) {
293
+ return Array.isArray(e) ? `[${e.map(F).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => oe(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${F(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
267
294
  }
268
- function oe(e, t) {
269
- return P(N(e, t));
295
+ function me(e, t) {
296
+ return F(pe(e, t));
270
297
  }
271
- async function se(e, t) {
272
- let n = oe(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
298
+ async function he(e, t) {
299
+ let n = me(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
273
300
  return Array.from(new Uint8Array(i), (e) => e.toString(16).padStart(2, "0")).join("");
274
301
  }
275
- async function F(e, t) {
276
- let n = N(e, t.target);
277
- if (await se(n) !== t.digest) throw new x("recipient_invite_intent_mismatch");
302
+ async function ge(e, t) {
303
+ let n = pe(e, t.target);
304
+ if (await he(n) !== t.digest) throw new k("recipient_invite_intent_mismatch");
278
305
  return n;
279
306
  }
280
- async function ce(e, t) {
307
+ async function _e(e, t) {
281
308
  if (!e) throw Error("recipient_invite_review_unavailable");
282
309
  let n;
283
310
  try {
@@ -286,21 +313,21 @@ async function ce(e, t) {
286
313
  throw Error("recipient_invite_review_unavailable");
287
314
  }
288
315
  try {
289
- let r = N(n, t.target);
290
- if (P(r) !== e) throw Error("recipient_invite_review_unavailable");
291
- return await F(r, t);
316
+ let r = pe(n, t.target);
317
+ if (F(r) !== e) throw Error("recipient_invite_review_unavailable");
318
+ return await ge(r, t);
292
319
  } catch (e) {
293
- throw e instanceof x && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
320
+ throw e instanceof k && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
294
321
  }
295
322
  }
296
323
  //#endregion
297
324
  //#region src/sync-fingerprint.ts
298
- function le(e) {
325
+ function ve(e) {
299
326
  return t("sha256").update(e, "utf-8").digest("hex");
300
327
  }
301
328
  //#endregion
302
329
  //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/compose.js
303
- var ue = (e, t, n) => (r, i) => {
330
+ var ye = (e, t, n) => (r, i) => {
304
331
  let a = -1;
305
332
  return o(0);
306
333
  async function o(s) {
@@ -316,40 +343,40 @@ var ue = (e, t, n) => (r, i) => {
316
343
  else r.finalized === !1 && n && (c = await n(r));
317
344
  return c && (r.finalized === !1 || l) && (r.res = c), r;
318
345
  }
319
- }, de = /* @__PURE__ */ Symbol(), fe = async (e, t = /* @__PURE__ */ Object.create(null)) => {
320
- let { all: n = !1, dot: r = !1 } = t, i = (e instanceof Pe ? e.raw.headers : e.headers).get("Content-Type");
321
- return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ? pe(e, {
346
+ }, be = /* @__PURE__ */ Symbol(), xe = async (e, t = /* @__PURE__ */ Object.create(null)) => {
347
+ let { all: n = !1, dot: r = !1 } = t, i = (e instanceof He ? e.raw.headers : e.headers).get("Content-Type");
348
+ return i?.startsWith("multipart/form-data") || i?.startsWith("application/x-www-form-urlencoded") ? Se(e, {
322
349
  all: n,
323
350
  dot: r
324
351
  }) : {};
325
352
  };
326
- async function pe(e, t) {
353
+ async function Se(e, t) {
327
354
  let n = await e.formData();
328
- return n ? me(n, t) : {};
355
+ return n ? Ce(n, t) : {};
329
356
  }
330
- function me(e, t) {
357
+ function Ce(e, t) {
331
358
  let n = /* @__PURE__ */ Object.create(null);
332
359
  return e.forEach((e, r) => {
333
- t.all || r.endsWith("[]") ? he(n, r, e) : n[r] = e;
360
+ t.all || r.endsWith("[]") ? we(n, r, e) : n[r] = e;
334
361
  }), t.dot && Object.entries(n).forEach(([e, t]) => {
335
- e.includes(".") && (ge(n, e, t), delete n[e]);
362
+ e.includes(".") && (Te(n, e, t), delete n[e]);
336
363
  }), n;
337
364
  }
338
- var he = (e, t, n) => {
365
+ var we = (e, t, n) => {
339
366
  e[t] === void 0 ? t.endsWith("[]") ? e[t] = [n] : e[t] = n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
340
- }, ge = (e, t, n) => {
367
+ }, Te = (e, t, n) => {
341
368
  if (/(?:^|\.)__proto__\./.test(t)) return;
342
369
  let r = e, i = t.split(".");
343
370
  i.forEach((e, t) => {
344
371
  t === i.length - 1 ? r[e] = n : ((!r[e] || typeof r[e] != "object" || Array.isArray(r[e]) || r[e] instanceof File) && (r[e] = /* @__PURE__ */ Object.create(null)), r = r[e]);
345
372
  });
346
- }, _e = (e) => {
373
+ }, Ee = (e) => {
347
374
  let t = e.split("/");
348
375
  return t[0] === "" && t.shift(), t;
349
- }, ve = (e) => {
350
- let { groups: t, path: n } = ye(e);
351
- return be(_e(n), t);
352
- }, ye = (e) => {
376
+ }, De = (e) => {
377
+ let { groups: t, path: n } = Oe(e);
378
+ return ke(Ee(n), t);
379
+ }, Oe = (e) => {
353
380
  let t = [];
354
381
  return e = e.replace(/\{[^}]+\}/g, (e, n) => {
355
382
  let r = `@${n}`;
@@ -358,7 +385,7 @@ var he = (e, t, n) => {
358
385
  groups: t,
359
386
  path: e
360
387
  };
361
- }, be = (e, t) => {
388
+ }, ke = (e, t) => {
362
389
  for (let n = t.length - 1; n >= 0; n--) {
363
390
  let [r] = t[n];
364
391
  for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
@@ -367,12 +394,12 @@ var he = (e, t, n) => {
367
394
  }
368
395
  }
369
396
  return e;
370
- }, xe = {}, Se = (e, t) => {
397
+ }, I = {}, Ae = (e, t) => {
371
398
  if (e === "*") return "*";
372
399
  let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
373
400
  if (n) {
374
401
  let r = `${e}#${t}`;
375
- return xe[r] || (n[2] ? xe[r] = t && t[0] !== ":" && t[0] !== "*" ? [
402
+ return I[r] || (n[2] ? I[r] = t && t[0] !== ":" && t[0] !== "*" ? [
376
403
  r,
377
404
  n[1],
378
405
  RegExp(`^${n[2]}(?=/${t})`)
@@ -380,14 +407,14 @@ var he = (e, t, n) => {
380
407
  e,
381
408
  n[1],
382
409
  RegExp(`^${n[2]}$`)
383
- ] : xe[r] = [
410
+ ] : I[r] = [
384
411
  e,
385
412
  n[1],
386
413
  !0
387
- ]), xe[r];
414
+ ]), I[r];
388
415
  }
389
416
  return null;
390
- }, Ce = (e, t) => {
417
+ }, je = (e, t) => {
391
418
  try {
392
419
  return t(e);
393
420
  } catch {
@@ -399,20 +426,20 @@ var he = (e, t, n) => {
399
426
  }
400
427
  });
401
428
  }
402
- }, we = (e) => Ce(e, decodeURI), Te = (e) => {
429
+ }, Me = (e) => je(e, decodeURI), Ne = (e) => {
403
430
  let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
404
431
  for (; r < t.length; r++) {
405
432
  let e = t.charCodeAt(r);
406
433
  if (e === 37) {
407
434
  let e = t.indexOf("?", r), i = t.indexOf("#", r), a = e === -1 ? i === -1 ? void 0 : i : i === -1 ? e : Math.min(e, i), o = t.slice(n, a);
408
- return we(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
435
+ return Me(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
409
436
  } else if (e === 63 || e === 35) break;
410
437
  }
411
438
  return t.slice(n, r);
412
- }, Ee = (e) => {
413
- let t = Te(e);
439
+ }, Pe = (e) => {
440
+ let t = Ne(e);
414
441
  return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
415
- }, I = (e, t, ...n) => (n.length && (t = I(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), De = (e) => {
442
+ }, L = (e, t, ...n) => (n.length && (t = L(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), Fe = (e) => {
416
443
  if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
417
444
  let t = e.split("/"), n = [], r = "";
418
445
  return t.forEach((e) => {
@@ -423,7 +450,7 @@ var he = (e, t, n) => {
423
450
  r += "/" + t, n.push(r);
424
451
  } else r += "/" + e;
425
452
  }), n.filter((e, t, n) => n.indexOf(e) === t);
426
- }, Oe = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : Ce(e, Me)) : e, ke = (e, t, n) => {
453
+ }, Ie = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : je(e, Be)) : e, Le = (e, t, n) => {
427
454
  let r;
428
455
  if (!n && t && !/[%+]/.test(t)) {
429
456
  let n = e.indexOf("?", 8);
@@ -432,7 +459,7 @@ var he = (e, t, n) => {
432
459
  let r = e.charCodeAt(n + t.length + 1);
433
460
  if (r === 61) {
434
461
  let r = n + t.length + 2, i = e.indexOf("&", r);
435
- return Oe(e.slice(r, i === -1 ? void 0 : i));
462
+ return Ie(e.slice(r, i === -1 ? void 0 : i));
436
463
  } else if (r == 38 || isNaN(r)) return "";
437
464
  n = e.indexOf(`&${t}`, n + 1);
438
465
  }
@@ -445,12 +472,12 @@ var he = (e, t, n) => {
445
472
  let t = e.indexOf("&", a + 1), o = e.indexOf("=", a);
446
473
  o > t && t !== -1 && (o = -1);
447
474
  let s = e.slice(a + 1, o === -1 ? t === -1 ? void 0 : t : o);
448
- if (r && (s = Oe(s)), a = t, s === "") continue;
475
+ if (r && (s = Ie(s)), a = t, s === "") continue;
449
476
  let c;
450
- o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = Oe(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
477
+ o === -1 ? c = "" : (c = e.slice(o + 1, t === -1 ? void 0 : t), r && (c = Ie(c))), n ? (i[s] && Array.isArray(i[s]) || (i[s] = []), i[s].push(c)) : i[s] ??= c;
451
478
  }
452
479
  return t ? i[t] : i;
453
- }, Ae = ke, je = (e, t) => ke(e, t, !0), Me = decodeURIComponent, Ne = (e) => Ce(e, Me), Pe = class {
480
+ }, Re = Le, ze = (e, t) => Le(e, t, !0), Be = decodeURIComponent, Ve = (e) => je(e, Be), He = class {
454
481
  raw;
455
482
  #e;
456
483
  #t;
@@ -465,13 +492,13 @@ var he = (e, t, n) => {
465
492
  }
466
493
  #n(e) {
467
494
  let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
468
- return n && /\%/.test(n) ? Ne(n) : n;
495
+ return n && /\%/.test(n) ? Ve(n) : n;
469
496
  }
470
497
  #r() {
471
498
  let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
472
499
  for (let n of t) {
473
500
  let t = this.#i(this.#t[0][this.routeIndex][1][n]);
474
- t !== void 0 && (e[n] = /\%/.test(t) ? Ne(t) : t);
501
+ t !== void 0 && (e[n] = /\%/.test(t) ? Ve(t) : t);
475
502
  }
476
503
  return e;
477
504
  }
@@ -479,10 +506,10 @@ var he = (e, t, n) => {
479
506
  return this.#t[1] ? this.#t[1][e] : e;
480
507
  }
481
508
  query(e) {
482
- return Ae(this.url, e);
509
+ return Re(this.url, e);
483
510
  }
484
511
  queries(e) {
485
- return je(this.url, e);
512
+ return ze(this.url, e);
486
513
  }
487
514
  header(e) {
488
515
  if (e) return this.raw.headers.get(e) ?? void 0;
@@ -492,7 +519,7 @@ var he = (e, t, n) => {
492
519
  }), t;
493
520
  }
494
521
  async parseBody(e) {
495
- return fe(this, e);
522
+ return xe(this, e);
496
523
  }
497
524
  #a = (e) => {
498
525
  let { bodyCache: t, raw: n } = this, r = t[e];
@@ -530,7 +557,7 @@ var he = (e, t, n) => {
530
557
  get method() {
531
558
  return this.raw.method;
532
559
  }
533
- get [de]() {
560
+ get [be]() {
534
561
  return this.#t;
535
562
  }
536
563
  get matchedRoutes() {
@@ -539,14 +566,14 @@ var he = (e, t, n) => {
539
566
  get routePath() {
540
567
  return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
541
568
  }
542
- }, Fe = {
569
+ }, Ue = {
543
570
  Stringify: 1,
544
571
  BeforeStream: 2,
545
572
  Stream: 3
546
- }, Ie = (e, t) => {
573
+ }, We = (e, t) => {
547
574
  let n = new String(e);
548
575
  return n.isEscaped = !0, n.callbacks = t, n;
549
- }, Le = async (e, t, n, r, i) => {
576
+ }, Ge = async (e, t, n, r, i) => {
550
577
  typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
551
578
  let a = e.callbacks;
552
579
  if (!a?.length) return Promise.resolve(e);
@@ -555,12 +582,12 @@ var he = (e, t, n) => {
555
582
  phase: t,
556
583
  buffer: i,
557
584
  context: r
558
- }))).then((e) => Promise.all(e.filter(Boolean).map((e) => Le(e, t, !1, r, i))).then(() => i[0]));
559
- return n ? Ie(await o, a) : o;
560
- }, Re = "text/plain; charset=UTF-8", ze = (e, t) => ({
585
+ }))).then((e) => Promise.all(e.filter(Boolean).map((e) => Ge(e, t, !1, r, i))).then(() => i[0]));
586
+ return n ? We(await o, a) : o;
587
+ }, Ke = "text/plain; charset=UTF-8", qe = (e, t) => ({
561
588
  "Content-Type": e,
562
589
  ...t
563
- }), L = (e, t) => new Response(e, t), Be = class {
590
+ }), R = (e, t) => new Response(e, t), Je = class {
564
591
  #e;
565
592
  #t;
566
593
  env = {};
@@ -580,7 +607,7 @@ var he = (e, t, n) => {
580
607
  this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
581
608
  }
582
609
  get req() {
583
- return this.#t ??= new Pe(this.#e, this.#d, this.#u), this.#t;
610
+ return this.#t ??= new He(this.#e, this.#d, this.#u), this.#t;
584
611
  }
585
612
  get event() {
586
613
  if (this.#i && "respondWith" in this.#i) return this.#i;
@@ -591,11 +618,11 @@ var he = (e, t, n) => {
591
618
  throw Error("This context has no ExecutionContext");
592
619
  }
593
620
  get res() {
594
- return this.#a ||= L(null, { headers: this.#l ??= new Headers() });
621
+ return this.#a ||= R(null, { headers: this.#l ??= new Headers() });
595
622
  }
596
623
  set res(e) {
597
624
  if (this.#a && e) {
598
- e = L(e.body, e);
625
+ e = R(e.body, e);
599
626
  for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") if (t === "set-cookie") {
600
627
  let t = this.#a.headers.getSetCookie();
601
628
  e.headers.delete("set-cookie");
@@ -611,7 +638,7 @@ var he = (e, t, n) => {
611
638
  this.#s = e;
612
639
  };
613
640
  header = (e, t, n) => {
614
- this.finalized && (this.#a = L(this.#a.body, this.#a));
641
+ this.finalized && (this.#a = R(this.#a.body, this.#a));
615
642
  let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
616
643
  t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
617
644
  };
@@ -636,38 +663,38 @@ var he = (e, t, n) => {
636
663
  r.delete(e);
637
664
  for (let n of t) r.append(e, n);
638
665
  }
639
- return L(e, {
666
+ return R(e, {
640
667
  status: typeof t == "number" ? t : t?.status ?? this.#r,
641
668
  headers: r
642
669
  });
643
670
  }
644
671
  newResponse = (...e) => this.#f(...e);
645
672
  body = (e, t, n) => this.#f(e, t, n);
646
- text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, ze(Re, n));
647
- json = (e, t, n) => this.#f(JSON.stringify(e), t, ze("application/json", n));
673
+ text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, qe(Ke, n));
674
+ json = (e, t, n) => this.#f(JSON.stringify(e), t, qe("application/json", n));
648
675
  html = (e, t, n) => {
649
- let r = (e) => this.#f(e, t, ze("text/html; charset=UTF-8", n));
650
- return typeof e == "object" ? Le(e, Fe.Stringify, !1, {}).then(r) : r(e);
676
+ let r = (e) => this.#f(e, t, qe("text/html; charset=UTF-8", n));
677
+ return typeof e == "object" ? Ge(e, Ue.Stringify, !1, {}).then(r) : r(e);
651
678
  };
652
679
  redirect = (e, t) => {
653
680
  let n = String(e);
654
681
  return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
655
682
  };
656
- notFound = () => (this.#c ??= () => L(), this.#c(this));
657
- }, Ve = [
683
+ notFound = () => (this.#c ??= () => R(), this.#c(this));
684
+ }, Ye = [
658
685
  "get",
659
686
  "post",
660
687
  "put",
661
688
  "delete",
662
689
  "options",
663
690
  "patch"
664
- ], He = "Can not add a route since the matcher is already built.", Ue = class extends Error {}, We = "__COMPOSED_HANDLER", Ge = (e) => e.text("404 Not Found", 404), Ke = (e, t) => {
691
+ ], Xe = "Can not add a route since the matcher is already built.", Ze = class extends Error {}, Qe = "__COMPOSED_HANDLER", $e = (e) => e.text("404 Not Found", 404), et = (e, t) => {
665
692
  if ("getResponse" in e) {
666
693
  let n = e.getResponse();
667
694
  return t.newResponse(n.body, n);
668
695
  }
669
696
  return console.error(e), t.text("Internal Server Error", 500);
670
- }, qe = class e {
697
+ }, tt = class e {
671
698
  get;
672
699
  post;
673
700
  put;
@@ -683,7 +710,7 @@ var he = (e, t, n) => {
683
710
  #e = "/";
684
711
  routes = [];
685
712
  constructor(e = {}) {
686
- [...Ve, "all"].forEach((e) => {
713
+ [...Ye, "all"].forEach((e) => {
687
714
  this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
688
715
  this.#r(e, this.#e, t);
689
716
  }), this);
@@ -699,7 +726,7 @@ var he = (e, t, n) => {
699
726
  this.#r("ALL", this.#e, e);
700
727
  }), this);
701
728
  let { strict: t, ...n } = e;
702
- Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Te : Ee;
729
+ Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Ne : Pe;
703
730
  }
704
731
  #t() {
705
732
  let t = new e({
@@ -708,18 +735,18 @@ var he = (e, t, n) => {
708
735
  });
709
736
  return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
710
737
  }
711
- #n = Ge;
712
- errorHandler = Ke;
738
+ #n = $e;
739
+ errorHandler = et;
713
740
  route(e, t) {
714
741
  let n = this.basePath(e);
715
742
  return t.routes.map((e) => {
716
743
  let r;
717
- t.errorHandler === Ke ? r = e.handler : (r = async (n, r) => (await ue([], t.errorHandler)(n, () => e.handler(n, r))).res, r[We] = e.handler), n.#r(e.method, e.path, r, e.basePath);
744
+ t.errorHandler === et ? r = e.handler : (r = async (n, r) => (await ye([], t.errorHandler)(n, () => e.handler(n, r))).res, r[Qe] = e.handler), n.#r(e.method, e.path, r, e.basePath);
718
745
  }), this;
719
746
  }
720
747
  basePath(e) {
721
748
  let t = this.#t();
722
- return t._basePath = I(this._basePath, e), t;
749
+ return t._basePath = L(this._basePath, e), t;
723
750
  }
724
751
  onError = (e) => (this.errorHandler = e, this);
725
752
  notFound = (e) => (this.#n = e, this);
@@ -737,21 +764,21 @@ var he = (e, t, n) => {
737
764
  return [e.env, t];
738
765
  };
739
766
  return r ||= (() => {
740
- let t = I(this._basePath, e), n = t === "/" ? 0 : t.length;
767
+ let t = L(this._basePath, e), n = t === "/" ? 0 : t.length;
741
768
  return (e) => {
742
769
  let t = new URL(e.url);
743
770
  return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
744
771
  };
745
- })(), this.#r("ALL", I(e, "*"), async (e, n) => {
772
+ })(), this.#r("ALL", L(e, "*"), async (e, n) => {
746
773
  let i = await t(r(e.req.raw), ...a(e));
747
774
  if (i) return i;
748
775
  await n();
749
776
  }), this;
750
777
  }
751
778
  #r(e, t, n, r) {
752
- e = e.toUpperCase(), t = I(this._basePath, t);
779
+ e = e.toUpperCase(), t = L(this._basePath, t);
753
780
  let i = {
754
- basePath: r === void 0 ? this._basePath : I(this._basePath, r),
781
+ basePath: r === void 0 ? this._basePath : L(this._basePath, r),
755
782
  path: t,
756
783
  method: e,
757
784
  handler: n
@@ -764,7 +791,7 @@ var he = (e, t, n) => {
764
791
  }
765
792
  #a(e, t, n, r) {
766
793
  if (r === "HEAD") return (async () => new Response(null, await this.#a(e, t, n, "GET")))();
767
- let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Be(e, {
794
+ let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Je(e, {
768
795
  path: i,
769
796
  matchResult: a,
770
797
  env: n,
@@ -782,7 +809,7 @@ var he = (e, t, n) => {
782
809
  }
783
810
  return e instanceof Promise ? e.then((e) => e || (o.finalized ? o.res : this.#n(o))).catch((e) => this.#i(e, o)) : e ?? this.#n(o);
784
811
  }
785
- let s = ue(a[0], this.errorHandler, this.#n);
812
+ let s = ye(a[0], this.errorHandler, this.#n);
786
813
  return (async () => {
787
814
  try {
788
815
  let e = await s(o);
@@ -794,19 +821,19 @@ var he = (e, t, n) => {
794
821
  })();
795
822
  }
796
823
  fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
797
- request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${I("/", e)}`, t), n, r));
824
+ request = (e, t, n, r) => e instanceof Request ? this.fetch(t ? new Request(e, t) : e, n, r) : (e = e.toString(), this.fetch(new Request(/^https?:\/\//.test(e) ? e : `http://localhost${L("/", e)}`, t), n, r));
798
825
  fire = () => {
799
826
  addEventListener("fetch", (e) => {
800
827
  e.respondWith(this.#a(e.request, e, void 0, e.request.method));
801
828
  });
802
829
  };
803
- }, Je = [];
804
- function Ye(e, t) {
830
+ }, nt = [];
831
+ function rt(e, t) {
805
832
  let n = this.buildAllMatchers(), r = ((e, t) => {
806
833
  let r = n[e] || n.ALL, i = r[2][t];
807
834
  if (i) return i;
808
835
  let a = t.match(r[0]);
809
- if (!a) return [[], Je];
836
+ if (!a) return [[], nt];
810
837
  let o = a.indexOf("", 1);
811
838
  return [r[1][o], a];
812
839
  });
@@ -814,17 +841,17 @@ function Ye(e, t) {
814
841
  }
815
842
  //#endregion
816
843
  //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/router/reg-exp-router/node.js
817
- var R = "[^/]+", z = ".*", B = "(?:|/.*)", V = /* @__PURE__ */ Symbol(), Xe = /* @__PURE__ */ new Set(".\\+*[^]$()");
818
- function Ze(e, t) {
819
- return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === z || e === B ? 1 : t === z || t === B ? -1 : e === R ? 1 : t === R ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
844
+ var z = "[^/]+", B = ".*", V = "(?:|/.*)", H = /* @__PURE__ */ Symbol(), it = /* @__PURE__ */ new Set(".\\+*[^]$()");
845
+ function at(e, t) {
846
+ return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 || e === B || e === V ? 1 : t === B || t === V ? -1 : e === z ? 1 : t === z ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
820
847
  }
821
- var Qe = class e {
848
+ var ot = class e {
822
849
  #e;
823
850
  #t;
824
851
  #n = /* @__PURE__ */ Object.create(null);
825
852
  insert(t, n, r, i, a) {
826
853
  if (t.length === 0) {
827
- if (this.#e !== void 0) throw V;
854
+ if (this.#e !== void 0) throw H;
828
855
  if (a) return;
829
856
  this.#e = n;
830
857
  return;
@@ -832,42 +859,42 @@ var Qe = class e {
832
859
  let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
833
860
  "",
834
861
  "",
835
- z
862
+ B
836
863
  ] : [
837
864
  "",
838
865
  "",
839
- R
866
+ z
840
867
  ] : o === "/*" ? [
841
868
  "",
842
869
  "",
843
- B
870
+ V
844
871
  ] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
845
872
  if (c) {
846
- let t = c[1], n = c[2] || R;
847
- if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw V;
873
+ let t = c[1], n = c[2] || z;
874
+ if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw H;
848
875
  if (l = this.#n[n], !l) {
849
- if (Object.keys(this.#n).some((e) => e !== z && e !== B)) throw V;
876
+ if (Object.keys(this.#n).some((e) => e !== B && e !== V)) throw H;
850
877
  if (a) return;
851
878
  l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
852
879
  }
853
880
  !a && t !== "" && r.push([t, l.#t]);
854
881
  } else if (l = this.#n[o], !l) {
855
- if (Object.keys(this.#n).some((e) => e.length > 1 && e !== z && e !== B)) throw V;
882
+ if (Object.keys(this.#n).some((e) => e.length > 1 && e !== B && e !== V)) throw H;
856
883
  if (a) return;
857
884
  l = this.#n[o] = new e();
858
885
  }
859
886
  l.insert(s, n, r, i, a);
860
887
  }
861
888
  buildRegExpStr() {
862
- let e = Object.keys(this.#n).sort(Ze).map((e) => {
889
+ let e = Object.keys(this.#n).sort(at).map((e) => {
863
890
  let t = this.#n[e];
864
- return (typeof t.#t == "number" ? `(${e})@${t.#t}` : Xe.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
891
+ return (typeof t.#t == "number" ? `(${e})@${t.#t}` : it.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
865
892
  });
866
893
  return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
867
894
  }
868
- }, $e = class {
895
+ }, st = class {
869
896
  #e = { varIndex: 0 };
870
- #t = new Qe();
897
+ #t = new ot();
871
898
  insert(e, t, n) {
872
899
  let r = [], i = [];
873
900
  for (let t = 0;;) {
@@ -901,29 +928,29 @@ var Qe = class e {
901
928
  r
902
929
  ];
903
930
  }
904
- }, et = [
931
+ }, ct = [
905
932
  /^$/,
906
933
  [],
907
934
  /* @__PURE__ */ Object.create(null)
908
- ], tt = /* @__PURE__ */ Object.create(null);
909
- function nt(e) {
910
- return tt[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
935
+ ], lt = /* @__PURE__ */ Object.create(null);
936
+ function ut(e) {
937
+ return lt[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
911
938
  }
912
- function rt() {
913
- tt = /* @__PURE__ */ Object.create(null);
939
+ function dt() {
940
+ lt = /* @__PURE__ */ Object.create(null);
914
941
  }
915
- function it(e) {
916
- let t = new $e(), n = [];
917
- if (e.length === 0) return et;
942
+ function ft(e) {
943
+ let t = new st(), n = [];
944
+ if (e.length === 0) return ct;
918
945
  let r = e.map((e) => [!/\*|\/:/.test(e[0]), ...e]).sort(([e, t], [n, r]) => e ? 1 : n ? -1 : t.length - r.length), i = /* @__PURE__ */ Object.create(null);
919
946
  for (let e = 0, a = -1, o = r.length; e < o; e++) {
920
947
  let [o, s, c] = r[e];
921
- o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), Je] : a++;
948
+ o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), nt] : a++;
922
949
  let l;
923
950
  try {
924
951
  l = t.insert(s, a, o);
925
952
  } catch (e) {
926
- throw e === V ? new Ue(s) : e;
953
+ throw e === H ? new Ze(s) : e;
927
954
  }
928
955
  o || (n[a] = c.map(([e, t]) => {
929
956
  let n = /* @__PURE__ */ Object.create(null);
@@ -949,12 +976,12 @@ function it(e) {
949
976
  i
950
977
  ];
951
978
  }
952
- function H(e, t) {
979
+ function U(e, t) {
953
980
  if (e) {
954
- for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (nt(n).test(t)) return [...e[n]];
981
+ for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (ut(n).test(t)) return [...e[n]];
955
982
  }
956
983
  }
957
- var at = class {
984
+ var pt = class {
958
985
  name = "RegExpRouter";
959
986
  #e;
960
987
  #t;
@@ -963,7 +990,7 @@ var at = class {
963
990
  }
964
991
  add(e, t, n) {
965
992
  let r = this.#e, i = this.#t;
966
- if (!r || !i) throw Error(He);
993
+ if (!r || !i) throw Error(Xe);
967
994
  r[e] || [r, i].forEach((t) => {
968
995
  t[e] = /* @__PURE__ */ Object.create(null), Object.keys(t.ALL).forEach((n) => {
969
996
  t[e][n] = [...t.ALL[n]];
@@ -971,10 +998,10 @@ var at = class {
971
998
  }), t === "/*" && (t = "*");
972
999
  let a = (t.match(/\/:/g) || []).length;
973
1000
  if (/\*$/.test(t)) {
974
- let o = nt(t);
1001
+ let o = ut(t);
975
1002
  e === "ALL" ? Object.keys(r).forEach((e) => {
976
- r[e][t] ||= H(r[e], t) || H(r.ALL, t) || [];
977
- }) : r[e][t] ||= H(r[e], t) || H(r.ALL, t) || [], Object.keys(r).forEach((t) => {
1003
+ r[e][t] ||= U(r[e], t) || U(r.ALL, t) || [];
1004
+ }) : r[e][t] ||= U(r[e], t) || U(r.ALL, t) || [], Object.keys(r).forEach((t) => {
978
1005
  (e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
979
1006
  o.test(e) && r[t][e].push([n, a]);
980
1007
  });
@@ -983,29 +1010,29 @@ var at = class {
983
1010
  });
984
1011
  return;
985
1012
  }
986
- let o = De(t) || [t];
1013
+ let o = Fe(t) || [t];
987
1014
  for (let t = 0, s = o.length; t < s; t++) {
988
1015
  let c = o[t];
989
1016
  Object.keys(i).forEach((o) => {
990
- (e === "ALL" || e === o) && (i[o][c] ||= [...H(r[o], c) || H(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
1017
+ (e === "ALL" || e === o) && (i[o][c] ||= [...U(r[o], c) || U(r.ALL, c) || []], i[o][c].push([n, a - s + t + 1]));
991
1018
  });
992
1019
  }
993
1020
  }
994
- match = Ye;
1021
+ match = rt;
995
1022
  buildAllMatchers() {
996
1023
  let e = /* @__PURE__ */ Object.create(null);
997
1024
  return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
998
1025
  e[t] ||= this.#n(t);
999
- }), this.#e = this.#t = void 0, rt(), e;
1026
+ }), this.#e = this.#t = void 0, dt(), e;
1000
1027
  }
1001
1028
  #n(e) {
1002
1029
  let t = [], n = e === "ALL";
1003
1030
  return [this.#e, this.#t].forEach((r) => {
1004
1031
  let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
1005
1032
  i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
1006
- }), n ? it(t) : null;
1033
+ }), n ? ft(t) : null;
1007
1034
  }
1008
- }, ot = class {
1035
+ }, mt = class {
1009
1036
  name = "SmartRouter";
1010
1037
  #e = [];
1011
1038
  #t = [];
@@ -1013,7 +1040,7 @@ var at = class {
1013
1040
  this.#e = e.routers;
1014
1041
  }
1015
1042
  add(e, t, n) {
1016
- if (!this.#t) throw Error(He);
1043
+ if (!this.#t) throw Error(Xe);
1017
1044
  this.#t.push([
1018
1045
  e,
1019
1046
  t,
@@ -1029,7 +1056,7 @@ var at = class {
1029
1056
  for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
1030
1057
  o = i.match(e, t);
1031
1058
  } catch (e) {
1032
- if (e instanceof Ue) continue;
1059
+ if (e instanceof Ze) continue;
1033
1060
  throw e;
1034
1061
  }
1035
1062
  this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
@@ -1042,15 +1069,15 @@ var at = class {
1042
1069
  if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
1043
1070
  return this.#e[0];
1044
1071
  }
1045
- }, U = /* @__PURE__ */ Object.create(null), st = (e) => {
1072
+ }, W = /* @__PURE__ */ Object.create(null), ht = (e) => {
1046
1073
  for (let t in e) return !0;
1047
1074
  return !1;
1048
- }, ct = class e {
1075
+ }, gt = class e {
1049
1076
  #e;
1050
1077
  #t;
1051
1078
  #n;
1052
1079
  #r = 0;
1053
- #i = U;
1080
+ #i = W;
1054
1081
  constructor(e, t, n) {
1055
1082
  if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
1056
1083
  let n = /* @__PURE__ */ Object.create(null);
@@ -1064,9 +1091,9 @@ var at = class {
1064
1091
  }
1065
1092
  insert(t, n, r) {
1066
1093
  this.#r = ++this.#r;
1067
- let i = this, a = ve(n), o = [];
1094
+ let i = this, a = De(n), o = [];
1068
1095
  for (let t = 0, n = a.length; t < n; t++) {
1069
- let n = a[t], r = a[t + 1], s = Se(n, r), c = Array.isArray(s) ? s[0] : n;
1096
+ let n = a[t], r = a[t + 1], s = Ae(n, r), c = Array.isArray(s) ? s[0] : n;
1070
1097
  if (c in i.#t) {
1071
1098
  i = i.#t[c], s && o.push(s[1]);
1072
1099
  continue;
@@ -1082,7 +1109,7 @@ var at = class {
1082
1109
  #a(e, t, n, r, i) {
1083
1110
  for (let a = 0, o = t.#e.length; a < o; a++) {
1084
1111
  let o = t.#e[a], s = o[n] || o.ALL, c = {};
1085
- if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== U || i && i !== U)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
1112
+ if (s !== void 0 && (s.params = /* @__PURE__ */ Object.create(null), e.push(s), r !== W || i && i !== W)) for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
1086
1113
  let t = s.possibleKeys[e], n = c[s.score];
1087
1114
  s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
1088
1115
  }
@@ -1090,15 +1117,15 @@ var at = class {
1090
1117
  }
1091
1118
  search(e, t) {
1092
1119
  let n = [];
1093
- this.#i = U;
1094
- let r = [this], i = _e(t), a = [], o = i.length, s = null;
1120
+ this.#i = W;
1121
+ let r = [this], i = Ee(t), a = [], o = i.length, s = null;
1095
1122
  for (let c = 0; c < o; c++) {
1096
1123
  let l = i[c], u = c === o - 1, d = [];
1097
1124
  for (let f = 0, p = r.length; f < p; f++) {
1098
1125
  let p = r[f], m = p.#t[l];
1099
1126
  m && (m.#i = p.#i, u ? (m.#t["*"] && this.#a(n, m.#t["*"], e, p.#i), this.#a(n, m, e, p.#i)) : d.push(m));
1100
1127
  for (let r = 0, f = p.#n.length; r < f; r++) {
1101
- let f = p.#n[r], m = p.#i === U ? {} : { ...p.#i };
1128
+ let f = p.#n[r], m = p.#i === W ? {} : { ...p.#i };
1102
1129
  if (f === "*") {
1103
1130
  let t = p.#t["*"];
1104
1131
  t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
@@ -1115,7 +1142,7 @@ var at = class {
1115
1142
  }
1116
1143
  let r = t.substring(s[c]), l = _.exec(r);
1117
1144
  if (l) {
1118
- if (m[g] = l[0], this.#a(n, v, e, p.#i, m), st(v.#t)) {
1145
+ if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ht(v.#t)) {
1119
1146
  v.#i = m;
1120
1147
  let e = l[0].match(/\//)?.length ?? 0;
1121
1148
  (a[e] ||= []).push(v);
@@ -1131,14 +1158,14 @@ var at = class {
1131
1158
  }
1132
1159
  return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
1133
1160
  }
1134
- }, lt = class {
1161
+ }, _t = class {
1135
1162
  name = "TrieRouter";
1136
1163
  #e;
1137
1164
  constructor() {
1138
- this.#e = new ct();
1165
+ this.#e = new gt();
1139
1166
  }
1140
1167
  add(e, t, n) {
1141
- let r = De(t);
1168
+ let r = Fe(t);
1142
1169
  if (r) {
1143
1170
  for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
1144
1171
  return;
@@ -1148,43 +1175,43 @@ var at = class {
1148
1175
  match(e, t) {
1149
1176
  return this.#e.search(e, t);
1150
1177
  }
1151
- }, ut = class extends qe {
1178
+ }, vt = class extends tt {
1152
1179
  constructor(e = {}) {
1153
- super(e), this.router = e.router ?? new ot({ routers: [new at(), new lt()] });
1180
+ super(e), this.router = e.router ?? new mt({ routers: [new pt(), new _t()] });
1154
1181
  }
1155
1182
  };
1156
1183
  //#endregion
1157
1184
  //#region src/coordinator-invites.ts
1158
- function dt(e) {
1185
+ function yt(e) {
1159
1186
  let t = "";
1160
1187
  for (let n of e) t += String.fromCharCode(n);
1161
1188
  return btoa(t);
1162
1189
  }
1163
- function ft(e) {
1190
+ function bt(e) {
1164
1191
  let t = atob(e), n = new Uint8Array(t.length);
1165
1192
  for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
1166
1193
  return n;
1167
1194
  }
1168
- function pt(e) {
1195
+ function xt(e) {
1169
1196
  return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1170
1197
  }
1171
- function mt(e) {
1198
+ function St(e) {
1172
1199
  let t = e.replace(/-/g, "+").replace(/_/g, "/");
1173
1200
  return t + "=".repeat((4 - t.length % 4) % 4);
1174
1201
  }
1175
- function W(e) {
1202
+ function G(e) {
1176
1203
  let t = JSON.stringify(e);
1177
- return pt(dt(new TextEncoder().encode(t)));
1204
+ return xt(yt(new TextEncoder().encode(t)));
1178
1205
  }
1179
- function ht(e) {
1180
- let t = new TextDecoder().decode(ft(mt(e))), n = JSON.parse(t);
1206
+ function Ct(e) {
1207
+ let t = new TextDecoder().decode(bt(St(e))), n = JSON.parse(t);
1181
1208
  if (typeof n != "object" || !n) throw Error("invalid invite payload");
1182
1209
  return n;
1183
1210
  }
1184
- function G(e) {
1211
+ function K(e) {
1185
1212
  return `codemem://join?invite=${encodeURIComponent(e)}`;
1186
1213
  }
1187
- function gt(e) {
1214
+ function wt(e) {
1188
1215
  let t = e.trim();
1189
1216
  if (t.startsWith("codemem://")) {
1190
1217
  let e = new URL(t).searchParams.get("invite") ?? "";
@@ -1195,44 +1222,44 @@ function gt(e) {
1195
1222
  }
1196
1223
  //#endregion
1197
1224
  //#region src/project-invite-acceptance.ts
1198
- var _t = "pending_setup", vt = "project_sync_enablement_failed", yt = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", bt = class extends Error {
1199
- code = vt;
1200
- detail = yt;
1225
+ var Tt = "pending_setup", Et = "project_sync_enablement_failed", Dt = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", Ot = class extends Error {
1226
+ code = Et;
1227
+ detail = Dt;
1201
1228
  constructor(e) {
1202
- super(yt, e), this.name = "ProjectSyncEnablementError";
1229
+ super(Dt, e), this.name = "ProjectSyncEnablementError";
1203
1230
  }
1204
1231
  };
1205
- function xt(e) {
1232
+ function kt(e) {
1206
1233
  return typeof e == "object" && !!e && "code" in e && e.code === "project_sync_enablement_failed" && "detail" in e && e.detail === "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.";
1207
1234
  }
1208
1235
  //#endregion
1209
1236
  //#region src/scope-resolution.ts
1210
- var St = "local-default", Ct = "legacy-shared-review";
1211
- function K(e) {
1237
+ var At = "local-default", jt = "legacy-shared-review";
1238
+ function q(e) {
1212
1239
  return e?.trim() || null;
1213
1240
  }
1214
- function q(e) {
1241
+ function J(e) {
1215
1242
  return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
1216
1243
  }
1217
- function wt(t) {
1218
- return q(e(t));
1244
+ function Mt(t) {
1245
+ return J(e(t));
1219
1246
  }
1220
- function Tt(e) {
1221
- let t = K(e);
1222
- return t ? q(t) : null;
1247
+ function Nt(e) {
1248
+ let t = q(e);
1249
+ return t ? J(t) : null;
1223
1250
  }
1224
- function Et(e) {
1251
+ function Pt(e) {
1225
1252
  let n = [
1226
1253
  e.cwd,
1227
1254
  e.project,
1228
1255
  e.workspaceId
1229
- ].map((e) => K(e)).find((e) => e != null);
1256
+ ].map((e) => q(e)).find((e) => e != null);
1230
1257
  return `unmapped:${t("sha256").update(n ?? "unknown", "utf8").digest("hex")}`;
1231
1258
  }
1232
- function Dt(e) {
1233
- let t = K(e.gitRemote), n = K(e.gitBranch), r = K(e.cwd), i = K(e.workspaceId), a = K(e.project);
1259
+ function Ft(e) {
1260
+ let t = q(e.gitRemote), n = q(e.gitBranch), r = q(e.cwd), i = q(e.workspaceId), a = q(e.project);
1234
1261
  if (t) {
1235
- let r = q(t);
1262
+ let r = J(t);
1236
1263
  return e.branchScoped && n ? {
1237
1264
  value: `${r}:${n}`,
1238
1265
  source: "git_remote_branch",
@@ -1244,49 +1271,49 @@ function Dt(e) {
1244
1271
  };
1245
1272
  }
1246
1273
  return r ? {
1247
- value: wt(r),
1274
+ value: Mt(r),
1248
1275
  source: "cwd",
1249
1276
  displayProject: a
1250
1277
  } : i ? {
1251
- value: q(i),
1278
+ value: J(i),
1252
1279
  source: "workspace_id",
1253
1280
  displayProject: a
1254
1281
  } : {
1255
- value: Et(e),
1282
+ value: Pt(e),
1256
1283
  source: "unmapped",
1257
1284
  displayProject: a
1258
1285
  };
1259
1286
  }
1260
- function Ot(e) {
1287
+ function It(e) {
1261
1288
  return !/[\\/:]/.test(e);
1262
1289
  }
1263
- function kt(e) {
1290
+ function Lt(e) {
1264
1291
  return e.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
1265
1292
  }
1266
- function At(e) {
1293
+ function Rt(e) {
1267
1294
  return e.replace(/[*?]/g, "").length;
1268
1295
  }
1269
- function jt(e, t) {
1270
- let n = q(t);
1271
- return !n || Ot(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${kt(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
1296
+ function zt(e, t) {
1297
+ let n = J(t);
1298
+ return !n || It(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${Lt(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
1272
1299
  }
1273
- function Mt(e) {
1300
+ function Bt(e) {
1274
1301
  return e.mapping.priority ?? 0;
1275
1302
  }
1276
- function Nt(e) {
1277
- let t = K(e.mapping.updated_at);
1303
+ function Vt(e) {
1304
+ let t = q(e.mapping.updated_at);
1278
1305
  if (!t) return 0;
1279
1306
  let n = Date.parse(t);
1280
1307
  return Number.isFinite(n) ? n : 0;
1281
1308
  }
1282
- function Pt(e, t) {
1283
- return Mt(t) - Mt(e) || t.specificity - e.specificity || Nt(t) - Nt(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
1309
+ function Ht(e, t) {
1310
+ return Bt(t) - Bt(e) || t.specificity - e.specificity || Vt(t) - Vt(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
1284
1311
  }
1285
- function Ft(e) {
1286
- return e.toSorted(Pt)[0] ?? null;
1312
+ function Ut(e) {
1313
+ return e.toSorted(Ht)[0] ?? null;
1287
1314
  }
1288
- function It(e) {
1289
- let t = Dt(e), n = K(e.explicitScopeId);
1315
+ function Wt(e) {
1316
+ let t = Ft(e), n = q(e.explicitScopeId);
1290
1317
  if (n) return {
1291
1318
  scopeId: n,
1292
1319
  reason: "explicit_override",
@@ -1301,7 +1328,7 @@ function It(e) {
1301
1328
  mapping: null,
1302
1329
  matchedPattern: null
1303
1330
  };
1304
- let r = e.mappings ?? [], i = Ft(r.filter((e) => Tt(e.workspace_identity) === t.value).map((e) => ({
1331
+ let r = e.mappings ?? [], i = Ut(r.filter((e) => Nt(e.workspace_identity) === t.value).map((e) => ({
1305
1332
  mapping: e,
1306
1333
  matchedPattern: null,
1307
1334
  specificity: t.value.length
@@ -1313,13 +1340,13 @@ function It(e) {
1313
1340
  mapping: i.mapping,
1314
1341
  matchedPattern: null
1315
1342
  };
1316
- let a = Ft(r.flatMap((e) => {
1317
- if (K(e.workspace_identity)) return [];
1318
- let n = K(e.project_pattern);
1319
- return !n || !jt(t.value, n) ? [] : [{
1343
+ let a = Ut(r.flatMap((e) => {
1344
+ if (q(e.workspace_identity)) return [];
1345
+ let n = q(e.project_pattern);
1346
+ return !n || !zt(t.value, n) ? [] : [{
1320
1347
  mapping: e,
1321
- matchedPattern: q(n),
1322
- specificity: At(n)
1348
+ matchedPattern: J(n),
1349
+ specificity: Rt(n)
1323
1350
  }];
1324
1351
  }));
1325
1352
  return a ? {
@@ -1336,11 +1363,11 @@ function It(e) {
1336
1363
  matchedPattern: null
1337
1364
  };
1338
1365
  }
1339
- function Lt(e, t) {
1366
+ function Gt(e, t) {
1340
1367
  let n = new Set([
1341
1368
  "",
1342
- St,
1343
- Ct
1369
+ At,
1370
+ jt
1344
1371
  ]), r = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
1345
1372
  for (let e of r) e.scope_id != null && n.add(e.scope_id);
1346
1373
  let i = e.prepare("SELECT sm.scope_id AS scope_id\n FROM scope_memberships sm\n JOIN replication_scopes rs ON rs.scope_id = sm.scope_id\n WHERE sm.device_id = ?\n AND sm.status = 'active'\n AND rs.status = 'active'\n AND sm.membership_epoch >= rs.membership_epoch").all(t);
@@ -1349,29 +1376,29 @@ function Lt(e, t) {
1349
1376
  }
1350
1377
  //#endregion
1351
1378
  //#region src/project-share-intent.ts
1352
- var Rt = "existing_and_future";
1353
- function zt(e) {
1379
+ var Kt = "existing_and_future";
1380
+ function qt(e) {
1354
1381
  return t("sha256").update(JSON.stringify(e)).digest("hex");
1355
1382
  }
1356
- function Bt(e) {
1357
- return zt({
1383
+ function Jt(e) {
1384
+ return qt({
1358
1385
  v: 1,
1359
- historyPolicy: Rt,
1386
+ historyPolicy: Kt,
1360
1387
  projects: e.map((e) => ({
1361
1388
  canonicalIdentity: e.canonicalIdentity,
1362
1389
  existingMemoryCount: e.existingMemoryCount
1363
1390
  })).toSorted((e, t) => e.canonicalIdentity.localeCompare(t.canonicalIdentity))
1364
1391
  });
1365
1392
  }
1366
- function Vt(e) {
1367
- return Bt(e.map((e) => ({
1393
+ function Yt(e) {
1394
+ return Jt(e.map((e) => ({
1368
1395
  canonicalIdentity: e.canonical_identity,
1369
1396
  displayName: e.display_name,
1370
1397
  identitySource: "coordinator_acceptance",
1371
1398
  existingMemoryCount: e.existing_memory_count
1372
1399
  })));
1373
1400
  }
1374
- function Ht(e) {
1401
+ function Xt(e) {
1375
1402
  if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("operation_intent_invalid");
1376
1403
  let t = e.map((e) => {
1377
1404
  if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
@@ -1379,11 +1406,11 @@ function Ht(e) {
1379
1406
  if (typeof t.canonical_identity != "string" || typeof t.display_name != "string") throw Error("operation_intent_invalid");
1380
1407
  let n = t.canonical_identity, r = n.trim(), i = t.display_name, a;
1381
1408
  try {
1382
- a = g(i, "project_name");
1409
+ a = C(i, "project_name");
1383
1410
  } catch {
1384
1411
  throw Error("operation_intent_invalid");
1385
1412
  }
1386
- let o = t.existing_memory_count, s = Dt({ gitRemote: r }).value;
1413
+ let o = t.existing_memory_count, s = Ft({ gitRemote: r }).value;
1387
1414
  if (!r || r !== n || r.length > 2048 || r.startsWith("unmapped:") || s !== r || a !== i || !Number.isSafeInteger(o) || Number(o) < 0 || /[\p{Cc}\p{Cf}]/u.test(r) || /[\p{Cc}\p{Cf}]/u.test(a)) throw Error("operation_intent_invalid");
1388
1415
  return {
1389
1416
  canonical_identity: r,
@@ -1396,20 +1423,20 @@ function Ht(e) {
1396
1423
  }
1397
1424
  //#endregion
1398
1425
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
1399
- function Ut(e) {
1426
+ function Zt(e) {
1400
1427
  let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
1401
1428
  return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
1402
1429
  }
1403
- function J() {
1404
- let [e, t] = Ut();
1430
+ function Y() {
1431
+ let [e, t] = Zt();
1405
1432
  return e * 1e3 + Math.floor(t / 1e6);
1406
1433
  }
1407
- function Wt(e) {
1434
+ function Qt(e) {
1408
1435
  return new Promise((t) => setTimeout(t, e));
1409
1436
  }
1410
1437
  //#endregion
1411
1438
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
1412
- var Gt = class {
1439
+ var $t = class {
1413
1440
  bucketSize;
1414
1441
  tokensPerInterval;
1415
1442
  interval;
@@ -1436,13 +1463,13 @@ var Gt = class {
1436
1463
  default: throw Error("Invalid interval " + n);
1437
1464
  }
1438
1465
  else this.interval = n;
1439
- this.parentBucket = r, this.content = 0, this.lastDrip = J();
1466
+ this.parentBucket = r, this.content = 0, this.lastDrip = Y();
1440
1467
  }
1441
1468
  async removeTokens(e) {
1442
1469
  if (this.bucketSize === 0) return Infinity;
1443
1470
  if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
1444
1471
  this.drip();
1445
- let t = async () => (await Wt(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
1472
+ let t = async () => (await Qt(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
1446
1473
  if (e > this.content) return t();
1447
1474
  if (this.parentBucket != null) {
1448
1475
  let n = await this.parentBucket.removeTokens(e);
@@ -1457,30 +1484,30 @@ var Gt = class {
1457
1484
  let e = this.content;
1458
1485
  return this.content = this.bucketSize, this.content > e;
1459
1486
  }
1460
- let e = J(), t = Math.max(e - this.lastDrip, 0);
1487
+ let e = Y(), t = Math.max(e - this.lastDrip, 0);
1461
1488
  this.lastDrip = e;
1462
1489
  let n = t * (this.tokensPerInterval / this.interval), r = this.content;
1463
1490
  return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
1464
1491
  }
1465
- }, Kt = class {
1492
+ }, en = class {
1466
1493
  tokenBucket;
1467
1494
  curIntervalStart;
1468
1495
  tokensThisInterval;
1469
1496
  fireImmediately;
1470
1497
  constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
1471
- this.tokenBucket = new Gt({
1498
+ this.tokenBucket = new $t({
1472
1499
  bucketSize: e,
1473
1500
  tokensPerInterval: e,
1474
1501
  interval: t
1475
- }), this.tokenBucket.content = e, this.curIntervalStart = J(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
1502
+ }), this.tokenBucket.content = e, this.curIntervalStart = Y(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
1476
1503
  }
1477
1504
  async removeTokens(e) {
1478
1505
  if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
1479
- let t = J();
1506
+ let t = Y();
1480
1507
  if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
1481
1508
  if (this.fireImmediately) return -1;
1482
1509
  {
1483
- await Wt(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
1510
+ await Qt(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
1484
1511
  let n = await this.tokenBucket.removeTokens(e);
1485
1512
  return this.tokensThisInterval += e, n;
1486
1513
  }
@@ -1490,7 +1517,7 @@ var Gt = class {
1490
1517
  }
1491
1518
  tryRemoveTokens(e) {
1492
1519
  if (e > this.tokenBucket.bucketSize) return !1;
1493
- let t = J();
1520
+ let t = Y();
1494
1521
  if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
1495
1522
  let n = this.tokenBucket.tryRemoveTokens(e);
1496
1523
  return n && (this.tokensThisInterval += e), n;
@@ -1501,7 +1528,7 @@ var Gt = class {
1501
1528
  };
1502
1529
  //#endregion
1503
1530
  //#region src/request-rate-limit.ts
1504
- function qt(e = {}) {
1531
+ function tn(e = {}) {
1505
1532
  let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
1506
1533
  function a(e) {
1507
1534
  return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
@@ -1518,7 +1545,7 @@ function qt(e = {}) {
1518
1545
  o(l);
1519
1546
  let u = `${c}:${e}`, d = r.get(u);
1520
1547
  return d || (d = {
1521
- limiter: new Kt({
1548
+ limiter: new en({
1522
1549
  tokensPerInterval: c,
1523
1550
  interval: t,
1524
1551
  fireImmediately: !0
@@ -1535,8 +1562,8 @@ function qt(e = {}) {
1535
1562
  }
1536
1563
  //#endregion
1537
1564
  //#region src/scope-membership-semantics.ts
1538
- var Jt = "Revocation blocks future sync for this Space. It does not remove data already copied to the revoked device; offline devices, backups, copied databases, malicious peers, or old versions may retain data.";
1539
- function Yt(e) {
1565
+ var nn = "Revocation blocks future sync for this Space. It does not remove data already copied to the revoked device; offline devices, backups, copied databases, malicious peers, or old versions may retain data.";
1566
+ function rn(e) {
1540
1567
  let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
1541
1568
  return t == null || n == null ? {
1542
1569
  membership_epoch: t,
@@ -1550,19 +1577,19 @@ function Yt(e) {
1550
1577
  reason: t < n ? "stale_epoch" : "current"
1551
1578
  };
1552
1579
  }
1553
- function Xt(e) {
1580
+ function an(e) {
1554
1581
  return {
1555
1582
  scope_id: e.scopeId,
1556
1583
  device_id: e.deviceId,
1557
1584
  membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
1558
1585
  prevents_future_sync: !0,
1559
1586
  deletes_already_copied_data: !1,
1560
- message: Jt
1587
+ message: nn
1561
1588
  };
1562
1589
  }
1563
1590
  //#endregion
1564
1591
  //#region src/sync-auth-constants.ts
1565
- var Zt = 300, Y = 64 * 1024, X = "X-Codemem-Coordinator-Admin", Qt = "X-Codemem-Coordinator-Admin-Actor", $t = 120, en = 30;
1592
+ var on = 300, sn = 64 * 1024, X = "X-Codemem-Coordinator-Admin", cn = "X-Codemem-Coordinator-Admin-Actor", ln = 120, un = 30;
1566
1593
  function Z(e, t) {
1567
1594
  let n = t.adminSecret();
1568
1595
  if (!n) return {
@@ -1581,14 +1608,14 @@ function Z(e, t) {
1581
1608
  error: "missing_admin_header"
1582
1609
  };
1583
1610
  }
1584
- function tn(e) {
1611
+ function dn(e) {
1585
1612
  let t = new URL(e);
1586
1613
  return t.search ? `${t.pathname}${t.search}` : t.pathname;
1587
1614
  }
1588
- async function nn(e, t, n, r) {
1615
+ async function fn(e, t, n, r) {
1589
1616
  return await e.recordNonce(t, n, r);
1590
1617
  }
1591
- async function rn(e, t) {
1618
+ async function pn(e, t) {
1592
1619
  await e.cleanupNonces(t);
1593
1620
  }
1594
1621
  async function Q(e, t, n, r) {
@@ -1624,7 +1651,7 @@ async function Q(e, t, n, r) {
1624
1651
  try {
1625
1652
  u = await n({
1626
1653
  method: r.method,
1627
- pathWithQuery: tn(r.url),
1654
+ pathWithQuery: dn(r.url),
1628
1655
  bodyBytes: r.body,
1629
1656
  timestamp: o,
1630
1657
  nonce: s,
@@ -1645,7 +1672,7 @@ async function Q(e, t, n, r) {
1645
1672
  enrollment: null
1646
1673
  };
1647
1674
  let d = t.now();
1648
- return await nn(e, i, s, d) ? (await rn(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
1675
+ return await fn(e, i, s, d) ? (await pn(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
1649
1676
  ok: !0,
1650
1677
  error: "ok",
1651
1678
  enrollment: c
@@ -1658,9 +1685,9 @@ async function Q(e, t, n, r) {
1658
1685
  function $(e) {
1659
1686
  return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
1660
1687
  }
1661
- function an(e) {
1688
+ function mn(e) {
1662
1689
  if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
1663
- let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, a = e.requestRateLimit ?? {}, o = a.limiter ?? qt(), s = Math.max(1, Math.trunc(a.readLimit ?? $t)), c = Math.max(1, Math.trunc(a.mutationLimit ?? en)), l = Math.max(1, Math.trunc(a.unauthenticatedReadLimit ?? Math.min(20, s))), u = Math.max(1, Math.trunc(a.unauthenticatedMutationLimit ?? Math.min(10, c))), d = new ut(), f = new TextDecoder();
1690
+ let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, a = e.requestRateLimit ?? {}, o = a.limiter ?? tn(), s = Math.max(1, Math.trunc(a.readLimit ?? ln)), c = Math.max(1, Math.trunc(a.mutationLimit ?? un)), l = Math.max(1, Math.trunc(a.unauthenticatedReadLimit ?? Math.min(20, s))), u = Math.max(1, Math.trunc(a.unauthenticatedMutationLimit ?? Math.min(10, c))), d = new vt(), f = new TextDecoder();
1664
1691
  function p(e, t, n) {
1665
1692
  let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = o.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? s : c : r ? l : u);
1666
1693
  return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
@@ -1670,7 +1697,7 @@ function an(e) {
1670
1697
  }
1671
1698
  async function m(e) {
1672
1699
  let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
1673
- if (Number.isFinite(t) && t > Y) return null;
1700
+ if (Number.isFinite(t) && t > sn) return null;
1674
1701
  let n = e.req.raw.body;
1675
1702
  if (!n) return new Uint8Array();
1676
1703
  let r = n.getReader(), i = [], a = 0;
@@ -1679,7 +1706,7 @@ function an(e) {
1679
1706
  let { done: e, value: t } = await r.read();
1680
1707
  if (e) break;
1681
1708
  if (t) {
1682
- if (a += t.byteLength, a > Y) return await r.cancel(), null;
1709
+ if (a += t.byteLength, a > sn) return await r.cancel(), null;
1683
1710
  i.push(t);
1684
1711
  }
1685
1712
  }
@@ -1705,7 +1732,7 @@ function an(e) {
1705
1732
  function v(e) {
1706
1733
  return e?.trim() || null;
1707
1734
  }
1708
- function b(e, t) {
1735
+ function y(e, t) {
1709
1736
  let n = e[t];
1710
1737
  if (n == null || n === "") return null;
1711
1738
  if (typeof n != "number" && typeof n != "string") return NaN;
@@ -1718,45 +1745,45 @@ function an(e) {
1718
1745
  let r = n;
1719
1746
  return Number.isFinite(r) ? Math.trunc(r) : NaN;
1720
1747
  }
1721
- function S(e) {
1748
+ function b(e) {
1722
1749
  return [
1723
1750
  "1",
1724
1751
  "true",
1725
1752
  "yes"
1726
1753
  ].includes(String(e ?? "").trim().toLowerCase());
1727
1754
  }
1728
- function C(e) {
1755
+ function x(e) {
1729
1756
  try {
1730
- return Ht(JSON.parse(e ?? ""));
1757
+ return Xt(JSON.parse(e ?? ""));
1731
1758
  } catch {
1732
1759
  throw Error("operation_intent_invalid");
1733
1760
  }
1734
1761
  }
1735
- function w(e) {
1762
+ function S(e) {
1736
1763
  let t = String(e.operation_id ?? "").trim(), n = String(e.reviewed_project_set_digest ?? "").trim();
1737
1764
  if (!/^share_[a-f0-9]{40}$/u.test(t) || !/^[a-f0-9]{64}$/u.test(n)) throw Error("operation_intent_invalid");
1738
- let r = C(e.project_intent_json);
1739
- if (Vt(r) !== n) throw Error("operation_intent_invalid");
1765
+ let r = x(e.project_intent_json);
1766
+ if (Yt(r) !== n) throw Error("operation_intent_invalid");
1740
1767
  return {
1741
1768
  operation_id: t,
1742
1769
  reviewed_project_set_digest: n,
1743
1770
  projects: r
1744
1771
  };
1745
1772
  }
1746
- function T(e) {
1773
+ function C(e) {
1747
1774
  try {
1748
- return y(JSON.parse(e ?? ""));
1775
+ return ee(JSON.parse(e ?? ""));
1749
1776
  } catch {
1750
1777
  throw Error("operation_intent_invalid");
1751
1778
  }
1752
1779
  }
1753
- async function E(e, t, n) {
1780
+ async function w(e, t, n) {
1754
1781
  if (!t) return n.json({ error: "group_id_required" }, 400);
1755
1782
  let r = await e.getGroup(t);
1756
1783
  return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
1757
1784
  }
1758
- async function D(e, t, n, r) {
1759
- let i = await E(e, t, r);
1785
+ async function E(e, t, n, r) {
1786
+ let i = await w(e, t, r);
1760
1787
  if (i) return {
1761
1788
  scope: null,
1762
1789
  response: i
@@ -1777,7 +1804,7 @@ function an(e) {
1777
1804
  response: r.json({ error: "scope_not_found" }, 404)
1778
1805
  };
1779
1806
  }
1780
- async function O(e, n, i) {
1807
+ async function D(e, n, i) {
1781
1808
  let a = await Q(e, t, r, {
1782
1809
  method: i.req.method,
1783
1810
  url: i.req.url,
@@ -1796,11 +1823,11 @@ function an(e) {
1796
1823
  response: p(i, String(a.enrollment.device_id), !0)
1797
1824
  };
1798
1825
  }
1799
- function k(e, t) {
1826
+ function O(e, t) {
1800
1827
  return e.status === "active" && e.membership_epoch >= t.membership_epoch;
1801
1828
  }
1802
1829
  async function A(e, t, n) {
1803
- return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n && k(e, t));
1830
+ return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n && O(e, t));
1804
1831
  }
1805
1832
  return d.post("/v1/presence", async (e) => {
1806
1833
  let i = await m(e);
@@ -1875,7 +1902,7 @@ function an(e) {
1875
1902
  if (!t) return e.json({ error: "group_id_required" }, 400);
1876
1903
  let r = n();
1877
1904
  try {
1878
- let { auth: n, response: i } = await O(r, t, e);
1905
+ let { auth: n, response: i } = await D(r, t, e);
1879
1906
  if (i) return i;
1880
1907
  if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
1881
1908
  let a = await r.listScopes({
@@ -1893,7 +1920,7 @@ function an(e) {
1893
1920
  if (!r) return e.json({ error: "scope_id_required" }, 400);
1894
1921
  let i = n();
1895
1922
  try {
1896
- let { auth: n, response: a } = await O(i, t, e);
1923
+ let { auth: n, response: a } = await D(i, t, e);
1897
1924
  if (a) return a;
1898
1925
  if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
1899
1926
  let o = (await i.listScopes({
@@ -1902,7 +1929,7 @@ function an(e) {
1902
1929
  })).find((e) => e.scope_id === r) ?? null;
1903
1930
  if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
1904
1931
  let s = await i.listScopeMemberships(r, !1);
1905
- return s.some((e) => e.device_id === String(n.enrollment?.device_id) && k(e, o)) ? e.json({ items: s.filter((e) => k(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
1932
+ return s.some((e) => e.device_id === String(n.enrollment?.device_id) && O(e, o)) ? e.json({ items: s.filter((e) => O(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
1906
1933
  } finally {
1907
1934
  await i.close();
1908
1935
  }
@@ -1940,11 +1967,11 @@ function an(e) {
1940
1967
  if (i == null) return e.json({ error: "body_too_large" }, 413);
1941
1968
  let a = h(i);
1942
1969
  if (!a) return e.json({ error: "invalid_json" }, 400);
1943
- let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim();
1970
+ let o = String(a.group_id ?? "").trim(), s = String(a.requested_device_id ?? "").trim(), c = Object.hasOwn(a, "expected_incoming_request_id") ? String(a.expected_incoming_request_id ?? "").trim() : void 0;
1944
1971
  if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
1945
- let c = n();
1972
+ let l = n();
1946
1973
  try {
1947
- let n = await Q(c, t, r, {
1974
+ let n = await Q(l, t, r, {
1948
1975
  method: e.req.method,
1949
1976
  url: e.req.url,
1950
1977
  groupId: o,
@@ -1958,18 +1985,24 @@ function an(e) {
1958
1985
  let a = p(e, String(n.enrollment.device_id), !0);
1959
1986
  if (a) return a;
1960
1987
  if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
1961
- if (!await c.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
1962
- let l = await c.createReciprocalApproval({
1963
- groupId: o,
1964
- requestingDeviceId: String(n.enrollment.device_id),
1965
- requestedDeviceId: s
1966
- });
1967
- return e.json({
1968
- ok: !0,
1969
- request: l
1970
- });
1988
+ if (!await l.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
1989
+ try {
1990
+ let t = await l.createReciprocalApproval({
1991
+ groupId: o,
1992
+ requestingDeviceId: String(n.enrollment.device_id),
1993
+ requestedDeviceId: s,
1994
+ ...c === void 0 ? {} : { expectedIncomingRequestId: c }
1995
+ });
1996
+ return e.json({
1997
+ ok: !0,
1998
+ request: t
1999
+ });
2000
+ } catch (t) {
2001
+ if (t instanceof g) return e.json({ error: t.code }, 409);
2002
+ throw t;
2003
+ }
1971
2004
  } finally {
1972
- await c.close();
2005
+ await l.close();
1973
2006
  }
1974
2007
  }), d.post("/v1/invites/add-device", async (e) => {
1975
2008
  let i = await m(e);
@@ -2007,7 +2040,7 @@ function an(e) {
2007
2040
  if (!d || d !== d.trim() || d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "identity_binding_required" }, 403);
2008
2041
  let f;
2009
2042
  try {
2010
- f = await F(a.reviewed_intent, {
2043
+ f = await ge(a.reviewed_intent, {
2011
2044
  target: {
2012
2045
  kind: "add_device",
2013
2046
  targetIdentityId: d
@@ -2015,7 +2048,7 @@ function an(e) {
2015
2048
  digest: l
2016
2049
  });
2017
2050
  } catch (t) {
2018
- return t instanceof x && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2051
+ return t instanceof k && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2019
2052
  }
2020
2053
  let m = await u.createInvite({
2021
2054
  groupId: s,
@@ -2039,13 +2072,13 @@ function an(e) {
2039
2072
  target_identity_id: m.target_identity_id ?? void 0,
2040
2073
  inviter_device_id: m.inviter_device_id ?? void 0,
2041
2074
  reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
2042
- }, g = W(h), { token: _, ...v } = m;
2075
+ }, g = G(h), { token: _, ...v } = m;
2043
2076
  return e.json({
2044
2077
  ok: !0,
2045
2078
  invite: v,
2046
2079
  payload: h,
2047
2080
  encoded: g,
2048
- link: G(g)
2081
+ link: K(g)
2049
2082
  });
2050
2083
  } finally {
2051
2084
  await u.close();
@@ -2061,7 +2094,7 @@ function an(e) {
2061
2094
  if (!o) return e.json({ error: "invalid_json" }, 400);
2062
2095
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.fingerprint ?? "").trim(), u = String(o.public_key ?? "").trim(), d = String(o.display_name ?? "").trim() || null;
2063
2096
  if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
2064
- if (le(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
2097
+ if (ve(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
2065
2098
  let f = n();
2066
2099
  try {
2067
2100
  await f.createGroup(s), await f.enrollDevice(s, {
@@ -2176,9 +2209,9 @@ function an(e) {
2176
2209
  if (i) return i;
2177
2210
  let a = String(e.req.param("group_id") ?? "").trim(), o = n();
2178
2211
  try {
2179
- let t = await E(o, a, e);
2212
+ let t = await w(o, a, e);
2180
2213
  if (t) return t;
2181
- let n = S(e.req.query("include_inactive"));
2214
+ let n = b(e.req.query("include_inactive"));
2182
2215
  return e.json({ items: await o.listScopes({
2183
2216
  groupId: a,
2184
2217
  includeInactive: n
@@ -2195,12 +2228,12 @@ function an(e) {
2195
2228
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2196
2229
  let o = h(a);
2197
2230
  if (!o) return e.json({ error: "invalid_json" }, 400);
2198
- let s = String(e.req.param("group_id") ?? "").trim(), c = _(o, "scope_id"), l = _(o, "label"), u = b(o, "membership_epoch");
2231
+ let s = String(e.req.param("group_id") ?? "").trim(), c = _(o, "scope_id"), l = _(o, "label"), u = y(o, "membership_epoch");
2199
2232
  if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
2200
2233
  if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2201
2234
  let d = n();
2202
2235
  try {
2203
- let t = await E(d, s, e);
2236
+ let t = await w(d, s, e);
2204
2237
  if (t) return t;
2205
2238
  let n = await d.createScope({
2206
2239
  scopeId: c,
@@ -2232,12 +2265,12 @@ function an(e) {
2232
2265
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2233
2266
  let o = h(a);
2234
2267
  if (!o) return e.json({ error: "invalid_json" }, 400);
2235
- let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = b(o, "membership_epoch");
2268
+ let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = y(o, "membership_epoch");
2236
2269
  if (!c) return e.json({ error: "scope_id_required" }, 400);
2237
2270
  if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2238
2271
  let u = n();
2239
2272
  try {
2240
- let t = await D(u, s, c, e);
2273
+ let t = await E(u, s, c, e);
2241
2274
  if (t.response) return t.response;
2242
2275
  let n = await u.updateScope({
2243
2276
  scopeId: c,
@@ -2267,8 +2300,8 @@ function an(e) {
2267
2300
  if (i) return i;
2268
2301
  let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
2269
2302
  try {
2270
- let t = await D(s, a, o, e);
2271
- return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, S(e.req.query("include_revoked"))) });
2303
+ let t = await E(s, a, o, e);
2304
+ return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, b(e.req.query("include_revoked"))) });
2272
2305
  } finally {
2273
2306
  await s.close();
2274
2307
  }
@@ -2281,13 +2314,13 @@ function an(e) {
2281
2314
  if (o == null) return e.json({ error: "body_too_large" }, 413);
2282
2315
  let s = h(o);
2283
2316
  if (!s) return e.json({ error: "invalid_json" }, 400);
2284
- let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = _(s, "effect_id"), d = _(s, "device_id"), f = b(s, "membership_epoch");
2317
+ let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = _(s, "effect_id"), d = _(s, "device_id"), f = y(s, "membership_epoch");
2285
2318
  if (!u) return e.json({ error: "effect_id_required" }, 400);
2286
2319
  if (!d) return e.json({ error: "device_id_required" }, 400);
2287
2320
  if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2288
2321
  let g = n();
2289
2322
  try {
2290
- let t = await D(g, c, l, e);
2323
+ let t = await E(g, c, l, e);
2291
2324
  if (t.response) return t.response;
2292
2325
  let n = await g.grantScopeMembership({
2293
2326
  effectId: u,
@@ -2301,7 +2334,7 @@ function an(e) {
2301
2334
  manifestHash: _(s, "manifest_hash"),
2302
2335
  signedManifestJson: _(s, "signed_manifest_json"),
2303
2336
  actorType: "admin",
2304
- actorId: v(e.req.header(Qt))
2337
+ actorId: v(e.req.header(cn))
2305
2338
  });
2306
2339
  return e.json({
2307
2340
  ok: !0,
@@ -2325,13 +2358,13 @@ function an(e) {
2325
2358
  if (o == null) return e.json({ error: "body_too_large" }, 413);
2326
2359
  let s = o.byteLength > 0 ? h(o) : {};
2327
2360
  if (!s) return e.json({ error: "invalid_json" }, 400);
2328
- let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = String(e.req.param("device_id") ?? "").trim(), d = _(s, "effect_id"), f = b(s, "membership_epoch");
2361
+ let c = String(e.req.param("group_id") ?? "").trim(), l = String(e.req.param("scope_id") ?? "").trim(), u = String(e.req.param("device_id") ?? "").trim(), d = _(s, "effect_id"), f = y(s, "membership_epoch");
2329
2362
  if (!d) return e.json({ error: "effect_id_required" }, 400);
2330
2363
  if (!u) return e.json({ error: "device_id_required" }, 400);
2331
2364
  if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2332
2365
  let g = n();
2333
2366
  try {
2334
- let t = await D(g, c, l, e);
2367
+ let t = await E(g, c, l, e);
2335
2368
  if (t.response) return t.response;
2336
2369
  if (!await g.revokeScopeMembership({
2337
2370
  effectId: d,
@@ -2342,7 +2375,7 @@ function an(e) {
2342
2375
  manifestHash: _(s, "manifest_hash"),
2343
2376
  signedManifestJson: _(s, "signed_manifest_json"),
2344
2377
  actorType: "admin",
2345
- actorId: v(e.req.header(Qt))
2378
+ actorId: v(e.req.header(cn))
2346
2379
  })) return e.json({ error: "membership_not_found" }, 404);
2347
2380
  let n;
2348
2381
  try {
@@ -2354,7 +2387,7 @@ function an(e) {
2354
2387
  ok: !0,
2355
2388
  scope_id: l,
2356
2389
  device_id: u,
2357
- revocation: Xt({
2390
+ revocation: an({
2358
2391
  scopeId: l,
2359
2392
  deviceId: u,
2360
2393
  membershipEpoch: n?.membership_epoch ?? f
@@ -2395,16 +2428,22 @@ function an(e) {
2395
2428
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
2396
2429
  if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
2397
2430
  if (!l) return e.json({ error: "display_name_required" }, 400);
2398
- let u = n();
2431
+ let u;
2399
2432
  try {
2400
- if (!await u.renameDevice(s, c, l)) return e.json({ error: "device_not_found" }, 404);
2401
- let t = await u.getEnrollment(s, c);
2433
+ u = T(l, "display_name");
2434
+ } catch (t) {
2435
+ return e.json({ error: t instanceof Error ? t.message : "display_name_invalid" }, 400);
2436
+ }
2437
+ let d = n();
2438
+ try {
2439
+ if (!await d.renameDevice(s, c, u)) return e.json({ error: "device_not_found" }, 404);
2440
+ let t = await d.getEnrollment(s, c);
2402
2441
  return e.json({
2403
2442
  ok: !0,
2404
2443
  device: t
2405
2444
  });
2406
2445
  } finally {
2407
- await u.close();
2446
+ await d.close();
2408
2447
  }
2409
2448
  }), d.post("/v1/admin/devices/disable", async (e) => {
2410
2449
  let r = Z(e.req.header(X), t);
@@ -2466,86 +2505,86 @@ function an(e) {
2466
2505
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2467
2506
  let o = h(a);
2468
2507
  if (!o) return e.json({ error: "invalid_json" }, 400);
2469
- let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null, d = String(o.operation_id ?? "").trim() || null, f = String(o.reviewed_project_set_digest ?? "").trim() || null, _ = String(o.inviter_actor_id ?? "").trim() || null, v = String(o.inviter_display_name ?? "").trim() || null, b = String(o.inviter_device_id ?? "").trim() || null, S = String(o.pending_person_id ?? "").trim() || null, C = String(o.invite_kind ?? o.kind ?? "").trim(), w = String(o.policy_team_id ?? "").trim() || null, T = String(o.target_identity_id ?? "").trim() || null, E = String(o.reviewed_preview_digest ?? "").trim() || null, D, O = null, k = null;
2508
+ let s = String(o.group_id ?? "").trim(), c = String(o.policy ?? "auto_admit").trim(), l = String(o.expires_at ?? "").trim(), u = String(o.created_by ?? "").trim() || null, d = String(o.operation_id ?? "").trim() || null, f = String(o.reviewed_project_set_digest ?? "").trim() || null, g = String(o.inviter_actor_id ?? "").trim() || null, _ = String(o.inviter_display_name ?? "").trim() || null, v = String(o.inviter_device_id ?? "").trim() || null, y = String(o.pending_person_id ?? "").trim() || null, b = String(o.invite_kind ?? o.kind ?? "").trim(), x = String(o.policy_team_id ?? "").trim() || null, S = String(o.target_identity_id ?? "").trim() || null, C = String(o.reviewed_preview_digest ?? "").trim() || null, w, E = null, D = null;
2470
2509
  if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
2471
2510
  if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
2472
2511
  if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
2473
2512
  if (!!d != !!f) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
2474
- let A = C || (d ? "project_share" : "legacy_enrollment");
2513
+ let O = b || (d ? "project_share" : "legacy_enrollment");
2475
2514
  if (![
2476
2515
  "legacy_enrollment",
2477
2516
  "project_share",
2478
2517
  "team_member",
2479
2518
  "add_device"
2480
- ].includes(A)) return e.json({ error: "invite_kind_invalid" }, 400);
2481
- if (A === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
2482
- if (E && !/^[a-f0-9]{64}$/u.test(E)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
2483
- if (A === "team_member" && (!w || !E || T) || A === "add_device" && (!T || !E || w) || !["team_member", "add_device"].includes(A) && (w || T || E)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
2484
- if ([w, T].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
2485
- if (A === "team_member" || A === "add_device") {
2519
+ ].includes(O)) return e.json({ error: "invite_kind_invalid" }, 400);
2520
+ if (O === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
2521
+ if (C && !/^[a-f0-9]{64}$/u.test(C)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
2522
+ if (O === "team_member" && (!x || !C || S) || O === "add_device" && (!S || !C || x) || !["team_member", "add_device"].includes(O) && (x || S || C)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
2523
+ if ([x, S].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
2524
+ if (O === "team_member" || O === "add_device") {
2486
2525
  if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
2487
2526
  try {
2488
- D = await F(o.reviewed_intent, {
2489
- target: A === "team_member" ? {
2527
+ w = await ge(o.reviewed_intent, {
2528
+ target: O === "team_member" ? {
2490
2529
  kind: "team_member",
2491
- policyTeamId: String(w)
2530
+ policyTeamId: String(x)
2492
2531
  } : {
2493
2532
  kind: "add_device",
2494
- targetIdentityId: String(T)
2533
+ targetIdentityId: String(S)
2495
2534
  },
2496
- digest: String(E)
2535
+ digest: String(C)
2497
2536
  });
2498
2537
  } catch (t) {
2499
- return t instanceof x && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2538
+ return t instanceof k && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2500
2539
  }
2501
2540
  } else if (o.reviewed_intent != null) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
2502
2541
  if (d && !/^share_[a-f0-9]{40}$/u.test(d) || f && !/^[a-f0-9]{64}$/u.test(f)) return e.json({ error: "operation_intent_reference_invalid" }, 400);
2503
2542
  if (d) {
2504
- if (!_ || !v || !b || !S) return e.json({ error: "project_invite_identity_context_required" }, 400);
2543
+ if (!g || !_ || !v || !y) return e.json({ error: "project_invite_identity_context_required" }, 400);
2505
2544
  if ([
2506
- _,
2507
- b,
2508
- S
2545
+ g,
2546
+ v,
2547
+ y
2509
2548
  ].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
2510
2549
  try {
2511
- if (g(v, "inviter_display_name"), O = y(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== O.length || (k = o.project_intent.map((e, t) => {
2550
+ if (T(_, "inviter_display_name"), E = ee(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== E.length || (D = o.project_intent.map((e, t) => {
2512
2551
  let n;
2513
2552
  try {
2514
- n = Ht([e])[0];
2553
+ n = Xt([e])[0];
2515
2554
  } catch {
2516
2555
  throw Error("project_intent_invalid");
2517
2556
  }
2518
- let r = O?.[t];
2557
+ let r = E?.[t];
2519
2558
  if (!n || !r || n.display_name !== r.display_name || n.existing_memory_count !== r.existing_memory_count) throw Error("project_intent_invalid");
2520
2559
  return n;
2521
- }), new Set(k.map((e) => e.canonical_identity)).size !== k.length)) throw Error("project_intent_invalid");
2560
+ }), new Set(D.map((e) => e.canonical_identity)).size !== D.length)) throw Error("project_intent_invalid");
2522
2561
  } catch (t) {
2523
2562
  return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
2524
2563
  }
2525
2564
  }
2526
- let j = n();
2565
+ let A = n();
2527
2566
  try {
2528
- let t = await j.getGroup(s);
2567
+ let t = await A.getGroup(s);
2529
2568
  if (!t) return e.json({ error: "group_not_found" }, 404);
2530
2569
  if (t.archived_at) return e.json({ error: "group_archived" }, 409);
2531
- let n = await j.createInvite({
2570
+ let n = await A.createInvite({
2532
2571
  groupId: s,
2533
2572
  policy: c,
2534
2573
  expiresAt: l,
2535
2574
  createdBy: u,
2536
2575
  operationId: d,
2537
2576
  reviewedProjectSetDigest: f,
2538
- inviterActorId: _,
2539
- inviterDisplayName: v,
2540
- inviterDeviceId: b,
2541
- pendingPersonId: S,
2542
- projectSummaries: O,
2543
- projectIntent: k,
2544
- inviteKind: A,
2545
- policyTeamId: w,
2546
- targetIdentityId: T,
2547
- reviewedPreviewDigest: E,
2548
- reviewedIntent: D
2577
+ inviterActorId: g,
2578
+ inviterDisplayName: _,
2579
+ inviterDeviceId: v,
2580
+ pendingPersonId: y,
2581
+ projectSummaries: E,
2582
+ projectIntent: D,
2583
+ inviteKind: O,
2584
+ policyTeamId: x,
2585
+ targetIdentityId: S,
2586
+ reviewedPreviewDigest: C,
2587
+ reviewedIntent: w
2549
2588
  }), r = {
2550
2589
  v: 1,
2551
2590
  kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
@@ -2558,7 +2597,7 @@ function an(e) {
2558
2597
  ...n.operation_id ? {
2559
2598
  operation_id: n.operation_id,
2560
2599
  inviter_name: n.inviter_display_name ?? null,
2561
- project_summaries: O ?? []
2600
+ project_summaries: E ?? []
2562
2601
  } : {},
2563
2602
  ...n.invite_kind === "team_member" ? {
2564
2603
  policy_team_id: n.policy_team_id ?? void 0,
@@ -2570,20 +2609,20 @@ function an(e) {
2570
2609
  inviter_device_id: n.inviter_device_id ?? void 0,
2571
2610
  reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
2572
2611
  } : {}
2573
- }, i = W(r), { token: a, ...p } = n;
2612
+ }, i = G(r), { token: a, ...p } = n;
2574
2613
  return e.json({
2575
2614
  ok: !0,
2576
2615
  invite: p,
2577
2616
  payload: r,
2578
2617
  encoded: i,
2579
- link: G(i)
2618
+ link: K(i)
2580
2619
  });
2581
2620
  } catch (t) {
2582
2621
  if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
2583
2622
  if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
2584
2623
  throw t;
2585
2624
  } finally {
2586
- await j.close();
2625
+ await A.close();
2587
2626
  }
2588
2627
  }), d.post("/v1/invites/inspect", async (e) => {
2589
2628
  let r = await m(e);
@@ -2628,7 +2667,7 @@ function an(e) {
2628
2667
  if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
2629
2668
  let i;
2630
2669
  try {
2631
- i = T(n.project_summaries_json);
2670
+ i = C(n.project_summaries_json);
2632
2671
  } catch {
2633
2672
  return e.json({ error: "invite_invalid" }, 409);
2634
2673
  }
@@ -2668,7 +2707,7 @@ function an(e) {
2668
2707
  if (!n) return e.json({ error: "operation_not_found" }, 404);
2669
2708
  let r;
2670
2709
  try {
2671
- r = C(n.project_intent_json);
2710
+ r = x(n.project_intent_json);
2672
2711
  } catch {
2673
2712
  return e.json({ error: "operation_intent_invalid" }, 409);
2674
2713
  }
@@ -2678,7 +2717,7 @@ function an(e) {
2678
2717
  display_name: String(e.display_name ?? ""),
2679
2718
  existing_memory_count: Number(e.existing_memory_count ?? 0)
2680
2719
  }));
2681
- s = G(W({
2720
+ s = K(G({
2682
2721
  v: 1,
2683
2722
  kind: "coordinator_team_invite",
2684
2723
  coordinator_url: new URL(e.req.url).origin,
@@ -2795,11 +2834,11 @@ function an(e) {
2795
2834
  } finally {
2796
2835
  await c.close();
2797
2836
  }
2798
- }), d.post("/v1/admin/join-requests/approve", async (e) => on(e, !0, {
2837
+ }), d.post("/v1/admin/join-requests/approve", async (e) => hn(e, !0, {
2799
2838
  createStore: n,
2800
2839
  runtime: t,
2801
2840
  rateLimitedResponse: p
2802
- })), d.post("/v1/admin/join-requests/deny", async (e) => on(e, !1, {
2841
+ })), d.post("/v1/admin/join-requests/deny", async (e) => hn(e, !1, {
2803
2842
  createStore: n,
2804
2843
  runtime: t,
2805
2844
  rateLimitedResponse: p
@@ -2823,10 +2862,10 @@ function an(e) {
2823
2862
  if (!i) return e.json({ error: "invalid_json" }, 400);
2824
2863
  let a = String(i.token ?? "").trim(), o = String(i.device_id ?? "").trim(), s = String(i.fingerprint ?? "").trim(), c = String(i.public_key ?? "").trim(), l = String(i.display_name ?? "").trim() || null, u = String(i.operation_id ?? "").trim(), d = String(i.recipient_actor_id ?? "").trim(), f = String(i.recipient_display_name ?? "").trim(), p = String(i.device_display_name ?? "").trim();
2825
2864
  if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
2826
- if (le(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
2827
- let _ = n();
2865
+ if (ve(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
2866
+ let g = n();
2828
2867
  try {
2829
- let n = await _.getInviteByTokenForInspection(a);
2868
+ let n = await g.getInviteByTokenForInspection(a);
2830
2869
  if (!n) return e.json({ error: "invite_invalid" }, 404);
2831
2870
  let r = !!(n.operation_id || n.reviewed_project_set_digest), m = n.invite_kind === "team_member" || n.invite_kind === "add_device";
2832
2871
  if (n.revoked_at) return e.json({ error: r || m ? "invite_invalid" : "revoked_token" }, 400);
@@ -2851,18 +2890,18 @@ function an(e) {
2851
2890
  try {
2852
2891
  if (i.recipient_display_name != null) {
2853
2892
  if (typeof i.recipient_display_name != "string") throw Error("recipient_display_name_invalid");
2854
- d = g(i.recipient_display_name, "recipient_display_name");
2893
+ d = T(i.recipient_display_name, "recipient_display_name");
2855
2894
  }
2856
2895
  if (i.device_display_name != null) {
2857
2896
  if (typeof i.device_display_name != "string") throw Error("device_display_name_invalid");
2858
- f = g(i.device_display_name, "device_display_name");
2897
+ f = T(i.device_display_name, "device_display_name");
2859
2898
  }
2860
2899
  } catch (t) {
2861
2900
  return e.json({ error: t instanceof Error ? t.message : "recipient_invite_identity_invalid" }, 400);
2862
2901
  }
2863
2902
  if (n.invite_kind === "add_device" && String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "add_device_invite_self_acceptance_forbidden" }, 409);
2864
2903
  try {
2865
- let r = await _.consumeRecipientInvite({
2904
+ let r = await g.consumeRecipientInvite({
2866
2905
  token: a,
2867
2906
  inviteKind: n.invite_kind,
2868
2907
  identityId: u,
@@ -2883,7 +2922,7 @@ function an(e) {
2883
2922
  target_identity_id: r.invite.target_identity_id ?? null,
2884
2923
  assigned_identity_id: r.invite.assigned_identity_id ?? null,
2885
2924
  bootstrap_grant_id: r.bootstrap_grant?.grant_id ?? null,
2886
- inviter_device: r.bootstrap_grant ? await _.getEnrollment(r.invite.group_id, r.bootstrap_grant.seed_device_id) : null,
2925
+ inviter_device: r.bootstrap_grant ? await g.getEnrollment(r.invite.group_id, r.bootstrap_grant.seed_device_id) : null,
2887
2926
  reviewed_preview_digest: r.invite.reviewed_preview_digest,
2888
2927
  reviewed_intent: r.reviewed_intent
2889
2928
  });
@@ -2910,18 +2949,18 @@ function an(e) {
2910
2949
  if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
2911
2950
  let l, m;
2912
2951
  try {
2913
- l = g(f, "recipient_display_name"), m = g(p, "device_display_name");
2952
+ l = T(f, "recipient_display_name"), m = T(p, "device_display_name");
2914
2953
  } catch (t) {
2915
2954
  return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
2916
2955
  }
2917
2956
  let h;
2918
2957
  try {
2919
- h = w(n);
2958
+ h = S(n);
2920
2959
  } catch {
2921
2960
  return e.json({ error: "operation_intent_invalid" }, 409);
2922
2961
  }
2923
2962
  try {
2924
- let n = await _.consumeProjectInvite({
2963
+ let n = await g.consumeProjectInvite({
2925
2964
  token: a,
2926
2965
  operationId: u,
2927
2966
  deviceId: o,
@@ -2934,7 +2973,7 @@ function an(e) {
2934
2973
  });
2935
2974
  return e.json({
2936
2975
  ok: !0,
2937
- status: _t,
2976
+ status: Tt,
2938
2977
  group_id: n.invite.group_id,
2939
2978
  operation_id: n.invite.operation_id,
2940
2979
  trust_state: n.invite.trust_state,
@@ -2958,21 +2997,21 @@ function an(e) {
2958
2997
  "recipient_display_name",
2959
2998
  "device_display_name"
2960
2999
  ].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
2961
- let h = await _.getGroup(String(n.group_id));
3000
+ let h = await g.getGroup(String(n.group_id));
2962
3001
  if (!h) return e.json({ error: "group_not_found" }, 404);
2963
3002
  if (h.archived_at) return e.json({ error: "group_archived" }, 409);
2964
- let v = String(n.group_id);
2965
- if (await _.getEnrollment(v, o)) return e.json({
3003
+ let _ = String(n.group_id);
3004
+ if (await g.getEnrollment(_, o)) return e.json({
2966
3005
  ok: !0,
2967
3006
  status: "already_enrolled",
2968
3007
  group_id: n.group_id,
2969
3008
  policy: n.policy
2970
3009
  });
2971
- let y = String(n.policy);
2972
- if (!["auto_admit", "approval_required"].includes(y)) return e.json({ error: `unknown invite policy: ${y}` }, 400);
2973
- if (y === "approval_required") {
2974
- let t = await _.createJoinRequest({
2975
- groupId: v,
3010
+ let v = String(n.policy);
3011
+ if (!["auto_admit", "approval_required"].includes(v)) return e.json({ error: `unknown invite policy: ${v}` }, 400);
3012
+ if (v === "approval_required") {
3013
+ let t = await g.createJoinRequest({
3014
+ groupId: _,
2976
3015
  deviceId: o,
2977
3016
  publicKey: c,
2978
3017
  fingerprint: s,
@@ -2987,7 +3026,7 @@ function an(e) {
2987
3026
  request_id: t.request_id
2988
3027
  });
2989
3028
  }
2990
- return await _.enrollDevice(v, {
3029
+ return await g.enrollDevice(_, {
2991
3030
  deviceId: o,
2992
3031
  fingerprint: s,
2993
3032
  publicKey: c,
@@ -2999,18 +3038,18 @@ function an(e) {
2999
3038
  policy: n.policy
3000
3039
  });
3001
3040
  } finally {
3002
- await _.close();
3041
+ await g.close();
3003
3042
  }
3004
3043
  }), d;
3005
3044
  }
3006
- async function on(e, t, n) {
3045
+ async function hn(e, t, n) {
3007
3046
  let r = Z(e.req.header(X), n.runtime);
3008
3047
  if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3009
3048
  let i = n.rateLimitedResponse(e, "admin", !0);
3010
3049
  if (i) return i;
3011
3050
  let a = await (async () => {
3012
3051
  let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
3013
- if (Number.isFinite(t) && t > Y) return null;
3052
+ if (Number.isFinite(t) && t > sn) return null;
3014
3053
  let n = e.req.raw.body;
3015
3054
  if (!n) return new Uint8Array();
3016
3055
  let r = n.getReader(), i = [], a = 0;
@@ -3019,7 +3058,7 @@ async function on(e, t, n) {
3019
3058
  let { done: e, value: t } = await r.read();
3020
3059
  if (e) break;
3021
3060
  if (t) {
3022
- if (a += t.byteLength, a > Y) return await r.cancel(), null;
3061
+ if (a += t.byteLength, a > sn) return await r.cancel(), null;
3023
3062
  i.push(t);
3024
3063
  }
3025
3064
  }
@@ -3067,6 +3106,6 @@ async function on(e, t, n) {
3067
3106
  }
3068
3107
  }
3069
3108
  //#endregion
3070
- export { se as A, l as B, G as C, oe as D, x as E, y as F, u as H, p as I, d as L, v as M, _ as N, N as O, g as P, m as R, gt as S, b as T, o as U, s as V, c as W, yt as _, Yt as a, ht as b, Ht as c, St as d, Dt as f, vt as g, _t as h, Xt as i, F as j, ce as k, Bt as l, Lt as m, Zt as n, Rt as o, It as p, Jt as r, Vt as s, an as t, Ct as u, bt as v, le as w, W as x, xt as y, i as z };
3109
+ export { he as A, p as B, K as C, me as D, k as E, T as F, s as G, m as H, C as I, c as J, u as K, ee as L, D as M, w as N, pe as O, E as P, g as R, wt as S, O as T, i as U, d as V, l as W, Dt as _, rn as a, Ct as b, Xt as c, At as d, Ft as f, Et as g, Tt as h, an as i, ge as j, _e as k, Jt as l, Gt as m, on as n, Kt as o, Wt as p, o as q, nn as r, Yt as s, mn as t, jt as u, Ot as v, ve as w, G as x, kt as y, h as z };
3071
3110
 
3072
- //# sourceMappingURL=coordinator-api-Bxw5Q3py.js.map
3111
+ //# sourceMappingURL=coordinator-api-DGTIU3Ri.js.map