activeagent 1.0.0.rc1 → 1.0.0

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.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -1
  3. data/lib/active_agent/providers/_base_provider.rb +92 -82
  4. data/lib/active_agent/providers/anthropic/_types.rb +2 -2
  5. data/lib/active_agent/providers/anthropic/request.rb +135 -81
  6. data/lib/active_agent/providers/anthropic/transforms.rb +353 -0
  7. data/lib/active_agent/providers/anthropic_provider.rb +96 -53
  8. data/lib/active_agent/providers/common/messages/_types.rb +37 -1
  9. data/lib/active_agent/providers/common/responses/base.rb +118 -70
  10. data/lib/active_agent/providers/common/usage.rb +385 -0
  11. data/lib/active_agent/providers/concerns/instrumentation.rb +263 -0
  12. data/lib/active_agent/providers/log_subscriber.rb +64 -246
  13. data/lib/active_agent/providers/mock_provider.rb +23 -23
  14. data/lib/active_agent/providers/ollama/chat/request.rb +214 -35
  15. data/lib/active_agent/providers/ollama/chat/transforms.rb +135 -0
  16. data/lib/active_agent/providers/ollama/embedding/request.rb +160 -47
  17. data/lib/active_agent/providers/ollama/embedding/transforms.rb +160 -0
  18. data/lib/active_agent/providers/ollama_provider.rb +0 -1
  19. data/lib/active_agent/providers/open_ai/_base.rb +3 -2
  20. data/lib/active_agent/providers/open_ai/chat/_types.rb +13 -1
  21. data/lib/active_agent/providers/open_ai/chat/request.rb +132 -186
  22. data/lib/active_agent/providers/open_ai/chat/transforms.rb +364 -0
  23. data/lib/active_agent/providers/open_ai/chat_provider.rb +57 -36
  24. data/lib/active_agent/providers/open_ai/embedding/_types.rb +13 -2
  25. data/lib/active_agent/providers/open_ai/embedding/request.rb +38 -70
  26. data/lib/active_agent/providers/open_ai/embedding/transforms.rb +88 -0
  27. data/lib/active_agent/providers/open_ai/responses/_types.rb +1 -7
  28. data/lib/active_agent/providers/open_ai/responses/request.rb +100 -134
  29. data/lib/active_agent/providers/open_ai/responses/transforms.rb +228 -0
  30. data/lib/active_agent/providers/open_ai/responses_provider.rb +77 -30
  31. data/lib/active_agent/providers/open_ai_provider.rb +0 -3
  32. data/lib/active_agent/providers/open_router/_types.rb +27 -1
  33. data/lib/active_agent/providers/open_router/options.rb +49 -1
  34. data/lib/active_agent/providers/open_router/request.rb +232 -66
  35. data/lib/active_agent/providers/open_router/requests/_types.rb +0 -1
  36. data/lib/active_agent/providers/open_router/requests/messages/_types.rb +37 -40
  37. data/lib/active_agent/providers/open_router/requests/messages/content/file.rb +19 -3
  38. data/lib/active_agent/providers/open_router/requests/messages/content/files/details.rb +15 -4
  39. data/lib/active_agent/providers/open_router/requests/plugin.rb +19 -3
  40. data/lib/active_agent/providers/open_router/requests/plugins/pdf_config.rb +30 -8
  41. data/lib/active_agent/providers/open_router/requests/prediction.rb +17 -0
  42. data/lib/active_agent/providers/open_router/requests/provider_preferences/max_price.rb +41 -7
  43. data/lib/active_agent/providers/open_router/requests/provider_preferences.rb +60 -19
  44. data/lib/active_agent/providers/open_router/requests/response_format.rb +30 -2
  45. data/lib/active_agent/providers/open_router/transforms.rb +134 -0
  46. data/lib/active_agent/providers/open_router_provider.rb +9 -0
  47. data/lib/active_agent/version.rb +1 -1
  48. metadata +15 -159
  49. data/lib/active_agent/generation_provider/open_router/types.rb +0 -505
  50. data/lib/active_agent/generation_provider/xai_provider.rb +0 -144
  51. data/lib/active_agent/providers/anthropic/requests/_types.rb +0 -190
  52. data/lib/active_agent/providers/anthropic/requests/container_params.rb +0 -19
  53. data/lib/active_agent/providers/anthropic/requests/content/base.rb +0 -21
  54. data/lib/active_agent/providers/anthropic/requests/content/sources/base.rb +0 -22
  55. data/lib/active_agent/providers/anthropic/requests/context_management_config.rb +0 -18
  56. data/lib/active_agent/providers/anthropic/requests/messages/_types.rb +0 -189
  57. data/lib/active_agent/providers/anthropic/requests/messages/assistant.rb +0 -23
  58. data/lib/active_agent/providers/anthropic/requests/messages/base.rb +0 -63
  59. data/lib/active_agent/providers/anthropic/requests/messages/content/_types.rb +0 -143
  60. data/lib/active_agent/providers/anthropic/requests/messages/content/base.rb +0 -21
  61. data/lib/active_agent/providers/anthropic/requests/messages/content/document.rb +0 -26
  62. data/lib/active_agent/providers/anthropic/requests/messages/content/image.rb +0 -23
  63. data/lib/active_agent/providers/anthropic/requests/messages/content/redacted_thinking.rb +0 -21
  64. data/lib/active_agent/providers/anthropic/requests/messages/content/search_result.rb +0 -27
  65. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/_types.rb +0 -171
  66. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/base.rb +0 -22
  67. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_base64.rb +0 -25
  68. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_file.rb +0 -23
  69. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_text.rb +0 -25
  70. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/document_url.rb +0 -23
  71. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_base64.rb +0 -27
  72. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_file.rb +0 -23
  73. data/lib/active_agent/providers/anthropic/requests/messages/content/sources/image_url.rb +0 -23
  74. data/lib/active_agent/providers/anthropic/requests/messages/content/text.rb +0 -22
  75. data/lib/active_agent/providers/anthropic/requests/messages/content/thinking.rb +0 -23
  76. data/lib/active_agent/providers/anthropic/requests/messages/content/tool_result.rb +0 -24
  77. data/lib/active_agent/providers/anthropic/requests/messages/content/tool_use.rb +0 -28
  78. data/lib/active_agent/providers/anthropic/requests/messages/user.rb +0 -21
  79. data/lib/active_agent/providers/anthropic/requests/metadata.rb +0 -18
  80. data/lib/active_agent/providers/anthropic/requests/response_format.rb +0 -22
  81. data/lib/active_agent/providers/anthropic/requests/thinking_config/_types.rb +0 -60
  82. data/lib/active_agent/providers/anthropic/requests/thinking_config/base.rb +0 -20
  83. data/lib/active_agent/providers/anthropic/requests/thinking_config/disabled.rb +0 -16
  84. data/lib/active_agent/providers/anthropic/requests/thinking_config/enabled.rb +0 -20
  85. data/lib/active_agent/providers/anthropic/requests/tool_choice/_types.rb +0 -78
  86. data/lib/active_agent/providers/anthropic/requests/tool_choice/any.rb +0 -17
  87. data/lib/active_agent/providers/anthropic/requests/tool_choice/auto.rb +0 -17
  88. data/lib/active_agent/providers/anthropic/requests/tool_choice/base.rb +0 -20
  89. data/lib/active_agent/providers/anthropic/requests/tool_choice/none.rb +0 -16
  90. data/lib/active_agent/providers/anthropic/requests/tool_choice/tool.rb +0 -20
  91. data/lib/active_agent/providers/ollama/chat/requests/_types.rb +0 -3
  92. data/lib/active_agent/providers/ollama/chat/requests/messages/_types.rb +0 -116
  93. data/lib/active_agent/providers/ollama/chat/requests/messages/assistant.rb +0 -19
  94. data/lib/active_agent/providers/ollama/chat/requests/messages/user.rb +0 -19
  95. data/lib/active_agent/providers/ollama/embedding/requests/_types.rb +0 -83
  96. data/lib/active_agent/providers/ollama/embedding/requests/options.rb +0 -104
  97. data/lib/active_agent/providers/open_ai/chat/requests/_types.rb +0 -229
  98. data/lib/active_agent/providers/open_ai/chat/requests/audio.rb +0 -24
  99. data/lib/active_agent/providers/open_ai/chat/requests/messages/_types.rb +0 -123
  100. data/lib/active_agent/providers/open_ai/chat/requests/messages/assistant.rb +0 -42
  101. data/lib/active_agent/providers/open_ai/chat/requests/messages/base.rb +0 -78
  102. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/_types.rb +0 -133
  103. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/audio.rb +0 -35
  104. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/base.rb +0 -24
  105. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/file.rb +0 -26
  106. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/_types.rb +0 -60
  107. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/files/details.rb +0 -41
  108. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/image.rb +0 -37
  109. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/refusal.rb +0 -25
  110. data/lib/active_agent/providers/open_ai/chat/requests/messages/content/text.rb +0 -25
  111. data/lib/active_agent/providers/open_ai/chat/requests/messages/developer.rb +0 -25
  112. data/lib/active_agent/providers/open_ai/chat/requests/messages/function.rb +0 -25
  113. data/lib/active_agent/providers/open_ai/chat/requests/messages/system.rb +0 -25
  114. data/lib/active_agent/providers/open_ai/chat/requests/messages/tool.rb +0 -26
  115. data/lib/active_agent/providers/open_ai/chat/requests/messages/user.rb +0 -32
  116. data/lib/active_agent/providers/open_ai/chat/requests/prediction.rb +0 -46
  117. data/lib/active_agent/providers/open_ai/chat/requests/response_format.rb +0 -53
  118. data/lib/active_agent/providers/open_ai/chat/requests/stream_options.rb +0 -24
  119. data/lib/active_agent/providers/open_ai/chat/requests/tool_choice.rb +0 -26
  120. data/lib/active_agent/providers/open_ai/chat/requests/tools/_types.rb +0 -5
  121. data/lib/active_agent/providers/open_ai/chat/requests/tools/base.rb +0 -22
  122. data/lib/active_agent/providers/open_ai/chat/requests/tools/custom_tool.rb +0 -41
  123. data/lib/active_agent/providers/open_ai/chat/requests/tools/function_tool.rb +0 -51
  124. data/lib/active_agent/providers/open_ai/chat/requests/web_search_options.rb +0 -45
  125. data/lib/active_agent/providers/open_ai/embedding/requests/_types.rb +0 -49
  126. data/lib/active_agent/providers/open_ai/responses/requests/_types.rb +0 -231
  127. data/lib/active_agent/providers/open_ai/responses/requests/conversation.rb +0 -23
  128. data/lib/active_agent/providers/open_ai/responses/requests/inputs/_types.rb +0 -264
  129. data/lib/active_agent/providers/open_ai/responses/requests/inputs/assistant_message.rb +0 -22
  130. data/lib/active_agent/providers/open_ai/responses/requests/inputs/base.rb +0 -89
  131. data/lib/active_agent/providers/open_ai/responses/requests/inputs/code_interpreter_tool_call.rb +0 -30
  132. data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call.rb +0 -28
  133. data/lib/active_agent/providers/open_ai/responses/requests/inputs/computer_tool_call_output.rb +0 -33
  134. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/_types.rb +0 -207
  135. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/base.rb +0 -22
  136. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_audio.rb +0 -26
  137. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_file.rb +0 -28
  138. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_image.rb +0 -28
  139. data/lib/active_agent/providers/open_ai/responses/requests/inputs/content/input_text.rb +0 -25
  140. data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call.rb +0 -28
  141. data/lib/active_agent/providers/open_ai/responses/requests/inputs/custom_tool_call_output.rb +0 -27
  142. data/lib/active_agent/providers/open_ai/responses/requests/inputs/developer_message.rb +0 -20
  143. data/lib/active_agent/providers/open_ai/responses/requests/inputs/file_search_tool_call.rb +0 -25
  144. data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_call_output.rb +0 -32
  145. data/lib/active_agent/providers/open_ai/responses/requests/inputs/function_tool_call.rb +0 -28
  146. data/lib/active_agent/providers/open_ai/responses/requests/inputs/image_gen_tool_call.rb +0 -27
  147. data/lib/active_agent/providers/open_ai/responses/requests/inputs/input_message.rb +0 -31
  148. data/lib/active_agent/providers/open_ai/responses/requests/inputs/item_reference.rb +0 -23
  149. data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call.rb +0 -26
  150. data/lib/active_agent/providers/open_ai/responses/requests/inputs/local_shell_tool_call_output.rb +0 -33
  151. data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_request.rb +0 -30
  152. data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_approval_response.rb +0 -28
  153. data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_list_tools.rb +0 -29
  154. data/lib/active_agent/providers/open_ai/responses/requests/inputs/mcp_tool_call.rb +0 -35
  155. data/lib/active_agent/providers/open_ai/responses/requests/inputs/output_message.rb +0 -35
  156. data/lib/active_agent/providers/open_ai/responses/requests/inputs/reasoning.rb +0 -33
  157. data/lib/active_agent/providers/open_ai/responses/requests/inputs/system_message.rb +0 -20
  158. data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_call_base.rb +0 -27
  159. data/lib/active_agent/providers/open_ai/responses/requests/inputs/tool_message.rb +0 -23
  160. data/lib/active_agent/providers/open_ai/responses/requests/inputs/user_message.rb +0 -20
  161. data/lib/active_agent/providers/open_ai/responses/requests/inputs/web_search_tool_call.rb +0 -24
  162. data/lib/active_agent/providers/open_ai/responses/requests/prompt_reference.rb +0 -23
  163. data/lib/active_agent/providers/open_ai/responses/requests/reasoning.rb +0 -23
  164. data/lib/active_agent/providers/open_ai/responses/requests/stream_options.rb +0 -20
  165. data/lib/active_agent/providers/open_ai/responses/requests/text/_types.rb +0 -89
  166. data/lib/active_agent/providers/open_ai/responses/requests/text/base.rb +0 -22
  167. data/lib/active_agent/providers/open_ai/responses/requests/text/json_object.rb +0 -20
  168. data/lib/active_agent/providers/open_ai/responses/requests/text/json_schema.rb +0 -48
  169. data/lib/active_agent/providers/open_ai/responses/requests/text/plain.rb +0 -20
  170. data/lib/active_agent/providers/open_ai/responses/requests/text.rb +0 -41
  171. data/lib/active_agent/providers/open_ai/responses/requests/tool_choice.rb +0 -26
  172. data/lib/active_agent/providers/open_ai/responses/requests/tools/_types.rb +0 -112
  173. data/lib/active_agent/providers/open_ai/responses/requests/tools/base.rb +0 -25
  174. data/lib/active_agent/providers/open_ai/responses/requests/tools/code_interpreter_tool.rb +0 -23
  175. data/lib/active_agent/providers/open_ai/responses/requests/tools/computer_tool.rb +0 -27
  176. data/lib/active_agent/providers/open_ai/responses/requests/tools/custom_tool.rb +0 -28
  177. data/lib/active_agent/providers/open_ai/responses/requests/tools/file_search_tool.rb +0 -27
  178. data/lib/active_agent/providers/open_ai/responses/requests/tools/function_tool.rb +0 -29
  179. data/lib/active_agent/providers/open_ai/responses/requests/tools/image_generation_tool.rb +0 -37
  180. data/lib/active_agent/providers/open_ai/responses/requests/tools/local_shell_tool.rb +0 -21
  181. data/lib/active_agent/providers/open_ai/responses/requests/tools/mcp_tool.rb +0 -41
  182. data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_preview_tool.rb +0 -24
  183. data/lib/active_agent/providers/open_ai/responses/requests/tools/web_search_tool.rb +0 -25
  184. data/lib/active_agent/providers/open_ai/schema.yml +0 -65937
  185. data/lib/active_agent/providers/open_router/requests/message.rb +0 -1
  186. data/lib/active_agent/providers/open_router/requests/messages/assistant.rb +0 -20
  187. data/lib/active_agent/providers/open_router/requests/messages/user.rb +0 -30
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveAgent
4
- module Providers
5
- module OpenAI
6
- module Embedding
7
- module Requests
8
- # Custom type for handling embedding input
9
- # Can be a string, array of strings, or array of token arrays
10
- # Always stores internally as an array for consistency
11
- class InputType < ActiveModel::Type::Value
12
- def cast(value)
13
- case value
14
- when String
15
- [ value.presence ].compact
16
- when Array
17
- value.compact
18
- when nil
19
- nil
20
- else
21
- raise ArgumentError, "Cannot cast #{value.class} to Input (expected String or Array)"
22
- end
23
- end
24
-
25
- def serialize(value)
26
- case value
27
- when Array
28
- # Return single string if array has only one string element
29
- if value in [ String => string ]
30
- string
31
- else
32
- value
33
- end
34
- when nil
35
- nil
36
- else
37
- raise ArgumentError, "Cannot serialize #{value.class}"
38
- end
39
- end
40
-
41
- def deserialize(value)
42
- cast(value)
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,231 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "inputs/_types"
4
- require_relative "tools/_types"
5
-
6
- require_relative "conversation"
7
- require_relative "prompt_reference"
8
- require_relative "reasoning"
9
- require_relative "stream_options"
10
- require_relative "text"
11
- require_relative "tool_choice"
12
-
13
- module ActiveAgent
14
- module Providers
15
- module OpenAI
16
- module Responses
17
- module Requests
18
- class ConversationType < ActiveModel::Type::Value
19
- def cast(value)
20
- case value
21
- when Conversation
22
- value
23
- when Hash
24
- Conversation.new(**value.symbolize_keys)
25
- when String
26
- value # Can be a conversation ID string
27
- when nil
28
- nil
29
- else
30
- raise ArgumentError, "Cannot cast #{value.class} to Conversation"
31
- end
32
- end
33
-
34
- def serialize(value)
35
- case value
36
- when Conversation
37
- value.serialize
38
- when Hash
39
- value
40
- when String
41
- value
42
- when nil
43
- nil
44
- else
45
- raise ArgumentError, "Cannot serialize #{value.class}"
46
- end
47
- end
48
-
49
- def deserialize(value)
50
- cast(value)
51
- end
52
- end
53
-
54
- class PromptReferenceType < ActiveModel::Type::Value
55
- def cast(value)
56
- case value
57
- when PromptReference
58
- value
59
- when Hash
60
- PromptReference.new(**value.symbolize_keys)
61
- when nil
62
- nil
63
- else
64
- raise ArgumentError, "Cannot cast #{value.class} to PromptReference"
65
- end
66
- end
67
-
68
- def serialize(value)
69
- case value
70
- when PromptReference
71
- value.serialize
72
- when Hash
73
- value
74
- when nil
75
- nil
76
- else
77
- raise ArgumentError, "Cannot serialize #{value.class}"
78
- end
79
- end
80
-
81
- def deserialize(value)
82
- cast(value)
83
- end
84
- end
85
-
86
- class ReasoningType < ActiveModel::Type::Value
87
- def cast(value)
88
- case value
89
- when Reasoning
90
- value
91
- when Hash
92
- Reasoning.new(**value.symbolize_keys)
93
- when nil
94
- nil
95
- else
96
- raise ArgumentError, "Cannot cast #{value.class} to Reasoning"
97
- end
98
- end
99
-
100
- def serialize(value)
101
- case value
102
- when Reasoning
103
- value.serialize
104
- when Hash
105
- value
106
- when nil
107
- nil
108
- else
109
- raise ArgumentError, "Cannot serialize #{value.class}"
110
- end
111
- end
112
-
113
- def deserialize(value)
114
- cast(value)
115
- end
116
- end
117
-
118
- class StreamOptionsType < ActiveModel::Type::Value
119
- def cast(value)
120
- case value
121
- when StreamOptions
122
- value
123
- when Hash
124
- StreamOptions.new(**value.symbolize_keys)
125
- when nil
126
- nil
127
- else
128
- raise ArgumentError, "Cannot cast #{value.class} to StreamOptions"
129
- end
130
- end
131
-
132
- def serialize(value)
133
- case value
134
- when StreamOptions
135
- value.serialize
136
- when Hash
137
- value
138
- when nil
139
- nil
140
- else
141
- raise ArgumentError, "Cannot serialize #{value.class}"
142
- end
143
- end
144
-
145
- def deserialize(value)
146
- cast(value)
147
- end
148
- end
149
-
150
- class TextType < ActiveModel::Type::Value
151
- def cast(value)
152
- case value
153
- when Text
154
- value
155
- when Hash
156
- if value.key?(:json_schema)
157
- Text.new(**value.symbolize_keys.except(:type)) # Prevent Losing the Schema on Format setting
158
- else
159
- Text.new(**value.symbolize_keys)
160
- end
161
- when nil
162
- nil
163
- else
164
- raise ArgumentError, "Cannot cast #{value.class} to Text"
165
- end
166
- end
167
-
168
- def serialize(value)
169
- case value
170
- when Text
171
- value.serialize
172
- when Hash
173
- value
174
- when nil
175
- nil
176
- else
177
- raise ArgumentError, "Cannot serialize #{value.class}"
178
- end
179
- end
180
-
181
- def deserialize(value)
182
- cast(value)
183
- end
184
- end
185
-
186
- class ToolChoiceType < ActiveModel::Type::Value
187
- def cast(value)
188
- case value
189
- when ToolChoice
190
- value
191
- when Hash
192
- ToolChoice.new(**value.symbolize_keys)
193
- when String
194
- ToolChoice.new(mode: value)
195
- when nil
196
- nil
197
- else
198
- raise ArgumentError, "Cannot cast #{value.class} to ToolChoice"
199
- end
200
- end
201
-
202
- def serialize(value)
203
- case value
204
- when ToolChoice
205
- hash = value.serialize
206
- # If it's just a mode string, return the string
207
- if hash[:mode].present? && hash[:type].blank? && hash[:function].blank? && hash[:custom].blank?
208
- hash[:mode]
209
- else
210
- hash
211
- end
212
- when Hash
213
- value
214
- when String
215
- value
216
- when nil
217
- nil
218
- else
219
- raise ArgumentError, "Cannot serialize #{value.class}"
220
- end
221
- end
222
-
223
- def deserialize(value)
224
- cast(value)
225
- end
226
- end
227
- end
228
- end
229
- end
230
- end
231
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_agent/providers/common/model"
4
-
5
- module ActiveAgent
6
- module Providers
7
- module OpenAI
8
- module Responses
9
- module Requests
10
- class Conversation < Common::BaseModel
11
- # Conversation ID
12
- attribute :id, :string
13
-
14
- # Optional: Store conversation items
15
- attribute :store, :boolean
16
-
17
- validates :id, presence: true, if: -> { store.nil? }
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,264 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "content/_types"
4
-
5
- require_relative "base"
6
- require_relative "tool_call_base"
7
- require_relative "input_message"
8
- require_relative "output_message"
9
- require_relative "user_message"
10
- require_relative "system_message"
11
- require_relative "developer_message"
12
- require_relative "assistant_message"
13
- require_relative "tool_message"
14
- require_relative "function_call_output"
15
- require_relative "item_reference"
16
- require_relative "reasoning"
17
-
18
- # Tool call types
19
- require_relative "file_search_tool_call"
20
- require_relative "computer_tool_call"
21
- require_relative "computer_tool_call_output"
22
- require_relative "web_search_tool_call"
23
- require_relative "function_tool_call"
24
- require_relative "image_gen_tool_call"
25
- require_relative "code_interpreter_tool_call"
26
- require_relative "local_shell_tool_call"
27
- require_relative "local_shell_tool_call_output"
28
- require_relative "custom_tool_call"
29
- require_relative "custom_tool_call_output"
30
-
31
- # MCP types
32
- require_relative "mcp_list_tools"
33
- require_relative "mcp_approval_request"
34
- require_relative "mcp_approval_response"
35
- require_relative "mcp_tool_call"
36
-
37
- module ActiveAgent
38
- module Providers
39
- module OpenAI
40
- module Responses
41
- module Requests
42
- module Inputs
43
- # Type for handling items (array of items - full Item types)
44
- class ItemsType < ActiveModel::Type::Value
45
- def initialize
46
- super
47
- @item_type = ItemType.new
48
- end
49
-
50
- def cast(value)
51
- case value
52
- when String
53
- # Plain text string becomes array with single user message
54
- [ UserMessage.new(text: value) ]
55
- when Array
56
- value.map { |item| @item_type.cast(item) }
57
- when Hash
58
- # Single hash becomes array with one item
59
- [ @item_type.cast(value) ]
60
- when nil
61
- nil
62
- else
63
- raise ArgumentError, "Cannot cast #{value.class} to Items (expected String, Array, Hash, or nil)"
64
- end
65
- end
66
-
67
- def serialize(value)
68
- case value
69
- when String
70
- value
71
- when Array
72
- value.map { |v| @item_type.serialize(v) }
73
- when Hash
74
- @item_type.serialize(value)
75
- when nil
76
- nil
77
- else
78
- raise ArgumentError, "Cannot serialize #{value.class}"
79
- end
80
- end
81
-
82
- def deserialize(value)
83
- cast(value)
84
- end
85
- end
86
-
87
- # Type for handling individual items (messages, tool calls, reasoning, etc.)
88
- class ItemType < ActiveModel::Type::Value
89
- def initialize
90
- super
91
- @content_type = Content::ContentType.new
92
- end
93
-
94
- def cast(value)
95
- case value
96
- when ::OpenAI::Internal::Type::BaseModel
97
- cast(value.to_h)
98
- when Base
99
- value
100
- when String
101
- # Plain text string becomes user message
102
- UserMessage.new(text: value)
103
- when Hash
104
- hash = value.deep_symbolize_keys
105
- type = hash[:type]&.to_sym
106
-
107
- case type
108
- # Message types
109
- when :message, nil
110
- cast_message(hash)
111
- # Tool call types
112
- when :file_search_call
113
- FileSearchToolCall.new(**hash)
114
- when :computer_call
115
- ComputerToolCall.new(**hash)
116
- when :computer_call_output
117
- ComputerToolCallOutput.new(**hash)
118
- when :web_search_call
119
- WebSearchToolCall.new(**hash)
120
- when :function_call
121
- FunctionToolCall.new(**hash)
122
- when :function_call_output
123
- FunctionCallOutput.new(**hash)
124
- when :image_generation_call
125
- ImageGenToolCall.new(**hash)
126
- when :code_interpreter_call
127
- CodeInterpreterToolCall.new(**hash)
128
- when :local_shell_call
129
- LocalShellToolCall.new(**hash)
130
- when :local_shell_call_output
131
- LocalShellToolCallOutput.new(**hash)
132
- when :custom_tool_call
133
- CustomToolCall.new(**hash)
134
- when :custom_tool_call_output
135
- CustomToolCallOutput.new(**hash)
136
- # MCP types
137
- when :mcp_list_tools
138
- MCPListTools.new(**hash)
139
- when :mcp_approval_request
140
- MCPApprovalRequest.new(**hash)
141
- when :mcp_approval_response
142
- MCPApprovalResponse.new(**hash)
143
- when :mcp_call
144
- MCPToolCall.new(**hash)
145
- # Other types
146
- when :reasoning
147
- Reasoning.new(**hash)
148
- when :item_reference
149
- ItemReference.new(**hash)
150
- else
151
- raise ArgumentError, "Unknown item type: #{type.inspect}"
152
- end
153
- when nil
154
- nil
155
- else
156
- raise ArgumentError, "Cannot cast #{value.class} to Item (expected Base, Hash, String, or nil)"
157
- end
158
- end
159
-
160
- def serialize(value)
161
- case value
162
- when Base
163
- hash = value.serialize
164
-
165
- if hash[:content] in [ { type: "input_text", text: String } ]
166
- hash[:content] = hash[:content].first[:text]
167
- end
168
-
169
- hash
170
- when Hash
171
- value
172
- when nil
173
- nil
174
- else
175
- raise ArgumentError, "Cannot serialize #{value.class} as Item"
176
- end
177
- end
178
-
179
- def deserialize(value)
180
- cast(value)
181
- end
182
-
183
- private
184
-
185
- def cast_message(hash)
186
- role = hash[:role]&.to_sym
187
-
188
- case role
189
- when :system
190
- SystemMessage.new(**hash)
191
- when :developer
192
- DeveloperMessage.new(**hash)
193
- when :user, nil
194
- UserMessage.new(**hash)
195
- when :assistant
196
- AssistantMessage.new(**hash)
197
- when :tool
198
- ToolMessage.new(**hash)
199
- else
200
- raise ArgumentError, "Unknown message role: #{role.inspect}"
201
- end
202
- end
203
- end
204
-
205
- # Type for handling messages (array of messages) - kept for backwards compatibility
206
- class MessagesType < ActiveModel::Type::Value
207
- def initialize
208
- super
209
- @item_type = ItemType.new
210
- end
211
-
212
- def cast(value)
213
- case value
214
- when String
215
- value
216
- when Array
217
- value.map { |item| @item_type.cast(item) }
218
- when Hash
219
- # Single hash becomes array with one message
220
- [ @item_type.cast(value) ]
221
- when nil
222
- nil
223
- else
224
- raise ArgumentError, "Cannot cast #{value.class} to Input (expected String, Array, or Hash)"
225
- end
226
- end
227
-
228
- def serialize(value)
229
- case value
230
- when String
231
- value
232
- when Array
233
- grouped = []
234
-
235
- value.each do |message|
236
- if grouped.empty?
237
- grouped << message.deep_dup
238
- elsif grouped.last.role == message.role && grouped.last.type == message.type
239
- grouped.last.content += message.content.deep_dup
240
- else
241
- grouped << message.deep_dup
242
- end
243
- end
244
-
245
- grouped.map { |v| @item_type.serialize(v) }
246
- when Hash
247
- @item_type.serialize(value)
248
- when nil
249
- nil
250
- else
251
- raise ArgumentError, "Cannot serialize #{value.class}"
252
- end
253
- end
254
-
255
- def deserialize(value)
256
- cast(value)
257
- end
258
- end
259
- end
260
- end
261
- end
262
- end
263
- end
264
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "output_message"
4
-
5
- module ActiveAgent
6
- module Providers
7
- module OpenAI
8
- module Responses
9
- module Requests
10
- module Inputs
11
- # Assistant message output for OpenAI Responses API.
12
- #
13
- # Represents an assistant message in the conversation history.
14
- class AssistantMessage < OutputMessage
15
- attribute :role, :string, as: "assistant"
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,89 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "active_agent/providers/common/model"
4
- require_relative "content/_types"
5
-
6
- module ActiveAgent
7
- module Providers
8
- module OpenAI
9
- module Responses
10
- module Requests
11
- module Inputs
12
- # Base class for input items in Responses API
13
- class Base < Common::BaseModel
14
- attribute :role, :string
15
- attribute :content, Content::ContentsType.new
16
-
17
- validates :role, inclusion: {
18
- in: %w[system user assistant developer tool],
19
- allow_nil: true
20
- }
21
-
22
- # Define content setter methods for different content types
23
- %i[text image document].each do |content_type|
24
- define_method(:"#{content_type}=") do |value|
25
- self.content ||= []
26
- self.content += [ { content_type => value } ]
27
- end
28
- end
29
-
30
- # Converts to common format.
31
- #
32
- # @return [Hash] message in canonical format
33
- def to_common
34
- {
35
- role: map_role_to_common,
36
- content: extract_text_content,
37
- name: respond_to?(:name) ? name : nil,
38
- tool_call_id: respond_to?(:tool_call_id) ? tool_call_id : nil
39
- }.compact
40
- end
41
-
42
- private
43
-
44
- # Maps OpenAI roles to canonical roles.
45
- #
46
- # @return [String] canonical role name
47
- def map_role_to_common
48
- case role
49
- when "developer", "system"
50
- "system"
51
- when "user"
52
- "user"
53
- when "assistant"
54
- "assistant"
55
- when "tool", "function"
56
- "tool"
57
- else
58
- role
59
- end
60
- end
61
-
62
- # Extracts text content from OpenAI's content structure.
63
- #
64
- # @return [String, nil] extracted text content
65
- def extract_text_content
66
- return nil unless respond_to?(:content)
67
-
68
- case content
69
- when String
70
- content
71
- when Array
72
- # For Responses API, content is an array of content objects (InputText, etc.)
73
- content.select { |part| part.respond_to?(:text) }
74
- .map(&:text)
75
- .compact
76
- .join("\n")
77
- when nil
78
- nil
79
- else
80
- content.to_s
81
- end
82
- end
83
- end
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "tool_call_base"
4
-
5
- module ActiveAgent
6
- module Providers
7
- module OpenAI
8
- module Responses
9
- module Requests
10
- module Inputs
11
- # Code interpreter tool call - runs Python code
12
- class CodeInterpreterToolCall < ToolCallBase
13
- attribute :type, :string, as: "code_interpreter_call"
14
- attribute :container_id, :string
15
- attribute :code, :string # Can be null
16
- attribute :outputs # Always an array of output objects, can be empty
17
-
18
- validates :type, inclusion: { in: %w[code_interpreter_call], allow_nil: false }
19
- validates :container_id, presence: true
20
- validates :status, inclusion: {
21
- in: %w[in_progress completed incomplete interpreting failed],
22
- allow_nil: false
23
- }
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end