sessioncast-cli 2.2.2 → 2.3.1

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.
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CdpClient = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ const events_1 = require("events");
9
+ const debug_1 = require("./debug");
10
+ /**
11
+ * Lightweight Chrome DevTools Protocol client.
12
+ * Uses the existing `ws` package — no additional dependencies.
13
+ */
14
+ class CdpClient extends events_1.EventEmitter {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.ws = null;
18
+ this.nextId = 1;
19
+ this.callbacks = new Map();
20
+ this.connected = false;
21
+ }
22
+ /**
23
+ * Connect to a Chrome DevTools WebSocket URL.
24
+ * URL is obtained from Chrome's --remote-debugging-port output.
25
+ */
26
+ async connect(browserDebugUrl) {
27
+ return new Promise((resolve, reject) => {
28
+ this.ws = new ws_1.default(browserDebugUrl);
29
+ this.ws.on('open', () => {
30
+ this.connected = true;
31
+ (0, debug_1.debugLog)('CDP', 'Connected to', browserDebugUrl);
32
+ resolve();
33
+ });
34
+ this.ws.on('message', (data) => {
35
+ try {
36
+ const msg = JSON.parse(data.toString());
37
+ if (msg.id !== undefined) {
38
+ // Response to a command
39
+ const cb = this.callbacks.get(msg.id);
40
+ if (cb) {
41
+ this.callbacks.delete(msg.id);
42
+ if (msg.error) {
43
+ cb.reject(new Error(`CDP error: ${msg.error.message}`));
44
+ }
45
+ else {
46
+ cb.resolve(msg.result);
47
+ }
48
+ }
49
+ }
50
+ else if (msg.method) {
51
+ // Event notification
52
+ this.emit(msg.method, msg.params);
53
+ }
54
+ }
55
+ catch (e) {
56
+ (0, debug_1.debugLog)('CDP', 'Failed to parse message:', e.message);
57
+ }
58
+ });
59
+ this.ws.on('close', () => {
60
+ this.connected = false;
61
+ this.emit('close');
62
+ // Reject all pending callbacks
63
+ for (const [id, cb] of this.callbacks) {
64
+ cb.reject(new Error('CDP connection closed'));
65
+ this.callbacks.delete(id);
66
+ }
67
+ });
68
+ this.ws.on('error', (err) => {
69
+ if (!this.connected) {
70
+ reject(err);
71
+ }
72
+ this.emit('error', err);
73
+ });
74
+ });
75
+ }
76
+ /**
77
+ * Send a CDP command and wait for the response.
78
+ */
79
+ async send(method, params) {
80
+ if (!this.ws || !this.connected) {
81
+ throw new Error('CDP not connected');
82
+ }
83
+ const id = this.nextId++;
84
+ const message = { id, method };
85
+ if (params) {
86
+ message.params = params;
87
+ }
88
+ return new Promise((resolve, reject) => {
89
+ this.callbacks.set(id, { resolve, reject });
90
+ this.ws.send(JSON.stringify(message), (err) => {
91
+ if (err) {
92
+ this.callbacks.delete(id);
93
+ reject(err);
94
+ }
95
+ });
96
+ });
97
+ }
98
+ /**
99
+ * Check if connected.
100
+ */
101
+ isConnected() {
102
+ return this.connected;
103
+ }
104
+ /**
105
+ * Close the CDP connection.
106
+ */
107
+ close() {
108
+ if (this.ws) {
109
+ this.ws.close();
110
+ this.ws = null;
111
+ }
112
+ this.connected = false;
113
+ }
114
+ }
115
+ exports.CdpClient = CdpClient;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Find system Chrome/Chromium binary path.
3
+ * Returns null if no Chrome installation is found.
4
+ */
5
+ export declare function findChromePath(): string | null;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.findChromePath = findChromePath;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const os = __importStar(require("os"));
40
+ const child_process_1 = require("child_process");
41
+ /**
42
+ * Find system Chrome/Chromium binary path.
43
+ * Returns null if no Chrome installation is found.
44
+ */
45
+ function findChromePath() {
46
+ const platform = os.platform();
47
+ if (platform === 'darwin') {
48
+ const macPaths = [
49
+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
50
+ '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
51
+ '/Applications/Chromium.app/Contents/MacOS/Chromium',
52
+ path.join(os.homedir(), 'Applications/Google Chrome.app/Contents/MacOS/Google Chrome'),
53
+ ];
54
+ for (const p of macPaths) {
55
+ if (fs.existsSync(p))
56
+ return p;
57
+ }
58
+ }
59
+ else if (platform === 'linux') {
60
+ const linuxNames = [
61
+ 'google-chrome-stable',
62
+ 'google-chrome',
63
+ 'chromium-browser',
64
+ 'chromium',
65
+ ];
66
+ for (const name of linuxNames) {
67
+ try {
68
+ const result = (0, child_process_1.execSync)(`which ${name}`, { stdio: 'pipe' }).toString().trim();
69
+ if (result)
70
+ return result;
71
+ }
72
+ catch { /* not found */ }
73
+ }
74
+ // Common Linux paths
75
+ const linuxPaths = [
76
+ '/usr/bin/google-chrome-stable',
77
+ '/usr/bin/google-chrome',
78
+ '/usr/bin/chromium-browser',
79
+ '/usr/bin/chromium',
80
+ '/snap/bin/chromium',
81
+ ];
82
+ for (const p of linuxPaths) {
83
+ if (fs.existsSync(p))
84
+ return p;
85
+ }
86
+ }
87
+ else if (platform === 'win32') {
88
+ const winPaths = [
89
+ path.join(process.env['PROGRAMFILES'] || '', 'Google/Chrome/Application/chrome.exe'),
90
+ path.join(process.env['PROGRAMFILES(X86)'] || '', 'Google/Chrome/Application/chrome.exe'),
91
+ path.join(process.env['LOCALAPPDATA'] || '', 'Google/Chrome/Application/chrome.exe'),
92
+ path.join(process.env['PROGRAMFILES'] || '', 'Chromium/Application/chrome.exe'),
93
+ ];
94
+ for (const p of winPaths) {
95
+ if (p && fs.existsSync(p))
96
+ return p;
97
+ }
98
+ }
99
+ return null;
100
+ }
@@ -0,0 +1,2 @@
1
+ export declare function encrypt(data: Buffer, key: Buffer): Buffer;
2
+ export declare function decrypt(data: Buffer, key: Buffer): Buffer;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encrypt = encrypt;
4
+ exports.decrypt = decrypt;
5
+ const crypto_1 = require("crypto");
6
+ const ALGO = 'aes-256-gcm';
7
+ const IV_LEN = 12;
8
+ const TAG_LEN = 16;
9
+ function encrypt(data, key) {
10
+ const iv = (0, crypto_1.randomBytes)(IV_LEN);
11
+ const cipher = (0, crypto_1.createCipheriv)(ALGO, key, iv);
12
+ const encrypted = Buffer.concat([cipher.update(data), cipher.final()]);
13
+ const tag = cipher.getAuthTag();
14
+ // Format: [iv(12) | tag(16) | ciphertext]
15
+ return Buffer.concat([iv, tag, encrypted]);
16
+ }
17
+ function decrypt(data, key) {
18
+ const iv = data.subarray(0, IV_LEN);
19
+ const tag = data.subarray(IV_LEN, IV_LEN + TAG_LEN);
20
+ const ciphertext = data.subarray(IV_LEN + TAG_LEN);
21
+ const decipher = (0, crypto_1.createDecipheriv)(ALGO, key, iv);
22
+ decipher.setAuthTag(tag);
23
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
24
+ }
@@ -1,12 +1,25 @@
1
1
  import { LlmConfig, LlmMessage, LlmResponse } from './types';
2
+ export type StreamChunk = {
3
+ content: string;
4
+ done: boolean;
5
+ };
2
6
  export declare class LlmService {
3
7
  private config;
4
8
  constructor(config?: LlmConfig);
5
9
  chat(model?: string, messages?: LlmMessage[], temperature?: number, maxTokens?: number, stream?: boolean): Promise<LlmResponse>;
10
+ chatStream(model?: string, messages?: LlmMessage[], temperature?: number, maxTokens?: number, onChunk?: (chunk: StreamChunk) => void): Promise<LlmResponse>;
6
11
  private callOllama;
7
12
  private convertOllamaToOpenAiFormat;
8
13
  private callOpenAi;
9
14
  private callAnthropic;
10
15
  private callClaudeCode;
16
+ private callCodex;
17
+ private callGemini;
18
+ private convertGeminiToOpenAiFormat;
19
+ private callCursor;
20
+ private callClaudeCodeStream;
21
+ private callOllamaStream;
22
+ private callOpenAiStream;
23
+ private callAnthropicStream;
11
24
  private convertAnthropicToOpenAiFormat;
12
25
  }