@jeffusion/bungee-core 5.24.0 → 5.24.1

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/main.js CHANGED
@@ -201027,7 +201027,7 @@ var package_default;
201027
201027
  var init_package = __esm(() => {
201028
201028
  package_default = {
201029
201029
  name: "@jeffusion/bungee-core",
201030
- version: "5.24.0",
201030
+ version: "5.24.1",
201031
201031
  description: "Bungee reverse proxy core engine",
201032
201032
  main: "./dist/main.js",
201033
201033
  types: "./dist/main.d.ts",
@@ -220107,6 +220107,16 @@ async function executePreFailoverPhase(phase, ctx, options) {
220107
220107
  }
220108
220108
  const interceptResult = await phase.hooks.onInterceptRequest.promise(ctx);
220109
220109
  if (interceptResult?.action === "respond") {
220110
+ if (interceptResult.response.ok) {
220111
+ try {
220112
+ await options.authorizeResponse?.();
220113
+ } catch (error) {
220114
+ await interceptResult.response.body?.cancel().catch(() => {
220115
+ return;
220116
+ });
220117
+ throw error;
220118
+ }
220119
+ }
220110
220120
  return interceptResult.response;
220111
220121
  }
220112
220122
  if (interceptResult?.action === "failover") {
@@ -220838,12 +220848,23 @@ async function executeHttpRequestInternal(req, config, runtimeContextOrSelector,
220838
220848
  phaseContext.url = new URL(dispatch.context.url);
220839
220849
  phaseContext.bodyRequirements = routeDemand;
220840
220850
  applyRoutePathRewriteToContext(phaseContext, route, requestLog);
220851
+ const authorizePhaseResponse = async () => {
220852
+ await dataAdmission?.inspect({
220853
+ attemptId: requestId,
220854
+ upstreamId: endpoints[0]?.id ?? "0",
220855
+ url: phaseContext.url.href,
220856
+ model: typeof phaseContext.body?.model === "string" ? phaseContext.body.model : null,
220857
+ body: phaseContext.body,
220858
+ transport: runtimeContext?.transport
220859
+ }, processingSignal);
220860
+ };
220841
220861
  const routePhaseResponse = await executePreFailoverPhase(requestPhaseHooks?.routePhase, phaseContext, {
220842
220862
  phaseName: "route",
220843
220863
  requestLog,
220844
220864
  requestId,
220845
220865
  routeId: currentRouteId,
220846
- serviceName: routeServiceName
220866
+ serviceName: routeServiceName,
220867
+ authorizeResponse: authorizePhaseResponse
220847
220868
  });
220848
220869
  if (routePhaseResponse) {
220849
220870
  responseStatus = routePhaseResponse.status;
@@ -220855,7 +220876,8 @@ async function executeHttpRequestInternal(req, config, runtimeContextOrSelector,
220855
220876
  requestLog,
220856
220877
  requestId,
220857
220878
  routeId: currentRouteId,
220858
- serviceName: routeServiceName
220879
+ serviceName: routeServiceName,
220880
+ authorizeResponse: authorizePhaseResponse
220859
220881
  });
220860
220882
  if (servicePhaseResponse) {
220861
220883
  responseStatus = servicePhaseResponse.status;
@@ -2012,6 +2012,10 @@ class ChatgptOauthAdapter {
2012
2012
  result.completion.then(cleanup, cleanup);
2013
2013
  return result;
2014
2014
  }
2015
+ if (state.target === "models" && result.response.status === 304) {
2016
+ trackCompletion(result.completion);
2017
+ return result;
2018
+ }
2015
2019
  if (!context.bodyHandle) {
2016
2020
  return errorResponse(502, Promise.resolve({ status: "failed", code: "body_view_missing" }));
2017
2021
  }
@@ -2037,10 +2041,14 @@ class ChatgptOauthAdapter {
2037
2041
  data: models.map(({ id }) => ({ id, object: "model", owned_by: "openai" }))
2038
2042
  };
2039
2043
  const completion = joinCompletion(result.completion, Promise.resolve({ status: "completed" }), context.signal);
2044
+ const headers = responseHeaders(result.response, "application/json; charset=utf-8");
2045
+ const etag = result.response.headers.get("etag");
2046
+ if (etag !== null)
2047
+ headers.set("etag", etag);
2040
2048
  const response = mark(new Response(JSON.stringify(body), {
2041
2049
  status: result.response.status,
2042
2050
  statusText: result.response.statusText,
2043
- headers: responseHeaders(result.response, "application/json; charset=utf-8")
2051
+ headers
2044
2052
  }));
2045
2053
  trackCompletion(completion);
2046
2054
  return { response, completion };
@@ -2134,4 +2142,4 @@ export {
2134
2142
  server_default as default
2135
2143
  };
2136
2144
 
2137
- //# debugId=76D0FF2CAF8435B164756E2164756E21
2145
+ //# debugId=6AB7BD049B59B52A64756E2164756E21