@infersec/conduit 1.16.1 → 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.
@@ -5,7 +5,7 @@ export interface APIClient {
5
5
  reportMachineMetadata: (payload: InferenceAgentMachineReportPayload) => Promise<void>;
6
6
  reportPromptMetrics: (payload: InferenceAgentLLMMetricsPayload) => Promise<void>;
7
7
  }
8
- export declare function createAPIClient({ apiURL, inferenceSourceID }: {
8
+ export declare function createAPIClient({ apiKey, apiURL, inferenceSourceID }: {
9
9
  apiKey: string;
10
10
  apiURL: string;
11
11
  inferenceSourceID: ULID;
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-Xtxz-3k5.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-Xtxz-3k5.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';
@@ -52625,6 +52625,19 @@ function requireUndici () {
52625
52625
 
52626
52626
  var undiciExports = requireUndici();
52627
52627
 
52628
+ function createFetchWithHeaders({ fetchFn = undiciExports.fetch, headers }) {
52629
+ function fetchWithHeaders(url, options) {
52630
+ const mergedHeaders = new Headers(options.headers);
52631
+ for (const [key, value] of Object.entries(headers)) {
52632
+ mergedHeaders.set(key, value);
52633
+ }
52634
+ return fetchFn(url, {
52635
+ ...options,
52636
+ headers: mergedHeaders
52637
+ });
52638
+ }
52639
+ return fetchWithHeaders;
52640
+ }
52628
52641
  async function fetchByReference(options) {
52629
52642
  const { baseURL, body, fetch: fetchFn = undiciExports.fetch, parameters = {}, query = {}, reference, route, method } = options;
52630
52643
  if (!reference[route]) {
@@ -97906,11 +97919,17 @@ function implementAPIReference({ api, logger, mount, reference }) {
97906
97919
  }
97907
97920
  }
97908
97921
 
97909
- function createAPIClient({ apiURL, inferenceSourceID }) {
97922
+ function createAPIClient({ apiKey, apiURL, inferenceSourceID }) {
97923
+ const fetchWithAPIKey = createFetchWithHeaders({
97924
+ headers: {
97925
+ "x-api-key": apiKey
97926
+ }
97927
+ });
97910
97928
  return {
97911
97929
  getConduitConfiguration: async () => {
97912
97930
  const result = await fetchByReference({
97913
97931
  baseURL: apiURL,
97932
+ fetch: fetchWithAPIKey,
97914
97933
  reference: API_SERVICE_CONDUIT_API_REFERENCE,
97915
97934
  route: "/conduit/api/v1/source/:sourceID/configuration",
97916
97935
  method: "GET",
@@ -97924,6 +97943,7 @@ function createAPIClient({ apiURL, inferenceSourceID }) {
97924
97943
  await fetchByReference({
97925
97944
  baseURL: apiURL,
97926
97945
  body: payload,
97946
+ fetch: fetchWithAPIKey,
97927
97947
  method: "POST",
97928
97948
  parameters: {
97929
97949
  sourceID: inferenceSourceID
@@ -97936,6 +97956,7 @@ function createAPIClient({ apiURL, inferenceSourceID }) {
97936
97956
  await fetchByReference({
97937
97957
  baseURL: apiURL,
97938
97958
  body: state,
97959
+ fetch: fetchWithAPIKey,
97939
97960
  method: "POST",
97940
97961
  parameters: {
97941
97962
  sourceID: inferenceSourceID
@@ -97948,6 +97969,7 @@ function createAPIClient({ apiURL, inferenceSourceID }) {
97948
97969
  await fetchByReference({
97949
97970
  baseURL: apiURL,
97950
97971
  body: payload,
97972
+ fetch: fetchWithAPIKey,
97951
97973
  method: "POST",
97952
97974
  parameters: {
97953
97975
  sourceID: inferenceSourceID
@@ -108485,6 +108507,91 @@ async function proxyRequest({ configuration, request }) {
108485
108507
  };
108486
108508
  }
108487
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
+
108488
108595
  class ConduitStateManager {
108489
108596
  currentState;
108490
108597
  constructor({ initialState }) {
@@ -118001,6 +118108,14 @@ async function createApplication({ abortController, apiClient, configuration, lo
118001
118108
  total: 0
118002
118109
  }
118003
118110
  });
118111
+ const conduitStateReportManager = new ConduitStateReportManager({
118112
+ apiClient,
118113
+ conduitStateManager,
118114
+ downloadProgressReportIntervalMs: 5000,
118115
+ logger,
118116
+ stateIntervalMs: 30000
118117
+ });
118118
+ await conduitStateReportManager.start();
118004
118119
  let lastDownloadKey = "";
118005
118120
  const reportDownloadProgress = (update) => {
118006
118121
  const filePercent = update.file.total > 0 ? Math.floor((update.file.bytes / update.file.total) * 100) : 0;
@@ -118022,6 +118137,7 @@ async function createApplication({ abortController, apiClient, configuration, lo
118022
118137
  total: Math.max(0, Math.floor(update.total.total))
118023
118138
  }
118024
118139
  });
118140
+ conduitStateReportManager.reportDownloadProgress();
118025
118141
  };
118026
118142
  await modelManager.prepare({
118027
118143
  onDownloadProgress: reportDownloadProgress
@@ -118086,25 +118202,6 @@ async function createApplication({ abortController, apiClient, configuration, lo
118086
118202
  mount: publicRouter,
118087
118203
  reference: API_CLIENT_INFERENCE_AGENT_API_REFERENCE
118088
118204
  });
118089
- const CONDUIT_STATE_INTERVAL_MS = 30000;
118090
- async function sendConduitState() {
118091
- try {
118092
- await apiClient.reportConduitState(conduitStateManager.touch());
118093
- }
118094
- catch (error) {
118095
- logger.error("Conduit state update failed", {
118096
- error: asError(error)
118097
- });
118098
- }
118099
- }
118100
- await sendConduitState();
118101
- setInterval(() => {
118102
- sendConduitState().catch(error => {
118103
- logger.error("Conduit state update failed", {
118104
- error: asError(error)
118105
- });
118106
- });
118107
- }, CONDUIT_STATE_INTERVAL_MS);
118108
118205
  let activeRequests = 0;
118109
118206
  const setOnlineState = () => {
118110
118207
  conduitStateManager.setState({
@@ -118203,6 +118300,7 @@ async function startInferenceAgent({ configurationOverrides }) {
118203
118300
  agentEngineType: configuration.agentEngineType
118204
118301
  });
118205
118302
  const apiClient = createAPIClient({
118303
+ apiKey: configuration.apiKey,
118206
118304
  apiURL: configuration.apiURL,
118207
118305
  inferenceSourceID: configuration.inferenceSourceID
118208
118306
  });
@@ -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.16.1",
4
+ "version": "1.17.1",
5
5
  "bin": {
6
6
  "infersec-conduit": "./dist/cli.js"
7
7
  },