@worktango/ai-assistant 0.0.38 → 0.0.39
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/express.js +20 -20
- package/package.json +1 -1
package/dist/express.js
CHANGED
|
@@ -6485,9 +6485,9 @@ var require_fix_request_body = __commonJS({
|
|
|
6485
6485
|
"../../node_modules/http-proxy-middleware/dist/handlers/fix-request-body.js"(exports) {
|
|
6486
6486
|
"use strict";
|
|
6487
6487
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6488
|
-
exports.fixRequestBody =
|
|
6488
|
+
exports.fixRequestBody = fixRequestBody2;
|
|
6489
6489
|
var querystring = require("querystring");
|
|
6490
|
-
function
|
|
6490
|
+
function fixRequestBody2(proxyReq, req) {
|
|
6491
6491
|
if (req.readableLength !== 0) {
|
|
6492
6492
|
return;
|
|
6493
6493
|
}
|
|
@@ -11191,6 +11191,15 @@ function setupAiAssistantRoutes(args) {
|
|
|
11191
11191
|
const routePath = args.route ?? "/ai-assistant";
|
|
11192
11192
|
const port = args.targetPort ?? 80;
|
|
11193
11193
|
const protocol = "http";
|
|
11194
|
+
args.app.use(routePath, (req, res, next) => {
|
|
11195
|
+
args.getBearerToken(req.headers).then((bearerToken) => {
|
|
11196
|
+
req.headers.Authorization = `Bearer ${bearerToken}`;
|
|
11197
|
+
next();
|
|
11198
|
+
}).catch((error) => {
|
|
11199
|
+
logger.error("Error getting bearer token:", error);
|
|
11200
|
+
next(error);
|
|
11201
|
+
});
|
|
11202
|
+
});
|
|
11194
11203
|
const proxyOptions = {
|
|
11195
11204
|
target: `${protocol}://${args.targetHost}:${port}`,
|
|
11196
11205
|
changeOrigin: true,
|
|
@@ -11199,24 +11208,16 @@ function setupAiAssistantRoutes(args) {
|
|
|
11199
11208
|
return args.getTargetPath(expressRequest.originalUrl || path);
|
|
11200
11209
|
},
|
|
11201
11210
|
on: {
|
|
11202
|
-
proxyReq:
|
|
11203
|
-
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
11210
|
-
logger.error("Error getting bearer token:", error);
|
|
11211
|
-
throw error;
|
|
11211
|
+
proxyReq: import_http_proxy_middleware.fixRequestBody,
|
|
11212
|
+
proxyRes: (proxyRes, req, res) => {
|
|
11213
|
+
if (req.headers.accept === "text/event-stream") {
|
|
11214
|
+
res.writeHead(res.statusCode, {
|
|
11215
|
+
"Content-Type": "text/event-stream",
|
|
11216
|
+
"Cache-Control": "no-transform",
|
|
11217
|
+
Connection: "keep-alive"
|
|
11218
|
+
});
|
|
11212
11219
|
}
|
|
11213
11220
|
},
|
|
11214
|
-
proxyRes: (proxyRes) => {
|
|
11215
|
-
logger.debug("Proxy response received", {
|
|
11216
|
-
status: proxyRes.statusCode,
|
|
11217
|
-
headers: proxyRes.headers
|
|
11218
|
-
});
|
|
11219
|
-
},
|
|
11220
11221
|
error: (err, req, res) => {
|
|
11221
11222
|
logger.error("Proxy error:", err);
|
|
11222
11223
|
if ("headersSent" in res && !res.headersSent) {
|
|
@@ -11225,8 +11226,7 @@ function setupAiAssistantRoutes(args) {
|
|
|
11225
11226
|
res.end();
|
|
11226
11227
|
}
|
|
11227
11228
|
}
|
|
11228
|
-
}
|
|
11229
|
-
logger
|
|
11229
|
+
}
|
|
11230
11230
|
};
|
|
11231
11231
|
const proxy = (0, import_http_proxy_middleware.createProxyMiddleware)(proxyOptions);
|
|
11232
11232
|
args.app.use(routePath, ...coalesce(args.preflightMiddlewares, []), proxy);
|