@kana-ai/edgar-ext-tinyfish 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +106 -2
- package/dist/src/api/client.d.ts +27 -0
- package/dist/src/api/client.js +53 -0
- package/dist/src/api/failures.d.ts +14 -0
- package/dist/src/api/failures.js +87 -0
- package/dist/src/index.d.ts +81 -0
- package/dist/src/index.js +15 -0
- package/dist/src/schemas/config.d.ts +6 -0
- package/dist/src/schemas/config.js +6 -0
- package/dist/src/schemas/tinyfish.d.ts +99 -0
- package/dist/src/schemas/tinyfish.js +60 -0
- package/dist/src/schemas/tools.d.ts +110 -0
- package/dist/src/schemas/tools.js +66 -0
- package/dist/src/tools/agent.d.ts +56 -0
- package/dist/src/tools/agent.js +129 -0
- package/dist/src/tools/web.d.ts +30 -0
- package/dist/src/tools/web.js +51 -0
- package/edgar-extension.json +107 -0
- package/package.json +41 -3
- package/schemas/cancel_run.in.json +11 -0
- package/schemas/cancel_run.out.json +16 -0
- package/schemas/config.json +17 -0
- package/schemas/fetch.in.json +16 -0
- package/schemas/fetch.out.json +46 -0
- package/schemas/run.in.json +27 -0
- package/schemas/run.out.json +16 -0
- package/schemas/run_state.in.json +11 -0
- package/schemas/run_state.out.json +52 -0
- package/schemas/search.in.json +16 -0
- package/schemas/search.out.json +33 -0
- package/schemas/start_run.in.json +27 -0
- package/schemas/start_run.out.json +10 -0
- package/schemas/step_screenshot.in.json +15 -0
- package/schemas/step_screenshot.out.json +15 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Why a run ended `FAILED` or `CANCELLED`; only the synchronous run sends `code`. */
|
|
3
|
+
export declare const runError: z.ZodObject<{
|
|
4
|
+
code: z.ZodOptional<z.ZodString>;
|
|
5
|
+
message: z.ZodString;
|
|
6
|
+
category: z.ZodString;
|
|
7
|
+
retry_after: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
/** The answer of `POST /v1/automation/run`. */
|
|
10
|
+
export declare const syncRun: z.ZodObject<{
|
|
11
|
+
run_id: z.ZodNullable<z.ZodString>;
|
|
12
|
+
status: z.ZodString;
|
|
13
|
+
num_of_steps: z.ZodNullable<z.ZodNumber>;
|
|
14
|
+
result: z.ZodUnknown;
|
|
15
|
+
error: z.ZodNullable<z.ZodObject<{
|
|
16
|
+
code: z.ZodOptional<z.ZodString>;
|
|
17
|
+
message: z.ZodString;
|
|
18
|
+
category: z.ZodString;
|
|
19
|
+
retry_after: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
20
|
+
}, z.core.$strip>>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
/** The answer of `POST /v1/automation/run-async`. */
|
|
23
|
+
export declare const startedRun: z.ZodObject<{
|
|
24
|
+
run_id: z.ZodNullable<z.ZodString>;
|
|
25
|
+
error: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
26
|
+
code: z.ZodOptional<z.ZodString>;
|
|
27
|
+
message: z.ZodString;
|
|
28
|
+
}, z.core.$strip>>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
/** The status of a run. */
|
|
31
|
+
export declare const runStatus: z.ZodEnum<{
|
|
32
|
+
CANCELLED: "CANCELLED";
|
|
33
|
+
COMPLETED: "COMPLETED";
|
|
34
|
+
FAILED: "FAILED";
|
|
35
|
+
PENDING: "PENDING";
|
|
36
|
+
RUNNING: "RUNNING";
|
|
37
|
+
}>;
|
|
38
|
+
/** The answer of `GET /v1/runs/{id}`, with the fields the tools read. */
|
|
39
|
+
export declare const runDetail: z.ZodObject<{
|
|
40
|
+
run_id: z.ZodString;
|
|
41
|
+
status: z.ZodEnum<{
|
|
42
|
+
CANCELLED: "CANCELLED";
|
|
43
|
+
COMPLETED: "COMPLETED";
|
|
44
|
+
FAILED: "FAILED";
|
|
45
|
+
PENDING: "PENDING";
|
|
46
|
+
RUNNING: "RUNNING";
|
|
47
|
+
}>;
|
|
48
|
+
num_of_steps: z.ZodNullable<z.ZodNumber>;
|
|
49
|
+
result: z.ZodUnknown;
|
|
50
|
+
error: z.ZodNullable<z.ZodObject<{
|
|
51
|
+
code: z.ZodOptional<z.ZodString>;
|
|
52
|
+
message: z.ZodString;
|
|
53
|
+
category: z.ZodString;
|
|
54
|
+
retry_after: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
streaming_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
57
|
+
steps: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
status: z.ZodString;
|
|
60
|
+
action: z.ZodNullable<z.ZodString>;
|
|
61
|
+
}, z.core.$strip>>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
/** The answer of `POST /v1/runs/{id}/cancel`. */
|
|
64
|
+
export declare const cancelledRun: z.ZodObject<{
|
|
65
|
+
run_id: z.ZodString;
|
|
66
|
+
status: z.ZodString;
|
|
67
|
+
message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
68
|
+
}, z.core.$strip>;
|
|
69
|
+
/** The answer of the Search API. */
|
|
70
|
+
export declare const searchAnswer: z.ZodObject<{
|
|
71
|
+
results: z.ZodArray<z.ZodObject<{
|
|
72
|
+
title: z.ZodString;
|
|
73
|
+
url: z.ZodString;
|
|
74
|
+
snippet: z.ZodString;
|
|
75
|
+
site_name: z.ZodString;
|
|
76
|
+
}, z.core.$strip>>;
|
|
77
|
+
total_results: z.ZodNumber;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
/** The answer of the Fetch API: each page, and each URL that failed. */
|
|
80
|
+
export declare const fetchAnswer: z.ZodObject<{
|
|
81
|
+
results: z.ZodArray<z.ZodObject<{
|
|
82
|
+
url: z.ZodString;
|
|
83
|
+
final_url: z.ZodNullable<z.ZodString>;
|
|
84
|
+
title: z.ZodNullable<z.ZodString>;
|
|
85
|
+
text: z.ZodNullable<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>>;
|
|
87
|
+
errors: z.ZodArray<z.ZodObject<{
|
|
88
|
+
url: z.ZodString;
|
|
89
|
+
error: z.ZodString;
|
|
90
|
+
status: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
}, z.core.$strip>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
/** The body of an error answer. */
|
|
94
|
+
export declare const errorBody: z.ZodObject<{
|
|
95
|
+
error: z.ZodObject<{
|
|
96
|
+
code: z.ZodOptional<z.ZodString>;
|
|
97
|
+
message: z.ZodOptional<z.ZodString>;
|
|
98
|
+
}, z.core.$strip>;
|
|
99
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Why a run ended `FAILED` or `CANCELLED`; only the synchronous run sends `code`. */
|
|
3
|
+
export const runError = z.object({
|
|
4
|
+
code: z.string().optional(),
|
|
5
|
+
message: z.string(),
|
|
6
|
+
category: z.string(),
|
|
7
|
+
retry_after: z.number().nullable().optional(),
|
|
8
|
+
});
|
|
9
|
+
/** The answer of `POST /v1/automation/run`. */
|
|
10
|
+
export const syncRun = z.object({
|
|
11
|
+
run_id: z.string().nullable(),
|
|
12
|
+
status: z.string(),
|
|
13
|
+
num_of_steps: z.number().int().nullable(),
|
|
14
|
+
result: z.unknown(),
|
|
15
|
+
error: runError.nullable(),
|
|
16
|
+
});
|
|
17
|
+
/** The answer of `POST /v1/automation/run-async`. */
|
|
18
|
+
export const startedRun = z.object({
|
|
19
|
+
run_id: z.string().nullable(),
|
|
20
|
+
error: z.object({ code: z.string().optional(), message: z.string() }).nullable().optional(),
|
|
21
|
+
});
|
|
22
|
+
/** The status of a run. */
|
|
23
|
+
export const runStatus = z.enum(["PENDING", "RUNNING", "COMPLETED", "FAILED", "CANCELLED"]);
|
|
24
|
+
/** The answer of `GET /v1/runs/{id}`, with the fields the tools read. */
|
|
25
|
+
export const runDetail = z.object({
|
|
26
|
+
run_id: z.string(),
|
|
27
|
+
status: runStatus,
|
|
28
|
+
num_of_steps: z.number().int().nullable(),
|
|
29
|
+
result: z.unknown(),
|
|
30
|
+
error: runError.nullable(),
|
|
31
|
+
streaming_url: z.string().nullable().optional(),
|
|
32
|
+
steps: z
|
|
33
|
+
.array(z.object({ id: z.string(), status: z.string(), action: z.string().nullable() }))
|
|
34
|
+
.default([]),
|
|
35
|
+
});
|
|
36
|
+
/** The answer of `POST /v1/runs/{id}/cancel`. */
|
|
37
|
+
export const cancelledRun = z.object({
|
|
38
|
+
run_id: z.string(),
|
|
39
|
+
status: z.string(),
|
|
40
|
+
message: z.string().nullable().optional(),
|
|
41
|
+
});
|
|
42
|
+
/** The answer of the Search API. */
|
|
43
|
+
export const searchAnswer = z.object({
|
|
44
|
+
results: z.array(z.object({ title: z.string(), url: z.string(), snippet: z.string(), site_name: z.string() })),
|
|
45
|
+
total_results: z.number().int(),
|
|
46
|
+
});
|
|
47
|
+
/** The answer of the Fetch API: each page, and each URL that failed. */
|
|
48
|
+
export const fetchAnswer = z.object({
|
|
49
|
+
results: z.array(z.object({
|
|
50
|
+
url: z.string(),
|
|
51
|
+
final_url: z.string().nullable(),
|
|
52
|
+
title: z.string().nullable(),
|
|
53
|
+
text: z.string().nullable(),
|
|
54
|
+
})),
|
|
55
|
+
errors: z.array(z.object({ url: z.string(), error: z.string(), status: z.number().int().optional() })),
|
|
56
|
+
});
|
|
57
|
+
/** The body of an error answer. */
|
|
58
|
+
export const errorBody = z.object({
|
|
59
|
+
error: z.object({ code: z.string().optional(), message: z.string().optional() }),
|
|
60
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The input and output of `run`. */
|
|
3
|
+
export declare const run: {
|
|
4
|
+
input: z.ZodObject<{
|
|
5
|
+
goal: z.ZodString;
|
|
6
|
+
url: z.ZodURL;
|
|
7
|
+
output_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
8
|
+
timeout_seconds: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
output: z.ZodObject<{
|
|
11
|
+
run_id: z.ZodNullable<z.ZodString>;
|
|
12
|
+
result: z.ZodUnknown;
|
|
13
|
+
steps: z.ZodNumber;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
};
|
|
16
|
+
/** The input and output of `start_run`. */
|
|
17
|
+
export declare const startRun: {
|
|
18
|
+
input: z.ZodObject<{
|
|
19
|
+
goal: z.ZodString;
|
|
20
|
+
url: z.ZodURL;
|
|
21
|
+
output_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
|
+
timeout_seconds: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
output: z.ZodObject<{
|
|
25
|
+
run_id: z.ZodString;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
};
|
|
28
|
+
/** The input and output of `run_state`. */
|
|
29
|
+
export declare const runState: {
|
|
30
|
+
input: z.ZodObject<{
|
|
31
|
+
run_id: z.ZodString;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
output: z.ZodObject<{
|
|
34
|
+
run_id: z.ZodString;
|
|
35
|
+
status: z.ZodEnum<{
|
|
36
|
+
CANCELLED: "CANCELLED";
|
|
37
|
+
COMPLETED: "COMPLETED";
|
|
38
|
+
FAILED: "FAILED";
|
|
39
|
+
PENDING: "PENDING";
|
|
40
|
+
RUNNING: "RUNNING";
|
|
41
|
+
}>;
|
|
42
|
+
result: z.ZodUnknown;
|
|
43
|
+
error: z.ZodNullable<z.ZodObject<{
|
|
44
|
+
category: z.ZodString;
|
|
45
|
+
message: z.ZodString;
|
|
46
|
+
}, z.core.$strip>>;
|
|
47
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
48
|
+
id: z.ZodString;
|
|
49
|
+
status: z.ZodString;
|
|
50
|
+
action: z.ZodNullable<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
};
|
|
54
|
+
/** The input and output of `cancel_run`. */
|
|
55
|
+
export declare const cancelRun: {
|
|
56
|
+
input: z.ZodObject<{
|
|
57
|
+
run_id: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
output: z.ZodObject<{
|
|
60
|
+
run_id: z.ZodString;
|
|
61
|
+
status: z.ZodString;
|
|
62
|
+
cancelled: z.ZodBoolean;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
};
|
|
65
|
+
/** The input and output of `step_screenshot`. */
|
|
66
|
+
export declare const stepScreenshot: {
|
|
67
|
+
input: z.ZodObject<{
|
|
68
|
+
run_id: z.ZodString;
|
|
69
|
+
step_id: z.ZodString;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
output: z.ZodObject<{
|
|
72
|
+
url: z.ZodString;
|
|
73
|
+
bytes: z.ZodNumber;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
};
|
|
76
|
+
/** The input and output of `search`. */
|
|
77
|
+
export declare const search: {
|
|
78
|
+
input: z.ZodObject<{
|
|
79
|
+
query: z.ZodString;
|
|
80
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
output: z.ZodObject<{
|
|
83
|
+
results: z.ZodArray<z.ZodObject<{
|
|
84
|
+
title: z.ZodString;
|
|
85
|
+
url: z.ZodString;
|
|
86
|
+
snippet: z.ZodString;
|
|
87
|
+
site: z.ZodString;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
total: z.ZodNumber;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
};
|
|
92
|
+
/** The input and output of `fetch`. */
|
|
93
|
+
export declare const fetchPages: {
|
|
94
|
+
input: z.ZodObject<{
|
|
95
|
+
urls: z.ZodArray<z.ZodURL>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
output: z.ZodObject<{
|
|
98
|
+
pages: z.ZodArray<z.ZodObject<{
|
|
99
|
+
url: z.ZodString;
|
|
100
|
+
final_url: z.ZodNullable<z.ZodString>;
|
|
101
|
+
title: z.ZodNullable<z.ZodString>;
|
|
102
|
+
text: z.ZodNullable<z.ZodString>;
|
|
103
|
+
}, z.core.$strip>>;
|
|
104
|
+
errors: z.ZodArray<z.ZodObject<{
|
|
105
|
+
url: z.ZodString;
|
|
106
|
+
error: z.ZodString;
|
|
107
|
+
status: z.ZodNullable<z.ZodNumber>;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { runStatus } from "#schemas/tinyfish";
|
|
3
|
+
const runId = z.string().min(1);
|
|
4
|
+
const goal = z.object({
|
|
5
|
+
goal: z.string().min(1),
|
|
6
|
+
url: z.url({ protocol: /^https?$/ }),
|
|
7
|
+
output_schema: z.record(z.string(), z.unknown()).optional(),
|
|
8
|
+
timeout_seconds: z.number().int().positive().optional(),
|
|
9
|
+
});
|
|
10
|
+
/** The input and output of `run`. */
|
|
11
|
+
export const run = {
|
|
12
|
+
input: goal,
|
|
13
|
+
output: z.object({ run_id: z.string().nullable(), result: z.unknown(), steps: z.number().int() }),
|
|
14
|
+
};
|
|
15
|
+
/** The input and output of `start_run`. */
|
|
16
|
+
export const startRun = { input: goal, output: z.object({ run_id: z.string() }) };
|
|
17
|
+
/** The input and output of `run_state`. */
|
|
18
|
+
export const runState = {
|
|
19
|
+
input: z.object({ run_id: runId }),
|
|
20
|
+
output: z.object({
|
|
21
|
+
run_id: z.string(),
|
|
22
|
+
status: runStatus,
|
|
23
|
+
result: z.unknown(),
|
|
24
|
+
error: z.object({ category: z.string(), message: z.string() }).nullable(),
|
|
25
|
+
steps: z.array(z.object({ id: z.string(), status: z.string(), action: z.string().nullable() })),
|
|
26
|
+
}),
|
|
27
|
+
};
|
|
28
|
+
/** The input and output of `cancel_run`. */
|
|
29
|
+
export const cancelRun = {
|
|
30
|
+
input: z.object({ run_id: runId }),
|
|
31
|
+
output: z.object({ run_id: z.string(), status: z.string(), cancelled: z.boolean() }),
|
|
32
|
+
};
|
|
33
|
+
/** The input and output of `step_screenshot`. */
|
|
34
|
+
export const stepScreenshot = {
|
|
35
|
+
input: z.object({ run_id: runId, step_id: z.string().min(1) }),
|
|
36
|
+
output: z.object({ url: z.string(), bytes: z.number().int() }),
|
|
37
|
+
};
|
|
38
|
+
/** The input and output of `search`. */
|
|
39
|
+
export const search = {
|
|
40
|
+
input: z.object({
|
|
41
|
+
query: z.string().min(1),
|
|
42
|
+
count: z.number().int().min(1).max(10).optional(),
|
|
43
|
+
}),
|
|
44
|
+
output: z.object({
|
|
45
|
+
results: z.array(z.object({ title: z.string(), url: z.string(), snippet: z.string(), site: z.string() })),
|
|
46
|
+
total: z.number().int(),
|
|
47
|
+
}),
|
|
48
|
+
};
|
|
49
|
+
/** The input and output of `fetch`. */
|
|
50
|
+
export const fetchPages = {
|
|
51
|
+
input: z.object({
|
|
52
|
+
urls: z
|
|
53
|
+
.array(z.url({ protocol: /^https?$/ }))
|
|
54
|
+
.min(1)
|
|
55
|
+
.max(10),
|
|
56
|
+
}),
|
|
57
|
+
output: z.object({
|
|
58
|
+
pages: z.array(z.object({
|
|
59
|
+
url: z.string(),
|
|
60
|
+
final_url: z.string().nullable(),
|
|
61
|
+
title: z.string().nullable(),
|
|
62
|
+
text: z.string().nullable(),
|
|
63
|
+
})),
|
|
64
|
+
errors: z.array(z.object({ url: z.string(), error: z.string(), status: z.number().nullable() })),
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import { type Reply } from "#api/client";
|
|
3
|
+
import { run } from "#schemas/tools";
|
|
4
|
+
/** The request body of a run: the goal, the start URL, the time limit and the captures from `[extensions.tinyfish]`. */
|
|
5
|
+
export declare function runBody(input: z.infer<typeof run.input>, settings: unknown): Reply<Readonly<Record<string, unknown>>>;
|
|
6
|
+
/** The web agent tools of the TinyFish extension, by the name the manifest gives them. */
|
|
7
|
+
export declare const agentTools: {
|
|
8
|
+
run: import("@kana-ai/edgar-sdk").Tool<{
|
|
9
|
+
goal: string;
|
|
10
|
+
url: string;
|
|
11
|
+
output_schema?: Record<string, unknown> | undefined;
|
|
12
|
+
timeout_seconds?: number | undefined;
|
|
13
|
+
}, {
|
|
14
|
+
run_id: string | null;
|
|
15
|
+
result: unknown;
|
|
16
|
+
steps: number;
|
|
17
|
+
}, "TINYFISH_API_KEY">;
|
|
18
|
+
start_run: import("@kana-ai/edgar-sdk").Tool<{
|
|
19
|
+
goal: string;
|
|
20
|
+
url: string;
|
|
21
|
+
output_schema?: Record<string, unknown> | undefined;
|
|
22
|
+
timeout_seconds?: number | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
run_id: string;
|
|
25
|
+
}, "TINYFISH_API_KEY">;
|
|
26
|
+
run_state: import("@kana-ai/edgar-sdk").Tool<{
|
|
27
|
+
run_id: string;
|
|
28
|
+
}, {
|
|
29
|
+
run_id: string;
|
|
30
|
+
status: "CANCELLED" | "COMPLETED" | "FAILED" | "PENDING" | "RUNNING";
|
|
31
|
+
result: unknown;
|
|
32
|
+
error: {
|
|
33
|
+
category: string;
|
|
34
|
+
message: string;
|
|
35
|
+
} | null;
|
|
36
|
+
steps: {
|
|
37
|
+
id: string;
|
|
38
|
+
status: string;
|
|
39
|
+
action: string | null;
|
|
40
|
+
}[];
|
|
41
|
+
}, "TINYFISH_API_KEY">;
|
|
42
|
+
cancel_run: import("@kana-ai/edgar-sdk").Tool<{
|
|
43
|
+
run_id: string;
|
|
44
|
+
}, {
|
|
45
|
+
run_id: string;
|
|
46
|
+
status: string;
|
|
47
|
+
cancelled: boolean;
|
|
48
|
+
}, "TINYFISH_API_KEY">;
|
|
49
|
+
step_screenshot: import("@kana-ai/edgar-sdk").Tool<{
|
|
50
|
+
run_id: string;
|
|
51
|
+
step_id: string;
|
|
52
|
+
}, {
|
|
53
|
+
url: string;
|
|
54
|
+
bytes: number;
|
|
55
|
+
}, "TINYFISH_API_KEY">;
|
|
56
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { defineTool, done, failure, permanentFailure } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { HOSTS, access, send, tinyfish } from "#api/client";
|
|
3
|
+
import { runFailure, startFailure } from "#api/failures";
|
|
4
|
+
import { config } from "#schemas/config";
|
|
5
|
+
import { cancelledRun, runDetail, startedRun, syncRun } from "#schemas/tinyfish";
|
|
6
|
+
import { cancelRun, run, runState, startRun, stepScreenshot } from "#schemas/tools";
|
|
7
|
+
const runAccess = access("agent");
|
|
8
|
+
const sideEffect = {
|
|
9
|
+
side_effect: true,
|
|
10
|
+
undo: "none",
|
|
11
|
+
undo_reason: "a web agent acts on outside websites, and its steps cannot be taken back; cancel_run only stops a started run",
|
|
12
|
+
};
|
|
13
|
+
/** The request body of a run: the goal, the start URL, the time limit and the captures from `[extensions.tinyfish]`. */
|
|
14
|
+
export function runBody(input, settings) {
|
|
15
|
+
const parsed = config.safeParse(settings ?? {});
|
|
16
|
+
if (!parsed.success) {
|
|
17
|
+
return {
|
|
18
|
+
ok: false,
|
|
19
|
+
error: permanentFailure("invalid", "the [extensions.tinyfish] table does not match its schema"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
ok: true,
|
|
24
|
+
value: {
|
|
25
|
+
url: input.url,
|
|
26
|
+
goal: input.goal,
|
|
27
|
+
api_integration: "edgar",
|
|
28
|
+
agent_config: {
|
|
29
|
+
max_duration_seconds: input.timeout_seconds ?? parsed.data.timeout_seconds,
|
|
30
|
+
},
|
|
31
|
+
capture_config: { screenshots: parsed.data.capture_screenshots },
|
|
32
|
+
...(input.output_schema === undefined ? {} : { output_schema: input.output_schema }),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function runPath(id, tail = "") {
|
|
37
|
+
return `/v1/runs/${encodeURIComponent(id)}${tail}`;
|
|
38
|
+
}
|
|
39
|
+
/** The web agent tools of the TinyFish extension, by the name the manifest gives them. */
|
|
40
|
+
export const agentTools = {
|
|
41
|
+
run: defineTool({
|
|
42
|
+
description: "Run a web agent on a goal from a start URL and wait for its result; for runs under about a minute",
|
|
43
|
+
input: run.input,
|
|
44
|
+
output: run.output,
|
|
45
|
+
...runAccess,
|
|
46
|
+
...sideEffect,
|
|
47
|
+
execute: async (input, ctx) => {
|
|
48
|
+
const body = runBody(input, ctx.config);
|
|
49
|
+
if (!body.ok)
|
|
50
|
+
return body.error;
|
|
51
|
+
const ended = await tinyfish(ctx, "agent", "POST", "/v1/automation/run", syncRun, body.value);
|
|
52
|
+
if (!ended.ok)
|
|
53
|
+
return ended.error;
|
|
54
|
+
const { run_id, status, result, error, num_of_steps } = ended.value;
|
|
55
|
+
if (status !== "COMPLETED") {
|
|
56
|
+
return runFailure(status, error, `tinyfish run ${run_id ?? "without an id"}`);
|
|
57
|
+
}
|
|
58
|
+
return done({ run_id, result, steps: num_of_steps ?? 0 });
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
start_run: defineTool({
|
|
62
|
+
description: "Start a web agent run on a goal from a start URL and return its run id at once",
|
|
63
|
+
input: startRun.input,
|
|
64
|
+
output: startRun.output,
|
|
65
|
+
...runAccess,
|
|
66
|
+
...sideEffect,
|
|
67
|
+
execute: async (input, ctx) => {
|
|
68
|
+
const body = runBody(input, ctx.config);
|
|
69
|
+
if (!body.ok)
|
|
70
|
+
return body.error;
|
|
71
|
+
const started = await tinyfish(ctx, "agent", "POST", "/v1/automation/run-async", startedRun, body.value);
|
|
72
|
+
if (!started.ok)
|
|
73
|
+
return started.error;
|
|
74
|
+
const { run_id, error } = started.value;
|
|
75
|
+
if (run_id === null)
|
|
76
|
+
return startFailure(error, "tinyfish start_run");
|
|
77
|
+
return done({ run_id });
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
run_state: defineTool({
|
|
81
|
+
description: "Read the status, the result and the steps of a web agent run",
|
|
82
|
+
input: runState.input,
|
|
83
|
+
output: runState.output,
|
|
84
|
+
...runAccess,
|
|
85
|
+
execute: async ({ run_id }, ctx) => {
|
|
86
|
+
const read = await tinyfish(ctx, "agent", "GET", runPath(run_id, "?screenshots=none&html=none"), runDetail);
|
|
87
|
+
if (!read.ok)
|
|
88
|
+
return read.error;
|
|
89
|
+
const r = read.value;
|
|
90
|
+
return done({
|
|
91
|
+
run_id: r.run_id,
|
|
92
|
+
status: r.status,
|
|
93
|
+
result: r.result,
|
|
94
|
+
error: r.error === null ? null : { category: r.error.category, message: r.error.message },
|
|
95
|
+
steps: r.steps,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
}),
|
|
99
|
+
cancel_run: defineTool({
|
|
100
|
+
description: "Stop a started web agent run; a run that already ended keeps its status",
|
|
101
|
+
input: cancelRun.input,
|
|
102
|
+
output: cancelRun.output,
|
|
103
|
+
...runAccess,
|
|
104
|
+
execute: async ({ run_id }, ctx) => {
|
|
105
|
+
const cancelled = await tinyfish(ctx, "agent", "POST", runPath(run_id, "/cancel"), cancelledRun);
|
|
106
|
+
if (!cancelled.ok)
|
|
107
|
+
return cancelled.error;
|
|
108
|
+
const { status } = cancelled.value;
|
|
109
|
+
return done({ run_id: cancelled.value.run_id, status, cancelled: status === "CANCELLED" });
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
step_screenshot: defineTool({
|
|
113
|
+
description: "Check that one step of a run has a screenshot and return its URL, which needs the TinyFish key to open",
|
|
114
|
+
input: stepScreenshot.input,
|
|
115
|
+
output: stepScreenshot.output,
|
|
116
|
+
...runAccess,
|
|
117
|
+
execute: async ({ run_id, step_id }, ctx) => {
|
|
118
|
+
const path = runPath(run_id, `/steps/${encodeURIComponent(step_id)}/screenshot`);
|
|
119
|
+
const image = await send(ctx, "agent", "GET", path);
|
|
120
|
+
if (!image.ok)
|
|
121
|
+
return image.error;
|
|
122
|
+
const bytes = await image.value.arrayBuffer().then((data) => data.byteLength, () => undefined);
|
|
123
|
+
if (bytes === undefined) {
|
|
124
|
+
return failure("provider_unavailable", `tinyfish GET ${HOSTS.agent}${path}: the image broke off`);
|
|
125
|
+
}
|
|
126
|
+
return done({ url: `https://${HOSTS.agent}${path}`, bytes });
|
|
127
|
+
},
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** The search and fetch tools of the TinyFish extension, by the name the manifest gives them. */
|
|
2
|
+
export declare const webTools: {
|
|
3
|
+
search: import("@kana-ai/edgar-sdk").Tool<{
|
|
4
|
+
query: string;
|
|
5
|
+
count?: number | undefined;
|
|
6
|
+
}, {
|
|
7
|
+
results: {
|
|
8
|
+
title: string;
|
|
9
|
+
url: string;
|
|
10
|
+
snippet: string;
|
|
11
|
+
site: string;
|
|
12
|
+
}[];
|
|
13
|
+
total: number;
|
|
14
|
+
}, "TINYFISH_API_KEY">;
|
|
15
|
+
fetch: import("@kana-ai/edgar-sdk").Tool<{
|
|
16
|
+
urls: string[];
|
|
17
|
+
}, {
|
|
18
|
+
pages: {
|
|
19
|
+
url: string;
|
|
20
|
+
final_url: string | null;
|
|
21
|
+
title: string | null;
|
|
22
|
+
text: string | null;
|
|
23
|
+
}[];
|
|
24
|
+
errors: {
|
|
25
|
+
url: string;
|
|
26
|
+
error: string;
|
|
27
|
+
status: number | null;
|
|
28
|
+
}[];
|
|
29
|
+
}, "TINYFISH_API_KEY">;
|
|
30
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineTool, done } from "@kana-ai/edgar-sdk";
|
|
2
|
+
import { access, tinyfish } from "#api/client";
|
|
3
|
+
import { fetchAnswer, searchAnswer } from "#schemas/tinyfish";
|
|
4
|
+
import { fetchPages, search } from "#schemas/tools";
|
|
5
|
+
/** The search and fetch tools of the TinyFish extension, by the name the manifest gives them. */
|
|
6
|
+
export const webTools = {
|
|
7
|
+
search: defineTool({
|
|
8
|
+
description: "Search the web and return the first results with their title, URL and snippet",
|
|
9
|
+
input: search.input,
|
|
10
|
+
output: search.output,
|
|
11
|
+
...access("search"),
|
|
12
|
+
execute: async ({ query, count }, ctx) => {
|
|
13
|
+
const found = await tinyfish(ctx, "search", "GET", `/?${new URLSearchParams({ query }).toString()}`, searchAnswer);
|
|
14
|
+
if (!found.ok)
|
|
15
|
+
return found.error;
|
|
16
|
+
return done({
|
|
17
|
+
results: found.value.results
|
|
18
|
+
.slice(0, count ?? 10)
|
|
19
|
+
.map((r) => ({ title: r.title, url: r.url, snippet: r.snippet, site: r.site_name })),
|
|
20
|
+
total: found.value.total_results,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
fetch: defineTool({
|
|
25
|
+
description: "Fetch up to 10 URLs as Markdown; a URL that fails is listed in errors",
|
|
26
|
+
input: fetchPages.input,
|
|
27
|
+
output: fetchPages.output,
|
|
28
|
+
...access("fetch"),
|
|
29
|
+
execute: async ({ urls }, ctx) => {
|
|
30
|
+
const fetched = await tinyfish(ctx, "fetch", "POST", "/", fetchAnswer, {
|
|
31
|
+
urls,
|
|
32
|
+
format: "markdown",
|
|
33
|
+
});
|
|
34
|
+
if (!fetched.ok)
|
|
35
|
+
return fetched.error;
|
|
36
|
+
return done({
|
|
37
|
+
pages: fetched.value.results.map((p) => ({
|
|
38
|
+
url: p.url,
|
|
39
|
+
final_url: p.final_url,
|
|
40
|
+
title: p.title,
|
|
41
|
+
text: p.text,
|
|
42
|
+
})),
|
|
43
|
+
errors: fetched.value.errors.map((e) => ({
|
|
44
|
+
url: e.url,
|
|
45
|
+
error: e.error,
|
|
46
|
+
status: e.status ?? null,
|
|
47
|
+
})),
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
};
|