diff --git a/.release-please-manifest.json b/.release-please-manifest.json index d0ab664..2a8f4ff 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "1.2.0" + ".": "1.3.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index e34b116..9dc6067 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ configured_endpoints: 25 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-4903d5902cec6a80f42b9adaa9cf0defa9805ff22d7ae96970d209a4f867e195.yml -openapi_spec_hash: 1097891c23530dfe0155f23170daf973 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-d3da262409c68576e457536f6c0e7ecc538219e0af19df415111c18f8fe92cfd.yml +openapi_spec_hash: 25009575202702d24bc6672472eb8506 config_hash: c7b0cdaba3b9797b77efd89e1754d803 diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b03d82..d98c81a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 1.3.0 (2026-06-26) + +Full Changelog: [v1.2.0...v1.3.0](https://github.com/context-dot-dev/context-php-sdk/compare/v1.2.0...v1.3.0) + +### Features + +* **api:** api update ([df50f08](https://github.com/context-dot-dev/context-php-sdk/commit/df50f08fb5e0eb21378598088d745bc3ebd6b1dd)) +* **api:** api update ([8d1b848](https://github.com/context-dot-dev/context-php-sdk/commit/8d1b84827184cc37a49fa3c532e21c16fa7dbc47)) + ## 1.2.0 (2026-06-25) Full Changelog: [v1.1.0...v1.2.0](https://github.com/context-dot-dev/context-php-sdk/compare/v1.1.0...v1.2.0) diff --git a/README.md b/README.md index ee10b94..bf4e14c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The REST API documentation can be found on [docs.context.dev](https://docs.conte ``` -composer require "context-dev/context-dev-php 1.2.0" +composer require "context-dev/context-dev-php 1.3.0" ``` diff --git a/src/ServiceContracts/WebContract.php b/src/ServiceContracts/WebContract.php index b6b0288..14a1f55 100644 --- a/src/ServiceContracts/WebContract.php +++ b/src/ServiceContracts/WebContract.php @@ -11,6 +11,7 @@ use ContextDev\Web\WebExtractParams\Pdf; use ContextDev\Web\WebExtractResponse; use ContextDev\Web\WebExtractStyleguideResponse; +use ContextDev\Web\WebScreenshotParams\Country; use ContextDev\Web\WebScreenshotParams\FullScreenshot; use ContextDev\Web\WebScreenshotParams\HandleCookiePopup; use ContextDev\Web\WebScreenshotParams\Page; @@ -133,6 +134,7 @@ public function extractStyleguide( /** * @api * + * @param Country|value-of $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param string $directURL A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both. * @param string $domain Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both. * @param FullScreenshot|value-of $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view). @@ -148,6 +150,7 @@ public function extractStyleguide( * @throws APIException */ public function screenshot( + Country|string|null $country = null, ?string $directURL = null, ?string $domain = null, FullScreenshot|string|null $fullScreenshot = null, @@ -164,11 +167,13 @@ public function screenshot( /** * @api * - * @param string $query natural-language search query + * @param string $query Search query. Accepts natural language as well as Google-style search operators such as `site:`, `-site:`, `inurl:`, `intitle:`, quoted phrases, and `OR`. + * @param \ContextDev\Web\WebSearchParams\Country|value-of<\ContextDev\Web\WebSearchParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code to localize results to a specific country (maps to Google's `gl` parameter). Example: "us", "gb", "de". * @param list $excludeDomains Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"]. * @param Freshness|value-of $freshness restrict results to content published within this window * @param list $includeDomains Allowlist — only return results from these domains. Example: ["arxiv.org", "github.com"]. * @param MarkdownOptions|MarkdownOptionsShape $markdownOptions Inline Markdown scraping for each result. Set `enabled: true` to activate. + * @param int $numResults Number of results to request and return (10–100). Defaults to 10. * @param bool $queryFanout expand the query into multiple parallel variants for broader recall * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). * @param RequestOpts|null $requestOptions @@ -177,10 +182,12 @@ public function screenshot( */ public function search( string $query, + \ContextDev\Web\WebSearchParams\Country|string|null $country = null, ?array $excludeDomains = null, Freshness|string|null $freshness = null, ?array $includeDomains = null, MarkdownOptions|array|null $markdownOptions = null, + int $numResults = 10, ?bool $queryFanout = null, ?int $timeoutMs = null, RequestOptions|array|null $requestOptions = null, @@ -190,6 +197,7 @@ public function search( * @api * * @param string $url The starting URL for the crawl (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebCrawlMdParams\Country|value-of<\ContextDev\Web\WebWebCrawlMdParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param bool $followSubdomains When true, follow links on subdomains of the starting URL's domain (e.g. docs.example.com when starting from example.com). www and apex are always treated as equivalent. * @param bool $includeFrames when true, the contents of iframes are rendered to Markdown for each crawled page @@ -212,6 +220,7 @@ public function search( */ public function webCrawlMd( string $url, + \ContextDev\Web\WebWebCrawlMdParams\Country|string|null $country = null, ?array $excludeSelectors = null, bool $followSubdomains = false, bool $includeFrames = false, @@ -237,6 +246,7 @@ public function webCrawlMd( * @api * * @param string $url Full URL to scrape (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebScrapeHTMLParams\Country|value-of<\ContextDev\Web\WebWebScrapeHTMLParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param bool $includeFrames when true, iframes are rendered inline into the returned HTML @@ -252,6 +262,7 @@ public function webCrawlMd( */ public function webScrapeHTML( string $url, + \ContextDev\Web\WebWebScrapeHTMLParams\Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, bool $includeFrames = false, @@ -293,6 +304,7 @@ public function webScrapeImages( * @api * * @param string $url Full URL to scrape into LLM usable Markdown (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebScrapeMdParams\Country|value-of<\ContextDev\Web\WebWebScrapeMdParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param bool $includeFrames when true, the contents of iframes are rendered to Markdown @@ -311,6 +323,7 @@ public function webScrapeImages( */ public function webScrapeMd( string $url, + \ContextDev\Web\WebWebScrapeMdParams\Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, bool $includeFrames = false, diff --git a/src/Services/WebRawService.php b/src/Services/WebRawService.php index c6f0459..6505344 100644 --- a/src/Services/WebRawService.php +++ b/src/Services/WebRawService.php @@ -20,6 +20,7 @@ use ContextDev\Web\WebExtractStyleguideParams; use ContextDev\Web\WebExtractStyleguideResponse; use ContextDev\Web\WebScreenshotParams; +use ContextDev\Web\WebScreenshotParams\Country; use ContextDev\Web\WebScreenshotParams\FullScreenshot; use ContextDev\Web\WebScreenshotParams\HandleCookiePopup; use ContextDev\Web\WebScreenshotParams\Page; @@ -215,6 +216,7 @@ public function extractStyleguide( * Capture a screenshot of a website. * * @param array{ + * country?: value-of, * directURL?: string, * domain?: string, * fullScreenshot?: FullScreenshot|value-of, @@ -261,10 +263,12 @@ public function screenshot( * * @param array{ * query: string, + * country?: value-of, * excludeDomains?: list, * freshness?: Freshness|value-of, * includeDomains?: list, * markdownOptions?: MarkdownOptions|MarkdownOptionsShape, + * numResults?: int, * queryFanout?: bool, * timeoutMs?: int, * }|WebSearchParams $params @@ -300,6 +304,7 @@ public function search( * * @param array{ * url: string, + * country?: value-of, * excludeSelectors?: list, * followSubdomains?: bool, * includeFrames?: bool, @@ -349,6 +354,7 @@ public function webCrawlMd( * * @param array{ * url: string, + * country?: value-of, * excludeSelectors?: list, * headers?: array, * includeFrames?: bool, @@ -429,6 +435,7 @@ public function webScrapeImages( * * @param array{ * url: string, + * country?: value-of, * excludeSelectors?: list, * headers?: array, * includeFrames?: bool, diff --git a/src/Services/WebService.php b/src/Services/WebService.php index 224efa2..84a997a 100644 --- a/src/Services/WebService.php +++ b/src/Services/WebService.php @@ -14,6 +14,7 @@ use ContextDev\Web\WebExtractParams\Pdf; use ContextDev\Web\WebExtractResponse; use ContextDev\Web\WebExtractStyleguideResponse; +use ContextDev\Web\WebScreenshotParams\Country; use ContextDev\Web\WebScreenshotParams\FullScreenshot; use ContextDev\Web\WebScreenshotParams\HandleCookiePopup; use ContextDev\Web\WebScreenshotParams\Page; @@ -223,6 +224,7 @@ public function extractStyleguide( * * Capture a screenshot of a website. * + * @param Country|value-of $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param string $directURL A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both. * @param string $domain Domain name to take screenshot of (e.g., 'example.com', 'google.com'). The domain will be automatically normalized and validated. You must provide either 'domain' or 'directUrl', but not both. * @param FullScreenshot|value-of $fullScreenshot Optional parameter to determine screenshot type. If 'true', takes a full page screenshot capturing all content. If 'false' or not provided, takes a viewport screenshot (standard browser view). @@ -238,6 +240,7 @@ public function extractStyleguide( * @throws APIException */ public function screenshot( + Country|string|null $country = null, ?string $directURL = null, ?string $domain = null, FullScreenshot|string|null $fullScreenshot = null, @@ -252,6 +255,7 @@ public function screenshot( ): WebScreenshotResponse { $params = Util::removeNulls( [ + 'country' => $country, 'directURL' => $directURL, 'domain' => $domain, 'fullScreenshot' => $fullScreenshot, @@ -276,11 +280,13 @@ public function screenshot( * * Search the web and optionally scrape each result to Markdown in one round-trip. * - * @param string $query natural-language search query + * @param string $query Search query. Accepts natural language as well as Google-style search operators such as `site:`, `-site:`, `inurl:`, `intitle:`, quoted phrases, and `OR`. + * @param \ContextDev\Web\WebSearchParams\Country|value-of<\ContextDev\Web\WebSearchParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code to localize results to a specific country (maps to Google's `gl` parameter). Example: "us", "gb", "de". * @param list $excludeDomains Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"]. * @param Freshness|value-of $freshness restrict results to content published within this window * @param list $includeDomains Allowlist — only return results from these domains. Example: ["arxiv.org", "github.com"]. * @param MarkdownOptions|MarkdownOptionsShape $markdownOptions Inline Markdown scraping for each result. Set `enabled: true` to activate. + * @param int $numResults Number of results to request and return (10–100). Defaults to 10. * @param bool $queryFanout expand the query into multiple parallel variants for broader recall * @param int $timeoutMs Optional timeout in milliseconds for the request. If the request takes longer than this value, it will be aborted with a 408 status code. Maximum allowed value is 300000ms (5 minutes). * @param RequestOpts|null $requestOptions @@ -289,10 +295,12 @@ public function screenshot( */ public function search( string $query, + \ContextDev\Web\WebSearchParams\Country|string|null $country = null, ?array $excludeDomains = null, Freshness|string|null $freshness = null, ?array $includeDomains = null, MarkdownOptions|array|null $markdownOptions = null, + int $numResults = 10, ?bool $queryFanout = null, ?int $timeoutMs = null, RequestOptions|array|null $requestOptions = null, @@ -300,10 +308,12 @@ public function search( $params = Util::removeNulls( [ 'query' => $query, + 'country' => $country, 'excludeDomains' => $excludeDomains, 'freshness' => $freshness, 'includeDomains' => $includeDomains, 'markdownOptions' => $markdownOptions, + 'numResults' => $numResults, 'queryFanout' => $queryFanout, 'timeoutMs' => $timeoutMs, ], @@ -321,6 +331,7 @@ public function search( * Performs a crawl starting from a given URL, extracts page content as Markdown, and returns results for all crawled pages. * * @param string $url The starting URL for the crawl (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebCrawlMdParams\Country|value-of<\ContextDev\Web\WebWebCrawlMdParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param bool $followSubdomains When true, follow links on subdomains of the starting URL's domain (e.g. docs.example.com when starting from example.com). www and apex are always treated as equivalent. * @param bool $includeFrames when true, the contents of iframes are rendered to Markdown for each crawled page @@ -343,6 +354,7 @@ public function search( */ public function webCrawlMd( string $url, + \ContextDev\Web\WebWebCrawlMdParams\Country|string|null $country = null, ?array $excludeSelectors = null, bool $followSubdomains = false, bool $includeFrames = false, @@ -366,6 +378,7 @@ public function webCrawlMd( $params = Util::removeNulls( [ 'url' => $url, + 'country' => $country, 'excludeSelectors' => $excludeSelectors, 'followSubdomains' => $followSubdomains, 'includeFrames' => $includeFrames, @@ -397,6 +410,7 @@ public function webCrawlMd( * Scrapes the given URL and returns the raw HTML content of the page. * * @param string $url Full URL to scrape (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebScrapeHTMLParams\Country|value-of<\ContextDev\Web\WebWebScrapeHTMLParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param bool $includeFrames when true, iframes are rendered inline into the returned HTML @@ -412,6 +426,7 @@ public function webCrawlMd( */ public function webScrapeHTML( string $url, + \ContextDev\Web\WebWebScrapeHTMLParams\Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, bool $includeFrames = false, @@ -428,6 +443,7 @@ public function webScrapeHTML( $params = Util::removeNulls( [ 'url' => $url, + 'country' => $country, 'excludeSelectors' => $excludeSelectors, 'headers' => $headers, 'includeFrames' => $includeFrames, @@ -493,6 +509,7 @@ public function webScrapeImages( * Scrapes the given URL into LLM usable Markdown. * * @param string $url Full URL to scrape into LLM usable Markdown (must include http:// or https:// protocol) + * @param \ContextDev\Web\WebWebScrapeMdParams\Country|value-of<\ContextDev\Web\WebWebScrapeMdParams\Country> $country Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. * @param list $excludeSelectors CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @param array $headers Optional outbound HTTP headers forwarded only to the target URL, sent as deep-object query params such as headers[X-Custom]=value. When provided, caching is bypassed: the result is neither read from nor written to cache. * @param bool $includeFrames when true, the contents of iframes are rendered to Markdown @@ -511,6 +528,7 @@ public function webScrapeImages( */ public function webScrapeMd( string $url, + \ContextDev\Web\WebWebScrapeMdParams\Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, bool $includeFrames = false, @@ -530,6 +548,7 @@ public function webScrapeMd( $params = Util::removeNulls( [ 'url' => $url, + 'country' => $country, 'excludeSelectors' => $excludeSelectors, 'headers' => $headers, 'includeFrames' => $includeFrames, diff --git a/src/Version.php b/src/Version.php index 664fee6..348143f 100644 --- a/src/Version.php +++ b/src/Version.php @@ -5,5 +5,5 @@ namespace ContextDev; // x-release-please-start-version -const VERSION = '1.2.0'; +const VERSION = '1.3.0'; // x-release-please-end diff --git a/src/Web/WebScreenshotParams.php b/src/Web/WebScreenshotParams.php index 56d3b65..e0385ee 100644 --- a/src/Web/WebScreenshotParams.php +++ b/src/Web/WebScreenshotParams.php @@ -8,6 +8,7 @@ use ContextDev\Core\Concerns\SdkModel; use ContextDev\Core\Concerns\SdkParams; use ContextDev\Core\Contracts\BaseModel; +use ContextDev\Web\WebScreenshotParams\Country; use ContextDev\Web\WebScreenshotParams\FullScreenshot; use ContextDev\Web\WebScreenshotParams\HandleCookiePopup; use ContextDev\Web\WebScreenshotParams\Page; @@ -21,6 +22,7 @@ * @phpstan-import-type ViewportShape from \ContextDev\Web\WebScreenshotParams\Viewport * * @phpstan-type WebScreenshotParamsShape = array{ + * country?: null|Country|value-of, * directURL?: string|null, * domain?: string|null, * fullScreenshot?: null|FullScreenshot|value-of, @@ -39,6 +41,14 @@ final class WebScreenshotParams implements BaseModel use SdkModel; use SdkParams; + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + /** * A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both. */ @@ -115,12 +125,14 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param Country|value-of|null $country * @param FullScreenshot|value-of|null $fullScreenshot * @param HandleCookiePopup|value-of|null $handleCookiePopup * @param Page|value-of|null $page * @param Viewport|ViewportShape|null $viewport */ public static function with( + Country|string|null $country = null, ?string $directURL = null, ?string $domain = null, FullScreenshot|string|null $fullScreenshot = null, @@ -134,6 +146,7 @@ public static function with( ): self { $self = new self; + null !== $country && $self['country'] = $country; null !== $directURL && $self['directURL'] = $directURL; null !== $domain && $self['domain'] = $domain; null !== $fullScreenshot && $self['fullScreenshot'] = $fullScreenshot; @@ -148,6 +161,19 @@ public static function with( return $self; } + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + /** * A specific URL to screenshot directly, bypassing domain resolution (e.g., 'https://example.com/pricing'). When provided, the screenshot is taken of this exact URL. You must provide either 'domain' or 'directUrl', but not both. */ diff --git a/src/Web/WebScreenshotParams/Country.php b/src/Web/WebScreenshotParams/Country.php new file mode 100644 index 0000000..912e435 --- /dev/null +++ b/src/Web/WebScreenshotParams/Country.php @@ -0,0 +1,419 @@ +, * excludeDomains?: list|null, * freshness?: null|Freshness|value-of, * includeDomains?: list|null, * markdownOptions?: null|MarkdownOptions|MarkdownOptionsShape, + * numResults?: int|null, * queryFanout?: bool|null, * timeoutMs?: int|null, * } @@ -36,11 +39,19 @@ final class WebSearchParams implements BaseModel use SdkParams; /** - * Natural-language search query. + * Search query. Accepts natural language as well as Google-style search operators such as `site:`, `-site:`, `inurl:`, `intitle:`, quoted phrases, and `OR`. */ #[Required] public string $query; + /** + * Two-letter ISO 3166-1 alpha-2 country code to localize results to a specific country (maps to Google's `gl` parameter). Example: "us", "gb", "de". + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + /** * Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"]. * @@ -71,6 +82,12 @@ final class WebSearchParams implements BaseModel #[Optional] public ?MarkdownOptions $markdownOptions; + /** + * Number of results to request and return (10–100). Defaults to 10. + */ + #[Optional] + public ?int $numResults; + /** * Expand the query into multiple parallel variants for broader recall. */ @@ -107,6 +124,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param Country|value-of|null $country * @param list|null $excludeDomains * @param Freshness|value-of|null $freshness * @param list|null $includeDomains @@ -114,10 +132,12 @@ public function __construct() */ public static function with( string $query, + Country|string|null $country = null, ?array $excludeDomains = null, Freshness|string|null $freshness = null, ?array $includeDomains = null, MarkdownOptions|array|null $markdownOptions = null, + ?int $numResults = null, ?bool $queryFanout = null, ?int $timeoutMs = null, ): self { @@ -125,10 +145,12 @@ public static function with( $self['query'] = $query; + null !== $country && $self['country'] = $country; null !== $excludeDomains && $self['excludeDomains'] = $excludeDomains; null !== $freshness && $self['freshness'] = $freshness; null !== $includeDomains && $self['includeDomains'] = $includeDomains; null !== $markdownOptions && $self['markdownOptions'] = $markdownOptions; + null !== $numResults && $self['numResults'] = $numResults; null !== $queryFanout && $self['queryFanout'] = $queryFanout; null !== $timeoutMs && $self['timeoutMs'] = $timeoutMs; @@ -136,7 +158,7 @@ public static function with( } /** - * Natural-language search query. + * Search query. Accepts natural language as well as Google-style search operators such as `site:`, `-site:`, `inurl:`, `intitle:`, quoted phrases, and `OR`. */ public function withQuery(string $query): self { @@ -146,6 +168,19 @@ public function withQuery(string $query): self return $self; } + /** + * Two-letter ISO 3166-1 alpha-2 country code to localize results to a specific country (maps to Google's `gl` parameter). Example: "us", "gb", "de". + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + /** * Blocklist — drop results from these domains. Example: ["pinterest.com", "reddit.com"]. * @@ -199,6 +234,17 @@ public function withMarkdownOptions( return $self; } + /** + * Number of results to request and return (10–100). Defaults to 10. + */ + public function withNumResults(int $numResults): self + { + $self = clone $this; + $self['numResults'] = $numResults; + + return $self; + } + /** * Expand the query into multiple parallel variants for broader recall. */ diff --git a/src/Web/WebSearchParams/Country.php b/src/Web/WebSearchParams/Country.php new file mode 100644 index 0000000..4b7a183 --- /dev/null +++ b/src/Web/WebSearchParams/Country.php @@ -0,0 +1,489 @@ +, * excludeSelectors?: list|null, * followSubdomains?: bool|null, * includeFrames?: bool|null, @@ -50,6 +52,14 @@ final class WebWebCrawlMdParams implements BaseModel #[Required] public string $url; + /** + * Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country. + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + /** * CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @@ -174,12 +184,14 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param Country|value-of|null $country * @param list|null $excludeSelectors * @param list|null $includeSelectors * @param Pdf|PdfShape|null $pdf */ public static function with( string $url, + Country|string|null $country = null, ?array $excludeSelectors = null, ?bool $followSubdomains = null, ?bool $includeFrames = null, @@ -201,6 +213,7 @@ public static function with( $self['url'] = $url; + null !== $country && $self['country'] = $country; null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; null !== $followSubdomains && $self['followSubdomains'] = $followSubdomains; null !== $includeFrames && $self['includeFrames'] = $includeFrames; @@ -232,6 +245,19 @@ public function withURL(string $url): self return $self; } + /** + * Two-letter ISO 3166-1 alpha-2 country code identifying a supported Context.dev residential proxy exit location. Must be one of Context.dev's supported countries. When provided, Context.dev fetches the target page from that country. + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + /** * CSS selectors to remove before each crawled page is converted to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * diff --git a/src/Web/WebWebCrawlMdParams/Country.php b/src/Web/WebWebCrawlMdParams/Country.php new file mode 100644 index 0000000..e3c0594 --- /dev/null +++ b/src/Web/WebWebCrawlMdParams/Country.php @@ -0,0 +1,419 @@ +, * excludeSelectors?: list|null, * headers?: array|null, * includeFrames?: bool|null, @@ -43,6 +45,14 @@ final class WebWebScrapeHTMLParams implements BaseModel #[Required] public string $url; + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + /** * CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @@ -127,6 +137,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param Country|value-of|null $country * @param list|null $excludeSelectors * @param array|null $headers * @param list|null $includeSelectors @@ -134,6 +145,7 @@ public function __construct() */ public static function with( string $url, + Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, ?bool $includeFrames = null, @@ -148,6 +160,7 @@ public static function with( $self['url'] = $url; + null !== $country && $self['country'] = $country; null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; null !== $headers && $self['headers'] = $headers; null !== $includeFrames && $self['includeFrames'] = $includeFrames; @@ -172,6 +185,19 @@ public function withURL(string $url): self return $self; } + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + /** * CSS selectors to remove from the result. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * diff --git a/src/Web/WebWebScrapeHTMLParams/Country.php b/src/Web/WebWebScrapeHTMLParams/Country.php new file mode 100644 index 0000000..6c784e4 --- /dev/null +++ b/src/Web/WebWebScrapeHTMLParams/Country.php @@ -0,0 +1,419 @@ +, * excludeSelectors?: list|null, * headers?: array|null, * includeFrames?: bool|null, @@ -46,6 +48,14 @@ final class WebWebScrapeMdParams implements BaseModel #[Required] public string $url; + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @var value-of|null $country + */ + #[Optional(enum: Country::class)] + public ?string $country; + /** * CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * @@ -148,6 +158,7 @@ public function __construct() * * You must use named parameters to construct any parameters with a default value. * + * @param Country|value-of|null $country * @param list|null $excludeSelectors * @param array|null $headers * @param list|null $includeSelectors @@ -155,6 +166,7 @@ public function __construct() */ public static function with( string $url, + Country|string|null $country = null, ?array $excludeSelectors = null, ?array $headers = null, ?bool $includeFrames = null, @@ -172,6 +184,7 @@ public static function with( $self['url'] = $url; + null !== $country && $self['country'] = $country; null !== $excludeSelectors && $self['excludeSelectors'] = $excludeSelectors; null !== $headers && $self['headers'] = $headers; null !== $includeFrames && $self['includeFrames'] = $includeFrames; @@ -199,6 +212,19 @@ public function withURL(string $url): self return $self; } + /** + * Two-letter ISO 3166-1 alpha-2 country code for the website request location. When provided, Context.dev fetches the target page from that country. + * + * @param Country|value-of $country + */ + public function withCountry(Country|string $country): self + { + $self = clone $this; + $self['country'] = $country; + + return $self; + } + /** * CSS selectors to remove before conversion to Markdown. Applied after includeSelectors. Exclusion takes precedence: an element matching both is removed. Examples: "nav", "footer", ".ad-banner", "[aria-hidden=true]". * diff --git a/src/Web/WebWebScrapeMdParams/Country.php b/src/Web/WebWebScrapeMdParams/Country.php new file mode 100644 index 0000000..3d1460e --- /dev/null +++ b/src/Web/WebWebScrapeMdParams/Country.php @@ -0,0 +1,419 @@ +client->web->search( query: 'x', + country: 'af', excludeDomains: ['string'], freshness: 'last_24_hours', includeDomains: ['string'], @@ -197,6 +198,7 @@ public function testSearchWithOptionalParams(): void 'useMainContentOnly' => true, 'waitForMs' => 0, ], + numResults: 10, queryFanout: true, timeoutMs: 1000, ); @@ -227,6 +229,7 @@ public function testWebCrawlMdWithOptionalParams(): void $result = $this->client->web->webCrawlMd( url: 'https://example.com', + country: 'de', excludeSelectors: ['string'], followSubdomains: true, includeFrames: true, @@ -271,6 +274,7 @@ public function testWebScrapeHTMLWithOptionalParams(): void $result = $this->client->web->webScrapeHTML( url: 'https://example.com', + country: 'de', excludeSelectors: ['string'], headers: ['foo' => 'J!'], includeFrames: true, @@ -346,6 +350,7 @@ public function testWebScrapeMdWithOptionalParams(): void $result = $this->client->web->webScrapeMd( url: 'https://example.com', + country: 'de', excludeSelectors: ['string'], headers: ['foo' => 'J!'], includeFrames: true,