Skip to content

Commit 8cce45f

Browse files
author
stlc-bot
committed
feat(answers): limit research to listed sources with controls (#3252)
Stainless-Generated-From: d089a466cacb294a63ae44a8e73cad287f535a4c
1 parent 20fa936 commit 8cce45f

6 files changed

Lines changed: 127 additions & 0 deletions

File tree

‎src/ServiceContracts/WebContract.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ContextDev\Core\Exceptions\APIException;
88
use ContextDev\RequestOptions;
9+
use ContextDev\Web\WebAnswersParams\Controls;
910
use ContextDev\Web\WebAnswersParams\Mode;
1011
use ContextDev\Web\WebAnswersParams\TimeoutOpts;
1112
use ContextDev\Web\WebAnswersParams\Zdr;
@@ -39,6 +40,7 @@
3940
use ContextDev\Web\WebWebCrawlMdResponse;
4041

4142
/**
43+
* @phpstan-import-type ControlsShape from \ContextDev\Web\WebAnswersParams\Controls
4244
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebAnswersParams\TimeoutOpts
4345
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractCompetitorsParams\TimeoutOpts as TimeoutOptsShape1
4446
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractStyleguideParams\TimeoutOpts as TimeoutOptsShape2
@@ -69,6 +71,7 @@ interface WebContract
6971
* @api
7072
*
7173
* @param string $task Research task, up to 2000 characters. The agent selects company/profile lookups, web searches, or page reads. Include domains or URLs to focus the research.
74+
* @param Controls|ControlsShape $controls limits what the research may use
7275
* @param array<string,mixed> $jsonFormat Example answer object, not JSON Schema. Up to 8 levels, 500 values, and 16000 characters; unknowns may be null.
7376
* @param Mode|value-of<Mode> $mode `fast` prioritizes speed, with extra verification for people and companies; `ultra` supports deeper research (default)
7477
* @param list<string> $policies Access policy IDs to apply. A URL must pass every policy. Leave it out unless access policies are enabled for your organization; otherwise the request fails with `ACCESS_POLICIES_NOT_ENABLED`.
@@ -81,6 +84,7 @@ interface WebContract
8184
*/
8285
public function answers(
8386
string $task,
87+
Controls|array|null $controls = null,
8488
?array $jsonFormat = null,
8589
Mode|string|null $mode = null,
8690
?array $policies = null,

‎src/Services/WebRawService.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use ContextDev\RequestOptions;
1212
use ContextDev\ServiceContracts\WebRawContract;
1313
use ContextDev\Web\WebAnswersParams;
14+
use ContextDev\Web\WebAnswersParams\Controls;
1415
use ContextDev\Web\WebAnswersParams\Mode;
1516
use ContextDev\Web\WebAnswersParams\TimeoutOpts;
1617
use ContextDev\Web\WebAnswersParams\Zdr;
@@ -49,6 +50,7 @@
4950
use ContextDev\Web\WebWebCrawlMdResponse;
5051

5152
/**
53+
* @phpstan-import-type ControlsShape from \ContextDev\Web\WebAnswersParams\Controls
5254
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebAnswersParams\TimeoutOpts
5355
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractCompetitorsParams\TimeoutOpts as TimeoutOptsShape1
5456
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractStyleguideParams\TimeoutOpts as TimeoutOptsShape2
@@ -88,6 +90,7 @@ public function __construct(private Client $client) {}
8890
*
8991
* @param array{
9092
* task: string,
93+
* controls?: Controls|ControlsShape,
9194
* jsonFormat?: array<string,mixed>,
9295
* mode?: Mode|value-of<Mode>,
9396
* policies?: list<string>,

‎src/Services/WebService.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ContextDev\Core\Util;
1010
use ContextDev\RequestOptions;
1111
use ContextDev\ServiceContracts\WebContract;
12+
use ContextDev\Web\WebAnswersParams\Controls;
1213
use ContextDev\Web\WebAnswersParams\Mode;
1314
use ContextDev\Web\WebAnswersParams\TimeoutOpts;
1415
use ContextDev\Web\WebAnswersParams\Zdr;
@@ -42,6 +43,7 @@
4243
use ContextDev\Web\WebWebCrawlMdResponse;
4344

4445
/**
46+
* @phpstan-import-type ControlsShape from \ContextDev\Web\WebAnswersParams\Controls
4547
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebAnswersParams\TimeoutOpts
4648
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractCompetitorsParams\TimeoutOpts as TimeoutOptsShape1
4749
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebExtractStyleguideParams\TimeoutOpts as TimeoutOptsShape2
@@ -87,6 +89,7 @@ public function __construct(private Client $client)
8789
* Research the web and return a sourced answer in your JSON shape. Choose `fast` for a short task or `ultra` for deeper research.
8890
*
8991
* @param string $task Research task, up to 2000 characters. The agent selects company/profile lookups, web searches, or page reads. Include domains or URLs to focus the research.
92+
* @param Controls|ControlsShape $controls limits what the research may use
9093
* @param array<string,mixed> $jsonFormat Example answer object, not JSON Schema. Up to 8 levels, 500 values, and 16000 characters; unknowns may be null.
9194
* @param Mode|value-of<Mode> $mode `fast` prioritizes speed, with extra verification for people and companies; `ultra` supports deeper research (default)
9295
* @param list<string> $policies Access policy IDs to apply. A URL must pass every policy. Leave it out unless access policies are enabled for your organization; otherwise the request fails with `ACCESS_POLICIES_NOT_ENABLED`.
@@ -99,6 +102,7 @@ public function __construct(private Client $client)
99102
*/
100103
public function answers(
101104
string $task,
105+
Controls|array|null $controls = null,
102106
?array $jsonFormat = null,
103107
Mode|string|null $mode = null,
104108
?array $policies = null,
@@ -110,6 +114,7 @@ public function answers(
110114
$params = Util::removeNulls(
111115
[
112116
'task' => $task,
117+
'controls' => $controls,
113118
'jsonFormat' => $jsonFormat,
114119
'mode' => $mode,
115120
'policies' => $policies,

‎src/Web/WebAnswersParams.php‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use ContextDev\Core\Concerns\SdkModel;
1010
use ContextDev\Core\Concerns\SdkParams;
1111
use ContextDev\Core\Contracts\BaseModel;
12+
use ContextDev\Web\WebAnswersParams\Controls;
1213
use ContextDev\Web\WebAnswersParams\Mode;
1314
use ContextDev\Web\WebAnswersParams\TimeoutOpts;
1415
use ContextDev\Web\WebAnswersParams\Zdr;
@@ -18,10 +19,12 @@
1819
*
1920
* @see ContextDev\Services\WebService::answers()
2021
*
22+
* @phpstan-import-type ControlsShape from \ContextDev\Web\WebAnswersParams\Controls
2123
* @phpstan-import-type TimeoutOptsShape from \ContextDev\Web\WebAnswersParams\TimeoutOpts
2224
*
2325
* @phpstan-type WebAnswersParamsShape = array{
2426
* task: string,
27+
* controls?: null|Controls|ControlsShape,
2528
* jsonFormat?: array<string,mixed>|null,
2629
* mode?: null|Mode|value-of<Mode>,
2730
* policies?: list<string>|null,
@@ -42,6 +45,12 @@ final class WebAnswersParams implements BaseModel
4245
#[Required]
4346
public string $task;
4447

48+
/**
49+
* Limits what the research may use.
50+
*/
51+
#[Optional]
52+
public ?Controls $controls;
53+
4554
/**
4655
* Example answer object, not JSON Schema. Up to 8 levels, 500 values, and 16000 characters; unknowns may be null.
4756
*
@@ -112,6 +121,7 @@ public function __construct()
112121
*
113122
* You must use named parameters to construct any parameters with a default value.
114123
*
124+
* @param Controls|ControlsShape|null $controls
115125
* @param array<string,mixed>|null $jsonFormat
116126
* @param Mode|value-of<Mode>|null $mode
117127
* @param list<string>|null $policies
@@ -121,6 +131,7 @@ public function __construct()
121131
*/
122132
public static function with(
123133
string $task,
134+
Controls|array|null $controls = null,
124135
?array $jsonFormat = null,
125136
Mode|string|null $mode = null,
126137
?array $policies = null,
@@ -132,6 +143,7 @@ public static function with(
132143

133144
$self['task'] = $task;
134145

146+
null !== $controls && $self['controls'] = $controls;
135147
null !== $jsonFormat && $self['jsonFormat'] = $jsonFormat;
136148
null !== $mode && $self['mode'] = $mode;
137149
null !== $policies && $self['policies'] = $policies;
@@ -153,6 +165,19 @@ public function withTask(string $task): self
153165
return $self;
154166
}
155167

168+
/**
169+
* Limits what the research may use.
170+
*
171+
* @param Controls|ControlsShape $controls
172+
*/
173+
public function withControls(Controls|array $controls): self
174+
{
175+
$self = clone $this;
176+
$self['controls'] = $controls;
177+
178+
return $self;
179+
}
180+
156181
/**
157182
* Example answer object, not JSON Schema. Up to 8 levels, 500 values, and 16000 characters; unknowns may be null.
158183
*
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ContextDev\Web\WebAnswersParams;
6+
7+
use ContextDev\Core\Attributes\Optional;
8+
use ContextDev\Core\Concerns\SdkModel;
9+
use ContextDev\Core\Contracts\BaseModel;
10+
11+
/**
12+
* Limits what the research may use.
13+
*
14+
* @phpstan-type ControlsShape = array{
15+
* excludeSources?: list<string>|null, sources?: list<string>|null
16+
* }
17+
*/
18+
final class Controls implements BaseModel
19+
{
20+
/** @use SdkModel<ControlsShape> */
21+
use SdkModel;
22+
23+
/**
24+
* Never search, read or cite these sites, sections or pages. Same format as `sources`. Up to 100 entries.
25+
*
26+
* @var list<string>|null $excludeSources
27+
*/
28+
#[Optional(list: 'string')]
29+
public ?array $excludeSources;
30+
31+
/**
32+
* Only search, read and cite these sites, sections or pages. Each entry is a URL prefix: "example.com" covers the site and its subdomains, "example.com/docs" covers that section, and "example.com/docs/setup.html" is one page. Up to 20 entries.
33+
*
34+
* @var list<string>|null $sources
35+
*/
36+
#[Optional(list: 'string')]
37+
public ?array $sources;
38+
39+
public function __construct()
40+
{
41+
$this->initialize();
42+
}
43+
44+
/**
45+
* Construct an instance from the required parameters.
46+
*
47+
* You must use named parameters to construct any parameters with a default value.
48+
*
49+
* @param list<string>|null $excludeSources
50+
* @param list<string>|null $sources
51+
*/
52+
public static function with(
53+
?array $excludeSources = null,
54+
?array $sources = null
55+
): self {
56+
$self = new self;
57+
58+
null !== $excludeSources && $self['excludeSources'] = $excludeSources;
59+
null !== $sources && $self['sources'] = $sources;
60+
61+
return $self;
62+
}
63+
64+
/**
65+
* Never search, read or cite these sites, sections or pages. Same format as `sources`. Up to 100 entries.
66+
*
67+
* @param list<string> $excludeSources
68+
*/
69+
public function withExcludeSources(array $excludeSources): self
70+
{
71+
$self = clone $this;
72+
$self['excludeSources'] = $excludeSources;
73+
74+
return $self;
75+
}
76+
77+
/**
78+
* Only search, read and cite these sites, sections or pages. Each entry is a URL prefix: "example.com" covers the site and its subdomains, "example.com/docs" covers that section, and "example.com/docs/setup.html" is one page. Up to 20 entries.
79+
*
80+
* @param list<string> $sources
81+
*/
82+
public function withSources(array $sources): self
83+
{
84+
$self = clone $this;
85+
$self['sources'] = $sources;
86+
87+
return $self;
88+
}
89+
}

‎tests/Services/WebTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function testAnswersWithOptionalParams(): void
5959

6060
$result = $this->client->web->answers(
6161
task: 'Find the pricing page URL and plan names for context.dev.',
62+
controls: ['excludeSources' => ['string'], 'sources' => ['string']],
6263
jsonFormat: ['pricing_page_url' => 'bar', 'plans' => 'bar'],
6364
mode: 'fast',
6465
policies: ['pol_3f9c2a7e5b8d4c1f9a6e0b2d7c4f8a1e'],

0 commit comments

Comments
 (0)