@agents-at-scale/ark 0.1.35 → 0.1.36

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.
Files changed (167) hide show
  1. package/dist/arkServices.d.ts +42 -0
  2. package/dist/arkServices.js +138 -0
  3. package/dist/arkServices.spec.d.ts +1 -0
  4. package/dist/arkServices.spec.js +24 -0
  5. package/dist/commands/agents/index.d.ts +3 -0
  6. package/dist/commands/agents/index.js +65 -0
  7. package/dist/commands/agents/index.spec.d.ts +1 -0
  8. package/dist/commands/agents/index.spec.js +67 -0
  9. package/dist/commands/chat/index.d.ts +3 -0
  10. package/dist/commands/chat/index.js +29 -0
  11. package/dist/commands/cluster/get.d.ts +2 -0
  12. package/dist/commands/cluster/get.js +39 -0
  13. package/dist/commands/cluster/get.spec.d.ts +1 -0
  14. package/dist/commands/cluster/get.spec.js +92 -0
  15. package/dist/commands/cluster/index.d.ts +2 -1
  16. package/dist/commands/cluster/index.js +3 -5
  17. package/dist/commands/cluster/index.spec.d.ts +1 -0
  18. package/dist/commands/cluster/index.spec.js +24 -0
  19. package/dist/commands/completion/index.d.ts +3 -0
  20. package/dist/commands/completion/index.js +230 -0
  21. package/dist/commands/completion/index.spec.d.ts +1 -0
  22. package/dist/commands/completion/index.spec.js +34 -0
  23. package/dist/commands/config/index.d.ts +3 -0
  24. package/dist/commands/config/index.js +42 -0
  25. package/dist/commands/config/index.spec.d.ts +1 -0
  26. package/dist/commands/config/index.spec.js +78 -0
  27. package/dist/commands/dashboard/index.d.ts +4 -0
  28. package/dist/commands/dashboard/index.js +39 -0
  29. package/dist/commands/docs/index.d.ts +4 -0
  30. package/dist/commands/docs/index.js +18 -0
  31. package/dist/commands/generate/config.js +5 -24
  32. package/dist/commands/generate/generators/mcpserver.d.ts +2 -1
  33. package/dist/commands/generate/generators/mcpserver.js +26 -5
  34. package/dist/commands/generate/generators/project.js +22 -41
  35. package/dist/commands/generate/index.d.ts +2 -1
  36. package/dist/commands/generate/index.js +1 -1
  37. package/dist/commands/install/index.d.ts +8 -0
  38. package/dist/commands/install/index.js +295 -0
  39. package/dist/commands/install/index.spec.d.ts +1 -0
  40. package/dist/commands/install/index.spec.js +143 -0
  41. package/dist/commands/models/create.d.ts +1 -0
  42. package/dist/commands/models/create.js +213 -0
  43. package/dist/commands/models/create.spec.d.ts +1 -0
  44. package/dist/commands/models/create.spec.js +125 -0
  45. package/dist/commands/models/index.d.ts +3 -0
  46. package/dist/commands/models/index.js +75 -0
  47. package/dist/commands/models/index.spec.d.ts +1 -0
  48. package/dist/commands/models/index.spec.js +96 -0
  49. package/dist/commands/query/index.d.ts +3 -0
  50. package/dist/commands/query/index.js +24 -0
  51. package/dist/commands/query/index.spec.d.ts +1 -0
  52. package/dist/commands/query/index.spec.js +53 -0
  53. package/dist/commands/routes/index.d.ts +3 -0
  54. package/dist/commands/routes/index.js +93 -0
  55. package/dist/commands/status/index.d.ts +3 -0
  56. package/dist/commands/status/index.js +281 -0
  57. package/dist/commands/targets/index.d.ts +3 -0
  58. package/dist/commands/targets/index.js +72 -0
  59. package/dist/commands/targets/index.spec.d.ts +1 -0
  60. package/dist/commands/targets/index.spec.js +154 -0
  61. package/dist/commands/teams/index.d.ts +3 -0
  62. package/dist/commands/teams/index.js +64 -0
  63. package/dist/commands/teams/index.spec.d.ts +1 -0
  64. package/dist/commands/teams/index.spec.js +70 -0
  65. package/dist/commands/tools/index.d.ts +3 -0
  66. package/dist/commands/tools/index.js +49 -0
  67. package/dist/commands/tools/index.spec.d.ts +1 -0
  68. package/dist/commands/tools/index.spec.js +70 -0
  69. package/dist/commands/uninstall/index.d.ts +3 -0
  70. package/dist/commands/uninstall/index.js +101 -0
  71. package/dist/commands/uninstall/index.spec.d.ts +1 -0
  72. package/dist/commands/uninstall/index.spec.js +125 -0
  73. package/dist/components/ChatUI.d.ts +16 -0
  74. package/dist/components/ChatUI.js +801 -0
  75. package/dist/components/statusChecker.d.ts +14 -24
  76. package/dist/components/statusChecker.js +295 -129
  77. package/dist/index.d.ts +1 -1
  78. package/dist/index.js +42 -42
  79. package/dist/lib/arkApiClient.d.ts +53 -0
  80. package/dist/lib/arkApiClient.js +102 -0
  81. package/dist/lib/arkApiProxy.d.ts +9 -0
  82. package/dist/lib/arkApiProxy.js +22 -0
  83. package/dist/lib/arkServiceProxy.d.ts +14 -0
  84. package/dist/lib/arkServiceProxy.js +95 -0
  85. package/dist/lib/arkStatus.d.ts +10 -0
  86. package/dist/lib/arkStatus.js +79 -0
  87. package/dist/lib/arkStatus.spec.d.ts +1 -0
  88. package/dist/lib/arkStatus.spec.js +49 -0
  89. package/dist/lib/chatClient.d.ts +33 -0
  90. package/dist/lib/chatClient.js +93 -0
  91. package/dist/lib/cluster.d.ts +2 -1
  92. package/dist/lib/cluster.js +37 -16
  93. package/dist/lib/cluster.spec.d.ts +1 -0
  94. package/dist/lib/cluster.spec.js +338 -0
  95. package/dist/lib/commands.d.ts +16 -0
  96. package/dist/lib/commands.js +29 -0
  97. package/dist/lib/commands.spec.d.ts +1 -0
  98. package/dist/lib/commands.spec.js +146 -0
  99. package/dist/lib/config.d.ts +26 -80
  100. package/dist/lib/config.js +70 -205
  101. package/dist/lib/config.spec.d.ts +1 -0
  102. package/dist/lib/config.spec.js +99 -0
  103. package/dist/lib/errors.js +1 -1
  104. package/dist/lib/errors.spec.d.ts +1 -0
  105. package/dist/lib/errors.spec.js +221 -0
  106. package/dist/lib/executeQuery.d.ts +20 -0
  107. package/dist/lib/executeQuery.js +135 -0
  108. package/dist/lib/executeQuery.spec.d.ts +1 -0
  109. package/dist/lib/executeQuery.spec.js +170 -0
  110. package/dist/lib/nextSteps.d.ts +4 -0
  111. package/dist/lib/nextSteps.js +20 -0
  112. package/dist/lib/nextSteps.spec.d.ts +1 -0
  113. package/dist/lib/nextSteps.spec.js +59 -0
  114. package/dist/lib/output.d.ts +36 -0
  115. package/dist/lib/output.js +89 -0
  116. package/dist/lib/output.spec.d.ts +1 -0
  117. package/dist/lib/output.spec.js +123 -0
  118. package/dist/lib/startup.d.ts +9 -0
  119. package/dist/lib/startup.js +87 -0
  120. package/dist/lib/startup.spec.d.ts +1 -0
  121. package/dist/lib/startup.spec.js +152 -0
  122. package/dist/lib/types.d.ts +87 -3
  123. package/dist/lib/versions.d.ts +23 -0
  124. package/dist/lib/versions.js +51 -0
  125. package/dist/types/types.d.ts +40 -0
  126. package/dist/types/types.js +1 -0
  127. package/dist/ui/AgentSelector.d.ts +8 -0
  128. package/dist/ui/AgentSelector.js +53 -0
  129. package/dist/ui/MainMenu.d.ts +5 -1
  130. package/dist/ui/MainMenu.js +226 -91
  131. package/dist/ui/ModelSelector.d.ts +8 -0
  132. package/dist/ui/ModelSelector.js +53 -0
  133. package/dist/ui/TeamSelector.d.ts +8 -0
  134. package/dist/ui/TeamSelector.js +55 -0
  135. package/dist/ui/ToolSelector.d.ts +8 -0
  136. package/dist/ui/ToolSelector.js +53 -0
  137. package/dist/ui/statusFormatter.d.ts +22 -7
  138. package/dist/ui/statusFormatter.js +39 -39
  139. package/dist/ui/statusFormatter.spec.d.ts +1 -0
  140. package/dist/ui/statusFormatter.spec.js +58 -0
  141. package/package.json +16 -5
  142. package/dist/commands/cluster/get-ip.d.ts +0 -2
  143. package/dist/commands/cluster/get-ip.js +0 -32
  144. package/dist/commands/cluster/get-type.d.ts +0 -2
  145. package/dist/commands/cluster/get-type.js +0 -26
  146. package/dist/commands/completion.d.ts +0 -2
  147. package/dist/commands/completion.js +0 -108
  148. package/dist/commands/config.d.ts +0 -5
  149. package/dist/commands/config.js +0 -327
  150. package/dist/components/DashboardCLI.d.ts +0 -3
  151. package/dist/components/DashboardCLI.js +0 -149
  152. package/dist/config.d.ts +0 -42
  153. package/dist/config.js +0 -243
  154. package/dist/lib/arkClient.d.ts +0 -32
  155. package/dist/lib/arkClient.js +0 -43
  156. package/dist/lib/consts.d.ts +0 -10
  157. package/dist/lib/consts.js +0 -15
  158. package/dist/lib/exec.d.ts +0 -5
  159. package/dist/lib/exec.js +0 -20
  160. package/dist/lib/gatewayManager.d.ts +0 -24
  161. package/dist/lib/gatewayManager.js +0 -85
  162. package/dist/lib/kubernetes.d.ts +0 -28
  163. package/dist/lib/kubernetes.js +0 -122
  164. package/dist/lib/progress.d.ts +0 -128
  165. package/dist/lib/progress.js +0 -273
  166. package/dist/lib/wrappers/git.d.ts +0 -2
  167. package/dist/lib/wrappers/git.js +0 -43
package/dist/index.js CHANGED
@@ -1,67 +1,67 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env NODE_NO_WARNINGS=1 node
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import chalk from 'chalk';
4
3
  import { Command } from 'commander';
5
4
  import { render } from 'ink';
6
5
  import { createRequire } from 'module';
7
6
  const require = createRequire(import.meta.url);
8
7
  const packageJson = require('../package.json');
8
+ import output from './lib/output.js';
9
+ import { startup } from './lib/startup.js';
10
+ import { createAgentsCommand } from './commands/agents/index.js';
11
+ import { createChatCommand } from './commands/chat/index.js';
9
12
  import { createClusterCommand } from './commands/cluster/index.js';
10
- import { createCompletionCommand } from './commands/completion.js';
13
+ import { createCompletionCommand } from './commands/completion/index.js';
14
+ import { createDashboardCommand } from './commands/dashboard/index.js';
15
+ import { createDocsCommand } from './commands/docs/index.js';
11
16
  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';
17
+ import { createInstallCommand } from './commands/install/index.js';
18
+ import { createModelsCommand } from './commands/models/index.js';
19
+ import { createQueryCommand } from './commands/query/index.js';
20
+ import { createUninstallCommand } from './commands/uninstall/index.js';
21
+ import { createStatusCommand } from './commands/status/index.js';
22
+ import { createConfigCommand } from './commands/config/index.js';
23
+ import { createTargetsCommand } from './commands/targets/index.js';
24
+ import { createTeamsCommand } from './commands/teams/index.js';
25
+ import { createToolsCommand } from './commands/tools/index.js';
26
+ import { createRoutesCommand } from './commands/routes/index.js';
16
27
  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
- }
28
+ function showMainMenu(config) {
29
+ const app = render(_jsx(MainMenu, { config: config }));
30
+ globalThis.inkApp = app;
37
31
  }
38
32
  async function main() {
33
+ // Initialize CLI - check requirements and load config
34
+ const config = await startup();
39
35
  const program = new Command();
40
36
  program
41
37
  .name(packageJson.name)
42
38
  .description(packageJson.description)
43
39
  .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);
40
+ program.addCommand(createAgentsCommand(config));
41
+ program.addCommand(createChatCommand(config));
42
+ program.addCommand(createClusterCommand(config));
43
+ program.addCommand(createCompletionCommand(config));
44
+ program.addCommand(createDashboardCommand(config));
45
+ program.addCommand(createDocsCommand(config));
46
+ program.addCommand(createGenerateCommand(config));
47
+ program.addCommand(createInstallCommand(config));
48
+ program.addCommand(createModelsCommand(config));
49
+ program.addCommand(createQueryCommand(config));
50
+ program.addCommand(createUninstallCommand(config));
51
+ program.addCommand(createStatusCommand());
52
+ program.addCommand(createConfigCommand(config));
53
+ program.addCommand(createTargetsCommand(config));
54
+ program.addCommand(createTeamsCommand(config));
55
+ program.addCommand(createToolsCommand(config));
56
+ program.addCommand(createRoutesCommand(config));
56
57
  // If no args provided, show interactive menu
57
58
  if (process.argv.length === 2) {
58
- console.log();
59
- showMainMenu();
59
+ showMainMenu(config);
60
60
  return;
61
61
  }
62
62
  await program.parseAsync(process.argv);
63
63
  }
64
64
  main().catch((error) => {
65
- console.error(chalk.red('Failed to start ARK CLI:'), error);
65
+ output.error('failed to start ark cli: ', error);
66
66
  process.exit(1);
67
67
  });
@@ -0,0 +1,53 @@
1
+ import OpenAI from 'openai';
2
+ export interface QueryTarget {
3
+ id: string;
4
+ name: string;
5
+ type: 'agent' | 'model' | 'tool' | string;
6
+ description?: string;
7
+ }
8
+ export interface Agent {
9
+ name: string;
10
+ namespace: string;
11
+ description?: string;
12
+ model_ref?: string;
13
+ prompt?: string;
14
+ status?: string;
15
+ annotations?: Record<string, string>;
16
+ }
17
+ export interface Model {
18
+ name: string;
19
+ namespace: string;
20
+ type: string;
21
+ model: string;
22
+ status: string;
23
+ annotations?: Record<string, string>;
24
+ }
25
+ export interface Tool {
26
+ name: string;
27
+ namespace: string;
28
+ description?: string;
29
+ labels?: Record<string, string>;
30
+ annotations?: Record<string, string>;
31
+ }
32
+ export interface Team {
33
+ name: string;
34
+ namespace: string;
35
+ description?: string;
36
+ strategy?: string;
37
+ members_count?: number;
38
+ status?: string;
39
+ }
40
+ export declare class ArkApiClient {
41
+ private openai;
42
+ private baseUrl;
43
+ private namespace;
44
+ constructor(arkApiUrl: string, namespace?: string);
45
+ getBaseUrl(): string;
46
+ getQueryTargets(): Promise<QueryTarget[]>;
47
+ getAgents(): Promise<Agent[]>;
48
+ getModels(): Promise<Model[]>;
49
+ getTools(): Promise<Tool[]>;
50
+ getTeams(): Promise<Team[]>;
51
+ createChatCompletion(params: OpenAI.Chat.Completions.ChatCompletionCreateParams): Promise<OpenAI.Chat.Completions.ChatCompletion>;
52
+ createChatCompletionStream(params: OpenAI.Chat.Completions.ChatCompletionCreateParams): AsyncIterable<OpenAI.Chat.Completions.ChatCompletionChunk>;
53
+ }
@@ -0,0 +1,102 @@
1
+ import OpenAI from 'openai';
2
+ export class ArkApiClient {
3
+ constructor(arkApiUrl, namespace = 'default') {
4
+ this.baseUrl = arkApiUrl;
5
+ this.namespace = namespace;
6
+ this.openai = new OpenAI({
7
+ baseURL: `${arkApiUrl}/openai/v1`,
8
+ apiKey: 'dummy', // ark-api doesn't require an API key
9
+ dangerouslyAllowBrowser: false,
10
+ });
11
+ }
12
+ getBaseUrl() {
13
+ return this.baseUrl;
14
+ }
15
+ async getQueryTargets() {
16
+ try {
17
+ const models = await this.openai.models.list();
18
+ const targets = models.data.map((model) => {
19
+ const parts = model.id.split('/');
20
+ const type = parts[0] || 'model';
21
+ const name = parts.slice(1).join('/') || model.id;
22
+ return {
23
+ id: model.id,
24
+ name,
25
+ type,
26
+ description: model.id,
27
+ };
28
+ });
29
+ return targets;
30
+ }
31
+ catch (error) {
32
+ throw new Error(`Failed to get query targets: ${error instanceof Error ? error.message : 'Unknown error'}`);
33
+ }
34
+ }
35
+ async getAgents() {
36
+ try {
37
+ const response = await fetch(`${this.baseUrl}/v1/namespaces/${this.namespace}/agents`);
38
+ if (!response.ok) {
39
+ throw new Error(`HTTP error! status: ${response.status}`);
40
+ }
41
+ const data = (await response.json());
42
+ return data.items || [];
43
+ }
44
+ catch (error) {
45
+ throw new Error(`Failed to get agents: ${error instanceof Error ? error.message : 'Unknown error'}`);
46
+ }
47
+ }
48
+ async getModels() {
49
+ try {
50
+ const response = await fetch(`${this.baseUrl}/v1/namespaces/${this.namespace}/models`);
51
+ if (!response.ok) {
52
+ throw new Error(`HTTP error! status: ${response.status}`);
53
+ }
54
+ const data = (await response.json());
55
+ return data.items || [];
56
+ }
57
+ catch (error) {
58
+ throw new Error(`Failed to get models: ${error instanceof Error ? error.message : 'Unknown error'}`);
59
+ }
60
+ }
61
+ async getTools() {
62
+ try {
63
+ const response = await fetch(`${this.baseUrl}/v1/namespaces/${this.namespace}/tools`);
64
+ if (!response.ok) {
65
+ throw new Error(`HTTP error! status: ${response.status}`);
66
+ }
67
+ const data = (await response.json());
68
+ return data.items || [];
69
+ }
70
+ catch (error) {
71
+ throw new Error(`Failed to get tools: ${error instanceof Error ? error.message : 'Unknown error'}`);
72
+ }
73
+ }
74
+ async getTeams() {
75
+ try {
76
+ const response = await fetch(`${this.baseUrl}/v1/namespaces/${this.namespace}/teams`);
77
+ if (!response.ok) {
78
+ throw new Error(`HTTP error! status: ${response.status}`);
79
+ }
80
+ const data = (await response.json());
81
+ return data.items || [];
82
+ }
83
+ catch (error) {
84
+ throw new Error(`Failed to get teams: ${error instanceof Error ? error.message : 'Unknown error'}`);
85
+ }
86
+ }
87
+ async createChatCompletion(params) {
88
+ return (await this.openai.chat.completions.create({
89
+ ...params,
90
+ stream: false,
91
+ }));
92
+ }
93
+ async *createChatCompletionStream(params) {
94
+ const stream = await this.openai.chat.completions.create({
95
+ ...params,
96
+ stream: true,
97
+ });
98
+ for await (const chunk of stream) {
99
+ yield chunk;
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,9 @@
1
+ import { ArkApiClient } from './arkApiClient.js';
2
+ export declare class ArkApiProxy {
3
+ private serviceProxy;
4
+ constructor(localPort?: number);
5
+ start(): Promise<ArkApiClient>;
6
+ stop(): void;
7
+ isRunning(): boolean;
8
+ getLocalUrl(): string;
9
+ }
@@ -0,0 +1,22 @@
1
+ import { ArkApiClient } from './arkApiClient.js';
2
+ import { ArkServiceProxy } from './arkServiceProxy.js';
3
+ import { arkServices } from '../arkServices.js';
4
+ export class ArkApiProxy {
5
+ constructor(localPort) {
6
+ const arkApiService = arkServices['ark-api'];
7
+ this.serviceProxy = new ArkServiceProxy(arkApiService, localPort);
8
+ }
9
+ async start() {
10
+ const arkApiUrl = await this.serviceProxy.start();
11
+ return new ArkApiClient(arkApiUrl);
12
+ }
13
+ stop() {
14
+ this.serviceProxy.stop();
15
+ }
16
+ isRunning() {
17
+ return this.serviceProxy.isRunning();
18
+ }
19
+ getLocalUrl() {
20
+ return this.serviceProxy.getLocalUrl();
21
+ }
22
+ }
@@ -0,0 +1,14 @@
1
+ import { ArkService } from '../arkServices.js';
2
+ export declare class ArkServiceProxy {
3
+ private kubectlProcess?;
4
+ private localPort;
5
+ private isReady;
6
+ private service;
7
+ constructor(service: ArkService, localPort?: number);
8
+ private getRandomPort;
9
+ start(): Promise<string>;
10
+ stop(): void;
11
+ isRunning(): boolean;
12
+ getLocalUrl(): string;
13
+ getService(): ArkService;
14
+ }
@@ -0,0 +1,95 @@
1
+ import { spawn } from 'child_process';
2
+ export class ArkServiceProxy {
3
+ constructor(service, localPort) {
4
+ this.isReady = false;
5
+ this.service = service;
6
+ this.localPort =
7
+ localPort || service.k8sPortForwardLocalPort || this.getRandomPort();
8
+ }
9
+ getRandomPort() {
10
+ return Math.floor(Math.random() * (65535 - 1024) + 1024);
11
+ }
12
+ async start() {
13
+ if (!this.service.k8sServiceName || !this.service.k8sServicePort) {
14
+ throw new Error(`${this.service.name} service configuration missing k8sServiceName or k8sServicePort`);
15
+ }
16
+ return new Promise((resolve, reject) => {
17
+ const args = [
18
+ 'port-forward',
19
+ `service/${this.service.k8sServiceName}`,
20
+ `${this.localPort}:${this.service.k8sServicePort}`,
21
+ ];
22
+ // Add namespace flag only if namespace is defined
23
+ if (this.service.namespace) {
24
+ args.push('--namespace', this.service.namespace);
25
+ }
26
+ this.kubectlProcess = spawn('kubectl', args, {
27
+ stdio: ['ignore', 'pipe', 'pipe'],
28
+ });
29
+ let setupComplete = false;
30
+ const setupTimeout = setTimeout(() => {
31
+ if (!setupComplete) {
32
+ this.stop();
33
+ reject(new Error(`${this.service.name} port forward setup timeout`));
34
+ }
35
+ }, 10000);
36
+ this.kubectlProcess.stdout?.on('data', (data) => {
37
+ const output = data.toString();
38
+ if (output.includes('Forwarding from') && !setupComplete) {
39
+ setupComplete = true;
40
+ clearTimeout(setupTimeout);
41
+ this.isReady = true;
42
+ const localUrl = `http://localhost:${this.localPort}`;
43
+ resolve(localUrl);
44
+ }
45
+ });
46
+ this.kubectlProcess.stderr?.on('data', (data) => {
47
+ const errorOutput = data.toString();
48
+ if (!setupComplete) {
49
+ setupComplete = true;
50
+ clearTimeout(setupTimeout);
51
+ this.stop();
52
+ reject(new Error(`${this.service.name} port forward failed: ${errorOutput.trim()}`));
53
+ }
54
+ });
55
+ this.kubectlProcess.on('error', (error) => {
56
+ if (!setupComplete) {
57
+ setupComplete = true;
58
+ clearTimeout(setupTimeout);
59
+ reject(new Error(`Failed to start ${this.service.name} port forward: ${error.message}`));
60
+ }
61
+ });
62
+ this.kubectlProcess.on('exit', (code) => {
63
+ this.isReady = false;
64
+ if (!setupComplete && code !== 0) {
65
+ setupComplete = true;
66
+ clearTimeout(setupTimeout);
67
+ reject(new Error(`${this.service.name} port forward exited with code ${code}`));
68
+ }
69
+ });
70
+ });
71
+ }
72
+ stop() {
73
+ if (this.kubectlProcess) {
74
+ // Use SIGTERM for graceful shutdown
75
+ this.kubectlProcess.kill('SIGTERM');
76
+ // Give it a second to clean up, then force kill if needed
77
+ setTimeout(() => {
78
+ if (this.kubectlProcess && !this.kubectlProcess.killed) {
79
+ this.kubectlProcess.kill('SIGKILL');
80
+ }
81
+ }, 1000);
82
+ this.kubectlProcess = undefined;
83
+ }
84
+ this.isReady = false;
85
+ }
86
+ isRunning() {
87
+ return this.isReady && this.kubectlProcess !== undefined;
88
+ }
89
+ getLocalUrl() {
90
+ return `http://localhost:${this.localPort}`;
91
+ }
92
+ getService() {
93
+ return this.service;
94
+ }
95
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Get current installed ARK version
3
+ * @returns version string if found, undefined otherwise
4
+ */
5
+ export declare function getArkVersion(): Promise<string | undefined>;
6
+ /**
7
+ * Check if ARK is ready by verifying the ark-controller is running
8
+ * @returns true if ark-controller deployment exists and has ready replicas
9
+ */
10
+ export declare function isArkReady(): Promise<boolean>;
@@ -0,0 +1,79 @@
1
+ import { execa } from 'execa';
2
+ import { arkServices } from '../arkServices.js';
3
+ /**
4
+ * Get current installed ARK version
5
+ * @returns version string if found, undefined otherwise
6
+ */
7
+ export async function getArkVersion() {
8
+ try {
9
+ const controller = arkServices['ark-controller'];
10
+ const { stdout } = await execa('helm', ['list', '-n', controller.namespace, '-o', 'json'], { stdio: 'pipe' });
11
+ const releases = JSON.parse(stdout);
12
+ const arkController = releases.find((r) => r.name === controller.helmReleaseName);
13
+ return arkController?.app_version;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ /**
20
+ * Check if ARK is ready by verifying the ark-controller is running
21
+ * @returns true if ark-controller deployment exists and has ready replicas
22
+ */
23
+ export async function isArkReady() {
24
+ try {
25
+ // Check if ark-controller deployment exists and get its status
26
+ const result = await execa('kubectl', ['get', 'deployment', 'ark-controller', '-n', 'ark-system', '-o', 'json'], { stdio: 'pipe' });
27
+ const deployment = JSON.parse(result.stdout);
28
+ const readyReplicas = deployment.status?.readyReplicas || 0;
29
+ const replicas = deployment.spec?.replicas || 0;
30
+ // If main deployment has 0 replicas, check devspace deployment
31
+ if (replicas === 0) {
32
+ try {
33
+ const devResult = await execa('kubectl', [
34
+ 'get',
35
+ 'deployment',
36
+ 'ark-controller-devspace',
37
+ '-n',
38
+ 'ark-system',
39
+ '-o',
40
+ 'json',
41
+ ], { stdio: 'pipe' });
42
+ const devDeployment = JSON.parse(devResult.stdout);
43
+ const devReadyReplicas = devDeployment.status?.readyReplicas || 0;
44
+ const devReplicas = devDeployment.spec?.replicas || 0;
45
+ // ARK is ready if devspace deployment has ready replicas
46
+ return devReadyReplicas > 0 && devReadyReplicas === devReplicas;
47
+ }
48
+ catch {
49
+ // Devspace deployment doesn't exist
50
+ return false;
51
+ }
52
+ }
53
+ // ARK is ready if deployment exists and has at least one ready replica
54
+ return readyReplicas > 0 && readyReplicas === replicas;
55
+ }
56
+ catch {
57
+ // Main deployment doesn't exist, try devspace deployment
58
+ try {
59
+ const devResult = await execa('kubectl', [
60
+ 'get',
61
+ 'deployment',
62
+ 'ark-controller-devspace',
63
+ '-n',
64
+ 'ark-system',
65
+ '-o',
66
+ 'json',
67
+ ], { stdio: 'pipe' });
68
+ const devDeployment = JSON.parse(devResult.stdout);
69
+ const devReadyReplicas = devDeployment.status?.readyReplicas || 0;
70
+ const devReplicas = devDeployment.spec?.replicas || 0;
71
+ // ARK is ready if devspace deployment has ready replicas
72
+ return devReadyReplicas > 0 && devReadyReplicas === devReplicas;
73
+ }
74
+ catch {
75
+ // Neither deployment exists or kubectl failed
76
+ return false;
77
+ }
78
+ }
79
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ import { describe, it, expect, jest, beforeEach } from '@jest/globals';
2
+ // Mock execa using unstable_mockModule
3
+ jest.unstable_mockModule('execa', () => ({
4
+ execa: jest.fn(),
5
+ }));
6
+ // Dynamic imports after mock
7
+ const { execa } = await import('execa');
8
+ const { isArkReady } = await import('./arkStatus.js');
9
+ describe('arkStatus with __mocks__', () => {
10
+ describe('isArkReady', () => {
11
+ beforeEach(() => {
12
+ jest.clearAllMocks();
13
+ });
14
+ it('should return true when ark-controller is deployed and ready', async () => {
15
+ // Mock successful kubectl response with ready deployment
16
+ const mockDeployment = {
17
+ metadata: { name: 'ark-controller' },
18
+ spec: { replicas: 3 },
19
+ status: {
20
+ readyReplicas: 3,
21
+ availableReplicas: 3,
22
+ },
23
+ };
24
+ execa.mockResolvedValue({
25
+ stdout: JSON.stringify(mockDeployment),
26
+ stderr: '',
27
+ exitCode: 0,
28
+ failed: false,
29
+ });
30
+ const result = await isArkReady();
31
+ expect(result).toBe(true);
32
+ expect(execa).toHaveBeenCalledWith('kubectl', [
33
+ 'get',
34
+ 'deployment',
35
+ 'ark-controller',
36
+ '-n',
37
+ 'ark-system',
38
+ '-o',
39
+ 'json',
40
+ ], { stdio: 'pipe' });
41
+ });
42
+ it('should return false when kubectl fails', async () => {
43
+ // Mock kubectl failure
44
+ execa.mockRejectedValue(new Error('kubectl not found'));
45
+ const result = await isArkReady();
46
+ expect(result).toBe(false);
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,33 @@
1
+ import { ArkApiClient, QueryTarget } from './arkApiClient.js';
2
+ export { QueryTarget };
3
+ export interface ChatConfig {
4
+ streamingEnabled: boolean;
5
+ currentTarget?: QueryTarget;
6
+ }
7
+ export interface ToolCall {
8
+ id: string;
9
+ type: 'function';
10
+ function: {
11
+ name: string;
12
+ arguments: string;
13
+ };
14
+ }
15
+ export interface ArkMetadata {
16
+ agent?: string;
17
+ team?: string;
18
+ model?: string;
19
+ query?: string;
20
+ target?: string;
21
+ }
22
+ export declare class ChatClient {
23
+ private arkApiClient;
24
+ constructor(arkApiClient: ArkApiClient);
25
+ getQueryTargets(): Promise<QueryTarget[]>;
26
+ /**
27
+ * Send a chat completion request
28
+ */
29
+ sendMessage(targetId: string, messages: Array<{
30
+ role: 'user' | 'assistant' | 'system';
31
+ content: string;
32
+ }>, config: ChatConfig, onChunk?: (chunk: string, toolCalls?: ToolCall[], arkMetadata?: ArkMetadata) => void, signal?: AbortSignal): Promise<string>;
33
+ }