@dealcrawl/sdk 2.2.0 → 2.3.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.mts +363 -2
- package/dist/index.d.ts +363 -2
- package/dist/index.js +240 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -776,6 +776,69 @@ interface UpdatePreferencesResponse {
|
|
|
776
776
|
success: boolean;
|
|
777
777
|
preferences: ClientPreferences;
|
|
778
778
|
}
|
|
779
|
+
/** Agent job creation response */
|
|
780
|
+
interface AgentJobResponse extends JobResponse {
|
|
781
|
+
/** Estimated completion time based on maxSteps */
|
|
782
|
+
estimatedTime?: string;
|
|
783
|
+
}
|
|
784
|
+
/** Agent step in execution trace */
|
|
785
|
+
interface AgentStepResponse {
|
|
786
|
+
/** Step number (1-indexed) */
|
|
787
|
+
step: number;
|
|
788
|
+
/** Agent's reasoning before action */
|
|
789
|
+
thought: string;
|
|
790
|
+
/** Type of action taken */
|
|
791
|
+
actionType: string;
|
|
792
|
+
/** Action details */
|
|
793
|
+
action: Record<string, unknown>;
|
|
794
|
+
/** Whether the action succeeded */
|
|
795
|
+
result: "success" | "failed" | "skipped";
|
|
796
|
+
/** Duration of this step in ms */
|
|
797
|
+
durationMs: number;
|
|
798
|
+
/** Error message if failed */
|
|
799
|
+
error?: string;
|
|
800
|
+
/** Screenshot URL if captured */
|
|
801
|
+
screenshotUrl?: string;
|
|
802
|
+
/** Current URL after action */
|
|
803
|
+
currentUrl?: string;
|
|
804
|
+
}
|
|
805
|
+
/** Agent completion reason */
|
|
806
|
+
type AgentCompletionReason = "goal_achieved" | "max_steps_reached" | "stuck" | "error" | "cancelled";
|
|
807
|
+
/** Agent result (from completed job) */
|
|
808
|
+
interface AgentResultResponse {
|
|
809
|
+
/** Extracted/collected data (matches provided schema if given) */
|
|
810
|
+
data: Record<string, unknown>;
|
|
811
|
+
/** Steps executed by the agent */
|
|
812
|
+
steps: AgentStepResponse[];
|
|
813
|
+
/** Final URL after all navigation */
|
|
814
|
+
finalUrl: string;
|
|
815
|
+
/** Credits/tokens used */
|
|
816
|
+
creditsUsed: number;
|
|
817
|
+
/** Total execution time in ms */
|
|
818
|
+
totalDurationMs: number;
|
|
819
|
+
/** Screenshots captured (if takeScreenshots enabled) */
|
|
820
|
+
screenshots?: string[];
|
|
821
|
+
/** Completion reason */
|
|
822
|
+
completionReason: AgentCompletionReason;
|
|
823
|
+
/** Agent metadata */
|
|
824
|
+
metadata: {
|
|
825
|
+
model: string;
|
|
826
|
+
stepsExecuted: number;
|
|
827
|
+
tokensUsed?: number;
|
|
828
|
+
timestamp: string;
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
/** Agent status response (extended from JobStatusResponse) */
|
|
832
|
+
interface AgentStatusResponse extends JobStatusResponse {
|
|
833
|
+
/** Partial result with steps so far */
|
|
834
|
+
partialResult?: {
|
|
835
|
+
steps: AgentStepResponse[];
|
|
836
|
+
currentUrl?: string;
|
|
837
|
+
extractedData?: Record<string, unknown>;
|
|
838
|
+
};
|
|
839
|
+
/** Final result when completed */
|
|
840
|
+
result?: AgentResultResponse;
|
|
841
|
+
}
|
|
779
842
|
|
|
780
843
|
/**
|
|
781
844
|
* Polling Utilities
|
|
@@ -1197,7 +1260,7 @@ interface UpdateWebhookOptions {
|
|
|
1197
1260
|
* API key scope - Must match @dealcrawl/shared/src/types/api-key.types.ts
|
|
1198
1261
|
* These are the actual scopes enforced by the backend via requireScope() middleware
|
|
1199
1262
|
*/
|
|
1200
|
-
type ApiKeyScope = "scrape" | "crawl" | "dork" | "extract" | "status" | "data:read" | "data:export" | "keys:manage" | "webhooks:manage";
|
|
1263
|
+
type ApiKeyScope = "scrape" | "crawl" | "dork" | "extract" | "agent" | "status" | "data:read" | "data:export" | "keys:manage" | "webhooks:manage";
|
|
1201
1264
|
/**
|
|
1202
1265
|
* All available scopes (for reference and validation)
|
|
1203
1266
|
*/
|
|
@@ -1250,6 +1313,111 @@ interface UpdatePreferencesOptions {
|
|
|
1250
1313
|
/** Enable webhook notifications */
|
|
1251
1314
|
webhookEnabled?: boolean;
|
|
1252
1315
|
}
|
|
1316
|
+
/** LLM provider for agent */
|
|
1317
|
+
type AgentModel = "openai" | "anthropic";
|
|
1318
|
+
/** Browser action types */
|
|
1319
|
+
type AgentActionType = "click" | "scroll" | "write" | "wait" | "press" | "screenshot" | "hover" | "select";
|
|
1320
|
+
/** Base action interface */
|
|
1321
|
+
interface BaseAgentAction {
|
|
1322
|
+
type: AgentActionType;
|
|
1323
|
+
optional?: boolean;
|
|
1324
|
+
retries?: number;
|
|
1325
|
+
delayBefore?: number;
|
|
1326
|
+
}
|
|
1327
|
+
/** Click action */
|
|
1328
|
+
interface ClickAction extends BaseAgentAction {
|
|
1329
|
+
type: "click";
|
|
1330
|
+
selector: string;
|
|
1331
|
+
waitAfter?: number;
|
|
1332
|
+
button?: "left" | "right" | "middle";
|
|
1333
|
+
clickCount?: number;
|
|
1334
|
+
force?: boolean;
|
|
1335
|
+
}
|
|
1336
|
+
/** Scroll action */
|
|
1337
|
+
interface ScrollAction extends BaseAgentAction {
|
|
1338
|
+
type: "scroll";
|
|
1339
|
+
direction: "up" | "down" | "left" | "right" | "to-element";
|
|
1340
|
+
selector?: string;
|
|
1341
|
+
amount?: number;
|
|
1342
|
+
smooth?: boolean;
|
|
1343
|
+
}
|
|
1344
|
+
/** Write action */
|
|
1345
|
+
interface WriteAction extends BaseAgentAction {
|
|
1346
|
+
type: "write";
|
|
1347
|
+
selector: string;
|
|
1348
|
+
text: string;
|
|
1349
|
+
clearFirst?: boolean;
|
|
1350
|
+
pressEnter?: boolean;
|
|
1351
|
+
typeDelay?: number;
|
|
1352
|
+
}
|
|
1353
|
+
/** Wait action */
|
|
1354
|
+
interface WaitAction extends BaseAgentAction {
|
|
1355
|
+
type: "wait";
|
|
1356
|
+
milliseconds?: number;
|
|
1357
|
+
selector?: string;
|
|
1358
|
+
condition?: "visible" | "hidden" | "attached" | "detached";
|
|
1359
|
+
timeout?: number;
|
|
1360
|
+
}
|
|
1361
|
+
/** Press action */
|
|
1362
|
+
interface PressAction extends BaseAgentAction {
|
|
1363
|
+
type: "press";
|
|
1364
|
+
key: string;
|
|
1365
|
+
modifiers?: Array<"Alt" | "Control" | "Meta" | "Shift">;
|
|
1366
|
+
}
|
|
1367
|
+
/** Screenshot action */
|
|
1368
|
+
interface ScreenshotAgentAction extends BaseAgentAction {
|
|
1369
|
+
type: "screenshot";
|
|
1370
|
+
fullPage?: boolean;
|
|
1371
|
+
selector?: string;
|
|
1372
|
+
format?: "png" | "jpeg";
|
|
1373
|
+
quality?: number;
|
|
1374
|
+
name?: string;
|
|
1375
|
+
}
|
|
1376
|
+
/** Hover action */
|
|
1377
|
+
interface HoverAction extends BaseAgentAction {
|
|
1378
|
+
type: "hover";
|
|
1379
|
+
selector: string;
|
|
1380
|
+
duration?: number;
|
|
1381
|
+
}
|
|
1382
|
+
/** Select action */
|
|
1383
|
+
interface SelectAction extends BaseAgentAction {
|
|
1384
|
+
type: "select";
|
|
1385
|
+
selector: string;
|
|
1386
|
+
value: string | string[];
|
|
1387
|
+
byLabel?: boolean;
|
|
1388
|
+
}
|
|
1389
|
+
/** All agent action types */
|
|
1390
|
+
type AgentAction = ClickAction | ScrollAction | WriteAction | WaitAction | PressAction | ScreenshotAgentAction | HoverAction | SelectAction;
|
|
1391
|
+
/** Options for creating an AI agent job */
|
|
1392
|
+
interface AgentOptions {
|
|
1393
|
+
/** Starting URL for the agent (required) */
|
|
1394
|
+
url: string;
|
|
1395
|
+
/** Additional URLs to process */
|
|
1396
|
+
urls?: string[];
|
|
1397
|
+
/** Natural language instructions for the agent (required, 10-2000 chars) */
|
|
1398
|
+
prompt: string;
|
|
1399
|
+
/** JSON Schema for structured output */
|
|
1400
|
+
schema?: Record<string, unknown>;
|
|
1401
|
+
/** Maximum number of steps (default: 10, max: 25) */
|
|
1402
|
+
maxSteps?: number;
|
|
1403
|
+
/** Preset actions to execute before agent reasoning */
|
|
1404
|
+
actions?: AgentAction[];
|
|
1405
|
+
/** LLM provider (default: openai) */
|
|
1406
|
+
model?: AgentModel;
|
|
1407
|
+
/** Per-step timeout in milliseconds (default: 30000, max: 60000) */
|
|
1408
|
+
timeout?: number;
|
|
1409
|
+
/** Extract only main content area (default: true) */
|
|
1410
|
+
onlyMainContent?: boolean;
|
|
1411
|
+
/** Take screenshots at each step (default: false) */
|
|
1412
|
+
takeScreenshots?: boolean;
|
|
1413
|
+
/** Custom headers for HTTP requests */
|
|
1414
|
+
headers?: Record<string, string>;
|
|
1415
|
+
/** Webhook for async notification */
|
|
1416
|
+
webhook?: {
|
|
1417
|
+
url: string;
|
|
1418
|
+
headers?: Record<string, string>;
|
|
1419
|
+
};
|
|
1420
|
+
}
|
|
1253
1421
|
|
|
1254
1422
|
/**
|
|
1255
1423
|
* Account Resource
|
|
@@ -1392,6 +1560,161 @@ declare class AccountResource {
|
|
|
1392
1560
|
isPremium(): Promise<boolean>;
|
|
1393
1561
|
}
|
|
1394
1562
|
|
|
1563
|
+
/**
|
|
1564
|
+
* Agent Resource
|
|
1565
|
+
* Handles AI agent operations for autonomous web navigation and data extraction
|
|
1566
|
+
*/
|
|
1567
|
+
|
|
1568
|
+
/**
|
|
1569
|
+
* Agent resource class
|
|
1570
|
+
* Provides methods for creating and managing AI agent jobs
|
|
1571
|
+
*
|
|
1572
|
+
* The agent uses the ReAct pattern (Observation → Thought → Action → Evaluation)
|
|
1573
|
+
* to navigate web pages and extract structured data based on natural language instructions.
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```ts
|
|
1577
|
+
* // Create an agent to search and extract product info
|
|
1578
|
+
* const job = await client.agent.create({
|
|
1579
|
+
* url: "https://amazon.com",
|
|
1580
|
+
* prompt: "Search for wireless headphones under $50 and extract the top 5 results with name, price, and rating",
|
|
1581
|
+
* schema: {
|
|
1582
|
+
* type: "object",
|
|
1583
|
+
* properties: {
|
|
1584
|
+
* products: {
|
|
1585
|
+
* type: "array",
|
|
1586
|
+
* items: {
|
|
1587
|
+
* type: "object",
|
|
1588
|
+
* properties: {
|
|
1589
|
+
* name: { type: "string" },
|
|
1590
|
+
* price: { type: "number" },
|
|
1591
|
+
* rating: { type: "number" }
|
|
1592
|
+
* }
|
|
1593
|
+
* }
|
|
1594
|
+
* }
|
|
1595
|
+
* }
|
|
1596
|
+
* },
|
|
1597
|
+
* maxSteps: 15
|
|
1598
|
+
* });
|
|
1599
|
+
*
|
|
1600
|
+
* // Wait for result
|
|
1601
|
+
* const result = await client.waitForResult(job.jobId);
|
|
1602
|
+
* ```
|
|
1603
|
+
*/
|
|
1604
|
+
declare class AgentResource {
|
|
1605
|
+
private ctx;
|
|
1606
|
+
constructor(ctx: RequestContext);
|
|
1607
|
+
/**
|
|
1608
|
+
* Create a new AI agent job
|
|
1609
|
+
*
|
|
1610
|
+
* @param options - Agent configuration options
|
|
1611
|
+
* @returns Job creation response with jobId and status URL
|
|
1612
|
+
*
|
|
1613
|
+
* @example
|
|
1614
|
+
* ```ts
|
|
1615
|
+
* const job = await client.agent.create({
|
|
1616
|
+
* url: "https://booking.com",
|
|
1617
|
+
* prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
|
|
1618
|
+
* maxSteps: 20,
|
|
1619
|
+
* takeScreenshots: true
|
|
1620
|
+
* });
|
|
1621
|
+
* ```
|
|
1622
|
+
*/
|
|
1623
|
+
create(options: AgentOptions): Promise<AgentJobResponse>;
|
|
1624
|
+
/**
|
|
1625
|
+
* Get the status of an agent job
|
|
1626
|
+
*
|
|
1627
|
+
* @param jobId - The job ID to check
|
|
1628
|
+
* @returns Agent status with progress and partial results
|
|
1629
|
+
*
|
|
1630
|
+
* @example
|
|
1631
|
+
* ```ts
|
|
1632
|
+
* const status = await client.agent.getStatus(jobId);
|
|
1633
|
+
* console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
|
|
1634
|
+
* ```
|
|
1635
|
+
*/
|
|
1636
|
+
getStatus(jobId: string): Promise<AgentStatusResponse>;
|
|
1637
|
+
/**
|
|
1638
|
+
* Create an agent with preset actions
|
|
1639
|
+
* Useful for handling common scenarios like cookie consent, popups, etc.
|
|
1640
|
+
*
|
|
1641
|
+
* @example
|
|
1642
|
+
* ```ts
|
|
1643
|
+
* const job = await client.agent.withPresetActions(
|
|
1644
|
+
* "https://shop.com",
|
|
1645
|
+
* "Find the best discount and extract product details",
|
|
1646
|
+
* [
|
|
1647
|
+
* { type: "click", selector: "#accept-cookies" },
|
|
1648
|
+
* { type: "wait", milliseconds: 1000 }
|
|
1649
|
+
* ]
|
|
1650
|
+
* );
|
|
1651
|
+
* ```
|
|
1652
|
+
*/
|
|
1653
|
+
withPresetActions(url: string, prompt: string, actions: AgentOptions["actions"], options?: Omit<AgentOptions, "url" | "prompt" | "actions">): Promise<AgentJobResponse>;
|
|
1654
|
+
/**
|
|
1655
|
+
* Create an agent with a JSON schema for structured output
|
|
1656
|
+
* The agent will extract data matching the provided schema
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```ts
|
|
1660
|
+
* const job = await client.agent.withSchema(
|
|
1661
|
+
* "https://linkedin.com/company/example",
|
|
1662
|
+
* "Extract company information",
|
|
1663
|
+
* {
|
|
1664
|
+
* type: "object",
|
|
1665
|
+
* properties: {
|
|
1666
|
+
* name: { type: "string" },
|
|
1667
|
+
* employees: { type: "number" },
|
|
1668
|
+
* description: { type: "string" },
|
|
1669
|
+
* website: { type: "string" }
|
|
1670
|
+
* },
|
|
1671
|
+
* required: ["name"]
|
|
1672
|
+
* }
|
|
1673
|
+
* );
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
withSchema(url: string, prompt: string, schema: Record<string, unknown>, options?: Omit<AgentOptions, "url" | "prompt" | "schema">): Promise<AgentJobResponse>;
|
|
1677
|
+
/**
|
|
1678
|
+
* Create an agent optimized for deal/product extraction
|
|
1679
|
+
* Pre-configured for e-commerce scenarios
|
|
1680
|
+
*
|
|
1681
|
+
* @example
|
|
1682
|
+
* ```ts
|
|
1683
|
+
* const job = await client.agent.forDeals(
|
|
1684
|
+
* "https://slickdeals.net",
|
|
1685
|
+
* "Find the top 10 tech deals posted today"
|
|
1686
|
+
* );
|
|
1687
|
+
* ```
|
|
1688
|
+
*/
|
|
1689
|
+
forDeals(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "schema">): Promise<AgentJobResponse>;
|
|
1690
|
+
/**
|
|
1691
|
+
* Create an agent to fill and submit a form
|
|
1692
|
+
* Useful for search forms, login forms, etc.
|
|
1693
|
+
*
|
|
1694
|
+
* @example
|
|
1695
|
+
* ```ts
|
|
1696
|
+
* const job = await client.agent.fillForm(
|
|
1697
|
+
* "https://kayak.com",
|
|
1698
|
+
* "Search for flights from Paris to New York on March 20, return March 27",
|
|
1699
|
+
* { takeScreenshots: true }
|
|
1700
|
+
* );
|
|
1701
|
+
* ```
|
|
1702
|
+
*/
|
|
1703
|
+
fillForm(url: string, instructions: string, options?: Omit<AgentOptions, "url" | "prompt">): Promise<AgentJobResponse>;
|
|
1704
|
+
/**
|
|
1705
|
+
* Create an agent using Claude (Anthropic) instead of GPT
|
|
1706
|
+
*
|
|
1707
|
+
* @example
|
|
1708
|
+
* ```ts
|
|
1709
|
+
* const job = await client.agent.withClaude(
|
|
1710
|
+
* "https://complex-site.com",
|
|
1711
|
+
* "Navigate through the multi-step checkout process"
|
|
1712
|
+
* );
|
|
1713
|
+
* ```
|
|
1714
|
+
*/
|
|
1715
|
+
withClaude(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "model">): Promise<AgentJobResponse>;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1395
1718
|
/**
|
|
1396
1719
|
* Crawl Resource
|
|
1397
1720
|
* Handles website crawling operations
|
|
@@ -2504,6 +2827,29 @@ declare class DealCrawl {
|
|
|
2504
2827
|
* ```
|
|
2505
2828
|
*/
|
|
2506
2829
|
readonly dork: DorkResource;
|
|
2830
|
+
/**
|
|
2831
|
+
* Agent resource - AI-powered autonomous web navigation
|
|
2832
|
+
*
|
|
2833
|
+
* The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
|
|
2834
|
+
* to navigate web pages and extract structured data based on natural language.
|
|
2835
|
+
*
|
|
2836
|
+
* @example
|
|
2837
|
+
* ```ts
|
|
2838
|
+
* const job = await client.agent.create({
|
|
2839
|
+
* url: "https://amazon.com",
|
|
2840
|
+
* prompt: "Search for wireless headphones under $50 and extract top 5 results",
|
|
2841
|
+
* maxSteps: 15
|
|
2842
|
+
* });
|
|
2843
|
+
*
|
|
2844
|
+
* // With schema for structured output
|
|
2845
|
+
* const job = await client.agent.withSchema(
|
|
2846
|
+
* "https://example.com",
|
|
2847
|
+
* "Extract product info",
|
|
2848
|
+
* { type: "object", properties: {...} }
|
|
2849
|
+
* );
|
|
2850
|
+
* ```
|
|
2851
|
+
*/
|
|
2852
|
+
readonly agent: AgentResource;
|
|
2507
2853
|
/**
|
|
2508
2854
|
* Status resource - Job status management
|
|
2509
2855
|
*
|
|
@@ -2683,6 +3029,21 @@ declare class DealCrawl {
|
|
|
2683
3029
|
* ```
|
|
2684
3030
|
*/
|
|
2685
3031
|
searchAndWait(options: Parameters<SearchResource["create"]>[0]): Promise<ReturnType<SearchResource["create"]>>;
|
|
3032
|
+
/**
|
|
3033
|
+
* Create an agent job and wait for result
|
|
3034
|
+
* Combines create and waitForResult
|
|
3035
|
+
*
|
|
3036
|
+
* @example
|
|
3037
|
+
* ```ts
|
|
3038
|
+
* const result = await client.agentAndWait({
|
|
3039
|
+
* url: "https://booking.com",
|
|
3040
|
+
* prompt: "Find hotels in Paris for March 15-17",
|
|
3041
|
+
* maxSteps: 20
|
|
3042
|
+
* });
|
|
3043
|
+
* console.log(result.data);
|
|
3044
|
+
* ```
|
|
3045
|
+
*/
|
|
3046
|
+
agentAndWait<T = unknown>(options: Parameters<AgentResource["create"]>[0], waitOptions?: WaitOptions): Promise<WaitResult<T>>;
|
|
2686
3047
|
}
|
|
2687
3048
|
|
|
2688
3049
|
/**
|
|
@@ -2766,4 +3127,4 @@ declare class DealCrawlError extends Error {
|
|
|
2766
3127
|
}, retryAfter?: number | string | null): DealCrawlError;
|
|
2767
3128
|
}
|
|
2768
3129
|
|
|
2769
|
-
export { ALL_API_KEY_SCOPES, type AccountInfoResponse, type AccountMetricsResponse, AccountResource, type ApiError, type ApiKeyInfo, type ApiKeyScope, type ApiResponse, type BatchScrapeDefaults, type BatchScrapeItem, type BatchScrapeOptions, type BatchScrapeResponse, type BatchScrapeResultItem, type BatchStatusResponse, type CancelJobResponse, type CheckpointInfo, type ClientPreferences, type ClientStatsResponse, type CrawlAnalysisResponse, type CrawlJobResponse, type CrawlOptions, type CrawlRecommendation, CrawlResource, type CrawlResult, type CrawlTemplate, type CrawlTemplateId, type CreateApiKeyOptions, type CreateKeyResponse, type CreateWebhookOptions, type CreateWebhookResponse, type CreatedApiKey, DEFAULT_API_KEY_SCOPES, DEFAULT_CONFIG, DataResource, DealCrawl, type DealCrawlConfig, DealCrawlError, type DealDetails, type DealItem, type DealMetrics, type DealScoreSummary, type DealSummary, type DealUpMetrics, type DealUpMetricsResponse, type DeleteKeyResponse, type DeleteWebhookResponse, type DiscountSignal, type DorkJobResponse, type DorkOptions, DorkResource, type DorkResult, ERROR_CODES, type ErrorCode, type ExportDealsOptions, type ExportFormat, type ExportJobsOptions, type ExtractJobResponse, type ExtractModel, type ExtractOptions, ExtractResource, type ExtractedDeal, type GetApiKeyStatsOptions, type GetDealsOptions, type JobDealsResponse, type JobMetricsResponse, type JobResponse, type JobStatus, type JobStatusFilter, type JobStatusResponse, type JobSummary, type JobTypeFilter, type KeyStatsResponse, KeysResource, type ListApiKeysOptions, type ListDealsOptions, type ListDealsResponse, type ListJobsOptions, type ListJobsResponse, type ListKeysResponse, type ListWebhooksResponse, type PaginatedResponse, type PaginationInfo, type ParsedPage, type PreferencesResponse, type PriceSignal, type PricingInfo, type ProductCategory, type ProductInfo, type RateLimitInfo, type RecommendationsResponse, type RequestContext, type ResumeJobResponse, type RevokeApiKeyOptions, type RotateApiKeyOptions, type RotateKeyResponse, type ScrapeJobResponse, type ScrapeOptions, ScrapeResource, type ScrapeResult, type ScreenshotOptions, type SearchAiModel, type SearchAiProvider, type SearchData, type SearchDateRange, type SearchFilters, type SearchJobResponse, type SearchOptions, SearchResource, type SearchResultItem, type SearchStatusResponse, type Signal, type SortOrder, StatusResource, type TestWebhookResponse, type UpdatePreferencesOptions, type UpdatePreferencesResponse, type UpdateWebhookOptions, type UpdateWebhookResponse, type UsageStats, type WaitOptions, type WaitResult, type WebhookEvent, type WebhookItem, WebhooksResource, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };
|
|
3130
|
+
export { ALL_API_KEY_SCOPES, type AccountInfoResponse, type AccountMetricsResponse, AccountResource, type AgentAction, type AgentActionType, type AgentCompletionReason, type AgentJobResponse, type AgentModel, type AgentOptions, AgentResource, type AgentResultResponse, type AgentStatusResponse, type AgentStepResponse, type ApiError, type ApiKeyInfo, type ApiKeyScope, type ApiResponse, type BatchScrapeDefaults, type BatchScrapeItem, type BatchScrapeOptions, type BatchScrapeResponse, type BatchScrapeResultItem, type BatchStatusResponse, type CancelJobResponse, type CheckpointInfo, type ClickAction, type ClientPreferences, type ClientStatsResponse, type CrawlAnalysisResponse, type CrawlJobResponse, type CrawlOptions, type CrawlRecommendation, CrawlResource, type CrawlResult, type CrawlTemplate, type CrawlTemplateId, type CreateApiKeyOptions, type CreateKeyResponse, type CreateWebhookOptions, type CreateWebhookResponse, type CreatedApiKey, DEFAULT_API_KEY_SCOPES, DEFAULT_CONFIG, DataResource, DealCrawl, type DealCrawlConfig, DealCrawlError, type DealDetails, type DealItem, type DealMetrics, type DealScoreSummary, type DealSummary, type DealUpMetrics, type DealUpMetricsResponse, type DeleteKeyResponse, type DeleteWebhookResponse, type DiscountSignal, type DorkJobResponse, type DorkOptions, DorkResource, type DorkResult, ERROR_CODES, type ErrorCode, type ExportDealsOptions, type ExportFormat, type ExportJobsOptions, type ExtractJobResponse, type ExtractModel, type ExtractOptions, ExtractResource, type ExtractedDeal, type GetApiKeyStatsOptions, type GetDealsOptions, type HoverAction, type JobDealsResponse, type JobMetricsResponse, type JobResponse, type JobStatus, type JobStatusFilter, type JobStatusResponse, type JobSummary, type JobTypeFilter, type KeyStatsResponse, KeysResource, type ListApiKeysOptions, type ListDealsOptions, type ListDealsResponse, type ListJobsOptions, type ListJobsResponse, type ListKeysResponse, type ListWebhooksResponse, type PaginatedResponse, type PaginationInfo, type ParsedPage, type PreferencesResponse, type PressAction, type PriceSignal, type PricingInfo, type ProductCategory, type ProductInfo, type RateLimitInfo, type RecommendationsResponse, type RequestContext, type ResumeJobResponse, type RevokeApiKeyOptions, type RotateApiKeyOptions, type RotateKeyResponse, type ScrapeJobResponse, type ScrapeOptions, ScrapeResource, type ScrapeResult, type ScreenshotAgentAction, type ScreenshotOptions, type ScrollAction, type SearchAiModel, type SearchAiProvider, type SearchData, type SearchDateRange, type SearchFilters, type SearchJobResponse, type SearchOptions, SearchResource, type SearchResultItem, type SearchStatusResponse, type SelectAction, type Signal, type SortOrder, StatusResource, type TestWebhookResponse, type UpdatePreferencesOptions, type UpdatePreferencesResponse, type UpdateWebhookOptions, type UpdateWebhookResponse, type UsageStats, type WaitAction, type WaitOptions, type WaitResult, type WebhookEvent, type WebhookItem, WebhooksResource, type WriteAction, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };
|
package/dist/index.js
CHANGED
|
@@ -589,6 +589,203 @@ var AccountResource = class {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
|
|
592
|
+
// src/resources/agent.ts
|
|
593
|
+
var AgentResource = class {
|
|
594
|
+
constructor(ctx) {
|
|
595
|
+
this.ctx = ctx;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Create a new AI agent job
|
|
599
|
+
*
|
|
600
|
+
* @param options - Agent configuration options
|
|
601
|
+
* @returns Job creation response with jobId and status URL
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```ts
|
|
605
|
+
* const job = await client.agent.create({
|
|
606
|
+
* url: "https://booking.com",
|
|
607
|
+
* prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
|
|
608
|
+
* maxSteps: 20,
|
|
609
|
+
* takeScreenshots: true
|
|
610
|
+
* });
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
async create(options) {
|
|
614
|
+
const body = {
|
|
615
|
+
url: options.url,
|
|
616
|
+
urls: options.urls,
|
|
617
|
+
prompt: options.prompt,
|
|
618
|
+
schema: options.schema,
|
|
619
|
+
maxSteps: options.maxSteps ?? 10,
|
|
620
|
+
actions: options.actions,
|
|
621
|
+
model: options.model ?? "openai",
|
|
622
|
+
timeout: options.timeout ?? 3e4,
|
|
623
|
+
onlyMainContent: options.onlyMainContent ?? true,
|
|
624
|
+
takeScreenshots: options.takeScreenshots ?? false,
|
|
625
|
+
headers: options.headers,
|
|
626
|
+
webhook: options.webhook
|
|
627
|
+
};
|
|
628
|
+
const result = await post(this.ctx, "/v1/agent", body);
|
|
629
|
+
return result.data;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get the status of an agent job
|
|
633
|
+
*
|
|
634
|
+
* @param jobId - The job ID to check
|
|
635
|
+
* @returns Agent status with progress and partial results
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* const status = await client.agent.getStatus(jobId);
|
|
640
|
+
* console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
async getStatus(jobId) {
|
|
644
|
+
const result = await get(
|
|
645
|
+
this.ctx,
|
|
646
|
+
`/v1/status/${jobId}`
|
|
647
|
+
);
|
|
648
|
+
return result.data;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Create an agent with preset actions
|
|
652
|
+
* Useful for handling common scenarios like cookie consent, popups, etc.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* const job = await client.agent.withPresetActions(
|
|
657
|
+
* "https://shop.com",
|
|
658
|
+
* "Find the best discount and extract product details",
|
|
659
|
+
* [
|
|
660
|
+
* { type: "click", selector: "#accept-cookies" },
|
|
661
|
+
* { type: "wait", milliseconds: 1000 }
|
|
662
|
+
* ]
|
|
663
|
+
* );
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
async withPresetActions(url, prompt, actions, options) {
|
|
667
|
+
return this.create({
|
|
668
|
+
url,
|
|
669
|
+
prompt,
|
|
670
|
+
actions,
|
|
671
|
+
...options
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Create an agent with a JSON schema for structured output
|
|
676
|
+
* The agent will extract data matching the provided schema
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* const job = await client.agent.withSchema(
|
|
681
|
+
* "https://linkedin.com/company/example",
|
|
682
|
+
* "Extract company information",
|
|
683
|
+
* {
|
|
684
|
+
* type: "object",
|
|
685
|
+
* properties: {
|
|
686
|
+
* name: { type: "string" },
|
|
687
|
+
* employees: { type: "number" },
|
|
688
|
+
* description: { type: "string" },
|
|
689
|
+
* website: { type: "string" }
|
|
690
|
+
* },
|
|
691
|
+
* required: ["name"]
|
|
692
|
+
* }
|
|
693
|
+
* );
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
async withSchema(url, prompt, schema, options) {
|
|
697
|
+
return this.create({
|
|
698
|
+
url,
|
|
699
|
+
prompt,
|
|
700
|
+
schema,
|
|
701
|
+
...options
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Create an agent optimized for deal/product extraction
|
|
706
|
+
* Pre-configured for e-commerce scenarios
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* const job = await client.agent.forDeals(
|
|
711
|
+
* "https://slickdeals.net",
|
|
712
|
+
* "Find the top 10 tech deals posted today"
|
|
713
|
+
* );
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
async forDeals(url, prompt, options) {
|
|
717
|
+
return this.create({
|
|
718
|
+
url,
|
|
719
|
+
prompt: `${prompt}. Extract deal information including: product name, current price, original price (if available), discount percentage, merchant/store, and any promo codes or coupons.`,
|
|
720
|
+
schema: {
|
|
721
|
+
type: "object",
|
|
722
|
+
properties: {
|
|
723
|
+
deals: {
|
|
724
|
+
type: "array",
|
|
725
|
+
items: {
|
|
726
|
+
type: "object",
|
|
727
|
+
properties: {
|
|
728
|
+
productName: { type: "string" },
|
|
729
|
+
currentPrice: { type: "number" },
|
|
730
|
+
originalPrice: { type: "number" },
|
|
731
|
+
discountPercent: { type: "number" },
|
|
732
|
+
merchant: { type: "string" },
|
|
733
|
+
promoCode: { type: "string" },
|
|
734
|
+
url: { type: "string" },
|
|
735
|
+
expiresAt: { type: "string" }
|
|
736
|
+
},
|
|
737
|
+
required: ["productName", "currentPrice"]
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
required: ["deals"]
|
|
742
|
+
},
|
|
743
|
+
maxSteps: options?.maxSteps ?? 15,
|
|
744
|
+
...options
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Create an agent to fill and submit a form
|
|
749
|
+
* Useful for search forms, login forms, etc.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```ts
|
|
753
|
+
* const job = await client.agent.fillForm(
|
|
754
|
+
* "https://kayak.com",
|
|
755
|
+
* "Search for flights from Paris to New York on March 20, return March 27",
|
|
756
|
+
* { takeScreenshots: true }
|
|
757
|
+
* );
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
async fillForm(url, instructions, options) {
|
|
761
|
+
return this.create({
|
|
762
|
+
url,
|
|
763
|
+
prompt: `Navigate to the form and ${instructions}. After submitting, extract the results.`,
|
|
764
|
+
maxSteps: options?.maxSteps ?? 12,
|
|
765
|
+
...options
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Create an agent using Claude (Anthropic) instead of GPT
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* const job = await client.agent.withClaude(
|
|
774
|
+
* "https://complex-site.com",
|
|
775
|
+
* "Navigate through the multi-step checkout process"
|
|
776
|
+
* );
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
async withClaude(url, prompt, options) {
|
|
780
|
+
return this.create({
|
|
781
|
+
url,
|
|
782
|
+
prompt,
|
|
783
|
+
model: "anthropic",
|
|
784
|
+
...options
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
|
|
592
789
|
// src/resources/crawl.ts
|
|
593
790
|
var CRAWL_TEMPLATES = {
|
|
594
791
|
ecommerce: {
|
|
@@ -2278,6 +2475,29 @@ var DealCrawl = class {
|
|
|
2278
2475
|
* ```
|
|
2279
2476
|
*/
|
|
2280
2477
|
dork;
|
|
2478
|
+
/**
|
|
2479
|
+
* Agent resource - AI-powered autonomous web navigation
|
|
2480
|
+
*
|
|
2481
|
+
* The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
|
|
2482
|
+
* to navigate web pages and extract structured data based on natural language.
|
|
2483
|
+
*
|
|
2484
|
+
* @example
|
|
2485
|
+
* ```ts
|
|
2486
|
+
* const job = await client.agent.create({
|
|
2487
|
+
* url: "https://amazon.com",
|
|
2488
|
+
* prompt: "Search for wireless headphones under $50 and extract top 5 results",
|
|
2489
|
+
* maxSteps: 15
|
|
2490
|
+
* });
|
|
2491
|
+
*
|
|
2492
|
+
* // With schema for structured output
|
|
2493
|
+
* const job = await client.agent.withSchema(
|
|
2494
|
+
* "https://example.com",
|
|
2495
|
+
* "Extract product info",
|
|
2496
|
+
* { type: "object", properties: {...} }
|
|
2497
|
+
* );
|
|
2498
|
+
* ```
|
|
2499
|
+
*/
|
|
2500
|
+
agent;
|
|
2281
2501
|
/**
|
|
2282
2502
|
* Status resource - Job status management
|
|
2283
2503
|
*
|
|
@@ -2377,6 +2597,7 @@ var DealCrawl = class {
|
|
|
2377
2597
|
this.crawl = new CrawlResource(this.ctx);
|
|
2378
2598
|
this.extract = new ExtractResource(this.ctx);
|
|
2379
2599
|
this.dork = new DorkResource(this.ctx);
|
|
2600
|
+
this.agent = new AgentResource(this.ctx);
|
|
2380
2601
|
this.status = new StatusResource(this.ctx);
|
|
2381
2602
|
this.data = new DataResource(this.ctx);
|
|
2382
2603
|
this.webhooks = new WebhooksResource(this.ctx);
|
|
@@ -2505,9 +2726,28 @@ var DealCrawl = class {
|
|
|
2505
2726
|
async searchAndWait(options) {
|
|
2506
2727
|
return this.search.create(options);
|
|
2507
2728
|
}
|
|
2729
|
+
/**
|
|
2730
|
+
* Create an agent job and wait for result
|
|
2731
|
+
* Combines create and waitForResult
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```ts
|
|
2735
|
+
* const result = await client.agentAndWait({
|
|
2736
|
+
* url: "https://booking.com",
|
|
2737
|
+
* prompt: "Find hotels in Paris for March 15-17",
|
|
2738
|
+
* maxSteps: 20
|
|
2739
|
+
* });
|
|
2740
|
+
* console.log(result.data);
|
|
2741
|
+
* ```
|
|
2742
|
+
*/
|
|
2743
|
+
async agentAndWait(options, waitOptions) {
|
|
2744
|
+
const job = await this.agent.create(options);
|
|
2745
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
2746
|
+
}
|
|
2508
2747
|
};
|
|
2509
2748
|
|
|
2510
2749
|
exports.AccountResource = AccountResource;
|
|
2750
|
+
exports.AgentResource = AgentResource;
|
|
2511
2751
|
exports.CrawlResource = CrawlResource;
|
|
2512
2752
|
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
2513
2753
|
exports.DataResource = DataResource;
|