Skip to content

Commit f7a3ee5

Browse files
feat(api): api update
1 parent d1b85dd commit f7a3ee5

258 files changed

Lines changed: 4279 additions & 13730 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 36
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-8667763c416101820f5086c97d542bf13bb3bb12b57f5f604da671d9dcea0599.yml
3-
openapi_spec_hash: e33db883d584bc8573897391f3edb105
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/context-dev/context.dev-66a3bf68b47ba61c9b61406d36f614a079ff752b8964a8df8062e485391d5598.yml
3+
openapi_spec_hash: b17d6cfe3710dd0605078f3907a1a419
44
config_hash: 7ec4851ee8d93177947e95df5ae897b5

src/Monitors/MonitorCreateParams.php

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,34 @@
1010
use ContextDev\Core\Concerns\SdkParams;
1111
use ContextDev\Core\Contracts\BaseModel;
1212
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection;
13+
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsExactChangeDetection;
14+
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsSemanticChangeDetection;
15+
use ContextDev\Monitors\MonitorCreateParams\Mode;
1316
use ContextDev\Monitors\MonitorCreateParams\Schedule;
1417
use ContextDev\Monitors\MonitorCreateParams\Target;
18+
use ContextDev\Monitors\MonitorCreateParams\Target\MonitorsExtractTarget;
19+
use ContextDev\Monitors\MonitorCreateParams\Target\MonitorsPageTarget;
20+
use ContextDev\Monitors\MonitorCreateParams\Target\MonitorsSitemapTarget;
1521
use ContextDev\Monitors\MonitorCreateParams\Webhook;
1622

1723
/**
1824
* Creates a monitor. The request body is a union of the supported target/change detection combinations. The monitor runs immediately after creation to create its initial baseline.
1925
*
2026
* @see ContextDev\Services\MonitorsService::create()
2127
*
28+
* @phpstan-import-type ChangeDetectionVariants from \ContextDev\Monitors\MonitorCreateParams\ChangeDetection
29+
* @phpstan-import-type TargetVariants from \ContextDev\Monitors\MonitorCreateParams\Target
2230
* @phpstan-import-type ChangeDetectionShape from \ContextDev\Monitors\MonitorCreateParams\ChangeDetection
2331
* @phpstan-import-type ScheduleShape from \ContextDev\Monitors\MonitorCreateParams\Schedule
2432
* @phpstan-import-type TargetShape from \ContextDev\Monitors\MonitorCreateParams\Target
2533
* @phpstan-import-type WebhookShape from \ContextDev\Monitors\MonitorCreateParams\Webhook
2634
*
2735
* @phpstan-type MonitorCreateParamsShape = array{
28-
* changeDetection: ChangeDetection|ChangeDetectionShape,
36+
* changeDetection: ChangeDetectionShape,
2937
* name: string,
3038
* schedule: Schedule|ScheduleShape,
31-
* target: Target|TargetShape,
39+
* target: TargetShape,
40+
* mode?: null|Mode|value-of<Mode>,
3241
* tags?: list<string>|null,
3342
* webhook?: null|Webhook|WebhookShape,
3443
* }
@@ -40,10 +49,12 @@ final class MonitorCreateParams implements BaseModel
4049
use SdkParams;
4150

4251
/**
43-
* Detect meaning-level changes that match a natural language query.
52+
* Discriminated union describing how changes are detected.
53+
*
54+
* @var ChangeDetectionVariants $changeDetection
4455
*/
45-
#[Required('change_detection')]
46-
public ChangeDetection $changeDetection;
56+
#[Required('change_detection', union: ChangeDetection::class)]
57+
public MonitorsExactChangeDetection|MonitorsSemanticChangeDetection $changeDetection;
4758

4859
#[Required]
4960
public string $name;
@@ -54,8 +65,21 @@ final class MonitorCreateParams implements BaseModel
5465
#[Required]
5566
public Schedule $schedule;
5667

57-
#[Required]
58-
public Target $target;
68+
/**
69+
* Discriminated union describing what the monitor watches.
70+
*
71+
* @var TargetVariants $target
72+
*/
73+
#[Required(union: Target::class)]
74+
public MonitorsPageTarget|MonitorsSitemapTarget|MonitorsExtractTarget $target;
75+
76+
/**
77+
* Top-level monitor category. Always `web` today; the concrete behavior is described by `target` and `change_detection`.
78+
*
79+
* @var value-of<Mode>|null $mode
80+
*/
81+
#[Optional(enum: Mode::class)]
82+
public ?string $mode;
5983

6084
/**
6185
* User-defined tags for grouping and filtering monitors and their changes.
@@ -98,17 +122,19 @@ public function __construct()
98122
*
99123
* You must use named parameters to construct any parameters with a default value.
100124
*
101-
* @param ChangeDetection|ChangeDetectionShape $changeDetection
125+
* @param ChangeDetectionShape $changeDetection
102126
* @param Schedule|ScheduleShape $schedule
103-
* @param Target|TargetShape $target
127+
* @param TargetShape $target
128+
* @param Mode|value-of<Mode>|null $mode
104129
* @param list<string>|null $tags
105130
* @param Webhook|WebhookShape|null $webhook
106131
*/
107132
public static function with(
108-
ChangeDetection|array $changeDetection,
133+
MonitorsExactChangeDetection|array|MonitorsSemanticChangeDetection $changeDetection,
109134
string $name,
110135
Schedule|array $schedule,
111-
Target|array $target,
136+
MonitorsPageTarget|array|MonitorsSitemapTarget|MonitorsExtractTarget $target,
137+
Mode|string|null $mode = null,
112138
?array $tags = null,
113139
Webhook|array|null $webhook = null,
114140
): self {
@@ -119,19 +145,20 @@ public static function with(
119145
$self['schedule'] = $schedule;
120146
$self['target'] = $target;
121147

148+
null !== $mode && $self['mode'] = $mode;
122149
null !== $tags && $self['tags'] = $tags;
123150
null !== $webhook && $self['webhook'] = $webhook;
124151

125152
return $self;
126153
}
127154

128155
/**
129-
* Detect meaning-level changes that match a natural language query.
156+
* Discriminated union describing how changes are detected.
130157
*
131-
* @param ChangeDetection|ChangeDetectionShape $changeDetection
158+
* @param ChangeDetectionShape $changeDetection
132159
*/
133160
public function withChangeDetection(
134-
ChangeDetection|array $changeDetection
161+
MonitorsExactChangeDetection|array|MonitorsSemanticChangeDetection $changeDetection,
135162
): self {
136163
$self = clone $this;
137164
$self['changeDetection'] = $changeDetection;
@@ -161,16 +188,32 @@ public function withSchedule(Schedule|array $schedule): self
161188
}
162189

163190
/**
164-
* @param Target|TargetShape $target
191+
* Discriminated union describing what the monitor watches.
192+
*
193+
* @param TargetShape $target
165194
*/
166-
public function withTarget(Target|array $target): self
167-
{
195+
public function withTarget(
196+
MonitorsPageTarget|array|MonitorsSitemapTarget|MonitorsExtractTarget $target
197+
): self {
168198
$self = clone $this;
169199
$self['target'] = $target;
170200

171201
return $self;
172202
}
173203

204+
/**
205+
* Top-level monitor category. Always `web` today; the concrete behavior is described by `target` and `change_detection`.
206+
*
207+
* @param Mode|value-of<Mode> $mode
208+
*/
209+
public function withMode(Mode|string $mode): self
210+
{
211+
$self = clone $this;
212+
$self['mode'] = $mode;
213+
214+
return $self;
215+
}
216+
174217
/**
175218
* User-defined tags for grouping and filtering monitors and their changes.
176219
*

src/Monitors/MonitorCreateParams/ChangeDetection.php

Lines changed: 21 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,99 +4,38 @@
44

55
namespace ContextDev\Monitors\MonitorCreateParams;
66

7-
use ContextDev\Core\Attributes\Optional;
8-
use ContextDev\Core\Attributes\Required;
9-
use ContextDev\Core\Concerns\SdkModel;
10-
use ContextDev\Core\Contracts\BaseModel;
11-
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection\Type;
7+
use ContextDev\Core\Concerns\SdkUnion;
8+
use ContextDev\Core\Conversion\Contracts\Converter;
9+
use ContextDev\Core\Conversion\Contracts\ConverterSource;
10+
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsExactChangeDetection;
11+
use ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsSemanticChangeDetection;
1212

1313
/**
14-
* Detect meaning-level changes that match a natural language query.
14+
* Discriminated union describing how changes are detected.
1515
*
16-
* @phpstan-type ChangeDetectionShape = array{
17-
* query: string, type: Type|value-of<Type>, confidenceThreshold?: float|null
18-
* }
16+
* @phpstan-import-type MonitorsExactChangeDetectionShape from \ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsExactChangeDetection
17+
* @phpstan-import-type MonitorsSemanticChangeDetectionShape from \ContextDev\Monitors\MonitorCreateParams\ChangeDetection\MonitorsSemanticChangeDetection
18+
*
19+
* @phpstan-type ChangeDetectionVariants = MonitorsExactChangeDetection|MonitorsSemanticChangeDetection
20+
* @phpstan-type ChangeDetectionShape = ChangeDetectionVariants|MonitorsExactChangeDetectionShape|MonitorsSemanticChangeDetectionShape
1921
*/
20-
final class ChangeDetection implements BaseModel
22+
final class ChangeDetection implements ConverterSource
2123
{
22-
/** @use SdkModel<ChangeDetectionShape> */
23-
use SdkModel;
24-
25-
#[Required]
26-
public string $query;
27-
28-
/** @var value-of<Type> $type */
29-
#[Required(enum: Type::class)]
30-
public string $type;
31-
32-
#[Optional('confidence_threshold')]
33-
public ?float $confidenceThreshold;
34-
35-
/**
36-
* `new ChangeDetection()` is missing required properties by the API.
37-
*
38-
* To enforce required parameters use
39-
* ```
40-
* ChangeDetection::with(query: ..., type: ...)
41-
* ```
42-
*
43-
* Otherwise ensure the following setters are called
44-
*
45-
* ```
46-
* (new ChangeDetection)->withQuery(...)->withType(...)
47-
* ```
48-
*/
49-
public function __construct()
50-
{
51-
$this->initialize();
52-
}
53-
54-
/**
55-
* Construct an instance from the required parameters.
56-
*
57-
* You must use named parameters to construct any parameters with a default value.
58-
*
59-
* @param Type|value-of<Type> $type
60-
*/
61-
public static function with(
62-
string $query,
63-
Type|string $type,
64-
?float $confidenceThreshold = null
65-
): self {
66-
$self = new self;
67-
68-
$self['query'] = $query;
69-
$self['type'] = $type;
70-
71-
null !== $confidenceThreshold && $self['confidenceThreshold'] = $confidenceThreshold;
24+
use SdkUnion;
7225

73-
return $self;
74-
}
75-
76-
public function withQuery(string $query): self
26+
public static function discriminator(): string
7727
{
78-
$self = clone $this;
79-
$self['query'] = $query;
80-
81-
return $self;
28+
return 'type';
8229
}
8330

8431
/**
85-
* @param Type|value-of<Type> $type
32+
* @return list<string|Converter|ConverterSource>|array<string,string|Converter|ConverterSource>
8633
*/
87-
public function withType(Type|string $type): self
34+
public static function variants(): array
8835
{
89-
$self = clone $this;
90-
$self['type'] = $type;
91-
92-
return $self;
93-
}
94-
95-
public function withConfidenceThreshold(float $confidenceThreshold): self
96-
{
97-
$self = clone $this;
98-
$self['confidenceThreshold'] = $confidenceThreshold;
99-
100-
return $self;
36+
return [
37+
'exact' => MonitorsExactChangeDetection::class,
38+
'semantic' => MonitorsSemanticChangeDetection::class,
39+
];
10140
}
10241
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ContextDev\Monitors\MonitorCreateParams\ChangeDetection;
6+
7+
use ContextDev\Core\Attributes\Required;
8+
use ContextDev\Core\Concerns\SdkModel;
9+
use ContextDev\Core\Contracts\BaseModel;
10+
11+
/**
12+
* Detect exact changes. For page targets, this means visible text diffs. For sitemap targets, this means URL additions and removals.
13+
*
14+
* @phpstan-type MonitorsExactChangeDetectionShape = array{type: 'exact'}
15+
*/
16+
final class MonitorsExactChangeDetection implements BaseModel
17+
{
18+
/** @use SdkModel<MonitorsExactChangeDetectionShape> */
19+
use SdkModel;
20+
21+
/** @var 'exact' $type */
22+
#[Required]
23+
public string $type = 'exact';
24+
25+
public function __construct()
26+
{
27+
$this->initialize();
28+
}
29+
30+
/**
31+
* Construct an instance from the required parameters.
32+
*
33+
* You must use named parameters to construct any parameters with a default value.
34+
*/
35+
public static function with(): self
36+
{
37+
return new self;
38+
}
39+
40+
/**
41+
* @param 'exact' $type
42+
*/
43+
public function withType(string $type): self
44+
{
45+
$self = clone $this;
46+
$self['type'] = $type;
47+
48+
return $self;
49+
}
50+
}

0 commit comments

Comments
 (0)