@vite-hub/comments 0.3.1 → 0.4.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.
Files changed (56) hide show
  1. package/README.md +20 -10
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/{client-diagnostics-CcFpkbAk.js → client-diagnostics-Bubm7Shd.js} +20 -5
  4. package/dist/client-files-CJZl5Kc4.js +53 -0
  5. package/dist/client.d.ts +151 -10
  6. package/dist/client.js +807 -32
  7. package/dist/database.js +1 -1
  8. package/dist/{define-B3TF9zzn.d.ts → define-CHTWfHPo.d.ts} +1 -1
  9. package/dist/{define-43mMR39K.js → define-CX_Yr_hz.js} +1 -1
  10. package/dist/{errors-CyQyKAvy.d.ts → errors-BEChnUo7.d.ts} +14 -2
  11. package/dist/{errors-C6qptPoG.js → errors-BHsVXlpd.js} +7 -3
  12. package/dist/{index-DNhy69Wt.d.ts → index-iPGlSAgj.d.ts} +13 -4
  13. package/dist/index.d.ts +7 -7
  14. package/dist/index.js +41 -7
  15. package/dist/{install-W9ghhGoh.d.ts → install-96NXWnrw.d.ts} +3 -3
  16. package/dist/{install-BcMPgPk_.js → install-jRKmuLHK.js} +72 -26
  17. package/dist/{installed-B-PfERBU.js → installed-g6nDr5ac.js} +1 -1
  18. package/dist/{migrate-BDQ8xqUs.js → migrate-Bpw3xL5e.js} +1 -1
  19. package/dist/{operations-D4A1Fcgf.d.ts → operations-7ycAhDCw.d.ts} +5 -0
  20. package/dist/{operations-DMMIfYPW.js → operations-9tskoLsk.js} +22 -11
  21. package/dist/{operations-GLeOqgMt.d.ts → operations-D93EV10O.d.ts} +5 -4
  22. package/dist/operations.d.ts +2 -2
  23. package/dist/operations.js +2 -2
  24. package/dist/overlay/client-lZesR40x.js +4 -0
  25. package/dist/overlay/overlay.js +20 -40
  26. package/dist/{page-DtbMOEMd.d.ts → page-CWwnmF3K.d.ts} +1 -1
  27. package/dist/{page-B41ozN63.js → page-DRz_sDY4.js} +1 -1
  28. package/dist/{plugin-PS8PMYus.js → plugin-BNFd1zGz.js} +27 -6
  29. package/dist/realtime.d.ts +2 -2
  30. package/dist/realtime.js +2 -2
  31. package/dist/reply-id-P_bSuEng.js +12 -0
  32. package/dist/{rpc-RKPAusHp.js → rpc-BQqYx8kb.js} +23 -7
  33. package/dist/{rpc-HBcWtg0T.d.ts → rpc-BZ1QNkCC.d.ts} +1 -1
  34. package/dist/rpc.d.ts +1 -1
  35. package/dist/rpc.js +1 -1
  36. package/dist/runtime/auth.d.ts +2 -2
  37. package/dist/runtime/auth.js +2 -2
  38. package/dist/runtime/console.js +3 -3
  39. package/dist/runtime/index.d.ts +38 -11
  40. package/dist/runtime/index.js +83 -15
  41. package/dist/{server-D8k-0GXe.js → server-CqyzrqTI.js} +1 -1
  42. package/dist/server.d.ts +5 -5
  43. package/dist/server.js +6 -6
  44. package/dist/{service-GHhhyQj4.js → service-C8ZgFWvy.js} +34 -5
  45. package/dist/{service-CFVm23k7.d.ts → service-wC9kx9EX.d.ts} +11 -4
  46. package/dist/{session-EkudzUmm.js → session-ByjMyTak.js} +1 -1
  47. package/dist/{session-DVx-1Tym.d.ts → session-CKfW6DGE.d.ts} +3 -3
  48. package/dist/table-names-DfiKUlOV.js +14 -0
  49. package/dist/testing.d.ts +1 -1
  50. package/dist/testing.js +37 -4
  51. package/dist/{types-BIS0hCEl.d.ts → types-C1qzObs2.d.ts} +12 -3
  52. package/dist/{types-CZujrMFd.d.ts → types-C7LzhgRb.d.ts} +47 -3
  53. package/dist/vite.d.ts +6 -6
  54. package/dist/vite.js +187 -113
  55. package/package.json +9 -9
  56. package/dist/overlay/client-DmsSMOzi.js +0 -4
package/dist/database.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as migrateComments, c as commentForge, d as commentsSchema, i as liveThreadsBackup, l as commentMessages, o as commentsTables, r as commentsSchemaState, s as commentCounters, t as commentsMigrationSql, u as commentThreads } from "./migrate-BDQ8xqUs.js";
1
+ import { a as migrateComments, c as commentForge, d as commentsSchema, i as liveThreadsBackup, l as commentMessages, o as commentsTables, r as commentsSchemaState, s as commentCounters, t as commentsMigrationSql, u as commentThreads } from "./migrate-Bpw3xL5e.js";
2
2
  export { commentCounters, commentForge, commentMessages, commentThreads, commentsMigrationSql, commentsSchema, commentsSchemaState, commentsTables, liveThreadsBackup, migrateComments };
@@ -1,4 +1,4 @@
1
- import { S as CommentThread, _ as CommentMetadata, g as CommentMessage, n as CommentActor, w as CommentUser, x as CommentSubject } from "./types-CZujrMFd.js";
1
+ import { D as CommentUser, T as CommentThread, b as CommentMetadata, n as CommentActor, w as CommentSubject, y as CommentMessage } from "./types-C7LzhgRb.js";
2
2
  //#region src/operations-core/define.d.ts
3
3
  /**
4
4
  * - `read`: see threads, join the presence room of a page, and get `@` suggestions.
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
2
  //#region src/operations-core/define.ts
3
3
  const marker = Symbol.for("vitehub.comments.definition");
4
4
  /** Marks a definition, so the build can check what `server/comments.ts` exports. */
@@ -94,8 +94,8 @@ declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
94
94
  readonly fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob.";
95
95
  };
96
96
  readonly COMMENTS_R0022: {
97
- readonly why: "Another comment thread of this scope already uses this requestId: it has another author or another subject, or you may not read it.";
98
- readonly fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment. Send the same requestId again only to retry the same comment.";
97
+ readonly why: "Another comment thread of this scope, or another reply in this thread, already uses this requestId: it has another author or another subject, or you may not read it.";
98
+ readonly fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment or reply. Send the same requestId again only to retry the same one.";
99
99
  };
100
100
  readonly COMMENTS_B0001: {
101
101
  readonly why: ({ file }: {
@@ -119,6 +119,10 @@ declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
119
119
  }) => string;
120
120
  readonly fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database.";
121
121
  };
122
+ readonly COMMENTS_DATABASE_TOKEN_IN_BUILD: {
123
+ readonly why: "The `database` option of `comments()` has an `authToken` in its URL, so the token ends up in the build output.";
124
+ readonly fix: "Put the URL with its token in a variable, and pass the variable: `comments({ database: \"env:COMMENTS_DATABASE_URL\" })`.";
125
+ };
122
126
  readonly COMMENTS_GITHUB_CREDENTIALS_MISSING: {
123
127
  readonly why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.";
124
128
  readonly fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`.";
@@ -166,6 +170,14 @@ declare const commentsErrorDiagnostics: import("nostics").Diagnostics<{
166
170
  }) => string;
167
171
  readonly fix: "Set `VITEHUB_SECRET` to the output of `openssl rand -base64 32`, which has 44 characters.";
168
172
  };
173
+ readonly COMMENTS_OUTBOX_ACCOUNT_CHANGED: {
174
+ why: string;
175
+ fix: string;
176
+ };
177
+ readonly COMMENTS_OUTBOX_SENDING: {
178
+ why: string;
179
+ fix: string;
180
+ };
169
181
  readonly COMMENTS_R0001: {
170
182
  why: ({ target }: {
171
183
  target: string;
@@ -1,4 +1,4 @@
1
- import { n as commentsClientCodes } from "./client-diagnostics-CcFpkbAk.js";
1
+ import { n as commentsClientCodes } from "./client-diagnostics-Bubm7Shd.js";
2
2
  import { defineDiagnostics } from "nostics";
3
3
  //#region src/operations-core/errors.ts
4
4
  const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
@@ -78,8 +78,8 @@ const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
78
78
  fix: "Pass readAttachment to defineComments(), next to storeAttachment, and return the file of the key as a Blob."
79
79
  },
80
80
  COMMENTS_R0022: {
81
- why: "Another comment thread of this scope already uses this requestId: it has another author or another subject, or you may not read it.",
82
- fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment. Send the same requestId again only to retry the same comment."
81
+ why: "Another comment thread of this scope, or another reply in this thread, already uses this requestId: it has another author or another subject, or you may not read it.",
82
+ fix: "Send a new requestId, such as crypto.randomUUID(), for each new comment or reply. Send the same requestId again only to retry the same one."
83
83
  },
84
84
  COMMENTS_B0001: {
85
85
  why: ({ file }) => `${file} needs a Database, but the Database is off for this app.`,
@@ -97,6 +97,10 @@ const commentsErrorDiagnostics = /*#__PURE__*/ defineDiagnostics({
97
97
  why: ({ file }) => `The \`database\` option of defineComments() in ${file} is not a string literal. The build reads it without running the file, so Comments would use the default Database.`,
98
98
  fix: "Write the Database name as a string literal, such as `defineComments({ database: \"content\" })`, and put no spread after it. Remove the option to use the default or only Database."
99
99
  },
100
+ COMMENTS_DATABASE_TOKEN_IN_BUILD: {
101
+ why: "The `database` option of `comments()` has an `authToken` in its URL, so the token ends up in the build output.",
102
+ fix: "Put the URL with its token in a variable, and pass the variable: `comments({ database: \"env:COMMENTS_DATABASE_URL\" })`."
103
+ },
100
104
  COMMENTS_GITHUB_CREDENTIALS_MISSING: {
101
105
  why: "Comments needs GitHub credentials to post to pull requests: VITEHUB_GITHUB_APP_ID with VITEHUB_GITHUB_PRIVATE_KEY, or VITEHUB_GITHUB_TOKEN.",
102
106
  fix: "Set `VITEHUB_GITHUB_APP_ID` and `VITEHUB_GITHUB_PRIVATE_KEY` of a GitHub App that is installed on the repository, or set `VITEHUB_GITHUB_TOKEN`."
@@ -1,7 +1,7 @@
1
- import { S as CommentThread, g as CommentMessage, s as CommentContext, w as CommentUser, x as CommentSubject } from "./types-CZujrMFd.js";
2
- import { f as CommentsPolicyGate, g as CommentsUser, t as CommentAction } from "./define-B3TF9zzn.js";
3
- import { c as CreateCommentThreadInput, d as ListCommentThreadsOptions, f as ReplyInput, l as DefineCommentsOptions, p as ReplyOptions, t as CommentsErrorCode, u as EditCommentInput } from "./types-BIS0hCEl.js";
4
- import { i as CommentsRuntime } from "./service-CFVm23k7.js";
1
+ import { D as CommentUser, T as CommentThread, n as CommentActor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-C7LzhgRb.js";
2
+ import { f as CommentsPolicyGate, g as CommentsUser, t as CommentAction } from "./define-CHTWfHPo.js";
3
+ import { c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, l as DefineCommentsOptions, m as ReplyOptions, p as ReplyInput, t as CommentsErrorCode, u as EditCommentInput } from "./types-C1qzObs2.js";
4
+ import { i as CommentsRuntime } from "./service-wC9kx9EX.js";
5
5
  import { Result } from "@vite-hub/runtime";
6
6
  //#region src/context.d.ts
7
7
  /**
@@ -31,12 +31,21 @@ interface Comments {
31
31
  getByMessage(messageId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
32
32
  /** Thread `#n` of a numbering scope, such as `site`. */
33
33
  getByNumber(scope: string, n: number): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
34
+ /**
35
+ * The thread that a `create` with this `requestId` stored in the scope of the subject, else `null`. Check it before
36
+ * work that a retry must not do twice, such as storing files. It does not compare authors: `create` does.
37
+ */
38
+ findThread(input: FindCommentThreadInput): Promise<Result<CommentThread | null, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
39
+ /** The message that a `reply` with this `requestId` stored in the thread, else `null`. */
40
+ findReply(threadId: string, requestId: string): Promise<Result<CommentMessage | null, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT">>>;
34
41
  /** Starts a thread with its first message, numbered next in the scope of its subject. Runs `onComment`. */
35
42
  create(input: CreateCommentThreadInput): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_INVALID_INPUT">>>;
36
43
  /** Adds a message to an open thread. Runs `onComment`. */
37
44
  reply(threadId: string, input: ReplyInput, options?: ReplyOptions): Promise<Result<CommentMessage, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_INVALID_INPUT" | "COMMENTS_RESOLVED">>>;
45
+ /** `actor`: the agent that resolves it for `by`, as on `reply`. */
38
46
  resolve(threadId: string, options: {
39
47
  by: CommentUser;
48
+ actor?: CommentActor;
40
49
  }): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
41
50
  reopen(threadId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
42
51
  /** Deletes a thread and all its messages. */
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { A as TextAnchor, C as CommentUploadInput, D as ElementAnchor, E as CommentsTransport, O as ImageAnchor, S as CommentThread, T as CommentUsersInput, _ as CommentMetadata, a as CommentBuild, b as CommentStatusInput, c as CommentCreateInput, d as CommentEvent, f as CommentForgeLink, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, k as PageAnchor, l as CommentDeleteInput, m as CommentListCursor, n as CommentActor, o as CommentComponent, p as CommentGetInput, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentEditInput, v as CommentReplyInput, w as CommentUser, x as CommentSubject, y as CommentStatus } from "./types-CZujrMFd.js";
2
- import { _ as builtinCommentSubjects, a as CommentsAttachmentFile, b as defineCommentSubject, c as CommentsCanMentionContext, d as CommentsPeople, f as CommentsPolicyGate, g as CommentsUser, h as CommentsStoreAttachmentContext, i as CommentSubjectDefinition, l as CommentsDefinition, m as CommentsReadAttachmentContext, n as CommentMentionEvent, o as CommentsAuthorize, p as CommentsRateLimit, r as CommentMessageEvent, s as CommentsAuthorizeContext, t as CommentAction, u as CommentsGitHubAccess, v as commentsRoleAllows, y as defaultPolicy } from "./define-B3TF9zzn.js";
3
- import { a as CommentsPageContext, c as CreateCommentThreadInput, d as ListCommentThreadsOptions, f as ReplyInput, i as CommentsIdentifyContext, l as DefineCommentsOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyOptions, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput } from "./types-BIS0hCEl.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-CyQyKAvy.js";
5
- import { a as describeCommentContext, i as resolveCommentsRuntime, n as defineComments, r as commentsRuntimeOf, t as Comments } from "./index-DNhy69Wt.js";
6
- import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-DtbMOEMd.js";
7
- export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentEditInput, type CommentEvent, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, builtinCommentSubjects, commentRoom, commentsErrorDiagnostics, commentsPageScope, commentsRealtimeDefinition, commentsRoleAllows, commentsRoute, commentsRuntimeOf, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage, resolveCommentsRuntime };
1
+ import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-C7LzhgRb.js";
2
+ import { _ as builtinCommentSubjects, a as CommentsAttachmentFile, b as defineCommentSubject, c as CommentsCanMentionContext, d as CommentsPeople, f as CommentsPolicyGate, g as CommentsUser, h as CommentsStoreAttachmentContext, i as CommentSubjectDefinition, l as CommentsDefinition, m as CommentsReadAttachmentContext, n as CommentMentionEvent, o as CommentsAuthorize, p as CommentsRateLimit, r as CommentMessageEvent, s as CommentsAuthorizeContext, t as CommentAction, u as CommentsGitHubAccess, v as commentsRoleAllows, y as defaultPolicy } from "./define-CHTWfHPo.js";
3
+ import { a as CommentsPageContext, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, i as CommentsIdentifyContext, l as DefineCommentsOptions, m as ReplyOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyInput, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput } from "./types-C1qzObs2.js";
4
+ import { t as commentsErrorDiagnostics } from "./errors-BEChnUo7.js";
5
+ import { a as describeCommentContext, i as resolveCommentsRuntime, n as defineComments, r as commentsRuntimeOf, t as Comments } from "./index-iPGlSAgj.js";
6
+ import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-CWwnmF3K.js";
7
+ export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type FindCommentThreadInput, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, builtinCommentSubjects, commentRoom, commentsErrorDiagnostics, commentsPageScope, commentsRealtimeDefinition, commentsRoleAllows, commentsRoute, commentsRuntimeOf, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage, resolveCommentsRuntime };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
2
- import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-B41ozN63.js";
3
- import { _ as scopeOf, i as createThread, m as replyToThread, n as can, s as editMessage, x as clientRateLimitIssue, y as suggest } from "./service-GHhhyQj4.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
+ import { i as commentsRoute, n as commentsPageScope, o as normalizeCommentPage, r as commentsRealtimeDefinition, t as commentRoom } from "./page-DRz_sDY4.js";
3
+ import { S as suggest, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply, w as clientRateLimitIssue } from "./service-C8ZgFWvy.js";
4
4
  import { t as describeCommentContext } from "./context-BqIsmYP1.js";
5
- import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition, t as builtinCommentSubjects } from "./define-43mMR39K.js";
6
- import { a as runtimeOf, n as pendingKey, o as runtimes, r as resolveCommentsRuntime, t as commentsRuntimeOf } from "./installed-B-PfERBU.js";
5
+ import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition, t as builtinCommentSubjects } from "./define-CX_Yr_hz.js";
6
+ import { a as runtimeOf, n as pendingKey, o as runtimes, r as resolveCommentsRuntime, t as commentsRuntimeOf } from "./installed-g6nDr5ac.js";
7
7
  import { t as commentsErrors } from "./errors-4gelGVmK.js";
8
8
  //#region src/index.ts
9
9
  /** A thread that someone deleted during the change: the store reads it again and finds nothing. */
@@ -16,6 +16,11 @@ function resultError(error, id) {
16
16
  const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
17
17
  if (code === "COMMENTS_R0002" || code === "COMMENTS_R0003") return commentsErrors.COMMENTS_NOT_FOUND({ id });
18
18
  if (code === "COMMENTS_R0016") return commentsErrors.COMMENTS_RESOLVED();
19
+ return invalidInput(error);
20
+ }
21
+ /** A diagnostic of the shared core about the input, as `COMMENTS_INVALID_INPUT`. Any other error is thrown again. */
22
+ function invalidInput(error) {
23
+ const code = error instanceof Error ? Reflect.get(error, "code") : void 0;
19
24
  if (typeof code === "string" && [
20
25
  "COMMENTS_R0005",
21
26
  "COMMENTS_R0007",
@@ -77,6 +82,35 @@ function defineComments(options = {}) {
77
82
  if (!current) return notInstalled();
78
83
  return one(current, await current.store.getByNumber(scope, n), `${scope}#${n}`);
79
84
  },
85
+ async findThread({ page, subject, requestId }) {
86
+ const current = await runtime();
87
+ if (!current) return notInstalled();
88
+ const target = subject ?? (page === void 0 ? void 0 : {
89
+ id: normalizeCommentPage(page),
90
+ kind: "page"
91
+ });
92
+ if (!target) return [commentsErrors.COMMENTS_INVALID_INPUT({ issue: "subject: Give a subject, or a page." }), void 0];
93
+ try {
94
+ const found = await earlierThread(current, {
95
+ requestId,
96
+ subject: target
97
+ });
98
+ return [void 0, found ? (await withForge(current, [found]))[0] : null];
99
+ } catch (error) {
100
+ return [invalidInput(error), void 0];
101
+ }
102
+ },
103
+ async findReply(threadId, requestId) {
104
+ const current = await runtime();
105
+ if (!current) return notInstalled();
106
+ const found = await current.store.getById(threadId);
107
+ if (!found) return notFound(threadId);
108
+ try {
109
+ return [void 0, await earlierReply(found, requestId) ?? null];
110
+ } catch (error) {
111
+ return [invalidInput(error), void 0];
112
+ }
113
+ },
80
114
  async create({ page, subject, ...input }) {
81
115
  const current = await runtime();
82
116
  if (!current) return notInstalled();
@@ -107,11 +141,11 @@ function defineComments(options = {}) {
107
141
  return [resultError(error, threadId), void 0];
108
142
  }
109
143
  },
110
- async resolve(threadId, { by }) {
144
+ async resolve(threadId, { by, actor }) {
111
145
  const current = await runtime();
112
146
  if (!current) return notInstalled();
113
147
  if (!await current.store.getById(threadId)) return notFound(threadId);
114
- const thread = await current.store.setStatus(threadId, "resolved", by, Date.now()).catch(gone);
148
+ const thread = await current.store.setStatus(threadId, "resolved", by, Date.now(), actor).catch(gone);
115
149
  if (!thread) return notFound(threadId);
116
150
  current.forge?.changed(threadId);
117
151
  return [void 0, thread];
@@ -1,8 +1,8 @@
1
- import { d as CommentsPeople } from "./define-B3TF9zzn.js";
1
+ import { d as CommentsPeople } from "./define-CHTWfHPo.js";
2
2
  import { a as commentsSchema } from "./database-CA1aHKN7.js";
3
3
  import { r as CommentsSchemaOwner } from "./migrate-B0k_0swk.js";
4
- import { t as Comments } from "./index-DNhy69Wt.js";
5
- import { c as CommentsTables, i as CommentsRuntime, n as CommentsAttachmentStore, o as CommentsDatabase, u as SharedRateLimit } from "./service-CFVm23k7.js";
4
+ import { t as Comments } from "./index-iPGlSAgj.js";
5
+ import { c as CommentsTables, i as CommentsRuntime, n as CommentsAttachmentStore, o as CommentsDatabase, u as SharedRateLimit } from "./service-wC9kx9EX.js";
6
6
  //#region src/install.d.ts
7
7
  interface InstallCommentsOptions {
8
8
  database: CommentsDatabase;
@@ -1,10 +1,10 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
2
  import { r as guestIdPrefix } from "./identity-CBOzgxSf.js";
3
3
  import { t as describeCommentContext } from "./context-BqIsmYP1.js";
4
- import { c as commentForge, d as commentsSchema, l as commentMessages, n as commentsSchemaGate, s as commentCounters, u as commentThreads } from "./migrate-BDQ8xqUs.js";
5
- import { i as installCommentsRuntime } from "./server-D8k-0GXe.js";
4
+ import { c as commentForge, d as commentsSchema, l as commentMessages, n as commentsSchemaGate, s as commentCounters, u as commentThreads } from "./migrate-Bpw3xL5e.js";
5
+ import { i as installCommentsRuntime } from "./server-CqyzrqTI.js";
6
6
  import { i as getActiveCloudflareBinding, n as recentGitHubToken } from "./tokens-DSbwkVSy.js";
7
- import { n as pendingKey, o as runtimes } from "./installed-B-PfERBU.js";
7
+ import { n as pendingKey, o as runtimes } from "./installed-g6nDr5ac.js";
8
8
  import { getStandardContext } from "@vite-hub/runtime/internal/h3";
9
9
  import * as v from "valibot";
10
10
  import { and, asc, desc, eq, gt, inArray, isNotNull, isNull, like, lt, lte, or, sql } from "drizzle-orm";
@@ -60,9 +60,18 @@ function messageOf(row) {
60
60
  ...row.editedAt === null ? {} : { editedAt: row.editedAt }
61
61
  };
62
62
  }
63
+ /** `resolved_by` keeps the person, with the agent that acted for them as `actor`. Rows from before it hold the person alone. */
64
+ function resolver(json) {
65
+ const found = parseJson(json, void 0);
66
+ if (!found) return {};
67
+ const { actor, ...by } = found;
68
+ return {
69
+ resolvedBy: by,
70
+ ...actor ? { resolvedActor: actor } : {}
71
+ };
72
+ }
63
73
  function threadOf(row, messages) {
64
74
  const actor = parseJson(row.actor, void 0);
65
- const resolvedBy = parseJson(row.resolvedBy, void 0);
66
75
  const metadata = parseJson(row.metadata, void 0);
67
76
  const context = parseJson(row.context, void 0);
68
77
  return {
@@ -80,11 +89,12 @@ function threadOf(row, messages) {
80
89
  },
81
90
  updatedAt: row.updatedAt,
82
91
  ...actor ? { actor } : {},
83
- ...resolvedBy ? { resolvedBy } : {},
92
+ ...resolver(row.resolvedBy),
84
93
  ...row.resolvedAt === null ? {} : { resolvedAt: row.resolvedAt },
85
94
  ...metadata ? { metadata } : {},
86
95
  ...context ? { context } : {},
87
- ...row.revision === null ? {} : { revision: row.revision }
96
+ ...row.revision === null ? {} : { revision: row.revision },
97
+ ...row.requestId === null ? {} : { requestId: row.requestId }
88
98
  };
89
99
  }
90
100
  const uniqueCodes = /* @__PURE__ */ new Set([
@@ -160,20 +170,17 @@ function createCommentsStore(database, tables = {
160
170
  * failure leaves nothing visible.
161
171
  */
162
172
  async function together(build) {
163
- if (typeof driver.batch === "function") {
164
- await driver.batch(build(db));
165
- return;
173
+ if (typeof driver.batch === "function") return driver.batch(build(db));
174
+ async function run(target) {
175
+ const results = [];
176
+ for (const statement of build(target)) results.push(await statement);
177
+ return results;
166
178
  }
167
- if (typeof driver.transaction === "function") {
168
- await driver.transaction(async (target) => {
169
- for (const statement of build(target)) await statement;
170
- });
171
- return;
172
- }
173
- for (const statement of build(db)) await statement;
179
+ return typeof driver.transaction === "function" ? driver.transaction(run) : run(db);
174
180
  }
181
+ const newer = (now) => sql`case when ${threads.updatedAt} >= ${now} then ${threads.updatedAt} + 1 else ${now} end`;
175
182
  function touching(target, id, now, values = {}, only) {
176
- const updatedAt = sql`case when ${threads.updatedAt} >= ${now} then ${threads.updatedAt} + 1 else ${now} end`;
183
+ const updatedAt = newer(now);
177
184
  return target.update(threads).set({
178
185
  ...values,
179
186
  updatedAt,
@@ -304,29 +311,34 @@ function createCommentsStore(database, tables = {
304
311
  throw commentsErrorDiagnostics.COMMENTS_R0011();
305
312
  },
306
313
  async addMessage(threadId, input, { allowResolved = false } = {}) {
307
- if ((await one(threadId)).status === "resolved" && !allowResolved) throw commentsErrorDiagnostics.COMMENTS_R0016();
308
- await together((target) => [touching(target, threadId, input.now, {}, allowResolved ? void 0 : eq(threads.status, "open")), target.insert(messages).select(sql`select
314
+ const before = await one(threadId);
315
+ if (before.messages.some((message) => message.id === input.id)) throw commentsErrorDiagnostics.COMMENTS_R0022();
316
+ if (before.status === "resolved" && !allowResolved) throw commentsErrorDiagnostics.COMMENTS_R0016();
317
+ const [, inserted] = await together((target) => [touching(target, threadId, input.now, {}, allowResolved ? void 0 : eq(threads.status, "open")), target.insert(messages).select(sql`select
309
318
  ${input.id}, ${threadId}, ${input.body}, ${input.author.id}, ${input.author.name ?? null}, ${input.author.image ?? null},
310
319
  ${input.actor ? JSON.stringify(input.actor) : null}, ${JSON.stringify(input.mentions)}, ${JSON.stringify(input.attachments)},
311
320
  ${threads.updatedAt}, null
312
- from ${threads} where ${threads.id} = ${threadId}${allowResolved ? sql`` : sql` and ${threads.status} = 'open'`}`)]);
321
+ from ${threads} where ${threads.id} = ${threadId}${allowResolved ? sql`` : sql` and ${threads.status} = 'open'`}`).returning({ id: messages.id })]).catch((error) => {
322
+ throw isUniqueViolation(error) ? commentsErrorDiagnostics.COMMENTS_R0022() : error;
323
+ });
313
324
  const after = await one(threadId);
314
325
  if (!after.messages.some((message) => message.id === input.id)) throw commentsErrorDiagnostics.COMMENTS_R0016();
326
+ if (!inserted.length) throw commentsErrorDiagnostics.COMMENTS_R0022();
315
327
  return after;
316
328
  },
317
329
  async editMessage(threadId, messageId, input) {
318
330
  if (!(await one(threadId)).messages.some((message) => message.id === messageId)) throw commentsErrorDiagnostics.COMMENTS_R0003({ messageId });
319
- await together((target) => [target.update(messages).set({
331
+ await together((target) => [touching(target, threadId, input.now, {}, sql`exists (select 1 from ${messages} where ${messages.id} = ${messageId} and ${messages.threadId} = ${threadId})`), target.update(messages).set({
320
332
  body: input.body,
321
333
  editedAt: input.now,
322
334
  mentions: JSON.stringify(input.mentions)
323
- }).where(and(eq(messages.id, messageId), eq(messages.threadId, threadId))), touching(target, threadId, input.now, {}, sql`exists (select 1 from ${messages} where ${messages.id} = ${messageId} and ${messages.threadId} = ${threadId})`)]);
335
+ }).where(and(eq(messages.id, messageId), eq(messages.threadId, threadId)))]);
324
336
  const after = await one(threadId);
325
337
  if (!after.messages.some((message) => message.id === messageId)) throw commentsErrorDiagnostics.COMMENTS_R0003({ messageId });
326
338
  return after;
327
339
  },
328
340
  async deleteMessage(threadId, messageId, now) {
329
- await together((target) => [target.delete(messages).where(and(eq(messages.id, messageId), eq(messages.threadId, threadId))), touching(target, threadId, now)]);
341
+ await together((target) => [touching(target, threadId, now), target.delete(messages).where(and(eq(messages.id, messageId), eq(messages.threadId, threadId)))]);
330
342
  return one(threadId);
331
343
  },
332
344
  async deleteThread(threadId, ownerId) {
@@ -337,10 +349,13 @@ function createCommentsStore(database, tables = {
337
349
  ]);
338
350
  return await find(threadId) === null;
339
351
  },
340
- async setStatus(threadId, status, by, now) {
352
+ async setStatus(threadId, status, by, now, actor) {
341
353
  await one(threadId);
342
354
  await touching(db, threadId, now, status === "resolved" ? {
343
- resolvedBy: JSON.stringify(by),
355
+ resolvedBy: JSON.stringify(actor ? {
356
+ ...by,
357
+ actor
358
+ } : by),
344
359
  status
345
360
  } : {
346
361
  resolvedAt: null,
@@ -363,6 +378,37 @@ function createCommentsStore(database, tables = {
363
378
  }
364
379
  return removed.map((row) => row.id);
365
380
  },
381
+ async deleteUser(userId) {
382
+ const written = await db.selectDistinct({ id: messages.threadId }).from(messages).where(eq(messages.authorId, userId));
383
+ const started = await db.select({ id: threads.id }).from(threads).where(and(eq(threads.authorId, userId), or(isNotNull(threads.authorName), isNotNull(threads.authorImage))));
384
+ const resolved = (await db.select({
385
+ id: threads.id,
386
+ resolvedBy: threads.resolvedBy
387
+ }).from(threads).where(sql`${threads.resolvedBy} like ${`%${escapeLike(JSON.stringify(userId))}%`} escape '\\'`)).flatMap(({ id, resolvedBy }) => resolvedBy !== null && parseJson(resolvedBy, void 0)?.id === userId ? [{
388
+ id,
389
+ resolvedBy
390
+ }] : []);
391
+ const touched = [...new Set([
392
+ ...written,
393
+ ...started,
394
+ ...resolved
395
+ ].map((row) => row.id))].sort();
396
+ if (!touched.length) return [];
397
+ const now = Date.now();
398
+ const parts = chunks(touched);
399
+ await together((target) => [
400
+ ...parts.map((part) => target.update(threads).set({ id: sql`${threads.id}` }).where(inArray(threads.id, part))),
401
+ ...parts.map((part) => target.delete(messages).where(and(eq(messages.authorId, userId), inArray(messages.threadId, part)))),
402
+ ...parts.map((part) => target.delete(threads).where(and(inArray(threads.id, part), sql`not exists (select 1 from ${messages} where ${messages.threadId} = ${threads.id})`))),
403
+ ...parts.map((part) => target.update(threads).set({
404
+ authorName: null,
405
+ authorImage: null
406
+ }).where(and(eq(threads.authorId, userId), inArray(threads.id, part)))),
407
+ ...resolved.map((row) => target.update(threads).set({ resolvedBy: null }).where(and(eq(threads.id, row.id), eq(threads.resolvedBy, row.resolvedBy)))),
408
+ ...parts.map((part) => target.update(threads).set({ updatedAt: newer(now) }).where(inArray(threads.id, part)))
409
+ ]);
410
+ return touched;
411
+ },
366
412
  async knownUsersByIds(ids, canRead) {
367
413
  const seen = /* @__PURE__ */ new Map();
368
414
  const readable = /* @__PURE__ */ new Map();
@@ -1,4 +1,4 @@
1
- import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-D8k-0GXe.js";
1
+ import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-CqyzrqTI.js";
2
2
  //#region src/installed.ts
3
3
  /** The runtime that `installComments()` connected to each definition. */
4
4
  const runtimes = /* @__PURE__ */ new WeakMap();
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.js";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
4
4
  //#region src/operations-core/database.ts
@@ -39,6 +39,11 @@ interface OperationContext {
39
39
  surface: "console" | "cli" | "mcp" | "agent";
40
40
  /** Set by the host from generated build identity, never from request input or runtime NODE_ENV. */
41
41
  development?: boolean;
42
+ /**
43
+ * The project root of a development server, for operations that read build files, such as `bundle.report`. Hosts set
44
+ * it only with `development`, so a deployed server never reads project files through it.
45
+ */
46
+ projectRoot?: string;
42
47
  env?: Record<string, unknown>;
43
48
  waitUntil?: (task: Promise<unknown>) => void;
44
49
  request?: Request;
@@ -1,10 +1,11 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-C6qptPoG.js";
1
+ import { n as outboxAccountHeader } from "./client-files-CJZl5Kc4.js";
2
+ import { t as commentsErrorDiagnostics } from "./errors-BHsVXlpd.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, a as deniedError, b as clientAddressKey, c as fail, f as personOf, g as retried, h as requestIdSchema, i as createThread, l as maximumAttachmentBytes, m as replyToThread, n as can, o as earlierThread, p as readAttachment, s as editMessage, t as attachmentThread, u as maximumCommentBodyLength, v as storeAttachment, y as suggest } from "./service-GHhhyQj4.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
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-D8k-0GXe.js";
8
+ import { t as commentsRuntime } from "./server-CqyzrqTI.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";
@@ -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 `fetch()` Source options, or ask the server for a smaller response."
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."
@@ -450,7 +455,7 @@ function describeCommentThread(thread) {
450
455
  "",
451
456
  ...thread.messages.flatMap((message) => [`${commentPersonName(message.author)}, ${new Date(message.createdAt).toISOString()}: ${message.body}`, ...message.attachments.length ? [`Attachments: ${message.attachments.join(", ")}`] : []])
452
457
  ];
453
- if (thread.resolvedBy) lines.push("", `Resolved by ${commentPersonName(thread.resolvedBy)} at ${new Date(thread.resolvedAt ?? thread.updatedAt).toISOString()}`);
458
+ 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
459
  return lines.join("\n");
455
460
  }
456
461
  /** At most `max` characters of `value`, flattened to one line and cut at a word, with `…` when cut. */
@@ -641,6 +646,10 @@ function author(who) {
641
646
  if (!guest) throw fail(commentsErrorDiagnostics.COMMENTS_R0012(), 401);
642
647
  return guest;
643
648
  }
649
+ function checkOutboxAccount(who) {
650
+ const expected = who.request?.headers.get(outboxAccountHeader);
651
+ if (expected != null && expected !== encodeURIComponent(author(who).id)) throw fail(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), 401);
652
+ }
644
653
  const guestLimits = /* @__PURE__ */ new WeakMap();
645
654
  /**
646
655
  * Counts one write of a guest against `defineComments({ rateLimit })`, by the address of the request. Signed-in people
@@ -732,6 +741,7 @@ const replyInput = v.strictObject({
732
741
  attachments,
733
742
  body: text,
734
743
  mentions,
744
+ requestId: v.optional(requestIdSchema),
735
745
  threadId: id
736
746
  });
737
747
  const editInput = v.strictObject({
@@ -816,6 +826,7 @@ const commentActions = {
816
826
  },
817
827
  /** `context` is the page context that the overlay read and its transport checked. */
818
828
  async create(input, who) {
829
+ checkOutboxAccount(who);
819
830
  const canRead = (thread) => permitted(who, "read", { thread });
820
831
  const earlier = await earlierThread(who.runtime, input);
821
832
  if (earlier) return retried(earlier, {
@@ -836,7 +847,10 @@ const commentActions = {
836
847
  },
837
848
  /** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
838
849
  async reply(input, who, options = {}) {
850
+ checkOutboxAccount(who);
839
851
  const found = await load(who, input.threadId);
852
+ const earlier = await earlierReply(found, input.requestId);
853
+ if (earlier) return retriedReply(found, earlier, author(who));
840
854
  await allow(who, "write", { thread: found });
841
855
  await limitGuest(who);
842
856
  return replyToThread(who.runtime, found, {
@@ -844,6 +858,7 @@ const commentActions = {
844
858
  author: author(who),
845
859
  ...input.mentions ? { mentions: input.mentions } : {},
846
860
  ...input.attachments ? { attachments: input.attachments } : {},
861
+ ...input.requestId === void 0 ? {} : { requestId: input.requestId },
847
862
  ...who.actor ? { actor: who.actor } : {}
848
863
  }, {
849
864
  allowResolved: options.allowResolved === true,
@@ -907,6 +922,7 @@ const commentActions = {
907
922
  });
908
923
  },
909
924
  async upload(input, who) {
925
+ checkOutboxAccount(who);
910
926
  const target = input.subject ? { subject: input.subject } : {};
911
927
  await allow(who, "read", target);
912
928
  await allow(who, "write", target);
@@ -923,11 +939,6 @@ const commentActions = {
923
939
  });
924
940
  }
925
941
  };
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
942
  const list = defineOperation({
932
943
  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
944
  input: listInput,
@@ -1008,7 +1019,7 @@ const create = defineOperation({
1008
1019
  section: "comments"
1009
1020
  });
1010
1021
  const reply = defineOperation({
1011
- description: "Add a message to a comment thread, for example to say what you changed. A resolved thread stays resolved.",
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.",
1012
1023
  input: replyInput,
1013
1024
  kind: "write",
1014
1025
  name: "comments.reply",
@@ -1,7 +1,7 @@
1
- import { C as CommentUploadInput, S as CommentThread, T as CommentUsersInput, b as CommentStatusInput, c as CommentCreateInput, g as CommentMessage, h as CommentListQuery, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, p as CommentGetInput, s as CommentContext, u as CommentEditInput, v as CommentReplyInput, w as CommentUser } from "./types-CZujrMFd.js";
2
- import { f as CommentsPolicyGate, g as CommentsUser } from "./define-B3TF9zzn.js";
3
- import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-CFVm23k7.js";
4
- import { t as AnyOperation } from "./operations-D4A1Fcgf.js";
1
+ import { C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, O as CommentUsersInput, T as CommentThread, c as CommentCreateInput, f as CommentEditInput, g as CommentGetInput, i as CommentAttachment, l as CommentDeleteInput, n as CommentActor, s as CommentContext, v as CommentListQuery, x as CommentReplyInput, y as CommentMessage } from "./types-C7LzhgRb.js";
2
+ import { f as CommentsPolicyGate, g as CommentsUser } from "./define-CHTWfHPo.js";
3
+ import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-wC9kx9EX.js";
4
+ import { t as AnyOperation } from "./operations-7ycAhDCw.js";
5
5
  import * as v from "valibot";
6
6
  //#region src/operations-core/operations.d.ts
7
7
  declare const anchor: v.UnionSchema<[v.StrictObjectSchema<{
@@ -195,6 +195,7 @@ declare const commentInputSchemas: {
195
195
  readonly attachments: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 500, undefined>]>, undefined>, v.MaxLengthAction<string[], 10, undefined>]>, undefined>;
196
196
  readonly body: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 10000, undefined>]>;
197
197
  readonly mentions: v.OptionalSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>, v.MaxLengthAction<string[], 20, undefined>]>, undefined>;
198
+ readonly requestId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 200, undefined>]>, undefined>;
198
199
  readonly threadId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>;
199
200
  }, undefined>;
200
201
  readonly status: v.StrictObjectSchema<{
@@ -1,3 +1,3 @@
1
- import { a as maximumCommentBodyLength } from "./service-CFVm23k7.js";
2
- import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-GLeOqgMt.js";
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";
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-DMMIfYPW.js";
2
- import { u as maximumCommentBodyLength } from "./service-GHhhyQj4.js";
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";
3
3
  export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };