11package firecrawl
22
3+ import "encoding/json"
4+
5+ // QueryFormatMode selects how query answers are generated.
6+ type QueryFormatMode string
7+
8+ const (
9+ QueryModeFreeform QueryFormatMode = "freeform"
10+ QueryModeDirectQuote QueryFormatMode = "directQuote"
11+ )
12+
13+ // QueryFormat asks a question about page content.
14+ type QueryFormat struct {
15+ Prompt string `json:"prompt"`
16+ Mode QueryFormatMode `json:"mode,omitempty"`
17+ }
18+
19+ // MarshalJSON always emits the API-required query format type.
20+ func (q QueryFormat ) MarshalJSON () ([]byte , error ) {
21+ type queryFormat struct {
22+ Type string `json:"type"`
23+ Prompt string `json:"prompt"`
24+ Mode QueryFormatMode `json:"mode,omitempty"`
25+ }
26+
27+ return json .Marshal (queryFormat {
28+ Type : "query" ,
29+ Prompt : q .Prompt ,
30+ Mode : q .Mode ,
31+ })
32+ }
33+
334// ScrapeOptions configures a single-page scrape request.
435type ScrapeOptions struct {
5- Formats []string `json:"formats,omitempty"`
36+ Formats []string `json:"-"`
37+ FormatOptions []interface {} `json:"-"`
638 Headers map [string ]string `json:"headers,omitempty"`
739 IncludeTags []string `json:"includeTags,omitempty"`
840 ExcludeTags []string `json:"excludeTags,omitempty"`
@@ -24,6 +56,25 @@ type ScrapeOptions struct {
2456 JsonOptions * JsonOptions `json:"jsonOptions,omitempty"`
2557}
2658
59+ // MarshalJSON preserves string formats while allowing object formats such as QueryFormat.
60+ func (o ScrapeOptions ) MarshalJSON () ([]byte , error ) {
61+ type scrapeOptions ScrapeOptions
62+ payload := struct {
63+ scrapeOptions
64+ Formats interface {} `json:"formats,omitempty"`
65+ }{
66+ scrapeOptions : scrapeOptions (o ),
67+ }
68+
69+ if len (o .FormatOptions ) > 0 {
70+ payload .Formats = o .FormatOptions
71+ } else if len (o .Formats ) > 0 {
72+ payload .Formats = o .Formats
73+ }
74+
75+ return json .Marshal (payload )
76+ }
77+
2778// CrawlOptions configures a crawl request.
2879type CrawlOptions struct {
2980 Prompt * string `json:"prompt,omitempty"`
@@ -34,7 +85,7 @@ type CrawlOptions struct {
3485 IgnoreQueryParameters * bool `json:"ignoreQueryParameters,omitempty"`
3586 DeduplicateSimilarURLs * bool `json:"deduplicateSimilarURLs,omitempty"`
3687 Limit * int `json:"limit,omitempty"`
37- CrawlEntireDomain * bool `json:"crawlEntireDomain,omitempty"`
88+ CrawlEntireDomain * bool `json:"crawlEntireDomain,omitempty"`
3889 AllowExternalLinks * bool `json:"allowExternalLinks,omitempty"`
3990 AllowSubdomains * bool `json:"allowSubdomains,omitempty"`
4091 Delay * int `json:"delay,omitempty"`
@@ -87,14 +138,14 @@ type SearchOptions struct {
87138
88139// AgentOptions configures an agent request.
89140type AgentOptions struct {
90- URLs []string `json:"urls,omitempty"`
91- Prompt string `json:"prompt"`
92- Schema map [string ]interface {} `json:"schema,omitempty"`
93- Integration * string `json:"integration,omitempty"`
94- MaxCredits * int `json:"maxCredits,omitempty"`
95- StrictConstrainToURLs * bool `json:"strictConstrainToURLs,omitempty"`
96- Model * string `json:"model,omitempty"`
97- Webhook * WebhookConfig `json:"webhook,omitempty"`
141+ URLs []string `json:"urls,omitempty"`
142+ Prompt string `json:"prompt"`
143+ Schema map [string ]interface {} `json:"schema,omitempty"`
144+ Integration * string `json:"integration,omitempty"`
145+ MaxCredits * int `json:"maxCredits,omitempty"`
146+ StrictConstrainToURLs * bool `json:"strictConstrainToURLs,omitempty"`
147+ Model * string `json:"model,omitempty"`
148+ Webhook * WebhookConfig `json:"webhook,omitempty"`
98149}
99150
100151// LocationConfig specifies geolocation for requests.
0 commit comments