@howells/fieldwork-sdk 0.0.0-stage → 0.2.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.
@@ -0,0 +1,165 @@
1
+ import { t as defineAdapter } from "./adapter-D-6-GFhJ.js";
2
+ import { r as withJob, t as FieldworkError } from "./errors-pzPMh82H.js";
3
+ import { a as list, c as record, d as strings, f as text, g as requireKey, i as compact, l as requireId, m as createRawClient, p as uniqueCitations, r as citations, t as callSettings } from "./util-DgcIZI2K.js";
4
+ // src/adapters/parallel.ts
5
+ function sourcePolicy(o) {
6
+ const policy = compact({
7
+ include_domains: o.includeDomains,
8
+ exclude_domains: o.excludeDomains,
9
+ after_date: o.publishedAfter
10
+ });
11
+ return Object.keys(policy).length > 0 ? policy : void 0;
12
+ }
13
+ function outputSchema(schema) {
14
+ return schema ? {
15
+ type: "json",
16
+ json_schema: schema
17
+ } : { type: "text" };
18
+ }
19
+ /** Creates a Task run, or picks up `resume`, and waits for its result. */
20
+ async function runTask(raw, body, call, resume) {
21
+ const id = resume ?? requireId(raw.provider, record(await raw.request("POST", "/v1/tasks/runs", {
22
+ ...call,
23
+ body
24
+ })).run_id);
25
+ const deadline = Date.now() + (call.timeout ?? 6e5);
26
+ for (;;) {
27
+ const wait = Math.max(1, Math.min(600, Math.floor((deadline - Date.now()) / 1e3)));
28
+ try {
29
+ return {
30
+ id,
31
+ result: record(await raw.request("GET", `/v1/tasks/runs/${id}/result`, {
32
+ query: { timeout: wait },
33
+ signal: call.signal
34
+ }))
35
+ };
36
+ } catch (error) {
37
+ if (!(error instanceof FieldworkError && error.code === "Timeout") || Date.now() >= deadline) throw withJob(error, id);
38
+ }
39
+ }
40
+ }
41
+ function basis(output) {
42
+ return list(output.basis).map((item) => {
43
+ const entry = record(item);
44
+ return compact({
45
+ field: text(entry.field) ?? "",
46
+ citations: citations(entry.citations),
47
+ confidence: text(entry.confidence),
48
+ reasoning: text(entry.reasoning)
49
+ });
50
+ });
51
+ }
52
+ function parallel(config = {}) {
53
+ const provider = "parallel";
54
+ const raw = createRawClient({
55
+ provider,
56
+ baseUrl: config.baseUrl ?? "https://api.parallel.ai",
57
+ headers: { "x-api-key": requireKey(provider, config.apiKey, "PARALLEL_API_KEY") },
58
+ fetch: config.fetch
59
+ });
60
+ return defineAdapter({
61
+ name: provider,
62
+ operations: {
63
+ async search(query, options) {
64
+ const { call, rest: o } = callSettings(options);
65
+ const response = record(await raw.request("POST", "/v1/search", {
66
+ ...call,
67
+ body: compact({
68
+ objective: o.objective ?? query,
69
+ search_queries: o.queries ?? [query],
70
+ mode: o.mode,
71
+ max_chars_total: o.maxCharsTotal,
72
+ advanced_settings: compact({
73
+ max_results: o.limit,
74
+ source_policy: sourcePolicy(o)
75
+ })
76
+ })
77
+ }));
78
+ return {
79
+ results: list(response.results).map((item) => {
80
+ const result = record(item);
81
+ return compact({
82
+ url: text(result.url) ?? "",
83
+ title: text(result.title),
84
+ snippet: strings(result.excerpts)?.join(" … "),
85
+ publishedAt: text(result.publish_date)
86
+ });
87
+ }),
88
+ raw: response
89
+ };
90
+ },
91
+ async read(url, options) {
92
+ const { call, rest: o } = callSettings(options);
93
+ const response = record(await raw.request("POST", "/v1/extract", {
94
+ ...call,
95
+ body: compact({
96
+ urls: [url],
97
+ objective: o.objective,
98
+ search_queries: o.queries,
99
+ advanced_settings: compact({
100
+ full_content: true,
101
+ fetch_policy: o.maxAgeSeconds === void 0 ? void 0 : { max_age_seconds: o.maxAgeSeconds }
102
+ })
103
+ })
104
+ }));
105
+ const result = record(list(response.results)[0]);
106
+ if (!result.url) {
107
+ const failure = record(list(response.errors)[0]);
108
+ throw new FieldworkError("ProviderError", `parallel could not read ${url}: ${text(failure.content) ?? text(failure.error_type) ?? "no content returned"}`, {
109
+ provider,
110
+ cause: response
111
+ });
112
+ }
113
+ return compact({
114
+ url: text(result.url) ?? "",
115
+ title: text(result.title),
116
+ markdown: text(result.full_content),
117
+ excerpts: strings(result.excerpts),
118
+ raw: response
119
+ });
120
+ },
121
+ async extract(url, options) {
122
+ const { call, rest: o } = callSettings(options);
123
+ const target = new URL(url);
124
+ const { id, result } = await runTask(raw, {
125
+ processor: o.processor ?? "base",
126
+ input: {
127
+ url,
128
+ instructions: o.prompt ?? "Extract the values in the output schema from this page only."
129
+ },
130
+ source_policy: { include_domains: [`${target.hostname}${target.pathname}`.replace(/\/$/u, "")] },
131
+ task_spec: { output_schema: outputSchema(o.schema) }
132
+ }, call, o.resume);
133
+ const output = record(result.output);
134
+ return {
135
+ data: output.content,
136
+ fields: basis(output),
137
+ raw: {
138
+ id,
139
+ ...result
140
+ }
141
+ };
142
+ },
143
+ async research(question, options) {
144
+ const { call, rest: o } = callSettings(options);
145
+ const { id, result } = await runTask(raw, compact({
146
+ processor: o.processor ?? "base",
147
+ input: question,
148
+ source_policy: sourcePolicy(o),
149
+ task_spec: { output_schema: outputSchema(o.schema) }
150
+ }), call, o.resume);
151
+ const output = record(result.output);
152
+ const fields = basis(output);
153
+ return {
154
+ id,
155
+ output: output.content,
156
+ sources: uniqueCitations(fields.flatMap((field) => field.citations)),
157
+ fields,
158
+ raw: result
159
+ };
160
+ }
161
+ },
162
+ raw
163
+ });
164
+ }
165
+ export { parallel };
@@ -0,0 +1,45 @@
1
+ import { C as SearchResponse, S as Research, _ as JsonSchema, a as RawClient, l as CallOptions, t as Adapter } from "./adapter-C_kRm6TT.js";
2
+ import { t as Json } from "./util-D0PLE6Rl.js";
3
+ export interface PerplexityConfig {
4
+ /** Defaults to the PERPLEXITY_API_KEY environment variable. */
5
+ apiKey?: string;
6
+ /** The model research runs on, unless a call names another. */
7
+ model?: string;
8
+ baseUrl?: string;
9
+ fetch?: typeof fetch;
10
+ }
11
+ export interface PerplexitySearchOptions extends CallOptions {
12
+ /** Results to return; Perplexity allows up to 20. */
13
+ limit?: number;
14
+ /** Up to five queries in one request. */
15
+ queries?: string[];
16
+ type?: "web" | "fast" | "people";
17
+ includeDomains?: string[];
18
+ excludeDomains?: string[];
19
+ /** YYYY-MM-DD. */
20
+ publishedAfter?: string;
21
+ /** YYYY-MM-DD. */
22
+ publishedBefore?: string;
23
+ recency?: "hour" | "day" | "week" | "month" | "year";
24
+ country?: string;
25
+ /** ISO 639-1 language codes. */
26
+ languages?: string[];
27
+ maxTokensPerPage?: number;
28
+ }
29
+ export interface PerplexityResearchOptions extends CallOptions {
30
+ schema?: JsonSchema;
31
+ /** Overrides the adapter's model. */
32
+ model?: string;
33
+ effort?: "fast" | "low" | "medium" | "high" | "xhigh";
34
+ /** Caps tool and reasoning steps, not money. */
35
+ maxSteps?: number;
36
+ maxOutputTokens?: number;
37
+ instructions?: string;
38
+ /** Defaults to web search and URL fetching. */
39
+ tools?: Json[];
40
+ }
41
+ export interface PerplexityOperations {
42
+ search(query: string, options?: PerplexitySearchOptions): Promise<SearchResponse>;
43
+ research<T = unknown>(question: string, options?: PerplexityResearchOptions): Promise<Research<T>>;
44
+ }
45
+ export declare function perplexity(config?: PerplexityConfig): Adapter<"perplexity", PerplexityOperations, RawClient>;
@@ -0,0 +1,107 @@
1
+ import { t as defineAdapter } from "./adapter-D-6-GFhJ.js";
2
+ import { t as FieldworkError } from "./errors-pzPMh82H.js";
3
+ import { a as list, c as record, f as text, g as requireKey, i as compact, l as requireId, m as createRawClient, n as citation, p as uniqueCitations, s as parseJson, t as callSettings } from "./util-DgcIZI2K.js";
4
+ // src/adapters/perplexity.ts
5
+ /** Perplexity takes dates as MM/DD/YYYY. */
6
+ function usDate(date) {
7
+ const [year, month, day] = date?.split("-") ?? [];
8
+ return date === void 0 ? void 0 : `${month}/${day}/${year}`;
9
+ }
10
+ function domainFilter(include, exclude) {
11
+ const filter = [...include ?? [], ...(exclude ?? []).map((domain) => `-${domain}`)];
12
+ return filter.length > 0 ? filter : void 0;
13
+ }
14
+ function perplexity(config = {}) {
15
+ const provider = "perplexity";
16
+ const raw = createRawClient({
17
+ provider,
18
+ baseUrl: config.baseUrl ?? "https://api.perplexity.ai",
19
+ headers: { authorization: `Bearer ${requireKey(provider, config.apiKey, "PERPLEXITY_API_KEY")}` },
20
+ fetch: config.fetch
21
+ });
22
+ return defineAdapter({
23
+ name: provider,
24
+ operations: {
25
+ async search(query, options) {
26
+ const { call, rest: o } = callSettings(options);
27
+ const response = record(await raw.request("POST", "/search", {
28
+ ...call,
29
+ body: compact({
30
+ query: o.queries ? [query, ...o.queries] : query,
31
+ max_results: o.limit,
32
+ search_type: o.type,
33
+ search_domain_filter: domainFilter(o.includeDomains, o.excludeDomains),
34
+ search_after_date_filter: usDate(o.publishedAfter),
35
+ search_before_date_filter: usDate(o.publishedBefore),
36
+ search_recency_filter: o.recency,
37
+ country: o.country,
38
+ search_language_filter: o.languages,
39
+ max_tokens_per_page: o.maxTokensPerPage
40
+ })
41
+ }));
42
+ return {
43
+ results: list(response.results).map((item) => {
44
+ const result = record(item);
45
+ return compact({
46
+ url: text(result.url) ?? "",
47
+ title: text(result.title),
48
+ snippet: text(result.snippet),
49
+ publishedAt: text(result.date) ?? text(result.last_updated)
50
+ });
51
+ }),
52
+ raw: response
53
+ };
54
+ },
55
+ async research(question, options) {
56
+ const { call, rest: o } = callSettings(options);
57
+ const model = o.model ?? config.model;
58
+ if (!model) throw new FieldworkError("InvalidRequest", "perplexity research needs a model: pass model to perplexity() or to the call", { provider });
59
+ const response = record(await raw.request("POST", "/v1/agent", {
60
+ ...call,
61
+ body: compact({
62
+ model,
63
+ input: question,
64
+ instructions: o.instructions,
65
+ effort: o.effort,
66
+ max_steps: o.maxSteps,
67
+ max_output_tokens: o.maxOutputTokens,
68
+ tools: o.tools ?? [{ type: "web_search" }, { type: "fetch_url" }],
69
+ response_format: o.schema ? {
70
+ type: "json_schema",
71
+ json_schema: {
72
+ name: "output",
73
+ schema: o.schema
74
+ }
75
+ } : void 0
76
+ })
77
+ }));
78
+ if (response.status && response.status !== "completed") throw new FieldworkError("JobFailed", `perplexity research ended ${text(response.status) ?? "unknown"}`, {
79
+ provider,
80
+ cause: response
81
+ });
82
+ const sources = [];
83
+ const parts = [];
84
+ for (const item of list(response.output)) {
85
+ const entry = record(item);
86
+ if (entry.type === "message") for (const content of list(entry.content)) {
87
+ const value = text(record(content).text);
88
+ if (value) parts.push(value);
89
+ }
90
+ for (const found of [...list(entry.results), ...list(entry.contents)]) {
91
+ const source = citation(found);
92
+ if (source) sources.push(source);
93
+ }
94
+ }
95
+ const reply = parts.join("");
96
+ return {
97
+ id: requireId(provider, response.id),
98
+ output: o.schema ? parseJson(provider, reply) : reply,
99
+ sources: uniqueCitations(sources),
100
+ raw: response
101
+ };
102
+ }
103
+ },
104
+ raw
105
+ });
106
+ }
107
+ export { perplexity };
@@ -0,0 +1,84 @@
1
+ import { C as SearchResponse, E as SiteMap, S as Research, _ as JsonSchema, a as RawClient, f as Crawl, l as CallOptions, t as Adapter, v as Page } from "./adapter-C_kRm6TT.js";
2
+ export interface TavilyConfig {
3
+ /** Defaults to the TAVILY_API_KEY environment variable. */
4
+ apiKey?: string;
5
+ baseUrl?: string;
6
+ fetch?: typeof fetch;
7
+ }
8
+ export interface TavilySearchOptions extends CallOptions {
9
+ /** Results to return; Tavily allows up to 20. */
10
+ limit?: number;
11
+ depth?: "ultra-fast" | "fast" | "basic" | "advanced";
12
+ topic?: "general" | "news" | "finance";
13
+ timeRange?: "day" | "week" | "month" | "year";
14
+ /** YYYY-MM-DD. */
15
+ publishedAfter?: string;
16
+ /** YYYY-MM-DD. */
17
+ publishedBefore?: string;
18
+ includeDomains?: string[];
19
+ excludeDomains?: string[];
20
+ /** "restrict" keeps to includeDomains; "prefer" only ranks them higher. */
21
+ includeDomainsMode?: "restrict" | "prefer";
22
+ /** A country name in lower case, such as "united states". */
23
+ country?: string;
24
+ /** Add a generated answer above the results. */
25
+ answer?: boolean | "basic" | "advanced";
26
+ /** Include each result's page text. */
27
+ content?: boolean;
28
+ exactMatch?: boolean;
29
+ /** Hours of cache Tavily may use; 0 forces live results. */
30
+ maxAgeHours?: number;
31
+ }
32
+ export interface TavilyReadOptions extends CallOptions {
33
+ /** "advanced" handles JavaScript, tables and embedded content. */
34
+ depth?: "basic" | "advanced";
35
+ /** Return only the passages that answer this query, not the whole page. */
36
+ query?: string;
37
+ chunksPerSource?: number;
38
+ format?: "markdown" | "text";
39
+ includeImages?: boolean;
40
+ }
41
+ interface TavilyTraversal {
42
+ /** Plain-words instructions that focus the walk. */
43
+ instructions?: string;
44
+ maxDepth?: number;
45
+ maxBreadth?: number;
46
+ limit?: number;
47
+ selectPaths?: string[];
48
+ excludePaths?: string[];
49
+ selectDomains?: string[];
50
+ excludeDomains?: string[];
51
+ /** Tavily defaults to true. */
52
+ allowExternal?: boolean;
53
+ }
54
+ export interface TavilyMapOptions extends CallOptions, TavilyTraversal {}
55
+ export interface TavilyCrawlOptions extends CallOptions, TavilyTraversal {
56
+ extractDepth?: "basic" | "advanced";
57
+ format?: "markdown" | "text";
58
+ includeImages?: boolean;
59
+ }
60
+ export interface TavilyResearchOptions extends CallOptions {
61
+ /** Tavily accepts object, string, integer, number and array types only. */
62
+ schema?: JsonSchema;
63
+ model?: "mini" | "pro" | "auto";
64
+ citationFormat?: "numbered" | "mla" | "apa" | "chicago";
65
+ outputLength?: "short" | "standard" | "long";
66
+ /** A preference, not a restriction. */
67
+ includeDomains?: string[];
68
+ excludeDomains?: string[];
69
+ interval?: number;
70
+ /**
71
+ * The id of a job that timed out or was cancelled, from the error's
72
+ * `jobId`. Waits for that job instead of starting a new one.
73
+ */
74
+ resume?: string;
75
+ }
76
+ export interface TavilyOperations {
77
+ search(query: string, options?: TavilySearchOptions): Promise<SearchResponse>;
78
+ read(url: string, options?: TavilyReadOptions): Promise<Page>;
79
+ map(url: string, options?: TavilyMapOptions): Promise<SiteMap>;
80
+ crawl(url: string, options?: TavilyCrawlOptions): Promise<Crawl>;
81
+ research<T = unknown>(question: string, options?: TavilyResearchOptions): Promise<Research<T>>;
82
+ }
83
+ export declare function tavily(config?: TavilyConfig): Adapter<"tavily", TavilyOperations, RawClient>;
84
+ export {};
package/dist/tavily.js ADDED
@@ -0,0 +1,172 @@
1
+ import { t as defineAdapter } from "./adapter-D-6-GFhJ.js";
2
+ import { t as FieldworkError } from "./errors-pzPMh82H.js";
3
+ import { a as list, c as record, d as strings, f as text, g as requireKey, h as poll, i as compact, l as requireId, m as createRawClient, o as num, r as citations, t as callSettings } from "./util-DgcIZI2K.js";
4
+ // src/adapters/tavily.ts
5
+ function traversal(o) {
6
+ return compact({
7
+ instructions: o.instructions,
8
+ max_depth: o.maxDepth,
9
+ max_breadth: o.maxBreadth,
10
+ limit: o.limit,
11
+ select_paths: o.selectPaths,
12
+ exclude_paths: o.excludePaths,
13
+ select_domains: o.selectDomains,
14
+ exclude_domains: o.excludeDomains,
15
+ allow_external: o.allowExternal
16
+ });
17
+ }
18
+ function tavily(config = {}) {
19
+ const provider = "tavily";
20
+ const raw = createRawClient({
21
+ provider,
22
+ baseUrl: config.baseUrl ?? "https://api.tavily.com",
23
+ headers: { authorization: `Bearer ${requireKey(provider, config.apiKey, "TAVILY_API_KEY")}` },
24
+ fetch: config.fetch
25
+ });
26
+ return defineAdapter({
27
+ name: provider,
28
+ operations: {
29
+ async search(query, options) {
30
+ const { call, rest: o } = callSettings(options);
31
+ const response = record(await raw.request("POST", "/search", {
32
+ ...call,
33
+ body: compact({
34
+ query,
35
+ max_results: o.limit,
36
+ search_depth: o.depth,
37
+ topic: o.topic,
38
+ time_range: o.timeRange,
39
+ start_date: o.publishedAfter,
40
+ end_date: o.publishedBefore,
41
+ include_domains: o.includeDomains,
42
+ exclude_domains: o.excludeDomains,
43
+ include_domains_mode: o.includeDomainsMode,
44
+ country: o.country,
45
+ include_answer: o.answer,
46
+ include_raw_content: o.content ? "markdown" : void 0,
47
+ exact_match: o.exactMatch,
48
+ max_age_hours: o.maxAgeHours
49
+ })
50
+ }));
51
+ return compact({
52
+ results: list(response.results).map((item) => {
53
+ const result = record(item);
54
+ return compact({
55
+ url: text(result.url) ?? "",
56
+ title: text(result.title),
57
+ snippet: text(result.content),
58
+ content: text(result.raw_content),
59
+ publishedAt: text(result.published_date),
60
+ score: num(result.score)
61
+ });
62
+ }),
63
+ answer: text(response.answer),
64
+ raw: response
65
+ });
66
+ },
67
+ async read(url, options) {
68
+ const { call, rest: o } = callSettings(options);
69
+ const response = record(await raw.request("POST", "/extract", {
70
+ ...call,
71
+ body: compact({
72
+ urls: [url],
73
+ extract_depth: o.depth,
74
+ query: o.query,
75
+ chunks_per_source: o.chunksPerSource,
76
+ format: o.format,
77
+ include_images: o.includeImages
78
+ })
79
+ }));
80
+ const result = record(list(response.results)[0]);
81
+ if (!result.url) {
82
+ const failure = record(list(response.failed_results)[0]);
83
+ throw new FieldworkError("ProviderError", `tavily could not read ${url}: ${text(failure.error) ?? "no content returned"}`, {
84
+ provider,
85
+ cause: response
86
+ });
87
+ }
88
+ return compact({
89
+ url: text(result.url) ?? "",
90
+ title: text(result.title),
91
+ markdown: text(result.raw_content),
92
+ images: strings(result.images),
93
+ raw: response
94
+ });
95
+ },
96
+ async map(url, options) {
97
+ const { call, rest: o } = callSettings(options);
98
+ const response = record(await raw.request("POST", "/map", {
99
+ ...call,
100
+ body: {
101
+ url,
102
+ ...traversal(o)
103
+ }
104
+ }));
105
+ return {
106
+ links: list(response.results).flatMap((item) => typeof item === "string" ? [{ url: item }] : []),
107
+ raw: response
108
+ };
109
+ },
110
+ async crawl(url, options) {
111
+ const { call, rest: o } = callSettings(options);
112
+ const response = record(await raw.request("POST", "/crawl", {
113
+ ...call,
114
+ body: compact({
115
+ url,
116
+ ...traversal(o),
117
+ extract_depth: o.extractDepth,
118
+ format: o.format,
119
+ include_images: o.includeImages
120
+ })
121
+ }));
122
+ return {
123
+ pages: list(response.results).map((item) => {
124
+ const page = record(item);
125
+ return compact({
126
+ url: text(page.url) ?? "",
127
+ markdown: text(page.raw_content),
128
+ images: strings(page.images),
129
+ raw: item
130
+ });
131
+ }),
132
+ raw: response
133
+ };
134
+ },
135
+ async research(question, options) {
136
+ const { call, rest: o } = callSettings(options);
137
+ const id = o.resume ?? requireId(provider, record(await raw.request("POST", "/research", {
138
+ ...call,
139
+ body: compact({
140
+ input: question,
141
+ model: o.model,
142
+ output_schema: o.schema,
143
+ citation_format: o.citationFormat,
144
+ output_length: o.outputLength,
145
+ include_domains: o.includeDomains,
146
+ exclude_domains: o.excludeDomains,
147
+ stream: false
148
+ })
149
+ })).request_id);
150
+ const run = await poll(provider, id, async () => {
151
+ const current = record(await raw.request("GET", `/research/${id}`, { signal: call.signal }));
152
+ if (current.status === "failed") throw new FieldworkError("JobFailed", `tavily research ${id} failed`, {
153
+ provider,
154
+ cause: current
155
+ });
156
+ return current.status === "completed" ? current : void 0;
157
+ }, {
158
+ ...call,
159
+ interval: o.interval
160
+ });
161
+ return {
162
+ id,
163
+ output: run.content,
164
+ sources: citations(run.sources),
165
+ raw: run
166
+ };
167
+ }
168
+ },
169
+ raw
170
+ });
171
+ }
172
+ export { tavily };
@@ -0,0 +1,76 @@
1
+ import { i as FieldworkErrorCode, t as Fieldwork } from "./fieldwork-nPzWEelg.js";
2
+ import { _ as JsonSchema, l as CallOptions, n as AnyAdapter, u as Capability } from "./adapter-C_kRm6TT.js";
3
+ /**
4
+ * Tool definitions for agents, built from a Fieldwork instance. Each tool's
5
+ * input schema lists only the options its provider supports, so a model is
6
+ * never offered an option that would be ignored. The definitions are plain
7
+ * JSON Schema with MCP-style annotations, so they work with the AI SDK, MCP
8
+ * servers and any framework that accepts JSON Schema tools.
9
+ */
10
+ export interface ToolAnnotations {
11
+ title: string;
12
+ /** True when the tool changes nothing outside Fieldwork. */
13
+ readOnlyHint: boolean;
14
+ /** True when the tool can make changes that cannot be undone. */
15
+ destructiveHint: boolean;
16
+ /** True when repeating a call with the same input has no further effect. */
17
+ idempotentHint: boolean;
18
+ /** True when the tool reaches the open web. */
19
+ openWorldHint: boolean;
20
+ }
21
+ export interface FieldworkTool {
22
+ /** A verb_noun name, such as `search_web`. */
23
+ name: string;
24
+ capability: Capability;
25
+ /** The provider that serves this tool, such as "firecrawl". */
26
+ provider: string;
27
+ /** What the tool does, when to use it and when to use another tool. */
28
+ description: string;
29
+ /** A JSON Schema object for the tool's input. */
30
+ inputSchema: JsonSchema;
31
+ /** A JSON Schema object for what `execute` returns. */
32
+ outputSchema: JsonSchema;
33
+ annotations: ToolAnnotations;
34
+ /**
35
+ * Checks the input against `inputSchema`, calls the capability and returns
36
+ * the result shaped for a model: without the provider's `raw` response and
37
+ * with long text cut to the `maxCharacters` budget. Throws a
38
+ * `FieldworkError`; bad input is `InvalidRequest`.
39
+ */
40
+ execute(input: unknown, options?: CallOptions): Promise<unknown>;
41
+ }
42
+ export interface ToolsOptions {
43
+ /**
44
+ * Capabilities to make tools for. Defaults to every capability the instance
45
+ * supports except `act`, which runs code in a browser and is included only
46
+ * when named here.
47
+ */
48
+ capabilities?: Capability[];
49
+ /**
50
+ * The most characters of long text (page Markdown, reports, document text)
51
+ * one result returns, shared across its fields. Text of 500 characters or
52
+ * fewer, such as titles, URLs and snippets, is never cut. Defaults to 20,000.
53
+ */
54
+ maxCharacters?: number;
55
+ }
56
+ /** Makes one tool per capability the instance supports. */
57
+ export declare function toolsFor(web: Fieldwork<AnyAdapter>, options?: ToolsOptions): FieldworkTool[];
58
+ /**
59
+ * An error as a model or an MCP client should see it: the code, the message
60
+ * and what to do next, without the provider's response.
61
+ */
62
+ export declare function toolError(error: unknown): {
63
+ name: string;
64
+ code: FieldworkErrorCode;
65
+ message: string;
66
+ provider: string | undefined;
67
+ status: number | undefined;
68
+ retryable: boolean;
69
+ retryAfter: number | undefined;
70
+ jobId: string | undefined;
71
+ } | {
72
+ name: string;
73
+ code: "ProviderError";
74
+ message: string;
75
+ retryable: boolean;
76
+ };