fix: move Kernel connection IDs out of source into settings.json (gitignored)
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
"profiles": {
|
||||
"linkedin": "LinkedIn-YourName",
|
||||
"wellfound": "WellFound-YourName"
|
||||
},
|
||||
"connection_ids": {
|
||||
"linkedin": "your-linkedin-connection-id",
|
||||
"wellfound": "your-wellfound-connection-id"
|
||||
}
|
||||
},
|
||||
"browser": {
|
||||
|
||||
@@ -97,7 +97,7 @@ async function main() {
|
||||
let liBrowser;
|
||||
try {
|
||||
liBrowser = await createBrowser(settings, 'linkedin');
|
||||
const loggedIn = await ensureLoggedIn(liBrowser.page, liLogin, 'linkedin', settings.kernel_api_key || process.env.KERNEL_API_KEY);
|
||||
const loggedIn = await ensureLoggedIn(liBrowser.page, liLogin, 'linkedin', settings.kernel_api_key || process.env.KERNEL_API_KEY, settings.kernel?.connection_ids || {});
|
||||
if (!loggedIn) throw new Error('LinkedIn not logged in');
|
||||
console.log(' ✅ Logged in');
|
||||
|
||||
@@ -136,7 +136,7 @@ async function main() {
|
||||
let wfBrowser;
|
||||
try {
|
||||
wfBrowser = await createBrowser(settings, 'wellfound');
|
||||
const loggedIn = await ensureLoggedIn(wfBrowser.page, wfLogin, 'wellfound', settings.kernel_api_key || process.env.KERNEL_API_KEY);
|
||||
const loggedIn = await ensureLoggedIn(wfBrowser.page, wfLogin, 'wellfound', settings.kernel_api_key || process.env.KERNEL_API_KEY, settings.kernel?.connection_ids || {});
|
||||
if (!loggedIn) console.warn(' ⚠️ Wellfound login unconfirmed, proceeding');
|
||||
else console.log(' ✅ Logged in');
|
||||
|
||||
|
||||
@@ -7,14 +7,9 @@ const require = createRequire(import.meta.url);
|
||||
|
||||
const KERNEL_SDK_PATH = '/home/ubuntu/.openclaw/workspace/node_modules/@onkernel/sdk/index.js';
|
||||
|
||||
const CONNECTION_IDS = {
|
||||
linkedin: 'REDACTED_CONNECTION_ID_LINKEDIN',
|
||||
wellfound: 'REDACTED_CONNECTION_ID_WELLFOUND',
|
||||
};
|
||||
|
||||
export async function refreshSession(platform, apiKey) {
|
||||
const connectionId = CONNECTION_IDS[platform];
|
||||
if (!connectionId) throw new Error(`No connection ID for platform: ${platform}`);
|
||||
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`);
|
||||
|
||||
const Kernel = require(KERNEL_SDK_PATH);
|
||||
const kernel = new Kernel({ apiKey });
|
||||
@@ -51,14 +46,14 @@ export async function refreshSession(platform, apiKey) {
|
||||
/**
|
||||
* Verify login after browser connects — if not logged in, trigger refresh and retry
|
||||
*/
|
||||
export async function ensureLoggedIn(page, verifyFn, platform, apiKey, maxAttempts = 2) {
|
||||
export async function ensureLoggedIn(page, verifyFn, platform, apiKey, connectionIds = {}, maxAttempts = 2) {
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
const loggedIn = await verifyFn(page);
|
||||
if (loggedIn) return true;
|
||||
|
||||
if (attempt < maxAttempts) {
|
||||
console.warn(` ⚠️ ${platform} not logged in (attempt ${attempt}), refreshing session...`);
|
||||
await refreshSession(platform, apiKey);
|
||||
await refreshSession(platform, apiKey, connectionIds);
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await page.waitForTimeout(3000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user