@spotpatch/agent 1.0.0 → 1.1.0
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.cjs +16 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -278,6 +278,19 @@ async function readSseEvents(stream, options) {
|
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
// src/provider/provider-transport.ts
|
|
281
|
+
function createProviderHeaders(authentication, credential) {
|
|
282
|
+
const headers = new Headers({
|
|
283
|
+
Accept: "text/event-stream",
|
|
284
|
+
"Content-Type": "application/json"
|
|
285
|
+
});
|
|
286
|
+
const value = readProviderCredential(credential);
|
|
287
|
+
if (authentication === "x-api-key") {
|
|
288
|
+
headers.set("x-api-key", value);
|
|
289
|
+
} else {
|
|
290
|
+
headers.set("Authorization", `Bearer ${value}`);
|
|
291
|
+
}
|
|
292
|
+
return headers;
|
|
293
|
+
}
|
|
281
294
|
function mapStatus(status) {
|
|
282
295
|
if (status === 401 || status === 403) {
|
|
283
296
|
return new import_shared4.SpotPatchError(import_shared4.ERROR_CODES.PROVIDER_AUTH_FAILED);
|
|
@@ -317,11 +330,7 @@ async function postProviderStream(options) {
|
|
|
317
330
|
try {
|
|
318
331
|
response = await options.fetch(options.url, {
|
|
319
332
|
method: "POST",
|
|
320
|
-
headers:
|
|
321
|
-
Accept: "text/event-stream",
|
|
322
|
-
Authorization: `Bearer ${readProviderCredential(options.credential)}`,
|
|
323
|
-
"Content-Type": "application/json"
|
|
324
|
-
},
|
|
333
|
+
headers: createProviderHeaders(options.authentication, options.credential),
|
|
325
334
|
body: JSON.stringify(options.body),
|
|
326
335
|
redirect: "error",
|
|
327
336
|
signal: requestController.signal
|
|
@@ -514,6 +523,7 @@ function createChatCompletionsSession(options) {
|
|
|
514
523
|
}
|
|
515
524
|
const parsed = parseChatEvents(
|
|
516
525
|
await postProviderStream({
|
|
526
|
+
authentication: options.provider.authentication,
|
|
517
527
|
body: {
|
|
518
528
|
model: options.model.model,
|
|
519
529
|
messages,
|
|
@@ -685,6 +695,7 @@ function createResponsesSession(options) {
|
|
|
685
695
|
};
|
|
686
696
|
const parsed = parseResponsesEvents(
|
|
687
697
|
await postProviderStream({
|
|
698
|
+
authentication: options.provider.authentication,
|
|
688
699
|
body,
|
|
689
700
|
credential: options.credential,
|
|
690
701
|
fetch,
|