@ai.ntellect/core 0.1.81 → 0.1.84
Sign up to get free protection for your applications and to get access to all the features.
- package/README.FR.md +31 -60
- package/README.md +74 -96
- package/agent/handlers/ActionHandler.ts +1 -1
- package/agent/index.ts +85 -43
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +61 -33
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/llm/evaluator/context.js +3 -5
- package/dist/llm/evaluator/index.js +25 -29
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.js +30 -9
- package/dist/llm/synthesizer/index.d.ts +1 -5
- package/dist/llm/synthesizer/index.js +1 -5
- package/dist/memory/cache.d.ts +5 -5
- package/dist/memory/cache.js +19 -49
- package/dist/memory/persistent.d.ts +1 -1
- package/dist/memory/persistent.js +5 -6
- package/dist/services/queue.js +21 -8
- package/dist/t.d.ts +46 -0
- package/dist/t.js +102 -0
- package/dist/test.d.ts +68 -0
- package/dist/test.js +167 -0
- package/dist/types.d.ts +27 -3
- package/dist/types.js +9 -1
- package/dist/utils/inject-actions.js +1 -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/index.ts +0 -1
- package/llm/evaluator/context.ts +3 -5
- package/llm/evaluator/index.ts +25 -31
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +42 -13
- package/llm/synthesizer/index.ts +2 -10
- package/memory/cache.ts +23 -61
- package/memory/persistent.ts +7 -6
- package/package.json +3 -1
- package/services/queue.ts +21 -12
- package/t.ts +133 -0
- package/types.ts +14 -3
- package/utils/inject-actions.ts +1 -1
- package/utils/queue-item-transformer.ts +25 -11
- package/utils/sanitize-results.ts +66 -0
package/types.ts
CHANGED
@@ -126,9 +126,9 @@ export interface CacheMemoryOptions {
|
|
126
126
|
}
|
127
127
|
|
128
128
|
export interface CreateMemoryInput {
|
129
|
-
content:
|
129
|
+
content: any;
|
130
130
|
type: MemoryType;
|
131
|
-
data:
|
131
|
+
data: QueueResult[];
|
132
132
|
userId?: string;
|
133
133
|
scope?: MemoryScope;
|
134
134
|
}
|
@@ -137,7 +137,6 @@ export interface CacheMemoryType {
|
|
137
137
|
id: string;
|
138
138
|
type: MemoryType;
|
139
139
|
data: any;
|
140
|
-
purpose: string;
|
141
140
|
query: string;
|
142
141
|
embedding: Embedding;
|
143
142
|
userId?: string;
|
@@ -169,6 +168,18 @@ export interface Memory {
|
|
169
168
|
chunks?: MemoryChunk[];
|
170
169
|
}
|
171
170
|
|
171
|
+
export const ActionSchema = z.array(
|
172
|
+
z.object({
|
173
|
+
name: z.string(),
|
174
|
+
parameters: z.array(
|
175
|
+
z.object({
|
176
|
+
name: z.string(),
|
177
|
+
value: z.string(),
|
178
|
+
})
|
179
|
+
),
|
180
|
+
})
|
181
|
+
);
|
182
|
+
|
172
183
|
export enum MemoryType {
|
173
184
|
ACTION = "action",
|
174
185
|
CONVERSATION = "conversation",
|
package/utils/inject-actions.ts
CHANGED
@@ -5,7 +5,7 @@ export const injectActions = (actions: ActionSchema[]) => {
|
|
5
5
|
return actions.map((action) => {
|
6
6
|
const parameters = action.parameters as z.ZodObject<any>;
|
7
7
|
const schemaShape = Object.keys(parameters._def.shape()).join(", ");
|
8
|
-
const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments: { ${schemaShape} }`;
|
8
|
+
const actionString = `Name: ${action.name}, Description: ${action.description}, Arguments (STRICTLY REQUIRED): { ${schemaShape} }`;
|
9
9
|
return actionString;
|
10
10
|
});
|
11
11
|
};
|
@@ -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
|
+
}
|