builder = $builder; } public function register(): void { add_filter( 'acez_seo_ai_prompt', array( $this, 'maybe_override' ), 10, 3 ); } /** * @param mixed $context Unused for these fields — the site context is * gathered here so the REST layer stays ignorant of * what an llms.txt prompt needs. */ public function maybe_override( string $prompt, string $field, $context ): string { if ( ! in_array( $field, self::FIELDS, true ) ) { return $prompt; } unset( $context ); $site = $this->site_context(); if ( 'llms_title' === $field ) { return sprintf( /* translators: %s: current llms.txt file content, used as site context */ __( 'Below is the llms.txt file of a website, which is a short guide to that site for language models: %s Write a title for this site — the name a reader should see at the top of that file. Use the brand or organization name if one is apparent, otherwise a short descriptive name. Rules: ONE line, at most 60 characters, no quotation marks, no markdown, no trailing period, and write it in the same language as the content above. Return the title itself and nothing else.', 'acez-seo' ), $site ); } if ( 'llms_description' === $field ) { return sprintf( /* translators: %s: current llms.txt file content, used as site context */ __( 'Below is the llms.txt file of a website, which is a short guide to that site for language models: %s Write a one-sentence description of what this site is and who it is for. Rules: ONE sentence, at most 200 characters, plain text with no markdown and no quotation marks, factual and specific to this site (never generic filler such as "welcome to our website"), and written in the same language as the content above. Return the sentence itself and nothing else.', 'acez-seo' ), $site ); } if ( 'llms_intro' === $field ) { return sprintf( /* translators: %s: current llms.txt file content, used as site context */ __( 'Below is the llms.txt file of a website, which is a short guide to that site for language models: %s Write a short introduction for that file: what this site covers, what kinds of content a model will find here, and where the most useful material is. Rules: 2 to 4 sentences, at most 600 characters, plain paragraphs of markdown with no headings, no bullet lists and no links, based only on what is visible above (never invent sections, offers or claims), and written in the same language as the content above. Return the introduction itself and nothing else.', 'acez-seo' ), $site ); } return sprintf( /* translators: %s: current llms.txt file content, used as site context */ __( 'Below is the llms.txt file of a website, which is a short guide to that site for language models: %s Write a short closing note for the end of that file — for example how a model should attribute this content, or where to find contact or licensing information. Rules: 1 to 2 sentences, at most 300 characters, plain text with no headings and no bullet lists, no invented contact details, email addresses or legal terms (mention them only if they already appear above), and written in the same language as the content above. Return the note itself and nothing else.', 'acez-seo' ), $site ); } /** * The llms.txt body as it would be served right now, with the editorial * overrides left empty so the builder falls back to its defaults * (organization name, tagline, top pages, recent posts). */ private function site_context(): string { $body = $this->builder->build( '' ); if ( '' === trim( $body ) ) { // Defensive only: build() always emits at least a title line, but // an empty prompt would be sent to the provider as a blank request. $body = (string) get_bloginfo( 'name' ); } if ( mb_strlen( $body ) > self::MAX_CONTEXT_CHARS ) { $body = mb_substr( $body, 0, self::MAX_CONTEXT_CHARS ); } return "\n\n" . trim( $body ) . "\n\n"; } }