@vite-hub/comments 0.7.0 → 0.9.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 (70) hide show
  1. package/README.md +4 -10
  2. package/dist/anchor.d.ts +2 -2
  3. package/dist/anchor.js +0 -1
  4. package/dist/{client-files-lC6X7XyS.js → client-files-CMPJEd21.js} +0 -1
  5. package/dist/client-request-B1DCz3a9.js +29 -0
  6. package/dist/client.d.ts +21 -241
  7. package/dist/client.js +4 -425
  8. package/dist/database.d.ts +1 -2
  9. package/dist/database.js +1 -1
  10. package/dist/{define-BqPcuDhf.js → define-hs9Z38io.js} +1 -2
  11. package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
  12. package/dist/{errors-CBvIpwbo.js → errors-DeSEHzRf.js} +0 -12
  13. package/dist/hosted/hosted-comments/frame.js +4 -1
  14. package/dist/hosted/hosted-comments/tools.js +71 -77
  15. package/dist/hosted/hosted-comments.js +1 -1
  16. package/dist/{index-D1T7RJ4R.d.ts → index-CbXek64X.d.ts} +5 -113
  17. package/dist/index.d.ts +5 -6
  18. package/dist/index.js +6 -23
  19. package/dist/{install-CqBWFmU7.js → install--HecUN5c.js} +8 -789
  20. package/dist/{install-9L4ASzUC.d.ts → install-C3CW6Vvw.d.ts} +6 -12
  21. package/dist/{installed-wUYjqk_k.js → installed-BqQKo6WC.js} +2 -7
  22. package/dist/{database-BuSNVwTx.js → migrate-cxoJK4JQ.js} +2 -64
  23. package/dist/{operations-Qt8ASQqW.d.ts → operations-D0EO1pzL.d.ts} +36 -8
  24. package/dist/{operations-kMPw-Cyb.js → operations-DHXmbtb3.js} +47 -75
  25. package/dist/operations.d.ts +3 -3
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-BszZKIf8.js +4 -0
  28. package/dist/overlay/overlay.js +50 -43
  29. package/dist/page/loader.js +37 -30
  30. package/dist/{page-2NzFladc.js → page-CJz1K67L.js} +25 -2
  31. package/dist/page-DRM1j84-.d.ts +32 -0
  32. package/dist/{page-tools-shared-BNw-aWEH.js → page-tools-shared-BCdvqA4S.js} +40 -2
  33. package/dist/{path-8yqMd8zR.js → path-sv8kjq3i.js} +0 -4
  34. package/dist/{plugin-ChOHe7vq.js → plugin-DczA2K-y.js} +9 -9
  35. package/dist/realtime.d.ts +7 -9
  36. package/dist/realtime.js +2 -4
  37. package/dist/{rpc-kkxzQ3Qy.js → rpc-51X1TWKb.js} +1 -1
  38. package/dist/{rpc-D-eqtyfh.d.ts → rpc-DZB3yU0z.d.ts} +1 -1
  39. package/dist/rpc.d.ts +1 -1
  40. package/dist/rpc.js +1 -1
  41. package/dist/runtime/auth.d.ts +1 -2
  42. package/dist/runtime/auth.js +1 -1
  43. package/dist/runtime/client-request-plugin.d.ts +2 -0
  44. package/dist/runtime/client-request-plugin.js +21 -0
  45. package/dist/runtime/console.js +2 -2
  46. package/dist/runtime/index.d.ts +6 -9
  47. package/dist/runtime/index.js +25 -175
  48. package/dist/{server-8o9u8leM.js → server-CAMs6viR.js} +1 -1
  49. package/dist/server.d.ts +12 -8
  50. package/dist/server.js +8 -7
  51. package/dist/{service-XT2A8YEF.js → service-DFMwCr60.js} +34 -42
  52. package/dist/{store-DvNTDNgn.d.ts → service-qaMuJ7UX.d.ts} +68 -2
  53. package/dist/{session-DGdFKWDB.js → session-1SI3_wLJ.js} +212 -66
  54. package/dist/{session-CN4irEqf.d.ts → session-CK3Rnjto.d.ts} +2 -3
  55. package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
  56. package/dist/testing.d.ts +1 -1
  57. package/dist/testing.js +1 -2
  58. package/dist/{tokens-Bx4lZ0yt.js → tokens-WRh__ppm.js} +0 -1
  59. package/dist/{types-BX3vH18p.d.ts → types-BmzTyGt-.d.ts} +4 -0
  60. package/dist/{define-B1jLSPe9.d.ts → types-VSVs4jIw.d.ts} +157 -4
  61. package/dist/vite.d.ts +3 -20
  62. package/dist/vite.js +15 -82
  63. package/package.json +8 -8
  64. package/dist/database-CPua6Q6_.d.ts +0 -573
  65. package/dist/overlay/client-CrnKCZXc.js +0 -4
  66. package/dist/overlay/dist-yIZmvSaU.js +0 -1
  67. package/dist/page-DE71P_gQ.d.ts +0 -11
  68. package/dist/request-origin-B-CPVAVk.js +0 -53
  69. package/dist/service-IvgrI4XM.d.ts +0 -71
  70. package/dist/types-l6GOb_yc.d.ts +0 -206
@@ -1,11 +1,9 @@
1
- import { T as CommentThread } from "./types-BX3vH18p.js";
1
+ import { T as CommentThread } from "./types-BmzTyGt-.js";
2
2
  import { o as commentsSchema } from "./database-DUs3c2al.js";
3
- import { i as CommentsRuntime, n as CommentsAttachmentStore, o as SharedRateLimit } from "./service-IvgrI4XM.js";
4
- import { c as CommentSendWebhooks, t as Comments } from "./index-D1T7RJ4R.js";
5
- import { d as CommentsPeople } from "./define-B1jLSPe9.js";
6
- import { r as CommentsTables, t as CommentsDatabase } from "./store-DvNTDNgn.js";
3
+ import { c as CommentsTables, i as CommentsRuntime, n as CommentsAttachmentStore, o as CommentsDatabase, u as SharedRateLimit } from "./service-qaMuJ7UX.js";
4
+ import { t as Comments } from "./index-CbXek64X.js";
5
+ import { T as CommentsPeople } from "./types-VSVs4jIw.js";
7
6
  import { r as CommentsSchemaOwner } from "./migrate-XjFeQppf.js";
8
- import "./types-l6GOb_yc.js";
9
7
  /** Options of `tenantCommentsStore()`. */
10
8
  interface TenantCommentsStoreOptions {
11
9
  /** The stored scope of every thread of the tenant, such as a project id. */
@@ -35,14 +33,10 @@ interface InstallCommentsOptions {
35
33
  schema?: CommentsSchemaOwner;
36
34
  /** The SQL dialect of `database`. Default `sqlite`: SQLite, libSQL, and D1. */
37
35
  dialect?: "sqlite" | "postgresql";
38
- /**
39
- * Loads `@vite-hub/webhooks`, for `defineComments({ send })`. The generated plugin passes it when `send` is on.
40
- * Without it, the Send routes answer `COMMENTS_SEND_OFF`.
41
- */
42
- webhooks?: () => Promise<CommentSendWebhooks>;
43
36
  /**
44
37
  * Loads `@vite-hub/comments/realtime`, when the app has the page presence rooms. After each change of a thread, it
45
- * tells the open pages of the thread to load their threads again. The generated plugin passes it.
38
+ * tells the open pages of the thread to load their threads again. The generated plugin passes it. With `tenant`, pass
39
+ * a notifier whose rooms belong to the tenant, such as the rooms of `hostedCommentNoticeRoom()`.
46
40
  */
47
41
  realtime?: () => Promise<{
48
42
  notifyCommentsChange: (thread: CommentThread) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-8o9u8leM.js";
1
+ import { r as hasCommentsRuntime, t as commentsRuntime } from "./server-CAMs6viR.js";
2
2
  // src/installed.ts
3
3
  /** The runtime that `installComments()` connected to each definition. */
4
4
  const runtimes = /* @__PURE__ */ new WeakMap();
@@ -22,9 +22,4 @@ async function runtimeOf(comments) {
22
22
  async function resolveCommentsRuntime(comments) {
23
23
  return runtimeOf(comments);
24
24
  }
25
- /** The Send service of a definition, after the runtime is built. Undefined while Send is off. */
26
- async function commentSendOf(comments) {
27
- await runtimeOf(comments);
28
- return runtimes.get(comments)?.send;
29
- }
30
- export { runtimeOf as a, runtimeBuilds as i, pendingKey as n, runtimes as o, resolveCommentsRuntime as r, commentSendOf as t };
25
+ export { runtimes as a, runtimeOf as i, resolveCommentsRuntime as n, runtimeBuilds as r, pendingKey as t };
@@ -1,4 +1,4 @@
1
- import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
1
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
4
4
  // src/operations-core/database.ts
@@ -25,13 +25,9 @@ function commentsSqliteTables(options) {
25
25
  authorName: text("author_name"),
26
26
  authorImage: text("author_image"),
27
27
  actor: text("actor"),
28
- /** JSON of the fields that app code keeps on the thread. */
29
28
  metadata: text("metadata"),
30
- /** JSON of the page, element, components, browser, and build that the overlay read. */
31
29
  context: text("context"),
32
- /** The version of the subject that the thread was started on. */
33
30
  revision: integer("revision"),
34
- /** The retry key of `comments.create`. Unique inside `scope`. */
35
31
  requestId: text("request_id"),
36
32
  createdAt: integer("created_at").notNull(),
37
33
  updatedAt: integer("updated_at").notNull()
@@ -79,19 +75,14 @@ const commentCounters = defaultTables.commentCounters;
79
75
  */
80
76
  const commentForge = sqliteTable("vitehub_comment_forge", {
81
77
  id: text("id").primaryKey(),
82
- /** Null for summaries and cleanup rows, which survive deletion of the original thread. */
83
78
  threadId: text("thread_id"),
84
79
  repository: text("repository").notNull(),
85
80
  pullRequest: integer("pull_request").notNull(),
86
- /** The forge's id of the comment. Null until it posts. */
87
81
  remoteId: text("remote_id"),
88
- /** The GraphQL id, to hide the comment of a resolved thread. */
89
82
  nodeId: text("node_id"),
90
83
  url: text("url"),
91
- /** Hash of the body the forge has, so an unchanged comment is not sent again. */
92
84
  digest: text("digest"),
93
85
  postedAs: text("posted_as", { enum: ["author", "app"] }),
94
- /** Whether the forge hides the comment, because its thread is resolved. */
95
86
  minimized: integer("minimized", { mode: "boolean" }).notNull().default(false),
96
87
  error: text("error"),
97
88
  updatedAt: integer("updated_at").notNull()
@@ -130,25 +121,18 @@ const commentsTables = [
130
121
  // src/migrate.ts
131
122
  /** The live-site threads, after the migration renames them. The migration never deletes them. */
132
123
  const liveThreadsBackup = "vitehub_comment_threads_live";
133
- /** The columns that one model added to `vitehub_comment_threads` after its first version. */
134
124
  const addedColumns = {
135
125
  metadata: "text",
136
126
  context: "text",
137
127
  revision: "integer",
138
128
  request_id: "text"
139
129
  };
140
- /** The unique index of the `comments.create` retry key, which came with `request_id`. */
141
130
  const requestIndex = commentsTables.find((statement) => statement.includes("`vitehub_comment_threads_scope_request`"));
142
131
  const scopeOf = "CASE WHEN `scope` = 'pages' THEN 'site' ELSE `scope` END";
143
132
  function migratedAuthorId(column) {
144
133
  const id = `json_extract(${column}, '$.id')`;
145
134
  return `CASE WHEN json_extract(${column}, '$.guest') = 1 AND substr(${id}, 1, 6) <> 'guest:' THEN 'guest:' || ${id} ELSE ${id} END`;
146
135
  }
147
- /**
148
- * Moves the live-site tables to the tables of one model, on SQLite, libSQL, and D1. It renames the threads table to
149
- * `vitehub_comment_threads_live`, creates the new tables, and copies every thread and comment. It deletes nothing:
150
- * `vitehub_comment_threads_live`, `vitehub_comments`, and `vitehub_comment_scope_counters` stay for you to check.
151
- */
152
136
  function liveToCurrent() {
153
137
  const subjectKind = "CASE WHEN `scope` = 'pages' THEN 'page' WHEN instr(`scope`, ':') > 1 THEN substr(`scope`, 1, instr(`scope`, ':') - 1) ELSE `scope` END";
154
138
  const subjectId = "CASE WHEN `scope` = 'pages' THEN `page` WHEN instr(`scope`, ':') > 1 THEN substr(`scope`, instr(`scope`, ':') + 1) ELSE `page` END";
@@ -205,14 +189,12 @@ function commentsMigrationSql(options) {
205
189
  ...commentsTables.filter((statement) => statement.includes("vitehub_comment_forge"))
206
190
  ];
207
191
  }
208
- /** Keep synchronous transaction callbacks synchronous, so their driver can roll back a later failure. */
209
192
  function runSqliteStatements(db, statements, start = 0) {
210
193
  for (let index = start; index < statements.length; index++) {
211
194
  const result = db.run(sql.raw(statements[index]));
212
195
  if (typeof result === "object" && result !== null && "then" in result && typeof result.then === "function") return Promise.resolve(result).then(() => runSqliteStatements(db, statements, index + 1));
213
196
  }
214
197
  }
215
- /** The first column of each row: libSQL and D1 return objects, the SQLite proxy returns arrays. */
216
198
  function names(rows) {
217
199
  return (Array.isArray(rows) ? rows : Array.isArray(Reflect.get(Object(rows), "rows")) ? Reflect.get(Object(rows), "rows") : []).map((row) => String(Array.isArray(row) ? row[0] : Object.values(Object(row))[0]));
218
200
  }
@@ -299,48 +281,4 @@ function commentsSchemaGate(db, owner, options = {}) {
299
281
  return ready;
300
282
  };
301
283
  }
302
- // src/send/database.ts
303
- /**
304
- * One row for each send: the member, the threads it carried with the last message of each, and the read token. `threads`
305
- * holds JSON, `[{ id, message, role }]`, and `sender` the member as Comments knew them when they sent. The token is
306
- * kept as its SHA-256 hash.
307
- */
308
- const commentSends = sqliteTable("vitehub_comment_sends", {
309
- id: text("id").primaryKey(),
310
- member: text("member").notNull(),
311
- subjectKind: text("subject_kind").notNull(),
312
- subjectId: text("subject_id").notNull(),
313
- page: text("page").notNull(),
314
- threads: text("threads").notNull(),
315
- key: text("key").notNull(),
316
- state: text("state", { enum: [
317
- "pending",
318
- "sent",
319
- "working",
320
- "done",
321
- "failed"
322
- ] }).notNull(),
323
- delivery: text("delivery"),
324
- endpoint: text("endpoint"),
325
- thread: text("thread"),
326
- error: text("error"),
327
- sender: text("sender").notNull(),
328
- tokenHash: text("token_hash"),
329
- tokenExpiresAt: integer("token_expires_at"),
330
- createdAt: integer("created_at").notNull(),
331
- updatedAt: integer("updated_at").notNull()
332
- }, (table) => [
333
- index("vitehub_comment_sends_member").on(table.member, table.createdAt),
334
- index("vitehub_comment_sends_subject").on(table.subjectKind, table.subjectId, table.createdAt),
335
- uniqueIndex("vitehub_comment_sends_live_key").on(table.key).where(sql`${table.state} <> 'failed'`)
336
- ]);
337
- /** The tables of Send, for a Database contribution. Comments adds them only when `defineComments({ send })` is on. */
338
- const commentSendsSchema = { commentSends };
339
- /** `commentSendsSchema` as SQLite statements that are safe to run on every start. */
340
- const commentSendsTables = [
341
- "CREATE TABLE IF NOT EXISTS `vitehub_comment_sends` (`id` text PRIMARY KEY NOT NULL, `member` text NOT NULL, `subject_kind` text NOT NULL, `subject_id` text NOT NULL, `page` text NOT NULL, `threads` text NOT NULL, `key` text NOT NULL, `state` text NOT NULL, `delivery` text, `endpoint` text, `thread` text, `error` text, `sender` text NOT NULL, `token_hash` text, `token_expires_at` integer, `created_at` integer NOT NULL, `updated_at` integer NOT NULL)",
342
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_member` ON `vitehub_comment_sends` (`member`,`created_at`)",
343
- "CREATE INDEX IF NOT EXISTS `vitehub_comment_sends_subject` ON `vitehub_comment_sends` (`subject_kind`,`subject_id`,`created_at`)",
344
- "CREATE UNIQUE INDEX IF NOT EXISTS `vitehub_comment_sends_live_key` ON `vitehub_comment_sends` (`key`) WHERE `state` <> 'failed'"
345
- ];
346
- export { commentsSchemaGate as a, migrateComments as c, commentForge as d, commentMessages as f, commentsSqliteTables as h, commentsMigrationSql as i, commentsTables as l, commentsSchema as m, commentSendsSchema as n, commentsSchemaState as o, commentThreads as p, commentSendsTables as r, liveThreadsBackup as s, commentSends as t, commentCounters as u };
284
+ export { migrateComments as a, commentForge as c, commentsSchema as d, commentsSqliteTables as f, liveThreadsBackup as i, commentMessages as l, commentsSchemaGate as n, commentsTables as o, commentsSchemaState as r, commentCounters as s, commentsMigrationSql as t, commentThreads as u };
@@ -1,8 +1,24 @@
1
- import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-IvgrI4XM.js";
1
+ import { i as CommentsRuntime, t as CommentsAttachmentBody } from "./service-qaMuJ7UX.js";
2
2
  import { t as AnyOperation } from "./operations-DFLer1fR.js";
3
- import { f as CommentsPolicyGate, g as CommentsUser } from "./define-B1jLSPe9.js";
4
- 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-BX3vH18p.js";
3
+ import { D as CommentsPolicyGate, j as CommentsUser } from "./types-VSVs4jIw.js";
4
+ 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-BmzTyGt-.js";
5
5
  import * as v from "valibot";
6
+ /** The fields of a thread in a list, as JSON. */
7
+ interface CommentThreadSummary {
8
+ id: string;
9
+ n: number;
10
+ page: string;
11
+ status: CommentThread["status"];
12
+ /** What the comment points at, in words, such as `"Buy now"`, `the text "per month"`, or `the whole page`. */
13
+ anchor: string;
14
+ comment: string;
15
+ author: string;
16
+ replies: number;
17
+ /** The Vue components that render the element, outermost first. */
18
+ components: string[];
19
+ /** The last activity, in milliseconds since the epoch. */
20
+ updatedAt: number;
21
+ }
6
22
  declare const anchor: v.UnionSchema<[v.StrictObjectSchema<{
7
23
  readonly kind: v.LiteralSchema<"page", undefined>;
8
24
  }, undefined>, v.StrictObjectSchema<{
@@ -80,6 +96,12 @@ interface CommentsCaller {
80
96
  request?: Request;
81
97
  waitUntil?: (task: Promise<unknown>) => void;
82
98
  }
99
+ declare const threadsInput: v.StrictObjectSchema<{
100
+ readonly limit: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 100, undefined>]>, undefined>;
101
+ readonly page: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.DescriptionAction<string, "A path such as /pricing, or a full URL of the page.">, v.TransformAction<string, string>, v.CheckAction<string, "A page is an app path that starts with one \"/\", such as \"/pricing\", without \"?\" or \"#\", or a full http(s) URL of the page.">, v.TransformAction<string, string>]>, undefined>;
102
+ readonly search: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 200, undefined>]>, undefined>;
103
+ readonly status: v.OptionalSchema<v.PicklistSchema<["open", "resolved"], undefined>, undefined>;
104
+ }, undefined>;
83
105
  /** The inputs of the comment actions, for transports that read their input themselves, such as the overlay API. */
84
106
  declare const commentInputSchemas: {
85
107
  readonly attachment: v.StrictObjectSchema<{
@@ -219,19 +241,27 @@ declare const commentInputSchemas: {
219
241
  readonly threadId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 100, undefined>]>, undefined>;
220
242
  }, undefined>;
221
243
  };
244
+ /** A short list of page threads, for an Agent: `comments.threads`. */
245
+ interface CommentThreadsPage {
246
+ status: "open" | "resolved";
247
+ threads: CommentThreadSummary[];
248
+ /** The threads that `authorize` hid from the caller. */
249
+ hidden: number;
250
+ note?: string;
251
+ next?: string;
252
+ }
222
253
  /**
223
254
  * The comment actions behind every surface. The operations (RPC, CLI, MCP) and the overlay API call the same
224
255
  * functions, so one policy, one set of checks, and one set of errors serve them all. Each one checks `authorize` for
225
256
  * its caller; the input must have passed `commentInputSchemas`.
226
257
  */
227
258
  declare const commentActions: {
259
+ threads(input: v.InferOutput<typeof threadsInput>, who: CommentsCaller): Promise<CommentThreadsPage>;
228
260
  list(input: CommentListQuery, who: CommentsCaller): Promise<CommentThread[]>;
229
261
  get(input: CommentGetInput, who: CommentsCaller): Promise<CommentThread | null>;
230
- /** `context` is the page context that the overlay read and its transport checked. */
231
262
  create(input: CommentCreateInput & {
232
263
  context?: CommentContext;
233
264
  }, who: CommentsCaller): Promise<CommentThread>;
234
- /** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
235
265
  reply(input: CommentReplyInput, who: CommentsCaller, options?: {
236
266
  allowResolved?: boolean;
237
267
  }): Promise<{
@@ -245,16 +275,14 @@ declare const commentActions: {
245
275
  threadId: string;
246
276
  reply?: string;
247
277
  }[], who: CommentsCaller): Promise<CommentThread[]>;
248
- /** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
249
278
  users(input: CommentUsersInput, who: CommentsCaller, options?: {
250
279
  minimum?: number;
251
280
  }): Promise<CommentUser[]>;
252
281
  upload(input: CommentUploadInput, who: CommentsCaller): Promise<CommentAttachment>;
253
- /** The file of an attachment key, for a caller who may read a thread whose messages list it. */
254
282
  attachment(input: {
255
283
  key: string;
256
284
  }, who: CommentsCaller): Promise<CommentsAttachmentBody>;
257
285
  };
258
286
  /** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
259
287
  declare const commentsOperations: readonly AnyOperation[];
260
- export { commentsOperations as a, commentInputSchemas as i, commentActions as n, commentAnchorSchema as r, CommentsCaller as t };
288
+ export { commentInputSchemas as a, commentAnchorSchema as i, CommentsCaller as n, commentsOperations as o, commentActions as r, CommentThreadsPage as t };
@@ -1,11 +1,11 @@
1
- import { n as outboxAccountHeader } from "./client-files-lC6X7XyS.js";
2
- import { n as pagePathOf, t as isPagePath } from "./path-8yqMd8zR.js";
1
+ import { n as outboxAccountHeader } from "./client-files-CMPJEd21.js";
2
+ import { n as pagePathOf, t as isPagePath } from "./path-sv8kjq3i.js";
3
3
  import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
4
- import { t as commentsErrorDiagnostics } from "./errors-CBvIpwbo.js";
5
- import { C as threadChanged, E as createClientRateLimit, S as suggest, _ 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, w as clientAddressKey, x as storeAttachment, y as retriedReply } from "./service-XT2A8YEF.js";
4
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
5
+ import { C as threadChanged, E as createClientRateLimit, S as suggest, _ 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, w as clientAddressKey, x as storeAttachment, y as retriedReply } from "./service-DFMwCr60.js";
6
6
  import { n as guestFromHeaders, t as authorOf } from "./identity-CT7-UGmS.js";
7
7
  import { t as describeCommentContext } from "./context-DbkBjITZ.js";
8
- import { t as commentsRuntime } from "./server-8o9u8leM.js";
8
+ import { t as commentsRuntime } from "./server-CAMs6viR.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";
@@ -437,9 +437,7 @@ function operationAccessAllows(access, section, call) {
437
437
  function commentPersonName(person) {
438
438
  return `${person.name ?? person.id}${person.guest ? " (guest)" : ""}`;
439
439
  }
440
- /** Thousandths of an element box as a percentage, such as `97.3%`. */
441
440
  const share = (value) => `${Number((value / 10).toFixed(1))}%`;
442
- /** What the comment points at, in words: the element, the quoted text, or the part of the element box it marked. */
443
441
  function describeAnchor(anchor) {
444
442
  switch (anchor.kind) {
445
443
  case "page": return "Anchor: the whole page";
@@ -461,7 +459,6 @@ function describeCommentThread(thread) {
461
459
  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()}`);
462
460
  return lines.join("\n");
463
461
  }
464
- /** At most `max` characters of `value`, flattened to one line and cut at a word, with `…` when cut. */
465
462
  function clip(value, max) {
466
463
  const flat = value.replace(/\s+/g, " ").trim();
467
464
  if (flat.length <= max) return flat;
@@ -493,7 +490,6 @@ function commentThreadSummary(thread) {
493
490
  updatedAt: thread.updatedAt
494
491
  };
495
492
  }
496
- /** A time to the minute in UTC, in ISO 8601, such as `2026-11-17T09:22Z`. */
497
493
  function minute(time) {
498
494
  return `${new Date(time).toISOString().slice(0, 16)}Z`;
499
495
  }
@@ -526,7 +522,6 @@ const defaultLimit = 200;
526
522
  const maximumLimit = 500;
527
523
  const maximumSuggestions = 10;
528
524
  const minimumQuery = 2;
529
- /** Threads that `authorize` checks at once. */
530
525
  const authorizeConcurrency = 16;
531
526
  const thousandths = v.pipe(v.number(), v.minValue(0), v.maxValue(1e3));
532
527
  const selector = v.pipe(v.string(), v.minLength(1), v.maxLength(2048));
@@ -611,12 +606,6 @@ function actorOf(actor) {
611
606
  ...actor.label ? { name: actor.label } : {}
612
607
  } : void 0;
613
608
  }
614
- /**
615
- * Operations run only after the Console admitted the call to the `comments` section, so `authorize` gets
616
- * `console: true`. With `identify`, the app names the user from the request of the call, as in the overlay API, and
617
- * `authorize` decides; a call without a request, such as an agent's, has no user. Without `identify`, the user is the
618
- * Console's, and the default policy trusts it.
619
- */
620
609
  async function caller(context) {
621
610
  const runtime = await commentsRuntime();
622
611
  const actor = actorOf(context.actor);
@@ -639,7 +628,6 @@ async function caller(context) {
639
628
  ...context.waitUntil ? { waitUntil: context.waitUntil } : {}
640
629
  };
641
630
  }
642
- /** Asks the policy, with the thread and its subject, or the subject a thread would start on. */
643
631
  async function permitted(who, action, target = {}) {
644
632
  return can(who.runtime, {
645
633
  action,
@@ -652,7 +640,6 @@ async function permitted(who, action, target = {}) {
652
640
  async function allow(who, action, target) {
653
641
  if (!await permitted(who, action, target)) throw deniedError(who.runtime, action, who.user, who.gate);
654
642
  }
655
- /** The signed-in user, else the guest of the request, which only a policy that lets anonymous people write gets this far. */
656
643
  function author(who) {
657
644
  if (who.user) return personOf(authorOf(who.user));
658
645
  const guest = who.request ? guestFromHeaders(who.request.headers) : void 0;
@@ -664,10 +651,6 @@ function checkOutboxAccount(who) {
664
651
  if (expected != null && expected !== encodeURIComponent(author(who).id)) throw fail(commentsErrorDiagnostics.COMMENTS_OUTBOX_ACCOUNT_CHANGED(), 401);
665
652
  }
666
653
  const guestLimits = /* @__PURE__ */ new WeakMap();
667
- /**
668
- * Counts one write of a guest against `defineComments({ rateLimit })`, by the address of the request. Signed-in people
669
- * and Agents are not limited. Call it after the policy allowed the write, so a refused write uses no budget.
670
- */
671
654
  async function limitGuest(who) {
672
655
  const policy = who.runtime.definition.rateLimit;
673
656
  if (!policy || !who.request || who.actor || who.user && who.user.guest !== true) return;
@@ -694,7 +677,6 @@ function writeOptions(who) {
694
677
  ...who.waitUntil ? { waitUntil: who.waitUntil } : {}
695
678
  };
696
679
  }
697
- /** A thread that does not exist and one that the caller may not read look the same: not found. */
698
680
  async function load(who, threadIdValue) {
699
681
  const found = await who.runtime.store.getById(threadIdValue);
700
682
  if (!found || !await permitted(who, "read", { thread: found })) throw fail(commentsErrorDiagnostics.COMMENTS_R0002({ id: threadIdValue }), 404);
@@ -794,10 +776,6 @@ const commentInputSchemas = {
794
776
  upload: uploadInput,
795
777
  users: usersInput
796
778
  };
797
- /**
798
- * The threads of a list that the caller may read, and how many threads the policy left out on the way. Threads the
799
- * caller may not read are left out, so it asks again after them until the page is full or the threads end.
800
- */
801
779
  async function readableThreads(input, who) {
802
780
  const limit = input.limit ?? defaultLimit;
803
781
  const readable = [];
@@ -824,12 +802,53 @@ async function readableThreads(input, who) {
824
802
  hidden
825
803
  };
826
804
  }
805
+ 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.";
806
+ const searchBatch = maximumLimit;
827
807
  /**
828
808
  * The comment actions behind every surface. The operations (RPC, CLI, MCP) and the overlay API call the same
829
809
  * functions, so one policy, one set of checks, and one set of errors serve them all. Each one checks `authorize` for
830
810
  * its caller; the input must have passed `commentInputSchemas`.
831
811
  */
832
812
  const commentActions = {
813
+ async threads(input, who) {
814
+ const status = input.status ?? "open";
815
+ const limit = input.limit ?? 25;
816
+ const search = input.search?.toLowerCase();
817
+ const batch = search ? searchBatch : limit;
818
+ const found = [];
819
+ let hidden = 0;
820
+ let before;
821
+ while (found.length < limit) {
822
+ const listed = await readableThreads({
823
+ limit: batch,
824
+ status,
825
+ subjectKind: "page",
826
+ ...input.page ? { page: input.page } : {},
827
+ ...before ? { before } : {}
828
+ }, who);
829
+ hidden += listed.hidden;
830
+ for (const thread of listed.threads) {
831
+ if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
832
+ if (found.length === limit) break;
833
+ }
834
+ if (listed.threads.length < batch) break;
835
+ before = cursorOf(listed.threads.at(-1));
836
+ }
837
+ const note = hiddenThreadsNote(hidden, {
838
+ authorize: Boolean(who.runtime.definition.authorize),
839
+ identify: Boolean(who.runtime.identify),
840
+ user: who.user !== null,
841
+ console: who.console === true
842
+ });
843
+ const next = status === "open" && found.length ? resolveNext : void 0;
844
+ return {
845
+ status,
846
+ threads: found.map(commentThreadSummary),
847
+ hidden,
848
+ ...note ? { note } : {},
849
+ ...next ? { next } : {}
850
+ };
851
+ },
833
852
  async list(input, who) {
834
853
  return (await readableThreads(input, who)).threads;
835
854
  },
@@ -838,7 +857,6 @@ const commentActions = {
838
857
  if (!found || !await permitted(who, "read", { thread: found })) return null;
839
858
  return (await withForge(who, [found]))[0];
840
859
  },
841
- /** `context` is the page context that the overlay read and its transport checked. */
842
860
  async create(input, who) {
843
861
  checkOutboxAccount(who);
844
862
  const canRead = (thread) => permitted(who, "read", { thread });
@@ -859,7 +877,6 @@ const commentActions = {
859
877
  canRead
860
878
  });
861
879
  },
862
- /** `allowResolved`: the operations keep a reply box on resolved threads, and a reply keeps the thread resolved. */
863
880
  async reply(input, who, options = {}) {
864
881
  checkOutboxAccount(who);
865
882
  const found = await load(who, input.threadId);
@@ -916,7 +933,6 @@ const commentActions = {
916
933
  await allow(who, "resolve", { thread: found });
917
934
  const next = await who.runtime.store.setStatus(found.id, status, author(who), Date.now(), status === "resolved" ? who.actor : void 0);
918
935
  await threadChanged(who.runtime, next);
919
- if (status === "open") await who.runtime.reopened?.(next);
920
936
  return next;
921
937
  },
922
938
  async resolveThreads(input, who) {
@@ -977,7 +993,6 @@ const commentActions = {
977
993
  }
978
994
  return resolved;
979
995
  },
980
- /** `minimum`: the shortest query that gets suggestions. The operations ask for two characters. */
981
996
  async users(input, who, options = {}) {
982
997
  const thread = input.threadId === void 0 ? void 0 : await load(who, input.threadId);
983
998
  const target = thread ? { thread } : input.subject ? { subject: input.subject } : {};
@@ -1003,7 +1018,6 @@ const commentActions = {
1003
1018
  await limitGuest(who);
1004
1019
  return storeAttachment(who.runtime, input, who.user);
1005
1020
  },
1006
- /** The file of an attachment key, for a caller who may read a thread whose messages list it. */
1007
1021
  async attachment(input, who) {
1008
1022
  const thread = await attachmentThread(who.runtime, input.key, (candidate) => permitted(who, "read", { thread: candidate }));
1009
1023
  return readAttachment(who.runtime, input.key, {
@@ -1020,9 +1034,6 @@ const list = defineOperation({
1020
1034
  run: async (input, context) => commentActions.list(input, await caller(context)),
1021
1035
  section: "comments"
1022
1036
  });
1023
- 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.";
1024
- /** Threads that one search reads from the store at a time. */
1025
- const searchBatch = maximumLimit;
1026
1037
  /** The comment operations. The Console, the CLI, MCP, and the comments client call them. */
1027
1038
  const commentsOperations = [
1028
1039
  defineOperation({
@@ -1030,46 +1041,7 @@ const commentsOperations = [
1030
1041
  input: threadsInput,
1031
1042
  kind: "read",
1032
1043
  name: "comments.threads",
1033
- run: async (input, context) => {
1034
- const who = await caller(context);
1035
- const status = input.status ?? "open";
1036
- const limit = input.limit ?? 25;
1037
- const search = input.search?.toLowerCase();
1038
- const batch = search ? searchBatch : limit;
1039
- const found = [];
1040
- let hidden = 0;
1041
- let before;
1042
- while (found.length < limit) {
1043
- const listed = await readableThreads({
1044
- limit: batch,
1045
- status,
1046
- subjectKind: "page",
1047
- ...input.page ? { page: input.page } : {},
1048
- ...before ? { before } : {}
1049
- }, who);
1050
- hidden += listed.hidden;
1051
- for (const thread of listed.threads) {
1052
- if (!search || thread.messages.some((message) => message.body.toLowerCase().includes(search))) found.push(thread);
1053
- if (found.length === limit) break;
1054
- }
1055
- if (listed.threads.length < batch) break;
1056
- before = cursorOf(listed.threads.at(-1));
1057
- }
1058
- const note = hiddenThreadsNote(hidden, {
1059
- authorize: Boolean(who.runtime.definition.authorize),
1060
- identify: Boolean(who.runtime.identify),
1061
- user: who.user !== null,
1062
- console: who.console === true
1063
- });
1064
- const next = status === "open" && found.length ? resolveNext : void 0;
1065
- return {
1066
- status,
1067
- threads: found.map(commentThreadSummary),
1068
- hidden,
1069
- ...note ? { note } : {},
1070
- ...next ? { next } : {}
1071
- };
1072
- },
1044
+ run: async (input, context) => commentActions.threads(input, await caller(context)),
1073
1045
  mcp: {
1074
1046
  format: ({ status, threads, note }) => commentThreadsText(threads, status, note ?? ""),
1075
1047
  title: "List ViteHub Comments threads"
@@ -1,3 +1,3 @@
1
- import { a as maximumCommentBodyLength } from "./service-IvgrI4XM.js";
2
- import { a as commentsOperations, i as commentInputSchemas, n as commentActions, r as commentAnchorSchema, t as CommentsCaller } from "./operations-Qt8ASQqW.js";
3
- export { CommentsCaller, commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };
1
+ import { a as maximumCommentBodyLength } from "./service-qaMuJ7UX.js";
2
+ import { a as commentInputSchemas, i as commentAnchorSchema, n as CommentsCaller, o as commentsOperations, r as commentActions, t as CommentThreadsPage } from "./operations-D0EO1pzL.js";
3
+ export { CommentThreadsPage, 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-kMPw-Cyb.js";
2
- import { f as maximumCommentBodyLength } from "./service-XT2A8YEF.js";
1
+ import { i as commentsOperations, n as commentAnchorSchema, r as commentInputSchemas, t as commentActions } from "./operations-DHXmbtb3.js";
2
+ import { f as maximumCommentBodyLength } from "./service-DFMwCr60.js";
3
3
  export { commentActions, commentAnchorSchema, commentInputSchemas, commentsOperations, maximumCommentBodyLength };