completion-kit 0.12.1 → 0.12.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: a39761d576cee622378682d2b920ed0540bd4cbefbda033236c2108c1676d835
4
- data.tar.gz: 7ad068f5c6a9a96513d47e689f5b0926e101aec4058e033076c9e6d87b31d003
3
+ metadata.gz: 678fa5e49856863408484244ead7994c2168558199d247134abbc18e97a66b8e
4
+ data.tar.gz: 758176dbbbabb1bd6ef53598dde78f20c1606650187e7e3edc317e0b73c26744
5
5
  SHA512:
6
- metadata.gz: 80e6c44594f02b408911390576ea7ed9c377ef4ab4d7f068341b5177277a8baa6776e09986a4afedd430d723f84e700ca85962a504f949eb17a860d53cfeba82
7
- data.tar.gz: 749da38fb1236140bc6f6cf45419d979500c671a1a8e92471c35aa79abe95fbb32a5d898286932cf4b82af0628e533b93a8ad6fc0b458c4322321efa98317c4d
6
+ metadata.gz: a8cd93d6aca2264b16218a16a4a06582b1332575a5e9f29ea076ef3188ca9edad7160286897250d042d6aa0af83179846fd02561dfdd12c01c2c785f8c62f11a
7
+ data.tar.gz: b4c5b9a904446c8c4dd17c75d89cb7754fd434b455b29766db9282ee3b1a3ce1401cfef1c635ed5c24612ee1699f61983e5d5e9a3bbef39c066425ee85ee4de1
@@ -111,13 +111,19 @@ function ckSetRefreshButtonsBusy(busy) {
111
111
  btn.disabled = busy;
112
112
  });
113
113
  }
114
+ function ckRefreshUrl() {
115
+ var el = document.querySelector("[data-ck-refresh-url]");
116
+ return el ? el.getAttribute("data-ck-refresh-url") : null;
117
+ }
114
118
  function ckRefreshModels() {
115
119
  if (ckRefreshing) return;
120
+ var url = ckRefreshUrl();
121
+ if (!url) return;
116
122
  ckRefreshing = true;
117
123
  ckSetRefreshButtonsBusy(true);
118
124
  ckUpdateRefreshProgress();
119
125
  var csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute("content");
120
- fetch("/completion_kit/refresh_models", {
126
+ fetch(url, {
121
127
  method: "POST",
122
128
  headers: { "X-CSRF-Token": csrfToken }
123
129
  });
@@ -131,8 +137,15 @@ function ckDiscoveringInDom() {
131
137
  return !!document.querySelector('[id^="discovery_status_"] .ck-discovery-bar:not(.ck-discovery-bar--failed):not(.ck-discovery-bar--completed)');
132
138
  }
133
139
 
140
+ function ckStatusesUrl() {
141
+ var el = document.querySelector("[data-ck-statuses-url]");
142
+ return el ? el.getAttribute("data-ck-statuses-url") : null;
143
+ }
144
+
134
145
  function ckPollDiscoveryOnce() {
135
- fetch("/completion_kit/provider_credentials/statuses", { headers: { "Accept": "text/vnd.turbo-stream.html" } })
146
+ var url = ckStatusesUrl();
147
+ if (!url) return;
148
+ fetch(url, { headers: { "Accept": "text/vnd.turbo-stream.html" } })
136
149
  .then(function(r) { return r.ok ? r.text() : null; })
137
150
  .then(function(html) {
138
151
  if (html && window.Turbo && window.Turbo.renderStreamMessage) window.Turbo.renderStreamMessage(html);
@@ -142,6 +155,7 @@ function ckPollDiscoveryOnce() {
142
155
 
143
156
  function ckStartDiscoveryPolling(graceMs) {
144
157
  if (!document.querySelector('[id^="discovery_status_"]')) return;
158
+ if (!ckStatusesUrl()) return;
145
159
  ckDiscoveryPollUntil = Date.now() + (graceMs || 0);
146
160
  if (ckDiscoveryPollTimer) return;
147
161
  ckPollDiscoveryOnce();
@@ -114,22 +114,24 @@ module CompletionKit
114
114
  end
115
115
 
116
116
  def broadcast_model_dropdowns
117
- helper = ApplicationController.helpers
118
- gen_html = helper.ck_model_options_html(:generation)
119
- judge_html = '<option value="">None</option>' + helper.ck_model_options_html(:judging)
120
-
121
- Turbo::StreamsChannel.broadcast_action_to(
122
- "completion_kit_provider_#{id}",
123
- action: :replace,
124
- target: "prompt_llm_model",
125
- html: "<select name=\"prompt[llm_model]\" id=\"prompt_llm_model\" class=\"ck-input\">#{gen_html}</select>"
126
- )
127
- Turbo::StreamsChannel.broadcast_action_to(
128
- "completion_kit_provider_#{id}",
129
- action: :replace,
130
- target: "run_judge_model",
131
- html: "<select name=\"run[judge_model]\" id=\"run_judge_model\" class=\"ck-input\">#{judge_html}</select>"
132
- )
117
+ safely_broadcast do
118
+ helper = ApplicationController.helpers
119
+ gen_html = helper.ck_model_options_html(:generation)
120
+ judge_html = '<option value="">None</option>' + helper.ck_model_options_html(:judging)
121
+
122
+ Turbo::StreamsChannel.broadcast_action_to(
123
+ "completion_kit_provider_#{id}",
124
+ action: :replace,
125
+ target: "prompt_llm_model",
126
+ html: "<select name=\"prompt[llm_model]\" id=\"prompt_llm_model\" class=\"ck-input\">#{gen_html}</select>"
127
+ )
128
+ Turbo::StreamsChannel.broadcast_action_to(
129
+ "completion_kit_provider_#{id}",
130
+ action: :replace,
131
+ target: "run_judge_model",
132
+ html: "<select name=\"run[judge_model]\" id=\"run_judge_model\" class=\"ck-input\">#{judge_html}</select>"
133
+ )
134
+ end
133
135
  end
134
136
 
135
137
  def render_partial(partial, locals)
@@ -46,7 +46,7 @@
46
46
  <% else %>
47
47
  <p class="ck-meta-copy">No models available. <%= link_to "Add a provider", provider_credentials_path, class: "ck-link" %> or click refresh after configuring a provider.</p>
48
48
  <% end %>
49
- <div hidden data-refresh-progress-carriers>
49
+ <div hidden data-refresh-progress-carriers data-ck-refresh-url="<%= refresh_models_path %>" data-ck-statuses-url="<%= statuses_provider_credentials_path %>">
50
50
  <% CompletionKit::ProviderCredential.find_each do |pc| %>
51
51
  <%= turbo_stream_from "completion_kit_provider_#{pc.id}" %>
52
52
  <%= render "completion_kit/provider_credentials/discovery_status", provider_credential: pc, show_completed: false %>
@@ -38,5 +38,7 @@
38
38
 
39
39
  <% if provider_credential.persisted? %>
40
40
  <%= turbo_stream_from "completion_kit_provider_#{provider_credential.id}" %>
41
- <%= render "models_card", provider_credential: provider_credential %>
41
+ <div data-ck-statuses-url="<%= statuses_provider_credentials_path %>">
42
+ <%= render "models_card", provider_credential: provider_credential %>
43
+ </div>
42
44
  <% end %>
@@ -16,7 +16,7 @@
16
16
 
17
17
  <% if @provider_credentials.any? %>
18
18
  <% default_endpoints = {"openai" => "https://api.openai.com", "anthropic" => "https://api.anthropic.com"} %>
19
- <div class="ck-provider-list">
19
+ <div class="ck-provider-list" data-ck-statuses-url="<%= statuses_provider_credentials_path %>">
20
20
  <% @provider_credentials.each do |provider_credential| %>
21
21
  <% masked_key = provider_credential.api_key.present? ? "#{provider_credential.api_key[0..6]}#{'•' * 12}#{provider_credential.api_key[-4..]}" : "—" %>
22
22
  <a href="<%= edit_provider_credential_path(provider_credential) %>" class="ck-provider-card">
@@ -97,7 +97,7 @@
97
97
  <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>
98
98
  </div>
99
99
  <p class="ck-field-hint" id="judge-hint"></p>
100
- <div hidden data-refresh-progress-carriers>
100
+ <div hidden data-refresh-progress-carriers data-ck-refresh-url="<%= refresh_models_path %>" data-ck-statuses-url="<%= statuses_provider_credentials_path %>">
101
101
  <% CompletionKit::ProviderCredential.find_each do |pc| %>
102
102
  <%= turbo_stream_from "completion_kit_provider_#{pc.id}" %>
103
103
  <%= render "completion_kit/provider_credentials/discovery_status", provider_credential: pc, show_completed: false %>
@@ -1,3 +1,3 @@
1
1
  module CompletionKit
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.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.12.1
4
+ version: 0.12.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Bastin