@infersec/conduit 1.41.0 → 1.42.0
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/requestHandlers/createConduitAnthropicAPIReferenceHandlers.d.ts +2 -2
- package/dist/requestHandlers/createConduitOpenAIAPIReferenceHandlers.d.ts +4 -4
- package/dist/{start-CPrgh7rN.js → start-DGdf6ycx.js} +60 -29
- package/dist/utils/anthropic.d.ts +2 -1
- package/dist/utils/openai.d.ts +2 -1
- 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-DGdf6ycx.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-DGdf6ycx.js';
|
|
9
9
|
import 'argon2';
|
|
10
10
|
import 'node:child_process';
|
|
11
11
|
import 'node:stream';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { API_CLIENT_CONDUIT_ANTHROPIC_REFERENCE } from "@infersec/definitions";
|
|
2
|
-
import { implementAPIReference } from "@infersec/fetch";
|
|
2
|
+
import { implementAPIReference, type APIRequest } from "@infersec/fetch";
|
|
3
3
|
import { Logger } from "@infersec/logger";
|
|
4
4
|
import { APIClient } from "../apiClient/index.js";
|
|
5
5
|
import { Configuration } from "../configuration.js";
|
|
@@ -19,7 +19,7 @@ export declare function createPostMessagesHandler(options: {
|
|
|
19
19
|
getModelManager: () => ModelManager;
|
|
20
20
|
logger: Logger;
|
|
21
21
|
}): (params: {
|
|
22
|
-
req:
|
|
22
|
+
req: APIRequest;
|
|
23
23
|
res: import("@infersec/fetch").APIResponse;
|
|
24
24
|
parameters: Record<string, never>;
|
|
25
25
|
query: Record<string, never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { API_CLIENT_CONDUIT_OPENAI_REFERENCE } from "@infersec/definitions";
|
|
2
|
-
import { implementAPIReference } from "@infersec/fetch";
|
|
2
|
+
import { implementAPIReference, type APIRequest } from "@infersec/fetch";
|
|
3
3
|
import { Logger } from "@infersec/logger";
|
|
4
4
|
import { APIClient } from "../apiClient/index.js";
|
|
5
5
|
import { Configuration } from "../configuration.js";
|
|
@@ -21,7 +21,7 @@ export declare function createGetModelsHandler(options: {
|
|
|
21
21
|
logger: Logger;
|
|
22
22
|
startup: number;
|
|
23
23
|
}): (params: {
|
|
24
|
-
req:
|
|
24
|
+
req: APIRequest;
|
|
25
25
|
res: import("@infersec/fetch").APIResponse;
|
|
26
26
|
parameters: Record<string, never>;
|
|
27
27
|
query: Record<string, never>;
|
|
@@ -66,7 +66,7 @@ export declare function createPostChatCompletionsHandler(options: {
|
|
|
66
66
|
logger: Logger;
|
|
67
67
|
startup: number;
|
|
68
68
|
}): (params: {
|
|
69
|
-
req:
|
|
69
|
+
req: APIRequest;
|
|
70
70
|
res: import("@infersec/fetch").APIResponse;
|
|
71
71
|
parameters: Record<string, never>;
|
|
72
72
|
query: Record<string, never>;
|
|
@@ -172,7 +172,7 @@ export declare function createPostCompletionsHandler(options: {
|
|
|
172
172
|
logger: Logger;
|
|
173
173
|
startup: number;
|
|
174
174
|
}): (params: {
|
|
175
|
-
req:
|
|
175
|
+
req: APIRequest;
|
|
176
176
|
res: import("@infersec/fetch").APIResponse;
|
|
177
177
|
parameters: Record<string, never>;
|
|
178
178
|
query: Record<string, never>;
|
|
@@ -15622,21 +15622,30 @@ const ServerToClientAPIRequestSchema = APIRequestSchema.extend({
|
|
|
15622
15622
|
|
|
15623
15623
|
_enum(["inf-end", "inf-src", "storage"]);
|
|
15624
15624
|
|
|
15625
|
-
const
|
|
15626
|
-
|
|
15627
|
-
|
|
15628
|
-
|
|
15629
|
-
endpoints: number$1().int().nonnegative(),
|
|
15630
|
-
sources: number$1().int().nonnegative(),
|
|
15631
|
-
users: number$1().int().nonnegative()
|
|
15632
|
-
}),
|
|
15633
|
-
monthlyCostEUR: number$1().int().nonnegative(),
|
|
15634
|
-
name: string$1(),
|
|
15635
|
-
slug: PlanSlugSchema,
|
|
15636
|
-
trialDays: number$1().int().positive().nullable(),
|
|
15637
|
-
websiteFeatures: array(string$1()),
|
|
15638
|
-
websiteIconPath: string$1()
|
|
15625
|
+
const ConnectedSourceMetaSchema = object({
|
|
15626
|
+
chargeName: literal("connected_source"),
|
|
15627
|
+
unitCost: number$1(),
|
|
15628
|
+
units: number$1()
|
|
15639
15629
|
});
|
|
15630
|
+
const TokenInputMetaSchema = object({
|
|
15631
|
+
chargeName: literal("tokens_input"),
|
|
15632
|
+
modelId: string$1().nullable(),
|
|
15633
|
+
requestId: string$1().nullable(),
|
|
15634
|
+
unitCost: number$1(),
|
|
15635
|
+
units: number$1()
|
|
15636
|
+
});
|
|
15637
|
+
const TokenOutputMetaSchema = object({
|
|
15638
|
+
chargeName: literal("tokens_output"),
|
|
15639
|
+
modelId: string$1().nullable(),
|
|
15640
|
+
requestId: string$1().nullable(),
|
|
15641
|
+
unitCost: number$1(),
|
|
15642
|
+
units: number$1()
|
|
15643
|
+
});
|
|
15644
|
+
discriminatedUnion("chargeName", [
|
|
15645
|
+
ConnectedSourceMetaSchema,
|
|
15646
|
+
TokenInputMetaSchema,
|
|
15647
|
+
TokenOutputMetaSchema
|
|
15648
|
+
]);
|
|
15640
15649
|
|
|
15641
15650
|
function readEnvIntegerOptional({ defaultValue, name }) {
|
|
15642
15651
|
const str = readEnvStringOptional(name, `${defaultValue}`).trim();
|
|
@@ -109465,7 +109474,7 @@ function calculateTokensPerSecond$2({ durationMs, totalTokens }) {
|
|
|
109465
109474
|
}
|
|
109466
109475
|
return Math.round(tokensPerSecond);
|
|
109467
109476
|
}
|
|
109468
|
-
async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID, modelManager, path, reportMetrics, signal }) {
|
|
109477
|
+
async function proxyOpenAIStreamingRoute({ body, configuration, endpointId, logger, modelID, modelManager, path, reportMetrics, signal }) {
|
|
109469
109478
|
function normalizeTokenCount(value) {
|
|
109470
109479
|
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
109471
109480
|
return value;
|
|
@@ -109493,7 +109502,7 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID,
|
|
|
109493
109502
|
bytes: requestBodyBytes + responseBytes,
|
|
109494
109503
|
completionTokens,
|
|
109495
109504
|
engine: configuration.agentEngineType,
|
|
109496
|
-
endpointId: null,
|
|
109505
|
+
endpointId: endpointId ?? null,
|
|
109497
109506
|
latencyMs,
|
|
109498
109507
|
modelId: modelID,
|
|
109499
109508
|
promptTokens,
|
|
@@ -109536,7 +109545,7 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID,
|
|
|
109536
109545
|
bytes: requestBodyBytes,
|
|
109537
109546
|
completionTokens: 0,
|
|
109538
109547
|
engine: configuration.agentEngineType,
|
|
109539
|
-
endpointId: null,
|
|
109548
|
+
endpointId: endpointId ?? null,
|
|
109540
109549
|
latencyMs,
|
|
109541
109550
|
modelId: modelID,
|
|
109542
109551
|
promptTokens: 0,
|
|
@@ -109586,7 +109595,7 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID,
|
|
|
109586
109595
|
bytes: requestBodyBytes,
|
|
109587
109596
|
completionTokens: 0,
|
|
109588
109597
|
engine: configuration.agentEngineType,
|
|
109589
|
-
endpointId: null,
|
|
109598
|
+
endpointId: endpointId ?? null,
|
|
109590
109599
|
latencyMs,
|
|
109591
109600
|
modelId: modelID,
|
|
109592
109601
|
promptTokens: 0,
|
|
@@ -109637,10 +109646,15 @@ async function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID,
|
|
|
109637
109646
|
};
|
|
109638
109647
|
}
|
|
109639
109648
|
|
|
109649
|
+
function extractEndpointId$1(req) {
|
|
109650
|
+
const value = req.headers["x-endpoint-id"];
|
|
109651
|
+
const raw = typeof value === "string" ? value : Array.isArray(value) ? value[0] : null;
|
|
109652
|
+
return raw && isValid(raw) ? raw : null;
|
|
109653
|
+
}
|
|
109640
109654
|
function createConduitOpenAIAPIReferenceHandlers({ apiClient, configuration, getModelID, getModelManager, logger, startup }) {
|
|
109641
109655
|
return {
|
|
109642
109656
|
"/v1/chat/completions": {
|
|
109643
|
-
POST: async ({ body, res }) => {
|
|
109657
|
+
POST: async ({ body, req, res }) => {
|
|
109644
109658
|
const modelID = getModelID();
|
|
109645
109659
|
const modelManager = getModelManager();
|
|
109646
109660
|
const abortController = new AbortController();
|
|
@@ -109650,6 +109664,7 @@ function createConduitOpenAIAPIReferenceHandlers({ apiClient, configuration, get
|
|
|
109650
109664
|
return proxyOpenAIStreamingRoute({
|
|
109651
109665
|
body,
|
|
109652
109666
|
configuration,
|
|
109667
|
+
endpointId: extractEndpointId$1(req),
|
|
109653
109668
|
logger,
|
|
109654
109669
|
modelID,
|
|
109655
109670
|
modelManager,
|
|
@@ -109660,7 +109675,7 @@ function createConduitOpenAIAPIReferenceHandlers({ apiClient, configuration, get
|
|
|
109660
109675
|
}
|
|
109661
109676
|
},
|
|
109662
109677
|
"/v1/completions": {
|
|
109663
|
-
POST: async ({ body, res }) => {
|
|
109678
|
+
POST: async ({ body, req, res }) => {
|
|
109664
109679
|
const modelID = getModelID();
|
|
109665
109680
|
const modelManager = getModelManager();
|
|
109666
109681
|
const abortController = new AbortController();
|
|
@@ -109670,6 +109685,7 @@ function createConduitOpenAIAPIReferenceHandlers({ apiClient, configuration, get
|
|
|
109670
109685
|
return proxyOpenAIStreamingRoute({
|
|
109671
109686
|
body,
|
|
109672
109687
|
configuration,
|
|
109688
|
+
endpointId: extractEndpointId$1(req),
|
|
109673
109689
|
logger,
|
|
109674
109690
|
modelID,
|
|
109675
109691
|
modelManager,
|
|
@@ -109789,7 +109805,7 @@ function extractAnthropicNonStreamUsage(body) {
|
|
|
109789
109805
|
return null;
|
|
109790
109806
|
}
|
|
109791
109807
|
}
|
|
109792
|
-
async function proxyAnthropicStreamingRoute({ body, configuration, logger, modelID, modelManager, reportMetrics, signal }) {
|
|
109808
|
+
async function proxyAnthropicStreamingRoute({ body, configuration, endpointId, logger, modelID, modelManager, reportMetrics, signal }) {
|
|
109793
109809
|
function reportMetricsSafe(payload) {
|
|
109794
109810
|
reportMetrics(payload).catch(error => {
|
|
109795
109811
|
logger.warn("Failed to upload LLM prompt metrics", {
|
|
@@ -109811,7 +109827,7 @@ async function proxyAnthropicStreamingRoute({ body, configuration, logger, model
|
|
|
109811
109827
|
bytes: requestBodyBytes + responseBytes,
|
|
109812
109828
|
completionTokens,
|
|
109813
109829
|
engine: configuration.agentEngineType,
|
|
109814
|
-
endpointId: null,
|
|
109830
|
+
endpointId: endpointId ?? null,
|
|
109815
109831
|
latencyMs,
|
|
109816
109832
|
modelId: modelID,
|
|
109817
109833
|
promptTokens,
|
|
@@ -109854,7 +109870,7 @@ async function proxyAnthropicStreamingRoute({ body, configuration, logger, model
|
|
|
109854
109870
|
bytes: requestBodyBytes,
|
|
109855
109871
|
completionTokens: 0,
|
|
109856
109872
|
engine: configuration.agentEngineType,
|
|
109857
|
-
endpointId: null,
|
|
109873
|
+
endpointId: endpointId ?? null,
|
|
109858
109874
|
latencyMs,
|
|
109859
109875
|
modelId: modelID,
|
|
109860
109876
|
promptTokens: 0,
|
|
@@ -109899,7 +109915,7 @@ async function proxyAnthropicStreamingRoute({ body, configuration, logger, model
|
|
|
109899
109915
|
bytes: requestBodyBytes,
|
|
109900
109916
|
completionTokens: 0,
|
|
109901
109917
|
engine: configuration.agentEngineType,
|
|
109902
|
-
endpointId: null,
|
|
109918
|
+
endpointId: endpointId ?? null,
|
|
109903
109919
|
latencyMs,
|
|
109904
109920
|
modelId: modelID,
|
|
109905
109921
|
promptTokens: 0,
|
|
@@ -110077,10 +110093,15 @@ async function proxyAnthropicStreamingRoute({ body, configuration, logger, model
|
|
|
110077
110093
|
};
|
|
110078
110094
|
}
|
|
110079
110095
|
|
|
110096
|
+
function extractEndpointId(req) {
|
|
110097
|
+
const value = req.headers["x-endpoint-id"];
|
|
110098
|
+
const raw = typeof value === "string" ? value : Array.isArray(value) ? value[0] : null;
|
|
110099
|
+
return raw && isValid(raw) ? raw : null;
|
|
110100
|
+
}
|
|
110080
110101
|
function createConduitAnthropicAPIReferenceHandlers({ apiClient, configuration, getModelID, getModelManager, logger }) {
|
|
110081
110102
|
return {
|
|
110082
110103
|
"/v1/messages": {
|
|
110083
|
-
POST: async ({ body, res }) => {
|
|
110104
|
+
POST: async ({ body, req, res }) => {
|
|
110084
110105
|
const modelID = getModelID();
|
|
110085
110106
|
const modelManager = getModelManager();
|
|
110086
110107
|
const abortController = new AbortController();
|
|
@@ -110090,6 +110111,7 @@ function createConduitAnthropicAPIReferenceHandlers({ apiClient, configuration,
|
|
|
110090
110111
|
return proxyAnthropicStreamingRoute({
|
|
110091
110112
|
body,
|
|
110092
110113
|
configuration,
|
|
110114
|
+
endpointId: extractEndpointId(req),
|
|
110093
110115
|
logger,
|
|
110094
110116
|
modelID,
|
|
110095
110117
|
modelManager,
|
|
@@ -110146,6 +110168,9 @@ async function handleSSERequests({ apiURL, configuration, logger, modelID, onReq
|
|
|
110146
110168
|
const payload = ServerToClientAPIRequestSchema.parse(JSON.parse(message.data));
|
|
110147
110169
|
const perRequestController = new AbortController();
|
|
110148
110170
|
activeRequests.set(payload.requestID, perRequestController);
|
|
110171
|
+
const effectiveSignal = signal
|
|
110172
|
+
? AbortSignal.any([perRequestController.signal, signal])
|
|
110173
|
+
: perRequestController.signal;
|
|
110149
110174
|
handleRequest({
|
|
110150
110175
|
activeRequests,
|
|
110151
110176
|
apiURL,
|
|
@@ -110157,7 +110182,7 @@ async function handleSSERequests({ apiURL, configuration, logger, modelID, onReq
|
|
|
110157
110182
|
onRequestStart,
|
|
110158
110183
|
reportMetrics,
|
|
110159
110184
|
request: payload,
|
|
110160
|
-
signal:
|
|
110185
|
+
signal: effectiveSignal
|
|
110161
110186
|
}).catch(error => {
|
|
110162
110187
|
logger.error("SSE request handler failed", {
|
|
110163
110188
|
error: asError(error),
|
|
@@ -110201,6 +110226,7 @@ async function handleRequest({ activeRequests, apiURL, configuration, logger, mo
|
|
|
110201
110226
|
});
|
|
110202
110227
|
});
|
|
110203
110228
|
}
|
|
110229
|
+
const endpointId = request.parameters?.endpointID ?? null;
|
|
110204
110230
|
const requestStartedAt = Date.now();
|
|
110205
110231
|
const requestBytes = calculateRequestBytes(request.body ?? null);
|
|
110206
110232
|
try {
|
|
@@ -110225,7 +110251,7 @@ async function handleRequest({ activeRequests, apiURL, configuration, logger, mo
|
|
|
110225
110251
|
bytes: requestBytes + responseMetrics.responseBytes,
|
|
110226
110252
|
completionTokens: 0,
|
|
110227
110253
|
engine: configuration.agentEngineType,
|
|
110228
|
-
endpointId
|
|
110254
|
+
endpointId,
|
|
110229
110255
|
latencyMs,
|
|
110230
110256
|
modelId: modelID,
|
|
110231
110257
|
promptTokens: 0,
|
|
@@ -110279,7 +110305,7 @@ async function handleRequest({ activeRequests, apiURL, configuration, logger, mo
|
|
|
110279
110305
|
bytes: isCancelled ? requestBytes : requestBytes + failureBytes,
|
|
110280
110306
|
completionTokens: 0,
|
|
110281
110307
|
engine: configuration.agentEngineType,
|
|
110282
|
-
endpointId
|
|
110308
|
+
endpointId,
|
|
110283
110309
|
latencyMs,
|
|
110284
110310
|
modelId: modelID,
|
|
110285
110311
|
promptTokens: 0,
|
|
@@ -110508,7 +110534,12 @@ async function proxyRequest({ configuration, request, signal }) {
|
|
|
110508
110534
|
}
|
|
110509
110535
|
const fetchOptions = {
|
|
110510
110536
|
method: request.method,
|
|
110511
|
-
headers:
|
|
110537
|
+
headers: {
|
|
110538
|
+
...request.headers,
|
|
110539
|
+
...(request.parameters?.endpointID
|
|
110540
|
+
? { "x-endpoint-id": request.parameters.endpointID }
|
|
110541
|
+
: undefined)
|
|
110542
|
+
}
|
|
110512
110543
|
};
|
|
110513
110544
|
if (signal) {
|
|
110514
110545
|
fetchOptions.signal = signal;
|
|
@@ -3,9 +3,10 @@ import { InferenceAgentLLMMetricsPayload, type ULID } from "@infersec/definition
|
|
|
3
3
|
import { Logger } from "@infersec/logger";
|
|
4
4
|
import { Configuration } from "../configuration.js";
|
|
5
5
|
import { ModelManager } from "../modelManagement/ModelManager.js";
|
|
6
|
-
export declare function proxyAnthropicStreamingRoute({ body, configuration, logger, modelID, modelManager, reportMetrics, signal }: {
|
|
6
|
+
export declare function proxyAnthropicStreamingRoute({ body, configuration, endpointId, logger, modelID, modelManager, reportMetrics, signal }: {
|
|
7
7
|
body: unknown;
|
|
8
8
|
configuration: Configuration;
|
|
9
|
+
endpointId?: ULID | null;
|
|
9
10
|
logger: Logger;
|
|
10
11
|
modelID: ULID;
|
|
11
12
|
modelManager: ModelManager;
|
package/dist/utils/openai.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { InferenceAgentLLMMetricsPayload, type ULID } from "@infersec/definition
|
|
|
3
3
|
import { Logger } from "@infersec/logger";
|
|
4
4
|
import { Configuration } from "../configuration.js";
|
|
5
5
|
import { ModelManager } from "../modelManagement/ModelManager.js";
|
|
6
|
-
export declare function proxyOpenAIStreamingRoute({ body, configuration, logger, modelID, modelManager, path, reportMetrics, signal }: {
|
|
6
|
+
export declare function proxyOpenAIStreamingRoute({ body, configuration, endpointId, logger, modelID, modelManager, path, reportMetrics, signal }: {
|
|
7
7
|
body: unknown;
|
|
8
8
|
configuration: Configuration;
|
|
9
|
+
endpointId?: ULID | null;
|
|
9
10
|
logger: Logger;
|
|
10
11
|
modelID: ULID;
|
|
11
12
|
modelManager: ModelManager;
|