@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.
- package/agent/index.ts +52 -25
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.js +41 -22
- package/dist/llm/evaluator/context.js +3 -5
- package/dist/llm/evaluator/index.js +25 -29
- package/dist/llm/orchestrator/index.js +10 -13
- package/dist/llm/synthesizer/index.d.ts +1 -5
- package/dist/llm/synthesizer/index.js +1 -5
- package/dist/memory/cache.d.ts +1 -1
- package/dist/memory/cache.js +2 -35
- package/dist/memory/persistent.d.ts +1 -1
- package/dist/memory/persistent.js +3 -3
- package/dist/test.d.ts +28 -0
- package/dist/test.js +36 -4
- package/dist/types.d.ts +26 -1
- package/dist/types.js +9 -1
- package/dist/utils/queue-item-transformer.d.ts +2 -2
- package/dist/utils/queue-item-transformer.js +5 -6
- package/dist/utils/sanitize-results.d.ts +17 -0
- package/dist/utils/sanitize-results.js +60 -0
- package/llm/evaluator/context.ts +29 -25
- package/llm/evaluator/index.ts +25 -31
- package/llm/orchestrator/index.ts +9 -17
- package/llm/synthesizer/index.ts +2 -10
- package/memory/cache.ts +4 -42
- package/memory/persistent.ts +3 -3
- package/package.json +1 -1
- package/types.ts +13 -1
- package/utils/queue-item-transformer.ts +25 -11
- package/utils/sanitize-results.ts +66 -0
@@ -1,26 +1,40 @@
|
|
1
|
-
import {
|
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(
|
11
|
+
name: action.name || "",
|
12
|
+
parameters: QueueItemTransformer.transformParameters(
|
13
|
+
action.parameters || {}
|
14
|
+
),
|
8
15
|
};
|
9
16
|
}
|
10
17
|
|
11
|
-
static transformFromSimilarActions(
|
12
|
-
|
13
|
-
|
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(
|
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 ===
|
31
|
+
value: typeof value === "object" ? JSON.stringify(value) : String(value),
|
20
32
|
}));
|
21
33
|
}
|
22
34
|
|
23
|
-
static transformActionsToQueueItems(
|
24
|
-
|
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(/&/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
|
+
}
|