galaxy-code 0.1.6 → 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.
- package/dist/cli.bundle.js +588 -0
- package/package.json +6 -6
- package/dist/app.d.ts +0 -7
- package/dist/app.js +0 -597
- package/dist/auto-updater.d.ts +0 -21
- package/dist/auto-updater.js +0 -144
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -159
- package/dist/cli.min.js +0 -589
- package/dist/connections/claude.d.ts +0 -71
- package/dist/connections/claude.js +0 -303
- package/dist/connections/gemini.d.ts +0 -40
- package/dist/connections/gemini.js +0 -232
- package/dist/connections/index.d.ts +0 -11
- package/dist/connections/index.js +0 -11
- package/dist/connections/ollama.d.ts +0 -37
- package/dist/connections/ollama.js +0 -73
- package/dist/connections/types.d.ts +0 -22
- package/dist/connections/types.js +0 -7
- package/dist/env.d.ts +0 -1
- package/dist/env.js +0 -29
- package/dist/prompts/ba-it-analyzer.d.ts +0 -1
- package/dist/prompts/ba-it-analyzer.js +0 -143
- package/dist/prompts/index.d.ts +0 -11
- package/dist/prompts/index.js +0 -11
- package/dist/prompts/orchestrator.d.ts +0 -8
- package/dist/prompts/orchestrator.js +0 -88
- package/dist/prompts/planning-agent.d.ts +0 -8
- package/dist/prompts/planning-agent.js +0 -195
- package/dist/prompts/universal-agent.d.ts +0 -7
- package/dist/prompts/universal-agent.js +0 -111
- package/dist/providers/agent-selector.d.ts +0 -29
- package/dist/providers/agent-selector.js +0 -84
- package/dist/providers/claude-agent.d.ts +0 -29
- package/dist/providers/claude-agent.js +0 -121
- package/dist/providers/gemini-agent.d.ts +0 -36
- package/dist/providers/gemini-agent.js +0 -168
- package/dist/providers/index.d.ts +0 -12
- package/dist/providers/index.js +0 -12
- package/dist/providers/ollama-agent.d.ts +0 -53
- package/dist/providers/ollama-agent.js +0 -276
- package/dist/providers/orchestrator.d.ts +0 -16
- package/dist/providers/orchestrator.js +0 -76
- package/dist/tools/ba-it-analyzer.d.ts +0 -66
- package/dist/tools/ba-it-analyzer.js +0 -90
- package/dist/tools/code-generate-agent.d.ts +0 -51
- package/dist/tools/code-generate-agent.js +0 -159
- package/dist/tools/command-runner.d.ts +0 -14
- package/dist/tools/command-runner.js +0 -120
- package/dist/tools/document-parser.d.ts +0 -11
- package/dist/tools/document-parser.js +0 -83
- package/dist/tools/file-operations.d.ts +0 -17
- package/dist/tools/file-operations.js +0 -127
- package/dist/tools/galaxy-ui-integration.d.ts +0 -94
- package/dist/tools/galaxy-ui-integration.js +0 -244
- package/dist/tools/git-operations.d.ts +0 -11
- package/dist/tools/git-operations.js +0 -114
- package/dist/tools/index.d.ts +0 -10
- package/dist/tools/index.js +0 -10
- package/dist/tools/planning-agent.d.ts +0 -29
- package/dist/tools/planning-agent.js +0 -134
- package/dist/tools/progress-reporter.d.ts +0 -19
- package/dist/tools/progress-reporter.js +0 -52
- package/dist/tools/registry.d.ts +0 -21
- package/dist/tools/registry.js +0 -695
- package/dist/tools/tool-event-emitter.d.ts +0 -24
- package/dist/tools/tool-event-emitter.js +0 -25
- package/dist/tools/types.d.ts +0 -31
- package/dist/tools/types.js +0 -1
- package/dist/types.d.ts +0 -39
- package/dist/types.js +0 -8
- package/dist/update-checker.d.ts +0 -22
- package/dist/update-checker.js +0 -85
- package/dist/utils/config-manager.d.ts +0 -102
- package/dist/utils/config-manager.js +0 -326
- package/dist/utils/devtools.d.ts +0 -21
- package/dist/utils/devtools.js +0 -61
- package/dist/utils/message-formatters.d.ts +0 -32
- package/dist/utils/message-formatters.js +0 -590
- package/dist/utils/progress-tracker.d.ts +0 -59
- package/dist/utils/progress-tracker.js +0 -213
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-22
|
|
5
|
-
* @desc Universal Agent - Concise execution-focused prompt
|
|
6
|
-
*/
|
|
7
|
-
export function buildUniversalAgentPrompt(toolsContext) {
|
|
8
|
-
return `You are Galaxy AI - software development expert by kevinbui.
|
|
9
|
-
|
|
10
|
-
# Response Language
|
|
11
|
-
**Match user's language exactly** (detect from their input)
|
|
12
|
-
|
|
13
|
-
# Available Tools
|
|
14
|
-
${toolsContext}
|
|
15
|
-
|
|
16
|
-
# Planning & Execution Workflow
|
|
17
|
-
|
|
18
|
-
## When to Plan
|
|
19
|
-
Multi-step projects (apps, websites, features with 3+ steps) → Use planning workflow
|
|
20
|
-
|
|
21
|
-
## Execution Loop
|
|
22
|
-
\`\`\`
|
|
23
|
-
1. plan_task({userContext: "user's request"})
|
|
24
|
-
→ Receive: {summary, steps: [{step, action, tool, reasoning}]}
|
|
25
|
-
|
|
26
|
-
2. FOR EACH step in plan.steps:
|
|
27
|
-
a. Execute the step using specified tool
|
|
28
|
-
b. ⚠️ CRITICAL: MUST call progress_reporter({step: N, status: "success"|"error"|"in_progress"})
|
|
29
|
-
- After EVERY step execution
|
|
30
|
-
- Even if step fails
|
|
31
|
-
- NO EXCEPTIONS
|
|
32
|
-
c. Move to next step
|
|
33
|
-
|
|
34
|
-
3. All steps complete → Done
|
|
35
|
-
\`\`\`
|
|
36
|
-
|
|
37
|
-
## ⚠️ CRITICAL RULE: Progress Reporting
|
|
38
|
-
**YOU MUST call progress_reporter after EVERY step execution. This is NOT optional.**
|
|
39
|
-
|
|
40
|
-
Example of CORRECT execution:
|
|
41
|
-
\`\`\`
|
|
42
|
-
Step 1: file_tree(...) → progress_reporter({step: 1, status: "success"})
|
|
43
|
-
Step 2: command_run(...) → progress_reporter({step: 2, status: "success"})
|
|
44
|
-
Step 3: file_write(...) → progress_reporter({step: 3, status: "success"})
|
|
45
|
-
\`\`\`
|
|
46
|
-
|
|
47
|
-
Example of WRONG execution (DO NOT DO THIS):
|
|
48
|
-
\`\`\`
|
|
49
|
-
Step 1: file_tree(...) ❌ Missing progress_reporter
|
|
50
|
-
Step 2: command_run(...) ❌ Missing progress_reporter
|
|
51
|
-
Step 3: file_write(...) ❌ Missing progress_reporter
|
|
52
|
-
\`\`\`
|
|
53
|
-
|
|
54
|
-
## Example Flow
|
|
55
|
-
\`\`\`
|
|
56
|
-
User: "Create todo app with Next.js"
|
|
57
|
-
|
|
58
|
-
→ Step 1: plan_task({userContext: "..."})
|
|
59
|
-
Result: 5-step plan
|
|
60
|
-
|
|
61
|
-
→ Step 2: command_run({command: "npx create-next-app..."})
|
|
62
|
-
→ Step 3: progress_reporter({step: 1, status: "success"})
|
|
63
|
-
|
|
64
|
-
→ Step 4: file_write({path: "components/TodoList.tsx", content: "..."})
|
|
65
|
-
→ Step 5: progress_reporter({step: 2, status: "success"})
|
|
66
|
-
|
|
67
|
-
... repeat for all steps ...
|
|
68
|
-
\`\`\`
|
|
69
|
-
|
|
70
|
-
# Command Execution Rules
|
|
71
|
-
|
|
72
|
-
**Setup commands (create-*, npm init, etc.):**
|
|
73
|
-
1. ✅ Run ONCE with ALL default flags (--yes, --default, etc.)
|
|
74
|
-
2. ✅ Check result → Success? → STOP → Continue to file creation
|
|
75
|
-
3. ❌ DON'T retry with different flags
|
|
76
|
-
4. ❌ NEVER use "cd" - working directory managed automatically
|
|
77
|
-
5. ❌ NEVER execute in /tmp or outside project
|
|
78
|
-
|
|
79
|
-
# Workflows
|
|
80
|
-
|
|
81
|
-
## NEW Projects
|
|
82
|
-
\`\`\`
|
|
83
|
-
1. plan_task: Get execution plan (optional for simple projects)
|
|
84
|
-
2. command_run: Setup with ALL flags → ONCE
|
|
85
|
-
3. file_write: Pages, components, configs
|
|
86
|
-
4. progress_reporter: After each major step
|
|
87
|
-
5. Done: Complete functional app
|
|
88
|
-
\`\`\`
|
|
89
|
-
|
|
90
|
-
## ADD Features (Existing Project)
|
|
91
|
-
\`\`\`
|
|
92
|
-
1. file_tree: Understand structure
|
|
93
|
-
2. file_read: Check current code
|
|
94
|
-
3. file_write: New/updated files
|
|
95
|
-
4. command_run: Install deps (--yes)
|
|
96
|
-
5. Done
|
|
97
|
-
\`\`\`
|
|
98
|
-
|
|
99
|
-
# Detection
|
|
100
|
-
- **NEW**: "Create/Build/Make" + project/app/website
|
|
101
|
-
- **FEATURE**: "Add/Fix/Update" + mentions existing/current
|
|
102
|
-
|
|
103
|
-
# Core Rules
|
|
104
|
-
- **Code**: TypeScript preferred, clean, maintainable, error handling
|
|
105
|
-
- **Git** (if enabled): Conventional commits at logical checkpoints
|
|
106
|
-
- **Testing** (if enabled): Run after changes, fix failures
|
|
107
|
-
- **Errors**: Analyze → Try alternative approach → Explain
|
|
108
|
-
- **Progress**: ALWAYS call progress_reporter after completing each step in a plan
|
|
109
|
-
|
|
110
|
-
Remember: Execute commands ONCE → Check success → Build complete app!`;
|
|
111
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-21
|
|
5
|
-
* @modify 2025-10-22
|
|
6
|
-
* @desc Agent factory for selecting appropriate AI agent based on config
|
|
7
|
-
*/
|
|
8
|
-
import type { GalaxyConfig } from '../utils/config-manager.js';
|
|
9
|
-
export interface AgentInterface {
|
|
10
|
-
handleUserInput(input: string, options?: {
|
|
11
|
-
gitEnabled: boolean;
|
|
12
|
-
testEnabled: boolean;
|
|
13
|
-
}, onMessage?: (author: 'user' | 'assistant' | 'system' | 'tool', content: string, toolName?: string, toolInfo?: any) => void): Promise<{
|
|
14
|
-
content: string;
|
|
15
|
-
}>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Select appropriate agent based on Galaxy config
|
|
19
|
-
* Uses the configured agent
|
|
20
|
-
*/
|
|
21
|
-
export declare function selectAgent(config: GalaxyConfig): AgentInterface | null;
|
|
22
|
-
/**
|
|
23
|
-
* Get human-readable agent description
|
|
24
|
-
*/
|
|
25
|
-
export declare function getAgentDescription(config: GalaxyConfig): string;
|
|
26
|
-
/**
|
|
27
|
-
* Check if agent supports tool use
|
|
28
|
-
*/
|
|
29
|
-
export declare function agentSupportsTools(): boolean;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// import {orchestratorAgent} from './orchestrator.js';
|
|
2
|
-
import { claudeAgent } from './claude-agent.js';
|
|
3
|
-
import { OllamaAgent } from './ollama-agent.js';
|
|
4
|
-
import { geminiAgent } from './gemini-agent.js';
|
|
5
|
-
/**
|
|
6
|
-
* Select appropriate agent based on Galaxy config
|
|
7
|
-
* Uses the configured agent
|
|
8
|
-
*/
|
|
9
|
-
export function selectAgent(config) {
|
|
10
|
-
// Get agent config array
|
|
11
|
-
const agentArray = config.agent;
|
|
12
|
-
if (!agentArray || agentArray.length === 0) {
|
|
13
|
-
console.warn('⚠️ No agents configured. Using Ollama agent as default.');
|
|
14
|
-
return new OllamaAgent();
|
|
15
|
-
}
|
|
16
|
-
// Check for manual mode first - both CLI and VSCode should use Ollama with qwen3-coder:480b-cloud
|
|
17
|
-
const manualAgent = agentArray.find((a) => a.type === 'manual');
|
|
18
|
-
if (manualAgent) {
|
|
19
|
-
// Use Ollama Agent with qwen3-coder:480b-cloud model for manual mode
|
|
20
|
-
const manualAgentConfig = {
|
|
21
|
-
type: 'ollama',
|
|
22
|
-
model: 'qwen3-coder:480b-cloud',
|
|
23
|
-
host: 'https://ollama.com',
|
|
24
|
-
apiKey: manualAgent.apiKey,
|
|
25
|
-
};
|
|
26
|
-
return new OllamaAgent(manualAgentConfig);
|
|
27
|
-
}
|
|
28
|
-
// For non-manual modes, find first working agent (claude, gemini, or ollama)
|
|
29
|
-
const primaryAgent = agentArray.find((a) => a.type === 'claude' || a.type === 'gemini' || a.type === 'ollama') ?? agentArray[0];
|
|
30
|
-
// Check if primaryAgent is defined
|
|
31
|
-
if (!primaryAgent) {
|
|
32
|
-
console.warn('⚠️ No valid agent found. Using Ollama agent as default.');
|
|
33
|
-
return new OllamaAgent();
|
|
34
|
-
}
|
|
35
|
-
switch (primaryAgent.type) {
|
|
36
|
-
case 'claude':
|
|
37
|
-
// Use Claude Agent with full tool access
|
|
38
|
-
return claudeAgent.instance;
|
|
39
|
-
case 'gemini':
|
|
40
|
-
// Use Gemini Agent with full tool access
|
|
41
|
-
return geminiAgent.instance;
|
|
42
|
-
case 'ollama':
|
|
43
|
-
// Use Ollama Agent with full tool access
|
|
44
|
-
return new OllamaAgent(primaryAgent);
|
|
45
|
-
default:
|
|
46
|
-
// Default to Ollama agent
|
|
47
|
-
console.warn('⚠️ Unknown agent type. Using Ollama agent.');
|
|
48
|
-
return new OllamaAgent();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Get human-readable agent description
|
|
53
|
-
*/
|
|
54
|
-
export function getAgentDescription(config) {
|
|
55
|
-
const agentArray = config.agent;
|
|
56
|
-
if (!agentArray || agentArray.length === 0) {
|
|
57
|
-
return 'Ollama (default)';
|
|
58
|
-
}
|
|
59
|
-
// Find manual agent first, otherwise use first agent
|
|
60
|
-
const primaryAgent = agentArray.find((a) => a.type === 'manual') ?? agentArray[0];
|
|
61
|
-
// Check if primaryAgent is defined
|
|
62
|
-
if (!primaryAgent) {
|
|
63
|
-
return 'Ollama (default)';
|
|
64
|
-
}
|
|
65
|
-
switch (primaryAgent.type) {
|
|
66
|
-
case 'claude':
|
|
67
|
-
return 'Claude';
|
|
68
|
-
case 'gemini':
|
|
69
|
-
return 'Gemini';
|
|
70
|
-
case 'ollama':
|
|
71
|
-
return 'Ollama';
|
|
72
|
-
case 'manual':
|
|
73
|
-
return 'Manual (Orchestrator)';
|
|
74
|
-
default:
|
|
75
|
-
return 'Ollama (default)';
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Check if agent supports tool use
|
|
80
|
-
*/
|
|
81
|
-
export function agentSupportsTools() {
|
|
82
|
-
// All agents support tools
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig } from '../utils/config-manager.js';
|
|
2
|
-
export interface ClaudeAgentOptions {
|
|
3
|
-
gitEnabled: boolean;
|
|
4
|
-
testEnabled: boolean;
|
|
5
|
-
}
|
|
6
|
-
export type MessageCallback = (author: 'user' | 'assistant' | 'system' | 'tool', content: string, toolName?: string, toolInfo?: any) => void;
|
|
7
|
-
export declare class ClaudeAgent {
|
|
8
|
-
private connection;
|
|
9
|
-
private toolsRegistry;
|
|
10
|
-
private readonly toolNames;
|
|
11
|
-
constructor(config?: AgentConfig);
|
|
12
|
-
/**
|
|
13
|
-
* Convert tool registry format to Anthropic tool format
|
|
14
|
-
*/
|
|
15
|
-
private getAnthropicTools;
|
|
16
|
-
/**
|
|
17
|
-
* Handle user input and orchestrate tool calls
|
|
18
|
-
*/
|
|
19
|
-
handleUserInput(input: string, options?: ClaudeAgentOptions, onMessage?: MessageCallback, retryCount?: number): Promise<{
|
|
20
|
-
content: string;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* Clear conversation history
|
|
24
|
-
*/
|
|
25
|
-
clearHistory(): void;
|
|
26
|
-
}
|
|
27
|
-
export declare const claudeAgent: {
|
|
28
|
-
readonly instance: ClaudeAgent;
|
|
29
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { ToolRegistry } from '../tools/index.js';
|
|
2
|
-
import { ClaudeConnection } from '../connections/claude.js';
|
|
3
|
-
import { buildUniversalAgentPrompt } from '../prompts/index.js';
|
|
4
|
-
export class ClaudeAgent {
|
|
5
|
-
constructor(config) {
|
|
6
|
-
Object.defineProperty(this, "connection", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "toolsRegistry", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: new ToolRegistry()
|
|
17
|
-
});
|
|
18
|
-
// Low-level tools for Claude to build software
|
|
19
|
-
Object.defineProperty(this, "toolNames", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: [
|
|
24
|
-
'file_read',
|
|
25
|
-
'file_write',
|
|
26
|
-
'file_tree',
|
|
27
|
-
'file_list',
|
|
28
|
-
'file_search',
|
|
29
|
-
'git_status',
|
|
30
|
-
'git_commit',
|
|
31
|
-
'git_push',
|
|
32
|
-
'git_pull',
|
|
33
|
-
'git_diff',
|
|
34
|
-
'git_log',
|
|
35
|
-
'git_branches',
|
|
36
|
-
'command_run',
|
|
37
|
-
'install_dependencies',
|
|
38
|
-
'test_run',
|
|
39
|
-
'document_parse',
|
|
40
|
-
'plan_task',
|
|
41
|
-
'progress_reporter',
|
|
42
|
-
// Galaxy UI Integration
|
|
43
|
-
'galaxy_ui_list',
|
|
44
|
-
'galaxy_ui_search',
|
|
45
|
-
'galaxy_ui_get_component',
|
|
46
|
-
'galaxy_ui_categories',
|
|
47
|
-
'galaxy_ui_add',
|
|
48
|
-
'galaxy_ui_init',
|
|
49
|
-
'galaxy_ui_docs',
|
|
50
|
-
]
|
|
51
|
-
});
|
|
52
|
-
// Build system prompt using shared universal prompt
|
|
53
|
-
const toolsContext = this.toolsRegistry.getToolsContext(this.toolNames);
|
|
54
|
-
const systemPrompt = buildUniversalAgentPrompt(toolsContext);
|
|
55
|
-
// Initialize connection with config and systemPrompt
|
|
56
|
-
this.connection = new ClaudeConnection(config, systemPrompt);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Convert tool registry format to Anthropic tool format
|
|
60
|
-
*/
|
|
61
|
-
getAnthropicTools() {
|
|
62
|
-
const tools = this.toolsRegistry.getToolsByNames(this.toolNames);
|
|
63
|
-
return tools.map(tool => ({
|
|
64
|
-
name: tool.name,
|
|
65
|
-
description: tool.description,
|
|
66
|
-
input_schema: tool.inputSchema,
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Handle user input and orchestrate tool calls
|
|
71
|
-
*/
|
|
72
|
-
async handleUserInput(input, options, onMessage, retryCount = 0) {
|
|
73
|
-
const MAX_RETRIES = 3;
|
|
74
|
-
try {
|
|
75
|
-
// Add system context to input
|
|
76
|
-
const contextMessage = options
|
|
77
|
-
? `[System Context: Git=${options.gitEnabled ? 'ON' : 'OFF'}, Test Planning=${options.testEnabled ? 'ON' : 'OFF'}]\n\n${input}`
|
|
78
|
-
: input;
|
|
79
|
-
// Notify user message
|
|
80
|
-
if (onMessage) {
|
|
81
|
-
onMessage('user', contextMessage);
|
|
82
|
-
}
|
|
83
|
-
// Call connection's chatWithTools (handles full loop)
|
|
84
|
-
const response = await this.connection.chatWithTools(contextMessage, this.getAnthropicTools(), onMessage);
|
|
85
|
-
// Notify final response
|
|
86
|
-
if (onMessage) {
|
|
87
|
-
onMessage('assistant', response);
|
|
88
|
-
}
|
|
89
|
-
return { content: response || '(No response)' };
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
// Silent auto-retry with exponential backoff
|
|
93
|
-
if (retryCount < MAX_RETRIES) {
|
|
94
|
-
// Wait before retry (exponential backoff: 1s, 2s, 4s)
|
|
95
|
-
const delayMs = Math.pow(2, retryCount) * 1000;
|
|
96
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
97
|
-
// Silent retry - continue with "Continued" message
|
|
98
|
-
return await this.handleUserInput('Continued', options, onMessage, retryCount + 1);
|
|
99
|
-
}
|
|
100
|
-
// Max retries exceeded - throw error to app.tsx
|
|
101
|
-
throw new Error(`Agent failed after ${MAX_RETRIES} retries: ${error instanceof Error ? error.message : String(error)}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Clear conversation history
|
|
106
|
-
*/
|
|
107
|
-
clearHistory() {
|
|
108
|
-
this.connection.clearHistory();
|
|
109
|
-
this.connection.clearToolHistory();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
// Singleton instance with lazy initialization
|
|
113
|
-
let _claudeAgent = null;
|
|
114
|
-
export const claudeAgent = {
|
|
115
|
-
get instance() {
|
|
116
|
-
if (!_claudeAgent) {
|
|
117
|
-
_claudeAgent = new ClaudeAgent();
|
|
118
|
-
}
|
|
119
|
-
return _claudeAgent;
|
|
120
|
-
},
|
|
121
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig } from '../utils/config-manager.js';
|
|
2
|
-
export interface GeminiAgentOptions {
|
|
3
|
-
gitEnabled: boolean;
|
|
4
|
-
testEnabled: boolean;
|
|
5
|
-
}
|
|
6
|
-
export type MessageCallback = (author: 'user' | 'assistant' | 'system' | 'tool', content: string, toolName?: string, toolInfo?: any) => void;
|
|
7
|
-
interface ConversationMessage {
|
|
8
|
-
role: 'user' | 'assistant' | 'system';
|
|
9
|
-
content: string;
|
|
10
|
-
}
|
|
11
|
-
export declare class GeminiAgent {
|
|
12
|
-
private connection;
|
|
13
|
-
private toolsRegistry;
|
|
14
|
-
private conversationHistory;
|
|
15
|
-
private systemPrompt;
|
|
16
|
-
private readonly toolNames;
|
|
17
|
-
constructor(config?: AgentConfig);
|
|
18
|
-
/**
|
|
19
|
-
* Handle user input and orchestrate tool calls
|
|
20
|
-
*/
|
|
21
|
-
handleUserInput(input: string, options?: GeminiAgentOptions, onMessage?: MessageCallback, retryCount?: number): Promise<{
|
|
22
|
-
content: string;
|
|
23
|
-
}>;
|
|
24
|
-
/**
|
|
25
|
-
* Clear conversation history
|
|
26
|
-
*/
|
|
27
|
-
clearHistory(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Get conversation history
|
|
30
|
-
*/
|
|
31
|
-
getHistory(): ConversationMessage[];
|
|
32
|
-
}
|
|
33
|
-
export declare const geminiAgent: {
|
|
34
|
-
readonly instance: GeminiAgent;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-22
|
|
5
|
-
* @modify 2025-10-22
|
|
6
|
-
* @desc Gemini Agent - Self-contained AI orchestrator
|
|
7
|
-
*/
|
|
8
|
-
import { GeminiConnection } from '../connections/gemini.js';
|
|
9
|
-
import { ToolRegistry } from '../tools/index.js';
|
|
10
|
-
import { buildUniversalAgentPrompt } from '../prompts/index.js';
|
|
11
|
-
export class GeminiAgent {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
Object.defineProperty(this, "connection", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: void 0
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "toolsRegistry", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: new ToolRegistry()
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "conversationHistory", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: []
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "systemPrompt", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
|
-
// Low-level tools for Gemini to build software
|
|
38
|
-
Object.defineProperty(this, "toolNames", {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
writable: true,
|
|
42
|
-
value: [
|
|
43
|
-
'file_read',
|
|
44
|
-
'file_write',
|
|
45
|
-
'file_tree',
|
|
46
|
-
'file_list',
|
|
47
|
-
'file_search',
|
|
48
|
-
'git_status',
|
|
49
|
-
'git_commit',
|
|
50
|
-
'git_push',
|
|
51
|
-
'git_pull',
|
|
52
|
-
'git_diff',
|
|
53
|
-
'git_log',
|
|
54
|
-
'git_branches',
|
|
55
|
-
'command_run',
|
|
56
|
-
'install_dependencies',
|
|
57
|
-
'test_run',
|
|
58
|
-
'document_parse',
|
|
59
|
-
'plan_task',
|
|
60
|
-
'progress_reporter',
|
|
61
|
-
// Galaxy UI Integration
|
|
62
|
-
'galaxy_ui_list',
|
|
63
|
-
'galaxy_ui_search',
|
|
64
|
-
'galaxy_ui_get_component',
|
|
65
|
-
'galaxy_ui_categories',
|
|
66
|
-
'galaxy_ui_add',
|
|
67
|
-
'galaxy_ui_init',
|
|
68
|
-
'galaxy_ui_docs',
|
|
69
|
-
]
|
|
70
|
-
});
|
|
71
|
-
// Build system prompt using shared universal prompt
|
|
72
|
-
const toolsContext = this.toolsRegistry.getToolsContext(this.toolNames);
|
|
73
|
-
this.systemPrompt = buildUniversalAgentPrompt(toolsContext);
|
|
74
|
-
this.connection = new GeminiConnection(config, this.systemPrompt);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Handle user input and orchestrate tool calls
|
|
78
|
-
*/
|
|
79
|
-
async handleUserInput(input, options, onMessage, retryCount = 0) {
|
|
80
|
-
const MAX_RETRIES = 3;
|
|
81
|
-
try {
|
|
82
|
-
// Add system context to input
|
|
83
|
-
const contextMessage = options
|
|
84
|
-
? `[System Context: Git=${options.gitEnabled ? 'ON' : 'OFF'}, Test Planning=${options.testEnabled ? 'ON' : 'OFF'}]\n\n${input}`
|
|
85
|
-
: input;
|
|
86
|
-
// Add user message to history
|
|
87
|
-
this.conversationHistory.push({
|
|
88
|
-
role: 'user',
|
|
89
|
-
content: contextMessage,
|
|
90
|
-
});
|
|
91
|
-
// Notify user message
|
|
92
|
-
if (onMessage) {
|
|
93
|
-
onMessage('user', contextMessage);
|
|
94
|
-
}
|
|
95
|
-
// Create callback wrapper for tool execution notifications
|
|
96
|
-
const geminiCallback = (author, content, toolName, toolInfo) => {
|
|
97
|
-
if (onMessage && author === 'tool' && toolName) {
|
|
98
|
-
// Special handling for plan_task and progress_reporter
|
|
99
|
-
if (toolName === 'plan_task' || toolName === 'progress_reporter') {
|
|
100
|
-
// Don't notify - event already emitted by tool
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
// Regular tool handling - notify result only
|
|
104
|
-
const success = !content.startsWith('❌');
|
|
105
|
-
onMessage('tool', content, toolName, {
|
|
106
|
-
success,
|
|
107
|
-
output: toolInfo?.result || content,
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
// Start conversation with Gemini
|
|
112
|
-
const response = await this.connection.chat(contextMessage, geminiCallback);
|
|
113
|
-
// Add assistant response to history
|
|
114
|
-
this.conversationHistory.push({
|
|
115
|
-
role: 'assistant',
|
|
116
|
-
content: response,
|
|
117
|
-
});
|
|
118
|
-
// Notify final response
|
|
119
|
-
if (onMessage) {
|
|
120
|
-
onMessage('assistant', response);
|
|
121
|
-
}
|
|
122
|
-
return { content: response || '(No response)' };
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
// Silent auto-retry with exponential backoff
|
|
126
|
-
if (retryCount < MAX_RETRIES) {
|
|
127
|
-
// Remove last user message from history to avoid duplication
|
|
128
|
-
if (this.conversationHistory.length > 0 &&
|
|
129
|
-
this.conversationHistory[this.conversationHistory.length - 1]?.role === 'user') {
|
|
130
|
-
this.conversationHistory.pop();
|
|
131
|
-
}
|
|
132
|
-
// Wait before retry (exponential backoff: 1s, 2s, 4s)
|
|
133
|
-
const delayMs = Math.pow(2, retryCount) * 1000;
|
|
134
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
135
|
-
// Silent retry - continue with "Continued" message
|
|
136
|
-
return await this.handleUserInput('Continued', options, onMessage, retryCount + 1);
|
|
137
|
-
}
|
|
138
|
-
// Max retries exceeded - throw error to app.tsx
|
|
139
|
-
throw new Error(`Agent failed after ${MAX_RETRIES} retries: ${error instanceof Error ? error.message : String(error)}`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Clear conversation history
|
|
144
|
-
*/
|
|
145
|
-
clearHistory() {
|
|
146
|
-
this.conversationHistory = [];
|
|
147
|
-
// Call clearHistory on connection if available
|
|
148
|
-
if ('clearHistory' in this.connection && typeof this.connection.clearHistory === 'function') {
|
|
149
|
-
this.connection.clearHistory();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Get conversation history
|
|
154
|
-
*/
|
|
155
|
-
getHistory() {
|
|
156
|
-
return [...this.conversationHistory];
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// Singleton instance with lazy initialization
|
|
160
|
-
let _geminiAgent = null;
|
|
161
|
-
export const geminiAgent = {
|
|
162
|
-
get instance() {
|
|
163
|
-
if (!_geminiAgent) {
|
|
164
|
-
_geminiAgent = new GeminiAgent();
|
|
165
|
-
}
|
|
166
|
-
return _geminiAgent;
|
|
167
|
-
},
|
|
168
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-21
|
|
5
|
-
* @modify 2025-10-22
|
|
6
|
-
* @desc AI module exports - orchestrator, agents, and selector
|
|
7
|
-
*/
|
|
8
|
-
export { OrchestratorAgent } from './orchestrator.js';
|
|
9
|
-
export { ClaudeAgent } from './claude-agent.js';
|
|
10
|
-
export { OllamaAgent } from './ollama-agent.js';
|
|
11
|
-
export { GeminiAgent } from './gemini-agent.js';
|
|
12
|
-
export { selectAgent, getAgentDescription, agentSupportsTools, type AgentInterface, } from './agent-selector.js';
|
package/dist/providers/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-21
|
|
5
|
-
* @modify 2025-10-22
|
|
6
|
-
* @desc AI module exports - orchestrator, agents, and selector
|
|
7
|
-
*/
|
|
8
|
-
export { OrchestratorAgent } from './orchestrator.js';
|
|
9
|
-
export { ClaudeAgent } from './claude-agent.js';
|
|
10
|
-
export { OllamaAgent } from './ollama-agent.js';
|
|
11
|
-
export { GeminiAgent } from './gemini-agent.js';
|
|
12
|
-
export { selectAgent, getAgentDescription, agentSupportsTools, } from './agent-selector.js';
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author Bùi Trọng Hiếu
|
|
3
|
-
* @email kevinbui210191@gmail.com
|
|
4
|
-
* @create 2025-10-22
|
|
5
|
-
* @modify 2025-10-22
|
|
6
|
-
* @desc Ollama Agent - Self-contained AI orchestrator
|
|
7
|
-
*/
|
|
8
|
-
import { type OllamaModelId } from '../connections/ollama.js';
|
|
9
|
-
import type { Message } from 'ollama';
|
|
10
|
-
import type { AgentConfig } from '../utils/config-manager.js';
|
|
11
|
-
export interface OllamaAgentOptions {
|
|
12
|
-
gitEnabled: boolean;
|
|
13
|
-
testEnabled: boolean;
|
|
14
|
-
}
|
|
15
|
-
export type MessageCallback = (author: 'user' | 'assistant' | 'system' | 'tool', content: string, toolName?: string, toolInfo?: any) => void;
|
|
16
|
-
export declare class OllamaAgent {
|
|
17
|
-
private connection;
|
|
18
|
-
private model;
|
|
19
|
-
private toolsRegistry;
|
|
20
|
-
private conversationHistory;
|
|
21
|
-
private systemPrompt;
|
|
22
|
-
private readonly toolNames;
|
|
23
|
-
constructor(config?: AgentConfig);
|
|
24
|
-
/**
|
|
25
|
-
* Convert tool registry format to Ollama tool format
|
|
26
|
-
*/
|
|
27
|
-
private getOllamaTools;
|
|
28
|
-
/**
|
|
29
|
-
* Handle user input and orchestrate tool calls
|
|
30
|
-
*/
|
|
31
|
-
handleUserInput(input: string, options?: OllamaAgentOptions, onMessage?: MessageCallback, retryCount?: number): Promise<{
|
|
32
|
-
content: string;
|
|
33
|
-
}>;
|
|
34
|
-
/**
|
|
35
|
-
* Clear conversation history
|
|
36
|
-
*/
|
|
37
|
-
clearHistory(): void;
|
|
38
|
-
/**
|
|
39
|
-
* Get conversation history
|
|
40
|
-
*/
|
|
41
|
-
getHistory(): Message[];
|
|
42
|
-
/**
|
|
43
|
-
* Change model
|
|
44
|
-
*/
|
|
45
|
-
setModel(model: OllamaModelId): void;
|
|
46
|
-
/**
|
|
47
|
-
* Get current model
|
|
48
|
-
*/
|
|
49
|
-
getModel(): OllamaModelId;
|
|
50
|
-
}
|
|
51
|
-
export declare const ollamaAgent: {
|
|
52
|
-
readonly instance: OllamaAgent;
|
|
53
|
-
};
|