@vite-hub/comments 0.6.1 → 0.8.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.
- package/README.md +8 -12
- package/dist/anchor.d.ts +1 -1
- package/dist/{client-diagnostics-D987sEK7.js → client-diagnostics-DoXqdnBd.js} +8 -0
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/client.d.ts +48 -223
- package/dist/client.js +232 -569
- package/dist/database.d.ts +1 -2
- package/dist/database.js +1 -1
- package/dist/{define-C2tnAtBU.js → define-C-LUOouq.js} +1 -1
- package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
- package/dist/{errors-ByCRdInk.js → errors-DeSEHzRf.js} +1 -13
- package/dist/hosted/hosted-comments/frame.js +4 -1
- package/dist/hosted/hosted-comments/tools.js +362 -0
- package/dist/hosted/hosted-comments.js +1 -19
- package/dist/{index-D1T7RJ4R.d.ts → index-d6NsDxu9.d.ts} +4 -112
- package/dist/index.d.ts +4 -5
- package/dist/index.js +6 -20
- package/dist/{install-D6hXZaSN.js → install-BueV_fJY.js} +22 -780
- package/dist/{install-9L4ASzUC.d.ts → install-F-_O7zDr.d.ts} +5 -11
- package/dist/{installed-bPUnazFf.js → installed-BqQKo6WC.js} +2 -7
- package/dist/{database-Cguz3hZL.js → migrate-oseJAYbm.js} +2 -46
- package/dist/{operations-B1ALn4VS.js → operations-0llC5kKO.js} +49 -51
- package/dist/{operations-8hqTi0DH.d.ts → operations-DFLer1fR.d.ts} +1 -0
- package/dist/{operations-BkkrI8a3.d.ts → operations-jaihyWw2.d.ts} +36 -4
- package/dist/operations.d.ts +3 -3
- package/dist/operations.js +2 -2
- package/dist/overlay/client-ZBsUybIe.js +4 -0
- package/dist/overlay/overlay.js +68 -37
- package/dist/page/loader.js +36 -30
- package/dist/page-BgvzzsJb.d.ts +32 -0
- package/dist/{page-2NzFladc.js → page-CDhmXO-y.js} +24 -1
- package/dist/{page-tools-shared-fvmJQCrP.js → page-tools-shared-BCdvqA4S.js} +41 -6
- package/dist/{plugin-l4sPt5-n.js → plugin-DGUqlc3C.js} +9 -9
- package/dist/realtime.d.ts +10 -9
- package/dist/realtime.js +2 -4
- package/dist/{rpc-BYmbVkr8.js → rpc-kkxzQ3Qy.js} +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +1 -2
- package/dist/runtime/auth.js +1 -1
- package/dist/runtime/client-request-plugin.d.ts +2 -0
- package/dist/runtime/client-request-plugin.js +21 -0
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/index.d.ts +6 -8
- package/dist/runtime/index.js +25 -153
- package/dist/{server-DvSehkPP.js → server-CAMs6viR.js} +1 -1
- package/dist/server.d.ts +11 -7
- package/dist/server.js +8 -7
- package/dist/{store-DvNTDNgn.d.ts → service-CMVA_Ryv.d.ts} +67 -1
- package/dist/{service-BIGe1Hpo.js → service-DaMq8TBw.js} +35 -33
- package/dist/{session-CCRLR9bf.js → session-B7GDrqsK.js} +207 -41
- package/dist/{session-CN4irEqf.d.ts → session-EzQqBeE8.d.ts} +2 -3
- package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
- package/dist/testing.js +1 -1
- package/dist/{define-B1jLSPe9.d.ts → types-qzJKgWYS.d.ts} +157 -4
- package/dist/vite.d.ts +3 -20
- package/dist/vite.js +20 -52
- package/package.json +9 -8
- package/dist/database-CPua6Q6_.d.ts +0 -573
- package/dist/hosted/hosted-comments/client-Czl2zu9P.js +0 -4
- package/dist/hosted/hosted-comments/dist-DyVmH21U.js +0 -14
- package/dist/hosted/hosted-comments/overlay-DpS0P-nd.js +0 -186
- package/dist/hosted/hosted-comments/protocol-DuB0Zhs-.js +0 -1
- package/dist/hosted/hosted-comments/rest-transport-CKZG_jZ4.js +0 -1
- package/dist/hosted/hosted-comments/tools-D8xg-kDW.js +0 -126
- package/dist/overlay/client-C7ftI-CB.js +0 -4
- package/dist/overlay/dist-yIZmvSaU.js +0 -1
- package/dist/page-DE71P_gQ.d.ts +0 -11
- package/dist/request-origin-YPzfE2eh.js +0 -48
- package/dist/service-IvgrI4XM.d.ts +0 -71
- package/dist/types-l6GOb_yc.d.ts +0 -206
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ export const comments = defineComments({
|
|
|
76
76
|
|
|
77
77
|
Console `comments:read` access allows reading threads and joining presence. Writes also require full `comments` access and the Comments policy.
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
With the pill open, press `C` and click the page to start a thread, or press `B` to draw on the page with a marker, a pen, arrows, or text labels and comment with a picture of it. Press `E` to edit text that `contentField()` marks:
|
|
80
80
|
|
|
81
81
|
```vue
|
|
82
82
|
<script setup lang="ts">
|
|
@@ -93,7 +93,7 @@ An edit reads the draft, changes one string field, and saves the document with `
|
|
|
93
93
|
|
|
94
94
|
### Add Hosted Comments
|
|
95
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
|
|
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**, and set `comments: { overlay: false }`. This turns off the app's overlay but keeps its Comments API. When the app's Comments start, Hosted Comments stay off or stop after you send or discard any draft. The browser console shows `COMMENTS_HOSTED_CONFLICT`. The hosted overlay draws in `<vitehub-hosted-comments>`, so it never takes the element of the app's overlay. The Console signs reviewers in and stores their page threads. Send shows a comment at once and sends it in the background, with one outbox for each project. Confirming an unlink permanently deletes that project's hosted threads and replies.
|
|
97
97
|
|
|
98
98
|
## Server API
|
|
99
99
|
|
|
@@ -114,13 +114,11 @@ On a preview, `forge: { provider: "github" }` posts each thread to the pull requ
|
|
|
114
114
|
|
|
115
115
|
## Failures in logs
|
|
116
116
|
|
|
117
|
-
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).
|
|
117
|
+
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. `onComment` runs before the answer; give slow work to its `waitUntil(promise)`, which keeps the promise running after the answer, and a rejection is logged as its own event with `hook: "onComment"`. 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).
|
|
118
118
|
|
|
119
|
-
##
|
|
119
|
+
## Hand comments to an agent
|
|
120
120
|
|
|
121
|
-
Each open thread has **Open in T3 Code** and **Copy**, and the list of open threads has **Open in T3 Code**
|
|
122
|
-
|
|
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).
|
|
121
|
+
Each open thread has **Open in T3 Code** and **Copy**, and the list of open threads has **Copy prompt** and **Open in T3 Code** in one row under the title. **Copy** and **Open in T3 Code** give a prompt with the page URL, the text and replies of each thread, the element, and the URLs of its files, for every person who may read the comments. For a Console team member whose MCP access may read the threads, the prompt also names the linked app, its team, and the steps of the ViteHub MCP. It includes resolution steps only with Console MCP write access. `/session` supplies `agent: { mcp, project, resolve }`, and `repository`, the GitHub `owner/name` that the T3 Code link opens: `forge.repository`, else the repository of the build. A Hosted Comments script tag gives it with `data-vitehub-repo`. The pill shows **Copy prompt** too, in both modes, when the page has open threads. In the pill and in the list, **Copy prompt** copies the same text. For a Console team member, it is a short prompt that names the page, the app (its Console name, else its domain), and the ViteHub MCP calls that read and resolve the page's threads. Other people get the full text. <kbd>Shift</kbd> <kbd>C</kbd> hides or shows the pins, as the eye does. Build it with `commentsPagePrompt({ url, threads, agent })`.
|
|
124
122
|
|
|
125
123
|
## Deployment and security boundaries
|
|
126
124
|
|
|
@@ -138,7 +136,7 @@ Each open thread has **Open in T3 Code** and **Copy**, and the list of open thre
|
|
|
138
136
|
| Import | Purpose |
|
|
139
137
|
| --- | --- |
|
|
140
138
|
| `@vite-hub/comments` | `defineComments()` and types. `installComments()` is in `@vite-hub/comments/server`. |
|
|
141
|
-
| `@vite-hub/comments/client` | Framework-free client, transport types, `createAnchor()`, `resolveAnchor()`, `commentsAgentPrompt()`, the text of **Copy**, `
|
|
139
|
+
| `@vite-hub/comments/client` | Framework-free client, transport types, `createAnchor()`, `resolveAnchor()`, `commentsAgentPrompt()`, the text of **Copy**, `commentsPagePrompt()`, the text of **Copy prompt** in the pill, and `commentsT3CodeLink()`, the link of **Open in T3 Code**. |
|
|
142
140
|
| `@vite-hub/comments/testing` | In-memory client transport for tests and examples. |
|
|
143
141
|
| `@vite-hub/comments/anchor` | DOM anchoring: `createAnchor()`, `placeAnchor()`, `selectorOf()`, `labelOf()`. |
|
|
144
142
|
| `@vite-hub/comments/database` | `commentsSchema`, the Drizzle tables, and `commentsTables`, the statements that create them. |
|
|
@@ -247,6 +245,8 @@ client.threads; // The cached threads, ordered by number.
|
|
|
247
245
|
client.onChange(() => console.log(`${client.threads.length} threads`));
|
|
248
246
|
```
|
|
249
247
|
|
|
248
|
+
Without `transport`, the client uses the Comments API of the app, with the guest that `saveCommentsGuest(name)` saved in this browser. In Vue, `useComments({ subject })` from `@vite-hub/ui/headless` and `<CommentLayer :subject>` use that client and learn the user from `GET /session`.
|
|
249
|
+
|
|
250
250
|
To retry a create safely, give it a `requestId`, such as `crypto.randomUUID()`, and keep it for that draft. A second create with the same `requestId` in the same scope returns the first thread and creates no new thread. Only the author of the first thread gets it back, for the same subject, and only when that author may still read it. Anything else fails: the Operations and `POST /threads` answer `409` with `COMMENTS_R0022`, and the server API `comments.create()` returns `COMMENTS_INVALID_INPUT` with the reason. Make a new `requestId` for each new comment.
|
|
251
251
|
|
|
252
252
|
A reply takes a `requestId` too. A second reply with the same `requestId` in the same thread returns the thread with the first message, adds nothing, and runs no hooks. Another author with that key gets the same `409`.
|
|
@@ -317,10 +317,6 @@ const client = createCommentsClient({ transport, user: ana });
|
|
|
317
317
|
|
|
318
318
|
`transport.as(user)` gives another person on the same store, and `transport.reconnect()` sends `reconnected` to the listeners.
|
|
319
319
|
|
|
320
|
-
### Send
|
|
321
|
-
|
|
322
|
-
`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).
|
|
323
|
-
|
|
324
320
|
## Errors
|
|
325
321
|
|
|
326
322
|
Errors have a stable code, a `why`, and a `fix`.
|
package/dist/anchor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as ElementAnchor } from "./types-BX3vH18p.js";
|
|
2
|
-
import "./types-
|
|
2
|
+
import "./types-qzJKgWYS.js";
|
|
3
3
|
/** The anchor of a pin that the overlay drops: an element anchor with every hint that `placeAnchor()` uses. */
|
|
4
4
|
export type PinAnchor = ElementAnchor & Required<Pick<ElementAnchor, "label" | "page" | "viewport">>;
|
|
5
5
|
/** The attribute that Content's `contentField()` writes on an element that renders a field. */
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Diagnostic, defineDiagnostics } from "nostics";
|
|
2
2
|
// src/client-diagnostics.ts
|
|
3
3
|
const commentsClientCodes = {
|
|
4
|
+
COMMENTS_HOSTED_CONFLICT: {
|
|
5
|
+
why: "This page runs the app's own Comments, so the Hosted Comments script does not start its overlay.",
|
|
6
|
+
fix: "Remove the Hosted Comments script, or keep it and set `comments: { overlay: false }` to turn off the app's overlay. See https://vitehub.dev/docs/comments/configure#add-hosted-comments"
|
|
7
|
+
},
|
|
4
8
|
COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
|
|
5
9
|
why: "The current author is not the author of this queued comment.",
|
|
6
10
|
fix: "Sign in as the original author and retry the outbox."
|
|
@@ -13,6 +17,10 @@ const commentsClientCodes = {
|
|
|
13
17
|
why: "The server may already have this comment, so the draft cannot change.",
|
|
14
18
|
fix: "Wait for delivery to finish, then edit or delete the server copy."
|
|
15
19
|
},
|
|
20
|
+
COMMENTS_OVERLAY_ELEMENT_TAKEN: {
|
|
21
|
+
why: ({ name }) => `Another script defined the <${name}> element, so this Comments overlay cannot start.`,
|
|
22
|
+
fix: "Load one Comments overlay script on the page. Remove the other script that defines the element."
|
|
23
|
+
},
|
|
16
24
|
COMMENTS_R0001: {
|
|
17
25
|
why: ({ target }) => `createAnchor() found nothing to anchor to for ${target}.`,
|
|
18
26
|
fix: "Pass an element, a non-empty selection, or a point that is over an element of the page."
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
// ../internal/src/runtime/client-request.ts
|
|
3
|
+
const storageKey = Symbol.for("vitehub.client-request");
|
|
4
|
+
const runtimeGlobal = globalThis;
|
|
5
|
+
const clientRequests = runtimeGlobal[storageKey] ||= new AsyncLocalStorage();
|
|
6
|
+
function isRelativeInProcessRequest(request, client) {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
if (url.protocol !== "http:") return false;
|
|
9
|
+
if (url.host === "localhost") return true;
|
|
10
|
+
const clientUrl = new URL(client.url);
|
|
11
|
+
url.protocol = clientUrl.protocol;
|
|
12
|
+
return url.host === clientUrl.host || url.host === client.headers.get("host");
|
|
13
|
+
}
|
|
14
|
+
/** Runs `next` with `request` as the client request, unless `request` is a relative request inside a client request. */
|
|
15
|
+
function runWithClientRequest(request, next) {
|
|
16
|
+
const client = clientRequests.getStore();
|
|
17
|
+
return client && isRelativeInProcessRequest(request, client) ? next() : clientRequests.run(request, next);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The request that the client sent. Nitro builds a relative request that the server sends to itself, such as a Nuxt
|
|
21
|
+
* `useFetch()` during server rendering or `serverFetch("/api/...")`, at `http://localhost` or `http://<forwarded Host>`,
|
|
22
|
+
* so the URL of that request does not show the origin of the page. Read origins from this request instead. It needs
|
|
23
|
+
* the Nitro plugin that `clientRequestPlugin()` of `@vite-hub/internal/nitro-kit` gives.
|
|
24
|
+
*/
|
|
25
|
+
function clientRequest(request) {
|
|
26
|
+
const client = clientRequests.getStore();
|
|
27
|
+
return client && isRelativeInProcessRequest(request, client) ? client : request;
|
|
28
|
+
}
|
|
29
|
+
export { runWithClientRequest as n, clientRequest as t };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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";
|
|
2
|
-
import "./types-
|
|
2
|
+
import "./types-qzJKgWYS.js";
|
|
3
3
|
/** A page event that a client store reacts to. */
|
|
4
4
|
type BrowserEvent = "online" | "offline" | "visible" | "hidden";
|
|
5
5
|
/** What a client store needs from the browser: page events, one sender across tabs, and messages between tabs. Tests pass a fake one. */
|
|
@@ -137,10 +137,12 @@ interface CommentsAgentPromptThread {
|
|
|
137
137
|
/** The ViteHub MCP of a Console member, and the linked app that the agent checks before it reads the threads. */
|
|
138
138
|
interface CommentsAgentAccess {
|
|
139
139
|
mcp: string;
|
|
140
|
+
/** `name` is the app's name in the Console, such as `Acme Docs`. */
|
|
140
141
|
project: {
|
|
141
142
|
id: string;
|
|
142
143
|
teamId: string;
|
|
143
144
|
url: string;
|
|
145
|
+
name?: string;
|
|
144
146
|
};
|
|
145
147
|
/** `true` when the member's MCP access may resolve the threads. */
|
|
146
148
|
resolve: boolean;
|
|
@@ -166,6 +168,12 @@ export declare function commentsAgentPrompt(input: CommentsAgentPromptInput): st
|
|
|
166
168
|
* the last option is the thread IDs and instructions. Returns `undefined` if none of these fit.
|
|
167
169
|
*/
|
|
168
170
|
export declare function commentsT3CodeLink(input: CommentsAgentPromptInput, repository?: string): string | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* The prompt of **Copy prompt** in the pill, for the open threads of one page. With `agent`, it is three lines: the page,
|
|
173
|
+
* the app in the Console to read the threads from, and what to do with them. Without it, the agent cannot read the
|
|
174
|
+
* threads, so the prompt is `commentsAgentPrompt()` with their text.
|
|
175
|
+
*/
|
|
176
|
+
export declare function commentsPagePrompt(input: CommentsAgentPromptInput): string;
|
|
169
177
|
/** A point in client (viewport) coordinates, such as `event.clientX` and `event.clientY`. */
|
|
170
178
|
interface AnchorPoint {
|
|
171
179
|
x: number;
|
|
@@ -410,22 +418,6 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
410
418
|
}) => string;
|
|
411
419
|
readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
|
|
412
420
|
};
|
|
413
|
-
readonly COMMENTS_SEND_POSTGRES: {
|
|
414
|
-
readonly why: "`defineComments({ send })` keeps its sends in SQLite tables, and this app keeps comments in Postgres.";
|
|
415
|
-
readonly fix: "Keep comments in a SQLite, libSQL, or D1 Database, or remove `send` from `defineComments()`.";
|
|
416
|
-
};
|
|
417
|
-
readonly COMMENTS_SEND_TABLES_MISSING: {
|
|
418
|
-
readonly why: ({ missing }: {
|
|
419
|
-
missing: string;
|
|
420
|
-
}) => string;
|
|
421
|
-
readonly fix: "Run `vitehub database generate` and `vitehub database migrate`. `vite dev` applies the migration for you.";
|
|
422
|
-
};
|
|
423
|
-
readonly COMMENTS_SEND_WEBHOOKS_OFF: {
|
|
424
|
-
readonly why: ({ file }: {
|
|
425
|
-
file: string;
|
|
426
|
-
}) => string;
|
|
427
|
-
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.";
|
|
428
|
-
};
|
|
429
421
|
readonly COMMENTS_TENANT_DELETE_USER: {
|
|
430
422
|
readonly why: "Deleting a user from shared Comments tables requires access to all projects.";
|
|
431
423
|
readonly fix: "Delete the user's messages through the project that owns them.";
|
|
@@ -437,6 +429,10 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
437
429
|
}) => string;
|
|
438
430
|
readonly fix: "Start a thread on a page in this project.";
|
|
439
431
|
};
|
|
432
|
+
readonly COMMENTS_HOSTED_CONFLICT: {
|
|
433
|
+
why: string;
|
|
434
|
+
fix: string;
|
|
435
|
+
};
|
|
440
436
|
readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
|
|
441
437
|
why: string;
|
|
442
438
|
fix: string;
|
|
@@ -449,6 +445,12 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
449
445
|
why: string;
|
|
450
446
|
fix: string;
|
|
451
447
|
};
|
|
448
|
+
readonly COMMENTS_OVERLAY_ELEMENT_TAKEN: {
|
|
449
|
+
why: ({ name }: {
|
|
450
|
+
name: string;
|
|
451
|
+
}) => string;
|
|
452
|
+
fix: string;
|
|
453
|
+
};
|
|
452
454
|
readonly COMMENTS_R0001: {
|
|
453
455
|
why: ({ target }: {
|
|
454
456
|
target: string;
|
|
@@ -464,191 +466,27 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
464
466
|
fix: string;
|
|
465
467
|
};
|
|
466
468
|
}, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
|
|
467
|
-
/**
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
interface
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
|
|
476
|
-
}
|
|
477
|
-
/** What the server knows about the member's Send now. */
|
|
478
|
-
interface CommentSendStatus {
|
|
479
|
-
/** The open threads that wait for an answer and that no send has carried yet. */
|
|
480
|
-
count: number;
|
|
481
|
-
/** The member's agent. Without one, Send pairs an agent first. */
|
|
482
|
-
agent?: CommentSendAgent;
|
|
483
|
-
/** 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. */
|
|
484
|
-
working?: {
|
|
485
|
-
id: string;
|
|
486
|
-
thread?: string;
|
|
487
|
-
};
|
|
488
|
-
/**
|
|
489
|
-
* The member's last send, delivered and not read by the agent yet. An inbox send stays here until the agent reads it.
|
|
490
|
-
* `inbox` tells where this send went. If omitted, the client uses `agent` to tell whether it went to an inbox.
|
|
491
|
-
*/
|
|
492
|
-
sent?: {
|
|
493
|
-
id: string;
|
|
494
|
-
thread?: string;
|
|
495
|
-
inbox?: boolean;
|
|
496
|
-
};
|
|
497
|
-
/** The last delivery is still being attempted. */
|
|
498
|
-
pending?: boolean;
|
|
499
|
-
/** While the member may not send, the time in ms when the next send may go. */
|
|
500
|
-
retryAt?: number;
|
|
501
|
-
/** Names the `count` waiting threads and their last messages. Allow sends only the threads that it names. */
|
|
502
|
-
selection?: string;
|
|
503
|
-
}
|
|
504
|
-
/** A new setup code. The member pastes `prompt` in the agent's thread, and the agent pairs with `code`. */
|
|
505
|
-
interface CommentSendPairing {
|
|
506
|
-
code: string;
|
|
507
|
-
/** The setup prompt, with the code in it. */
|
|
508
|
-
prompt: string;
|
|
509
|
-
/** The time in ms when the code stops working. */
|
|
510
|
-
expiresAt: number;
|
|
511
|
-
/** The agent that the prompt is for. `host` is the only host its URL may have. */
|
|
512
|
-
agent: CommentSendAgent;
|
|
513
|
-
/** The threads that wait now, which Allow sends, and the selection that names them. */
|
|
514
|
-
count: number;
|
|
515
|
-
selection: string;
|
|
516
|
-
}
|
|
517
|
-
/** 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. */
|
|
518
|
-
type CommentSendPairingCheck = {
|
|
519
|
-
status: "waiting";
|
|
520
|
-
} | {
|
|
521
|
-
status: "paired";
|
|
522
|
-
agent: CommentSendAgent;
|
|
523
|
-
} | {
|
|
524
|
-
status: "expired";
|
|
525
|
-
} | {
|
|
526
|
-
status: "refused";
|
|
527
|
-
};
|
|
528
|
-
/**
|
|
529
|
-
* The answer to a send: delivered, not delivered, or refused until `retryAt`. Allow answers `changed` when the waiting
|
|
530
|
-
* threads are not the ones that the member confirmed, and keeps the code for the new `count`.
|
|
531
|
-
*/
|
|
532
|
-
type CommentSendResult = {
|
|
533
|
-
status: "sent" | "pending";
|
|
534
|
-
id: string;
|
|
535
|
-
thread?: string;
|
|
536
|
-
inbox?: boolean;
|
|
537
|
-
} | {
|
|
538
|
-
status: "failed";
|
|
539
|
-
reason: string;
|
|
540
|
-
} | {
|
|
541
|
-
status: "limited";
|
|
542
|
-
retryAt: number;
|
|
543
|
-
} | {
|
|
544
|
-
status: "changed";
|
|
545
|
-
count: number;
|
|
546
|
-
selection: string;
|
|
547
|
-
};
|
|
548
|
-
/** What the server pushes: the agent started on a send, finished it, or the number of waiting threads changed. */
|
|
549
|
-
type CommentSendEvent = {
|
|
550
|
-
type: "working";
|
|
551
|
-
id: string;
|
|
552
|
-
thread?: string;
|
|
553
|
-
} | {
|
|
554
|
-
type: "done";
|
|
555
|
-
id: string;
|
|
556
|
-
} | {
|
|
557
|
-
type: "count";
|
|
558
|
-
count: number;
|
|
559
|
-
};
|
|
560
|
-
/** How a Send segment talks to the server. Comments `send: true` gives one over HTTP. */
|
|
561
|
-
interface CommentSendTransport {
|
|
562
|
-
status: () => Promise<CommentSendStatus>;
|
|
563
|
-
startPairing: () => Promise<CommentSendPairing>;
|
|
564
|
-
pollPairing: (code: string) => Promise<CommentSendPairingCheck>;
|
|
565
|
-
/** Pairs the agent that used `code` and sends the waiting threads that `selection` names to it. */
|
|
566
|
-
allow: (code: string, selection: string) => Promise<CommentSendResult>;
|
|
567
|
-
/** Drops `code`, so no agent can use it. */
|
|
568
|
-
cancel: (code: string) => Promise<void>;
|
|
569
|
-
send: () => Promise<CommentSendResult>;
|
|
570
|
-
/** Pushes events, and returns a function that stops them. Without it, the client asks `status()` while the agent works. */
|
|
571
|
-
subscribe?: (listener: (event: CommentSendEvent) => void) => () => void;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* What the Send segment shows. Every state has the number of waiting threads, `count`. In `sent`, `inbox` tells where
|
|
575
|
-
* the last send went, and `agent` is where the next Send goes.
|
|
576
|
-
*/
|
|
577
|
-
type CommentSendState = {
|
|
578
|
-
status: "idle";
|
|
579
|
-
count: number;
|
|
580
|
-
inbox: boolean;
|
|
581
|
-
canPairAnother?: true;
|
|
582
|
-
} | {
|
|
583
|
-
status: "pairing";
|
|
584
|
-
count: number;
|
|
585
|
-
prompt: string;
|
|
586
|
-
expiresAt: number;
|
|
587
|
-
agent: CommentSendAgent;
|
|
588
|
-
reason?: "expired" | "refused";
|
|
589
|
-
} | {
|
|
590
|
-
status: "confirm";
|
|
591
|
-
count: number;
|
|
592
|
-
agent: CommentSendAgent;
|
|
593
|
-
} | {
|
|
594
|
-
status: "sending";
|
|
595
|
-
count: number;
|
|
596
|
-
} | {
|
|
597
|
-
status: "sent";
|
|
598
|
-
count: number;
|
|
599
|
-
inbox: boolean;
|
|
600
|
-
agent?: CommentSendAgent;
|
|
601
|
-
} | {
|
|
602
|
-
status: "working";
|
|
603
|
-
count: number;
|
|
604
|
-
agent?: CommentSendAgent;
|
|
605
|
-
thread?: string;
|
|
606
|
-
} | {
|
|
607
|
-
status: "failed";
|
|
608
|
-
count: number;
|
|
609
|
-
reason: string;
|
|
610
|
-
} | {
|
|
611
|
-
status: "limited";
|
|
612
|
-
count: number;
|
|
613
|
-
retryAt: number;
|
|
614
|
-
};
|
|
615
|
-
/** Writes the setup prompt to the clipboard once it loads. Resolves to `false` when the browser refuses. */
|
|
616
|
-
type CommentSendCopy = (prompt: Promise<string>) => Promise<boolean>;
|
|
617
|
-
interface CommentSendOptions {
|
|
618
|
-
/** How often, in ms, the client asks whether an agent used the setup code. Default 1500. */
|
|
619
|
-
pairingInterval?: number;
|
|
620
|
-
/** How often, in ms, the client asks `status()` while the agent works and the transport cannot push. Default 5000. */
|
|
621
|
-
statusInterval?: number;
|
|
622
|
-
/** How long, in ms, Sent shows before Working. Default 2000. */
|
|
623
|
-
sentFor?: number;
|
|
624
|
-
}
|
|
625
|
-
interface CommentSendClient {
|
|
626
|
-
readonly state: CommentSendState;
|
|
627
|
-
/** Calls `listener` after every change of `state`. Returns a function that stops it. */
|
|
628
|
-
onChange: (listener: () => void) => () => void;
|
|
629
|
-
/** Loads the status, then follows the agent: pushed events, or `status()` while it works. Returns a function that stops it. */
|
|
630
|
-
start: () => () => void;
|
|
631
|
-
/** Loads the status again, such as after the member wrote a comment. */
|
|
632
|
-
refresh: () => Promise<void>;
|
|
633
|
-
/**
|
|
634
|
-
* Send N, and Retry after Not delivered. Without an agent, it gets a setup code, gives its prompt to `copy`, and waits
|
|
635
|
-
* for an agent to use the code.
|
|
636
|
-
*/
|
|
637
|
-
send: (copy?: CommentSendCopy) => Promise<void>;
|
|
638
|
-
/** Starts a new pairing without changing where the regular Send button sends. */
|
|
639
|
-
pairAnother: (copy?: CommentSendCopy) => Promise<void>;
|
|
640
|
-
/** Allow and send N: pairs the agent that used the code and sends to it. */
|
|
641
|
-
allow: () => Promise<void>;
|
|
642
|
-
/** Copy again, after the code expired or the agent used a URL on another host. */
|
|
643
|
-
copyAgain: (copy?: CommentSendCopy) => Promise<void>;
|
|
644
|
-
/** × or Escape while pairing: drops the code and goes back to Send N. */
|
|
645
|
-
cancel: () => void;
|
|
469
|
+
/** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
|
|
470
|
+
export declare function foldName(text: string): string;
|
|
471
|
+
/** What the Comments API session lets the person do on the page. */
|
|
472
|
+
interface CommentsPageCan {
|
|
473
|
+
comment: boolean;
|
|
474
|
+
resolve: boolean;
|
|
475
|
+
delete?: boolean;
|
|
476
|
+
/** `false` keeps every message as it was sent. */
|
|
477
|
+
change?: false;
|
|
646
478
|
}
|
|
647
479
|
/**
|
|
648
|
-
*
|
|
649
|
-
*
|
|
480
|
+
* Whether the Comments API lets `user` do `action`, from the permissions of the page session and the ones that the API
|
|
481
|
+
* sent with the thread. A guest never edits or deletes, because the server does not take a guest id as proof. The
|
|
482
|
+
* server still decides.
|
|
650
483
|
*/
|
|
651
|
-
export declare function
|
|
484
|
+
export declare function commentsApiCan(user: CommentUser | undefined, page: CommentsPageCan | undefined, action: "reply" | "resolve" | "edit" | "delete", { thread, message }: {
|
|
485
|
+
thread: CommentThread;
|
|
486
|
+
message?: CommentMessage;
|
|
487
|
+
}): boolean;
|
|
488
|
+
/** The app base, such as `/portal`, that Vite `base` or Nuxt `app.baseURL` sets. The Comments API of the app runs below it. */
|
|
489
|
+
export declare function appCommentsBase(): string;
|
|
652
490
|
/** A guest that named itself in the browser. The server keeps the name as display data only. */
|
|
653
491
|
interface CommentsGuest {
|
|
654
492
|
id: string;
|
|
@@ -715,27 +553,13 @@ interface RestTransport extends CommentsTransport {
|
|
|
715
553
|
export declare function createRestTransport(options?: RestTransportOptions & {
|
|
716
554
|
route?: string;
|
|
717
555
|
}): RestTransport;
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
|
|
728
|
-
* ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
|
|
729
|
-
*
|
|
730
|
-
* ```ts
|
|
731
|
-
* import { createCommentSend, createCommentSendTransport } from "@vite-hub/comments/client"
|
|
732
|
-
*
|
|
733
|
-
* const send = createCommentSend(createCommentSendTransport({ page: () => location.pathname }))
|
|
734
|
-
* ```
|
|
735
|
-
*/
|
|
736
|
-
export declare function createCommentSendTransport(options?: CommentSendTransportOptions): CommentSendTransport;
|
|
737
|
-
/** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
|
|
738
|
-
export declare function foldName(text: string): string;
|
|
556
|
+
/** The guest name and id that this browser saved, the same one that the overlay uses. */
|
|
557
|
+
export declare function readCommentsGuest(): CommentsGuest | undefined;
|
|
558
|
+
/** Saves the name that a guest typed. The id stays when the guest saved a name before. */
|
|
559
|
+
export declare function saveCommentsGuest(name: string): CommentsGuest;
|
|
560
|
+
/** Calls `listener` each time `saveCommentsGuest()` saves a guest on this page. Returns a function that stops it. */
|
|
561
|
+
export declare function onCommentsGuestSaved(listener: (guest: CommentsGuest) => void): () => void;
|
|
562
|
+
export declare function commentsGuestUser(guest: CommentsGuest): CommentUser;
|
|
739
563
|
/**
|
|
740
564
|
* The id of the message that a reply with `requestId` stores in a thread. Every retry gets the same id, so the primary
|
|
741
565
|
* key of the messages refuses a second message, and the client's outbox finds the server copy of its waiting reply.
|
|
@@ -744,7 +568,8 @@ export declare function foldName(text: string): string;
|
|
|
744
568
|
export declare function replyMessageId(threadId: string, requestId: string): Promise<string>;
|
|
745
569
|
export type CommentsClientStatus = "idle" | "loading" | "ready" | "error";
|
|
746
570
|
export interface CommentsClientOptions {
|
|
747
|
-
|
|
571
|
+
/** Default: the Comments API of this app, as the signed-in user, or as the guest that `saveCommentsGuest()` saved. */
|
|
572
|
+
transport?: CommentsTransport;
|
|
748
573
|
/** The signed-in user. The UI uses it for the "mine" filter and to know which messages the user may edit. */
|
|
749
574
|
user?: CommentUser;
|
|
750
575
|
/** What `refresh()` lists. For example `{ page: "/pricing" }`. Without an explicit limit, loads all pages. */
|
|
@@ -796,5 +621,5 @@ export declare function createCommentsClient(options: CommentsClientOptions & {
|
|
|
796
621
|
}): CommentsClient & {
|
|
797
622
|
readonly outbox: CommentsOutbox;
|
|
798
623
|
};
|
|
799
|
-
export declare function createCommentsClient(options
|
|
800
|
-
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,
|
|
624
|
+
export declare function createCommentsClient(options?: CommentsClientOptions): CommentsClient;
|
|
625
|
+
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, CommentStatus, CommentStatusInput, CommentSubject, CommentThread, CommentUploadInput, CommentUser, CommentUsersInput, CommentsAgentAccess, CommentsAgentPromptInput, CommentsAgentPromptThread, CommentsClientFiles, CommentsGuest, CommentsOutbox, CommentsOutboxEntry, CommentsOutboxEnvironment, CommentsOutboxMessage, CommentsOutboxOptions, CommentsOutboxStore, CommentsPageCan, CommentsRestAnswer, CommentsRestRequest, CommentsTransport, CreateAnchorOptions, DetachedAnchor, ElementAnchor, ImageAnchor, PageAnchor, ResolvedAnchor, RestCommentThread, RestTransport, RestTransportOptions, TextAnchor };
|