mirror of
https://github.com/Wx-2025/ST-Amily2-Chat-Optimisation.git
synced 2026-06-06 09:15:50 +00:00
Update executor.js
This commit is contained in:
@@ -5,6 +5,13 @@ function insertRow(state, tableIndex, data) {
|
||||
log(`AI指令错误:尝试在不存在的表格索引 ${tableIndex} 中插入行。`, 'error');
|
||||
return { state, changes: [] };
|
||||
}
|
||||
|
||||
// 【安全检查】确保 data 是对象
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
log(`AI指令错误:insertRow 的 data 参数必须是对象,实际收到: ${typeof data} (${data})`, 'error');
|
||||
return { state, changes: [] };
|
||||
}
|
||||
|
||||
const table = state[tableIndex];
|
||||
const colCount = table.headers.length;
|
||||
const newRow = Array(colCount).fill('');
|
||||
@@ -28,6 +35,12 @@ function updateRow(state, tableIndex, rowIndex, data) {
|
||||
return { state, changes: [] };
|
||||
}
|
||||
|
||||
// 【安全检查】确保 data 是对象
|
||||
if (typeof data !== 'object' || data === null) {
|
||||
log(`AI指令错误:updateRow 的 data 参数必须是对象,实际收到: ${typeof data} (${data})`, 'error');
|
||||
return { state, changes: [] };
|
||||
}
|
||||
|
||||
const table = state[tableIndex];
|
||||
|
||||
if (rowIndex >= table.rows.length) {
|
||||
@@ -156,16 +169,24 @@ function parseValue(val) {
|
||||
try {
|
||||
return JSON.parse(val);
|
||||
} catch (e) {
|
||||
let fixedKeys = val.replace(/([{,]\s*)(\d+)(\s*:)/g, '$1"$2"$3');
|
||||
try {
|
||||
let fixedVal = val.replace(/([{,]\s*)(\d+)(\s*:)/g, '$1"$2"$3');
|
||||
fixedVal = fixedVal.replace(/'/g, '"');
|
||||
|
||||
return JSON.parse(fixedVal);
|
||||
return JSON.parse(fixedKeys);
|
||||
} catch (e2) {
|
||||
let fixedQuotes = fixedKeys.replace(/'/g, '"');
|
||||
try {
|
||||
return JSON.parse(fixedQuotes);
|
||||
} catch (e3) {
|
||||
let fixedAllKeys = val.replace(/([{,]\s*)([a-zA-Z0-9_]+)(\s*:)/g, '$1"$2"$3');
|
||||
try {
|
||||
return JSON.parse(fixedAllKeys);
|
||||
} catch (e4) {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user