chore: added more @spec
This commit is contained in:
@@ -6,6 +6,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.MessageBuild do
|
||||
alias BDS.Desktop.ShellData
|
||||
alias BDS.Desktop.ShellLive.ChatEditor.{ModelSelection, ToolSurfaces, ToolTracking}
|
||||
|
||||
@spec build(term()) :: term()
|
||||
def build(%{current_tab: %{type: :chat, id: conversation_id}} = assigns) do
|
||||
case AI.get_chat_conversation(conversation_id) do
|
||||
nil ->
|
||||
|
||||
@@ -6,6 +6,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ModelSelection do
|
||||
|
||||
import Phoenix.Component, only: [assign: 3]
|
||||
|
||||
@spec toggle_model_selector(term(), term()) :: term()
|
||||
def toggle_model_selector(socket, reload) do
|
||||
%{id: conversation_id} = socket.assigns.current_tab
|
||||
current = Map.get(socket.assigns.chat_model_selectors_open, conversation_id, false)
|
||||
@@ -18,6 +19,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ModelSelection do
|
||||
|> reload.(socket.assigns.workbench)
|
||||
end
|
||||
|
||||
@spec set_model(term(), term(), term(), term()) :: term()
|
||||
def set_model(socket, model_id, reload, append_output) do
|
||||
%{id: conversation_id} = socket.assigns.current_tab
|
||||
|
||||
@@ -37,6 +39,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ModelSelection do
|
||||
end
|
||||
end
|
||||
|
||||
@spec group_available_models(term()) :: term()
|
||||
def group_available_models(models) when is_list(models) do
|
||||
models
|
||||
|> Enum.group_by(&Map.get(&1, :provider, "other"))
|
||||
@@ -54,6 +57,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ModelSelection do
|
||||
|> Enum.sort_by(&String.downcase(to_string(&1.label)))
|
||||
end
|
||||
|
||||
@spec needs_api_key?(term()) :: term()
|
||||
def needs_api_key?(true), do: false
|
||||
|
||||
def needs_api_key?(false) do
|
||||
|
||||
@@ -14,9 +14,12 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
"render_tabs"
|
||||
])
|
||||
|
||||
@spec render_tool?(term()) :: term()
|
||||
def render_tool?(name) when is_binary(name), do: MapSet.member?(@render_tool_names, name)
|
||||
@spec render_tool?(term()) :: term()
|
||||
def render_tool?(_name), do: false
|
||||
|
||||
@spec build_render_surfaces(term(), term(), term()) :: term()
|
||||
def build_render_surfaces(tool_calls, message_id, assigns) do
|
||||
tool_calls
|
||||
|> Enum.with_index()
|
||||
@@ -28,6 +31,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec build_render_surface(term(), term(), term()) :: term()
|
||||
def build_render_surface(%{name: name, arguments: arguments}, surface_id, assigns) do
|
||||
if MapSet.member?(@render_tool_names, name) do
|
||||
do_build_render_surface(name, arguments || %{}, surface_id, assigns)
|
||||
@@ -51,6 +55,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
end
|
||||
end
|
||||
|
||||
@spec normalize_tool_surface(term()) :: term()
|
||||
def normalize_tool_surface(_content), do: nil
|
||||
|
||||
defp do_build_render_surface("render_card", arguments, surface_id, _assigns) do
|
||||
@@ -150,7 +155,12 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
label: map_value(field, "label", key),
|
||||
input_type: map_value(field, "inputType") || map_value(field, "input_type", "text"),
|
||||
placeholder: map_value(field, "placeholder"),
|
||||
value: Map.get(stored_fields, key, map_value(field, "defaultValue") || map_value(field, "default_value")),
|
||||
value:
|
||||
Map.get(
|
||||
stored_fields,
|
||||
key,
|
||||
map_value(field, "defaultValue") || map_value(field, "default_value")
|
||||
),
|
||||
options: decode_surface_options(map_value(field, "options", [])),
|
||||
required?: truthy?(map_value(field, "required", false))
|
||||
}
|
||||
@@ -161,8 +171,12 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
type: "form",
|
||||
title: map_value(arguments, "title"),
|
||||
fields: fields,
|
||||
submit_label: map_value(arguments, "submitLabel") || map_value(arguments, "submit_label", translated("chat.stop")),
|
||||
submit_action: map_value(arguments, "submitAction") || map_value(arguments, "submit_action", "submitForm")
|
||||
submit_label:
|
||||
map_value(arguments, "submitLabel") ||
|
||||
map_value(arguments, "submit_label", translated("chat.stop")),
|
||||
submit_action:
|
||||
map_value(arguments, "submitAction") ||
|
||||
map_value(arguments, "submit_action", "submitForm")
|
||||
}
|
||||
end
|
||||
|
||||
@@ -181,7 +195,11 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
|> List.wrap()
|
||||
|> Enum.with_index()
|
||||
|> Enum.map(fn {content, content_index} ->
|
||||
build_tab_surface(content, "#{surface_id}-tab-#{tab_index}-#{content_index}", assigns)
|
||||
build_tab_surface(
|
||||
content,
|
||||
"#{surface_id}-tab-#{tab_index}-#{content_index}",
|
||||
assigns
|
||||
)
|
||||
end)
|
||||
}
|
||||
end)
|
||||
@@ -203,11 +221,21 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolSurfaces do
|
||||
type = map_value(content, "type", "text")
|
||||
|
||||
case type do
|
||||
render_type when render_type in ["card", "chart", "form", "list", "metric", "mindmap", "table", "tabs"] ->
|
||||
do_build_render_surface("render_#{render_type}", Map.delete(content, "type"), surface_id, assigns)
|
||||
render_type
|
||||
when render_type in ["card", "chart", "form", "list", "metric", "mindmap", "table", "tabs"] ->
|
||||
do_build_render_surface(
|
||||
"render_#{render_type}",
|
||||
Map.delete(content, "type"),
|
||||
surface_id,
|
||||
assigns
|
||||
)
|
||||
|
||||
"text" ->
|
||||
%{id: surface_id, type: "text", body: map_value(content, "body") || map_value(content, "text", "")}
|
||||
%{
|
||||
id: surface_id,
|
||||
type: "text",
|
||||
body: map_value(content, "body") || map_value(content, "text", "")
|
||||
}
|
||||
|
||||
_other ->
|
||||
%{id: surface_id, type: "json", raw: content}
|
||||
|
||||
@@ -3,10 +3,12 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolTracking do
|
||||
|
||||
@tool_args_max_length 30
|
||||
|
||||
@spec tool_call_name(term()) :: term()
|
||||
def tool_call_name(tool_call) when is_map(tool_call) do
|
||||
BDS.MapUtils.attr(tool_call, :name) || "tool"
|
||||
end
|
||||
|
||||
@spec tool_call_arguments(term()) :: term()
|
||||
def tool_call_arguments(tool_call) when is_map(tool_call) do
|
||||
BDS.MapUtils.attr(tool_call, :arguments) || BDS.MapUtils.attr(tool_call, :args) || %{}
|
||||
end
|
||||
@@ -25,6 +27,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolTracking do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec normalize_tool_calls(term()) :: term()
|
||||
def normalize_tool_calls(_tool_calls), do: []
|
||||
|
||||
def tool_arguments_preview(arguments) when is_map(arguments) do
|
||||
@@ -33,6 +36,7 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolTracking do
|
||||
|> Enum.join(", ")
|
||||
end
|
||||
|
||||
@spec tool_arguments_preview(term()) :: term()
|
||||
def tool_arguments_preview(_arguments), do: ""
|
||||
|
||||
def mark_tool_call_completed(entry, tool_call_id) when is_binary(tool_call_id) do
|
||||
@@ -47,8 +51,10 @@ defmodule BDS.Desktop.ShellLive.ChatEditor.ToolTracking do
|
||||
end)
|
||||
end
|
||||
|
||||
@spec mark_tool_call_completed(term(), term()) :: term()
|
||||
def mark_tool_call_completed(entry, _tool_call_id), do: entry
|
||||
|
||||
@spec tool_markers_from_events(term()) :: term()
|
||||
def tool_markers_from_events(nil), do: []
|
||||
|
||||
def tool_markers_from_events(%{tool_events: tool_events}) do
|
||||
|
||||
Reference in New Issue
Block a user