map static method
Translate event, or return null when it carries no public breadcrumb.
Implementation
static SdkEvent? map(events_pb.SDKEvent event) {
if (event.hasInitialization()) {
switch (event.initialization.stage) {
case InitializationStage.INITIALIZATION_STAGE_COMPLETED:
return const SdkReady();
case InitializationStage.INITIALIZATION_STAGE_FAILED:
return SdkError(
event.initialization.error.isEmpty
? 'SDK initialization failed'
: event.initialization.error,
recoverable: false,
);
default:
return null;
}
}
if (event.hasComponentLifecycle()) {
final lifecycle = event.componentLifecycle;
if (lifecycle.modelId.isEmpty) return null;
switch (lifecycle.currentState) {
case ComponentLifecycleState.COMPONENT_LIFECYCLE_STATE_READY:
return SdkModelLoaded(
lifecycle.modelId,
lifecycle.hasSnapshot()
? lifecycle.snapshot.category
: _unspecifiedCategory,
);
case ComponentLifecycleState.COMPONENT_LIFECYCLE_STATE_NOT_LOADED:
case ComponentLifecycleState.COMPONENT_LIFECYCLE_STATE_SHUTDOWN:
return SdkModelUnloaded(lifecycle.modelId);
default:
return null;
}
}
if (event.hasModel()) {
final model = event.model;
switch (model.kind) {
case ModelEventKind.MODEL_EVENT_KIND_UNLOAD_COMPLETED:
return SdkModelUnloaded(model.modelId);
case ModelEventKind.MODEL_EVENT_KIND_LOAD_FAILED:
case ModelEventKind.MODEL_EVENT_KIND_DOWNLOAD_FAILED:
return SdkError(
model.error.isEmpty ? 'Model operation failed' : model.error,
recoverable: true,
);
default:
return null;
}
}
// `FailureEvent` was deleted outright (idl/sdk_events.proto): every
// field already existed on the envelope — `error` -> `SDKEvent.error`,
// `recoverable` -> `SDKError.retryable`.
if (event.hasError()) {
return SdkError(event.error.message, recoverable: event.error.retryable);
}
return null;
}