From 07d089a2bd41ea74ea9edcd7e1395e6d21e14645 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 27 Sep 2024 13:31:07 +0800 Subject: [PATCH 1/3] try using method and path when operationId is undefined #5525 --- app/store/plugin.ts | 11 ++++++----- app/utils.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/store/plugin.ts b/app/store/plugin.ts index 84ae0816e..a79a1ae4b 100644 --- a/app/store/plugin.ts +++ b/app/store/plugin.ts @@ -4,7 +4,7 @@ import { nanoid } from "nanoid"; import { createPersistStore } from "../utils/store"; import { getClientConfig } from "../config/client"; import yaml from "js-yaml"; -import { adapter } from "../utils"; +import { adapter, getOperationId } from "../utils"; import { useAccessStore } from "./access"; const isApp = getClientConfig()?.isApp; @@ -116,7 +116,7 @@ export const FunctionToolService = { return { type: "function", function: { - name: o.operationId, + name: getOperationId(o), description: o.description || o.summary, parameters: parameters, }, @@ -124,7 +124,7 @@ export const FunctionToolService = { }), funcs: operations.reduce((s, o) => { // @ts-ignore - s[o.operationId] = function (args) { + s[getOperationId(o)] = function (args) { const parameters: Record = {}; if (o.parameters instanceof Array) { o.parameters.forEach((p) => { @@ -139,8 +139,8 @@ export const FunctionToolService = { } else if (authLocation == "body") { args[headerName] = tokenValue; } - // @ts-ignore - return api.client[o.operationId]( + // @ts-ignore if o.operationId is null, then using o.path and o.method + return api.client.paths[o.path][o.method]( parameters, args, api.axiosConfigDefaults, @@ -253,6 +253,7 @@ export const usePluginStore = createPersistStore( .catch((e) => item), ), ).then((builtinPlugins: any) => { + return; builtinPlugins .filter((item: any) => item?.content) .forEach((item: any) => { diff --git a/app/utils.ts b/app/utils.ts index 9a8bebf38..6b2f65952 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -377,3 +377,15 @@ export function safeLocalStorage(): { }, }; } + +export function getOperationId(operation: { + operationId?: string; + method: string; + path: string; +}) { + // pattern '^[a-zA-Z0-9_-]+$' + return ( + operation?.operationId || + `${operation.method.toUpperCase()}${operation.path.replaceAll("/", "_")}` + ); +} From 22aa1698b407322c2cb980aed971ad3d06e6f87c Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Fri, 27 Sep 2024 13:31:49 +0800 Subject: [PATCH 2/3] try using method and path when operationId is undefined #5525 --- app/store/plugin.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/app/store/plugin.ts b/app/store/plugin.ts index a79a1ae4b..40abdc8d9 100644 --- a/app/store/plugin.ts +++ b/app/store/plugin.ts @@ -253,7 +253,6 @@ export const usePluginStore = createPersistStore( .catch((e) => item), ), ).then((builtinPlugins: any) => { - return; builtinPlugins .filter((item: any) => item?.content) .forEach((item: any) => { From 5bdf41139917f815143de11a9e04b261666c7707 Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Sun, 29 Sep 2024 15:51:28 +0800 Subject: [PATCH 3/3] hotfix for `x-goog-api-key` --- app/api/google.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/api/google.ts b/app/api/google.ts index 7d3f08be4..707892c33 100644 --- a/app/api/google.ts +++ b/app/api/google.ts @@ -23,7 +23,8 @@ export async function handle( }); } - const bearToken = req.headers.get("Authorization") ?? ""; + const bearToken = + req.headers.get("x-goog-api-key") || req.headers.get("Authorization") || ""; const token = bearToken.trim().replaceAll("Bearer ", "").trim(); const apiKey = token ? token : serverConfig.googleApiKey; @@ -92,7 +93,7 @@ async function request(req: NextRequest, apiKey: string) { 10 * 60 * 1000, ); const fetchUrl = `${baseUrl}${path}${ - req?.nextUrl?.searchParams?.get("alt") === "sse" ? "&alt=sse" : "" + req?.nextUrl?.searchParams?.get("alt") === "sse" ? "?alt=sse" : "" }`; console.log("[Fetch Url] ", fetchUrl); @@ -100,8 +101,8 @@ async function request(req: NextRequest, apiKey: string) { headers: { "Content-Type": "application/json", "Cache-Control": "no-store", - "x-google-api-key": - req.headers.get("x-google-api-key") || + "x-goog-api-key": + req.headers.get("x-goog-api-key") || (req.headers.get("Authorization") ?? "").replace("Bearer ", ""), }, method: req.method,