@infersec/conduit 1.4.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/README.md +29 -0
- package/dist/apiClient/index.d.ts +12 -0
- package/dist/application.d.ts +10 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +134 -0
- package/dist/configuration.d.ts +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +64 -0
- package/dist/modelManagement/ModelManager.d.ts +31 -0
- package/dist/modelManagement/download.d.ts +8 -0
- package/dist/modelManagement/healthCheck.d.ts +2 -0
- package/dist/modelManagement/llamacpp.d.ts +6 -0
- package/dist/modelManagement/ollama.d.ts +4 -0
- package/dist/modelManagement/schemas.d.ts +5 -0
- package/dist/modelManagement/vllm.d.ts +5 -0
- package/dist/sse/handler.d.ts +9 -0
- package/dist/sse/requestProxy.d.ts +9 -0
- package/dist/start-CijRnu19.js +104949 -0
- package/dist/start.d.ts +4 -0
- package/dist/utils/engineMetrics.d.ts +36 -0
- package/dist/utils/machineInfo.d.ts +2 -0
- package/dist/utils/openai.d.ts +20 -0
- package/dist/utils/timer.d.ts +1 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @infersec/conduit
|
|
2
|
+
|
|
3
|
+
Inference agent for connecting local LLMs to the Infersec cloud.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx @infersec/conduit --source <source-id> --key <api-key>
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Optional flags:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
--api-url <url> API base URL
|
|
15
|
+
--engine <type> Engine type
|
|
16
|
+
--port <number> Port to listen on
|
|
17
|
+
--root <path> Root directory
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Environment variables
|
|
21
|
+
|
|
22
|
+
- AGENT_ENGINE_TYPE
|
|
23
|
+
- API_KEY
|
|
24
|
+
- API_URL
|
|
25
|
+
- INFERENCE_SOURCE_ID
|
|
26
|
+
- PORT
|
|
27
|
+
- ROOT_DIRECTORY
|
|
28
|
+
|
|
29
|
+
CLI flags override environment variables when both are provided.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InferenceAgentConfiguration, InferenceAgentHeartbeatPayload, InferenceAgentLLMMetricsPayload, InferenceAgentMachineReportPayload, ULID } from "@infersec/definitions";
|
|
2
|
+
export interface APIClient {
|
|
3
|
+
getAgentConfiguration: () => Promise<InferenceAgentConfiguration>;
|
|
4
|
+
reportHeartbeat: (payload: InferenceAgentHeartbeatPayload) => Promise<void>;
|
|
5
|
+
reportMachineMetadata: (payload: InferenceAgentMachineReportPayload) => Promise<void>;
|
|
6
|
+
reportPromptMetrics: (payload: InferenceAgentLLMMetricsPayload) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createAPIClient({ apiURL, inferenceSourceID }: {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
apiURL: string;
|
|
11
|
+
inferenceSourceID: ULID;
|
|
12
|
+
}): APIClient;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Application } from "express";
|
|
2
|
+
import { Logger } from "@infersec/logger";
|
|
3
|
+
import { APIClient } from "./apiClient/index.js";
|
|
4
|
+
import { Configuration } from "./configuration.js";
|
|
5
|
+
export declare function createApplication({ abortController, apiClient, configuration, logger }: {
|
|
6
|
+
abortController: AbortController;
|
|
7
|
+
apiClient: APIClient;
|
|
8
|
+
configuration: Configuration;
|
|
9
|
+
logger: Logger;
|
|
10
|
+
}): Promise<Application>;
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import 'node:crypto';
|
|
9
|
+
import { a as asError, s as startInferenceAgent } from './start-CijRnu19.js';
|
|
10
|
+
import 'argon2';
|
|
11
|
+
import 'node:child_process';
|
|
12
|
+
import 'node:stream';
|
|
13
|
+
import 'os';
|
|
14
|
+
import 'fs';
|
|
15
|
+
import 'util';
|
|
16
|
+
import 'assert';
|
|
17
|
+
import 'events';
|
|
18
|
+
import 'stream';
|
|
19
|
+
import 'node:assert';
|
|
20
|
+
import 'node:net';
|
|
21
|
+
import 'node:http';
|
|
22
|
+
import 'node:querystring';
|
|
23
|
+
import 'node:events';
|
|
24
|
+
import 'node:diagnostics_channel';
|
|
25
|
+
import 'node:tls';
|
|
26
|
+
import 'node:buffer';
|
|
27
|
+
import 'node:zlib';
|
|
28
|
+
import 'node:perf_hooks';
|
|
29
|
+
import 'node:util/types';
|
|
30
|
+
import 'node:worker_threads';
|
|
31
|
+
import 'node:url';
|
|
32
|
+
import 'node:async_hooks';
|
|
33
|
+
import 'node:console';
|
|
34
|
+
import 'node:fs/promises';
|
|
35
|
+
import 'node:path';
|
|
36
|
+
import 'node:dns';
|
|
37
|
+
import 'node:sqlite';
|
|
38
|
+
import 'path';
|
|
39
|
+
import 'tty';
|
|
40
|
+
import 'net';
|
|
41
|
+
import 'zlib';
|
|
42
|
+
import 'buffer';
|
|
43
|
+
import 'string_decoder';
|
|
44
|
+
import 'querystring';
|
|
45
|
+
import 'url';
|
|
46
|
+
import 'http';
|
|
47
|
+
import 'crypto';
|
|
48
|
+
import 'node:fs';
|
|
49
|
+
import 'node:string_decoder';
|
|
50
|
+
import 'node:stream/promises';
|
|
51
|
+
import 'fs/promises';
|
|
52
|
+
import 'stream/promises';
|
|
53
|
+
import 'node:os';
|
|
54
|
+
import 'node:process';
|
|
55
|
+
import 'node:tty';
|
|
56
|
+
import 'child_process';
|
|
57
|
+
import 'node:timers/promises';
|
|
58
|
+
import 'node:v8';
|
|
59
|
+
import 'systeminformation';
|
|
60
|
+
|
|
61
|
+
const USAGE = `Usage: npx @infersec/conduit --source <id> --key <key> [options]
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--api-url <url> API base URL (or API_URL)
|
|
65
|
+
--engine <type> Engine type (or AGENT_ENGINE_TYPE)
|
|
66
|
+
--key <value> API key (or API_KEY)
|
|
67
|
+
--port <number> Port to listen on (or PORT)
|
|
68
|
+
--root <path> Root directory (or ROOT_DIRECTORY)
|
|
69
|
+
--source <id> Inference source ID (or INFERENCE_SOURCE_ID)
|
|
70
|
+
-h, --help Show this help message
|
|
71
|
+
`;
|
|
72
|
+
async function run() {
|
|
73
|
+
const { values } = parseArgs({
|
|
74
|
+
allowPositionals: false,
|
|
75
|
+
options: {
|
|
76
|
+
"api-url": {
|
|
77
|
+
type: "string"
|
|
78
|
+
},
|
|
79
|
+
engine: {
|
|
80
|
+
type: "string"
|
|
81
|
+
},
|
|
82
|
+
help: {
|
|
83
|
+
short: "h",
|
|
84
|
+
type: "boolean"
|
|
85
|
+
},
|
|
86
|
+
key: {
|
|
87
|
+
type: "string"
|
|
88
|
+
},
|
|
89
|
+
port: {
|
|
90
|
+
type: "string"
|
|
91
|
+
},
|
|
92
|
+
root: {
|
|
93
|
+
type: "string"
|
|
94
|
+
},
|
|
95
|
+
source: {
|
|
96
|
+
type: "string"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (values.help) {
|
|
101
|
+
console.log(USAGE);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const configurationOverrides = {};
|
|
105
|
+
if (values.engine) {
|
|
106
|
+
configurationOverrides.agentEngineType = values.engine;
|
|
107
|
+
}
|
|
108
|
+
if (values["api-url"]) {
|
|
109
|
+
configurationOverrides.apiURL = values["api-url"];
|
|
110
|
+
}
|
|
111
|
+
if (values.key) {
|
|
112
|
+
configurationOverrides.apiKey = values.key;
|
|
113
|
+
}
|
|
114
|
+
if (values.source) {
|
|
115
|
+
configurationOverrides.inferenceSourceID = values.source;
|
|
116
|
+
}
|
|
117
|
+
if (values.root) {
|
|
118
|
+
configurationOverrides.rootDirectory = values.root;
|
|
119
|
+
}
|
|
120
|
+
if (values.port) {
|
|
121
|
+
const port = Number.parseInt(values.port, 10);
|
|
122
|
+
if (Number.isNaN(port)) {
|
|
123
|
+
throw new Error(`Invalid port: ${values.port}`);
|
|
124
|
+
}
|
|
125
|
+
configurationOverrides.port = port;
|
|
126
|
+
}
|
|
127
|
+
await startInferenceAgent({
|
|
128
|
+
configurationOverrides
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
run().catch(err => {
|
|
132
|
+
console.error(asError(err));
|
|
133
|
+
process.exit(1);
|
|
134
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LLMEngine, ULID } from "@infersec/definitions";
|
|
2
|
+
export interface Configuration {
|
|
3
|
+
agentEngineType: LLMEngine;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
apiURL: string;
|
|
6
|
+
inferenceSourceID: ULID;
|
|
7
|
+
port: number;
|
|
8
|
+
rootDirectory: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ConfigurationOverrides {
|
|
11
|
+
agentEngineType?: string;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
apiURL?: string;
|
|
14
|
+
inferenceSourceID?: ULID;
|
|
15
|
+
port?: number;
|
|
16
|
+
rootDirectory?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function getConfiguration({ overrides }?: {
|
|
19
|
+
overrides?: ConfigurationOverrides;
|
|
20
|
+
}): Configuration;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
|
|
7
|
+
import 'node:crypto';
|
|
8
|
+
import { s as startInferenceAgent, a as asError } from './start-CijRnu19.js';
|
|
9
|
+
import 'argon2';
|
|
10
|
+
import 'node:child_process';
|
|
11
|
+
import 'node:stream';
|
|
12
|
+
import 'os';
|
|
13
|
+
import 'fs';
|
|
14
|
+
import 'util';
|
|
15
|
+
import 'assert';
|
|
16
|
+
import 'events';
|
|
17
|
+
import 'stream';
|
|
18
|
+
import 'node:assert';
|
|
19
|
+
import 'node:net';
|
|
20
|
+
import 'node:http';
|
|
21
|
+
import 'node:querystring';
|
|
22
|
+
import 'node:events';
|
|
23
|
+
import 'node:diagnostics_channel';
|
|
24
|
+
import 'node:util';
|
|
25
|
+
import 'node:tls';
|
|
26
|
+
import 'node:buffer';
|
|
27
|
+
import 'node:zlib';
|
|
28
|
+
import 'node:perf_hooks';
|
|
29
|
+
import 'node:util/types';
|
|
30
|
+
import 'node:worker_threads';
|
|
31
|
+
import 'node:url';
|
|
32
|
+
import 'node:async_hooks';
|
|
33
|
+
import 'node:console';
|
|
34
|
+
import 'node:fs/promises';
|
|
35
|
+
import 'node:path';
|
|
36
|
+
import 'node:dns';
|
|
37
|
+
import 'node:sqlite';
|
|
38
|
+
import 'path';
|
|
39
|
+
import 'tty';
|
|
40
|
+
import 'net';
|
|
41
|
+
import 'zlib';
|
|
42
|
+
import 'buffer';
|
|
43
|
+
import 'string_decoder';
|
|
44
|
+
import 'querystring';
|
|
45
|
+
import 'url';
|
|
46
|
+
import 'http';
|
|
47
|
+
import 'crypto';
|
|
48
|
+
import 'node:fs';
|
|
49
|
+
import 'node:string_decoder';
|
|
50
|
+
import 'node:stream/promises';
|
|
51
|
+
import 'fs/promises';
|
|
52
|
+
import 'stream/promises';
|
|
53
|
+
import 'node:os';
|
|
54
|
+
import 'node:process';
|
|
55
|
+
import 'node:tty';
|
|
56
|
+
import 'child_process';
|
|
57
|
+
import 'node:timers/promises';
|
|
58
|
+
import 'node:v8';
|
|
59
|
+
import 'systeminformation';
|
|
60
|
+
|
|
61
|
+
startInferenceAgent({}).catch(err => {
|
|
62
|
+
console.error(asError(err));
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { LLMEngine, LLMModel } from "@infersec/definitions";
|
|
2
|
+
import { Logger } from "@infersec/logger";
|
|
3
|
+
import EventEmitter from "eventemitter3";
|
|
4
|
+
import { RequestInit, Response } from "undici";
|
|
5
|
+
interface ModelManagerEvents {
|
|
6
|
+
engineError: (error: Error) => void;
|
|
7
|
+
engineReady: () => void;
|
|
8
|
+
engineTerminated: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare class ModelManager extends EventEmitter<ModelManagerEvents> {
|
|
11
|
+
readonly engine: LLMEngine;
|
|
12
|
+
readonly model: LLMModel;
|
|
13
|
+
readonly parallelism: number | null;
|
|
14
|
+
private uniqueName;
|
|
15
|
+
readonly contextLength: number | null;
|
|
16
|
+
protected readonly logger: Logger;
|
|
17
|
+
private engineProcess;
|
|
18
|
+
protected readonly modelsDirectory: string;
|
|
19
|
+
constructor({ contextLength, engine, logger, model, parallelism, root }: {
|
|
20
|
+
contextLength?: number | null;
|
|
21
|
+
engine: LLMEngine;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
model: LLMModel;
|
|
24
|
+
parallelism?: number | null;
|
|
25
|
+
root: string;
|
|
26
|
+
});
|
|
27
|
+
fetchOpenAI(path: string, opts?: RequestInit): Promise<Response>;
|
|
28
|
+
prepare(): Promise<void>;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LLMModel } from "@infersec/definitions";
|
|
2
|
+
export declare function downloadModelViaHuggingFace({ format, huggingFaceToken, modelSlug: rawModelSlug, progressFilePath, targetDirectory }: {
|
|
3
|
+
format: LLMModel["format"];
|
|
4
|
+
huggingFaceToken: string | null | undefined;
|
|
5
|
+
modelSlug: string;
|
|
6
|
+
progressFilePath: string;
|
|
7
|
+
targetDirectory: string;
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProcessManager } from "@infersec/utils";
|
|
2
|
+
import { ModelManager } from "./ModelManager.js";
|
|
3
|
+
export declare function startLlamacpp(this: ModelManager, { targetDirectory }: {
|
|
4
|
+
targetDirectory: string;
|
|
5
|
+
}): Promise<ProcessManager>;
|
|
6
|
+
export declare function checkLlamacppHealth(): Promise<boolean>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type APIResponse, type ServerToClientAPIRequest } from "@infersec/definitions";
|
|
2
|
+
import { Logger } from "@infersec/logger";
|
|
3
|
+
import { Configuration } from "../configuration.js";
|
|
4
|
+
export declare function handleSSERequests({ apiURL, configuration, logger, onRequest }: {
|
|
5
|
+
apiURL: string;
|
|
6
|
+
configuration: Configuration;
|
|
7
|
+
logger: Logger;
|
|
8
|
+
onRequest: (request: ServerToClientAPIRequest) => Promise<APIResponse>;
|
|
9
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { APIResponse, ServerToClientAPIRequest } from "@infersec/definitions";
|
|
2
|
+
import type { Configuration } from "../configuration.js";
|
|
3
|
+
/**
|
|
4
|
+
* Proxy server requests to the local inference HTTP server.
|
|
5
|
+
*/
|
|
6
|
+
export declare function proxyRequest({ configuration, request }: {
|
|
7
|
+
configuration: Configuration;
|
|
8
|
+
request: ServerToClientAPIRequest;
|
|
9
|
+
}): Promise<APIResponse>;
|