@@ -19,6 +19,7 @@ import { composeBaseURL, tracingFetch as fetch, isNonEmptyArray } from '@adobe/s
1919import AhrefsAPIClient from '@adobe/spacecat-shared-ahrefs-client' ;
2020import { parse as parseDomain } from 'tldts' ;
2121import { postSlackMessage } from '../../utils/slack/base.js' ;
22+ import DrsClient from '../../support/drs-client.js' ;
2223
2324// LLMO Constants
2425const LLMO_PRODUCT_CODE = EntitlementModel . PRODUCT_CODES . LLMO ;
@@ -39,6 +40,7 @@ export const BASIC_AUDITS = [
3940export const ASO_DEMO_ORG = '66331367-70e6-4a49-8445-4f6d9c265af9' ;
4041
4142export const ASO_CRITICAL_SITES = [ ] ;
43+ const LLMO_ONBOARDING_PUBLISH_TRIGGER = 'trigger:llmo-onboarding-publish' ;
4244
4345/**
4446 * Generates the data folder name from a domain.
@@ -254,53 +256,6 @@ export async function validateSiteNotOnboarded(baseURL, imsOrgId, dataFolder, co
254256 }
255257}
256258
257- /**
258- * Publishes a file to admin.hlx.page.
259- * @param {string } filename - The filename to publish
260- * @param {string } outputLocation - The output location
261- * @param {object } log - Logger instance
262- */
263- async function publishToAdminHlx ( filename , outputLocation , log ) {
264- try {
265- const org = 'adobe' ;
266- const site = 'project-elmo-ui-data' ;
267- const ref = 'main' ;
268- const jsonFilename = `${ filename . replace ( / \. [ ^ / . ] + $ / , '' ) } .json` ;
269- const path = `${ outputLocation } /${ jsonFilename } ` ;
270- const headers = { Cookie : `auth_token=${ process . env . HLX_ADMIN_TOKEN } ` } ;
271-
272- if ( ! process . env . HLX_ADMIN_TOKEN ) {
273- log . warn ( 'LLMO onboarding: HLX_ADMIN_TOKEN is not set' ) ;
274- }
275-
276- const baseUrl = 'https://admin.hlx.page' ;
277- const endpoints = [
278- { name : 'preview' , url : `${ baseUrl } /preview/${ org } /${ site } /${ ref } /${ path } ` } ,
279- { name : 'live' , url : `${ baseUrl } /live/${ org } /${ site } /${ ref } /${ path } ` } ,
280- ] ;
281-
282- for ( const [ index , endpoint ] of endpoints . entries ( ) ) {
283- log . debug ( `Publishing Excel report via admin API (${ endpoint . name } ): ${ endpoint . url } ` ) ;
284-
285- // eslint-disable-next-line no-await-in-loop
286- const response = await fetch ( endpoint . url , { method : 'POST' , headers } ) ;
287-
288- if ( ! response . ok ) {
289- throw new Error ( `${ endpoint . name } failed: ${ response . status } ${ response . statusText } ` ) ;
290- }
291-
292- log . debug ( `Excel report successfully published to ${ endpoint . name } ` ) ;
293-
294- if ( index === 0 ) {
295- // eslint-disable-next-line no-await-in-loop,max-statements-per-line
296- await new Promise ( ( resolve ) => { setTimeout ( resolve , 2000 ) ; } ) ;
297- }
298- }
299- } catch ( publishError ) {
300- log . error ( `Failed to publish via admin.hlx.page: ${ publishError . message } ` ) ;
301- }
302- }
303-
304259/**
305260 * Starts a bulk status job for a given path.
306261 * @param {string } path - The folder path to get status for
@@ -545,9 +500,6 @@ export async function copyFilesToSharepoint(dataFolder, context, say = () => {})
545500 log . warn ( `Warning: Query index at ${ dataFolder } already exists. Skipping creation.` ) ;
546501 await say ( `Query index in ${ dataFolder } already exists. Skipping creation.` ) ;
547502 }
548-
549- log . debug ( 'Publishing query-index to admin.hlx.page' ) ;
550- await publishToAdminHlx ( 'query-index' , dataFolder , log ) ;
551503}
552504
553505/**
@@ -999,6 +951,22 @@ export async function triggerAudits(audits, context, site) {
999951 ) ;
1000952}
1001953
954+ export async function enqueueLlmoOnboardingPublish ( context , site , dataFolder ) {
955+ const { sqs, dataAccess, log } = context ;
956+ const { Configuration } = dataAccess ;
957+ const configuration = await Configuration . findLatest ( ) ;
958+
959+ await sqs . sendMessage ( configuration . getQueues ( ) . audits , {
960+ type : LLMO_ONBOARDING_PUBLISH_TRIGGER ,
961+ siteId : site . getId ( ) ,
962+ auditContext : {
963+ dataFolder,
964+ } ,
965+ } ) ;
966+
967+ log . info ( `Queued ${ LLMO_ONBOARDING_PUBLISH_TRIGGER } for site ${ site . getId ( ) } ` ) ;
968+ }
969+
1002970/**
1003971 * Complete LLMO onboarding process.
1004972 * @param {object } params - Onboarding parameters
@@ -1039,6 +1007,12 @@ export async function performLlmoOnboarding(params, context, say = () => {}) {
10391007 // Copy files to SharePoint
10401008 await copyFilesToSharepoint ( dataFolder , context , say ) ;
10411009
1010+ try {
1011+ await enqueueLlmoOnboardingPublish ( context , site , dataFolder ) ;
1012+ } catch ( error ) {
1013+ log . warn ( `Failed to enqueue ${ LLMO_ONBOARDING_PUBLISH_TRIGGER } for site ${ site . getId ( ) } : ${ error . message } ` ) ;
1014+ }
1015+
10421016 // Update index config
10431017 await updateIndexConfig ( dataFolder , context , say ) ;
10441018
@@ -1083,8 +1057,37 @@ export async function performLlmoOnboarding(params, context, say = () => {}) {
10831057 site . setConfig ( Config . toDynamoItem ( siteConfig ) ) ;
10841058 await site . save ( ) ;
10851059
1086- // Trigger audits
1087- await triggerAudits ( [ ...BASIC_AUDITS , 'llmo-customer-analysis' , 'wikipedia-analysis' ] , context , site ) ;
1060+ // Trigger audits (llmo-customer-analysis is NOT triggered here; it will be triggered
1061+ // after the DRS prompt generation job completes, via SNS → audit-worker. LLMO-1819)
1062+ await triggerAudits ( [ ...BASIC_AUDITS , 'wikipedia-analysis' ] , context , site ) ;
1063+
1064+ // Submit DRS prompt generation job (non-blocking)
1065+ try {
1066+ const drsClient = DrsClient ( context ) ;
1067+ if ( drsClient . isConfigured ( ) ) {
1068+ // Try to get audience from brand profile, fall back to default
1069+ const brandProfile = siteConfig . getBrandProfile ?. ( ) ;
1070+ const audience = brandProfile ?. main_profile ?. target_audience
1071+ || `General consumers interested in ${ brandName } products and services` ;
1072+
1073+ const drsJob = await drsClient . submitPromptGenerationJob ( {
1074+ baseUrl : baseURL ,
1075+ brandName : brandName . trim ( ) ,
1076+ audience,
1077+ region : 'US' ,
1078+ numPrompts : 42 ,
1079+ siteId : site . getId ( ) ,
1080+ imsOrgId,
1081+ } ) ;
1082+ log . info ( `Started DRS prompt generation: job=${ drsJob . job_id } ` ) ;
1083+ say ( `:robot_face: Started DRS prompt generation job: ${ drsJob . job_id } ` ) ;
1084+ } else {
1085+ log . debug ( 'DRS client not configured, skipping prompt generation' ) ;
1086+ }
1087+ } catch ( drsError ) {
1088+ log . error ( `Failed to start DRS prompt generation: ${ drsError . message } ` ) ;
1089+ say ( ':warning: Failed to start DRS prompt generation (will need manual trigger)' ) ;
1090+ }
10881091
10891092 return {
10901093 site,
0 commit comments