@vite-hub/comments 0.4.1 → 0.5.1
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 +23 -7
- package/dist/anchor.d.ts +3 -5
- package/dist/anchor.js +1 -2
- package/dist/{client-diagnostics-Bubm7Shd.js → client-diagnostics-CvfTW5d4.js} +1 -2
- package/dist/{client-files-CJZl5Kc4.js → client-files-lC6X7XyS.js} +1 -2
- package/dist/client.d.ts +430 -24
- package/dist/client.js +413 -20
- package/dist/{console-h4KlhIik.d.ts → console-CK2F53QP.d.ts} +2 -4
- package/dist/{context-BqIsmYP1.js → context-DbkBjITZ.js} +1 -2
- package/dist/database/postgres.d.ts +1 -3
- package/dist/database/postgres.js +1 -2
- package/dist/{migrate-Bpw3xL5e.js → database-BkPoOdZr.js} +116 -59
- package/dist/database-CPua6Q6_.d.ts +573 -0
- package/dist/{database-CA1aHKN7.d.ts → database-DUs3c2al.d.ts} +625 -73
- package/dist/database.d.ts +4 -5
- package/dist/database.js +1 -2
- package/dist/{define-CX_Yr_hz.js → define-9uMM3Ewc.js} +2 -3
- package/dist/{define-CHTWfHPo.d.ts → define-B1jLSPe9.d.ts} +8 -6
- package/dist/{errors-4gelGVmK.js → errors-C0VwRHiy.js} +25 -2
- package/dist/{errors-BHsVXlpd.js → errors-DFNiJg67.js} +26 -3
- package/dist/{fold-name-B7Zb3-MF.js → fold-name-g-xg0mQk.js} +1 -2
- package/dist/hosted/hosted-comments/client-B3dlmmQd.js +4 -0
- package/dist/{overlay/dist-BoHMOFax.js → hosted/hosted-comments/dist-DyVmH21U.js} +1 -1
- package/dist/hosted/hosted-comments/frame.js +1 -0
- package/dist/hosted/hosted-comments/overlay-4-mWX4Uz.js +170 -0
- package/dist/hosted/hosted-comments/protocol-BHvtQKte.js +1 -0
- package/dist/hosted/hosted-comments/rest-transport-D-9_pNqZ.js +1 -0
- package/dist/hosted/hosted-comments/tools-CdwnUCOr.js +126 -0
- package/dist/hosted/hosted-comments.js +9 -0
- package/dist/{identity-CBOzgxSf.js → identity-CT7-UGmS.js} +1 -2
- package/dist/{index-iPGlSAgj.d.ts → index-BEnHTj2Z.d.ts} +109 -15
- package/dist/index.d.ts +6 -7
- package/dist/index.js +23 -10
- package/dist/{install-96NXWnrw.d.ts → install-B-FQpi47.d.ts} +24 -7
- package/dist/{install-jRKmuLHK.js → install-BUXxryut.js} +950 -55
- package/dist/{installed-g6nDr5ac.js → installed-C9SkldMi.js} +8 -8
- package/dist/{invariant-D8_xBqmZ.js → invariant-CmdvZ3vp.js} +1 -2
- package/dist/{migrate-B0k_0swk.d.ts → migrate-XjFeQppf.d.ts} +2 -2
- package/dist/{object-Da1zyPCR.js → object-CAK6UYR5.js} +1 -2
- package/dist/{operations-7ycAhDCw.d.ts → operations-8hqTi0DH.d.ts} +8 -4
- package/dist/{operations-9tskoLsk.js → operations-CKC_lMG_.js} +309 -229
- package/dist/{operations-D93EV10O.d.ts → operations-Cic9A9e_.d.ts} +9 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/{client-lZesR40x.js → client-CerbVjTz.js} +3 -3
- package/dist/overlay/dist-DyVmH21U.js +14 -0
- package/dist/overlay/overlay.js +36 -40
- package/dist/page/loader.js +45 -52
- package/dist/page-DE71P_gQ.d.ts +11 -0
- package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-fvmJQCrP.js} +8 -5
- package/dist/{page-DRz_sDY4.js → page-xzgZ6DGm.js} +2 -3
- package/dist/{path--zk6PEMz.js → path-8yqMd8zR.js} +0 -1
- package/dist/{plugin-BNFd1zGz.js → plugin-B2hETRii.js} +16 -13
- package/dist/realtime.d.ts +3 -5
- package/dist/realtime.js +4 -5
- package/dist/{reply-id-P_bSuEng.js → reply-id-Cm9FGOBs.js} +1 -2
- package/dist/request-log-DllKQXj7.js +104 -0
- package/dist/request-origin-YPzfE2eh.js +48 -0
- package/dist/{rpc-BQqYx8kb.js → rpc-BKY7XRlR.js} +5 -7
- package/dist/{rpc-BZ1QNkCC.d.ts → rpc-D-eqtyfh.d.ts} +1 -3
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -2
- package/dist/runtime/auth.d.ts +3 -5
- package/dist/runtime/auth.js +2 -3
- package/dist/runtime/console.d.ts +2 -4
- package/dist/runtime/console.js +4 -5
- package/dist/runtime/index.d.ts +12 -27
- package/dist/runtime/index.js +160 -31
- package/dist/{server-CqyzrqTI.js → server-BGbD7H5s.js} +2 -3
- package/dist/server.d.ts +6 -7
- package/dist/server.js +6 -6
- package/dist/service-CPiWPoiY.d.ts +69 -0
- package/dist/{service-C8ZgFWvy.js → service-DDD4Ubxd.js} +44 -18
- package/dist/{session-ByjMyTak.js → session-BGN6Vlm6.js} +31 -37
- package/dist/{session-CKfW6DGE.d.ts → session-CTh9nisq.d.ts} +3 -5
- package/dist/{service-wC9kx9EX.d.ts → store-DvNTDNgn.d.ts} +3 -73
- package/dist/{table-names-DfiKUlOV.js → table-names-BIHjuEFK.js} +4 -3
- package/dist/testing.d.ts +2 -4
- package/dist/testing.js +4 -5
- package/dist/{tokens-DSbwkVSy.js → tokens-Bx4lZ0yt.js} +3 -6
- package/dist/{types-C7LzhgRb.d.ts → types-BX3vH18p.d.ts} +1 -3
- package/dist/{types-C1qzObs2.d.ts → types-l6GOb_yc.d.ts} +79 -6
- package/dist/vite.d.ts +22 -21
- package/dist/vite.js +161 -104
- package/package.json +19 -19
- package/dist/errors-BEChnUo7.d.ts +0 -197
- package/dist/page-CWwnmF3K.d.ts +0 -22
package/dist/runtime/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import { t as
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { t as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { t as
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
1
|
+
import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-Bx4lZ0yt.js";
|
|
2
|
+
import { t as forwardedRequestOrigin } from "../request-origin-YPzfE2eh.js";
|
|
3
|
+
import "../client-files-lC6X7XyS.js";
|
|
4
|
+
import { t as commentsErrors } from "../errors-C0VwRHiy.js";
|
|
5
|
+
import { i as text, n as guestFromHeaders, t as authorOf } from "../identity-CT7-UGmS.js";
|
|
6
|
+
import { a as runtimeOf, r as resolveCommentsRuntime, t as commentSendOf } from "../installed-C9SkldMi.js";
|
|
7
|
+
import { a as commentThreadSummary, c as hiddenThreadsNote, n as commentAnchorSchema, o as commentThreadsText, r as commentInputSchemas, s as describeCommentThread, t as commentActions } from "../operations-CKC_lMG_.js";
|
|
8
|
+
import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-9uMM3Ewc.js";
|
|
9
|
+
import { h as readAttachment, i as contextSchema, n as base64, o as deniedError, p as mentionedPeople, r as can } from "../service-DDD4Ubxd.js";
|
|
10
|
+
import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage } from "../page-xzgZ6DGm.js";
|
|
11
|
+
import { a as viteHubPageSessionHandler, n as resolveCommentsPage, t as resolveCommentsIdentity } from "../session-BGN6Vlm6.js";
|
|
12
|
+
import { n as installedComments, t as defineCommentsPlugin } from "../plugin-B2hETRii.js";
|
|
13
|
+
import { t as invariant } from "../invariant-CmdvZ3vp.js";
|
|
14
|
+
import { t as commentsErrorDiagnostics } from "../errors-DFNiJg67.js";
|
|
14
15
|
import { getStandardContext, installRequestStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
15
16
|
import * as v from "valibot";
|
|
16
17
|
import { defineGrant } from "@vite-hub/runtime/internal/grant";
|
|
17
18
|
import { hkdfSync } from "node:crypto";
|
|
18
19
|
import { defineAuth } from "@vite-hub/auth";
|
|
19
20
|
import { stateless } from "@vite-hub/auth/presets";
|
|
20
|
-
|
|
21
|
+
// src/runtime/handler.ts
|
|
21
22
|
const fieldEditGrant = defineGrant("vitehub.comments.field-edit", (input) => input);
|
|
22
23
|
const pageSchema = v.pipe(v.string(), v.startsWith("/", "A page starts with `/`."), v.maxLength(1024));
|
|
23
24
|
/** `POST /threads`: the input of `comments.create`, or a `page` instead of the subject, and the page context of the overlay. */
|
|
@@ -53,8 +54,14 @@ const fieldBody = v.object({
|
|
|
53
54
|
function status(code) {
|
|
54
55
|
switch (code) {
|
|
55
56
|
case "COMMENTS_NOT_FOUND":
|
|
56
|
-
case "COMMENTS_CONTENT_MISSING":
|
|
57
|
+
case "COMMENTS_CONTENT_MISSING":
|
|
58
|
+
case "COMMENTS_SEND_OFF": return 404;
|
|
59
|
+
case "COMMENTS_SEND_GRANT_INVALID": return 401;
|
|
60
|
+
case "COMMENTS_SEND_CODE_EXPIRED": return 410;
|
|
61
|
+
case "COMMENTS_SEND_CODE_USED": return 409;
|
|
62
|
+
case "COMMENTS_SEND_CODE_REFUSED": return 422;
|
|
57
63
|
case "COMMENTS_FORBIDDEN":
|
|
64
|
+
case "COMMENTS_SEND_INSECURE":
|
|
58
65
|
case "COMMENTS_POLICY_MISSING":
|
|
59
66
|
case "COMMENTS_FIELD_FORBIDDEN": return 403;
|
|
60
67
|
case "COMMENTS_RESOLVED":
|
|
@@ -274,6 +281,7 @@ function createCommentsHandler(options) {
|
|
|
274
281
|
url: `${route}/auth/github`
|
|
275
282
|
} : void 0;
|
|
276
283
|
const signOut = user && user.github && github ? `${route}/auth/sign-out` : void 0;
|
|
284
|
+
const send = Boolean(comments.options.send && user && !user.guest && comment && await commentSendOf(comments));
|
|
277
285
|
return json({ data: {
|
|
278
286
|
user: user ? authorOf(user) : null,
|
|
279
287
|
...user && user.github ? { github: user.github } : {},
|
|
@@ -286,8 +294,10 @@ function createCommentsHandler(options) {
|
|
|
286
294
|
...signIn ? { signIn } : {},
|
|
287
295
|
...signOut ? { signOut } : {},
|
|
288
296
|
realtime: options.realtime,
|
|
297
|
+
...options.attachments === false ? { attachments: false } : {},
|
|
289
298
|
...options.presence === false ? { presence: false } : {},
|
|
290
299
|
content: Boolean(options.content),
|
|
300
|
+
...send ? { send: true } : {},
|
|
291
301
|
...subject ? { subject } : {},
|
|
292
302
|
...revision === void 0 ? {} : { revision }
|
|
293
303
|
} });
|
|
@@ -483,6 +493,77 @@ function createCommentsHandler(options) {
|
|
|
483
493
|
const env = request["~standard"].runtime?.cloudflare?.env;
|
|
484
494
|
return env ? await runWithActiveCloudflareEnv(env, () => handle(request)) : await handle(request);
|
|
485
495
|
} };
|
|
496
|
+
async function sendRoute(request, url, parts, pageOf) {
|
|
497
|
+
const service = await commentSendOf(comments);
|
|
498
|
+
if (!service) return failure$1(commentsErrors.COMMENTS_SEND_OFF());
|
|
499
|
+
const method = request.method;
|
|
500
|
+
const [, action, code] = parts;
|
|
501
|
+
if (method === "POST" && action === "pair" && !code) {
|
|
502
|
+
const [error, paired] = await service.pair(await readJson(request), forwardedRequestOrigin(request));
|
|
503
|
+
return error ? json({
|
|
504
|
+
error,
|
|
505
|
+
reason: {
|
|
506
|
+
COMMENTS_SEND_CODE_EXPIRED: "expired",
|
|
507
|
+
COMMENTS_SEND_CODE_USED: "used",
|
|
508
|
+
COMMENTS_SEND_CODE_REFUSED: "refused",
|
|
509
|
+
COMMENTS_SEND_INSECURE: "insecure"
|
|
510
|
+
}[error.code] ?? "invalid"
|
|
511
|
+
}, { status: status(error.code) }) : json({ data: paired });
|
|
512
|
+
}
|
|
513
|
+
if (method === "GET" && action && action.startsWith("send_") && !code) {
|
|
514
|
+
const token = /^Bearer\s+(\S+)$/i.exec(request.headers.get("authorization") ?? "")?.[1];
|
|
515
|
+
if (!token) return failure$1(commentsErrors.COMMENTS_SEND_GRANT_INVALID());
|
|
516
|
+
return respond(await service.read(decodeURIComponent(action), token));
|
|
517
|
+
}
|
|
518
|
+
const { user, gate } = await identityOf(request);
|
|
519
|
+
const pathname = url.pathname;
|
|
520
|
+
const caller = async () => {
|
|
521
|
+
const subject = (await pageOf())?.subject;
|
|
522
|
+
if (!subject) return void 0;
|
|
523
|
+
return {
|
|
524
|
+
user,
|
|
525
|
+
gate,
|
|
526
|
+
subject,
|
|
527
|
+
page: normalizeCommentPage(url.searchParams.get("page") ?? "/"),
|
|
528
|
+
origin: forwardedRequestOrigin(request),
|
|
529
|
+
route: pathname.slice(0, pathname.indexOf(commentsRoute) + commentsRoute.length)
|
|
530
|
+
};
|
|
531
|
+
};
|
|
532
|
+
if (action === "pair" && code && !parts[3]) {
|
|
533
|
+
const who = {
|
|
534
|
+
user,
|
|
535
|
+
gate,
|
|
536
|
+
subject: {
|
|
537
|
+
kind: "page",
|
|
538
|
+
id: "/"
|
|
539
|
+
},
|
|
540
|
+
page: "/",
|
|
541
|
+
origin: "",
|
|
542
|
+
route: ""
|
|
543
|
+
};
|
|
544
|
+
if (method === "GET") return json({ data: await service.check(who, decodeURIComponent(code)) });
|
|
545
|
+
if (method === "DELETE") {
|
|
546
|
+
await service.cancel(who, decodeURIComponent(code));
|
|
547
|
+
return json({ data: null });
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const who = await caller();
|
|
551
|
+
if (!who) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "page: Give the page that Send is on." }));
|
|
552
|
+
if (method === "GET" && action === "status" && !code) return json({ data: await service.status(who) });
|
|
553
|
+
if (method === "POST" && action === "start" && !code) return respond(await service.start(who));
|
|
554
|
+
if (method === "POST" && action === "allow" && !code) {
|
|
555
|
+
const body = await readJson(request);
|
|
556
|
+
const given = typeof body === "object" && body !== null ? Reflect.get(body, "code") : void 0;
|
|
557
|
+
if (typeof given !== "string" || !given) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "code: Send the setup code that the agent used." }));
|
|
558
|
+
const selection = typeof body === "object" && body !== null ? Reflect.get(body, "selection") : void 0;
|
|
559
|
+
return respond(await service.allow(who, given, typeof selection === "string" ? selection : ""));
|
|
560
|
+
}
|
|
561
|
+
if (method === "POST" && !action) return respond(await service.send(who));
|
|
562
|
+
return json({ error: {
|
|
563
|
+
code: "COMMENTS_NOT_FOUND",
|
|
564
|
+
why: `No Comments route ${method} ${url.pathname.slice(url.pathname.indexOf(commentsRoute) + commentsRoute.length)}.`
|
|
565
|
+
} }, { status: 404 });
|
|
566
|
+
}
|
|
486
567
|
async function route(request) {
|
|
487
568
|
const url = new URL(request.url);
|
|
488
569
|
const path = url.pathname.slice(url.pathname.indexOf("/_vitehub/comments") + 18).replace(/\/+$/, "") || "/";
|
|
@@ -496,10 +577,11 @@ function createCommentsHandler(options) {
|
|
|
496
577
|
id: subjectId
|
|
497
578
|
} } : void 0;
|
|
498
579
|
const subjectOf = async () => (await pageOf())?.subject;
|
|
499
|
-
if (method !== "GET" && !sameOrigin(request)) return json({ error: {
|
|
580
|
+
if (method !== "GET" && !(method === "POST" && path === "/send/pair") && !sameOrigin(request)) return json({ error: {
|
|
500
581
|
code: "COMMENTS_FORBIDDEN",
|
|
501
582
|
why: "Comments requests must come from the site's own pages."
|
|
502
583
|
} }, { status: 403 });
|
|
584
|
+
if (parts[0] === "send") return await sendRoute(request, url, parts, pageOf);
|
|
503
585
|
if (method === "GET" && path === "/session") {
|
|
504
586
|
const current = await pageOf();
|
|
505
587
|
return await session(request, current?.subject, current?.revision);
|
|
@@ -549,7 +631,7 @@ function createCommentsHandler(options) {
|
|
|
549
631
|
const threadId = decodeURIComponent(parts[1]);
|
|
550
632
|
const action = parts[2];
|
|
551
633
|
const messageId = parts[3] ? decodeURIComponent(parts[3]) : void 0;
|
|
552
|
-
if (method === "GET" && !action) return await act(request, "read", (who) => commentActions.get({
|
|
634
|
+
if (method === "GET" && !action) return await act(request, "read", (who) => commentActions.get({ threadId }, who), (thread, who) => threadResponse(who, thread));
|
|
553
635
|
if (method === "POST" && action === "comments" && !messageId) {
|
|
554
636
|
const parsed = v.safeParse(replyBody, await readJson(request));
|
|
555
637
|
if (!parsed.success) return invalid(parsed.issues);
|
|
@@ -616,8 +698,7 @@ function createCommentsHandler(options) {
|
|
|
616
698
|
} }, { status: 404 });
|
|
617
699
|
}
|
|
618
700
|
}
|
|
619
|
-
|
|
620
|
-
//#region src/runtime/database.ts
|
|
701
|
+
// src/runtime/database.ts
|
|
621
702
|
/**
|
|
622
703
|
* The Database that `defineComments({ database })` names, else `default`, else the only one. The plugin calls it when
|
|
623
704
|
* the server starts. On Cloudflare that is before any request, so a D1 Database can't connect yet: its db throws until
|
|
@@ -640,8 +721,7 @@ function isPlaceholder(db) {
|
|
|
640
721
|
return code === "DATABASE_DISABLED" || code === "DATABASE_NOT_FOUND";
|
|
641
722
|
}
|
|
642
723
|
}
|
|
643
|
-
|
|
644
|
-
//#region src/runtime/definition.ts
|
|
724
|
+
// src/runtime/definition.ts
|
|
645
725
|
/**
|
|
646
726
|
* The Comments definition of `server/comments.ts`: its `comments` export, else its default export. Both forms run the
|
|
647
727
|
* same surfaces. The generated files call it, so a file without `defineComments()` fails with `COMMENTS_B0002`.
|
|
@@ -649,8 +729,7 @@ function isPlaceholder(db) {
|
|
|
649
729
|
function commentsDefinitionOf(module, file) {
|
|
650
730
|
return validateCommentsDefinition(module.comments ?? module.default, file);
|
|
651
731
|
}
|
|
652
|
-
|
|
653
|
-
//#region src/runtime/mcp.ts
|
|
732
|
+
// src/runtime/mcp.ts
|
|
654
733
|
/** A user supplied by an app's own MCP server. Missing identities remain anonymous. */
|
|
655
734
|
function commentsUser(user) {
|
|
656
735
|
const id = text(user?.id) ?? text(user?.email);
|
|
@@ -765,7 +844,7 @@ function commentsMcpTools(comments, options = {}) {
|
|
|
765
844
|
})
|
|
766
845
|
};
|
|
767
846
|
}
|
|
768
|
-
|
|
847
|
+
const tools = [
|
|
769
848
|
{
|
|
770
849
|
name: "comments_list_threads",
|
|
771
850
|
title: "List ViteHub Comments threads",
|
|
@@ -903,7 +982,11 @@ function commentsMcpTools(comments, options = {}) {
|
|
|
903
982
|
body: {
|
|
904
983
|
type: "string",
|
|
905
984
|
description: "Markdown, at most 10,000 characters."
|
|
906
|
-
}
|
|
985
|
+
},
|
|
986
|
+
...comments.options.send ? { send: {
|
|
987
|
+
type: "string",
|
|
988
|
+
description: "The send ID from comments_get_send when answering an ask."
|
|
989
|
+
} } : {}
|
|
907
990
|
},
|
|
908
991
|
required: ["id", "body"],
|
|
909
992
|
additionalProperties: false
|
|
@@ -915,10 +998,23 @@ function commentsMcpTools(comments, options = {}) {
|
|
|
915
998
|
const { thread, grant } = found;
|
|
916
999
|
const author = identity.user ? authorOf(identity.user) : guestFor(context);
|
|
917
1000
|
if (!author) return forbidden("write");
|
|
1001
|
+
const send = text(input.send);
|
|
1002
|
+
if (send) {
|
|
1003
|
+
const service = await commentSendOf(comments);
|
|
1004
|
+
const opened = identity.user && !identity.user.guest && await service?.readOwn(identity.user, send, {
|
|
1005
|
+
gate: identity.gate,
|
|
1006
|
+
console: admitted
|
|
1007
|
+
});
|
|
1008
|
+
if (!opened || !opened.threads.some((entry) => entry.id === thread.id && entry.role === "ask")) return forbidden("write");
|
|
1009
|
+
}
|
|
918
1010
|
spend(grant, "write", thread.id);
|
|
919
1011
|
const [error, message] = await comments.reply(thread.id, {
|
|
920
1012
|
body: text(input.body) ?? "",
|
|
921
|
-
author
|
|
1013
|
+
author,
|
|
1014
|
+
...send ? { actor: {
|
|
1015
|
+
id: "comments-mcp",
|
|
1016
|
+
name: "Comments agent"
|
|
1017
|
+
} } : {}
|
|
922
1018
|
});
|
|
923
1019
|
if (error) return failure(error.why);
|
|
924
1020
|
await comments.flush();
|
|
@@ -968,9 +1064,44 @@ function commentsMcpTools(comments, options = {}) {
|
|
|
968
1064
|
}
|
|
969
1065
|
}
|
|
970
1066
|
];
|
|
1067
|
+
if (comments.options.send) tools.push({
|
|
1068
|
+
name: "comments_get_send",
|
|
1069
|
+
title: "Read a ViteHub Comments send",
|
|
1070
|
+
description: "ViteHub Comments: read the threads that the signed-in user sent to their agent with Send in the comment pill. Each thread says whether it is an ask, the user's own question, or a quote, what someone else said. Without an id, it reads the user's latest send that no agent read yet. Answer each ask with comments_reply, passing the send ID as `send`.",
|
|
1071
|
+
section: "comments",
|
|
1072
|
+
annotations: { readOnlyHint: true },
|
|
1073
|
+
inputSchema: {
|
|
1074
|
+
type: "object",
|
|
1075
|
+
properties: { id: {
|
|
1076
|
+
type: "string",
|
|
1077
|
+
description: "The send id, such as send_… from the delivery. Default: the latest unread send."
|
|
1078
|
+
} },
|
|
1079
|
+
additionalProperties: false
|
|
1080
|
+
},
|
|
1081
|
+
async call(input, context) {
|
|
1082
|
+
const { user, gate } = await identityFor(context);
|
|
1083
|
+
if (!user || user.guest) return forbidden("read");
|
|
1084
|
+
const service = await commentSendOf(comments);
|
|
1085
|
+
if (!service) return failure(`${commentsErrors.COMMENTS_SEND_OFF().why} ${commentsErrors.COMMENTS_SEND_OFF().fix}`);
|
|
1086
|
+
const id = text(input.id);
|
|
1087
|
+
const opened = await service.readOwn(user, id, {
|
|
1088
|
+
gate,
|
|
1089
|
+
console: admitted
|
|
1090
|
+
});
|
|
1091
|
+
if (!opened) return failure(id ? `No send ${id} of this user.` : "This user has no send that an agent did not read yet.");
|
|
1092
|
+
const { send, threads } = opened;
|
|
1093
|
+
return {
|
|
1094
|
+
text: [`Send ${send.id} from ${send.page}, ${new Date(send.createdAt).toISOString()}: ${threads.length} ${threads.length === 1 ? "thread" : "threads"}.`, ...threads.flatMap((thread) => ["", `${thread.role === "ask" ? "Ask" : "Quote"}: ${describeCommentThread(thread)}`])].join("\n"),
|
|
1095
|
+
structured: {
|
|
1096
|
+
send: { ...send },
|
|
1097
|
+
threads: threads.map((thread) => ({ ...thread }))
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
return tools;
|
|
971
1103
|
}
|
|
972
|
-
|
|
973
|
-
//#region ../internal/src/runtime/mcp-server.ts
|
|
1104
|
+
// ../internal/src/runtime/mcp-server.ts
|
|
974
1105
|
/** The MCP result of a `ViteHubMcpTool` call: a text block, then one image block for each image. */
|
|
975
1106
|
function mcpToolResult(result) {
|
|
976
1107
|
const content = [{
|
|
@@ -997,8 +1128,7 @@ function readViteHubSecret(env) {
|
|
|
997
1128
|
return typeof value === "string" && value ? value : void 0;
|
|
998
1129
|
}
|
|
999
1130
|
Object.freeze({ prefix: "sha256=" });
|
|
1000
|
-
|
|
1001
|
-
//#region src/runtime/github-login.ts
|
|
1131
|
+
// src/runtime/github-login.ts
|
|
1002
1132
|
/** The Server Env names of the OAuth client that people sign in to Comments with: a GitHub App's, or an OAuth App's. */
|
|
1003
1133
|
const githubLoginEnv = {
|
|
1004
1134
|
clientId: "VITEHUB_GITHUB_CLIENT_ID",
|
|
@@ -1177,5 +1307,4 @@ function createCommentsGitHubLogin(options = {}) {
|
|
|
1177
1307
|
}
|
|
1178
1308
|
};
|
|
1179
1309
|
}
|
|
1180
|
-
//#endregion
|
|
1181
1310
|
export { commentsDefinitionOf, commentsMcpTools, createCommentsGitHubLogin, createCommentsHandler, defineCommentsPlugin, githubLoginEnv, installedComments, mcpToolResult, selectCommentsDatabase, viteHubPageSessionHandler };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
2
|
-
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
2
|
+
// src/operations-core/server.ts
|
|
3
3
|
const key = Symbol.for("vitehub.comments.runtime");
|
|
4
4
|
const scope = globalThis;
|
|
5
5
|
/**
|
|
@@ -68,5 +68,4 @@ function createAuthUsers(getAuth) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
-
//#endregion
|
|
72
71
|
export { installCommentsRuntime as i, createAuthUsers as n, hasCommentsRuntime as r, commentsRuntime as t };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as maximumCommentBodyLength,
|
|
3
|
-
import {
|
|
4
|
-
import { n as
|
|
5
|
-
import { n as
|
|
6
|
-
|
|
1
|
+
import { b as validateCommentsDefinition, d as CommentsPeople } from "./define-B1jLSPe9.js";
|
|
2
|
+
import { a as maximumCommentBodyLength, i as CommentsRuntime, n as CommentsAttachmentStore, r as CommentsForgeHooks } from "./service-CPiWPoiY.js";
|
|
3
|
+
import { i as createCommentsStore, n as CommentsStore, r as CommentsTables, t as CommentsDatabase } from "./store-DvNTDNgn.js";
|
|
4
|
+
import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Cic9A9e_.js";
|
|
5
|
+
import { n as createRpcTransport, t as RpcTransportOptions } from "./rpc-D-eqtyfh.js";
|
|
6
|
+
import { n as installComments, t as InstallCommentsOptions } from "./install-B-FQpi47.js";
|
|
7
7
|
/** Where mentions find people. The same shape as `defineComments({ people })`. */
|
|
8
8
|
export type CommentsUsers = CommentsPeople;
|
|
9
9
|
/**
|
|
@@ -16,5 +16,4 @@ export declare function commentsRuntime(): Promise<CommentsRuntime>;
|
|
|
16
16
|
export declare function hasCommentsRuntime(): boolean;
|
|
17
17
|
/** People from a Better Auth instance, through its internal adapter. The generated Nitro plugin passes it when the app has Auth. */
|
|
18
18
|
export declare function createAuthUsers(getAuth: () => object | Promise<object>): CommentsPeople;
|
|
19
|
-
//#endregion
|
|
20
19
|
export { type CommentsAttachmentStore, CommentsCaller, type CommentsDatabase, type CommentsForgeHooks, type CommentsRuntime, type CommentsStore, type CommentsTables, type InstallCommentsOptions, RpcTransportOptions, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, createCommentsStore, createRpcTransport, installComments, maximumCommentBodyLength, validateCommentsDefinition };
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { r as
|
|
2
|
-
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-
|
|
3
|
-
import { t as createRpcTransport } from "./rpc-
|
|
4
|
-
import { f as maximumCommentBodyLength } from "./service-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { i as installCommentsRuntime, n as createAuthUsers, r as hasCommentsRuntime, t as commentsRuntime } from "./server-BGbD7H5s.js";
|
|
2
|
+
import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-CKC_lMG_.js";
|
|
3
|
+
import { t as createRpcTransport } from "./rpc-BKY7XRlR.js";
|
|
4
|
+
import { f as maximumCommentBodyLength } from "./service-DDD4Ubxd.js";
|
|
5
|
+
import { r as createCommentsStore, t as installComments } from "./install-BUXxryut.js";
|
|
6
|
+
import { c as validateCommentsDefinition } from "./define-9uMM3Ewc.js";
|
|
7
7
|
export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, commentsRuntime, createAuthUsers, createCommentsStore, createRpcTransport, hasCommentsRuntime, installComments, installCommentsRuntime, maximumCommentBodyLength, validateCommentsDefinition };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { d as CommentsPeople, g as CommentsUser, l as CommentsDefinition } from "./define-B1jLSPe9.js";
|
|
2
|
+
import { n as CommentsStore } from "./store-DvNTDNgn.js";
|
|
3
|
+
import { T as CommentThread } from "./types-BX3vH18p.js";
|
|
4
|
+
import "valibot";
|
|
5
|
+
/** The part of `checkRateLimit()` from `vite-hub/rate-limit` that a public write calls. */
|
|
6
|
+
type SharedRateLimit = (request: Request, name: string, options: {
|
|
7
|
+
key: string;
|
|
8
|
+
limit: number;
|
|
9
|
+
window: `${number}${"ms" | "s" | "m" | "h" | "d"}`;
|
|
10
|
+
}) => Promise<[unknown, {
|
|
11
|
+
allowed: boolean;
|
|
12
|
+
reason?: string;
|
|
13
|
+
retryAfter?: number;
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
} | undefined]>;
|
|
16
|
+
/** Longest message, in characters. */
|
|
17
|
+
declare const maximumCommentBodyLength = 10000;
|
|
18
|
+
/** The parts of a Blob store that attachments use: `blob` of `@vite-hub/blob`. */
|
|
19
|
+
interface CommentsAttachmentStore {
|
|
20
|
+
put: (pathname: string, body: Uint8Array, options: {
|
|
21
|
+
contentType: string;
|
|
22
|
+
}) => Promise<readonly [unknown, unknown]>;
|
|
23
|
+
get?: (pathname: string) => Promise<readonly [unknown, Blob | null | undefined]>;
|
|
24
|
+
}
|
|
25
|
+
/** A file to answer, with the headers that keep a browser from running it. */
|
|
26
|
+
interface CommentsAttachmentBody {
|
|
27
|
+
key: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** The stored media type when Comments attaches that type, else `application/octet-stream`. */
|
|
30
|
+
type: string;
|
|
31
|
+
size: number;
|
|
32
|
+
/** Whether a browser may show it in the page: images other than SVG. */
|
|
33
|
+
inline: boolean;
|
|
34
|
+
data: Blob;
|
|
35
|
+
}
|
|
36
|
+
/** The pull request sync of `defineComments({ forge })`. */
|
|
37
|
+
interface CommentsForgeHooks {
|
|
38
|
+
/** Starts the sync of a thread after a change. */
|
|
39
|
+
changed: (threadId: string) => void;
|
|
40
|
+
/** The threads with their `forge` link. */
|
|
41
|
+
attach: (threads: CommentThread[]) => Promise<CommentThread[]>;
|
|
42
|
+
}
|
|
43
|
+
/** Everything that the comment operations, the server API, and the overlay API share. */
|
|
44
|
+
interface CommentsRuntime {
|
|
45
|
+
definition: CommentsDefinition;
|
|
46
|
+
/**
|
|
47
|
+
* The app's `identify`, given the server event of a call. With it, the comment operations ask it for the user, as
|
|
48
|
+
* the overlay API does, instead of taking the Console's user.
|
|
49
|
+
*/
|
|
50
|
+
identify?: (event: unknown) => Promise<CommentsUser | null>;
|
|
51
|
+
store: CommentsStore;
|
|
52
|
+
/** The Auth adapter. `people` wins over it. Without both, `@` finds the authors that the store knows. */
|
|
53
|
+
users?: CommentsPeople;
|
|
54
|
+
/** Vite's serve command, for the default guest policy. */
|
|
55
|
+
development?: boolean;
|
|
56
|
+
/** The Blob store for attachments, when the app has one and no `storeAttachment`. */
|
|
57
|
+
attachments?: CommentsAttachmentStore;
|
|
58
|
+
forge?: CommentsForgeHooks;
|
|
59
|
+
/**
|
|
60
|
+
* `checkRateLimit` of ViteHub Rate Limit, when it counts in a KV store that every server process shares. Guest writes
|
|
61
|
+
* then count under the Rate Limit name `comments`. Without it, they count in the memory of this process.
|
|
62
|
+
*/
|
|
63
|
+
rateLimit?: SharedRateLimit;
|
|
64
|
+
/** Work that runs after the answer, such as `onMention`. `flush()` of the server API waits for it. */
|
|
65
|
+
background?: (task: Promise<unknown>) => void;
|
|
66
|
+
/** Runs after someone opens a thread again. With Send, it puts back the sends that carried the thread. */
|
|
67
|
+
reopened?: (thread: CommentThread) => Promise<unknown>;
|
|
68
|
+
}
|
|
69
|
+
export { maximumCommentBodyLength as a, CommentsRuntime as i, CommentsAttachmentStore as n, SharedRateLimit as o, CommentsForgeHooks as r, CommentsAttachmentBody as t };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { t as replyMessageId } from "./reply-id-
|
|
2
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
3
|
-
import { t as
|
|
4
|
-
import { t as
|
|
5
|
-
import { r as guestIdPrefix } from "./identity-
|
|
6
|
-
import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-
|
|
1
|
+
import { t as replyMessageId } from "./reply-id-Cm9FGOBs.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
3
|
+
import { t as isPagePath } from "./path-8yqMd8zR.js";
|
|
4
|
+
import { t as foldName } from "./fold-name-g-xg0mQk.js";
|
|
5
|
+
import { r as guestIdPrefix } from "./identity-CT7-UGmS.js";
|
|
6
|
+
import { i as defaultPolicy, o as deniedForMissingPolicy, t as builtinCommentSubjects } from "./define-9uMM3Ewc.js";
|
|
7
|
+
import { t as logFailure } from "./request-log-DllKQXj7.js";
|
|
7
8
|
import * as v from "valibot";
|
|
8
|
-
|
|
9
|
+
// ../internal/src/runtime/client-rate-limit.ts
|
|
9
10
|
const windowPattern = /^(\d+)(ms|s|m|h|d)$/;
|
|
10
11
|
const units = {
|
|
11
12
|
ms: 1,
|
|
@@ -89,8 +90,7 @@ function createClientRateLimit(options) {
|
|
|
89
90
|
return memory(key, policy);
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
|
-
|
|
93
|
-
//#region src/operations-core/service.ts
|
|
93
|
+
// src/operations-core/service.ts
|
|
94
94
|
/** Longest message, in characters. */
|
|
95
95
|
const maximumCommentBodyLength = 1e4;
|
|
96
96
|
/** Largest attachment, in bytes. */
|
|
@@ -145,20 +145,23 @@ function scopeOf(runtime, target) {
|
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* The one access policy of every surface: `authorize`, else `defaultPolicy()`. Only `true` allows. `gate` says what the
|
|
148
|
-
* server checked before, such as the Console's section access; `development` defaults to the runtime's.
|
|
148
|
+
* server checked before, such as the Console's section access; `development` defaults to the runtime's. `authorize`
|
|
149
|
+
* gets `development` from it. It gets `console` only from `context`: a mention check keeps the writer's gate, but the
|
|
150
|
+
* mentioned person was not admitted by the Console.
|
|
149
151
|
*/
|
|
150
152
|
async function can(runtime, context, gate = {}) {
|
|
151
153
|
const { authorize } = runtime.definition;
|
|
152
154
|
const subject = context.subject ?? context.thread?.subject;
|
|
153
|
-
const full = {
|
|
154
|
-
...context,
|
|
155
|
-
user: context.user ? { ...context.user } : null,
|
|
156
|
-
...subject ? { subject } : {}
|
|
157
|
-
};
|
|
158
155
|
const checked = {
|
|
159
156
|
...gate,
|
|
160
157
|
development: gate.development ?? runtime.development === true
|
|
161
158
|
};
|
|
159
|
+
const full = {
|
|
160
|
+
...context,
|
|
161
|
+
user: context.user ? { ...context.user } : null,
|
|
162
|
+
...subject ? { subject } : {},
|
|
163
|
+
development: checked.development
|
|
164
|
+
};
|
|
162
165
|
if (authorize) return await authorize(full) === true;
|
|
163
166
|
if (defaultPolicy(full.user, checked, full.action)) return true;
|
|
164
167
|
if (deniedForMissingPolicy(runtime.definition, full.user, checked)) warnMissingPolicy();
|
|
@@ -343,10 +346,23 @@ async function announce(runtime, thread, message, mentions, fresh, options) {
|
|
|
343
346
|
thread
|
|
344
347
|
});
|
|
345
348
|
} catch (error) {
|
|
346
|
-
|
|
349
|
+
logFailure({
|
|
350
|
+
field: "comments",
|
|
351
|
+
fields: {
|
|
352
|
+
hook: "onComment",
|
|
353
|
+
thread: thread.id
|
|
354
|
+
},
|
|
355
|
+
message: "Comments onComment failed",
|
|
356
|
+
error,
|
|
357
|
+
...options.request ? { request: options.request } : {}
|
|
358
|
+
}, () => globalThis.console.error("[vitehub] Comments onComment failed:", error));
|
|
347
359
|
}
|
|
348
360
|
if (!onMention || !fresh.length) return;
|
|
349
361
|
const link = subjectDefinition(runtime, thread.subject.kind)?.link?.(thread);
|
|
362
|
+
const keep = (promise) => {
|
|
363
|
+
options.waitUntil?.(promise);
|
|
364
|
+
runtime.background?.(promise);
|
|
365
|
+
};
|
|
350
366
|
const task = (async () => {
|
|
351
367
|
try {
|
|
352
368
|
await onMention({
|
|
@@ -356,7 +372,16 @@ async function announce(runtime, thread, message, mentions, fresh, options) {
|
|
|
356
372
|
...link ? { link } : {}
|
|
357
373
|
});
|
|
358
374
|
} catch (error) {
|
|
359
|
-
|
|
375
|
+
logFailure({
|
|
376
|
+
field: "comments",
|
|
377
|
+
fields: {
|
|
378
|
+
hook: "onMention",
|
|
379
|
+
thread: thread.id
|
|
380
|
+
},
|
|
381
|
+
message: "Comments onMention failed",
|
|
382
|
+
error,
|
|
383
|
+
waitUntil: keep
|
|
384
|
+
}, () => globalThis.console.error("[vitehub] Comments onMention failed:", error));
|
|
360
385
|
}
|
|
361
386
|
})();
|
|
362
387
|
options.waitUntil?.(task);
|
|
@@ -419,6 +444,7 @@ async function createThread(runtime, input, options = {}) {
|
|
|
419
444
|
if (created.id !== threadId) return retried(created, input, options.canRead);
|
|
420
445
|
await announce(runtime, created, created.messages[0], mentioned, mentioned, {
|
|
421
446
|
comment: true,
|
|
447
|
+
...options.request ? { request: options.request } : {},
|
|
422
448
|
...options.waitUntil ? { waitUntil: options.waitUntil } : {}
|
|
423
449
|
});
|
|
424
450
|
runtime.forge?.changed(created.id);
|
|
@@ -485,6 +511,7 @@ async function replyToThread(runtime, thread, input, options = {}) {
|
|
|
485
511
|
const message = next.messages.find((entry) => entry.id === id);
|
|
486
512
|
await announce(runtime, next, message, mentioned, mentioned, {
|
|
487
513
|
comment: true,
|
|
514
|
+
...options.request ? { request: options.request } : {},
|
|
488
515
|
...options.waitUntil ? { waitUntil: options.waitUntil } : {}
|
|
489
516
|
});
|
|
490
517
|
runtime.forge?.changed(next.id);
|
|
@@ -634,5 +661,4 @@ async function readAttachment(runtime, key, context) {
|
|
|
634
661
|
type
|
|
635
662
|
};
|
|
636
663
|
}
|
|
637
|
-
//#endregion
|
|
638
664
|
export { clientAddressKey as C, suggest as S, createClientRateLimit as T, requestIdSchema as _, createThread as a, scopeOf as b, earlierThread as c, maximumAttachmentBytes as d, maximumCommentBodyLength as f, replyToThread as g, readAttachment as h, contextSchema as i, editMessage as l, personOf as m, base64 as n, deniedError as o, mentionedPeople as p, can as r, earlierReply as s, attachmentThread as t, fail as u, retried as v, clientRateLimitIssue as w, storeAttachment as x, retriedReply as y };
|