@axvaich/ai-lib 1.0.2 → 1.0.4

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 (2) hide show
  1. package/dist/index.js +5 -24
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ import "dotenv/config";
4
4
 
5
5
  // src/utils.ts
6
6
  import crypto from "crypto";
7
- import ts from "typescript";
8
7
  function generateHash(input) {
9
8
  return crypto.createHash("sha256").update(input).digest("hex");
10
9
  }
@@ -15,24 +14,6 @@ function extractCodeBlock(text) {
15
14
  }
16
15
  return match[1].trim();
17
16
  }
18
- function getFunctionName(code) {
19
- const source = ts.createSourceFile(
20
- "temp.ts",
21
- code,
22
- ts.ScriptTarget.Latest,
23
- true
24
- );
25
- let name = "";
26
- source.forEachChild((node) => {
27
- if (ts.isFunctionDeclaration(node) && node.name) {
28
- name = node.name.text;
29
- }
30
- });
31
- if (!name) {
32
- throw new Error("No named function found");
33
- }
34
- return name;
35
- }
36
17
  async function loadFunction(filePath) {
37
18
  const module = await import(`file://${filePath}`);
38
19
  return module.default;
@@ -60,7 +41,7 @@ var Storage = class {
60
41
  var store = new Storage();
61
42
 
62
43
  // src/generator.ts
63
- import ts2 from "typescript";
44
+ import ts from "typescript";
64
45
  var SYSTEM_PROMPT = `\u0422\u044B \u0433\u0435\u043D\u0435\u0440\u0430\u0442\u043E\u0440 TypeScript \u0444\u0443\u043D\u043A\u0446\u0438\u0439. \u0421\u0442\u0440\u043E\u0433\u0438\u0435 \u043F\u0440\u0430\u0432\u0438\u043B\u0430:
65
46
  - \u041E\u0434\u043D\u0430 \u0444\u0443\u043D\u043A\u0446\u0438\u044F \u0441 export default
66
47
  - \u0421\u0442\u0440\u043E\u0433\u0430\u044F \u0442\u0438\u043F\u0438\u0437\u0430\u0446\u0438\u044F \u0432\u0441\u0435\u0445 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u043E\u0432 \u0438 return type
@@ -75,10 +56,10 @@ var groq = new Groq({
75
56
  apiKey: process.env.GROQ_API_KEY
76
57
  });
77
58
  function compileTs(code) {
78
- const result = ts2.transpileModule(code, {
59
+ const result = ts.transpileModule(code, {
79
60
  compilerOptions: {
80
- module: ts2.ModuleKind.ESNext,
81
- target: ts2.ScriptTarget.ES2020,
61
+ module: ts.ModuleKind.ESNext,
62
+ target: ts.ScriptTarget.ES2020,
82
63
  strict: true
83
64
  }
84
65
  });
@@ -96,7 +77,7 @@ async function generate(prompt) {
96
77
  });
97
78
  const content = result.choices[0]?.message?.content || "";
98
79
  const code = extractCodeBlock(content);
99
- const fileName = getFunctionName(code);
80
+ const fileName = generateHash(prompt);
100
81
  const filePath = await store.createFunction(fileName, compileTs(code));
101
82
  return await loadFunction(filePath);
102
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axvaich/ai-lib",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"