@tiny-fish/cli 0.1.4-next.37 → 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
@@ -59,6 +59,35 @@ tinyfish agent run get <run_id> --pretty
59
59
  tinyfish agent run cancel <run_id> --pretty
60
60
  ```
61
61
 
62
+ ### Search
63
+
64
+ ```bash
65
+ # Query TinyFish Search
66
+ tinyfish search query "agentql pricing"
67
+
68
+ # Add location and language hints
69
+ tinyfish search query "agentql pricing" --location US --language en
70
+
71
+ # Human-readable output
72
+ tinyfish search query "agentql pricing" --pretty
73
+ ```
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
+
62
91
  ### Output format
63
92
 
64
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
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from "commander";
2
+ export declare function registerSearch(program: Command): void;
@@ -0,0 +1,50 @@
1
+ import { getApiKey } from "../lib/auth.js";
2
+ import { searchQuery } from "../lib/client.js";
3
+ import { handleApiError, out, outLine } from "../lib/output.js";
4
+ function printPrettySearch(response) {
5
+ outLine(`Query: ${response.query}`);
6
+ outLine(`Total results: ${response.total_results}`);
7
+ outLine("");
8
+ if (response.results.length === 0) {
9
+ outLine("No results.");
10
+ return;
11
+ }
12
+ for (const result of response.results) {
13
+ outLine(`${result.position}. ${result.title}`);
14
+ outLine(` ${result.url}`);
15
+ outLine(` ${result.snippet}`);
16
+ outLine("");
17
+ }
18
+ }
19
+ export function registerSearch(program) {
20
+ const searchCmd = program
21
+ .command("search")
22
+ .description("Search commands")
23
+ .enablePositionalOptions();
24
+ searchCmd
25
+ .command("query")
26
+ .description("Query TinyFish Search")
27
+ .argument("<query>", "Search query")
28
+ .option("--location <value>", "Search location hint")
29
+ .option("--language <value>", "Search language hint")
30
+ .option("--pretty", "Human-readable output")
31
+ .action(async (query, opts) => {
32
+ const apiKey = getApiKey();
33
+ try {
34
+ const response = await searchQuery({
35
+ query,
36
+ ...(opts.location !== undefined ? { location: opts.location } : {}),
37
+ ...(opts.language !== undefined ? { language: opts.language } : {}),
38
+ }, apiKey);
39
+ if (opts.pretty) {
40
+ printPrettySearch(response);
41
+ }
42
+ else {
43
+ out(response);
44
+ }
45
+ }
46
+ catch (error) {
47
+ handleApiError(error);
48
+ }
49
+ });
50
+ }
package/dist/index.js CHANGED
@@ -3,8 +3,10 @@ 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";
9
+ import { registerSearch } from "./commands/search.js";
8
10
  const { version } = createRequire(import.meta.url)("../package.json");
9
11
  const program = new Command();
10
12
  program
@@ -28,6 +30,8 @@ const agentCmd = program
28
30
  const runCmd = registerRun(agentCmd);
29
31
  registerRuns(runCmd);
30
32
  registerBatch(agentCmd);
33
+ registerSearch(program);
34
+ registerFetch(program);
31
35
  // Await parseAsync so async command handlers complete before the process exits
32
36
  program.parseAsync(process.argv).catch((e) => {
33
37
  process.stderr.write(JSON.stringify({ error: e instanceof Error ? e.message : String(e) }) + "\n");
@@ -1,10 +1,12 @@
1
- import { type AgentRunAsyncResponse, type AgentRunParams, type AgentRunResponse, type AgentRunWithStreamingResponse, type Run, type RunListParams, type RunListResponse } 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>;
5
5
  export declare function runStream(req: AgentRunParams, apiKey: string, signal?: AbortSignal): AsyncGenerator<AgentRunWithStreamingResponse>;
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
+ export declare function searchQuery(params: SearchQueryParams, apiKey: string): Promise<SearchQueryResponse>;
9
+ export declare function fetchContentGet(params: FetchGetContentsParams, apiKey: string): Promise<FetchResponse>;
8
10
  export declare function cancelRun(runId: string, apiKey: string): Promise<CancelRunResponse>;
9
11
  export declare function submitBatch(req: BatchRunRequest, apiKey: string): Promise<BatchRunResponse>;
10
12
  export declare function getBatchRuns(runIds: string[], apiKey: string): Promise<BatchGetResponse>;
@@ -1,4 +1,4 @@
1
- import { APIStatusError, 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";
@@ -115,6 +115,24 @@ export async function getRun(runId, apiKey) {
115
115
  rethrowSdkError(error);
116
116
  }
117
117
  }
118
+ export async function searchQuery(params, apiKey) {
119
+ try {
120
+ const response = await createSdkClient(apiKey).search.query(params);
121
+ return searchQueryResponseSchema.parse(response);
122
+ }
123
+ catch (error) {
124
+ rethrowSdkError(error);
125
+ }
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
+ }
118
136
  export async function cancelRun(runId, apiKey) {
119
137
  try {
120
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.37",
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",