@tiny-fish/sdk 0.0.1 → 0.0.3
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/dist/_utils/client.d.ts +5 -1
- package/dist/_utils/client.d.ts.map +1 -1
- package/dist/_utils/client.js +22 -4
- package/dist/_utils/client.js.map +1 -1
- package/dist/agent/index.d.ts +4 -3
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +35 -16
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/types.d.ts +25 -12
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/runs/index.d.ts.map +1 -1
- package/dist/runs/index.js +2 -1
- package/dist/runs/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -4
- package/src/_utils/client.ts +0 -219
- package/src/_utils/errors.ts +0 -153
- package/src/_utils/index.ts +0 -31
- package/src/_utils/resource.ts +0 -9
- package/src/_utils/sse.ts +0 -72
- package/src/agent/index.ts +0 -210
- package/src/agent/types.ts +0 -190
- package/src/client.ts +0 -19
- package/src/index.ts +0 -64
- package/src/runs/index.ts +0 -47
- package/src/runs/types.ts +0 -81
- package/src/version.ts +0 -2
package/src/agent/types.ts
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent automation request/response types.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
// -- Input types --
|
|
6
|
-
|
|
7
|
-
/** Browser profile for execution. */
|
|
8
|
-
export enum BrowserProfile {
|
|
9
|
-
LITE = "lite",
|
|
10
|
-
STEALTH = "stealth",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** ISO 3166-1 alpha-2 country code for proxy location. */
|
|
14
|
-
export enum ProxyCountryCode {
|
|
15
|
-
US = "US",
|
|
16
|
-
GB = "GB",
|
|
17
|
-
CA = "CA",
|
|
18
|
-
DE = "DE",
|
|
19
|
-
FR = "FR",
|
|
20
|
-
JP = "JP",
|
|
21
|
-
AU = "AU",
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Proxy configuration for browser automation. */
|
|
25
|
-
export interface ProxyConfig {
|
|
26
|
-
/** Enable proxy for this automation run. */
|
|
27
|
-
enabled: boolean;
|
|
28
|
-
/** ISO 3166-1 alpha-2 country code for proxy location. */
|
|
29
|
-
country_code?: ProxyCountryCode;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Parameters for a synchronous agent run. */
|
|
33
|
-
export interface AgentRunParams {
|
|
34
|
-
/** Natural language description of what to do on the page. */
|
|
35
|
-
goal: string;
|
|
36
|
-
/** The URL to open the browser on. */
|
|
37
|
-
url: string;
|
|
38
|
-
/** `"lite"` (default) or `"stealth"` (anti-detection). */
|
|
39
|
-
browser_profile?: BrowserProfile;
|
|
40
|
-
/** Optional proxy settings. */
|
|
41
|
-
proxy_config?: ProxyConfig;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// -- Response types (shared with runs later) --
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Status of an automation run.
|
|
48
|
-
*
|
|
49
|
-
* Use these constants instead of raw strings when filtering or branching
|
|
50
|
-
* on run status — your IDE will autocomplete the options and typos become
|
|
51
|
-
* type errors.
|
|
52
|
-
*/
|
|
53
|
-
export enum RunStatus {
|
|
54
|
-
PENDING = "PENDING",
|
|
55
|
-
RUNNING = "RUNNING",
|
|
56
|
-
COMPLETED = "COMPLETED",
|
|
57
|
-
FAILED = "FAILED",
|
|
58
|
-
CANCELLED = "CANCELLED",
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Error category indicating the source of failure.
|
|
63
|
-
*
|
|
64
|
-
* - `SYSTEM_FAILURE` — TinyFish infrastructure issue, safe to retry.
|
|
65
|
-
* - `AGENT_FAILURE` — Problem with the run itself, fix the input.
|
|
66
|
-
* - `UNKNOWN` — Unclassified, treat as retryable.
|
|
67
|
-
*/
|
|
68
|
-
export enum ErrorCategory {
|
|
69
|
-
SYSTEM_FAILURE = "SYSTEM_FAILURE",
|
|
70
|
-
AGENT_FAILURE = "AGENT_FAILURE",
|
|
71
|
-
UNKNOWN = "UNKNOWN",
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Error details for failed runs. */
|
|
75
|
-
export interface RunError {
|
|
76
|
-
/** Error message describing why the run failed. */
|
|
77
|
-
message: string;
|
|
78
|
-
/** Error category indicating the source of failure. */
|
|
79
|
-
category: ErrorCategory;
|
|
80
|
-
/** Suggested retry delay in whole seconds (integer). */
|
|
81
|
-
retry_after: number | null;
|
|
82
|
-
/** URL to troubleshooting docs. */
|
|
83
|
-
help_url?: string;
|
|
84
|
-
/** Human-readable guidance. */
|
|
85
|
-
help_message?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Response from synchronous automation execution.
|
|
90
|
-
*
|
|
91
|
-
* Check `status` to determine success/failure:
|
|
92
|
-
* - On success: `result` is populated, `error` is `null`.
|
|
93
|
-
* - On failure: `result` is `null`, `error` contains the message.
|
|
94
|
-
*/
|
|
95
|
-
export interface AgentRunResponse {
|
|
96
|
-
/** Final status of the automation run. */
|
|
97
|
-
status: RunStatus;
|
|
98
|
-
/** Unique identifier for the automation run. */
|
|
99
|
-
run_id: string | null;
|
|
100
|
-
/** Structured JSON result extracted from the automation. `null` if the run failed. */
|
|
101
|
-
result: Record<string, unknown> | null;
|
|
102
|
-
/** Error details. `null` if the run succeeded. */
|
|
103
|
-
error: RunError | null;
|
|
104
|
-
/** Number of steps taken during the automation. */
|
|
105
|
-
num_of_steps: number;
|
|
106
|
-
/** ISO 8601 timestamp when the run started. */
|
|
107
|
-
started_at: string | null;
|
|
108
|
-
/** ISO 8601 timestamp when the run finished. */
|
|
109
|
-
finished_at: string | null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Response from asynchronous automation execution.
|
|
114
|
-
*
|
|
115
|
-
* Returns `run_id` immediately without waiting for completion.
|
|
116
|
-
* Use `client.runs.get(run_id)` to check status later.
|
|
117
|
-
*/
|
|
118
|
-
export interface AgentRunAsyncResponse {
|
|
119
|
-
/** Unique identifier for the created automation run. */
|
|
120
|
-
run_id: string | null;
|
|
121
|
-
/** Error details. `null` if successful. */
|
|
122
|
-
error: RunError | null;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// -- SSE streaming event types --
|
|
126
|
-
|
|
127
|
-
/** SSE event type discriminator. */
|
|
128
|
-
export enum EventType {
|
|
129
|
-
STARTED = "STARTED",
|
|
130
|
-
STREAMING_URL = "STREAMING_URL",
|
|
131
|
-
PROGRESS = "PROGRESS",
|
|
132
|
-
HEARTBEAT = "HEARTBEAT",
|
|
133
|
-
COMPLETE = "COMPLETE",
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/** SSE event indicating the automation run has started. */
|
|
137
|
-
export interface StartedEvent {
|
|
138
|
-
type: "STARTED";
|
|
139
|
-
runId: string;
|
|
140
|
-
timestamp: string;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** SSE event providing the live browser streaming URL. */
|
|
144
|
-
export interface StreamingUrlEvent {
|
|
145
|
-
type: "STREAMING_URL";
|
|
146
|
-
runId: string;
|
|
147
|
-
streamingUrl: string;
|
|
148
|
-
timestamp: string;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/** SSE event indicating automation progress/activity. */
|
|
152
|
-
export interface ProgressEvent {
|
|
153
|
-
type: "PROGRESS";
|
|
154
|
-
runId: string;
|
|
155
|
-
purpose: string;
|
|
156
|
-
timestamp: string;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** SSE event for connection keepalive. */
|
|
160
|
-
export interface HeartbeatEvent {
|
|
161
|
-
type: "HEARTBEAT";
|
|
162
|
-
timestamp: string;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** SSE event indicating the automation run has completed. */
|
|
166
|
-
export interface CompleteEvent {
|
|
167
|
-
type: "COMPLETE";
|
|
168
|
-
runId: string;
|
|
169
|
-
status: RunStatus;
|
|
170
|
-
timestamp: string;
|
|
171
|
-
resultJson: Record<string, unknown> | null;
|
|
172
|
-
error: RunError | null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/** Union type for all possible SSE streaming events. */
|
|
176
|
-
export type AgentRunWithStreamingResponse =
|
|
177
|
-
| StartedEvent
|
|
178
|
-
| StreamingUrlEvent
|
|
179
|
-
| ProgressEvent
|
|
180
|
-
| HeartbeatEvent
|
|
181
|
-
| CompleteEvent;
|
|
182
|
-
|
|
183
|
-
/** Optional callbacks for stream events. */
|
|
184
|
-
export interface StreamOptions {
|
|
185
|
-
onStarted?: (event: StartedEvent) => void;
|
|
186
|
-
onStreamingUrl?: (event: StreamingUrlEvent) => void;
|
|
187
|
-
onProgress?: (event: ProgressEvent) => void;
|
|
188
|
-
onHeartbeat?: (event: HeartbeatEvent) => void;
|
|
189
|
-
onComplete?: (event: CompleteEvent) => void;
|
|
190
|
-
}
|
package/src/client.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TinyFish TypeScript SDK client.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { BaseClient } from "./_utils/client.js";
|
|
6
|
-
import type { ClientOptions } from "./_utils/client.js";
|
|
7
|
-
import { AgentResource } from "./agent/index.js";
|
|
8
|
-
import { RunsResource } from "./runs/index.js";
|
|
9
|
-
|
|
10
|
-
export class TinyFish extends BaseClient {
|
|
11
|
-
readonly agent: AgentResource;
|
|
12
|
-
readonly runs: RunsResource;
|
|
13
|
-
|
|
14
|
-
constructor(options?: ClientOptions) {
|
|
15
|
-
super(options);
|
|
16
|
-
this.agent = new AgentResource(this);
|
|
17
|
-
this.runs = new RunsResource(this);
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TinyFish TypeScript SDK — State-of-the-art web agents in an API.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { VERSION } from "./version.js";
|
|
6
|
-
export type { ClientOptions } from "./_utils/client.js";
|
|
7
|
-
|
|
8
|
-
// Client
|
|
9
|
-
export { TinyFish } from "./client.js";
|
|
10
|
-
|
|
11
|
-
// Resources
|
|
12
|
-
export { AgentStream } from "./agent/index.js";
|
|
13
|
-
|
|
14
|
-
// Agent types
|
|
15
|
-
export {
|
|
16
|
-
BrowserProfile,
|
|
17
|
-
ProxyCountryCode,
|
|
18
|
-
RunStatus,
|
|
19
|
-
ErrorCategory,
|
|
20
|
-
EventType,
|
|
21
|
-
} from "./agent/types.js";
|
|
22
|
-
export type {
|
|
23
|
-
ProxyConfig,
|
|
24
|
-
AgentRunParams,
|
|
25
|
-
AgentRunResponse,
|
|
26
|
-
AgentRunAsyncResponse,
|
|
27
|
-
RunError,
|
|
28
|
-
StartedEvent,
|
|
29
|
-
StreamingUrlEvent,
|
|
30
|
-
ProgressEvent,
|
|
31
|
-
HeartbeatEvent,
|
|
32
|
-
CompleteEvent,
|
|
33
|
-
AgentRunWithStreamingResponse,
|
|
34
|
-
StreamOptions,
|
|
35
|
-
} from "./agent/types.js";
|
|
36
|
-
|
|
37
|
-
// Runs types
|
|
38
|
-
export { SortDirection } from "./runs/types.js";
|
|
39
|
-
export type {
|
|
40
|
-
BrowserConfig,
|
|
41
|
-
Run,
|
|
42
|
-
PaginationInfo,
|
|
43
|
-
RunListResponse,
|
|
44
|
-
RunListParams,
|
|
45
|
-
} from "./runs/types.js";
|
|
46
|
-
|
|
47
|
-
// Error hierarchy
|
|
48
|
-
export {
|
|
49
|
-
SDKError,
|
|
50
|
-
SSEParseError,
|
|
51
|
-
APIError,
|
|
52
|
-
APIConnectionError,
|
|
53
|
-
APITimeoutError,
|
|
54
|
-
APIStatusError,
|
|
55
|
-
BadRequestError,
|
|
56
|
-
AuthenticationError,
|
|
57
|
-
PermissionDeniedError,
|
|
58
|
-
NotFoundError,
|
|
59
|
-
RequestTimeoutError,
|
|
60
|
-
ConflictError,
|
|
61
|
-
UnprocessableEntityError,
|
|
62
|
-
RateLimitError,
|
|
63
|
-
InternalServerError,
|
|
64
|
-
} from "./_utils/errors.js";
|
package/src/runs/index.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runs resource for retrieving and listing automation runs.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { APIResource } from "../_utils/resource.js";
|
|
6
|
-
import type { Run, RunListParams, RunListResponse } from "./types.js";
|
|
7
|
-
|
|
8
|
-
/** Retrieve and list automation runs. */
|
|
9
|
-
export class RunsResource extends APIResource {
|
|
10
|
-
/**
|
|
11
|
-
* Retrieve a single run by its ID.
|
|
12
|
-
*
|
|
13
|
-
* Returns a promise that resolves with the full run details
|
|
14
|
-
* including status, result, error, and browser configuration.
|
|
15
|
-
*
|
|
16
|
-
* @param runId - The run ID returned by `agent.queue()` or any run response.
|
|
17
|
-
*/
|
|
18
|
-
async get(runId: string): Promise<Run> {
|
|
19
|
-
if (typeof runId !== "string" || !runId.trim()) {
|
|
20
|
-
throw new Error("run_id must be a non-empty string");
|
|
21
|
-
}
|
|
22
|
-
return this._client.get<Run>(`/v1/runs/${encodeURIComponent(runId)}`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* List automation runs, with optional filtering and pagination.
|
|
27
|
-
*
|
|
28
|
-
* Returns a promise that resolves with a paginated list of runs
|
|
29
|
-
* and pagination info (total count, next cursor).
|
|
30
|
-
*/
|
|
31
|
-
async list(params: RunListParams = {}): Promise<RunListResponse> {
|
|
32
|
-
const queryParams: Record<string, string | number | boolean> = {};
|
|
33
|
-
if (params.cursor !== undefined) queryParams["cursor"] = params.cursor;
|
|
34
|
-
if (params.limit !== undefined) queryParams["limit"] = params.limit;
|
|
35
|
-
if (params.status !== undefined) queryParams["status"] = params.status;
|
|
36
|
-
if (params.goal !== undefined) queryParams["goal"] = params.goal;
|
|
37
|
-
if (params.created_after !== undefined) queryParams["created_after"] = params.created_after;
|
|
38
|
-
if (params.created_before !== undefined) queryParams["created_before"] = params.created_before;
|
|
39
|
-
if (params.sort_direction !== undefined) queryParams["sort_direction"] = params.sort_direction;
|
|
40
|
-
|
|
41
|
-
const hasParams = Object.keys(queryParams).length > 0;
|
|
42
|
-
return this._client.get<RunListResponse>(
|
|
43
|
-
"/v1/runs",
|
|
44
|
-
hasParams ? { params: queryParams } : undefined,
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/runs/types.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Runs management request/response types.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { RunError, RunStatus } from "../agent/types.js";
|
|
6
|
-
|
|
7
|
-
/** Sort order for list queries. */
|
|
8
|
-
export enum SortDirection {
|
|
9
|
-
ASC = "asc",
|
|
10
|
-
DESC = "desc",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Browser configuration used for a run. */
|
|
14
|
-
export interface BrowserConfig {
|
|
15
|
-
/** Whether proxy was enabled. */
|
|
16
|
-
proxy_enabled: boolean | null;
|
|
17
|
-
/** Country code for proxy. */
|
|
18
|
-
proxy_country_code: string | null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** A single automation run with full details. */
|
|
22
|
-
export interface Run {
|
|
23
|
-
/** Unique identifier for the run. */
|
|
24
|
-
run_id: string;
|
|
25
|
-
/** Current status of the run. */
|
|
26
|
-
status: RunStatus;
|
|
27
|
-
/** Natural language goal for this automation run. */
|
|
28
|
-
goal: string;
|
|
29
|
-
/** ISO 8601 timestamp when run was created. */
|
|
30
|
-
created_at: string;
|
|
31
|
-
/** ISO 8601 timestamp when run started executing. */
|
|
32
|
-
started_at: string | null;
|
|
33
|
-
/** ISO 8601 timestamp when run finished executing. */
|
|
34
|
-
finished_at: string | null;
|
|
35
|
-
/** Number of steps taken during the automation. */
|
|
36
|
-
num_of_steps: number;
|
|
37
|
-
/** Extracted data from the automation run. `null` if not completed or failed. */
|
|
38
|
-
result: Record<string, unknown> | null;
|
|
39
|
-
/** Error details. `null` if the run succeeded or is still running. */
|
|
40
|
-
error: RunError | null;
|
|
41
|
-
/** URL to watch live browser session (available while running). */
|
|
42
|
-
streaming_url: string | null;
|
|
43
|
-
/** Browser configuration used for the run. */
|
|
44
|
-
browser_config: BrowserConfig | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Pagination metadata for list responses. */
|
|
48
|
-
export interface PaginationInfo {
|
|
49
|
-
/** Total number of runs matching the current filters. */
|
|
50
|
-
total: number;
|
|
51
|
-
/** Whether there are more results after this page. */
|
|
52
|
-
has_more: boolean;
|
|
53
|
-
/** Cursor for fetching next page. `null` if no more results. */
|
|
54
|
-
next_cursor: string | null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Paginated list of automation runs. */
|
|
58
|
-
export interface RunListResponse {
|
|
59
|
-
/** Array of runs. */
|
|
60
|
-
data: Run[];
|
|
61
|
-
/** Pagination information. */
|
|
62
|
-
pagination: PaginationInfo;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Parameters for listing runs. */
|
|
66
|
-
export interface RunListParams {
|
|
67
|
-
/** Pagination cursor from a previous response's `next_cursor` field. */
|
|
68
|
-
cursor?: string;
|
|
69
|
-
/** Maximum number of runs to return. */
|
|
70
|
-
limit?: number;
|
|
71
|
-
/** Filter by run status. */
|
|
72
|
-
status?: RunStatus;
|
|
73
|
-
/** Filter by goal text. */
|
|
74
|
-
goal?: string;
|
|
75
|
-
/** Filter runs created after this ISO timestamp. */
|
|
76
|
-
created_after?: string;
|
|
77
|
-
/** Filter runs created before this ISO timestamp. */
|
|
78
|
-
created_before?: string;
|
|
79
|
-
/** Sort order — `"asc"` or `"desc"`. */
|
|
80
|
-
sort_direction?: SortDirection;
|
|
81
|
-
}
|
package/src/version.ts
DELETED