@ai.ntellect/core 0.6.17 → 0.6.19

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.
Files changed (78) hide show
  1. package/.mocharc.json +1 -2
  2. package/README.md +123 -178
  3. package/dist/graph/controller.js +29 -6
  4. package/dist/graph/index.js +302 -62
  5. package/dist/index.js +21 -6
  6. package/dist/interfaces/index.js +15 -0
  7. package/dist/modules/agenda/adapters/node-cron/index.js +29 -0
  8. package/dist/modules/agenda/index.js +140 -0
  9. package/dist/{services/embedding.js → modules/embedding/adapters/ai/index.js} +24 -7
  10. package/dist/modules/embedding/index.js +59 -0
  11. package/dist/modules/memory/adapters/in-memory/index.js +210 -0
  12. package/dist/{memory → modules/memory}/adapters/meilisearch/index.js +97 -2
  13. package/dist/{memory → modules/memory}/adapters/redis/index.js +77 -15
  14. package/dist/modules/memory/index.js +103 -0
  15. package/dist/utils/{stringifiy-zod-schema.js → generate-action-schema.js} +5 -5
  16. package/graph/controller.ts +37 -13
  17. package/graph/index.ts +348 -73
  18. package/index.ts +24 -6
  19. package/interfaces/index.ts +346 -27
  20. package/modules/agenda/adapters/node-cron/index.ts +25 -0
  21. package/modules/agenda/index.ts +159 -0
  22. package/modules/embedding/adapters/ai/index.ts +42 -0
  23. package/modules/embedding/index.ts +45 -0
  24. package/modules/memory/adapters/in-memory/index.ts +203 -0
  25. package/{memory → modules/memory}/adapters/meilisearch/index.ts +114 -12
  26. package/modules/memory/adapters/redis/index.ts +164 -0
  27. package/modules/memory/index.ts +93 -0
  28. package/package.json +3 -1
  29. package/test/graph/index.test.ts +646 -0
  30. package/test/modules/agenda/node-cron.test.ts +286 -0
  31. package/test/modules/embedding/ai.test.ts +78 -0
  32. package/test/modules/memory/adapters/in-memory.test.ts +153 -0
  33. package/test/{memory → modules/memory}/adapters/meilisearch.test.ts +79 -75
  34. package/test/modules/memory/adapters/redis.test.ts +169 -0
  35. package/test/modules/memory/base.test.ts +230 -0
  36. package/test/services/agenda.test.ts +279 -280
  37. package/types/index.ts +82 -203
  38. package/utils/{stringifiy-zod-schema.ts → generate-action-schema.ts} +3 -3
  39. package/app/README.md +0 -36
  40. package/app/app/favicon.ico +0 -0
  41. package/app/app/globals.css +0 -21
  42. package/app/app/gun.ts +0 -0
  43. package/app/app/layout.tsx +0 -18
  44. package/app/app/page.tsx +0 -321
  45. package/app/eslint.config.mjs +0 -16
  46. package/app/next.config.ts +0 -7
  47. package/app/package-lock.json +0 -5912
  48. package/app/package.json +0 -31
  49. package/app/pnpm-lock.yaml +0 -4031
  50. package/app/postcss.config.mjs +0 -8
  51. package/app/public/file.svg +0 -1
  52. package/app/public/globe.svg +0 -1
  53. package/app/public/next.svg +0 -1
  54. package/app/public/vercel.svg +0 -1
  55. package/app/public/window.svg +0 -1
  56. package/app/tailwind.config.ts +0 -18
  57. package/app/tsconfig.json +0 -27
  58. package/dist/memory/index.js +0 -9
  59. package/dist/services/agenda.js +0 -115
  60. package/dist/services/queue.js +0 -142
  61. package/dist/utils/experimental-graph-rag.js +0 -152
  62. package/dist/utils/generate-object.js +0 -111
  63. package/dist/utils/inject-actions.js +0 -16
  64. package/dist/utils/queue-item-transformer.js +0 -24
  65. package/dist/utils/sanitize-results.js +0 -60
  66. package/memory/adapters/redis/index.ts +0 -103
  67. package/memory/index.ts +0 -22
  68. package/services/agenda.ts +0 -118
  69. package/services/embedding.ts +0 -26
  70. package/services/queue.ts +0 -145
  71. package/test/memory/adapters/redis.test.ts +0 -159
  72. package/test/memory/base.test.ts +0 -225
  73. package/test/services/queue.test.ts +0 -286
  74. package/utils/experimental-graph-rag.ts +0 -170
  75. package/utils/generate-object.ts +0 -117
  76. package/utils/inject-actions.ts +0 -19
  77. package/utils/queue-item-transformer.ts +0 -38
  78. package/utils/sanitize-results.ts +0 -66
@@ -1,117 +0,0 @@
1
- import { CoreMessage, LanguageModelV1, generateText } from "ai";
2
- import { z } from "zod";
3
-
4
- export const describeZodSchema = (schema: z.ZodType): string => {
5
- if (schema instanceof z.ZodObject) {
6
- const entries = Object.entries(schema.shape);
7
- const fields = entries.map(([key, value]) => {
8
- const description = (value as any)._def.description || "";
9
- const fieldSchema = describeZodSchema(value as z.ZodType);
10
- return description
11
- ? `${key}: ${fieldSchema} // ${description}`
12
- : `${key}: ${fieldSchema}`;
13
- });
14
- return `z.object({${fields.join(", ")}})`;
15
- }
16
-
17
- if (schema instanceof z.ZodArray) {
18
- return `z.array(${describeZodSchema(schema.element)})`;
19
- }
20
-
21
- if (schema instanceof z.ZodString) {
22
- return "z.string()";
23
- }
24
-
25
- if (schema instanceof z.ZodNumber) {
26
- return "z.number()";
27
- }
28
-
29
- if (schema instanceof z.ZodBoolean) {
30
- return "z.boolean()";
31
- }
32
-
33
- if (schema instanceof z.ZodOptional) {
34
- return `z.optional(${describeZodSchema(schema._def.innerType)})`;
35
- }
36
-
37
- if (schema instanceof z.ZodUnion) {
38
- return `z.union([${schema._def.options
39
- .map((option: z.ZodType) => describeZodSchema(option))
40
- .join(", ")}])`;
41
- }
42
-
43
- if (schema instanceof z.ZodEnum) {
44
- return `z.enum(${JSON.stringify(schema._def.values)})`;
45
- }
46
-
47
- if (schema instanceof z.ZodLiteral) {
48
- return `z.literal(${JSON.stringify(schema._def.value)})`;
49
- }
50
-
51
- return "z.unknown()"; // Fallback for unknown types
52
- };
53
-
54
- export const generateObject = async <T>(config: {
55
- model: LanguageModelV1;
56
- schema: z.ZodSchema;
57
- system: string;
58
- temperature: number;
59
- prompt?: string;
60
- messages?: CoreMessage[];
61
- }): Promise<{ object: T }> => {
62
- // Generate a detailed description of the schema
63
- const schemaDescription = describeZodSchema(config.schema);
64
-
65
- const baseContext = `
66
- ${config.system}
67
- EXPECTED SCHEMA:
68
- ${schemaDescription}
69
-
70
- BAD EXAMPLE:
71
- \`\`\`json
72
- {
73
- "key": "value"
74
- }
75
- \`\`\`
76
-
77
- GOOD EXAMPLE:
78
- {
79
- "key": "value"
80
- }
81
-
82
- OUTPUT ONLY THE JSON SCHEMA, NO 'TRIPLE QUOTES'JSON OR ANY OTHER TEXT. ONLY THE JSON SCHEMA.
83
- `;
84
-
85
- console.log("🔍 Generating object with context:");
86
- console.log(`${config.prompt}\n${baseContext}\n`);
87
- const response = await generateText({
88
- model: config.model,
89
- messages: !config.prompt
90
- ? [
91
- {
92
- role: "system",
93
- content: baseContext,
94
- },
95
- ...(config.messages ?? []),
96
- ]
97
- : undefined,
98
- system: config.system,
99
- temperature: config.temperature,
100
- prompt: !config.prompt ? undefined : `${config.prompt}\n\n${baseContext}`,
101
- });
102
-
103
- try {
104
- // Clean the response text from any markdown or code block markers
105
- const cleanText = response.text
106
- .replace(/```json\s*/g, "")
107
- .replace(/```\s*$/g, "")
108
- .trim();
109
-
110
- const parsedResponse = JSON.parse(cleanText);
111
- const validatedResponse = config.schema.parse(parsedResponse);
112
- return { object: validatedResponse as T };
113
- } catch (error) {
114
- console.error("Error parsing or validating JSON response:", error);
115
- throw new Error("Failed to generate valid JSON response");
116
- }
117
- };
@@ -1,19 +0,0 @@
1
- import { z } from "zod";
2
- import { ActionSchema } from "../types";
3
-
4
- export const injectActions = (actions: ActionSchema[]) => {
5
- return actions.map((action) => {
6
- const parameters = action.parameters as z.ZodObject<any>;
7
- const schemaShape = Object.keys(parameters._def.shape()).join(", ");
8
- const actionString = `* ${action.name}( { ${schemaShape} }) (${
9
- action.description
10
- }) ${
11
- action.examples
12
- ? `Eg: ${action.examples.map((example: any) => {
13
- return JSON.stringify(example);
14
- })}`
15
- : ""
16
- }`;
17
- return actionString;
18
- });
19
- };
@@ -1,38 +0,0 @@
1
- import { QueueItem, QueueItemParameter, QueueResult } from "../types";
2
-
3
- export class QueueItemTransformer {
4
- static transformActionToQueueItem(action: {
5
- name: string;
6
- parameters: Record<string, any>;
7
- }): QueueItem {
8
- return {
9
- name: action.name || "",
10
- parameters: QueueItemTransformer.transformParameters(
11
- action.parameters || {}
12
- ),
13
- };
14
- }
15
-
16
- static transformFromSimilarActions(
17
- similarActions: QueueResult[]
18
- ): QueueItem[] | undefined {
19
- return similarActions?.map((action: QueueResult) =>
20
- QueueItemTransformer.transformActionToQueueItem(action)
21
- );
22
- }
23
-
24
- private static transformParameters(
25
- parameters: Record<string, any>
26
- ): QueueItemParameter[] {
27
- return Object.entries(parameters).map(([name, value]) => ({
28
- name,
29
- value: typeof value === "object" ? JSON.stringify(value) : String(value),
30
- }));
31
- }
32
-
33
- static transformActionsToQueueItems(
34
- actions: { name: string; parameters: Record<string, any> }[] | undefined
35
- ): QueueItem[] | undefined {
36
- return actions?.map((action) => this.transformActionToQueueItem(action));
37
- }
38
- }
@@ -1,66 +0,0 @@
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
- }