-module(glean@tool). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/glean/tool.gleam"). -export([new/4, with_max_retries/2, toolset/1, empty_toolset/0, find/2, to_specs/1, names/1, is_empty/1, size/1]). -export_type([tool/1, tool_context/1, toolset/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -type tool(IRT) :: {tool, binary(), binary(), glean@schema:schema(), fun((tool_context(IRT), binary()) -> {ok, binary()} | {error, glean@error:glean_error()}), integer()}. -type tool_context(IRU) :: {tool_context, IRU, binary(), binary(), integer(), integer(), integer()}. -opaque toolset(IRV) :: {toolset, gleam@dict:dict(binary(), tool(IRV))}. -file("src/glean/tool.gleam", 59). ?DOC(" Create a tool with the required fields.\n"). -spec new( binary(), binary(), glean@schema:schema(), fun((tool_context(IRW), binary()) -> {ok, binary()} | {error, glean@error:glean_error()}) ) -> tool(IRW). new(Name, Description, Input_schema, Execute) -> case Name /= <<""/utf8>> of true -> nil; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"glean/tool"/utf8>>, function => <<"new"/utf8>>, line => 65, value => _assert_fail, start => 2163, 'end' => 2191, pattern_start => 2174, pattern_end => 2178}) end, case Description /= <<""/utf8>> of true -> nil; _assert_fail@1 -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"glean/tool"/utf8>>, function => <<"new"/utf8>>, line => 66, value => _assert_fail@1, start => 2194, 'end' => 2229, pattern_start => 2205, pattern_end => 2209}) end, {tool, Name, Description, Input_schema, Execute, 0}. -file("src/glean/tool.gleam", 77). ?DOC(" Set max retries on a tool.\n"). -spec with_max_retries(tool(ISB), integer()) -> tool(ISB). with_max_retries(Tool, Max_retries) -> case Max_retries >= 0 of true -> nil; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"glean/tool"/utf8>>, function => <<"with_max_retries"/utf8>>, line => 78, value => _assert_fail, start => 2474, 'end' => 2508, pattern_start => 2485, pattern_end => 2489}) end, {tool, erlang:element(2, Tool), erlang:element(3, Tool), erlang:element(4, Tool), erlang:element(5, Tool), Max_retries}. -file("src/glean/tool.gleam", 84). ?DOC( " Create a Toolset from a list of tools.\n" " Asserts that all tool names are unique.\n" ). -spec toolset(list(tool(ISE))) -> toolset(ISE). toolset(Tools) -> Names = gleam@list:map(Tools, fun(T) -> erlang:element(2, T) end), Unique_names = gleam@list:unique(Names), case erlang:length(Names) =:= erlang:length(Unique_names) of true -> nil; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Pattern match failed, no pattern matched the value."/utf8>>, file => <>, module => <<"glean/tool"/utf8>>, function => <<"toolset"/utf8>>, line => 87, value => _assert_fail, start => 2789, 'end' => 2854, pattern_start => 2800, pattern_end => 2804}) end, Tool_dict = begin _pipe = Tools, _pipe@1 = gleam@list:map( _pipe, fun(T@1) -> {erlang:element(2, T@1), T@1} end ), maps:from_list(_pipe@1) end, {toolset, Tool_dict}. -file("src/glean/tool.gleam", 96). ?DOC(" Create an empty toolset.\n"). -spec empty_toolset() -> toolset(any()). empty_toolset() -> {toolset, maps:new()}. -file("src/glean/tool.gleam", 101). ?DOC(" Look up a tool by name.\n"). -spec find(toolset(ISK), binary()) -> {ok, tool(ISK)} | {error, glean@error:glean_error()}. find(Toolset, Name) -> case gleam_stdlib:map_get(erlang:element(2, Toolset), Name) of {ok, Tool} -> {ok, Tool}; {error, nil} -> {error, {tool_not_found, Name}} end. -file("src/glean/tool.gleam", 112). ?DOC(" Convert all tools in the toolset to ToolSpecs for sending to the provider.\n"). -spec to_specs(toolset(any())) -> list(glean@provider:tool_spec()). to_specs(Toolset) -> _pipe = erlang:element(2, Toolset), _pipe@1 = maps:values(_pipe), gleam@list:map( _pipe@1, fun(T) -> {tool_spec, erlang:element(2, T), erlang:element(3, T), erlang:element(4, T)} end ). -file("src/glean/tool.gleam", 125). ?DOC(" Get the list of tool names in this toolset.\n"). -spec names(toolset(any())) -> list(binary()). names(Toolset) -> maps:keys(erlang:element(2, Toolset)). -file("src/glean/tool.gleam", 130). ?DOC(" Check if a toolset is empty (has no tools).\n"). -spec is_empty(toolset(any())) -> boolean(). is_empty(Toolset) -> gleam@dict:is_empty(erlang:element(2, Toolset)). -file("src/glean/tool.gleam", 135). ?DOC(" Get the number of tools in the toolset.\n"). -spec size(toolset(any())) -> integer(). size(Toolset) -> maps:size(erlang:element(2, Toolset)).