@vite-hub/comments 0.3.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 (67) hide show
  1. package/README.md +37 -15
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/{client-diagnostics-CcFpkbAk.js → client-diagnostics-Bubm7Shd.js} +20 -5
  4. package/dist/client-files-CJZl5Kc4.js +53 -0
  5. package/dist/client.d.ts +567 -13
  6. package/dist/client.js +1209 -34
  7. package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
  8. package/dist/{migrate-BDQ8xqUs.js → database-6hXRnqDE.js} +47 -2
  9. package/dist/database-CTo7mx6t.d.ts +575 -0
  10. package/dist/database.d.ts +2 -1
  11. package/dist/database.js +2 -2
  12. package/dist/{define-43mMR39K.js → define-BMBSVbD9.js} +1 -1
  13. package/dist/{define-B3TF9zzn.d.ts → define-CmIFU96x.d.ts} +8 -4
  14. package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
  15. package/dist/{errors-C6qptPoG.js → errors-Dq4AHjza.js} +23 -3
  16. package/dist/index-RiHzmV16.d.ts +194 -0
  17. package/dist/index.d.ts +6 -7
  18. package/dist/index.js +57 -9
  19. package/dist/{install-W9ghhGoh.d.ts → install-BGGQKbQ4.d.ts} +9 -3
  20. package/dist/{install-BcMPgPk_.js → install-DrAse1Fa.js} +912 -60
  21. package/dist/{installed-B-PfERBU.js → installed-C3EoqJEY.js} +7 -6
  22. package/dist/{operations-GLeOqgMt.d.ts → operations-BKhUWYkb.d.ts} +10 -5
  23. package/dist/{operations-D4A1Fcgf.d.ts → operations-VyyNZusz.d.ts} +13 -2
  24. package/dist/{operations-DMMIfYPW.js → operations-lsVKE0GH.js} +312 -219
  25. package/dist/operations.d.ts +2 -2
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-DBmJ4C1M.js +4 -0
  28. package/dist/overlay/overlay.js +41 -65
  29. package/dist/page/loader.js +39 -47
  30. package/dist/{page-DtbMOEMd.d.ts → page-Bzj0CszG.d.ts} +1 -10
  31. package/dist/{page-B41ozN63.js → page-DRz_sDY4.js} +1 -1
  32. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
  33. package/dist/{plugin-PS8PMYus.js → plugin-DRsNaJaK.js} +34 -8
  34. package/dist/realtime.d.ts +2 -2
  35. package/dist/realtime.js +2 -2
  36. package/dist/reply-id-P_bSuEng.js +12 -0
  37. package/dist/request-log-Dj9Vw7qG.js +105 -0
  38. package/dist/request-origin-CFU0TQ7E.js +49 -0
  39. package/dist/{rpc-RKPAusHp.js → rpc-BQqYx8kb.js} +23 -7
  40. package/dist/{rpc-HBcWtg0T.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
  41. package/dist/rpc.d.ts +1 -1
  42. package/dist/rpc.js +1 -1
  43. package/dist/runtime/auth.d.ts +2 -2
  44. package/dist/runtime/auth.js +2 -2
  45. package/dist/runtime/console.d.ts +1 -1
  46. package/dist/runtime/console.js +3 -3
  47. package/dist/runtime/index.d.ts +42 -13
  48. package/dist/runtime/index.js +224 -22
  49. package/dist/{server-D8k-0GXe.js → server-Yk610niJ.js} +1 -1
  50. package/dist/server.d.ts +6 -5
  51. package/dist/server.js +6 -6
  52. package/dist/service-Bj-Mg63c.d.ts +73 -0
  53. package/dist/{service-GHhhyQj4.js → service-DA5BwfPQ.js} +71 -14
  54. package/dist/{session-DVx-1Tym.d.ts → session-DUcEor2W.d.ts} +3 -3
  55. package/dist/{session-EkudzUmm.js → session-X_g9dnU5.js} +27 -30
  56. package/dist/{service-CFVm23k7.d.ts → store-CsUNfC1w.d.ts} +11 -72
  57. package/dist/table-names-B9LlRC0B.js +16 -0
  58. package/dist/testing.d.ts +1 -1
  59. package/dist/testing.js +38 -5
  60. package/dist/{types-CZujrMFd.d.ts → types-BLaYh0_f.d.ts} +48 -4
  61. package/dist/{types-BIS0hCEl.d.ts → types-C35INXIs.d.ts} +88 -4
  62. package/dist/vite.d.ts +24 -7
  63. package/dist/vite.js +322 -173
  64. package/package.json +9 -9
  65. package/dist/errors-CyQyKAvy.d.ts +0 -185
  66. package/dist/index-DNhy69Wt.d.ts +0 -83
  67. package/dist/overlay/client-DmsSMOzi.js +0 -4
package/dist/client.d.ts CHANGED
@@ -1,5 +1,119 @@
1
- import { A as TextAnchor, C as CommentUploadInput, D as ElementAnchor, E as CommentsTransport, O as ImageAnchor, S as CommentThread, T as CommentUsersInput, _ as CommentMetadata, a as CommentBuild, b as CommentStatusInput, c as CommentCreateInput, d as CommentEvent, f as CommentForgeLink, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, k as PageAnchor, l as CommentDeleteInput, m as CommentListCursor, n as CommentActor, o as CommentComponent, p as CommentGetInput, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentEditInput, v as CommentReplyInput, w as CommentUser, x as CommentSubject, y as CommentStatus } from "./types-CZujrMFd.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-CyQyKAvy.js";
1
+ import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BLaYh0_f.js";
2
+ //#region ../internal/src/browser-environment.d.ts
3
+ /** A page event that a client store reacts to. */
4
+ type BrowserEvent = "online" | "offline" | "visible" | "hidden";
5
+ /** What a client store needs from the browser: page events, one sender across tabs, and messages between tabs. Tests pass a fake one. */
6
+ interface BrowserEnvironment<Message> {
7
+ listen: (listener: (event: BrowserEvent) => void) => () => void;
8
+ isVisible: () => boolean;
9
+ isOnline: () => boolean;
10
+ /** Runs `task` while this tab holds the lock `name`, so one tab at a time sends. */
11
+ lock: <T>(name: string, task: () => Promise<T>) => Promise<T>;
12
+ /**
13
+ * Runs `task` once this tab is the leader for `name`, so one tab of the browser does it at a time. The tab stays the
14
+ * leader until `task` ends. The returned function gives up: it aborts the signal of `task`, or stops waiting.
15
+ */
16
+ lead: (name: string, task: (signal: AbortSignal) => Promise<void>) => () => void;
17
+ post: (message: Message) => void;
18
+ receive: (listener: (message: Message) => void) => () => void;
19
+ /** Runs `task` after `ms`. Returns a function that cancels it. */
20
+ schedule: (task: () => void, ms: number) => () => void;
21
+ random: () => number;
22
+ }
23
+ //#endregion
24
+ //#region src/client-outbox.d.ts
25
+ /** A message between the tabs of one browser. */
26
+ type CommentsOutboxMessage = {
27
+ type: "change";
28
+ account: string;
29
+ } | {
30
+ type: "sent";
31
+ account: string;
32
+ id: string;
33
+ kind: "create" | "reply";
34
+ key: string;
35
+ thread: CommentThread;
36
+ };
37
+ /** What the outbox needs from the browser: online and visible events, Web Locks, and a BroadcastChannel. Tests pass a fake one. */
38
+ type CommentsOutboxEnvironment = BrowserEnvironment<CommentsOutboxMessage>;
39
+ interface CommentsOutboxEntryBase {
40
+ /** The local thread or message id. Use it for outbox actions. */
41
+ id: string;
42
+ /** The retry key that the server gets. */
43
+ requestId: string;
44
+ account: string;
45
+ files: Blob[];
46
+ /** Milliseconds since the epoch. */
47
+ createdAt: number;
48
+ /** The place in the queue. */
49
+ order: number;
50
+ /** `sending` while one tab sends it. `failed` when the server refused it: it waits for `retry` or a safe `edit` or `dismiss`. */
51
+ status: "pending" | "sending" | "failed";
52
+ /** Why the last try did not go out. */
53
+ error?: CommentDeliveryError;
54
+ uncertain?: boolean;
55
+ claim?: string;
56
+ attempts?: number;
57
+ retryAt?: number;
58
+ held?: boolean;
59
+ uploaded?: string[];
60
+ }
61
+ /** A comment or reply that the outbox holds. */
62
+ type CommentsOutboxEntry = CommentsOutboxEntryBase & ({
63
+ kind: "create";
64
+ input: Omit<CommentCreateInput, "requestId">;
65
+ } | {
66
+ kind: "reply";
67
+ input: Omit<CommentReplyInput, "requestId">;
68
+ subject?: CommentSubject;
69
+ });
70
+ /** Where the outbox keeps its entries. The default is IndexedDB, else memory. */
71
+ interface CommentsOutboxStore {
72
+ /** `false` when the entries live only in this page, and a reload loses them. */
73
+ readonly persisted: boolean;
74
+ /** The entries of `account`, in queue order. */
75
+ list: (account: string) => Promise<CommentsOutboxEntry[]>;
76
+ /** Read and change one account's entries in one transaction. Replace entries rather than mutating them. */
77
+ update: <T>(account: string, change: (entries: Map<string, CommentsOutboxEntry>) => T) => Promise<T>;
78
+ }
79
+ interface CommentsOutboxOptions {
80
+ /**
81
+ * Who writes, such as the user id or a guest id. Entries of another account stay stored and do not send, so a
82
+ * comment never goes out as somebody else.
83
+ */
84
+ account: string;
85
+ /** Default: the `vitehub-comments` IndexedDB database, else memory with `persisted: false`. */
86
+ store?: CommentsOutboxStore;
87
+ /** Default: the browser. */
88
+ environment?: CommentsOutboxEnvironment;
89
+ }
90
+ /** The outbox of a client. `onChange` of the client tells every change. */
91
+ interface CommentsOutbox {
92
+ /** Every entry of the account, in queue order. */
93
+ readonly entries: readonly CommentsOutboxEntry[];
94
+ /** The entries that wait to go out or are going out. */
95
+ readonly queued: readonly CommentsOutboxEntry[];
96
+ /** The entries that the server refused. */
97
+ readonly failures: readonly CommentsOutboxEntry[];
98
+ /** `false` when IndexedDB is not available, so a reload loses the entries. */
99
+ readonly persisted: boolean;
100
+ /** Sends the entry again now. Without `id`, resumes pending entries, such as after a sign-in. */
101
+ retry: (id?: string) => Promise<void>;
102
+ /** Removes a draft and its waiting replies. `false` if it is gone or the server may already have it. */
103
+ dismiss: (id: string) => Promise<boolean>;
104
+ /** Changes a draft and requeues a refused entry. `false` if it is gone or the server may already have it. */
105
+ edit: (id: string, body: string, mentions?: string[]) => Promise<boolean>;
106
+ /** Removes every entry of the account, such as at sign-out. */
107
+ clear: () => Promise<void>;
108
+ }
109
+ /** An outbox store in memory. Entries live as long as the store object. Pass one store to two clients to test a reload. */
110
+ export declare function createMemoryOutboxStore(): CommentsOutboxStore;
111
+ /**
112
+ * The default store: the `drafts` object store of the `vitehub-comments` IndexedDB database. When IndexedDB is missing or
113
+ * does not open, as in some private windows, it keeps the entries in memory and `persisted` is `false`.
114
+ */
115
+ export declare function createIndexedDBOutboxStore(): CommentsOutboxStore;
116
+ //#endregion
3
117
  //#region src/client-anchor.d.ts
4
118
  /** A point in client (viewport) coordinates, such as `event.clientX` and `event.clientY`. */
5
119
  interface AnchorPoint {
@@ -67,9 +181,398 @@ export declare function anchorRange(anchor: TextAnchor, root?: ParentNode): Rang
67
181
  */
68
182
  export declare function resolveAnchor(anchor: CommentAnchor, root?: ParentNode): AnchorPosition;
69
183
  //#endregion
70
- //#region src/fold-name.d.ts
71
- /** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
72
- export declare function foldName(text: string): string;
184
+ //#region src/operations-core/errors.d.ts
185
+ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
186
+ readonly COMMENTS_R0002: {
187
+ readonly why: ({ id }: {
188
+ id: string;
189
+ }) => string;
190
+ readonly fix: "List the threads again, because someone may have deleted this one.";
191
+ };
192
+ readonly COMMENTS_R0003: {
193
+ readonly why: ({ messageId }: {
194
+ messageId: string;
195
+ }) => string;
196
+ readonly fix: "Read the thread again, because someone may have deleted the message.";
197
+ };
198
+ readonly COMMENTS_R0004: {
199
+ readonly why: "Only the author of a message can edit or delete it.";
200
+ readonly fix: "Sign in as the author, or ask them to change the message.";
201
+ };
202
+ readonly COMMENTS_R0005: {
203
+ readonly why: "A comment needs some text.";
204
+ readonly fix: "Write at least one character before you send.";
205
+ };
206
+ readonly COMMENTS_R0006: {
207
+ readonly why: "server/comments.ts defines no authorize policy, so a production build lets in only people signed in with GitHub who can push to the repository, and people that the Console admits to its Comments section. Other signed-in people, such as users of ViteHub Auth or identify, get nothing.";
208
+ readonly fix: "Pass authorize to defineComments({ authorize }) and return true for the people and Agents that may take the action. See https://vitehub.dev/docs/comments/configure#decide-who-can-comment";
209
+ };
210
+ readonly COMMENTS_R0007: {
211
+ readonly why: ({ message }: {
212
+ message: string;
213
+ }) => string;
214
+ readonly fix: "Mention only people that users() finds, and write @ and their name in the text.";
215
+ };
216
+ readonly COMMENTS_R0008: {
217
+ readonly why: ({ kind }: {
218
+ kind: string;
219
+ }) => string;
220
+ readonly fix: "Use page or content, or add defineCommentSubject({ kind, scope }) to defineComments({ subjects }).";
221
+ };
222
+ readonly COMMENTS_R0009: {
223
+ readonly why: ({ action }: {
224
+ action: string;
225
+ }) => string;
226
+ readonly fix: "Ask for access, or allow the action in defineComments({ authorize }).";
227
+ };
228
+ readonly COMMENTS_R0010: {
229
+ readonly why: "The comments runtime is not installed.";
230
+ readonly fix: "Add server/comments.ts and enable the Database with vitehub({ database: true }). `vite dev` and builds install the runtime for you.";
231
+ };
232
+ readonly COMMENTS_R0011: {
233
+ readonly why: "The comment numbers of this scope are busy.";
234
+ readonly fix: "Try again. Several people created a comment at the same moment.";
235
+ };
236
+ readonly COMMENTS_R0012: {
237
+ readonly why: "Writing a comment needs a signed-in user.";
238
+ readonly fix: "Sign in, then try again. Without ViteHub Auth or `identify`, sign in with GitHub so comments know who writes.";
239
+ };
240
+ readonly COMMENTS_R0014: {
241
+ readonly why: "Comments has no place to store attachments: the app has no Blob store and no storeAttachment hook.";
242
+ readonly fix: "Turn on Blob with vitehub({ blob: true }), or pass storeAttachment to defineComments().";
243
+ };
244
+ readonly COMMENTS_R0016: {
245
+ readonly why: "The thread is resolved, so it takes no new replies.";
246
+ readonly fix: "Reopen the thread first, or pass { allowResolved: true } to comments.reply() when your UI allows replies to resolved threads.";
247
+ };
248
+ readonly COMMENTS_R0017: {
249
+ readonly why: ({ message }: {
250
+ message: string;
251
+ }) => string;
252
+ readonly fix: "Attach an image, a PDF, or a text file of at most 5 MB.";
253
+ };
254
+ readonly COMMENTS_R0018: {
255
+ readonly why: ({ message }: {
256
+ message: string;
257
+ }) => string;
258
+ readonly fix: "Check the input against the limits of comments: https://vitehub.dev/docs/comments/limits-and-errors";
259
+ };
260
+ readonly COMMENTS_R0019: {
261
+ readonly why: ({ state, missing }: {
262
+ state: "empty" | "live" | "outdated";
263
+ missing: readonly string[];
264
+ }) => string;
265
+ readonly fix: ({ state }: {
266
+ state: "empty" | "live" | "outdated";
267
+ }) => "Move the tables once in a custom migration: run vitehub database generate --custom --schema-snapshot --name comments_one_model, put the SQL of commentsMigrationSql({ from: \"live\" }) from vite-hub/comments/database in it, then run vitehub database migrate. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model" | "Run vitehub database generate and vitehub database migrate, so the Database gets the comment tables of this version. See https://vitehub.dev/docs/comments/configure#upgrade-to-one-model";
268
+ };
269
+ readonly COMMENTS_R0020: {
270
+ readonly why: ({ key }: {
271
+ key: string;
272
+ }) => string;
273
+ readonly fix: "Read the attachment through a message that lists its key, as a person who may read that thread.";
274
+ };
275
+ readonly COMMENTS_R0021: {
276
+ readonly why: "Comments stores attachments with storeAttachment, but has no readAttachment to read them back.";
277
+ readonly fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob.";
278
+ };
279
+ readonly COMMENTS_R0022: {
280
+ readonly why: "Another comment thread of this scope, or another reply in this thread, already uses this requestId: it has another author or another subject, or you may not read it.";
281
+ readonly fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment or reply. Send the same requestId again only to retry the same one.";
282
+ };
283
+ readonly COMMENTS_B0001: {
284
+ readonly why: ({ file }: {
285
+ file: string;
286
+ }) => string;
287
+ readonly fix: "Remove `database: false` from vitehub(), or set `database: true`. vitehub() turns the Database on for comments when the option is unset.";
288
+ };
289
+ readonly COMMENTS_B0002: {
290
+ readonly why: ({ file }: {
291
+ file: string;
292
+ }) => string;
293
+ readonly fix: "Write `export default defineComments({ authorize })` in server/comments.ts.";
294
+ };
295
+ readonly COMMENTS_B0003: {
296
+ readonly why: "comments() from @vite-hub/comments/vite is for apps without vitehub(). In this app vitehub() owns the Comments configuration.";
297
+ readonly fix: "Remove comments() from the plugins and set vitehub({ comments: true }), or add server/comments.ts. See https://vitehub.dev/docs/comments/configure#turn-comments-on-in-a-vitehub-app";
298
+ };
299
+ readonly COMMENTS_B0004: {
300
+ readonly why: ({ file }: {
301
+ file: string;
302
+ }) => string;
303
+ readonly fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database.";
304
+ };
305
+ readonly COMMENTS_DATABASE_TOKEN_IN_BUILD: {
306
+ readonly why: "The `database` option of `comments()` has an `authToken` in its URL, so the token ends up in the build output.";
307
+ readonly fix: "Put the URL with its token in a variable, and pass the variable: `comments({ database: \"env:COMMENTS_DATABASE_URL\" })`.";
308
+ };
309
+ readonly COMMENTS_GITHUB_CREDENTIALS_MISSING: {
310
+ readonly why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.";
311
+ readonly fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`.";
312
+ };
313
+ readonly COMMENTS_GITHUB_REQUEST_FAILED: {
314
+ readonly why: ({ path, status }: {
315
+ path: string;
316
+ status: number;
317
+ }) => string;
318
+ readonly fix: "Sign in with GitHub again, because a status of 401 means that the token expired. For other statuses, check that the GitHub OAuth app of the Comments login is active and that GitHub is reachable.";
319
+ };
320
+ readonly COMMENTS_GITHUB_SYNC_FAILED: {
321
+ readonly why: ({ reason, request, status }: {
322
+ reason: string;
323
+ request: string;
324
+ status: number;
325
+ }) => string;
326
+ readonly fix: "Check that the GitHub App or `VITEHUB_GITHUB_TOKEN` can write pull request comments in the repository. A retry helps for a 5xx status.";
327
+ };
328
+ readonly COMMENTS_GUEST_RATE_LIMITED: {
329
+ readonly why: ({ retryAfter }: {
330
+ retryAfter: number | undefined;
331
+ }) => string;
332
+ readonly fix: "Wait, then try again. Sign in to write without the guest limit of defineComments({ rateLimit }).";
333
+ };
334
+ readonly COMMENTS_MIGRATION_DATABASE_UNSUPPORTED: {
335
+ readonly why: ({ dialect }: {
336
+ dialect: "postgresql" | "sqlite";
337
+ }) => "[vitehub] migrateComments() needs a Postgres Drizzle database with transaction()." | "[vitehub] migrateComments() needs a Drizzle database with batch() or transaction(), so a failure changes nothing.";
338
+ readonly fix: "Pass `migrateComments()` the Drizzle database of `useDatabase()`, or of another driver with `transaction()` on Postgres, or `batch()` or `transaction()` on SQLite.";
339
+ };
340
+ readonly COMMENTS_MIGRATION_LIVE_POSTGRES: {
341
+ readonly why: "[vitehub] The live-site comments model had no Postgres tables, so there is nothing to move.";
342
+ readonly fix: "Use `from: \"outdated\"` for a Postgres Database. Only SQLite, libSQL, and D1 have tables of the live-site model.";
343
+ };
344
+ readonly COMMENTS_RATE_LIMIT_INVALID: {
345
+ readonly why: ({ issue }: {
346
+ issue: string;
347
+ }) => string;
348
+ readonly fix: "Pass rateLimit as { limit, window }, such as { limit: 5, window: \"1m\" }, or remove it to let guests write without a limit.";
349
+ };
350
+ readonly COMMENTS_RESOLVE_INTERRUPTED: {
351
+ readonly why: ({ completed, threadId, replied }: {
352
+ completed: string[];
353
+ threadId: string;
354
+ replied: boolean;
355
+ }) => string;
356
+ readonly fix: "Read the affected thread again and resolve the remaining threads.";
357
+ };
358
+ readonly COMMENTS_SECRET_TOO_SHORT: {
359
+ readonly why: ({ minimum }: {
360
+ minimum: number;
361
+ }) => string;
362
+ readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
363
+ };
364
+ readonly COMMENTS_SEND_POSTGRES: {
365
+ readonly why: "`defineComments({ send })` keeps its sends in SQLite tables, and this app keeps comments in Postgres.";
366
+ readonly fix: "Keep comments in a SQLite, libSQL, or D1 Database, or remove `send` from `defineComments()`.";
367
+ };
368
+ readonly COMMENTS_SEND_TABLES_MISSING: {
369
+ readonly why: ({ missing }: {
370
+ missing: string;
371
+ }) => string;
372
+ readonly fix: "Run `vitehub database generate` and `vitehub database migrate`. `vite dev` applies the migration for you.";
373
+ };
374
+ readonly COMMENTS_SEND_WEBHOOKS_OFF: {
375
+ readonly why: ({ file }: {
376
+ file: string;
377
+ }) => string;
378
+ readonly fix: "Use Comments through `vitehub()`, which adds Webhooks, and install `@vite-hub/webhooks` when you use the packages one by one. `comments()` without `vite-hub` has no Send.";
379
+ };
380
+ readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
381
+ why: string;
382
+ fix: string;
383
+ };
384
+ readonly COMMENTS_OUTBOX_SENDING: {
385
+ why: string;
386
+ fix: string;
387
+ };
388
+ readonly COMMENTS_R0001: {
389
+ why: ({ target }: {
390
+ target: string;
391
+ }) => string;
392
+ fix: string;
393
+ };
394
+ readonly COMMENTS_R0013: {
395
+ why: string;
396
+ fix: string;
397
+ };
398
+ readonly COMMENTS_R0015: {
399
+ why: string;
400
+ fix: string;
401
+ };
402
+ }, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
403
+ //#endregion
404
+ //#region src/client-send.d.ts
405
+ /** The logo that a Send segment shows for an agent. `@vite-hub/ui` draws each one. */
406
+ type CommentSendLogo = "t3" | "claude" | "codex";
407
+ /** The agent that gets a member's comments. */
408
+ interface CommentSendAgent {
409
+ /** Its name, such as `T3 Code`. */
410
+ name: string;
411
+ logo: CommentSendLogo;
412
+ /** The host that deliveries go to, such as `relay.t3.codes`. An inbox has none: the agent picks the comments up itself. */
413
+ host?: string;
414
+ }
415
+ /** What the server knows about the member's Send now. */
416
+ interface CommentSendStatus {
417
+ /** The open threads that wait for an answer and that no send has carried yet. */
418
+ count: number;
419
+ /** The member's agent. Without one, Send pairs an agent first. */
420
+ agent?: CommentSendAgent;
421
+ /** The member's last send, while the agent works on it. `thread` is the URL of the agent's thread. */
422
+ working?: {
423
+ id: string;
424
+ thread?: string;
425
+ };
426
+ /** The last delivery is still being attempted. */
427
+ pending?: boolean;
428
+ /** While the member may not send, the time in ms when the next send may go. */
429
+ retryAt?: number;
430
+ /** Names the `count` waiting threads and their last messages. Allow sends only the threads that it names. */
431
+ selection?: string;
432
+ }
433
+ /** A new setup code. The member pastes `prompt` in the agent's thread, and the agent pairs with `code`. */
434
+ interface CommentSendPairing {
435
+ code: string;
436
+ /** The setup prompt, with the code in it. */
437
+ prompt: string;
438
+ /** The time in ms when the code stops working. */
439
+ expiresAt: number;
440
+ /** The agent that the prompt is for. `host` is the only host its URL may have. */
441
+ agent: CommentSendAgent;
442
+ /** The threads that wait now, which Allow sends, and the selection that names them. */
443
+ count: number;
444
+ selection: string;
445
+ }
446
+ /** Where a setup code is: not used yet, used by an agent that waits for Allow, too old, or used with a URL on another host. */
447
+ type CommentSendPairingCheck = {
448
+ status: "waiting";
449
+ } | {
450
+ status: "paired";
451
+ agent: CommentSendAgent;
452
+ } | {
453
+ status: "expired";
454
+ } | {
455
+ status: "refused";
456
+ };
457
+ /**
458
+ * The answer to a send: delivered, not delivered, or refused until `retryAt`. Allow answers `changed` when the waiting
459
+ * threads are not the ones that the member confirmed, and keeps the code for the new `count`.
460
+ */
461
+ type CommentSendResult = {
462
+ status: "sent" | "pending";
463
+ id: string;
464
+ thread?: string;
465
+ } | {
466
+ status: "failed";
467
+ reason: string;
468
+ } | {
469
+ status: "limited";
470
+ retryAt: number;
471
+ } | {
472
+ status: "changed";
473
+ count: number;
474
+ selection: string;
475
+ };
476
+ /** What the server pushes: the agent started on a send, finished it, or the number of waiting threads changed. */
477
+ type CommentSendEvent = {
478
+ type: "working";
479
+ id: string;
480
+ thread?: string;
481
+ } | {
482
+ type: "done";
483
+ id: string;
484
+ } | {
485
+ type: "count";
486
+ count: number;
487
+ };
488
+ /** How a Send segment talks to the server. Comments `send: true` gives one over HTTP. */
489
+ interface CommentSendTransport {
490
+ status: () => Promise<CommentSendStatus>;
491
+ startPairing: () => Promise<CommentSendPairing>;
492
+ pollPairing: (code: string) => Promise<CommentSendPairingCheck>;
493
+ /** Pairs the agent that used `code` and sends the waiting threads that `selection` names to it. */
494
+ allow: (code: string, selection: string) => Promise<CommentSendResult>;
495
+ /** Drops `code`, so no agent can use it. */
496
+ cancel: (code: string) => Promise<void>;
497
+ send: () => Promise<CommentSendResult>;
498
+ /** Pushes events, and returns a function that stops them. Without it, the client asks `status()` while the agent works. */
499
+ subscribe?: (listener: (event: CommentSendEvent) => void) => () => void;
500
+ }
501
+ /** What the Send segment shows. Every state has the number of waiting threads, `count`. */
502
+ type CommentSendState = {
503
+ status: "idle";
504
+ count: number;
505
+ inbox: boolean;
506
+ canPairAnother?: true;
507
+ } | {
508
+ status: "pairing";
509
+ count: number;
510
+ prompt: string;
511
+ expiresAt: number;
512
+ agent: CommentSendAgent;
513
+ reason?: "expired" | "refused";
514
+ } | {
515
+ status: "confirm";
516
+ count: number;
517
+ agent: CommentSendAgent;
518
+ } | {
519
+ status: "sending";
520
+ count: number;
521
+ } | {
522
+ status: "sent";
523
+ count: number;
524
+ inbox: boolean;
525
+ } | {
526
+ status: "working";
527
+ count: number;
528
+ agent?: CommentSendAgent;
529
+ thread?: string;
530
+ } | {
531
+ status: "failed";
532
+ count: number;
533
+ reason: string;
534
+ } | {
535
+ status: "limited";
536
+ count: number;
537
+ retryAt: number;
538
+ };
539
+ /** Writes the setup prompt to the clipboard once it loads. Resolves to `false` when the browser refuses. */
540
+ type CommentSendCopy = (prompt: Promise<string>) => Promise<boolean>;
541
+ interface CommentSendOptions {
542
+ /** How often, in ms, the client asks whether an agent used the setup code. Default 1500. */
543
+ pairingInterval?: number;
544
+ /** How often, in ms, the client asks `status()` while the agent works and the transport cannot push. Default 5000. */
545
+ statusInterval?: number;
546
+ /** How long, in ms, Sent shows before Working. Default 2000. */
547
+ sentFor?: number;
548
+ }
549
+ interface CommentSendClient {
550
+ readonly state: CommentSendState;
551
+ /** Calls `listener` after every change of `state`. Returns a function that stops it. */
552
+ onChange: (listener: () => void) => () => void;
553
+ /** Loads the status, then follows the agent: pushed events, or `status()` while it works. Returns a function that stops it. */
554
+ start: () => () => void;
555
+ /** Loads the status again, such as after the member wrote a comment. */
556
+ refresh: () => Promise<void>;
557
+ /**
558
+ * Send N, and Retry after Not delivered. Without an agent, it gets a setup code, gives its prompt to `copy`, and waits
559
+ * for an agent to use the code.
560
+ */
561
+ send: (copy?: CommentSendCopy) => Promise<void>;
562
+ /** Starts a new pairing without changing where the regular Send button sends. */
563
+ pairAnother: (copy?: CommentSendCopy) => Promise<void>;
564
+ /** Allow and send N: pairs the agent that used the code and sends to it. */
565
+ allow: () => Promise<void>;
566
+ /** Copy again, after the code expired or the agent used a URL on another host. */
567
+ copyAgain: (copy?: CommentSendCopy) => Promise<void>;
568
+ /** × or Escape while pairing: drops the code and goes back to Send N. */
569
+ cancel: () => void;
570
+ }
571
+ /**
572
+ * The Send segment of a comment pill, without a framework: it hands the member's waiting threads to their agent, and
573
+ * pairs one in place first when there is none. `CommentSend` of `@vite-hub/ui` renders it.
574
+ */
575
+ export declare function createCommentSend(transport: CommentSendTransport, options?: CommentSendOptions): CommentSendClient;
73
576
  //#endregion
74
577
  //#region src/rest-transport.d.ts
75
578
  /** A guest that named itself in the browser. The server keeps the name as display data only. */
@@ -80,7 +583,7 @@ interface CommentsGuest {
80
583
  interface RestTransportOptions {
81
584
  /**
82
585
  * The app origin and mount, such as `https://app.example.com` or `/portal`. The routes are
83
- * `<base>/api/_vitehub/comments/**`. Default: the page origin.
586
+ * `<base>/_vitehub/comments/**`. Default: the page origin.
84
587
  */
85
588
  base?: string;
86
589
  /**
@@ -114,10 +617,10 @@ interface CommentsRestAnswer<T> {
114
617
  }
115
618
  /** The request function of the Comments API that the overlay and `createRestTransport()` share. */
116
619
  type CommentsRestRequest = <T>(path: string, init?: RequestInit) => Promise<CommentsRestAnswer<T>>;
117
- /** The URL of an attachment key below the Comments API, such as `/api/_vitehub/comments/attachments/comments/<id>/shot.png`. */
620
+ /** The URL of an attachment key below the Comments API, such as `/_vitehub/comments/attachments/comments/<id>/shot.png`. */
118
621
  export declare function commentAttachmentUrl(key: string, base?: string): string;
119
622
  /**
120
- * Requests to the Comments API at `<base>/api/_vitehub/comments`, with the guest headers and the session cookie. A
623
+ * Requests to the Comments API at `<base>/_vitehub/comments`, with the guest headers and the session cookie. A
121
624
  * failure throws a diagnostic with the `code`, `why`, and `fix` of the error object of the answer, and its `status`.
122
625
  */
123
626
  export declare function createCommentsRestRequest(options?: RestTransportOptions & {
@@ -130,13 +633,46 @@ interface RestTransport extends CommentsTransport {
130
633
  attachmentUrl: (key: string) => string;
131
634
  }
132
635
  /**
133
- * A transport over the Comments API at `<base>/api/_vitehub/comments`: the routes that the overlay uses. The server
636
+ * A transport over the Comments API at `<base>/_vitehub/comments`: the routes that the overlay uses. The server
134
637
  * runs the `authorize` policy of `server/comments.ts` for the user of the request: the app session, or a guest that
135
638
  * `guest` names. Guests and share-link readers can use it. It has no
136
639
  * `subscribe`: the client refreshes when the window gets focus.
137
640
  */
138
641
  export declare function createRestTransport(options?: RestTransportOptions): RestTransport;
139
642
  //#endregion
643
+ //#region src/send-transport.d.ts
644
+ interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base" | "headers" | "credentials" | "fetch"> {
645
+ /**
646
+ * The path of the page that Send is on, such as `/notes/azores`. The server turns it into the subject, as `page` of
647
+ * `defineComments()` decides. A function runs before each request, so it follows client-side navigation. Default:
648
+ * `location.pathname`.
649
+ */
650
+ page?: string | (() => string);
651
+ }
652
+ /**
653
+ * The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
654
+ * ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
655
+ *
656
+ * ```ts
657
+ * import { createCommentSend, createCommentSendTransport } from "@vite-hub/comments/client"
658
+ *
659
+ * const send = createCommentSend(createCommentSendTransport({ page: () => location.pathname }))
660
+ * ```
661
+ */
662
+ export declare function createCommentSendTransport(options?: CommentSendTransportOptions): CommentSendTransport;
663
+ //#endregion
664
+ //#region src/fold-name.d.ts
665
+ /** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
666
+ export declare function foldName(text: string): string;
667
+ //#endregion
668
+ //#region src/reply-id.d.ts
669
+ /**
670
+ * The id of the message that a reply with `requestId` stores in a thread. Every retry gets the same id, so the primary
671
+ * key of the messages refuses a second message, and the client's outbox finds the server copy of its waiting reply.
672
+ * The server and the browser client both import it, so it has no other import.
673
+ */
674
+ export declare function replyMessageId(threadId: string, requestId: string): Promise<string>;
675
+ //#endregion
140
676
  //#region src/client.d.ts
141
677
  export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
142
678
  export interface CommentsClientOptions {
@@ -147,6 +683,11 @@ export interface CommentsClientOptions {
147
683
  query?: CommentListQuery;
148
684
  /** Refresh when the window gets focus and the transport cannot push updates. Default `true`. */
149
685
  refreshOnFocus?: boolean;
686
+ /**
687
+ * Saves each new comment and reply before it sends, so it shows at once, survives a reload, and goes out once when
688
+ * the network is back. Off by default: `create` and `reply` wait for the server.
689
+ */
690
+ outbox?: CommentsOutboxOptions;
150
691
  }
151
692
  export interface CommentsClient {
152
693
  readonly transport: CommentsTransport;
@@ -158,8 +699,10 @@ export interface CommentsClient {
158
699
  query: CommentListQuery;
159
700
  refresh: () => Promise<readonly CommentThread[]>;
160
701
  get: (input: CommentGetInput) => Promise<CommentThread | null>;
161
- create: (input: CommentCreateInput) => Promise<CommentThread>;
162
- reply: (input: CommentReplyInput) => Promise<CommentThread>;
702
+ /** With an outbox, returns the waiting thread once it is saved, with a local `id` and `delivery`. */
703
+ create: (input: CommentCreateInput & CommentFiles) => Promise<CommentThread>;
704
+ /** With an outbox, returns a thread view with the waiting reply once it is saved. */
705
+ reply: (input: CommentReplyInput & CommentFiles) => Promise<CommentThread>;
163
706
  edit: (input: CommentEditInput) => Promise<CommentThread>;
164
707
  delete: (input: CommentDeleteInput) => Promise<CommentThread | null>;
165
708
  resolve: (input: CommentStatusInput) => Promise<CommentThread>;
@@ -167,10 +710,21 @@ export interface CommentsClient {
167
710
  users: (input: CommentUsersInput) => Promise<CommentUser[]>;
168
711
  /** Calls `listener` after every change of `threads`, `status`, or `error`. Returns a function that stops it. */
169
712
  onChange: (listener: () => void) => () => void;
170
- /** Loads the threads, then keeps them fresh: pushed events when the transport has `subscribe`, else a refresh on window focus. Returns a function that stops it. */
713
+ /**
714
+ * Loads the threads, then keeps them fresh: pushed events when the transport has `subscribe`, else a refresh on window
715
+ * focus. With an outbox, it also sends what an earlier page saved, and tries again when the page is back online.
716
+ * Returns a function that stops it.
717
+ */
171
718
  start: () => () => void;
719
+ /** The saved comments and replies that have not gone out. Only with the `outbox` option. */
720
+ readonly outbox: CommentsOutbox | undefined;
172
721
  }
173
722
  /** A cache and a change signal over a transport. It has no framework in it. */
723
+ export declare function createCommentsClient(options: CommentsClientOptions & {
724
+ outbox: CommentsOutboxOptions;
725
+ }): CommentsClient & {
726
+ readonly outbox: CommentsOutbox;
727
+ };
174
728
  export declare function createCommentsClient(options: CommentsClientOptions): CommentsClient;
175
729
  //#endregion
176
- export { type AnchorPoint, type AnchorPosition, type AnchorRect, type AnchorTarget, type AreaAnchor, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentEditInput, type CommentEvent, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMessage, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, type CommentsGuest, type CommentsRestAnswer, type CommentsRestRequest, type CommentsTransport, type CreateAnchorOptions, type DetachedAnchor, type ElementAnchor, type ImageAnchor, type PageAnchor, type ResolvedAnchor, type RestCommentThread, type RestTransport, type RestTransportOptions, type TextAnchor, commentsErrorDiagnostics };
730
+ export type { AnchorPoint, AnchorPosition, AnchorRect, AnchorTarget, AreaAnchor, CommentActor, CommentAnchor, CommentAttachment, CommentBuild, CommentComponent, CommentContext, CommentCreateInput, CommentDeleteInput, CommentDelivery, CommentDeliveryError, CommentEditInput, CommentEvent, CommentFiles, CommentForgeLink, CommentGetInput, CommentListCursor, CommentListQuery, CommentMessage, CommentMetadata, CommentReplyInput, CommentSendAgent, CommentSendClient, CommentSendCopy, CommentSendEvent, CommentSendLogo, CommentSendOptions, CommentSendPairing, CommentSendPairingCheck, CommentSendResult, CommentSendState, CommentSendStatus, CommentSendTransport, CommentSendTransportOptions, CommentStatus, CommentStatusInput, CommentSubject, CommentThread, CommentUploadInput, CommentUser, CommentUsersInput, CommentsGuest, CommentsOutbox, CommentsOutboxEntry, CommentsOutboxEnvironment, CommentsOutboxMessage, CommentsOutboxOptions, CommentsOutboxStore, CommentsRestAnswer, CommentsRestRequest, CommentsTransport, CreateAnchorOptions, DetachedAnchor, ElementAnchor, ImageAnchor, PageAnchor, ResolvedAnchor, RestCommentThread, RestTransport, RestTransportOptions, TextAnchor };