@llmgateway/ai-sdk-provider 3.5.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 +97 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -64
- 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 +97 -64
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +97 -64
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,12 +13,12 @@ The [LLMGateway](https://llmgateway.io/) provider for the [Vercel AI SDK](https:
|
|
|
13
13
|
## Setup
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
# For pnpm
|
|
17
|
-
pnpm add @llmgateway/ai-sdk-provider
|
|
18
|
-
|
|
19
16
|
# For npm
|
|
20
17
|
npm install @llmgateway/ai-sdk-provider
|
|
21
18
|
|
|
19
|
+
# For pnpm
|
|
20
|
+
pnpm add @llmgateway/ai-sdk-provider
|
|
21
|
+
|
|
22
22
|
# For yarn
|
|
23
23
|
yarn add @llmgateway/ai-sdk-provider
|
|
24
24
|
```
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
|
|
2
|
+
export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
3
3
|
import { models, Provider } from '@llmgateway/models';
|
|
4
4
|
|
|
5
5
|
type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
|
|
@@ -146,45 +146,17 @@ type LLMGatewayChatConfig = {
|
|
|
146
146
|
fetch?: typeof fetch;
|
|
147
147
|
extraBody?: Record<string, unknown>;
|
|
148
148
|
};
|
|
149
|
-
declare class LLMGatewayChatLanguageModel implements
|
|
150
|
-
readonly specificationVersion: "
|
|
149
|
+
declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
|
|
150
|
+
readonly specificationVersion: "v3";
|
|
151
151
|
readonly provider = "llmgateway";
|
|
152
|
-
readonly defaultObjectGenerationMode: "tool";
|
|
153
152
|
readonly modelId: LLMGatewayChatModelId;
|
|
154
153
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
155
154
|
readonly settings: LLMGatewayChatSettings;
|
|
156
155
|
private readonly config;
|
|
157
156
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
|
|
158
157
|
private getArgs;
|
|
159
|
-
doGenerate(options:
|
|
160
|
-
|
|
161
|
-
finishReason: LanguageModelV2FinishReason;
|
|
162
|
-
usage: LanguageModelV2Usage;
|
|
163
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
164
|
-
providerMetadata?: {
|
|
165
|
-
llmgateway: {
|
|
166
|
-
usage: LLMGatewayUsageAccounting;
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
request?: {
|
|
170
|
-
body?: unknown;
|
|
171
|
-
};
|
|
172
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
173
|
-
headers?: SharedV2Headers;
|
|
174
|
-
body?: unknown;
|
|
175
|
-
};
|
|
176
|
-
}>;
|
|
177
|
-
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
178
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
179
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
180
|
-
request?: {
|
|
181
|
-
body?: unknown;
|
|
182
|
-
};
|
|
183
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
184
|
-
headers?: SharedV2Headers;
|
|
185
|
-
body?: unknown;
|
|
186
|
-
};
|
|
187
|
-
}>;
|
|
158
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
159
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
188
160
|
}
|
|
189
161
|
|
|
190
162
|
type LLMGatewayCompletionConfig = {
|
|
@@ -198,18 +170,17 @@ type LLMGatewayCompletionConfig = {
|
|
|
198
170
|
fetch?: typeof fetch;
|
|
199
171
|
extraBody?: Record<string, unknown>;
|
|
200
172
|
};
|
|
201
|
-
declare class LLMGatewayCompletionLanguageModel implements
|
|
202
|
-
readonly specificationVersion: "
|
|
173
|
+
declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
|
|
174
|
+
readonly specificationVersion: "v3";
|
|
203
175
|
readonly provider = "llmgateway";
|
|
204
176
|
readonly modelId: LLMGatewayChatModelId;
|
|
205
177
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
206
|
-
readonly defaultObjectGenerationMode: undefined;
|
|
207
178
|
readonly settings: LLMGatewayCompletionSettings;
|
|
208
179
|
private readonly config;
|
|
209
180
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
|
|
210
181
|
private getArgs;
|
|
211
|
-
doGenerate(options:
|
|
212
|
-
doStream(options:
|
|
182
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
|
183
|
+
doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
|
213
184
|
}
|
|
214
185
|
|
|
215
186
|
type LLMGatewayImageConfig = {
|
|
@@ -240,7 +211,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
|
240
211
|
}>;
|
|
241
212
|
}
|
|
242
213
|
|
|
243
|
-
interface LLMGatewayProvider
|
|
214
|
+
interface LLMGatewayProvider {
|
|
244
215
|
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
245
216
|
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
246
217
|
languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, ImageModelV3, ImageModelV3CallOptions, SharedV3Warning } from '@ai-sdk/provider';
|
|
2
|
+
export { LanguageModelV3, LanguageModelV3Prompt } from '@ai-sdk/provider';
|
|
3
3
|
import { models, Provider } from '@llmgateway/models';
|
|
4
4
|
|
|
5
5
|
type LLMGatewayChatModelId = (typeof models)[number]['id'] | `${Provider}/${(typeof models)[number]['id']}` | 'test-model';
|
|
@@ -146,45 +146,17 @@ type LLMGatewayChatConfig = {
|
|
|
146
146
|
fetch?: typeof fetch;
|
|
147
147
|
extraBody?: Record<string, unknown>;
|
|
148
148
|
};
|
|
149
|
-
declare class LLMGatewayChatLanguageModel implements
|
|
150
|
-
readonly specificationVersion: "
|
|
149
|
+
declare class LLMGatewayChatLanguageModel implements LanguageModelV3 {
|
|
150
|
+
readonly specificationVersion: "v3";
|
|
151
151
|
readonly provider = "llmgateway";
|
|
152
|
-
readonly defaultObjectGenerationMode: "tool";
|
|
153
152
|
readonly modelId: LLMGatewayChatModelId;
|
|
154
153
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
155
154
|
readonly settings: LLMGatewayChatSettings;
|
|
156
155
|
private readonly config;
|
|
157
156
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
|
|
158
157
|
private getArgs;
|
|
159
|
-
doGenerate(options:
|
|
160
|
-
|
|
161
|
-
finishReason: LanguageModelV2FinishReason;
|
|
162
|
-
usage: LanguageModelV2Usage;
|
|
163
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
164
|
-
providerMetadata?: {
|
|
165
|
-
llmgateway: {
|
|
166
|
-
usage: LLMGatewayUsageAccounting;
|
|
167
|
-
};
|
|
168
|
-
};
|
|
169
|
-
request?: {
|
|
170
|
-
body?: unknown;
|
|
171
|
-
};
|
|
172
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
173
|
-
headers?: SharedV2Headers;
|
|
174
|
-
body?: unknown;
|
|
175
|
-
};
|
|
176
|
-
}>;
|
|
177
|
-
doStream(options: LanguageModelV2CallOptions): Promise<{
|
|
178
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
179
|
-
warnings: Array<LanguageModelV2CallWarning>;
|
|
180
|
-
request?: {
|
|
181
|
-
body?: unknown;
|
|
182
|
-
};
|
|
183
|
-
response?: LanguageModelV2ResponseMetadata & {
|
|
184
|
-
headers?: SharedV2Headers;
|
|
185
|
-
body?: unknown;
|
|
186
|
-
};
|
|
187
|
-
}>;
|
|
158
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
159
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
188
160
|
}
|
|
189
161
|
|
|
190
162
|
type LLMGatewayCompletionConfig = {
|
|
@@ -198,18 +170,17 @@ type LLMGatewayCompletionConfig = {
|
|
|
198
170
|
fetch?: typeof fetch;
|
|
199
171
|
extraBody?: Record<string, unknown>;
|
|
200
172
|
};
|
|
201
|
-
declare class LLMGatewayCompletionLanguageModel implements
|
|
202
|
-
readonly specificationVersion: "
|
|
173
|
+
declare class LLMGatewayCompletionLanguageModel implements LanguageModelV3 {
|
|
174
|
+
readonly specificationVersion: "v3";
|
|
203
175
|
readonly provider = "llmgateway";
|
|
204
176
|
readonly modelId: LLMGatewayChatModelId;
|
|
205
177
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
206
|
-
readonly defaultObjectGenerationMode: undefined;
|
|
207
178
|
readonly settings: LLMGatewayCompletionSettings;
|
|
208
179
|
private readonly config;
|
|
209
180
|
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
|
|
210
181
|
private getArgs;
|
|
211
|
-
doGenerate(options:
|
|
212
|
-
doStream(options:
|
|
182
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
|
183
|
+
doStream(options: LanguageModelV3CallOptions): Promise<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
|
213
184
|
}
|
|
214
185
|
|
|
215
186
|
type LLMGatewayImageConfig = {
|
|
@@ -240,7 +211,7 @@ declare class LLMGatewayImageModel implements ImageModelV3 {
|
|
|
240
211
|
}>;
|
|
241
212
|
}
|
|
242
213
|
|
|
243
|
-
interface LLMGatewayProvider
|
|
214
|
+
interface LLMGatewayProvider {
|
|
244
215
|
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
245
216
|
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
246
217
|
languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
package/dist/index.js
CHANGED
|
@@ -2252,16 +2252,16 @@ var llmgatewayFailedResponseHandler = createJsonErrorResponseHandler({
|
|
|
2252
2252
|
function mapLLMGatewayFinishReason(finishReason) {
|
|
2253
2253
|
switch (finishReason) {
|
|
2254
2254
|
case "stop":
|
|
2255
|
-
return "stop";
|
|
2255
|
+
return { unified: "stop", raw: finishReason };
|
|
2256
2256
|
case "length":
|
|
2257
|
-
return "length";
|
|
2257
|
+
return { unified: "length", raw: finishReason };
|
|
2258
2258
|
case "content_filter":
|
|
2259
|
-
return "content-filter";
|
|
2259
|
+
return { unified: "content-filter", raw: finishReason };
|
|
2260
2260
|
case "function_call":
|
|
2261
2261
|
case "tool_calls":
|
|
2262
|
-
return "tool-calls";
|
|
2262
|
+
return { unified: "tool-calls", raw: finishReason };
|
|
2263
2263
|
default:
|
|
2264
|
-
return "
|
|
2264
|
+
return { unified: "other", raw: finishReason != null ? finishReason : void 0 };
|
|
2265
2265
|
}
|
|
2266
2266
|
}
|
|
2267
2267
|
|
|
@@ -2464,6 +2464,7 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2464
2464
|
}
|
|
2465
2465
|
case "tool": {
|
|
2466
2466
|
for (const toolResponse of content) {
|
|
2467
|
+
if (toolResponse.type !== "tool-result") continue;
|
|
2467
2468
|
const content2 = getToolResultContent(toolResponse);
|
|
2468
2469
|
messages.push({
|
|
2469
2470
|
role: "tool",
|
|
@@ -2482,7 +2483,14 @@ function convertToLLMGatewayChatMessages(prompt) {
|
|
|
2482
2483
|
return messages;
|
|
2483
2484
|
}
|
|
2484
2485
|
function getToolResultContent(input) {
|
|
2485
|
-
|
|
2486
|
+
switch (input.output.type) {
|
|
2487
|
+
case "text":
|
|
2488
|
+
return input.output.value;
|
|
2489
|
+
case "json":
|
|
2490
|
+
return JSON.stringify(input.output.value);
|
|
2491
|
+
default:
|
|
2492
|
+
return JSON.stringify(input.output);
|
|
2493
|
+
}
|
|
2486
2494
|
}
|
|
2487
2495
|
|
|
2488
2496
|
// src/chat/get-tool-choice.ts
|
|
@@ -2652,9 +2660,8 @@ var LLMGatewayStreamChatCompletionChunkSchema = import_v45.z.union([
|
|
|
2652
2660
|
// src/chat/index.ts
|
|
2653
2661
|
var LLMGatewayChatLanguageModel = class {
|
|
2654
2662
|
constructor(modelId, settings, config) {
|
|
2655
|
-
this.specificationVersion = "
|
|
2663
|
+
this.specificationVersion = "v3";
|
|
2656
2664
|
this.provider = "llmgateway";
|
|
2657
|
-
this.defaultObjectGenerationMode = "tool";
|
|
2658
2665
|
this.supportedUrls = {
|
|
2659
2666
|
"image/*": [
|
|
2660
2667
|
/^data:image\/[a-zA-Z]+;base64,/,
|
|
@@ -2743,7 +2750,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2743
2750
|
return baseArgs;
|
|
2744
2751
|
}
|
|
2745
2752
|
async doGenerate(options) {
|
|
2746
|
-
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
|
|
2753
|
+
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;
|
|
2747
2754
|
const providerOptions = options.providerOptions || {};
|
|
2748
2755
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
2749
2756
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -2767,19 +2774,31 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2767
2774
|
throw new Error("No choice in response");
|
|
2768
2775
|
}
|
|
2769
2776
|
const usageInfo = response.usage ? {
|
|
2770
|
-
inputTokens:
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2777
|
+
inputTokens: {
|
|
2778
|
+
total: (_b16 = response.usage.prompt_tokens) != null ? _b16 : void 0,
|
|
2779
|
+
noCache: void 0,
|
|
2780
|
+
cacheRead: (_d = (_c = response.usage.prompt_tokens_details) == null ? void 0 : _c.cached_tokens) != null ? _d : void 0,
|
|
2781
|
+
cacheWrite: void 0
|
|
2782
|
+
},
|
|
2783
|
+
outputTokens: {
|
|
2784
|
+
total: (_e = response.usage.completion_tokens) != null ? _e : void 0,
|
|
2785
|
+
text: void 0,
|
|
2786
|
+
reasoning: (_g = (_f = response.usage.completion_tokens_details) == null ? void 0 : _f.reasoning_tokens) != null ? _g : void 0
|
|
2787
|
+
}
|
|
2775
2788
|
} : {
|
|
2776
|
-
inputTokens:
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2789
|
+
inputTokens: {
|
|
2790
|
+
total: void 0,
|
|
2791
|
+
noCache: void 0,
|
|
2792
|
+
cacheRead: void 0,
|
|
2793
|
+
cacheWrite: void 0
|
|
2794
|
+
},
|
|
2795
|
+
outputTokens: {
|
|
2796
|
+
total: void 0,
|
|
2797
|
+
text: void 0,
|
|
2798
|
+
reasoning: void 0
|
|
2799
|
+
}
|
|
2781
2800
|
};
|
|
2782
|
-
const reasoningDetails = (
|
|
2801
|
+
const reasoningDetails = (_h = choice.message.reasoning_details) != null ? _h : [];
|
|
2783
2802
|
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
2784
2803
|
switch (detail.type) {
|
|
2785
2804
|
case "reasoning.text" /* Text */: {
|
|
@@ -2835,7 +2854,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2835
2854
|
for (const toolCall of choice.message.tool_calls) {
|
|
2836
2855
|
content.push({
|
|
2837
2856
|
type: "tool-call",
|
|
2838
|
-
toolCallId: (
|
|
2857
|
+
toolCallId: (_i = toolCall.id) != null ? _i : generateId(),
|
|
2839
2858
|
toolName: toolCall.function.name,
|
|
2840
2859
|
input: toolCall.function.arguments
|
|
2841
2860
|
});
|
|
@@ -2876,18 +2895,18 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2876
2895
|
providerMetadata: includeUsageAccounting ? {
|
|
2877
2896
|
llmgateway: {
|
|
2878
2897
|
usage: {
|
|
2879
|
-
promptTokens: (
|
|
2880
|
-
completionTokens: (
|
|
2881
|
-
totalTokens: (
|
|
2882
|
-
cost: typeof ((
|
|
2898
|
+
promptTokens: (_j = usageInfo.inputTokens.total) != null ? _j : 0,
|
|
2899
|
+
completionTokens: (_k = usageInfo.outputTokens.total) != null ? _k : 0,
|
|
2900
|
+
totalTokens: ((_l = usageInfo.inputTokens.total) != null ? _l : 0) + ((_m = usageInfo.outputTokens.total) != null ? _m : 0),
|
|
2901
|
+
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,
|
|
2883
2902
|
promptTokensDetails: {
|
|
2884
|
-
cachedTokens: (
|
|
2903
|
+
cachedTokens: (_s = (_r = (_q = response.usage) == null ? void 0 : _q.prompt_tokens_details) == null ? void 0 : _r.cached_tokens) != null ? _s : 0
|
|
2885
2904
|
},
|
|
2886
2905
|
completionTokensDetails: {
|
|
2887
|
-
reasoningTokens: (
|
|
2906
|
+
reasoningTokens: (_v = (_u = (_t = response.usage) == null ? void 0 : _t.completion_tokens_details) == null ? void 0 : _u.reasoning_tokens) != null ? _v : 0
|
|
2888
2907
|
},
|
|
2889
2908
|
costDetails: {
|
|
2890
|
-
upstreamInferenceCost: (
|
|
2909
|
+
upstreamInferenceCost: (_y = (_x = (_w = response.usage) == null ? void 0 : _w.cost_details) == null ? void 0 : _x.upstream_inference_cost) != null ? _y : 0
|
|
2891
2910
|
}
|
|
2892
2911
|
}
|
|
2893
2912
|
}
|
|
@@ -2923,13 +2942,19 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2923
2942
|
fetch: this.config.fetch
|
|
2924
2943
|
});
|
|
2925
2944
|
const toolCalls = [];
|
|
2926
|
-
let finishReason = "other";
|
|
2945
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
2927
2946
|
const usage = {
|
|
2928
|
-
inputTokens:
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2947
|
+
inputTokens: {
|
|
2948
|
+
total: void 0,
|
|
2949
|
+
noCache: void 0,
|
|
2950
|
+
cacheRead: void 0,
|
|
2951
|
+
cacheWrite: void 0
|
|
2952
|
+
},
|
|
2953
|
+
outputTokens: {
|
|
2954
|
+
total: void 0,
|
|
2955
|
+
text: void 0,
|
|
2956
|
+
reasoning: void 0
|
|
2957
|
+
}
|
|
2933
2958
|
};
|
|
2934
2959
|
const llmgatewayUsage = {};
|
|
2935
2960
|
let textStarted = false;
|
|
@@ -2943,13 +2968,13 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2943
2968
|
transform(chunk, controller) {
|
|
2944
2969
|
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2945
2970
|
if (!chunk.success) {
|
|
2946
|
-
finishReason = "error";
|
|
2971
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2947
2972
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2948
2973
|
return;
|
|
2949
2974
|
}
|
|
2950
2975
|
const value = chunk.value;
|
|
2951
2976
|
if ("error" in value) {
|
|
2952
|
-
finishReason = "error";
|
|
2977
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
2953
2978
|
controller.enqueue({ type: "error", error: value.error });
|
|
2954
2979
|
return;
|
|
2955
2980
|
}
|
|
@@ -2967,13 +2992,12 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2967
2992
|
});
|
|
2968
2993
|
}
|
|
2969
2994
|
if (value.usage != null) {
|
|
2970
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
2971
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
2972
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
2995
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
2996
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
2973
2997
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
2974
2998
|
if (value.usage.prompt_tokens_details) {
|
|
2975
2999
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
2976
|
-
usage.
|
|
3000
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
2977
3001
|
llmgatewayUsage.promptTokensDetails = {
|
|
2978
3002
|
cachedTokens: cachedInputTokens
|
|
2979
3003
|
};
|
|
@@ -2981,7 +3005,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
2981
3005
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
2982
3006
|
if (value.usage.completion_tokens_details) {
|
|
2983
3007
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
2984
|
-
usage.
|
|
3008
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
2985
3009
|
llmgatewayUsage.completionTokensDetails = {
|
|
2986
3010
|
reasoningTokens
|
|
2987
3011
|
};
|
|
@@ -3164,7 +3188,7 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3164
3188
|
},
|
|
3165
3189
|
flush(controller) {
|
|
3166
3190
|
var _a16;
|
|
3167
|
-
if (finishReason === "tool-calls") {
|
|
3191
|
+
if (finishReason.unified === "tool-calls") {
|
|
3168
3192
|
for (const toolCall of toolCalls) {
|
|
3169
3193
|
if (toolCall && !toolCall.sent) {
|
|
3170
3194
|
controller.enqueue({
|
|
@@ -3203,7 +3227,6 @@ var LLMGatewayChatLanguageModel = class {
|
|
|
3203
3227
|
}
|
|
3204
3228
|
})
|
|
3205
3229
|
),
|
|
3206
|
-
warnings: [],
|
|
3207
3230
|
request: { body: args },
|
|
3208
3231
|
response: { headers: responseHeaders }
|
|
3209
3232
|
};
|
|
@@ -3355,7 +3378,7 @@ var LLMGatewayCompletionChunkSchema = import_v46.z.union([
|
|
|
3355
3378
|
// src/completion/index.ts
|
|
3356
3379
|
var LLMGatewayCompletionLanguageModel = class {
|
|
3357
3380
|
constructor(modelId, settings, config) {
|
|
3358
|
-
this.specificationVersion = "
|
|
3381
|
+
this.specificationVersion = "v3";
|
|
3359
3382
|
this.provider = "llmgateway";
|
|
3360
3383
|
this.supportedUrls = {
|
|
3361
3384
|
"image/*": [
|
|
@@ -3365,7 +3388,6 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3365
3388
|
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
3366
3389
|
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
3367
3390
|
};
|
|
3368
|
-
this.defaultObjectGenerationMode = void 0;
|
|
3369
3391
|
this.modelId = modelId;
|
|
3370
3392
|
this.settings = settings;
|
|
3371
3393
|
this.config = config;
|
|
@@ -3425,7 +3447,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3425
3447
|
}, this.config.extraBody), this.settings.extraBody);
|
|
3426
3448
|
}
|
|
3427
3449
|
async doGenerate(options) {
|
|
3428
|
-
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
3450
|
+
var _a16, _b16, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3429
3451
|
const providerOptions = options.providerOptions || {};
|
|
3430
3452
|
const llmgatewayOptions = providerOptions.llmgateway || {};
|
|
3431
3453
|
const args = __spreadValues(__spreadValues({}, this.getArgs(options)), llmgatewayOptions);
|
|
@@ -3459,11 +3481,17 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3459
3481
|
],
|
|
3460
3482
|
finishReason: mapLLMGatewayFinishReason(choice.finish_reason),
|
|
3461
3483
|
usage: {
|
|
3462
|
-
inputTokens:
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3484
|
+
inputTokens: {
|
|
3485
|
+
total: (_c = (_b16 = response.usage) == null ? void 0 : _b16.prompt_tokens) != null ? _c : void 0,
|
|
3486
|
+
noCache: void 0,
|
|
3487
|
+
cacheRead: (_f = (_e = (_d = response.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
3488
|
+
cacheWrite: void 0
|
|
3489
|
+
},
|
|
3490
|
+
outputTokens: {
|
|
3491
|
+
total: (_h = (_g = response.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
|
3492
|
+
text: void 0,
|
|
3493
|
+
reasoning: (_k = (_j = (_i = response.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
3494
|
+
}
|
|
3467
3495
|
},
|
|
3468
3496
|
warnings: [],
|
|
3469
3497
|
response: {
|
|
@@ -3493,13 +3521,19 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3493
3521
|
abortSignal: options.abortSignal,
|
|
3494
3522
|
fetch: this.config.fetch
|
|
3495
3523
|
});
|
|
3496
|
-
let finishReason = "other";
|
|
3524
|
+
let finishReason = { unified: "other", raw: void 0 };
|
|
3497
3525
|
const usage = {
|
|
3498
|
-
inputTokens:
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3526
|
+
inputTokens: {
|
|
3527
|
+
total: void 0,
|
|
3528
|
+
noCache: void 0,
|
|
3529
|
+
cacheRead: void 0,
|
|
3530
|
+
cacheWrite: void 0
|
|
3531
|
+
},
|
|
3532
|
+
outputTokens: {
|
|
3533
|
+
total: void 0,
|
|
3534
|
+
text: void 0,
|
|
3535
|
+
reasoning: void 0
|
|
3536
|
+
}
|
|
3503
3537
|
};
|
|
3504
3538
|
const llmgatewayUsage = {};
|
|
3505
3539
|
return {
|
|
@@ -3508,24 +3542,23 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3508
3542
|
transform(chunk, controller) {
|
|
3509
3543
|
var _a16, _b16, _c;
|
|
3510
3544
|
if (!chunk.success) {
|
|
3511
|
-
finishReason = "error";
|
|
3545
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3512
3546
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
3513
3547
|
return;
|
|
3514
3548
|
}
|
|
3515
3549
|
const value = chunk.value;
|
|
3516
3550
|
if ("error" in value) {
|
|
3517
|
-
finishReason = "error";
|
|
3551
|
+
finishReason = { unified: "error", raw: void 0 };
|
|
3518
3552
|
controller.enqueue({ type: "error", error: value.error });
|
|
3519
3553
|
return;
|
|
3520
3554
|
}
|
|
3521
3555
|
if (value.usage != null) {
|
|
3522
|
-
usage.inputTokens = value.usage.prompt_tokens;
|
|
3523
|
-
usage.outputTokens = value.usage.completion_tokens;
|
|
3524
|
-
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
3556
|
+
usage.inputTokens.total = value.usage.prompt_tokens;
|
|
3557
|
+
usage.outputTokens.total = value.usage.completion_tokens;
|
|
3525
3558
|
llmgatewayUsage.promptTokens = value.usage.prompt_tokens;
|
|
3526
3559
|
if (value.usage.prompt_tokens_details) {
|
|
3527
3560
|
const cachedInputTokens = (_a16 = value.usage.prompt_tokens_details.cached_tokens) != null ? _a16 : 0;
|
|
3528
|
-
usage.
|
|
3561
|
+
usage.inputTokens.cacheRead = cachedInputTokens;
|
|
3529
3562
|
llmgatewayUsage.promptTokensDetails = {
|
|
3530
3563
|
cachedTokens: cachedInputTokens
|
|
3531
3564
|
};
|
|
@@ -3533,7 +3566,7 @@ var LLMGatewayCompletionLanguageModel = class {
|
|
|
3533
3566
|
llmgatewayUsage.completionTokens = value.usage.completion_tokens;
|
|
3534
3567
|
if (value.usage.completion_tokens_details) {
|
|
3535
3568
|
const reasoningTokens = (_b16 = value.usage.completion_tokens_details.reasoning_tokens) != null ? _b16 : 0;
|
|
3536
|
-
usage.
|
|
3569
|
+
usage.outputTokens.reasoning = reasoningTokens;
|
|
3537
3570
|
llmgatewayUsage.completionTokensDetails = {
|
|
3538
3571
|
reasoningTokens
|
|
3539
3572
|
};
|