@infersec/conduit 1.8.1 → 1.8.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 +1 -1
- package/dist/index.js +1 -1
- package/dist/sse/handler.d.ts +2 -1
- package/dist/{start-ItMOqpI1.js → start-LWLy96m_.js} +83 -68
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ const __dirname = __pathDirname(__filename);
|
|
|
6
6
|
|
|
7
7
|
import { parseArgs } from 'node:util';
|
|
8
8
|
import 'node:crypto';
|
|
9
|
-
import { a as asError, s as startInferenceAgent } from './start-
|
|
9
|
+
import { a as asError, s as startInferenceAgent } from './start-LWLy96m_.js';
|
|
10
10
|
import 'argon2';
|
|
11
11
|
import 'node:child_process';
|
|
12
12
|
import 'node:stream';
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ const __filename = __fileURLToPath(import.meta.url);
|
|
|
5
5
|
const __dirname = __pathDirname(__filename);
|
|
6
6
|
|
|
7
7
|
import 'node:crypto';
|
|
8
|
-
import { s as startInferenceAgent, a as asError } from './start-
|
|
8
|
+
import { s as startInferenceAgent, a as asError } from './start-LWLy96m_.js';
|
|
9
9
|
import 'argon2';
|
|
10
10
|
import 'node:child_process';
|
|
11
11
|
import 'node:stream';
|
package/dist/sse/handler.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type APIResponse, type ServerToClientAPIRequest } from "@infersec/definitions";
|
|
2
2
|
import { Logger } from "@infersec/logger";
|
|
3
3
|
import { Configuration } from "../configuration.js";
|
|
4
|
-
export declare function handleSSERequests({ apiURL, configuration, logger, onRequest, onRequestEnd, onRequestStart }: {
|
|
4
|
+
export declare function handleSSERequests({ apiURL, configuration, logger, onRequest, onRequestEnd, onRequestStart, signal }: {
|
|
5
5
|
apiURL: string;
|
|
6
6
|
configuration: Configuration;
|
|
7
7
|
logger: Logger;
|
|
8
8
|
onRequest: (request: ServerToClientAPIRequest) => Promise<APIResponse>;
|
|
9
9
|
onRequestEnd?: (request: ServerToClientAPIRequest) => Promise<void> | void;
|
|
10
10
|
onRequestStart?: (request: ServerToClientAPIRequest) => Promise<void> | void;
|
|
11
|
+
signal?: AbortSignal;
|
|
11
12
|
}): Promise<void>;
|
|
@@ -105135,38 +105135,68 @@ class ModelManager extends EventEmitter {
|
|
|
105135
105135
|
}
|
|
105136
105136
|
}
|
|
105137
105137
|
|
|
105138
|
-
|
|
105138
|
+
function sleep(ms) {
|
|
105139
|
+
return new Promise(resolve => {
|
|
105140
|
+
setTimeout(() => resolve(), ms);
|
|
105141
|
+
});
|
|
105142
|
+
}
|
|
105143
|
+
|
|
105144
|
+
async function handleSSERequests({ apiURL, configuration, logger, onRequest, onRequestEnd, onRequestStart, signal }) {
|
|
105139
105145
|
const streamURL = `${apiURL}/conduit/api/v1/source/${configuration.inferenceSourceID}/requests/stream`;
|
|
105140
|
-
|
|
105141
|
-
|
|
105142
|
-
|
|
105143
|
-
|
|
105144
|
-
|
|
105145
|
-
|
|
105146
|
-
|
|
105146
|
+
const maxReconnectDelayMs = 30000;
|
|
105147
|
+
let reconnectAttempt = 0;
|
|
105148
|
+
while (!signal?.aborted) {
|
|
105149
|
+
const connectionStartedAt = Date.now();
|
|
105150
|
+
try {
|
|
105151
|
+
await connectSSE(streamURL, {
|
|
105152
|
+
headers: {
|
|
105153
|
+
"x-api-key": configuration.apiKey
|
|
105154
|
+
},
|
|
105155
|
+
onError: (error) => {
|
|
105156
|
+
logger.error("SSE connection error", {
|
|
105157
|
+
error
|
|
105158
|
+
});
|
|
105159
|
+
},
|
|
105160
|
+
onMessage: (message) => {
|
|
105161
|
+
if (message.event !== "request") {
|
|
105162
|
+
return;
|
|
105163
|
+
}
|
|
105164
|
+
const payload = ServerToClientAPIRequestSchema.parse(JSON.parse(message.data));
|
|
105165
|
+
handleRequest({
|
|
105166
|
+
apiURL,
|
|
105167
|
+
configuration,
|
|
105168
|
+
logger,
|
|
105169
|
+
onRequest,
|
|
105170
|
+
onRequestEnd,
|
|
105171
|
+
onRequestStart,
|
|
105172
|
+
request: payload
|
|
105173
|
+
}).catch(error => {
|
|
105174
|
+
logger.error("SSE request handler failed", {
|
|
105175
|
+
error: asError(error),
|
|
105176
|
+
requestMethod: payload.requestID
|
|
105177
|
+
});
|
|
105178
|
+
});
|
|
105179
|
+
},
|
|
105180
|
+
signal
|
|
105147
105181
|
});
|
|
105148
|
-
}
|
|
105149
|
-
|
|
105150
|
-
if (
|
|
105182
|
+
}
|
|
105183
|
+
catch (error) {
|
|
105184
|
+
if (signal?.aborted) {
|
|
105151
105185
|
return;
|
|
105152
105186
|
}
|
|
105153
|
-
|
|
105154
|
-
|
|
105155
|
-
apiURL,
|
|
105156
|
-
configuration,
|
|
105157
|
-
logger,
|
|
105158
|
-
onRequestEnd,
|
|
105159
|
-
onRequestStart,
|
|
105160
|
-
onRequest,
|
|
105161
|
-
request: payload
|
|
105162
|
-
}).catch(error => {
|
|
105163
|
-
logger.error("SSE request handler failed", {
|
|
105164
|
-
error: asError(error),
|
|
105165
|
-
requestMethod: payload.requestID
|
|
105166
|
-
});
|
|
105187
|
+
logger.error("SSE connection failed", {
|
|
105188
|
+
error: asError(error)
|
|
105167
105189
|
});
|
|
105168
105190
|
}
|
|
105169
|
-
|
|
105191
|
+
if (signal?.aborted) {
|
|
105192
|
+
return;
|
|
105193
|
+
}
|
|
105194
|
+
const connectionDurationMs = Date.now() - connectionStartedAt;
|
|
105195
|
+
reconnectAttempt = connectionDurationMs > 10000 ? 0 : reconnectAttempt + 1;
|
|
105196
|
+
const reconnectDelayMs = Math.min(maxReconnectDelayMs, Math.max(1000, 1000 * 2 ** Math.min(6, reconnectAttempt)));
|
|
105197
|
+
logger.warn("SSE disconnected, retrying");
|
|
105198
|
+
await sleep(reconnectDelayMs);
|
|
105199
|
+
}
|
|
105170
105200
|
}
|
|
105171
105201
|
async function handleRequest({ apiURL, configuration, logger, onRequest, onRequestEnd, onRequestStart, request }) {
|
|
105172
105202
|
try {
|
|
@@ -114824,7 +114854,6 @@ async function createApplication({ abortController, apiClient, configuration, lo
|
|
|
114824
114854
|
});
|
|
114825
114855
|
const modelFileName = getConduitModelFileName(conduitConfiguration);
|
|
114826
114856
|
const modelName = getConduitModelName(conduitConfiguration);
|
|
114827
|
-
const idleReason = "Awaiting requests";
|
|
114828
114857
|
const startup = Date.now();
|
|
114829
114858
|
// Initialise model manager
|
|
114830
114859
|
const modelManager = new ModelManager({
|
|
@@ -114835,28 +114864,6 @@ async function createApplication({ abortController, apiClient, configuration, lo
|
|
|
114835
114864
|
parallelism: conduitConfiguration.parallelism ?? null,
|
|
114836
114865
|
root: configuration.rootDirectory
|
|
114837
114866
|
});
|
|
114838
|
-
modelManager.on("engineError", err => {
|
|
114839
|
-
logger.error("LLM engine error", {
|
|
114840
|
-
error: err
|
|
114841
|
-
});
|
|
114842
|
-
conduitStateManager.setState({
|
|
114843
|
-
error: err.message,
|
|
114844
|
-
state: "error"
|
|
114845
|
-
});
|
|
114846
|
-
abortController.abort(err);
|
|
114847
|
-
});
|
|
114848
|
-
modelManager.on("engineTerminated", () => {
|
|
114849
|
-
conduitStateManager.setState({
|
|
114850
|
-
state: "offline"
|
|
114851
|
-
});
|
|
114852
|
-
abortController.abort();
|
|
114853
|
-
});
|
|
114854
|
-
modelManager.on("engineReady", () => {
|
|
114855
|
-
conduitStateManager.setState({
|
|
114856
|
-
reason: idleReason,
|
|
114857
|
-
state: "idle"
|
|
114858
|
-
});
|
|
114859
|
-
});
|
|
114860
114867
|
conduitStateManager.setState({
|
|
114861
114868
|
modelFileName,
|
|
114862
114869
|
modelName,
|
|
@@ -114971,40 +114978,54 @@ async function createApplication({ abortController, apiClient, configuration, lo
|
|
|
114971
114978
|
});
|
|
114972
114979
|
}, CONDUIT_STATE_INTERVAL_MS);
|
|
114973
114980
|
let activeRequests = 0;
|
|
114974
|
-
const setIdleState = () => {
|
|
114975
|
-
conduitStateManager.setState({
|
|
114976
|
-
reason: idleReason,
|
|
114977
|
-
state: "idle"
|
|
114978
|
-
});
|
|
114979
|
-
};
|
|
114980
114981
|
const setOnlineState = () => {
|
|
114981
114982
|
conduitStateManager.setState({
|
|
114982
114983
|
modelName,
|
|
114983
114984
|
state: "online"
|
|
114984
114985
|
});
|
|
114985
114986
|
};
|
|
114987
|
+
modelManager.on("engineError", err => {
|
|
114988
|
+
logger.error("LLM engine error", {
|
|
114989
|
+
error: err
|
|
114990
|
+
});
|
|
114991
|
+
conduitStateManager.setState({
|
|
114992
|
+
error: err.message,
|
|
114993
|
+
state: "error"
|
|
114994
|
+
});
|
|
114995
|
+
abortController.abort(err);
|
|
114996
|
+
});
|
|
114997
|
+
modelManager.on("engineTerminated", () => {
|
|
114998
|
+
conduitStateManager.setState({
|
|
114999
|
+
state: "offline"
|
|
115000
|
+
});
|
|
115001
|
+
abortController.abort();
|
|
115002
|
+
});
|
|
115003
|
+
modelManager.on("engineReady", () => {
|
|
115004
|
+
setOnlineState();
|
|
115005
|
+
});
|
|
114986
115006
|
handleSSERequests({
|
|
114987
115007
|
apiURL: configuration.apiURL,
|
|
114988
115008
|
configuration,
|
|
114989
115009
|
logger,
|
|
114990
|
-
onRequestEnd: () => {
|
|
114991
|
-
activeRequests = Math.max(0, activeRequests - 1);
|
|
114992
|
-
if (activeRequests === 0) {
|
|
114993
|
-
setIdleState();
|
|
114994
|
-
}
|
|
114995
|
-
},
|
|
114996
115010
|
onRequest: async (request) => {
|
|
114997
115011
|
return proxyRequest({
|
|
114998
115012
|
configuration,
|
|
114999
115013
|
request
|
|
115000
115014
|
});
|
|
115001
115015
|
},
|
|
115016
|
+
onRequestEnd: () => {
|
|
115017
|
+
activeRequests = Math.max(0, activeRequests - 1);
|
|
115018
|
+
if (activeRequests === 0) {
|
|
115019
|
+
setOnlineState();
|
|
115020
|
+
}
|
|
115021
|
+
},
|
|
115002
115022
|
onRequestStart: () => {
|
|
115003
115023
|
activeRequests += 1;
|
|
115004
115024
|
if (activeRequests === 1) {
|
|
115005
115025
|
setOnlineState();
|
|
115006
115026
|
}
|
|
115007
|
-
}
|
|
115027
|
+
},
|
|
115028
|
+
signal: abortController.signal
|
|
115008
115029
|
}).catch(error => {
|
|
115009
115030
|
logger.error("SSE handler failed", {
|
|
115010
115031
|
error: asError(error)
|
|
@@ -115044,12 +115065,6 @@ function getConfiguration({ overrides } = {}) {
|
|
|
115044
115065
|
};
|
|
115045
115066
|
}
|
|
115046
115067
|
|
|
115047
|
-
function sleep(ms) {
|
|
115048
|
-
return new Promise(resolve => {
|
|
115049
|
-
setTimeout(() => resolve(), ms);
|
|
115050
|
-
});
|
|
115051
|
-
}
|
|
115052
|
-
|
|
115053
115068
|
async function startInferenceAgent({ configurationOverrides }) {
|
|
115054
115069
|
const abortController = new AbortController();
|
|
115055
115070
|
const configuration = getConfiguration({ overrides: configurationOverrides });
|