Installation
This guide walks you through installing the Alokai Compass module in your Storefront project.
Prerequisites
- Redis: Redis-backed caching must be enabled on your Alokai Cloud instance — this is an instance-level setting, not a project setting.
- Alokai@Edge (optional): needed for token-by-token streaming of AI Assistant replies. Without it, replies still work, just arrive as a complete response instead of streaming.
Both are instance-level settings — contact Alokai support to enable them.
Bootstrapping Compass with Alokai Storefront
To get access to this module and installation assistance, please contact the Alokai sales team or reach out to your Customer Support Manager.
Update environment variables
Contact Alokai support to get your Compass API key, then set it in the Middleware app's .env:
- ALOKAI_COMPASS_API_KEY=<alokai-compass-api-key>
+ ALOKAI_COMPASS_API_KEY=<your-alokai-compass-api-key>Manual installation (existing projects)
Adding Compass to an existing project? Use the Storefront CLI's add-module command instead of the bootstrap flow above.
To get access to this module and installation assistance, please contact the Alokai sales team or reach out to your Customer Support Manager.
Add the module files
npx @vsf-enterprise/storefront-cli add-module compass -e sapccThis does two separate things:
- Copies files and installs the package — module files into
sf-modules(Middleware and Next.js apps), aguided-sellingroute atapp/[locale]/(default)/guided-selling, a Playwright suite intests/, and the@alokai/compasspackage. Always runs in full, regardless of what happens next. - Runs codemods that wire the AI Assistant, Use Case Comparison, Product Page messages, and other integration points into your existing files, by matching anchors such as the
childrenexpression inroot-layout-content-wrapper.tsx,<Breadcrumbs>on the product page,<DecoratedPriceClient>insideProductCardVertical,createUnifiedExtension(...), orintegrations: {}inmiddleware.config.ts.
To install Compass on a modified Storefront project:
- Run
npx @vsf-enterprise/storefront-cli add-module compass -e sapcc. - Run
yarn install. - If the codemods fail with an error like
Error: Expected to insert JSX expression at least once(common once a project has diverged from the default structure), the file copy already succeeded. Continue to Wire up the module features manually below to finish the integration by hand.
Verify: apps/storefront-middleware/sf-modules contains a compass directory.
Set the Compass API key
Contact Alokai support to get your Compass API key. The installer writes ALOKAI_COMPASS_API_KEY (and a commented-out # ALOKAI_COMPASS_API_URL=https://llm-gateway.alokai.cloud, for pointing at a non-default Compass API endpoint) to apps/storefront-middleware/.env.example only — it never touches your actual .env. Copy both over yourself:
+ ALOKAI_COMPASS_API_KEY=<your-alokai-compass-api-key>
+ # ALOKAI_COMPASS_API_URL=https://llm-gateway.alokai.cloudLeave ALOKAI_COMPASS_API_URL commented out unless support tells you otherwise.
Until ALOKAI_COMPASS_API_KEY is set, the Middleware crashes on startup with Missing env var: ALOKAI_COMPASS_API_KEY.
The installer also appends yarn alokai-cli plugins install @alokai/cli-plugin-compass to your root package.json's postinstall script, adding an optional yarn alokai-cli compass tool generate scaffolding command. Safe to skip if you're wiring things up by hand.
Wire up the module features manually
Expect to need this section on any existing project with real history — codemods only reliably match a fresh, default-structure Storefront. Before applying a step below, check with git diff whether the codemod already applied it; skip if so.
Run yarn install from the project root first. If add-module aborted mid-codemod, @alokai/compass may already be in your package.json files without being installed, and every import below will fail with a module-not-found error until you install it.
Codemods run file-by-file in a fixed order, split into three sets: Middleware, Next.js, Playwright. A thrown error aborts the entire run immediately — not just later files in that set, but every set that hadn't started yet. So a Middleware-side failure (e.g. a mismatched createUnifiedExtension(...)) can mean the Next.js SDK registration below never even ran. After a failed run, check git diff across both apps to see exactly what landed before reapplying steps — reapplying an already-applied step risks duplicate imports/exports.
Middleware integration registration
Register Compass as a Middleware integration and re-export its types:
+ import { config as compassConfig } from '@sf-modules-middleware/compass';
export const config = {
integrations: {
// ...other integrations
+ compass: compassConfig,
},
};+ export * from '@/sf-modules/compass/types';Without this, none of Compass's endpoints exist server-side, regardless of anything else you wire up.
SDK module registration
Create sdk/modules/compass.ts to register Compass with buildModule, then re-export it:
import type { CompassModuleTypeParams } from 'storefront-middleware/types';
import { defineSdkModule } from '@vue-storefront/next';
import { getConfigSwitcherHeader } from './utils';
import { compassModule } from '@alokai/compass/sdk';
import { STATE_PATCHES } from '@sf-modules-middleware/compass/responses/state-patches';
import { UI_COMPONENTS } from '@sf-modules-middleware/compass/responses/dynamic-ui';
export const compass = defineSdkModule(({ buildModule, config, getRequestHeaders }) =>
buildModule(compassModule<CompassModuleTypeParams>, {
apiUrl: `${config.apiUrl}/compass`,
ssrApiUrl: `${config.ssrApiUrl}/compass`,
cdnCacheBustingId: config.cdnCacheBustingId,
defaultRequestConfig: {
getConfigSwitcherHeader,
headers: getRequestHeaders(),
},
responseSchemas: {
statePatches: STATE_PATCHES,
uiComponents: UI_COMPONENTS,
},
}),
);+ export * from "./compass";Without this, the Storefront can't call the Compass API at all. No utils.ts exporting getConfigSwitcherHeader in your sdk/modules directory? Add one, or drop that import and the getConfigSwitcherHeader line above.
Generative UI response types
Compass's bundled generative UI components type their props off AI_RESPONSE_TYPES. Create (or extend) shared/index.ts to assemble it:
+ import { FRONTEND_HINTS } from '@sf-modules-middleware/compass/responses/frontend-hints';
+ import { STATE_PATCHES } from '@sf-modules-middleware/compass/responses/state-patches';
+ import { STRUCTURED_OUTPUTS } from '@sf-modules-middleware/compass/responses/structured-outputs';
+ import { UI_COMPONENTS } from '@sf-modules-middleware/compass/responses/dynamic-ui';
+ export const AI_RESPONSE_TYPES = {
+ FRONTEND_HINTS,
+ STATE_PATCHES,
+ STRUCTURED_OUTPUTS,
+ UI_COMPONENTS,
+ };Required even if you never touch generative UI yourself — the AI Assistant's message renderer imports this file, so skipping it breaks the build once you wire up the AI Assistant below.
Search form replacement
Compass overlays config/search-form.tsx to open the AI Assistant instead of navigating to the search page. Replace its entire contents:
export { default } from '@/sf-modules/compass/components/search/search';This replaces the whole file. If you've customized search-form.tsx, move that logic into the Compass search component first.
AI Assistant
Wrap your root layout's children with CompassProvider and AiAssistant:
+ import AiAssistant from '@/sf-modules/compass/components/ai-assistant/ai-assistant';
+ import { CompassProvider } from '@/sf-modules/compass/contexts/compass-context';
+ import type { PropsWithChildren } from 'react';
export default function RootLayoutContentWrapper({ children }: PropsWithChildren) {
return (
+ <CompassProvider>
+ <AiAssistant>
{children}
+ </AiAssistant>
+ </CompassProvider>
);
}CompassProvider is an async Server Component. If your root layout wrapper is a Client Component ('use client'), Next.js won't let you render it there — add a small Server Component above it that wraps children with CompassProvider/AiAssistant instead. Verify with a build.
Use Case Comparison
Lets customers rate products by their own criteria. Three changes:
Add a showUseCases prop to ProductCardVertical:
+ import LatestUseCases from '@sf-modules/compass/components/use-cases/latest-use-cases';
export interface ProductCardVerticalProps {
/* ...other properties */
+ /**
+ * Show use cases ratings (uses product.$custom.description)
+ */
+ showUseCases?: boolean;
}
export default function ProductCardVertical({
product,
/* ...other props */
+ showUseCases,
}: ProductCardVerticalProps) {
return (
<>
{/* Product Rating component */}
+ {showUseCases && (
+ <div className="mt-auto pb-2 pt-2">
+ <LatestUseCases product={product} />
+ </div>
+ )}
{/* Decorated Price component */}
</>
);
}Pass the prop wherever ProductCardVertical is rendered in the products list:
- <ProductCardVertical /* ...other props */ />
+ <ProductCardVertical /* ...other props */ showUseCases />Wrap the page with UseCasesProvider and add UseCasesManager to the filters sidebar:
+ import UseCasesManager from '@/sf-modules/compass/components/use-cases/use-cases-manager';
+ import { UseCasesProvider } from '@/sf-modules/compass/contexts/use-cases-context';
export default function ProductsListingPage(/* ...props */) {
return (
+ <UseCasesProvider>
{/* ... */}
<FiltersContainer>
+ <FilterGroup title={'Use cases'}>
+ <UseCasesManager />
+ </FilterGroup>
{/* ...other filter groups */}
</FiltersContainer>
{/* ... */}
+ </UseCasesProvider>
);
}Render ProductListingMessage under the page title:
+ import ProductListingMessage from '@/sf-modules/compass/components/ai-assistant/product-listing-message';
export default function ProductsListingPage({
/* ...other props */
+ searchParams,
title,
}: ProductsListingPageProps) {
const { products } = productsCatalog;
return (
<>
{/* ... */}
<h1 data-testid="category-title">
{title}
</h1>
+ <ProductListingMessage products={products} searchParams={searchParams} title={title} />
{/* ... */}
</>
);
}Product Page messages
Render ProductMessage after the breadcrumbs so the AI Assistant can surface product details in the chat:
+ import ProductMessage from '@/sf-modules/compass/components/ai-assistant/product-message';
export default function ProductPage(/* ...props */) {
return (
<>
<Breadcrumbs /* ... */ />
+ <ProductMessage product={product} />
{/* ... */}
</>
);
}Unified API overrides
Register Compass's custom fields and method overrides in your SAPCC Unified API extension:
+ import { compassCustomFields } from '@sf-modules-middleware/compass';
+ import { methods } from '@sf-modules-middleware/compass';
export const unifiedApiExtension = createUnifiedExtension({
// ...
+ methods: {
+ override: {
+ ...methods,
+ },
+ },
normalizers: {
addCustomFields: [
- {},
+ compassCustomFields,
],
},
});A fresh Storefront ships a placeholder {} here — replace it with compassCustomFields rather than adding alongside it. If you already have other custom fields registered, just add compassCustomFields to that array.
Localized error messages
Add Compass's error strings, shown by the AI Assistant on a generic server error or oversized request:
{
+ "Compass": {
+ "internalServerError": "Something went wrong. Please try again.",
+ "payloadTooLarge": "Your conversation has reached the size limit. Please start a new conversation."
+ }
} {
+ "Compass": {
+ "internalServerError": "Etwas ist schiefgelaufen. Bitte versuchen Sie es erneut.",
+ "payloadTooLarge": "Ihre Konversation hat das Größenlimit erreicht. Bitte starten Sie eine neue Konversation."
+ }
}Add the same keys to any other locales you support — Compass only ships English and German.
Request body parser configuration
AI workflows can exceed the Middleware's default body-parser limit. Raise it for the compass integration:
+ import type bodyParserNamespace from 'body-parser';
+ const bodyParserConfig: CreateServerOptions['bodyParser'] = ({ functionName, integrationName }) => {
+ const optionsMap: Record<string, Record<string, bodyParserNamespace.OptionsJson>> = {
+ compass: {
+ devToolsImport: {
+ limit: '2mb',
+ },
+ invoke: {
+ limit: '40mb',
+ },
+ },
+ };
+
+ return (
+ optionsMap[integrationName]?.[functionName] || {
+ limit: '100kb',
+ }
+ );
+ };
async function runApp() {
const app = await createServer(config, {
+ bodyParser: bodyParserConfig,
});
}invoke covers AI Assistant chat requests (can carry embedded images and full history). devToolsImport covers the Compass Dev Tools trace importer (/compass/devTools, dev-only) — uploaded trace dumps easily exceed the default 100kb limit without it. Add both regardless of install path; add further entries under optionsMap.compass if a future Compass endpoint hits 413 Payload Too Large.
Pin the zod dependency
@alokai/compass ships against a specific zod version (4.1.12 as of writing — check middleware.dependencies.zod in the installed version's module.json). Pin it so yarn's hoisting can't give another app in the monorepo a mismatched version:
{
+ "resolutions": {
+ "zod": "4.1.12"
+ }
}Already have a resolutions block? Add the zod entry to it instead of replacing it.
What next?
With the Alokai Compass module installed in your Storefront, you're ready to build your first AI workflow!