netra-sdk 1.7.0 → 1.8.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
@@ -80,7 +80,7 @@ declare const DEFAULT_INSTRUMENTS: Set<NetraInstruments>;
80
80
  declare class Config {
81
81
  static readonly SDK_NAME = "netra";
82
82
  static readonly LIBRARY_NAME = "netra";
83
- static readonly LIBRARY_VERSION = "1.6.0";
83
+ static readonly LIBRARY_VERSION = "1.8.0";
84
84
  static readonly TRIAL_BLOCK_DURATION_SECONDS = 900;
85
85
  private static _spanAttributeMaxSize;
86
86
  /**
@@ -1101,7 +1101,11 @@ type SpanCallback<T> = (span: SpanWrapper) => T;
1101
1101
  * - beforeAll failure -> entire run is marked failed (prescript_failed), no scenarios run
1102
1102
  * - beforeEach failure -> that scenario is marked failed (prescript_failed), others continue
1103
1103
  * - before failure -> that scenario is marked failed (prescript_failed), others continue
1104
- * - after / afterEach / afterAll failures are logged as warnings and do not affect run/scenario status
1104
+ * - after / afterEach -> both always attempt to run; if the scenario otherwise
1105
+ * succeeded it is marked postscript_failed, otherwise the
1106
+ * existing failure status/reason is preserved
1107
+ * - afterAll failure -> successfully completed scenarios are marked
1108
+ * postscript_failed; already-failed scenarios keep their status
1105
1109
  */
1106
1110
  /** Hook that runs once before any scenario starts. May return shared context. */
1107
1111
  type BeforeAllFn = () => Record<string, any> | null | void | Promise<Record<string, any> | null | void>;
@@ -1197,6 +1201,7 @@ interface ConversationResult {
1197
1201
  runItemId: string;
1198
1202
  success: boolean;
1199
1203
  error?: string;
1204
+ status?: string;
1200
1205
  finalTurnId?: string;
1201
1206
  turnId?: string;
1202
1207
  }
@@ -1265,6 +1270,18 @@ declare class Simulation {
1265
1270
  * Orchestrate concurrent simulation execution with hooks support.
1266
1271
  */
1267
1272
  private _runSimulationAsync;
1273
+ /**
1274
+ * Report failures for many items concurrently, capped like other paths.
1275
+ */
1276
+ private _reportFailures;
1277
+ /**
1278
+ * Run after/afterEach hooks independently.
1279
+ *
1280
+ * Both hooks always attempt to run. `postscript_failed` is reported only
1281
+ * when the item otherwise succeeded — an existing failure status/reason is
1282
+ * never overwritten.
1283
+ */
1284
+ private _runAfterHooks;
1268
1285
  /**
1269
1286
  * Execute a multi-turn conversation for a single simulation item.
1270
1287
  *
package/dist/index.d.ts CHANGED
@@ -80,7 +80,7 @@ declare const DEFAULT_INSTRUMENTS: Set<NetraInstruments>;
80
80
  declare class Config {
81
81
  static readonly SDK_NAME = "netra";
82
82
  static readonly LIBRARY_NAME = "netra";
83
- static readonly LIBRARY_VERSION = "1.6.0";
83
+ static readonly LIBRARY_VERSION = "1.8.0";
84
84
  static readonly TRIAL_BLOCK_DURATION_SECONDS = 900;
85
85
  private static _spanAttributeMaxSize;
86
86
  /**
@@ -1101,7 +1101,11 @@ type SpanCallback<T> = (span: SpanWrapper) => T;
1101
1101
  * - beforeAll failure -> entire run is marked failed (prescript_failed), no scenarios run
1102
1102
  * - beforeEach failure -> that scenario is marked failed (prescript_failed), others continue
1103
1103
  * - before failure -> that scenario is marked failed (prescript_failed), others continue
1104
- * - after / afterEach / afterAll failures are logged as warnings and do not affect run/scenario status
1104
+ * - after / afterEach -> both always attempt to run; if the scenario otherwise
1105
+ * succeeded it is marked postscript_failed, otherwise the
1106
+ * existing failure status/reason is preserved
1107
+ * - afterAll failure -> successfully completed scenarios are marked
1108
+ * postscript_failed; already-failed scenarios keep their status
1105
1109
  */
1106
1110
  /** Hook that runs once before any scenario starts. May return shared context. */
1107
1111
  type BeforeAllFn = () => Record<string, any> | null | void | Promise<Record<string, any> | null | void>;
@@ -1197,6 +1201,7 @@ interface ConversationResult {
1197
1201
  runItemId: string;
1198
1202
  success: boolean;
1199
1203
  error?: string;
1204
+ status?: string;
1200
1205
  finalTurnId?: string;
1201
1206
  turnId?: string;
1202
1207
  }
@@ -1265,6 +1270,18 @@ declare class Simulation {
1265
1270
  * Orchestrate concurrent simulation execution with hooks support.
1266
1271
  */
1267
1272
  private _runSimulationAsync;
1273
+ /**
1274
+ * Report failures for many items concurrently, capped like other paths.
1275
+ */
1276
+ private _reportFailures;
1277
+ /**
1278
+ * Run after/afterEach hooks independently.
1279
+ *
1280
+ * Both hooks always attempt to run. `postscript_failed` is reported only
1281
+ * when the item otherwise succeeded — an existing failure status/reason is
1282
+ * never overwritten.
1283
+ */
1284
+ private _runAfterHooks;
1268
1285
  /**
1269
1286
  * Execute a multi-turn conversation for a single simulation item.
1270
1287
  *
package/dist/index.js CHANGED
@@ -579,7 +579,7 @@ var Usage = class {
579
579
  };
580
580
 
581
581
  // src/version.ts
582
- var SDK_VERSION = "1.6.0";
582
+ var SDK_VERSION = "1.8.0";
583
583
 
584
584
  // src/config.ts
585
585
  var NetraInstruments = /* @__PURE__ */ ((NetraInstruments2) => {
@@ -12474,6 +12474,16 @@ var SimulationHttpClient = class {
12474
12474
  }
12475
12475
  /**
12476
12476
  * Report a task execution failure to the backend.
12477
+ *
12478
+ * @param runId - Identifier of the run.
12479
+ * @param runItemId - Identifier of the run item.
12480
+ * @param error - Error message describing the failure.
12481
+ * @param status - The run status to set on the item. Use `"prescript_failed"`
12482
+ * when the failure originated from a beforeAll or before hook, or
12483
+ * `"postscript_failed"` when an after/afterEach/afterAll hook failed on an
12484
+ * otherwise successful item. Callers must not overwrite an existing real
12485
+ * failure (e.g. `failed` / `prescript_failed`) with `postscript_failed`.
12486
+ * Defaults to `"failed"`.
12477
12487
  */
12478
12488
  async reportFailure(runId, runItemId, error, status = "failed") {
12479
12489
  if (!this.client) {
@@ -12636,14 +12646,7 @@ async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
12636
12646
  Logger.info(
12637
12647
  `${LOG_PREFIX6}: running after hook for datasetItemId=${datasetItemId}`
12638
12648
  );
12639
- try {
12640
- await hooks.after[datasetItemId](itemResult, setupContext);
12641
- } catch (error) {
12642
- Logger.warn(
12643
- `${LOG_PREFIX6}: after hook raised an exception for datasetItemId=${datasetItemId} (ignored):`,
12644
- error
12645
- );
12646
- }
12649
+ await hooks.after[datasetItemId](itemResult, setupContext);
12647
12650
  }
12648
12651
  }
12649
12652
  async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
@@ -12651,26 +12654,12 @@ async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
12651
12654
  Logger.info(
12652
12655
  `${LOG_PREFIX6}: running afterEach hook for datasetItemId=${datasetItemId}`
12653
12656
  );
12654
- try {
12655
- await hooks.afterEach(itemResult, setupContext);
12656
- } catch (error) {
12657
- Logger.warn(
12658
- `${LOG_PREFIX6}: afterEach hook raised an exception for datasetItemId=${datasetItemId} (ignored):`,
12659
- error
12660
- );
12661
- }
12657
+ await hooks.afterEach(itemResult, setupContext);
12662
12658
  }
12663
12659
  async function runAfterAll(hooks, results, sharedContext) {
12664
12660
  if (!hooks?.afterAll) return;
12665
12661
  Logger.info(`${LOG_PREFIX6}: running afterAll hook`);
12666
- try {
12667
- await hooks.afterAll(results, sharedContext);
12668
- } catch (error) {
12669
- Logger.warn(
12670
- `${LOG_PREFIX6}: afterAll hook raised an exception (ignored):`,
12671
- error
12672
- );
12673
- }
12662
+ await hooks.afterAll(results, sharedContext);
12674
12663
  }
12675
12664
 
12676
12665
  // src/simulation/api.ts
@@ -12761,14 +12750,13 @@ var Simulation = class {
12761
12750
  } catch (error) {
12762
12751
  const errorMsg = `beforeAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
12763
12752
  Logger.error(`${LOG_PREFIX7}: ${errorMsg} \u2014 aborting run (no LLM spent)`);
12764
- for (const item of items) {
12765
- await this._client.reportFailure(
12766
- runId,
12767
- item.runItemId,
12768
- errorMsg,
12769
- "prescript_failed"
12770
- );
12771
- }
12753
+ await this._reportFailures(
12754
+ runId,
12755
+ items.map((item) => item.runItemId),
12756
+ errorMsg,
12757
+ "prescript_failed",
12758
+ maxConcurrency
12759
+ );
12772
12760
  const results = {
12773
12761
  success: false,
12774
12762
  completed: [],
@@ -12779,7 +12767,12 @@ var Simulation = class {
12779
12767
  })),
12780
12768
  totalItems: items.length
12781
12769
  };
12782
- await runAfterAll(hooks, results, null);
12770
+ try {
12771
+ await runAfterAll(hooks, results, null);
12772
+ } catch (afterAllError) {
12773
+ const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
12774
+ Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
12775
+ }
12783
12776
  await this._client.postRunStatus(runId, "completed");
12784
12777
  return results;
12785
12778
  }
@@ -12809,8 +12802,7 @@ var Simulation = class {
12809
12802
  error: errorMsg
12810
12803
  };
12811
12804
  failedItems.push(itemResult);
12812
- await runAfter(hooks, datasetItemId, itemResult, setupContext);
12813
- await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
12805
+ await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
12814
12806
  return;
12815
12807
  }
12816
12808
  } else {
@@ -12826,8 +12818,7 @@ var Simulation = class {
12826
12818
  error: "Failed to generate first user message"
12827
12819
  };
12828
12820
  failedItems.push(itemResult);
12829
- await runAfter(hooks, datasetItemId, itemResult, setupContexts.get(runItemId) ?? null);
12830
- await runAfterEach(hooks, datasetItemId, itemResult, setupContexts.get(runItemId) ?? null);
12821
+ await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContexts.get(runItemId) ?? null);
12831
12822
  return;
12832
12823
  }
12833
12824
  simulationItems.push(simItem);
@@ -12842,7 +12833,12 @@ var Simulation = class {
12842
12833
  failed: failedItems,
12843
12834
  totalItems: items.length
12844
12835
  };
12845
- await runAfterAll(hooks, results, sharedContext);
12836
+ try {
12837
+ await runAfterAll(hooks, results, sharedContext);
12838
+ } catch (afterAllError) {
12839
+ const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
12840
+ Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
12841
+ }
12846
12842
  await this._client.postRunStatus(runId, "completed");
12847
12843
  return results;
12848
12844
  }
@@ -12912,12 +12908,84 @@ var Simulation = class {
12912
12908
  );
12913
12909
  await Promise.all(promises);
12914
12910
  results.failed.push(...setupFailedItems);
12915
- await runAfterAll(hooks, results, sharedContext);
12911
+ try {
12912
+ await runAfterAll(hooks, results, sharedContext);
12913
+ } catch (error) {
12914
+ const errorMsg = `afterAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
12915
+ Logger.error(`${LOG_PREFIX7}: ${errorMsg}`);
12916
+ const completed = results.completed;
12917
+ const successfulIds = completed.map((item) => item.runItemId);
12918
+ await this._reportFailures(
12919
+ runId,
12920
+ successfulIds,
12921
+ errorMsg,
12922
+ "postscript_failed",
12923
+ maxConcurrency
12924
+ );
12925
+ for (const item of completed) {
12926
+ item.success = false;
12927
+ item.error = errorMsg;
12928
+ item.status = "postscript_failed";
12929
+ }
12930
+ results.failed.push(...completed);
12931
+ results.completed = [];
12932
+ }
12933
+ results.success = results.failed.length === 0;
12916
12934
  Logger.info(
12917
12935
  `${LOG_PREFIX7}: Completed=${results.completed.length}, Failed=${results.failed.length}`
12918
12936
  );
12919
12937
  return results;
12920
12938
  }
12939
+ /**
12940
+ * Report failures for many items concurrently, capped like other paths.
12941
+ */
12942
+ async _reportFailures(runId, runItemIds, error, status, maxConcurrency = 5) {
12943
+ if (runItemIds.length === 0) {
12944
+ return;
12945
+ }
12946
+ const limit = pLimit2(Math.min(5, maxConcurrency));
12947
+ await Promise.all(
12948
+ runItemIds.map(
12949
+ (runItemId) => limit(() => this._client.reportFailure(runId, runItemId, error, status))
12950
+ )
12951
+ );
12952
+ }
12953
+ /**
12954
+ * Run after/afterEach hooks independently.
12955
+ *
12956
+ * Both hooks always attempt to run. `postscript_failed` is reported only
12957
+ * when the item otherwise succeeded — an existing failure status/reason is
12958
+ * never overwritten.
12959
+ */
12960
+ async _runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext) {
12961
+ const errors = [];
12962
+ try {
12963
+ await runAfter(hooks, datasetItemId, itemResult, setupContext);
12964
+ } catch (error) {
12965
+ const errorMsg = `after hook failed: ${error instanceof Error ? error.message : String(error)}`;
12966
+ Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
12967
+ errors.push(errorMsg);
12968
+ }
12969
+ try {
12970
+ await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
12971
+ } catch (error) {
12972
+ const errorMsg = `afterEach hook failed: ${error instanceof Error ? error.message : String(error)}`;
12973
+ Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
12974
+ errors.push(errorMsg);
12975
+ }
12976
+ if (errors.length > 0 && itemResult.success) {
12977
+ const error = errors.join("; ");
12978
+ await this._client.reportFailure(
12979
+ runId,
12980
+ runItemId,
12981
+ error,
12982
+ "postscript_failed"
12983
+ );
12984
+ itemResult.success = false;
12985
+ itemResult.error = error;
12986
+ itemResult.status = "postscript_failed";
12987
+ }
12988
+ }
12921
12989
  /**
12922
12990
  * Execute a multi-turn conversation for a single simulation item.
12923
12991
  *
@@ -12957,8 +13025,7 @@ var Simulation = class {
12957
13025
  error: "Failed to get conversation response",
12958
13026
  turnId
12959
13027
  };
12960
- await runAfter(hooks, datasetItemId, itemResult, setupContext);
12961
- await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
13028
+ await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
12962
13029
  return itemResult;
12963
13030
  }
12964
13031
  if (response.decision === "stop") {
@@ -12970,8 +13037,7 @@ var Simulation = class {
12970
13037
  success: true,
12971
13038
  finalTurnId: turnId
12972
13039
  };
12973
- await runAfter(hooks, datasetItemId, itemResult, setupContext);
12974
- await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
13040
+ await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
12975
13041
  return itemResult;
12976
13042
  }
12977
13043
  message = response.nextUserMessage;
@@ -12989,8 +13055,7 @@ var Simulation = class {
12989
13055
  error: errorMsg,
12990
13056
  turnId
12991
13057
  };
12992
- await runAfter(hooks, datasetItemId, itemResult, setupContext);
12993
- await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
13058
+ await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
12994
13059
  return itemResult;
12995
13060
  } finally {
12996
13061
  span2.end();