@delofarag/ai-utils 1.4.2 → 1.5.0

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 (126) hide show
  1. package/README.md +354 -216
  2. package/dist/chatbot.d.ts +33 -0
  3. package/dist/chatbot.d.ts.map +1 -0
  4. package/dist/chatbot.js +72 -0
  5. package/dist/chatbot.js.map +1 -0
  6. package/dist/heart/agent.d.ts +1 -1
  7. package/dist/heart/agent.d.ts.map +1 -1
  8. package/dist/heart/agent.js +3 -8
  9. package/dist/heart/agent.js.map +1 -1
  10. package/dist/heart/chain.d.ts +1 -1
  11. package/dist/heart/chain.d.ts.map +1 -1
  12. package/dist/heart/chain.js +4 -4
  13. package/dist/heart/chain.js.map +1 -1
  14. package/dist/heart/chatbot.d.ts +1 -1
  15. package/dist/heart/memorychain.d.ts +2 -2
  16. package/dist/heart/memorychain.js +6 -6
  17. package/dist/heart/memorychain.js.map +1 -1
  18. package/dist/heart/tools/zodios/ZodiosToolRegistry.d.ts +1 -1
  19. package/dist/heart/tools/zodios/ZodiosToolRegistry.d.ts.map +1 -1
  20. package/dist/helpers/chatbot.d.ts +33 -0
  21. package/dist/helpers/chatbot.d.ts.map +1 -0
  22. package/dist/helpers/chatbot.js +72 -0
  23. package/dist/helpers/chatbot.js.map +1 -0
  24. package/dist/helpers/helpers.d.ts +25 -0
  25. package/dist/helpers/helpers.d.ts.map +1 -0
  26. package/dist/helpers/helpers.js +43 -0
  27. package/dist/helpers/helpers.js.map +1 -0
  28. package/dist/helpers/llms.d.ts +92 -0
  29. package/dist/helpers/llms.d.ts.map +1 -0
  30. package/dist/helpers/llms.js +49 -0
  31. package/dist/helpers/llms.js.map +1 -0
  32. package/dist/helpers/memory.d.ts +91 -0
  33. package/dist/helpers/memory.d.ts.map +1 -0
  34. package/dist/helpers/memory.js +351 -0
  35. package/dist/helpers/memory.js.map +1 -0
  36. package/dist/helpers/rag.d.ts +42 -0
  37. package/dist/helpers/rag.d.ts.map +1 -0
  38. package/dist/helpers/rag.js +66 -0
  39. package/dist/helpers/rag.js.map +1 -0
  40. package/dist/helpers.d.ts +3 -3
  41. package/dist/index.d.ts +10 -10
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +10 -10
  44. package/dist/index.js.map +1 -1
  45. package/dist/magic-funcs/answerers/ask.d.ts +18 -2
  46. package/dist/magic-funcs/answerers/ask.d.ts.map +1 -1
  47. package/dist/magic-funcs/answerers/ask.js +20 -9
  48. package/dist/magic-funcs/answerers/ask.js.map +1 -1
  49. package/dist/magic-funcs/answerers/websearch.d.ts +15 -0
  50. package/dist/magic-funcs/answerers/websearch.d.ts.map +1 -1
  51. package/dist/magic-funcs/answerers/websearch.js +15 -0
  52. package/dist/magic-funcs/answerers/websearch.js.map +1 -1
  53. package/dist/magic-funcs/evaluators/classify.d.ts +20 -1
  54. package/dist/magic-funcs/evaluators/classify.d.ts.map +1 -1
  55. package/dist/magic-funcs/evaluators/classify.js +22 -3
  56. package/dist/magic-funcs/evaluators/classify.js.map +1 -1
  57. package/dist/magic-funcs/evaluators/decide.d.ts +18 -0
  58. package/dist/magic-funcs/evaluators/decide.d.ts.map +1 -1
  59. package/dist/magic-funcs/evaluators/decide.js +21 -3
  60. package/dist/magic-funcs/evaluators/decide.js.map +1 -1
  61. package/dist/magic-funcs/optimizers/promptify.d.ts +18 -0
  62. package/dist/magic-funcs/optimizers/promptify.d.ts.map +1 -1
  63. package/dist/magic-funcs/optimizers/promptify.js +21 -3
  64. package/dist/magic-funcs/optimizers/promptify.js.map +1 -1
  65. package/dist/magic-funcs/optimizers/ragify.d.ts +16 -0
  66. package/dist/magic-funcs/optimizers/ragify.d.ts.map +1 -1
  67. package/dist/magic-funcs/optimizers/ragify.js +19 -3
  68. package/dist/magic-funcs/optimizers/ragify.js.map +1 -1
  69. package/dist/magic-funcs/parsers/extract.d.ts +23 -0
  70. package/dist/magic-funcs/parsers/extract.d.ts.map +1 -1
  71. package/dist/magic-funcs/parsers/extract.js +26 -3
  72. package/dist/magic-funcs/parsers/extract.js.map +1 -1
  73. package/dist/magic-funcs/parsers/rewrite.d.ts +19 -0
  74. package/dist/magic-funcs/parsers/rewrite.d.ts.map +1 -1
  75. package/dist/magic-funcs/parsers/rewrite.js +22 -2
  76. package/dist/magic-funcs/parsers/rewrite.js.map +1 -1
  77. package/dist/magic-funcs/parsers/structure.d.ts +22 -0
  78. package/dist/magic-funcs/parsers/structure.d.ts.map +1 -1
  79. package/dist/magic-funcs/parsers/structure.js +27 -4
  80. package/dist/magic-funcs/parsers/structure.js.map +1 -1
  81. package/dist/magic-funcs/parsers/summarize.d.ts +20 -0
  82. package/dist/magic-funcs/parsers/summarize.d.ts.map +1 -1
  83. package/dist/magic-funcs/parsers/summarize.js +23 -3
  84. package/dist/magic-funcs/parsers/summarize.js.map +1 -1
  85. package/dist/memory.d.ts +1 -1
  86. package/dist/modalities/image-gen/generateImages.d.ts +56 -0
  87. package/dist/modalities/image-gen/generateImages.d.ts.map +1 -0
  88. package/dist/modalities/image-gen/generateImages.js +66 -0
  89. package/dist/modalities/image-gen/generateImages.js.map +1 -0
  90. package/dist/modalities/image-gen/helpers.d.ts +15 -0
  91. package/dist/modalities/image-gen/helpers.d.ts.map +1 -0
  92. package/dist/modalities/image-gen/helpers.js +17 -0
  93. package/dist/modalities/image-gen/helpers.js.map +1 -0
  94. package/dist/modalities/openrouter.d.ts +11 -0
  95. package/dist/modalities/openrouter.d.ts.map +1 -0
  96. package/dist/modalities/openrouter.js +39 -0
  97. package/dist/modalities/openrouter.js.map +1 -0
  98. package/dist/modalities/speech/VoiceEngine.d.ts +3 -0
  99. package/dist/modalities/speech/VoiceEngine.d.ts.map +1 -0
  100. package/dist/modalities/speech/VoiceEngine.js +3 -0
  101. package/dist/modalities/speech/VoiceEngine.js.map +1 -0
  102. package/dist/modalities/speech/stt/helpers.d.ts +3 -0
  103. package/dist/modalities/speech/stt/helpers.d.ts.map +1 -0
  104. package/dist/modalities/speech/stt/helpers.js +28 -0
  105. package/dist/modalities/speech/stt/helpers.js.map +1 -0
  106. package/dist/modalities/speech/stt/stt.d.ts +113 -0
  107. package/dist/modalities/speech/stt/stt.d.ts.map +1 -0
  108. package/dist/modalities/speech/stt/stt.js +177 -0
  109. package/dist/modalities/speech/stt/stt.js.map +1 -0
  110. package/dist/modalities/speech/tts/helpers.d.ts +12 -0
  111. package/dist/modalities/speech/tts/helpers.d.ts.map +1 -0
  112. package/dist/modalities/speech/tts/helpers.js +10 -0
  113. package/dist/modalities/speech/tts/helpers.js.map +1 -0
  114. package/dist/modalities/speech/tts/tts.d.ts +115 -0
  115. package/dist/modalities/speech/tts/tts.d.ts.map +1 -0
  116. package/dist/modalities/speech/tts/tts.js +142 -0
  117. package/dist/modalities/speech/tts/tts.js.map +1 -0
  118. package/dist/modalities/vision/helpers.d.ts +3 -0
  119. package/dist/modalities/vision/helpers.d.ts.map +1 -0
  120. package/dist/modalities/vision/helpers.js +7 -0
  121. package/dist/modalities/vision/helpers.js.map +1 -0
  122. package/dist/modalities/vision/vision.d.ts +55 -0
  123. package/dist/modalities/vision/vision.d.ts.map +1 -0
  124. package/dist/modalities/vision/vision.js +71 -0
  125. package/dist/modalities/vision/vision.js.map +1 -0
  126. package/package.json +7 -7
@@ -0,0 +1,7 @@
1
+ export function normalizeVisionImage(input) {
2
+ if (input.startsWith("http://") || input.startsWith("https://") || input.startsWith("data:image/")) {
3
+ return input;
4
+ }
5
+ return `data:image/jpeg;base64,${input}`;
6
+ }
7
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/modalities/vision/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,KAAuB;IACxD,IAAI,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;QACjG,OAAO,KAAK,CAAA;IAChB,CAAC;IAED,OAAO,0BAA0B,KAAK,EAAE,CAAA;AAC5C,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { OpenRouterVisionModel } from "../../helpers/llms";
2
+ import { LLMInstance } from "../openrouter";
3
+ import { VisionImageInput } from "./helpers";
4
+ type VisionOptions = {
5
+ llm?: LLMInstance;
6
+ prompt: string;
7
+ images: VisionImageInput[];
8
+ detail?: "auto" | "low" | "high";
9
+ model?: OpenRouterVisionModel;
10
+ };
11
+ /**
12
+ * Analyzes one or more images with a vision-capable OpenRouter model.
13
+ *
14
+ * Internally this function sends `image_url` content parts through OpenRouter's
15
+ * chat-completions-compatible interface. If no `llm` is provided, it builds one
16
+ * with `getLLM({ provider: "openrouter", type: "vision" })` and reads
17
+ * `process.env.OPENROUTER_API_KEY`.
18
+ *
19
+ * Make sure `OPENROUTER_API_KEY` is set in your `.env`.
20
+ *
21
+ * @param params.llm Optional LLM instance from `getLLM(...)`.
22
+ * @param params.prompt Instruction/question for the model about the provided images.
23
+ * @param params.images Array of image URLs, data URLs, or base64 strings.
24
+ * @param params.detail Vision detail level (`auto`, `low`, `high`).
25
+ * @param params.model Optional model override for this call.
26
+ * @returns Promise with normalized `text` and full provider response in `raw`.
27
+ *
28
+ * @example
29
+ * CONFIG:
30
+ * ```ts
31
+ * vision({
32
+ * llm = getLLM({ provider: "openrouter", type: "vision" }),
33
+ * prompt = "Describe the image in detail.",
34
+ * detail = "auto",
35
+ * images,
36
+ * model
37
+ * })
38
+ * ```
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const result = await vision({
43
+ * prompt: "What objects do you see?",
44
+ * images: ["https://example.com/cat.jpg"]
45
+ * });
46
+ *
47
+ * console.log(result.text);
48
+ * ```
49
+ */
50
+ export declare function vision({ llm, prompt, detail, images, model }: VisionOptions): Promise<{
51
+ text: string;
52
+ raw: unknown;
53
+ }>;
54
+ export {};
55
+ //# sourceMappingURL=vision.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision.d.ts","sourceRoot":"","sources":["../../../src/modalities/vision/vision.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAE,WAAW,EAAwB,MAAM,eAAe,CAAA;AACjE,OAAO,EAAwB,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAElE,KAAK,aAAa,GAAG;IACjB,GAAG,CAAC,EAAE,WAAW,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,gBAAgB,EAAE,CAAA;IAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAA;IAChC,KAAK,CAAC,EAAE,qBAAqB,CAAA;CAChC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAsB,MAAM,CAAC,EACzB,GAAwD,EACxD,MAAwC,EACxC,MAAe,EACf,MAAM,EACN,KAAK,EACR,EAAE,aAAa,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC,CA+BzD"}
@@ -0,0 +1,71 @@
1
+ import { HumanMessage } from "../../imports";
2
+ import { getLLM } from "../../helpers/llms";
3
+ import { getOpenRouterRuntime } from "../openrouter";
4
+ import { normalizeVisionImage } from "./helpers";
5
+ /**
6
+ * Analyzes one or more images with a vision-capable OpenRouter model.
7
+ *
8
+ * Internally this function sends `image_url` content parts through OpenRouter's
9
+ * chat-completions-compatible interface. If no `llm` is provided, it builds one
10
+ * with `getLLM({ provider: "openrouter", type: "vision" })` and reads
11
+ * `process.env.OPENROUTER_API_KEY`.
12
+ *
13
+ * Make sure `OPENROUTER_API_KEY` is set in your `.env`.
14
+ *
15
+ * @param params.llm Optional LLM instance from `getLLM(...)`.
16
+ * @param params.prompt Instruction/question for the model about the provided images.
17
+ * @param params.images Array of image URLs, data URLs, or base64 strings.
18
+ * @param params.detail Vision detail level (`auto`, `low`, `high`).
19
+ * @param params.model Optional model override for this call.
20
+ * @returns Promise with normalized `text` and full provider response in `raw`.
21
+ *
22
+ * @example
23
+ * CONFIG:
24
+ * ```ts
25
+ * vision({
26
+ * llm = getLLM({ provider: "openrouter", type: "vision" }),
27
+ * prompt = "Describe the image in detail.",
28
+ * detail = "auto",
29
+ * images,
30
+ * model
31
+ * })
32
+ * ```
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const result = await vision({
37
+ * prompt: "What objects do you see?",
38
+ * images: ["https://example.com/cat.jpg"]
39
+ * });
40
+ *
41
+ * console.log(result.text);
42
+ * ```
43
+ */
44
+ export async function vision({ llm = getLLM({ provider: "openrouter", type: "vision" }), prompt = "Describe the image in detail.", detail = "auto", images, model }) {
45
+ const runtime = getOpenRouterRuntime(llm);
46
+ const content = [
47
+ { type: "text", text: prompt },
48
+ ...images.map((image) => ({
49
+ type: "image_url",
50
+ image_url: {
51
+ url: normalizeVisionImage(image),
52
+ detail
53
+ }
54
+ }))
55
+ ];
56
+ const runtimeLLM = model && model !== runtime.model
57
+ ? getLLM({
58
+ provider: "openrouter",
59
+ type: "vision",
60
+ model,
61
+ apikey: runtime.apiKey
62
+ })
63
+ : llm;
64
+ const response = await runtimeLLM.invoke([new HumanMessage({ content })]);
65
+ const text = typeof response.content === "string" ? response.content : JSON.stringify(response.content);
66
+ return {
67
+ text,
68
+ raw: response
69
+ };
70
+ }
71
+ //# sourceMappingURL=vision.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vision.js","sourceRoot":"","sources":["../../../src/modalities/vision/vision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAyB,MAAM,oBAAoB,CAAA;AAClE,OAAO,EAAe,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAoB,MAAM,WAAW,CAAA;AAUlE;;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1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delofarag/ai-utils",
3
- "version": "1.4.2",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,11 +8,6 @@
8
8
  "dist",
9
9
  "README.md"
10
10
  ],
11
- "scripts": {
12
- "build": "tsc",
13
- "dev": "tsx",
14
- "start": "tsx"
15
- },
16
11
  "dependencies": {
17
12
  "@supabase/supabase-js": "^2.39.0",
18
13
  "@delofarag/base-utils": "^1.3.1",
@@ -40,5 +35,10 @@
40
35
  "@types/node": "^20.0.0",
41
36
  "tsx": "^4.0.0",
42
37
  "typescript": "^5.9.3"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "dev": "tsx",
42
+ "start": "tsx"
43
43
  }
44
- }
44
+ }