@tiny-fish/cli 0.1.4-next.39 → 0.1.4-next.40

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/README.md CHANGED
@@ -72,6 +72,22 @@ tinyfish search query "agentql pricing" --location US --language en
72
72
  tinyfish search query "agentql pricing" --pretty
73
73
  ```
74
74
 
75
+ ### Fetch
76
+
77
+ ```bash
78
+ # Fetch extracted content from one or more URLs
79
+ tinyfish fetch content get https://agentql.com
80
+
81
+ # Choose the output format
82
+ tinyfish fetch content get https://agentql.com --format markdown
83
+
84
+ # Include links and image links
85
+ tinyfish fetch content get https://agentql.com --links --image-links
86
+
87
+ # Human-readable output
88
+ tinyfish fetch content get https://agentql.com --pretty
89
+ ```
90
+
75
91
  ### Output format
76
92
 
77
93
  By default all commands output newline-delimited JSON to stdout — pipe-friendly for agents and scripts. Add `--pretty` for human-readable output.
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerFetch(program: Command): void;
@@ -0,0 +1,66 @@
1
+ import { getApiKey } from "../lib/auth.js";
2
+ import { fetchContentGet } from "../lib/client.js";
3
+ import { handleApiError, out, outLine } from "../lib/output.js";
4
+ function printPrettyFetch(response) {
5
+ outLine(`Results: ${response.results.length}`);
6
+ outLine(`Errors: ${response.errors.length}`);
7
+ outLine("");
8
+ if (response.results.length > 0) {
9
+ outLine("Successful fetches:");
10
+ for (const result of response.results) {
11
+ outLine(`- ${result.url}`);
12
+ outLine(` Format: ${result.format}`);
13
+ if (result.title)
14
+ outLine(` Title: ${result.title}`);
15
+ if (result.final_url && result.final_url !== result.url)
16
+ outLine(` Final URL: ${result.final_url}`);
17
+ outLine("");
18
+ }
19
+ }
20
+ if (response.errors.length > 0) {
21
+ outLine("Errors:");
22
+ for (const error of response.errors) {
23
+ outLine(`- ${error.url}`);
24
+ outLine(` ${error.error}`);
25
+ outLine("");
26
+ }
27
+ }
28
+ }
29
+ export function registerFetch(program) {
30
+ const fetchCmd = program
31
+ .command("fetch")
32
+ .description("Fetch commands")
33
+ .enablePositionalOptions();
34
+ const contentCmd = fetchCmd
35
+ .command("content")
36
+ .description("Content extraction commands")
37
+ .enablePositionalOptions();
38
+ contentCmd
39
+ .command("get")
40
+ .description("Fetch clean content from one or more URLs")
41
+ .argument("<urls...>", "One or more URLs to fetch")
42
+ .option("--format <format>", "Output format: markdown, html, or json")
43
+ .option("--links", "Include extracted links")
44
+ .option("--image-links", "Include extracted image links")
45
+ .option("--pretty", "Human-readable output")
46
+ .action(async (urls, opts) => {
47
+ const apiKey = getApiKey();
48
+ try {
49
+ const response = await fetchContentGet({
50
+ urls,
51
+ ...(opts.format !== undefined ? { format: opts.format } : {}),
52
+ ...(opts.links !== undefined ? { links: opts.links } : {}),
53
+ ...(opts.imageLinks !== undefined ? { image_links: opts.imageLinks } : {}),
54
+ }, apiKey);
55
+ if (opts.pretty) {
56
+ printPrettyFetch(response);
57
+ }
58
+ else {
59
+ out(response);
60
+ }
61
+ }
62
+ catch (error) {
63
+ handleApiError(error);
64
+ }
65
+ });
66
+ }
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { createRequire } from "module";
3
3
  import { Command } from "commander";
4
4
  import { registerAuth } from "./commands/auth.js";
5
5
  import { registerBatch } from "./commands/batch.js";
6
+ import { registerFetch } from "./commands/fetch.js";
6
7
  import { registerRun } from "./commands/run.js";
7
8
  import { registerRuns } from "./commands/runs.js";
8
9
  import { registerSearch } from "./commands/search.js";
@@ -30,6 +31,7 @@ const runCmd = registerRun(agentCmd);
30
31
  registerRuns(runCmd);
31
32
  registerBatch(agentCmd);
32
33
  registerSearch(program);
34
+ registerFetch(program);
33
35
  // Await parseAsync so async command handlers complete before the process exits
34
36
  program.parseAsync(process.argv).catch((e) => {
35
37
  process.stderr.write(JSON.stringify({ error: e instanceof Error ? e.message : String(e) }) + "\n");
@@ -1,4 +1,4 @@
1
- import { type AgentRunAsyncResponse, type AgentRunParams, type AgentRunResponse, type AgentRunWithStreamingResponse, type Run, type RunListParams, type RunListResponse, type SearchQueryParams, type SearchQueryResponse } from "@tiny-fish/sdk";
1
+ import { type AgentRunAsyncResponse, type AgentRunParams, type AgentRunResponse, type AgentRunWithStreamingResponse, type FetchGetContentsParams, type FetchResponse, type Run, type RunListParams, type RunListResponse, type SearchQueryParams, type SearchQueryResponse } from "@tiny-fish/sdk";
2
2
  import type { BatchCancelResponse, BatchGetResponse, BatchRunRequest, BatchRunResponse, CancelRunResponse } from "./types.js";
3
3
  export declare function runSync(req: AgentRunParams, apiKey: string): Promise<AgentRunResponse>;
4
4
  export declare function runAsync(req: AgentRunParams, apiKey: string): Promise<AgentRunAsyncResponse>;
@@ -6,6 +6,7 @@ export declare function runStream(req: AgentRunParams, apiKey: string, signal?:
6
6
  export declare function listRuns(opts: RunListParams, apiKey: string): Promise<RunListResponse>;
7
7
  export declare function getRun(runId: string, apiKey: string): Promise<Run>;
8
8
  export declare function searchQuery(params: SearchQueryParams, apiKey: string): Promise<SearchQueryResponse>;
9
+ export declare function fetchContentGet(params: FetchGetContentsParams, apiKey: string): Promise<FetchResponse>;
9
10
  export declare function cancelRun(runId: string, apiKey: string): Promise<CancelRunResponse>;
10
11
  export declare function submitBatch(req: BatchRunRequest, apiKey: string): Promise<BatchRunResponse>;
11
12
  export declare function getBatchRuns(runIds: string[], apiKey: string): Promise<BatchGetResponse>;
@@ -1,4 +1,4 @@
1
- import { APIStatusError, searchQueryResponseSchema, TinyFish, runSchema, } from "@tiny-fish/sdk";
1
+ import { APIStatusError, fetchResponseSchema, searchQueryResponseSchema, TinyFish, runSchema, } from "@tiny-fish/sdk";
2
2
  import { BASE_URL } from "./constants.js";
3
3
  import { ApiError } from "./output.js";
4
4
  import { z } from "zod";
@@ -124,6 +124,15 @@ export async function searchQuery(params, apiKey) {
124
124
  rethrowSdkError(error);
125
125
  }
126
126
  }
127
+ export async function fetchContentGet(params, apiKey) {
128
+ try {
129
+ const response = await createSdkClient(apiKey).fetch.getContents(params);
130
+ return fetchResponseSchema.parse(response);
131
+ }
132
+ catch (error) {
133
+ rethrowSdkError(error);
134
+ }
135
+ }
127
136
  export async function cancelRun(runId, apiKey) {
128
137
  try {
129
138
  const response = await createSdkClient(apiKey).post(`/v1/runs/${encodeURIComponent(runId)}/cancel`, { json: {} });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-fish/cli",
3
- "version": "0.1.4-next.39",
3
+ "version": "0.1.4-next.40",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,15 @@
16
16
  "test": "vitest --run",
17
17
  "test:file": "vitest --run",
18
18
  "test:watch": "vitest",
19
- "test:integration": "vitest --run --config vitest.integration.config.ts",
19
+ "test:integration:auth": "vitest --run --config vitest.integration.config.ts tests/auth.integration.test.ts",
20
+ "test:integration:api:fetch": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"fetch content get|skips real API coverage when TINYFISH_API_KEY is not set\"",
21
+ "test:integration:api:search": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"search query|skips real API coverage when TINYFISH_API_KEY is not set\"",
22
+ "test:integration:api:sync": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"agent run --sync|skips real API coverage when TINYFISH_API_KEY is not set\"",
23
+ "test:integration:api:stream": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"agent run streaming exits cleanly after COMPLETE|skips real API coverage when TINYFISH_API_KEY is not set\"",
24
+ "test:integration:api:async": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"agent run --async returns a run id that can be fetched and listed|skips real API coverage when TINYFISH_API_KEY is not set\"",
25
+ "test:integration:api:cancel": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"agent run cancel cancels an in-flight run|skips real API coverage when TINYFISH_API_KEY is not set\"",
26
+ "test:integration:api:batch": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"batch commands work end-to-end against the real API|skips real API coverage when TINYFISH_API_KEY is not set\"",
27
+ "test:integration": "npm run test:integration:auth && npm run test:integration:api:fetch && npm run test:integration:api:search && npm run test:integration:api:sync && npm run test:integration:api:stream && npm run test:integration:api:async && npm run test:integration:api:cancel && npm run test:integration:api:batch",
20
28
  "lint": "eslint src tests",
21
29
  "format": "prettier --write src tests",
22
30
  "type-check": "tsc --noEmit --project tsconfig.all.json",