forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_events.go
More file actions
353 lines (323 loc) · 14.2 KB
/
Copy pathsession_events.go
File metadata and controls
353 lines (323 loc) · 14.2 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// AUTO-GENERATED FILE - DO NOT EDIT
//
// Generated from: @github/copilot/session-events.schema.json
// Generated by: scripts/generate-session-types.ts
// Generated at: 2026-01-13T00:08:21.118Z
//
// To update these types:
// 1. Update the schema in copilot-agent-runtime
// 2. Run: npm run generate:session-types
// Code generated from JSON Schema using quicktype. DO NOT EDIT.
// To parse and unparse this JSON data, add this code to your project and do:
//
// sessionEvent, err := UnmarshalSessionEvent(bytes)
// bytes, err = sessionEvent.Marshal()
package generated
import "bytes"
import "errors"
import "time"
import "encoding/json"
func UnmarshalSessionEvent(data []byte) (SessionEvent, error) {
var r SessionEvent
err := json.Unmarshal(data, &r)
return r, err
}
func (r *SessionEvent) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type SessionEvent struct {
Data Data `json:"data"`
Ephemeral *bool `json:"ephemeral,omitempty"`
ID string `json:"id"`
ParentID *string `json:"parentId"`
Timestamp time.Time `json:"timestamp"`
Type SessionEventType `json:"type"`
}
type Data struct {
CopilotVersion *string `json:"copilotVersion,omitempty"`
Producer *string `json:"producer,omitempty"`
SelectedModel *string `json:"selectedModel,omitempty"`
SessionID *string `json:"sessionId,omitempty"`
StartTime *time.Time `json:"startTime,omitempty"`
Version *float64 `json:"version,omitempty"`
EventCount *float64 `json:"eventCount,omitempty"`
ResumeTime *time.Time `json:"resumeTime,omitempty"`
ErrorType *string `json:"errorType,omitempty"`
Message *string `json:"message,omitempty"`
Stack *string `json:"stack,omitempty"`
InfoType *string `json:"infoType,omitempty"`
NewModel *string `json:"newModel,omitempty"`
PreviousModel *string `json:"previousModel,omitempty"`
Context *string `json:"context,omitempty"`
HandoffTime *time.Time `json:"handoffTime,omitempty"`
RemoteSessionID *string `json:"remoteSessionId,omitempty"`
Repository *Repository `json:"repository,omitempty"`
SourceType *SourceType `json:"sourceType,omitempty"`
Summary *string `json:"summary,omitempty"`
MessagesRemovedDuringTruncation *float64 `json:"messagesRemovedDuringTruncation,omitempty"`
PerformedBy *string `json:"performedBy,omitempty"`
PostTruncationMessagesLength *float64 `json:"postTruncationMessagesLength,omitempty"`
PostTruncationTokensInMessages *float64 `json:"postTruncationTokensInMessages,omitempty"`
PreTruncationMessagesLength *float64 `json:"preTruncationMessagesLength,omitempty"`
PreTruncationTokensInMessages *float64 `json:"preTruncationTokensInMessages,omitempty"`
TokenLimit *float64 `json:"tokenLimit,omitempty"`
TokensRemovedDuringTruncation *float64 `json:"tokensRemovedDuringTruncation,omitempty"`
Attachments []Attachment `json:"attachments,omitempty"`
Content *string `json:"content,omitempty"`
Source *string `json:"source,omitempty"`
TransformedContent *string `json:"transformedContent,omitempty"`
TurnID *string `json:"turnId,omitempty"`
Intent *string `json:"intent,omitempty"`
ChunkContent *string `json:"chunkContent,omitempty"`
ReasoningID *string `json:"reasoningId,omitempty"`
DeltaContent *string `json:"deltaContent,omitempty"`
MessageID *string `json:"messageId,omitempty"`
ParentToolCallID *string `json:"parentToolCallId,omitempty"`
ToolRequests []ToolRequest `json:"toolRequests,omitempty"`
TotalResponseSizeBytes *float64 `json:"totalResponseSizeBytes,omitempty"`
APICallID *string `json:"apiCallId,omitempty"`
CacheReadTokens *float64 `json:"cacheReadTokens,omitempty"`
CacheWriteTokens *float64 `json:"cacheWriteTokens,omitempty"`
Cost *float64 `json:"cost,omitempty"`
Duration *float64 `json:"duration,omitempty"`
Initiator *string `json:"initiator,omitempty"`
InputTokens *float64 `json:"inputTokens,omitempty"`
Model *string `json:"model,omitempty"`
OutputTokens *float64 `json:"outputTokens,omitempty"`
ProviderCallID *string `json:"providerCallId,omitempty"`
QuotaSnapshots map[string]QuotaSnapshot `json:"quotaSnapshots,omitempty"`
Reason *string `json:"reason,omitempty"`
Arguments interface{} `json:"arguments"`
ToolCallID *string `json:"toolCallId,omitempty"`
ToolName *string `json:"toolName,omitempty"`
PartialOutput *string `json:"partialOutput,omitempty"`
Error *ErrorUnion `json:"error"`
IsUserRequested *bool `json:"isUserRequested,omitempty"`
Result *Result `json:"result,omitempty"`
Success *bool `json:"success,omitempty"`
ToolTelemetry map[string]interface{} `json:"toolTelemetry,omitempty"`
AgentDescription *string `json:"agentDescription,omitempty"`
AgentDisplayName *string `json:"agentDisplayName,omitempty"`
AgentName *string `json:"agentName,omitempty"`
Tools []string `json:"tools"`
HookInvocationID *string `json:"hookInvocationId,omitempty"`
HookType *string `json:"hookType,omitempty"`
Input interface{} `json:"input"`
Output interface{} `json:"output"`
Metadata *Metadata `json:"metadata,omitempty"`
Name *string `json:"name,omitempty"`
Role *Role `json:"role,omitempty"`
}
type Attachment struct {
DisplayName string `json:"displayName"`
Path string `json:"path"`
Type AttachmentType `json:"type"`
}
type ErrorClass struct {
Code *string `json:"code,omitempty"`
Message string `json:"message"`
Stack *string `json:"stack,omitempty"`
}
type Metadata struct {
PromptVersion *string `json:"promptVersion,omitempty"`
Variables map[string]interface{} `json:"variables,omitempty"`
}
type QuotaSnapshot struct {
EntitlementRequests float64 `json:"entitlementRequests"`
IsUnlimitedEntitlement bool `json:"isUnlimitedEntitlement"`
Overage float64 `json:"overage"`
OverageAllowedWithExhaustedQuota bool `json:"overageAllowedWithExhaustedQuota"`
RemainingPercentage float64 `json:"remainingPercentage"`
ResetDate *time.Time `json:"resetDate,omitempty"`
UsageAllowedWithExhaustedQuota bool `json:"usageAllowedWithExhaustedQuota"`
UsedRequests float64 `json:"usedRequests"`
}
type Repository struct {
Branch *string `json:"branch,omitempty"`
Name string `json:"name"`
Owner string `json:"owner"`
}
type Result struct {
Content string `json:"content"`
}
type ToolRequest struct {
Arguments interface{} `json:"arguments"`
Name string `json:"name"`
ToolCallID string `json:"toolCallId"`
}
type AttachmentType string
const (
Directory AttachmentType = "directory"
File AttachmentType = "file"
)
type Role string
const (
Developer Role = "developer"
System Role = "system"
)
type SourceType string
const (
Local SourceType = "local"
Remote SourceType = "remote"
)
type SessionEventType string
const (
Abort SessionEventType = "abort"
AssistantIntent SessionEventType = "assistant.intent"
AssistantMessage SessionEventType = "assistant.message"
AssistantMessageDelta SessionEventType = "assistant.message_delta"
AssistantReasoning SessionEventType = "assistant.reasoning"
AssistantReasoningDelta SessionEventType = "assistant.reasoning_delta"
AssistantTurnEnd SessionEventType = "assistant.turn_end"
AssistantTurnStart SessionEventType = "assistant.turn_start"
AssistantUsage SessionEventType = "assistant.usage"
CustomAgentCompleted SessionEventType = "custom_agent.completed"
CustomAgentFailed SessionEventType = "custom_agent.failed"
CustomAgentSelected SessionEventType = "custom_agent.selected"
CustomAgentStarted SessionEventType = "custom_agent.started"
HookEnd SessionEventType = "hook.end"
HookStart SessionEventType = "hook.start"
PendingMessagesModified SessionEventType = "pending_messages.modified"
SessionError SessionEventType = "session.error"
SessionHandoff SessionEventType = "session.handoff"
SessionIdle SessionEventType = "session.idle"
SessionInfo SessionEventType = "session.info"
SessionModelChange SessionEventType = "session.model_change"
SessionResume SessionEventType = "session.resume"
SessionStart SessionEventType = "session.start"
SessionTruncation SessionEventType = "session.truncation"
SystemMessage SessionEventType = "system.message"
ToolExecutionComplete SessionEventType = "tool.execution_complete"
ToolExecutionPartialResult SessionEventType = "tool.execution_partial_result"
ToolExecutionStart SessionEventType = "tool.execution_start"
ToolUserRequested SessionEventType = "tool.user_requested"
UserMessage SessionEventType = "user.message"
)
type ErrorUnion struct {
ErrorClass *ErrorClass
String *string
}
func (x *ErrorUnion) UnmarshalJSON(data []byte) error {
x.ErrorClass = nil
var c ErrorClass
object, err := unmarshalUnion(data, nil, nil, nil, &x.String, false, nil, true, &c, false, nil, false, nil, false)
if err != nil {
return err
}
if object {
x.ErrorClass = &c
}
return nil
}
func (x *ErrorUnion) MarshalJSON() ([]byte, error) {
return marshalUnion(nil, nil, nil, x.String, false, nil, x.ErrorClass != nil, x.ErrorClass, false, nil, false, nil, false)
}
func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) {
if pi != nil {
*pi = nil
}
if pf != nil {
*pf = nil
}
if pb != nil {
*pb = nil
}
if ps != nil {
*ps = nil
}
dec := json.NewDecoder(bytes.NewReader(data))
dec.UseNumber()
tok, err := dec.Token()
if err != nil {
return false, err
}
switch v := tok.(type) {
case json.Number:
if pi != nil {
i, err := v.Int64()
if err == nil {
*pi = &i
return false, nil
}
}
if pf != nil {
f, err := v.Float64()
if err == nil {
*pf = &f
return false, nil
}
return false, errors.New("Unparsable number")
}
return false, errors.New("Union does not contain number")
case float64:
return false, errors.New("Decoder should not return float64")
case bool:
if pb != nil {
*pb = &v
return false, nil
}
return false, errors.New("Union does not contain bool")
case string:
if haveEnum {
return false, json.Unmarshal(data, pe)
}
if ps != nil {
*ps = &v
return false, nil
}
return false, errors.New("Union does not contain string")
case nil:
if nullable {
return false, nil
}
return false, errors.New("Union does not contain null")
case json.Delim:
if v == '{' {
if haveObject {
return true, json.Unmarshal(data, pc)
}
if haveMap {
return false, json.Unmarshal(data, pm)
}
return false, errors.New("Union does not contain object")
}
if v == '[' {
if haveArray {
return false, json.Unmarshal(data, pa)
}
return false, errors.New("Union does not contain array")
}
return false, errors.New("Cannot handle delimiter")
}
return false, errors.New("Cannot unmarshal union")
}
func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) {
if pi != nil {
return json.Marshal(*pi)
}
if pf != nil {
return json.Marshal(*pf)
}
if pb != nil {
return json.Marshal(*pb)
}
if ps != nil {
return json.Marshal(*ps)
}
if haveArray {
return json.Marshal(pa)
}
if haveObject {
return json.Marshal(pc)
}
if haveMap {
return json.Marshal(pm)
}
if haveEnum {
return json.Marshal(pe)
}
if nullable {
return json.Marshal(nil)
}
return nil, errors.New("Union must not be null")
}