@plosson/agentio 0.1.15 → 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.15",
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,7 +1,7 @@
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
- import { chromium } from 'playwright-core';
5
5
  import { getValidTokens, createGoogleAuth } from '../auth/token-manager';
6
6
  import { setCredentials, removeCredentials, getCredentials } from '../auth/token-store';
7
7
  import { setProfile, removeProfile, listProfiles } from '../config/config-manager';
@@ -20,6 +20,53 @@ function escapeHtml(text: string): string {
20
20
  .replace(/"/g, '"');
21
21
  }
22
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
+
23
70
  async function getGmailClient(profileName?: string): Promise<{ client: GmailClient; profile: string }> {
24
71
  const { tokens, profile } = await getValidTokens('gmail', profileName);
25
72
  const auth = createGoogleAuth(tokens);
@@ -324,22 +371,47 @@ ${emailHeader}
324
371
  </html>`;
325
372
  }
326
373
 
327
- // Launch browser and generate PDF
328
- console.error('Launching browser...');
329
- const browser = await chromium.launch({
330
- channel: 'chrome', // Use system Chrome
331
- });
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
+ }
332
383
 
333
- const page = await browser.newPage();
334
- await page.setContent(html, { waitUntil: 'networkidle' });
335
- await page.pdf({
336
- path: options.output,
337
- format: 'A4',
338
- margin: { top: '1cm', right: '1cm', bottom: '1cm', left: '1cm' },
339
- });
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
+ }
340
409
 
341
- await browser.close();
342
- 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
+ }
343
415
  } catch (error) {
344
416
  handleError(error);
345
417
  }