orchestrated 0.1.30 → 0.1.32
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/index.d.ts +2 -0
- package/index.js +115 -31
- package/index.js.map +7 -7
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -815,6 +815,7 @@ declare const InteractionsDatasetOptionsSchema: z.ZodObject<{
|
|
|
815
815
|
month: z.ZodOptional<z.ZodString>;
|
|
816
816
|
startDate: z.ZodOptional<z.ZodString>;
|
|
817
817
|
endDate: z.ZodOptional<z.ZodString>;
|
|
818
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
818
819
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
819
820
|
}, z.core.$strip>;
|
|
820
821
|
|
|
@@ -1287,6 +1288,7 @@ declare const SessionsDatasetOptionsSchema: z.ZodObject<{
|
|
|
1287
1288
|
month: z.ZodOptional<z.ZodString>;
|
|
1288
1289
|
startDate: z.ZodOptional<z.ZodString>;
|
|
1289
1290
|
endDate: z.ZodOptional<z.ZodString>;
|
|
1291
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
1290
1292
|
timeout: z.ZodOptional<z.ZodNumber>;
|
|
1291
1293
|
}, z.core.$strip>;
|
|
1292
1294
|
|
package/index.js
CHANGED
|
@@ -21230,6 +21230,7 @@ function resetState() {
|
|
|
21230
21230
|
globalState = null;
|
|
21231
21231
|
isInitialized = false;
|
|
21232
21232
|
globalThis.__ORCHESTRATED_LAZY_LOAD__ = undefined;
|
|
21233
|
+
if (false) {}
|
|
21233
21234
|
}
|
|
21234
21235
|
function isStateInitialized() {
|
|
21235
21236
|
return isInitialized || globalThis.__ORCHESTRATED_SHARED_STATE__ !== undefined;
|
|
@@ -58802,6 +58803,9 @@ async function getDataset(datasetName, source, options) {
|
|
|
58802
58803
|
const timeout = options.timeout ?? 30000;
|
|
58803
58804
|
const allResults = [];
|
|
58804
58805
|
let cursor;
|
|
58806
|
+
let latestHasMore = false;
|
|
58807
|
+
let latestLastEvalTimestamp = null;
|
|
58808
|
+
const hasExplicitLimit = typeof options.limit === "number" && options.limit > 0;
|
|
58805
58809
|
do {
|
|
58806
58810
|
const controller = new AbortController;
|
|
58807
58811
|
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
@@ -58835,7 +58839,10 @@ async function getDataset(datasetName, source, options) {
|
|
|
58835
58839
|
const rawData = await response.json();
|
|
58836
58840
|
const data = DatasetResponseSchema.parse(rawData);
|
|
58837
58841
|
allResults.push(...data.data);
|
|
58838
|
-
cursor = data.nextCursor;
|
|
58842
|
+
cursor = hasExplicitLimit ? undefined : data.nextCursor;
|
|
58843
|
+
latestHasMore = data.hasMore ?? Boolean(data.nextCursor);
|
|
58844
|
+
latestLastEvalTimestamp = data.lastEvalTimestamp ?? null;
|
|
58845
|
+
console.log(`[dataset:${datasetName}] page fetched: pageCount=${data.data.length}, runningTotal=${allResults.length}, hasMore=${latestHasMore}, lastEvalTimestamp=${latestLastEvalTimestamp}`);
|
|
58839
58846
|
} catch (error48) {
|
|
58840
58847
|
clearTimeout(timeoutId);
|
|
58841
58848
|
if (error48 instanceof Error && error48.name === "AbortError") {
|
|
@@ -58844,11 +58851,18 @@ async function getDataset(datasetName, source, options) {
|
|
|
58844
58851
|
throw error48;
|
|
58845
58852
|
}
|
|
58846
58853
|
} while (cursor);
|
|
58854
|
+
globalThis[DATASET_METADATA_KEY] = {
|
|
58855
|
+
datasetName,
|
|
58856
|
+
count: allResults.length,
|
|
58857
|
+
hasMore: latestHasMore,
|
|
58858
|
+
lastEvalTimestamp: latestLastEvalTimestamp
|
|
58859
|
+
};
|
|
58860
|
+
console.log(`[dataset:${datasetName}] pull complete: total=${allResults.length}, hasMore=${latestHasMore}, lastEvalTimestamp=${latestLastEvalTimestamp}`);
|
|
58847
58861
|
return allResults;
|
|
58848
58862
|
}
|
|
58849
58863
|
var getApiUrl = () => {
|
|
58850
58864
|
return getState().apiUrl;
|
|
58851
|
-
}, DatasetResponseSchema;
|
|
58865
|
+
}, DatasetResponseSchema, DATASET_METADATA_KEY = "__ORCHESTRATED_DATASET_METADATA__";
|
|
58852
58866
|
var init_data_source = __esm(() => {
|
|
58853
58867
|
init_zod();
|
|
58854
58868
|
DatasetResponseSchema = exports_external.object({
|
|
@@ -58860,7 +58874,9 @@ var init_data_source = __esm(() => {
|
|
|
58860
58874
|
input: exports_external.string(),
|
|
58861
58875
|
output: exports_external.string()
|
|
58862
58876
|
}).loose()),
|
|
58863
|
-
nextCursor: exports_external.string().optional()
|
|
58877
|
+
nextCursor: exports_external.string().optional(),
|
|
58878
|
+
hasMore: exports_external.boolean().optional(),
|
|
58879
|
+
lastEvalTimestamp: exports_external.string().nullable().optional()
|
|
58864
58880
|
}).passthrough();
|
|
58865
58881
|
});
|
|
58866
58882
|
|
|
@@ -113999,8 +114015,27 @@ class S3FileManager {
|
|
|
113999
114015
|
async upload(content, key) {
|
|
114000
114016
|
const { getState: getState2 } = await Promise.resolve().then(() => exports_state);
|
|
114001
114017
|
const state = getState2();
|
|
114018
|
+
if (state.awsAccessKeyId && state.awsSecretAccessKey) {
|
|
114019
|
+
const { PutObjectCommand, S3Client } = require_dist_cjs79();
|
|
114020
|
+
const s3Key = state.tenantId && state.serviceName ? `${state.tenantId}/${state.serviceName}/${key}` : key;
|
|
114021
|
+
const s3Client = new S3Client({
|
|
114022
|
+
region: this.region,
|
|
114023
|
+
credentials: {
|
|
114024
|
+
accessKeyId: state.awsAccessKeyId,
|
|
114025
|
+
secretAccessKey: state.awsSecretAccessKey,
|
|
114026
|
+
sessionToken: state.awsSessionToken || undefined
|
|
114027
|
+
}
|
|
114028
|
+
});
|
|
114029
|
+
await s3Client.send(new PutObjectCommand({
|
|
114030
|
+
Bucket: this.bucket,
|
|
114031
|
+
Key: s3Key,
|
|
114032
|
+
Body: content,
|
|
114033
|
+
ContentType: "application/jsonl"
|
|
114034
|
+
}));
|
|
114035
|
+
return `s3://${this.bucket}/${s3Key}`;
|
|
114036
|
+
}
|
|
114002
114037
|
if (!state.accessToken) {
|
|
114003
|
-
throw new Error("No access token found. Please run 'orcha login' to authenticate before using Bedrock batch mode.");
|
|
114038
|
+
throw new Error("No AWS credentials or access token found. Please run 'orcha login' to authenticate before using Bedrock batch mode.");
|
|
114004
114039
|
}
|
|
114005
114040
|
if (!state.tenantId || !state.serviceName) {
|
|
114006
114041
|
throw new Error("tenantId and serviceName are required for Bedrock batch uploads.");
|
|
@@ -114155,13 +114190,16 @@ class BatchClient {
|
|
|
114155
114190
|
fs.mkdirSync(this.tempDir, { recursive: true });
|
|
114156
114191
|
}
|
|
114157
114192
|
}
|
|
114158
|
-
async initialize(name, checksum, dataSourceType, maxAgeDays =
|
|
114193
|
+
async initialize(name, checksum, dataSourceType, maxAgeDays = 2) {
|
|
114159
114194
|
this.metadata = { name, checksum };
|
|
114160
|
-
|
|
114195
|
+
console.log(`BatchClient.initialize: searching for name="${name}", checksum="${checksum}", mode=${this.mode}, dataSourceType=${dataSourceType ?? "unknown"}`);
|
|
114196
|
+
const batches = await this.listBatches(100);
|
|
114197
|
+
console.log(`BatchClient.initialize: listBatches returned ${batches.length} batch(es): ${JSON.stringify(batches.map((b) => ({ id: b.id, status: b.status, created_at: b.created_at, metadata: b.metadata })))}`);
|
|
114161
114198
|
const maxAgeMs = maxAgeDays * 24 * 60 * 60 * 1000;
|
|
114162
114199
|
const cutoff = Date.now() - maxAgeMs;
|
|
114163
114200
|
const matchingBatches = batches.filter((batch) => {
|
|
114164
|
-
|
|
114201
|
+
const createdAtMs = this.mode === "OPENAI" ? batch.created_at * 1000 : batch.created_at;
|
|
114202
|
+
if (createdAtMs < cutoff) {
|
|
114165
114203
|
return false;
|
|
114166
114204
|
}
|
|
114167
114205
|
const nameMatches = batch.metadata?.name === this.metadata?.name;
|
|
@@ -114172,30 +114210,35 @@ class BatchClient {
|
|
|
114172
114210
|
}
|
|
114173
114211
|
});
|
|
114174
114212
|
if (matchingBatches.length === 0) {
|
|
114213
|
+
console.log("BatchClient.initialize: no matching batches found");
|
|
114175
114214
|
return;
|
|
114176
114215
|
}
|
|
114216
|
+
console.log(`BatchClient.initialize: ${matchingBatches.length} matching batch(es): ${JSON.stringify(matchingBatches.map((b) => ({ id: b.id, status: b.status })))}`);
|
|
114177
114217
|
const pendingBatches = matchingBatches.filter((batch) => !this.isBatchComplete(batch));
|
|
114178
|
-
const
|
|
114218
|
+
const resultBearingBatches = matchingBatches.filter((batch) => batch.status === "completed" || batch.status === "expired" || batch.status === "cancelled");
|
|
114179
114219
|
if (pendingBatches.length > 0) {
|
|
114220
|
+
console.log(`BatchClient.initialize: ${pendingBatches.length} pending batch(es), waiting`);
|
|
114180
114221
|
this.hasPendingBatch = true;
|
|
114181
114222
|
this.pendingBatches = pendingBatches;
|
|
114182
114223
|
return;
|
|
114183
114224
|
}
|
|
114184
|
-
if (
|
|
114225
|
+
if (resultBearingBatches.length > 0) {
|
|
114226
|
+
console.log(`BatchClient.initialize: loading results from ${resultBearingBatches.length} batch(es): ${JSON.stringify(resultBearingBatches.map((b) => ({ id: b.id, status: b.status })))}`);
|
|
114185
114227
|
this.hasCompletedBatch = true;
|
|
114186
|
-
this.completedBatches =
|
|
114228
|
+
this.completedBatches = resultBearingBatches;
|
|
114187
114229
|
const allResponses = [];
|
|
114188
|
-
for (const batch of
|
|
114230
|
+
for (const batch of resultBearingBatches) {
|
|
114189
114231
|
try {
|
|
114190
114232
|
const results = await this.getBatchResults(batch.id);
|
|
114233
|
+
console.log(`BatchClient.initialize: loaded ${results.length} result(s) from batch ${batch.id} (status=${batch.status})`);
|
|
114191
114234
|
allResponses.push(...results);
|
|
114192
114235
|
} catch (error48) {
|
|
114193
114236
|
console.warn(`Failed to load results from batch ${batch.id}:`, error48);
|
|
114194
114237
|
}
|
|
114195
114238
|
}
|
|
114196
114239
|
this.responses = allResponses;
|
|
114197
|
-
if (
|
|
114198
|
-
iso.writeln(`${colors.gray}Loaded ${allResponses.length} total results from ${
|
|
114240
|
+
if (resultBearingBatches.length > 1) {
|
|
114241
|
+
iso.writeln(`${colors.gray}Loaded ${allResponses.length} total results from ${resultBearingBatches.length} batches`);
|
|
114199
114242
|
}
|
|
114200
114243
|
}
|
|
114201
114244
|
}
|
|
@@ -115038,6 +115081,7 @@ var traced = {
|
|
|
115038
115081
|
};
|
|
115039
115082
|
|
|
115040
115083
|
// src/evaluator/core.ts
|
|
115084
|
+
var BATCH_MIN_RECORDS = 100;
|
|
115041
115085
|
function deterministicStringify(obj) {
|
|
115042
115086
|
if (obj === null)
|
|
115043
115087
|
return "null";
|
|
@@ -115191,9 +115235,28 @@ function getEvaluationOptions(name, options, state) {
|
|
|
115191
115235
|
let evalClient;
|
|
115192
115236
|
let openaiClient;
|
|
115193
115237
|
const batchProcessor = merged.batchProcessor ?? "OPENAI";
|
|
115238
|
+
const createSyncFallbackClient = () => {
|
|
115239
|
+
if (batchProcessor === "BEDROCK_OPENAI") {
|
|
115240
|
+
if (!state.bedrockRegion || !state.bedrockApiKey || !state.bedrockServiceRoleArn || !state.bedrockModelId) {
|
|
115241
|
+
return;
|
|
115242
|
+
}
|
|
115243
|
+
const { BedrockOpenAI: BedrockOpenAI2 } = (init_bedrock_openai_client(), __toCommonJS(exports_bedrock_openai_client));
|
|
115244
|
+
return new BedrockOpenAI2({
|
|
115245
|
+
baseURL: `https://bedrock-mantle.${state.bedrockRegion}.api.aws/v1`,
|
|
115246
|
+
apiKey: state.bedrockApiKey,
|
|
115247
|
+
defaultHeaders: {
|
|
115248
|
+
"X-Amzn-Bedrock-RoleArn": state.bedrockServiceRoleArn,
|
|
115249
|
+
"X-Amzn-Bedrock-ModelId": state.bedrockModelId
|
|
115250
|
+
}
|
|
115251
|
+
});
|
|
115252
|
+
}
|
|
115253
|
+
const OpenAI5 = __require("openai").default;
|
|
115254
|
+
return new OpenAI5;
|
|
115255
|
+
};
|
|
115194
115256
|
if (execute === "batch") {
|
|
115195
115257
|
if (merged.batchClient) {
|
|
115196
115258
|
batchClient = merged.batchClient;
|
|
115259
|
+
openaiClient = merged.openaiClient ?? createSyncFallbackClient();
|
|
115197
115260
|
} else {
|
|
115198
115261
|
if (batchProcessor === "BEDROCK_OPENAI") {
|
|
115199
115262
|
if (!state.bedrockRegion || !state.bedrockApiKey || !state.bedrockServiceRoleArn || !state.bedrockModelId || !state.bedrockS3Bucket) {
|
|
@@ -115210,17 +115273,10 @@ function getEvaluationOptions(name, options, state) {
|
|
|
115210
115273
|
s3Bucket: state.bedrockS3Bucket
|
|
115211
115274
|
}
|
|
115212
115275
|
});
|
|
115213
|
-
|
|
115214
|
-
openaiClient = new BedrockOpenAI2({
|
|
115215
|
-
baseURL: `https://bedrock-mantle.${state.bedrockRegion}.api.aws/v1`,
|
|
115216
|
-
apiKey: state.bedrockApiKey,
|
|
115217
|
-
defaultHeaders: {
|
|
115218
|
-
"X-Amzn-Bedrock-RoleArn": state.bedrockServiceRoleArn,
|
|
115219
|
-
"X-Amzn-Bedrock-ModelId": state.bedrockModelId
|
|
115220
|
-
}
|
|
115221
|
-
});
|
|
115276
|
+
openaiClient = createSyncFallbackClient();
|
|
115222
115277
|
} else {
|
|
115223
115278
|
batchClient = new BatchClient;
|
|
115279
|
+
openaiClient = createSyncFallbackClient();
|
|
115224
115280
|
}
|
|
115225
115281
|
}
|
|
115226
115282
|
evalClient = merged.evalClient || new EvalClient({
|
|
@@ -115541,14 +115597,12 @@ async function runEval(name, evaluator, options) {
|
|
|
115541
115597
|
[ATTR_DATASET_SOURCE_TYPE]: data.ctx.sourceType,
|
|
115542
115598
|
[ATTR_EVAL_EXECUTION_METADATA_TEST_CASE_COUNT]: data.ctx.caseCount
|
|
115543
115599
|
});
|
|
115544
|
-
|
|
115545
|
-
if (execute === "batch" && batchProcessor === "BEDROCK_OPENAI" && totalBatchRequests < 100) {
|
|
115546
|
-
execute = "sync";
|
|
115547
|
-
iso.writeln(`ℹ ${totalBatchRequests} batch request(s) (${data.dataset.length} records × ${evaluator.scores.length} scorers) is below the 100 minimum for Bedrock batch. Falling back to sync mode.`);
|
|
115548
|
-
}
|
|
115600
|
+
iso.writeln(`ℹ [batch-trace] dataset resolved: ${data.dataset.length} case(s), sourceType="${data.ctx.sourceType}", dataSourceType="${data.ctx.dataSourceType}", checksum="${data.ctx.checksum}", execute="${execute}", batchProcessor="${batchProcessor}", scorers=${evaluator.scores.length}.`);
|
|
115549
115601
|
if (execute === "batch" && batchClient) {
|
|
115550
115602
|
await batchClient.initialize(name, data.ctx.checksum, data.ctx.dataSourceType);
|
|
115603
|
+
iso.writeln(`ℹ [batch-trace] after initialize: ${batchClient.responses.length} cached response(s) loaded from prior batch(es), hasPendingBatch=${batchClient.hasPendingBatch}, hasCompletedBatch=${batchClient.hasCompletedBatch}.`);
|
|
115551
115604
|
if (batchClient.hasPendingBatch) {
|
|
115605
|
+
iso.writeln("ℹ [batch-trace] a prior batch is still pending — returning early to wait/retry (no new work this run).");
|
|
115552
115606
|
return batchClient.getPending();
|
|
115553
115607
|
}
|
|
115554
115608
|
}
|
|
@@ -115573,11 +115627,37 @@ async function runEval(name, evaluator, options) {
|
|
|
115573
115627
|
if (!jsonl) {
|
|
115574
115628
|
progress.stop();
|
|
115575
115629
|
}
|
|
115630
|
+
if (execute === "batch" && batchClient) {
|
|
115631
|
+
const pendingSoFar = results.filter((r) => r.hasPendingBatch).length;
|
|
115632
|
+
const erroredSoFar = results.filter((r) => r.error).length;
|
|
115633
|
+
const resolvedSoFar = results.length - pendingSoFar - erroredSoFar;
|
|
115634
|
+
iso.writeln(`ℹ [batch-trace] after scoring loop: ${results.length} case(s) processed → ${resolvedSoFar} resolved from cache, ${pendingSoFar} pending (new/changed), ${erroredSoFar} errored. Accumulated ${batchClient.requests.length} batch record(s) across ${evaluator.scores.length} scorer(s)/case, ${batchClient.duplicateCount} duplicate request(s) skipped.`);
|
|
115635
|
+
}
|
|
115576
115636
|
let batch;
|
|
115577
115637
|
if (execute === "batch" && batchClient) {
|
|
115578
|
-
|
|
115579
|
-
|
|
115580
|
-
|
|
115638
|
+
const pendingRequestCount = batchClient.requests.length;
|
|
115639
|
+
const pendingCaseCount = results.filter((r) => r.hasPendingBatch).length;
|
|
115640
|
+
iso.writeln(`ℹ Batch submit decision: ${pendingCaseCount} pending case(s) → ${pendingRequestCount} batch record(s) (minimum ${BATCH_MIN_RECORDS}, sync-fallback client ${options.openaiClient ? "available" : "MISSING"}).`);
|
|
115641
|
+
if (pendingRequestCount > 0 && pendingRequestCount < BATCH_MIN_RECORDS && options.openaiClient) {
|
|
115642
|
+
iso.writeln(`ℹ ${pendingRequestCount} pending request(s) is below the ${BATCH_MIN_RECORDS}-record batch minimum. Running pending case(s) synchronously.`);
|
|
115643
|
+
const syncOptions = { ...effectiveOptions, execute: "sync" };
|
|
115644
|
+
let reranCount = 0;
|
|
115645
|
+
for (let i2 = 0;i2 < results.length; i2++) {
|
|
115646
|
+
if (!results[i2].hasPendingBatch) {
|
|
115647
|
+
continue;
|
|
115648
|
+
}
|
|
115649
|
+
const caseResult = await evaluateDataCase(data.dataset[i2], evaluator, ctx.mutate({ dataset: data.ctx }), syncOptions);
|
|
115650
|
+
results[i2] = caseResult.result;
|
|
115651
|
+
aggregateScorerErrors(errors6, caseResult.errors);
|
|
115652
|
+
reranCount++;
|
|
115653
|
+
}
|
|
115654
|
+
iso.writeln(`ℹ [batch-trace] SYNC-FALLBACK path: re-ran ${reranCount} pending case(s) synchronously; no batch submitted.`);
|
|
115655
|
+
} else {
|
|
115656
|
+
iso.writeln(`ℹ [batch-trace] SUBMIT path: sending ${pendingRequestCount} record(s) to a new batch${options.openaiClient ? "" : " (sync-fallback unavailable, could not run synchronously)"}.`);
|
|
115657
|
+
batch = await batchClient.submit();
|
|
115658
|
+
if (verbose) {
|
|
115659
|
+
console.log(batch);
|
|
115660
|
+
}
|
|
115581
115661
|
}
|
|
115582
115662
|
}
|
|
115583
115663
|
const summary = createEvaluationSummary(name, results, errors6);
|
|
@@ -115762,6 +115842,7 @@ var InteractionsDatasetOptionsSchema = exports_external.object({
|
|
|
115762
115842
|
month: exports_external.string().optional(),
|
|
115763
115843
|
startDate: exports_external.string().optional(),
|
|
115764
115844
|
endDate: exports_external.string().optional(),
|
|
115845
|
+
limit: exports_external.number().optional(),
|
|
115765
115846
|
timeout: exports_external.number().optional()
|
|
115766
115847
|
});
|
|
115767
115848
|
function interactions(options = {}) {
|
|
@@ -115784,6 +115865,7 @@ function interactions(options = {}) {
|
|
|
115784
115865
|
month: options.month,
|
|
115785
115866
|
startDate: options.startDate,
|
|
115786
115867
|
endDate: options.endDate,
|
|
115868
|
+
limit: options.limit,
|
|
115787
115869
|
timeout: options.timeout
|
|
115788
115870
|
},
|
|
115789
115871
|
args: argsJsonSchema
|
|
@@ -115798,6 +115880,7 @@ var SessionsDatasetOptionsSchema = exports_external.object({
|
|
|
115798
115880
|
month: exports_external.string().optional(),
|
|
115799
115881
|
startDate: exports_external.string().optional(),
|
|
115800
115882
|
endDate: exports_external.string().optional(),
|
|
115883
|
+
limit: exports_external.number().optional(),
|
|
115801
115884
|
timeout: exports_external.number().optional()
|
|
115802
115885
|
});
|
|
115803
115886
|
function sessions(options = {}) {
|
|
@@ -115820,6 +115903,7 @@ function sessions(options = {}) {
|
|
|
115820
115903
|
month: options.month,
|
|
115821
115904
|
startDate: options.startDate,
|
|
115822
115905
|
endDate: options.endDate,
|
|
115906
|
+
limit: options.limit,
|
|
115823
115907
|
timeout: options.timeout
|
|
115824
115908
|
},
|
|
115825
115909
|
args: argsJsonSchema
|
|
@@ -116034,4 +116118,4 @@ export {
|
|
|
116034
116118
|
Behavioral
|
|
116035
116119
|
};
|
|
116036
116120
|
|
|
116037
|
-
//# debugId=
|
|
116121
|
+
//# debugId=E69C9539C2C08B5A64756E2164756E21
|