@ai-sdk/huggingface 2.0.0-beta.3 → 2.0.0-beta.30
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 +247 -4
- package/README.md +2 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +265 -254
- package/dist/index.js.map +1 -1
- package/package.json +8 -10
- package/src/huggingface-config.ts +1 -1
- package/src/huggingface-provider.ts +7 -7
- package/src/responses/convert-huggingface-responses-usage.ts +2 -2
- package/src/responses/convert-to-huggingface-responses-messages.ts +12 -5
- package/src/responses/huggingface-responses-language-model.ts +41 -21
- package/src/responses/huggingface-responses-prepare-tools.ts +5 -5
- package/src/responses/map-huggingface-responses-finish-reason.ts +2 -2
- package/dist/index.d.mts +0 -59
- package/dist/index.mjs +0 -974
- 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,7 +80,10 @@ function convertHuggingFaceResponsesUsage(usage) {
|
|
|
89
80
|
}
|
|
90
81
|
|
|
91
82
|
// src/responses/convert-to-huggingface-responses-messages.ts
|
|
92
|
-
|
|
83
|
+
import {
|
|
84
|
+
UnsupportedFunctionalityError
|
|
85
|
+
} from "@ai-sdk/provider";
|
|
86
|
+
import { isProviderReference } from "@ai-sdk/provider-utils";
|
|
93
87
|
async function convertToHuggingFaceResponsesMessages({
|
|
94
88
|
prompt
|
|
95
89
|
}) {
|
|
@@ -110,6 +104,11 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
110
104
|
return { type: "input_text", text: part.text };
|
|
111
105
|
}
|
|
112
106
|
case "file": {
|
|
107
|
+
if (isProviderReference(part.data)) {
|
|
108
|
+
throw new UnsupportedFunctionalityError({
|
|
109
|
+
functionality: "file parts with provider references"
|
|
110
|
+
});
|
|
111
|
+
}
|
|
113
112
|
if (part.mediaType.startsWith("image/")) {
|
|
114
113
|
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
115
114
|
return {
|
|
@@ -117,7 +116,7 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
117
116
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`
|
|
118
117
|
};
|
|
119
118
|
} else {
|
|
120
|
-
throw new
|
|
119
|
+
throw new UnsupportedFunctionalityError({
|
|
121
120
|
functionality: `file part media type ${part.mediaType}`
|
|
122
121
|
});
|
|
123
122
|
}
|
|
@@ -253,15 +252,27 @@ function mapHuggingFaceResponsesFinishReason(finishReason) {
|
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
// src/responses/huggingface-responses-language-model.ts
|
|
256
|
-
var HuggingFaceResponsesLanguageModel = class {
|
|
255
|
+
var HuggingFaceResponsesLanguageModel = class _HuggingFaceResponsesLanguageModel {
|
|
257
256
|
constructor(modelId, config) {
|
|
258
|
-
this.specificationVersion = "
|
|
257
|
+
this.specificationVersion = "v4";
|
|
259
258
|
this.supportedUrls = {
|
|
260
259
|
"image/*": [/^https?:\/\/.*$/]
|
|
261
260
|
};
|
|
262
261
|
this.modelId = modelId;
|
|
263
262
|
this.config = config;
|
|
264
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
|
+
}
|
|
265
276
|
get provider() {
|
|
266
277
|
return this.config.provider;
|
|
267
278
|
}
|
|
@@ -301,7 +312,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
301
312
|
prompt
|
|
302
313
|
});
|
|
303
314
|
warnings.push(...messageWarnings);
|
|
304
|
-
const huggingfaceOptions = await
|
|
315
|
+
const huggingfaceOptions = await parseProviderOptions({
|
|
305
316
|
provider: "huggingface",
|
|
306
317
|
providerOptions,
|
|
307
318
|
schema: huggingfaceResponsesProviderOptionsSchema
|
|
@@ -348,7 +359,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
348
359
|
return { args: baseArgs, warnings };
|
|
349
360
|
}
|
|
350
361
|
async doGenerate(options) {
|
|
351
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
362
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
352
363
|
const { args, warnings } = await this.getArgs(options);
|
|
353
364
|
const body = {
|
|
354
365
|
...args,
|
|
@@ -362,19 +373,19 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
362
373
|
value: response,
|
|
363
374
|
responseHeaders,
|
|
364
375
|
rawValue: rawResponse
|
|
365
|
-
} = await
|
|
376
|
+
} = await postJsonToApi({
|
|
366
377
|
url,
|
|
367
|
-
headers: (
|
|
378
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
368
379
|
body,
|
|
369
380
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
370
|
-
successfulResponseHandler:
|
|
381
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
371
382
|
huggingfaceResponsesResponseSchema
|
|
372
383
|
),
|
|
373
384
|
abortSignal: options.abortSignal,
|
|
374
385
|
fetch: this.config.fetch
|
|
375
386
|
});
|
|
376
387
|
if (response.error) {
|
|
377
|
-
throw new
|
|
388
|
+
throw new APICallError({
|
|
378
389
|
message: response.error.message,
|
|
379
390
|
url,
|
|
380
391
|
requestBodyValues: body,
|
|
@@ -403,7 +414,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
403
414
|
content.push({
|
|
404
415
|
type: "source",
|
|
405
416
|
sourceType: "url",
|
|
406
|
-
id: (
|
|
417
|
+
id: (_e = (_d = (_c = this.config).generateId) == null ? void 0 : _d.call(_c)) != null ? _e : generateId(),
|
|
407
418
|
url: annotation.url,
|
|
408
419
|
title: annotation.title
|
|
409
420
|
});
|
|
@@ -488,9 +499,9 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
488
499
|
content,
|
|
489
500
|
finishReason: {
|
|
490
501
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
491
|
-
(
|
|
502
|
+
(_g = (_f = response.incomplete_details) == null ? void 0 : _f.reason) != null ? _g : "stop"
|
|
492
503
|
),
|
|
493
|
-
raw: (
|
|
504
|
+
raw: (_i = (_h = response.incomplete_details) == null ? void 0 : _h.reason) != null ? _i : void 0
|
|
494
505
|
},
|
|
495
506
|
usage: convertHuggingFaceResponsesUsage(response.usage),
|
|
496
507
|
request: { body },
|
|
@@ -510,20 +521,21 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
510
521
|
};
|
|
511
522
|
}
|
|
512
523
|
async doStream(options) {
|
|
524
|
+
var _a, _b;
|
|
513
525
|
const { args, warnings } = await this.getArgs(options);
|
|
514
526
|
const body = {
|
|
515
527
|
...args,
|
|
516
528
|
stream: true
|
|
517
529
|
};
|
|
518
|
-
const { value: response, responseHeaders } = await
|
|
530
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
519
531
|
url: this.config.url({
|
|
520
532
|
path: "/responses",
|
|
521
533
|
modelId: this.modelId
|
|
522
534
|
}),
|
|
523
|
-
headers: (
|
|
535
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
524
536
|
body,
|
|
525
537
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
526
|
-
successfulResponseHandler:
|
|
538
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
527
539
|
huggingfaceResponsesChunkSchema
|
|
528
540
|
),
|
|
529
541
|
abortSignal: options.abortSignal,
|
|
@@ -542,7 +554,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
542
554
|
controller.enqueue({ type: "stream-start", warnings });
|
|
543
555
|
},
|
|
544
556
|
transform(chunk, controller) {
|
|
545
|
-
var
|
|
557
|
+
var _a2, _b2, _c, _d;
|
|
546
558
|
if (!chunk.success) {
|
|
547
559
|
finishReason = {
|
|
548
560
|
unified: "error",
|
|
@@ -624,7 +636,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
624
636
|
responseId = value.response.id;
|
|
625
637
|
finishReason = {
|
|
626
638
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
627
|
-
(
|
|
639
|
+
(_b2 = (_a2 = value.response.incomplete_details) == null ? void 0 : _a2.reason) != null ? _b2 : "stop"
|
|
628
640
|
),
|
|
629
641
|
raw: (_d = (_c = value.response.incomplete_details) == null ? void 0 : _c.reason) != null ? _d : void 0
|
|
630
642
|
};
|
|
@@ -676,231 +688,231 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
676
688
|
};
|
|
677
689
|
}
|
|
678
690
|
};
|
|
679
|
-
var huggingfaceResponsesProviderOptionsSchema =
|
|
680
|
-
metadata:
|
|
681
|
-
instructions:
|
|
682
|
-
strictJsonSchema:
|
|
683
|
-
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()
|
|
684
696
|
});
|
|
685
|
-
var huggingfaceResponsesOutputSchema =
|
|
686
|
-
|
|
687
|
-
type:
|
|
688
|
-
id:
|
|
689
|
-
role:
|
|
690
|
-
status:
|
|
691
|
-
content:
|
|
692
|
-
|
|
693
|
-
type:
|
|
694
|
-
text:
|
|
695
|
-
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()
|
|
696
708
|
})
|
|
697
709
|
)
|
|
698
710
|
}),
|
|
699
|
-
|
|
700
|
-
type:
|
|
701
|
-
id:
|
|
702
|
-
status:
|
|
703
|
-
content:
|
|
704
|
-
|
|
705
|
-
type:
|
|
706
|
-
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()
|
|
707
719
|
})
|
|
708
720
|
),
|
|
709
|
-
summary:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
721
|
+
summary: z2.array(
|
|
722
|
+
z2.object({
|
|
723
|
+
type: z2.literal("reasoning_summary"),
|
|
724
|
+
text: z2.string()
|
|
713
725
|
}).optional()
|
|
714
726
|
).optional()
|
|
715
727
|
}),
|
|
716
|
-
|
|
717
|
-
type:
|
|
718
|
-
id:
|
|
719
|
-
call_id:
|
|
720
|
-
name:
|
|
721
|
-
arguments:
|
|
722
|
-
output:
|
|
723
|
-
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()
|
|
724
736
|
}),
|
|
725
|
-
|
|
726
|
-
type:
|
|
727
|
-
id:
|
|
728
|
-
name:
|
|
729
|
-
arguments:
|
|
730
|
-
output:
|
|
731
|
-
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()
|
|
732
744
|
}),
|
|
733
|
-
|
|
734
|
-
type:
|
|
735
|
-
id:
|
|
736
|
-
server_label:
|
|
737
|
-
tools:
|
|
738
|
-
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()
|
|
739
751
|
})
|
|
740
752
|
]);
|
|
741
|
-
var huggingfaceResponsesResponseSchema =
|
|
742
|
-
id:
|
|
743
|
-
model:
|
|
744
|
-
object:
|
|
745
|
-
created_at:
|
|
746
|
-
status:
|
|
747
|
-
error:
|
|
748
|
-
instructions:
|
|
749
|
-
max_output_tokens:
|
|
750
|
-
metadata:
|
|
751
|
-
tool_choice:
|
|
752
|
-
tools:
|
|
753
|
-
temperature:
|
|
754
|
-
top_p:
|
|
755
|
-
incomplete_details:
|
|
756
|
-
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()
|
|
757
769
|
}).nullable().optional(),
|
|
758
|
-
usage:
|
|
759
|
-
input_tokens:
|
|
760
|
-
input_tokens_details:
|
|
761
|
-
cached_tokens:
|
|
770
|
+
usage: z2.object({
|
|
771
|
+
input_tokens: z2.number(),
|
|
772
|
+
input_tokens_details: z2.object({
|
|
773
|
+
cached_tokens: z2.number()
|
|
762
774
|
}).optional(),
|
|
763
|
-
output_tokens:
|
|
764
|
-
output_tokens_details:
|
|
765
|
-
reasoning_tokens:
|
|
775
|
+
output_tokens: z2.number(),
|
|
776
|
+
output_tokens_details: z2.object({
|
|
777
|
+
reasoning_tokens: z2.number()
|
|
766
778
|
}).optional(),
|
|
767
|
-
total_tokens:
|
|
779
|
+
total_tokens: z2.number()
|
|
768
780
|
}).nullable().optional(),
|
|
769
|
-
output:
|
|
770
|
-
output_text:
|
|
781
|
+
output: z2.array(huggingfaceResponsesOutputSchema),
|
|
782
|
+
output_text: z2.string().nullable().optional()
|
|
771
783
|
});
|
|
772
|
-
var responseOutputItemAddedSchema =
|
|
773
|
-
type:
|
|
774
|
-
output_index:
|
|
775
|
-
item:
|
|
776
|
-
|
|
777
|
-
type:
|
|
778
|
-
id:
|
|
779
|
-
role:
|
|
780
|
-
status:
|
|
781
|
-
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()
|
|
782
794
|
}),
|
|
783
|
-
|
|
784
|
-
type:
|
|
785
|
-
id:
|
|
786
|
-
status:
|
|
787
|
-
content:
|
|
788
|
-
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()
|
|
789
801
|
}),
|
|
790
|
-
|
|
791
|
-
type:
|
|
792
|
-
id:
|
|
793
|
-
server_label:
|
|
794
|
-
tools:
|
|
795
|
-
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()
|
|
796
808
|
}),
|
|
797
|
-
|
|
798
|
-
type:
|
|
799
|
-
id:
|
|
800
|
-
server_label:
|
|
801
|
-
name:
|
|
802
|
-
arguments:
|
|
803
|
-
output:
|
|
804
|
-
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()
|
|
805
817
|
}),
|
|
806
|
-
|
|
807
|
-
type:
|
|
808
|
-
id:
|
|
809
|
-
call_id:
|
|
810
|
-
name:
|
|
811
|
-
arguments:
|
|
812
|
-
output:
|
|
813
|
-
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()
|
|
814
826
|
})
|
|
815
827
|
]),
|
|
816
|
-
sequence_number:
|
|
828
|
+
sequence_number: z2.number()
|
|
817
829
|
});
|
|
818
|
-
var responseOutputItemDoneSchema =
|
|
819
|
-
type:
|
|
820
|
-
output_index:
|
|
821
|
-
item:
|
|
822
|
-
|
|
823
|
-
type:
|
|
824
|
-
id:
|
|
825
|
-
role:
|
|
826
|
-
status:
|
|
827
|
-
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()
|
|
828
840
|
}),
|
|
829
|
-
|
|
830
|
-
type:
|
|
831
|
-
id:
|
|
832
|
-
server_label:
|
|
833
|
-
tools:
|
|
834
|
-
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()
|
|
835
847
|
}),
|
|
836
|
-
|
|
837
|
-
type:
|
|
838
|
-
id:
|
|
839
|
-
server_label:
|
|
840
|
-
name:
|
|
841
|
-
arguments:
|
|
842
|
-
output:
|
|
843
|
-
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()
|
|
844
856
|
}),
|
|
845
|
-
|
|
846
|
-
type:
|
|
847
|
-
id:
|
|
848
|
-
call_id:
|
|
849
|
-
name:
|
|
850
|
-
arguments:
|
|
851
|
-
output:
|
|
852
|
-
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()
|
|
853
865
|
}),
|
|
854
|
-
|
|
855
|
-
type:
|
|
856
|
-
id:
|
|
857
|
-
status:
|
|
858
|
-
content:
|
|
859
|
-
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()
|
|
860
872
|
})
|
|
861
873
|
]),
|
|
862
|
-
sequence_number:
|
|
874
|
+
sequence_number: z2.number()
|
|
863
875
|
});
|
|
864
|
-
var textDeltaChunkSchema =
|
|
865
|
-
type:
|
|
866
|
-
item_id:
|
|
867
|
-
output_index:
|
|
868
|
-
content_index:
|
|
869
|
-
delta:
|
|
870
|
-
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()
|
|
871
883
|
});
|
|
872
|
-
var reasoningTextDeltaChunkSchema =
|
|
873
|
-
type:
|
|
874
|
-
item_id:
|
|
875
|
-
output_index:
|
|
876
|
-
content_index:
|
|
877
|
-
delta:
|
|
878
|
-
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()
|
|
879
891
|
});
|
|
880
|
-
var reasoningTextEndChunkSchema =
|
|
881
|
-
type:
|
|
882
|
-
item_id:
|
|
883
|
-
output_index:
|
|
884
|
-
content_index:
|
|
885
|
-
text:
|
|
886
|
-
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()
|
|
887
899
|
});
|
|
888
|
-
var responseCompletedChunkSchema =
|
|
889
|
-
type:
|
|
900
|
+
var responseCompletedChunkSchema = z2.object({
|
|
901
|
+
type: z2.literal("response.completed"),
|
|
890
902
|
response: huggingfaceResponsesResponseSchema,
|
|
891
|
-
sequence_number:
|
|
903
|
+
sequence_number: z2.number()
|
|
892
904
|
});
|
|
893
|
-
var responseCreatedChunkSchema =
|
|
894
|
-
type:
|
|
895
|
-
response:
|
|
896
|
-
id:
|
|
897
|
-
object:
|
|
898
|
-
created_at:
|
|
899
|
-
status:
|
|
900
|
-
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()
|
|
901
913
|
})
|
|
902
914
|
});
|
|
903
|
-
var huggingfaceResponsesChunkSchema =
|
|
915
|
+
var huggingfaceResponsesChunkSchema = z2.union([
|
|
904
916
|
responseOutputItemAddedSchema,
|
|
905
917
|
responseOutputItemDoneSchema,
|
|
906
918
|
reasoningTextDeltaChunkSchema,
|
|
@@ -908,7 +920,7 @@ var huggingfaceResponsesChunkSchema = import_v42.z.union([
|
|
|
908
920
|
textDeltaChunkSchema,
|
|
909
921
|
responseCompletedChunkSchema,
|
|
910
922
|
responseCreatedChunkSchema,
|
|
911
|
-
|
|
923
|
+
z2.object({ type: z2.string() }).loose()
|
|
912
924
|
// fallback for unknown chunks
|
|
913
925
|
]);
|
|
914
926
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
@@ -936,9 +948,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
936
948
|
// src/huggingface-provider.ts
|
|
937
949
|
function createHuggingFace(options = {}) {
|
|
938
950
|
var _a;
|
|
939
|
-
const baseURL = (_a =
|
|
951
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
|
|
940
952
|
const getHeaders = () => ({
|
|
941
|
-
Authorization: `Bearer ${
|
|
953
|
+
Authorization: `Bearer ${loadApiKey({
|
|
942
954
|
apiKey: options.apiKey,
|
|
943
955
|
environmentVariableName: "HUGGINGFACE_API_KEY",
|
|
944
956
|
description: "Hugging Face"
|
|
@@ -952,15 +964,15 @@ function createHuggingFace(options = {}) {
|
|
|
952
964
|
url: ({ path }) => `${baseURL}${path}`,
|
|
953
965
|
headers: getHeaders,
|
|
954
966
|
fetch: options.fetch,
|
|
955
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
967
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
956
968
|
});
|
|
957
969
|
};
|
|
958
970
|
const provider = (modelId) => createResponsesModel(modelId);
|
|
959
|
-
provider.specificationVersion = "
|
|
971
|
+
provider.specificationVersion = "v4";
|
|
960
972
|
provider.languageModel = createResponsesModel;
|
|
961
973
|
provider.responses = createResponsesModel;
|
|
962
974
|
provider.embeddingModel = (modelId) => {
|
|
963
|
-
throw new
|
|
975
|
+
throw new NoSuchModelError({
|
|
964
976
|
modelId,
|
|
965
977
|
modelType: "embeddingModel",
|
|
966
978
|
message: "Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings."
|
|
@@ -968,7 +980,7 @@ function createHuggingFace(options = {}) {
|
|
|
968
980
|
};
|
|
969
981
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
970
982
|
provider.imageModel = (modelId) => {
|
|
971
|
-
throw new
|
|
983
|
+
throw new NoSuchModelError({
|
|
972
984
|
modelId,
|
|
973
985
|
modelType: "imageModel",
|
|
974
986
|
message: "Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models."
|
|
@@ -977,9 +989,8 @@ function createHuggingFace(options = {}) {
|
|
|
977
989
|
return provider;
|
|
978
990
|
}
|
|
979
991
|
var huggingface = createHuggingFace();
|
|
980
|
-
|
|
981
|
-
0 && (module.exports = {
|
|
992
|
+
export {
|
|
982
993
|
createHuggingFace,
|
|
983
994
|
huggingface
|
|
984
|
-
}
|
|
995
|
+
};
|
|
985
996
|
//# sourceMappingURL=index.js.map
|