@infersec/conduit 1.17.0 → 1.17.1

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-Cf1W68Pz.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-Cf1W68Pz.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 }) {
@@ -118023,6 +118108,14 @@ async function createApplication({ abortController, apiClient, configuration, lo
118023
118108
  total: 0
118024
118109
  }
118025
118110
  });
118111
+ const conduitStateReportManager = new ConduitStateReportManager({
118112
+ apiClient,
118113
+ conduitStateManager,
118114
+ downloadProgressReportIntervalMs: 5000,
118115
+ logger,
118116
+ stateIntervalMs: 30000
118117
+ });
118118
+ await conduitStateReportManager.start();
118026
118119
  let lastDownloadKey = "";
118027
118120
  const reportDownloadProgress = (update) => {
118028
118121
  const filePercent = update.file.total > 0 ? Math.floor((update.file.bytes / update.file.total) * 100) : 0;
@@ -118044,6 +118137,7 @@ async function createApplication({ abortController, apiClient, configuration, lo
118044
118137
  total: Math.max(0, Math.floor(update.total.total))
118045
118138
  }
118046
118139
  });
118140
+ conduitStateReportManager.reportDownloadProgress();
118047
118141
  };
118048
118142
  await modelManager.prepare({
118049
118143
  onDownloadProgress: reportDownloadProgress
@@ -118108,25 +118202,6 @@ async function createApplication({ abortController, apiClient, configuration, lo
118108
118202
  mount: publicRouter,
118109
118203
  reference: API_CLIENT_INFERENCE_AGENT_API_REFERENCE
118110
118204
  });
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
118205
  let activeRequests = 0;
118131
118206
  const setOnlineState = () => {
118132
118207
  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.1",
5
5
  "bin": {
6
6
  "infersec-conduit": "./dist/cli.js"
7
7
  },