Skip to content

Conversation

@dipratap
Copy link
Contributor

@dipratap dipratap commented Oct 14, 2025

Introduces a new API for deploying LLMO Opportunity suggestions on Edge (Project Tokowaka).
Implementation details are captured in https://wiki.corp.adobe.com/display/AEMSites/Tokowaka+-+Spacecat+Integration and https://wiki.corp.adobe.com/display/AEMSites/Tokowaka+Spacecat+Integration+-+Implementation+Internals.

Briefly, the API first fetches LLMO opportunity - Empty Headings for first iteration, generates a json patch config, uploads on S3, and invalidates the Tokowaka Cloudfront CDN cache.
The API is expected to be called from LLMO UI when the user clicks on deploy suggestion button.

@github-actions
Copy link

This PR will trigger a patch release when merged.

@dipratap dipratap changed the title fix: add tokowaka client [wip] fix: add tokowaka client Oct 23, 2025
@dipratap dipratap requested a review from nit23uec October 23, 2025 07:00
const response = await this.client.send(command);
const invalidation = response.Invalidation;

this.log.info(`CloudFront cache invalidation initiated: ${invalidation.Id}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets also log the time to invalidate the cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @private
*/
#initializeClient() {
/* c8 ignore start */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use nock to. mock the cdn requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used aws-sdk-client-mock, nock faces some issues with aws clients.

import { S3Client } from '@aws-sdk/client-s3';

export interface TokawakaPatch {
op: 'replace' | 'add' | 'prerender';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace
appendChild
insertBefore
insertAfter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


export interface TokawakaPatch {
op: 'replace' | 'add' | 'prerender';
selector?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selector is mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated index.d.ts

selector?: string;
value?: string;
attribute?: string;
element?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated index.d.ts

/**
* Akamai CDN client implementation
*/
export class AkamaiCdnClient extends BaseCdnClient {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets remove AkamaiCdnClient. its not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated index.d.ts

return s3Path;
} catch (error) {
this.log.error(`Failed to upload Tokowaka config to S3: ${error.message}`, error);
throw this.#createError(`S3 upload failed: ${error.message}`, HTTP_INTERNAL_SERVER_ERROR);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for displaying error in UI, we should not highlight internal impl details like S3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is not going to the UI, in case of unexpected errors - UI will get "Deployment failed - Internal Server Error"

this.log.info(`CDN cache invalidation completed: ${JSON.stringify(result)}`);
return result;
} catch (error) {
this.log.error(`Failed to invalidate CDN cache: ${error.message}`, error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tokowaka CDN cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated log

const newConfig = this.generateConfig(site, opportunity, eligibleSuggestions);

if (Object.keys(newConfig.tokowakaOptimizations).length === 0) {
this.log.warn('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty warn?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants