@infersec/conduit 1.109.1 → 1.109.2
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/cli.js +27 -1
- package/dist/cli.sea.cjs +27 -1
- package/dist/sse/handler.d.ts +13 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -126399,6 +126399,17 @@ async function streamResponse({ apiURL, configuration, logger, requestID, reques
|
|
|
126399
126399
|
function encodeBinaryChunk(chunk) {
|
|
126400
126400
|
return chunk.toString("base64");
|
|
126401
126401
|
}
|
|
126402
|
+
const FLUSH_MAX_BATCH = 16;
|
|
126403
|
+
const FLUSH_WINDOW_MS = 60;
|
|
126404
|
+
/**
|
|
126405
|
+
* Decides whether the chunk queue must flush at a chunk arrival. Age-based,
|
|
126406
|
+
* so cadence adapts to generation speed: slow streams flush almost
|
|
126407
|
+
* immediately, fast streams accumulate into larger batches. The max batch
|
|
126408
|
+
* guards bursts faster than any flush roundtrip can absorb.
|
|
126409
|
+
*/
|
|
126410
|
+
function shouldFlushChunkBatch({ ageMs, count, isTerminal, maxBatch, windowMs }) {
|
|
126411
|
+
return isTerminal || ageMs >= windowMs || count >= maxBatch;
|
|
126412
|
+
}
|
|
126402
126413
|
async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
126403
126414
|
const streamURL = `${apiURL}/conduit/api/v1/source/${configuration.inferenceSourceID}/requests/${requestID}/stream`;
|
|
126404
126415
|
const maxFlushAttempts = 3;
|
|
@@ -126407,6 +126418,7 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126407
126418
|
let isClosed = false;
|
|
126408
126419
|
let activeAbortController = null;
|
|
126409
126420
|
let consecutiveFlushFailures = 0;
|
|
126421
|
+
let pendingSince = null;
|
|
126410
126422
|
const chunks = [];
|
|
126411
126423
|
const sendChunk = async (payload) => {
|
|
126412
126424
|
if (isAborted || isClosed) {
|
|
@@ -126422,9 +126434,22 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126422
126434
|
...response,
|
|
126423
126435
|
sequence: payload.sequence
|
|
126424
126436
|
});
|
|
126437
|
+
const now = Date.now();
|
|
126438
|
+
if (pendingSince === null) {
|
|
126439
|
+
pendingSince = now;
|
|
126440
|
+
}
|
|
126425
126441
|
chunks.push(Buffer.from(chunk + "\n"));
|
|
126426
|
-
if (
|
|
126442
|
+
if (shouldFlushChunkBatch({
|
|
126443
|
+
ageMs: now - pendingSince,
|
|
126444
|
+
count: chunks.length,
|
|
126445
|
+
isTerminal: payload.data === null,
|
|
126446
|
+
maxBatch: FLUSH_MAX_BATCH,
|
|
126447
|
+
windowMs: FLUSH_WINDOW_MS
|
|
126448
|
+
})) {
|
|
126427
126449
|
await flushChunks();
|
|
126450
|
+
if (chunks.length === 0) {
|
|
126451
|
+
pendingSince = null;
|
|
126452
|
+
}
|
|
126428
126453
|
}
|
|
126429
126454
|
};
|
|
126430
126455
|
const flushChunks = async () => {
|
|
@@ -126493,6 +126518,7 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126493
126518
|
activeAbortController.abort();
|
|
126494
126519
|
}
|
|
126495
126520
|
chunks.length = 0;
|
|
126521
|
+
pendingSince = null;
|
|
126496
126522
|
if (error) {
|
|
126497
126523
|
logger.error("Chunk stream aborted", {
|
|
126498
126524
|
error: asError(error)
|
package/dist/cli.sea.cjs
CHANGED
|
@@ -126414,6 +126414,17 @@ async function streamResponse({ apiURL, configuration, logger, requestID, reques
|
|
|
126414
126414
|
function encodeBinaryChunk(chunk) {
|
|
126415
126415
|
return chunk.toString("base64");
|
|
126416
126416
|
}
|
|
126417
|
+
const FLUSH_MAX_BATCH = 16;
|
|
126418
|
+
const FLUSH_WINDOW_MS = 60;
|
|
126419
|
+
/**
|
|
126420
|
+
* Decides whether the chunk queue must flush at a chunk arrival. Age-based,
|
|
126421
|
+
* so cadence adapts to generation speed: slow streams flush almost
|
|
126422
|
+
* immediately, fast streams accumulate into larger batches. The max batch
|
|
126423
|
+
* guards bursts faster than any flush roundtrip can absorb.
|
|
126424
|
+
*/
|
|
126425
|
+
function shouldFlushChunkBatch({ ageMs, count, isTerminal, maxBatch, windowMs }) {
|
|
126426
|
+
return isTerminal || ageMs >= windowMs || count >= maxBatch;
|
|
126427
|
+
}
|
|
126417
126428
|
async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
126418
126429
|
const streamURL = `${apiURL}/conduit/api/v1/source/${configuration.inferenceSourceID}/requests/${requestID}/stream`;
|
|
126419
126430
|
const maxFlushAttempts = 3;
|
|
@@ -126422,6 +126433,7 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126422
126433
|
let isClosed = false;
|
|
126423
126434
|
let activeAbortController = null;
|
|
126424
126435
|
let consecutiveFlushFailures = 0;
|
|
126436
|
+
let pendingSince = null;
|
|
126425
126437
|
const chunks = [];
|
|
126426
126438
|
const sendChunk = async (payload) => {
|
|
126427
126439
|
if (isAborted || isClosed) {
|
|
@@ -126437,9 +126449,22 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126437
126449
|
...response,
|
|
126438
126450
|
sequence: payload.sequence
|
|
126439
126451
|
});
|
|
126452
|
+
const now = Date.now();
|
|
126453
|
+
if (pendingSince === null) {
|
|
126454
|
+
pendingSince = now;
|
|
126455
|
+
}
|
|
126440
126456
|
chunks.push(Buffer.from(chunk + "\n"));
|
|
126441
|
-
if (
|
|
126457
|
+
if (shouldFlushChunkBatch({
|
|
126458
|
+
ageMs: now - pendingSince,
|
|
126459
|
+
count: chunks.length,
|
|
126460
|
+
isTerminal: payload.data === null,
|
|
126461
|
+
maxBatch: FLUSH_MAX_BATCH,
|
|
126462
|
+
windowMs: FLUSH_WINDOW_MS
|
|
126463
|
+
})) {
|
|
126442
126464
|
await flushChunks();
|
|
126465
|
+
if (chunks.length === 0) {
|
|
126466
|
+
pendingSince = null;
|
|
126467
|
+
}
|
|
126443
126468
|
}
|
|
126444
126469
|
};
|
|
126445
126470
|
const flushChunks = async () => {
|
|
@@ -126508,6 +126533,7 @@ async function sendChunkStream({ apiURL, configuration, requestID, logger }) {
|
|
|
126508
126533
|
activeAbortController.abort();
|
|
126509
126534
|
}
|
|
126510
126535
|
chunks.length = 0;
|
|
126536
|
+
pendingSince = null;
|
|
126511
126537
|
if (error) {
|
|
126512
126538
|
logger.error("Chunk stream aborted", {
|
|
126513
126539
|
error: asError(error)
|
package/dist/sse/handler.d.ts
CHANGED
|
@@ -13,3 +13,16 @@ export declare function handleSSERequests({ apiURL, configuration, logger, onReq
|
|
|
13
13
|
onRequestStart?: (request: ServerToClientAPIRequest) => Promise<void> | void;
|
|
14
14
|
signal?: AbortSignal;
|
|
15
15
|
}): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Decides whether the chunk queue must flush at a chunk arrival. Age-based,
|
|
18
|
+
* so cadence adapts to generation speed: slow streams flush almost
|
|
19
|
+
* immediately, fast streams accumulate into larger batches. The max batch
|
|
20
|
+
* guards bursts faster than any flush roundtrip can absorb.
|
|
21
|
+
*/
|
|
22
|
+
export declare function shouldFlushChunkBatch({ ageMs, count, isTerminal, maxBatch, windowMs }: {
|
|
23
|
+
ageMs: number;
|
|
24
|
+
count: number;
|
|
25
|
+
isTerminal: boolean;
|
|
26
|
+
maxBatch: number;
|
|
27
|
+
windowMs: number;
|
|
28
|
+
}): boolean;
|