@vite-hub/comments 0.4.1 → 0.5.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 (59) hide show
  1. package/README.md +19 -7
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/client.d.ts +424 -11
  4. package/dist/client.js +405 -5
  5. package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
  6. package/dist/{migrate-Bpw3xL5e.js → database-6hXRnqDE.js} +47 -2
  7. package/dist/database-CTo7mx6t.d.ts +575 -0
  8. package/dist/database.d.ts +2 -1
  9. package/dist/database.js +2 -2
  10. package/dist/{define-CX_Yr_hz.js → define-BMBSVbD9.js} +1 -1
  11. package/dist/{define-CHTWfHPo.d.ts → define-CmIFU96x.d.ts} +8 -4
  12. package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
  13. package/dist/{errors-BHsVXlpd.js → errors-Dq4AHjza.js} +16 -0
  14. package/dist/{index-iPGlSAgj.d.ts → index-RiHzmV16.d.ts} +113 -11
  15. package/dist/index.d.ts +6 -7
  16. package/dist/index.js +21 -7
  17. package/dist/{install-96NXWnrw.d.ts → install-BGGQKbQ4.d.ts} +9 -3
  18. package/dist/{install-jRKmuLHK.js → install-DrAse1Fa.js} +844 -38
  19. package/dist/{installed-g6nDr5ac.js → installed-C3EoqJEY.js} +7 -6
  20. package/dist/{operations-D93EV10O.d.ts → operations-BKhUWYkb.d.ts} +9 -5
  21. package/dist/{operations-7ycAhDCw.d.ts → operations-VyyNZusz.d.ts} +8 -2
  22. package/dist/{operations-9tskoLsk.js → operations-lsVKE0GH.js} +294 -212
  23. package/dist/operations.d.ts +2 -2
  24. package/dist/operations.js +2 -2
  25. package/dist/overlay/{client-lZesR40x.js → client-DBmJ4C1M.js} +1 -1
  26. package/dist/overlay/overlay.js +36 -40
  27. package/dist/page/loader.js +39 -47
  28. package/dist/{page-CWwnmF3K.d.ts → page-Bzj0CszG.d.ts} +1 -10
  29. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
  30. package/dist/{plugin-BNFd1zGz.js → plugin-DRsNaJaK.js} +14 -9
  31. package/dist/realtime.d.ts +2 -2
  32. package/dist/realtime.js +1 -1
  33. package/dist/request-log-Dj9Vw7qG.js +105 -0
  34. package/dist/request-origin-CFU0TQ7E.js +49 -0
  35. package/dist/{rpc-BZ1QNkCC.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
  36. package/dist/rpc.d.ts +1 -1
  37. package/dist/runtime/auth.d.ts +2 -2
  38. package/dist/runtime/auth.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +1 -1
  41. package/dist/runtime/index.d.ts +11 -9
  42. package/dist/runtime/index.js +148 -14
  43. package/dist/{server-CqyzrqTI.js → server-Yk610niJ.js} +1 -1
  44. package/dist/server.d.ts +6 -5
  45. package/dist/server.js +5 -5
  46. package/dist/service-Bj-Mg63c.d.ts +73 -0
  47. package/dist/{service-C8ZgFWvy.js → service-DA5BwfPQ.js} +39 -11
  48. package/dist/{session-CKfW6DGE.d.ts → session-DUcEor2W.d.ts} +3 -3
  49. package/dist/{session-ByjMyTak.js → session-X_g9dnU5.js} +26 -29
  50. package/dist/{service-wC9kx9EX.d.ts → store-CsUNfC1w.d.ts} +2 -70
  51. package/dist/{table-names-DfiKUlOV.js → table-names-B9LlRC0B.js} +3 -1
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +2 -2
  54. package/dist/{types-C7LzhgRb.d.ts → types-BLaYh0_f.d.ts} +1 -1
  55. package/dist/{types-C1qzObs2.d.ts → types-C35INXIs.d.ts} +79 -4
  56. package/dist/vite.d.ts +22 -5
  57. package/dist/vite.js +140 -65
  58. package/package.json +8 -8
  59. package/dist/errors-BEChnUo7.d.ts +0 -197
@@ -1,9 +1,10 @@
1
1
  import { t as replyMessageId } from "./reply-id-P_bSuEng.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
3
- import { t as foldName } from "./fold-name-B7Zb3-MF.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
4
3
  import { t as isPagePath } from "./path--zk6PEMz.js";
4
+ import { t as foldName } from "./fold-name-B7Zb3-MF.js";
5
5
  import { r as guestIdPrefix } from "./identity-CBOzgxSf.js";
6
- import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-CX_Yr_hz.js";
6
+ import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-BMBSVbD9.js";
7
+ import { t as logFailure } from "./request-log-Dj9Vw7qG.js";
7
8
  import * as v from "valibot";
8
9
  //#region ../internal/src/runtime/client-rate-limit.ts
9
10
  const windowPattern = /^(\d+)(ms|s|m|h|d)$/;
@@ -145,20 +146,23 @@ function scopeOf(runtime, target) {
145
146
  }
146
147
  /**
147
148
  * The one access policy of every surface: `authorize`, else `defaultPolicy()`. Only `true` allows. `gate` says what the
148
- * server checked before, such as the Console's section access; `development` defaults to the runtime's.
149
+ * server checked before, such as the Console's section access; `development` defaults to the runtime's. `authorize`
150
+ * gets `development` from it. It gets `console` only from `context`: a mention check keeps the writer's gate, but the
151
+ * mentioned person was not admitted by the Console.
149
152
  */
150
153
  async function can(runtime, context, gate = {}) {
151
154
  const { authorize } = runtime.definition;
152
155
  const subject = context.subject ?? context.thread?.subject;
153
- const full = {
154
- ...context,
155
- user: context.user ? { ...context.user } : null,
156
- ...subject ? { subject } : {}
157
- };
158
156
  const checked = {
159
157
  ...gate,
160
158
  development: gate.development ?? runtime.development === true
161
159
  };
160
+ const full = {
161
+ ...context,
162
+ user: context.user ? { ...context.user } : null,
163
+ ...subject ? { subject } : {},
164
+ development: checked.development
165
+ };
162
166
  if (authorize) return await authorize(full) === true;
163
167
  if (defaultPolicy(full.user, checked, full.action)) return true;
164
168
  if (deniedForMissingPolicy(runtime.definition, full.user, checked)) warnMissingPolicy();
@@ -343,10 +347,23 @@ async function announce(runtime, thread, message, mentions, fresh, options) {
343
347
  thread
344
348
  });
345
349
  } catch (error) {
346
- globalThis.console.error("[vitehub] Comments onComment failed:", error);
350
+ logFailure({
351
+ field: "comments",
352
+ fields: {
353
+ hook: "onComment",
354
+ thread: thread.id
355
+ },
356
+ message: "Comments onComment failed",
357
+ error,
358
+ ...options.request ? { request: options.request } : {}
359
+ }, () => globalThis.console.error("[vitehub] Comments onComment failed:", error));
347
360
  }
348
361
  if (!onMention || !fresh.length) return;
349
362
  const link = subjectDefinition(runtime, thread.subject.kind)?.link?.(thread);
363
+ const keep = (promise) => {
364
+ options.waitUntil?.(promise);
365
+ runtime.background?.(promise);
366
+ };
350
367
  const task = (async () => {
351
368
  try {
352
369
  await onMention({
@@ -356,7 +373,16 @@ async function announce(runtime, thread, message, mentions, fresh, options) {
356
373
  ...link ? { link } : {}
357
374
  });
358
375
  } catch (error) {
359
- globalThis.console.error("[vitehub] Comments onMention failed:", error);
376
+ logFailure({
377
+ field: "comments",
378
+ fields: {
379
+ hook: "onMention",
380
+ thread: thread.id
381
+ },
382
+ message: "Comments onMention failed",
383
+ error,
384
+ waitUntil: keep
385
+ }, () => globalThis.console.error("[vitehub] Comments onMention failed:", error));
360
386
  }
361
387
  })();
362
388
  options.waitUntil?.(task);
@@ -419,6 +445,7 @@ async function createThread(runtime, input, options = {}) {
419
445
  if (created.id !== threadId) return retried(created, input, options.canRead);
420
446
  await announce(runtime, created, created.messages[0], mentioned, mentioned, {
421
447
  comment: true,
448
+ ...options.request ? { request: options.request } : {},
422
449
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
423
450
  });
424
451
  runtime.forge?.changed(created.id);
@@ -485,6 +512,7 @@ async function replyToThread(runtime, thread, input, options = {}) {
485
512
  const message = next.messages.find((entry) => entry.id === id);
486
513
  await announce(runtime, next, message, mentioned, mentioned, {
487
514
  comment: true,
515
+ ...options.request ? { request: options.request } : {},
488
516
  ...options.waitUntil ? { waitUntil: options.waitUntil } : {}
489
517
  });
490
518
  runtime.forge?.changed(next.id);
@@ -1,6 +1,6 @@
1
- import { g as CommentsUser } from "./define-CHTWfHPo.js";
2
- import { s as CommentsRequestEvent } from "./types-C1qzObs2.js";
3
- import "./index-iPGlSAgj.js";
1
+ import { g as CommentsUser } from "./define-CmIFU96x.js";
2
+ import { f as CommentsRequestEvent } from "./types-C35INXIs.js";
3
+ import "./index-RiHzmV16.js";
4
4
  //#region src/runtime/session.d.ts
5
5
  interface CommentsSessionOptions {
6
6
  /** Reads the ViteHub Auth user only when no custom `identify` is configured. */
@@ -1,5 +1,6 @@
1
1
  import { o as normalizeCommentPage } from "./page-DRz_sDY4.js";
2
- import { c as viteHubPageToolsInlineStart, 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-NHUjKI8E.js";
2
+ import { r as matchesPublicOrigin, t as forwardedRequestOrigin } from "./request-origin-CFU0TQ7E.js";
3
+ import { c as viteHubPageToolsInlineStart, 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-BNnuPK93.js";
3
4
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
4
5
  //#region ../internal/src/runtime/page-tools-html.ts
5
6
  /** The effective script-element directive is shared by HTTP and HTML meta policies. */
@@ -29,7 +30,7 @@ function isGeneratedCheck(inline) {
29
30
  try {
30
31
  const path = JSON.parse(inline.slice(at + 7, -1));
31
32
  const nonce = tagNonce(inline);
32
- return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=21") && viteHubPageToolsInlineScript(path.slice(0, -36), nonce) === `${inline}<\/script>`;
33
+ return typeof path === "string" && path.endsWith("/_vitehub/page/assets/loader.js?v=22") && viteHubPageToolsInlineScript(path.slice(0, -36), nonce) === `${inline}<\/script>`;
33
34
  } catch {
34
35
  return false;
35
36
  }
@@ -163,28 +164,6 @@ function pageToolsHtmlTransform(loader) {
163
164
  });
164
165
  }
165
166
  //#endregion
166
- //#region ../internal/src/runtime/request-origin.ts
167
- function firstHeaderValue(headers, name) {
168
- return headers.get(name)?.split(",", 1)[0]?.trim() || void 0;
169
- }
170
- /**
171
- * The origin that the client used for `request`. A TLS-terminating proxy sends the client scheme in
172
- * `X-Forwarded-Proto` and the client host in `X-Forwarded-Host`. Each proxy appends its value, so the first value wins.
173
- * Without these headers, or with values that are not valid, the result is the origin of `request.url`.
174
- */
175
- function forwardedRequestOrigin(request) {
176
- const url = new URL(request.url);
177
- const forwardedProtocol = firstHeaderValue(request.headers, "x-forwarded-proto")?.toLowerCase();
178
- const protocol = forwardedProtocol === "http" || forwardedProtocol === "https" ? forwardedProtocol : url.protocol.slice(0, -1);
179
- const host = firstHeaderValue(request.headers, "x-forwarded-host") ?? url.host;
180
- if (/[\u0000-\u001F\s/\\?#@]/.test(host)) return url.origin;
181
- try {
182
- return new URL(`${protocol}://${host}`).origin;
183
- } catch {
184
- return url.origin;
185
- }
186
- }
187
- //#endregion
188
167
  //#region ../internal/src/runtime/page-tools.ts
189
168
  const stateKey = Symbol.for("vitehub.page-tools");
190
169
  const scope = globalThis;
@@ -224,6 +203,10 @@ async function readAccount(nitroApp, request) {
224
203
  function viteHubSiteVisitorReader() {
225
204
  return state().siteVisitor;
226
205
  }
206
+ /** Whether the app serves its page tools on the origin of the request. Every origin counts for an app without `origins`. */
207
+ function servesOrigin(nitroApp, request) {
208
+ return matchesPublicOrigin(request, state().origins?.get(nitroApp) ?? []);
209
+ }
227
210
  /** The path of a URL below the app base. A path outside the base stays as it is. */
228
211
  function pathBelow(base, pathname) {
229
212
  return base && (pathname === base || pathname.startsWith(`${base}/`)) ? pathname.slice(base.length) || "/" : pathname;
@@ -241,6 +224,7 @@ function isPagePath(url, base) {
241
224
  function pageAddition(nitroApp, request, base) {
242
225
  const url = new URL(request.url);
243
226
  if ((state().tools.get(nitroApp)?.size ?? 0) === 0 || !isPagePath(url, base)) return void 0;
227
+ if (!request.headers.has("x-nitro-prerender") && !servesOrigin(nitroApp, request)) return void 0;
244
228
  return viteHubPageToolsWanted(url.search, request.headers.get("cookie") ?? "") ? "loader" : "bootstrap";
245
229
  }
246
230
  function loaderTag(base, nonce) {
@@ -258,12 +242,13 @@ function sessionResponse(value, init = {}) {
258
242
  });
259
243
  }
260
244
  /**
261
- * Answers `GET <base>/_vitehub/page/session`: the tools whose `allowed` check passes for this visitor, in registration
245
+ * Answers `GET <base>/_vitehub/page/tools`: the tools whose `allowed` check passes for this visitor, in registration
262
246
  * order. The app base is the part of the request path before the session path, as the Console finds its own base, and
263
247
  * each tool `script` path gets it. When at least one tool is allowed, the answer also has the `account` of a signed-in
264
248
  * visitor, from the reader of `registerViteHubPageAccount()`. An anonymous visitor never gets one. It sets the hint cookie to `1` when at least one tool is allowed, and to `0` when
265
249
  * none is, so a signed-in person without access does not ask again on each page. A tool whose check throws is not
266
- * allowed. Requests from other sites get 403 and run no check.
250
+ * allowed. Requests from other sites get 403 and run no check. An origin that the app does not serve its page tools on
251
+ * gets 404.
267
252
  */
268
253
  async function respondViteHubPageSession(nitroApp, request) {
269
254
  if (request.method !== "GET" && request.method !== "HEAD") return sessionResponse({ error: {
@@ -275,6 +260,10 @@ async function respondViteHubPageSession(nitroApp, request) {
275
260
  code: "VITEHUB_PAGE_TOOLS_CROSS_ORIGIN",
276
261
  why: "The page tools session answers the site's own pages only."
277
262
  } }, { status: 403 });
263
+ if (!servesOrigin(nitroApp, request)) return sessionResponse({ error: {
264
+ code: "VITEHUB_PAGE_TOOLS_ORIGIN",
265
+ why: "The page tools answer only on the public URL of the app."
266
+ } }, { status: 404 });
278
267
  const registered = [...state().tools.get(nitroApp)?.values() ?? []];
279
268
  const checks = await Promise.all(registered.map(async (tool) => {
280
269
  try {
@@ -299,8 +288,8 @@ async function respondViteHubPageSession(nitroApp, request) {
299
288
  } : { tools }, { cookie: viteHubPageToolsHintCookie(tools.length > 0) });
300
289
  }
301
290
  /**
302
- * The route of `GET /_vitehub/page/session`: a Fetchable (https://fetchable.org). Nitro 3 binds each Request to its
303
- * app in `installViteHubPageTools()`, so the route finds the tools of that app.
291
+ * The route of `GET /_vitehub/page/tools`: a Fetchable (https://fetchable.org). `installViteHubPageTools()` binds
292
+ * each Request to its app in Nitro's `request` hook, so the route finds the tools of that app.
304
293
  */
305
294
  const viteHubPageSessionHandler = { async fetch(request) {
306
295
  const nitroApp = state().apps.get(request);
@@ -412,13 +401,21 @@ function transformPage(response, tag, personal) {
412
401
  * static assets, still shows the pill. Call it from each owner's Nitro plugin: it installs once per app, whatever the
413
402
  * number of calls. It reads that app's registry and configured base on each request, so plugin order does not matter.
414
403
  * It wraps `nitroApp.fetch`, the Web entry that every preset and the prerenderer call. The tag uses `options.base`.
404
+ * It binds each request to the app in Nitro's `request` hook too, since another wrapper of `fetch` may pass a copy of
405
+ * the request inward, such as the `security` policy of `vite-hub` on Node.js.
415
406
  */
416
407
  function installViteHubPageTools(nitroApp, options = {}) {
417
408
  if (nitroApp === null || typeof nitroApp !== "object") return;
418
409
  const { installed, bases } = state();
419
410
  if (options.base !== void 0) bases.set(nitroApp, viteHubBasePath(options.base));
411
+ if (options.origins !== void 0) (state().origins ??= /* @__PURE__ */ new WeakMap()).set(nitroApp, options.origins);
420
412
  if (installed.has(nitroApp)) return;
421
413
  installed.add(nitroApp);
414
+ const hooks = Reflect.get(nitroApp, "hooks");
415
+ const hook = hooks && typeof hooks === "object" ? Reflect.get(hooks, "hook") : void 0;
416
+ if (hook instanceof Function) Reflect.apply(hook, hooks, ["request", (event) => {
417
+ if (event?.req instanceof Request) state().apps.set(event.req, nitroApp);
418
+ }]);
422
419
  const fetch = Reflect.get(nitroApp, "fetch");
423
420
  if (fetch instanceof Function) {
424
421
  Reflect.set(nitroApp, "fetch", async (request, ...rest) => {
@@ -500,4 +497,4 @@ async function resolveCommentsPage(comments, event, request, path) {
500
497
  };
501
498
  }
502
499
  //#endregion
503
- export { viteHubPageSessionHandler as a, registerViteHubPageTool as i, resolveCommentsPage as n, forwardedRequestOrigin as o, installViteHubPageTools as r, resolveCommentsIdentity as t };
500
+ export { viteHubPageSessionHandler as a, registerViteHubPageTool as i, resolveCommentsPage as n, installViteHubPageTools as r, resolveCommentsIdentity as t };
@@ -1,21 +1,6 @@
1
- import { D as CommentUser, S as CommentStatus, T as CommentThread, b as CommentMetadata, n as CommentActor, r as CommentAnchor, s as CommentContext, v as CommentListQuery, w as CommentSubject } from "./types-C7LzhgRb.js";
2
- import { d as CommentsPeople, g as CommentsUser, l as CommentsDefinition } from "./define-CHTWfHPo.js";
1
+ import { D as CommentUser, S as CommentStatus, T as CommentThread, b as CommentMetadata, n as CommentActor, r as CommentAnchor, s as CommentContext, v as CommentListQuery, w as CommentSubject } from "./types-BLaYh0_f.js";
3
2
  import { i as commentThreads, r as commentMessages, t as commentCounters } from "./database-CA1aHKN7.js";
4
- import "valibot";
5
3
  import { LibSQLDatabase } from "drizzle-orm/libsql";
6
- //#region ../internal/src/runtime/client-rate-limit.d.ts
7
- /** The part of `checkRateLimit()` from `vite-hub/rate-limit` that a public write calls. */
8
- type SharedRateLimit = (request: Request, name: string, options: {
9
- key: string;
10
- limit: number;
11
- window: `${number}${"ms" | "s" | "m" | "h" | "d"}`;
12
- }) => Promise<[unknown, {
13
- allowed: boolean;
14
- reason?: string;
15
- retryAfter?: number;
16
- cause?: unknown;
17
- } | undefined]>;
18
- //#endregion
19
4
  //#region src/operations-core/store.d.ts
20
5
  /**
21
6
  * The Drizzle database that the store uses. The store calls `select`, `insert`, `update`, and `delete` (with
@@ -109,57 +94,4 @@ interface CommentsStore {
109
94
  }
110
95
  declare function createCommentsStore(database: CommentsDatabase, tables?: CommentsTables): CommentsStore;
111
96
  //#endregion
112
- //#region src/operations-core/service.d.ts
113
- /** Longest message, in characters. */
114
- declare const maximumCommentBodyLength = 10000;
115
- /** The parts of a Blob store that attachments use: `blob` of `@vite-hub/blob`. */
116
- interface CommentsAttachmentStore {
117
- put: (pathname: string, body: Uint8Array, options: {
118
- contentType: string;
119
- }) => Promise<readonly [unknown, unknown]>;
120
- get?: (pathname: string) => Promise<readonly [unknown, Blob | null | undefined]>;
121
- }
122
- /** A file to answer, with the headers that keep a browser from running it. */
123
- interface CommentsAttachmentBody {
124
- key: string;
125
- name: string;
126
- /** The stored media type when Comments attaches that type, else `application/octet-stream`. */
127
- type: string;
128
- size: number;
129
- /** Whether a browser may show it in the page: images other than SVG. */
130
- inline: boolean;
131
- data: Blob;
132
- }
133
- /** The pull request sync of `defineComments({ forge })`. */
134
- interface CommentsForgeHooks {
135
- /** Starts the sync of a thread after a change. */
136
- changed: (threadId: string) => void;
137
- /** The threads with their `forge` link. */
138
- attach: (threads: CommentThread[]) => Promise<CommentThread[]>;
139
- }
140
- /** Everything that the comment operations, the server API, and the overlay API share. */
141
- interface CommentsRuntime {
142
- definition: CommentsDefinition;
143
- /**
144
- * The app's `identify`, given the server event of a call. With it, the comment operations ask it for the user, as
145
- * the overlay API does, instead of taking the Console's user.
146
- */
147
- identify?: (event: unknown) => Promise<CommentsUser | null>;
148
- store: CommentsStore;
149
- /** The Auth adapter. `people` wins over it. Without both, `@` finds the authors that the store knows. */
150
- users?: CommentsPeople;
151
- /** Vite's serve command, for the default guest policy. */
152
- development?: boolean;
153
- /** The Blob store for attachments, when the app has one and no `storeAttachment`. */
154
- attachments?: CommentsAttachmentStore;
155
- forge?: CommentsForgeHooks;
156
- /**
157
- * `checkRateLimit` of ViteHub Rate Limit, when it counts in a KV store that every server process shares. Guest writes
158
- * then count under the Rate Limit name `comments`. Without it, they count in the memory of this process.
159
- */
160
- rateLimit?: SharedRateLimit;
161
- /** Work that runs after the answer, such as `onMention`. `flush()` of the server API waits for it. */
162
- background?: (task: Promise<unknown>) => void;
163
- }
164
- //#endregion
165
- export { maximumCommentBodyLength as a, CommentsTables as c, CommentsRuntime as i, createCommentsStore as l, CommentsAttachmentStore as n, CommentsDatabase as o, CommentsForgeHooks as r, CommentsStore as s, CommentsAttachmentBody as t, SharedRateLimit as u };
97
+ export { createCommentsStore as i, CommentsStore as n, CommentsTables as r, CommentsDatabase as t };
@@ -10,5 +10,7 @@ const commentsTableNames = {
10
10
  vitehubCommentCounters: "vitehub_comment_counters",
11
11
  vitehubCommentForge: "vitehub_comment_forge"
12
12
  };
13
+ /** The tables of `commentSendsSchema`: each schema key and its SQL name. Comments adds them when `send` is on. */
14
+ const commentSendsTableNames = { commentSends: "vitehub_comment_sends" };
13
15
  //#endregion
14
- export { commentsTableNames as t };
16
+ export { commentsTableNames as n, commentSendsTableNames as t };
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { D as CommentUser, T as CommentThread, k as CommentsTransport, w as CommentSubject } from "./types-C7LzhgRb.js";
1
+ import { D as CommentUser, T as CommentThread, k as CommentsTransport, w as CommentSubject } from "./types-BLaYh0_f.js";
2
2
  //#region src/operations-core/testing.d.ts
3
3
  export interface MemoryTransportOptions {
4
4
  /** The signed-in user. Every call acts as this user. */
package/dist/testing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as replyMessageId } from "./reply-id-P_bSuEng.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
3
3
  //#region 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 });
@@ -98,7 +98,7 @@ function view(store, user) {
98
98
  return threads.sort((a, b) => a.n - b.n).map(copy);
99
99
  },
100
100
  async get(input) {
101
- const found = "id" in input ? store.threads.get(input.id) : [...store.threads.values()].find((item) => item.n === input.n && item.scope === input.scope);
101
+ const found = "threadId" in input ? store.threads.get(input.threadId) : [...store.threads.values()].find((item) => item.n === input.n && item.scope === input.scope);
102
102
  return found ? copy(found) : null;
103
103
  },
104
104
  async create(input) {
@@ -249,7 +249,7 @@ interface CommentListCursor {
249
249
  }
250
250
  /** By id, or by number inside its scope, as `?comment=<n>` names it. */
251
251
  type CommentGetInput = {
252
- id: string;
252
+ threadId: string;
253
253
  } | {
254
254
  scope: string;
255
255
  n: number;
@@ -1,5 +1,5 @@
1
- import { D as CommentUser, S as CommentStatus, T as CommentThread, _ as CommentListCursor, b as CommentMetadata, r as CommentAnchor, s as CommentContext, w as CommentSubject } from "./types-C7LzhgRb.js";
2
- import { g as CommentsUser, l as CommentsDefinition } from "./define-CHTWfHPo.js";
1
+ import { D as CommentUser, S as CommentStatus, T as CommentThread, _ as CommentListCursor, b as CommentMetadata, n as CommentActor, r as CommentAnchor, s as CommentContext, w as CommentSubject } from "./types-BLaYh0_f.js";
2
+ import { g as CommentsUser, l as CommentsDefinition } from "./define-CmIFU96x.js";
3
3
  import { ViteHubContext } from "@vite-hub/runtime";
4
4
  //#region src/types.d.ts
5
5
  interface CommentsForgeTarget {
@@ -52,7 +52,80 @@ interface CommentsPageContext {
52
52
  interface CommentsPageSubject extends CommentSubject {
53
53
  revision?: number;
54
54
  }
55
+ /** What `send.address` gets: the member who presses Send, and the subject of their page. */
56
+ interface CommentSendAddressContext {
57
+ user: CommentsUser;
58
+ subject: CommentSubject;
59
+ }
60
+ /** What `send.payload` gets: one send, before Comments delivers it. */
61
+ interface CommentSendPayloadContext {
62
+ /** The id of the send, as `send` of the delivered body. */
63
+ send: string;
64
+ /** The member who pressed Send. */
65
+ user: CommentsUser;
66
+ /** The subject of the page that the member sent from. */
67
+ subject: CommentSubject;
68
+ /** The threads of the send. `asks` and `quotes` split their ids. */
69
+ threads: readonly CommentThread[];
70
+ asks: readonly string[];
71
+ quotes: readonly string[];
72
+ }
73
+ /** What `send.prompt` gets: the values of one setup code, and the default prompt. */
74
+ interface CommentSendPromptContext {
75
+ /** The member who pressed Send. */
76
+ user: CommentsUser;
77
+ /** The subject of the page that the member pairs from. */
78
+ subject: CommentSubject;
79
+ /** The public origin of the app, such as `https://joyandmaxi.com`. */
80
+ origin: string;
81
+ /** The URL that the agent posts the code to: `{ code, url, thread }` for a T3 task, or `{ code, inbox }` for an inbox. */
82
+ pairUrl: string;
83
+ /** The setup code. It works once, for 10 minutes. */
84
+ code: string;
85
+ /** The secret that signs each delivery to a T3 webhook task. */
86
+ secret: string;
87
+ /** Whether each send carries a read token. `false` when `grant` is `false`. */
88
+ grant: boolean;
89
+ /** The default prompt: the steps that connect a T3 Code thread. */
90
+ prompt: string;
91
+ }
92
+ /** A JSON value, as the delivered body holds it. */
93
+ type CommentSendData = string | number | boolean | null | CommentSendData[] | {
94
+ [key: string]: CommentSendData;
95
+ };
96
+ /**
97
+ * Send: a member hands the threads that wait for an answer to their own agent, such as a T3 Code thread. Each member
98
+ * pairs their agent once, in the comment pill.
99
+ */
100
+ interface CommentSendOptions {
101
+ /** Adds `data` to the delivered body, such as the id of a document that your own MCP reads. Default: `null`. */
102
+ payload?: (context: CommentSendPayloadContext) => CommentSendData | Promise<CommentSendData>;
103
+ /**
104
+ * The address of the agent that should get a send from this subject, such as the T3 thread link that wrote the
105
+ * document. A member who paired an agent from that thread sends there; otherwise to the agent they paired last.
106
+ * Default: none, so every send goes to the agent the member paired last.
107
+ */
108
+ address?: (context: CommentSendAddressContext) => string | null | undefined | Promise<string | null | undefined>;
109
+ /**
110
+ * `false` sends no read token: the agent reads the threads through your own MCP server, as the member. Default: each
111
+ * send carries a token that reads its threads, as the member, for 24 hours.
112
+ */
113
+ grant?: false;
114
+ /** The hosts that a paired agent URL may use. Default: `["relay.t3.codes"]`, the T3 Code relay. */
115
+ hosts?: readonly string[];
116
+ /**
117
+ * The setup prompt that Send copies, such as to add the steps of a Claude Code or Codex inbox, or to name the tools of
118
+ * your own MCP server. Default: `context.prompt`, the steps that connect a T3 Code thread.
119
+ */
120
+ prompt?: (context: CommentSendPromptContext) => string | Promise<string>;
121
+ }
55
122
  interface DefineCommentsOptions extends CommentsDefinition {
123
+ /**
124
+ * `true` turns on **Send** in the comment pill, for signed-in people who may write. It needs Webhooks and a SQLite
125
+ * Database: ViteHub adds the `vitehub_comment_sends` tables and the member endpoints of Webhooks. See
126
+ * https://vitehub.dev/docs/comments/send
127
+ */
128
+ send?: boolean | CommentSendOptions;
56
129
  /** Resolves the user of a request. Without it, Comments reads the ViteHub Auth session. Return `null` for anonymous. */
57
130
  identify?: (context: CommentsIdentifyContext) => CommentsUser | null | undefined | Promise<CommentsUser | null | undefined>;
58
131
  /** Name of the Database that stores comments. Defaults to the `default` Database, or the only one. */
@@ -111,6 +184,8 @@ interface EditCommentInput {
111
184
  interface ReplyInput {
112
185
  body: string;
113
186
  author: CommentUser;
187
+ /** The agent replying on behalf of the author. */
188
+ actor?: CommentActor;
114
189
  mentions?: string[];
115
190
  attachments?: string[];
116
191
  /** A retry key. A second reply with the same key and author in the same thread returns the first message. */
@@ -128,6 +203,6 @@ interface ReplyOptions {
128
203
  allowResolved?: boolean;
129
204
  }
130
205
  /** Codes of the errors that Comments methods return in the `[error, data]` tuple. */
131
- type CommentsErrorCode = "COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_FORBIDDEN" | "COMMENTS_POLICY_MISSING" | "COMMENTS_RESOLVED" | "COMMENTS_CONTENT_MISSING" | "COMMENTS_FIELD_INVALID" | "COMMENTS_FIELD_NOT_EDITABLE" | "COMMENTS_FIELD_FORBIDDEN" | "COMMENTS_FIELD_CONFLICT" | "COMMENTS_FIELD_LOCKED";
206
+ type CommentsErrorCode = "COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_FORBIDDEN" | "COMMENTS_POLICY_MISSING" | "COMMENTS_RESOLVED" | "COMMENTS_CONTENT_MISSING" | "COMMENTS_FIELD_INVALID" | "COMMENTS_FIELD_NOT_EDITABLE" | "COMMENTS_FIELD_FORBIDDEN" | "COMMENTS_FIELD_CONFLICT" | "COMMENTS_FIELD_LOCKED" | "COMMENTS_SEND_OFF";
132
207
  //#endregion
133
- export { CommentsPageContext as a, CreateCommentThreadInput as c, FindCommentThreadInput as d, ListCommentThreadsOptions as f, CommentsIdentifyContext as i, DefineCommentsOptions as l, ReplyOptions as m, CommentsForgeOptions as n, CommentsPageSubject as o, ReplyInput as p, CommentsForgeTarget as r, CommentsRequestEvent as s, CommentsErrorCode as t, EditCommentInput as u };
208
+ export { ListCommentThreadsOptions as _, CommentSendPromptContext as a, CommentsForgeTarget as c, CommentsPageSubject as d, CommentsRequestEvent as f, FindCommentThreadInput as g, EditCommentInput as h, CommentSendPayloadContext as i, CommentsIdentifyContext as l, DefineCommentsOptions as m, CommentSendData as n, CommentsErrorCode as o, CreateCommentThreadInput as p, CommentSendOptions as r, CommentsForgeOptions as s, CommentSendAddressContext as t, CommentsPageContext as u, ReplyInput as v, ReplyOptions as y };
package/dist/vite.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { a as CommentBuild } from "./types-C7LzhgRb.js";
2
- import "./types-C1qzObs2.js";
3
- import { a as mountedCommentsRoute } from "./page-CWwnmF3K.js";
4
- import { n as OperationContributions } from "./operations-7ycAhDCw.js";
5
- import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-h4KlhIik.js";
1
+ import { a as CommentBuild } from "./types-BLaYh0_f.js";
2
+ import "./types-C35INXIs.js";
3
+ import { n as mountedCommentsRoute } from "./page-Bzj0CszG.js";
4
+ import { n as OperationContributions } from "./operations-VyyNZusz.js";
5
+ import { i as ViteHubInspectionPluginMetadata, r as ViteHubConsoleRuntimeRecordTableSection, t as ViteHubConsoleOperationSection } from "./console-D1lwNMZn.js";
6
6
  import { Plugin, PluginOption } from "vite";
7
7
  import { githubRepository } from "@vite-hub/forge/build/node";
8
8
  import { DatabaseContributionContext, DatabaseContributionEntry } from "@vite-hub/database/vite";
@@ -74,6 +74,8 @@ interface CommentsImports {
74
74
  blob: string;
75
75
  /** Exports `checkRateLimit`, which counts guest writes when Rate Limit counts in a shared KV store. */
76
76
  rateLimit: string;
77
+ /** `@vite-hub/webhooks`: the member endpoints that `defineComments({ send })` delivers to. */
78
+ webhooks: string;
77
79
  }
78
80
  /** Options of `comments()`, for apps that use Comments without `vite-hub`. */
79
81
  interface CommentsOptions {
@@ -161,6 +163,15 @@ type CommentsVitePlugin$1 = Plugin & {
161
163
  };
162
164
  vitehub: ViteHubInspectionPluginMetadata & {
163
165
  databases: (context: DatabaseContributionContext) => Promise<DatabaseContributionEntry[]>;
166
+ /** Turns on the member endpoints of Webhooks while `defineComments({ send })` is on. */
167
+ webhooks: (context: {
168
+ root?: string;
169
+ projectRoot?: string;
170
+ serverDirs?: readonly string[];
171
+ }) => Promise<{
172
+ memberEndpoints: true;
173
+ reason: string;
174
+ } | undefined>;
164
175
  };
165
176
  };
166
177
  /**
@@ -168,6 +179,11 @@ type CommentsVitePlugin$1 = Plugin & {
168
179
  * default or only Database.
169
180
  */
170
181
  export declare function readCommentsDatabase(file: string): Promise<string | undefined>;
182
+ /**
183
+ * Whether `defineComments({ send })` turns Send on, read without running the file: Send is on unless `send` is missing
184
+ * or `false`. A value known only at runtime counts as on, so the build adds the tables and the member endpoints.
185
+ */
186
+ export declare function readCommentsSend(file: string): Promise<boolean>;
171
187
  /** The directory of the prebuilt overlay script in this package. */
172
188
  export declare function commentsOverlayDirectory(): string;
173
189
  /**
@@ -204,6 +220,7 @@ export declare function renderCommentsPlugin(input: {
204
220
  development?: boolean;
205
221
  build?: CommentBuild;
206
222
  base?: string;
223
+ send?: boolean;
207
224
  }): string;
208
225
  /**
209
226
  * Comments for any Vite app, without `vite-hub`: the comment overlay on every page with `?vitehub`, threads in a