try using method and path when operationId is undefined #5525
This commit is contained in:
parent
93ff7d26cc
commit
07d089a2bd
|
@ -4,7 +4,7 @@ import { nanoid } from "nanoid";
|
||||||
import { createPersistStore } from "../utils/store";
|
import { createPersistStore } from "../utils/store";
|
||||||
import { getClientConfig } from "../config/client";
|
import { getClientConfig } from "../config/client";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { adapter } from "../utils";
|
import { adapter, getOperationId } from "../utils";
|
||||||
import { useAccessStore } from "./access";
|
import { useAccessStore } from "./access";
|
||||||
|
|
||||||
const isApp = getClientConfig()?.isApp;
|
const isApp = getClientConfig()?.isApp;
|
||||||
|
@ -116,7 +116,7 @@ export const FunctionToolService = {
|
||||||
return {
|
return {
|
||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
name: o.operationId,
|
name: getOperationId(o),
|
||||||
description: o.description || o.summary,
|
description: o.description || o.summary,
|
||||||
parameters: parameters,
|
parameters: parameters,
|
||||||
},
|
},
|
||||||
|
@ -124,7 +124,7 @@ export const FunctionToolService = {
|
||||||
}),
|
}),
|
||||||
funcs: operations.reduce((s, o) => {
|
funcs: operations.reduce((s, o) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
s[o.operationId] = function (args) {
|
s[getOperationId(o)] = function (args) {
|
||||||
const parameters: Record<string, any> = {};
|
const parameters: Record<string, any> = {};
|
||||||
if (o.parameters instanceof Array) {
|
if (o.parameters instanceof Array) {
|
||||||
o.parameters.forEach((p) => {
|
o.parameters.forEach((p) => {
|
||||||
|
@ -139,8 +139,8 @@ export const FunctionToolService = {
|
||||||
} else if (authLocation == "body") {
|
} else if (authLocation == "body") {
|
||||||
args[headerName] = tokenValue;
|
args[headerName] = tokenValue;
|
||||||
}
|
}
|
||||||
// @ts-ignore
|
// @ts-ignore if o.operationId is null, then using o.path and o.method
|
||||||
return api.client[o.operationId](
|
return api.client.paths[o.path][o.method](
|
||||||
parameters,
|
parameters,
|
||||||
args,
|
args,
|
||||||
api.axiosConfigDefaults,
|
api.axiosConfigDefaults,
|
||||||
|
@ -253,6 +253,7 @@ export const usePluginStore = createPersistStore(
|
||||||
.catch((e) => item),
|
.catch((e) => item),
|
||||||
),
|
),
|
||||||
).then((builtinPlugins: any) => {
|
).then((builtinPlugins: any) => {
|
||||||
|
return;
|
||||||
builtinPlugins
|
builtinPlugins
|
||||||
.filter((item: any) => item?.content)
|
.filter((item: any) => item?.content)
|
||||||
.forEach((item: any) => {
|
.forEach((item: any) => {
|
||||||
|
|
12
app/utils.ts
12
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("/", "_")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue