|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace OpenAI\Actions\Conversations; |
| 6 | + |
| 7 | +use OpenAI\Responses\Responses\Input\ComputerToolCallOutput; |
| 8 | +use OpenAI\Responses\Responses\Input\FunctionToolCallOutput; |
| 9 | +use OpenAI\Responses\Responses\Input\InputMessage; |
| 10 | +use OpenAI\Responses\Responses\Output\OutputCodeInterpreterToolCall; |
| 11 | +use OpenAI\Responses\Responses\Output\OutputComputerToolCall; |
| 12 | +use OpenAI\Responses\Responses\Output\OutputFileSearchToolCall; |
| 13 | +use OpenAI\Responses\Responses\Output\OutputFunctionToolCall; |
| 14 | +use OpenAI\Responses\Responses\Output\OutputImageGenerationToolCall; |
| 15 | +use OpenAI\Responses\Responses\Output\OutputMcpApprovalRequest; |
| 16 | +use OpenAI\Responses\Responses\Output\OutputMcpCall; |
| 17 | +use OpenAI\Responses\Responses\Output\OutputMcpListTools; |
| 18 | +use OpenAI\Responses\Responses\Output\OutputReasoning; |
| 19 | +use OpenAI\Responses\Responses\Output\OutputWebSearchToolCall; |
| 20 | + |
| 21 | +/** |
| 22 | + * @phpstan-import-type InputMessageType from InputMessage |
| 23 | + * @phpstan-import-type ComputerToolCallOutputType from ComputerToolCallOutput |
| 24 | + * @phpstan-import-type FunctionToolCallOutputType from FunctionToolCallOutput |
| 25 | + * @phpstan-import-type OutputComputerToolCallType from OutputComputerToolCall |
| 26 | + * @phpstan-import-type OutputFileSearchToolCallType from OutputFileSearchToolCall |
| 27 | + * @phpstan-import-type OutputFunctionToolCallType from OutputFunctionToolCall |
| 28 | + * @phpstan-import-type OutputReasoningType from OutputReasoning |
| 29 | + * @phpstan-import-type OutputWebSearchToolCallType from OutputWebSearchToolCall |
| 30 | + * @phpstan-import-type OutputMcpListToolsType from OutputMcpListTools |
| 31 | + * @phpstan-import-type OutputMcpApprovalRequestType from OutputMcpApprovalRequest |
| 32 | + * @phpstan-import-type OutputMcpCallType from OutputMcpCall |
| 33 | + * @phpstan-import-type OutputImageGenerationToolCallType from OutputImageGenerationToolCall |
| 34 | + * @phpstan-import-type OutputCodeInterpreterToolCallType from OutputCodeInterpreterToolCall |
| 35 | + * |
| 36 | + * @phpstan-type ConversationItemObjectTypes array<int, InputMessageType|ComputerToolCallOutputType|FunctionToolCallOutputType|OutputComputerToolCallType|OutputFileSearchToolCallType|OutputFunctionToolCallType|OutputReasoningType|OutputWebSearchToolCallType|OutputMcpListToolsType|OutputMcpApprovalRequestType|OutputMcpCallType|OutputImageGenerationToolCallType|OutputCodeInterpreterToolCallType> |
| 37 | + * @phpstan-type ConversationItemObjectReturnType array<int, InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall> |
| 38 | + */ |
| 39 | +final class ItemObjects |
| 40 | +{ |
| 41 | + /** |
| 42 | + * @param ConversationItemObjectTypes $outputItems |
| 43 | + * @return ConversationItemObjectReturnType |
| 44 | + */ |
| 45 | + public static function parse(array $outputItems): array |
| 46 | + { |
| 47 | + return array_map( |
| 48 | + fn (array $item): InputMessage|ComputerToolCallOutput|FunctionToolCallOutput|OutputComputerToolCall|OutputFileSearchToolCall|OutputWebSearchToolCall|OutputFunctionToolCall|OutputReasoning|OutputMcpListTools|OutputMcpApprovalRequest|OutputMcpCall|OutputImageGenerationToolCall|OutputCodeInterpreterToolCall => match ($item['type']) { |
| 49 | + 'message' => InputMessage::from($item), |
| 50 | + 'file_search_call' => OutputFileSearchToolCall::from($item), |
| 51 | + 'function_call' => OutputFunctionToolCall::from($item), |
| 52 | + 'function_call_output' => FunctionToolCallOutput::from($item), |
| 53 | + 'web_search_call' => OutputWebSearchToolCall::from($item), |
| 54 | + 'computer_call' => OutputComputerToolCall::from($item), |
| 55 | + 'computer_call_output' => ComputerToolCallOutput::from($item), |
| 56 | + 'reasoning' => OutputReasoning::from($item), |
| 57 | + 'mcp_list_tools' => OutputMcpListTools::from($item), |
| 58 | + 'mcp_approval_request' => OutputMcpApprovalRequest::from($item), |
| 59 | + 'mcp_call' => OutputMcpCall::from($item), |
| 60 | + 'image_generation_call' => OutputImageGenerationToolCall::from($item), |
| 61 | + 'code_interpreter_call' => OutputCodeInterpreterToolCall::from($item), |
| 62 | + // todo |
| 63 | + // local_shell_call |
| 64 | + // local_shell_call_output |
| 65 | + // mcp_approval_response |
| 66 | + // custom_tool_call |
| 67 | + // custom_tool_call_output |
| 68 | + }, |
| 69 | + $outputItems, |
| 70 | + ); |
| 71 | + } |
| 72 | +} |
0 commit comments