@vite-hub/comments 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +7 -1
  2. package/dist/anchor.d.ts +3 -5
  3. package/dist/anchor.js +1 -2
  4. package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
  5. package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
  6. package/dist/client.d.ts +44 -25
  7. package/dist/client.js +64 -43
  8. package/dist/{console-D1lwNMZn.d.ts → console-CCLX_eIk.d.ts} +1 -5
  9. package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
  10. package/dist/database/postgres.d.ts +1 -3
  11. package/dist/database/postgres.js +1 -2
  12. package/dist/{database-6hXRnqDE.js → database-BkPoOdZr.js} +73 -61
  13. package/dist/{database-CTo7mx6t.d.ts → database-CPua6Q6_.d.ts} +0 -2
  14. package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
  15. package/dist/database.d.ts +4 -6
  16. package/dist/database.js +1 -2
  17. package/dist/{define-CmIFU96x.d.ts → define-B1jLSPe9.d.ts} +1 -3
  18. package/dist/{define-BMBSVbD9.js → define-BCxNaSZv.js} +3 -4
  19. package/dist/{errors-BJTZ9iyv.js → errors-C0VwRHiy.js} +1 -2
  20. package/dist/{errors-Dq4AHjza.js → errors-DFNiJg67.js} +10 -3
  21. package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
  22. package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
  23. package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
  24. package/dist/hosted/hosted-comments/frame.js +1 -0
  25. package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +182 -0
  26. package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
  27. package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
  28. package/dist/hosted/hosted-comments/tools-Bz--joZw.js +126 -0
  29. package/dist/hosted/hosted-comments.js +9 -0
  30. package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
  31. package/dist/{index-RiHzmV16.d.ts → index-D1T7RJ4R.d.ts} +10 -15
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +8 -9
  34. package/dist/{install-BGGQKbQ4.d.ts → install-NehuMNhG.d.ts} +19 -8
  35. package/dist/{install-DrAse1Fa.js → install-w6CCgGFV.js} +158 -45
  36. package/dist/{installed-C3EoqJEY.js → installed-C9SkldMi.js} +2 -3
  37. package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
  38. package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
  39. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  40. package/dist/{operations-VyyNZusz.d.ts → operations-8hqTi0DH.d.ts} +0 -2
  41. package/dist/{operations-lsVKE0GH.js → operations-B8IMhRmY.js} +18 -20
  42. package/dist/{operations-BKhUWYkb.d.ts → operations-Cic9A9e_.d.ts} +4 -6
  43. package/dist/operations.d.ts +2 -2
  44. package/dist/operations.js +2 -2
  45. package/dist/overlay/{client-DBmJ4C1M.js → client-CerbVjTz.js} +3 -3
  46. package/dist/overlay/dist-DyVmH21U.js +14 -0
  47. package/dist/overlay/overlay.js +28 -16
  48. package/dist/page/loader.js +22 -21
  49. package/dist/{page-Bzj0CszG.d.ts → page-DE71P_gQ.d.ts} +0 -2
  50. package/dist/{page-tools-shared-BNnuPK93.js → page-tools-shared-fvmJQCrP.js} +2 -2
  51. package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
  52. package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
  53. package/dist/{plugin-DRsNaJaK.js → plugin-DbCYT7Ac.js} +14 -11
  54. package/dist/realtime.d.ts +3 -5
  55. package/dist/realtime.js +4 -5
  56. package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
  57. package/dist/{request-log-Dj9Vw7qG.js → request-log-DllKQXj7.js} +1 -2
  58. package/dist/{request-origin-CFU0TQ7E.js → request-origin-YPzfE2eh.js} +1 -2
  59. package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
  60. package/dist/{rpc-CuJ5GLIz.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
  61. package/dist/rpc.d.ts +1 -1
  62. package/dist/rpc.js +1 -2
  63. package/dist/runtime/auth.d.ts +3 -5
  64. package/dist/runtime/auth.js +2 -3
  65. package/dist/runtime/console.d.ts +2 -4
  66. package/dist/runtime/console.js +4 -5
  67. package/dist/runtime/index.d.ts +45 -32
  68. package/dist/runtime/index.js +27 -26
  69. package/dist/{server-Yk610niJ.js → server-BGbD7H5s.js} +2 -3
  70. package/dist/server.d.ts +6 -8
  71. package/dist/server.js +6 -6
  72. package/dist/{service-Bj-Mg63c.d.ts → service-CPiWPoiY.d.ts} +3 -7
  73. package/dist/{service-DA5BwfPQ.js → service-DUh2uGd2.js} +9 -11
  74. package/dist/{session-DUcEor2W.d.ts → session-CN4irEqf.d.ts} +3 -5
  75. package/dist/{session-X_g9dnU5.js → session-_1GY5gaG.js} +30 -18
  76. package/dist/{store-CsUNfC1w.d.ts → store-DvNTDNgn.d.ts} +2 -4
  77. package/dist/{table-names-B9LlRC0B.js → table-names-BIHjuEFK.js} +1 -2
  78. package/dist/testing.d.ts +2 -4
  79. package/dist/testing.js +3 -4
  80. package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
  81. package/dist/{types-BLaYh0_f.d.ts → types-BX3vH18p.d.ts} +0 -2
  82. package/dist/{types-C35INXIs.d.ts → types-l6GOb_yc.d.ts} +2 -4
  83. package/dist/vite.d.ts +22 -22
  84. package/dist/vite.js +40 -45
  85. package/package.json +19 -19
@@ -1,19 +1,19 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
2
- import { t as invariant } from "./invariant-D8_xBqmZ.js";
3
- import { r as guestIdPrefix } from "./identity-CBOzgxSf.js";
4
- import { t as describeCommentContext } from "./context-BqIsmYP1.js";
5
- import { a as commentsSchemaGate, d as commentForge, f as commentMessages, m as commentsSchema, p as commentThreads, r as commentSendsTables, t as commentSends, u as commentCounters } from "./database-6hXRnqDE.js";
6
- import { i as installCommentsRuntime } from "./server-Yk610niJ.js";
7
- import { t as logFailure } from "./request-log-Dj9Vw7qG.js";
8
- import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-DSbwkVSy.js";
9
- import { n as isSecureOrigin } from "./request-origin-CFU0TQ7E.js";
10
- import { t as commentsErrors } from "./errors-BJTZ9iyv.js";
11
- import { n as pendingKey, o as runtimes } from "./installed-C3EoqJEY.js";
1
+ import { i as installCommentsRuntime } from "./server-BGbD7H5s.js";
2
+ import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
4
+ import { a as commentsSchemaGate, d as commentForge, f as commentMessages, m as commentsSchema, p as commentThreads, r as commentSendsTables, t as commentSends, u as commentCounters } from "./database-BkPoOdZr.js";
5
+ import { t as logFailure } from "./request-log-DllKQXj7.js";
6
+ import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-Bx4lZ0yt.js";
7
+ import { t as describeCommentContext } from "./context-DbkBjITZ.js";
8
+ import { t as invariant } from "./invariant-CmdvZ3vp.js";
9
+ import { n as isSecureOrigin } from "./request-origin-YPzfE2eh.js";
10
+ import { t as commentsErrors } from "./errors-C0VwRHiy.js";
11
+ import { n as pendingKey, o as runtimes } from "./installed-C9SkldMi.js";
12
12
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
13
13
  import * as v from "valibot";
14
- import { and, asc, desc, eq, gt, gte, inArray, isNotNull, isNull, like, lt, lte, or, sql } from "drizzle-orm";
14
+ import { and, asc, desc, eq, getTableName, gt, gte, inArray, isNotNull, isNull, like, lt, lte, or, sql } from "drizzle-orm";
15
15
  import { forgeEnv, githubAppCredentials, githubInstallationFor, githubInstallationRouting, readForgeEnv, readGitHubAppPrivateKey } from "@vite-hub/forge";
16
- //#region \0rolldown/runtime.js
16
+ // \0rolldown/runtime.js
17
17
  var __defProp = Object.defineProperty;
18
18
  var __exportAll = (all, no_symbols) => {
19
19
  let target = {};
@@ -24,8 +24,7 @@ var __exportAll = (all, no_symbols) => {
24
24
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
25
25
  return target;
26
26
  };
27
- //#endregion
28
- //#region src/operations-core/store.ts
27
+ // src/operations-core/store.ts
29
28
  const chunkSize = 80;
30
29
  const allocationAttempts = 12;
31
30
  const candidateLimit = 200;
@@ -497,8 +496,99 @@ function createCommentsStore(database, tables = {
497
496
  }
498
497
  };
499
498
  }
500
- //#endregion
501
- //#region src/forge/github.ts
499
+ // src/operations-core/tenant-store.ts
500
+ /**
501
+ * A store that keeps the threads of one tenant in tables that several tenants share. It stores `scope` as the tenant
502
+ * and gives the threads back with the scope of Comments, so thread numbers count per tenant. Each call by id first reads
503
+ * the stored scope of the thread: ids are unique and a scope never changes, so a thread of another tenant is not found.
504
+ */
505
+ function tenantCommentsStore(store, options) {
506
+ const { tenant } = options;
507
+ const tenantScope = options.scope ?? "site";
508
+ const owned = (thread) => thread?.scope === tenant;
509
+ const shown = (thread) => ({
510
+ ...thread,
511
+ scope: tenantScope
512
+ });
513
+ const visible = (thread) => thread && owned(thread) ? shown(thread) : null;
514
+ async function own(threadId) {
515
+ if (!owned(await store.getById(threadId))) throw commentsErrorDiagnostics.COMMENTS_R0002({ id: threadId });
516
+ }
517
+ const canReadOwned = (canRead) => async (thread) => owned(thread) && await canRead(shown(thread));
518
+ return {
519
+ async list(query) {
520
+ if (query.scope !== void 0 && query.scope !== tenantScope) return [];
521
+ return (await store.list({
522
+ ...query,
523
+ scope: tenant
524
+ })).map(shown);
525
+ },
526
+ async getById(id) {
527
+ return visible(await store.getById(id));
528
+ },
529
+ async getByNumber(scope, n) {
530
+ return scope === tenantScope ? visible(await store.getByNumber(tenant, n)) : null;
531
+ },
532
+ async getByRequestId(scope, requestId) {
533
+ return scope === tenantScope ? visible(await store.getByRequestId(tenant, requestId)) : null;
534
+ },
535
+ async getByMessage(messageId) {
536
+ return visible(await store.getByMessage(messageId));
537
+ },
538
+ async getByAttachment(key, cursor) {
539
+ const found = await store.getByAttachment(key, cursor);
540
+ return {
541
+ ...found,
542
+ threads: found.threads.filter(owned).map(shown)
543
+ };
544
+ },
545
+ async createThread(input) {
546
+ if (input.scope !== tenantScope) throw commentsErrorDiagnostics.COMMENTS_TENANT_SCOPE_INVALID({
547
+ scope: input.scope,
548
+ tenantScope
549
+ });
550
+ return shown(await store.createThread({
551
+ ...input,
552
+ scope: tenant
553
+ }));
554
+ },
555
+ async addMessage(threadId, input, addOptions) {
556
+ await own(threadId);
557
+ return shown(await store.addMessage(threadId, input, addOptions));
558
+ },
559
+ async editMessage(threadId, messageId, input) {
560
+ await own(threadId);
561
+ return shown(await store.editMessage(threadId, messageId, input));
562
+ },
563
+ async deleteMessage(threadId, messageId, now) {
564
+ await own(threadId);
565
+ return shown(await store.deleteMessage(threadId, messageId, now));
566
+ },
567
+ async deleteThread(threadId, ownerId) {
568
+ const thread = await store.getById(threadId);
569
+ if (!thread) return true;
570
+ if (!owned(thread)) return false;
571
+ return store.deleteThread(threadId, ownerId);
572
+ },
573
+ async setStatus(threadId, status, by, now, actor) {
574
+ await own(threadId);
575
+ return shown(await store.setStatus(threadId, status, by, now, actor));
576
+ },
577
+ async deleteScope(scope) {
578
+ return scope === tenantScope ? store.deleteScope(tenant) : [];
579
+ },
580
+ async deleteUser() {
581
+ throw commentsErrorDiagnostics.COMMENTS_TENANT_DELETE_USER();
582
+ },
583
+ async knownUsers(query, limit, canRead) {
584
+ return store.knownUsers(query, limit, canReadOwned(canRead));
585
+ },
586
+ async knownUsersByIds(ids, canRead) {
587
+ return store.knownUsersByIds(ids, canReadOwned(canRead));
588
+ }
589
+ };
590
+ }
591
+ // src/forge/github.ts
502
592
  /** The HTTP status of a GitHub failure of the pull request sync, or `undefined` for another error. */
503
593
  function gitHubFailureStatus(error) {
504
594
  if (!(error instanceof Error)) return void 0;
@@ -646,8 +736,7 @@ function createGitHubClient(options = {}) {
646
736
  }
647
737
  };
648
738
  }
649
- //#endregion
650
- //#region src/forge/render.ts
739
+ // src/forge/render.ts
651
740
  /** The `<!-- -->` marker that ends every comment the sync posts, so people and tools can tell them apart. */
652
741
  const forgeMarker = "vitehub-comments";
653
742
  const summaryMarker = `<!-- ${forgeMarker} summary -->`;
@@ -780,8 +869,7 @@ function renderSummary(input) {
780
869
  summaryMarker
781
870
  ].join("\n");
782
871
  }
783
- //#endregion
784
- //#region src/forge/sync.ts
872
+ // src/forge/sync.ts
785
873
  /** How long a row that is being posted stays claimed, so a sync that died does not block the comment for good. */
786
874
  const claimTimeout = 6e4;
787
875
  /** Change detection only: two FNV-1a passes, as `commentRoom()` hashes pages. */
@@ -1188,8 +1276,7 @@ function createForgeSync(options, input) {
1188
1276
  }
1189
1277
  };
1190
1278
  }
1191
- //#endregion
1192
- //#region src/send/store.ts
1279
+ // src/send/store.ts
1193
1280
  const tableNames = ["vitehub_comment_sends"];
1194
1281
  function names(rows) {
1195
1282
  return (Array.isArray(rows) ? rows : []).map((row) => String(Array.isArray(row) ? row[0] : Object.values(Object(row))[0]));
@@ -1255,8 +1342,7 @@ function createCommentSendStore(db, options = {}) {
1255
1342
  })
1256
1343
  };
1257
1344
  }
1258
- //#endregion
1259
- //#region src/send/service.ts
1345
+ // src/send/service.ts
1260
1346
  const grantLifetime = 864e5;
1261
1347
  const window = 36e5;
1262
1348
  const defaultHosts = ["relay.t3.codes"];
@@ -1378,9 +1464,12 @@ function createCommentSendService(options) {
1378
1464
  const forbidden = () => [commentsErrors.COMMENTS_FORBIDDEN({ action: "send" }), void 0];
1379
1465
  const insecure = (origin) => isSecureOrigin(origin) ? void 0 : [commentsErrors.COMMENTS_SEND_INSECURE({ origin }), void 0];
1380
1466
  const deliveryFailed = "The agent's receiver did not take the send.";
1467
+ async function deliveryOf(row) {
1468
+ return row.delivery ? await (await webhooks()).getMemberDelivery(row.delivery) : void 0;
1469
+ }
1381
1470
  async function reconcile(row) {
1382
1471
  if (row.state !== "pending") return row;
1383
- const delivery = row.delivery && await (await webhooks()).getMemberDeliveryState(row.delivery);
1472
+ const delivery = (await deliveryOf(row))?.state;
1384
1473
  const state = delivery === "sent" ? "sent" : delivery === "dead" || delivery === "cancelled" || !delivery && Date.now() - row.updatedAt > 6e4 ? "failed" : "pending";
1385
1474
  if (state === "pending") return row;
1386
1475
  const error = state === "failed" ? deliveryFailed : null;
@@ -1520,12 +1609,13 @@ function createCommentSendService(options) {
1520
1609
  }
1521
1610
  async function view(row, user, policy) {
1522
1611
  const opened = await viewOf(row, user, policy);
1523
- await store.setSendState(row.id, ["sent"], "working", Date.now());
1612
+ if (row.state !== "sent" && row.state !== "pending") return opened;
1613
+ const state = await store.setSendState(row.id, ["pending", "sent"], "working", Date.now()) ? "working" : (await store.send(row.id))?.state ?? row.state;
1524
1614
  return {
1525
1615
  ...opened,
1526
1616
  send: {
1527
1617
  ...opened.send,
1528
- state: row.state === "sent" ? "working" : row.state
1618
+ state
1529
1619
  }
1530
1620
  };
1531
1621
  }
@@ -1536,13 +1626,15 @@ function createCommentSendService(options) {
1536
1626
  status: "failed",
1537
1627
  reason: "No agent is paired. Press Send to pair one."
1538
1628
  };
1629
+ const inbox = endpoint.kind === "inbox";
1539
1630
  const resultOf = (row) => row.state === "failed" ? {
1540
1631
  status: "failed",
1541
1632
  reason: row.error ?? deliveryFailed
1542
1633
  } : {
1543
1634
  status: row.state === "pending" ? "pending" : "sent",
1544
1635
  id: row.id,
1545
- ...row.thread ? { thread: row.thread } : {}
1636
+ ...row.thread ? { thread: row.thread } : {},
1637
+ inbox
1546
1638
  };
1547
1639
  const live = [
1548
1640
  "pending",
@@ -1619,7 +1711,10 @@ function createCommentSendService(options) {
1619
1711
  };
1620
1712
  }
1621
1713
  const fail = async (reason) => {
1622
- await store.setSendState(id, ["pending"], "failed", Date.now(), { error: reason });
1714
+ if (!await store.setSendState(id, ["pending"], "failed", Date.now(), { error: reason })) {
1715
+ const current = await store.send(id);
1716
+ if (current) return resultOf(current);
1717
+ }
1623
1718
  return {
1624
1719
  status: "failed",
1625
1720
  reason
@@ -1667,11 +1762,15 @@ function createCommentSendService(options) {
1667
1762
  });
1668
1763
  if (error || delivered.status === "failed") return fail(error?.why ?? deliveryFailed);
1669
1764
  const status = delivered.status === "pending" ? "pending" : "sent";
1670
- await store.setSendState(id, ["pending"], status, Date.now(), { delivery: delivered.id });
1765
+ if (!await store.setSendState(id, ["pending"], status, Date.now(), { delivery: delivered.id })) {
1766
+ const current = await store.send(id);
1767
+ if (current) return resultOf(current);
1768
+ }
1671
1769
  return {
1672
1770
  status,
1673
1771
  id,
1674
- ...thread ? { thread } : {}
1772
+ ...thread ? { thread } : {},
1773
+ inbox
1675
1774
  };
1676
1775
  }
1677
1776
  return {
@@ -1691,20 +1790,25 @@ function createCommentSendService(options) {
1691
1790
  ]);
1692
1791
  const latest = candidate && await reconcile(candidate);
1693
1792
  const agent = agentOf(endpoint);
1694
- let working;
1793
+ let last = {};
1695
1794
  if (latest?.state === "sent" || latest?.state === "working") {
1696
1795
  const byId = new Map(open.map((thread) => [thread.id, thread]));
1697
- if (!finished(latest, (id) => byId.get(id))) working = {
1698
- id: latest.id,
1699
- ...latest.thread ? { thread: latest.thread } : {}
1700
- };
1701
- else await store.setSendState(latest.id, ["sent", "working"], "done", now);
1796
+ if (!finished(latest, (id) => byId.get(id))) {
1797
+ const send = {
1798
+ id: latest.id,
1799
+ ...latest.thread ? { thread: latest.thread } : {}
1800
+ };
1801
+ last = latest.state === "sent" ? { sent: {
1802
+ ...send,
1803
+ inbox: (await deliveryOf(latest))?.inbox ?? false
1804
+ } } : { working: send };
1805
+ } else await store.setSendState(latest.id, ["sent", "working"], "done", now);
1702
1806
  }
1703
1807
  return {
1704
1808
  count: ready.length,
1705
1809
  selection: await selectionOf(caller.subject, ready),
1706
1810
  ...agent ? { agent } : {},
1707
- ...working ? { working } : {},
1811
+ ...last,
1708
1812
  ...latest?.state === "pending" ? { pending: true } : {},
1709
1813
  ...limitedUntil === void 0 ? {} : { retryAt: limitedUntil }
1710
1814
  };
@@ -1818,6 +1922,7 @@ function createCommentSendService(options) {
1818
1922
  if (allowed.status !== "allowed") return allowed.status === "not-owner" ? forbidden() : [commentsErrors.COMMENTS_SEND_CODE_EXPIRED(), void 0];
1819
1923
  return [void 0, await deliver(caller, user, {
1820
1924
  id: allowed.endpoint.id,
1925
+ kind: allowed.endpoint.kind,
1821
1926
  thread: allowed.pairing.address
1822
1927
  }, confirmed)];
1823
1928
  },
@@ -1844,7 +1949,12 @@ function createCommentSendService(options) {
1844
1949
  const found = id ? await store.send(id) : await store.latestSend(user.id, void 0, ["pending", "sent"]);
1845
1950
  if (found?.member !== user.id) return void 0;
1846
1951
  const row = await reconcile(found);
1847
- if (row.state === "failed" || row.state === "pending") return void 0;
1952
+ if (row.state === "failed") return void 0;
1953
+ if (row.state === "pending") {
1954
+ if (!id) return void 0;
1955
+ const delivery = (await deliveryOf(row))?.state;
1956
+ if (delivery !== "sending" && delivery !== "sent") return void 0;
1957
+ }
1848
1958
  return view(row, user, policy);
1849
1959
  },
1850
1960
  async listOwn(user, options = {}) {
@@ -1919,8 +2029,7 @@ function createCommentSendService(options) {
1919
2029
  }
1920
2030
  };
1921
2031
  }
1922
- //#endregion
1923
- //#region src/install.ts
2032
+ // src/install.ts
1924
2033
  var install_exports = /* @__PURE__ */ __exportAll({ installComments: () => installComments });
1925
2034
  /** The store, after the tables are ready: each method waits for `ready` first. */
1926
2035
  function gated(store, ready) {
@@ -1944,7 +2053,12 @@ function installComments(comments, install) {
1944
2053
  commentMessages: commentsSchema.vitehubCommentMessages,
1945
2054
  commentThreads: commentsSchema.vitehubCommentThreads
1946
2055
  };
1947
- const store = gated(createCommentsStore(install.database, tables), commentsSchemaGate(install.database, install.schema ?? "app", { dialect: install.dialect ?? "sqlite" }));
2056
+ const owner = install.tenant ? "app" : install.schema ?? "app";
2057
+ const shared = createCommentsStore(install.database, tables);
2058
+ const store = gated(install.tenant ? tenantCommentsStore(shared, install.tenant) : shared, commentsSchemaGate(install.database, owner, {
2059
+ dialect: install.dialect ?? "sqlite",
2060
+ ...owner === "app" ? { table: getTableName(tables.commentThreads) } : {}
2061
+ }));
1948
2062
  const pending = Reflect.get(comments, pendingKey);
1949
2063
  const track = (task) => {
1950
2064
  if (!pending) return;
@@ -1999,8 +2113,7 @@ function installComments(comments, install) {
1999
2113
  ...sync ? { sync } : {},
2000
2114
  ...send ? { send } : {}
2001
2115
  });
2002
- installCommentsRuntime(runtime);
2116
+ if (!install.tenant) installCommentsRuntime(runtime);
2003
2117
  return runtime;
2004
2118
  }
2005
- //#endregion
2006
2119
  export { install_exports as n, createCommentsStore as r, installComments as t };
@@ -1,5 +1,5 @@
1
- import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-Yk610niJ.js";
2
- //#region src/installed.ts
1
+ import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-BGbD7H5s.js";
2
+ // src/installed.ts
3
3
  /** The runtime that `installComments()` connected to each definition. */
4
4
  const runtimes = /* @__PURE__ */ new WeakMap();
5
5
  /** The runtime that the generated Nitro plugin builds on the first call, per definition. */
@@ -27,5 +27,4 @@ async function commentSendOf(comments) {
27
27
  await runtimeOf(comments);
28
28
  return runtimes.get(comments)?.send;
29
29
  }
30
- //#endregion
31
30
  export { runtimeOf as a, runtimeBuilds as i, pendingKey as n, runtimes as o, resolveCommentsRuntime as r, commentSendOf as t };
@@ -1,5 +1,5 @@
1
1
  import { defineDiagnostics } from "nostics";
2
- //#region ../internal/src/invariant.ts
2
+ // ../internal/src/invariant.ts
3
3
  const invariantDiagnostics = /*#__PURE__*/ defineDiagnostics({
4
4
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
5
5
  codes: { INTERNAL_INVARIANT_FAILED: {
@@ -18,5 +18,4 @@ function invariantError(what) {
18
18
  function invariant(condition, what) {
19
19
  if (!condition) throw invariantError(what);
20
20
  }
21
- //#endregion
22
21
  export { invariant as t };
@@ -1,4 +1,3 @@
1
- //#region src/migrate.d.ts
2
1
  /**
3
2
  * - `empty`: no `vitehub_comment_threads` table.
4
3
  * - `live`: the tables of the live-site model: threads with `number`, `page`, and `created_by`, and `vitehub_comments`.
@@ -9,6 +8,8 @@ type CommentsSchemaState = "empty" | "live" | "outdated" | "current";
9
8
  interface CommentsMigrationOptions {
10
9
  /** `postgresql` for a Postgres Database. Default `sqlite`: SQLite, libSQL, and D1. */
11
10
  dialect?: "sqlite" | "postgresql";
11
+ /** The SQL name of the threads table that tells the state. Default `vitehub_comment_threads`. */
12
+ table?: string;
12
13
  }
13
14
  interface CommentsMigration {
14
15
  /** What the Database had before. */
@@ -50,5 +51,4 @@ declare function migrateComments(db: object, options?: CommentsMigrationOptions)
50
51
  * the tables, and fails with `COMMENTS_R0019` until a migration brings them to this version.
51
52
  */
52
53
  type CommentsSchemaOwner = "comments" | "app";
53
- //#endregion
54
54
  export { commentsMigrationSql as a, migrateComments as c, CommentsSchemaState as i, CommentsMigrationOptions as n, commentsSchemaState as o, CommentsSchemaOwner as r, liveThreadsBackup as s, CommentsMigration as t };
@@ -1,4 +1,4 @@
1
- //#region ../internal/src/object.ts
1
+ // ../internal/src/object.ts
2
2
  /** A non-null object that is not an array. Functions do not pass. */
3
3
  function isRecord(value) {
4
4
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -7,5 +7,4 @@ function isRecord(value) {
7
7
  function isRecordOrFunction(value) {
8
8
  return Object(value) === value && !Array.isArray(value);
9
9
  }
10
- //#endregion
11
10
  export { isRecordOrFunction as n, isRecord as t };
@@ -1,5 +1,4 @@
1
1
  import { StandardSchemaV1 } from "@standard-schema/spec";
2
- //#region ../internal/src/operation-definition.d.ts
3
2
  /** `read` never changes state. `write` changes state. `destructive` deletes or publishes. */
4
3
  type OperationKind = "read" | "write" | "destructive";
5
4
  /** The signed-in user of a call. */
@@ -167,5 +166,4 @@ interface OperationContributionEntry {
167
166
  }
168
167
  /** The contribution of a plugin: a list, or a function that returns it, for a plugin that reads the project first. */
169
168
  type OperationContributions = readonly OperationContributionEntry[] | (() => readonly OperationContributionEntry[] | Promise<readonly OperationContributionEntry[]>);
170
- //#endregion
171
169
  export { OperationContributions as n, AnyOperation as t };
@@ -1,16 +1,16 @@
1
- import { n as outboxAccountHeader } from "./client-files-CJZl5Kc4.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
3
- import { n as pagePathOf, t as isPagePath } from "./path--zk6PEMz.js";
4
- import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
5
- import { C as clientAddressKey, S as suggest, T as createClientRateLimit, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, x as storeAttachment, y as retriedReply } from "./service-DA5BwfPQ.js";
6
- import { n as guestFromHeaders, t as authorOf } from "./identity-CBOzgxSf.js";
7
- import { t as describeCommentContext } from "./context-BqIsmYP1.js";
8
- import { t as commentsRuntime } from "./server-Yk610niJ.js";
1
+ import { n as outboxAccountHeader } from "./client-files-lC6X7XyS.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
3
+ import { n as pagePathOf, t as isPagePath } from "./path-8yqMd8zR.js";
4
+ import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
5
+ import { C as clientAddressKey, S as suggest, T as createClientRateLimit, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, x as storeAttachment, y as retriedReply } from "./service-DUh2uGd2.js";
6
+ import { n as guestFromHeaders, t as authorOf } from "./identity-CT7-UGmS.js";
7
+ import { t as describeCommentContext } from "./context-DbkBjITZ.js";
8
+ import { t as commentsRuntime } from "./server-BGbD7H5s.js";
9
9
  import { defineDiagnostics } from "nostics";
10
10
  import { toJsonSchema } from "@valibot/to-json-schema";
11
11
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
12
12
  import * as v from "valibot";
13
- //#region ../internal/src/error-diagnostics.ts
13
+ // ../internal/src/error-diagnostics.ts
14
14
  const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
15
15
  const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
16
16
  docsBase: "https://vitehub.dev/docs/development/diagnostics",
@@ -267,6 +267,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
267
267
  why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
268
268
  fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
269
269
  },
270
+ INTERNAL_SITE_TOKEN_TOO_LONG: {
271
+ why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
272
+ fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
273
+ },
270
274
  INTERNAL_SQLITE_ARGUMENT_INVALID: {
271
275
  why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
272
276
  fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
@@ -281,8 +285,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
281
285
  }
282
286
  }
283
287
  });
284
- //#endregion
285
- //#region ../internal/src/standard-schema.ts
288
+ // ../internal/src/standard-schema.ts
286
289
  function readOwn(value, key) {
287
290
  if (value === null || Object(value) !== value) return;
288
291
  try {
@@ -311,8 +314,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
311
314
  return;
312
315
  }
313
316
  }
314
- //#endregion
315
- //#region ../internal/src/valibot.ts
317
+ // ../internal/src/valibot.ts
316
318
  const valibotTargets = /* @__PURE__ */ new Set([
317
319
  "draft-07",
318
320
  "draft-2020-12",
@@ -353,8 +355,7 @@ function withValibotJsonSchema(schema, options = {}) {
353
355
  }
354
356
  };
355
357
  }
356
- //#endregion
357
- //#region ../internal/src/operation-definition.ts
358
+ // ../internal/src/operation-definition.ts
358
359
  const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
359
360
  const kinds = /* @__PURE__ */ new Set([
360
361
  "read",
@@ -433,8 +434,7 @@ function operationAccessAllows(access, section, call) {
433
434
  if (!grants.some((grant) => sections.includes(`${grant}:read`))) return false;
434
435
  return call === void 0 || call.kind === "read" || call.readOnly === true;
435
436
  }
436
- //#endregion
437
- //#region src/thread-text.ts
437
+ // src/thread-text.ts
438
438
  function commentPersonName(person) {
439
439
  return `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
440
440
  }
@@ -522,8 +522,7 @@ function commentThreadsText(threads, status, note) {
522
522
  if (!threads.length) return note ? `No ${status} threads that this caller may read. ${note}` : `No ${status} threads.`;
523
523
  return [...threads.map(commentThreadLine), ...note ? ["", note] : []].join("\n");
524
524
  }
525
- //#endregion
526
- //#region src/operations-core/operations.ts
525
+ // src/operations-core/operations.ts
527
526
  const defaultLimit = 200;
528
527
  const maximumLimit = 500;
529
528
  const maximumSuggestions = 10;
@@ -1248,5 +1247,4 @@ const commentsOperations = [
1248
1247
  section: "comments"
1249
1248
  })
1250
1249
  ];
1251
- //#endregion
1252
1250
  export { commentThreadSummary as a, hiddenThreadsNote as c, commentsOperations as i, commentAnchorSchema as n, commentThreadsText as o, commentInputSchemas as r, describeCommentThread as s, commentActions as t };
@@ -1,9 +1,8 @@
1
- import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-BLaYh0_f.js";
2
- import { f as CommentsPolicyGate, g as CommentsUser } from "./define-CmIFU96x.js";
3
- import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-Bj-Mg63c.js";
4
- import { t as AnyOperation } from "./operations-VyyNZusz.js";
1
+ import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-CPiWPoiY.js";
2
+ import { t as AnyOperation } from "./operations-8hqTi0DH.js";
3
+ import { f as CommentsPolicyGate, g as CommentsUser } from "./define-B1jLSPe9.js";
4
+ import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-BX3vH18p.js";
5
5
  import * as v from "valibot";
6
- //#region src/operations-core/operations.d.ts
7
6
  declare const anchor: v.UnionSchema<[v.StrictObjectSchema<{
8
7
  readonly kind: v.LiteralSchema<"page", undefined>;
9
8
  }, undefined>, v.StrictObjectSchema<{
@@ -258,5 +257,4 @@ declare const commentActions: {
258
257
  };
259
258
  /** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
260
259
  declare const commentsOperations: readonly AnyOperation[];
261
- //#endregion
262
260
  export { commentsOperations as a, commentInputSchemas as i, commentActions as n, commentAnchorSchema as r, CommentsCaller as t };
@@ -1,3 +1,3 @@
1
- import { a as maximumCommentBodyLength } from "./service-Bj-Mg63c.js";
2
- import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-BKhUWYkb.js";
1
+ import { a as maximumCommentBodyLength } from "./service-CPiWPoiY.js";
2
+ import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Cic9A9e_.js";
3
3
  export { CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
@@ -1,3 +1,3 @@
1
- import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-lsVKE0GH.js";
2
- import { f as maximumCommentBodyLength } from "./service-DA5BwfPQ.js";
1
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-B8IMhRmY.js";
2
+ import { f as maximumCommentBodyLength } from "./service-DUh2uGd2.js";
3
3
  export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };