@@ -597,6 +597,9 @@ private static function is_post_creation_tool( string $name ): bool {
597597 }
598598
599599 /** Preserve the stable identifiers returned by media and form creation tools. */
600+ /**
601+ * @param array<string,mixed> $function_response Serialized function response.
602+ */
600603 private static function compact_resource_response_receipt ( array $ function_response ): string {
601604 [ $ name , $ response ] = self ::compact_response_identity ( $ function_response );
602605 if ( ! self ::is_compact_resource_tool ( $ name ) ) {
@@ -612,6 +615,9 @@ private static function compact_resource_response_receipt( array $function_respo
612615 }
613616
614617 /** Preserve bounded intent for media and form creation calls. */
618+ /**
619+ * @param array<string,mixed> $function_call Serialized function call.
620+ */
615621 private static function compact_resource_call_receipt ( array $ function_call ): string {
616622 [ $ name , $ args ] = self ::compact_call_identity ( $ function_call );
617623 if ( ! self ::is_compact_resource_tool ( $ name ) ) {
@@ -898,6 +904,10 @@ private static function tool_name_has_suffix( string $name, string $suffix ): bo
898904 *
899905 * @return array{0:string,1:array<string,mixed>}
900906 */
907+ /**
908+ * @param array<string,mixed> $function_call Serialized function call.
909+ * @return array{0:string,1:array<string,mixed>}
910+ */
901911 private static function compact_call_identity ( array $ function_call ): array {
902912 $ name = self ::compact_tool_name ( $ function_call ['name ' ] ?? 'tool ' );
903913 $ args = self ::compact_tool_payload_array ( $ function_call ['args ' ] ?? array () );
@@ -914,6 +924,10 @@ private static function compact_call_identity( array $function_call ): array {
914924 *
915925 * @return array{0:string,1:array<string,mixed>}
916926 */
927+ /**
928+ * @param array<string,mixed> $function_response Serialized function response.
929+ * @return array{0:string,1:array<string,mixed>}
930+ */
917931 private static function compact_response_identity ( array $ function_response ): array {
918932 $ name = self ::compact_tool_name ( $ function_response ['name ' ] ?? 'tool ' );
919933 $ response = self ::compact_tool_payload_array ( $ function_response ['response ' ] ?? array () );
@@ -929,20 +943,43 @@ private static function compact_response_identity( array $function_response ): a
929943 return array ( $ name , $ response );
930944 }
931945
932- /** Normalize a JSON-or-array tool payload without retaining it beyond the caller. */
946+ /**
947+ * Normalize a JSON-or-array tool payload without retaining it beyond the caller.
948+ *
949+ * @return array<string,mixed>
950+ */
933951 private static function compact_tool_payload_array ( mixed $ payload ): array {
934952 if ( is_array ( $ payload ) ) {
935- return $ payload ;
953+ /** @var array<string,mixed> $normalized */
954+ $ normalized = self ::string_keyed_payload ( $ payload );
955+ return $ normalized ;
936956 }
937957
938958 if ( is_string ( $ payload ) ) {
939959 $ decoded = json_decode ( $ payload , true );
940- return is_array ( $ decoded ) ? $ decoded : array ();
960+ if ( is_array ( $ decoded ) ) {
961+ return self ::string_keyed_payload ( $ decoded );
962+ }
963+ return array ();
941964 }
942965
943966 return array ();
944967 }
945968
969+ /**
970+ * @param array $payload Tool payload.
971+ * @return array<string,mixed> String-keyed payload.
972+ */
973+ private static function string_keyed_payload ( array $ payload ): array {
974+ $ normalized = array ();
975+ foreach ( $ payload as $ key => $ value ) {
976+ if ( is_string ( $ key ) ) {
977+ $ normalized [ $ key ] = $ value ;
978+ }
979+ }
980+ return $ normalized ;
981+ }
982+
946983 /** Normalize and bound one safe receipt value. */
947984 private static function compact_receipt_value ( string $ value ): string {
948985 $ value = self ::normalize_compact_text ( wp_strip_all_tags ( $ value ) );
0 commit comments