sam-coder-cli 1.0.4 → 1.0.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 (2) hide show
  1. package/bin/agi-cli.js +43 -49
  2. package/package.json +2 -2
package/bin/agi-cli.js CHANGED
@@ -508,12 +508,10 @@ async function handleToolCalls(toolCalls, messages) {
508
508
  }
509
509
 
510
510
  // Process a query with tool calling
511
- async function processQueryWithTools(query, conversation = [], maxIterations = 5) {
511
+ async function processQueryWithTools(query, conversation = []) {
512
512
  // Add user message to conversation
513
513
  const userMessage = { role: 'user', content: query };
514
- let messages = [...conversation, userMessage];
515
- let iteration = 0;
516
- let finalResponse = null;
514
+ const messages = [...conversation, userMessage];
517
515
 
518
516
  // Add system message if this is the first message
519
517
  if (conversation.length === 0) {
@@ -526,54 +524,50 @@ If a tool fails, you can try again with different parameters or a different appr
526
524
  });
527
525
  }
528
526
 
529
- // Process in a loop to handle multiple tool calls
530
- while (iteration < maxIterations) {
531
- ui.startThinking();
532
-
533
- try {
534
- const response = await callOpenRouterWithTools(messages);
535
- const assistantMessage = response.choices[0].message;
536
- messages.push(assistantMessage);
537
-
538
- // If there are no tool calls, we're done
539
- if (!assistantMessage.tool_calls || assistantMessage.tool_calls.length === 0) {
540
- ui.stopThinking();
541
- finalResponse = assistantMessage.content || 'No content in response';
542
- break;
543
- }
544
-
545
- // Process tool calls
546
- console.log(`đŸ› ī¸ Executing ${assistantMessage.tool_calls.length} tools...`);
547
- const toolResults = await handleToolCalls(assistantMessage.tool_calls, messages);
548
-
549
- // Add tool results to messages
550
- messages = [...messages, ...toolResults];
551
-
552
- // If we've reached max iterations, get a final response
553
- if (iteration === maxIterations - 1) {
554
- console.log('â„šī¸ Reached maximum number of iterations. Getting final response...');
555
- const finalResponseObj = await callOpenRouterWithTools(messages);
556
- finalResponse = finalResponseObj.choices[0].message.content || 'No content in final response';
557
- }
558
-
559
- iteration++;
560
- } catch (error) {
527
+ ui.startThinking();
528
+
529
+ try {
530
+ const response = await callOpenRouterWithTools(messages);
531
+ const assistantMessage = response.choices[0].message;
532
+ messages.push(assistantMessage);
533
+
534
+ // If there are no tool calls, we're done
535
+ if (!assistantMessage.tool_calls || assistantMessage.tool_calls.length === 0) {
561
536
  ui.stopThinking();
562
- console.error('❌ Error during processing:', error);
563
- finalResponse = `An error occurred: ${error.message}`;
564
- break;
537
+ return {
538
+ response: assistantMessage.content || 'No content in response',
539
+ conversation: messages
540
+ };
565
541
  }
542
+
543
+ // Process tool calls
544
+ ui.stopThinking(); // Stop thinking while tools execute
545
+ console.log(`đŸ› ī¸ Executing ${assistantMessage.tool_calls.length} tools...`);
546
+ const toolResults = await handleToolCalls(assistantMessage.tool_calls, messages);
547
+
548
+ // Add tool results to messages
549
+ messages.push(...toolResults);
550
+
551
+ // Now, get the AI's response to the tool results
552
+ ui.startThinking();
553
+ const finalResponseObj = await callOpenRouterWithTools(messages);
554
+ const finalAssistantMessage = finalResponseObj.choices[0].message;
555
+ messages.push(finalAssistantMessage);
556
+ ui.stopThinking();
557
+
558
+ return {
559
+ response: finalAssistantMessage.content || 'Actions executed. What is the next step?',
560
+ conversation: messages
561
+ };
562
+
563
+ } catch (error) {
564
+ ui.stopThinking();
565
+ console.error('❌ Error during processing:', error);
566
+ return {
567
+ response: `An error occurred: ${error.message}`,
568
+ conversation: messages
569
+ };
566
570
  }
567
-
568
- // If we don't have a final response yet (shouldn't happen, but just in case)
569
- if (!finalResponse) {
570
- finalResponse = 'No response generated. The operation may have timed out or encountered an error.';
571
- }
572
-
573
- return {
574
- response: finalResponse,
575
- conversation: messages
576
- };
577
571
  }
578
572
 
579
573
  // Execute a single action from the action system
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {
7
- "sam-coder": "./bin/agi-cli.js"
7
+ "sam-coder": "bin/agi-cli.js"
8
8
  },
9
9
  "scripts": {
10
10
  "start": "node ./bin/agi-cli.js"