Skip to content

Commit 80151ce

Browse files
feat(api): add structured stop_details to message responses
1 parent ee2528d commit 80151ce

File tree

9 files changed

+407
-7
lines changed

9 files changed

+407
-7
lines changed

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 31
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-3088a13fc94214c1b39c66c09fe0af997aed84b412f2fda478af89a9c016f3e6.yml
3-
openapi_spec_hash: ebeeaa9a9bf7603f0bbcce30389e27ca
4-
config_hash: 6f5727994013c43f452e6ac0b4d5e92a
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic%2Fanthropic-efe26b096126c693462514b8cbd3ec3e376569232becbfb730cd26fb31c7c7e3.yml
3+
openapi_spec_hash: cae9199aabfd7b87f0ff2dcc10760c92
4+
config_hash: 79b43ba5cfb2877d888e0d5ecab99d41

src/Beta/Messages/BetaMessage.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* @phpstan-import-type BetaContainerShape from \Anthropic\Beta\Messages\BetaContainer
1616
* @phpstan-import-type BetaContentBlockShape from \Anthropic\Beta\Messages\BetaContentBlock
1717
* @phpstan-import-type BetaContextManagementResponseShape from \Anthropic\Beta\Messages\BetaContextManagementResponse
18+
* @phpstan-import-type BetaRefusalStopDetailsShape from \Anthropic\Beta\Messages\BetaRefusalStopDetails
1819
* @phpstan-import-type BetaUsageShape from \Anthropic\Beta\Messages\BetaUsage
1920
*
2021
* @phpstan-type BetaMessageShape = array{
@@ -24,6 +25,7 @@
2425
* contextManagement: null|BetaContextManagementResponse|BetaContextManagementResponseShape,
2526
* model: string|Model|value-of<Model>,
2627
* role: 'assistant',
28+
* stopDetails: null|BetaRefusalStopDetails|BetaRefusalStopDetailsShape,
2729
* stopReason: null|BetaStopReason|value-of<BetaStopReason>,
2830
* stopSequence: string|null,
2931
* type: 'message',
@@ -117,6 +119,12 @@ final class BetaMessage implements BaseModel
117119
#[Required(enum: Model::class)]
118120
public string $model;
119121

122+
/**
123+
* Structured information about a refusal.
124+
*/
125+
#[Required('stop_details')]
126+
public ?BetaRefusalStopDetails $stopDetails;
127+
120128
/**
121129
* The reason that we stopped.
122130
*
@@ -168,6 +176,7 @@ final class BetaMessage implements BaseModel
168176
* content: ...,
169177
* contextManagement: ...,
170178
* model: ...,
179+
* stopDetails: ...,
171180
* stopReason: ...,
172181
* stopSequence: ...,
173182
* usage: ...,
@@ -183,6 +192,7 @@ final class BetaMessage implements BaseModel
183192
* ->withContent(...)
184193
* ->withContextManagement(...)
185194
* ->withModel(...)
195+
* ->withStopDetails(...)
186196
* ->withStopReason(...)
187197
* ->withStopSequence(...)
188198
* ->withUsage(...)
@@ -222,6 +232,7 @@ public function parsedOutput(): mixed
222232
* @param list<BetaContentBlockShape> $content
223233
* @param BetaContextManagementResponse|BetaContextManagementResponseShape|null $contextManagement
224234
* @param string|Model|value-of<Model> $model
235+
* @param BetaRefusalStopDetails|BetaRefusalStopDetailsShape|null $stopDetails
225236
* @param BetaStopReason|value-of<BetaStopReason>|null $stopReason
226237
* @param BetaUsage|BetaUsageShape $usage
227238
*/
@@ -231,6 +242,7 @@ public static function with(
231242
array $content,
232243
BetaContextManagementResponse|array|null $contextManagement,
233244
Model|string $model,
245+
BetaRefusalStopDetails|array|null $stopDetails,
234246
BetaStopReason|string|null $stopReason,
235247
?string $stopSequence,
236248
BetaUsage|array $usage,
@@ -242,6 +254,7 @@ public static function with(
242254
$self['content'] = $content;
243255
$self['contextManagement'] = $contextManagement;
244256
$self['model'] = $model;
257+
$self['stopDetails'] = $stopDetails;
245258
$self['stopReason'] = $stopReason;
246259
$self['stopSequence'] = $stopSequence;
247260
$self['usage'] = $usage;
@@ -356,6 +369,20 @@ public function withRole(string $role): self
356369
return $self;
357370
}
358371

372+
/**
373+
* Structured information about a refusal.
374+
*
375+
* @param BetaRefusalStopDetails|BetaRefusalStopDetailsShape|null $stopDetails
376+
*/
377+
public function withStopDetails(
378+
BetaRefusalStopDetails|array|null $stopDetails
379+
): self {
380+
$self = clone $this;
381+
$self['stopDetails'] = $stopDetails;
382+
383+
return $self;
384+
}
385+
359386
/**
360387
* The reason that we stopped.
361388
*

src/Beta/Messages/BetaRawMessageDeltaEvent/Delta.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
namespace Anthropic\Beta\Messages\BetaRawMessageDeltaEvent;
66

77
use Anthropic\Beta\Messages\BetaContainer;
8+
use Anthropic\Beta\Messages\BetaRefusalStopDetails;
89
use Anthropic\Beta\Messages\BetaStopReason;
910
use Anthropic\Core\Attributes\Required;
1011
use Anthropic\Core\Concerns\SdkModel;
1112
use Anthropic\Core\Contracts\BaseModel;
1213

1314
/**
1415
* @phpstan-import-type BetaContainerShape from \Anthropic\Beta\Messages\BetaContainer
16+
* @phpstan-import-type BetaRefusalStopDetailsShape from \Anthropic\Beta\Messages\BetaRefusalStopDetails
1517
*
1618
* @phpstan-type DeltaShape = array{
1719
* container: null|BetaContainer|BetaContainerShape,
20+
* stopDetails: null|BetaRefusalStopDetails|BetaRefusalStopDetailsShape,
1821
* stopReason: null|BetaStopReason|value-of<BetaStopReason>,
1922
* stopSequence: string|null,
2023
* }
@@ -30,6 +33,12 @@ final class Delta implements BaseModel
3033
#[Required]
3134
public ?BetaContainer $container;
3235

36+
/**
37+
* Structured information about a refusal.
38+
*/
39+
#[Required('stop_details')]
40+
public ?BetaRefusalStopDetails $stopDetails;
41+
3342
/** @var value-of<BetaStopReason>|null $stopReason */
3443
#[Required('stop_reason', enum: BetaStopReason::class)]
3544
public ?string $stopReason;
@@ -42,13 +51,19 @@ final class Delta implements BaseModel
4251
*
4352
* To enforce required parameters use
4453
* ```
45-
* Delta::with(container: ..., stopReason: ..., stopSequence: ...)
54+
* Delta::with(
55+
* container: ..., stopDetails: ..., stopReason: ..., stopSequence: ...
56+
* )
4657
* ```
4758
*
4859
* Otherwise ensure the following setters are called
4960
*
5061
* ```
51-
* (new Delta)->withContainer(...)->withStopReason(...)->withStopSequence(...)
62+
* (new Delta)
63+
* ->withContainer(...)
64+
* ->withStopDetails(...)
65+
* ->withStopReason(...)
66+
* ->withStopSequence(...)
5267
* ```
5368
*/
5469
public function __construct()
@@ -62,16 +77,19 @@ public function __construct()
6277
* You must use named parameters to construct any parameters with a default value.
6378
*
6479
* @param BetaContainer|BetaContainerShape|null $container
80+
* @param BetaRefusalStopDetails|BetaRefusalStopDetailsShape|null $stopDetails
6581
* @param BetaStopReason|value-of<BetaStopReason>|null $stopReason
6682
*/
6783
public static function with(
6884
BetaContainer|array|null $container,
85+
BetaRefusalStopDetails|array|null $stopDetails,
6986
BetaStopReason|string|null $stopReason,
7087
?string $stopSequence,
7188
): self {
7289
$self = new self;
7390

7491
$self['container'] = $container;
92+
$self['stopDetails'] = $stopDetails;
7593
$self['stopReason'] = $stopReason;
7694
$self['stopSequence'] = $stopSequence;
7795

@@ -91,6 +109,20 @@ public function withContainer(BetaContainer|array|null $container): self
91109
return $self;
92110
}
93111

112+
/**
113+
* Structured information about a refusal.
114+
*
115+
* @param BetaRefusalStopDetails|BetaRefusalStopDetailsShape|null $stopDetails
116+
*/
117+
public function withStopDetails(
118+
BetaRefusalStopDetails|array|null $stopDetails
119+
): self {
120+
$self = clone $this;
121+
$self['stopDetails'] = $stopDetails;
122+
123+
return $self;
124+
}
125+
94126
/**
95127
* @param BetaStopReason|value-of<BetaStopReason>|null $stopReason
96128
*/
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Anthropic\Beta\Messages;
6+
7+
use Anthropic\Beta\Messages\BetaRefusalStopDetails\Category;
8+
use Anthropic\Core\Attributes\Required;
9+
use Anthropic\Core\Concerns\SdkModel;
10+
use Anthropic\Core\Contracts\BaseModel;
11+
12+
/**
13+
* Structured information about a refusal.
14+
*
15+
* @phpstan-type BetaRefusalStopDetailsShape = array{
16+
* category: null|Category|value-of<Category>,
17+
* explanation: string|null,
18+
* type: 'refusal',
19+
* }
20+
*/
21+
final class BetaRefusalStopDetails implements BaseModel
22+
{
23+
/** @use SdkModel<BetaRefusalStopDetailsShape> */
24+
use SdkModel;
25+
26+
/** @var 'refusal' $type */
27+
#[Required]
28+
public string $type = 'refusal';
29+
30+
/**
31+
* The policy category that triggered the refusal.
32+
*
33+
* `null` when the refusal doesn't map to a named category.
34+
*
35+
* @var value-of<Category>|null $category
36+
*/
37+
#[Required(enum: Category::class)]
38+
public ?string $category;
39+
40+
/**
41+
* Human-readable explanation of the refusal.
42+
*
43+
* This text is not guaranteed to be stable. `null` when no explanation is available for the category.
44+
*/
45+
#[Required]
46+
public ?string $explanation;
47+
48+
/**
49+
* `new BetaRefusalStopDetails()` is missing required properties by the API.
50+
*
51+
* To enforce required parameters use
52+
* ```
53+
* BetaRefusalStopDetails::with(category: ..., explanation: ...)
54+
* ```
55+
*
56+
* Otherwise ensure the following setters are called
57+
*
58+
* ```
59+
* (new BetaRefusalStopDetails)->withCategory(...)->withExplanation(...)
60+
* ```
61+
*/
62+
public function __construct()
63+
{
64+
$this->initialize();
65+
}
66+
67+
/**
68+
* Construct an instance from the required parameters.
69+
*
70+
* You must use named parameters to construct any parameters with a default value.
71+
*
72+
* @param Category|value-of<Category>|null $category
73+
*/
74+
public static function with(
75+
Category|string|null $category,
76+
?string $explanation
77+
): self {
78+
$self = new self;
79+
80+
$self['category'] = $category;
81+
$self['explanation'] = $explanation;
82+
83+
return $self;
84+
}
85+
86+
/**
87+
* The policy category that triggered the refusal.
88+
*
89+
* `null` when the refusal doesn't map to a named category.
90+
*
91+
* @param Category|value-of<Category>|null $category
92+
*/
93+
public function withCategory(Category|string|null $category): self
94+
{
95+
$self = clone $this;
96+
$self['category'] = $category;
97+
98+
return $self;
99+
}
100+
101+
/**
102+
* Human-readable explanation of the refusal.
103+
*
104+
* This text is not guaranteed to be stable. `null` when no explanation is available for the category.
105+
*/
106+
public function withExplanation(?string $explanation): self
107+
{
108+
$self = clone $this;
109+
$self['explanation'] = $explanation;
110+
111+
return $self;
112+
}
113+
114+
/**
115+
* @param 'refusal' $type
116+
*/
117+
public function withType(string $type): self
118+
{
119+
$self = clone $this;
120+
$self['type'] = $type;
121+
122+
return $self;
123+
}
124+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Anthropic\Beta\Messages\BetaRefusalStopDetails;
6+
7+
/**
8+
* The policy category that triggered the refusal.
9+
*
10+
* `null` when the refusal doesn't map to a named category.
11+
*/
12+
enum Category: string
13+
{
14+
case CYBER = 'cyber';
15+
16+
case BIO = 'bio';
17+
}

0 commit comments

Comments
 (0)