/** 修 Models.kt 里被正则吃掉的 JSON 字段名。跑完可删。 */ import fs from 'node:fs'; const p = process.argv[2]; let s = fs.readFileSync(p, 'utf8'); const fixes = [ ['attachments = optJSONArray().mapObj', 'attachments = optJSONArray("attachments").mapObj'], ['models = optJSONArray().mapObj', 'models = optJSONArray("models").mapObj'], ['allow = sec?.optJSONArray().mapObj', 'allow = sec?.optJSONArray("allow")?.strings() ?: emptyList()'], ['tools = python?.optJSONArray().mapObj', 'tools = python?.optJSONArray("tools").mapObj'], ['mcp = optJSONArray().mapObj', 'mcp = optJSONArray("mcp").mapObj'], ['conversations = optJSONArray().mapObj', 'conversations = optJSONArray("conversations").mapObj'], ['agents = optJSONArray().mapObj', 'agents = optJSONArray("agents").mapObj'], ['toolNames = optJSONArray().mapObj', 'toolNames = optJSONArray("toolNames").strings()'], ['suggestedAllow = optJSONArray().mapObj', 'suggestedAllow = optJSONArray("suggestedAllow").strings()'], ]; for (const [from, to] of fixes) { if (s.includes(from)) s = s.replace(from, to); } // 剩下的 { it.toString() } 形式统一换成 strings() s = s.replace(/optJSONArray\("([a-zA-Z]+)"\)\.mapObj \{ it\.toString\(\) \}/g, 'optJSONArray("$1").strings()'); // allow 那行可能被上一步换成 strings(),去掉多余的三元 s = s.replace(/allow = sec\?\.optJSONArray\("allow"\)\.strings\(\) \?: emptyList\(\)/, 'allow = sec?.optJSONArray("allow")?.strings() ?: emptyList()'); fs.writeFileSync(p, s, 'utf8'); console.log('已修复'); for (const line of s.split('\n')) { if (line.includes('optJSONArray')) console.log(' ' + line.trim()); }