@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.mjs
CHANGED
|
@@ -55,7 +55,7 @@ function prepareTools({
|
|
|
55
55
|
}
|
|
56
56
|
const openaiCompatTools = [];
|
|
57
57
|
for (const tool of tools) {
|
|
58
|
-
if (tool.type === "provider
|
|
58
|
+
if (tool.type === "provider") {
|
|
59
59
|
openaiCompatTools.push({
|
|
60
60
|
// NOTE: It would be better to use tool.name, but since ":" is replaced with "_", the following code is used instead
|
|
61
61
|
type: (_a = tool.id.split(".")[1]) != null ? _a : "unknown"
|
|
@@ -102,7 +102,7 @@ function prepareTools({
|
|
|
102
102
|
var FriendliAIChatLanguageModel = class {
|
|
103
103
|
// type inferred via constructor
|
|
104
104
|
constructor(modelId, config) {
|
|
105
|
-
this.specificationVersion = "
|
|
105
|
+
this.specificationVersion = "v3";
|
|
106
106
|
var _a;
|
|
107
107
|
this.modelId = modelId;
|
|
108
108
|
this.config = config;
|
|
@@ -137,7 +137,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
137
137
|
var _a;
|
|
138
138
|
const warnings = [];
|
|
139
139
|
if (topK != null) {
|
|
140
|
-
warnings.push({ type: "unsupported
|
|
140
|
+
warnings.push({ type: "unsupported", feature: "topK" });
|
|
141
141
|
}
|
|
142
142
|
const friendliOptions = await parseProviderOptions({
|
|
143
143
|
provider: "friendli",
|
|
@@ -146,8 +146,8 @@ var FriendliAIChatLanguageModel = class {
|
|
|
146
146
|
});
|
|
147
147
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !this.supportsStructuredOutputs) {
|
|
148
148
|
warnings.push({
|
|
149
|
-
type: "unsupported
|
|
150
|
-
|
|
149
|
+
type: "unsupported",
|
|
150
|
+
feature: "responseFormat",
|
|
151
151
|
details: "JSON response format schema is only supported with structuredOutputs"
|
|
152
152
|
});
|
|
153
153
|
}
|
|
@@ -199,7 +199,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
async doGenerate(options) {
|
|
202
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
202
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
203
203
|
const { args, warnings } = await this.getArgs({ ...options, stream: false });
|
|
204
204
|
const body = JSON.stringify(args);
|
|
205
205
|
const {
|
|
@@ -245,11 +245,17 @@ var FriendliAIChatLanguageModel = class {
|
|
|
245
245
|
content,
|
|
246
246
|
finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),
|
|
247
247
|
usage: {
|
|
248
|
-
inputTokens:
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
248
|
+
inputTokens: {
|
|
249
|
+
total: (_c = (_b = responseBody.usage) == null ? void 0 : _b.prompt_tokens) != null ? _c : void 0,
|
|
250
|
+
noCache: void 0,
|
|
251
|
+
cacheRead: (_f = (_e = (_d = responseBody.usage) == null ? void 0 : _d.prompt_tokens_details) == null ? void 0 : _e.cached_tokens) != null ? _f : void 0,
|
|
252
|
+
cacheWrite: void 0
|
|
253
|
+
},
|
|
254
|
+
outputTokens: {
|
|
255
|
+
total: (_h = (_g = responseBody.usage) == null ? void 0 : _g.completion_tokens) != null ? _h : void 0,
|
|
256
|
+
text: void 0,
|
|
257
|
+
reasoning: (_k = (_j = (_i = responseBody.usage) == null ? void 0 : _i.completion_tokens_details) == null ? void 0 : _j.reasoning_tokens) != null ? _k : void 0
|
|
258
|
+
}
|
|
253
259
|
},
|
|
254
260
|
// providerMetadata,
|
|
255
261
|
request: { body },
|
|
@@ -308,7 +314,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
308
314
|
},
|
|
309
315
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
|
310
316
|
transform(chunk, controller) {
|
|
311
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
317
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
312
318
|
if (!chunk.success) {
|
|
313
319
|
finishReason = "error";
|
|
314
320
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
@@ -316,6 +322,49 @@ var FriendliAIChatLanguageModel = class {
|
|
|
316
322
|
}
|
|
317
323
|
const value = chunk.value;
|
|
318
324
|
metadataExtractor == null ? void 0 : metadataExtractor.processChunk(chunk.rawValue);
|
|
325
|
+
if ("status" in value) {
|
|
326
|
+
const toolCallId = (_a2 = value.tool_call_id) != null ? _a2 : generateId();
|
|
327
|
+
switch (value.status) {
|
|
328
|
+
case "STARTED":
|
|
329
|
+
controller.enqueue({
|
|
330
|
+
type: "tool-call",
|
|
331
|
+
toolCallId,
|
|
332
|
+
toolName: value.name,
|
|
333
|
+
input: JSON.stringify(
|
|
334
|
+
Object.fromEntries(value.parameters.map((p) => [p.name, p.value]))
|
|
335
|
+
),
|
|
336
|
+
providerExecuted: true
|
|
337
|
+
});
|
|
338
|
+
break;
|
|
339
|
+
case "UPDATING":
|
|
340
|
+
break;
|
|
341
|
+
case "ENDED":
|
|
342
|
+
controller.enqueue({
|
|
343
|
+
type: "tool-result",
|
|
344
|
+
toolCallId,
|
|
345
|
+
toolName: value.name,
|
|
346
|
+
result: (_b = value.result) != null ? _b : ""
|
|
347
|
+
});
|
|
348
|
+
break;
|
|
349
|
+
case "ERRORED":
|
|
350
|
+
finishReason = "error";
|
|
351
|
+
controller.enqueue({
|
|
352
|
+
type: "tool-result",
|
|
353
|
+
toolCallId,
|
|
354
|
+
toolName: value.name,
|
|
355
|
+
result: (_d = (_c = value.error) == null ? void 0 : _c.msg) != null ? _d : "Unknown error",
|
|
356
|
+
isError: true
|
|
357
|
+
});
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
finishReason = "error";
|
|
361
|
+
controller.enqueue({
|
|
362
|
+
type: "error",
|
|
363
|
+
error: new Error(`Unsupported tool call status: ${value.status}`)
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
319
368
|
if ("error" in value) {
|
|
320
369
|
finishReason = "error";
|
|
321
370
|
controller.enqueue({ type: "error", error: value.error.message });
|
|
@@ -390,7 +439,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
390
439
|
message: `Expected 'id' to be a string.`
|
|
391
440
|
});
|
|
392
441
|
}
|
|
393
|
-
if (((
|
|
442
|
+
if (((_e = toolCallDelta.function) == null ? void 0 : _e.name) == null) {
|
|
394
443
|
throw new InvalidResponseDataError({
|
|
395
444
|
data: toolCallDelta,
|
|
396
445
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -401,12 +450,12 @@ var FriendliAIChatLanguageModel = class {
|
|
|
401
450
|
type: "function",
|
|
402
451
|
function: {
|
|
403
452
|
name: toolCallDelta.function.name,
|
|
404
|
-
arguments: (
|
|
453
|
+
arguments: (_f = toolCallDelta.function.arguments) != null ? _f : ""
|
|
405
454
|
},
|
|
406
455
|
hasFinished: false
|
|
407
456
|
};
|
|
408
457
|
const toolCall2 = toolCalls[index];
|
|
409
|
-
if (((
|
|
458
|
+
if (((_g = toolCall2.function) == null ? void 0 : _g.name) != null && ((_h = toolCall2.function) == null ? void 0 : _h.arguments) != null) {
|
|
410
459
|
if (toolCall2.function.arguments.length > 0) {
|
|
411
460
|
controller.enqueue({
|
|
412
461
|
type: "tool-input-delta",
|
|
@@ -417,7 +466,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
417
466
|
if (isParsableJson(toolCall2.function.arguments)) {
|
|
418
467
|
controller.enqueue({
|
|
419
468
|
type: "tool-call",
|
|
420
|
-
toolCallId: (
|
|
469
|
+
toolCallId: (_i = toolCall2.id) != null ? _i : generateId(),
|
|
421
470
|
toolName: toolCall2.function.name,
|
|
422
471
|
input: toolCall2.function.arguments
|
|
423
472
|
});
|
|
@@ -430,18 +479,18 @@ var FriendliAIChatLanguageModel = class {
|
|
|
430
479
|
if (toolCall.hasFinished) {
|
|
431
480
|
continue;
|
|
432
481
|
}
|
|
433
|
-
if (((
|
|
434
|
-
toolCall.function.arguments += (
|
|
482
|
+
if (((_j = toolCallDelta.function) == null ? void 0 : _j.arguments) != null) {
|
|
483
|
+
toolCall.function.arguments += (_l = (_k = toolCallDelta.function) == null ? void 0 : _k.arguments) != null ? _l : "";
|
|
435
484
|
}
|
|
436
485
|
controller.enqueue({
|
|
437
486
|
type: "tool-input-delta",
|
|
438
487
|
id: toolCall.id,
|
|
439
|
-
delta: (
|
|
488
|
+
delta: (_m = toolCallDelta.function.arguments) != null ? _m : ""
|
|
440
489
|
});
|
|
441
|
-
if (((
|
|
490
|
+
if (((_n = toolCall.function) == null ? void 0 : _n.name) != null && ((_o = toolCall.function) == null ? void 0 : _o.arguments) != null && isParsableJson(toolCall.function.arguments)) {
|
|
442
491
|
controller.enqueue({
|
|
443
492
|
type: "tool-call",
|
|
444
|
-
toolCallId: (
|
|
493
|
+
toolCallId: (_p = toolCall.id) != null ? _p : generateId(),
|
|
445
494
|
toolName: toolCall.function.name,
|
|
446
495
|
input: toolCall.function.arguments
|
|
447
496
|
});
|
|
@@ -451,7 +500,7 @@ var FriendliAIChatLanguageModel = class {
|
|
|
451
500
|
}
|
|
452
501
|
},
|
|
453
502
|
flush(controller) {
|
|
454
|
-
var _a2, _b, _c, _d
|
|
503
|
+
var _a2, _b, _c, _d;
|
|
455
504
|
const providerMetadata = {
|
|
456
505
|
[providerOptionsName]: {},
|
|
457
506
|
...metadataExtractor == null ? void 0 : metadataExtractor.buildMetadata()
|
|
@@ -466,11 +515,17 @@ var FriendliAIChatLanguageModel = class {
|
|
|
466
515
|
type: "finish",
|
|
467
516
|
finishReason,
|
|
468
517
|
usage: {
|
|
469
|
-
inputTokens:
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
518
|
+
inputTokens: {
|
|
519
|
+
total: (_a2 = usage.promptTokens) != null ? _a2 : void 0,
|
|
520
|
+
noCache: void 0,
|
|
521
|
+
cacheRead: (_b = usage.promptTokensDetails.cachedTokens) != null ? _b : void 0,
|
|
522
|
+
cacheWrite: void 0
|
|
523
|
+
},
|
|
524
|
+
outputTokens: {
|
|
525
|
+
total: (_c = usage.completionTokens) != null ? _c : void 0,
|
|
526
|
+
text: void 0,
|
|
527
|
+
reasoning: (_d = usage.completionTokensDetails.reasoningTokens) != null ? _d : void 0
|
|
528
|
+
}
|
|
474
529
|
},
|
|
475
530
|
providerMetadata
|
|
476
531
|
});
|
|
@@ -629,6 +684,25 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => z2.union([
|
|
|
629
684
|
),
|
|
630
685
|
usage: openaiCompatibleTokenUsageSchema
|
|
631
686
|
}),
|
|
687
|
+
z2.object({
|
|
688
|
+
name: z2.string(),
|
|
689
|
+
status: z2.enum(["ENDED", "STARTED", "ERRORED", "UPDATING"]),
|
|
690
|
+
message: z2.null(),
|
|
691
|
+
parameters: z2.array(
|
|
692
|
+
z2.object({
|
|
693
|
+
name: z2.string(),
|
|
694
|
+
value: z2.string()
|
|
695
|
+
})
|
|
696
|
+
),
|
|
697
|
+
result: z2.string().nullable(),
|
|
698
|
+
error: z2.object({
|
|
699
|
+
type: z2.enum(["INVALID_PARAMETER", "UNKNOWN"]),
|
|
700
|
+
msg: z2.string()
|
|
701
|
+
}).nullable(),
|
|
702
|
+
timestamp: z2.number(),
|
|
703
|
+
usage: z2.null(),
|
|
704
|
+
tool_call_id: z2.string().nullable()
|
|
705
|
+
}),
|
|
632
706
|
errorSchema
|
|
633
707
|
]);
|
|
634
708
|
var friendliProviderOptionsSchema = z2.object({
|
|
@@ -646,10 +720,13 @@ var friendliProviderOptionsSchema = z2.object({
|
|
|
646
720
|
|
|
647
721
|
// src/friendli-settings.ts
|
|
648
722
|
var FriendliAIServerlessModelIds = [
|
|
723
|
+
"MiniMaxAI/MiniMax-M2",
|
|
724
|
+
"zai-org/GLM-4.6",
|
|
649
725
|
"LGAI-EXAONE/EXAONE-4.0.1-32B",
|
|
650
726
|
"skt/A.X-4.0",
|
|
651
727
|
"skt/A.X-3.1",
|
|
652
728
|
"naver-hyperclovax/HyperCLOVAX-SEED-Think-14B",
|
|
729
|
+
"deepseek-ai/DeepSeek-V3.1",
|
|
653
730
|
"deepseek-ai/DeepSeek-R1-0528",
|
|
654
731
|
"meta-llama/Llama-4-Maverick-17B-128E-Instruct",
|
|
655
732
|
"meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
|
@@ -668,61 +745,62 @@ var FriendliAIServerlessModelIds = [
|
|
|
668
745
|
];
|
|
669
746
|
|
|
670
747
|
// src/friendli-tools.ts
|
|
671
|
-
|
|
748
|
+
import { jsonSchema } from "@ai-sdk/provider-utils";
|
|
749
|
+
function webSearch() {
|
|
672
750
|
return {
|
|
673
|
-
type: "provider
|
|
674
|
-
id: "friendli.web:
|
|
675
|
-
|
|
676
|
-
|
|
751
|
+
type: "provider",
|
|
752
|
+
id: "friendli.web:search",
|
|
753
|
+
args: {},
|
|
754
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
677
755
|
};
|
|
678
756
|
}
|
|
679
|
-
function
|
|
757
|
+
function webUrl() {
|
|
680
758
|
return {
|
|
681
|
-
type: "provider
|
|
682
|
-
id: "friendli.web:
|
|
683
|
-
|
|
684
|
-
|
|
759
|
+
type: "provider",
|
|
760
|
+
id: "friendli.web:url",
|
|
761
|
+
args: {},
|
|
762
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
685
763
|
};
|
|
686
764
|
}
|
|
687
|
-
function
|
|
765
|
+
function mathCalendar() {
|
|
688
766
|
return {
|
|
689
|
-
type: "provider
|
|
767
|
+
type: "provider",
|
|
690
768
|
id: "friendli.math:calendar",
|
|
691
|
-
|
|
692
|
-
|
|
769
|
+
args: {},
|
|
770
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
693
771
|
};
|
|
694
772
|
}
|
|
695
|
-
function
|
|
773
|
+
function mathStatistics() {
|
|
696
774
|
return {
|
|
697
|
-
type: "provider
|
|
775
|
+
type: "provider",
|
|
698
776
|
id: "friendli.math:statistics",
|
|
699
|
-
|
|
700
|
-
|
|
777
|
+
args: {},
|
|
778
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
701
779
|
};
|
|
702
780
|
}
|
|
703
|
-
function
|
|
781
|
+
function mathCalculator() {
|
|
704
782
|
return {
|
|
705
|
-
type: "provider
|
|
783
|
+
type: "provider",
|
|
706
784
|
id: "friendli.math:calculator",
|
|
707
|
-
|
|
708
|
-
|
|
785
|
+
args: {},
|
|
786
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
709
787
|
};
|
|
710
788
|
}
|
|
711
|
-
function
|
|
789
|
+
function codePythonInterpreter() {
|
|
712
790
|
return {
|
|
713
|
-
type: "provider
|
|
791
|
+
type: "provider",
|
|
714
792
|
id: "friendli.code:python-interpreter",
|
|
715
|
-
|
|
716
|
-
|
|
793
|
+
args: {},
|
|
794
|
+
inputSchema: jsonSchema({ type: "object", properties: {} })
|
|
717
795
|
};
|
|
718
796
|
}
|
|
719
797
|
var friendliTools = {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
798
|
+
webSearch,
|
|
799
|
+
webUrl,
|
|
800
|
+
mathCalendar,
|
|
801
|
+
mathStatistics,
|
|
802
|
+
mathCalculator,
|
|
803
|
+
codePythonInterpreter
|
|
726
804
|
};
|
|
727
805
|
|
|
728
806
|
// src/get-available-models.ts
|
|
@@ -903,7 +981,7 @@ function createFriendli(options = {}) {
|
|
|
903
981
|
});
|
|
904
982
|
};
|
|
905
983
|
const createTextEmbeddingModel = (modelId) => {
|
|
906
|
-
throw new NoSuchModelError({ modelId, modelType: "
|
|
984
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
907
985
|
};
|
|
908
986
|
const createImageModel = (modelId) => {
|
|
909
987
|
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
@@ -919,7 +997,7 @@ function createFriendli(options = {}) {
|
|
|
919
997
|
provider.chat = createLanguageModel;
|
|
920
998
|
provider.completion = createCompletionModel;
|
|
921
999
|
provider.embedding = createTextEmbeddingModel;
|
|
922
|
-
provider.
|
|
1000
|
+
provider.embeddingModel = createTextEmbeddingModel;
|
|
923
1001
|
provider.getAvailableModels = async (opts) => {
|
|
924
1002
|
var _a;
|
|
925
1003
|
const defaultURL = "https://api-internal.friendli.ai/api/graphql";
|