mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-04-28 11:41:04 +00:00
fix: correct hooks JSON schema type definition
The hooks array items were incorrectly typed as 'string' in the JSON schema, causing VS Code to show type errors when users configure HookDefinition objects. This fix adds proper schema support for complex array item types. - Add SettingItemDefinition interface for array item schema - Add items schema for UserPromptSubmit and Stop hooks - Update generate-settings-schema.ts to convert complex item types Fixes #2246 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
bf99f95602
commit
700806ce83
3 changed files with 314 additions and 3 deletions
|
|
@ -21,6 +21,7 @@ import { fileURLToPath } from 'node:url';
|
|||
|
||||
import type {
|
||||
SettingDefinition,
|
||||
SettingItemDefinition,
|
||||
SettingsSchema,
|
||||
} from '../packages/cli/src/config/settingsSchema.js';
|
||||
import { getSettingsSchema } from '../packages/cli/src/config/settingsSchema.js';
|
||||
|
|
@ -37,6 +38,57 @@ interface JsonSchemaProperty {
|
|||
enum?: (string | number)[];
|
||||
default?: unknown;
|
||||
additionalProperties?: boolean | JsonSchemaProperty;
|
||||
required?: string[];
|
||||
}
|
||||
|
||||
function convertItemDefinitionToJsonSchema(
|
||||
itemDef: SettingItemDefinition,
|
||||
): JsonSchemaProperty {
|
||||
const schema: JsonSchemaProperty = {};
|
||||
|
||||
if (itemDef.description) {
|
||||
schema.description = itemDef.description;
|
||||
}
|
||||
|
||||
schema.type = itemDef.type;
|
||||
|
||||
if (itemDef.enum) {
|
||||
schema.enum = itemDef.enum;
|
||||
}
|
||||
|
||||
if (itemDef.type === 'object' && itemDef.properties) {
|
||||
schema.properties = {};
|
||||
const requiredFields: string[] = [];
|
||||
|
||||
for (const [key, childDef] of Object.entries(itemDef.properties)) {
|
||||
const childSchema = convertItemDefinitionToJsonSchema(childDef);
|
||||
schema.properties[key] = childSchema;
|
||||
if (childDef.required) {
|
||||
requiredFields.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (requiredFields.length > 0) {
|
||||
schema.required = requiredFields;
|
||||
}
|
||||
|
||||
if (itemDef.additionalProperties !== undefined) {
|
||||
if (typeof itemDef.additionalProperties === 'boolean') {
|
||||
schema.additionalProperties = itemDef.additionalProperties;
|
||||
} else {
|
||||
schema.additionalProperties = convertItemDefinitionToJsonSchema(
|
||||
itemDef.additionalProperties,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (itemDef.items) {
|
||||
schema.type = 'array';
|
||||
schema.items = convertItemDefinitionToJsonSchema(itemDef.items);
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
function convertSettingToJsonSchema(
|
||||
|
|
@ -60,7 +112,11 @@ function convertSettingToJsonSchema(
|
|||
break;
|
||||
case 'array':
|
||||
schema.type = 'array';
|
||||
schema.items = { type: 'string' };
|
||||
if (setting.items) {
|
||||
schema.items = convertItemDefinitionToJsonSchema(setting.items);
|
||||
} else {
|
||||
schema.items = { type: 'string' };
|
||||
}
|
||||
break;
|
||||
case 'enum':
|
||||
if (setting.options && setting.options.length > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue