@plosson/agentio 0.1.14 → 0.1.15

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.14",
3
+ "version": "0.1.15",
4
4
  "description": "CLI for LLM agents to interact with communication and tracking services",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -47,6 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "commander": "^14.0.2",
50
- "googleapis": "^169.0.0"
50
+ "googleapis": "^169.0.0",
51
+ "playwright-core": "^1.57.0"
51
52
  }
52
53
  }
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { basename, join } from 'path';
3
3
  import { google } from 'googleapis';
4
+ import { chromium } from 'playwright-core';
4
5
  import { getValidTokens, createGoogleAuth } from '../auth/token-manager';
5
6
  import { setCredentials, removeCredentials, getCredentials } from '../auth/token-store';
6
7
  import { setProfile, removeProfile, listProfiles } from '../config/config-manager';
@@ -11,6 +12,14 @@ import { CliError, handleError } from '../utils/errors';
11
12
  import { readStdin, resolveProfileName } from '../utils/stdin';
12
13
  import type { GmailAttachment } from '../types/gmail';
13
14
 
15
+ function escapeHtml(text: string): string {
16
+ return text
17
+ .replace(/&/g, '&')
18
+ .replace(/</g, '&lt;')
19
+ .replace(/>/g, '&gt;')
20
+ .replace(/"/g, '&quot;');
21
+ }
22
+
14
23
  async function getGmailClient(profileName?: string): Promise<{ client: GmailClient; profile: string }> {
15
24
  const { tokens, profile } = await getValidTokens('gmail', profileName);
16
25
  const auth = createGoogleAuth(tokens);
@@ -277,6 +286,65 @@ Query Syntax Examples:
277
286
  }
278
287
  });
279
288
 
289
+ gmail
290
+ .command('export <message-id>')
291
+ .description('Export a message as PDF')
292
+ .option('--profile <name>', 'Profile name')
293
+ .option('--output <path>', 'Output file path', 'message.pdf')
294
+ .action(async (messageId: string, options) => {
295
+ try {
296
+ const { client } = await getGmailClient(options.profile);
297
+ const message = await client.get(messageId, 'html');
298
+
299
+ // Build HTML document - inject header before body content
300
+ const emailHeader = `
301
+ <div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; padding: 16px 20px; margin-bottom: 16px; border-bottom: 1px solid #ddd; background: #f9f9f9;">
302
+ <div style="font-size: 1.3em; font-weight: 600; margin-bottom: 12px;">${escapeHtml(message.subject)}</div>
303
+ <div style="margin: 4px 0; font-size: 0.9em;"><strong>From:</strong> ${escapeHtml(message.from)}</div>
304
+ <div style="margin: 4px 0; font-size: 0.9em;"><strong>To:</strong> ${escapeHtml(message.to.join(', '))}</div>
305
+ <div style="margin: 4px 0; font-size: 0.9em;"><strong>Date:</strong> ${escapeHtml(message.date)}</div>
306
+ </div>`;
307
+
308
+ let html: string;
309
+ const body = message.body || '';
310
+
311
+ // Check if body is already a full HTML document
312
+ if (body.trim().toLowerCase().startsWith('<!doctype') || body.trim().toLowerCase().startsWith('<html')) {
313
+ // Inject header after <body> tag
314
+ html = body.replace(/<body[^>]*>/i, (match) => `${match}${emailHeader}`);
315
+ } else {
316
+ // Wrap fragment in minimal HTML
317
+ html = `<!DOCTYPE html>
318
+ <html>
319
+ <head><meta charset="utf-8"></head>
320
+ <body>
321
+ ${emailHeader}
322
+ <div style="padding: 0 20px;">${body}</div>
323
+ </body>
324
+ </html>`;
325
+ }
326
+
327
+ // Launch browser and generate PDF
328
+ console.error('Launching browser...');
329
+ const browser = await chromium.launch({
330
+ channel: 'chrome', // Use system Chrome
331
+ });
332
+
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
+ });
340
+
341
+ await browser.close();
342
+ console.log(`Exported to ${options.output}`);
343
+ } catch (error) {
344
+ handleError(error);
345
+ }
346
+ });
347
+
280
348
  // Profile management
281
349
  const profile = gmail
282
350
  .command('profile')