1616use OpenAI \Responses \Responses \Tool \WebSearchTool ;
1717
1818/**
19- * @phpstan-type ResponseToolObjectTypes array<int, array{type: string}>
20- * @phpstan-type ResponseToolObjectReturnType array<int, ComputerUseTool|FileSearchTool|FunctionTool|WebSearchTool|ImageGenerationTool|RemoteMcpTool|CodeInterpreterTool|ToolSearchTool|NamespaceTool|CustomTool>
19+ * @phpstan-import-type CodeInterpreterToolType from CodeInterpreterTool
20+ * @phpstan-import-type ComputerUseToolType from ComputerUseTool
21+ * @phpstan-import-type CustomToolType from CustomTool
22+ * @phpstan-import-type FileSearchToolType from FileSearchTool
23+ * @phpstan-import-type FunctionToolType from FunctionTool
24+ * @phpstan-import-type ImageGenerationToolType from ImageGenerationTool
25+ * @phpstan-import-type NamespaceToolType from NamespaceTool
26+ * @phpstan-import-type RemoteMcpToolType from RemoteMcpTool
27+ * @phpstan-import-type ToolSearchToolType from ToolSearchTool
28+ * @phpstan-import-type WebSearchToolType from WebSearchTool
29+ *
30+ * @phpstan-type ResponseToolObjectTypes array<int, CodeInterpreterToolType|ComputerUseToolType|CustomToolType|FileSearchToolType|FunctionToolType|ImageGenerationToolType|NamespaceToolType|RemoteMcpToolType|ToolSearchToolType|WebSearchToolType>
31+ * @phpstan-type ResponseToolObjectReturnType array<int, CodeInterpreterTool|ComputerUseTool|CustomTool|FileSearchTool|FunctionTool|ImageGenerationTool|NamespaceTool|RemoteMcpTool|ToolSearchTool|WebSearchTool>
2132 */
2233final class ToolObjects
2334{
@@ -28,18 +39,17 @@ final class ToolObjects
2839 public static function parse (array $ toolItems ): array
2940 {
3041 return array_map (
31- fn (array $ tool ): ComputerUseTool |FileSearchTool |FunctionTool |WebSearchTool |ImageGenerationTool |RemoteMcpTool |CodeInterpreterTool |ToolSearchTool |NamespaceTool |CustomTool => match ($ tool ['type ' ]) {
32- 'file_search ' => FileSearchTool::from ($ tool ), // @phpstan-ignore-line
33- 'web_search ' , 'web_search_preview ' , 'web_search_preview_2025_03_11 ' => WebSearchTool::from ($ tool ), // @phpstan-ignore-line
34- 'function ' => FunctionTool::from ($ tool ), // @phpstan-ignore-line
35- 'computer_use_preview ' => ComputerUseTool::from ($ tool ), // @phpstan-ignore-line
36- 'image_generation ' => ImageGenerationTool::from ($ tool ), // @phpstan-ignore-line
37- 'mcp ' => RemoteMcpTool::from ($ tool ), // @phpstan-ignore-line
38- 'code_interpreter ' => CodeInterpreterTool::from ($ tool ), // @phpstan-ignore-line
39- 'tool_search ' => ToolSearchTool::from ($ tool ), // @phpstan-ignore-line
40- 'namespace ' => NamespaceTool::from ($ tool ), // @phpstan-ignore-line
41- 'custom ' => CustomTool::from ($ tool ), // @phpstan-ignore-line
42- default => throw new \InvalidArgumentException ("Unknown tool type: {$ tool ['type ' ]}" ),
42+ fn (array $ tool ): CodeInterpreterTool |ComputerUseTool |CustomTool |FileSearchTool |FunctionTool |ImageGenerationTool |NamespaceTool |RemoteMcpTool |ToolSearchTool |WebSearchTool => match ($ tool ['type ' ]) {
43+ 'file_search ' => FileSearchTool::from ($ tool ),
44+ 'web_search ' , 'web_search_preview ' , 'web_search_preview_2025_03_11 ' => WebSearchTool::from ($ tool ),
45+ 'function ' => FunctionTool::from ($ tool ),
46+ 'computer_use_preview ' => ComputerUseTool::from ($ tool ),
47+ 'image_generation ' => ImageGenerationTool::from ($ tool ),
48+ 'mcp ' => RemoteMcpTool::from ($ tool ),
49+ 'code_interpreter ' => CodeInterpreterTool::from ($ tool ),
50+ 'tool_search ' => ToolSearchTool::from ($ tool ),
51+ 'namespace ' => NamespaceTool::from ($ tool ),
52+ 'custom ' => CustomTool::from ($ tool ),
4353 },
4454 $ toolItems ,
4555 );
0 commit comments