Bläddra i källkod

Merge pull request #5547 from ConnectAI-E/hotfix/plugin-opration-id

Hotfix/plugin opration
Lloyd Zhou 1 år sedan
förälder
incheckning
fcba50f041
2 ändrade filer med 17 tillägg och 5 borttagningar
  1. 5 5
      app/store/plugin.ts
  2. 12 0
      app/utils.ts

+ 5 - 5
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<string, any> = {};
           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,

+ 12 - 0
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("/", "_")}`
+  );
+}