@vite-hub/comments 0.5.0 → 0.6.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 (85) hide show
  1. package/README.md +7 -1
  2. package/dist/anchor.d.ts +3 -5
  3. package/dist/anchor.js +1 -2
  4. package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
  5. package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
  6. package/dist/client.d.ts +44 -25
  7. package/dist/client.js +64 -43
  8. package/dist/{console-D1lwNMZn.d.ts → console-CCLX_eIk.d.ts} +1 -5
  9. package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
  10. package/dist/database/postgres.d.ts +1 -3
  11. package/dist/database/postgres.js +1 -2
  12. package/dist/{database-6hXRnqDE.js → database-BkPoOdZr.js} +73 -61
  13. package/dist/{database-CTo7mx6t.d.ts → database-CPua6Q6_.d.ts} +0 -2
  14. package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
  15. package/dist/database.d.ts +4 -6
  16. package/dist/database.js +1 -2
  17. package/dist/{define-CmIFU96x.d.ts → define-B1jLSPe9.d.ts} +1 -3
  18. package/dist/{define-BMBSVbD9.js → define-BCxNaSZv.js} +3 -4
  19. package/dist/{errors-BJTZ9iyv.js → errors-C0VwRHiy.js} +1 -2
  20. package/dist/{errors-Dq4AHjza.js → errors-DFNiJg67.js} +10 -3
  21. package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
  22. package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
  23. package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
  24. package/dist/hosted/hosted-comments/frame.js +1 -0
  25. package/dist/hosted/hosted-comments/overlay-CFuq5QAH.js +182 -0
  26. package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
  27. package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
  28. package/dist/hosted/hosted-comments/tools-Bz--joZw.js +126 -0
  29. package/dist/hosted/hosted-comments.js +9 -0
  30. package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
  31. package/dist/{index-RiHzmV16.d.ts → index-D1T7RJ4R.d.ts} +10 -15
  32. package/dist/index.d.ts +5 -5
  33. package/dist/index.js +8 -9
  34. package/dist/{install-BGGQKbQ4.d.ts → install-NehuMNhG.d.ts} +19 -8
  35. package/dist/{install-DrAse1Fa.js → install-w6CCgGFV.js} +158 -45
  36. package/dist/{installed-C3EoqJEY.js → installed-C9SkldMi.js} +2 -3
  37. package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
  38. package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
  39. package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
  40. package/dist/{operations-VyyNZusz.d.ts → operations-8hqTi0DH.d.ts} +0 -2
  41. package/dist/{operations-lsVKE0GH.js → operations-B8IMhRmY.js} +18 -20
  42. package/dist/{operations-BKhUWYkb.d.ts → operations-Cic9A9e_.d.ts} +4 -6
  43. package/dist/operations.d.ts +2 -2
  44. package/dist/operations.js +2 -2
  45. package/dist/overlay/{client-DBmJ4C1M.js → client-CerbVjTz.js} +3 -3
  46. package/dist/overlay/dist-DyVmH21U.js +14 -0
  47. package/dist/overlay/overlay.js +28 -16
  48. package/dist/page/loader.js +22 -21
  49. package/dist/{page-Bzj0CszG.d.ts → page-DE71P_gQ.d.ts} +0 -2
  50. package/dist/{page-tools-shared-BNnuPK93.js → page-tools-shared-fvmJQCrP.js} +2 -2
  51. package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
  52. package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
  53. package/dist/{plugin-DRsNaJaK.js → plugin-DbCYT7Ac.js} +14 -11
  54. package/dist/realtime.d.ts +3 -5
  55. package/dist/realtime.js +4 -5
  56. package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
  57. package/dist/{request-log-Dj9Vw7qG.js → request-log-DllKQXj7.js} +1 -2
  58. package/dist/{request-origin-CFU0TQ7E.js → request-origin-YPzfE2eh.js} +1 -2
  59. package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
  60. package/dist/{rpc-CuJ5GLIz.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
  61. package/dist/rpc.d.ts +1 -1
  62. package/dist/rpc.js +1 -2
  63. package/dist/runtime/auth.d.ts +3 -5
  64. package/dist/runtime/auth.js +2 -3
  65. package/dist/runtime/console.d.ts +2 -4
  66. package/dist/runtime/console.js +4 -5
  67. package/dist/runtime/index.d.ts +45 -32
  68. package/dist/runtime/index.js +27 -26
  69. package/dist/{server-Yk610niJ.js → server-BGbD7H5s.js} +2 -3
  70. package/dist/server.d.ts +6 -8
  71. package/dist/server.js +6 -6
  72. package/dist/{service-Bj-Mg63c.d.ts → service-CPiWPoiY.d.ts} +3 -7
  73. package/dist/{service-DA5BwfPQ.js → service-DUh2uGd2.js} +9 -11
  74. package/dist/{session-DUcEor2W.d.ts → session-CN4irEqf.d.ts} +3 -5
  75. package/dist/{session-X_g9dnU5.js → session-_1GY5gaG.js} +30 -18
  76. package/dist/{store-CsUNfC1w.d.ts → store-DvNTDNgn.d.ts} +2 -4
  77. package/dist/{table-names-B9LlRC0B.js → table-names-BIHjuEFK.js} +1 -2
  78. package/dist/testing.d.ts +2 -4
  79. package/dist/testing.js +3 -4
  80. package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
  81. package/dist/{types-BLaYh0_f.d.ts → types-BX3vH18p.d.ts} +0 -2
  82. package/dist/{types-C35INXIs.d.ts → types-l6GOb_yc.d.ts} +2 -4
  83. package/dist/vite.d.ts +22 -22
  84. package/dist/vite.js +40 -45
  85. package/package.json +19 -19
package/README.md CHANGED
@@ -91,6 +91,10 @@ import { contentField } from "vite-hub/content/client"
91
91
 
92
92
  An edit reads the draft, changes one string field, and saves the document with `ifDigest`. It needs `content.can({ action: "write" })`. Publishing stays in the Content publish flow.
93
93
 
94
+ ### Add Hosted Comments
95
+
96
+ Register your site in the Console with **Hosted Comments only**, then copy the script into your page HTML. For a connected app, copy it from **Settings** > **Connection** > **Hosted Comments**. The Console signs reviewers in and stores their page threads. Confirming an unlink permanently deletes that project's hosted threads and replies.
97
+
94
98
  ## Server API
95
99
 
96
100
  Every method returns `[error, data]`.
@@ -114,6 +118,8 @@ A failure in `onComment`, `onMention`, or the pull request sync never fails the
114
118
 
115
119
  ## Send to an agent
116
120
 
121
+ A Console team member who opens the app through Site access gets **Copy prompt** when the page has open threads and the Console MCP lets them read those threads. The prompt names the linked app, its team, and the thread IDs. It includes resolution instructions only with Console MCP write access. `/session` supplies `agent: { mcp, project, resolve }`. For one click without a paste, use `send`:
122
+
117
123
  `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
124
 
119
125
  ## Deployment and security boundaries
@@ -132,7 +138,7 @@ A failure in `onComment`, `onMention`, or the pull request sync never fails the
132
138
  | Import | Purpose |
133
139
  | --- | --- |
134
140
  | `@vite-hub/comments` | `defineComments()` and types. `installComments()` is in `@vite-hub/comments/server`. |
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. |
141
+ | `@vite-hub/comments/client` | Framework-free client, transport types, `createAnchor()`, `resolveAnchor()`, `commentsAgentPrompt()`, the text of **Copy prompt**, and `createCommentSend()`, the state of the Send segment that hands a member's waiting comments to their agent. |
136
142
  | `@vite-hub/comments/testing` | In-memory client transport for tests and examples. |
137
143
  | `@vite-hub/comments/anchor` | DOM anchoring: `createAnchor()`, `placeAnchor()`, `selectorOf()`, `labelOf()`. |
138
144
  | `@vite-hub/comments/database` | `commentsSchema`, the Drizzle tables, and `commentsTables`, the statements that create them. |
package/dist/anchor.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { A as ElementAnchor } from "./types-BLaYh0_f.js";
2
- import "./types-C35INXIs.js";
3
- //#region src/anchor.d.ts
1
+ import { A as ElementAnchor } from "./types-BX3vH18p.js";
2
+ import "./types-l6GOb_yc.js";
4
3
  /** The anchor of a pin that the overlay drops: an element anchor with every hint that `placeAnchor()` uses. */
5
4
  export type PinAnchor = ElementAnchor & Required<Pick<ElementAnchor, "label" | "page" | "viewport">>;
6
5
  /** The attribute that Content's `contentField()` writes on an element that renders a field. */
@@ -39,5 +38,4 @@ export type PlacedAnchor =
39
38
  * Where an anchor is now, in client coordinates: the Content field, then the CSS path if its label still matches,
40
39
  * then any element of that tag with the same label, then the page point. An anchor without a label trusts the path.
41
40
  */
42
- export declare function placeAnchor(anchor: ElementAnchor): PlacedAnchor;
43
- //#endregion
41
+ export declare function placeAnchor(anchor: ElementAnchor): PlacedAnchor;
package/dist/anchor.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/anchor.ts
1
+ // src/anchor.ts
2
2
  /** The attribute that Content's `contentField()` writes on an element that renders a field. */
3
3
  const fieldAttribute = "data-content-field";
4
4
  const maxDepth = 10;
@@ -129,5 +129,4 @@ function placeAnchor(anchor) {
129
129
  y: page.y - window.scrollY
130
130
  };
131
131
  }
132
- //#endregion
133
132
  export { createAnchor, fieldAttribute, fieldElementOf, labelOf, placeAnchor, selectorOf };
@@ -1,5 +1,5 @@
1
1
  import { Diagnostic, defineDiagnostics } from "nostics";
2
- //#region src/client-diagnostics.ts
2
+ // src/client-diagnostics.ts
3
3
  const commentsClientCodes = {
4
4
  COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
5
5
  why: "The current author is not the author of this queued comment.",
@@ -51,5 +51,4 @@ function commentsUnansweredError(status, cause, retryAfter) {
51
51
  ...retryAfter === void 0 ? {} : { retryAfter }
52
52
  });
53
53
  }
54
- //#endregion
55
54
  export { commentsUnansweredError as i, commentsClientCodes as n, commentsClientDiagnostics as r, commentsAnswerError as t };
@@ -1,4 +1,4 @@
1
- //#region src/client-files.ts
1
+ // src/client-files.ts
2
2
  const outboxAccountHeader = "x-vitehub-comments-outbox-account";
3
3
  const failedCommentPreparation = /* @__PURE__ */ new WeakMap();
4
4
  /** The file as Base64, the form that `comments.upload` takes. */
@@ -49,5 +49,4 @@ function retryAfterOf(response, now = Date.now()) {
49
49
  const date = Date.parse(value);
50
50
  return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
51
51
  }
52
- //#endregion
53
52
  export { withCommentFiles as i, outboxAccountHeader as n, retryAfterOf as r, failedCommentPreparation as t };
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-BLaYh0_f.js";
2
- //#region ../internal/src/browser-environment.d.ts
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-BX3vH18p.js";
3
2
  /** A page event that a client store reacts to. */
4
3
  type BrowserEvent = "online" | "offline" | "visible" | "hidden";
5
4
  /** What a client store needs from the browser: page events, one sender across tabs, and messages between tabs. Tests pass a fake one. */
@@ -20,8 +19,6 @@ interface BrowserEnvironment<Message> {
20
19
  schedule: (task: () => void, ms: number) => () => void;
21
20
  random: () => number;
22
21
  }
23
- //#endregion
24
- //#region src/client-outbox.d.ts
25
22
  /** A message between the tabs of one browser. */
26
23
  type CommentsOutboxMessage = {
27
24
  type: "change";
@@ -113,8 +110,18 @@ export declare function createMemoryOutboxStore(): CommentsOutboxStore;
113
110
  * does not open, as in some private windows, it keeps the entries in memory and `persisted` is `false`.
114
111
  */
115
112
  export declare function createIndexedDBOutboxStore(): CommentsOutboxStore;
116
- //#endregion
117
- //#region src/client-anchor.d.ts
113
+ interface CommentsAgentPromptInput {
114
+ url: string;
115
+ threadIds: readonly string[];
116
+ mcp: string;
117
+ project: {
118
+ id: string;
119
+ teamId: string;
120
+ url: string;
121
+ };
122
+ resolve: boolean;
123
+ }
124
+ export declare function commentsAgentPrompt({ mcp, project, resolve, threadIds, url }: CommentsAgentPromptInput): string;
118
125
  /** A point in client (viewport) coordinates, such as `event.clientX` and `event.clientY`. */
119
126
  interface AnchorPoint {
120
127
  x: number;
@@ -180,8 +187,6 @@ export declare function anchorRange(anchor: TextAnchor, root?: ParentNode): Rang
180
187
  * that holds the quote best.
181
188
  */
182
189
  export declare function resolveAnchor(anchor: CommentAnchor, root?: ParentNode): AnchorPosition;
183
- //#endregion
184
- //#region src/operations-core/errors.d.ts
185
190
  export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
186
191
  readonly COMMENTS_R0002: {
187
192
  readonly why: ({ id }: {
@@ -377,6 +382,17 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
377
382
  }) => string;
378
383
  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
384
  };
385
+ readonly COMMENTS_TENANT_DELETE_USER: {
386
+ readonly why: "Deleting a user from shared Comments tables requires access to all projects.";
387
+ readonly fix: "Delete the user's messages through the project that owns them.";
388
+ };
389
+ readonly COMMENTS_TENANT_SCOPE_INVALID: {
390
+ readonly why: ({ scope, tenantScope }: {
391
+ scope: string;
392
+ tenantScope: string;
393
+ }) => string;
394
+ readonly fix: "Start a thread on a page in this project.";
395
+ };
380
396
  readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
381
397
  why: string;
382
398
  fix: string;
@@ -400,8 +416,6 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
400
416
  fix: string;
401
417
  };
402
418
  }, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
403
- //#endregion
404
- //#region src/client-send.d.ts
405
419
  /** The logo that a Send segment shows for an agent. `@vite-hub/ui` draws each one. */
406
420
  type CommentSendLogo = "t3" | "claude" | "codex";
407
421
  /** The agent that gets a member's comments. */
@@ -418,11 +432,20 @@ interface CommentSendStatus {
418
432
  count: number;
419
433
  /** The member's agent. Without one, Send pairs an agent first. */
420
434
  agent?: CommentSendAgent;
421
- /** The member's last send, while the agent works on it. `thread` is the URL of the agent's thread. */
435
+ /** The member's last send, after the agent read it and while it works on it. `thread` is the URL of the agent's thread. */
422
436
  working?: {
423
437
  id: string;
424
438
  thread?: string;
425
439
  };
440
+ /**
441
+ * The member's last send, delivered and not read by the agent yet. An inbox send stays here until the agent reads it.
442
+ * `inbox` tells where this send went. If omitted, the client uses `agent` to tell whether it went to an inbox.
443
+ */
444
+ sent?: {
445
+ id: string;
446
+ thread?: string;
447
+ inbox?: boolean;
448
+ };
426
449
  /** The last delivery is still being attempted. */
427
450
  pending?: boolean;
428
451
  /** While the member may not send, the time in ms when the next send may go. */
@@ -462,6 +485,7 @@ type CommentSendResult = {
462
485
  status: "sent" | "pending";
463
486
  id: string;
464
487
  thread?: string;
488
+ inbox?: boolean;
465
489
  } | {
466
490
  status: "failed";
467
491
  reason: string;
@@ -498,7 +522,10 @@ interface CommentSendTransport {
498
522
  /** Pushes events, and returns a function that stops them. Without it, the client asks `status()` while the agent works. */
499
523
  subscribe?: (listener: (event: CommentSendEvent) => void) => () => void;
500
524
  }
501
- /** What the Send segment shows. Every state has the number of waiting threads, `count`. */
525
+ /**
526
+ * What the Send segment shows. Every state has the number of waiting threads, `count`. In `sent`, `inbox` tells where
527
+ * the last send went, and `agent` is where the next Send goes.
528
+ */
502
529
  type CommentSendState = {
503
530
  status: "idle";
504
531
  count: number;
@@ -522,6 +549,7 @@ type CommentSendState = {
522
549
  status: "sent";
523
550
  count: number;
524
551
  inbox: boolean;
552
+ agent?: CommentSendAgent;
525
553
  } | {
526
554
  status: "working";
527
555
  count: number;
@@ -573,8 +601,6 @@ interface CommentSendClient {
573
601
  * pairs one in place first when there is none. `CommentSend` of `@vite-hub/ui` renders it.
574
602
  */
575
603
  export declare function createCommentSend(transport: CommentSendTransport, options?: CommentSendOptions): CommentSendClient;
576
- //#endregion
577
- //#region src/rest-transport.d.ts
578
604
  /** A guest that named itself in the browser. The server keeps the name as display data only. */
579
605
  interface CommentsGuest {
580
606
  id: string;
@@ -638,9 +664,9 @@ interface RestTransport extends CommentsTransport {
638
664
  * `guest` names. Guests and share-link readers can use it. It has no
639
665
  * `subscribe`: the client refreshes when the window gets focus.
640
666
  */
641
- export declare function createRestTransport(options?: RestTransportOptions): RestTransport;
642
- //#endregion
643
- //#region src/send-transport.d.ts
667
+ export declare function createRestTransport(options?: RestTransportOptions & {
668
+ route?: string;
669
+ }): RestTransport;
644
670
  interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base" | "headers" | "credentials" | "fetch"> {
645
671
  /**
646
672
  * The path of the page that Send is on, such as `/notes/azores`. The server turns it into the subject, as `page` of
@@ -660,20 +686,14 @@ interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base"
660
686
  * ```
661
687
  */
662
688
  export declare function createCommentSendTransport(options?: CommentSendTransportOptions): CommentSendTransport;
663
- //#endregion
664
- //#region src/fold-name.d.ts
665
689
  /** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
666
690
  export declare function foldName(text: string): string;
667
- //#endregion
668
- //#region src/reply-id.d.ts
669
691
  /**
670
692
  * The id of the message that a reply with `requestId` stores in a thread. Every retry gets the same id, so the primary
671
693
  * key of the messages refuses a second message, and the client's outbox finds the server copy of its waiting reply.
672
694
  * The server and the browser client both import it, so it has no other import.
673
695
  */
674
696
  export declare function replyMessageId(threadId: string, requestId: string): Promise<string>;
675
- //#endregion
676
- //#region src/client.d.ts
677
697
  export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
678
698
  export interface CommentsClientOptions {
679
699
  transport: CommentsTransport;
@@ -726,5 +746,4 @@ export declare function createCommentsClient(options: CommentsClientOptions & {
726
746
  readonly outbox: CommentsOutbox;
727
747
  };
728
748
  export declare function createCommentsClient(options: CommentsClientOptions): CommentsClient;
729
- //#endregion
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 };
749
+ 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, CommentsAgentPromptInput, CommentsGuest, CommentsOutbox, CommentsOutboxEntry, CommentsOutboxEnvironment, CommentsOutboxMessage, CommentsOutboxOptions, CommentsOutboxStore, CommentsRestAnswer, CommentsRestRequest, CommentsTransport, CreateAnchorOptions, DetachedAnchor, ElementAnchor, ImageAnchor, PageAnchor, ResolvedAnchor, RestCommentThread, RestTransport, RestTransportOptions, TextAnchor };
package/dist/client.js CHANGED
@@ -1,11 +1,11 @@
1
- import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-Bubm7Shd.js";
2
- import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-CJZl5Kc4.js";
3
- import { t as replyMessageId } from "./reply-id-P_bSuEng.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
5
- import { i as commentsRoute } from "./page-DRz_sDY4.js";
6
- import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
7
- import { t as foldName } from "./fold-name-B7Zb3-MF.js";
8
- //#region ../internal/src/browser-environment.ts
1
+ import { i as commentsUnansweredError, r as commentsClientDiagnostics, t as commentsAnswerError } from "./client-diagnostics-CvfTW5d4.js";
2
+ import { i as withCommentFiles, n as outboxAccountHeader, r as retryAfterOf, t as failedCommentPreparation } from "./client-files-lC6X7XyS.js";
3
+ import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
4
+ import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
5
+ import { i as commentsRoute } from "./page-xzgZ6DGm.js";
6
+ import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
7
+ import { t as foldName } from "./fold-name-g-xg0mQk.js";
8
+ // ../internal/src/browser-environment.ts
9
9
  /** The real browser: window events, Web Locks, and a BroadcastChannel, each only when the browser has it. */
10
10
  function createBrowserEnvironment(options) {
11
11
  let channel;
@@ -84,8 +84,7 @@ function backoffDelay(attempt, random) {
84
84
  const ceiling = Math.min(3e4, 1e3 * 2 ** attempt);
85
85
  return ceiling / 2 + random * ceiling / 2;
86
86
  }
87
- //#endregion
88
- //#region src/client-outbox.ts
87
+ // src/client-outbox.ts
89
88
  function changeable(entry) {
90
89
  return entry.status !== "sending" && !entry.uncertain;
91
90
  }
@@ -727,8 +726,15 @@ function createOutbox(options, host) {
727
726
  }
728
727
  };
729
728
  }
730
- //#endregion
731
- //#region src/client-anchor.ts
729
+ // src/agent-prompt.ts
730
+ function commentsAgentPrompt({ mcp, project, resolve, threadIds, url }) {
731
+ return [
732
+ `Fix ${threadIds.length === 1 ? "the open ViteHub comment" : `the ${threadIds.length} open ViteHub comments`} on ${new URL(url).href}`,
733
+ `In the ViteHub MCP (${mcp}), use list_apps to verify team ${project.teamId} and app ${project.url} (id: ${project.id}). If the team is different, ask me to switch to that team in the Console; if the app is missing, ask me to check the link. Only after both match, call read_operation with the app id, operation "comments.get", and input { threadId } for each ID in ${JSON.stringify(threadIds)}.`,
734
+ resolve ? "After each fix, use run_operation with the app id, operation \"comments.resolve\", and input { threadId, reply }. In the reply, say what changed." : "Report the fixes to me without resolving the threads."
735
+ ].join("\n");
736
+ }
737
+ // src/client-anchor.ts
732
738
  const defaultContext = 32;
733
739
  const clamp = (value) => Math.min(1e3, Math.max(0, value));
734
740
  function thousandths(value, size) {
@@ -1130,8 +1136,7 @@ function resolveAnchor(anchor, root = document) {
1130
1136
  element
1131
1137
  };
1132
1138
  }
1133
- //#endregion
1134
- //#region src/client-send.ts
1139
+ // src/client-send.ts
1135
1140
  const reasonOf = (error) => error instanceof Error ? error.message : String(error);
1136
1141
  /**
1137
1142
  * The Send segment of a comment pill, without a framework: it hands the member's waiting threads to their agent, and
@@ -1156,10 +1161,13 @@ function createCommentSend(transport, options = {}) {
1156
1161
  let fetching = false;
1157
1162
  let sendId;
1158
1163
  let thread;
1164
+ let sentInbox = false;
1159
1165
  let pushed;
1160
1166
  let step = 0;
1167
+ let sentUntil = 0;
1161
1168
  let timer;
1162
1169
  let run = 0;
1170
+ let lastStep = "send";
1163
1171
  const notify = () => {
1164
1172
  for (const listener of listeners) listener();
1165
1173
  };
@@ -1176,6 +1184,7 @@ function createCommentSend(transport, options = {}) {
1176
1184
  timer = setTimeout(() => at === step && then(), ms);
1177
1185
  };
1178
1186
  const inbox = () => Boolean(agent && !agent.host);
1187
+ const needsStatus = () => state.status === "failed" && lastStep === "allow";
1179
1188
  const idleState = () => ({
1180
1189
  status: "idle",
1181
1190
  count,
@@ -1183,6 +1192,12 @@ function createCommentSend(transport, options = {}) {
1183
1192
  ...agent && count > 0 ? { canPairAnother: true } : {}
1184
1193
  });
1185
1194
  const idle = () => set(idleState());
1195
+ const sentState = () => ({
1196
+ status: "sent",
1197
+ count,
1198
+ inbox: sentInbox,
1199
+ ...agent ? { agent } : {}
1200
+ });
1186
1201
  const finish = () => {
1187
1202
  sendId = void 0;
1188
1203
  thread = void 0;
@@ -1197,6 +1212,11 @@ function createCommentSend(transport, options = {}) {
1197
1212
  });
1198
1213
  if (!transport.subscribe) later(statusInterval, () => void refresh(working));
1199
1214
  };
1215
+ const sent = () => {
1216
+ set(sentState());
1217
+ if (!transport.subscribe) later(statusInterval, () => void refresh(sent));
1218
+ };
1219
+ const holdingSent = () => state.status === "sent" && Date.now() < sentUntil;
1200
1220
  const limited = (retryAt) => {
1201
1221
  set({
1202
1222
  status: "limited",
@@ -1215,18 +1235,17 @@ function createCommentSend(transport, options = {}) {
1215
1235
  const apply = (status) => {
1216
1236
  agent = status.agent;
1217
1237
  if (status.pending) return pending();
1218
- if (status.working) {
1219
- sendId = status.working.id;
1220
- thread = status.working.thread;
1221
- if (state.status === "sent") {
1222
- state = {
1223
- ...state,
1224
- count,
1225
- inbox: inbox()
1226
- };
1238
+ const last = status.working ?? status.sent;
1239
+ if (last) {
1240
+ if (status.sent) sentInbox = status.sent.inbox ?? inbox();
1241
+ const hold = holdingSent() && sendId === last.id;
1242
+ sendId = last.id;
1243
+ thread = hold ? thread ?? last.thread : last.thread;
1244
+ if (hold) {
1245
+ state = sentState();
1227
1246
  return notify();
1228
1247
  }
1229
- return working();
1248
+ return status.working ? working() : sent();
1230
1249
  }
1231
1250
  sendId = void 0;
1232
1251
  thread = void 0;
@@ -1279,13 +1298,12 @@ function createCommentSend(transport, options = {}) {
1279
1298
  const update = updates?.get(result.id);
1280
1299
  thread = update?.thread ?? result.thread;
1281
1300
  if (revision === countRevision) count = 0;
1282
- set({
1283
- status: "sent",
1284
- count,
1285
- inbox: inbox()
1286
- });
1287
- later(sentFor, update?.done ? finish : working);
1301
+ sentInbox = result.inbox ?? inbox();
1302
+ set(sentState());
1303
+ sentUntil = Date.now() + sentFor;
1304
+ later(sentFor, update?.done ? finish : update ? working : () => void refresh(sent));
1288
1305
  };
1306
+ const drop = (dropped) => void transport.cancel(dropped).catch(() => void 0);
1289
1307
  const deliver = async (request, paired) => {
1290
1308
  const revision = countRevision;
1291
1309
  pushed = transport.subscribe ? /* @__PURE__ */ new Map() : void 0;
@@ -1303,9 +1321,10 @@ function createCommentSend(transport, options = {}) {
1303
1321
  reason: reasonOf(error)
1304
1322
  };
1305
1323
  }
1306
- if (at === step) settle(result, revision, paired);
1324
+ const current = at === step;
1325
+ if (current) settle(result, revision, paired);
1326
+ if (paired && (result.status === "failed" || result.status === "limited" || !current && result.status === "changed")) drop(paired.code);
1307
1327
  };
1308
- const drop = (dropped) => void transport.cancel(dropped).catch(() => void 0);
1309
1328
  const poll = () => {
1310
1329
  later(pairingInterval, async () => {
1311
1330
  if (state.status !== "pairing" || !code) return;
@@ -1331,6 +1350,7 @@ function createCommentSend(transport, options = {}) {
1331
1350
  const pair = async (copy) => {
1332
1351
  if (fetching) return;
1333
1352
  fetching = true;
1353
+ lastStep = "pair";
1334
1354
  const at = ++step;
1335
1355
  try {
1336
1356
  const pairing = transport.startPairing();
@@ -1427,12 +1447,13 @@ function createCommentSend(transport, options = {}) {
1427
1447
  });
1428
1448
  return;
1429
1449
  }
1430
- if (fetching || state.status === "pairing" || state.status === "confirm") return;
1450
+ if (fetching || state.status === "pairing" || state.status === "confirm" || needsStatus()) return;
1431
1451
  if ((state.status === "working" || state.status === "sent") && sendId !== event.id) return;
1432
1452
  if (event.type === "working") {
1433
1453
  thread = event.thread ?? (event.id === sendId ? thread : void 0);
1434
1454
  sendId = event.id;
1435
- if (state.status !== "sent") working();
1455
+ if (holdingSent()) later(sentUntil - Date.now(), working);
1456
+ else working();
1436
1457
  return;
1437
1458
  }
1438
1459
  if (event.id === sendId) finish();
@@ -1453,9 +1474,12 @@ function createCommentSend(transport, options = {}) {
1453
1474
  },
1454
1475
  refresh: () => refresh(),
1455
1476
  async send(copy) {
1456
- if (fetching || state.status !== "idle" && state.status !== "failed" && state.status !== "working") return;
1477
+ if (fetching || state.status !== "idle" && state.status !== "failed" && state.status !== "sent" && state.status !== "working") return;
1457
1478
  if (state.status !== "failed" && count === 0) return;
1479
+ if (state.status === "failed" && lastStep === "pair") return pair(copy);
1480
+ if (needsStatus()) return refresh(() => void 0);
1458
1481
  if (!agent) return pair(copy);
1482
+ lastStep = "send";
1459
1483
  return deliver(() => transport.send());
1460
1484
  },
1461
1485
  async pairAnother(copy) {
@@ -1466,6 +1490,7 @@ function createCommentSend(transport, options = {}) {
1466
1490
  if (state.status !== "confirm" || !code) return;
1467
1491
  const used = code;
1468
1492
  code = void 0;
1493
+ lastStep = "allow";
1469
1494
  return deliver(() => transport.allow(used, selection), {
1470
1495
  code: used,
1471
1496
  agent: state.agent
@@ -1484,8 +1509,7 @@ function createCommentSend(transport, options = {}) {
1484
1509
  }
1485
1510
  };
1486
1511
  }
1487
- //#endregion
1488
- //#region src/rest-transport.ts
1512
+ // src/rest-transport.ts
1489
1513
  /** The URL of an attachment key below the Comments API, such as `/_vitehub/comments/attachments/comments/<id>/shot.png`. */
1490
1514
  function commentAttachmentUrl(key, base = "") {
1491
1515
  return `${base.replace(/\/+$/, "")}${commentsRoute}/attachments/${key.split("/").map((part) => encodeURIComponent(part)).join("/")}`;
@@ -1630,8 +1654,7 @@ function createRestTransport(options = {}) {
1630
1654
  attachmentUrl: (key) => commentAttachmentUrl(key, base)
1631
1655
  };
1632
1656
  }
1633
- //#endregion
1634
- //#region src/send-transport.ts
1657
+ // src/send-transport.ts
1635
1658
  /**
1636
1659
  * The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
1637
1660
  * ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
@@ -1676,8 +1699,7 @@ function createCommentSendTransport(options = {}) {
1676
1699
  send: async () => (await request(`/send?page=${page()}`, post())).data
1677
1700
  };
1678
1701
  }
1679
- //#endregion
1680
- //#region src/client.ts
1702
+ // src/client.ts
1681
1703
  function createCommentsClient(options) {
1682
1704
  const { transport } = options;
1683
1705
  const listeners = /* @__PURE__ */ new Set();
@@ -1909,5 +1931,4 @@ function createCommentsClient(options) {
1909
1931
  }
1910
1932
  };
1911
1933
  }
1912
- //#endregion
1913
- export { anchorRange, commentAttachmentUrl, commentsErrorDiagnostics, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
1934
+ export { anchorRange, commentAttachmentUrl, commentsAgentPrompt, commentsErrorDiagnostics, createAnchor, createCommentSend, createCommentSendTransport, createCommentsClient, createCommentsRestRequest, createIndexedDBOutboxStore, createMemoryOutboxStore, createRestTransport, foldName, replyMessageId, resolveAnchor, selectorFor };
@@ -1,4 +1,3 @@
1
- //#region ../internal/src/inspect.d.ts
2
1
  interface ViteHubDefinitionField {
3
2
  label: string;
4
3
  value: string;
@@ -60,8 +59,6 @@ type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor |
60
59
  interface ViteHubInspectionPluginMetadata {
61
60
  inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
62
61
  }
63
- //#endregion
64
- //#region ../internal/src/console.d.ts
65
62
  type MaybePromise<T> = T | Promise<T>;
66
63
  /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
67
64
  interface ViteHubConsoleDefinitionCatalogView {
@@ -130,7 +127,7 @@ interface ViteHubConsoleOperationAction {
130
127
  operation: string;
131
128
  input: Readonly<Record<string, string>>;
132
129
  /**
133
- * The result is `{ url }`, such as a one-time link or a provider sign-in: the Console opens it in a new tab, and loads
130
+ * The result is `{ url }`, such as a provider sign-in: the Console opens it in a new tab, and loads
134
131
  * the list again when the person comes back. The URL must be `https:`, or `http:` on a loopback host.
135
132
  */
136
133
  tab?: true;
@@ -330,5 +327,4 @@ interface ViteHubConsoleRuntimeRecordTableSection<TOptions = void> extends ViteH
330
327
  }
331
328
  /** A section whose list comes from an operation, called with the Console user on each visit. It has no build-time data. */
332
329
  interface ViteHubConsoleOperationSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleOperationView> {}
333
- //#endregion
334
330
  export { ViteHubInspectionPluginMetadata as i, ViteHubConsoleRecord as n, ViteHubConsoleRuntimeRecordTableSection as r, ViteHubConsoleOperationSection as t };
@@ -1,4 +1,4 @@
1
- //#region src/context.ts
1
+ // src/context.ts
2
2
  /**
3
3
  * The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
4
4
  * browser, build. The Console and Agent tools show these.
@@ -57,5 +57,4 @@ function describeCommentContext(context) {
57
57
  });
58
58
  return fields;
59
59
  }
60
- //#endregion
61
60
  export { describeCommentContext as t };
@@ -1,4 +1,3 @@
1
- //#region src/operations-core/database/postgres.d.ts
2
1
  /**
3
2
  * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`, and
4
3
  * `resolvedBy` hold JSON. Times are milliseconds since the epoch.
@@ -1398,5 +1397,4 @@ export declare const commentsPostgresSchema: {
1398
1397
  dialect: "pg";
1399
1398
  isAlias: false;
1400
1399
  }>;
1401
- };
1402
- //#endregion
1400
+ };
@@ -1,5 +1,5 @@
1
1
  import { bigint, boolean, index, pgTable, text, uniqueIndex } from "drizzle-orm/pg-core";
2
- //#region src/operations-core/database/postgres.ts
2
+ // src/operations-core/database/postgres.ts
3
3
  /**
4
4
  * Threads of comments. `n` is unique inside `scope`, which is what `?comment=<n>` names. `anchor`, `actor`, and
5
5
  * `resolvedBy` hold JSON. Times are milliseconds since the epoch.
@@ -77,5 +77,4 @@ const commentsPostgresSchema = {
77
77
  vitehubCommentCounters: commentCounters,
78
78
  vitehubCommentForge: commentForge
79
79
  };
80
- //#endregion
81
80
  export { commentCounters, commentForge, commentMessages, commentThreads, commentsPostgresSchema };