@voltro/plugin-comments 0.90.0 → 0.91.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -41,6 +41,137 @@ _Changes staged for the next release accumulate here (rolled up from
41
41
 
42
42
  ---
43
43
 
44
+ ## [0.91.1] — 2026-11-26
45
+
46
+ ### Fixed
47
+
48
+ - **The local dashboard package installs again with pnpm** — `@voltro/dashboard`
49
+
50
+ `@voltro/dashboard@0.91.0` was published with an unresolved `"effect": "catalog:"` dependency, so pnpm refused to install it (`"effect@catalog:" isn't supported`). 0.91.1 pins the Effect version the release is built on, and a dashboard manifest that still carries a workspace protocol is no longer published. Update with `voltro update` to 0.91.1; there is nothing else to change.
51
+
52
+ ---
53
+
54
+ ## [0.91.0] — 2026-11-25
55
+
56
+ ### ⚠ BREAKING
57
+
58
+ - **The AI provider adapters are peer dependencies of `@voltro/ai`** — `@voltro/ai`
59
+
60
+ `@ai-sdk/anthropic` (`^4.0.91`) and `@ai-sdk/openai` (`^4.0.104`) moved from `dependencies` to `peerDependencies`, next to `ai`, `@ai-sdk/provider` and `@ai-sdk/gateway`. Each adapter pins `@ai-sdk/provider` exactly. As a dependency, a fresh install resolved the newest adapter, which could pin a newer `@ai-sdk/provider` than the app's own `ai`. The model it built was then typed against a second copy (`Type 'LanguageModelV4' is not assignable to type 'LanguageModel'`) and could stream parts that the app's `ai` does not know. Now the adapter resolves from the app's own pins. Most apps already declare the adapter they configure and need no change. If the install warns about an unmet peer, add that adapter or raise its pin to the floor. `voltro doctor` lists any duplicate copies that remain.
61
+
62
+ **`voltro update` carries you across this** — codemod `0.91.0/01_ai-provider-adapters-are-peers`. If you pin versions by hand and never run it, print the notes without changing anything: `voltro update --codemods-only --from <your current version> --dry-run` (this one ships in 0.91.0).
63
+ - **Workflow cluster tuning is configurable in `app.config.ts` and validated at boot** — `@voltro/workflow`, `@voltro/cli`
64
+
65
+ The failover lease, failover heartbeat, message poll and the new assignment refresh of the workflow cluster can be set in `app.config.ts` under `workflows.cluster` (`failoverLeaseSeconds`, `failoverHeartbeatSeconds`, `messagePollSeconds`, `assignmentRefreshSeconds`). The environment variables `VOLTRO_WORKFLOW_FAILOVER_LEASE`, `VOLTRO_WORKFLOW_FAILOVER_HEARTBEAT`, `VOLTRO_WORKFLOW_POLL_INTERVAL` and the new `VOLTRO_WORKFLOW_ASSIGNMENT_REFRESH` override the matching field. A value outside its range (lease 5–600 s, heartbeat 1–300 s and at most half the lease, poll 1–300 s, assignment refresh 1–60 s) now stops the boot with a message naming the setting. Before, a malformed value was silently replaced by the default, which hid the one setting an operator had changed on purpose. `voltro dev` and `voltro serve` resolve the settings the same way. The assignment refresh defaults to 10 s instead of the cluster library's 3 s: it decides only how soon a newly started or gracefully stopped replica changes shard ownership, while a crashed replica is still detected through its lease.
66
+
67
+ **`voltro update` carries you across this** — codemod `0.91.0/02_workflow-cluster-tuning-is-validated`. If you pin versions by hand and never run it, print the notes without changing anything: `voltro update --codemods-only --from <your current version> --dry-run` (this one ships in 0.91.0).
68
+
69
+ ### Added
70
+
71
+ - **`voltro add patches --ai 7.0.173` supports the current AI SDK release** — `@voltro/cli`
72
+
73
+ `voltro add patches --ai 7.0.173` writes the declaration patch for `@ai-sdk/provider-utils` 5.0.81, the release `ai` 7.0.173 installs, together with the provider's `@types/json-schema` package extension. Run it before installing AI UI items with shadcn or Voltro. The patches for 7.0.156, 7.0.132 and 7.0.105 remain available.
74
+ - **Serving instances seal previous-release idempotency receipts themselves** — `@voltro/runtime`, `@voltro/cli`
75
+
76
+ Receipts written before input bindings were sealed keep a plaintext digest, which serving refuses as `input-unbound`. Converting them needed `voltro db protect-idempotency-inputs --writers-stopped --yes`, and on a rolling deploy no step runs after the last previous-release instance is gone, so it stayed a manual step. An in-flight receipt that a replaced instance abandoned kept its key refused until someone ran it.
77
+
78
+ The instances that run retention now seal every plaintext receipt on their own, also while previous-release instances still serve. A completed receipt is sealed on the first pass. An in-flight receipt is sealed once it has gone unrenewed for four in-flight leases (two minutes); the previous release itself takes such a receipt over as abandoned, and after sealing the current release does the same, so the key is usable again. A receipt its writer still renews is left for a later pass, and a renewal racing the seal wins. A previous-release instance that meets a sealed receipt refuses that request; it never executes it twice. No operator step remains after a rolling deploy; the command stays for an offline window.
79
+
80
+ `makeIdempotencyInputProtection` accepts `{ liveWriters: true, staleAfterMs?, now? }` for this mode, its report gains `deferred`, and `DEFAULT_ABANDONED_INPUT_BINDING_MS` names the default window.
81
+
82
+ ### Changed
83
+
84
+ - **The framework runs on effect 4.1.4** — `@voltro/cli`, `@voltro/devtools`, `@voltro/runtime`, `@voltro/database`, `@voltro/voltro`, `@voltro/workflow`, `@voltro/sql-sqlite`, `@voltro/sql-mysql`, `@voltro/sql-mssql`, `@voltro/sql-postgres`
85
+
86
+ Every `@voltro/*` package now pins `effect` and its `@effect/*` companions to 4.1.4. `voltro update` moves the pins, the lockstep overrides and the version-keyed patch entries for you; a workspace you update by hand runs `voltro add patches` after pinning 4.1.4, which writes the 4.1.4 patch files and retires the 4.1.2 entries.
87
+
88
+ Effect 4.1.4 fixes the configuration parser's shared sentinels itself, so the framework's `effect` patch no longer carries that change; its cluster, workflow and SQL message-storage changes carry over unchanged.
89
+
90
+ Two upstream changes reach code that uses Effect's SQL and cluster modules directly:
91
+
92
+ - `PgClient`, `MysqlClient` and `MssqlClient` no longer extend `SqlClient`; their layers provide both services side by side. The framework's store options (`sqlLayer` of the PostgreSQL, MySQL and SQL Server stores) now ask only for `SqlClient`, so any layer that provides it is accepted. A PostgreSQL store with `changeStrategy: 'cdc'` still reads `PgClient` for `LISTEN` and refuses to start its consumer, naming `makePostgresSqlLayer()`, when the layer does not provide it. - `MessageStorage` has a new `deleteProcessed` operation. A custom `MessageStorage` implementation must add it. The workflow engine's journal admission bounds it like every other storage operation.
93
+ - **An idle multi-replica deployment runs a fraction of its former database traffic** — `@voltro/cli`, `@voltro/runtime`, `@voltro/workflow`, `@voltro/database`
94
+
95
+ A two-replica PostgreSQL deployment that nobody used ran about 500 statements a minute per replica, most of them workflow recovery reads that returned no rows every second. Measured the same way, it now runs about 75. The workflow control, restart, admission and flow-control sweeps run on the coordinated scheduler: they wake at once on a write they can see through the change feed or a broadcast broker, and otherwise back off to the 30-second idle ceiling (`pollCeilingMs`), which remains the crash backstop. Without a visible change feed, workflow admission still reconciles every five seconds. The field-key lease renews every 30 seconds with a 90-second lifetime and reacts at once to a key change. The secret-window sync reads its table once per pass. Web replicas publish their observation every 30 seconds and count as stale after 90. Schedule claims and replica observations no longer carry a change trigger, so their periodic writes notify no listener. What an idle fleet still costs, and why each statement is time-bound, is documented under production hardening.
96
+ - **VoltroFooter links Contact to the contact form, names the company in formation** — `@voltro/ui-shadcn`
97
+
98
+ `VoltroFooter`'s Contact link under Company now opens the contact form on voltro.cloud (`/contact`, or `/de/contact` in German) instead of a `mailto:` address, and the copyright line and `voltroOrganizationJsonLd()` name the company as `Voltro UG (haftungsbeschränkt) i.G.` while its commercial register entry is pending.
99
+
100
+ ### Fixed
101
+
102
+ - **The billing plugin loads without an initialisation error** — `@voltro/plugin-billing`
103
+
104
+ Loading `@voltro/plugin-billing` could stop with `Cannot access '…' before initialization`, which made `voltro codegen` refuse an `app.config.ts` that uses the plugin. Two internal modules imported each other, and the catalog read the Stripe SDK before that module had finished loading. The package's modules no longer import each other in a cycle, and a test keeps it that way.
105
+ - **Trailing-slash URLs keep their page during hydration** — `@voltro/web`
106
+
107
+ Browser routing now accepts the same trailing-slash URLs as server rendering. Opening `/about/` or `/users/42/` retains the matching page during hydration and navigation instead of showing a not-found page or a broader catch-all. Route priority and once-decoded parameters remain consistent.
108
+ - **The `voltro build` prerender no longer fails on a slow module transform** — `@voltro/cli`
109
+
110
+ The prerender loaded each page, layout and helper through Vite's `ssrLoadModule`, whose fetch of one module times out after a fixed 60 seconds. On a busy machine, such as a CI runner shared with other jobs or a container at its CPU limit, one cold transform could take longer than that, and the build failed with `transport invoke timed out after 60000ms` although the app was fine. The prerender now loads through its own module runner, which allows ten minutes per module. A transform that never settles still fails the build. Errors keep their source-mapped stack, and all prerendered pages still share one instance of each module.
111
+ - **Charset conversion restores foreign keys in plan order, and so does its undo** — `@voltro/database`, `@voltro/cli`
112
+
113
+ When a declared `store: { charset }` converts two tables joined by a foreign key, the constraint is now re-created by whichever conversion runs later in the plan. It used to be decided by table name. A table with column changes in the same plan converts later than one without, so an apply could stop with InnoDB `errno 150` (MySQL `3780`) when the earlier table re-created the constraint against a column not yet converted. Even without that error, the later table skipped the constraint, so it was lost. The undo of a deploy that stopped in that state also tried to re-create such a constraint across the two character sets and stopped on its first statement with nothing reverted. It now converts the tables back first and re-creates the dropped constraints afterwards.
114
+ - **Clients view compares SDKs in bundle-only production images** — `@voltro/cli`
115
+
116
+ The dashboard's Clients view and `GET /_voltro/inspect/clients` could not tell whether a connected engine SDK was generated from the running API when the API ran from the serve bundle alone: the comparison value was computed from the app's TypeScript sources at request time, and a standalone image has neither those nor their loader, so every client showed as unknown. `voltro build` now computes the API's `surfaceSha256` and records it in the serve bundle. Rebuild the api to get the comparison in production.
117
+ - **Restore keyboard focus after live row removal** — `@voltro/devtools-ui`
118
+
119
+ After a successful confirmation, a dialog with a connected `returnFocusTo` destination focuses it immediately. This keeps keyboard focus in the directory when the live row disappears after the mutation acknowledgment. Cancel returns focus to the original opener while it is available.
120
+ - **A failed SSR module load in dev is retried on the next request** — `@voltro/cli`
121
+
122
+ Vite keeps a module whose server evaluation threw and rethrows that error on every later load until the file changes. In `voltro dev` a one-off failure therefore broke every route that imports the module until the dev server restarted. One example is the module runner's 60-second fetch timeout on an overloaded machine. The failed modules are now invalidated after the failed request, so the next request loads them again. A bug in the code still fails on every request. The `voltro start` fallback that compiles pages on demand behaves the same way.
123
+ - **A dev SSR load whose import transform hung recovers on the next request** — `@voltro/cli`
124
+
125
+ When the module runner's 60-second fetch timeout failed a page while one of its imports was still being transformed, that import carried no error of its own, so the earlier recovery left it alone. Vite then handed every later request the same pending transform, and the route kept answering 500 after another 60 seconds until the dev server restarted. A failed load in `voltro dev` and in the `voltro start` on-demand fallback now also invalidates each import of the failed modules that never finished loading, so the next request transforms it afresh. The inspect route list, the OG route and content collections load pages through the same recovery.
126
+ - **Dev server keeps seeing edits in nested folders of a recreated directory** — `@voltro/cli`
127
+
128
+ When a generator deletes and recreates a directory while the dev server is busy, edits inside its subfolders now reach the server again too. Before, only files directly inside the recreated directory were picked up, and a page under a subfolder kept serving its old module until `voltro dev` restarted.
129
+ - **The devtools capsule keeps a steady status and stays where you drop it** — `@voltro/devtools`, `@voltro/web`
130
+
131
+ During a dev navigation the capsule switched between `Loading` and `Compiling` several times a second. A page request now only advances (`Loading` → `Compiling` → `Rendering`), `Compiling page` stays until the page's code has arrived, and the capsule keeps each progress status on screen briefly before showing the newest one. Errors and a navigation to another route still show at once. A long route is shortened in the middle of its path on one line, so the action and the end of the route stay readable; the tooltip carries the full text. A capsule you drag over page content now stays where you drop it until the page reloads, instead of moving to the nearest free slot, which was often the one it came from.
132
+ - **Engine server checkpoints stay in their environment** — `@voltro/data-transfer`
133
+
134
+ `voltro data export` and environment seeding now treat the game checkpoints that `@voltro/plugin-engine-servers` keeps for crash recovery as environment-local, like the sessions they belong to. A checkpoint copied into another environment would resume a session that environment never hosted.
135
+ - **Copied agent-docs and desktop serve bundles are replaced whole, never partly** — `@voltro/cli`
136
+
137
+ The `agent-docs/` directory that `voltro agents-md` and `voltro dev` copy into a project, and the `src-tauri/resources/serveBundle/` that `voltro desktop build` places, are now built beside the old directory and swapped in only once complete. A copy that cannot finish now leaves the previous directory exactly as it was. That includes a source the package manager is replacing during an install, an interrupted or killed process, and a second seeder working at the same moment. Before, the old directory was removed first and refilled file by file, so a stopped copy left part of it deleted: for a committed `agent-docs/`, dozens of deletions in `git status`. Two concurrent seeds of one repository also no longer report spurious copy failures. A process killed mid-copy may leave a `.agent-docs.voltro-replace-*` directory with its own `.gitignore`, which a later seed removes once its process has ended.
138
+ - **The document language returns after leaving a URL locale** — `@voltro/web`
139
+
140
+ After a client-side switch to a `[locale]` route (`/x` → `/de/x`), navigating back to a page without a URL locale now restores `<html lang>` and the language `meta` resolves in to the one the server rendered. Previously the router read its own earlier change back, so the English page kept `lang="de"` and a German title.
141
+ - **A boot waiting for the migration lock takes it once the holder releases** — `@voltro/database`
142
+
143
+ A replica waiting for another replica's migration on PostgreSQL, MySQL or MariaDB could abort its boot with `its holder has been silent for 30s` while the holder was alive and had just finished: when the holder released the lock between the waiter's failed attempt and its liveness read, "no holder any more" was judged like "a holder gone quiet". The waiter now retries at once when it finds no holder and takes the lock. A holder whose session the waiting role cannot read is refused at the timeout as before, and the refusal now says that the session was not visible instead of claiming it was silent.
144
+ - **SQL Server reads outside a transaction replay a deadlock victim** — `@voltro/sql-mssql`, `@voltro/plugin-engine-servers`
145
+
146
+ Under locking `READ COMMITTED`, SQL Server can pick a plain `SELECT` as the deadlock victim (error 1205) when it meets concurrent writers. A transaction already replayed such a failure, but a read outside one failed at once. On engine servers this let a sweep racing a resume answer `unavailable`. A read outside a transaction now replays on the same bounded schedule as a transaction (4 attempts, exponential backoff from 10 ms). A read inside your transaction still replays only with the whole transaction.
147
+
148
+ Engine-server errors that answer `unavailable` for a storage failure now keep the original error as a non-enumerable `cause` for server logs. The wire error still carries only `code` and `reason`.
149
+ - **Native backups report success only after the dump file is written** — `@voltro/data-transfer`
150
+
151
+ `voltro data backup` with a native dump tool now waits until the dump file is fully written and closed before it reports success. On a busy machine the command could previously finish while the file was still missing, empty or truncated. A failure to write the file now fails the backup and removes the partial output.
152
+ - **prune-runtime no longer keeps the CLI behind the serve bundle** — `@voltro/cli`
153
+
154
+ `voltro prune-runtime` followed the serve bundle's lazy import of `@voltro/cli/devArtifacts` and kept the CLI's whole command graph and its templates in the image — several thousand files. That subpath reads the app's TypeScript sources and cannot work in a bundle-only image, where the caller already falls back, so the trace now skips it.
155
+
156
+ No action needed. Standalone images get smaller on the next build.
157
+ - **voltro prune-runtime no longer runs out of memory on large api apps** — `@voltro/cli`
158
+
159
+ `voltro prune-runtime` could stop with "heap out of memory" at Node's default heap limit on an api app with a few thousand modules. Bundled code that reads files below the working directory made the trace follow the whole deploy directory: the app's sources, the unbundled entries and every package those import were parsed although none of them runs in production. The trace now follows files outside `node_modules` only inside the built bundles, and traces each bundle on its own. On an api of about 2,450 modules the peak heap fell from 3.5 GB for one bundle to under 0.7 GB for all three, and packages that only the sources import are no longer kept in the image. Remove a raised `--max-old-space-size` for this step once you are on this version.
160
+ - **Rolling-deploy advisory skips constraints on a column the same plan adds** — `@voltro/database`, `@voltro/cli`
161
+
162
+ `voltro db plan` and `voltro db apply` no longer report a foreign key, CHECK or JSON check as unsafe under a rolling deploy when it lands on a column the same plan adds as nullable without a default. An instance on the previous release does not know that column and can only leave it `NULL`, which these constraints admit — so an upgrade that adds a nullable reference column, its parent table and the foreign key together (including on framework tables) prints no advisory. `NOT NULL`, unique constraints and constraints on a new column with a default keep their verdict. `rollingDeployContextOf(operations)` is exported beside `createdTablesOf` for callers that classify single operations.
163
+ - **Concurrent first Room moderation of one Subject no longer fails on Postgres** — `@voltro/plugin-rooms`
164
+
165
+ Two servers that kicked the same Subject at the same moment for the first time could make one of them answer "Original Room moderation outcome is unconfirmed" on Postgres. The losing transaction hit the Subject table's second unique key. It now runs once more, finds the committed Subject row, and both callers receive the same result.
166
+ - **Boot catch-up after downtime no longer holds scheduler readiness** — `@voltro/runtime`
167
+
168
+ A schedule with `backfill: 'latest'` that had not run for a long time claimed and recorded every missed occurrence one after another, up to 1000 per schedule, before the scheduler reported running, so readiness stayed `503` for minutes after a long downtime. It also fired the thousandth occurrence after the last run instead of the most recent one, which left the next boot another gap to walk. The catch-up now fires once at the most recent due occurrence and records the older ones as a single `missed` row whose `result` carries `{ missed: { from, through, occurrences } }` (`occurrencesAtLeast` once the count passes 1000) — two claims per gap, whatever its length. Boot catch-up for `latest` and `all` runs after startup, per schedule and before that schedule's live timer arms, so `SchedulerHandle.isRunning()` and readiness no longer wait for catch-up handlers. Readers that counted `missed` rows per occurrence should read the count from `result` instead. An `all` gap longer than 1000 occurrences now logs the first occurrence it did not fire.
169
+ - **yarn workspaces also get the peers of the framework's peers** — `@voltro/cli`
170
+
171
+ A yarn workspace's `.yarnrc.yml` lists every non-optional peer of the framework tree as `packageExtensions`, because yarn installs no peers. That list now also covers the packages those peers bring in. The AI adapters became peers of `@voltro/ai` in this release; without this, a fresh yarn workspace installed `@ai-sdk/provider-utils` without `zod` and `voltro codegen` stopped with `Cannot find package 'zod'`. Workspaces created by an earlier release already list `zod` through the adapters they installed then, and need no change.
172
+
173
+ ---
174
+
44
175
  ## [0.90.0] — 2026-11-16
45
176
 
46
177
  ### ⚠ BREAKING
@@ -149,7 +149,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
149
149
  SOFTWARE.
150
150
  ```
151
151
 
152
- ## jose@6.2.13
152
+ ## jose@6.2.17
153
153
 
154
154
  License: MIT
155
155
 
package/dist/index.js CHANGED
@@ -1,124 +1,124 @@
1
- import { CommentAccessRefused as e, CommentNotFound as t, CommentNotYours as n, CommentStatusRefused as r } from "./errors.js";
2
- import { QUOTE_MAX_LENGTH as i, findQuote as a, textQuote as o } from "./quote.js";
3
- import { BASE_NAME as s, COMMENT_THREAD_KINDS as c, commentsFeed as l, commentsRpcClientImports as u, createDescriptor as d, deleteDescriptor as f, editDescriptor as p, listDescriptor as m, markReadDescriptor as h, mentionSearchDescriptor as g, reactDescriptor as _, resolveDescriptor as ee } from "./rpc.js";
4
- import { Effect as v, Option as y } from "effect";
5
- import { and as b, contains as x, eq as S, generateId as C, id as w, inSet as T, json as E, neq as D, or as O, table as k, text as A, timestamp as j } from "@voltro/database";
6
- import { definePlugin as M, effectiveScopes as N, pluginInstanceName as P, publishReactivity as F } from "@voltro/protocol";
7
- import { NotificationService as I } from "@voltro/plugin-notifications";
1
+ import { BASE_NAME as e, COMMENT_THREAD_KINDS as t, commentsFeed as n, commentsRpcClientImports as r, createDescriptor as i, deleteDescriptor as a, editDescriptor as o, listDescriptor as s, markReadDescriptor as c, mentionSearchDescriptor as l, reactDescriptor as u, resolveDescriptor as d } from "./rpc.js";
2
+ import { CommentAccessRefused as f, CommentNotFound as p, CommentNotYours as m, CommentStatusRefused as h } from "./errors.js";
3
+ import { QUOTE_MAX_LENGTH as g, findQuote as _, textQuote as v } from "./quote.js";
4
+ import { Effect as y, Option as b } from "effect";
5
+ import { and as x, contains as S, eq as C, generateId as w, id as T, inSet as E, json as D, neq as O, or as k, table as A, text as j, timestamp as M } from "@voltro/database";
6
+ import { definePlugin as N, effectiveScopes as P, pluginInstanceName as F, publishReactivity as I } from "@voltro/protocol";
7
+ import { NotificationService as L } from "@voltro/plugin-notifications";
8
8
  // src/index.ts
9
- var L = k("_voltro_comment_threads", {
10
- id: w({ prefix: "cmtthr" }),
11
- anchor: A(),
12
- quote: E().nullable(),
13
- kind: A().default("discussion"),
14
- status: A().default("open"),
15
- createdBy: A(),
16
- createdAt: j().default("now"),
17
- tenantId: A().nullable()
18
- }).index("byThreadAnchor", ["anchor", "tenantId"]), R = k("_voltro_comments", {
19
- id: w({ prefix: "cmt" }),
20
- threadId: A(),
21
- body: A(),
22
- authorSubjectId: A(),
23
- mentions: E(),
24
- editedAt: j().nullable(),
25
- createdAt: j().default("now"),
26
- tenantId: A().nullable()
27
- }).index("byCommentThread", ["threadId"]), z = k("_voltro_comment_thread_events", {
28
- id: w({ prefix: "cmtevt" }),
29
- threadId: A(),
30
- fromStatus: A().nullable(),
31
- toStatus: A(),
32
- actor: A(),
33
- reason: A().nullable(),
34
- at: j().default("now"),
35
- tenantId: A().nullable()
36
- }).index("byThreadEvents", ["threadId"]), B = k("_voltro_comment_reactions", {
37
- id: w({ prefix: "cmtrx" }),
38
- commentId: A(),
39
- subjectId: A(),
40
- emoji: A()
9
+ var R = A("_voltro_comment_threads", {
10
+ id: T({ prefix: "cmtthr" }),
11
+ anchor: j(),
12
+ quote: D().nullable(),
13
+ kind: j().default("discussion"),
14
+ status: j().default("open"),
15
+ createdBy: j(),
16
+ createdAt: M().default("now"),
17
+ tenantId: j().nullable()
18
+ }).index("byThreadAnchor", ["anchor", "tenantId"]), z = A("_voltro_comments", {
19
+ id: T({ prefix: "cmt" }),
20
+ threadId: j(),
21
+ body: j(),
22
+ authorSubjectId: j(),
23
+ mentions: D(),
24
+ editedAt: M().nullable(),
25
+ createdAt: M().default("now"),
26
+ tenantId: j().nullable()
27
+ }).index("byCommentThread", ["threadId"]), B = A("_voltro_comment_thread_events", {
28
+ id: T({ prefix: "cmtevt" }),
29
+ threadId: j(),
30
+ fromStatus: j().nullable(),
31
+ toStatus: j(),
32
+ actor: j(),
33
+ reason: j().nullable(),
34
+ at: M().default("now"),
35
+ tenantId: j().nullable()
36
+ }).index("byThreadEvents", ["threadId"]), V = A("_voltro_comment_reactions", {
37
+ id: T({ prefix: "cmtrx" }),
38
+ commentId: j(),
39
+ subjectId: j(),
40
+ emoji: j()
41
41
  }).unique("byReactionIdentity", [
42
42
  "commentId",
43
43
  "subjectId",
44
44
  "emoji"
45
- ]).index("byReactionComment", ["commentId"]), V = k("_voltro_comment_reads", {
46
- id: w({ prefix: "cmtread" }),
47
- threadId: A(),
48
- subjectId: A(),
49
- lastReadAt: j()
50
- }).unique("byReadThreadSubject", ["threadId", "subjectId"]), H = s, U = (e) => {
45
+ ]).index("byReactionComment", ["commentId"]), H = A("_voltro_comment_reads", {
46
+ id: T({ prefix: "cmtread" }),
47
+ threadId: j(),
48
+ subjectId: j(),
49
+ lastReadAt: M()
50
+ }).unique("byReadThreadSubject", ["threadId", "subjectId"]), U = e, W = (e) => {
51
51
  let t = e.request.subject ?? {};
52
52
  return {
53
53
  id: t.id ?? null,
54
54
  tenantId: t.tenantId ?? null,
55
- scopes: N(t)
55
+ scopes: P(t)
56
56
  };
57
- }, W = (i = {}) => {
58
- let a = P({
59
- base: H,
60
- alias: i.alias,
61
- instance: i.name
62
- }), o, s, w = async (e, t, n) => o === void 0 ? [] : o.query({
57
+ }, G = (e = {}) => {
58
+ let g = F({
59
+ base: U,
60
+ alias: e.alias,
61
+ instance: e.name
62
+ }), _, v, T = async (e, t, n) => _ === void 0 ? [] : _.query({
63
63
  table: e,
64
64
  predicate: t,
65
65
  order: [],
66
66
  take: n,
67
67
  skip: void 0,
68
68
  projection: void 0
69
- }), E = async (e, t, n, r) => {
69
+ }), D = async (e, t, n, r) => {
70
70
  let i = [], a = [...new Set(n)];
71
71
  for (let n = 0; n < a.length; n += 500) {
72
- let o = T(t, a.slice(n, n + 500));
73
- i.push(...await w(e, r === void 0 ? o : b(o, r)));
72
+ let o = E(t, a.slice(n, n + 500));
73
+ i.push(...await T(e, r === void 0 ? o : x(o, r)));
74
74
  }
75
75
  return i;
76
- }, k = (e, t) => {
76
+ }, A = (e, t) => {
77
77
  let n = /* @__PURE__ */ new Map();
78
78
  for (let r of e) {
79
79
  let e = String(r[t]), i = n.get(e);
80
80
  i === void 0 ? n.set(e, [r]) : i.push(r);
81
81
  }
82
82
  return n;
83
- }, A = () => {
84
- F(s, l);
85
- }, j = (t, n) => v.gen(function* () {
86
- let r = U(n);
87
- return i.access?.viaEntity === void 0 ? i.access?.scope === void 0 ? yield* v.fail(new e({
83
+ }, j = () => {
84
+ I(v, n);
85
+ }, M = (t, n) => y.gen(function* () {
86
+ let r = W(n);
87
+ return e.access?.viaEntity === void 0 ? e.access?.scope === void 0 ? yield* y.fail(new f({
88
88
  anchor: t,
89
89
  reason: "no access rule declared — set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }"
90
- })) : r.scopes.includes(i.access.scope) ? void 0 : yield* v.fail(new e({
90
+ })) : r.scopes.includes(e.access.scope) ? void 0 : yield* y.fail(new f({
91
91
  anchor: t,
92
- reason: `missing scope '${i.access.scope}'`
93
- })) : (yield* v.promise(async () => {
92
+ reason: `missing scope '${e.access.scope}'`
93
+ })) : (yield* y.promise(async () => {
94
94
  try {
95
- return await i.access.viaEntity({
95
+ return await e.access.viaEntity({
96
96
  anchor: t,
97
97
  subject: r,
98
- store: o
98
+ store: _
99
99
  });
100
100
  } catch {
101
101
  return !1;
102
102
  }
103
- })) ? void 0 : yield* v.fail(new e({
103
+ })) ? void 0 : yield* y.fail(new f({
104
104
  anchor: t,
105
105
  reason: "the anchored entity is not readable by this caller (or no longer available)"
106
106
  }));
107
- }), N = async (e) => (await w("_voltro_comment_threads", S("id", e), 1))[0], W = (e) => ({
107
+ }), P = async (e) => (await T("_voltro_comment_threads", C("id", e), 1))[0], G = (e) => ({
108
108
  id: String(e.id),
109
109
  anchor: String(e.anchor),
110
- kind: c.includes(String(e.kind)) ? e.kind : "discussion",
110
+ kind: t.includes(String(e.kind)) ? e.kind : "discussion",
111
111
  status: e.status === "resolved" ? "resolved" : "open",
112
112
  createdBy: String(e.createdBy)
113
- }), G = (e, t) => i.visibleTo === void 0 || i.visibleTo({
114
- thread: W(e),
115
- subject: U(t)
116
- }), K = async (e, t) => {
117
- let n = await N(e);
118
- return n !== void 0 && G(n, t) ? n : void 0;
119
- }, q = async (e, t) => {
113
+ }), K = (t, n) => e.visibleTo === void 0 || e.visibleTo({
114
+ thread: G(t),
115
+ subject: W(n)
116
+ }), q = async (e, t) => {
117
+ let n = await P(e);
118
+ return n !== void 0 && K(n, t) ? n : void 0;
119
+ }, J = async (e, t) => {
120
120
  await e.insert("_voltro_comment_thread_events", {
121
- id: C({
121
+ id: w({
122
122
  kind: "typeid",
123
123
  prefix: "cmtevt"
124
124
  }, "_voltro_comment_thread_events"),
@@ -130,44 +130,44 @@ var L = k("_voltro_comment_threads", {
130
130
  at: (/* @__PURE__ */ new Date()).toISOString(),
131
131
  tenantId: t.tenantId
132
132
  });
133
- }, J = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : "", Y = (e) => v.gen(function* () {
134
- if (e.mentions.length === 0) return;
135
- let t = yield* v.serviceOption(I);
136
- if (y.isNone(t)) yield* v.logInfo("comments: mention recorded without notification — @voltro/plugin-notifications is not configured");
137
- else for (let n of e.mentions) n !== e.author && (yield* v.promise(() => t.value.send({
138
- to: n,
139
- category: i.mentionCategory ?? "mention",
133
+ }, Y = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" ? e : "", X = (t) => y.gen(function* () {
134
+ if (t.mentions.length === 0) return;
135
+ let n = yield* y.serviceOption(L);
136
+ if (b.isNone(n)) yield* y.logInfo("comments: mention recorded without notification — @voltro/plugin-notifications is not configured");
137
+ else for (let r of t.mentions) r !== t.author && (yield* y.promise(() => n.value.send({
138
+ to: r,
139
+ category: e.mentionCategory ?? "mention",
140
140
  title: "You were mentioned",
141
- body: e.body.length > 200 ? `${e.body.slice(0, 200)}…` : e.body,
141
+ body: t.body.length > 200 ? `${t.body.slice(0, 200)}…` : t.body,
142
142
  data: {
143
- anchor: e.anchor,
144
- threadId: e.threadId
143
+ anchor: t.anchor,
144
+ threadId: t.threadId
145
145
  },
146
- tenantId: e.tenantId
146
+ tenantId: t.tenantId
147
147
  }).then(() => void 0).catch(() => void 0)));
148
- }), X = async (e, t) => {
149
- if (e.length === 0 || i.resolveMentions === void 0) return [];
150
- let n = [];
151
- for (let r of [...new Set(e)].slice(0, 20)) {
152
- let e = (await i.resolveMentions({
153
- query: r,
154
- subject: t
155
- }).catch(() => [])).find((e) => e.subjectId === r);
156
- e !== void 0 && (i.crossTenant === !0 || e.tenantId === void 0 || e.tenantId === null || e.tenantId === t.tenantId) && n.push(r);
148
+ }), Z = async (t, n) => {
149
+ if (t.length === 0 || e.resolveMentions === void 0) return [];
150
+ let r = [];
151
+ for (let i of [...new Set(t)].slice(0, 20)) {
152
+ let t = (await e.resolveMentions({
153
+ query: i,
154
+ subject: n
155
+ }).catch(() => [])).find((e) => e.subjectId === i);
156
+ t !== void 0 && (e.crossTenant === !0 || t.tenantId === void 0 || t.tenantId === null || t.tenantId === n.tenantId) && r.push(i);
157
157
  }
158
- return n;
159
- }, Z = async (e, t) => {
160
- let { tenantId: n, id: r } = U(t), i = (await w("_voltro_comment_threads", b(S("anchor", e), S("tenantId", n)))).filter((e) => G(e, t));
158
+ return r;
159
+ }, Q = async (e, t) => {
160
+ let { tenantId: n, id: r } = W(t), i = (await T("_voltro_comment_threads", x(C("anchor", e), C("tenantId", n)))).filter((e) => K(e, t));
161
161
  if (i.length === 0) return [];
162
162
  let a = i.map((e) => String(e.id)), [o, s, c] = await Promise.all([
163
- E("_voltro_comments", "threadId", a),
164
- r === null ? Promise.resolve([]) : E("_voltro_comment_reads", "threadId", a, S("subjectId", r)),
165
- E("_voltro_comment_thread_events", "threadId", a)
166
- ]), l = k(o, "threadId"), u = k(s, "threadId"), d = k(c, "threadId"), f = k(await E("_voltro_comment_reactions", "commentId", o.map((e) => String(e.id))), "commentId"), p = [];
163
+ D("_voltro_comments", "threadId", a),
164
+ r === null ? Promise.resolve([]) : D("_voltro_comment_reads", "threadId", a, C("subjectId", r)),
165
+ D("_voltro_comment_thread_events", "threadId", a)
166
+ ]), l = A(o, "threadId"), u = A(s, "threadId"), d = A(c, "threadId"), f = A(await D("_voltro_comment_reactions", "commentId", o.map((e) => String(e.id))), "commentId"), p = [];
167
167
  for (let e of i) {
168
168
  let t = l.get(String(e.id)) ?? [];
169
- t.sort((e, t) => J(e.createdAt) < J(t.createdAt) ? -1 : 1);
170
- let n = u.get(String(e.id)) ?? [], i = n[0] ? J(n[0].lastReadAt) : "", a = [];
169
+ t.sort((e, t) => Y(e.createdAt) < Y(t.createdAt) ? -1 : 1);
170
+ let n = u.get(String(e.id)) ?? [], i = n[0] ? Y(n[0].lastReadAt) : "", a = [];
171
171
  for (let e of t) {
172
172
  let t = f.get(String(e.id)) ?? [], n = /* @__PURE__ */ new Map();
173
173
  for (let e of t) {
@@ -183,8 +183,8 @@ var L = k("_voltro_comment_threads", {
183
183
  body: String(e.body),
184
184
  authorSubjectId: String(e.authorSubjectId),
185
185
  mentions: e.mentions ?? [],
186
- editedAt: e.editedAt == null ? null : J(e.editedAt),
187
- createdAt: J(e.createdAt),
186
+ editedAt: e.editedAt == null ? null : Y(e.editedAt),
187
+ createdAt: Y(e.createdAt),
188
188
  reactions: [...n.entries()].map(([e, t]) => ({
189
189
  emoji: e,
190
190
  count: t.count,
@@ -193,8 +193,8 @@ var L = k("_voltro_comment_threads", {
193
193
  });
194
194
  }
195
195
  let o = d.get(String(e.id)) ?? [];
196
- o.sort((e, t) => J(e.at) < J(t.at) ? -1 : J(e.at) > J(t.at) ? 1 : String(e.id) < String(t.id) ? -1 : 1);
197
- let s = W(e);
196
+ o.sort((e, t) => Y(e.at) < Y(t.at) ? -1 : Y(e.at) > Y(t.at) ? 1 : String(e.id) < String(t.id) ? -1 : 1);
197
+ let s = G(e);
198
198
  p.push({
199
199
  id: s.id,
200
200
  anchor: s.anchor,
@@ -202,207 +202,207 @@ var L = k("_voltro_comment_threads", {
202
202
  quote: e.quote ?? null,
203
203
  status: s.status,
204
204
  createdBy: String(e.createdBy),
205
- createdAt: J(e.createdAt),
205
+ createdAt: Y(e.createdAt),
206
206
  comments: a,
207
207
  unreadCount: a.filter((e) => String(e.authorSubjectId) !== r && String(e.createdAt) > i).length,
208
208
  history: o.map((e) => ({
209
209
  from: e.fromStatus === "open" || e.fromStatus === "resolved" ? e.fromStatus : null,
210
210
  to: e.toStatus === "resolved" ? "resolved" : "open",
211
211
  by: String(e.actor),
212
- at: J(e.at),
212
+ at: Y(e.at),
213
213
  reason: e.reason == null ? null : String(e.reason)
214
214
  }))
215
215
  });
216
216
  }
217
217
  return p.sort((e, t) => String(e.createdAt) < String(t.createdAt) ? -1 : 1), p;
218
- }, Q = [
218
+ }, ee = [
219
219
  {
220
- ...m,
220
+ ...s,
221
221
  description: "Threads + comments + reactions + unread for one anchor, live.",
222
- execute: (e, t) => v.gen(function* () {
222
+ execute: (e, t) => y.gen(function* () {
223
223
  let { anchor: n } = e;
224
- return yield* j(n, t), yield* v.promise(() => Z(n, t));
224
+ return yield* M(n, t), yield* y.promise(() => Q(n, t));
225
225
  })
226
226
  },
227
227
  {
228
- ...d,
228
+ ...i,
229
229
  description: "Comment on an anchor — a reply into a thread, or a new thread.",
230
- execute: (n, r) => v.gen(function* () {
231
- let i = n;
232
- yield* j(i.anchor, r);
233
- let a = U(r), s = a.id ?? "anonymous", c = o;
234
- if (c === void 0) return yield* v.fail(new t({ id: i.anchor }));
235
- let l = i.threadId;
236
- if (l !== void 0) {
237
- let e = yield* v.promise(() => K(l, r));
238
- if (e === void 0 || String(e.anchor) !== i.anchor) return yield* v.fail(new t({ id: l }));
230
+ execute: (e, t) => y.gen(function* () {
231
+ let n = e;
232
+ yield* M(n.anchor, t);
233
+ let r = W(t), i = r.id ?? "anonymous", a = _;
234
+ if (a === void 0) return yield* y.fail(new p({ id: n.anchor }));
235
+ let o = n.threadId;
236
+ if (o !== void 0) {
237
+ let e = yield* y.promise(() => q(o, t));
238
+ if (e === void 0 || String(e.anchor) !== n.anchor) return yield* y.fail(new p({ id: o }));
239
239
  } else {
240
- let t = C({
240
+ let e = w({
241
241
  kind: "typeid",
242
242
  prefix: "cmtthr"
243
243
  }, "_voltro_comment_threads");
244
- l = t;
245
- let n = i.kind ?? "discussion";
246
- if (!G({
247
- id: t,
248
- anchor: i.anchor,
249
- kind: n,
244
+ o = e;
245
+ let s = n.kind ?? "discussion";
246
+ if (!K({
247
+ id: e,
248
+ anchor: n.anchor,
249
+ kind: s,
250
250
  status: "open",
251
- createdBy: s
252
- }, r)) return yield* v.fail(new e({
253
- anchor: i.anchor,
254
- reason: `a ${n} thread here would not be visible to its author`
251
+ createdBy: i
252
+ }, t)) return yield* y.fail(new f({
253
+ anchor: n.anchor,
254
+ reason: `a ${s} thread here would not be visible to its author`
255
255
  }));
256
- yield* v.promise(async () => {
257
- await c.insert("_voltro_comment_threads", {
258
- id: t,
259
- anchor: i.anchor,
260
- quote: i.quote ?? null,
261
- kind: n,
256
+ yield* y.promise(async () => {
257
+ await a.insert("_voltro_comment_threads", {
258
+ id: e,
259
+ anchor: n.anchor,
260
+ quote: n.quote ?? null,
261
+ kind: s,
262
262
  status: "open",
263
- createdBy: s,
263
+ createdBy: i,
264
264
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
265
- tenantId: a.tenantId
266
- }), await q(c, {
267
- threadId: t,
265
+ tenantId: r.tenantId
266
+ }), await J(a, {
267
+ threadId: e,
268
268
  from: null,
269
269
  to: "open",
270
- actor: s,
270
+ actor: i,
271
271
  reason: null,
272
- tenantId: a.tenantId
272
+ tenantId: r.tenantId
273
273
  });
274
274
  });
275
275
  }
276
- let u = yield* v.promise(() => X(i.mentions ?? [], a)), d = C({
276
+ let s = yield* y.promise(() => Z(n.mentions ?? [], r)), c = w({
277
277
  kind: "typeid",
278
278
  prefix: "cmt"
279
279
  }, "_voltro_comments");
280
- return yield* v.promise(() => c.insert("_voltro_comments", {
281
- id: d,
282
- threadId: l,
283
- body: i.body,
284
- authorSubjectId: s,
285
- mentions: u,
280
+ return yield* y.promise(() => a.insert("_voltro_comments", {
281
+ id: c,
282
+ threadId: o,
283
+ body: n.body,
284
+ authorSubjectId: i,
285
+ mentions: s,
286
286
  editedAt: null,
287
287
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
288
- tenantId: a.tenantId
289
- })), A(), yield* Y({
290
- mentions: u,
291
- author: s,
292
- anchor: i.anchor,
293
- threadId: l,
294
- body: i.body,
295
- tenantId: a.tenantId
288
+ tenantId: r.tenantId
289
+ })), j(), yield* X({
290
+ mentions: s,
291
+ author: i,
292
+ anchor: n.anchor,
293
+ threadId: o,
294
+ body: n.body,
295
+ tenantId: r.tenantId
296
296
  }), {
297
- threadId: l,
298
- commentId: d
297
+ threadId: o,
298
+ commentId: c
299
299
  };
300
300
  })
301
301
  },
302
302
  {
303
- ...p,
303
+ ...o,
304
304
  description: "Edit your own comment.",
305
- execute: (e, r) => v.gen(function* () {
306
- let i = e, a = (yield* v.promise(() => w("_voltro_comments", S("id", i.commentId), 1)))[0];
307
- if (a === void 0) return yield* v.fail(new t({ id: i.commentId }));
308
- let s = yield* v.promise(() => K(String(a.threadId), r));
309
- return s === void 0 ? yield* v.fail(new t({ id: i.commentId })) : (yield* j(String(s.anchor), r), String(a.authorSubjectId) === (U(r).id ?? "anonymous") ? (yield* v.promise(() => o.update("_voltro_comments", i.commentId, {
310
- body: i.body,
305
+ execute: (e, t) => y.gen(function* () {
306
+ let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
307
+ if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
308
+ let i = yield* y.promise(() => q(String(r.threadId), t));
309
+ return i === void 0 ? yield* y.fail(new p({ id: n.commentId })) : (yield* M(String(i.anchor), t), String(r.authorSubjectId) === (W(t).id ?? "anonymous") ? (yield* y.promise(() => _.update("_voltro_comments", n.commentId, {
310
+ body: n.body,
311
311
  editedAt: (/* @__PURE__ */ new Date()).toISOString()
312
- })), A(), { ok: !0 }) : yield* v.fail(new n({ id: i.commentId })));
312
+ })), j(), { ok: !0 }) : yield* y.fail(new m({ id: n.commentId })));
313
313
  })
314
314
  },
315
315
  {
316
- ...ee,
316
+ ...d,
317
317
  description: "Resolve or reopen a thread.",
318
- execute: (e, n) => v.gen(function* () {
319
- let a = e, s = yield* v.promise(() => K(a.threadId, n));
320
- if (s === void 0) return yield* v.fail(new t({ id: a.threadId }));
321
- yield* j(String(s.anchor), n);
322
- let c = W(s), l = a.resolved ? "resolved" : "open";
323
- if (c.status === l) return { ok: !0 };
324
- let u = U(n);
325
- if (i.statusPolicy !== void 0 && !(yield* v.promise(async () => {
318
+ execute: (t, n) => y.gen(function* () {
319
+ let r = t, i = yield* y.promise(() => q(r.threadId, n));
320
+ if (i === void 0) return yield* y.fail(new p({ id: r.threadId }));
321
+ yield* M(String(i.anchor), n);
322
+ let a = G(i), o = r.resolved ? "resolved" : "open";
323
+ if (a.status === o) return { ok: !0 };
324
+ let s = W(n);
325
+ if (e.statusPolicy !== void 0 && !(yield* y.promise(async () => {
326
326
  try {
327
- return await i.statusPolicy({
328
- thread: c,
329
- to: l,
330
- subject: u,
331
- store: o
327
+ return await e.statusPolicy({
328
+ thread: a,
329
+ to: o,
330
+ subject: s,
331
+ store: _
332
332
  });
333
333
  } catch {
334
334
  return !1;
335
335
  }
336
- }))) return yield* v.fail(new r({
337
- threadId: a.threadId,
338
- reason: `the status policy does not let this caller ${a.resolved ? "resolve" : "reopen"} this ${c.kind} thread`
336
+ }))) return yield* y.fail(new h({
337
+ threadId: r.threadId,
338
+ reason: `the status policy does not let this caller ${r.resolved ? "resolve" : "reopen"} this ${a.kind} thread`
339
339
  }));
340
- let d = a.reason?.trim() ? a.reason.trim() : null;
341
- return yield* v.promise(async () => {
342
- await o.update("_voltro_comment_threads", a.threadId, { status: l }), await q(o, {
343
- threadId: a.threadId,
344
- from: c.status,
345
- to: l,
346
- actor: u.id ?? "anonymous",
347
- reason: d,
348
- tenantId: u.tenantId
340
+ let c = r.reason?.trim() ? r.reason.trim() : null;
341
+ return yield* y.promise(async () => {
342
+ await _.update("_voltro_comment_threads", r.threadId, { status: o }), await J(_, {
343
+ threadId: r.threadId,
344
+ from: a.status,
345
+ to: o,
346
+ actor: s.id ?? "anonymous",
347
+ reason: c,
348
+ tenantId: s.tenantId
349
349
  });
350
- }), A(), { ok: !0 };
350
+ }), j(), { ok: !0 };
351
351
  })
352
352
  },
353
353
  {
354
- ...f,
354
+ ...a,
355
355
  description: "Delete your own comment (comments:moderate deletes any).",
356
- execute: (e, r) => v.gen(function* () {
357
- let i = e, a = (yield* v.promise(() => w("_voltro_comments", S("id", i.commentId), 1)))[0];
358
- if (a === void 0) return yield* v.fail(new t({ id: i.commentId }));
359
- let s = yield* v.promise(() => K(String(a.threadId), r));
360
- if (s === void 0) return yield* v.fail(new t({ id: i.commentId }));
361
- yield* j(String(s.anchor), r);
362
- let c = U(r);
363
- return String(a.authorSubjectId) !== (c.id ?? "anonymous") && !c.scopes.includes("comments:moderate") ? yield* v.fail(new n({ id: i.commentId })) : (yield* v.promise(async () => {
364
- for (let e of await w("_voltro_comment_reactions", S("commentId", i.commentId))) await o.delete("_voltro_comment_reactions", String(e.id));
365
- await o.delete("_voltro_comments", i.commentId);
366
- }), A(), { ok: !0 });
356
+ execute: (e, t) => y.gen(function* () {
357
+ let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
358
+ if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
359
+ let i = yield* y.promise(() => q(String(r.threadId), t));
360
+ if (i === void 0) return yield* y.fail(new p({ id: n.commentId }));
361
+ yield* M(String(i.anchor), t);
362
+ let a = W(t);
363
+ return String(r.authorSubjectId) !== (a.id ?? "anonymous") && !a.scopes.includes("comments:moderate") ? yield* y.fail(new m({ id: n.commentId })) : (yield* y.promise(async () => {
364
+ for (let e of await T("_voltro_comment_reactions", C("commentId", n.commentId))) await _.delete("_voltro_comment_reactions", String(e.id));
365
+ await _.delete("_voltro_comments", n.commentId);
366
+ }), j(), { ok: !0 });
367
367
  })
368
368
  },
369
369
  {
370
- ..._,
370
+ ...u,
371
371
  description: "Toggle an emoji reaction on a comment.",
372
- execute: (e, n) => v.gen(function* () {
373
- let r = e, i = (yield* v.promise(() => w("_voltro_comments", S("id", r.commentId), 1)))[0];
374
- if (i === void 0) return yield* v.fail(new t({ id: r.commentId }));
375
- let a = yield* v.promise(() => K(String(i.threadId), n));
376
- if (a === void 0) return yield* v.fail(new t({ id: r.commentId }));
377
- yield* j(String(a.anchor), n);
378
- let s = U(n).id ?? "anonymous", c = (yield* v.promise(() => w("_voltro_comment_reactions", b(S("commentId", r.commentId), b(S("subjectId", s), S("emoji", r.emoji))), 1)))[0];
379
- if (c !== void 0) return yield* v.promise(() => o.delete("_voltro_comment_reactions", String(c.id))), A(), { reacted: !1 };
380
- let l = C({
372
+ execute: (e, t) => y.gen(function* () {
373
+ let n = e, r = (yield* y.promise(() => T("_voltro_comments", C("id", n.commentId), 1)))[0];
374
+ if (r === void 0) return yield* y.fail(new p({ id: n.commentId }));
375
+ let i = yield* y.promise(() => q(String(r.threadId), t));
376
+ if (i === void 0) return yield* y.fail(new p({ id: n.commentId }));
377
+ yield* M(String(i.anchor), t);
378
+ let a = W(t).id ?? "anonymous", o = (yield* y.promise(() => T("_voltro_comment_reactions", x(C("commentId", n.commentId), x(C("subjectId", a), C("emoji", n.emoji))), 1)))[0];
379
+ if (o !== void 0) return yield* y.promise(() => _.delete("_voltro_comment_reactions", String(o.id))), j(), { reacted: !1 };
380
+ let s = w({
381
381
  kind: "typeid",
382
382
  prefix: "cmtrx"
383
383
  }, "_voltro_comment_reactions");
384
- return yield* v.promise(() => o.insert("_voltro_comment_reactions", {
385
- id: l,
386
- commentId: r.commentId,
387
- subjectId: s,
388
- emoji: r.emoji
389
- })), A(), { reacted: !0 };
384
+ return yield* y.promise(() => _.insert("_voltro_comment_reactions", {
385
+ id: s,
386
+ commentId: n.commentId,
387
+ subjectId: a,
388
+ emoji: n.emoji
389
+ })), j(), { reacted: !0 };
390
390
  })
391
391
  },
392
392
  {
393
- ...h,
393
+ ...c,
394
394
  description: "Stamp the caller's read marker for a thread.",
395
- execute: (e, n) => v.gen(function* () {
396
- let r = e;
397
- if ((yield* v.promise(() => N(r.threadId))) === void 0) return yield* v.fail(new t({ id: r.threadId }));
398
- let i = U(n).id ?? "anonymous", a = C({
395
+ execute: (e, t) => y.gen(function* () {
396
+ let n = e;
397
+ if ((yield* y.promise(() => P(n.threadId))) === void 0) return yield* y.fail(new p({ id: n.threadId }));
398
+ let r = W(t).id ?? "anonymous", i = w({
399
399
  kind: "typeid",
400
400
  prefix: "cmtread"
401
401
  }, "_voltro_comment_reads");
402
- return yield* v.promise(() => o.upsert("_voltro_comment_reads", {
403
- id: a,
404
- threadId: r.threadId,
405
- subjectId: i,
402
+ return yield* y.promise(() => _.upsert("_voltro_comment_reads", {
403
+ id: i,
404
+ threadId: n.threadId,
405
+ subjectId: r,
406
406
  lastReadAt: (/* @__PURE__ */ new Date()).toISOString()
407
407
  }, {
408
408
  conflictColumns: ["threadId", "subjectId"],
@@ -411,19 +411,19 @@ var L = k("_voltro_comment_threads", {
411
411
  })
412
412
  },
413
413
  {
414
- ...g,
414
+ ...l,
415
415
  description: "@-mention autocomplete over the app-declared directory, tenant-filtered.",
416
- execute: (e, t) => v.promise(async () => {
417
- let { query: n } = e;
418
- if (i.resolveMentions === void 0) return [];
419
- let r = U(t);
420
- return (await i.resolveMentions({
421
- query: n,
416
+ execute: (t, n) => y.promise(async () => {
417
+ let { query: r } = t;
418
+ if (e.resolveMentions === void 0) return [];
419
+ let i = W(n);
420
+ return (await e.resolveMentions({
421
+ query: r,
422
422
  subject: {
423
- id: r.id,
424
- tenantId: r.tenantId
423
+ id: i.id,
424
+ tenantId: i.tenantId
425
425
  }
426
- }).catch(() => [])).filter((e) => i.crossTenant === !0 || e.tenantId === void 0 || e.tenantId === null || e.tenantId === r.tenantId).map((e) => ({
426
+ }).catch(() => [])).filter((t) => e.crossTenant === !0 || t.tenantId === void 0 || t.tenantId === null || t.tenantId === i.tenantId).map((e) => ({
427
427
  subjectId: e.subjectId,
428
428
  label: e.label
429
429
  }));
@@ -433,29 +433,29 @@ var L = k("_voltro_comment_threads", {
433
433
  kind: "json",
434
434
  data: e
435
435
  });
436
- return M({
437
- name: a,
438
- baseName: H,
436
+ return N({
437
+ name: g,
438
+ baseName: U,
439
439
  description: "Comment threads on any app entity — replies, resolve/reopen, @-mentions with notifications, reactions, unread — live over the reactive engine.",
440
440
  permissions: ["inspect:read", "store:write"],
441
441
  extendSchema: { tables: [
442
- L,
443
- z,
444
442
  R,
445
443
  B,
446
- V
444
+ z,
445
+ V,
446
+ H
447
447
  ] },
448
- routes: Q,
449
- rpcClientDescriptors: u,
448
+ routes: ee,
449
+ rpcClientDescriptors: r,
450
450
  inspectEndpoints: [{
451
451
  method: "GET",
452
452
  path: "/threads",
453
453
  scope: "process",
454
454
  description: "Thread volume and searchable, paginated threads (operator surface).",
455
- handler: (e) => v.promise(async () => {
455
+ handler: (e) => y.promise(async () => {
456
456
  let t = new URL(e.url, "http://inspect.local").searchParams, n = t.get("threadId"), r = Number(t.get("offset") ?? 0), i = Number.isSafeInteger(r) && r >= 0 ? r : 0, a = (t.get("search") ?? "").trim().slice(0, 200);
457
457
  if (n) {
458
- let e = (await w("_voltro_comment_threads", S("id", n), 1))[0], t = S("threadId", n), [r, a] = e && o ? await Promise.all([o.query({
458
+ let e = (await T("_voltro_comment_threads", C("id", n), 1))[0], t = C("threadId", n), [r, a] = e && _ ? await Promise.all([_.query({
459
459
  table: "_voltro_comments",
460
460
  predicate: t,
461
461
  order: [{
@@ -468,7 +468,7 @@ var L = k("_voltro_comment_threads", {
468
468
  take: 50,
469
469
  skip: i,
470
470
  projection: void 0
471
- }), o.query({
471
+ }), _.query({
472
472
  table: "_voltro_comments",
473
473
  predicate: t,
474
474
  order: [],
@@ -479,32 +479,32 @@ var L = k("_voltro_comment_threads", {
479
479
  op: "count",
480
480
  alias: "count"
481
481
  }]
482
- })]) : [[], []], s = Number(a[0]?.count ?? 0);
482
+ })]) : [[], []], o = Number(a[0]?.count ?? 0);
483
483
  return $({
484
484
  stats: {
485
485
  threads: +!!e,
486
486
  open: e && e.status !== "resolved" ? 1 : 0,
487
- comments: s
487
+ comments: o
488
488
  },
489
489
  recent: [],
490
490
  detail: {
491
491
  threadId: n,
492
492
  found: !!e,
493
493
  offset: i,
494
- total: s,
494
+ total: o,
495
495
  messages: r.map((e) => ({
496
496
  id: String(e.id),
497
497
  body: String(e.body),
498
498
  author: String(e.authorSubjectId),
499
- createdAt: J(e.createdAt),
500
- editedAt: e.editedAt == null ? null : J(e.editedAt)
499
+ createdAt: Y(e.createdAt),
500
+ editedAt: e.editedAt == null ? null : Y(e.editedAt)
501
501
  }))
502
502
  }
503
503
  });
504
504
  }
505
- if (!o) throw Error("Comments store is not available");
506
- let s = async (e, t) => {
507
- let n = await o.query({
505
+ if (!_) throw Error("Comments store is not available");
506
+ let o = async (e, t) => {
507
+ let n = await _.query({
508
508
  table: e,
509
509
  predicate: t,
510
510
  order: [],
@@ -517,10 +517,10 @@ var L = k("_voltro_comment_threads", {
517
517
  }]
518
518
  });
519
519
  return Number(n[0]?.count ?? 0);
520
- }, c = a ? O(x("anchor", a), x("id", a), x("createdBy", a)) : void 0, [l, u, d, f, p] = await Promise.all([
521
- o.query({
520
+ }, s = a ? k(S("anchor", a), S("id", a), S("createdBy", a)) : void 0, [c, l, u, d, f] = await Promise.all([
521
+ _.query({
522
522
  table: "_voltro_comment_threads",
523
- predicate: c,
523
+ predicate: s,
524
524
  order: [{
525
525
  column: "createdAt",
526
526
  direction: "desc"
@@ -532,13 +532,13 @@ var L = k("_voltro_comment_threads", {
532
532
  skip: i,
533
533
  projection: void 0
534
534
  }),
535
- s("_voltro_comment_threads"),
536
- s("_voltro_comment_threads", D("status", "resolved")),
537
- s("_voltro_comments"),
538
- s("_voltro_comment_threads", c)
539
- ]), m = l.length === 0 ? [] : await o.query({
535
+ o("_voltro_comment_threads"),
536
+ o("_voltro_comment_threads", O("status", "resolved")),
537
+ o("_voltro_comments"),
538
+ o("_voltro_comment_threads", s)
539
+ ]), p = c.length === 0 ? [] : await _.query({
540
540
  table: "_voltro_comments",
541
- predicate: T("threadId", l.map((e) => String(e.id))),
541
+ predicate: E("threadId", c.map((e) => String(e.id))),
542
542
  order: [],
543
543
  take: void 0,
544
544
  skip: void 0,
@@ -552,41 +552,41 @@ var L = k("_voltro_comment_threads", {
552
552
  alias: "count"
553
553
  }],
554
554
  groupBy: ["threadId"]
555
- }), h = new Map(m.map((e) => [String(e.threadId), Number(e.count)]));
555
+ }), m = new Map(p.map((e) => [String(e.threadId), Number(e.count)]));
556
556
  return $({
557
557
  stats: {
558
- threads: u,
559
- open: d,
560
- comments: f
558
+ threads: l,
559
+ open: u,
560
+ comments: d
561
561
  },
562
562
  page: {
563
563
  offset: i,
564
564
  search: a,
565
- total: p,
565
+ total: f,
566
566
  pageSize: 50
567
567
  },
568
- recent: l.map((e) => ({
568
+ recent: c.map((e) => ({
569
569
  id: String(e.id),
570
570
  anchor: String(e.anchor),
571
571
  status: String(e.status),
572
572
  createdBy: String(e.createdBy),
573
- createdAt: J(e.createdAt),
574
- comments: h.get(String(e.id)) ?? 0
573
+ createdAt: Y(e.createdAt),
574
+ comments: m.get(String(e.id)) ?? 0
575
575
  }))
576
576
  });
577
577
  })
578
578
  }],
579
579
  bindDataStore: (e) => {
580
- o = e, s = e;
580
+ _ = e, v = e;
581
581
  },
582
- onActivate: (e) => v.sync(() => {
583
- i.access?.viaEntity === void 0 && i.access?.scope === void 0 && e.logger.warn("comments: no access rule declared — EVERY read and write will be refused (fail-closed). Set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }."), e.logger.info("comments active", { mentions: i.resolveMentions !== void 0 });
582
+ onActivate: (t) => y.sync(() => {
583
+ e.access?.viaEntity === void 0 && e.access?.scope === void 0 && t.logger.warn("comments: no access rule declared — EVERY read and write will be refused (fail-closed). Set commentsPlugin({ access: { viaEntity } }) or { access: { scope } }."), t.logger.info("comments active", { mentions: e.resolveMentions !== void 0 });
584
584
  }),
585
- onDeactivate: () => v.sync(() => {
586
- o = void 0, s = void 0;
585
+ onDeactivate: () => y.sync(() => {
586
+ _ = void 0, v = void 0;
587
587
  })
588
588
  });
589
- }, G = async (e, t, n = /* @__PURE__ */ new Date()) => {
589
+ }, K = async (e, t, n = /* @__PURE__ */ new Date()) => {
590
590
  let r = (t, n) => e.query({
591
591
  table: t,
592
592
  predicate: n,
@@ -598,20 +598,20 @@ var L = k("_voltro_comment_threads", {
598
598
  for (let [o, s] of Object.entries(t)) {
599
599
  if (s === void 0 || !(s >= 0)) continue;
600
600
  let t = n.getTime() - s * 864e5;
601
- for (let c of await r("_voltro_comment_threads", b(S("status", "resolved"), S("kind", o)))) {
602
- let o = [...await r("_voltro_comment_thread_events", S("threadId", String(c.id)))], l = (e) => new Date(e.at instanceof Date ? e.at : String(e.at)).getTime();
601
+ for (let c of await r("_voltro_comment_threads", x(C("status", "resolved"), C("kind", o)))) {
602
+ let o = [...await r("_voltro_comment_thread_events", C("threadId", String(c.id)))], l = (e) => new Date(e.at instanceof Date ? e.at : String(e.at)).getTime();
603
603
  o.sort((e, t) => l(e) - l(t));
604
604
  let u = [...o].reverse().find((e) => e.toStatus === "resolved" && e.fromStatus === "open");
605
605
  if (u === void 0 || l(u) > t) continue;
606
- let d = await r("_voltro_comments", S("threadId", String(c.id)));
606
+ let d = await r("_voltro_comments", C("threadId", String(c.id)));
607
607
  if (d.length !== 0) {
608
608
  for (let t of d) {
609
- for (let n of await r("_voltro_comment_reactions", S("commentId", String(t.id)))) await e.delete("_voltro_comment_reactions", String(n.id));
609
+ for (let n of await r("_voltro_comment_reactions", C("commentId", String(t.id)))) await e.delete("_voltro_comment_reactions", String(n.id));
610
610
  await e.delete("_voltro_comments", String(t.id));
611
611
  }
612
- for (let t of await r("_voltro_comment_reads", S("threadId", String(c.id)))) await e.delete("_voltro_comment_reads", String(t.id));
612
+ for (let t of await r("_voltro_comment_reads", C("threadId", String(c.id)))) await e.delete("_voltro_comment_reads", String(t.id));
613
613
  await e.insert("_voltro_comment_thread_events", {
614
- id: C({
614
+ id: w({
615
615
  kind: "typeid",
616
616
  prefix: "cmtevt"
617
617
  }, "_voltro_comment_thread_events"),
@@ -630,5 +630,5 @@ var L = k("_voltro_comment_threads", {
630
630
  threads: i,
631
631
  comments: a
632
632
  };
633
- }, K = () => "plugin-comments";
634
- export { c as COMMENT_THREAD_KINDS, e as CommentAccessRefused, t as CommentNotFound, n as CommentNotYours, r as CommentStatusRefused, i as QUOTE_MAX_LENGTH, G as applyCommentRetention, B as commentReactionsTable, V as commentReadsTable, z as commentThreadEventsTable, L as commentThreadsTable, l as commentsFeed, W as commentsPlugin, R as commentsTable, a as findQuote, K as pluginComments, o as textQuote };
633
+ }, q = () => "plugin-comments";
634
+ export { t as COMMENT_THREAD_KINDS, f as CommentAccessRefused, p as CommentNotFound, m as CommentNotYours, h as CommentStatusRefused, g as QUOTE_MAX_LENGTH, K as applyCommentRetention, V as commentReactionsTable, H as commentReadsTable, B as commentThreadEventsTable, R as commentThreadsTable, n as commentsFeed, G as commentsPlugin, z as commentsTable, _ as findQuote, q as pluginComments, v as textQuote };
package/dist/web.js CHANGED
@@ -1,9 +1,9 @@
1
- import { QUOTE_MAX_LENGTH as e, findQuote as t, textQuote as n } from "./quote.js";
2
- import { BASE_NAME as r, COMMENT_THREAD_KINDS as i } from "./rpc.js";
1
+ import { BASE_NAME as e, COMMENT_THREAD_KINDS as t } from "./rpc.js";
2
+ import { QUOTE_MAX_LENGTH as n, findQuote as r, textQuote as i } from "./quote.js";
3
3
  import { pluginTag as a } from "@voltro/protocol";
4
4
  import { useMutation as o, useSubscription as s } from "@voltro/client";
5
5
  // src/web.ts
6
- var c = (e) => a(r, e), l = (e, t = "app") => {
6
+ var c = (t) => a(e, t), l = (e, t = "app") => {
7
7
  let { data: n, loading: r } = s(t, c("list"), { anchor: e }), i = o(t, c("create")), a = o(t, c("edit")), l = o(t, c("resolve")), u = o(t, c("delete")), d = o(t, c("react")), f = o(t, c("markRead")), p = n ?? [];
8
8
  return {
9
9
  threads: p,
@@ -37,4 +37,4 @@ var c = (e) => a(r, e), l = (e, t = "app") => {
37
37
  let { data: n } = s(t, c("mentionSearch"), { query: e });
38
38
  return n ?? [];
39
39
  };
40
- export { i as COMMENT_THREAD_KINDS, e as QUOTE_MAX_LENGTH, t as findQuote, n as textQuote, l as useComments, d as useMentionSearch, u as useThread };
40
+ export { t as COMMENT_THREAD_KINDS, n as QUOTE_MAX_LENGTH, r as findQuote, i as textQuote, l as useComments, d as useMentionSearch, u as useThread };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voltro/plugin-comments",
3
- "version": "0.90.0",
3
+ "version": "0.91.1",
4
4
  "description": "Comment threads on any anchor your app can name — replies, resolve/reopen, reactions, per-subject unread — live over the existing reactivity channel, with no second push mechanism. Access delegates to your app's own guard (access.viaEntity) or a scope and fails closed when neither is declared; @-mentions are re-filtered to the caller's tenant on search and re-validated at create, then delivered through plugin-notifications when it is installed. useComments / useThread / useMentionSearch in /web, an ejectable <CommentsThread> in @voltro/ui, plus inspect endpoints and a dashboard panel.",
5
5
  "keywords": [
6
6
  "voltro",
@@ -48,13 +48,13 @@
48
48
  "node": ">=24.0.0"
49
49
  },
50
50
  "dependencies": {
51
- "@voltro/client": "0.90.0",
52
- "@voltro/database": "0.90.0",
53
- "@voltro/plugin-notifications": "0.90.0",
54
- "@voltro/protocol": "0.90.0"
51
+ "@voltro/client": "0.91.1",
52
+ "@voltro/database": "0.91.1",
53
+ "@voltro/plugin-notifications": "0.91.1",
54
+ "@voltro/protocol": "0.91.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "effect": "4.1.2",
57
+ "effect": "4.1.4",
58
58
  "react": "^19.0.0"
59
59
  },
60
60
  "publishConfig": {