galaxy-code 0.1.5 → 0.1.7

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 (222) hide show
  1. package/README.md +149 -600
  2. package/dist/cli.bundle.js +588 -0
  3. package/package.json +14 -12
  4. package/dist/app.d.ts +0 -7
  5. package/dist/app.js +0 -597
  6. package/dist/auto-updater.d.ts +0 -21
  7. package/dist/auto-updater.js +0 -144
  8. package/dist/cli.d.ts +0 -2
  9. package/dist/cli.js +0 -159
  10. package/dist/connections/claude.d.ts +0 -71
  11. package/dist/connections/claude.js +0 -303
  12. package/dist/connections/gemini.d.ts +0 -40
  13. package/dist/connections/gemini.js +0 -232
  14. package/dist/connections/index.d.ts +0 -11
  15. package/dist/connections/index.js +0 -11
  16. package/dist/connections/ollama.d.ts +0 -37
  17. package/dist/connections/ollama.js +0 -73
  18. package/dist/connections/types.d.ts +0 -22
  19. package/dist/connections/types.js +0 -7
  20. package/dist/env.d.ts +0 -1
  21. package/dist/env.js +0 -29
  22. package/dist/node_modules/@workspace/agent-core/connections/claude.d.ts +0 -72
  23. package/dist/node_modules/@workspace/agent-core/connections/claude.d.ts.map +0 -1
  24. package/dist/node_modules/@workspace/agent-core/connections/claude.js +0 -270
  25. package/dist/node_modules/@workspace/agent-core/connections/claude.js.map +0 -1
  26. package/dist/node_modules/@workspace/agent-core/connections/gemini.d.ts +0 -41
  27. package/dist/node_modules/@workspace/agent-core/connections/gemini.d.ts.map +0 -1
  28. package/dist/node_modules/@workspace/agent-core/connections/gemini.js +0 -203
  29. package/dist/node_modules/@workspace/agent-core/connections/gemini.js.map +0 -1
  30. package/dist/node_modules/@workspace/agent-core/connections/index.d.ts +0 -12
  31. package/dist/node_modules/@workspace/agent-core/connections/index.d.ts.map +0 -1
  32. package/dist/node_modules/@workspace/agent-core/connections/index.js +0 -12
  33. package/dist/node_modules/@workspace/agent-core/connections/index.js.map +0 -1
  34. package/dist/node_modules/@workspace/agent-core/connections/ollama.d.ts +0 -38
  35. package/dist/node_modules/@workspace/agent-core/connections/ollama.d.ts.map +0 -1
  36. package/dist/node_modules/@workspace/agent-core/connections/ollama.js +0 -64
  37. package/dist/node_modules/@workspace/agent-core/connections/ollama.js.map +0 -1
  38. package/dist/node_modules/@workspace/agent-core/connections/types.d.ts +0 -23
  39. package/dist/node_modules/@workspace/agent-core/connections/types.d.ts.map +0 -1
  40. package/dist/node_modules/@workspace/agent-core/connections/types.js +0 -8
  41. package/dist/node_modules/@workspace/agent-core/connections/types.js.map +0 -1
  42. package/dist/node_modules/@workspace/agent-core/index.d.ts +0 -13
  43. package/dist/node_modules/@workspace/agent-core/index.d.ts.map +0 -1
  44. package/dist/node_modules/@workspace/agent-core/index.js +0 -22
  45. package/dist/node_modules/@workspace/agent-core/index.js.map +0 -1
  46. package/dist/node_modules/@workspace/agent-core/package.json +0 -53
  47. package/dist/node_modules/@workspace/agent-core/prompts/ba-it-analyzer.d.ts +0 -2
  48. package/dist/node_modules/@workspace/agent-core/prompts/ba-it-analyzer.d.ts.map +0 -1
  49. package/dist/node_modules/@workspace/agent-core/prompts/ba-it-analyzer.js +0 -144
  50. package/dist/node_modules/@workspace/agent-core/prompts/ba-it-analyzer.js.map +0 -1
  51. package/dist/node_modules/@workspace/agent-core/prompts/index.d.ts +0 -12
  52. package/dist/node_modules/@workspace/agent-core/prompts/index.d.ts.map +0 -1
  53. package/dist/node_modules/@workspace/agent-core/prompts/index.js +0 -12
  54. package/dist/node_modules/@workspace/agent-core/prompts/index.js.map +0 -1
  55. package/dist/node_modules/@workspace/agent-core/prompts/orchestrator.d.ts +0 -9
  56. package/dist/node_modules/@workspace/agent-core/prompts/orchestrator.d.ts.map +0 -1
  57. package/dist/node_modules/@workspace/agent-core/prompts/orchestrator.js +0 -89
  58. package/dist/node_modules/@workspace/agent-core/prompts/orchestrator.js.map +0 -1
  59. package/dist/node_modules/@workspace/agent-core/prompts/planning-agent.d.ts +0 -9
  60. package/dist/node_modules/@workspace/agent-core/prompts/planning-agent.d.ts.map +0 -1
  61. package/dist/node_modules/@workspace/agent-core/prompts/planning-agent.js +0 -196
  62. package/dist/node_modules/@workspace/agent-core/prompts/planning-agent.js.map +0 -1
  63. package/dist/node_modules/@workspace/agent-core/prompts/universal-agent.d.ts +0 -8
  64. package/dist/node_modules/@workspace/agent-core/prompts/universal-agent.d.ts.map +0 -1
  65. package/dist/node_modules/@workspace/agent-core/prompts/universal-agent.js +0 -112
  66. package/dist/node_modules/@workspace/agent-core/prompts/universal-agent.js.map +0 -1
  67. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.d.ts +0 -30
  68. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.d.ts.map +0 -1
  69. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.js +0 -76
  70. package/dist/node_modules/@workspace/agent-core/providers/agent-selector.js.map +0 -1
  71. package/dist/node_modules/@workspace/agent-core/providers/claude-agent.d.ts +0 -30
  72. package/dist/node_modules/@workspace/agent-core/providers/claude-agent.d.ts.map +0 -1
  73. package/dist/node_modules/@workspace/agent-core/providers/claude-agent.js +0 -107
  74. package/dist/node_modules/@workspace/agent-core/providers/claude-agent.js.map +0 -1
  75. package/dist/node_modules/@workspace/agent-core/providers/gemini-agent.d.ts +0 -37
  76. package/dist/node_modules/@workspace/agent-core/providers/gemini-agent.d.ts.map +0 -1
  77. package/dist/node_modules/@workspace/agent-core/providers/gemini-agent.js +0 -144
  78. package/dist/node_modules/@workspace/agent-core/providers/gemini-agent.js.map +0 -1
  79. package/dist/node_modules/@workspace/agent-core/providers/index.d.ts +0 -13
  80. package/dist/node_modules/@workspace/agent-core/providers/index.d.ts.map +0 -1
  81. package/dist/node_modules/@workspace/agent-core/providers/index.js +0 -13
  82. package/dist/node_modules/@workspace/agent-core/providers/index.js.map +0 -1
  83. package/dist/node_modules/@workspace/agent-core/providers/ollama-agent.d.ts +0 -54
  84. package/dist/node_modules/@workspace/agent-core/providers/ollama-agent.d.ts.map +0 -1
  85. package/dist/node_modules/@workspace/agent-core/providers/ollama-agent.js +0 -247
  86. package/dist/node_modules/@workspace/agent-core/providers/ollama-agent.js.map +0 -1
  87. package/dist/node_modules/@workspace/agent-core/providers/orchestrator.d.ts +0 -17
  88. package/dist/node_modules/@workspace/agent-core/providers/orchestrator.d.ts.map +0 -1
  89. package/dist/node_modules/@workspace/agent-core/providers/orchestrator.js +0 -62
  90. package/dist/node_modules/@workspace/agent-core/providers/orchestrator.js.map +0 -1
  91. package/dist/node_modules/@workspace/agent-core/tools/ba-it-analyzer.d.ts +0 -67
  92. package/dist/node_modules/@workspace/agent-core/tools/ba-it-analyzer.d.ts.map +0 -1
  93. package/dist/node_modules/@workspace/agent-core/tools/ba-it-analyzer.js +0 -81
  94. package/dist/node_modules/@workspace/agent-core/tools/ba-it-analyzer.js.map +0 -1
  95. package/dist/node_modules/@workspace/agent-core/tools/code-generate-agent.d.ts +0 -52
  96. package/dist/node_modules/@workspace/agent-core/tools/code-generate-agent.d.ts.map +0 -1
  97. package/dist/node_modules/@workspace/agent-core/tools/code-generate-agent.js +0 -150
  98. package/dist/node_modules/@workspace/agent-core/tools/code-generate-agent.js.map +0 -1
  99. package/dist/node_modules/@workspace/agent-core/tools/command-runner.d.ts +0 -15
  100. package/dist/node_modules/@workspace/agent-core/tools/command-runner.d.ts.map +0 -1
  101. package/dist/node_modules/@workspace/agent-core/tools/command-runner.js +0 -121
  102. package/dist/node_modules/@workspace/agent-core/tools/command-runner.js.map +0 -1
  103. package/dist/node_modules/@workspace/agent-core/tools/document-parser.d.ts +0 -12
  104. package/dist/node_modules/@workspace/agent-core/tools/document-parser.d.ts.map +0 -1
  105. package/dist/node_modules/@workspace/agent-core/tools/document-parser.js +0 -84
  106. package/dist/node_modules/@workspace/agent-core/tools/document-parser.js.map +0 -1
  107. package/dist/node_modules/@workspace/agent-core/tools/file-operations.d.ts +0 -18
  108. package/dist/node_modules/@workspace/agent-core/tools/file-operations.d.ts.map +0 -1
  109. package/dist/node_modules/@workspace/agent-core/tools/file-operations.js +0 -126
  110. package/dist/node_modules/@workspace/agent-core/tools/file-operations.js.map +0 -1
  111. package/dist/node_modules/@workspace/agent-core/tools/galaxy-ui-integration.d.ts +0 -95
  112. package/dist/node_modules/@workspace/agent-core/tools/galaxy-ui-integration.d.ts.map +0 -1
  113. package/dist/node_modules/@workspace/agent-core/tools/galaxy-ui-integration.js +0 -245
  114. package/dist/node_modules/@workspace/agent-core/tools/galaxy-ui-integration.js.map +0 -1
  115. package/dist/node_modules/@workspace/agent-core/tools/git-operations.d.ts +0 -12
  116. package/dist/node_modules/@workspace/agent-core/tools/git-operations.d.ts.map +0 -1
  117. package/dist/node_modules/@workspace/agent-core/tools/git-operations.js +0 -115
  118. package/dist/node_modules/@workspace/agent-core/tools/git-operations.js.map +0 -1
  119. package/dist/node_modules/@workspace/agent-core/tools/index.d.ts +0 -11
  120. package/dist/node_modules/@workspace/agent-core/tools/index.d.ts.map +0 -1
  121. package/dist/node_modules/@workspace/agent-core/tools/index.js +0 -11
  122. package/dist/node_modules/@workspace/agent-core/tools/index.js.map +0 -1
  123. package/dist/node_modules/@workspace/agent-core/tools/planning-agent.d.ts +0 -30
  124. package/dist/node_modules/@workspace/agent-core/tools/planning-agent.d.ts.map +0 -1
  125. package/dist/node_modules/@workspace/agent-core/tools/planning-agent.js +0 -125
  126. package/dist/node_modules/@workspace/agent-core/tools/planning-agent.js.map +0 -1
  127. package/dist/node_modules/@workspace/agent-core/tools/progress-reporter.d.ts +0 -20
  128. package/dist/node_modules/@workspace/agent-core/tools/progress-reporter.d.ts.map +0 -1
  129. package/dist/node_modules/@workspace/agent-core/tools/progress-reporter.js +0 -46
  130. package/dist/node_modules/@workspace/agent-core/tools/progress-reporter.js.map +0 -1
  131. package/dist/node_modules/@workspace/agent-core/tools/registry.d.ts +0 -22
  132. package/dist/node_modules/@workspace/agent-core/tools/registry.d.ts.map +0 -1
  133. package/dist/node_modules/@workspace/agent-core/tools/registry.js +0 -651
  134. package/dist/node_modules/@workspace/agent-core/tools/registry.js.map +0 -1
  135. package/dist/node_modules/@workspace/agent-core/tools/tool-event-emitter.d.ts +0 -25
  136. package/dist/node_modules/@workspace/agent-core/tools/tool-event-emitter.d.ts.map +0 -1
  137. package/dist/node_modules/@workspace/agent-core/tools/tool-event-emitter.js +0 -26
  138. package/dist/node_modules/@workspace/agent-core/tools/tool-event-emitter.js.map +0 -1
  139. package/dist/node_modules/@workspace/agent-core/tools/types.d.ts +0 -32
  140. package/dist/node_modules/@workspace/agent-core/tools/types.d.ts.map +0 -1
  141. package/dist/node_modules/@workspace/agent-core/tools/types.js +0 -2
  142. package/dist/node_modules/@workspace/agent-core/tools/types.js.map +0 -1
  143. package/dist/node_modules/@workspace/agent-core/types.d.ts +0 -40
  144. package/dist/node_modules/@workspace/agent-core/types.d.ts.map +0 -1
  145. package/dist/node_modules/@workspace/agent-core/types.js +0 -9
  146. package/dist/node_modules/@workspace/agent-core/types.js.map +0 -1
  147. package/dist/node_modules/@workspace/agent-core/utils/config-manager.d.ts +0 -103
  148. package/dist/node_modules/@workspace/agent-core/utils/config-manager.d.ts.map +0 -1
  149. package/dist/node_modules/@workspace/agent-core/utils/config-manager.js +0 -307
  150. package/dist/node_modules/@workspace/agent-core/utils/config-manager.js.map +0 -1
  151. package/dist/node_modules/@workspace/agent-core/utils/devtools.d.ts +0 -22
  152. package/dist/node_modules/@workspace/agent-core/utils/devtools.d.ts.map +0 -1
  153. package/dist/node_modules/@workspace/agent-core/utils/devtools.js +0 -62
  154. package/dist/node_modules/@workspace/agent-core/utils/devtools.js.map +0 -1
  155. package/dist/node_modules/@workspace/agent-core/utils/message-formatters.d.ts +0 -33
  156. package/dist/node_modules/@workspace/agent-core/utils/message-formatters.d.ts.map +0 -1
  157. package/dist/node_modules/@workspace/agent-core/utils/message-formatters.js +0 -591
  158. package/dist/node_modules/@workspace/agent-core/utils/message-formatters.js.map +0 -1
  159. package/dist/node_modules/@workspace/agent-core/utils/progress-tracker.d.ts +0 -60
  160. package/dist/node_modules/@workspace/agent-core/utils/progress-tracker.d.ts.map +0 -1
  161. package/dist/node_modules/@workspace/agent-core/utils/progress-tracker.js +0 -204
  162. package/dist/node_modules/@workspace/agent-core/utils/progress-tracker.js.map +0 -1
  163. package/dist/prompts/ba-it-analyzer.d.ts +0 -1
  164. package/dist/prompts/ba-it-analyzer.js +0 -143
  165. package/dist/prompts/index.d.ts +0 -11
  166. package/dist/prompts/index.js +0 -11
  167. package/dist/prompts/orchestrator.d.ts +0 -8
  168. package/dist/prompts/orchestrator.js +0 -88
  169. package/dist/prompts/planning-agent.d.ts +0 -8
  170. package/dist/prompts/planning-agent.js +0 -195
  171. package/dist/prompts/universal-agent.d.ts +0 -7
  172. package/dist/prompts/universal-agent.js +0 -111
  173. package/dist/providers/agent-selector.d.ts +0 -29
  174. package/dist/providers/agent-selector.js +0 -84
  175. package/dist/providers/claude-agent.d.ts +0 -29
  176. package/dist/providers/claude-agent.js +0 -121
  177. package/dist/providers/gemini-agent.d.ts +0 -36
  178. package/dist/providers/gemini-agent.js +0 -168
  179. package/dist/providers/index.d.ts +0 -12
  180. package/dist/providers/index.js +0 -12
  181. package/dist/providers/ollama-agent.d.ts +0 -53
  182. package/dist/providers/ollama-agent.js +0 -276
  183. package/dist/providers/orchestrator.d.ts +0 -16
  184. package/dist/providers/orchestrator.js +0 -76
  185. package/dist/tools/ba-it-analyzer.d.ts +0 -66
  186. package/dist/tools/ba-it-analyzer.js +0 -90
  187. package/dist/tools/code-generate-agent.d.ts +0 -51
  188. package/dist/tools/code-generate-agent.js +0 -159
  189. package/dist/tools/command-runner.d.ts +0 -14
  190. package/dist/tools/command-runner.js +0 -120
  191. package/dist/tools/document-parser.d.ts +0 -11
  192. package/dist/tools/document-parser.js +0 -83
  193. package/dist/tools/file-operations.d.ts +0 -17
  194. package/dist/tools/file-operations.js +0 -127
  195. package/dist/tools/galaxy-ui-integration.d.ts +0 -94
  196. package/dist/tools/galaxy-ui-integration.js +0 -244
  197. package/dist/tools/git-operations.d.ts +0 -11
  198. package/dist/tools/git-operations.js +0 -114
  199. package/dist/tools/index.d.ts +0 -10
  200. package/dist/tools/index.js +0 -10
  201. package/dist/tools/planning-agent.d.ts +0 -29
  202. package/dist/tools/planning-agent.js +0 -134
  203. package/dist/tools/progress-reporter.d.ts +0 -19
  204. package/dist/tools/progress-reporter.js +0 -52
  205. package/dist/tools/registry.d.ts +0 -21
  206. package/dist/tools/registry.js +0 -695
  207. package/dist/tools/tool-event-emitter.d.ts +0 -24
  208. package/dist/tools/tool-event-emitter.js +0 -25
  209. package/dist/tools/types.d.ts +0 -31
  210. package/dist/tools/types.js +0 -1
  211. package/dist/types.d.ts +0 -39
  212. package/dist/types.js +0 -8
  213. package/dist/update-checker.d.ts +0 -22
  214. package/dist/update-checker.js +0 -85
  215. package/dist/utils/config-manager.d.ts +0 -102
  216. package/dist/utils/config-manager.js +0 -326
  217. package/dist/utils/devtools.d.ts +0 -21
  218. package/dist/utils/devtools.js +0 -61
  219. package/dist/utils/message-formatters.d.ts +0 -32
  220. package/dist/utils/message-formatters.js +0 -590
  221. package/dist/utils/progress-tracker.d.ts +0 -59
  222. package/dist/utils/progress-tracker.js +0 -213
@@ -1,40 +0,0 @@
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
- }
@@ -1,232 +0,0 @@
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 { GoogleGenAI, Type, } from '@google/genai';
9
- import { globalToolRegistry } from '../tools/registry.js';
10
- const geminiModel = 'gemini-2.5-flash';
11
- export class GeminiConnection {
12
- constructor(config, systemPrompt) {
13
- Object.defineProperty(this, "client", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: void 0
18
- });
19
- Object.defineProperty(this, "apiKey", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "chatSession", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- Object.defineProperty(this, "systemInstruction", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: void 0
36
- });
37
- Object.defineProperty(this, "model", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- Object.defineProperty(this, "toolsRegistry", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: globalToolRegistry
48
- });
49
- // Only get apiKey from config - no fallback to env
50
- this.apiKey = config?.apiKey;
51
- this.model = config?.model ?? 'gemini-2.5-flash';
52
- this.client = new GoogleGenAI({ apiKey: this.apiKey });
53
- this.systemInstruction = systemPrompt;
54
- this.initChat();
55
- }
56
- initChat() {
57
- this.chatSession = this.client.chats.create({
58
- model: this.model,
59
- config: {
60
- systemInstruction: this.systemInstruction,
61
- tools: [{ functionDeclarations: this.getToolDeclarations() }],
62
- temperature: 0.7,
63
- thinkingConfig: {
64
- thinkingBudget: 0,
65
- },
66
- },
67
- });
68
- }
69
- async generate(parameters) {
70
- const response = await this.client.models.generateContent({
71
- model: geminiModel,
72
- contents: parameters.prompt,
73
- });
74
- const text = response.text ?? '';
75
- return { text, raw: response };
76
- }
77
- async chat(message, onMessage) {
78
- if (!this.chatSession) {
79
- throw new Error('Chat session is not initialized.');
80
- }
81
- let currentMessage = message;
82
- let response;
83
- let iteration = 0;
84
- const MAX_ITERATIONS = 15; // Tăng lên vì xử lý từng tool một
85
- while (currentMessage && iteration < MAX_ITERATIONS) {
86
- iteration++;
87
- response = await this.chatSession.sendMessage({
88
- message: currentMessage,
89
- });
90
- if (response.functionCalls && response.functionCalls.length > 0) {
91
- const functionResponses = [];
92
- // **IMPROVED: Sequential execution với early feedback**
93
- for (const functionCall of response.functionCalls) {
94
- try {
95
- const toolName = functionCall.name || 'unknown';
96
- const args = functionCall.args || {};
97
- const toolResult = await this.toolsRegistry.executeTool(toolName, args);
98
- const resultStr = typeof toolResult === 'string' ? toolResult : JSON.stringify(toolResult);
99
- if (onMessage) {
100
- // Pass tool execution info for better formatting
101
- const toolInfo = {
102
- toolName,
103
- args,
104
- result: toolResult,
105
- };
106
- onMessage('tool', resultStr, toolName, toolInfo);
107
- }
108
- functionResponses.push({
109
- functionResponse: {
110
- name: functionCall.name,
111
- response: { result: resultStr },
112
- },
113
- });
114
- // **NEW: Cho phép xử lý từng tool một nếu cần**
115
- // Nếu có nhiều function calls, có thể break ở đây để feedback sớm
116
- // Nhưng hiện tại vẫn xử lý hết để tương thích
117
- }
118
- catch (error) {
119
- const errorMsg = error instanceof Error ? error.message : String(error);
120
- // Log error
121
- if (onMessage) {
122
- const toolInfo = {
123
- toolName: functionCall.name || 'unknown',
124
- args: functionCall.args || {},
125
- result: `❌ Error: ${errorMsg}`,
126
- };
127
- onMessage('tool', `❌ Error: ${errorMsg}`, functionCall.name, toolInfo);
128
- }
129
- functionResponses.push({
130
- functionResponse: {
131
- name: functionCall.name,
132
- response: {
133
- error: errorMsg,
134
- },
135
- },
136
- });
137
- // **NEW: Stop on critical errors**
138
- // Nếu là lỗi nghiêm trọng, có thể break để không lãng phí
139
- // nhưng hiện tại vẫn tiếp tục để AI có đầy đủ context
140
- }
141
- }
142
- // Gửi tất cả function responses
143
- currentMessage = functionResponses;
144
- }
145
- else {
146
- // Không có function calls → trả về text response
147
- return response.text ?? '';
148
- }
149
- }
150
- if (iteration >= MAX_ITERATIONS) {
151
- console.warn(`⚠️ Max iterations (${MAX_ITERATIONS}) reached. This may indicate:`);
152
- console.warn(' - Too many sequential tool calls');
153
- console.warn(' - AI stuck in a reasoning loop');
154
- console.warn(' - Consider reviewing system prompt or tool definitions');
155
- throw new Error(`Max iterations (${MAX_ITERATIONS}) reached`);
156
- }
157
- return '';
158
- }
159
- getToolDeclarations() {
160
- const tools = this.toolsRegistry.list();
161
- return tools.map(tool => this.convertToFunctionDeclaration(tool));
162
- }
163
- convertToFunctionDeclaration(tool) {
164
- return {
165
- name: tool.name,
166
- description: tool.description,
167
- parameters: this.convertSchemaToGeminiSchema(tool.inputSchema),
168
- };
169
- }
170
- convertSchemaToGeminiSchema(schema) {
171
- if (!schema) {
172
- return {
173
- type: Type.OBJECT,
174
- properties: {},
175
- };
176
- }
177
- const converted = {
178
- type: Type.OBJECT,
179
- properties: {},
180
- };
181
- if (schema['properties']) {
182
- converted.properties = {};
183
- for (const [key, value] of Object.entries(schema['properties'])) {
184
- const prop = value;
185
- converted.properties[key] = this.convertPropertyToGeminiSchema(prop);
186
- }
187
- }
188
- if (schema['required']) {
189
- converted.required = schema['required'];
190
- }
191
- return converted;
192
- }
193
- convertPropertyToGeminiSchema(prop) {
194
- const propSchema = {
195
- type: this.mapTypeToGemini(prop.type),
196
- description: prop.description || '',
197
- };
198
- if (prop.type === 'object' && prop.properties) {
199
- propSchema.properties = {};
200
- for (const [key, value] of Object.entries(prop.properties)) {
201
- propSchema.properties[key] = this.convertPropertyToGeminiSchema(value);
202
- }
203
- if (prop.required) {
204
- propSchema.required = prop.required;
205
- }
206
- }
207
- if (prop.type === 'array') {
208
- if (prop.items && typeof prop.items === 'object') {
209
- propSchema.items = this.convertPropertyToGeminiSchema(prop.items);
210
- }
211
- else {
212
- // Gemini requires items field for arrays
213
- propSchema.items = {
214
- type: Type.STRING,
215
- description: '',
216
- };
217
- }
218
- }
219
- return propSchema;
220
- }
221
- mapTypeToGemini(type) {
222
- const typeMap = {
223
- string: Type.STRING,
224
- number: Type.NUMBER,
225
- integer: Type.INTEGER,
226
- boolean: Type.BOOLEAN,
227
- object: Type.OBJECT,
228
- array: Type.ARRAY,
229
- };
230
- return typeMap[type.toLowerCase()] || Type.STRING;
231
- }
232
- }
@@ -1,11 +0,0 @@
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 Export entry for connection modules.
7
- */
8
- export * from './types.js';
9
- export * from './ollama.js';
10
- export * from './gemini.js';
11
- export * from './claude.js';
@@ -1,11 +0,0 @@
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 Export entry for connection modules.
7
- */
8
- export * from './types.js';
9
- export * from './ollama.js';
10
- export * from './gemini.js';
11
- export * from './claude.js';
@@ -1,37 +0,0 @@
1
- /**
2
- * @author Bùi Trọng Hiếu
3
- * @email kevinbui210191@gmail.com
4
- * @create 2024-10-08
5
- * @modify 2024-10-08
6
- * @desc Ollama connection helper wrapping chat completion endpoint.
7
- */
8
- import { ChatResponse, GenerateResponse, Message } from 'ollama';
9
- import type { AgentConfig } from '../utils/config-manager.js';
10
- export declare const ollamaModels: readonly ["deepseek-v3.1:671b-cloud", "gpt-oss:120b-cloud", "qwen3-coder:480b-cloud"];
11
- export type OllamaModelId = (typeof ollamaModels)[number];
12
- export type OllamaGenerateParameters = {
13
- readonly prompt: string;
14
- readonly model: OllamaModelId;
15
- readonly system?: string;
16
- };
17
- export type OllamaGenerateResult<T = unknown> = {
18
- readonly text: string;
19
- readonly raw: T;
20
- };
21
- export declare class OllamaConnection {
22
- private ollama;
23
- private model;
24
- constructor(config?: AgentConfig | {
25
- model?: OllamaModelId;
26
- host?: string;
27
- apiKey?: string;
28
- });
29
- generate(parameters: OllamaGenerateParameters): Promise<GenerateResponse>;
30
- chat(userMessage: string): Promise<string>;
31
- chatWithTools(options: {
32
- model: string;
33
- messages: Message[];
34
- tools?: any[];
35
- stream?: false;
36
- }): Promise<ChatResponse>;
37
- }
@@ -1,73 +0,0 @@
1
- /**
2
- * @author Bùi Trọng Hiếu
3
- * @email kevinbui210191@gmail.com
4
- * @create 2024-10-08
5
- * @modify 2024-10-08
6
- * @desc Ollama connection helper wrapping chat completion endpoint.
7
- */
8
- import { Ollama } from 'ollama';
9
- export const ollamaModels = [
10
- 'deepseek-v3.1:671b-cloud',
11
- 'gpt-oss:120b-cloud',
12
- 'qwen3-coder:480b-cloud',
13
- ];
14
- export class OllamaConnection {
15
- constructor(config) {
16
- Object.defineProperty(this, "ollama", {
17
- enumerable: true,
18
- configurable: true,
19
- writable: true,
20
- value: void 0
21
- });
22
- Object.defineProperty(this, "model", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: 'deepseek-v3.1:671b-cloud'
27
- });
28
- this.model = config?.model ?? this.model;
29
- const host = config?.host ?? 'https://ollama.com';
30
- // If using ollama.com cloud, need API key
31
- const needsApiKey = host === 'https://ollama.com' || host.includes('ollama.com');
32
- // Only get apiKey from config - no fallback to env
33
- const apiKey = config?.apiKey;
34
- // if (needsApiKey && !apiKey) {
35
- // console.log('Hiện tại bạn chưa thêm apikey cho model ollama. Vui lòng thêm để dùng phần mềm')
36
- // }
37
- this.ollama = new Ollama({
38
- host: host,
39
- headers: needsApiKey
40
- ? {
41
- Authorization: 'Bearer ' + apiKey,
42
- }
43
- : {},
44
- });
45
- }
46
- async generate(parameters) {
47
- const response = await this.ollama.generate({
48
- model: parameters.model || this.model,
49
- prompt: parameters.prompt,
50
- system: parameters.system,
51
- stream: false,
52
- });
53
- return response;
54
- }
55
- // Simple chat method for direct conversation (matches GeminiConnection/ClaudeConnection)
56
- async chat(userMessage) {
57
- const response = await this.ollama.chat({
58
- model: this.model,
59
- messages: [{ role: 'user', content: userMessage }],
60
- stream: false,
61
- });
62
- return response.message.content;
63
- }
64
- // Advanced chat with tools (used by ollama-agent)
65
- async chatWithTools(options) {
66
- return await this.ollama.chat({
67
- model: options.model,
68
- messages: options.messages,
69
- tools: options.tools,
70
- stream: false,
71
- });
72
- }
73
- }
@@ -1,22 +0,0 @@
1
- /**
2
- * @author Bùi Trọng Hiếu
3
- * @email kevinbui210191@gmail.com
4
- * @create 2025-10-22
5
- * @desc Shared types for connection classes
6
- */
7
- /**
8
- * Tool execution information for callbacks
9
- * Supports both Gemini and Claude patterns
10
- */
11
- export interface ToolExecutionInfo {
12
- success?: boolean;
13
- output?: string;
14
- error?: string;
15
- toolName?: string;
16
- args?: any;
17
- result?: any;
18
- }
19
- /**
20
- * Message callback type for agent notifications
21
- */
22
- export type MessageCallback = (author: 'user' | 'assistant' | 'system' | 'tool', content: string, toolName?: string, toolInfo?: ToolExecutionInfo) => void;
@@ -1,7 +0,0 @@
1
- /**
2
- * @author Bùi Trọng Hiếu
3
- * @email kevinbui210191@gmail.com
4
- * @create 2025-10-22
5
- * @desc Shared types for connection classes
6
- */
7
- export {};
package/dist/env.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/env.js DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * @author Bùi Trọng Hiếu
3
- * @email kevinbui210191@gmail.com
4
- * @create 2024-10-08
5
- * @modify 2024-10-08
6
- * @desc Loads environment variables from .env files.
7
- */
8
- import { config } from 'dotenv';
9
- import { fileURLToPath } from 'node:url';
10
- import { dirname, join } from 'node:path';
11
- // Get the directory where this file is located
12
- const __filename = fileURLToPath(import.meta.url);
13
- const __dirname = dirname(__filename);
14
- // Load .env from apps/galaxy-code directory (completely silent)
15
- const originalStdout = process.stdout.write;
16
- const originalStderr = process.stderr.write;
17
- const originalConsoleLog = console.log;
18
- const originalConsoleInfo = console.info;
19
- // Suppress all possible output channels
20
- process.stdout.write = () => true;
21
- process.stderr.write = () => true;
22
- console.log = () => { };
23
- console.info = () => { };
24
- config({ path: join(__dirname, '..', '.env'), debug: false, override: false });
25
- // Restore output
26
- process.stdout.write = originalStdout;
27
- process.stderr.write = originalStderr;
28
- console.log = originalConsoleLog;
29
- console.info = originalConsoleInfo;
@@ -1,72 +0,0 @@
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
- }
72
- //# sourceMappingURL=claude.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/connections/claude.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAMzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAE7D,OAAO,KAAK,EAAqB,eAAe,EAAE,MAAM,YAAY,CAAA;AAEpE,MAAM,MAAM,aAAa,GACrB,4BAA4B,GAC5B,2BAA2B,GAC3B,wBAAwB,GACxB,0BAA0B,GAC1B,4BAA4B,CAAA;AAEhC,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,GAAG,eAAe,GAAG,cAAc,CAAA;IAC9D,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;CACF;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,mBAAmB,CAAsB;IACjD,OAAO,CAAC,4BAA4B,CAAqB;IACzD,OAAO,CAAC,YAAY,CAAC,CAAQ;IAC7B,OAAO,CAAC,aAAa,CAAqB;gBAE9B,MAAM,CAAC,EAAE,WAAW,EAAE,YAAY,CAAC,EAAE,MAAM;IAkBvD;;OAEG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BhD;;OAEG;IACI,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IAoC7E;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBtE;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;OAEG;IACH,UAAU,IAAI,aAAa,EAAE;IAI7B;;OAEG;IACH,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIrC;;OAEG;IACH,QAAQ,IAAI,aAAa;IAIzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI;IAIpC;;OAEG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,EACvB,SAAS,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,MAAM,CAAC;IAgIlB;;OAEG;IACH,gBAAgB,IAAI,IAAI;CAGzB"}