Skip to content

ai-apply fatals without laravel/ai installed #7

Closed

Description

@Nejcc

What's wrong

laravel/ai is only a suggest in composer.json, but ApiController::aiApplyFix() (src/Controllers/ApiController.php:449-470) always instantiates WriteSourceFileTool and \Laravel\Ai\Tools\Request. WriteSourceFileTool implements Laravel\Ai\Contracts\Tool. Without the package, the endpoint throws a class-not-found error, which surfaces as a 500 instead of the 501 that aiSuggest returns.

Suggested fix

Guard with class_exists(\Laravel\Ai\Tools\Request::class) and return 501 like aiSuggest. Or move the file-patching logic into a plain class that doesn't depend on laravel/ai.

Activity

  1. mikemikimike commented on Oct 31, 2026

    @mikemikimike

    Implemented in PR #10: #10

    aiApplyFix now returns HTTP 501 when the optional laravel/ai SDK is unavailable, matching the existing AI endpoint behavior, and avoids constructing SDK-dependent tools before that check.

    Validation completed with PHP lint across the project source, a regression script for Issue #7, composer validate --no-check-publish, and git diff --check.

  2. Nejcc commented on Oct 31, 2026

    @Nejcc
    MemberAuthor

    Same root cause also hits aiSuggest and aiInvestigateException: class_exists(QueryFixerAgent::class) autoloads the agent, which uses the Laravel\Ai\Promptable trait, so the probe itself fatals without laravel/ai. The hardening PR replaces the probe with trait_exists(\Laravel\Ai\Promptable::class) in one helper used by all three endpoints, with a regression test.

  3. added 4 commits that reference this issue on Oct 31, 2026
  4. Nejcc commented on Oct 31, 2026

    @Nejcc
    MemberAuthor

    Fixed in #20; covered by tests/Feature/SecurityTest.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions