galaxy-code 0.1.2 → 0.1.5

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 (74) hide show
  1. package/dist/app.d.ts +1 -1
  2. package/dist/app.js +5 -5
  3. package/dist/cli.js +4 -4
  4. package/dist/connections/claude.d.ts +71 -0
  5. package/dist/connections/claude.js +303 -0
  6. package/dist/connections/gemini.d.ts +40 -0
  7. package/dist/connections/gemini.js +232 -0
  8. package/dist/connections/index.d.ts +11 -0
  9. package/dist/connections/index.js +11 -0
  10. package/dist/connections/ollama.d.ts +37 -0
  11. package/dist/connections/ollama.js +73 -0
  12. package/dist/connections/types.d.ts +22 -0
  13. package/dist/connections/types.js +7 -0
  14. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.d.ts.map +1 -1
  15. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.js +18 -18
  16. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.js.map +1 -1
  17. package/dist/prompts/ba-it-analyzer.d.ts +1 -0
  18. package/dist/prompts/ba-it-analyzer.js +143 -0
  19. package/dist/prompts/index.d.ts +11 -0
  20. package/dist/prompts/index.js +11 -0
  21. package/dist/prompts/orchestrator.d.ts +8 -0
  22. package/dist/prompts/orchestrator.js +88 -0
  23. package/dist/prompts/planning-agent.d.ts +8 -0
  24. package/dist/prompts/planning-agent.js +195 -0
  25. package/dist/prompts/universal-agent.d.ts +7 -0
  26. package/dist/prompts/universal-agent.js +111 -0
  27. package/dist/providers/agent-selector.d.ts +29 -0
  28. package/dist/providers/agent-selector.js +84 -0
  29. package/dist/providers/claude-agent.d.ts +29 -0
  30. package/dist/providers/claude-agent.js +121 -0
  31. package/dist/providers/gemini-agent.d.ts +36 -0
  32. package/dist/providers/gemini-agent.js +168 -0
  33. package/dist/providers/index.d.ts +12 -0
  34. package/dist/providers/index.js +12 -0
  35. package/dist/providers/ollama-agent.d.ts +53 -0
  36. package/dist/providers/ollama-agent.js +276 -0
  37. package/dist/providers/orchestrator.d.ts +16 -0
  38. package/dist/providers/orchestrator.js +76 -0
  39. package/dist/tools/ba-it-analyzer.d.ts +66 -0
  40. package/dist/tools/ba-it-analyzer.js +90 -0
  41. package/dist/tools/code-generate-agent.d.ts +51 -0
  42. package/dist/tools/code-generate-agent.js +159 -0
  43. package/dist/tools/command-runner.d.ts +14 -0
  44. package/dist/tools/command-runner.js +120 -0
  45. package/dist/tools/document-parser.d.ts +11 -0
  46. package/dist/tools/document-parser.js +83 -0
  47. package/dist/tools/file-operations.d.ts +17 -0
  48. package/dist/tools/file-operations.js +127 -0
  49. package/dist/tools/galaxy-ui-integration.d.ts +94 -0
  50. package/dist/tools/galaxy-ui-integration.js +244 -0
  51. package/dist/tools/git-operations.d.ts +11 -0
  52. package/dist/tools/git-operations.js +114 -0
  53. package/dist/tools/index.d.ts +10 -0
  54. package/dist/tools/index.js +10 -0
  55. package/dist/tools/planning-agent.d.ts +29 -0
  56. package/dist/tools/planning-agent.js +134 -0
  57. package/dist/tools/progress-reporter.d.ts +19 -0
  58. package/dist/tools/progress-reporter.js +52 -0
  59. package/dist/tools/registry.d.ts +21 -0
  60. package/dist/tools/registry.js +695 -0
  61. package/dist/tools/tool-event-emitter.d.ts +24 -0
  62. package/dist/tools/tool-event-emitter.js +25 -0
  63. package/dist/tools/types.d.ts +31 -0
  64. package/dist/tools/types.js +1 -0
  65. package/dist/types.d.ts +1 -1
  66. package/dist/utils/config-manager.d.ts +102 -0
  67. package/dist/utils/config-manager.js +326 -0
  68. package/dist/utils/devtools.d.ts +21 -0
  69. package/dist/utils/devtools.js +61 -0
  70. package/dist/utils/message-formatters.d.ts +32 -0
  71. package/dist/utils/message-formatters.js +590 -0
  72. package/dist/utils/progress-tracker.d.ts +59 -0
  73. package/dist/utils/progress-tracker.js +213 -0
  74. package/package.json +3 -2
package/dist/app.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { MergedConfig } from '@workspace/agent-core';
2
+ import { MergedConfig } from './utils/config-manager.js';
3
3
  interface AppProps {
4
4
  config: MergedConfig;
5
5
  }
package/dist/app.js CHANGED
@@ -11,11 +11,11 @@ import { Box, Static, Text, useApp, useInput } from 'ink';
11
11
  import TextInput from 'ink-text-input';
12
12
  import Spinner from 'ink-spinner';
13
13
  import figlet from 'figlet';
14
- import { ClaudeAgent, GeminiAgent, OllamaAgent, } from '@workspace/agent-core/providers';
15
- import { configManager } from '@workspace/agent-core';
16
- import { formatMessage } from '@workspace/agent-core/utils/message-formatters';
17
- import { toolEventEmitter } from '@workspace/agent-core/tools';
18
- const cliVersion = '0.1.2';
14
+ import { ClaudeAgent, GeminiAgent, OllamaAgent } from './providers/index.js';
15
+ import { configManager } from './utils/config-manager.js';
16
+ import { formatMessage } from './utils/message-formatters.js';
17
+ import { toolEventEmitter } from './tools/index.js';
18
+ const cliVersion = '0.1.4';
19
19
  const getTerminalWidth = () => {
20
20
  const width = process.stdout?.columns;
21
21
  return typeof width === 'number' && Number.isFinite(width) ? width : 80;
package/dist/cli.js CHANGED
@@ -11,9 +11,9 @@ import { render } from 'ink';
11
11
  import meow from 'meow';
12
12
  import './env.js';
13
13
  import App from './app.js';
14
- import { configManager } from '@workspace/agent-core';
15
14
  import { checkForUpdate, shouldSkipVersion } from './update-checker.js';
16
15
  import { performUpdate, restartCLI, showUpdateSuccess, showUpdateError, } from './auto-updater.js';
16
+ import { configManager } from './utils/config-manager.js';
17
17
  const cli = meow(`
18
18
  Cách sử dụng
19
19
  $ galaxy [tùy chọn]
@@ -77,9 +77,9 @@ async function handleAutoUpdate() {
77
77
  const config = configManager.getConfig();
78
78
  const autoUpdateConfig = config.autoUpdate;
79
79
  // Check if auto-update is disabled
80
- if (!autoUpdateConfig.enabled
81
- || !autoUpdateConfig.checkOnStartup
82
- || cli.flags.noAutoUpdate) {
80
+ if (!autoUpdateConfig.enabled ||
81
+ !autoUpdateConfig.checkOnStartup ||
82
+ cli.flags.noAutoUpdate) {
83
83
  return false; // Skip update
84
84
  }
85
85
  try {
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @author Bùi Trọng Hiếu
3
+ * @email kevinbui210191@gmail.com
4
+ * @create 2024-10-13
5
+ * @modify 2024-10-13
6
+ * @desc Claude API connection using Anthropic SDK
7
+ */
8
+ import Anthropic from '@anthropic-ai/sdk';
9
+ import type { AgentConfig } from '../utils/config-manager.js';
10
+ import type { MessageCallback } from './types.js';
11
+ export type ClaudeModelId = 'claude-3-5-sonnet-20241022' | 'claude-3-5-haiku-20241022' | 'claude-3-opus-20240229' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4.5-20250929';
12
+ export interface ClaudeMessage {
13
+ role: 'user' | 'assistant';
14
+ content: string;
15
+ }
16
+ export interface ClaudeStreamChunk {
17
+ type: 'content_block_delta' | 'message_delta' | 'message_stop';
18
+ delta?: {
19
+ text?: string;
20
+ type?: string;
21
+ };
22
+ }
23
+ export declare class ClaudeConnection {
24
+ private client;
25
+ private model;
26
+ private conversationHistory;
27
+ private conversationHistoryWithTools;
28
+ private systemPrompt?;
29
+ private toolsRegistry;
30
+ constructor(config?: AgentConfig, systemPrompt?: string);
31
+ /**
32
+ * Send a message and get response
33
+ */
34
+ chat(userMessage: string): Promise<string>;
35
+ /**
36
+ * Stream response (for future implementation)
37
+ */
38
+ chatStream(userMessage: string): AsyncGenerator<string, void, unknown>;
39
+ /**
40
+ * Generate single response without conversation history
41
+ */
42
+ generate(prompt: string, systemPrompt?: string): Promise<string>;
43
+ /**
44
+ * Clear conversation history
45
+ */
46
+ clearHistory(): void;
47
+ /**
48
+ * Get conversation history
49
+ */
50
+ getHistory(): ClaudeMessage[];
51
+ /**
52
+ * Set system prompt
53
+ */
54
+ setSystemPrompt(prompt: string): void;
55
+ /**
56
+ * Get current model
57
+ */
58
+ getModel(): ClaudeModelId;
59
+ /**
60
+ * Change model
61
+ */
62
+ setModel(model: ClaudeModelId): void;
63
+ /**
64
+ * Chat with tools support - handles full tool loop
65
+ */
66
+ chatWithTools(userMessage: string, tools: Anthropic.Tool[], onMessage?: MessageCallback): Promise<string>;
67
+ /**
68
+ * Clear tool conversation history
69
+ */
70
+ clearToolHistory(): void;
71
+ }
@@ -0,0 +1,303 @@
1
+ /**
2
+ * @author Bùi Trọng Hiếu
3
+ * @email kevinbui210191@gmail.com
4
+ * @create 2024-10-13
5
+ * @modify 2024-10-13
6
+ * @desc Claude API connection using Anthropic SDK
7
+ */
8
+ import Anthropic from '@anthropic-ai/sdk';
9
+ import { ToolRegistry } from '../tools/index.js';
10
+ export class ClaudeConnection {
11
+ constructor(config, systemPrompt) {
12
+ Object.defineProperty(this, "client", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "model", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "conversationHistory", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: []
29
+ });
30
+ Object.defineProperty(this, "conversationHistoryWithTools", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: []
35
+ });
36
+ Object.defineProperty(this, "systemPrompt", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "toolsRegistry", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: new ToolRegistry()
47
+ });
48
+ // Only get apiKey from config - no fallback to env
49
+ const apiKey = config?.apiKey;
50
+ // if (!apiKey) {
51
+ // throw new Error(
52
+ // 'Hiện tại bạn chưa thêm apikey cho model claude. Vui lòng thêm để dùng phần mềm'
53
+ // );
54
+ // }
55
+ this.client = new Anthropic({
56
+ apiKey,
57
+ });
58
+ this.model =
59
+ config?.model || 'claude-sonnet-4.5-20250929';
60
+ this.systemPrompt = systemPrompt;
61
+ }
62
+ /**
63
+ * Send a message and get response
64
+ */
65
+ async chat(userMessage) {
66
+ // Add user message to history
67
+ this.conversationHistory.push({
68
+ role: 'user',
69
+ content: userMessage,
70
+ });
71
+ try {
72
+ const response = await this.client.messages.create({
73
+ model: this.model,
74
+ max_tokens: 8192,
75
+ system: this.systemPrompt,
76
+ messages: this.conversationHistory,
77
+ });
78
+ // Extract assistant response
79
+ const assistantMessage = response.content[0]?.type === 'text' ? response.content[0].text : '';
80
+ // Add to history
81
+ this.conversationHistory.push({
82
+ role: 'assistant',
83
+ content: assistantMessage,
84
+ });
85
+ return assistantMessage;
86
+ }
87
+ catch (error) {
88
+ console.error('Claude API Error:', error);
89
+ throw error;
90
+ }
91
+ }
92
+ /**
93
+ * Stream response (for future implementation)
94
+ */
95
+ async *chatStream(userMessage) {
96
+ this.conversationHistory.push({
97
+ role: 'user',
98
+ content: userMessage,
99
+ });
100
+ try {
101
+ const stream = await this.client.messages.create({
102
+ model: this.model,
103
+ max_tokens: 8192,
104
+ system: this.systemPrompt,
105
+ messages: this.conversationHistory,
106
+ stream: true,
107
+ });
108
+ let fullResponse = '';
109
+ for await (const chunk of stream) {
110
+ if (chunk.type === 'content_block_delta' &&
111
+ chunk.delta.type === 'text_delta') {
112
+ const text = chunk.delta.text || '';
113
+ fullResponse += text;
114
+ yield text;
115
+ }
116
+ }
117
+ // Add complete response to history
118
+ this.conversationHistory.push({
119
+ role: 'assistant',
120
+ content: fullResponse,
121
+ });
122
+ }
123
+ catch (error) {
124
+ console.error('Claude Stream Error:', error);
125
+ throw error;
126
+ }
127
+ }
128
+ /**
129
+ * Generate single response without conversation history
130
+ */
131
+ async generate(prompt, systemPrompt) {
132
+ try {
133
+ const response = await this.client.messages.create({
134
+ model: this.model,
135
+ max_tokens: 8192,
136
+ system: systemPrompt || this.systemPrompt,
137
+ messages: [
138
+ {
139
+ role: 'user',
140
+ content: prompt,
141
+ },
142
+ ],
143
+ });
144
+ return response.content[0]?.type === 'text'
145
+ ? response.content[0].text
146
+ : '';
147
+ }
148
+ catch (error) {
149
+ console.error('Claude Generate Error:', error);
150
+ throw error;
151
+ }
152
+ }
153
+ /**
154
+ * Clear conversation history
155
+ */
156
+ clearHistory() {
157
+ this.conversationHistory = [];
158
+ }
159
+ /**
160
+ * Get conversation history
161
+ */
162
+ getHistory() {
163
+ return [...this.conversationHistory];
164
+ }
165
+ /**
166
+ * Set system prompt
167
+ */
168
+ setSystemPrompt(prompt) {
169
+ this.systemPrompt = prompt;
170
+ }
171
+ /**
172
+ * Get current model
173
+ */
174
+ getModel() {
175
+ return this.model;
176
+ }
177
+ /**
178
+ * Change model
179
+ */
180
+ setModel(model) {
181
+ this.model = model;
182
+ }
183
+ /**
184
+ * Chat with tools support - handles full tool loop
185
+ */
186
+ async chatWithTools(userMessage, tools, onMessage) {
187
+ // Add user message to history
188
+ this.conversationHistoryWithTools.push({
189
+ role: 'user',
190
+ content: userMessage,
191
+ });
192
+ let iteration = 0;
193
+ const MAX_ITERATIONS = 100; // Safety limit
194
+ while (iteration < MAX_ITERATIONS) {
195
+ iteration++;
196
+ // Call Claude API
197
+ const response = await this.client.messages.create({
198
+ model: this.model,
199
+ max_tokens: 8192,
200
+ system: this.systemPrompt,
201
+ messages: this.conversationHistoryWithTools,
202
+ tools: tools,
203
+ });
204
+ // Check stop reason
205
+ if (response.stop_reason !== 'tool_use') {
206
+ // No more tools to execute - add final response to history
207
+ this.conversationHistoryWithTools.push({
208
+ role: 'assistant',
209
+ content: response.content,
210
+ });
211
+ // Extract text from response
212
+ const textBlock = response.content.find((block) => block.type === 'text');
213
+ return textBlock?.text || '';
214
+ }
215
+ // Add assistant response with tool_use to history
216
+ this.conversationHistoryWithTools.push({
217
+ role: 'assistant',
218
+ content: response.content,
219
+ });
220
+ // Execute tools and collect results
221
+ const toolResults = [];
222
+ for (const block of response.content) {
223
+ if (block.type === 'tool_use') {
224
+ const toolUseBlock = block;
225
+ const toolName = toolUseBlock.name;
226
+ const toolInput = toolUseBlock.input;
227
+ // Special handling for plan_task and progress_reporter
228
+ if (toolName === 'plan_task' || toolName === 'progress_reporter') {
229
+ try {
230
+ const result = await this.toolsRegistry.executeTool(toolName, toolInput);
231
+ const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
232
+ toolResults.push({
233
+ type: 'tool_result',
234
+ tool_use_id: toolUseBlock.id,
235
+ content: resultStr,
236
+ });
237
+ }
238
+ catch (error) {
239
+ const errorMsg = error instanceof Error ? error.message : String(error);
240
+ toolResults.push({
241
+ type: 'tool_result',
242
+ tool_use_id: toolUseBlock.id,
243
+ content: `Error: ${errorMsg}`,
244
+ is_error: true,
245
+ });
246
+ }
247
+ }
248
+ else {
249
+ // Regular tool handling with notification
250
+ try {
251
+ const result = await this.toolsRegistry.executeTool(toolName, toolInput);
252
+ const resultStr = typeof result === 'string' ? result : JSON.stringify(result);
253
+ // Notify tool execution
254
+ if (onMessage) {
255
+ const success = !resultStr.startsWith('❌');
256
+ onMessage('tool', resultStr, toolName, {
257
+ success,
258
+ output: resultStr,
259
+ });
260
+ }
261
+ toolResults.push({
262
+ type: 'tool_result',
263
+ tool_use_id: toolUseBlock.id,
264
+ content: resultStr,
265
+ });
266
+ }
267
+ catch (error) {
268
+ const errorMsg = error instanceof Error ? error.message : String(error);
269
+ // Notify error
270
+ if (onMessage) {
271
+ onMessage('tool', `❌ Error: ${errorMsg}`, toolName, {
272
+ success: false,
273
+ error: errorMsg,
274
+ });
275
+ }
276
+ toolResults.push({
277
+ type: 'tool_result',
278
+ tool_use_id: toolUseBlock.id,
279
+ content: `Error: ${errorMsg}`,
280
+ is_error: true,
281
+ });
282
+ }
283
+ }
284
+ }
285
+ }
286
+ // Add tool results to history
287
+ this.conversationHistoryWithTools.push({
288
+ role: 'user',
289
+ content: toolResults,
290
+ });
291
+ // Loop continues to call API again with tool results
292
+ }
293
+ // Safety limit reached
294
+ console.warn(`⚠️ Safety limit (${MAX_ITERATIONS}) reached in Claude tool loop.`);
295
+ return 'Maximum iteration limit reached. Please try again.';
296
+ }
297
+ /**
298
+ * Clear tool conversation history
299
+ */
300
+ clearToolHistory() {
301
+ this.conversationHistoryWithTools = [];
302
+ }
303
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @author Bùi Trọng Hiếu
3
+ * @email kevinbui210191@gmail.com
4
+ * @create 2024-10-08
5
+ * @modify 2024-10-13
6
+ * @desc Gemini connection helper using @google/genai with improved function call handling.
7
+ */
8
+ import { FunctionDeclaration, type GenerateContentConfig } from '@google/genai';
9
+ import type { AgentConfig } from '../utils/config-manager.js';
10
+ import type { ToolExecutionInfo } from './types.js';
11
+ export type GeminiGenerateParameters = {
12
+ readonly prompt: string;
13
+ readonly config?: GenerateContentConfig;
14
+ };
15
+ export type GeminiChatParameters = {
16
+ readonly prompt: string;
17
+ readonly tools?: FunctionDeclaration[];
18
+ readonly message: string;
19
+ };
20
+ export type GeminiGenerateResult<T = unknown> = {
21
+ readonly text: string;
22
+ readonly raw: T;
23
+ };
24
+ export declare class GeminiConnection {
25
+ private client;
26
+ private readonly apiKey;
27
+ private chatSession;
28
+ private readonly systemInstruction?;
29
+ private readonly model;
30
+ private toolsRegistry;
31
+ constructor(config?: AgentConfig, systemPrompt?: string);
32
+ initChat(): void;
33
+ generate(parameters: GeminiGenerateParameters): Promise<GeminiGenerateResult>;
34
+ chat(message: string, onMessage?: (author: 'tool' | 'assistant', content: string, toolName?: string, toolInfo?: ToolExecutionInfo) => void): Promise<string>;
35
+ private getToolDeclarations;
36
+ private convertToFunctionDeclaration;
37
+ private convertSchemaToGeminiSchema;
38
+ private convertPropertyToGeminiSchema;
39
+ private mapTypeToGemini;
40
+ }