@vite-hub/comments 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -15
- package/dist/anchor.d.ts +2 -2
- package/dist/{client-diagnostics-CcFpkbAk.js → client-diagnostics-Bubm7Shd.js} +20 -5
- package/dist/client-files-CJZl5Kc4.js +53 -0
- package/dist/client.d.ts +567 -13
- package/dist/client.js +1209 -34
- package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
- package/dist/{migrate-BDQ8xqUs.js → database-6hXRnqDE.js} +47 -2
- package/dist/database-CTo7mx6t.d.ts +575 -0
- package/dist/database.d.ts +2 -1
- package/dist/database.js +2 -2
- package/dist/{define-43mMR39K.js → define-BMBSVbD9.js} +1 -1
- package/dist/{define-B3TF9zzn.d.ts → define-CmIFU96x.d.ts} +8 -4
- package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
- package/dist/{errors-C6qptPoG.js → errors-Dq4AHjza.js} +23 -3
- package/dist/index-RiHzmV16.d.ts +194 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.js +57 -9
- package/dist/{install-W9ghhGoh.d.ts → install-BGGQKbQ4.d.ts} +9 -3
- package/dist/{install-BcMPgPk_.js → install-DrAse1Fa.js} +912 -60
- package/dist/{installed-B-PfERBU.js → installed-C3EoqJEY.js} +7 -6
- package/dist/{operations-GLeOqgMt.d.ts → operations-BKhUWYkb.d.ts} +10 -5
- package/dist/{operations-D4A1Fcgf.d.ts → operations-VyyNZusz.d.ts} +13 -2
- package/dist/{operations-DMMIfYPW.js → operations-lsVKE0GH.js} +312 -219
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +2 -2
- package/dist/overlay/client-DBmJ4C1M.js +4 -0
- package/dist/overlay/overlay.js +41 -65
- package/dist/page/loader.js +39 -47
- package/dist/{page-DtbMOEMd.d.ts → page-Bzj0CszG.d.ts} +1 -10
- package/dist/{page-B41ozN63.js → page-DRz_sDY4.js} +1 -1
- package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
- package/dist/{plugin-PS8PMYus.js → plugin-DRsNaJaK.js} +34 -8
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js +2 -2
- package/dist/reply-id-P_bSuEng.js +12 -0
- package/dist/request-log-Dj9Vw7qG.js +105 -0
- package/dist/request-origin-CFU0TQ7E.js +49 -0
- package/dist/{rpc-RKPAusHp.js → rpc-BQqYx8kb.js} +23 -7
- package/dist/{rpc-HBcWtg0T.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
- package/dist/rpc.d.ts +1 -1
- package/dist/rpc.js +1 -1
- package/dist/runtime/auth.d.ts +2 -2
- package/dist/runtime/auth.js +2 -2
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +3 -3
- package/dist/runtime/index.d.ts +42 -13
- package/dist/runtime/index.js +224 -22
- package/dist/{server-D8k-0GXe.js → server-Yk610niJ.js} +1 -1
- package/dist/server.d.ts +6 -5
- package/dist/server.js +6 -6
- package/dist/service-Bj-Mg63c.d.ts +73 -0
- package/dist/{service-GHhhyQj4.js → service-DA5BwfPQ.js} +71 -14
- package/dist/{session-DVx-1Tym.d.ts → session-DUcEor2W.d.ts} +3 -3
- package/dist/{session-EkudzUmm.js → session-X_g9dnU5.js} +27 -30
- package/dist/{service-CFVm23k7.d.ts → store-CsUNfC1w.d.ts} +11 -72
- package/dist/table-names-B9LlRC0B.js +16 -0
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +38 -5
- package/dist/{types-CZujrMFd.d.ts → types-BLaYh0_f.d.ts} +48 -4
- package/dist/{types-BIS0hCEl.d.ts → types-C35INXIs.d.ts} +88 -4
- package/dist/vite.d.ts +24 -7
- package/dist/vite.js +322 -173
- package/package.json +9 -9
- package/dist/errors-CyQyKAvy.d.ts +0 -185
- package/dist/index-DNhy69Wt.d.ts +0 -83
- package/dist/overlay/client-DmsSMOzi.js +0 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as outboxAccountHeader } from "./client-files-CJZl5Kc4.js";
|
|
2
|
+
import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
|
|
2
3
|
import { n as pagePathOf, t as isPagePath } from "./path--zk6PEMz.js";
|
|
3
4
|
import { n as isRecordOrFunction } from "./object-Da1zyPCR.js";
|
|
4
|
-
import { S as createClientRateLimit,
|
|
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-DA5BwfPQ.js";
|
|
5
6
|
import { n as guestFromHeaders, t as authorOf } from "./identity-CBOzgxSf.js";
|
|
6
7
|
import { t as describeCommentContext } from "./context-BqIsmYP1.js";
|
|
7
|
-
import { t as commentsRuntime } from "./server-
|
|
8
|
+
import { t as commentsRuntime } from "./server-Yk610niJ.js";
|
|
8
9
|
import { defineDiagnostics } from "nostics";
|
|
9
10
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
10
11
|
import { getStandardContext } from "@vite-hub/runtime/internal/h3";
|
|
@@ -35,7 +36,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
35
36
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
36
37
|
},
|
|
37
38
|
INTERNAL_R0022: {
|
|
38
|
-
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.",
|
|
39
40
|
why: ({ message }) => message === void 0 ? "" : String(message)
|
|
40
41
|
},
|
|
41
42
|
INTERNAL_R0024: {
|
|
@@ -180,7 +181,7 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
180
181
|
},
|
|
181
182
|
INTERNAL_R0004: {
|
|
182
183
|
...dynamicError,
|
|
183
|
-
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `
|
|
184
|
+
fix: "Set a larger `maxResponseBytes` on the HTTP request, such as the `url()` Source options, or ask the server for a smaller response."
|
|
184
185
|
},
|
|
185
186
|
INTERNAL_R0005: {
|
|
186
187
|
...dynamicError,
|
|
@@ -226,6 +227,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
226
227
|
why: ({ variable }) => `[vitehub] ${variable} must be the 43-character private key that \`vitehub secret console-key\` prints, and its name 1 to 64 of A-Z, 0-9, and _.`,
|
|
227
228
|
fix: "Set the variable that the message names to the private key that `vitehub secret console-key` prints, and name it `VITEHUB_CONSOLE_PRIVATE_KEY_<NAME>` with A-Z, 0-9, and _ in `<NAME>`."
|
|
228
229
|
},
|
|
230
|
+
INTERNAL_DEV_SERVER_NOT_FOUND: {
|
|
231
|
+
why: ({ command }) => `[vitehub] No dev server of this project is running, and --url is not set, so \`vitehub ${command}\` has no app to call.`,
|
|
232
|
+
fix: "Start the dev server of this project, such as with `pnpm dev`, or pass --url with the app URL, such as --url http://localhost:3000."
|
|
233
|
+
},
|
|
229
234
|
INTERNAL_FORGE_NOT_INSTALLED: {
|
|
230
235
|
why: ({ feature }) => `${feature} needs @vite-hub/forge, and the app did not install it.`,
|
|
231
236
|
fix: "Install Forge in your app with `pnpm add @vite-hub/forge`, then build again."
|
|
@@ -250,6 +255,10 @@ const internalErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
|
|
|
250
255
|
why: ({ owner }) => `[vitehub] ${owner} extends tuple requires [preset, options] with an options object.`,
|
|
251
256
|
fix: "Set `extends` to a preset, or to a two-item tuple `[preset, { ...options }]` whose second item is a plain object."
|
|
252
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
|
+
},
|
|
253
262
|
INTERNAL_SECRET_PURPOSE_MISSING: {
|
|
254
263
|
why: "[vitehub] A derived secret requires a purpose.",
|
|
255
264
|
fix: "Pass a non-empty purpose to `deriveSecret()`, such as `deriveSecret(\"my-module:session\")`."
|
|
@@ -450,7 +459,7 @@ function describeCommentThread(thread) {
|
|
|
450
459
|
"",
|
|
451
460
|
...thread.messages.flatMap((message) => [`${commentPersonName(message.author)}, ${new Date(message.createdAt).toISOString()}: ${message.body}`, ...message.attachments.length ? [`Attachments: ${message.attachments.join(", ")}`] : []])
|
|
452
461
|
];
|
|
453
|
-
if (thread.resolvedBy) lines.push("", `Resolved by ${commentPersonName(thread.resolvedBy)} at ${new Date(thread.resolvedAt ?? thread.updatedAt).toISOString()}`);
|
|
462
|
+
if (thread.resolvedBy) lines.push("", `Resolved by ${thread.resolvedActor ? `${thread.resolvedActor.name ?? thread.resolvedActor.id} for ` : ""}${commentPersonName(thread.resolvedBy)} at ${new Date(thread.resolvedAt ?? thread.updatedAt).toISOString()}`);
|
|
454
463
|
return lines.join("\n");
|
|
455
464
|
}
|
|
456
465
|
/** At most `max` characters of `value`, flattened to one line and cut at a word, with `…` when cut. */
|
|
@@ -587,6 +596,17 @@ const metadata = v.optional(v.record(v.string(), v.union([
|
|
|
587
596
|
])));
|
|
588
597
|
const revision = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
589
598
|
const threadId = v.strictObject({ threadId: id });
|
|
599
|
+
const maximumResolvedThreads = 50;
|
|
600
|
+
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."));
|
|
601
|
+
const resolveEntry = v.strictObject({
|
|
602
|
+
threadId: id,
|
|
603
|
+
reply: v.optional(resolveReply)
|
|
604
|
+
});
|
|
605
|
+
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.")) })]);
|
|
606
|
+
async function digest(value) {
|
|
607
|
+
const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
|
|
608
|
+
return Array.from(bytes.subarray(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
609
|
+
}
|
|
590
610
|
function actorOf(actor) {
|
|
591
611
|
return actor ? {
|
|
592
612
|
id: actor.id,
|
|
@@ -641,6 +661,10 @@ function author(who) {
|
|
|
641
661
|
if (!guest) throw fail(commentsErrorDiagnostics.COMMENTS_R0012(), 401);
|
|
642
662
|
return guest;
|
|
643
663
|
}
|
|
664
|
+
function checkOutboxAccount(who) {
|
|
665
|
+
const expected = who.request?.headers.get(outboxAccountHeader);
|
|
666
|
+
if (expected != null && expected !== encodeURIComponent(author(who).id)) throw fail(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), 401);
|
|
667
|
+
}
|
|
644
668
|
const guestLimits = /* @__PURE__ */ new WeakMap();
|
|
645
669
|
/**
|
|
646
670
|
* Counts one write of a guest against `defineComments({ rateLimit })`, by the address of the request. Signed-in people
|
|
@@ -668,6 +692,7 @@ function writeOptions(who) {
|
|
|
668
692
|
console: who.console,
|
|
669
693
|
gate: who.gate,
|
|
670
694
|
user: who.user,
|
|
695
|
+
...who.request ? { request: who.request } : {},
|
|
671
696
|
...who.waitUntil ? { waitUntil: who.waitUntil } : {}
|
|
672
697
|
};
|
|
673
698
|
}
|
|
@@ -714,7 +739,7 @@ const listInput = v.strictObject({
|
|
|
714
739
|
subject: v.optional(subject),
|
|
715
740
|
subjectKind: v.optional(subjectKind)
|
|
716
741
|
});
|
|
717
|
-
const getInput = v.union([v.strictObject({ id }), v.strictObject({
|
|
742
|
+
const getInput = v.union([v.strictObject({ threadId: id }), v.strictObject({
|
|
718
743
|
n: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
719
744
|
scope: v.pipe(v.string(), v.minLength(1), v.maxLength(200))
|
|
720
745
|
})]);
|
|
@@ -732,6 +757,7 @@ const replyInput = v.strictObject({
|
|
|
732
757
|
attachments,
|
|
733
758
|
body: text,
|
|
734
759
|
mentions,
|
|
760
|
+
requestId: v.optional(requestIdSchema),
|
|
735
761
|
threadId: id
|
|
736
762
|
});
|
|
737
763
|
const editInput = v.strictObject({
|
|
@@ -810,12 +836,13 @@ const commentActions = {
|
|
|
810
836
|
return (await readableThreads(input, who)).threads;
|
|
811
837
|
},
|
|
812
838
|
async get(input, who) {
|
|
813
|
-
const found = "
|
|
839
|
+
const found = "threadId" in input ? await who.runtime.store.getById(input.threadId) : await who.runtime.store.getByNumber(input.scope, input.n);
|
|
814
840
|
if (!found || !await permitted(who, "read", { thread: found })) return null;
|
|
815
841
|
return (await withForge(who, [found]))[0];
|
|
816
842
|
},
|
|
817
843
|
/** `context` is the page context that the overlay read and its transport checked. */
|
|
818
844
|
async create(input, who) {
|
|
845
|
+
checkOutboxAccount(who);
|
|
819
846
|
const canRead = (thread) => permitted(who, "read", { thread });
|
|
820
847
|
const earlier = await earlierThread(who.runtime, input);
|
|
821
848
|
if (earlier) return retried(earlier, {
|
|
@@ -836,7 +863,10 @@ const commentActions = {
|
|
|
836
863
|
},
|
|
837
864
|
/** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
|
|
838
865
|
async reply(input, who, options = {}) {
|
|
866
|
+
checkOutboxAccount(who);
|
|
839
867
|
const found = await load(who, input.threadId);
|
|
868
|
+
const earlier = await earlierReply(found, input.requestId);
|
|
869
|
+
if (earlier) return retriedReply(found, earlier, author(who));
|
|
840
870
|
await allow(who, "write", { thread: found });
|
|
841
871
|
await limitGuest(who);
|
|
842
872
|
return replyToThread(who.runtime, found, {
|
|
@@ -844,6 +874,7 @@ const commentActions = {
|
|
|
844
874
|
author: author(who),
|
|
845
875
|
...input.mentions ? { mentions: input.mentions } : {},
|
|
846
876
|
...input.attachments ? { attachments: input.attachments } : {},
|
|
877
|
+
...input.requestId === void 0 ? {} : { requestId: input.requestId },
|
|
847
878
|
...who.actor ? { actor: who.actor } : {}
|
|
848
879
|
}, {
|
|
849
880
|
allowResolved: options.allowResolved === true,
|
|
@@ -885,10 +916,69 @@ const commentActions = {
|
|
|
885
916
|
async setStatus(input, who, status) {
|
|
886
917
|
const found = await load(who, input.threadId);
|
|
887
918
|
await allow(who, "resolve", { thread: found });
|
|
888
|
-
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now());
|
|
919
|
+
const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now(), status === "resolved" ? who.actor : void 0);
|
|
889
920
|
who.runtime.forge?.changed(found.id);
|
|
921
|
+
if (status === "open") await who.runtime.reopened?.(next);
|
|
890
922
|
return next;
|
|
891
923
|
},
|
|
924
|
+
async resolveThreads(input, who) {
|
|
925
|
+
const by = author(who);
|
|
926
|
+
const plans = await Promise.all(input.map(async (entry) => {
|
|
927
|
+
const thread = await load(who, entry.threadId);
|
|
928
|
+
await allow(who, "resolve", { thread });
|
|
929
|
+
const body = entry.reply?.trim();
|
|
930
|
+
if (body === void 0) return { thread };
|
|
931
|
+
checkOutboxAccount(who);
|
|
932
|
+
await allow(who, "write", { thread });
|
|
933
|
+
const replyKey = async (previousId) => `resolve:${await digest(JSON.stringify([
|
|
934
|
+
by.id,
|
|
935
|
+
who.actor?.id,
|
|
936
|
+
previousId,
|
|
937
|
+
body
|
|
938
|
+
]))}`;
|
|
939
|
+
const last = thread.messages.at(-1);
|
|
940
|
+
if (thread.status === "resolved" && last && last.createdAt <= (thread.resolvedAt ?? 0) && last.body === body) {
|
|
941
|
+
if ((await earlierReply(thread, await replyKey(thread.messages.at(-2)?.id)))?.id === last.id) return { thread };
|
|
942
|
+
}
|
|
943
|
+
return {
|
|
944
|
+
thread,
|
|
945
|
+
reply: {
|
|
946
|
+
author: by,
|
|
947
|
+
body,
|
|
948
|
+
requestId: await replyKey(last?.id),
|
|
949
|
+
...who.actor ? { actor: who.actor } : {}
|
|
950
|
+
}
|
|
951
|
+
};
|
|
952
|
+
}));
|
|
953
|
+
for (const plan of plans) if (plan.reply) await limitGuest(who);
|
|
954
|
+
const resolved = [];
|
|
955
|
+
for (const plan of plans) {
|
|
956
|
+
let { thread } = plan;
|
|
957
|
+
let replied = false;
|
|
958
|
+
try {
|
|
959
|
+
if (plan.reply) {
|
|
960
|
+
thread = (await replyToThread(who.runtime, thread, plan.reply, {
|
|
961
|
+
allowResolved: true,
|
|
962
|
+
...writeOptions(who)
|
|
963
|
+
})).thread;
|
|
964
|
+
replied = true;
|
|
965
|
+
}
|
|
966
|
+
if (thread.status !== "resolved" || thread.messages.some((message) => message.createdAt > (thread.resolvedAt ?? 0))) {
|
|
967
|
+
thread = await who.runtime.store.setStatus(thread.id, "resolved", by, Date.now(), who.actor);
|
|
968
|
+
who.runtime.forge?.changed(thread.id);
|
|
969
|
+
}
|
|
970
|
+
resolved.push(thread);
|
|
971
|
+
} catch (cause) {
|
|
972
|
+
if (!resolved.length && !replied) throw cause;
|
|
973
|
+
throw Object.assign(fail(commentsErrorDiagnostics.COMMENTS_RESOLVE_INTERRUPTED({
|
|
974
|
+
completed: resolved.map((entry) => entry.id),
|
|
975
|
+
threadId: thread.id,
|
|
976
|
+
replied
|
|
977
|
+
}), 409), { cause });
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
return resolved;
|
|
981
|
+
},
|
|
892
982
|
/** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
|
|
893
983
|
async users(input, who, options = {}) {
|
|
894
984
|
const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
|
|
@@ -907,6 +997,7 @@ const commentActions = {
|
|
|
907
997
|
});
|
|
908
998
|
},
|
|
909
999
|
async upload(input, who) {
|
|
1000
|
+
checkOutboxAccount(who);
|
|
910
1001
|
const target = input.subject ? { subject: input.subject } : {};
|
|
911
1002
|
await allow(who, "read", target);
|
|
912
1003
|
await allow(who, "write", target);
|
|
@@ -923,11 +1014,6 @@ const commentActions = {
|
|
|
923
1014
|
});
|
|
924
1015
|
}
|
|
925
1016
|
};
|
|
926
|
-
function base64(bytes) {
|
|
927
|
-
let binary = "";
|
|
928
|
-
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
929
|
-
return btoa(binary);
|
|
930
|
-
}
|
|
931
1017
|
const list = defineOperation({
|
|
932
1018
|
description: "ViteHub Comments: list threads on any subject, such as the app's pages where people comment with the Comments toolbar, newest first, as full threads. Filter by subject, page, status, author, mention, or subject revision. Pass the last thread as `before` for the next page. For a short list of page threads, use comments.threads.",
|
|
933
1019
|
input: listInput,
|
|
@@ -936,224 +1022,231 @@ const list = defineOperation({
|
|
|
936
1022
|
run: async (input, context) => commentActions.list(input, await caller(context)),
|
|
937
1023
|
section: "comments"
|
|
938
1024
|
});
|
|
1025
|
+
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.";
|
|
939
1026
|
/** Threads that one search reads from the store at a time. */
|
|
940
1027
|
const searchBatch = maximumLimit;
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
1028
|
+
/** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
|
|
1029
|
+
const commentsOperations = [
|
|
1030
|
+
defineOperation({
|
|
1031
|
+
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.",
|
|
1032
|
+
input: threadsInput,
|
|
1033
|
+
kind: "read",
|
|
1034
|
+
name: "comments.threads",
|
|
1035
|
+
run: async (input, context) => {
|
|
1036
|
+
const who = await caller(context);
|
|
1037
|
+
const status = input.status ?? "open";
|
|
1038
|
+
const limit = input.limit ?? 25;
|
|
1039
|
+
const search = input.search?.toLowerCase();
|
|
1040
|
+
const batch = search ? searchBatch : limit;
|
|
1041
|
+
const found = [];
|
|
1042
|
+
let hidden = 0;
|
|
1043
|
+
let before;
|
|
1044
|
+
while (found.length < limit) {
|
|
1045
|
+
const listed = await readableThreads({
|
|
1046
|
+
limit: batch,
|
|
1047
|
+
status,
|
|
1048
|
+
subjectKind: "page",
|
|
1049
|
+
...input.page ? { page: input.page } : {},
|
|
1050
|
+
...before ? { before } : {}
|
|
1051
|
+
}, who);
|
|
1052
|
+
hidden += listed.hidden;
|
|
1053
|
+
for (const thread of listed.threads) {
|
|
1054
|
+
if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
|
|
1055
|
+
if (found.length === limit) break;
|
|
1056
|
+
}
|
|
1057
|
+
if (listed.threads.length < batch) break;
|
|
1058
|
+
before = cursorOf(listed.threads.at(-1));
|
|
967
1059
|
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
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
|
-
|
|
1060
|
+
const note = hiddenThreadsNote(hidden, {
|
|
1061
|
+
authorize: Boolean(who.runtime.definition.authorize),
|
|
1062
|
+
identify: Boolean(who.runtime.identify),
|
|
1063
|
+
user: who.user !== null,
|
|
1064
|
+
console: who.console === true
|
|
1065
|
+
});
|
|
1066
|
+
const next = status === "open" && found.length ? resolveNext : void 0;
|
|
1067
|
+
return {
|
|
1068
|
+
status,
|
|
1069
|
+
threads: found.map(commentThreadSummary),
|
|
1070
|
+
hidden,
|
|
1071
|
+
...note ? { note } : {},
|
|
1072
|
+
...next ? { next } : {}
|
|
1073
|
+
};
|
|
1074
|
+
},
|
|
1075
|
+
mcp: {
|
|
1076
|
+
format: ({ status, threads, note }) => commentThreadsText(threads, status, note ?? ""),
|
|
1077
|
+
title: "List ViteHub Comments threads"
|
|
1078
|
+
},
|
|
1079
|
+
section: "comments"
|
|
1080
|
+
}),
|
|
1081
|
+
list,
|
|
1082
|
+
defineOperation({
|
|
1083
|
+
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.",
|
|
1084
|
+
input: getInput,
|
|
1085
|
+
kind: "read",
|
|
1086
|
+
name: "comments.get",
|
|
1087
|
+
run: async (input, context) => commentActions.get(input, await caller(context)),
|
|
1088
|
+
mcp: {
|
|
1089
|
+
format: (thread) => thread ? describeCommentThread(thread) : "No thread with this id that you may read.",
|
|
1090
|
+
title: "Read a comment thread"
|
|
1091
|
+
},
|
|
1092
|
+
section: "comments"
|
|
1093
|
+
}),
|
|
1094
|
+
defineOperation({
|
|
1095
|
+
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.",
|
|
1096
|
+
input: createInput,
|
|
1097
|
+
kind: "write",
|
|
1098
|
+
name: "comments.create",
|
|
1099
|
+
run: async (input, context) => commentActions.create(input, await caller(context)),
|
|
1100
|
+
section: "comments"
|
|
1101
|
+
}),
|
|
1102
|
+
defineOperation({
|
|
1103
|
+
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.",
|
|
1104
|
+
input: replyInput,
|
|
1105
|
+
kind: "write",
|
|
1106
|
+
name: "comments.reply",
|
|
1107
|
+
run: async (input, context) => (await commentActions.reply(input, await caller(context), { allowResolved: true })).thread,
|
|
1108
|
+
mcp: {
|
|
1109
|
+
format: (thread) => `Replied to thread ${thread.id}.`,
|
|
1110
|
+
title: "Reply to a comment thread"
|
|
1111
|
+
},
|
|
1112
|
+
section: "comments"
|
|
1113
|
+
}),
|
|
1114
|
+
defineOperation({
|
|
1115
|
+
description: "Change the text of your own message.",
|
|
1116
|
+
input: editInput,
|
|
1117
|
+
kind: "write",
|
|
1118
|
+
name: "comments.edit",
|
|
1119
|
+
run: async (input, context) => commentActions.edit(input, await caller(context)),
|
|
1120
|
+
section: "comments"
|
|
1121
|
+
}),
|
|
1122
|
+
defineOperation({
|
|
1123
|
+
description: "Delete a message, or the whole thread. Deleting the first message deletes the thread.",
|
|
1124
|
+
input: deleteInput,
|
|
1125
|
+
kind: "destructive",
|
|
1126
|
+
name: "comments.delete",
|
|
1127
|
+
run: async (input, context) => commentActions.delete(input, await caller(context)),
|
|
1128
|
+
section: "comments"
|
|
1129
|
+
}),
|
|
1130
|
+
defineOperation({
|
|
1131
|
+
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.",
|
|
1132
|
+
input: resolveInput,
|
|
1133
|
+
kind: "write",
|
|
1134
|
+
maxRequestBytes: 32e5,
|
|
1135
|
+
name: "comments.resolve",
|
|
1136
|
+
run: async (input, context) => {
|
|
1137
|
+
const who = await caller(context);
|
|
1138
|
+
if ("threads" in input) return commentActions.resolveThreads(input.threads, who);
|
|
1139
|
+
const [thread] = await commentActions.resolveThreads([input], who);
|
|
1140
|
+
return thread;
|
|
1141
|
+
},
|
|
1142
|
+
mcp: {
|
|
1143
|
+
format: (output) => [output].flat().map((thread) => `Thread ${thread.id} is ${thread.status}.`).join("\n"),
|
|
1144
|
+
title: "Resolve comment threads"
|
|
1145
|
+
},
|
|
1146
|
+
section: "comments"
|
|
1147
|
+
}),
|
|
1148
|
+
defineOperation({
|
|
1149
|
+
description: "Open a resolved comment thread again.",
|
|
1041
1150
|
input: threadId,
|
|
1042
1151
|
kind: "write",
|
|
1152
|
+
name: "comments.reopen",
|
|
1153
|
+
run: async (input, context) => commentActions.setStatus(input, await caller(context), "open"),
|
|
1043
1154
|
mcp: {
|
|
1044
1155
|
format: (thread) => `Thread ${thread.id} is ${thread.status}.`,
|
|
1045
|
-
title
|
|
1156
|
+
title: "Reopen a comment thread"
|
|
1046
1157
|
},
|
|
1047
|
-
name,
|
|
1048
|
-
run: async (input, context) => commentActions.setStatus(input, await caller(context), status),
|
|
1049
1158
|
section: "comments"
|
|
1050
|
-
});
|
|
1051
|
-
}
|
|
1052
|
-
const users = defineOperation({
|
|
1053
|
-
description: "Find people to mention by name. Needs at least two characters, and the right to write.",
|
|
1054
|
-
input: usersInput,
|
|
1055
|
-
kind: "read",
|
|
1056
|
-
name: "comments.users",
|
|
1057
|
-
run: async (input, context) => commentActions.users(input, await caller(context)),
|
|
1058
|
-
section: "comments"
|
|
1059
|
-
});
|
|
1060
|
-
const upload = defineOperation({
|
|
1061
|
-
description: "Store a file to attach to a comment. Pass the returned key in `attachments` of comments.create or comments.reply.",
|
|
1062
|
-
input: uploadInput,
|
|
1063
|
-
kind: "write",
|
|
1064
|
-
maxRequestBytes: Math.ceil(maximumAttachmentBytes / 3) * 4 + 4096,
|
|
1065
|
-
mcp: false,
|
|
1066
|
-
name: "comments.upload",
|
|
1067
|
-
run: async (input, context) => commentActions.upload(input, await caller(context)),
|
|
1068
|
-
section: "comments"
|
|
1069
|
-
});
|
|
1070
|
-
const attachment = defineOperation({
|
|
1071
|
-
description: "Read the file of an attachment key, Base64-encoded, from a thread that you may read.",
|
|
1072
|
-
input: attachmentInput,
|
|
1073
|
-
kind: "read",
|
|
1074
|
-
mcp: false,
|
|
1075
|
-
name: "comments.attachment",
|
|
1076
|
-
run: async (input, context) => {
|
|
1077
|
-
const file = await commentActions.attachment(input, await caller(context));
|
|
1078
|
-
return {
|
|
1079
|
-
data: base64(new Uint8Array(await file.data.arrayBuffer())),
|
|
1080
|
-
inline: file.inline,
|
|
1081
|
-
key: file.key,
|
|
1082
|
-
name: file.name,
|
|
1083
|
-
size: file.size,
|
|
1084
|
-
type: file.type
|
|
1085
|
-
};
|
|
1086
|
-
},
|
|
1087
|
-
section: "comments"
|
|
1088
|
-
});
|
|
1089
|
-
const session = defineOperation({
|
|
1090
|
-
description: "Tell the comments overlay who is signed in and what that person may do. Nothing else leaves the server.",
|
|
1091
|
-
input: v.strictObject({
|
|
1092
|
-
subject: v.optional(subject),
|
|
1093
|
-
threadId: v.optional(id)
|
|
1094
1159
|
}),
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1160
|
+
defineOperation({
|
|
1161
|
+
description: "Find people to mention by name. Needs at least two characters, and the right to write.",
|
|
1162
|
+
input: usersInput,
|
|
1163
|
+
kind: "read",
|
|
1164
|
+
name: "comments.users",
|
|
1165
|
+
run: async (input, context) => commentActions.users(input, await caller(context)),
|
|
1166
|
+
section: "comments"
|
|
1167
|
+
}),
|
|
1168
|
+
defineOperation({
|
|
1169
|
+
description: "Store a file to attach to a comment. Pass the returned key in `attachments` of comments.create or comments.reply.",
|
|
1170
|
+
input: uploadInput,
|
|
1171
|
+
kind: "write",
|
|
1172
|
+
maxRequestBytes: Math.ceil(maximumAttachmentBytes / 3) * 4 + 4096,
|
|
1173
|
+
mcp: false,
|
|
1174
|
+
name: "comments.upload",
|
|
1175
|
+
run: async (input, context) => commentActions.upload(input, await caller(context)),
|
|
1176
|
+
section: "comments"
|
|
1177
|
+
}),
|
|
1178
|
+
defineOperation({
|
|
1179
|
+
description: "Read the file of an attachment key, Base64-encoded, from a thread that you may read.",
|
|
1180
|
+
input: attachmentInput,
|
|
1181
|
+
kind: "read",
|
|
1182
|
+
mcp: false,
|
|
1183
|
+
name: "comments.attachment",
|
|
1184
|
+
run: async (input, context) => {
|
|
1185
|
+
const file = await commentActions.attachment(input, await caller(context));
|
|
1119
1186
|
return {
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1187
|
+
data: base64(new Uint8Array(await file.data.arrayBuffer())),
|
|
1188
|
+
inline: file.inline,
|
|
1189
|
+
key: file.key,
|
|
1190
|
+
name: file.name,
|
|
1191
|
+
size: file.size,
|
|
1192
|
+
type: file.type
|
|
1193
|
+
};
|
|
1194
|
+
},
|
|
1195
|
+
section: "comments"
|
|
1196
|
+
}),
|
|
1197
|
+
defineOperation({
|
|
1198
|
+
description: "Tell the comments overlay who is signed in and what that person may do. Nothing else leaves the server.",
|
|
1199
|
+
input: v.strictObject({
|
|
1200
|
+
subject: v.optional(subject),
|
|
1201
|
+
threadId: v.optional(id)
|
|
1202
|
+
}),
|
|
1203
|
+
kind: "read",
|
|
1204
|
+
name: "comments.session",
|
|
1205
|
+
run: async (input, context) => {
|
|
1206
|
+
const who = await caller(context);
|
|
1207
|
+
if (!who.user) return {
|
|
1208
|
+
canRead: false,
|
|
1209
|
+
canWrite: false,
|
|
1210
|
+
user: null
|
|
1211
|
+
};
|
|
1212
|
+
if (input.threadId) {
|
|
1213
|
+
const found = await load(who, input.threadId);
|
|
1214
|
+
const can = (action) => permitted(who, action, { thread: found }).catch(() => false);
|
|
1215
|
+
const [write, resolve, remove] = await Promise.all([
|
|
1216
|
+
can("write"),
|
|
1217
|
+
can("resolve"),
|
|
1218
|
+
can("delete")
|
|
1219
|
+
]);
|
|
1220
|
+
const writes = operationAccessAllows(context.access, "comments", { kind: "write" });
|
|
1221
|
+
const deletes = operationAccessAllows(context.access, "comments", { kind: "destructive" });
|
|
1222
|
+
const signedIn = who.user.guest !== true;
|
|
1223
|
+
const userId = who.user.id;
|
|
1224
|
+
const owns = (message) => signedIn && !who.actor && !message.author.guest && message.author.id === userId;
|
|
1225
|
+
const ownsThread = found.messages.every(owns);
|
|
1226
|
+
const deleteThread = signedIn && deletes && (ownsThread ? write : remove);
|
|
1227
|
+
return {
|
|
1228
|
+
canRead: true,
|
|
1229
|
+
canWrite: writes && write,
|
|
1230
|
+
capabilities: {
|
|
1231
|
+
delete: found.messages.filter((message, index) => index === 0 ? deleteThread : signedIn && deletes && (owns(message) ? write : remove)).map((message) => message.id),
|
|
1232
|
+
deleteThread,
|
|
1233
|
+
edit: signedIn && writes && (!who.actor || write) ? found.messages.filter((message) => !message.author.guest && message.author.id === userId).map((message) => message.id) : [],
|
|
1234
|
+
reply: writes && write,
|
|
1235
|
+
resolve: writes && resolve
|
|
1236
|
+
},
|
|
1237
|
+
user: personOf(who.user)
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
const allowed = (action) => permitted(who, action, input.subject ? { subject: input.subject } : {}).catch(() => false);
|
|
1241
|
+
const [canRead, canWrite] = await Promise.all([allowed("read"), allowed("write")]);
|
|
1242
|
+
return {
|
|
1243
|
+
canRead,
|
|
1244
|
+
canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
|
|
1129
1245
|
user: personOf(who.user)
|
|
1130
1246
|
};
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
return {
|
|
1135
|
-
canRead,
|
|
1136
|
-
canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
|
|
1137
|
-
user: personOf(who.user)
|
|
1138
|
-
};
|
|
1139
|
-
},
|
|
1140
|
-
section: "comments"
|
|
1141
|
-
});
|
|
1142
|
-
/** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
|
|
1143
|
-
const commentsOperations = [
|
|
1144
|
-
threads,
|
|
1145
|
-
list,
|
|
1146
|
-
get,
|
|
1147
|
-
create,
|
|
1148
|
-
reply,
|
|
1149
|
-
edit,
|
|
1150
|
-
remove,
|
|
1151
|
-
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"),
|
|
1152
|
-
statusOperation("comments.reopen", "open", "Open a resolved comment thread again.", "Reopen a comment thread"),
|
|
1153
|
-
users,
|
|
1154
|
-
upload,
|
|
1155
|
-
attachment,
|
|
1156
|
-
session
|
|
1247
|
+
},
|
|
1248
|
+
section: "comments"
|
|
1249
|
+
})
|
|
1157
1250
|
];
|
|
1158
1251
|
//#endregion
|
|
1159
1252
|
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 };
|