@querying/sneaky 0.4.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { type ActOptions, type ActResult, type Action, type BlockResourceType, DEFAULT_LOCAL_URL, DEFAULT_REMOTE_URL, type ExtractKind, type NetworkEntry, type PageMeta, SneakyError, type SnapshotMode, type SnapshotResult, type SnapshotSource, type Target, type TargetInput, type WaitUntil, parseTarget } from "./agent/index.js";
1
+ import { type ActOptions, type ActResult, type Action, type BlockResourceType, DEFAULT_LOCAL_URL, DEFAULT_REMOTE_URL, type DialogInfo, type DownloadInfo, type ExtractKind, type NetworkEntry, type PageMeta, type PopupInfo, SneakyError, type SnapshotMode, type SnapshotResult, type SnapshotSource, type Target, type TargetInput, type UploadResult, type WaitUntil, parseTarget } from "./agent/index.js";
2
2
  import { type PersonaOptions, type Platform, type ProxyConfig, type ScreenSize, buildArgs, buildEnv, deriveAcceptLanguage, formatProxyUrl, profileSeed } from "./browser/index.js";
3
3
  import { type ManagedDaemon, PLATFORM_PACKAGES, type StartDaemonOptions, resolveBinaryPath, startDaemon } from "./cli/index.js";
4
4
  export { DEFAULT_LOCAL_URL, DEFAULT_REMOTE_URL, PLATFORM_PACKAGES, SneakyError, buildArgs, buildEnv, deriveAcceptLanguage, formatProxyUrl, parseTarget, profileSeed, resolveBinaryPath, startDaemon, };
5
- export type { ActOptions, ActResult, Action, BlockResourceType, ExtractKind, ManagedDaemon, NetworkEntry, PageMeta, PersonaOptions, Platform, ProxyConfig, ScreenSize, SnapshotMode, SnapshotResult, SnapshotSource, StartDaemonOptions, Target, TargetInput, WaitUntil, };
5
+ export type { ActOptions, ActResult, Action, BlockResourceType, DialogInfo, DownloadInfo, ExtractKind, ManagedDaemon, NetworkEntry, PageMeta, PersonaOptions, Platform, PopupInfo, ProxyConfig, ScreenSize, SnapshotMode, SnapshotResult, SnapshotSource, StartDaemonOptions, Target, TargetInput, UploadResult, WaitUntil, };
6
6
  export type SessionMode = "auto" | "http" | "browser";
7
7
  export type CookieSource = "all" | "http" | "browser";
8
8
  export type CookieTarget = "both" | "http" | "browser";
@@ -46,6 +46,8 @@ export interface CreateUnifiedSessionOptions {
46
46
  mode?: SessionMode;
47
47
  persona?: PersonaOptions | UnifiedPersona;
48
48
  headless?: boolean;
49
+ /** Launches headful windows without stealing OS focus or switching macOS Spaces (default true for agent launches). */
50
+ background?: boolean;
49
51
  stealth?: boolean;
50
52
  proxyServer?: string;
51
53
  binary?: string;
@@ -84,6 +86,8 @@ export interface FetchOptions {
84
86
  escalateOnStatus?: number[];
85
87
  /** "retry" (default: load in browser, sync cookies, retry via tfrd) or "render" (return browser HTML). */
86
88
  escalateMode?: "retry" | "render";
89
+ /** Optional page URL to navigate in Browser during escalation (useful when an API call needs its app/login page refreshed). */
90
+ escalateUrl?: string;
87
91
  }
88
92
  export interface StandaloneFetchOptions extends FetchOptions {
89
93
  persona?: PersonaOptions | UnifiedPersona;
@@ -133,6 +137,54 @@ export interface TabInfo {
133
137
  title: string;
134
138
  url: string;
135
139
  active: boolean;
140
+ frozen?: boolean;
141
+ space?: string;
142
+ idle_seconds?: number;
143
+ }
144
+ export interface AppSettings {
145
+ launch_at_login: boolean;
146
+ auto_open_daily_on_launch: boolean;
147
+ tab_freeze_minutes: number;
148
+ memory_saver_level: "aggressive" | "balanced" | "off";
149
+ tab_discard_minutes: number;
150
+ idle_profile_sleep_minutes: number;
151
+ idle_session_minutes: number;
152
+ idle_space_minutes: number;
153
+ memory_budget_mb: number;
154
+ max_parallel_workers: number;
155
+ download_dir: string;
156
+ process_per_site: boolean;
157
+ }
158
+ export interface SpaceInfo {
159
+ name: string;
160
+ profile_id: string;
161
+ session_id?: string;
162
+ client?: string;
163
+ target_ids: string[];
164
+ active_target_id?: string;
165
+ active_url?: string;
166
+ active_title?: string;
167
+ tab_count: number;
168
+ created_at: number;
169
+ last_active_at: number;
170
+ handoff_state?: "agent" | "user" | string;
171
+ handoff_reason?: string;
172
+ handoff_message?: string;
173
+ handoff_at?: number;
174
+ }
175
+ export interface FreezeTabsResult {
176
+ profile_id: string;
177
+ total_tabs: number;
178
+ frozen_count: number;
179
+ skipped: number;
180
+ frozen_ids: string[];
181
+ before_mb: number;
182
+ after_mb: number;
183
+ method?: string;
184
+ }
185
+ export interface CallScope {
186
+ targetId?: string;
187
+ space?: string;
136
188
  }
137
189
  export interface ProxySummary {
138
190
  proxy_id?: string;
@@ -197,6 +249,7 @@ export interface ProxyCheckResult {
197
249
  export interface ProfileInfo {
198
250
  id: string;
199
251
  name?: string;
252
+ mode?: "daily" | "stealth" | string;
200
253
  tags?: string[];
201
254
  notes?: string;
202
255
  color?: string;
@@ -218,6 +271,12 @@ export interface ProfileInfo {
218
271
  running_headless?: boolean;
219
272
  engine?: "sneaky-browser" | "chrome-fallback" | "remote" | string;
220
273
  pid?: number;
274
+ memory_rss_mb?: number;
275
+ memory_method?: string;
276
+ process_count?: number;
277
+ frozen_tab_count?: number;
278
+ active_space_count?: number;
279
+ extension_count?: number;
221
280
  proxy_summary?: ProxySummary;
222
281
  proxy_collision_ids?: string[];
223
282
  accounts?: AccountMeta[];
@@ -234,6 +293,7 @@ export interface ProfileListResult {
234
293
  export interface StartProfileOptions {
235
294
  headless?: boolean;
236
295
  headful?: boolean;
296
+ background?: boolean;
237
297
  stealth?: boolean;
238
298
  proxyServer?: string;
239
299
  binary?: string;
@@ -321,6 +381,116 @@ export interface SneakyOptions {
321
381
  timeoutMs?: number;
322
382
  fetch?: typeof fetch;
323
383
  }
384
+ export interface SiteNote {
385
+ domain: string;
386
+ path: string;
387
+ profile_id?: string;
388
+ tags?: string[];
389
+ recipes?: string[];
390
+ body: string;
391
+ updated_at?: string;
392
+ bytes: number;
393
+ preview?: string;
394
+ }
395
+ export interface SiteListResult {
396
+ dir: string;
397
+ url?: string;
398
+ notes: SiteNote[];
399
+ count: number;
400
+ }
401
+ export interface RecipeParam {
402
+ name: string;
403
+ default?: string;
404
+ required?: boolean;
405
+ description?: string;
406
+ }
407
+ export interface RecipeStep {
408
+ name: string;
409
+ method: string;
410
+ url: string;
411
+ headers?: Array<[string, string]>;
412
+ body?: string;
413
+ extract?: Record<string, string>;
414
+ expect_status?: number[];
415
+ escalate_on_status?: number[];
416
+ escalate_url?: string;
417
+ timeout_ms?: number;
418
+ }
419
+ export interface Recipe {
420
+ id: string;
421
+ name: string;
422
+ domain?: string;
423
+ profile_id?: string;
424
+ description?: string;
425
+ source_url?: string;
426
+ tags?: string[];
427
+ params?: RecipeParam[];
428
+ steps: RecipeStep[];
429
+ created_at?: string;
430
+ updated_at?: string;
431
+ last_run_at?: string;
432
+ last_run_ok?: boolean;
433
+ last_run_ms?: number;
434
+ path?: string;
435
+ }
436
+ export interface RecipeStepResult {
437
+ index: number;
438
+ name: string;
439
+ method: string;
440
+ url: string;
441
+ ok: boolean;
442
+ status: number;
443
+ protocol?: string;
444
+ duration_ms: number;
445
+ bytes_received?: number;
446
+ escalated?: boolean;
447
+ cookies_synced?: number;
448
+ extracted?: Record<string, unknown>;
449
+ body_preview?: string;
450
+ json?: unknown;
451
+ error?: string;
452
+ }
453
+ export interface RecipeRunResult {
454
+ recipe_id: string;
455
+ ok: boolean;
456
+ failed_step?: number;
457
+ error?: string;
458
+ transport: string;
459
+ escalated?: boolean;
460
+ duration_ms: number;
461
+ vars?: Record<string, string>;
462
+ extracted?: Record<string, unknown>;
463
+ steps: RecipeStepResult[];
464
+ last_body?: string;
465
+ last_json?: unknown;
466
+ }
467
+ export interface RecipeRecordingCandidate {
468
+ request_id: string;
469
+ seq: number;
470
+ method: string;
471
+ url: string;
472
+ status?: number;
473
+ resource_type?: string;
474
+ has_body?: boolean;
475
+ }
476
+ export interface RecipeRecordingStatus {
477
+ recording: boolean;
478
+ profile_id: string;
479
+ session_id?: string;
480
+ target_id?: string;
481
+ url_contains?: string;
482
+ source_url?: string;
483
+ since_seq?: number;
484
+ started_at?: string;
485
+ captured_count: number;
486
+ candidates?: RecipeRecordingCandidate[];
487
+ }
488
+ export interface RecipeListResult {
489
+ dir: string;
490
+ recipes: Recipe[];
491
+ count: number;
492
+ recordings?: RecipeRecordingStatus[];
493
+ }
324
494
  export interface StartSneakyOptions extends StartDaemonOptions {
325
495
  /** Optional custom captcha solver plugin hook. */
326
496
  captcha?: CaptchaPlugin;
@@ -349,7 +519,7 @@ export declare class Sneaky {
349
519
  /** Stops the managed local daemon if this client was created via `Sneaky.start()`. */
350
520
  stop(): Promise<void>;
351
521
  [Symbol.asyncDispose](): Promise<void>;
352
- request<T>(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, options?: {
522
+ request<T>(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", path: string, options?: {
353
523
  body?: unknown;
354
524
  query?: Record<string, string | number | undefined>;
355
525
  headers?: Record<string, string>;
@@ -426,6 +596,177 @@ export declare class Sneaky {
426
596
  session: SneakySession;
427
597
  tabs: TabInfo[];
428
598
  }>;
599
+ settings(): Promise<AppSettings>;
600
+ updateSettings(patch: Partial<AppSettings>): Promise<AppSettings>;
601
+ maintenanceStatus(): Promise<Record<string, unknown>>;
602
+ maintenanceReap(options?: {
603
+ memoryBudgetMB?: number;
604
+ idleSessionSeconds?: number;
605
+ idleSpaceSeconds?: number;
606
+ idleProfileSeconds?: number;
607
+ tabFreezeSeconds?: number;
608
+ }): Promise<Record<string, unknown>>;
609
+ maintenanceClean(options?: {
610
+ dryRun?: boolean;
611
+ reap?: boolean;
612
+ minAgeMinutes?: number;
613
+ }): Promise<Record<string, unknown>>;
614
+ spaces(profileId?: string): Promise<{
615
+ spaces: SpaceInfo[];
616
+ count: number;
617
+ }>;
618
+ ensureSpace(profileId: string, options: {
619
+ name: string;
620
+ url?: string;
621
+ client?: string;
622
+ createTab?: boolean;
623
+ headful?: boolean;
624
+ headless?: boolean;
625
+ }): Promise<{
626
+ profile_id: string;
627
+ session_id: string;
628
+ target_id: string;
629
+ space: SpaceInfo;
630
+ }>;
631
+ openSpaceTab(profileId: string, spaceName: string, url?: string): Promise<{
632
+ profile_id: string;
633
+ session_id: string;
634
+ target_id: string;
635
+ space: SpaceInfo;
636
+ }>;
637
+ focusSpace(profileId: string, spaceName: string): Promise<{
638
+ focused: boolean;
639
+ target_id: string;
640
+ }>;
641
+ handoffSpace(profileId: string, spaceName: string, options?: {
642
+ reason?: string;
643
+ message?: string;
644
+ focus?: boolean;
645
+ }): Promise<{
646
+ profile_id: string;
647
+ session_id?: string;
648
+ space: SpaceInfo;
649
+ focused: boolean;
650
+ window_focused: boolean;
651
+ }>;
652
+ resumeSpace(profileId: string, spaceName: string): Promise<{
653
+ profile_id: string;
654
+ space: SpaceInfo;
655
+ resumed: boolean;
656
+ }>;
657
+ waitForSpaceResume(profileId: string, spaceName: string, options?: {
658
+ timeoutMs?: number;
659
+ }): Promise<{
660
+ profile_id: string;
661
+ space: SpaceInfo;
662
+ resumed: boolean;
663
+ waited_ms: number;
664
+ }>;
665
+ closeSpace(profileId: string, spaceName: string): Promise<{
666
+ deleted: boolean;
667
+ closed_tabs: number;
668
+ }>;
669
+ freezeProfileTabs(profileId: string, options?: {
670
+ minIdleSeconds?: number;
671
+ excludeTargetIds?: string[];
672
+ }): Promise<FreezeTabsResult>;
673
+ freezeAllTabs(minIdleSeconds?: number): Promise<{
674
+ profiles_checked: number;
675
+ frozen_count: number;
676
+ before_mb: number;
677
+ after_mb: number;
678
+ }>;
679
+ sites(options?: {
680
+ q?: string;
681
+ url?: string;
682
+ }): Promise<SiteListResult>;
683
+ matchSiteNotes(url: string): Promise<SiteListResult>;
684
+ getSiteNote(domain: string): Promise<SiteNote>;
685
+ saveSiteNote(domain: string, options: {
686
+ body: string;
687
+ profileId?: string;
688
+ tags?: string[];
689
+ recipes?: string[];
690
+ }): Promise<SiteNote>;
691
+ appendSiteNote(domain: string, entry: string, options?: {
692
+ profileId?: string;
693
+ tags?: string[];
694
+ recipeId?: string;
695
+ }): Promise<SiteNote>;
696
+ deleteSiteNote(domain: string): Promise<{
697
+ domain: string;
698
+ deleted: boolean;
699
+ }>;
700
+ recipes(options?: {
701
+ domain?: string;
702
+ q?: string;
703
+ }): Promise<RecipeListResult>;
704
+ getRecipe(id: string): Promise<Recipe>;
705
+ saveRecipe(recipe: Recipe, options?: {
706
+ linkSiteNote?: boolean;
707
+ }): Promise<Recipe>;
708
+ deleteRecipe(id: string): Promise<{
709
+ id: string;
710
+ deleted: boolean;
711
+ }>;
712
+ compileRecipeFromCapture(options: {
713
+ sessionId?: string;
714
+ profileId?: string;
715
+ id: string;
716
+ name?: string;
717
+ description?: string;
718
+ sourceUrl?: string;
719
+ tags?: string[];
720
+ urlContains?: string;
721
+ sinceSeq?: number;
722
+ requestIds?: string[];
723
+ autoParameterize?: boolean;
724
+ escalateOnStatus?: number[];
725
+ save?: boolean;
726
+ linkSiteNote?: boolean;
727
+ }): Promise<{
728
+ recipe: Recipe;
729
+ saved: boolean;
730
+ captured_count: number;
731
+ step_count: number;
732
+ cookies_cached: number;
733
+ }>;
734
+ startRecipeRecording(profileId: string, options?: {
735
+ urlContains?: string;
736
+ targetId?: string;
737
+ headful?: boolean;
738
+ url?: string;
739
+ }): Promise<RecipeRecordingStatus>;
740
+ recipeRecordingStatus(profileId: string): Promise<RecipeRecordingStatus>;
741
+ stopRecipeRecording(profileId: string, options?: {
742
+ id?: string;
743
+ name?: string;
744
+ description?: string;
745
+ tags?: string[];
746
+ urlContains?: string;
747
+ requestIds?: string[];
748
+ autoParameterize?: boolean;
749
+ escalateOnStatus?: number[];
750
+ save?: boolean;
751
+ discard?: boolean;
752
+ linkSiteNote?: boolean;
753
+ }): Promise<{
754
+ recording: boolean;
755
+ profile_id: string;
756
+ discarded?: boolean;
757
+ recipe?: Recipe;
758
+ saved?: boolean;
759
+ captured_count?: number;
760
+ step_count?: number;
761
+ cookies_cached?: number;
762
+ }>;
763
+ runRecipe(id: string, options?: {
764
+ profileId?: string;
765
+ params?: Record<string, string>;
766
+ escalate?: boolean;
767
+ timeoutMs?: number;
768
+ ignoreCertErrors?: boolean;
769
+ }): Promise<RecipeRunResult>;
429
770
  }
430
771
  export declare class SneakySession {
431
772
  private readonly client;
@@ -449,7 +790,7 @@ export declare class SneakySession {
449
790
  clear?: boolean;
450
791
  submit?: boolean;
451
792
  speed?: "fast" | "natural" | "stealth";
452
- }): Promise<{
793
+ } & CallScope): Promise<{
453
794
  ok: boolean;
454
795
  account_id: string;
455
796
  field: string;
@@ -480,7 +821,7 @@ export declare class SneakySession {
480
821
  timeoutMs?: number;
481
822
  returnSnapshot?: boolean;
482
823
  snapshotMode?: SnapshotMode;
483
- }): Promise<{
824
+ } & CallScope): Promise<{
484
825
  url: string;
485
826
  title: string;
486
827
  ready_state: string;
@@ -498,23 +839,59 @@ export declare class SneakySession {
498
839
  maxNodes?: number;
499
840
  maxChars?: number;
500
841
  screenshot?: boolean;
501
- }): Promise<SnapshotResult>;
502
- screenshot(options?: ScreenshotOptions): Promise<ScreenshotResult>;
503
- pdf(options?: PdfOptions): Promise<PdfResult>;
504
- setViewport(options: ViewportOptions): Promise<ViewportResult>;
505
- eval<T = unknown>(expression: string, options?: EvalOptions): Promise<EvalResult<T>>;
506
- query<T = unknown>(target: TargetInput, op: QueryOp, arg?: string): Promise<QueryResult<T>>;
507
- act(actions: Action | Action[], options?: ActOptions): Promise<ActResult>;
508
- click(target: TargetInput, options?: ActOptions): Promise<ActResult>;
842
+ } & CallScope): Promise<SnapshotResult>;
843
+ screenshot(options?: ScreenshotOptions & CallScope): Promise<ScreenshotResult>;
844
+ pdf(options?: PdfOptions & CallScope): Promise<PdfResult>;
845
+ setViewport(options: ViewportOptions & CallScope): Promise<ViewportResult>;
846
+ eval<T = unknown>(expression: string, options?: EvalOptions & CallScope): Promise<EvalResult<T>>;
847
+ query<T = unknown>(target: TargetInput, op: QueryOp, arg?: string, scope?: CallScope): Promise<QueryResult<T>>;
848
+ act(actions: Action | Action[], options?: ActOptions & CallScope): Promise<ActResult>;
849
+ click(target: TargetInput, options?: ActOptions & CallScope): Promise<ActResult>;
509
850
  fill(target: TargetInput, text: string, options?: ActOptions & {
510
851
  clear?: boolean;
511
- }): Promise<ActResult>;
512
- press(key: string, options?: ActOptions): Promise<ActResult>;
852
+ } & CallScope): Promise<ActResult>;
853
+ press(key: string, options?: ActOptions & CallScope): Promise<ActResult>;
854
+ pendingDialog(scope?: CallScope): Promise<{
855
+ dialog: DialogInfo | null;
856
+ }>;
857
+ handleDialog(accept: boolean, promptText?: string, scope?: CallScope): Promise<{
858
+ handled: boolean;
859
+ accept: boolean;
860
+ dialog?: DialogInfo | null;
861
+ }>;
862
+ acceptDialog(promptText?: string, scope?: CallScope): Promise<{
863
+ handled: boolean;
864
+ accept: boolean;
865
+ dialog?: DialogInfo | null;
866
+ }>;
867
+ dismissDialog(scope?: CallScope): Promise<{
868
+ handled: boolean;
869
+ accept: boolean;
870
+ dialog?: DialogInfo | null;
871
+ }>;
872
+ upload(target: TargetInput, files: string | string[], options?: {
873
+ triggerClick?: boolean;
874
+ } & CallScope): Promise<UploadResult>;
875
+ downloads(): Promise<{
876
+ downloads: DownloadInfo[];
877
+ count: number;
878
+ seq: number;
879
+ }>;
880
+ waitForDownload(options?: {
881
+ downloadDir?: string;
882
+ sinceSeq?: number;
883
+ timeoutMs?: number;
884
+ }): Promise<DownloadInfo>;
885
+ waitForPopup(options?: {
886
+ openerId?: string;
887
+ sinceSeq?: number;
888
+ timeoutMs?: number;
889
+ } & CallScope): Promise<PopupInfo>;
513
890
  extract(options?: {
514
891
  kind?: ExtractKind;
515
892
  target?: TargetInput;
516
893
  maxChars?: number;
517
- }): Promise<Record<string, unknown>>;
894
+ } & CallScope): Promise<Record<string, unknown>>;
518
895
  locator(selectorOrRef: string): UnifiedLocator;
519
896
  getByRole(role: string, options?: {
520
897
  name?: string;
@@ -530,22 +907,20 @@ export declare class SneakySession {
530
907
  exact?: boolean;
531
908
  }): UnifiedLocator;
532
909
  tabs(): Promise<{
533
- tabs: Array<{
534
- id: string;
535
- title: string;
536
- url: string;
537
- active: boolean;
538
- }>;
539
- }>;
540
- openTab(url?: string): Promise<{
910
+ tabs: TabInfo[];
911
+ }>;
912
+ openTab(url?: string, options?: {
913
+ background?: boolean;
914
+ space?: string;
915
+ }): Promise<{
541
916
  target_id: string;
542
- tabs: Array<{
543
- id: string;
544
- title: string;
545
- url: string;
546
- active: boolean;
547
- }>;
917
+ tabs: TabInfo[];
548
918
  }>;
919
+ freezeTabs(options?: {
920
+ targetId?: string;
921
+ minIdleSeconds?: number;
922
+ }): Promise<unknown>;
923
+ trimMemory(): Promise<unknown>;
549
924
  activateTab(targetId: string): Promise<unknown>;
550
925
  closeTab(targetId: string): Promise<unknown>;
551
926
  close(): Promise<void>;
@@ -572,6 +947,9 @@ export declare class UnifiedLocator {
572
947
  value?: string;
573
948
  label?: string;
574
949
  }, options?: ActOptions): Promise<ActResult>;
950
+ setInputFiles(files: string | string[], options?: {
951
+ triggerClick?: boolean;
952
+ }): Promise<UploadResult>;
575
953
  waitFor(options?: {
576
954
  timeout?: number;
577
955
  }): Promise<ActResult>;