@llmgateway/ai-sdk-provider 3.4.0 → 3.6.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/README.md +3 -3
- package/dist/index.d.mts +11 -40
- package/dist/index.d.ts +11 -40
- package/dist/index.js +111 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -69
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -39
- package/dist/internal/index.d.ts +10 -39
- package/dist/internal/index.js +111 -69
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +111 -69
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
2
|
+
export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
3
3
|
import { models, Provider } from '@llmgateway/models';
|
|
4
4
|
export { Model, ModelDefinition, Provider, ProviderModelMapping, StabilityLevel, models } from '@llmgateway/models';
|
|
5
5
|
|
|
@@ -107,18 +107,17 @@ type LLMGatewayCompletionConfig = {
|
|
|
107
107
|
fetch?: typeof fetch;
|
|
108
108
|
extraBody?: Record<string, unknown>;
|
|
109
109
|
};
|
|
110
|
-
declare class LLMGatewayCompletionLanguageModel implements
|
|
111
|
-
readonly specificationVersion: "
|
|
110
|
+
declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
|
|
111
|
+
readonly specificationVersion: "v3";
|
|
112
112
|
readonly provider = "llmgateway";
|
|
113
113
|
readonly modelId: LLMGatewayChatModelId;
|
|
114
114
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
115
|
-
readonly defaultObjectGenerationMode: undefined;
|
|
116
115
|
readonly settings: LLMGatewayCompletionSettings;
|
|
117
116
|
private readonly config;
|
|
118
117
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
|
|
119
118
|
private getArgs;
|
|
120
|
-
doGenerate(options:
|
|
121
|
-
doStream(options:
|
|
119
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
|
120
|
+
doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
type LLMGatewayImageConfig = {
|
|
@@ -389,45 +388,17 @@ type LLMGatewayChatConfig = {
|
|
|
389
388
|
fetch?: typeof fetch;
|
|
390
389
|
extraBody?: Record<string, unknown>;
|
|
391
390
|
};
|
|
392
|
-
declare class LLMGatewayChatLanguageModel implements
|
|
393
|
-
readonly specificationVersion: "
|
|
391
|
+
declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
|
|
392
|
+
readonly specificationVersion: "v3";
|
|
394
393
|
readonly provider = "llmgateway";
|
|
395
|
-
readonly defaultObjectGenerationMode: "tool";
|
|
396
394
|
readonly modelId: LLMGatewayChatModelId;
|
|
397
395
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
398
396
|
readonly settings: LLMGatewayChatSettings;
|
|
399
397
|
private readonly config;
|
|
400
398
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
|
|
401
399
|
private getArgs;
|
|
402
|
-
doGenerate(options:
|
|
403
|
-
|
|
404
|
-
finishReason: LanguageModelV2FinishReason;
|
|
405
|
-
usage: LanguageModelV2Usage;
|
|
406
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
407
|
-
providerMetadata?: {
|
|
408
|
-
llmgateway: {
|
|
409
|
-
usage: LLMGatewayUsageAccounting;
|
|
410
|
-
};
|
|
411
|
-
};
|
|
412
|
-
request?: {
|
|
413
|
-
body?: unknown;
|
|
414
|
-
};
|
|
415
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
416
|
-
headers?: SharedV2Headers;
|
|
417
|
-
body?: unknown;
|
|
418
|
-
};
|
|
419
|
-
}>;
|
|
420
|
-
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
421
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
422
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
423
|
-
request?: {
|
|
424
|
-
body?: unknown;
|
|
425
|
-
};
|
|
426
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
427
|
-
headers?: SharedV2Headers;
|
|
428
|
-
body?: unknown;
|
|
429
|
-
};
|
|
430
|
-
}>;
|
|
400
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
401
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
431
402
|
}
|
|
432
403
|
|
|
433
404
|
export { LLMGatewayChatLanguageModel, type LLMGatewayChatModelId, type LLMGatewayChatSettings, LLMGatewayCompletionLanguageModel, type LLMGatewayCompletionSettings, LLMGatewayImageModel, type LLMGatewayImageModelId, type LLMGatewayImageSettings, type LLMGatewayProviderOptions, type LLMGatewaySharedSettings, type LLMGatewayUsageAccounting, type ProviderId, providers };
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
2
|
+
export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
3
3
|
import { models, Provider } from '@llmgateway/models';
|
|
4
4
|
export { Model, ModelDefinition, Provider, ProviderModelMapping, StabilityLevel, models } from '@llmgateway/models';
|
|
5
5
|
|
|
@@ -107,18 +107,17 @@ type LLMGatewayCompletionConfig = {
|
|
|
107
107
|
fetch?: typeof fetch;
|
|
108
108
|
extraBody?: Record<string, unknown>;
|
|
109
109
|
};
|
|
110
|
-
declare class LLMGatewayCompletionLanguageModel implements
|
|
111
|
-
readonly specificationVersion: "
|
|
110
|
+
declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
|
|
111
|
+
readonly specificationVersion: "v3";
|
|
112
112
|
readonly provider = "llmgateway";
|
|
113
113
|
readonly modelId: LLMGatewayChatModelId;
|
|
114
114
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
115
|
-
readonly defaultObjectGenerationMode: undefined;
|
|
116
115
|
readonly settings: LLMGatewayCompletionSettings;
|
|
117
116
|
private readonly config;
|
|
118
117
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
|
|
119
118
|
private getArgs;
|
|
120
|
-
doGenerate(options:
|
|
121
|
-
doStream(options:
|
|
119
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
|
120
|
+
doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
|
122
121
|
}
|
|
123
122
|
|
|
124
123
|
type LLMGatewayImageConfig = {
|
|
@@ -389,45 +388,17 @@ type LLMGatewayChatConfig = {
|
|
|
389
388
|
fetch?: typeof fetch;
|
|
390
389
|
extraBody?: Record<string, unknown>;
|
|
391
390
|
};
|
|
392
|
-
declare class LLMGatewayChatLanguageModel implements
|
|
393
|
-
readonly specificationVersion: "
|
|
391
|
+
declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
|
|
392
|
+
readonly specificationVersion: "v3";
|
|
394
393
|
readonly provider = "llmgateway";
|
|
395
|
-
readonly defaultObjectGenerationMode: "tool";
|
|
396
394
|
readonly modelId: LLMGatewayChatModelId;
|
|
397
395
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
398
396
|
readonly settings: LLMGatewayChatSettings;
|
|
399
397
|
private readonly config;
|
|
400
398
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
|
|
401
399
|
private getArgs;
|
|
402
|
-
doGenerate(options:
|
|
403
|
-
|
|
404
|
-
finishReason: LanguageModelV2FinishReason;
|
|
405
|
-
usage: LanguageModelV2Usage;
|
|
406
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
407
|
-
providerMetadata?: {
|
|
408
|
-
llmgateway: {
|
|
409
|
-
usage: LLMGatewayUsageAccounting;
|
|
410
|
-
};
|
|
411
|
-
};
|
|
412
|
-
request?: {
|
|
413
|
-
body?: unknown;
|
|
414
|
-
};
|
|
415
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
416
|
-
headers?: SharedV2Headers;
|
|
417
|
-
body?: unknown;
|
|
418
|
-
};
|
|
419
|
-
}>;
|
|
420
|
-
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
421
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
422
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
423
|
-
request?: {
|
|
424
|
-
body?: unknown;
|
|
425
|
-
};
|
|
426
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
427
|
-
headers?: SharedV2Headers;
|
|
428
|
-
body?: unknown;
|
|
429
|
-
};
|
|
430
|
-
}>;
|
|
400
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
401
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
431
402
|
}
|
|
432
403
|
|
|
433
404
|
export { LLMGatewayChatLanguageModel, type LLMGatewayChatModelId, type LLMGatewayChatSettings, LLMGatewayCompletionLanguageModel, type LLMGatewayCompletionSettings, LLMGatewayImageModel, type LLMGatewayImageModelId, type LLMGatewayImageSettings, type LLMGatewayProviderOptions, type LLMGatewaySharedSettings, type LLMGatewayUsageAccounting, type ProviderId, providers };
|
package/dist/internal/index.js
CHANGED
|
@@ -2219,16 +2219,16 @@ var llmgatewayFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
2219
2219
|
function mapLLMGatewayFinishReason(finishReason) {
|
|
2220
2220
|
switch (finishReason) {
|
|
2221
2221
|
case "stop":
|
|
2222
|
-
return "stop";
|
|
2222
|
+
return { unified: "stop", raw: finishReason };
|
|
2223
2223
|
case "length":
|
|
2224
|
-
return "length";
|
|
2224
|
+
return { unified: "length", raw: finishReason };
|
|
2225
2225
|
case "content_filter":
|
|
2226
|
-
return "content-filter";
|
|
2226
|
+
return { unified: "content-filter", raw: finishReason };
|
|
2227
2227
|
case "function_call":
|
|
2228
2228
|
case "tool_calls":
|
|
2229
|
-
return "tool-calls";
|
|
2229
|
+
return { unified: "tool-calls", raw: finishReason };
|
|
2230
2230
|
default:
|
|
2231
|
-
return "
|
|
2231
|
+
return { unified: "other", raw: finishReason != null ? finishReason : void 0 };
|
|
2232
2232
|
}
|
|
2233
2233
|
}
|
|
2234
2234
|
|
|
@@ -2431,6 +2431,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2431
2431
|
}
|
|
2432
2432
|
case "tool": {
|
|
2433
2433
|
for (const toolResponse of content) {
|
|
2434
|
+
if (toolResponse.type !== "tool-result") continue;
|
|
2434
2435
|
const content2 = getToolResultContent(toolResponse);
|
|
2435
2436
|
messages.push({
|
|
2436
2437
|
role: "tool",
|
|
@@ -2449,7 +2450,14 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2449
2450
|
return messages;
|
|
2450
2451
|
}
|
|
2451
2452
|
function getToolResultContent(input) {
|
|
2452
|
-
|
|
2453
|
+
switch (input.output.type) {
|
|
2454
|
+
case "text":
|
|
2455
|
+
return input.output.value;
|
|
2456
|
+
case "json":
|
|
2457
|
+
return JSON.stringify(input.output.value);
|
|
2458
|
+
default:
|
|
2459
|
+
return JSON.stringify(input.output);
|
|
2460
|
+
}
|
|
2453
2461
|
}
|
|
2454
2462
|
|
|
2455
2463
|
// src/chat/get-tool-choice.ts
|
|
@@ -2515,10 +2523,7 @@ var LLMGatewayChatCompletionBaseResponseSchema = import_v45.z.object({
|
|
|
2515
2523
|
reasoning_tokens: import_v45.z.number()
|
|
2516
2524
|
}).nullish(),
|
|
2517
2525
|
total_tokens: import_v45.z.number(),
|
|
2518
|
-
cost: import_v45.z.union([
|
|
2519
|
-
import_v45.z.number(),
|
|
2520
|
-
import_v45.z.object({ total_cost: import_v45.z.number() }).passthrough()
|
|
2521
|
-
]).optional(),
|
|
2526
|
+
cost: import_v45.z.union([import_v45.z.number(), import_v45.z.object({ total_cost: import_v45.z.number() }).passthrough()]).optional(),
|
|
2522
2527
|
cost_details: import_v45.z.object({
|
|
2523
2528
|
upstream_inference_cost: import_v45.z.number().nullish()
|
|
2524
2529
|
}).nullish()
|
|
@@ -2622,9 +2627,8 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
|
2622
2627
|
// src/chat/index.ts
|
|
2623
2628
|
var LLMGatewayChatLanguageModel = class {
|
|
2624
2629
|
constructor(modelId, settings, config) {
|
|
2625
|
-
this.specificationVersion = "
|
|
2630
|
+
this.specificationVersion = "v3";
|
|
2626
2631
|
this.provider = "llmgateway";
|
|
2627
|
-
this.defaultObjectGenerationMode = "tool";
|
|
2628
2632
|
this.supportedUrls = {
|
|
2629
2633
|
"image/*": [
|
|
2630
2634
|
/^data:image\/[a-zA-Z]+;base64,/,
|
|
@@ -2713,7 +2717,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2713
2717
|
return baseArgs;
|
|
2714
2718
|
}
|
|
2715
2719
|
async doGenerate(options) {
|
|
2716
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y
|
|
2720
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
2717
2721
|
const providerOptions = options.providerOptions || {};
|
|
2718
2722
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2719
2723
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2737,19 +2741,31 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2737
2741
|
throw new Error("No choice in response");
|
|
2738
2742
|
}
|
|
2739
2743
|
const usageInfo = response.usage ? {
|
|
2740
|
-
inputTokens:
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2744
|
+
inputTokens: {
|
|
2745
|
+
total: (_b16 = response.usage.prompt_tokens) != null ? _b16 : void 0,
|
|
2746
|
+
noCache: void 0,
|
|
2747
|
+
cacheRead: (_d = (_c = response.usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : void 0,
|
|
2748
|
+
cacheWrite: void 0
|
|
2749
|
+
},
|
|
2750
|
+
outputTokens: {
|
|
2751
|
+
total: (_e = response.usage.completion_tokens) != null ? _e : void 0,
|
|
2752
|
+
text: void 0,
|
|
2753
|
+
reasoning: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0
|
|
2754
|
+
}
|
|
2745
2755
|
} : {
|
|
2746
|
-
inputTokens:
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2756
|
+
inputTokens: {
|
|
2757
|
+
total: void 0,
|
|
2758
|
+
noCache: void 0,
|
|
2759
|
+
cacheRead: void 0,
|
|
2760
|
+
cacheWrite: void 0
|
|
2761
|
+
},
|
|
2762
|
+
outputTokens: {
|
|
2763
|
+
total: void 0,
|
|
2764
|
+
text: void 0,
|
|
2765
|
+
reasoning: void 0
|
|
2766
|
+
}
|
|
2751
2767
|
};
|
|
2752
|
-
const reasoningDetails = (
|
|
2768
|
+
const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
|
|
2753
2769
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
2754
2770
|
switch (detail.type) {
|
|
2755
2771
|
case "reasoning.text" /* Text */: {
|
|
@@ -2805,7 +2821,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2805
2821
|
for (const toolCall of choice.message.tool_calls) {
|
|
2806
2822
|
content.push({
|
|
2807
2823
|
type: "tool-call",
|
|
2808
|
-
toolCallId: (
|
|
2824
|
+
toolCallId: (_i = toolCall.id) != null ? _i : generateId(),
|
|
2809
2825
|
toolName: toolCall.function.name,
|
|
2810
2826
|
input: toolCall.function.arguments
|
|
2811
2827
|
});
|
|
@@ -2846,18 +2862,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2846
2862
|
providerMetadata: includeUsageAccounting ? {
|
|
2847
2863
|
llmgateway: {
|
|
2848
2864
|
usage: {
|
|
2849
|
-
promptTokens: (
|
|
2850
|
-
completionTokens: (
|
|
2851
|
-
totalTokens: (
|
|
2852
|
-
cost: typeof ((
|
|
2865
|
+
promptTokens: (_j = usageInfo.inputTokens.total) != null ? _j : 0,
|
|
2866
|
+
completionTokens: (_k = usageInfo.outputTokens.total) != null ? _k : 0,
|
|
2867
|
+
totalTokens: ((_l = usageInfo.inputTokens.total) != null ? _l : 0) + ((_m = usageInfo.outputTokens.total) != null ? _m : 0),
|
|
2868
|
+
cost: typeof ((_n = response.usage) == null ? void 0 : _n.cost) === "number" ? response.usage.cost : (_p = (_o = response.usage) == null ? void 0 : _o.cost) == null ? void 0 : _p.total_cost,
|
|
2853
2869
|
promptTokensDetails: {
|
|
2854
|
-
cachedTokens: (
|
|
2870
|
+
cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
|
|
2855
2871
|
},
|
|
2856
2872
|
completionTokensDetails: {
|
|
2857
|
-
reasoningTokens: (
|
|
2873
|
+
reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
|
|
2858
2874
|
},
|
|
2859
2875
|
costDetails: {
|
|
2860
|
-
upstreamInferenceCost: (
|
|
2876
|
+
upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
|
|
2861
2877
|
}
|
|
2862
2878
|
}
|
|
2863
2879
|
}
|
|
@@ -2893,13 +2909,19 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2893
2909
|
fetch: this.config.fetch
|
|
2894
2910
|
});
|
|
2895
2911
|
const toolCalls = [];
|
|
2896
|
-
let finishReason = "other";
|
|
2912
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
2897
2913
|
const usage = {
|
|
2898
|
-
inputTokens:
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2914
|
+
inputTokens: {
|
|
2915
|
+
total: void 0,
|
|
2916
|
+
noCache: void 0,
|
|
2917
|
+
cacheRead: void 0,
|
|
2918
|
+
cacheWrite: void 0
|
|
2919
|
+
},
|
|
2920
|
+
outputTokens: {
|
|
2921
|
+
total: void 0,
|
|
2922
|
+
text: void 0,
|
|
2923
|
+
reasoning: void 0
|
|
2924
|
+
}
|
|
2903
2925
|
};
|
|
2904
2926
|
const llmgatewayUsage = {};
|
|
2905
2927
|
let textStarted = false;
|
|
@@ -2913,13 +2935,13 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2913
2935
|
transform(chunk, controller) {
|
|
2914
2936
|
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2915
2937
|
if (!chunk.success) {
|
|
2916
|
-
finishReason = "error";
|
|
2938
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2917
2939
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2918
2940
|
return;
|
|
2919
2941
|
}
|
|
2920
2942
|
const value = chunk.value;
|
|
2921
2943
|
if ("error" in value) {
|
|
2922
|
-
finishReason = "error";
|
|
2944
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2923
2945
|
controller.enqueue({ type: "error", error: value.error });
|
|
2924
2946
|
return;
|
|
2925
2947
|
}
|
|
@@ -2937,13 +2959,12 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2937
2959
|
});
|
|
2938
2960
|
}
|
|
2939
2961
|
if (value.usage != null) {
|
|
2940
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
2941
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
2942
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
2962
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
2963
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
2943
2964
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
2944
2965
|
if (value.usage.prompt_tokens_details) {
|
|
2945
2966
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
2946
|
-
usage.
|
|
2967
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
2947
2968
|
llmgatewayUsage.promptTokensDetails = {
|
|
2948
2969
|
cachedTokens: cachedInputTokens
|
|
2949
2970
|
};
|
|
@@ -2951,7 +2972,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2951
2972
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
2952
2973
|
if (value.usage.completion_tokens_details) {
|
|
2953
2974
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
2954
|
-
usage.
|
|
2975
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
2955
2976
|
llmgatewayUsage.completionTokensDetails = {
|
|
2956
2977
|
reasoningTokens
|
|
2957
2978
|
};
|
|
@@ -3134,7 +3155,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3134
3155
|
},
|
|
3135
3156
|
flush(controller) {
|
|
3136
3157
|
var _a16;
|
|
3137
|
-
if (finishReason === "tool-calls") {
|
|
3158
|
+
if (finishReason.unified === "tool-calls") {
|
|
3138
3159
|
for (const toolCall of toolCalls) {
|
|
3139
3160
|
if (toolCall && !toolCall.sent) {
|
|
3140
3161
|
controller.enqueue({
|
|
@@ -3173,7 +3194,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3173
3194
|
}
|
|
3174
3195
|
})
|
|
3175
3196
|
),
|
|
3176
|
-
warnings: [],
|
|
3177
3197
|
request: { body: args },
|
|
3178
3198
|
response: { headers: responseHeaders }
|
|
3179
3199
|
};
|
|
@@ -3325,7 +3345,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
|
3325
3345
|
// src/completion/index.ts
|
|
3326
3346
|
var LLMGatewayCompletionLanguageModel = class {
|
|
3327
3347
|
constructor(modelId, settings, config) {
|
|
3328
|
-
this.specificationVersion = "
|
|
3348
|
+
this.specificationVersion = "v3";
|
|
3329
3349
|
this.provider = "llmgateway";
|
|
3330
3350
|
this.supportedUrls = {
|
|
3331
3351
|
"image/*": [
|
|
@@ -3335,7 +3355,6 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3335
3355
|
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
3336
3356
|
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
3337
3357
|
};
|
|
3338
|
-
this.defaultObjectGenerationMode = void 0;
|
|
3339
3358
|
this.modelId = modelId;
|
|
3340
3359
|
this.settings = settings;
|
|
3341
3360
|
this.config = config;
|
|
@@ -3395,7 +3414,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3395
3414
|
}, this.config.extraBody), this.settings.extraBody);
|
|
3396
3415
|
}
|
|
3397
3416
|
async doGenerate(options) {
|
|
3398
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
3417
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3399
3418
|
const providerOptions = options.providerOptions || {};
|
|
3400
3419
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
3401
3420
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -3429,11 +3448,17 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3429
3448
|
],
|
|
3430
3449
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
3431
3450
|
usage: {
|
|
3432
|
-
inputTokens:
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3451
|
+
inputTokens: {
|
|
3452
|
+
total: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : void 0,
|
|
3453
|
+
noCache: void 0,
|
|
3454
|
+
cacheRead: (_f = (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
3455
|
+
cacheWrite: void 0
|
|
3456
|
+
},
|
|
3457
|
+
outputTokens: {
|
|
3458
|
+
total: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
|
3459
|
+
text: void 0,
|
|
3460
|
+
reasoning: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
3461
|
+
}
|
|
3437
3462
|
},
|
|
3438
3463
|
warnings: [],
|
|
3439
3464
|
response: {
|
|
@@ -3463,13 +3488,19 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3463
3488
|
abortSignal: options.abortSignal,
|
|
3464
3489
|
fetch: this.config.fetch
|
|
3465
3490
|
});
|
|
3466
|
-
let finishReason = "other";
|
|
3491
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
3467
3492
|
const usage = {
|
|
3468
|
-
inputTokens:
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3493
|
+
inputTokens: {
|
|
3494
|
+
total: void 0,
|
|
3495
|
+
noCache: void 0,
|
|
3496
|
+
cacheRead: void 0,
|
|
3497
|
+
cacheWrite: void 0
|
|
3498
|
+
},
|
|
3499
|
+
outputTokens: {
|
|
3500
|
+
total: void 0,
|
|
3501
|
+
text: void 0,
|
|
3502
|
+
reasoning: void 0
|
|
3503
|
+
}
|
|
3473
3504
|
};
|
|
3474
3505
|
const llmgatewayUsage = {};
|
|
3475
3506
|
return {
|
|
@@ -3478,24 +3509,23 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3478
3509
|
transform(chunk, controller) {
|
|
3479
3510
|
var _a16, _b16, _c;
|
|
3480
3511
|
if (!chunk.success) {
|
|
3481
|
-
finishReason = "error";
|
|
3512
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3482
3513
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
3483
3514
|
return;
|
|
3484
3515
|
}
|
|
3485
3516
|
const value = chunk.value;
|
|
3486
3517
|
if ("error" in value) {
|
|
3487
|
-
finishReason = "error";
|
|
3518
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3488
3519
|
controller.enqueue({ type: "error", error: value.error });
|
|
3489
3520
|
return;
|
|
3490
3521
|
}
|
|
3491
3522
|
if (value.usage != null) {
|
|
3492
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
3493
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
3494
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
3523
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
3524
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
3495
3525
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
3496
3526
|
if (value.usage.prompt_tokens_details) {
|
|
3497
3527
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
3498
|
-
usage.
|
|
3528
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
3499
3529
|
llmgatewayUsage.promptTokensDetails = {
|
|
3500
3530
|
cachedTokens: cachedInputTokens
|
|
3501
3531
|
};
|
|
@@ -3503,7 +3533,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3503
3533
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
3504
3534
|
if (value.usage.completion_tokens_details) {
|
|
3505
3535
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
3506
|
-
usage.
|
|
3536
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
3507
3537
|
llmgatewayUsage.completionTokensDetails = {
|
|
3508
3538
|
reasoningTokens
|
|
3509
3539
|
};
|
|
@@ -3572,12 +3602,24 @@ var LLMGatewayImageModel = class {
|
|
|
3572
3602
|
feature: "seed"
|
|
3573
3603
|
});
|
|
3574
3604
|
}
|
|
3605
|
+
const hasFiles = options.files != null && options.files.length > 0;
|
|
3575
3606
|
const body = {
|
|
3576
3607
|
model: this.modelId,
|
|
3577
3608
|
prompt: options.prompt,
|
|
3578
3609
|
n: options.n,
|
|
3579
3610
|
response_format: "b64_json"
|
|
3580
3611
|
};
|
|
3612
|
+
if (hasFiles) {
|
|
3613
|
+
body.images = options.files.map((file) => {
|
|
3614
|
+
var _a16;
|
|
3615
|
+
if (file.type === "url") {
|
|
3616
|
+
return { image_url: file.url };
|
|
3617
|
+
}
|
|
3618
|
+
const base64 = typeof file.data === "string" ? file.data : Buffer.from(file.data).toString("base64");
|
|
3619
|
+
const mediaType = (_a16 = file.mediaType) != null ? _a16 : "image/png";
|
|
3620
|
+
return { image_url: `data:${mediaType};base64,${base64}` };
|
|
3621
|
+
});
|
|
3622
|
+
}
|
|
3581
3623
|
if (options.size != null) {
|
|
3582
3624
|
body.size = options.size;
|
|
3583
3625
|
}
|
|
@@ -3586,7 +3628,7 @@ var LLMGatewayImageModel = class {
|
|
|
3586
3628
|
}
|
|
3587
3629
|
const { value: response, responseHeaders } = await postJsonToApi({
|
|
3588
3630
|
url: this.config.url({
|
|
3589
|
-
path: "/images/generations",
|
|
3631
|
+
path: hasFiles ? "/images/edits" : "/images/generations",
|
|
3590
3632
|
modelId: this.modelId
|
|
3591
3633
|
}),
|
|
3592
3634
|
headers: combineHeaders(this.config.headers(), options.headers),
|