@ai-sdk/huggingface 2.0.0-beta.23 → 2.0.0-beta.25
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 +31 -0
- package/dist/index.js +260 -255
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/src/huggingface-config.ts +1 -1
- package/src/responses/huggingface-responses-language-model.ts +22 -2
- package/dist/index.d.mts +0 -59
- package/dist/index.mjs +0 -980
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,50 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createHuggingFace: () => createHuggingFace,
|
|
24
|
-
huggingface: () => huggingface
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
1
|
// src/huggingface-provider.ts
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId as generateId2,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
31
10
|
|
|
32
11
|
// src/responses/huggingface-responses-language-model.ts
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
APICallError
|
|
14
|
+
} from "@ai-sdk/provider";
|
|
15
|
+
import {
|
|
16
|
+
combineHeaders,
|
|
17
|
+
createEventSourceResponseHandler,
|
|
18
|
+
createJsonResponseHandler,
|
|
19
|
+
generateId,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi,
|
|
22
|
+
serializeModelOptions,
|
|
23
|
+
WORKFLOW_SERIALIZE,
|
|
24
|
+
WORKFLOW_DESERIALIZE
|
|
25
|
+
} from "@ai-sdk/provider-utils";
|
|
26
|
+
import { z as z2 } from "zod/v4";
|
|
36
27
|
|
|
37
28
|
// src/huggingface-error.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var huggingfaceErrorDataSchema =
|
|
41
|
-
error:
|
|
42
|
-
message:
|
|
43
|
-
type:
|
|
44
|
-
code:
|
|
29
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
30
|
+
import { z } from "zod/v4";
|
|
31
|
+
var huggingfaceErrorDataSchema = z.object({
|
|
32
|
+
error: z.object({
|
|
33
|
+
message: z.string(),
|
|
34
|
+
type: z.string().optional(),
|
|
35
|
+
code: z.string().optional()
|
|
45
36
|
})
|
|
46
37
|
});
|
|
47
|
-
var huggingfaceFailedResponseHandler =
|
|
38
|
+
var huggingfaceFailedResponseHandler = createJsonErrorResponseHandler({
|
|
48
39
|
errorSchema: huggingfaceErrorDataSchema,
|
|
49
40
|
errorToMessage: (data) => data.error.message
|
|
50
41
|
});
|
|
@@ -89,8 +80,10 @@ function convertHuggingFaceResponsesUsage(usage) {
|
|
|
89
80
|
}
|
|
90
81
|
|
|
91
82
|
// src/responses/convert-to-huggingface-responses-messages.ts
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
import {
|
|
84
|
+
UnsupportedFunctionalityError
|
|
85
|
+
} from "@ai-sdk/provider";
|
|
86
|
+
import { isProviderReference } from "@ai-sdk/provider-utils";
|
|
94
87
|
async function convertToHuggingFaceResponsesMessages({
|
|
95
88
|
prompt
|
|
96
89
|
}) {
|
|
@@ -111,8 +104,8 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
111
104
|
return { type: "input_text", text: part.text };
|
|
112
105
|
}
|
|
113
106
|
case "file": {
|
|
114
|
-
if (
|
|
115
|
-
throw new
|
|
107
|
+
if (isProviderReference(part.data)) {
|
|
108
|
+
throw new UnsupportedFunctionalityError({
|
|
116
109
|
functionality: "file parts with provider references"
|
|
117
110
|
});
|
|
118
111
|
}
|
|
@@ -123,7 +116,7 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
123
116
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`
|
|
124
117
|
};
|
|
125
118
|
} else {
|
|
126
|
-
throw new
|
|
119
|
+
throw new UnsupportedFunctionalityError({
|
|
127
120
|
functionality: `file part media type ${part.mediaType}`
|
|
128
121
|
});
|
|
129
122
|
}
|
|
@@ -259,7 +252,7 @@ function mapHuggingFaceResponsesFinishReason(finishReason) {
|
|
|
259
252
|
}
|
|
260
253
|
|
|
261
254
|
// src/responses/huggingface-responses-language-model.ts
|
|
262
|
-
var HuggingFaceResponsesLanguageModel = class {
|
|
255
|
+
var HuggingFaceResponsesLanguageModel = class _HuggingFaceResponsesLanguageModel {
|
|
263
256
|
constructor(modelId, config) {
|
|
264
257
|
this.specificationVersion = "v4";
|
|
265
258
|
this.supportedUrls = {
|
|
@@ -268,6 +261,18 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
268
261
|
this.modelId = modelId;
|
|
269
262
|
this.config = config;
|
|
270
263
|
}
|
|
264
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
265
|
+
return serializeModelOptions({
|
|
266
|
+
modelId: model.modelId,
|
|
267
|
+
config: model.config
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
271
|
+
return new _HuggingFaceResponsesLanguageModel(
|
|
272
|
+
options.modelId,
|
|
273
|
+
options.config
|
|
274
|
+
);
|
|
275
|
+
}
|
|
271
276
|
get provider() {
|
|
272
277
|
return this.config.provider;
|
|
273
278
|
}
|
|
@@ -307,7 +312,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
307
312
|
prompt
|
|
308
313
|
});
|
|
309
314
|
warnings.push(...messageWarnings);
|
|
310
|
-
const huggingfaceOptions = await
|
|
315
|
+
const huggingfaceOptions = await parseProviderOptions({
|
|
311
316
|
provider: "huggingface",
|
|
312
317
|
providerOptions,
|
|
313
318
|
schema: huggingfaceResponsesProviderOptionsSchema
|
|
@@ -354,7 +359,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
354
359
|
return { args: baseArgs, warnings };
|
|
355
360
|
}
|
|
356
361
|
async doGenerate(options) {
|
|
357
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
362
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
358
363
|
const { args, warnings } = await this.getArgs(options);
|
|
359
364
|
const body = {
|
|
360
365
|
...args,
|
|
@@ -368,19 +373,19 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
368
373
|
value: response,
|
|
369
374
|
responseHeaders,
|
|
370
375
|
rawValue: rawResponse
|
|
371
|
-
} = await
|
|
376
|
+
} = await postJsonToApi({
|
|
372
377
|
url,
|
|
373
|
-
headers: (
|
|
378
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
374
379
|
body,
|
|
375
380
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
376
|
-
successfulResponseHandler:
|
|
381
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
377
382
|
huggingfaceResponsesResponseSchema
|
|
378
383
|
),
|
|
379
384
|
abortSignal: options.abortSignal,
|
|
380
385
|
fetch: this.config.fetch
|
|
381
386
|
});
|
|
382
387
|
if (response.error) {
|
|
383
|
-
throw new
|
|
388
|
+
throw new APICallError({
|
|
384
389
|
message: response.error.message,
|
|
385
390
|
url,
|
|
386
391
|
requestBodyValues: body,
|
|
@@ -409,7 +414,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
409
414
|
content.push({
|
|
410
415
|
type: "source",
|
|
411
416
|
sourceType: "url",
|
|
412
|
-
id: (
|
|
417
|
+
id: (_e = (_d = (_c = this.config).generateId) == null ? void 0 : _d.call(_c)) != null ? _e : generateId(),
|
|
413
418
|
url: annotation.url,
|
|
414
419
|
title: annotation.title
|
|
415
420
|
});
|
|
@@ -494,9 +499,9 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
494
499
|
content,
|
|
495
500
|
finishReason: {
|
|
496
501
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
497
|
-
(
|
|
502
|
+
(_g = (_f = response.incomplete_details) == null ? void 0 : _f.reason) != null ? _g : "stop"
|
|
498
503
|
),
|
|
499
|
-
raw: (
|
|
504
|
+
raw: (_i = (_h = response.incomplete_details) == null ? void 0 : _h.reason) != null ? _i : void 0
|
|
500
505
|
},
|
|
501
506
|
usage: convertHuggingFaceResponsesUsage(response.usage),
|
|
502
507
|
request: { body },
|
|
@@ -516,20 +521,21 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
516
521
|
};
|
|
517
522
|
}
|
|
518
523
|
async doStream(options) {
|
|
524
|
+
var _a, _b;
|
|
519
525
|
const { args, warnings } = await this.getArgs(options);
|
|
520
526
|
const body = {
|
|
521
527
|
...args,
|
|
522
528
|
stream: true
|
|
523
529
|
};
|
|
524
|
-
const { value: response, responseHeaders } = await
|
|
530
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
525
531
|
url: this.config.url({
|
|
526
532
|
path: "/responses",
|
|
527
533
|
modelId: this.modelId
|
|
528
534
|
}),
|
|
529
|
-
headers: (
|
|
535
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
530
536
|
body,
|
|
531
537
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
532
|
-
successfulResponseHandler:
|
|
538
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
533
539
|
huggingfaceResponsesChunkSchema
|
|
534
540
|
),
|
|
535
541
|
abortSignal: options.abortSignal,
|
|
@@ -548,7 +554,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
548
554
|
controller.enqueue({ type: "stream-start", warnings });
|
|
549
555
|
},
|
|
550
556
|
transform(chunk, controller) {
|
|
551
|
-
var
|
|
557
|
+
var _a2, _b2, _c, _d;
|
|
552
558
|
if (!chunk.success) {
|
|
553
559
|
finishReason = {
|
|
554
560
|
unified: "error",
|
|
@@ -630,7 +636,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
630
636
|
responseId = value.response.id;
|
|
631
637
|
finishReason = {
|
|
632
638
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
633
|
-
(
|
|
639
|
+
(_b2 = (_a2 = value.response.incomplete_details) == null ? void 0 : _a2.reason) != null ? _b2 : "stop"
|
|
634
640
|
),
|
|
635
641
|
raw: (_d = (_c = value.response.incomplete_details) == null ? void 0 : _c.reason) != null ? _d : void 0
|
|
636
642
|
};
|
|
@@ -682,231 +688,231 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
682
688
|
};
|
|
683
689
|
}
|
|
684
690
|
};
|
|
685
|
-
var huggingfaceResponsesProviderOptionsSchema =
|
|
686
|
-
metadata:
|
|
687
|
-
instructions:
|
|
688
|
-
strictJsonSchema:
|
|
689
|
-
reasoningEffort:
|
|
691
|
+
var huggingfaceResponsesProviderOptionsSchema = z2.object({
|
|
692
|
+
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
693
|
+
instructions: z2.string().optional(),
|
|
694
|
+
strictJsonSchema: z2.boolean().optional(),
|
|
695
|
+
reasoningEffort: z2.string().optional()
|
|
690
696
|
});
|
|
691
|
-
var huggingfaceResponsesOutputSchema =
|
|
692
|
-
|
|
693
|
-
type:
|
|
694
|
-
id:
|
|
695
|
-
role:
|
|
696
|
-
status:
|
|
697
|
-
content:
|
|
698
|
-
|
|
699
|
-
type:
|
|
700
|
-
text:
|
|
701
|
-
annotations:
|
|
697
|
+
var huggingfaceResponsesOutputSchema = z2.discriminatedUnion("type", [
|
|
698
|
+
z2.object({
|
|
699
|
+
type: z2.literal("message"),
|
|
700
|
+
id: z2.string(),
|
|
701
|
+
role: z2.string().optional(),
|
|
702
|
+
status: z2.string().optional(),
|
|
703
|
+
content: z2.array(
|
|
704
|
+
z2.object({
|
|
705
|
+
type: z2.literal("output_text"),
|
|
706
|
+
text: z2.string(),
|
|
707
|
+
annotations: z2.array(z2.any()).optional()
|
|
702
708
|
})
|
|
703
709
|
)
|
|
704
710
|
}),
|
|
705
|
-
|
|
706
|
-
type:
|
|
707
|
-
id:
|
|
708
|
-
status:
|
|
709
|
-
content:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
711
|
+
z2.object({
|
|
712
|
+
type: z2.literal("reasoning"),
|
|
713
|
+
id: z2.string(),
|
|
714
|
+
status: z2.string().optional(),
|
|
715
|
+
content: z2.array(
|
|
716
|
+
z2.object({
|
|
717
|
+
type: z2.literal("reasoning_text"),
|
|
718
|
+
text: z2.string()
|
|
713
719
|
})
|
|
714
720
|
),
|
|
715
|
-
summary:
|
|
716
|
-
|
|
717
|
-
type:
|
|
718
|
-
text:
|
|
721
|
+
summary: z2.array(
|
|
722
|
+
z2.object({
|
|
723
|
+
type: z2.literal("reasoning_summary"),
|
|
724
|
+
text: z2.string()
|
|
719
725
|
}).optional()
|
|
720
726
|
).optional()
|
|
721
727
|
}),
|
|
722
|
-
|
|
723
|
-
type:
|
|
724
|
-
id:
|
|
725
|
-
call_id:
|
|
726
|
-
name:
|
|
727
|
-
arguments:
|
|
728
|
-
output:
|
|
729
|
-
status:
|
|
728
|
+
z2.object({
|
|
729
|
+
type: z2.literal("function_call"),
|
|
730
|
+
id: z2.string(),
|
|
731
|
+
call_id: z2.string(),
|
|
732
|
+
name: z2.string(),
|
|
733
|
+
arguments: z2.string(),
|
|
734
|
+
output: z2.string().optional(),
|
|
735
|
+
status: z2.string().optional()
|
|
730
736
|
}),
|
|
731
|
-
|
|
732
|
-
type:
|
|
733
|
-
id:
|
|
734
|
-
name:
|
|
735
|
-
arguments:
|
|
736
|
-
output:
|
|
737
|
-
status:
|
|
737
|
+
z2.object({
|
|
738
|
+
type: z2.literal("mcp_call"),
|
|
739
|
+
id: z2.string(),
|
|
740
|
+
name: z2.string(),
|
|
741
|
+
arguments: z2.string(),
|
|
742
|
+
output: z2.string().optional(),
|
|
743
|
+
status: z2.string().optional()
|
|
738
744
|
}),
|
|
739
|
-
|
|
740
|
-
type:
|
|
741
|
-
id:
|
|
742
|
-
server_label:
|
|
743
|
-
tools:
|
|
744
|
-
status:
|
|
745
|
+
z2.object({
|
|
746
|
+
type: z2.literal("mcp_list_tools"),
|
|
747
|
+
id: z2.string(),
|
|
748
|
+
server_label: z2.string(),
|
|
749
|
+
tools: z2.array(z2.any()).optional(),
|
|
750
|
+
status: z2.string().optional()
|
|
745
751
|
})
|
|
746
752
|
]);
|
|
747
|
-
var huggingfaceResponsesResponseSchema =
|
|
748
|
-
id:
|
|
749
|
-
model:
|
|
750
|
-
object:
|
|
751
|
-
created_at:
|
|
752
|
-
status:
|
|
753
|
-
error:
|
|
754
|
-
instructions:
|
|
755
|
-
max_output_tokens:
|
|
756
|
-
metadata:
|
|
757
|
-
tool_choice:
|
|
758
|
-
tools:
|
|
759
|
-
temperature:
|
|
760
|
-
top_p:
|
|
761
|
-
incomplete_details:
|
|
762
|
-
reason:
|
|
753
|
+
var huggingfaceResponsesResponseSchema = z2.object({
|
|
754
|
+
id: z2.string(),
|
|
755
|
+
model: z2.string(),
|
|
756
|
+
object: z2.string(),
|
|
757
|
+
created_at: z2.number(),
|
|
758
|
+
status: z2.string(),
|
|
759
|
+
error: z2.any().nullable(),
|
|
760
|
+
instructions: z2.any().nullable(),
|
|
761
|
+
max_output_tokens: z2.any().nullable(),
|
|
762
|
+
metadata: z2.any().nullable(),
|
|
763
|
+
tool_choice: z2.any(),
|
|
764
|
+
tools: z2.array(z2.any()),
|
|
765
|
+
temperature: z2.number(),
|
|
766
|
+
top_p: z2.number(),
|
|
767
|
+
incomplete_details: z2.object({
|
|
768
|
+
reason: z2.string()
|
|
763
769
|
}).nullable().optional(),
|
|
764
|
-
usage:
|
|
765
|
-
input_tokens:
|
|
766
|
-
input_tokens_details:
|
|
767
|
-
cached_tokens:
|
|
770
|
+
usage: z2.object({
|
|
771
|
+
input_tokens: z2.number(),
|
|
772
|
+
input_tokens_details: z2.object({
|
|
773
|
+
cached_tokens: z2.number()
|
|
768
774
|
}).optional(),
|
|
769
|
-
output_tokens:
|
|
770
|
-
output_tokens_details:
|
|
771
|
-
reasoning_tokens:
|
|
775
|
+
output_tokens: z2.number(),
|
|
776
|
+
output_tokens_details: z2.object({
|
|
777
|
+
reasoning_tokens: z2.number()
|
|
772
778
|
}).optional(),
|
|
773
|
-
total_tokens:
|
|
779
|
+
total_tokens: z2.number()
|
|
774
780
|
}).nullable().optional(),
|
|
775
|
-
output:
|
|
776
|
-
output_text:
|
|
781
|
+
output: z2.array(huggingfaceResponsesOutputSchema),
|
|
782
|
+
output_text: z2.string().nullable().optional()
|
|
777
783
|
});
|
|
778
|
-
var responseOutputItemAddedSchema =
|
|
779
|
-
type:
|
|
780
|
-
output_index:
|
|
781
|
-
item:
|
|
782
|
-
|
|
783
|
-
type:
|
|
784
|
-
id:
|
|
785
|
-
role:
|
|
786
|
-
status:
|
|
787
|
-
content:
|
|
784
|
+
var responseOutputItemAddedSchema = z2.object({
|
|
785
|
+
type: z2.literal("response.output_item.added"),
|
|
786
|
+
output_index: z2.number(),
|
|
787
|
+
item: z2.discriminatedUnion("type", [
|
|
788
|
+
z2.object({
|
|
789
|
+
type: z2.literal("message"),
|
|
790
|
+
id: z2.string(),
|
|
791
|
+
role: z2.string().optional(),
|
|
792
|
+
status: z2.string().optional(),
|
|
793
|
+
content: z2.array(z2.any()).optional()
|
|
788
794
|
}),
|
|
789
|
-
|
|
790
|
-
type:
|
|
791
|
-
id:
|
|
792
|
-
status:
|
|
793
|
-
content:
|
|
794
|
-
summary:
|
|
795
|
+
z2.object({
|
|
796
|
+
type: z2.literal("reasoning"),
|
|
797
|
+
id: z2.string(),
|
|
798
|
+
status: z2.string().optional(),
|
|
799
|
+
content: z2.array(z2.any()).optional(),
|
|
800
|
+
summary: z2.array(z2.any()).optional()
|
|
795
801
|
}),
|
|
796
|
-
|
|
797
|
-
type:
|
|
798
|
-
id:
|
|
799
|
-
server_label:
|
|
800
|
-
tools:
|
|
801
|
-
error:
|
|
802
|
+
z2.object({
|
|
803
|
+
type: z2.literal("mcp_list_tools"),
|
|
804
|
+
id: z2.string(),
|
|
805
|
+
server_label: z2.string(),
|
|
806
|
+
tools: z2.array(z2.any()).optional(),
|
|
807
|
+
error: z2.string().optional()
|
|
802
808
|
}),
|
|
803
|
-
|
|
804
|
-
type:
|
|
805
|
-
id:
|
|
806
|
-
server_label:
|
|
807
|
-
name:
|
|
808
|
-
arguments:
|
|
809
|
-
output:
|
|
810
|
-
error:
|
|
809
|
+
z2.object({
|
|
810
|
+
type: z2.literal("mcp_call"),
|
|
811
|
+
id: z2.string(),
|
|
812
|
+
server_label: z2.string(),
|
|
813
|
+
name: z2.string(),
|
|
814
|
+
arguments: z2.string(),
|
|
815
|
+
output: z2.string().optional(),
|
|
816
|
+
error: z2.string().optional()
|
|
811
817
|
}),
|
|
812
|
-
|
|
813
|
-
type:
|
|
814
|
-
id:
|
|
815
|
-
call_id:
|
|
816
|
-
name:
|
|
817
|
-
arguments:
|
|
818
|
-
output:
|
|
819
|
-
error:
|
|
818
|
+
z2.object({
|
|
819
|
+
type: z2.literal("function_call"),
|
|
820
|
+
id: z2.string(),
|
|
821
|
+
call_id: z2.string(),
|
|
822
|
+
name: z2.string(),
|
|
823
|
+
arguments: z2.string(),
|
|
824
|
+
output: z2.string().optional(),
|
|
825
|
+
error: z2.string().optional()
|
|
820
826
|
})
|
|
821
827
|
]),
|
|
822
|
-
sequence_number:
|
|
828
|
+
sequence_number: z2.number()
|
|
823
829
|
});
|
|
824
|
-
var responseOutputItemDoneSchema =
|
|
825
|
-
type:
|
|
826
|
-
output_index:
|
|
827
|
-
item:
|
|
828
|
-
|
|
829
|
-
type:
|
|
830
|
-
id:
|
|
831
|
-
role:
|
|
832
|
-
status:
|
|
833
|
-
content:
|
|
830
|
+
var responseOutputItemDoneSchema = z2.object({
|
|
831
|
+
type: z2.literal("response.output_item.done"),
|
|
832
|
+
output_index: z2.number(),
|
|
833
|
+
item: z2.discriminatedUnion("type", [
|
|
834
|
+
z2.object({
|
|
835
|
+
type: z2.literal("message"),
|
|
836
|
+
id: z2.string(),
|
|
837
|
+
role: z2.string().optional(),
|
|
838
|
+
status: z2.string().optional(),
|
|
839
|
+
content: z2.array(z2.any()).optional()
|
|
834
840
|
}),
|
|
835
|
-
|
|
836
|
-
type:
|
|
837
|
-
id:
|
|
838
|
-
server_label:
|
|
839
|
-
tools:
|
|
840
|
-
error:
|
|
841
|
+
z2.object({
|
|
842
|
+
type: z2.literal("mcp_list_tools"),
|
|
843
|
+
id: z2.string(),
|
|
844
|
+
server_label: z2.string(),
|
|
845
|
+
tools: z2.array(z2.any()).optional(),
|
|
846
|
+
error: z2.string().optional()
|
|
841
847
|
}),
|
|
842
|
-
|
|
843
|
-
type:
|
|
844
|
-
id:
|
|
845
|
-
server_label:
|
|
846
|
-
name:
|
|
847
|
-
arguments:
|
|
848
|
-
output:
|
|
849
|
-
error:
|
|
848
|
+
z2.object({
|
|
849
|
+
type: z2.literal("mcp_call"),
|
|
850
|
+
id: z2.string(),
|
|
851
|
+
server_label: z2.string(),
|
|
852
|
+
name: z2.string(),
|
|
853
|
+
arguments: z2.string(),
|
|
854
|
+
output: z2.string().optional(),
|
|
855
|
+
error: z2.string().optional()
|
|
850
856
|
}),
|
|
851
|
-
|
|
852
|
-
type:
|
|
853
|
-
id:
|
|
854
|
-
call_id:
|
|
855
|
-
name:
|
|
856
|
-
arguments:
|
|
857
|
-
output:
|
|
858
|
-
error:
|
|
857
|
+
z2.object({
|
|
858
|
+
type: z2.literal("function_call"),
|
|
859
|
+
id: z2.string(),
|
|
860
|
+
call_id: z2.string(),
|
|
861
|
+
name: z2.string(),
|
|
862
|
+
arguments: z2.string(),
|
|
863
|
+
output: z2.string().optional(),
|
|
864
|
+
error: z2.string().optional()
|
|
859
865
|
}),
|
|
860
|
-
|
|
861
|
-
type:
|
|
862
|
-
id:
|
|
863
|
-
status:
|
|
864
|
-
content:
|
|
865
|
-
summary:
|
|
866
|
+
z2.object({
|
|
867
|
+
type: z2.literal("reasoning"),
|
|
868
|
+
id: z2.string(),
|
|
869
|
+
status: z2.string().optional(),
|
|
870
|
+
content: z2.array(z2.any()).optional(),
|
|
871
|
+
summary: z2.array(z2.any()).optional()
|
|
866
872
|
})
|
|
867
873
|
]),
|
|
868
|
-
sequence_number:
|
|
874
|
+
sequence_number: z2.number()
|
|
869
875
|
});
|
|
870
|
-
var textDeltaChunkSchema =
|
|
871
|
-
type:
|
|
872
|
-
item_id:
|
|
873
|
-
output_index:
|
|
874
|
-
content_index:
|
|
875
|
-
delta:
|
|
876
|
-
sequence_number:
|
|
876
|
+
var textDeltaChunkSchema = z2.object({
|
|
877
|
+
type: z2.literal("response.output_text.delta"),
|
|
878
|
+
item_id: z2.string(),
|
|
879
|
+
output_index: z2.number(),
|
|
880
|
+
content_index: z2.number(),
|
|
881
|
+
delta: z2.string(),
|
|
882
|
+
sequence_number: z2.number()
|
|
877
883
|
});
|
|
878
|
-
var reasoningTextDeltaChunkSchema =
|
|
879
|
-
type:
|
|
880
|
-
item_id:
|
|
881
|
-
output_index:
|
|
882
|
-
content_index:
|
|
883
|
-
delta:
|
|
884
|
-
sequence_number:
|
|
884
|
+
var reasoningTextDeltaChunkSchema = z2.object({
|
|
885
|
+
type: z2.literal("response.reasoning_text.delta"),
|
|
886
|
+
item_id: z2.string(),
|
|
887
|
+
output_index: z2.number(),
|
|
888
|
+
content_index: z2.number(),
|
|
889
|
+
delta: z2.string(),
|
|
890
|
+
sequence_number: z2.number()
|
|
885
891
|
});
|
|
886
|
-
var reasoningTextEndChunkSchema =
|
|
887
|
-
type:
|
|
888
|
-
item_id:
|
|
889
|
-
output_index:
|
|
890
|
-
content_index:
|
|
891
|
-
text:
|
|
892
|
-
sequence_number:
|
|
892
|
+
var reasoningTextEndChunkSchema = z2.object({
|
|
893
|
+
type: z2.literal("response.reasoning_text.done"),
|
|
894
|
+
item_id: z2.string(),
|
|
895
|
+
output_index: z2.number(),
|
|
896
|
+
content_index: z2.number(),
|
|
897
|
+
text: z2.string(),
|
|
898
|
+
sequence_number: z2.number()
|
|
893
899
|
});
|
|
894
|
-
var responseCompletedChunkSchema =
|
|
895
|
-
type:
|
|
900
|
+
var responseCompletedChunkSchema = z2.object({
|
|
901
|
+
type: z2.literal("response.completed"),
|
|
896
902
|
response: huggingfaceResponsesResponseSchema,
|
|
897
|
-
sequence_number:
|
|
903
|
+
sequence_number: z2.number()
|
|
898
904
|
});
|
|
899
|
-
var responseCreatedChunkSchema =
|
|
900
|
-
type:
|
|
901
|
-
response:
|
|
902
|
-
id:
|
|
903
|
-
object:
|
|
904
|
-
created_at:
|
|
905
|
-
status:
|
|
906
|
-
model:
|
|
905
|
+
var responseCreatedChunkSchema = z2.object({
|
|
906
|
+
type: z2.literal("response.created"),
|
|
907
|
+
response: z2.object({
|
|
908
|
+
id: z2.string(),
|
|
909
|
+
object: z2.string(),
|
|
910
|
+
created_at: z2.number(),
|
|
911
|
+
status: z2.string(),
|
|
912
|
+
model: z2.string()
|
|
907
913
|
})
|
|
908
914
|
});
|
|
909
|
-
var huggingfaceResponsesChunkSchema =
|
|
915
|
+
var huggingfaceResponsesChunkSchema = z2.union([
|
|
910
916
|
responseOutputItemAddedSchema,
|
|
911
917
|
responseOutputItemDoneSchema,
|
|
912
918
|
reasoningTextDeltaChunkSchema,
|
|
@@ -914,7 +920,7 @@ var huggingfaceResponsesChunkSchema = import_v42.z.union([
|
|
|
914
920
|
textDeltaChunkSchema,
|
|
915
921
|
responseCompletedChunkSchema,
|
|
916
922
|
responseCreatedChunkSchema,
|
|
917
|
-
|
|
923
|
+
z2.object({ type: z2.string() }).loose()
|
|
918
924
|
// fallback for unknown chunks
|
|
919
925
|
]);
|
|
920
926
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
@@ -942,9 +948,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
942
948
|
// src/huggingface-provider.ts
|
|
943
949
|
function createHuggingFace(options = {}) {
|
|
944
950
|
var _a;
|
|
945
|
-
const baseURL = (_a =
|
|
951
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
|
|
946
952
|
const getHeaders = () => ({
|
|
947
|
-
Authorization: `Bearer ${
|
|
953
|
+
Authorization: `Bearer ${loadApiKey({
|
|
948
954
|
apiKey: options.apiKey,
|
|
949
955
|
environmentVariableName: "HUGGINGFACE_API_KEY",
|
|
950
956
|
description: "Hugging Face"
|
|
@@ -958,7 +964,7 @@ function createHuggingFace(options = {}) {
|
|
|
958
964
|
url: ({ path }) => `${baseURL}${path}`,
|
|
959
965
|
headers: getHeaders,
|
|
960
966
|
fetch: options.fetch,
|
|
961
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
967
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
962
968
|
});
|
|
963
969
|
};
|
|
964
970
|
const provider = (modelId) => createResponsesModel(modelId);
|
|
@@ -966,7 +972,7 @@ function createHuggingFace(options = {}) {
|
|
|
966
972
|
provider.languageModel = createResponsesModel;
|
|
967
973
|
provider.responses = createResponsesModel;
|
|
968
974
|
provider.embeddingModel = (modelId) => {
|
|
969
|
-
throw new
|
|
975
|
+
throw new NoSuchModelError({
|
|
970
976
|
modelId,
|
|
971
977
|
modelType: "embeddingModel",
|
|
972
978
|
message: "Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings."
|
|
@@ -974,7 +980,7 @@ function createHuggingFace(options = {}) {
|
|
|
974
980
|
};
|
|
975
981
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
976
982
|
provider.imageModel = (modelId) => {
|
|
977
|
-
throw new
|
|
983
|
+
throw new NoSuchModelError({
|
|
978
984
|
modelId,
|
|
979
985
|
modelType: "imageModel",
|
|
980
986
|
message: "Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models."
|
|
@@ -983,9 +989,8 @@ function createHuggingFace(options = {}) {
|
|
|
983
989
|
return provider;
|
|
984
990
|
}
|
|
985
991
|
var huggingface = createHuggingFace();
|
|
986
|
-
|
|
987
|
-
0 && (module.exports = {
|
|
992
|
+
export {
|
|
988
993
|
createHuggingFace,
|
|
989
994
|
huggingface
|
|
990
|
-
}
|
|
995
|
+
};
|
|
991
996
|
//# sourceMappingURL=index.js.map
|