@howells/fieldwork-sdk 0.11.0 → 0.13.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.
Files changed (47) hide show
  1. package/README.md +73 -15
  2. package/dist/{adapter-DWYJys20.js → adapter-CBSAfErv.js} +1 -1
  3. package/dist/adapter-J2yatZJ0.d.ts +73 -0
  4. package/dist/best-DiKYwLdC.js +1436 -0
  5. package/dist/brave.d.ts +7 -6
  6. package/dist/brave.js +175 -168
  7. package/dist/browserbase.d.ts +4 -3
  8. package/dist/browserbase.js +182 -167
  9. package/dist/{document-DMIUCoDA.js → document-x9fWsQ1W.js} +2 -2
  10. package/dist/{download-CP8noBdX.js → download-kuTqNnuZ.js} +1 -1
  11. package/dist/{adapter-B8kAAAgF.d.ts → errors-gMtejKHc.d.ts} +87 -69
  12. package/dist/exa.d.ts +18 -11
  13. package/dist/exa.js +301 -267
  14. package/dist/fieldwork-D7npPoUf.d.ts +35 -0
  15. package/dist/firecrawl.d.ts +4 -3
  16. package/dist/firecrawl.js +432 -399
  17. package/dist/{parse-Q7H4mrnO.js → http-Bg0h3D-t.js} +222 -224
  18. package/dist/image.d.ts +253 -0
  19. package/dist/image.js +1 -0
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +66 -82
  22. package/dist/{job-DnavRq_s.js → job-BsrOrrO1.js} +7 -7
  23. package/dist/kernel.d.ts +20 -2
  24. package/dist/kernel.js +58 -12
  25. package/dist/llamaparse.d.ts +3 -2
  26. package/dist/llamaparse.js +8 -8
  27. package/dist/parallel.d.ts +10 -10
  28. package/dist/parallel.js +432 -391
  29. package/dist/path-tDCyAKK9.js +10 -0
  30. package/dist/perplexity.d.ts +6 -5
  31. package/dist/perplexity.js +16 -16
  32. package/dist/reducto.d.ts +3 -2
  33. package/dist/reducto.js +8 -8
  34. package/dist/{schema--iU4AXSM.js → schema-Bfd2E8u2.js} +12 -3
  35. package/dist/{schema-CAPSX7yQ.d.ts → schema-C9xzRkKJ.d.ts} +17 -6
  36. package/dist/serpapi.d.ts +3 -3
  37. package/dist/serpapi.js +170 -165
  38. package/dist/tavily.d.ts +4 -3
  39. package/dist/tavily.js +242 -229
  40. package/dist/tools.d.ts +79 -15
  41. package/dist/tools.js +431 -77
  42. package/dist/{util-DFUXQX6v.js → util-BOqd71Om.js} +44 -12
  43. package/package.json +11 -6
  44. package/dist/fieldwork-BrfoehvG.d.ts +0 -113
  45. package/dist/path-DL5P8XH2.js +0 -17
  46. package/dist/util-DhYr1OS3.d.ts +0 -1
  47. package/dist/{errors-DkFJysIM.js → errors-gpxg6Tnh.js} +5 -5
@@ -0,0 +1,10 @@
1
+ import { v as isNumber } from "./util-BOqd71Om.js";
2
+ // src/path.ts
3
+ /** A JSON path, with brackets for indices and keys that are not identifiers. */
4
+ const joinPath = (segments) => {
5
+ let path = "";
6
+ for (const key of segments) if (isNumber(key)) path += `[${key}]`;
7
+ else path += /^[A-Za-z_$][\w$]*$/u.test(key) ? `${path ? "." : ""}${key}` : `[${JSON.stringify(key)}]`;
8
+ return path;
9
+ };
10
+ export { joinPath as t };
@@ -1,5 +1,6 @@
1
- import { $ as Research, Q as Recency, a as RawClient, b as Decisions, l as Answer, nt as SearchResponse, p as CallOptions, t as Adapter, y as DecisionQuestion } from "./adapter-B8kAAAgF.js";
2
- import { t as OutputSchema } from "./schema-CAPSX7yQ.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { J as Recency, Q as SearchResponse, Y as Research, a as Answer, g as Decisions, h as DecisionQuestion, l as CallOptions, ot as JsonValue } from "./errors-gMtejKHc.js";
3
+ import { t as OutputSchema } from "./schema-C9xzRkKJ.js";
3
4
  /** Settings for `perplexity()`. */
4
5
  interface PerplexityConfig {
5
6
  /** Defaults to the PERPLEXITY_API_KEY environment variable. */
@@ -54,7 +55,7 @@ interface PerplexitySearchOptions extends CallOptions, PerplexityFilters {
54
55
  /** Page-content tokens across all results. */
55
56
  maxTokens?: number;
56
57
  /** Page-content tokens for each result. */
57
- maxTokensPerPage?: number;
58
+ maxTokensPerResult?: number;
58
59
  }
59
60
  /** An effort level, or a name pinned to a version such as `fast@2026-10-16.0`. */
60
61
  type Pinned<Name extends string> = Name | `${Name}@${string}`;
@@ -131,10 +132,10 @@ interface PerplexityOperations {
131
132
  search: (query: string, options?: PerplexitySearchOptions) => Promise<SearchResponse>;
132
133
  answer: <T = unknown>(question: string, options?: PerplexityAnswerOptions<T>) => Promise<Answer<T>>;
133
134
  research: <T = unknown>(question: string, options?: PerplexityResearchOptions<T>) => Promise<Research<T>>;
134
- decide: (context: unknown, questions: Record<string, DecisionQuestion>, options?: PerplexityDecideOptions) => Promise<Decisions>;
135
+ decide: (context: JsonValue, questions: Record<string, DecisionQuestion>, options?: PerplexityDecideOptions) => Promise<Decisions>;
135
136
  }
136
137
  /**
137
- * An adapter for Perplexity: search, answer, research and decide. Pass it to `new Fieldwork({ adapter })`.
138
+ * An adapter for Perplexity: search, answer, research and decide. Pass it to `fieldwork({ adapter })`.
138
139
  *
139
140
  * Throws `Unauthorized` when neither `apiKey` nor `PERPLEXITY_API_KEY` is set.
140
141
  */
@@ -1,10 +1,10 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
3
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, i as both, m as optionalScalar, n as anything, r as arrayOf, t as Source, v as recordOf, y as sourceShape } from "./parse-Q7H4mrnO.js";
4
- import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema--iU4AXSM.js";
6
- import { a as compact, c as parseJson, f as refuseTogether, m as uniqueCitations, r as citationOf, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
7
1
  import * as z from "zod/mini";
2
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
3
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
4
+ import { O as withOriginal, T as sourceShape, _ as optionalId, b as optionalScalar, c as anything, d as looseObject, i as segment, l as arrayOf, r as requireKey, s as Source, t as createRawClient, u as both, v as optionalNumber, w as recordOf, x as optionalString } from "./http-Bg0h3D-t.js";
5
+ import { i as startJob, r as runJob, t as jobState } from "./job-BsrOrrO1.js";
6
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-Bfd2E8u2.js";
7
+ import { a as compact, c as parseJson, f as refuseTogether, h as isFlag, m as uniqueCitations, r as citationOf, s as meta, t as callSettings, v as isNumber } from "./util-BOqd71Om.js";
8
8
  // src/adapters/perplexity/parse.ts
9
9
  /** The name this adapter reports in errors and results. */
10
10
  const provider = "perplexity";
@@ -141,12 +141,12 @@ const responseFormat = (schema) => schema ? {
141
141
  } : void 0;
142
142
  /**
143
143
  * The decision `state`. A string, object or array goes through as it is; a number
144
- * or boolean is sent as text; anything else is refused.
144
+ * or boolean is sent as text; null is refused.
145
145
  */
146
146
  const decisionState = (context) => {
147
- if (typeof context === "string" || typeof context === "object" && context) return context;
148
- if (typeof context === "number" || typeof context === "boolean") return String(context);
149
- throw invalidRequest(provider, "decide needs a context: a string, object or array");
147
+ if (isNumber(context) || isFlag(context)) return String(context);
148
+ if (context === null) throw invalidRequest(provider, "decide needs a context: a string, object or array");
149
+ return context;
150
150
  };
151
151
  /**
152
152
  * The effort, model, step and tool fields of a research run. Refuses `models`
@@ -315,7 +315,7 @@ const DecisionsResponse = looseObject({
315
315
  * flat list. Refuses more than five queries in all, and a `limit` over 20, or
316
316
  * over 50 when `searchType` is "people".
317
317
  */
318
- const search = async (raw, query, options) => {
318
+ const search = async (raw, query, options = {}) => {
319
319
  const { call, rest: o } = callSettings(options);
320
320
  const queries = [query, ...o.queries ?? []];
321
321
  if (queries.length > 5) throw invalidRequest(provider, `search takes at most 5 queries in one request, got ${queries.length}`);
@@ -327,7 +327,7 @@ const search = async (raw, query, options) => {
327
327
  country: o.country,
328
328
  max_results: o.limit,
329
329
  max_tokens: o.maxTokens,
330
- max_tokens_per_page: o.maxTokensPerPage,
330
+ max_tokens_per_page: o.maxTokensPerResult,
331
331
  query: queries.length > 1 ? queries : query,
332
332
  search_language_filter: languageCodes(o.language),
333
333
  search_type: o.searchType,
@@ -352,7 +352,7 @@ const search = async (raw, query, options) => {
352
352
  * otherwise. An `incomplete` response returns its text with a warning; a failed or
353
353
  * cancelled one, or one with no text, throws.
354
354
  */
355
- const answer = async (raw, question, options) => {
355
+ const answer = async (raw, question, options = {}) => {
356
356
  const { call, rest: o } = callSettings(options);
357
357
  const run = z.parse(AgentRun, await raw.request("POST", "/v1/agent", {
358
358
  ...call,
@@ -410,7 +410,7 @@ const startResearch = async (raw, question, o, call) => await startJob(raw, "/v1
410
410
  * `partial` with that status as `stopReason`. A `failed` run, or one with no text,
411
411
  * throws `JobFailed`. The run's id is also its `continuationId`.
412
412
  */
413
- const research = async (raw, question, options) => {
413
+ const research = async (raw, question, options = {}) => {
414
414
  const { call, rest: o } = callSettings(options);
415
415
  return await runJob(provider, {
416
416
  check: async (id, request) => {
@@ -447,7 +447,7 @@ const research = async (raw, question, options) => {
447
447
  * `/v1/decisions`. Perplexity returns no citations, so `citations` is always empty.
448
448
  * Score answers are keyed by the caller's scale keys.
449
449
  */
450
- const decide = async (raw, context, questions, options) => {
450
+ const decide = async (raw, context, questions, options = {}) => {
451
451
  const { call, rest: o } = callSettings(options);
452
452
  const response = await raw.request("POST", "/v1/decisions", {
453
453
  ...call,
@@ -482,7 +482,7 @@ const decide = async (raw, context, questions, options) => {
482
482
  };
483
483
  };
484
484
  /**
485
- * An adapter for Perplexity: search, answer, research and decide. Pass it to `new Fieldwork({ adapter })`.
485
+ * An adapter for Perplexity: search, answer, research and decide. Pass it to `fieldwork({ adapter })`.
486
486
  *
487
487
  * Throws `Unauthorized` when neither `apiKey` nor `PERPLEXITY_API_KEY` is set.
488
488
  */
package/dist/reducto.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { C as DocumentInput, K as ParsedDocument, T as DocumentUrl, a as RawClient, p as CallOptions, t as Adapter } from "./adapter-B8kAAAgF.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { H as ParsedDocument, l as CallOptions, x as DocumentUrl, y as DocumentInput } from "./errors-gMtejKHc.js";
2
3
  /** Settings for `reducto()`. */
3
4
  export interface ReductoConfig {
4
5
  /** Defaults to the REDUCTO_API_KEY environment variable. */
@@ -38,7 +39,7 @@ export interface ReductoOperations {
38
39
  };
39
40
  }
40
41
  /**
41
- * An adapter for Reducto: parse. Pass it to `new Fieldwork({ adapter })`.
42
+ * An adapter for Reducto: parse. Pass it to `fieldwork({ adapter })`.
42
43
  *
43
44
  * Throws `Unauthorized` when neither `apiKey` nor `REDUCTO_API_KEY` is set.
44
45
  */
package/dist/reducto.js CHANGED
@@ -1,10 +1,10 @@
1
- import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { n as documentPart, o as refuseLarger, r as documentUrl } from "./document-DMIUCoDA.js";
3
- import { t as FieldworkError } from "./errors-DkFJysIM.js";
4
- import { C as createRawClient, E as segment, S as withOriginal, T as requireKey, a as looseObject, d as optionalId, f as optionalNumber, h as optionalString, r as arrayOf, s as optionalAnyString, w as readSigned } from "./parse-Q7H4mrnO.js";
5
- import { i as startJob, r as runJob, t as jobState } from "./job-DnavRq_s.js";
6
- import { a as compact, c as parseJson, p as requireJobId, s as meta, t as callSettings } from "./util-DFUXQX6v.js";
7
1
  import * as z from "zod/mini";
2
+ import { t as defineAdapter } from "./adapter-CBSAfErv.js";
3
+ import { n as documentPart, o as refuseLarger, r as documentUrl } from "./document-x9fWsQ1W.js";
4
+ import { t as FieldworkError } from "./errors-gpxg6Tnh.js";
5
+ import { O as withOriginal, _ as optionalId, d as looseObject, i as segment, l as arrayOf, n as readSigned, p as optionalAnyString, r as requireKey, t as createRawClient, v as optionalNumber, x as optionalString } from "./http-Bg0h3D-t.js";
6
+ import { i as startJob, r as runJob, t as jobState } from "./job-BsrOrrO1.js";
7
+ import { a as compact, c as parseJson, p as requireJobId, s as meta, t as callSettings } from "./util-BOqd71Om.js";
8
8
  // src/adapters/reducto/response.ts
9
9
  /** A box in fractions of the page, from its top-left corner. `page` counts the pages parsed; `original_page` the file's. */
10
10
  const FractionBox = looseObject({
@@ -212,7 +212,7 @@ const parse = async (raw, document, options, fetchImpl) => {
212
212
  });
213
213
  };
214
214
  /**
215
- * An adapter for Reducto: parse. Pass it to `new Fieldwork({ adapter })`.
215
+ * An adapter for Reducto: parse. Pass it to `fieldwork({ adapter })`.
216
216
  *
217
217
  * Throws `Unauthorized` when neither `apiKey` nor `REDUCTO_API_KEY` is set.
218
218
  */
@@ -226,7 +226,7 @@ const reducto = (config = {}) => {
226
226
  });
227
227
  return defineAdapter({
228
228
  name: provider,
229
- operations: { async parse(first, options) {
229
+ operations: { async parse(first, options = {}) {
230
230
  return "resume" in first ? await parse(raw, void 0, first, config.fetch) : await parse(raw, first, options, config.fetch);
231
231
  } },
232
232
  raw
@@ -1,5 +1,6 @@
1
- import { r as invalidRequest, t as FieldworkError } from "./errors-DkFJysIM.js";
2
- import { o as isText, r as isJsonObject, t as joinPath } from "./path-DL5P8XH2.js";
1
+ import { r as invalidRequest, t as FieldworkError } from "./errors-gpxg6Tnh.js";
2
+ import { g as isJsonObject, y as isText } from "./util-BOqd71Om.js";
3
+ import { t as joinPath } from "./path-tDCyAKK9.js";
3
4
  // src/schema-subset.ts
4
5
  const MAPS = /* @__PURE__ */ new Set([
5
6
  "properties",
@@ -87,6 +88,12 @@ const checkSchemaSubset = (schema, provider) => {
87
88
  // src/schema.ts
88
89
  const isStandard = (schema) => "~standard" in schema;
89
90
  /**
91
+ * Whether the provider's output stands as the result unchecked: there is no
92
+ * schema, or a plain JSON Schema, which `OutputSchema` admits only for a
93
+ * result type that holds the unchecked value.
94
+ */
95
+ const isUnchecked = (schema, _value) => schema === void 0 || !isStandard(schema);
96
+ /**
90
97
  * The JSON Schema to send to a provider. A plain JSON Schema passes through as
91
98
  * given; a Standard Schema is converted to `target`, without its `$schema` key,
92
99
  * because the provider's docs, not the library, say which dialect it reads.
@@ -99,6 +106,7 @@ const jsonSchemaOf = (schema, target = "draft-2020-12", subset) => {
99
106
  let result;
100
107
  try {
101
108
  const converted = schema["~standard"].jsonSchema.input({ target });
109
+ if (!isJsonObject(converted)) throw new TypeError("the library returned a JSON Schema that is not an object");
102
110
  result = Object.fromEntries(Object.entries(converted).filter(([key]) => key !== "$schema"));
103
111
  } catch (error) {
104
112
  throw new FieldworkError("InvalidRequest", `the ${schema["~standard"].vendor} schema cannot be written as ${target} JSON Schema: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
@@ -123,7 +131,8 @@ const describeIssues = (issues) => {
123
131
  * plain JSON Schema, or no schema, leaves it unchecked.
124
132
  */
125
133
  const checkOutput = async (schema, value, context) => {
126
- if (schema === void 0 || !isStandard(schema)) return value;
134
+ if (isUnchecked(schema, value)) return value;
135
+ if (schema === void 0 || !isStandard(schema)) throw new TypeError("a schema that is not a Standard Schema leaves output unchecked");
127
136
  const result = await schema["~standard"].validate(value);
128
137
  if (result.issues !== void 0) throw new FieldworkError("ProviderError", `${context.provider} returned output that does not match the schema: ${describeIssues(result.issues)}`, {
129
138
  cause: result.issues,
@@ -1,4 +1,4 @@
1
- import { I as JsonSchema } from "./adapter-B8kAAAgF.js";
1
+ import { M as JsonSchema, ot as JsonValue } from "./errors-gMtejKHc.js";
2
2
  /** Vendor-specific parameters a schema library may accept. */
3
3
  type LibraryOptions = JsonSchema;
4
4
  /** The path segment interface of an issue. */
@@ -65,12 +65,16 @@ interface StandardJSONSchemaOptions {
65
65
  /** Implicit support for additional vendor-specific parameters, if needed. */
66
66
  readonly libraryOptions?: LibraryOptions;
67
67
  }
68
- /** The Standard JSON Schema converter interface. */
68
+ /**
69
+ * The Standard JSON Schema converter interface. The spec types the schema a
70
+ * library writes as an object of unknown values; `jsonSchemaOf` checks it is
71
+ * an object before reading it as JSON.
72
+ */
69
73
  interface StandardJSONSchemaConverter {
70
74
  /** Converts the input type to JSON Schema. May throw if conversion is not supported. */
71
- readonly input: (options: StandardJSONSchemaOptions) => JsonSchema;
75
+ readonly input: (options: StandardJSONSchemaOptions) => object;
72
76
  /** Converts the output type to JSON Schema. May throw if conversion is not supported. */
73
- readonly output: (options: StandardJSONSchemaOptions) => JsonSchema;
77
+ readonly output: (options: StandardJSONSchemaOptions) => object;
74
78
  }
75
79
  /** The Standard JSON Schema properties interface. */
76
80
  interface StandardJSONSchemaProps<Input = unknown, Output = Input> extends StandardTypedProps<Input, Output> {
@@ -81,10 +85,17 @@ interface StandardJSONSchemaProps<Input = unknown, Output = Input> extends Stand
81
85
  interface StandardSchemaWithJSON<Input = unknown, Output = Input> {
82
86
  readonly "~standard": StandardSchemaProps<Input, Output> & StandardJSONSchemaProps<Input, Output>;
83
87
  }
88
+ /**
89
+ * The output a plain JSON Schema, or no schema, leaves unchecked: the
90
+ * provider's JSON as it arrived.
91
+ */
92
+ type UncheckedOutput = JsonValue | undefined;
84
93
  /**
85
94
  * The shape of a structured output: a plain JSON Schema, or a Standard Schema
86
95
  * with JSON Schema support. A Standard Schema gives the result its type and
87
- * checks the provider's output against it; a plain JSON Schema does neither.
96
+ * checks the provider's output against it; a plain JSON Schema does neither,
97
+ * so it is accepted only where the result's type `T` admits whatever the
98
+ * provider can send unchecked (`Unchecked`), as the default `unknown` does.
88
99
  */
89
- type OutputSchema<T> = JsonSchema | StandardSchemaWithJSON<unknown, T>;
100
+ type OutputSchema<T, Unchecked = UncheckedOutput> = StandardSchemaWithJSON<unknown, T> | ([Unchecked] extends [T] ? JsonSchema : never);
90
101
  export { StandardSchemaWithJSON as n, OutputSchema as t };
package/dist/serpapi.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { F as ImageSearch, Q as Recency, R as MatchKind, a as RawClient, et as ReverseImageSearch, nt as SearchResponse, p as CallOptions, s as AccountUsage, t as Adapter } from "./adapter-B8kAAAgF.js";
2
- import "./util-DhYr1OS3.js";
1
+ import { a as RawClient, t as Adapter } from "./adapter-J2yatZJ0.js";
2
+ import { J as Recency, P as MatchKind, Q as SearchResponse, X as ReverseImageSearch, j as ImageSearch, l as CallOptions, r as AccountUsage } from "./errors-gMtejKHc.js";
3
3
  /** Settings for `serpapi()`. */
4
4
  interface SerpApiConfig {
5
5
  /** Defaults to the SERPAPI_API_KEY environment variable. */
@@ -250,7 +250,7 @@ interface SerpApiOperations {
250
250
  usage: (options?: CallOptions) => Promise<AccountUsage>;
251
251
  }
252
252
  /**
253
- * An adapter for SerpApi: search, images, reverse image and usage. Pass it to `new Fieldwork({ adapter })`.
253
+ * An adapter for SerpApi: search, images, reverse image and usage. Pass it to `fieldwork({ adapter })`.
254
254
  *
255
255
  * Throws `Unauthorized` when neither `apiKey` nor `SERPAPI_API_KEY` is set.
256
256
  */