@vite-hub/comments 0.6.1 → 0.8.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 (70) hide show
  1. package/README.md +8 -12
  2. package/dist/anchor.d.ts +1 -1
  3. package/dist/{client-diagnostics-D987sEK7.js → client-diagnostics-DoXqdnBd.js} +8 -0
  4. package/dist/client-request-B1DCz3a9.js +29 -0
  5. package/dist/client.d.ts +48 -223
  6. package/dist/client.js +232 -569
  7. package/dist/database.d.ts +1 -2
  8. package/dist/database.js +1 -1
  9. package/dist/{define-C2tnAtBU.js → define-C-LUOouq.js} +1 -1
  10. package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
  11. package/dist/{errors-ByCRdInk.js → errors-DeSEHzRf.js} +1 -13
  12. package/dist/hosted/hosted-comments/frame.js +4 -1
  13. package/dist/hosted/hosted-comments/tools.js +362 -0
  14. package/dist/hosted/hosted-comments.js +1 -19
  15. package/dist/{index-D1T7RJ4R.d.ts → index-d6NsDxu9.d.ts} +4 -112
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.js +6 -20
  18. package/dist/{install-D6hXZaSN.js → install-BueV_fJY.js} +22 -780
  19. package/dist/{install-9L4ASzUC.d.ts → install-F-_O7zDr.d.ts} +5 -11
  20. package/dist/{installed-bPUnazFf.js → installed-BqQKo6WC.js} +2 -7
  21. package/dist/{database-Cguz3hZL.js → migrate-oseJAYbm.js} +2 -46
  22. package/dist/{operations-B1ALn4VS.js → operations-0llC5kKO.js} +49 -51
  23. package/dist/{operations-8hqTi0DH.d.ts → operations-DFLer1fR.d.ts} +1 -0
  24. package/dist/{operations-BkkrI8a3.d.ts → operations-jaihyWw2.d.ts} +36 -4
  25. package/dist/operations.d.ts +3 -3
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-ZBsUybIe.js +4 -0
  28. package/dist/overlay/overlay.js +68 -37
  29. package/dist/page/loader.js +36 -30
  30. package/dist/page-BgvzzsJb.d.ts +32 -0
  31. package/dist/{page-2NzFladc.js → page-CDhmXO-y.js} +24 -1
  32. package/dist/{page-tools-shared-fvmJQCrP.js → page-tools-shared-BCdvqA4S.js} +41 -6
  33. package/dist/{plugin-l4sPt5-n.js → plugin-DGUqlc3C.js} +9 -9
  34. package/dist/realtime.d.ts +10 -9
  35. package/dist/realtime.js +2 -4
  36. package/dist/{rpc-BYmbVkr8.js → rpc-kkxzQ3Qy.js} +1 -1
  37. package/dist/rpc.js +1 -1
  38. package/dist/runtime/auth.d.ts +1 -2
  39. package/dist/runtime/auth.js +1 -1
  40. package/dist/runtime/client-request-plugin.d.ts +2 -0
  41. package/dist/runtime/client-request-plugin.js +21 -0
  42. package/dist/runtime/console.js +2 -2
  43. package/dist/runtime/index.d.ts +6 -8
  44. package/dist/runtime/index.js +25 -153
  45. package/dist/{server-DvSehkPP.js → server-CAMs6viR.js} +1 -1
  46. package/dist/server.d.ts +11 -7
  47. package/dist/server.js +8 -7
  48. package/dist/{store-DvNTDNgn.d.ts → service-CMVA_Ryv.d.ts} +67 -1
  49. package/dist/{service-BIGe1Hpo.js → service-DaMq8TBw.js} +35 -33
  50. package/dist/{session-CCRLR9bf.js → session-B7GDrqsK.js} +207 -41
  51. package/dist/{session-CN4irEqf.d.ts → session-EzQqBeE8.d.ts} +2 -3
  52. package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
  53. package/dist/testing.js +1 -1
  54. package/dist/{define-B1jLSPe9.d.ts → types-qzJKgWYS.d.ts} +157 -4
  55. package/dist/vite.d.ts +3 -20
  56. package/dist/vite.js +20 -52
  57. package/package.json +9 -8
  58. package/dist/database-CPua6Q6_.d.ts +0 -573
  59. package/dist/hosted/hosted-comments/client-Czl2zu9P.js +0 -4
  60. package/dist/hosted/hosted-comments/dist-DyVmH21U.js +0 -14
  61. package/dist/hosted/hosted-comments/overlay-DpS0P-nd.js +0 -186
  62. package/dist/hosted/hosted-comments/protocol-DuB0Zhs-.js +0 -1
  63. package/dist/hosted/hosted-comments/rest-transport-CKZG_jZ4.js +0 -1
  64. package/dist/hosted/hosted-comments/tools-D8xg-kDW.js +0 -126
  65. package/dist/overlay/client-C7ftI-CB.js +0 -4
  66. package/dist/overlay/dist-yIZmvSaU.js +0 -1
  67. package/dist/page-DE71P_gQ.d.ts +0 -11
  68. package/dist/request-origin-YPzfE2eh.js +0 -48
  69. package/dist/service-IvgrI4XM.d.ts +0 -71
  70. package/dist/types-l6GOb_yc.d.ts +0 -206
@@ -1,8 +1,4 @@
1
1
  // ../internal/src/runtime/page-tools-shared.ts
2
- /**
3
- * The names and the session answer that the page tools server and the browser loader share. It has no DOM and no Node
4
- * code, so both sides import it.
5
- */
6
2
  /** The query that turns the page tools on for a page. `?vitehub=<tool id>` also opens that tool. */
7
3
  const viteHubPageToolsQuery = "vitehub";
8
4
  /**
@@ -56,11 +52,12 @@ const viteHubPageSessionPath = "/_vitehub/page/tools";
56
52
  * The URL of the loader script, below the app base. Its version query changes when the loader changes, so caches keep
57
53
  * it 5 minutes.
58
54
  */
59
- const viteHubPageToolsLoader = "/_vitehub/page/assets/loader.js?v=22";
55
+ const viteHubPageToolsLoader = "/_vitehub/page/assets/loader.js?v=28";
60
56
  /** The attribute of the script that loads the page tools. A page that has it does not get a second one. */
61
57
  const viteHubPageToolsMarker = "data-vitehub-page-tools";
62
58
  /** The bootstrap's opening tag, so the server can recognize the generated bootstrap when it replaces it. */
63
59
  const viteHubPageToolsInlineStart = `<script type="module" ${viteHubPageToolsMarker}>`;
60
+ `${JSON.stringify([viteHubPageToolsQuery, ...viteHubPageToolsLinkParams])}`;
64
61
  /**
65
62
  * The exact page tools bootstrap: an inline module script that imports `<base>/_vitehub/page/assets/loader.js` only
66
63
  * when `viteHubPageToolsWanted()` is true in the browser. Without the hint it makes no request. Vite adds it to a
@@ -96,6 +93,24 @@ function withViteHubBase(base, path) {
96
93
  function text(value) {
97
94
  return typeof value === "string" && value ? value : void 0;
98
95
  }
96
+ function readTool(value) {
97
+ if (value === null || typeof value !== "object") return void 0;
98
+ const id = text(Reflect.get(value, "id"));
99
+ const script = text(Reflect.get(value, "script"));
100
+ if (!id || !script) return void 0;
101
+ const tool = {
102
+ id,
103
+ label: text(Reflect.get(value, "label")) ?? id,
104
+ icon: text(Reflect.get(value, "icon")) ?? "",
105
+ script
106
+ };
107
+ if (Reflect.get(value, "lazy") === true) tool.lazy = true;
108
+ const hotkey = text(Reflect.get(value, "hotkey"));
109
+ if (hotkey) tool.hotkey = hotkey;
110
+ const param = text(Reflect.get(value, "param"));
111
+ if (param) tool.param = param;
112
+ return tool;
113
+ }
99
114
  /**
100
115
  * An account from untrusted input, or `undefined` when it has no name or its `signOut` is not a path of this origin. The
101
116
  * browser posts to `signOut` with the session cookie, so it never goes to another site.
@@ -117,4 +132,24 @@ function readViteHubPageAccount(value) {
117
132
  if (Reflect.get(value, "guest") === true) account.guest = true;
118
133
  return account;
119
134
  }
120
- export { viteHubPageToolsCookie as a, viteHubPageToolsInlineStart as c, viteHubPageToolsQuery as d, viteHubPageToolsWanted as f, viteHubPageToolsAssets as i, viteHubPageToolsLoader as l, viteHubBasePath as n, viteHubPageToolsHintCookie as o, withViteHubBase as p, viteHubPageSessionPath as r, viteHubPageToolsInlineScript as s, readViteHubPageAccount as t, viteHubPageToolsMarker as u };
135
+ /** The tools and the account of a session answer. Entries without an id or a script are skipped. */
136
+ function readViteHubPageSession(value) {
137
+ const tools = value !== null && typeof value === "object" ? Reflect.get(value, "tools") : void 0;
138
+ const session = { tools: Array.isArray(tools) ? tools.map(readTool).filter((tool) => Boolean(tool)) : [] };
139
+ const account = value !== null && typeof value === "object" ? readViteHubPageAccount(Reflect.get(value, "account")) : void 0;
140
+ if (account) session.account = account;
141
+ return session;
142
+ }
143
+ /**
144
+ * The `Symbol.for()` key of the session that the server hands to the loader in the page. The handoff is an inline script
145
+ * with the page's nonce that sets this global. Markup cannot set a symbol key, so a page's own content cannot forge it.
146
+ */
147
+ const viteHubPageSessionHandoffKey = "vitehub.page-tools.session";
148
+ function scriptJson(value) {
149
+ return JSON.stringify(value).replaceAll("<", "\\u003c").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029");
150
+ }
151
+ /** The inline script that hands a session to the loader, with the page's nonce when there is one. */
152
+ function viteHubPageSessionHandoffScript(handoff, nonce) {
153
+ return `<script${nonce ? ` nonce="${nonce}"` : ""}>globalThis[Symbol.for(${JSON.stringify(viteHubPageSessionHandoffKey)})]=${scriptJson(handoff)}<\/script>`;
154
+ }
155
+ export { viteHubPageSessionPath as a, viteHubPageToolsHintCookie as c, viteHubPageToolsLoader as d, viteHubPageToolsMarker as f, withViteHubBase as h, viteHubPageSessionHandoffScript as i, viteHubPageToolsInlineScript as l, viteHubPageToolsWanted as m, readViteHubPageSession as n, viteHubPageToolsAssets as o, viteHubPageToolsQuery as p, viteHubBasePath as r, viteHubPageToolsCookie as s, readViteHubPageAccount as t, viteHubPageToolsInlineStart as u };
@@ -1,9 +1,9 @@
1
- import { a as registerViteHubPageTool, i as installViteHubSiteVisitor, n as resolveCommentsPage, r as installViteHubPageTools, t as resolveCommentsIdentity } from "./session-CCRLR9bf.js";
2
- import { r as commentsRoleGrants } from "./define-C2tnAtBU.js";
3
- import { t as commentsErrorDiagnostics } from "./errors-ByCRdInk.js";
4
- import { i as installCommentsRuntime } from "./server-DvSehkPP.js";
5
- import { i as runtimeBuilds } from "./installed-bPUnazFf.js";
6
- import { n as commentsTableNames } from "./table-names-BIHjuEFK.js";
1
+ import { a as registerViteHubPageTool, i as installViteHubSiteVisitor, n as resolveCommentsPage, r as installViteHubPageTools, t as resolveCommentsIdentity } from "./session-B7GDrqsK.js";
2
+ import { r as commentsRoleGrants } from "./define-C-LUOouq.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
4
+ import { i as installCommentsRuntime } from "./server-CAMs6viR.js";
5
+ import { r as runtimeBuilds } from "./installed-BqQKo6WC.js";
6
+ import { t as commentsTableNames } from "./table-names-DUmWROM4.js";
7
7
  import { installRequestStandardContext } from "@vite-hub/runtime/internal/h3";
8
8
  import { configuredPublicOrigins } from "@vite-hub/runtime/internal/public-url";
9
9
  // ../internal/src/runtime/user-data.ts
@@ -38,7 +38,7 @@ function defineCommentsPlugin(options) {
38
38
  warned = true;
39
39
  throw Object.assign(commentsErrorDiagnostics.COMMENTS_R0010(), { status: 503 });
40
40
  }
41
- const { installComments } = await import("./install-D6hXZaSN.js").then((n) => n.n);
41
+ const { installComments } = await import("./install-BueV_fJY.js").then((n) => n.n);
42
42
  return installComments(options.comments, {
43
43
  database,
44
44
  development: options.development === true,
@@ -48,7 +48,6 @@ function defineCommentsPlugin(options) {
48
48
  ...options.users ? { users: options.users } : {},
49
49
  ...options.attachments ? { attachments: options.attachments } : {},
50
50
  ...options.rateLimit ? { rateLimit: options.rateLimit } : {},
51
- ...options.webhooks ? { webhooks: options.webhooks } : {},
52
51
  ...options.realtime ? { realtime: options.realtime } : {}
53
52
  });
54
53
  })().catch((error) => {
@@ -97,7 +96,8 @@ function defineCommentsPlugin(options) {
97
96
  });
98
97
  installViteHubPageTools(nitroApp, {
99
98
  base: options.base,
100
- origins: options.development === true ? [] : configuredPublicOrigins()
99
+ origins: options.development === true ? [] : configuredPublicOrigins,
100
+ sessionHandoff: options.comments.options.pageToolsSessionHandoff === true
101
101
  });
102
102
  };
103
103
  }
@@ -1,7 +1,8 @@
1
1
  import { T as CommentThread } from "./types-BX3vH18p.js";
2
- import { t as Comments } from "./index-D1T7RJ4R.js";
3
- import { t as CommentsSessionOptions } from "./session-CN4irEqf.js";
4
- import "./types-l6GOb_yc.js";
2
+ import { n as commentsChangeNotice } from "./page-BgvzzsJb.js";
3
+ import { t as Comments } from "./index-d6NsDxu9.js";
4
+ import { t as CommentsSessionOptions } from "./session-EzQqBeE8.js";
5
+ import "./types-qzJKgWYS.js";
5
6
  import { RealtimeDefinition } from "@vite-hub/realtime";
6
7
  /**
7
8
  * The Realtime Definition of the page presence rooms: who is on a page and where their cursor is. Rooms hold no
@@ -9,10 +10,10 @@ import { RealtimeDefinition } from "@vite-hub/realtime";
9
10
  * Guests name themselves in the browser. ViteHub adds it as the `comments` definition when the host has a room
10
11
  * authority.
11
12
  */
12
- export declare function commentsRealtime(comments: Comments, options?: CommentsSessionOptions, purpose?: "presence" | "notices"): RealtimeDefinition;
13
- /** The notice that tells the open pages of a thread to load their threads again. */
14
- export declare const commentsChangeNotice: {
15
- readonly type: "comments";
16
- };
13
+ export declare function commentsRealtime(comments: Comments, options?: CommentsSessionOptions, purpose?: "presence" | "notices"): Extract<RealtimeDefinition, {
14
+ document: false;
15
+ identify: NonNullable<RealtimeDefinition["identify"]>;
16
+ }>;
17
17
  /** Tells the browsers on the page of a thread that it changed, so they load their threads again. It never throws. */
18
- export declare function notifyCommentsChange(thread: Pick<CommentThread, "subject">): Promise<void>;
18
+ export declare function notifyCommentsChange(thread: Pick<CommentThread, "subject">): Promise<void>;
19
+ export { commentsChangeNotice };
package/dist/realtime.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { i as text } from "./identity-CT7-UGmS.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-CCRLR9bf.js";
2
+ import { i as commentsNoticeDefinition, n as commentRoom, p as normalizeCommentPage, r as commentsChangeNotice, t as commentNoticeRoom } from "./page-CDhmXO-y.js";
3
+ import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-B7GDrqsK.js";
4
4
  // src/realtime.ts
5
5
  function toRealtimeUser(user) {
6
6
  const result = { id: user.id };
@@ -45,8 +45,6 @@ function commentsRealtime(comments, options = {}, purpose = "presence") {
45
45
  ...purpose === "notices" ? { awareness: false } : {}
46
46
  };
47
47
  }
48
- /** The notice that tells the open pages of a thread to load their threads again. */
49
- const commentsChangeNotice = { type: "comments" };
50
48
  /** Tells the browsers on the page of a thread that it changed, so they load their threads again. It never throws. */
51
49
  async function notifyCommentsChange(thread) {
52
50
  await (await import("@vite-hub/realtime/server").catch(() => void 0))?.notifyRealtimeRoom(commentsNoticeDefinition, commentNoticeRoom(thread.subject), commentsChangeNotice);
@@ -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-D987sEK7.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-BYmbVkr8.js";
1
+ export { t as createRpcTransport } from "./rpc-kkxzQ3Qy.js";
@@ -1,5 +1,4 @@
1
- import { d as CommentsPeople, g as CommentsUser } from "../define-B1jLSPe9.js";
2
- import { f as CommentsRequestEvent } from "../types-l6GOb_yc.js";
1
+ import { T as CommentsPeople, j as CommentsUser, s as CommentsRequestEvent } from "../types-qzJKgWYS.js";
3
2
  /** The ViteHub Auth user of a request, or null. Generated Comments files pass it as `session` when the app has Auth. */
4
3
  export declare function commentsAuthSession(event: CommentsRequestEvent): Promise<CommentsUser | null>;
5
4
  /** The users of ViteHub Auth, for `@` suggestions. Generated Comments files pass it as `users` when the app has Auth. */
@@ -1,4 +1,4 @@
1
- import { n as createAuthUsers } from "../server-DvSehkPP.js";
1
+ import { n as createAuthUsers } from "../server-CAMs6viR.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");
@@ -0,0 +1,2 @@
1
+ /** Keeps each request that the Nitro app serves for `clientRequest()`. Auth and Comments each ship it, so it wraps `fetch` once. */
2
+ export default function clientRequestPlugin(nitroApp: unknown): void;
@@ -0,0 +1,21 @@
1
+ import { t as isRecord } from "../object-CAK6UYR5.js";
2
+ import { n as runWithClientRequest } from "../client-request-B1DCz3a9.js";
3
+ // ../internal/src/runtime/client-request-plugin.ts
4
+ const installed = Symbol.for("vitehub.client-request.installed");
5
+ function isRequest(value) {
6
+ return isRecord(value) && typeof value.url === "string" && value.headers instanceof Headers;
7
+ }
8
+ /** Keeps each request that the Nitro app serves for `clientRequest()`. Auth and Comments each ship it, so it wraps `fetch` once. */
9
+ function clientRequestPlugin(nitroApp) {
10
+ if (!isRecord(nitroApp)) return;
11
+ const h3 = nitroApp.h3;
12
+ const owner = isRecord(h3) && h3.fetch instanceof Function ? h3 : nitroApp;
13
+ const fetch = owner.fetch;
14
+ if (!(fetch instanceof Function) || owner[installed]) return;
15
+ owner[installed] = true;
16
+ owner.fetch = (request, ...rest) => {
17
+ const call = () => Reflect.apply(fetch, owner, [request, ...rest]);
18
+ return isRequest(request) ? runWithClientRequest(request, call) : call();
19
+ };
20
+ }
21
+ export { clientRequestPlugin as default };
@@ -1,6 +1,6 @@
1
1
  import { t as describeCommentContext } from "../context-DbkBjITZ.js";
2
- import { i as commentsPageScope } from "../page-2NzFladc.js";
3
- import { n as installedComments } from "../plugin-l4sPt5-n.js";
2
+ import { a as commentsPageScope } from "../page-CDhmXO-y.js";
3
+ import { n as installedComments } from "../plugin-DGUqlc3C.js";
4
4
  // src/runtime/console.ts
5
5
  function excerpt(text) {
6
6
  const line = text.replace(/\s+/g, " ").trim();
@@ -1,10 +1,9 @@
1
1
  import { s as CommentContext } from "../types-BX3vH18p.js";
2
- import { g as CommentsUser } from "../define-B1jLSPe9.js";
3
- import { t as Comments } from "../index-D1T7RJ4R.js";
4
- import { f as CommentsRequestEvent } from "../types-l6GOb_yc.js";
5
- import { t as CommentsSessionOptions } from "../session-CN4irEqf.js";
6
- import { t as InstallCommentsOptions } from "../install-9L4ASzUC.js";
7
- import { t as CommentsDatabase } from "../store-DvNTDNgn.js";
2
+ import { t as Comments } from "../index-d6NsDxu9.js";
3
+ import { j as CommentsUser, s as CommentsRequestEvent } from "../types-qzJKgWYS.js";
4
+ import { t as CommentsSessionOptions } from "../session-EzQqBeE8.js";
5
+ import { t as InstallCommentsOptions } from "../install-F-_O7zDr.js";
6
+ import { o as CommentsDatabase } from "../service-CMVA_Ryv.js";
8
7
  /**
9
8
  * A person that Site access in the ViteHub Console signed in to the app: a Console member, or a guest, with their roles,
10
9
  * such as `console` and `comments-write`. The Console signs them in a Site access token, which the app keeps in its
@@ -23,6 +22,7 @@ interface ViteHubSiteVisitor {
23
22
  id: string;
24
23
  teamId: string;
25
24
  url: string;
25
+ name?: string;
26
26
  };
27
27
  resolve: boolean;
28
28
  };
@@ -161,8 +161,6 @@ interface CommentsPluginOptions extends CommentsSessionOptions {
161
161
  /** The tables of a Postgres Database. Default: the SQLite tables. */
162
162
  tables?: InstallCommentsOptions["tables"];
163
163
  dialect?: InstallCommentsOptions["dialect"];
164
- /** Loads `@vite-hub/webhooks`, when `defineComments({ send })` is on. */
165
- webhooks?: InstallCommentsOptions["webhooks"];
166
164
  /** Loads `@vite-hub/comments/realtime`, when the app has the page presence rooms. */
167
165
  realtime?: InstallCommentsOptions["realtime"];
168
166
  /** Install more segments of the pill, such as the **Console** segment of `vite-hub`. Only with the overlay on. */
@@ -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 { n as resolveCommentsPage, o as viteHubPageSessionHandler, s as applicationRequestOrigin, t as resolveCommentsIdentity } from "../session-B7GDrqsK.js";
3
3
  import "../client-files-lC6X7XyS.js";
4
- import { t as commentsErrors } from "../errors-C0VwRHiy.js";
4
+ import { t as commentsErrors } from "../errors-C5utwZ5H.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-bPUnazFf.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-B1ALn4VS.js";
8
- import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-C2tnAtBU.js";
9
- import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-BIGe1Hpo.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-CCRLR9bf.js";
12
- import { n as installedComments, t as defineCommentsPlugin } from "../plugin-l4sPt5-n.js";
6
+ import { i as runtimeOf, n as resolveCommentsRuntime } from "../installed-BqQKo6WC.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-0llC5kKO.js";
8
+ import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-C-LUOouq.js";
9
+ import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-DaMq8TBw.js";
10
+ import { a as commentsPageScope, p as normalizeCommentPage, s as commentsRoute } from "../page-CDhmXO-y.js";
11
+ import { n as installedComments, t as defineCommentsPlugin } from "../plugin-DGUqlc3C.js";
13
12
  import { t as invariant } from "../invariant-CmdvZ3vp.js";
14
- import { t as commentsErrorDiagnostics } from "../errors-ByCRdInk.js";
13
+ import { t as commentsErrorDiagnostics } from "../errors-DeSEHzRf.js";
14
+ import { t as clientRequest } from "../client-request-B1DCz3a9.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";
@@ -55,14 +55,8 @@ const fieldBody = v.object({
55
55
  function status(code) {
56
56
  switch (code) {
57
57
  case "COMMENTS_NOT_FOUND":
58
- case "COMMENTS_CONTENT_MISSING":
59
- case "COMMENTS_SEND_OFF": return 404;
60
- case "COMMENTS_SEND_GRANT_INVALID": return 401;
61
- case "COMMENTS_SEND_CODE_EXPIRED": return 410;
62
- case "COMMENTS_SEND_CODE_USED": return 409;
63
- case "COMMENTS_SEND_CODE_REFUSED": return 422;
58
+ case "COMMENTS_CONTENT_MISSING": return 404;
64
59
  case "COMMENTS_FORBIDDEN":
65
- case "COMMENTS_SEND_INSECURE":
66
60
  case "COMMENTS_POLICY_MISSING":
67
61
  case "COMMENTS_FIELD_FORBIDDEN": return 403;
68
62
  case "COMMENTS_RESOLVED":
@@ -146,7 +140,7 @@ function respond([error, data]) {
146
140
  }
147
141
  function sameOrigin(request) {
148
142
  const origin = request.headers.get("origin");
149
- return !origin || origin === forwardedRequestOrigin(request);
143
+ return !origin || origin === applicationRequestOrigin(request);
150
144
  }
151
145
  function readPath(data, path) {
152
146
  let current = data;
@@ -282,7 +276,6 @@ function createCommentsHandler(options) {
282
276
  url: `${route}/auth/github`
283
277
  } : void 0;
284
278
  const signOut = user && user.github && github ? `${route}/auth/sign-out` : void 0;
285
- const send = Boolean(comments.options.send && user && !user.guest && comment && await commentSendOf(comments));
286
279
  const agent = identity.commentsAgent && read ? {
287
280
  ...identity.commentsAgent,
288
281
  mcp: `${configuredConsoleOrigin()}/mcp/account`
@@ -303,7 +296,6 @@ function createCommentsHandler(options) {
303
296
  ...options.attachments === false ? { attachments: false } : {},
304
297
  ...options.presence === false ? { presence: false } : {},
305
298
  content: Boolean(options.content),
306
- ...send ? { send: true } : {},
307
299
  ...agent ? { agent } : {},
308
300
  ...repository ? { repository } : {},
309
301
  ...subject ? { subject } : {},
@@ -391,7 +383,7 @@ function createCommentsHandler(options) {
391
383
  * the origin and the path, and gives the revision of the page subject.
392
384
  */
393
385
  async function checkContext(request, context, subject) {
394
- const origin = forwardedRequestOrigin(request);
386
+ const origin = applicationRequestOrigin(request);
395
387
  let submitted;
396
388
  try {
397
389
  submitted = new URL(context.url);
@@ -501,77 +493,6 @@ function createCommentsHandler(options) {
501
493
  const env = request["~standard"].runtime?.cloudflare?.env;
502
494
  return env ? await runWithActiveCloudflareEnv(env, () => handle(request)) : await handle(request);
503
495
  } };
504
- async function sendRoute(request, url, parts, pageOf) {
505
- const service = await commentSendOf(comments);
506
- if (!service) return failure$1(commentsErrors.COMMENTS_SEND_OFF());
507
- const method = request.method;
508
- const [, action, code] = parts;
509
- if (method === "POST" && action === "pair" && !code) {
510
- const [error, paired] = await service.pair(await readJson(request), forwardedRequestOrigin(request));
511
- return error ? json({
512
- error,
513
- reason: {
514
- COMMENTS_SEND_CODE_EXPIRED: "expired",
515
- COMMENTS_SEND_CODE_USED: "used",
516
- COMMENTS_SEND_CODE_REFUSED: "refused",
517
- COMMENTS_SEND_INSECURE: "insecure"
518
- }[error.code] ?? "invalid"
519
- }, { status: status(error.code) }) : json({ data: paired });
520
- }
521
- if (method === "GET" && action && action.startsWith("send_") && !code) {
522
- const token = /^Bearer\s+(\S+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
523
- if (!token) return failure$1(commentsErrors.COMMENTS_SEND_GRANT_INVALID());
524
- return respond(await service.read(decodeURIComponent(action), token));
525
- }
526
- const { user, gate } = await identityOf(request);
527
- const pathname = url.pathname;
528
- const caller = async () => {
529
- const subject = (await pageOf())?.subject;
530
- if (!subject) return void 0;
531
- return {
532
- user,
533
- gate,
534
- subject,
535
- page: normalizeCommentPage(url.searchParams.get("page") ?? "/"),
536
- origin: forwardedRequestOrigin(request),
537
- route: pathname.slice(0, pathname.indexOf(commentsRoute) + commentsRoute.length)
538
- };
539
- };
540
- if (action === "pair" && code && !parts[3]) {
541
- const who = {
542
- user,
543
- gate,
544
- subject: {
545
- kind: "page",
546
- id: "/"
547
- },
548
- page: "/",
549
- origin: "",
550
- route: ""
551
- };
552
- if (method === "GET") return json({ data: await service.check(who, decodeURIComponent(code)) });
553
- if (method === "DELETE") {
554
- await service.cancel(who, decodeURIComponent(code));
555
- return json({ data: null });
556
- }
557
- }
558
- const who = await caller();
559
- if (!who) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "page: Give the page that Send is on." }));
560
- if (method === "GET" && action === "status" && !code) return json({ data: await service.status(who) });
561
- if (method === "POST" && action === "start" && !code) return respond(await service.start(who));
562
- if (method === "POST" && action === "allow" && !code) {
563
- const body = await readJson(request);
564
- const given = typeof body === "object" && body !== null ? Reflect.get(body, "code") : void 0;
565
- if (typeof given !== "string" || !given) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "code: Send the setup code that the agent used." }));
566
- const selection = typeof body === "object" && body !== null ? Reflect.get(body, "selection") : void 0;
567
- return respond(await service.allow(who, given, typeof selection === "string" ? selection : ""));
568
- }
569
- if (method === "POST" && !action) return respond(await service.send(who));
570
- return json({ error: {
571
- code: "COMMENTS_NOT_FOUND",
572
- why: `No Comments route ${method} ${url.pathname.slice(url.pathname.indexOf(commentsRoute) + commentsRoute.length)}.`
573
- } }, { status: 404 });
574
- }
575
496
  async function route(request) {
576
497
  const url = new URL(request.url);
577
498
  const path = url.pathname.slice(url.pathname.indexOf("/_vitehub/comments") + 18).replace(/\/+$/, "") || "/";
@@ -585,11 +506,10 @@ function createCommentsHandler(options) {
585
506
  id: subjectId
586
507
  } } : void 0;
587
508
  const subjectOf = async () => (await pageOf())?.subject;
588
- if (method !== "GET" && !(method === "POST" && path === "/send/pair") && !sameOrigin(request)) return json({ error: {
509
+ if (method !== "GET" && !sameOrigin(request)) return json({ error: {
589
510
  code: "COMMENTS_FORBIDDEN",
590
511
  why: "Comments requests must come from the site's own pages."
591
512
  } }, { status: 403 });
592
- if (parts[0] === "send") return await sendRoute(request, url, parts, pageOf);
593
513
  if (method === "GET" && path === "/session") {
594
514
  const current = await pageOf();
595
515
  return await session(request, current?.subject, current?.revision);
@@ -852,7 +772,12 @@ function commentsMcpTools(comments, options = {}) {
852
772
  })
853
773
  };
854
774
  }
855
- const tools = [
775
+ async function finishWrite(context) {
776
+ const standard = context.event?.["~standard"];
777
+ if (standard?.waitUntil) standard.waitUntil(comments.flush());
778
+ else await comments.flush();
779
+ }
780
+ return [
856
781
  {
857
782
  name: "comments_list_threads",
858
783
  title: "List ViteHub Comments threads",
@@ -990,11 +915,7 @@ function commentsMcpTools(comments, options = {}) {
990
915
  body: {
991
916
  type: "string",
992
917
  description: "Markdown, at most 10,000 characters."
993
- },
994
- ...comments.options.send ? { send: {
995
- type: "string",
996
- description: "The send ID from comments_get_send when answering an ask."
997
- } } : {}
918
+ }
998
919
  },
999
920
  required: ["id", "body"],
1000
921
  additionalProperties: false
@@ -1006,26 +927,13 @@ function commentsMcpTools(comments, options = {}) {
1006
927
  const { thread, grant } = found;
1007
928
  const author = identity.user ? authorOf(identity.user) : guestFor(context);
1008
929
  if (!author) return forbidden("write");
1009
- const send = text(input.send);
1010
- if (send) {
1011
- const service = await commentSendOf(comments);
1012
- const opened = identity.user && !identity.user.guest && await service?.readOwn(identity.user, send, {
1013
- gate: identity.gate,
1014
- console: admitted
1015
- });
1016
- if (!opened || !opened.threads.some((entry) => entry.id === thread.id && entry.role === "ask")) return forbidden("write");
1017
- }
1018
930
  spend(grant, "write", thread.id);
1019
931
  const [error, message] = await comments.reply(thread.id, {
1020
932
  body: text(input.body) ?? "",
1021
- author,
1022
- ...send ? { actor: {
1023
- id: "comments-mcp",
1024
- name: "Comments agent"
1025
- } } : {}
933
+ author
1026
934
  });
1027
935
  if (error) return failure(error.why);
1028
- await comments.flush();
936
+ await finishWrite(context);
1029
937
  return {
1030
938
  text: `Replied to thread ${thread.id}.`,
1031
939
  structured: { message: { ...message } }
@@ -1064,7 +972,7 @@ function commentsMcpTools(comments, options = {}) {
1064
972
  };
1065
973
  const [error, updated] = input.resolved === false ? await comments.reopen(thread.id) : await comments.resolve(thread.id, { by: author });
1066
974
  if (error) return failure(error.why);
1067
- await comments.flush();
975
+ await finishWrite(context);
1068
976
  return {
1069
977
  text: `Thread ${updated.id} is ${updated.status}.`,
1070
978
  structured: { thread: { ...commentThreadSummary(updated) } }
@@ -1072,42 +980,6 @@ function commentsMcpTools(comments, options = {}) {
1072
980
  }
1073
981
  }
1074
982
  ];
1075
- if (comments.options.send) tools.push({
1076
- name: "comments_get_send",
1077
- title: "Read a ViteHub Comments send",
1078
- description: "ViteHub Comments: read the threads that the signed-in user sent to their agent with Send in the comment pill. Each thread says whether it is an ask, the user's own question, or a quote, what someone else said. Without an id, it reads the user's latest send that no agent read yet. Answer each ask with comments_reply, passing the send ID as `send`.",
1079
- section: "comments",
1080
- annotations: { readOnlyHint: true },
1081
- inputSchema: {
1082
- type: "object",
1083
- properties: { id: {
1084
- type: "string",
1085
- description: "The send id, such as send_… from the delivery. Default: the latest unread send."
1086
- } },
1087
- additionalProperties: false
1088
- },
1089
- async call(input, context) {
1090
- const { user, gate } = await identityFor(context);
1091
- if (!user || user.guest) return forbidden("read");
1092
- const service = await commentSendOf(comments);
1093
- if (!service) return failure(`${commentsErrors.COMMENTS_SEND_OFF().why} ${commentsErrors.COMMENTS_SEND_OFF().fix}`);
1094
- const id = text(input.id);
1095
- const opened = await service.readOwn(user, id, {
1096
- gate,
1097
- console: admitted
1098
- });
1099
- if (!opened) return failure(id ? `No send ${id} of this user.` : "This user has no send that an agent did not read yet.");
1100
- const { send, threads } = opened;
1101
- return {
1102
- text: [`Send ${send.id} from ${send.page}, ${new Date(send.createdAt).toISOString()}: ${threads.length} ${threads.length === 1 ? "thread" : "threads"}.`, ...threads.flatMap((thread) => ["", `${thread.role === "ask" ? "Ask" : "Quote"}: ${describeCommentThread(thread)}`])].join("\n"),
1103
- structured: {
1104
- send: { ...send },
1105
- threads: threads.map((thread) => ({ ...thread }))
1106
- }
1107
- };
1108
- }
1109
- });
1110
- return tools;
1111
983
  }
1112
984
  // ../internal/src/runtime/mcp-server.ts
1113
985
  /** The MCP result of a `ViteHubMcpTool` call: a text block, then one image block for each image. */
@@ -1184,7 +1056,7 @@ function createCommentsGitHubLogin(options = {}) {
1184
1056
  const clientId = serverEnv(githubLoginEnv.clientId);
1185
1057
  const clientSecret = serverEnv(githubLoginEnv.clientSecret);
1186
1058
  const secret = sessionSecret();
1187
- const origin = forwardedRequestOrigin(request);
1059
+ const origin = applicationRequestOrigin(clientRequest(request));
1188
1060
  const key = [
1189
1061
  origin,
1190
1062
  clientId,
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-ByCRdInk.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.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,10 @@
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-IvgrI4XM.js";
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-BkkrI8a3.js";
1
+ import { F as validateCommentsDefinition, T as CommentsPeople } from "./types-qzJKgWYS.js";
2
+ import { a as maximumCommentBodyLength, c as CommentsTables, i as CommentsRuntime, l as createCommentsStore, n as CommentsAttachmentStore, o as CommentsDatabase, r as CommentsForgeHooks, s as CommentsStore } from "./service-CMVA_Ryv.js";
3
+ import { D as CommentUser } from "./types-BX3vH18p.js";
4
+ import { a as commentInputSchemas, i as commentAnchorSchema, n as CommentsCaller, o as commentsOperations, r as commentActions, t as CommentThreadsPage } from "./operations-jaihyWw2.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-9L4ASzUC.js";
6
+ import { n as installComments, t as InstallCommentsOptions } from "./install-F-_O7zDr.js";
7
+ import { a as hostedCommentsEndedNotice, i as hostedCommentsChangeNotice, o as hostedCommentsNoticeDefinition, r as hostedCommentNoticeRoom } from "./page-BgvzzsJb.js";
7
8
  /** Where mentions find people. The same shape as `defineComments({ people })`. */
8
9
  export type CommentsUsers = CommentsPeople;
9
10
  /**
@@ -15,5 +16,8 @@ export declare function installCommentsRuntime(runtime: CommentsRuntime | (() =>
15
16
  export declare function commentsRuntime(): Promise<CommentsRuntime>;
16
17
  export declare function hasCommentsRuntime(): boolean;
17
18
  /** People from a Better Auth instance, through its internal adapter. The generated Nitro plugin passes it when the app has Auth. */
18
- export declare function createAuthUsers(getAuth: () => object | Promise<object>): CommentsPeople;
19
- export { type CommentsAttachmentStore, CommentsCaller, type CommentsDatabase, type CommentsForgeHooks, type CommentsRuntime, type CommentsStore, type CommentsTables, type InstallCommentsOptions, RpcTransportOptions, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, createCommentsStore, createRpcTransport, installComments, maximumCommentBodyLength, validateCommentsDefinition };
19
+ export declare function createAuthUsers(getAuth: () => object | Promise<object>): {
20
+ byIds(ids: readonly string[]): Promise<CommentUser[]>;
21
+ search(query: string, limit: number): Promise<CommentUser[]>;
22
+ };
23
+ export { CommentThreadsPage, type CommentsAttachmentStore, CommentsCaller, type CommentsDatabase, type CommentsForgeHooks, type CommentsRuntime, type CommentsStore, type CommentsTables, type InstallCommentsOptions, RpcTransportOptions, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, createCommentsStore, createRpcTransport, hostedCommentNoticeRoom, hostedCommentsChangeNotice, hostedCommentsEndedNotice, hostedCommentsNoticeDefinition, installComments, maximumCommentBodyLength, validateCommentsDefinition };
package/dist/server.js CHANGED
@@ -1,7 +1,8 @@
1
- import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-DvSehkPP.js";
2
- import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-B1ALn4VS.js";
3
- import { t as createRpcTransport } from "./rpc-BYmbVkr8.js";
4
- import { f as maximumCommentBodyLength } from "./service-BIGe1Hpo.js";
5
- import { r as createCommentsStore, t as installComments } from "./install-D6hXZaSN.js";
6
- import { c as validateCommentsDefinition } from "./define-C2tnAtBU.js";
7
- export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };
1
+ import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-CAMs6viR.js";
2
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-0llC5kKO.js";
3
+ import { t as createRpcTransport } from "./rpc-kkxzQ3Qy.js";
4
+ import { r as createCommentsStore, t as installComments } from "./install-BueV_fJY.js";
5
+ import { f as maximumCommentBodyLength } from "./service-DaMq8TBw.js";
6
+ import { c as validateCommentsDefinition } from "./define-C-LUOouq.js";
7
+ import { c as hostedCommentNoticeRoom, d as hostedCommentsNoticeDefinition, l as hostedCommentsChangeNotice, u as hostedCommentsEndedNotice } from "./page-CDhmXO-y.js";
8
+ export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, hostedCommentNoticeRoom, hostedCommentsChangeNotice, hostedCommentsEndedNotice, hostedCommentsNoticeDefinition, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };