This repository was archived by the owner on Mar 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAbstractSessionEvent.java
More file actions
176 lines (159 loc) · 5.56 KB
/
AbstractSessionEvent.java
File metadata and controls
176 lines (159 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
package com.github.copilot.sdk.events;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.OffsetDateTime;
import java.util.UUID;
/**
* Base class for all session events in the Copilot SDK.
* <p>
* Session events represent all activities that occur during a Copilot
* conversation, including messages from the user and assistant, tool
* executions, and session state changes. Events are delivered to handlers
* registered via
* {@link com.github.copilot.sdk.CopilotSession#on(java.util.function.Consumer)}.
*
* <h2>Event Categories</h2>
* <ul>
* <li><strong>Session events</strong>: {@link SessionStartEvent},
* {@link SessionResumeEvent}, {@link SessionErrorEvent},
* {@link SessionIdleEvent}, etc.</li>
* <li><strong>Assistant events</strong>: {@link AssistantMessageEvent},
* {@link AssistantMessageDeltaEvent}, {@link AssistantTurnStartEvent},
* etc.</li>
* <li><strong>Tool events</strong>: {@link ToolExecutionStartEvent},
* {@link ToolExecutionCompleteEvent}, etc.</li>
* <li><strong>User events</strong>: {@link UserMessageEvent}</li>
* </ul>
*
* <h2>Example Usage</h2>
*
* <pre>{@code
* session.on(event -> {
* if (event instanceof AssistantMessageEvent msg) {
* System.out.println("Assistant: " + msg.getData().content());
* } else if (event instanceof SessionIdleEvent) {
* System.out.println("Session is idle");
* }
* });
* }</pre>
*
* @see com.github.copilot.sdk.CopilotSession#on(java.util.function.Consumer)
* @see SessionEventParser
* @since 1.0.0
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract sealed class AbstractSessionEvent permits
// Session events
SessionStartEvent, SessionResumeEvent, SessionErrorEvent, SessionIdleEvent, SessionInfoEvent,
SessionModelChangeEvent, SessionModeChangedEvent, SessionPlanChangedEvent, SessionWorkspaceFileChangedEvent,
SessionHandoffEvent, SessionTruncationEvent, SessionSnapshotRewindEvent, SessionUsageInfoEvent,
SessionCompactionStartEvent, SessionCompactionCompleteEvent, SessionShutdownEvent, SessionContextChangedEvent,
SessionTaskCompleteEvent,
// Assistant events
AssistantTurnStartEvent, AssistantIntentEvent, AssistantReasoningEvent, AssistantReasoningDeltaEvent,
AssistantMessageEvent, AssistantMessageDeltaEvent, AssistantStreamingDeltaEvent, AssistantTurnEndEvent,
AssistantUsageEvent, AbortEvent,
// Tool events
ToolUserRequestedEvent, ToolExecutionStartEvent, ToolExecutionPartialResultEvent, ToolExecutionProgressEvent,
ToolExecutionCompleteEvent,
// User events
UserMessageEvent, PendingMessagesModifiedEvent,
// Skill events
SkillInvokedEvent,
// Other events
SubagentStartedEvent, SubagentCompletedEvent, SubagentFailedEvent, SubagentSelectedEvent,
SubagentDeselectedEvent, HookStartEvent, HookEndEvent, SystemMessageEvent, SystemNotificationEvent,
// Protocol v3 broadcast events
ExternalToolRequestedEvent, ExternalToolCompletedEvent, PermissionRequestedEvent, CommandQueuedEvent,
CommandCompletedEvent, ExitPlanModeRequestedEvent, ExitPlanModeCompletedEvent {
@JsonProperty("id")
private UUID id;
@JsonProperty("timestamp")
private OffsetDateTime timestamp;
@JsonProperty("parentId")
private UUID parentId;
@JsonProperty("ephemeral")
private Boolean ephemeral;
/**
* Gets the event type discriminator string.
* <p>
* This corresponds to the event type in the JSON protocol (e.g.,
* "assistant.message", "session.idle").
*
* @return the event type string
*/
public abstract String getType();
/**
* Gets the unique identifier for this event.
*
* @return the event UUID
*/
public UUID getId() {
return id;
}
/**
* Sets the event identifier.
*
* @param id
* the event UUID
*/
public void setId(UUID id) {
this.id = id;
}
/**
* Gets the timestamp when this event occurred.
*
* @return the event timestamp
*/
public OffsetDateTime getTimestamp() {
return timestamp;
}
/**
* Sets the event timestamp.
*
* @param timestamp
* the event timestamp
*/
public void setTimestamp(OffsetDateTime timestamp) {
this.timestamp = timestamp;
}
/**
* Gets the parent event ID, if this event is a child of another.
*
* @return the parent event UUID, or {@code null}
*/
public UUID getParentId() {
return parentId;
}
/**
* Sets the parent event ID.
*
* @param parentId
* the parent event UUID
*/
public void setParentId(UUID parentId) {
this.parentId = parentId;
}
/**
* Returns whether this is an ephemeral event.
* <p>
* Ephemeral events are not persisted in session history.
*
* @return {@code true} if ephemeral, {@code false} otherwise
*/
public Boolean getEphemeral() {
return ephemeral;
}
/**
* Sets whether this is an ephemeral event.
*
* @param ephemeral
* {@code true} if ephemeral
*/
public void setEphemeral(Boolean ephemeral) {
this.ephemeral = ephemeral;
}
}