@tiny-fish/cli 0.1.4 → 0.1.5

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,48 @@ 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
+
91
+ ### Browser
92
+
93
+ ```bash
94
+ # Create a remote browser session
95
+ tinyfish browser session create
96
+
97
+ # Open a URL when the session starts
98
+ tinyfish browser session create --url https://agentql.com
99
+
100
+ # Human-readable output
101
+ tinyfish browser session create --pretty
102
+ ```
103
+
62
104
  ### Output format
63
105
 
64
106
  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 registerBrowser(program: Command): void;
@@ -0,0 +1,41 @@
1
+ import { getApiKey } from "../lib/auth.js";
2
+ import { browserSessionCreate } from "../lib/client.js";
3
+ import { handleApiError, out, outLine } from "../lib/output.js";
4
+ function printPrettyBrowserSession(session) {
5
+ outLine("Browser session created");
6
+ outLine(`Session ID: ${session.session_id}`);
7
+ outLine(`CDP URL: ${session.cdp_url}`);
8
+ outLine(`Base URL: ${session.base_url}`);
9
+ }
10
+ export function registerBrowser(program) {
11
+ const browserCmd = program
12
+ .command("browser")
13
+ .description("Browser commands")
14
+ .enablePositionalOptions();
15
+ const sessionCmd = browserCmd
16
+ .command("session")
17
+ .description("Manage browser sessions")
18
+ .enablePositionalOptions();
19
+ sessionCmd
20
+ .command("create")
21
+ .description("Create a remote browser session")
22
+ .option("--url <value>", "Open a URL after session creation")
23
+ .option("--pretty", "Human-readable output")
24
+ .action(async (opts) => {
25
+ const apiKey = getApiKey();
26
+ try {
27
+ const response = await browserSessionCreate({
28
+ ...(opts.url !== undefined ? { url: opts.url } : {}),
29
+ }, apiKey);
30
+ if (opts.pretty) {
31
+ printPrettyBrowserSession(response);
32
+ }
33
+ else {
34
+ out(response);
35
+ }
36
+ }
37
+ catch (error) {
38
+ handleApiError(error);
39
+ }
40
+ });
41
+ }
@@ -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,11 @@ 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";
7
+ import { registerBrowser } from "./commands/browser.js";
6
8
  import { registerRun } from "./commands/run.js";
7
9
  import { registerRuns } from "./commands/runs.js";
10
+ import { registerSearch } from "./commands/search.js";
8
11
  const { version } = createRequire(import.meta.url)("../package.json");
9
12
  const program = new Command();
10
13
  program
@@ -21,6 +24,7 @@ program
21
24
  }
22
25
  });
23
26
  registerAuth(program);
27
+ registerBrowser(program);
24
28
  const agentCmd = program
25
29
  .command("agent")
26
30
  .description("Agent automation commands")
@@ -28,6 +32,8 @@ const agentCmd = program
28
32
  const runCmd = registerRun(agentCmd);
29
33
  registerRuns(runCmd);
30
34
  registerBatch(agentCmd);
35
+ registerSearch(program);
36
+ registerFetch(program);
31
37
  // Await parseAsync so async command handlers complete before the process exits
32
38
  program.parseAsync(process.argv).catch((e) => {
33
39
  process.stderr.write(JSON.stringify({ error: e instanceof Error ? e.message : String(e) }) + "\n");
@@ -1,10 +1,13 @@
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 BrowserSession, type BrowserSessionCreateParams, 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>;
10
+ export declare function browserSessionCreate(params: BrowserSessionCreateParams, apiKey: string): Promise<BrowserSession>;
8
11
  export declare function cancelRun(runId: string, apiKey: string): Promise<CancelRunResponse>;
9
12
  export declare function submitBatch(req: BatchRunRequest, apiKey: string): Promise<BatchRunResponse>;
10
13
  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, browserSessionSchema, 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,33 @@ 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
+ }
136
+ export async function browserSessionCreate(params, apiKey) {
137
+ try {
138
+ const response = await createSdkClient(apiKey).browser.sessions.create(params);
139
+ return browserSessionSchema.parse(response);
140
+ }
141
+ catch (error) {
142
+ rethrowSdkError(error);
143
+ }
144
+ }
118
145
  export async function cancelRun(runId, apiKey) {
119
146
  try {
120
147
  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",
3
+ "version": "0.1.5",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -16,7 +16,16 @@
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:browser": "vitest --run --passWithNoTests --config vitest.integration.config.ts tests/api.integration.test.ts --testNamePattern \"browser session create|skips real API coverage when TINYFISH_API_KEY is not set\"",
22
+ "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\"",
23
+ "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\"",
24
+ "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\"",
25
+ "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\"",
26
+ "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\"",
27
+ "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\"",
28
+ "test:integration": "npm run test:integration:auth && npm run test:integration:api:fetch && npm run test:integration:api:browser && 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
29
  "lint": "eslint src tests",
21
30
  "format": "prettier --write src tests",
22
31
  "type-check": "tsc --noEmit --project tsconfig.all.json",
@@ -39,6 +48,7 @@
39
48
  "vitest": "^3.0.0"
40
49
  },
41
50
  "overrides": {
51
+ "vite": "7.3.2",
42
52
  "brace-expansion": "5.0.5"
43
53
  },
44
54
  "engines": {