@friendliai/ai-provider 1.1.15 → 1.1.16
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ import { friendli } from '@friendliai/ai-provider';
|
|
|
24
24
|
import { generateText } from 'ai';
|
|
25
25
|
|
|
26
26
|
const { text } = await generateText({
|
|
27
|
-
model: friendli('
|
|
27
|
+
model: friendli('zai-org/GLM-5.2'),
|
|
28
28
|
prompt: 'What is the meaning of life?',
|
|
29
29
|
maxTokens: 20,
|
|
30
30
|
topK: 10,
|
package/dist/index.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ declare const friendliaiErrorSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>]>;
|
|
13
13
|
type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
|
|
14
14
|
|
|
15
|
-
declare const FriendliAIServerlessModelIds: readonly ["google/gemma-4-31B-it", "zai-org/GLM-5.1", "zai-org/GLM-5", "meta-llama/Llama-3.3-70B-Instruct", "meta-llama-3.3-70b-instruct", "meta-llama/Llama-3.1-8B-Instruct", "meta-llama-3.1-8b-instruct", "Qwen/Qwen3-235B-A22B-Instruct-2507", "deepseek-ai/DeepSeek-V3.2", "openai/whisper-large-v3", "MiniMaxAI/MiniMax-M2.5", "LGAI-EXAONE/K-EXAONE-236B-A23B"];
|
|
15
|
+
declare const FriendliAIServerlessModelIds: readonly ["google/gemma-4-31B-it", "zai-org/GLM-5.2", "zai-org/GLM-5.1", "zai-org/GLM-5", "meta-llama/Llama-3.3-70B-Instruct", "meta-llama-3.3-70b-instruct", "meta-llama/Llama-3.1-8B-Instruct", "meta-llama-3.1-8b-instruct", "Qwen/Qwen3-235B-A22B-Instruct-2507", "deepseek-ai/DeepSeek-V3.2", "openai/whisper-large-v3", "MiniMaxAI/MiniMax-M2.5", "LGAI-EXAONE/K-EXAONE-236B-A23B"];
|
|
16
16
|
type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
|
|
17
17
|
type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
|
|
18
18
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare const friendliaiErrorSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
12
12
|
}, z.core.$strip>]>;
|
|
13
13
|
type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
|
|
14
14
|
|
|
15
|
-
declare const FriendliAIServerlessModelIds: readonly ["google/gemma-4-31B-it", "zai-org/GLM-5.1", "zai-org/GLM-5", "meta-llama/Llama-3.3-70B-Instruct", "meta-llama-3.3-70b-instruct", "meta-llama/Llama-3.1-8B-Instruct", "meta-llama-3.1-8b-instruct", "Qwen/Qwen3-235B-A22B-Instruct-2507", "deepseek-ai/DeepSeek-V3.2", "openai/whisper-large-v3", "MiniMaxAI/MiniMax-M2.5", "LGAI-EXAONE/K-EXAONE-236B-A23B"];
|
|
15
|
+
declare const FriendliAIServerlessModelIds: readonly ["google/gemma-4-31B-it", "zai-org/GLM-5.2", "zai-org/GLM-5.1", "zai-org/GLM-5", "meta-llama/Llama-3.3-70B-Instruct", "meta-llama-3.3-70b-instruct", "meta-llama/Llama-3.1-8B-Instruct", "meta-llama-3.1-8b-instruct", "Qwen/Qwen3-235B-A22B-Instruct-2507", "deepseek-ai/DeepSeek-V3.2", "openai/whisper-large-v3", "MiniMaxAI/MiniMax-M2.5", "LGAI-EXAONE/K-EXAONE-236B-A23B"];
|
|
16
16
|
type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
|
|
17
17
|
type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
|
|
18
18
|
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,7 @@ var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
|
34
34
|
var import_internal = require("@ai-sdk/openai-compatible/internal");
|
|
35
35
|
var import_provider3 = require("@ai-sdk/provider");
|
|
36
36
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
37
|
+
var import_es_toolkit2 = require("es-toolkit");
|
|
37
38
|
var import_v4 = require("zod/v4");
|
|
38
39
|
|
|
39
40
|
// src/friendli-error.ts
|
|
@@ -149,6 +150,7 @@ var tryWrapFriendliJsonEnvelopeError = async (error) => {
|
|
|
149
150
|
|
|
150
151
|
// src/friendli-prepare-tools.ts
|
|
151
152
|
var import_provider2 = require("@ai-sdk/provider");
|
|
153
|
+
var import_es_toolkit = require("es-toolkit");
|
|
152
154
|
function prepareTools({
|
|
153
155
|
tools,
|
|
154
156
|
toolChoice
|
|
@@ -156,7 +158,7 @@ function prepareTools({
|
|
|
156
158
|
var _a;
|
|
157
159
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
158
160
|
const toolWarnings = [];
|
|
159
|
-
if (
|
|
161
|
+
if ((0, import_es_toolkit.isNil)(tools)) {
|
|
160
162
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
161
163
|
}
|
|
162
164
|
const openaiCompatTools = [];
|
|
@@ -179,7 +181,7 @@ function prepareTools({
|
|
|
179
181
|
});
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
|
-
if (
|
|
184
|
+
if ((0, import_es_toolkit.isNil)(toolChoice)) {
|
|
183
185
|
return { tools: openaiCompatTools, toolChoice: void 0, toolWarnings };
|
|
184
186
|
}
|
|
185
187
|
const type = toolChoice.type;
|
|
@@ -208,7 +210,7 @@ function prepareTools({
|
|
|
208
210
|
|
|
209
211
|
// src/friendli-chat-language-model.ts
|
|
210
212
|
function isRecord(value) {
|
|
211
|
-
return typeof value === "object" && value
|
|
213
|
+
return typeof value === "object" && (0, import_es_toolkit2.isNotNil)(value);
|
|
212
214
|
}
|
|
213
215
|
function isHostedToolExecutionChunk(value) {
|
|
214
216
|
if (!isRecord(value)) return false;
|
|
@@ -302,7 +304,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
302
304
|
...legacyFriendliOptions,
|
|
303
305
|
...friendliOptions
|
|
304
306
|
};
|
|
305
|
-
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema
|
|
307
|
+
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && (0, import_es_toolkit2.isNotNil)(responseFormat.schema) && !this.supportsStructuredOutputs) {
|
|
306
308
|
warnings.push({
|
|
307
309
|
type: "unsupported",
|
|
308
310
|
feature: "responseFormat",
|
|
@@ -317,8 +319,8 @@ var FriendliAIChatLanguageModel = class {
|
|
|
317
319
|
tools,
|
|
318
320
|
toolChoice
|
|
319
321
|
});
|
|
320
|
-
const isToolsPresent = openaiTools
|
|
321
|
-
if (isToolsPresent && (responseFormat
|
|
322
|
+
const isToolsPresent = (0, import_es_toolkit2.isNotNil)(openaiTools) && openaiTools.length > 0;
|
|
323
|
+
if (isToolsPresent && ((0, import_es_toolkit2.isNotNil)(responseFormat) || (0, import_es_toolkit2.isNotNil)(options == null ? void 0 : options.regex))) {
|
|
322
324
|
warnings.push({
|
|
323
325
|
type: "unsupported",
|
|
324
326
|
feature: "responseFormat",
|
|
@@ -339,14 +341,14 @@ var FriendliAIChatLanguageModel = class {
|
|
|
339
341
|
top_k: topK,
|
|
340
342
|
frequency_penalty: frequencyPenalty,
|
|
341
343
|
presence_penalty: presencePenalty,
|
|
342
|
-
response_format: isToolsPresent === false ? (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && responseFormat.schema
|
|
344
|
+
response_format: isToolsPresent === false ? (responseFormat == null ? void 0 : responseFormat.type) === "json" ? this.supportsStructuredOutputs === true && (0, import_es_toolkit2.isNotNil)(responseFormat.schema) ? {
|
|
343
345
|
type: "json_schema",
|
|
344
346
|
json_schema: {
|
|
345
347
|
schema: responseFormat.schema,
|
|
346
348
|
name: (_a = responseFormat.name) != null ? _a : "response",
|
|
347
349
|
description: responseFormat.description
|
|
348
350
|
}
|
|
349
|
-
} : { type: "json_object" } : (options == null ? void 0 : options.regex)
|
|
351
|
+
} : { type: "json_object" } : (0, import_es_toolkit2.isNotNil)(options == null ? void 0 : options.regex) ? {
|
|
350
352
|
type: "regex",
|
|
351
353
|
schema: options.regex
|
|
352
354
|
} : void 0 : void 0,
|
|
@@ -389,7 +391,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
389
391
|
});
|
|
390
392
|
} catch (error) {
|
|
391
393
|
const wrappedError = await tryWrapFriendliJsonEnvelopeError(error);
|
|
392
|
-
if (
|
|
394
|
+
if ((0, import_es_toolkit2.isNotNil)(wrappedError)) {
|
|
393
395
|
throw wrappedError;
|
|
394
396
|
}
|
|
395
397
|
throw error;
|
|
@@ -399,17 +401,17 @@ var FriendliAIChatLanguageModel = class {
|
|
|
399
401
|
const choice = responseBody.choices[0];
|
|
400
402
|
const content = [];
|
|
401
403
|
const text = choice.message.content;
|
|
402
|
-
if (text
|
|
404
|
+
if ((0, import_es_toolkit2.isNotNil)(text) && text.length > 0) {
|
|
403
405
|
content.push({ type: "text", text });
|
|
404
406
|
}
|
|
405
407
|
const reasoning = choice.message.reasoning_content;
|
|
406
|
-
if (reasoning
|
|
408
|
+
if ((0, import_es_toolkit2.isNotNil)(reasoning) && reasoning.length > 0) {
|
|
407
409
|
content.push({
|
|
408
410
|
type: "reasoning",
|
|
409
411
|
text: reasoning
|
|
410
412
|
});
|
|
411
413
|
}
|
|
412
|
-
if (choice.message.tool_calls
|
|
414
|
+
if ((0, import_es_toolkit2.isNotNil)(choice.message.tool_calls)) {
|
|
413
415
|
for (const toolCall of choice.message.tool_calls) {
|
|
414
416
|
content.push({
|
|
415
417
|
type: "tool-call",
|
|
@@ -532,7 +534,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
532
534
|
return;
|
|
533
535
|
}
|
|
534
536
|
const chunkErrorMessage = getChunkErrorMessage(value);
|
|
535
|
-
if (
|
|
537
|
+
if ((0, import_es_toolkit2.isNotNil)(chunkErrorMessage)) {
|
|
536
538
|
finishReason = { unified: "error", raw: void 0 };
|
|
537
539
|
controller.enqueue({ type: "error", error: chunkErrorMessage });
|
|
538
540
|
return;
|
|
@@ -553,22 +555,22 @@ var FriendliAIChatLanguageModel = class {
|
|
|
553
555
|
...(0, import_internal.getResponseMetadata)(chunkValue)
|
|
554
556
|
});
|
|
555
557
|
}
|
|
556
|
-
if (chunkValue.usage
|
|
558
|
+
if ((0, import_es_toolkit2.isNotNil)(chunkValue.usage)) {
|
|
557
559
|
usage = chunkValue.usage;
|
|
558
560
|
}
|
|
559
561
|
const choice = chunkValue.choices[0];
|
|
560
|
-
if ((choice == null ? void 0 : choice.finish_reason)
|
|
562
|
+
if ((0, import_es_toolkit2.isNotNil)(choice == null ? void 0 : choice.finish_reason)) {
|
|
561
563
|
finishReason = {
|
|
562
564
|
unified: (0, import_internal.mapOpenAICompatibleFinishReason)(choice.finish_reason),
|
|
563
565
|
raw: choice.finish_reason
|
|
564
566
|
};
|
|
565
567
|
}
|
|
566
|
-
if ((choice == null ? void 0 : choice.delta)
|
|
568
|
+
if ((0, import_es_toolkit2.isNil)(choice == null ? void 0 : choice.delta)) {
|
|
567
569
|
return;
|
|
568
570
|
}
|
|
569
571
|
const delta = choice.delta;
|
|
570
|
-
if (delta.reasoning_content
|
|
571
|
-
if (
|
|
572
|
+
if ((0, import_es_toolkit2.isNotNil)(delta.reasoning_content)) {
|
|
573
|
+
if ((0, import_es_toolkit2.isNil)(currentReasoningId)) {
|
|
572
574
|
currentReasoningId = (0, import_provider_utils2.generateId)();
|
|
573
575
|
controller.enqueue({
|
|
574
576
|
type: "reasoning-start",
|
|
@@ -581,8 +583,8 @@ var FriendliAIChatLanguageModel = class {
|
|
|
581
583
|
delta: delta.reasoning_content
|
|
582
584
|
});
|
|
583
585
|
}
|
|
584
|
-
if (delta.content
|
|
585
|
-
if (
|
|
586
|
+
if ((0, import_es_toolkit2.isNotNil)(delta.content)) {
|
|
587
|
+
if ((0, import_es_toolkit2.isNil)(currentTextId)) {
|
|
586
588
|
currentTextId = (0, import_provider_utils2.generateId)();
|
|
587
589
|
controller.enqueue({
|
|
588
590
|
type: "text-start",
|
|
@@ -595,23 +597,23 @@ var FriendliAIChatLanguageModel = class {
|
|
|
595
597
|
delta: delta.content
|
|
596
598
|
});
|
|
597
599
|
}
|
|
598
|
-
if (delta.tool_calls
|
|
600
|
+
if ((0, import_es_toolkit2.isNotNil)(delta.tool_calls)) {
|
|
599
601
|
for (const toolCallDelta of delta.tool_calls) {
|
|
600
602
|
const index = toolCallDelta.index;
|
|
601
|
-
if (toolCalls[index]
|
|
603
|
+
if ((0, import_es_toolkit2.isNil)(toolCalls[index])) {
|
|
602
604
|
if (toolCallDelta.type !== "function") {
|
|
603
605
|
throw new import_provider3.InvalidResponseDataError({
|
|
604
606
|
data: toolCallDelta,
|
|
605
607
|
message: `Expected 'function' type.`
|
|
606
608
|
});
|
|
607
609
|
}
|
|
608
|
-
if (toolCallDelta.id
|
|
610
|
+
if ((0, import_es_toolkit2.isNil)(toolCallDelta.id)) {
|
|
609
611
|
throw new import_provider3.InvalidResponseDataError({
|
|
610
612
|
data: toolCallDelta,
|
|
611
613
|
message: `Expected 'id' to be a string.`
|
|
612
614
|
});
|
|
613
615
|
}
|
|
614
|
-
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name)
|
|
616
|
+
if ((0, import_es_toolkit2.isNil)((_e = toolCallDelta.function) == null ? void 0 : _e.name)) {
|
|
615
617
|
throw new import_provider3.InvalidResponseDataError({
|
|
616
618
|
data: toolCallDelta,
|
|
617
619
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -632,7 +634,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
632
634
|
toolName: toolCallDelta.function.name
|
|
633
635
|
});
|
|
634
636
|
const toolCall2 = toolCalls[index];
|
|
635
|
-
if (((_g = toolCall2.function) == null ? void 0 : _g.name)
|
|
637
|
+
if ((0, import_es_toolkit2.isNotNil)((_g = toolCall2.function) == null ? void 0 : _g.name) && (0, import_es_toolkit2.isNotNil)((_h = toolCall2.function) == null ? void 0 : _h.arguments)) {
|
|
636
638
|
if (toolCall2.function.arguments.length > 0) {
|
|
637
639
|
controller.enqueue({
|
|
638
640
|
type: "tool-input-delta",
|
|
@@ -660,7 +662,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
660
662
|
if (toolCall.hasFinished) {
|
|
661
663
|
continue;
|
|
662
664
|
}
|
|
663
|
-
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments)
|
|
665
|
+
if ((0, import_es_toolkit2.isNotNil)((_j = toolCallDelta.function) == null ? void 0 : _j.arguments)) {
|
|
664
666
|
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
665
667
|
}
|
|
666
668
|
controller.enqueue({
|
|
@@ -668,7 +670,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
668
670
|
id: toolCall.id,
|
|
669
671
|
delta: (_n = (_m = toolCallDelta.function) == null ? void 0 : _m.arguments) != null ? _n : ""
|
|
670
672
|
});
|
|
671
|
-
if (((_o = toolCall.function) == null ? void 0 : _o.name)
|
|
673
|
+
if ((0, import_es_toolkit2.isNotNil)((_o = toolCall.function) == null ? void 0 : _o.name) && (0, import_es_toolkit2.isNotNil)((_p = toolCall.function) == null ? void 0 : _p.arguments) && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
672
674
|
controller.enqueue({
|
|
673
675
|
type: "tool-input-end",
|
|
674
676
|
id: toolCall.id
|
|
@@ -686,13 +688,13 @@ var FriendliAIChatLanguageModel = class {
|
|
|
686
688
|
},
|
|
687
689
|
flush(controller) {
|
|
688
690
|
var _a2, _b, _c;
|
|
689
|
-
if (
|
|
691
|
+
if ((0, import_es_toolkit2.isNotNil)(currentReasoningId)) {
|
|
690
692
|
controller.enqueue({
|
|
691
693
|
type: "reasoning-end",
|
|
692
694
|
id: currentReasoningId
|
|
693
695
|
});
|
|
694
696
|
}
|
|
695
|
-
if (
|
|
697
|
+
if ((0, import_es_toolkit2.isNotNil)(currentTextId)) {
|
|
696
698
|
controller.enqueue({
|
|
697
699
|
type: "text-end",
|
|
698
700
|
id: currentTextId
|
|
@@ -716,10 +718,10 @@ var FriendliAIChatLanguageModel = class {
|
|
|
716
718
|
[providerOptionsName]: {},
|
|
717
719
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
|
718
720
|
};
|
|
719
|
-
if (((_b = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens)
|
|
721
|
+
if ((0, import_es_toolkit2.isNotNil)((_b = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _b.accepted_prediction_tokens)) {
|
|
720
722
|
providerMetadata[providerOptionsName].acceptedPredictionTokens = usage.completion_tokens_details.accepted_prediction_tokens;
|
|
721
723
|
}
|
|
722
|
-
if (((_c = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens)
|
|
724
|
+
if ((0, import_es_toolkit2.isNotNil)((_c = usage == null ? void 0 : usage.completion_tokens_details) == null ? void 0 : _c.rejected_prediction_tokens)) {
|
|
723
725
|
providerMetadata[providerOptionsName].rejectedPredictionTokens = usage.completion_tokens_details.rejected_prediction_tokens;
|
|
724
726
|
}
|
|
725
727
|
controller.enqueue({
|
|
@@ -856,6 +858,7 @@ var friendliProviderOptionsSchema = import_v4.z.object({
|
|
|
856
858
|
// src/friendli-settings.ts
|
|
857
859
|
var FriendliAIServerlessModelIds = [
|
|
858
860
|
"google/gemma-4-31B-it",
|
|
861
|
+
"zai-org/GLM-5.2",
|
|
859
862
|
"zai-org/GLM-5.1",
|
|
860
863
|
"zai-org/GLM-5",
|
|
861
864
|
"meta-llama/Llama-3.3-70B-Instruct",
|