json([ 'models' => config('ai.allowed_models', []), 'default' => config('ai.default_model'), 'api_key_configured' => filled(config('ai.openrouter.api_key')), ]); } /** * Paginated listing of registered AI agents. */ public function index(Request $request): JsonResponse { $query = AiAgent::query()->orderBy('name'); if ($type = $request->query('type')) { $query->where('type', $type); } if ($status = $request->query('status')) { $query->where('status', $status); } return response()->json($query->paginate((int) $request->query('per_page', 15))); } /** * Return a compact snapshot of active agents for the 3D renderer. */ public function world(): JsonResponse { $agents = AiAgent::query() ->where('status', '!=', 'paused') ->get(['id', 'name', 'type', 'status', 'pos_x', 'pos_y', 'pos_z', 'rotation_y', 'current_goal']) ->map(fn (AiAgent $agent): array => [ 'id' => $agent->id, 'name' => $agent->name, 'type' => $agent->type, 'status' => $agent->status, 'position' => [(float) $agent->pos_x, (float) $agent->pos_y, (float) $agent->pos_z], 'rotation_y' => (float) $agent->rotation_y, 'goal' => $agent->current_goal, ]); return response()->json(['agents' => $agents]); } /** * Persist a new AI agent. */ public function store(AiAgentRequest $request): JsonResponse { $data = $request->validated(); $data['model'] = $data['model'] ?? config('ai.default_model'); $data['status'] = $data['status'] ?? 'active'; $agent = AiAgent::create($data); return response()->json($agent, 201); } /** * Return a single AI agent. */ public function show(AiAgent $aiAgent): JsonResponse { return response()->json($aiAgent->load('stores:id,name,agent_id,is_open')); } /** * Update an AI agent. */ public function update(AiAgentRequest $request, AiAgent $aiAgent): JsonResponse { $aiAgent->update($request->validated()); return response()->json($aiAgent->fresh()); } /** * Delete an AI agent. */ public function destroy(AiAgent $aiAgent): JsonResponse { $aiAgent->delete(); return response()->json(['message' => __('agents.deleted')]); } }