take_card(); if ( null === $card || empty( $card['card'] ) ) { return null; } if ( is_array( $result_data ) && false === ( $result_data['ok'] ?? null ) ) { return null; } return [ 'type' => 'card', 'card' => (string) $card['card'], 'data' => is_array( $card['data'] ?? null ) ? $card['data'] : [], ]; } /** * The `tool_call_start` SSE payload for a tool that just started, with its * status line when it has one. * * @param object $tool The tool that is starting. * @return array */ public static function tool_start( object $tool ): array { return [ 'type' => 'tool_call_start', 'label' => $tool instanceof Chat_Status_Contract ? $tool->status_label() : '', ]; } /** * Whether this exact card was already sent in the current turn. * * Keyed on what the visitor sees, not on the tool inputs: two calls with * different inputs (e.g. attendees omitted, then attendees 1) can build the * same card, which showed up as two identical "Continue booking" cards. * * @param array $card Card payload from from_tool(). * @param array $shown Keys already sent this turn; updated in place. * @return bool */ public static function is_repeat( array $card, array &$shown ): bool { $key = 'card|' . wp_json_encode( $card ); if ( isset( $shown[ $key ] ) ) { return true; } $shown[ $key ] = true; return false; } }