Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Updates related to the launch of the app (#1178)

Matthew Diakonovfb7a19f41302
diff --git a/pipes/linkedin-ai-assistant/app/api/chrome/check-login/route.ts b/pipes/linkedin-ai-assistant/app/api/chrome/check-login/route.ts
index cdb055119..5088d1631 100644
--- a/pipes/linkedin-ai-assistant/app/api/chrome/check-login/route.ts
+++ b/pipes/linkedin-ai-assistant/app/api/chrome/check-login/route.ts
@@ -1,18 +1,27 @@
import { NextResponse } from 'next/server';
import { setupBrowser, getActiveBrowser } from '@/lib/browser-setup';
+const logs: string[] = [];
+const addLog = (msg: string) => {
+ console.log(msg);
+ logs.push(`${new Date().toISOString()} - ${msg}`);
+};
+
export async function POST(request: Request) {
try {
await request.json(); // keep reading the request to avoid hanging
- console.log('checking linkedin login status');
+ addLog('checking linkedin login status');
- await setupBrowser();
+ addLog('setting up browser...');
+ await setupBrowser(logs);
const { page } = getActiveBrowser();
if (!page) {
+ addLog('no active browser session found');
throw new Error('no active browser session');
}
+ addLog('evaluating login state...');
// Check for elements that indicate logged-in state
const isLoggedIn = await page.evaluate(() => {
// Check for feed-specific elements that only appear when logged in
@@ -21,19 +30,20 @@ export async function POST(request: Request) {
// Return true if we find elements specific to logged-in state
return !!(feedElements || navElements)
- })
+ });
- console.log(`login status: ${isLoggedIn ? 'logged in' : 'logged out'}`)
+ addLog(`login status: ${isLoggedIn ? 'logged in' : 'logged out'}`);
return NextResponse.json({
success: true,
- isLoggedIn: Boolean(isLoggedIn)
+ isLoggedIn: Boolean(isLoggedIn),
+ logs
});
} catch (error) {
- console.error('failed to check login status:', error);
+ addLog(`failed to check login status: ${error}`);
return NextResponse.json(
- { success: false, error: String(error) },
+ { success: false, error: String(error), logs },
{ status: 500 }
);
}
diff --git a/pipes/linkedin-ai-assistant/app/api/chrome/navigate/route.ts b/pipes/linkedin-ai-assistant/app/api/chrome/navigate/route.ts
index 2269a2c48..6110594bd 100644
--- a/pipes/linkedin-ai-assistant/app/api/chrome/navigate/route.ts
+++ b/pipes/linkedin-ai-assistant/app/api/chrome/navigate/route.ts
@@ -3,24 +3,37 @@ import { setupBrowser } from '@/lib/browser-setup';
import { ChromeSession } from '@/lib/chrome-session';
import type { Page } from 'puppeteer-core';
+const logs: string[] = [];
+const addLog = (msg: string) => {
+ console.log(msg);
+ logs.push(`${new Date().toISOString()} - ${msg}`);
+};
+
async function navigateToPage(page: Page, url: string) {
try {
- console.log('starting navigation');
+ addLog('starting navigation');
+ addLog(`target url: ${url}`);
// Set longer timeout but keep navigation simple
await page.setDefaultNavigationTimeout(60000);
+ addLog('navigation timeout set to 60s');
// Navigate to the target URL with same settings as search navigation
+ addLog('navigating to page...');
const response = await page.goto(url, {
waitUntil: 'domcontentloaded',
timeout: 60000
});
+ addLog(`navigation response status: ${response?.status() || 0}`);
// Wait for the main content to load
+ addLog('waiting for body element...');
await page.waitForSelector('body', { timeout: 30000 });
+ addLog('body element found');
// Store the page in ChromeSession after successful navigation
ChromeSession.getInstance().setActivePage(page);
+ addLog('page stored in chrome session');
return {
status: response?.status() || 0,
@@ -28,7 +41,7 @@ async function navigateToPage(page: Page, url: string) {
};
} catch (error) {
- console.error('navigation error:', error);
+ addLog(`navigation error: ${error}`);
throw error;
}
}
@@ -36,28 +49,32 @@ async function navigateToPage(page: Page, url: string) {
export async function POST(request: Request) {
try {
const { url } = await request.json();
- console.log('attempting to navigate to:', url);
+ addLog(`attempting to navigate to: ${url}`);
// Setup the browser connection
- const { page } = await setupBrowser();
+ addLog('setting up browser...');
+ const { page } = await setupBrowser(logs);
// Perform the navigation
const result = await navigateToPage(page, url);
+ addLog(`navigation complete. final url: ${result.finalUrl}`);
// Return a successful response with navigation details
return NextResponse.json({
success: true,
status: result.status,
- finalUrl: result.finalUrl
+ finalUrl: result.finalUrl,
+ logs
});
} catch (error) {
- console.error('failed to navigate:', error);
+ addLog(`failed to navigate: ${error}`);
// Return an error response with details
return NextResponse.json({
success: false,
error: 'failed to navigate',
- details: error instanceof Error ? error.message : String(error)
+ details: error instanceof Error ? error.message : String(error),
+ logs
}, { status: 500 });
}
}
\ No newline at end of file
diff --git a/pipes/linkedin-ai-assistant/app/api/chrome/route.ts b/pipes/linkedin-ai-assistant/app/api/chrome/route.ts
index 6c2fbd73c..f0825a1e9 100644
--- a/pipes/linkedin-ai-assistant/app/api/chrome/route.ts
+++ b/pipes/linkedin-ai-assistant/app/api/chrome/route.ts
@@ -6,6 +6,12 @@ import os from 'os';
import { ChromeSession } from '@/lib/chrome-session';
// import { pipe } from "@screenpipe/js";
+const logs: string[] = [];
+const addLog = (msg: string) => {
+ console.log(msg);
+ logs.push(`${new Date().toISOString()} - ${msg}`);
+};
+
export const runtime = 'nodejs'; // specify node runtime
const execPromise = promisify(exec);
@@ -13,8 +19,11 @@ const execPromise = promisify(exec);
// helper to get chrome path based on platform
function getChromePath() {
switch (os.platform()) {
- case "darwin":
+ case "darwin": {
+ const isArm = os.arch() === 'arm64';
+ addLog(`mac architecture: ${os.arch()}`);
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
+ }
case "linux":
return "/usr/bin/google-chrome";
case "win32":
@@ -24,17 +33,54 @@ function getChromePath() {
}
}
-export async function POST() {
- const logs: string[] = [];
- const addLog = (msg: string) => {
- console.log(msg); // keep server-side logging
- logs.push(`${new Date().toISOString()} - ${msg}`);
- };
+interface ScreenDimensions {
+ width: number;
+ height: number;
+}
+function getScreenDimensions(requestDims?: ScreenDimensions) {
+ const defaultDims = { width: 2560, height: 1440 };
+
+ if (requestDims) {
+ addLog(`using client screen dimensions: ${requestDims.width}x${requestDims.height}`);
+ return requestDims;
+ }
+
+ addLog(`no dimensions provided, using defaults: ${defaultDims.width}x${defaultDims.height}`);
+ return defaultDims;
+}
+
+export async function POST(request: Request) {
try {
addLog('chrome route: starting POST request');
+
+ // Get dimensions from request first
+ const body = await request.json();
+ const screenDims = getScreenDimensions(body.screenDims);
+ const additionalFlags = [
+ '--remote-debugging-port=9222',
+ '--restore-last-session',
+ '--no-first-run',
+ '--no-default-browser-check',
+ `--window-position=${screenDims.width / 2},0`,
+ `--window-size=${screenDims.width / 2},${screenDims.height}`,
+ '--no-sandbox',
+ '--disable-setuid-sandbox',
+ '--disable-dev-shm-usage',
+ '--disable-gpu',
+ '--disable-background-timer-throttling',
+ '--disable-backgrounding-occluded-windows',
+ '--disable-renderer-backgrounding',
+ '--disable-background-networking',
+ '--disable-features=TranslateUI',
+ '--disable-features=IsolateOrigins',
+ '--disable-site-isolation-trials',
+ ].flat();
+ // Log environment info
addLog(`environment: ${process.env.NODE_ENV}`);
addLog(`current platform: ${os.platform()}`);
+ addLog(`system architecture: ${os.arch()}`);
+ addLog(`cpu info: ${JSON.stringify(os.cpus()[0], null, 2)}`);
addLog("attempting to launch chrome");
addLog("killing existing chrome instances...");
@@ -46,16 +92,17 @@ export async function POST() {
addLog(`checking if chrome exists: ${require('fs').existsSync(chromePath)}`);
addLog("spawning chrome with debugging port 9222...");
- const chromeProcess = spawn(chromePath, [
- '--remote-debugging-port=9222',
- '--restore-last-session',
- '--no-first-run',
- '--no-default-browser-check',
- '--no-sandbox',
- '--disable-setuid-sandbox',
- '--disable-dev-shm-usage',
- '--disable-gpu'
- ], {
+ const isArmMac = os.platform() === 'darwin' && os.arch() === 'arm64';
+ const spawnCommand = isArmMac ? 'arch' : chromePath;
+ const spawnArgs = isArmMac ? [
+ '-arm64',
+ chromePath,
+ ...additionalFlags
+ ] : [
+ ...additionalFlags
+ ];
+
+ const chromeProcess = spawn(spawnCommand, spawnArgs, {
detached: true,
stdio: 'ignore'
});
@@ -108,12 +155,6 @@ export async function POST() {
}
export async function DELETE() {
- const logs: string[] = [];
- const addLog = (msg: string) => {
- console.log(msg);
- logs.push(`${new Date().toISOString()} - ${msg}`);
- };
-
try {
addLog('chrome route: starting DELETE request');
await quitChrome();
@@ -148,3 +189,5 @@ async function quitChrome() {
}
}
+
+
diff --git a/pipes/linkedin-ai-assistant/app/api/chrome/status/route.ts b/pipes/linkedin-ai-assistant/app/api/chrome/status/route.ts
index 52b2dc981..5c3b65508 100644
--- a/pipes/linkedin-ai-assistant/app/api/chrome/status/route.ts
+++ b/pipes/linkedin-ai-assistant/app/api/chrome/status/route.ts
@@ -2,21 +2,42 @@ import { NextResponse } from 'next/server';
export const runtime = 'nodejs';
+const logs: string[] = [];
+const addLog = (msg: string) => {
+ console.log(msg);
+ logs.push(`${new Date().toISOString()} - ${msg}`);
+};
+
export async function GET() {
try {
+ addLog('checking chrome connection status...');
const response = await fetch('http://127.0.0.1:9222/json/version');
+
if (!response.ok) {
- return NextResponse.json({ status: 'not_connected' }, { status: 200 });
+ addLog('chrome not connected');
+ return NextResponse.json({
+ status: 'not_connected',
+ logs
+ }, { status: 200 });
}
- const data = await response.json() as { webSocketDebuggerUrl: string };
+ const data = await response.json() as { webSocketDebuggerUrl: string };
+ addLog('chrome connected, getting websocket url');
+
const wsUrl = data.webSocketDebuggerUrl.replace('ws://localhost:', 'ws://127.0.0.1:');
+ addLog(`websocket url: ${wsUrl}`);
return NextResponse.json({
wsUrl,
- status: 'connected'
+ status: 'connected',
+ logs
});
- } catch {
- return NextResponse.json({ status: 'not_connected' }, { status: 200 });
+ } catch (error) {
+ addLog(`error checking status: ${error}`);
+ return NextResponse.json({
+ status: 'not_connected',
+ error: String(error),
+ logs
+ }, { status: 200 });
}
}
\ No newline at end of file
diff --git a/pipes/linkedin-ai-assistant/app/layout.tsx b/pipes/linkedin-ai-assistant/app/layout.tsx
index 4c4afb66e..39e32e99d 100644
--- a/pipes/linkedin-ai-assistant/app/layout.tsx
+++ b/pipes/linkedin-ai-assistant/app/layout.tsx
@@ -2,6 +2,7 @@ import type { Metadata } from "next";
import { Toaster } from "@/components/toaster";
import { Inter } from "next/font/google";
import "./globals.css";
+import { WindowSizer } from "@/components/window-sizer";
export const metadata: Metadata = {
title: "LinkedIn AI Assistant",
@@ -25,6 +26,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
+ <WindowSizer />
{children}
<Toaster />
</body>
diff --git a/pipes/linkedin-ai-assistant/app/page.tsx b/pipes/linkedin-ai-assistant/app/page.tsx
index f234723f1..76f47aab3 100644
--- a/pipes/linkedin-ai-assistant/app/page.tsx
+++ b/pipes/linkedin-ai-assistant/app/page.tsx
@@ -14,11 +14,6 @@ export default function Home() {
<div className="space-y-1.5 mb-8">
<h1 className="text-2xl font-semibold tracking-tight">linkedin ai assistant</h1>
<p className="text-sm text-muted-foreground">automate your linkedin interactions with ai</p>
- <p className="text-sm text-muted-foreground mt-4">
- this tool helps you manage your linkedin network by automating common tasks. you can harvest connections
- from your network and request introductions using ai-powered workflows. make sure you&apos;re logged into
- linkedin before starting any automation.
- </p>
</div>
<div className="space-y-8">
diff --git a/pipes/linkedin-ai-assistant/components/harvest.tsx b/pipes/linkedin-ai-assistant/components/harvest.tsx
index 336c45026..f422110fa 100644
--- a/pipes/linkedin-ai-assistant/components/harvest.tsx
+++ b/pipes/linkedin-ai-assistant/components/harvest.tsx
@@ -426,7 +426,6 @@ export function HarvestClosestConnections() {
onClick={() => updateConnectionsStatus()}
className="ml-2 p-2 rounded-md bg-red-100 hover:bg-red-200 transition-all"
aria-label="stop withdrawing"
- aria-label="stop withdrawing"
>
<span className="text-red-600 text-sm">stop</span>
</button>
diff --git a/pipes/linkedin-ai-assistant/components/launch-linkedin-chrome-session.tsx b/pipes/linkedin-ai-assistant/components/launch-linkedin-chrome-session.tsx
index 7fadc46c2..025211172 100644
--- a/pipes/linkedin-ai-assistant/components/launch-linkedin-chrome-session.tsx
+++ b/pipes/linkedin-ai-assistant/components/launch-linkedin-chrome-session.tsx
@@ -28,6 +28,7 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
const [logs, setLogs] = useState<string[]>([]);
const [isLogsOpen, setIsLogsOpen] = useState(false);
const [hasCopied, setHasCopied] = useState(false);
+ const [error, setError] = useState<string | null>(null);
useEffect(() => {
return () => {
@@ -71,27 +72,34 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
try {
await killChrome();
setStatus('connecting');
+ setError(null);
- // await pipe.captureMainFeatureEvent("linkedin_chrome_launched", {
- // status: "started"
- // });
+ // Get screen dimensions from browser
+ const screenDims = {
+ width: window.screen.availWidth,
+ height: window.screen.availHeight
+ };
+ addLog(`screen dimensions: ${screenDims.width}x${screenDims.height}`);
- const response = await fetch('/api/chrome', { method: 'POST' });
+ const response = await fetch('/api/chrome', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ screenDims })
+ });
const data = await response.json();
- if (!response.ok) throw new Error('Failed to launch chrome');
if (data.logs) {
data.logs.forEach((log: string) => addLog(log));
}
+ if (!response.ok) {
+ throw new Error(data.error || 'Failed to launch chrome');
+ }
// Start polling the server-side API for debugger URL
pollDebuggerStatus();
} catch (error) {
console.error('failed to launch chrome:', error);
- // await pipe.captureMainFeatureEvent("linkedin_chrome_launched", {
- // status: "error",
- // error: error instanceof Error ? error.message : String(error)
- // });
setStatus('error');
+ setError(error instanceof Error ? error.message : String(error));
}
};
@@ -101,21 +109,32 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
while (attempts < maxAttempts) {
try {
+ addLog('polling debugger status...');
const response = await fetch('/api/chrome/status');
const data = await response.json();
+
+ // Add logs from the status endpoint
+ if (data.logs) {
+ data.logs.forEach((log: string) => addLog(log));
+ }
+
+ addLog(`poll response: ${JSON.stringify(data)}`);
if (data.status === 'connected') {
+ addLog('debugger connected, proceeding to linkedin');
setStatus('connected');
- // Automatically navigate to LinkedIn when Chrome connects
await navigateToLinkedIn();
return;
}
+ addLog(`not connected yet, attempt ${attempts + 1}/${maxAttempts}`);
} catch (error) {
+ addLog(`poll error: ${error}`);
console.error('error checking debugger status:', error);
}
await new Promise(resolve => setTimeout(resolve, 1000));
attempts++;
}
+ addLog('max polling attempts reached, setting error state');
setStatus('error');
};
@@ -129,6 +148,12 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
if (!response.ok) throw new Error('Failed to check login status');
const data = await response.json();
+
+ // Add log handling
+ if (data.logs) {
+ data.logs.forEach((log: string) => addLog(log));
+ }
+
const isLoggedIn = data.isLoggedIn;
setLoginStatus(isLoggedIn ? 'logged_in' : 'logged_out');
@@ -173,6 +198,12 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
throw new Error(error.details || 'Failed to navigate');
}
+ // Missing: We need to handle the response data and logs here
+ const data = await response.json();
+ if (data.logs) {
+ data.logs.forEach((log: string) => addLog(log));
+ }
+
// Add login status check after navigation
setLoginStatus('checking');
await checkLoginStatus(statusData.wsUrl);
@@ -250,8 +281,9 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
)}
{status === 'error' && (
- <div className="text-sm text-red-500">
- failed to launch chrome
+ <div className="text-sm text-red-500 flex items-center gap-2">
+ <span>failed to launch chrome</span>
+ {error && <span className="font-mono">({error})</span>}
</div>
)}
</div>
@@ -265,7 +297,7 @@ export function LaunchLinkedInChromeSession({ loginStatus, setLoginStatus }: Pro
{isLogsOpen ? 'hide logs' : 'show logs'}
</CollapsibleTrigger>
<CollapsibleContent className="absolute mt-2 right-0 left-0">
- <div className="bg-gray-50 rounded-md text-xs font-mono max-h-40 w-full relative">
+ <div className="bg-gray-50 rounded-md text-xs font-mono max-h-40 w-full relative border border-gray-200/50">
<div className="absolute top-2 right-2 z-10">
<Button
variant="ghost"
diff --git a/pipes/linkedin-ai-assistant/components/reload-button.tsx b/pipes/linkedin-ai-assistant/components/reload-button.tsx
index eeca09fa4..e7780abcd 100644
--- a/pipes/linkedin-ai-assistant/components/reload-button.tsx
+++ b/pipes/linkedin-ai-assistant/components/reload-button.tsx
@@ -2,22 +2,29 @@
import { Button } from "@/components/ui/button";
import { RotateCw } from "lucide-react";
+import { useRouter } from "next/navigation";
export function ReloadButton() {
+ const router = useRouter();
+
const handleReload = () => {
+ console.log("performing full app reload...");
+ // First refresh the Next.js router cache
+ router.refresh();
+ // Then do a hard reload
window.location.reload();
};
return (
<div className="flex items-center gap-1">
- {/* <Button
+ <Button
variant="ghost"
size="icon"
onClick={handleReload}
className="hover:bg-gray-100 dark:hover:bg-gray-800"
>
<RotateCw className="h-4 w-4" />
- </Button> */}
+ </Button>
<span className="text-sm text-muted-foreground">if button does not work, right click to Reload</span>
</div>
);
diff --git a/pipes/linkedin-ai-assistant/components/window-sizer.tsx b/pipes/linkedin-ai-assistant/components/window-sizer.tsx
new file mode 100644
index 000000000..02c2bf43e
--- /dev/null
+++ b/pipes/linkedin-ai-assistant/components/window-sizer.tsx
@@ -0,0 +1,24 @@
+'use client'
+
+import { useEffect } from "react"
+
+export function WindowSizer() {
+ useEffect(() => {
+ // Set initial window size
+ fetch("http://localhost:11435/window-size", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ title: "linkedin-ai-assistant",
+ width: 950,
+ height: 550,
+ }),
+ }).catch(err => {
+ console.error("failed to set window size:", err)
+ });
+ }, []);
+
+ return null;
+}
\ No newline at end of file