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.
package/dist/index.d.cts CHANGED
@@ -1261,6 +1261,8 @@ declare class StreamProcessor {
1261
1261
  private completedResults;
1262
1262
  /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
1263
1263
  private failedInvocations;
1264
+ /** Promises for independent gadgets currently executing (fire-and-forget) */
1265
+ private inFlightExecutions;
1264
1266
  constructor(options: StreamProcessorOptions);
1265
1267
  /**
1266
1268
  * Process an LLM stream and yield events in real-time.
@@ -1313,6 +1315,18 @@ declare class StreamProcessor {
1313
1315
  * Generator version that yields gadget_result immediately when execution completes.
1314
1316
  */
1315
1317
  private executeGadgetGenerator;
1318
+ /**
1319
+ * Execute a gadget and collect all events into an array (non-blocking).
1320
+ * Used for fire-and-forget parallel execution of independent gadgets.
1321
+ */
1322
+ private executeGadgetAndCollect;
1323
+ /**
1324
+ * Collect results from all fire-and-forget (in-flight) gadget executions.
1325
+ * Called at stream end to await parallel independent gadgets.
1326
+ * Clears the inFlightExecutions map after collection.
1327
+ * @returns Array of all events from completed gadgets
1328
+ */
1329
+ private collectInFlightResults;
1316
1330
  /**
1317
1331
  * Handle a gadget that cannot execute because a dependency failed.
1318
1332
  * Calls the onDependencySkipped controller to allow customization.
package/dist/index.d.ts CHANGED
@@ -1261,6 +1261,8 @@ declare class StreamProcessor {
1261
1261
  private completedResults;
1262
1262
  /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
1263
1263
  private failedInvocations;
1264
+ /** Promises for independent gadgets currently executing (fire-and-forget) */
1265
+ private inFlightExecutions;
1264
1266
  constructor(options: StreamProcessorOptions);
1265
1267
  /**
1266
1268
  * Process an LLM stream and yield events in real-time.
@@ -1313,6 +1315,18 @@ declare class StreamProcessor {
1313
1315
  * Generator version that yields gadget_result immediately when execution completes.
1314
1316
  */
1315
1317
  private executeGadgetGenerator;
1318
+ /**
1319
+ * Execute a gadget and collect all events into an array (non-blocking).
1320
+ * Used for fire-and-forget parallel execution of independent gadgets.
1321
+ */
1322
+ private executeGadgetAndCollect;
1323
+ /**
1324
+ * Collect results from all fire-and-forget (in-flight) gadget executions.
1325
+ * Called at stream end to await parallel independent gadgets.
1326
+ * Clears the inFlightExecutions map after collection.
1327
+ * @returns Array of all events from completed gadgets
1328
+ */
1329
+ private collectInFlightResults;
1316
1330
  /**
1317
1331
  * Handle a gadget that cannot execute because a dependency failed.
1318
1332
  * Calls the onDependencySkipped controller to allow customization.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  resultWithImages,
12
12
  resultWithMedia,
13
13
  z
14
- } from "./chunk-UBPZUVIN.js";
14
+ } from "./chunk-F62X5W2G.js";
15
15
  import {
16
16
  AbortException,
17
17
  AbstractGadget,
@@ -89,7 +89,7 @@ import {
89
89
  toBase64,
90
90
  validateAndApplyDefaults,
91
91
  validateGadgetParams
92
- } from "./chunk-3SZIQI45.js";
92
+ } from "./chunk-EIE5VRSI.js";
93
93
  export {
94
94
  AbortException,
95
95
  AbstractGadget,
@@ -3859,6 +3859,8 @@ var init_stream_processor = __esm({
3859
3859
  completedResults = /* @__PURE__ */ new Map();
3860
3860
  /** Invocation IDs of gadgets that have failed (error or skipped due to dependency) */
3861
3861
  failedInvocations = /* @__PURE__ */ new Set();
3862
+ /** Promises for independent gadgets currently executing (fire-and-forget) */
3863
+ inFlightExecutions = /* @__PURE__ */ new Map();
3862
3864
  constructor(options) {
3863
3865
  this.iteration = options.iteration;
3864
3866
  this.registry = options.registry;
@@ -3967,6 +3969,16 @@ var init_stream_processor = __esm({
3967
3969
  }
3968
3970
  }
3969
3971
  }
3972
+ const inFlightResults = await this.collectInFlightResults();
3973
+ for (const evt of inFlightResults) {
3974
+ yield evt;
3975
+ if (evt.type === "gadget_result") {
3976
+ didExecuteGadgets = true;
3977
+ if (evt.result.breaksLoop) {
3978
+ shouldBreakLoop = true;
3979
+ }
3980
+ }
3981
+ }
3970
3982
  for await (const evt of this.processPendingGadgetsGenerator()) {
3971
3983
  yield evt;
3972
3984
  if (evt.type === "gadget_result") {
@@ -4152,12 +4164,24 @@ var init_stream_processor = __esm({
4152
4164
  this.gadgetsAwaitingDependencies.set(call.invocationId, call);
4153
4165
  return;
4154
4166
  }
4167
+ for await (const evt of this.executeGadgetGenerator(call)) {
4168
+ yield evt;
4169
+ }
4170
+ for await (const evt of this.processPendingGadgetsGenerator()) {
4171
+ yield evt;
4172
+ }
4173
+ return;
4155
4174
  }
4156
- for await (const evt of this.executeGadgetGenerator(call)) {
4157
- yield evt;
4158
- }
4159
- for await (const evt of this.processPendingGadgetsGenerator()) {
4160
- yield evt;
4175
+ if (this.stopOnGadgetError) {
4176
+ for await (const evt of this.executeGadgetGenerator(call)) {
4177
+ yield evt;
4178
+ }
4179
+ for await (const evt of this.processPendingGadgetsGenerator()) {
4180
+ yield evt;
4181
+ }
4182
+ } else {
4183
+ const executionPromise = this.executeGadgetAndCollect(call);
4184
+ this.inFlightExecutions.set(call.invocationId, executionPromise);
4161
4185
  }
4162
4186
  }
4163
4187
  /**
@@ -4469,6 +4493,36 @@ var init_stream_processor = __esm({
4469
4493
  }
4470
4494
  }
4471
4495
  }
4496
+ /**
4497
+ * Execute a gadget and collect all events into an array (non-blocking).
4498
+ * Used for fire-and-forget parallel execution of independent gadgets.
4499
+ */
4500
+ async executeGadgetAndCollect(call) {
4501
+ const events = [];
4502
+ for await (const evt of this.executeGadgetGenerator(call)) {
4503
+ events.push(evt);
4504
+ }
4505
+ return events;
4506
+ }
4507
+ /**
4508
+ * Collect results from all fire-and-forget (in-flight) gadget executions.
4509
+ * Called at stream end to await parallel independent gadgets.
4510
+ * Clears the inFlightExecutions map after collection.
4511
+ * @returns Array of all events from completed gadgets
4512
+ */
4513
+ async collectInFlightResults() {
4514
+ if (this.inFlightExecutions.size === 0) {
4515
+ return [];
4516
+ }
4517
+ this.logger.debug("Collecting in-flight gadget results", {
4518
+ count: this.inFlightExecutions.size,
4519
+ invocationIds: Array.from(this.inFlightExecutions.keys())
4520
+ });
4521
+ const promises = Array.from(this.inFlightExecutions.values());
4522
+ const results = await Promise.all(promises);
4523
+ this.inFlightExecutions.clear();
4524
+ return results.flat();
4525
+ }
4472
4526
  /**
4473
4527
  * Handle a gadget that cannot execute because a dependency failed.
4474
4528
  * Calls the onDependencySkipped controller to allow customization.
@@ -6194,13 +6248,24 @@ ${endPrefix}`
6194
6248
  observers: {
6195
6249
  ...hooks?.observers,
6196
6250
  onLLMCallStart: async (context) => {
6251
+ let inputTokens;
6252
+ try {
6253
+ if (this.client) {
6254
+ inputTokens = await this.client.countTokens(
6255
+ context.options.model,
6256
+ context.options.messages
6257
+ );
6258
+ }
6259
+ } catch {
6260
+ }
6197
6261
  onSubagentEvent({
6198
6262
  type: "llm_call_start",
6199
6263
  gadgetInvocationId: invocationId,
6200
6264
  depth,
6201
6265
  event: {
6202
6266
  iteration: context.iteration,
6203
- model: context.options.model
6267
+ model: context.options.model,
6268
+ inputTokens
6204
6269
  }
6205
6270
  });
6206
6271
  if (existingOnLLMCallStart) {