completion-kit 0.26.1 → 0.26.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e0435edbf9ccffb90715ab2d16fca2d158ad8e81767d550c3290c61a18de5ef
4
- data.tar.gz: 365c545d14c7e9795f822cbda48d88327d70ea2b825276a4cb3b5e57b3ca2f6d
3
+ metadata.gz: 1fd4ab63494debc29d699a8cc14a9f5fc2a30c52f3d85e7c1afeedb8566eb55b
4
+ data.tar.gz: 46ad64c09d27c95c98f284efb3ab8fc1b9790c8c84d85a38461ed5fb67cc42fe
5
5
  SHA512:
6
- metadata.gz: 046de8a9141dcd65497cde60b4fe5fae8cae31c7813f1c973469e4294a531292414d035979e1594e56829a0c3e81fd13eacd6d59221da9b8009a0f29574f38ba
7
- data.tar.gz: 913f8ccbf9a907c958a29bd8e6af9c272d3fb55e4b1dd526c51dc4fc310fa20a06901818665adc09fa2ce440f141feb0d751f84b3a2bcaf2938c6183ff78cd9c
6
+ metadata.gz: 56277125c6b63a340796b7b409ca7f6307d2e8ad35ff751ef9e1f01a2a61706b72e8e43960dc43b2d167f370a3cbb95b140ca6f7cc3607e2c74cb499f6e940bf
7
+ data.tar.gz: b57d0ba59815c246c48f704cc75d5a6e91b301c7783b518e3a98f0acd6b413b1026318f762a1e6595c3726f803007b55c5e920699382c461ffa8176b85a7bec5
@@ -290,6 +290,30 @@ document.addEventListener("change", function(e) {
290
290
  }
291
291
  });
292
292
 
293
+ function ckApplyProviderFields(scope) {
294
+ if (!scope) return;
295
+ var select = scope.querySelector("[data-ck-provider-select]");
296
+ if (!select) return;
297
+ var provider = select.value;
298
+ scope.querySelectorAll("[data-ck-provider-field]").forEach(function(field) {
299
+ var wanted = (field.getAttribute("data-ck-provider-field") || "").split(",");
300
+ field.hidden = wanted.indexOf(provider) === -1;
301
+ });
302
+ }
303
+
304
+ document.addEventListener("turbo:load", function() {
305
+ document.querySelectorAll("[data-ck-provider-select]").forEach(function(select) {
306
+ ckApplyProviderFields(select.closest("form") || document);
307
+ });
308
+ });
309
+
310
+ document.addEventListener("change", function(e) {
311
+ var target = e.target;
312
+ if (target && target.matches && target.matches("[data-ck-provider-select]")) {
313
+ ckApplyProviderFields(target.closest("form") || document);
314
+ }
315
+ });
316
+
293
317
  document.addEventListener("click", function(e) {
294
318
  var btn = e.target.closest("[data-ck-apply]");
295
319
  if (!btn) return;
@@ -378,3 +402,51 @@ document.addEventListener("keydown", function(e) {
378
402
  else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (options[idx]) ckSelectChoose(sel, options[idx]); }
379
403
  else if (e.key === "Escape") { e.preventDefault(); ckSelectClose(sel); trigger.focus(); }
380
404
  });
405
+
406
+ function ckConfirmModal(message, formEl, submitter) {
407
+ var dialog = document.getElementById("ck-confirm-modal");
408
+ if (!dialog || typeof dialog.showModal !== "function") {
409
+ return Promise.resolve(window.confirm(message));
410
+ }
411
+ var messageEl = dialog.querySelector("#ck-confirm-message");
412
+ var acceptBtn = dialog.querySelector("[data-ck-confirm-accept]");
413
+ var cancelBtn = dialog.querySelector("[data-ck-confirm-cancel]");
414
+ if (messageEl) messageEl.textContent = message || "Are you sure?";
415
+ var label = (submitter && submitter.getAttribute("data-ck-confirm-label")) || "Confirm";
416
+ var tone = (submitter && submitter.getAttribute("data-ck-confirm-tone")) || "";
417
+ if (acceptBtn) {
418
+ acceptBtn.textContent = label;
419
+ acceptBtn.className = "ck-button " + (tone === "danger" ? "ck-button--danger" : "ck-button--primary");
420
+ }
421
+ return new Promise(function(resolve) {
422
+ function onClose() {
423
+ dialog.removeEventListener("close", onClose);
424
+ acceptBtn.removeEventListener("click", onAccept);
425
+ cancelBtn.removeEventListener("click", onCancel);
426
+ dialog.removeEventListener("click", onBackdrop);
427
+ resolve(dialog.returnValue === "accept");
428
+ }
429
+ function onAccept() { dialog.close("accept"); }
430
+ function onCancel() { dialog.close("cancel"); }
431
+ function onBackdrop(e) { if (e.target === dialog) dialog.close("cancel"); }
432
+ dialog.addEventListener("close", onClose);
433
+ acceptBtn.addEventListener("click", onAccept);
434
+ cancelBtn.addEventListener("click", onCancel);
435
+ dialog.addEventListener("click", onBackdrop);
436
+ dialog.returnValue = "";
437
+ dialog.showModal();
438
+ var focusTarget = (tone === "danger" ? cancelBtn : acceptBtn);
439
+ if (focusTarget) focusTarget.focus();
440
+ });
441
+ }
442
+
443
+ function ckInstallConfirm() {
444
+ if (!window.Turbo) return;
445
+ if (Turbo.config && Turbo.config.forms) {
446
+ Turbo.config.forms.confirm = ckConfirmModal;
447
+ } else if (typeof Turbo.setConfirmMethod === "function") {
448
+ Turbo.setConfirmMethod(ckConfirmModal);
449
+ }
450
+ }
451
+ document.addEventListener("turbo:load", ckInstallConfirm);
452
+ ckInstallConfirm();
@@ -2259,6 +2259,21 @@ label.ck-checkbox[hidden] {
2259
2259
  outline-offset: 2px;
2260
2260
  }
2261
2261
 
2262
+ .ck-icon-btn:disabled {
2263
+ opacity: 0.4;
2264
+ cursor: not-allowed;
2265
+ }
2266
+
2267
+ .ck-icon-btn:disabled:hover {
2268
+ background: none;
2269
+ border-color: transparent;
2270
+ color: var(--ck-dim);
2271
+ }
2272
+
2273
+ .ck-delete-form {
2274
+ display: contents;
2275
+ }
2276
+
2262
2277
  .ck-icon-btn--spinning svg {
2263
2278
  animation: ck-spin 0.8s linear infinite;
2264
2279
  }
@@ -2711,6 +2726,17 @@ select.ck-input {
2711
2726
  backdrop-filter: blur(4px);
2712
2727
  }
2713
2728
 
2729
+ .ck-modal--sm {
2730
+ max-width: min(92vw, 440px);
2731
+ }
2732
+
2733
+ .ck-confirm__message {
2734
+ margin: 0;
2735
+ color: var(--ck-muted);
2736
+ font-size: 0.95rem;
2737
+ line-height: 1.55;
2738
+ }
2739
+
2714
2740
  .ck-modal[open] {
2715
2741
  animation: ck-modal-in 0.18s ease-out;
2716
2742
  }
@@ -29,6 +29,21 @@ module CompletionKit
29
29
  "#{base} #{styles}"
30
30
  end
31
31
 
32
+ def ck_delete_trigger(form_id:, label:, confirm: nil, disabled: false, title: nil)
33
+ content_tag(
34
+ :button,
35
+ type: "submit",
36
+ form: (disabled ? nil : form_id),
37
+ class: "ck-icon-btn",
38
+ title: title || label,
39
+ "aria-label": label,
40
+ disabled: disabled,
41
+ data: (disabled ? {} : {turbo_confirm: confirm, ck_confirm_label: "Delete", ck_confirm_tone: "danger"})
42
+ ) do
43
+ heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true"
44
+ end
45
+ end
46
+
32
47
  def ck_badge_classes(kind)
33
48
  case kind.to_s
34
49
  when "high"
@@ -1,3 +1,11 @@
1
+ <% if dataset.persisted? %>
2
+ <% dataset_delete_id = "ck_delete_dataset_#{dataset.id}" %>
3
+ <% runs_n = dataset.runs.count %>
4
+ <% responses_n = CompletionKit::Response.where(run_id: dataset.runs.select(:id)).count %>
5
+ <% dataset_delete_confirm = runs_n.zero? ?
6
+ "Delete \"#{dataset.name}\"? It has no runs." :
7
+ "Delete \"#{dataset.name}\"? Cascades through #{pluralize(runs_n, 'run')} and #{pluralize(responses_n, 'response')} (and their reviews) that used this dataset." %>
8
+ <% end %>
1
9
  <%= form_with(model: dataset, local: true) do |form| %>
2
10
  <% if dataset.errors.any? %>
3
11
  <div class="ck-flash ck-flash--alert" role="alert">
@@ -32,21 +40,7 @@
32
40
 
33
41
  <div class="ck-actions">
34
42
  <% if dataset.persisted? %>
35
- <% runs_n = dataset.runs.count %>
36
- <% responses_n = CompletionKit::Response.where(run_id: dataset.runs.select(:id)).count %>
37
- <% confirm = if runs_n.zero?
38
- "Delete \"#{dataset.name}\"? It has no runs."
39
- else
40
- "Delete \"#{dataset.name}\"? Cascades through #{pluralize(runs_n, 'run')} and #{pluralize(responses_n, 'response')} (and their reviews) that used this dataset."
41
- end %>
42
- <%= button_to dataset_path(dataset), method: :delete,
43
- form_class: "inline-block",
44
- class: "ck-icon-btn",
45
- title: "Delete dataset",
46
- "aria-label": "Delete dataset",
47
- data: { turbo_confirm: confirm } do %>
48
- <%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %>
49
- <% end %>
43
+ <%= ck_delete_trigger(form_id: dataset_delete_id, label: "Delete dataset", confirm: dataset_delete_confirm) %>
50
44
  <% end %>
51
45
  <%= link_to "Cancel", datasets_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
52
46
  <%= form.submit(dataset.persisted? ? "Save dataset" : "Create dataset", class: ck_button_classes(:dark)) %>
@@ -81,3 +75,7 @@ document.addEventListener('turbo:load', ckDatasetHeaderPreview);
81
75
  ckDatasetHeaderPreview();
82
76
  </script>
83
77
  <% end %>
78
+
79
+ <% if dataset.persisted? %>
80
+ <%= render "completion_kit/shared/delete_form", form_id: dataset_delete_id, path: dataset_path(dataset) %>
81
+ <% end %>
@@ -1,3 +1,10 @@
1
+ <% if metric_group.persisted? %>
2
+ <% metric_group_delete_id = "ck_delete_metric_group_#{metric_group.id}" %>
3
+ <% members_n = metric_group.metrics.count %>
4
+ <% metric_group_delete_confirm = members_n.zero? ?
5
+ "Delete \"#{metric_group.name}\"? It has no members." :
6
+ "Delete \"#{metric_group.name}\"? Removes this grouping. #{pluralize(members_n, 'member metric')} #{members_n == 1 ? 'is' : 'are'} kept." %>
7
+ <% end %>
1
8
  <%= form_with(model: metric_group, url: metric_group.persisted? ? metric_group_path(metric_group) : metric_groups_path, local: true) do |form| %>
2
9
  <% name_error = metric_group.errors[:name].first %>
3
10
 
@@ -81,21 +88,14 @@
81
88
 
82
89
  <div class="ck-actions">
83
90
  <% if metric_group.persisted? %>
84
- <% members_n = metric_group.metrics.count %>
85
- <% confirm = members_n.zero? ?
86
- "Delete \"#{metric_group.name}\"? It has no members." :
87
- "Delete \"#{metric_group.name}\"? Removes this grouping. #{pluralize(members_n, 'member metric')} #{members_n == 1 ? 'is' : 'are'} kept." %>
88
- <%= button_to metric_group_path(metric_group), method: :delete,
89
- form_class: "inline-block",
90
- class: "ck-icon-btn",
91
- title: "Delete metric group",
92
- "aria-label": "Delete metric group",
93
- data: { turbo_confirm: confirm } do %>
94
- <%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %>
95
- <% end %>
91
+ <%= ck_delete_trigger(form_id: metric_group_delete_id, label: "Delete metric group", confirm: metric_group_delete_confirm) %>
96
92
  <% end %>
97
93
  <%= link_to "Cancel", metrics_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
98
94
  <%= form.submit(metric_group.persisted? ? "Save metric group" : "Create metric group", class: ck_button_classes(:dark)) %>
99
95
  </div>
100
96
  </div>
101
97
  <% end %>
98
+
99
+ <% if metric_group.persisted? %>
100
+ <%= render "completion_kit/shared/delete_form", form_id: metric_group_delete_id, path: metric_group_path(metric_group) %>
101
+ <% end %>
@@ -3,6 +3,58 @@
3
3
  <% suggestion_bands = suggestion ? Array(suggestion.rubric_bands).each_with_object({}) { |b, h| h[b["stars"].to_i] = b["description"].to_s } : {} %>
4
4
  <% suggested_instruction = suggestion&.instruction.to_s %>
5
5
  <% instruction_changed = suggestion && suggested_instruction.present? && suggested_instruction != metric.instruction.to_s %>
6
+ <% if metric.persisted? %>
7
+ <% metric_delete_id = "ck_delete_metric_#{metric.id}" %>
8
+ <% groups_n = metric.metric_groups.count %>
9
+ <% reviews_n = metric.reviews.count %>
10
+ <% parts = [] %>
11
+ <% parts << "in #{pluralize(groups_n, 'metric group')} (removed from each)" if groups_n > 0 %>
12
+ <% parts << "scored in #{pluralize(reviews_n, 'review')} (scores kept, link cleared)" if reviews_n > 0 %>
13
+ <% metric_delete_confirm = parts.empty? ? "Delete \"#{metric.name}\"? It's not in use." : "Delete \"#{metric.name}\"? It's #{parts.to_sentence}." %>
14
+ <% end %>
15
+
16
+ <% if edit_draft %>
17
+ <% pub = local_assigns[:published_metric_version] %>
18
+ <% draft_instr_changed = pub && pub.instruction.to_s != edit_draft.instruction.to_s %>
19
+ <% draft_rubric_changed = pub && pub.rubric_bands != edit_draft.rubric_bands %>
20
+ <div class="ck-suggestion-banner" role="status">
21
+ <div class="ck-suggestion-banner__body">
22
+ <p class="ck-kicker">Draft pending</p>
23
+ <p class="ck-meta-copy">The form below shows your unpublished draft. Publish to replace the live<%= " instruction" if draft_instr_changed %><%= " and" if draft_instr_changed && draft_rubric_changed %><%= " rubric" if draft_rubric_changed %> for future runs, or keep editing.</p>
24
+ </div>
25
+ <div class="ck-suggestion-banner__actions">
26
+ <%= button_to "Discard draft", dismiss_suggestion_metric_path(metric, draft_id: edit_draft.id, back_to: "edit"),
27
+ method: :delete, form_class: "inline-block",
28
+ class: ck_button_classes(:light, variant: :outline),
29
+ data: { turbo_confirm: "Drop this draft?", ck_confirm_label: "Discard", ck_confirm_tone: "danger" } %>
30
+ <%= button_to "Publish this version", publish_draft_metric_path(metric, draft_id: edit_draft.id),
31
+ method: :post, form_class: "inline-block",
32
+ class: ck_button_classes(:dark) %>
33
+ </div>
34
+ </div>
35
+ <% end %>
36
+
37
+ <% if suggestion %>
38
+ <div class="ck-suggestion-banner" role="status">
39
+ <div class="ck-suggestion-banner__body">
40
+ <p class="ck-kicker ck-kicker--icon"><%= heroicon_tag "sparkles", variant: :outline, class: "ck-magic-icon", "aria-hidden": "true" %>Proposed changes</p>
41
+ <p class="ck-meta-copy">Based on human reviews, here are some proposed changes to the metric.</p>
42
+ </div>
43
+ <div class="ck-suggestion-banner__actions">
44
+ <%= button_to suggest_variants_metric_path(metric, back_to: "edit"),
45
+ method: :post, form_class: "inline-block", class: "ck-icon-btn",
46
+ title: "Try again", "aria-label": "Try again",
47
+ data: { turbo_confirm: "Replace these changes with fresh ones from the model?" } do %><%= heroicon_tag "arrow-path", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
48
+ <%= button_to dismiss_suggestion_metric_path(metric, draft_id: suggestion.id, back_to: "edit"),
49
+ method: :delete, form_class: "inline-block", class: "ck-icon-btn",
50
+ title: "Discard these changes", "aria-label": "Discard",
51
+ data: { turbo_confirm: "Drop these changes?", ck_confirm_label: "Discard", ck_confirm_tone: "danger" } do %><%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
52
+ <%= button_to "Apply all", publish_draft_metric_path(metric, draft_id: suggestion.id),
53
+ method: :post, form_class: "inline-block",
54
+ class: ck_button_classes(:dark) %>
55
+ </div>
56
+ </div>
57
+ <% end %>
6
58
 
7
59
  <%= form_with(model: metric, local: true) do |form| %>
8
60
  <% if metric.errors.any? %>
@@ -16,49 +68,6 @@
16
68
  </div>
17
69
  <% end %>
18
70
 
19
- <% if edit_draft %>
20
- <% pub = local_assigns[:published_metric_version] %>
21
- <% draft_instr_changed = pub && pub.instruction.to_s != edit_draft.instruction.to_s %>
22
- <% draft_rubric_changed = pub && pub.rubric_bands != edit_draft.rubric_bands %>
23
- <div class="ck-suggestion-banner" role="status">
24
- <div class="ck-suggestion-banner__body">
25
- <p class="ck-kicker">Draft pending</p>
26
- <p class="ck-meta-copy">The form below shows your unpublished draft. Publish to replace the live<%= " instruction" if draft_instr_changed %><%= " and" if draft_instr_changed && draft_rubric_changed %><%= " rubric" if draft_rubric_changed %> for future runs, or keep editing.</p>
27
- </div>
28
- <div class="ck-suggestion-banner__actions">
29
- <%= button_to "Discard draft", dismiss_suggestion_metric_path(metric, draft_id: edit_draft.id, back_to: "edit"),
30
- method: :delete, form_class: "inline-block",
31
- class: ck_button_classes(:light, variant: :outline),
32
- data: { turbo_confirm: "Drop this draft?" } %>
33
- <%= button_to "Publish this version", publish_draft_metric_path(metric, draft_id: edit_draft.id),
34
- method: :post, form_class: "inline-block",
35
- class: ck_button_classes(:dark) %>
36
- </div>
37
- </div>
38
- <% end %>
39
-
40
- <% if suggestion %>
41
- <div class="ck-suggestion-banner" role="status">
42
- <div class="ck-suggestion-banner__body">
43
- <p class="ck-kicker ck-kicker--icon"><%= heroicon_tag "sparkles", variant: :outline, class: "ck-magic-icon", "aria-hidden": "true" %>Proposed changes</p>
44
- <p class="ck-meta-copy">Based on human reviews, here are some proposed changes to the metric.</p>
45
- </div>
46
- <div class="ck-suggestion-banner__actions">
47
- <%= button_to suggest_variants_metric_path(metric, back_to: "edit"),
48
- method: :post, form_class: "inline-block", class: "ck-icon-btn",
49
- title: "Try again", "aria-label": "Try again",
50
- data: { turbo_confirm: "Replace these changes with fresh ones from the model?" } do %><%= heroicon_tag "arrow-path", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
51
- <%= button_to dismiss_suggestion_metric_path(metric, draft_id: suggestion.id, back_to: "edit"),
52
- method: :delete, form_class: "inline-block", class: "ck-icon-btn",
53
- title: "Discard these changes", "aria-label": "Discard",
54
- data: { turbo_confirm: "Drop these changes?" } do %><%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
55
- <%= button_to "Apply all", publish_draft_metric_path(metric, draft_id: suggestion.id),
56
- method: :post, form_class: "inline-block",
57
- class: ck_button_classes(:dark) %>
58
- </div>
59
- </div>
60
- <% end %>
61
-
62
71
  <div class="ck-card ck-form-card">
63
72
  <div class="ck-field">
64
73
  <%= form.label :name, "Metric name", class: "ck-label" %>
@@ -255,23 +264,14 @@
255
264
 
256
265
  <div class="ck-actions">
257
266
  <% if metric.persisted? %>
258
- <% groups_n = metric.metric_groups.count %>
259
- <% reviews_n = metric.reviews.count %>
260
- <% parts = [] %>
261
- <% parts << "in #{pluralize(groups_n, 'metric group')} (removed from each)" if groups_n > 0 %>
262
- <% parts << "scored in #{pluralize(reviews_n, 'review')} (scores kept, link cleared)" if reviews_n > 0 %>
263
- <% confirm = parts.empty? ? "Delete \"#{metric.name}\"? It's not in use." : "Delete \"#{metric.name}\"? It's #{parts.to_sentence}." %>
264
- <%= button_to metric_path(metric), method: :delete,
265
- form_class: "inline-block",
266
- class: "ck-icon-btn ck-icon-btn--form",
267
- title: "Delete metric",
268
- "aria-label": "Delete metric",
269
- data: { turbo_confirm: confirm } do %>
270
- <%= heroicon_tag "trash", variant: :outline, size: 24, "aria-hidden": "true" %>
271
- <% end %>
267
+ <%= ck_delete_trigger(form_id: metric_delete_id, label: "Delete metric", confirm: metric_delete_confirm) %>
272
268
  <% end %>
273
269
  <%= link_to "Cancel", metrics_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
274
270
  <%= form.submit(metric.persisted? ? "Save metric" : "Create metric", class: ck_button_classes(:dark)) %>
275
271
  </div>
276
272
  </div>
277
273
  <% end %>
274
+
275
+ <% if metric.persisted? %>
276
+ <%= render "completion_kit/shared/delete_form", form_id: metric_delete_id, path: metric_path(metric) %>
277
+ <% end %>
@@ -1,3 +1,11 @@
1
+ <% if prompt.persisted? %>
2
+ <% prompt_delete_id = "ck_delete_prompt_#{prompt.id}" %>
3
+ <% runs_n = prompt.runs.count %>
4
+ <% responses_n = prompt.responses.count %>
5
+ <% prompt_delete_confirm = runs_n.zero? ?
6
+ "Delete \"#{prompt.display_name}\"? This version has no runs." :
7
+ "Delete \"#{prompt.display_name}\"? Cascades through #{pluralize(runs_n, 'run')} and #{pluralize(responses_n, 'response')} (and their reviews). Other versions of this prompt are untouched." %>
8
+ <% end %>
1
9
  <%= form_with(model: prompt, local: true) do |form| %>
2
10
  <% if prompt.errors.any? %>
3
11
  <div class="ck-flash ck-flash--alert" role="alert">
@@ -11,7 +19,7 @@
11
19
  <% end %>
12
20
 
13
21
  <% if prompt.persisted? && prompt.runs.exists? %>
14
- <p class="ck-version-note">Editing <%= prompt.version_label %> it has runs, so saving creates a new version of this prompt.</p>
22
+ <p class="ck-version-note">Editing <%= prompt.version_label %>. It has runs, so saving creates a new version of this prompt.</p>
15
23
  <% end %>
16
24
 
17
25
  <div class="ck-card ck-form-card">
@@ -39,7 +47,7 @@
39
47
  <% available = CompletionKit::ApiConfig.available_models(scope: :generation) %>
40
48
  <% if available.any? %>
41
49
  <div class="ck-select-with-action">
42
- <%= form.select :llm_model, ck_grouped_models(available, prompt.llm_model), { include_blank: "Select a model" }, { class: "ck-input", id: "prompt_llm_model" } %>
50
+ <%= form.select :llm_model, ck_grouped_models(available, prompt.llm_model), { include_blank: "Select a model" }, { class: "ck-input", id: "prompt_llm_model" } %>
43
51
  <% ck_refreshing = CompletionKit::ProviderCredential.discovery_in_progress? %>
44
52
  <button type="button" class="ck-icon-btn<%= ' ck-icon-btn--spinning' if ck_refreshing %>" title="Refresh models" <%= 'disabled' if ck_refreshing %> onclick="ckRefreshModels()"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="16" height="16"><path fill-rule="evenodd" d="M13.836 2.477a.75.75 0 0 1 .75.75v3.182a.75.75 0 0 1-.75.75h-3.182a.75.75 0 0 1 0-1.5h1.37l-.84-.841a4.5 4.5 0 0 0-7.08.681.75.75 0 0 1-1.264-.808 6 6 0 0 1 9.44-.908l.84.84V3.227a.75.75 0 0 1 .75-.75Zm-.911 7.5A.75.75 0 0 1 13.199 11a6 6 0 0 1-9.44.908l-.84-.84v1.68a.75.75 0 0 1-1.5 0V9.567a.75.75 0 0 1 .75-.75h3.182a.75.75 0 0 1 0 1.5h-1.37l.84.841a4.5 4.5 0 0 0 7.08-.681.75.75 0 0 1 1.024-.274Z" clip-rule="evenodd"/></svg></button>
45
53
  </div>
@@ -59,24 +67,14 @@
59
67
 
60
68
  <div class="ck-actions">
61
69
  <% if prompt.persisted? %>
62
- <% runs_n = prompt.runs.count %>
63
- <% responses_n = prompt.responses.count %>
64
- <% confirm = if runs_n.zero?
65
- "Delete \"#{prompt.display_name}\"? This version has no runs."
66
- else
67
- "Delete \"#{prompt.display_name}\"? Cascades through #{pluralize(runs_n, 'run')} and #{pluralize(responses_n, 'response')} (and their reviews). Other versions of this prompt are untouched."
68
- end %>
69
- <%= button_to prompt_path(prompt), method: :delete,
70
- form_class: "inline-block",
71
- class: "ck-icon-btn",
72
- title: "Delete prompt",
73
- "aria-label": "Delete prompt",
74
- data: { turbo_confirm: confirm } do %>
75
- <%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %>
76
- <% end %>
70
+ <%= ck_delete_trigger(form_id: prompt_delete_id, label: "Delete prompt", confirm: prompt_delete_confirm) %>
77
71
  <% end %>
78
72
  <%= link_to "Cancel", prompts_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
79
73
  <%= form.submit(prompt.persisted? ? "Save prompt" : "Create prompt", class: ck_button_classes(:dark), disabled: available.empty?) %>
80
74
  </div>
81
75
  </div>
82
76
  <% end %>
77
+
78
+ <% if prompt.persisted? %>
79
+ <%= render "completion_kit/shared/delete_form", form_id: prompt_delete_id, path: prompt_path(prompt) %>
80
+ <% end %>
@@ -1,3 +1,8 @@
1
+ <% if provider_credential.persisted? %>
2
+ <% pc_delete_id = "ck_delete_provider_#{provider_credential.id}" %>
3
+ <% pc_delete_blocked = provider_credential.in_use? %>
4
+ <% pc_delete_confirm = "Delete the #{provider_credential.display_provider} provider and its discovered models? This can't be undone." %>
5
+ <% end %>
1
6
  <%= form_with(model: provider_credential, local: true) do |form| %>
2
7
  <% if provider_credential.errors.any? %>
3
8
  <div class="ck-flash ck-flash--alert" role="alert">
@@ -13,7 +18,7 @@
13
18
  <div class="ck-card ck-form-card">
14
19
  <div class="ck-field">
15
20
  <%= form.label :provider, class: "ck-label" %>
16
- <%= form.select :provider, CompletionKit::ProviderCredential::PROVIDERS.map { |p| [CompletionKit::ProviderCredential::PROVIDER_LABELS[p] || p.titleize, p] }, {}, { class: "ck-input" } %>
21
+ <%= form.select :provider, CompletionKit::ProviderCredential::PROVIDERS.map { |p| [CompletionKit::ProviderCredential::PROVIDER_LABELS[p] || p.titleize, p] }, {}, { class: "ck-input", data: { ck_provider_select: true } } %>
17
22
  </div>
18
23
 
19
24
  <div class="ck-field">
@@ -28,35 +33,28 @@
28
33
  <%= ck_field_error(form, :api_endpoint) %>
29
34
  </div>
30
35
 
31
- <div class="ck-field">
36
+ <div class="ck-field" data-ck-provider-field="azure_foundry"<%= provider_credential.azure_foundry? ? "" : " hidden" %>>
32
37
  <%= form.label :api_version, "API version", class: "ck-label" %>
33
- <%= form.text_field :api_version, class: "ck-input", placeholder: "Only needed for Azure AI Foundry (e.g. 2024-10-21)", **ck_field_aria(form, :api_version) %>
38
+ <%= form.text_field :api_version, class: "ck-input", placeholder: "e.g. 2024-10-21", **ck_field_aria(form, :api_version) %>
34
39
  <%= ck_field_error(form, :api_version) %>
35
40
  </div>
36
41
 
37
42
  <div class="ck-actions">
43
+ <% if provider_credential.persisted? %>
44
+ <%= ck_delete_trigger(form_id: pc_delete_id, label: "Delete provider", confirm: pc_delete_confirm, disabled: pc_delete_blocked, title: (pc_delete_blocked ? provider_credential.in_use_message : "Delete provider")) %>
45
+ <% end %>
38
46
  <%= link_to "Cancel", provider_credentials_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
39
47
  <%= form.submit(provider_credential.persisted? ? "Save provider" : "Create provider", class: ck_button_classes(:dark)) %>
40
48
  </div>
49
+ <% if provider_credential.persisted? && pc_delete_blocked %>
50
+ <p class="ck-field-hint"><%= provider_credential.in_use_message %></p>
51
+ <% end %>
41
52
 
42
53
  </div>
43
54
  <% end %>
44
55
 
45
- <% if provider_credential.persisted? %>
46
- <% if provider_credential.in_use? %>
47
- <p class="ck-field-hint"><%= provider_credential.in_use_message %></p>
48
- <% else %>
49
- <div class="ck-actions">
50
- <%= button_to provider_credential_path(provider_credential), method: :delete,
51
- form_class: "inline-block",
52
- class: "ck-icon-btn",
53
- title: "Delete provider",
54
- "aria-label": "Delete provider",
55
- data: { turbo_confirm: "Delete the #{provider_credential.display_provider} provider and its discovered models? This can't be undone." } do %>
56
- <%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %>
57
- <% end %>
58
- </div>
59
- <% end %>
56
+ <% if provider_credential.persisted? && !pc_delete_blocked %>
57
+ <%= render "completion_kit/shared/delete_form", form_id: pc_delete_id, path: provider_credential_path(provider_credential) %>
60
58
  <% end %>
61
59
 
62
60
  <% if provider_credential.persisted? %>
@@ -1,6 +1,6 @@
1
1
  <div class="ck-actions" id="run_actions">
2
2
  <% running = run.status == "running" %>
3
- <%= button_to run_path(run), method: :delete, form_class: "inline-block", class: "ck-icon-btn", title: "Delete run", "aria-label": "Delete run", disabled: running, data: { turbo_confirm: "Delete this run and all its responses?" } do %><%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
3
+ <%= button_to run_path(run), method: :delete, form_class: "inline-block", class: "ck-icon-btn", title: "Delete run", "aria-label": "Delete run", disabled: running, data: { turbo_confirm: "Delete this run and all its responses?", ck_confirm_label: "Delete", ck_confirm_tone: "danger" } do %><%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %><% end %>
4
4
  <% if running %>
5
5
  <%= link_to "Edit", edit_run_path(run), class: ck_button_classes(:light, variant: :outline) + " disabled", "aria-disabled": "true", tabindex: "-1" %>
6
6
  <% else %>
@@ -0,0 +1,2 @@
1
+ <%# locals: (form_id:, path:) %>
2
+ <%= form_with url: path, method: :delete, id: form_id, class: "ck-delete-form" do %><% end %>
@@ -1,3 +1,10 @@
1
+ <% if tag.persisted? %>
2
+ <% tag_delete_id = "ck_delete_tag_#{tag.id}" %>
3
+ <% applied_n = tag.taggings.count %>
4
+ <% tag_delete_confirm = applied_n.zero? ?
5
+ "Delete \"#{tag.name}\"? It's not currently applied to anything." :
6
+ "Delete \"#{tag.name}\"? It's currently applied to #{pluralize(applied_n, 'item')}. They'll lose this tag." %>
7
+ <% end %>
1
8
  <%= form_with(model: tag, local: true) do |form| %>
2
9
  <div class="ck-card ck-form-card">
3
10
  <% name_error = tag.errors[:name].first %>
@@ -18,23 +25,14 @@
18
25
 
19
26
  <div class="ck-actions">
20
27
  <% if tag.persisted? %>
21
- <% applied_n = tag.taggings.count %>
22
- <% confirm = if applied_n.zero?
23
- "Delete \"#{tag.name}\"? It's not currently applied to anything."
24
- else
25
- "Delete \"#{tag.name}\"? It's currently applied to #{pluralize(applied_n, 'item')} — they'll lose this tag."
26
- end %>
27
- <%= button_to tag_path(tag), method: :delete,
28
- form_class: "inline-block",
29
- class: "ck-icon-btn",
30
- title: "Delete tag",
31
- "aria-label": "Delete tag",
32
- data: { turbo_confirm: confirm } do %>
33
- <%= heroicon_tag "trash", variant: :outline, size: 16, "aria-hidden": "true" %>
34
- <% end %>
28
+ <%= ck_delete_trigger(form_id: tag_delete_id, label: "Delete tag", confirm: tag_delete_confirm) %>
35
29
  <% end %>
36
30
  <%= link_to "Cancel", tags_path, class: ck_button_classes(:light, variant: :outline), tabindex: "0" %>
37
31
  <%= form.submit(tag.persisted? ? "Save tag" : "Create tag", class: ck_button_classes(:dark)) %>
38
32
  </div>
39
33
  </div>
40
34
  <% end %>
35
+
36
+ <% if tag.persisted? %>
37
+ <%= render "completion_kit/shared/delete_form", form_id: tag_delete_id, path: tag_path(tag) %>
38
+ <% end %>
@@ -60,5 +60,22 @@
60
60
  <%= yield %>
61
61
  </div>
62
62
  </main>
63
+
64
+ <dialog id="ck-confirm-modal" class="ck-modal ck-modal--sm" role="alertdialog" aria-labelledby="ck-confirm-title" aria-describedby="ck-confirm-message">
65
+ <article class="ck-modal__panel" tabindex="-1">
66
+ <header class="ck-modal__header">
67
+ <div class="ck-modal__heading">
68
+ <h2 class="ck-modal__title" id="ck-confirm-title">Please confirm</h2>
69
+ </div>
70
+ </header>
71
+ <div class="ck-modal__body">
72
+ <p class="ck-confirm__message" id="ck-confirm-message"></p>
73
+ </div>
74
+ <div class="ck-modal__footer">
75
+ <button type="button" class="<%= ck_button_classes(:light, variant: :outline) %>" data-ck-confirm-cancel>Cancel</button>
76
+ <button type="button" class="<%= ck_button_classes(:dark) %>" data-ck-confirm-accept>Confirm</button>
77
+ </div>
78
+ </article>
79
+ </dialog>
63
80
  </body>
64
81
  </html>
@@ -1,3 +1,3 @@
1
1
  module CompletionKit
2
- VERSION = "0.26.1"
2
+ VERSION = "0.26.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.1
4
+ version: 0.26.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Bastin
@@ -421,6 +421,7 @@ files:
421
421
  - app/views/completion_kit/runs/new.html.erb
422
422
  - app/views/completion_kit/runs/show.html.erb
423
423
  - app/views/completion_kit/shared/_branded_select.html.erb
424
+ - app/views/completion_kit/shared/_delete_form.html.erb
424
425
  - app/views/completion_kit/shared/_settings_nav.html.erb
425
426
  - app/views/completion_kit/suggestions/_scoreboard.html.erb
426
427
  - app/views/completion_kit/suggestions/_state.html.erb