Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Actions/Conversations/ItemObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace OpenAI\Actions\Conversations;

use OpenAI\Responses\Conversations\Objects\Message;
use OpenAI\Responses\Responses\Input\ApplyPatchToolCallOutput;
use OpenAI\Responses\Responses\Input\ComputerToolCallOutput;
use OpenAI\Responses\Responses\Input\CustomToolCallOutput;
use OpenAI\Responses\Responses\Input\FunctionToolCallOutput;
use OpenAI\Responses\Responses\Input\LocalShellCallOutput;
use OpenAI\Responses\Responses\Input\McpApprovalResponse;
use OpenAI\Responses\Responses\Output\OutputApplyPatchToolCall;
use OpenAI\Responses\Responses\Output\OutputCodeInterpreterToolCall;
use OpenAI\Responses\Responses\Output\OutputComputerToolCall;
use OpenAI\Responses\Responses\Output\OutputCustomToolCall;
Expand All @@ -26,13 +28,15 @@
use OpenAI\Responses\Responses\Output\OutputWebSearchToolCall;

/**
* @phpstan-import-type ApplyPatchToolCallOutputType from ApplyPatchToolCallOutput
* @phpstan-import-type MessageType from Message
* @phpstan-import-type ComputerToolCallOutputType from ComputerToolCallOutput
* @phpstan-import-type FunctionToolCallOutputType from FunctionToolCallOutput
* @phpstan-import-type LocalShellCallOutputType from LocalShellCallOutput
* @phpstan-import-type McpApprovalResponseType from McpApprovalResponse
* @phpstan-import-type CustomToolCallOutputType from CustomToolCallOutput
* @phpstan-import-type OutputComputerToolCallType from OutputComputerToolCall
* @phpstan-import-type OutputApplyPatchToolCallType from OutputApplyPatchToolCall
* @phpstan-import-type OutputFileSearchToolCallType from OutputFileSearchToolCall
* @phpstan-import-type OutputFunctionToolCallType from OutputFunctionToolCall
* @phpstan-import-type OutputReasoningType from OutputReasoning
Expand All @@ -47,9 +51,9 @@
* @phpstan-import-type OutputProgramType from OutputProgram
* @phpstan-import-type OutputProgramOutputType from OutputProgramOutput
*
* @phpstan-type ItemObjectTypes MessageType|ComputerToolCallOutputType|FunctionToolCallOutputType|LocalShellCallOutputType|McpApprovalResponseType|CustomToolCallOutputType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputProgramType|OutputProgramOutputType
* @phpstan-type ItemObjectTypes ApplyPatchToolCallOutputType|MessageType|ComputerToolCallOutputType|FunctionToolCallOutputType|LocalShellCallOutputType|McpApprovalResponseType|CustomToolCallOutputType|OutputApplyPatchToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputProgramType|OutputProgramOutputType
* @phpstan-type ConversationItemObjectTypes array<int, ItemObjectTypes>
* @phpstan-type ConversationItemObjectReturnType array<int, Message|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|CustomToolCallOutput|OutputProgram|OutputProgramOutput>
* @phpstan-type ConversationItemObjectReturnType array<int, ApplyPatchToolCallOutput|Message|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|OutputApplyPatchToolCall|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|CustomToolCallOutput|OutputProgram|OutputProgramOutput>
*/
final class ItemObjects
{
Expand All @@ -60,7 +64,7 @@ final class ItemObjects
public static function parse(array $outputItems): array
{
return array_map(
fn (array $item): Message|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|CustomToolCallOutput|OutputProgram|OutputProgramOutput => match ($item['type']) {
fn (array $item): ApplyPatchToolCallOutput|Message|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|OutputApplyPatchToolCall|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|CustomToolCallOutput|OutputProgram|OutputProgramOutput => match ($item['type']) {
'message' => Message::from($item),
'file_search_call' => OutputFileSearchToolCall::from($item),
'function_call' => OutputFunctionToolCall::from($item),
Expand All @@ -81,6 +85,8 @@ public static function parse(array $outputItems): array
'mcp_approval_response' => McpApprovalResponse::from($item),
'program' => OutputProgram::from($item),
'program_output' => OutputProgramOutput::from($item),
'apply_patch_call' => OutputApplyPatchToolCall::from($item),
'apply_patch_call_output' => ApplyPatchToolCallOutput::from($item),
},
$outputItems,
);
Expand Down
12 changes: 9 additions & 3 deletions src/Actions/Responses/ItemObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace OpenAI\Actions\Responses;

use OpenAI\Responses\Responses\Input\ApplyPatchToolCallOutput;
use OpenAI\Responses\Responses\Input\ComputerToolCallOutput;
use OpenAI\Responses\Responses\Input\CustomToolCallOutput;
use OpenAI\Responses\Responses\Input\FunctionToolCallOutput;
use OpenAI\Responses\Responses\Input\InputMessage;
use OpenAI\Responses\Responses\Input\LocalShellCallOutput;
use OpenAI\Responses\Responses\Input\McpApprovalResponse;
use OpenAI\Responses\Responses\Output\OutputApplyPatchToolCall;
use OpenAI\Responses\Responses\Output\OutputCodeInterpreterToolCall;
use OpenAI\Responses\Responses\Output\OutputComputerToolCall;
use OpenAI\Responses\Responses\Output\OutputCustomToolCall;
Expand All @@ -27,13 +29,15 @@
use OpenAI\Responses\Responses\Output\OutputWebSearchToolCall;

/**
* @phpstan-import-type ApplyPatchToolCallOutputType from ApplyPatchToolCallOutput
* @phpstan-import-type InputMessageType from InputMessage
* @phpstan-import-type ComputerToolCallOutputType from ComputerToolCallOutput
* @phpstan-import-type FunctionToolCallOutputType from FunctionToolCallOutput
* @phpstan-import-type LocalShellCallOutputType from LocalShellCallOutput
* @phpstan-import-type McpApprovalResponseType from McpApprovalResponse
* @phpstan-import-type CustomToolCallOutputType from CustomToolCallOutput
* @phpstan-import-type OutputComputerToolCallType from OutputComputerToolCall
* @phpstan-import-type OutputApplyPatchToolCallType from OutputApplyPatchToolCall
* @phpstan-import-type OutputFileSearchToolCallType from OutputFileSearchToolCall
* @phpstan-import-type OutputFunctionToolCallType from OutputFunctionToolCall
* @phpstan-import-type OutputMessageType from OutputMessage
Expand All @@ -49,8 +53,8 @@
* @phpstan-import-type OutputProgramType from OutputProgram
* @phpstan-import-type OutputProgramOutputType from OutputProgramOutput
*
* @phpstan-type ResponseItemObjectTypes array<int, InputMessageType|ComputerToolCallOutputType|FunctionToolCallOutputType|LocalShellCallOutputType|McpApprovalResponseType|CustomToolCallOutputType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputProgramType|OutputProgramOutputType>
* @phpstan-type ResponseItemObjectReturnType array<int, InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|CustomToolCallOutput|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputProgram|OutputProgramOutput>
* @phpstan-type ResponseItemObjectTypes array<int, ApplyPatchToolCallOutputType|InputMessageType|ComputerToolCallOutputType|FunctionToolCallOutputType|LocalShellCallOutputType|McpApprovalResponseType|CustomToolCallOutputType|OutputApplyPatchToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputProgramType|OutputProgramOutputType>
* @phpstan-type ResponseItemObjectReturnType array<int, ApplyPatchToolCallOutput|InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|CustomToolCallOutput|OutputApplyPatchToolCall|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputProgram|OutputProgramOutput>
*/
final class ItemObjects
{
Expand All @@ -61,7 +65,7 @@ final class ItemObjects
public static function parse(array $outputItems): array
{
return array_map(
fn (array $item): InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|CustomToolCallOutput|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputProgram|OutputProgramOutput => match ($item['type']) {
fn (array $item): ApplyPatchToolCallOutput|InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|LocalShellCallOutput|McpApprovalResponse|CustomToolCallOutput|OutputApplyPatchToolCall|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputProgram|OutputProgramOutput => match ($item['type']) {
'message' => $item['role'] === 'assistant' ? OutputMessage::from($item) : InputMessage::from($item),
'file_search_call' => OutputFileSearchToolCall::from($item),
'function_call' => OutputFunctionToolCall::from($item),
Expand All @@ -82,6 +86,8 @@ public static function parse(array $outputItems): array
'mcp_approval_response' => McpApprovalResponse::from($item),
'program' => OutputProgram::from($item),
'program_output' => OutputProgramOutput::from($item),
'apply_patch_call' => OutputApplyPatchToolCall::from($item),
'apply_patch_call_output' => ApplyPatchToolCallOutput::from($item),
},
$outputItems,
);
Expand Down
9 changes: 6 additions & 3 deletions src/Actions/Responses/OutputObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OpenAI\Actions\Responses;

use OpenAI\Responses\Responses\Output\OutputApplyPatchToolCall;
use OpenAI\Responses\Responses\Output\OutputCodeInterpreterToolCall;
use OpenAI\Responses\Responses\Output\OutputCompaction;
use OpenAI\Responses\Responses\Output\OutputComputerToolCall;
Expand All @@ -24,6 +25,7 @@
use OpenAI\Responses\Responses\Output\OutputWebSearchToolCall;

/**
* @phpstan-import-type OutputApplyPatchToolCallType from OutputApplyPatchToolCall
* @phpstan-import-type OutputComputerToolCallType from OutputComputerToolCall
* @phpstan-import-type OutputFileSearchToolCallType from OutputFileSearchToolCall
* @phpstan-import-type OutputFunctionToolCallType from OutputFunctionToolCall
Expand All @@ -43,8 +45,8 @@
* @phpstan-import-type OutputToolSearchCallType from OutputToolSearchCall
* @phpstan-import-type OutputToolSearchOutputType from OutputToolSearchOutput
*
* @phpstan-type ResponseOutputObjectTypes array<int, OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputProgramType|OutputProgramOutputType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputToolSearchCallType|OutputToolSearchOutputType|OutputCompactionType>
* @phpstan-type ResponseOutputObjectReturnType array<int, OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputProgram|OutputProgramOutput|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputToolSearchCall|OutputToolSearchOutput|OutputCompaction>
* @phpstan-type ResponseOutputObjectTypes array<int, OutputApplyPatchToolCallType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputMessageType|OutputProgramType|OutputProgramOutputType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType|OutputLocalShellCallType|OutputCustomToolCallType|OutputToolSearchCallType|OutputToolSearchOutputType|OutputCompactionType>
* @phpstan-type ResponseOutputObjectReturnType array<int, OutputApplyPatchToolCall|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputProgram|OutputProgramOutput|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputToolSearchCall|OutputToolSearchOutput|OutputCompaction>
*/
final class OutputObjects
{
Expand All @@ -55,7 +57,7 @@ final class OutputObjects
public static function parse(array $outputItems): array
{
return array_map(
fn (array $item): OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputProgram|OutputProgramOutput|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputToolSearchCall|OutputToolSearchOutput|OutputCompaction => match ($item['type']) {
fn (array $item): OutputApplyPatchToolCall|OutputMessage|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputProgram|OutputProgramOutput|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall|OutputLocalShellCall|OutputCustomToolCall|OutputToolSearchCall|OutputToolSearchOutput|OutputCompaction => match ($item['type']) {
'message' => OutputMessage::from($item),
'file_search_call' => OutputFileSearchToolCall::from($item),
'function_call' => OutputFunctionToolCall::from($item),
Expand All @@ -74,6 +76,7 @@ public static function parse(array $outputItems): array
'tool_search_call' => OutputToolSearchCall::from($item),
'tool_search_output' => OutputToolSearchOutput::from($item),
'compaction' => OutputCompaction::from($item),
'apply_patch_call' => OutputApplyPatchToolCall::from($item),
default => throw new \UnexpectedValueException('Uh oh! We do not recognize this type. Please submit a bug to openai-php/client on GitHub!'),
},
$outputItems,
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/Responses/ToolChoiceObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function parse(array|string $toolChoice): string|FunctionToolChoic
{
return is_array($toolChoice)
? match ($toolChoice['type']) {
'file_search', 'web_search', 'web_search_preview', 'computer_use_preview', 'programmatic_tool_calling' => HostedToolChoice::from($toolChoice),
'apply_patch', 'file_search', 'web_search', 'web_search_preview', 'computer_use_preview', 'programmatic_tool_calling' => HostedToolChoice::from($toolChoice),
'function' => FunctionToolChoice::from($toolChoice),
}
: $toolChoice;
Expand Down
Loading