@@ -83,6 +83,20 @@ final class CrawlStartParams implements BaseModel
8383 #[Api(optional: true )]
8484 public ?bool $ sitemap ;
8585
86+ /**
87+ * `new CrawlStartParams()` is missing required properties by the API.
88+ *
89+ * To enforce required parameters use
90+ * ```
91+ * CrawlStartParams::with(url: ...)
92+ * ```
93+ *
94+ * Otherwise ensure the following setters are called
95+ *
96+ * ```
97+ * (new CrawlStartParams)->withURL(...)
98+ * ```
99+ */
86100 public function __construct ()
87101 {
88102 self ::introspect ();
@@ -94,7 +108,7 @@ public function __construct()
94108 *
95109 * You must use named parameters to construct any parameters with a default value.
96110 */
97- public static function from (
111+ public static function with (
98112 string $ url ,
99113 ?int $ depth = null ,
100114 ?bool $ extractionMode = null ,
@@ -124,87 +138,96 @@ public static function from(
124138 /**
125139 * Starting URL for crawling.
126140 */
127- public function setURL (string $ url ): self
141+ public function withURL (string $ url ): self
128142 {
129- $ this ->url = $ url ;
143+ $ obj = clone $ this ;
144+ $ obj ->url = $ url ;
130145
131- return $ this ;
146+ return $ obj ;
132147 }
133148
134149 /**
135150 * Maximum crawl depth from starting URL.
136151 */
137- public function setDepth (int $ depth ): self
152+ public function withDepth (int $ depth ): self
138153 {
139- $ this ->depth = $ depth ;
154+ $ obj = clone $ this ;
155+ $ obj ->depth = $ depth ;
140156
141- return $ this ;
157+ return $ obj ;
142158 }
143159
144160 /**
145161 * Use AI extraction (true) or markdown conversion (false).
146162 */
147- public function setExtractionMode (bool $ extractionMode ): self
163+ public function withExtractionMode (bool $ extractionMode ): self
148164 {
149- $ this ->extractionMode = $ extractionMode ;
165+ $ obj = clone $ this ;
166+ $ obj ->extractionMode = $ extractionMode ;
150167
151- return $ this ;
168+ return $ obj ;
152169 }
153170
154171 /**
155172 * Maximum number of pages to crawl.
156173 */
157- public function setMaxPages (int $ maxPages ): self
174+ public function withMaxPages (int $ maxPages ): self
158175 {
159- $ this ->maxPages = $ maxPages ;
176+ $ obj = clone $ this ;
177+ $ obj ->maxPages = $ maxPages ;
160178
161- return $ this ;
179+ return $ obj ;
162180 }
163181
164182 /**
165183 * Extraction prompt (required if extraction_mode is true).
166184 */
167- public function setPrompt (?string $ prompt ): self
185+ public function withPrompt (?string $ prompt ): self
168186 {
169- $ this ->prompt = $ prompt ;
187+ $ obj = clone $ this ;
188+ $ obj ->prompt = $ prompt ;
170189
171- return $ this ;
190+ return $ obj ;
172191 }
173192
174193 /**
175194 * Enable heavy JavaScript rendering.
176195 */
177- public function setRenderHeavyJs (bool $ renderHeavyJs ): self
196+ public function withRenderHeavyJs (bool $ renderHeavyJs ): self
178197 {
179- $ this ->renderHeavyJs = $ renderHeavyJs ;
198+ $ obj = clone $ this ;
199+ $ obj ->renderHeavyJs = $ renderHeavyJs ;
180200
181- return $ this ;
201+ return $ obj ;
182202 }
183203
184- public function setRules (Rules $ rules ): self
204+ public function withRules (Rules $ rules ): self
185205 {
186- $ this ->rules = $ rules ;
206+ $ obj = clone $ this ;
207+ $ obj ->rules = $ rules ;
187208
188- return $ this ;
209+ return $ obj ;
189210 }
190211
191212 /**
192213 * Output schema for extraction.
193214 */
194- public function setSchema (mixed $ schema ): self
215+ public function withSchema (mixed $ schema ): self
195216 {
196- $ this ->schema = $ schema ;
217+ $ obj = clone $ this ;
218+ $ obj ->schema = $ schema ;
197219
198- return $ this ;
220+ return $ obj ;
199221 }
200222
201223 /**
202224 * Use sitemap for crawling.
203225 */
204- public function setSitemap (bool $ sitemap ): self
226+ public function withSitemap (bool $ sitemap ): self
205227 {
206- $ this ->sitemap = $ sitemap ;
228+ $ obj = clone $ this ;
229+ $ obj ->sitemap = $ sitemap ;
207230
208- return $ this ;
231+ return $ obj ;
209232 }
210233}
0 commit comments