@infersec/conduit 1.17.0 → 1.17.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 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-CCmUbFoS.js';
9
+ import { a as asError, s as startInferenceAgent } from './start-CP94v_Uv.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-CCmUbFoS.js';
8
+ import { s as startInferenceAgent, a as asError } from './start-CP94v_Uv.js';
9
9
  import 'argon2';
10
10
  import 'node:child_process';
11
11
  import 'node:stream';
@@ -108507,6 +108507,91 @@ async function proxyRequest({ configuration, request }) {
108507
108507
  };
108508
108508
  }
108509
108509
 
108510
+ class ConduitStateReportManager {
108511
+ apiClient;
108512
+ conduitStateManager;
108513
+ downloadProgressReportIntervalMs;
108514
+ logger;
108515
+ stateIntervalMs;
108516
+ conduitStateReportInFlight = false;
108517
+ lastConduitStateReportAt = 0;
108518
+ pendingConduitStateReport = null;
108519
+ stateInterval = null;
108520
+ constructor({ apiClient, conduitStateManager, downloadProgressReportIntervalMs, logger, stateIntervalMs }) {
108521
+ this.apiClient = apiClient;
108522
+ this.conduitStateManager = conduitStateManager;
108523
+ this.downloadProgressReportIntervalMs = downloadProgressReportIntervalMs;
108524
+ this.logger = logger;
108525
+ this.stateIntervalMs = stateIntervalMs;
108526
+ }
108527
+ async start() {
108528
+ await this.sendConduitState();
108529
+ this.stateInterval = setInterval(() => {
108530
+ this.sendConduitState().catch(error => {
108531
+ this.logger.error("Conduit state update failed", {
108532
+ error: asError(error)
108533
+ });
108534
+ });
108535
+ }, this.stateIntervalMs);
108536
+ }
108537
+ stop() {
108538
+ if (this.stateInterval) {
108539
+ clearInterval(this.stateInterval);
108540
+ this.stateInterval = null;
108541
+ }
108542
+ if (this.pendingConduitStateReport) {
108543
+ clearTimeout(this.pendingConduitStateReport);
108544
+ this.pendingConduitStateReport = null;
108545
+ }
108546
+ }
108547
+ reportDownloadProgress() {
108548
+ this.scheduleConduitStateReport();
108549
+ }
108550
+ async sendConduitState() {
108551
+ try {
108552
+ await this.apiClient.reportConduitState(this.conduitStateManager.touch());
108553
+ this.lastConduitStateReportAt = Date.now();
108554
+ }
108555
+ catch (error) {
108556
+ this.logger.error("Conduit state update failed", {
108557
+ error: asError(error)
108558
+ });
108559
+ }
108560
+ }
108561
+ async triggerConduitStateReport() {
108562
+ if (this.conduitStateReportInFlight) {
108563
+ this.scheduleConduitStateReport();
108564
+ return;
108565
+ }
108566
+ this.conduitStateReportInFlight = true;
108567
+ await this.sendConduitState();
108568
+ this.conduitStateReportInFlight = false;
108569
+ }
108570
+ scheduleConduitStateReport() {
108571
+ const now = Date.now();
108572
+ const elapsed = now - this.lastConduitStateReportAt;
108573
+ if (elapsed >= this.downloadProgressReportIntervalMs && !this.conduitStateReportInFlight) {
108574
+ this.triggerConduitStateReport().catch(error => {
108575
+ this.logger.error("Conduit state update failed", {
108576
+ error: asError(error)
108577
+ });
108578
+ });
108579
+ return;
108580
+ }
108581
+ if (this.pendingConduitStateReport)
108582
+ return;
108583
+ const delay = Math.max(this.downloadProgressReportIntervalMs - elapsed, 0);
108584
+ this.pendingConduitStateReport = setTimeout(() => {
108585
+ this.pendingConduitStateReport = null;
108586
+ this.triggerConduitStateReport().catch(error => {
108587
+ this.logger.error("Conduit state update failed", {
108588
+ error: asError(error)
108589
+ });
108590
+ });
108591
+ }, delay);
108592
+ }
108593
+ }
108594
+
108510
108595
  class ConduitStateManager {
108511
108596
  currentState;
108512
108597
  constructor({ initialState }) {
@@ -117930,6 +118015,19 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelMan
117930
118015
  });
117931
118016
  throw error;
117932
118017
  });
118018
+ const responseStatusText = response.statusText ?? "Upstream request failed";
118019
+ if (!response.ok) {
118020
+ const responseBody = await response.text().catch(() => null);
118021
+ const responseError = new Error(responseBody
118022
+ ? `Upstream error response: ${responseBody}`
118023
+ : "Upstream error response: empty body");
118024
+ logger.error("LLM engine request failed", {
118025
+ error: responseError,
118026
+ requestUrl: path,
118027
+ statusCode: response.status,
118028
+ statusText: responseStatusText
118029
+ });
118030
+ }
117933
118031
  if (!response.body || !response.ok) {
117934
118032
  logEngineMetrics({
117935
118033
  agentEngineType: configuration.agentEngineType,
@@ -117949,7 +118047,7 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelMan
117949
118047
  });
117950
118048
  return {
117951
118049
  status: response.status,
117952
- statusText: response.statusText ?? "Upstream request failed"
118050
+ statusText: responseStatusText
117953
118051
  };
117954
118052
  }
117955
118053
  const monitoredResponse = monitorEngineResponseStream({
@@ -118023,6 +118121,14 @@ async function createApplication({ abortController, apiClient, configuration, lo
118023
118121
  total: 0
118024
118122
  }
118025
118123
  });
118124
+ const conduitStateReportManager = new ConduitStateReportManager({
118125
+ apiClient,
118126
+ conduitStateManager,
118127
+ downloadProgressReportIntervalMs: 5000,
118128
+ logger,
118129
+ stateIntervalMs: 30000
118130
+ });
118131
+ await conduitStateReportManager.start();
118026
118132
  let lastDownloadKey = "";
118027
118133
  const reportDownloadProgress = (update) => {
118028
118134
  const filePercent = update.file.total > 0 ? Math.floor((update.file.bytes / update.file.total) * 100) : 0;
@@ -118044,6 +118150,7 @@ async function createApplication({ abortController, apiClient, configuration, lo
118044
118150
  total: Math.max(0, Math.floor(update.total.total))
118045
118151
  }
118046
118152
  });
118153
+ conduitStateReportManager.reportDownloadProgress();
118047
118154
  };
118048
118155
  await modelManager.prepare({
118049
118156
  onDownloadProgress: reportDownloadProgress
@@ -118108,25 +118215,6 @@ async function createApplication({ abortController, apiClient, configuration, lo
118108
118215
  mount: publicRouter,
118109
118216
  reference: API_CLIENT_INFERENCE_AGENT_API_REFERENCE
118110
118217
  });
118111
- const CONDUIT_STATE_INTERVAL_MS = 30000;
118112
- async function sendConduitState() {
118113
- try {
118114
- await apiClient.reportConduitState(conduitStateManager.touch());
118115
- }
118116
- catch (error) {
118117
- logger.error("Conduit state update failed", {
118118
- error: asError(error)
118119
- });
118120
- }
118121
- }
118122
- await sendConduitState();
118123
- setInterval(() => {
118124
- sendConduitState().catch(error => {
118125
- logger.error("Conduit state update failed", {
118126
- error: asError(error)
118127
- });
118128
- });
118129
- }, CONDUIT_STATE_INTERVAL_MS);
118130
118218
  let activeRequests = 0;
118131
118219
  const setOnlineState = () => {
118132
118220
  conduitStateManager.setState({
@@ -0,0 +1,27 @@
1
+ import { Logger } from "@infersec/logger";
2
+ import { APIClient } from "../apiClient/index.js";
3
+ import { ConduitStateManager } from "./ConduitStateManager.js";
4
+ export declare class ConduitStateReportManager {
5
+ private apiClient;
6
+ private conduitStateManager;
7
+ private downloadProgressReportIntervalMs;
8
+ private logger;
9
+ private stateIntervalMs;
10
+ private conduitStateReportInFlight;
11
+ private lastConduitStateReportAt;
12
+ private pendingConduitStateReport;
13
+ private stateInterval;
14
+ constructor({ apiClient, conduitStateManager, downloadProgressReportIntervalMs, logger, stateIntervalMs }: {
15
+ apiClient: APIClient;
16
+ conduitStateManager: ConduitStateManager;
17
+ downloadProgressReportIntervalMs: number;
18
+ logger: Logger;
19
+ stateIntervalMs: number;
20
+ });
21
+ start(): Promise<void>;
22
+ stop(): void;
23
+ reportDownloadProgress(): void;
24
+ private sendConduitState;
25
+ private triggerConduitStateReport;
26
+ private scheduleConduitStateReport;
27
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infersec/conduit",
3
3
  "description": "End user conduit agent for connecting local LLMs to the cloud.",
4
- "version": "1.17.0",
4
+ "version": "1.17.2",
5
5
  "bin": {
6
6
  "infersec-conduit": "./dist/cli.js"
7
7
  },