@friendliai/ai-provider 1.0.0-beta.0 → 1.0.0-beta.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/CHANGELOG.md +27 -0
- package/dist/index.d.mts +61 -28
- package/dist/index.d.ts +61 -28
- package/dist/index.js +144 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
28
|
// src/friendli-provider.ts
|
|
29
29
|
var import_openai_compatible = require("@ai-sdk/openai-compatible");
|
|
30
30
|
var import_provider3 = require("@ai-sdk/provider");
|
|
31
|
-
var
|
|
31
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/friendli-chat-language-model.ts
|
|
34
34
|
var import_internal = require("@ai-sdk/openai-compatible/internal");
|
|
@@ -63,7 +63,7 @@ function prepareTools({
|
|
|
63
63
|
}
|
|
64
64
|
const openaiCompatTools = [];
|
|
65
65
|
for (const tool of tools) {
|
|
66
|
-
if (tool.type === "provider
|
|
66
|
+
if (tool.type === "provider") {
|
|
67
67
|
openaiCompatTools.push({
|
|
68
68
|
// NOTE: It would be better to use tool.name, but since ":" is replaced with "_", the following code is used instead
|
|
69
69
|
type: (_a = tool.id.split(".")[1]) != null ? _a : "unknown"
|
|
@@ -110,7 +110,7 @@ function prepareTools({
|
|
|
110
110
|
var FriendliAIChatLanguageModel = class {
|
|
111
111
|
// type inferred via constructor
|
|
112
112
|
constructor(modelId, config) {
|
|
113
|
-
this.specificationVersion = "
|
|
113
|
+
this.specificationVersion = "v3";
|
|
114
114
|
var _a;
|
|
115
115
|
this.modelId = modelId;
|
|
116
116
|
this.config = config;
|
|
@@ -145,7 +145,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
145
145
|
var _a;
|
|
146
146
|
const warnings = [];
|
|
147
147
|
if (topK != null) {
|
|
148
|
-
warnings.push({ type: "unsupported
|
|
148
|
+
warnings.push({ type: "unsupported", feature: "topK" });
|
|
149
149
|
}
|
|
150
150
|
const friendliOptions = await (0, import_provider_utils2.parseProviderOptions)({
|
|
151
151
|
provider: "friendli",
|
|
@@ -154,8 +154,8 @@ var FriendliAIChatLanguageModel = class {
|
|
|
154
154
|
});
|
|
155
155
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
|
|
156
156
|
warnings.push({
|
|
157
|
-
type: "unsupported
|
|
158
|
-
|
|
157
|
+
type: "unsupported",
|
|
158
|
+
feature: "responseFormat",
|
|
159
159
|
details: "JSON response format schema is only supported with structuredOutputs"
|
|
160
160
|
});
|
|
161
161
|
}
|
|
@@ -207,7 +207,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
async doGenerate(options) {
|
|
210
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
210
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
211
211
|
const { args, warnings } = await this.getArgs({ ...options, stream: false });
|
|
212
212
|
const body = JSON.stringify(args);
|
|
213
213
|
const {
|
|
@@ -253,11 +253,17 @@ var FriendliAIChatLanguageModel = class {
|
|
|
253
253
|
content,
|
|
254
254
|
finishReason: (0, import_internal.mapOpenAICompatibleFinishReason)(choice.finish_reason),
|
|
255
255
|
usage: {
|
|
256
|
-
inputTokens:
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
inputTokens: {
|
|
257
|
+
total: (_c = (_b = responseBody.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
|
|
258
|
+
noCache: void 0,
|
|
259
|
+
cacheRead: (_f = (_e = (_d = responseBody.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
260
|
+
cacheWrite: void 0
|
|
261
|
+
},
|
|
262
|
+
outputTokens: {
|
|
263
|
+
total: (_h = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
|
264
|
+
text: void 0,
|
|
265
|
+
reasoning: (_k = (_j = (_i = responseBody.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
266
|
+
}
|
|
261
267
|
},
|
|
262
268
|
// providerMetadata,
|
|
263
269
|
request: { body },
|
|
@@ -316,7 +322,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
316
322
|
},
|
|
317
323
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
|
318
324
|
transform(chunk, controller) {
|
|
319
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
325
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
320
326
|
if (!chunk.success) {
|
|
321
327
|
finishReason = "error";
|
|
322
328
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -324,6 +330,49 @@ var FriendliAIChatLanguageModel = class {
|
|
|
324
330
|
}
|
|
325
331
|
const value = chunk.value;
|
|
326
332
|
metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
|
|
333
|
+
if ("status" in value) {
|
|
334
|
+
const toolCallId = (_a2 = value.tool_call_id) != null ? _a2 : (0, import_provider_utils2.generateId)();
|
|
335
|
+
switch (value.status) {
|
|
336
|
+
case "STARTED":
|
|
337
|
+
controller.enqueue({
|
|
338
|
+
type: "tool-call",
|
|
339
|
+
toolCallId,
|
|
340
|
+
toolName: value.name,
|
|
341
|
+
input: JSON.stringify(
|
|
342
|
+
Object.fromEntries(value.parameters.map((p) => [p.name, p.value]))
|
|
343
|
+
),
|
|
344
|
+
providerExecuted: true
|
|
345
|
+
});
|
|
346
|
+
break;
|
|
347
|
+
case "UPDATING":
|
|
348
|
+
break;
|
|
349
|
+
case "ENDED":
|
|
350
|
+
controller.enqueue({
|
|
351
|
+
type: "tool-result",
|
|
352
|
+
toolCallId,
|
|
353
|
+
toolName: value.name,
|
|
354
|
+
result: (_b = value.result) != null ? _b : ""
|
|
355
|
+
});
|
|
356
|
+
break;
|
|
357
|
+
case "ERRORED":
|
|
358
|
+
finishReason = "error";
|
|
359
|
+
controller.enqueue({
|
|
360
|
+
type: "tool-result",
|
|
361
|
+
toolCallId,
|
|
362
|
+
toolName: value.name,
|
|
363
|
+
result: (_d = (_c = value.error) == null ? void 0 : _c.msg) != null ? _d : "Unknown error",
|
|
364
|
+
isError: true
|
|
365
|
+
});
|
|
366
|
+
break;
|
|
367
|
+
default:
|
|
368
|
+
finishReason = "error";
|
|
369
|
+
controller.enqueue({
|
|
370
|
+
type: "error",
|
|
371
|
+
error: new Error(`Unsupported tool call status: ${value.status}`)
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
327
376
|
if ("error" in value) {
|
|
328
377
|
finishReason = "error";
|
|
329
378
|
controller.enqueue({ type: "error", error: value.error.message });
|
|
@@ -398,7 +447,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
398
447
|
message: `Expected 'id' to be a string.`
|
|
399
448
|
});
|
|
400
449
|
}
|
|
401
|
-
if (((
|
|
450
|
+
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
|
|
402
451
|
throw new import_provider2.InvalidResponseDataError({
|
|
403
452
|
data: toolCallDelta,
|
|
404
453
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -409,12 +458,12 @@ var FriendliAIChatLanguageModel = class {
|
|
|
409
458
|
type: "function",
|
|
410
459
|
function: {
|
|
411
460
|
name: toolCallDelta.function.name,
|
|
412
|
-
arguments: (
|
|
461
|
+
arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
|
|
413
462
|
},
|
|
414
463
|
hasFinished: false
|
|
415
464
|
};
|
|
416
465
|
const toolCall2 = toolCalls[index];
|
|
417
|
-
if (((
|
|
466
|
+
if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
|
|
418
467
|
if (toolCall2.function.arguments.length > 0) {
|
|
419
468
|
controller.enqueue({
|
|
420
469
|
type: "tool-input-delta",
|
|
@@ -425,7 +474,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
425
474
|
if ((0, import_provider_utils2.isParsableJson)(toolCall2.function.arguments)) {
|
|
426
475
|
controller.enqueue({
|
|
427
476
|
type: "tool-call",
|
|
428
|
-
toolCallId: (
|
|
477
|
+
toolCallId: (_i = toolCall2.id) != null ? _i : (0, import_provider_utils2.generateId)(),
|
|
429
478
|
toolName: toolCall2.function.name,
|
|
430
479
|
input: toolCall2.function.arguments
|
|
431
480
|
});
|
|
@@ -438,18 +487,18 @@ var FriendliAIChatLanguageModel = class {
|
|
|
438
487
|
if (toolCall.hasFinished) {
|
|
439
488
|
continue;
|
|
440
489
|
}
|
|
441
|
-
if (((
|
|
442
|
-
toolCall.function.arguments += (
|
|
490
|
+
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
491
|
+
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
443
492
|
}
|
|
444
493
|
controller.enqueue({
|
|
445
494
|
type: "tool-input-delta",
|
|
446
495
|
id: toolCall.id,
|
|
447
|
-
delta: (
|
|
496
|
+
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
448
497
|
});
|
|
449
|
-
if (((
|
|
498
|
+
if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && (0, import_provider_utils2.isParsableJson)(toolCall.function.arguments)) {
|
|
450
499
|
controller.enqueue({
|
|
451
500
|
type: "tool-call",
|
|
452
|
-
toolCallId: (
|
|
501
|
+
toolCallId: (_p = toolCall.id) != null ? _p : (0, import_provider_utils2.generateId)(),
|
|
453
502
|
toolName: toolCall.function.name,
|
|
454
503
|
input: toolCall.function.arguments
|
|
455
504
|
});
|
|
@@ -459,7 +508,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
459
508
|
}
|
|
460
509
|
},
|
|
461
510
|
flush(controller) {
|
|
462
|
-
var _a2, _b, _c, _d
|
|
511
|
+
var _a2, _b, _c, _d;
|
|
463
512
|
const providerMetadata = {
|
|
464
513
|
[providerOptionsName]: {},
|
|
465
514
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
|
@@ -474,11 +523,17 @@ var FriendliAIChatLanguageModel = class {
|
|
|
474
523
|
type: "finish",
|
|
475
524
|
finishReason,
|
|
476
525
|
usage: {
|
|
477
|
-
inputTokens:
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
526
|
+
inputTokens: {
|
|
527
|
+
total: (_a2 = usage.promptTokens) != null ? _a2 : void 0,
|
|
528
|
+
noCache: void 0,
|
|
529
|
+
cacheRead: (_b = usage.promptTokensDetails.cachedTokens) != null ? _b : void 0,
|
|
530
|
+
cacheWrite: void 0
|
|
531
|
+
},
|
|
532
|
+
outputTokens: {
|
|
533
|
+
total: (_c = usage.completionTokens) != null ? _c : void 0,
|
|
534
|
+
text: void 0,
|
|
535
|
+
reasoning: (_d = usage.completionTokensDetails.reasoningTokens) != null ? _d : void 0
|
|
536
|
+
}
|
|
482
537
|
},
|
|
483
538
|
providerMetadata
|
|
484
539
|
});
|
|
@@ -637,6 +692,25 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_v42.z.union(
|
|
|
637
692
|
),
|
|
638
693
|
usage: openaiCompatibleTokenUsageSchema
|
|
639
694
|
}),
|
|
695
|
+
import_v42.z.object({
|
|
696
|
+
name: import_v42.z.string(),
|
|
697
|
+
status: import_v42.z.enum(["ENDED", "STARTED", "ERRORED", "UPDATING"]),
|
|
698
|
+
message: import_v42.z.null(),
|
|
699
|
+
parameters: import_v42.z.array(
|
|
700
|
+
import_v42.z.object({
|
|
701
|
+
name: import_v42.z.string(),
|
|
702
|
+
value: import_v42.z.string()
|
|
703
|
+
})
|
|
704
|
+
),
|
|
705
|
+
result: import_v42.z.string().nullable(),
|
|
706
|
+
error: import_v42.z.object({
|
|
707
|
+
type: import_v42.z.enum(["INVALID_PARAMETER", "UNKNOWN"]),
|
|
708
|
+
msg: import_v42.z.string()
|
|
709
|
+
}).nullable(),
|
|
710
|
+
timestamp: import_v42.z.number(),
|
|
711
|
+
usage: import_v42.z.null(),
|
|
712
|
+
tool_call_id: import_v42.z.string().nullable()
|
|
713
|
+
}),
|
|
640
714
|
errorSchema
|
|
641
715
|
]);
|
|
642
716
|
var friendliProviderOptionsSchema = import_v42.z.object({
|
|
@@ -654,10 +728,13 @@ var friendliProviderOptionsSchema = import_v42.z.object({
|
|
|
654
728
|
|
|
655
729
|
// src/friendli-settings.ts
|
|
656
730
|
var FriendliAIServerlessModelIds = [
|
|
731
|
+
"MiniMaxAI/MiniMax-M2",
|
|
732
|
+
"zai-org/GLM-4.6",
|
|
657
733
|
"LGAI-EXAONE/EXAONE-4.0.1-32B",
|
|
658
734
|
"skt/A.X-4.0",
|
|
659
735
|
"skt/A.X-3.1",
|
|
660
736
|
"naver-hyperclovax/HyperCLOVAX-SEED-Think-14B",
|
|
737
|
+
"deepseek-ai/DeepSeek-V3.1",
|
|
661
738
|
"deepseek-ai/DeepSeek-R1-0528",
|
|
662
739
|
"meta-llama/Llama-4-Maverick-17B-128E-Instruct",
|
|
663
740
|
"meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
|
@@ -676,65 +753,66 @@ var FriendliAIServerlessModelIds = [
|
|
|
676
753
|
];
|
|
677
754
|
|
|
678
755
|
// src/friendli-tools.ts
|
|
679
|
-
|
|
756
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
757
|
+
function webSearch() {
|
|
680
758
|
return {
|
|
681
|
-
type: "provider
|
|
682
|
-
id: "friendli.web:
|
|
683
|
-
|
|
684
|
-
|
|
759
|
+
type: "provider",
|
|
760
|
+
id: "friendli.web:search",
|
|
761
|
+
args: {},
|
|
762
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
685
763
|
};
|
|
686
764
|
}
|
|
687
|
-
function
|
|
765
|
+
function webUrl() {
|
|
688
766
|
return {
|
|
689
|
-
type: "provider
|
|
690
|
-
id: "friendli.web:
|
|
691
|
-
|
|
692
|
-
|
|
767
|
+
type: "provider",
|
|
768
|
+
id: "friendli.web:url",
|
|
769
|
+
args: {},
|
|
770
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
693
771
|
};
|
|
694
772
|
}
|
|
695
|
-
function
|
|
773
|
+
function mathCalendar() {
|
|
696
774
|
return {
|
|
697
|
-
type: "provider
|
|
775
|
+
type: "provider",
|
|
698
776
|
id: "friendli.math:calendar",
|
|
699
|
-
|
|
700
|
-
|
|
777
|
+
args: {},
|
|
778
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
701
779
|
};
|
|
702
780
|
}
|
|
703
|
-
function
|
|
781
|
+
function mathStatistics() {
|
|
704
782
|
return {
|
|
705
|
-
type: "provider
|
|
783
|
+
type: "provider",
|
|
706
784
|
id: "friendli.math:statistics",
|
|
707
|
-
|
|
708
|
-
|
|
785
|
+
args: {},
|
|
786
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
709
787
|
};
|
|
710
788
|
}
|
|
711
|
-
function
|
|
789
|
+
function mathCalculator() {
|
|
712
790
|
return {
|
|
713
|
-
type: "provider
|
|
791
|
+
type: "provider",
|
|
714
792
|
id: "friendli.math:calculator",
|
|
715
|
-
|
|
716
|
-
|
|
793
|
+
args: {},
|
|
794
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
717
795
|
};
|
|
718
796
|
}
|
|
719
|
-
function
|
|
797
|
+
function codePythonInterpreter() {
|
|
720
798
|
return {
|
|
721
|
-
type: "provider
|
|
799
|
+
type: "provider",
|
|
722
800
|
id: "friendli.code:python-interpreter",
|
|
723
|
-
|
|
724
|
-
|
|
801
|
+
args: {},
|
|
802
|
+
inputSchema: (0, import_provider_utils3.jsonSchema)({ type: "object", properties: {} })
|
|
725
803
|
};
|
|
726
804
|
}
|
|
727
805
|
var friendliTools = {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
806
|
+
webSearch,
|
|
807
|
+
webUrl,
|
|
808
|
+
mathCalendar,
|
|
809
|
+
mathStatistics,
|
|
810
|
+
mathCalculator,
|
|
811
|
+
codePythonInterpreter
|
|
734
812
|
};
|
|
735
813
|
|
|
736
814
|
// src/get-available-models.ts
|
|
737
|
-
var
|
|
815
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
738
816
|
var DEFAULT_GRAPHQL_URL = "https://api-internal.friendli.ai/api/graphql";
|
|
739
817
|
async function postGraphQL(url, body, headers) {
|
|
740
818
|
const res = await fetch(url, {
|
|
@@ -770,7 +848,7 @@ async function getAvailableModelsImpl(options) {
|
|
|
770
848
|
var _a, _b, _c, _d, _e, _f;
|
|
771
849
|
let token;
|
|
772
850
|
try {
|
|
773
|
-
token = (_a = options.apiKey) != null ? _a : (0,
|
|
851
|
+
token = (_a = options.apiKey) != null ? _a : (0, import_provider_utils4.loadApiKey)({
|
|
774
852
|
apiKey: void 0,
|
|
775
853
|
environmentVariableName: "FRIENDLI_TOKEN",
|
|
776
854
|
description: "FRIENDLI_TOKEN"
|
|
@@ -843,7 +921,7 @@ async function getAvailableModelsImpl(options) {
|
|
|
843
921
|
// src/friendli-provider.ts
|
|
844
922
|
function createFriendli(options = {}) {
|
|
845
923
|
const getHeaders = () => ({
|
|
846
|
-
Authorization: `Bearer ${(0,
|
|
924
|
+
Authorization: `Bearer ${(0, import_provider_utils5.loadApiKey)({
|
|
847
925
|
apiKey: options.apiKey,
|
|
848
926
|
environmentVariableName: "FRIENDLI_TOKEN",
|
|
849
927
|
description: "FRIENDLI_TOKEN"
|
|
@@ -857,7 +935,7 @@ function createFriendli(options = {}) {
|
|
|
857
935
|
serverless_tools: "https://api.friendli.ai/serverless/tools/v1",
|
|
858
936
|
dedicated: "https://api.friendli.ai/dedicated/v1"
|
|
859
937
|
};
|
|
860
|
-
const customBaseURL = (0,
|
|
938
|
+
const customBaseURL = (0, import_provider_utils5.withoutTrailingSlash)(baseURL);
|
|
861
939
|
if (typeof customBaseURL === "string" && customBaseURL !== "dedicated" && customBaseURL !== "serverless" && customBaseURL !== "serverless-tools") {
|
|
862
940
|
return { baseURL: customBaseURL, type: "custom" };
|
|
863
941
|
}
|
|
@@ -911,7 +989,7 @@ function createFriendli(options = {}) {
|
|
|
911
989
|
});
|
|
912
990
|
};
|
|
913
991
|
const createTextEmbeddingModel = (modelId) => {
|
|
914
|
-
throw new import_provider3.NoSuchModelError({ modelId, modelType: "
|
|
992
|
+
throw new import_provider3.NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
915
993
|
};
|
|
916
994
|
const createImageModel = (modelId) => {
|
|
917
995
|
throw new import_provider3.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
@@ -927,7 +1005,7 @@ function createFriendli(options = {}) {
|
|
|
927
1005
|
provider.chat = createLanguageModel;
|
|
928
1006
|
provider.completion = createCompletionModel;
|
|
929
1007
|
provider.embedding = createTextEmbeddingModel;
|
|
930
|
-
provider.
|
|
1008
|
+
provider.embeddingModel = createTextEmbeddingModel;
|
|
931
1009
|
provider.getAvailableModels = async (opts) => {
|
|
932
1010
|
var _a;
|
|
933
1011
|
const defaultURL = "https://api-internal.friendli.ai/api/graphql";
|