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
|
@@ -569,6 +569,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
569
569
|
this.setCornerPosition(partial.position);
|
|
570
570
|
}
|
|
571
571
|
const nowAgentEnabled = Boolean(this.config.agent?.enabled);
|
|
572
|
+
this.syncAgentSidebarMount();
|
|
572
573
|
if (nowAgentEnabled && !wasAgentEnabled) {
|
|
573
574
|
this.surfaceMode = "agent";
|
|
574
575
|
if (this.isOpen) {
|
|
@@ -1787,9 +1788,95 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1787
1788
|
}
|
|
1788
1789
|
}
|
|
1789
1790
|
|
|
1791
|
+
private clearAgentSidebarRefs(): void {
|
|
1792
|
+
this.agentSidebarEl = null;
|
|
1793
|
+
this.sidebarPinBtn = null;
|
|
1794
|
+
this.sidebarEnvPillEl = null;
|
|
1795
|
+
this.sidebarThemeToggleBtn = null;
|
|
1796
|
+
this.sidebarPushBtn = null;
|
|
1797
|
+
this.keyDotEl = null;
|
|
1798
|
+
this.providerPillLabelEl = null;
|
|
1799
|
+
this.keysToggleBtn = null;
|
|
1800
|
+
this.feedbacksToggleBtn = null;
|
|
1801
|
+
this.byokDrawerEl = null;
|
|
1802
|
+
this.byokProviderSelect = null;
|
|
1803
|
+
this.byokModelInput = null;
|
|
1804
|
+
this.byokModelPresetsSelect = null;
|
|
1805
|
+
this.byokBaseUrlField = null;
|
|
1806
|
+
this.byokBaseUrlInput = null;
|
|
1807
|
+
this.byokKeySourceBadge = null;
|
|
1808
|
+
this.byokKeyInput = null;
|
|
1809
|
+
this.feedbacksDrawerEl = null;
|
|
1810
|
+
this.feedbacksTabsEl = null;
|
|
1811
|
+
this.feedbacksListEl = null;
|
|
1812
|
+
this.agentStreamEl = null;
|
|
1813
|
+
this.agentTrayEl = null;
|
|
1814
|
+
this.agentStatusEl = null;
|
|
1815
|
+
this.agentTextareaEl = null;
|
|
1816
|
+
this.agentSendBtn = null;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
private syncAgentSidebarMount(): void {
|
|
1820
|
+
const enabled = Boolean(this.config.agent?.enabled);
|
|
1821
|
+
if (enabled) {
|
|
1822
|
+
if (!this.agentSidebarEl && this.shadow) {
|
|
1823
|
+
const sidebar = this.buildAgentSidebarDom();
|
|
1824
|
+
sidebar.setAttribute("data-theme", this.currentTheme);
|
|
1825
|
+
if (
|
|
1826
|
+
this.bookCornerBtn &&
|
|
1827
|
+
this.bookCornerBtn.parentNode === this.shadow &&
|
|
1828
|
+
typeof this.shadow.insertBefore === "function"
|
|
1829
|
+
) {
|
|
1830
|
+
this.shadow.insertBefore(sidebar, this.bookCornerBtn);
|
|
1831
|
+
} else {
|
|
1832
|
+
this.shadow.appendChild(sidebar);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
this.isByokDrawerOpen = false;
|
|
1839
|
+
this.isFeedbacksDrawerOpen = false;
|
|
1840
|
+
if (this.agentSidebarEl) {
|
|
1841
|
+
this.agentSidebarEl.parentNode?.removeChild(this.agentSidebarEl);
|
|
1842
|
+
}
|
|
1843
|
+
this.clearAgentSidebarRefs();
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
private buildFormShell(): HTMLFormElement {
|
|
1847
|
+
const form = document.createElement("form");
|
|
1848
|
+
form.className = "cd-form-shell";
|
|
1849
|
+
form.autocomplete = "off";
|
|
1850
|
+
form.setAttribute("autocomplete", "off");
|
|
1851
|
+
form.noValidate = true;
|
|
1852
|
+
form.setAttribute("novalidate", "");
|
|
1853
|
+
form.setAttribute("data-1p-ignore", "true");
|
|
1854
|
+
form.setAttribute("data-lpignore", "true");
|
|
1855
|
+
form.setAttribute("data-bwignore", "true");
|
|
1856
|
+
form.setAttribute("data-form-type", "other");
|
|
1857
|
+
form.addEventListener("submit", (ev) => {
|
|
1858
|
+
ev.preventDefault();
|
|
1859
|
+
});
|
|
1860
|
+
return form;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
private applyByokAutofillIgnore(control: HTMLInputElement | HTMLSelectElement): void {
|
|
1864
|
+
control.autocomplete = "off";
|
|
1865
|
+
control.setAttribute("autocomplete", "off");
|
|
1866
|
+
control.spellcheck = false;
|
|
1867
|
+
control.setAttribute("spellcheck", "false");
|
|
1868
|
+
control.setAttribute("autocorrect", "off");
|
|
1869
|
+
control.setAttribute("autocapitalize", "off");
|
|
1870
|
+
control.setAttribute("data-1p-ignore", "true");
|
|
1871
|
+
control.setAttribute("data-lpignore", "true");
|
|
1872
|
+
control.setAttribute("data-bwignore", "true");
|
|
1873
|
+
control.setAttribute("data-form-type", "other");
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1790
1876
|
private renderShadowDom(): void {
|
|
1791
1877
|
if (!this.shadow) return;
|
|
1792
1878
|
this.shadow.innerHTML = "";
|
|
1879
|
+
this.clearAgentSidebarRefs();
|
|
1793
1880
|
|
|
1794
1881
|
const styleEl = document.createElement("style");
|
|
1795
1882
|
styleEl.textContent = WIDGET_SHADOW_STYLES;
|
|
@@ -1809,9 +1896,11 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1809
1896
|
|
|
1810
1897
|
this.shadow.appendChild(root);
|
|
1811
1898
|
|
|
1812
|
-
// 3. Docked Local BYOK Agentic Coding Sidebar (
|
|
1813
|
-
|
|
1814
|
-
|
|
1899
|
+
// 3. Docked Local BYOK Agentic Coding Sidebar (mounted only when local agent is enabled)
|
|
1900
|
+
if (Boolean(this.config.agent?.enabled)) {
|
|
1901
|
+
const sidebar = this.buildAgentSidebarDom();
|
|
1902
|
+
this.shadow.appendChild(sidebar);
|
|
1903
|
+
}
|
|
1815
1904
|
|
|
1816
1905
|
// 4. Book-Corner Fold Launcher (flush at viewport corner, peels into pushpin on drag)
|
|
1817
1906
|
const bookCorner = document.createElement("button");
|
|
@@ -2071,8 +2160,13 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2071
2160
|
this.statusEl = status;
|
|
2072
2161
|
composer.appendChild(status);
|
|
2073
2162
|
|
|
2163
|
+
const composerForm = this.buildFormShell();
|
|
2164
|
+
|
|
2074
2165
|
const fileInput = document.createElement("input");
|
|
2075
2166
|
fileInput.type = "file";
|
|
2167
|
+
fileInput.setAttribute("type", "file");
|
|
2168
|
+
fileInput.autocomplete = "off";
|
|
2169
|
+
fileInput.setAttribute("autocomplete", "off");
|
|
2076
2170
|
fileInput.multiple = true;
|
|
2077
2171
|
fileInput.accept = this.config.limits.allowed_content_types.join(",");
|
|
2078
2172
|
fileInput.hidden = true;
|
|
@@ -2083,7 +2177,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2083
2177
|
}
|
|
2084
2178
|
});
|
|
2085
2179
|
this.fileInputEl = fileInput;
|
|
2086
|
-
|
|
2180
|
+
composerForm.appendChild(fileInput);
|
|
2087
2181
|
|
|
2088
2182
|
const promptShell = document.createElement("div");
|
|
2089
2183
|
promptShell.className = "cd-prompt-shell";
|
|
@@ -2115,6 +2209,12 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2115
2209
|
|
|
2116
2210
|
const textarea = document.createElement("textarea");
|
|
2117
2211
|
textarea.className = "cd-textarea";
|
|
2212
|
+
textarea.autocomplete = "off";
|
|
2213
|
+
textarea.setAttribute("autocomplete", "off");
|
|
2214
|
+
textarea.setAttribute("data-1p-ignore", "true");
|
|
2215
|
+
textarea.setAttribute("data-lpignore", "true");
|
|
2216
|
+
textarea.setAttribute("data-bwignore", "true");
|
|
2217
|
+
textarea.setAttribute("data-form-type", "other");
|
|
2118
2218
|
textarea.placeholder = this.config.placeholder;
|
|
2119
2219
|
textarea.setAttribute("aria-label", "Feedback description");
|
|
2120
2220
|
textarea.addEventListener("keydown", (ev) => {
|
|
@@ -2157,7 +2257,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2157
2257
|
toolbar.appendChild(actions);
|
|
2158
2258
|
toolbar.appendChild(submitBtn);
|
|
2159
2259
|
promptShell.appendChild(toolbar);
|
|
2160
|
-
|
|
2260
|
+
composerForm.appendChild(promptShell);
|
|
2261
|
+
composer.appendChild(composerForm);
|
|
2161
2262
|
|
|
2162
2263
|
return composer;
|
|
2163
2264
|
}
|
|
@@ -2414,11 +2515,19 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2414
2515
|
this.agentStatusEl = agentStatus;
|
|
2415
2516
|
sidebar.appendChild(agentStatus);
|
|
2416
2517
|
|
|
2518
|
+
const agentPromptForm = this.buildFormShell();
|
|
2519
|
+
|
|
2417
2520
|
const promptShell = document.createElement("div");
|
|
2418
2521
|
promptShell.className = "cd-prompt-shell";
|
|
2419
2522
|
|
|
2420
2523
|
const textarea = document.createElement("textarea");
|
|
2421
2524
|
textarea.className = "cd-textarea";
|
|
2525
|
+
textarea.autocomplete = "off";
|
|
2526
|
+
textarea.setAttribute("autocomplete", "off");
|
|
2527
|
+
textarea.setAttribute("data-1p-ignore", "true");
|
|
2528
|
+
textarea.setAttribute("data-lpignore", "true");
|
|
2529
|
+
textarea.setAttribute("data-bwignore", "true");
|
|
2530
|
+
textarea.setAttribute("data-form-type", "other");
|
|
2422
2531
|
textarea.placeholder =
|
|
2423
2532
|
"Ask the local agent to inspect pinned DOM elements, read Rails views, or propose a fix...";
|
|
2424
2533
|
textarea.setAttribute("aria-label", "Agent prompt");
|
|
@@ -2451,7 +2560,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2451
2560
|
|
|
2452
2561
|
toolbar.appendChild(sendBtn);
|
|
2453
2562
|
promptShell.appendChild(toolbar);
|
|
2454
|
-
|
|
2563
|
+
agentPromptForm.appendChild(promptShell);
|
|
2564
|
+
sidebar.appendChild(agentPromptForm);
|
|
2455
2565
|
|
|
2456
2566
|
this.syncProviderControls();
|
|
2457
2567
|
return sidebar;
|
|
@@ -2468,6 +2578,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2468
2578
|
securityNote.innerHTML = `${ICON_SHIELD}<span>Keys stay encrypted on disk in <code>tmp/context_drop_byok.enc</code> (AES-256-GCM) or read from server ENV—never stored in browser storage.</span>`;
|
|
2469
2579
|
drawer.appendChild(securityNote);
|
|
2470
2580
|
|
|
2581
|
+
const byokForm = this.buildFormShell();
|
|
2582
|
+
|
|
2471
2583
|
const grid = document.createElement("div");
|
|
2472
2584
|
grid.className = "cd-form-grid";
|
|
2473
2585
|
|
|
@@ -2480,6 +2592,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2480
2592
|
const provSelect = document.createElement("select");
|
|
2481
2593
|
provSelect.className = "cd-select";
|
|
2482
2594
|
provSelect.setAttribute("aria-label", "LLM Provider");
|
|
2595
|
+
this.applyByokAutofillIgnore(provSelect);
|
|
2483
2596
|
provSelect.addEventListener("change", () => {
|
|
2484
2597
|
this.selectedVaultProviderId = provSelect.value;
|
|
2485
2598
|
this.syncByokDrawerFields();
|
|
@@ -2498,6 +2611,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2498
2611
|
const presetSelect = document.createElement("select");
|
|
2499
2612
|
presetSelect.className = "cd-select";
|
|
2500
2613
|
presetSelect.setAttribute("aria-label", "Model preset");
|
|
2614
|
+
this.applyByokAutofillIgnore(presetSelect);
|
|
2501
2615
|
presetSelect.addEventListener("change", () => {
|
|
2502
2616
|
if (this.byokModelInput && presetSelect.value) {
|
|
2503
2617
|
this.byokModelInput.value = presetSelect.value;
|
|
@@ -2516,8 +2630,10 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2516
2630
|
modelLabel.textContent = "Model ID";
|
|
2517
2631
|
const modelInput = document.createElement("input");
|
|
2518
2632
|
modelInput.type = "text";
|
|
2633
|
+
modelInput.setAttribute("type", "text");
|
|
2519
2634
|
modelInput.className = "cd-input is-mono";
|
|
2520
2635
|
modelInput.setAttribute("aria-label", "Model identifier");
|
|
2636
|
+
this.applyByokAutofillIgnore(modelInput);
|
|
2521
2637
|
this.byokModelInput = modelInput;
|
|
2522
2638
|
modelField.appendChild(modelLabel);
|
|
2523
2639
|
modelField.appendChild(modelInput);
|
|
@@ -2532,16 +2648,19 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2532
2648
|
baseUrlLabel.textContent = "OpenAI-Compatible Base URL";
|
|
2533
2649
|
const baseUrlInput = document.createElement("input");
|
|
2534
2650
|
baseUrlInput.type = "url";
|
|
2651
|
+
baseUrlInput.setAttribute("type", "url");
|
|
2535
2652
|
baseUrlInput.className = "cd-input is-mono";
|
|
2536
2653
|
baseUrlInput.placeholder = "https://openrouter.ai/api/v1 or http://localhost:11434/v1";
|
|
2537
2654
|
baseUrlInput.setAttribute("aria-label", "Custom OpenAI-compatible Base URL");
|
|
2655
|
+
this.applyByokAutofillIgnore(baseUrlInput);
|
|
2538
2656
|
this.byokBaseUrlInput = baseUrlInput;
|
|
2539
2657
|
baseUrlField.appendChild(baseUrlLabel);
|
|
2540
2658
|
baseUrlField.appendChild(baseUrlInput);
|
|
2541
2659
|
this.byokBaseUrlField = baseUrlField;
|
|
2542
2660
|
grid.appendChild(baseUrlField);
|
|
2543
2661
|
|
|
2544
|
-
// API Key field
|
|
2662
|
+
// API Key field — uses CSS-masked type="text" rather than type="password" so Chromium/browser
|
|
2663
|
+
// password managers never classify preceding or host-page inputs as login username fields.
|
|
2545
2664
|
const keyField = document.createElement("div");
|
|
2546
2665
|
keyField.className = "cd-field is-full";
|
|
2547
2666
|
const keyLabel = document.createElement("label");
|
|
@@ -2556,17 +2675,20 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
2556
2675
|
keyLabel.appendChild(keyBadge);
|
|
2557
2676
|
|
|
2558
2677
|
const keyInput = document.createElement("input");
|
|
2559
|
-
keyInput.type = "
|
|
2560
|
-
keyInput.
|
|
2561
|
-
keyInput.className = "cd-input is-mono";
|
|
2678
|
+
keyInput.type = "text";
|
|
2679
|
+
keyInput.setAttribute("type", "text");
|
|
2680
|
+
keyInput.className = "cd-input is-mono is-masked-secret";
|
|
2562
2681
|
keyInput.placeholder = "Paste API key (leave blank to keep existing key)";
|
|
2563
2682
|
keyInput.setAttribute("aria-label", "Provider API Key");
|
|
2683
|
+
keyInput.disabled = !this.isByokDrawerOpen;
|
|
2684
|
+
this.applyByokAutofillIgnore(keyInput);
|
|
2564
2685
|
this.byokKeyInput = keyInput;
|
|
2565
2686
|
keyField.appendChild(keyLabel);
|
|
2566
2687
|
keyField.appendChild(keyInput);
|
|
2567
2688
|
grid.appendChild(keyField);
|
|
2568
2689
|
|
|
2569
|
-
|
|
2690
|
+
byokForm.appendChild(grid);
|
|
2691
|
+
drawer.appendChild(byokForm);
|
|
2570
2692
|
|
|
2571
2693
|
const actions = document.createElement("div");
|
|
2572
2694
|
actions.className = "cd-drawer-actions";
|
|
@@ -3483,6 +3605,9 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3483
3605
|
if (this.byokDrawerEl) {
|
|
3484
3606
|
this.byokDrawerEl.hidden = !this.isByokDrawerOpen;
|
|
3485
3607
|
}
|
|
3608
|
+
if (this.byokKeyInput) {
|
|
3609
|
+
this.byokKeyInput.disabled = !this.isByokDrawerOpen;
|
|
3610
|
+
}
|
|
3486
3611
|
if (this.keysToggleBtn) {
|
|
3487
3612
|
this.keysToggleBtn.classList.toggle("is-active", this.isByokDrawerOpen);
|
|
3488
3613
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
class EventOccurrence < ApplicationRecord
|
|
5
|
+
self.table_name = "context_drop_event_occurrences"
|
|
6
|
+
|
|
7
|
+
EVENT_NAMES = %w[
|
|
8
|
+
feedback.created
|
|
9
|
+
feedback.updated
|
|
10
|
+
feedback.status_changed
|
|
11
|
+
feedback.deleted
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
14
|
+
validates :event_id, :name, :occurred_at, presence: true
|
|
15
|
+
validates :name, inclusion: { in: EVENT_NAMES }
|
|
16
|
+
|
|
17
|
+
scope :chronological, -> { order(occurred_at: :asc, id: :asc) }
|
|
18
|
+
scope :named, ->(event_name) { where(name: event_name) }
|
|
19
|
+
|
|
20
|
+
def cursor
|
|
21
|
+
id.to_s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def occurrence_payload
|
|
25
|
+
{
|
|
26
|
+
eventId: event_id,
|
|
27
|
+
name: name,
|
|
28
|
+
timestamp: occurred_at.iso8601(3),
|
|
29
|
+
cursor: cursor,
|
|
30
|
+
data: data.is_a?(Hash) ? data : {}
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
class McpEventSubscription < ApplicationRecord
|
|
5
|
+
self.table_name = "context_drop_mcp_event_subscriptions"
|
|
6
|
+
|
|
7
|
+
scope :active, -> { where("expires_at > ?", Time.current) }
|
|
8
|
+
|
|
9
|
+
validates :subscription_id, :event_name, :callback_url, :signing_secret, :expires_at, presence: true
|
|
10
|
+
|
|
11
|
+
def expired?
|
|
12
|
+
expires_at <= Time.current
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def matches_occurrence?(occurrence)
|
|
16
|
+
return false unless occurrence.name == event_name
|
|
17
|
+
|
|
18
|
+
arg_env = arguments.is_a?(Hash) ? arguments["environment"].to_s.strip : ""
|
|
19
|
+
return true if arg_env.empty?
|
|
20
|
+
|
|
21
|
+
data_env = occurrence.data.is_a?(Hash) ? occurrence.data["environment"].to_s.strip : ""
|
|
22
|
+
arg_env.casecmp?(data_env)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
class NotificationDestination < ApplicationRecord
|
|
5
|
+
self.table_name = "context_drop_notification_destinations"
|
|
6
|
+
|
|
7
|
+
DESTINATION_TYPES = %w[lark webhook].freeze
|
|
8
|
+
|
|
9
|
+
validates :name, :destination_type, presence: true
|
|
10
|
+
validates :destination_type, inclusion: { in: DESTINATION_TYPES }
|
|
11
|
+
validate :validate_event_types
|
|
12
|
+
validate :validate_settings_shape
|
|
13
|
+
validate :validate_destination_secrets
|
|
14
|
+
|
|
15
|
+
scope :enabled, -> { where(enabled: true) }
|
|
16
|
+
|
|
17
|
+
def secrets
|
|
18
|
+
@secrets ||= ContextDrop::NotificationSecrets.decrypt(secrets_ciphertext)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def secrets=(hash)
|
|
22
|
+
@secrets = (hash || {}).transform_keys(&:to_s).compact_blank
|
|
23
|
+
self.secrets_ciphertext = @secrets.empty? ? nil : ContextDrop::NotificationSecrets.encrypt(@secrets)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def merge_secrets!(updates)
|
|
27
|
+
current = secrets
|
|
28
|
+
updates.each do |key, val|
|
|
29
|
+
next if val.to_s.strip.empty?
|
|
30
|
+
|
|
31
|
+
current[key.to_s] = val.to_s.strip
|
|
32
|
+
end
|
|
33
|
+
self.secrets = current
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def subscribed_to?(event_name)
|
|
37
|
+
Array(event_types).map(&:to_s).include?(event_name.to_s)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def masked_secrets
|
|
41
|
+
secrets.transform_values { |v| ContextDrop::NotificationSecrets.mask_secret(v) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def record_delivery!(status:, error: nil)
|
|
45
|
+
update_columns(
|
|
46
|
+
last_delivery_status: status.to_s,
|
|
47
|
+
last_delivery_error: error&.to_s&.truncate(2000),
|
|
48
|
+
last_delivered_at: Time.current,
|
|
49
|
+
updated_at: Time.current
|
|
50
|
+
)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def validate_event_types
|
|
56
|
+
invalid = Array(event_types).map(&:to_s) - ContextDrop::EventOccurrence::EVENT_NAMES
|
|
57
|
+
errors.add(:event_types, "include unsupported events: #{invalid.join(', ')}") if invalid.any?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def validate_destination_secrets
|
|
61
|
+
return unless enabled
|
|
62
|
+
|
|
63
|
+
case destination_type
|
|
64
|
+
when "lark"
|
|
65
|
+
errors.add(:secrets, "require Lark app_id") if secrets["app_id"].to_s.strip.empty?
|
|
66
|
+
if secrets["app_secret"].to_s.strip.empty? && secrets_ciphertext.blank?
|
|
67
|
+
errors.add(:secrets, "require Lark app_secret")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def validate_settings_shape
|
|
73
|
+
return unless enabled
|
|
74
|
+
|
|
75
|
+
case destination_type
|
|
76
|
+
when "lark"
|
|
77
|
+
errors.add(:settings, "require receive_id for Lark") if settings.is_a?(Hash) && settings["receive_id"].to_s.strip.empty?
|
|
78
|
+
when "webhook"
|
|
79
|
+
url = settings.is_a?(Hash) ? settings["url"].to_s.strip : ""
|
|
80
|
+
errors.add(:settings, "require HTTPS url for webhook") if url.empty?
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -208,13 +208,11 @@
|
|
|
208
208
|
|
|
209
209
|
<% if att.respond_to?(:file) && att.file.attached? %>
|
|
210
210
|
<div style="margin: 0.5rem 0;">
|
|
211
|
-
|
|
212
|
-
<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
</a>
|
|
217
|
-
<% end %>
|
|
211
|
+
<a href="<%= cd_dashboard_attachment_path(att) %>" target="_blank" rel="noopener noreferrer">
|
|
212
|
+
<img src="<%= cd_dashboard_attachment_path(att) %>"
|
|
213
|
+
alt="Attachment #<%= att.id %>"
|
|
214
|
+
style="max-width: 100%; max-height: 280px; object-fit: contain; border-radius: 6px; border: 1px solid var(--cd-border-subtle); display: block;" />
|
|
215
|
+
</a>
|
|
218
216
|
</div>
|
|
219
217
|
<div style="font-size: 0.75rem; color: var(--cd-muted); font-family: var(--cd-font-mono);">
|
|
220
218
|
<%= att.file.filename %> (<%= att.file.content_type %>, <%= att.file.byte_size %> bytes)
|
|
@@ -261,9 +259,9 @@
|
|
|
261
259
|
<% if comment.attachments.any? %>
|
|
262
260
|
<div class="cd-comment-images">
|
|
263
261
|
<% comment.attachments.each do |att| %>
|
|
264
|
-
<% if att.respond_to?(:file) && att.file.attached?
|
|
265
|
-
<a href="<%=
|
|
266
|
-
<img src="<%=
|
|
262
|
+
<% if att.respond_to?(:file) && att.file.attached? %>
|
|
263
|
+
<a href="<%= cd_dashboard_attachment_path(att) %>" target="_blank" rel="noopener noreferrer" title="<%= att.file.filename %>">
|
|
264
|
+
<img src="<%= cd_dashboard_attachment_path(att) %>"
|
|
267
265
|
alt="Comment attachment #<%= att.id %>"
|
|
268
266
|
class="cd-comment-thumb" />
|
|
269
267
|
</a>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<%= form_with model: @destination, url: @destination.persisted? ? dashboard_integration_path(@destination) : dashboard_integrations_path, scope: :notification_destination, class: "cd-form-stack" do |f| %>
|
|
2
|
+
<% if @destination.errors.any? %>
|
|
3
|
+
<div class="cd-flash cd-flash-alert" role="alert">
|
|
4
|
+
<%= @destination.errors.full_messages.join(", ") %>
|
|
5
|
+
</div>
|
|
6
|
+
<% end %>
|
|
7
|
+
|
|
8
|
+
<div class="cd-form-grid">
|
|
9
|
+
<div class="cd-field">
|
|
10
|
+
<%= f.label :name, "Display name" %>
|
|
11
|
+
<%= f.text_field :name, class: "cd-input", required: true, placeholder: "Triage · Lark" %>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<div class="cd-field">
|
|
15
|
+
<%= f.label :destination_type, "Destination type" %>
|
|
16
|
+
<%= f.select :destination_type, ContextDrop::NotificationDestination::DESTINATION_TYPES, {}, class: "cd-input" %>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div class="cd-field cd-field-span">
|
|
20
|
+
<span class="cd-label">Lifecycle events</span>
|
|
21
|
+
<div class="cd-check-grid">
|
|
22
|
+
<% ContextDrop::EventOccurrence::EVENT_NAMES.each do |ev| %>
|
|
23
|
+
<label class="cd-check-row">
|
|
24
|
+
<%= check_box_tag "notification_destination[event_types][]", ev, @destination.subscribed_to?(ev) %>
|
|
25
|
+
<span class="cd-chip cd-chip-mono cd-chip-compact"><%= ev %></span>
|
|
26
|
+
</label>
|
|
27
|
+
<% end %>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<div class="cd-field">
|
|
32
|
+
<label class="cd-check-row">
|
|
33
|
+
<%= f.check_box :enabled %>
|
|
34
|
+
<span>Enabled</span>
|
|
35
|
+
</label>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<% if @destination.destination_type == "lark" %>
|
|
40
|
+
<div class="cd-card cd-card-inset" style="margin-top: 1rem;">
|
|
41
|
+
<h3 class="cd-section-title">Lark app bot</h3>
|
|
42
|
+
<p class="cd-section-hint">Credentials are encrypted at rest. Use a custom app with Bot capability and <code class="cd-inline-code">im:message</code> scope in your Lark developer console.</p>
|
|
43
|
+
<div class="cd-form-grid">
|
|
44
|
+
<div class="cd-field">
|
|
45
|
+
<label for="notification_destination_app_id">App ID</label>
|
|
46
|
+
<input type="text" name="notification_destination[app_id]" id="notification_destination_app_id" class="cd-input" autocomplete="off"
|
|
47
|
+
placeholder="<%= @destination.masked_secrets['app_id'] || 'cli_xxxxxxxx' %>" />
|
|
48
|
+
</div>
|
|
49
|
+
<div class="cd-field">
|
|
50
|
+
<label for="notification_destination_app_secret">App Secret</label>
|
|
51
|
+
<input type="password" name="notification_destination[app_secret]" id="notification_destination_app_secret" class="cd-input" autocomplete="new-password"
|
|
52
|
+
placeholder="<%= @destination.persisted? ? 'Leave blank to keep current secret' : 'Required' %>" />
|
|
53
|
+
</div>
|
|
54
|
+
<div class="cd-field">
|
|
55
|
+
<%= f.label :receive_id, "Receive ID (chat_id)", value: nil %>
|
|
56
|
+
<%= f.text_field :receive_id, name: "notification_destination[settings][receive_id]", value: @destination.settings["receive_id"], class: "cd-input", placeholder: "oc_xxxxxxxx" %>
|
|
57
|
+
</div>
|
|
58
|
+
<div class="cd-field">
|
|
59
|
+
<%= f.label :receive_id_type, "Receive ID type" %>
|
|
60
|
+
<%= select_tag "notification_destination[settings][receive_id_type]",
|
|
61
|
+
options_for_select([%w[chat_id chat_id], %w[open_id open_id], %w[user_id user_id]], @destination.settings["receive_id_type"].presence || "chat_id"),
|
|
62
|
+
class: "cd-input" %>
|
|
63
|
+
</div>
|
|
64
|
+
<div class="cd-field cd-field-span">
|
|
65
|
+
<%= f.label :api_host, "API host (optional)" %>
|
|
66
|
+
<%= f.text_field :api_host, name: "notification_destination[settings][api_host]", value: @destination.settings["api_host"], class: "cd-input", placeholder: "https://open.larksuite.com" %>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
<% else %>
|
|
71
|
+
<div class="cd-card cd-card-inset" style="margin-top: 1rem;">
|
|
72
|
+
<h3 class="cd-section-title">HTTPS webhook</h3>
|
|
73
|
+
<p class="cd-section-hint">Deliveries use Standard Webhooks signatures (<code class="cd-inline-code">webhook-signature</code> header).</p>
|
|
74
|
+
<div class="cd-form-grid">
|
|
75
|
+
<div class="cd-field cd-field-span">
|
|
76
|
+
<%= f.label :url, "Callback URL" %>
|
|
77
|
+
<%= f.text_field :url, name: "notification_destination[settings][url]", value: @destination.settings["url"], class: "cd-input", placeholder: "https://example.com/hooks/contextdrop" %>
|
|
78
|
+
</div>
|
|
79
|
+
<div class="cd-field cd-field-span">
|
|
80
|
+
<label for="notification_destination_signing_secret">Signing secret</label>
|
|
81
|
+
<input type="password" name="notification_destination[signing_secret]" id="notification_destination_signing_secret" class="cd-input" autocomplete="new-password"
|
|
82
|
+
placeholder="<%= @destination.persisted? ? 'Leave blank to keep current secret' : 'Optional HMAC secret' %>" />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
<% end %>
|
|
87
|
+
|
|
88
|
+
<div class="cd-form-actions">
|
|
89
|
+
<%= f.submit @destination.persisted? ? "Save destination" : "Create destination", class: "cd-btn cd-btn-primary" %>
|
|
90
|
+
<%= link_to "Cancel", dashboard_integrations_path, class: "cd-btn" %>
|
|
91
|
+
</div>
|
|
92
|
+
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<% content_for :cd_breadcrumbs do %>
|
|
2
|
+
<%= link_to "Integrations", dashboard_integrations_path, class: "cd-crumb-link" %>
|
|
3
|
+
<span class="cd-crumb-sep">/</span>
|
|
4
|
+
<span class="cd-crumb-current"><%= @destination.name %></span>
|
|
5
|
+
<% end %>
|
|
6
|
+
|
|
7
|
+
<div class="cd-page-head">
|
|
8
|
+
<h1 class="cd-page-title">Edit destination</h1>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
<div class="cd-card" style="padding: 1.25rem 1.5rem 1.5rem;">
|
|
12
|
+
<%= render "form" %>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<% content_for :cd_breadcrumbs do %>
|
|
2
|
+
<span class="cd-crumb-current">Integrations</span>
|
|
3
|
+
<% end %>
|
|
4
|
+
|
|
5
|
+
<div class="cd-page-head">
|
|
6
|
+
<div>
|
|
7
|
+
<h1 class="cd-page-title">Notifications & webhooks</h1>
|
|
8
|
+
<p class="cd-page-lede">Route ContextDrop lifecycle events to Lark message cards or signed HTTPS webhooks. MCP clients can also subscribe via <code class="cd-inline-code">events/poll</code>, <code class="cd-inline-code">events/stream</code>, and <code class="cd-inline-code">events/subscribe</code>.</p>
|
|
9
|
+
</div>
|
|
10
|
+
<div class="cd-page-actions">
|
|
11
|
+
<%= link_to "Add Lark bot", new_dashboard_integration_path(destination_type: "lark"), class: "cd-btn cd-btn-primary" %>
|
|
12
|
+
<%= link_to "Add webhook", new_dashboard_integration_path(destination_type: "webhook"), class: "cd-btn" %>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<div class="cd-card cd-card-tight" style="margin-bottom: 1rem;">
|
|
17
|
+
<h2 class="cd-section-title">MCP event types</h2>
|
|
18
|
+
<ul class="cd-chip-list" aria-label="Supported MCP events">
|
|
19
|
+
<% ContextDrop::EventOccurrence::EVENT_NAMES.each do |ev| %>
|
|
20
|
+
<li><span class="cd-chip cd-chip-mono"><%= ev %></span></li>
|
|
21
|
+
<% end %>
|
|
22
|
+
</ul>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<% if @destinations.empty? %>
|
|
26
|
+
<div class="cd-card" style="padding: 2.5rem 1.5rem; text-align: center;">
|
|
27
|
+
<p style="margin: 0 0 0.35rem; font-weight: 600;">No destinations configured</p>
|
|
28
|
+
<p style="margin: 0 0 1rem; color: var(--cd-muted); font-size: 0.875rem;">Add a Lark bot to notify your triage channel when new feedback arrives.</p>
|
|
29
|
+
<%= link_to "Configure Lark", new_dashboard_integration_path(destination_type: "lark"), class: "cd-btn cd-btn-primary" %>
|
|
30
|
+
</div>
|
|
31
|
+
<% else %>
|
|
32
|
+
<div class="cd-table-wrap cd-card cd-card-tight">
|
|
33
|
+
<table class="cd-table">
|
|
34
|
+
<thead>
|
|
35
|
+
<tr>
|
|
36
|
+
<th>Name</th>
|
|
37
|
+
<th>Type</th>
|
|
38
|
+
<th>Events</th>
|
|
39
|
+
<th>Status</th>
|
|
40
|
+
<th>Last delivery</th>
|
|
41
|
+
<th class="cd-cell-actions">Actions</th>
|
|
42
|
+
</tr>
|
|
43
|
+
</thead>
|
|
44
|
+
<tbody>
|
|
45
|
+
<% @destinations.each do |dest| %>
|
|
46
|
+
<tr>
|
|
47
|
+
<td style="font-weight: 600;"><%= dest.name %></td>
|
|
48
|
+
<td><span class="cd-chip"><%= dest.destination_type %></span></td>
|
|
49
|
+
<td>
|
|
50
|
+
<div class="cd-chip-row">
|
|
51
|
+
<% dest.event_types.each do |ev| %>
|
|
52
|
+
<span class="cd-chip cd-chip-mono cd-chip-compact"><%= ev %></span>
|
|
53
|
+
<% end %>
|
|
54
|
+
</div>
|
|
55
|
+
</td>
|
|
56
|
+
<td>
|
|
57
|
+
<% if dest.enabled? %>
|
|
58
|
+
<span class="cd-status-badge cd-status-reviewed">Enabled</span>
|
|
59
|
+
<% else %>
|
|
60
|
+
<span class="cd-status-badge cd-status-dismissed">Paused</span>
|
|
61
|
+
<% end %>
|
|
62
|
+
</td>
|
|
63
|
+
<td style="font-size: 0.8125rem; color: var(--cd-muted); max-width: 220px;">
|
|
64
|
+
<% if dest.last_delivered_at %>
|
|
65
|
+
<div><%= dest.last_delivery_status %> · <%= time_ago_in_words(dest.last_delivered_at) %> ago</div>
|
|
66
|
+
<% if dest.last_delivery_error.present? %>
|
|
67
|
+
<div style="color: var(--cd-deleted-text); margin-top: 0.25rem;"><%= dest.last_delivery_error.truncate(120) %></div>
|
|
68
|
+
<% end %>
|
|
69
|
+
<% else %>
|
|
70
|
+
<span>Not yet delivered</span>
|
|
71
|
+
<% end %>
|
|
72
|
+
</td>
|
|
73
|
+
<td class="cd-cell-actions">
|
|
74
|
+
<div class="cd-btn-row">
|
|
75
|
+
<%= button_to "Test", test_delivery_dashboard_integration_path(dest), method: :post, class: "cd-btn cd-btn-compact", form: { data: { turbo: false } } %>
|
|
76
|
+
<%= link_to "Edit", edit_dashboard_integration_path(dest), class: "cd-btn cd-btn-compact" %>
|
|
77
|
+
<%= button_to "Remove", dashboard_integration_path(dest), method: :delete, class: "cd-btn cd-btn-danger cd-btn-compact", form: { data: { turbo_confirm: "Remove this destination?" } } %>
|
|
78
|
+
</div>
|
|
79
|
+
</td>
|
|
80
|
+
</tr>
|
|
81
|
+
<% end %>
|
|
82
|
+
</tbody>
|
|
83
|
+
</table>
|
|
84
|
+
</div>
|
|
85
|
+
<% end %>
|
|
86
|
+
|
|
87
|
+
<% if @mcp_subscriptions.present? %>
|
|
88
|
+
<div class="cd-card cd-card-tight" style="margin-top: 1.25rem;">
|
|
89
|
+
<h2 class="cd-section-title">Active MCP webhook subscriptions</h2>
|
|
90
|
+
<p class="cd-section-hint">Registered by MCP clients via <code class="cd-inline-code">events/subscribe</code> (expires automatically).</p>
|
|
91
|
+
<ul class="cd-meta-list" style="margin-top: 0.75rem;">
|
|
92
|
+
<% @mcp_subscriptions.each do |sub| %>
|
|
93
|
+
<dt><span class="cd-chip cd-chip-mono"><%= sub.event_name %></span></dt>
|
|
94
|
+
<dd>
|
|
95
|
+
<span class="cd-break-all"><%= sub.callback_url %></span>
|
|
96
|
+
<span style="color: var(--cd-muted);"> · expires <%= sub.expires_at.iso8601 %></span>
|
|
97
|
+
</dd>
|
|
98
|
+
<% end %>
|
|
99
|
+
</ul>
|
|
100
|
+
</div>
|
|
101
|
+
<% end %>
|