@tiny-fish/cli 0.1.5-next.44 → 0.1.5-next.47

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
@@ -41,6 +41,36 @@ tinyfish agent run "Find the pricing page" --url https://example.com --sync
41
41
 
42
42
  # Submit and return immediately (don't wait)
43
43
  tinyfish agent run "Find the pricing page" --url https://example.com --async
44
+
45
+ # Request structured output with an inline JSON Schema
46
+ tinyfish agent run "Extract the product price" \
47
+ --url https://example.com/product \
48
+ --sync \
49
+ --output-schema "{\"type\":\"object\",\"properties\":{\"price\":{\"type\":\"string\"}},\"required\":[\"price\"]}"
50
+
51
+ # Or load the schema from a file
52
+ tinyfish agent run "Extract the product price" \
53
+ --url https://example.com/product \
54
+ --sync \
55
+ --output-schema-file ./schemas/product-price.json
56
+ ```
57
+
58
+ ### Structured output
59
+
60
+ Use `--output-schema <json>` for short inline schemas and `--output-schema-file <path>` for schemas you want to reuse, review, or keep in source control.
61
+ Both flags work with the default streaming mode, `--sync`, and `--async`.
62
+
63
+ Example schema file:
64
+
65
+ ```json
66
+ {
67
+ "type": "object",
68
+ "properties": {
69
+ "price": { "type": "string" },
70
+ "currency": { "type": "string" }
71
+ },
72
+ "required": ["price", "currency"]
73
+ }
44
74
  ```
45
75
 
46
76
  ### Manage runs
@@ -107,6 +137,8 @@ By default all commands output newline-delimited JSON to stdout — pipe-friendl
107
137
 
108
138
  Errors are JSON to stderr with exit code 1. Ctrl+C during a streaming run cancels it automatically.
109
139
 
140
+ `--output-schema` and `--output-schema-file` are mutually exclusive. Both inputs must parse to a top-level JSON object. The CLI only validates that outer shape locally; the API performs full schema validation and may return errors such as `INVALID_INPUT` or feature-flag access failures.
141
+
110
142
  ### Debug
111
143
 
112
144
  ```bash
@@ -1,8 +1,11 @@
1
1
  import { EventType, RunStatus } from "@tiny-fish/sdk";
2
+ import { readFile } from "node:fs/promises";
3
+ import { z } from "zod";
2
4
  import { getApiKey } from "../lib/auth.js";
3
5
  import { cancelRun, runAsync, runStream, runSync } from "../lib/client.js";
4
6
  import { err, errLine, handleApiError, out, outLine } from "../lib/output.js";
5
7
  import { BASE_URL } from "../lib/constants.js";
8
+ const outputSchemaFieldSchema = z.object({}).catchall(z.unknown());
6
9
  function extractErrorMessage(error) {
7
10
  if (typeof error === "string")
8
11
  return error;
@@ -29,6 +32,42 @@ function checkRunResult(result, expectComplete = true) {
29
32
  process.exit(1);
30
33
  }
31
34
  }
35
+ function parseOutputSchema(rawOutputSchema, sourceLabel) {
36
+ let parsed;
37
+ try {
38
+ parsed = JSON.parse(rawOutputSchema);
39
+ }
40
+ catch {
41
+ err({ error: `Invalid ${sourceLabel} JSON. Provide a valid JSON object.` });
42
+ process.exit(1);
43
+ }
44
+ const result = outputSchemaFieldSchema.safeParse(parsed);
45
+ if (!result.success) {
46
+ err({ error: `${sourceLabel} must be a JSON object` });
47
+ process.exit(1);
48
+ }
49
+ return result.data;
50
+ }
51
+ async function loadOutputSchema(opts) {
52
+ if (opts.outputSchema !== undefined && opts.outputSchemaFile !== undefined) {
53
+ err({ error: "--output-schema and --output-schema-file are mutually exclusive" });
54
+ process.exit(1);
55
+ }
56
+ if (opts.outputSchema !== undefined) {
57
+ return parseOutputSchema(opts.outputSchema, "--output-schema");
58
+ }
59
+ if (opts.outputSchemaFile === undefined)
60
+ return undefined;
61
+ let fileContents;
62
+ try {
63
+ fileContents = await readFile(opts.outputSchemaFile, "utf8");
64
+ }
65
+ catch {
66
+ err({ error: `Unable to read --output-schema-file "${opts.outputSchemaFile}"` });
67
+ process.exit(1);
68
+ }
69
+ return parseOutputSchema(fileContents, "--output-schema-file");
70
+ }
32
71
  export function registerRun(agentCmd) {
33
72
  const runCmd = agentCmd
34
73
  .command("run")
@@ -36,6 +75,8 @@ export function registerRun(agentCmd) {
36
75
  .option("--url <url>", "Target URL for the automation")
37
76
  .option("--sync", "Wait for result without streaming steps")
38
77
  .option("--async", "Submit without waiting for result")
78
+ .option("--output-schema <json>", "Inline JSON Schema object for structured output")
79
+ .option("--output-schema-file <path>", "Path to a JSON file containing the output schema")
39
80
  .option("--pretty", "Human-readable output")
40
81
  .argument("[goal]", "Goal to automate")
41
82
  .action(async (goal, opts) => {
@@ -72,8 +113,13 @@ export function registerRun(agentCmd) {
72
113
  err({ error: 'Goal cannot be empty' });
73
114
  process.exit(1);
74
115
  }
116
+ const outputSchema = await loadOutputSchema(opts);
75
117
  const apiKey = getApiKey();
76
- const req = { goal, url: normalizedUrl };
118
+ const req = {
119
+ goal,
120
+ url: normalizedUrl,
121
+ ...(outputSchema !== undefined ? { output_schema: outputSchema } : {}),
122
+ };
77
123
  if (opts.async) {
78
124
  let result;
79
125
  try {
@@ -1,8 +1,8 @@
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
- import type { BatchCancelResponse, BatchGetResponse, BatchRunRequest, BatchRunResponse, CancelRunResponse } from "./types.js";
3
- export declare function runSync(req: AgentRunParams, apiKey: string): Promise<AgentRunResponse>;
4
- export declare function runAsync(req: AgentRunParams, apiKey: string): Promise<AgentRunAsyncResponse>;
5
- export declare function runStream(req: AgentRunParams, apiKey: string, signal?: AbortSignal): AsyncGenerator<AgentRunWithStreamingResponse>;
1
+ import { type AgentRunAsyncResponse, 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
+ import type { BatchCancelResponse, BatchGetResponse, BatchRunRequest, BatchRunResponse, CancelRunResponse, CliAgentRunParams } from "./types.js";
3
+ export declare function runSync(req: CliAgentRunParams, apiKey: string): Promise<AgentRunResponse>;
4
+ export declare function runAsync(req: CliAgentRunParams, apiKey: string): Promise<AgentRunAsyncResponse>;
5
+ export declare function runStream(req: CliAgentRunParams, 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
8
  export declare function searchQuery(params: SearchQueryParams, apiKey: string): Promise<SearchQueryResponse>;
@@ -1,4 +1,8 @@
1
- import type { Run, RunStatus } from "@tiny-fish/sdk";
1
+ import type { AgentRunParams, Run, RunStatus } from "@tiny-fish/sdk";
2
+ export type OutputSchema = Record<string, unknown>;
3
+ export interface CliAgentRunParams extends AgentRunParams {
4
+ output_schema?: OutputSchema;
5
+ }
2
6
  export interface CancelRunResponse {
3
7
  run_id: string;
4
8
  status: RunStatus | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-fish/cli",
3
- "version": "0.1.5-next.44",
3
+ "version": "0.1.5-next.47",
4
4
  "description": "TinyFish CLI — run web automations from your terminal",
5
5
  "type": "module",
6
6
  "bin": {