@apo-ai/sdk 0.12.0 → 0.13.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.
|
@@ -1193,7 +1193,13 @@ async function readCompletion(response, onData, guards) {
|
|
|
1193
1193
|
dispatch();
|
|
1194
1194
|
return { text, usage, finishReason };
|
|
1195
1195
|
}
|
|
1196
|
-
var
|
|
1196
|
+
var prefixLanes = /* @__PURE__ */ new Map();
|
|
1197
|
+
function judgeConcurrency() {
|
|
1198
|
+
const raw = process.env.APO_JUDGE_CONCURRENCY?.trim();
|
|
1199
|
+
if (!raw) return 1;
|
|
1200
|
+
const n = Number(raw);
|
|
1201
|
+
return Number.isInteger(n) && n >= 1 ? n : 1;
|
|
1202
|
+
}
|
|
1197
1203
|
function promptCacheKey(prefix) {
|
|
1198
1204
|
return `apo-${createHash("sha256").update(prefix).digest("hex").slice(0, 32)}`;
|
|
1199
1205
|
}
|
|
@@ -1225,16 +1231,36 @@ async function fetchWithPromptCacheKey(input, init) {
|
|
|
1225
1231
|
return retry;
|
|
1226
1232
|
}
|
|
1227
1233
|
function runWithSharedPrefix(key, task2) {
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
key,
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1234
|
+
const existing = prefixLanes.get(key);
|
|
1235
|
+
if (!existing) {
|
|
1236
|
+
const warmer = task2();
|
|
1237
|
+
prefixLanes.set(key, {
|
|
1238
|
+
warmed: warmer.then(
|
|
1239
|
+
() => void 0,
|
|
1240
|
+
() => void 0
|
|
1241
|
+
),
|
|
1242
|
+
active: 0,
|
|
1243
|
+
waiting: []
|
|
1244
|
+
});
|
|
1245
|
+
return warmer;
|
|
1246
|
+
}
|
|
1247
|
+
const lane = existing;
|
|
1248
|
+
const acquire = () => new Promise((resolve5) => {
|
|
1249
|
+
if (lane.active < judgeConcurrency()) {
|
|
1250
|
+
lane.active += 1;
|
|
1251
|
+
resolve5();
|
|
1252
|
+
} else {
|
|
1253
|
+
lane.waiting.push(() => {
|
|
1254
|
+
lane.active += 1;
|
|
1255
|
+
resolve5();
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
});
|
|
1259
|
+
const release = () => {
|
|
1260
|
+
lane.active -= 1;
|
|
1261
|
+
lane.waiting.shift()?.();
|
|
1262
|
+
};
|
|
1263
|
+
return lane.warmed.then(acquire).then(() => task2().finally(release));
|
|
1238
1264
|
}
|
|
1239
1265
|
function defaultJudgeBaseURL(baseURL) {
|
|
1240
1266
|
return baseURL ?? process.env.OPENROUTER_BASE_URL ?? "https://openrouter.ai/api/v1";
|