@mrscraper/ai-sdk 0.2.1 → 0.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.js CHANGED
@@ -1,116 +1,89 @@
1
- import { account, scraper_api } from "@mrscraper/sdk";
1
+ import { MrScraperError, getScreenshot, scrapeBrand, scrapeHtml, scrapeJson, scrapeMarkdown, status, webSearch, } from "@mrscraper/sdk";
2
2
  import { tool } from "ai";
3
- import { z } from "zod/v4";
4
- import { toPageModelOutput, toPageResult, toSearchResult, } from "./results.js";
5
- import { searchQuery, webSearch } from "./search.js";
3
+ import { getScreenshotInput, scrapeBrandInput, scrapeHtmlInput, scrapeJsonInput, scrapeMarkdownInput, statusInput, webSearchInput, } from "./inputs.js";
4
+ import { screenshotModelOutput } from "./model-output.js";
6
5
  function apiKey(options) {
7
- return options.apiKey ?? process.env.MRSCRAPER_API_KEY ?? undefined;
6
+ const key = options.apiKey || process.env.MRSCRAPER_API_KEY || process.env.MRSCRAPER_API_TOKEN || "";
7
+ if (!key.trim()) {
8
+ throw new MrScraperError("API key is not set. Pass apiKey or set MRSCRAPER_API_KEY. Get your key at https://app.mrscraper.com/api-tokens.");
9
+ }
10
+ return key;
11
+ }
12
+ /** Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields. */
13
+ export function statusTool(options = {}) {
14
+ return tool({
15
+ description: "Return the raw account status API response without summarizing, redacting body fields, or adding calculated fields.",
16
+ inputSchema: statusInput,
17
+ execute: async () => status({ token: apiKey(options) }),
18
+ });
19
+ }
20
+ /** Retrieve the raw HTML of a page. Browser rendering is optional. */
21
+ export function scrapeHtmlTool(options = {}) {
22
+ return tool({
23
+ description: "Retrieve the raw HTML of a page. Browser rendering is optional.",
24
+ inputSchema: scrapeHtmlInput,
25
+ execute: async ({ url, ...input }) => scrapeHtml(url, { ...input, token: apiKey(options) }),
26
+ });
27
+ }
28
+ /** Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON. */
29
+ export function scrapeMarkdownTool(options = {}) {
30
+ return tool({
31
+ description: "Retrieve a page as Markdown. Including HTML also enables browser rendering and returns both outputs as JSON.",
32
+ inputSchema: scrapeMarkdownInput,
33
+ execute: async ({ url, ...input }) => scrapeMarkdown(url, { ...input, token: apiKey(options) }),
34
+ });
8
35
  }
9
- const formatSchema = z.enum(["markdown", "html", "screenshot"]);
10
36
  /**
11
- * Retrieves a known public page as Markdown, HTML, a screenshot, or a
12
- * combination through MrScraper's Scraper API.
37
+ * Capture a base64 screenshot of the full page or top viewport. Browser
38
+ * rendering is always enabled. The model receives the screenshot as an image.
13
39
  */
14
- export function scraperApiTool(options = {}) {
40
+ export function getScreenshotTool(options = {}) {
15
41
  return tool({
16
- description: "Retrieve a known public web page through MrScraper as Markdown, HTML, a screenshot, or a combination. " +
17
- "Use Markdown for reading and summarizing; add html when exact markup or attributes matter. " +
18
- "MrScraper renders JavaScript-heavy pages in a browser when needed. Each call uses MrScraper plan tokens.",
19
- inputSchema: z.object({
20
- url: z.url({ protocol: /^https?$/ }).describe("Absolute http or https URL of the page."),
21
- formats: z
22
- .array(formatSchema)
23
- .min(1)
24
- .default(["markdown"])
25
- .describe("Representations to return. Defaults to markdown."),
26
- browserRendering: z
27
- .boolean()
28
- .optional()
29
- .describe("true forces a real browser, false disables it; omit for automatic fallback."),
30
- waitForSelector: z
31
- .string()
32
- .min(1)
33
- .optional()
34
- .describe("CSS selector to wait for before the page is captured."),
35
- geoCode: z
36
- .string()
37
- .length(2)
38
- .optional()
39
- .describe("Two-letter country code for the request location, such as US or GB."),
40
- timeout: z
41
- .number()
42
- .int()
43
- .min(1)
44
- .max(300)
45
- .optional()
46
- .describe("Page timeout in seconds, 1 to 300. Defaults to 120."),
47
- }),
48
- async execute({ url, formats, browserRendering, waitForSelector, geoCode, timeout }) {
49
- const requested = new Set(formats);
50
- const response = await scraper_api(url, {
51
- token: apiKey(options),
52
- markdown: requested.has("markdown"),
53
- html: requested.has("html"),
54
- screenshot: requested.has("screenshot"),
55
- browser_rendering: browserRendering ?? null,
56
- wait_for_selector: waitForSelector ?? null,
57
- ...(geoCode === undefined ? {} : { geo_code: geoCode.toUpperCase() }),
58
- ...(timeout === undefined ? {} : { timeout }),
59
- });
60
- return toPageResult(url, [...requested], response);
61
- },
62
- toModelOutput: ({ output }) => toPageModelOutput(output),
42
+ description: "Capture a base64 screenshot of the full page or top viewport. Browser rendering is always enabled.",
43
+ inputSchema: getScreenshotInput,
44
+ execute: async ({ url, ...input }) => getScreenshot(url, { ...input, token: apiKey(options) }),
45
+ toModelOutput: screenshotModelOutput,
63
46
  });
64
47
  }
65
- /** Searches the web through MrScraper and returns ranked results. */
66
- export function webSearchTool(options = {}) {
48
+ /** Extract a website's colors, typography, logos, and social links as JSON. */
49
+ export function scrapeBrandTool(options = {}) {
50
+ return tool({
51
+ description: "Extract a website's colors, typography, logos, and social links as JSON.",
52
+ inputSchema: scrapeBrandInput,
53
+ execute: async ({ url }) => scrapeBrand(url, { token: apiKey(options) }),
54
+ });
55
+ }
56
+ /**
57
+ * Extract structured JSON from a page using a natural-language prompt. Append
58
+ * Json Schema: and a JSON schema to shape the output. A requested screenshot
59
+ * reaches the model as an image.
60
+ */
61
+ export function scrapeJsonTool(options = {}) {
67
62
  return tool({
68
- description: "Search the web through MrScraper and get ranked results (rank, title, link, description, source). " +
69
- "Use it to discover pages when no URL is known, then retrieve chosen pages with the scraperAPI tool. " +
70
- "Each call uses MrScraper plan tokens.",
71
- inputSchema: z.object({
72
- query: z
73
- .string()
74
- .min(1)
75
- .describe("Search terms, or a search results URL whose q parameter is used."),
76
- region: z
77
- .string()
78
- .length(2)
79
- .optional()
80
- .describe("Two-letter country code for the results, such as us, gb, or id. Defaults to us."),
81
- numResults: z
82
- .number()
83
- .int()
84
- .min(10)
85
- .max(100)
86
- .optional()
87
- .describe("Number of results, from 10 to 100. Defaults to 10; fewer may come back."),
88
- }),
89
- async execute({ query, region, numResults }) {
90
- const searched = searchQuery(query);
91
- const response = await webSearch(apiKey(options), { query: searched, country: region, numResults });
92
- return toSearchResult(searched, response);
93
- },
63
+ description: "Extract structured JSON from a page using a natural-language prompt. Append Json Schema: and a JSON schema to shape the output.",
64
+ inputSchema: scrapeJsonInput,
65
+ execute: async ({ url, ...input }) => scrapeJson(url, { ...input, token: apiKey(options) }),
66
+ toModelOutput: screenshotModelOutput,
94
67
  });
95
68
  }
96
- /** Reports the MrScraper plan, token usage, and remaining tokens. */
97
- export function accountStatusTool(options = {}) {
69
+ /** Search the web and return ranked results with titles, URLs, descriptions, and sources. */
70
+ export function webSearchTool(options = {}) {
98
71
  return tool({
99
- description: "Show the connected MrScraper account's subscription status, token limit, tokens used, and tokens remaining. " +
100
- "Uses no tokens.",
101
- inputSchema: z.object({}),
102
- async execute() {
103
- const response = await account({ token: apiKey(options) });
104
- return response.data;
105
- },
72
+ description: "Search the web and return ranked results with titles, URLs, descriptions, and sources.",
73
+ inputSchema: webSearchInput,
74
+ execute: async ({ query, ...input }) => webSearch(query, { ...input, token: apiKey(options) }),
106
75
  });
107
76
  }
108
- /** All MrScraper tools, keyed by the names the MrScraper MCP server uses. */
77
+ /** All seven MrScraper tools, keyed by the names the Node SDK and MCP server use. */
109
78
  export function mrscraperTools(options = {}) {
110
79
  return {
111
- scraperAPI: scraperApiTool(options),
80
+ status: statusTool(options),
81
+ scrapeHtml: scrapeHtmlTool(options),
82
+ scrapeMarkdown: scrapeMarkdownTool(options),
83
+ getScreenshot: getScreenshotTool(options),
84
+ scrapeBrand: scrapeBrandTool(options),
85
+ scrapeJson: scrapeJsonTool(options),
112
86
  webSearch: webSearchTool(options),
113
- status: accountStatusTool(options),
114
87
  };
115
88
  }
116
89
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAuB,MAAM,gBAAgB,CAAC;AAC3E,O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C,UAAU,EAAE,cAAc,CAAC,OAAO,CAAC;QACnC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC;KAClC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,113 @@
1
+ import { z } from "zod/v4";
2
+ export declare const statusInput: z.ZodObject<{}, z.core.$strict>;
3
+ export declare const scrapeHtmlInput: z.ZodObject<{
4
+ browserRendering: z.ZodDefault<z.ZodBoolean>;
5
+ warmStart: z.ZodDefault<z.ZodBoolean>;
6
+ blockResources: z.ZodDefault<z.ZodBoolean>;
7
+ waitForSelector: z.ZodOptional<z.ZodString>;
8
+ returnCookie: z.ZodDefault<z.ZodBoolean>;
9
+ url: z.ZodURL;
10
+ timeout: z.ZodDefault<z.ZodNumber>;
11
+ geoCode: z.ZodDefault<z.ZodString>;
12
+ proxyCountry: z.ZodDefault<z.ZodString>;
13
+ super: z.ZodDefault<z.ZodBoolean>;
14
+ waitUntil: z.ZodDefault<z.ZodEnum<{
15
+ domcontentloaded: "domcontentloaded";
16
+ load: "load";
17
+ networkidle0: "networkidle0";
18
+ networkidle2: "networkidle2";
19
+ }>>;
20
+ proxy: z.ZodOptional<z.ZodString>;
21
+ maxRetries: z.ZodOptional<z.ZodNumber>;
22
+ saveResult: z.ZodDefault<z.ZodBoolean>;
23
+ }, z.core.$strict>;
24
+ export declare const scrapeMarkdownInput: z.ZodObject<{
25
+ browserRendering: z.ZodDefault<z.ZodBoolean>;
26
+ warmStart: z.ZodDefault<z.ZodBoolean>;
27
+ html: z.ZodDefault<z.ZodBoolean>;
28
+ blockResources: z.ZodDefault<z.ZodBoolean>;
29
+ waitForSelector: z.ZodOptional<z.ZodString>;
30
+ returnCookie: z.ZodDefault<z.ZodBoolean>;
31
+ url: z.ZodURL;
32
+ timeout: z.ZodDefault<z.ZodNumber>;
33
+ geoCode: z.ZodDefault<z.ZodString>;
34
+ proxyCountry: z.ZodDefault<z.ZodString>;
35
+ super: z.ZodDefault<z.ZodBoolean>;
36
+ waitUntil: z.ZodDefault<z.ZodEnum<{
37
+ domcontentloaded: "domcontentloaded";
38
+ load: "load";
39
+ networkidle0: "networkidle0";
40
+ networkidle2: "networkidle2";
41
+ }>>;
42
+ proxy: z.ZodOptional<z.ZodString>;
43
+ maxRetries: z.ZodOptional<z.ZodNumber>;
44
+ saveResult: z.ZodDefault<z.ZodBoolean>;
45
+ }, z.core.$strict>;
46
+ export declare const getScreenshotInput: z.ZodObject<{
47
+ screenshot: z.ZodDefault<z.ZodEnum<{
48
+ full: "full";
49
+ top: "top";
50
+ }>>;
51
+ html: z.ZodDefault<z.ZodBoolean>;
52
+ markdown: z.ZodDefault<z.ZodBoolean>;
53
+ blockResources: z.ZodDefault<z.ZodBoolean>;
54
+ waitForSelector: z.ZodOptional<z.ZodString>;
55
+ returnCookie: z.ZodDefault<z.ZodBoolean>;
56
+ url: z.ZodURL;
57
+ timeout: z.ZodDefault<z.ZodNumber>;
58
+ geoCode: z.ZodDefault<z.ZodString>;
59
+ proxyCountry: z.ZodDefault<z.ZodString>;
60
+ super: z.ZodDefault<z.ZodBoolean>;
61
+ waitUntil: z.ZodDefault<z.ZodEnum<{
62
+ domcontentloaded: "domcontentloaded";
63
+ load: "load";
64
+ networkidle0: "networkidle0";
65
+ networkidle2: "networkidle2";
66
+ }>>;
67
+ proxy: z.ZodOptional<z.ZodString>;
68
+ maxRetries: z.ZodOptional<z.ZodNumber>;
69
+ saveResult: z.ZodDefault<z.ZodBoolean>;
70
+ }, z.core.$strict>;
71
+ export declare const scrapeBrandInput: z.ZodObject<{
72
+ url: z.ZodURL;
73
+ }, z.core.$strict>;
74
+ export declare const scrapeJsonInput: z.ZodObject<{
75
+ prompt: z.ZodDefault<z.ZodString>;
76
+ browserRendering: z.ZodDefault<z.ZodBoolean>;
77
+ html: z.ZodDefault<z.ZodBoolean>;
78
+ screenshot: z.ZodDefault<z.ZodBoolean>;
79
+ url: z.ZodURL;
80
+ timeout: z.ZodDefault<z.ZodNumber>;
81
+ geoCode: z.ZodDefault<z.ZodString>;
82
+ proxyCountry: z.ZodDefault<z.ZodString>;
83
+ super: z.ZodDefault<z.ZodBoolean>;
84
+ waitUntil: z.ZodDefault<z.ZodEnum<{
85
+ domcontentloaded: "domcontentloaded";
86
+ load: "load";
87
+ networkidle0: "networkidle0";
88
+ networkidle2: "networkidle2";
89
+ }>>;
90
+ proxy: z.ZodOptional<z.ZodString>;
91
+ maxRetries: z.ZodOptional<z.ZodNumber>;
92
+ saveResult: z.ZodDefault<z.ZodBoolean>;
93
+ }, z.core.$strict>;
94
+ export declare const webSearchInput: z.ZodObject<{
95
+ query: z.ZodString;
96
+ country: z.ZodDefault<z.ZodString>;
97
+ numResults: z.ZodDefault<z.ZodNumber>;
98
+ }, z.core.$strict>;
99
+ /** Input of the status tool after validation. */
100
+ export type StatusInput = z.infer<typeof statusInput>;
101
+ /** Input of the scrapeHtml tool after validation and defaults. */
102
+ export type ScrapeHtmlInput = z.infer<typeof scrapeHtmlInput>;
103
+ /** Input of the scrapeMarkdown tool after validation and defaults. */
104
+ export type ScrapeMarkdownInput = z.infer<typeof scrapeMarkdownInput>;
105
+ /** Input of the getScreenshot tool after validation and defaults. */
106
+ export type GetScreenshotInput = z.infer<typeof getScreenshotInput>;
107
+ /** Input of the scrapeBrand tool after validation. */
108
+ export type ScrapeBrandInput = z.infer<typeof scrapeBrandInput>;
109
+ /** Input of the scrapeJson tool after validation and defaults. */
110
+ export type ScrapeJsonInput = z.infer<typeof scrapeJsonInput>;
111
+ /** Input of the webSearch tool after validation and defaults. */
112
+ export type WebSearchInput = z.infer<typeof webSearchInput>;
113
+ //# sourceMappingURL=inputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAoE3B,eAAO,MAAM,WAAW,iCAAqB,CAAC;AAE9C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;kBAAuE,CAAC;AAEpG,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;kBAM9B,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;kBAS7B,CAAC;AAEH,eAAO,MAAM,gBAAgB;;kBAA0B,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;kBAa1B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;kBAezB,CAAC;AAEH,iDAAiD;AACjD,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AACtD,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC9D,sEAAsE;AACtE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACtE,qEAAqE;AACrE,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,sDAAsD;AACtD,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAChE,kEAAkE;AAClE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAC9D,iEAAiE;AACjE,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
package/dist/inputs.js ADDED
@@ -0,0 +1,108 @@
1
+ import { z } from "zod/v4";
2
+ // Field names, defaults, and descriptions follow the MrScraper Integrations
3
+ // Standard. Copy description text exactly when changing them.
4
+ const url = z.url({ protocol: /^https?$/ }).describe("Absolute HTTP or HTTPS URL of the page to process.");
5
+ const countryCode = z
6
+ .string()
7
+ .regex(/^[A-Za-z]{2}$/)
8
+ .default("us");
9
+ /** Page controls shared by HTML, Markdown, screenshots, and JSON extraction. */
10
+ const page = {
11
+ url,
12
+ timeout: z
13
+ .number()
14
+ .int()
15
+ .min(1)
16
+ .max(300)
17
+ .default(300)
18
+ .describe("Page load timeout in seconds, from 1 to 300. The HTTP request allows 30 additional seconds."),
19
+ geoCode: countryCode.describe("Two-letter country code to load the page from, sent in lowercase."),
20
+ proxyCountry: countryCode.describe("Two-letter country code of the proxy server, sent in lowercase."),
21
+ super: z.boolean().default(false).describe("Whether to route the request through real devices."),
22
+ waitUntil: z
23
+ .enum(["domcontentloaded", "load", "networkidle0", "networkidle2"])
24
+ .default("domcontentloaded")
25
+ .describe("Navigation completion event to wait for: domcontentloaded, load, networkidle0, or networkidle2."),
26
+ proxy: z.string().trim().min(1).optional().describe("Custom proxy URL used to load the page."),
27
+ maxRetries: z
28
+ .number()
29
+ .int()
30
+ .min(0)
31
+ .optional()
32
+ .describe("Maximum number of retries, as a nonnegative integer. Omit this parameter for no limit."),
33
+ saveResult: z.boolean().default(false).describe("Whether to save the result to the dashboard Result tab."),
34
+ };
35
+ /** Loading controls shared by HTML, Markdown, and screenshots. */
36
+ const loading = {
37
+ blockResources: z
38
+ .boolean()
39
+ .default(false)
40
+ .describe("Whether to block images, fonts, and stylesheets while loading the page."),
41
+ waitForSelector: z
42
+ .string()
43
+ .trim()
44
+ .min(1)
45
+ .optional()
46
+ .describe("Wait for the page to contain the specified CSS selector before returning the result."),
47
+ returnCookie: z.boolean().default(false).describe("Whether to include browser session cookies in the response."),
48
+ };
49
+ const browserRendering = z
50
+ .boolean()
51
+ .default(false)
52
+ .describe("Whether to render the page in a browser before returning the result.");
53
+ const warmStart = z
54
+ .boolean()
55
+ .default(false)
56
+ .describe("Whether to enable warm start for more reliable scraping, at the cost of additional latency.");
57
+ function html(defaultValue) {
58
+ return z.boolean().default(defaultValue).describe("Whether to include the page HTML in the response.");
59
+ }
60
+ export const statusInput = z.strictObject({});
61
+ export const scrapeHtmlInput = z.strictObject({ ...page, ...loading, browserRendering, warmStart });
62
+ export const scrapeMarkdownInput = z.strictObject({
63
+ ...page,
64
+ ...loading,
65
+ browserRendering,
66
+ warmStart,
67
+ html: html(false),
68
+ });
69
+ export const getScreenshotInput = z.strictObject({
70
+ ...page,
71
+ ...loading,
72
+ screenshot: z
73
+ .enum(["full", "top"])
74
+ .default("full")
75
+ .describe("Screenshot area to capture: full for the entire page or top for the top viewport."),
76
+ html: html(true),
77
+ markdown: z.boolean().default(false).describe("Whether to include the page Markdown in the response."),
78
+ });
79
+ export const scrapeBrandInput = z.strictObject({ url });
80
+ export const scrapeJsonInput = z.strictObject({
81
+ ...page,
82
+ prompt: z
83
+ .string()
84
+ .min(1)
85
+ .refine((value) => value.trim() !== "", "prompt must be non-empty")
86
+ .default("Extract all data as complete as possible.")
87
+ .describe("Instructions describing the data to extract. Append Json Schema: and a JSON schema to shape the output."),
88
+ browserRendering,
89
+ html: html(false),
90
+ screenshot: z.boolean().default(false).describe("Whether to include a base64 screenshot in the response."),
91
+ });
92
+ export const webSearchInput = z.strictObject({
93
+ query: z
94
+ .string()
95
+ .trim()
96
+ .min(1)
97
+ .refine((value) => [...value].length <= 1000, "query must be 1 to 1000 characters")
98
+ .describe("Search query text, trimmed before sending, containing 1 to 1000 characters."),
99
+ country: countryCode.describe("Two-letter country code to search from, sent in lowercase."),
100
+ numResults: z
101
+ .number()
102
+ .int()
103
+ .min(10)
104
+ .max(100)
105
+ .default(10)
106
+ .describe("Number of search results to request, as an integer from 10 to 100. Fewer results may be returned."),
107
+ });
108
+ //# sourceMappingURL=inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.js","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,4EAA4E;AAC5E,8DAA8D;AAE9D,MAAM,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,oDAA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U,EAAE,CAAC;SACV,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,EAAE,CAAC;SACP,GAAG,CAAC,GAAG,CAAC;SACR,OAAO,CAAC,EAAE,CAAC;SACX,QAAQ,CAAC,mGAAmG,CAAC;CACjH,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { MrScraperResponse } from "@mrscraper/sdk";
2
+ import type { ToolResultPart } from "ai";
3
+ /**
4
+ * Sends a base64 screenshot to the model as an image part instead of a string
5
+ * inside JSON, which would cost hundreds of thousands of text tokens. Results
6
+ * without a screenshot go to the model as JSON, as the AI SDK sends them by
7
+ * default. The tool result itself keeps the screenshot.
8
+ */
9
+ export declare function screenshotModelOutput({ output }: {
10
+ output: MrScraperResponse;
11
+ }): ToolResultPart["output"];
12
+ //# sourceMappingURL=model-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-output.d.ts","sourceRoot":"","sources":["../src/model-output.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAa,cAAc,EAAE,MAAM,IAAI,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,iBAAiB,CAAA;CAAE,GAAG,cAAc,CAAC,QAAQ,CAAC,CAezG"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Sends a base64 screenshot to the model as an image part instead of a string
3
+ * inside JSON, which would cost hundreds of thousands of text tokens. Results
4
+ * without a screenshot go to the model as JSON, as the AI SDK sends them by
5
+ * default. The tool result itself keeps the screenshot.
6
+ */
7
+ export function screenshotModelOutput({ output }) {
8
+ const { data } = output;
9
+ if (data !== null && typeof data === "object" && !Array.isArray(data)) {
10
+ const { screenshot, ...rest } = data;
11
+ if (typeof screenshot === "string" && screenshot !== "") {
12
+ return {
13
+ type: "content",
14
+ value: [
15
+ { type: "text", text: JSON.stringify({ ...output, data: rest }) },
16
+ { type: "file", mediaType: "image", data: { type: "data", data: screenshot } },
17
+ ],
18
+ };
19
+ }
20
+ }
21
+ return { type: "json", value: JSON.parse(JSON.stringify(output)) };
22
+ }
23
+ //# sourceMappingURL=model-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-output.js","sourceRoot":"","sources":["../src/model-output.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAE,MAAM,EAAiC;IAC7E,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACxB,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,IAA+B,CAAC;QAChE,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;YACxD,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE;oBACjE,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE;iBAC/E;aACF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAc,EAAE,CAAC;AAClF,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mrscraper/ai-sdk",
3
- "version": "0.2.1",
4
- "description": "MrScraper tools for the Vercel AI SDK: retrieve public web pages as Markdown, HTML, or screenshots, search the web, and check account usage.",
3
+ "version": "0.3.0",
4
+ "description": "MrScraper tools for the Vercel AI SDK: retrieve public web pages as HTML, Markdown, or screenshots, extract brand details and structured JSON, search the web, and check account status.",
5
5
  "license": "MIT",
6
6
  "author": "MrScraper <support@mrscraper.com> (https://mrscraper.com)",
7
7
  "homepage": "https://docs.mrscraper.com/docs/integrations/vercel-ai-sdk",
@@ -44,7 +44,7 @@
44
44
  "prepublishOnly": "npm run typecheck && npm test && npm run build"
45
45
  },
46
46
  "dependencies": {
47
- "@mrscraper/sdk": "^5.0.0"
47
+ "@mrscraper/sdk": "^6.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "ai": "^7.0.0",
package/dist/results.d.ts DELETED
@@ -1,71 +0,0 @@
1
- /** Page formats the scraperAPI tool can return. */
2
- export type PageFormat = "markdown" | "html" | "screenshot";
3
- /** What the scraperAPI tool returns for one page. */
4
- export interface PageResult {
5
- url: string;
6
- /** HTTP status of the MrScraper API response, not of the target page. */
7
- statusCode: number;
8
- markdown?: string;
9
- html?: string;
10
- /**
11
- * Base64-encoded image (PNG or JPEG, depending on the page). Sent to the
12
- * model as an image, not as text.
13
- */
14
- screenshot?: string;
15
- /** MrScraper tokens this request used, when the API reports it. */
16
- tokenUsage?: number;
17
- /** Error the API reported alongside a successful response. */
18
- error?: string;
19
- }
20
- /** One web search result. */
21
- export interface SearchResultItem {
22
- rank?: number;
23
- title?: string;
24
- link?: string;
25
- description?: string;
26
- source?: string;
27
- }
28
- /** What the webSearch tool returns. */
29
- export interface SearchResult {
30
- query: string;
31
- results: SearchResultItem[];
32
- }
33
- interface ApiResponse {
34
- status_code: number;
35
- data: unknown;
36
- }
37
- /**
38
- * Keeps the requested formats the API returned, plus usage and errors.
39
- *
40
- * When only HTML is requested, the API proxies the page and answers with the
41
- * raw HTML string instead of a JSON object; that string is the html format.
42
- */
43
- export declare function toPageResult(url: string, formats: readonly PageFormat[], response: ApiResponse): PageResult;
44
- /** Reduces the search response to what a model needs to choose pages. */
45
- export declare function toSearchResult(query: string, response: ApiResponse): SearchResult;
46
- type ModelOutput = {
47
- type: "json";
48
- value: {
49
- [key: string]: string | number | undefined;
50
- };
51
- } | {
52
- type: "content";
53
- value: Array<{
54
- type: "text";
55
- text: string;
56
- } | {
57
- type: "file";
58
- mediaType: string;
59
- data: {
60
- type: "data";
61
- data: string;
62
- };
63
- }>;
64
- };
65
- /**
66
- * Sends a screenshot to the model as an image part instead of a base64 string
67
- * inside JSON, which would cost hundreds of thousands of text tokens.
68
- */
69
- export declare function toPageModelOutput(output: PageResult): ModelOutput;
70
- export {};
71
- //# sourceMappingURL=results.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,YAAY,CAAC;AAE5D,qDAAqD;AACrD,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,6BAA6B;AAC7B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,KAAK,E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