runLive method

Stream<Event> runLive(
  1. InvocationContext parentContext
)

Runs the agent in live mode with lifecycle callbacks.

Implementation

Stream<Event> runLive(InvocationContext parentContext) async* {
  final InvocationContext context = createInvocationContext(parentContext);
  if (context.isAborted) {
    return;
  }

  // Wrap the full agent lifecycle so that any unhandled error is surfaced to
  // on_agent_error_callback before being re-raised. Notification-only.
  try {
    final Event? before = await _handleBeforeAgentCallback(context);
    if (context.isAborted) {
      return;
    }
    if (before != null) {
      _stampIsolationScope(context, before);
      yield before;
    }

    if (context.endInvocation) {
      return;
    }

    await for (final Event event in runLiveImpl(context)) {
      if (context.isAborted) {
        return;
      }
      _stampIsolationScope(context, event);
      yield event;
    }

    if (context.isAborted) {
      return;
    }
    final Event? after = await _handleAfterAgentCallback(context);
    if (context.isAborted) {
      return;
    }
    if (after != null) {
      _stampIsolationScope(context, after);
      yield after;
    }
  } catch (error) {
    await _handleAgentErrorCallback(context, error);
    rethrow;
  }
}