notte-sdk 0.0.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.
package/README.md ADDED
@@ -0,0 +1,632 @@
1
+ # notte-sdk
2
+
3
+ > TypeScript SDK for Notte - Cloud-hosted browser sessions with LLM-powered web agents
4
+
5
+ The official TypeScript SDK for Notte API, providing cloud-hosted browser sessions with precise control, LLM-powered web agents for automated tasks, serverless functions, and secure credential management.
6
+
7
+ ## Features
8
+
9
+ - 🌐 **Cloud Browser Sessions** - Access remote browsers with full control
10
+ - 🤖 **LLM-Powered Agents** - Intelligent web automation with natural language
11
+ - 🔒 **Secret Vaults** - Enterprise-grade credential management with end-to-end encryption
12
+ - 👤 **Digital Personas** - Complete identities with email, SMS, and 2FA for automated account creation
13
+ - 🎯 **Session Management** - Context managers for reliable resource cleanup
14
+ - 📡 **Real-time Updates** - WebSocket support for live agent monitoring
15
+ - 📝 **Type Safety** - Full TypeScript support with generated types
16
+ - ⚡ **Serverless Functions** - Run pre-built automation workflows with simple API calls
17
+ - 🔄 **Auto-sync** - Generated from OpenAPI spec, always up-to-date
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ npm install notte-sdk
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### Basic Session Usage
28
+
29
+ ```typescript
30
+ import { NotteClient } from 'notte-sdk';
31
+
32
+ const notte = new NotteClient({
33
+ apiKey: 'your-api-key', // pragma: allowlist secret
34
+ baseUrl: 'https://api.notte.cc' // optional, defaults to https://api.notte.cc
35
+ });
36
+
37
+ // Use session with automatic cleanup (mirrors Python's context manager)
38
+ await notte.Session({ timeoutMinutes: 30 }).use(async (session) => {
39
+ const status = await session.status();
40
+ console.log('Session status:', status);
41
+ });
42
+ ```
43
+
44
+ ### Agent Automation
45
+
46
+ ```typescript
47
+ import { NotteClient } from 'notte-sdk';
48
+
49
+ const notte = new NotteClient();
50
+
51
+ // Run an agent task with live updates
52
+ await notte.Session().use(async (session) => {
53
+ const agent = notte.Agent({ session, max_steps: 10 });
54
+
55
+ const response = await agent.run(
56
+ "Find the best Italian restaurant in San Francisco and book a table for 2 at 7pm today",
57
+ (update) => {
58
+ // Receive real-time updates via WebSocket
59
+ console.log(`Step ${update.data.currentStep}: ${update.data.message}`);
60
+ }
61
+ );
62
+
63
+ console.log(`Agent completed: ${response.success ? 'Success' : 'Failed'}`);
64
+ console.log(`Answer: ${response.answer}`);
65
+ });
66
+ ```
67
+
68
+ ## Core Classes
69
+
70
+ ### NotteClient
71
+
72
+ The main client for interacting with the Notte API.
73
+
74
+ ```typescript
75
+ import { NotteClient } from 'notte-sdk';
76
+
77
+ const notte = new NotteClient();
78
+
79
+ // Create sessions
80
+ const session = notte.Session({ timeoutMinutes: 30 });
81
+
82
+ // Create agents
83
+ const agent = notte.Agent({ session, max_steps: 15 });
84
+
85
+ // Create vaults
86
+ const vault = notte.Vault({ name: 'My Vault' });
87
+
88
+ // Create personas
89
+ const persona = notte.Persona({ create_vault: true });
90
+ ```
91
+
92
+ ### Session
93
+
94
+ Manages browser sessions with automatic lifecycle management.
95
+
96
+ ```typescript
97
+ import { NotteClient } from 'notte-sdk';
98
+
99
+ const notte = new NotteClient();
100
+
101
+ // Context manager pattern (automatic start/stop)
102
+ await notte.Session({ timeoutMinutes: 30 }).use(async (session) => {
103
+ // Session is automatically started
104
+ console.log('Session ID:', session.getId());
105
+
106
+ const status = await session.status();
107
+ console.log('Session status:', status);
108
+
109
+ // Session is automatically stopped when done
110
+ });
111
+
112
+ // Manual session management
113
+ const session = notte.Session();
114
+ await session.start();
115
+ try {
116
+ const status = await session.status();
117
+ console.log('Session status:', status);
118
+ } finally {
119
+ await session.stop();
120
+ }
121
+
122
+ // Async iterator pattern
123
+ for await (const session of notte.Session({ timeoutMinutes: 15 })) {
124
+ // Use session here
125
+ const status = await session.status();
126
+ console.log('Session active:', status);
127
+ // Session automatically closed after loop
128
+ }
129
+ ```
130
+
131
+ #### Session Methods
132
+
133
+ - `start()` - Start the session
134
+ - `stop()` - Stop the session
135
+ - `status()` - Get session status
136
+ - `use(callback)` - Context manager pattern
137
+ - `getId()` - Get session ID
138
+ - `isSessionActive()` - Check if session is running
139
+
140
+ ### Agent
141
+
142
+ Executes tasks using LLM-powered web automation.
143
+
144
+ ```typescript
145
+ import { NotteClient } from 'notte-sdk';
146
+
147
+ const notte = new NotteClient();
148
+
149
+ await notte.Session().use(async (session) => {
150
+ const agent = notte.Agent({
151
+ session,
152
+ max_steps: 10
153
+ });
154
+
155
+ // Non-blocking: start agent and get ID
156
+ const agentId = await agent.start("Navigate to Google and search for 'TypeScript'");
157
+ console.log('Agent started:', agentId);
158
+
159
+ // Check agent status
160
+ const status = await agent.status();
161
+ console.log('Agent status:', status);
162
+
163
+ // Blocking: run agent and wait for completion with live updates
164
+ const response = await agent.run(
165
+ "Find the latest TypeScript documentation",
166
+ (update) => {
167
+ if (update.type === 'step') {
168
+ console.log(`Step update:`, update.data);
169
+ } else if (update.type === 'completion') {
170
+ console.log(`Completed:`, update.data);
171
+ }
172
+ }
173
+ );
174
+
175
+ console.log('Final result:', response);
176
+ });
177
+ ```
178
+
179
+ #### Agent Methods
180
+
181
+ - `start(task)` - Start agent with task (non-blocking)
182
+ - `run(task, onUpdate?)` - Start agent and wait for completion (blocking)
183
+ - `status()` - Get agent status
184
+ - `stop()` - Stop the agent
185
+ - `getId()` - Get agent ID
186
+ - `isRunning()` - Check if agent is running
187
+
188
+ ### Secret Vaults
189
+
190
+ Manage credentials securely with enterprise-grade encryption.
191
+
192
+ ```typescript
193
+ import { NotteClient } from 'notte-sdk';
194
+
195
+ const notte = new NotteClient();
196
+
197
+ // Create a new vault
198
+ const vault = notte.Vault({ name: 'My Secure Vault' });
199
+
200
+ // Add credentials for websites
201
+ await vault.addCredentials('https://github.com/', {
202
+ email: 'user@example.com',
203
+ password: 'secure-password', // pragma: allowlist secret
204
+ mfa_secret: 'PYNT7I67RFS2EPR5' // pragma: allowlist secret
205
+ });
206
+
207
+ // Generate secure passwords
208
+ const strongPassword = vault.generatePassword(20, true); // 20 chars with special chars
209
+ const simplePassword = vault.generatePassword(12, false); // 12 chars, no special chars
210
+
211
+ // Add credit card information
212
+ await vault.setCreditCard({
213
+ card_holder_name: 'John Doe',
214
+ card_number: '4111111111111111',
215
+ card_cvv: '123',
216
+ expiry_month: '12',
217
+ expiry_year: '2025'
218
+ });
219
+
220
+ // Use with agents for automatic credential management
221
+ await notte.Session().use(async (session) => {
222
+ const agent = notte.Agent({
223
+ session,
224
+ vault_id: vault.vaultId // Agent will use vault for authentication
225
+ });
226
+
227
+ const result = await agent.run({
228
+ task: "Login to GitHub and create a new repository",
229
+ url: "https://github.com/login"
230
+ });
231
+ });
232
+
233
+ // Access existing vault
234
+ const existingVault = notte.Vault({ vault_id: 'vault-abc-123' });
235
+ const credentials = await existingVault.listCredentials();
236
+
237
+ // Cleanup
238
+ await vault.deleteCredentials('https://github.com/');
239
+ await vault.deleteCreditCard();
240
+ await vault.stop(); // Deletes entire vault
241
+ ```
242
+
243
+ #### Vault Methods
244
+
245
+ - `addCredentials(url, credentials)` - Store credentials for a URL
246
+ - `getCredentials(url)` - Retrieve credentials for a URL
247
+ - `deleteCredentials(url)` - Delete credentials for a URL
248
+ - `listCredentials()` - List all stored credentials
249
+ - `setCreditCard(card)` - Store credit card information
250
+ - `getCreditCard()` - Retrieve credit card information
251
+ - `deleteCreditCard()` - Delete credit card information
252
+ - `generatePassword(length?, includeSpecialChars?)` - Generate secure passwords
253
+ - `delete()` - Delete the entire vault
254
+ - `stop()` - Stop and delete the vault
255
+
256
+ #### Security Features
257
+
258
+ - **End-to-End Encryption** - All credentials encrypted at rest and in transit
259
+ - **Zero Trust Architecture** - Credentials never exposed to LLMs or external services
260
+ - **Access Control** - Strict access logging and permissions
261
+ - **Two-Factor Authentication** - Support for MFA secrets (TOTP)
262
+
263
+ ### Personas
264
+
265
+ Manage complete digital identities for automated account creation and 2FA.
266
+
267
+ ```typescript
268
+ import { NotteClient } from 'notte-sdk';
269
+
270
+ const notte = new NotteClient();
271
+
272
+ // Create a new persona with vault and phone number
273
+ const persona = notte.Persona({
274
+ create_vault: true,
275
+ create_phone_number: true
276
+ });
277
+
278
+ // Get persona information
279
+ console.log(`Email: ${persona.info.email}`);
280
+ console.log(`Phone: ${persona.info.phone_number}`);
281
+
282
+ // Read emails sent to the persona
283
+ const emails = await persona.emails({
284
+ limit: 10,
285
+ only_unread: true
286
+ });
287
+ console.log(`Received ${emails.length} new emails`);
288
+
289
+ // Read SMS messages for 2FA codes
290
+ const smsMessages = await persona.sms({
291
+ limit: 5,
292
+ only_unread: true
293
+ });
294
+ console.log(`Received ${smsMessages.length} SMS messages`);
295
+
296
+ // Use with agents for automated account creation
297
+ await notte.Session().use(async (session) => {
298
+ const agent = notte.Agent({
299
+ session,
300
+ vault_id: persona.vault.vaultId // Agent will use persona's vault
301
+ });
302
+
303
+ const result = await agent.run(
304
+ `Create an account on GitHub using the persona credentials`
305
+ );
306
+ console.log(`Account created: ${result.success}`);
307
+ });
308
+
309
+ // Access existing persona
310
+ const existingPersona = notte.Persona({ persona_id: 'persona-abc-123' });
311
+ const personaEmails = await existingPersona.emails();
312
+
313
+ // Add credentials to persona's vault
314
+ await persona.addCredentials('https://github.com/');
315
+ // This automatically generates a secure password and stores:
316
+ // - Email: persona's email
317
+ // - Password: generated secure password
318
+
319
+ // Cleanup
320
+ await persona.stop(); // Deletes persona and all associated data
321
+ ```
322
+
323
+ #### Persona Methods
324
+
325
+ - `emails(options?)` - Read emails sent to the persona
326
+ - `sms(options?)` - Read SMS messages sent to the persona
327
+ - `createNumber(options?)` - Create a phone number for the persona
328
+ - `deleteNumber()` - Delete the persona's phone number
329
+ - `addCredentials(url)` - Add auto-generated credentials to the persona's vault
330
+ - `delete()` - Delete the persona
331
+ - `stop()` - Stop and delete the persona
332
+
333
+ #### Message Reading Options
334
+
335
+ ```typescript
336
+ const options = {
337
+ limit: 10, // Maximum number of messages (default: unlimited)
338
+ only_unread: true, // Only return unread messages (default: false)
339
+ timedelta: '1h' // Maximum age of messages (e.g., '1h', '30m', '24h')
340
+ };
341
+
342
+ const emails = await persona.emails(options);
343
+ const sms = await persona.sms(options);
344
+ ```
345
+
346
+ #### Persona Features
347
+
348
+ - **Complete Digital Identity** - Unique email address and phone number
349
+ - **2FA Support** - Receive and read SMS verification codes automatically
350
+ - **Automated Account Creation** - Seamless integration with agents for signup flows
351
+ - **Vault Integration** - Optional secure credential storage
352
+ - **Email Management** - Full email reading capabilities
353
+ - **Message Tracking** - Mark messages as read/unread automatically
354
+
355
+ ### Functions
356
+
357
+ Run pre-built automation workflows (Notte Functions) with a simple API call. Functions are serverless workflows that run on Notte's infrastructure — you provide the `function_id` and input variables, and get the result back.
358
+
359
+ ```typescript
360
+ import { NotteClient } from 'notte-sdk';
361
+
362
+ const notte = new NotteClient();
363
+
364
+ // Create a function instance
365
+ const fn = notte.NotteFunction({
366
+ function_id: 'your-function-id',
367
+ decryption_key: 'optional-decryption-key' // optional, for encrypted outputs
368
+ });
369
+
370
+ // Run the function with input variables
371
+ const result = await fn.run({
372
+ url: 'https://example.com',
373
+ query: 'extract pricing information'
374
+ });
375
+
376
+ console.log('Run ID:', result.function_run_id);
377
+
378
+ // Retrieve the run result / metadata later
379
+ const metadata = await fn.retrieve(result.function_run_id);
380
+ console.log('Status:', metadata.status); // 'active' | 'closed' | 'failed'
381
+ console.log('Result:', metadata);
382
+ ```
383
+
384
+ #### Polling for completion
385
+
386
+ Since functions run asynchronously, you can poll for the result:
387
+
388
+ ```typescript
389
+ const fn = notte.NotteFunction({ function_id: 'your-function-id' });
390
+ const { function_run_id } = await fn.run({ url: 'https://example.com' });
391
+
392
+ // Poll until complete
393
+ let metadata;
394
+ do {
395
+ await new Promise(r => setTimeout(r, 2000)); // wait 2s between checks
396
+ metadata = await fn.retrieve(function_run_id);
397
+ } while (metadata.status === 'active');
398
+
399
+ if (metadata.status === 'closed') {
400
+ console.log('Function completed successfully:', metadata);
401
+ } else {
402
+ console.error('Function failed:', metadata);
403
+ }
404
+ ```
405
+
406
+ #### Function Methods
407
+
408
+ - `run(variables?)` - Start a function run with optional input variables
409
+ - `retrieve(functionRunId)` - Get metadata/result for a specific run
410
+ - `getFunctionId()` - Get the function ID
411
+ - `functionId` - The function ID (read-only property)
412
+ - `decryptionKey` - The decryption key, if provided (read-only property)
413
+
414
+ ## Advanced Usage
415
+
416
+ ### Session Configuration
417
+
418
+ ```typescript
419
+ const session = notte.Session({
420
+ timeoutMinutes: 45, // Session timeout (default: 30)
421
+ // Add other session options as supported by the API
422
+ });
423
+ ```
424
+
425
+ ### Agent Configuration
426
+
427
+ ```typescript
428
+ const agent = notte.Agent({
429
+ session: session,
430
+ max_steps: 20, // Maximum steps for agent (default: 10)
431
+ });
432
+ ```
433
+
434
+ ### Error Handling
435
+
436
+ ```typescript
437
+ try {
438
+ await notte.Session().use(async (session) => {
439
+ const agent = notte.Agent({ session });
440
+ const response = await agent.run("Complete a complex task");
441
+
442
+ if (!response.success) {
443
+ console.error('Agent failed:', response.error);
444
+ }
445
+ });
446
+ } catch (error) {
447
+ console.error('Session error:', error);
448
+ }
449
+ ```
450
+
451
+ ### WebSocket Updates
452
+
453
+ The `agent.run()` method provides real-time updates via WebSocket:
454
+
455
+ ```typescript
456
+ const response = await agent.run("Your task", (update) => {
457
+ switch (update.type) {
458
+ case 'step':
459
+ console.log(`Step ${update.data.currentStep}:`, update.data);
460
+ break;
461
+ case 'completion':
462
+ console.log('Task completed:', update.data);
463
+ break;
464
+ default:
465
+ console.log('Update:', update);
466
+ }
467
+ });
468
+ ```
469
+
470
+ ### Legacy API Support
471
+
472
+ For backward compatibility, you can still use the legacy client creation:
473
+
474
+ ```typescript
475
+ import { createClient, client } from 'notte-sdk';
476
+
477
+ // Legacy method 1
478
+ const legacyClient = createClient({
479
+ baseUrl: 'https://api.notte.cc',
480
+ token: 'your-api-key'
481
+ });
482
+
483
+ // Legacy method 2
484
+ import { client } from 'notte-sdk';
485
+ client.setConfig({ baseUrl: 'https://api.notte.cc' });
486
+ client.interceptors.request.use((request) => {
487
+ request.headers.set('Authorization', 'Bearer your-api-key');
488
+ return request;
489
+ });
490
+ ```
491
+
492
+ ## Python SDK Equivalence
493
+
494
+ This TypeScript SDK closely mirrors the Python SDK patterns:
495
+
496
+ ### Python
497
+ ```python
498
+ from notte_sdk import NotteClient
499
+
500
+ notte = NotteClient()
501
+
502
+ # Session context manager
503
+ with notte.Session(timeout_minutes=2) as session:
504
+ status = session.status()
505
+ print(status)
506
+
507
+ # Agent usage
508
+ with notte.Session() as session:
509
+ agent = notte.Agent(session=session, max_steps=10)
510
+ response = agent.run(task="Find the best italian restaurant in SF")
511
+ print(f"Agent completed: {response.success}, answer: {response.answer}")
512
+ ```
513
+
514
+ ### TypeScript
515
+ ```typescript
516
+ import { NotteClient } from 'notte-sdk';
517
+
518
+ const notte = new NotteClient();
519
+
520
+ // Session context manager equivalent
521
+ await notte.Session({ timeoutMinutes: 2 }).use(async (session) => {
522
+ const status = await session.status();
523
+ console.log(status);
524
+ });
525
+
526
+ // Agent usage
527
+ await notte.Session().use(async (session) => {
528
+ const agent = notte.Agent({ session, max_steps: 10 });
529
+ const response = await agent.run("Find the best italian restaurant in SF");
530
+ console.log(`Agent completed: ${response.success}, answer: ${response.answer}`);
531
+ });
532
+ ```
533
+
534
+ ## Development
535
+
536
+ ### Building the SDK
537
+
538
+ ```bash
539
+ # Install dependencies
540
+ npm install
541
+
542
+ # Generate client from OpenAPI spec
543
+ npm run generate
544
+
545
+ # Build the SDK
546
+ npm run build
547
+
548
+ # Run tests
549
+ npm test
550
+
551
+ # Type checking
552
+ npm run typecheck
553
+ ```
554
+
555
+ ### Testing
556
+
557
+ The SDK includes comprehensive tests:
558
+
559
+ ```bash
560
+ # Run all tests
561
+ npm test
562
+
563
+ # Run tests with coverage
564
+ npm run test -- --coverage
565
+
566
+ # Run specific test file
567
+ npm run test src/test/client.test.ts
568
+ ```
569
+
570
+ ### Regenerating from API
571
+
572
+ The SDK is auto-generated from the Notte OpenAPI specification:
573
+
574
+ ```bash
575
+ # Regenerate client code
576
+ npm run generate
577
+ ```
578
+
579
+ This will fetch the latest API specification and update the generated client code.
580
+
581
+ ## TypeScript Support
582
+
583
+ The SDK is built with full TypeScript support:
584
+
585
+ ```typescript
586
+ import { NotteClient, SessionStatus, AgentResponse } from 'notte-sdk';
587
+
588
+ const notte = new NotteClient();
589
+
590
+ // All types are properly inferred
591
+ await notte.Session().use(async (session) => {
592
+ const status: SessionStatus = await session.status();
593
+ const agent = notte.Agent({ session });
594
+ const response: AgentResponse = await agent.run("task");
595
+ });
596
+ ```
597
+
598
+ ## API Reference
599
+
600
+ ### Types
601
+
602
+ The SDK exports all generated types from the OpenAPI specification:
603
+
604
+ ```typescript
605
+ import type {
606
+ NotteClientConfig,
607
+ SessionOptions,
608
+ SessionStatus,
609
+ AgentConstructor,
610
+ AgentRunRequest,
611
+ AgentUpdateHandler,
612
+ VaultConstructor,
613
+ CredentialsDict,
614
+ CreditCardDict,
615
+ Credential,
616
+ PersonaConstructor,
617
+ MessageReadOptions,
618
+ PersonaListOptions,
619
+ CreatePhoneNumberOptions
620
+ } from 'notte-sdk';
621
+ ```
622
+
623
+ ## License
624
+
625
+ MIT
626
+
627
+ ## Support
628
+
629
+ For issues and questions:
630
+ - GitHub Issues: [Report issues](https://github.com/notte/sdk/issues)
631
+ - Documentation: [docs.notte.cc](https://docs.notte.cc)
632
+ - Python SDK: [notte-sdk](https://pypi.org/project/notte-sdk/)