Skip to content

Commit 415f9a7

Browse files
committed
Assistants redirect to settings if no token yet
1 parent fc7a482 commit 415f9a7

File tree

5 files changed

+68
-32
lines changed

5 files changed

+68
-32
lines changed

app/models/api_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def effective_token
3131
token.presence || default_llm_key
3232
end
3333

34+
def effective_token?
35+
effective_token.present?
36+
end
37+
3438
private
3539

3640
def default_llm_key

app/views/assistants/_assistant.html.erb

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,41 +18,55 @@
1818
data-role="assistant"
1919
data-radio-behavior-target="radio"
2020
data-action="radio-changed@window->radio-behavior#select"
21-
data-radio-behavior-id-param="<%= assistant.id %>"
22-
data-transition-target="<%= !visible && 'transitionable' %>"
21+
data-radio-behavior-id-param="<%= assistant.id %>"
22+
data-transition-target="<%= !visible && 'transitionable' %>"
2323
>
24-
<%= link_to new_assistant_message_path(assistant), class: "flex-1 flex py-1 items-center text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
25-
<%= render partial: "layouts/assistant_avatar", locals: { assistant: assistant, size: 7, classes: "mr-2" } %>
26-
<%= assistant.name %>
27-
<% end %>
28-
<div class="hidden gap-3 pl-2 relationship:flex group-hover:flex">
29-
<% if settings %>
30-
<div class="inline-flex outline-none dropdown dropdown-end">
31-
<%= icon "ellipsis-horizontal",
32-
tabindex: 0,
33-
role: :button,
34-
variant: :micro,
24+
<% if assistant.api_service.effective_token? %>
25+
<%= link_to new_assistant_message_path(assistant), class: "flex items-center py-1 text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
26+
<div class="relative inline-block w-7 h-7 mr-2">
27+
<%= render partial: "layouts/assistant_avatar", locals: { assistant:, size: 7 } %>
28+
</div>
29+
<%= assistant.name %>
30+
<% end %>
31+
<div class="hidden gap-3 pl-2 relationship:flex group-hover:flex">
32+
<% if settings %>
33+
<div class="inline-flex outline-none dropdown dropdown-end">
34+
<%= icon "ellipsis-horizontal",
35+
tabindex: 0,
36+
role: :button,
37+
variant: :micro,
38+
size: 18,
39+
class: "outline-none text-gray-950 dark:text-gray-100 invisible group-hover:visible cursor-pointer",
40+
data: { controller: "nested-pointer" },
41+
title: "More"
42+
%>
43+
<menu tabindex="0" class="dropdown-content z-10 menu p-2 shadow-xl bg-base-100 rounded-box w-52 -mr-10 mt-7 dark:!bg-gray-700" data-controller="nested-pointer">
44+
<li><%= link_to edit_settings_assistant_path(assistant) do %><%= icon "cog-6-tooth", variant: :outline, size: 18 %>Settings<% end %></li>
45+
<!-- <li><a><%= icon "arrow-up-tray", variant: :outline, size: 18 %>Share</a></li> -->
46+
</menu>
47+
</div>
48+
<% end %>
49+
<%= link_to new_assistant_message_path(assistant), class: "inline-flex", data: { role: "new" } do %>
50+
<%= icon "pencil-square",
51+
variant: :outline,
3552
size: 18,
36-
class: "outline-none text-gray-950 dark:text-gray-100 invisible group-hover:visible cursor-pointer",
37-
'data-controller': "nested-pointer",
38-
title: "More"
53+
class: "text-gray-950 dark:text-gray-100 cursor-pointer group-hover:visible invisible
54+
relationship:visible relationship:text-gray-950 dark:relationship:text-gray-100",
55+
data: { controller: "nested-pointer" },
56+
title: "New"
3957
%>
40-
<menu tabindex="0" class="dropdown-content z-10 menu p-2 shadow-xl bg-base-100 rounded-box w-52 -mr-10 mt-7 dark:!bg-gray-700" data-controller="nested-pointer">
41-
<li><%= link_to edit_settings_assistant_path(assistant) do %><%= icon "cog-6-tooth", variant: :outline, size: 18 %>Settings<% end %></li>
42-
<!-- <li><a><%= icon "arrow-up-tray", variant: :outline, size: 18 %>Share</a></li> -->
43-
</menu>
58+
<% end %>
59+
</div>
60+
<% else %>
61+
<%= link_to edit_settings_api_service_path(assistant.api_service), class: "flex items-center py-1 text-gray-950 dark:text-gray-100 font-medium truncate", data: { role: "name" } do %>
62+
<div class="relative inline-block w-7 h-7 mr-2">
63+
<%= render partial: "layouts/assistant_avatar", locals: { assistant:, size: 7 } %>
64+
<div class="absolute -bottom-1 right-0 bg-gray-50 dark:bg-gray-900 px-px py-[2px] rounded-full">
65+
<%= icon "lock-closed", variant: :outline, size: 12, class: "text-gray-950 dark:text-gray-100" %>
66+
</div>
4467
</div>
68+
<%= assistant.name %>
4569
<% end %>
46-
<%= link_to new_assistant_message_path(assistant), class: "inline-flex", data: { role: "new" } do %>
47-
<%= icon "pencil-square",
48-
variant: :outline,
49-
size: 18,
50-
class: "text-gray-950 dark:text-gray-100 cursor-pointer group-hover:visible invisible
51-
relationship:visible relationship:text-gray-950 dark:relationship:text-gray-100",
52-
'data-controller': "nested-pointer",
53-
title: "New"
54-
%>
55-
<% end %>
56-
</div>
70+
<% end %>
5771
</div>
5872
</div>

app/views/layouts/_assistant_avatar.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ elsif assistant.name.starts_with?("Meta Llama")
1414
end
1515
%>
1616
<% if logo %>
17-
<picture class="<%= classes %> bg-white border border-gray-100 overflow-hidden">
17+
<picture class="<%= classes %> block bg-white border border-gray-100 overflow-hidden">
1818
<%= image_tag(logo, class: "w-full h-full") %>
1919
</picture>
2020
<% else %>

test/fixtures/api_services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ keith_other_service:
2626
token: abc-secret
2727
driver: openai
2828

29+
keith_missing_token_service:
30+
name: Keith Server
31+
user: keith
32+
url: http://test.com/models
33+
driver: openai
2934

3035
rob_openai_service:
3136
name: OpenAI

test/system/messages/nav_column_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,17 @@ class NavColumnTest < ApplicationSystemTestCase
160160
click_element pencil_on_second_assistant
161161
assert_current_path new_assistant_message_path(assistant2)
162162
end
163+
164+
test "clicking the assistant name redirects to API service settings if token is missing" do
165+
assistant = assistants(:keith_gpt4)
166+
keith_missing_token_service = api_services(:keith_missing_token_service)
167+
assistant.language_model.update! api_service: keith_missing_token_service
168+
169+
conversation_path = conversation_messages_path(conversations(:greeting), version: 1)
170+
visit conversation_path
171+
172+
click_text assistant.name
173+
174+
assert_current_path edit_settings_api_service_path(keith_missing_token_service)
175+
end
163176
end

0 commit comments

Comments
 (0)