@ai-sdk/huggingface 2.0.0-beta.9 → 2.0.0-canary.38
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 +278 -0
- package/README.md +2 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +296 -265
- package/dist/index.js.map +1 -1
- package/docs/170-huggingface.mdx +21 -19
- package/package.json +12 -10
- package/src/huggingface-config.ts +2 -2
- package/src/huggingface-provider.ts +5 -5
- package/src/index.ts +7 -1
- package/src/responses/convert-huggingface-responses-usage.ts +1 -1
- package/src/responses/convert-to-huggingface-responses-messages.ts +33 -19
- package/src/responses/huggingface-responses-language-model-options.ts +12 -0
- package/src/responses/huggingface-responses-language-model.ts +36 -22
- package/src/responses/huggingface-responses-prepare-tools.ts +4 -1
- package/src/responses/map-huggingface-responses-finish-reason.ts +1 -1
- package/src/version.ts +6 -0
- 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 z3 } 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,13 @@ 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 {
|
|
87
|
+
getTopLevelMediaType,
|
|
88
|
+
resolveFullMediaType
|
|
89
|
+
} from "@ai-sdk/provider-utils";
|
|
93
90
|
async function convertToHuggingFaceResponsesMessages({
|
|
94
91
|
prompt
|
|
95
92
|
}) {
|
|
@@ -110,16 +107,30 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
110
107
|
return { type: "input_text", text: part.text };
|
|
111
108
|
}
|
|
112
109
|
case "file": {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
110
|
+
switch (part.data.type) {
|
|
111
|
+
case "reference": {
|
|
112
|
+
throw new UnsupportedFunctionalityError({
|
|
113
|
+
functionality: "file parts with provider references"
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
case "text": {
|
|
117
|
+
throw new UnsupportedFunctionalityError({
|
|
118
|
+
functionality: "text file parts"
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
case "url":
|
|
122
|
+
case "data": {
|
|
123
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
124
|
+
return {
|
|
125
|
+
type: "input_image",
|
|
126
|
+
image_url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${part.data.data}`
|
|
127
|
+
};
|
|
128
|
+
} else {
|
|
129
|
+
throw new UnsupportedFunctionalityError({
|
|
130
|
+
functionality: `file part media type ${part.mediaType}`
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
136
|
default: {
|
|
@@ -171,6 +182,15 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
171
182
|
return { input: messages, warnings };
|
|
172
183
|
}
|
|
173
184
|
|
|
185
|
+
// src/responses/huggingface-responses-language-model-options.ts
|
|
186
|
+
import { z as z2 } from "zod/v4";
|
|
187
|
+
var huggingfaceLanguageModelResponsesOptions = z2.object({
|
|
188
|
+
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
189
|
+
instructions: z2.string().optional(),
|
|
190
|
+
strictJsonSchema: z2.boolean().optional(),
|
|
191
|
+
reasoningEffort: z2.string().optional()
|
|
192
|
+
});
|
|
193
|
+
|
|
174
194
|
// src/responses/huggingface-responses-prepare-tools.ts
|
|
175
195
|
function prepareResponsesTools({
|
|
176
196
|
tools,
|
|
@@ -253,7 +273,7 @@ function mapHuggingFaceResponsesFinishReason(finishReason) {
|
|
|
253
273
|
}
|
|
254
274
|
|
|
255
275
|
// src/responses/huggingface-responses-language-model.ts
|
|
256
|
-
var HuggingFaceResponsesLanguageModel = class {
|
|
276
|
+
var HuggingFaceResponsesLanguageModel = class _HuggingFaceResponsesLanguageModel {
|
|
257
277
|
constructor(modelId, config) {
|
|
258
278
|
this.specificationVersion = "v4";
|
|
259
279
|
this.supportedUrls = {
|
|
@@ -262,6 +282,18 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
262
282
|
this.modelId = modelId;
|
|
263
283
|
this.config = config;
|
|
264
284
|
}
|
|
285
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
286
|
+
return serializeModelOptions({
|
|
287
|
+
modelId: model.modelId,
|
|
288
|
+
config: model.config
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
292
|
+
return new _HuggingFaceResponsesLanguageModel(
|
|
293
|
+
options.modelId,
|
|
294
|
+
options.config
|
|
295
|
+
);
|
|
296
|
+
}
|
|
265
297
|
get provider() {
|
|
266
298
|
return this.config.provider;
|
|
267
299
|
}
|
|
@@ -301,10 +333,10 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
301
333
|
prompt
|
|
302
334
|
});
|
|
303
335
|
warnings.push(...messageWarnings);
|
|
304
|
-
const huggingfaceOptions = await
|
|
336
|
+
const huggingfaceOptions = await parseProviderOptions({
|
|
305
337
|
provider: "huggingface",
|
|
306
338
|
providerOptions,
|
|
307
|
-
schema:
|
|
339
|
+
schema: huggingfaceLanguageModelResponsesOptions
|
|
308
340
|
});
|
|
309
341
|
const {
|
|
310
342
|
tools: preparedTools,
|
|
@@ -348,7 +380,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
348
380
|
return { args: baseArgs, warnings };
|
|
349
381
|
}
|
|
350
382
|
async doGenerate(options) {
|
|
351
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
383
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
352
384
|
const { args, warnings } = await this.getArgs(options);
|
|
353
385
|
const body = {
|
|
354
386
|
...args,
|
|
@@ -362,19 +394,19 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
362
394
|
value: response,
|
|
363
395
|
responseHeaders,
|
|
364
396
|
rawValue: rawResponse
|
|
365
|
-
} = await
|
|
397
|
+
} = await postJsonToApi({
|
|
366
398
|
url,
|
|
367
|
-
headers: (
|
|
399
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
368
400
|
body,
|
|
369
401
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
370
|
-
successfulResponseHandler:
|
|
402
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
371
403
|
huggingfaceResponsesResponseSchema
|
|
372
404
|
),
|
|
373
405
|
abortSignal: options.abortSignal,
|
|
374
406
|
fetch: this.config.fetch
|
|
375
407
|
});
|
|
376
408
|
if (response.error) {
|
|
377
|
-
throw new
|
|
409
|
+
throw new APICallError({
|
|
378
410
|
message: response.error.message,
|
|
379
411
|
url,
|
|
380
412
|
requestBodyValues: body,
|
|
@@ -403,7 +435,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
403
435
|
content.push({
|
|
404
436
|
type: "source",
|
|
405
437
|
sourceType: "url",
|
|
406
|
-
id: (
|
|
438
|
+
id: (_e = (_d = (_c = this.config).generateId) == null ? void 0 : _d.call(_c)) != null ? _e : generateId(),
|
|
407
439
|
url: annotation.url,
|
|
408
440
|
title: annotation.title
|
|
409
441
|
});
|
|
@@ -488,9 +520,9 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
488
520
|
content,
|
|
489
521
|
finishReason: {
|
|
490
522
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
491
|
-
(
|
|
523
|
+
(_g = (_f = response.incomplete_details) == null ? void 0 : _f.reason) != null ? _g : "stop"
|
|
492
524
|
),
|
|
493
|
-
raw: (
|
|
525
|
+
raw: (_i = (_h = response.incomplete_details) == null ? void 0 : _h.reason) != null ? _i : void 0
|
|
494
526
|
},
|
|
495
527
|
usage: convertHuggingFaceResponsesUsage(response.usage),
|
|
496
528
|
request: { body },
|
|
@@ -510,20 +542,21 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
510
542
|
};
|
|
511
543
|
}
|
|
512
544
|
async doStream(options) {
|
|
545
|
+
var _a, _b;
|
|
513
546
|
const { args, warnings } = await this.getArgs(options);
|
|
514
547
|
const body = {
|
|
515
548
|
...args,
|
|
516
549
|
stream: true
|
|
517
550
|
};
|
|
518
|
-
const { value: response, responseHeaders } = await
|
|
551
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
519
552
|
url: this.config.url({
|
|
520
553
|
path: "/responses",
|
|
521
554
|
modelId: this.modelId
|
|
522
555
|
}),
|
|
523
|
-
headers: (
|
|
556
|
+
headers: combineHeaders((_b = (_a = this.config).headers) == null ? void 0 : _b.call(_a), options.headers),
|
|
524
557
|
body,
|
|
525
558
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
526
|
-
successfulResponseHandler:
|
|
559
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
527
560
|
huggingfaceResponsesChunkSchema
|
|
528
561
|
),
|
|
529
562
|
abortSignal: options.abortSignal,
|
|
@@ -542,7 +575,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
542
575
|
controller.enqueue({ type: "stream-start", warnings });
|
|
543
576
|
},
|
|
544
577
|
transform(chunk, controller) {
|
|
545
|
-
var
|
|
578
|
+
var _a2, _b2, _c, _d;
|
|
546
579
|
if (!chunk.success) {
|
|
547
580
|
finishReason = {
|
|
548
581
|
unified: "error",
|
|
@@ -624,7 +657,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
624
657
|
responseId = value.response.id;
|
|
625
658
|
finishReason = {
|
|
626
659
|
unified: mapHuggingFaceResponsesFinishReason(
|
|
627
|
-
(
|
|
660
|
+
(_b2 = (_a2 = value.response.incomplete_details) == null ? void 0 : _a2.reason) != null ? _b2 : "stop"
|
|
628
661
|
),
|
|
629
662
|
raw: (_d = (_c = value.response.incomplete_details) == null ? void 0 : _c.reason) != null ? _d : void 0
|
|
630
663
|
};
|
|
@@ -676,231 +709,225 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
676
709
|
};
|
|
677
710
|
}
|
|
678
711
|
};
|
|
679
|
-
var
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
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()
|
|
712
|
+
var huggingfaceResponsesOutputSchema = z3.discriminatedUnion("type", [
|
|
713
|
+
z3.object({
|
|
714
|
+
type: z3.literal("message"),
|
|
715
|
+
id: z3.string(),
|
|
716
|
+
role: z3.string().optional(),
|
|
717
|
+
status: z3.string().optional(),
|
|
718
|
+
content: z3.array(
|
|
719
|
+
z3.object({
|
|
720
|
+
type: z3.literal("output_text"),
|
|
721
|
+
text: z3.string(),
|
|
722
|
+
annotations: z3.array(z3.any()).optional()
|
|
696
723
|
})
|
|
697
724
|
)
|
|
698
725
|
}),
|
|
699
|
-
|
|
700
|
-
type:
|
|
701
|
-
id:
|
|
702
|
-
status:
|
|
703
|
-
content:
|
|
704
|
-
|
|
705
|
-
type:
|
|
706
|
-
text:
|
|
726
|
+
z3.object({
|
|
727
|
+
type: z3.literal("reasoning"),
|
|
728
|
+
id: z3.string(),
|
|
729
|
+
status: z3.string().optional(),
|
|
730
|
+
content: z3.array(
|
|
731
|
+
z3.object({
|
|
732
|
+
type: z3.literal("reasoning_text"),
|
|
733
|
+
text: z3.string()
|
|
707
734
|
})
|
|
708
735
|
),
|
|
709
|
-
summary:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
736
|
+
summary: z3.array(
|
|
737
|
+
z3.object({
|
|
738
|
+
type: z3.literal("reasoning_summary"),
|
|
739
|
+
text: z3.string()
|
|
713
740
|
}).optional()
|
|
714
741
|
).optional()
|
|
715
742
|
}),
|
|
716
|
-
|
|
717
|
-
type:
|
|
718
|
-
id:
|
|
719
|
-
call_id:
|
|
720
|
-
name:
|
|
721
|
-
arguments:
|
|
722
|
-
output:
|
|
723
|
-
status:
|
|
743
|
+
z3.object({
|
|
744
|
+
type: z3.literal("function_call"),
|
|
745
|
+
id: z3.string(),
|
|
746
|
+
call_id: z3.string(),
|
|
747
|
+
name: z3.string(),
|
|
748
|
+
arguments: z3.string(),
|
|
749
|
+
output: z3.string().optional(),
|
|
750
|
+
status: z3.string().optional()
|
|
724
751
|
}),
|
|
725
|
-
|
|
726
|
-
type:
|
|
727
|
-
id:
|
|
728
|
-
name:
|
|
729
|
-
arguments:
|
|
730
|
-
output:
|
|
731
|
-
status:
|
|
752
|
+
z3.object({
|
|
753
|
+
type: z3.literal("mcp_call"),
|
|
754
|
+
id: z3.string(),
|
|
755
|
+
name: z3.string(),
|
|
756
|
+
arguments: z3.string(),
|
|
757
|
+
output: z3.string().optional(),
|
|
758
|
+
status: z3.string().optional()
|
|
732
759
|
}),
|
|
733
|
-
|
|
734
|
-
type:
|
|
735
|
-
id:
|
|
736
|
-
server_label:
|
|
737
|
-
tools:
|
|
738
|
-
status:
|
|
760
|
+
z3.object({
|
|
761
|
+
type: z3.literal("mcp_list_tools"),
|
|
762
|
+
id: z3.string(),
|
|
763
|
+
server_label: z3.string(),
|
|
764
|
+
tools: z3.array(z3.any()).optional(),
|
|
765
|
+
status: z3.string().optional()
|
|
739
766
|
})
|
|
740
767
|
]);
|
|
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:
|
|
768
|
+
var huggingfaceResponsesResponseSchema = z3.object({
|
|
769
|
+
id: z3.string(),
|
|
770
|
+
model: z3.string(),
|
|
771
|
+
object: z3.string(),
|
|
772
|
+
created_at: z3.number(),
|
|
773
|
+
status: z3.string(),
|
|
774
|
+
error: z3.any().nullable(),
|
|
775
|
+
instructions: z3.any().nullable(),
|
|
776
|
+
max_output_tokens: z3.any().nullable(),
|
|
777
|
+
metadata: z3.any().nullable(),
|
|
778
|
+
tool_choice: z3.any(),
|
|
779
|
+
tools: z3.array(z3.any()),
|
|
780
|
+
temperature: z3.number(),
|
|
781
|
+
top_p: z3.number(),
|
|
782
|
+
incomplete_details: z3.object({
|
|
783
|
+
reason: z3.string()
|
|
757
784
|
}).nullable().optional(),
|
|
758
|
-
usage:
|
|
759
|
-
input_tokens:
|
|
760
|
-
input_tokens_details:
|
|
761
|
-
cached_tokens:
|
|
785
|
+
usage: z3.object({
|
|
786
|
+
input_tokens: z3.number(),
|
|
787
|
+
input_tokens_details: z3.object({
|
|
788
|
+
cached_tokens: z3.number()
|
|
762
789
|
}).optional(),
|
|
763
|
-
output_tokens:
|
|
764
|
-
output_tokens_details:
|
|
765
|
-
reasoning_tokens:
|
|
790
|
+
output_tokens: z3.number(),
|
|
791
|
+
output_tokens_details: z3.object({
|
|
792
|
+
reasoning_tokens: z3.number()
|
|
766
793
|
}).optional(),
|
|
767
|
-
total_tokens:
|
|
794
|
+
total_tokens: z3.number()
|
|
768
795
|
}).nullable().optional(),
|
|
769
|
-
output:
|
|
770
|
-
output_text:
|
|
796
|
+
output: z3.array(huggingfaceResponsesOutputSchema),
|
|
797
|
+
output_text: z3.string().nullable().optional()
|
|
771
798
|
});
|
|
772
|
-
var responseOutputItemAddedSchema =
|
|
773
|
-
type:
|
|
774
|
-
output_index:
|
|
775
|
-
item:
|
|
776
|
-
|
|
777
|
-
type:
|
|
778
|
-
id:
|
|
779
|
-
role:
|
|
780
|
-
status:
|
|
781
|
-
content:
|
|
799
|
+
var responseOutputItemAddedSchema = z3.object({
|
|
800
|
+
type: z3.literal("response.output_item.added"),
|
|
801
|
+
output_index: z3.number(),
|
|
802
|
+
item: z3.discriminatedUnion("type", [
|
|
803
|
+
z3.object({
|
|
804
|
+
type: z3.literal("message"),
|
|
805
|
+
id: z3.string(),
|
|
806
|
+
role: z3.string().optional(),
|
|
807
|
+
status: z3.string().optional(),
|
|
808
|
+
content: z3.array(z3.any()).optional()
|
|
782
809
|
}),
|
|
783
|
-
|
|
784
|
-
type:
|
|
785
|
-
id:
|
|
786
|
-
status:
|
|
787
|
-
content:
|
|
788
|
-
summary:
|
|
810
|
+
z3.object({
|
|
811
|
+
type: z3.literal("reasoning"),
|
|
812
|
+
id: z3.string(),
|
|
813
|
+
status: z3.string().optional(),
|
|
814
|
+
content: z3.array(z3.any()).optional(),
|
|
815
|
+
summary: z3.array(z3.any()).optional()
|
|
789
816
|
}),
|
|
790
|
-
|
|
791
|
-
type:
|
|
792
|
-
id:
|
|
793
|
-
server_label:
|
|
794
|
-
tools:
|
|
795
|
-
error:
|
|
817
|
+
z3.object({
|
|
818
|
+
type: z3.literal("mcp_list_tools"),
|
|
819
|
+
id: z3.string(),
|
|
820
|
+
server_label: z3.string(),
|
|
821
|
+
tools: z3.array(z3.any()).optional(),
|
|
822
|
+
error: z3.string().optional()
|
|
796
823
|
}),
|
|
797
|
-
|
|
798
|
-
type:
|
|
799
|
-
id:
|
|
800
|
-
server_label:
|
|
801
|
-
name:
|
|
802
|
-
arguments:
|
|
803
|
-
output:
|
|
804
|
-
error:
|
|
824
|
+
z3.object({
|
|
825
|
+
type: z3.literal("mcp_call"),
|
|
826
|
+
id: z3.string(),
|
|
827
|
+
server_label: z3.string(),
|
|
828
|
+
name: z3.string(),
|
|
829
|
+
arguments: z3.string(),
|
|
830
|
+
output: z3.string().optional(),
|
|
831
|
+
error: z3.string().optional()
|
|
805
832
|
}),
|
|
806
|
-
|
|
807
|
-
type:
|
|
808
|
-
id:
|
|
809
|
-
call_id:
|
|
810
|
-
name:
|
|
811
|
-
arguments:
|
|
812
|
-
output:
|
|
813
|
-
error:
|
|
833
|
+
z3.object({
|
|
834
|
+
type: z3.literal("function_call"),
|
|
835
|
+
id: z3.string(),
|
|
836
|
+
call_id: z3.string(),
|
|
837
|
+
name: z3.string(),
|
|
838
|
+
arguments: z3.string(),
|
|
839
|
+
output: z3.string().optional(),
|
|
840
|
+
error: z3.string().optional()
|
|
814
841
|
})
|
|
815
842
|
]),
|
|
816
|
-
sequence_number:
|
|
843
|
+
sequence_number: z3.number()
|
|
817
844
|
});
|
|
818
|
-
var responseOutputItemDoneSchema =
|
|
819
|
-
type:
|
|
820
|
-
output_index:
|
|
821
|
-
item:
|
|
822
|
-
|
|
823
|
-
type:
|
|
824
|
-
id:
|
|
825
|
-
role:
|
|
826
|
-
status:
|
|
827
|
-
content:
|
|
845
|
+
var responseOutputItemDoneSchema = z3.object({
|
|
846
|
+
type: z3.literal("response.output_item.done"),
|
|
847
|
+
output_index: z3.number(),
|
|
848
|
+
item: z3.discriminatedUnion("type", [
|
|
849
|
+
z3.object({
|
|
850
|
+
type: z3.literal("message"),
|
|
851
|
+
id: z3.string(),
|
|
852
|
+
role: z3.string().optional(),
|
|
853
|
+
status: z3.string().optional(),
|
|
854
|
+
content: z3.array(z3.any()).optional()
|
|
828
855
|
}),
|
|
829
|
-
|
|
830
|
-
type:
|
|
831
|
-
id:
|
|
832
|
-
server_label:
|
|
833
|
-
tools:
|
|
834
|
-
error:
|
|
856
|
+
z3.object({
|
|
857
|
+
type: z3.literal("mcp_list_tools"),
|
|
858
|
+
id: z3.string(),
|
|
859
|
+
server_label: z3.string(),
|
|
860
|
+
tools: z3.array(z3.any()).optional(),
|
|
861
|
+
error: z3.string().optional()
|
|
835
862
|
}),
|
|
836
|
-
|
|
837
|
-
type:
|
|
838
|
-
id:
|
|
839
|
-
server_label:
|
|
840
|
-
name:
|
|
841
|
-
arguments:
|
|
842
|
-
output:
|
|
843
|
-
error:
|
|
863
|
+
z3.object({
|
|
864
|
+
type: z3.literal("mcp_call"),
|
|
865
|
+
id: z3.string(),
|
|
866
|
+
server_label: z3.string(),
|
|
867
|
+
name: z3.string(),
|
|
868
|
+
arguments: z3.string(),
|
|
869
|
+
output: z3.string().optional(),
|
|
870
|
+
error: z3.string().optional()
|
|
844
871
|
}),
|
|
845
|
-
|
|
846
|
-
type:
|
|
847
|
-
id:
|
|
848
|
-
call_id:
|
|
849
|
-
name:
|
|
850
|
-
arguments:
|
|
851
|
-
output:
|
|
852
|
-
error:
|
|
872
|
+
z3.object({
|
|
873
|
+
type: z3.literal("function_call"),
|
|
874
|
+
id: z3.string(),
|
|
875
|
+
call_id: z3.string(),
|
|
876
|
+
name: z3.string(),
|
|
877
|
+
arguments: z3.string(),
|
|
878
|
+
output: z3.string().optional(),
|
|
879
|
+
error: z3.string().optional()
|
|
853
880
|
}),
|
|
854
|
-
|
|
855
|
-
type:
|
|
856
|
-
id:
|
|
857
|
-
status:
|
|
858
|
-
content:
|
|
859
|
-
summary:
|
|
881
|
+
z3.object({
|
|
882
|
+
type: z3.literal("reasoning"),
|
|
883
|
+
id: z3.string(),
|
|
884
|
+
status: z3.string().optional(),
|
|
885
|
+
content: z3.array(z3.any()).optional(),
|
|
886
|
+
summary: z3.array(z3.any()).optional()
|
|
860
887
|
})
|
|
861
888
|
]),
|
|
862
|
-
sequence_number:
|
|
889
|
+
sequence_number: z3.number()
|
|
863
890
|
});
|
|
864
|
-
var textDeltaChunkSchema =
|
|
865
|
-
type:
|
|
866
|
-
item_id:
|
|
867
|
-
output_index:
|
|
868
|
-
content_index:
|
|
869
|
-
delta:
|
|
870
|
-
sequence_number:
|
|
891
|
+
var textDeltaChunkSchema = z3.object({
|
|
892
|
+
type: z3.literal("response.output_text.delta"),
|
|
893
|
+
item_id: z3.string(),
|
|
894
|
+
output_index: z3.number(),
|
|
895
|
+
content_index: z3.number(),
|
|
896
|
+
delta: z3.string(),
|
|
897
|
+
sequence_number: z3.number()
|
|
871
898
|
});
|
|
872
|
-
var reasoningTextDeltaChunkSchema =
|
|
873
|
-
type:
|
|
874
|
-
item_id:
|
|
875
|
-
output_index:
|
|
876
|
-
content_index:
|
|
877
|
-
delta:
|
|
878
|
-
sequence_number:
|
|
899
|
+
var reasoningTextDeltaChunkSchema = z3.object({
|
|
900
|
+
type: z3.literal("response.reasoning_text.delta"),
|
|
901
|
+
item_id: z3.string(),
|
|
902
|
+
output_index: z3.number(),
|
|
903
|
+
content_index: z3.number(),
|
|
904
|
+
delta: z3.string(),
|
|
905
|
+
sequence_number: z3.number()
|
|
879
906
|
});
|
|
880
|
-
var reasoningTextEndChunkSchema =
|
|
881
|
-
type:
|
|
882
|
-
item_id:
|
|
883
|
-
output_index:
|
|
884
|
-
content_index:
|
|
885
|
-
text:
|
|
886
|
-
sequence_number:
|
|
907
|
+
var reasoningTextEndChunkSchema = z3.object({
|
|
908
|
+
type: z3.literal("response.reasoning_text.done"),
|
|
909
|
+
item_id: z3.string(),
|
|
910
|
+
output_index: z3.number(),
|
|
911
|
+
content_index: z3.number(),
|
|
912
|
+
text: z3.string(),
|
|
913
|
+
sequence_number: z3.number()
|
|
887
914
|
});
|
|
888
|
-
var responseCompletedChunkSchema =
|
|
889
|
-
type:
|
|
915
|
+
var responseCompletedChunkSchema = z3.object({
|
|
916
|
+
type: z3.literal("response.completed"),
|
|
890
917
|
response: huggingfaceResponsesResponseSchema,
|
|
891
|
-
sequence_number:
|
|
918
|
+
sequence_number: z3.number()
|
|
892
919
|
});
|
|
893
|
-
var responseCreatedChunkSchema =
|
|
894
|
-
type:
|
|
895
|
-
response:
|
|
896
|
-
id:
|
|
897
|
-
object:
|
|
898
|
-
created_at:
|
|
899
|
-
status:
|
|
900
|
-
model:
|
|
920
|
+
var responseCreatedChunkSchema = z3.object({
|
|
921
|
+
type: z3.literal("response.created"),
|
|
922
|
+
response: z3.object({
|
|
923
|
+
id: z3.string(),
|
|
924
|
+
object: z3.string(),
|
|
925
|
+
created_at: z3.number(),
|
|
926
|
+
status: z3.string(),
|
|
927
|
+
model: z3.string()
|
|
901
928
|
})
|
|
902
929
|
});
|
|
903
|
-
var huggingfaceResponsesChunkSchema =
|
|
930
|
+
var huggingfaceResponsesChunkSchema = z3.union([
|
|
904
931
|
responseOutputItemAddedSchema,
|
|
905
932
|
responseOutputItemDoneSchema,
|
|
906
933
|
reasoningTextDeltaChunkSchema,
|
|
@@ -908,7 +935,7 @@ var huggingfaceResponsesChunkSchema = import_v42.z.union([
|
|
|
908
935
|
textDeltaChunkSchema,
|
|
909
936
|
responseCompletedChunkSchema,
|
|
910
937
|
responseCreatedChunkSchema,
|
|
911
|
-
|
|
938
|
+
z3.object({ type: z3.string() }).loose()
|
|
912
939
|
// fallback for unknown chunks
|
|
913
940
|
]);
|
|
914
941
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
@@ -936,9 +963,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
936
963
|
// src/huggingface-provider.ts
|
|
937
964
|
function createHuggingFace(options = {}) {
|
|
938
965
|
var _a;
|
|
939
|
-
const baseURL = (_a =
|
|
966
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
|
|
940
967
|
const getHeaders = () => ({
|
|
941
|
-
Authorization: `Bearer ${
|
|
968
|
+
Authorization: `Bearer ${loadApiKey({
|
|
942
969
|
apiKey: options.apiKey,
|
|
943
970
|
environmentVariableName: "HUGGINGFACE_API_KEY",
|
|
944
971
|
description: "Hugging Face"
|
|
@@ -952,7 +979,7 @@ function createHuggingFace(options = {}) {
|
|
|
952
979
|
url: ({ path }) => `${baseURL}${path}`,
|
|
953
980
|
headers: getHeaders,
|
|
954
981
|
fetch: options.fetch,
|
|
955
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
982
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
956
983
|
});
|
|
957
984
|
};
|
|
958
985
|
const provider = (modelId) => createResponsesModel(modelId);
|
|
@@ -960,7 +987,7 @@ function createHuggingFace(options = {}) {
|
|
|
960
987
|
provider.languageModel = createResponsesModel;
|
|
961
988
|
provider.responses = createResponsesModel;
|
|
962
989
|
provider.embeddingModel = (modelId) => {
|
|
963
|
-
throw new
|
|
990
|
+
throw new NoSuchModelError({
|
|
964
991
|
modelId,
|
|
965
992
|
modelType: "embeddingModel",
|
|
966
993
|
message: "Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings."
|
|
@@ -968,7 +995,7 @@ function createHuggingFace(options = {}) {
|
|
|
968
995
|
};
|
|
969
996
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
970
997
|
provider.imageModel = (modelId) => {
|
|
971
|
-
throw new
|
|
998
|
+
throw new NoSuchModelError({
|
|
972
999
|
modelId,
|
|
973
1000
|
modelType: "imageModel",
|
|
974
1001
|
message: "Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models."
|
|
@@ -976,10 +1003,14 @@ function createHuggingFace(options = {}) {
|
|
|
976
1003
|
};
|
|
977
1004
|
return provider;
|
|
978
1005
|
}
|
|
979
|
-
var
|
|
980
|
-
|
|
981
|
-
|
|
1006
|
+
var huggingFace = createHuggingFace();
|
|
1007
|
+
|
|
1008
|
+
// src/version.ts
|
|
1009
|
+
var VERSION = true ? "2.0.0-canary.38" : "0.0.0-test";
|
|
1010
|
+
export {
|
|
1011
|
+
VERSION,
|
|
982
1012
|
createHuggingFace,
|
|
983
|
-
|
|
984
|
-
|
|
1013
|
+
huggingFace,
|
|
1014
|
+
huggingFace as huggingface
|
|
1015
|
+
};
|
|
985
1016
|
//# sourceMappingURL=index.js.map
|