Command: python -c "from pathlib import Path;s=Path(r'C:\\Users\\ash\\ChatGPTMasterBridge\\Code.gs').read_text(encoding='utf-8',errors='replace');a=s.index('function poll_(');b=s.index('function result_(',a);c=s.index('function heartbeat_(',b);print(s[a:c])"
Directory: projects
Status: SUCCESS
Exit code: 0
Cancel Job Rerun Command Refresh
function poll_(bridge, target) {
const sheet = sheetById_(bridge.spreadsheet_id, COMMANDS_SHEET);
const values = sheet.getDataRange().getValues();
const headers = values[0] || [];
const col = headerMap_(headers);
for (let r = 1; r < values.length; r++) {
const row = values[r];
const status = String(row[col.status] || '').toLowerCase();
const confirm = String(row[col.confirm] || '').toLowerCase();
if (status === 'pending' && confirm === 'yes') {
const attempts = Number(row[col.attempts] || 0) + 1;
sheet.getRange(r + 1, col.status + 1).setValue('running');
sheet.getRange(r + 1, col.claimed_at + 1).setValue(nowIso_());
sheet.getRange(r + 1, col.attempts + 1).setValue(attempts);
return json_({
ok: true,
target: target,
command: {
row: r + 1,
id: String(row[col.id] || ''),
action: String(row[col.action] || ''),
payload_json: String(row[col.payload_json] || '{}'),
attempts: attempts
}
});
}
}
return json_({ ok: true, target: target, command: null });
}
function result_(bridge, target, body) {
const commandId = String(body.command_id || '');
if (!commandId) return json_({ ok: false, error: 'command_id_required' }, 400);
const status = String(body.status || 'done');
const completedAt = nowIso_();
const resultText = truncate_(String(body.result_text || ''));
const errorText = truncate_(String(body.error || ''));
const httpStatus = body.http_status === undefined ? '' : String(body.http_status);
const durationMs = body.duration_ms === undefined ? '' : String(body.duration_ms);
const sha = String(body.result_sha256 || '');
const truncated = body.truncated ? 'yes' : 'no';
const resultSheet = sheetById_(bridge.spreadsheet_id, RESULTS_SHEET);
const resultId = Utilities.getUuid();
resultSheet.appendRow([resultId, commandId, completedAt, status, httpStatus, resultText, errorText, durationMs, sha, truncated]);
const commandSheet = sheetById_(bridge.spreadsheet_id, COMMANDS_SHEET);
const rows = commandSheet.getDataRange().getValues();
const col = headerMap_(rows[0] || []);
for (let r = 1; r < rows.length; r++) {
if (String(rows[r][col.id] || '') === commandId) {
commandSheet.getRange(r + 1, col.status + 1).setValue(status);
commandSheet.getRange(r + 1, col.completed_at + 1).setValue(completedAt);
commandSheet.getRange(r + 1, col.result_ref + 1).setValue(resultId);
commandSheet.getRange(r + 1, col.error + 1).setValue(errorText);
break;
}
}
setStateValueById_(bridge.spreadsheet_id, 'last_command_id', commandId, 'Updated by relay result');
return json_({ ok: true, target: target, result_id: resultId });
}