@akanjs/devkit 0.0.58 → 0.0.59

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/index.cjs CHANGED
@@ -15,3 +15,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
15
  var devkit_exports = {};
16
16
  module.exports = __toCommonJS(devkit_exports);
17
17
  __reExport(devkit_exports, require("./src"), module.exports);
18
+ // Annotate the CommonJS export names for ESM import in node:
19
+ 0 && (module.exports = {
20
+ ...require("./src")
21
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "0.0.58",
3
+ "version": "0.0.59",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inquirer/prompts": "^7.2.1",
19
- "@langchain/core": "^0.3.27",
20
- "@langchain/openai": "^0.3.16",
19
+ "@langchain/core": "^0.3.56",
20
+ "@langchain/openai": "^0.5.10",
21
21
  "@nx/devkit": "^20.7.2",
22
22
  "@trapezedev/project": "^7.1.3",
23
23
  "axios": "^1.7.9",
package/src/aiEditor.cjs CHANGED
@@ -17,30 +17,76 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var aiEditor_exports = {};
19
19
  __export(aiEditor_exports, {
20
- AiEditor: () => AiEditor
20
+ AiSession: () => AiSession
21
21
  });
22
22
  module.exports = __toCommonJS(aiEditor_exports);
23
- var import_prompts = require("@langchain/core/prompts");
24
- var import_runnables = require("@langchain/core/runnables");
23
+ var import_common = require("@akanjs/common");
24
+ var import_prompts = require("@inquirer/prompts");
25
+ var import_messages = require("@langchain/core/messages");
25
26
  var import_openai = require("@langchain/openai");
26
- class AiEditor {
27
- chat;
28
- constructor(apiKey = process.env.DEEPSEEK_API_KEY) {
29
- this.chat = new import_openai.ChatOpenAI({
30
- modelName: "deepseek-reasoner",
31
- temperature: 0.7,
32
- streaming: true,
33
- // Enable streaming
34
- configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
35
- });
27
+ const MAX_ASK_TRY = 300;
28
+ class AiSession {
29
+ static #chat = new import_openai.ChatOpenAI({
30
+ modelName: "deepseek-chat",
31
+ temperature: 0.7,
32
+ streaming: true,
33
+ // Enable streaming
34
+ configuration: { baseURL: "https://api.deepseek.com/v1", apiKey: process.env.DEEPSEEK_API_KEY }
35
+ });
36
+ messageHistory = [];
37
+ constructor(messageHistory = []) {
38
+ this.messageHistory = messageHistory;
36
39
  }
37
- #createProcessingChain() {
38
- return import_runnables.RunnableSequence.from([import_prompts.PromptTemplate.fromTemplate(`Answer concisely: {question}`), this.chat]);
40
+ async ask(question, {
41
+ onChunk = (chunk) => {
42
+ import_common.Logger.raw(chunk);
43
+ }
44
+ } = {}) {
45
+ try {
46
+ const humanMessage = new import_messages.HumanMessage(question);
47
+ this.messageHistory.push(humanMessage);
48
+ const stream = await AiSession.#chat.stream(this.messageHistory);
49
+ let fullResponse = "";
50
+ for await (const chunk of stream) {
51
+ const content = chunk.content;
52
+ if (typeof content === "string") {
53
+ fullResponse += content;
54
+ onChunk(content);
55
+ }
56
+ }
57
+ this.messageHistory.push(new import_messages.AIMessage(fullResponse));
58
+ return { content: fullResponse, messageHistory: this.messageHistory };
59
+ } catch (error) {
60
+ throw new Error("Failed to stream response");
61
+ }
39
62
  }
40
- async edit(question) {
41
- const chain = this.#createProcessingChain();
42
- const stream = await chain.stream({ question });
43
- for await (const chunk of stream) {
63
+ async edit(question, { onChunk, maxTry = MAX_ASK_TRY } = {}) {
64
+ for (let tryCount = 0; tryCount < maxTry; tryCount++) {
65
+ const response = await this.ask(question, { onChunk });
66
+ const isConfirmed = await (0, import_prompts.select)({
67
+ message: "Do you want to edit the response?",
68
+ choices: [
69
+ { name: "\u2705 Yes, confirm and apply this result", value: true },
70
+ { name: "\u{1F504} No, I want to edit it more", value: false }
71
+ ]
72
+ });
73
+ if (isConfirmed)
74
+ return response.content;
75
+ question = await (0, import_prompts.input)({ message: "What do you want to change?" });
76
+ tryCount++;
44
77
  }
78
+ throw new Error("Failed to edit");
79
+ }
80
+ async editTypescript(question, options = {}) {
81
+ const content = await this.edit(question, options);
82
+ return this.#getTypescriptCode(content);
83
+ }
84
+ #getTypescriptCode(content) {
85
+ const code = /```typescript([\s\S]*?)```/.exec(content);
86
+ return code ? code[1] : content;
45
87
  }
46
88
  }
89
+ // Annotate the CommonJS export names for ESM import in node:
90
+ 0 && (module.exports = {
91
+ AiSession
92
+ });
package/src/aiEditor.d.ts CHANGED
@@ -1,7 +1,17 @@
1
- import { ChatOpenAI } from "@langchain/openai";
2
- export declare class AiEditor {
1
+ import { BaseMessage } from "@langchain/core/messages";
2
+ interface EditOptions {
3
+ onChunk?: (chunk: string) => void;
4
+ maxTry?: number;
5
+ }
6
+ export declare class AiSession {
3
7
  #private;
4
- chat: ChatOpenAI;
5
- constructor(apiKey?: string | undefined);
6
- edit(question: string): Promise<void>;
8
+ readonly messageHistory: BaseMessage[];
9
+ constructor(messageHistory?: BaseMessage[]);
10
+ ask(question: string, { onChunk, }?: EditOptions): Promise<{
11
+ content: string;
12
+ messageHistory: BaseMessage[];
13
+ }>;
14
+ edit(question: string, { onChunk, maxTry }?: EditOptions): Promise<string>;
15
+ editTypescript(question: string, options?: EditOptions): Promise<string>;
7
16
  }
17
+ export {};
package/src/aiEditor.js CHANGED
@@ -1,27 +1,69 @@
1
- import { PromptTemplate } from "@langchain/core/prompts";
2
- import { RunnableSequence } from "@langchain/core/runnables";
1
+ import { Logger } from "@akanjs/common";
2
+ import { input, select } from "@inquirer/prompts";
3
+ import { AIMessage, HumanMessage } from "@langchain/core/messages";
3
4
  import { ChatOpenAI } from "@langchain/openai";
4
- class AiEditor {
5
- chat;
6
- constructor(apiKey = process.env.DEEPSEEK_API_KEY) {
7
- this.chat = new ChatOpenAI({
8
- modelName: "deepseek-reasoner",
9
- temperature: 0.7,
10
- streaming: true,
11
- // Enable streaming
12
- configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
13
- });
5
+ const MAX_ASK_TRY = 300;
6
+ class AiSession {
7
+ static #chat = new ChatOpenAI({
8
+ modelName: "deepseek-chat",
9
+ temperature: 0.7,
10
+ streaming: true,
11
+ // Enable streaming
12
+ configuration: { baseURL: "https://api.deepseek.com/v1", apiKey: process.env.DEEPSEEK_API_KEY }
13
+ });
14
+ messageHistory = [];
15
+ constructor(messageHistory = []) {
16
+ this.messageHistory = messageHistory;
14
17
  }
15
- #createProcessingChain() {
16
- return RunnableSequence.from([PromptTemplate.fromTemplate(`Answer concisely: {question}`), this.chat]);
18
+ async ask(question, {
19
+ onChunk = (chunk) => {
20
+ Logger.raw(chunk);
21
+ }
22
+ } = {}) {
23
+ try {
24
+ const humanMessage = new HumanMessage(question);
25
+ this.messageHistory.push(humanMessage);
26
+ const stream = await AiSession.#chat.stream(this.messageHistory);
27
+ let fullResponse = "";
28
+ for await (const chunk of stream) {
29
+ const content = chunk.content;
30
+ if (typeof content === "string") {
31
+ fullResponse += content;
32
+ onChunk(content);
33
+ }
34
+ }
35
+ this.messageHistory.push(new AIMessage(fullResponse));
36
+ return { content: fullResponse, messageHistory: this.messageHistory };
37
+ } catch (error) {
38
+ throw new Error("Failed to stream response");
39
+ }
17
40
  }
18
- async edit(question) {
19
- const chain = this.#createProcessingChain();
20
- const stream = await chain.stream({ question });
21
- for await (const chunk of stream) {
41
+ async edit(question, { onChunk, maxTry = MAX_ASK_TRY } = {}) {
42
+ for (let tryCount = 0; tryCount < maxTry; tryCount++) {
43
+ const response = await this.ask(question, { onChunk });
44
+ const isConfirmed = await select({
45
+ message: "Do you want to edit the response?",
46
+ choices: [
47
+ { name: "\u2705 Yes, confirm and apply this result", value: true },
48
+ { name: "\u{1F504} No, I want to edit it more", value: false }
49
+ ]
50
+ });
51
+ if (isConfirmed)
52
+ return response.content;
53
+ question = await input({ message: "What do you want to change?" });
54
+ tryCount++;
22
55
  }
56
+ throw new Error("Failed to edit");
57
+ }
58
+ async editTypescript(question, options = {}) {
59
+ const content = await this.edit(question, options);
60
+ return this.#getTypescriptCode(content);
61
+ }
62
+ #getTypescriptCode(content) {
63
+ const code = /```typescript([\s\S]*?)```/.exec(content);
64
+ return code ? code[1] : content;
23
65
  }
24
66
  }
25
67
  export {
26
- AiEditor
68
+ AiSession
27
69
  };
package/src/auth.cjs CHANGED
@@ -62,3 +62,11 @@ const getSelf = async (token) => {
62
62
  return null;
63
63
  }
64
64
  };
65
+ // Annotate the CommonJS export names for ESM import in node:
66
+ 0 && (module.exports = {
67
+ getAkanGlobalConfig,
68
+ getHostConfig,
69
+ getSelf,
70
+ setAkanGlobalConfig,
71
+ setHostConfig
72
+ });
@@ -43,3 +43,8 @@ const getSshTunnelOptions = (appName, environment) => {
43
43
  password: process.env.SSU_TUNNEL_PASSWORD ?? repoName
44
44
  };
45
45
  };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ getBaseDevEnv,
49
+ getSshTunnelOptions
50
+ });
@@ -151,3 +151,7 @@ class CapacitorApp {
151
151
  return this.#getPermissionsInAndroid().includes(permission);
152
152
  }
153
153
  }
154
+ // Annotate the CommonJS export names for ESM import in node:
155
+ 0 && (module.exports = {
156
+ CapacitorApp
157
+ });
@@ -65,3 +65,15 @@ const Lib = createArgMetaDecorator("Lib");
65
65
  const Sys = createArgMetaDecorator("Sys");
66
66
  const Pkg = createArgMetaDecorator("Pkg");
67
67
  const Workspace = createArgMetaDecorator("Workspace");
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ App,
71
+ Lib,
72
+ Option,
73
+ Pkg,
74
+ Sys,
75
+ Workspace,
76
+ argTypes,
77
+ getArgMetas,
78
+ internalArgTypes
79
+ });
@@ -158,3 +158,7 @@ const runCommands = async (...commands) => {
158
158
  }
159
159
  await import_commander.program.parseAsync(process.argv);
160
160
  };
161
+ // Annotate the CommonJS export names for ESM import in node:
162
+ 0 && (module.exports = {
163
+ runCommands
164
+ });
@@ -24,3 +24,7 @@ const Commands = () => {
24
24
  return function(target) {
25
25
  };
26
26
  };
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ Commands
30
+ });
@@ -19,3 +19,11 @@ __reExport(commandDecorators_exports, require("./commandMeta"), module.exports);
19
19
  __reExport(commandDecorators_exports, require("./targetMeta"), module.exports);
20
20
  __reExport(commandDecorators_exports, require("./types"), module.exports);
21
21
  __reExport(commandDecorators_exports, require("./command"), module.exports);
22
+ // Annotate the CommonJS export names for ESM import in node:
23
+ 0 && (module.exports = {
24
+ ...require("./argMeta"),
25
+ ...require("./commandMeta"),
26
+ ...require("./targetMeta"),
27
+ ...require("./types"),
28
+ ...require("./command")
29
+ });
@@ -50,3 +50,8 @@ const Target = {
50
50
  Cloud: getTarget("cloud"),
51
51
  Dev: getTarget("dev")
52
52
  };
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ Target,
56
+ getTargetMetas
57
+ });
package/src/constants.cjs CHANGED
@@ -35,3 +35,13 @@ const akanCloudBackendUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION
35
35
  const akanCloudClientUrl = `${akanCloudHost}${process.env.NEXT_PUBLIC_OPERATION_MODE === "local" ? ":4200" : ""}`;
36
36
  const defaultHostConfig = {};
37
37
  const defaultAkanGlobalConfig = {};
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ akanCloudBackendUrl,
41
+ akanCloudClientUrl,
42
+ akanCloudHost,
43
+ basePath,
44
+ configPath,
45
+ defaultAkanGlobalConfig,
46
+ defaultHostConfig
47
+ });
@@ -35,3 +35,7 @@ const createTunnel = async ({ appName, environment, port = 27017 }) => {
35
35
  const [server, client] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
36
36
  return `localhost:${port}`;
37
37
  };
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ createTunnel
41
+ });
@@ -157,3 +157,7 @@ class TypeScriptDependencyScanner {
157
157
  return graph;
158
158
  }
159
159
  }
160
+ // Annotate the CommonJS export names for ESM import in node:
161
+ 0 && (module.exports = {
162
+ TypeScriptDependencyScanner
163
+ });
package/src/executors.cjs CHANGED
@@ -138,6 +138,11 @@ class Executor {
138
138
  this.writeFile(filePath, JSON.stringify(content, null, 2));
139
139
  return this;
140
140
  }
141
+ getLocalFile(filePath) {
142
+ const filepath = import_path.default.isAbsolute(filePath) ? filePath : filePath.replace(this.cwdPath, "");
143
+ const content = this.readFile(filepath);
144
+ return { filepath, content };
145
+ }
141
146
  readFile(filePath) {
142
147
  const readPath = import_path.default.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
143
148
  return import_fs.default.readFileSync(readPath, "utf8");
@@ -176,7 +181,7 @@ class Executor {
176
181
  targetPath,
177
182
  scanResult
178
183
  }, dict = {}) {
179
- if (targetPath.endsWith(".js")) {
184
+ if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
180
185
  const getContent = await import(templatePath);
181
186
  const content = getContent.default(scanResult ?? null, dict);
182
187
  const convertedTargetPath = Object.entries(dict).reduce(
@@ -194,7 +199,7 @@ class Executor {
194
199
  targetPath.slice(0, -9)
195
200
  );
196
201
  const convertedContent = Object.entries(dict).reduce(
197
- (content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value),
202
+ (data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value),
198
203
  content
199
204
  );
200
205
  this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
@@ -292,6 +297,21 @@ class WorkspaceExecutor extends Executor {
292
297
  async getPkgs() {
293
298
  return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
294
299
  }
300
+ setTsPaths(type, name) {
301
+ const rootTsConfig = this.readJson("tsconfig.json");
302
+ if (type === "lib")
303
+ rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
304
+ rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
305
+ this.writeJson("tsconfig.json", rootTsConfig);
306
+ return this;
307
+ }
308
+ async commit(message, { init = false, add = true } = {}) {
309
+ if (init)
310
+ await this.exec(`git init`);
311
+ if (add)
312
+ await this.exec(`git add .`);
313
+ await this.exec(`git commit -m "${message}"`);
314
+ }
295
315
  async #getDirHasFile(basePath, targetFilename) {
296
316
  const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
297
317
  const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
@@ -314,6 +334,14 @@ class WorkspaceExecutor extends Executor {
314
334
  };
315
335
  return await getDirs(basePath);
316
336
  }
337
+ async getScalarConstantFiles() {
338
+ const [appNames, libNames] = await this.getSyss();
339
+ const scalarConstantExampleFiles = [
340
+ ...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getScalarConstantFiles()))).flat(),
341
+ ...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getScalarConstantFiles()))).flat()
342
+ ];
343
+ return scalarConstantExampleFiles;
344
+ }
317
345
  }
318
346
  class SysExecutor extends Executor {
319
347
  workspace;
@@ -457,6 +485,11 @@ class SysExecutor extends Executor {
457
485
  this.writeJson(`akan.${this.type}.json`, scanResult);
458
486
  return scanResult;
459
487
  }
488
+ getLocalFile(filePath) {
489
+ const filepath = import_path.default.isAbsolute(filePath) ? filePath : `${this.type}s/${this.name}/${filePath}`;
490
+ const content = this.workspace.readFile(filepath);
491
+ return { filepath, content };
492
+ }
460
493
  async getDatabaseModules() {
461
494
  const databaseModules = (await import_promises.default.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
462
495
  return databaseModules;
@@ -469,6 +502,22 @@ class SysExecutor extends Executor {
469
502
  const scalarModules = (await import_promises.default.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => import_fs.default.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
470
503
  return scalarModules;
471
504
  }
505
+ async getScalarConstantFiles() {
506
+ const scalarModules = await this.getScalarModules();
507
+ return scalarModules.map(
508
+ (scalarModule) => this.getLocalFile(`lib/__scalar/${scalarModule}/${scalarModule}.constant.ts`)
509
+ );
510
+ }
511
+ async getScalarDictionaryFiles() {
512
+ const scalarModules = await this.getScalarModules();
513
+ return scalarModules.map(
514
+ (scalarModule) => this.getLocalFile(`lib/__scalar/${scalarModule}/${scalarModule}.dictionary.ts`)
515
+ );
516
+ }
517
+ setTsPaths() {
518
+ this.workspace.setTsPaths(this.type, this.name);
519
+ return this;
520
+ }
472
521
  }
473
522
  class AppExecutor extends SysExecutor {
474
523
  constructor({ workspace, name }) {
@@ -590,3 +639,15 @@ class DistPkgExecutor extends Executor {
590
639
  });
591
640
  }
592
641
  }
642
+ // Annotate the CommonJS export names for ESM import in node:
643
+ 0 && (module.exports = {
644
+ AppExecutor,
645
+ DistAppExecutor,
646
+ DistLibExecutor,
647
+ DistPkgExecutor,
648
+ Executor,
649
+ LibExecutor,
650
+ PkgExecutor,
651
+ SysExecutor,
652
+ WorkspaceExecutor
653
+ });
@@ -16,6 +16,10 @@ export declare class Executor {
16
16
  mkdir(dirPath: string): this;
17
17
  writeFile(filePath: string, content: string | object): this;
18
18
  writeJson(filePath: string, content: object): this;
19
+ getLocalFile(filePath: string): {
20
+ filepath: string;
21
+ content: string;
22
+ };
19
23
  readFile(filePath: string): string;
20
24
  readJson(filePath: string): object;
21
25
  cp(srcPath: string, destPath: string): Promise<void>;
@@ -46,6 +50,15 @@ export declare class WorkspaceExecutor extends Executor {
46
50
  getLibs(): Promise<string[]>;
47
51
  getSyss(): Promise<[string[], string[]]>;
48
52
  getPkgs(): Promise<string[]>;
53
+ setTsPaths(type: "app" | "lib", name: string): this;
54
+ commit(message: string, { init, add }?: {
55
+ init?: boolean;
56
+ add?: boolean;
57
+ }): Promise<void>;
58
+ getScalarConstantFiles(): Promise<{
59
+ filepath: string;
60
+ content: string;
61
+ }[]>;
49
62
  }
50
63
  interface SysExecutorOptions {
51
64
  workspace?: WorkspaceExecutor;
@@ -64,9 +77,22 @@ export declare class SysExecutor extends Executor {
64
77
  }, libScanResults?: {
65
78
  [key: string]: LibScanResult;
66
79
  }): Promise<AppScanResult | LibScanResult>;
80
+ getLocalFile(filePath: string): {
81
+ filepath: string;
82
+ content: string;
83
+ };
67
84
  getDatabaseModules(): Promise<string[]>;
68
85
  getServiceModules(): Promise<string[]>;
69
86
  getScalarModules(): Promise<string[]>;
87
+ getScalarConstantFiles(): Promise<{
88
+ filepath: string;
89
+ content: string;
90
+ }[]>;
91
+ getScalarDictionaryFiles(): Promise<{
92
+ filepath: string;
93
+ content: string;
94
+ }[]>;
95
+ setTsPaths(): this;
70
96
  }
71
97
  interface AppExecutorOptions {
72
98
  workspace?: WorkspaceExecutor;
package/src/executors.js CHANGED
@@ -102,6 +102,11 @@ class Executor {
102
102
  this.writeFile(filePath, JSON.stringify(content, null, 2));
103
103
  return this;
104
104
  }
105
+ getLocalFile(filePath) {
106
+ const filepath = path.isAbsolute(filePath) ? filePath : filePath.replace(this.cwdPath, "");
107
+ const content = this.readFile(filepath);
108
+ return { filepath, content };
109
+ }
105
110
  readFile(filePath) {
106
111
  const readPath = path.isAbsolute(filePath) ? filePath : `${this.cwdPath}/${filePath}`;
107
112
  return fs.readFileSync(readPath, "utf8");
@@ -140,7 +145,7 @@ class Executor {
140
145
  targetPath,
141
146
  scanResult
142
147
  }, dict = {}) {
143
- if (targetPath.endsWith(".js")) {
148
+ if (targetPath.endsWith(".js") || targetPath.endsWith(".jsx")) {
144
149
  const getContent = await import(templatePath);
145
150
  const content = getContent.default(scanResult ?? null, dict);
146
151
  const convertedTargetPath = Object.entries(dict).reduce(
@@ -158,7 +163,7 @@ class Executor {
158
163
  targetPath.slice(0, -9)
159
164
  );
160
165
  const convertedContent = Object.entries(dict).reduce(
161
- (content2, [key, value]) => content2.replace(new RegExp(`<%= ${key} %>`, "g"), value),
166
+ (data, [key, value]) => data.replace(new RegExp(`<%= ${key} %>`, "g"), value),
162
167
  content
163
168
  );
164
169
  this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
@@ -256,6 +261,21 @@ class WorkspaceExecutor extends Executor {
256
261
  async getPkgs() {
257
262
  return await this.#getDirHasFile(`${this.workspaceRoot}/pkgs`, "package.json");
258
263
  }
264
+ setTsPaths(type, name) {
265
+ const rootTsConfig = this.readJson("tsconfig.json");
266
+ if (type === "lib")
267
+ rootTsConfig.compilerOptions.paths[`@${name}`] = [`${type}s/${name}/index.ts`];
268
+ rootTsConfig.compilerOptions.paths[`@${name}/*`] = [`${type}s/${name}/*`];
269
+ this.writeJson("tsconfig.json", rootTsConfig);
270
+ return this;
271
+ }
272
+ async commit(message, { init = false, add = true } = {}) {
273
+ if (init)
274
+ await this.exec(`git init`);
275
+ if (add)
276
+ await this.exec(`git add .`);
277
+ await this.exec(`git commit -m "${message}"`);
278
+ }
259
279
  async #getDirHasFile(basePath, targetFilename) {
260
280
  const AVOID_DIRS = ["node_modules", "dist", "public", "./next"];
261
281
  const getDirs = async (dirname, maxDepth = 3, results = [], prefix = "") => {
@@ -278,6 +298,14 @@ class WorkspaceExecutor extends Executor {
278
298
  };
279
299
  return await getDirs(basePath);
280
300
  }
301
+ async getScalarConstantFiles() {
302
+ const [appNames, libNames] = await this.getSyss();
303
+ const scalarConstantExampleFiles = [
304
+ ...(await Promise.all(appNames.map((appName) => AppExecutor.from(this, appName).getScalarConstantFiles()))).flat(),
305
+ ...(await Promise.all(libNames.map((libName) => LibExecutor.from(this, libName).getScalarConstantFiles()))).flat()
306
+ ];
307
+ return scalarConstantExampleFiles;
308
+ }
281
309
  }
282
310
  class SysExecutor extends Executor {
283
311
  workspace;
@@ -421,6 +449,11 @@ class SysExecutor extends Executor {
421
449
  this.writeJson(`akan.${this.type}.json`, scanResult);
422
450
  return scanResult;
423
451
  }
452
+ getLocalFile(filePath) {
453
+ const filepath = path.isAbsolute(filePath) ? filePath : `${this.type}s/${this.name}/${filePath}`;
454
+ const content = this.workspace.readFile(filepath);
455
+ return { filepath, content };
456
+ }
424
457
  async getDatabaseModules() {
425
458
  const databaseModules = (await fsPromise.readdir(`${this.cwdPath}/lib`)).filter((name) => !name.startsWith("_")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/${name}/${name}.constant.ts`));
426
459
  return databaseModules;
@@ -433,6 +466,22 @@ class SysExecutor extends Executor {
433
466
  const scalarModules = (await fsPromise.readdir(`${this.cwdPath}/lib/__scalar`)).filter((name) => !name.startsWith("_")).filter((name) => fs.existsSync(`${this.cwdPath}/lib/__scalar/${name}/${name}.constant.ts`));
434
467
  return scalarModules;
435
468
  }
469
+ async getScalarConstantFiles() {
470
+ const scalarModules = await this.getScalarModules();
471
+ return scalarModules.map(
472
+ (scalarModule) => this.getLocalFile(`lib/__scalar/${scalarModule}/${scalarModule}.constant.ts`)
473
+ );
474
+ }
475
+ async getScalarDictionaryFiles() {
476
+ const scalarModules = await this.getScalarModules();
477
+ return scalarModules.map(
478
+ (scalarModule) => this.getLocalFile(`lib/__scalar/${scalarModule}/${scalarModule}.dictionary.ts`)
479
+ );
480
+ }
481
+ setTsPaths() {
482
+ this.workspace.setTsPaths(this.type, this.name);
483
+ return this;
484
+ }
436
485
  }
437
486
  class AppExecutor extends SysExecutor {
438
487
  constructor({ workspace, name }) {
@@ -97,3 +97,7 @@ const extractDependencies = (filepaths, pacakgeJson, defaultDependencies = []) =
97
97
  })
98
98
  );
99
99
  };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ extractDependencies
103
+ });
@@ -38,3 +38,7 @@ const getCredentials = (app, environment) => {
38
38
  );
39
39
  return secret[environment];
40
40
  };
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ getCredentials
44
+ });
@@ -49,3 +49,7 @@ const getDependencies = async (projectName) => {
49
49
  npmDeps: [...npmDepSet.values()].map((depName) => depName.replace("npm:", ""))
50
50
  };
51
51
  };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ getDependencies
55
+ });
@@ -60,3 +60,7 @@ const getModelFileData = (modulePath, modelName) => {
60
60
  viewFileStr
61
61
  };
62
62
  };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ getModelFileData
66
+ });
@@ -136,3 +136,7 @@ const getRelatedCnsts = (constantFilePath) => {
136
136
  spinner.succeed("property origin found.");
137
137
  return { paths };
138
138
  };
139
+ // Annotate the CommonJS export names for ESM import in node:
140
+ 0 && (module.exports = {
141
+ getRelatedCnsts
142
+ });
package/src/index.cjs CHANGED
@@ -32,3 +32,26 @@ __reExport(src_exports, require("./capacitorApp"), module.exports);
32
32
  __reExport(src_exports, require("./extractDeps"), module.exports);
33
33
  __reExport(src_exports, require("./commandDecorators"), module.exports);
34
34
  __reExport(src_exports, require("./installExternalLib"), module.exports);
35
+ __reExport(src_exports, require("./aiEditor"), module.exports);
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ ...require("./baseDevEnv"),
39
+ ...require("./createTunnel"),
40
+ ...require("./getCredentials"),
41
+ ...require("./getDependencies"),
42
+ ...require("./uploadRelease"),
43
+ ...require("./getModelFileData"),
44
+ ...require("./getRelatedCnsts"),
45
+ ...require("./selectModel"),
46
+ ...require("./streamAi"),
47
+ ...require("./executors"),
48
+ ...require("./dependencyScanner"),
49
+ ...require("./constants"),
50
+ ...require("./auth"),
51
+ ...require("./types"),
52
+ ...require("./capacitorApp"),
53
+ ...require("./extractDeps"),
54
+ ...require("./commandDecorators"),
55
+ ...require("./installExternalLib"),
56
+ ...require("./aiEditor")
57
+ });
package/src/index.d.ts CHANGED
@@ -16,3 +16,4 @@ export * from "./capacitorApp";
16
16
  export * from "./extractDeps";
17
17
  export * from "./commandDecorators";
18
18
  export * from "./installExternalLib";
19
+ export * from "./aiEditor";
package/src/index.js CHANGED
@@ -16,3 +16,4 @@ export * from "./capacitorApp";
16
16
  export * from "./extractDeps";
17
17
  export * from "./commandDecorators";
18
18
  export * from "./installExternalLib";
19
+ export * from "./aiEditor";
@@ -27,3 +27,7 @@ const installExternalLib = async (libName, workspace) => {
27
27
  await workspace.exec(`git remote add ${libName} git@github.com:akan-team/${libName}.git`);
28
28
  await workspace.exec(`git subtree add --prefix=libs/${libName} ${libName} main`);
29
29
  };
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ installExternalLib
33
+ });
@@ -40,3 +40,7 @@ const selectModel = async (modulePath) => {
40
40
  });
41
41
  return modelName;
42
42
  };
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ selectModel
46
+ });
package/src/streamAi.cjs CHANGED
@@ -23,7 +23,9 @@ module.exports = __toCommonJS(streamAi_exports);
23
23
  var import_prompts = require("@langchain/core/prompts");
24
24
  var import_runnables = require("@langchain/core/runnables");
25
25
  var import_openai = require("@langchain/openai");
26
- const streamAi = async (question, callback) => {
26
+ const streamAi = async (question, callback = (chunk) => {
27
+ process.stdout.write(chunk);
28
+ }) => {
27
29
  const createStreamingModel = (apiKey = process.env.DEEPSEEK_API_KEY) => {
28
30
  if (!apiKey)
29
31
  throw new Error(`process.env.DEEPSEEK_API_KEY is not set`);
@@ -54,3 +56,7 @@ const streamAi = async (question, callback) => {
54
56
  throw new Error("Failed to stream response");
55
57
  }
56
58
  };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ streamAi
62
+ });
package/src/streamAi.d.ts CHANGED
@@ -2,5 +2,5 @@ interface StreamResponse {
2
2
  content: string;
3
3
  chunk?: string;
4
4
  }
5
- export declare const streamAi: (question: string, callback: (chunk: string) => void) => Promise<StreamResponse>;
5
+ export declare const streamAi: (question: string, callback?: (chunk: string) => void) => Promise<StreamResponse>;
6
6
  export {};
package/src/streamAi.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import { PromptTemplate } from "@langchain/core/prompts";
2
2
  import { RunnableSequence } from "@langchain/core/runnables";
3
3
  import { ChatOpenAI } from "@langchain/openai";
4
- const streamAi = async (question, callback) => {
4
+ const streamAi = async (question, callback = (chunk) => {
5
+ process.stdout.write(chunk);
6
+ }) => {
5
7
  const createStreamingModel = (apiKey = process.env.DEEPSEEK_API_KEY) => {
6
8
  if (!apiKey)
7
9
  throw new Error(`process.env.DEEPSEEK_API_KEY is not set`);
@@ -79,3 +79,7 @@ const uploadRelease = async (projectName, {
79
79
  return null;
80
80
  }
81
81
  };
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ uploadRelease
85
+ });