dino-browser 0.0.0-stage → 0.51.0

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/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # Dino Browser (`dino-browser`)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Official TypeScript/JavaScript SDK and CLI for [Dino](https://github.com/tarunbtw/dino) — the ultra-light native macOS WebKit browser engine built for AI agents.
4
+
5
+
6
+ - **Auto-Download Engine**: Works out-of-the-box via `npx dino-browser` or `import { Dino } from 'dino-browser'`. Automatically finds `/Applications/Dino.app` or downloads the native engine from GitHub Releases into `~/.dino/bin/dino`.
7
+ - **Token-Optimized Perception**: Compact accessibility tree (`dino snap -v`), DOM diffs (sub-50 tokens), and vision Set-of-Marks badges.
8
+ - **Native Hardware Input**: Direct AppKit & CGEvent keyboard/mouse synthesis.
9
+
10
+ ---
11
+
12
+ ## CLI Usage (Zero Install via npx)
13
+
14
+ ```bash
15
+ # Navigate to a URL
16
+ npx dino-browser goto https://github.com/tarunbtw/dino
17
+
18
+ # Token-optimized perception (~400 tokens)
19
+ npx dino-browser snap -v
20
+
21
+ # Click or type by deterministic element ID
22
+ npx dino-browser click e2
23
+ npx dino-browser type e3 "Hello world" --submit
24
+
25
+ # Capture vision-grounded screenshot with element badges
26
+ npx dino-browser shot page.png -l --crop
27
+
28
+ # Explicitly download or update native engine
29
+ npx dino-browser install
30
+ ```
31
+
32
+ ---
33
+
34
+ ## SDK Usage
35
+
36
+ ```bash
37
+ npm install dino-browser
38
+ ```
39
+
40
+ ```typescript
41
+ import { Dino } from 'dino-browser';
42
+
43
+ // Auto-connect to running Dino GUI or launch an isolated background headless worker
44
+ const dino = await Dino.launch({ profile: 'agent' });
45
+
46
+ // 1. Navigate
47
+ await dino.goto('https://html.duckduckgo.com/html/');
48
+
49
+ // 2. Token-Optimized Viewport Perception (~400 tokens)
50
+ const tree = await dino.snapshot({ viewportOnly: true, coords: true });
51
+ console.log(tree);
52
+
53
+ // 3. Native & Dynamic Interactions
54
+ await dino.type('e2', 'Apple Silicon M4 Max', { submit: true });
55
+ await dino.wait();
56
+
57
+ // 4. Differential Perception (Sub-50 tokens for sequential turns!)
58
+ const diff = await dino.diff();
59
+ console.log(`DOM Mutations: +${diff.addedCount}, Tokens: ${diff.tokenEstimate}`);
60
+
61
+ // 5. Parameterized Playbooks (0 LLM tokens!)
62
+ await dino.playbook.run('search_flow', { query: 'Apple Silicon' });
63
+
64
+ // 6. Network Interception
65
+ await dino.route.block('*://*.doubleclick.net/**');
66
+ await dino.route.mock('*/api/user', { name: 'Alice', tier: 'pro' });
67
+ ```
68
+
69
+ ---
70
+
71
+ ## License
72
+
73
+ MIT © [Tarun](https://github.com/tarunbtw)
package/bin/dino.js ADDED
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Dino Browser CLI Wrapper
5
+ * Resolves local Dino.app installation, global binary, ~/.dino/bin/dino,
6
+ * or auto-downloads the native macOS engine from GitHub Releases.
7
+ */
8
+
9
+ const { spawn, execSync } = require('child_process');
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+ const os = require('os');
13
+
14
+ const DINO_VERSION = '0.51';
15
+ const GITHUB_REPO = 'tarunbtw/dino';
16
+
17
+ function downloadBinary(targetPath) {
18
+ if (os.platform() !== 'darwin') {
19
+ console.error('\x1b[31m[dino]\x1b[0m Dino is an ultra-light native macOS WebKit browser engine and requires macOS.');
20
+ process.exit(1);
21
+ }
22
+
23
+ const url = `https://github.com/${GITHUB_REPO}/releases/download/v${DINO_VERSION}/Dino-${DINO_VERSION}.zip`;
24
+ console.log(`\x1b[36m[dino]\x1b[0m Downloading native macOS engine (v${DINO_VERSION})...`);
25
+
26
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dino-download-'));
27
+ const zipPath = path.join(tmpDir, `Dino-${DINO_VERSION}.zip`);
28
+ const extractDir = path.join(tmpDir, 'extracted');
29
+
30
+ try {
31
+ execSync(`curl -fsSL "${url}" -o "${zipPath}"`, { stdio: 'inherit' });
32
+ fs.mkdirSync(extractDir, { recursive: true });
33
+ execSync(`ditto -x -k "${zipPath}" "${extractDir}"`, { stdio: 'ignore' });
34
+
35
+ let binary = path.join(extractDir, 'Dino.app', 'Contents', 'MacOS', 'dino');
36
+ if (!fs.existsSync(binary)) {
37
+ binary = path.join(extractDir, 'Dino.app', 'Contents', 'MacOS', 'Dino');
38
+ }
39
+
40
+ if (!fs.existsSync(binary)) {
41
+ throw new Error('Dino binary not found inside release archive.');
42
+ }
43
+
44
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true, mode: 0o755 });
45
+ fs.copyFileSync(binary, targetPath);
46
+ fs.chmodSync(targetPath, 0o755);
47
+ console.log(`\x1b[32m[dino]\x1b[0m Native engine installed successfully to ${targetPath}`);
48
+ return targetPath;
49
+ } catch (err) {
50
+ console.error(`\x1b[31m[dino]\x1b[0m Failed to download binary: ${err.message}`);
51
+ process.exit(1);
52
+ } finally {
53
+ try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch {}
54
+ }
55
+ }
56
+
57
+ function resolveBinary(autoDownload = true) {
58
+ // 1. Check custom environment variable
59
+ if (process.env.DINO_BIN && fs.existsSync(process.env.DINO_BIN)) {
60
+ return process.env.DINO_BIN;
61
+ }
62
+
63
+ // 2. Check /Applications/Dino.app
64
+ const appPath = '/Applications/Dino.app/Contents/MacOS/dino';
65
+ if (fs.existsSync(appPath)) {
66
+ return appPath;
67
+ }
68
+
69
+ // 3. Check ~/.dino/bin/dino
70
+ const userBin = path.join(os.homedir(), '.dino', 'bin', 'dino');
71
+ if (fs.existsSync(userBin)) {
72
+ return userBin;
73
+ }
74
+
75
+ // 4. Check PATH via 'which dino'
76
+ try {
77
+ const p = execSync('which dino 2>/dev/null', { encoding: 'utf8' }).trim();
78
+ if (p && fs.existsSync(p)) {
79
+ return p;
80
+ }
81
+ } catch {}
82
+
83
+ // 5. Tier 3: Auto-download fallback
84
+ if (autoDownload) {
85
+ return downloadBinary(userBin);
86
+ }
87
+
88
+ return null;
89
+ }
90
+
91
+ const args = process.argv.slice(2);
92
+
93
+ // Explicit install trigger: "npx dino install"
94
+ if (args[0] === 'install') {
95
+ const userBin = path.join(os.homedir(), '.dino', 'bin', 'dino');
96
+ downloadBinary(userBin);
97
+ process.exit(0);
98
+ }
99
+
100
+ const binary = resolveBinary(true);
101
+
102
+ const child = spawn(binary, args, {
103
+ stdio: 'inherit',
104
+ env: process.env
105
+ });
106
+
107
+ child.on('exit', (code, signal) => {
108
+ if (signal) {
109
+ process.kill(process.pid, signal);
110
+ } else {
111
+ process.exit(code ?? 0);
112
+ }
113
+ });
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Dino Browser TypeScript SDK (v0.41.0)
3
+ * Ultra-light native macOS agentic browser driver, token-optimized perception, and Unix socket bridge.
4
+ */
5
+ export interface DinoOptions {
6
+ port?: number;
7
+ host?: string;
8
+ socketPath?: string;
9
+ token?: string;
10
+ }
11
+ export interface SnapshotOptions {
12
+ mode?: 'text' | 'json';
13
+ limit?: number;
14
+ offset?: number;
15
+ viewportOnly?: boolean;
16
+ coords?: boolean;
17
+ includeCoords?: boolean;
18
+ target?: string;
19
+ role?: string;
20
+ text?: string;
21
+ depth?: number;
22
+ }
23
+ export interface ActionOptions {
24
+ target?: string;
25
+ native?: boolean;
26
+ submit?: boolean;
27
+ clear?: boolean;
28
+ wait?: boolean;
29
+ modifiers?: string[];
30
+ tabId?: string;
31
+ }
32
+ export interface ScreenshotOptions {
33
+ file?: string;
34
+ labeled?: boolean;
35
+ crop?: boolean;
36
+ clip?: {
37
+ x: number;
38
+ y: number;
39
+ width: number;
40
+ height: number;
41
+ };
42
+ elementId?: string;
43
+ tabId?: string;
44
+ }
45
+ export interface LaunchOptions {
46
+ headless?: boolean;
47
+ profile?: string;
48
+ idleTimeout?: number;
49
+ port?: number;
50
+ binPath?: string;
51
+ args?: string[];
52
+ }
53
+ export interface WaitOptions {
54
+ mode?: 'auto' | 'stability' | 'selector' | 'networkidle' | 'url';
55
+ selector?: string;
56
+ timeout?: number;
57
+ duration?: number;
58
+ text?: string;
59
+ tabId?: string;
60
+ }
61
+ export declare class Dino {
62
+ readonly port: number;
63
+ readonly host: string;
64
+ readonly socketPath?: string;
65
+ readonly token: string;
66
+ constructor(options?: DinoOptions);
67
+ static loadToken(): string;
68
+ static resolveSocketPath(profile?: string): string | undefined;
69
+ static resolveBinary(autoDownload?: boolean): string | null;
70
+ static waitForSocket(profile?: string, timeoutMs?: number): Promise<string>;
71
+ /**
72
+ * Spawns an isolated background Dino engine and returns a connected Dino client instance.
73
+ */
74
+ static launch(options?: LaunchOptions): Promise<Dino>;
75
+ private request;
76
+ status(): Promise<any>;
77
+ tabs(): Promise<any[]>;
78
+ newTab(url?: string, options?: {
79
+ isGhost?: boolean;
80
+ select?: boolean;
81
+ }): Promise<any>;
82
+ switchTab(tabIdOrIndex: string | number): Promise<any>;
83
+ closeTab(tabIdOrIndex?: string | number): Promise<any>;
84
+ goto(url: string, options?: {
85
+ allowLocalFiles?: boolean;
86
+ }): Promise<any>;
87
+ back(): Promise<any>;
88
+ forward(): Promise<any>;
89
+ reload(): Promise<any>;
90
+ snapshot(options?: SnapshotOptions): Promise<any>;
91
+ diff(tabId?: string): Promise<any>;
92
+ find(query: {
93
+ role?: string;
94
+ text?: string;
95
+ selector?: string;
96
+ viewportOnly?: boolean;
97
+ }): Promise<any>;
98
+ click(target: string, options?: ActionOptions): Promise<any>;
99
+ dblclick(target: string, options?: ActionOptions): Promise<any>;
100
+ type(target: string, text: string, options?: ActionOptions): Promise<any>;
101
+ press(key: string, options?: {
102
+ modifiers?: string[];
103
+ tabId?: string;
104
+ }): Promise<any>;
105
+ scroll(direction?: 'up' | 'down' | 'left' | 'right', amount?: number, options?: {
106
+ native?: boolean;
107
+ tabId?: string;
108
+ }): Promise<any>;
109
+ drag(from: string, to: string, options?: {
110
+ native?: boolean;
111
+ tabId?: string;
112
+ }): Promise<any>;
113
+ hover(target: string, options?: {
114
+ tabId?: string;
115
+ }): Promise<any>;
116
+ wait(options?: WaitOptions): Promise<any>;
117
+ evaluate(expression: string, options?: {
118
+ world?: 'isolated' | 'page';
119
+ tabId?: string;
120
+ }): Promise<any>;
121
+ screenshot(options?: ScreenshotOptions): Promise<Buffer>;
122
+ readonly playbook: {
123
+ record: (name: string) => Promise<any>;
124
+ stop: () => Promise<any>;
125
+ run: (name: string, variables?: Record<string, string>) => Promise<any>;
126
+ list: () => Promise<any>;
127
+ export: (name: string) => Promise<any>;
128
+ delete: (name: string) => Promise<any>;
129
+ };
130
+ readonly route: {
131
+ block: (pattern: string) => Promise<any>;
132
+ mock: (pattern: string, body: any, status?: number, headers?: Record<string, string>) => Promise<any>;
133
+ list: () => Promise<any>;
134
+ clear: () => Promise<any>;
135
+ };
136
+ readonly hitl: {
137
+ status: () => Promise<any>;
138
+ resolve: () => Promise<any>;
139
+ };
140
+ }
141
+ export declare const dino: Dino;
142
+ export default Dino;
package/dist/index.js ADDED
@@ -0,0 +1,474 @@
1
+ "use strict";
2
+ /**
3
+ * Dino Browser TypeScript SDK (v0.41.0)
4
+ * Ultra-light native macOS agentic browser driver, token-optimized perception, and Unix socket bridge.
5
+ */
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.dino = exports.Dino = void 0;
41
+ const http = __importStar(require("http"));
42
+ const fs = __importStar(require("fs"));
43
+ const path = __importStar(require("path"));
44
+ const os = __importStar(require("os"));
45
+ class Dino {
46
+ port;
47
+ host;
48
+ socketPath;
49
+ token;
50
+ constructor(options = {}) {
51
+ if (os.platform() !== 'darwin') {
52
+ console.warn('Dino is a native Apple Silicon browser engine and runs on macOS.');
53
+ }
54
+ this.port = options.port ?? 9222;
55
+ this.host = options.host ?? '127.0.0.1';
56
+ this.socketPath = options.socketPath ?? Dino.resolveSocketPath();
57
+ this.token = options.token ?? Dino.loadToken();
58
+ }
59
+ static loadToken() {
60
+ if (process.env.DINO_TOKEN)
61
+ return process.env.DINO_TOKEN.trim();
62
+ const dinoTokenFile = path.join(os.homedir(), '.dino', 'agent-token');
63
+ try {
64
+ if (fs.existsSync(dinoTokenFile)) {
65
+ return fs.readFileSync(dinoTokenFile, 'utf8').trim();
66
+ }
67
+ }
68
+ catch {
69
+ // fallback
70
+ }
71
+ return '';
72
+ }
73
+ static resolveSocketPath(profile) {
74
+ const dinoDir = path.join(os.homedir(), '.dino');
75
+ const workersDir = path.join(dinoDir, 'workers');
76
+ // 1. If profile specified, search worker descriptors
77
+ if (profile && fs.existsSync(workersDir)) {
78
+ try {
79
+ const files = fs.readdirSync(workersDir);
80
+ for (const file of files) {
81
+ if (file.startsWith('worker-') && file.endsWith('.json')) {
82
+ const raw = fs.readFileSync(path.join(workersDir, file), 'utf8');
83
+ const data = JSON.parse(raw);
84
+ if (data.profile === profile && fs.existsSync(data.socketPath)) {
85
+ return data.socketPath;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ catch { }
91
+ }
92
+ // 2. Default socket ~/.dino/dino.sock
93
+ const defaultSock = path.join(dinoDir, 'dino.sock');
94
+ if (fs.existsSync(defaultSock))
95
+ return defaultSock;
96
+ // 3. Fallback to any active worker socket
97
+ if (fs.existsSync(workersDir)) {
98
+ try {
99
+ const files = fs.readdirSync(workersDir);
100
+ const sock = files.find((f) => f.endsWith('.sock'));
101
+ if (sock)
102
+ return path.join(workersDir, sock);
103
+ }
104
+ catch { }
105
+ }
106
+ return undefined;
107
+ }
108
+ static resolveBinary(autoDownload = true) {
109
+ if (process.env.DINO_BIN && fs.existsSync(process.env.DINO_BIN)) {
110
+ return process.env.DINO_BIN;
111
+ }
112
+ const appPath = '/Applications/Dino.app/Contents/MacOS/dino';
113
+ if (fs.existsSync(appPath))
114
+ return appPath;
115
+ const userBin = path.join(os.homedir(), '.dino', 'bin', 'dino');
116
+ if (fs.existsSync(userBin))
117
+ return userBin;
118
+ try {
119
+ const { execSync } = require('child_process');
120
+ const p = execSync('which dino 2>/dev/null', { encoding: 'utf8' }).trim();
121
+ if (p && fs.existsSync(p))
122
+ return p;
123
+ }
124
+ catch { }
125
+ if (autoDownload && os.platform() === 'darwin') {
126
+ const { execSync } = require('child_process');
127
+ const version = '0.42';
128
+ const url = `https://github.com/tarunbtw/dino/releases/download/v${version}/Dino-${version}.zip`;
129
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dino-dl-'));
130
+ const zipPath = path.join(tmpDir, `Dino-${version}.zip`);
131
+ const extDir = path.join(tmpDir, 'ext');
132
+ try {
133
+ execSync(`curl -fsSL "${url}" -o "${zipPath}"`, { stdio: 'ignore' });
134
+ fs.mkdirSync(extDir, { recursive: true });
135
+ execSync(`ditto -x -k "${zipPath}" "${extDir}"`, { stdio: 'ignore' });
136
+ let bin = path.join(extDir, 'Dino.app', 'Contents', 'MacOS', 'dino');
137
+ if (!fs.existsSync(bin))
138
+ bin = path.join(extDir, 'Dino.app', 'Contents', 'MacOS', 'Dino');
139
+ if (fs.existsSync(bin)) {
140
+ fs.mkdirSync(path.dirname(userBin), { recursive: true, mode: 0o755 });
141
+ fs.copyFileSync(bin, userBin);
142
+ fs.chmodSync(userBin, 0o755);
143
+ return userBin;
144
+ }
145
+ }
146
+ catch { }
147
+ finally {
148
+ try {
149
+ fs.rmSync(tmpDir, { recursive: true, force: true });
150
+ }
151
+ catch { }
152
+ }
153
+ }
154
+ return null;
155
+ }
156
+ static async waitForSocket(profile, timeoutMs = 3000) {
157
+ const start = Date.now();
158
+ while (Date.now() - start < timeoutMs) {
159
+ const sock = Dino.resolveSocketPath(profile);
160
+ if (sock && fs.existsSync(sock))
161
+ return sock;
162
+ await new Promise(r => setTimeout(r, 50));
163
+ }
164
+ throw new Error(`Dino socket not found after ${timeoutMs}ms. Ensure engine is running.`);
165
+ }
166
+ /**
167
+ * Spawns an isolated background Dino engine and returns a connected Dino client instance.
168
+ */
169
+ static async launch(options = {}) {
170
+ const headless = options.headless ?? true;
171
+ const profile = options.profile ?? 'agent';
172
+ const idleTimeout = options.idleTimeout ?? 60;
173
+ const binary = options.binPath ?? Dino.resolveBinary(true);
174
+ if (!binary) {
175
+ throw new Error('Dino binary not found. Run "npx dino-browser install" or install /Applications/Dino.app');
176
+ }
177
+ const spawnArgs = [...(options.args || [])];
178
+ if (headless && !spawnArgs.includes('--headless'))
179
+ spawnArgs.push('--headless');
180
+ if (!spawnArgs.includes('--profile'))
181
+ spawnArgs.push('--profile', profile);
182
+ if (!spawnArgs.includes('--idle-timeout'))
183
+ spawnArgs.push('--idle-timeout', String(idleTimeout));
184
+ if (options.port)
185
+ spawnArgs.push('--port', String(options.port));
186
+ const { spawn } = require('child_process');
187
+ const child = spawn(binary, spawnArgs, {
188
+ detached: true,
189
+ stdio: 'ignore',
190
+ env: process.env
191
+ });
192
+ child.unref();
193
+ const socketPath = await Dino.waitForSocket(profile, 4000);
194
+ return new Dino({ socketPath, port: options.port });
195
+ }
196
+ request(method, endpoint, body, timeoutMs = 30000) {
197
+ return new Promise((resolve, reject) => {
198
+ const payload = body ? JSON.stringify(body) : undefined;
199
+ const headers = {
200
+ 'Content-Type': 'application/json'
201
+ };
202
+ if (this.token) {
203
+ headers['Authorization'] = `Bearer ${this.token}`;
204
+ }
205
+ if (payload) {
206
+ headers['Content-Length'] = Buffer.byteLength(payload);
207
+ }
208
+ const reqOptions = {
209
+ method,
210
+ headers,
211
+ timeout: timeoutMs
212
+ };
213
+ if (this.socketPath && fs.existsSync(this.socketPath)) {
214
+ reqOptions.socketPath = this.socketPath;
215
+ reqOptions.path = endpoint;
216
+ }
217
+ else {
218
+ reqOptions.host = this.host;
219
+ reqOptions.port = this.port;
220
+ reqOptions.path = endpoint;
221
+ }
222
+ const req = http.request(reqOptions, (res) => {
223
+ const chunks = [];
224
+ res.on('data', chunk => chunks.push(chunk));
225
+ res.on('end', () => {
226
+ const raw = Buffer.concat(chunks).toString('utf8');
227
+ if (res.statusCode && res.statusCode >= 400) {
228
+ return reject(new Error(`Dino HTTP ${res.statusCode}: ${raw}`));
229
+ }
230
+ try {
231
+ const parsed = JSON.parse(raw);
232
+ resolve(parsed);
233
+ }
234
+ catch {
235
+ resolve(raw);
236
+ }
237
+ });
238
+ });
239
+ req.on('timeout', () => {
240
+ req.destroy();
241
+ reject(new Error(`Dino request timed out after ${timeoutMs}ms`));
242
+ });
243
+ req.on('error', (err) => reject(err));
244
+ if (payload) {
245
+ req.write(payload);
246
+ }
247
+ req.end();
248
+ });
249
+ }
250
+ // --- Status & Tabs ---
251
+ async status() {
252
+ return this.request('GET', '/status');
253
+ }
254
+ async tabs() {
255
+ const res = await this.request('GET', '/tabs');
256
+ return res.tabs || [];
257
+ }
258
+ async newTab(url, options = {}) {
259
+ return this.request('POST', '/tabs/new', {
260
+ url: url || '',
261
+ isGhost: options.isGhost ?? false,
262
+ select: options.select ?? true
263
+ });
264
+ }
265
+ async switchTab(tabIdOrIndex) {
266
+ const body = typeof tabIdOrIndex === 'number' ? { index: tabIdOrIndex } : { tabId: tabIdOrIndex };
267
+ return this.request('POST', '/tabs/switch', body);
268
+ }
269
+ async closeTab(tabIdOrIndex) {
270
+ const body = typeof tabIdOrIndex === 'number' ? { index: tabIdOrIndex } : (tabIdOrIndex ? { tabId: tabIdOrIndex } : {});
271
+ return this.request('POST', '/tabs/close', body);
272
+ }
273
+ // --- Navigation ---
274
+ async goto(url, options = {}) {
275
+ return this.request('POST', '/navigate', {
276
+ action: 'url',
277
+ url,
278
+ allowLocalFiles: options.allowLocalFiles ?? false
279
+ });
280
+ }
281
+ async back() {
282
+ return this.request('POST', '/navigate', { action: 'back' });
283
+ }
284
+ async forward() {
285
+ return this.request('POST', '/navigate', { action: 'forward' });
286
+ }
287
+ async reload() {
288
+ return this.request('POST', '/navigate', { action: 'reload' });
289
+ }
290
+ // --- Perception & Inspection ---
291
+ async snapshot(options = {}) {
292
+ const params = new URLSearchParams();
293
+ if (options.mode)
294
+ params.append('mode', options.mode);
295
+ if (options.limit !== undefined)
296
+ params.append('limit', String(options.limit));
297
+ if (options.offset !== undefined)
298
+ params.append('offset', String(options.offset));
299
+ if (options.viewportOnly)
300
+ params.append('viewportOnly', 'true');
301
+ if (options.target)
302
+ params.append('target', options.target);
303
+ if (options.role)
304
+ params.append('role', options.role);
305
+ if (options.text)
306
+ params.append('text', options.text);
307
+ if (options.depth !== undefined)
308
+ params.append('depth', String(options.depth));
309
+ const qs = params.toString();
310
+ return this.request('GET', qs ? `/snapshot?${qs}` : '/snapshot');
311
+ }
312
+ async diff(tabId) {
313
+ const endpoint = tabId ? `/diff?tabId=${encodeURIComponent(tabId)}` : '/diff';
314
+ return this.request('GET', endpoint);
315
+ }
316
+ async find(query) {
317
+ const params = new URLSearchParams();
318
+ if (query.role)
319
+ params.append('role', query.role);
320
+ if (query.text)
321
+ params.append('text', query.text);
322
+ if (query.selector)
323
+ params.append('selector', query.selector);
324
+ if (query.viewportOnly)
325
+ params.append('viewportOnly', 'true');
326
+ return this.request('GET', `/find?${params.toString()}`);
327
+ }
328
+ // --- Atomic Actions ---
329
+ async click(target, options = {}) {
330
+ return this.request('POST', '/action', {
331
+ action: 'click',
332
+ target,
333
+ native: options.native ?? false,
334
+ tabId: options.tabId
335
+ });
336
+ }
337
+ async dblclick(target, options = {}) {
338
+ return this.request('POST', '/action', {
339
+ action: 'dblclick',
340
+ target,
341
+ native: options.native ?? false,
342
+ tabId: options.tabId
343
+ });
344
+ }
345
+ async type(target, text, options = {}) {
346
+ return this.request('POST', '/action', {
347
+ action: 'type',
348
+ target,
349
+ text,
350
+ submit: options.submit ?? false,
351
+ clear: options.clear ?? false,
352
+ native: options.native ?? false,
353
+ tabId: options.tabId
354
+ });
355
+ }
356
+ async press(key, options = {}) {
357
+ return this.request('POST', '/action', {
358
+ action: 'press',
359
+ key,
360
+ modifiers: options.modifiers,
361
+ tabId: options.tabId
362
+ });
363
+ }
364
+ async scroll(direction = 'down', amount = 300, options = {}) {
365
+ return this.request('POST', '/action', {
366
+ action: 'scroll',
367
+ direction,
368
+ amount,
369
+ native: options.native ?? false,
370
+ tabId: options.tabId
371
+ });
372
+ }
373
+ async drag(from, to, options = {}) {
374
+ return this.request('POST', '/action', {
375
+ action: 'drag',
376
+ target: from,
377
+ toTarget: to,
378
+ native: options.native ?? true,
379
+ tabId: options.tabId
380
+ });
381
+ }
382
+ async hover(target, options = {}) {
383
+ return this.request('POST', '/action', {
384
+ action: 'hover',
385
+ target,
386
+ tabId: options.tabId
387
+ });
388
+ }
389
+ async wait(options = {}) {
390
+ return this.request('POST', '/wait', {
391
+ mode: options.mode || 'auto',
392
+ selector: options.selector,
393
+ timeout: options.timeout,
394
+ duration: options.duration,
395
+ text: options.text,
396
+ tabId: options.tabId
397
+ });
398
+ }
399
+ async evaluate(expression, options = {}) {
400
+ const res = await this.request('POST', '/evaluate', {
401
+ expression,
402
+ world: options.world || 'isolated',
403
+ tabId: options.tabId
404
+ });
405
+ return res.result;
406
+ }
407
+ // --- Vision & Screenshots ---
408
+ async screenshot(options = {}) {
409
+ const params = new URLSearchParams();
410
+ if (options.labeled)
411
+ params.append('labeled', 'true');
412
+ if (options.crop)
413
+ params.append('somCrop', 'true');
414
+ if (options.elementId)
415
+ params.append('elementId', options.elementId);
416
+ if (options.clip) {
417
+ params.append('clip', `${options.clip.x},${options.clip.y},${options.clip.width},${options.clip.height}`);
418
+ }
419
+ if (options.tabId)
420
+ params.append('tabId', options.tabId);
421
+ const qs = params.toString();
422
+ const endpoint = qs ? `/screenshot?${qs}` : '/screenshot';
423
+ return new Promise((resolve, reject) => {
424
+ const reqOptions = {
425
+ method: 'GET',
426
+ headers: this.token ? { 'Authorization': `Bearer ${this.token}` } : {}
427
+ };
428
+ if (this.socketPath && fs.existsSync(this.socketPath)) {
429
+ reqOptions.socketPath = this.socketPath;
430
+ reqOptions.path = endpoint;
431
+ }
432
+ else {
433
+ reqOptions.host = this.host;
434
+ reqOptions.port = this.port;
435
+ reqOptions.path = endpoint;
436
+ }
437
+ const req = http.request(reqOptions, (res) => {
438
+ const chunks = [];
439
+ res.on('data', chunk => chunks.push(chunk));
440
+ res.on('end', () => {
441
+ const buf = Buffer.concat(chunks);
442
+ if (options.file) {
443
+ fs.writeFileSync(options.file, buf);
444
+ }
445
+ resolve(buf);
446
+ });
447
+ });
448
+ req.on('error', reject);
449
+ req.end();
450
+ });
451
+ }
452
+ // --- Subsystems ---
453
+ playbook = {
454
+ record: (name) => this.request('POST', '/playbook/record', { name }),
455
+ stop: () => this.request('POST', '/playbook/stop'),
456
+ run: (name, variables = {}) => this.request('POST', '/playbook/replay', { name, variables }),
457
+ list: () => this.request('GET', '/playbook/list'),
458
+ export: (name) => this.request('GET', `/playbook/export?name=${encodeURIComponent(name)}`),
459
+ delete: (name) => this.request('DELETE', `/playbook?name=${encodeURIComponent(name)}`)
460
+ };
461
+ route = {
462
+ block: (pattern) => this.request('POST', '/route', { pattern, action: 'abort' }),
463
+ mock: (pattern, body, status = 200, headers) => this.request('POST', '/route', { pattern, action: 'mock', body, status, headers }),
464
+ list: () => this.request('GET', '/route/list'),
465
+ clear: () => this.request('DELETE', '/route')
466
+ };
467
+ hitl = {
468
+ status: () => this.request('GET', '/hitl/status'),
469
+ resolve: () => this.request('POST', '/hitl/resolve')
470
+ };
471
+ }
472
+ exports.Dino = Dino;
473
+ exports.dino = new Dino();
474
+ exports.default = Dino;
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "dino-browser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.51.0",
4
+ "description": "Official TypeScript/JavaScript SDK for Dino - the ultra-light native macOS agentic browser engine",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "dino": "bin/dino.js",
9
+ "dino-browser": "bin/dino.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "bin",
14
+ "README.md"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "prepare": "tsc"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/tarunbtw/dino.git"
23
+ },
24
+ "homepage": "https://github.com/tarunbtw/dino#readme",
25
+ "keywords": [
26
+ "dino",
27
+ "dino-browser",
28
+ "browser",
29
+ "agent",
30
+ "agentic",
31
+ "macos",
32
+ "webkit",
33
+ "playwright",
34
+ "puppeteer",
35
+ "ai"
36
+ ],
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@types/node": "^26.6.6"
40
+ }
41
+ }