language->value === 'ms' ? 'Bahasa Malaysia' : 'English'; $products = self::productList($store); return <<name} Category: {$store->category->label()} Write all store text in: {$language} Brand description from the merchant: """ {$store->description} """ {$products} TEXT; } /** * The store's real products, so the AI can link a "featured_product" section to one. * Empty when the store has no active products yet. */ public static function productList(Store $store): string { $products = $store->products()->active()->orderBy('name')->limit(40)->get(['slug', 'name', 'price']); if ($products->isEmpty()) { return ''; } $lines = $products ->map(fn (Product $product) => '- '.$product->slug.': '.$product->name.' (RM '.number_format($product->price / 100, 2).')') ->implode("\n"); return <<products()->with('variants')->orderBy('name')->limit(60)->get(); $codes = $store->discountCodes()->orderBy('code')->limit(30)->get(); $today = now(DiscountCodeRules::TIMEZONE)->format('Y-m-d (l)'); $money = fn (int $sen) => 'RM '.number_format($sen / 100, 2, '.', ''); $productLines = $products->map(function (Product $product) use ($money): string { $line = "- {$product->slug}: {$product->name}, {$product->status->value}"; if ($product->isBundle()) { return $line.', bundle, '.$money($product->price).', enough stock for '.$product->stock; } if ($product->hasVariants()) { return $line.', choices: '.$product->variants ->map(fn (ProductVariant $variant) => '"'.$variant->name().'" '.$money($variant->price).' stock '.$variant->stock) ->implode('; '); } return $line.', '.$money($product->price) .($product->compare_at_price !== null ? ' (was '.$money($product->compare_at_price).')' : '') .', stock '.$product->stock; })->implode("\n"); $codeLines = $codes->map(fn (DiscountCode $code) => "- {$code->code}: {$code->label()}, ".$code->status() .($code->ends_at !== null ? ', last day '.$code->ends_at->setTimezone(DiscountCodeRules::TIMEZONE)->format('Y-m-d') : '')) ->implode("\n"); return << $plan */ public static function editPrompt(array $plan, string $instruction, string $products = ''): string { $json = json_encode($plan, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); return << $errors */ public static function repairPrompt(string $originalPrompt, string $rejectedAnswer, array $errors): string { $list = implode("\n", array_map(fn (string $error) => '- '.$error, array_slice($errors, 0, 25))); return << $variants) { $rules = []; foreach (PlanSchema::contentRules($type) as $field => $fieldRules) { $rules[$field] = implode('|', array_map( fn (string $rule) => str_starts_with($rule, 'regex:') ? 'format' : $rule, $fieldRules, )); } $sections .= "## $type\nvariants: ".implode(', ', $variants)."\ncontent: ".json_encode($rules, $flags)."\n\n"; } $example = json_encode(SamplePlan::forName('Example Store'), $flags); return <<