@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/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
- var import_provider3 = require("@ai-sdk/provider");
30
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
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
- var import_provider2 = require("@ai-sdk/provider");
34
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
35
- var import_v42 = require("zod/v4");
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
- var import_provider_utils = require("@ai-sdk/provider-utils");
39
- var import_v4 = require("zod/v4");
40
- var huggingfaceErrorDataSchema = import_v4.z.object({
41
- error: import_v4.z.object({
42
- message: import_v4.z.string(),
43
- type: import_v4.z.string().optional(),
44
- code: import_v4.z.string().optional()
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 = (0, import_provider_utils.createJsonErrorResponseHandler)({
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
- var import_provider = require("@ai-sdk/provider");
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 import_provider.UnsupportedFunctionalityError({
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 = "v3";
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 (0, import_provider_utils2.parseProviderOptions)({
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 (0, import_provider_utils2.postJsonToApi)({
376
+ } = await postJsonToApi({
366
377
  url,
367
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.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: (0, import_provider_utils2.createJsonResponseHandler)(
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 import_provider2.APICallError({
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: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : (0, import_provider_utils2.generateId)(),
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
- (_e = (_d = response.incomplete_details) == null ? void 0 : _d.reason) != null ? _e : "stop"
502
+ (_g = (_f = response.incomplete_details) == null ? void 0 : _f.reason) != null ? _g : "stop"
492
503
  ),
493
- raw: (_g = (_f = response.incomplete_details) == null ? void 0 : _f.reason) != null ? _g : void 0
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 (0, import_provider_utils2.postJsonToApi)({
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: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.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: (0, import_provider_utils2.createEventSourceResponseHandler)(
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 _a, _b, _c, _d;
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
- (_b = (_a = value.response.incomplete_details) == null ? void 0 : _a.reason) != null ? _b : "stop"
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 = import_v42.z.object({
680
- metadata: import_v42.z.record(import_v42.z.string(), import_v42.z.string()).optional(),
681
- instructions: import_v42.z.string().optional(),
682
- strictJsonSchema: import_v42.z.boolean().optional(),
683
- reasoningEffort: import_v42.z.string().optional()
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 = import_v42.z.discriminatedUnion("type", [
686
- import_v42.z.object({
687
- type: import_v42.z.literal("message"),
688
- id: import_v42.z.string(),
689
- role: import_v42.z.string().optional(),
690
- status: import_v42.z.string().optional(),
691
- content: import_v42.z.array(
692
- import_v42.z.object({
693
- type: import_v42.z.literal("output_text"),
694
- text: import_v42.z.string(),
695
- annotations: import_v42.z.array(import_v42.z.any()).optional()
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
- import_v42.z.object({
700
- type: import_v42.z.literal("reasoning"),
701
- id: import_v42.z.string(),
702
- status: import_v42.z.string().optional(),
703
- content: import_v42.z.array(
704
- import_v42.z.object({
705
- type: import_v42.z.literal("reasoning_text"),
706
- text: import_v42.z.string()
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: import_v42.z.array(
710
- import_v42.z.object({
711
- type: import_v42.z.literal("reasoning_summary"),
712
- text: import_v42.z.string()
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
- import_v42.z.object({
717
- type: import_v42.z.literal("function_call"),
718
- id: import_v42.z.string(),
719
- call_id: import_v42.z.string(),
720
- name: import_v42.z.string(),
721
- arguments: import_v42.z.string(),
722
- output: import_v42.z.string().optional(),
723
- status: import_v42.z.string().optional()
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
- import_v42.z.object({
726
- type: import_v42.z.literal("mcp_call"),
727
- id: import_v42.z.string(),
728
- name: import_v42.z.string(),
729
- arguments: import_v42.z.string(),
730
- output: import_v42.z.string().optional(),
731
- status: import_v42.z.string().optional()
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
- import_v42.z.object({
734
- type: import_v42.z.literal("mcp_list_tools"),
735
- id: import_v42.z.string(),
736
- server_label: import_v42.z.string(),
737
- tools: import_v42.z.array(import_v42.z.any()).optional(),
738
- status: import_v42.z.string().optional()
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 = import_v42.z.object({
742
- id: import_v42.z.string(),
743
- model: import_v42.z.string(),
744
- object: import_v42.z.string(),
745
- created_at: import_v42.z.number(),
746
- status: import_v42.z.string(),
747
- error: import_v42.z.any().nullable(),
748
- instructions: import_v42.z.any().nullable(),
749
- max_output_tokens: import_v42.z.any().nullable(),
750
- metadata: import_v42.z.any().nullable(),
751
- tool_choice: import_v42.z.any(),
752
- tools: import_v42.z.array(import_v42.z.any()),
753
- temperature: import_v42.z.number(),
754
- top_p: import_v42.z.number(),
755
- incomplete_details: import_v42.z.object({
756
- reason: import_v42.z.string()
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: import_v42.z.object({
759
- input_tokens: import_v42.z.number(),
760
- input_tokens_details: import_v42.z.object({
761
- cached_tokens: import_v42.z.number()
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: import_v42.z.number(),
764
- output_tokens_details: import_v42.z.object({
765
- reasoning_tokens: import_v42.z.number()
775
+ output_tokens: z2.number(),
776
+ output_tokens_details: z2.object({
777
+ reasoning_tokens: z2.number()
766
778
  }).optional(),
767
- total_tokens: import_v42.z.number()
779
+ total_tokens: z2.number()
768
780
  }).nullable().optional(),
769
- output: import_v42.z.array(huggingfaceResponsesOutputSchema),
770
- output_text: import_v42.z.string().nullable().optional()
781
+ output: z2.array(huggingfaceResponsesOutputSchema),
782
+ output_text: z2.string().nullable().optional()
771
783
  });
772
- var responseOutputItemAddedSchema = import_v42.z.object({
773
- type: import_v42.z.literal("response.output_item.added"),
774
- output_index: import_v42.z.number(),
775
- item: import_v42.z.discriminatedUnion("type", [
776
- import_v42.z.object({
777
- type: import_v42.z.literal("message"),
778
- id: import_v42.z.string(),
779
- role: import_v42.z.string().optional(),
780
- status: import_v42.z.string().optional(),
781
- content: import_v42.z.array(import_v42.z.any()).optional()
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
- import_v42.z.object({
784
- type: import_v42.z.literal("reasoning"),
785
- id: import_v42.z.string(),
786
- status: import_v42.z.string().optional(),
787
- content: import_v42.z.array(import_v42.z.any()).optional(),
788
- summary: import_v42.z.array(import_v42.z.any()).optional()
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
- import_v42.z.object({
791
- type: import_v42.z.literal("mcp_list_tools"),
792
- id: import_v42.z.string(),
793
- server_label: import_v42.z.string(),
794
- tools: import_v42.z.array(import_v42.z.any()).optional(),
795
- error: import_v42.z.string().optional()
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
- import_v42.z.object({
798
- type: import_v42.z.literal("mcp_call"),
799
- id: import_v42.z.string(),
800
- server_label: import_v42.z.string(),
801
- name: import_v42.z.string(),
802
- arguments: import_v42.z.string(),
803
- output: import_v42.z.string().optional(),
804
- error: import_v42.z.string().optional()
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
- import_v42.z.object({
807
- type: import_v42.z.literal("function_call"),
808
- id: import_v42.z.string(),
809
- call_id: import_v42.z.string(),
810
- name: import_v42.z.string(),
811
- arguments: import_v42.z.string(),
812
- output: import_v42.z.string().optional(),
813
- error: import_v42.z.string().optional()
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: import_v42.z.number()
828
+ sequence_number: z2.number()
817
829
  });
818
- var responseOutputItemDoneSchema = import_v42.z.object({
819
- type: import_v42.z.literal("response.output_item.done"),
820
- output_index: import_v42.z.number(),
821
- item: import_v42.z.discriminatedUnion("type", [
822
- import_v42.z.object({
823
- type: import_v42.z.literal("message"),
824
- id: import_v42.z.string(),
825
- role: import_v42.z.string().optional(),
826
- status: import_v42.z.string().optional(),
827
- content: import_v42.z.array(import_v42.z.any()).optional()
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
- import_v42.z.object({
830
- type: import_v42.z.literal("mcp_list_tools"),
831
- id: import_v42.z.string(),
832
- server_label: import_v42.z.string(),
833
- tools: import_v42.z.array(import_v42.z.any()).optional(),
834
- error: import_v42.z.string().optional()
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
- import_v42.z.object({
837
- type: import_v42.z.literal("mcp_call"),
838
- id: import_v42.z.string(),
839
- server_label: import_v42.z.string(),
840
- name: import_v42.z.string(),
841
- arguments: import_v42.z.string(),
842
- output: import_v42.z.string().optional(),
843
- error: import_v42.z.string().optional()
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
- import_v42.z.object({
846
- type: import_v42.z.literal("function_call"),
847
- id: import_v42.z.string(),
848
- call_id: import_v42.z.string(),
849
- name: import_v42.z.string(),
850
- arguments: import_v42.z.string(),
851
- output: import_v42.z.string().optional(),
852
- error: import_v42.z.string().optional()
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
- import_v42.z.object({
855
- type: import_v42.z.literal("reasoning"),
856
- id: import_v42.z.string(),
857
- status: import_v42.z.string().optional(),
858
- content: import_v42.z.array(import_v42.z.any()).optional(),
859
- summary: import_v42.z.array(import_v42.z.any()).optional()
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: import_v42.z.number()
874
+ sequence_number: z2.number()
863
875
  });
864
- var textDeltaChunkSchema = import_v42.z.object({
865
- type: import_v42.z.literal("response.output_text.delta"),
866
- item_id: import_v42.z.string(),
867
- output_index: import_v42.z.number(),
868
- content_index: import_v42.z.number(),
869
- delta: import_v42.z.string(),
870
- sequence_number: import_v42.z.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 = import_v42.z.object({
873
- type: import_v42.z.literal("response.reasoning_text.delta"),
874
- item_id: import_v42.z.string(),
875
- output_index: import_v42.z.number(),
876
- content_index: import_v42.z.number(),
877
- delta: import_v42.z.string(),
878
- sequence_number: import_v42.z.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 = import_v42.z.object({
881
- type: import_v42.z.literal("response.reasoning_text.done"),
882
- item_id: import_v42.z.string(),
883
- output_index: import_v42.z.number(),
884
- content_index: import_v42.z.number(),
885
- text: import_v42.z.string(),
886
- sequence_number: import_v42.z.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 = import_v42.z.object({
889
- type: import_v42.z.literal("response.completed"),
900
+ var responseCompletedChunkSchema = z2.object({
901
+ type: z2.literal("response.completed"),
890
902
  response: huggingfaceResponsesResponseSchema,
891
- sequence_number: import_v42.z.number()
903
+ sequence_number: z2.number()
892
904
  });
893
- var responseCreatedChunkSchema = import_v42.z.object({
894
- type: import_v42.z.literal("response.created"),
895
- response: import_v42.z.object({
896
- id: import_v42.z.string(),
897
- object: import_v42.z.string(),
898
- created_at: import_v42.z.number(),
899
- status: import_v42.z.string(),
900
- model: import_v42.z.string()
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 = import_v42.z.union([
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
- import_v42.z.object({ type: import_v42.z.string() }).loose()
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 = (0, import_provider_utils3.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
951
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
940
952
  const getHeaders = () => ({
941
- Authorization: `Bearer ${(0, import_provider_utils3.loadApiKey)({
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 : import_provider_utils3.generateId
967
+ generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
956
968
  });
957
969
  };
958
970
  const provider = (modelId) => createResponsesModel(modelId);
959
- provider.specificationVersion = "v3";
971
+ provider.specificationVersion = "v4";
960
972
  provider.languageModel = createResponsesModel;
961
973
  provider.responses = createResponsesModel;
962
974
  provider.embeddingModel = (modelId) => {
963
- throw new import_provider3.NoSuchModelError({
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 import_provider3.NoSuchModelError({
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
- // Annotate the CommonJS export names for ESM import in node:
981
- 0 && (module.exports = {
992
+ export {
982
993
  createHuggingFace,
983
994
  huggingface
984
- });
995
+ };
985
996
  //# sourceMappingURL=index.js.map