Skip to main content

AI & workflows

Ai Loop Activity code

Copy the implementation or inspect every file that belongs to this component unit.

resources/views/components/ui/ai-loop-activity.blade.php

@props([
    'iteration' => 1,
    'events' => [],
    'title' => 'Loop activity',
    'embedded' => false,
])

@php
    /*
    | Per-iteration feed of agent tool calls and actions.
    |
    | Pass `events` as an array of rows or compose with <x-ui.ai-tool-call> in the slot.
    |
    | Usage:
    |   <x-ui.ai-loop-activity :iteration="4" :events="[
    |       ['label' => 'Read WorkflowComponentsTest.php', 'status' => 'complete', 'time' => '4s'],
    |   ]" />
    */
    $normalizedEvents = collect($events)
        ->map(function ($item) {
            if (! is_array($item)) {
                return [
                    'label' => (string) $item,
                    'status' => 'complete',
                    'detail' => null,
                    'time' => null,
                ];
            }

            return [
                'label' => $item['label'] ?? '',
                'status' => $item['status'] ?? 'complete',
                'detail' => $item['detail'] ?? null,
                'time' => $item['time'] ?? null,
            ];
        })
        ->filter(fn (array $item) => $item['label'] !== '')
        ->values()
        ->all();
@endphp

<div {{ $attributes->merge(['class' => $embedded ? 'min-w-0' : 'min-w-0 overflow-hidden rounded-2xl border border-gray-200 bg-white shadow-sm dark:border-gray-800 dark:bg-gray-900']) }}>
    @unless ($embedded)
        <div class="border-b border-gray-200 px-4 py-4 dark:border-gray-800 sm:px-5">
            <p class="text-sm font-semibold text-gray-900 dark:text-white">{{ $title }}</p>
            <p class="text-xs text-gray-500 dark:text-gray-400">Iteration {{ $iteration }}</p>
        </div>
    @endunless

    <div @class(['space-y-2 p-4 sm:p-5', 'border-t border-gray-200 dark:border-gray-800' => $embedded])>
        @if (count($normalizedEvents) > 0)
            <ul class="space-y-2" role="list">
                @foreach ($normalizedEvents as $event)
                    <x-ui.ai-tool-call
                        :label="$event['label']"
                        :status="$event['status']"
                        :detail="$event['detail']"
                        :time="$event['time']"
                    />
                @endforeach
            </ul>
        @endif

        @if (trim($slot) !== '')
            <ul class="space-y-2" role="list">{{ $slot }}</ul>
        @endif
    </div>
</div>