@akanjs/devkit 0.0.136 → 0.0.137
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/cjs/src/aiEditor.js +7 -1
- package/cjs/src/executors.js +2 -2
- package/esm/src/aiEditor.js +7 -1
- package/esm/src/executors.js +2 -2
- package/package.json +1 -1
package/cjs/src/aiEditor.js
CHANGED
|
@@ -33,6 +33,7 @@ __export(aiEditor_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(aiEditor_exports);
|
|
34
34
|
var import_common = require("@akanjs/common");
|
|
35
35
|
var import_prompts = require("@inquirer/prompts");
|
|
36
|
+
var import_ora = __toESM(require("ora"));
|
|
36
37
|
var import_messages = require("@langchain/core/messages");
|
|
37
38
|
var import_openai = require("@langchain/openai");
|
|
38
39
|
var import_chalk = __toESM(require("chalk"));
|
|
@@ -107,23 +108,28 @@ class AiSession {
|
|
|
107
108
|
await AiSession.init();
|
|
108
109
|
if (!AiSession.#chat)
|
|
109
110
|
throw new Error("Failed to initialize the AI session");
|
|
111
|
+
const loader = (0, import_ora.default)(`${AiSession.#chat.model} is thinking...`).start();
|
|
110
112
|
try {
|
|
111
113
|
const humanMessage = new import_messages.HumanMessage(question);
|
|
112
114
|
this.messageHistory.push(humanMessage);
|
|
113
115
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
114
|
-
let fullResponse = "";
|
|
116
|
+
let fullResponse = "", tokenIdx = 0;
|
|
115
117
|
for await (const chunk of stream) {
|
|
118
|
+
if (loader.isSpinning)
|
|
119
|
+
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
116
120
|
const content = chunk.content;
|
|
117
121
|
if (typeof content === "string") {
|
|
118
122
|
fullResponse += content;
|
|
119
123
|
onChunk(content);
|
|
120
124
|
}
|
|
125
|
+
tokenIdx++;
|
|
121
126
|
}
|
|
122
127
|
fullResponse += "\n";
|
|
123
128
|
onChunk("\n");
|
|
124
129
|
this.messageHistory.push(new import_messages.AIMessage(fullResponse));
|
|
125
130
|
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
126
131
|
} catch (error) {
|
|
132
|
+
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
127
133
|
throw new Error("Failed to stream response");
|
|
128
134
|
}
|
|
129
135
|
}
|
package/cjs/src/executors.js
CHANGED
|
@@ -205,7 +205,7 @@ class Executor {
|
|
|
205
205
|
`${dirname}/${filename}`
|
|
206
206
|
);
|
|
207
207
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
208
|
-
this.writeFile(convertedTargetPath, content);
|
|
208
|
+
this.writeFile(convertedTargetPath, content, { overwrite });
|
|
209
209
|
} else if (targetPath.endsWith(".template")) {
|
|
210
210
|
const content = await import_promises.default.readFile(templatePath, "utf8");
|
|
211
211
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
@@ -217,7 +217,7 @@ class Executor {
|
|
|
217
217
|
content
|
|
218
218
|
);
|
|
219
219
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
220
|
-
this.writeFile(convertedTargetPath, convertedContent);
|
|
220
|
+
this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
async applyTemplate({
|
package/esm/src/aiEditor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger } from "@akanjs/common";
|
|
2
2
|
import { input, select } from "@inquirer/prompts";
|
|
3
|
+
import ora from "ora";
|
|
3
4
|
import { AIMessage, HumanMessage } from "@langchain/core/messages";
|
|
4
5
|
import { ChatOpenAI } from "@langchain/openai";
|
|
5
6
|
import chalk from "chalk";
|
|
@@ -74,23 +75,28 @@ class AiSession {
|
|
|
74
75
|
await AiSession.init();
|
|
75
76
|
if (!AiSession.#chat)
|
|
76
77
|
throw new Error("Failed to initialize the AI session");
|
|
78
|
+
const loader = ora(`${AiSession.#chat.model} is thinking...`).start();
|
|
77
79
|
try {
|
|
78
80
|
const humanMessage = new HumanMessage(question);
|
|
79
81
|
this.messageHistory.push(humanMessage);
|
|
80
82
|
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
81
|
-
let fullResponse = "";
|
|
83
|
+
let fullResponse = "", tokenIdx = 0;
|
|
82
84
|
for await (const chunk of stream) {
|
|
85
|
+
if (loader.isSpinning)
|
|
86
|
+
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
83
87
|
const content = chunk.content;
|
|
84
88
|
if (typeof content === "string") {
|
|
85
89
|
fullResponse += content;
|
|
86
90
|
onChunk(content);
|
|
87
91
|
}
|
|
92
|
+
tokenIdx++;
|
|
88
93
|
}
|
|
89
94
|
fullResponse += "\n";
|
|
90
95
|
onChunk("\n");
|
|
91
96
|
this.messageHistory.push(new AIMessage(fullResponse));
|
|
92
97
|
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
93
98
|
} catch (error) {
|
|
99
|
+
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
94
100
|
throw new Error("Failed to stream response");
|
|
95
101
|
}
|
|
96
102
|
}
|
package/esm/src/executors.js
CHANGED
|
@@ -172,7 +172,7 @@ class Executor {
|
|
|
172
172
|
`${dirname}/${filename}`
|
|
173
173
|
);
|
|
174
174
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
175
|
-
this.writeFile(convertedTargetPath, content);
|
|
175
|
+
this.writeFile(convertedTargetPath, content, { overwrite });
|
|
176
176
|
} else if (targetPath.endsWith(".template")) {
|
|
177
177
|
const content = await fsPromise.readFile(templatePath, "utf8");
|
|
178
178
|
const convertedTargetPath = Object.entries(dict).reduce(
|
|
@@ -184,7 +184,7 @@ class Executor {
|
|
|
184
184
|
content
|
|
185
185
|
);
|
|
186
186
|
this.logger.verbose(`Apply template ${templatePath} to ${convertedTargetPath}`);
|
|
187
|
-
this.writeFile(convertedTargetPath, convertedContent);
|
|
187
|
+
this.writeFile(convertedTargetPath, convertedContent, { overwrite });
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
async applyTemplate({
|