|
21 | 21 | * <pre>{@code |
22 | 22 | * session.on(event -> { |
23 | 23 | * if (event instanceof AssistantMessageEvent msg) { |
24 | | - * String content = msg.getData().getContent(); |
| 24 | + * String content = msg.getData().content(); |
25 | 25 | * System.out.println("Assistant: " + content); |
26 | 26 | * } |
27 | 27 | * }); |
@@ -70,233 +70,25 @@ public void setData(AssistantMessageData data) { |
70 | 70 | * Contains the assistant message content and metadata. |
71 | 71 | */ |
72 | 72 | @JsonIgnoreProperties(ignoreUnknown = true) |
73 | | - public static class AssistantMessageData { |
74 | | - |
75 | | - @JsonProperty("messageId") |
76 | | - private String messageId; |
77 | | - |
78 | | - @JsonProperty("content") |
79 | | - private String content; |
80 | | - |
81 | | - @JsonProperty("toolRequests") |
82 | | - private List<ToolRequest> toolRequests; |
83 | | - |
84 | | - @JsonProperty("parentToolCallId") |
85 | | - private String parentToolCallId; |
86 | | - |
87 | | - @JsonProperty("reasoningOpaque") |
88 | | - private String reasoningOpaque; |
89 | | - |
90 | | - @JsonProperty("reasoningText") |
91 | | - private String reasoningText; |
92 | | - |
93 | | - @JsonProperty("encryptedContent") |
94 | | - private String encryptedContent; |
95 | | - |
96 | | - /** |
97 | | - * Gets the unique message identifier. |
98 | | - * |
99 | | - * @return the message ID |
100 | | - */ |
101 | | - public String getMessageId() { |
102 | | - return messageId; |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Sets the message identifier. |
107 | | - * |
108 | | - * @param messageId |
109 | | - * the message ID |
110 | | - */ |
111 | | - public void setMessageId(String messageId) { |
112 | | - this.messageId = messageId; |
113 | | - } |
114 | | - |
115 | | - /** |
116 | | - * Gets the text content of the assistant's message. |
117 | | - * |
118 | | - * @return the message content |
119 | | - */ |
120 | | - public String getContent() { |
121 | | - return content; |
122 | | - } |
123 | | - |
124 | | - /** |
125 | | - * Sets the message content. |
126 | | - * |
127 | | - * @param content |
128 | | - * the message content |
129 | | - */ |
130 | | - public void setContent(String content) { |
131 | | - this.content = content; |
132 | | - } |
133 | | - |
134 | | - /** |
135 | | - * Gets the list of tool requests made by the assistant. |
136 | | - * |
137 | | - * @return the tool requests, or {@code null} if none |
138 | | - */ |
139 | | - public List<ToolRequest> getToolRequests() { |
| 73 | + public record AssistantMessageData(@JsonProperty("messageId") String messageId, |
| 74 | + @JsonProperty("content") String content, @JsonProperty("toolRequests") List<ToolRequest> toolRequests, |
| 75 | + @JsonProperty("parentToolCallId") String parentToolCallId, |
| 76 | + @JsonProperty("reasoningOpaque") String reasoningOpaque, |
| 77 | + @JsonProperty("reasoningText") String reasoningText, |
| 78 | + @JsonProperty("encryptedContent") String encryptedContent) { |
| 79 | + |
| 80 | + /** Returns a defensive copy of the tool requests list. */ |
| 81 | + @Override |
| 82 | + public List<ToolRequest> toolRequests() { |
140 | 83 | return toolRequests == null ? null : Collections.unmodifiableList(toolRequests); |
141 | 84 | } |
142 | 85 |
|
143 | | - /** |
144 | | - * Sets the tool requests. |
145 | | - * |
146 | | - * @param toolRequests |
147 | | - * the tool requests |
148 | | - */ |
149 | | - public void setToolRequests(List<ToolRequest> toolRequests) { |
150 | | - this.toolRequests = toolRequests; |
151 | | - } |
152 | | - |
153 | | - /** |
154 | | - * Gets the parent tool call ID if this message is in response to a tool. |
155 | | - * |
156 | | - * @return the parent tool call ID, or {@code null} |
157 | | - */ |
158 | | - public String getParentToolCallId() { |
159 | | - return parentToolCallId; |
160 | | - } |
161 | | - |
162 | | - /** |
163 | | - * Sets the parent tool call ID. |
164 | | - * |
165 | | - * @param parentToolCallId |
166 | | - * the parent tool call ID |
167 | | - */ |
168 | | - public void setParentToolCallId(String parentToolCallId) { |
169 | | - this.parentToolCallId = parentToolCallId; |
170 | | - } |
171 | | - |
172 | | - /** |
173 | | - * Gets the opaque reasoning content (encrypted/encoded). |
174 | | - * |
175 | | - * @return the opaque reasoning content, or {@code null} |
176 | | - */ |
177 | | - public String getReasoningOpaque() { |
178 | | - return reasoningOpaque; |
179 | | - } |
180 | | - |
181 | | - /** |
182 | | - * Sets the opaque reasoning content. |
183 | | - * |
184 | | - * @param reasoningOpaque |
185 | | - * the opaque reasoning content |
186 | | - */ |
187 | | - public void setReasoningOpaque(String reasoningOpaque) { |
188 | | - this.reasoningOpaque = reasoningOpaque; |
189 | | - } |
190 | | - |
191 | | - /** |
192 | | - * Gets the human-readable reasoning text. |
193 | | - * |
194 | | - * @return the reasoning text, or {@code null} |
195 | | - */ |
196 | | - public String getReasoningText() { |
197 | | - return reasoningText; |
198 | | - } |
199 | | - |
200 | | - /** |
201 | | - * Sets the reasoning text. |
202 | | - * |
203 | | - * @param reasoningText |
204 | | - * the reasoning text |
205 | | - */ |
206 | | - public void setReasoningText(String reasoningText) { |
207 | | - this.reasoningText = reasoningText; |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Gets the encrypted content. |
212 | | - * |
213 | | - * @return the encrypted content, or {@code null} |
214 | | - */ |
215 | | - public String getEncryptedContent() { |
216 | | - return encryptedContent; |
217 | | - } |
218 | | - |
219 | | - /** |
220 | | - * Sets the encrypted content. |
221 | | - * |
222 | | - * @param encryptedContent |
223 | | - * the encrypted content |
224 | | - */ |
225 | | - public void setEncryptedContent(String encryptedContent) { |
226 | | - this.encryptedContent = encryptedContent; |
227 | | - } |
228 | | - |
229 | 86 | /** |
230 | 87 | * Represents a request from the assistant to invoke a tool. |
231 | 88 | */ |
232 | 89 | @JsonIgnoreProperties(ignoreUnknown = true) |
233 | | - public static class ToolRequest { |
234 | | - |
235 | | - @JsonProperty("toolCallId") |
236 | | - private String toolCallId; |
237 | | - |
238 | | - @JsonProperty("name") |
239 | | - private String name; |
240 | | - |
241 | | - @JsonProperty("arguments") |
242 | | - private Object arguments; |
243 | | - |
244 | | - /** |
245 | | - * Gets the unique tool call identifier. |
246 | | - * |
247 | | - * @return the tool call ID |
248 | | - */ |
249 | | - public String getToolCallId() { |
250 | | - return toolCallId; |
251 | | - } |
252 | | - |
253 | | - /** |
254 | | - * Sets the tool call identifier. |
255 | | - * |
256 | | - * @param toolCallId |
257 | | - * the tool call ID |
258 | | - */ |
259 | | - public void setToolCallId(String toolCallId) { |
260 | | - this.toolCallId = toolCallId; |
261 | | - } |
262 | | - |
263 | | - /** |
264 | | - * Gets the name of the tool to invoke. |
265 | | - * |
266 | | - * @return the tool name |
267 | | - */ |
268 | | - public String getName() { |
269 | | - return name; |
270 | | - } |
271 | | - |
272 | | - /** |
273 | | - * Sets the tool name. |
274 | | - * |
275 | | - * @param name |
276 | | - * the tool name |
277 | | - */ |
278 | | - public void setName(String name) { |
279 | | - this.name = name; |
280 | | - } |
281 | | - |
282 | | - /** |
283 | | - * Gets the arguments to pass to the tool. |
284 | | - * |
285 | | - * @return the tool arguments (typically a Map or JsonNode) |
286 | | - */ |
287 | | - public Object getArguments() { |
288 | | - return arguments; |
289 | | - } |
290 | | - |
291 | | - /** |
292 | | - * Sets the tool arguments. |
293 | | - * |
294 | | - * @param arguments |
295 | | - * the tool arguments |
296 | | - */ |
297 | | - public void setArguments(Object arguments) { |
298 | | - this.arguments = arguments; |
299 | | - } |
| 90 | + public record ToolRequest(@JsonProperty("toolCallId") String toolCallId, @JsonProperty("name") String name, |
| 91 | + @JsonProperty("arguments") Object arguments) { |
300 | 92 | } |
301 | 93 | } |
302 | 94 | } |
0 commit comments