|
| 1 | +# @rtrvr-ai/core |
| 2 | + |
| 3 | +Low-level client, types, and HTTP transport for RTRVR cloud and MCP endpoints. This package powers `@rtrvr-ai/sdk` and `@rtrvr-ai/cli`. |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @rtrvr-ai/core |
| 9 | +``` |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- Node.js 18+ |
| 14 | +- ESM (`"type": "module"`) |
| 15 | + |
| 16 | +## Quickstart |
| 17 | + |
| 18 | +```ts |
| 19 | +import { RtrvrClient } from '@rtrvr-ai/core'; |
| 20 | + |
| 21 | +const client = new RtrvrClient({ |
| 22 | + apiKey: process.env.RTRVR_API_KEY!, |
| 23 | + defaultTarget: 'auto', |
| 24 | +}); |
| 25 | + |
| 26 | +const run = await client.run({ |
| 27 | + input: 'Extract the top 5 products and prices', |
| 28 | + urls: ['https://example.com'], |
| 29 | +}); |
| 30 | + |
| 31 | +console.log(run.metadata, run.data); |
| 32 | +``` |
| 33 | + |
| 34 | +## Cloud agent and scrape |
| 35 | + |
| 36 | +```ts |
| 37 | +// Cloud /agent (requires rtrvr_ API key) |
| 38 | +const agent = await client.agentRun({ |
| 39 | + input: 'Summarize this page', |
| 40 | + urls: ['https://example.com'], |
| 41 | +}); |
| 42 | + |
| 43 | +// Cloud /scrape (requires rtrvr_ API key) |
| 44 | +const scrape = await client.scrapeRun({ |
| 45 | + urls: ['https://example.com'], |
| 46 | +}); |
| 47 | +``` |
| 48 | + |
| 49 | +## MCP tools and extension routing |
| 50 | + |
| 51 | +```ts |
| 52 | +// Call a tool directly through MCP |
| 53 | +const extracted = await client.toolRun({ |
| 54 | + tool: 'extract_from_tab', |
| 55 | + params: { |
| 56 | + user_input: 'Extract all product names and prices', |
| 57 | + tab_urls: ['https://example.com/products'], |
| 58 | + }, |
| 59 | +}); |
| 60 | + |
| 61 | +// List online extension devices |
| 62 | +const devices = await client.listDevices(); |
| 63 | +``` |
| 64 | + |
| 65 | +## Routing behavior |
| 66 | + |
| 67 | +- `run` and `scrape` support `target: 'cloud' | 'extension' | 'auto'`. |
| 68 | +- `auto` checks for online extension devices via `list_devices` and falls back to cloud when needed. |
| 69 | +- Use `deviceId` or `requireLocalSession: true` to force extension execution. |
| 70 | + |
| 71 | +## Auth tokens |
| 72 | + |
| 73 | +- `rtrvr_...` API keys can access cloud + MCP + control endpoints. |
| 74 | +- `mcp_at_...` tokens are limited to MCP endpoints. Cloud calls throw an error. |
| 75 | + |
| 76 | +## Client options |
| 77 | + |
| 78 | +```ts |
| 79 | +interface ClientOptions { |
| 80 | + apiKey: string; |
| 81 | + cloudBaseUrl?: string; // default https://api.rtrvr.ai |
| 82 | + mcpBaseUrl?: string; // default https://mcp.rtrvr.ai |
| 83 | + controlBaseUrl?: string; // default https://cli.rtrvr.ai |
| 84 | + timeoutMs?: number; // default 9 minutes |
| 85 | + retryPolicy?: { |
| 86 | + maxAttempts?: number; // default 1 |
| 87 | + baseDelayMs?: number; // default 250ms |
| 88 | + maxDelayMs?: number; // default 4000ms |
| 89 | + retriableStatusCodes?: number[]; // default [408, 429, 500, 502, 503, 504] |
| 90 | + }; |
| 91 | + defaultTarget?: 'auto' | 'cloud' | 'extension'; // default 'auto' |
| 92 | + preferExtensionByDefault?: boolean; // default false |
| 93 | + defaultHeaders?: Record<string, string>; |
| 94 | + fetchImpl?: typeof fetch; // custom fetch for tests or runtime |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +## Request options |
| 99 | + |
| 100 | +### UnifiedRunRequest |
| 101 | + |
| 102 | +```ts |
| 103 | +interface UnifiedRunRequest { |
| 104 | + input: string; // task description |
| 105 | + urls?: string[]; // starting URLs |
| 106 | + schema?: Record<string, unknown>; // structured output schema |
| 107 | + files?: CloudFile[]; // structured file inputs |
| 108 | + fileUrls?: string[]; // URLs to files for context |
| 109 | + dataInputs?: unknown[]; // additional data inputs |
| 110 | + settings?: Record<string, unknown>; // agent settings |
| 111 | + tools?: Record<string, unknown>; // tool configuration |
| 112 | + options?: Record<string, unknown>; // execution options |
| 113 | + response?: { |
| 114 | + verbosity?: 'final' | 'steps' | 'debug'; // response detail level |
| 115 | + inlineOutputMaxBytes?: number; // output size limit |
| 116 | + }; |
| 117 | + webhooks?: WebhookSubscription[]; // event webhooks |
| 118 | + trajectoryId?: string; // workflow tracking ID |
| 119 | + phase?: number; // workflow phase number |
| 120 | + recordingContext?: string; // replay context |
| 121 | + authToken?: string; // Google OAuth token for Drive/Docs/Sheets |
| 122 | + target?: 'auto' | 'cloud' | 'extension'; // routing mode |
| 123 | + preferExtension?: boolean; // prefer extension in auto mode |
| 124 | + requireLocalSession?: boolean; // require extension or fail |
| 125 | + deviceId?: string; // target device ID |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +### Webhooks |
| 130 | + |
| 131 | +```ts |
| 132 | +interface WebhookSubscription { |
| 133 | + url: string; |
| 134 | + events?: string[]; // event types to subscribe to |
| 135 | + auth?: WebhookAuth; // authentication config |
| 136 | + secret?: string; // webhook signing secret |
| 137 | +} |
| 138 | + |
| 139 | +type WebhookAuth = |
| 140 | + | { type: 'bearer'; token: string } |
| 141 | + | { type: 'basic'; username: string; password: string }; |
| 142 | +``` |
| 143 | + |
| 144 | +## Tool names |
| 145 | + |
| 146 | +MCP tools are `snake_case` (for example: `planner`, `act_on_tab`, `extract_from_tab`, `crawl_and_extract_from_tab`, `scrape`, `list_devices`, `get_current_credits`, `cloud_agent`, `cloud_scrape`). |
| 147 | + |
| 148 | +Aliases are available for a few tool names: `act`, `extract`, `crawl`, `getPageData`, `listDevices`, `getCurrentCredits`. |
| 149 | + |
| 150 | +## Errors |
| 151 | + |
| 152 | +Requests throw `RtrvrError` with `status`, `requestId`, and optional `details` when available. |
0 commit comments