Skip to content

Commit 6eb9cab

Browse files
committed
feat: Enhance event handling in executeAgent to map raw events to ExecutionEvent interface
1 parent 52c4d2e commit 6eb9cab

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/grpc/client.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,34 @@ class AegisRuntimeClient {
6161

6262
const call = this.client.ExecuteAgent(request);
6363

64-
call.on('data', (event: ExecutionEvent) => {
64+
call.on('data', (rawEvent: any) => {
65+
// The proto uses `oneof event` which @grpc/proto-loader decodes as:
66+
// { event: 'execution_completed', execution_completed: { ... } }
67+
// Map it to the flat ExecutionEvent interface expected by activities.
68+
const eventCase: string = rawEvent.event ?? '';
69+
const inner: any = rawEvent[eventCase] ?? {};
70+
71+
// Convert snake_case oneof case name to PascalCase event_type
72+
// e.g. 'execution_completed' → 'ExecutionCompleted'
73+
const eventType = eventCase
74+
.split('_')
75+
.map((w: string) => w.charAt(0).toUpperCase() + w.slice(1))
76+
.join('') as ExecutionEvent['event_type'];
77+
78+
const event: ExecutionEvent = {
79+
event_type: eventType,
80+
execution_id: inner.execution_id ?? '',
81+
timestamp: inner.started_at ?? inner.completed_at ?? inner.failed_at ?? inner.applied_at ?? new Date().toISOString(),
82+
iteration_number: inner.iteration_number,
83+
action: inner.action,
84+
output: inner.output,
85+
error_message: inner.error?.message,
86+
code_diff: inner.code_diff,
87+
final_output: inner.final_output,
88+
reason: inner.reason,
89+
total_iterations: inner.total_iterations,
90+
};
91+
6592
logger.debug({ event_type: event.event_type }, 'Received execution event');
6693
events.push(event);
6794
});

0 commit comments

Comments
 (0)