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.cjs +111 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +111 -46
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15049,7 +15049,7 @@ var Usage = class {
|
|
|
15049
15049
|
};
|
|
15050
15050
|
|
|
15051
15051
|
// src/version.ts
|
|
15052
|
-
var SDK_VERSION = "1.
|
|
15052
|
+
var SDK_VERSION = "1.8.0";
|
|
15053
15053
|
|
|
15054
15054
|
// src/config.ts
|
|
15055
15055
|
var NetraInstruments = /* @__PURE__ */ ((NetraInstruments2) => {
|
|
@@ -26944,6 +26944,16 @@ var SimulationHttpClient = class {
|
|
|
26944
26944
|
}
|
|
26945
26945
|
/**
|
|
26946
26946
|
* Report a task execution failure to the backend.
|
|
26947
|
+
*
|
|
26948
|
+
* @param runId - Identifier of the run.
|
|
26949
|
+
* @param runItemId - Identifier of the run item.
|
|
26950
|
+
* @param error - Error message describing the failure.
|
|
26951
|
+
* @param status - The run status to set on the item. Use `"prescript_failed"`
|
|
26952
|
+
* when the failure originated from a beforeAll or before hook, or
|
|
26953
|
+
* `"postscript_failed"` when an after/afterEach/afterAll hook failed on an
|
|
26954
|
+
* otherwise successful item. Callers must not overwrite an existing real
|
|
26955
|
+
* failure (e.g. `failed` / `prescript_failed`) with `postscript_failed`.
|
|
26956
|
+
* Defaults to `"failed"`.
|
|
26947
26957
|
*/
|
|
26948
26958
|
async reportFailure(runId, runItemId, error, status = "failed") {
|
|
26949
26959
|
if (!this.client) {
|
|
@@ -27106,14 +27116,7 @@ async function runAfter(hooks, datasetItemId, itemResult, setupContext) {
|
|
|
27106
27116
|
Logger.info(
|
|
27107
27117
|
`${LOG_PREFIX6}: running after hook for datasetItemId=${datasetItemId}`
|
|
27108
27118
|
);
|
|
27109
|
-
|
|
27110
|
-
await hooks.after[datasetItemId](itemResult, setupContext);
|
|
27111
|
-
} catch (error) {
|
|
27112
|
-
Logger.warn(
|
|
27113
|
-
`${LOG_PREFIX6}: after hook raised an exception for datasetItemId=${datasetItemId} (ignored):`,
|
|
27114
|
-
error
|
|
27115
|
-
);
|
|
27116
|
-
}
|
|
27119
|
+
await hooks.after[datasetItemId](itemResult, setupContext);
|
|
27117
27120
|
}
|
|
27118
27121
|
}
|
|
27119
27122
|
async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
|
|
@@ -27121,26 +27124,12 @@ async function runAfterEach(hooks, datasetItemId, itemResult, setupContext) {
|
|
|
27121
27124
|
Logger.info(
|
|
27122
27125
|
`${LOG_PREFIX6}: running afterEach hook for datasetItemId=${datasetItemId}`
|
|
27123
27126
|
);
|
|
27124
|
-
|
|
27125
|
-
await hooks.afterEach(itemResult, setupContext);
|
|
27126
|
-
} catch (error) {
|
|
27127
|
-
Logger.warn(
|
|
27128
|
-
`${LOG_PREFIX6}: afterEach hook raised an exception for datasetItemId=${datasetItemId} (ignored):`,
|
|
27129
|
-
error
|
|
27130
|
-
);
|
|
27131
|
-
}
|
|
27127
|
+
await hooks.afterEach(itemResult, setupContext);
|
|
27132
27128
|
}
|
|
27133
27129
|
async function runAfterAll(hooks, results, sharedContext) {
|
|
27134
27130
|
if (!hooks?.afterAll) return;
|
|
27135
27131
|
Logger.info(`${LOG_PREFIX6}: running afterAll hook`);
|
|
27136
|
-
|
|
27137
|
-
await hooks.afterAll(results, sharedContext);
|
|
27138
|
-
} catch (error) {
|
|
27139
|
-
Logger.warn(
|
|
27140
|
-
`${LOG_PREFIX6}: afterAll hook raised an exception (ignored):`,
|
|
27141
|
-
error
|
|
27142
|
-
);
|
|
27143
|
-
}
|
|
27132
|
+
await hooks.afterAll(results, sharedContext);
|
|
27144
27133
|
}
|
|
27145
27134
|
|
|
27146
27135
|
// src/simulation/api.ts
|
|
@@ -27231,14 +27220,13 @@ var Simulation = class {
|
|
|
27231
27220
|
} catch (error) {
|
|
27232
27221
|
const errorMsg = `beforeAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
27233
27222
|
Logger.error(`${LOG_PREFIX7}: ${errorMsg} \u2014 aborting run (no LLM spent)`);
|
|
27234
|
-
|
|
27235
|
-
|
|
27236
|
-
|
|
27237
|
-
|
|
27238
|
-
|
|
27239
|
-
|
|
27240
|
-
|
|
27241
|
-
}
|
|
27223
|
+
await this._reportFailures(
|
|
27224
|
+
runId,
|
|
27225
|
+
items.map((item) => item.runItemId),
|
|
27226
|
+
errorMsg,
|
|
27227
|
+
"prescript_failed",
|
|
27228
|
+
maxConcurrency
|
|
27229
|
+
);
|
|
27242
27230
|
const results = {
|
|
27243
27231
|
success: false,
|
|
27244
27232
|
completed: [],
|
|
@@ -27249,7 +27237,12 @@ var Simulation = class {
|
|
|
27249
27237
|
})),
|
|
27250
27238
|
totalItems: items.length
|
|
27251
27239
|
};
|
|
27252
|
-
|
|
27240
|
+
try {
|
|
27241
|
+
await runAfterAll(hooks, results, null);
|
|
27242
|
+
} catch (afterAllError) {
|
|
27243
|
+
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
27244
|
+
Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
|
|
27245
|
+
}
|
|
27253
27246
|
await this._client.postRunStatus(runId, "completed");
|
|
27254
27247
|
return results;
|
|
27255
27248
|
}
|
|
@@ -27279,8 +27272,7 @@ var Simulation = class {
|
|
|
27279
27272
|
error: errorMsg
|
|
27280
27273
|
};
|
|
27281
27274
|
failedItems.push(itemResult);
|
|
27282
|
-
await
|
|
27283
|
-
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
27275
|
+
await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
|
|
27284
27276
|
return;
|
|
27285
27277
|
}
|
|
27286
27278
|
} else {
|
|
@@ -27296,8 +27288,7 @@ var Simulation = class {
|
|
|
27296
27288
|
error: "Failed to generate first user message"
|
|
27297
27289
|
};
|
|
27298
27290
|
failedItems.push(itemResult);
|
|
27299
|
-
await
|
|
27300
|
-
await runAfterEach(hooks, datasetItemId, itemResult, setupContexts.get(runItemId) ?? null);
|
|
27291
|
+
await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContexts.get(runItemId) ?? null);
|
|
27301
27292
|
return;
|
|
27302
27293
|
}
|
|
27303
27294
|
simulationItems.push(simItem);
|
|
@@ -27312,7 +27303,12 @@ var Simulation = class {
|
|
|
27312
27303
|
failed: failedItems,
|
|
27313
27304
|
totalItems: items.length
|
|
27314
27305
|
};
|
|
27315
|
-
|
|
27306
|
+
try {
|
|
27307
|
+
await runAfterAll(hooks, results, sharedContext);
|
|
27308
|
+
} catch (afterAllError) {
|
|
27309
|
+
const afterAllMsg = `afterAll hook failed: ${afterAllError instanceof Error ? afterAllError.message : String(afterAllError)}`;
|
|
27310
|
+
Logger.error(`${LOG_PREFIX7}: ${afterAllMsg}`);
|
|
27311
|
+
}
|
|
27316
27312
|
await this._client.postRunStatus(runId, "completed");
|
|
27317
27313
|
return results;
|
|
27318
27314
|
}
|
|
@@ -27382,12 +27378,84 @@ var Simulation = class {
|
|
|
27382
27378
|
);
|
|
27383
27379
|
await Promise.all(promises);
|
|
27384
27380
|
results.failed.push(...setupFailedItems);
|
|
27385
|
-
|
|
27381
|
+
try {
|
|
27382
|
+
await runAfterAll(hooks, results, sharedContext);
|
|
27383
|
+
} catch (error) {
|
|
27384
|
+
const errorMsg = `afterAll hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
27385
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg}`);
|
|
27386
|
+
const completed = results.completed;
|
|
27387
|
+
const successfulIds = completed.map((item) => item.runItemId);
|
|
27388
|
+
await this._reportFailures(
|
|
27389
|
+
runId,
|
|
27390
|
+
successfulIds,
|
|
27391
|
+
errorMsg,
|
|
27392
|
+
"postscript_failed",
|
|
27393
|
+
maxConcurrency
|
|
27394
|
+
);
|
|
27395
|
+
for (const item of completed) {
|
|
27396
|
+
item.success = false;
|
|
27397
|
+
item.error = errorMsg;
|
|
27398
|
+
item.status = "postscript_failed";
|
|
27399
|
+
}
|
|
27400
|
+
results.failed.push(...completed);
|
|
27401
|
+
results.completed = [];
|
|
27402
|
+
}
|
|
27403
|
+
results.success = results.failed.length === 0;
|
|
27386
27404
|
Logger.info(
|
|
27387
27405
|
`${LOG_PREFIX7}: Completed=${results.completed.length}, Failed=${results.failed.length}`
|
|
27388
27406
|
);
|
|
27389
27407
|
return results;
|
|
27390
27408
|
}
|
|
27409
|
+
/**
|
|
27410
|
+
* Report failures for many items concurrently, capped like other paths.
|
|
27411
|
+
*/
|
|
27412
|
+
async _reportFailures(runId, runItemIds, error, status, maxConcurrency = 5) {
|
|
27413
|
+
if (runItemIds.length === 0) {
|
|
27414
|
+
return;
|
|
27415
|
+
}
|
|
27416
|
+
const limit = pLimit2__default.default(Math.min(5, maxConcurrency));
|
|
27417
|
+
await Promise.all(
|
|
27418
|
+
runItemIds.map(
|
|
27419
|
+
(runItemId) => limit(() => this._client.reportFailure(runId, runItemId, error, status))
|
|
27420
|
+
)
|
|
27421
|
+
);
|
|
27422
|
+
}
|
|
27423
|
+
/**
|
|
27424
|
+
* Run after/afterEach hooks independently.
|
|
27425
|
+
*
|
|
27426
|
+
* Both hooks always attempt to run. `postscript_failed` is reported only
|
|
27427
|
+
* when the item otherwise succeeded — an existing failure status/reason is
|
|
27428
|
+
* never overwritten.
|
|
27429
|
+
*/
|
|
27430
|
+
async _runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext) {
|
|
27431
|
+
const errors = [];
|
|
27432
|
+
try {
|
|
27433
|
+
await runAfter(hooks, datasetItemId, itemResult, setupContext);
|
|
27434
|
+
} catch (error) {
|
|
27435
|
+
const errorMsg = `after hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
27436
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
|
|
27437
|
+
errors.push(errorMsg);
|
|
27438
|
+
}
|
|
27439
|
+
try {
|
|
27440
|
+
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
27441
|
+
} catch (error) {
|
|
27442
|
+
const errorMsg = `afterEach hook failed: ${error instanceof Error ? error.message : String(error)}`;
|
|
27443
|
+
Logger.error(`${LOG_PREFIX7}: ${errorMsg} for runItemId=${runItemId}`);
|
|
27444
|
+
errors.push(errorMsg);
|
|
27445
|
+
}
|
|
27446
|
+
if (errors.length > 0 && itemResult.success) {
|
|
27447
|
+
const error = errors.join("; ");
|
|
27448
|
+
await this._client.reportFailure(
|
|
27449
|
+
runId,
|
|
27450
|
+
runItemId,
|
|
27451
|
+
error,
|
|
27452
|
+
"postscript_failed"
|
|
27453
|
+
);
|
|
27454
|
+
itemResult.success = false;
|
|
27455
|
+
itemResult.error = error;
|
|
27456
|
+
itemResult.status = "postscript_failed";
|
|
27457
|
+
}
|
|
27458
|
+
}
|
|
27391
27459
|
/**
|
|
27392
27460
|
* Execute a multi-turn conversation for a single simulation item.
|
|
27393
27461
|
*
|
|
@@ -27427,8 +27495,7 @@ var Simulation = class {
|
|
|
27427
27495
|
error: "Failed to get conversation response",
|
|
27428
27496
|
turnId
|
|
27429
27497
|
};
|
|
27430
|
-
await
|
|
27431
|
-
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
27498
|
+
await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
|
|
27432
27499
|
return itemResult;
|
|
27433
27500
|
}
|
|
27434
27501
|
if (response.decision === "stop") {
|
|
@@ -27440,8 +27507,7 @@ var Simulation = class {
|
|
|
27440
27507
|
success: true,
|
|
27441
27508
|
finalTurnId: turnId
|
|
27442
27509
|
};
|
|
27443
|
-
await
|
|
27444
|
-
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
27510
|
+
await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
|
|
27445
27511
|
return itemResult;
|
|
27446
27512
|
}
|
|
27447
27513
|
message = response.nextUserMessage;
|
|
@@ -27459,8 +27525,7 @@ var Simulation = class {
|
|
|
27459
27525
|
error: errorMsg,
|
|
27460
27526
|
turnId
|
|
27461
27527
|
};
|
|
27462
|
-
await
|
|
27463
|
-
await runAfterEach(hooks, datasetItemId, itemResult, setupContext);
|
|
27528
|
+
await this._runAfterHooks(runId, runItemId, datasetItemId, hooks, itemResult, setupContext);
|
|
27464
27529
|
return itemResult;
|
|
27465
27530
|
} finally {
|
|
27466
27531
|
span2.end();
|