@vite-hub/comments 0.7.0 → 0.9.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 +4 -10
- package/dist/anchor.d.ts +2 -2
- package/dist/anchor.js +0 -1
- package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/client.d.ts +21 -241
- package/dist/client.js +4 -425
- package/dist/database.d.ts +1 -2
- package/dist/database.js +1 -1
- package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
- package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
- package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
- package/dist/hosted/hosted-comments/frame.js +4 -1
- package/dist/hosted/hosted-comments/tools.js +71 -77
- package/dist/hosted/hosted-comments.js +1 -1
- package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
- package/dist/index.d.ts +5 -6
- package/dist/index.js +6 -23
- package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
- package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
- package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
- package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
- package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
- package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
- package/dist/operations.d.ts +3 -3
- package/dist/operations.js +2 -2
- package/dist/overlay/client-BszZKIf8.js +4 -0
- package/dist/overlay/overlay.js +50 -43
- package/dist/page/loader.js +37 -30
- package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
- package/dist/page-DRM1j84-.d.ts +32 -0
- package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
- package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
- package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
- package/dist/realtime.d.ts +7 -9
- package/dist/realtime.js +2 -4
- package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
- package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
- package/dist/rpc.d.ts +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 -9
- package/dist/runtime/index.js +25 -175
- package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
- package/dist/server.d.ts +12 -8
- package/dist/server.js +8 -7
- package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
- package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
- package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
- package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
- package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -2
- package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
- package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
- package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
- package/dist/vite.d.ts +3 -20
- package/dist/vite.js +15 -82
- package/package.json +8 -8
- package/dist/database-CPua6Q6_.d.ts +0 -573
- package/dist/overlay/client-CrnKCZXc.js +0 -4
- package/dist/overlay/dist-yIZmvSaU.js +0 -1
- package/dist/page-DE71P_gQ.d.ts +0 -11
- package/dist/request-origin-B-CPVAVk.js +0 -53
- package/dist/service-IvgrI4XM.d.ts +0 -71
- package/dist/types-l6GOb_yc.d.ts +0 -206
package/README.md
CHANGED
|
@@ -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 **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 })`.
|
|
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**, `commentsPagePrompt()`, the text of **Copy prompt** in the pill, `commentsT3CodeLink()`, the link of **Open in T3 Code
|
|
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. |
|
|
@@ -319,10 +317,6 @@ const client = createCommentsClient({ transport, user: ana });
|
|
|
319
317
|
|
|
320
318
|
`transport.as(user)` gives another person on the same store, and `transport.reconnect()` sends `reconnected` to the listeners.
|
|
321
319
|
|
|
322
|
-
### Send
|
|
323
|
-
|
|
324
|
-
`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).
|
|
325
|
-
|
|
326
320
|
## Errors
|
|
327
321
|
|
|
328
322
|
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-
|
|
2
|
-
import "./types-
|
|
1
|
+
import { A as ElementAnchor } from "./types-BmzTyGt-.js";
|
|
2
|
+
import "./types-VSVs4jIw.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. */
|
package/dist/anchor.js
CHANGED
|
@@ -82,7 +82,6 @@ function query(selector) {
|
|
|
82
82
|
function sameLabel(element, label) {
|
|
83
83
|
return labelOf(element) === label;
|
|
84
84
|
}
|
|
85
|
-
/** An element of the same tag whose label matches, for anchors whose CSS path moved. */
|
|
86
85
|
function findByLabel(label) {
|
|
87
86
|
const tag = label.split(" ", 1)[0];
|
|
88
87
|
if (!tag || tag === label) return;
|
|
@@ -8,7 +8,6 @@ async function base64(file) {
|
|
|
8
8
|
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
9
9
|
return btoa(binary);
|
|
10
10
|
}
|
|
11
|
-
/** A `File` keeps its name. A plain `Blob` gets `file` and the extension of its media type, such as `file.png`. */
|
|
12
11
|
function fileName(file) {
|
|
13
12
|
if (file instanceof File && file.name) return file.name;
|
|
14
13
|
const extension = /^[a-z]+\/([a-z0-9]+)/i.exec(file.type)?.[1];
|
|
@@ -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
|
-
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-
|
|
2
|
-
import "./types-
|
|
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-BmzTyGt-.js";
|
|
2
|
+
import "./types-VSVs4jIw.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. */
|
|
@@ -418,22 +418,6 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
418
418
|
}) => string;
|
|
419
419
|
readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
|
|
420
420
|
};
|
|
421
|
-
readonly COMMENTS_SEND_POSTGRES: {
|
|
422
|
-
readonly why: "`defineComments({ send })` keeps its sends in SQLite tables, and this app keeps comments in Postgres.";
|
|
423
|
-
readonly fix: "Keep comments in a SQLite, libSQL, or D1 Database, or remove `send` from `defineComments()`.";
|
|
424
|
-
};
|
|
425
|
-
readonly COMMENTS_SEND_TABLES_MISSING: {
|
|
426
|
-
readonly why: ({ missing }: {
|
|
427
|
-
missing: string;
|
|
428
|
-
}) => string;
|
|
429
|
-
readonly fix: "Run `vitehub database generate` and `vitehub database migrate`. `vite dev` applies the migration for you.";
|
|
430
|
-
};
|
|
431
|
-
readonly COMMENTS_SEND_WEBHOOKS_OFF: {
|
|
432
|
-
readonly why: ({ file }: {
|
|
433
|
-
file: string;
|
|
434
|
-
}) => string;
|
|
435
|
-
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.";
|
|
436
|
-
};
|
|
437
421
|
readonly COMMENTS_TENANT_DELETE_USER: {
|
|
438
422
|
readonly why: "Deleting a user from shared Comments tables requires access to all projects.";
|
|
439
423
|
readonly fix: "Delete the user's messages through the project that owns them.";
|
|
@@ -482,191 +466,27 @@ export declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
|
|
|
482
466
|
fix: string;
|
|
483
467
|
};
|
|
484
468
|
}, readonly import("nostics").AnyDiagnosticReporter[], import("nostics").InferCodesData>;
|
|
485
|
-
/**
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
interface
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
/** What the server knows about the member's Send now. */
|
|
496
|
-
interface CommentSendStatus {
|
|
497
|
-
/** The open threads that wait for an answer and that no send has carried yet. */
|
|
498
|
-
count: number;
|
|
499
|
-
/** The member's agent. Without one, Send pairs an agent first. */
|
|
500
|
-
agent?: CommentSendAgent;
|
|
501
|
-
/** 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. */
|
|
502
|
-
working?: {
|
|
503
|
-
id: string;
|
|
504
|
-
thread?: string;
|
|
505
|
-
};
|
|
506
|
-
/**
|
|
507
|
-
* The member's last send, delivered and not read by the agent yet. An inbox send stays here until the agent reads it.
|
|
508
|
-
* `inbox` tells where this send went. If omitted, the client uses `agent` to tell whether it went to an inbox.
|
|
509
|
-
*/
|
|
510
|
-
sent?: {
|
|
511
|
-
id: string;
|
|
512
|
-
thread?: string;
|
|
513
|
-
inbox?: boolean;
|
|
514
|
-
};
|
|
515
|
-
/** The last delivery is still being attempted. */
|
|
516
|
-
pending?: boolean;
|
|
517
|
-
/** While the member may not send, the time in ms when the next send may go. */
|
|
518
|
-
retryAt?: number;
|
|
519
|
-
/** Names the `count` waiting threads and their last messages. Allow sends only the threads that it names. */
|
|
520
|
-
selection?: string;
|
|
521
|
-
}
|
|
522
|
-
/** A new setup code. The member pastes `prompt` in the agent's thread, and the agent pairs with `code`. */
|
|
523
|
-
interface CommentSendPairing {
|
|
524
|
-
code: string;
|
|
525
|
-
/** The setup prompt, with the code in it. */
|
|
526
|
-
prompt: string;
|
|
527
|
-
/** The time in ms when the code stops working. */
|
|
528
|
-
expiresAt: number;
|
|
529
|
-
/** The agent that the prompt is for. `host` is the only host its URL may have. */
|
|
530
|
-
agent: CommentSendAgent;
|
|
531
|
-
/** The threads that wait now, which Allow sends, and the selection that names them. */
|
|
532
|
-
count: number;
|
|
533
|
-
selection: string;
|
|
534
|
-
}
|
|
535
|
-
/** 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. */
|
|
536
|
-
type CommentSendPairingCheck = {
|
|
537
|
-
status: "waiting";
|
|
538
|
-
} | {
|
|
539
|
-
status: "paired";
|
|
540
|
-
agent: CommentSendAgent;
|
|
541
|
-
} | {
|
|
542
|
-
status: "expired";
|
|
543
|
-
} | {
|
|
544
|
-
status: "refused";
|
|
545
|
-
};
|
|
546
|
-
/**
|
|
547
|
-
* The answer to a send: delivered, not delivered, or refused until `retryAt`. Allow answers `changed` when the waiting
|
|
548
|
-
* threads are not the ones that the member confirmed, and keeps the code for the new `count`.
|
|
549
|
-
*/
|
|
550
|
-
type CommentSendResult = {
|
|
551
|
-
status: "sent" | "pending";
|
|
552
|
-
id: string;
|
|
553
|
-
thread?: string;
|
|
554
|
-
inbox?: boolean;
|
|
555
|
-
} | {
|
|
556
|
-
status: "failed";
|
|
557
|
-
reason: string;
|
|
558
|
-
} | {
|
|
559
|
-
status: "limited";
|
|
560
|
-
retryAt: number;
|
|
561
|
-
} | {
|
|
562
|
-
status: "changed";
|
|
563
|
-
count: number;
|
|
564
|
-
selection: string;
|
|
565
|
-
};
|
|
566
|
-
/** What the server pushes: the agent started on a send, finished it, or the number of waiting threads changed. */
|
|
567
|
-
type CommentSendEvent = {
|
|
568
|
-
type: "working";
|
|
569
|
-
id: string;
|
|
570
|
-
thread?: string;
|
|
571
|
-
} | {
|
|
572
|
-
type: "done";
|
|
573
|
-
id: string;
|
|
574
|
-
} | {
|
|
575
|
-
type: "count";
|
|
576
|
-
count: number;
|
|
577
|
-
};
|
|
578
|
-
/** How a Send segment talks to the server. Comments `send: true` gives one over HTTP. */
|
|
579
|
-
interface CommentSendTransport {
|
|
580
|
-
status: () => Promise<CommentSendStatus>;
|
|
581
|
-
startPairing: () => Promise<CommentSendPairing>;
|
|
582
|
-
pollPairing: (code: string) => Promise<CommentSendPairingCheck>;
|
|
583
|
-
/** Pairs the agent that used `code` and sends the waiting threads that `selection` names to it. */
|
|
584
|
-
allow: (code: string, selection: string) => Promise<CommentSendResult>;
|
|
585
|
-
/** Drops `code`, so no agent can use it. */
|
|
586
|
-
cancel: (code: string) => Promise<void>;
|
|
587
|
-
send: () => Promise<CommentSendResult>;
|
|
588
|
-
/** Pushes events, and returns a function that stops them. Without it, the client asks `status()` while the agent works. */
|
|
589
|
-
subscribe?: (listener: (event: CommentSendEvent) => void) => () => void;
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* What the Send segment shows. Every state has the number of waiting threads, `count`. In `sent`, `inbox` tells where
|
|
593
|
-
* the last send went, and `agent` is where the next Send goes.
|
|
594
|
-
*/
|
|
595
|
-
type CommentSendState = {
|
|
596
|
-
status: "idle";
|
|
597
|
-
count: number;
|
|
598
|
-
inbox: boolean;
|
|
599
|
-
canPairAnother?: true;
|
|
600
|
-
} | {
|
|
601
|
-
status: "pairing";
|
|
602
|
-
count: number;
|
|
603
|
-
prompt: string;
|
|
604
|
-
expiresAt: number;
|
|
605
|
-
agent: CommentSendAgent;
|
|
606
|
-
reason?: "expired" | "refused";
|
|
607
|
-
} | {
|
|
608
|
-
status: "confirm";
|
|
609
|
-
count: number;
|
|
610
|
-
agent: CommentSendAgent;
|
|
611
|
-
} | {
|
|
612
|
-
status: "sending";
|
|
613
|
-
count: number;
|
|
614
|
-
} | {
|
|
615
|
-
status: "sent";
|
|
616
|
-
count: number;
|
|
617
|
-
inbox: boolean;
|
|
618
|
-
agent?: CommentSendAgent;
|
|
619
|
-
} | {
|
|
620
|
-
status: "working";
|
|
621
|
-
count: number;
|
|
622
|
-
agent?: CommentSendAgent;
|
|
623
|
-
thread?: string;
|
|
624
|
-
} | {
|
|
625
|
-
status: "failed";
|
|
626
|
-
count: number;
|
|
627
|
-
reason: string;
|
|
628
|
-
} | {
|
|
629
|
-
status: "limited";
|
|
630
|
-
count: number;
|
|
631
|
-
retryAt: number;
|
|
632
|
-
};
|
|
633
|
-
/** Writes the setup prompt to the clipboard once it loads. Resolves to `false` when the browser refuses. */
|
|
634
|
-
type CommentSendCopy = (prompt: Promise<string>) => Promise<boolean>;
|
|
635
|
-
interface CommentSendOptions {
|
|
636
|
-
/** How often, in ms, the client asks whether an agent used the setup code. Default 1500. */
|
|
637
|
-
pairingInterval?: number;
|
|
638
|
-
/** How often, in ms, the client asks `status()` while the agent works and the transport cannot push. Default 5000. */
|
|
639
|
-
statusInterval?: number;
|
|
640
|
-
/** How long, in ms, Sent shows before Working. Default 2000. */
|
|
641
|
-
sentFor?: number;
|
|
642
|
-
}
|
|
643
|
-
interface CommentSendClient {
|
|
644
|
-
readonly state: CommentSendState;
|
|
645
|
-
/** Calls `listener` after every change of `state`. Returns a function that stops it. */
|
|
646
|
-
onChange: (listener: () => void) => () => void;
|
|
647
|
-
/** Loads the status, then follows the agent: pushed events, or `status()` while it works. Returns a function that stops it. */
|
|
648
|
-
start: () => () => void;
|
|
649
|
-
/** Loads the status again, such as after the member wrote a comment. */
|
|
650
|
-
refresh: () => Promise<void>;
|
|
651
|
-
/**
|
|
652
|
-
* Send N, and Retry after Not delivered. Without an agent, it gets a setup code, gives its prompt to `copy`, and waits
|
|
653
|
-
* for an agent to use the code.
|
|
654
|
-
*/
|
|
655
|
-
send: (copy?: CommentSendCopy) => Promise<void>;
|
|
656
|
-
/** Starts a new pairing without changing where the regular Send button sends. */
|
|
657
|
-
pairAnother: (copy?: CommentSendCopy) => Promise<void>;
|
|
658
|
-
/** Allow and send N: pairs the agent that used the code and sends to it. */
|
|
659
|
-
allow: () => Promise<void>;
|
|
660
|
-
/** Copy again, after the code expired or the agent used a URL on another host. */
|
|
661
|
-
copyAgain: (copy?: CommentSendCopy) => Promise<void>;
|
|
662
|
-
/** × or Escape while pairing: drops the code and goes back to Send N. */
|
|
663
|
-
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;
|
|
664
478
|
}
|
|
665
479
|
/**
|
|
666
|
-
*
|
|
667
|
-
*
|
|
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.
|
|
668
483
|
*/
|
|
669
|
-
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;
|
|
670
490
|
/** A guest that named itself in the browser. The server keeps the name as display data only. */
|
|
671
491
|
interface CommentsGuest {
|
|
672
492
|
id: string;
|
|
@@ -733,46 +553,6 @@ interface RestTransport extends CommentsTransport {
|
|
|
733
553
|
export declare function createRestTransport(options?: RestTransportOptions & {
|
|
734
554
|
route?: string;
|
|
735
555
|
}): RestTransport;
|
|
736
|
-
interface CommentSendTransportOptions extends Pick<RestTransportOptions, "base" | "headers" | "credentials" | "fetch"> {
|
|
737
|
-
/**
|
|
738
|
-
* The path of the page that Send is on, such as `/notes/azores`. The server turns it into the subject, as `page` of
|
|
739
|
-
* `defineComments()` decides. A function runs before each request, so it follows client-side navigation. Default:
|
|
740
|
-
* `location.pathname`.
|
|
741
|
-
*/
|
|
742
|
-
page?: string | (() => string);
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* The transport of `createCommentSend()` over the Send routes of Comments, `<base>/_vitehub/comments/send/**`. The
|
|
746
|
-
* ViteHub pill uses it, and an app renders `CommentSend` of `@vite-hub/ui` with it in its own pill:
|
|
747
|
-
*
|
|
748
|
-
* ```ts
|
|
749
|
-
* import { createCommentSend, createCommentSendTransport } from "@vite-hub/comments/client"
|
|
750
|
-
*
|
|
751
|
-
* const send = createCommentSend(createCommentSendTransport({ page: () => location.pathname }))
|
|
752
|
-
* ```
|
|
753
|
-
*/
|
|
754
|
-
export declare function createCommentSendTransport(options?: CommentSendTransportOptions): CommentSendTransport;
|
|
755
|
-
/** Lower case without accents, so `jose` finds `José`. Mention suggestions match names this way, in the browser and on the server. */
|
|
756
|
-
export declare function foldName(text: string): string;
|
|
757
|
-
/** What the Comments API session lets the person do on the page. */
|
|
758
|
-
interface CommentsPageCan {
|
|
759
|
-
comment: boolean;
|
|
760
|
-
resolve: boolean;
|
|
761
|
-
delete?: boolean;
|
|
762
|
-
/** `false` keeps every message as it was sent. */
|
|
763
|
-
change?: false;
|
|
764
|
-
}
|
|
765
|
-
/**
|
|
766
|
-
* Whether the Comments API lets `user` do `action`, from the permissions of the page session and the ones that the API
|
|
767
|
-
* sent with the thread. A guest never edits or deletes, because the server does not take a guest id as proof. The
|
|
768
|
-
* server still decides.
|
|
769
|
-
*/
|
|
770
|
-
export declare function commentsApiCan(user: CommentUser | undefined, page: CommentsPageCan | undefined, action: "reply" | "resolve" | "edit" | "delete", { thread, message }: {
|
|
771
|
-
thread: CommentThread;
|
|
772
|
-
message?: CommentMessage;
|
|
773
|
-
}): boolean;
|
|
774
|
-
/** The app base, such as `/portal`, that Vite `base` or Nuxt `app.baseURL` sets. The Comments API of the app runs below it. */
|
|
775
|
-
export declare function appCommentsBase(): string;
|
|
776
556
|
/** The guest name and id that this browser saved, the same one that the overlay uses. */
|
|
777
557
|
export declare function readCommentsGuest(): CommentsGuest | undefined;
|
|
778
558
|
/** Saves the name that a guest typed. The id stays when the guest saved a name before. */
|
|
@@ -842,4 +622,4 @@ export declare function createCommentsClient(options: CommentsClientOptions & {
|
|
|
842
622
|
readonly outbox: CommentsOutbox;
|
|
843
623
|
};
|
|
844
624
|
export declare function createCommentsClient(options?: CommentsClientOptions): CommentsClient;
|
|
845
|
-
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,
|
|
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 };
|