context_drop 0.1.4 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +330 -116
- data/Rakefile +110 -1
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +6329 -682
- data/app/controllers/context_drop/agent_controller.rb +170 -0
- data/app/controllers/context_drop/application_controller.rb +52 -3
- data/app/controllers/context_drop/configs_controller.rb +12 -2
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +15 -11
- data/app/controllers/context_drop/feedbacks_controller.rb +396 -20
- data/app/controllers/context_drop/mcp_controller.rb +2 -1
- data/app/helpers/context_drop/widget_helper.rb +11 -1
- data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +1015 -89
- data/app/javascript/context_drop/api-client.ts +422 -19
- data/app/javascript/context_drop/element-picker.ts +186 -34
- data/app/javascript/context_drop/icons.ts +28 -0
- data/app/javascript/context_drop/markdown.ts +146 -0
- data/app/javascript/context_drop/sanitizer.ts +413 -2
- data/app/javascript/context_drop/screenshot.ts +103 -9
- data/app/javascript/context_drop/styles.ts +1705 -248
- data/app/javascript/context_drop/types.ts +243 -6
- data/app/javascript/context_drop/widget.ts +3318 -294
- data/app/models/context_drop/feedback.rb +88 -8
- data/app/services/context_drop/ownership_token.rb +114 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +13 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +19 -0
- data/app/views/layouts/context_drop/application.html.erb +6 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
- data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
- data/lib/context_drop/agent/key_store.rb +290 -0
- data/lib/context_drop/agent/llm_client.rb +413 -0
- data/lib/context_drop/agent/orchestrator.rb +314 -0
- data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
- data/lib/context_drop/configuration.rb +242 -3
- data/lib/context_drop/mcp/dispatcher.rb +71 -29
- data/lib/context_drop/mcp/environment_router.rb +115 -0
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +90 -9
- data/lib/context_drop/mcp/remote_client.rb +120 -0
- data/lib/context_drop/mcp/server.rb +9 -2
- data/lib/context_drop/mcp/tools/get_feedback.rb +62 -5
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +29 -4
- data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +195 -23
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +48 -5
- data/lib/context_drop/version.rb +1 -1
- data/lib/context_drop.rb +8 -2
- data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
- metadata +14 -2
|
@@ -3,7 +3,35 @@
|
|
|
3
3
|
module ContextDrop
|
|
4
4
|
class FeedbacksController < ApplicationController
|
|
5
5
|
before_action :enforce_submission_authorization!
|
|
6
|
-
before_action :enforce_rate_limit
|
|
6
|
+
before_action :enforce_rate_limit!, only: %i[create update destroy]
|
|
7
|
+
|
|
8
|
+
MAX_OWN_FEEDBACKS_LIMIT = 50
|
|
9
|
+
DEFAULT_OWN_FEEDBACKS_LIMIT = 20
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
raw_limit = params[:limit] ? params[:limit].to_i : DEFAULT_OWN_FEEDBACKS_LIMIT
|
|
13
|
+
limit = raw_limit.clamp(1, MAX_OWN_FEEDBACKS_LIMIT)
|
|
14
|
+
|
|
15
|
+
scope = own_active_feedbacks_scope
|
|
16
|
+
total = scope.count
|
|
17
|
+
raw_tokens = combined_raw_ownership_tokens
|
|
18
|
+
|
|
19
|
+
records = scope
|
|
20
|
+
.includes(:element_references, :attachments)
|
|
21
|
+
.recent
|
|
22
|
+
.limit(limit)
|
|
23
|
+
.map do |fb|
|
|
24
|
+
existing_tok = ContextDrop::OwnershipToken.find_token_for(raw_tokens, fb.id)
|
|
25
|
+
tok = existing_tok || ContextDrop::OwnershipToken.generate(fb.id)
|
|
26
|
+
serialize_own_feedback(fb, ownership_token: tok)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
render json: {
|
|
30
|
+
total_count: total,
|
|
31
|
+
total: total,
|
|
32
|
+
feedbacks: records
|
|
33
|
+
}, status: :ok
|
|
34
|
+
end
|
|
7
35
|
|
|
8
36
|
def create
|
|
9
37
|
payload = extract_feedback_payload
|
|
@@ -27,15 +55,24 @@ module ContextDrop
|
|
|
27
55
|
feedback = nil
|
|
28
56
|
|
|
29
57
|
ContextDrop::Feedback.transaction do
|
|
30
|
-
|
|
58
|
+
sanitized_meta = ContextDrop::MetadataSanitizer.sanitize_feedback_metadata(payload["metadata"])
|
|
59
|
+
host_env = ContextDrop.config.resolved_environment
|
|
60
|
+
sanitized_meta["environment"] = host_env
|
|
61
|
+
|
|
62
|
+
feedback_attrs = {
|
|
31
63
|
submitter: current_context_drop_submitter,
|
|
32
|
-
session_id: hashed_session_identifier,
|
|
64
|
+
session_id: hashed_session_identifier(initialize_if_missing: true),
|
|
33
65
|
message: payload["message"].to_s.strip.presence,
|
|
34
66
|
page_url: (payload["page_url"].presence || request.referer).to_s.strip,
|
|
35
67
|
user_agent: (payload["user_agent"].presence || request.user_agent).to_s.strip.presence,
|
|
36
|
-
metadata:
|
|
68
|
+
metadata: sanitized_meta,
|
|
37
69
|
status: "new"
|
|
38
|
-
|
|
70
|
+
}
|
|
71
|
+
if ContextDrop::Feedback.column_names.include?("environment")
|
|
72
|
+
feedback_attrs[:environment] = host_env
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
feedback = ContextDrop::Feedback.new(feedback_attrs)
|
|
39
76
|
|
|
40
77
|
element_refs_by_client_ref = {}
|
|
41
78
|
raw_elements.each_with_index do |raw_el, idx|
|
|
@@ -50,15 +87,7 @@ module ContextDrop
|
|
|
50
87
|
att_hash = stringify_hash(raw_att)
|
|
51
88
|
att_type = (att_hash["attachment_type"] || att_hash["type"] || "image").to_s.strip.downcase
|
|
52
89
|
att_meta = ContextDrop::MetadataSanitizer.sanitize_attachment_metadata(att_hash["metadata"])
|
|
53
|
-
|
|
54
|
-
linked_ref_key = (
|
|
55
|
-
att_hash["element_reference_ref"] ||
|
|
56
|
-
att_hash["element_attachment_ref"] ||
|
|
57
|
-
att_hash["client_ref"] ||
|
|
58
|
-
att_meta["element_attachment_ref"] ||
|
|
59
|
-
att_meta["client_ref"]
|
|
60
|
-
).to_s.strip.presence
|
|
61
|
-
|
|
90
|
+
linked_ref_key = extract_linked_element_ref_key(att_hash, att_meta)
|
|
62
91
|
linked_el = linked_ref_key ? element_refs_by_client_ref[linked_ref_key] : nil
|
|
63
92
|
file_source = resolve_attachment_file_source(att_hash)
|
|
64
93
|
|
|
@@ -71,7 +100,7 @@ module ContextDrop
|
|
|
71
100
|
|
|
72
101
|
att_record = feedback.attachments.build(
|
|
73
102
|
attachment_type: att_type,
|
|
74
|
-
element_reference: linked_el,
|
|
103
|
+
element_reference: (linked_el && !linked_el.new_record? ? linked_el : nil),
|
|
75
104
|
metadata: att_meta
|
|
76
105
|
)
|
|
77
106
|
pending_file_attachments << [att_record, linked_el, file_source]
|
|
@@ -95,19 +124,364 @@ module ContextDrop
|
|
|
95
124
|
|
|
96
125
|
return if performed?
|
|
97
126
|
|
|
98
|
-
|
|
127
|
+
feedback.reload
|
|
128
|
+
invoke_lifecycle_callback(:on_feedback_created, feedback)
|
|
129
|
+
ownership_token = ContextDrop::OwnershipToken.generate(feedback.id)
|
|
99
130
|
|
|
100
131
|
render json: {
|
|
101
132
|
id: feedback.id,
|
|
133
|
+
environment: feedback.environment_name,
|
|
102
134
|
status: feedback.status,
|
|
103
135
|
attachments_count: feedback.attachments.size,
|
|
104
136
|
element_references_count: feedback.element_references.size,
|
|
105
|
-
|
|
137
|
+
ownership_token: ownership_token,
|
|
138
|
+
feedback: serialize_own_feedback(feedback, ownership_token: ownership_token),
|
|
139
|
+
created_at: feedback.created_at.iso8601,
|
|
140
|
+
updated_at: feedback.updated_at.iso8601
|
|
106
141
|
}, status: :created
|
|
107
142
|
end
|
|
108
143
|
|
|
144
|
+
def update
|
|
145
|
+
feedback = ContextDrop::Feedback.includes(:element_references, :attachments).find_by(id: params[:id])
|
|
146
|
+
if feedback.nil? || feedback.deleted?
|
|
147
|
+
render json: { error: "Feedback not found" }, status: :not_found
|
|
148
|
+
return
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
payload = extract_feedback_payload
|
|
152
|
+
unless owns_feedback?(feedback, payload_token: payload["ownership_token"])
|
|
153
|
+
render json: { error: "Forbidden" }, status: :forbidden
|
|
154
|
+
return
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
has_elements_key = payload.key?("element_references")
|
|
158
|
+
has_attachments_key = payload.key?("attachments")
|
|
159
|
+
raw_elements = has_elements_key ? Array(payload["element_references"]) : nil
|
|
160
|
+
raw_attachments = has_attachments_key ? Array(payload["attachments"]) : nil
|
|
161
|
+
|
|
162
|
+
if has_attachments_key && raw_attachments.size > ContextDrop.config.max_attachments.to_i
|
|
163
|
+
render json: {
|
|
164
|
+
error: "Attachments count (#{raw_attachments.size}) exceeds maximum allowed (#{ContextDrop.config.max_attachments})"
|
|
165
|
+
}, status: :unprocessable_entity
|
|
166
|
+
return
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
if has_elements_key && raw_elements.size > ContextDrop.config.max_element_references.to_i
|
|
170
|
+
render json: {
|
|
171
|
+
error: "Element references count (#{raw_elements.size}) exceeds maximum allowed (#{ContextDrop.config.max_element_references})"
|
|
172
|
+
}, status: :unprocessable_entity
|
|
173
|
+
return
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
ContextDrop::Feedback.transaction do
|
|
177
|
+
if payload.key?("message")
|
|
178
|
+
feedback.message = payload["message"].to_s.strip.presence
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
if payload.key?("metadata")
|
|
182
|
+
sanitized_meta = ContextDrop::MetadataSanitizer.sanitize_feedback_metadata(payload["metadata"])
|
|
183
|
+
sanitized_meta["environment"] = feedback.environment_name
|
|
184
|
+
feedback.metadata = sanitized_meta
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
element_refs_by_client_ref = {}
|
|
188
|
+
if has_elements_key
|
|
189
|
+
sanitized_elements = raw_elements.map do |raw_el|
|
|
190
|
+
ContextDrop::MetadataSanitizer.sanitize_element_reference(raw_el)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
feedback.element_references.each(&:mark_for_destruction)
|
|
194
|
+
sanitized_elements.each_with_index do |sanitized_el, idx|
|
|
195
|
+
el_record = feedback.element_references.build(sanitized_el)
|
|
196
|
+
client_key = sanitized_el[:client_ref].presence || idx.to_s
|
|
197
|
+
element_refs_by_client_ref[client_key] = el_record
|
|
198
|
+
end
|
|
199
|
+
else
|
|
200
|
+
feedback.element_references.each_with_index do |el_record, idx|
|
|
201
|
+
client_key = el_record.client_ref.presence || idx.to_s
|
|
202
|
+
element_refs_by_client_ref[client_key] = el_record
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
retained_attachment_updates = []
|
|
207
|
+
pending_file_attachments = []
|
|
208
|
+
|
|
209
|
+
if has_attachments_key
|
|
210
|
+
existing_by_id = feedback.attachments.index_by { |a| a.id.to_s }
|
|
211
|
+
retained_ids = {}
|
|
212
|
+
|
|
213
|
+
raw_attachments.each do |raw_att|
|
|
214
|
+
att_hash = stringify_hash(raw_att)
|
|
215
|
+
has_new_binary = att_hash["signed_blob_id"].present? ||
|
|
216
|
+
att_hash["file"].present? ||
|
|
217
|
+
att_hash["data_url"].present? ||
|
|
218
|
+
att_hash["data"].present?
|
|
219
|
+
existing_id = (att_hash["existing_id"] || (!has_new_binary ? att_hash["id"] : nil)).to_s.strip
|
|
220
|
+
|
|
221
|
+
if existing_id.present?
|
|
222
|
+
existing_att = existing_by_id[existing_id]
|
|
223
|
+
unless existing_att
|
|
224
|
+
render json: { error: "Attachment does not belong to this feedback" }, status: :unprocessable_entity
|
|
225
|
+
raise ActiveRecord::Rollback
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
retained_ids[existing_id] = true
|
|
229
|
+
has_custom_meta = att_hash.key?("metadata") && att_hash["metadata"].is_a?(Hash)
|
|
230
|
+
att_meta = if has_custom_meta
|
|
231
|
+
merged_meta = (existing_att.metadata.is_a?(Hash) ? existing_att.metadata : {}).merge(
|
|
232
|
+
ContextDrop::MetadataSanitizer.sanitize_attachment_metadata(att_hash["metadata"])
|
|
233
|
+
)
|
|
234
|
+
merged_meta
|
|
235
|
+
else
|
|
236
|
+
existing_att.metadata.is_a?(Hash) ? existing_att.metadata : {}
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
linked_ref_key = extract_linked_element_ref_key(att_hash, att_meta)
|
|
240
|
+
linked_el = if linked_ref_key
|
|
241
|
+
element_refs_by_client_ref[linked_ref_key]
|
|
242
|
+
elsif !has_elements_key
|
|
243
|
+
existing_att.element_reference
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
retained_attachment_updates << [existing_att, linked_el, att_meta, has_custom_meta]
|
|
247
|
+
else
|
|
248
|
+
att_type = (att_hash["attachment_type"] || att_hash["type"] || "image").to_s.strip.downcase
|
|
249
|
+
att_meta = ContextDrop::MetadataSanitizer.sanitize_attachment_metadata(att_hash["metadata"])
|
|
250
|
+
linked_ref_key = extract_linked_element_ref_key(att_hash, att_meta)
|
|
251
|
+
linked_el = linked_ref_key ? element_refs_by_client_ref[linked_ref_key] : nil
|
|
252
|
+
file_source = resolve_attachment_file_source(att_hash)
|
|
253
|
+
|
|
254
|
+
if file_source[:dimensions] && att_meta["image_dimensions"].nil?
|
|
255
|
+
att_meta["image_dimensions"] = {
|
|
256
|
+
"width" => file_source[:dimensions][0],
|
|
257
|
+
"height" => file_source[:dimensions][1]
|
|
258
|
+
}
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
att_record = feedback.attachments.build(
|
|
262
|
+
attachment_type: att_type,
|
|
263
|
+
element_reference: (linked_el && !linked_el.new_record? ? linked_el : nil),
|
|
264
|
+
metadata: att_meta
|
|
265
|
+
)
|
|
266
|
+
pending_file_attachments << [att_record, linked_el, file_source]
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
feedback.attachments.each do |att|
|
|
271
|
+
next if att.new_record?
|
|
272
|
+
next if retained_ids[att.id.to_s]
|
|
273
|
+
|
|
274
|
+
att.mark_for_destruction
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
unless feedback.valid?
|
|
279
|
+
render json: { error: feedback.errors.full_messages.join(", "), errors: feedback.errors.full_messages },
|
|
280
|
+
status: :unprocessable_entity
|
|
281
|
+
raise ActiveRecord::Rollback
|
|
282
|
+
end
|
|
283
|
+
|
|
284
|
+
feedback.element_references.select(&:marked_for_destruction?).each(&:destroy!)
|
|
285
|
+
feedback.attachments.select(&:marked_for_destruction?).each(&:destroy!)
|
|
286
|
+
feedback.updated_at = Time.current
|
|
287
|
+
feedback.save!
|
|
288
|
+
|
|
289
|
+
retained_attachment_updates.each do |existing_att, linked_el, att_meta, has_custom_meta|
|
|
290
|
+
attrs_to_update = { element_reference_id: linked_el&.id }
|
|
291
|
+
attrs_to_update[:metadata] = att_meta if has_custom_meta
|
|
292
|
+
existing_att.update_columns(attrs_to_update)
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
pending_file_attachments.each do |att_record, linked_el, file_source|
|
|
296
|
+
if linked_el && att_record.element_reference_id.nil?
|
|
297
|
+
att_record.update_column(:element_reference_id, linked_el.id)
|
|
298
|
+
end
|
|
299
|
+
attach_binary_to_record!(att_record, file_source)
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
return if performed?
|
|
304
|
+
|
|
305
|
+
feedback.reload
|
|
306
|
+
invoke_lifecycle_callback(:on_feedback_updated, feedback)
|
|
307
|
+
|
|
308
|
+
raw_tokens = combined_raw_ownership_tokens(payload["ownership_token"])
|
|
309
|
+
ownership_token = ContextDrop::OwnershipToken.find_token_for(raw_tokens, feedback.id) ||
|
|
310
|
+
ContextDrop::OwnershipToken.generate(feedback.id)
|
|
311
|
+
|
|
312
|
+
render json: {
|
|
313
|
+
id: feedback.id,
|
|
314
|
+
environment: feedback.environment_name,
|
|
315
|
+
status: feedback.status,
|
|
316
|
+
message: feedback.message,
|
|
317
|
+
attachments_count: feedback.attachments.size,
|
|
318
|
+
element_references_count: feedback.element_references.size,
|
|
319
|
+
ownership_token: ownership_token,
|
|
320
|
+
feedback: serialize_own_feedback(feedback, ownership_token: ownership_token),
|
|
321
|
+
created_at: feedback.created_at.iso8601,
|
|
322
|
+
updated_at: feedback.updated_at.iso8601
|
|
323
|
+
}, status: :ok
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def destroy
|
|
327
|
+
feedback = ContextDrop::Feedback.find_by(id: params[:id])
|
|
328
|
+
if feedback.nil? || feedback.deleted?
|
|
329
|
+
render json: { error: "Feedback not found" }, status: :not_found
|
|
330
|
+
return
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
payload = extract_feedback_payload
|
|
334
|
+
unless owns_feedback?(feedback, payload_token: payload["ownership_token"])
|
|
335
|
+
render json: { error: "Forbidden" }, status: :forbidden
|
|
336
|
+
return
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
feedback.soft_delete!
|
|
340
|
+
invoke_lifecycle_callback(:on_feedback_deleted, feedback)
|
|
341
|
+
|
|
342
|
+
render json: {
|
|
343
|
+
id: feedback.id,
|
|
344
|
+
deleted: true,
|
|
345
|
+
deleted_at: feedback.deleted_at_value&.iso8601
|
|
346
|
+
}, status: :ok
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def attachment
|
|
350
|
+
feedback = ContextDrop::Feedback.find_by(id: params[:feedback_id])
|
|
351
|
+
if feedback.nil? || feedback.deleted?
|
|
352
|
+
head :not_found
|
|
353
|
+
return
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
unless owns_feedback?(feedback)
|
|
357
|
+
head :forbidden
|
|
358
|
+
return
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
att = feedback.attachments.find_by(id: params[:id])
|
|
362
|
+
if att.nil? || !att.respond_to?(:file) || !att.file.attached?
|
|
363
|
+
head :not_found
|
|
364
|
+
return
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
response.set_header("Cache-Control", "private, max-age=3600")
|
|
368
|
+
response.set_header("Content-Security-Policy", "default-src 'none'; sandbox")
|
|
369
|
+
send_data att.file.download,
|
|
370
|
+
type: att.file.content_type || "image/png",
|
|
371
|
+
disposition: "inline",
|
|
372
|
+
filename: att.file.filename.to_s
|
|
373
|
+
end
|
|
374
|
+
|
|
109
375
|
private
|
|
110
376
|
|
|
377
|
+
def own_active_feedbacks_scope
|
|
378
|
+
base = ContextDrop::Feedback.active
|
|
379
|
+
clauses = []
|
|
380
|
+
|
|
381
|
+
submitter = current_context_drop_submitter
|
|
382
|
+
if submitter && submitter.respond_to?(:id) && !submitter.id.nil?
|
|
383
|
+
clauses << base.where(submitter_type: submitter.class.name, submitter_id: submitter.id)
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
anon_base = base.where(submitter_id: nil)
|
|
387
|
+
sid = hashed_session_identifier(initialize_if_missing: false)
|
|
388
|
+
clauses << anon_base.where(session_id: sid) if sid.present?
|
|
389
|
+
|
|
390
|
+
token_ids = ContextDrop::OwnershipToken
|
|
391
|
+
.extract_verified_ids(combined_raw_ownership_tokens)
|
|
392
|
+
.map(&:to_i)
|
|
393
|
+
.select(&:positive?)
|
|
394
|
+
clauses << anon_base.where(id: token_ids) if token_ids.any?
|
|
395
|
+
|
|
396
|
+
return ContextDrop::Feedback.none if clauses.empty?
|
|
397
|
+
|
|
398
|
+
clauses.reduce { |acc, rel| acc.or(rel) }
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
def owns_feedback?(feedback, payload_token: nil)
|
|
402
|
+
submitter = current_context_drop_submitter
|
|
403
|
+
|
|
404
|
+
if feedback.submitter_id.present? || feedback.submitter_type.present?
|
|
405
|
+
return false unless submitter && submitter.respond_to?(:id) && !submitter.id.nil?
|
|
406
|
+
|
|
407
|
+
return feedback.submitter_type.to_s == submitter.class.name.to_s &&
|
|
408
|
+
feedback.submitter_id.to_s == submitter.id.to_s
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
raw_tokens = combined_raw_ownership_tokens(payload_token)
|
|
412
|
+
return true if ContextDrop::OwnershipToken.find_token_for(raw_tokens, feedback.id)
|
|
413
|
+
|
|
414
|
+
sid = hashed_session_identifier(initialize_if_missing: false)
|
|
415
|
+
return false if sid.blank? || feedback.session_id.blank?
|
|
416
|
+
|
|
417
|
+
ActiveSupport::SecurityUtils.secure_compare(feedback.session_id.to_s, sid.to_s)
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
def combined_raw_ownership_tokens(extra_token = nil)
|
|
421
|
+
[
|
|
422
|
+
extra_token,
|
|
423
|
+
request.headers["X-Context-Drop-Ownership-Token"],
|
|
424
|
+
request.headers["X-Context-Drop-Ownership-Tokens"],
|
|
425
|
+
params[:ownership_token],
|
|
426
|
+
params[:ownership_tokens]
|
|
427
|
+
].compact.map(&:to_s).reject(&:empty?).join(",")
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def serialize_own_feedback(feedback, ownership_token: nil)
|
|
431
|
+
elements_by_id = feedback.element_references.index_by(&:id)
|
|
432
|
+
|
|
433
|
+
{
|
|
434
|
+
id: feedback.id,
|
|
435
|
+
environment: feedback.environment_name,
|
|
436
|
+
status: feedback.status,
|
|
437
|
+
message: feedback.message,
|
|
438
|
+
page_url: feedback.page_url,
|
|
439
|
+
ownership_token: ownership_token,
|
|
440
|
+
created_at: feedback.created_at&.iso8601,
|
|
441
|
+
updated_at: feedback.updated_at&.iso8601,
|
|
442
|
+
element_references: feedback.element_references.map do |el|
|
|
443
|
+
{
|
|
444
|
+
id: el.id,
|
|
445
|
+
client_ref: el.client_ref,
|
|
446
|
+
tag_name: el.tag_name,
|
|
447
|
+
selector: el.selector,
|
|
448
|
+
dom_path: el.dom_path,
|
|
449
|
+
text_content: el.text_content,
|
|
450
|
+
attributes_snapshot: el.attributes_snapshot || {},
|
|
451
|
+
bounding_rect: el.bounding_rect || {},
|
|
452
|
+
viewport: el.viewport || {},
|
|
453
|
+
metadata: el.metadata || {},
|
|
454
|
+
captured_at: el.captured_at&.iso8601
|
|
455
|
+
}
|
|
456
|
+
end,
|
|
457
|
+
attachments: feedback.attachments.map do |att|
|
|
458
|
+
attached = att.respond_to?(:file) && att.file.attached?
|
|
459
|
+
linked_el = att.element_reference_id ? elements_by_id[att.element_reference_id] : att.element_reference
|
|
460
|
+
{
|
|
461
|
+
id: att.id,
|
|
462
|
+
attachment_type: att.attachment_type,
|
|
463
|
+
element_reference_id: att.element_reference_id,
|
|
464
|
+
element_reference_ref: linked_el&.client_ref,
|
|
465
|
+
filename: attached ? att.file.filename.to_s : nil,
|
|
466
|
+
content_type: attached ? att.file.content_type : nil,
|
|
467
|
+
byte_size: attached ? att.file.byte_size : nil,
|
|
468
|
+
metadata: att.metadata || {},
|
|
469
|
+
created_at: att.created_at&.iso8601
|
|
470
|
+
}
|
|
471
|
+
end
|
|
472
|
+
}
|
|
473
|
+
end
|
|
474
|
+
|
|
475
|
+
def extract_linked_element_ref_key(att_hash, att_meta)
|
|
476
|
+
(
|
|
477
|
+
att_hash["element_reference_ref"] ||
|
|
478
|
+
att_hash["element_attachment_ref"] ||
|
|
479
|
+
att_hash["client_ref"] ||
|
|
480
|
+
att_meta["element_attachment_ref"] ||
|
|
481
|
+
att_meta["client_ref"]
|
|
482
|
+
).to_s.strip.presence
|
|
483
|
+
end
|
|
484
|
+
|
|
111
485
|
def extract_feedback_payload
|
|
112
486
|
raw = params[:feedback].is_a?(ActionController::Parameters) || params[:feedback].is_a?(Hash) ? params[:feedback] : params
|
|
113
487
|
hash = stringify_hash(raw)
|
|
@@ -188,11 +562,13 @@ module ContextDrop
|
|
|
188
562
|
raise ContextDrop::UploadValidator::ValidationError, "Invalid base64 attachment data"
|
|
189
563
|
end
|
|
190
564
|
|
|
191
|
-
def
|
|
192
|
-
|
|
565
|
+
def invoke_lifecycle_callback(hook_name, feedback)
|
|
566
|
+
return unless ContextDrop.config.respond_to?(hook_name)
|
|
567
|
+
|
|
568
|
+
callback = ContextDrop.config.public_send(hook_name)
|
|
193
569
|
callback.call(feedback) if callback.respond_to?(:call)
|
|
194
570
|
rescue StandardError => e
|
|
195
|
-
Rails.logger.error("[ContextDrop]
|
|
571
|
+
Rails.logger.error("[ContextDrop] #{hook_name} callback error: #{e.class}: #{e.message}") if defined?(Rails.logger) && Rails.logger
|
|
196
572
|
end
|
|
197
573
|
|
|
198
574
|
def stringify_hash(obj)
|
|
@@ -13,7 +13,8 @@ module ContextDrop
|
|
|
13
13
|
def create
|
|
14
14
|
raw_body = request.raw_post.to_s
|
|
15
15
|
payload = JSON.parse(raw_body)
|
|
16
|
-
|
|
16
|
+
# Remote HTTP endpoints strictly serve their own host environment and never recursively fan out
|
|
17
|
+
response = ContextDrop::MCP::Server.handle_http_payload(payload, local_only: true)
|
|
17
18
|
|
|
18
19
|
if response.nil?
|
|
19
20
|
head :accepted
|
|
@@ -16,7 +16,17 @@ module ContextDrop
|
|
|
16
16
|
controller_instance = respond_to?(:controller) ? controller : nil
|
|
17
17
|
return nil unless cfg.submission_authorized?(controller_instance)
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
req = if respond_to?(:request)
|
|
20
|
+
request
|
|
21
|
+
elsif controller_instance.respond_to?(:request)
|
|
22
|
+
controller_instance.request
|
|
23
|
+
end
|
|
24
|
+
merged_options = if req
|
|
25
|
+
options.merge(agent_enabled: cfg.local_agent_allowed? && cfg.loopback_request?(req))
|
|
26
|
+
else
|
|
27
|
+
options
|
|
28
|
+
end
|
|
29
|
+
widget_config = cfg.public_widget_config(merged_options)
|
|
20
30
|
mount_path = resolve_context_drop_mount_path(options[:endpoint])
|
|
21
31
|
custom_metadata = options[:metadata].is_a?(Hash) ? options[:metadata] : {}
|
|
22
32
|
|