Fix misc tool call errors (#2544)

* Fix misc tool call errors

* Fix middleware
This commit is contained in:
Chris Weaver 2024-09-23 14:00:48 -07:00 committed by GitHub
parent 316b6b99ea
commit 77650c9ee3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 12 deletions

View File

@ -1,3 +1,4 @@
import itertools
from collections.abc import Callable
from collections.abc import Iterator
from typing import Any
@ -554,8 +555,7 @@ class Answer:
def _stream() -> Iterator[str]:
nonlocal stream_stop_info
yield cast(str, message)
for item in stream:
for item in itertools.chain([message], stream):
if isinstance(item, StreamStopInfo):
stream_stop_info = item
return

View File

@ -2,24 +2,29 @@ import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED } from "./lib/constants";
// NOTE: have to have the "/:path*" here since NextJS doesn't allow any real JS to
// be run before the config is defined e.g. if we try and do a .map it will complain
const eePaths = [
"/admin/groups",
"/admin/api-key",
"/admin/performance/usage",
"/admin/performance/query-history",
"/admin/whitelabeling",
"/admin/performance/custom-analytics",
"/admin/standard-answer",
"/admin/groups/:path*",
"/admin/api-key/:path*",
"/admin/performance/usage/:path*",
"/admin/performance/query-history/:path*",
"/admin/whitelabeling/:path*",
"/admin/performance/custom-analytics/:path*",
"/admin/standard-answer/:path*",
];
const eePathsForMatcher = eePaths.map((path) => `${path}/:path*`);
// removes the "/:path*" from the end
const strippedEEPaths = eePaths.map((path) =>
path.replace(/(.*):\path\*$/, "$1").replace(/\/$/, "")
);
export async function middleware(request: NextRequest) {
if (SERVER_SIDE_ONLY__PAID_ENTERPRISE_FEATURES_ENABLED) {
const pathname = request.nextUrl.pathname;
// Check if the current path is in the eePaths list
if (eePaths.some((path) => pathname.startsWith(path))) {
if (strippedEEPaths.some((path) => pathname.startsWith(path))) {
// Add '/ee' to the beginning of the pathname
const newPathname = `/ee${pathname}`;
@ -37,5 +42,5 @@ export async function middleware(request: NextRequest) {
// Specify the paths that the middleware should run for
export const config = {
matcher: eePathsForMatcher,
matcher: eePaths,
};