context-drop 0.3.0 → 0.3.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.
@@ -119,11 +119,23 @@ export function createPostgresStorageAdapter(options) {
119
119
  metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
120
120
  captured_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
121
121
  );
122
+ `);
123
+ await pool.query(`
124
+ CREATE TABLE IF NOT EXISTS context_drop_comments (
125
+ id BIGSERIAL PRIMARY KEY,
126
+ feedback_id BIGINT NOT NULL REFERENCES context_drop_feedbacks(id) ON DELETE CASCADE,
127
+ author_type TEXT,
128
+ author_label TEXT,
129
+ body TEXT,
130
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
131
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
132
+ );
122
133
  `);
123
134
  await pool.query(`
124
135
  CREATE TABLE IF NOT EXISTS context_drop_attachments (
125
136
  id BIGSERIAL PRIMARY KEY,
126
137
  feedback_id BIGINT NOT NULL REFERENCES context_drop_feedbacks(id) ON DELETE CASCADE,
138
+ comment_id BIGINT REFERENCES context_drop_comments(id) ON DELETE CASCADE,
127
139
  element_reference_id BIGINT REFERENCES context_drop_element_references(id) ON DELETE SET NULL,
128
140
  attachment_type TEXT NOT NULL,
129
141
  filename TEXT,
@@ -134,6 +146,13 @@ export function createPostgresStorageAdapter(options) {
134
146
  metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
135
147
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
136
148
  );
149
+ `);
150
+ await pool.query(`
151
+ ALTER TABLE context_drop_attachments
152
+ ADD COLUMN IF NOT EXISTS comment_id BIGINT REFERENCES context_drop_comments(id) ON DELETE CASCADE;
153
+ `);
154
+ await pool.query(`
155
+ UPDATE context_drop_feedbacks SET status = 'fixed' WHERE status = 'resolved';
137
156
  `);
138
157
  })();
139
158
  }
@@ -141,16 +160,20 @@ export function createPostgresStorageAdapter(options) {
141
160
  }
142
161
  async function hydrateFeedbackRow(row) {
143
162
  const fbId = Number(row["id"]);
144
- const [elRes, attRes] = await Promise.all([
163
+ const [elRes, attRes, commentRes] = await Promise.all([
145
164
  pool.query(`SELECT id, feedback_id, client_ref, tag_name, selector, dom_path, text_content,
146
165
  attributes_snapshot, bounding_rect, viewport, metadata, captured_at
147
166
  FROM context_drop_element_references
148
167
  WHERE feedback_id = $1
149
168
  ORDER BY id ASC`, [fbId]),
150
- pool.query(`SELECT id, feedback_id, element_reference_id, attachment_type, filename,
169
+ pool.query(`SELECT id, feedback_id, comment_id, element_reference_id, attachment_type, filename,
151
170
  content_type, byte_size, blob_key, metadata, created_at
152
171
  FROM context_drop_attachments
153
172
  WHERE feedback_id = $1
173
+ ORDER BY id ASC`, [fbId]),
174
+ pool.query(`SELECT id, feedback_id, author_type, author_label, body, created_at, updated_at
175
+ FROM context_drop_comments
176
+ WHERE feedback_id = $1
154
177
  ORDER BY id ASC`, [fbId])
155
178
  ]);
156
179
  const elements = elRes.rows.map((el) => ({
@@ -167,9 +190,12 @@ export function createPostgresStorageAdapter(options) {
167
190
  metadata: parseJsonColumn(el["metadata"], {}),
168
191
  captured_at: toIsoString(el["captured_at"])
169
192
  }));
170
- const attachments = attRes.rows.map((att) => ({
193
+ const allAttachments = attRes.rows.map((att) => ({
171
194
  id: Number(att["id"]),
172
195
  feedback_id: fbId,
196
+ comment_id: att["comment_id"] !== null && att["comment_id"] !== undefined
197
+ ? Number(att["comment_id"])
198
+ : null,
173
199
  element_reference_id: att["element_reference_id"] !== null && att["element_reference_id"] !== undefined
174
200
  ? Number(att["element_reference_id"])
175
201
  : null,
@@ -183,10 +209,34 @@ export function createPostgresStorageAdapter(options) {
183
209
  metadata: parseJsonColumn(att["metadata"], {}),
184
210
  created_at: toIsoString(att["created_at"])
185
211
  }));
212
+ const attachments = allAttachments.filter((a) => a.comment_id === null || a.comment_id === undefined);
213
+ const attachmentsByComment = new Map();
214
+ for (const a of allAttachments) {
215
+ if (a.comment_id !== null && a.comment_id !== undefined) {
216
+ const list = attachmentsByComment.get(Number(a.comment_id)) ?? [];
217
+ list.push(a);
218
+ attachmentsByComment.set(Number(a.comment_id), list);
219
+ }
220
+ }
221
+ const comments = commentRes.rows.map((c) => {
222
+ const cid = Number(c["id"]);
223
+ return {
224
+ id: cid,
225
+ feedback_id: fbId,
226
+ author_type: c["author_type"] ?? null,
227
+ author_label: String(c["author_label"] || "You"),
228
+ body: c["body"] ?? null,
229
+ attachments: attachmentsByComment.get(cid) ?? [],
230
+ created_at: toIsoString(c["created_at"]),
231
+ updated_at: toIsoString(c["updated_at"])
232
+ };
233
+ });
234
+ const rawStatus = String(row["status"] ?? "new");
235
+ const normalizedStatus = (rawStatus === "resolved" ? "fixed" : rawStatus);
186
236
  return {
187
237
  id: fbId,
188
238
  environment: String(row["environment"] ?? "production"),
189
- status: String(row["status"] ?? "new"),
239
+ status: normalizedStatus,
190
240
  message: row["message"] ?? null,
191
241
  page_url: String(row["page_url"] ?? ""),
192
242
  user_agent: row["user_agent"] ?? null,
@@ -195,6 +245,7 @@ export function createPostgresStorageAdapter(options) {
195
245
  metadata: parseJsonColumn(row["metadata"], {}),
196
246
  element_references: elements,
197
247
  attachments,
248
+ comments,
198
249
  created_at: toIsoString(row["created_at"]),
199
250
  updated_at: toIsoString(row["updated_at"]),
200
251
  deleted_at: row["deleted_at"] ? toIsoString(row["deleted_at"]) : null
@@ -443,9 +494,14 @@ export function createPostgresStorageAdapter(options) {
443
494
  return null;
444
495
  const nextMessage = input.message !== undefined ? input.message : existing.message;
445
496
  const nextMetadata = input.metadata !== undefined ? input.metadata : existing.metadata;
497
+ const contentEdited = input.message !== undefined ||
498
+ input.metadata !== undefined ||
499
+ input.element_references !== undefined ||
500
+ input.attachments !== undefined;
501
+ const nextStatus = input.status ?? (contentEdited ? "updated" : existing.status);
446
502
  await pool.query(`UPDATE context_drop_feedbacks
447
- SET message = $1, metadata = $2::jsonb, updated_at = NOW()
448
- WHERE id = $3`, [nextMessage, JSON.stringify(nextMetadata || {}), fbId]);
503
+ SET message = $1, metadata = $2::jsonb, status = $3, updated_at = NOW()
504
+ WHERE id = $4`, [nextMessage, JSON.stringify(nextMetadata || {}), nextStatus, fbId]);
449
505
  const elIdByRef = new Map();
450
506
  if (input.element_references !== undefined) {
451
507
  await pool.query("DELETE FROM context_drop_element_references WHERE feedback_id = $1", [fbId]);
@@ -624,6 +680,60 @@ export function createPostgresStorageAdapter(options) {
624
680
  previous_status: existing.status,
625
681
  feedback: await hydrateFeedbackRow(row)
626
682
  };
683
+ },
684
+ async addComment(feedbackId, input) {
685
+ await ensureMigrated();
686
+ const fbId = Number(feedbackId);
687
+ const existing = await this.getFeedback(fbId);
688
+ if (!existing || existing.deleted_at)
689
+ return null;
690
+ const commentRes = await pool.query(`INSERT INTO context_drop_comments (feedback_id, author_type, author_label, body)
691
+ VALUES ($1, $2, $3, $4)
692
+ RETURNING id`, [fbId, input.author_type ?? "User", input.author_label || "You", input.body]);
693
+ const commentId = Number(commentRes.rows[0]["id"]);
694
+ for (const att of input.attachments ?? []) {
695
+ let blobKey = null;
696
+ let inlineData = null;
697
+ if (att.data) {
698
+ if (blobStore) {
699
+ const saved = await blobStore.putBlob({
700
+ key: `fb_${fbId}_comment_${commentId}_${crypto.randomUUID()}`,
701
+ data: att.data,
702
+ contentType: att.content_type || "image/png",
703
+ filename: att.filename || "image.png"
704
+ });
705
+ blobKey = saved.key;
706
+ }
707
+ else {
708
+ inlineData = Buffer.from(att.data);
709
+ }
710
+ }
711
+ await pool.query(`INSERT INTO context_drop_attachments
712
+ (feedback_id, comment_id, element_reference_id, attachment_type, filename, content_type, byte_size, blob_key, data, metadata)
713
+ VALUES ($1, $2, NULL, $3, $4, $5, $6, $7, $8, $9::jsonb)`, [
714
+ fbId,
715
+ commentId,
716
+ att.attachment_type,
717
+ att.filename,
718
+ att.content_type,
719
+ att.byte_size,
720
+ blobKey,
721
+ inlineData,
722
+ JSON.stringify(att.metadata || {})
723
+ ]);
724
+ }
725
+ const nextStatus = input.status ?? "updated";
726
+ await pool.query(`UPDATE context_drop_feedbacks SET status = $1, updated_at = NOW() WHERE id = $2`, [nextStatus, fbId]);
727
+ const updated = await this.getFeedback(fbId);
728
+ if (!updated)
729
+ return null;
730
+ const createdComment = (updated.comments ?? []).find((c) => Number(c.id) === commentId);
731
+ if (!createdComment)
732
+ return null;
733
+ return {
734
+ comment: createdComment,
735
+ feedback: updated
736
+ };
627
737
  }
628
738
  };
629
739
  }
@@ -1,6 +1,6 @@
1
1
  import type { BoundingRectSnapshot, SelectionMode, ViewportSnapshot, WidgetPosition } from "../../app/javascript/context_drop/types.js";
2
- export declare const VERSION = "0.3.0";
3
- export type FeedbackStatus = "new" | "reviewed" | "resolved" | "dismissed";
2
+ export declare const VERSION = "0.3.1";
3
+ export type FeedbackStatus = "new" | "updated" | "fixed" | "reviewed" | "dismissed";
4
4
  export declare const FEEDBACK_STATUSES: readonly FeedbackStatus[];
5
5
  export interface SubmitterIdentity {
6
6
  type?: string | null;
@@ -24,6 +24,7 @@ export interface StoredElementReference {
24
24
  export interface StoredAttachment {
25
25
  id: number | string;
26
26
  feedback_id: number | string;
27
+ comment_id?: number | string | null;
27
28
  element_reference_id: number | string | null;
28
29
  attachment_type: "image" | "screenshot";
29
30
  filename: string | null;
@@ -33,6 +34,16 @@ export interface StoredAttachment {
33
34
  metadata: Record<string, unknown>;
34
35
  created_at: string;
35
36
  }
37
+ export interface StoredComment {
38
+ id: number | string;
39
+ feedback_id: number | string;
40
+ author_type?: string | null;
41
+ author_label: string;
42
+ body: string | null;
43
+ attachments: StoredAttachment[];
44
+ created_at: string;
45
+ updated_at: string;
46
+ }
36
47
  export interface StoredFeedbackRecord {
37
48
  id: number | string;
38
49
  environment: string;
@@ -45,6 +56,8 @@ export interface StoredFeedbackRecord {
45
56
  metadata: Record<string, unknown>;
46
57
  element_references: StoredElementReference[];
47
58
  attachments: StoredAttachment[];
59
+ comments?: StoredComment[];
60
+ comments_count?: number;
48
61
  created_at: string;
49
62
  updated_at: string;
50
63
  deleted_at?: string | null;
@@ -59,6 +72,7 @@ export interface FeedbackSummaryItem {
59
72
  submitter: string;
60
73
  attachments_count: number;
61
74
  element_references_count: number;
75
+ comments_count?: number;
62
76
  element_selectors: string[];
63
77
  created_at: string;
64
78
  deleted?: boolean;
@@ -125,10 +139,18 @@ export interface CreateFeedbackRecordInput {
125
139
  }
126
140
  export interface UpdateFeedbackRecordInput {
127
141
  message?: string | null;
142
+ status?: FeedbackStatus;
128
143
  metadata?: Record<string, unknown>;
129
144
  element_references?: SanitizedElementInput[];
130
145
  attachments?: UpdateAttachmentSpec[];
131
146
  }
147
+ export interface CreateCommentInput {
148
+ author_type?: string | null;
149
+ author_label?: string | null;
150
+ body: string | null;
151
+ attachments: CreateAttachmentInput[];
152
+ status?: FeedbackStatus;
153
+ }
132
154
  export interface OwnFeedbackLookupQuery {
133
155
  submitter?: SubmitterIdentity | null;
134
156
  session_id?: string | null;
@@ -174,6 +196,10 @@ export interface StorageAdapter {
174
196
  previous_status: FeedbackStatus;
175
197
  feedback: StoredFeedbackRecord;
176
198
  } | null>;
199
+ addComment?(feedbackId: string | number, input: CreateCommentInput): Promise<{
200
+ comment: StoredComment;
201
+ feedback: StoredFeedbackRecord;
202
+ } | null>;
177
203
  getOwnershipSecret?(): Buffer;
178
204
  }
179
205
  export interface RemoteMcpEnvironmentConfig {
@@ -1,7 +1,8 @@
1
- export const VERSION = "0.3.0";
1
+ export const VERSION = "0.3.1";
2
2
  export const FEEDBACK_STATUSES = [
3
3
  "new",
4
+ "updated",
5
+ "fixed",
4
6
  "reviewed",
5
- "resolved",
6
7
  "dismissed"
7
8
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "context-drop",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Self-hosted contextual feedback widget, Next.js & Rails integration, and unified multi-environment MCP server for AI coding agents.",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",