@codemem/core 0.43.2 → 0.44.0-beta.1

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 (100) hide show
  1. package/dist/attribution-diagnostics.d.ts.map +1 -1
  2. package/dist/better-sqlite-coordinator-store.d.ts +5 -0
  3. package/dist/better-sqlite-coordinator-store.d.ts.map +1 -1
  4. package/dist/coordinator-actions.d.ts +29 -0
  5. package/dist/coordinator-actions.d.ts.map +1 -1
  6. package/dist/{coordinator-api-DGTIU3Ri.js → coordinator-api-BAufmPEa.js} +1272 -924
  7. package/dist/coordinator-api-BAufmPEa.js.map +1 -0
  8. package/dist/coordinator-api.d.ts.map +1 -1
  9. package/dist/coordinator-enrollment-reconciler.d.ts +1 -1
  10. package/dist/coordinator-enrollment-reconciler.d.ts.map +1 -1
  11. package/dist/coordinator-legacy-team-completion.d.ts +75 -0
  12. package/dist/coordinator-legacy-team-completion.d.ts.map +1 -0
  13. package/dist/coordinator-membership-effects.d.ts.map +1 -1
  14. package/dist/coordinator-runtime.d.ts +11 -1
  15. package/dist/coordinator-runtime.d.ts.map +1 -1
  16. package/dist/coordinator-store-contract.d.ts +11 -0
  17. package/dist/coordinator-store-contract.d.ts.map +1 -1
  18. package/dist/coordinator-store-test-harness.d.ts.map +1 -1
  19. package/dist/coordinator-store.d.ts +2 -0
  20. package/dist/coordinator-store.d.ts.map +1 -1
  21. package/dist/d1-coordinator-store.d.ts +5 -0
  22. package/dist/d1-coordinator-store.d.ts.map +1 -1
  23. package/dist/db.d.ts.map +1 -1
  24. package/dist/dedup-key-backfill.d.ts.map +1 -1
  25. package/dist/distill.d.ts.map +1 -1
  26. package/dist/embeddings.d.ts +69 -6
  27. package/dist/embeddings.d.ts.map +1 -1
  28. package/dist/export-import.d.ts.map +1 -1
  29. package/dist/hook-transcript.d.ts.map +1 -1
  30. package/dist/identity-device-assignment.d.ts.map +1 -1
  31. package/dist/identity-target.d.ts +3 -1
  32. package/dist/identity-target.d.ts.map +1 -1
  33. package/dist/index.d.ts +12 -8
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +10779 -8897
  36. package/dist/index.js.map +1 -1
  37. package/dist/ingest-pipeline.d.ts +9 -0
  38. package/dist/ingest-pipeline.d.ts.map +1 -1
  39. package/dist/internal/cloudflare-coordinator.d.ts +2 -0
  40. package/dist/internal/cloudflare-coordinator.d.ts.map +1 -1
  41. package/dist/internal/cloudflare-coordinator.js +440 -354
  42. package/dist/internal/cloudflare-coordinator.js.map +1 -1
  43. package/dist/legacy-team-candidate.d.ts.map +1 -1
  44. package/dist/legacy-team-setup-activation.d.ts +40 -1
  45. package/dist/legacy-team-setup-activation.d.ts.map +1 -1
  46. package/dist/legacy-team-setup-completion-manifest.d.ts +57 -0
  47. package/dist/legacy-team-setup-completion-manifest.d.ts.map +1 -0
  48. package/dist/legacy-team-setup-draft.d.ts.map +1 -1
  49. package/dist/legacy-team-setup-errors.d.ts +11 -2
  50. package/dist/legacy-team-setup-errors.d.ts.map +1 -1
  51. package/dist/legacy-team-setup-limits.d.ts +19 -1
  52. package/dist/legacy-team-setup-limits.d.ts.map +1 -1
  53. package/dist/memory-kinds.d.ts.map +1 -1
  54. package/dist/native-runtime.d.ts +12 -0
  55. package/dist/native-runtime.d.ts.map +1 -0
  56. package/dist/observer-auth.d.ts.map +1 -1
  57. package/dist/observer-client.d.ts.map +1 -1
  58. package/dist/policy-team-device-eligibility.d.ts.map +1 -1
  59. package/dist/project-identity.d.ts +4 -0
  60. package/dist/project-identity.d.ts.map +1 -0
  61. package/dist/project-invite-acceptance.d.ts.map +1 -1
  62. package/dist/project-scope-settings.d.ts.map +1 -1
  63. package/dist/prompt-transport.d.ts.map +1 -1
  64. package/dist/raw-event-flush.d.ts.map +1 -1
  65. package/dist/raw-event-ingest.d.ts.map +1 -1
  66. package/dist/raw-event-sweeper.d.ts +2 -3
  67. package/dist/raw-event-sweeper.d.ts.map +1 -1
  68. package/dist/recipient-policy-edges.d.ts.map +1 -1
  69. package/dist/recipient-policy-identifiers.d.ts.map +1 -1
  70. package/dist/recipient-policy-onboarding.d.ts.map +1 -1
  71. package/dist/recipient-policy-review.d.ts +6 -0
  72. package/dist/recipient-policy-review.d.ts.map +1 -1
  73. package/dist/recipient-policy-team-metadata.d.ts +7 -0
  74. package/dist/recipient-policy-team-metadata.d.ts.map +1 -1
  75. package/dist/recipient-reviewed-intent.d.ts.map +1 -1
  76. package/dist/ref-backfill.d.ts.map +1 -1
  77. package/dist/release-discovery.d.ts +4 -0
  78. package/dist/release-discovery.d.ts.map +1 -1
  79. package/dist/schema.d.ts +109 -109
  80. package/dist/schema.d.ts.map +1 -1
  81. package/dist/scope-backfill.d.ts.map +1 -1
  82. package/dist/scope-resolution.d.ts.map +1 -1
  83. package/dist/secret-scanner.d.ts.map +1 -1
  84. package/dist/session-context-backfill.d.ts.map +1 -1
  85. package/dist/store.d.ts +9 -1
  86. package/dist/store.d.ts.map +1 -1
  87. package/dist/summary-dedup-backfill.d.ts.map +1 -1
  88. package/dist/sync-capability.d.ts.map +1 -1
  89. package/dist/sync-daemon.d.ts +15 -0
  90. package/dist/sync-daemon.d.ts.map +1 -1
  91. package/dist/sync-identity.d.ts.map +1 -1
  92. package/dist/sync-retention-runner.d.ts.map +1 -1
  93. package/dist/test-schema.generated.d.ts +1 -1
  94. package/dist/test-schema.generated.d.ts.map +1 -1
  95. package/dist/vector-migration.d.ts +1 -0
  96. package/dist/vector-migration.d.ts.map +1 -1
  97. package/dist/vectors.d.ts +42 -3
  98. package/dist/vectors.d.ts.map +1 -1
  99. package/package.json +18 -10
  100. package/dist/coordinator-api-DGTIU3Ri.js.map +0 -1
@@ -1,57 +1,338 @@
1
1
  import { resolve as e } from "node:path";
2
2
  import { createHash as t } from "node:crypto";
3
+ function n(e) {
4
+ if (e.devices.length > 500 || e.projects.length > 500 || e.devices.length * e.projects.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
5
+ }
6
+ function r(e) {
7
+ if (e.projectIdentities.size * e.deviceCount > 1e4) throw Error("legacy_team_setup_roster_too_large");
8
+ }
9
+ function i(e, t, n) {
10
+ if (n.length === 0) return;
11
+ let r = Number(e.prepare("SELECT COUNT(*) FROM identity_devices").pluck().get() ?? 0);
12
+ if ((t.length + r) * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
13
+ }
14
+ function a(e, t, n, r) {
15
+ if (!r) return;
16
+ let i = [...new Set(t.map((e) => e.deviceId))], a = i.map(() => "?").join(", "), o = a ? `AND device_id NOT IN (${a})` : "", s = Number(e.prepare(`SELECT COUNT(*) FROM legacy_team_setup_draft_devices
17
+ WHERE attempt_id = ? ${o}`).pluck().get(r, ...i) ?? 0), c = t.length + s;
18
+ if (c > 500 || c * n.length > 1e4) throw Error("legacy_team_setup_roster_too_large");
19
+ }
20
+ //#endregion
21
+ //#region src/recipient-policy-identifiers.ts
22
+ function o(e, t) {
23
+ return e < t ? -1 : +(e > t);
24
+ }
25
+ var s = /[\p{Cc}\p{Cf}]/u;
26
+ function c(e, t) {
27
+ return typeof e == "string" && e.length > 0 && e === e.trim() && e.length <= t && !s.test(e);
28
+ }
29
+ function l(e) {
30
+ return c(e, 256);
31
+ }
32
+ function u(e) {
33
+ return c(e, 2048);
34
+ }
35
+ var d = "Recipient policy value must be strict JSON data";
36
+ function f() {
37
+ throw TypeError(d);
38
+ }
39
+ function p(e) {
40
+ let t = JSON.stringify(e);
41
+ return t === void 0 ? f() : t;
42
+ }
43
+ function m(e, t) {
44
+ if (e === null) return "null";
45
+ if (typeof e == "boolean") return e ? "true" : "false";
46
+ if (typeof e == "string") return p(e);
47
+ if (typeof e == "number") return !Number.isFinite(e) || Object.is(e, -0) ? f() : String(e);
48
+ if (typeof e != "object" || t.has(e)) return f();
49
+ t.add(e);
50
+ try {
51
+ if (Array.isArray(e)) {
52
+ if (Object.getPrototypeOf(e) !== Array.prototype) return f();
53
+ let n = Reflect.ownKeys(e);
54
+ if (n.length !== e.length + 1 || n.some((e) => typeof e != "string")) return f();
55
+ let r = [];
56
+ for (let n = 0; n < e.length; n += 1) {
57
+ let i = Object.getOwnPropertyDescriptor(e, String(n));
58
+ if (!i?.enumerable || !("value" in i)) return f();
59
+ r.push(m(i.value, t));
60
+ }
61
+ return `[${r.join(",")}]`;
62
+ }
63
+ let n = Object.getPrototypeOf(e);
64
+ return n !== Object.prototype && n !== null ? f() : `{${Reflect.ownKeys(e).map((t) => {
65
+ if (typeof t != "string") return f();
66
+ let n = Object.getOwnPropertyDescriptor(e, t);
67
+ return !n?.enumerable || !("value" in n) ? f() : [t, n.value];
68
+ }).toSorted(([e], [t]) => o(e, t)).map(([e, n]) => `${p(e)}:${m(n, t)}`).join(",")}}`;
69
+ } finally {
70
+ t.delete(e);
71
+ }
72
+ }
73
+ function h(e) {
74
+ return m(e, /* @__PURE__ */ new WeakSet());
75
+ }
76
+ function g(e, n) {
77
+ if (e.includes("\0") || !e.isWellFormed()) throw TypeError("Recipient policy digest prefix must be well-formed without NUL");
78
+ return `${e}:${t("sha256").update(e, "utf8").update("\0", "utf8").update(h(n), "utf8").digest("hex")}`;
79
+ }
80
+ function _(e, n) {
81
+ return `${e}:${t("sha256").update(h(n), "utf8").digest("hex")}`;
82
+ }
83
+ var v = ["team_invite", "coordinator_invite"];
84
+ function y(e, n) {
85
+ return `legacy-team-candidate:${t("sha256").update(JSON.stringify([e, n])).digest("hex").slice(0, 32)}`;
86
+ }
87
+ function ee(e, t) {
88
+ return g("legacy-team-project-ref-v1", [e, t]);
89
+ }
90
+ function b(e, t) {
91
+ return g("legacy-team-canonical-project-ref-v1", [e, t]);
92
+ }
93
+ function x(e, t) {
94
+ return g("legacy-team-device-ref-v1", [e, t]);
95
+ }
96
+ function S(e) {
97
+ return _("policy-team-v1", e);
98
+ }
99
+ function te(e) {
100
+ return g("legacy-team-roster-v1", e.map((e) => ({
101
+ deviceId: e.deviceId,
102
+ fingerprint: e.fingerprint,
103
+ enabled: e.enabled,
104
+ identityId: e.identityId
105
+ })).toSorted((e, t) => o(e.deviceId, t.deviceId)));
106
+ }
107
+ //#endregion
108
+ //#region src/coordinator-legacy-team-completion.ts
109
+ var C = 1, w = 50, T = 500, E = 15e5, ne = 25 * E, re = 256, ie = 37661024, ae = "completion_conflict", oe = class extends Error {
110
+ code = ae;
111
+ constructor() {
112
+ super(ae), this.name = "CoordinatorLegacyTeamCompletionConflictError";
113
+ }
114
+ };
115
+ function D() {
116
+ throw Error("completion_manifest_invalid");
117
+ }
118
+ function O(e) {
119
+ return (!e || typeof e != "object" || Array.isArray(e)) && D(), e;
120
+ }
121
+ function k(e, t) {
122
+ let n = new Set(t);
123
+ Object.keys(e).some((e) => !n.has(e)) && D();
124
+ }
125
+ function se(e) {
126
+ return /^(?:[\\/]{2}|\.{1,2}[\\/]|\/|~[\\/]|[a-z]:[\\/]|file:)/iu.test(e);
127
+ }
128
+ function A(e) {
129
+ return (typeof e != "string" || !e || e !== e.trim() || e.length > re || /[\p{Cc}\p{Cf}]/u.test(e) || se(e)) && D(), e;
130
+ }
131
+ function j(e) {
132
+ let t = A(e);
133
+ return /^[a-f0-9]{64}$/u.test(t) || D(), t;
134
+ }
135
+ function ce(e) {
136
+ typeof e != "string" && D();
137
+ let t = e.normalize("NFC").trim();
138
+ return (!t || [...t].length > 120 || /[\p{Cc}\p{Cf}]/u.test(t) || se(t)) && D(), t;
139
+ }
140
+ function le(e) {
141
+ (typeof e != "string" || !e) && D();
142
+ let t = new Date(e);
143
+ return (Number.isNaN(t.getTime()) || t.toISOString() !== e) && D(), e;
144
+ }
145
+ function ue(e, t) {
146
+ return (!Array.isArray(e) || e.length > t) && D(), e;
147
+ }
148
+ function M(e, t) {
149
+ let n = e.toSorted((e, n) => o(t(e), t(n)));
150
+ return n.some((e, r) => r > 0 && t(n[r - 1]) === t(e)) && D(), n;
151
+ }
152
+ function de(e) {
153
+ return M(ue(e, 50).map(A), (e) => e);
154
+ }
155
+ function fe(e) {
156
+ let t = A(e);
157
+ return /^legacy-team-candidate:[a-f0-9]{32}$/u.test(t) || D(), t;
158
+ }
159
+ function pe(e) {
160
+ let t = O(e);
161
+ k(t, [
162
+ "version",
163
+ "coordinator_id",
164
+ "candidate_ref",
165
+ "candidate_digest",
166
+ "team_id",
167
+ "team_digest",
168
+ "source_digest",
169
+ "finish_digest",
170
+ "access_delta_digest",
171
+ "team",
172
+ "memberships",
173
+ "device_decisions",
174
+ "project_mappings",
175
+ "project_recipients",
176
+ "completed_at"
177
+ ]), t.version !== 1 && D();
178
+ let n = O(t.team);
179
+ k(n, [
180
+ "display_name",
181
+ "policy_revision",
182
+ "device_eligibility_mode"
183
+ ]), n.device_eligibility_mode !== "reviewed_allowlist" && D();
184
+ let r = A(t.team_id), i = M(ue(t.memberships, 500).map((e) => {
185
+ let t = O(e);
186
+ return k(t, ["identity_id", "role"]), t.role !== "member" && D(), {
187
+ identity_id: A(t.identity_id),
188
+ role: "member"
189
+ };
190
+ }), (e) => e.identity_id), a = M(ue(t.device_decisions, 500).map((e) => {
191
+ let t = O(e);
192
+ k(t, [
193
+ "device_id",
194
+ "key_fingerprint",
195
+ "enabled",
196
+ "identity_id",
197
+ "decision"
198
+ ]), t.decision !== "included" && t.decision !== "excluded" && D(), typeof t.enabled != "boolean" && D();
199
+ let n = t.identity_id == null ? null : A(t.identity_id);
200
+ t.decision === "included" != !!n && D(), t.decision === "included" && !t.enabled && D();
201
+ let r = t.decision;
202
+ return {
203
+ device_id: A(t.device_id),
204
+ key_fingerprint: j(t.key_fingerprint),
205
+ enabled: t.enabled,
206
+ identity_id: n,
207
+ decision: r
208
+ };
209
+ }), (e) => e.device_id);
210
+ a.length === 0 && D();
211
+ let s = new Set(i.map((e) => e.identity_id)), c = new Set(a.flatMap((e) => e.identity_id ? [e.identity_id] : []));
212
+ (s.size !== c.size || [...c].some((e) => !s.has(e))) && D();
213
+ let l = M(ue(t.project_mappings, 500).map((e) => {
214
+ let t = O(e);
215
+ k(t, [
216
+ "project_ref",
217
+ "resolved_project_ref",
218
+ "scope_id"
219
+ ]);
220
+ let n = A(t.project_ref), r = A(t.resolved_project_ref);
221
+ return /^legacy-team-project-ref-v1:[0-9a-f]{64}$/u.test(n) || D(), /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(r) || D(), {
222
+ project_ref: n,
223
+ resolved_project_ref: r,
224
+ scope_id: A(t.scope_id)
225
+ };
226
+ }), (e) => e.project_ref), u = /* @__PURE__ */ new Map();
227
+ for (let e of l) {
228
+ let t = u.get(e.resolved_project_ref);
229
+ t && t !== e.scope_id && D(), u.set(e.resolved_project_ref, e.scope_id);
230
+ }
231
+ let d = M(ue(t.project_recipients, 500).map((e) => {
232
+ let t = O(e);
233
+ k(t, ["resolved_project_ref", "team_id"]);
234
+ let n = A(t.team_id);
235
+ n !== r && D();
236
+ let i = A(t.resolved_project_ref);
237
+ return /^legacy-team-resolved-project-ref-v1:[0-9a-f]{64}$/u.test(i) || D(), {
238
+ resolved_project_ref: i,
239
+ team_id: n
240
+ };
241
+ }), (e) => e.resolved_project_ref), f = [...new Set(l.map((e) => e.resolved_project_ref))].toSorted(o), p = d.map((e) => e.resolved_project_ref);
242
+ JSON.stringify(p) !== JSON.stringify(f) && D();
243
+ let m = {
244
+ version: 1,
245
+ coordinator_id: A(t.coordinator_id),
246
+ candidate_ref: fe(t.candidate_ref),
247
+ candidate_digest: j(t.candidate_digest),
248
+ team_id: r,
249
+ team_digest: j(t.team_digest),
250
+ source_digest: j(t.source_digest),
251
+ finish_digest: j(t.finish_digest),
252
+ access_delta_digest: j(t.access_delta_digest),
253
+ team: {
254
+ display_name: ce(n.display_name),
255
+ policy_revision: j(n.policy_revision),
256
+ device_eligibility_mode: "reviewed_allowlist"
257
+ },
258
+ memberships: i,
259
+ device_decisions: a,
260
+ project_mappings: l,
261
+ project_recipients: d,
262
+ completed_at: le(t.completed_at)
263
+ };
264
+ return new TextEncoder().encode(JSON.stringify(m)).byteLength > 15e5 && D(), m;
265
+ }
266
+ function me(e) {
267
+ return JSON.stringify(pe(e));
268
+ }
269
+ function he(e) {
270
+ e.team_id !== S(e.candidate_ref) && D();
271
+ }
272
+ function ge(e, t) {
273
+ y(e.coordinator_id, t) !== e.candidate_ref && D();
274
+ }
275
+ function _e(e, t, n) {
276
+ ge(e, t);
277
+ let r = new Set(e.project_mappings.map((e) => e.scope_id));
278
+ n.length !== r.size && D();
279
+ let i = e.coordinator_id;
280
+ for (let e of n) (!e.scope_id || !r.has(e.scope_id) || e.authority_type !== "coordinator" || !e.coordinator_id || e.group_id !== t || e.status !== "active" || e.coordinator_id !== i) && D();
281
+ return i;
282
+ }
283
+ //#endregion
3
284
  //#region src/coordinator-membership-effects.ts
4
- var n = "scope_membership_effect_conflict", r = {
285
+ var ve = "scope_membership_effect_conflict", ye = {
5
286
  device_not_enrolled: "device must be enrolled and enabled in the scope group.",
6
287
  scope_group_mismatch: "membership groupId must match the scope groupId.",
7
288
  scope_inactive: "scope is not active.",
8
289
  scope_not_found: "scopeId must reference an existing scope."
9
- }, i = class extends Error {
290
+ }, N = class extends Error {
10
291
  code;
11
292
  constructor(e) {
12
- super(r[e]), this.name = "CoordinatorMembershipError", this.code = e;
293
+ super(ye[e]), this.name = "CoordinatorMembershipError", this.code = e;
13
294
  }
14
295
  };
15
- function a(e) {
296
+ function P(e) {
16
297
  return e?.trim() || null;
17
298
  }
18
- function o(e) {
19
- let t = a(e);
299
+ function be(e) {
300
+ let t = P(e);
20
301
  if (!t) throw Error("effectId is required.");
21
302
  if (t.length > 512 || /[\p{Cc}\p{Cf}]/u.test(t)) throw Error("effectId is invalid.");
22
303
  return t;
23
304
  }
24
- function s(e) {
305
+ function xe(e) {
25
306
  return JSON.stringify({
26
- scopeId: a(e.scopeId),
27
- deviceId: a(e.deviceId),
28
- role: a(e.role),
307
+ scopeId: P(e.scopeId),
308
+ deviceId: P(e.deviceId),
309
+ role: P(e.role),
29
310
  membershipEpoch: e.membershipEpoch ?? null,
30
- coordinatorId: a(e.coordinatorId),
31
- groupId: a(e.groupId),
32
- manifestIssuerDeviceId: a(e.manifestIssuerDeviceId),
33
- manifestHash: a(e.manifestHash),
34
- signedManifestJson: a(e.signedManifestJson),
35
- actorType: a(e.actorType),
36
- actorId: a(e.actorId)
311
+ coordinatorId: P(e.coordinatorId),
312
+ groupId: P(e.groupId),
313
+ manifestIssuerDeviceId: P(e.manifestIssuerDeviceId),
314
+ manifestHash: P(e.manifestHash),
315
+ signedManifestJson: P(e.signedManifestJson),
316
+ actorType: P(e.actorType),
317
+ actorId: P(e.actorId)
37
318
  });
38
319
  }
39
- function c(e) {
320
+ function Se(e) {
40
321
  return JSON.stringify({
41
- scopeId: a(e.scopeId),
42
- deviceId: a(e.deviceId),
43
- groupId: a(e.groupId),
322
+ scopeId: P(e.scopeId),
323
+ deviceId: P(e.deviceId),
324
+ groupId: P(e.groupId),
44
325
  membershipEpoch: e.membershipEpoch ?? null,
45
- manifestHash: a(e.manifestHash),
46
- signedManifestJson: a(e.signedManifestJson),
47
- actorType: a(e.actorType),
48
- actorId: a(e.actorId)
326
+ manifestHash: P(e.manifestHash),
327
+ signedManifestJson: P(e.signedManifestJson),
328
+ actorType: P(e.actorType),
329
+ actorId: P(e.actorId)
49
330
  });
50
331
  }
51
- function l(e, t, r) {
52
- if (e.action !== t || e.request_json !== r) throw Error(n);
332
+ function Ce(e, t, n) {
333
+ if (e.action !== t || e.request_json !== n) throw Error(ve);
53
334
  }
54
- function u(e) {
335
+ function we(e) {
55
336
  if (e.action !== "grant" || e.outcome_applied !== 1 || e.role == null || e.status == null || e.membership_epoch == null || e.updated_at == null) throw Error("scope_membership_effect_receipt_invalid");
56
337
  return {
57
338
  scope_id: e.scope_id,
@@ -69,242 +350,242 @@ function u(e) {
69
350
  }
70
351
  //#endregion
71
352
  //#region src/coordinator-store-contract.ts
72
- function d(e) {
353
+ function Te(e) {
73
354
  let t = e.trim(), n = new Date(t);
74
355
  if (!t || Number.isNaN(n.getTime())) throw Error("expiresAt must be a valid date.");
75
356
  return n.toISOString();
76
357
  }
77
- var f = /^identity:[A-Za-z0-9_-]{18,24}$/u;
78
- function p(e) {
79
- return typeof e == "string" && e === e.trim() && f.test(e);
358
+ var Ee = /^identity:[A-Za-z0-9_-]{18,24}$/u;
359
+ function De(e) {
360
+ return typeof e == "string" && e === e.trim() && Ee.test(e);
80
361
  }
81
- function m(e) {
362
+ function Oe(e) {
82
363
  return String(e.kind === "team_member" ? e.assigned_identity_id ?? "" : e.target_identity_id ?? "").trim();
83
364
  }
84
- var h = "reciprocal_approval_request_changed", g = class extends Error {
85
- code = h;
365
+ var ke = "reciprocal_approval_request_changed", Ae = class extends Error {
366
+ code = ke;
86
367
  constructor() {
87
- super(h), this.name = "CoordinatorReciprocalApprovalRequestChangedError";
368
+ super(ke), this.name = "CoordinatorReciprocalApprovalRequestChangedError";
88
369
  }
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) {
370
+ }, je = 120, Me = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/iu, Ne = /^(?:actor|device|identity|local):\S+$/iu, Pe = /^(?:actor|device|identity)[_-][a-z0-9][a-z0-9._:-]{4,}$/iu, Fe = /^pending[_-]\S+$/iu, Ie = /^[a-f0-9]{12,64}$/iu;
371
+ function F(e, t) {
91
372
  if ([...e].some((e) => /[\p{Cc}\p{Cf}]/u.test(e))) throw Error(`${t}_invalid`);
92
373
  let n = e.replace(/\s+/gu, " ").trim();
93
374
  if (!n) throw Error(`${t}_required`);
94
- if ([...n].length > _) throw Error(`${t}_too_long`);
375
+ if ([...n].length > je) throw Error(`${t}_too_long`);
95
376
  return n;
96
377
  }
97
- function w(e) {
378
+ function Le(e) {
98
379
  if (typeof e != "string") return !1;
99
380
  let t;
100
381
  try {
101
- t = C(e, "display_name");
382
+ t = F(e, "display_name");
102
383
  } catch {
103
384
  return !1;
104
385
  }
105
386
  return ![
106
- v,
107
- y,
108
- b,
109
- x,
110
- S
387
+ Me,
388
+ Ne,
389
+ Pe,
390
+ Fe,
391
+ Ie
111
392
  ].some((e) => e.test(t));
112
393
  }
113
- function T(e, t) {
114
- let n = C(e, t);
115
- if (!w(n)) throw Error(`${t}_invalid`);
394
+ function I(e, t) {
395
+ let n = F(e, t);
396
+ if (!Le(n)) throw Error(`${t}_invalid`);
116
397
  return n;
117
398
  }
118
- function E(e) {
399
+ function Re(e) {
119
400
  let t = String(e ?? "").replace(/\.local$/iu, "");
120
- return t.trim() ? C(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
401
+ return t.trim() ? F(t.replace(/[-_]+/gu, " "), "device_display_name") : null;
121
402
  }
122
- function D(e) {
403
+ function ze(e) {
123
404
  for (let t of [
124
405
  e.explicitName,
125
406
  e.osName,
126
407
  e.coordinatorName
127
408
  ]) {
128
409
  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;
410
+ if (!(!e || !Le(e))) try {
411
+ let e = Re(t);
412
+ if (e && Le(e)) return e;
132
413
  } catch {}
133
414
  }
134
415
  let t = String(e.fallbackSeed ?? "").replace(/[^a-z0-9]/giu, "").slice(0, 6);
135
416
  return t ? `Codemem device ${t}` : "Codemem device";
136
417
  }
137
- function ee(e) {
418
+ function Be(e) {
138
419
  if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("project_summaries_invalid");
139
420
  return e.map((e) => {
140
421
  if (!e || typeof e != "object" || Array.isArray(e)) throw Error("project_summaries_invalid");
141
422
  let t = e;
142
423
  if (!Number.isSafeInteger(t.existing_memory_count) || Number(t.existing_memory_count) < 0) throw Error("project_summaries_invalid");
143
424
  return {
144
- display_name: C(String(t.display_name ?? ""), "project_name"),
425
+ display_name: F(String(t.display_name ?? ""), "project_name"),
145
426
  existing_memory_count: Number(t.existing_memory_count)
146
427
  };
147
428
  });
148
429
  }
149
430
  //#endregion
150
431
  //#region src/recipient-reviewed-intent.ts
151
- var O = 1, k = class extends Error {
432
+ var Ve = 1, L = class extends Error {
152
433
  code;
153
434
  constructor(e) {
154
435
  super(e), this.name = "RecipientReviewedIntentError", this.code = e;
155
436
  }
156
- }, A = /[\p{Cc}\p{Cf}]/u, te = 100, ne = 64 * 1024;
157
- function j() {
158
- throw new k("recipient_reviewed_intent_invalid");
437
+ }, He = /[\p{Cc}\p{Cf}]/u, Ue = 100, We = 65536;
438
+ function R() {
439
+ throw new L("recipient_reviewed_intent_invalid");
159
440
  }
160
- function M(e) {
161
- return (!e || typeof e != "object" || Array.isArray(e)) && j(), e;
441
+ function z(e) {
442
+ return (!e || typeof e != "object" || Array.isArray(e)) && R(), e;
162
443
  }
163
- function N(e, t) {
164
- Object.keys(e).some((e) => !t.includes(e)) && j();
444
+ function B(e, t) {
445
+ Object.keys(e).some((e) => !t.includes(e)) && R();
165
446
  }
166
- function P(e, t) {
167
- return (typeof e != "string" || !e || e !== e.trim() || e.length > t || A.test(e)) && j(), e;
447
+ function V(e, t) {
448
+ return (typeof e != "string" || !e || e !== e.trim() || e.length > t || He.test(e)) && R(), e;
168
449
  }
169
- function re(e) {
170
- (typeof e != "string" || A.test(e)) && j();
450
+ function Ge(e) {
451
+ (typeof e != "string" || He.test(e)) && R();
171
452
  let t = e.trim().replace(/\s+/gu, " ");
172
- return (!t || t.length > 256) && j(), t;
453
+ return (!t || t.length > 256) && R(), t;
173
454
  }
174
- function ie(e) {
175
- typeof e != "string" && j();
455
+ function Ke(e) {
456
+ typeof e != "string" && R();
176
457
  try {
177
- return C(e, "identity_display_name");
458
+ return F(e, "identity_display_name");
178
459
  } catch {
179
- return j();
460
+ return R();
180
461
  }
181
462
  }
182
- function ae(e) {
183
- return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && j(), e;
463
+ function qe(e) {
464
+ return (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) && R(), e;
184
465
  }
185
- function oe(e, t) {
466
+ function Je(e, t) {
186
467
  return e < t ? -1 : +(e > t);
187
468
  }
188
- function se(e) {
469
+ function Ye(e) {
189
470
  return e.kind === "direct" ? "direct" : `team\u0000${e.teamId}`;
190
471
  }
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, [
472
+ function Xe(e) {
473
+ let t = z(e);
474
+ return t.kind === "direct" ? (B(t, ["kind"]), { kind: "direct" }) : (t.kind !== "team" && R(), B(t, [
194
475
  "kind",
195
476
  "teamId",
196
477
  "displayName"
197
478
  ]), {
198
479
  kind: "team",
199
- teamId: P(t.teamId, 256),
200
- displayName: re(t.displayName)
480
+ teamId: V(t.teamId, 256),
481
+ displayName: Ge(t.displayName)
201
482
  });
202
483
  }
203
- function le(e) {
204
- let t = M(e);
205
- N(t, [
484
+ function Ze(e) {
485
+ let t = z(e);
486
+ B(t, [
206
487
  "canonicalProjectIdentity",
207
488
  "displayName",
208
489
  "existingMemoryCount",
209
490
  "futureMemoriesShared",
210
491
  "sources"
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),
492
+ ]), (t.futureMemoriesShared !== !0 || !Array.isArray(t.sources) || !t.sources.length) && R();
493
+ let n = t.sources.map(Xe).toSorted((e, t) => Je(Ye(e), Ye(t)));
494
+ return new Set(n.map(Ye)).size !== n.length && R(), {
495
+ canonicalProjectIdentity: V(t.canonicalProjectIdentity, 512),
496
+ displayName: Ge(t.displayName),
497
+ existingMemoryCount: qe(t.existingMemoryCount),
217
498
  futureMemoriesShared: !0,
218
499
  sources: n
219
500
  };
220
501
  }
221
- function ue(e) {
222
- let t = M(e);
223
- return N(t, [
502
+ function Qe(e) {
503
+ let t = z(e);
504
+ return B(t, [
224
505
  "canonicalProjectIdentity",
225
506
  "displayName",
226
507
  "existingMemoryCount"
227
508
  ]), {
228
- canonicalProjectIdentity: P(t.canonicalProjectIdentity, 512),
229
- displayName: re(t.displayName),
230
- existingMemoryCount: ae(t.existingMemoryCount)
509
+ canonicalProjectIdentity: V(t.canonicalProjectIdentity, 512),
510
+ displayName: Ge(t.displayName),
511
+ existingMemoryCount: qe(t.existingMemoryCount)
231
512
  };
232
513
  }
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(), {
514
+ function $e(e) {
515
+ (!Array.isArray(e.projects) || !Array.isArray(e.excludedProjects) || e.projects.length > Ue) && R();
516
+ let t = e.projects.map(Ze).toSorted((e, t) => Je(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), n = e.excludedProjects.map(Qe).toSorted((e, t) => Je(e.canonicalProjectIdentity, t.canonicalProjectIdentity)), r = t.map((e) => e.canonicalProjectIdentity), i = n.map((e) => e.canonicalProjectIdentity);
517
+ return (new Set(r).size !== r.length || new Set(i).size !== i.length || i.some((e) => r.includes(e))) && R(), {
237
518
  projects: t,
238
519
  excludedProjects: n
239
520
  };
240
521
  }
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");
522
+ function et(e, t) {
523
+ 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 L("recipient_invite_intent_mismatch");
243
524
  }
244
- function pe(e, t) {
245
- let n = M(e);
246
- n.version !== 1 && j();
247
- let r = de(n), i;
525
+ function tt(e, t) {
526
+ let n = z(e);
527
+ n.version !== 1 && R();
528
+ let r = $e(n), i;
248
529
  if (n.journey === "team") {
249
- N(n, [
530
+ B(n, [
250
531
  "version",
251
532
  "journey",
252
533
  "team",
253
534
  "projects",
254
535
  "excludedProjects"
255
536
  ]);
256
- let e = M(n.team);
257
- N(e, [
537
+ let e = z(n.team);
538
+ B(e, [
258
539
  "teamId",
259
540
  "displayName",
260
541
  "futureProjectsInherit"
261
- ]), e.futureProjectsInherit !== !0 && j(), i = {
542
+ ]), e.futureProjectsInherit !== !0 && R(), i = {
262
543
  version: 1,
263
544
  journey: "team",
264
545
  team: {
265
- teamId: P(e.teamId, 256),
266
- displayName: re(e.displayName),
546
+ teamId: V(e.teamId, 256),
547
+ displayName: Ge(e.displayName),
267
548
  futureProjectsInherit: !0
268
549
  },
269
550
  ...r
270
551
  };
271
552
  } else if (n.journey === "add_device") {
272
- N(n, [
553
+ B(n, [
273
554
  "version",
274
555
  "journey",
275
556
  "targetIdentity",
276
557
  "projects",
277
558
  "excludedProjects"
278
559
  ]);
279
- let e = M(n.targetIdentity);
280
- N(e, ["identityId", "displayName"]), i = {
560
+ let e = z(n.targetIdentity);
561
+ B(e, ["identityId", "displayName"]), i = {
281
562
  version: 1,
282
563
  journey: "add_device",
283
564
  targetIdentity: {
284
- identityId: P(e.identityId, 256),
285
- displayName: ie(e.displayName)
565
+ identityId: V(e.identityId, 256),
566
+ displayName: Ke(e.displayName)
286
567
  },
287
568
  ...r
288
569
  };
289
- } else j();
290
- return t && fe(i, t), new TextEncoder().encode(F(i)).byteLength > ne && j(), i;
570
+ } else R();
571
+ return t && et(i, t), new TextEncoder().encode(H(i)).byteLength > We && R(), i;
291
572
  }
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";
573
+ function H(e) {
574
+ return Array.isArray(e) ? `[${e.map(H).join(",")}]` : e && typeof e == "object" ? `{${Object.entries(e).toSorted(([e], [t]) => Je(e, t)).map(([e, t]) => `${JSON.stringify(e)}:${H(t)}`).join(",")}}` : JSON.stringify(e) ?? "null";
294
575
  }
295
- function me(e, t) {
296
- return F(pe(e, t));
576
+ function nt(e, t) {
577
+ return H(tt(e, t));
297
578
  }
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);
579
+ async function rt(e, t) {
580
+ let n = nt(e, t), r = new TextEncoder().encode(`recipient-reviewed-intent-v1\n${n}`), i = await globalThis.crypto.subtle.digest("SHA-256", r);
300
581
  return Array.from(new Uint8Array(i), (e) => e.toString(16).padStart(2, "0")).join("");
301
582
  }
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");
583
+ async function it(e, t) {
584
+ let n = tt(e, t.target);
585
+ if (await rt(n) !== t.digest) throw new L("recipient_invite_intent_mismatch");
305
586
  return n;
306
587
  }
307
- async function _e(e, t) {
588
+ async function at(e, t) {
308
589
  if (!e) throw Error("recipient_invite_review_unavailable");
309
590
  let n;
310
591
  try {
@@ -313,21 +594,21 @@ async function _e(e, t) {
313
594
  throw Error("recipient_invite_review_unavailable");
314
595
  }
315
596
  try {
316
- let r = pe(n, t.target);
317
- if (F(r) !== e) throw Error("recipient_invite_review_unavailable");
318
- return await ge(r, t);
597
+ let r = tt(n, t.target);
598
+ if (H(r) !== e) throw Error("recipient_invite_review_unavailable");
599
+ return await it(r, t);
319
600
  } catch (e) {
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");
601
+ throw e instanceof L && e.code === "recipient_invite_intent_mismatch" || e instanceof Error && e.message === "recipient_invite_review_unavailable" ? e : Error("recipient_invite_review_unavailable");
321
602
  }
322
603
  }
323
604
  //#endregion
324
605
  //#region src/sync-fingerprint.ts
325
- function ve(e) {
606
+ function ot(e) {
326
607
  return t("sha256").update(e, "utf-8").digest("hex");
327
608
  }
328
609
  //#endregion
329
- //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/compose.js
330
- var ye = (e, t, n) => (r, i) => {
610
+ //#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/compose.js
611
+ var st = (e, t, n) => (r, i) => {
331
612
  let a = -1;
332
613
  return o(0);
333
614
  async function o(s) {
@@ -343,40 +624,45 @@ var ye = (e, t, n) => (r, i) => {
343
624
  else r.finalized === !1 && n && (c = await n(r));
344
625
  return c && (r.finalized === !1 || l) && (r.res = c), r;
345
626
  }
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, {
627
+ }, ct = /* @__PURE__ */ Symbol(), lt = (e, t) => new Response(e, { headers: { "Content-Type": t.replace(/^[^;]+/, (e) => e.toLowerCase()) } }).formData(), ut = 32, dt = 1e4, ft = (e) => "headers" in e, pt = async (e, t = /* @__PURE__ */ Object.create(null)) => {
628
+ let { all: n = !1, dot: r = !1 } = t, i = (ft(e) ? e.headers : e.raw.headers).get("Content-Type")?.split(";")[0].trim().toLowerCase();
629
+ return i === "multipart/form-data" || i === "application/x-www-form-urlencoded" ? mt(e, {
349
630
  all: n,
350
631
  dot: r
351
632
  }) : {};
352
633
  };
353
- async function Se(e, t) {
354
- let n = await e.formData();
355
- return n ? Ce(n, t) : {};
356
- }
357
- function Ce(e, t) {
358
- let n = /* @__PURE__ */ Object.create(null);
634
+ async function mt(e, t) {
635
+ if (!ft(e) && e.bodyCache.formData) return ht(await e.bodyCache.formData, t);
636
+ let n = ft(e) ? e.headers : e.raw.headers, r = lt(await e.arrayBuffer(), n.get("Content-Type") || "");
637
+ ft(e) || (e.bodyCache.formData = r);
638
+ let i = await r;
639
+ return i ? ht(i, t) : {};
640
+ }
641
+ function ht(e, t) {
642
+ let n = /* @__PURE__ */ Object.create(null), r = { count: 0 };
359
643
  return e.forEach((e, r) => {
360
- t.all || r.endsWith("[]") ? we(n, r, e) : n[r] = e;
644
+ t.all || r.endsWith("[]") ? gt(n, r, e) : n[r] = e;
361
645
  }), t.dot && Object.entries(n).forEach(([e, t]) => {
362
- e.includes(".") && (Te(n, e, t), delete n[e]);
646
+ e.includes(".") && (_t(n, e, t, r), delete n[e]);
363
647
  }), n;
364
648
  }
365
- var we = (e, t, n) => {
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];
367
- }, Te = (e, t, n) => {
649
+ var gt = (e, t, n) => {
650
+ e[t] === void 0 ? e[t] = t.endsWith("[]") ? [n] : n : Array.isArray(e[t]) ? e[t].push(n) : e[t] = [e[t], n];
651
+ }, _t = (e, t, n, r) => {
368
652
  if (/(?:^|\.)__proto__\./.test(t)) return;
369
- let r = e, i = t.split(".");
370
- i.forEach((e, t) => {
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]);
653
+ let i = e, a = t.split(".", ut + 2);
654
+ a.length > ut + 1 && vt(), a.forEach((e, t) => {
655
+ t === a.length - 1 ? i[e] = n : ((!i[e] || typeof i[e] != "object" || Array.isArray(i[e]) || i[e] instanceof File) && (r.count++ >= dt && vt(), i[e] = /* @__PURE__ */ Object.create(null)), i = i[e]);
372
656
  });
373
- }, Ee = (e) => {
657
+ }, vt = () => {
658
+ throw Error("Nesting limit exceeded");
659
+ }, yt = (e) => {
374
660
  let t = e.split("/");
375
661
  return t[0] === "" && t.shift(), t;
376
- }, De = (e) => {
377
- let { groups: t, path: n } = Oe(e);
378
- return ke(Ee(n), t);
379
- }, Oe = (e) => {
662
+ }, bt = (e) => {
663
+ let { groups: t, path: n } = xt(e);
664
+ return St(yt(n), t);
665
+ }, xt = (e) => {
380
666
  let t = [];
381
667
  return e = e.replace(/\{[^}]+\}/g, (e, n) => {
382
668
  let r = `@${n}`;
@@ -385,7 +671,7 @@ var we = (e, t, n) => {
385
671
  groups: t,
386
672
  path: e
387
673
  };
388
- }, ke = (e, t) => {
674
+ }, St = (e, t) => {
389
675
  for (let n = t.length - 1; n >= 0; n--) {
390
676
  let [r] = t[n];
391
677
  for (let i = e.length - 1; i >= 0; i--) if (e[i].includes(r)) {
@@ -394,12 +680,12 @@ var we = (e, t, n) => {
394
680
  }
395
681
  }
396
682
  return e;
397
- }, I = {}, Ae = (e, t) => {
683
+ }, Ct = {}, wt = (e, t) => {
398
684
  if (e === "*") return "*";
399
685
  let n = e.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/);
400
686
  if (n) {
401
687
  let r = `${e}#${t}`;
402
- return I[r] || (n[2] ? I[r] = t && t[0] !== ":" && t[0] !== "*" ? [
688
+ return Ct[r] || (Ct[r] = n[2] ? t && t[0] !== ":" && t[0] !== "*" ? [
403
689
  r,
404
690
  n[1],
405
691
  RegExp(`^${n[2]}(?=/${t})`)
@@ -407,14 +693,14 @@ var we = (e, t, n) => {
407
693
  e,
408
694
  n[1],
409
695
  RegExp(`^${n[2]}$`)
410
- ] : I[r] = [
696
+ ] : [
411
697
  e,
412
698
  n[1],
413
699
  !0
414
- ]), I[r];
700
+ ]), Ct[r];
415
701
  }
416
702
  return null;
417
- }, je = (e, t) => {
703
+ }, Tt = (e, t) => {
418
704
  try {
419
705
  return t(e);
420
706
  } catch {
@@ -426,58 +712,64 @@ var we = (e, t, n) => {
426
712
  }
427
713
  });
428
714
  }
429
- }, Me = (e) => je(e, decodeURI), Ne = (e) => {
715
+ }, Et = (e) => Tt(e, decodeURI), Dt = (e) => {
430
716
  let t = e.url, n = t.indexOf("/", t.indexOf(":") + 4), r = n;
431
717
  for (; r < t.length; r++) {
432
718
  let e = t.charCodeAt(r);
433
719
  if (e === 37) {
434
720
  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);
435
- return Me(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
436
- } else if (e === 63 || e === 35) break;
721
+ return Et(o.includes("%25") ? o.replace(/%25/g, "%2525") : o);
722
+ }
723
+ if (e === 63 || e === 35) break;
437
724
  }
438
725
  return t.slice(n, r);
439
- }, Pe = (e) => {
440
- let t = Ne(e);
726
+ }, Ot = (e) => {
727
+ let t = Dt(e);
441
728
  return t.length > 1 && t.at(-1) === "/" ? t.slice(0, -1) : t;
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) => {
729
+ }, U = (e, t, ...n) => (n.length && (t = U(t, ...n)), `${e?.[0] === "/" ? "" : "/"}${e}${t === "/" ? "" : `${e?.at(-1) === "/" ? "" : "/"}${t?.[0] === "/" ? t.slice(1) : t}`}`), kt = (e) => {
443
730
  if (e.charCodeAt(e.length - 1) !== 63 || !e.includes(":")) return null;
444
731
  let t = e.split("/"), n = [], r = "";
445
732
  return t.forEach((e) => {
446
733
  if (e !== "" && !/\:/.test(e)) r += "/" + e;
447
- else if (/\:/.test(e)) if (/\?/.test(e)) {
448
- n.length === 0 && r === "" ? n.push("/") : n.push(r);
449
- let t = e.replace("?", "");
450
- r += "/" + t, n.push(r);
451
- } else r += "/" + e;
734
+ else if (/\:/.test(e)) {
735
+ if (e.charCodeAt(e.length - 1) === 63) {
736
+ n.length === 0 && r === "" ? n.push("/") : n.push(r);
737
+ let t = e.slice(0, -1);
738
+ r += "/" + t, n.push(r);
739
+ } else r += "/" + e;
740
+ }
452
741
  }), n.filter((e, t, n) => n.indexOf(e) === t);
453
- }, Ie = (e) => /[%+]/.test(e) ? (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), e.indexOf("%") === -1 ? e : je(e, Be)) : e, Le = (e, t, n) => {
454
- let r;
455
- if (!n && t && !/[%+]/.test(t)) {
742
+ }, At = (e) => e.indexOf("%") === -1 ? e : Tt(e, Ft), jt = (e) => (e.indexOf("+") !== -1 && (e = e.replace(/\+/g, " ")), At(e)), Mt = (e, t, n) => {
743
+ let r = e.indexOf("#", 8);
744
+ r !== -1 && (e = e.slice(0, r));
745
+ let i;
746
+ if (!n && t && t.indexOf("%") === -1 && t.indexOf("+") === -1) {
456
747
  let n = e.indexOf("?", 8);
457
748
  if (n === -1) return;
458
749
  for (e.startsWith(t, n + 1) || (n = e.indexOf(`&${t}`, n + 1)); n !== -1;) {
459
750
  let r = e.charCodeAt(n + t.length + 1);
460
751
  if (r === 61) {
461
752
  let r = n + t.length + 2, i = e.indexOf("&", r);
462
- return Ie(e.slice(r, i === -1 ? void 0 : i));
463
- } else if (r == 38 || isNaN(r)) return "";
753
+ return jt(e.slice(r, i === -1 ? void 0 : i));
754
+ }
755
+ if (r == 38 || isNaN(r)) return "";
464
756
  n = e.indexOf(`&${t}`, n + 1);
465
757
  }
466
- if (r = /[%+]/.test(e), !r) return;
758
+ if (i = /[%+]/.test(e), !i) return;
467
759
  }
468
- let i = {};
469
- r ??= /[%+]/.test(e);
470
- let a = e.indexOf("?", 8);
471
- for (; a !== -1;) {
472
- let t = e.indexOf("&", a + 1), o = e.indexOf("=", a);
473
- o > t && t !== -1 && (o = -1);
474
- let s = e.slice(a + 1, o === -1 ? t === -1 ? void 0 : t : o);
475
- if (r && (s = Ie(s)), a = t, s === "") continue;
760
+ let a = /* @__PURE__ */ Object.create(null);
761
+ i ??= /[%+]/.test(e);
762
+ let o = e.indexOf("?", 8);
763
+ for (; o !== -1;) {
764
+ let t = e.indexOf("&", o + 1), r = e.indexOf("=", o);
765
+ r > t && t !== -1 && (r = -1);
766
+ let s = e.slice(o + 1, r === -1 ? t === -1 ? void 0 : t : r);
767
+ if (i && (s = jt(s)), o = t, s === "") continue;
476
768
  let 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;
769
+ r === -1 ? c = "" : (c = e.slice(r + 1, t === -1 ? void 0 : t), i && (c = jt(c))), n ? (a[s] && Array.isArray(a[s]) || (a[s] = []), a[s].push(c)) : a[s] ??= c;
478
770
  }
479
- return t ? i[t] : i;
480
- }, Re = Le, ze = (e, t) => Le(e, t, !0), Be = decodeURIComponent, Ve = (e) => je(e, Be), He = class {
771
+ return t ? a[t] : a;
772
+ }, Nt = Mt, Pt = (e, t) => Mt(e, t, !0), Ft = decodeURIComponent, It = class {
481
773
  raw;
482
774
  #e;
483
775
  #t;
@@ -485,20 +777,20 @@ var we = (e, t, n) => {
485
777
  path;
486
778
  bodyCache = {};
487
779
  constructor(e, t = "/", n = [[]]) {
488
- this.raw = e, this.path = t, this.#t = n, this.#e = {};
780
+ this.raw = e, this.path = t, this.#t = n;
489
781
  }
490
782
  param(e) {
491
783
  return e ? this.#n(e) : this.#r();
492
784
  }
493
785
  #n(e) {
494
- let t = this.#t[0][this.routeIndex][1][e], n = this.#i(t);
495
- return n && /\%/.test(n) ? Ve(n) : n;
786
+ let t = this.#t[0][this.routeIndex]?.[1][e], n = this.#i(t);
787
+ return n && At(n);
496
788
  }
497
789
  #r() {
498
- let e = {}, t = Object.keys(this.#t[0][this.routeIndex][1]);
790
+ let e = {}, t = Object.keys(this.#t[0][this.routeIndex]?.[1] ?? {});
499
791
  for (let n of t) {
500
792
  let t = this.#i(this.#t[0][this.routeIndex][1][n]);
501
- t !== void 0 && (e[n] = /\%/.test(t) ? Ve(t) : t);
793
+ t !== void 0 && (e[n] = At(t));
502
794
  }
503
795
  return e;
504
796
  }
@@ -506,26 +798,26 @@ var we = (e, t, n) => {
506
798
  return this.#t[1] ? this.#t[1][e] : e;
507
799
  }
508
800
  query(e) {
509
- return Re(this.url, e);
801
+ return Nt(this.url, e);
510
802
  }
511
803
  queries(e) {
512
- return ze(this.url, e);
804
+ return Pt(this.url, e);
513
805
  }
514
806
  header(e) {
515
807
  if (e) return this.raw.headers.get(e) ?? void 0;
516
- let t = {};
808
+ let t = /* @__PURE__ */ Object.create(null);
517
809
  return this.raw.headers.forEach((e, n) => {
518
810
  t[n] = e;
519
811
  }), t;
520
812
  }
521
813
  async parseBody(e) {
522
- return xe(this, e);
814
+ return pt(this, e);
523
815
  }
524
816
  #a = (e) => {
525
817
  let { bodyCache: t, raw: n } = this, r = t[e];
526
818
  if (r) return r;
527
- let i = Object.keys(t)[0];
528
- return i ? t[i].then((t) => (i === "json" && (t = JSON.stringify(t)), new Response(t)[e]())) : t[e] = n[e]();
819
+ for (let n in t) return t[n].then((t) => (n === "json" && (t = JSON.stringify(t)), new Response(t)[e]()));
820
+ return t[e] = n[e]();
529
821
  };
530
822
  json() {
531
823
  return this.#a("text").then((e) => JSON.parse(e));
@@ -546,10 +838,10 @@ var we = (e, t, n) => {
546
838
  return this.#a("formData");
547
839
  }
548
840
  addValidatedData(e, t) {
549
- this.#e[e] = t;
841
+ (this.#e ??= {})[e] = t;
550
842
  }
551
843
  valid(e) {
552
- return this.#e[e];
844
+ return this.#e?.[e];
553
845
  }
554
846
  get url() {
555
847
  return this.raw.url;
@@ -557,7 +849,7 @@ var we = (e, t, n) => {
557
849
  get method() {
558
850
  return this.raw.method;
559
851
  }
560
- get [be]() {
852
+ get [ct]() {
561
853
  return this.#t;
562
854
  }
563
855
  get matchedRoutes() {
@@ -566,14 +858,14 @@ var we = (e, t, n) => {
566
858
  get routePath() {
567
859
  return this.#t[0].map(([[, e]]) => e)[this.routeIndex].path;
568
860
  }
569
- }, Ue = {
861
+ }, Lt = {
570
862
  Stringify: 1,
571
863
  BeforeStream: 2,
572
864
  Stream: 3
573
- }, We = (e, t) => {
865
+ }, Rt = (e, t) => {
574
866
  let n = new String(e);
575
867
  return n.isEscaped = !0, n.callbacks = t, n;
576
- }, Ge = async (e, t, n, r, i) => {
868
+ }, zt = async (e, t, n, r, i) => {
577
869
  typeof e == "object" && !(e instanceof String) && (e instanceof Promise || (e = e.toString()), e instanceof Promise && (e = await e));
578
870
  let a = e.callbacks;
579
871
  if (!a?.length) return Promise.resolve(e);
@@ -582,12 +874,12 @@ var we = (e, t, n) => {
582
874
  phase: t,
583
875
  buffer: i,
584
876
  context: r
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) => ({
877
+ }))).then((e) => Promise.all(e.filter(Boolean).map((e) => zt(e, t, !1, r, i))).then(() => i[0]));
878
+ return n ? Rt(await o, a) : o;
879
+ }, Bt = "text/plain; charset=UTF-8", Vt = (e, t) => ({
588
880
  "Content-Type": e,
589
881
  ...t
590
- }), R = (e, t) => new Response(e, t), Je = class {
882
+ }), W = (e, t) => new Response(e, t), Ht = class {
591
883
  #e;
592
884
  #t;
593
885
  env = {};
@@ -607,7 +899,7 @@ var we = (e, t, n) => {
607
899
  this.#e = e, t && (this.#i = t.executionCtx, this.env = t.env, this.#c = t.notFoundHandler, this.#d = t.path, this.#u = t.matchResult);
608
900
  }
609
901
  get req() {
610
- return this.#t ??= new He(this.#e, this.#d, this.#u), this.#t;
902
+ return this.#t ??= new It(this.#e, this.#d, this.#u), this.#t;
611
903
  }
612
904
  get event() {
613
905
  if (this.#i && "respondWith" in this.#i) return this.#i;
@@ -618,16 +910,18 @@ var we = (e, t, n) => {
618
910
  throw Error("This context has no ExecutionContext");
619
911
  }
620
912
  get res() {
621
- return this.#a ||= R(null, { headers: this.#l ??= new Headers() });
913
+ return this.#a ||= W(null, { headers: this.#l ??= new Headers() });
622
914
  }
623
915
  set res(e) {
624
916
  if (this.#a && e) {
625
- e = R(e.body, e);
626
- for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") if (t === "set-cookie") {
627
- let t = this.#a.headers.getSetCookie();
628
- e.headers.delete("set-cookie");
629
- for (let n of t) e.headers.append("set-cookie", n);
630
- } else e.headers.set(t, n);
917
+ e = W(e.body, e);
918
+ for (let [t, n] of this.#a.headers.entries()) if (t !== "content-type") {
919
+ if (t === "set-cookie") {
920
+ let t = this.#a.headers.getSetCookie();
921
+ e.headers.delete("set-cookie");
922
+ for (let n of t) e.headers.append("set-cookie", n);
923
+ } else e.headers.set(t, n);
924
+ }
631
925
  }
632
926
  this.#a = e, this.finalized = !0;
633
927
  }
@@ -638,7 +932,7 @@ var we = (e, t, n) => {
638
932
  this.#s = e;
639
933
  };
640
934
  header = (e, t, n) => {
641
- this.finalized && (this.#a = R(this.#a.body, this.#a));
935
+ this.finalized && (this.#a = W(this.#a.body, this.#a));
642
936
  let r = this.#a ? this.#a.headers : this.#l ??= new Headers();
643
937
  t === void 0 ? r.delete(e) : n?.append ? r.append(e, t) : r.set(e, t);
644
938
  };
@@ -653,54 +947,68 @@ var we = (e, t, n) => {
653
947
  return this.#n ? Object.fromEntries(this.#n) : {};
654
948
  }
655
949
  #f(e, t, n) {
656
- let r = this.#a ? new Headers(this.#a.headers) : this.#l ?? new Headers();
657
- if (typeof t == "object" && "headers" in t) {
658
- let e = t.headers instanceof Headers ? t.headers : new Headers(t.headers);
659
- for (let [t, n] of e) t.toLowerCase() === "set-cookie" ? r.append(t, n) : r.set(t, n);
660
- }
661
- if (n) for (let [e, t] of Object.entries(n)) if (typeof t == "string") r.set(e, t);
662
- else {
663
- r.delete(e);
664
- for (let n of t) r.append(e, n);
950
+ let r = this.#a ? new Headers(this.#a.headers) : this.#l;
951
+ if (typeof t == "object" && t.headers) {
952
+ r ??= new Headers();
953
+ for (let [e, n] of new Headers(t.headers)) e === "set-cookie" ? r.append(e, n) : r.set(e, n);
954
+ }
955
+ if (n) {
956
+ if (!r) {
957
+ let e = 0;
958
+ for (let t in n) if (++e > 1 || typeof n[t] != "string") {
959
+ r = new Headers();
960
+ break;
961
+ }
962
+ }
963
+ if (r) for (let e in n) {
964
+ let t = n[e];
965
+ if (typeof t == "string") r.set(e, t);
966
+ else {
967
+ r.delete(e);
968
+ for (let n of t) r.append(e, n);
969
+ }
970
+ }
665
971
  }
666
- return R(e, {
972
+ return W(e, {
667
973
  status: typeof t == "number" ? t : t?.status ?? this.#r,
668
- headers: r
974
+ headers: r ?? n
669
975
  });
670
976
  }
671
977
  newResponse = (...e) => this.#f(...e);
672
978
  body = (e, t, n) => this.#f(e, t, 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));
979
+ text = (e, t, n) => !this.#l && !this.#r && !t && !n && !this.finalized ? new Response(e) : this.#f(e, t, Vt(Bt, n));
980
+ json = (e, t, n) => this.#f(JSON.stringify(e), t, Vt("application/json", n));
675
981
  html = (e, t, n) => {
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);
982
+ let r = (e) => this.#f(e, t, Vt("text/html; charset=UTF-8", n));
983
+ return typeof e == "object" ? zt(e, Lt.Stringify, !1, {}).then(r) : r(e);
678
984
  };
679
985
  redirect = (e, t) => {
680
986
  let n = String(e);
681
987
  return this.header("Location", /[^\x00-\xFF]/.test(n) ? encodeURI(n) : n), this.newResponse(null, t ?? 302);
682
988
  };
683
- notFound = () => (this.#c ??= () => R(), this.#c(this));
684
- }, Ye = [
989
+ notFound = () => (this.#c ??= () => W(), this.#c(this));
990
+ }, Ut = [
685
991
  "get",
686
992
  "post",
687
993
  "put",
688
994
  "delete",
689
995
  "options",
690
- "patch"
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) => {
996
+ "patch",
997
+ "query"
998
+ ], Wt = "Can not add a route since the matcher is already built.", Gt = class extends Error {}, Kt = "__COMPOSED_HANDLER", qt = (e) => e.text("404 Not Found", 404), Jt = (e, t) => {
692
999
  if ("getResponse" in e) {
693
1000
  let n = e.getResponse();
694
1001
  return t.newResponse(n.body, n);
695
1002
  }
696
1003
  return console.error(e), t.text("Internal Server Error", 500);
697
- }, tt = class e {
1004
+ }, Yt = class e {
698
1005
  get;
699
1006
  post;
700
1007
  put;
701
1008
  delete;
702
1009
  options;
703
1010
  patch;
1011
+ query;
704
1012
  all;
705
1013
  on;
706
1014
  use;
@@ -710,7 +1018,7 @@ var we = (e, t, n) => {
710
1018
  #e = "/";
711
1019
  routes = [];
712
1020
  constructor(e = {}) {
713
- [...Ye, "all"].forEach((e) => {
1021
+ [...Ut, "all"].forEach((e) => {
714
1022
  this[e] = (t, ...n) => (typeof t == "string" ? this.#e = t : this.#r(e, this.#e, t), n.forEach((t) => {
715
1023
  this.#r(e, this.#e, t);
716
1024
  }), this);
@@ -726,7 +1034,7 @@ var we = (e, t, n) => {
726
1034
  this.#r("ALL", this.#e, e);
727
1035
  }), this);
728
1036
  let { strict: t, ...n } = e;
729
- Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Ne : Pe;
1037
+ Object.assign(this, n), this.getPath = t ?? !0 ? e.getPath ?? Dt : Ot;
730
1038
  }
731
1039
  #t() {
732
1040
  let t = new e({
@@ -735,18 +1043,18 @@ var we = (e, t, n) => {
735
1043
  });
736
1044
  return t.errorHandler = this.errorHandler, t.#n = this.#n, t.routes = this.routes, t;
737
1045
  }
738
- #n = $e;
739
- errorHandler = et;
1046
+ #n = qt;
1047
+ errorHandler = Jt;
740
1048
  route(e, t) {
741
1049
  let n = this.basePath(e);
742
1050
  return t.routes.map((e) => {
743
1051
  let r;
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);
1052
+ t.errorHandler === Jt ? r = e.handler : (r = async (n, r) => (await st([], t.errorHandler)(n, () => e.handler(n, r))).res, r[Kt] = e.handler), n.#r(e.method, e.path, r, e.basePath);
745
1053
  }), this;
746
1054
  }
747
1055
  basePath(e) {
748
1056
  let t = this.#t();
749
- return t._basePath = L(this._basePath, e), t;
1057
+ return t._basePath = U(this._basePath, e), t;
750
1058
  }
751
1059
  onError = (e) => (this.errorHandler = e, this);
752
1060
  notFound = (e) => (this.#n = e, this);
@@ -764,21 +1072,21 @@ var we = (e, t, n) => {
764
1072
  return [e.env, t];
765
1073
  };
766
1074
  return r ||= (() => {
767
- let t = L(this._basePath, e), n = t === "/" ? 0 : t.length;
1075
+ let t = U(this._basePath, e), n = t === "/" ? 0 : t.length;
768
1076
  return (e) => {
769
1077
  let t = new URL(e.url);
770
1078
  return t.pathname = this.getPath(e).slice(n) || "/", new Request(t, e);
771
1079
  };
772
- })(), this.#r("ALL", L(e, "*"), async (e, n) => {
1080
+ })(), this.#r("ALL", U(e, "*"), async (e, n) => {
773
1081
  let i = await t(r(e.req.raw), ...a(e));
774
1082
  if (i) return i;
775
1083
  await n();
776
1084
  }), this;
777
1085
  }
778
1086
  #r(e, t, n, r) {
779
- e = e.toUpperCase(), t = L(this._basePath, t);
1087
+ e = e.toUpperCase(), t = U(this._basePath, t);
780
1088
  let i = {
781
- basePath: r === void 0 ? this._basePath : L(this._basePath, r),
1089
+ basePath: r === void 0 ? this._basePath : U(this._basePath, r),
782
1090
  path: t,
783
1091
  method: e,
784
1092
  handler: n
@@ -791,7 +1099,7 @@ var we = (e, t, n) => {
791
1099
  }
792
1100
  #a(e, t, n, r) {
793
1101
  if (r === "HEAD") return (async () => new Response(null, await this.#a(e, t, n, "GET")))();
794
- let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Je(e, {
1102
+ let i = this.getPath(e, { env: n }), a = this.router.match(r, i), o = new Ht(e, {
795
1103
  path: i,
796
1104
  matchResult: a,
797
1105
  env: n,
@@ -809,7 +1117,7 @@ var we = (e, t, n) => {
809
1117
  }
810
1118
  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);
811
1119
  }
812
- let s = ye(a[0], this.errorHandler, this.#n);
1120
+ let s = st(a[0], this.errorHandler, this.#n);
813
1121
  return (async () => {
814
1122
  try {
815
1123
  let e = await s(o);
@@ -821,98 +1129,103 @@ var we = (e, t, n) => {
821
1129
  })();
822
1130
  }
823
1131
  fetch = (e, ...t) => this.#a(e, t[1], t[0], e.method);
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));
1132
+ 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${U("/", e)}`, t), n, r));
825
1133
  fire = () => {
826
1134
  addEventListener("fetch", (e) => {
827
1135
  e.respondWith(this.#a(e.request, e, void 0, e.request.method));
828
1136
  });
829
1137
  };
830
- }, nt = [];
831
- function rt(e, t) {
1138
+ }, G = () => /* @__PURE__ */ Object.create(null), Xt = [];
1139
+ function Zt(e, t) {
832
1140
  let n = this.buildAllMatchers(), r = ((e, t) => {
833
1141
  let r = n[e] || n.ALL, i = r[2][t];
834
1142
  if (i) return i;
835
1143
  let a = t.match(r[0]);
836
- if (!a) return [[], nt];
1144
+ if (!a) return [[], Xt];
837
1145
  let o = a.indexOf("", 1);
838
1146
  return [r[1][o], a];
839
1147
  });
840
1148
  return this.match = r, r(e, t);
841
1149
  }
842
1150
  //#endregion
843
- //#region ../../node_modules/.pnpm/hono@4.12.26/node_modules/hono/dist/router/reg-exp-router/node.js
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;
1151
+ //#region ../../node_modules/.pnpm/hono@4.13.5/node_modules/hono/dist/router/reg-exp-router/node.js
1152
+ var Qt = "[^/]+", $t = "(?:|/.*)", K = /* @__PURE__ */ Symbol(), en = /* @__PURE__ */ new Set(".\\+*[^]$()");
1153
+ function tn(e, t) {
1154
+ return e.length === 1 ? t.length === 1 ? e < t ? -1 : 1 : -1 : t.length === 1 ? 1 : e === ".*" || e === "(?:|/.*)" ? t === "(?:|/.*)" ? -1 : 1 : t === ".*" || t === "(?:|/.*)" ? -1 : e === "[^/]+" ? 1 : t === "[^/]+" ? -1 : e.length === t.length ? e < t ? -1 : 1 : t.length - e.length;
847
1155
  }
848
- var ot = class e {
1156
+ var nn = class e {
849
1157
  #e;
850
1158
  #t;
851
- #n = /* @__PURE__ */ Object.create(null);
1159
+ #n = G();
852
1160
  insert(t, n, r, i, a) {
853
- if (t.length === 0) {
854
- if (this.#e !== void 0) throw H;
855
- if (a) return;
856
- this.#e = n;
857
- return;
858
- }
859
- let [o, ...s] = t, c = o === "*" ? s.length === 0 ? [
860
- "",
861
- "",
862
- B
863
- ] : [
864
- "",
865
- "",
866
- z
867
- ] : o === "/*" ? [
868
- "",
869
- "",
870
- V
871
- ] : o.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
872
- if (c) {
873
- let t = c[1], n = c[2] || z;
874
- if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)))) throw H;
875
- if (l = this.#n[n], !l) {
876
- if (Object.keys(this.#n).some((e) => e !== B && e !== V)) throw H;
877
- if (a) return;
878
- l = this.#n[n] = new e(), t !== "" && (l.#t = i.varIndex++);
1161
+ let o = this;
1162
+ for (let n = 0, a = t.length; n < a; n++) {
1163
+ let s = t[n], c = s.length === 1 ? s === "*" ? n === a - 1 ? [
1164
+ "",
1165
+ "",
1166
+ ".*"
1167
+ ] : [
1168
+ "",
1169
+ "",
1170
+ Qt
1171
+ ] : null : s === "/*" ? [
1172
+ "",
1173
+ "",
1174
+ $t
1175
+ ] : s.match(/^\:([^\{\}]+)(?:\{(.+)\})?$/), l;
1176
+ if (c) {
1177
+ let t = c[1], n = c[2] || "[^/]+";
1178
+ if (t && c[2] && (n === ".*" || (n = n.replace(/^\((?!\?:)(?=[^)]+\)$)/, "(?:"), /\((?!\?:)/.test(n)) || n.length === 1 && en.has(n))) throw K;
1179
+ if (l = o.#n[n], !l) {
1180
+ if (n !== ".*" && n !== "(?:|/.*)") {
1181
+ for (let e in o.#n) if ((n.length > 1 || e.length > 1) && e !== ".*" && e !== "(?:|/.*)") throw K;
1182
+ }
1183
+ l = o.#n[n] = new e();
1184
+ }
1185
+ t !== "" && (l.#t ??= i.varIndex++, r.push([t, l.#t]));
1186
+ } else if (l = o.#n[s], !l) {
1187
+ for (let e in o.#n) if (e.length > 1 && e !== ".*" && e !== "(?:|/.*)") throw K;
1188
+ l = o.#n[s] = new e();
879
1189
  }
880
- !a && t !== "" && r.push([t, l.#t]);
881
- } else if (l = this.#n[o], !l) {
882
- if (Object.keys(this.#n).some((e) => e.length > 1 && e !== B && e !== V)) throw H;
883
- if (a) return;
884
- l = this.#n[o] = new e();
1190
+ o = l;
885
1191
  }
886
- l.insert(s, n, r, i, a);
1192
+ if (o.#e !== void 0) throw K;
1193
+ o.#e = a ? -1 : n;
887
1194
  }
888
1195
  buildRegExpStr() {
889
- let e = Object.keys(this.#n).sort(at).map((e) => {
890
- let t = this.#n[e];
891
- return (typeof t.#t == "number" ? `(${e})@${t.#t}` : it.has(e) ? `\\${e}` : e) + t.buildRegExpStr();
892
- });
893
- return typeof this.#e == "number" && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
1196
+ let e = Object.keys(this.#n).sort(tn).map((e) => {
1197
+ let t = this.#n[e], n = t.buildRegExpStr();
1198
+ return n === "" ? "" : (typeof t.#t == "number" ? `(${e})@${t.#t}` : en.has(e) ? `\\${e}` : e) + n;
1199
+ }).filter(Boolean);
1200
+ return typeof this.#e == "number" && this.#e !== -1 && e.unshift(`#${this.#e}`), e.length === 0 ? "" : e.length === 1 ? e[0] : "(?:" + e.join("|") + ")";
894
1201
  }
895
- }, st = class {
1202
+ }, rn = class {
896
1203
  #e = { varIndex: 0 };
897
- #t = new ot();
898
- insert(e, t, n) {
899
- let r = [], i = [];
900
- for (let t = 0;;) {
901
- let n = !1;
902
- if (e = e.replace(/\{[^}]+\}/g, (e) => {
903
- let r = `@\\${t}`;
904
- return i[t] = [r, e], t++, n = !0, r;
905
- }), !n) break;
906
- }
907
- let a = e.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
908
- for (let e = i.length - 1; e >= 0; e--) {
909
- let [t] = i[e];
1204
+ #t = new nn();
1205
+ #n = 0;
1206
+ paths = G();
1207
+ insert(e, t) {
1208
+ if (t) {
1209
+ this.#t.insert(e.split(""), 0, [], this.#e, !0);
1210
+ return;
1211
+ }
1212
+ let n = [], r = [], i = e;
1213
+ for (let e = 0;;) {
1214
+ let t = !1;
1215
+ if (i = i.replace(/\{[^}]+\}/g, (n) => {
1216
+ let i = `@\\${e}`;
1217
+ return r[e] = [i, n], e++, t = !0, i;
1218
+ }), !t) break;
1219
+ }
1220
+ let a = i.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
1221
+ for (let e = r.length - 1; e >= 0; e--) {
1222
+ let [t] = r[e];
910
1223
  for (let n = a.length - 1; n >= 0; n--) if (a[n].indexOf(t) !== -1) {
911
- a[n] = a[n].replace(t, i[e][1]);
1224
+ a[n] = a[n].replace(t, r[e][1]);
912
1225
  break;
913
1226
  }
914
1227
  }
915
- return this.#t.insert(a, t, r, this.#e, n), r;
1228
+ this.#t.insert(a, this.#n, n, this.#e, !1), this.paths[e] = [this.#n++, n];
916
1229
  }
917
1230
  buildRegExp() {
918
1231
  let e = this.#t.buildRegExpStr();
@@ -928,111 +1241,72 @@ var ot = class e {
928
1241
  r
929
1242
  ];
930
1243
  }
931
- }, ct = [
932
- /^$/,
933
- [],
934
- /* @__PURE__ */ Object.create(null)
935
- ], lt = /* @__PURE__ */ Object.create(null);
936
- function ut(e) {
937
- return lt[e] ??= RegExp(e === "*" ? "" : `^${e.replace(/\/\*$|([.\\+*[^\]$()])/g, (e, t) => t ? `\\${t}` : "(?:|/.*)")}$`);
938
- }
939
- function dt() {
940
- lt = /* @__PURE__ */ Object.create(null);
941
- }
942
- function ft(e) {
943
- let t = new st(), n = [];
944
- if (e.length === 0) return ct;
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);
946
- for (let e = 0, a = -1, o = r.length; e < o; e++) {
947
- let [o, s, c] = r[e];
948
- o ? i[s] = [c.map(([e]) => [e, /* @__PURE__ */ Object.create(null)]), nt] : a++;
949
- let l;
950
- try {
951
- l = t.insert(s, a, o);
952
- } catch (e) {
953
- throw e === H ? new Ze(s) : e;
954
- }
955
- o || (n[a] = c.map(([e, t]) => {
956
- let n = /* @__PURE__ */ Object.create(null);
957
- for (--t; t >= 0; t--) {
958
- let [e, r] = l[t];
959
- n[e] = r;
960
- }
961
- return [e, n];
962
- }));
963
- }
964
- let [a, o, s] = t.buildRegExp();
965
- for (let e = 0, t = n.length; e < t; e++) for (let t = 0, r = n[e].length; t < r; t++) {
966
- let r = n[e][t]?.[1];
967
- if (!r) continue;
968
- let i = Object.keys(r);
969
- for (let e = 0, t = i.length; e < t; e++) r[i[e]] = s[r[i[e]]];
970
- }
971
- let c = [];
972
- for (let e in o) c[e] = n[o[e]];
973
- return [
974
- a,
975
- c,
976
- i
977
- ];
978
- }
979
- function U(e, t) {
980
- if (e) {
981
- for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (ut(n).test(t)) return [...e[n]];
982
- }
983
- }
984
- var pt = class {
1244
+ }, an = G();
1245
+ function on(e) {
1246
+ return an[e] ??= RegExp(`^${e.replace(/\/:[^/{}]+(?:\{\[\^\/]\+})?(?=[/{]|$)|\/?\*$|([.\\+*[^\]$()?{}|])/g, (e, t) => t ? `\\${t}` : e === "/*" ? $t : e === "*" ? ".*" : `/:${Qt}`)}$`);
1247
+ }
1248
+ function sn(e, t) {
1249
+ for (let n of Object.keys(e).sort((e, t) => t.length - e.length)) if (on(n).test(t)) return [...e[n]];
1250
+ }
1251
+ var cn = class {
985
1252
  name = "RegExpRouter";
986
1253
  #e;
987
1254
  #t;
1255
+ #n;
988
1256
  constructor() {
989
- this.#e = { ALL: /* @__PURE__ */ Object.create(null) }, this.#t = { ALL: /* @__PURE__ */ Object.create(null) };
1257
+ this.#e = { ALL: G() }, this.#t = { ALL: G() }, this.#n = { ALL: new rn() };
1258
+ }
1259
+ #r(e, t) {
1260
+ try {
1261
+ this.#n[e].insert(t, !/\*|\/:/.test(t));
1262
+ } catch (e) {
1263
+ throw e === K ? new Gt(t) : e;
1264
+ }
990
1265
  }
991
1266
  add(e, t, n) {
992
1267
  let r = this.#e, i = this.#t;
993
- if (!r || !i) throw Error(Xe);
994
- r[e] || [r, i].forEach((t) => {
995
- t[e] = /* @__PURE__ */ Object.create(null), Object.keys(t.ALL).forEach((n) => {
996
- t[e][n] = [...t.ALL[n]];
997
- });
998
- }), t === "/*" && (t = "*");
999
- let a = (t.match(/\/:/g) || []).length;
1268
+ if (!r) throw Error(Wt);
1269
+ if (!r[e]) {
1270
+ this.#n[e] = new rn();
1271
+ for (let t of [r, i]) {
1272
+ t[e] = G();
1273
+ for (let n in t.ALL) t[e][n] = [...t.ALL[n]], this.#r(e, n);
1274
+ }
1275
+ }
1276
+ t === "/*" && (t = "*");
1277
+ let a = e === "ALL" ? Object.keys(r) : [e];
1000
1278
  if (/\*$/.test(t)) {
1001
- let o = ut(t);
1002
- e === "ALL" ? Object.keys(r).forEach((e) => {
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) => {
1005
- (e === "ALL" || e === t) && Object.keys(r[t]).forEach((e) => {
1006
- o.test(e) && r[t][e].push([n, a]);
1007
- });
1008
- }), Object.keys(i).forEach((t) => {
1009
- (e === "ALL" || e === t) && Object.keys(i[t]).forEach((e) => o.test(e) && i[t][e].push([n, a]));
1010
- });
1279
+ let e = on(t);
1280
+ for (let e of a) r[e][t] || (this.#r(e, t), r[e][t] = sn(r[e], t) || sn(r.ALL, t) || []);
1281
+ for (let o of [r, i]) for (let r of a) for (let i in o[r]) e.test(i) && o[r][i].push([n, t]);
1011
1282
  return;
1012
1283
  }
1013
- let o = Fe(t) || [t];
1014
- for (let t = 0, s = o.length; t < s; t++) {
1015
- let c = o[t];
1016
- Object.keys(i).forEach((o) => {
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]));
1018
- });
1019
- }
1284
+ let o = kt(t) || [t];
1285
+ for (let e of o) for (let t of a) i[t][e] || (this.#r(t, e), i[t][e] = sn(r[t], e) || sn(r.ALL, e) || []), i[t][e].push([n, e]);
1020
1286
  }
1021
- match = rt;
1287
+ match = Zt;
1022
1288
  buildAllMatchers() {
1023
- let e = /* @__PURE__ */ Object.create(null);
1024
- return Object.keys(this.#t).concat(Object.keys(this.#e)).forEach((t) => {
1025
- e[t] ||= this.#n(t);
1026
- }), this.#e = this.#t = void 0, dt(), e;
1289
+ let e = G();
1290
+ for (let t of Object.keys(this.#t)) e[t] = this.#i(t);
1291
+ return this.#e = this.#t = this.#n = void 0, an = G(), e;
1027
1292
  }
1028
- #n(e) {
1029
- let t = [], n = e === "ALL";
1030
- return [this.#e, this.#t].forEach((r) => {
1031
- let i = r[e] ? Object.keys(r[e]).map((t) => [t, r[e][t]]) : [];
1032
- i.length === 0 ? e !== "ALL" && t.push(...Object.keys(r.ALL).map((e) => [e, r.ALL[e]])) : (n ||= !0, t.push(...i));
1033
- }), n ? ft(t) : null;
1293
+ #i(e) {
1294
+ let t = this.#e[e], n = this.#t[e], r = this.#n[e], i = G(), a = [], [o, s, c] = r.buildRegExp();
1295
+ for (let e of [t, n]) for (let t in e) {
1296
+ let n = e[t], o = r.paths[t];
1297
+ if (!o) {
1298
+ i[t] = [n.map(([e]) => [e, G()]), Xt];
1299
+ continue;
1300
+ }
1301
+ a[o[0]] = n.map(([e, t]) => [e, r.paths[t][1].reduceRight((e, [t], n) => (e[t] = c[o[1][n][1]], e), G())]);
1302
+ }
1303
+ return [
1304
+ o,
1305
+ s.map((e) => a[e]),
1306
+ i
1307
+ ];
1034
1308
  }
1035
- }, mt = class {
1309
+ }, ln = class {
1036
1310
  name = "SmartRouter";
1037
1311
  #e = [];
1038
1312
  #t = [];
@@ -1040,7 +1314,7 @@ var pt = class {
1040
1314
  this.#e = e.routers;
1041
1315
  }
1042
1316
  add(e, t, n) {
1043
- if (!this.#t) throw Error(Xe);
1317
+ if (!this.#t) throw Error(Wt);
1044
1318
  this.#t.push([
1045
1319
  e,
1046
1320
  t,
@@ -1056,7 +1330,7 @@ var pt = class {
1056
1330
  for (let e = 0, t = r.length; e < t; e++) i.add(...r[e]);
1057
1331
  o = i.match(e, t);
1058
1332
  } catch (e) {
1059
- if (e instanceof Ze) continue;
1333
+ if (e instanceof Gt) continue;
1060
1334
  throw e;
1061
1335
  }
1062
1336
  this.match = i.match.bind(i), this.#e = [i], this.#t = void 0;
@@ -1069,149 +1343,126 @@ var pt = class {
1069
1343
  if (this.#t || this.#e.length !== 1) throw Error("No active router has been determined yet.");
1070
1344
  return this.#e[0];
1071
1345
  }
1072
- }, W = /* @__PURE__ */ Object.create(null), ht = (e) => {
1073
- for (let t in e) return !0;
1074
- return !1;
1075
- }, gt = class e {
1076
- #e;
1077
- #t;
1078
- #n;
1079
- #r = 0;
1080
- #i = W;
1081
- constructor(e, t, n) {
1082
- if (this.#t = n || /* @__PURE__ */ Object.create(null), this.#e = [], e && t) {
1083
- let n = /* @__PURE__ */ Object.create(null);
1084
- n[e] = {
1085
- handler: t,
1086
- possibleKeys: [],
1087
- score: 0
1088
- }, this.#e = [n];
1089
- }
1090
- this.#n = [];
1091
- }
1346
+ }, un = G(), dn = 0, fn = class e {
1347
+ #e = [];
1348
+ #t = G();
1349
+ #n = [];
1350
+ #r;
1351
+ #i = un;
1092
1352
  insert(t, n, r) {
1093
- this.#r = ++this.#r;
1094
- let i = this, a = De(n), o = [];
1095
- for (let t = 0, n = a.length; t < n; t++) {
1096
- let n = a[t], r = a[t + 1], s = Ae(n, r), c = Array.isArray(s) ? s[0] : n;
1097
- if (c in i.#t) {
1098
- i = i.#t[c], s && o.push(s[1]);
1099
- continue;
1100
- }
1101
- i.#t[c] = new e(), s && (i.#n.push(s), o.push(s[1])), i = i.#t[c];
1353
+ let i = this, a = bt(n), o = /* @__PURE__ */ new Set(), s = 0;
1354
+ for (let t of a) {
1355
+ let n = a[++s], r = wt(t, n) || (n === void 0 && t && t.indexOf("*") === t.length - 1 ? t : null), c = Array.isArray(r), l = c ? r[0] : r || t, u = i.#t[l] ||= new e();
1356
+ r && !u.#r && (u.#r = r, i.#n.push(u)), i = u, c && o.add(r[1]);
1102
1357
  }
1103
- return i.#e.push({ [t]: {
1358
+ i.#e.push({ [t]: {
1104
1359
  handler: r,
1105
- possibleKeys: o.filter((e, t, n) => n.indexOf(e) === t),
1106
- score: this.#r
1107
- } }), i;
1360
+ possibleKeys: [...o],
1361
+ score: ++dn
1362
+ } });
1108
1363
  }
1109
1364
  #a(e, t, n, r, i) {
1110
1365
  for (let a = 0, o = t.#e.length; a < o; a++) {
1111
- let o = t.#e[a], s = o[n] || o.ALL, c = {};
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++) {
1113
- let t = s.possibleKeys[e], n = c[s.score];
1114
- s.params[t] = i?.[t] && !n ? i[t] : r[t] ?? i?.[t], c[s.score] = !0;
1366
+ let o = t.#e[a], s = o[n] || o.ALL;
1367
+ if (s) {
1368
+ s.params = G(), e.push(s);
1369
+ for (let e = 0, t = s.possibleKeys.length; e < t; e++) {
1370
+ let t = s.possibleKeys[e];
1371
+ s.params[t] = i?.[t] && !e ? i[t] : r[t] ?? i?.[t];
1372
+ }
1115
1373
  }
1116
1374
  }
1117
1375
  }
1118
1376
  search(e, t) {
1119
1377
  let n = [];
1120
- this.#i = W;
1121
- let r = [this], i = Ee(t), a = [], o = i.length, s = null;
1378
+ this.#i = un;
1379
+ let r = [this], i = yt(t), a = [], o = i.length, s = null;
1122
1380
  for (let c = 0; c < o; c++) {
1123
1381
  let l = i[c], u = c === o - 1, d = [];
1124
1382
  for (let f = 0, p = r.length; f < p; f++) {
1125
1383
  let p = r[f], m = p.#t[l];
1126
1384
  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));
1127
- for (let r = 0, f = p.#n.length; r < f; r++) {
1128
- let f = p.#n[r], m = p.#i === W ? {} : { ...p.#i };
1129
- if (f === "*") {
1130
- let t = p.#t["*"];
1131
- t && (this.#a(n, t, e, p.#i), t.#i = m, d.push(t));
1385
+ for (let r of p.#n) {
1386
+ let f = r.#r, m = p.#i === un ? {} : { ...p.#i };
1387
+ if (typeof f == "string") {
1388
+ (f === "*" || l.startsWith(f.slice(0, -1))) && (this.#a(n, r, e, p.#i), f === "*" && (r.#i = m, d.push(r)));
1132
1389
  continue;
1133
1390
  }
1134
- let [h, g, _] = f;
1135
- if (!l && !(_ instanceof RegExp)) continue;
1136
- let v = p.#t[h];
1137
- if (_ instanceof RegExp) {
1138
- if (s === null) {
1139
- s = Array(o);
1140
- let e = +(t[0] === "/");
1141
- for (let t = 0; t < o; t++) s[t] = e, e += i[t].length + 1;
1142
- }
1143
- let r = t.substring(s[c]), l = _.exec(r);
1144
- if (l) {
1145
- if (m[g] = l[0], this.#a(n, v, e, p.#i, m), ht(v.#t)) {
1146
- v.#i = m;
1147
- let e = l[0].match(/\//)?.length ?? 0;
1148
- (a[e] ||= []).push(v);
1391
+ let [, h, g] = f;
1392
+ if (!(!l && g === !0)) {
1393
+ if (g !== !0) {
1394
+ if (!s) {
1395
+ s = [];
1396
+ let e = +(t[0] === "/");
1397
+ for (let t = 0; t < o; t++) s[t] = e, e += i[t].length + 1;
1398
+ }
1399
+ let l = t.slice(s[c]), u = g.exec(l);
1400
+ if (u) {
1401
+ m[h] = u[0], this.#a(n, r, e, p.#i, m), u[0].length === l.length && r.#t["*"] && this.#a(n, r.#t["*"], e, p.#i, m);
1402
+ for (let e in r.#t) {
1403
+ r.#i = m;
1404
+ let e = u[0].match(/\//g)?.length ?? 0;
1405
+ (a[e] ||= []).push(r);
1406
+ break;
1407
+ }
1408
+ continue;
1149
1409
  }
1150
- continue;
1151
1410
  }
1411
+ (g === !0 || g.test(l)) && (m[h] = l, u ? (this.#a(n, r, e, m, p.#i), r.#t["*"] && this.#a(n, r.#t["*"], e, m, p.#i)) : (r.#i = m, d.push(r)));
1152
1412
  }
1153
- (_ === !0 || _.test(l)) && (m[g] = l, u ? (this.#a(n, v, e, m, p.#i), v.#t["*"] && this.#a(n, v.#t["*"], e, m, p.#i)) : (v.#i = m, d.push(v)));
1154
1413
  }
1155
1414
  }
1156
1415
  let f = a.shift();
1157
1416
  r = f ? d.concat(f) : d;
1158
1417
  }
1159
- return n.length > 1 && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
1418
+ return n[1] && n.sort((e, t) => e.score - t.score), [n.map(({ handler: e, params: t }) => [e, t])];
1160
1419
  }
1161
- }, _t = class {
1420
+ }, pn = class {
1162
1421
  name = "TrieRouter";
1163
- #e;
1164
- constructor() {
1165
- this.#e = new gt();
1166
- }
1422
+ #e = new fn();
1167
1423
  add(e, t, n) {
1168
- let r = Fe(t);
1169
- if (r) {
1170
- for (let t = 0, i = r.length; t < i; t++) this.#e.insert(e, r[t], n);
1171
- return;
1172
- }
1173
- this.#e.insert(e, t, n);
1424
+ for (let r of kt(t) || [t]) this.#e.insert(e, r, n);
1174
1425
  }
1175
1426
  match(e, t) {
1176
1427
  return this.#e.search(e, t);
1177
1428
  }
1178
- }, vt = class extends tt {
1429
+ }, mn = class extends Yt {
1179
1430
  constructor(e = {}) {
1180
- super(e), this.router = e.router ?? new mt({ routers: [new pt(), new _t()] });
1431
+ super(e), this.router = e.router ?? new ln({ routers: [new cn(), new pn()] });
1181
1432
  }
1182
1433
  };
1183
1434
  //#endregion
1184
1435
  //#region src/coordinator-invites.ts
1185
- function yt(e) {
1436
+ function hn(e) {
1186
1437
  let t = "";
1187
1438
  for (let n of e) t += String.fromCharCode(n);
1188
1439
  return btoa(t);
1189
1440
  }
1190
- function bt(e) {
1441
+ function gn(e) {
1191
1442
  let t = atob(e), n = new Uint8Array(t.length);
1192
1443
  for (let e = 0; e < t.length; e += 1) n[e] = t.charCodeAt(e);
1193
1444
  return n;
1194
1445
  }
1195
- function xt(e) {
1446
+ function _n(e) {
1196
1447
  return e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1197
1448
  }
1198
- function St(e) {
1449
+ function vn(e) {
1199
1450
  let t = e.replace(/-/g, "+").replace(/_/g, "/");
1200
1451
  return t + "=".repeat((4 - t.length % 4) % 4);
1201
1452
  }
1202
- function G(e) {
1453
+ function yn(e) {
1203
1454
  let t = JSON.stringify(e);
1204
- return xt(yt(new TextEncoder().encode(t)));
1455
+ return _n(hn(new TextEncoder().encode(t)));
1205
1456
  }
1206
- function Ct(e) {
1207
- let t = new TextDecoder().decode(bt(St(e))), n = JSON.parse(t);
1457
+ function bn(e) {
1458
+ let t = new TextDecoder().decode(gn(vn(e))), n = JSON.parse(t);
1208
1459
  if (typeof n != "object" || !n) throw Error("invalid invite payload");
1209
1460
  return n;
1210
1461
  }
1211
- function K(e) {
1462
+ function xn(e) {
1212
1463
  return `codemem://join?invite=${encodeURIComponent(e)}`;
1213
1464
  }
1214
- function wt(e) {
1465
+ function Sn(e) {
1215
1466
  let t = e.trim();
1216
1467
  if (t.startsWith("codemem://")) {
1217
1468
  let e = new URL(t).searchParams.get("invite") ?? "";
@@ -1222,44 +1473,62 @@ function wt(e) {
1222
1473
  }
1223
1474
  //#endregion
1224
1475
  //#region src/project-invite-acceptance.ts
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;
1476
+ var Cn = "pending_setup", wn = "project_sync_enablement_failed", Tn = "Invitation was accepted, but sync could not be enabled. Make the codemem config writable, then retry.", En = class extends Error {
1477
+ code = wn;
1478
+ detail = Tn;
1228
1479
  constructor(e) {
1229
- super(Dt, e), this.name = "ProjectSyncEnablementError";
1480
+ super(Tn, e), this.name = "ProjectSyncEnablementError";
1230
1481
  }
1231
1482
  };
1232
- function kt(e) {
1483
+ function Dn(e) {
1233
1484
  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.";
1234
1485
  }
1235
1486
  //#endregion
1236
- //#region src/scope-resolution.ts
1237
- var At = "local-default", jt = "legacy-shared-review";
1487
+ //#region src/project-identity.ts
1488
+ var On = /^(?:command failed(?:\s|:)|error:\s|fatal:\s|git:\s)/iu, kn = /^(?:giterror|git error|git command failed):[^\r\n]*(?:not a git repository|unknown revision or path|no such remote)\b/iu;
1489
+ function An(e) {
1490
+ if (typeof e != "string") return !1;
1491
+ let t = e.trim();
1492
+ return t ? t.includes("\n") || t.includes("\r") ? !0 : On.test(t) || kn.test(t) : !1;
1493
+ }
1238
1494
  function q(e) {
1239
- return e?.trim() || null;
1495
+ let t = e?.trim();
1496
+ return !t || An(t) ? null : t;
1240
1497
  }
1498
+ //#endregion
1499
+ //#region src/scope-resolution.ts
1500
+ var jn = "local-default", Mn = "legacy-shared-review";
1241
1501
  function J(e) {
1502
+ return e?.trim() || null;
1503
+ }
1504
+ function Y(e) {
1242
1505
  return e.trim().replaceAll("\\", "/").replace(/\/+$/, "") || e.trim();
1243
1506
  }
1244
- function Mt(t) {
1245
- return J(e(t));
1507
+ function Nn(t) {
1508
+ return Y(e(t));
1246
1509
  }
1247
- function Nt(e) {
1248
- let t = q(e);
1249
- return t ? J(t) : null;
1510
+ function Pn(e) {
1511
+ let t = J(e);
1512
+ return t ? Y(t) : null;
1250
1513
  }
1251
- function Pt(e) {
1514
+ function Fn(e) {
1252
1515
  let n = [
1253
1516
  e.cwd,
1254
1517
  e.project,
1255
1518
  e.workspaceId
1256
- ].map((e) => q(e)).find((e) => e != null);
1257
- return `unmapped:${t("sha256").update(n ?? "unknown", "utf8").digest("hex")}`;
1519
+ ].map((e) => q(e)).find((e) => e !== null), r = [
1520
+ e.gitRemote,
1521
+ e.gitBranch,
1522
+ e.cwd,
1523
+ e.project,
1524
+ e.workspaceId
1525
+ ].map((e) => typeof e == "string" ? e.trim() : null), i = n ?? "unknown";
1526
+ return !n && r.some(An) && (i = JSON.stringify(r)), `unmapped:${t("sha256").update(i, "utf8").digest("hex")}`;
1258
1527
  }
1259
- function Ft(e) {
1528
+ function In(e) {
1260
1529
  let t = q(e.gitRemote), n = q(e.gitBranch), r = q(e.cwd), i = q(e.workspaceId), a = q(e.project);
1261
1530
  if (t) {
1262
- let r = J(t);
1531
+ let r = Y(t);
1263
1532
  return e.branchScoped && n ? {
1264
1533
  value: `${r}:${n}`,
1265
1534
  source: "git_remote_branch",
@@ -1271,49 +1540,49 @@ function Ft(e) {
1271
1540
  };
1272
1541
  }
1273
1542
  return r ? {
1274
- value: Mt(r),
1543
+ value: Nn(r),
1275
1544
  source: "cwd",
1276
1545
  displayProject: a
1277
1546
  } : i ? {
1278
- value: J(i),
1547
+ value: Y(i),
1279
1548
  source: "workspace_id",
1280
1549
  displayProject: a
1281
1550
  } : {
1282
- value: Pt(e),
1551
+ value: Fn(e),
1283
1552
  source: "unmapped",
1284
1553
  displayProject: a
1285
1554
  };
1286
1555
  }
1287
- function It(e) {
1556
+ function Ln(e) {
1288
1557
  return !/[\\/:]/.test(e);
1289
1558
  }
1290
- function Lt(e) {
1559
+ function Rn(e) {
1291
1560
  return e.replace(/[|\\{}()[\]^$+?.*]/g, "\\$&");
1292
1561
  }
1293
- function Rt(e) {
1562
+ function zn(e) {
1294
1563
  return e.replace(/[*?]/g, "").length;
1295
1564
  }
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;
1565
+ function Bn(e, t) {
1566
+ let n = Y(t);
1567
+ return !n || Ln(n) ? !1 : /[*?]/.test(n) ? RegExp(`^${Rn(n).replaceAll("\\*", ".*").replaceAll("\\?", ".")}$`).test(e) : e === n;
1299
1568
  }
1300
- function Bt(e) {
1569
+ function Vn(e) {
1301
1570
  return e.mapping.priority ?? 0;
1302
1571
  }
1303
- function Vt(e) {
1304
- let t = q(e.mapping.updated_at);
1572
+ function Hn(e) {
1573
+ let t = J(e.mapping.updated_at);
1305
1574
  if (!t) return 0;
1306
1575
  let n = Date.parse(t);
1307
1576
  return Number.isFinite(n) ? n : 0;
1308
1577
  }
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);
1578
+ function Un(e, t) {
1579
+ return Vn(t) - Vn(e) || t.specificity - e.specificity || Hn(t) - Hn(e) || (t.mapping.id ?? 0) - (e.mapping.id ?? 0) || e.mapping.scope_id.localeCompare(t.mapping.scope_id);
1311
1580
  }
1312
- function Ut(e) {
1313
- return e.toSorted(Ht)[0] ?? null;
1581
+ function Wn(e) {
1582
+ return e.toSorted(Un)[0] ?? null;
1314
1583
  }
1315
- function Wt(e) {
1316
- let t = Ft(e), n = q(e.explicitScopeId);
1584
+ function Gn(e) {
1585
+ let t = In(e), n = J(e.explicitScopeId);
1317
1586
  if (n) return {
1318
1587
  scopeId: n,
1319
1588
  reason: "explicit_override",
@@ -1328,7 +1597,7 @@ function Wt(e) {
1328
1597
  mapping: null,
1329
1598
  matchedPattern: null
1330
1599
  };
1331
- let r = e.mappings ?? [], i = Ut(r.filter((e) => Nt(e.workspace_identity) === t.value).map((e) => ({
1600
+ let r = e.mappings ?? [], i = Wn(r.filter((e) => Pn(e.workspace_identity) === t.value).map((e) => ({
1332
1601
  mapping: e,
1333
1602
  matchedPattern: null,
1334
1603
  specificity: t.value.length
@@ -1340,13 +1609,13 @@ function Wt(e) {
1340
1609
  mapping: i.mapping,
1341
1610
  matchedPattern: null
1342
1611
  };
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) ? [] : [{
1612
+ let a = Wn(r.flatMap((e) => {
1613
+ if (J(e.workspace_identity)) return [];
1614
+ let n = J(e.project_pattern);
1615
+ return !n || !Bn(t.value, n) ? [] : [{
1347
1616
  mapping: e,
1348
- matchedPattern: J(n),
1349
- specificity: Rt(n)
1617
+ matchedPattern: Y(n),
1618
+ specificity: zn(n)
1350
1619
  }];
1351
1620
  }));
1352
1621
  return a ? {
@@ -1363,11 +1632,11 @@ function Wt(e) {
1363
1632
  matchedPattern: null
1364
1633
  };
1365
1634
  }
1366
- function Gt(e, t) {
1367
- let n = new Set([
1635
+ function Kn(e, t) {
1636
+ let n = /* @__PURE__ */ new Set([
1368
1637
  "",
1369
- At,
1370
- jt
1638
+ jn,
1639
+ Mn
1371
1640
  ]), r = e.prepare("SELECT scope_id\n FROM replication_scopes\n WHERE status = 'active' AND authority_type = 'local'").all();
1372
1641
  for (let e of r) e.scope_id != null && n.add(e.scope_id);
1373
1642
  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);
@@ -1376,29 +1645,29 @@ function Gt(e, t) {
1376
1645
  }
1377
1646
  //#endregion
1378
1647
  //#region src/project-share-intent.ts
1379
- var Kt = "existing_and_future";
1380
- function qt(e) {
1648
+ var qn = "existing_and_future";
1649
+ function Jn(e) {
1381
1650
  return t("sha256").update(JSON.stringify(e)).digest("hex");
1382
1651
  }
1383
- function Jt(e) {
1384
- return qt({
1652
+ function Yn(e) {
1653
+ return Jn({
1385
1654
  v: 1,
1386
- historyPolicy: Kt,
1655
+ historyPolicy: qn,
1387
1656
  projects: e.map((e) => ({
1388
1657
  canonicalIdentity: e.canonicalIdentity,
1389
1658
  existingMemoryCount: e.existingMemoryCount
1390
1659
  })).toSorted((e, t) => e.canonicalIdentity.localeCompare(t.canonicalIdentity))
1391
1660
  });
1392
1661
  }
1393
- function Yt(e) {
1394
- return Jt(e.map((e) => ({
1662
+ function Xn(e) {
1663
+ return Yn(e.map((e) => ({
1395
1664
  canonicalIdentity: e.canonical_identity,
1396
1665
  displayName: e.display_name,
1397
1666
  identitySource: "coordinator_acceptance",
1398
1667
  existingMemoryCount: e.existing_memory_count
1399
1668
  })));
1400
1669
  }
1401
- function Xt(e) {
1670
+ function Zn(e) {
1402
1671
  if (!Array.isArray(e) || e.length === 0 || e.length > 100) throw Error("operation_intent_invalid");
1403
1672
  let t = e.map((e) => {
1404
1673
  if (!e || typeof e != "object" || Array.isArray(e)) throw Error("operation_intent_invalid");
@@ -1406,11 +1675,11 @@ function Xt(e) {
1406
1675
  if (typeof t.canonical_identity != "string" || typeof t.display_name != "string") throw Error("operation_intent_invalid");
1407
1676
  let n = t.canonical_identity, r = n.trim(), i = t.display_name, a;
1408
1677
  try {
1409
- a = C(i, "project_name");
1678
+ a = F(i, "project_name");
1410
1679
  } catch {
1411
1680
  throw Error("operation_intent_invalid");
1412
1681
  }
1413
- let o = t.existing_memory_count, s = Ft({ gitRemote: r }).value;
1682
+ let o = t.existing_memory_count, s = In({ gitRemote: r }).value;
1414
1683
  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");
1415
1684
  return {
1416
1685
  canonical_identity: r,
@@ -1423,20 +1692,20 @@ function Xt(e) {
1423
1692
  }
1424
1693
  //#endregion
1425
1694
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/clock.js
1426
- function Zt(e) {
1695
+ function Qn(e) {
1427
1696
  let t = performance.now() * .001, n = Math.floor(t), r = Math.floor(t % 1 * 1e9);
1428
1697
  return e != null && (n -= e[0], r -= e[1], r < 0 && (n--, r += 1e9)), [n, r];
1429
1698
  }
1430
- function Y() {
1431
- let [e, t] = Zt();
1699
+ function $n() {
1700
+ let [e, t] = Qn();
1432
1701
  return e * 1e3 + Math.floor(t / 1e6);
1433
1702
  }
1434
- function Qt(e) {
1703
+ function er(e) {
1435
1704
  return new Promise((t) => setTimeout(t, e));
1436
1705
  }
1437
1706
  //#endregion
1438
1707
  //#region ../../node_modules/.pnpm/limiter@3.0.0/node_modules/limiter/dist/esm/TokenBucket.js
1439
- var $t = class {
1708
+ var tr = class {
1440
1709
  bucketSize;
1441
1710
  tokensPerInterval;
1442
1711
  interval;
@@ -1451,30 +1720,31 @@ var $t = class {
1451
1720
  break;
1452
1721
  case "min":
1453
1722
  case "minute":
1454
- this.interval = 1e3 * 60;
1723
+ this.interval = 6e4;
1455
1724
  break;
1456
1725
  case "hr":
1457
1726
  case "hour":
1458
- this.interval = 1e3 * 60 * 60;
1727
+ this.interval = 36e5;
1459
1728
  break;
1460
1729
  case "day":
1461
- this.interval = 1e3 * 60 * 60 * 24;
1730
+ this.interval = 864e5;
1462
1731
  break;
1463
1732
  default: throw Error("Invalid interval " + n);
1464
1733
  }
1465
1734
  else this.interval = n;
1466
- this.parentBucket = r, this.content = 0, this.lastDrip = Y();
1735
+ this.parentBucket = r, this.content = 0, this.lastDrip = $n();
1467
1736
  }
1468
1737
  async removeTokens(e) {
1469
1738
  if (this.bucketSize === 0) return Infinity;
1470
1739
  if (e > this.bucketSize) throw Error(`Requested tokens ${e} exceeds bucket size ${this.bucketSize}`);
1471
1740
  this.drip();
1472
- let t = async () => (await Qt(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
1741
+ let t = async () => (await er(Math.ceil((e - this.content) * (this.interval / this.tokensPerInterval))), this.removeTokens(e));
1473
1742
  if (e > this.content) return t();
1474
1743
  if (this.parentBucket != null) {
1475
1744
  let n = await this.parentBucket.removeTokens(e);
1476
1745
  return e > this.content ? t() : (this.content -= e, Math.min(n, this.content));
1477
- } else return this.content -= e, this.content;
1746
+ }
1747
+ return this.content -= e, this.content;
1478
1748
  }
1479
1749
  tryRemoveTokens(e) {
1480
1750
  return this.bucketSize ? e > this.bucketSize || (this.drip(), e > this.content) || this.parentBucket && !this.parentBucket.tryRemoveTokens(e) ? !1 : (this.content -= e, !0) : !0;
@@ -1484,30 +1754,30 @@ var $t = class {
1484
1754
  let e = this.content;
1485
1755
  return this.content = this.bucketSize, this.content > e;
1486
1756
  }
1487
- let e = Y(), t = Math.max(e - this.lastDrip, 0);
1757
+ let e = $n(), t = Math.max(e - this.lastDrip, 0);
1488
1758
  this.lastDrip = e;
1489
1759
  let n = t * (this.tokensPerInterval / this.interval), r = this.content;
1490
1760
  return this.content = Math.min(this.content + n, this.bucketSize), Math.floor(this.content) > Math.floor(r);
1491
1761
  }
1492
- }, en = class {
1762
+ }, nr = class {
1493
1763
  tokenBucket;
1494
1764
  curIntervalStart;
1495
1765
  tokensThisInterval;
1496
1766
  fireImmediately;
1497
1767
  constructor({ tokensPerInterval: e, interval: t, fireImmediately: n }) {
1498
- this.tokenBucket = new $t({
1768
+ this.tokenBucket = new tr({
1499
1769
  bucketSize: e,
1500
1770
  tokensPerInterval: e,
1501
1771
  interval: t
1502
- }), this.tokenBucket.content = e, this.curIntervalStart = Y(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
1772
+ }), this.tokenBucket.content = e, this.curIntervalStart = $n(), this.tokensThisInterval = 0, this.fireImmediately = n ?? !1;
1503
1773
  }
1504
1774
  async removeTokens(e) {
1505
1775
  if (e > this.tokenBucket.bucketSize) throw Error(`Requested tokens ${e} exceeds maximum tokens per interval ${this.tokenBucket.bucketSize}`);
1506
- let t = Y();
1776
+ let t = $n();
1507
1777
  if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) {
1508
1778
  if (this.fireImmediately) return -1;
1509
1779
  {
1510
- await Qt(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
1780
+ await er(Math.ceil(this.curIntervalStart + this.tokenBucket.interval - t));
1511
1781
  let n = await this.tokenBucket.removeTokens(e);
1512
1782
  return this.tokensThisInterval += e, n;
1513
1783
  }
@@ -1517,7 +1787,7 @@ var $t = class {
1517
1787
  }
1518
1788
  tryRemoveTokens(e) {
1519
1789
  if (e > this.tokenBucket.bucketSize) return !1;
1520
- let t = Y();
1790
+ let t = $n();
1521
1791
  if ((t < this.curIntervalStart || t - this.curIntervalStart >= this.tokenBucket.interval) && (this.curIntervalStart = t, this.tokensThisInterval = 0), e > this.tokenBucket.tokensPerInterval - this.tokensThisInterval) return !1;
1522
1792
  let n = this.tokenBucket.tryRemoveTokens(e);
1523
1793
  return n && (this.tokensThisInterval += e), n;
@@ -1528,7 +1798,7 @@ var $t = class {
1528
1798
  };
1529
1799
  //#endregion
1530
1800
  //#region src/request-rate-limit.ts
1531
- function tn(e = {}) {
1801
+ function rr(e = {}) {
1532
1802
  let t = Math.max(1e3, Math.trunc(e.windowMs ?? 6e4)), n = e.now ?? (() => Date.now()), r = /* @__PURE__ */ new Map(), i = 0;
1533
1803
  function a(e) {
1534
1804
  return Math.max(1, Math.ceil(t / Math.max(1, e) / 1e3));
@@ -1545,7 +1815,7 @@ function tn(e = {}) {
1545
1815
  o(l);
1546
1816
  let u = `${c}:${e}`, d = r.get(u);
1547
1817
  return d || (d = {
1548
- limiter: new en({
1818
+ limiter: new nr({
1549
1819
  tokensPerInterval: c,
1550
1820
  interval: t,
1551
1821
  fireImmediately: !0
@@ -1562,8 +1832,8 @@ function tn(e = {}) {
1562
1832
  }
1563
1833
  //#endregion
1564
1834
  //#region src/scope-membership-semantics.ts
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) {
1835
+ var ir = "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.";
1836
+ function ar(e) {
1567
1837
  let t = Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null, n = Number.isFinite(e.requiredEpoch) ? Number(e.requiredEpoch) : null;
1568
1838
  return t == null || n == null ? {
1569
1839
  membership_epoch: t,
@@ -1577,19 +1847,19 @@ function rn(e) {
1577
1847
  reason: t < n ? "stale_epoch" : "current"
1578
1848
  };
1579
1849
  }
1580
- function an(e) {
1850
+ function or(e) {
1581
1851
  return {
1582
1852
  scope_id: e.scopeId,
1583
1853
  device_id: e.deviceId,
1584
1854
  membership_epoch: Number.isFinite(e.membershipEpoch) ? Number(e.membershipEpoch) : null,
1585
1855
  prevents_future_sync: !0,
1586
1856
  deletes_already_copied_data: !1,
1587
- message: nn
1857
+ message: ir
1588
1858
  };
1589
1859
  }
1590
1860
  //#endregion
1591
1861
  //#region src/sync-auth-constants.ts
1592
- var on = 300, sn = 64 * 1024, X = "X-Codemem-Coordinator-Admin", cn = "X-Codemem-Coordinator-Admin-Actor", ln = 120, un = 30;
1862
+ var sr = 300, cr = 65536, lr = E + 1024, X = "X-Codemem-Coordinator-Admin", ur = "X-Codemem-Coordinator-Admin-Actor", dr = 120, fr = 30;
1593
1863
  function Z(e, t) {
1594
1864
  let n = t.adminSecret();
1595
1865
  if (!n) return {
@@ -1608,14 +1878,14 @@ function Z(e, t) {
1608
1878
  error: "missing_admin_header"
1609
1879
  };
1610
1880
  }
1611
- function dn(e) {
1881
+ function pr(e) {
1612
1882
  let t = new URL(e);
1613
1883
  return t.search ? `${t.pathname}${t.search}` : t.pathname;
1614
1884
  }
1615
- async function fn(e, t, n, r) {
1885
+ async function mr(e, t, n, r) {
1616
1886
  return await e.recordNonce(t, n, r);
1617
1887
  }
1618
- async function pn(e, t) {
1888
+ async function hr(e, t) {
1619
1889
  await e.cleanupNonces(t);
1620
1890
  }
1621
1891
  async function Q(e, t, n, r) {
@@ -1651,7 +1921,7 @@ async function Q(e, t, n, r) {
1651
1921
  try {
1652
1922
  u = await n({
1653
1923
  method: r.method,
1654
- pathWithQuery: dn(r.url),
1924
+ pathWithQuery: pr(r.url),
1655
1925
  bodyBytes: r.body,
1656
1926
  timestamp: o,
1657
1927
  nonce: s,
@@ -1672,7 +1942,7 @@ async function Q(e, t, n, r) {
1672
1942
  enrollment: null
1673
1943
  };
1674
1944
  let d = t.now();
1675
- return await fn(e, i, s, d) ? (await pn(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 300 * 2 * 1e3)).toISOString()), {
1945
+ return await mr(e, i, s, d) ? (await hr(e, (/* @__PURE__ */ new Date(new Date(d).getTime() - 6e5)).toISOString()), {
1676
1946
  ok: !0,
1677
1947
  error: "ok",
1678
1948
  enrollment: c
@@ -1685,54 +1955,54 @@ async function Q(e, t, n, r) {
1685
1955
  function $(e) {
1686
1956
  return e === "device_disabled" ? 403 : e === "group_archived" ? 409 : 401;
1687
1957
  }
1688
- function mn(e) {
1958
+ function gr(e) {
1689
1959
  if (!e?.storeFactory || !e.runtime || !e.requestVerifier) throw Error("createCoordinatorApp requires storeFactory, runtime, and requestVerifier.");
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();
1691
- function p(e, t, n) {
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);
1960
+ let t = e.runtime, n = e.storeFactory, r = e.requestVerifier, i = e.requestRateLimit ?? {}, a = i.limiter ?? rr(), o = Math.max(1, Math.trunc(i.readLimit ?? dr)), s = Math.max(1, Math.trunc(i.mutationLimit ?? fr)), c = Math.max(1, Math.trunc(i.unauthenticatedReadLimit ?? Math.min(20, o))), l = Math.max(1, Math.trunc(i.unauthenticatedMutationLimit ?? Math.min(10, s))), u = new mn(), d = new TextDecoder();
1961
+ function f(e, t, n) {
1962
+ let r = e.req.method === "GET" || e.req.method === "HEAD" || e.req.method === "OPTIONS", i = a.check(`${e.req.method}:${n ? "auth" : "anon"}:${t}`, n ? r ? o : s : r ? c : l);
1693
1963
  return i.allowed ? null : (e.header("Retry-After", String(i.retryAfterS)), e.json({
1694
1964
  error: "rate_limited",
1695
1965
  retry_after_s: i.retryAfterS
1696
1966
  }, 429));
1697
1967
  }
1698
- async function m(e) {
1699
- let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
1700
- if (Number.isFinite(t) && t > sn) return null;
1701
- let n = e.req.raw.body;
1702
- if (!n) return new Uint8Array();
1703
- let r = n.getReader(), i = [], a = 0;
1968
+ async function p(e, t = cr) {
1969
+ let n = Number.parseInt(e.req.header("content-length") ?? "", 10);
1970
+ if (Number.isFinite(n) && n > t) return null;
1971
+ let r = e.req.raw.body;
1972
+ if (!r) return /* @__PURE__ */ new Uint8Array();
1973
+ let i = r.getReader(), a = [], o = 0;
1704
1974
  try {
1705
1975
  for (;;) {
1706
- let { done: e, value: t } = await r.read();
1976
+ let { done: e, value: n } = await i.read();
1707
1977
  if (e) break;
1708
- if (t) {
1709
- if (a += t.byteLength, a > sn) return await r.cancel(), null;
1710
- i.push(t);
1978
+ if (n) {
1979
+ if (o += n.byteLength, o > t) return await i.cancel(), null;
1980
+ a.push(n);
1711
1981
  }
1712
1982
  }
1713
1983
  } finally {
1714
- r.releaseLock();
1984
+ i.releaseLock();
1715
1985
  }
1716
- let o = new Uint8Array(a), s = 0;
1717
- for (let e of i) o.set(e, s), s += e.byteLength;
1718
- return o;
1986
+ let s = new Uint8Array(o), c = 0;
1987
+ for (let e of a) s.set(e, c), c += e.byteLength;
1988
+ return s;
1719
1989
  }
1720
- function h(e) {
1990
+ function m(e) {
1721
1991
  try {
1722
- let t = JSON.parse(f.decode(e));
1992
+ let t = JSON.parse(d.decode(e));
1723
1993
  return typeof t != "object" || !t || Array.isArray(t) ? null : t;
1724
1994
  } catch {
1725
1995
  return null;
1726
1996
  }
1727
1997
  }
1728
- function _(e, t) {
1998
+ function h(e, t) {
1729
1999
  let n = e[t];
1730
2000
  return n == null ? null : String(n).trim() || null;
1731
2001
  }
1732
- function v(e) {
2002
+ function g(e) {
1733
2003
  return e?.trim() || null;
1734
2004
  }
1735
- function y(e, t) {
2005
+ function _(e, t) {
1736
2006
  let n = e[t];
1737
2007
  if (n == null || n === "") return null;
1738
2008
  if (typeof n != "number" && typeof n != "string") return NaN;
@@ -1745,45 +2015,45 @@ function mn(e) {
1745
2015
  let r = n;
1746
2016
  return Number.isFinite(r) ? Math.trunc(r) : NaN;
1747
2017
  }
1748
- function b(e) {
2018
+ function v(e) {
1749
2019
  return [
1750
2020
  "1",
1751
2021
  "true",
1752
2022
  "yes"
1753
2023
  ].includes(String(e ?? "").trim().toLowerCase());
1754
2024
  }
1755
- function x(e) {
2025
+ function y(e) {
1756
2026
  try {
1757
- return Xt(JSON.parse(e ?? ""));
2027
+ return Zn(JSON.parse(e ?? ""));
1758
2028
  } catch {
1759
2029
  throw Error("operation_intent_invalid");
1760
2030
  }
1761
2031
  }
1762
- function S(e) {
2032
+ function ee(e) {
1763
2033
  let t = String(e.operation_id ?? "").trim(), n = String(e.reviewed_project_set_digest ?? "").trim();
1764
2034
  if (!/^share_[a-f0-9]{40}$/u.test(t) || !/^[a-f0-9]{64}$/u.test(n)) throw Error("operation_intent_invalid");
1765
- let r = x(e.project_intent_json);
1766
- if (Yt(r) !== n) throw Error("operation_intent_invalid");
2035
+ let r = y(e.project_intent_json);
2036
+ if (Xn(r) !== n) throw Error("operation_intent_invalid");
1767
2037
  return {
1768
2038
  operation_id: t,
1769
2039
  reviewed_project_set_digest: n,
1770
2040
  projects: r
1771
2041
  };
1772
2042
  }
1773
- function C(e) {
2043
+ function b(e) {
1774
2044
  try {
1775
- return ee(JSON.parse(e ?? ""));
2045
+ return Be(JSON.parse(e ?? ""));
1776
2046
  } catch {
1777
2047
  throw Error("operation_intent_invalid");
1778
2048
  }
1779
2049
  }
1780
- async function w(e, t, n) {
2050
+ async function x(e, t, n) {
1781
2051
  if (!t) return n.json({ error: "group_id_required" }, 400);
1782
2052
  let r = await e.getGroup(t);
1783
2053
  return r ? r.archived_at ? n.json({ error: "group_archived" }, 409) : null : n.json({ error: "group_not_found" }, 404);
1784
2054
  }
1785
- async function E(e, t, n, r) {
1786
- let i = await w(e, t, r);
2055
+ async function S(e, t, n, r) {
2056
+ let i = await x(e, t, r);
1787
2057
  if (i) return {
1788
2058
  scope: null,
1789
2059
  response: i
@@ -1804,12 +2074,12 @@ function mn(e) {
1804
2074
  response: r.json({ error: "scope_not_found" }, 404)
1805
2075
  };
1806
2076
  }
1807
- async function D(e, n, i) {
2077
+ async function te(e, n, i) {
1808
2078
  let a = await Q(e, t, r, {
1809
2079
  method: i.req.method,
1810
2080
  url: i.req.url,
1811
2081
  groupId: n,
1812
- body: new Uint8Array(),
2082
+ body: /* @__PURE__ */ new Uint8Array(),
1813
2083
  deviceId: i.req.header("X-Opencode-Device") ?? null,
1814
2084
  signature: i.req.header("X-Opencode-Signature") ?? null,
1815
2085
  timestamp: i.req.header("X-Opencode-Timestamp") ?? null,
@@ -1817,22 +2087,19 @@ function mn(e) {
1817
2087
  });
1818
2088
  return !a.ok || !a.enrollment ? {
1819
2089
  auth: a,
1820
- response: p(i, i.req.path, !1) ?? i.json({ error: a.error }, $(a.error))
2090
+ response: f(i, i.req.path, !1) ?? i.json({ error: a.error }, $(a.error))
1821
2091
  } : {
1822
2092
  auth: a,
1823
- response: p(i, String(a.enrollment.device_id), !0)
2093
+ response: f(i, String(a.enrollment.device_id), !0)
1824
2094
  };
1825
2095
  }
1826
- function O(e, t) {
2096
+ function C(e, t) {
1827
2097
  return e.status === "active" && e.membership_epoch >= t.membership_epoch;
1828
2098
  }
1829
- async function A(e, t, n) {
1830
- return (await e.listScopeMemberships(t.scope_id, !1)).some((e) => e.device_id === n && O(e, t));
1831
- }
1832
- return d.post("/v1/presence", async (e) => {
1833
- let i = await m(e);
2099
+ return u.post("/v1/presence", async (e) => {
2100
+ let i = await p(e);
1834
2101
  if (i == null) return e.json({ error: "body_too_large" }, 413);
1835
- let a = h(i);
2102
+ let a = m(i);
1836
2103
  if (!a) return e.json({ error: "invalid_json" }, 400);
1837
2104
  let o = String(a.group_id ?? "").trim();
1838
2105
  if (!o) return e.json({ error: "group_id_required" }, 400);
@@ -1848,8 +2115,8 @@ function mn(e) {
1848
2115
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
1849
2116
  nonce: e.req.header("X-Opencode-Nonce") ?? null
1850
2117
  });
1851
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
1852
- let c = p(e, String(n.enrollment.device_id), !0);
2118
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
2119
+ let c = f(e, String(n.enrollment.device_id), !0);
1853
2120
  if (c) return c;
1854
2121
  if (a.fingerprint && String(a.fingerprint) !== String(n.enrollment.fingerprint)) return e.json({ error: "fingerprint_mismatch" }, 401);
1855
2122
  let l = a.addresses ?? [];
@@ -1874,7 +2141,7 @@ function mn(e) {
1874
2141
  } finally {
1875
2142
  await s.close();
1876
2143
  }
1877
- }), d.get("/v1/peers", async (e) => {
2144
+ }), u.get("/v1/peers", async (e) => {
1878
2145
  let i = (e.req.query("group_id") ?? "").trim();
1879
2146
  if (!i) return e.json({ error: "group_id_required" }, 400);
1880
2147
  let a = n();
@@ -1883,44 +2150,47 @@ function mn(e) {
1883
2150
  method: e.req.method,
1884
2151
  url: e.req.url,
1885
2152
  groupId: i,
1886
- body: new Uint8Array(),
2153
+ body: /* @__PURE__ */ new Uint8Array(),
1887
2154
  deviceId: e.req.header("X-Opencode-Device") ?? null,
1888
2155
  signature: e.req.header("X-Opencode-Signature") ?? null,
1889
2156
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
1890
2157
  nonce: e.req.header("X-Opencode-Nonce") ?? null
1891
2158
  });
1892
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
1893
- let o = p(e, String(n.enrollment.device_id), !0);
2159
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) || e.json({ error: n.error }, $(n.error));
2160
+ let o = f(e, String(n.enrollment.device_id), !0);
1894
2161
  if (o) return o;
1895
2162
  let s = await a.listGroupPeers(i, String(n.enrollment.device_id));
1896
2163
  return e.json({ items: s });
1897
2164
  } finally {
1898
2165
  await a.close();
1899
2166
  }
1900
- }), d.get("/v1/scopes", async (e) => {
2167
+ }), u.get("/v1/scopes", async (e) => {
1901
2168
  let t = (e.req.query("group_id") ?? "").trim();
1902
2169
  if (!t) return e.json({ error: "group_id_required" }, 400);
1903
2170
  let r = n();
1904
2171
  try {
1905
- let { auth: n, response: i } = await D(r, t, e);
2172
+ let { auth: n, response: i } = await te(r, t, e);
1906
2173
  if (i) return i;
1907
2174
  if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
1908
2175
  let a = await r.listScopes({
1909
2176
  groupId: t,
1910
2177
  includeInactive: !1
1911
- }), o = [];
1912
- for (let e of a) e.status === "active" && await A(r, e, String(n.enrollment.device_id)) && o.push(e);
1913
- return e.json({ items: o });
2178
+ }), o = await r.listDeviceScopeMemberships(String(n.enrollment.device_id), !1), s = new Map(o.map((e) => [e.scope_id, e])), c = a.filter((e) => {
2179
+ if (e.status !== "active") return !1;
2180
+ let t = s.get(e.scope_id);
2181
+ return !!(t && C(t, e));
2182
+ });
2183
+ return e.json({ items: c });
1914
2184
  } finally {
1915
2185
  await r.close();
1916
2186
  }
1917
- }), d.get("/v1/scopes/:scope_id/members", async (e) => {
2187
+ }), u.get("/v1/scopes/:scope_id/members", async (e) => {
1918
2188
  let t = (e.req.query("group_id") ?? "").trim(), r = String(e.req.param("scope_id") ?? "").trim();
1919
2189
  if (!t) return e.json({ error: "group_id_required" }, 400);
1920
2190
  if (!r) return e.json({ error: "scope_id_required" }, 400);
1921
2191
  let i = n();
1922
2192
  try {
1923
- let { auth: n, response: a } = await D(i, t, e);
2193
+ let { auth: n, response: a } = await te(i, t, e);
1924
2194
  if (a) return a;
1925
2195
  if (!n.enrollment) return e.json({ error: "unknown_device" }, 401);
1926
2196
  let o = (await i.listScopes({
@@ -1929,11 +2199,11 @@ function mn(e) {
1929
2199
  })).find((e) => e.scope_id === r) ?? null;
1930
2200
  if (o?.status !== "active") return e.json({ error: "scope_not_found" }, 404);
1931
2201
  let s = await i.listScopeMemberships(r, !1);
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);
2202
+ return s.some((e) => e.device_id === String(n.enrollment?.device_id) && C(e, o)) ? e.json({ items: s.filter((e) => C(e, o)) }) : e.json({ error: "scope_not_authorized" }, 403);
1933
2203
  } finally {
1934
2204
  await i.close();
1935
2205
  }
1936
- }), d.get("/v1/reciprocal-approvals", async (e) => {
2206
+ }), u.get("/v1/reciprocal-approvals", async (e) => {
1937
2207
  let i = (e.req.query("group_id") ?? "").trim(), a = (e.req.query("direction") ?? "incoming").trim(), o = (e.req.query("status") ?? "pending").trim() || "pending";
1938
2208
  if (!i) return e.json({ error: "group_id_required" }, 400);
1939
2209
  if (!["incoming", "outgoing"].includes(a)) return e.json({ error: "direction_must_be_incoming_or_outgoing" }, 400);
@@ -1943,14 +2213,14 @@ function mn(e) {
1943
2213
  method: e.req.method,
1944
2214
  url: e.req.url,
1945
2215
  groupId: i,
1946
- body: new Uint8Array(),
2216
+ body: /* @__PURE__ */ new Uint8Array(),
1947
2217
  deviceId: e.req.header("X-Opencode-Device") ?? null,
1948
2218
  signature: e.req.header("X-Opencode-Signature") ?? null,
1949
2219
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
1950
2220
  nonce: e.req.header("X-Opencode-Nonce") ?? null
1951
2221
  });
1952
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
1953
- let c = p(e, String(n.enrollment.device_id), !0);
2222
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2223
+ let c = f(e, String(n.enrollment.device_id), !0);
1954
2224
  if (c) return c;
1955
2225
  let l = await s.listReciprocalApprovals({
1956
2226
  groupId: i,
@@ -1962,10 +2232,10 @@ function mn(e) {
1962
2232
  } finally {
1963
2233
  await s.close();
1964
2234
  }
1965
- }), d.post("/v1/reciprocal-approvals", async (e) => {
1966
- let i = await m(e);
2235
+ }), u.post("/v1/reciprocal-approvals", async (e) => {
2236
+ let i = await p(e);
1967
2237
  if (i == null) return e.json({ error: "body_too_large" }, 413);
1968
- let a = h(i);
2238
+ let a = m(i);
1969
2239
  if (!a) return e.json({ error: "invalid_json" }, 400);
1970
2240
  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;
1971
2241
  if (!o || !s) return e.json({ error: "group_id_and_requested_device_id_required" }, 400);
@@ -1981,8 +2251,8 @@ function mn(e) {
1981
2251
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
1982
2252
  nonce: e.req.header("X-Opencode-Nonce") ?? null
1983
2253
  });
1984
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
1985
- let a = p(e, String(n.enrollment.device_id), !0);
2254
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2255
+ let a = f(e, String(n.enrollment.device_id), !0);
1986
2256
  if (a) return a;
1987
2257
  if (s === String(n.enrollment.device_id)) return e.json({ error: "requested_device_must_differ" }, 400);
1988
2258
  if (!await l.getEnrollment(o, s)) return e.json({ error: "requested_device_not_found" }, 404);
@@ -1998,18 +2268,18 @@ function mn(e) {
1998
2268
  request: t
1999
2269
  });
2000
2270
  } catch (t) {
2001
- if (t instanceof g) return e.json({ error: t.code }, 409);
2271
+ if (t instanceof Ae) return e.json({ error: t.code }, 409);
2002
2272
  throw t;
2003
2273
  }
2004
2274
  } finally {
2005
2275
  await l.close();
2006
2276
  }
2007
- }), d.post("/v1/invites/add-device", async (e) => {
2008
- let i = await m(e);
2277
+ }), u.post("/v1/invites/add-device", async (e) => {
2278
+ let i = await p(e);
2009
2279
  if (i == null) return e.json({ error: "body_too_large" }, 413);
2010
- let a = h(i);
2280
+ let a = m(i);
2011
2281
  if (!a) return e.json({ error: "invalid_json" }, 400);
2012
- let o = new Set([
2282
+ let o = /* @__PURE__ */ new Set([
2013
2283
  "group_id",
2014
2284
  "expires_at",
2015
2285
  "reviewed_preview_digest",
@@ -2033,14 +2303,14 @@ function mn(e) {
2033
2303
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2034
2304
  nonce: e.req.header("X-Opencode-Nonce") ?? null
2035
2305
  });
2036
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2037
- let o = p(e, String(n.enrollment.device_id), !0);
2306
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2307
+ let o = f(e, String(n.enrollment.device_id), !0);
2038
2308
  if (o) return o;
2039
2309
  let d = n.enrollment.identity_id;
2040
2310
  if (!d || d !== d.trim() || d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "identity_binding_required" }, 403);
2041
- let f;
2311
+ let p;
2042
2312
  try {
2043
- f = await ge(a.reviewed_intent, {
2313
+ p = await it(a.reviewed_intent, {
2044
2314
  target: {
2045
2315
  kind: "add_device",
2046
2316
  targetIdentityId: d
@@ -2048,7 +2318,7 @@ function mn(e) {
2048
2318
  digest: l
2049
2319
  });
2050
2320
  } catch (t) {
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);
2321
+ return t instanceof L && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2052
2322
  }
2053
2323
  let m = await u.createInvite({
2054
2324
  groupId: s,
@@ -2059,7 +2329,7 @@ function mn(e) {
2059
2329
  inviteKind: "add_device",
2060
2330
  targetIdentityId: d,
2061
2331
  reviewedPreviewDigest: l,
2062
- reviewedIntent: f
2332
+ reviewedIntent: p
2063
2333
  }), h = {
2064
2334
  v: 1,
2065
2335
  kind: "add_device",
@@ -2072,45 +2342,45 @@ function mn(e) {
2072
2342
  target_identity_id: m.target_identity_id ?? void 0,
2073
2343
  inviter_device_id: m.inviter_device_id ?? void 0,
2074
2344
  reviewed_preview_digest: m.reviewed_preview_digest ?? void 0
2075
- }, g = G(h), { token: _, ...v } = m;
2345
+ }, g = yn(h), { token: _, ...v } = m;
2076
2346
  return e.json({
2077
2347
  ok: !0,
2078
2348
  invite: v,
2079
2349
  payload: h,
2080
2350
  encoded: g,
2081
- link: K(g)
2351
+ link: xn(g)
2082
2352
  });
2083
2353
  } finally {
2084
2354
  await u.close();
2085
2355
  }
2086
- }), d.post("/v1/admin/devices", async (e) => {
2356
+ }), u.post("/v1/admin/devices", async (e) => {
2087
2357
  let r = Z(e.req.header(X), t);
2088
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2089
- let i = p(e, "admin", !0);
2358
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2359
+ let i = f(e, "admin", !0);
2090
2360
  if (i) return i;
2091
- let a = await m(e);
2361
+ let a = await p(e);
2092
2362
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2093
- let o = h(a);
2363
+ let o = m(a);
2094
2364
  if (!o) return e.json({ error: "invalid_json" }, 400);
2095
2365
  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;
2096
2366
  if (!s || !c || !l || !u) return e.json({ error: "group_id_device_id_fingerprint_public_key_required" }, 400);
2097
- if (ve(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
2098
- let f = n();
2367
+ if (ot(u) !== l) return e.json({ error: "fingerprint_mismatch" }, 400);
2368
+ let h = n();
2099
2369
  try {
2100
- await f.createGroup(s), await f.enrollDevice(s, {
2370
+ await h.createGroup(s), await h.enrollDevice(s, {
2101
2371
  deviceId: c,
2102
2372
  fingerprint: l,
2103
2373
  publicKey: u,
2104
2374
  displayName: d
2105
2375
  });
2106
2376
  } finally {
2107
- await f.close();
2377
+ await h.close();
2108
2378
  }
2109
2379
  return e.json({ ok: !0 });
2110
- }), d.get("/v1/admin/groups", async (e) => {
2380
+ }), u.get("/v1/admin/groups", async (e) => {
2111
2381
  let r = Z(e.req.header(X), t);
2112
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2113
- let i = p(e, "admin", !0);
2382
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2383
+ let i = f(e, "admin", !0);
2114
2384
  if (i) return i;
2115
2385
  let a = [
2116
2386
  "1",
@@ -2122,14 +2392,14 @@ function mn(e) {
2122
2392
  } finally {
2123
2393
  await o.close();
2124
2394
  }
2125
- }), d.post("/v1/admin/groups", async (e) => {
2395
+ }), u.post("/v1/admin/groups", async (e) => {
2126
2396
  let r = Z(e.req.header(X), t);
2127
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2128
- let i = p(e, "admin", !0);
2397
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2398
+ let i = f(e, "admin", !0);
2129
2399
  if (i) return i;
2130
- let a = await m(e);
2400
+ let a = await p(e);
2131
2401
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2132
- let o = h(a);
2402
+ let o = m(a);
2133
2403
  if (!o) return e.json({ error: "invalid_json" }, 400);
2134
2404
  let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim() || null;
2135
2405
  if (!s) return e.json({ error: "group_id_required" }, 400);
@@ -2142,14 +2412,14 @@ function mn(e) {
2142
2412
  } finally {
2143
2413
  await l.close();
2144
2414
  }
2145
- }), d.post("/v1/admin/groups/rename", async (e) => {
2415
+ }), u.post("/v1/admin/groups/rename", async (e) => {
2146
2416
  let r = Z(e.req.header(X), t);
2147
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2148
- let i = p(e, "admin", !0);
2417
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2418
+ let i = f(e, "admin", !0);
2149
2419
  if (i) return i;
2150
- let a = await m(e);
2420
+ let a = await p(e);
2151
2421
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2152
- let o = h(a);
2422
+ let o = m(a);
2153
2423
  if (!o) return e.json({ error: "invalid_json" }, 400);
2154
2424
  let s = String(o.group_id ?? "").trim(), c = String(o.display_name ?? "").trim();
2155
2425
  if (!s || !c) return e.json({ error: "group_id_and_display_name_required" }, 400);
@@ -2162,14 +2432,14 @@ function mn(e) {
2162
2432
  } finally {
2163
2433
  await l.close();
2164
2434
  }
2165
- }), d.post("/v1/admin/groups/archive", async (e) => {
2435
+ }), u.post("/v1/admin/groups/archive", async (e) => {
2166
2436
  let r = Z(e.req.header(X), t);
2167
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2168
- let i = p(e, "admin", !0);
2437
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2438
+ let i = f(e, "admin", !0);
2169
2439
  if (i) return i;
2170
- let a = await m(e);
2440
+ let a = await p(e);
2171
2441
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2172
- let o = h(a);
2442
+ let o = m(a);
2173
2443
  if (!o) return e.json({ error: "invalid_json" }, 400);
2174
2444
  let s = String(o.group_id ?? "").trim();
2175
2445
  if (!s) return e.json({ error: "group_id_required" }, 400);
@@ -2182,14 +2452,14 @@ function mn(e) {
2182
2452
  } finally {
2183
2453
  await c.close();
2184
2454
  }
2185
- }), d.post("/v1/admin/groups/unarchive", async (e) => {
2455
+ }), u.post("/v1/admin/groups/unarchive", async (e) => {
2186
2456
  let r = Z(e.req.header(X), t);
2187
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2188
- let i = p(e, "admin", !0);
2457
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2458
+ let i = f(e, "admin", !0);
2189
2459
  if (i) return i;
2190
- let a = await m(e);
2460
+ let a = await p(e);
2191
2461
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2192
- let o = h(a);
2462
+ let o = m(a);
2193
2463
  if (!o) return e.json({ error: "invalid_json" }, 400);
2194
2464
  let s = String(o.group_id ?? "").trim();
2195
2465
  if (!s) return e.json({ error: "group_id_required" }, 400);
@@ -2202,16 +2472,16 @@ function mn(e) {
2202
2472
  } finally {
2203
2473
  await c.close();
2204
2474
  }
2205
- }), d.get("/v1/admin/groups/:group_id/scopes", async (e) => {
2475
+ }), u.get("/v1/admin/groups/:group_id/scopes", async (e) => {
2206
2476
  let r = Z(e.req.header(X), t);
2207
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2208
- let i = p(e, "admin", !0);
2477
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2478
+ let i = f(e, "admin", !0);
2209
2479
  if (i) return i;
2210
2480
  let a = String(e.req.param("group_id") ?? "").trim(), o = n();
2211
2481
  try {
2212
- let t = await w(o, a, e);
2482
+ let t = await x(o, a, e);
2213
2483
  if (t) return t;
2214
- let n = b(e.req.query("include_inactive"));
2484
+ let n = v(e.req.query("include_inactive"));
2215
2485
  return e.json({ items: await o.listScopes({
2216
2486
  groupId: a,
2217
2487
  includeInactive: n
@@ -2219,33 +2489,33 @@ function mn(e) {
2219
2489
  } finally {
2220
2490
  await o.close();
2221
2491
  }
2222
- }), d.post("/v1/admin/groups/:group_id/scopes", async (e) => {
2492
+ }), u.post("/v1/admin/groups/:group_id/scopes", async (e) => {
2223
2493
  let r = Z(e.req.header(X), t);
2224
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2225
- let i = p(e, "admin", !0);
2494
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2495
+ let i = f(e, "admin", !0);
2226
2496
  if (i) return i;
2227
- let a = await m(e);
2497
+ let a = await p(e);
2228
2498
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2229
- let o = h(a);
2499
+ let o = m(a);
2230
2500
  if (!o) return e.json({ error: "invalid_json" }, 400);
2231
- let s = String(e.req.param("group_id") ?? "").trim(), c = _(o, "scope_id"), l = _(o, "label"), u = y(o, "membership_epoch");
2501
+ let s = String(e.req.param("group_id") ?? "").trim(), c = h(o, "scope_id"), l = h(o, "label"), u = _(o, "membership_epoch");
2232
2502
  if (!c || !l) return e.json({ error: "scope_id_and_label_required" }, 400);
2233
2503
  if (Number.isNaN(u)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2234
2504
  let d = n();
2235
2505
  try {
2236
- let t = await w(d, s, e);
2506
+ let t = await x(d, s, e);
2237
2507
  if (t) return t;
2238
2508
  let n = await d.createScope({
2239
2509
  scopeId: c,
2240
2510
  label: l,
2241
- kind: _(o, "kind"),
2242
- authorityType: _(o, "authority_type"),
2243
- coordinatorId: _(o, "coordinator_id"),
2511
+ kind: h(o, "kind"),
2512
+ authorityType: h(o, "authority_type"),
2513
+ coordinatorId: h(o, "coordinator_id"),
2244
2514
  groupId: s,
2245
- manifestIssuerDeviceId: _(o, "manifest_issuer_device_id"),
2515
+ manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
2246
2516
  membershipEpoch: u,
2247
- manifestHash: _(o, "manifest_hash"),
2248
- status: _(o, "status")
2517
+ manifestHash: h(o, "manifest_hash"),
2518
+ status: h(o, "status")
2249
2519
  });
2250
2520
  return e.json({
2251
2521
  ok: !0,
@@ -2256,33 +2526,33 @@ function mn(e) {
2256
2526
  } finally {
2257
2527
  await d.close();
2258
2528
  }
2259
- }), d.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
2529
+ }), u.patch("/v1/admin/groups/:group_id/scopes/:scope_id", async (e) => {
2260
2530
  let r = Z(e.req.header(X), t);
2261
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2262
- let i = p(e, "admin", !0);
2531
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2532
+ let i = f(e, "admin", !0);
2263
2533
  if (i) return i;
2264
- let a = await m(e);
2534
+ let a = await p(e);
2265
2535
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2266
- let o = h(a);
2536
+ let o = m(a);
2267
2537
  if (!o) return e.json({ error: "invalid_json" }, 400);
2268
- let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = y(o, "membership_epoch");
2538
+ let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = _(o, "membership_epoch");
2269
2539
  if (!c) return e.json({ error: "scope_id_required" }, 400);
2270
2540
  if (Number.isNaN(l)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2271
2541
  let u = n();
2272
2542
  try {
2273
- let t = await E(u, s, c, e);
2543
+ let t = await S(u, s, c, e);
2274
2544
  if (t.response) return t.response;
2275
2545
  let n = await u.updateScope({
2276
2546
  scopeId: c,
2277
- label: o.label === void 0 ? void 0 : _(o, "label"),
2278
- kind: o.kind === void 0 ? void 0 : _(o, "kind"),
2279
- authorityType: o.authority_type === void 0 ? void 0 : _(o, "authority_type"),
2280
- coordinatorId: o.coordinator_id === void 0 ? void 0 : _(o, "coordinator_id"),
2547
+ label: o.label === void 0 ? void 0 : h(o, "label"),
2548
+ kind: o.kind === void 0 ? void 0 : h(o, "kind"),
2549
+ authorityType: o.authority_type === void 0 ? void 0 : h(o, "authority_type"),
2550
+ coordinatorId: o.coordinator_id === void 0 ? void 0 : h(o, "coordinator_id"),
2281
2551
  groupId: s,
2282
- manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : _(o, "manifest_issuer_device_id"),
2552
+ manifestIssuerDeviceId: o.manifest_issuer_device_id === void 0 ? void 0 : h(o, "manifest_issuer_device_id"),
2283
2553
  membershipEpoch: l,
2284
- manifestHash: o.manifest_hash === void 0 ? void 0 : _(o, "manifest_hash"),
2285
- status: o.status === void 0 ? void 0 : _(o, "status")
2554
+ manifestHash: o.manifest_hash === void 0 ? void 0 : h(o, "manifest_hash"),
2555
+ status: o.status === void 0 ? void 0 : h(o, "status")
2286
2556
  });
2287
2557
  return n ? e.json({
2288
2558
  ok: !0,
@@ -2293,48 +2563,48 @@ function mn(e) {
2293
2563
  } finally {
2294
2564
  await u.close();
2295
2565
  }
2296
- }), d.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2566
+ }), u.get("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2297
2567
  let r = Z(e.req.header(X), t);
2298
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2299
- let i = p(e, "admin", !0);
2568
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2569
+ let i = f(e, "admin", !0);
2300
2570
  if (i) return i;
2301
2571
  let a = String(e.req.param("group_id") ?? "").trim(), o = String(e.req.param("scope_id") ?? "").trim(), s = n();
2302
2572
  try {
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"))) });
2573
+ let t = await S(s, a, o, e);
2574
+ return t.response ? t.response : e.json({ items: await s.listScopeMemberships(o, v(e.req.query("include_revoked"))) });
2305
2575
  } finally {
2306
2576
  await s.close();
2307
2577
  }
2308
- }), d.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2578
+ }), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members", async (e) => {
2309
2579
  let r = Z(e.req.header(X), t);
2310
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2311
- let a = p(e, "admin", !0);
2312
- if (a) return a;
2313
- let o = await m(e);
2314
- if (o == null) return e.json({ error: "body_too_large" }, 413);
2315
- let s = h(o);
2316
- if (!s) return e.json({ error: "invalid_json" }, 400);
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");
2318
- if (!u) return e.json({ error: "effect_id_required" }, 400);
2319
- if (!d) return e.json({ error: "device_id_required" }, 400);
2320
- if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2321
- let g = n();
2580
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2581
+ let i = f(e, "admin", !0);
2582
+ if (i) return i;
2583
+ let a = await p(e);
2584
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
2585
+ let o = m(a);
2586
+ if (!o) return e.json({ error: "invalid_json" }, 400);
2587
+ let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = h(o, "effect_id"), u = h(o, "device_id"), d = _(o, "membership_epoch");
2588
+ if (!l) return e.json({ error: "effect_id_required" }, 400);
2589
+ if (!u) return e.json({ error: "device_id_required" }, 400);
2590
+ if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2591
+ let v = n();
2322
2592
  try {
2323
- let t = await E(g, c, l, e);
2593
+ let t = await S(v, s, c, e);
2324
2594
  if (t.response) return t.response;
2325
- let n = await g.grantScopeMembership({
2326
- effectId: u,
2327
- scopeId: l,
2328
- deviceId: d,
2329
- role: _(s, "role"),
2330
- membershipEpoch: f,
2331
- coordinatorId: _(s, "coordinator_id"),
2332
- groupId: c,
2333
- manifestIssuerDeviceId: _(s, "manifest_issuer_device_id"),
2334
- manifestHash: _(s, "manifest_hash"),
2335
- signedManifestJson: _(s, "signed_manifest_json"),
2595
+ let n = await v.grantScopeMembership({
2596
+ effectId: l,
2597
+ scopeId: c,
2598
+ deviceId: u,
2599
+ role: h(o, "role"),
2600
+ membershipEpoch: d,
2601
+ coordinatorId: h(o, "coordinator_id"),
2602
+ groupId: s,
2603
+ manifestIssuerDeviceId: h(o, "manifest_issuer_device_id"),
2604
+ manifestHash: h(o, "manifest_hash"),
2605
+ signedManifestJson: h(o, "signed_manifest_json"),
2336
2606
  actorType: "admin",
2337
- actorId: v(e.req.header(cn))
2607
+ actorId: g(e.req.header(ur))
2338
2608
  });
2339
2609
  return e.json({
2340
2610
  ok: !0,
@@ -2342,67 +2612,67 @@ function mn(e) {
2342
2612
  }, 201);
2343
2613
  } catch (t) {
2344
2614
  let n = t instanceof Error ? t.message : String(t);
2345
- if (t instanceof i && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
2346
- if (t instanceof i && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
2347
- let r = t instanceof i && t.code === "scope_inactive";
2615
+ if (t instanceof N && (t.code === "scope_not_found" || t.code === "scope_group_mismatch")) return e.json({ error: "scope_not_found" }, 404);
2616
+ if (t instanceof N && t.code === "device_not_enrolled") return e.json({ error: "device_not_enrolled_for_scope_group" }, 404);
2617
+ let r = t instanceof N && t.code === "scope_inactive";
2348
2618
  return e.json({ error: r ? "scope_not_active" : n }, n === "scope_membership_effect_conflict" || r ? 409 : 400);
2349
2619
  } finally {
2350
- await g.close();
2620
+ await v.close();
2351
2621
  }
2352
- }), d.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
2622
+ }), u.post("/v1/admin/groups/:group_id/scopes/:scope_id/members/:device_id/revoke", async (e) => {
2353
2623
  let r = Z(e.req.header(X), t);
2354
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2355
- let a = p(e, "admin", !0);
2356
- if (a) return a;
2357
- let o = await m(e);
2358
- if (o == null) return e.json({ error: "body_too_large" }, 413);
2359
- let s = o.byteLength > 0 ? h(o) : {};
2360
- if (!s) return e.json({ error: "invalid_json" }, 400);
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");
2362
- if (!d) return e.json({ error: "effect_id_required" }, 400);
2363
- if (!u) return e.json({ error: "device_id_required" }, 400);
2364
- if (Number.isNaN(f)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2365
- let g = n();
2624
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2625
+ let i = f(e, "admin", !0);
2626
+ if (i) return i;
2627
+ let a = await p(e);
2628
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
2629
+ let o = a.byteLength > 0 ? m(a) : {};
2630
+ if (!o) return e.json({ error: "invalid_json" }, 400);
2631
+ let s = String(e.req.param("group_id") ?? "").trim(), c = String(e.req.param("scope_id") ?? "").trim(), l = String(e.req.param("device_id") ?? "").trim(), u = h(o, "effect_id"), d = _(o, "membership_epoch");
2632
+ if (!u) return e.json({ error: "effect_id_required" }, 400);
2633
+ if (!l) return e.json({ error: "device_id_required" }, 400);
2634
+ if (Number.isNaN(d)) return e.json({ error: "membership_epoch_must_be_number" }, 400);
2635
+ let v = n();
2366
2636
  try {
2367
- let t = await E(g, c, l, e);
2637
+ let t = await S(v, s, c, e);
2368
2638
  if (t.response) return t.response;
2369
- if (!await g.revokeScopeMembership({
2370
- effectId: d,
2371
- scopeId: l,
2372
- deviceId: u,
2373
- groupId: c,
2374
- membershipEpoch: f,
2375
- manifestHash: _(s, "manifest_hash"),
2376
- signedManifestJson: _(s, "signed_manifest_json"),
2639
+ if (!await v.revokeScopeMembership({
2640
+ effectId: u,
2641
+ scopeId: c,
2642
+ deviceId: l,
2643
+ groupId: s,
2644
+ membershipEpoch: d,
2645
+ manifestHash: h(o, "manifest_hash"),
2646
+ signedManifestJson: h(o, "signed_manifest_json"),
2377
2647
  actorType: "admin",
2378
- actorId: v(e.req.header(cn))
2648
+ actorId: g(e.req.header(ur))
2379
2649
  })) return e.json({ error: "membership_not_found" }, 404);
2380
2650
  let n;
2381
2651
  try {
2382
- n = (await g.listScopeMemberships(l, !0)).find((e) => e.device_id === u);
2652
+ n = (await v.listScopeMemberships(c, !0)).find((e) => e.device_id === l);
2383
2653
  } catch {
2384
2654
  n = void 0;
2385
2655
  }
2386
2656
  return e.json({
2387
2657
  ok: !0,
2388
- scope_id: l,
2389
- device_id: u,
2390
- revocation: an({
2391
- scopeId: l,
2392
- deviceId: u,
2393
- membershipEpoch: n?.membership_epoch ?? f
2658
+ scope_id: c,
2659
+ device_id: l,
2660
+ revocation: or({
2661
+ scopeId: c,
2662
+ deviceId: l,
2663
+ membershipEpoch: n?.membership_epoch ?? d
2394
2664
  })
2395
2665
  });
2396
2666
  } catch (t) {
2397
2667
  let n = t instanceof Error ? t.message : String(t);
2398
- return t instanceof i && t.code === "scope_group_mismatch" ? e.json({ error: "scope_not_found" }, 404) : e.json({ error: n }, n === "scope_membership_effect_conflict" ? 409 : 400);
2668
+ return t instanceof N && t.code === "scope_group_mismatch" ? e.json({ error: "scope_not_found" }, 404) : e.json({ error: n }, n === "scope_membership_effect_conflict" ? 409 : 400);
2399
2669
  } finally {
2400
- await g.close();
2670
+ await v.close();
2401
2671
  }
2402
- }), d.get("/v1/admin/devices", async (e) => {
2672
+ }), u.get("/v1/admin/devices", async (e) => {
2403
2673
  let r = Z(e.req.header(X), t);
2404
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2405
- let i = p(e, "admin", !0);
2674
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2675
+ let i = f(e, "admin", !0);
2406
2676
  if (i) return i;
2407
2677
  let a = (e.req.query("group_id") ?? "").trim();
2408
2678
  if (!a) return e.json({ error: "group_id_required" }, 400);
@@ -2416,21 +2686,21 @@ function mn(e) {
2416
2686
  } finally {
2417
2687
  await s.close();
2418
2688
  }
2419
- }), d.post("/v1/admin/devices/rename", async (e) => {
2689
+ }), u.post("/v1/admin/devices/rename", async (e) => {
2420
2690
  let r = Z(e.req.header(X), t);
2421
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2422
- let i = p(e, "admin", !0);
2691
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2692
+ let i = f(e, "admin", !0);
2423
2693
  if (i) return i;
2424
- let a = await m(e);
2694
+ let a = await p(e);
2425
2695
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2426
- let o = h(a);
2696
+ let o = m(a);
2427
2697
  if (!o) return e.json({ error: "invalid_json" }, 400);
2428
2698
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim(), l = String(o.display_name ?? "").trim();
2429
2699
  if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
2430
2700
  if (!l) return e.json({ error: "display_name_required" }, 400);
2431
2701
  let u;
2432
2702
  try {
2433
- u = T(l, "display_name");
2703
+ u = I(l, "display_name");
2434
2704
  } catch (t) {
2435
2705
  return e.json({ error: t instanceof Error ? t.message : "display_name_invalid" }, 400);
2436
2706
  }
@@ -2445,14 +2715,14 @@ function mn(e) {
2445
2715
  } finally {
2446
2716
  await d.close();
2447
2717
  }
2448
- }), d.post("/v1/admin/devices/disable", async (e) => {
2718
+ }), u.post("/v1/admin/devices/disable", async (e) => {
2449
2719
  let r = Z(e.req.header(X), t);
2450
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2451
- let i = p(e, "admin", !0);
2720
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2721
+ let i = f(e, "admin", !0);
2452
2722
  if (i) return i;
2453
- let a = await m(e);
2723
+ let a = await p(e);
2454
2724
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2455
- let o = h(a);
2725
+ let o = m(a);
2456
2726
  if (!o) return e.json({ error: "invalid_json" }, 400);
2457
2727
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
2458
2728
  if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
@@ -2462,14 +2732,14 @@ function mn(e) {
2462
2732
  } finally {
2463
2733
  await l.close();
2464
2734
  }
2465
- }), d.post("/v1/admin/devices/enable", async (e) => {
2735
+ }), u.post("/v1/admin/devices/enable", async (e) => {
2466
2736
  let r = Z(e.req.header(X), t);
2467
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2468
- let i = p(e, "admin", !0);
2737
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2738
+ let i = f(e, "admin", !0);
2469
2739
  if (i) return i;
2470
- let a = await m(e);
2740
+ let a = await p(e);
2471
2741
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2472
- let o = h(a);
2742
+ let o = m(a);
2473
2743
  if (!o) return e.json({ error: "invalid_json" }, 400);
2474
2744
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
2475
2745
  if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
@@ -2479,14 +2749,14 @@ function mn(e) {
2479
2749
  } finally {
2480
2750
  await l.close();
2481
2751
  }
2482
- }), d.post("/v1/admin/devices/remove", async (e) => {
2752
+ }), u.post("/v1/admin/devices/remove", async (e) => {
2483
2753
  let r = Z(e.req.header(X), t);
2484
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2485
- let i = p(e, "admin", !0);
2754
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2755
+ let i = f(e, "admin", !0);
2486
2756
  if (i) return i;
2487
- let a = await m(e);
2757
+ let a = await p(e);
2488
2758
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2489
- let o = h(a);
2759
+ let o = m(a);
2490
2760
  if (!o) return e.json({ error: "invalid_json" }, 400);
2491
2761
  let s = String(o.group_id ?? "").trim(), c = String(o.device_id ?? "").trim();
2492
2762
  if (!s || !c) return e.json({ error: "group_id_and_device_id_required" }, 400);
@@ -2496,49 +2766,127 @@ function mn(e) {
2496
2766
  } finally {
2497
2767
  await l.close();
2498
2768
  }
2499
- }), d.post("/v1/admin/invites", async (e) => {
2769
+ }), u.post("/v1/admin/legacy-team-completions", async (e) => {
2770
+ let r = Z(e.req.header(X), t);
2771
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2772
+ let i = f(e, "admin", !0);
2773
+ if (i) return i;
2774
+ let a = await p(e, lr);
2775
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
2776
+ let o = m(a);
2777
+ if (!o) return e.json({ error: "invalid_json" }, 400);
2778
+ if (Object.keys(o).some((e) => e !== "group_id" && e !== "manifest")) return e.json({ error: "completion_manifest_invalid" }, 400);
2779
+ let s, c;
2780
+ try {
2781
+ let e = de([o.group_id])[0];
2782
+ if (!e) throw Error("completion_manifest_invalid");
2783
+ s = e, c = pe(o.manifest), he(c);
2784
+ } catch {
2785
+ return e.json({ error: "completion_manifest_invalid" }, 400);
2786
+ }
2787
+ let l = n();
2788
+ try {
2789
+ let t = await l.createLegacyTeamCompletion(s, c);
2790
+ return e.json({
2791
+ ok: !0,
2792
+ ...t
2793
+ }, t.status === "created" ? 201 : 200);
2794
+ } catch (t) {
2795
+ if (t instanceof oe) return e.json({ error: t.code }, 409);
2796
+ let n = t instanceof Error ? t.message : "completion_manifest_invalid";
2797
+ if (n === "group_not_found") return e.json({ error: n }, 404);
2798
+ if (n === "group_archived" || n === "completion_manifest_unavailable") return e.json({ error: n }, 409);
2799
+ if (n === "completion_manifest_invalid") return e.json({ error: n }, 400);
2800
+ throw t;
2801
+ } finally {
2802
+ await l.close();
2803
+ }
2804
+ }), u.get("/v1/admin/legacy-team-completions", async (e) => {
2805
+ let r = Z(e.req.header(X), t);
2806
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2807
+ let i = f(e, "admin", !0);
2808
+ if (i) return i;
2809
+ let a = String(e.req.query("group_id") ?? "").trim(), o;
2810
+ try {
2811
+ if (de([a]).length !== 1) throw Error("completion_manifest_invalid");
2812
+ o = fe(e.req.query("candidate_ref"));
2813
+ } catch {
2814
+ return e.json({ error: "group_id_and_candidate_ref_required" }, 400);
2815
+ }
2816
+ let s = n();
2817
+ try {
2818
+ let t = await s.getLegacyTeamCompletion(a, o);
2819
+ return t ? e.json({ manifest: t }) : e.json({ error: "completion_not_found" }, 404);
2820
+ } finally {
2821
+ await s.close();
2822
+ }
2823
+ }), u.post("/v1/admin/legacy-team-completions/query", async (e) => {
2824
+ let r = Z(e.req.header(X), t);
2825
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2826
+ let i = f(e, "admin", !0);
2827
+ if (i) return i;
2828
+ let a = await p(e);
2829
+ if (a == null) return e.json({ error: "body_too_large" }, 413);
2830
+ let o = m(a);
2831
+ if (!o || Object.keys(o).some((e) => e !== "group_ids")) return e.json({ error: "completion_query_invalid" }, 400);
2832
+ let s;
2833
+ try {
2834
+ if (s = de(o.group_ids), s.length === 0) throw Error("completion_query_invalid");
2835
+ } catch {
2836
+ return e.json({ error: "completion_query_invalid" }, 400);
2837
+ }
2838
+ let c = n();
2839
+ try {
2840
+ return e.json({ items: await c.listLegacyTeamCompletions(s) });
2841
+ } catch (t) {
2842
+ if (t instanceof Error && t.message === "completion_results_too_large") return e.json({ error: t.message }, 413);
2843
+ throw t;
2844
+ } finally {
2845
+ await c.close();
2846
+ }
2847
+ }), u.post("/v1/admin/invites", async (e) => {
2500
2848
  let r = Z(e.req.header(X), t);
2501
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2502
- let i = p(e, "admin", !0);
2849
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2850
+ let i = f(e, "admin", !0);
2503
2851
  if (i) return i;
2504
- let a = await m(e);
2852
+ let a = await p(e);
2505
2853
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2506
- let o = h(a);
2854
+ let o = m(a);
2507
2855
  if (!o) return e.json({ error: "invalid_json" }, 400);
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;
2856
+ 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, h = 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, ee = String(o.invite_kind ?? o.kind ?? "").trim(), b = String(o.policy_team_id ?? "").trim() || null, x = String(o.target_identity_id ?? "").trim() || null, S = String(o.reviewed_preview_digest ?? "").trim() || null, te, C = null, w = null;
2509
2857
  if (!s || !["auto_admit", "approval_required"].includes(c) || !l) return e.json({ error: "group_id_policy_and_expires_at_required" }, 400);
2510
2858
  if (Object.hasOwn(o, "assigned_identity_id")) return e.json({ error: "assigned_identity_id_forbidden" }, 400);
2511
2859
  if (Number.isNaN(new Date(l).getTime())) return e.json({ error: "invalid_expires_at" }, 400);
2512
- if (!!d != !!f) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
2513
- let O = b || (d ? "project_share" : "legacy_enrollment");
2860
+ if (!!d != !!h) return e.json({ error: "operation_intent_reference_incomplete" }, 400);
2861
+ let T = ee || (d ? "project_share" : "legacy_enrollment");
2514
2862
  if (![
2515
2863
  "legacy_enrollment",
2516
2864
  "project_share",
2517
2865
  "team_member",
2518
2866
  "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") {
2867
+ ].includes(T)) return e.json({ error: "invite_kind_invalid" }, 400);
2868
+ if (T === "project_share" ? !d : d) return e.json({ error: "invite_kind_intent_mismatch" }, 400);
2869
+ if (S && !/^[a-f0-9]{64}$/u.test(S)) return e.json({ error: "reviewed_preview_digest_invalid" }, 400);
2870
+ if (T === "team_member" && (!b || !S || x) || T === "add_device" && (!x || !S || b) || !["team_member", "add_device"].includes(T) && (b || x || S)) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
2871
+ if ([b, x].filter((e) => !!e).some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "recipient_invite_identifier_invalid" }, 400);
2872
+ if (T === "team_member" || T === "add_device") {
2525
2873
  if (o.reviewed_intent == null) return e.json({ error: "recipient_invite_review_unavailable" }, 400);
2526
2874
  try {
2527
- w = await ge(o.reviewed_intent, {
2528
- target: O === "team_member" ? {
2875
+ te = await it(o.reviewed_intent, {
2876
+ target: T === "team_member" ? {
2529
2877
  kind: "team_member",
2530
- policyTeamId: String(x)
2878
+ policyTeamId: String(b)
2531
2879
  } : {
2532
2880
  kind: "add_device",
2533
- targetIdentityId: String(S)
2881
+ targetIdentityId: String(x)
2534
2882
  },
2535
- digest: String(C)
2883
+ digest: String(S)
2536
2884
  });
2537
2885
  } catch (t) {
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);
2886
+ return t instanceof L && t.code === "recipient_invite_intent_mismatch" ? e.json({ error: t.code }, 409) : e.json({ error: "recipient_invite_review_unavailable" }, 400);
2539
2887
  }
2540
2888
  } else if (o.reviewed_intent != null) return e.json({ error: "recipient_invite_metadata_invalid" }, 400);
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);
2889
+ if (d && !/^share_[a-f0-9]{40}$/u.test(d) || h && !/^[a-f0-9]{64}$/u.test(h)) return e.json({ error: "operation_intent_reference_invalid" }, 400);
2542
2890
  if (d) {
2543
2891
  if (!g || !_ || !v || !y) return e.json({ error: "project_invite_identity_context_required" }, 400);
2544
2892
  if ([
@@ -2547,44 +2895,44 @@ function mn(e) {
2547
2895
  y
2548
2896
  ].some((e) => e.length > 256 || /[\p{Cc}\p{Cf}]/u.test(e))) return e.json({ error: "project_invite_identity_context_invalid" }, 400);
2549
2897
  try {
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) => {
2898
+ if (I(_, "inviter_display_name"), C = Be(o.project_summaries), !Array.isArray(o.project_intent) || o.project_intent.length !== C.length || (w = o.project_intent.map((e, t) => {
2551
2899
  let n;
2552
2900
  try {
2553
- n = Xt([e])[0];
2901
+ n = Zn([e])[0];
2554
2902
  } catch {
2555
2903
  throw Error("project_intent_invalid");
2556
2904
  }
2557
- let r = E?.[t];
2905
+ let r = C?.[t];
2558
2906
  if (!n || !r || n.display_name !== r.display_name || n.existing_memory_count !== r.existing_memory_count) throw Error("project_intent_invalid");
2559
2907
  return n;
2560
- }), new Set(D.map((e) => e.canonical_identity)).size !== D.length)) throw Error("project_intent_invalid");
2908
+ }), new Set(w.map((e) => e.canonical_identity)).size !== w.length)) throw Error("project_intent_invalid");
2561
2909
  } catch (t) {
2562
2910
  return e.json({ error: t instanceof Error ? t.message : "project_invite_invalid" }, 400);
2563
2911
  }
2564
2912
  }
2565
- let A = n();
2913
+ let E = n();
2566
2914
  try {
2567
- let t = await A.getGroup(s);
2915
+ let t = await E.getGroup(s);
2568
2916
  if (!t) return e.json({ error: "group_not_found" }, 404);
2569
2917
  if (t.archived_at) return e.json({ error: "group_archived" }, 409);
2570
- let n = await A.createInvite({
2918
+ let n = await E.createInvite({
2571
2919
  groupId: s,
2572
2920
  policy: c,
2573
2921
  expiresAt: l,
2574
2922
  createdBy: u,
2575
2923
  operationId: d,
2576
- reviewedProjectSetDigest: f,
2924
+ reviewedProjectSetDigest: h,
2577
2925
  inviterActorId: g,
2578
2926
  inviterDisplayName: _,
2579
2927
  inviterDeviceId: v,
2580
2928
  pendingPersonId: y,
2581
- projectSummaries: E,
2582
- projectIntent: D,
2583
- inviteKind: O,
2584
- policyTeamId: x,
2585
- targetIdentityId: S,
2586
- reviewedPreviewDigest: C,
2587
- reviewedIntent: w
2929
+ projectSummaries: C,
2930
+ projectIntent: w,
2931
+ inviteKind: T,
2932
+ policyTeamId: b,
2933
+ targetIdentityId: x,
2934
+ reviewedPreviewDigest: S,
2935
+ reviewedIntent: te
2588
2936
  }), r = {
2589
2937
  v: 1,
2590
2938
  kind: n.invite_kind === "team_member" || n.invite_kind === "add_device" ? n.invite_kind : "coordinator_team_invite",
@@ -2597,7 +2945,7 @@ function mn(e) {
2597
2945
  ...n.operation_id ? {
2598
2946
  operation_id: n.operation_id,
2599
2947
  inviter_name: n.inviter_display_name ?? null,
2600
- project_summaries: E ?? []
2948
+ project_summaries: C ?? []
2601
2949
  } : {},
2602
2950
  ...n.invite_kind === "team_member" ? {
2603
2951
  policy_team_id: n.policy_team_id ?? void 0,
@@ -2609,25 +2957,25 @@ function mn(e) {
2609
2957
  inviter_device_id: n.inviter_device_id ?? void 0,
2610
2958
  reviewed_preview_digest: n.reviewed_preview_digest ?? void 0
2611
2959
  } : {}
2612
- }, i = G(r), { token: a, ...p } = n;
2960
+ }, i = yn(r), { token: a, ...f } = n;
2613
2961
  return e.json({
2614
2962
  ok: !0,
2615
- invite: p,
2963
+ invite: f,
2616
2964
  payload: r,
2617
2965
  encoded: i,
2618
- link: K(i)
2966
+ link: xn(i)
2619
2967
  });
2620
2968
  } catch (t) {
2621
2969
  if (t instanceof Error && t.message === "invite_operation_intent_conflict") return e.json({ error: "invite_operation_intent_conflict" }, 409);
2622
2970
  if (t instanceof Error && t.message === "invite_already_bound") return e.json({ error: "invite_already_bound" }, 409);
2623
2971
  throw t;
2624
2972
  } finally {
2625
- await A.close();
2973
+ await E.close();
2626
2974
  }
2627
- }), d.post("/v1/invites/inspect", async (e) => {
2628
- let r = await m(e);
2975
+ }), u.post("/v1/invites/inspect", async (e) => {
2976
+ let r = await p(e);
2629
2977
  if (r == null) return e.json({ error: "body_too_large" }, 413);
2630
- let i = h(r);
2978
+ let i = m(r);
2631
2979
  if (!i) return e.json({ error: "invalid_json" }, 400);
2632
2980
  let a = String(i.token ?? "").trim();
2633
2981
  if (!a) return e.json({ error: "invite_invalid" }, 404);
@@ -2667,7 +3015,7 @@ function mn(e) {
2667
3015
  if (!n.project_intent_json || !n.project_summaries_json) return e.json({ error: "invite_invalid" }, 404);
2668
3016
  let i;
2669
3017
  try {
2670
- i = C(n.project_summaries_json);
3018
+ i = b(n.project_summaries_json);
2671
3019
  } catch {
2672
3020
  return e.json({ error: "invite_invalid" }, 409);
2673
3021
  }
@@ -2682,10 +3030,10 @@ function mn(e) {
2682
3030
  } finally {
2683
3031
  await o.close();
2684
3032
  }
2685
- }), d.get("/v1/admin/invites", async (e) => {
3033
+ }), u.get("/v1/admin/invites", async (e) => {
2686
3034
  let r = Z(e.req.header(X), t);
2687
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2688
- let i = p(e, "admin", !0);
3035
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3036
+ let i = f(e, "admin", !0);
2689
3037
  if (i) return i;
2690
3038
  let a = (e.req.query("group_id") ?? "").trim();
2691
3039
  if (!a) return e.json({ error: "group_id_required" }, 400);
@@ -2696,7 +3044,7 @@ function mn(e) {
2696
3044
  } finally {
2697
3045
  await o.close();
2698
3046
  }
2699
- }), d.get("/v1/admin/project-invites/:operationId", async (e) => {
3047
+ }), u.get("/v1/admin/project-invites/:operationId", async (e) => {
2700
3048
  let r = Z(e.req.header(X), t);
2701
3049
  if (!r.ok) return e.json({ error: r.error }, 401);
2702
3050
  let i = String(e.req.param("operationId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
@@ -2707,7 +3055,7 @@ function mn(e) {
2707
3055
  if (!n) return e.json({ error: "operation_not_found" }, 404);
2708
3056
  let r;
2709
3057
  try {
2710
- r = x(n.project_intent_json);
3058
+ r = y(n.project_intent_json);
2711
3059
  } catch {
2712
3060
  return e.json({ error: "operation_intent_invalid" }, 409);
2713
3061
  }
@@ -2717,7 +3065,7 @@ function mn(e) {
2717
3065
  display_name: String(e.display_name ?? ""),
2718
3066
  existing_memory_count: Number(e.existing_memory_count ?? 0)
2719
3067
  }));
2720
- s = K(G({
3068
+ s = xn(yn({
2721
3069
  v: 1,
2722
3070
  kind: "coordinator_team_invite",
2723
3071
  coordinator_url: new URL(e.req.url).origin,
@@ -2752,10 +3100,10 @@ function mn(e) {
2752
3100
  } finally {
2753
3101
  await o.close();
2754
3102
  }
2755
- }), d.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
3103
+ }), u.get("/v1/admin/bootstrap-grants/:grantId", async (e) => {
2756
3104
  let r = Z(e.req.header(X), t);
2757
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2758
- let i = p(e, "admin", !0);
3105
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3106
+ let i = f(e, "admin", !0);
2759
3107
  if (i) return i;
2760
3108
  let a = String(e.req.param("grantId") ?? "").trim();
2761
3109
  if (!a) return e.json({ error: "grant_id_required" }, 400);
@@ -2773,7 +3121,7 @@ function mn(e) {
2773
3121
  } finally {
2774
3122
  await o.close();
2775
3123
  }
2776
- }), d.get("/v1/bootstrap-grants/:grantId", async (e) => {
3124
+ }), u.get("/v1/bootstrap-grants/:grantId", async (e) => {
2777
3125
  let i = String(e.req.param("grantId") ?? "").trim(), a = String(e.req.query("group_id") ?? "").trim();
2778
3126
  if (!i || !a) return e.json({ error: "grant_id_and_group_id_required" }, 400);
2779
3127
  let o = n();
@@ -2782,14 +3130,14 @@ function mn(e) {
2782
3130
  method: e.req.method,
2783
3131
  url: e.req.url,
2784
3132
  groupId: a,
2785
- body: new Uint8Array(),
3133
+ body: /* @__PURE__ */ new Uint8Array(),
2786
3134
  deviceId: e.req.header("X-Opencode-Device") ?? null,
2787
3135
  signature: e.req.header("X-Opencode-Signature") ?? null,
2788
3136
  timestamp: e.req.header("X-Opencode-Timestamp") ?? null,
2789
3137
  nonce: e.req.header("X-Opencode-Nonce") ?? null
2790
3138
  });
2791
- if (!n.ok || !n.enrollment) return p(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
2792
- let s = p(e, String(n.enrollment.device_id), !0);
3139
+ if (!n.ok || !n.enrollment) return f(e, e.req.path, !1) ?? e.json({ error: n.error }, $(n.error));
3140
+ let s = f(e, String(n.enrollment.device_id), !0);
2793
3141
  if (s) return s;
2794
3142
  let c = await o.getBootstrapGrant(i);
2795
3143
  if (!c || c.group_id !== a || c.seed_device_id !== String(n.enrollment.device_id)) return e.json({ error: "grant_not_found" }, 404);
@@ -2801,10 +3149,10 @@ function mn(e) {
2801
3149
  } finally {
2802
3150
  await o.close();
2803
3151
  }
2804
- }), d.get("/v1/admin/bootstrap-grants", async (e) => {
3152
+ }), u.get("/v1/admin/bootstrap-grants", async (e) => {
2805
3153
  let r = Z(e.req.header(X), t);
2806
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2807
- let i = p(e, "admin", !0);
3154
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3155
+ let i = f(e, "admin", !0);
2808
3156
  if (i) return i;
2809
3157
  let a = (e.req.query("group_id") ?? "").trim();
2810
3158
  if (!a) return e.json({ error: "group_id_required" }, 400);
@@ -2814,14 +3162,14 @@ function mn(e) {
2814
3162
  } finally {
2815
3163
  await o.close();
2816
3164
  }
2817
- }), d.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
3165
+ }), u.post("/v1/admin/bootstrap-grants/revoke", async (e) => {
2818
3166
  let r = Z(e.req.header(X), t);
2819
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2820
- let i = p(e, "admin", !0);
3167
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3168
+ let i = f(e, "admin", !0);
2821
3169
  if (i) return i;
2822
- let a = await m(e);
3170
+ let a = await p(e);
2823
3171
  if (a == null) return e.json({ error: "body_too_large" }, 413);
2824
- let o = h(a);
3172
+ let o = m(a);
2825
3173
  if (!o) return e.json({ error: "invalid_json" }, 400);
2826
3174
  let s = String(o.grant_id ?? "").trim();
2827
3175
  if (!s) return e.json({ error: "grant_id_required" }, 400);
@@ -2834,18 +3182,18 @@ function mn(e) {
2834
3182
  } finally {
2835
3183
  await c.close();
2836
3184
  }
2837
- }), d.post("/v1/admin/join-requests/approve", async (e) => hn(e, !0, {
3185
+ }), u.post("/v1/admin/join-requests/approve", async (e) => _r(e, !0, {
2838
3186
  createStore: n,
2839
3187
  runtime: t,
2840
- rateLimitedResponse: p
2841
- })), d.post("/v1/admin/join-requests/deny", async (e) => hn(e, !1, {
3188
+ rateLimitedResponse: f
3189
+ })), u.post("/v1/admin/join-requests/deny", async (e) => _r(e, !1, {
2842
3190
  createStore: n,
2843
3191
  runtime: t,
2844
- rateLimitedResponse: p
2845
- })), d.get("/v1/admin/join-requests", async (e) => {
3192
+ rateLimitedResponse: f
3193
+ })), u.get("/v1/admin/join-requests", async (e) => {
2846
3194
  let r = Z(e.req.header(X), t);
2847
- if (!r.ok) return p(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
2848
- let i = p(e, "admin", !0);
3195
+ if (!r.ok) return f(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3196
+ let i = f(e, "admin", !0);
2849
3197
  if (i) return i;
2850
3198
  let a = (e.req.query("group_id") ?? "").trim();
2851
3199
  if (!a) return e.json({ error: "group_id_required" }, 400);
@@ -2855,23 +3203,23 @@ function mn(e) {
2855
3203
  } finally {
2856
3204
  await o.close();
2857
3205
  }
2858
- }), d.post("/v1/join", async (e) => {
2859
- let r = await m(e);
3206
+ }), u.post("/v1/join", async (e) => {
3207
+ let r = await p(e);
2860
3208
  if (r == null) return e.json({ error: "body_too_large" }, 413);
2861
- let i = h(r);
3209
+ let i = m(r);
2862
3210
  if (!i) return e.json({ error: "invalid_json" }, 400);
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();
3211
+ 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(), h = String(i.device_display_name ?? "").trim();
2864
3212
  if (!a || !o || !s || !c) return e.json({ error: "token_device_id_fingerprint_public_key_required" }, 400);
2865
- if (ve(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
3213
+ if (ot(c) !== s) return e.json({ error: "fingerprint_mismatch" }, 400);
2866
3214
  let g = n();
2867
3215
  try {
2868
3216
  let n = await g.getInviteByTokenForInspection(a);
2869
3217
  if (!n) return e.json({ error: "invite_invalid" }, 404);
2870
- let r = !!(n.operation_id || n.reviewed_project_set_digest), m = n.invite_kind === "team_member" || n.invite_kind === "add_device";
2871
- if (n.revoked_at) return e.json({ error: r || m ? "invite_invalid" : "revoked_token" }, 400);
2872
- if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || m ? "invite_expired" : "expired_token" }, 410);
2873
- if (m) {
2874
- let r = new Set([
3218
+ let r = !!(n.operation_id || n.reviewed_project_set_digest), p = n.invite_kind === "team_member" || n.invite_kind === "add_device";
3219
+ if (n.revoked_at) return e.json({ error: r || p ? "invite_invalid" : "revoked_token" }, 400);
3220
+ if (!n.consumed_at && new Date(n.expires_at) <= new Date(t.now())) return e.json({ error: r || p ? "invite_expired" : "expired_token" }, 410);
3221
+ if (p) {
3222
+ let r = /* @__PURE__ */ new Set([
2875
3223
  "token",
2876
3224
  "invite_kind",
2877
3225
  "kind",
@@ -2890,11 +3238,11 @@ function mn(e) {
2890
3238
  try {
2891
3239
  if (i.recipient_display_name != null) {
2892
3240
  if (typeof i.recipient_display_name != "string") throw Error("recipient_display_name_invalid");
2893
- d = T(i.recipient_display_name, "recipient_display_name");
3241
+ d = I(i.recipient_display_name, "recipient_display_name");
2894
3242
  }
2895
3243
  if (i.device_display_name != null) {
2896
3244
  if (typeof i.device_display_name != "string") throw Error("device_display_name_invalid");
2897
- f = T(i.device_display_name, "device_display_name");
3245
+ f = I(i.device_display_name, "device_display_name");
2898
3246
  }
2899
3247
  } catch (t) {
2900
3248
  return e.json({ error: t instanceof Error ? t.message : "recipient_invite_identity_invalid" }, 400);
@@ -2932,7 +3280,7 @@ function mn(e) {
2932
3280
  }
2933
3281
  }
2934
3282
  if (n.operation_id || n.reviewed_project_set_digest) {
2935
- let r = new Set([
3283
+ let r = /* @__PURE__ */ new Set([
2936
3284
  "token",
2937
3285
  "operation_id",
2938
3286
  "device_id",
@@ -2944,18 +3292,18 @@ function mn(e) {
2944
3292
  "device_display_name"
2945
3293
  ]);
2946
3294
  if (Object.keys(i).some((e) => !r.has(e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
2947
- if (!u || !d || !f || !p) return e.json({ error: "project_invite_identity_required" }, 400);
3295
+ if (!u || !d || !f || !h) return e.json({ error: "project_invite_identity_required" }, 400);
2948
3296
  if (String(n.inviter_device_id ?? "").trim() === o) return e.json({ error: "project_invite_self_acceptance_forbidden" }, 409);
2949
3297
  if (d.length > 256 || /[\p{Cc}\p{Cf}]/u.test(d)) return e.json({ error: "recipient_actor_id_invalid" }, 400);
2950
- let l, m;
3298
+ let l, p;
2951
3299
  try {
2952
- l = T(f, "recipient_display_name"), m = T(p, "device_display_name");
3300
+ l = I(f, "recipient_display_name"), p = I(h, "device_display_name");
2953
3301
  } catch (t) {
2954
3302
  return e.json({ error: t instanceof Error ? t.message : "project_invite_identity_invalid" }, 400);
2955
3303
  }
2956
- let h;
3304
+ let m;
2957
3305
  try {
2958
- h = S(n);
3306
+ m = ee(n);
2959
3307
  } catch {
2960
3308
  return e.json({ error: "operation_intent_invalid" }, 409);
2961
3309
  }
@@ -2968,12 +3316,12 @@ function mn(e) {
2968
3316
  fingerprint: s,
2969
3317
  recipientActorId: d,
2970
3318
  recipientDisplayName: l,
2971
- deviceDisplayName: m,
3319
+ deviceDisplayName: p,
2972
3320
  now: t.now()
2973
3321
  });
2974
3322
  return e.json({
2975
3323
  ok: !0,
2976
- status: Tt,
3324
+ status: Cn,
2977
3325
  group_id: n.invite.group_id,
2978
3326
  operation_id: n.invite.operation_id,
2979
3327
  trust_state: n.invite.trust_state,
@@ -2984,7 +3332,7 @@ function mn(e) {
2984
3332
  fingerprint: n.seed_enrollment.fingerprint,
2985
3333
  display_name: n.seed_enrollment.display_name
2986
3334
  } : null,
2987
- accepted_project_intent: h
3335
+ accepted_project_intent: m
2988
3336
  });
2989
3337
  } catch (t) {
2990
3338
  let n = t instanceof Error ? t.message : "invite_invalid", r = n === "invite_expired" ? 410 : n === "invite_invalid" ? 404 : 409;
@@ -2997,9 +3345,9 @@ function mn(e) {
2997
3345
  "recipient_display_name",
2998
3346
  "device_display_name"
2999
3347
  ].some((e) => Object.hasOwn(i, e))) return e.json({ error: "unexpected_project_invite_fields" }, 400);
3000
- let h = await g.getGroup(String(n.group_id));
3001
- if (!h) return e.json({ error: "group_not_found" }, 404);
3002
- if (h.archived_at) return e.json({ error: "group_archived" }, 409);
3348
+ let m = await g.getGroup(String(n.group_id));
3349
+ if (!m) return e.json({ error: "group_not_found" }, 404);
3350
+ if (m.archived_at) return e.json({ error: "group_archived" }, 409);
3003
3351
  let _ = String(n.group_id);
3004
3352
  if (await g.getEnrollment(_, o)) return e.json({
3005
3353
  ok: !0,
@@ -3040,25 +3388,25 @@ function mn(e) {
3040
3388
  } finally {
3041
3389
  await g.close();
3042
3390
  }
3043
- }), d;
3391
+ }), u;
3044
3392
  }
3045
- async function hn(e, t, n) {
3393
+ async function _r(e, t, n) {
3046
3394
  let r = Z(e.req.header(X), n.runtime);
3047
3395
  if (!r.ok) return n.rateLimitedResponse(e, e.req.path, !1) ?? e.json({ error: r.error }, 401);
3048
3396
  let i = n.rateLimitedResponse(e, "admin", !0);
3049
3397
  if (i) return i;
3050
3398
  let a = await (async () => {
3051
3399
  let t = Number.parseInt(e.req.header("content-length") ?? "", 10);
3052
- if (Number.isFinite(t) && t > sn) return null;
3400
+ if (Number.isFinite(t) && t > cr) return null;
3053
3401
  let n = e.req.raw.body;
3054
- if (!n) return new Uint8Array();
3402
+ if (!n) return /* @__PURE__ */ new Uint8Array();
3055
3403
  let r = n.getReader(), i = [], a = 0;
3056
3404
  try {
3057
3405
  for (;;) {
3058
3406
  let { done: e, value: t } = await r.read();
3059
3407
  if (e) break;
3060
3408
  if (t) {
3061
- if (a += t.byteLength, a > sn) return await r.cancel(), null;
3409
+ if (a += t.byteLength, a > cr) return await r.cancel(), null;
3062
3410
  i.push(t);
3063
3411
  }
3064
3412
  }
@@ -3106,6 +3454,6 @@ async function hn(e, t, n) {
3106
3454
  }
3107
3455
  }
3108
3456
  //#endregion
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 };
3457
+ export { E as $, at as A, ke as B, Sn as C, g as Ct, L as D, n as Dt, Ve as E, i as Et, Re as F, Ce as G, Te as H, I, be as J, xe as K, F as L, it as M, ze as N, nt as O, Le as P, ie as Q, Be as R, yn as S, te as St, ot as T, a as Tt, Oe as U, De as V, N as W, ae as X, Se as Y, ne as Z, wn as _, _ as _t, ar as a, fe as at, Dn as b, x as bt, Zn as c, ge as ct, jn as d, v as dt, w as et, In as f, h as ft, Cn as g, u as gt, q as h, l as ht, or as i, me as it, rt as j, tt as k, Yn as l, _e as lt, Kn as m, S as mt, sr as n, C as nt, qn as o, de as ot, Gn as p, o as pt, we as q, ir as r, oe as rt, Xn as s, pe as st, gr as t, T as tt, Mn as u, he as ut, Tn as v, y as vt, xn as w, r as wt, bn as x, ee as xt, En as y, b as yt, Ae as z };
3110
3458
 
3111
- //# sourceMappingURL=coordinator-api-DGTIU3Ri.js.map
3459
+ //# sourceMappingURL=coordinator-api-BAufmPEa.js.map