critiqs-react 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/AGENT_SETUP.md +198 -66
  2. package/README.md +214 -31
  3. package/bin/critiqs.mjs +3 -1
  4. package/dist/index.js +16877 -4770
  5. package/dist/server/index.d.ts +1 -87
  6. package/dist/server/index.js +1 -4889
  7. package/package.json +6 -5
  8. package/bin/cli.d.mts +0 -21
  9. package/bin/cli.mjs +0 -293
  10. package/bin/env.d.mts +0 -41
  11. package/bin/env.mjs +0 -384
  12. package/bin/init.d.mts +0 -126
  13. package/bin/init.mjs +0 -965
  14. package/bin/mcp.d.mts +0 -20
  15. package/bin/mcp.mjs +0 -314
  16. package/bin/setup.d.mts +0 -183
  17. package/bin/setup.mjs +0 -1054
  18. package/dist/backend/convex/_generated/api.d.ts +0 -95
  19. package/dist/backend/convex/_generated/api.js +0 -23
  20. package/dist/backend/convex/_generated/dataModel.d.ts +0 -60
  21. package/dist/backend/convex/_generated/server.d.ts +0 -162
  22. package/dist/backend/convex/_generated/server.js +0 -101
  23. package/dist/backend/convex/ai.ts +0 -93
  24. package/dist/backend/convex/aiSettings.ts +0 -43
  25. package/dist/backend/convex/auth.config.ts +0 -18
  26. package/dist/backend/convex/captureHttp.ts +0 -96
  27. package/dist/backend/convex/captures.ts +0 -167
  28. package/dist/backend/convex/crons.ts +0 -14
  29. package/dist/backend/convex/deviceSignIn.ts +0 -151
  30. package/dist/backend/convex/grouping.ts +0 -41
  31. package/dist/backend/convex/http.ts +0 -724
  32. package/dist/backend/convex/lib/ai.ts +0 -6
  33. package/dist/backend/convex/lib/links.ts +0 -12
  34. package/dist/backend/convex/lib/pages.ts +0 -207
  35. package/dist/backend/convex/lib/r2.ts +0 -75
  36. package/dist/backend/convex/lib/store.ts +0 -509
  37. package/dist/backend/convex/lib/tokens.ts +0 -101
  38. package/dist/backend/convex/lib/validators.ts +0 -73
  39. package/dist/backend/convex/lib/vendor/aws4fetch.js +0 -289
  40. package/dist/backend/convex/lib/vendor/critiqs_ai.js +0 -49081
  41. package/dist/backend/convex/lib/vendor/critiqs_core.js +0 -385
  42. package/dist/backend/convex/lib/vendor/critiqs_server.js +0 -3108
  43. package/dist/backend/convex/notificationEmails.ts +0 -61
  44. package/dist/backend/convex/notifications.ts +0 -182
  45. package/dist/backend/convex/plans.ts +0 -67
  46. package/dist/backend/convex/projects.ts +0 -46
  47. package/dist/backend/convex/schema.ts +0 -343
  48. package/dist/backend/convex/search.ts +0 -26
  49. package/dist/backend/convex/signIn.ts +0 -368
  50. package/dist/backend/convex/tags.ts +0 -68
  51. package/dist/backend/convex/threads.ts +0 -146
  52. package/dist/backend/convex/users.ts +0 -13
  53. package/dist/server/chunks/driver-n9zpr0k3.js +0 -21
  54. package/dist/server/chunks/index-9bg7tmnq.js +0 -522
  55. package/dist/server/chunks/index-askcfn7t.js +0 -148
  56. package/dist/server/chunks/providers-rv184xvj.js +0 -48444
  57. package/dist/server/chunks/token-kzddms7r.js +0 -63
  58. package/dist/server/chunks/token-util-k8bee1wc.js +0 -4
@@ -1,343 +0,0 @@
1
- import { defineSchema, defineTable } from "convex/server";
2
- import { v } from "convex/values";
3
- import {
4
- anchorValidator,
5
- captureValidator,
6
- locationValidator,
7
- profileValidator,
8
- revisionValidator,
9
- } from "./lib/validators";
10
-
11
- export default defineSchema({
12
- /** Reviewers, keyed by the sign-in provider's token identifier. */
13
- users: defineTable({
14
- tokenIdentifier: v.string(),
15
- name: v.string(),
16
- email: v.union(v.string(), v.null()),
17
- imageUrl: v.union(v.string(), v.null()),
18
- /** Profile version of the token that last set the name, so an older token cannot revert it. */
19
- profileVersion: v.optional(v.number()),
20
- /** Critiqs Cloud plan for the projects this account owns; absent means the default plan. */
21
- plan: v.optional(v.string()),
22
- }).index("by_token", ["tokenIdentifier"]),
23
-
24
- /** A Critiqs project: the shared feedback space for one prototype. */
25
- projects: defineTable({
26
- name: v.string(),
27
- tags: v.array(v.string()),
28
- createdBy: v.id("users"),
29
- createdAt: v.number(),
30
- /** The prototype address mention emails link to. */
31
- reviewUrl: v.optional(v.string()),
32
- }).index("by_creator", ["createdBy"]),
33
-
34
- /**
35
- * Critiqs Cloud plans configured on this deployment, replacing the built-in
36
- * plan of the same name. Set with `npx convex run plans:set`.
37
- */
38
- plans: defineTable({
39
- name: v.string(),
40
- label: v.string(),
41
- limits: v.array(
42
- v.object({
43
- metric: v.union(
44
- v.literal("projects"),
45
- v.literal("threads"),
46
- v.literal("messages"),
47
- v.literal("reviewers"),
48
- v.literal("captureBytes"),
49
- v.literal("mentionEmails"),
50
- v.literal("aiRequests"),
51
- ),
52
- period: v.union(v.literal("total"), v.literal("month"), v.literal("day")),
53
- max: v.number(),
54
- }),
55
- ),
56
- }).index("by_name", ["name"]),
57
-
58
- /** Usage counters for Critiqs Cloud plans, one per metric, account or project, and period. */
59
- usage: defineTable({ key: v.string(), count: v.number() }).index("by_key", ["key"]),
60
- /** Who already counted toward a counter that counts people once, such as reviewers per month. */
61
- usageMembers: defineTable({ key: v.string(), member: v.string() }).index("by_key_member", ["key", "member"]),
62
-
63
- /** R2 bytes stay private; only their location and upload lifecycle live in Convex. */
64
- captureFiles: defineTable({
65
- projectId: v.id("projects"),
66
- uploadedBy: v.id("users"),
67
- accountId: v.string(),
68
- bucket: v.string(),
69
- key: v.string(),
70
- status: v.union(v.literal("reserved"), v.literal("uploading"), v.literal("ready"), v.literal("attached"), v.literal("deleting")),
71
- contentType: v.optional(v.string()),
72
- size: v.optional(v.number()),
73
- createdAt: v.number(),
74
- cleanupAt: v.optional(v.number()),
75
- }).index("by_cleanup", ["cleanupAt"]).index("by_uploader_status", ["uploadedBy", "status"]),
76
-
77
- threads: defineTable({
78
- projectId: v.id("projects"),
79
- status: v.union(v.literal("open"), v.literal("resolved"), v.literal("deleted")),
80
- anchor: anchorValidator,
81
- tags: v.array(v.string()),
82
- capture: captureValidator,
83
- createdBy: v.id("users"),
84
- createdAt: v.number(),
85
- /** Newest message time. Edits, reactions, and status changes leave it unchanged. */
86
- lastMessageAt: v.number(),
87
- messageCount: v.number(),
88
- editCount: v.optional(v.number()),
89
- statusChangedBy: v.optional(v.id("users")),
90
- statusChangedAt: v.optional(v.number()),
91
- /** Replacement target. The anchor keeps the original target and evidence. */
92
- reattachment: v.optional(
93
- v.object({ location: locationValidator, reattachedBy: v.id("users"), reattachedAt: v.number() }),
94
- ),
95
- /** Hashtags the thread's messages use, with how many messages use each. Absent before the tag backfill. */
96
- textTags: v.optional(v.array(v.object({ key: v.string(), label: v.string(), count: v.number() }))),
97
- })
98
- .index("by_project_status", ["projectId", "status"])
99
- .index("by_project", ["projectId"])
100
- .index("by_project_activity", ["projectId", "lastMessageAt"])
101
- .index("by_capture_storage", ["capture.storageId"]),
102
-
103
- messages: defineTable({
104
- threadId: v.id("threads"),
105
- authorId: v.id("users"),
106
- body: v.string(),
107
- createdAt: v.number(),
108
- editedAt: v.union(v.number(), v.null()),
109
- revision: revisionValidator,
110
- /** Reviewers the message mentions, with the name as written in the text. */
111
- mentions: v.optional(v.array(v.object({ userId: v.id("users"), label: v.string() }))),
112
- /** The thread's project, for search; absent until the tag backfill reaches older messages. */
113
- projectId: v.optional(v.id("projects")),
114
- /** Unique hashtags the text uses, as first written; absent until the tag backfill. */
115
- hashtags: v.optional(v.array(v.string())),
116
- })
117
- .index("by_thread", ["threadId", "createdAt"])
118
- .searchIndex("search_body", { searchField: "body", filterFields: ["projectId"] }),
119
-
120
- /** Tags used or offered in a project, with their shared groups and automatic grouping state. */
121
- projectTags: defineTable({
122
- projectId: v.id("projects"),
123
- key: v.string(),
124
- label: v.string(),
125
- firstUsedAt: v.number(),
126
- lastUsedAt: v.number(),
127
- groupIds: v.array(v.id("tagGroups")),
128
- grouping: v.union(v.literal("pending"), v.literal("ai"), v.literal("starter"), v.literal("human"), v.literal("none")),
129
- epoch: v.number(),
130
- attempts: v.number(),
131
- nextAttemptAt: v.number(),
132
- claimToken: v.optional(v.string()),
133
- leaseUntil: v.optional(v.number()),
134
- lastError: v.optional(v.string()),
135
- })
136
- .index("by_project_key", ["projectId", "key"])
137
- .index("by_project_used", ["projectId", "lastUsedAt"])
138
- .index("by_project_grouping", ["projectId", "grouping", "nextAttemptAt"])
139
- .index("by_due", ["grouping", "nextAttemptAt"]),
140
-
141
- /** Shared groups of tags in a project. */
142
- tagGroups: defineTable({
143
- projectId: v.id("projects"),
144
- name: v.string(),
145
- nameKey: v.string(),
146
- origin: v.union(v.literal("ai"), v.literal("human"), v.literal("starter")),
147
- createdAt: v.number(),
148
- updatedAt: v.number(),
149
- }).index("by_project_name", ["projectId", "nameKey"]),
150
-
151
- /** That a thread has a tag, explicit or written, so search can find threads by tag. */
152
- threadTags: defineTable({
153
- projectId: v.id("projects"),
154
- threadId: v.id("threads"),
155
- key: v.string(),
156
- })
157
- .index("by_thread", ["threadId"])
158
- .index("by_project_key", ["projectId", "key"]),
159
-
160
- /** A project's AI connection. Keys are stored only encrypted (AES-GCM), never returned. */
161
- aiSettings: defineTable({
162
- projectId: v.id("projects"),
163
- enabled: v.boolean(),
164
- mode: v.union(v.literal("managed"), v.literal("own")),
165
- provider: v.optional(v.union(v.literal("openai"), v.literal("anthropic"), v.literal("google"), v.literal("gateway"), v.literal("compatible"))),
166
- model: v.optional(v.string()),
167
- baseUrl: v.optional(v.string()),
168
- secret: v.optional(v.object({ ciphertext: v.string(), iv: v.string(), hint: v.string() })),
169
- epoch: v.number(),
170
- updatedAt: v.number(),
171
- updatedBy: v.string(),
172
- lastTest: v.optional(v.object({ ok: v.boolean(), at: v.number(), message: v.string() })),
173
- }).index("by_project", ["projectId"]),
174
-
175
- /** Short-window counters for operational limits, such as searches per minute. */
176
- aiRateLimits: defineTable({ key: v.string(), count: v.number(), expiresAt: v.number() })
177
- .index("by_key", ["key"])
178
- .index("by_expiry", ["expiresAt"]),
179
-
180
- /** People who have commented in a project; the people who can be mentioned there. */
181
- participants: defineTable({
182
- projectId: v.id("projects"),
183
- userId: v.id("users"),
184
- lastActiveAt: v.number(),
185
- })
186
- .index("by_project_user", ["projectId", "userId"])
187
- .index("by_project_activity", ["projectId", "lastActiveAt"]),
188
-
189
- /**
190
- * One email owed to one reviewer about one thread. Mentions gather into it
191
- * for a short pause; once a send is attempted its content and key are fixed.
192
- */
193
- deliveries: defineTable({
194
- recipientId: v.id("users"),
195
- projectId: v.id("projects"),
196
- threadId: v.id("threads"),
197
- status: v.union(v.literal("pending"), v.literal("sending"), v.literal("sent"), v.literal("skipped"), v.literal("failed")),
198
- attempts: v.number(),
199
- dueAt: v.number(),
200
- claimToken: v.optional(v.string()),
201
- leaseUntil: v.optional(v.number()),
202
- message: v.optional(v.object({ to: v.string(), subject: v.string(), text: v.string(), html: v.string() })),
203
- /** The email as first prepared, stored as a private file, and the address it goes to. */
204
- payload: v.optional(v.object({ fileId: v.id("_storage"), to: v.string() })),
205
- createdAt: v.number(),
206
- finishedAt: v.optional(v.number()),
207
- reason: v.optional(v.string()),
208
- })
209
- .index("by_status_due", ["status", "dueAt"])
210
- .index("by_status_lease", ["status", "leaseUntil"])
211
- .index("by_recipient_thread", ["recipientId", "threadId", "status", "attempts"])
212
- .index("by_finished", ["finishedAt"]),
213
-
214
- /** The mentions a delivery reports. */
215
- notifications: defineTable({
216
- deliveryId: v.id("deliveries"),
217
- recipientId: v.id("users"),
218
- messageId: v.id("messages"),
219
- authorId: v.id("users"),
220
- createdAt: v.number(),
221
- }).index("by_delivery", ["deliveryId"]),
222
-
223
- /** A reviewer's email notification choices. */
224
- preferences: defineTable({
225
- userId: v.id("users"),
226
- mentionEmails: v.boolean(),
227
- mutedProjects: v.array(v.id("projects")),
228
- }).index("by_user", ["userId"]),
229
-
230
- /** Values a deployment generates for itself, such as the key that signs mute and unsubscribe links. */
231
- settings: defineTable({ key: v.string(), value: v.string() }).index("by_key", ["key"]),
232
-
233
- reactions: defineTable({
234
- threadId: v.id("threads"),
235
- messageId: v.id("messages"),
236
- userId: v.id("users"),
237
- emoji: v.string(),
238
- })
239
- .index("by_thread", ["threadId"])
240
- .index("by_message_user_emoji", ["messageId", "userId", "emoji"]),
241
-
242
- // Sign-in tables. Only Critiqs's sign-in deployment (the hosted one) uses them.
243
-
244
- /**
245
- * Reviewers known to the sign-in service. The document ID is the reviewer's
246
- * permanent Critiqs ID, the token subject every deployment sees; it never
247
- * changes with the sign-in method or display name.
248
- */
249
- reviewers: defineTable({
250
- /** Verified email address, lowercased. */
251
- email: v.string(),
252
- /** The name the reviewer chose to show on their comments. */
253
- name: v.string(),
254
- /** Increases with each name change; tokens carry it as `profile_version`. */
255
- nameVersion: v.number(),
256
- createdAt: v.number(),
257
- }).index("by_email", ["email"]),
258
-
259
- /** Transactional sign-in start counters; no untrusted IP headers. */
260
- signInLimits: defineTable({ key: v.string(), count: v.number(), expiresAt: v.number() })
261
- .index("by_key", ["key"]).index("by_expiry", ["expiresAt"]),
262
-
263
- /** A sign-in popup in progress: which site asked, its email code, and the reviewer once verified. */
264
- signInAttempts: defineTable({
265
- key: v.string(),
266
- origin: v.string(),
267
- clientState: v.string(),
268
- /** Hash of the cookie that ties the attempt to the browser that started it. */
269
- bindingHash: v.string(),
270
- createdAt: v.number(),
271
- /** Left over from WorkOS sign-in; attempts expire within the hour, then this can go. */
272
- codeVerifier: v.optional(v.string()),
273
- /** The address the latest code went to. */
274
- email: v.optional(v.string()),
275
- /** Codes sent so far, and which one is current. */
276
- codesSent: v.optional(v.number()),
277
- codeGeneration: v.optional(v.number()),
278
- /** Keyed digest of the current code, never the code itself. */
279
- codeDigest: v.optional(v.string()),
280
- codeExpiresAt: v.optional(v.number()),
281
- /** Wrong guesses still allowed, across every code this attempt sends. */
282
- guessesLeft: v.optional(v.number()),
283
- /** Set once a code matched; a new reviewer then chooses a name. */
284
- verifiedEmail: v.optional(v.string()),
285
- profile: v.optional(profileValidator),
286
- /** Hash of the token the consent page must return. */
287
- consentHash: v.optional(v.string()),
288
- /** Set when this sign-in approves setup on another device rather than signing in to a site. */
289
- device: v.optional(v.id("deviceGrants")),
290
- })
291
- .index("by_key", ["key"])
292
- .index("by_created", ["createdAt"]),
293
-
294
- /**
295
- * Setup waiting on another device (`critiqs init --remote`): the command
296
- * line holds a device secret and polls; the person enters a short code in a
297
- * browser anywhere, signs in, and approves. Both are stored only as hashes.
298
- */
299
- deviceGrants: defineTable({
300
- deviceHash: v.string(),
301
- userCodeHash: v.string(),
302
- createdAt: v.number(),
303
- expiresAt: v.number(),
304
- /** Seconds the command line waits between polls. */
305
- interval: v.number(),
306
- lastPolledAt: v.optional(v.number()),
307
- status: v.union(v.literal("pending"), v.literal("approved"), v.literal("denied")),
308
- /** Who approved, once approved. */
309
- profile: v.optional(profileValidator),
310
- })
311
- .index("by_device", ["deviceHash"])
312
- .index("by_user_code", ["userCodeHash"])
313
- .index("by_expiry", ["expiresAt"]),
314
-
315
- /** Sites a reviewer allowed to use their Critiqs account. */
316
- siteGrants: defineTable({
317
- subject: v.string(),
318
- origin: v.string(),
319
- grantedAt: v.number(),
320
- }).index("by_subject_origin", ["subject", "origin"]),
321
-
322
- /** A signed-in component on one site. Refresh tokens are stored only as hashes. */
323
- sessions: defineTable({
324
- refreshHash: v.string(),
325
- origin: v.string(),
326
- profile: profileValidator,
327
- createdAt: v.number(),
328
- /** Ends this long after last use… */
329
- expiresAt: v.number(),
330
- /** …but never after this, however often it is used. */
331
- endsAt: v.optional(v.number()),
332
- })
333
- .index("by_refresh_hash", ["refreshHash"])
334
- .index("by_expiry", ["expiresAt"]),
335
-
336
- /** Personal read state (F5). Never affects other reviewers or thread status. */
337
- readStates: defineTable({
338
- userId: v.id("users"),
339
- threadId: v.id("threads"),
340
- lastReadAt: v.number(),
341
- manualUnread: v.boolean(),
342
- }).index("by_user_thread", ["userId", "threadId"]),
343
- });
@@ -1,26 +0,0 @@
1
- import { finalizeSearch, prepareSearch, retrieveSearch } from "./lib/vendor/critiqs_server.js";
2
- import { v } from "convex/values";
3
- import { internalMutation, internalQuery } from "./_generated/server";
4
- import { deployment } from "./lib/ai";
5
- import { convexStore, identityOf, run } from "./lib/store";
6
-
7
- // The steps of a search, each its own transaction, run by the `ai.search`
8
- // action with the model called between them. Each checks the reviewer's
9
- // access again.
10
-
11
- const scope = v.object({ status: v.union(v.literal("open"), v.literal("resolved"), v.literal("all")), screen: v.union(v.string(), v.null()) });
12
-
13
- export const prepare = internalMutation({
14
- args: { projectId: v.string(), question: v.string(), scope },
15
- handler: async (ctx, args) => run(async () => prepareSearch(convexStore(ctx), await identityOf(ctx), args, deployment(), Date.now())),
16
- });
17
-
18
- export const retrieve = internalQuery({
19
- args: { projectId: v.string(), query: v.any(), groups: v.any() },
20
- handler: async (ctx, args) => run(async () => retrieveSearch(convexStore(ctx), await identityOf(ctx), args)),
21
- });
22
-
23
- export const finalize = internalQuery({
24
- args: { projectId: v.string(), response: v.any() },
25
- handler: async (ctx, args) => run(async () => finalizeSearch(convexStore(ctx), await identityOf(ctx), args)),
26
- });