agent_gate_bloc 0.1.0
agent_gate_bloc: ^0.1.0 copied to clipboard
Bloc / Cubit integration for agent_gate — AI-agnostic behavioural routing middleware for Flutter. Adds GateCubit, GateBloc, typed GateState and a GateBlocListener that performs navigation.
agent_gate_bloc #
Bloc / Cubit integration for
agent_gate — the AI-agnostic
behavioural routing middleware for Flutter.
Philosophy: in Bloc apps the decision is state and navigation is a side-effect done by the widget layer. So:
GateCubit/GateBlocrun the decision and emitGateIdle → GateDeciding → GateDecided.GateBlocListenerreacts toGateDecidedby navigating through the globally configuredAgentGate.adapter(Navigator, GoRouter, GetX — whichever you set), and layers the loading UI over your page whileGateDeciding.
dependencies:
agent_gate: ^0.1.0
agent_gate_bloc: ^0.1.0
flutter_bloc: ^9.0.0
Cubit #
BlocProvider(
create: (_) => GateCubit(),
child: GateBlocListener<GateCubit>(
onNavigated: (ctx, s) => ctx.read<GateCubit>().reset(),
child: CartView(),
),
);
// somewhere in CartView:
context.read<GateCubit>().decide(checkoutGate, extra: {'total': cart.total});
GateDecided carries gate, decision (candidateId, confidence,
reason, source) and candidate; isFallback tells you the AI/rules did
not decide.
Bloc #
context.read<GateBloc>().add(GateDecideRequested(checkoutGate, extra: {...}));
context.read<GateBloc>().add(const GateReset());
Events are processed sequentially by default (Bloc's own default is
concurrent, which lets a reset overtake a decision). Pass transformer: to
change the policy.
Custom navigation / error handling #
GateBlocListener<GateCubit>(
onDecided: (ctx, s) => s.isFallback
? showRetrySheet(ctx, s.decision.reason)
: ctx.go(s.candidate.route!),
child: CartView(),
)
or navigateOnFallback: false to keep the default navigation only for real
decisions.
Building your own UI on the state #
BlocBuilder<GateCubit, GateState>(builder: (_, s) => switch (s) {
GateIdle() => const ContinueButton(),
GateDeciding() => const AgentLoadingView(),
GateDecided() => Text('Going to ${s.candidate.label}: ${s.decision.reason}'),
});
License #
MIT © MSI Shamim / Increments Inc.