Skip to content

Commit 4385080

Browse files
committed
🐛 fix: fix openapi requestBody
1 parent 12bac99 commit 4385080

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/edge.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ export const createGatewayOnEdgeRuntime = (options: EdgeRuntimeGatewayOptions =
3535
} catch (error) {
3636
const { errorType, body } = error as GatewayErrorResponse;
3737

38+
if (!errorType) {
39+
const err = error as Error;
40+
console.error(err.stack);
41+
return createErrorResponse(PluginErrorType.PluginGatewayError, {
42+
stack: err.stack,
43+
});
44+
}
3845
return createErrorResponse(errorType, body);
3946
}
4047
};

src/gateway.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
pluginMetaSchema,
1515
pluginRequestPayloadSchema,
1616
} from '@lobehub/chat-plugin-sdk';
17+
import { OPENAPI_REQUEST_BODY_KEY } from '@lobehub/chat-plugin-sdk/openapi';
1718
// @ts-ignore
1819
import SwaggerClient from 'swagger-client';
1920

@@ -181,7 +182,7 @@ export class Gateway {
181182
message: '[plugin] plugin manifest is invalid',
182183
});
183184

184-
console.log(`[${identifier}] plugin manifest:`, manifest);
185+
// console.log(`[${identifier}] plugin manifest:`, manifest);
185186

186187
// ========== 6. 校验是否按照 manifest 包含了 settings 配置 ========== //
187188

@@ -281,7 +282,7 @@ export class Gateway {
281282
};
282283

283284
// 根据 settings 中的每个属性来构建 authorizations 对象
284-
for (const [key, value] of Object.entries(settings)) {
285+
for (const [key, value] of Object.entries(settings || {})) {
285286
// 处理 API Key 和 Bearer Token
286287
authorizations[key] = value as string;
287288

@@ -316,10 +317,11 @@ export class Gateway {
316317
});
317318
}
318319

319-
const parameters = JSON.parse(args || '{}');
320+
const requestParams = JSON.parse(args || '{}');
321+
const { [OPENAPI_REQUEST_BODY_KEY]: requestBody, ...parameters } = requestParams;
320322

321323
try {
322-
const res = await client.execute({ operationId: apiName, parameters });
324+
const res = await client.execute({ operationId: apiName, parameters, requestBody });
323325

324326
return this.createSuccessResponse(res.text);
325327
} catch (error) {
@@ -335,6 +337,7 @@ export class Gateway {
335337
'[plugin] there are problem with sending openapi request, please contact with LobeHub Team',
336338
openapi: manifest.openapi,
337339
parameters,
340+
requestBody,
338341
});
339342
}
340343

src/node.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const createGatewayOnNodeRuntime = (options: NodeRuntimeGatewayOptions =
4848

4949
res.send(data);
5050
} catch (error) {
51-
console.error(error);
5251
const { errorType, body } = error as GatewayErrorResponse;
5352

5453
res

0 commit comments

Comments
 (0)