@ai.ntellect/core 0.1.83 → 0.1.85

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.
@@ -1,26 +1,40 @@
1
- import { ActionData, QueueItemParameter, TransformedQueueItem } from "../types";
1
+ import {
2
+ ActionData,
3
+ QueueItemParameter,
4
+ QueueResult,
5
+ TransformedQueueItem,
6
+ } from "../types";
2
7
 
3
8
  export class QueueItemTransformer {
4
9
  static transformActionToQueueItem(action: ActionData): TransformedQueueItem {
5
10
  return {
6
- name: action.name || '',
7
- parameters: QueueItemTransformer.transformParameters(action.parameters || {})
11
+ name: action.name || "",
12
+ parameters: QueueItemTransformer.transformParameters(
13
+ action.parameters || {}
14
+ ),
8
15
  };
9
16
  }
10
17
 
11
- static transformFromSimilarActions(similarActions: any[]): TransformedQueueItem[] | undefined {
12
- const firstMatch = similarActions?.[0]?.data;
13
- return firstMatch?.map((action: ActionData) => QueueItemTransformer.transformActionToQueueItem(action));
18
+ static transformFromSimilarActions(
19
+ similarActions: QueueResult[]
20
+ ): TransformedQueueItem[] | undefined {
21
+ return similarActions?.map((action: ActionData) =>
22
+ QueueItemTransformer.transformActionToQueueItem(action)
23
+ );
14
24
  }
15
25
 
16
- private static transformParameters(parameters: Record<string, any>): QueueItemParameter[] {
26
+ private static transformParameters(
27
+ parameters: Record<string, any>
28
+ ): QueueItemParameter[] {
17
29
  return Object.entries(parameters).map(([name, value]) => ({
18
30
  name,
19
- value: typeof value === 'object' ? JSON.stringify(value) : String(value)
31
+ value: typeof value === "object" ? JSON.stringify(value) : String(value),
20
32
  }));
21
33
  }
22
34
 
23
- static transformActionsToQueueItems(actions: ActionData[] | undefined): TransformedQueueItem[] | undefined {
24
- return actions?.map(action => this.transformActionToQueueItem(action));
35
+ static transformActionsToQueueItems(
36
+ actions: ActionData[] | undefined
37
+ ): TransformedQueueItem[] | undefined {
38
+ return actions?.map((action) => this.transformActionToQueueItem(action));
25
39
  }
26
- }
40
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Utility class to sanitize JSON results for evaluation
3
+ */
4
+ export class ResultSanitizer {
5
+ /**
6
+ * Sanitizes JSON results by removing special characters and formatting
7
+ * @param results - The results to sanitize
8
+ * @returns Sanitized string
9
+ */
10
+ static sanitize(results: any): string {
11
+ if (!results) return "";
12
+
13
+ try {
14
+ const jsonString = JSON.stringify(results);
15
+ return (
16
+ jsonString
17
+ // Basic cleanup
18
+ .replace(/\\n/g, " ") // Remove newlines
19
+ .replace(/\s+/g, " ") // Remove extra spaces
20
+ .replace(/\\"/g, '"') // Fix escaped quotes
21
+ .replace(/\\+/g, "") // Remove extra backslashes
22
+
23
+ // Remove unnecessary quotes around objects and arrays
24
+ .replace(/"\[/g, "[") // Remove quotes around arrays start
25
+ .replace(/\]"/g, "]") // Remove quotes around arrays end
26
+ .replace(/"{/g, "{") // Remove quotes around objects start
27
+ .replace(/}"/g, "}") // Remove quotes around objects end
28
+
29
+ // Clean up numbers and values
30
+ .replace(/"(\d+\.?\d*)"/g, "$1") // Remove quotes around numbers
31
+ .replace(/:\s*"(true|false|null)"/g, ": $1") // Remove quotes around booleans and null
32
+
33
+ // Clean up URLs and content
34
+ .replace(
35
+ /(?<=content":")([^"]+)(?=")/g,
36
+ (match) => match.trim().replace(/\s+/g, " ") // Clean content spacing
37
+ )
38
+ .replace(
39
+ /(?<=link":")([^"]+)(?=")/g,
40
+ (match) => match.replace(/&amp;/g, "&") // Fix URL encodings
41
+ )
42
+
43
+ // Final cleanup
44
+ .replace(/,\s*([}\]])/g, "$1") // Remove trailing commas
45
+ .replace(/:\s+/g, ":") // Remove spaces after colons
46
+ .replace(/,\s+/g, ",") // Remove spaces after commas
47
+ .trim()
48
+ ); // Remove leading/trailing whitespace
49
+ } catch (error) {
50
+ console.error("Error sanitizing results:", error);
51
+ return String(results);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Formats numbers to a consistent format
57
+ * @param value - The number to format
58
+ * @returns Formatted number string
59
+ */
60
+ private static formatNumber(value: number): string {
61
+ return value.toLocaleString("en-US", {
62
+ maximumFractionDigits: 2,
63
+ useGrouping: false,
64
+ });
65
+ }
66
+ }