ParsesTextResponses
trait ParsesTextResponses
Traits
Methods
Decode a structured output payload, tolerating markdown code fences.
Join reasoning blocks, separating each block with a blank line.
Validate the Anthropic response data.
Parse the Anthropic response data into a single step response.
Build a single step response from Anthropic content blocks.
Extract the text content from Anthropic content blocks.
Get the separator between text written before a tool block and text written after it.
Determine if the given block type is a server tool call or its result.
Determine if the given block type is a provider tool result.
Extract the reasoning text from Anthropic content blocks.
Extract the server tool use and result blocks, each keyed by the tool use it belongs to.
Extract tool calls from Anthropic content blocks.
Extract citations from Anthropic content blocks.
Extract usage data from the Anthropic response.
Extract and map the finish reason from the Anthropic response.
Extract structured output from the synthetic tool call.
Details
in
DecodesStructuredOutput at line 12
protected array
decodeStructuredOutput(string|null $text)
Decode a structured output payload, tolerating markdown code fences.
in
JoinsReasoning at line 16
static protected string
joinReasoning(iterable $blocks)
Join reasoning blocks, separating each block with a blank line.
at line 30
protected void
validateTextResponse(array $data)
Validate the Anthropic response data.
at line 44
protected StepResponse
parseTextResponse(array $data, Provider $provider, bool $structured)
Parse the Anthropic response data into a single step response.
at line 62
protected StepResponse
buildStepResponse(array $content, Provider $provider, string $model, TextUsage $usage, FinishReason $finishReason, bool $structured)
Build a single step response from Anthropic content blocks.
at line 114
protected string
extractText(array $content)
Extract the text content from Anthropic content blocks.
at line 143
protected string
textSeparator(string $before, string $after)
Get the separator between text written before a tool block and text written after it.
at line 151
protected bool
isToolBlock(string $type)
Determine if the given block type is a server tool call or its result.
at line 159
protected bool
isProviderToolResultBlock(string $type)
Determine if the given block type is a provider tool result.
at line 167
protected string
extractReasoning(array $content)
Extract the reasoning text from Anthropic content blocks.
at line 179
protected array
extractProviderToolCalls(array $content)
Extract the server tool use and result blocks, each keyed by the tool use it belongs to.
at line 192
protected array
extractToolCalls(array $content)
Extract tool calls from Anthropic content blocks.
at line 207
protected Collection
extractCitations(array $content)
Extract citations from Anthropic content blocks.
at line 252
protected TextUsage
extractUsage(array $data)
Extract usage data from the Anthropic response.
at line 271
protected FinishReason
extractFinishReason(array $data)
Extract and map the finish reason from the Anthropic response.
at line 286
protected array
extractStructuredOutput(array $content)
Extract structured output from the synthetic tool call.