Repository navigation
1.1.0
Until now, decide() gave you a typed object and dropped the confidence behind it. So the moment you wanted to send unsure tickets to a human, you had to fall back to predict(). 1.1.0 moves that check into the decision class, and adds caching and a health check for production.
final readonly class Triage
{
public function __construct(
#[Ask('Which department should handle this?', minConfidence: 0.7)]
public ?Department $department, // null when laya isn't sure
#[Ask('Does the user threaten to cancel?', yes: 'says they will cancel or switch', threshold: 0.3)]
public bool $churn,
) {}
}New
minConfidenceon#[Ask]. A nullable parameter isnullwhen the calibratedanswerConfidenceis below the threshold. If the parameter isn't nullable,decide()throws before it sends a request.yes,noandthresholdfor bools.yesandnodescribe what each answer means, the same asQuestion::yesNo().thresholdsets the P(yes) at which the value becomestrue, instead of the fixed 0.5. Setting any of them on a parameter that isn't a bool throws, so a typo can't be silently ignored.- Fake a decision object.
Laya::fake(new Triage(...))takes its answers from the object's public properties, so tests build the same type your code gets back, and there are no string keys to go stale when you rename a field. - Unsure fake answers. Register
nulland the fake answers with even probabilities and zero confidence. That lets you test theminConfidencepath without a server. assertDecided(Triage::class). It passes when a recorded request asked exactly that class's questions. An optional callback gets the state and the model.- PSR-16 caching. Pass
cache:andcacheTtl:to the constructor. The key is a hash of the state, the questions and the pinned model. Laya gives the same answer to the same input, so repeat requests never reach the server. The key doesn't include the checkpoint revision, so clear the cache or set a TTL when you upgrade laya-serve. - Laravel caching. Set
LAYA_CACHE_STORE(e.g.redis) and optionallyLAYA_CACHE_TTLin seconds. Caching stays off by default. php artisan laya:health. It prints the server's status, device and loaded checkpoints, and exits with 1 when laya-serve is unhealthy or unreachable. Put it in your deploy checks.
Upgrading
No breaking changes. The one new dependency is psr/simple-cache ^3.0, which only contains interfaces. A published config/laya.php picks up the new cache block from the package defaults, so the env vars work without republishing.