Commit 9796796b by Finley Ge Committed by GitHub

fix: strip admin plugin IO schemas (#7141)

* refactor(core): optimize system tool input/output schema management

- Use `JSONSchema` instead of `InputConfig` for system tool I/O
  definitions
- Centralize JSON Schema to Node I/O conversion utilities
- Cleanup redundant type definitions and schema properties across
  packages

* refactor(global): improve workflow JSON schema mapping and tool catalog

- Update `getJsonSchemaPropertyFromValueType` to handle complex types
  like `arrayObject` and `chatHistory` properly instead of falling back
  to default types.
- Refactor `getEnumValuesFromNodeInput` to correctly collect enum values
  from different input configurations.
- Update `useToolCatalog` to use `nodeInputs2JsonSchema` for consistent
  schema generation across tools and nodes.
- Add comprehensive test cases to verify JSON schema conversion for
  various value types and enum sources.

* fix: strip admin plugin IO schemas

Admin plugin detail does not consume input/output schemas, so omit them from the admin response type to tolerate plugins that return null schemas.\n\nAdd regression coverage for parent and child tool details with null schemas.
parent e7fa0c9f
......@@ -44,6 +44,8 @@ export type AdminSystemToolChildDetailType = z.infer<typeof AdminSystemToolChild
/** 系统工具的详细信息 */
export const AdminSystemToolDetailSchema = z.object({
...SystemToolDetailSchema.omit({
inputSchema: true,
outputSchema: true,
isLatestVersion: true,
children: true
}).shape,
......
import { describe, expect, it } from 'vitest';
import { AdminSystemToolDetailSchema } from '@fastgpt/global/core/app/tool/systemTool/type';
import { PluginStatusEnum } from '@fastgpt/global/core/plugin/type';
import { SystemToolSystemSecretStatusEnum } from '@fastgpt/global/core/app/tool/systemTool/constants';
const createAdminToolDetail = () => ({
id: 'systemTool-null-schema',
version: '0.0.1',
status: PluginStatusEnum.Normal,
source: 'system',
isToolSet: false,
avatar: '/icon.svg',
name: 'Null schema tool',
intro: 'Tool intro',
author: 'FastGPT',
tags: [],
toolDescription: 'Tool description',
currentCost: 0,
systemKeyCost: 0,
hasTokenFee: false,
hasSystemSecret: false,
systemSecretStatus: SystemToolSystemSecretStatusEnum.none
});
describe('AdminSystemToolDetailSchema', () => {
it('strips input and output schemas from admin detail response', () => {
const detail = {
...createAdminToolDetail(),
inputSchema: null,
outputSchema: null,
secretSchema: {
type: 'object',
properties: {
apiKey: {
type: 'string',
isSecret: true
}
},
required: ['apiKey']
}
};
const result = AdminSystemToolDetailSchema.parse(detail);
expect(result).not.toHaveProperty('inputSchema');
expect(result).not.toHaveProperty('outputSchema');
expect(result.secretSchema).toEqual(detail.secretSchema);
});
it('strips child input and output schemas from admin detail response', () => {
const result = AdminSystemToolDetailSchema.parse({
...createAdminToolDetail(),
isToolSet: true,
children: [
{
id: 'child',
name: 'Child tool',
currentCost: 0,
systemKeyCost: 0,
inputSchema: null,
outputSchema: null
}
]
});
expect(result.children?.[0]).not.toHaveProperty('inputSchema');
expect(result.children?.[0]).not.toHaveProperty('outputSchema');
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment