critiqs-react 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT_SETUP.md +322 -0
- package/LICENSE +21 -0
- package/README.md +524 -2
- package/bin/critiqs.mjs +6 -0
- package/dist/Critiqs.d.ts +9 -0
- package/dist/constants.d.ts +4 -0
- package/dist/core/types.d.ts +72 -0
- package/dist/host.d.ts +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +20183 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +1 -0
- package/package.json +78 -4
package/README.md
CHANGED
|
@@ -1,3 +1,525 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Critiqs for React
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Reviewers comment directly on a running prototype, discuss feedback, and find
|
|
4
|
+
its original context as the prototype changes. Critiqs brings its own toolbar,
|
|
5
|
+
sidebar, sign-in, and styles. It works in any React 18 or 19 app: Vite, Create
|
|
6
|
+
React App, Next.js (App Router or Pages Router), Remix, or your own setup.
|
|
7
|
+
React and React DOM are peer dependencies; nothing else is required.
|
|
8
|
+
|
|
9
|
+
The browser package and setup CLI support Node.js 20 or later. The optional
|
|
10
|
+
`critiqs-react/server` SQLite server needs Node.js 22.13 or later, or Bun;
|
|
11
|
+
Node.js 20 does not include the built-in SQLite module.
|
|
12
|
+
|
|
13
|
+
## Set up in two commands
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install critiqs-react # or: pnpm add, yarn add, bun add
|
|
17
|
+
npx critiqs-react init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`npx critiqs-react init` runs Critiqs's setup command, `critiqs`, from the
|
|
21
|
+
shared `critiqs` package that `critiqs-react` installs (`npx critiqs init` is
|
|
22
|
+
the same command). It adds `<Critiqs />` where your app renders, signs you in through
|
|
23
|
+
your browser, creates a project on Critiqs Cloud, and connects the app to it.
|
|
24
|
+
Critiqs Cloud runs storage, sign-in, and email, so there are no keys to enter.
|
|
25
|
+
The project ID is public configuration, not a secret; reviewers never see or
|
|
26
|
+
enter it.
|
|
27
|
+
|
|
28
|
+
The result is one import and one component. In a Vite or Next.js app, the
|
|
29
|
+
component reads the project ID from the app's public environment variable, and
|
|
30
|
+
init sets that variable in `.env.local` on your computer:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { Critiqs } from "critiqs-react";
|
|
34
|
+
|
|
35
|
+
<Critiqs projectId={import.meta.env.VITE_CRITIQS_PROJECT_ID} requireProjectId />
|
|
36
|
+
// Next.js: projectId={process.env.NEXT_PUBLIC_CRITIQS_PROJECT_ID}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
# .env.local (this computer only; init adds an empty entry to .env.example)
|
|
41
|
+
VITE_CRITIQS_PROJECT_ID=<project ID>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
With `requireProjectId`, Critiqs appears only where the variable holds a
|
|
45
|
+
valid project ID: a copy built without it adds nothing to the page and
|
|
46
|
+
contacts no backend. In other builds, init writes the ID into the component
|
|
47
|
+
instead (`<Critiqs projectId="<project ID>" />`), and every copy shares that
|
|
48
|
+
project.
|
|
49
|
+
|
|
50
|
+
Init finishes with where setup stands: the code, the project, trying it
|
|
51
|
+
locally, deployments, and what reviewers on other computers still need. Then:
|
|
52
|
+
|
|
53
|
+
1. Start (or restart) your dev server, open the prototype, and sign in from
|
|
54
|
+
the Critiqs toolbar to leave a comment.
|
|
55
|
+
2. Commit the code change (not `.env.local`). In each deployment that should
|
|
56
|
+
show Critiqs, set the variable in its build settings, and record the
|
|
57
|
+
deployed address, including any path such as `/my-prototype/`, so mention
|
|
58
|
+
emails from every copy open it:
|
|
59
|
+
`npx critiqs-react init --review-url https://<deployed address>`.
|
|
60
|
+
3. `npx critiqs-react doctor` checks the setup at any time.
|
|
61
|
+
|
|
62
|
+
### Each app and deployment chooses its project
|
|
63
|
+
|
|
64
|
+
The project ID is an environment setting, so the same commit can be deployed
|
|
65
|
+
from different branches or environments with different projects, or with
|
|
66
|
+
none:
|
|
67
|
+
|
|
68
|
+
| Deployment | Setting | Result |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| Your computer | `.env.local`, written by init | Your project |
|
|
71
|
+
| A preview or staging deployment | `VITE_CRITIQS_PROJECT_ID=<staging project>` in its build settings | Its own feedback |
|
|
72
|
+
| Production for customers | unset | No Critiqs at all |
|
|
73
|
+
| Another deployment that shares feedback | the same ID | Shared feedback |
|
|
74
|
+
|
|
75
|
+
- **Built in, not read at run time.** Vite and Next.js copy `VITE_…` and
|
|
76
|
+
`NEXT_PUBLIC_…` values into the browser build when the app is built, so set
|
|
77
|
+
them in each deployment's build settings and rebuild after changing one.
|
|
78
|
+
Production-mode builds work the same way; Critiqs doesn't look at
|
|
79
|
+
`NODE_ENV`. If you build once and promote the same files through several
|
|
80
|
+
environments, read the ID from your own runtime configuration and pass it
|
|
81
|
+
to `projectId` yourself, keeping `requireProjectId`.
|
|
82
|
+
- **Wrong or unreachable settings stay out of sight.** A value that isn't a
|
|
83
|
+
project ID, a project the backend doesn't know, or a backend that can't be
|
|
84
|
+
reached shows visitors nothing; the browser console says what's wrong, and
|
|
85
|
+
`npx critiqs-react doctor` checks this computer's setting against the
|
|
86
|
+
backend. Doctor can't see a deployment's build settings.
|
|
87
|
+
- **Nothing is remembered in the browser.** With `requireProjectId`, Critiqs
|
|
88
|
+
never falls back to a project set up in the sidebar, so two apps on one site
|
|
89
|
+
(say `/` and `/admin/`) can't pick up each other's project.
|
|
90
|
+
- **Other builds.** Any React app can do the same by hand: pass its own public
|
|
91
|
+
setting as `projectId` and add `requireProjectId`. Without
|
|
92
|
+
`requireProjectId`, a component with no project ID shows project setup in its
|
|
93
|
+
sidebar, as before.
|
|
94
|
+
|
|
95
|
+
### Monorepos: one project per app
|
|
96
|
+
|
|
97
|
+
In a workspace (npm, Yarn, pnpm, or Bun), run init once for each app with
|
|
98
|
+
`--dir`. Each app gets its own project and its own variable, named after the
|
|
99
|
+
app (`VITE_CRITIQS_PROJECT_ID_ADMIN`, `NEXT_PUBLIC_CRITIQS_PROJECT_ID_WEB`),
|
|
100
|
+
so a value shared by the whole workspace, such as a root `.env` or one build
|
|
101
|
+
job that builds every app, can't connect them all to one project. Projects are
|
|
102
|
+
named after the workspace and the app (`acme/admin`), and an app whose package
|
|
103
|
+
name another workspace package shares is named by its path.
|
|
104
|
+
Names that become the same environment-variable name (such as `a-b` and
|
|
105
|
+
`a_b`) receive a stable suffix from the app's path, so shared environment
|
|
106
|
+
files keep separate project settings.
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
npx critiqs-react init --dir apps/admin
|
|
110
|
+
npx critiqs-react init --dir apps/web
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Run at the workspace root, init lists the apps and these commands and changes
|
|
114
|
+
nothing (at a terminal, it asks which app). Init writes only the chosen app's
|
|
115
|
+
files: its entry, and the `.env.local` and `.env.example` it loads. A Vite app
|
|
116
|
+
whose config sets `envDir` to a literal path or `resolve(__dirname, "…")`
|
|
117
|
+
gets its setting in that folder; for anything else, name the file with
|
|
118
|
+
`--project-env-file`, and pass the same option to `doctor` when checking it. Init adds
|
|
119
|
+
Critiqs to the app's entry, where it calls
|
|
120
|
+
`createRoot`, so another app that imports this app's components doesn't bring
|
|
121
|
+
its Critiqs along.
|
|
122
|
+
|
|
123
|
+
### Where init adds Critiqs
|
|
124
|
+
|
|
125
|
+
| App | Where | You can also add it yourself |
|
|
126
|
+
| --- | --- | --- |
|
|
127
|
+
| Vite, Create React App, and other single-page apps | beside `<App />` in the file that calls `createRoot(…).render(…)` or `ReactDOM.render(…)` | `root.render(<><App /><Critiqs /></>)` |
|
|
128
|
+
| Next.js App Router | inside `<body>` in `app/layout.tsx`. The layout stays a server component: the package marks `<Critiqs />` as a client component | `<body>{children}<Critiqs /></body>` |
|
|
129
|
+
| Next.js Pages Router | beside `<Component {...pageProps} />` in `pages/_app.tsx` | `<><Component {...pageProps} /><Critiqs /></>` |
|
|
130
|
+
| Server-rendered apps (`hydrateRoot`), Remix, and others | beside the element `hydrateRoot` receives, or the component every page renders | `<Critiqs />` renders nothing on the server, so hydration is unaffected |
|
|
131
|
+
| Anything else | name the file and element: `npx critiqs-react init --entry src/Shell.tsx --mount Outlet` | |
|
|
132
|
+
|
|
133
|
+
Init edits one source file, and only when it can tell exactly where: it
|
|
134
|
+
previews the change with `--dry-run`, and it refuses, changing nothing, when
|
|
135
|
+
there are several roots, when Critiqs is already loaded another way
|
|
136
|
+
(re-exported, as a namespace, or at run time), or when the name `Critiqs`
|
|
137
|
+
means something else there. It then prints the line to add by hand. A
|
|
138
|
+
`<Critiqs />` imported under another name is updated like any other. It checks
|
|
139
|
+
the source and `.env` files can be written before you sign in. Running init
|
|
140
|
+
again keeps the project the code already names, through a literal ID or the
|
|
141
|
+
variable's value in your `.env` files; a missing or malformed value doesn't
|
|
142
|
+
count, so init connects one. It keeps your other `.env` lines and values, a
|
|
143
|
+
component's other properties, and wiring you wrote yourself
|
|
144
|
+
(`projectId={import.meta.env.VITE_MY_PROJECT}` is set as it is; other code is
|
|
145
|
+
left alone). A retry after an interrupted run reuses your project with the
|
|
146
|
+
same name rather than creating another. `--new-project` creates a new one.
|
|
147
|
+
|
|
148
|
+
### Signing in from another device
|
|
149
|
+
|
|
150
|
+
On a remote machine, in a container, or with a coding agent, there may be no
|
|
151
|
+
browser to open. `npx critiqs-react init --remote` (automatic over SSH or without a
|
|
152
|
+
desktop) prints an address and a short code instead:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
Approve this setup from a browser on any device:
|
|
156
|
+
1. Open https://<sign-in service>/auth/device
|
|
157
|
+
2. Enter the code BCDF-GHJK
|
|
158
|
+
3. Sign in with your email and choose Approve.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Setup waits while you approve on your phone or laptop. The code works for 10
|
|
162
|
+
minutes and once; setup receives a 15-minute access token, only to create or
|
|
163
|
+
connect the project, and no lasting session. If the sign-in service doesn't
|
|
164
|
+
offer this yet, init says so: run it where a browser can open, or create the
|
|
165
|
+
project in the matching prototype's Critiqs sidebar and set its public
|
|
166
|
+
`projectId` on the existing component, keeping its `backend` property.
|
|
167
|
+
|
|
168
|
+
### If something goes wrong
|
|
169
|
+
|
|
170
|
+
| Message | What to do |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| Init didn't find where the app renders | Run with `--entry <file>` (and `--mount <Element>`), or add `<Critiqs />` by hand and run `npx critiqs-react init` again. |
|
|
173
|
+
| Found several places the app could render Critiqs | Choose one with `--entry`; in a monorepo, run init in the app's folder or pass `--dir`. |
|
|
174
|
+
| … is a workspace with 2 apps | Run one of the printed `init --dir <app>` commands for each app. |
|
|
175
|
+
| Sets projectId from code | Init doesn't edit computed values. Set the printed ID where your code reads it. |
|
|
176
|
+
| Sets envDir in a way init can't follow | Pass `--project-env-file <the .env.local file Vite loads>`, relative to the app. |
|
|
177
|
+
| Sets envPrefix | Give `<Critiqs />` `projectId={import.meta.env.<a name with your prefix>} requireProjectId`, then run init again. |
|
|
178
|
+
| Couldn't write `.env.local` after the project was created | Add the printed `NAME=<project ID>` line to that file yourself; the project and component are already in place. |
|
|
179
|
+
| Sign-in took too long, or Setup was denied | Run init again; nothing was created. |
|
|
180
|
+
| Source became unreadable or unwritable during setup | The result keeps the created project ID and backend. Restore file access and apply the complete component snippet shown, at the indicated entry/mount, and the `.env` line it names. Preserve its backend and update an existing component rather than adding another. |
|
|
181
|
+
| The code already uses project … | Nothing was changed. Use `--new-project` to replace it, or `--review-url` to set its review address. |
|
|
182
|
+
| No review address, or one that only opens on this computer or a private network (such as Tailscale) | If reviewers use a deployed copy, run `npx critiqs-react init --review-url https://<deployed address>`, or change it in the Critiqs sidebar's Project setup. |
|
|
183
|
+
| Critiqs Cloud isn't ready for this version | The hosted service runs an older backend; wait for it, or use your own Convex deployment. |
|
|
184
|
+
|
|
185
|
+
`npx critiqs-react doctor` checks the component, the backend and its version,
|
|
186
|
+
sign-in, the project, its review address, and email. Each check says whether
|
|
187
|
+
it read configuration or something the backend has actually done; doctor never
|
|
188
|
+
sends an email, uploads a screenshot, or posts a comment, so the first real
|
|
189
|
+
comment is what proves those work. AI is optional and doctor reports it as
|
|
190
|
+
information. `--json` prints init's and doctor's results for scripts and coding
|
|
191
|
+
agents. Coding agents can follow [AGENT_SETUP.md](../critiqs/AGENT_SETUP.md); an optional
|
|
192
|
+
MCP server (`npx critiqs-react mcp`) offers the same steps.
|
|
193
|
+
|
|
194
|
+
Coding agents can also read a project's feedback with its context, to act on
|
|
195
|
+
it: run `npx critiqs-react sign-in` once on the computer (or let the agent call
|
|
196
|
+
`critiqs_sign_in`), then the MCP server's `critiqs_comments`, `critiqs_thread`,
|
|
197
|
+
and `critiqs_screenshot` tools read threads, filtered by status, author, time,
|
|
198
|
+
tag, screen, or text, and `critiqs_reply` posts a reply as you, marked "via
|
|
199
|
+
coding agent", to ask people to check a fix. `critiqs_mockups` and
|
|
200
|
+
`critiqs_mockup` read mockups: each change Critiqs AI made to a page copy,
|
|
201
|
+
with the original element's markup and `data-critiqs-id` to find it in the
|
|
202
|
+
code, and the discussion behind it. The sign-in lasts until `npx critiqs-react sign-out`, 30
|
|
203
|
+
days without use, or 90 days. It is sent only to the backends it was approved
|
|
204
|
+
for, and to where each serves screenshots and page copies; the approval page
|
|
205
|
+
names them. For a backend other than Critiqs Cloud, sign in with
|
|
206
|
+
`npx critiqs-react sign-in --backend '<origin>'`, which needs that backend's
|
|
207
|
+
sign-in service to run the current Critiqs backend. A version of this package
|
|
208
|
+
from before this change, on the same computer, asks to sign in again. See [AGENT_SETUP.md](../critiqs/AGENT_SETUP.md#7-reading-feedback).
|
|
209
|
+
|
|
210
|
+
### Keeping feedback on your own backend
|
|
211
|
+
|
|
212
|
+
Critiqs Cloud is the default. To keep feedback on your team's own Convex
|
|
213
|
+
deployment instead, run `npx critiqs-react init --own-convex`: it deploys
|
|
214
|
+
Critiqs's functions there and asks only for a production Convex deploy key
|
|
215
|
+
(`CONVEX_DEPLOY_KEY`), plus a Resend key if you want mention emails, then also
|
|
216
|
+
writes `backend="https://<deployment>.convex.cloud"`. `--backend <url>` uses a
|
|
217
|
+
Critiqs backend that is already deployed. To run Critiqs inside your own Node or
|
|
218
|
+
Bun server instead, see [self-hosting](#self-hosting-inside-your-apps-server).
|
|
219
|
+
|
|
220
|
+
## Optional: more context for feedback
|
|
221
|
+
|
|
222
|
+
Optional properties record the prototype version and let the host app report
|
|
223
|
+
and restore context: `version`, `getContext`, and `restoreContext`. The package
|
|
224
|
+
exports their TypeScript types: `CritiqsProps`, `HostContext`, `RestoreRequest`,
|
|
225
|
+
`Scope`, and `ViewState`. Elements marked `data-critiqs-mask` are covered in captures.
|
|
226
|
+
For canvas, video or iframe content, mark a containing element: directly marked
|
|
227
|
+
media fail automatic capture safely because the renderer replaces their nodes
|
|
228
|
+
without retaining the privacy marker. The comment still saves with the reason.
|
|
229
|
+
|
|
230
|
+
Opening a thread from the list or a link, or choosing **Show in prototype**,
|
|
231
|
+
shows its target in the screen and view state where it was left. Unless that
|
|
232
|
+
view is already shown, Critiqs calls `restoreContext`, then waits up to three
|
|
233
|
+
seconds for `getContext` to report the thread's screen and view state and for
|
|
234
|
+
the target to appear; a matching element in another view doesn't count. Return
|
|
235
|
+
a promise to wait for slower content first, or `false` to decline, for example
|
|
236
|
+
to keep unsaved work. Report each key whenever its part of the app is shown,
|
|
237
|
+
with null when nothing is open; once `restoreContext` has run, a key an older
|
|
238
|
+
thread lacks is left to it. Report only state that `restoreContext` can set again;
|
|
239
|
+
if it keeps the current record for shared feedback, keep that record's ID out
|
|
240
|
+
of the view state.
|
|
241
|
+
Captures leave out every mounted Critiqs, including its pins and windows.
|
|
242
|
+
|
|
243
|
+
## Tags, search, and AI
|
|
244
|
+
|
|
245
|
+
Reviewers tag threads with the project's tags or by writing hashtags such as
|
|
246
|
+
`#wording` in comments; typing `#` suggests the project's tags. The project's
|
|
247
|
+
owner gathers related tags into shared groups (the Tags and AI button in the
|
|
248
|
+
sidebar), which everyone can filter by. The sidebar's search field finds
|
|
249
|
+
threads by words and `#tags`.
|
|
250
|
+
|
|
251
|
+
With AI, new tags are grouped automatically, searches can be plain questions,
|
|
252
|
+
and results come with insights that cite their threads. A project uses
|
|
253
|
+
Critiqs-managed AI where the deployment offers it, or its owner connects the
|
|
254
|
+
project's own OpenAI, Anthropic, Google Gemini, OpenRouter, Vercel AI
|
|
255
|
+
Gateway, or OpenAI-compatible provider in the same dialog, in three steps:
|
|
256
|
+
the provider, the key, and the models to offer, from the provider's list or
|
|
257
|
+
typed by name. Critiqs AI may offer several models, each costing its credits
|
|
258
|
+
per request; the owner picks the project's model and which models it allows. In Mockup mode, a **Model**
|
|
259
|
+
menu beside Send chooses among the models a person's AI offers, when there
|
|
260
|
+
are several.
|
|
261
|
+
|
|
262
|
+
Everyone has Critiqs AI where the deployment offers it, with nothing to set
|
|
263
|
+
up. **Your AI** in the avatar menu chooses its model by name, shows the
|
|
264
|
+
credits used against the plan with **Upgrade** where the deployment names an
|
|
265
|
+
upgrade page, and sets up the person's own API key in three steps instead. The
|
|
266
|
+
owner's **Who pays** decides which one the requests people start use:
|
|
267
|
+
**Project pays, personal allowed** (the default: the project pays unless
|
|
268
|
+
someone chooses their own), **Project pays**, or **Each person pays** (Critiqs
|
|
269
|
+
AI on each person's own plan, or their own key). Automatic grouping always
|
|
270
|
+
uses the project's AI. Your AI is offered on backends that keep it.
|
|
271
|
+
|
|
272
|
+
Keys go to the backend once, are stored encrypted, and never return to
|
|
273
|
+
browsers. AI is optional: without
|
|
274
|
+
it, commenting, replies, mentions, and tags work as usual, search is labeled
|
|
275
|
+
basic, and grouping is manual. Nobody installing the component is asked for an
|
|
276
|
+
AI key.
|
|
277
|
+
|
|
278
|
+
On your own Convex deployment, set `CRITIQS_AI_ENCRYPTION_KEY` (32 or more
|
|
279
|
+
random characters, such as from `openssl rand -base64 32`) so owners can save
|
|
280
|
+
keys, and optionally `CRITIQS_AI_PROVIDER`, `CRITIQS_AI_MODEL`, and
|
|
281
|
+
`CRITIQS_AI_API_KEY` for a provider every project uses by default.
|
|
282
|
+
`CRITIQS_AI_ALLOWED_ENDPOINTS` lists custom endpoint addresses owners may
|
|
283
|
+
enter. The same encryption key lets each person connect their own Linear
|
|
284
|
+
account in **Your trackers…**, in the avatar menu, with a Linear API key; with
|
|
285
|
+
`CRITIQS_LINEAR_CLIENT_ID` and `CRITIQS_LINEAR_CLIENT_SECRET` from your own
|
|
286
|
+
Linear OAuth app, whose callback is
|
|
287
|
+
`https://<deployment>.convex.site/trackers/linear/callback`, they sign in to
|
|
288
|
+
Linear instead. GitHub Issues works the same way: people paste a fine-grained
|
|
289
|
+
personal access token, or, with `CRITIQS_GITHUB_CLIENT_ID`,
|
|
290
|
+
`CRITIQS_GITHUB_CLIENT_SECRET`, and `CRITIQS_GITHUB_APP_SLUG` from your own
|
|
291
|
+
GitHub App (callback
|
|
292
|
+
`https://<deployment>.convex.site/trackers/github/callback`), sign in through
|
|
293
|
+
it. After upgrading an existing deployment, run
|
|
294
|
+
`npx convex run tags:backfill` once so earlier comments gain their hashtags,
|
|
295
|
+
and `npx convex run projects:shortenLongNames` once so project names from
|
|
296
|
+
before the 200-character limit are shortened to fit it.
|
|
297
|
+
|
|
298
|
+
The sidebar follows the mode. In Browse mode it shows the project: its open
|
|
299
|
+
and unread threads, who has access, your email notifications, and the project
|
|
300
|
+
ID. In Comment mode it shows the
|
|
301
|
+
threads.
|
|
302
|
+
|
|
303
|
+
Keyboard shortcuts: **C** Comment mode, **V** Browse mode, **M** Mockup mode,
|
|
304
|
+
**Escape** closes what is innermost, ending with the side panel, without
|
|
305
|
+
changing the mode, and **Ctrl or Cmd + `\`** hides or shows all of Critiqs.
|
|
306
|
+
|
|
307
|
+
### For a deployment's operator: Critiqs-managed AI
|
|
308
|
+
|
|
309
|
+
Critiqs-managed AI is configured once, on the backend, for every project; it
|
|
310
|
+
needs no change in host apps. On the Convex deployment, set these from your
|
|
311
|
+
own terminal, typing each value into the command's standard input rather than
|
|
312
|
+
on the command line, for example `npx convex env set CRITIQS_MANAGED_AI_API_KEY`:
|
|
313
|
+
|
|
314
|
+
| Setting | Value |
|
|
315
|
+
| --- | --- |
|
|
316
|
+
| `CRITIQS_MANAGED_AI` | `enabled` |
|
|
317
|
+
| `CRITIQS_MANAGED_AI_PROVIDER` | `openai`, `anthropic`, `google`, `openrouter`, `gateway`, or `compatible` |
|
|
318
|
+
| `CRITIQS_MANAGED_AI_MODELS` | The models on offer, as JSON: `[{"id":"claude-opus-5-5","label":"Claude Opus 5.5","model":"<provider's name>","price":{"input":4,"output":20}}, …]`; people choose them by `label`, and the first is the default. A model with a `price` (US dollars per million input and output tokens) charges each request by its tokens; a model with `credits` instead charges that flat amount per request |
|
|
319
|
+
| `CRITIQS_MANAGED_AI_MODEL` | Instead of `CRITIQS_MANAGED_AI_MODELS`: one model, the provider's name for it, shown as "Critiqs AI" and costing 1 credit a request |
|
|
320
|
+
| `CRITIQS_MANAGED_AI_PRICE` | Optional, with `CRITIQS_MANAGED_AI_MODEL`: its price as JSON, such as `{"input":4,"output":20}`, so requests are charged by their tokens |
|
|
321
|
+
| `CRITIQS_MANAGED_AI_API_KEY` | The provider key (optional only for `compatible`) |
|
|
322
|
+
| `CRITIQS_MANAGED_AI_BASE_URL` | Optional: the endpoint for `compatible` |
|
|
323
|
+
| `CRITIQS_UPGRADE_URL` | Optional, with plans: the https page where people upgrade, linked as **Upgrade** (with billing, **Upgrade** opens **Plan and billing** instead) |
|
|
324
|
+
|
|
325
|
+
Models from several makers share one provider, key, and address, so offer them
|
|
326
|
+
through a gateway that serves them all, such as Vercel AI Gateway
|
|
327
|
+
(`gateway`) or OpenRouter. For example, with the gateway's names for each
|
|
328
|
+
model and their list prices:
|
|
329
|
+
|
|
330
|
+
```json
|
|
331
|
+
[
|
|
332
|
+
{ "id": "claude-opus-5-5", "label": "Claude Opus 5.5", "model": "anthropic/claude-opus-5.5", "price": { "input": 4, "output": 20 } },
|
|
333
|
+
{ "id": "claude-haiku-5-5", "label": "Claude Haiku 5.5", "model": "anthropic/claude-haiku-5.5", "price": { "input": 0.1, "output": 0.5 } },
|
|
334
|
+
{ "id": "gemini-4-neon", "label": "Gemini 4 Neon", "model": "google/gemini-4-neon", "price": { "input": 3, "output": 15 } },
|
|
335
|
+
{ "id": "gpt-6-2-sol", "label": "GPT-6.2 Sol", "model": "openai/gpt-6.2-sol", "price": { "input": 2, "output": 10 } }
|
|
336
|
+
]
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
Check each `model` against the gateway's model list before deploying.
|
|
340
|
+
|
|
341
|
+
A priced request costs twice its API cost, in credits of 1 cent: `ceil(cost in
|
|
342
|
+
dollars × 200)`, at least 1. The cost is what OpenRouter or Vercel AI Gateway
|
|
343
|
+
reports charging (with a key of one's own there, the provider's charge
|
|
344
|
+
included), or otherwise the request's input tokens (cached ones included) and
|
|
345
|
+
output tokens (reasoning included) at the model's price. Before asking the
|
|
346
|
+
model, a request holds the most it could cost (each byte of its text as an
|
|
347
|
+
input token, and its longest answer) and starts only if that fits in what its
|
|
348
|
+
payer's organization may still spend this month, extra credits up to its cap
|
|
349
|
+
included, counting other requests still in flight. Once the model
|
|
350
|
+
answers, the request is counted at its real cost; one that fails costs
|
|
351
|
+
nothing. A hold lasts at most 10 minutes, so a request that never finishes
|
|
352
|
+
doesn't block its payer. People see each priced model's cost as "about N
|
|
353
|
+
credits": what a request of 2,000 input and 1,000 output tokens costs, such as
|
|
354
|
+
about 6 credits for Claude Opus 5.5 above.
|
|
355
|
+
|
|
356
|
+
Managed AI stays off until the provider, models, and key are all set. Check it
|
|
357
|
+
with `npx critiqs-react doctor` (or the backend's `/critiqs/health`, whose
|
|
358
|
+
`ai.managed` is `true`, or whose `ai.managedProblem` says what's wrong); like
|
|
359
|
+
every health check, that reads configuration without calling the model.
|
|
360
|
+
|
|
361
|
+
### For Critiqs Cloud's operator: payment through Autumn
|
|
362
|
+
|
|
363
|
+
Critiqs Cloud takes payment for its plans through [Autumn](https://useautumn.com),
|
|
364
|
+
which runs Stripe. Other deployments leave this off: without these settings
|
|
365
|
+
nothing calls Autumn, the webhook route answers 404, and `/critiqs/config`
|
|
366
|
+
doesn't report `billing`. Billing needs plans on (`CRITIQS_PLANS=enabled`).
|
|
367
|
+
Set these on the Convex deployment, typing secret values into standard input
|
|
368
|
+
as above:
|
|
369
|
+
|
|
370
|
+
| Setting | Value |
|
|
371
|
+
| --- | --- |
|
|
372
|
+
| `CRITIQS_BILLING` | `autumn` |
|
|
373
|
+
| `AUTUMN_SECRET_KEY` | Autumn's secret key: `am_sk_test_…` for its sandbox, `am_sk_live_…` for real payments |
|
|
374
|
+
| `AUTUMN_WEBHOOK_SECRET` | The `whsec_…` secret Autumn shows once when you add the webhook below |
|
|
375
|
+
| `AUTUMN_API_URL` | Optional: another Autumn address, such as a local stand-in for testing |
|
|
376
|
+
|
|
377
|
+
In Autumn's dashboard (Developer, then Webhooks), add an endpoint at
|
|
378
|
+
`https://<deployment>.convex.site/critiqs/billing/autumn` for `billing.updated`,
|
|
379
|
+
in the same environment as the key. Each verified message makes Critiqs read
|
|
380
|
+
the organization's subscription from Autumn again before it answers, so
|
|
381
|
+
messages that arrive twice, late, or out of order change nothing more. When
|
|
382
|
+
Autumn can't be read, the webhook answers 503 and Autumn sends it again later.
|
|
383
|
+
`/critiqs/health` reports `billing` with the key's environment and whether the
|
|
384
|
+
webhook secret is set, never the keys.
|
|
385
|
+
|
|
386
|
+
Autumn's catalog needs the plans `free` (enabled for every new customer), `plus`,
|
|
387
|
+
and `pro`, the add-on `storage_100gb` granting 100 `extra_storage_gb`, and the
|
|
388
|
+
metered feature `ai_credits`. An organization is Autumn's customer, with the
|
|
389
|
+
organization's ID, its name, and the email of the admin who first opened
|
|
390
|
+
billing. Prices live in Autumn; what each plan allows stays in Critiqs's plans
|
|
391
|
+
(`plans:set`), and the page shows each plan's limits from there, through
|
|
392
|
+
`billing:status`'s `plans`, so changing a plan's limits changes the page.
|
|
393
|
+
Until the backend has read Autumn's prices, changes that would charge the card
|
|
394
|
+
on file (between Plus and Pro, adding storage) are paused; buying on Stripe
|
|
395
|
+
Checkout, which shows the price, going back to Free, and removing storage
|
|
396
|
+
still work.
|
|
397
|
+
|
|
398
|
+
People use it from **Plan and billing** in the avatar menu, which every
|
|
399
|
+
**Upgrade** button opens on such deployments, on the organization whose plan
|
|
400
|
+
it shows: the person's home organization from **Your AI**, the project's
|
|
401
|
+
elsewhere, closing the dialog it was in. Members of an organization see
|
|
402
|
+
its plan, renewal or end date, credits and images used, and the cap on extra
|
|
403
|
+
credits; its admins upgrade, switch, go back to Free, keep a plan they had
|
|
404
|
+
cancelled, set the cap, add or remove Pro's extra storage, and open Stripe's
|
|
405
|
+
portal. A change that charges the card on file or ends something says what it
|
|
406
|
+
does and costs before it is made, naming the organization. Stripe returns to
|
|
407
|
+
the same page, which waits for the payment to arrive and allows no other
|
|
408
|
+
change meanwhile. Dates are the days Autumn's periods end, in UTC.
|
|
409
|
+
|
|
410
|
+
- **Plans.** An admin buying Plus or Pro with nothing billed pays on Stripe
|
|
411
|
+
Checkout, even with a card on file. Each change names the plan the page
|
|
412
|
+
showed as billed (`from`); when Autumn bills another by then, as when a
|
|
413
|
+
payment arrived meanwhile, it is refused and nothing is charged. Between Plus
|
|
414
|
+
and Pro with a card on file, Autumn charges an upgrade at once,
|
|
415
|
+
prorated, and moves a downgrade to the end of the period. Going back to Free
|
|
416
|
+
cancels at the end of the period. A renewal that fails (`past_due`) keeps the
|
|
417
|
+
paid plan; when Stripe gives up, the organization is on Free. Free after a
|
|
418
|
+
downgrade to Plus was scheduled drops the downgrade and ends the paid plan
|
|
419
|
+
with its period. A changed plan starts from its default cap on extra credits.
|
|
420
|
+
Stripe sends people back only to the site they signed in from.
|
|
421
|
+
- **Storage.** Pro organizations can buy a 100 GB storage add-on. Autumn makes
|
|
422
|
+
each attach its own subscription, so add-ons attached elsewhere (such as
|
|
423
|
+
Autumn's dashboard) stack: two grant 200 GB. Critiqs grants 100 GB for each
|
|
424
|
+
active add-on and shows those that renew. Removing storage cancels one at the
|
|
425
|
+
end of its period; leaving Pro cancels all of them with Pro, and keeping Pro
|
|
426
|
+
before then restores those, but not one the admin removed.
|
|
427
|
+
- **Usage.** Each Critiqs AI charge to an organization on Plus or Pro is
|
|
428
|
+
queued in the same transaction and reported to Autumn's `ai_credits` at
|
|
429
|
+
once, then each minute until Autumn has it, with the time it was used, in
|
|
430
|
+
full past the plan's included credits (Critiqs enforces the cap), and with
|
|
431
|
+
its own idempotency key, so retries never count twice. Autumn counts usage
|
|
432
|
+
in the billing period current when the report arrives, whatever its time
|
|
433
|
+
says, so usage still being sent when the month turns over (UTC, when plans
|
|
434
|
+
renew) is billed in the new month, and usage held up by an Autumn outage is
|
|
435
|
+
billed in the month it gets through. Autumn remembers a key for 24 hours,
|
|
436
|
+
so a report already tried but not sent within 20 hours of use is never
|
|
437
|
+
sent again: it is kept as `failed` in the `billingUsage` table and logged.
|
|
438
|
+
A report never tried is still sent, however old.
|
|
439
|
+
`npx convex run billing:failedUsage` lists the failed reports with their
|
|
440
|
+
credits per organization, which were never billed.
|
|
441
|
+
- **Plans an operator assigns** (`plans:assign`) stay until the organization's
|
|
442
|
+
Autumn subscription next changes. `billing:status` reports the plan whose
|
|
443
|
+
limits apply as `plan` and the billed one as `subscription.plan`, so such a
|
|
444
|
+
plan has no `subscription`: the page says Critiqs set it, and buying a plan
|
|
445
|
+
starts a subscription on Checkout that replaces it.
|
|
446
|
+
|
|
447
|
+
A daily check reads every organization with an Autumn customer or a paid plan
|
|
448
|
+
from Autumn again, catching anything a lost webhook missed. Run it at any time,
|
|
449
|
+
for example after first setting the webhook, with
|
|
450
|
+
`npx convex run billing:reconcile`, or for one organization with
|
|
451
|
+
`npx convex run billing:sync '{"organizationId":"..."}'`.
|
|
452
|
+
|
|
453
|
+
## Screenshot storage on Convex
|
|
454
|
+
|
|
455
|
+
Convex deployments can store screenshots in a private Cloudflare R2 bucket,
|
|
456
|
+
keeping comments, image metadata, and access checks in Convex. Configure
|
|
457
|
+
`CRITIQS_CAPTURE_STORAGE=r2` and `CRITIQS_R2_ACCOUNT_ID`, `CRITIQS_R2_BUCKET`,
|
|
458
|
+
`CRITIQS_R2_ACCESS_KEY_ID`, and `CRITIQS_R2_SECRET_ACCESS_KEY` on the backend.
|
|
459
|
+
Deploy matching protocol-4 functions and package. Keep the bucket private and
|
|
460
|
+
restrict its API token to that bucket. The host app needs no R2 keys or code
|
|
461
|
+
changes. Existing Convex captures remain readable; incomplete R2 setup fails
|
|
462
|
+
explicitly. `critiqs doctor` checks configuration; a real upload verifies access.
|
|
463
|
+
|
|
464
|
+
## Self-hosting inside your app's server
|
|
465
|
+
|
|
466
|
+
If your prototype has its own long-running Node or Bun server with a disk that
|
|
467
|
+
survives restarts, Critiqs can run inside it and keep feedback in a SQLite file.
|
|
468
|
+
No Critiqs service is involved. Static hosts and serverless platforms such as
|
|
469
|
+
Vercel can't keep the file; use Critiqs Cloud or your own Convex there.
|
|
470
|
+
`critiqs-react/server` is the shared package's `critiqs/server`; either import
|
|
471
|
+
works.
|
|
472
|
+
|
|
473
|
+
```ts
|
|
474
|
+
import { createCritiqsHandler, toNodeListener } from "critiqs-react/server";
|
|
475
|
+
|
|
476
|
+
const critiqs = await createCritiqsHandler({
|
|
477
|
+
database: "critiqs.sqlite",
|
|
478
|
+
email: { resendApiKey: process.env.RESEND_API_KEY!, from: "Critiqs <critiqs@example.com>" },
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// Bun, or any server built on web requests:
|
|
482
|
+
Bun.serve({
|
|
483
|
+
fetch: (request, server) =>
|
|
484
|
+
new URL(request.url).pathname.startsWith("/critiqs")
|
|
485
|
+
? critiqs.fetch(request, { remoteAddress: server.requestIP(request)?.address })
|
|
486
|
+
: app(request),
|
|
487
|
+
});
|
|
488
|
+
// Node: http.createServer(toNodeListener(critiqs)) for requests under /critiqs.
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
Then point the component at it: `<Critiqs backend="/critiqs" projectId="…" />`.
|
|
492
|
+
Reviewers sign in with an emailed code. To use your app's own sign-in instead,
|
|
493
|
+
pass `identify: (request) => ({ id, name, email })` for whoever the request's
|
|
494
|
+
session belongs to, or null. While developing without a Resend key,
|
|
495
|
+
`developmentSignIn: true` shows codes on screen, only for connections from this
|
|
496
|
+
computer (pass `remoteAddress` as above; the Node listener does it for you).
|
|
497
|
+
Captures must be PNG, JPEG, WebP, or GIF.
|
|
498
|
+
|
|
499
|
+
For AI, pass `ai`, read from your server's environment:
|
|
500
|
+
|
|
501
|
+
```ts
|
|
502
|
+
const critiqs = await createCritiqsHandler({
|
|
503
|
+
database: "critiqs.sqlite",
|
|
504
|
+
ai: {
|
|
505
|
+
// A provider for every project; omit for none. A local Ollama: provider "compatible", baseURL "http://localhost:11434/v1".
|
|
506
|
+
provider: "openai",
|
|
507
|
+
model: process.env.CRITIQS_AI_MODEL!,
|
|
508
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
509
|
+
// Lets project owners connect their own provider in Critiqs, with keys stored encrypted.
|
|
510
|
+
encryptionKey: process.env.CRITIQS_AI_ENCRYPTION_KEY,
|
|
511
|
+
allowedEndpoints: ["https://llm.example.com/v1"],
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
Model requests and providers' model lists come from this server, so
|
|
517
|
+
`localhost` means this server's machine. Existing feedback gains its hashtags when the database upgrades on start.
|
|
518
|
+
Back up the database with SQLite's online backup
|
|
519
|
+
(`sqlite3 critiqs.sqlite ".backup backup.sqlite"`).
|
|
520
|
+
|
|
521
|
+
The first-release API and interaction choices remain provisional. See the
|
|
522
|
+
[project documentation](https://github.com/noahsjung/critiqs/tree/main/docs)
|
|
523
|
+
for agreed behavior, proposed choices, and own-backend setup.
|
|
524
|
+
|
|
525
|
+
Critiqs is released under the [MIT license](LICENSE).
|
package/bin/critiqs.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CritiqsProps } from "./host.js";
|
|
2
|
+
/**
|
|
3
|
+
* Critiqs's one component. Add it anywhere in the prototype; it renders its
|
|
4
|
+
* toolbar, sidebar, and pins above the app in a shadow root, with its own
|
|
5
|
+
* sign-in, backend connection, and styles. It renders nothing in place.
|
|
6
|
+
* With `requireProjectId`, it adds nothing to the page until `projectId` is a
|
|
7
|
+
* valid project ID, and removes everything it added when the ID goes away.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Critiqs(props: CritiqsProps): null;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Thread statuses (F4). Resolved also serves as archive. */
|
|
2
|
+
export type ThreadStatus = "open" | "resolved" | "deleted";
|
|
3
|
+
/** Shared across compatible records, or specific to one record (F7). */
|
|
4
|
+
export type Scope = "shared" | "record";
|
|
5
|
+
/** Prototype build a message refers to. `null` means unknown. */
|
|
6
|
+
export type Revision = string | null;
|
|
7
|
+
/** Settings that affect visible content, recorded by the host app. */
|
|
8
|
+
export type ViewState = Record<string, string | number | boolean | null>;
|
|
9
|
+
export interface Target {
|
|
10
|
+
/** Stable purpose ID from `data-critiqs-id`, such as `user-details.department`. */
|
|
11
|
+
purposeId: string | null;
|
|
12
|
+
/** Record key from the nearest `data-critiqs-record`, when the target belongs to one. */
|
|
13
|
+
recordKey: string | null;
|
|
14
|
+
/** Backup clues used to confirm a match; never used to guess a nearby element. */
|
|
15
|
+
clues: TargetClues;
|
|
16
|
+
}
|
|
17
|
+
export interface TargetClues {
|
|
18
|
+
tagName: string;
|
|
19
|
+
role: string | null;
|
|
20
|
+
label: string | null;
|
|
21
|
+
/** Structural path of tag names and sibling positions from the anchor root. */
|
|
22
|
+
path: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Rect {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
/** The information stored to locate a target in the right context. */
|
|
31
|
+
export interface Anchor {
|
|
32
|
+
/** Logical page, such as `user-details`. */
|
|
33
|
+
screen: string;
|
|
34
|
+
viewState: ViewState;
|
|
35
|
+
target: Target;
|
|
36
|
+
scope: Scope;
|
|
37
|
+
evidence: Evidence;
|
|
38
|
+
}
|
|
39
|
+
/** Original evidence saved with the first message (F6). */
|
|
40
|
+
export interface Evidence {
|
|
41
|
+
url: string;
|
|
42
|
+
viewport: {
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
};
|
|
46
|
+
/** Marked location in page coordinates at capture time. */
|
|
47
|
+
marker: Rect | null;
|
|
48
|
+
capturedAt: number;
|
|
49
|
+
revision: Revision;
|
|
50
|
+
/** Browser that left the feedback, shown with the context. */
|
|
51
|
+
userAgent: string | null;
|
|
52
|
+
/** Demo persona shown in the prototype. Context only, never the author. */
|
|
53
|
+
persona: string | null;
|
|
54
|
+
}
|
|
55
|
+
/** Where a thread's target is now: the original anchor, or its reattachment (F8). */
|
|
56
|
+
export type TargetLocation = Pick<Anchor, "screen" | "viewState" | "target" | "scope">;
|
|
57
|
+
/** Where a thread sits relative to the reviewer's current view (sidebar groups). */
|
|
58
|
+
export type ThreadPlacement = "current-view" | "other-view" | "other-screen";
|
|
59
|
+
/** Result of trying to locate a target in the live page. */
|
|
60
|
+
export type LocateResult = {
|
|
61
|
+
status: "found";
|
|
62
|
+
elements: Element[];
|
|
63
|
+
} | {
|
|
64
|
+
status: "not-found";
|
|
65
|
+
} | {
|
|
66
|
+
status: "ambiguous";
|
|
67
|
+
candidates: number;
|
|
68
|
+
} | {
|
|
69
|
+
status: "wrong-record";
|
|
70
|
+
};
|
|
71
|
+
/** Reactions offered on messages. The server accepts only these. */
|
|
72
|
+
export declare const REACTIONS: readonly ["👍", "❤️", "🎉", "👀", "✅", "😄"];
|