@akanjs/devkit 1.0.20 → 2.1.0-rc.1
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/README.ko.md +65 -0
- package/README.md +62 -6
- package/aiEditor.ts +304 -0
- package/akanApp/akanApp.host.ts +393 -0
- package/akanApp/index.ts +1 -0
- package/akanConfig/akanConfig.test.ts +236 -0
- package/akanConfig/akanConfig.ts +384 -0
- package/akanConfig/index.ts +2 -0
- package/akanConfig/types.ts +23 -0
- package/applicationBuildReporter.ts +69 -0
- package/applicationBuildRunner.ts +302 -0
- package/applicationReleasePackager.ts +206 -0
- package/artifact/implicitRootLayout.ts +155 -0
- package/artifact/index.ts +1 -0
- package/artifact/routeSeedIndex.test.ts +98 -0
- package/artifact/routeSeedIndex.ts +130 -0
- package/auth.ts +41 -0
- package/builder.ts +164 -0
- package/capacitor.base.config.ts +88 -0
- package/capacitorApp.ts +440 -0
- package/commandDecorators/argMeta.ts +102 -0
- package/commandDecorators/command.ts +351 -0
- package/commandDecorators/commandBuilder.ts +224 -0
- package/commandDecorators/commandDecorators.test.ts +212 -0
- package/commandDecorators/commandMeta.ts +7 -0
- package/commandDecorators/dependencyBuilder.ts +100 -0
- package/{esm/src/commandDecorators/helpFormatter.js → commandDecorators/helpFormatter.ts} +100 -47
- package/{esm/src/commandDecorators/index.js → commandDecorators/index.ts} +4 -2
- package/commandDecorators/targetMeta.ts +31 -0
- package/commandDecorators/types.ts +10 -0
- package/constants.ts +25 -0
- package/createTunnel.ts +36 -0
- package/dependencyScanner.ts +357 -0
- package/devkitUtils.test.ts +259 -0
- package/executors.test.ts +315 -0
- package/executors.ts +1390 -0
- package/{esm/src/extractDeps.js → extractDeps.ts} +26 -20
- package/{esm/src/fileEditor.js → fileEditor.ts} +51 -32
- package/fileSys.ts +39 -0
- package/frontendBuild/allRoutesBuilder.ts +103 -0
- package/frontendBuild/buildRouteClient.test.ts +190 -0
- package/frontendBuild/clientBuildTypes.ts +114 -0
- package/frontendBuild/clientEntriesBundler.ts +303 -0
- package/frontendBuild/clientEntryDiscovery.ts +199 -0
- package/frontendBuild/csrArtifactBuilder.ts +237 -0
- package/frontendBuild/cssCompiler.ts +286 -0
- package/frontendBuild/cssImportResolver.ts +116 -0
- package/frontendBuild/fontOptimizer.ts +427 -0
- package/frontendBuild/frontendBuild.test.ts +204 -0
- package/frontendBuild/hmrChangeClassifier.ts +28 -0
- package/frontendBuild/hmrWatcher.ts +102 -0
- package/frontendBuild/index.ts +18 -0
- package/frontendBuild/pagesBundleBuilder.ts +137 -0
- package/frontendBuild/pagesEntrySourceGenerator.ts +37 -0
- package/frontendBuild/precompressArtifacts.ts +59 -0
- package/frontendBuild/routeClientBuilder.ts +290 -0
- package/frontendBuild/routesManifestArtifactSerializer.ts +62 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +139 -0
- package/frontendBuild/vendorSpecifiers.ts +16 -0
- package/frontendBuild/watchRootResolver.ts +28 -0
- package/getCredentials.ts +19 -0
- package/getDirname.ts +3 -0
- package/getModelFileData.ts +59 -0
- package/getRelatedCnsts.ts +313 -0
- package/guideline.ts +19 -0
- package/incrementalBuilder/incrementalBuilder.host.test.ts +51 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +152 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +331 -0
- package/incrementalBuilder/index.ts +1 -0
- package/{esm/src/index.js → index.ts} +28 -15
- package/lint/no-deep-internal-import.grit +25 -0
- package/lint/no-import-client-functions.grit +32 -0
- package/lint/no-import-external-library.grit +21 -0
- package/lint/no-js-private-class-method.grit +42 -0
- package/lint/no-use-client-in-server.grit +7 -0
- package/lint/non-scalar-props-restricted.grit +13 -0
- package/linter.ts +271 -0
- package/mobile/index.ts +1 -0
- package/mobile/mobileTarget.test.ts +53 -0
- package/mobile/mobileTarget.ts +88 -0
- package/package.json +48 -31
- package/prompter.ts +72 -0
- package/scanInfo.ts +606 -0
- package/selectModel.ts +11 -0
- package/{esm/src/spinner.js → spinner.ts} +22 -28
- package/{esm/src/capacitorApp.js → src/capacitorApp.ts} +82 -81
- package/sshTunnel.ts +152 -0
- package/{esm/src/streamAi.js → streamAi.ts} +18 -12
- package/transforms/barrelAnalyzer.ts +278 -0
- package/transforms/barrelImportsPlugin.ts +504 -0
- package/transforms/externalizeFrameworkPlugin.ts +185 -0
- package/transforms/index.ts +5 -0
- package/transforms/rscUseClientTransform.ts +59 -0
- package/transforms/transforms.test.ts +208 -0
- package/transforms/useClientBundlePlugin.ts +47 -0
- package/tsconfig.json +37 -0
- package/typeChecker.ts +264 -0
- package/types.ts +44 -0
- package/ui/MultiScrollList.tsx +242 -0
- package/ui/ScrollList.tsx +107 -0
- package/ui/index.ts +2 -0
- package/{esm/src/uploadRelease.js → uploadRelease.ts} +50 -34
- package/{esm/src/useStdoutDimensions.js → useStdoutDimensions.ts} +5 -5
- package/cjs/index.js +0 -21
- package/cjs/src/aiEditor.js +0 -311
- package/cjs/src/auth.js +0 -72
- package/cjs/src/builder.js +0 -114
- package/cjs/src/capacitorApp.js +0 -313
- package/cjs/src/commandDecorators/argMeta.js +0 -88
- package/cjs/src/commandDecorators/command.js +0 -324
- package/cjs/src/commandDecorators/commandMeta.js +0 -30
- package/cjs/src/commandDecorators/helpFormatter.js +0 -211
- package/cjs/src/commandDecorators/index.js +0 -31
- package/cjs/src/commandDecorators/targetMeta.js +0 -57
- package/cjs/src/commandDecorators/types.js +0 -15
- package/cjs/src/constants.js +0 -46
- package/cjs/src/createTunnel.js +0 -49
- package/cjs/src/dependencyScanner.js +0 -220
- package/cjs/src/executors.js +0 -964
- package/cjs/src/extractDeps.js +0 -103
- package/cjs/src/fileEditor.js +0 -120
- package/cjs/src/getCredentials.js +0 -44
- package/cjs/src/getDirname.js +0 -38
- package/cjs/src/getModelFileData.js +0 -66
- package/cjs/src/getRelatedCnsts.js +0 -260
- package/cjs/src/guideline.js +0 -15
- package/cjs/src/index.js +0 -65
- package/cjs/src/linter.js +0 -238
- package/cjs/src/prompter.js +0 -85
- package/cjs/src/scanInfo.js +0 -491
- package/cjs/src/selectModel.js +0 -46
- package/cjs/src/spinner.js +0 -93
- package/cjs/src/streamAi.js +0 -62
- package/cjs/src/typeChecker.js +0 -207
- package/cjs/src/types.js +0 -15
- package/cjs/src/uploadRelease.js +0 -112
- package/cjs/src/useStdoutDimensions.js +0 -43
- package/esm/index.js +0 -1
- package/esm/src/aiEditor.js +0 -282
- package/esm/src/auth.js +0 -42
- package/esm/src/builder.js +0 -81
- package/esm/src/commandDecorators/argMeta.js +0 -54
- package/esm/src/commandDecorators/command.js +0 -290
- package/esm/src/commandDecorators/commandMeta.js +0 -7
- package/esm/src/commandDecorators/targetMeta.js +0 -33
- package/esm/src/commandDecorators/types.js +0 -0
- package/esm/src/constants.js +0 -17
- package/esm/src/createTunnel.js +0 -26
- package/esm/src/dependencyScanner.js +0 -187
- package/esm/src/executors.js +0 -928
- package/esm/src/getCredentials.js +0 -11
- package/esm/src/getDirname.js +0 -5
- package/esm/src/getModelFileData.js +0 -33
- package/esm/src/getRelatedCnsts.js +0 -221
- package/esm/src/guideline.js +0 -0
- package/esm/src/linter.js +0 -205
- package/esm/src/prompter.js +0 -51
- package/esm/src/scanInfo.js +0 -455
- package/esm/src/selectModel.js +0 -13
- package/esm/src/typeChecker.js +0 -174
- package/esm/src/types.js +0 -0
- package/index.d.ts +0 -1
- package/src/aiEditor.d.ts +0 -50
- package/src/auth.d.ts +0 -9
- package/src/builder.d.ts +0 -18
- package/src/capacitorApp.d.ts +0 -39
- package/src/commandDecorators/argMeta.d.ts +0 -67
- package/src/commandDecorators/command.d.ts +0 -2
- package/src/commandDecorators/commandMeta.d.ts +0 -2
- package/src/commandDecorators/helpFormatter.d.ts +0 -3
- package/src/commandDecorators/index.d.ts +0 -6
- package/src/commandDecorators/targetMeta.d.ts +0 -19
- package/src/commandDecorators/types.d.ts +0 -1
- package/src/constants.d.ts +0 -26
- package/src/createTunnel.d.ts +0 -8
- package/src/dependencyScanner.d.ts +0 -23
- package/src/executors.d.ts +0 -296
- package/src/extractDeps.d.ts +0 -7
- package/src/fileEditor.d.ts +0 -16
- package/src/getCredentials.d.ts +0 -12
- package/src/getDirname.d.ts +0 -1
- package/src/getModelFileData.d.ts +0 -16
- package/src/getRelatedCnsts.d.ts +0 -53
- package/src/guideline.d.ts +0 -19
- package/src/index.d.ts +0 -23
- package/src/linter.d.ts +0 -109
- package/src/prompter.d.ts +0 -14
- package/src/scanInfo.d.ts +0 -82
- package/src/selectModel.d.ts +0 -1
- package/src/spinner.d.ts +0 -20
- package/src/streamAi.d.ts +0 -6
- package/src/typeChecker.d.ts +0 -52
- package/src/types.d.ts +0 -31
- package/src/uploadRelease.d.ts +0 -10
- package/src/useStdoutDimensions.d.ts +0 -1
package/cjs/src/aiEditor.js
DELETED
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var aiEditor_exports = {};
|
|
29
|
-
__export(aiEditor_exports, {
|
|
30
|
-
AiSession: () => AiSession,
|
|
31
|
-
supportedLlmModels: () => supportedLlmModels
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(aiEditor_exports);
|
|
34
|
-
var import_common = require("@akanjs/common");
|
|
35
|
-
var import_prompts = require("@inquirer/prompts");
|
|
36
|
-
var import_messages = require("@langchain/core/messages");
|
|
37
|
-
var import_deepseek = require("@langchain/deepseek");
|
|
38
|
-
var import_openai = require("@langchain/openai");
|
|
39
|
-
var import_chalk = __toESM(require("chalk"));
|
|
40
|
-
var import_fs = __toESM(require("fs"));
|
|
41
|
-
var import_auth = require("./auth");
|
|
42
|
-
var import_spinner = require("./spinner");
|
|
43
|
-
const MAX_ASK_TRY = 300;
|
|
44
|
-
const supportedLlmModels = ["deepseek-chat", "deepseek-reasoner"];
|
|
45
|
-
class AiSession {
|
|
46
|
-
static #cacheDir = "node_modules/.cache/akan/aiSession";
|
|
47
|
-
static #chat = null;
|
|
48
|
-
static async init({ temperature = 0, useExisting = true } = {}) {
|
|
49
|
-
if (useExisting) {
|
|
50
|
-
const llmConfig2 = this.getLlmConfig();
|
|
51
|
-
if (llmConfig2) {
|
|
52
|
-
this.#setChatModel(llmConfig2.model, llmConfig2.apiKey);
|
|
53
|
-
import_common.Logger.rawLog(import_chalk.default.dim(`\u{1F916}akan editor uses existing LLM config (${llmConfig2.model})`));
|
|
54
|
-
return this;
|
|
55
|
-
}
|
|
56
|
-
} else
|
|
57
|
-
import_common.Logger.rawLog(import_chalk.default.yellow("\u{1F916}akan-editor is not initialized. LLM configuration should be set first."));
|
|
58
|
-
const llmConfig = await this.#requestLlmConfig();
|
|
59
|
-
const { model, apiKey } = llmConfig;
|
|
60
|
-
await this.#validateApiKey(model, apiKey);
|
|
61
|
-
return this.#setChatModel(model, apiKey, { temperature }).setLlmConfig({ model, apiKey });
|
|
62
|
-
}
|
|
63
|
-
static #setChatModel(model, apiKey, { temperature = 0 } = {}) {
|
|
64
|
-
this.#chat = new import_deepseek.ChatDeepSeek({
|
|
65
|
-
modelName: model,
|
|
66
|
-
temperature,
|
|
67
|
-
streaming: true,
|
|
68
|
-
apiKey
|
|
69
|
-
// configuration: { baseURL: "https://api.deepseek.com/v1", apiKey },
|
|
70
|
-
});
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
static getLlmConfig() {
|
|
74
|
-
const akanConfig = (0, import_auth.getAkanGlobalConfig)();
|
|
75
|
-
return akanConfig.llm ?? null;
|
|
76
|
-
}
|
|
77
|
-
static setLlmConfig(llmConfig) {
|
|
78
|
-
const akanConfig = (0, import_auth.getAkanGlobalConfig)();
|
|
79
|
-
akanConfig.llm = llmConfig;
|
|
80
|
-
(0, import_auth.setAkanGlobalConfig)(akanConfig);
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
static async #requestLlmConfig() {
|
|
84
|
-
const model = await (0, import_prompts.select)({ message: "Select a LLM model", choices: supportedLlmModels });
|
|
85
|
-
const apiKey = await (0, import_prompts.input)({ message: "Enter your API key" });
|
|
86
|
-
return { model, apiKey };
|
|
87
|
-
}
|
|
88
|
-
static async #validateApiKey(modelName, apiKey) {
|
|
89
|
-
const spinner = new import_spinner.Spinner("Validating LLM API key...", { prefix: `\u{1F916}akan-editor` }).start();
|
|
90
|
-
const chat = new import_openai.ChatOpenAI({
|
|
91
|
-
modelName,
|
|
92
|
-
temperature: 0,
|
|
93
|
-
configuration: { baseURL: "https://api.deepseek.com/v1", apiKey }
|
|
94
|
-
});
|
|
95
|
-
try {
|
|
96
|
-
await chat.invoke("Hi, and just say 'ok'");
|
|
97
|
-
spinner.succeed("LLM API key is valid");
|
|
98
|
-
return true;
|
|
99
|
-
} catch (error) {
|
|
100
|
-
spinner.fail(
|
|
101
|
-
import_chalk.default.red(
|
|
102
|
-
`LLM API key is invalid. Please check your API key and try again. You can set it again by running "akan set-llm" or reset by running "akan reset-llm"`
|
|
103
|
-
)
|
|
104
|
-
);
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
static clearCache(workspaceRoot) {
|
|
109
|
-
const cacheDir = `${workspaceRoot}/${this.#cacheDir}`;
|
|
110
|
-
import_fs.default.rmSync(cacheDir, { recursive: true, force: true });
|
|
111
|
-
}
|
|
112
|
-
messageHistory = [];
|
|
113
|
-
sessionKey;
|
|
114
|
-
isCacheLoaded = false;
|
|
115
|
-
workspace;
|
|
116
|
-
constructor(type, { workspace, cacheKey, isContinued }) {
|
|
117
|
-
this.workspace = workspace;
|
|
118
|
-
this.sessionKey = `${type}${cacheKey ? `-${cacheKey}` : ""}`;
|
|
119
|
-
if (isContinued)
|
|
120
|
-
this.#loadCache();
|
|
121
|
-
}
|
|
122
|
-
#loadCache() {
|
|
123
|
-
const cacheFile = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
124
|
-
const isCacheExists = this.workspace.exists(cacheFile);
|
|
125
|
-
if (isCacheExists)
|
|
126
|
-
this.messageHistory = (0, import_messages.mapStoredMessagesToChatMessages)(this.workspace.readJson(cacheFile));
|
|
127
|
-
else
|
|
128
|
-
this.messageHistory = [];
|
|
129
|
-
this.isCacheLoaded = isCacheExists;
|
|
130
|
-
return isCacheExists;
|
|
131
|
-
}
|
|
132
|
-
#saveCache() {
|
|
133
|
-
const cacheFilePath = `${AiSession.#cacheDir}/${this.sessionKey}.json`;
|
|
134
|
-
this.workspace.writeJson(cacheFilePath, (0, import_messages.mapChatMessagesToStoredMessages)(this.messageHistory));
|
|
135
|
-
}
|
|
136
|
-
async ask(question, {
|
|
137
|
-
onReasoning = (reasoning) => {
|
|
138
|
-
import_common.Logger.raw(import_chalk.default.dim(reasoning));
|
|
139
|
-
},
|
|
140
|
-
onChunk = (chunk) => {
|
|
141
|
-
import_common.Logger.raw(chunk);
|
|
142
|
-
}
|
|
143
|
-
} = {}) {
|
|
144
|
-
if (!AiSession.#chat)
|
|
145
|
-
await AiSession.init();
|
|
146
|
-
if (!AiSession.#chat)
|
|
147
|
-
throw new Error("Failed to initialize the AI session");
|
|
148
|
-
const loader = new import_spinner.Spinner(`${AiSession.#chat.model} is thinking...`, {
|
|
149
|
-
prefix: `\u{1F916}akan-editor`
|
|
150
|
-
}).start();
|
|
151
|
-
try {
|
|
152
|
-
const humanMessage = new import_messages.HumanMessage(question);
|
|
153
|
-
this.messageHistory.push(humanMessage);
|
|
154
|
-
const stream = await AiSession.#chat.stream(this.messageHistory);
|
|
155
|
-
let reasoningResponse = "", fullResponse = "", tokenIdx = 0;
|
|
156
|
-
for await (const chunk of stream) {
|
|
157
|
-
if (loader.isSpinning())
|
|
158
|
-
loader.succeed(`${AiSession.#chat.model} responded`);
|
|
159
|
-
if (!fullResponse.length) {
|
|
160
|
-
const reasoningContent = chunk.additional_kwargs.reasoning_content ?? "";
|
|
161
|
-
if (reasoningContent.length) {
|
|
162
|
-
reasoningResponse += reasoningContent;
|
|
163
|
-
onReasoning(reasoningContent);
|
|
164
|
-
continue;
|
|
165
|
-
} else if (chunk.content.length) {
|
|
166
|
-
reasoningResponse += "\n";
|
|
167
|
-
onReasoning(reasoningResponse);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const content = chunk.content;
|
|
171
|
-
if (typeof content === "string") {
|
|
172
|
-
fullResponse += content;
|
|
173
|
-
onChunk(content);
|
|
174
|
-
}
|
|
175
|
-
tokenIdx++;
|
|
176
|
-
}
|
|
177
|
-
fullResponse += "\n";
|
|
178
|
-
onChunk("\n");
|
|
179
|
-
this.messageHistory.push(new import_messages.AIMessage(fullResponse));
|
|
180
|
-
return { content: fullResponse, messageHistory: this.messageHistory };
|
|
181
|
-
} catch (error) {
|
|
182
|
-
loader.fail(`${AiSession.#chat.model} failed to respond`);
|
|
183
|
-
throw new Error("Failed to stream response");
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async edit(question, { onChunk, onReasoning, maxTry = MAX_ASK_TRY, validate, approve } = {}) {
|
|
187
|
-
for (let tryCount = 0; tryCount < maxTry; tryCount++) {
|
|
188
|
-
let response = await this.ask(question, { onChunk, onReasoning });
|
|
189
|
-
if (validate?.length && tryCount === 0) {
|
|
190
|
-
const validateQuestion = `Double check if the response meets the requirements and conditions, and follow the instructions. If not, rewrite it.
|
|
191
|
-
${validate.map((v) => `- ${v}`).join("\n")}`;
|
|
192
|
-
response = await this.ask(validateQuestion, { onChunk, onReasoning });
|
|
193
|
-
}
|
|
194
|
-
const isConfirmed = approve ? true : await (0, import_prompts.select)({
|
|
195
|
-
message: "Do you want to edit the response?",
|
|
196
|
-
choices: [
|
|
197
|
-
{ name: "\u2705 Yes, confirm and apply this result", value: true },
|
|
198
|
-
{ name: "\u{1F504} No, I want to edit it more", value: false }
|
|
199
|
-
]
|
|
200
|
-
});
|
|
201
|
-
if (isConfirmed) {
|
|
202
|
-
this.#saveCache();
|
|
203
|
-
return response.content;
|
|
204
|
-
}
|
|
205
|
-
question = await (0, import_prompts.input)({ message: "What do you want to change?" });
|
|
206
|
-
tryCount++;
|
|
207
|
-
}
|
|
208
|
-
throw new Error("Failed to edit");
|
|
209
|
-
}
|
|
210
|
-
async editTypescript(question, options = {}) {
|
|
211
|
-
const content = await this.edit(question, options);
|
|
212
|
-
return this.#getTypescriptCode(content);
|
|
213
|
-
}
|
|
214
|
-
#getTypescriptCode(content) {
|
|
215
|
-
//! will be deprecated
|
|
216
|
-
const code = /```(typescript|tsx)([\s\S]*?)```/.exec(content);
|
|
217
|
-
return code ? code[2] : content;
|
|
218
|
-
}
|
|
219
|
-
addToolMessgaes(messages) {
|
|
220
|
-
const toolMessages = messages.map((message) => new import_messages.HumanMessage(message.content));
|
|
221
|
-
this.messageHistory.push(...toolMessages);
|
|
222
|
-
return this;
|
|
223
|
-
}
|
|
224
|
-
async writeTypescripts(question, executor, options = {}) {
|
|
225
|
-
const content = await this.edit(question, options);
|
|
226
|
-
const writes = this.#getTypescriptCodes(content);
|
|
227
|
-
for (const write of writes)
|
|
228
|
-
executor.writeFile(write.filePath, write.content);
|
|
229
|
-
return await this.#tryFixTypescripts(writes, executor, options);
|
|
230
|
-
}
|
|
231
|
-
async #editTypescripts(question, options = {}) {
|
|
232
|
-
const content = await this.edit(question, options);
|
|
233
|
-
return this.#getTypescriptCodes(content);
|
|
234
|
-
}
|
|
235
|
-
async #tryFixTypescripts(writes, executor, options = {}) {
|
|
236
|
-
const MAX_EDIT_TRY = 5;
|
|
237
|
-
for (let tryCount = 0; tryCount < MAX_EDIT_TRY; tryCount++) {
|
|
238
|
-
const loader = new import_spinner.Spinner(`Type checking and linting...`, { prefix: `\u{1F916}akan-editor` }).start();
|
|
239
|
-
const fileChecks = await Promise.all(
|
|
240
|
-
writes.map(async ({ filePath }) => {
|
|
241
|
-
const typeCheckResult = executor.typeCheck(filePath);
|
|
242
|
-
const lintResult = await executor.lint(filePath);
|
|
243
|
-
const needFix2 = !!typeCheckResult.fileErrors.length || !!lintResult.errors.length;
|
|
244
|
-
return { filePath, typeCheckResult, lintResult, needFix: needFix2 };
|
|
245
|
-
})
|
|
246
|
-
);
|
|
247
|
-
const needFix = fileChecks.some((fileCheck) => fileCheck.needFix);
|
|
248
|
-
if (needFix) {
|
|
249
|
-
loader.fail("Type checking and linting has some errors, try to fix them");
|
|
250
|
-
fileChecks.forEach((fileCheck) => {
|
|
251
|
-
import_common.Logger.rawLog(
|
|
252
|
-
`TypeCheck Result
|
|
253
|
-
${fileCheck.typeCheckResult.message}
|
|
254
|
-
Lint Result
|
|
255
|
-
${fileCheck.lintResult.message}`
|
|
256
|
-
);
|
|
257
|
-
this.addToolMessgaes([
|
|
258
|
-
{ type: "typescript", content: fileCheck.typeCheckResult.message },
|
|
259
|
-
{ type: "eslint", content: fileCheck.lintResult.message }
|
|
260
|
-
]);
|
|
261
|
-
});
|
|
262
|
-
writes = await this.#editTypescripts("Fix the typescript and eslint errors", {
|
|
263
|
-
...options,
|
|
264
|
-
validate: void 0,
|
|
265
|
-
approve: true
|
|
266
|
-
});
|
|
267
|
-
for (const write of writes)
|
|
268
|
-
executor.writeFile(write.filePath, write.content);
|
|
269
|
-
} else {
|
|
270
|
-
loader.succeed("Type checking and linting has no errors");
|
|
271
|
-
return writes;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
throw new Error("Failed to create scalar");
|
|
275
|
-
}
|
|
276
|
-
#getTypescriptCodes(text) {
|
|
277
|
-
const codes = text.match(/```(typescript|tsx)([\s\S]*?)```/g);
|
|
278
|
-
if (!codes)
|
|
279
|
-
return [];
|
|
280
|
-
const result = codes.map((code) => {
|
|
281
|
-
const content = /```(typescript|tsx)([\s\S]*?)```/.exec(code)?.[2];
|
|
282
|
-
if (!content)
|
|
283
|
-
return null;
|
|
284
|
-
const filePath = /\/\/ File: (.*?)(?:\n|$)/.exec(content)?.[1]?.trim();
|
|
285
|
-
if (!filePath)
|
|
286
|
-
return null;
|
|
287
|
-
const contentWithoutFilepath = content.replace(`// File: ${filePath}
|
|
288
|
-
`, "").trim();
|
|
289
|
-
return { filePath, content: contentWithoutFilepath };
|
|
290
|
-
});
|
|
291
|
-
return result.filter((code) => code !== null);
|
|
292
|
-
}
|
|
293
|
-
async editMarkdown(request, options = {}) {
|
|
294
|
-
const content = await this.edit(request, options);
|
|
295
|
-
return this.#getMarkdownContent(content);
|
|
296
|
-
}
|
|
297
|
-
#getMarkdownContent(text) {
|
|
298
|
-
const searchText = "```markdown";
|
|
299
|
-
const firstIndex = text.indexOf("```markdown");
|
|
300
|
-
const lastIndex = text.lastIndexOf("```");
|
|
301
|
-
if (firstIndex === -1)
|
|
302
|
-
return text;
|
|
303
|
-
else
|
|
304
|
-
return text.slice(firstIndex + searchText.length, lastIndex).trim();
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
308
|
-
0 && (module.exports = {
|
|
309
|
-
AiSession,
|
|
310
|
-
supportedLlmModels
|
|
311
|
-
});
|
package/cjs/src/auth.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var auth_exports = {};
|
|
29
|
-
__export(auth_exports, {
|
|
30
|
-
getAkanGlobalConfig: () => getAkanGlobalConfig,
|
|
31
|
-
getHostConfig: () => getHostConfig,
|
|
32
|
-
getSelf: () => getSelf,
|
|
33
|
-
setAkanGlobalConfig: () => setAkanGlobalConfig,
|
|
34
|
-
setHostConfig: () => setHostConfig
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(auth_exports);
|
|
37
|
-
var import_fs = __toESM(require("fs"));
|
|
38
|
-
var import_constants = require("./constants");
|
|
39
|
-
const getAkanGlobalConfig = () => {
|
|
40
|
-
const akanConfig = import_fs.default.existsSync(import_constants.configPath) ? JSON.parse(import_fs.default.readFileSync(import_constants.configPath, "utf8")) : import_constants.defaultAkanGlobalConfig;
|
|
41
|
-
return akanConfig;
|
|
42
|
-
};
|
|
43
|
-
const setAkanGlobalConfig = (akanConfig) => {
|
|
44
|
-
import_fs.default.mkdirSync(import_constants.basePath, { recursive: true });
|
|
45
|
-
import_fs.default.writeFileSync(import_constants.configPath, JSON.stringify(akanConfig, null, 2));
|
|
46
|
-
};
|
|
47
|
-
const getHostConfig = (host = import_constants.akanCloudHost) => {
|
|
48
|
-
const akanConfig = getAkanGlobalConfig();
|
|
49
|
-
return akanConfig.cloudHost[host] ?? import_constants.defaultHostConfig;
|
|
50
|
-
};
|
|
51
|
-
const setHostConfig = (host = import_constants.akanCloudHost, config = {}) => {
|
|
52
|
-
const akanConfig = getAkanGlobalConfig();
|
|
53
|
-
akanConfig.cloudHost[host] = config;
|
|
54
|
-
setAkanGlobalConfig(akanConfig);
|
|
55
|
-
};
|
|
56
|
-
const getSelf = async (token) => {
|
|
57
|
-
try {
|
|
58
|
-
const res = await fetch(`${import_constants.akanCloudBackendUrl}/user/getSelf`, { headers: { Authorization: `Bearer ${token}` } });
|
|
59
|
-
const user = await res.json();
|
|
60
|
-
return user;
|
|
61
|
-
} catch (e) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
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
|
-
});
|
package/cjs/src/builder.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var builder_exports = {};
|
|
29
|
-
__export(builder_exports, {
|
|
30
|
-
Builder: () => Builder
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(builder_exports);
|
|
33
|
-
var esbuild = __toESM(require("esbuild"));
|
|
34
|
-
var import_esbuild_plugin_d = require("esbuild-plugin-d.ts");
|
|
35
|
-
var import_fs = __toESM(require("fs"));
|
|
36
|
-
var import_extractDeps = require("./extractDeps");
|
|
37
|
-
const assetExtensions = [".css", ".md", ".js", ".png", ".ico", ".svg", ".json", ".template"];
|
|
38
|
-
const assetLoader = Object.fromEntries(assetExtensions.map((ext) => [ext, "copy"]));
|
|
39
|
-
class Builder {
|
|
40
|
-
#executor;
|
|
41
|
-
#distExecutor;
|
|
42
|
-
#pkgJson;
|
|
43
|
-
#rootPackageJson;
|
|
44
|
-
constructor({ executor, distExecutor, pkgJson, rootPackageJson }) {
|
|
45
|
-
this.#executor = executor;
|
|
46
|
-
this.#distExecutor = distExecutor;
|
|
47
|
-
this.#pkgJson = pkgJson;
|
|
48
|
-
this.#rootPackageJson = rootPackageJson;
|
|
49
|
-
}
|
|
50
|
-
#getBuildOptions(format, { bundle = false, additionalEntryPoints = [] } = {}) {
|
|
51
|
-
return {
|
|
52
|
-
entryPoints: [
|
|
53
|
-
...bundle ? [`${this.#executor.cwdPath}/index.ts`] : [`${this.#executor.cwdPath}/**/*.ts`, `${this.#executor.cwdPath}/**/*.tsx`],
|
|
54
|
-
...additionalEntryPoints
|
|
55
|
-
],
|
|
56
|
-
bundle,
|
|
57
|
-
packages: "external",
|
|
58
|
-
splitting: false,
|
|
59
|
-
platform: this.#pkgJson.esbuild?.platform,
|
|
60
|
-
format,
|
|
61
|
-
outdir: `${this.#distExecutor.cwdPath}/${format}`,
|
|
62
|
-
logLevel: "error",
|
|
63
|
-
// external: ["react", "react-dom"],
|
|
64
|
-
loader: assetLoader
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
#getAssetBuildOptions() {
|
|
68
|
-
return {
|
|
69
|
-
write: true,
|
|
70
|
-
bundle: false,
|
|
71
|
-
entryPoints: [
|
|
72
|
-
`${this.#executor.cwdPath}/**/*.css`,
|
|
73
|
-
`${this.#executor.cwdPath}/**/*.md`,
|
|
74
|
-
`${this.#executor.cwdPath}/**/*.js`
|
|
75
|
-
],
|
|
76
|
-
outdir: this.#distExecutor.cwdPath,
|
|
77
|
-
logLevel: "error",
|
|
78
|
-
loader: assetLoader
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
async build(options = {}) {
|
|
82
|
-
if (import_fs.default.existsSync(this.#distExecutor.cwdPath))
|
|
83
|
-
await this.#distExecutor.exec(`rm -rf ${this.#distExecutor.cwdPath}`);
|
|
84
|
-
const plugins = [(0, import_esbuild_plugin_d.dtsPlugin)({ tsconfig: `${this.#executor.cwdPath}/tsconfig.json` })];
|
|
85
|
-
const [buildResult] = await Promise.all([
|
|
86
|
-
esbuild.build({ ...this.#getBuildOptions("cjs", options), write: false, plugins }),
|
|
87
|
-
esbuild.build({ write: true, ...this.#getBuildOptions("esm", options) }),
|
|
88
|
-
esbuild.build({ ...this.#getAssetBuildOptions() })
|
|
89
|
-
]);
|
|
90
|
-
const existingDeps = Object.keys(this.#pkgJson.dependencies ?? {});
|
|
91
|
-
const dependencies = (0, import_extractDeps.extractDependencies)(buildResult.outputFiles, this.#rootPackageJson, existingDeps);
|
|
92
|
-
const pkgPackageJson = {
|
|
93
|
-
...this.#pkgJson,
|
|
94
|
-
main: "./index.js",
|
|
95
|
-
engines: { node: ">=20" },
|
|
96
|
-
dependencies,
|
|
97
|
-
exports: {
|
|
98
|
-
...this.#pkgJson.exports ?? {},
|
|
99
|
-
".": {
|
|
100
|
-
require: "./cjs/index.js",
|
|
101
|
-
import: "./esm/index.js",
|
|
102
|
-
types: "./index.d.ts"
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
buildResult.outputFiles.map((file) => this.#distExecutor.writeFile(file.path, file.text));
|
|
107
|
-
this.#distExecutor.setPackageJson(pkgPackageJson);
|
|
108
|
-
this.#executor.setPackageJson(pkgPackageJson);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
-
0 && (module.exports = {
|
|
113
|
-
Builder
|
|
114
|
-
});
|