sam-coder-cli 1.0.43 → 1.0.45

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/bin/ai-team.js DELETED
@@ -1,234 +0,0 @@
1
- // Import dependencies at runtime to avoid circular dependencies
2
- let callOpenRouter;
3
- let MultiplayerClient;
4
- const readline = require('readline');
5
- const chalk = require('chalk');
6
- const { v4: uuidv4 } = require('uuid');
7
-
8
- // Flag to track if MultiplayerClient is being required to prevent infinite loops
9
- let isRequiringMultiplayerClient = false;
10
-
11
- // Lazy load dependencies to avoid circular dependencies
12
- function getCallOpenRouter() {
13
- if (!callOpenRouter) {
14
- callOpenRouter = require('./agi-cli').callOpenRouter;
15
- }
16
- return callOpenRouter;
17
- }
18
-
19
- function getMultiplayerClient() {
20
- if (!MultiplayerClient && !isRequiringMultiplayerClient) {
21
- try {
22
- isRequiringMultiplayerClient = true;
23
- const mc = require('./multiplayer-client');
24
- MultiplayerClient = mc.MultiplayerClient;
25
- } finally {
26
- isRequiringMultiplayerClient = false;
27
- }
28
- }
29
- if (!MultiplayerClient) {
30
- throw new Error('Failed to load MultiplayerClient');
31
- }
32
- return MultiplayerClient;
33
- }
34
-
35
- // System prompt for AI team collaboration
36
- const TEAM_COLLABORATION_PROMPT = `You are an AI team facilitator that helps coordinate multiple AI agents working together on a project.
37
-
38
- Your responsibilities include:
39
- 1. Understanding the project requirements from the host
40
- 2. Breaking down the project into clear, actionable tasks
41
- 3. Assigning tasks to appropriate team members based on their roles
42
- 4. Monitoring progress and coordinating between team members
43
-
44
- When the host provides a project idea (e.g., "create a calculator"), you should:
45
- 1. Analyze the requirements
46
- 2. Break it down into logical components
47
- 3. Create a task list with clear assignments
48
- 4. Provide a summary of the plan
49
-
50
- Respond in markdown format with clear sections for each part of your response.`;
51
-
52
- class AITeam {
53
- constructor(options = {}) {
54
- const MultiplayerClient = getMultiplayerClient();
55
- this.client = new MultiplayerClient({
56
- name: options.name || `Agent-${uuidv4().substr(0, 4)}`,
57
- role: options.role || 'DEVELOPER',
58
- model: options.model || 'deepseek/deepseek-chat-v3-0324:free',
59
- rl: options.rl
60
- });
61
-
62
- this.rl = options.rl || readline.createInterface({
63
- input: process.stdin,
64
- output: process.stdout
65
- });
66
-
67
- this.conversation = [
68
- { role: 'system', content: TEAM_COLLABORATION_PROMPT }
69
- ];
70
-
71
- this.setupEventHandlers();
72
- }
73
-
74
- setupEventHandlers() {
75
- this.client.on('connected', () => {
76
- console.log(chalk.green('āœ… Connected to multiplayer server'));
77
- });
78
-
79
- this.client.on('disconnected', () => {
80
- console.log(chalk.yellow('Disconnected from multiplayer server'));
81
- });
82
-
83
- this.client.on('error', (error) => {
84
- console.error(chalk.red('Error:'), error.message);
85
- });
86
-
87
- this.client.on('session_joined', async (data) => {
88
- console.log(chalk.green(`\nšŸŽ‰ Joined session ${data.sessionId} as ${this.client.name}`));
89
- console.log(chalk.blue(`Role: ${this.client.role}`));
90
-
91
- if (data.isHost) {
92
- console.log('\nAs the host, you can now enter a project prompt (e.g., "create a calculator"):');
93
- await this.promptForProject();
94
- } else {
95
- console.log('\nWaiting for host to start a project...');
96
- }
97
- });
98
-
99
- this.client.on('chat_message', async (message) => {
100
- if (message.clientId !== this.client.clientId) {
101
- console.log(`\nšŸ’¬ ${message.clientName || 'Unknown'}: ${message.text}`);
102
-
103
- // If we receive a task assignment, process it
104
- if (message.task) {
105
- await this.processTask(message.task);
106
- }
107
- }
108
- });
109
- }
110
-
111
- async start(sessionId = null) {
112
- let serverId = null;
113
- let actualSessionId = sessionId;
114
-
115
- // Check if sessionId contains server information (format: serverId:sessionId)
116
- if (sessionId && sessionId.includes(':')) {
117
- [serverId, actualSessionId] = sessionId.split(':');
118
- console.log(chalk.blue(`Attempting to connect to server: ${serverId}`));
119
- }
120
-
121
- // Connect to the server first
122
- try {
123
- await this.client.connect(serverId);
124
-
125
- if (actualSessionId) {
126
- console.log(`Joining session ${actualSessionId}...`);
127
- await this.client.joinSession(actualSessionId, false); // Don't create if not exists
128
- } else {
129
- // Create a new session - this user will be the host
130
- console.log('Creating new session...');
131
- const newSessionId = await this.client.createSession();
132
- this.client.isHost = true; // Ensure this client is marked as host
133
- console.log(chalk.green(`āœ… Created new session: ${newSessionId}`));
134
- console.log(chalk.yellow('You are the host of this session.'));
135
- console.log('Share this ID with others to collaborate!');
136
- console.log(chalk.yellow(`To join this session, use: ${serverId || 'localhost:8080'}:${newSessionId}`));
137
-
138
- // Notify the user they are the host
139
- console.log('\nAs the host, you can now enter a project prompt (e.g., "create a calculator"):');
140
- }
141
- } catch (error) {
142
- console.error(chalk.red('Failed to connect to server:'), error.message);
143
- process.exit(1);
144
- }
145
-
146
- // Start chat input loop
147
- this.rl.on('line', async (input) => {
148
- if (input.trim()) {
149
- if (this.client.isHost) {
150
- await this.handleHostInput(input.trim());
151
- } else {
152
- await this.handleTeamMemberInput(input.trim());
153
- }
154
- }
155
- });
156
- }
157
-
158
- async handleHostInput(input) {
159
- // Add user message to conversation
160
- this.conversation.push({ role: 'user', content: input });
161
-
162
- // Get AI response
163
- const callOpenRouter = getCallOpenRouter();
164
- const response = await callOpenRouter(this.conversation, this.client.model);
165
- const aiMessage = response.choices[0].message;
166
-
167
- // Add AI response to conversation
168
- this.conversation.push(aiMessage);
169
-
170
- // Display response
171
- console.log(`\nšŸ¤– ${aiMessage.content}\n`);
172
-
173
- // If AI suggests tasks, assign them to team members
174
- if (aiMessage.tool_calls) {
175
- await this.handleToolCalls(aiMessage.tool_calls);
176
- }
177
-
178
- // Show prompt for next input
179
- this.showPrompt();
180
- }
181
-
182
- async handleTeamMemberInput(input) {
183
- // For team members, just send chat messages for now
184
- this.client.sendChatMessage(input);
185
- }
186
-
187
- async handleToolCalls(toolCalls) {
188
- for (const toolCall of toolCalls) {
189
- if (toolCall.function.name === 'assign_task') {
190
- const args = JSON.parse(toolCall.function.arguments);
191
- await this.assignTask(args.role, args.task);
192
- }
193
- }
194
- }
195
-
196
- async assignTask(role, task) {
197
- console.log(chalk.yellow(`\nšŸ“‹ Task for ${role}: ${task}`));
198
-
199
- // In a real implementation, this would find the appropriate team member
200
- // and assign them the task. For now, we'll just log it.
201
- this.client.sendChatMessage(`Task assigned to ${role}: ${task}`, {
202
- task: { role, description: task }
203
- });
204
- }
205
-
206
- async processTask(task) {
207
- console.log(chalk.blue(`\nšŸ“Œ Task received: ${task.description}`));
208
-
209
- // Process the task using the AGI-CLI's tool calling system
210
- const callOpenRouter = getCallOpenRouter();
211
- const response = await callOpenRouter([
212
- { role: 'system', content: `You are an AI assistant working on a task: ${task.description}` },
213
- { role: 'user', content: 'Please complete this task step by step.' }
214
- ], this.client.model, true);
215
-
216
- const result = response.choices[0].message.content;
217
- console.log(chalk.green('āœ… Task completed!'));
218
- console.log(result);
219
-
220
- // Notify the team of task completion
221
- this.client.sendChatMessage(`Completed task: ${task.description}`);
222
- }
223
-
224
- showPrompt() {
225
- const prefix = this.client.isHost ? 'šŸ‘‘ Host' : 'šŸ‘¤ You';
226
- process.stdout.write(`\n${prefix} > `);
227
- }
228
-
229
- async promptForProject() {
230
- this.showPrompt();
231
- }
232
- }
233
-
234
- module.exports = AITeam;
@@ -1,48 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const AICollaboration = require('./ai-collaboration');
4
- const readline = require('readline');
5
- const chalk = require('chalk');
6
-
7
- // Create readline interface
8
- const rl = readline.createInterface({
9
- input: process.stdin,
10
- output: process.stdout
11
- });
12
-
13
- // Parse command line arguments
14
- const args = process.argv.slice(2);
15
- const sessionId = args[0];
16
- const role = args[1]?.toUpperCase() || 'DEVELOPER';
17
-
18
- console.log(chalk.cyan('\nšŸ¤– AI Team Collaboration šŸ¤–'));
19
- console.log(chalk.cyan('==========================\n'));
20
-
21
- // Get user's name
22
- rl.question('Enter your name (or press Enter for a random one): ', (name) => {
23
- // Create AI collaboration instance
24
- const aiCollab = new AICollaboration({
25
- name: name.trim() || undefined,
26
- role: role,
27
- rl: rl
28
- });
29
-
30
- // Handle Ctrl+C to exit gracefully
31
- process.on('SIGINT', () => {
32
- console.log('\nšŸ‘‹ Disconnecting...');
33
- process.exit(0);
34
- });
35
-
36
- // Start the collaboration
37
- aiCollab.start(sessionId).catch(error => {
38
- console.error(chalk.red('Error:'), error.message);
39
- process.exit(1);
40
- });
41
-
42
- // Listen for chat messages
43
- rl.on('line', (input) => {
44
- if (input.trim()) {
45
- aiCollab.sendChatMessage(input.trim());
46
- }
47
- });
48
- });