(raw: string)
| 60 | // 解析 @param 行: name type [required] description |
| 61 | // type 支持 string|number|boolean,支持 enum [val1,val2] |
| 62 | function parseParam(raw: string): SkillScriptParam | null { |
| 63 | // 匹配: paramName type [required] description |
| 64 | // 或: paramName type[val1,val2] [required] description |
| 65 | const match = raw.match(/^(\w+)\s+(string|number|boolean)(\[[^\]]*\])?\s*(.*)/); |
| 66 | if (!match) return null; |
| 67 | |
| 68 | const [, name, type, enumPart, rest] = match; |
| 69 | |
| 70 | let enumValues: string[] | undefined; |
| 71 | if (enumPart) { |
| 72 | // 解析 [val1,val2] |
| 73 | const inner = enumPart.slice(1, -1).trim(); |
| 74 | if (inner) { |
| 75 | enumValues = inner.split(",").map((v) => v.trim()); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // rest 可能以 [required] 开头 |
| 80 | let required = false; |
| 81 | let description = rest.trim(); |
| 82 | if (description.startsWith("[required]")) { |
| 83 | required = true; |
| 84 | description = description.slice("[required]".length).trim(); |
| 85 | } |
| 86 | |
| 87 | return { |
| 88 | name, |
| 89 | type: type as SkillScriptParam["type"], |
| 90 | required, |
| 91 | description, |
| 92 | ...(enumValues ? { enum: enumValues } : {}), |
| 93 | }; |
| 94 | } |
| 95 | |
| 96 | // 获取 Skill Script 脚本体(去掉元数据头) |
| 97 | export function getSkillScriptBody(code: string): string { |
no test coverage detected