@blaxel/vercel 0.2.60 → 0.2.61-dev.59
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/model.js +46 -2
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/model.js +46 -2
- package/package.json +70 -70
- package/LICENSE +0 -21
package/dist/cjs/model.js
CHANGED
|
@@ -22,8 +22,32 @@ const blModel = async (model, options) => {
|
|
|
22
22
|
// Custom fetch function that refreshes authentication on each request
|
|
23
23
|
const authenticatedFetch = async (input, init) => {
|
|
24
24
|
await (0, core_1.authenticate)();
|
|
25
|
+
// Properly extract headers from init, handling Headers object, plain object, or array
|
|
26
|
+
let existingHeaders = {};
|
|
27
|
+
if (init?.headers) {
|
|
28
|
+
if (init.headers instanceof Headers) {
|
|
29
|
+
// Headers object - iterate to extract all headers
|
|
30
|
+
init.headers.forEach((value, key) => {
|
|
31
|
+
existingHeaders[key] = value;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else if (Array.isArray(init.headers)) {
|
|
35
|
+
// Array of [key, value] pairs
|
|
36
|
+
for (const [key, value] of init.headers) {
|
|
37
|
+
existingHeaders[key] = value;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Plain object
|
|
42
|
+
existingHeaders = { ...init.headers };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Remove the SDK's authorization header since we use x-blaxel-authorization
|
|
46
|
+
// The SDK sets "Authorization: Bearer replaced" which would be rejected by the server
|
|
47
|
+
delete existingHeaders['authorization'];
|
|
48
|
+
delete existingHeaders['Authorization'];
|
|
25
49
|
const headers = {
|
|
26
|
-
...
|
|
50
|
+
...existingHeaders,
|
|
27
51
|
...core_1.settings.headers,
|
|
28
52
|
};
|
|
29
53
|
return fetch(input, {
|
|
@@ -37,8 +61,28 @@ const blModel = async (model, options) => {
|
|
|
37
61
|
apiKey: "replaced",
|
|
38
62
|
fetch: async (_, options) => {
|
|
39
63
|
await (0, core_1.authenticate)();
|
|
64
|
+
// Properly extract headers from options, handling Headers object
|
|
65
|
+
let existingHeaders = {};
|
|
66
|
+
if (options?.headers) {
|
|
67
|
+
if (options.headers instanceof Headers) {
|
|
68
|
+
options.headers.forEach((value, key) => {
|
|
69
|
+
existingHeaders[key] = value;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (Array.isArray(options.headers)) {
|
|
73
|
+
for (const [key, value] of options.headers) {
|
|
74
|
+
existingHeaders[key] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
existingHeaders = { ...options.headers };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Remove the SDK's authorization header since we use x-blaxel-authorization
|
|
82
|
+
delete existingHeaders['authorization'];
|
|
83
|
+
delete existingHeaders['Authorization'];
|
|
40
84
|
const headers = {
|
|
41
|
-
...
|
|
85
|
+
...existingHeaders,
|
|
42
86
|
...core_1.settings.headers,
|
|
43
87
|
};
|
|
44
88
|
return fetch(`${url}/v1beta/models/${modelId}:generateContent`, {
|