@vite-hub/comments 0.5.0 → 0.5.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 (85) hide show
  1. package/README.md +4 -0
  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 +15 -22
  7. package/dist/client.js +14 -21
  8. package/dist/{console-D1lwNMZn.d.ts → console-CK2F53QP.d.ts} +0 -4
  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-BMBSVbD9.js → define-9uMM3Ewc.js} +2 -3
  18. package/dist/{define-CmIFU96x.d.ts → define-B1jLSPe9.d.ts} +1 -3
  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-4-mWX4Uz.js +170 -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-CdwnUCOr.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-BEnHTj2Z.d.ts} +5 -13
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +8 -9
  34. package/dist/{install-BGGQKbQ4.d.ts → install-B-FQpi47.d.ts} +19 -8
  35. package/dist/{install-DrAse1Fa.js → install-BUXxryut.js} +119 -30
  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-CKC_lMG_.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 +15 -15
  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-B2hETRii.js} +9 -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 +8 -25
  68. package/dist/runtime/index.js +21 -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-DDD4Ubxd.js} +9 -11
  74. package/dist/{session-X_g9dnU5.js → session-BGN6Vlm6.js} +7 -10
  75. package/dist/{session-DUcEor2W.d.ts → session-CTh9nisq.d.ts} +3 -5
  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 +5 -21
  84. package/dist/vite.js +25 -43
  85. package/package.json +19 -19
package/README.md CHANGED
@@ -91,6 +91,10 @@ import { contentField } from "vite-hub/content/client"
91
91
 
92
92
  An edit reads the draft, changes one string field, and saves the document with `ifDigest`. It needs `content.can({ action: "write" })`. Publishing stays in the Content publish flow.
93
93
 
94
+ ### Add Hosted Comments
95
+
96
+ Register your site in the Console with **Hosted Comments only**, then copy the script into your page HTML. For a connected app, copy it from **Settings** > **Connection** > **Hosted Comments**. The Console signs reviewers in and stores their page threads. Confirming an unlink permanently deletes that project's hosted threads and replies.
97
+
94
98
  ## Server API
95
99
 
96
100
  Every method returns `[error, data]`.
package/dist/anchor.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { A as ElementAnchor } from "./types-BLaYh0_f.js";
2
- import "./types-C35INXIs.js";
3
- //#region src/anchor.d.ts
1
+ import { A as ElementAnchor } from "./types-BX3vH18p.js";
2
+ import "./types-l6GOb_yc.js";
4
3
  /** The anchor of a pin that the overlay drops: an element anchor with every hint that `placeAnchor()` uses. */
5
4
  export type PinAnchor = ElementAnchor & Required<Pick<ElementAnchor, "label" | "page" | "viewport">>;
6
5
  /** The attribute that Content's `contentField()` writes on an element that renders a field. */
@@ -39,5 +38,4 @@ export type PlacedAnchor =
39
38
  * Where an anchor is now, in client coordinates: the Content field, then the CSS path if its label still matches,
40
39
  * then any element of that tag with the same label, then the page point. An anchor without a label trusts the path.
41
40
  */
42
- export declare function placeAnchor(anchor: ElementAnchor): PlacedAnchor;
43
- //#endregion
41
+ export declare function placeAnchor(anchor: ElementAnchor): PlacedAnchor;
package/dist/anchor.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/anchor.ts
1
+ // src/anchor.ts
2
2
  /** The attribute that Content's `contentField()` writes on an element that renders a field. */
3
3
  const fieldAttribute = "data-content-field";
4
4
  const maxDepth = 10;
@@ -129,5 +129,4 @@ function placeAnchor(anchor) {
129
129
  y: page.y - window.scrollY
130
130
  };
131
131
  }
132
- //#endregion
133
132
  export { createAnchor, fieldAttribute, fieldElementOf, labelOf, placeAnchor, selectorOf };
@@ -1,5 +1,5 @@
1
1
  import { Diagnostic, defineDiagnostics } from "nostics";
2
- //#region src/client-diagnostics.ts
2
+ // src/client-diagnostics.ts
3
3
  const commentsClientCodes = {
4
4
  COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
5
5
  why: "The current author is not the author of this queued comment.",
@@ -51,5 +51,4 @@ function commentsUnansweredError(status, cause, retryAfter) {
51
51
  ...retryAfter === void 0 ? {} : { retryAfter }
52
52
  });
53
53
  }
54
- //#endregion
55
54
  export { commentsUnansweredError as i, commentsClientCodes as n, commentsClientDiagnostics as r, commentsAnswerError as t };
@@ -1,4 +1,4 @@
1
- //#region src/client-files.ts
1
+ // src/client-files.ts
2
2
  const outboxAccountHeader = "x-vitehub-comments-outbox-account";
3
3
  const failedCommentPreparation = /* @__PURE__ */ new WeakMap();
4
4
  /** The file as Base64, the form that `comments.upload` takes. */
@@ -49,5 +49,4 @@ function retryAfterOf(response, now = Date.now()) {
49
49
  const date = Date.parse(value);
50
50
  return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
51
51
  }
52
- //#endregion
53
52
  export { withCommentFiles as i, outboxAccountHeader as n, retryAfterOf as r, failedCommentPreparation as t };
package/dist/client.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BLaYh0_f.js";
2
- //#region ../internal/src/browser-environment.d.ts
1
+ import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BX3vH18p.js";
3
2
  /** A page event that a client store reacts to. */
4
3
  type BrowserEvent = "online" | "offline" | "visible" | "hidden";
5
4
  /** What a client store needs from the browser: page events, one sender across tabs, and messages between tabs. Tests pass a fake one. */
@@ -20,8 +19,6 @@ interface BrowserEnvironment<Message> {
20
19
  schedule: (task: () => void, ms: number) => () => void;
21
20
  random: () => number;
22
21
  }
23
- //#endregion
24
- //#region src/client-outbox.d.ts
25
22
  /** A message between the tabs of one browser. */
26
23
  type CommentsOutboxMessage = {
27
24
  type: "change";
@@ -113,8 +110,6 @@ export declare function createMemoryOutboxStore(): CommentsOutboxStore;
113
110
  * does not open, as in some private windows, it keeps the entries in memory and `persisted` is `false`.
114
111
  */
115
112
  export declare function createIndexedDBOutboxStore(): CommentsOutboxStore;
116
- //#endregion
117
- //#region src/client-anchor.d.ts
118
113
  /** A point in client (viewport) coordinates, such as `event.clientX` and `event.clientY`. */
119
114
  interface AnchorPoint {
120
115
  x: number;
@@ -180,8 +175,6 @@ export declare function anchorRange(anchor: TextAnchor, root?: ParentNode): Rang
180
175
  * that holds the quote best.
181
176
  */
182
177
  export declare function resolveAnchor(anchor: CommentAnchor, root?: ParentNode): AnchorPosition;
183
- //#endregion
184
- //#region src/operations-core/errors.d.ts
185
178
  export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
186
179
  readonly COMMENTS_R0002: {
187
180
  readonly why: ({ id }: {
@@ -377,6 +370,17 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
377
370
  }) => string;
378
371
  readonly fix: "Use Comments through `vitehub()`, which adds Webhooks, and install `@vite-hub/webhooks` when you use the packages one by one. `comments()` without `vite-hub` has no Send.";
379
372
  };
373
+ readonly COMMENTS_TENANT_DELETE_USER: {
374
+ readonly why: "Deleting a user from shared Comments tables requires access to all projects.";
375
+ readonly fix: "Delete the user's messages through the project that owns them.";
376
+ };
377
+ readonly COMMENTS_TENANT_SCOPE_INVALID: {
378
+ readonly why: ({ scope, tenantScope }: {
379
+ scope: string;
380
+ tenantScope: string;
381
+ }) => string;
382
+ readonly fix: "Start a thread on a page in this project.";
383
+ };
380
384
  readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
381
385
  why: string;
382
386
  fix: string;
@@ -400,8 +404,6 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
400
404
  fix: string;
401
405
  };
402
406
  }, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
403
- //#endregion
404
- //#region src/client-send.d.ts
405
407
  /** The logo that a Send segment shows for an agent. `@vite-hub/ui` draws each one. */
406
408
  type CommentSendLogo = "t3" | "claude" | "codex";
407
409
  /** The agent that gets a member's comments. */
@@ -573,8 +575,6 @@ interface CommentSendClient {
573
575
  * pairs one in place first when there is none. `CommentSend` of `@vite-hub/ui` renders it.
574
576
  */
575
577
  export declare function createCommentSend(transport: CommentSendTransport, options?: CommentSendOptions): CommentSendClient;
576
- //#endregion
577
- //#region src/rest-transport.d.ts
578
578
  /** A guest that named itself in the browser. The server keeps the name as display data only. */
579
579
  interface CommentsGuest {
580
580
  id: string;
@@ -638,9 +638,9 @@ interface RestTransport extends CommentsTransport {
638
638
  * `guest` names. Guests and share-link readers can use it. It has no
639
639
  * `subscribe`: the client refreshes when the window gets focus.
640
640
  */
641
- export declare function createRestTransport(options?: RestTransportOptions): RestTransport;
642
- //#endregion
643
- //#region src/send-transport.d.ts
641
+ export declare function createRestTransport(options?: RestTransportOptions & {
642
+ route?: string;
643
+ }): RestTransport;
644
644
  interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base" | "headers" | "credentials" | "fetch"> {
645
645
  /**
646
646
  * The path of the page that Send is on, such as `/notes/azores`. The server turns it into the subject, as `page` of
@@ -660,20 +660,14 @@ interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base"
660
660
  * ```
661
661
  */
662
662
  export declare function createCommentSendTransport(options?: CommentSendTransportOptions): CommentSendTransport;
663
- //#endregion
664
- //#region src/fold-name.d.ts
665
663
  /** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
666
664
  export declare function foldName(text: string): string;
667
- //#endregion
668
- //#region src/reply-id.d.ts
669
665
  /**
670
666
  * The id of the message that a reply with `requestId` stores in a thread. Every retry gets the same id, so the primary
671
667
  * key of the messages refuses a second message, and the client's outbox finds the server copy of its waiting reply.
672
668
  * The server and the browser client both import it, so it has no other import.
673
669
  */
674
670
  export declare function replyMessageId(threadId: string, requestId: string): Promise<string>;
675
- //#endregion
676
- //#region src/client.d.ts
677
671
  export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
678
672
  export interface CommentsClientOptions {
679
673
  transport: CommentsTransport;
@@ -726,5 +720,4 @@ export declare function createCommentsClient(options: CommentsClientOptions & {
726
720
  readonly outbox: CommentsOutbox;
727
721
  };
728
722
  export declare function createCommentsClient(options: CommentsClientOptions): CommentsClient;
729
- //#endregion
730
723
  export type { AnchorPoint, AnchorPosition, AnchorRect, AnchorTarget, AreaAnchor, CommentActor, CommentAnchor, CommentAttachment, CommentBuild, CommentComponent, CommentContext, CommentCreateInput, CommentDeleteInput, CommentDelivery, CommentDeliveryError, CommentEditInput, CommentEvent, CommentFiles, CommentForgeLink, CommentGetInput, CommentListCursor, CommentListQuery, CommentMessage, CommentMetadata, CommentReplyInput, CommentSendAgent, CommentSendClient, CommentSendCopy, CommentSendEvent, CommentSendLogo, CommentSendOptions, CommentSendPairing, CommentSendPairingCheck, CommentSendResult, CommentSendState, CommentSendStatus, CommentSendTransport, CommentSendTransportOptions, CommentStatus, CommentStatusInput, CommentSubject, CommentThread, CommentUploadInput, CommentUser, CommentUsersInput, CommentsGuest, CommentsOutbox, CommentsOutboxEntry, CommentsOutboxEnvironment, CommentsOutboxMessage, CommentsOutboxOptions, CommentsOutboxStore, CommentsRestAnswer, CommentsRestRequest, CommentsTransport, CreateAnchorOptions, DetachedAnchor, ElementAnchor, ImageAnchor, PageAnchor, ResolvedAnchor, RestCommentThread, RestTransport, RestTransportOptions, TextAnchor };
package/dist/client.js CHANGED
@@ -1,11 +1,11 @@
1
- import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-Bubm7Shd.js";
2
- import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-CJZl5Kc4.js";
3
- import { t as replyMessageId } from "./reply-id-P_bSuEng.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
5
- import { i as commentsRoute } from "./page-DRz_sDY4.js";
6
- import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
7
- import { t as foldName } from "./fold-name-B7Zb3-MF.js";
8
- //#region ../internal/src/browser-environment.ts
1
+ import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-CvfTW5d4.js";
2
+ import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-lC6X7XyS.js";
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";
6
+ import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
7
+ import { t as foldName } from "./fold-name-g-xg0mQk.js";
8
+ // ../internal/src/browser-environment.ts
9
9
  /** The real browser: window events, Web Locks, and a BroadcastChannel, each only when the browser has it. */
10
10
  function createBrowserEnvironment(options) {
11
11
  let channel;
@@ -84,8 +84,7 @@ function backoffDelay(attempt, random) {
84
84
  const ceiling = Math.min(3e4, 1e3 * 2 ** attempt);
85
85
  return ceiling / 2 + random * ceiling / 2;
86
86
  }
87
- //#endregion
88
- //#region src/client-outbox.ts
87
+ // src/client-outbox.ts
89
88
  function changeable(entry) {
90
89
  return entry.status !== "sending" && !entry.uncertain;
91
90
  }
@@ -727,8 +726,7 @@ function createOutbox(options, host) {
727
726
  }
728
727
  };
729
728
  }
730
- //#endregion
731
- //#region src/client-anchor.ts
729
+ // src/client-anchor.ts
732
730
  const defaultContext = 32;
733
731
  const clamp = (value) => Math.min(1e3, Math.max(0, value));
734
732
  function thousandths(value, size) {
@@ -1130,8 +1128,7 @@ function resolveAnchor(anchor, root = document) {
1130
1128
  element
1131
1129
  };
1132
1130
  }
1133
- //#endregion
1134
- //#region src/client-send.ts
1131
+ // src/client-send.ts
1135
1132
  const reasonOf = (error) => error instanceof Error ? error.message : String(error);
1136
1133
  /**
1137
1134
  * The Send segment of a comment pill, without a framework: it hands the member's waiting threads to their agent, and
@@ -1484,8 +1481,7 @@ function createCommentSend(transport, options = {}) {
1484
1481
  }
1485
1482
  };
1486
1483
  }
1487
- //#endregion
1488
- //#region src/rest-transport.ts
1484
+ // src/rest-transport.ts
1489
1485
  /** The URL of an attachment key below the Comments API, such as `/_vitehub/comments/attachments/comments/<id>/shot.png`. */
1490
1486
  function commentAttachmentUrl(key, base = "") {
1491
1487
  return `${base.replace(/\/+$/, "")}${commentsRoute}/attachments/${key.split("/").map((part) => encodeURIComponent(part)).join("/")}`;
@@ -1630,8 +1626,7 @@ function createRestTransport(options = {}) {
1630
1626
  attachmentUrl: (key) => commentAttachmentUrl(key, base)
1631
1627
  };
1632
1628
  }
1633
- //#endregion
1634
- //#region src/send-transport.ts
1629
+ // src/send-transport.ts
1635
1630
  /**
1636
1631
  * The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
1637
1632
  * ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
@@ -1676,8 +1671,7 @@ function createCommentSendTransport(options = {}) {
1676
1671
  send: async () => (await request(`/send?page=${page()}`, post())).data
1677
1672
  };
1678
1673
  }
1679
- //#endregion
1680
- //#region src/client.ts
1674
+ // src/client.ts
1681
1675
  function createCommentsClient(options) {
1682
1676
  const { transport } = options;
1683
1677
  const listeners = /* @__PURE__ */ new Set();
@@ -1909,5 +1903,4 @@ function createCommentsClient(options) {
1909
1903
  }
1910
1904
  };
1911
1905
  }
1912
- //#endregion
1913
1906
  export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
@@ -1,4 +1,3 @@
1
- //#region ../internal/src/inspect.d.ts
2
1
  interface ViteHubDefinitionField {
3
2
  label: string;
4
3
  value: string;
@@ -60,8 +59,6 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
60
59
  interface ViteHubInspectionPluginMetadata {
61
60
  inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
62
61
  }
63
- //#endregion
64
- //#region ../internal/src/console.d.ts
65
62
  type MaybePromise<T> = T | Promise<T>;
66
63
  /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
67
64
  interface ViteHubConsoleDefinitionCatalogView {
@@ -330,5 +327,4 @@ interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteH
330
327
  }
331
328
  /** A section whose list comes from an operation, called with the Console user on each visit. It has no build-time data. */
332
329
  interface ViteHubConsoleOperationSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleOperationView> {}
333
- //#endregion
334
330
  export { ViteHubInspectionPluginMetadata as i, ViteHubConsoleRecord as n, ViteHubConsoleRuntimeRecordTableSection as r, ViteHubConsoleOperationSection as t };
@@ -1,4 +1,4 @@
1
- //#region src/context.ts
1
+ // src/context.ts
2
2
  /**
3
3
  * The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
4
4
  * browser, build. The Console and Agent tools show these.
@@ -57,5 +57,4 @@ function describeCommentContext(context) {
57
57
  });
58
58
  return fields;
59
59
  }
60
- //#endregion
61
60
  export { describeCommentContext as t };
@@ -1,4 +1,3 @@
1
- //#region src/operations-core/database/postgres.d.ts
2
1
  /**
3
2
  * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`, and
4
3
  * `resolvedBy` hold JSON. Times are milliseconds since the epoch.
@@ -1398,5 +1397,4 @@ export declare const commentsPostgresSchema: {
1398
1397
  dialect: "pg";
1399
1398
  isAlias: false;
1400
1399
  }>;
1401
- };
1402
- //#endregion
1400
+ };
@@ -1,5 +1,5 @@
1
1
  import { bigint, boolean, index, pgTable, text, uniqueIndex } from "drizzle-orm/pg-core";
2
- //#region src/operations-core/database/postgres.ts
2
+ // src/operations-core/database/postgres.ts
3
3
  /**
4
4
  * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`, and
5
5
  * `resolvedBy` hold JSON. Times are milliseconds since the epoch.
@@ -77,5 +77,4 @@ const commentsPostgresSchema = {
77
77
  vitehubCommentCounters: commentCounters,
78
78
  vitehubCommentForge: commentForge
79
79
  };
80
- //#endregion
81
80
  export { commentCounters, commentForge, commentMessages, commentThreads, commentsPostgresSchema };
@@ -1,63 +1,78 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
4
- //#region src/operations-core/database.ts
4
+ // src/operations-core/database.ts
5
+ /**
6
+ * The thread, message, and counter tables of Comments under other names, for an app that keeps more than one set
7
+ * in one Database. Pass them to `installComments({ tables, tenant })`. Messages have no foreign key to their thread,
8
+ * because a thread is stored after its first message: delete the messages of a deleted thread with a trigger.
9
+ */
10
+ function commentsSqliteTables(options) {
11
+ const { prefix, scope } = options;
12
+ const scopeColumn = () => scope ? text("scope").notNull().references(scope, { onDelete: "cascade" }) : text("scope").notNull();
13
+ return {
14
+ commentThreads: sqliteTable(`${prefix}_threads`, {
15
+ id: text("id").primaryKey(),
16
+ scope: scopeColumn(),
17
+ n: integer("n").notNull(),
18
+ subjectKind: text("subject_kind").notNull(),
19
+ subjectId: text("subject_id").notNull(),
20
+ anchor: text("anchor").notNull(),
21
+ status: text("status", { enum: ["open", "resolved"] }).notNull(),
22
+ resolvedBy: text("resolved_by"),
23
+ resolvedAt: integer("resolved_at"),
24
+ authorId: text("author_id").notNull(),
25
+ authorName: text("author_name"),
26
+ authorImage: text("author_image"),
27
+ actor: text("actor"),
28
+ /** JSON of the fields that app code keeps on the thread. */
29
+ metadata: text("metadata"),
30
+ /** JSON of the page, element, components, browser, and build that the overlay read. */
31
+ context: text("context"),
32
+ /** The version of the subject that the thread was started on. */
33
+ revision: integer("revision"),
34
+ /** The retry key of `comments.create`. Unique inside `scope`. */
35
+ requestId: text("request_id"),
36
+ createdAt: integer("created_at").notNull(),
37
+ updatedAt: integer("updated_at").notNull()
38
+ }, (table) => [
39
+ uniqueIndex(`${prefix}_threads_scope_n`).on(table.scope, table.n),
40
+ uniqueIndex(`${prefix}_threads_scope_request`).on(table.scope, table.requestId),
41
+ index(`${prefix}_threads_subject`).on(table.subjectKind, table.subjectId),
42
+ index(`${prefix}_threads_status`).on(table.status, table.updatedAt)
43
+ ]),
44
+ commentMessages: sqliteTable(`${prefix}_messages`, {
45
+ id: text("id").primaryKey(),
46
+ threadId: text("thread_id").notNull(),
47
+ body: text("body").notNull(),
48
+ authorId: text("author_id").notNull(),
49
+ authorName: text("author_name"),
50
+ authorImage: text("author_image"),
51
+ actor: text("actor"),
52
+ mentions: text("mentions").notNull(),
53
+ attachments: text("attachments").notNull(),
54
+ createdAt: integer("created_at").notNull(),
55
+ editedAt: integer("edited_at")
56
+ }, (table) => [index(`${prefix}_messages_thread`).on(table.threadId, table.createdAt)]),
57
+ commentCounters: sqliteTable(`${prefix}_counters`, {
58
+ scope: (scope ? scopeColumn() : text("scope")).primaryKey(),
59
+ next: integer("next").notNull()
60
+ })
61
+ };
62
+ }
63
+ const defaultTables = commentsSqliteTables({ prefix: "vitehub_comment" });
5
64
  /**
6
65
  * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`,
7
66
  * `resolvedBy`, `metadata`, and `context` hold JSON. Times are milliseconds since the epoch.
8
67
  */
9
- const commentThreads = sqliteTable("vitehub_comment_threads", {
10
- id: text("id").primaryKey(),
11
- scope: text("scope").notNull(),
12
- n: integer("n").notNull(),
13
- subjectKind: text("subject_kind").notNull(),
14
- subjectId: text("subject_id").notNull(),
15
- anchor: text("anchor").notNull(),
16
- status: text("status", { enum: ["open", "resolved"] }).notNull(),
17
- resolvedBy: text("resolved_by"),
18
- resolvedAt: integer("resolved_at"),
19
- authorId: text("author_id").notNull(),
20
- authorName: text("author_name"),
21
- authorImage: text("author_image"),
22
- actor: text("actor"),
23
- /** JSON of the fields that app code keeps on the thread. */
24
- metadata: text("metadata"),
25
- /** JSON of the page, element, components, browser, and build that the overlay read. */
26
- context: text("context"),
27
- /** The version of the subject that the thread was started on. */
28
- revision: integer("revision"),
29
- /** The retry key of `comments.create`. Unique inside `scope`. */
30
- requestId: text("request_id"),
31
- createdAt: integer("created_at").notNull(),
32
- updatedAt: integer("updated_at").notNull()
33
- }, (table) => [
34
- uniqueIndex("vitehub_comment_threads_scope_n").on(table.scope, table.n),
35
- uniqueIndex("vitehub_comment_threads_scope_request").on(table.scope, table.requestId),
36
- index("vitehub_comment_threads_subject").on(table.subjectKind, table.subjectId),
37
- index("vitehub_comment_threads_status").on(table.status, table.updatedAt)
38
- ]);
68
+ const commentThreads = defaultTables.commentThreads;
39
69
  /** One Markdown message. The first message of a thread is the comment. `mentions` and `attachments` hold JSON lists. */
40
- const commentMessages = sqliteTable("vitehub_comment_messages", {
41
- id: text("id").primaryKey(),
42
- threadId: text("thread_id").notNull(),
43
- body: text("body").notNull(),
44
- authorId: text("author_id").notNull(),
45
- authorName: text("author_name"),
46
- authorImage: text("author_image"),
47
- actor: text("actor"),
48
- mentions: text("mentions").notNull(),
49
- attachments: text("attachments").notNull(),
50
- createdAt: integer("created_at").notNull(),
51
- editedAt: integer("edited_at")
52
- }, (table) => [index("vitehub_comment_messages_thread").on(table.threadId, table.createdAt)]);
70
+ const commentMessages = defaultTables.commentMessages;
53
71
  /**
54
72
  * The next thread number of each scope. A number is handed out once, so a deleted thread never gives its number to a
55
73
  * new one, and a link such as `?comment=3` keeps naming the same thread.
56
74
  */
57
- const commentCounters = sqliteTable("vitehub_comment_counters", {
58
- scope: text("scope").primaryKey(),
59
- next: integer("next").notNull()
60
- });
75
+ const commentCounters = defaultTables.commentCounters;
61
76
  /**
62
77
  * The pull request comment of each message, when `defineComments({ forge })` posts threads. `id` is a message id,
63
78
  * `summary:<repository>#<pull request>`, or `cleanup:<repository>#<remote id>` for a pending delete.
@@ -92,8 +107,7 @@ const commentsSchema = {
92
107
  vitehubCommentCounters: commentCounters,
93
108
  vitehubCommentForge: commentForge
94
109
  };
95
- //#endregion
96
- //#region src/tables.ts
110
+ // src/tables.ts
97
111
  /**
98
112
  * The tables of `commentsSchema` as SQLite statements that are safe to run on every start. A database that Comments
99
113
  * opens itself gets them on first use; a ViteHub Database gets the same tables from `vitehub database generate` instead.
@@ -113,8 +127,7 @@ const commentsTables = [
113
127
  "CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_thread` ON `vitehub_comment_forge` (`thread_id`)",
114
128
  "CREATE INDEX IF NOT EXISTS `vitehub_comment_forge_pull_request` ON `vitehub_comment_forge` (`repository`,`pull_request`)"
115
129
  ];
116
- //#endregion
117
- //#region src/migrate.ts
130
+ // src/migrate.ts
118
131
  /** The live-site threads, after the migration renames them. The migration never deletes them. */
119
132
  const liveThreadsBackup = "vitehub_comment_threads_live";
120
133
  /** The columns that one model added to `vitehub_comment_threads` after its first version. */
@@ -203,13 +216,14 @@ function runSqliteStatements(db, statements, start = 0) {
203
216
  function names(rows) {
204
217
  return (Array.isArray(rows) ? rows : Array.isArray(Reflect.get(Object(rows), "rows")) ? Reflect.get(Object(rows), "rows") : []).map((row) => String(Array.isArray(row) ? row[0] : Object.values(Object(row))[0]));
205
218
  }
206
- async function columns(db, postgres) {
207
- if (postgres) return names(await db.execute(sql.raw("SELECT column_name FROM information_schema.columns WHERE table_name = 'vitehub_comment_threads' AND table_schema = current_schema()")));
208
- return names(await db.all(sql.raw("SELECT name FROM pragma_table_info('vitehub_comment_threads')")));
219
+ async function columns(db, postgres, table = "vitehub_comment_threads") {
220
+ const name = `'${table.replaceAll("'", "''")}'`;
221
+ if (postgres) return names(await db.execute(sql.raw(`SELECT column_name FROM information_schema.columns WHERE table_name = ${name} AND table_schema = current_schema()`)));
222
+ return names(await db.all(sql.raw(`SELECT name FROM pragma_table_info(${name})`)));
209
223
  }
210
224
  /** What the Database has: no comments yet, the live-site tables, one model without newer columns, or nothing to do. */
211
225
  async function commentsSchemaState(db, options = {}) {
212
- const found = await columns(db, options.dialect === "postgresql");
226
+ const found = await columns(db, options.dialect === "postgresql", options.table);
213
227
  if (!found.length) return {
214
228
  missing: [],
215
229
  state: "empty"
@@ -285,8 +299,7 @@ function commentsSchemaGate(db, owner, options = {}) {
285
299
  return ready;
286
300
  };
287
301
  }
288
- //#endregion
289
- //#region src/send/database.ts
302
+ // src/send/database.ts
290
303
  /**
291
304
  * One row for each send: the member, the threads it carried with the last message of each, and the read token. `threads`
292
305
  * holds JSON, `[{ id, message, role }]`, and `sender` the member as Comments knew them when they sent. The token is
@@ -330,5 +343,4 @@ const commentSendsTables = [
330
343
  "CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_subject` ON `vitehub_comment_sends` (`subject_kind`,`subject_id`,`created_at`)",
331
344
  "CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_comment_sends_live_key` ON `vitehub_comment_sends` (`key`) WHERE `state` <> 'failed'"
332
345
  ];
333
- //#endregion
334
- export { commentsSchemaGate as a, migrateComments as c, commentForge as d, commentMessages as f, commentsMigrationSql as i, commentsTables as l, commentsSchema as m, commentSendsSchema as n, commentsSchemaState as o, commentThreads as p, commentSendsTables as r, liveThreadsBackup as s, commentSends as t, commentCounters as u };
346
+ export { commentsSchemaGate as a, migrateComments as c, commentForge as d, commentMessages as f, commentsSqliteTables as h, commentsMigrationSql as i, commentsTables as l, commentsSchema as m, commentSendsSchema as n, commentsSchemaState as o, commentThreads as p, commentSendsTables as r, liveThreadsBackup as s, commentSends as t, commentCounters as u };
@@ -1,4 +1,3 @@
1
- //#region src/send/database.d.ts
2
1
  /** Where a send is: delivered, read by the agent, answered, or not delivered. */
3
2
  type CommentSendState = "pending" | "sent" | "working" | "done" | "failed";
4
3
  /**
@@ -571,5 +570,4 @@ declare const commentSendsSchema: {
571
570
  };
572
571
  /** `commentSendsSchema` as SQLite statements that are safe to run on every start. */
573
572
  declare const commentSendsTables: readonly string[];
574
- //#endregion
575
573
  export { commentSendsTables as i, commentSends as n, commentSendsSchema as r, CommentSendState as t };