refactor: extract magic numbers to constants, fix audit issues
- Centralize all magic numbers/strings in lib/constants.mjs - Fix double-replaced import names in filter.mjs - Consolidate duplicate fs imports in job_applier/job_searcher - Remove empty JSDoc block in job_searcher - Update keywords.mjs model from claude-3-haiku to claude-haiku-4-5 - Extract Anthropic API URLs to constants - Convert :has-text() selectors to page.locator() API - Fix SIGTERM handler conflict — move partial-run notification into lock.onShutdown - Remove unused exports (LOCAL_USER_AGENT, DEFAULT_REVIEW_WINDOW_MINUTES) - Fix variable shadowing (b -> v) in job_filter reduce callback - Replace SKILL.md PM2 references with system cron Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
* Call refreshSession() before creating a browser to ensure the profile is fresh
|
||||
*/
|
||||
import { createRequire } from 'module';
|
||||
import {
|
||||
KERNEL_SDK_PATH, SESSION_REFRESH_POLL_TIMEOUT, SESSION_REFRESH_POLL_WAIT,
|
||||
SESSION_LOGIN_VERIFY_WAIT
|
||||
} from './constants.mjs';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
const KERNEL_SDK_PATH = '/home/ubuntu/.openclaw/workspace/node_modules/@onkernel/sdk/index.js';
|
||||
|
||||
export async function refreshSession(platform, apiKey, connectionIds = {}) {
|
||||
const connectionId = connectionIds[platform];
|
||||
if (!connectionId) throw new Error(`No Kernel connection ID configured for platform: ${platform} — add it to settings.json under kernel.connection_ids`);
|
||||
@@ -28,8 +30,8 @@ export async function refreshSession(platform, apiKey, connectionIds = {}) {
|
||||
console.log(` ⏳ ${platform} session pending (status: ${loginResp.status}), polling...`);
|
||||
const start = Date.now();
|
||||
let pollCount = 0;
|
||||
while (Date.now() - start < 30000) {
|
||||
await new Promise(r => setTimeout(r, 2000));
|
||||
while (Date.now() - start < SESSION_REFRESH_POLL_TIMEOUT) {
|
||||
await new Promise(r => setTimeout(r, SESSION_REFRESH_POLL_WAIT));
|
||||
pollCount++;
|
||||
const conn = await kernel.auth.connections.retrieve(connectionId);
|
||||
if (conn.status === 'SUCCESS') {
|
||||
@@ -58,7 +60,7 @@ export async function ensureLoggedIn(page, verifyFn, platform, apiKey, connectio
|
||||
console.warn(` ⚠️ ${platform} not logged in (attempt ${attempt}), refreshing session...`);
|
||||
await refreshSession(platform, apiKey, connectionIds);
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await page.waitForTimeout(3000);
|
||||
await page.waitForTimeout(SESSION_LOGIN_VERIFY_WAIT);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user