@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.js CHANGED
@@ -69,7 +69,10 @@ function jsonStringifyToolOutput(value) {
69
69
  }
70
70
 
71
71
  // src/provider/provider-transport.ts
72
- import { ERROR_CODES as ERROR_CODES4, SpotPatchError as SpotPatchError4 } from "@spotpatch/shared";
72
+ import {
73
+ ERROR_CODES as ERROR_CODES4,
74
+ SpotPatchError as SpotPatchError4
75
+ } from "@spotpatch/shared";
73
76
 
74
77
  // src/provider/provider-credential.ts
75
78
  import { ERROR_CODES as ERROR_CODES2, SpotPatchError as SpotPatchError2 } from "@spotpatch/shared";
@@ -239,6 +242,19 @@ async function readSseEvents(stream, options) {
239
242
  }
240
243
 
241
244
  // src/provider/provider-transport.ts
245
+ function createProviderHeaders(authentication, credential) {
246
+ const headers = new Headers({
247
+ Accept: "text/event-stream",
248
+ "Content-Type": "application/json"
249
+ });
250
+ const value = readProviderCredential(credential);
251
+ if (authentication === "x-api-key") {
252
+ headers.set("x-api-key", value);
253
+ } else {
254
+ headers.set("Authorization", `Bearer ${value}`);
255
+ }
256
+ return headers;
257
+ }
242
258
  function mapStatus(status) {
243
259
  if (status === 401 || status === 403) {
244
260
  return new SpotPatchError4(ERROR_CODES4.PROVIDER_AUTH_FAILED);
@@ -278,11 +294,7 @@ async function postProviderStream(options) {
278
294
  try {
279
295
  response = await options.fetch(options.url, {
280
296
  method: "POST",
281
- headers: {
282
- Accept: "text/event-stream",
283
- Authorization: `Bearer ${readProviderCredential(options.credential)}`,
284
- "Content-Type": "application/json"
285
- },
297
+ headers: createProviderHeaders(options.authentication, options.credential),
286
298
  body: JSON.stringify(options.body),
287
299
  redirect: "error",
288
300
  signal: requestController.signal
@@ -475,6 +487,7 @@ function createChatCompletionsSession(options) {
475
487
  }
476
488
  const parsed = parseChatEvents(
477
489
  await postProviderStream({
490
+ authentication: options.provider.authentication,
478
491
  body: {
479
492
  model: options.model.model,
480
493
  messages,
@@ -646,6 +659,7 @@ function createResponsesSession(options) {
646
659
  };
647
660
  const parsed = parseResponsesEvents(
648
661
  await postProviderStream({
662
+ authentication: options.provider.authentication,
649
663
  body,
650
664
  credential: options.credential,
651
665
  fetch,