@ai.ntellect/core 0.6.0 → 0.6.2
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/create-llm-to-select-multiple-graph copy.ts +243 -0
- package/create-llm-to-select-multiple-graph.ts +148 -0
- package/dist/create-llm-to-select-multiple-graph copy.js +201 -0
- package/dist/create-llm-to-select-multiple-graph.js +142 -0
- package/dist/graph/controller.js +6 -6
- package/dist/graph/engine.js +198 -135
- package/dist/index copy.js +76 -0
- package/dist/utils/setup-graphs.js +28 -0
- package/dist/utils/stringifiy-zod-schema.js +41 -0
- package/graph/controller.ts +11 -9
- package/graph/engine.ts +244 -166
- package/index copy.ts +81 -0
- package/index.ts +1 -1
- package/package.json +1 -1
- package/test/graph/engine.test.ts +27 -44
- package/tsconfig.json +1 -1
- package/types/index.ts +11 -3
- package/utils/setup-graphs.ts +45 -0
- package/utils/stringifiy-zod-schema.ts +45 -0
- package/dist/test/graph/controller.test.js +0 -170
- package/dist/test/graph/engine.test.js +0 -465
- package/dist/test/memory/adapters/meilisearch.test.js +0 -250
- package/dist/test/memory/adapters/redis.test.js +0 -143
- package/dist/test/memory/base.test.js +0 -209
- package/dist/test/services/agenda.test.js +0 -230
- package/dist/test/services/queue.test.js +0 -258
- package/dist/utils/schema-generator.js +0 -46
- package/dist/utils/state-manager.js +0 -20
- package/utils/generate-object.js +0 -111
- package/utils/header-builder.js +0 -34
- package/utils/inject-actions.js +0 -16
- package/utils/queue-item-transformer.js +0 -24
- package/utils/sanitize-results.js +0 -60
- package/utils/schema-generator.js +0 -46
- package/utils/schema-generator.ts +0 -73
- package/utils/state-manager.js +0 -20
- package/utils/state-manager.ts +0 -30
package/utils/header-builder.js
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.LLMHeaderBuilder = void 0;
|
4
|
-
class LLMHeaderBuilder {
|
5
|
-
constructor() {
|
6
|
-
this.headers = new Map();
|
7
|
-
this._result = "";
|
8
|
-
}
|
9
|
-
addHeader(key, value) {
|
10
|
-
if (Array.isArray(value)) {
|
11
|
-
this.headers.set(key, value.join("\n"));
|
12
|
-
}
|
13
|
-
else {
|
14
|
-
this.headers.set(key, value);
|
15
|
-
}
|
16
|
-
// Build result immediately
|
17
|
-
this._result = Array.from(this.headers.entries())
|
18
|
-
.filter(([_, value]) => value !== undefined)
|
19
|
-
.map(([key, value]) => `# ${key}: ${value}`)
|
20
|
-
.join("\n")
|
21
|
-
.trim();
|
22
|
-
return this;
|
23
|
-
}
|
24
|
-
valueOf() {
|
25
|
-
return this._result;
|
26
|
-
}
|
27
|
-
toString() {
|
28
|
-
return this._result;
|
29
|
-
}
|
30
|
-
static create() {
|
31
|
-
return new LLMHeaderBuilder();
|
32
|
-
}
|
33
|
-
}
|
34
|
-
exports.LLMHeaderBuilder = LLMHeaderBuilder;
|
package/utils/inject-actions.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.injectActions = void 0;
|
4
|
-
const injectActions = (actions) => {
|
5
|
-
return actions.map((action) => {
|
6
|
-
const parameters = action.parameters;
|
7
|
-
const schemaShape = Object.keys(parameters._def.shape()).join(", ");
|
8
|
-
const actionString = `* ${action.name}( { ${schemaShape} }) (${action.description}) ${action.examples
|
9
|
-
? `Eg: ${action.examples.map((example) => {
|
10
|
-
return JSON.stringify(example);
|
11
|
-
})}`
|
12
|
-
: ""}`;
|
13
|
-
return actionString;
|
14
|
-
});
|
15
|
-
};
|
16
|
-
exports.injectActions = injectActions;
|
@@ -1,24 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.QueueItemTransformer = void 0;
|
4
|
-
class QueueItemTransformer {
|
5
|
-
static transformActionToQueueItem(action) {
|
6
|
-
return {
|
7
|
-
name: action.name || "",
|
8
|
-
parameters: QueueItemTransformer.transformParameters(action.parameters || {}),
|
9
|
-
};
|
10
|
-
}
|
11
|
-
static transformFromSimilarActions(similarActions) {
|
12
|
-
return similarActions === null || similarActions === void 0 ? void 0 : similarActions.map((action) => QueueItemTransformer.transformActionToQueueItem(action));
|
13
|
-
}
|
14
|
-
static transformParameters(parameters) {
|
15
|
-
return Object.entries(parameters).map(([name, value]) => ({
|
16
|
-
name,
|
17
|
-
value: typeof value === "object" ? JSON.stringify(value) : String(value),
|
18
|
-
}));
|
19
|
-
}
|
20
|
-
static transformActionsToQueueItems(actions) {
|
21
|
-
return actions === null || actions === void 0 ? void 0 : actions.map((action) => this.transformActionToQueueItem(action));
|
22
|
-
}
|
23
|
-
}
|
24
|
-
exports.QueueItemTransformer = QueueItemTransformer;
|
@@ -1,60 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ResultSanitizer = void 0;
|
4
|
-
/**
|
5
|
-
* Utility class to sanitize JSON results for evaluation
|
6
|
-
*/
|
7
|
-
class ResultSanitizer {
|
8
|
-
/**
|
9
|
-
* Sanitizes JSON results by removing special characters and formatting
|
10
|
-
* @param results - The results to sanitize
|
11
|
-
* @returns Sanitized string
|
12
|
-
*/
|
13
|
-
static sanitize(results) {
|
14
|
-
if (!results)
|
15
|
-
return "";
|
16
|
-
try {
|
17
|
-
const jsonString = JSON.stringify(results);
|
18
|
-
return (jsonString
|
19
|
-
// Basic cleanup
|
20
|
-
.replace(/\\n/g, " ") // Remove newlines
|
21
|
-
.replace(/\s+/g, " ") // Remove extra spaces
|
22
|
-
.replace(/\\"/g, '"') // Fix escaped quotes
|
23
|
-
.replace(/\\+/g, "") // Remove extra backslashes
|
24
|
-
// Remove unnecessary quotes around objects and arrays
|
25
|
-
.replace(/"\[/g, "[") // Remove quotes around arrays start
|
26
|
-
.replace(/\]"/g, "]") // Remove quotes around arrays end
|
27
|
-
.replace(/"{/g, "{") // Remove quotes around objects start
|
28
|
-
.replace(/}"/g, "}") // Remove quotes around objects end
|
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
|
-
// Clean up URLs and content
|
33
|
-
.replace(/(?<=content":")([^"]+)(?=")/g, (match) => match.trim().replace(/\s+/g, " ") // Clean content spacing
|
34
|
-
)
|
35
|
-
.replace(/(?<=link":")([^"]+)(?=")/g, (match) => match.replace(/&/g, "&") // Fix URL encodings
|
36
|
-
)
|
37
|
-
// Final cleanup
|
38
|
-
.replace(/,\s*([}\]])/g, "$1") // Remove trailing commas
|
39
|
-
.replace(/:\s+/g, ":") // Remove spaces after colons
|
40
|
-
.replace(/,\s+/g, ",") // Remove spaces after commas
|
41
|
-
.trim()); // Remove leading/trailing whitespace
|
42
|
-
}
|
43
|
-
catch (error) {
|
44
|
-
console.error("Error sanitizing results:", error);
|
45
|
-
return String(results);
|
46
|
-
}
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* Formats numbers to a consistent format
|
50
|
-
* @param value - The number to format
|
51
|
-
* @returns Formatted number string
|
52
|
-
*/
|
53
|
-
static formatNumber(value) {
|
54
|
-
return value.toLocaleString("en-US", {
|
55
|
-
maximumFractionDigits: 2,
|
56
|
-
useGrouping: false,
|
57
|
-
});
|
58
|
-
}
|
59
|
-
}
|
60
|
-
exports.ResultSanitizer = ResultSanitizer;
|
@@ -1,46 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SchemaGenerator = void 0;
|
4
|
-
const zod_1 = require("zod");
|
5
|
-
class SchemaGenerator {
|
6
|
-
static generate(config) {
|
7
|
-
const { schema, instructions = "Output only the JSON schema, no 'triple quotes'json or any other text. Only the JSON schema.", outputExamples = [], } = config;
|
8
|
-
const getSchemaString = (schema) => {
|
9
|
-
if (schema instanceof zod_1.z.ZodObject) {
|
10
|
-
const entries = Object.entries(schema.shape);
|
11
|
-
const fields = entries.map(([key, value]) => {
|
12
|
-
const description = value._def.description;
|
13
|
-
const schemaStr = getSchemaString(value);
|
14
|
-
return description
|
15
|
-
? `${key}: ${schemaStr} // ${description}`
|
16
|
-
: `${key}: ${schemaStr}`;
|
17
|
-
});
|
18
|
-
return `z.object({${fields.join(", ")}})`;
|
19
|
-
}
|
20
|
-
if (schema instanceof zod_1.z.ZodArray) {
|
21
|
-
return `z.array(${getSchemaString(schema.element)})`;
|
22
|
-
}
|
23
|
-
if (schema instanceof zod_1.z.ZodString) {
|
24
|
-
return "z.string()";
|
25
|
-
}
|
26
|
-
if (schema instanceof zod_1.z.ZodNumber) {
|
27
|
-
return "z.number()";
|
28
|
-
}
|
29
|
-
if (schema instanceof zod_1.z.ZodBoolean) {
|
30
|
-
return "z.boolean()";
|
31
|
-
}
|
32
|
-
// Fallback for other Zod types
|
33
|
-
return `z.unknown()`;
|
34
|
-
};
|
35
|
-
const schemaString = getSchemaString(schema);
|
36
|
-
return {
|
37
|
-
schema: schemaString,
|
38
|
-
instructions,
|
39
|
-
outputExamples: outputExamples
|
40
|
-
.map((example) => `Input: ${JSON.stringify(example.input)}, Output: ${JSON.stringify(example.output)}`)
|
41
|
-
.join("\n")
|
42
|
-
.trim(),
|
43
|
-
};
|
44
|
-
}
|
45
|
-
}
|
46
|
-
exports.SchemaGenerator = SchemaGenerator;
|
@@ -1,73 +0,0 @@
|
|
1
|
-
import { z } from "zod";
|
2
|
-
|
3
|
-
export interface SchemaConfig {
|
4
|
-
schema: z.ZodType;
|
5
|
-
instructions?: string;
|
6
|
-
outputExamples?: {
|
7
|
-
input: string;
|
8
|
-
output: string;
|
9
|
-
}[];
|
10
|
-
}
|
11
|
-
|
12
|
-
export class SchemaGenerator {
|
13
|
-
static generate(config: SchemaConfig): {
|
14
|
-
schema: string;
|
15
|
-
instructions: string;
|
16
|
-
outputExamples: string;
|
17
|
-
} {
|
18
|
-
const {
|
19
|
-
schema,
|
20
|
-
instructions = "Output only the JSON schema, no 'triple quotes'json or any other text. Only the JSON schema.",
|
21
|
-
outputExamples = [],
|
22
|
-
} = config;
|
23
|
-
|
24
|
-
const getSchemaString = (schema: z.ZodType): string => {
|
25
|
-
if (schema instanceof z.ZodObject) {
|
26
|
-
const entries = Object.entries(schema.shape);
|
27
|
-
const fields = entries.map(([key, value]) => {
|
28
|
-
const description = (value as any)._def.description;
|
29
|
-
const schemaStr = getSchemaString(value as z.ZodType);
|
30
|
-
return description
|
31
|
-
? `${key}: ${schemaStr} // ${description}`
|
32
|
-
: `${key}: ${schemaStr}`;
|
33
|
-
});
|
34
|
-
return `z.object({${fields.join(", ")}})`;
|
35
|
-
}
|
36
|
-
|
37
|
-
if (schema instanceof z.ZodArray) {
|
38
|
-
return `z.array(${getSchemaString(schema.element)})`;
|
39
|
-
}
|
40
|
-
|
41
|
-
if (schema instanceof z.ZodString) {
|
42
|
-
return "z.string()";
|
43
|
-
}
|
44
|
-
|
45
|
-
if (schema instanceof z.ZodNumber) {
|
46
|
-
return "z.number()";
|
47
|
-
}
|
48
|
-
|
49
|
-
if (schema instanceof z.ZodBoolean) {
|
50
|
-
return "z.boolean()";
|
51
|
-
}
|
52
|
-
|
53
|
-
// Fallback for other Zod types
|
54
|
-
return `z.unknown()`;
|
55
|
-
};
|
56
|
-
|
57
|
-
const schemaString = getSchemaString(schema);
|
58
|
-
|
59
|
-
return {
|
60
|
-
schema: schemaString,
|
61
|
-
instructions,
|
62
|
-
outputExamples: outputExamples
|
63
|
-
.map(
|
64
|
-
(example) =>
|
65
|
-
`Input: ${JSON.stringify(example.input)}, Output: ${JSON.stringify(
|
66
|
-
example.output
|
67
|
-
)}`
|
68
|
-
)
|
69
|
-
.join("\n")
|
70
|
-
.trim(),
|
71
|
-
};
|
72
|
-
}
|
73
|
-
}
|
package/utils/state-manager.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.StateManager = void 0;
|
4
|
-
class StateManager {
|
5
|
-
/**
|
6
|
-
* Updates the shared state while preserving immutability
|
7
|
-
* @param currentState Current shared state
|
8
|
-
* @param updates Partial updates to apply
|
9
|
-
* @returns Updated shared state
|
10
|
-
*/
|
11
|
-
static updateState(state, updates) {
|
12
|
-
return Object.assign(Object.assign({}, state), { context: Object.assign(Object.assign({}, (state.context || {})), updates) });
|
13
|
-
}
|
14
|
-
static createUpdate(updates) {
|
15
|
-
return {
|
16
|
-
context: Object.assign({}, updates),
|
17
|
-
};
|
18
|
-
}
|
19
|
-
}
|
20
|
-
exports.StateManager = StateManager;
|
package/utils/state-manager.ts
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import { SharedState } from "../types";
|
2
|
-
|
3
|
-
export class StateManager {
|
4
|
-
/**
|
5
|
-
* Updates the shared state while preserving immutability
|
6
|
-
* @param currentState Current shared state
|
7
|
-
* @param updates Partial updates to apply
|
8
|
-
* @returns Updated shared state
|
9
|
-
*/
|
10
|
-
static updateState<T>(
|
11
|
-
state: SharedState<T>,
|
12
|
-
updates: Partial<T>
|
13
|
-
): SharedState<T> {
|
14
|
-
return {
|
15
|
-
...state,
|
16
|
-
context: {
|
17
|
-
...(state.context || {}),
|
18
|
-
...updates,
|
19
|
-
},
|
20
|
-
};
|
21
|
-
}
|
22
|
-
|
23
|
-
static createUpdate<T>(updates: Partial<T>) {
|
24
|
-
return {
|
25
|
-
context: {
|
26
|
-
...updates,
|
27
|
-
},
|
28
|
-
};
|
29
|
-
}
|
30
|
-
}
|