@vite-hub/comments 0.4.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.
Files changed (59) hide show
  1. package/README.md +19 -7
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/client.d.ts +424 -11
  4. package/dist/client.js +405 -5
  5. package/dist/{console-h4KlhIik.d.ts → console-D1lwNMZn.d.ts} +2 -0
  6. package/dist/{migrate-Bpw3xL5e.js → database-6hXRnqDE.js} +47 -2
  7. package/dist/database-CTo7mx6t.d.ts +575 -0
  8. package/dist/database.d.ts +2 -1
  9. package/dist/database.js +2 -2
  10. package/dist/{define-CX_Yr_hz.js → define-BMBSVbD9.js} +1 -1
  11. package/dist/{define-CHTWfHPo.d.ts → define-CmIFU96x.d.ts} +8 -4
  12. package/dist/{errors-4gelGVmK.js → errors-BJTZ9iyv.js} +24 -0
  13. package/dist/{errors-BHsVXlpd.js → errors-Dq4AHjza.js} +16 -0
  14. package/dist/{index-iPGlSAgj.d.ts → index-RiHzmV16.d.ts} +113 -11
  15. package/dist/index.d.ts +6 -7
  16. package/dist/index.js +21 -7
  17. package/dist/{install-96NXWnrw.d.ts → install-BGGQKbQ4.d.ts} +9 -3
  18. package/dist/{install-jRKmuLHK.js → install-DrAse1Fa.js} +844 -38
  19. package/dist/{installed-g6nDr5ac.js → installed-C3EoqJEY.js} +7 -6
  20. package/dist/{operations-D93EV10O.d.ts → operations-BKhUWYkb.d.ts} +9 -5
  21. package/dist/{operations-7ycAhDCw.d.ts → operations-VyyNZusz.d.ts} +8 -2
  22. package/dist/{operations-9tskoLsk.js → operations-lsVKE0GH.js} +294 -212
  23. package/dist/operations.d.ts +2 -2
  24. package/dist/operations.js +2 -2
  25. package/dist/overlay/{client-lZesR40x.js → client-DBmJ4C1M.js} +1 -1
  26. package/dist/overlay/overlay.js +36 -40
  27. package/dist/page/loader.js +39 -47
  28. package/dist/{page-CWwnmF3K.d.ts → page-Bzj0CszG.d.ts} +1 -10
  29. package/dist/{page-tools-shared-NHUjKI8E.js → page-tools-shared-BNnuPK93.js} +6 -3
  30. package/dist/{plugin-BNFd1zGz.js → plugin-DRsNaJaK.js} +14 -9
  31. package/dist/realtime.d.ts +2 -2
  32. package/dist/realtime.js +1 -1
  33. package/dist/request-log-Dj9Vw7qG.js +105 -0
  34. package/dist/request-origin-CFU0TQ7E.js +49 -0
  35. package/dist/{rpc-BZ1QNkCC.d.ts → rpc-CuJ5GLIz.d.ts} +1 -1
  36. package/dist/rpc.d.ts +1 -1
  37. package/dist/runtime/auth.d.ts +2 -2
  38. package/dist/runtime/auth.js +1 -1
  39. package/dist/runtime/console.d.ts +1 -1
  40. package/dist/runtime/console.js +1 -1
  41. package/dist/runtime/index.d.ts +11 -9
  42. package/dist/runtime/index.js +148 -14
  43. package/dist/{server-CqyzrqTI.js → server-Yk610niJ.js} +1 -1
  44. package/dist/server.d.ts +6 -5
  45. package/dist/server.js +5 -5
  46. package/dist/service-Bj-Mg63c.d.ts +73 -0
  47. package/dist/{service-C8ZgFWvy.js → service-DA5BwfPQ.js} +39 -11
  48. package/dist/{session-CKfW6DGE.d.ts → session-DUcEor2W.d.ts} +3 -3
  49. package/dist/{session-ByjMyTak.js → session-X_g9dnU5.js} +26 -29
  50. package/dist/{service-wC9kx9EX.d.ts → store-CsUNfC1w.d.ts} +2 -70
  51. package/dist/{table-names-DfiKUlOV.js → table-names-B9LlRC0B.js} +3 -1
  52. package/dist/testing.d.ts +1 -1
  53. package/dist/testing.js +2 -2
  54. package/dist/{types-C7LzhgRb.d.ts → types-BLaYh0_f.d.ts} +1 -1
  55. package/dist/{types-C1qzObs2.d.ts → types-C35INXIs.d.ts} +79 -4
  56. package/dist/vite.d.ts +22 -5
  57. package/dist/vite.js +140 -65
  58. package/package.json +8 -8
  59. package/dist/errors-BEChnUo7.d.ts +0 -197
@@ -1,11 +1,11 @@
1
1
  import { n as outboxAccountHeader } from "./client-files-CJZl5Kc4.js";
2
- import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-Dq4AHjza.js";
3
3
  import { n as pagePathOf, t as isPagePath } from "./path--zk6PEMz.js";
4
4
  import { n as isRecordOrFunction } from "./object-Da1zyPCR.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-C8ZgFWvy.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-DA5BwfPQ.js";
6
6
  import { n as guestFromHeaders, t as authorOf } from "./identity-CBOzgxSf.js";
7
7
  import { t as describeCommentContext } from "./context-BqIsmYP1.js";
8
- import { t as commentsRuntime } from "./server-CqyzrqTI.js";
8
+ import { t as commentsRuntime } from "./server-Yk610niJ.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";
@@ -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\")`."
@@ -592,6 +596,17 @@ const metadata = v.optional(v.record(v.string(), v.union([
592
596
  ])));
593
597
  const revision = v.pipe(v.number(), v.integer(), v.minValue(0));
594
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
+ }
595
610
  function actorOf(actor) {
596
611
  return actor ? {
597
612
  id: actor.id,
@@ -677,6 +692,7 @@ function writeOptions(who) {
677
692
  console: who.console,
678
693
  gate: who.gate,
679
694
  user: who.user,
695
+ ...who.request ? { request: who.request } : {},
680
696
  ...who.waitUntil ? { waitUntil: who.waitUntil } : {}
681
697
  };
682
698
  }
@@ -723,7 +739,7 @@ const listInput = v.strictObject({
723
739
  subject: v.optional(subject),
724
740
  subjectKind: v.optional(subjectKind)
725
741
  });
726
- const getInput = v.union([v.strictObject({ id }), v.strictObject({
742
+ const getInput = v.union([v.strictObject({ threadId: id }), v.strictObject({
727
743
  n: v.pipe(v.number(), v.integer(), v.minValue(1)),
728
744
  scope: v.pipe(v.string(), v.minLength(1), v.maxLength(200))
729
745
  })]);
@@ -820,7 +836,7 @@ const commentActions = {
820
836
  return (await readableThreads(input, who)).threads;
821
837
  },
822
838
  async get(input, who) {
823
- const found = "id" in input ? await who.runtime.store.getById(input.id) : await who.runtime.store.getByNumber(input.scope, input.n);
839
+ const found = "threadId" in input ? await who.runtime.store.getById(input.threadId) : await who.runtime.store.getByNumber(input.scope, input.n);
824
840
  if (!found || !await permitted(who, "read", { thread: found })) return null;
825
841
  return (await withForge(who, [found]))[0];
826
842
  },
@@ -900,10 +916,69 @@ const commentActions = {
900
916
  async setStatus(input, who, status) {
901
917
  const found = await load(who, input.threadId);
902
918
  await allow(who, "resolve", { thread: found });
903
- 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);
904
920
  who.runtime.forge?.changed(found.id);
921
+ if (status === "open") await who.runtime.reopened?.(next);
905
922
  return next;
906
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
+ },
907
982
  /** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
908
983
  async users(input, who, options = {}) {
909
984
  const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
@@ -947,224 +1022,231 @@ const list = defineOperation({
947
1022
  run: async (input, context) => commentActions.list(input, await caller(context)),
948
1023
  section: "comments"
949
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.";
950
1026
  /** Threads that one search reads from the store at a time. */
951
1027
  const searchBatch = maximumLimit;
952
- const threads = defineOperation({
953
- 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. After you change the code, reply with comments.reply and resolve it with comments.resolve.",
954
- input: threadsInput,
955
- kind: "read",
956
- name: "comments.threads",
957
- run: async (input, context) => {
958
- const who = await caller(context);
959
- const status = input.status ?? "open";
960
- const limit = input.limit ?? 25;
961
- const search = input.search?.toLowerCase();
962
- const batch = search ? searchBatch : limit;
963
- const found = [];
964
- let hidden = 0;
965
- let before;
966
- while (found.length < limit) {
967
- const listed = await readableThreads({
968
- limit: batch,
969
- status,
970
- subjectKind: "page",
971
- ...input.page ? { page: input.page } : {},
972
- ...before ? { before } : {}
973
- }, who);
974
- hidden += listed.hidden;
975
- for (const thread of listed.threads) {
976
- if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
977
- if (found.length === limit) break;
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));
978
1059
  }
979
- if (listed.threads.length < batch) break;
980
- before = cursorOf(listed.threads.at(-1));
981
- }
982
- const note = hiddenThreadsNote(hidden, {
983
- authorize: Boolean(who.runtime.definition.authorize),
984
- identify: Boolean(who.runtime.identify),
985
- user: who.user !== null,
986
- console: who.console === true
987
- });
988
- return {
989
- status,
990
- threads: found.map(commentThreadSummary),
991
- hidden,
992
- ...note ? { note } : {}
993
- };
994
- },
995
- mcp: {
996
- format: ({ status, threads, note }) => commentThreadsText(threads, status, note ?? ""),
997
- title: "List ViteHub Comments threads"
998
- },
999
- section: "comments"
1000
- });
1001
- const get = defineOperation({
1002
- description: "Read one comment thread by id, or by 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.",
1003
- input: getInput,
1004
- kind: "read",
1005
- name: "comments.get",
1006
- run: async (input, context) => commentActions.get(input, await caller(context)),
1007
- mcp: {
1008
- format: (thread) => thread ? describeCommentThread(thread) : "No thread with this id that you may read.",
1009
- title: "Read a comment thread"
1010
- },
1011
- section: "comments"
1012
- });
1013
- const create = defineOperation({
1014
- 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.",
1015
- input: createInput,
1016
- kind: "write",
1017
- name: "comments.create",
1018
- run: async (input, context) => commentActions.create(input, await caller(context)),
1019
- section: "comments"
1020
- });
1021
- const reply = defineOperation({
1022
- description: "Add a message to a comment thread, for example to say what you changed. A resolved thread stays resolved. Send the same `requestId` again to retry: you get the first message, not a second one.",
1023
- input: replyInput,
1024
- kind: "write",
1025
- name: "comments.reply",
1026
- run: async (input, context) => (await commentActions.reply(input, await caller(context), { allowResolved: true })).thread,
1027
- mcp: {
1028
- format: (thread) => `Replied to thread ${thread.id}.`,
1029
- title: "Reply to a comment thread"
1030
- },
1031
- section: "comments"
1032
- });
1033
- const edit = defineOperation({
1034
- description: "Change the text of your own message.",
1035
- input: editInput,
1036
- kind: "write",
1037
- name: "comments.edit",
1038
- run: async (input, context) => commentActions.edit(input, await caller(context)),
1039
- section: "comments"
1040
- });
1041
- const remove = defineOperation({
1042
- description: "Delete a message, or the whole thread. Deleting the first message deletes the thread.",
1043
- input: deleteInput,
1044
- kind: "destructive",
1045
- name: "comments.delete",
1046
- run: async (input, context) => commentActions.delete(input, await caller(context)),
1047
- section: "comments"
1048
- });
1049
- function statusOperation(name, status, description, title) {
1050
- return defineOperation({
1051
- description,
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.",
1052
1150
  input: threadId,
1053
1151
  kind: "write",
1152
+ name: "comments.reopen",
1153
+ run: async (input, context) => commentActions.setStatus(input, await caller(context), "open"),
1054
1154
  mcp: {
1055
1155
  format: (thread) => `Thread ${thread.id} is ${thread.status}.`,
1056
- title
1156
+ title: "Reopen a comment thread"
1057
1157
  },
1058
- name,
1059
- run: async (input, context) => commentActions.setStatus(input, await caller(context), status),
1060
1158
  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
1159
  }),
1106
- kind: "read",
1107
- name: "comments.session",
1108
- run: async (input, context) => {
1109
- const who = await caller(context);
1110
- if (!who.user) return {
1111
- canRead: false,
1112
- canWrite: false,
1113
- user: null
1114
- };
1115
- if (input.threadId) {
1116
- const found = await load(who, input.threadId);
1117
- const can = (action) => permitted(who, action, { thread: found }).catch(() => false);
1118
- const [write, resolve, remove] = await Promise.all([
1119
- can("write"),
1120
- can("resolve"),
1121
- can("delete")
1122
- ]);
1123
- const writes = operationAccessAllows(context.access, "comments", { kind: "write" });
1124
- const deletes = operationAccessAllows(context.access, "comments", { kind: "destructive" });
1125
- const signedIn = who.user.guest !== true;
1126
- const userId = who.user.id;
1127
- const owns = (message) => signedIn && !who.actor && !message.author.guest && message.author.id === userId;
1128
- const ownsThread = found.messages.every(owns);
1129
- const deleteThread = signedIn && deletes && (ownsThread ? write : remove);
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));
1186
+ return {
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")]);
1130
1242
  return {
1131
- canRead: true,
1132
- canWrite: writes && write,
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
- },
1243
+ canRead,
1244
+ canWrite: canRead && canWrite && operationAccessAllows(context.access, "comments", { kind: "write" }),
1140
1245
  user: personOf(who.user)
1141
1246
  };
1142
- }
1143
- const allowed = (action) => permitted(who, action, input.subject ? { subject: input.subject } : {}).catch(() => false);
1144
- const [canRead, canWrite] = await Promise.all([allowed("read"), allowed("write")]);
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
1247
+ },
1248
+ section: "comments"
1249
+ })
1168
1250
  ];
1169
1251
  //#endregion
1170
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 };
@@ -1,3 +1,3 @@
1
- import { a as maximumCommentBodyLength } from "./service-wC9kx9EX.js";
2
- import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-D93EV10O.js";
1
+ import { a as maximumCommentBodyLength } from "./service-Bj-Mg63c.js";
2
+ import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-BKhUWYkb.js";
3
3
  export { CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
@@ -1,3 +1,3 @@
1
- import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-9tskoLsk.js";
2
- import { f as maximumCommentBodyLength } from "./service-C8ZgFWvy.js";
1
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-lsVKE0GH.js";
2
+ import { f as maximumCommentBodyLength } from "./service-DA5BwfPQ.js";
3
3
  export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };