@akanjs/devkit 2.1.1-rc.1 → 2.1.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/aiEditor.test.ts +68 -0
- package/aiEditor.ts +183 -57
- package/cloud/cloudApi.ts +83 -50
- package/cloud/constants.ts +48 -0
- package/cloud/globalConfig.ts +109 -0
- package/cloud/index.ts +2 -0
- package/executors.ts +748 -164
- package/index.ts +2 -3
- package/linter.ts +308 -97
- package/package.json +2 -2
- package/prompter.ts +17 -4
- package/typecheck/typecheck.proc.ts +21 -0
- package/auth.ts +0 -41
- package/constants.ts +0 -32
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import dayjs from "dayjs";
|
|
3
|
+
import { FileSys } from "../fileSys";
|
|
4
|
+
import {
|
|
5
|
+
type AccessToken,
|
|
6
|
+
type AccessTokenDto,
|
|
7
|
+
type AkanGlobalConfig,
|
|
8
|
+
akanCloudHost,
|
|
9
|
+
basePath,
|
|
10
|
+
configPath,
|
|
11
|
+
defaultAkanGlobalConfig,
|
|
12
|
+
defaultHostConfig,
|
|
13
|
+
type HostConfig,
|
|
14
|
+
type HostConfigDto,
|
|
15
|
+
type RemoteEnvServerConfig,
|
|
16
|
+
} from "./constants";
|
|
17
|
+
|
|
18
|
+
export class GlobalConfig {
|
|
19
|
+
static async #getAkanGlobalConfig(): Promise<AkanGlobalConfig> {
|
|
20
|
+
const exists = await FileSys.fileExists(configPath);
|
|
21
|
+
const akanConfig = exists ? await FileSys.readJson<Partial<AkanGlobalConfig>>(configPath) : {};
|
|
22
|
+
return {
|
|
23
|
+
...defaultAkanGlobalConfig,
|
|
24
|
+
...akanConfig,
|
|
25
|
+
cloudHost: akanConfig.cloudHost ?? defaultAkanGlobalConfig.cloudHost,
|
|
26
|
+
remoteEnvServers: akanConfig.remoteEnvServers ?? defaultAkanGlobalConfig.remoteEnvServers,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
static async #setAkanGlobalConfig(akanConfig: AkanGlobalConfig) {
|
|
30
|
+
await mkdir(basePath, { recursive: true });
|
|
31
|
+
await Bun.write(configPath, JSON.stringify(akanConfig, null, 2));
|
|
32
|
+
}
|
|
33
|
+
static async getHostConfig(host = akanCloudHost): Promise<HostConfig> {
|
|
34
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
35
|
+
return GlobalConfig.toHostConfig(akanConfig.cloudHost[host] ?? defaultHostConfig);
|
|
36
|
+
}
|
|
37
|
+
static async setHostConfig(host = akanCloudHost, config: HostConfig = {}) {
|
|
38
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
39
|
+
akanConfig.cloudHost[host] = GlobalConfig.toHostConfigDto(config);
|
|
40
|
+
await GlobalConfig.#setAkanGlobalConfig(akanConfig);
|
|
41
|
+
}
|
|
42
|
+
static async getLlmConfig(): Promise<AkanGlobalConfig["llm"]> {
|
|
43
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
44
|
+
return akanConfig.llm ?? null;
|
|
45
|
+
}
|
|
46
|
+
static async setLlmConfig(llmConfig: AkanGlobalConfig["llm"]) {
|
|
47
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
48
|
+
await GlobalConfig.#setAkanGlobalConfig({ ...akanConfig, llm: llmConfig });
|
|
49
|
+
}
|
|
50
|
+
static async getRemoteEnvServers(): Promise<AkanGlobalConfig["remoteEnvServers"]> {
|
|
51
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
52
|
+
return akanConfig.remoteEnvServers;
|
|
53
|
+
}
|
|
54
|
+
static async setRemoteEnvServer(name: string, config: RemoteEnvServerConfig) {
|
|
55
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
56
|
+
await GlobalConfig.#setAkanGlobalConfig({
|
|
57
|
+
...akanConfig,
|
|
58
|
+
remoteEnvServers: {
|
|
59
|
+
...akanConfig.remoteEnvServers,
|
|
60
|
+
[name]: config,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
static async removeRemoteEnvServer(name: string) {
|
|
65
|
+
const akanConfig = await GlobalConfig.#getAkanGlobalConfig();
|
|
66
|
+
const { [name]: _, ...remoteEnvServers } = akanConfig.remoteEnvServers;
|
|
67
|
+
await GlobalConfig.#setAkanGlobalConfig({
|
|
68
|
+
...akanConfig,
|
|
69
|
+
remoteEnvServers,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
static needRefreshToken(accessToken: AccessToken): boolean {
|
|
73
|
+
return !!accessToken?.expiresAt?.isBefore(dayjs().add(1, "hour"));
|
|
74
|
+
}
|
|
75
|
+
static toAccessToken(accessToken: AccessTokenDto): AccessToken {
|
|
76
|
+
return {
|
|
77
|
+
jwt: accessToken.jwt,
|
|
78
|
+
refreshToken: accessToken.refreshToken ?? null,
|
|
79
|
+
expiresAt: accessToken.expiresAt ? dayjs(accessToken.expiresAt) : null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
static toAccessTokenDto(accessToken: AccessToken): AccessTokenDto {
|
|
83
|
+
return {
|
|
84
|
+
jwt: accessToken.jwt,
|
|
85
|
+
refreshToken: accessToken.refreshToken ?? null,
|
|
86
|
+
expiresAt: accessToken.expiresAt?.toString() ?? null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
static toHostConfigDto(hostConfig: HostConfig): HostConfigDto {
|
|
90
|
+
return {
|
|
91
|
+
auth: {
|
|
92
|
+
accessToken: hostConfig.auth?.accessToken
|
|
93
|
+
? GlobalConfig.toAccessTokenDto(hostConfig.auth.accessToken)
|
|
94
|
+
: undefined,
|
|
95
|
+
self: hostConfig.auth?.self,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
static toHostConfig(hostConfigDto: HostConfigDto): HostConfig {
|
|
100
|
+
return {
|
|
101
|
+
auth: {
|
|
102
|
+
accessToken: hostConfigDto.auth?.accessToken
|
|
103
|
+
? GlobalConfig.toAccessToken(hostConfigDto.auth.accessToken)
|
|
104
|
+
: undefined,
|
|
105
|
+
self: hostConfigDto.auth?.self,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
package/cloud/index.ts
CHANGED