Browse Source

fix: model number regex matches digit-first patterns (e.g. 2259W-5, 1436W-6)

Previous regex [A-Z]{1,4}\d{3,} only matched letter-first models.
Now also matches \d{2,}[A-Z]\d*[-\w]* for Homelegance digit-first models.
Applies to both stock lookup and product image intent detection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T 5 days ago
parent
commit
10f612cab7
1 changed files with 3 additions and 3 deletions
  1. 3 3
      server/routers.ts

+ 3 - 3
server/routers.ts

@@ -394,8 +394,8 @@ export const appRouter = router({
 
             // 5. Stock / inventory
             if (!erpContext && /\b(in stock|available|inventory|stock|availability)\b/.test(msgLower)) {
-              // Try to extract a model number: capital letters + digits, e.g. "B1234-1"
-              const modelMatch = msg.match(/\b([A-Z]{1,4}[-\s]?\d{3,}[-\w]*)\b/);
+              // Match model numbers: letter-first (B1234-1) or digit-first (2259W-5, 1436W-6)
+              const modelMatch = msg.match(/\b([A-Z]{1,4}\d{2,}[-\w]*|\d{2,}[A-Z]\d*[-\w]*)\b/i);
               if (modelMatch) {
                 erpContext = await lookupStock({ model: modelMatch[1] }, userCtx);
               }
@@ -418,7 +418,7 @@ export const appRouter = router({
 
             // 7. Product images — "show image/photo/picture of [model]" or "image for 1436W-6"
             if (!erpContext && /\b(image|images|photo|photos|picture|pictures|what does .* look like|show me)\b/.test(msgLower)) {
-              const modelMatch = msg.match(/\b([A-Z]{1,5}[-]?\d{3,}[-\w]*)\b/);
+              const modelMatch = msg.match(/\b([A-Z]{1,4}\d{2,}[-\w]*|\d{2,}[A-Z]\d*[-\w]*)\b/i);
               if (modelMatch) {
                 erpContext = await lookupProductImages(modelMatch[1], userCtx);
               }