@vite-hub/comments 0.0.0 → 0.3.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/LICENSE +201 -0
- package/README.md +291 -0
- package/dist/anchor.d.ts +43 -0
- package/dist/anchor.js +133 -0
- package/dist/client-diagnostics-CcFpkbAk.js +40 -0
- package/dist/client.d.ts +176 -0
- package/dist/client.js +738 -0
- package/dist/console-h4KlhIik.d.ts +332 -0
- package/dist/context-BqIsmYP1.js +61 -0
- package/dist/database/postgres.d.ts +1402 -0
- package/dist/database/postgres.js +81 -0
- package/dist/database-CA1aHKN7.d.ts +1495 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +2 -0
- package/dist/define-43mMR39K.js +89 -0
- package/dist/define-B3TF9zzn.d.ts +204 -0
- package/dist/errors-4gelGVmK.js +57 -0
- package/dist/errors-C6qptPoG.js +135 -0
- package/dist/errors-CyQyKAvy.d.ts +185 -0
- package/dist/fold-name-B7Zb3-MF.js +7 -0
- package/dist/identity-CBOzgxSf.js +39 -0
- package/dist/index-DNhy69Wt.d.ts +83 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +196 -0
- package/dist/install-BcMPgPk_.js +1154 -0
- package/dist/install-W9ghhGoh.d.ts +36 -0
- package/dist/installed-B-PfERBU.js +30 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/migrate-B0k_0swk.d.ts +54 -0
- package/dist/migrate-BDQ8xqUs.js +289 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operations-D4A1Fcgf.d.ts +160 -0
- package/dist/operations-DMMIfYPW.js +1159 -0
- package/dist/operations-GLeOqgMt.d.ts +257 -0
- package/dist/operations.d.ts +3 -0
- package/dist/operations.js +3 -0
- package/dist/overlay/client-DmsSMOzi.js +4 -0
- package/dist/overlay/dist-BoHMOFax.js +14 -0
- package/dist/overlay/dist-yIZmvSaU.js +1 -0
- package/dist/overlay/overlay.js +201 -0
- package/dist/page/loader.js +142 -0
- package/dist/page-B41ozN63.js +40 -0
- package/dist/page-DtbMOEMd.d.ts +22 -0
- package/dist/page-tools-shared-NHUjKI8E.js +117 -0
- package/dist/path--zk6PEMz.js +18 -0
- package/dist/plugin-PS8PMYus.js +74 -0
- package/dist/realtime.d.ts +12 -0
- package/dist/realtime.js +47 -0
- package/dist/rpc-HBcWtg0T.d.ts +17 -0
- package/dist/rpc-RKPAusHp.js +153 -0
- package/dist/rpc.d.ts +2 -0
- package/dist/rpc.js +2 -0
- package/dist/runtime/auth.d.ts +8 -0
- package/dist/runtime/auth.js +18 -0
- package/dist/runtime/connect/node.d.ts +1 -0
- package/dist/runtime/connect/node.js +2 -0
- package/dist/runtime/connect.d.ts +1 -0
- package/dist/runtime/connect.js +2 -0
- package/dist/runtime/console.d.ts +5 -0
- package/dist/runtime/console.js +64 -0
- package/dist/runtime/index.d.ts +270 -0
- package/dist/runtime/index.js +1113 -0
- package/dist/server-D8k-0GXe.js +72 -0
- package/dist/server.d.ts +20 -0
- package/dist/server.js +7 -0
- package/dist/service-CFVm23k7.d.ts +158 -0
- package/dist/service-GHhhyQj4.js +609 -0
- package/dist/session-DVx-1Tym.d.ts +14 -0
- package/dist/session-EkudzUmm.js +503 -0
- package/dist/testing.d.ts +30 -0
- package/dist/testing.js +187 -0
- package/dist/tokens-DSbwkVSy.js +58 -0
- package/dist/types-BIS0hCEl.d.ts +124 -0
- package/dist/types-CZujrMFd.d.ts +322 -0
- package/dist/vite.d.ts +308 -0
- package/dist/vite.js +1660 -0
- package/package.json +153 -4
|
@@ -0,0 +1,1113 @@
|
|
|
1
|
+
import { t as commentsErrorDiagnostics } from "../errors-C6qptPoG.js";
|
|
2
|
+
import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage } from "../page-B41ozN63.js";
|
|
3
|
+
import { a as commentThreadSummary, c as hiddenThreadsNote, n as commentAnchorSchema, o as commentThreadsText, r as commentInputSchemas, s as describeCommentThread, t as commentActions } from "../operations-DMMIfYPW.js";
|
|
4
|
+
import { t as invariant } from "../invariant-D8_xBqmZ.js";
|
|
5
|
+
import { a as deniedError, d as mentionedPeople, n as can, r as contextSchema } from "../service-GHhhyQj4.js";
|
|
6
|
+
import { i as text, n as guestFromHeaders, t as authorOf } from "../identity-CBOzgxSf.js";
|
|
7
|
+
import { c as validateCommentsDefinition, o as deniedForMissingPolicy } from "../define-43mMR39K.js";
|
|
8
|
+
import { a as runWithActiveCloudflareEnv, i as getActiveCloudflareBinding, r as rememberGitHubToken, t as forgetGitHubToken } from "../tokens-DSbwkVSy.js";
|
|
9
|
+
import { r as resolveCommentsRuntime } from "../installed-B-PfERBU.js";
|
|
10
|
+
import { t as commentsErrors } from "../errors-4gelGVmK.js";
|
|
11
|
+
import { a as viteHubPageSessionHandler, n as resolveCommentsPage, o as forwardedRequestOrigin, t as resolveCommentsIdentity } from "../session-EkudzUmm.js";
|
|
12
|
+
import { n as installedComments, t as defineCommentsPlugin } from "../plugin-PS8PMYus.js";
|
|
13
|
+
import { getStandardContext, installRequestStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
14
|
+
import * as v from "valibot";
|
|
15
|
+
import { defineGrant } from "@vite-hub/runtime/internal/grant";
|
|
16
|
+
import { hkdfSync } from "node:crypto";
|
|
17
|
+
import { defineAuth } from "@vite-hub/auth";
|
|
18
|
+
import { stateless } from "@vite-hub/auth/presets";
|
|
19
|
+
//#region src/runtime/handler.ts
|
|
20
|
+
const fieldEditGrant = defineGrant("vitehub.comments.field-edit", (input) => input);
|
|
21
|
+
const pageSchema = v.pipe(v.string(), v.startsWith("/", "A page starts with `/`."), v.maxLength(1024));
|
|
22
|
+
/** `POST /threads`: the input of `comments.create`, or a `page` instead of the subject, and the page context of the overlay. */
|
|
23
|
+
const createBody = v.object({
|
|
24
|
+
...commentInputSchemas.create.entries,
|
|
25
|
+
subject: v.optional(commentInputSchemas.create.entries.subject),
|
|
26
|
+
page: v.optional(pageSchema),
|
|
27
|
+
anchor: v.optional(commentAnchorSchema),
|
|
28
|
+
context: v.optional(contextSchema)
|
|
29
|
+
});
|
|
30
|
+
const replyBody = v.object({
|
|
31
|
+
body: commentInputSchemas.reply.entries.body,
|
|
32
|
+
mentions: commentInputSchemas.reply.entries.mentions,
|
|
33
|
+
attachments: commentInputSchemas.reply.entries.attachments
|
|
34
|
+
});
|
|
35
|
+
const editBody = v.object({
|
|
36
|
+
body: commentInputSchemas.edit.entries.body,
|
|
37
|
+
mentions: commentInputSchemas.edit.entries.mentions
|
|
38
|
+
});
|
|
39
|
+
/** The first issue as one sentence, for `COMMENTS_INVALID_INPUT`. */
|
|
40
|
+
function describeIssue(issues) {
|
|
41
|
+
const issue = issues[0];
|
|
42
|
+
if (!issue) return "unknown issue.";
|
|
43
|
+
const path = issue.path?.map((item) => String(item.key)).join(".");
|
|
44
|
+
return path ? `${path}: ${issue.message}` : issue.message;
|
|
45
|
+
}
|
|
46
|
+
const fieldBody = v.object({
|
|
47
|
+
field: v.pipe(v.string(), v.maxLength(512)),
|
|
48
|
+
value: v.pipe(v.string(), v.maxLength(2e4)),
|
|
49
|
+
ifDigest: v.string()
|
|
50
|
+
});
|
|
51
|
+
function status(code) {
|
|
52
|
+
switch (code) {
|
|
53
|
+
case "COMMENTS_NOT_FOUND":
|
|
54
|
+
case "COMMENTS_CONTENT_MISSING": return 404;
|
|
55
|
+
case "COMMENTS_FORBIDDEN":
|
|
56
|
+
case "COMMENTS_POLICY_MISSING":
|
|
57
|
+
case "COMMENTS_FIELD_FORBIDDEN": return 403;
|
|
58
|
+
case "COMMENTS_RESOLVED":
|
|
59
|
+
case "COMMENTS_FIELD_CONFLICT": return 409;
|
|
60
|
+
case "COMMENTS_FIELD_LOCKED": return 423;
|
|
61
|
+
case "COMMENTS_FIELD_NOT_EDITABLE": return 422;
|
|
62
|
+
case "COMMENTS_NOT_INSTALLED": return 503;
|
|
63
|
+
default: return 400;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function json(value, init = {}) {
|
|
67
|
+
const headers = new Headers(init.headers);
|
|
68
|
+
headers.set("content-type", "application/json; charset=utf-8");
|
|
69
|
+
headers.set("cache-control", "private, no-store");
|
|
70
|
+
return new Response(JSON.stringify(value), {
|
|
71
|
+
...init,
|
|
72
|
+
headers
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function failure$1(error) {
|
|
76
|
+
return json({ error }, { status: status(error.code) });
|
|
77
|
+
}
|
|
78
|
+
/** A thrown Comments diagnostic, such as `COMMENTS_R0019` for tables that need a migration, as the API's error object. */
|
|
79
|
+
function diagnosticResponse(error) {
|
|
80
|
+
const code = Reflect.get(Object(error), "code");
|
|
81
|
+
const status = Reflect.get(Object(error), "status");
|
|
82
|
+
if (!(error instanceof Error) || typeof code !== "string" || !code.startsWith("COMMENTS_") || typeof status !== "number") throw error;
|
|
83
|
+
const fix = Reflect.get(error, "fix");
|
|
84
|
+
const retryAfter = Reflect.get(error, "retryAfter");
|
|
85
|
+
return json({ error: {
|
|
86
|
+
code,
|
|
87
|
+
why: Reflect.get(error, "why") ?? error.message,
|
|
88
|
+
...typeof fix === "string" ? { fix } : {}
|
|
89
|
+
} }, {
|
|
90
|
+
status,
|
|
91
|
+
...typeof retryAfter === "number" ? { headers: { "retry-after": String(Math.ceil(retryAfter)) } } : {}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/** The REST code of a diagnostic of the comment actions. Codes without one, such as `COMMENTS_R0019`, stay as they are. */
|
|
95
|
+
const restCodes = {
|
|
96
|
+
COMMENTS_R0002: "COMMENTS_NOT_FOUND",
|
|
97
|
+
COMMENTS_R0003: "COMMENTS_NOT_FOUND",
|
|
98
|
+
COMMENTS_R0004: "COMMENTS_FORBIDDEN",
|
|
99
|
+
COMMENTS_R0005: "COMMENTS_INVALID_INPUT",
|
|
100
|
+
COMMENTS_R0006: "COMMENTS_POLICY_MISSING",
|
|
101
|
+
COMMENTS_R0007: "COMMENTS_INVALID_INPUT",
|
|
102
|
+
COMMENTS_R0008: "COMMENTS_INVALID_INPUT",
|
|
103
|
+
COMMENTS_R0009: "COMMENTS_FORBIDDEN",
|
|
104
|
+
COMMENTS_R0012: "COMMENTS_FORBIDDEN",
|
|
105
|
+
COMMENTS_R0016: "COMMENTS_RESOLVED",
|
|
106
|
+
COMMENTS_R0017: "COMMENTS_INVALID_INPUT",
|
|
107
|
+
COMMENTS_R0018: "COMMENTS_INVALID_INPUT"
|
|
108
|
+
};
|
|
109
|
+
/** A failure of a comment action as the API's error object: the REST code, and the status of the diagnostic. */
|
|
110
|
+
function actionFailure(error, action) {
|
|
111
|
+
const code = Reflect.get(Object(error), "code");
|
|
112
|
+
const mapped = typeof code === "string" ? restCodes[code] : void 0;
|
|
113
|
+
if (!(error instanceof Error) || !mapped) return diagnosticResponse(error);
|
|
114
|
+
const why = String(Reflect.get(error, "why") ?? error.message);
|
|
115
|
+
const result = mapped === "COMMENTS_FORBIDDEN" ? commentsErrors.COMMENTS_FORBIDDEN({ action }) : mapped === "COMMENTS_POLICY_MISSING" ? commentsErrors.COMMENTS_POLICY_MISSING() : mapped === "COMMENTS_RESOLVED" ? commentsErrors.COMMENTS_RESOLVED() : mapped === "COMMENTS_NOT_FOUND" ? commentsErrors.COMMENTS_NOT_FOUND({ id: why }) : commentsErrors.COMMENTS_INVALID_INPUT({ issue: why });
|
|
116
|
+
const statusOf = Reflect.get(error, "status");
|
|
117
|
+
return json({ error: mapped === "COMMENTS_NOT_FOUND" ? {
|
|
118
|
+
...result,
|
|
119
|
+
why
|
|
120
|
+
} : result }, { status: mapped === "COMMENTS_INVALID_INPUT" && typeof statusOf === "number" ? statusOf : status(mapped) });
|
|
121
|
+
}
|
|
122
|
+
/** Response headers for a stored file: its checked type, a file name, and no way for the browser to run it. */
|
|
123
|
+
function attachmentHeaders(file) {
|
|
124
|
+
return new Headers({
|
|
125
|
+
"cache-control": "private, max-age=300",
|
|
126
|
+
"content-disposition": `${file.inline ? "inline" : "attachment"}; filename*=UTF-8''${encodeURIComponent(file.name)}`,
|
|
127
|
+
"content-length": String(file.size),
|
|
128
|
+
"content-security-policy": "default-src 'none'; sandbox",
|
|
129
|
+
"content-type": file.type === "text/plain" ? "text/plain; charset=utf-8" : file.type,
|
|
130
|
+
"cross-origin-resource-policy": "same-origin",
|
|
131
|
+
"x-content-type-options": "nosniff"
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
function respond([error, data]) {
|
|
135
|
+
return error ? failure$1(error) : json({ data: data ?? null });
|
|
136
|
+
}
|
|
137
|
+
function sameOrigin(request) {
|
|
138
|
+
const origin = request.headers.get("origin");
|
|
139
|
+
return !origin || origin === forwardedRequestOrigin(request);
|
|
140
|
+
}
|
|
141
|
+
function readPath(data, path) {
|
|
142
|
+
let current = data;
|
|
143
|
+
for (const key of path) {
|
|
144
|
+
if (current === null || typeof current !== "object") return void 0;
|
|
145
|
+
current = Reflect.get(current, key);
|
|
146
|
+
}
|
|
147
|
+
return current;
|
|
148
|
+
}
|
|
149
|
+
function writePath(data, path, value) {
|
|
150
|
+
const copy = structuredClone(data);
|
|
151
|
+
let current = copy;
|
|
152
|
+
for (const key of path.slice(0, -1)) current = Reflect.get(Object(current), key);
|
|
153
|
+
Reflect.set(Object(current), path.at(-1), value);
|
|
154
|
+
return copy;
|
|
155
|
+
}
|
|
156
|
+
function errorCode(error) {
|
|
157
|
+
return error instanceof Error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
158
|
+
}
|
|
159
|
+
function leaseHolder(error) {
|
|
160
|
+
const details = error instanceof Error && "details" in error ? error.details : void 0;
|
|
161
|
+
const name = readPath(details, [
|
|
162
|
+
"holder",
|
|
163
|
+
"user",
|
|
164
|
+
"name"
|
|
165
|
+
]) ?? readPath(details, [
|
|
166
|
+
"holder",
|
|
167
|
+
"user",
|
|
168
|
+
"id"
|
|
169
|
+
]);
|
|
170
|
+
return typeof name === "string" && name ? name : "Someone";
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The Comments API at `/api/_vitehub/comments/**`, as a Fetchable: mount it as a Nitro or H3 route, or call
|
|
174
|
+
* `fetch(request)`. The overlay calls it; every route checks the `authorize` policy of `defineComments()` for the user of
|
|
175
|
+
* the request, and inline edits also check `content.can()`.
|
|
176
|
+
*/
|
|
177
|
+
function createCommentsHandler(options) {
|
|
178
|
+
const { comments } = options;
|
|
179
|
+
/** The user of the request. See `resolveCommentsIdentity()`. */
|
|
180
|
+
async function identityOf(request) {
|
|
181
|
+
return resolveCommentsIdentity(comments, request, options);
|
|
182
|
+
}
|
|
183
|
+
async function access(request, action, thread, subject) {
|
|
184
|
+
const { user, gate } = await identityOf(request);
|
|
185
|
+
if (!await comments.can({
|
|
186
|
+
user,
|
|
187
|
+
action,
|
|
188
|
+
...thread ? { thread } : {},
|
|
189
|
+
...subject ? { subject } : {}
|
|
190
|
+
}, gate)) return [deniedForMissingPolicy(comments.options, user, {
|
|
191
|
+
...gate,
|
|
192
|
+
development: (await resolveCommentsRuntime(comments))?.development === true
|
|
193
|
+
}) ? commentsErrors.COMMENTS_POLICY_MISSING() : commentsErrors.COMMENTS_FORBIDDEN({ action }), void 0];
|
|
194
|
+
return [void 0, {
|
|
195
|
+
user,
|
|
196
|
+
gate,
|
|
197
|
+
author: user ? authorOf(user) : guestFromHeaders(request.headers)
|
|
198
|
+
}];
|
|
199
|
+
}
|
|
200
|
+
/** The caller of a comment action: the user of the request. */
|
|
201
|
+
async function callerOf(request) {
|
|
202
|
+
const runtime = await resolveCommentsRuntime(comments);
|
|
203
|
+
if (!runtime) return { denied: failure$1(commentsErrors.COMMENTS_NOT_INSTALLED()) };
|
|
204
|
+
const identity = await identityOf(request);
|
|
205
|
+
const waitUntil = request["~standard"].waitUntil;
|
|
206
|
+
return { who: {
|
|
207
|
+
gate: {
|
|
208
|
+
...identity.gate,
|
|
209
|
+
development: runtime.development === true
|
|
210
|
+
},
|
|
211
|
+
request,
|
|
212
|
+
runtime,
|
|
213
|
+
user: identity.user,
|
|
214
|
+
...waitUntil ? { waitUntil } : {}
|
|
215
|
+
} };
|
|
216
|
+
}
|
|
217
|
+
/** Runs a comment action for the request, and answers its diagnostics as the API's error objects. */
|
|
218
|
+
async function act(request, action, run, answer) {
|
|
219
|
+
const called = await callerOf(request);
|
|
220
|
+
if ("denied" in called) return called.denied;
|
|
221
|
+
let value;
|
|
222
|
+
try {
|
|
223
|
+
value = await run(called.who);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return actionFailure(error, action);
|
|
226
|
+
}
|
|
227
|
+
return await answer(value, called.who);
|
|
228
|
+
}
|
|
229
|
+
/** Adds the build, and the source files of each component, to the context that the overlay read. */
|
|
230
|
+
function completeContext(context) {
|
|
231
|
+
const named = context.components?.map((component) => {
|
|
232
|
+
const files = options.components && Object.hasOwn(options.components, component.name) ? options.components[component.name] : void 0;
|
|
233
|
+
return files?.length ? {
|
|
234
|
+
name: component.name,
|
|
235
|
+
files: files.slice(0, 8)
|
|
236
|
+
} : { name: component.name };
|
|
237
|
+
});
|
|
238
|
+
const own = named?.filter((component) => component.files);
|
|
239
|
+
const components = own?.length ? own : named?.slice(-3);
|
|
240
|
+
const { build: _build, ...read } = context;
|
|
241
|
+
return {
|
|
242
|
+
...read,
|
|
243
|
+
...components ? { components } : {},
|
|
244
|
+
...options.build && Object.values(options.build).some(Boolean) ? { build: options.build } : {}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async function readJson(request) {
|
|
248
|
+
try {
|
|
249
|
+
return await request.json();
|
|
250
|
+
} catch {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
function invalid(issues) {
|
|
255
|
+
return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: describeIssue(issues) }));
|
|
256
|
+
}
|
|
257
|
+
/** Who the overlay's person is, what they may do, and the subject of the page. The page tools session decides whether the overlay loads. */
|
|
258
|
+
async function session(request, subject, revision) {
|
|
259
|
+
const identity = await identityOf(request);
|
|
260
|
+
const { user } = identity;
|
|
261
|
+
const [read, comment, resolve, remove] = await Promise.all([
|
|
262
|
+
"read",
|
|
263
|
+
"write",
|
|
264
|
+
"resolve",
|
|
265
|
+
"delete"
|
|
266
|
+
].map((action) => can$1(identity, action, void 0, subject)));
|
|
267
|
+
const github = options.githubLogin?.configured() ? options.githubLogin : void 0;
|
|
268
|
+
const pathname = new URL(request.url).pathname;
|
|
269
|
+
const route = pathname.slice(0, pathname.indexOf(commentsRoute) + commentsRoute.length);
|
|
270
|
+
const signIn = !user && !comments.options.identify && github ? {
|
|
271
|
+
provider: "github",
|
|
272
|
+
url: `${route}/auth/github`
|
|
273
|
+
} : void 0;
|
|
274
|
+
const signOut = user && user.github && github ? `${route}/auth/sign-out` : void 0;
|
|
275
|
+
return json({ data: {
|
|
276
|
+
user: user ? authorOf(user) : null,
|
|
277
|
+
...user && user.github ? { github: user.github } : {},
|
|
278
|
+
can: {
|
|
279
|
+
read,
|
|
280
|
+
comment,
|
|
281
|
+
resolve,
|
|
282
|
+
delete: remove
|
|
283
|
+
},
|
|
284
|
+
...signIn ? { signIn } : {},
|
|
285
|
+
...signOut ? { signOut } : {},
|
|
286
|
+
realtime: options.realtime,
|
|
287
|
+
...options.presence === false ? { presence: false } : {},
|
|
288
|
+
content: Boolean(options.content),
|
|
289
|
+
...subject ? { subject } : {},
|
|
290
|
+
...revision === void 0 ? {} : { revision }
|
|
291
|
+
} });
|
|
292
|
+
}
|
|
293
|
+
async function can$1(identity, action, thread, subject) {
|
|
294
|
+
return comments.can({
|
|
295
|
+
user: identity.user,
|
|
296
|
+
action,
|
|
297
|
+
...thread ? { thread } : {},
|
|
298
|
+
...subject ? { subject } : {}
|
|
299
|
+
}, identity.gate);
|
|
300
|
+
}
|
|
301
|
+
async function permissions(who, thread) {
|
|
302
|
+
const [comment, resolve, remove] = await Promise.all([
|
|
303
|
+
"write",
|
|
304
|
+
"resolve",
|
|
305
|
+
"delete"
|
|
306
|
+
].map((action) => can$1(who, action, thread)));
|
|
307
|
+
return {
|
|
308
|
+
...thread,
|
|
309
|
+
can: {
|
|
310
|
+
comment,
|
|
311
|
+
resolve,
|
|
312
|
+
delete: remove
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
/** The people that the threads mention, so a UI shows their names. */
|
|
317
|
+
async function people(who, threads) {
|
|
318
|
+
return await mentionedPeople(who.runtime, who.user, threads, who.gate);
|
|
319
|
+
}
|
|
320
|
+
/** A thread with what the reader may do with it, and the people that it mentions. */
|
|
321
|
+
async function threadResponse(who, thread, extra = {}) {
|
|
322
|
+
if (!thread) return json({
|
|
323
|
+
data: null,
|
|
324
|
+
...extra
|
|
325
|
+
});
|
|
326
|
+
return json({
|
|
327
|
+
data: await permissions(who, thread),
|
|
328
|
+
people: await people(who, [thread]),
|
|
329
|
+
...extra
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
/** Lists check `read` on the filter first, so a person who may not read gets `403`, not an empty list. */
|
|
333
|
+
async function mayRead(who, subject) {
|
|
334
|
+
if (!await can(who.runtime, {
|
|
335
|
+
action: "read",
|
|
336
|
+
user: who.user,
|
|
337
|
+
...subject ? { subject } : {}
|
|
338
|
+
}, who.gate)) throw deniedError(who.runtime, "read", who.user, who.gate);
|
|
339
|
+
}
|
|
340
|
+
/** The list query of `GET /threads`: the filters of `comments.list` as search parameters. */
|
|
341
|
+
/** `page`: the subject that `page` of `defineComments()` gives for the `?page=` path, as the overlay sees it. */
|
|
342
|
+
function listQuery(url, page) {
|
|
343
|
+
const params = url.searchParams;
|
|
344
|
+
const number = (name) => params.has(name) ? Number(params.get(name)) : void 0;
|
|
345
|
+
const flag = (name) => params.has(name) ? params.get(name) === "true" || params.get(name) === "1" : void 0;
|
|
346
|
+
const kind = params.get("subjectKind");
|
|
347
|
+
const subjectId = params.get("subjectId");
|
|
348
|
+
const state = params.get("status");
|
|
349
|
+
const lte = number("revision");
|
|
350
|
+
const beforeId = params.get("beforeId");
|
|
351
|
+
const beforeUpdatedAt = number("beforeUpdatedAt");
|
|
352
|
+
const parsed = v.safeParse(commentInputSchemas.list, {
|
|
353
|
+
...page ? { subject: page } : kind && subjectId ? { subject: {
|
|
354
|
+
kind,
|
|
355
|
+
id: subjectId
|
|
356
|
+
} } : kind ? { subjectKind: kind } : {},
|
|
357
|
+
...state === "open" || state === "resolved" ? { status: state } : {},
|
|
358
|
+
...lte === void 0 ? {} : { revision: { lte } },
|
|
359
|
+
...number("limit") === void 0 ? {} : { limit: number("limit") },
|
|
360
|
+
...beforeId && beforeUpdatedAt !== void 0 ? { before: {
|
|
361
|
+
id: beforeId,
|
|
362
|
+
updatedAt: beforeUpdatedAt
|
|
363
|
+
} } : {},
|
|
364
|
+
...flag("mine") === void 0 ? {} : { mine: flag("mine") },
|
|
365
|
+
...flag("mentions") === void 0 ? {} : { mentions: flag("mentions") }
|
|
366
|
+
});
|
|
367
|
+
return parsed.success ? [void 0, parsed.output] : [commentsErrors.COMMENTS_INVALID_INPUT({ issue: describeIssue(parsed.issues) }), void 0];
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Checks the page context that the overlay read: same origin, and a thread on the subject of that page. Keeps only
|
|
371
|
+
* the origin and the path, and gives the revision of the page subject.
|
|
372
|
+
*/
|
|
373
|
+
async function checkContext(request, context, subject) {
|
|
374
|
+
const origin = forwardedRequestOrigin(request);
|
|
375
|
+
let submitted;
|
|
376
|
+
try {
|
|
377
|
+
submitted = new URL(context.url);
|
|
378
|
+
} catch {
|
|
379
|
+
return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: "context.url: Expected an absolute page URL." }), void 0];
|
|
380
|
+
}
|
|
381
|
+
if (submitted.origin !== origin) return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: "context.url: Must match the request origin and thread page." }), void 0];
|
|
382
|
+
const page = normalizeCommentPage(submitted.pathname);
|
|
383
|
+
const expected = await resolveCommentsPage(comments, request, request, page);
|
|
384
|
+
if (expected.subject.kind !== subject.kind || expected.subject.id !== subject.id) return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: `context.url: The page ${page} maps to the subject ${expected.subject.kind}:${expected.subject.id}, not ${subject.kind}:${subject.id}.` }), void 0];
|
|
385
|
+
return [void 0, {
|
|
386
|
+
context: completeContext({
|
|
387
|
+
...context,
|
|
388
|
+
url: `${origin}${page}`
|
|
389
|
+
}),
|
|
390
|
+
...expected.revision === void 0 ? {} : { revision: expected.revision }
|
|
391
|
+
}];
|
|
392
|
+
}
|
|
393
|
+
async function fieldTarget(request, address, subject) {
|
|
394
|
+
if (!options.content) return [commentsErrors.COMMENTS_CONTENT_MISSING(), void 0];
|
|
395
|
+
const [denied, allowed] = await access(request, "write", void 0, subject);
|
|
396
|
+
if (denied) return [denied, void 0];
|
|
397
|
+
const parsed = options.content.parseField(address);
|
|
398
|
+
const collection = parsed && options.content.runtime.collections().find((candidate) => candidate.name === parsed.collection);
|
|
399
|
+
const id = collection?.kind === "singleton" ? collection.id : parsed?.id;
|
|
400
|
+
if (!parsed || !collection || !id) return [commentsErrors.COMMENTS_FIELD_INVALID({ field: address }), void 0];
|
|
401
|
+
if (!allowed.author) return [commentsErrors.COMMENTS_FORBIDDEN({ action: "write" }), void 0];
|
|
402
|
+
if (!await options.content.runtime.can({
|
|
403
|
+
user: allowed.user ?? void 0,
|
|
404
|
+
collection: collection.name,
|
|
405
|
+
action: "write",
|
|
406
|
+
id
|
|
407
|
+
})) return [commentsErrors.COMMENTS_FIELD_FORBIDDEN({ field: address }), void 0];
|
|
408
|
+
const document = await collection.get(id, { ref: "draft" });
|
|
409
|
+
if (!document) return [commentsErrors.COMMENTS_FIELD_INVALID({ field: address }), void 0];
|
|
410
|
+
return [void 0, {
|
|
411
|
+
collection,
|
|
412
|
+
id,
|
|
413
|
+
path: parsed.field.split("."),
|
|
414
|
+
document,
|
|
415
|
+
author: allowed.author,
|
|
416
|
+
user: allowed.user
|
|
417
|
+
}];
|
|
418
|
+
}
|
|
419
|
+
async function readField(request, address, subject) {
|
|
420
|
+
const [error, target] = await fieldTarget(request, address, subject);
|
|
421
|
+
if (error) return failure$1(error);
|
|
422
|
+
const value = readPath(target.document.data, target.path);
|
|
423
|
+
return json({ data: {
|
|
424
|
+
field: address,
|
|
425
|
+
value: typeof value === "string" ? value : null,
|
|
426
|
+
editable: typeof value === "string",
|
|
427
|
+
digest: target.document.digest,
|
|
428
|
+
collection: target.collection.name,
|
|
429
|
+
id: target.id
|
|
430
|
+
} });
|
|
431
|
+
}
|
|
432
|
+
async function saveField(request, subject) {
|
|
433
|
+
const parsed = v.safeParse(fieldBody, await readJson(request));
|
|
434
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
435
|
+
const [error, target] = await fieldTarget(request, parsed.output.field, subject);
|
|
436
|
+
if (error) return failure$1(error);
|
|
437
|
+
if (typeof readPath(target.document.data, target.path) !== "string") return failure$1(commentsErrors.COMMENTS_FIELD_NOT_EDITABLE({ field: parsed.output.field }));
|
|
438
|
+
if (target.document.digest !== parsed.output.ifDigest) return failure$1(commentsErrors.COMMENTS_FIELD_CONFLICT({ field: parsed.output.field }));
|
|
439
|
+
return await writeField(fieldEditGrant.issue({
|
|
440
|
+
collection: target.collection,
|
|
441
|
+
id: target.id,
|
|
442
|
+
field: parsed.output.field,
|
|
443
|
+
user: target.author
|
|
444
|
+
}), target, parsed.output);
|
|
445
|
+
}
|
|
446
|
+
/** Saves one field as a new draft. It needs the grant that `saveField` issues after `authorize` and `content.can()`. */
|
|
447
|
+
async function writeField(grant, target, input) {
|
|
448
|
+
const { collection, id, field, user } = fieldEditGrant.consume(grant);
|
|
449
|
+
try {
|
|
450
|
+
const saved = await collection.save(id, {
|
|
451
|
+
data: writePath(target.document.data, target.path, input.value),
|
|
452
|
+
...target.document.body === void 0 || collection.format !== "markdown" ? {} : { body: target.document.body }
|
|
453
|
+
}, {
|
|
454
|
+
ifDigest: input.ifDigest,
|
|
455
|
+
message: `Edit ${target.path.join(".")} on the page`,
|
|
456
|
+
metadata: {
|
|
457
|
+
source: "comments",
|
|
458
|
+
author: user.name ?? user.id
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
return json({ data: {
|
|
462
|
+
field,
|
|
463
|
+
value: input.value,
|
|
464
|
+
digest: saved.digest
|
|
465
|
+
} });
|
|
466
|
+
} catch (cause) {
|
|
467
|
+
const code = errorCode(cause);
|
|
468
|
+
if (code === "WORKSPACE_CONFLICT") return failure$1(commentsErrors.COMMENTS_FIELD_CONFLICT({ field }));
|
|
469
|
+
if (code === "CONTENT_LEASE_HELD") return failure$1(commentsErrors.COMMENTS_FIELD_LOCKED({ holder: leaseHolder(cause) }));
|
|
470
|
+
throw cause;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
async function handle(request) {
|
|
474
|
+
const response = await route(request).catch(diagnosticResponse);
|
|
475
|
+
if (request.method !== "GET" && comments.options.forge) request["~standard"].waitUntil?.(comments.flush());
|
|
476
|
+
return response;
|
|
477
|
+
}
|
|
478
|
+
return { async fetch(input) {
|
|
479
|
+
installRequestStandardContext(input);
|
|
480
|
+
const request = input;
|
|
481
|
+
const env = request["~standard"].runtime?.cloudflare?.env;
|
|
482
|
+
return env ? await runWithActiveCloudflareEnv(env, () => handle(request)) : await handle(request);
|
|
483
|
+
} };
|
|
484
|
+
async function route(request) {
|
|
485
|
+
const url = new URL(request.url);
|
|
486
|
+
const path = url.pathname.slice(url.pathname.indexOf("/api/_vitehub/comments") + 22).replace(/\/+$/, "") || "/";
|
|
487
|
+
const parts = path.split("/").filter(Boolean);
|
|
488
|
+
const method = request.method;
|
|
489
|
+
const page = url.searchParams.get("page");
|
|
490
|
+
const subjectKind = url.searchParams.get("subjectKind");
|
|
491
|
+
const subjectId = url.searchParams.get("subjectId");
|
|
492
|
+
const pageOf = async () => page ? await resolveCommentsPage(comments, request, request, page) : subjectKind && subjectId ? { subject: {
|
|
493
|
+
kind: subjectKind,
|
|
494
|
+
id: subjectId
|
|
495
|
+
} } : void 0;
|
|
496
|
+
const subjectOf = async () => (await pageOf())?.subject;
|
|
497
|
+
if (method !== "GET" && !sameOrigin(request)) return json({ error: {
|
|
498
|
+
code: "COMMENTS_FORBIDDEN",
|
|
499
|
+
why: "Comments requests must come from the site's own pages."
|
|
500
|
+
} }, { status: 403 });
|
|
501
|
+
if (method === "GET" && path === "/session") {
|
|
502
|
+
const current = await pageOf();
|
|
503
|
+
return await session(request, current?.subject, current?.revision);
|
|
504
|
+
}
|
|
505
|
+
if (path.startsWith("/auth/") && options.githubLogin) return await options.githubLogin.handle(request, path);
|
|
506
|
+
if (path === "/threads") {
|
|
507
|
+
if (method === "GET") {
|
|
508
|
+
const [invalidQuery, query] = listQuery(url, page ? await subjectOf() : void 0);
|
|
509
|
+
if (invalidQuery) return failure$1(invalidQuery);
|
|
510
|
+
return await act(request, "read", async (who) => {
|
|
511
|
+
await mayRead(who, query.subject);
|
|
512
|
+
return await commentActions.list(query, who);
|
|
513
|
+
}, async (threads, who) => json({
|
|
514
|
+
data: await Promise.all(threads.map((thread) => permissions(who, thread))),
|
|
515
|
+
people: await people(who, threads)
|
|
516
|
+
}));
|
|
517
|
+
}
|
|
518
|
+
if (method === "POST") {
|
|
519
|
+
const parsed = v.safeParse(createBody, await readJson(request));
|
|
520
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
521
|
+
const { page, subject: given, context, anchor, ...input } = parsed.output;
|
|
522
|
+
const mappedPage = given || page === void 0 ? void 0 : await resolveCommentsPage(comments, request, request, page);
|
|
523
|
+
const target = given ?? mappedPage?.subject;
|
|
524
|
+
if (!target) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "subject: Give a subject, or a page." }));
|
|
525
|
+
const [badContext, checked] = context ? await checkContext(request, context, target) : [void 0, void 0];
|
|
526
|
+
if (badContext) return failure$1(badContext);
|
|
527
|
+
const mapped = checked?.revision ?? mappedPage?.revision;
|
|
528
|
+
const revision = mapped === void 0 ? input.revision : input.revision !== void 0 && input.revision <= mapped ? input.revision : mapped;
|
|
529
|
+
return await act(request, "write", (who) => commentActions.create({
|
|
530
|
+
...input,
|
|
531
|
+
anchor: anchor ?? { kind: "page" },
|
|
532
|
+
subject: target,
|
|
533
|
+
...checked ? { context: checked.context } : {},
|
|
534
|
+
...revision === void 0 ? {} : { revision }
|
|
535
|
+
}, who), (thread, who) => threadResponse(who, thread));
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (parts[0] === "scopes" && parts[1] && parts[2] === "threads" && parts[3] && !parts[4] && method === "GET") {
|
|
539
|
+
const parsed = v.safeParse(commentInputSchemas.get, {
|
|
540
|
+
scope: decodeURIComponent(parts[1]),
|
|
541
|
+
n: Number(parts[3])
|
|
542
|
+
});
|
|
543
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
544
|
+
return await act(request, "read", (who) => commentActions.get(parsed.output, who), (thread, who) => threadResponse(who, thread));
|
|
545
|
+
}
|
|
546
|
+
if (parts[0] === "threads" && parts[1]) {
|
|
547
|
+
const threadId = decodeURIComponent(parts[1]);
|
|
548
|
+
const action = parts[2];
|
|
549
|
+
const messageId = parts[3] ? decodeURIComponent(parts[3]) : void 0;
|
|
550
|
+
if (method === "GET" && !action) return await act(request, "read", (who) => commentActions.get({ id: threadId }, who), (thread, who) => threadResponse(who, thread));
|
|
551
|
+
if (method === "POST" && action === "comments" && !messageId) {
|
|
552
|
+
const parsed = v.safeParse(replyBody, await readJson(request));
|
|
553
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
554
|
+
return await act(request, "write", (who) => commentActions.reply({
|
|
555
|
+
...parsed.output,
|
|
556
|
+
threadId
|
|
557
|
+
}, who), async ({ message, thread }, who) => json({
|
|
558
|
+
data: message,
|
|
559
|
+
thread: await permissions(who, thread),
|
|
560
|
+
people: await people(who, [thread])
|
|
561
|
+
}));
|
|
562
|
+
}
|
|
563
|
+
if (method === "PATCH" && action === "comments" && messageId) {
|
|
564
|
+
const parsed = v.safeParse(editBody, await readJson(request));
|
|
565
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
566
|
+
return await act(request, "write", (who) => commentActions.edit({
|
|
567
|
+
...parsed.output,
|
|
568
|
+
threadId,
|
|
569
|
+
messageId
|
|
570
|
+
}, who), (thread, who) => threadResponse(who, thread));
|
|
571
|
+
}
|
|
572
|
+
if (method === "POST" && (action === "resolve" || action === "reopen") && !messageId) return await act(request, "resolve", (who) => commentActions.setStatus({ threadId }, who, action === "resolve" ? "resolved" : "open"), (thread, who) => threadResponse(who, thread));
|
|
573
|
+
if (method === "DELETE" && (action === "comments" ? messageId : !action)) return await act(request, "delete", (who) => commentActions.delete({
|
|
574
|
+
threadId,
|
|
575
|
+
...messageId ? { messageId } : {}
|
|
576
|
+
}, who), (thread, who) => threadResponse(who, thread));
|
|
577
|
+
}
|
|
578
|
+
if (path === "/attachments" && method === "POST") {
|
|
579
|
+
const parsed = v.safeParse(commentInputSchemas.upload, await readJson(request));
|
|
580
|
+
if (!parsed.success) return invalid(parsed.issues);
|
|
581
|
+
return await act(request, "write", (who) => commentActions.upload(parsed.output, who), (attachment) => json({ data: attachment }));
|
|
582
|
+
}
|
|
583
|
+
if (parts[0] === "attachments" && parts.length > 1 && method === "GET") {
|
|
584
|
+
const key = parts.slice(1).map((part) => decodeURIComponent(part)).join("/");
|
|
585
|
+
return await act(request, "read", (who) => commentActions.attachment({ key }, who), (file) => new Response(file.data.stream(), { headers: attachmentHeaders(file) }));
|
|
586
|
+
}
|
|
587
|
+
if (method === "GET" && path === "/people") {
|
|
588
|
+
const threadId = url.searchParams.get("thread");
|
|
589
|
+
const [missing, current] = threadId ? await comments.get(threadId) : [void 0, void 0];
|
|
590
|
+
if (missing) return failure$1(missing);
|
|
591
|
+
const target = current?.subject ?? await subjectOf();
|
|
592
|
+
const [denied, allowed] = await access(request, "read", current, target);
|
|
593
|
+
if (denied) return failure$1(denied);
|
|
594
|
+
const limit = Number(url.searchParams.get("limit") ?? 20);
|
|
595
|
+
return respond(await comments.people({
|
|
596
|
+
query: url.searchParams.get("q") ?? "",
|
|
597
|
+
user: allowed.user,
|
|
598
|
+
gate: allowed.gate,
|
|
599
|
+
...Number.isFinite(limit) ? { limit } : {},
|
|
600
|
+
...current ? { thread: current } : {},
|
|
601
|
+
...target ? { subject: target } : {}
|
|
602
|
+
}));
|
|
603
|
+
}
|
|
604
|
+
if (path === "/fields") {
|
|
605
|
+
const subject = page ? await subjectOf() : void 0;
|
|
606
|
+
if (!subject) return failure$1(commentsErrors.COMMENTS_INVALID_INPUT({ issue: "page: Give the current page for a field edit." }));
|
|
607
|
+
if (method === "GET") return await readField(request, url.searchParams.get("field") ?? "", subject);
|
|
608
|
+
if (method === "POST") return await saveField(request, subject);
|
|
609
|
+
}
|
|
610
|
+
return json({ error: {
|
|
611
|
+
code: "COMMENTS_NOT_FOUND",
|
|
612
|
+
why: `No Comments route ${method} ${path}.`
|
|
613
|
+
} }, { status: 404 });
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/runtime/database.ts
|
|
618
|
+
/**
|
|
619
|
+
* The Database that `defineComments({ database })` names, else `default`, else the only one. The plugin calls it when
|
|
620
|
+
* the server starts. On Cloudflare that is before any request, so a D1 Database can't connect yet: its db throws until
|
|
621
|
+
* a request brings the binding. An app without a default Database uses a placeholder that throws
|
|
622
|
+
* `DATABASE_DISABLED` or `DATABASE_NOT_FOUND`. The store reads the db per query, by which time the binding is there.
|
|
623
|
+
*/
|
|
624
|
+
function selectCommentsDatabase(databases, name) {
|
|
625
|
+
if (name) return databases[name]?.db;
|
|
626
|
+
const fallback = databases.default?.db;
|
|
627
|
+
if (fallback && !isPlaceholder(fallback)) return fallback;
|
|
628
|
+
const names = Object.keys(databases).filter((key) => key !== "default");
|
|
629
|
+
return names.length === 1 ? databases[names[0]]?.db : void 0;
|
|
630
|
+
}
|
|
631
|
+
function isPlaceholder(db) {
|
|
632
|
+
try {
|
|
633
|
+
Reflect.get(db, "select");
|
|
634
|
+
return false;
|
|
635
|
+
} catch (error) {
|
|
636
|
+
const code = error?.code;
|
|
637
|
+
return code === "DATABASE_DISABLED" || code === "DATABASE_NOT_FOUND";
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
//#endregion
|
|
641
|
+
//#region src/runtime/definition.ts
|
|
642
|
+
/**
|
|
643
|
+
* The Comments definition of `server/comments.ts`: its `comments` export, else its default export. Both forms run the
|
|
644
|
+
* same surfaces. The generated files call it, so a file without `defineComments()` fails with `COMMENTS_B0002`.
|
|
645
|
+
*/
|
|
646
|
+
function commentsDefinitionOf(module, file) {
|
|
647
|
+
return validateCommentsDefinition(module.comments ?? module.default, file);
|
|
648
|
+
}
|
|
649
|
+
//#endregion
|
|
650
|
+
//#region src/runtime/mcp.ts
|
|
651
|
+
/** A user supplied by an app's own MCP server. Missing identities remain anonymous. */
|
|
652
|
+
function commentsUser(user) {
|
|
653
|
+
const id = text(user?.id) ?? text(user?.email);
|
|
654
|
+
return user && id ? {
|
|
655
|
+
...user,
|
|
656
|
+
id
|
|
657
|
+
} : null;
|
|
658
|
+
}
|
|
659
|
+
function guestFor(context) {
|
|
660
|
+
return context.event ? guestFromHeaders(context.event["~standard"].req.headers) : void 0;
|
|
661
|
+
}
|
|
662
|
+
function failure(why) {
|
|
663
|
+
return {
|
|
664
|
+
text: why,
|
|
665
|
+
isError: true
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
/** The catalog's COMMENTS_FORBIDDEN, as the overlay API answers it. */
|
|
669
|
+
function forbidden(action) {
|
|
670
|
+
const error = commentsErrors.COMMENTS_FORBIDDEN({ action });
|
|
671
|
+
return failure(`${error.why} ${error.fix}`);
|
|
672
|
+
}
|
|
673
|
+
/** Issued after `authorize` allows a tool's action on a thread. The reply and resolve writes need it. */
|
|
674
|
+
const toolGrant = defineGrant("vitehub.comments.mcp-action", (input) => Object.freeze({ ...input }));
|
|
675
|
+
function spend(grant, action, threadId) {
|
|
676
|
+
const allowed = toolGrant.consume(grant);
|
|
677
|
+
invariant(allowed.action === action && allowed.threadId === threadId, "each Comments tool spends the grant that it issued for the same action and thread");
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* The Comments tools for an app's own MCP server. Each call resolves the Comments identity and checks `authorize`,
|
|
681
|
+
* as the overlay does. The server supplies the checked `context.user`. ViteHub MCP offers the comment operations instead.
|
|
682
|
+
* With `identify` and a request event, `identify` names the user, as in the overlay API. Otherwise the tools use the
|
|
683
|
+
* checked `context.user`. Replies and resolves show that user as the author.
|
|
684
|
+
*/
|
|
685
|
+
function commentsMcpTools(comments, options = {}) {
|
|
686
|
+
const admitted = options.console === true;
|
|
687
|
+
async function identityFor(context) {
|
|
688
|
+
const { identify } = comments.options;
|
|
689
|
+
if (identify && context.event) {
|
|
690
|
+
const event = context.event;
|
|
691
|
+
getStandardContext(event);
|
|
692
|
+
return {
|
|
693
|
+
user: await identify({ event }) ?? null,
|
|
694
|
+
gate: {}
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
return {
|
|
698
|
+
user: commentsUser(context.user),
|
|
699
|
+
gate: options.console && !identify ? { console: true } : {}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
async function threadFor(input, { user, gate }, action) {
|
|
703
|
+
const id = text(input.id);
|
|
704
|
+
if (!id) return failure("Give the thread id from comments_list_threads.");
|
|
705
|
+
const [error, thread] = await comments.get(id);
|
|
706
|
+
if (error) return failure(error.why);
|
|
707
|
+
if (thread.subject.kind !== "page") return failure(`No thread ${id} on the app's pages.`);
|
|
708
|
+
if (!await comments.can({
|
|
709
|
+
user,
|
|
710
|
+
action,
|
|
711
|
+
thread,
|
|
712
|
+
console: admitted
|
|
713
|
+
}, gate)) return forbidden(action);
|
|
714
|
+
return {
|
|
715
|
+
thread,
|
|
716
|
+
grant: toolGrant.issue({
|
|
717
|
+
action,
|
|
718
|
+
threadId: thread.id
|
|
719
|
+
})
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
return [
|
|
723
|
+
{
|
|
724
|
+
name: "comments_list_threads",
|
|
725
|
+
title: "List ViteHub Comments threads",
|
|
726
|
+
description: "ViteHub Comments: threads people left with the Comments toolbar on the app's pages, newest activity first. Each line has the page, what the comment points at, the time, the first comment, and the Vue component. Says how many threads `authorize` hid. Read one with comments_get_thread. After you change the code, reply with comments_reply and resolve it with comments_resolve_thread.",
|
|
727
|
+
section: "comments",
|
|
728
|
+
annotations: { readOnlyHint: true },
|
|
729
|
+
inputSchema: {
|
|
730
|
+
type: "object",
|
|
731
|
+
properties: {
|
|
732
|
+
page: {
|
|
733
|
+
type: "string",
|
|
734
|
+
description: "Only threads of this page: a path such as /pricing, or a full URL of the page."
|
|
735
|
+
},
|
|
736
|
+
status: {
|
|
737
|
+
type: "string",
|
|
738
|
+
enum: ["open", "resolved"],
|
|
739
|
+
description: "Default: open."
|
|
740
|
+
},
|
|
741
|
+
search: {
|
|
742
|
+
type: "string",
|
|
743
|
+
description: "Only threads whose comments contain this text."
|
|
744
|
+
},
|
|
745
|
+
limit: {
|
|
746
|
+
type: "integer",
|
|
747
|
+
minimum: 1,
|
|
748
|
+
maximum: 100,
|
|
749
|
+
description: "Default 25."
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
additionalProperties: false
|
|
753
|
+
},
|
|
754
|
+
async call(input, context) {
|
|
755
|
+
const { user, gate } = await identityFor(context);
|
|
756
|
+
const page = text(input.page);
|
|
757
|
+
const subject = page ? {
|
|
758
|
+
kind: "page",
|
|
759
|
+
id: normalizeCommentPage(page)
|
|
760
|
+
} : void 0;
|
|
761
|
+
if (!await comments.can({
|
|
762
|
+
user,
|
|
763
|
+
action: "read",
|
|
764
|
+
console: admitted,
|
|
765
|
+
...subject ? { subject } : {}
|
|
766
|
+
}, gate)) return forbidden("read");
|
|
767
|
+
const status = input.status === "resolved" ? "resolved" : "open";
|
|
768
|
+
const search = text(input.search)?.toLowerCase();
|
|
769
|
+
const limit = Math.min(Math.max(Number(input.limit) || 25, 1), 100);
|
|
770
|
+
const found = [];
|
|
771
|
+
let hidden = 0;
|
|
772
|
+
const batchSize = search ? 500 : limit;
|
|
773
|
+
let before;
|
|
774
|
+
while (found.length < limit) {
|
|
775
|
+
const [error, listed] = await comments.list({
|
|
776
|
+
scope: commentsPageScope,
|
|
777
|
+
subjectKind: "page",
|
|
778
|
+
status,
|
|
779
|
+
limit: batchSize,
|
|
780
|
+
...subject ? { subject } : {},
|
|
781
|
+
...before ? { before } : {}
|
|
782
|
+
});
|
|
783
|
+
if (error) return failure(error.why);
|
|
784
|
+
for (const thread of listed) {
|
|
785
|
+
if (!await comments.can({
|
|
786
|
+
user,
|
|
787
|
+
action: "read",
|
|
788
|
+
thread,
|
|
789
|
+
console: admitted
|
|
790
|
+
}, gate)) hidden++;
|
|
791
|
+
else if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
|
|
792
|
+
if (found.length === limit) break;
|
|
793
|
+
}
|
|
794
|
+
if (listed.length < batchSize) break;
|
|
795
|
+
const last = listed.at(-1);
|
|
796
|
+
before = {
|
|
797
|
+
id: last.id,
|
|
798
|
+
updatedAt: last.updatedAt
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
const threads = found.map(commentThreadSummary);
|
|
802
|
+
const note = hiddenThreadsNote(hidden, {
|
|
803
|
+
authorize: Boolean(comments.options.authorize),
|
|
804
|
+
identify: Boolean(comments.options.identify),
|
|
805
|
+
user: user !== null,
|
|
806
|
+
console: admitted
|
|
807
|
+
});
|
|
808
|
+
return {
|
|
809
|
+
text: commentThreadsText(threads, status, note),
|
|
810
|
+
structured: {
|
|
811
|
+
threads: threads.map((thread) => ({ ...thread })),
|
|
812
|
+
hidden
|
|
813
|
+
}
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
name: "comments_get_thread",
|
|
819
|
+
title: "Read a ViteHub Comments thread",
|
|
820
|
+
description: "ViteHub Comments: read one thread that people left with the Comments toolbar: its page, the element and Vue components with their source files, the browser and build, and every comment with its time. Use it to find the code to change.",
|
|
821
|
+
section: "comments",
|
|
822
|
+
annotations: { readOnlyHint: true },
|
|
823
|
+
inputSchema: {
|
|
824
|
+
type: "object",
|
|
825
|
+
properties: { id: {
|
|
826
|
+
type: "string",
|
|
827
|
+
description: "The thread id."
|
|
828
|
+
} },
|
|
829
|
+
required: ["id"],
|
|
830
|
+
additionalProperties: false
|
|
831
|
+
},
|
|
832
|
+
async call(input, context) {
|
|
833
|
+
const found = await threadFor(input, await identityFor(context), "read");
|
|
834
|
+
if (!("thread" in found)) return found;
|
|
835
|
+
const { thread } = found;
|
|
836
|
+
return {
|
|
837
|
+
text: describeCommentThread(thread),
|
|
838
|
+
structured: { thread: { ...thread } }
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
name: "comments_reply",
|
|
844
|
+
title: "Reply to a ViteHub Comments thread",
|
|
845
|
+
description: "ViteHub Comments: reply to a thread that people left with the Comments toolbar, for example to say what you changed. The reply shows the signed-in Console user as its author.",
|
|
846
|
+
section: "comments",
|
|
847
|
+
inputSchema: {
|
|
848
|
+
type: "object",
|
|
849
|
+
properties: {
|
|
850
|
+
id: {
|
|
851
|
+
type: "string",
|
|
852
|
+
description: "The thread id."
|
|
853
|
+
},
|
|
854
|
+
body: {
|
|
855
|
+
type: "string",
|
|
856
|
+
description: "Markdown, at most 10,000 characters."
|
|
857
|
+
}
|
|
858
|
+
},
|
|
859
|
+
required: ["id", "body"],
|
|
860
|
+
additionalProperties: false
|
|
861
|
+
},
|
|
862
|
+
async call(input, context) {
|
|
863
|
+
const identity = await identityFor(context);
|
|
864
|
+
const found = await threadFor(input, identity, "write");
|
|
865
|
+
if (!("thread" in found)) return found;
|
|
866
|
+
const { thread, grant } = found;
|
|
867
|
+
const author = identity.user ? authorOf(identity.user) : guestFor(context);
|
|
868
|
+
if (!author) return forbidden("write");
|
|
869
|
+
spend(grant, "write", thread.id);
|
|
870
|
+
const [error, message] = await comments.reply(thread.id, {
|
|
871
|
+
body: text(input.body) ?? "",
|
|
872
|
+
author
|
|
873
|
+
});
|
|
874
|
+
if (error) return failure(error.why);
|
|
875
|
+
await comments.flush();
|
|
876
|
+
return {
|
|
877
|
+
text: `Replied to thread ${thread.id}.`,
|
|
878
|
+
structured: { message: { ...message } }
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: "comments_resolve_thread",
|
|
884
|
+
title: "Resolve or reopen a ViteHub Comments thread",
|
|
885
|
+
description: "ViteHub Comments: resolve a thread that people left with the Comments toolbar after the change it asks for is done, or reopen it. Resolved threads leave the page.",
|
|
886
|
+
section: "comments",
|
|
887
|
+
inputSchema: {
|
|
888
|
+
type: "object",
|
|
889
|
+
properties: {
|
|
890
|
+
id: {
|
|
891
|
+
type: "string",
|
|
892
|
+
description: "The thread id."
|
|
893
|
+
},
|
|
894
|
+
resolved: {
|
|
895
|
+
type: "boolean",
|
|
896
|
+
description: "Default true. False reopens the thread."
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
required: ["id"],
|
|
900
|
+
additionalProperties: false
|
|
901
|
+
},
|
|
902
|
+
async call(input, context) {
|
|
903
|
+
const identity = await identityFor(context);
|
|
904
|
+
const found = await threadFor(input, identity, "resolve");
|
|
905
|
+
if (!("thread" in found)) return found;
|
|
906
|
+
const { thread, grant } = found;
|
|
907
|
+
spend(grant, "resolve", thread.id);
|
|
908
|
+
const author = identity.user ? authorOf(identity.user) : guestFor(context) ?? {
|
|
909
|
+
id: "anonymous",
|
|
910
|
+
name: "Someone"
|
|
911
|
+
};
|
|
912
|
+
const [error, updated] = input.resolved === false ? await comments.reopen(thread.id) : await comments.resolve(thread.id, { by: author });
|
|
913
|
+
if (error) return failure(error.why);
|
|
914
|
+
await comments.flush();
|
|
915
|
+
return {
|
|
916
|
+
text: `Thread ${updated.id} is ${updated.status}.`,
|
|
917
|
+
structured: { thread: { ...commentThreadSummary(updated) } }
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
];
|
|
922
|
+
}
|
|
923
|
+
new TextEncoder();
|
|
924
|
+
/** HKDF salt for every ViteHub-derived secret. A different salt than Nuxt's keeps both derivations apart for one shared root. */
|
|
925
|
+
const viteHubSecretSalt = "vitehub";
|
|
926
|
+
/** Reads the root app secret, `VITEHUB_SECRET`, from an env record. Returns `undefined` when it is not a non-empty string. */
|
|
927
|
+
function readViteHubSecret(env) {
|
|
928
|
+
const value = env.VITEHUB_SECRET;
|
|
929
|
+
return typeof value === "string" && value ? value : void 0;
|
|
930
|
+
}
|
|
931
|
+
Object.freeze({ prefix: "sha256=" });
|
|
932
|
+
//#endregion
|
|
933
|
+
//#region src/runtime/github-login.ts
|
|
934
|
+
/** The Server Env names of the OAuth client that people sign in to Comments with: a GitHub App's, or an OAuth App's. */
|
|
935
|
+
const githubLoginEnv = {
|
|
936
|
+
clientId: "VITEHUB_GITHUB_CLIENT_ID",
|
|
937
|
+
clientSecret: "VITEHUB_GITHUB_CLIENT_SECRET"
|
|
938
|
+
};
|
|
939
|
+
/** Where Better Auth serves the GitHub sign-in of Comments. */
|
|
940
|
+
const githubLoginPath = `${commentsRoute}/auth`;
|
|
941
|
+
/** How long a sign-in lasts. The session is in an encrypted cookie, so it cannot be revoked before then. */
|
|
942
|
+
const sessionLifetime = "7d";
|
|
943
|
+
/** How long Comments trusts the repository access that GitHub reported for a person. */
|
|
944
|
+
const accessLifetime = 3e5;
|
|
945
|
+
const userResponse = v.object({ login: v.string() });
|
|
946
|
+
const repositoryResponse = v.object({ permissions: v.optional(v.object({ push: v.optional(v.boolean()) })) });
|
|
947
|
+
function serverEnv(name) {
|
|
948
|
+
const value = getActiveCloudflareBinding(name) ?? globalThis.process?.env?.[name];
|
|
949
|
+
return typeof value === "string" && value ? value : void 0;
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* The secret of the session cookies: derived from `VITEHUB_SECRET` for Comments alone, so the app's own Auth cookies
|
|
953
|
+
* and these never open each other. Without a root secret, Better Auth uses its development secret, and fails in
|
|
954
|
+
* production.
|
|
955
|
+
*/
|
|
956
|
+
function sessionSecret() {
|
|
957
|
+
const root = readViteHubSecret({ VITEHUB_SECRET: serverEnv("VITEHUB_SECRET") });
|
|
958
|
+
if (!root) return;
|
|
959
|
+
if (root.length < 32) throw commentsErrorDiagnostics.COMMENTS_SECRET_TOO_SHORT({ minimum: 32 });
|
|
960
|
+
const bytes = new Uint8Array(hkdfSync("sha256", root, viteHubSecretSalt, "vitehub:comments:auth", 32));
|
|
961
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
962
|
+
}
|
|
963
|
+
/** A return path on this site, so the sign-in cannot send people elsewhere. */
|
|
964
|
+
function safeReturn(value) {
|
|
965
|
+
return value && value.startsWith("/") && !value.startsWith("//") && !value.startsWith("/\\") ? value : "/?vitehub";
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* Sign in with GitHub for Comments, with no database: ViteHub Auth's `stateless()` preset keeps the session, and the
|
|
969
|
+
* GitHub token, in encrypted cookies. A person may comment when GitHub says they can push to the repository of the
|
|
970
|
+
* build.
|
|
971
|
+
*/
|
|
972
|
+
function createCommentsGitHubLogin(options = {}) {
|
|
973
|
+
const apiUrl = (options.apiUrl ?? "https://api.github.com").replace(/\/+$/, "");
|
|
974
|
+
const fetcher = options.fetch ?? globalThis.fetch;
|
|
975
|
+
const instances = /* @__PURE__ */ new Map();
|
|
976
|
+
const access = /* @__PURE__ */ new Map();
|
|
977
|
+
async function auth(event, request) {
|
|
978
|
+
const clientId = serverEnv(githubLoginEnv.clientId);
|
|
979
|
+
const clientSecret = serverEnv(githubLoginEnv.clientSecret);
|
|
980
|
+
const secret = sessionSecret();
|
|
981
|
+
const origin = forwardedRequestOrigin(request);
|
|
982
|
+
const key = [
|
|
983
|
+
origin,
|
|
984
|
+
clientId,
|
|
985
|
+
clientSecret,
|
|
986
|
+
secret
|
|
987
|
+
].join("\0");
|
|
988
|
+
let instance = instances.get(key);
|
|
989
|
+
if (!instance) {
|
|
990
|
+
const definition = defineAuth(() => ({
|
|
991
|
+
baseURL: origin,
|
|
992
|
+
basePath: options.basePath ?? githubLoginPath,
|
|
993
|
+
...secret ? { secret } : {},
|
|
994
|
+
preset: stateless({ maxAge: sessionLifetime }),
|
|
995
|
+
socialProviders: { github: {
|
|
996
|
+
clientId,
|
|
997
|
+
clientSecret,
|
|
998
|
+
mapProfileToUser: (profile) => profile.email ? {} : { email: `${profile.id}+${profile.login}@users.noreply.github.com` }
|
|
999
|
+
} },
|
|
1000
|
+
advanced: { cookiePrefix: "vitehub_comments" }
|
|
1001
|
+
}));
|
|
1002
|
+
instance = (await import("@vite-hub/auth/internal/server")).createAuthForRequest(definition, request, event);
|
|
1003
|
+
if (instances.size > 20) instances.clear();
|
|
1004
|
+
instances.set(key, instance);
|
|
1005
|
+
}
|
|
1006
|
+
return instance;
|
|
1007
|
+
}
|
|
1008
|
+
async function github(token, path) {
|
|
1009
|
+
const response = await fetcher(`${apiUrl}${path}`, { headers: {
|
|
1010
|
+
"accept": "application/vnd.github+json",
|
|
1011
|
+
"authorization": `Bearer ${token}`,
|
|
1012
|
+
"user-agent": "vitehub-comments",
|
|
1013
|
+
"x-github-api-version": "2022-11-28"
|
|
1014
|
+
} });
|
|
1015
|
+
if (response.status === 404) return void 0;
|
|
1016
|
+
if (!response.ok) throw commentsErrorDiagnostics.COMMENTS_GITHUB_REQUEST_FAILED({
|
|
1017
|
+
path,
|
|
1018
|
+
status: response.status
|
|
1019
|
+
});
|
|
1020
|
+
return await response.json();
|
|
1021
|
+
}
|
|
1022
|
+
/** The GitHub login of a person, and whether they can push to the repository. */
|
|
1023
|
+
async function accessOf(userId, token) {
|
|
1024
|
+
const key = `${userId}\0${options.repository ?? ""}`;
|
|
1025
|
+
const cached = access.get(key);
|
|
1026
|
+
if (cached && cached.until > Date.now()) return {
|
|
1027
|
+
login: cached.login,
|
|
1028
|
+
...cached.repository ? { repository: cached.repository } : {},
|
|
1029
|
+
write: cached.write
|
|
1030
|
+
};
|
|
1031
|
+
const [user, repository] = await Promise.all([github(token, "/user"), options.repository ? github(token, `/repos/${options.repository}`) : void 0]);
|
|
1032
|
+
const login = v.parse(userResponse, user).login;
|
|
1033
|
+
const write = repository === void 0 ? false : v.parse(repositoryResponse, repository).permissions?.push === true;
|
|
1034
|
+
const result = {
|
|
1035
|
+
login,
|
|
1036
|
+
...options.repository ? { repository: options.repository } : {},
|
|
1037
|
+
write
|
|
1038
|
+
};
|
|
1039
|
+
if (access.size > 1e3) access.clear();
|
|
1040
|
+
access.set(key, {
|
|
1041
|
+
...result,
|
|
1042
|
+
until: Date.now() + accessLifetime
|
|
1043
|
+
});
|
|
1044
|
+
return result;
|
|
1045
|
+
}
|
|
1046
|
+
const configured = () => Boolean(serverEnv(githubLoginEnv.clientId) && serverEnv(githubLoginEnv.clientSecret));
|
|
1047
|
+
return {
|
|
1048
|
+
configured,
|
|
1049
|
+
async user(event) {
|
|
1050
|
+
if (!configured()) return null;
|
|
1051
|
+
const request = getStandardContext(event).req;
|
|
1052
|
+
const instance = await auth(event, request);
|
|
1053
|
+
const user = (await instance.api.getSession({ headers: request.headers }))?.user;
|
|
1054
|
+
if (!user || typeof user !== "object" || !("id" in user) || typeof user.id !== "string") return null;
|
|
1055
|
+
const accessToken = await instance.api.getAccessToken({
|
|
1056
|
+
body: { useAccountCookie: true },
|
|
1057
|
+
headers: request.headers
|
|
1058
|
+
}).then((tokens) => tokens.accessToken, () => void 0);
|
|
1059
|
+
if (!accessToken) return null;
|
|
1060
|
+
const githubAccess = await accessOf(user.id, accessToken);
|
|
1061
|
+
rememberGitHubToken(user.id, accessToken);
|
|
1062
|
+
const name = "name" in user && typeof user.name === "string" && user.name ? user.name : githubAccess.login;
|
|
1063
|
+
return {
|
|
1064
|
+
...user,
|
|
1065
|
+
id: user.id,
|
|
1066
|
+
name,
|
|
1067
|
+
github: githubAccess
|
|
1068
|
+
};
|
|
1069
|
+
},
|
|
1070
|
+
async handle(request, path) {
|
|
1071
|
+
if (!configured()) return Response.json({ error: {
|
|
1072
|
+
code: "COMMENTS_SIGN_IN_OFF",
|
|
1073
|
+
why: "This site has no GitHub sign-in for Comments.",
|
|
1074
|
+
fix: `Set ${githubLoginEnv.clientId} and ${githubLoginEnv.clientSecret} on the server.`
|
|
1075
|
+
} }, { status: 404 });
|
|
1076
|
+
const instance = await auth(request, request);
|
|
1077
|
+
const url = new URL(request.url);
|
|
1078
|
+
if (path === "/auth/github" && request.method === "GET") {
|
|
1079
|
+
const response = await instance.api.signInSocial({
|
|
1080
|
+
body: {
|
|
1081
|
+
provider: "github",
|
|
1082
|
+
callbackURL: safeReturn(url.searchParams.get("return")),
|
|
1083
|
+
disableRedirect: true
|
|
1084
|
+
},
|
|
1085
|
+
headers: request.headers,
|
|
1086
|
+
asResponse: true
|
|
1087
|
+
});
|
|
1088
|
+
const body = await response.json().catch(() => void 0);
|
|
1089
|
+
const target = body && typeof body === "object" && "url" in body && typeof body.url === "string" ? body.url : void 0;
|
|
1090
|
+
if (!target) return Response.json({ error: {
|
|
1091
|
+
code: "COMMENTS_SIGN_IN_FAILED",
|
|
1092
|
+
why: "GitHub sign-in could not start."
|
|
1093
|
+
} }, { status: 502 });
|
|
1094
|
+
const headers = new Headers({
|
|
1095
|
+
"location": target,
|
|
1096
|
+
"cache-control": "no-store"
|
|
1097
|
+
});
|
|
1098
|
+
for (const cookie of response.headers.getSetCookie()) headers.append("set-cookie", cookie);
|
|
1099
|
+
return new Response(null, {
|
|
1100
|
+
status: 302,
|
|
1101
|
+
headers
|
|
1102
|
+
});
|
|
1103
|
+
}
|
|
1104
|
+
if (path === "/auth/sign-out") {
|
|
1105
|
+
const session = await instance.api.getSession({ headers: request.headers }).catch(() => null);
|
|
1106
|
+
if (session?.user.id) forgetGitHubToken(session.user.id);
|
|
1107
|
+
}
|
|
1108
|
+
return await instance.handler(request);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
//#endregion
|
|
1113
|
+
export { commentsDefinitionOf, commentsMcpTools, createCommentsGitHubLogin, createCommentsHandler, defineCommentsPlugin, githubLoginEnv, installedComments, selectCommentsDatabase, viteHubPageSessionHandler };
|