axexec 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.
- package/LICENSE +21 -0
- package/README.md +196 -0
- package/bin/axexec +17 -0
- package/dist/agents/claude-code/adapter.d.ts +6 -0
- package/dist/agents/claude-code/adapter.js +71 -0
- package/dist/agents/claude-code/parse-event.d.ts +16 -0
- package/dist/agents/claude-code/parse-event.js +185 -0
- package/dist/agents/claude-code/types.d.ts +180 -0
- package/dist/agents/claude-code/types.js +112 -0
- package/dist/agents/codex/adapter.d.ts +6 -0
- package/dist/agents/codex/adapter.js +62 -0
- package/dist/agents/codex/item-parsers.d.ts +17 -0
- package/dist/agents/codex/item-parsers.js +126 -0
- package/dist/agents/codex/parse-event.d.ts +38 -0
- package/dist/agents/codex/parse-event.js +141 -0
- package/dist/agents/codex/types.d.ts +407 -0
- package/dist/agents/codex/types.js +188 -0
- package/dist/agents/copilot/adapter.d.ts +11 -0
- package/dist/agents/copilot/adapter.js +81 -0
- package/dist/agents/copilot/parse-event.d.ts +20 -0
- package/dist/agents/copilot/parse-event.js +137 -0
- package/dist/agents/copilot/stream-session.d.ts +10 -0
- package/dist/agents/copilot/stream-session.js +120 -0
- package/dist/agents/copilot/tail-file.d.ts +11 -0
- package/dist/agents/copilot/tail-file.js +52 -0
- package/dist/agents/copilot/transform-event.d.ts +19 -0
- package/dist/agents/copilot/transform-event.js +100 -0
- package/dist/agents/copilot/types.d.ts +320 -0
- package/dist/agents/copilot/types.js +220 -0
- package/dist/agents/copilot/watch-session.d.ts +26 -0
- package/dist/agents/copilot/watch-session.js +186 -0
- package/dist/agents/gemini/adapter.d.ts +6 -0
- package/dist/agents/gemini/adapter.js +78 -0
- package/dist/agents/gemini/parse-event.d.ts +18 -0
- package/dist/agents/gemini/parse-event.js +144 -0
- package/dist/agents/gemini/types.d.ts +162 -0
- package/dist/agents/gemini/types.js +103 -0
- package/dist/agents/opencode/adapter.d.ts +16 -0
- package/dist/agents/opencode/adapter.js +142 -0
- package/dist/agents/opencode/cleanup-session.d.ts +17 -0
- package/dist/agents/opencode/cleanup-session.js +41 -0
- package/dist/agents/opencode/create-session-start-event.d.ts +18 -0
- package/dist/agents/opencode/create-session-start-event.js +24 -0
- package/dist/agents/opencode/detect-empty-session.d.ts +25 -0
- package/dist/agents/opencode/detect-empty-session.js +42 -0
- package/dist/agents/opencode/map-error-to-event.d.ts +10 -0
- package/dist/agents/opencode/map-error-to-event.js +55 -0
- package/dist/agents/opencode/parse-message-part.d.ts +24 -0
- package/dist/agents/opencode/parse-message-part.js +112 -0
- package/dist/agents/opencode/parse-sse-event.d.ts +23 -0
- package/dist/agents/opencode/parse-sse-event.js +125 -0
- package/dist/agents/opencode/process-sse-events.d.ts +24 -0
- package/dist/agents/opencode/process-sse-events.js +66 -0
- package/dist/agents/opencode/server-types.d.ts +509 -0
- package/dist/agents/opencode/server-types.js +293 -0
- package/dist/agents/opencode/session-api.d.ts +56 -0
- package/dist/agents/opencode/session-api.js +151 -0
- package/dist/agents/opencode/spawn-server.d.ts +29 -0
- package/dist/agents/opencode/spawn-server.js +95 -0
- package/dist/agents/opencode/sse-client.d.ts +33 -0
- package/dist/agents/opencode/sse-client.js +145 -0
- package/dist/agents/registry.d.ts +15 -0
- package/dist/agents/registry.js +24 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +119 -0
- package/dist/credentials/get-credential-environment.d.ts +13 -0
- package/dist/credentials/get-credential-environment.js +46 -0
- package/dist/credentials/install-credentials.d.ts +27 -0
- package/dist/credentials/install-credentials.js +102 -0
- package/dist/credentials/save-json-file.d.ts +11 -0
- package/dist/credentials/save-json-file.js +21 -0
- package/dist/credentials/types.d.ts +24 -0
- package/dist/credentials/types.js +4 -0
- package/dist/credentials/write-agent-credentials.d.ts +36 -0
- package/dist/credentials/write-agent-credentials.js +91 -0
- package/dist/determine-session-success.d.ts +15 -0
- package/dist/determine-session-success.js +25 -0
- package/dist/format-event-tsv.d.ts +23 -0
- package/dist/format-event-tsv.js +136 -0
- package/dist/parse-credentials.d.ts +13 -0
- package/dist/parse-credentials.js +63 -0
- package/dist/parse-iso-timestamp.d.ts +21 -0
- package/dist/parse-iso-timestamp.js +37 -0
- package/dist/resolve-binary.d.ts +29 -0
- package/dist/resolve-binary.js +46 -0
- package/dist/resolve-output-mode.d.ts +39 -0
- package/dist/resolve-output-mode.js +39 -0
- package/dist/run-agent.d.ts +32 -0
- package/dist/run-agent.js +146 -0
- package/dist/stream-agent.d.ts +20 -0
- package/dist/stream-agent.js +207 -0
- package/dist/types/adapter.d.ts +101 -0
- package/dist/types/adapter.js +14 -0
- package/dist/types/events.d.ts +82 -0
- package/dist/types/events.js +13 -0
- package/dist/types/options.d.ts +41 -0
- package/dist/types/options.js +4 -0
- package/dist/validate-agent.d.ts +20 -0
- package/dist/validate-agent.js +50 -0
- package/dist/write-event.d.ts +23 -0
- package/dist/write-event.js +43 -0
- package/package.json +79 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw event types from Copilot CLI's JSONL session files.
|
|
3
|
+
*
|
|
4
|
+
* These types represent the session events from Copilot CLI,
|
|
5
|
+
* which are persisted to `~/.copilot/session-state/{sessionId}.jsonl`.
|
|
6
|
+
*
|
|
7
|
+
* Copilot CLI writes session events to JSONL files in the session-state
|
|
8
|
+
* directory. The adapter tails these files and parses each JSONL record.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
/** Session start event - emitted when session begins */
|
|
12
|
+
declare const CopilotSessionStartEvent: z.ZodObject<{
|
|
13
|
+
id: z.ZodString;
|
|
14
|
+
timestamp: z.ZodString;
|
|
15
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
16
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
+
type: z.ZodLiteral<"session.start">;
|
|
18
|
+
data: z.ZodObject<{
|
|
19
|
+
sessionId: z.ZodString;
|
|
20
|
+
version: z.ZodNumber;
|
|
21
|
+
producer: z.ZodString;
|
|
22
|
+
copilotVersion: z.ZodString;
|
|
23
|
+
startTime: z.ZodString;
|
|
24
|
+
selectedModel: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
type CopilotSessionStartEvent = z.infer<typeof CopilotSessionStartEvent>;
|
|
28
|
+
/** Session error event - emitted on session error */
|
|
29
|
+
declare const CopilotSessionErrorEvent: z.ZodObject<{
|
|
30
|
+
id: z.ZodString;
|
|
31
|
+
timestamp: z.ZodString;
|
|
32
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
33
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
34
|
+
type: z.ZodLiteral<"session.error">;
|
|
35
|
+
data: z.ZodObject<{
|
|
36
|
+
errorType: z.ZodString;
|
|
37
|
+
message: z.ZodString;
|
|
38
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, z.core.$strip>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
type CopilotSessionErrorEvent = z.infer<typeof CopilotSessionErrorEvent>;
|
|
42
|
+
/** Session model change event - emitted when model is selected/changed */
|
|
43
|
+
declare const CopilotSessionModelChangeEvent: z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
timestamp: z.ZodString;
|
|
46
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
47
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
+
type: z.ZodLiteral<"session.model_change">;
|
|
49
|
+
data: z.ZodObject<{
|
|
50
|
+
previousModel: z.ZodOptional<z.ZodString>;
|
|
51
|
+
newModel: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
type CopilotSessionModelChangeEvent = z.infer<typeof CopilotSessionModelChangeEvent>;
|
|
55
|
+
/** Assistant message event - AI response */
|
|
56
|
+
declare const CopilotAssistantMessageEvent: z.ZodObject<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
timestamp: z.ZodString;
|
|
59
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
60
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
type: z.ZodLiteral<"assistant.message">;
|
|
62
|
+
data: z.ZodObject<{
|
|
63
|
+
messageId: z.ZodString;
|
|
64
|
+
content: z.ZodString;
|
|
65
|
+
chunkContent: z.ZodOptional<z.ZodString>;
|
|
66
|
+
totalResponseSizeBytes: z.ZodOptional<z.ZodNumber>;
|
|
67
|
+
toolRequests: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
68
|
+
toolCallId: z.ZodString;
|
|
69
|
+
name: z.ZodString;
|
|
70
|
+
arguments: z.ZodOptional<z.ZodUnknown>;
|
|
71
|
+
}, z.core.$strip>>>;
|
|
72
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
73
|
+
}, z.core.$strip>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
type CopilotAssistantMessageEvent = z.infer<typeof CopilotAssistantMessageEvent>;
|
|
76
|
+
/** Assistant turn end event */
|
|
77
|
+
declare const CopilotAssistantTurnEndEvent: z.ZodObject<{
|
|
78
|
+
id: z.ZodString;
|
|
79
|
+
timestamp: z.ZodString;
|
|
80
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
81
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
type: z.ZodLiteral<"assistant.turn_end">;
|
|
83
|
+
data: z.ZodObject<{
|
|
84
|
+
turnId: z.ZodString;
|
|
85
|
+
}, z.core.$strip>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
type CopilotAssistantTurnEndEvent = z.infer<typeof CopilotAssistantTurnEndEvent>;
|
|
88
|
+
/** Assistant usage event (ephemeral) - token/cost info */
|
|
89
|
+
declare const CopilotAssistantUsageEvent: z.ZodObject<{
|
|
90
|
+
id: z.ZodString;
|
|
91
|
+
timestamp: z.ZodString;
|
|
92
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
93
|
+
type: z.ZodLiteral<"assistant.usage">;
|
|
94
|
+
ephemeral: z.ZodLiteral<true>;
|
|
95
|
+
data: z.ZodObject<{
|
|
96
|
+
model: z.ZodOptional<z.ZodString>;
|
|
97
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
cost: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
initiator: z.ZodOptional<z.ZodString>;
|
|
104
|
+
apiCallId: z.ZodOptional<z.ZodString>;
|
|
105
|
+
providerCallId: z.ZodOptional<z.ZodString>;
|
|
106
|
+
}, z.core.$strip>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
type CopilotAssistantUsageEvent = z.infer<typeof CopilotAssistantUsageEvent>;
|
|
109
|
+
/** Tool execution start event */
|
|
110
|
+
declare const CopilotToolExecutionStartEvent: z.ZodObject<{
|
|
111
|
+
id: z.ZodString;
|
|
112
|
+
timestamp: z.ZodString;
|
|
113
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
114
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
+
type: z.ZodLiteral<"tool.execution_start">;
|
|
116
|
+
data: z.ZodObject<{
|
|
117
|
+
toolCallId: z.ZodString;
|
|
118
|
+
toolName: z.ZodString;
|
|
119
|
+
arguments: z.ZodOptional<z.ZodUnknown>;
|
|
120
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
121
|
+
}, z.core.$strip>;
|
|
122
|
+
}, z.core.$strip>;
|
|
123
|
+
type CopilotToolExecutionStartEvent = z.infer<typeof CopilotToolExecutionStartEvent>;
|
|
124
|
+
/** Tool execution complete event */
|
|
125
|
+
declare const CopilotToolExecutionCompleteEvent: z.ZodObject<{
|
|
126
|
+
id: z.ZodString;
|
|
127
|
+
timestamp: z.ZodString;
|
|
128
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
129
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
130
|
+
type: z.ZodLiteral<"tool.execution_complete">;
|
|
131
|
+
data: z.ZodObject<{
|
|
132
|
+
toolCallId: z.ZodString;
|
|
133
|
+
success: z.ZodBoolean;
|
|
134
|
+
isUserRequested: z.ZodOptional<z.ZodBoolean>;
|
|
135
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
136
|
+
content: z.ZodString;
|
|
137
|
+
}, z.core.$strip>>;
|
|
138
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
139
|
+
message: z.ZodString;
|
|
140
|
+
code: z.ZodOptional<z.ZodString>;
|
|
141
|
+
}, z.core.$strip>>;
|
|
142
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, z.core.$strip>;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
type CopilotToolExecutionCompleteEvent = z.infer<typeof CopilotToolExecutionCompleteEvent>;
|
|
146
|
+
/** Abort event - session aborted */
|
|
147
|
+
declare const CopilotAbortEvent: z.ZodObject<{
|
|
148
|
+
id: z.ZodString;
|
|
149
|
+
timestamp: z.ZodString;
|
|
150
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
151
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
152
|
+
type: z.ZodLiteral<"abort">;
|
|
153
|
+
data: z.ZodObject<{
|
|
154
|
+
reason: z.ZodString;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
}, z.core.$strip>;
|
|
157
|
+
type CopilotAbortEvent = z.infer<typeof CopilotAbortEvent>;
|
|
158
|
+
/** Union of all Copilot CLI event types */
|
|
159
|
+
declare const CopilotEvent: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
160
|
+
id: z.ZodString;
|
|
161
|
+
timestamp: z.ZodString;
|
|
162
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
163
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
type: z.ZodLiteral<"session.start">;
|
|
165
|
+
data: z.ZodObject<{
|
|
166
|
+
sessionId: z.ZodString;
|
|
167
|
+
version: z.ZodNumber;
|
|
168
|
+
producer: z.ZodString;
|
|
169
|
+
copilotVersion: z.ZodString;
|
|
170
|
+
startTime: z.ZodString;
|
|
171
|
+
selectedModel: z.ZodOptional<z.ZodString>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
174
|
+
id: z.ZodString;
|
|
175
|
+
timestamp: z.ZodString;
|
|
176
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
177
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
178
|
+
type: z.ZodLiteral<"session.error">;
|
|
179
|
+
data: z.ZodObject<{
|
|
180
|
+
errorType: z.ZodString;
|
|
181
|
+
message: z.ZodString;
|
|
182
|
+
stack: z.ZodOptional<z.ZodString>;
|
|
183
|
+
}, z.core.$strip>;
|
|
184
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
185
|
+
id: z.ZodString;
|
|
186
|
+
timestamp: z.ZodString;
|
|
187
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
188
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
189
|
+
type: z.ZodLiteral<"session.model_change">;
|
|
190
|
+
data: z.ZodObject<{
|
|
191
|
+
previousModel: z.ZodOptional<z.ZodString>;
|
|
192
|
+
newModel: z.ZodString;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
195
|
+
id: z.ZodString;
|
|
196
|
+
timestamp: z.ZodString;
|
|
197
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
198
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
199
|
+
type: z.ZodLiteral<"user.message">;
|
|
200
|
+
data: z.ZodObject<{
|
|
201
|
+
content: z.ZodString;
|
|
202
|
+
transformedContent: z.ZodOptional<z.ZodString>;
|
|
203
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
204
|
+
}, z.core.$strip>;
|
|
205
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
206
|
+
id: z.ZodString;
|
|
207
|
+
timestamp: z.ZodString;
|
|
208
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
209
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
210
|
+
type: z.ZodLiteral<"assistant.message">;
|
|
211
|
+
data: z.ZodObject<{
|
|
212
|
+
messageId: z.ZodString;
|
|
213
|
+
content: z.ZodString;
|
|
214
|
+
chunkContent: z.ZodOptional<z.ZodString>;
|
|
215
|
+
totalResponseSizeBytes: z.ZodOptional<z.ZodNumber>;
|
|
216
|
+
toolRequests: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
217
|
+
toolCallId: z.ZodString;
|
|
218
|
+
name: z.ZodString;
|
|
219
|
+
arguments: z.ZodOptional<z.ZodUnknown>;
|
|
220
|
+
}, z.core.$strip>>>;
|
|
221
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
222
|
+
}, z.core.$strip>;
|
|
223
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
224
|
+
id: z.ZodString;
|
|
225
|
+
timestamp: z.ZodString;
|
|
226
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
227
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
228
|
+
type: z.ZodLiteral<"assistant.turn_start">;
|
|
229
|
+
data: z.ZodObject<{
|
|
230
|
+
turnId: z.ZodString;
|
|
231
|
+
}, z.core.$strip>;
|
|
232
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
233
|
+
id: z.ZodString;
|
|
234
|
+
timestamp: z.ZodString;
|
|
235
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
236
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
+
type: z.ZodLiteral<"assistant.turn_end">;
|
|
238
|
+
data: z.ZodObject<{
|
|
239
|
+
turnId: z.ZodString;
|
|
240
|
+
}, z.core.$strip>;
|
|
241
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
242
|
+
id: z.ZodString;
|
|
243
|
+
timestamp: z.ZodString;
|
|
244
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
245
|
+
type: z.ZodLiteral<"assistant.usage">;
|
|
246
|
+
ephemeral: z.ZodLiteral<true>;
|
|
247
|
+
data: z.ZodObject<{
|
|
248
|
+
model: z.ZodOptional<z.ZodString>;
|
|
249
|
+
inputTokens: z.ZodOptional<z.ZodNumber>;
|
|
250
|
+
outputTokens: z.ZodOptional<z.ZodNumber>;
|
|
251
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
252
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
253
|
+
cost: z.ZodOptional<z.ZodNumber>;
|
|
254
|
+
duration: z.ZodOptional<z.ZodNumber>;
|
|
255
|
+
initiator: z.ZodOptional<z.ZodString>;
|
|
256
|
+
apiCallId: z.ZodOptional<z.ZodString>;
|
|
257
|
+
providerCallId: z.ZodOptional<z.ZodString>;
|
|
258
|
+
}, z.core.$strip>;
|
|
259
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
260
|
+
id: z.ZodString;
|
|
261
|
+
timestamp: z.ZodString;
|
|
262
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
263
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
264
|
+
type: z.ZodLiteral<"tool.execution_start">;
|
|
265
|
+
data: z.ZodObject<{
|
|
266
|
+
toolCallId: z.ZodString;
|
|
267
|
+
toolName: z.ZodString;
|
|
268
|
+
arguments: z.ZodOptional<z.ZodUnknown>;
|
|
269
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
270
|
+
}, z.core.$strip>;
|
|
271
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
272
|
+
id: z.ZodString;
|
|
273
|
+
timestamp: z.ZodString;
|
|
274
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
275
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
276
|
+
type: z.ZodLiteral<"tool.execution_complete">;
|
|
277
|
+
data: z.ZodObject<{
|
|
278
|
+
toolCallId: z.ZodString;
|
|
279
|
+
success: z.ZodBoolean;
|
|
280
|
+
isUserRequested: z.ZodOptional<z.ZodBoolean>;
|
|
281
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
282
|
+
content: z.ZodString;
|
|
283
|
+
}, z.core.$strip>>;
|
|
284
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
285
|
+
message: z.ZodString;
|
|
286
|
+
code: z.ZodOptional<z.ZodString>;
|
|
287
|
+
}, z.core.$strip>>;
|
|
288
|
+
parentToolCallId: z.ZodOptional<z.ZodString>;
|
|
289
|
+
}, z.core.$strip>;
|
|
290
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
291
|
+
id: z.ZodString;
|
|
292
|
+
timestamp: z.ZodString;
|
|
293
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
294
|
+
ephemeral: z.ZodOptional<z.ZodBoolean>;
|
|
295
|
+
type: z.ZodLiteral<"abort">;
|
|
296
|
+
data: z.ZodObject<{
|
|
297
|
+
reason: z.ZodString;
|
|
298
|
+
}, z.core.$strip>;
|
|
299
|
+
}, z.core.$strip>], "type">;
|
|
300
|
+
type CopilotEvent = z.infer<typeof CopilotEvent>;
|
|
301
|
+
/** Type guard for session.start events */
|
|
302
|
+
declare function isSessionStartEvent(event: CopilotEvent): event is CopilotSessionStartEvent;
|
|
303
|
+
/** Type guard for session.error events */
|
|
304
|
+
declare function isSessionErrorEvent(event: CopilotEvent): event is CopilotSessionErrorEvent;
|
|
305
|
+
/** Type guard for session.model_change events */
|
|
306
|
+
declare function isSessionModelChangeEvent(event: CopilotEvent): event is CopilotSessionModelChangeEvent;
|
|
307
|
+
/** Type guard for assistant.turn_end events */
|
|
308
|
+
declare function isAssistantTurnEndEvent(event: CopilotEvent): event is CopilotAssistantTurnEndEvent;
|
|
309
|
+
/** Type guard for assistant.message events */
|
|
310
|
+
declare function isAssistantMessageEvent(event: CopilotEvent): event is CopilotAssistantMessageEvent;
|
|
311
|
+
/** Type guard for assistant.usage events */
|
|
312
|
+
declare function isAssistantUsageEvent(event: CopilotEvent): event is CopilotAssistantUsageEvent;
|
|
313
|
+
/** Type guard for tool.execution_start events */
|
|
314
|
+
declare function isToolExecutionStartEvent(event: CopilotEvent): event is CopilotToolExecutionStartEvent;
|
|
315
|
+
/** Type guard for tool.execution_complete events */
|
|
316
|
+
declare function isToolExecutionCompleteEvent(event: CopilotEvent): event is CopilotToolExecutionCompleteEvent;
|
|
317
|
+
/** Type guard for abort events */
|
|
318
|
+
declare function isAbortEvent(event: CopilotEvent): event is CopilotAbortEvent;
|
|
319
|
+
export { CopilotEvent, isAbortEvent, isAssistantMessageEvent, isAssistantTurnEndEvent, isAssistantUsageEvent, isSessionErrorEvent, isSessionModelChangeEvent, isSessionStartEvent, isToolExecutionCompleteEvent, isToolExecutionStartEvent, };
|
|
320
|
+
export type { CopilotAssistantMessageEvent, CopilotAssistantUsageEvent, CopilotSessionErrorEvent, CopilotSessionStartEvent, CopilotToolExecutionCompleteEvent, CopilotToolExecutionStartEvent, };
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw event types from Copilot CLI's JSONL session files.
|
|
3
|
+
*
|
|
4
|
+
* These types represent the session events from Copilot CLI,
|
|
5
|
+
* which are persisted to `~/.copilot/session-state/{sessionId}.jsonl`.
|
|
6
|
+
*
|
|
7
|
+
* Copilot CLI writes session events to JSONL files in the session-state
|
|
8
|
+
* directory. The adapter tails these files and parses each JSONL record.
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Base Event Schema
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/** Base fields present in all Copilot events */
|
|
15
|
+
const CopilotEventBase = z.object({
|
|
16
|
+
id: z.string(),
|
|
17
|
+
timestamp: z.string(),
|
|
18
|
+
parentId: z.string().nullable(),
|
|
19
|
+
ephemeral: z.boolean().optional(),
|
|
20
|
+
});
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Session Events
|
|
23
|
+
// =============================================================================
|
|
24
|
+
/** Session start event - emitted when session begins */
|
|
25
|
+
const CopilotSessionStartEvent = CopilotEventBase.extend({
|
|
26
|
+
type: z.literal("session.start"),
|
|
27
|
+
data: z.object({
|
|
28
|
+
sessionId: z.string(),
|
|
29
|
+
version: z.number(),
|
|
30
|
+
producer: z.string(),
|
|
31
|
+
copilotVersion: z.string(),
|
|
32
|
+
startTime: z.string(),
|
|
33
|
+
selectedModel: z.string().optional(),
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
/** Session error event - emitted on session error */
|
|
37
|
+
const CopilotSessionErrorEvent = CopilotEventBase.extend({
|
|
38
|
+
type: z.literal("session.error"),
|
|
39
|
+
data: z.object({
|
|
40
|
+
errorType: z.string(),
|
|
41
|
+
message: z.string(),
|
|
42
|
+
stack: z.string().optional(),
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
45
|
+
/** Session model change event - emitted when model is selected/changed */
|
|
46
|
+
const CopilotSessionModelChangeEvent = CopilotEventBase.extend({
|
|
47
|
+
type: z.literal("session.model_change"),
|
|
48
|
+
data: z.object({
|
|
49
|
+
previousModel: z.string().optional(),
|
|
50
|
+
newModel: z.string(),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// User Events
|
|
55
|
+
// =============================================================================
|
|
56
|
+
/** User message event - user input */
|
|
57
|
+
const CopilotUserMessageEvent = CopilotEventBase.extend({
|
|
58
|
+
type: z.literal("user.message"),
|
|
59
|
+
data: z.object({
|
|
60
|
+
content: z.string(),
|
|
61
|
+
transformedContent: z.string().optional(),
|
|
62
|
+
attachments: z.array(z.unknown()).optional(),
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
// =============================================================================
|
|
66
|
+
// Assistant Events
|
|
67
|
+
// =============================================================================
|
|
68
|
+
/** Tool request within assistant message */
|
|
69
|
+
const CopilotToolRequest = z.object({
|
|
70
|
+
toolCallId: z.string(),
|
|
71
|
+
name: z.string(),
|
|
72
|
+
arguments: z.unknown().optional(),
|
|
73
|
+
});
|
|
74
|
+
/** Assistant message event - AI response */
|
|
75
|
+
const CopilotAssistantMessageEvent = CopilotEventBase.extend({
|
|
76
|
+
type: z.literal("assistant.message"),
|
|
77
|
+
data: z.object({
|
|
78
|
+
messageId: z.string(),
|
|
79
|
+
content: z.string(),
|
|
80
|
+
chunkContent: z.string().optional(),
|
|
81
|
+
totalResponseSizeBytes: z.number().optional(),
|
|
82
|
+
toolRequests: z.array(CopilotToolRequest).optional(),
|
|
83
|
+
parentToolCallId: z.string().optional(),
|
|
84
|
+
}),
|
|
85
|
+
});
|
|
86
|
+
/** Assistant turn start event */
|
|
87
|
+
const CopilotAssistantTurnStartEvent = CopilotEventBase.extend({
|
|
88
|
+
type: z.literal("assistant.turn_start"),
|
|
89
|
+
data: z.object({
|
|
90
|
+
turnId: z.string(),
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
/** Assistant turn end event */
|
|
94
|
+
const CopilotAssistantTurnEndEvent = CopilotEventBase.extend({
|
|
95
|
+
type: z.literal("assistant.turn_end"),
|
|
96
|
+
data: z.object({
|
|
97
|
+
turnId: z.string(),
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
/** Assistant usage event (ephemeral) - token/cost info */
|
|
101
|
+
const CopilotAssistantUsageEvent = CopilotEventBase.extend({
|
|
102
|
+
type: z.literal("assistant.usage"),
|
|
103
|
+
ephemeral: z.literal(true),
|
|
104
|
+
data: z.object({
|
|
105
|
+
model: z.string().optional(),
|
|
106
|
+
inputTokens: z.number().optional(),
|
|
107
|
+
outputTokens: z.number().optional(),
|
|
108
|
+
cacheReadTokens: z.number().optional(),
|
|
109
|
+
cacheWriteTokens: z.number().optional(),
|
|
110
|
+
cost: z.number().optional(),
|
|
111
|
+
duration: z.number().optional(),
|
|
112
|
+
initiator: z.string().optional(),
|
|
113
|
+
apiCallId: z.string().optional(),
|
|
114
|
+
providerCallId: z.string().optional(),
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
// =============================================================================
|
|
118
|
+
// Tool Events
|
|
119
|
+
// =============================================================================
|
|
120
|
+
/** Tool execution start event */
|
|
121
|
+
const CopilotToolExecutionStartEvent = CopilotEventBase.extend({
|
|
122
|
+
type: z.literal("tool.execution_start"),
|
|
123
|
+
data: z.object({
|
|
124
|
+
toolCallId: z.string(),
|
|
125
|
+
toolName: z.string(),
|
|
126
|
+
arguments: z.unknown().optional(),
|
|
127
|
+
parentToolCallId: z.string().optional(),
|
|
128
|
+
}),
|
|
129
|
+
});
|
|
130
|
+
/** Tool execution complete event */
|
|
131
|
+
const CopilotToolExecutionCompleteEvent = CopilotEventBase.extend({
|
|
132
|
+
type: z.literal("tool.execution_complete"),
|
|
133
|
+
data: z.object({
|
|
134
|
+
toolCallId: z.string(),
|
|
135
|
+
success: z.boolean(),
|
|
136
|
+
isUserRequested: z.boolean().optional(),
|
|
137
|
+
result: z
|
|
138
|
+
.object({
|
|
139
|
+
content: z.string(),
|
|
140
|
+
})
|
|
141
|
+
.optional(),
|
|
142
|
+
error: z
|
|
143
|
+
.object({
|
|
144
|
+
message: z.string(),
|
|
145
|
+
code: z.string().optional(),
|
|
146
|
+
})
|
|
147
|
+
.optional(),
|
|
148
|
+
parentToolCallId: z.string().optional(),
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
151
|
+
// =============================================================================
|
|
152
|
+
// Other Events
|
|
153
|
+
// =============================================================================
|
|
154
|
+
/** Abort event - session aborted */
|
|
155
|
+
const CopilotAbortEvent = CopilotEventBase.extend({
|
|
156
|
+
type: z.literal("abort"),
|
|
157
|
+
data: z.object({
|
|
158
|
+
reason: z.string(),
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
// =============================================================================
|
|
162
|
+
// Union Types
|
|
163
|
+
// =============================================================================
|
|
164
|
+
/** Union of all Copilot CLI event types */
|
|
165
|
+
const CopilotEvent = z.discriminatedUnion("type", [
|
|
166
|
+
CopilotSessionStartEvent,
|
|
167
|
+
CopilotSessionErrorEvent,
|
|
168
|
+
CopilotSessionModelChangeEvent,
|
|
169
|
+
CopilotUserMessageEvent,
|
|
170
|
+
CopilotAssistantMessageEvent,
|
|
171
|
+
CopilotAssistantTurnStartEvent,
|
|
172
|
+
CopilotAssistantTurnEndEvent,
|
|
173
|
+
CopilotAssistantUsageEvent,
|
|
174
|
+
CopilotToolExecutionStartEvent,
|
|
175
|
+
CopilotToolExecutionCompleteEvent,
|
|
176
|
+
CopilotAbortEvent,
|
|
177
|
+
]);
|
|
178
|
+
// =============================================================================
|
|
179
|
+
// Type Guards
|
|
180
|
+
// =============================================================================
|
|
181
|
+
/** Type guard for session.start events */
|
|
182
|
+
function isSessionStartEvent(event) {
|
|
183
|
+
return event.type === "session.start";
|
|
184
|
+
}
|
|
185
|
+
/** Type guard for session.error events */
|
|
186
|
+
function isSessionErrorEvent(event) {
|
|
187
|
+
return event.type === "session.error";
|
|
188
|
+
}
|
|
189
|
+
/** Type guard for session.model_change events */
|
|
190
|
+
function isSessionModelChangeEvent(event) {
|
|
191
|
+
return event.type === "session.model_change";
|
|
192
|
+
}
|
|
193
|
+
/** Type guard for assistant.turn_end events */
|
|
194
|
+
function isAssistantTurnEndEvent(event) {
|
|
195
|
+
return event.type === "assistant.turn_end";
|
|
196
|
+
}
|
|
197
|
+
/** Type guard for assistant.message events */
|
|
198
|
+
function isAssistantMessageEvent(event) {
|
|
199
|
+
return event.type === "assistant.message";
|
|
200
|
+
}
|
|
201
|
+
/** Type guard for assistant.usage events */
|
|
202
|
+
function isAssistantUsageEvent(event) {
|
|
203
|
+
return event.type === "assistant.usage";
|
|
204
|
+
}
|
|
205
|
+
/** Type guard for tool.execution_start events */
|
|
206
|
+
function isToolExecutionStartEvent(event) {
|
|
207
|
+
return event.type === "tool.execution_start";
|
|
208
|
+
}
|
|
209
|
+
/** Type guard for tool.execution_complete events */
|
|
210
|
+
function isToolExecutionCompleteEvent(event) {
|
|
211
|
+
return event.type === "tool.execution_complete";
|
|
212
|
+
}
|
|
213
|
+
/** Type guard for abort events */
|
|
214
|
+
function isAbortEvent(event) {
|
|
215
|
+
return event.type === "abort";
|
|
216
|
+
}
|
|
217
|
+
// =============================================================================
|
|
218
|
+
// Exports
|
|
219
|
+
// =============================================================================
|
|
220
|
+
export { CopilotEvent, isAbortEvent, isAssistantMessageEvent, isAssistantTurnEndEvent, isAssistantUsageEvent, isSessionErrorEvent, isSessionModelChangeEvent, isSessionStartEvent, isToolExecutionCompleteEvent, isToolExecutionStartEvent, };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session file watcher for Copilot CLI.
|
|
3
|
+
*
|
|
4
|
+
* Watches ~/.copilot/session-state/ for new session files.
|
|
5
|
+
*
|
|
6
|
+
* Copilot CLI has two session file formats:
|
|
7
|
+
* - Old: ~/.copilot/session-state/<uuid>.jsonl
|
|
8
|
+
* - New (0.0.380+): ~/.copilot/session-state/<uuid>/events.jsonl
|
|
9
|
+
*
|
|
10
|
+
* This module supports both formats for compatibility.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Get all existing session entries (both old .jsonl files and new directories).
|
|
14
|
+
* Returns entry names (not full paths) for comparison.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getExistingSessionFiles(): Set<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Wait for a new session file to appear.
|
|
19
|
+
*
|
|
20
|
+
* Uses both file watching and polling to detect new session files.
|
|
21
|
+
* Returns a promise that resolves with the new session file path.
|
|
22
|
+
*/
|
|
23
|
+
export declare function waitForSessionFile(existingFiles: Set<string>, timeoutMs?: number): {
|
|
24
|
+
promise: Promise<string>;
|
|
25
|
+
cleanup: () => void;
|
|
26
|
+
};
|