context_drop 0.3.3 → 0.3.5
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 +74 -1
- data/app/assets/javascripts/context_drop/context_drop.js +152 -11
- data/app/controllers/context_drop/application_controller.rb +12 -0
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +38 -0
- data/app/controllers/context_drop/dashboard/integrations_controller.rb +140 -0
- data/app/controllers/context_drop/feedbacks_controller.rb +38 -14
- data/app/controllers/context_drop/mcp_events_controller.rb +66 -0
- data/app/helpers/context_drop/dashboard_helper.rb +6 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +229 -18
- data/app/javascript/context_drop/styles.ts +16 -0
- data/app/javascript/context_drop/widget.ts +136 -11
- data/app/models/context_drop/event_occurrence.rb +34 -0
- data/app/models/context_drop/mcp_event_subscription.rb +25 -0
- data/app/models/context_drop/notification_destination.rb +84 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +8 -10
- data/app/views/context_drop/dashboard/integrations/_form.html.erb +92 -0
- data/app/views/context_drop/dashboard/integrations/edit.html.erb +13 -0
- data/app/views/context_drop/dashboard/integrations/index.html.erb +101 -0
- data/app/views/context_drop/dashboard/integrations/new.html.erb +13 -0
- data/app/views/layouts/context_drop/application.html.erb +78 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20261124000001_create_context_drop_events_and_notifications.rb +47 -0
- data/lib/context_drop/feedback_events/publisher.rb +100 -0
- data/lib/context_drop/mcp/dispatcher.rb +20 -5
- data/lib/context_drop/mcp/event_stream_registry.rb +34 -0
- data/lib/context_drop/mcp/events.rb +178 -0
- data/lib/context_drop/notification_secrets.rb +85 -0
- data/lib/context_drop/notifications/deliverer.rb +49 -0
- data/lib/context_drop/notifications/lark_client.rb +140 -0
- data/lib/context_drop/notifications/webhook_client.rb +103 -0
- data/lib/context_drop/version.rb +1 -1
- data/lib/context_drop.rb +5 -0
- metadata +21 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module ContextDrop
|
|
8
|
+
module Notifications
|
|
9
|
+
class LarkClient
|
|
10
|
+
class DeliveryError < StandardError; end
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
def deliver(destination, occurrence)
|
|
14
|
+
settings = destination.settings.is_a?(Hash) ? destination.settings : {}
|
|
15
|
+
secrets = destination.secrets
|
|
16
|
+
app_id = secrets["app_id"].to_s.strip
|
|
17
|
+
app_secret = secrets["app_secret"].to_s.strip
|
|
18
|
+
receive_id = settings["receive_id"].to_s.strip
|
|
19
|
+
receive_id_type = settings["receive_id_type"].to_s.strip.presence || "chat_id"
|
|
20
|
+
api_host = settings["api_host"].to_s.strip.presence || "https://open.larksuite.com"
|
|
21
|
+
|
|
22
|
+
raise DeliveryError, "Lark app_id missing" if app_id.empty?
|
|
23
|
+
raise DeliveryError, "Lark app_secret missing" if app_secret.empty?
|
|
24
|
+
raise DeliveryError, "Lark receive_id missing" if receive_id.empty?
|
|
25
|
+
|
|
26
|
+
token = fetch_tenant_access_token(api_host, app_id, app_secret)
|
|
27
|
+
card = build_message_card(occurrence)
|
|
28
|
+
post_message(api_host, token, receive_id_type, receive_id, card)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def fetch_tenant_access_token(api_host, app_id, app_secret)
|
|
34
|
+
uri = URI.join("#{api_host}/", "open-apis/auth/v3/tenant_access_token/internal")
|
|
35
|
+
body = JSON.generate(app_id: app_id, app_secret: app_secret)
|
|
36
|
+
res = post_json(uri, body, "Content-Type" => "application/json")
|
|
37
|
+
parsed = JSON.parse(res.body)
|
|
38
|
+
raise DeliveryError, parsed["msg"].to_s unless parsed["code"].to_i.zero?
|
|
39
|
+
|
|
40
|
+
parsed["tenant_access_token"].to_s
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def post_message(api_host, token, receive_id_type, receive_id, card)
|
|
44
|
+
uri = URI.join("#{api_host}/", "open-apis/im/v1/messages")
|
|
45
|
+
uri.query = URI.encode_www_form(receive_id_type: receive_id_type)
|
|
46
|
+
payload = {
|
|
47
|
+
receive_id: receive_id,
|
|
48
|
+
msg_type: "interactive",
|
|
49
|
+
content: card
|
|
50
|
+
}
|
|
51
|
+
res = post_json(uri, JSON.generate(payload), "Authorization" => "Bearer #{token}", "Content-Type" => "application/json")
|
|
52
|
+
parsed = JSON.parse(res.body)
|
|
53
|
+
raise DeliveryError, parsed["msg"].to_s unless parsed["code"].to_i.zero?
|
|
54
|
+
|
|
55
|
+
true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def build_message_card(occurrence)
|
|
59
|
+
data = occurrence.data.is_a?(Hash) ? occurrence.data : {}
|
|
60
|
+
title = event_title(occurrence.name)
|
|
61
|
+
env = data["environment"].to_s
|
|
62
|
+
status = data["status"].to_s
|
|
63
|
+
prev = data["previous_status"].to_s
|
|
64
|
+
status_line = prev.present? ? "#{prev} → #{status}" : status
|
|
65
|
+
msg = data["message"].to_s
|
|
66
|
+
page = data["page_url"].to_s
|
|
67
|
+
dash = data["dashboard_url"].to_s
|
|
68
|
+
|
|
69
|
+
lines = [
|
|
70
|
+
"**Feedback ##{data['feedback_id']}** · `#{env}`",
|
|
71
|
+
"**Status:** #{status_line}",
|
|
72
|
+
msg.present? ? "> #{msg}" : nil,
|
|
73
|
+
page.present? ? "**Page:** #{page}" : nil
|
|
74
|
+
].compact.join("\n")
|
|
75
|
+
|
|
76
|
+
card = {
|
|
77
|
+
config: { wide_screen_mode: true },
|
|
78
|
+
header: {
|
|
79
|
+
template: header_color(occurrence.name),
|
|
80
|
+
title: { tag: "plain_text", content: title }
|
|
81
|
+
},
|
|
82
|
+
elements: [
|
|
83
|
+
{ tag: "div", text: { tag: "lark_md", content: lines } }
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
if dash.present?
|
|
87
|
+
card[:elements] << {
|
|
88
|
+
tag: "action",
|
|
89
|
+
actions: [
|
|
90
|
+
{
|
|
91
|
+
tag: "button",
|
|
92
|
+
text: { tag: "plain_text", content: "Open in Dashboard" },
|
|
93
|
+
type: "primary",
|
|
94
|
+
multi_url: {
|
|
95
|
+
url: dash,
|
|
96
|
+
pc_url: dash,
|
|
97
|
+
android_url: dash,
|
|
98
|
+
ios_url: dash
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
JSON.generate(card)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def event_title(name)
|
|
108
|
+
{
|
|
109
|
+
"feedback.created" => "New ContextDrop feedback",
|
|
110
|
+
"feedback.updated" => "Feedback updated",
|
|
111
|
+
"feedback.status_changed" => "Feedback status changed",
|
|
112
|
+
"feedback.deleted" => "Feedback deleted"
|
|
113
|
+
}[name] || "ContextDrop feedback event"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def header_color(name)
|
|
117
|
+
case name
|
|
118
|
+
when "feedback.created" then "blue"
|
|
119
|
+
when "feedback.status_changed" then "orange"
|
|
120
|
+
when "feedback.deleted" then "red"
|
|
121
|
+
else "wathet"
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def post_json(uri, body, headers)
|
|
126
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
127
|
+
http.use_ssl = uri.scheme == "https"
|
|
128
|
+
http.open_timeout = 8
|
|
129
|
+
http.read_timeout = 15
|
|
130
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
|
131
|
+
req.body = body
|
|
132
|
+
res = http.request(req)
|
|
133
|
+
return res if res.is_a?(Net::HTTPSuccess)
|
|
134
|
+
|
|
135
|
+
raise DeliveryError, "HTTP #{res.code}: #{res.body.to_s.truncate(300)}"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "uri"
|
|
7
|
+
require_relative "../../context_drop/base64_util"
|
|
8
|
+
|
|
9
|
+
module ContextDrop
|
|
10
|
+
module Notifications
|
|
11
|
+
class WebhookClient
|
|
12
|
+
class DeliveryError < StandardError; end
|
|
13
|
+
|
|
14
|
+
USER_AGENT = "ContextDrop-Webhook/1.0"
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def deliver_destination(destination, occurrence)
|
|
18
|
+
url = destination.settings["url"].to_s.strip
|
|
19
|
+
raise DeliveryError, "Webhook URL missing" if url.empty?
|
|
20
|
+
|
|
21
|
+
uri = validate_https_uri!(url)
|
|
22
|
+
body = JSON.generate(occurrence.occurrence_payload)
|
|
23
|
+
headers = signed_headers(secret: destination.secrets["signing_secret"].to_s, body: body, msg_id: occurrence.event_id)
|
|
24
|
+
headers["Content-Type"] = "application/json"
|
|
25
|
+
headers["User-Agent"] = USER_AGENT
|
|
26
|
+
post_json(uri, body, headers)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def deliver_mcp_subscription(subscription, occurrence)
|
|
30
|
+
uri = validate_https_uri!(subscription.callback_url)
|
|
31
|
+
body = JSON.generate(occurrence.occurrence_payload)
|
|
32
|
+
headers = signed_headers(
|
|
33
|
+
secret: subscription.signing_secret,
|
|
34
|
+
body: body,
|
|
35
|
+
msg_id: occurrence.event_id
|
|
36
|
+
)
|
|
37
|
+
headers["Content-Type"] = "application/json"
|
|
38
|
+
headers["User-Agent"] = USER_AGENT
|
|
39
|
+
post_json(uri, body, headers)
|
|
40
|
+
subscription.update_columns(last_cursor: occurrence.cursor, updated_at: Time.current)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def validate_https_uri!(url)
|
|
44
|
+
uri = URI.parse(url)
|
|
45
|
+
raise DeliveryError, "Webhook URL must use HTTPS" unless uri.is_a?(URI::HTTPS)
|
|
46
|
+
raise DeliveryError, "Webhook URL host missing" if uri.host.to_s.strip.empty?
|
|
47
|
+
raise DeliveryError, "Webhook URL blocked (private network)" if private_or_local_host?(uri.host)
|
|
48
|
+
|
|
49
|
+
uri
|
|
50
|
+
rescue URI::InvalidURIError => e
|
|
51
|
+
raise DeliveryError, "Invalid webhook URL: #{e.message}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def signed_headers(secret:, body:, msg_id:)
|
|
55
|
+
timestamp = Time.now.to_i.to_s
|
|
56
|
+
base = "#{msg_id}.#{timestamp}.#{body}"
|
|
57
|
+
sig = if secret.to_s.strip.empty?
|
|
58
|
+
""
|
|
59
|
+
else
|
|
60
|
+
"v1,#{ContextDrop::Base64Util.strict_encode64(OpenSSL::HMAC.digest("SHA256", secret, base))}"
|
|
61
|
+
end
|
|
62
|
+
{
|
|
63
|
+
"webhook-id" => msg_id,
|
|
64
|
+
"webhook-timestamp" => timestamp,
|
|
65
|
+
"webhook-signature" => sig
|
|
66
|
+
}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def post_json(uri, body, headers)
|
|
72
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
73
|
+
http.use_ssl = uri.scheme == "https"
|
|
74
|
+
http.open_timeout = 8
|
|
75
|
+
http.read_timeout = 12
|
|
76
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
|
77
|
+
req.body = body
|
|
78
|
+
res = http.request(req)
|
|
79
|
+
return res if res.is_a?(Net::HTTPSuccess)
|
|
80
|
+
|
|
81
|
+
raise DeliveryError, "HTTP #{res.code}: #{res.body.to_s.truncate(300)}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def private_or_local_host?(host)
|
|
85
|
+
down = host.to_s.strip.downcase
|
|
86
|
+
return true if %w[localhost metadata.google.internal].include?(down)
|
|
87
|
+
|
|
88
|
+
if down.match?(/\A\d{1,3}(\.\d{1,3}){3}\z/)
|
|
89
|
+
octets = down.split(".").map(&:to_i)
|
|
90
|
+
return true if octets[0] == 10
|
|
91
|
+
return true if octets[0] == 127
|
|
92
|
+
return true if octets[0] == 0
|
|
93
|
+
return true if octets[0] == 169 && octets[1] == 254
|
|
94
|
+
return true if octets[0] == 192 && octets[1] == 168
|
|
95
|
+
return true if octets[0] == 172 && octets[1] >= 16 && octets[1] <= 31
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
false
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
data/lib/context_drop/version.rb
CHANGED
data/lib/context_drop.rb
CHANGED
|
@@ -7,6 +7,11 @@ end
|
|
|
7
7
|
require_relative "context_drop/version"
|
|
8
8
|
require_relative "context_drop/base64_util"
|
|
9
9
|
require_relative "context_drop/configuration"
|
|
10
|
+
require_relative "context_drop/notification_secrets"
|
|
11
|
+
require_relative "context_drop/feedback_events/publisher"
|
|
12
|
+
require_relative "context_drop/notifications/webhook_client"
|
|
13
|
+
require_relative "context_drop/notifications/lark_client"
|
|
14
|
+
require_relative "context_drop/notifications/deliverer"
|
|
10
15
|
require_relative "context_drop/mcp/server"
|
|
11
16
|
require_relative "context_drop/agent/key_store"
|
|
12
17
|
require_relative "context_drop/agent/workspace_sandbox"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: context_drop
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kemal Elmizan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|
|
@@ -173,9 +173,11 @@ files:
|
|
|
173
173
|
- app/controllers/context_drop/attachments_controller.rb
|
|
174
174
|
- app/controllers/context_drop/configs_controller.rb
|
|
175
175
|
- app/controllers/context_drop/dashboard/feedbacks_controller.rb
|
|
176
|
+
- app/controllers/context_drop/dashboard/integrations_controller.rb
|
|
176
177
|
- app/controllers/context_drop/feedbacks_controller.rb
|
|
177
178
|
- app/controllers/context_drop/health_controller.rb
|
|
178
179
|
- app/controllers/context_drop/mcp_controller.rb
|
|
180
|
+
- app/controllers/context_drop/mcp_events_controller.rb
|
|
179
181
|
- app/helpers/context_drop/dashboard_helper.rb
|
|
180
182
|
- app/helpers/context_drop/widget_helper.rb
|
|
181
183
|
- app/javascript/context_drop/__tests__/api-client.test.ts
|
|
@@ -194,12 +196,19 @@ files:
|
|
|
194
196
|
- app/models/context_drop/attachment.rb
|
|
195
197
|
- app/models/context_drop/comment.rb
|
|
196
198
|
- app/models/context_drop/element_reference.rb
|
|
199
|
+
- app/models/context_drop/event_occurrence.rb
|
|
197
200
|
- app/models/context_drop/feedback.rb
|
|
201
|
+
- app/models/context_drop/mcp_event_subscription.rb
|
|
202
|
+
- app/models/context_drop/notification_destination.rb
|
|
198
203
|
- app/services/context_drop/metadata_sanitizer.rb
|
|
199
204
|
- app/services/context_drop/ownership_token.rb
|
|
200
205
|
- app/services/context_drop/upload_validator.rb
|
|
201
206
|
- app/views/context_drop/dashboard/feedbacks/index.html.erb
|
|
202
207
|
- app/views/context_drop/dashboard/feedbacks/show.html.erb
|
|
208
|
+
- app/views/context_drop/dashboard/integrations/_form.html.erb
|
|
209
|
+
- app/views/context_drop/dashboard/integrations/edit.html.erb
|
|
210
|
+
- app/views/context_drop/dashboard/integrations/index.html.erb
|
|
211
|
+
- app/views/context_drop/dashboard/integrations/new.html.erb
|
|
203
212
|
- app/views/layouts/context_drop/application.html.erb
|
|
204
213
|
- config/routes.rb
|
|
205
214
|
- db/migrate/20261109000001_create_context_drop_feedbacks.rb
|
|
@@ -208,6 +217,7 @@ files:
|
|
|
208
217
|
- db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb
|
|
209
218
|
- db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb
|
|
210
219
|
- db/migrate/20261116000001_create_context_drop_comments_and_update_statuses.rb
|
|
220
|
+
- db/migrate/20261124000001_create_context_drop_events_and_notifications.rb
|
|
211
221
|
- lib/context_drop.rb
|
|
212
222
|
- lib/context_drop/agent/key_store.rb
|
|
213
223
|
- lib/context_drop/agent/llm_client.rb
|
|
@@ -216,8 +226,11 @@ files:
|
|
|
216
226
|
- lib/context_drop/base64_util.rb
|
|
217
227
|
- lib/context_drop/configuration.rb
|
|
218
228
|
- lib/context_drop/engine.rb
|
|
229
|
+
- lib/context_drop/feedback_events/publisher.rb
|
|
219
230
|
- lib/context_drop/mcp/dispatcher.rb
|
|
220
231
|
- lib/context_drop/mcp/environment_router.rb
|
|
232
|
+
- lib/context_drop/mcp/event_stream_registry.rb
|
|
233
|
+
- lib/context_drop/mcp/events.rb
|
|
221
234
|
- lib/context_drop/mcp/prompts/investigate_feedback.rb
|
|
222
235
|
- lib/context_drop/mcp/remote_client.rb
|
|
223
236
|
- lib/context_drop/mcp/server.rb
|
|
@@ -228,6 +241,10 @@ files:
|
|
|
228
241
|
- lib/context_drop/mcp/tools/list_environments.rb
|
|
229
242
|
- lib/context_drop/mcp/tools/list_feedbacks.rb
|
|
230
243
|
- lib/context_drop/mcp/tools/update_feedback_status.rb
|
|
244
|
+
- lib/context_drop/notification_secrets.rb
|
|
245
|
+
- lib/context_drop/notifications/deliverer.rb
|
|
246
|
+
- lib/context_drop/notifications/lark_client.rb
|
|
247
|
+
- lib/context_drop/notifications/webhook_client.rb
|
|
231
248
|
- lib/context_drop/version.rb
|
|
232
249
|
- lib/generators/context_drop/install/install_generator.rb
|
|
233
250
|
- lib/generators/context_drop/install/templates/initializer.rb.tt
|
|
@@ -248,14 +265,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
248
265
|
requirements:
|
|
249
266
|
- - ">="
|
|
250
267
|
- !ruby/object:Gem::Version
|
|
251
|
-
version: 3.
|
|
268
|
+
version: 3.3.14
|
|
252
269
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
253
270
|
requirements:
|
|
254
271
|
- - ">="
|
|
255
272
|
- !ruby/object:Gem::Version
|
|
256
273
|
version: '0'
|
|
257
274
|
requirements: []
|
|
258
|
-
rubygems_version: 3.
|
|
275
|
+
rubygems_version: 3.5.22
|
|
259
276
|
signing_key:
|
|
260
277
|
specification_version: 4
|
|
261
278
|
summary: Self-hosted contextual feedback engine, Shadow DOM widget, and MCP server
|