@vite-hub/comments 0.6.0 → 0.7.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 (52) hide show
  1. package/README.md +23 -6
  2. package/dist/{client-diagnostics-CvfTW5d4.js → client-diagnostics-DoXqdnBd.js} +12 -0
  3. package/dist/client.d.ts +119 -23
  4. package/dist/client.js +708 -209
  5. package/dist/{database-BkPoOdZr.js → database-BuSNVwTx.js} +1 -1
  6. package/dist/database.js +1 -1
  7. package/dist/{define-BCxNaSZv.js → define-BqPcuDhf.js} +1 -1
  8. package/dist/{errors-DFNiJg67.js → errors-CBvIpwbo.js} +1 -1
  9. package/dist/hosted/hosted-comments/frame.js +1 -1
  10. package/dist/hosted/hosted-comments/tools.js +371 -0
  11. package/dist/hosted/hosted-comments.js +1 -9
  12. package/dist/index.js +11 -10
  13. package/dist/{install-NehuMNhG.d.ts → install-9L4ASzUC.d.ts} +10 -1
  14. package/dist/{install-w6CCgGFV.js → install-CqBWFmU7.js} +23 -15
  15. package/dist/{installed-C9SkldMi.js → installed-wUYjqk_k.js} +1 -1
  16. package/dist/{operations-8hqTi0DH.d.ts → operations-DFLer1fR.d.ts} +1 -0
  17. package/dist/{operations-Cic9A9e_.d.ts → operations-Qt8ASQqW.d.ts} +2 -2
  18. package/dist/{operations-B8IMhRmY.js → operations-kMPw-Cyb.js} +10 -11
  19. package/dist/operations.d.ts +2 -2
  20. package/dist/operations.js +2 -2
  21. package/dist/overlay/client-CrnKCZXc.js +4 -0
  22. package/dist/overlay/overlay.js +70 -29
  23. package/dist/page/loader.js +25 -23
  24. package/dist/{page-xzgZ6DGm.js → page-2NzFladc.js} +5 -1
  25. package/dist/{page-tools-shared-fvmJQCrP.js → page-tools-shared-BNw-aWEH.js} +2 -5
  26. package/dist/{plugin-DbCYT7Ac.js → plugin-ChOHe7vq.js} +9 -8
  27. package/dist/realtime.d.ts +12 -1
  28. package/dist/realtime.js +14 -6
  29. package/dist/{request-origin-YPzfE2eh.js → request-origin-B-CPVAVk.js} +6 -1
  30. package/dist/{rpc-BKY7XRlR.js → rpc-kkxzQ3Qy.js} +1 -1
  31. package/dist/rpc.js +1 -1
  32. package/dist/runtime/auth.js +1 -1
  33. package/dist/runtime/console.js +2 -2
  34. package/dist/runtime/index.d.ts +4 -1
  35. package/dist/runtime/index.js +16 -14
  36. package/dist/{server-BGbD7H5s.js → server-8o9u8leM.js} +1 -1
  37. package/dist/server.d.ts +3 -3
  38. package/dist/server.js +6 -6
  39. package/dist/{service-CPiWPoiY.d.ts → service-IvgrI4XM.d.ts} +2 -0
  40. package/dist/{service-DUh2uGd2.js → service-XT2A8YEF.js} +11 -6
  41. package/dist/{session-_1GY5gaG.js → session-DGdFKWDB.js} +8 -7
  42. package/dist/testing.js +1 -1
  43. package/dist/vite.d.ts +2 -1
  44. package/dist/vite.js +31 -11
  45. package/package.json +9 -8
  46. package/dist/hosted/hosted-comments/client-B3dlmmQd.js +0 -4
  47. package/dist/hosted/hosted-comments/dist-DyVmH21U.js +0 -14
  48. package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +0 -182
  49. package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +0 -1
  50. package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +0 -1
  51. package/dist/hosted/hosted-comments/tools-Bz--joZw.js +0 -126
  52. package/dist/overlay/client-CerbVjTz.js +0 -4
package/dist/realtime.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as text } from "./identity-CT7-UGmS.js";
2
- import { o as normalizeCommentPage, t as commentRoom } from "./page-xzgZ6DGm.js";
3
- import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-_1GY5gaG.js";
2
+ import { c as normalizeCommentPage, n as commentRoom, r as commentsNoticeDefinition, t as commentNoticeRoom } from "./page-2NzFladc.js";
3
+ import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-DGdFKWDB.js";
4
4
  // src/realtime.ts
5
5
  function toRealtimeUser(user) {
6
6
  const result = { id: user.id };
@@ -18,7 +18,7 @@ function toRealtimeUser(user) {
18
18
  * Guests name themselves in the browser. ViteHub adds it as the `comments` definition when the host has a room
19
19
  * authority.
20
20
  */
21
- function commentsRealtime(comments, options = {}) {
21
+ function commentsRealtime(comments, options = {}, purpose = "presence") {
22
22
  const readers = /* @__PURE__ */ new WeakMap();
23
23
  return {
24
24
  async identify({ event }) {
@@ -32,15 +32,23 @@ function commentsRealtime(comments, options = {}) {
32
32
  if (mode !== "read" || identity === void 0) return false;
33
33
  const page = new URL(request.url).searchParams.get("page");
34
34
  if (!page) return false;
35
- if (documentId !== commentRoom(normalizeCommentPage(page))) return false;
35
+ if (purpose === "presence" && documentId !== commentRoom(normalizeCommentPage(page))) return false;
36
36
  const { subject } = await resolveCommentsPage(comments, event, request, page);
37
+ if (purpose === "notices" && documentId !== commentNoticeRoom(subject)) return false;
37
38
  return await comments.can({
38
39
  user: identity.user,
39
40
  action: "read",
40
41
  subject
41
42
  }, identity.gate);
42
43
  },
43
- document: false
44
+ document: false,
45
+ ...purpose === "notices" ? { awareness: false } : {}
44
46
  };
45
47
  }
46
- export { commentsRealtime };
48
+ /** The notice that tells the open pages of a thread to load their threads again. */
49
+ const commentsChangeNotice = { type: "comments" };
50
+ /** Tells the browsers on the page of a thread that it changed, so they load their threads again. It never throws. */
51
+ async function notifyCommentsChange(thread) {
52
+ await (await import("@vite-hub/realtime/server").catch(() => void 0))?.notifyRealtimeRoom(commentsNoticeDefinition, commentNoticeRoom(thread.subject), commentsChangeNotice);
53
+ }
54
+ export { commentsChangeNotice, commentsRealtime, notifyCommentsChange };
@@ -2,6 +2,11 @@
2
2
  function firstHeaderValue(headers, name) {
3
3
  return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
4
4
  }
5
+ const applicationOriginKey = Symbol.for("vitehub.request.application-origin");
6
+ const requestGlobals = globalThis;
7
+ function applicationRequestOrigin(request) {
8
+ return requestGlobals[applicationOriginKey]?.get(request) ?? forwardedRequestOrigin(request);
9
+ }
5
10
  /**
6
11
  * The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
7
12
  * `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
@@ -45,4 +50,4 @@ function isSecureOrigin(origin) {
45
50
  if (protocol !== "http:") return false;
46
51
  return isLoopbackHostname(hostname) || hostname.endsWith(".localhost");
47
52
  }
48
- export { isSecureOrigin as n, matchesPublicOrigin as r, forwardedRequestOrigin as t };
53
+ export { isSecureOrigin as n, matchesPublicOrigin as r, applicationRequestOrigin as t };
@@ -1,5 +1,5 @@
1
1
  import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
2
- import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-CvfTW5d4.js";
2
+ import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-DoXqdnBd.js";
3
3
  import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf } from "./client-files-lC6X7XyS.js";
4
4
  import { createBirpc } from "birpc";
5
5
  // ../internal/src/operation-rpc.ts
package/dist/rpc.js CHANGED
@@ -1 +1 @@
1
- export { t as createRpcTransport } from "./rpc-BKY7XRlR.js";
1
+ export { t as createRpcTransport } from "./rpc-kkxzQ3Qy.js";
@@ -1,4 +1,4 @@
1
- import { n as createAuthUsers } from "../server-BGbD7H5s.js";
1
+ import { n as createAuthUsers } from "../server-8o9u8leM.js";
2
2
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
3
3
  // src/runtime/auth.ts
4
4
  const authServer = () => import("@vite-hub/auth/internal/server");
@@ -1,6 +1,6 @@
1
1
  import { t as describeCommentContext } from "../context-DbkBjITZ.js";
2
- import { n as commentsPageScope } from "../page-xzgZ6DGm.js";
3
- import { n as installedComments } from "../plugin-DbCYT7Ac.js";
2
+ import { i as commentsPageScope } from "../page-2NzFladc.js";
3
+ import { n as installedComments } from "../plugin-ChOHe7vq.js";
4
4
  // src/runtime/console.ts
5
5
  function excerpt(text) {
6
6
  const line = text.replace(/\s+/g, " ").trim();
@@ -3,7 +3,7 @@ import { g as CommentsUser } from "../define-B1jLSPe9.js";
3
3
  import { t as Comments } from "../index-D1T7RJ4R.js";
4
4
  import { f as CommentsRequestEvent } from "../types-l6GOb_yc.js";
5
5
  import { t as CommentsSessionOptions } from "../session-CN4irEqf.js";
6
- import { t as InstallCommentsOptions } from "../install-NehuMNhG.js";
6
+ import { t as InstallCommentsOptions } from "../install-9L4ASzUC.js";
7
7
  import { t as CommentsDatabase } from "../store-DvNTDNgn.js";
8
8
  /**
9
9
  * A person that Site access in the ViteHub Console signed in to the app: a Console member, or a guest, with their roles,
@@ -23,6 +23,7 @@ interface ViteHubSiteVisitor {
23
23
  id: string;
24
24
  teamId: string;
25
25
  url: string;
26
+ name?: string;
26
27
  };
27
28
  resolve: boolean;
28
29
  };
@@ -163,6 +164,8 @@ interface CommentsPluginOptions extends CommentsSessionOptions {
163
164
  dialect?: InstallCommentsOptions["dialect"];
164
165
  /** Loads `@vite-hub/webhooks`, when `defineComments({ send })` is on. */
165
166
  webhooks?: InstallCommentsOptions["webhooks"];
167
+ /** Loads `@vite-hub/comments/realtime`, when the app has the page presence rooms. */
168
+ realtime?: InstallCommentsOptions["realtime"];
166
169
  /** Install more segments of the pill, such as the **Console** segment of `vite-hub`. Only with the overlay on. */
167
170
  pillSegments?: ReadonlyArray<(nitroApp: unknown, context: {
168
171
  base?: string;
@@ -1,17 +1,17 @@
1
1
  import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-Bx4lZ0yt.js";
2
- import { t as forwardedRequestOrigin } from "../request-origin-YPzfE2eh.js";
2
+ import { t as applicationRequestOrigin } from "../request-origin-B-CPVAVk.js";
3
3
  import "../client-files-lC6X7XyS.js";
4
4
  import { t as commentsErrors } from "../errors-C0VwRHiy.js";
5
5
  import { i as text, n as guestFromHeaders, t as authorOf } from "../identity-CT7-UGmS.js";
6
- import { a as runtimeOf, r as resolveCommentsRuntime, t as commentSendOf } from "../installed-C9SkldMi.js";
7
- import { a as commentThreadSummary, c as hiddenThreadsNote, n as commentAnchorSchema, o as commentThreadsText, r as commentInputSchemas, s as describeCommentThread, t as commentActions } from "../operations-B8IMhRmY.js";
8
- import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-BCxNaSZv.js";
9
- import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-DUh2uGd2.js";
10
- import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage } from "../page-xzgZ6DGm.js";
11
- import { n as resolveCommentsPage, o as viteHubPageSessionHandler, t as resolveCommentsIdentity } from "../session-_1GY5gaG.js";
12
- import { n as installedComments, t as defineCommentsPlugin } from "../plugin-DbCYT7Ac.js";
6
+ import { a as runtimeOf, r as resolveCommentsRuntime, t as commentSendOf } from "../installed-wUYjqk_k.js";
7
+ import { a as commentThreadSummary, c as hiddenThreadsNote, n as commentAnchorSchema, o as commentThreadsText, r as commentInputSchemas, s as describeCommentThread, t as commentActions } from "../operations-kMPw-Cyb.js";
8
+ import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-BqPcuDhf.js";
9
+ import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-XT2A8YEF.js";
10
+ import { c as normalizeCommentPage, i as commentsPageScope, o as commentsRoute } from "../page-2NzFladc.js";
11
+ import { n as resolveCommentsPage, o as viteHubPageSessionHandler, t as resolveCommentsIdentity } from "../session-DGdFKWDB.js";
12
+ import { n as installedComments, t as defineCommentsPlugin } from "../plugin-ChOHe7vq.js";
13
13
  import { t as invariant } from "../invariant-CmdvZ3vp.js";
14
- import { t as commentsErrorDiagnostics } from "../errors-DFNiJg67.js";
14
+ import { t as commentsErrorDiagnostics } from "../errors-CBvIpwbo.js";
15
15
  import { getStandardContext, installRequestStandardContext } from "@vite-hub/runtime/internal/h3";
16
16
  import * as v from "valibot";
17
17
  import { configuredConsoleOrigin } from "@vite-hub/runtime/internal/console";
@@ -146,7 +146,7 @@ function respond([error, data]) {
146
146
  }
147
147
  function sameOrigin(request) {
148
148
  const origin = request.headers.get("origin");
149
- return !origin || origin === forwardedRequestOrigin(request);
149
+ return !origin || origin === applicationRequestOrigin(request);
150
150
  }
151
151
  function readPath(data, path) {
152
152
  let current = data;
@@ -287,6 +287,7 @@ function createCommentsHandler(options) {
287
287
  ...identity.commentsAgent,
288
288
  mcp: `${configuredConsoleOrigin()}/mcp/account`
289
289
  } : void 0;
290
+ const repository = read ? comments.options.forge?.repository ?? options.build?.repository : void 0;
290
291
  return json({ data: {
291
292
  user: user ? authorOf(user) : null,
292
293
  ...user && user.github ? { github: user.github } : {},
@@ -304,6 +305,7 @@ function createCommentsHandler(options) {
304
305
  content: Boolean(options.content),
305
306
  ...send ? { send: true } : {},
306
307
  ...agent ? { agent } : {},
308
+ ...repository ? { repository } : {},
307
309
  ...subject ? { subject } : {},
308
310
  ...revision === void 0 ? {} : { revision }
309
311
  } });
@@ -389,7 +391,7 @@ function createCommentsHandler(options) {
389
391
  * the origin and the path, and gives the revision of the page subject.
390
392
  */
391
393
  async function checkContext(request, context, subject) {
392
- const origin = forwardedRequestOrigin(request);
394
+ const origin = applicationRequestOrigin(request);
393
395
  let submitted;
394
396
  try {
395
397
  submitted = new URL(context.url);
@@ -505,7 +507,7 @@ function createCommentsHandler(options) {
505
507
  const method = request.method;
506
508
  const [, action, code] = parts;
507
509
  if (method === "POST" && action === "pair" && !code) {
508
- const [error, paired] = await service.pair(await readJson(request), forwardedRequestOrigin(request));
510
+ const [error, paired] = await service.pair(await readJson(request), applicationRequestOrigin(request));
509
511
  return error ? json({
510
512
  error,
511
513
  reason: {
@@ -531,7 +533,7 @@ function createCommentsHandler(options) {
531
533
  gate,
532
534
  subject,
533
535
  page: normalizeCommentPage(url.searchParams.get("page") ?? "/"),
534
- origin: forwardedRequestOrigin(request),
536
+ origin: applicationRequestOrigin(request),
535
537
  route: pathname.slice(0, pathname.indexOf(commentsRoute) + commentsRoute.length)
536
538
  };
537
539
  };
@@ -1182,7 +1184,7 @@ function createCommentsGitHubLogin(options = {}) {
1182
1184
  const clientId = serverEnv(githubLoginEnv.clientId);
1183
1185
  const clientSecret = serverEnv(githubLoginEnv.clientSecret);
1184
1186
  const secret = sessionSecret();
1185
- const origin = forwardedRequestOrigin(request);
1187
+ const origin = applicationRequestOrigin(request);
1186
1188
  const key = [
1187
1189
  origin,
1188
1190
  clientId,
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
2
2
  // src/operations-core/server.ts
3
3
  const key = Symbol.for("vitehub.comments.runtime");
4
4
  const scope = globalThis;
package/dist/server.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { b as validateCommentsDefinition, d as CommentsPeople } from "./define-B1jLSPe9.js";
2
- import { a as maximumCommentBodyLength, i as CommentsRuntime, n as CommentsAttachmentStore, r as CommentsForgeHooks } from "./service-CPiWPoiY.js";
2
+ import { a as maximumCommentBodyLength, i as CommentsRuntime, n as CommentsAttachmentStore, r as CommentsForgeHooks } from "./service-IvgrI4XM.js";
3
3
  import { i as createCommentsStore, n as CommentsStore, r as CommentsTables, t as CommentsDatabase } from "./store-DvNTDNgn.js";
4
- import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Cic9A9e_.js";
4
+ import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Qt8ASQqW.js";
5
5
  import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-D-eqtyfh.js";
6
- import { n as installComments, t as InstallCommentsOptions } from "./install-NehuMNhG.js";
6
+ import { n as installComments, t as InstallCommentsOptions } from "./install-9L4ASzUC.js";
7
7
  /** Where mentions find people. The same shape as `defineComments({ people })`. */
8
8
  export type CommentsUsers = CommentsPeople;
9
9
  /**
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
- import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-BGbD7H5s.js";
2
- import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-B8IMhRmY.js";
3
- import { t as createRpcTransport } from "./rpc-BKY7XRlR.js";
4
- import { f as maximumCommentBodyLength } from "./service-DUh2uGd2.js";
5
- import { r as createCommentsStore, t as installComments } from "./install-w6CCgGFV.js";
6
- import { c as validateCommentsDefinition } from "./define-BCxNaSZv.js";
1
+ import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-8o9u8leM.js";
2
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-kMPw-Cyb.js";
3
+ import { t as createRpcTransport } from "./rpc-kkxzQ3Qy.js";
4
+ import { f as maximumCommentBodyLength } from "./service-XT2A8YEF.js";
5
+ import { r as createCommentsStore, t as installComments } from "./install-CqBWFmU7.js";
6
+ import { c as validateCommentsDefinition } from "./define-BqPcuDhf.js";
7
7
  export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };
@@ -65,5 +65,7 @@ interface CommentsRuntime {
65
65
  background?: (task: Promise<unknown>) => void;
66
66
  /** Runs after someone opens a thread again. With Send, it puts back the sends that carried the thread. */
67
67
  reopened?: (thread: CommentThread) => Promise<unknown>;
68
+ /** Tells the open pages of a thread that it changed, such as through a Realtime notice to its page room. */
69
+ changed?: (thread: CommentThread) => Promise<void>;
68
70
  }
69
71
  export { maximumCommentBodyLength as a, CommentsRuntime as i, CommentsAttachmentStore as n, SharedRateLimit as o, CommentsForgeHooks as r, CommentsAttachmentBody as t };
@@ -1,9 +1,9 @@
1
1
  import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
3
2
  import { t as isPagePath } from "./path-8yqMd8zR.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
4
4
  import { t as foldName } from "./fold-name-g-xg0mQk.js";
5
5
  import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
6
- import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-BCxNaSZv.js";
6
+ import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-BqPcuDhf.js";
7
7
  import { t as logFailure } from "./request-log-DllKQXj7.js";
8
8
  import * as v from "valibot";
9
9
  // ../internal/src/runtime/client-rate-limit.ts
@@ -113,6 +113,11 @@ const inlineTypes = [
113
113
  "image/webp",
114
114
  "image/avif"
115
115
  ];
116
+ /** Runs the hooks that follow a change of a thread: the pull request sync and the notice to its open pages. */
117
+ async function threadChanged(runtime, thread) {
118
+ runtime.forge?.changed(thread.id);
119
+ await runtime.changed?.(thread).catch(() => void 0);
120
+ }
116
121
  /** An error with the HTTP status that the operation RPC answers. */
117
122
  function fail(error, status) {
118
123
  return Object.assign(error, { status });
@@ -447,7 +452,7 @@ async function createThread(runtime, input, options = {}) {
447
452
  ...options.request ? { request: options.request } : {},
448
453
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
449
454
  });
450
- runtime.forge?.changed(created.id);
455
+ await threadChanged(runtime, created);
451
456
  return created;
452
457
  }
453
458
  /** The message that an earlier reply with this `requestId` stored in the thread. A retry gets it back before the reply checks. */
@@ -514,7 +519,7 @@ async function replyToThread(runtime, thread, input, options = {}) {
514
519
  ...options.request ? { request: options.request } : {},
515
520
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
516
521
  });
517
- runtime.forge?.changed(next.id);
522
+ await threadChanged(runtime, next);
518
523
  return {
519
524
  message,
520
525
  thread: next
@@ -548,7 +553,7 @@ async function editMessage(runtime, thread, messageId, input, options) {
548
553
  comment: false,
549
554
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
550
555
  });
551
- runtime.forge?.changed(next.id);
556
+ await threadChanged(runtime, next);
552
557
  return next;
553
558
  }
554
559
  function safeName(name) {
@@ -661,4 +666,4 @@ async function readAttachment(runtime, key, context) {
661
666
  type
662
667
  };
663
668
  }
664
- export { clientAddressKey as C, suggest as S, createClientRateLimit as T, requestIdSchema as _, createThread as a, scopeOf as b, earlierThread as c, maximumAttachmentBytes as d, maximumCommentBodyLength as f, replyToThread as g, readAttachment as h, contextSchema as i, editMessage as l, personOf as m, base64 as n, deniedError as o, mentionedPeople as p, can as r, earlierReply as s, attachmentThread as t, fail as u, retried as v, clientRateLimitIssue as w, storeAttachment as x, retriedReply as y };
669
+ export { threadChanged as C, createClientRateLimit as E, suggest as S, clientRateLimitIssue as T, requestIdSchema as _, createThread as a, scopeOf as b, earlierThread as c, maximumAttachmentBytes as d, maximumCommentBodyLength as f, replyToThread as g, readAttachment as h, contextSchema as i, editMessage as l, personOf as m, base64 as n, deniedError as o, mentionedPeople as p, can as r, earlierReply as s, attachmentThread as t, fail as u, retried as v, clientAddressKey as w, storeAttachment as x, retriedReply as y };
@@ -1,6 +1,6 @@
1
- import { f as viteHubPageToolsWanted, l as viteHubPageToolsLoader, n as viteHubBasePath, o as viteHubPageToolsHintCookie, p as withViteHubBase, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript, t as readViteHubPageAccount, u as viteHubPageToolsMarker } from "./page-tools-shared-fvmJQCrP.js";
2
- import { r as matchesPublicOrigin, t as forwardedRequestOrigin } from "./request-origin-YPzfE2eh.js";
3
- import { o as normalizeCommentPage } from "./page-xzgZ6DGm.js";
1
+ import { f as viteHubPageToolsWanted, l as viteHubPageToolsLoader, n as viteHubBasePath, o as viteHubPageToolsHintCookie, p as withViteHubBase, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript, t as readViteHubPageAccount, u as viteHubPageToolsMarker } from "./page-tools-shared-BNw-aWEH.js";
2
+ import { r as matchesPublicOrigin, t as applicationRequestOrigin } from "./request-origin-B-CPVAVk.js";
3
+ import { c as normalizeCommentPage } from "./page-2NzFladc.js";
4
4
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
5
5
  // ../internal/src/runtime/page-tools-html.ts
6
6
  /** The effective script-element directive is shared by HTTP and HTML meta policies. */
@@ -30,7 +30,7 @@ function isGeneratedCheck(inline) {
30
30
  try {
31
31
  const path = JSON.parse(inline.slice(at + 7, -1));
32
32
  const nonce = tagNonce(inline);
33
- return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=22") && viteHubPageToolsInlineScript(path.slice(0, -36), nonce) === `${inline}<\/script>`;
33
+ return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=25") && viteHubPageToolsInlineScript(path.slice(0, -36), nonce) === `${inline}<\/script>`;
34
34
  } catch {
35
35
  return false;
36
36
  }
@@ -211,7 +211,8 @@ function viteHubSiteVisitorReader() {
211
211
  }
212
212
  /** Whether the app serves its page tools on the origin of the request. Every origin counts for an app without `origins`. */
213
213
  function servesOrigin(nitroApp, request) {
214
- return matchesPublicOrigin(request, state().origins?.get(nitroApp) ?? []);
214
+ const origins = state().origins?.get(nitroApp) ?? [];
215
+ return matchesPublicOrigin(request, typeof origins === "function" ? origins() : origins);
215
216
  }
216
217
  /** The path of a URL below the app base. A path outside the base stays as it is. */
217
218
  function pathBelow(base, pathname) {
@@ -262,7 +263,7 @@ async function respondViteHubPageSession(nitroApp, request) {
262
263
  why: "The page tools session accepts GET only."
263
264
  } }, { status: 405 });
264
265
  const origin = request.headers.get("origin");
265
- if (origin && origin !== forwardedRequestOrigin(request) || request.headers.get("sec-fetch-site") === "cross-site") return sessionResponse({ error: {
266
+ if (origin && origin !== applicationRequestOrigin(request) || request.headers.get("sec-fetch-site") === "cross-site") return sessionResponse({ error: {
266
267
  code: "VITEHUB_PAGE_TOOLS_CROSS_ORIGIN",
267
268
  why: "The page tools session answers the site's own pages only."
268
269
  } }, { status: 403 });
@@ -494,7 +495,7 @@ async function resolveCommentsPage(comments, event, request, path) {
494
495
  } };
495
496
  getStandardContext(event);
496
497
  const mapped = await comments.options.page({
497
- url: new URL(id, forwardedRequestOrigin(request)),
498
+ url: new URL(id, applicationRequestOrigin(request)),
498
499
  event
499
500
  });
500
501
  if (!mapped) return { subject: {
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
3
3
  // src/operations-core/testing.ts
4
4
  function checkOutboxAccount(input, user) {
5
5
  if (input.outbox && input.outbox.account !== user.id) throw Object.assign(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), { status: 401 });
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { a as CommentBuild } from "./types-BX3vH18p.js";
2
- import { n as OperationContributions } from "./operations-8hqTi0DH.js";
2
+ import { n as OperationContributions } from "./operations-DFLer1fR.js";
3
3
  import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-CCLX_eIk.js";
4
4
  import "./types-l6GOb_yc.js";
5
5
  import { n as mountedCommentsRoute } from "./page-DE71P_gQ.js";
@@ -230,6 +230,7 @@ export declare function renderCommentsPlugin(input: {
230
230
  build?: CommentBuild;
231
231
  base?: string;
232
232
  send?: boolean;
233
+ realtime?: boolean;
233
234
  }): string;
234
235
  /**
235
236
  * Comments for any Vite app, without `vite-hub`: the comment overlay on every page with `?vitehub`, threads in a
package/dist/vite.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { t as invariant } from "./invariant-CmdvZ3vp.js";
2
- import { c as validateCommentsDefinition } from "./define-BCxNaSZv.js";
3
- import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
4
- import { a as viteHubPageToolsCookie, d as viteHubPageToolsQuery, i as viteHubPageToolsAssets, n as viteHubBasePath, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript } from "./page-tools-shared-fvmJQCrP.js";
2
+ import { c as validateCommentsDefinition } from "./define-BqPcuDhf.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
4
+ import { a as viteHubPageToolsCookie, d as viteHubPageToolsQuery, i as viteHubPageToolsAssets, n as viteHubBasePath, r as viteHubPageSessionPath, s as viteHubPageToolsInlineScript } from "./page-tools-shared-BNw-aWEH.js";
5
5
  import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
6
- import { a as mountedCommentsRoute, i as commentsRoute, r as commentsRealtimeDefinition } from "./page-xzgZ6DGm.js";
6
+ import { a as commentsRealtimeDefinition, o as commentsRoute, r as commentsNoticeDefinition, s as mountedCommentsRoute } from "./page-2NzFladc.js";
7
7
  import { n as commentsTableNames, t as commentSendsTableNames } from "./table-names-BIHjuEFK.js";
8
8
  import { formatDiagnostic } from "nostics";
9
9
  import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
@@ -957,6 +957,7 @@ function renderCommentsPlugin(input) {
957
957
  const postgres = input.session?.dialect === "postgresql";
958
958
  const overlay = input.session?.overlay === false ? "false" : JSON.stringify(`${commentsRoute}/assets/overlay.js?v=${version}`);
959
959
  const segments = pillSegmentLines(input.session?.overlay === false ? [] : input.session?.pillSegments ?? []);
960
+ const realtime = input.realtime ? `realtime: () => import(${JSON.stringify(input.imports.realtime)})` : void 0;
960
961
  const siteVisitor = input.session?.overlay === false && input.imports.siteVisitor ? `siteVisitor: async (request) => (await import(${JSON.stringify(input.imports.siteVisitor)})).readConsoleSiteVisitor(request, ${JSON.stringify(input.base ?? "")}, ${input.development === true})` : void 0;
961
962
  if (input.standalone) {
962
963
  const { where, fallback, node } = input.standalone;
@@ -970,7 +971,7 @@ function renderCommentsPlugin(input) {
970
971
  "",
971
972
  `const database = () => connectDatabase(${where === void 0 ? "undefined" : JSON.stringify(where)}, { ${options.join(", ")} })`,
972
973
  "",
973
- `export default defineCommentsPlugin({ comments, database, schema: "comments", session: ${session.value}, ${session.githubLogin ? "githubLogin, " : ""}development: ${input.development === true}, overlay: ${overlay}, base: ${JSON.stringify(input.base ?? "")}${segments.value ? `, pillSegments: ${segments.value}` : ""} })`,
974
+ `export default defineCommentsPlugin({ comments, database, schema: "comments", session: ${session.value}, ${session.githubLogin ? "githubLogin, " : ""}development: ${input.development === true}, overlay: ${overlay}, base: ${JSON.stringify(input.base ?? "")}${realtime ? `, ${realtime}` : ""}${segments.value ? `, pillSegments: ${segments.value}` : ""} })`,
974
975
  ""
975
976
  ].join("\n");
976
977
  }
@@ -996,6 +997,7 @@ function renderCommentsPlugin(input) {
996
997
  ...input.session?.rateLimit ? ["rateLimit: checkRateLimit"] : [],
997
998
  ...postgres ? ["dialect: \"postgresql\"", "tables: { commentCounters: schema.vitehubCommentCounters, commentMessages: schema.vitehubCommentMessages, commentThreads: schema.vitehubCommentThreads, commentForge: schema.vitehubCommentForge }"] : [],
998
999
  ...input.send ? [`webhooks: () => import(${JSON.stringify(input.imports.webhooks)})`] : [],
1000
+ ...realtime ? [realtime] : [],
999
1001
  `development: ${input.development === true}`,
1000
1002
  `overlay: ${overlay}`,
1001
1003
  `base: ${JSON.stringify(input.base ?? "")}`,
@@ -1178,7 +1180,8 @@ function hubComments$1(options = {}) {
1178
1180
  build,
1179
1181
  base: appBase,
1180
1182
  standalone,
1181
- development
1183
+ development,
1184
+ realtime
1182
1185
  }));
1183
1186
  await addD1Binding(projectRoot, nitro.options, standalone.where);
1184
1187
  await addD1Binding(projectRoot, nitro.options, standalone.fallback);
@@ -1194,20 +1197,32 @@ function hubComments$1(options = {}) {
1194
1197
  if (!definition) return;
1195
1198
  realtime = true;
1196
1199
  const file = join(context.directory, "comments.mjs");
1200
+ const notices = join(context.directory, "comments-notices.mjs");
1197
1201
  const { repository } = await readCommentsBuild(context.projectRoot);
1198
1202
  const session = sessionWithGitHubLines(options, imports, repository, appBase);
1199
1203
  await mkdir(context.directory, { recursive: true });
1200
- await writeFile(file, [
1204
+ const importsAndDefinition = [
1201
1205
  `import { commentsRealtime } from ${JSON.stringify(imports.realtime)}`,
1202
1206
  ...definitionLines(definition, imports.runtime),
1203
1207
  ...session.imports,
1204
- "",
1205
- `export default commentsRealtime(comments, { session: ${session.value}${session.githubLogin ? ", githubLogin" : ""} })`,
1206
1208
  ""
1207
- ].join("\n"));
1209
+ ];
1210
+ const sessionOptions = `{ session: ${session.value}${session.githubLogin ? ", githubLogin" : ""} }`;
1211
+ await Promise.all([writeFile(file, [
1212
+ ...importsAndDefinition,
1213
+ `export default commentsRealtime(comments, ${sessionOptions})`,
1214
+ ""
1215
+ ].join("\n")), writeFile(notices, [
1216
+ ...importsAndDefinition,
1217
+ `export default commentsRealtime(comments, ${sessionOptions}, "notices")`,
1218
+ ""
1219
+ ].join("\n"))]);
1208
1220
  return { definitions: [{
1209
1221
  handler: file,
1210
1222
  name: commentsRealtimeDefinition
1223
+ }, {
1224
+ handler: notices,
1225
+ name: commentsNoticeDefinition
1211
1226
  }] };
1212
1227
  }
1213
1228
  },
@@ -1298,6 +1313,10 @@ function hubComments$1(options = {}) {
1298
1313
  });
1299
1314
  return;
1300
1315
  }
1316
+ config.define = {
1317
+ ...config.define,
1318
+ __VITEHUB_APP_BASE_URL__: JSON.stringify(`${base}/`)
1319
+ };
1301
1320
  await mkdir(directory, { recursive: true });
1302
1321
  const definition = discover() ?? await writeDefaultDefinition(directory, imports);
1303
1322
  const handler = join(directory, "handler.mjs");
@@ -1313,6 +1332,7 @@ function hubComments$1(options = {}) {
1313
1332
  build,
1314
1333
  base,
1315
1334
  development,
1335
+ realtime,
1316
1336
  send: !options.standalone && await readCommentsSend(definition)
1317
1337
  };
1318
1338
  await Promise.all([
@@ -1443,7 +1463,7 @@ const commentsConsoleSection$1 = {
1443
1463
  ],
1444
1464
  kind: "operation-view",
1445
1465
  link: {
1446
- label: "Open page",
1466
+ label: "Open on page",
1447
1467
  template: "{subject.id:path}?comment={n}",
1448
1468
  when: {
1449
1469
  equals: "page",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/comments",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Comments and in-place edits on live ViteHub sites, with presence and Content drafts.",
5
5
  "keywords": [
6
6
  "annotations",
@@ -106,10 +106,10 @@
106
106
  "@valibot/to-json-schema": "^1.8.0",
107
107
  "nostics": "1.4.0",
108
108
  "valibot": "^1.5.0",
109
- "@vite-hub/auth": "0.6.0",
110
- "@vite-hub/forge": "0.6.0",
111
- "@vite-hub/realtime": "0.6.0",
112
- "@vite-hub/runtime": "0.6.0",
109
+ "@vite-hub/auth": "0.7.0",
110
+ "@vite-hub/forge": "0.7.0",
111
+ "@vite-hub/realtime": "0.7.0",
112
+ "@vite-hub/runtime": "0.7.0",
113
113
  "birpc": "^4.2.0",
114
114
  "confbox": "^0.3.2",
115
115
  "h3": "^2.0.8"
@@ -117,6 +117,7 @@
117
117
  "devDependencies": {
118
118
  "@types/node": "^24.19.2",
119
119
  "@vite-hub/internal": "0.0.1",
120
+ "@vitejs/plugin-vue": "^6.0.11",
120
121
  "happy-dom": "21.0.4",
121
122
  "marked": "17.0.6",
122
123
  "modern-screenshot": "4.7.0",
@@ -128,12 +129,12 @@
128
129
  "vitest": "5.1.0",
129
130
  "vue": "3.5.46",
130
131
  "@libsql/client": "^0.18.0",
131
- "@vite-hub/database": "0.6.0",
132
+ "@vite-hub/database": "0.7.0",
132
133
  "vite": "^8.3.8",
133
134
  "drizzle-orm": "1.0.0-rc.6"
134
135
  },
135
136
  "peerDependencies": {
136
- "@vite-hub/database": "0.6.0",
137
+ "@vite-hub/database": "0.7.0",
137
138
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
138
139
  "vite": ">=8.0.0",
139
140
  "drizzle-orm": "1.0.0-rc.5 || 1.0.0-rc.6 || ^1.0.0"
@@ -151,6 +152,6 @@
151
152
  "dev": "vp pack && vp build --config overlay.vite.config.ts && vp pack --watch --no-clean",
152
153
  "typecheck": "vp run --cache -t @vite-hub/comments#build && node ../../test/package-typecheck.mjs --noEmit -p ./tsconfig.json",
153
154
  "test": "vp run --cache -t @vite-hub/comments#build && vp test",
154
- "test:browser": "vp run --cache -t @vite-hub/comments#build && node --test test/browser/overlay.browser.mjs test/browser/hosted.browser.mjs test/browser/presence.browser.mjs test/browser/outbox.browser.mjs test/browser/send.browser.mjs"
155
+ "test:browser": "vp run --cache -t @vite-hub/comments#build && node --test test/browser/overlay.browser.mjs test/browser/hosted.browser.mjs test/browser/presence.browser.mjs test/browser/outbox.browser.mjs test/browser/send.browser.mjs test/browser/controls.browser.mjs"
155
156
  }
156
157
  }