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