@meistrari/agent-core 0.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/README.md +26 -0
- package/package.json +69 -0
- package/scripts/write-provenance.ts +74 -0
- package/src/errors/app-error.ts +66 -0
- package/src/errors/application-error.ts +55 -0
- package/src/errors/index.ts +16 -0
- package/src/errors/infrastructure-error.ts +13 -0
- package/src/errors/provider-error.ts +13 -0
- package/src/errors/validation-error.ts +19 -0
- package/src/logger/index.ts +75 -0
- package/src/protocol/agent-command.ts +65 -0
- package/src/protocol/agent-content.ts +73 -0
- package/src/protocol/agent-error.ts +81 -0
- package/src/protocol/agent-event.ts +391 -0
- package/src/protocol/agent-json.ts +30 -0
- package/src/protocol/agent-metadata.ts +30 -0
- package/src/protocol/agent-model.ts +68 -0
- package/src/protocol/agent-overflow.ts +18 -0
- package/src/protocol/agent-presentation.ts +98 -0
- package/src/protocol/agent-provider.ts +4 -0
- package/src/protocol/agent-tool-name.ts +48 -0
- package/src/protocol/agent-tool.ts +40 -0
- package/src/protocol/agent-usage.ts +14 -0
- package/src/protocol/agent-user-input.ts +38 -0
- package/src/protocol/agent-work.ts +100 -0
- package/src/protocol/index.ts +13 -0
- package/src/provenance.gen.ts +6 -0
- package/src/provenance.ts +27 -0
- package/src/supervisor-protocol/agent-event-wrapper.ts +179 -0
- package/src/supervisor-protocol/bootstrap-rejection-receipt.ts +3 -0
- package/src/supervisor-protocol/bootstrap.ts +126 -0
- package/src/supervisor-protocol/command-body.ts +82 -0
- package/src/supervisor-protocol/context-file-content.ts +90 -0
- package/src/supervisor-protocol/control-authority.ts +88 -0
- package/src/supervisor-protocol/durability.ts +33 -0
- package/src/supervisor-protocol/envelope.ts +58 -0
- package/src/supervisor-protocol/envelopes/common.ts +7 -0
- package/src/supervisor-protocol/envelopes/control-plane-to-supervisor.ts +38 -0
- package/src/supervisor-protocol/envelopes/supervisor-to-control-plane.ts +89 -0
- package/src/supervisor-protocol/event-body.ts +13 -0
- package/src/supervisor-protocol/input-attachment-content.ts +3 -0
- package/src/supervisor-protocol/payload-overflow.ts +15 -0
- package/src/supervisor-protocol/product-event.ts +27 -0
- package/src/supervisor-protocol/profile.ts +22 -0
- package/src/supervisor-protocol/rpc.ts +77 -0
- package/src/supervisor-protocol/supervisor-agent-run-snapshot.ts +12 -0
- package/src/supervisor-protocol/supervisor-event.ts +361 -0
- package/src/supervisor-protocol/tela-page-content.ts +6 -0
- package/src/supervisor-protocol/wire-codec.ts +71 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { jsonValueSchema } from './agent-json'
|
|
3
|
+
import { agentRunMetadataSchema } from './agent-metadata'
|
|
4
|
+
import { agentPayloadOverflowSchema } from './agent-overflow'
|
|
5
|
+
import { agentProviderIdSchema } from './agent-provider'
|
|
6
|
+
import { agentToolCallStatusSchema, agentToolResultSchema } from './agent-tool'
|
|
7
|
+
import { agentUsageSchema } from './agent-usage'
|
|
8
|
+
import { agentUserInputAnswersSchema, agentUserInputQuestionSchema } from './agent-user-input'
|
|
9
|
+
import { agentWorkObservationSchema } from './agent-work'
|
|
10
|
+
|
|
11
|
+
export interface AgentError {
|
|
12
|
+
message: string
|
|
13
|
+
code?: string
|
|
14
|
+
name?: string
|
|
15
|
+
stack?: string
|
|
16
|
+
cause?: AgentError
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const agentErrorSchema: z.ZodType<AgentError> = z.object({
|
|
20
|
+
message: z.string().min(1),
|
|
21
|
+
code: z.string().min(1).optional(),
|
|
22
|
+
name: z.string().min(1).optional(),
|
|
23
|
+
stack: z.string().min(1).optional(),
|
|
24
|
+
cause: z.lazy(() => agentErrorSchema).optional(),
|
|
25
|
+
}).strict()
|
|
26
|
+
|
|
27
|
+
export const agentMessageRoleSchema = z.enum(['user', 'assistant', 'system'])
|
|
28
|
+
export const agentSessionEndReasonSchema = z.enum(['completed', 'stopped', 'interrupted', 'failed'])
|
|
29
|
+
export const agentSessionStateSchema = z.enum(['ready', 'running', 'idle', 'waiting_for_user_input', 'stopping', 'stopped', 'failed'])
|
|
30
|
+
export const agentTurnEndStatusSchema = z.enum(['completed', 'failed', 'cancelled', 'interrupted'])
|
|
31
|
+
export const agentSubagentStatusSchema = z.enum(['completed', 'failed', 'cancelled'])
|
|
32
|
+
export const agentContextCompactionTriggerSchema = z.enum(['manual', 'auto', 'unknown'])
|
|
33
|
+
export const agentContextCompactionStatusSchema = z.enum(['completed', 'failed'])
|
|
34
|
+
export const agentErrorSourceSchema = z.enum(['provider', 'runtime', 'transport', 'unknown'])
|
|
35
|
+
export const agentSkillScopeSchema = z.enum(['user', 'repository', 'system', 'admin'])
|
|
36
|
+
|
|
37
|
+
export const agentSkillSchema = z.object({
|
|
38
|
+
id: z.string().min(1),
|
|
39
|
+
name: z.string().min(1),
|
|
40
|
+
description: z.string().min(1),
|
|
41
|
+
scope: agentSkillScopeSchema,
|
|
42
|
+
}).strict()
|
|
43
|
+
|
|
44
|
+
export const agentEventBaseSchema = z.object({
|
|
45
|
+
eventId: z.string().min(1),
|
|
46
|
+
provider: agentProviderIdSchema,
|
|
47
|
+
sessionId: z.string().min(1),
|
|
48
|
+
providerSessionId: z.string().min(1),
|
|
49
|
+
timestamp: z.string().datetime(),
|
|
50
|
+
sequence: z.number().int().nonnegative(),
|
|
51
|
+
}).strict()
|
|
52
|
+
|
|
53
|
+
export const agentEventActorOriginSchema = z.discriminatedUnion('type', [
|
|
54
|
+
z.object({
|
|
55
|
+
type: z.literal('tool_call'),
|
|
56
|
+
toolCallId: z.string().min(1),
|
|
57
|
+
}).strict(),
|
|
58
|
+
z.object({
|
|
59
|
+
type: z.literal('provider_task'),
|
|
60
|
+
taskId: z.string().min(1),
|
|
61
|
+
}).strict(),
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
export const agentEventActorSchema = z.discriminatedUnion('type', [
|
|
65
|
+
z.object({
|
|
66
|
+
type: z.literal('main'),
|
|
67
|
+
actorId: z.literal('main'),
|
|
68
|
+
}).strict(),
|
|
69
|
+
z.object({
|
|
70
|
+
type: z.literal('subagent'),
|
|
71
|
+
actorId: z.string().min(1),
|
|
72
|
+
subagentId: z.string().min(1),
|
|
73
|
+
parentActorId: z.string().min(1),
|
|
74
|
+
origin: agentEventActorOriginSchema,
|
|
75
|
+
parentToolCallId: z.string().min(1).optional(),
|
|
76
|
+
name: z.string().min(1).optional(),
|
|
77
|
+
}).strict(),
|
|
78
|
+
])
|
|
79
|
+
|
|
80
|
+
const subagentRefSchema = z.object({
|
|
81
|
+
subagentId: z.string().min(1),
|
|
82
|
+
actorId: z.string().min(1),
|
|
83
|
+
parentActorId: z.string().min(1),
|
|
84
|
+
origin: agentEventActorOriginSchema,
|
|
85
|
+
parentToolCallId: z.string().min(1).optional(),
|
|
86
|
+
name: z.string().min(1).optional(),
|
|
87
|
+
}).strict()
|
|
88
|
+
|
|
89
|
+
export const agentTurnEventBaseSchema = agentEventBaseSchema.extend({
|
|
90
|
+
turnId: z.string().min(1),
|
|
91
|
+
actor: agentEventActorSchema,
|
|
92
|
+
}).strict()
|
|
93
|
+
|
|
94
|
+
export const sessionStartedAgentEventSchema = agentEventBaseSchema.extend({
|
|
95
|
+
type: z.literal('session.started'),
|
|
96
|
+
payload: agentRunMetadataSchema,
|
|
97
|
+
}).strict()
|
|
98
|
+
|
|
99
|
+
export const sessionConfiguredAgentEventSchema = agentEventBaseSchema.extend({
|
|
100
|
+
type: z.literal('session.configured'),
|
|
101
|
+
payload: z.object({
|
|
102
|
+
model: z.string().min(1),
|
|
103
|
+
cwd: z.string().min(1),
|
|
104
|
+
approvalMode: z.literal('full-access'),
|
|
105
|
+
tools: z.array(z.string().min(1)),
|
|
106
|
+
reasoningEffort: z.string().min(1).optional(),
|
|
107
|
+
environment: z.record(z.string().min(1), z.literal('[REDACTED]')),
|
|
108
|
+
}).strict(),
|
|
109
|
+
}).strict()
|
|
110
|
+
|
|
111
|
+
export const sessionSkillsUpdatedAgentEventSchema = agentEventBaseSchema.extend({
|
|
112
|
+
type: z.literal('session.skills.updated'),
|
|
113
|
+
payload: z.object({
|
|
114
|
+
skills: z.array(agentSkillSchema),
|
|
115
|
+
}).strict(),
|
|
116
|
+
}).strict()
|
|
117
|
+
|
|
118
|
+
export const sessionStateChangedAgentEventSchema = agentEventBaseSchema.extend({
|
|
119
|
+
type: z.literal('session.state.changed'),
|
|
120
|
+
payload: z.object({
|
|
121
|
+
state: agentSessionStateSchema,
|
|
122
|
+
error: agentErrorSchema.optional(),
|
|
123
|
+
}).strict(),
|
|
124
|
+
}).strict()
|
|
125
|
+
|
|
126
|
+
export const sessionEndedAgentEventSchema = agentEventBaseSchema.extend({
|
|
127
|
+
type: z.literal('session.ended'),
|
|
128
|
+
payload: z.object({
|
|
129
|
+
reason: agentSessionEndReasonSchema,
|
|
130
|
+
exitCode: z.number().int().nullable().optional(),
|
|
131
|
+
signal: z.string().min(1).nullable().optional(),
|
|
132
|
+
error: agentErrorSchema.optional(),
|
|
133
|
+
}).strict(),
|
|
134
|
+
}).strict()
|
|
135
|
+
|
|
136
|
+
export const turnStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
137
|
+
type: z.literal('turn.started'),
|
|
138
|
+
payload: z.object({}).strict(),
|
|
139
|
+
}).strict()
|
|
140
|
+
|
|
141
|
+
export const turnEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
142
|
+
type: z.literal('turn.ended'),
|
|
143
|
+
payload: z.object({
|
|
144
|
+
status: agentTurnEndStatusSchema,
|
|
145
|
+
reason: z.string().min(1).optional(),
|
|
146
|
+
error: agentErrorSchema.optional(),
|
|
147
|
+
duration: z.number().int().nonnegative().optional(),
|
|
148
|
+
}).strict(),
|
|
149
|
+
}).strict()
|
|
150
|
+
|
|
151
|
+
export const workObservedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
152
|
+
type: z.literal('work.observed'),
|
|
153
|
+
payload: z.object({
|
|
154
|
+
observations: z.array(agentWorkObservationSchema).min(1),
|
|
155
|
+
}).strict(),
|
|
156
|
+
}).strict()
|
|
157
|
+
|
|
158
|
+
export const messageStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
159
|
+
type: z.literal('message.started'),
|
|
160
|
+
payload: z.object({
|
|
161
|
+
messageId: z.string().min(1),
|
|
162
|
+
role: agentMessageRoleSchema,
|
|
163
|
+
commandId: z.string().min(1).optional(),
|
|
164
|
+
}).strict(),
|
|
165
|
+
}).strict()
|
|
166
|
+
|
|
167
|
+
export const messageDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
168
|
+
type: z.literal('message.delta'),
|
|
169
|
+
payload: z.object({
|
|
170
|
+
messageId: z.string().min(1),
|
|
171
|
+
role: agentMessageRoleSchema,
|
|
172
|
+
delta: z.string(),
|
|
173
|
+
}).strict(),
|
|
174
|
+
}).strict()
|
|
175
|
+
|
|
176
|
+
export const messageEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
177
|
+
type: z.literal('message.ended'),
|
|
178
|
+
payload: z.object({
|
|
179
|
+
messageId: z.string().min(1),
|
|
180
|
+
role: agentMessageRoleSchema,
|
|
181
|
+
text: z.string().optional(),
|
|
182
|
+
commandId: z.string().min(1).optional(),
|
|
183
|
+
overflow: agentPayloadOverflowSchema.optional(),
|
|
184
|
+
}).strict(),
|
|
185
|
+
}).strict()
|
|
186
|
+
|
|
187
|
+
export const reasoningStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
188
|
+
type: z.literal('reasoning.started'),
|
|
189
|
+
payload: z.object({
|
|
190
|
+
reasoningId: z.string().min(1),
|
|
191
|
+
}).strict(),
|
|
192
|
+
}).strict()
|
|
193
|
+
|
|
194
|
+
export const reasoningSummaryDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
195
|
+
type: z.literal('reasoning.summary.delta'),
|
|
196
|
+
payload: z.object({
|
|
197
|
+
reasoningId: z.string().min(1),
|
|
198
|
+
text: z.string(),
|
|
199
|
+
}).strict(),
|
|
200
|
+
}).strict()
|
|
201
|
+
|
|
202
|
+
export const reasoningEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
203
|
+
type: z.literal('reasoning.ended'),
|
|
204
|
+
payload: z.object({
|
|
205
|
+
reasoningId: z.string().min(1),
|
|
206
|
+
summary: z.string().optional(),
|
|
207
|
+
}).strict(),
|
|
208
|
+
}).strict()
|
|
209
|
+
|
|
210
|
+
export const toolCallStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
211
|
+
type: z.literal('tool.call.started'),
|
|
212
|
+
payload: z.object({
|
|
213
|
+
toolCallId: z.string().min(1),
|
|
214
|
+
toolName: z.string().min(1),
|
|
215
|
+
input: jsonValueSchema.optional(),
|
|
216
|
+
}).strict(),
|
|
217
|
+
}).strict()
|
|
218
|
+
|
|
219
|
+
export const toolOutputDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
220
|
+
type: z.literal('tool.output.delta'),
|
|
221
|
+
payload: z.object({
|
|
222
|
+
toolCallId: z.string().min(1),
|
|
223
|
+
delta: z.string(),
|
|
224
|
+
}).strict(),
|
|
225
|
+
}).strict()
|
|
226
|
+
|
|
227
|
+
export const toolCallCompletedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
228
|
+
type: z.literal('tool.call.completed'),
|
|
229
|
+
payload: z.object({
|
|
230
|
+
toolCallId: z.string().min(1),
|
|
231
|
+
status: agentToolCallStatusSchema,
|
|
232
|
+
output: agentToolResultSchema.optional(),
|
|
233
|
+
error: agentErrorSchema.optional(),
|
|
234
|
+
overflow: agentPayloadOverflowSchema.optional(),
|
|
235
|
+
}).strict(),
|
|
236
|
+
}).strict()
|
|
237
|
+
|
|
238
|
+
export const subagentStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
239
|
+
type: z.literal('subagent.started'),
|
|
240
|
+
payload: subagentRefSchema.extend({
|
|
241
|
+
description: z.string().min(1).optional(),
|
|
242
|
+
}).strict(),
|
|
243
|
+
}).strict()
|
|
244
|
+
|
|
245
|
+
export const subagentProgressAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
246
|
+
type: z.literal('subagent.progress'),
|
|
247
|
+
payload: subagentRefSchema.extend({
|
|
248
|
+
summary: z.string().min(1).optional(),
|
|
249
|
+
lastToolName: z.string().min(1).optional(),
|
|
250
|
+
usage: agentUsageSchema.optional(),
|
|
251
|
+
}).strict(),
|
|
252
|
+
}).strict()
|
|
253
|
+
|
|
254
|
+
export const subagentEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
255
|
+
type: z.literal('subagent.ended'),
|
|
256
|
+
payload: subagentRefSchema.extend({
|
|
257
|
+
status: agentSubagentStatusSchema,
|
|
258
|
+
summary: z.string().optional(),
|
|
259
|
+
usage: agentUsageSchema.optional(),
|
|
260
|
+
error: agentErrorSchema.optional(),
|
|
261
|
+
}).strict(),
|
|
262
|
+
}).strict()
|
|
263
|
+
|
|
264
|
+
export const usageAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
265
|
+
type: z.literal('usage'),
|
|
266
|
+
payload: z.object({
|
|
267
|
+
usage: agentUsageSchema,
|
|
268
|
+
}).strict(),
|
|
269
|
+
}).strict()
|
|
270
|
+
|
|
271
|
+
export const contextCompactionStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
272
|
+
type: z.literal('context.compaction.started'),
|
|
273
|
+
payload: z.object({
|
|
274
|
+
compactionId: z.string().min(1),
|
|
275
|
+
trigger: agentContextCompactionTriggerSchema,
|
|
276
|
+
}).strict(),
|
|
277
|
+
}).strict()
|
|
278
|
+
|
|
279
|
+
export const contextCompactionCompletedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
280
|
+
type: z.literal('context.compaction.completed'),
|
|
281
|
+
payload: z.object({
|
|
282
|
+
compactionId: z.string().min(1),
|
|
283
|
+
trigger: agentContextCompactionTriggerSchema,
|
|
284
|
+
status: agentContextCompactionStatusSchema,
|
|
285
|
+
duration: z.number().int().nonnegative().optional(),
|
|
286
|
+
inputTokensBefore: z.number().int().nonnegative().optional(),
|
|
287
|
+
inputTokensAfter: z.number().int().nonnegative().optional(),
|
|
288
|
+
error: agentErrorSchema.optional(),
|
|
289
|
+
}).strict(),
|
|
290
|
+
}).strict()
|
|
291
|
+
|
|
292
|
+
export const userInputRequestedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
293
|
+
type: z.literal('user-input.requested'),
|
|
294
|
+
payload: z.object({
|
|
295
|
+
requestId: z.string().min(1),
|
|
296
|
+
toolCallId: z.string().min(1),
|
|
297
|
+
prompt: z.string().min(1),
|
|
298
|
+
questions: z.array(agentUserInputQuestionSchema).min(1),
|
|
299
|
+
}).strict(),
|
|
300
|
+
}).strict()
|
|
301
|
+
|
|
302
|
+
export const userInputResolvedAgentEventSchema = agentEventBaseSchema.extend({
|
|
303
|
+
type: z.literal('user-input.resolved'),
|
|
304
|
+
payload: z.object({
|
|
305
|
+
requestId: z.string().min(1),
|
|
306
|
+
requestedTurnId: z.string().min(1),
|
|
307
|
+
toolCallId: z.string().min(1),
|
|
308
|
+
answers: agentUserInputAnswersSchema,
|
|
309
|
+
}).strict(),
|
|
310
|
+
}).strict()
|
|
311
|
+
|
|
312
|
+
export const errorAgentEventSchema = agentEventBaseSchema.extend({
|
|
313
|
+
type: z.literal('error'),
|
|
314
|
+
payload: z.object({
|
|
315
|
+
message: z.string().min(1),
|
|
316
|
+
fatal: z.boolean(),
|
|
317
|
+
source: agentErrorSourceSchema.optional(),
|
|
318
|
+
error: agentErrorSchema.optional(),
|
|
319
|
+
}).strict(),
|
|
320
|
+
}).strict()
|
|
321
|
+
|
|
322
|
+
export const agentEventSchema = z.discriminatedUnion('type', [
|
|
323
|
+
sessionStartedAgentEventSchema,
|
|
324
|
+
sessionConfiguredAgentEventSchema,
|
|
325
|
+
sessionSkillsUpdatedAgentEventSchema,
|
|
326
|
+
sessionStateChangedAgentEventSchema,
|
|
327
|
+
sessionEndedAgentEventSchema,
|
|
328
|
+
turnStartedAgentEventSchema,
|
|
329
|
+
turnEndedAgentEventSchema,
|
|
330
|
+
workObservedAgentEventSchema,
|
|
331
|
+
messageStartedAgentEventSchema,
|
|
332
|
+
messageDeltaAgentEventSchema,
|
|
333
|
+
messageEndedAgentEventSchema,
|
|
334
|
+
reasoningStartedAgentEventSchema,
|
|
335
|
+
reasoningSummaryDeltaAgentEventSchema,
|
|
336
|
+
reasoningEndedAgentEventSchema,
|
|
337
|
+
toolCallStartedAgentEventSchema,
|
|
338
|
+
toolOutputDeltaAgentEventSchema,
|
|
339
|
+
toolCallCompletedAgentEventSchema,
|
|
340
|
+
subagentStartedAgentEventSchema,
|
|
341
|
+
subagentProgressAgentEventSchema,
|
|
342
|
+
subagentEndedAgentEventSchema,
|
|
343
|
+
usageAgentEventSchema,
|
|
344
|
+
contextCompactionStartedAgentEventSchema,
|
|
345
|
+
contextCompactionCompletedAgentEventSchema,
|
|
346
|
+
userInputRequestedAgentEventSchema,
|
|
347
|
+
userInputResolvedAgentEventSchema,
|
|
348
|
+
errorAgentEventSchema,
|
|
349
|
+
])
|
|
350
|
+
|
|
351
|
+
export type AgentMessageRole = z.infer<typeof agentMessageRoleSchema>
|
|
352
|
+
export type AgentSessionEndReason = z.infer<typeof agentSessionEndReasonSchema>
|
|
353
|
+
export type AgentSessionState = z.infer<typeof agentSessionStateSchema>
|
|
354
|
+
export type AgentTurnEndStatus = z.infer<typeof agentTurnEndStatusSchema>
|
|
355
|
+
export type AgentSubagentStatus = z.infer<typeof agentSubagentStatusSchema>
|
|
356
|
+
export type AgentContextCompactionTrigger = z.infer<typeof agentContextCompactionTriggerSchema>
|
|
357
|
+
export type AgentContextCompactionStatus = z.infer<typeof agentContextCompactionStatusSchema>
|
|
358
|
+
export type AgentErrorSource = z.infer<typeof agentErrorSourceSchema>
|
|
359
|
+
export type AgentSkillScope = z.infer<typeof agentSkillScopeSchema>
|
|
360
|
+
export type AgentSkill = z.infer<typeof agentSkillSchema>
|
|
361
|
+
export type AgentEventActorOrigin = z.infer<typeof agentEventActorOriginSchema>
|
|
362
|
+
export type AgentEventActor = z.infer<typeof agentEventActorSchema>
|
|
363
|
+
export type AgentEventBase = z.infer<typeof agentEventBaseSchema>
|
|
364
|
+
export type AgentTurnEventBase = z.infer<typeof agentTurnEventBaseSchema>
|
|
365
|
+
export type SessionStartedAgentEvent = z.infer<typeof sessionStartedAgentEventSchema>
|
|
366
|
+
export type SessionConfiguredAgentEvent = z.infer<typeof sessionConfiguredAgentEventSchema>
|
|
367
|
+
export type SessionSkillsUpdatedAgentEvent = z.infer<typeof sessionSkillsUpdatedAgentEventSchema>
|
|
368
|
+
export type SessionStateChangedAgentEvent = z.infer<typeof sessionStateChangedAgentEventSchema>
|
|
369
|
+
export type SessionEndedAgentEvent = z.infer<typeof sessionEndedAgentEventSchema>
|
|
370
|
+
export type TurnStartedAgentEvent = z.infer<typeof turnStartedAgentEventSchema>
|
|
371
|
+
export type TurnEndedAgentEvent = z.infer<typeof turnEndedAgentEventSchema>
|
|
372
|
+
export type WorkObservedAgentEvent = z.infer<typeof workObservedAgentEventSchema>
|
|
373
|
+
export type MessageStartedAgentEvent = z.infer<typeof messageStartedAgentEventSchema>
|
|
374
|
+
export type MessageDeltaAgentEvent = z.infer<typeof messageDeltaAgentEventSchema>
|
|
375
|
+
export type MessageEndedAgentEvent = z.infer<typeof messageEndedAgentEventSchema>
|
|
376
|
+
export type ReasoningStartedAgentEvent = z.infer<typeof reasoningStartedAgentEventSchema>
|
|
377
|
+
export type ReasoningSummaryDeltaAgentEvent = z.infer<typeof reasoningSummaryDeltaAgentEventSchema>
|
|
378
|
+
export type ReasoningEndedAgentEvent = z.infer<typeof reasoningEndedAgentEventSchema>
|
|
379
|
+
export type ToolCallStartedAgentEvent = z.infer<typeof toolCallStartedAgentEventSchema>
|
|
380
|
+
export type ToolOutputDeltaAgentEvent = z.infer<typeof toolOutputDeltaAgentEventSchema>
|
|
381
|
+
export type ToolCallCompletedAgentEvent = z.infer<typeof toolCallCompletedAgentEventSchema>
|
|
382
|
+
export type SubagentStartedAgentEvent = z.infer<typeof subagentStartedAgentEventSchema>
|
|
383
|
+
export type SubagentProgressAgentEvent = z.infer<typeof subagentProgressAgentEventSchema>
|
|
384
|
+
export type SubagentEndedAgentEvent = z.infer<typeof subagentEndedAgentEventSchema>
|
|
385
|
+
export type UsageAgentEvent = z.infer<typeof usageAgentEventSchema>
|
|
386
|
+
export type ContextCompactionStartedAgentEvent = z.infer<typeof contextCompactionStartedAgentEventSchema>
|
|
387
|
+
export type ContextCompactionCompletedAgentEvent = z.infer<typeof contextCompactionCompletedAgentEventSchema>
|
|
388
|
+
export type UserInputRequestedAgentEvent = z.infer<typeof userInputRequestedAgentEventSchema>
|
|
389
|
+
export type UserInputResolvedAgentEvent = z.infer<typeof userInputResolvedAgentEventSchema>
|
|
390
|
+
export type ErrorAgentEvent = z.infer<typeof errorAgentEventSchema>
|
|
391
|
+
export type AgentEvent = z.infer<typeof agentEventSchema>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ZodType } from 'zod'
|
|
2
|
+
import z from 'zod'
|
|
3
|
+
|
|
4
|
+
export const jsonPrimitiveSchema = z.union([
|
|
5
|
+
z.string(),
|
|
6
|
+
z.number().finite(),
|
|
7
|
+
z.boolean(),
|
|
8
|
+
z.null(),
|
|
9
|
+
])
|
|
10
|
+
|
|
11
|
+
export type JsonPrimitive = z.infer<typeof jsonPrimitiveSchema>
|
|
12
|
+
export interface JsonObject { readonly [key: string]: JsonValue }
|
|
13
|
+
export type JsonArray = readonly JsonValue[]
|
|
14
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray
|
|
15
|
+
|
|
16
|
+
export const jsonValueSchema: ZodType<JsonValue> = z.lazy(() => z.union([
|
|
17
|
+
jsonPrimitiveSchema,
|
|
18
|
+
z.array(jsonValueSchema),
|
|
19
|
+
z.record(z.string(), jsonValueSchema),
|
|
20
|
+
]))
|
|
21
|
+
|
|
22
|
+
export const jsonObjectSchema: ZodType<JsonObject> = z.record(z.string(), jsonValueSchema)
|
|
23
|
+
export const jsonArraySchema: ZodType<JsonArray> = z.array(jsonValueSchema)
|
|
24
|
+
|
|
25
|
+
const utf8Encoder = new TextEncoder()
|
|
26
|
+
|
|
27
|
+
/** UTF-8 byte length of `JSON.stringify(value)`; the unit every wire size cap is expressed in. */
|
|
28
|
+
export function jsonUtf8ByteLength(value: unknown): number {
|
|
29
|
+
return utf8Encoder.encode(JSON.stringify(value)).byteLength
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
import { claudeModelIdSchema, codexModelIdSchema } from './agent-model'
|
|
3
|
+
|
|
4
|
+
const metadataShape = {
|
|
5
|
+
sessionId: z.string().min(1),
|
|
6
|
+
providerSessionId: z.string().min(1),
|
|
7
|
+
cwd: z.string().min(1),
|
|
8
|
+
transcriptPath: z.string().min(1),
|
|
9
|
+
} as const
|
|
10
|
+
|
|
11
|
+
export const codexAgentRunMetadataSchema = z.object({
|
|
12
|
+
provider: z.literal('codex'),
|
|
13
|
+
...metadataShape,
|
|
14
|
+
model: codexModelIdSchema.optional(),
|
|
15
|
+
}).strict()
|
|
16
|
+
|
|
17
|
+
export const claudeAgentRunMetadataSchema = z.object({
|
|
18
|
+
provider: z.literal('claude'),
|
|
19
|
+
...metadataShape,
|
|
20
|
+
model: claudeModelIdSchema.optional(),
|
|
21
|
+
}).strict()
|
|
22
|
+
|
|
23
|
+
export const agentRunMetadataSchema = z.discriminatedUnion('provider', [
|
|
24
|
+
codexAgentRunMetadataSchema,
|
|
25
|
+
claudeAgentRunMetadataSchema,
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
export type CodexAgentRunMetadata = z.infer<typeof codexAgentRunMetadataSchema>
|
|
29
|
+
export type ClaudeAgentRunMetadata = z.infer<typeof claudeAgentRunMetadataSchema>
|
|
30
|
+
export type AgentRunMetadata = z.infer<typeof agentRunMetadataSchema>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { AgentProviderId } from './agent-provider'
|
|
2
|
+
import z from 'zod'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Known model catalogs. They document what each harness has been exercised
|
|
6
|
+
* with and drive presentation helpers, but they are deliberately NOT the wire
|
|
7
|
+
* contract: a new model must be usable by re-provisioning nothing, so every
|
|
8
|
+
* schema that carries a model id accepts any non-empty string.
|
|
9
|
+
*/
|
|
10
|
+
export const codexModelIds = [
|
|
11
|
+
'gpt-5.6-sol',
|
|
12
|
+
'gpt-5.5',
|
|
13
|
+
'gpt-5.4',
|
|
14
|
+
'gpt-5.4-mini',
|
|
15
|
+
'gpt-5.3-codex',
|
|
16
|
+
'gpt-5.2',
|
|
17
|
+
] as const
|
|
18
|
+
|
|
19
|
+
export const claudeModelIds = [
|
|
20
|
+
'sonnet',
|
|
21
|
+
'claude-opus-4-8',
|
|
22
|
+
'opus',
|
|
23
|
+
'haiku',
|
|
24
|
+
'claude-opus-4-7',
|
|
25
|
+
'claude-mythos-preview',
|
|
26
|
+
'claude-opus-4-6',
|
|
27
|
+
'claude-sonnet-4-6',
|
|
28
|
+
'claude-haiku-4-5',
|
|
29
|
+
'claude-haiku-4-5-20251001',
|
|
30
|
+
'claude-opus-4-5',
|
|
31
|
+
'claude-opus-4-5-20251101',
|
|
32
|
+
'claude-sonnet-4-5',
|
|
33
|
+
'claude-sonnet-4-5-20250929',
|
|
34
|
+
'claude-opus-4-1',
|
|
35
|
+
'claude-opus-4-1-20250805',
|
|
36
|
+
'claude-opus-4-0',
|
|
37
|
+
'claude-opus-4-20250514',
|
|
38
|
+
'claude-sonnet-4-0',
|
|
39
|
+
'claude-sonnet-4-20250514',
|
|
40
|
+
'claude-3-haiku-20240307',
|
|
41
|
+
] as const
|
|
42
|
+
|
|
43
|
+
export const knownCodexModelIdSchema = z.enum(codexModelIds)
|
|
44
|
+
export const knownClaudeModelIdSchema = z.enum(claudeModelIds)
|
|
45
|
+
export const knownAgentModelIdSchema = z.union([knownCodexModelIdSchema, knownClaudeModelIdSchema])
|
|
46
|
+
|
|
47
|
+
export const agentModelIdSchema = z.string().min(1).max(256)
|
|
48
|
+
export const codexModelIdSchema = agentModelIdSchema
|
|
49
|
+
export const claudeModelIdSchema = agentModelIdSchema
|
|
50
|
+
|
|
51
|
+
export type KnownCodexModelId = typeof codexModelIds[number]
|
|
52
|
+
export type KnownClaudeModelId = typeof claudeModelIds[number]
|
|
53
|
+
export type KnownAgentModelId = KnownCodexModelId | KnownClaudeModelId
|
|
54
|
+
|
|
55
|
+
export type CodexModelId = string
|
|
56
|
+
export type ClaudeModelId = string
|
|
57
|
+
|
|
58
|
+
export interface AgentModelIdByProvider {
|
|
59
|
+
codex: CodexModelId
|
|
60
|
+
claude: ClaudeModelId
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export type AgentModelId<Provider extends AgentProviderId = AgentProviderId> = AgentModelIdByProvider[Provider]
|
|
64
|
+
|
|
65
|
+
export function isKnownModelId(provider: AgentProviderId, modelId: string): modelId is KnownAgentModelId {
|
|
66
|
+
const catalog: readonly string[] = provider === 'codex' ? codexModelIds : claudeModelIds
|
|
67
|
+
return catalog.includes(modelId)
|
|
68
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reference to a payload that was too large to travel inline on the wire.
|
|
5
|
+
*
|
|
6
|
+
* The producer keeps a bounded head inline (for example the first bytes of a
|
|
7
|
+
* tool result) and stores the complete JSON-encoded value out of band. `ref` is
|
|
8
|
+
* opaque to agent-core: the host that provided the `LargePayloadStore` port is
|
|
9
|
+
* the only party that can resolve it (agent-api uses `vault://` references).
|
|
10
|
+
*/
|
|
11
|
+
export const agentPayloadOverflowSchema = z.object({
|
|
12
|
+
ref: z.string().min(1).max(2048),
|
|
13
|
+
byteLength: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
14
|
+
sha256: z.string().regex(/^[0-9a-f]{64}$/u),
|
|
15
|
+
encoding: z.literal('json'),
|
|
16
|
+
}).strict()
|
|
17
|
+
|
|
18
|
+
export type AgentPayloadOverflow = z.infer<typeof agentPayloadOverflowSchema>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { AgentReasoningEffort } from './agent-command'
|
|
2
|
+
import type { KnownCodexModelId } from './agent-model'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Display metadata for protocol identifiers, kept beside the registries so a model
|
|
6
|
+
* or effort added to the wire unions cannot ship without its presentation: the
|
|
7
|
+
* `Record` types below fail to compile until every identifier is covered.
|
|
8
|
+
*
|
|
9
|
+
* Copy and figures mirror the bundled Codex CLI catalog
|
|
10
|
+
* (`codex-rs/models-manager/models.json` at the pinned `@openai/codex@0.145.0`).
|
|
11
|
+
* Update this file together with the pinned CLI version. Upstream defines efforts
|
|
12
|
+
* by description only — no per-effort reasoning-token budget exists, so none is
|
|
13
|
+
* invented here.
|
|
14
|
+
*
|
|
15
|
+
* This is UI copy and relative sizing only. Billing, pricing, and cost estimation
|
|
16
|
+
* stay out of protocol (docs/agents-protocol.md) — `relativeCost` is a 1–5 picker
|
|
17
|
+
* weight, not a price.
|
|
18
|
+
*/
|
|
19
|
+
export interface AgentModelPresentation {
|
|
20
|
+
label: string
|
|
21
|
+
description: string
|
|
22
|
+
/** Relative cost weight for pickers (1 = cheapest, 5 = most expensive). Not a price. */
|
|
23
|
+
relativeCost: 1 | 2 | 3 | 4 | 5
|
|
24
|
+
maxInputTokens: number
|
|
25
|
+
maxOutputTokens?: number
|
|
26
|
+
isMultiModal: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const CODEX_CONTEXT_WINDOW = 272_000
|
|
30
|
+
|
|
31
|
+
export const codexModelPresentation: Record<KnownCodexModelId, AgentModelPresentation> = {
|
|
32
|
+
'gpt-5.6-sol': {
|
|
33
|
+
label: 'GPT-5.6-Sol',
|
|
34
|
+
description: 'Latest frontier agentic coding model.',
|
|
35
|
+
relativeCost: 5,
|
|
36
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
37
|
+
isMultiModal: true,
|
|
38
|
+
},
|
|
39
|
+
'gpt-5.5': {
|
|
40
|
+
label: 'GPT-5.5',
|
|
41
|
+
description: 'Frontier model for complex coding, research, and real-world work.',
|
|
42
|
+
relativeCost: 4,
|
|
43
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
44
|
+
isMultiModal: true,
|
|
45
|
+
},
|
|
46
|
+
'gpt-5.4': {
|
|
47
|
+
label: 'GPT-5.4',
|
|
48
|
+
description: 'Strong model for everyday coding.',
|
|
49
|
+
relativeCost: 3,
|
|
50
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
51
|
+
isMultiModal: true,
|
|
52
|
+
},
|
|
53
|
+
'gpt-5.4-mini': {
|
|
54
|
+
label: 'GPT-5.4-Mini',
|
|
55
|
+
description: 'Small, fast, and cost-efficient model for simpler coding tasks.',
|
|
56
|
+
relativeCost: 2,
|
|
57
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
58
|
+
isMultiModal: true,
|
|
59
|
+
},
|
|
60
|
+
/* Absent from the 0.145.0 upstream catalog; retained in our registry, so the
|
|
61
|
+
copy below is ours. */
|
|
62
|
+
'gpt-5.3-codex': {
|
|
63
|
+
label: 'GPT-5.3-Codex',
|
|
64
|
+
description: 'Code-tuned model for focused engineering tasks.',
|
|
65
|
+
relativeCost: 3,
|
|
66
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
67
|
+
isMultiModal: true,
|
|
68
|
+
},
|
|
69
|
+
'gpt-5.2': {
|
|
70
|
+
label: 'GPT-5.2',
|
|
71
|
+
description: 'Optimized for professional work and long-running agents.',
|
|
72
|
+
relativeCost: 3,
|
|
73
|
+
maxInputTokens: CODEX_CONTEXT_WINDOW,
|
|
74
|
+
isMultiModal: true,
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface AgentReasoningEffortPresentation {
|
|
79
|
+
label: string
|
|
80
|
+
description: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Effort descriptions are upstream's own wording (gpt-5.6 catalog entries). */
|
|
84
|
+
export const agentReasoningEffortPresentation: Record<AgentReasoningEffort, AgentReasoningEffortPresentation> = {
|
|
85
|
+
low: { label: 'Low', description: 'Fast responses with lighter reasoning' },
|
|
86
|
+
medium: { label: 'Medium', description: 'Balances speed and reasoning depth for everyday tasks' },
|
|
87
|
+
high: { label: 'High', description: 'Greater reasoning depth for complex problems' },
|
|
88
|
+
xhigh: { label: 'Extra high', description: 'Extra high reasoning depth for complex problems' },
|
|
89
|
+
max: { label: 'Max', description: 'Maximum reasoning depth for the hardest problems' },
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The efforts products offer to users. `max` stays a valid wire value for
|
|
94
|
+
* compatibility but is not selectable anywhere.
|
|
95
|
+
*/
|
|
96
|
+
export const selectableAgentReasoningEfforts = ['low', 'medium', 'high', 'xhigh'] as const satisfies readonly AgentReasoningEffort[]
|
|
97
|
+
|
|
98
|
+
export type SelectableAgentReasoningEffort = typeof selectableAgentReasoningEfforts[number]
|