@vite-hub/comments 0.5.1 → 0.6.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 (55) hide show
  1. package/README.md +21 -4
  2. package/dist/{client-diagnostics-CvfTW5d4.js → client-diagnostics-D987sEK7.js} +4 -0
  3. package/dist/client.d.ts +96 -19
  4. package/dist/client.js +525 -79
  5. package/dist/{console-CK2F53QP.d.ts → console-CCLX_eIk.d.ts} +1 -1
  6. package/dist/{database-BkPoOdZr.js → database-Cguz3hZL.js} +1 -1
  7. package/dist/database.js +1 -1
  8. package/dist/{define-9uMM3Ewc.js → define-C2tnAtBU.js} +2 -2
  9. package/dist/{errors-DFNiJg67.js → errors-ByCRdInk.js} +1 -1
  10. package/dist/hosted/hosted-comments/{client-B3dlmmQd.js → client-Czl2zu9P.js} +3 -3
  11. package/dist/hosted/hosted-comments/frame.js +1 -1
  12. package/dist/hosted/hosted-comments/overlay-DpS0P-nd.js +186 -0
  13. package/dist/hosted/hosted-comments/protocol-DuB0Zhs-.js +1 -0
  14. package/dist/hosted/hosted-comments/rest-transport-CKZG_jZ4.js +1 -0
  15. package/dist/hosted/hosted-comments/tools-D8xg-kDW.js +126 -0
  16. package/dist/hosted/hosted-comments.js +13 -3
  17. package/dist/{index-BEnHTj2Z.d.ts → index-D1T7RJ4R.d.ts} +5 -2
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +11 -10
  20. package/dist/{install-B-FQpi47.d.ts → install-9L4ASzUC.d.ts} +11 -2
  21. package/dist/{install-BUXxryut.js → install-D6hXZaSN.js} +45 -19
  22. package/dist/{installed-C9SkldMi.js → installed-bPUnazFf.js} +1 -1
  23. package/dist/{operations-CKC_lMG_.js → operations-B1ALn4VS.js} +7 -7
  24. package/dist/{operations-Cic9A9e_.d.ts → operations-BkkrI8a3.d.ts} +1 -1
  25. package/dist/operations.d.ts +2 -2
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/{client-CerbVjTz.js → client-C7ftI-CB.js} +3 -3
  28. package/dist/overlay/overlay.js +42 -16
  29. package/dist/page/loader.js +1 -1
  30. package/dist/{page-xzgZ6DGm.js → page-2NzFladc.js} +5 -1
  31. package/dist/{plugin-B2hETRii.js → plugin-l4sPt5-n.js} +13 -7
  32. package/dist/realtime.d.ts +11 -3
  33. package/dist/realtime.js +14 -6
  34. package/dist/{rpc-BKY7XRlR.js → rpc-BYmbVkr8.js} +1 -1
  35. package/dist/rpc.js +1 -1
  36. package/dist/runtime/auth.js +1 -1
  37. package/dist/runtime/console.d.ts +1 -1
  38. package/dist/runtime/console.js +2 -2
  39. package/dist/runtime/index.d.ts +42 -10
  40. package/dist/runtime/index.js +16 -8
  41. package/dist/{server-BGbD7H5s.js → server-DvSehkPP.js} +1 -1
  42. package/dist/server.d.ts +3 -3
  43. package/dist/server.js +6 -6
  44. package/dist/{service-DDD4Ubxd.js → service-BIGe1Hpo.js} +11 -6
  45. package/dist/{service-CPiWPoiY.d.ts → service-IvgrI4XM.d.ts} +2 -0
  46. package/dist/{session-BGN6Vlm6.js → session-CCRLR9bf.js} +24 -9
  47. package/dist/{session-CTh9nisq.d.ts → session-CN4irEqf.d.ts} +1 -1
  48. package/dist/testing.js +1 -1
  49. package/dist/vite.d.ts +19 -2
  50. package/dist/vite.js +39 -10
  51. package/package.json +7 -7
  52. package/dist/hosted/hosted-comments/overlay-4-mWX4Uz.js +0 -170
  53. package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +0 -1
  54. package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +0 -1
  55. package/dist/hosted/hosted-comments/tools-CdwnUCOr.js +0 -126
package/dist/client.js CHANGED
@@ -1,8 +1,8 @@
1
- import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-CvfTW5d4.js";
1
+ import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-D987sEK7.js";
2
2
  import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-lC6X7XyS.js";
3
3
  import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
5
- import { i as commentsRoute } from "./page-xzgZ6DGm.js";
4
+ import { t as commentsErrorDiagnostics } from "./errors-ByCRdInk.js";
5
+ import { o as commentsRoute } from "./page-2NzFladc.js";
6
6
  import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
7
7
  import { t as foldName } from "./fold-name-g-xg0mQk.js";
8
8
  // ../internal/src/browser-environment.ts
@@ -146,9 +146,9 @@ function requested(request) {
146
146
  request.onerror = () => reject(request.error ?? /* @__PURE__ */ new Error("The IndexedDB request failed."));
147
147
  });
148
148
  }
149
- function openDatabase() {
149
+ function openDatabase(name) {
150
150
  return new Promise((resolve, reject) => {
151
- const request = indexedDB.open(databaseName, format);
151
+ const request = indexedDB.open(name, format);
152
152
  request.onupgradeneeded = (event) => {
153
153
  const drafts = request.result.createObjectStore("drafts", { keyPath: ["account", "id"] });
154
154
  drafts.createIndex("account", "account");
@@ -184,9 +184,12 @@ function openDatabase() {
184
184
  * does not open, as in some private windows, it keeps the entries in memory and `persisted` is `false`.
185
185
  */
186
186
  function createIndexedDBOutboxStore() {
187
+ return indexedDBOutboxStore(databaseName);
188
+ }
189
+ function indexedDBOutboxStore(name) {
187
190
  let backend;
188
191
  let persisted = typeof indexedDB !== "undefined";
189
- const open = () => backend ??= (persisted ? openDatabase() : Promise.reject(/* @__PURE__ */ new Error("No IndexedDB."))).then((database) => ({ database }), () => {
192
+ const open = () => backend ??= (persisted ? openDatabase(name) : Promise.reject(/* @__PURE__ */ new Error("No IndexedDB."))).then((database) => ({ database }), () => {
190
193
  persisted = false;
191
194
  return { memory: createMemoryOutboxStore() };
192
195
  });
@@ -226,7 +229,6 @@ function createIndexedDBOutboxStore() {
226
229
  })
227
230
  };
228
231
  }
229
- /** The error of a try, as plain data that the store keeps. */
230
232
  function deliveryError(error) {
231
233
  const field = (name) => error && typeof error === "object" ? Reflect.get(error, name) : void 0;
232
234
  const status = field("status");
@@ -242,7 +244,6 @@ function deliveryError(error) {
242
244
  ...typeof retryAfter === "number" && retryAfter >= 0 ? { retryAfter } : {}
243
245
  };
244
246
  }
245
- /** `wait`: try again later. `hold`: wait for `retry()`, such as after a sign-in or a plan upgrade. `fail`: the server refused this entry. */
246
247
  function outcomeOf(status) {
247
248
  if (status === 401 || status === 402) return "hold";
248
249
  if (status === 408 || status === 429) return "wait";
@@ -250,14 +251,32 @@ function outcomeOf(status) {
250
251
  }
251
252
  /** The outbox of one client. */
252
253
  function createOutbox(options, host) {
253
- const { account } = options;
254
- const store = options.store ?? createIndexedDBOutboxStore();
254
+ const { account, namespace } = options;
255
+ const scopedChannel = namespace === void 0 ? channel : `${channel}:${JSON.stringify(namespace)}`;
256
+ const hasLocks = Boolean(options.environment || globalThis.navigator?.locks);
257
+ const stageFiles = Boolean(options.store && !hasLocks);
258
+ const store = options.store ?? (hasLocks ? indexedDBOutboxStore(scopedChannel) : createMemoryOutboxStore());
255
259
  const environment = options.environment ?? createBrowserEnvironment({
256
- channel,
260
+ channel: scopedChannel,
257
261
  isMessage: isOutboxMessage
258
262
  });
259
- const lockName = `vitehub-comments-outbox:${account}`;
263
+ const queue = namespace === void 0 ? account : JSON.stringify([namespace, account]);
264
+ const storeKey = options.store ? queue : account;
265
+ const lockName = `vitehub-comments-outbox:${queue}`;
266
+ const filesLock = (id) => `vitehub-comments-files:${queue}:${id}`;
260
267
  let entries = [];
268
+ let stored = [];
269
+ const unsaved = /* @__PURE__ */ new Map();
270
+ const arriving = /* @__PURE__ */ new Map();
271
+ const blockedFiles = /* @__PURE__ */ new Map();
272
+ const aliases = /* @__PURE__ */ new Map();
273
+ const entryId = (id) => aliases.get(id) ?? id;
274
+ const queueListeners = /* @__PURE__ */ new Set();
275
+ const queueChanged = () => {
276
+ for (const listener of queueListeners) listener();
277
+ };
278
+ const written = /* @__PURE__ */ new Set();
279
+ let lastOrder = 0;
261
280
  const sent = /* @__PURE__ */ new Map();
262
281
  const receipts = /* @__PURE__ */ new Map();
263
282
  const keyOf = (entry) => entry.kind === "create" ? JSON.stringify([
@@ -275,10 +294,12 @@ function createOutbox(options, host) {
275
294
  let loading = Promise.resolve();
276
295
  let leading;
277
296
  let again = false;
297
+ let stopped = false;
278
298
  let cancelWait;
279
299
  const post = (message) => environment.post(message);
280
300
  const reload = () => loading = loading.catch(() => void 0).then(async () => {
281
- const pending = await store.list(account);
301
+ const landed = [...unsaved].flatMap(([id, local]) => local.saved ? [id] : []);
302
+ const pending = await store.list(storeKey);
282
303
  const ids = /* @__PURE__ */ new Map();
283
304
  if (globalThis.crypto?.subtle) await Promise.all(pending.map(async (entry) => {
284
305
  if (entry.kind !== "reply") return;
@@ -287,22 +308,49 @@ function createOutbox(options, host) {
287
308
  ids.set(key, replyIds.get(key) ?? await replyMessageId(threadId, entry.requestId));
288
309
  }));
289
310
  replyIds = ids;
290
- entries = pending;
291
- host.changed();
311
+ stored = pending;
312
+ for (const id of landed) unsaved.delete(id);
313
+ merge();
292
314
  });
315
+ const merge = () => {
316
+ const ids = new Set(stored.map((entry) => entry.id));
317
+ entries = sortEntries([...stored, ...[...unsaved.values()].flatMap((local) => ids.has(local.entry.id) || local.duplicate ? [] : [local.entry])]).map((entry) => {
318
+ const blocked = blockedFiles.get(entry.id);
319
+ return blocked ? {
320
+ ...entry,
321
+ status: "failed",
322
+ files: [...entry.files, ...blocked.files],
323
+ error: blocked.error
324
+ } : entry;
325
+ });
326
+ guardUnload(!store.persisted && entries.length > 0 || blockedFiles.size > 0 || [...unsaved.values()].some((local) => !local.saved));
327
+ host.changed();
328
+ queueChanged();
329
+ };
330
+ let guarded = false;
331
+ const holdPage = (event) => {
332
+ event.preventDefault();
333
+ Reflect.set(event, "returnValue", "");
334
+ };
335
+ const guardUnload = (on) => {
336
+ if (on === guarded || typeof globalThis.addEventListener !== "function") return;
337
+ guarded = on;
338
+ if (on) globalThis.addEventListener("beforeunload", holdPage);
339
+ else globalThis.removeEventListener("beforeunload", holdPage);
340
+ };
293
341
  const changed = async () => {
294
342
  await reload();
295
343
  post({
296
344
  type: "change",
297
- account
345
+ account: queue
298
346
  });
299
347
  };
300
348
  const serverThread = (id) => {
301
349
  for (const thread of host.threads()) if (thread.id === id) return thread;
302
350
  };
303
- /** The server id of a thread that the client may still name by its local id. */
304
351
  const realId = (threadId) => {
305
- return sent.get(threadId)?.id ?? threadId;
352
+ const id = entryId(threadId);
353
+ return sent.get(id)?.id ?? id;
306
354
  };
307
355
  const delivery = (entry) => ({
308
356
  status: entry.status === "failed" ? "failed" : "pending",
@@ -372,11 +420,15 @@ function createOutbox(options, host) {
372
420
  delivery: delivery(entry)
373
421
  };
374
422
  };
375
- /** The first entry that may go out now. A reply waits while its comment has not gone out. */
376
423
  const next = (list) => {
377
- const waiting = new Set(list.flatMap((entry) => entry.kind === "create" ? [entry.id] : []));
424
+ const waiting = new Set([...list, ...[...unsaved.values()].map((local) => local.entry)].flatMap((entry) => entry.kind === "create" ? [entry.id] : []));
378
425
  return list.find((entry) => entry.status !== "failed" && !(entry.kind === "reply" && waiting.has(entry.input.threadId)));
379
426
  };
427
+ const saving = (order) => [...unsaved.values()].some((local) => !local.saved && !local.parked && local.entry.status !== "failed" && local.entry.order < order);
428
+ const aborted = (signal) => new Promise((resolve) => {
429
+ if (signal.aborted) resolve();
430
+ else signal.addEventListener("abort", () => resolve(), { once: true });
431
+ });
380
432
  const wait = (ms) => {
381
433
  cancelWait?.();
382
434
  cancelWait = environment.schedule(() => {
@@ -384,7 +436,7 @@ function createOutbox(options, host) {
384
436
  kick();
385
437
  }, ms);
386
438
  };
387
- const update = (change) => store.update(account, change);
439
+ const update = (change) => store.update(storeKey, change);
388
440
  const send = async (entry) => {
389
441
  const withClaim = (change) => update((drafts) => {
390
442
  const current = drafts.get(entry.id);
@@ -469,7 +521,7 @@ function createOutbox(options, host) {
469
521
  await reload();
470
522
  post({
471
523
  type: "sent",
472
- account,
524
+ account: queue,
473
525
  id: entry.id,
474
526
  kind: entry.kind,
475
527
  key,
@@ -484,7 +536,8 @@ function createOutbox(options, host) {
484
536
  const selected = await update((drafts) => {
485
537
  if (signal.aborted) return;
486
538
  const entry = next(sortEntries([...drafts.values()]));
487
- if (!entry || entry.held) return;
539
+ if (!entry || entry.held || saving(entry.order)) return;
540
+ if (entry.awaitingFiles) return { files: entry.id };
488
541
  const delay = (entry.retryAt ?? 0) - Date.now();
489
542
  if (delay > 0) return { delay };
490
543
  const claimed = {
@@ -497,16 +550,30 @@ function createOutbox(options, host) {
497
550
  return { claimed };
498
551
  });
499
552
  if (!selected) return;
500
- if (selected.delay !== void 0) {
553
+ if ("delay" in selected) {
501
554
  wait(selected.delay);
502
555
  return;
503
556
  }
557
+ if ("files" in selected) {
558
+ if (stageFiles || arriving.has(selected.files)) return;
559
+ await Promise.race([environment.lock(filesLock(selected.files), async () => void 0), aborted(signal)]);
560
+ if (signal.aborted) return;
561
+ await update((drafts) => {
562
+ const current = drafts.get(selected.files);
563
+ if (current?.awaitingFiles && !arriving.has(current.id)) drafts.set(current.id, {
564
+ ...current,
565
+ awaitingFiles: false
566
+ });
567
+ });
568
+ await changed();
569
+ continue;
570
+ }
504
571
  await reload();
505
572
  await send(selected.claimed);
506
573
  }
507
574
  };
508
- /** Sends what waits, in the tab that holds the lock. */
509
575
  function kick() {
576
+ if (stopped) return;
510
577
  if (leading) {
511
578
  again = true;
512
579
  return;
@@ -524,22 +591,181 @@ function createOutbox(options, host) {
524
591
  }
525
592
  });
526
593
  }
527
- const enqueue = async (entry) => {
528
- const saved = await update((drafts) => {
529
- const key = keyOf(entry);
530
- const existing = [...drafts.values()].find((draft) => keyOf(draft) === key);
531
- if (existing) return existing;
532
- let order = entry.createdAt;
533
- for (const draft of drafts.values()) order = Math.max(order, draft.order + 1);
534
- const ordered = {
594
+ const save = (id) => {
595
+ const local = unsaved.get(id);
596
+ if (!local) return Promise.resolve();
597
+ const run = async () => {
598
+ local.parked = false;
599
+ let group = [local];
600
+ try {
601
+ if (await update((drafts) => {
602
+ if (unsaved.get(id) !== local) return false;
603
+ if (local.entry.kind === "reply") local.entry = {
604
+ ...local.entry,
605
+ input: {
606
+ ...local.entry.input,
607
+ threadId: realId(local.entry.input.threadId)
608
+ }
609
+ };
610
+ const parent = local.entry.kind === "reply" ? unsaved.get(local.entry.input.threadId) : void 0;
611
+ if (parent && !parent.saved && !drafts.has(parent.entry.id)) return true;
612
+ let order = local.entry.order;
613
+ for (const draft of drafts.values()) if (!written.has(draft.id)) order = Math.max(order, draft.order + 1);
614
+ const later = [...unsaved.values()].filter((other) => other !== local && !drafts.has(other.entry.id) && other.entry.order > local.entry.order);
615
+ let previous = order;
616
+ for (const other of later.sort((a, b) => a.entry.order - b.entry.order)) {
617
+ previous = Math.max(other.entry.order, previous + 1);
618
+ other.entry = {
619
+ ...other.entry,
620
+ order: previous
621
+ };
622
+ }
623
+ lastOrder = Math.max(lastOrder, previous);
624
+ local.entry = {
625
+ ...local.entry,
626
+ order
627
+ };
628
+ group = [local, ...[...unsaved.values()].filter((other) => other.parked && other.entry.kind === "reply" && other.entry.input.threadId === id)];
629
+ for (const member of group) member.write ??= write;
630
+ const keys = new Map([...drafts.values()].map((draft) => [keyOf(draft), draft]));
631
+ for (const member of group) {
632
+ if (member.entry.kind === "reply") member.entry = {
633
+ ...member.entry,
634
+ input: {
635
+ ...member.entry.input,
636
+ threadId: realId(member.entry.input.threadId)
637
+ }
638
+ };
639
+ const key = keyOf(member.entry);
640
+ const duplicate = keys.get(key);
641
+ if (duplicate) {
642
+ member.duplicate = duplicate;
643
+ aliases.set(member.entry.id, duplicate.id);
644
+ } else {
645
+ drafts.set(member.entry.id, member.entry);
646
+ keys.set(key, member.entry);
647
+ }
648
+ }
649
+ return false;
650
+ })) {
651
+ local.parked = true;
652
+ return;
653
+ }
654
+ } catch (cause) {
655
+ local.entry = {
656
+ ...local.entry,
657
+ status: "failed",
658
+ error: deliveryError(cause)
659
+ };
660
+ merge();
661
+ kick();
662
+ return;
663
+ } finally {
664
+ for (const member of group) if (member.write === write) member.write = void 0;
665
+ }
666
+ for (const member of group) Object.assign(member, {
667
+ saved: true,
668
+ parked: false
669
+ });
670
+ await changed().catch(() => void 0);
671
+ kick();
672
+ };
673
+ const write = Promise.resolve().then(run);
674
+ local.write = write;
675
+ return write;
676
+ };
677
+ const flushStaged = () => {
678
+ const locals = [...unsaved.values()];
679
+ if (locals.some((local) => local.write)) return;
680
+ const next = locals.find((local) => !local.saved && !local.parked && local.entry.status === "pending");
681
+ if (next && !next.entry.awaitingFiles) save(next.entry.id).then(flushStaged);
682
+ };
683
+ const queueSave = (local) => {
684
+ if (!stageFiles) return save(local.entry.id);
685
+ local.parked = false;
686
+ flushStaged();
687
+ return local.write ?? Promise.resolve();
688
+ };
689
+ const add = (entry, files) => {
690
+ const later = files !== void 0 && !Array.isArray(files);
691
+ const order = Math.max(Date.now(), lastOrder + 1, ...entries.map((other) => other.order + 1));
692
+ lastOrder = order;
693
+ written.add(entry.id);
694
+ const local = {
695
+ entry: copyEntry({
535
696
  ...entry,
536
- order
537
- };
538
- drafts.set(entry.id, ordered);
539
- return ordered;
697
+ order,
698
+ ...later ? { awaitingFiles: true } : {}
699
+ }),
700
+ saved: false
701
+ };
702
+ unsaved.set(entry.id, local);
703
+ if (later) arrive(entry.id, Promise.resolve(files));
704
+ merge();
705
+ return {
706
+ local,
707
+ write: queueSave(local)
708
+ };
709
+ };
710
+ const queueEntry = (entry, files) => {
711
+ const existing = entries.find((draft) => keyOf(draft) === keyOf(entry));
712
+ if (!existing) return {
713
+ entry,
714
+ ...add(entry, files)
715
+ };
716
+ const local = unsaved.get(existing.id);
717
+ return {
718
+ entry: existing,
719
+ local,
720
+ write: local?.write
721
+ };
722
+ };
723
+ const arrive = (id, files) => {
724
+ const arrival = environment.lock(filesLock(id), async () => {
725
+ const arrived = await files.then((list) => [...list], () => []);
726
+ const local = unsaved.get(id);
727
+ await local?.write;
728
+ const settled = (entry) => ({
729
+ ...entry,
730
+ files: [...entry.files, ...arrived],
731
+ awaitingFiles: false
732
+ });
733
+ if (local && !local.saved) {
734
+ local.entry = settled(local.entry);
735
+ merge();
736
+ if (stageFiles) flushStaged();
737
+ return;
738
+ }
739
+ while (arriving.has(id)) try {
740
+ await update((drafts) => {
741
+ const current = drafts.get(id);
742
+ if (current?.awaitingFiles) drafts.set(id, settled(current));
743
+ });
744
+ break;
745
+ } catch (cause) {
746
+ if (!arriving.has(id)) break;
747
+ const retry = new Promise((resume) => {
748
+ blockedFiles.set(id, {
749
+ files: arrived,
750
+ error: deliveryError(cause),
751
+ resume
752
+ });
753
+ });
754
+ merge();
755
+ await retry;
756
+ }
757
+ }).catch(() => void 0).then(async () => {
758
+ arriving.delete(id);
759
+ blockedFiles.delete(id);
760
+ await changed().catch(() => void 0);
761
+ kick();
540
762
  });
541
- await changed();
542
- return saved;
763
+ arriving.set(id, arrival);
764
+ };
765
+ const unsavedEntry = async (id) => {
766
+ await unsaved.get(id)?.write;
767
+ const local = unsaved.get(id);
768
+ return local && !local.saved ? local : void 0;
543
769
  };
544
770
  const fields = (requestId, files) => {
545
771
  const now = Date.now();
@@ -548,7 +774,7 @@ function createOutbox(options, host) {
548
774
  id,
549
775
  requestId: requestId ?? id,
550
776
  account,
551
- files: [...files ?? []],
777
+ files: Array.isArray(files) ? [...files] : [],
552
778
  createdAt: now,
553
779
  order: now,
554
780
  status: "pending"
@@ -569,8 +795,24 @@ function createOutbox(options, host) {
569
795
  return store.persisted;
570
796
  },
571
797
  overlay,
572
- owns: (threadId, messageId) => entries.some((entry) => entry.id === (messageId ?? threadId)),
573
- async create({ files, requestId, ...input }) {
798
+ owns: (threadId, messageId) => entries.some((entry) => entry.id === entryId(messageId ?? threadId)),
799
+ async beforeResolve(threadId) {
800
+ await reload();
801
+ while (true) {
802
+ const id = realId(threadId);
803
+ const pending = entries.filter((entry) => entry.id === id || entry.kind === "reply" && realId(entry.input.threadId) === id);
804
+ if (!pending.length) return id;
805
+ if (stopped || !environment.isOnline() || pending.some((entry) => entry.held || entry.status === "failed" || entry.retryAt !== void 0) || entries.some((entry) => entry.held)) return;
806
+ await new Promise((resolve) => {
807
+ const wake = () => {
808
+ queueListeners.delete(wake);
809
+ resolve();
810
+ };
811
+ queueListeners.add(wake);
812
+ });
813
+ }
814
+ },
815
+ async create({ files, deferredFiles, requestId, ...input }) {
574
816
  const entry = {
575
817
  ...fields(requestId, files),
576
818
  kind: "create",
@@ -579,11 +821,16 @@ function createOutbox(options, host) {
579
821
  const receipt = () => receipts.get(keyOf(entry)) ?? [...host.threads()].find((thread) => matchesCreate(entry, thread));
580
822
  const earlier = receipt();
581
823
  if (earlier) return earlier;
582
- const saved = await enqueue(entry);
583
- kick();
584
- return receipt() ?? localThread(saved.kind === "create" ? saved : entry);
824
+ const queued = queueEntry(entry, deferredFiles ?? files);
825
+ if (requestId !== void 0) {
826
+ await queued.write;
827
+ const confirmed = receipt();
828
+ if (confirmed) return confirmed;
829
+ }
830
+ const saved = queued.local?.duplicate ?? entries.find((draft) => draft.id === queued.entry.id) ?? queued.entry;
831
+ return localThread(saved.kind === "create" ? saved : entry);
585
832
  },
586
- async reply({ files, requestId, subject, ...input }) {
833
+ async reply({ files, deferredFiles, requestId, subject, ...input }) {
587
834
  const threadId = realId(input.threadId);
588
835
  const parent = entries.find((entry) => entry.kind === "create" && entry.id === threadId);
589
836
  const cached = serverThread(threadId);
@@ -599,14 +846,18 @@ function createOutbox(options, host) {
599
846
  };
600
847
  const earlier = receipts.get(keyOf(entry));
601
848
  if (earlier) return serverThread(earlier.id) ?? earlier;
602
- const saved = await enqueue(entry);
603
- kick();
604
- const thread = serverThread(realId(threadId)) ?? cached;
849
+ const queued = queueEntry(entry, deferredFiles ?? files);
850
+ if (requestId !== void 0) await queued.write;
851
+ const saved = queued.local?.duplicate ?? queued.local?.entry ?? queued.entry;
852
+ const confirmed = receipts.get(keyOf(saved));
853
+ if (confirmed) return serverThread(confirmed.id) ?? confirmed;
854
+ const resolvedId = realId(threadId);
855
+ const thread = serverThread(resolvedId) ?? cached;
605
856
  if (thread) return overlay([thread]).server[0] ?? thread;
606
- const local = overlay([]).local.find((local) => local.id === threadId);
857
+ const local = overlay([]).local.find((local) => local.id === resolvedId);
607
858
  if (local) return local;
608
859
  return {
609
- id: threadId,
860
+ id: resolvedId,
610
861
  scope: "",
611
862
  n: 0,
612
863
  subject: target ?? {
@@ -616,12 +867,31 @@ function createOutbox(options, host) {
616
867
  anchor: { kind: "page" },
617
868
  status: "open",
618
869
  author: author(),
619
- messages: [localMessage(saved, threadId)],
870
+ messages: [localMessage(saved, resolvedId)],
620
871
  createdAt: entry.createdAt,
621
872
  updatedAt: entry.createdAt
622
873
  };
623
874
  },
624
875
  async retry(id) {
876
+ if (id !== void 0) {
877
+ id = entryId(id);
878
+ const blocked = blockedFiles.get(id);
879
+ if (blocked) {
880
+ blocked.resume();
881
+ return;
882
+ }
883
+ }
884
+ const local = id === void 0 ? void 0 : await unsavedEntry(id);
885
+ if (local) {
886
+ local.entry = {
887
+ ...local.entry,
888
+ status: "pending",
889
+ error: void 0
890
+ };
891
+ merge();
892
+ await queueSave(local);
893
+ return;
894
+ }
625
895
  await update((drafts) => {
626
896
  for (const entry of drafts.values()) {
627
897
  if (entry.status === "sending" || id !== void 0 && entry.id !== id) continue;
@@ -640,6 +910,17 @@ function createOutbox(options, host) {
640
910
  kick();
641
911
  },
642
912
  async dismiss(id) {
913
+ id = entryId(id);
914
+ if (await unsavedEntry(id)) {
915
+ for (const [other, local] of unsaved) if (other === id || local.entry.kind === "reply" && local.entry.input.threadId === id) unsaved.delete(other);
916
+ await update((drafts) => {
917
+ for (const reply of drafts.values()) if (reply.kind === "reply" && reply.input.threadId === id) drafts.delete(reply.id);
918
+ });
919
+ await changed();
920
+ if (stageFiles) flushStaged();
921
+ kick();
922
+ return true;
923
+ }
643
924
  const removed = await update((drafts) => {
644
925
  const entry = drafts.get(id);
645
926
  if (!entry || !changeable(entry)) return false;
@@ -649,12 +930,32 @@ function createOutbox(options, host) {
649
930
  return drafts.delete(id);
650
931
  });
651
932
  if (removed) {
933
+ arriving.delete(id);
934
+ blockedFiles.get(id)?.resume();
652
935
  await changed();
653
936
  kick();
654
937
  }
655
938
  return removed;
656
939
  },
657
940
  async edit(id, body, mentions) {
941
+ id = entryId(id);
942
+ const local = await unsavedEntry(id);
943
+ if (local) {
944
+ const input = {
945
+ ...local.entry.input,
946
+ body,
947
+ ...mentions ? { mentions } : {}
948
+ };
949
+ local.entry = {
950
+ ...local.entry,
951
+ input,
952
+ status: "pending",
953
+ error: void 0
954
+ };
955
+ merge();
956
+ await queueSave(local);
957
+ return true;
958
+ }
658
959
  const edited = await update((drafts) => {
659
960
  const entry = drafts.get(id);
660
961
  if (!entry || !changeable(entry)) return false;
@@ -691,13 +992,20 @@ function createOutbox(options, host) {
691
992
  async clear() {
692
993
  cancelWait?.();
693
994
  cancelWait = void 0;
995
+ unsaved.clear();
694
996
  await update((drafts) => drafts.clear());
997
+ arriving.clear();
998
+ for (const blocked of blockedFiles.values()) blocked.resume();
999
+ blockedFiles.clear();
1000
+ aliases.clear();
695
1001
  sent.clear();
696
1002
  receipts.clear();
697
1003
  await changed();
698
1004
  },
699
1005
  start() {
1006
+ stopped = false;
700
1007
  const stops = [environment.listen((event) => {
1008
+ if (event === "offline") queueChanged();
701
1009
  if (event !== "online" && event !== "visible") return;
702
1010
  update((drafts) => {
703
1011
  for (const entry of drafts.values()) if (entry.status === "pending" && entry.retryAt !== void 0) drafts.set(entry.id, {
@@ -706,7 +1014,7 @@ function createOutbox(options, host) {
706
1014
  });
707
1015
  }).then(changed).then(kick);
708
1016
  }), environment.receive((message) => {
709
- if (message.account !== account) return;
1017
+ if (message.account !== queue) return;
710
1018
  if (message.type === "sent") {
711
1019
  if (message.kind === "create") sent.set(message.id, message.thread);
712
1020
  receipts.set(message.key, message.thread);
@@ -718,6 +1026,8 @@ function createOutbox(options, host) {
718
1026
  kick();
719
1027
  return () => {
720
1028
  for (const stop of stops.splice(0)) stop();
1029
+ stopped = true;
1030
+ queueChanged();
721
1031
  cancelWait?.();
722
1032
  cancelWait = void 0;
723
1033
  leading?.giveUp();
@@ -726,6 +1036,96 @@ function createOutbox(options, host) {
726
1036
  }
727
1037
  };
728
1038
  }
1039
+ // src/agent-prompt.ts
1040
+ /** The longest link that `commentsT3CodeLink()` makes. */
1041
+ const t3CodeLinkLimit = 8e3;
1042
+ const t3CodeNewThread = "https://app.t3.codes/new";
1043
+ const githubRepository = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/(?!\.+$)[A-Za-z0-9._-]{1,100}$/;
1044
+ const shortest = 40;
1045
+ /** `value` when it names a GitHub repository as `owner/name`. */
1046
+ function gitHubRepositoryOf(value) {
1047
+ return value && githubRepository.test(value) ? value : void 0;
1048
+ }
1049
+ function cut(text, length) {
1050
+ return text.length > length ? `${text.slice(0, length).trimEnd()}…` : text;
1051
+ }
1052
+ function where(anchor, length) {
1053
+ if (anchor.kind === "page") return "on the whole page";
1054
+ if (anchor.kind === "text") return `on the text "${cut(anchor.exact, length)}" in ${cut(anchor.selector, length)}`;
1055
+ return `on ${cut(anchor.selector, length)}`;
1056
+ }
1057
+ function threadLines(thread, length) {
1058
+ const [comment, ...replies] = thread.messages;
1059
+ const version = thread.revision === void 0 ? "" : ` (version ${thread.revision})`;
1060
+ return [
1061
+ `"${cut(comment?.body ?? "", length)}" — ${comment?.author ?? "Someone"}, ${where(thread.anchor, length)}${version}`,
1062
+ ...replies.map((reply) => `Reply: "${cut(reply.body, length)}" — ${reply.author}`),
1063
+ ...thread.files?.length ? [`Files: ${thread.files.join(" ")}`] : []
1064
+ ];
1065
+ }
1066
+ function steps(agent, ids) {
1067
+ if (!agent) return ["When you are done, tell me what you changed."];
1068
+ const { mcp, project, resolve } = agent;
1069
+ const read = `operation "comments.get", and input { threadId } for ${ids.length === 1 ? `thread ${ids[0]}` : `each ID in ${JSON.stringify(ids)}`}`;
1070
+ return [`In the ViteHub MCP (${mcp}), use list_apps to verify team ${project.teamId} and app ${project.url} (id: ${project.id}). If the team is different, ask me to switch to that team in the Console; if the app is missing, ask me to check the link. Only after both match, call read_operation with the app id, ${read}.`, resolve ? "When the fix is live, use run_operation with the app id, operation \"comments.resolve\", and input { threadId, reply }. In the reply, say what you changed." : "Report the fixes to me without resolving the threads."];
1071
+ }
1072
+ function title(thread) {
1073
+ return `${thread.id}: "${cut(thread.messages[0]?.body ?? "", shortest)}"`;
1074
+ }
1075
+ function render({ agent, threads, url }, detail) {
1076
+ const page = new URL(url).href;
1077
+ const one = threads.length === 1;
1078
+ const instructions = steps(agent, threads.map((thread) => thread.id));
1079
+ const heading = one ? `Fix this comment on ${page}` : `Fix these ${threads.length} comments on ${page}`;
1080
+ if (detail === "ids") return [heading, ...instructions].join("\n\n");
1081
+ if (detail === "titles") return [
1082
+ heading,
1083
+ threads.map((thread, index) => one ? title(thread) : `${index + 1}. ${title(thread)}`).join("\n"),
1084
+ ...instructions
1085
+ ].join("\n\n");
1086
+ if (one) return [
1087
+ heading,
1088
+ ...threadLines(threads[0], detail),
1089
+ ...instructions
1090
+ ].join("\n");
1091
+ return [
1092
+ heading,
1093
+ ...threads.map((thread, index) => threadLines(thread, detail).map((line, at) => at === 0 ? `${index + 1}. ${line}` : ` ${line}`).join("\n")),
1094
+ instructions.join("\n")
1095
+ ].join("\n\n");
1096
+ }
1097
+ /**
1098
+ * The prompt that sends an agent to fix comments: the text of each thread, where it is, and its files. With `agent`, it
1099
+ * also tells the agent to read the threads, and to resolve them when the member may, through the ViteHub MCP.
1100
+ */
1101
+ function commentsAgentPrompt(input) {
1102
+ return render(input, Number.POSITIVE_INFINITY);
1103
+ }
1104
+ /**
1105
+ * A link that opens a new T3 Code thread with the prompt of `commentsAgentPrompt()`, in `repository` (`owner/name`)
1106
+ * when it is a GitHub repository. The link is at most `t3CodeLinkLimit` characters. A long prompt always keeps its steps:
1107
+ * first its messages and anchors get shorter, then each thread keeps only its ID and a short title. For an MCP prompt,
1108
+ * the last option is the thread IDs and instructions. Returns `undefined` if none of these fit.
1109
+ */
1110
+ function commentsT3CodeLink(input, repository) {
1111
+ const repo = gitHubRepositoryOf(repository);
1112
+ const link = (detail) => {
1113
+ const url = new URL(t3CodeNewThread);
1114
+ url.searchParams.set("prompt", render(input, detail));
1115
+ if (repo) url.searchParams.set("repo", repo);
1116
+ return url.href;
1117
+ };
1118
+ const lengths = [Number.POSITIVE_INFINITY];
1119
+ for (let length = 2e3; length >= shortest; length = Math.floor(length / 2)) lengths.push(length);
1120
+ for (const detail of [
1121
+ ...lengths,
1122
+ "titles",
1123
+ ...input.agent ? ["ids"] : []
1124
+ ]) {
1125
+ const href = link(detail);
1126
+ if (href.length <= 8e3) return href;
1127
+ }
1128
+ }
729
1129
  // src/client-anchor.ts
730
1130
  const defaultContext = 32;
731
1131
  const clamp = (value) => Math.min(1e3, Math.max(0, value));
@@ -1153,10 +1553,13 @@ function createCommentSend(transport, options = {}) {
1153
1553
  let fetching = false;
1154
1554
  let sendId;
1155
1555
  let thread;
1556
+ let sentInbox = false;
1156
1557
  let pushed;
1157
1558
  let step = 0;
1559
+ let sentUntil = 0;
1158
1560
  let timer;
1159
1561
  let run = 0;
1562
+ let lastStep = "send";
1160
1563
  const notify = () => {
1161
1564
  for (const listener of listeners) listener();
1162
1565
  };
@@ -1173,6 +1576,7 @@ function createCommentSend(transport, options = {}) {
1173
1576
  timer = setTimeout(() => at === step && then(), ms);
1174
1577
  };
1175
1578
  const inbox = () => Boolean(agent && !agent.host);
1579
+ const needsStatus = () => state.status === "failed" && lastStep === "allow";
1176
1580
  const idleState = () => ({
1177
1581
  status: "idle",
1178
1582
  count,
@@ -1180,6 +1584,12 @@ function createCommentSend(transport, options = {}) {
1180
1584
  ...agent && count > 0 ? { canPairAnother: true } : {}
1181
1585
  });
1182
1586
  const idle = () => set(idleState());
1587
+ const sentState = () => ({
1588
+ status: "sent",
1589
+ count,
1590
+ inbox: sentInbox,
1591
+ ...agent ? { agent } : {}
1592
+ });
1183
1593
  const finish = () => {
1184
1594
  sendId = void 0;
1185
1595
  thread = void 0;
@@ -1194,6 +1604,11 @@ function createCommentSend(transport, options = {}) {
1194
1604
  });
1195
1605
  if (!transport.subscribe) later(statusInterval, () => void refresh(working));
1196
1606
  };
1607
+ const sent = () => {
1608
+ set(sentState());
1609
+ if (!transport.subscribe) later(statusInterval, () => void refresh(sent));
1610
+ };
1611
+ const holdingSent = () => state.status === "sent" && Date.now() < sentUntil;
1197
1612
  const limited = (retryAt) => {
1198
1613
  set({
1199
1614
  status: "limited",
@@ -1212,18 +1627,17 @@ function createCommentSend(transport, options = {}) {
1212
1627
  const apply = (status) => {
1213
1628
  agent = status.agent;
1214
1629
  if (status.pending) return pending();
1215
- if (status.working) {
1216
- sendId = status.working.id;
1217
- thread = status.working.thread;
1218
- if (state.status === "sent") {
1219
- state = {
1220
- ...state,
1221
- count,
1222
- inbox: inbox()
1223
- };
1630
+ const last = status.working ?? status.sent;
1631
+ if (last) {
1632
+ if (status.sent) sentInbox = status.sent.inbox ?? inbox();
1633
+ const hold = holdingSent() && sendId === last.id;
1634
+ sendId = last.id;
1635
+ thread = hold ? thread ?? last.thread : last.thread;
1636
+ if (hold) {
1637
+ state = sentState();
1224
1638
  return notify();
1225
1639
  }
1226
- return working();
1640
+ return status.working ? working() : sent();
1227
1641
  }
1228
1642
  sendId = void 0;
1229
1643
  thread = void 0;
@@ -1276,13 +1690,12 @@ function createCommentSend(transport, options = {}) {
1276
1690
  const update = updates?.get(result.id);
1277
1691
  thread = update?.thread ?? result.thread;
1278
1692
  if (revision === countRevision) count = 0;
1279
- set({
1280
- status: "sent",
1281
- count,
1282
- inbox: inbox()
1283
- });
1284
- later(sentFor, update?.done ? finish : working);
1693
+ sentInbox = result.inbox ?? inbox();
1694
+ set(sentState());
1695
+ sentUntil = Date.now() + sentFor;
1696
+ later(sentFor, update?.done ? finish : update ? working : () => void refresh(sent));
1285
1697
  };
1698
+ const drop = (dropped) => void transport.cancel(dropped).catch(() => void 0);
1286
1699
  const deliver = async (request, paired) => {
1287
1700
  const revision = countRevision;
1288
1701
  pushed = transport.subscribe ? /* @__PURE__ */ new Map() : void 0;
@@ -1300,9 +1713,10 @@ function createCommentSend(transport, options = {}) {
1300
1713
  reason: reasonOf(error)
1301
1714
  };
1302
1715
  }
1303
- if (at === step) settle(result, revision, paired);
1716
+ const current = at === step;
1717
+ if (current) settle(result, revision, paired);
1718
+ if (paired && (result.status === "failed" || result.status === "limited" || !current && result.status === "changed")) drop(paired.code);
1304
1719
  };
1305
- const drop = (dropped) => void transport.cancel(dropped).catch(() => void 0);
1306
1720
  const poll = () => {
1307
1721
  later(pairingInterval, async () => {
1308
1722
  if (state.status !== "pairing" || !code) return;
@@ -1328,6 +1742,7 @@ function createCommentSend(transport, options = {}) {
1328
1742
  const pair = async (copy) => {
1329
1743
  if (fetching) return;
1330
1744
  fetching = true;
1745
+ lastStep = "pair";
1331
1746
  const at = ++step;
1332
1747
  try {
1333
1748
  const pairing = transport.startPairing();
@@ -1424,12 +1839,13 @@ function createCommentSend(transport, options = {}) {
1424
1839
  });
1425
1840
  return;
1426
1841
  }
1427
- if (fetching || state.status === "pairing" || state.status === "confirm") return;
1842
+ if (fetching || state.status === "pairing" || state.status === "confirm" || needsStatus()) return;
1428
1843
  if ((state.status === "working" || state.status === "sent") && sendId !== event.id) return;
1429
1844
  if (event.type === "working") {
1430
1845
  thread = event.thread ?? (event.id === sendId ? thread : void 0);
1431
1846
  sendId = event.id;
1432
- if (state.status !== "sent") working();
1847
+ if (holdingSent()) later(sentUntil - Date.now(), working);
1848
+ else working();
1433
1849
  return;
1434
1850
  }
1435
1851
  if (event.id === sendId) finish();
@@ -1450,9 +1866,12 @@ function createCommentSend(transport, options = {}) {
1450
1866
  },
1451
1867
  refresh: () => refresh(),
1452
1868
  async send(copy) {
1453
- if (fetching || state.status !== "idle" && state.status !== "failed" && state.status !== "working") return;
1869
+ if (fetching || state.status !== "idle" && state.status !== "failed" && state.status !== "sent" && state.status !== "working") return;
1454
1870
  if (state.status !== "failed" && count === 0) return;
1871
+ if (state.status === "failed" && lastStep === "pair") return pair(copy);
1872
+ if (needsStatus()) return refresh(() => void 0);
1455
1873
  if (!agent) return pair(copy);
1874
+ lastStep = "send";
1456
1875
  return deliver(() => transport.send());
1457
1876
  },
1458
1877
  async pairAnother(copy) {
@@ -1463,6 +1882,7 @@ function createCommentSend(transport, options = {}) {
1463
1882
  if (state.status !== "confirm" || !code) return;
1464
1883
  const used = code;
1465
1884
  code = void 0;
1885
+ lastStep = "allow";
1466
1886
  return deliver(() => transport.allow(used, selection), {
1467
1887
  code: used,
1468
1888
  agent: state.agent
@@ -1672,6 +2092,20 @@ function createCommentSendTransport(options = {}) {
1672
2092
  };
1673
2093
  }
1674
2094
  // src/client.ts
2095
+ function observed(input) {
2096
+ for (const files of [input.files, input.deferredFiles]) if (files && !Array.isArray(files)) files.catch(() => {});
2097
+ return input;
2098
+ }
2099
+ async function filesArrived({ files, deferredFiles, ...input }) {
2100
+ if (deferredFiles) return {
2101
+ ...input,
2102
+ files: [...files ?? [], ...await deferredFiles]
2103
+ };
2104
+ return {
2105
+ ...input,
2106
+ ...files ? { files: await files } : {}
2107
+ };
2108
+ }
1675
2109
  function createCommentsClient(options) {
1676
2110
  const { transport } = options;
1677
2111
  const listeners = /* @__PURE__ */ new Set();
@@ -1802,7 +2236,6 @@ function createCommentsClient(options) {
1802
2236
  }
1803
2237
  return threads;
1804
2238
  };
1805
- /** The thread as the client shows it, with what waits in the outbox, also when the query leaves it out. */
1806
2239
  const shown = (threadId) => {
1807
2240
  const stored = byId.get(threadId);
1808
2241
  const { server, local } = outbox ? outbox.overlay(stored ? [stored] : []) : {
@@ -1857,8 +2290,14 @@ function createCommentsClient(options) {
1857
2290
  upsert(thread);
1858
2291
  return shown(thread.id) ?? thread;
1859
2292
  },
1860
- create: async (input) => outbox ? outbox.create(input) : upsert(await transport.create(input)),
1861
- reply: (input) => outbox ? outbox.reply(input) : mutate(input.threadId, async () => upsert(await transport.reply(input))),
2293
+ create: async (input) => {
2294
+ observed(input);
2295
+ return outbox ? outbox.create(input) : upsert(await transport.create(await filesArrived(input)));
2296
+ },
2297
+ reply: (input) => {
2298
+ observed(input);
2299
+ return outbox ? outbox.reply(input) : mutate(input.threadId, async () => upsert(await transport.reply(await filesArrived(input))));
2300
+ },
1862
2301
  edit: async (input) => {
1863
2302
  if (outbox?.owns(input.threadId, input.messageId)) {
1864
2303
  if (!await outbox.edit(input.messageId, input.body, input.mentions)) throw commentsClientDiagnostics.COMMENTS_OUTBOX_SENDING();
@@ -1878,7 +2317,14 @@ function createCommentsClient(options) {
1878
2317
  return next;
1879
2318
  });
1880
2319
  },
1881
- resolve: (input) => mutate(input.threadId, async () => upsert(await transport.resolve(input))),
2320
+ resolve: (input) => mutate(input.threadId, async () => {
2321
+ const threadId = outbox ? await outbox.beforeResolve(input.threadId) : input.threadId;
2322
+ if (threadId === void 0) throw commentsClientDiagnostics.COMMENTS_OUTBOX_RESOLVE_BLOCKED();
2323
+ return upsert(await transport.resolve({
2324
+ ...input,
2325
+ threadId
2326
+ }));
2327
+ }),
1882
2328
  reopen: (input) => mutate(input.threadId, async () => upsert(await transport.reopen(input))),
1883
2329
  users: (input) => transport.users(input),
1884
2330
  outbox,
@@ -1903,4 +2349,4 @@ function createCommentsClient(options) {
1903
2349
  }
1904
2350
  };
1905
2351
  }
1906
- export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
2352
+ export { anchorRange, commentAttachmentUrl, commentsAgentPrompt, commentsErrorDiagnostics, commentsT3CodeLink, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor, t3CodeLinkLimit };