llmist 5.0.0 → 6.0.0

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.
@@ -3923,6 +3923,8 @@ var init_stream_processor = __esm({
3923
3923
  completedResults = /* @__PURE__ */ new Map();
3924
3924
  /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
3925
3925
  failedInvocations = /* @__PURE__ */ new Set();
3926
+ /** Promises for independent gadgets currently executing (fire-and-forget) */
3927
+ inFlightExecutions = /* @__PURE__ */ new Map();
3926
3928
  constructor(options) {
3927
3929
  this.iteration = options.iteration;
3928
3930
  this.registry = options.registry;
@@ -4031,6 +4033,16 @@ var init_stream_processor = __esm({
4031
4033
  }
4032
4034
  }
4033
4035
  }
4036
+ const inFlightResults = await this.collectInFlightResults();
4037
+ for (const evt of inFlightResults) {
4038
+ yield evt;
4039
+ if (evt.type === "gadget_result") {
4040
+ didExecuteGadgets = true;
4041
+ if (evt.result.breaksLoop) {
4042
+ shouldBreakLoop = true;
4043
+ }
4044
+ }
4045
+ }
4034
4046
  for await (const evt of this.processPendingGadgetsGenerator()) {
4035
4047
  yield evt;
4036
4048
  if (evt.type === "gadget_result") {
@@ -4216,12 +4228,24 @@ var init_stream_processor = __esm({
4216
4228
  this.gadgetsAwaitingDependencies.set(call.invocationId, call);
4217
4229
  return;
4218
4230
  }
4231
+ for await (const evt of this.executeGadgetGenerator(call)) {
4232
+ yield evt;
4233
+ }
4234
+ for await (const evt of this.processPendingGadgetsGenerator()) {
4235
+ yield evt;
4236
+ }
4237
+ return;
4219
4238
  }
4220
- for await (const evt of this.executeGadgetGenerator(call)) {
4221
- yield evt;
4222
- }
4223
- for await (const evt of this.processPendingGadgetsGenerator()) {
4224
- yield evt;
4239
+ if (this.stopOnGadgetError) {
4240
+ for await (const evt of this.executeGadgetGenerator(call)) {
4241
+ yield evt;
4242
+ }
4243
+ for await (const evt of this.processPendingGadgetsGenerator()) {
4244
+ yield evt;
4245
+ }
4246
+ } else {
4247
+ const executionPromise = this.executeGadgetAndCollect(call);
4248
+ this.inFlightExecutions.set(call.invocationId, executionPromise);
4225
4249
  }
4226
4250
  }
4227
4251
  /**
@@ -4533,6 +4557,36 @@ var init_stream_processor = __esm({
4533
4557
  }
4534
4558
  }
4535
4559
  }
4560
+ /**
4561
+ * Execute a gadget and collect all events into an array (non-blocking).
4562
+ * Used for fire-and-forget parallel execution of independent gadgets.
4563
+ */
4564
+ async executeGadgetAndCollect(call) {
4565
+ const events = [];
4566
+ for await (const evt of this.executeGadgetGenerator(call)) {
4567
+ events.push(evt);
4568
+ }
4569
+ return events;
4570
+ }
4571
+ /**
4572
+ * Collect results from all fire-and-forget (in-flight) gadget executions.
4573
+ * Called at stream end to await parallel independent gadgets.
4574
+ * Clears the inFlightExecutions map after collection.
4575
+ * @returns Array of all events from completed gadgets
4576
+ */
4577
+ async collectInFlightResults() {
4578
+ if (this.inFlightExecutions.size === 0) {
4579
+ return [];
4580
+ }
4581
+ this.logger.debug("Collecting in-flight gadget results", {
4582
+ count: this.inFlightExecutions.size,
4583
+ invocationIds: Array.from(this.inFlightExecutions.keys())
4584
+ });
4585
+ const promises = Array.from(this.inFlightExecutions.values());
4586
+ const results = await Promise.all(promises);
4587
+ this.inFlightExecutions.clear();
4588
+ return results.flat();
4589
+ }
4536
4590
  /**
4537
4591
  * Handle a gadget that cannot execute because a dependency failed.
4538
4592
  * Calls the onDependencySkipped controller to allow customization.
@@ -6258,13 +6312,24 @@ ${endPrefix}`
6258
6312
  observers: {
6259
6313
  ...hooks?.observers,
6260
6314
  onLLMCallStart: async (context) => {
6315
+ let inputTokens;
6316
+ try {
6317
+ if (this.client) {
6318
+ inputTokens = await this.client.countTokens(
6319
+ context.options.model,
6320
+ context.options.messages
6321
+ );
6322
+ }
6323
+ } catch {
6324
+ }
6261
6325
  onSubagentEvent({
6262
6326
  type: "llm_call_start",
6263
6327
  gadgetInvocationId: invocationId,
6264
6328
  depth,
6265
6329
  event: {
6266
6330
  iteration: context.iteration,
6267
- model: context.options.model
6331
+ model: context.options.model,
6332
+ inputTokens
6268
6333
  }
6269
6334
  });
6270
6335
  if (existingOnLLMCallStart) {
@@ -11707,4 +11772,4 @@ export {
11707
11772
  createEmptyStream,
11708
11773
  createErrorStream
11709
11774
  };
11710
- //# sourceMappingURL=chunk-3SZIQI45.js.map
11775
+ //# sourceMappingURL=chunk-EIE5VRSI.js.map