lwazi 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lwazi",
3
- "version": "1.8.2",
3
+ "version": "1.8.3",
4
4
  "description": "Lwazi is an AI assistant for Laravel. Install with one command to add an AI assistant to your Laravel app.",
5
5
  "main": "bin/lwazi.js",
6
6
  "bin": {
@@ -93,10 +93,20 @@ class LwaziService
93
93
  }
94
94
  }
95
95
 
96
- $dataResponse = $this->fetchRelevantData($message);
97
- if ($dataResponse) {
98
- $this->conversationHistory[] = ['role' => 'assistant', 'content' => $dataResponse];
99
- return $dataResponse;
96
+ if ($intent === 'content') {
97
+ $contentResponse = $this->searchContent($message);
98
+ if ($contentResponse) {
99
+ $this->conversationHistory[] = ['role' => 'assistant', 'content' => $contentResponse];
100
+ return $contentResponse;
101
+ }
102
+ }
103
+
104
+ if ($intent === 'data') {
105
+ $dataResponse = $this->fetchRelevantData($message);
106
+ if ($dataResponse) {
107
+ $this->conversationHistory[] = ['role' => 'assistant', 'content' => $dataResponse];
108
+ return $dataResponse;
109
+ }
100
110
  }
101
111
 
102
112
  $prompt = $this->buildPrompt();
@@ -315,23 +325,35 @@ class LwaziService
315
325
  protected function findBestRouteWithTerms(array $routes, array $terms): ?string
316
326
  {
317
327
  $scored = [];
328
+ $termSet = array_filter(array_map('strtolower', array_map('trim', $terms)), fn($t) => strlen($t) >= 3);
329
+
330
+ if (empty($termSet)) {
331
+ return null;
332
+ }
333
+
318
334
  foreach ($routes as $r) {
319
335
  $uri = strtolower($r['uri'] ?? '');
320
- if ($uri === '') continue;
336
+ if ($uri === '' || $uri === '/') continue;
321
337
 
338
+ $uriClean = preg_replace('/[^a-z0-9]/', '', $uri);
339
+
340
+ $hasExactMatch = false;
322
341
  $score = 0;
323
- foreach ($terms as $term) {
324
- $term = strtolower(trim($term));
325
- if (strlen($term) < 2) continue;
326
- if (str_contains($uri, $term)) {
327
- $score += 10;
328
- if ($uri === $term || $uri === '/' . $term) {
329
- $score += 20;
330
- }
342
+
343
+ foreach ($termSet as $term) {
344
+ $termClean = preg_replace('/[^a-z0-9]/', '', $term);
345
+
346
+ if (strlen($termClean) < 3) continue;
347
+
348
+ if ($uri === '/' . $term || $uri === $term || str_contains($uri, '/' . $term . '/')) {
349
+ $hasExactMatch = true;
350
+ $score += 50;
351
+ } elseif (!empty($termClean) && str_contains($uriClean, $termClean)) {
352
+ $score += 5;
331
353
  }
332
354
  }
333
355
 
334
- if ($score > 0) {
356
+ if ($hasExactMatch && $score > 0) {
335
357
  $scored[] = ['uri' => $r['uri'], 'score' => $score];
336
358
  }
337
359
  }