@vite-hub/comments 0.7.0 → 0.9.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 +4 -10
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/anchor.js +0 -1
  4. package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
  5. package/dist/client-request-B1DCz3a9.js +29 -0
  6. package/dist/client.d.ts +21 -241
  7. package/dist/client.js +4 -425
  8. package/dist/database.d.ts +1 -2
  9. package/dist/database.js +1 -1
  10. package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
  11. package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
  12. package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
  13. package/dist/hosted/hosted-comments/frame.js +4 -1
  14. package/dist/hosted/hosted-comments/tools.js +71 -77
  15. package/dist/hosted/hosted-comments.js +1 -1
  16. package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
  17. package/dist/index.d.ts +5 -6
  18. package/dist/index.js +6 -23
  19. package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
  20. package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
  21. package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
  22. package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
  23. package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
  24. package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
  25. package/dist/operations.d.ts +3 -3
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-BszZKIf8.js +4 -0
  28. package/dist/overlay/overlay.js +50 -43
  29. package/dist/page/loader.js +37 -30
  30. package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
  31. package/dist/page-DRM1j84-.d.ts +32 -0
  32. package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
  33. package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
  34. package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
  35. package/dist/realtime.d.ts +7 -9
  36. package/dist/realtime.js +2 -4
  37. package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
  38. package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
  39. package/dist/rpc.d.ts +1 -1
  40. package/dist/rpc.js +1 -1
  41. package/dist/runtime/auth.d.ts +1 -2
  42. package/dist/runtime/auth.js +1 -1
  43. package/dist/runtime/client-request-plugin.d.ts +2 -0
  44. package/dist/runtime/client-request-plugin.js +21 -0
  45. package/dist/runtime/console.js +2 -2
  46. package/dist/runtime/index.d.ts +6 -9
  47. package/dist/runtime/index.js +25 -175
  48. package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
  49. package/dist/server.d.ts +12 -8
  50. package/dist/server.js +8 -7
  51. package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
  52. package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
  53. package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
  54. package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
  55. package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
  56. package/dist/testing.d.ts +1 -1
  57. package/dist/testing.js +1 -2
  58. package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
  59. package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
  60. package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
  61. package/dist/vite.d.ts +3 -20
  62. package/dist/vite.js +15 -82
  63. package/package.json +8 -8
  64. package/dist/database-CPua6Q6_.d.ts +0 -573
  65. package/dist/overlay/client-CrnKCZXc.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-B-CPVAVk.js +0 -53
  69. package/dist/service-IvgrI4XM.d.ts +0 -71
  70. package/dist/types-l6GOb_yc.d.ts +0 -206
@@ -52,7 +52,7 @@ const viteHubPageSessionPath = "/_vitehub/page/tools";
52
52
  * The URL of the loader script, below the app base. Its version query changes when the loader changes, so caches keep
53
53
  * it 5 minutes.
54
54
  */
55
- const viteHubPageToolsLoader = "/_vitehub/page/assets/loader.js?v=25";
55
+ const viteHubPageToolsLoader = "/_vitehub/page/assets/loader.js?v=28";
56
56
  /** The attribute of the script that loads the page tools. A page that has it does not get a second one. */
57
57
  const viteHubPageToolsMarker = "data-vitehub-page-tools";
58
58
  /** The bootstrap's opening tag, so the server can recognize the generated bootstrap when it replaces it. */
@@ -93,6 +93,24 @@ function withViteHubBase(base, path) {
93
93
  function text(value) {
94
94
  return typeof value === "string" && value ? value : void 0;
95
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
+ }
96
114
  /**
97
115
  * An account from untrusted input, or `undefined` when it has no name or its `signOut` is not a path of this origin. The
98
116
  * browser posts to `signOut` with the session cookie, so it never goes to another site.
@@ -114,4 +132,24 @@ function readViteHubPageAccount(value) {
114
132
  if (Reflect.get(value, "guest") === true) account.guest = true;
115
133
  return account;
116
134
  }
117
- 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,7 +1,3 @@
1
- /**
2
- * An app path: one slash, then no second slash or backslash (`//host` and `/\host` leave the site), no whitespace,
3
- * and no `?` or `#`, which a link adds itself.
4
- */
5
1
  const pagePath = /^\/(?![/\\])[^\s\\?#]*$/;
6
2
  function isPagePath(value) {
7
3
  return value.length <= 500 && pagePath.test(value) && !new URL(value, "https://comments.invalid").pathname.startsWith("//");
@@ -1,9 +1,9 @@
1
- import { a as registerViteHubPageTool, i as installViteHubSiteVisitor, n as resolveCommentsPage, r as installViteHubPageTools, t as resolveCommentsIdentity } from "./session-DGdFKWDB.js";
2
- import { r as commentsRoleGrants } from "./define-BqPcuDhf.js";
3
- import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
4
- import { i as installCommentsRuntime } from "./server-8o9u8leM.js";
5
- import { i as runtimeBuilds } from "./installed-wUYjqk_k.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-1SI3_wLJ.js";
2
+ import { r as commentsRoleGrants } from "./define-hs9Z38io.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-CqBWFmU7.js").then((n) => n.n);
41
+ const { installComments } = await import("./install--HecUN5c.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
- 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";
1
+ import { T as CommentThread } from "./types-BmzTyGt-.js";
2
+ import { n as commentsChangeNotice } from "./page-DRM1j84-.js";
3
+ import { t as Comments } from "./index-CbXek64X.js";
4
+ import { t as CommentsSessionOptions } from "./session-CK3Rnjto.js";
5
+ import "./types-VSVs4jIw.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
@@ -13,9 +14,6 @@ export declare function commentsRealtime(comments: Comments, options?: CommentsS
13
14
  document: false;
14
15
  identify: NonNullable<RealtimeDefinition["identify"]>;
15
16
  }>;
16
- /** The notice that tells the open pages of a thread to load their threads again. */
17
- export declare const commentsChangeNotice: {
18
- readonly type: "comments";
19
- };
20
17
  /** Tells the browsers on the page of a thread that it changed, so they load their threads again. It never throws. */
21
- 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-DGdFKWDB.js";
2
+ import { i as commentsNoticeDefinition, n as commentRoom, p as normalizeCommentPage, r as commentsChangeNotice, t as commentNoticeRoom } from "./page-CJz1K67L.js";
3
+ import { n as resolveCommentsPage, t as resolveCommentsIdentity } from "./session-1SI3_wLJ.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,6 +1,6 @@
1
1
  import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
2
2
  import { i as commentsUnansweredError, t as commentsAnswerError } from "./client-diagnostics-DoXqdnBd.js";
3
- import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf } from "./client-files-lC6X7XyS.js";
3
+ import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf } from "./client-files-CMPJEd21.js";
4
4
  import { createBirpc } from "birpc";
5
5
  // ../internal/src/operation-rpc.ts
6
6
  /** Path of the operation RPC under the app. Dev servers and deployed apps serve it the same way, one birpc call per POST. */
@@ -1,4 +1,4 @@
1
- import { k as CommentsTransport } from "./types-BX3vH18p.js";
1
+ import { k as CommentsTransport } from "./types-BmzTyGt-.js";
2
2
  interface RpcTransportOptions {
3
3
  /** The app origin and mount, such as `https://app.example.com` or `/portal`. Defaults to the page origin. */
4
4
  base?: string;
package/dist/rpc.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-D-eqtyfh.js";
1
+ import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-DZB3yU0z.js";
2
2
  export { RpcTransportOptions, createRpcTransport };
package/dist/rpc.js CHANGED
@@ -1 +1 @@
1
- export { t as createRpcTransport } from "./rpc-kkxzQ3Qy.js";
1
+ export { t as createRpcTransport } from "./rpc-51X1TWKb.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-VSVs4jIw.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-8o9u8leM.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-ChOHe7vq.js";
2
+ import { a as commentsPageScope } from "../page-CJz1K67L.js";
3
+ import { n as installedComments } from "../plugin-DczA2K-y.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
- 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";
1
+ import { s as CommentContext } from "../types-BmzTyGt-.js";
2
+ import { t as Comments } from "../index-CbXek64X.js";
3
+ import { j as CommentsUser, s as CommentsRequestEvent } from "../types-VSVs4jIw.js";
4
+ import { t as CommentsSessionOptions } from "../session-CK3Rnjto.js";
5
+ import { t as InstallCommentsOptions } from "../install-C3CW6Vvw.js";
6
+ import { o as CommentsDatabase } from "../service-qaMuJ7UX.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
@@ -162,8 +161,6 @@ interface CommentsPluginOptions extends CommentsSessionOptions {
162
161
  /** The tables of a Postgres Database. Default: the SQLite tables. */
163
162
  tables?: InstallCommentsOptions["tables"];
164
163
  dialect?: InstallCommentsOptions["dialect"];
165
- /** Loads `@vite-hub/webhooks`, when `defineComments({ send })` is on. */
166
- webhooks?: InstallCommentsOptions["webhooks"];
167
164
  /** Loads `@vite-hub/comments/realtime`, when the app has the page presence rooms. */
168
165
  realtime?: InstallCommentsOptions["realtime"];
169
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
- import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-Bx4lZ0yt.js";
2
- import { t as applicationRequestOrigin } from "../request-origin-B-CPVAVk.js";
3
- import "../client-files-lC6X7XyS.js";
4
- import { t as commentsErrors } from "../errors-C0VwRHiy.js";
1
+ import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-WRh__ppm.js";
2
+ import { n as resolveCommentsPage, o as viteHubPageSessionHandler, s as applicationRequestOrigin, t as resolveCommentsIdentity } from "../session-1SI3_wLJ.js";
3
+ import "../client-files-CMPJEd21.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-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";
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-DHXmbtb3.js";
8
+ import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-hs9Z38io.js";
9
+ import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-DFMwCr60.js";
10
+ import { a as commentsPageScope, p as normalizeCommentPage, s as commentsRoute } from "../page-CJz1K67L.js";
11
+ import { n as installedComments, t as defineCommentsPlugin } from "../plugin-DczA2K-y.js";
13
12
  import { t as invariant } from "../invariant-CmdvZ3vp.js";
14
- import { t as commentsErrorDiagnostics } from "../errors-CBvIpwbo.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";
@@ -22,7 +22,6 @@ import { stateless } from "@vite-hub/auth/presets";
22
22
  // src/runtime/handler.ts
23
23
  const fieldEditGrant = defineGrant("vitehub.comments.field-edit", (input) => input);
24
24
  const pageSchema = v.pipe(v.string(), v.startsWith("/", "A page starts with `/`."), v.maxLength(1024));
25
- /** `POST /threads`: the input of `comments.create`, or a `page` instead of the subject, and the page context of the overlay. */
26
25
  const createBody = v.object({
27
26
  ...commentInputSchemas.create.entries,
28
27
  subject: v.optional(commentInputSchemas.create.entries.subject),
@@ -40,7 +39,6 @@ const editBody = v.object({
40
39
  body: commentInputSchemas.edit.entries.body,
41
40
  mentions: commentInputSchemas.edit.entries.mentions
42
41
  });
43
- /** The first issue as one sentence, for `COMMENTS_INVALID_INPUT`. */
44
42
  function describeIssue(issues) {
45
43
  const issue = issues[0];
46
44
  if (!issue) return "unknown issue.";
@@ -55,14 +53,8 @@ const fieldBody = v.object({
55
53
  function status(code) {
56
54
  switch (code) {
57
55
  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;
56
+ case "COMMENTS_CONTENT_MISSING": return 404;
64
57
  case "COMMENTS_FORBIDDEN":
65
- case "COMMENTS_SEND_INSECURE":
66
58
  case "COMMENTS_POLICY_MISSING":
67
59
  case "COMMENTS_FIELD_FORBIDDEN": return 403;
68
60
  case "COMMENTS_RESOLVED":
@@ -85,7 +77,6 @@ function json(value, init = {}) {
85
77
  function failure$1(error) {
86
78
  return json({ error }, { status: status(error.code) });
87
79
  }
88
- /** A thrown Comments diagnostic, such as `COMMENTS_R0019` for tables that need a migration, as the API's error object. */
89
80
  function diagnosticResponse(error) {
90
81
  const code = Reflect.get(Object(error), "code");
91
82
  const status = Reflect.get(Object(error), "status");
@@ -101,7 +92,6 @@ function diagnosticResponse(error) {
101
92
  ...typeof retryAfter === "number" ? { headers: { "retry-after": String(Math.ceil(retryAfter)) } } : {}
102
93
  });
103
94
  }
104
- /** The REST code of a diagnostic of the comment actions. Codes without one, such as `COMMENTS_R0019`, stay as they are. */
105
95
  const restCodes = {
106
96
  COMMENTS_R0002: "COMMENTS_NOT_FOUND",
107
97
  COMMENTS_R0003: "COMMENTS_NOT_FOUND",
@@ -116,7 +106,6 @@ const restCodes = {
116
106
  COMMENTS_R0017: "COMMENTS_INVALID_INPUT",
117
107
  COMMENTS_R0018: "COMMENTS_INVALID_INPUT"
118
108
  };
119
- /** A failure of a comment action as the API's error object: the REST code, and the status of the diagnostic. */
120
109
  function actionFailure(error, action) {
121
110
  const code = Reflect.get(Object(error), "code");
122
111
  const mapped = typeof code === "string" ? restCodes[code] : void 0;
@@ -129,7 +118,6 @@ function actionFailure(error, action) {
129
118
  why
130
119
  } : result }, { status: mapped === "COMMENTS_INVALID_INPUT" && typeof statusOf === "number" ? statusOf : status(mapped) });
131
120
  }
132
- /** Response headers for a stored file: its checked type, a file name, and no way for the browser to run it. */
133
121
  function attachmentHeaders(file) {
134
122
  return new Headers({
135
123
  "cache-control": "private, max-age=300",
@@ -282,7 +270,6 @@ function createCommentsHandler(options) {
282
270
  url: `${route}/auth/github`
283
271
  } : void 0;
284
272
  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
273
  const agent = identity.commentsAgent && read ? {
287
274
  ...identity.commentsAgent,
288
275
  mcp: `${configuredConsoleOrigin()}/mcp/account`
@@ -303,7 +290,6 @@ function createCommentsHandler(options) {
303
290
  ...options.attachments === false ? { attachments: false } : {},
304
291
  ...options.presence === false ? { presence: false } : {},
305
292
  content: Boolean(options.content),
306
- ...send ? { send: true } : {},
307
293
  ...agent ? { agent } : {},
308
294
  ...repository ? { repository } : {},
309
295
  ...subject ? { subject } : {},
@@ -357,7 +343,6 @@ function createCommentsHandler(options) {
357
343
  ...subject ? { subject } : {}
358
344
  }, who.gate)) throw deniedError(who.runtime, "read", who.user, who.gate);
359
345
  }
360
- /** The list query of `GET /threads`: the filters of `comments.list` as search parameters. */
361
346
  /** `page`: the subject that `page` of `defineComments()` gives for the `?page=` path, as the overlay sees it. */
362
347
  function listQuery(url, page) {
363
348
  const params = url.searchParams;
@@ -501,77 +486,6 @@ function createCommentsHandler(options) {
501
486
  const env = request["~standard"].runtime?.cloudflare?.env;
502
487
  return env ? await runWithActiveCloudflareEnv(env, () => handle(request)) : await handle(request);
503
488
  } };
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), applicationRequestOrigin(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: applicationRequestOrigin(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
489
  async function route(request) {
576
490
  const url = new URL(request.url);
577
491
  const path = url.pathname.slice(url.pathname.indexOf("/_vitehub/comments") + 18).replace(/\/+$/, "") || "/";
@@ -585,11 +499,10 @@ function createCommentsHandler(options) {
585
499
  id: subjectId
586
500
  } } : void 0;
587
501
  const subjectOf = async () => (await pageOf())?.subject;
588
- if (method !== "GET" && !(method === "POST" && path === "/send/pair") && !sameOrigin(request)) return json({ error: {
502
+ if (method !== "GET" && !sameOrigin(request)) return json({ error: {
589
503
  code: "COMMENTS_FORBIDDEN",
590
504
  why: "Comments requests must come from the site's own pages."
591
505
  } }, { status: 403 });
592
- if (parts[0] === "send") return await sendRoute(request, url, parts, pageOf);
593
506
  if (method === "GET" && path === "/session") {
594
507
  const current = await pageOf();
595
508
  return await session(request, current?.subject, current?.revision);
@@ -738,7 +651,6 @@ function commentsDefinitionOf(module, file) {
738
651
  return validateCommentsDefinition(module.comments ?? module.default, file);
739
652
  }
740
653
  // src/runtime/mcp.ts
741
- /** A user supplied by an app's own MCP server. Missing identities remain anonymous. */
742
654
  function commentsUser(user) {
743
655
  const id = text(user?.id) ?? text(user?.email);
744
656
  return user && id ? {
@@ -755,23 +667,16 @@ function failure(why) {
755
667
  isError: true
756
668
  };
757
669
  }
758
- /** The catalog's COMMENTS_FORBIDDEN, as the overlay API answers it. */
759
670
  function forbidden(action) {
760
671
  const error = commentsErrors.COMMENTS_FORBIDDEN({ action });
761
672
  return failure(`${error.why} ${error.fix}`);
762
673
  }
763
- /** Issued after `authorize` allows a tool's action on a thread. The reply and resolve writes need it. */
764
674
  const toolGrant = defineGrant("vitehub.comments.mcp-action", (input) => Object.freeze({ ...input }));
765
675
  function spend(grant, action, threadId) {
766
676
  const allowed = toolGrant.consume(grant);
767
677
  invariant(allowed.action === action && allowed.threadId === threadId, "each Comments tool spends the grant that it issued for the same action and thread");
768
678
  }
769
- /** The bytes of images that one `comments_get_thread` answer carries, before Base64. */
770
679
  const maximumThreadImageBytes = 4194304;
771
- /**
772
- * The image attachments of a thread, in message order, for a reader who may read it, until they reach
773
- * `maximumThreadImageBytes`. `notes` says which files the Agent does not see, and why.
774
- */
775
680
  async function threadImages(comments, thread, user) {
776
681
  const runtime = await runtimeOf(comments);
777
682
  if (!runtime) return {
@@ -852,7 +757,12 @@ function commentsMcpTools(comments, options = {}) {
852
757
  })
853
758
  };
854
759
  }
855
- const tools = [
760
+ async function finishWrite(context) {
761
+ const standard = context.event?.["~standard"];
762
+ if (standard?.waitUntil) standard.waitUntil(comments.flush());
763
+ else await comments.flush();
764
+ }
765
+ return [
856
766
  {
857
767
  name: "comments_list_threads",
858
768
  title: "List ViteHub Comments threads",
@@ -990,11 +900,7 @@ function commentsMcpTools(comments, options = {}) {
990
900
  body: {
991
901
  type: "string",
992
902
  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
- } } : {}
903
+ }
998
904
  },
999
905
  required: ["id", "body"],
1000
906
  additionalProperties: false
@@ -1006,26 +912,13 @@ function commentsMcpTools(comments, options = {}) {
1006
912
  const { thread, grant } = found;
1007
913
  const author = identity.user ? authorOf(identity.user) : guestFor(context);
1008
914
  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
915
  spend(grant, "write", thread.id);
1019
916
  const [error, message] = await comments.reply(thread.id, {
1020
917
  body: text(input.body) ?? "",
1021
- author,
1022
- ...send ? { actor: {
1023
- id: "comments-mcp",
1024
- name: "Comments agent"
1025
- } } : {}
918
+ author
1026
919
  });
1027
920
  if (error) return failure(error.why);
1028
- await comments.flush();
921
+ await finishWrite(context);
1029
922
  return {
1030
923
  text: `Replied to thread ${thread.id}.`,
1031
924
  structured: { message: { ...message } }
@@ -1064,7 +957,7 @@ function commentsMcpTools(comments, options = {}) {
1064
957
  };
1065
958
  const [error, updated] = input.resolved === false ? await comments.reopen(thread.id) : await comments.resolve(thread.id, { by: author });
1066
959
  if (error) return failure(error.why);
1067
- await comments.flush();
960
+ await finishWrite(context);
1068
961
  return {
1069
962
  text: `Thread ${updated.id} is ${updated.status}.`,
1070
963
  structured: { thread: { ...commentThreadSummary(updated) } }
@@ -1072,42 +965,6 @@ function commentsMcpTools(comments, options = {}) {
1072
965
  }
1073
966
  }
1074
967
  ];
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
968
  }
1112
969
  // ../internal/src/runtime/mcp-server.ts
1113
970
  /** The MCP result of a `ViteHubMcpTool` call: a text block, then one image block for each image. */
@@ -1144,9 +1001,7 @@ const githubLoginEnv = {
1144
1001
  };
1145
1002
  /** Where Better Auth serves the GitHub sign-in of Comments. */
1146
1003
  const githubLoginPath = `${commentsRoute}/auth`;
1147
- /** How long a sign-in lasts. The session is in an encrypted cookie, so it cannot be revoked before then. */
1148
1004
  const sessionLifetime = "7d";
1149
- /** How long Comments trusts the repository access that GitHub reported for a person. */
1150
1005
  const accessLifetime = 3e5;
1151
1006
  const userResponse = v.object({ login: v.string() });
1152
1007
  const repositoryResponse = v.object({ permissions: v.optional(v.object({ push: v.optional(v.boolean()) })) });
@@ -1154,11 +1009,6 @@ function serverEnv(name) {
1154
1009
  const value = getActiveCloudflareBinding(name) ?? globalThis.process?.env?.[name];
1155
1010
  return typeof value === "string" && value ? value : void 0;
1156
1011
  }
1157
- /**
1158
- * The secret of the session cookies: derived from `VITEHUB_SECRET` for Comments alone, so the app's own Auth cookies
1159
- * and these never open each other. Without a root secret, Better Auth uses its development secret, and fails in
1160
- * production.
1161
- */
1162
1012
  function sessionSecret() {
1163
1013
  const root = readViteHubSecret({ VITEHUB_SECRET: serverEnv("VITEHUB_SECRET") });
1164
1014
  if (!root) return;
@@ -1184,7 +1034,7 @@ function createCommentsGitHubLogin(options = {}) {
1184
1034
  const clientId = serverEnv(githubLoginEnv.clientId);
1185
1035
  const clientSecret = serverEnv(githubLoginEnv.clientSecret);
1186
1036
  const secret = sessionSecret();
1187
- const origin = applicationRequestOrigin(request);
1037
+ const origin = applicationRequestOrigin(clientRequest(request));
1188
1038
  const key = [
1189
1039
  origin,
1190
1040
  clientId,
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.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;