@strayl/agent 0.1.24 → 0.1.25

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/dist/agent.js +59 -3
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -13770,12 +13770,68 @@ ${IMPLEMENTATION_MODE_PROMPT2}`);
13770
13770
  emitter.emit({ type: "debug", message: `[LOOP] Tool calls: ${completedToolCalls.map((tc) => tc.function.name).join(", ")}` });
13771
13771
  hasUsedTools = true;
13772
13772
  nudgedToContinue = false;
13773
- for (const tc of completedToolCalls) {
13773
+ let tci = 0;
13774
+ while (tci < completedToolCalls.length) {
13774
13775
  if (stdin.isCancelled()) {
13775
- context.addToolResult(tc.id, tc.function.name, JSON.stringify({ error: "Cancelled by user." }));
13776
- emitter.emit({ type: "tool-result", id: tc.id, name: tc.function.name, output: "Cancelled by user.", error: "Cancelled by user." });
13776
+ for (let r = tci; r < completedToolCalls.length; r++) {
13777
+ const rem = completedToolCalls[r];
13778
+ context.addToolResult(rem.id, rem.function.name, JSON.stringify({ error: "Cancelled by user." }));
13779
+ emitter.emit({ type: "tool-result", id: rem.id, name: rem.function.name, output: "Cancelled by user.", error: "Cancelled by user." });
13780
+ }
13777
13781
  break;
13778
13782
  }
13783
+ if (completedToolCalls[tci].function.name === "task") {
13784
+ const taskBatch = [];
13785
+ while (tci < completedToolCalls.length && completedToolCalls[tci].function.name === "task") {
13786
+ taskBatch.push(completedToolCalls[tci]);
13787
+ tci++;
13788
+ }
13789
+ if (taskBatch.length === 1) {
13790
+ const tc2 = taskBatch[0];
13791
+ let parsedArgs2;
13792
+ try {
13793
+ parsedArgs2 = JSON.parse(tc2.function.arguments);
13794
+ } catch {
13795
+ parsedArgs2 = {};
13796
+ }
13797
+ const activity2 = toolToActivity(tc2.function.name, parsedArgs2);
13798
+ if (activity2) emitter.emit({ type: "activity", ...activity2 });
13799
+ emitter.emit({ type: "tool-call-start", id: tc2.id, name: tc2.function.name, args: parsedArgs2 });
13800
+ const toolCtx2 = { emitter, workDir: config.workDir, env: config.env, sessionId: config.sessionId, toolCallId: tc2.id };
13801
+ const modifiedTc2 = { ...tc2, function: { ...tc2.function, arguments: JSON.stringify(parsedArgs2) } };
13802
+ const result2 = await executeTool(registry, modifiedTc2, toolCtx2, middleware);
13803
+ emitter.emit({ type: "tool-result", id: tc2.id, name: tc2.function.name, output: result2 });
13804
+ context.addToolResult(tc2.id, tc2.function.name, result2);
13805
+ } else {
13806
+ emitter.emit({ type: "debug", message: `[PARALLEL] Spawning ${taskBatch.length} task calls in parallel` });
13807
+ const prepared = taskBatch.map((tc2) => {
13808
+ let parsedArgs2;
13809
+ try {
13810
+ parsedArgs2 = JSON.parse(tc2.function.arguments);
13811
+ } catch {
13812
+ parsedArgs2 = {};
13813
+ }
13814
+ const activity2 = toolToActivity(tc2.function.name, parsedArgs2);
13815
+ if (activity2) emitter.emit({ type: "activity", ...activity2 });
13816
+ emitter.emit({ type: "tool-call-start", id: tc2.id, name: tc2.function.name, args: parsedArgs2 });
13817
+ return { tc: tc2, parsedArgs: parsedArgs2 };
13818
+ });
13819
+ const results = await Promise.all(prepared.map(async ({ tc: tc2, parsedArgs: parsedArgs2 }) => {
13820
+ const toolCtx2 = { emitter, workDir: config.workDir, env: config.env, sessionId: config.sessionId, toolCallId: tc2.id };
13821
+ const modifiedTc2 = { ...tc2, function: { ...tc2.function, arguments: JSON.stringify(parsedArgs2) } };
13822
+ const result2 = await executeTool(registry, modifiedTc2, toolCtx2, middleware);
13823
+ return { tc: tc2, result: result2 };
13824
+ }));
13825
+ for (const { tc: tc2, result: result2 } of results) {
13826
+ emitter.emit({ type: "tool-result", id: tc2.id, name: tc2.function.name, output: result2 });
13827
+ context.addToolResult(tc2.id, tc2.function.name, result2);
13828
+ }
13829
+ emitter.emit({ type: "debug", message: `[PARALLEL] All ${taskBatch.length} tasks completed` });
13830
+ }
13831
+ continue;
13832
+ }
13833
+ const tc = completedToolCalls[tci];
13834
+ tci++;
13779
13835
  let parsedArgs;
13780
13836
  try {
13781
13837
  parsedArgs = JSON.parse(tc.function.arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strayl/agent",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"