@tiny-fish/cli 0.1.7 → 0.1.8-next.70
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 +3 -0
- package/dist/commands/fetch.js +16 -0
- package/dist/commands/profile.d.ts +14 -0
- package/dist/commands/profile.js +315 -0
- package/dist/index.js +2 -0
- package/dist/lib/client.d.ts +3 -1
- package/dist/lib/client.js +42 -5
- package/dist/lib/constants.d.ts +1 -0
- package/dist/lib/constants.js +4 -0
- package/dist/lib/types.d.ts +21 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -130,6 +130,9 @@ tinyfish fetch content get https://agentql.com --format markdown
|
|
|
130
130
|
# Include links and image links
|
|
131
131
|
tinyfish fetch content get https://agentql.com --links --image-links
|
|
132
132
|
|
|
133
|
+
# Bound each URL independently
|
|
134
|
+
tinyfish fetch content get https://agentql.com --per-url-timeout-ms 45000
|
|
135
|
+
|
|
133
136
|
# Human-readable output
|
|
134
137
|
tinyfish fetch content get https://agentql.com --pretty
|
|
135
138
|
```
|
package/dist/commands/fetch.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
1
2
|
import { getApiKey } from "../lib/auth.js";
|
|
2
3
|
import { fetchContentGet } from "../lib/client.js";
|
|
3
4
|
import { handleApiError, out, outLine } from "../lib/output.js";
|
|
5
|
+
const MIN_PER_URL_TIMEOUT_MS = 1;
|
|
6
|
+
const MAX_PER_URL_TIMEOUT_MS = 110000;
|
|
7
|
+
function parsePerUrlTimeoutMs(value) {
|
|
8
|
+
const parsed = Number(value);
|
|
9
|
+
if (!Number.isInteger(parsed) ||
|
|
10
|
+
parsed < MIN_PER_URL_TIMEOUT_MS ||
|
|
11
|
+
parsed > MAX_PER_URL_TIMEOUT_MS) {
|
|
12
|
+
throw new InvalidArgumentError(`must be an integer between ${MIN_PER_URL_TIMEOUT_MS} and ${MAX_PER_URL_TIMEOUT_MS}`);
|
|
13
|
+
}
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
4
16
|
function printPrettyFetch(response) {
|
|
5
17
|
outLine(`Results: ${response.results.length}`);
|
|
6
18
|
outLine(`Errors: ${response.errors.length}`);
|
|
@@ -42,6 +54,7 @@ export function registerFetch(program) {
|
|
|
42
54
|
.option("--format <format>", "Output format: markdown, html, or json")
|
|
43
55
|
.option("--links", "Include extracted links")
|
|
44
56
|
.option("--image-links", "Include extracted image links")
|
|
57
|
+
.option("--per-url-timeout-ms <milliseconds>", "Per-URL timeout budget in milliseconds", parsePerUrlTimeoutMs)
|
|
45
58
|
.option("--pretty", "Human-readable output")
|
|
46
59
|
.action(async (urls, opts) => {
|
|
47
60
|
const apiKey = getApiKey();
|
|
@@ -51,6 +64,9 @@ export function registerFetch(program) {
|
|
|
51
64
|
...(opts.format !== undefined ? { format: opts.format } : {}),
|
|
52
65
|
...(opts.links !== undefined ? { links: opts.links } : {}),
|
|
53
66
|
...(opts.imageLinks !== undefined ? { image_links: opts.imageLinks } : {}),
|
|
67
|
+
...(opts.perUrlTimeoutMs !== undefined
|
|
68
|
+
? { per_url_timeout_ms: opts.perUrlTimeoutMs }
|
|
69
|
+
: {}),
|
|
54
70
|
}, apiKey);
|
|
55
71
|
if (opts.pretty) {
|
|
56
72
|
printPrettyFetch(response);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { CookieRecord } from "../lib/types.js";
|
|
3
|
+
export declare function extractChromeCookies(domain: string): Promise<CookieRecord[]>;
|
|
4
|
+
export declare function extractAllChromeCookies(): Promise<CookieRecord[]>;
|
|
5
|
+
type TldtsParse = (host: string, opts: {
|
|
6
|
+
allowPrivateDomains: boolean;
|
|
7
|
+
}) => {
|
|
8
|
+
domain?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function groupByCanonicalDomain(cookies: CookieRecord[], parse: TldtsParse): Map<string, CookieRecord[]>;
|
|
11
|
+
export declare const MAX_COOKIES_PER_UPLOAD = 3000;
|
|
12
|
+
export declare function buildChunks(groups: Map<string, CookieRecord[]>): CookieRecord[][];
|
|
13
|
+
export declare function registerProfile(program: Command): void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as os from "os";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { getApiKey } from "../lib/auth.js";
|
|
6
|
+
import { profileCreate, profileUpload } from "../lib/client.js";
|
|
7
|
+
import { err, errLine, handleApiError, out, outLine } from "../lib/output.js";
|
|
8
|
+
// ── UserFacingError ───────────────────────────────────────────────────────────
|
|
9
|
+
// Thrown by helpers to signal a terminal error that should be printed and exit 1
|
|
10
|
+
// without going through handleApiError (which would print a second error line).
|
|
11
|
+
class UserFacingError extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "UserFacingError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
18
|
+
function getChromeCookiesPath() {
|
|
19
|
+
const platform = process.platform;
|
|
20
|
+
if (platform === "darwin") {
|
|
21
|
+
return path.join(os.homedir(), "Library", "Application Support", "Google", "Chrome", "Default", "Cookies");
|
|
22
|
+
}
|
|
23
|
+
if (platform === "linux") {
|
|
24
|
+
return path.join(os.homedir(), ".config", "google-chrome", "Default", "Cookies");
|
|
25
|
+
}
|
|
26
|
+
// Windows guard — handled in withCookiesDb
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
function validateDomain(domain) {
|
|
30
|
+
if (domain.includes("/") || domain.includes("://") || /\s/.test(domain) || /:\d/.test(domain)) {
|
|
31
|
+
err({ error: "domain must be a plain hostname (e.g. github.com)" });
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Chrome-internal timestamp (microseconds since 1601-01-01) → Unix seconds
|
|
36
|
+
const CHROME_EPOCH_DELTA_SECONDS = 11644473600;
|
|
37
|
+
function chromeTimeToUnix(chromeMicros) {
|
|
38
|
+
return Math.floor(chromeMicros / 1e6) - CHROME_EPOCH_DELTA_SECONDS;
|
|
39
|
+
}
|
|
40
|
+
// Sets up chrome-cookies-secure in a temp dir and calls fn; cleans up after.
|
|
41
|
+
async function withCookiesDb(fn) {
|
|
42
|
+
if (process.platform === "win32") {
|
|
43
|
+
throw new UserFacingError("Cookie extraction is not supported on Windows yet");
|
|
44
|
+
}
|
|
45
|
+
const cookiesPath = getChromeCookiesPath();
|
|
46
|
+
if (!fs.existsSync(cookiesPath)) {
|
|
47
|
+
throw new UserFacingError(`Chrome cookies file not found at ${cookiesPath}. Is Google Chrome installed?`);
|
|
48
|
+
}
|
|
49
|
+
// chrome-cookies-secure expects a profile directory and appends "/Cookies".
|
|
50
|
+
// Copy the file into a temp dir so we avoid the Chrome file lock.
|
|
51
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tinyfish-chrome-cookies-"));
|
|
52
|
+
try {
|
|
53
|
+
fs.copyFileSync(cookiesPath, path.join(tmpDir, "Cookies"));
|
|
54
|
+
// chrome-cookies-secure is a CommonJS module — use createRequire to load it
|
|
55
|
+
const require = createRequire(import.meta.url);
|
|
56
|
+
const chromeCookies = require("chrome-cookies-secure");
|
|
57
|
+
return await fn(tmpDir, chromeCookies);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
try {
|
|
61
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Ignore cleanup errors
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Extract cookies for a single domain using an already-open cookies DB.
|
|
69
|
+
async function extractDomain(tmpDir, chromeCookies, domain) {
|
|
70
|
+
// "puppeteer" format returns an array with capitalized boolean fields and
|
|
71
|
+
// Chrome-internal microsecond timestamps — convert to our CookieRecord shape.
|
|
72
|
+
const raw = await chromeCookies.getCookiesPromised(`https://${domain}`, "puppeteer", tmpDir);
|
|
73
|
+
return raw.map((c) => ({
|
|
74
|
+
name: c.name,
|
|
75
|
+
value: c.value,
|
|
76
|
+
domain: c.domain,
|
|
77
|
+
path: c.path,
|
|
78
|
+
secure: c.Secure ?? false,
|
|
79
|
+
httpOnly: c.HttpOnly ?? false,
|
|
80
|
+
...(c.expires && c.expires > 0 ? { expires: chromeTimeToUnix(c.expires) } : {}),
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
// Exported for testing
|
|
84
|
+
export async function extractChromeCookies(domain) {
|
|
85
|
+
return withCookiesDb((tmpDir, chromeCookies) => extractDomain(tmpDir, chromeCookies, domain));
|
|
86
|
+
}
|
|
87
|
+
// Exported for testing
|
|
88
|
+
export async function extractAllChromeCookies() {
|
|
89
|
+
return withCookiesDb(async (tmpDir, chromeCookies) => {
|
|
90
|
+
const { DatabaseSync } = createRequire(import.meta.url)("node:sqlite");
|
|
91
|
+
let sqliteDb = null;
|
|
92
|
+
let hostKeys;
|
|
93
|
+
try {
|
|
94
|
+
sqliteDb = new DatabaseSync(path.join(tmpDir, "Cookies")); // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal
|
|
95
|
+
// Only import domains with auth-relevant cookies — skips tracking/analytics junk.
|
|
96
|
+
// A domain qualifies if it has any HttpOnly cookie (session/auth indicator) or
|
|
97
|
+
// a cookie whose name suggests authentication.
|
|
98
|
+
const rows = sqliteDb
|
|
99
|
+
.prepare(`SELECT DISTINCT host_key FROM cookies
|
|
100
|
+
WHERE is_httponly = 1
|
|
101
|
+
OR name LIKE '%session%'
|
|
102
|
+
OR name LIKE '%token%'
|
|
103
|
+
OR name LIKE '%auth%'
|
|
104
|
+
OR name LIKE '%sid%'
|
|
105
|
+
OR name LIKE '%login%'
|
|
106
|
+
OR name LIKE '%user%'
|
|
107
|
+
OR name LIKE '%account%'`)
|
|
108
|
+
.all();
|
|
109
|
+
hostKeys = rows.map((r) => r.host_key);
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
throw new UserFacingError(`Failed to read Chrome cookies database: ${e instanceof Error ? e.message : String(e)}`);
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
try {
|
|
116
|
+
sqliteDb?.close();
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// Ignore
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// 2. Canonicalize host_keys → registrable domains (mirrors frontend/app/lib/services/domain-utils.ts)
|
|
123
|
+
const require = createRequire(import.meta.url);
|
|
124
|
+
const { parse } = require("tldts");
|
|
125
|
+
const registrableDomains = new Set();
|
|
126
|
+
for (const hk of hostKeys) {
|
|
127
|
+
const cleaned = hk.startsWith(".") ? hk.slice(1) : hk;
|
|
128
|
+
const result = parse(cleaned, { allowPrivateDomains: true });
|
|
129
|
+
if (result.domain)
|
|
130
|
+
registrableDomains.add(result.domain.toLowerCase());
|
|
131
|
+
}
|
|
132
|
+
errLine(`Scanning ${registrableDomains.size} domains from Chrome...`);
|
|
133
|
+
// 3. Extract per-domain and concat
|
|
134
|
+
const all = [];
|
|
135
|
+
for (const domain of registrableDomains) {
|
|
136
|
+
try {
|
|
137
|
+
const cookies = await extractDomain(tmpDir, chromeCookies, domain);
|
|
138
|
+
all.push(...cookies);
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
// skip domains chrome-cookies-secure can't parse (IPs, .local, etc.)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// 4. Dedup by name+domain+path
|
|
145
|
+
const seen = new Set();
|
|
146
|
+
return all.filter((c) => {
|
|
147
|
+
const key = `${c.name}\t${c.domain}\t${c.path}`;
|
|
148
|
+
if (seen.has(key))
|
|
149
|
+
return false;
|
|
150
|
+
seen.add(key);
|
|
151
|
+
return true;
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
// Exported for testing
|
|
156
|
+
export function groupByCanonicalDomain(cookies, parse) {
|
|
157
|
+
const groups = new Map();
|
|
158
|
+
for (const c of cookies) {
|
|
159
|
+
const cleaned = c.domain.startsWith(".") ? c.domain.slice(1) : c.domain;
|
|
160
|
+
const cd = parse(cleaned, { allowPrivateDomains: true }).domain?.toLowerCase() ?? cleaned;
|
|
161
|
+
const bucket = groups.get(cd) ?? [];
|
|
162
|
+
bucket.push(c);
|
|
163
|
+
groups.set(cd, bucket);
|
|
164
|
+
}
|
|
165
|
+
return groups;
|
|
166
|
+
}
|
|
167
|
+
// Exported for testing
|
|
168
|
+
export const MAX_COOKIES_PER_UPLOAD = 3000;
|
|
169
|
+
// Exported for testing
|
|
170
|
+
export function buildChunks(groups) {
|
|
171
|
+
const chunks = [];
|
|
172
|
+
let current = [];
|
|
173
|
+
for (const group of groups.values()) {
|
|
174
|
+
// A group that alone exceeds the cap is its own chunk (never split a canonical domain)
|
|
175
|
+
if (group.length > MAX_COOKIES_PER_UPLOAD) {
|
|
176
|
+
if (current.length > 0) {
|
|
177
|
+
chunks.push(current);
|
|
178
|
+
current = [];
|
|
179
|
+
}
|
|
180
|
+
chunks.push(group);
|
|
181
|
+
}
|
|
182
|
+
else if (current.length + group.length > MAX_COOKIES_PER_UPLOAD) {
|
|
183
|
+
chunks.push(current);
|
|
184
|
+
current = [...group];
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
current.push(...group);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (current.length > 0)
|
|
191
|
+
chunks.push(current);
|
|
192
|
+
return chunks;
|
|
193
|
+
}
|
|
194
|
+
// ── Pretty printers ───────────────────────────────────────────────────────────
|
|
195
|
+
function printPrettyProfileCreate(profile) {
|
|
196
|
+
outLine("Profile created");
|
|
197
|
+
outLine(`ID: ${profile.id}`);
|
|
198
|
+
outLine(`Name: ${profile.name}`);
|
|
199
|
+
outLine(`Created at: ${profile.created_at}`);
|
|
200
|
+
}
|
|
201
|
+
function printPrettyProfileUpload(result) {
|
|
202
|
+
if (result.profile_id)
|
|
203
|
+
outLine(`Profile ID: ${result.profile_id}`);
|
|
204
|
+
outLine(`Cookies uploaded: ${result.cookie_count}`);
|
|
205
|
+
outLine(`Domains updated: ${result.domains_updated.join(", ")}`);
|
|
206
|
+
}
|
|
207
|
+
export function registerProfile(program) {
|
|
208
|
+
const profileCmd = program
|
|
209
|
+
.command("profile")
|
|
210
|
+
.description("Profile commands")
|
|
211
|
+
.enablePositionalOptions();
|
|
212
|
+
profileCmd
|
|
213
|
+
.command("create")
|
|
214
|
+
.description("Create a browser profile")
|
|
215
|
+
.requiredOption("--name <name>", "Profile name")
|
|
216
|
+
.option("--pretty", "Human-readable output")
|
|
217
|
+
.action(async (opts) => {
|
|
218
|
+
const apiKey = getApiKey();
|
|
219
|
+
try {
|
|
220
|
+
const response = await profileCreate(opts.name, apiKey);
|
|
221
|
+
if (opts.pretty) {
|
|
222
|
+
printPrettyProfileCreate(response);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
out(response);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
handleApiError(error);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
profileCmd
|
|
233
|
+
.command("import-cookies")
|
|
234
|
+
.description("Import Chrome cookies into a profile. Use --domain for a single domain or --all-domains for every domain in your Chrome profile. Exactly one must be provided.")
|
|
235
|
+
.option("--domain <domain>", "Domain to import cookies for (e.g. github.com)")
|
|
236
|
+
.option("--all-domains", "Import cookies for all registrable domains (e.g. github.com) found in your Chrome profile. IPs and non-resolvable hostnames (e.g. localhost) are skipped.")
|
|
237
|
+
.option("--profile-id <id>", "Profile ID to import cookies into (creates new profile if omitted)")
|
|
238
|
+
.option("--pretty", "Human-readable output")
|
|
239
|
+
.action(async (opts) => {
|
|
240
|
+
// Mutual-exclusivity guard — must provide exactly one of --domain / --all-domains
|
|
241
|
+
if (!opts.domain && !opts.allDomains) {
|
|
242
|
+
err({ error: "Provide exactly one of --domain or --all-domains" });
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
if (opts.domain && opts.allDomains) {
|
|
246
|
+
err({ error: "Provide exactly one of --domain or --all-domains" });
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
const apiKey = getApiKey();
|
|
250
|
+
if (opts.domain) {
|
|
251
|
+
validateDomain(opts.domain);
|
|
252
|
+
}
|
|
253
|
+
let profileId = opts.profileId;
|
|
254
|
+
try {
|
|
255
|
+
// Extract cookies before creating profile to avoid orphan profiles
|
|
256
|
+
// if extraction fails (Windows, no Chrome, no cookies).
|
|
257
|
+
const cookies = opts.allDomains
|
|
258
|
+
? await extractAllChromeCookies()
|
|
259
|
+
: await extractChromeCookies(opts.domain);
|
|
260
|
+
if (cookies.length === 0) {
|
|
261
|
+
throw new UserFacingError(opts.allDomains
|
|
262
|
+
? "No Chrome cookies found. Is Google Chrome installed and have you logged in to any sites?"
|
|
263
|
+
: `No Chrome cookies found for ${opts.domain}. Are you logged in to this site in Chrome?`);
|
|
264
|
+
}
|
|
265
|
+
if (profileId === undefined) {
|
|
266
|
+
const name = opts.allDomains ? "chrome-import" : opts.domain;
|
|
267
|
+
const created = await profileCreate(name, apiKey);
|
|
268
|
+
profileId = created.id;
|
|
269
|
+
}
|
|
270
|
+
let result;
|
|
271
|
+
if (opts.allDomains) {
|
|
272
|
+
// Batch upload — never split a canonical domain across chunks
|
|
273
|
+
const require = createRequire(import.meta.url);
|
|
274
|
+
const { parse } = require("tldts");
|
|
275
|
+
const groups = groupByCanonicalDomain(cookies, parse);
|
|
276
|
+
const chunks = buildChunks(groups);
|
|
277
|
+
let cookieCount = 0;
|
|
278
|
+
const domainsUpdated = [];
|
|
279
|
+
const domainsFailed = [];
|
|
280
|
+
for (const chunk of chunks) {
|
|
281
|
+
const r = await profileUpload(profileId, chunk, apiKey);
|
|
282
|
+
cookieCount += r.cookie_count;
|
|
283
|
+
domainsUpdated.push(...r.domains_updated);
|
|
284
|
+
if (r.domains_failed)
|
|
285
|
+
domainsFailed.push(...r.domains_failed);
|
|
286
|
+
}
|
|
287
|
+
result = {
|
|
288
|
+
profile_id: profileId,
|
|
289
|
+
cookie_count: cookieCount,
|
|
290
|
+
domains_updated: domainsUpdated,
|
|
291
|
+
...(domainsFailed.length > 0 ? { domains_failed: domainsFailed } : {}),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
result = await profileUpload(profileId, cookies, apiKey);
|
|
296
|
+
}
|
|
297
|
+
if (result.domains_failed && result.domains_failed.length > 0) {
|
|
298
|
+
errLine(`Warning: failed to update cookies for domains: ${result.domains_failed.join(", ")}`);
|
|
299
|
+
}
|
|
300
|
+
if (opts.pretty) {
|
|
301
|
+
printPrettyProfileUpload(result);
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
out(result);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
if (error instanceof UserFacingError) {
|
|
309
|
+
err({ error: error.message });
|
|
310
|
+
process.exit(1);
|
|
311
|
+
}
|
|
312
|
+
handleApiError(error);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { registerAuth } from "./commands/auth.js";
|
|
|
5
5
|
import { registerBatch } from "./commands/batch.js";
|
|
6
6
|
import { registerFetch } from "./commands/fetch.js";
|
|
7
7
|
import { registerBrowser } from "./commands/browser.js";
|
|
8
|
+
import { registerProfile } from "./commands/profile.js";
|
|
8
9
|
import { registerRun } from "./commands/run.js";
|
|
9
10
|
import { registerRuns } from "./commands/runs.js";
|
|
10
11
|
import { registerConfigureClaude } from "./commands/config-claude.js";
|
|
@@ -27,6 +28,7 @@ program
|
|
|
27
28
|
registerAuth(program);
|
|
28
29
|
registerConfigureClaude(program);
|
|
29
30
|
registerBrowser(program);
|
|
31
|
+
registerProfile(program);
|
|
30
32
|
const agentCmd = program
|
|
31
33
|
.command("agent")
|
|
32
34
|
.description("Agent automation commands")
|
package/dist/lib/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AgentRunAsyncResponse, type AgentRunResponse, type AgentRunWithStreamingResponse, type FetchGetContentsParams, type FetchResponse, type BrowserSession, type Run, type RunListParams, type RunListResponse, type SearchQueryParams, type SearchQueryResponse } from "@tiny-fish/sdk";
|
|
2
|
-
import type { BatchCancelResponse, BatchGetResponse, BatchRunRequest, BatchRunResponse, CancelRunResponse, CliAgentRunParams, CliBrowserSessionCreateParams, RunStepsResponse } from "./types.js";
|
|
2
|
+
import type { BatchCancelResponse, BatchGetResponse, BatchRunRequest, BatchRunResponse, CancelRunResponse, CliAgentRunParams, CliBrowserSessionCreateParams, CookieRecord, ProfileCreateResponse, ProfileUploadResponse, RunStepsResponse } from "./types.js";
|
|
3
3
|
export declare function runSync(req: CliAgentRunParams, apiKey: string): Promise<AgentRunResponse>;
|
|
4
4
|
export declare function runAsync(req: CliAgentRunParams, apiKey: string): Promise<AgentRunAsyncResponse>;
|
|
5
5
|
export declare function runStream(req: CliAgentRunParams, apiKey: string, signal?: AbortSignal): AsyncGenerator<AgentRunWithStreamingResponse>;
|
|
@@ -13,3 +13,5 @@ export declare function cancelRun(runId: string, apiKey: string): Promise<Cancel
|
|
|
13
13
|
export declare function submitBatch(req: BatchRunRequest, apiKey: string): Promise<BatchRunResponse>;
|
|
14
14
|
export declare function getBatchRuns(runIds: string[], apiKey: string): Promise<BatchGetResponse>;
|
|
15
15
|
export declare function cancelBatchRuns(runIds: string[], apiKey: string): Promise<BatchCancelResponse>;
|
|
16
|
+
export declare function profileCreate(name: string, apiKey: string): Promise<ProfileCreateResponse>;
|
|
17
|
+
export declare function profileUpload(profileId: string, cookies: CookieRecord[], apiKey: string): Promise<ProfileUploadResponse>;
|
package/dist/lib/client.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { APIStatusError, agentRunAsyncResponseSchema, agentRunResponseSchema, agentRunWithStreamingResponseSchema, fetchResponseSchema, browserSessionSchema, searchQueryResponseSchema, TinyFish, runSchema, runStatusSchema, } from "@tiny-fish/sdk";
|
|
2
|
-
import { BASE_URL } from "./constants.js";
|
|
2
|
+
import { BASE_URL, CLI_VERSION } from "./constants.js";
|
|
3
3
|
import { ApiError } from "./output.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
class TinyFishCliClient extends TinyFish {
|
|
6
6
|
_buildHeaders() {
|
|
7
|
+
const base = super._buildHeaders();
|
|
7
8
|
return {
|
|
8
|
-
...
|
|
9
|
+
...base,
|
|
9
10
|
"X-TF-Request-Origin": "tinyfish-cli",
|
|
11
|
+
"User-Agent": `${base["User-Agent"] ?? ""} @tiny-fish/cli/${CLI_VERSION}`.trim(),
|
|
10
12
|
};
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -35,10 +37,12 @@ const cancelRunResponseSchema = z.object({
|
|
|
35
37
|
});
|
|
36
38
|
const batchRunResponseSchema = z.object({
|
|
37
39
|
run_ids: z.array(z.string()).nullable(),
|
|
38
|
-
error: z
|
|
40
|
+
error: z
|
|
41
|
+
.object({
|
|
39
42
|
code: z.string(),
|
|
40
43
|
message: z.string(),
|
|
41
|
-
})
|
|
44
|
+
})
|
|
45
|
+
.nullable(),
|
|
42
46
|
});
|
|
43
47
|
const batchGetResponseSchema = z.object({
|
|
44
48
|
data: z.array(runSchema),
|
|
@@ -79,7 +83,9 @@ function parseWithSchema(schema, value, message) {
|
|
|
79
83
|
return result.data;
|
|
80
84
|
}
|
|
81
85
|
function normalizeStreamEvent(event) {
|
|
82
|
-
if (typeof event !== "object" ||
|
|
86
|
+
if (typeof event !== "object" ||
|
|
87
|
+
event === null ||
|
|
88
|
+
event.type !== "COMPLETE") {
|
|
83
89
|
return event;
|
|
84
90
|
}
|
|
85
91
|
const data = event;
|
|
@@ -270,3 +276,34 @@ export async function cancelBatchRuns(runIds, apiKey) {
|
|
|
270
276
|
rethrowSdkError(error);
|
|
271
277
|
}
|
|
272
278
|
}
|
|
279
|
+
const profileCreateResponseSchema = z.object({
|
|
280
|
+
id: z.string(),
|
|
281
|
+
name: z.string(),
|
|
282
|
+
created_at: z.string(),
|
|
283
|
+
});
|
|
284
|
+
const profileUploadResponseSchema = z.object({
|
|
285
|
+
profile_id: z.string().optional(),
|
|
286
|
+
cookie_count: z.number(),
|
|
287
|
+
domains_updated: z.array(z.string()),
|
|
288
|
+
domains_failed: z.array(z.string()).optional(),
|
|
289
|
+
});
|
|
290
|
+
export async function profileCreate(name, apiKey) {
|
|
291
|
+
try {
|
|
292
|
+
const response = await createSdkClient(apiKey).post("/v1/profiles", {
|
|
293
|
+
json: { name },
|
|
294
|
+
});
|
|
295
|
+
return parseWithSchema(profileCreateResponseSchema, response, "Invalid profile create response");
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
rethrowSdkError(error);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export async function profileUpload(profileId, cookies, apiKey) {
|
|
302
|
+
try {
|
|
303
|
+
const response = await createSdkClient(apiKey).post(`/v1/profiles/${encodeURIComponent(profileId)}/upload`, { json: { cookies } });
|
|
304
|
+
return parseWithSchema(profileUploadResponseSchema, response, "Invalid profile upload response");
|
|
305
|
+
}
|
|
306
|
+
catch (error) {
|
|
307
|
+
rethrowSdkError(error);
|
|
308
|
+
}
|
|
309
|
+
}
|
package/dist/lib/constants.d.ts
CHANGED
package/dist/lib/constants.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { createRequire } from "module";
|
|
2
|
+
const _require = createRequire(import.meta.url);
|
|
3
|
+
const _pkg = _require("../../package.json");
|
|
4
|
+
export const CLI_VERSION = _pkg.version;
|
|
1
5
|
/** Base URL for the TinyFish API. Override with TINYFISH_API_URL for staging/self-hosted (must be https). */
|
|
2
6
|
const apiUrlOverride = process.env["TINYFISH_API_URL"]?.trim();
|
|
3
7
|
if (apiUrlOverride) {
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -69,3 +69,24 @@ export interface LocalBatch {
|
|
|
69
69
|
submitted: number;
|
|
70
70
|
created_at: string;
|
|
71
71
|
}
|
|
72
|
+
export interface ProfileCreateResponse {
|
|
73
|
+
id: string;
|
|
74
|
+
name: string;
|
|
75
|
+
created_at: string;
|
|
76
|
+
}
|
|
77
|
+
export interface CookieRecord {
|
|
78
|
+
name: string;
|
|
79
|
+
value: string;
|
|
80
|
+
domain: string;
|
|
81
|
+
path: string;
|
|
82
|
+
httpOnly: boolean;
|
|
83
|
+
secure: boolean;
|
|
84
|
+
sameSite?: string;
|
|
85
|
+
expires?: number;
|
|
86
|
+
}
|
|
87
|
+
export interface ProfileUploadResponse {
|
|
88
|
+
profile_id?: string;
|
|
89
|
+
cookie_count: number;
|
|
90
|
+
domains_updated: string[];
|
|
91
|
+
domains_failed?: string[];
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-fish/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8-next.70",
|
|
4
4
|
"description": "TinyFish CLI — run web automations from your terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@tiny-fish/sdk": "^0.0.7",
|
|
36
|
+
"chrome-cookies-secure": "^3.0.2",
|
|
36
37
|
"commander": "^12.0.0",
|
|
37
38
|
"globals": "^17.4.0",
|
|
38
39
|
"zod": "^4.3.6"
|
|
@@ -48,9 +49,11 @@
|
|
|
48
49
|
"vitest": "^4.1.0"
|
|
49
50
|
},
|
|
50
51
|
"overrides": {
|
|
51
|
-
"
|
|
52
|
+
"esbuild": "0.28.1",
|
|
53
|
+
"vite": "7.3.5",
|
|
52
54
|
"brace-expansion": "^5.0.6",
|
|
53
|
-
"postcss": "8.5.10"
|
|
55
|
+
"postcss": "8.5.10",
|
|
56
|
+
"tar": "^7"
|
|
54
57
|
},
|
|
55
58
|
"engines": {
|
|
56
59
|
"node": ">=24.0.0"
|