Skip to content

Commit f103c94

Browse files
cursoragentfacundo.yuffrida
andcommitted
Refactor: Sanitize product name for AI description generation
Co-authored-by: facundo.yuffrida <facundo.yuffrida@commerce.com>
1 parent 2cd4478 commit f103c94

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • src/app/productDescription/[productId]

src/app/productDescription/[productId]/form.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import Loader from '~/components/Loader';
1212
import { useAppContext } from '~/context/AppContext';
1313
import { useTracking } from '~/hooks/useTracking';
1414

15+
const sanitizeProductNameForGeneration = (name: string) =>
16+
name.replaceAll('#', '').replace(/\s{2,}/g, ' ').trim();
17+
1518
export default function Form({
1619
product,
1720
csrfToken,
@@ -43,10 +46,19 @@ export default function Form({
4346

4447
const handleGenerateDescription = async () => {
4548
setIsLoading(true);
49+
50+
// BigCommerce product names may contain '#' (e.g. for internal naming). For the
51+
// /productDescription/${id} generator flow we strip those symbols only for the AI
52+
// generation request, then keep the original name unchanged everywhere else.
53+
const productForGeneration = {
54+
...product,
55+
name: sanitizeProductNameForGeneration(product.name),
56+
} satisfies Product | NewProduct;
57+
4658
const res = await fetch(`/api/generateDescription`, {
4759
method: 'POST',
4860
body: JSON.stringify(
49-
prepareAiPromptAttributes(currentAttributes, product)
61+
prepareAiPromptAttributes(currentAttributes, productForGeneration)
5062
),
5163
headers: {
5264
'X-CSRF-Token': csrfToken,

0 commit comments

Comments
 (0)