@plosson/agentio 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plosson/agentio",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "CLI for LLM agents to interact with communication and tracking services",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,7 +47,6 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "commander": "^14.0.2",
50
- "googleapis": "^169.0.0",
51
- "playwright-core": "^1.57.0"
50
+ "googleapis": "^169.0.0"
52
51
  }
53
52
  }
@@ -1,5 +1,6 @@
1
1
  import { Command } from 'commander';
2
2
  import { basename, join } from 'path';
3
+ import { tmpdir } from 'os';
3
4
  import { google } from 'googleapis';
4
5
  import { getValidTokens, createGoogleAuth } from '../auth/token-manager';
5
6
  import { setCredentials, removeCredentials, getCredentials } from '../auth/token-store';
@@ -19,6 +20,53 @@ function escapeHtml(text: string): string {
19
20
  .replace(/"/g, '"');
20
21
  }
21
22
 
23
+ function findChromePath(): string | null {
24
+ const platform = process.platform;
25
+
26
+ const paths: string[] = [];
27
+
28
+ if (platform === 'darwin') {
29
+ paths.push(
30
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
31
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
32
+ '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
33
+ '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
34
+ );
35
+ } else if (platform === 'linux') {
36
+ paths.push(
37
+ '/usr/bin/google-chrome',
38
+ '/usr/bin/google-chrome-stable',
39
+ '/usr/bin/chromium',
40
+ '/usr/bin/chromium-browser',
41
+ '/snap/bin/chromium',
42
+ '/usr/bin/microsoft-edge',
43
+ '/usr/bin/brave-browser',
44
+ );
45
+ } else if (platform === 'win32') {
46
+ const programFiles = process.env['PROGRAMFILES'] || 'C:\\Program Files';
47
+ const programFilesX86 = process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)';
48
+ const localAppData = process.env['LOCALAPPDATA'] || '';
49
+
50
+ paths.push(
51
+ `${programFiles}\\Google\\Chrome\\Application\\chrome.exe`,
52
+ `${programFilesX86}\\Google\\Chrome\\Application\\chrome.exe`,
53
+ `${localAppData}\\Google\\Chrome\\Application\\chrome.exe`,
54
+ `${programFiles}\\Microsoft\\Edge\\Application\\msedge.exe`,
55
+ `${programFilesX86}\\Microsoft\\Edge\\Application\\msedge.exe`,
56
+ `${programFiles}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe`,
57
+ `${localAppData}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe`,
58
+ );
59
+ }
60
+
61
+ for (const p of paths) {
62
+ if (Bun.file(p).size > 0) {
63
+ return p;
64
+ }
65
+ }
66
+
67
+ return null;
68
+ }
69
+
22
70
  async function getGmailClient(profileName?: string): Promise<{ client: GmailClient; profile: string }> {
23
71
  const { tokens, profile } = await getValidTokens('gmail', profileName);
24
72
  const auth = createGoogleAuth(tokens);
@@ -323,25 +371,47 @@ ${emailHeader}
323
371
  </html>`;
324
372
  }
325
373
 
326
- // Lazy load playwright-core to avoid bundling issues
327
- const { chromium } = await import('playwright-core');
328
-
329
- // Launch browser and generate PDF
330
- console.error('Launching browser...');
331
- const browser = await chromium.launch({
332
- channel: 'chrome', // Use system Chrome
333
- });
374
+ // Find Chrome browser
375
+ const chromePath = findChromePath();
376
+ if (!chromePath) {
377
+ throw new CliError(
378
+ 'NOT_FOUND',
379
+ 'Chrome/Chromium not found',
380
+ 'Install Google Chrome, Chromium, or Microsoft Edge'
381
+ );
382
+ }
334
383
 
335
- const page = await browser.newPage();
336
- await page.setContent(html, { waitUntil: 'networkidle' });
337
- await page.pdf({
338
- path: options.output,
339
- format: 'A4',
340
- margin: { top: '1cm', right: '1cm', bottom: '1cm', left: '1cm' },
341
- });
384
+ // Write HTML to temp file
385
+ const tempHtml = join(tmpdir(), `agentio-email-${Date.now()}.html`);
386
+ await Bun.write(tempHtml, html);
387
+
388
+ // Resolve output path to absolute
389
+ const outputPath = options.output.startsWith('/')
390
+ ? options.output
391
+ : join(process.cwd(), options.output);
392
+
393
+ try {
394
+ // Run Chrome in headless mode to generate PDF
395
+ console.error('Generating PDF...');
396
+ const result = Bun.spawnSync([
397
+ chromePath,
398
+ '--headless=new',
399
+ '--disable-gpu',
400
+ '--no-pdf-header-footer',
401
+ `--print-to-pdf=${outputPath}`,
402
+ tempHtml,
403
+ ]);
404
+
405
+ if (result.exitCode !== 0) {
406
+ const stderr = result.stderr.toString();
407
+ throw new CliError('API_ERROR', `Chrome failed: ${stderr}`);
408
+ }
342
409
 
343
- await browser.close();
344
- console.log(`Exported to ${options.output}`);
410
+ console.log(`Exported to ${options.output}`);
411
+ } finally {
412
+ // Clean up temp file
413
+ await Bun.file(tempHtml).unlink();
414
+ }
345
415
  } catch (error) {
346
416
  handleError(error);
347
417
  }