activeagent 0.6.3 → 1.0.0.rc1
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 +4 -4
- data/CHANGELOG.md +210 -2
- data/README.md +15 -24
- data/lib/active_agent/base.rb +389 -39
- data/lib/active_agent/concerns/callbacks.rb +251 -0
- data/lib/active_agent/concerns/observers.rb +147 -0
- data/lib/active_agent/concerns/parameterized.rb +292 -0
- data/lib/active_agent/concerns/provider.rb +120 -0
- data/lib/active_agent/concerns/queueing.rb +36 -0
- data/lib/active_agent/concerns/rescue.rb +64 -0
- data/lib/active_agent/concerns/streaming.rb +282 -0
- data/lib/active_agent/concerns/tooling.rb +23 -0
- data/lib/active_agent/concerns/view.rb +150 -0
- data/lib/active_agent/configuration.rb +442 -20
- data/lib/active_agent/generation.rb +141 -47
- data/lib/active_agent/generation_provider/open_router/types.rb +505 -0
- data/lib/active_agent/generation_provider/xai_provider.rb +144 -0
- data/lib/active_agent/providers/_base_provider.rb +410 -0
- data/lib/active_agent/providers/anthropic/_types.rb +63 -0
- data/lib/active_agent/providers/anthropic/options.rb +53 -0
- data/lib/active_agent/providers/anthropic/request.rb +109 -0
- data/lib/active_agent/providers/anthropic/requests/_types.rb +190 -0
- data/lib/active_agent/providers/anthropic/requests/container_params.rb +19 -0
- data/lib/active_agent/providers/anthropic/requests/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/context_management_config.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/messages/_types.rb +189 -0
- data/lib/active_agent/providers/anthropic/requests/messages/assistant.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/base.rb +63 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/_types.rb +143 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/base.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/document.rb +26 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/image.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/redacted_thinking.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/search_result.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/_types.rb +171 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/base.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_text.rb +25 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_base64.rb +27 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_file.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_url.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/text.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/thinking.rb +23 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_result.rb +24 -0
- data/lib/active_agent/providers/anthropic/requests/messages/content/tool_use.rb +28 -0
- data/lib/active_agent/providers/anthropic/requests/messages/user.rb +21 -0
- data/lib/active_agent/providers/anthropic/requests/metadata.rb +18 -0
- data/lib/active_agent/providers/anthropic/requests/response_format.rb +22 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/_types.rb +60 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/disabled.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/thinking_config/enabled.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/_types.rb +78 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/any.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/auto.rb +17 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/base.rb +20 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/none.rb +16 -0
- data/lib/active_agent/providers/anthropic/requests/tool_choice/tool.rb +20 -0
- data/lib/active_agent/providers/anthropic_provider.rb +211 -0
- data/lib/active_agent/providers/common/messages/_types.rb +124 -0
- data/lib/active_agent/providers/common/messages/assistant.rb +57 -0
- data/lib/active_agent/providers/common/messages/base.rb +17 -0
- data/lib/active_agent/providers/common/messages/system.rb +20 -0
- data/lib/active_agent/providers/common/messages/tool.rb +21 -0
- data/lib/active_agent/providers/common/messages/user.rb +20 -0
- data/lib/active_agent/providers/common/model.rb +361 -0
- data/lib/active_agent/providers/common/response.rb +13 -0
- data/lib/active_agent/providers/common/responses/_types.rb +51 -0
- data/lib/active_agent/providers/common/responses/base.rb +151 -0
- data/lib/active_agent/providers/common/responses/embed.rb +33 -0
- data/lib/active_agent/providers/common/responses/format.rb +31 -0
- data/lib/active_agent/providers/common/responses/message.rb +3 -0
- data/lib/active_agent/providers/common/responses/prompt.rb +42 -0
- data/lib/active_agent/providers/concerns/exception_handler.rb +72 -0
- data/lib/active_agent/providers/concerns/previewable.rb +150 -0
- data/lib/active_agent/providers/log_subscriber.rb +360 -0
- data/lib/active_agent/providers/mock/_types.rb +77 -0
- data/lib/active_agent/providers/mock/embedding_request.rb +17 -0
- data/lib/active_agent/providers/mock/messages/_types.rb +103 -0
- data/lib/active_agent/providers/mock/messages/assistant.rb +26 -0
- data/lib/active_agent/providers/mock/messages/base.rb +63 -0
- data/lib/active_agent/providers/mock/messages/user.rb +18 -0
- data/lib/active_agent/providers/mock/options.rb +30 -0
- data/lib/active_agent/providers/mock/request.rb +38 -0
- data/lib/active_agent/providers/mock_provider.rb +311 -0
- data/lib/active_agent/providers/ollama/_types.rb +5 -0
- data/lib/active_agent/providers/ollama/chat/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/chat/request.rb +70 -0
- data/lib/active_agent/providers/ollama/chat/requests/_types.rb +3 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/_types.rb +116 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/assistant.rb +19 -0
- data/lib/active_agent/providers/ollama/chat/requests/messages/user.rb +19 -0
- data/lib/active_agent/providers/ollama/embedding/_types.rb +44 -0
- data/lib/active_agent/providers/ollama/embedding/request.rb +77 -0
- data/lib/active_agent/providers/ollama/embedding/requests/_types.rb +83 -0
- data/lib/active_agent/providers/ollama/embedding/requests/options.rb +104 -0
- data/lib/active_agent/providers/ollama/options.rb +27 -0
- data/lib/active_agent/providers/ollama_provider.rb +95 -0
- data/lib/active_agent/providers/open_ai/_base.rb +58 -0
- data/lib/active_agent/providers/open_ai/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/_types.rb +44 -0
- data/lib/active_agent/providers/open_ai/chat/request.rb +215 -0
- data/lib/active_agent/providers/open_ai/chat/requests/_types.rb +229 -0
- data/lib/active_agent/providers/open_ai/chat/requests/audio.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/_types.rb +123 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/assistant.rb +42 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/base.rb +78 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/_types.rb +133 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/audio.rb +35 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/base.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/file.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/_types.rb +60 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/details.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/image.rb +37 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/refusal.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/content/text.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/developer.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/function.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/system.rb +25 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/tool.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/messages/user.rb +32 -0
- data/lib/active_agent/providers/open_ai/chat/requests/prediction.rb +46 -0
- data/lib/active_agent/providers/open_ai/chat/requests/response_format.rb +53 -0
- data/lib/active_agent/providers/open_ai/chat/requests/stream_options.rb +24 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/_types.rb +5 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/custom_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/chat/requests/tools/function_tool.rb +51 -0
- data/lib/active_agent/providers/open_ai/chat/requests/web_search_options.rb +45 -0
- data/lib/active_agent/providers/open_ai/chat_provider.rb +198 -0
- data/lib/active_agent/providers/open_ai/embedding/_types.rb +45 -0
- data/lib/active_agent/providers/open_ai/embedding/request.rb +85 -0
- data/lib/active_agent/providers/open_ai/embedding/requests/_types.rb +49 -0
- data/lib/active_agent/providers/open_ai/options.rb +74 -0
- data/lib/active_agent/providers/open_ai/responses/_types.rb +50 -0
- data/lib/active_agent/providers/open_ai/responses/request.rb +163 -0
- data/lib/active_agent/providers/open_ai/responses/requests/_types.rb +231 -0
- data/lib/active_agent/providers/open_ai/responses/requests/conversation.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/_types.rb +264 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/assistant_message.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/base.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/code_interpreter_tool_call.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/_types.rb +207 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_audio.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_file.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_image.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_text.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call_output.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/developer_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/file_search_tool_call.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_call_output.rb +32 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_tool_call.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/image_gen_tool_call.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/input_message.rb +31 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/item_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call_output.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_request.rb +30 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_response.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_list_tools.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_tool_call.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/output_message.rb +35 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/reasoning.rb +33 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/system_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_call_base.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_message.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/user_message.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/inputs/web_search_tool_call.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/prompt_reference.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/reasoning.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/stream_options.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/_types.rb +89 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/base.rb +22 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_object.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/json_schema.rb +48 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text/plain.rb +20 -0
- data/lib/active_agent/providers/open_ai/responses/requests/text.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tool_choice.rb +26 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/_types.rb +112 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/base.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/code_interpreter_tool.rb +23 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/computer_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/custom_tool.rb +28 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/file_search_tool.rb +27 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/function_tool.rb +29 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/image_generation_tool.rb +37 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/local_shell_tool.rb +21 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/mcp_tool.rb +41 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_preview_tool.rb +24 -0
- data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_tool.rb +25 -0
- data/lib/active_agent/providers/open_ai/responses_provider.rb +153 -0
- data/lib/active_agent/providers/open_ai/schema.yml +65937 -0
- data/lib/active_agent/providers/open_ai_provider.rb +97 -0
- data/lib/active_agent/providers/open_router/_types.rb +45 -0
- data/lib/active_agent/providers/open_router/options.rb +93 -0
- data/lib/active_agent/providers/open_router/request.rb +83 -0
- data/lib/active_agent/providers/open_router/requests/_types.rb +198 -0
- data/lib/active_agent/providers/open_router/requests/message.rb +1 -0
- data/lib/active_agent/providers/open_router/requests/messages/_types.rb +59 -0
- data/lib/active_agent/providers/open_router/requests/messages/assistant.rb +20 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/_types.rb +97 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/file.rb +27 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/_types.rb +61 -0
- data/lib/active_agent/providers/open_router/requests/messages/content/files/details.rb +26 -0
- data/lib/active_agent/providers/open_router/requests/messages/user.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/plugin.rb +25 -0
- data/lib/active_agent/providers/open_router/requests/plugins/_types.rb +46 -0
- data/lib/active_agent/providers/open_router/requests/plugins/pdf_config.rb +29 -0
- data/lib/active_agent/providers/open_router/requests/prediction.rb +17 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/_types.rb +44 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences/max_price.rb +30 -0
- data/lib/active_agent/providers/open_router/requests/provider_preferences.rb +64 -0
- data/lib/active_agent/providers/open_router/requests/response_format.rb +49 -0
- data/lib/active_agent/providers/open_router_provider.rb +53 -0
- data/lib/active_agent/providers/openai_provider.rb +2 -0
- data/lib/active_agent/providers/openrouter_provider.rb +2 -0
- data/lib/active_agent/railtie.rb +8 -6
- data/lib/active_agent/schema_generator.rb +333 -166
- data/lib/active_agent/version.rb +1 -1
- data/lib/active_agent.rb +112 -36
- data/lib/generators/active_agent/agent/USAGE +78 -0
- data/lib/generators/active_agent/{agent_generator.rb → agent/agent_generator.rb} +14 -4
- data/lib/generators/active_agent/install/USAGE +25 -0
- data/lib/generators/active_agent/{install_generator.rb → install/install_generator.rb} +1 -19
- data/lib/generators/active_agent/templates/agent.rb.tt +7 -3
- data/lib/generators/active_agent/templates/application_agent.rb.tt +0 -2
- data/lib/generators/erb/agent_generator.rb +31 -16
- data/lib/generators/erb/templates/instructions.md.erb.tt +3 -0
- data/lib/generators/erb/templates/instructions.md.tt +3 -0
- data/lib/generators/erb/templates/instructions.text.tt +1 -0
- data/lib/generators/erb/templates/message.md.erb.tt +5 -0
- data/lib/generators/erb/templates/schema.json.tt +10 -0
- data/lib/generators/test_unit/agent_generator.rb +1 -1
- data/lib/generators/test_unit/templates/functional_test.rb.tt +4 -2
- metadata +320 -65
- data/lib/active_agent/action_prompt/action.rb +0 -13
- data/lib/active_agent/action_prompt/base.rb +0 -623
- data/lib/active_agent/action_prompt/message.rb +0 -126
- data/lib/active_agent/action_prompt/prompt.rb +0 -136
- data/lib/active_agent/action_prompt.rb +0 -19
- data/lib/active_agent/callbacks.rb +0 -33
- data/lib/active_agent/generation_provider/anthropic_provider.rb +0 -163
- data/lib/active_agent/generation_provider/base.rb +0 -55
- data/lib/active_agent/generation_provider/base_adapter.rb +0 -19
- data/lib/active_agent/generation_provider/error_handling.rb +0 -167
- data/lib/active_agent/generation_provider/log_subscriber.rb +0 -92
- data/lib/active_agent/generation_provider/message_formatting.rb +0 -107
- data/lib/active_agent/generation_provider/ollama_provider.rb +0 -66
- data/lib/active_agent/generation_provider/open_ai_provider.rb +0 -279
- data/lib/active_agent/generation_provider/open_router_provider.rb +0 -385
- data/lib/active_agent/generation_provider/parameter_builder.rb +0 -119
- data/lib/active_agent/generation_provider/response.rb +0 -75
- data/lib/active_agent/generation_provider/responses_adapter.rb +0 -44
- data/lib/active_agent/generation_provider/stream_processing.rb +0 -58
- data/lib/active_agent/generation_provider/tool_management.rb +0 -142
- data/lib/active_agent/generation_provider.rb +0 -67
- data/lib/active_agent/log_subscriber.rb +0 -44
- data/lib/active_agent/parameterized.rb +0 -75
- data/lib/active_agent/prompt_helper.rb +0 -19
- data/lib/active_agent/queued_generation.rb +0 -12
- data/lib/active_agent/rescuable.rb +0 -34
- data/lib/active_agent/sanitizers.rb +0 -40
- data/lib/active_agent/streaming.rb +0 -34
- data/lib/active_agent/test_case.rb +0 -125
- data/lib/generators/USAGE +0 -47
- data/lib/generators/active_agent/USAGE +0 -56
- data/lib/generators/erb/install_generator.rb +0 -44
- data/lib/generators/erb/templates/layout.html.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.json.erb.tt +0 -1
- data/lib/generators/erb/templates/layout.text.erb.tt +0 -1
- data/lib/generators/erb/templates/view.html.erb.tt +0 -5
- data/lib/generators/erb/templates/view.json.erb.tt +0 -16
- /data/lib/active_agent/{preview.rb → concerns/preview.rb} +0 -0
- /data/lib/generators/erb/templates/{view.text.erb.tt → message.text.erb.tt} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
require_relative "sources/_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module Anthropic
|
|
9
|
+
module Requests
|
|
10
|
+
module Content
|
|
11
|
+
# Base class for all content items
|
|
12
|
+
class Base < Common::BaseModel
|
|
13
|
+
attribute :type, :string
|
|
14
|
+
|
|
15
|
+
validates :type, presence: true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "sources/_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module Anthropic
|
|
9
|
+
module Requests
|
|
10
|
+
module Content
|
|
11
|
+
# Document content block
|
|
12
|
+
class Document < Base
|
|
13
|
+
attribute :type, :string, as: "document"
|
|
14
|
+
attribute :source, Sources::SourceType.new # Can be base64, text, url, or file
|
|
15
|
+
attribute :title, :string # Optional title
|
|
16
|
+
attribute :context, :string # Optional context
|
|
17
|
+
attribute :citations # Optional citations config
|
|
18
|
+
attribute :cache_control # Optional cache control
|
|
19
|
+
|
|
20
|
+
validates :source, presence: true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "sources/_types"
|
|
5
|
+
|
|
6
|
+
module ActiveAgent
|
|
7
|
+
module Providers
|
|
8
|
+
module Anthropic
|
|
9
|
+
module Requests
|
|
10
|
+
module Content
|
|
11
|
+
# Image content block
|
|
12
|
+
class Image < Base
|
|
13
|
+
attribute :type, :string, as: "image"
|
|
14
|
+
attribute :source, Sources::SourceType.new # Can be base64, url, or file
|
|
15
|
+
attribute :cache_control # Optional cache control
|
|
16
|
+
|
|
17
|
+
validates :source, presence: true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Redacted thinking content block
|
|
11
|
+
class RedactedThinking < Base
|
|
12
|
+
attribute :type, :string, as: "redacted_thinking"
|
|
13
|
+
attribute :data, :string
|
|
14
|
+
|
|
15
|
+
validates :data, presence: true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Search result content block
|
|
11
|
+
class SearchResult < Base
|
|
12
|
+
attribute :type, :string, as: "search_result"
|
|
13
|
+
attribute :source, :string
|
|
14
|
+
attribute :title, :string
|
|
15
|
+
attribute :content # Array of text blocks
|
|
16
|
+
attribute :citations # Optional citations config
|
|
17
|
+
attribute :cache_control # Optional cache control
|
|
18
|
+
|
|
19
|
+
validates :source, presence: true
|
|
20
|
+
validates :title, presence: true
|
|
21
|
+
validates :content, presence: true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
require_relative "document_base64"
|
|
5
|
+
require_relative "document_file"
|
|
6
|
+
require_relative "document_text"
|
|
7
|
+
require_relative "document_url"
|
|
8
|
+
require_relative "image_base64"
|
|
9
|
+
require_relative "image_file"
|
|
10
|
+
require_relative "image_url"
|
|
11
|
+
|
|
12
|
+
module ActiveAgent
|
|
13
|
+
module Providers
|
|
14
|
+
module Anthropic
|
|
15
|
+
module Requests
|
|
16
|
+
module Content
|
|
17
|
+
module Sources
|
|
18
|
+
# Type for source objects (image/document sources)
|
|
19
|
+
class SourceType < ActiveModel::Type::Value
|
|
20
|
+
def cast(value)
|
|
21
|
+
case value
|
|
22
|
+
when Base
|
|
23
|
+
# Already a Source object, return as-is
|
|
24
|
+
value
|
|
25
|
+
when Hash
|
|
26
|
+
hash = value.deep_symbolize_keys
|
|
27
|
+
type = hash[:type]&.to_sym
|
|
28
|
+
|
|
29
|
+
case type
|
|
30
|
+
when :base64
|
|
31
|
+
# Determine if it's image or document based on media_type or context
|
|
32
|
+
media_type = hash[:media_type]&.to_s
|
|
33
|
+
if media_type&.start_with?("image/")
|
|
34
|
+
ImageBase64.new(**hash)
|
|
35
|
+
else
|
|
36
|
+
DocumentBase64.new(**hash)
|
|
37
|
+
end
|
|
38
|
+
when :url
|
|
39
|
+
# Could be either - default to image for now
|
|
40
|
+
# Callers can be more specific by passing the right class
|
|
41
|
+
ImageURL.new(**hash)
|
|
42
|
+
when :file
|
|
43
|
+
# Could be either - default to image for now
|
|
44
|
+
ImageFile.new(**hash)
|
|
45
|
+
when :text
|
|
46
|
+
DocumentText.new(**hash)
|
|
47
|
+
when nil
|
|
48
|
+
# No type specified - try to infer
|
|
49
|
+
infer_source_from_hash(hash)
|
|
50
|
+
else
|
|
51
|
+
raise ArgumentError, "Unknown source type: #{type}"
|
|
52
|
+
end
|
|
53
|
+
when nil
|
|
54
|
+
nil
|
|
55
|
+
else
|
|
56
|
+
raise ArgumentError, "Cannot cast #{value.class} to Source"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def serialize(value)
|
|
61
|
+
case value
|
|
62
|
+
when Base
|
|
63
|
+
value.serialize
|
|
64
|
+
when Hash
|
|
65
|
+
value
|
|
66
|
+
when nil
|
|
67
|
+
nil
|
|
68
|
+
else
|
|
69
|
+
raise ArgumentError, "Cannot serialize #{value.class}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def deserialize(value)
|
|
74
|
+
cast(value)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def infer_source_from_hash(hash)
|
|
80
|
+
if hash.key?(:image)
|
|
81
|
+
# Handle image key - detect URI or base64 data URI
|
|
82
|
+
cast_image_source(hash[:image], hash)
|
|
83
|
+
elsif hash.key?(:document)
|
|
84
|
+
# Handle document key - detect URI or base64 data URI
|
|
85
|
+
cast_document_source(hash[:document], hash)
|
|
86
|
+
elsif hash.key?(:data) && hash.key?(:media_type)
|
|
87
|
+
media_type = hash[:media_type]&.to_s
|
|
88
|
+
if media_type&.start_with?("image/")
|
|
89
|
+
ImageBase64.new(**hash.merge(type: "base64"))
|
|
90
|
+
else
|
|
91
|
+
DocumentBase64.new(**hash.merge(type: "base64"))
|
|
92
|
+
end
|
|
93
|
+
elsif hash.key?(:url)
|
|
94
|
+
ImageURL.new(**hash.merge(type: "url"))
|
|
95
|
+
elsif hash.key?(:file_id)
|
|
96
|
+
ImageFile.new(**hash.merge(type: "file"))
|
|
97
|
+
elsif hash.key?(:text)
|
|
98
|
+
DocumentText.new(**hash.merge(type: "text"))
|
|
99
|
+
else
|
|
100
|
+
raise ArgumentError, "Cannot cast hash without type to Source: #{hash.inspect}"
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def cast_image_source(image_value, original_hash)
|
|
105
|
+
case image_value
|
|
106
|
+
when String
|
|
107
|
+
if uri?(image_value)
|
|
108
|
+
# It's a URI/URL
|
|
109
|
+
ImageURL.new(type: "url", url: image_value)
|
|
110
|
+
elsif data_uri?(image_value)
|
|
111
|
+
# It's a data URI (e.g., data:image/jpeg;base64,...)
|
|
112
|
+
media_type, data = parse_data_uri(image_value)
|
|
113
|
+
ImageBase64.new(type: "base64", media_type: media_type, data: data)
|
|
114
|
+
else
|
|
115
|
+
raise ArgumentError, "Cannot determine source type for image value: #{image_value.inspect}"
|
|
116
|
+
end
|
|
117
|
+
else
|
|
118
|
+
raise ArgumentError, "Expected String for image key, got #{image_value.class}"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def cast_document_source(file_value, original_hash)
|
|
123
|
+
case file_value
|
|
124
|
+
when String
|
|
125
|
+
if uri?(file_value)
|
|
126
|
+
# It's a URI/URL
|
|
127
|
+
DocumentURL.new(type: "url", url: file_value)
|
|
128
|
+
elsif data_uri?(file_value)
|
|
129
|
+
# It's a data URI (e.g., data:application/pdf;base64,...)
|
|
130
|
+
media_type, data = parse_data_uri(file_value)
|
|
131
|
+
DocumentBase64.new(type: "base64", media_type: media_type, data: data)
|
|
132
|
+
else
|
|
133
|
+
raise ArgumentError, "Cannot determine source type for file value: #{file_value.inspect}"
|
|
134
|
+
end
|
|
135
|
+
else
|
|
136
|
+
raise ArgumentError, "Expected String for file key, got #{file_value.class}"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def uri?(value)
|
|
141
|
+
# Check if it looks like a URI (http://, https://, etc.)
|
|
142
|
+
value.match?(%r{\A(https?)://}i)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def data_uri?(value)
|
|
146
|
+
# Check if it's a data URI (data:...)
|
|
147
|
+
value.match?(/\Adata:/i)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def parse_data_uri(data_uri)
|
|
151
|
+
# Parse data URI format: data:mime/type;base64,encoded_data
|
|
152
|
+
match = data_uri.match(/\Adata:([^;,]+)(;base64)?,(.+)\z/i)
|
|
153
|
+
raise ArgumentError, "Invalid data URI format: #{data_uri[0..50]}..." unless match
|
|
154
|
+
|
|
155
|
+
media_type = match[1]
|
|
156
|
+
is_base64 = !match[2].nil?
|
|
157
|
+
data = match[3]
|
|
158
|
+
|
|
159
|
+
unless is_base64
|
|
160
|
+
raise ArgumentError, "Only base64-encoded data URIs are supported: #{data_uri[0..50]}..."
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
[ media_type, data ]
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# Base class for all content sources
|
|
12
|
+
class Base < Common::BaseModel
|
|
13
|
+
attribute :type, :string
|
|
14
|
+
|
|
15
|
+
validates :type, presence: true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# Base64-encoded document source
|
|
12
|
+
class DocumentBase64 < Base
|
|
13
|
+
attribute :type, :string, as: "base64"
|
|
14
|
+
attribute :media_type, :string
|
|
15
|
+
attribute :data, :string
|
|
16
|
+
|
|
17
|
+
validates :media_type, presence: true
|
|
18
|
+
validates :data, presence: true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# File-based document source
|
|
12
|
+
class DocumentFile < Base
|
|
13
|
+
attribute :type, :string, as: "file"
|
|
14
|
+
attribute :file_id, :string
|
|
15
|
+
|
|
16
|
+
validates :file_id, presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# Text document source
|
|
12
|
+
class DocumentText < Base
|
|
13
|
+
attribute :type, :string, as: "text"
|
|
14
|
+
attribute :text, :string
|
|
15
|
+
attribute :media_type, :string
|
|
16
|
+
|
|
17
|
+
validates :text, presence: true
|
|
18
|
+
validates :media_type, presence: true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# URL-based document source
|
|
12
|
+
class DocumentURL < Base
|
|
13
|
+
attribute :type, :string, as: "url"
|
|
14
|
+
attribute :url, :string
|
|
15
|
+
|
|
16
|
+
validates :url, presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# Base64-encoded image source
|
|
12
|
+
class ImageBase64 < Base
|
|
13
|
+
attribute :type, :string, as: "base64"
|
|
14
|
+
attribute :media_type, :string
|
|
15
|
+
attribute :data, :string
|
|
16
|
+
|
|
17
|
+
validates :media_type, presence: true, inclusion: {
|
|
18
|
+
in: %w[image/jpeg image/png image/gif image/webp]
|
|
19
|
+
}
|
|
20
|
+
validates :data, presence: true
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# File-based image source
|
|
12
|
+
class ImageFile < Base
|
|
13
|
+
attribute :type, :string, as: "file"
|
|
14
|
+
attribute :file_id, :string
|
|
15
|
+
|
|
16
|
+
validates :file_id, presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
module Sources
|
|
11
|
+
# URL-based image source
|
|
12
|
+
class ImageURL < Base
|
|
13
|
+
attribute :type, :string, as: "url"
|
|
14
|
+
attribute :url, :string
|
|
15
|
+
|
|
16
|
+
validates :url, presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Text content block
|
|
11
|
+
class Text < Base
|
|
12
|
+
attribute :type, :string, as: "text"
|
|
13
|
+
attribute :text, :string
|
|
14
|
+
attribute :cache_control # Optional cache control
|
|
15
|
+
|
|
16
|
+
validates :text, presence: true
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Thinking content block
|
|
11
|
+
class Thinking < Base
|
|
12
|
+
attribute :type, :string, as: "thinking"
|
|
13
|
+
attribute :thinking, :string
|
|
14
|
+
attribute :signature, :string
|
|
15
|
+
|
|
16
|
+
validates :thinking, presence: true
|
|
17
|
+
validates :signature, presence: true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Tool result content block
|
|
11
|
+
class ToolResult < Base
|
|
12
|
+
attribute :type, :string, as: "tool_result"
|
|
13
|
+
attribute :tool_use_id, :string
|
|
14
|
+
attribute :content # String or array of content blocks
|
|
15
|
+
attribute :is_error, :boolean
|
|
16
|
+
attribute :cache_control # Optional cache control
|
|
17
|
+
|
|
18
|
+
validates :tool_use_id, presence: true, format: { with: /\A[a-zA-Z0-9_-]+\z/ }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "base"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
module Content
|
|
10
|
+
# Tool use content block
|
|
11
|
+
class ToolUse < Base
|
|
12
|
+
attribute :type, :string, as: "tool_use"
|
|
13
|
+
attribute :id, :string
|
|
14
|
+
attribute :name, :string
|
|
15
|
+
attribute :input # Object containing tool input
|
|
16
|
+
attribute :cache_control # Optional cache control
|
|
17
|
+
|
|
18
|
+
validates :id, presence: true, format: { with: /\A[a-zA-Z0-9_-]+\z/ }
|
|
19
|
+
validates :name, presence: true, length: { minimum: 1, maximum: 200 }
|
|
20
|
+
validates :input, presence: true
|
|
21
|
+
|
|
22
|
+
drop_attributes :json_buf
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveAgent
|
|
4
|
+
module Providers
|
|
5
|
+
module Anthropic
|
|
6
|
+
module Requests
|
|
7
|
+
module Messages
|
|
8
|
+
# User message - messages sent by the user
|
|
9
|
+
class User < Base
|
|
10
|
+
attribute :role, :string, as: "user"
|
|
11
|
+
|
|
12
|
+
# Content can be:
|
|
13
|
+
# - A string (shorthand for single text block)
|
|
14
|
+
# - An array of content blocks (text, image, document, etc.)
|
|
15
|
+
validates :content, presence: true
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
# Metadata about the request
|
|
10
|
+
class Metadata < Common::BaseModel
|
|
11
|
+
attribute :user_id, :string
|
|
12
|
+
|
|
13
|
+
validates :user_id, length: { maximum: 256 }, allow_nil: true
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_agent/providers/common/model"
|
|
4
|
+
|
|
5
|
+
module ActiveAgent
|
|
6
|
+
module Providers
|
|
7
|
+
module Anthropic
|
|
8
|
+
module Requests
|
|
9
|
+
# Configures the response format for Anthropic API requests.
|
|
10
|
+
#
|
|
11
|
+
# Anthropic does not natively support response formats. This class emulates
|
|
12
|
+
# the feature using a lead-in assistant message and response parsing.
|
|
13
|
+
class ResponseFormat < Common::BaseModel
|
|
14
|
+
# @return [String] format type: "text" or "json_object"
|
|
15
|
+
attribute :type, :string, default: "text"
|
|
16
|
+
|
|
17
|
+
validates :type, inclusion: { in: %w[text json_object] }, allow_nil: true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|