@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
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { n as outboxAccountHeader } from "./client-files-
|
|
2
|
-
import { t as commentsErrorDiagnostics } from "./errors-
|
|
3
|
-
import { n as pagePathOf, t as isPagePath } from "./path
|
|
4
|
-
import { n as isRecordOrFunction } from "./object-
|
|
5
|
-
import { C as clientAddressKey, S as suggest, T as createClientRateLimit, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, x as storeAttachment, y as retriedReply } from "./service-
|
|
6
|
-
import { n as guestFromHeaders, t as authorOf } from "./identity-
|
|
7
|
-
import { t as describeCommentContext } from "./context-
|
|
8
|
-
import { t as commentsRuntime } from "./server-
|
|
1
|
+
import { n as outboxAccountHeader } from "./client-files-lC6X7XyS.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-DFNiJg67.js";
|
|
3
|
+
import { n as pagePathOf, t as isPagePath } from "./path-8yqMd8zR.js";
|
|
4
|
+
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
5
|
+
import { C as clientAddressKey, S as suggest, T as createClientRateLimit, _ as requestIdSchema, a as createThread, c as earlierThread, d as maximumAttachmentBytes, f as maximumCommentBodyLength, g as replyToThread, h as readAttachment, l as editMessage, m as personOf, n as base64, o as deniedError, r as can, s as earlierReply, t as attachmentThread, u as fail, v as retried, x as storeAttachment, y as retriedReply } from "./service-DDD4Ubxd.js";
|
|
6
|
+
import { n as guestFromHeaders, t as authorOf } from "./identity-CT7-UGmS.js";
|
|
7
|
+
import { t as describeCommentContext } from "./context-DbkBjITZ.js";
|
|
8
|
+
import { t as commentsRuntime } from "./server-BGbD7H5s.js";
|
|
9
9
|
import { defineDiagnostics } from "nostics";
|
|
10
10
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
11
11
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
12
12
|
import * as v from "valibot";
|
|
13
|
-
|
|
13
|
+
// ../internal/src/error-diagnostics.ts
|
|
14
14
|
const dynamicError = { why: ({ message }) => message === void 0 ? "" : String(message) };
|
|
15
15
|
const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
16
16
|
docsBase: "https://vitehub.dev/docs/development/diagnostics",
|
|
@@ -36,7 +36,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
36
36
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
37
37
|
},
|
|
38
38
|
INTERNAL_R0022: {
|
|
39
|
-
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields.",
|
|
39
|
+
fix: "Send input that matches the schema of the operation. `vitehub <namespace> <command> --help` shows the fields, and the list_operations tool of the ViteHub MCP gives the input schema of each operation.",
|
|
40
40
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
41
41
|
},
|
|
42
42
|
INTERNAL_R0024: {
|
|
@@ -255,6 +255,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
255
255
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
256
256
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
257
257
|
},
|
|
258
|
+
INTERNAL_RUNTIME_PACKAGE_VERSION_CONFLICT: {
|
|
259
|
+
why: ({ first, name, second }) => `[vitehub] One server function needs ${name} from two installations: ${first} and ${second}.`,
|
|
260
|
+
fix: "Install one version of the package that the message names, for example with `pnpm dedupe` or an `overrides` entry in `package.json`, then build again."
|
|
261
|
+
},
|
|
258
262
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
259
263
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
260
264
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -263,6 +267,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
263
267
|
why: ({ minimum }) => `[vitehub] VITEHUB_SECRET must be at least ${minimum} characters. Generate one with \`openssl rand -base64 32\`.`,
|
|
264
268
|
fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters."
|
|
265
269
|
},
|
|
270
|
+
INTERNAL_SITE_TOKEN_TOO_LONG: {
|
|
271
|
+
why: ({ length, maximum }) => `The Site access token is ${length} characters, and an app accepts ${maximum}.`,
|
|
272
|
+
fix: "Open the app with a shorter path, or give the person and the project shorter names, so that the Site access token fits."
|
|
273
|
+
},
|
|
266
274
|
INTERNAL_SQLITE_ARGUMENT_INVALID: {
|
|
267
275
|
why: ({ value }) => value === "undefined" ? "undefined cannot be passed as argument to the database" : "Only finite numbers (not Infinity or NaN) can be passed as arguments",
|
|
268
276
|
fix: "Pass query arguments as finite numbers, strings, booleans, bigints, dates, byte arrays, or null. Replace undefined with null, and check numbers with `Number.isFinite()` before the query."
|
|
@@ -277,8 +285,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
277
285
|
}
|
|
278
286
|
}
|
|
279
287
|
});
|
|
280
|
-
|
|
281
|
-
//#region ../internal/src/standard-schema.ts
|
|
288
|
+
// ../internal/src/standard-schema.ts
|
|
282
289
|
function readOwn(value, key) {
|
|
283
290
|
if (value === null || Object(value) !== value) return;
|
|
284
291
|
try {
|
|
@@ -307,8 +314,7 @@ function standardJsonSchema(schema, direction, target = "draft-2020-12", library
|
|
|
307
314
|
return;
|
|
308
315
|
}
|
|
309
316
|
}
|
|
310
|
-
|
|
311
|
-
//#region ../internal/src/valibot.ts
|
|
317
|
+
// ../internal/src/valibot.ts
|
|
312
318
|
const valibotTargets = /* @__PURE__ */ new Set([
|
|
313
319
|
"draft-07",
|
|
314
320
|
"draft-2020-12",
|
|
@@ -349,8 +355,7 @@ function withValibotJsonSchema(schema, options = {}) {
|
|
|
349
355
|
}
|
|
350
356
|
};
|
|
351
357
|
}
|
|
352
|
-
|
|
353
|
-
//#region ../internal/src/operation-definition.ts
|
|
358
|
+
// ../internal/src/operation-definition.ts
|
|
354
359
|
const nameFormat = /^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/;
|
|
355
360
|
const kinds = /* @__PURE__ */ new Set([
|
|
356
361
|
"read",
|
|
@@ -429,8 +434,7 @@ function operationAccessAllows(access, section, call) {
|
|
|
429
434
|
if (!grants.some((grant) => sections.includes(`${grant}:read`))) return false;
|
|
430
435
|
return call === void 0 || call.kind === "read" || call.readOnly === true;
|
|
431
436
|
}
|
|
432
|
-
|
|
433
|
-
//#region src/thread-text.ts
|
|
437
|
+
// src/thread-text.ts
|
|
434
438
|
function commentPersonName(person) {
|
|
435
439
|
return `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
|
|
436
440
|
}
|
|
@@ -518,8 +522,7 @@ function commentThreadsText(threads, status, note) {
|
|
|
518
522
|
if (!threads.length) return note ? `No ${status} threads that this caller may read. ${note}` : `No ${status} threads.`;
|
|
519
523
|
return [...threads.map(commentThreadLine), ...note ? ["", note] : []].join("\n");
|
|
520
524
|
}
|
|
521
|
-
|
|
522
|
-
//#region src/operations-core/operations.ts
|
|
525
|
+
// src/operations-core/operations.ts
|
|
523
526
|
const defaultLimit = 200;
|
|
524
527
|
const maximumLimit = 500;
|
|
525
528
|
const maximumSuggestions = 10;
|
|
@@ -592,6 +595,17 @@ const metadata = v.optional(v.record(v.string(), v.union([
|
|
|
592
595
|
])));
|
|
593
596
|
const revision = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
594
597
|
const threadId = v.strictObject({ threadId: id });
|
|
598
|
+
const maximumResolvedThreads = 50;
|
|
599
|
+
const resolveReply = v.pipe(v.string(), v.regex(/\S/, "A resolution reply needs some text."), v.maxLength(maximumCommentBodyLength), v.description("What changed, such as the commit or a link. It is added to the thread as a reply."));
|
|
600
|
+
const resolveEntry = v.strictObject({
|
|
601
|
+
threadId: id,
|
|
602
|
+
reply: v.optional(resolveReply)
|
|
603
|
+
});
|
|
604
|
+
const resolveInput = v.union([resolveEntry, v.strictObject({ threads: v.pipe(v.array(resolveEntry), v.minLength(1), v.maxLength(maximumResolvedThreads), v.check((entries) => new Set(entries.map((entry) => entry.threadId)).size === entries.length, "List each thread only once.")) })]);
|
|
605
|
+
async function digest(value) {
|
|
606
|
+
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
|
|
607
|
+
return Array.from(bytes.subarray(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
608
|
+
}
|
|
595
609
|
function actorOf(actor) {
|
|
596
610
|
return actor ? {
|
|
597
611
|
id: actor.id,
|
|
@@ -677,6 +691,7 @@ function writeOptions(who) {
|
|
|
677
691
|
console: who.console,
|
|
678
692
|
gate: who.gate,
|
|
679
693
|
user: who.user,
|
|
694
|
+
...who.request ? { request: who.request } : {},
|
|
680
695
|
...who.waitUntil ? { waitUntil: who.waitUntil } : {}
|
|
681
696
|
};
|
|
682
697
|
}
|
|
@@ -723,7 +738,7 @@ const listInput = v.strictObject({
|
|
|
723
738
|
subject: v.optional(subject),
|
|
724
739
|
subjectKind: v.optional(subjectKind)
|
|
725
740
|
});
|
|
726
|
-
const getInput = v.union([v.strictObject({ id }), v.strictObject({
|
|
741
|
+
const getInput = v.union([v.strictObject({ threadId: id }), v.strictObject({
|
|
727
742
|
n: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
728
743
|
scope: v.pipe(v.string(), v.minLength(1), v.maxLength(200))
|
|
729
744
|
})]);
|
|
@@ -820,7 +835,7 @@ const commentActions = {
|
|
|
820
835
|
return (await readableThreads(input, who)).threads;
|
|
821
836
|
},
|
|
822
837
|
async get(input, who) {
|
|
823
|
-
const found = "
|
|
838
|
+
const found = "threadId" in input ? await who.runtime.store.getById(input.threadId) : await who.runtime.store.getByNumber(input.scope, input.n);
|
|
824
839
|
if (!found || !await permitted(who, "read", { thread: found })) return null;
|
|
825
840
|
return (await withForge(who, [found]))[0];
|
|
826
841
|
},
|
|
@@ -900,10 +915,69 @@ const commentActions = {
|
|
|
900
915
|
async setStatus(input, who, status) {
|
|
901
916
|
const found = await load(who, input.threadId);
|
|
902
917
|
await allow(who, "resolve", { thread: found });
|
|
903
|
-
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now());
|
|
918
|
+
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now(), status === "resolved" ? who.actor : void 0);
|
|
904
919
|
who.runtime.forge?.changed(found.id);
|
|
920
|
+
if (status === "open") await who.runtime.reopened?.(next);
|
|
905
921
|
return next;
|
|
906
922
|
},
|
|
923
|
+
async resolveThreads(input, who) {
|
|
924
|
+
const by = author(who);
|
|
925
|
+
const plans = await Promise.all(input.map(async (entry) => {
|
|
926
|
+
const thread = await load(who, entry.threadId);
|
|
927
|
+
await allow(who, "resolve", { thread });
|
|
928
|
+
const body = entry.reply?.trim();
|
|
929
|
+
if (body === void 0) return { thread };
|
|
930
|
+
checkOutboxAccount(who);
|
|
931
|
+
await allow(who, "write", { thread });
|
|
932
|
+
const replyKey = async (previousId) => `resolve:${await digest(JSON.stringify([
|
|
933
|
+
by.id,
|
|
934
|
+
who.actor?.id,
|
|
935
|
+
previousId,
|
|
936
|
+
body
|
|
937
|
+
]))}`;
|
|
938
|
+
const last = thread.messages.at(-1);
|
|
939
|
+
if (thread.status === "resolved" && last && last.createdAt <= (thread.resolvedAt ?? 0) && last.body === body) {
|
|
940
|
+
if ((await earlierReply(thread, await replyKey(thread.messages.at(-2)?.id)))?.id === last.id) return { thread };
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
thread,
|
|
944
|
+
reply: {
|
|
945
|
+
author: by,
|
|
946
|
+
body,
|
|
947
|
+
requestId: await replyKey(last?.id),
|
|
948
|
+
...who.actor ? { actor: who.actor } : {}
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
}));
|
|
952
|
+
for (const plan of plans) if (plan.reply) await limitGuest(who);
|
|
953
|
+
const resolved = [];
|
|
954
|
+
for (const plan of plans) {
|
|
955
|
+
let { thread } = plan;
|
|
956
|
+
let replied = false;
|
|
957
|
+
try {
|
|
958
|
+
if (plan.reply) {
|
|
959
|
+
thread = (await replyToThread(who.runtime, thread, plan.reply, {
|
|
960
|
+
allowResolved: true,
|
|
961
|
+
...writeOptions(who)
|
|
962
|
+
})).thread;
|
|
963
|
+
replied = true;
|
|
964
|
+
}
|
|
965
|
+
if (thread.status !== "resolved" || thread.messages.some((message) => message.createdAt > (thread.resolvedAt ?? 0))) {
|
|
966
|
+
thread = await who.runtime.store.setStatus(thread.id, "resolved", by, Date.now(), who.actor);
|
|
967
|
+
who.runtime.forge?.changed(thread.id);
|
|
968
|
+
}
|
|
969
|
+
resolved.push(thread);
|
|
970
|
+
} catch (cause) {
|
|
971
|
+
if (!resolved.length && !replied) throw cause;
|
|
972
|
+
throw Object.assign(fail(commentsErrorDiagnostics.COMMENTS_RESOLVE_INTERRUPTED({
|
|
973
|
+
completed: resolved.map((entry) => entry.id),
|
|
974
|
+
threadId: thread.id,
|
|
975
|
+
replied
|
|
976
|
+
}), 409), { cause });
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return resolved;
|
|
980
|
+
},
|
|
907
981
|
/** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
|
|
908
982
|
async users(input, who, options = {}) {
|
|
909
983
|
const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
|
|
@@ -947,224 +1021,230 @@ const list = defineOperation({
|
|
|
947
1021
|
run: async (input, context) => commentActions.list(input, await caller(context)),
|
|
948
1022
|
section: "comments"
|
|
949
1023
|
});
|
|
1024
|
+
const resolveNext = "After you make the change that a thread asks for, resolve it with comments.resolve and a reply that says what changed, such as the commit or a link. Resolve every thread that you handled in one call: { threads: [{ threadId, reply }] }. Open threads stay on the page.";
|
|
950
1025
|
/** Threads that one search reads from the store at a time. */
|
|
951
1026
|
const searchBatch = maximumLimit;
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1027
|
+
/** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
|
|
1028
|
+
const commentsOperations = [
|
|
1029
|
+
defineOperation({
|
|
1030
|
+
description: "ViteHub Comments: threads people left with the Comments toolbar on the app's pages, newest activity first. Each has the page, what the comment points at, the time, the first comment, and the Vue components. `hidden` counts the threads that `authorize` hid from you. Read one with comments.get { threadId }. When you have made the change that a thread asks for, resolve it with comments.resolve and a reply that says what changed: the person expects it, and open threads stay on their page.",
|
|
1031
|
+
input: threadsInput,
|
|
1032
|
+
kind: "read",
|
|
1033
|
+
name: "comments.threads",
|
|
1034
|
+
run: async (input, context) => {
|
|
1035
|
+
const who = await caller(context);
|
|
1036
|
+
const status = input.status ?? "open";
|
|
1037
|
+
const limit = input.limit ?? 25;
|
|
1038
|
+
const search = input.search?.toLowerCase();
|
|
1039
|
+
const batch = search ? searchBatch : limit;
|
|
1040
|
+
const found = [];
|
|
1041
|
+
let hidden = 0;
|
|
1042
|
+
let before;
|
|
1043
|
+
while (found.length < limit) {
|
|
1044
|
+
const listed = await readableThreads({
|
|
1045
|
+
limit: batch,
|
|
1046
|
+
status,
|
|
1047
|
+
subjectKind: "page",
|
|
1048
|
+
...input.page ? { page: input.page } : {},
|
|
1049
|
+
...before ? { before } : {}
|
|
1050
|
+
}, who);
|
|
1051
|
+
hidden += listed.hidden;
|
|
1052
|
+
for (const thread of listed.threads) {
|
|
1053
|
+
if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
|
|
1054
|
+
if (found.length === limit) break;
|
|
1055
|
+
}
|
|
1056
|
+
if (listed.threads.length < batch) break;
|
|
1057
|
+
before = cursorOf(listed.threads.at(-1));
|
|
978
1058
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
})
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
})
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
})
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
})
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
})
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1059
|
+
const note = hiddenThreadsNote(hidden, {
|
|
1060
|
+
authorize: Boolean(who.runtime.definition.authorize),
|
|
1061
|
+
identify: Boolean(who.runtime.identify),
|
|
1062
|
+
user: who.user !== null,
|
|
1063
|
+
console: who.console === true
|
|
1064
|
+
});
|
|
1065
|
+
const next = status === "open" && found.length ? resolveNext : void 0;
|
|
1066
|
+
return {
|
|
1067
|
+
status,
|
|
1068
|
+
threads: found.map(commentThreadSummary),
|
|
1069
|
+
hidden,
|
|
1070
|
+
...note ? { note } : {},
|
|
1071
|
+
...next ? { next } : {}
|
|
1072
|
+
};
|
|
1073
|
+
},
|
|
1074
|
+
mcp: {
|
|
1075
|
+
format: ({ status, threads, note }) => commentThreadsText(threads, status, note ?? ""),
|
|
1076
|
+
title: "List ViteHub Comments threads"
|
|
1077
|
+
},
|
|
1078
|
+
section: "comments"
|
|
1079
|
+
}),
|
|
1080
|
+
list,
|
|
1081
|
+
defineOperation({
|
|
1082
|
+
description: "Read one comment thread by { threadId }, or by { scope, n }, its number inside its scope: its page, the element and Vue components with their source files, the browser and build, and every comment. A thread that does not exist or that you may not read is null.",
|
|
1083
|
+
input: getInput,
|
|
1084
|
+
kind: "read",
|
|
1085
|
+
name: "comments.get",
|
|
1086
|
+
run: async (input, context) => commentActions.get(input, await caller(context)),
|
|
1087
|
+
mcp: {
|
|
1088
|
+
format: (thread) => thread ? describeCommentThread(thread) : "No thread with this id that you may read.",
|
|
1089
|
+
title: "Read a comment thread"
|
|
1090
|
+
},
|
|
1091
|
+
section: "comments"
|
|
1092
|
+
}),
|
|
1093
|
+
defineOperation({
|
|
1094
|
+
description: "Start a comment thread on a subject, such as a page, with an anchor and a first message. Send the same `requestId` again to retry: you get the first thread, not a second one.",
|
|
1095
|
+
input: createInput,
|
|
1096
|
+
kind: "write",
|
|
1097
|
+
name: "comments.create",
|
|
1098
|
+
run: async (input, context) => commentActions.create(input, await caller(context)),
|
|
1099
|
+
section: "comments"
|
|
1100
|
+
}),
|
|
1101
|
+
defineOperation({
|
|
1102
|
+
description: "Add a message to a comment thread, such as a question to the person. To say what you changed and close the thread, use comments.resolve with reply. A resolved thread stays resolved. Send the same `requestId` again to retry: you get the first message, not a second one.",
|
|
1103
|
+
input: replyInput,
|
|
1104
|
+
kind: "write",
|
|
1105
|
+
name: "comments.reply",
|
|
1106
|
+
run: async (input, context) => (await commentActions.reply(input, await caller(context), { allowResolved: true })).thread,
|
|
1107
|
+
mcp: {
|
|
1108
|
+
format: (thread) => `Replied to thread ${thread.id}.`,
|
|
1109
|
+
title: "Reply to a comment thread"
|
|
1110
|
+
},
|
|
1111
|
+
section: "comments"
|
|
1112
|
+
}),
|
|
1113
|
+
defineOperation({
|
|
1114
|
+
description: "Change the text of your own message.",
|
|
1115
|
+
input: editInput,
|
|
1116
|
+
kind: "write",
|
|
1117
|
+
name: "comments.edit",
|
|
1118
|
+
run: async (input, context) => commentActions.edit(input, await caller(context)),
|
|
1119
|
+
section: "comments"
|
|
1120
|
+
}),
|
|
1121
|
+
defineOperation({
|
|
1122
|
+
description: "Delete a message, or the whole thread. Deleting the first message deletes the thread.",
|
|
1123
|
+
input: deleteInput,
|
|
1124
|
+
kind: "destructive",
|
|
1125
|
+
name: "comments.delete",
|
|
1126
|
+
run: async (input, context) => commentActions.delete(input, await caller(context)),
|
|
1127
|
+
section: "comments"
|
|
1128
|
+
}),
|
|
1129
|
+
defineOperation({
|
|
1130
|
+
description: "Resolve the comment threads that you handled, each with a reply that says what changed, such as the commit or a link. This is the last step of every thread that you act on, and the person who commented expects it: resolved threads leave their page, open ones stay on it. Pass { threadId, reply } for one thread, or { threads: [{ threadId, reply }] } to resolve every thread that you handled in one call. A thread that you did not change stays open.",
|
|
1131
|
+
input: resolveInput,
|
|
1132
|
+
kind: "write",
|
|
1133
|
+
maxRequestBytes: 32e5,
|
|
1134
|
+
name: "comments.resolve",
|
|
1135
|
+
run: async (input, context) => {
|
|
1136
|
+
const who = await caller(context);
|
|
1137
|
+
if ("threads" in input) return commentActions.resolveThreads(input.threads, who);
|
|
1138
|
+
const [thread] = await commentActions.resolveThreads([input], who);
|
|
1139
|
+
return thread;
|
|
1140
|
+
},
|
|
1141
|
+
mcp: {
|
|
1142
|
+
format: (output) => [output].flat().map((thread) => `Thread ${thread.id} is ${thread.status}.`).join("\n"),
|
|
1143
|
+
title: "Resolve comment threads"
|
|
1144
|
+
},
|
|
1145
|
+
section: "comments"
|
|
1146
|
+
}),
|
|
1147
|
+
defineOperation({
|
|
1148
|
+
description: "Open a resolved comment thread again.",
|
|
1052
1149
|
input: threadId,
|
|
1053
1150
|
kind: "write",
|
|
1151
|
+
name: "comments.reopen",
|
|
1152
|
+
run: async (input, context) => commentActions.setStatus(input, await caller(context), "open"),
|
|
1054
1153
|
mcp: {
|
|
1055
1154
|
format: (thread) => `Thread ${thread.id} is ${thread.status}.`,
|
|
1056
|
-
title
|
|
1155
|
+
title: "Reopen a comment thread"
|
|
1057
1156
|
},
|
|
1058
|
-
name,
|
|
1059
|
-
run: async (input, context) => commentActions.setStatus(input, await caller(context), status),
|
|
1060
1157
|
section: "comments"
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
const users = defineOperation({
|
|
1064
|
-
description: "Find people to mention by name. Needs at least two characters, and the right to write.",
|
|
1065
|
-
input: usersInput,
|
|
1066
|
-
kind: "read",
|
|
1067
|
-
name: "comments.users",
|
|
1068
|
-
run: async (input, context) => commentActions.users(input, await caller(context)),
|
|
1069
|
-
section: "comments"
|
|
1070
|
-
});
|
|
1071
|
-
const upload = defineOperation({
|
|
1072
|
-
description: "Store a file to attach to a comment. Pass the returned key in `attachments` of comments.create or comments.reply.",
|
|
1073
|
-
input: uploadInput,
|
|
1074
|
-
kind: "write",
|
|
1075
|
-
maxRequestBytes: Math.ceil(maximumAttachmentBytes / 3) * 4 + 4096,
|
|
1076
|
-
mcp: false,
|
|
1077
|
-
name: "comments.upload",
|
|
1078
|
-
run: async (input, context) => commentActions.upload(input, await caller(context)),
|
|
1079
|
-
section: "comments"
|
|
1080
|
-
});
|
|
1081
|
-
const attachment = defineOperation({
|
|
1082
|
-
description: "Read the file of an attachment key, Base64-encoded, from a thread that you may read.",
|
|
1083
|
-
input: attachmentInput,
|
|
1084
|
-
kind: "read",
|
|
1085
|
-
mcp: false,
|
|
1086
|
-
name: "comments.attachment",
|
|
1087
|
-
run: async (input, context) => {
|
|
1088
|
-
const file = await commentActions.attachment(input, await caller(context));
|
|
1089
|
-
return {
|
|
1090
|
-
data: base64(new Uint8Array(await file.data.arrayBuffer())),
|
|
1091
|
-
inline: file.inline,
|
|
1092
|
-
key: file.key,
|
|
1093
|
-
name: file.name,
|
|
1094
|
-
size: file.size,
|
|
1095
|
-
type: file.type
|
|
1096
|
-
};
|
|
1097
|
-
},
|
|
1098
|
-
section: "comments"
|
|
1099
|
-
});
|
|
1100
|
-
const session = defineOperation({
|
|
1101
|
-
description: "Tell the comments overlay who is signed in and what that person may do. Nothing else leaves the server.",
|
|
1102
|
-
input: v.strictObject({
|
|
1103
|
-
subject: v.optional(subject),
|
|
1104
|
-
threadId: v.optional(id)
|
|
1105
1158
|
}),
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1159
|
+
defineOperation({
|
|
1160
|
+
description: "Find people to mention by name. Needs at least two characters, and the right to write.",
|
|
1161
|
+
input: usersInput,
|
|
1162
|
+
kind: "read",
|
|
1163
|
+
name: "comments.users",
|
|
1164
|
+
run: async (input, context) => commentActions.users(input, await caller(context)),
|
|
1165
|
+
section: "comments"
|
|
1166
|
+
}),
|
|
1167
|
+
defineOperation({
|
|
1168
|
+
description: "Store a file to attach to a comment. Pass the returned key in `attachments` of comments.create or comments.reply.",
|
|
1169
|
+
input: uploadInput,
|
|
1170
|
+
kind: "write",
|
|
1171
|
+
maxRequestBytes: Math.ceil(maximumAttachmentBytes / 3) * 4 + 4096,
|
|
1172
|
+
mcp: false,
|
|
1173
|
+
name: "comments.upload",
|
|
1174
|
+
run: async (input, context) => commentActions.upload(input, await caller(context)),
|
|
1175
|
+
section: "comments"
|
|
1176
|
+
}),
|
|
1177
|
+
defineOperation({
|
|
1178
|
+
description: "Read the file of an attachment key, Base64-encoded, from a thread that you may read.",
|
|
1179
|
+
input: attachmentInput,
|
|
1180
|
+
kind: "read",
|
|
1181
|
+
mcp: false,
|
|
1182
|
+
name: "comments.attachment",
|
|
1183
|
+
run: async (input, context) => {
|
|
1184
|
+
const file = await commentActions.attachment(input, await caller(context));
|
|
1185
|
+
return {
|
|
1186
|
+
data: base64(new Uint8Array(await file.data.arrayBuffer())),
|
|
1187
|
+
inline: file.inline,
|
|
1188
|
+
key: file.key,
|
|
1189
|
+
name: file.name,
|
|
1190
|
+
size: file.size,
|
|
1191
|
+
type: file.type
|
|
1192
|
+
};
|
|
1193
|
+
},
|
|
1194
|
+
section: "comments"
|
|
1195
|
+
}),
|
|
1196
|
+
defineOperation({
|
|
1197
|
+
description: "Tell the comments overlay who is signed in and what that person may do. Nothing else leaves the server.",
|
|
1198
|
+
input: v.strictObject({
|
|
1199
|
+
subject: v.optional(subject),
|
|
1200
|
+
threadId: v.optional(id)
|
|
1201
|
+
}),
|
|
1202
|
+
kind: "read",
|
|
1203
|
+
name: "comments.session",
|
|
1204
|
+
run: async (input, context) => {
|
|
1205
|
+
const who = await caller(context);
|
|
1206
|
+
if (!who.user) return {
|
|
1207
|
+
canRead: false,
|
|
1208
|
+
canWrite: false,
|
|
1209
|
+
user: null
|
|
1210
|
+
};
|
|
1211
|
+
if (input.threadId) {
|
|
1212
|
+
const found = await load(who, input.threadId);
|
|
1213
|
+
const can = (action) => permitted(who, action, { thread: found }).catch(() => false);
|
|
1214
|
+
const [write, resolve, remove] = await Promise.all([
|
|
1215
|
+
can("write"),
|
|
1216
|
+
can("resolve"),
|
|
1217
|
+
can("delete")
|
|
1218
|
+
]);
|
|
1219
|
+
const writes = operationAccessAllows(context.access, "comments", { kind: "write" });
|
|
1220
|
+
const deletes = operationAccessAllows(context.access, "comments", { kind: "destructive" });
|
|
1221
|
+
const signedIn = who.user.guest !== true;
|
|
1222
|
+
const userId = who.user.id;
|
|
1223
|
+
const owns = (message) => signedIn && !who.actor && !message.author.guest && message.author.id === userId;
|
|
1224
|
+
const ownsThread = found.messages.every(owns);
|
|
1225
|
+
const deleteThread = signedIn && deletes && (ownsThread ? write : remove);
|
|
1226
|
+
return {
|
|
1227
|
+
canRead: true,
|
|
1228
|
+
canWrite: writes && write,
|
|
1229
|
+
capabilities: {
|
|
1230
|
+
delete: found.messages.filter((message, index) => index === 0 ? deleteThread : signedIn && deletes && (owns(message) ? write : remove)).map((message) => message.id),
|
|
1231
|
+
deleteThread,
|
|
1232
|
+
edit: signedIn && writes && (!who.actor || write) ? found.messages.filter((message) => !message.author.guest && message.author.id === userId).map((message) => message.id) : [],
|
|
1233
|
+
reply: writes && write,
|
|
1234
|
+
resolve: writes && resolve
|
|
1235
|
+
},
|
|
1236
|
+
user: personOf(who.user)
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
const allowed = (action) => permitted(who, action, input.subject ? { subject: input.subject } : {}).catch(() => false);
|
|
1240
|
+
const [canRead, canWrite] = await Promise.all([allowed("read"), allowed("write")]);
|
|
1130
1241
|
return {
|
|
1131
|
-
canRead
|
|
1132
|
-
canWrite:
|
|
1133
|
-
capabilities: {
|
|
1134
|
-
delete: found.messages.filter((message, index) => index === 0 ? deleteThread : signedIn && deletes && (owns(message) ? write : remove)).map((message) => message.id),
|
|
1135
|
-
deleteThread,
|
|
1136
|
-
edit: signedIn && writes && (!who.actor || write) ? found.messages.filter((message) => !message.author.guest && message.author.id === userId).map((message) => message.id) : [],
|
|
1137
|
-
reply: writes && write,
|
|
1138
|
-
resolve: writes && resolve
|
|
1139
|
-
},
|
|
1242
|
+
canRead,
|
|
1243
|
+
canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
|
|
1140
1244
|
user: personOf(who.user)
|
|
1141
1245
|
};
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
return {
|
|
1146
|
-
canRead,
|
|
1147
|
-
canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
|
|
1148
|
-
user: personOf(who.user)
|
|
1149
|
-
};
|
|
1150
|
-
},
|
|
1151
|
-
section: "comments"
|
|
1152
|
-
});
|
|
1153
|
-
/** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
|
|
1154
|
-
const commentsOperations = [
|
|
1155
|
-
threads,
|
|
1156
|
-
list,
|
|
1157
|
-
get,
|
|
1158
|
-
create,
|
|
1159
|
-
reply,
|
|
1160
|
-
edit,
|
|
1161
|
-
remove,
|
|
1162
|
-
statusOperation("comments.resolve", "resolved", "Mark a comment thread as resolved, after the change it asks for is done. Resolved threads leave the page.", "Resolve a comment thread"),
|
|
1163
|
-
statusOperation("comments.reopen", "open", "Open a resolved comment thread again.", "Reopen a comment thread"),
|
|
1164
|
-
users,
|
|
1165
|
-
upload,
|
|
1166
|
-
attachment,
|
|
1167
|
-
session
|
|
1246
|
+
},
|
|
1247
|
+
section: "comments"
|
|
1248
|
+
})
|
|
1168
1249
|
];
|
|
1169
|
-
//#endregion
|
|
1170
1250
|
export { commentThreadSummary as a, hiddenThreadsNote as c, commentsOperations as i, commentAnchorSchema as n, commentThreadsText as o, commentInputSchemas as r, describeCommentThread as s, commentActions as t };
|