Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"chalk": "^5.4.1",
"citty": "^0.1.6",
"dotenv": "^17.2.4",
"scrapegraph-js": "github:ScrapeGraphAI/scrapegraph-js#096c110"
"scrapegraph-js": "^2.1.0"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
8 changes: 4 additions & 4 deletions src/commands/crawl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from "citty";
import { crawl } from "scrapegraph-js";
import type { ApiCrawlRequest, ApiScrapeFormatEntry } from "scrapegraph-js";
import type { CrawlRequest, FormatConfig } from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";

Expand All @@ -17,9 +17,9 @@ type Format = (typeof FORMATS)[number];

const POLL_INTERVAL_MS = 3000;

function buildFormat(f: Format): ApiScrapeFormatEntry {
function buildFormat(f: Format): FormatConfig {
if (f === "markdown" || f === "html") return { type: f, mode: "normal" };
return { type: f } as ApiScrapeFormatEntry;
return { type: f } as FormatConfig;
}

export default defineCommand({
Expand Down Expand Up @@ -69,7 +69,7 @@ export default defineCommand({
}
const formats = requested.map((f) => buildFormat(f as Format));

const params: ApiCrawlRequest = { url: args.url, formats };
const params: CrawlRequest = { url: args.url, formats };
const mut = params as Record<string, unknown>;
if (args["max-pages"]) mut.maxPages = Number(args["max-pages"]);
if (args["max-depth"]) mut.maxDepth = Number(args["max-depth"]);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/extract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from "citty";
import { extract } from "scrapegraph-js";
import type { ApiExtractRequest } from "scrapegraph-js";
import type { ExtractRequest } from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";

Expand Down Expand Up @@ -47,7 +47,7 @@ export default defineCommand({
if (args.headers) fetchConfig.headers = JSON.parse(args.headers);
if (args.country) fetchConfig.country = args.country;

const params: ApiExtractRequest = { url: args.url, prompt: args.prompt };
const params: ExtractRequest = { url: args.url, prompt: args.prompt };
if (args.schema) (params as Record<string, unknown>).schema = JSON.parse(args.schema);
if (args["html-mode"]) (params as Record<string, unknown>).mode = args["html-mode"];
if (Object.keys(fetchConfig).length > 0)
Expand Down
12 changes: 6 additions & 6 deletions src/commands/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import * as p from "@clack/prompts";
import chalk from "chalk";
import { defineCommand } from "citty";
import { history } from "scrapegraph-js";
import type { ApiHistoryEntry, ApiHistoryService } from "scrapegraph-js";
import type { HistoryEntry, Service } from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";

const SERVICES = ["scrape", "extract", "search", "monitor", "crawl"] as const;
const VALID = SERVICES.join(", ");
const LOAD_MORE = "__load_more__";

function entryUrl(e: ApiHistoryEntry): string {
function entryUrl(e: HistoryEntry): string {
const params = e.params as Record<string, unknown>;
return String(params.url ?? params.query ?? "");
}

function entryLabel(e: ApiHistoryEntry): string {
function entryLabel(e: HistoryEntry): string {
const short = e.id.length > 12 ? `${e.id.slice(0, 12)}…` : e.id;
const url = entryUrl(e);
const urlShort = url.length > 50 ? `${url.slice(0, 49)}…` : url;
Expand All @@ -24,7 +24,7 @@ function entryLabel(e: ApiHistoryEntry): string {
return `${chalk.dim(short)} ${color(e.status)} ${urlShort}`;
}

function entryHint(e: ApiHistoryEntry): string {
function entryHint(e: HistoryEntry): string {
if (!e.createdAt) return "";
const d = new Date(e.createdAt);
return Number.isNaN(d.getTime()) ? e.createdAt : d.toLocaleString();
Expand All @@ -49,7 +49,7 @@ export default defineCommand({
const quiet = !!args.json;
const out = log.create(quiet);
const apiKey = await resolveApiKey(quiet);
const service = args.service as ApiHistoryService | undefined;
const service = args.service as Service | undefined;
if (service && !SERVICES.includes(service)) out.error(`Invalid service. Valid: ${VALID}`);
const requestId = (args as { _: string[] })._.at(1);
const limit = args["page-size"] ? Number(args["page-size"]) : 20;
Expand All @@ -62,7 +62,7 @@ export default defineCommand({
...(service ? { service } : {}),
});
if (!r.data) out.error(r.error);
const d = r.data as { data: ApiHistoryEntry[]; pagination: { total: number } };
const d = r.data as { data: HistoryEntry[]; pagination: { total: number } };
return {
rows: d.data ?? [],
hasMore: (d.pagination?.total ?? 0) > pg * limit,
Expand Down
14 changes: 7 additions & 7 deletions src/commands/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import chalk from "chalk";
import { defineCommand } from "citty";
import { monitor } from "scrapegraph-js";
import type {
ApiMonitorCreateInput,
ApiMonitorUpdateInput,
ApiScrapeFormatEntry,
MonitorCreateRequest,
MonitorUpdateRequest,
FormatConfig,
} from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
Expand All @@ -32,14 +32,14 @@ const FORMATS = [
"summary",
] as const;

function buildFormats(raw: string): ApiScrapeFormatEntry[] {
function buildFormats(raw: string): FormatConfig[] {
return raw
.split(",")
.map((f) => f.trim())
.filter(Boolean)
.map((f) => {
if (f === "markdown" || f === "html") return { type: f, mode: "normal" as const };
return { type: f } as ApiScrapeFormatEntry;
return { type: f } as FormatConfig;
});
}

Expand Down Expand Up @@ -99,7 +99,7 @@ export default defineCommand({
if (!args.url) return out.error("--url is required for create");
if (!args.interval) return out.error("--interval is required for create");

const params: ApiMonitorCreateInput = {
const params: MonitorCreateRequest = {
url: args.url,
interval: args.interval,
formats: buildFormats(args.format ?? "markdown"),
Expand Down Expand Up @@ -146,7 +146,7 @@ export default defineCommand({
}

case "update": {
const params: ApiMonitorUpdateInput = {};
const params: MonitorUpdateRequest = {};
const mut = params as Record<string, unknown>;
if (args.name) mut.name = args.name;
if (args.interval) mut.interval = args.interval;
Expand Down
6 changes: 3 additions & 3 deletions src/commands/scrape.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from "citty";
import { scrape } from "scrapegraph-js";
import type { ApiScrapeFormatEntry, ApiScrapeRequest } from "scrapegraph-js";
import type { FormatConfig, ScrapeRequest } from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";

Expand Down Expand Up @@ -59,7 +59,7 @@ export default defineCommand({
.map((f) => f.trim())
.filter(Boolean);

const formats: ApiScrapeFormatEntry[] = [];
const formats: FormatConfig[] = [];
for (const f of requested) {
if (!FORMATS.includes(f as Format)) {
out.error(`Unknown format: ${f}. Valid: ${FORMATS.join(", ")}`);
Expand Down Expand Up @@ -104,7 +104,7 @@ export default defineCommand({
if (args.scrolls) fetchConfig.scrolls = Number(args.scrolls);
if (args.country) fetchConfig.country = args.country;

const params: ApiScrapeRequest = { url: args.url, formats };
const params: ScrapeRequest = { url: args.url, formats };
if (Object.keys(fetchConfig).length > 0)
(params as unknown as Record<string, unknown>).fetchConfig = fetchConfig;

Expand Down
4 changes: 2 additions & 2 deletions src/commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineCommand } from "citty";
import { search } from "scrapegraph-js";
import type { ApiSearchRequest } from "scrapegraph-js";
import type { SearchRequest } from "scrapegraph-js";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";

Expand Down Expand Up @@ -43,7 +43,7 @@ export default defineCommand({
out.docs("https://docs.scrapegraphai.com/api-reference/search");
const apiKey = await resolveApiKey(!!args.json);

const params: ApiSearchRequest = { query: args.query };
const params: SearchRequest = { query: args.query };
const mut = params as Record<string, unknown>;
if (args["num-results"]) mut.numResults = Number(args["num-results"]);
if (args.prompt) mut.prompt = args.prompt;
Expand Down
Loading