|
30 | 30 | * @phpstan-import-type WaitType from Wait |
31 | 31 | * @phpstan-import-type PendingSafetyCheckType from OutputComputerPendingSafetyCheck |
32 | 32 | * |
33 | | - * @phpstan-type OutputComputerToolCallType array{action: ClickType|DoubleClickType|DragType|KeyPressType|MoveType|ScreenshotType|ScrollType|TypeType|WaitType, call_id: string, id: string, pending_safety_checks: array<int, PendingSafetyCheckType>, status: 'in_progress'|'completed'|'incomplete', type: 'computer_call'} |
| 33 | + * @phpstan-type ActionType ClickType|DoubleClickType|DragType|KeyPressType|MoveType|ScreenshotType|ScrollType|TypeType|WaitType |
| 34 | + * @phpstan-type OutputComputerToolCallType array{action?: ActionType, actions?: array<int, ActionType>, call_id: string, id: string, pending_safety_checks?: array<int, PendingSafetyCheckType>, status: 'in_progress'|'completed'|'incomplete', type: 'computer_call'} |
34 | 35 | * |
35 | 36 | * @implements ResponseContract<OutputComputerToolCallType> |
36 | 37 | */ |
@@ -62,21 +63,23 @@ private function __construct( |
62 | 63 | */ |
63 | 64 | public static function from(array $attributes): self |
64 | 65 | { |
65 | | - $action = match ($attributes['action']['type']) { |
66 | | - 'click' => Click::from($attributes['action']), |
67 | | - 'double_click' => DoubleClick::from($attributes['action']), |
68 | | - 'drag' => Drag::from($attributes['action']), |
69 | | - 'keypress' => KeyPress::from($attributes['action']), |
70 | | - 'move' => Move::from($attributes['action']), |
71 | | - 'screenshot' => Screenshot::from($attributes['action']), |
72 | | - 'scroll' => Scroll::from($attributes['action']), |
73 | | - 'type' => Type::from($attributes['action']), |
74 | | - 'wait' => Wait::from($attributes['action']), |
| 66 | + $actionAttributes = $attributes['action'] ?? ($attributes['actions'][0] ?? []); |
| 67 | + |
| 68 | + $action = match ($actionAttributes['type']) { |
| 69 | + 'click' => Click::from($actionAttributes), |
| 70 | + 'double_click' => DoubleClick::from($actionAttributes), |
| 71 | + 'drag' => Drag::from($actionAttributes), |
| 72 | + 'keypress' => KeyPress::from($actionAttributes), |
| 73 | + 'move' => Move::from($actionAttributes), |
| 74 | + 'screenshot' => Screenshot::from($actionAttributes), |
| 75 | + 'scroll' => Scroll::from($actionAttributes), |
| 76 | + 'type' => Type::from($actionAttributes), |
| 77 | + 'wait' => Wait::from($actionAttributes), |
75 | 78 | }; |
76 | 79 |
|
77 | 80 | $pendingSafetyChecks = array_map( |
78 | 81 | fn (array $safetyCheck): OutputComputerPendingSafetyCheck => OutputComputerPendingSafetyCheck::from($safetyCheck), |
79 | | - $attributes['pending_safety_checks'] |
| 82 | + $attributes['pending_safety_checks'] ?? [] |
80 | 83 | ); |
81 | 84 |
|
82 | 85 | return new self( |
|
0 commit comments