Skip to content

Commit 16ff788

Browse files
authored
Merge pull request #117 from copilot-community-sdk/feat/records-for-data-types
Refactor data types to use records
2 parents 48c18a2 + b9c714f commit 16ff788

27 files changed

Lines changed: 282 additions & 1284 deletions

src/main/java/com/github/copilot/sdk/CopilotClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* var session = client.createSession(new SessionConfig().setModel("gpt-5")).get();
4949
*
5050
* session.on(AssistantMessageEvent.class, msg -> {
51-
* System.out.println(msg.getData().getContent());
51+
* System.out.println(msg.getData().content());
5252
* });
5353
*
5454
* session.send(new MessageOptions().setPrompt("Hello!")).get();

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
*
6464
* // Register type-safe event handlers
6565
* session.on(AssistantMessageEvent.class, msg -> {
66-
* System.out.println(msg.getData().getContent());
66+
* System.out.println(msg.getData().content());
6767
* });
6868
* session.on(SessionIdleEvent.class, idle -> {
6969
* System.out.println("Session is idle");
@@ -453,7 +453,7 @@ public Closeable on(Consumer<AbstractSessionEvent> handler) {
453453
* <pre>{@code
454454
* // Handle assistant messages
455455
* session.on(AssistantMessageEvent.class, msg -> {
456-
* System.out.println(msg.getData().getContent());
456+
* System.out.println(msg.getData().content());
457457
* });
458458
*
459459
* // Handle session idle

src/main/java/com/github/copilot/sdk/events/AbstractSessionEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* <pre>{@code
3838
* session.on(event -> {
3939
* if (event instanceof AssistantMessageEvent msg) {
40-
* System.out.println("Assistant: " + msg.getData().getContent());
40+
* System.out.println("Assistant: " + msg.getData().content());
4141
* } else if (event instanceof SessionIdleEvent) {
4242
* System.out.println("Session is idle");
4343
* }

src/main/java/com/github/copilot/sdk/events/AssistantMessageEvent.java

Lines changed: 13 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* <pre>{@code
2222
* session.on(event -> {
2323
* if (event instanceof AssistantMessageEvent msg) {
24-
* String content = msg.getData().getContent();
24+
* String content = msg.getData().content();
2525
* System.out.println("Assistant: " + content);
2626
* }
2727
* });
@@ -70,233 +70,25 @@ public void setData(AssistantMessageData data) {
7070
* Contains the assistant message content and metadata.
7171
*/
7272
@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() {
14083
return toolRequests == null ? null : Collections.unmodifiableList(toolRequests);
14184
}
14285

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-
22986
/**
23087
* Represents a request from the assistant to invoke a tool.
23188
*/
23289
@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) {
30092
}
30193
}
30294
}

0 commit comments

Comments
 (0)