@agents-at-scale/ark 0.1.31
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.md +95 -0
- package/dist/commands/cluster/get-ip.d.ts +2 -0
- package/dist/commands/cluster/get-ip.js +32 -0
- package/dist/commands/cluster/get-type.d.ts +2 -0
- package/dist/commands/cluster/get-type.js +26 -0
- package/dist/commands/cluster/index.d.ts +2 -0
- package/dist/commands/cluster/index.js +10 -0
- package/dist/commands/completion.d.ts +2 -0
- package/dist/commands/completion.js +108 -0
- package/dist/commands/config.d.ts +5 -0
- package/dist/commands/config.js +327 -0
- package/dist/commands/generate/config.d.ts +145 -0
- package/dist/commands/generate/config.js +253 -0
- package/dist/commands/generate/generators/agent.d.ts +2 -0
- package/dist/commands/generate/generators/agent.js +156 -0
- package/dist/commands/generate/generators/index.d.ts +6 -0
- package/dist/commands/generate/generators/index.js +6 -0
- package/dist/commands/generate/generators/marketplace.d.ts +2 -0
- package/dist/commands/generate/generators/marketplace.js +304 -0
- package/dist/commands/generate/generators/mcpserver.d.ts +25 -0
- package/dist/commands/generate/generators/mcpserver.js +350 -0
- package/dist/commands/generate/generators/project.d.ts +2 -0
- package/dist/commands/generate/generators/project.js +784 -0
- package/dist/commands/generate/generators/query.d.ts +2 -0
- package/dist/commands/generate/generators/query.js +213 -0
- package/dist/commands/generate/generators/team.d.ts +2 -0
- package/dist/commands/generate/generators/team.js +407 -0
- package/dist/commands/generate/index.d.ts +24 -0
- package/dist/commands/generate/index.js +357 -0
- package/dist/commands/generate/templateDiscovery.d.ts +30 -0
- package/dist/commands/generate/templateDiscovery.js +94 -0
- package/dist/commands/generate/templateEngine.d.ts +78 -0
- package/dist/commands/generate/templateEngine.js +368 -0
- package/dist/commands/generate/utils/nameUtils.d.ts +35 -0
- package/dist/commands/generate/utils/nameUtils.js +110 -0
- package/dist/commands/generate/utils/projectUtils.d.ts +28 -0
- package/dist/commands/generate/utils/projectUtils.js +133 -0
- package/dist/components/DashboardCLI.d.ts +3 -0
- package/dist/components/DashboardCLI.js +149 -0
- package/dist/components/GeneratorUI.d.ts +3 -0
- package/dist/components/GeneratorUI.js +167 -0
- package/dist/components/statusChecker.d.ts +48 -0
- package/dist/components/statusChecker.js +251 -0
- package/dist/config.d.ts +42 -0
- package/dist/config.js +243 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +67 -0
- package/dist/lib/arkClient.d.ts +32 -0
- package/dist/lib/arkClient.js +43 -0
- package/dist/lib/cluster.d.ts +8 -0
- package/dist/lib/cluster.js +134 -0
- package/dist/lib/config.d.ts +82 -0
- package/dist/lib/config.js +223 -0
- package/dist/lib/consts.d.ts +10 -0
- package/dist/lib/consts.js +15 -0
- package/dist/lib/errors.d.ts +56 -0
- package/dist/lib/errors.js +208 -0
- package/dist/lib/exec.d.ts +5 -0
- package/dist/lib/exec.js +20 -0
- package/dist/lib/gatewayManager.d.ts +24 -0
- package/dist/lib/gatewayManager.js +85 -0
- package/dist/lib/kubernetes.d.ts +28 -0
- package/dist/lib/kubernetes.js +122 -0
- package/dist/lib/progress.d.ts +128 -0
- package/dist/lib/progress.js +273 -0
- package/dist/lib/security.d.ts +37 -0
- package/dist/lib/security.js +295 -0
- package/dist/lib/types.d.ts +37 -0
- package/dist/lib/types.js +1 -0
- package/dist/lib/wrappers/git.d.ts +2 -0
- package/dist/lib/wrappers/git.js +43 -0
- package/dist/ui/MainMenu.d.ts +3 -0
- package/dist/ui/MainMenu.js +116 -0
- package/dist/ui/statusFormatter.d.ts +9 -0
- package/dist/ui/statusFormatter.js +47 -0
- package/package.json +62 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import Debug from 'debug';
|
|
6
|
+
import { ArkClient } from './lib/arkClient.js';
|
|
7
|
+
import { DEFAULT_ADDRESS_ARK_API, CONFIG_DIR_NAME, CONFIG_FILE_NAME, } from './lib/consts.js';
|
|
8
|
+
import { GatewayManager } from './lib/gatewayManager.js';
|
|
9
|
+
import { KubernetesConfigManager } from './lib/kubernetes.js';
|
|
10
|
+
const debug = Debug('ark:config');
|
|
11
|
+
/**
|
|
12
|
+
* ConfigManager handles ARK CLI configuration with automatic service discovery
|
|
13
|
+
* and multiple fallback mechanisms. Complex discovery logic can be debugged by
|
|
14
|
+
* setting DEBUG=ark:config or DEBUG=ark:* environment variable.
|
|
15
|
+
*
|
|
16
|
+
* Example usage:
|
|
17
|
+
* DEBUG=ark:config ark check status
|
|
18
|
+
* DEBUG=ark:* ark dashboard
|
|
19
|
+
*/
|
|
20
|
+
export class ConfigManager {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.kubeConfig = null;
|
|
23
|
+
this.configDir = join(homedir(), '.config', CONFIG_DIR_NAME);
|
|
24
|
+
this.configFile = join(this.configDir, CONFIG_FILE_NAME);
|
|
25
|
+
this.kubernetesManager = new KubernetesConfigManager();
|
|
26
|
+
this.gatewayManager = new GatewayManager();
|
|
27
|
+
}
|
|
28
|
+
async ensureConfigDir() {
|
|
29
|
+
try {
|
|
30
|
+
await fs.mkdir(this.configDir, { recursive: true });
|
|
31
|
+
}
|
|
32
|
+
catch (_error) {
|
|
33
|
+
// Directory might already exist
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async loadConfig() {
|
|
37
|
+
await this.ensureConfigDir();
|
|
38
|
+
try {
|
|
39
|
+
// Check if config file exists
|
|
40
|
+
await fs.access(this.configFile);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
// Config file doesn't exist - start with default config and enrich with kube config
|
|
44
|
+
if (error &&
|
|
45
|
+
typeof error === 'object' &&
|
|
46
|
+
'code' in error &&
|
|
47
|
+
error.code === 'ENOENT') {
|
|
48
|
+
return await this.getDefaultConfig();
|
|
49
|
+
}
|
|
50
|
+
// Other access errors (permissions, etc.) should be thrown
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
// Config file exists - try to read and parse it
|
|
55
|
+
const data = await fs.readFile(this.configFile, 'utf-8');
|
|
56
|
+
const config = JSON.parse(data);
|
|
57
|
+
// Merge with current Kubernetes config if not present
|
|
58
|
+
await this.initKubernetesConfig();
|
|
59
|
+
return {
|
|
60
|
+
...config,
|
|
61
|
+
kubeconfig: config.kubeconfig || this.kubeConfig?.kubeconfig,
|
|
62
|
+
currentContext: config.currentContext || this.kubeConfig?.currentContext,
|
|
63
|
+
kubeNamespace: config.kubeNamespace || this.kubeConfig?.namespace,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
// If it's a JSON parsing error, throw a clear error message
|
|
68
|
+
if (error instanceof SyntaxError) {
|
|
69
|
+
throw new Error(`Invalid JSON in config file ${this.configFile}: ${error.message}`);
|
|
70
|
+
}
|
|
71
|
+
// Other errors (read errors, etc.) should be thrown as-is
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async saveConfig(config) {
|
|
76
|
+
await this.ensureConfigDir();
|
|
77
|
+
const jsonData = JSON.stringify(config, null, 2);
|
|
78
|
+
await fs.writeFile(this.configFile, jsonData);
|
|
79
|
+
}
|
|
80
|
+
async updateConfig(updates) {
|
|
81
|
+
const currentConfig = await this.loadConfig();
|
|
82
|
+
const newConfig = { ...currentConfig, ...updates };
|
|
83
|
+
await this.saveConfig(newConfig);
|
|
84
|
+
return newConfig;
|
|
85
|
+
}
|
|
86
|
+
async getDefaultConfig() {
|
|
87
|
+
// Initialize Kubernetes config to get defaults
|
|
88
|
+
await this.initKubernetesConfig();
|
|
89
|
+
return {
|
|
90
|
+
defaultAgent: 'default',
|
|
91
|
+
defaultModel: 'default',
|
|
92
|
+
defaultNamespace: this.kubeConfig?.namespace || 'default',
|
|
93
|
+
apiBaseUrl: DEFAULT_ADDRESS_ARK_API,
|
|
94
|
+
kubeconfig: this.kubeConfig?.kubeconfig,
|
|
95
|
+
currentContext: this.kubeConfig?.currentContext,
|
|
96
|
+
kubeNamespace: this.kubeConfig?.namespace,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async initializeConfig() {
|
|
100
|
+
const config = await this.loadConfig();
|
|
101
|
+
const defaultConfig = await this.getDefaultConfig();
|
|
102
|
+
const mergedConfig = { ...defaultConfig, ...config };
|
|
103
|
+
await this.saveConfig(mergedConfig);
|
|
104
|
+
return mergedConfig;
|
|
105
|
+
}
|
|
106
|
+
getConfigPath() {
|
|
107
|
+
return this.configFile;
|
|
108
|
+
}
|
|
109
|
+
async getApiBaseUrl() {
|
|
110
|
+
const config = await this.loadConfig();
|
|
111
|
+
// If apiBaseUrl is explicitly set in config, use it
|
|
112
|
+
if (config.apiBaseUrl && config.apiBaseUrl !== DEFAULT_ADDRESS_ARK_API) {
|
|
113
|
+
debug('using explicit config apiBaseUrl: %s', config.apiBaseUrl);
|
|
114
|
+
return config.apiBaseUrl;
|
|
115
|
+
}
|
|
116
|
+
// First try to detect localhost-gateway (works for everyone with standard setup)
|
|
117
|
+
if (await this.isLocalhostGatewayRunning()) {
|
|
118
|
+
const gatewayUrls = this.getLocalhostGatewayUrls();
|
|
119
|
+
const arkApiUrl = gatewayUrls['ark-api'];
|
|
120
|
+
if (arkApiUrl) {
|
|
121
|
+
debug('localhost-gateway detected, using: %s', arkApiUrl);
|
|
122
|
+
return arkApiUrl;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
// Try to discover ark-api service via Kubernetes (requires kubeconfig)
|
|
126
|
+
await this.initKubernetesConfig();
|
|
127
|
+
if (this.kubeConfig) {
|
|
128
|
+
try {
|
|
129
|
+
const namespace = config.kubeNamespace || config.defaultNamespace || 'default';
|
|
130
|
+
const discoveredUrl = await this.kubernetesManager.getArkApiUrl(namespace);
|
|
131
|
+
debug('kubernetes discovery successful in %s: %s', namespace, discoveredUrl);
|
|
132
|
+
return discoveredUrl;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
debug('kubernetes discovery failed: %s', error instanceof Error ? error.message : error);
|
|
136
|
+
// Fall back to default if discovery fails
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const fallbackUrl = config.apiBaseUrl || DEFAULT_ADDRESS_ARK_API;
|
|
140
|
+
debug('falling back to default: %s', fallbackUrl);
|
|
141
|
+
return fallbackUrl;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Check if localhost-gateway is running by testing port 8080
|
|
145
|
+
*/
|
|
146
|
+
async isLocalhostGatewayRunning() {
|
|
147
|
+
try {
|
|
148
|
+
// Try to connect to the localhost gateway port
|
|
149
|
+
const response = await axios.get('http://127.0.0.1:8080', {
|
|
150
|
+
timeout: 2000,
|
|
151
|
+
validateStatus: () => true, // Accept any status code, we just want to know if it's reachable
|
|
152
|
+
});
|
|
153
|
+
debug('localhost-gateway check: available (status %d)', response.status);
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
debug('localhost-gateway check: unavailable (%s)', error instanceof Error ? error.message : error);
|
|
158
|
+
// Gateway not responding - fall back to other discovery methods
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Construct standard localhost-gateway URLs for known ARK services
|
|
164
|
+
*/
|
|
165
|
+
getLocalhostGatewayUrls() {
|
|
166
|
+
const port = 8080;
|
|
167
|
+
// Known services that are typically exposed via localhost-gateway
|
|
168
|
+
const knownServices = {
|
|
169
|
+
'ark-api': `http://ark-api.127.0.0.1.nip.io:${port}`,
|
|
170
|
+
'ark-dashboard': `http://dashboard.127.0.0.1.nip.io:${port}`,
|
|
171
|
+
'ark-api-a2a': `http://ark-api-a2a.127.0.0.1.nip.io:${port}`,
|
|
172
|
+
langfuse: `http://langfuse.telemetry.127.0.0.1.nip.io:${port}`, // Fixed URL to match HTTPRoute
|
|
173
|
+
// Add other services as they become available via gateway
|
|
174
|
+
};
|
|
175
|
+
return knownServices;
|
|
176
|
+
}
|
|
177
|
+
async initKubernetesConfig() {
|
|
178
|
+
if (!this.kubeConfig) {
|
|
179
|
+
try {
|
|
180
|
+
this.kubeConfig = await this.kubernetesManager.initializeConfig();
|
|
181
|
+
debug('kubernetes config loaded: context=%s namespace=%s', this.kubeConfig?.currentContext, this.kubeConfig?.namespace);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
debug('kubernetes config unavailable: %s', error instanceof Error ? error.message : error);
|
|
185
|
+
// Kubernetes config not available - that's okay for some use cases
|
|
186
|
+
this.kubeConfig = null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
async getKubernetesConfig() {
|
|
191
|
+
await this.initKubernetesConfig();
|
|
192
|
+
return this.kubeConfig;
|
|
193
|
+
}
|
|
194
|
+
async testClusterAccess() {
|
|
195
|
+
await this.initKubernetesConfig();
|
|
196
|
+
if (!this.kubeConfig) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return await this.kubernetesManager.testClusterAccess();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Discover service URLs from ark-api service discovery
|
|
203
|
+
*/
|
|
204
|
+
async discoverServicesFromApi() {
|
|
205
|
+
try {
|
|
206
|
+
const apiBaseUrl = await this.getApiBaseUrl();
|
|
207
|
+
const arkClient = new ArkClient(apiBaseUrl);
|
|
208
|
+
const config = await this.loadConfig();
|
|
209
|
+
const namespace = config.kubeNamespace || config.defaultNamespace || 'default';
|
|
210
|
+
debug('service discovery: querying ark-api at %s (namespace: %s)', apiBaseUrl, namespace);
|
|
211
|
+
const services = await arkClient.getArkServices(namespace);
|
|
212
|
+
const serviceUrls = {};
|
|
213
|
+
// Dynamically map all discovered services with HTTP routes
|
|
214
|
+
for (const service of services) {
|
|
215
|
+
if (service.httproutes && service.httproutes.length > 0) {
|
|
216
|
+
const serviceName = service.release_name || service.name;
|
|
217
|
+
const serviceUrl = service.httproutes[0].url; // Use first route URL
|
|
218
|
+
serviceUrls[serviceName] = serviceUrl;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const discoveredServices = Object.entries(serviceUrls).map(([key, url]) => `${key}: ${url}`);
|
|
222
|
+
debug('service discovery: found %d services - %s', discoveredServices.length, discoveredServices.join(', ') || 'none');
|
|
223
|
+
return serviceUrls;
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
debug('service discovery failed: %s', error instanceof Error ? error.message : error);
|
|
227
|
+
// Return empty object if discovery fails - will fall back to config/defaults
|
|
228
|
+
return {};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async getServiceUrls() {
|
|
232
|
+
// Try localhost-gateway detection (works for everyone with standard setup)
|
|
233
|
+
if (await this.isLocalhostGatewayRunning()) {
|
|
234
|
+
const gatewayUrls = this.getLocalhostGatewayUrls();
|
|
235
|
+
debug('localhost-gateway detected, using: %o', gatewayUrls);
|
|
236
|
+
return gatewayUrls;
|
|
237
|
+
}
|
|
238
|
+
// Try to discover services from ark-api (requires kubeconfig)
|
|
239
|
+
const discoveredUrls = await this.discoverServicesFromApi();
|
|
240
|
+
debug('discovered services: %o', discoveredUrls);
|
|
241
|
+
return discoveredUrls;
|
|
242
|
+
}
|
|
243
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
import { render } from 'ink';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
const packageJson = require('../package.json');
|
|
9
|
+
import { createClusterCommand } from './commands/cluster/index.js';
|
|
10
|
+
import { createCompletionCommand } from './commands/completion.js';
|
|
11
|
+
import { createGenerateCommand } from './commands/generate/index.js';
|
|
12
|
+
import { createConfigCommand } from './commands/config.js';
|
|
13
|
+
import { StatusChecker } from './components/statusChecker.js';
|
|
14
|
+
import { ConfigManager } from './config.js';
|
|
15
|
+
import { ArkClient } from './lib/arkClient.js';
|
|
16
|
+
import MainMenu from './ui/MainMenu.js';
|
|
17
|
+
import { StatusFormatter } from './ui/statusFormatter.js';
|
|
18
|
+
function showMainMenu() {
|
|
19
|
+
console.clear();
|
|
20
|
+
render(_jsx(MainMenu, {}));
|
|
21
|
+
}
|
|
22
|
+
async function handleStatusCheck() {
|
|
23
|
+
try {
|
|
24
|
+
const configManager = new ConfigManager();
|
|
25
|
+
const apiBaseUrl = await configManager.getApiBaseUrl();
|
|
26
|
+
const serviceUrls = await configManager.getServiceUrls();
|
|
27
|
+
const arkClient = new ArkClient(apiBaseUrl);
|
|
28
|
+
const statusChecker = new StatusChecker(arkClient);
|
|
29
|
+
const statusData = await statusChecker.checkAll(serviceUrls, apiBaseUrl);
|
|
30
|
+
StatusFormatter.printStatus(statusData);
|
|
31
|
+
process.exit(0); // Exit cleanly after showing status
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.error(chalk.red('Failed to check status:'), error);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function main() {
|
|
39
|
+
const program = new Command();
|
|
40
|
+
program
|
|
41
|
+
.name(packageJson.name)
|
|
42
|
+
.description(packageJson.description)
|
|
43
|
+
.version(packageJson.version);
|
|
44
|
+
program.addCommand(createClusterCommand());
|
|
45
|
+
program.addCommand(createCompletionCommand());
|
|
46
|
+
program.addCommand(createGenerateCommand());
|
|
47
|
+
program.addCommand(createConfigCommand());
|
|
48
|
+
// Add check status command
|
|
49
|
+
const checkCommand = new Command('check');
|
|
50
|
+
checkCommand.description('Check various ARK system components');
|
|
51
|
+
checkCommand
|
|
52
|
+
.command('status')
|
|
53
|
+
.description('Check system status')
|
|
54
|
+
.action(handleStatusCheck);
|
|
55
|
+
program.addCommand(checkCommand);
|
|
56
|
+
// If no args provided, show interactive menu
|
|
57
|
+
if (process.argv.length === 2) {
|
|
58
|
+
console.log();
|
|
59
|
+
showMainMenu();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await program.parseAsync(process.argv);
|
|
63
|
+
}
|
|
64
|
+
main().catch((error) => {
|
|
65
|
+
console.error(chalk.red('Failed to start ARK CLI:'), error);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface ArkService {
|
|
2
|
+
name: string;
|
|
3
|
+
namespace: string;
|
|
4
|
+
release_name: string;
|
|
5
|
+
chart_name: string;
|
|
6
|
+
chart_version: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
routes?: HTTPRouteInfo[];
|
|
9
|
+
httproutes?: HTTPRouteInfo[];
|
|
10
|
+
}
|
|
11
|
+
export interface HTTPRouteInfo {
|
|
12
|
+
name: string;
|
|
13
|
+
namespace: string;
|
|
14
|
+
url: string;
|
|
15
|
+
rules: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ArkServiceListResponse {
|
|
18
|
+
items: ArkService[];
|
|
19
|
+
}
|
|
20
|
+
export declare class ArkClient {
|
|
21
|
+
private client;
|
|
22
|
+
constructor(baseURL: string);
|
|
23
|
+
getBaseURL(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Get ARK services and their discovered URLs from gateway routes
|
|
26
|
+
*/
|
|
27
|
+
getArkServices(namespace?: string): Promise<ArkService[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Test if the API is reachable
|
|
30
|
+
*/
|
|
31
|
+
testConnection(): Promise<boolean>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { DEFAULT_TIMEOUT_MS, DEFAULT_CONNECTION_TEST_TIMEOUT_MS, } from './consts.js';
|
|
3
|
+
export class ArkClient {
|
|
4
|
+
constructor(baseURL) {
|
|
5
|
+
this.client = axios.create({
|
|
6
|
+
baseURL,
|
|
7
|
+
timeout: DEFAULT_TIMEOUT_MS,
|
|
8
|
+
headers: {
|
|
9
|
+
'Content-Type': 'application/json',
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
getBaseURL() {
|
|
14
|
+
return this.client.defaults.baseURL || '';
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get ARK services and their discovered URLs from gateway routes
|
|
18
|
+
*/
|
|
19
|
+
async getArkServices(namespace = 'default') {
|
|
20
|
+
try {
|
|
21
|
+
const response = await this.client.get(`/v1/namespaces/${namespace}/ark-services`);
|
|
22
|
+
return response.data.items;
|
|
23
|
+
}
|
|
24
|
+
catch (_error) {
|
|
25
|
+
// If service discovery fails, return empty array to fall back to defaults
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Test if the API is reachable
|
|
31
|
+
*/
|
|
32
|
+
async testConnection() {
|
|
33
|
+
try {
|
|
34
|
+
await this.client.get('/health', {
|
|
35
|
+
timeout: DEFAULT_CONNECTION_TEST_TIMEOUT_MS,
|
|
36
|
+
});
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ClusterInfo {
|
|
2
|
+
type: 'minikube' | 'kind' | 'k3s' | 'docker-desktop' | 'cloud' | 'unknown';
|
|
3
|
+
ip?: string;
|
|
4
|
+
context?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function detectClusterType(): Promise<ClusterInfo>;
|
|
8
|
+
export declare function getClusterIp(_context?: string): Promise<ClusterInfo>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { executeCommand } from './exec.js';
|
|
2
|
+
export async function detectClusterType() {
|
|
3
|
+
try {
|
|
4
|
+
const { stdout } = await executeCommand('kubectl', [
|
|
5
|
+
'config',
|
|
6
|
+
'current-context',
|
|
7
|
+
]);
|
|
8
|
+
const context = stdout.trim();
|
|
9
|
+
if (context.includes('minikube')) {
|
|
10
|
+
return { type: 'minikube', context };
|
|
11
|
+
}
|
|
12
|
+
else if (context.includes('kind')) {
|
|
13
|
+
return { type: 'kind', context };
|
|
14
|
+
}
|
|
15
|
+
else if (context.includes('k3s')) {
|
|
16
|
+
return { type: 'k3s', context };
|
|
17
|
+
}
|
|
18
|
+
else if (context.includes('docker-desktop')) {
|
|
19
|
+
return { type: 'docker-desktop', context };
|
|
20
|
+
}
|
|
21
|
+
else if (context.includes('gke') ||
|
|
22
|
+
context.includes('eks') ||
|
|
23
|
+
context.includes('aks')) {
|
|
24
|
+
return { type: 'cloud', context };
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return { type: 'unknown', context };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return { type: 'unknown', error: error.message };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export async function getClusterIp(_context) {
|
|
35
|
+
try {
|
|
36
|
+
const clusterInfo = await detectClusterType();
|
|
37
|
+
if (clusterInfo.error) {
|
|
38
|
+
return clusterInfo;
|
|
39
|
+
}
|
|
40
|
+
let ip;
|
|
41
|
+
switch (clusterInfo.type) {
|
|
42
|
+
case 'minikube':
|
|
43
|
+
try {
|
|
44
|
+
const { stdout } = await executeCommand('minikube', ['ip']);
|
|
45
|
+
ip = stdout.trim();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Fallback to kubectl if minikube command fails
|
|
49
|
+
const { stdout } = await executeCommand('kubectl', [
|
|
50
|
+
'get',
|
|
51
|
+
'nodes',
|
|
52
|
+
'-o',
|
|
53
|
+
'jsonpath={.items[0].status.addresses[?(@.type=="InternalIP")].address}',
|
|
54
|
+
]);
|
|
55
|
+
ip = stdout.trim();
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'kind': {
|
|
59
|
+
const { stdout: kindOutput } = await executeCommand('kubectl', [
|
|
60
|
+
'get',
|
|
61
|
+
'nodes',
|
|
62
|
+
'-o',
|
|
63
|
+
'jsonpath={.items[0].status.addresses[?(@.type=="InternalIP")].address}',
|
|
64
|
+
]);
|
|
65
|
+
ip = kindOutput.trim();
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'docker-desktop':
|
|
69
|
+
ip = 'localhost';
|
|
70
|
+
break;
|
|
71
|
+
case 'k3s': {
|
|
72
|
+
const { stdout: k3sOutput } = await executeCommand('kubectl', [
|
|
73
|
+
'get',
|
|
74
|
+
'nodes',
|
|
75
|
+
'-o',
|
|
76
|
+
'jsonpath={.items[0].status.addresses[?(@.type=="InternalIP")].address}',
|
|
77
|
+
]);
|
|
78
|
+
ip = k3sOutput.trim();
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case 'cloud':
|
|
82
|
+
// For cloud clusters, try to get the external IP or load balancer IP
|
|
83
|
+
try {
|
|
84
|
+
const { stdout: lbOutput } = await executeCommand('kubectl', [
|
|
85
|
+
'get',
|
|
86
|
+
'svc',
|
|
87
|
+
'-n',
|
|
88
|
+
'istio-system',
|
|
89
|
+
'istio-ingressgateway',
|
|
90
|
+
'-o',
|
|
91
|
+
'jsonpath={.status.loadBalancer.ingress[0].ip}',
|
|
92
|
+
]);
|
|
93
|
+
ip = lbOutput.trim();
|
|
94
|
+
if (!ip) {
|
|
95
|
+
const { stdout: hostnameOutput } = await executeCommand('kubectl', [
|
|
96
|
+
'get',
|
|
97
|
+
'svc',
|
|
98
|
+
'-n',
|
|
99
|
+
'istio-system',
|
|
100
|
+
'istio-ingressgateway',
|
|
101
|
+
'-o',
|
|
102
|
+
'jsonpath={.status.loadBalancer.ingress[0].hostname}',
|
|
103
|
+
]);
|
|
104
|
+
ip = hostnameOutput.trim();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Fallback to node IP
|
|
109
|
+
const { stdout: nodeOutput } = await executeCommand('kubectl', [
|
|
110
|
+
'get',
|
|
111
|
+
'nodes',
|
|
112
|
+
'-o',
|
|
113
|
+
'jsonpath={.items[0].status.addresses[?(@.type=="ExternalIP")].address}',
|
|
114
|
+
]);
|
|
115
|
+
ip = nodeOutput.trim();
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
default: {
|
|
119
|
+
const { stdout: defaultOutput } = await executeCommand('kubectl', [
|
|
120
|
+
'get',
|
|
121
|
+
'nodes',
|
|
122
|
+
'-o',
|
|
123
|
+
'jsonpath={.items[0].status.addresses[?(@.type=="InternalIP")].address}',
|
|
124
|
+
]);
|
|
125
|
+
ip = defaultOutput.trim();
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { ...clusterInfo, ip };
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return { type: 'unknown', error: error.message };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for ARK CLI
|
|
3
|
+
*/
|
|
4
|
+
export interface ArkConfig {
|
|
5
|
+
defaultProjectType: 'empty' | 'with-samples';
|
|
6
|
+
defaultDestination: string;
|
|
7
|
+
skipGitByDefault: boolean;
|
|
8
|
+
skipModelsbyDefault: boolean;
|
|
9
|
+
preferredEditor: string;
|
|
10
|
+
colorOutput: boolean;
|
|
11
|
+
verboseOutput: boolean;
|
|
12
|
+
defaultModelProvider: 'azure' | 'openai' | 'claude' | 'gemini' | 'custom';
|
|
13
|
+
templateDirectory?: string;
|
|
14
|
+
customTemplates: Record<string, string>;
|
|
15
|
+
parallelOperations: boolean;
|
|
16
|
+
maxConcurrentFiles: number;
|
|
17
|
+
fileWatchingEnabled: boolean;
|
|
18
|
+
telemetryEnabled: boolean;
|
|
19
|
+
errorReporting: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare const DEFAULT_CONFIG: ArkConfig;
|
|
22
|
+
export declare class ConfigManager {
|
|
23
|
+
private configPath;
|
|
24
|
+
private config;
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* Get the path to the configuration file
|
|
28
|
+
*/
|
|
29
|
+
private getConfigPath;
|
|
30
|
+
/**
|
|
31
|
+
* Load configuration from file or create with defaults
|
|
32
|
+
*/
|
|
33
|
+
private loadConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Save configuration to file
|
|
36
|
+
*/
|
|
37
|
+
private saveConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Get the current configuration
|
|
40
|
+
*/
|
|
41
|
+
getConfig(): ArkConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Update configuration
|
|
44
|
+
*/
|
|
45
|
+
updateConfig(updates: Partial<ArkConfig>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Reset configuration to defaults
|
|
48
|
+
*/
|
|
49
|
+
resetConfig(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get a specific configuration value
|
|
52
|
+
*/
|
|
53
|
+
get<K extends keyof ArkConfig>(key: K): ArkConfig[K];
|
|
54
|
+
/**
|
|
55
|
+
* Set a specific configuration value
|
|
56
|
+
*/
|
|
57
|
+
set<K extends keyof ArkConfig>(key: K, value: ArkConfig[K]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Validate configuration values
|
|
60
|
+
*/
|
|
61
|
+
validateConfig(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get environment variable overrides
|
|
64
|
+
*/
|
|
65
|
+
getEnvironmentOverrides(): Partial<ArkConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* Get merged configuration with environment overrides
|
|
68
|
+
*/
|
|
69
|
+
getMergedConfig(): ArkConfig;
|
|
70
|
+
/**
|
|
71
|
+
* Export configuration for backup
|
|
72
|
+
*/
|
|
73
|
+
exportConfig(): string;
|
|
74
|
+
/**
|
|
75
|
+
* Import configuration from backup
|
|
76
|
+
*/
|
|
77
|
+
importConfig(configJson: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Get configuration file path for CLI display
|
|
80
|
+
*/
|
|
81
|
+
getConfigFilePath(): string;
|
|
82
|
+
}
|