@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
package/README.md CHANGED
@@ -41,13 +41,13 @@ export const comments = defineComments({
41
41
 
42
42
  Without the file, `vitehub({ comments: true })` turns Comments on with `defineComments()`, and so does an object such as `{ database: "team" }`. The Console does not turn it on. `comments: false` turns it off. Docs sites of `@vite-hub/docs` on `vite-hub/nuxt` set it by default; `docs: { comments: false }` turns it off.
43
43
 
44
- ViteHub then adds the `vitehub_comment_threads`, `vitehub_comment_messages`, `vitehub_comment_counters`, and `vitehub_comment_forge` tables to the default Database (or the only one, or `defineComments({ database: "name" })`; without a Database Definition, the implicit `default` Database of `@vite-hub/database`), serves `/_vitehub/comments/**`, and adds a Comments section to the Console. Apply the tables with `vitehub database generate` and `vitehub database migrate`.
44
+ ViteHub then adds the `vitehub_comment_threads`, `vitehub_comment_messages`, `vitehub_comment_counters`, and `vitehub_comment_forge` tables to the default Database (or the only one, or `defineComments({ database: "name" })`; without a Database Definition, the implicit `default` Database of `@vite-hub/database`), serves `/_vitehub/comments/**`, and adds a Comments section to the Console. Apply the tables with `vitehub database generate` and `vitehub database migrate`. A production build fails with `DATABASE_CONTRIBUTED_TABLES_NOT_GENERATED` while the migrations lack a Comments table or column, such as one that a new version of Comments added.
45
45
 
46
46
  A ViteHub Database with the tables of the earlier live-site model must move them once in a migration: see [Upgrade to one model](https://vitehub.dev/docs/comments/configure#upgrade-to-one-model). Until then every Comments request fails with `COMMENTS_R0019`, whose `fix` names `commentsMigrationSql({ from: "live" })`. `migrateComments(db)` from `@vite-hub/comments/database` moves them in place and keeps the old tables as a backup.
47
47
 
48
- Comments is a ViteHub page tool. Open any page with `?vitehub`, or `?vitehub=comments`. The server adds the page tools loader to that page. The loader calls `GET /_vitehub/page/session`, which allows Comments when `authorize` allows `read` or offers GitHub sign-in or account switching, and sets the `vitehub-tools` cookie so later pages open in comment mode too. The loader then draws the ViteHub tools pill at the bottom of the page and imports the overlay. The overlay draws its toolbar in its segment of the pill, and its pins, cursors, and cards in `<vitehub-comments>`. The pill's **×** button turns the page tools off, so the toolbar has no close button of its own. A small ViteHub hexagon then stays at the pill's place, on every page, and pressing it turns them on again. The cookie is a hint, never a credential: every Comments route checks `authorize` again. A request without the hint gets the page with a short inline bootstrap that loads the loader in the browser only when the hint is there, so prerendered pages that a host serves as static files work too. Opening the Console calls the same session route, so the Console's people see the toolbar on the app's pages. The session route and the loader do not need the Console.
48
+ Comments is a ViteHub page tool. Open any page with `?vitehub`, or `?vitehub=comments`. The server adds the page tools loader to that page. The loader calls `GET /_vitehub/page/tools`, which allows Comments when `authorize` allows `read` or offers GitHub sign-in or account switching, and sets the `vitehub-tools` cookie so later pages open in comment mode too. The loader then draws the ViteHub tools pill at the bottom of the page and imports the overlay. The overlay draws its toolbar in its segment of the pill, and its pins, cursors, and cards in `<vitehub-comments>`. The pill's **×** button turns the page tools off, so the toolbar has no close button of its own. A small ViteHub hexagon then stays at the pill's place, on every page, and pressing it turns them on again. The cookie is a hint, never a credential: every Comments route checks `authorize` again. A request without the hint gets the page with a short inline bootstrap that loads the loader in the browser only when the hint is there, so prerendered pages that a host serves as static files work too. Opening the Console calls the same session route, so the Console's people see the toolbar on the app's pages. The session route and the loader do not need the Console.
49
49
 
50
- A single page app whose `index.html` Vite serves or builds gets a short inline check in that file. It imports the loader in the browser when the page has the query or the cookie, so a built `index.html` that a host serves as a static file also gets the tools. When the app has a Vite `base` or a Nuxt `app.baseURL`, such as `/docs/`, every path follows it: `/docs/_vitehub/page/session`, `/docs/_vitehub/page/assets/loader.js`, and `/docs/_vitehub/comments/**`. The loader and the overlay find the base from their own URL, including the overlay's Realtime presence and live update connections.
50
+ A single page app whose `index.html` Vite serves or builds gets a short inline check in that file. It imports the loader in the browser when the page has the query or the cookie, so a built `index.html` that a host serves as a static file also gets the tools. When the app has a Vite `base` or a Nuxt `app.baseURL`, such as `/docs/`, every path follows it: `/docs/_vitehub/page/tools`, `/docs/_vitehub/page/assets/loader.js`, and `/docs/_vitehub/comments/**`. The loader and the overlay find the base from their own URL, including the overlay's Realtime presence and live update connections.
51
51
 
52
52
  Custom `identify` names the user of every surface, and `authorize` decides; Comments then reads neither the Auth session nor the Console's access. Without `identify`, when the app has the Console, its Comments section controls access, and opening the Console enables the toolbar on the app's pages. Otherwise Comments reads the Auth session.
53
53
 
@@ -108,12 +108,20 @@ await comments.resolve(threadId, { by: { id: "agent", name: "Docs Agent" } })
108
108
 
109
109
  On a preview, `forge: { provider: "github" }` posts each thread to the pull request that the build previews: one summary comment that lists every thread, then one comment per comment, with the page, the element, the components, and the browser. Resolving a thread hides its comment. It posts with the GitHub App of `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY`, or as each person: people who signed in with GitHub post as themselves, and `token(author)` returns the token for any other sign-in. Each thread's `forge` field says whether it posted.
110
110
 
111
+ ## Failures in logs
112
+
113
+ A failure in `onComment`, `onMention`, or the pull request sync never fails the comment. With the evlog Nitro module registered, Comments logs it with `comments: { hook, step?, thread, code }`: a failed `onComment` on the wide event of the request, the others as their own evlog events. Without evlog, they go to the console. See [Limits and errors](https://vitehub.dev/docs/comments/limits-and-errors#see-hook-and-sync-failures-in-logs).
114
+
115
+ ## Send to an agent
116
+
117
+ `defineComments({ send: true })` adds **Send N** to the comment pill: one click hands the open threads of the page that wait for an answer to the person's own agent, such as a T3 Code thread. The first press copies a setup prompt; the agent creates a T3 webhook task and pairs it with the one-use code, and the pill asks once to allow it. Each send is a signed `POST` with the thread ids and a read token for 24 hours, through the member endpoints of `@vite-hub/webhooks`. `send: { grant: false }` leaves the token out, for an app that reads through its own MCP server, and `payload` adds fields, and `prompt` changes the setup prompt. Each member has their own count, and Allow sends only the threads the member saw. The `comments_get_send` MCP tool reads a send, and `comments.listSends(user)` and `comments.readSend(user, id)` read sends on the server. Reopening a thread can restore a done inbox send or let the member send it to a webhook agent again. Send needs a ViteHub app with a SQLite Database. See [Send comments to your agent](https://vitehub.dev/docs/comments/send).
118
+
111
119
  ## Deployment and security boundaries
112
120
 
113
121
  - Threads live only in the Database. Presence rooms hold no document, and connections are read-only. The server binds each person's presence to the user that `identify` or the Auth session resolves.
114
122
  - Pins anchor to the Content field first, then a CSS path checked against the element text, then the text alone, then the page point. A pin whose element is gone shows dashed.
115
123
  - A thread change tells the other tabs of the page through the Realtime events room, and they read the threads again. Changes from the server API reach open pages when they refetch: on focus and every 30 seconds.
116
- - Without a Realtime authority, such as on Vercel, comments work without presence or cursors.
124
+ - Without a Realtime driver, such as on Vercel, comments work without presence or cursors.
117
125
  - Write routes compare `Origin` with the request origin, and honour `X-Forwarded-Proto` and `X-Forwarded-Host` from a proxy that ends TLS.
118
126
  - Page context stores only the URL origin and pathname, validated against the request origin and thread page. Query parameters, URL credentials, and fragments are discarded. Nuxt component files come from its resolved component registry.
119
127
  - Guests can comment only when `authorize` allows `user: null`. They name themselves in the browser, and their names and IDs are display data only. Guests cannot delete comments or threads. `defineComments({ rateLimit: { limit: 5, window: "1m" } })` limits the writes of each guest address.
@@ -124,7 +132,7 @@ On a preview, `forge: { provider: "github" }` posts each thread to the pull requ
124
132
  | Import | Purpose |
125
133
  | --- | --- |
126
134
  | `@vite-hub/comments` | `defineComments()` and types. `installComments()` is in `@vite-hub/comments/server`. |
127
- | `@vite-hub/comments/client` | Framework-free client, transport types, `createAnchor()`, and `resolveAnchor()`. |
135
+ | `@vite-hub/comments/client` | Framework-free client, transport types, `createAnchor()`, `resolveAnchor()`, and `createCommentSend()`, the state of the Send segment that hands a member's waiting comments to their agent. |
128
136
  | `@vite-hub/comments/testing` | In-memory client transport for tests and examples. |
129
137
  | `@vite-hub/comments/anchor` | DOM anchoring: `createAnchor()`, `placeAnchor()`, `selectorOf()`, `labelOf()`. |
130
138
  | `@vite-hub/comments/database` | `commentsSchema`, the Drizzle tables, and `commentsTables`, the statements that create them. |
@@ -151,7 +159,7 @@ const response = await handler.fetch(new Request("https://site.test/_vitehub/com
151
159
 
152
160
  - [Comments](https://vitehub.dev/docs/comments) covers access, guests, mentions, hosts, and errors.
153
161
  - [Content](https://vitehub.dev/docs/content) covers collections, drafts, and publishing.
154
- - [Realtime](https://vitehub.dev/docs/realtime) covers room authorities.
162
+ - [Realtime](https://vitehub.dev/docs/realtime) covers room drivers.
155
163
 
156
164
  ### Floating window
157
165
 
@@ -257,7 +265,7 @@ import type { CommentCreateInput, CommentDeleteInput, CommentEditInput, CommentE
257
265
  interface CommentsTransport {
258
266
  supportsAttachments?: boolean; // Defaults to true for custom transports.
259
267
  list(query: CommentListQuery): Promise<CommentThread[]>;
260
- get(input: CommentGetInput): Promise<CommentThread | null>; // { id } or { scope, n }
268
+ get(input: CommentGetInput): Promise<CommentThread | null>; // { threadId } or { scope, n }
261
269
  create(input: CommentCreateInput & CommentFiles): Promise<CommentThread>; // `files` to store before the comment
262
270
  reply(input: CommentReplyInput & CommentFiles): Promise<CommentThread>; // and `subject` of the thread, for the upload
263
271
  edit(input: CommentEditInput): Promise<CommentThread>;
@@ -288,6 +296,10 @@ const client = createCommentsClient({ transport, user: ana });
288
296
 
289
297
  `transport.as(user)` gives another person on the same store, and `transport.reconnect()` sends `reconnected` to the listeners.
290
298
 
299
+ ### Send
300
+
301
+ `createCommentSend(transport)` is the state of the **Send** segment of a comment pill, without a framework. Its states are `idle`, `pairing`, `confirm`, `sending`, `sent`, `working`, `failed`, and `limited`. `send.state` holds the state and its data, and `send.onChange()` reports each change. The transport has `status()`, `startPairing()`, `pollPairing(code)`, `allow(code, selection)`, `cancel(code)`, `send()`, and an optional `subscribe()`. `CommentSend` of `@vite-hub/ui` renders it. `createCommentSendTransport({ page })` is the transport over the Send routes of `send: true`. See [Send to an agent](https://vitehub.dev/docs/ui/comments#send-to-an-agent).
302
+
291
303
  ## Errors
292
304
 
293
305
  Errors have a stable code, a `why`, and a `fix`.
package/dist/anchor.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as ElementAnchor } from "./types-C7LzhgRb.js";
2
- import "./types-C1qzObs2.js";
1
+ import { A as ElementAnchor } from "./types-BLaYh0_f.js";
2
+ import "./types-C35INXIs.js";
3
3
  //#region src/anchor.d.ts
4
4
  /** The anchor of a pin that the overlay drops: an element anchor with every hint that `placeAnchor()` uses. */
5
5
  export type PinAnchor = ElementAnchor & Required<Pick<ElementAnchor, "label" | "page" | "viewport">>;
package/dist/client.d.ts CHANGED
@@ -1,5 +1,4 @@
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-C7LzhgRb.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-BEChnUo7.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";
3
2
  //#region ../internal/src/browser-environment.d.ts
4
3
  /** A page event that a client store reacts to. */
5
4
  type BrowserEvent = "online" | "offline" | "visible" | "hidden";
@@ -182,17 +181,398 @@ export declare function anchorRange(anchor: TextAnchor, root?: ParentNode): Rang
182
181
  */
183
182
  export declare function resolveAnchor(anchor: CommentAnchor, root?: ParentNode): AnchorPosition;
184
183
  //#endregion
185
- //#region src/fold-name.d.ts
186
- /** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
187
- 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>;
188
403
  //#endregion
189
- //#region src/reply-id.d.ts
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
+ };
190
457
  /**
191
- * The id of the message that a reply with `requestId` stores in a thread. Every retry gets the same id, so the primary
192
- * key of the messages refuses a second message, and the client's outbox finds the server copy of its waiting reply.
193
- * The server and the browser client both import it, so it has no other import.
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`.
194
460
  */
195
- export declare function replyMessageId(threadId: string, requestId: string): Promise<string>;
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;
196
576
  //#endregion
197
577
  //#region src/rest-transport.d.ts
198
578
  /** A guest that named itself in the browser. The server keeps the name as display data only. */
@@ -260,6 +640,39 @@ interface RestTransport extends CommentsTransport {
260
640
  */
261
641
  export declare function createRestTransport(options?: RestTransportOptions): RestTransport;
262
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
263
676
  //#region src/client.d.ts
264
677
  export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
265
678
  export interface CommentsClientOptions {
@@ -314,4 +727,4 @@ export declare function createCommentsClient(options: CommentsClientOptions & {
314
727
  };
315
728
  export declare function createCommentsClient(options: CommentsClientOptions): CommentsClient;
316
729
  //#endregion
317
- 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 CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, 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 CommentsOutbox, type CommentsOutboxEntry, type CommentsOutboxEnvironment, type CommentsOutboxMessage, type CommentsOutboxOptions, type CommentsOutboxStore, 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 };