@kana-ai/edgar-ext-tinyfish 0.0.0-stage → 0.1.0

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 ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Kana.ai
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md CHANGED
@@ -1,3 +1,107 @@
1
- # Temporary Holding Version
1
+ # @kana-ai/edgar-ext-tinyfish
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The TinyFish extension of EDGAR. It runs a TinyFish web agent on a goal in plain words, searches the web and fetches pages. A stage calls its tools as `tinyfish__<tool>`. The extension is opt-in: `edgar init` does not turn it on, because it needs a key.
4
+
5
+ ## Tools
6
+
7
+ | Tool | Input | Output | Endpoint |
8
+ | ----------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------- |
9
+ | `run` | `goal`, `url`, optional `output_schema`, `timeout_seconds` | `run_id`, `result`, `steps` | `POST agent.tinyfish.ai/v1/automation/run` |
10
+ | `start_run` | the same as `run` | `run_id` | `POST /v1/automation/run-async` |
11
+ | `run_state` | `run_id` | `run_id`, `status`, `result`, `error`, `steps` | `GET /v1/runs/{id}` |
12
+ | `cancel_run` | `run_id` | `run_id`, `status`, `cancelled` | `POST /v1/runs/{id}/cancel` |
13
+ | `step_screenshot` | `run_id`, `step_id` | `url`, `bytes` | `GET /v1/runs/{id}/steps/{step}/screenshot` |
14
+ | `search` | `query`, optional `count` from 1 to 10 | `results`: `title`, `url`, `snippet`, `site`; `total` | `GET api.search.tinyfish.ai/?query=` |
15
+ | `fetch` | `urls`: 1 to 10 URLs | `pages`: `url`, `final_url`, `title`, `text`; `errors`: `url`, `error`, `status` | `POST api.fetch.tinyfish.ai/` |
16
+
17
+ - `run` waits for the end of the run. Use it for a goal that takes less than about a minute. A run that ends `FAILED` returns a failure (see [Errors](#errors)).
18
+ - `timeout_seconds` sets TinyFish's `max_duration_seconds`. When the limit comes, the agent takes one more step to write up what it has, and then ends the run `COMPLETED` with partial data.
19
+ - If the stage's own `timeout_seconds` comes first, the engine ends the call. The TinyFish run continues to its own limit and costs money, because TinyFish cannot cancel a run that `run` started. For a long goal, use `start_run`, then `run_state` in a wait, and `cancel_run` when you stop.
20
+ - `run`, `start_run` and `step_screenshot` read and act on outside websites. `run` and `start_run` are side effects with no undo: `cancel_run` stops a run, but it does not take back its steps.
21
+ - `run_state` gets the run without its screenshots and HTML. Each step has `id`, `status` and `action`. Just after `cancel_run`, `run_state` can show `RUNNING` for some seconds.
22
+ - `step_screenshot` downloads the JPEG of one step to make sure that it exists, and returns its size and its API URL. The URL needs the TinyFish key in `X-API-Key` to open. A tool output carries JSON only, so the image itself does not travel.
23
+ - `search` reads one page of results and keeps the first `count`. In the smoke test, one page had 5 results.
24
+ - `fetch` asks for Markdown. A URL that fails is in `errors` with TinyFish's reason, such as `page_not_found`, and the call still ends `done`.
25
+
26
+ ## Configuration
27
+
28
+ ```toml
29
+ [extensions.tinyfish]
30
+ timeout_seconds = 300 # the default max_duration_seconds of a run; a tool input can set its own
31
+ capture_screenshots = true # capture a screenshot at each step, for step_screenshot
32
+ ```
33
+
34
+ A stage that reads the docs page of a failing dependency. The `investigate` stage before it writes `docs_goal` and `docs_url` in its output:
35
+
36
+ ```toml
37
+ [stages.read_docs]
38
+ needs = ["investigate"]
39
+ tool = "tinyfish__run"
40
+ input = { goal = "stages.investigate.output.docs_goal", url = "stages.investigate.output.docs_url" }
41
+ ```
42
+
43
+ ## Secrets
44
+
45
+ - `TINYFISH_API_KEY`: a key from [agent.tinyfish.ai/api-keys](https://agent.tinyfish.ai/api-keys). It goes in the `X-API-Key` header, and it reaches only `agent.tinyfish.ai`, `api.search.tinyfish.ai` and `api.fetch.tinyfish.ai`. Each tool has the capability of the one host it calls.
46
+
47
+ ## Errors
48
+
49
+ One table in `src/api/failures.ts` maps each answer to an outcome. `cause` holds the HTTP status, TinyFish's `error.code` and its `message`. Each failure text has the key removed.
50
+
51
+ | Answer | Outcome |
52
+ | --------------------------------------------------------------------- | -------------------------------------------------------- |
53
+ | 400 `INVALID_INPUT`, 422 | `invalid` |
54
+ | 401 `MISSING_API_KEY`, `INVALID_API_KEY` | `unauthenticated` |
55
+ | 402, or the code `INSUFFICIENT_CREDITS` or `FREE_ALLOWANCE_EXHAUSTED` | `forbidden`, with the reason and the wallet URL |
56
+ | 403 `FORBIDDEN` | `forbidden` |
57
+ | 404 `NOT_FOUND` | `not_found` |
58
+ | 429 `RATE_LIMIT_EXCEEDED` | `rate_limited`; waits for `Retry-After`, else one minute |
59
+ | 5xx and network errors | `provider_unavailable` |
60
+ | Any other status | `tool_error` |
61
+
62
+ A run that ends `FAILED` maps by `error.category`: `SYSTEM_FAILURE` and `UNKNOWN` to `provider_unavailable`, after `retry_after` when TinyFish sets it; `AGENT_FAILURE` to `tool_error`; `BILLING_FAILURE` to `forbidden`.
63
+
64
+ ## Limits
65
+
66
+ TinyFish sends no limit headers, so a failure reads `Retry-After` only, with the SDK's `retry_after` scheme, for the source of the host the tool called (`agent.tinyfish.ai`, `api.search.tinyfish.ai` or `api.fetch.tinyfish.ai`). The wallet codes also give a used-up limit: `FREE_ALLOWANCE_EXHAUSTED` has the window `free_allowance` and resets at the next 00:00 UTC; `INSUFFICIENT_CREDITS` has the window `wallet` and no reset, because only a top-up ends it, so it never holds a stage. The operator sees the source on the console's Limits page and on `GET /api/limits`.
67
+
68
+ ## Build and test
69
+
70
+ ```sh
71
+ pnpm build # writes edgar-extension.json and schemas/
72
+ pnpm test # unit tests with a mock TinyFish, no network
73
+ ```
74
+
75
+ The tests replay answers recorded from the real API, with no key in them. `edgar-extension.json` and `schemas/` are committed: a change to them in a diff is a change to what a person approves.
76
+
77
+ ## Validation
78
+
79
+ These commands ran on 2026-11-10, from the repository root unless a step says otherwise.
80
+
81
+ | Command | Exit | Result |
82
+ | ----------------------------------------------------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------- |
83
+ | `pnpm install` | 0 | The lockfile lists `@kana-ai/edgar-ext-tinyfish`. |
84
+ | `pnpm -C packages/extensions/ext-tinyfish build` | 0 | Wrote `edgar-extension.json` and 15 schema files. |
85
+ | `pnpm -C packages/extensions/ext-tinyfish check-types` | 0 | |
86
+ | `pnpm -C packages/extensions/ext-tinyfish lint` | 0 | 0 warnings, 0 errors. |
87
+ | `pnpm -C packages/extensions/ext-tinyfish format:check` | 0 | |
88
+ | `pnpm -C packages/extensions/ext-tinyfish test` | 0 | 59 tests, 0 failures. Each test failed once with its behavior removed. |
89
+ | `set -a; . ~/.edgar-secrets/tinyfish.env; set +a`, then one call of each tool's `execute` | 0 | All 7 tools `done` against the real API; 401, 404 and 400 answers recorded for the tests. |
90
+ | `edgar extensions approve demo tinyfish --project <scratch project>` | 0 | |
91
+ | `edgar check --project <scratch project>` | 0 | 0 errors. |
92
+ | `edgar start --project <scratch project>`, stopped with SIGINT | 0 | A card started a workflow whose one stage called `tinyfish__search` through the runtime; the run ended `done`. |
93
+
94
+ ## Not in this version
95
+
96
+ - Browser sessions: a remote browser over CDP needs a client that EDGAR does not run in a tool.
97
+ - Batch runs: `run-batch` starts many runs; a workflow can use `for_each` over `start_run`.
98
+ - Streamed runs: `run-sse` is for a live view, and a tool returns only once.
99
+ - Datasets: TinySet fills tables from the web, which no on-call stage needs yet.
100
+ - Monitors: a page or topic watch on a schedule overlaps EDGAR's own schedule triggers.
101
+ - Vault and Browser Context Profiles: signed-in runs need credentials outside EDGAR's secrets.
102
+ - Wallet: reading and topping up the balance is for a person, not a stage.
103
+
104
+ ## Shortcuts
105
+
106
+ - shortcut: the hosts are fixed, so a self-hosted or test endpoint is not configurable; the network policy refuses any host outside the manifest. Upgrade when the engine can take a host from the project's config.
107
+ - shortcut: `search` reads the first page only. Upgrade to the `page` parameter when a stage needs more than one page.
@@ -0,0 +1,27 @@
1
+ import { type Ctx, type Failure, type Result } from "@kana-ai/edgar-sdk";
2
+ import type { z } from "zod";
3
+ /** The secret every TinyFish call sends, as `X-API-Key`. */
4
+ export declare const KEY = "TINYFISH_API_KEY";
5
+ /** The host of each TinyFish API the tools call. */
6
+ export declare const HOSTS: {
7
+ readonly agent: "agent.tinyfish.ai";
8
+ readonly search: "api.search.tinyfish.ai";
9
+ readonly fetch: "api.fetch.tinyfish.ai";
10
+ };
11
+ /** One of the TinyFish APIs. */
12
+ export type Api = keyof typeof HOSTS;
13
+ /** The secret and the one capability of a tool that calls `api`. */
14
+ export declare function access<A extends Api>(api: A): {
15
+ readonly secrets: readonly ["TINYFISH_API_KEY"];
16
+ readonly capabilities: readonly [`network:${{
17
+ readonly agent: "agent.tinyfish.ai";
18
+ readonly search: "api.search.tinyfish.ai";
19
+ readonly fetch: "api.fetch.tinyfish.ai";
20
+ }[A]}`];
21
+ };
22
+ /** The answer of one TinyFish call: the value, or the failure it maps to. */
23
+ export type Reply<T> = Result<T, Failure>;
24
+ /** Sends one request to `api` with the call's key; an answer that is not 2xx maps to a failure with the key removed. */
25
+ export declare function send(ctx: Ctx<typeof KEY>, api: Api, method: "GET" | "POST", path: string, body?: Readonly<Record<string, unknown>>): Promise<Reply<Response>>;
26
+ /** Sends one request to `api` and parses the JSON answer with `schema`. */
27
+ export declare function tinyfish<T>(ctx: Ctx<typeof KEY>, api: Api, method: "GET" | "POST", path: string, schema: z.ZodType<T>, body?: Readonly<Record<string, unknown>>): Promise<Reply<T>>;
@@ -0,0 +1,53 @@
1
+ import { attemptAsync, err, failure, fetchFailure, ok, unwrapOr, } from "@kana-ai/edgar-sdk";
2
+ import { mapFailure, redact } from "#api/failures";
3
+ /** The secret every TinyFish call sends, as `X-API-Key`. */
4
+ export const KEY = "TINYFISH_API_KEY";
5
+ /** The host of each TinyFish API the tools call. */
6
+ export const HOSTS = {
7
+ agent: "agent.tinyfish.ai",
8
+ search: "api.search.tinyfish.ai",
9
+ fetch: "api.fetch.tinyfish.ai",
10
+ };
11
+ /** The secret and the one capability of a tool that calls `api`. */
12
+ export function access(api) {
13
+ return { secrets: [KEY], capabilities: [`network:${HOSTS[api]}`] };
14
+ }
15
+ /** The JSON body of an answer, or `null` when it is not JSON. */
16
+ async function bodyOf(response) {
17
+ return unwrapOr(await attemptAsync(async () => await response.json(), () => null), null);
18
+ }
19
+ /** Sends one request to `api` with the call's key; an answer that is not 2xx maps to a failure with the key removed. */
20
+ export async function send(ctx, api, method, path, body) {
21
+ const key = ctx.secrets.get(KEY);
22
+ const context = `tinyfish ${method} ${HOSTS[api]}${path.split("?")[0] ?? ""}`;
23
+ const sent = await attemptAsync(async () => await fetch(`https://${HOSTS[api]}${path}`, {
24
+ method,
25
+ signal: ctx.signal,
26
+ headers: {
27
+ "x-api-key": key,
28
+ "user-agent": "edgar",
29
+ ...(body === undefined ? {} : { "content-type": "application/json" }),
30
+ },
31
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
32
+ }), (caught) => redact(fetchFailure(caught, ctx.signal, context), key));
33
+ if (!sent.ok)
34
+ return sent;
35
+ const response = sent.value;
36
+ if (response.ok)
37
+ return sent;
38
+ const json = await bodyOf(response);
39
+ return err(redact(mapFailure(response.status, response.headers, json, context, HOSTS[api]), key));
40
+ }
41
+ /** Sends one request to `api` and parses the JSON answer with `schema`. */
42
+ export async function tinyfish(ctx, api, method, path, schema, body) {
43
+ const sent = await send(ctx, api, method, path, body);
44
+ if (!sent.ok)
45
+ return sent;
46
+ const parsed = schema.safeParse(await bodyOf(sent.value));
47
+ if (parsed.success)
48
+ return ok(parsed.data);
49
+ const fields = parsed.error.issues.map((issue) => issue.path.join(".")).join(", ");
50
+ return err(failure("tool_error", `tinyfish ${method} ${HOSTS[api]}: unexpected answer`, {
51
+ cause: `fields: ${fields}`,
52
+ }));
53
+ }
@@ -0,0 +1,14 @@
1
+ import { type Failure } from "@kana-ai/edgar-sdk";
2
+ import type { z } from "zod";
3
+ import { type runError } from "#schemas/tinyfish";
4
+ /** Maps a TinyFish error answer of the API at `source` to a failure; `cause` holds the status, TinyFish's `code` and `message`. A rate limit reads `Retry-After`, and a wallet code carries its limit. */
5
+ export declare function mapFailure(status: number, headers: Headers, body: unknown, context: string, source: string, now?: number): Failure;
6
+ /** Maps a run that ended without its result to a failure, by `error.category`; a system failure waits for `retry_after`. */
7
+ export declare function runFailure(status: string, error: z.infer<typeof runError> | null, context: string): Failure;
8
+ /** The failure of a start that TinyFish refused with a `200` and no run id. */
9
+ export declare function startFailure(error: {
10
+ readonly code?: string | undefined;
11
+ readonly message: string;
12
+ } | null | undefined, context: string): Failure;
13
+ /** `failure` with every copy of `secret` removed from its message and cause. */
14
+ export declare function redact(value: Failure, secret: string): Failure;
@@ -0,0 +1,87 @@
1
+ import { failure, vendorFailure, } from "@kana-ai/edgar-sdk";
2
+ import { errorBody } from "#schemas/tinyfish";
3
+ const statusKinds = new Map([
4
+ [400, "invalid"],
5
+ [401, "unauthenticated"],
6
+ [402, "forbidden"],
7
+ [403, "forbidden"],
8
+ [404, "not_found"],
9
+ [422, "invalid"],
10
+ [429, "rate_limited"],
11
+ ]);
12
+ const walletReasons = new Map([
13
+ [
14
+ "INSUFFICIENT_CREDITS",
15
+ "the TinyFish wallet has no money left; add money at https://agent.tinyfish.ai/wallet",
16
+ ],
17
+ ["FREE_ALLOWANCE_EXHAUSTED", "the daily free allowance is used; it resets at 00:00 UTC"],
18
+ ["BILLING_REJECTED", "the billing check refused the run; add money to the TinyFish wallet"],
19
+ ]);
20
+ const categoryKinds = new Map([
21
+ ["SYSTEM_FAILURE", "provider_unavailable"],
22
+ ["UNKNOWN", "provider_unavailable"],
23
+ ["AGENT_FAILURE", "tool_error"],
24
+ ["BILLING_FAILURE", "forbidden"],
25
+ ]);
26
+ /** The wallet limit a code names: the free allowance is used up until the next 00:00 UTC, an empty wallet until a person adds money, so it has no reset. */
27
+ function walletLimit(code, source, now) {
28
+ if (code === "FREE_ALLOWANCE_EXHAUSTED") {
29
+ const midnight = new Date(now);
30
+ midnight.setUTCHours(24, 0, 0, 0);
31
+ return { source, remaining: 0, resets_at: midnight.getTime(), window: "free_allowance" };
32
+ }
33
+ if (code === "INSUFFICIENT_CREDITS")
34
+ return { source, remaining: 0, window: "wallet" };
35
+ return undefined;
36
+ }
37
+ function causeOf(head, message) {
38
+ return message === undefined || message === "" ? head : `${head}: ${message}`;
39
+ }
40
+ /** Maps a TinyFish error answer of the API at `source` to a failure; `cause` holds the status, TinyFish's `code` and `message`. A rate limit reads `Retry-After`, and a wallet code carries its limit. */
41
+ export function mapFailure(status, headers, body, context, source, now = Date.now()) {
42
+ const vendor = errorBody.safeParse(body);
43
+ const error = vendor.success ? vendor.data.error : undefined;
44
+ const code = error?.code ?? "";
45
+ const cause = causeOf(`${String(status)} ${code}`.trim(), error?.message);
46
+ const wallet = walletReasons.get(code);
47
+ if (wallet !== undefined || status === 402) {
48
+ const limit = walletLimit(code, source, now);
49
+ return failure("forbidden", `${context}: ${wallet ?? "payment required"}`, {
50
+ cause,
51
+ ...(limit === undefined ? {} : { limit }),
52
+ });
53
+ }
54
+ const kind = status >= 500 ? "provider_unavailable" : (statusKinds.get(status) ?? "tool_error");
55
+ return vendorFailure(kind, context, cause, headers, { scheme: "retry_after", source }, now);
56
+ }
57
+ /** Maps a run that ended without its result to a failure, by `error.category`; a system failure waits for `retry_after`. */
58
+ export function runFailure(status, error, context) {
59
+ if (error === null)
60
+ return failure("tool_error", `${context}: the run ended ${status}`);
61
+ const code = error.code ?? error.category;
62
+ const kind = categoryKinds.get(error.category) ?? "tool_error";
63
+ const reason = walletReasons.get(code) ?? `the run ended ${status}`;
64
+ return failure(kind, `${context}: ${reason}`, {
65
+ cause: causeOf(code, error.message),
66
+ ...(typeof error.retry_after === "number" ? { retryAfterSeconds: error.retry_after } : {}),
67
+ });
68
+ }
69
+ /** The failure of a start that TinyFish refused with a `200` and no run id. */
70
+ export function startFailure(error, context) {
71
+ const code = error?.code ?? "";
72
+ const wallet = walletReasons.get(code);
73
+ return failure(wallet === undefined ? "tool_error" : "forbidden", `${context}: ${wallet ?? "no run id"}`, {
74
+ cause: causeOf(code === "" ? "200" : code, error?.message),
75
+ });
76
+ }
77
+ /** `failure` with every copy of `secret` removed from its message and cause. */
78
+ export function redact(value, secret) {
79
+ if (secret === "")
80
+ return value;
81
+ const clean = (text) => text.replaceAll(secret, "[redacted]");
82
+ return {
83
+ ...value,
84
+ message: clean(value.message),
85
+ ...(value.cause === undefined ? {} : { cause: clean(value.cause) }),
86
+ };
87
+ }
@@ -0,0 +1,81 @@
1
+ /** Every tool of the TinyFish extension, by the name the manifest gives it. */
2
+ export declare const tools: {
3
+ run: import("@kana-ai/edgar-sdk").Tool<{
4
+ goal: string;
5
+ url: string;
6
+ output_schema?: Record<string, unknown> | undefined;
7
+ timeout_seconds?: number | undefined;
8
+ }, {
9
+ run_id: string | null;
10
+ result: unknown;
11
+ steps: number;
12
+ }, "TINYFISH_API_KEY">;
13
+ start_run: import("@kana-ai/edgar-sdk").Tool<{
14
+ goal: string;
15
+ url: string;
16
+ output_schema?: Record<string, unknown> | undefined;
17
+ timeout_seconds?: number | undefined;
18
+ }, {
19
+ run_id: string;
20
+ }, "TINYFISH_API_KEY">;
21
+ run_state: import("@kana-ai/edgar-sdk").Tool<{
22
+ run_id: string;
23
+ }, {
24
+ run_id: string;
25
+ status: "CANCELLED" | "COMPLETED" | "FAILED" | "PENDING" | "RUNNING";
26
+ result: unknown;
27
+ error: {
28
+ category: string;
29
+ message: string;
30
+ } | null;
31
+ steps: {
32
+ id: string;
33
+ status: string;
34
+ action: string | null;
35
+ }[];
36
+ }, "TINYFISH_API_KEY">;
37
+ cancel_run: import("@kana-ai/edgar-sdk").Tool<{
38
+ run_id: string;
39
+ }, {
40
+ run_id: string;
41
+ status: string;
42
+ cancelled: boolean;
43
+ }, "TINYFISH_API_KEY">;
44
+ step_screenshot: import("@kana-ai/edgar-sdk").Tool<{
45
+ run_id: string;
46
+ step_id: string;
47
+ }, {
48
+ url: string;
49
+ bytes: number;
50
+ }, "TINYFISH_API_KEY">;
51
+ search: import("@kana-ai/edgar-sdk").Tool<{
52
+ query: string;
53
+ count?: number | undefined;
54
+ }, {
55
+ results: {
56
+ title: string;
57
+ url: string;
58
+ snippet: string;
59
+ site: string;
60
+ }[];
61
+ total: number;
62
+ }, "TINYFISH_API_KEY">;
63
+ fetch: import("@kana-ai/edgar-sdk").Tool<{
64
+ urls: string[];
65
+ }, {
66
+ pages: {
67
+ url: string;
68
+ final_url: string | null;
69
+ title: string | null;
70
+ text: string | null;
71
+ }[];
72
+ errors: {
73
+ url: string;
74
+ error: string;
75
+ status: number | null;
76
+ }[];
77
+ }, "TINYFISH_API_KEY">;
78
+ };
79
+ /** The TinyFish extension: a web agent that works toward a goal, web search and page fetch. */
80
+ declare const _default: import("@kana-ai/edgar-sdk").Extension;
81
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import { defineExtension } from "@kana-ai/edgar-sdk";
2
+ import { HOSTS, KEY } from "#api/client";
3
+ import { config } from "#schemas/config";
4
+ import { agentTools } from "#tools/agent";
5
+ import { webTools } from "#tools/web";
6
+ /** Every tool of the TinyFish extension, by the name the manifest gives it. */
7
+ export const tools = { ...agentTools, ...webTools };
8
+ /** The TinyFish extension: a web agent that works toward a goal, web search and page fetch. */
9
+ export default defineExtension({
10
+ name: "tinyfish",
11
+ config,
12
+ secrets: { [KEY]: { hosts: [HOSTS.agent, HOSTS.search, HOSTS.fetch] } },
13
+ capabilities: [`network:${HOSTS.agent}`, `network:${HOSTS.search}`, `network:${HOSTS.fetch}`],
14
+ tools,
15
+ });
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ /** The extension's `[extensions.tinyfish]` table. */
3
+ export declare const config: z.ZodObject<{
4
+ timeout_seconds: z.ZodDefault<z.ZodNumber>;
5
+ capture_screenshots: z.ZodDefault<z.ZodBoolean>;
6
+ }, z.core.$strict>;
@@ -0,0 +1,6 @@
1
+ import { z } from "zod";
2
+ /** The extension's `[extensions.tinyfish]` table. */
3
+ export const config = z.strictObject({
4
+ timeout_seconds: z.number().int().positive().default(300),
5
+ capture_screenshots: z.boolean().default(true),
6
+ });