@meistrari/agent-core 0.2.0-experimental.1 → 0.2.0-experimental.2
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 +50 -0
- package/docs/consumer-capability-matrix.md +374 -0
- package/package.json +17 -10
- package/scripts/generate-codex-protocol.ts +711 -0
- package/src/agents/agent-operation.ts +8 -0
- package/src/agents/agent-provider.ts +3 -0
- package/src/agents/agent-run.ts +14 -2
- package/src/agents/agent-runtime-error.ts +28 -0
- package/src/agents/agent-session-events.ts +33 -0
- package/src/agents/agent-tool-runner.ts +12 -11
- package/src/agents/agent-tool.ts +12 -4
- package/src/agents/author-context.ts +1 -1
- package/src/agents/claude/claude-auth.ts +40 -0
- package/src/agents/claude/claude-browser-turn-metadata.ts +70 -0
- package/src/agents/claude/claude-code-process.ts +98 -0
- package/src/agents/claude/claude-command-mapper.ts +63 -3
- package/src/agents/claude/claude-desktop.ts +55 -0
- package/src/agents/claude/claude-event-mapper.ts +864 -135
- package/src/agents/claude/claude-file-change.ts +128 -0
- package/src/agents/claude/claude-provider.ts +344 -29
- package/src/agents/claude/claude-run.ts +893 -130
- package/src/agents/claude/claude-selected-repository-instructions.ts +91 -0
- package/src/agents/claude/claude-skill-catalog.ts +75 -0
- package/src/agents/claude/claude-steered-notifications.ts +180 -0
- package/src/agents/claude/claude-tool-mapper.ts +81 -2
- package/src/agents/claude/claude-workspace-skills.ts +87 -0
- package/src/agents/claude/index.ts +2 -0
- package/src/agents/codex/codex-auth-mapper.ts +27 -0
- package/src/agents/codex/codex-auth.ts +19 -0
- package/src/agents/codex/codex-browser-auth-broker.ts +320 -0
- package/src/agents/codex/codex-browser-auth-status.ts +55 -0
- package/src/agents/codex/codex-command-mapper.ts +38 -3
- package/src/agents/codex/codex-event-mapper.ts +375 -64
- package/src/agents/codex/codex-json-rpc-client.ts +66 -21
- package/src/agents/codex/codex-provider.ts +118 -236
- package/src/agents/codex/codex-run-auth.ts +113 -0
- package/src/agents/codex/codex-run.ts +423 -53
- package/src/agents/codex/codex-tool-mapper.ts +2 -2
- package/src/agents/codex/codex.errors.ts +8 -0
- package/src/agents/codex/generated/meta.gen.ts +144 -6
- package/src/agents/codex/generated/namespaces.gen.ts +92 -3
- package/src/agents/codex/generated/schema.gen.ts +24698 -15638
- package/src/agents/codex/lazy-codex-run-auth.ts +47 -0
- package/src/agents/index.ts +5 -0
- package/src/agents/input-attachment-preparation.ts +13 -0
- package/src/agents/mcp-tool-content.ts +82 -0
- package/src/agents/model-rebinding-run.ts +14 -3
- package/src/agents/selected-repository-instructions.ts +202 -0
- package/src/agents/session-context.ts +41 -0
- package/src/agents/subscription-token-refresh.ts +73 -0
- package/src/agents/user-input-request.ts +19 -20
- package/src/errors/index.ts +1 -1
- package/src/errors/validation-error.ts +6 -0
- package/src/protocol/agent-catalog.ts +159 -0
- package/src/protocol/agent-command.ts +52 -7
- package/src/protocol/agent-content.ts +36 -16
- package/src/protocol/agent-event.ts +210 -73
- package/src/protocol/agent-identity.ts +29 -0
- package/src/protocol/agent-json.ts +122 -8
- package/src/protocol/agent-metadata.ts +2 -2
- package/src/protocol/agent-model.ts +13 -1
- package/src/protocol/agent-notification.ts +110 -0
- package/src/protocol/agent-presentation.ts +71 -20
- package/src/protocol/agent-tool.ts +66 -10
- package/src/protocol/agent-usage.ts +3 -1
- package/src/protocol/agent-user-input.ts +4 -4
- package/src/protocol/agent-work.ts +12 -10
- package/src/protocol/index.ts +2 -0
- package/src/protocol/rejected-keys.ts +11 -0
- package/src/provenance.gen.ts +3 -3
- package/src/supervisor-protocol/agent-event-wrapper.ts +30 -0
|
@@ -7,6 +7,7 @@ import { agentToolCallStatusSchema, agentToolResultSchema } from './agent-tool'
|
|
|
7
7
|
import { agentUsageAccountingSchema, agentUsageSchema } from './agent-usage'
|
|
8
8
|
import { agentUserInputAnswersSchema, agentUserInputQuestionSchema } from './agent-user-input'
|
|
9
9
|
import { agentWorkObservationSchema } from './agent-work'
|
|
10
|
+
import { objectRejectingKeys } from './rejected-keys'
|
|
10
11
|
|
|
11
12
|
export interface AgentError {
|
|
12
13
|
message: string
|
|
@@ -17,12 +18,12 @@ export interface AgentError {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export const agentErrorSchema: z.ZodType<AgentError> = z.object({
|
|
20
|
-
message: z.string()
|
|
21
|
+
message: z.string(),
|
|
21
22
|
code: z.string().min(1).optional(),
|
|
22
23
|
name: z.string().min(1).optional(),
|
|
23
24
|
stack: z.string().min(1).optional(),
|
|
24
25
|
cause: z.lazy(() => agentErrorSchema).optional(),
|
|
25
|
-
})
|
|
26
|
+
})
|
|
26
27
|
|
|
27
28
|
export const agentMessageRoleSchema = z.enum(['user', 'assistant', 'system'])
|
|
28
29
|
export const agentSessionEndReasonSchema = z.enum(['completed', 'stopped', 'interrupted', 'failed'])
|
|
@@ -31,41 +32,53 @@ export const agentTurnEndStatusSchema = z.enum(['completed', 'failed', 'cancelle
|
|
|
31
32
|
export const agentSubagentStatusSchema = z.enum(['completed', 'failed', 'cancelled'])
|
|
32
33
|
export const agentContextCompactionTriggerSchema = z.enum(['manual', 'auto', 'unknown'])
|
|
33
34
|
export const agentContextCompactionStatusSchema = z.enum(['completed', 'failed'])
|
|
35
|
+
export const agentContextCompactionRequestResultSchema = z.discriminatedUnion('status', [
|
|
36
|
+
z.object({ status: z.literal('completed') }),
|
|
37
|
+
z.object({ status: z.literal('no_op'), reason: z.string() }),
|
|
38
|
+
z.object({ status: z.literal('failed'), error: agentErrorSchema }),
|
|
39
|
+
z.object({ status: z.literal('unknown') }),
|
|
40
|
+
])
|
|
34
41
|
export const agentErrorSourceSchema = z.enum(['provider', 'runtime', 'transport', 'unknown'])
|
|
35
42
|
export const agentSkillScopeSchema = z.enum(['user', 'repository', 'system', 'admin'])
|
|
36
43
|
|
|
37
|
-
export const agentSkillSchema = z.
|
|
44
|
+
export const agentSkillSchema = z.strictObject({
|
|
38
45
|
id: z.string().min(1),
|
|
39
46
|
name: z.string().min(1),
|
|
40
47
|
description: z.string().min(1),
|
|
41
48
|
scope: agentSkillScopeSchema,
|
|
42
|
-
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const wireAgentSkillSchema = agentSkillSchema.strip()
|
|
43
52
|
|
|
44
|
-
|
|
53
|
+
// Provider turn identity never crosses this boundary; only the canonical turnId does.
|
|
54
|
+
export const agentEventBaseSchema = objectRejectingKeys({
|
|
45
55
|
eventId: z.string().min(1),
|
|
46
56
|
provider: agentProviderIdSchema,
|
|
47
57
|
sessionId: z.string().min(1),
|
|
48
58
|
providerSessionId: z.string().min(1),
|
|
49
59
|
timestamp: z.string().datetime(),
|
|
50
60
|
sequence: z.number().int().nonnegative(),
|
|
51
|
-
})
|
|
61
|
+
}, ['providerTurnId'])
|
|
62
|
+
|
|
63
|
+
// Session-scoped events are never turn- or actor-attributed; those keys are rejected, not stripped.
|
|
64
|
+
const agentSessionEventBaseSchema = objectRejectingKeys(agentEventBaseSchema.shape, ['turnId', 'actor'])
|
|
52
65
|
|
|
53
66
|
export const agentEventActorOriginSchema = z.discriminatedUnion('type', [
|
|
54
67
|
z.object({
|
|
55
68
|
type: z.literal('tool_call'),
|
|
56
69
|
toolCallId: z.string().min(1),
|
|
57
|
-
})
|
|
70
|
+
}),
|
|
58
71
|
z.object({
|
|
59
72
|
type: z.literal('provider_task'),
|
|
60
73
|
taskId: z.string().min(1),
|
|
61
|
-
})
|
|
74
|
+
}),
|
|
62
75
|
])
|
|
63
76
|
|
|
64
77
|
export const agentEventActorSchema = z.discriminatedUnion('type', [
|
|
65
78
|
z.object({
|
|
66
79
|
type: z.literal('main'),
|
|
67
80
|
actorId: z.literal('main'),
|
|
68
|
-
})
|
|
81
|
+
}),
|
|
69
82
|
z.object({
|
|
70
83
|
type: z.literal('subagent'),
|
|
71
84
|
actorId: z.string().min(1),
|
|
@@ -74,7 +87,7 @@ export const agentEventActorSchema = z.discriminatedUnion('type', [
|
|
|
74
87
|
origin: agentEventActorOriginSchema,
|
|
75
88
|
parentToolCallId: z.string().min(1).optional(),
|
|
76
89
|
name: z.string().min(1).optional(),
|
|
77
|
-
})
|
|
90
|
+
}),
|
|
78
91
|
])
|
|
79
92
|
|
|
80
93
|
const subagentRefSchema = z.object({
|
|
@@ -84,19 +97,19 @@ const subagentRefSchema = z.object({
|
|
|
84
97
|
origin: agentEventActorOriginSchema,
|
|
85
98
|
parentToolCallId: z.string().min(1).optional(),
|
|
86
99
|
name: z.string().min(1).optional(),
|
|
87
|
-
})
|
|
100
|
+
})
|
|
88
101
|
|
|
89
102
|
export const agentTurnEventBaseSchema = agentEventBaseSchema.extend({
|
|
90
103
|
turnId: z.string().min(1),
|
|
91
104
|
actor: agentEventActorSchema,
|
|
92
|
-
})
|
|
105
|
+
})
|
|
93
106
|
|
|
94
|
-
export const sessionStartedAgentEventSchema =
|
|
107
|
+
export const sessionStartedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
95
108
|
type: z.literal('session.started'),
|
|
96
109
|
payload: agentRunMetadataSchema,
|
|
97
|
-
})
|
|
110
|
+
})
|
|
98
111
|
|
|
99
|
-
export const sessionConfiguredAgentEventSchema =
|
|
112
|
+
export const sessionConfiguredAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
100
113
|
type: z.literal('session.configured'),
|
|
101
114
|
payload: z.object({
|
|
102
115
|
model: z.string().min(1),
|
|
@@ -105,55 +118,84 @@ export const sessionConfiguredAgentEventSchema = agentEventBaseSchema.extend({
|
|
|
105
118
|
tools: z.array(z.string().min(1)),
|
|
106
119
|
reasoningEffort: z.string().min(1).optional(),
|
|
107
120
|
environment: z.record(z.string().min(1), z.literal('[REDACTED]')),
|
|
108
|
-
})
|
|
109
|
-
})
|
|
121
|
+
}),
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
export const agentSettingsAppliesFromSchema = z.enum(['current_turn', 'next_turn'])
|
|
125
|
+
|
|
126
|
+
export const currentTurnUnavailableReasonMaxLength = 300
|
|
110
127
|
|
|
111
|
-
|
|
128
|
+
// The session's current model and effort after a prompt changed them. `appliesFrom` states whether the
|
|
129
|
+
// turn that handles that prompt runs on them. `current_turn`: it does, whether a steer switched the
|
|
130
|
+
// running turn or the prompt started its own turn; `turnId` is that turn when the provider knows it.
|
|
131
|
+
// `next_turn`: a steer could not switch the running turn, so the settings apply from the following turn.
|
|
132
|
+
// `currentTurnUnavailableReason` is the provider's own diagnostic text, truncated, for why the running
|
|
133
|
+
// turn could not change; only with `next_turn`, and only when the provider gave one.
|
|
134
|
+
export const sessionSettingsChangedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
135
|
+
type: z.literal('session.settings.changed'),
|
|
136
|
+
payload: z.object({
|
|
137
|
+
model: z.string().min(1),
|
|
138
|
+
reasoningEffort: z.string().min(1).optional(),
|
|
139
|
+
commandId: z.string().min(1),
|
|
140
|
+
turnId: z.string().min(1).optional(),
|
|
141
|
+
appliesFrom: agentSettingsAppliesFromSchema,
|
|
142
|
+
currentTurnUnavailableReason: z.string().min(1).max(currentTurnUnavailableReasonMaxLength).optional(),
|
|
143
|
+
}),
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
export const sessionSkillsUpdatedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
112
147
|
type: z.literal('session.skills.updated'),
|
|
113
148
|
payload: z.object({
|
|
114
|
-
skills: z.array(
|
|
115
|
-
})
|
|
116
|
-
})
|
|
149
|
+
skills: z.array(wireAgentSkillSchema),
|
|
150
|
+
}),
|
|
151
|
+
})
|
|
117
152
|
|
|
118
|
-
export const sessionStateChangedAgentEventSchema =
|
|
153
|
+
export const sessionStateChangedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
119
154
|
type: z.literal('session.state.changed'),
|
|
120
155
|
payload: z.object({
|
|
121
156
|
state: agentSessionStateSchema,
|
|
122
157
|
error: agentErrorSchema.optional(),
|
|
123
|
-
})
|
|
124
|
-
})
|
|
158
|
+
}),
|
|
159
|
+
})
|
|
125
160
|
|
|
126
|
-
export const sessionEndedAgentEventSchema =
|
|
161
|
+
export const sessionEndedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
127
162
|
type: z.literal('session.ended'),
|
|
128
163
|
payload: z.object({
|
|
129
164
|
reason: agentSessionEndReasonSchema,
|
|
130
165
|
exitCode: z.number().int().nullable().optional(),
|
|
131
166
|
signal: z.string().min(1).nullable().optional(),
|
|
132
167
|
error: agentErrorSchema.optional(),
|
|
133
|
-
})
|
|
134
|
-
})
|
|
168
|
+
}),
|
|
169
|
+
})
|
|
135
170
|
|
|
136
171
|
export const turnStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
137
172
|
type: z.literal('turn.started'),
|
|
138
|
-
payload: z.object({ commandId: z.string().min(1).optional() })
|
|
139
|
-
})
|
|
173
|
+
payload: z.object({ commandId: z.string().min(1).optional() }),
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
// Provider-confirmed input consumption; distinct from acceptance receipts.
|
|
177
|
+
export const promptTurnCorrelatedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
178
|
+
type: z.literal('prompt.turn-correlated'),
|
|
179
|
+
payload: z.object({ commandId: z.string().min(1), turnId: z.string().min(1) }),
|
|
180
|
+
})
|
|
140
181
|
|
|
141
182
|
export const turnEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
142
183
|
type: z.literal('turn.ended'),
|
|
143
|
-
|
|
184
|
+
// Usage is reported only through the dedicated `usage` event.
|
|
185
|
+
payload: objectRejectingKeys({
|
|
144
186
|
status: agentTurnEndStatusSchema,
|
|
145
187
|
reason: z.string().min(1).optional(),
|
|
146
188
|
error: agentErrorSchema.optional(),
|
|
147
189
|
duration: z.number().int().nonnegative().optional(),
|
|
148
|
-
})
|
|
149
|
-
})
|
|
190
|
+
}, ['usage']),
|
|
191
|
+
})
|
|
150
192
|
|
|
151
193
|
export const workObservedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
152
194
|
type: z.literal('work.observed'),
|
|
153
195
|
payload: z.object({
|
|
154
196
|
observations: z.array(agentWorkObservationSchema).min(1),
|
|
155
|
-
})
|
|
156
|
-
})
|
|
197
|
+
}),
|
|
198
|
+
})
|
|
157
199
|
|
|
158
200
|
export const messageStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
159
201
|
type: z.literal('message.started'),
|
|
@@ -161,17 +203,18 @@ export const messageStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
|
161
203
|
messageId: z.string().min(1),
|
|
162
204
|
role: agentMessageRoleSchema,
|
|
163
205
|
commandId: z.string().min(1).optional(),
|
|
164
|
-
})
|
|
165
|
-
})
|
|
206
|
+
}),
|
|
207
|
+
})
|
|
166
208
|
|
|
167
209
|
export const messageDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
168
210
|
type: z.literal('message.delta'),
|
|
169
|
-
|
|
211
|
+
// Command association belongs to message.started/ended only.
|
|
212
|
+
payload: objectRejectingKeys({
|
|
170
213
|
messageId: z.string().min(1),
|
|
171
214
|
role: agentMessageRoleSchema,
|
|
172
215
|
delta: z.string(),
|
|
173
|
-
})
|
|
174
|
-
})
|
|
216
|
+
}, ['commandId']),
|
|
217
|
+
})
|
|
175
218
|
|
|
176
219
|
export const messageEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
177
220
|
type: z.literal('message.ended'),
|
|
@@ -181,31 +224,31 @@ export const messageEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
|
181
224
|
text: z.string().optional(),
|
|
182
225
|
commandId: z.string().min(1).optional(),
|
|
183
226
|
overflow: agentPayloadOverflowSchema.optional(),
|
|
184
|
-
})
|
|
185
|
-
})
|
|
227
|
+
}),
|
|
228
|
+
})
|
|
186
229
|
|
|
187
230
|
export const reasoningStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
188
231
|
type: z.literal('reasoning.started'),
|
|
189
232
|
payload: z.object({
|
|
190
233
|
reasoningId: z.string().min(1),
|
|
191
|
-
})
|
|
192
|
-
})
|
|
234
|
+
}),
|
|
235
|
+
})
|
|
193
236
|
|
|
194
237
|
export const reasoningSummaryDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
195
238
|
type: z.literal('reasoning.summary.delta'),
|
|
196
239
|
payload: z.object({
|
|
197
240
|
reasoningId: z.string().min(1),
|
|
198
241
|
text: z.string(),
|
|
199
|
-
})
|
|
200
|
-
})
|
|
242
|
+
}),
|
|
243
|
+
})
|
|
201
244
|
|
|
202
245
|
export const reasoningEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
203
246
|
type: z.literal('reasoning.ended'),
|
|
204
247
|
payload: z.object({
|
|
205
248
|
reasoningId: z.string().min(1),
|
|
206
249
|
summary: z.string().optional(),
|
|
207
|
-
})
|
|
208
|
-
})
|
|
250
|
+
}),
|
|
251
|
+
})
|
|
209
252
|
|
|
210
253
|
export const toolCallStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
211
254
|
type: z.literal('tool.call.started'),
|
|
@@ -213,34 +256,43 @@ export const toolCallStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
|
213
256
|
toolCallId: z.string().min(1),
|
|
214
257
|
toolName: z.string().min(1),
|
|
215
258
|
input: jsonValueSchema.optional(),
|
|
216
|
-
})
|
|
217
|
-
})
|
|
259
|
+
}),
|
|
260
|
+
})
|
|
218
261
|
|
|
219
262
|
export const toolOutputDeltaAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
220
263
|
type: z.literal('tool.output.delta'),
|
|
221
264
|
payload: z.object({
|
|
222
265
|
toolCallId: z.string().min(1),
|
|
223
266
|
delta: z.string(),
|
|
224
|
-
})
|
|
225
|
-
})
|
|
267
|
+
}),
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
export const toolOutputUpdatedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
271
|
+
type: z.literal('tool.output.updated'),
|
|
272
|
+
payload: z.object({
|
|
273
|
+
toolCallId: z.string().min(1),
|
|
274
|
+
output: agentToolResultSchema,
|
|
275
|
+
}),
|
|
276
|
+
})
|
|
226
277
|
|
|
227
278
|
export const toolCallCompletedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
228
279
|
type: z.literal('tool.call.completed'),
|
|
229
280
|
payload: z.object({
|
|
230
281
|
toolCallId: z.string().min(1),
|
|
282
|
+
toolName: z.string().min(1).optional(),
|
|
231
283
|
status: agentToolCallStatusSchema,
|
|
232
284
|
output: agentToolResultSchema.optional(),
|
|
233
285
|
error: agentErrorSchema.optional(),
|
|
234
286
|
overflow: agentPayloadOverflowSchema.optional(),
|
|
235
|
-
})
|
|
236
|
-
})
|
|
287
|
+
}),
|
|
288
|
+
})
|
|
237
289
|
|
|
238
290
|
export const subagentStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
239
291
|
type: z.literal('subagent.started'),
|
|
240
292
|
payload: subagentRefSchema.extend({
|
|
241
293
|
description: z.string().min(1).optional(),
|
|
242
|
-
})
|
|
243
|
-
})
|
|
294
|
+
}),
|
|
295
|
+
})
|
|
244
296
|
|
|
245
297
|
export const subagentProgressAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
246
298
|
type: z.literal('subagent.progress'),
|
|
@@ -248,8 +300,8 @@ export const subagentProgressAgentEventSchema = agentTurnEventBaseSchema.extend(
|
|
|
248
300
|
summary: z.string().min(1).optional(),
|
|
249
301
|
lastToolName: z.string().min(1).optional(),
|
|
250
302
|
usage: agentUsageSchema.optional(),
|
|
251
|
-
})
|
|
252
|
-
})
|
|
303
|
+
}),
|
|
304
|
+
})
|
|
253
305
|
|
|
254
306
|
export const subagentEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
255
307
|
type: z.literal('subagent.ended'),
|
|
@@ -258,24 +310,84 @@ export const subagentEndedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
|
258
310
|
summary: z.string().optional(),
|
|
259
311
|
usage: agentUsageSchema.optional(),
|
|
260
312
|
error: agentErrorSchema.optional(),
|
|
261
|
-
})
|
|
262
|
-
})
|
|
313
|
+
}),
|
|
314
|
+
})
|
|
263
315
|
|
|
264
316
|
export const usageAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
265
317
|
type: z.literal('usage'),
|
|
266
318
|
payload: z.object({
|
|
267
319
|
usage: agentUsageSchema,
|
|
268
320
|
accounting: agentUsageAccountingSchema.optional(),
|
|
269
|
-
})
|
|
270
|
-
})
|
|
321
|
+
}),
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
export type AgentContextWindow
|
|
325
|
+
= | { status: 'unknown' }
|
|
326
|
+
| { status: 'known', capacityTokens: number, remainingPercent: number }
|
|
327
|
+
|
|
328
|
+
export type AgentContextSnapshot
|
|
329
|
+
= | { status: 'unknown' }
|
|
330
|
+
| { status: 'observed', usedTokens: number, window: AgentContextWindow }
|
|
331
|
+
|
|
332
|
+
const knownAgentContextWindowShape = {
|
|
333
|
+
status: z.literal('known'),
|
|
334
|
+
capacityTokens: z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
335
|
+
remainingPercent: z.number().int().min(0).max(100),
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export const agentContextWindowSchema: z.ZodType<AgentContextWindow> = z.discriminatedUnion('status', [
|
|
339
|
+
z.strictObject({ status: z.literal('unknown') }),
|
|
340
|
+
z.strictObject(knownAgentContextWindowShape),
|
|
341
|
+
])
|
|
342
|
+
|
|
343
|
+
const wireAgentContextWindowSchema: z.ZodType<AgentContextWindow> = z.discriminatedUnion('status', [
|
|
344
|
+
z.object({
|
|
345
|
+
status: z.literal('unknown'),
|
|
346
|
+
capacityTokens: z.never().optional(),
|
|
347
|
+
remainingPercent: z.never().optional(),
|
|
348
|
+
}),
|
|
349
|
+
z.object(knownAgentContextWindowShape),
|
|
350
|
+
])
|
|
351
|
+
|
|
352
|
+
export const agentContextSnapshotSchema: z.ZodType<AgentContextSnapshot> = z.discriminatedUnion('status', [
|
|
353
|
+
z.strictObject({ status: z.literal('unknown') }),
|
|
354
|
+
z.strictObject({
|
|
355
|
+
status: z.literal('observed'),
|
|
356
|
+
usedTokens: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
357
|
+
window: agentContextWindowSchema,
|
|
358
|
+
}),
|
|
359
|
+
])
|
|
360
|
+
|
|
361
|
+
const wireAgentContextSnapshotSchema: z.ZodType<AgentContextSnapshot> = z.discriminatedUnion('status', [
|
|
362
|
+
z.object({
|
|
363
|
+
status: z.literal('unknown'),
|
|
364
|
+
usedTokens: z.never().optional(),
|
|
365
|
+
window: z.never().optional(),
|
|
366
|
+
providerModel: z.never().optional(),
|
|
367
|
+
}),
|
|
368
|
+
z.object({
|
|
369
|
+
status: z.literal('observed'),
|
|
370
|
+
usedTokens: z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER),
|
|
371
|
+
window: wireAgentContextWindowSchema,
|
|
372
|
+
// Provider model identity is not part of the provider-neutral snapshot.
|
|
373
|
+
providerModel: z.never().optional(),
|
|
374
|
+
}),
|
|
375
|
+
])
|
|
376
|
+
|
|
377
|
+
export const contextUpdatedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
378
|
+
type: z.literal('context.updated'),
|
|
379
|
+
payload: z.object({
|
|
380
|
+
snapshot: wireAgentContextSnapshotSchema,
|
|
381
|
+
}),
|
|
382
|
+
})
|
|
271
383
|
|
|
272
384
|
export const contextCompactionStartedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
273
385
|
type: z.literal('context.compaction.started'),
|
|
274
386
|
payload: z.object({
|
|
275
387
|
compactionId: z.string().min(1),
|
|
276
388
|
trigger: agentContextCompactionTriggerSchema,
|
|
277
|
-
})
|
|
278
|
-
})
|
|
389
|
+
}),
|
|
390
|
+
})
|
|
279
391
|
|
|
280
392
|
export const contextCompactionCompletedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
281
393
|
type: z.literal('context.compaction.completed'),
|
|
@@ -287,8 +399,16 @@ export const contextCompactionCompletedAgentEventSchema = agentTurnEventBaseSche
|
|
|
287
399
|
inputTokensBefore: z.number().int().nonnegative().optional(),
|
|
288
400
|
inputTokensAfter: z.number().int().nonnegative().optional(),
|
|
289
401
|
error: agentErrorSchema.optional(),
|
|
290
|
-
})
|
|
291
|
-
})
|
|
402
|
+
}),
|
|
403
|
+
})
|
|
404
|
+
|
|
405
|
+
export const contextCompactionRequestCompletedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
406
|
+
type: z.literal('context.compaction.request.completed'),
|
|
407
|
+
payload: z.object({
|
|
408
|
+
commandId: z.string().min(1),
|
|
409
|
+
result: agentContextCompactionRequestResultSchema,
|
|
410
|
+
}),
|
|
411
|
+
})
|
|
292
412
|
|
|
293
413
|
export const userInputRequestedAgentEventSchema = agentTurnEventBaseSchema.extend({
|
|
294
414
|
type: z.literal('user-input.requested'),
|
|
@@ -297,36 +417,38 @@ export const userInputRequestedAgentEventSchema = agentTurnEventBaseSchema.exten
|
|
|
297
417
|
toolCallId: z.string().min(1),
|
|
298
418
|
prompt: z.string().min(1),
|
|
299
419
|
questions: z.array(agentUserInputQuestionSchema).min(1),
|
|
300
|
-
})
|
|
301
|
-
})
|
|
420
|
+
}),
|
|
421
|
+
})
|
|
302
422
|
|
|
303
|
-
export const userInputResolvedAgentEventSchema =
|
|
423
|
+
export const userInputResolvedAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
304
424
|
type: z.literal('user-input.resolved'),
|
|
305
425
|
payload: z.object({
|
|
306
426
|
requestId: z.string().min(1),
|
|
307
427
|
requestedTurnId: z.string().min(1),
|
|
308
428
|
toolCallId: z.string().min(1),
|
|
309
429
|
answers: agentUserInputAnswersSchema,
|
|
310
|
-
})
|
|
311
|
-
})
|
|
430
|
+
}),
|
|
431
|
+
})
|
|
312
432
|
|
|
313
|
-
export const errorAgentEventSchema =
|
|
433
|
+
export const errorAgentEventSchema = agentSessionEventBaseSchema.extend({
|
|
314
434
|
type: z.literal('error'),
|
|
315
435
|
payload: z.object({
|
|
316
436
|
message: z.string().min(1),
|
|
317
437
|
fatal: z.boolean(),
|
|
318
438
|
source: agentErrorSourceSchema.optional(),
|
|
319
439
|
error: agentErrorSchema.optional(),
|
|
320
|
-
})
|
|
321
|
-
})
|
|
440
|
+
}),
|
|
441
|
+
})
|
|
322
442
|
|
|
323
443
|
export const agentEventSchema = z.discriminatedUnion('type', [
|
|
324
444
|
sessionStartedAgentEventSchema,
|
|
325
445
|
sessionConfiguredAgentEventSchema,
|
|
446
|
+
sessionSettingsChangedAgentEventSchema,
|
|
326
447
|
sessionSkillsUpdatedAgentEventSchema,
|
|
327
448
|
sessionStateChangedAgentEventSchema,
|
|
328
449
|
sessionEndedAgentEventSchema,
|
|
329
450
|
turnStartedAgentEventSchema,
|
|
451
|
+
promptTurnCorrelatedAgentEventSchema,
|
|
330
452
|
turnEndedAgentEventSchema,
|
|
331
453
|
workObservedAgentEventSchema,
|
|
332
454
|
messageStartedAgentEventSchema,
|
|
@@ -338,12 +460,15 @@ export const agentEventSchema = z.discriminatedUnion('type', [
|
|
|
338
460
|
toolCallStartedAgentEventSchema,
|
|
339
461
|
toolOutputDeltaAgentEventSchema,
|
|
340
462
|
toolCallCompletedAgentEventSchema,
|
|
463
|
+
toolOutputUpdatedAgentEventSchema,
|
|
341
464
|
subagentStartedAgentEventSchema,
|
|
342
465
|
subagentProgressAgentEventSchema,
|
|
343
466
|
subagentEndedAgentEventSchema,
|
|
344
467
|
usageAgentEventSchema,
|
|
468
|
+
contextUpdatedAgentEventSchema,
|
|
345
469
|
contextCompactionStartedAgentEventSchema,
|
|
346
470
|
contextCompactionCompletedAgentEventSchema,
|
|
471
|
+
contextCompactionRequestCompletedAgentEventSchema,
|
|
347
472
|
userInputRequestedAgentEventSchema,
|
|
348
473
|
userInputResolvedAgentEventSchema,
|
|
349
474
|
errorAgentEventSchema,
|
|
@@ -356,6 +481,7 @@ export type AgentTurnEndStatus = z.infer<typeof agentTurnEndStatusSchema>
|
|
|
356
481
|
export type AgentSubagentStatus = z.infer<typeof agentSubagentStatusSchema>
|
|
357
482
|
export type AgentContextCompactionTrigger = z.infer<typeof agentContextCompactionTriggerSchema>
|
|
358
483
|
export type AgentContextCompactionStatus = z.infer<typeof agentContextCompactionStatusSchema>
|
|
484
|
+
export type AgentContextCompactionRequestResult = z.infer<typeof agentContextCompactionRequestResultSchema>
|
|
359
485
|
export type AgentErrorSource = z.infer<typeof agentErrorSourceSchema>
|
|
360
486
|
export type AgentSkillScope = z.infer<typeof agentSkillScopeSchema>
|
|
361
487
|
export type AgentSkill = z.infer<typeof agentSkillSchema>
|
|
@@ -365,6 +491,8 @@ export type AgentEventBase = z.infer<typeof agentEventBaseSchema>
|
|
|
365
491
|
export type AgentTurnEventBase = z.infer<typeof agentTurnEventBaseSchema>
|
|
366
492
|
export type SessionStartedAgentEvent = z.infer<typeof sessionStartedAgentEventSchema>
|
|
367
493
|
export type SessionConfiguredAgentEvent = z.infer<typeof sessionConfiguredAgentEventSchema>
|
|
494
|
+
export type AgentSettingsAppliesFrom = z.infer<typeof agentSettingsAppliesFromSchema>
|
|
495
|
+
export type SessionSettingsChangedAgentEvent = z.infer<typeof sessionSettingsChangedAgentEventSchema>
|
|
368
496
|
export type SessionSkillsUpdatedAgentEvent = z.infer<typeof sessionSkillsUpdatedAgentEventSchema>
|
|
369
497
|
export type SessionStateChangedAgentEvent = z.infer<typeof sessionStateChangedAgentEventSchema>
|
|
370
498
|
export type SessionEndedAgentEvent = z.infer<typeof sessionEndedAgentEventSchema>
|
|
@@ -380,13 +508,22 @@ export type ReasoningEndedAgentEvent = z.infer<typeof reasoningEndedAgentEventSc
|
|
|
380
508
|
export type ToolCallStartedAgentEvent = z.infer<typeof toolCallStartedAgentEventSchema>
|
|
381
509
|
export type ToolOutputDeltaAgentEvent = z.infer<typeof toolOutputDeltaAgentEventSchema>
|
|
382
510
|
export type ToolCallCompletedAgentEvent = z.infer<typeof toolCallCompletedAgentEventSchema>
|
|
511
|
+
export type ToolOutputUpdatedAgentEvent = z.infer<typeof toolOutputUpdatedAgentEventSchema>
|
|
383
512
|
export type SubagentStartedAgentEvent = z.infer<typeof subagentStartedAgentEventSchema>
|
|
384
513
|
export type SubagentProgressAgentEvent = z.infer<typeof subagentProgressAgentEventSchema>
|
|
385
514
|
export type SubagentEndedAgentEvent = z.infer<typeof subagentEndedAgentEventSchema>
|
|
386
515
|
export type UsageAgentEvent = z.infer<typeof usageAgentEventSchema>
|
|
516
|
+
export type ContextUpdatedAgentEvent = z.infer<typeof contextUpdatedAgentEventSchema>
|
|
387
517
|
export type ContextCompactionStartedAgentEvent = z.infer<typeof contextCompactionStartedAgentEventSchema>
|
|
388
518
|
export type ContextCompactionCompletedAgentEvent = z.infer<typeof contextCompactionCompletedAgentEventSchema>
|
|
519
|
+
export type ContextCompactionRequestCompletedAgentEvent = z.infer<typeof contextCompactionRequestCompletedAgentEventSchema>
|
|
389
520
|
export type UserInputRequestedAgentEvent = z.infer<typeof userInputRequestedAgentEventSchema>
|
|
390
521
|
export type UserInputResolvedAgentEvent = z.infer<typeof userInputResolvedAgentEventSchema>
|
|
391
522
|
export type ErrorAgentEvent = z.infer<typeof errorAgentEventSchema>
|
|
392
523
|
export type AgentEvent = z.infer<typeof agentEventSchema>
|
|
524
|
+
|
|
525
|
+
export const agentEventTypes: readonly AgentEvent['type'][] = agentEventSchema.options.map(
|
|
526
|
+
schema => schema.shape.type.value,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
export type PromptTurnCorrelatedAgentEvent = z.infer<typeof promptTurnCorrelatedAgentEventSchema>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AgentEventActor, AgentEventBase } from './agent-event'
|
|
2
|
+
|
|
3
|
+
export type AgentSubagentIdentity = Pick<Extract<AgentEventActor, { type: 'subagent' }>, 'actorId' | 'subagentId' | 'parentActorId' | 'origin' | 'parentToolCallId'>
|
|
4
|
+
|
|
5
|
+
export function normalizeAgentSubagentIdentity(identity: AgentSubagentIdentity): AgentSubagentIdentity {
|
|
6
|
+
return {
|
|
7
|
+
actorId: identity.actorId,
|
|
8
|
+
subagentId: identity.subagentId,
|
|
9
|
+
parentActorId: identity.parentActorId,
|
|
10
|
+
origin: identity.origin,
|
|
11
|
+
parentToolCallId: identity.parentToolCallId ?? (identity.origin.type === 'tool_call' ? identity.origin.toolCallId : undefined),
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function agentSubagentIdentitiesEqual(left: AgentSubagentIdentity, right: AgentSubagentIdentity): boolean {
|
|
16
|
+
const normalizedLeft = normalizeAgentSubagentIdentity(left)
|
|
17
|
+
const normalizedRight = normalizeAgentSubagentIdentity(right)
|
|
18
|
+
return normalizedLeft.actorId === normalizedRight.actorId
|
|
19
|
+
&& normalizedLeft.subagentId === normalizedRight.subagentId
|
|
20
|
+
&& normalizedLeft.parentActorId === normalizedRight.parentActorId
|
|
21
|
+
&& normalizedLeft.parentToolCallId === normalizedRight.parentToolCallId
|
|
22
|
+
&& (normalizedLeft.origin.type === 'tool_call'
|
|
23
|
+
? normalizedRight.origin.type === 'tool_call' && normalizedLeft.origin.toolCallId === normalizedRight.origin.toolCallId
|
|
24
|
+
: normalizedRight.origin.type === 'provider_task' && normalizedLeft.origin.taskId === normalizedRight.origin.taskId)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function agentRuntimeIdentityKey(event: Pick<AgentEventBase, 'sessionId' | 'providerSessionId'>): string {
|
|
28
|
+
return `${event.sessionId.length}:${event.sessionId}:${event.providerSessionId.length}:${event.providerSessionId}`
|
|
29
|
+
}
|